Skip to content

Release new version (beta)#378

Merged
mvantellingen merged 1 commit intomainfrom
changeset-release/main
Mar 4, 2026
Merged

Release new version (beta)#378
mvantellingen merged 1 commit intomainfrom
changeset-release/main

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 3, 2026

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

main is currently in pre mode so this branch has prereleases rather than normal releases. If you want to exit prereleases, run changeset pre exit on main.

⚠️⚠️⚠️⚠️⚠️⚠️

Releases

@labdigital/commercetools-mock@3.0.0-beta.0

Major Changes

  • #377 48ca265 Thanks @mvantellingen! - Make the storage engine async to support pluggable persistent storage backends (e.g., SQLite, PostgreSQL). All AbstractStorage methods now return Promises. This is a breaking change for users who call ctMock.project().unsafeAdd(), ctMock.project().get(), or ctMock.clear() — these methods are now async and must be awaited.

    Breaking changes

    • ctMock.project().unsafeAdd(type, resource) is now async — use await ctMock.project().unsafeAdd(type, resource)
    • ctMock.project().get(type, id) is now async — use await ctMock.project().get(type, id)
    • ctMock.clear() is now async — use await ctMock.clear()

    New features

    • AbstractStorage and InMemoryStorage are now exported from the package, allowing custom storage backend implementations
    • New storage option on CommercetoolsMockOptions to inject a custom storage backend
  • #377 50bcd7d Thanks @mvantellingen! - Replace the internal HTTP server with Fastify. The standalone mock server now uses Fastify for routing and request handling, improving performance and maintainability.

  • #377 ba62b38 Thanks @mvantellingen! - Remove deprecated start(), stop(), and add() methods. Use registerHandlers() to bind to an msw server and unsafeAdd() for adding resources directly.

Minor Changes

  • #377 50bcd7d Thanks @mvantellingen! - Add createdBy and lastModifiedBy fields to all resources, reflecting the client credentials used when creating or updating them.

  • #377 5056e4a Thanks @mvantellingen! - Add draft validation for resource creation when strict mode is enabled. Generated Zod schemas validate incoming request bodies against the commercetools API spec before passing them to repositories.

  • #377 35bd4ca Thanks @mvantellingen! - Add SQLiteStorage backend using Node.js built-in node:sqlite module (available since v22.5.0). This provides a persistent storage option that stores data in a SQLite database file while maintaining full compatibility with the existing in-memory backend.

    SQLiteStorage is available as a separate entry point to avoid breaking compatibility with Node.js < 22.5.0:

    Usage

    import { CommercetoolsMock } from "@labdigital/commercetools-mock";
    import { SQLiteStorage } from "@labdigital/commercetools-mock/sqlite";
    
    // File-based persistent storage
    const storage = new SQLiteStorage({ filename: "my-mock.db" });
    const ctMock = new CommercetoolsMock({ storage });
    
    // In-memory SQLite (useful for tests)
    const storage = new SQLiteStorage({ filename: ":memory:" });

    New exports

    • @labdigital/commercetools-mock/sqlite — Separate entry point exporting SQLiteStorage and SQLiteStorageOptions
  • #379 90d3287 Thanks @mvantellingen! - Unify logging to use Pino (via Fastify's built-in logger) instead of
    console.error. Add support for passing a custom Pino logger instance via the
    new logger option on CommercetoolsMockOptions. The standalone server now
    uses pino-pretty for human-readable output.

Patch Changes

  • #377 16dc10e Thanks @mvantellingen! - Add setKey, changeName, and changeDescription update actions for product types

  • #377 50bcd7d Thanks @mvantellingen! - Fix cart discount code handling based on review feedback from PR Add basic support for discount codes in the cart repository #360.

  • #379 5f269f2 Thanks @mvantellingen! - Fix creating categories with a parent specified by key instead of id. Previously, only the id field was used when storing the parent reference, causing a "ResourceIdentifier requires an 'id' xor a 'key'" error when the parent was specified by key.

  • #379 c8511f9 Thanks @mvantellingen! - Fix Fastify rejecting DELETE requests with an empty JSON body by adding a custom content-type parser that tolerates empty bodies.

  • #379 7dc5dcc Thanks @mvantellingen! - Route all error responses through the central error handler by converting direct
    reply.status(4xx).send() calls to throw CommercetoolsError instead. This
    ensures all error responses are logged when the silent option is set to false
    and provides consistent error response bodies with statusCode, message, and
    errors fields.

  • #379 1e9b331 Thanks @mvantellingen! - Optimize custom object lookups by container and key from O(n) to O(1):

    • Add a secondary in-memory index (container+key -> id) in InMemoryStorage, maintained on add/delete
    • Add a json_extract expression index in SQLiteStorage for direct SQL lookup instead of loading all rows
    • Replace the full-scan all() + find() in CustomObjectRepository.getWithContainerAndKey() with the new indexed lookup
  • #379 b573a84 Thanks @mvantellingen! - Improve resource creation performance, especially noticeable with SQLite storage and large numbers of resources:

    • Eliminate redundant re-fetch after inserting a resource in both SQLite and InMemory storage backends
    • Cache known project keys in SQLite storage to skip repeated INSERT+SELECT on the projects table
    • Avoid double-fetching the resource in the service POST handler by reusing the already-created resource instead of re-fetching from storage
  • #379 1e9b331 Thanks @mvantellingen! - Fix performance degradation with large datasets (40k+ resources) in SQLite storage:

    • Add indexed container and co_key columns to the SQLite resources table, replacing the O(n) json_extract-based custom object lookup with an O(log n) indexed query
    • Include automatic schema migration for existing databases
    • Add count() method to storage backends, enabling fast O(1) existence checks
    • Short-circuit review statistics calculation when no reviews exist, avoiding a full table scan on every product creation/retrieval
  • #377 50bcd7d Thanks @mvantellingen! - Update project dependencies to their latest compatible versions.

  • #377 0b36231 Thanks @mvantellingen! - Upgrade zod from v3 to v4 and remove zod-validation-error dependency. Validation error messages now use a built-in formatter that produces commercetools-style error details.

@github-actions github-actions bot force-pushed the changeset-release/main branch from 1c75132 to db04d7e Compare March 4, 2026 07:59
@mvantellingen mvantellingen merged commit 3eb9ae9 into main Mar 4, 2026
@mvantellingen mvantellingen deleted the changeset-release/main branch March 4, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant