Releases: labd/commercetools-node-mock
v3.0.0-beta.0
Major Changes
-
#377
48ca265Thanks @mvantellingen! - Make the storage engine async to support pluggable persistent storage backends (e.g., SQLite, PostgreSQL). AllAbstractStoragemethods now return Promises. This is a breaking change for users who callctMock.project().unsafeAdd(),ctMock.project().get(), orctMock.clear()— these methods are now async and must be awaited.Breaking changes
ctMock.project().unsafeAdd(type, resource)is now async — useawait ctMock.project().unsafeAdd(type, resource)ctMock.project().get(type, id)is now async — useawait ctMock.project().get(type, id)ctMock.clear()is now async — useawait ctMock.clear()
New features
AbstractStorageandInMemoryStorageare now exported from the package, allowing custom storage backend implementations- New
storageoption onCommercetoolsMockOptionsto inject a custom storage backend
-
#377
50bcd7dThanks @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
ba62b38Thanks @mvantellingen! - Remove deprecatedstart(),stop(), andadd()methods. UseregisterHandlers()to bind to an msw server andunsafeAdd()for adding resources directly.
Minor Changes
-
#377
50bcd7dThanks @mvantellingen! - AddcreatedByandlastModifiedByfields to all resources, reflecting the client credentials used when creating or updating them. -
#377
5056e4aThanks @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
35bd4caThanks @mvantellingen! - AddSQLiteStoragebackend using Node.js built-innode:sqlitemodule (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.SQLiteStorageis 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 exportingSQLiteStorageandSQLiteStorageOptions
-
#379
90d3287Thanks @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
newloggeroption onCommercetoolsMockOptions. The standalone server now
uses pino-pretty for human-readable output.
Patch Changes
-
#377
16dc10eThanks @mvantellingen! - Add setKey, changeName, and changeDescription update actions for product types -
#377
50bcd7dThanks @mvantellingen! - Fix cart discount code handling based on review feedback from PR #360. -
#379
5f269f2Thanks @mvantellingen! - Fix creating categories with a parent specified by key instead of id. Previously, only theidfield 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
c8511f9Thanks @mvantellingen! - Fix Fastify rejecting DELETE requests with an empty JSON body by adding a custom content-type parser that tolerates empty bodies. -
#379
7dc5dccThanks @mvantellingen! - Route all error responses through the central error handler by converting direct
reply.status(4xx).send()calls to throwCommercetoolsErrorinstead. This
ensures all error responses are logged when thesilentoption is set tofalse
and provides consistent error response bodies withstatusCode,message, and
errorsfields. -
#379
1e9b331Thanks @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_extractexpression index in SQLiteStorage for direct SQL lookup instead of loading all rows - Replace the full-scan
all()+find()inCustomObjectRepository.getWithContainerAndKey()with the new indexed lookup
-
#379
b573a84Thanks @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
1e9b331Thanks @mvantellingen! - Fix performance degradation with large datasets (40k+ resources) in SQLite storage:- Add indexed
containerandco_keycolumns 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
- Add indexed
-
#377
50bcd7dThanks @mvantellingen! - Update project dependencies to their latest compatible versions. -
#377
0b36231Thanks @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
v2.65.1
Patch Changes
- #373
0729881Thanks @stephanbeek! - Added support for addDelivery order update action
v2.65.0
Minor Changes
- #370
a0f4312Thanks @BramKaashoek! - Add email token verification
v2.64.0
Minor Changes
- #368
a91c04eThanks @demeyerthom! - Add order search endpoint functionality
v2.63.0
v2.62.1
Patch Changes
- #363
18bf0cbThanks @BramKaashoek! - properly fetch the business unit key in getBusinessUnitKeyReference
v2.62.0
Minor Changes
- #361
378ad0dThanks @BramKaashoek! - Add support for as associate shopping lists
v2.61.3
Patch Changes
-
#357
b07c7c9Thanks @mvantellingen! - Fix file ref to typings file -
#359
564b3f8Thanks @BramKaashoek! - fix: allow business unit address actions to work with key as well as ID
v2.61.2
Patch Changes
- #355
263e40fThanks @mvantellingen! - Fix release by properly referencing theindex.mjsfile in the package.json