@labdigital/commercetools-mock 2.60.0 → 2.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.d.ts → index.d.mts} +154 -275
- package/dist/{index.js → index.mjs} +241 -349
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -18
- package/src/config.ts +1 -1
- package/src/ctMock.test.ts +1 -1
- package/src/ctMock.ts +22 -21
- package/src/index.test.ts +1 -1
- package/src/index.ts +3 -3
- package/src/lib/haversine.test.ts +2 -2
- package/src/lib/masking.ts +1 -1
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +1 -1
- package/src/lib/predicateParser.test.ts +1 -1
- package/src/lib/predicateParser.ts +4 -4
- package/src/lib/product-review-statistics.test.ts +4 -8
- package/src/lib/productSearchFilter.test.ts +3 -3
- package/src/lib/productSearchFilter.ts +6 -6
- package/src/lib/projectionSearchFilter.test.ts +3 -3
- package/src/lib/projectionSearchFilter.ts +4 -4
- package/src/lib/review-statistics.ts +1 -1
- package/src/lib/searchQueryTypeChecker.test.ts +3 -3
- package/src/lib/searchQueryTypeChecker.ts +8 -4
- package/src/lib/tax.test.ts +3 -3
- package/src/lib/tax.ts +3 -3
- package/src/oauth/server.test.ts +7 -7
- package/src/oauth/server.ts +7 -7
- package/src/priceSelector.test.ts +1 -1
- package/src/priceSelector.ts +2 -2
- package/src/product-projection-search.ts +10 -12
- package/src/product-search-availability.test.ts +1 -1
- package/src/product-search.ts +6 -7
- package/src/projectAPI.test.ts +1 -1
- package/src/projectAPI.ts +7 -7
- package/src/repositories/abstract.ts +8 -10
- package/src/repositories/as-associate.test.ts +4 -4
- package/src/repositories/as-associate.ts +3 -3
- package/src/repositories/associate-role.ts +7 -9
- package/src/repositories/attribute-group.test.ts +3 -3
- package/src/repositories/attribute-group.ts +5 -5
- package/src/repositories/business-unit.test.ts +6 -6
- package/src/repositories/business-unit.ts +21 -23
- package/src/repositories/cart/actions.ts +12 -15
- package/src/repositories/cart/helpers.ts +5 -5
- package/src/repositories/cart/index.test.ts +5 -10
- package/src/repositories/cart/index.ts +13 -18
- package/src/repositories/cart-discount/actions.ts +5 -6
- package/src/repositories/cart-discount/index.ts +5 -5
- package/src/repositories/category/actions.ts +4 -4
- package/src/repositories/category/index.test.ts +3 -3
- package/src/repositories/category/index.ts +8 -8
- package/src/repositories/channel.test.ts +4 -4
- package/src/repositories/channel.ts +6 -6
- package/src/repositories/custom-object.ts +11 -8
- package/src/repositories/customer/actions.ts +9 -9
- package/src/repositories/customer/index.test.ts +3 -3
- package/src/repositories/customer/index.ts +12 -9
- package/src/repositories/customer-group.test.ts +4 -4
- package/src/repositories/customer-group.ts +6 -6
- package/src/repositories/discount-code/actions.ts +4 -4
- package/src/repositories/discount-code/index.ts +5 -5
- package/src/repositories/discount-group/actions.ts +3 -4
- package/src/repositories/discount-group/index.ts +4 -4
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.test.ts +3 -3
- package/src/repositories/extension.ts +6 -6
- package/src/repositories/helpers.ts +9 -12
- package/src/repositories/index.test.ts +3 -3
- package/src/repositories/index.ts +43 -43
- package/src/repositories/inventory-entry/actions.ts +15 -3
- package/src/repositories/inventory-entry/index.ts +5 -5
- package/src/repositories/my-customer.ts +5 -5
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/my-quote-request.ts +1 -1
- package/src/repositories/order/actions.ts +8 -9
- package/src/repositories/order/index.test.ts +8 -9
- package/src/repositories/order/index.ts +16 -17
- package/src/repositories/order-edit.ts +4 -4
- package/src/repositories/payment/actions.ts +6 -6
- package/src/repositories/payment/helpers.ts +3 -3
- package/src/repositories/payment/index.ts +7 -7
- package/src/repositories/product/actions.ts +7 -7
- package/src/repositories/product/helpers.ts +4 -4
- package/src/repositories/product/index.ts +13 -13
- package/src/repositories/product-discount.ts +9 -6
- package/src/repositories/product-projection.ts +7 -7
- package/src/repositories/product-selection.ts +9 -6
- package/src/repositories/product-tailoring.ts +6 -3
- package/src/repositories/product-type.ts +8 -5
- package/src/repositories/project.ts +5 -5
- package/src/repositories/quote/actions.ts +6 -6
- package/src/repositories/quote/index.ts +5 -5
- package/src/repositories/quote-request/actions.ts +6 -6
- package/src/repositories/quote-request/index.test.ts +3 -3
- package/src/repositories/quote-request/index.ts +5 -5
- package/src/repositories/quote-staged/actions.ts +6 -6
- package/src/repositories/quote-staged/index.ts +5 -5
- package/src/repositories/recurrence-policy/actions.ts +3 -3
- package/src/repositories/recurrence-policy/index.ts +4 -8
- package/src/repositories/recurring-order/actions.ts +3 -3
- package/src/repositories/recurring-order/index.ts +5 -5
- package/src/repositories/review.test.ts +5 -5
- package/src/repositories/review.ts +10 -9
- package/src/repositories/shipping-method/actions.ts +7 -9
- package/src/repositories/shipping-method/helpers.ts +1 -1
- package/src/repositories/shipping-method/index.ts +8 -8
- package/src/repositories/shopping-list/actions.ts +5 -5
- package/src/repositories/shopping-list/index.ts +7 -7
- package/src/repositories/standalone-price.ts +9 -6
- package/src/repositories/state.ts +9 -6
- package/src/repositories/store.ts +10 -7
- package/src/repositories/subscription.test.ts +3 -3
- package/src/repositories/subscription.ts +9 -6
- package/src/repositories/tax-category/actions.ts +4 -4
- package/src/repositories/tax-category/index.ts +6 -6
- package/src/repositories/type/actions.ts +4 -4
- package/src/repositories/type/index.ts +5 -5
- package/src/repositories/zone.test.ts +3 -3
- package/src/repositories/zone.ts +8 -5
- package/src/server.ts +4 -3
- package/src/services/abstract.ts +5 -5
- package/src/services/as-associate-cart.test.ts +1 -1
- package/src/services/as-associate-cart.ts +2 -2
- package/src/services/as-associate-order.test.ts +1 -1
- package/src/services/as-associate-order.ts +2 -2
- package/src/services/as-associate-quote-request.ts +2 -3
- package/src/services/as-associate.test.ts +1 -1
- package/src/services/as-associate.ts +4 -4
- package/src/services/associate-roles.test.ts +1 -1
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.test.ts +1 -1
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +5 -5
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.ts +2 -2
- package/src/services/cart.test.ts +2 -2
- package/src/services/cart.ts +4 -5
- package/src/services/category.test.ts +1 -1
- package/src/services/category.ts +2 -2
- package/src/services/channel.test.ts +1 -1
- package/src/services/channel.ts +2 -2
- package/src/services/custom-object.test.ts +2 -2
- package/src/services/custom-object.ts +3 -3
- package/src/services/customer-group.test.ts +1 -1
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +3 -3
- package/src/services/customer.ts +4 -5
- package/src/services/discount-code.test.ts +1 -1
- package/src/services/discount-code.ts +2 -2
- package/src/services/discount-group.test.ts +1 -1
- package/src/services/discount-group.ts +2 -2
- package/src/services/extension.test.ts +1 -1
- package/src/services/extension.ts +2 -2
- package/src/services/index.ts +44 -44
- package/src/services/inventory-entry.test.ts +16 -1
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.test.ts +1 -1
- package/src/services/my-business-unit.ts +2 -2
- package/src/services/my-cart.test.ts +1 -1
- package/src/services/my-cart.ts +2 -2
- package/src/services/my-customer.test.ts +2 -2
- package/src/services/my-customer.ts +6 -6
- package/src/services/my-order.ts +2 -2
- package/src/services/my-payment.test.ts +1 -1
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.test.ts +4 -11
- package/src/services/order.ts +4 -4
- package/src/services/payment.test.ts +1 -1
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.test.ts +1 -1
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +2 -2
- package/src/services/product-projection.ts +4 -4
- package/src/services/product-selection.test.ts +1 -1
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.test.ts +1 -1
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +3 -3
- package/src/services/project.test.ts +1 -1
- package/src/services/project.ts +4 -4
- package/src/services/quote-request.test.ts +2 -2
- package/src/services/quote-request.ts +2 -2
- package/src/services/quote-staged.ts +2 -2
- package/src/services/quote.ts +2 -2
- package/src/services/recurrence-policy.test.ts +1 -1
- package/src/services/recurrence-policy.ts +2 -2
- package/src/services/recurring-order.test.ts +1 -1
- package/src/services/recurring-order.ts +2 -2
- package/src/services/reviews.test.ts +1 -1
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.test.ts +2 -2
- package/src/services/shipping-method.ts +4 -4
- package/src/services/shopping-list.test.ts +1 -1
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.test.ts +1 -1
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.test.ts +1 -1
- package/src/services/state.ts +2 -2
- package/src/services/store.test.ts +1 -1
- package/src/services/store.ts +2 -2
- package/src/services/subscription.test.ts +1 -1
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.test.ts +1 -1
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.test.ts +1 -1
- package/src/services/type.ts +2 -2
- package/src/services/zone.test.ts +1 -1
- package/src/services/zone.ts +2 -2
- package/src/shipping.test.ts +1 -1
- package/src/shipping.ts +8 -8
- package/src/storage/abstract.ts +1 -1
- package/src/storage/in-memory.ts +15 -17
- package/src/storage/index.ts +2 -2
- package/src/testing/business-unit.ts +1 -2
- package/src/testing/customer.ts +1 -1
- package/src/testing/type.ts +1 -1
- package/src/types.ts +1 -1
- package/src/validate.ts +1 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.61.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michael van Tellingen",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./dist/index.js"
|
|
9
9
|
},
|
|
10
|
+
"imports": {
|
|
11
|
+
"#src/*": "./src/*",
|
|
12
|
+
"#vendor/*": "./vendor/*"
|
|
13
|
+
},
|
|
10
14
|
"main": "dist/index.js",
|
|
11
15
|
"module": "dist/index.js",
|
|
12
16
|
"typings": "dist/index.d.ts",
|
|
@@ -16,49 +20,57 @@
|
|
|
16
20
|
],
|
|
17
21
|
"dependencies": {
|
|
18
22
|
"basic-auth": "2.0.1",
|
|
19
|
-
"body-parser": "2.2.
|
|
23
|
+
"body-parser": "2.2.1",
|
|
20
24
|
"decimal.js": "10.5.0",
|
|
21
25
|
"express": "5.1.0",
|
|
22
26
|
"light-my-request": "6.6.0",
|
|
23
|
-
"morgan": "1.10.
|
|
27
|
+
"morgan": "1.10.1",
|
|
24
28
|
"msw": "2.8.4",
|
|
25
29
|
"uuid": "11.1.0",
|
|
26
30
|
"zod": "3.24.2",
|
|
27
31
|
"zod-validation-error": "3.4.0"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "
|
|
31
|
-
"@
|
|
32
|
-
"@changesets/
|
|
33
|
-
"@changesets/cli": "2.28.1",
|
|
34
|
+
"@biomejs/biome": "2.3.7",
|
|
35
|
+
"@changesets/changelog-github": "0.5.2",
|
|
36
|
+
"@changesets/cli": "2.29.7",
|
|
34
37
|
"@commercetools/platform-sdk": "8.16.0",
|
|
35
38
|
"@types/basic-auth": "1.1.8",
|
|
36
39
|
"@types/body-parser": "1.19.5",
|
|
37
|
-
"@types/express
|
|
40
|
+
"@types/express": "5.0.5",
|
|
41
|
+
"@types/express-serve-static-core": "^5.1.0",
|
|
38
42
|
"@types/morgan": "1.9.9",
|
|
39
43
|
"@types/node": "20.16.14",
|
|
40
44
|
"@types/qs": "6.9.11",
|
|
41
|
-
"@types/supertest": "6.0.
|
|
45
|
+
"@types/supertest": "6.0.3",
|
|
42
46
|
"@types/uuid": "9.0.8",
|
|
43
|
-
"@vitest/coverage-v8": "
|
|
44
|
-
"esbuild": "0.25.2",
|
|
47
|
+
"@vitest/coverage-v8": "4.0.13",
|
|
45
48
|
"fishery": "2.2.3",
|
|
46
|
-
"supertest": "7.1.
|
|
49
|
+
"supertest": "7.1.4",
|
|
47
50
|
"timekeeper": "2.3.1",
|
|
48
|
-
"tsdown": "
|
|
49
|
-
"typescript": "5.
|
|
50
|
-
"vitest": "
|
|
51
|
+
"tsdown": "0.16.8",
|
|
52
|
+
"typescript": "5.9.3",
|
|
53
|
+
"vitest": "4.0.13"
|
|
51
54
|
},
|
|
52
55
|
"engines": {
|
|
53
56
|
"node": ">=18",
|
|
54
|
-
"pnpm": ">=
|
|
57
|
+
"pnpm": ">=10.8.0"
|
|
55
58
|
},
|
|
56
59
|
"publishConfig": {
|
|
57
|
-
"access": "public"
|
|
60
|
+
"access": "public",
|
|
61
|
+
"provenance": true
|
|
62
|
+
},
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "git+https://github.com/labd/commercetools-node-mock.git"
|
|
66
|
+
},
|
|
67
|
+
"bugs": {
|
|
68
|
+
"url": "https://github.com/labd/commercetools-node-mock/issues"
|
|
58
69
|
},
|
|
70
|
+
"homepage": "https://github.com/labd/commercetools-node-mock#readme",
|
|
59
71
|
"scripts": {
|
|
60
72
|
"build": "tsdown",
|
|
61
|
-
"build:server": "
|
|
73
|
+
"build:server": "tsdown src/server.ts --platform=node",
|
|
62
74
|
"check": "biome check && tsc",
|
|
63
75
|
"format": "biome check --fix",
|
|
64
76
|
"lint": "biome check",
|
package/src/config.ts
CHANGED
package/src/ctMock.test.ts
CHANGED
package/src/ctMock.ts
CHANGED
|
@@ -2,23 +2,23 @@ import type { NextFunction, Request, Response } from "express";
|
|
|
2
2
|
import express from "express";
|
|
3
3
|
import inject from "light-my-request";
|
|
4
4
|
import morgan from "morgan";
|
|
5
|
-
import {
|
|
5
|
+
import { HttpResponse, http } from "msw";
|
|
6
6
|
import type { SetupServer, SetupServerApi } from "msw/node";
|
|
7
7
|
import { setupServer } from "msw/node";
|
|
8
|
-
import type { Config } from "./config";
|
|
9
|
-
import { DEFAULT_API_HOSTNAME, DEFAULT_AUTH_HOSTNAME } from "./constants";
|
|
10
|
-
import { CommercetoolsError } from "./exceptions";
|
|
11
|
-
import { mapHeaderType } from "./helpers";
|
|
12
|
-
import { copyHeaders } from "./lib/proxy";
|
|
13
|
-
import { OAuth2Server } from "./oauth/server";
|
|
14
|
-
import { ProjectAPI } from "./projectAPI";
|
|
15
|
-
import type { RepositoryMap } from "./repositories";
|
|
16
|
-
import { createRepositories } from "./repositories";
|
|
17
|
-
import type { ProjectRepository } from "./repositories/project";
|
|
18
|
-
import { createServices } from "./services";
|
|
19
|
-
import { ProjectService } from "./services/project";
|
|
20
|
-
import type { AbstractStorage } from "./storage";
|
|
21
|
-
import { InMemoryStorage } from "./storage";
|
|
8
|
+
import type { Config } from "./config.ts";
|
|
9
|
+
import { DEFAULT_API_HOSTNAME, DEFAULT_AUTH_HOSTNAME } from "./constants.ts";
|
|
10
|
+
import { CommercetoolsError } from "./exceptions.ts";
|
|
11
|
+
import { mapHeaderType } from "./helpers.ts";
|
|
12
|
+
import { copyHeaders } from "./lib/proxy.ts";
|
|
13
|
+
import { OAuth2Server } from "./oauth/server.ts";
|
|
14
|
+
import { ProjectAPI } from "./projectAPI.ts";
|
|
15
|
+
import type { RepositoryMap } from "./repositories/index.ts";
|
|
16
|
+
import { createRepositories } from "./repositories/index.ts";
|
|
17
|
+
import type { ProjectRepository } from "./repositories/project.ts";
|
|
18
|
+
import { createServices } from "./services/index.ts";
|
|
19
|
+
import { ProjectService } from "./services/project.ts";
|
|
20
|
+
import type { AbstractStorage } from "./storage/index.ts";
|
|
21
|
+
import { InMemoryStorage } from "./storage/index.ts";
|
|
22
22
|
|
|
23
23
|
export type CommercetoolsMockOptions = {
|
|
24
24
|
validateCredentials: boolean;
|
|
@@ -57,7 +57,8 @@ export class CommercetoolsMock {
|
|
|
57
57
|
|
|
58
58
|
private _repositories: RepositoryMap | null;
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
// biome-ignore lint: lint/correctness/noUnusedPrivateClassMembers
|
|
61
|
+
private _projectService: ProjectService | undefined;
|
|
61
62
|
|
|
62
63
|
constructor(options: Partial<CommercetoolsMockOptions> = {}) {
|
|
63
64
|
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
@@ -123,9 +124,7 @@ export class CommercetoolsMock {
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
runServer(port = 3000, options?: AppOptions) {
|
|
126
|
-
const server = this.app.listen(port, () => {
|
|
127
|
-
console.info(`Mock server listening at http://localhost:${port}`);
|
|
128
|
-
});
|
|
127
|
+
const server = this.app.listen(port, () => {});
|
|
129
128
|
server.keepAliveTimeout = 60 * 1000;
|
|
130
129
|
}
|
|
131
130
|
|
|
@@ -186,7 +185,6 @@ export class CommercetoolsMock {
|
|
|
186
185
|
});
|
|
187
186
|
return;
|
|
188
187
|
}
|
|
189
|
-
console.error(err);
|
|
190
188
|
resp.status(500).send({
|
|
191
189
|
error: err.message,
|
|
192
190
|
});
|
|
@@ -312,7 +310,10 @@ export class CommercetoolsMock {
|
|
|
312
310
|
throw new Error("Server already started");
|
|
313
311
|
}
|
|
314
312
|
process.emitWarning("Server wasn't stopped properly, clearing");
|
|
315
|
-
|
|
313
|
+
for (const listener of _globalListeners) {
|
|
314
|
+
listener.close();
|
|
315
|
+
}
|
|
316
|
+
_globalListeners.length = 0;
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
const server = setupServer();
|
package/src/index.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { InvalidTokenError } from "@commercetools/platform-sdk";
|
|
2
2
|
import { setupServer } from "msw/node";
|
|
3
3
|
import { afterEach, beforeAll, expect, test } from "vitest";
|
|
4
|
-
import { CommercetoolsMock } from "./index";
|
|
4
|
+
import { CommercetoolsMock } from "./index.ts";
|
|
5
5
|
|
|
6
6
|
const mswServer = setupServer();
|
|
7
7
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CommercetoolsMockOptions } from "./ctMock";
|
|
2
|
-
import { CommercetoolsMock } from "./ctMock";
|
|
3
|
-
import { getBaseResourceProperties } from "./helpers";
|
|
1
|
+
import type { CommercetoolsMockOptions } from "./ctMock.ts";
|
|
2
|
+
import { CommercetoolsMock } from "./ctMock.ts";
|
|
3
|
+
import { getBaseResourceProperties } from "./helpers.ts";
|
|
4
4
|
|
|
5
5
|
export {
|
|
6
6
|
CommercetoolsMock,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
-
import type { Location } from "./haversine";
|
|
3
|
-
import { haversineDistance } from "./haversine";
|
|
2
|
+
import type { Location } from "./haversine.ts";
|
|
3
|
+
import { haversineDistance } from "./haversine.ts";
|
|
4
4
|
|
|
5
5
|
test("haversine", () => {
|
|
6
6
|
// Lab Digital
|
package/src/lib/masking.ts
CHANGED
package/src/lib/parser.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Lexer } from "
|
|
2
|
-
export {
|
|
1
|
+
export { Lexer } from "#vendor/perplex/lexer.ts";
|
|
2
|
+
export { type ITokenPosition, Parser } from "#vendor/pratt/index.ts";
|
package/src/lib/password.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { VariableMap } from "@commercetools/platform-sdk";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { PredicateError, parseQueryExpression } from "./predicateParser";
|
|
3
|
+
import { PredicateError, parseQueryExpression } from "./predicateParser.ts";
|
|
4
4
|
|
|
5
5
|
describe("Predicate filter", () => {
|
|
6
6
|
const exampleObject = {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* See https://docs.commercetools.com/api/predicates/query
|
|
6
6
|
*/
|
|
7
|
-
import { haversineDistance } from "./haversine";
|
|
8
|
-
import { type ITokenPosition, Lexer, Parser } from "./parser";
|
|
7
|
+
import { haversineDistance } from "./haversine.ts";
|
|
8
|
+
import { type ITokenPosition, Lexer, Parser } from "./parser.ts";
|
|
9
9
|
|
|
10
10
|
export class PredicateError {
|
|
11
11
|
message: string;
|
|
@@ -194,7 +194,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
194
194
|
(t) =>
|
|
195
195
|
({
|
|
196
196
|
type: "var",
|
|
197
|
-
// @ts-
|
|
197
|
+
// @ts-expect-error
|
|
198
198
|
value: t.token.groups[1],
|
|
199
199
|
pos: t.token.strpos(),
|
|
200
200
|
}) as TypeSymbol,
|
|
@@ -205,7 +205,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
205
205
|
(t) =>
|
|
206
206
|
({
|
|
207
207
|
type: "string",
|
|
208
|
-
// @ts-
|
|
208
|
+
// @ts-expect-error
|
|
209
209
|
value: t.token.groups[1],
|
|
210
210
|
pos: t.token.strpos(),
|
|
211
211
|
}) as TypeSymbol,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Product,
|
|
3
|
-
ProductProjection,
|
|
4
|
-
Review,
|
|
5
|
-
} from "@commercetools/platform-sdk";
|
|
1
|
+
import type { Product } from "@commercetools/platform-sdk";
|
|
6
2
|
import supertest from "supertest";
|
|
7
3
|
import { beforeEach, describe, expect, test } from "vitest";
|
|
8
|
-
import { CommercetoolsMock } from "
|
|
4
|
+
import { CommercetoolsMock } from "#src/index.ts";
|
|
9
5
|
|
|
10
6
|
describe("Product Review Statistics", () => {
|
|
11
7
|
let ctMock: CommercetoolsMock;
|
|
@@ -179,7 +175,7 @@ describe("Product Review Statistics", () => {
|
|
|
179
175
|
|
|
180
176
|
test("only reviews with includedInStatistics=true are counted", async () => {
|
|
181
177
|
// Create reviews - both will be included by default
|
|
182
|
-
const
|
|
178
|
+
const _review1Response = await supertest(ctMock.app)
|
|
183
179
|
.post("/dummy/reviews")
|
|
184
180
|
.send({
|
|
185
181
|
authorName: "Reviewer 1",
|
|
@@ -190,7 +186,7 @@ describe("Product Review Statistics", () => {
|
|
|
190
186
|
},
|
|
191
187
|
});
|
|
192
188
|
|
|
193
|
-
const
|
|
189
|
+
const _review2Response = await supertest(ctMock.app)
|
|
194
190
|
.post("/dummy/reviews")
|
|
195
191
|
.send({
|
|
196
192
|
authorName: "Reviewer 2",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
ProductProjection,
|
|
3
2
|
_SearchQuery,
|
|
3
|
+
ProductProjection,
|
|
4
4
|
} from "@commercetools/platform-sdk";
|
|
5
5
|
import { describe, expect, test } from "vitest";
|
|
6
|
-
import { cloneObject } from "
|
|
7
|
-
import { parseSearchQuery } from "./productSearchFilter";
|
|
6
|
+
import { cloneObject } from "#src/helpers.ts";
|
|
7
|
+
import { parseSearchQuery } from "./productSearchFilter.ts";
|
|
8
8
|
|
|
9
9
|
describe("Product search filter", () => {
|
|
10
10
|
const exampleProduct: ProductProjection = {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
_SearchQuery,
|
|
3
|
+
_SearchQueryExpression,
|
|
4
|
+
_SearchQueryExpressionValue,
|
|
2
5
|
ProductProjection,
|
|
3
6
|
ProductVariant,
|
|
4
7
|
SearchAndExpression,
|
|
@@ -16,13 +19,10 @@ import type {
|
|
|
16
19
|
SearchPrefixExpression,
|
|
17
20
|
SearchTimeRangeExpression,
|
|
18
21
|
SearchWildCardExpression,
|
|
19
|
-
_SearchQuery,
|
|
20
|
-
_SearchQueryExpression,
|
|
21
|
-
_SearchQueryExpressionValue,
|
|
22
22
|
} from "@commercetools/platform-sdk";
|
|
23
|
-
import { nestedLookup } from "
|
|
24
|
-
import type { Writable } from "../types";
|
|
25
|
-
import { getVariants } from "./projectionSearchFilter";
|
|
23
|
+
import { nestedLookup } from "#src/helpers.ts";
|
|
24
|
+
import type { Writable } from "../types.ts";
|
|
25
|
+
import { getVariants } from "./projectionSearchFilter.ts";
|
|
26
26
|
|
|
27
27
|
type ProductSearchFilterFunc = (
|
|
28
28
|
p: Writable<ProductProjection>,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ProductProjection } from "@commercetools/platform-sdk";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { cloneObject } from "../helpers";
|
|
4
|
-
import { applyPriceSelector } from "../priceSelector";
|
|
5
|
-
import { parseFilterExpression } from "./projectionSearchFilter";
|
|
3
|
+
import { cloneObject } from "../helpers.ts";
|
|
4
|
+
import { applyPriceSelector } from "../priceSelector.ts";
|
|
5
|
+
import { parseFilterExpression } from "./projectionSearchFilter.ts";
|
|
6
6
|
|
|
7
7
|
describe("Search filter", () => {
|
|
8
8
|
const exampleProduct: ProductProjection = {
|
|
@@ -6,9 +6,9 @@ import type {
|
|
|
6
6
|
ProductProjection,
|
|
7
7
|
ProductVariant,
|
|
8
8
|
} from "@commercetools/platform-sdk";
|
|
9
|
-
import { nestedLookup } from "../helpers";
|
|
10
|
-
import type { Writable } from "../types";
|
|
11
|
-
import { Lexer, Parser } from "./parser";
|
|
9
|
+
import { nestedLookup } from "../helpers.ts";
|
|
10
|
+
import type { Writable } from "../types.ts";
|
|
11
|
+
import { Lexer, Parser } from "./parser.ts";
|
|
12
12
|
|
|
13
13
|
type MatchFunc = (target: any) => boolean;
|
|
14
14
|
|
|
@@ -143,7 +143,7 @@ const parseFilter = (filter: string): ExpressionSet => {
|
|
|
143
143
|
({
|
|
144
144
|
type: "Symbol",
|
|
145
145
|
kind: "string",
|
|
146
|
-
// @ts-
|
|
146
|
+
// @ts-expect-error
|
|
147
147
|
value: t.token.groups[1],
|
|
148
148
|
}) as TypeSymbol,
|
|
149
149
|
)
|
|
@@ -2,7 +2,7 @@ import type {
|
|
|
2
2
|
Review,
|
|
3
3
|
ReviewRatingStatistics,
|
|
4
4
|
} from "@commercetools/platform-sdk";
|
|
5
|
-
import type { AbstractStorage } from "../storage";
|
|
5
|
+
import type { AbstractStorage } from "../storage/index.ts";
|
|
6
6
|
|
|
7
7
|
export class ReviewStatisticsService {
|
|
8
8
|
constructor(private _storage: AbstractStorage) {}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
SearchAndExpression,
|
|
3
|
-
SearchOrExpression,
|
|
4
2
|
_SearchQuery,
|
|
5
3
|
_SearchQueryExpression,
|
|
4
|
+
SearchAndExpression,
|
|
5
|
+
SearchOrExpression,
|
|
6
6
|
} from "@commercetools/platform-sdk";
|
|
7
7
|
import { describe, expect, it } from "vitest";
|
|
8
8
|
import {
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
isSearchRangeExpression,
|
|
20
20
|
isSearchWildCardExpression,
|
|
21
21
|
validateSearchQuery,
|
|
22
|
-
} from "./searchQueryTypeChecker";
|
|
22
|
+
} from "./searchQueryTypeChecker.ts";
|
|
23
23
|
|
|
24
24
|
describe("searchQueryTypeChecker", () => {
|
|
25
25
|
it("should validate SearchAndExpression", () => {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
_SearchQuery,
|
|
3
|
+
_SearchQueryExpression,
|
|
2
4
|
SearchAndExpression,
|
|
3
5
|
SearchAnyValue,
|
|
4
6
|
SearchDateRangeExpression,
|
|
@@ -15,15 +17,17 @@ import type {
|
|
|
15
17
|
SearchPrefixExpression,
|
|
16
18
|
SearchTimeRangeExpression,
|
|
17
19
|
SearchWildCardExpression,
|
|
18
|
-
_SearchQuery,
|
|
19
|
-
_SearchQueryExpression,
|
|
20
20
|
} from "@commercetools/platform-sdk";
|
|
21
21
|
|
|
22
22
|
export const validateSearchQuery = (query: _SearchQuery): void => {
|
|
23
23
|
if (isSearchAndExpression(query)) {
|
|
24
|
-
query.and
|
|
24
|
+
for (const expr of query.and) {
|
|
25
|
+
validateSearchQuery(expr);
|
|
26
|
+
}
|
|
25
27
|
} else if (isSearchOrExpression(query)) {
|
|
26
|
-
query.or
|
|
28
|
+
for (const expr of query.or) {
|
|
29
|
+
validateSearchQuery(expr);
|
|
30
|
+
}
|
|
27
31
|
} else if (isSearchNotExpression(query)) {
|
|
28
32
|
validateSearchQuery(query.not);
|
|
29
33
|
} else if (
|
package/src/lib/tax.test.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
TaxCategory,
|
|
3
|
-
TaxRate,
|
|
4
3
|
TaxedItemPrice,
|
|
4
|
+
TaxRate,
|
|
5
5
|
} from "@commercetools/platform-sdk";
|
|
6
6
|
import { describe, expect, test } from "vitest";
|
|
7
7
|
import {
|
|
8
|
-
calculateTaxTotals,
|
|
9
8
|
calculateTaxedPrice,
|
|
10
9
|
calculateTaxedPriceFromRate,
|
|
11
|
-
|
|
10
|
+
calculateTaxTotals,
|
|
11
|
+
} from "#src/lib/tax.ts";
|
|
12
12
|
|
|
13
13
|
const money = (centAmount: number) => ({
|
|
14
14
|
type: "centPrecision" as const,
|
package/src/lib/tax.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Cart,
|
|
3
3
|
TaxCategory,
|
|
4
|
-
TaxPortion,
|
|
5
|
-
TaxRate,
|
|
6
4
|
TaxedItemPrice,
|
|
7
5
|
TaxedPrice,
|
|
6
|
+
TaxPortion,
|
|
7
|
+
TaxRate,
|
|
8
8
|
} from "@commercetools/platform-sdk";
|
|
9
|
-
import { createCentPrecisionMoney } from "
|
|
9
|
+
import { createCentPrecisionMoney } from "#src/repositories/helpers.ts";
|
|
10
10
|
|
|
11
11
|
type TaxableResource = Pick<
|
|
12
12
|
Cart,
|
package/src/oauth/server.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import supertest from "supertest";
|
|
3
3
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
4
|
-
import type { Config } from "
|
|
5
|
-
import { getBaseResourceProperties } from "../helpers";
|
|
6
|
-
import { hashPassword } from "../lib/password";
|
|
7
|
-
import { CustomerRepository } from "../repositories/customer";
|
|
8
|
-
import type { AbstractStorage } from "../storage";
|
|
9
|
-
import { InMemoryStorage } from "../storage";
|
|
10
|
-
import { OAuth2Server } from "./server";
|
|
4
|
+
import type { Config } from "#src/config.ts";
|
|
5
|
+
import { getBaseResourceProperties } from "../helpers.ts";
|
|
6
|
+
import { hashPassword } from "../lib/password.ts";
|
|
7
|
+
import { CustomerRepository } from "../repositories/customer/index.ts";
|
|
8
|
+
import type { AbstractStorage } from "../storage/index.ts";
|
|
9
|
+
import { InMemoryStorage } from "../storage/index.ts";
|
|
10
|
+
import { OAuth2Server } from "./server.ts";
|
|
11
11
|
|
|
12
12
|
describe("OAuth2Server", () => {
|
|
13
13
|
let app: express.Express;
|
package/src/oauth/server.ts
CHANGED
|
@@ -6,13 +6,13 @@ import express, {
|
|
|
6
6
|
type Request,
|
|
7
7
|
type Response,
|
|
8
8
|
} from "express";
|
|
9
|
-
import type { AuthError, InvalidRequestError } from "
|
|
10
|
-
import { CommercetoolsError } from "
|
|
11
|
-
import { hashPassword } from "../lib/password";
|
|
12
|
-
import type { CustomerRepository } from "../repositories/customer";
|
|
13
|
-
import type { InvalidClientError, UnsupportedGrantType } from "./errors";
|
|
14
|
-
import { getBearerToken } from "./helpers";
|
|
15
|
-
import { OAuth2Store } from "./store";
|
|
9
|
+
import type { AuthError, InvalidRequestError } from "#src/exceptions.ts";
|
|
10
|
+
import { CommercetoolsError } from "#src/exceptions.ts";
|
|
11
|
+
import { hashPassword } from "../lib/password.ts";
|
|
12
|
+
import type { CustomerRepository } from "../repositories/customer/index.ts";
|
|
13
|
+
import type { InvalidClientError, UnsupportedGrantType } from "./errors.ts";
|
|
14
|
+
import { getBearerToken } from "./helpers.ts";
|
|
15
|
+
import { OAuth2Store } from "./store.ts";
|
|
16
16
|
|
|
17
17
|
type AuthRequest = Request & {
|
|
18
18
|
credentials?: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProductProjection } from "@commercetools/platform-sdk";
|
|
2
2
|
import { beforeEach, describe, expect, test } from "vitest";
|
|
3
|
-
import { applyPriceSelector } from "./priceSelector";
|
|
3
|
+
import { applyPriceSelector } from "./priceSelector.ts";
|
|
4
4
|
|
|
5
5
|
describe("priceSelector", () => {
|
|
6
6
|
let product: ProductProjection;
|
package/src/priceSelector.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type {
|
|
|
4
4
|
ProductProjection,
|
|
5
5
|
ProductVariant,
|
|
6
6
|
} from "@commercetools/platform-sdk";
|
|
7
|
-
import { CommercetoolsError } from "./exceptions";
|
|
8
|
-
import type { Writable } from "./types";
|
|
7
|
+
import { CommercetoolsError } from "./exceptions.ts";
|
|
8
|
+
import type { Writable } from "./types.ts";
|
|
9
9
|
|
|
10
10
|
export type PriceSelector = {
|
|
11
11
|
currency?: string;
|
|
@@ -3,30 +3,29 @@ import type {
|
|
|
3
3
|
FilteredFacetResult,
|
|
4
4
|
InvalidInputError,
|
|
5
5
|
Product,
|
|
6
|
-
ProductData,
|
|
7
6
|
ProductProjection,
|
|
8
7
|
ProductProjectionPagedSearchResponse,
|
|
9
8
|
QueryParam,
|
|
10
9
|
RangeFacetResult,
|
|
11
10
|
TermFacetResult,
|
|
12
11
|
} from "@commercetools/platform-sdk";
|
|
13
|
-
import type { Config } from "./config";
|
|
14
|
-
import { CommercetoolsError } from "./exceptions";
|
|
15
|
-
import { nestedLookup } from "./helpers";
|
|
12
|
+
import type { Config } from "./config.ts";
|
|
13
|
+
import { CommercetoolsError } from "./exceptions.ts";
|
|
14
|
+
import { nestedLookup } from "./helpers.ts";
|
|
16
15
|
import type {
|
|
17
16
|
FilterExpression,
|
|
18
17
|
RangeExpression,
|
|
19
|
-
} from "./lib/projectionSearchFilter";
|
|
18
|
+
} from "./lib/projectionSearchFilter.ts";
|
|
20
19
|
import {
|
|
21
20
|
generateFacetFunc,
|
|
22
21
|
getVariants,
|
|
23
22
|
parseFilterExpression,
|
|
24
23
|
resolveVariantValue,
|
|
25
|
-
} from "./lib/projectionSearchFilter";
|
|
26
|
-
import { ReviewStatisticsService } from "./lib/review-statistics";
|
|
27
|
-
import { applyPriceSelector } from "./priceSelector";
|
|
28
|
-
import type { AbstractStorage } from "./storage";
|
|
29
|
-
import type { Writable } from "./types";
|
|
24
|
+
} from "./lib/projectionSearchFilter.ts";
|
|
25
|
+
import { ReviewStatisticsService } from "./lib/review-statistics.ts";
|
|
26
|
+
import { applyPriceSelector } from "./priceSelector.ts";
|
|
27
|
+
import type { AbstractStorage } from "./storage/index.ts";
|
|
28
|
+
import type { Writable } from "./types.ts";
|
|
30
29
|
|
|
31
30
|
export type ProductProjectionSearchParams = {
|
|
32
31
|
fuzzy?: boolean;
|
|
@@ -94,7 +93,6 @@ export class ProductProjectionSearch {
|
|
|
94
93
|
filters.every((f) => f(resource, markMatchingVariant)),
|
|
95
94
|
);
|
|
96
95
|
} catch (err) {
|
|
97
|
-
console.error(err);
|
|
98
96
|
throw new CommercetoolsError<InvalidInputError>(
|
|
99
97
|
{
|
|
100
98
|
code: "InvalidInput",
|
|
@@ -364,7 +362,7 @@ export class ProductProjectionSearch {
|
|
|
364
362
|
}) || [];
|
|
365
363
|
const data: RangeFacetResult = {
|
|
366
364
|
type: "range",
|
|
367
|
-
// @ts-
|
|
365
|
+
// @ts-expect-error
|
|
368
366
|
dataType: "number",
|
|
369
367
|
ranges: counts,
|
|
370
368
|
};
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from "@commercetools/platform-sdk";
|
|
7
7
|
import supertest from "supertest";
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
9
|
-
import { CommercetoolsMock } from "./index";
|
|
9
|
+
import { CommercetoolsMock } from "./index.ts";
|
|
10
10
|
|
|
11
11
|
describe("Product Search - Availability Filtering", () => {
|
|
12
12
|
const ctMock = new CommercetoolsMock();
|
package/src/product-search.ts
CHANGED
|
@@ -6,12 +6,12 @@ import type {
|
|
|
6
6
|
ProductSearchRequest,
|
|
7
7
|
ProductSearchResult,
|
|
8
8
|
} from "@commercetools/platform-sdk";
|
|
9
|
-
import type { Config } from "./config";
|
|
10
|
-
import { CommercetoolsError } from "./exceptions";
|
|
11
|
-
import { parseSearchQuery } from "./lib/productSearchFilter";
|
|
12
|
-
import { validateSearchQuery } from "./lib/searchQueryTypeChecker";
|
|
13
|
-
import { applyPriceSelector } from "./priceSelector";
|
|
14
|
-
import type { AbstractStorage } from "./storage";
|
|
9
|
+
import type { Config } from "./config.ts";
|
|
10
|
+
import { CommercetoolsError } from "./exceptions.ts";
|
|
11
|
+
import { parseSearchQuery } from "./lib/productSearchFilter.ts";
|
|
12
|
+
import { validateSearchQuery } from "./lib/searchQueryTypeChecker.ts";
|
|
13
|
+
import { applyPriceSelector } from "./priceSelector.ts";
|
|
14
|
+
import type { AbstractStorage } from "./storage/index.ts";
|
|
15
15
|
|
|
16
16
|
interface ProductSearchVariantAvailability {
|
|
17
17
|
isOnStock: boolean;
|
|
@@ -78,7 +78,6 @@ export class ProductSearch {
|
|
|
78
78
|
matchFunc(resource, markMatchingVariant),
|
|
79
79
|
);
|
|
80
80
|
} catch (err) {
|
|
81
|
-
console.error(err);
|
|
82
81
|
throw new CommercetoolsError<InvalidInputError>(
|
|
83
82
|
{
|
|
84
83
|
code: "InvalidInput",
|