@labdigital/commercetools-mock 2.36.0 → 2.38.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.cjs +273 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +273 -89
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
- package/src/ctMock.ts +10 -6
- package/src/helpers.ts +4 -4
- package/src/index.ts +2 -1
- package/src/lib/expandParser.ts +1 -1
- package/src/lib/haversine.test.ts +2 -1
- package/src/lib/password.ts +2 -2
- package/src/lib/predicateParser.ts +1 -1
- package/src/lib/productSearchFilter.test.ts +4 -1
- package/src/lib/projectionSearchFilter.ts +3 -3
- package/src/oauth/helpers.ts +1 -1
- package/src/oauth/server.test.ts +44 -1
- package/src/oauth/server.ts +49 -15
- package/src/oauth/store.ts +1 -1
- package/src/priceSelector.ts +1 -1
- package/src/product-projection-search.ts +4 -2
- package/src/product-search.ts +2 -2
- package/src/projectAPI.ts +4 -4
- package/src/repositories/abstract.ts +20 -3
- package/src/repositories/associate-role.ts +3 -3
- package/src/repositories/attribute-group.ts +3 -3
- package/src/repositories/business-unit.ts +6 -4
- package/src/repositories/cart/actions.ts +6 -7
- package/src/repositories/cart/helpers.ts +1 -1
- package/src/repositories/cart/index.ts +1 -1
- package/src/repositories/cart-discount/actions.ts +2 -5
- package/src/repositories/cart-discount/index.ts +1 -1
- package/src/repositories/category/actions.ts +4 -7
- package/src/repositories/category/index.ts +3 -3
- package/src/repositories/channel.ts +2 -2
- package/src/repositories/custom-object.ts +3 -6
- package/src/repositories/customer/actions.ts +272 -68
- package/src/repositories/customer/index.ts +10 -8
- package/src/repositories/customer-group.ts +2 -2
- package/src/repositories/discount-code/actions.ts +2 -5
- package/src/repositories/discount-code/index.ts +1 -1
- package/src/repositories/extension.ts +3 -3
- package/src/repositories/helpers.ts +4 -2
- package/src/repositories/index.ts +1 -1
- package/src/repositories/inventory-entry/actions.ts +2 -5
- package/src/repositories/inventory-entry/index.ts +1 -1
- package/src/repositories/my-customer.ts +2 -2
- package/src/repositories/order/actions.ts +2 -5
- package/src/repositories/order/index.ts +3 -6
- package/src/repositories/order-edit.ts +3 -2
- package/src/repositories/payment/actions.ts +2 -5
- package/src/repositories/payment/helpers.ts +6 -3
- package/src/repositories/payment/index.ts +3 -2
- package/src/repositories/product/actions.ts +2 -2
- package/src/repositories/product/helpers.ts +4 -4
- package/src/repositories/product/index.ts +3 -2
- package/src/repositories/product-discount.ts +3 -7
- package/src/repositories/product-projection.ts +2 -5
- package/src/repositories/product-selection.ts +3 -7
- package/src/repositories/product-tailoring.ts +3 -7
- package/src/repositories/product-type.ts +7 -11
- package/src/repositories/project.ts +30 -9
- package/src/repositories/quote-request.ts +3 -2
- package/src/repositories/quote.ts +3 -2
- package/src/repositories/review.ts +6 -3
- package/src/repositories/shipping-method/actions.ts +5 -6
- package/src/repositories/shipping-method/helpers.ts +4 -1
- package/src/repositories/shipping-method/index.ts +3 -6
- package/src/repositories/shopping-list/actions.ts +3 -6
- package/src/repositories/shopping-list/index.ts +4 -3
- package/src/repositories/staged-quote.ts +3 -2
- package/src/repositories/standalone-price.ts +3 -7
- package/src/repositories/state.ts +3 -7
- package/src/repositories/store.ts +3 -7
- package/src/repositories/subscription.ts +4 -8
- package/src/repositories/tax-category/actions.ts +2 -1
- package/src/repositories/tax-category/helpers.ts +1 -1
- package/src/repositories/tax-category/index.ts +3 -2
- package/src/repositories/type/actions.ts +2 -1
- package/src/repositories/type/index.ts +3 -2
- package/src/repositories/zone.ts +3 -7
- package/src/services/abstract.ts +2 -2
- package/src/services/associate-roles.test.ts +1 -1
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +1 -1
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.test.ts +1 -1
- package/src/services/cart-discount.ts +2 -2
- package/src/services/category.ts +2 -2
- package/src/services/channel.ts +2 -2
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +422 -132
- package/src/services/customer.ts +4 -3
- package/src/services/discount-code.ts +2 -2
- package/src/services/extension.ts +2 -2
- package/src/services/index.ts +1 -1
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.ts +1 -1
- package/src/services/my-cart.ts +3 -2
- package/src/services/my-customer.ts +4 -3
- package/src/services/my-order.ts +1 -1
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.ts +2 -2
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +1 -1
- package/src/services/product-projection.ts +2 -2
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +2 -2
- package/src/services/project.test.ts +6 -0
- package/src/services/project.ts +3 -3
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.ts +2 -2
- package/src/services/shopping-list.test.ts +1 -1
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.ts +2 -2
- package/src/services/store.ts +2 -2
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.ts +2 -2
- package/src/services/zone.ts +2 -2
- package/src/shipping.test.ts +1 -1
- package/src/shipping.ts +3 -3
- package/src/storage/abstract.ts +5 -1
- package/src/storage/in-memory.ts +12 -8
- package/src/types.ts +2 -2
- package/src/validate.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labdigital/commercetools-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.38.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michael van Tellingen",
|
|
6
6
|
"type": "module",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"body-parser": "^1.20.2",
|
|
24
24
|
"decimal.js": "10.4.3",
|
|
25
25
|
"deep-equal": "^2.2.3",
|
|
26
|
-
"express": "^4.
|
|
26
|
+
"express": "^4.21.1",
|
|
27
27
|
"light-my-request": "^5.11.1",
|
|
28
28
|
"lodash.isequal": "^4.5.0",
|
|
29
29
|
"morgan": "^1.10.0",
|
|
30
|
-
"msw": "^2.
|
|
30
|
+
"msw": "^2.5.0",
|
|
31
31
|
"uuid": "^9.0.1",
|
|
32
32
|
"zod": "^3.22.4",
|
|
33
33
|
"zod-validation-error": "^3.0.2"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@changesets/changelog-github": "^0.5.0",
|
|
37
37
|
"@changesets/cli": "^2.27.1",
|
|
38
|
-
"@commercetools/platform-sdk": "7.
|
|
38
|
+
"@commercetools/platform-sdk": "7.17.0",
|
|
39
39
|
"@stylistic/eslint-plugin": "^1.6.2",
|
|
40
40
|
"@types/basic-auth": "^1.1.8",
|
|
41
41
|
"@types/body-parser": "^1.19.5",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/express-serve-static-core": "^4.17.43",
|
|
45
45
|
"@types/lodash.isequal": "^4.5.8",
|
|
46
46
|
"@types/morgan": "^1.9.9",
|
|
47
|
-
"@types/node": "^20.
|
|
47
|
+
"@types/node": "^20.16.14",
|
|
48
48
|
"@types/qs": "^6.9.11",
|
|
49
49
|
"@types/supertest": "^6.0.2",
|
|
50
50
|
"@types/uuid": "^9.0.8",
|
|
@@ -52,20 +52,21 @@
|
|
|
52
52
|
"@typescript-eslint/parser": "^7.0.2",
|
|
53
53
|
"@vitest/coverage-v8": "^1.5.0",
|
|
54
54
|
"esbuild": "^0.20.1",
|
|
55
|
-
"eslint": "^8.57.
|
|
56
|
-
"eslint-plugin-sort-class-members": "^1.
|
|
55
|
+
"eslint": "^8.57.1",
|
|
56
|
+
"eslint-plugin-sort-class-members": "^1.21.0",
|
|
57
57
|
"eslint-plugin-unused-imports": "^3.1.0",
|
|
58
|
+
"fishery": "^2.2.2",
|
|
58
59
|
"got": "^14.2.0",
|
|
59
60
|
"husky": "^9.0.11",
|
|
60
61
|
"prettier": "^3.2.5",
|
|
61
62
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
62
|
-
"prettier-plugin-packagejson": "^2.
|
|
63
|
+
"prettier-plugin-packagejson": "^2.5.3",
|
|
63
64
|
"supertest": "^6.3.4",
|
|
64
65
|
"timekeeper": "^2.3.1",
|
|
65
66
|
"ts-node": "^10.9.2",
|
|
66
|
-
"tslib": "^2.
|
|
67
|
+
"tslib": "^2.8.0",
|
|
67
68
|
"tsup": "^8.0.2",
|
|
68
|
-
"typescript": "^5.
|
|
69
|
+
"typescript": "^5.6.3",
|
|
69
70
|
"vitest": "^1.5.0"
|
|
70
71
|
},
|
|
71
72
|
"engines": {
|
package/src/ctMock.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { NextFunction, Request, Response } from "express";
|
|
2
|
+
import express from "express";
|
|
2
3
|
import inject from "light-my-request";
|
|
3
4
|
import morgan from "morgan";
|
|
4
5
|
import { http, HttpResponse } from "msw";
|
|
5
|
-
import {
|
|
6
|
+
import type { SetupServer, SetupServerApi } from "msw/node";
|
|
7
|
+
import { setupServer } from "msw/node";
|
|
6
8
|
import { DEFAULT_API_HOSTNAME, DEFAULT_AUTH_HOSTNAME } from "./constants";
|
|
7
9
|
import { CommercetoolsError } from "./exceptions";
|
|
8
10
|
import { copyHeaders } from "./lib/proxy";
|
|
9
11
|
import { OAuth2Server } from "./oauth/server";
|
|
10
12
|
import { ProjectAPI } from "./projectAPI";
|
|
11
|
-
import { AbstractStorage
|
|
12
|
-
import {
|
|
13
|
+
import type { AbstractStorage } from "./storage";
|
|
14
|
+
import { InMemoryStorage } from "./storage";
|
|
15
|
+
import type { Services } from "./types";
|
|
13
16
|
|
|
14
17
|
// Services
|
|
15
18
|
import { warnDeprecation } from "./deprecation";
|
|
16
19
|
import { mapHeaderType } from "./helpers";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
20
|
+
import type { RepositoryMap } from "./repositories";
|
|
21
|
+
import { createRepositories } from "./repositories";
|
|
22
|
+
import type { ProjectRepository } from "./repositories/project";
|
|
19
23
|
import { createServices } from "./services";
|
|
20
24
|
import { ProjectService } from "./services/project";
|
|
21
25
|
|
package/src/helpers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OutgoingHttpHeaders } from "node:http";
|
|
2
|
-
import { ParsedQs } from "qs";
|
|
1
|
+
import type { OutgoingHttpHeaders } from "node:http";
|
|
2
|
+
import type { ParsedQs } from "qs";
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
4
|
|
|
5
5
|
export const getBaseResourceProperties = () => ({
|
|
@@ -23,7 +23,7 @@ export const nestedLookup = (obj: any, path: string): any => {
|
|
|
23
23
|
|
|
24
24
|
for (let i = 0; i < parts.length; i++) {
|
|
25
25
|
const part = parts[i];
|
|
26
|
-
if (val
|
|
26
|
+
if (val === undefined) {
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -36,7 +36,7 @@ export const nestedLookup = (obj: any, path: string): any => {
|
|
|
36
36
|
export const queryParamsArray = (
|
|
37
37
|
input: string | ParsedQs | string[] | ParsedQs[] | undefined,
|
|
38
38
|
): string[] | undefined => {
|
|
39
|
-
if (input
|
|
39
|
+
if (input === undefined) {
|
|
40
40
|
return undefined;
|
|
41
41
|
}
|
|
42
42
|
|
package/src/index.ts
CHANGED
package/src/lib/expandParser.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const parseExpandClause = (clause: string): ExpandResult => {
|
|
|
27
27
|
|
|
28
28
|
const match = result.element.match(/\[([^\]+])]/);
|
|
29
29
|
if (match) {
|
|
30
|
-
result.index = match[1] === "*" ? "*" : parseInt(match[1], 10);
|
|
30
|
+
result.index = match[1] === "*" ? "*" : Number.parseInt(match[1], 10);
|
|
31
31
|
result.element = result.element.substring(0, match.index);
|
|
32
32
|
}
|
|
33
33
|
return result;
|
package/src/lib/password.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Customer } from "@commercetools/platform-sdk";
|
|
1
|
+
import type { Customer } from "@commercetools/platform-sdk";
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
|
|
4
4
|
const PWRESET_SECRET = "pwreset";
|
|
@@ -31,7 +31,7 @@ export const validatePasswordResetToken = (token: string) => {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Check if the token is expired
|
|
34
|
-
if (parseInt(time) < new Date().getTime()) {
|
|
34
|
+
if (Number.parseInt(time) < new Date().getTime()) {
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -399,7 +399,7 @@ const generateMatchFunc = (predicate: string): MatchFunc => {
|
|
|
399
399
|
const value = resolveValue(obj, left);
|
|
400
400
|
const other = resolveSymbol(expr, vars);
|
|
401
401
|
|
|
402
|
-
if (typeof value
|
|
402
|
+
if (typeof value !== "string") {
|
|
403
403
|
throw new PredicateError(
|
|
404
404
|
`The field '${left.value}' does not support this expression.`,
|
|
405
405
|
);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
ProductProjection,
|
|
3
|
+
_SearchQuery,
|
|
4
|
+
} from "@commercetools/platform-sdk";
|
|
2
5
|
import { describe, expect, test } from "vitest";
|
|
3
6
|
import { cloneObject } from "~src/helpers";
|
|
4
7
|
import { parseSearchQuery } from "./productSearchFilter";
|
|
@@ -113,12 +113,12 @@ const parseFilter = (filter: string): ExpressionSet => {
|
|
|
113
113
|
// Convert plain symbols to a filter expression. For example
|
|
114
114
|
// variants.attribute.foobar:4 where 4 is a Symbol should result
|
|
115
115
|
// in a comparison
|
|
116
|
-
if (expressions.some((expr) => expr.type
|
|
116
|
+
if (expressions.some((expr) => expr.type === "Symbol")) {
|
|
117
117
|
return {
|
|
118
118
|
source: left as string,
|
|
119
119
|
type: "FilterExpression",
|
|
120
120
|
children: expressions.map((e): FilterExpression => {
|
|
121
|
-
if (e.type
|
|
121
|
+
if (e.type !== "Symbol") {
|
|
122
122
|
throw new Error("Invalid expression");
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -245,7 +245,7 @@ const generateMatchFunc = (filter: string) => {
|
|
|
245
245
|
// const column = lines[lines.length - 1].length
|
|
246
246
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
247
247
|
}
|
|
248
|
-
if (result.type
|
|
248
|
+
if (result.type === "TermExpression") {
|
|
249
249
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
250
250
|
}
|
|
251
251
|
|
package/src/oauth/helpers.ts
CHANGED
package/src/oauth/server.test.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
4
4
|
import { getBaseResourceProperties } from "../helpers";
|
|
5
5
|
import { hashPassword } from "../lib/password";
|
|
6
6
|
import { CustomerRepository } from "../repositories/customer";
|
|
7
|
-
import { AbstractStorage
|
|
7
|
+
import type { AbstractStorage } from "../storage";
|
|
8
|
+
import { InMemoryStorage } from "../storage";
|
|
8
9
|
import { OAuth2Server } from "./server";
|
|
9
10
|
|
|
10
11
|
describe("OAuth2Server", () => {
|
|
@@ -130,4 +131,46 @@ describe("OAuth2Server", () => {
|
|
|
130
131
|
});
|
|
131
132
|
});
|
|
132
133
|
});
|
|
134
|
+
|
|
135
|
+
describe("POST /:projectKey/in-store/key=:storeKey/customers/token", () => {
|
|
136
|
+
it("should return a token for in-store customer access", async () => {
|
|
137
|
+
const projectKey = "test-project";
|
|
138
|
+
const storeKey = "test-store";
|
|
139
|
+
|
|
140
|
+
storage.add(projectKey, "customer", {
|
|
141
|
+
...getBaseResourceProperties(),
|
|
142
|
+
email: "j.doe@example.org",
|
|
143
|
+
password: hashPassword("password"),
|
|
144
|
+
addresses: [],
|
|
145
|
+
authenticationMode: "password",
|
|
146
|
+
isEmailVerified: true,
|
|
147
|
+
stores: [
|
|
148
|
+
{
|
|
149
|
+
typeId: "store",
|
|
150
|
+
key: storeKey,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const response = await supertest(app)
|
|
156
|
+
.post(`/${projectKey}/in-store/key=${storeKey}/customers/token`)
|
|
157
|
+
.auth("validClientId", "validClientSecret")
|
|
158
|
+
.query({
|
|
159
|
+
grant_type: "password",
|
|
160
|
+
username: "j.doe@example.org",
|
|
161
|
+
password: "password",
|
|
162
|
+
scope: `${projectKey}:manage_my_profile`,
|
|
163
|
+
})
|
|
164
|
+
.send();
|
|
165
|
+
|
|
166
|
+
expect(response.status).toBe(200);
|
|
167
|
+
expect(response.body).toEqual({
|
|
168
|
+
scope: expect.stringMatching(/customer_id:([^\s]+)/),
|
|
169
|
+
access_token: expect.stringMatching(/\S{8,}==$/),
|
|
170
|
+
refresh_token: expect.stringMatching(/test-project:\S{8,}==$/),
|
|
171
|
+
expires_in: 172800,
|
|
172
|
+
token_type: "Bearer",
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
133
176
|
});
|
package/src/oauth/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InvalidTokenError } from "@commercetools/platform-sdk";
|
|
1
|
+
import type { InvalidTokenError } from "@commercetools/platform-sdk";
|
|
2
2
|
import auth from "basic-auth";
|
|
3
3
|
import bodyParser from "body-parser";
|
|
4
4
|
import express, {
|
|
@@ -6,14 +6,11 @@ import express, {
|
|
|
6
6
|
type Request,
|
|
7
7
|
type Response,
|
|
8
8
|
} from "express";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
CommercetoolsError,
|
|
12
|
-
InvalidRequestError,
|
|
13
|
-
} from "~src/exceptions";
|
|
9
|
+
import type { AuthError, InvalidRequestError } from "~src/exceptions";
|
|
10
|
+
import { CommercetoolsError } from "~src/exceptions";
|
|
14
11
|
import { hashPassword } from "../lib/password";
|
|
15
|
-
import { CustomerRepository } from "../repositories/customer";
|
|
16
|
-
import { InvalidClientError, UnsupportedGrantType } from "./errors";
|
|
12
|
+
import type { CustomerRepository } from "../repositories/customer";
|
|
13
|
+
import type { InvalidClientError, UnsupportedGrantType } from "./errors";
|
|
17
14
|
import { getBearerToken } from "./helpers";
|
|
18
15
|
import { OAuth2Store } from "./store";
|
|
19
16
|
|
|
@@ -287,15 +284,52 @@ export class OAuth2Server {
|
|
|
287
284
|
response: Response,
|
|
288
285
|
next: NextFunction,
|
|
289
286
|
) {
|
|
290
|
-
|
|
291
|
-
|
|
287
|
+
const projectKey = request.params.projectKey;
|
|
288
|
+
const storeKey = request.params.storeKey;
|
|
289
|
+
const grantType = request.query.grant_type || request.body.grant_type;
|
|
290
|
+
if (!grantType) {
|
|
291
|
+
return next(
|
|
292
|
+
new CommercetoolsError<InvalidRequestError>(
|
|
293
|
+
{
|
|
294
|
+
code: "invalid_request",
|
|
295
|
+
message: "Missing required parameter: grant_type.",
|
|
296
|
+
},
|
|
297
|
+
400,
|
|
298
|
+
),
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (grantType === "password") {
|
|
303
|
+
const username = request.query.username || request.body.username;
|
|
304
|
+
const password = hashPassword(
|
|
305
|
+
request.query.password || request.body.password,
|
|
306
|
+
);
|
|
307
|
+
const scope =
|
|
308
|
+
request.query.scope?.toString() || request.body.scope?.toString();
|
|
309
|
+
|
|
310
|
+
const result = this.customerRepository.query(
|
|
311
|
+
{ projectKey, storeKey },
|
|
292
312
|
{
|
|
293
|
-
|
|
294
|
-
message: "Not implemented yet in commercetools-mock",
|
|
313
|
+
where: [`email = "${username}"`, `password = "${password}"`],
|
|
295
314
|
},
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
if (result.count === 0) {
|
|
318
|
+
return next(
|
|
319
|
+
new CommercetoolsError<any>(
|
|
320
|
+
{
|
|
321
|
+
code: "invalid_customer_account_credentials",
|
|
322
|
+
message: "Customer account with the given credentials not found.",
|
|
323
|
+
},
|
|
324
|
+
400,
|
|
325
|
+
),
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const customer = result.results[0];
|
|
330
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
331
|
+
return response.status(200).send(token);
|
|
332
|
+
}
|
|
299
333
|
}
|
|
300
334
|
|
|
301
335
|
async anonymousTokenHandler(
|
package/src/oauth/store.ts
CHANGED
package/src/priceSelector.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const applyPriceSelector = (
|
|
|
31
31
|
const variants: Writable<ProductVariant>[] = [
|
|
32
32
|
product.masterVariant,
|
|
33
33
|
...(product.variants ?? []),
|
|
34
|
-
].filter((x) => x
|
|
34
|
+
].filter((x) => x !== undefined);
|
|
35
35
|
|
|
36
36
|
for (const variant of variants) {
|
|
37
37
|
const scopedPrices =
|
|
@@ -11,16 +11,18 @@ import type {
|
|
|
11
11
|
} from "@commercetools/platform-sdk";
|
|
12
12
|
import { CommercetoolsError } from "./exceptions";
|
|
13
13
|
import { nestedLookup } from "./helpers";
|
|
14
|
-
import {
|
|
14
|
+
import type {
|
|
15
15
|
FilterExpression,
|
|
16
16
|
RangeExpression,
|
|
17
|
+
} from "./lib/projectionSearchFilter";
|
|
18
|
+
import {
|
|
17
19
|
generateFacetFunc,
|
|
18
20
|
getVariants,
|
|
19
21
|
parseFilterExpression,
|
|
20
22
|
resolveVariantValue,
|
|
21
23
|
} from "./lib/projectionSearchFilter";
|
|
22
24
|
import { applyPriceSelector } from "./priceSelector";
|
|
23
|
-
import { AbstractStorage } from "./storage";
|
|
25
|
+
import type { AbstractStorage } from "./storage";
|
|
24
26
|
import type { Writable } from "./types";
|
|
25
27
|
|
|
26
28
|
export type ProductProjectionSearchParams = {
|
package/src/product-search.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
InvalidInputError,
|
|
3
3
|
Product,
|
|
4
4
|
ProductPagedSearchResponse,
|
|
@@ -10,7 +10,7 @@ import { CommercetoolsError } from "./exceptions";
|
|
|
10
10
|
import { parseSearchQuery } from "./lib/productSearchFilter";
|
|
11
11
|
import { validateSearchQuery } from "./lib/searchQueryTypeChecker";
|
|
12
12
|
import { applyPriceSelector } from "./priceSelector";
|
|
13
|
-
import { AbstractStorage } from "./storage";
|
|
13
|
+
import type { AbstractStorage } from "./storage";
|
|
14
14
|
|
|
15
15
|
export class ProductSearch {
|
|
16
16
|
protected _storage: AbstractStorage;
|
package/src/projectAPI.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getBaseResourceProperties } from "./helpers";
|
|
2
|
-
import { RepositoryMap } from "./repositories";
|
|
3
|
-
import { GetParams } from "./repositories/abstract";
|
|
4
|
-
import { AbstractStorage } from "./storage";
|
|
5
|
-
import { ResourceMap, ResourceType } from "./types";
|
|
2
|
+
import type { RepositoryMap } from "./repositories";
|
|
3
|
+
import type { GetParams } from "./repositories/abstract";
|
|
4
|
+
import type { AbstractStorage } from "./storage";
|
|
5
|
+
import type { ResourceMap, ResourceType } from "./types";
|
|
6
6
|
|
|
7
7
|
export class ProjectAPI {
|
|
8
8
|
private projectKey: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
BaseResource,
|
|
3
|
+
InvalidInputError,
|
|
3
4
|
Project,
|
|
4
5
|
QueryParam,
|
|
5
6
|
ResourceNotFoundError,
|
|
@@ -8,8 +9,8 @@ import type {
|
|
|
8
9
|
import deepEqual from "deep-equal";
|
|
9
10
|
import { CommercetoolsError } from "~src/exceptions";
|
|
10
11
|
import { cloneObject } from "../helpers";
|
|
11
|
-
import { AbstractStorage } from "../storage";
|
|
12
|
-
import {
|
|
12
|
+
import type { AbstractStorage } from "../storage";
|
|
13
|
+
import type {
|
|
13
14
|
ResourceMap,
|
|
14
15
|
ResourceType,
|
|
15
16
|
ShallowWritable,
|
|
@@ -74,7 +75,7 @@ export abstract class AbstractRepository<R extends BaseResource | Project> {
|
|
|
74
75
|
|
|
75
76
|
// If all actions succeeded we write the new version
|
|
76
77
|
// to the storage.
|
|
77
|
-
if (resource.version
|
|
78
|
+
if (resource.version !== updatedResource.version) {
|
|
78
79
|
this.saveUpdate(context, version, updatedResource);
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -253,6 +254,22 @@ export class AbstractUpdateHandler {
|
|
|
253
254
|
: (resource as Project).key;
|
|
254
255
|
|
|
255
256
|
for (const action of actions) {
|
|
257
|
+
// Validate if this action exists
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
if (this[action.action] === undefined) {
|
|
260
|
+
console.info(`No handler for action ${action.action}`);
|
|
261
|
+
throw new CommercetoolsError<InvalidInputError>({
|
|
262
|
+
code: "InvalidInput",
|
|
263
|
+
message: `Invalid action ${action.action}`,
|
|
264
|
+
errors: [
|
|
265
|
+
{
|
|
266
|
+
code: "InvalidInput",
|
|
267
|
+
message: `Invalid action ${action.action}`,
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
256
273
|
// @ts-ignore
|
|
257
274
|
const updateFunc = this[action.action].bind(this);
|
|
258
275
|
|
|
@@ -10,12 +10,12 @@ import type {
|
|
|
10
10
|
AssociateRoleUpdateAction,
|
|
11
11
|
} from "@commercetools/platform-sdk";
|
|
12
12
|
import { getBaseResourceProperties } from "../helpers";
|
|
13
|
-
import { AbstractStorage } from "../storage/abstract";
|
|
14
|
-
import { Writable } from "../types";
|
|
13
|
+
import type { AbstractStorage } from "../storage/abstract";
|
|
14
|
+
import type { Writable } from "../types";
|
|
15
|
+
import type { UpdateHandlerInterface } from "./abstract";
|
|
15
16
|
import {
|
|
16
17
|
AbstractResourceRepository,
|
|
17
18
|
AbstractUpdateHandler,
|
|
18
|
-
UpdateHandlerInterface,
|
|
19
19
|
type RepositoryContext,
|
|
20
20
|
} from "./abstract";
|
|
21
21
|
import { createCustomFields } from "./helpers";
|
|
@@ -8,12 +8,12 @@ import type {
|
|
|
8
8
|
AttributeGroupUpdateAction,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
10
|
import { getBaseResourceProperties } from "../helpers";
|
|
11
|
-
import { AbstractStorage } from "../storage/abstract";
|
|
12
|
-
import { Writable } from "../types";
|
|
11
|
+
import type { AbstractStorage } from "../storage/abstract";
|
|
12
|
+
import type { Writable } from "../types";
|
|
13
|
+
import type { UpdateHandlerInterface } from "./abstract";
|
|
13
14
|
import {
|
|
14
15
|
AbstractResourceRepository,
|
|
15
16
|
AbstractUpdateHandler,
|
|
16
|
-
UpdateHandlerInterface,
|
|
17
17
|
type RepositoryContext,
|
|
18
18
|
} from "./abstract";
|
|
19
19
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
BusinessUnitChangeApprovalRuleModeAction,
|
|
3
3
|
BusinessUnitChangeAssociateModeAction,
|
|
4
4
|
BusinessUnitChangeStatusAction,
|
|
5
5
|
BusinessUnitUpdateAction,
|
|
6
6
|
CompanyDraft,
|
|
7
7
|
DivisionDraft,
|
|
8
|
+
} from "@commercetools/platform-sdk";
|
|
9
|
+
import {
|
|
8
10
|
type Associate,
|
|
9
11
|
type BusinessUnit,
|
|
10
12
|
type BusinessUnitAddAddressAction,
|
|
@@ -20,13 +22,13 @@ import {
|
|
|
20
22
|
type Company,
|
|
21
23
|
type Division,
|
|
22
24
|
} from "@commercetools/platform-sdk";
|
|
23
|
-
import { AbstractStorage } from "~src/storage";
|
|
25
|
+
import type { AbstractStorage } from "~src/storage";
|
|
24
26
|
import { generateRandomString, getBaseResourceProperties } from "../helpers";
|
|
25
|
-
import { Writable } from "../types";
|
|
27
|
+
import type { Writable } from "../types";
|
|
28
|
+
import type { UpdateHandlerInterface } from "./abstract";
|
|
26
29
|
import {
|
|
27
30
|
AbstractResourceRepository,
|
|
28
31
|
AbstractUpdateHandler,
|
|
29
|
-
UpdateHandlerInterface,
|
|
30
32
|
type RepositoryContext,
|
|
31
33
|
} from "./abstract";
|
|
32
34
|
import {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CartSetAnonymousIdAction,
|
|
3
3
|
CartSetCustomerIdAction,
|
|
4
4
|
CartUpdateAction,
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
InvalidOperationError,
|
|
7
7
|
MissingTaxRateForCountryError,
|
|
8
8
|
ShippingMethodDoesNotMatchCartError,
|
|
9
|
+
} from "@commercetools/platform-sdk";
|
|
10
|
+
import {
|
|
9
11
|
type Address,
|
|
10
12
|
type AddressDraft,
|
|
11
13
|
type Cart,
|
|
@@ -36,7 +38,7 @@ import {
|
|
|
36
38
|
type ProductPagedQueryResponse,
|
|
37
39
|
type ProductVariant,
|
|
38
40
|
} from "@commercetools/platform-sdk";
|
|
39
|
-
import {
|
|
41
|
+
import type {
|
|
40
42
|
DirectDiscount,
|
|
41
43
|
TaxPortion,
|
|
42
44
|
TaxedItemPrice,
|
|
@@ -46,11 +48,8 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
46
48
|
import { CommercetoolsError } from "~src/exceptions";
|
|
47
49
|
import { getShippingMethodsMatchingCart } from "~src/shipping";
|
|
48
50
|
import type { Writable } from "~src/types";
|
|
49
|
-
import {
|
|
50
|
-
|
|
51
|
-
UpdateHandlerInterface,
|
|
52
|
-
type RepositoryContext,
|
|
53
|
-
} from "../abstract";
|
|
51
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
52
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
54
53
|
import {
|
|
55
54
|
createAddress,
|
|
56
55
|
createCentPrecisionMoney,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { v4 as uuidv4 } from "uuid";
|
|
11
11
|
import { CommercetoolsError } from "~src/exceptions";
|
|
12
12
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
13
|
-
import { AbstractStorage } from "~src/storage/abstract";
|
|
13
|
+
import type { AbstractStorage } from "~src/storage/abstract";
|
|
14
14
|
import type { Writable } from "~src/types";
|
|
15
15
|
import {
|
|
16
16
|
AbstractResourceRepository,
|
|
@@ -14,11 +14,8 @@ import type {
|
|
|
14
14
|
InvalidOperationError,
|
|
15
15
|
} from "@commercetools/platform-sdk";
|
|
16
16
|
import type { Writable } from "~src/types";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
UpdateHandlerInterface,
|
|
20
|
-
type RepositoryContext,
|
|
21
|
-
} from "../abstract";
|
|
17
|
+
import type { UpdateHandlerInterface } from "../abstract";
|
|
18
|
+
import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
|
|
22
19
|
|
|
23
20
|
import { CommercetoolsError } from "~src/exceptions";
|
|
24
21
|
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
CartDiscountValueRelative,
|
|
9
9
|
} from "@commercetools/platform-sdk";
|
|
10
10
|
import { getBaseResourceProperties } from "~src/helpers";
|
|
11
|
-
import { AbstractStorage } from "~src/storage/abstract";
|
|
11
|
+
import type { AbstractStorage } from "~src/storage/abstract";
|
|
12
12
|
import {
|
|
13
13
|
AbstractResourceRepository,
|
|
14
14
|
type RepositoryContext,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Asset,
|
|
3
3
|
AssetDraft,
|
|
4
4
|
Category,
|
|
@@ -20,12 +20,9 @@ import {
|
|
|
20
20
|
CategoryUpdateAction,
|
|
21
21
|
} from "@commercetools/platform-sdk";
|
|
22
22
|
import { v4 as uuidv4 } from "uuid";
|
|
23
|
-
import { Writable } from "~src/types";
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
RepositoryContext,
|
|
27
|
-
UpdateHandlerInterface,
|
|
28
|
-
} from "../abstract";
|
|
23
|
+
import type { Writable } from "~src/types";
|
|
24
|
+
import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
|
|
25
|
+
import { AbstractUpdateHandler } from "../abstract";
|
|
29
26
|
import { createCustomFields } from "../helpers";
|
|
30
27
|
|
|
31
28
|
export class CategoryUpdateHandler
|