Skip to content

Releases: labd/commercetools-node-mock

v3.0.0-beta.0

04 Mar 09:15

Choose a tag to compare

v3.0.0-beta.0 Pre-release
Pre-release

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 #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.

v2.66.0

29 Jan 08:10
d16c82e

Choose a tag to compare

Minor Changes

v2.65.1

27 Jan 19:13
7f46dbf

Choose a tag to compare

Patch Changes

v2.65.0

22 Jan 08:28
f75bfc0

Choose a tag to compare

Minor Changes

v2.64.0

02 Jan 14:35
24325e0

Choose a tag to compare

Minor Changes

v2.63.0

30 Dec 09:52
9a6a5da

Choose a tag to compare

Minor Changes

v2.62.1

19 Dec 09:02
a3156cc

Choose a tag to compare

Patch Changes

v2.62.0

18 Dec 13:18
ac3a7c0

Choose a tag to compare

Minor Changes

v2.61.3

02 Dec 16:29
f6b528f

Choose a tag to compare

Patch Changes

v2.61.2

02 Dec 15:37
e3d2838

Choose a tag to compare

Patch Changes