@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/dist/index.cjs
CHANGED
|
@@ -93,7 +93,7 @@ var validatePasswordResetToken = (token) => {
|
|
|
93
93
|
if (secret !== PWRESET_SECRET) {
|
|
94
94
|
return void 0;
|
|
95
95
|
}
|
|
96
|
-
if (parseInt(time) < (/* @__PURE__ */ new Date()).getTime()) {
|
|
96
|
+
if (Number.parseInt(time) < (/* @__PURE__ */ new Date()).getTime()) {
|
|
97
97
|
return void 0;
|
|
98
98
|
}
|
|
99
99
|
return customerId;
|
|
@@ -118,7 +118,7 @@ var getBearerToken = (request) => {
|
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
// src/oauth/store.ts
|
|
121
|
-
var
|
|
121
|
+
var import_node_crypto = require("crypto");
|
|
122
122
|
var import_uuid2 = require("uuid");
|
|
123
123
|
var OAuth2Store = class {
|
|
124
124
|
tokens = [];
|
|
@@ -131,11 +131,11 @@ var OAuth2Store = class {
|
|
|
131
131
|
}
|
|
132
132
|
getClientToken(clientId, clientSecret, scope) {
|
|
133
133
|
const token = {
|
|
134
|
-
access_token: (0,
|
|
134
|
+
access_token: (0, import_node_crypto.randomBytes)(16).toString("base64"),
|
|
135
135
|
token_type: "Bearer",
|
|
136
136
|
expires_in: 172800,
|
|
137
137
|
scope: scope || "todo",
|
|
138
|
-
refresh_token: `my-project-${(0,
|
|
138
|
+
refresh_token: `my-project-${(0, import_node_crypto.randomBytes)(16).toString("base64")}`
|
|
139
139
|
};
|
|
140
140
|
this.addToken(token);
|
|
141
141
|
return token;
|
|
@@ -145,22 +145,22 @@ var OAuth2Store = class {
|
|
|
145
145
|
anonymousId = (0, import_uuid2.v4)();
|
|
146
146
|
}
|
|
147
147
|
const token = {
|
|
148
|
-
access_token: (0,
|
|
148
|
+
access_token: (0, import_node_crypto.randomBytes)(16).toString("base64"),
|
|
149
149
|
token_type: "Bearer",
|
|
150
150
|
expires_in: 172800,
|
|
151
151
|
scope: scope ? `${scope} anonymous_id:${anonymousId}` : `anonymous_id:${anonymousId}`,
|
|
152
|
-
refresh_token: `${projectKey}:${(0,
|
|
152
|
+
refresh_token: `${projectKey}:${(0, import_node_crypto.randomBytes)(16).toString("base64")}`
|
|
153
153
|
};
|
|
154
154
|
this.addToken(token);
|
|
155
155
|
return token;
|
|
156
156
|
}
|
|
157
157
|
getCustomerToken(projectKey, customerId, scope) {
|
|
158
158
|
const token = {
|
|
159
|
-
access_token: (0,
|
|
159
|
+
access_token: (0, import_node_crypto.randomBytes)(16).toString("base64"),
|
|
160
160
|
token_type: "Bearer",
|
|
161
161
|
expires_in: 172800,
|
|
162
162
|
scope: scope ? `${scope} customer_id:${customerId}` : `customer_id:${customerId}`,
|
|
163
|
-
refresh_token: `${projectKey}:${(0,
|
|
163
|
+
refresh_token: `${projectKey}:${(0, import_node_crypto.randomBytes)(16).toString("base64")}`
|
|
164
164
|
};
|
|
165
165
|
this.addToken(token);
|
|
166
166
|
return token;
|
|
@@ -172,7 +172,7 @@ var OAuth2Store = class {
|
|
|
172
172
|
}
|
|
173
173
|
const token = {
|
|
174
174
|
...existing,
|
|
175
|
-
access_token: (0,
|
|
175
|
+
access_token: (0, import_node_crypto.randomBytes)(16).toString("base64")
|
|
176
176
|
};
|
|
177
177
|
this.addToken(token);
|
|
178
178
|
return {
|
|
@@ -404,15 +404,47 @@ var OAuth2Server = class {
|
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
async inStoreCustomerTokenHandler(request, response, next) {
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
const projectKey = request.params.projectKey;
|
|
408
|
+
const storeKey = request.params.storeKey;
|
|
409
|
+
const grantType = request.query.grant_type || request.body.grant_type;
|
|
410
|
+
if (!grantType) {
|
|
411
|
+
return next(
|
|
412
|
+
new CommercetoolsError(
|
|
413
|
+
{
|
|
414
|
+
code: "invalid_request",
|
|
415
|
+
message: "Missing required parameter: grant_type."
|
|
416
|
+
},
|
|
417
|
+
400
|
|
418
|
+
)
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
if (grantType === "password") {
|
|
422
|
+
const username = request.query.username || request.body.username;
|
|
423
|
+
const password = hashPassword(
|
|
424
|
+
request.query.password || request.body.password
|
|
425
|
+
);
|
|
426
|
+
const scope = request.query.scope?.toString() || request.body.scope?.toString();
|
|
427
|
+
const result = this.customerRepository.query(
|
|
428
|
+
{ projectKey, storeKey },
|
|
409
429
|
{
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
430
|
+
where: [`email = "${username}"`, `password = "${password}"`]
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
if (result.count === 0) {
|
|
434
|
+
return next(
|
|
435
|
+
new CommercetoolsError(
|
|
436
|
+
{
|
|
437
|
+
code: "invalid_customer_account_credentials",
|
|
438
|
+
message: "Customer account with the given credentials not found."
|
|
439
|
+
},
|
|
440
|
+
400
|
|
441
|
+
)
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const customer = result.results[0];
|
|
445
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
446
|
+
return response.status(200).send(token);
|
|
447
|
+
}
|
|
416
448
|
}
|
|
417
449
|
async anonymousTokenHandler(request, response, next) {
|
|
418
450
|
const projectKey = request.params.projectKey;
|
|
@@ -457,7 +489,7 @@ var nestedLookup = (obj, path) => {
|
|
|
457
489
|
let val = obj;
|
|
458
490
|
for (let i = 0; i < parts.length; i++) {
|
|
459
491
|
const part = parts[i];
|
|
460
|
-
if (val
|
|
492
|
+
if (val === void 0) {
|
|
461
493
|
return void 0;
|
|
462
494
|
}
|
|
463
495
|
val = val[part];
|
|
@@ -465,7 +497,7 @@ var nestedLookup = (obj, path) => {
|
|
|
465
497
|
return val;
|
|
466
498
|
};
|
|
467
499
|
var queryParamsArray = (input) => {
|
|
468
|
-
if (input
|
|
500
|
+
if (input === void 0) {
|
|
469
501
|
return void 0;
|
|
470
502
|
}
|
|
471
503
|
const values = Array.isArray(input) ? input : [input];
|
|
@@ -564,7 +596,7 @@ var parseExpandClause = (clause) => {
|
|
|
564
596
|
}
|
|
565
597
|
const match = result.element.match(/\[([^\]+])]/);
|
|
566
598
|
if (match) {
|
|
567
|
-
result.index = match[1] === "*" ? "*" : parseInt(match[1], 10);
|
|
599
|
+
result.index = match[1] === "*" ? "*" : Number.parseInt(match[1], 10);
|
|
568
600
|
result.element = result.element.substring(0, match.index);
|
|
569
601
|
}
|
|
570
602
|
return result;
|
|
@@ -1348,7 +1380,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
1348
1380
|
return (obj, vars) => {
|
|
1349
1381
|
const value = resolveValue(obj, left);
|
|
1350
1382
|
const other = resolveSymbol(expr, vars);
|
|
1351
|
-
if (typeof value
|
|
1383
|
+
if (typeof value !== "string") {
|
|
1352
1384
|
throw new PredicateError(
|
|
1353
1385
|
`The field '${left.value}' does not support this expression.`
|
|
1354
1386
|
);
|
|
@@ -1437,8 +1469,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1437
1469
|
products: {
|
|
1438
1470
|
status: "Deactivated"
|
|
1439
1471
|
},
|
|
1472
|
+
productsSearch: {
|
|
1473
|
+
status: "Deactivated"
|
|
1474
|
+
},
|
|
1440
1475
|
orders: {
|
|
1441
1476
|
status: "Deactivated"
|
|
1477
|
+
},
|
|
1478
|
+
customers: {
|
|
1479
|
+
status: "Deactivated"
|
|
1442
1480
|
}
|
|
1443
1481
|
},
|
|
1444
1482
|
version: 1
|
|
@@ -1780,7 +1818,7 @@ var AbstractRepository = class {
|
|
|
1780
1818
|
version,
|
|
1781
1819
|
actions
|
|
1782
1820
|
);
|
|
1783
|
-
if (resource.version
|
|
1821
|
+
if (resource.version !== updatedResource.version) {
|
|
1784
1822
|
this.saveUpdate(context, version, updatedResource);
|
|
1785
1823
|
}
|
|
1786
1824
|
const result = this.postProcessResource(context, updatedResource);
|
|
@@ -1887,6 +1925,19 @@ var AbstractUpdateHandler = class {
|
|
|
1887
1925
|
const updatedResource = cloneObject(resource);
|
|
1888
1926
|
const identifier = resource.id ? resource.id : resource.key;
|
|
1889
1927
|
for (const action of actions) {
|
|
1928
|
+
if (this[action.action] === void 0) {
|
|
1929
|
+
console.info(`No handler for action ${action.action}`);
|
|
1930
|
+
throw new CommercetoolsError({
|
|
1931
|
+
code: "InvalidInput",
|
|
1932
|
+
message: `Invalid action ${action.action}`,
|
|
1933
|
+
errors: [
|
|
1934
|
+
{
|
|
1935
|
+
code: "InvalidInput",
|
|
1936
|
+
message: `Invalid action ${action.action}`
|
|
1937
|
+
}
|
|
1938
|
+
]
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1890
1941
|
const updateFunc = this[action.action].bind(this);
|
|
1891
1942
|
if (!updateFunc) {
|
|
1892
1943
|
console.error(`No mock implemented for update action ${action.action}`);
|
|
@@ -3553,6 +3604,7 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3553
3604
|
};
|
|
3554
3605
|
|
|
3555
3606
|
// src/repositories/customer/actions.ts
|
|
3607
|
+
var import_node_assert = __toESM(require("assert"), 1);
|
|
3556
3608
|
var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
3557
3609
|
addAddress(_context, resource, { address }) {
|
|
3558
3610
|
resource.addresses.push({
|
|
@@ -3561,67 +3613,35 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3561
3613
|
});
|
|
3562
3614
|
}
|
|
3563
3615
|
addBillingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3564
|
-
const address =
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3569
|
-
});
|
|
3570
|
-
if (!address) {
|
|
3571
|
-
throw new CommercetoolsError(
|
|
3572
|
-
{
|
|
3573
|
-
code: "InvalidInput",
|
|
3574
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3575
|
-
},
|
|
3576
|
-
400
|
|
3577
|
-
);
|
|
3616
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3617
|
+
(0, import_node_assert.default)(address?.id);
|
|
3618
|
+
if (resource.billingAddressIds === void 0) {
|
|
3619
|
+
resource.billingAddressIds = [];
|
|
3578
3620
|
}
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
resource.billingAddressIds.push(billingAddressId);
|
|
3582
|
-
} else if (address) {
|
|
3583
|
-
resource.billingAddressIds = [billingAddressId];
|
|
3621
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3622
|
+
resource.billingAddressIds.push(address.id);
|
|
3584
3623
|
}
|
|
3585
3624
|
}
|
|
3586
3625
|
addShippingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3587
|
-
const address =
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3592
|
-
});
|
|
3593
|
-
if (!address) {
|
|
3594
|
-
throw new CommercetoolsError(
|
|
3595
|
-
{
|
|
3596
|
-
code: "InvalidInput",
|
|
3597
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3598
|
-
},
|
|
3599
|
-
400
|
|
3600
|
-
);
|
|
3626
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3627
|
+
(0, import_node_assert.default)(address?.id);
|
|
3628
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3629
|
+
resource.shippingAddressIds = [];
|
|
3601
3630
|
}
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
resource.shippingAddressIds.push(shippingAddressId);
|
|
3605
|
-
} else if (address) {
|
|
3606
|
-
resource.shippingAddressIds = [shippingAddressId];
|
|
3631
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3632
|
+
resource.shippingAddressIds.push(address.id);
|
|
3607
3633
|
}
|
|
3634
|
+
return resource;
|
|
3635
|
+
}
|
|
3636
|
+
addStore(context, resource, action) {
|
|
3637
|
+
throw new Error("Method not implemented.");
|
|
3608
3638
|
}
|
|
3609
3639
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3610
|
-
const
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
});
|
|
3616
|
-
if (oldAddressIndex === -1) {
|
|
3617
|
-
throw new CommercetoolsError(
|
|
3618
|
-
{
|
|
3619
|
-
code: "InvalidInput",
|
|
3620
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3621
|
-
},
|
|
3622
|
-
400
|
|
3623
|
-
);
|
|
3624
|
-
}
|
|
3640
|
+
const current = this._findAddress(resource, addressId, addressKey, true);
|
|
3641
|
+
(0, import_node_assert.default)(current?.id);
|
|
3642
|
+
const oldAddressIndex = resource.addresses.findIndex(
|
|
3643
|
+
(a) => a.id === current.id
|
|
3644
|
+
);
|
|
3625
3645
|
const newAddress = createAddress(
|
|
3626
3646
|
address,
|
|
3627
3647
|
context.projectKey,
|
|
@@ -3637,6 +3657,55 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3637
3657
|
changeEmail(_context, resource, { email }) {
|
|
3638
3658
|
resource.email = email;
|
|
3639
3659
|
}
|
|
3660
|
+
removeAddress(context, resource, action) {
|
|
3661
|
+
const address = this._findAddress(
|
|
3662
|
+
resource,
|
|
3663
|
+
action.addressId,
|
|
3664
|
+
action.addressKey,
|
|
3665
|
+
true
|
|
3666
|
+
);
|
|
3667
|
+
(0, import_node_assert.default)(address?.id);
|
|
3668
|
+
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
3669
|
+
}
|
|
3670
|
+
removeBillingAddressId(context, resource, action) {
|
|
3671
|
+
const address = this._findAddress(
|
|
3672
|
+
resource,
|
|
3673
|
+
action.addressId,
|
|
3674
|
+
action.addressKey,
|
|
3675
|
+
true
|
|
3676
|
+
);
|
|
3677
|
+
(0, import_node_assert.default)(address?.id);
|
|
3678
|
+
resource.billingAddressIds = resource.billingAddressIds?.filter(
|
|
3679
|
+
(id) => id !== address.id
|
|
3680
|
+
);
|
|
3681
|
+
if (resource.defaultBillingAddressId === address.id) {
|
|
3682
|
+
resource.defaultBillingAddressId = void 0;
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
removeShippingAddressId(context, resource, action) {
|
|
3686
|
+
const address = this._findAddress(
|
|
3687
|
+
resource,
|
|
3688
|
+
action.addressId,
|
|
3689
|
+
action.addressKey,
|
|
3690
|
+
true
|
|
3691
|
+
);
|
|
3692
|
+
(0, import_node_assert.default)(address?.id);
|
|
3693
|
+
resource.shippingAddressIds = resource.shippingAddressIds?.filter(
|
|
3694
|
+
(id) => id !== address.id
|
|
3695
|
+
);
|
|
3696
|
+
if (resource.defaultShippingAddressId === address.id) {
|
|
3697
|
+
resource.defaultShippingAddressId = void 0;
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
removeStore(context, resource, action) {
|
|
3701
|
+
throw new Error("Method not implemented.");
|
|
3702
|
+
}
|
|
3703
|
+
setAddressCustomField(context, resource, action) {
|
|
3704
|
+
throw new Error("Method not implemented.");
|
|
3705
|
+
}
|
|
3706
|
+
setAddressCustomType(context, resource, action) {
|
|
3707
|
+
throw new Error("Method not implemented.");
|
|
3708
|
+
}
|
|
3640
3709
|
setAuthenticationMode(_context, resource, { authMode, password }) {
|
|
3641
3710
|
if (resource.authenticationMode === authMode) {
|
|
3642
3711
|
throw new CommercetoolsError(
|
|
@@ -3668,6 +3737,25 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3668
3737
|
setCompanyName(_context, resource, { companyName }) {
|
|
3669
3738
|
resource.companyName = companyName;
|
|
3670
3739
|
}
|
|
3740
|
+
setCustomerGroup(context, resource, action) {
|
|
3741
|
+
if (!action.customerGroup) {
|
|
3742
|
+
throw new CommercetoolsError(
|
|
3743
|
+
{
|
|
3744
|
+
code: "InvalidOperation",
|
|
3745
|
+
message: "CustomerGroup is required."
|
|
3746
|
+
},
|
|
3747
|
+
400
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
const group = this._storage.getByResourceIdentifier(
|
|
3751
|
+
context.projectKey,
|
|
3752
|
+
action.customerGroup
|
|
3753
|
+
);
|
|
3754
|
+
resource.customerGroup = {
|
|
3755
|
+
typeId: "customer-group",
|
|
3756
|
+
id: group.id
|
|
3757
|
+
};
|
|
3758
|
+
}
|
|
3671
3759
|
setCustomerNumber(_context, resource, { customerNumber }) {
|
|
3672
3760
|
if (resource.customerNumber) {
|
|
3673
3761
|
throw new Error(
|
|
@@ -3693,6 +3781,41 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3693
3781
|
resource.custom = void 0;
|
|
3694
3782
|
}
|
|
3695
3783
|
}
|
|
3784
|
+
setDateOfBirth(context, resource, action) {
|
|
3785
|
+
resource.dateOfBirth = action.dateOfBirth;
|
|
3786
|
+
}
|
|
3787
|
+
setDefaultBillingAddress(context, resource, action) {
|
|
3788
|
+
const address = this._findAddress(
|
|
3789
|
+
resource,
|
|
3790
|
+
action.addressId,
|
|
3791
|
+
action.addressKey,
|
|
3792
|
+
true
|
|
3793
|
+
);
|
|
3794
|
+
(0, import_node_assert.default)(address?.id);
|
|
3795
|
+
resource.defaultBillingAddressId = address.id;
|
|
3796
|
+
if (resource.billingAddressIds === void 0) {
|
|
3797
|
+
resource.billingAddressIds = [];
|
|
3798
|
+
}
|
|
3799
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3800
|
+
resource.billingAddressIds.push(address.id);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
setDefaultShippingAddress(context, resource, action) {
|
|
3804
|
+
const address = this._findAddress(
|
|
3805
|
+
resource,
|
|
3806
|
+
action.addressId,
|
|
3807
|
+
action.addressKey,
|
|
3808
|
+
true
|
|
3809
|
+
);
|
|
3810
|
+
(0, import_node_assert.default)(address?.id);
|
|
3811
|
+
resource.defaultShippingAddressId = address.id;
|
|
3812
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3813
|
+
resource.shippingAddressIds = [];
|
|
3814
|
+
}
|
|
3815
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3816
|
+
resource.shippingAddressIds.push(address.id);
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3696
3819
|
setExternalId(_context, resource, { externalId }) {
|
|
3697
3820
|
resource.externalId = externalId;
|
|
3698
3821
|
}
|
|
@@ -3708,12 +3831,58 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3708
3831
|
setLocale(_context, resource, { locale }) {
|
|
3709
3832
|
resource.locale = locale;
|
|
3710
3833
|
}
|
|
3834
|
+
setMiddleName(context, resource, action) {
|
|
3835
|
+
resource.middleName = action.middleName;
|
|
3836
|
+
}
|
|
3711
3837
|
setSalutation(_context, resource, { salutation }) {
|
|
3712
3838
|
resource.salutation = salutation;
|
|
3713
3839
|
}
|
|
3840
|
+
setStores(context, resource, action) {
|
|
3841
|
+
throw new Error("Method not implemented.");
|
|
3842
|
+
}
|
|
3843
|
+
setTitle(context, resource, action) {
|
|
3844
|
+
resource.title = action.title;
|
|
3845
|
+
}
|
|
3714
3846
|
setVatId(_context, resource, { vatId }) {
|
|
3715
3847
|
resource.vatId = vatId;
|
|
3716
3848
|
}
|
|
3849
|
+
_findAddress(resource, addressId, addressKey, required = false) {
|
|
3850
|
+
if (addressKey) {
|
|
3851
|
+
const address = resource.addresses.find((a) => a.key === addressKey);
|
|
3852
|
+
if (!address) {
|
|
3853
|
+
throw new CommercetoolsError(
|
|
3854
|
+
{
|
|
3855
|
+
code: "InvalidOperation",
|
|
3856
|
+
message: `Customer does not contain an address with the key ${addressKey}.`
|
|
3857
|
+
},
|
|
3858
|
+
400
|
|
3859
|
+
);
|
|
3860
|
+
}
|
|
3861
|
+
return address;
|
|
3862
|
+
}
|
|
3863
|
+
if (addressId) {
|
|
3864
|
+
const address = resource.addresses.find((a) => a.id === addressId);
|
|
3865
|
+
if (!address) {
|
|
3866
|
+
throw new CommercetoolsError(
|
|
3867
|
+
{
|
|
3868
|
+
code: "InvalidOperation",
|
|
3869
|
+
message: `Customer does not contain an address with the id ${addressId}.`
|
|
3870
|
+
},
|
|
3871
|
+
400
|
|
3872
|
+
);
|
|
3873
|
+
}
|
|
3874
|
+
return address;
|
|
3875
|
+
}
|
|
3876
|
+
if (required) {
|
|
3877
|
+
throw new CommercetoolsError(
|
|
3878
|
+
{
|
|
3879
|
+
code: "InvalidOperation",
|
|
3880
|
+
message: "One of address 'addressId' or 'addressKey' is required."
|
|
3881
|
+
},
|
|
3882
|
+
400
|
|
3883
|
+
);
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3717
3886
|
};
|
|
3718
3887
|
|
|
3719
3888
|
// src/repositories/customer/index.ts
|
|
@@ -3765,8 +3934,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3765
3934
|
]
|
|
3766
3935
|
});
|
|
3767
3936
|
};
|
|
3768
|
-
const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3769
|
-
const defaultShippingAddressId = draft.defaultShippingAddress ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3937
|
+
const defaultBillingAddressId = draft.defaultBillingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3938
|
+
const defaultShippingAddressId = draft.defaultShippingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3770
3939
|
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
3771
3940
|
(addressId) => lookupAdressId(addresses, addressId)
|
|
3772
3941
|
) ?? [];
|
|
@@ -4069,7 +4238,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
4069
4238
|
extension,
|
|
4070
4239
|
"destination.authentication.headerValue"
|
|
4071
4240
|
);
|
|
4072
|
-
} else if (extension.destination.type
|
|
4241
|
+
} else if (extension.destination.type === "AWSLambda") {
|
|
4073
4242
|
return maskSecretValue(resource, "destination.accessSecret");
|
|
4074
4243
|
}
|
|
4075
4244
|
}
|
|
@@ -4886,12 +5055,12 @@ var parseFilter = (filter) => {
|
|
|
4886
5055
|
if (unique.size > 1) {
|
|
4887
5056
|
throw new Error("Invalid expression");
|
|
4888
5057
|
}
|
|
4889
|
-
if (expressions.some((expr) => expr.type
|
|
5058
|
+
if (expressions.some((expr) => expr.type === "Symbol")) {
|
|
4890
5059
|
return {
|
|
4891
5060
|
source: left,
|
|
4892
5061
|
type: "FilterExpression",
|
|
4893
5062
|
children: expressions.map((e) => {
|
|
4894
|
-
if (e.type
|
|
5063
|
+
if (e.type !== "Symbol") {
|
|
4895
5064
|
throw new Error("Invalid expression");
|
|
4896
5065
|
}
|
|
4897
5066
|
return {
|
|
@@ -4989,7 +5158,7 @@ var generateMatchFunc2 = (filter) => {
|
|
|
4989
5158
|
if (!result) {
|
|
4990
5159
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
4991
5160
|
}
|
|
4992
|
-
if (result.type
|
|
5161
|
+
if (result.type === "TermExpression") {
|
|
4993
5162
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
4994
5163
|
}
|
|
4995
5164
|
return (obj) => {
|
|
@@ -5253,7 +5422,7 @@ var applyPriceSelector = (products, selector, noScopedPrice = false) => {
|
|
|
5253
5422
|
const variants = [
|
|
5254
5423
|
product.masterVariant,
|
|
5255
5424
|
...product.variants ?? []
|
|
5256
|
-
].filter((x) => x
|
|
5425
|
+
].filter((x) => x !== void 0);
|
|
5257
5426
|
for (const variant of variants) {
|
|
5258
5427
|
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
5259
5428
|
if (scopedPrices.length > 0) {
|
|
@@ -5722,7 +5891,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5722
5891
|
);
|
|
5723
5892
|
const foundCategory = data.categories.find(
|
|
5724
5893
|
(productCategory) => {
|
|
5725
|
-
if (productCategory.id
|
|
5894
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5726
5895
|
return productCategory;
|
|
5727
5896
|
}
|
|
5728
5897
|
return false;
|
|
@@ -5739,7 +5908,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5739
5908
|
}
|
|
5740
5909
|
data.categories = data.categories.filter(
|
|
5741
5910
|
(productCategory) => {
|
|
5742
|
-
if (productCategory.id
|
|
5911
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5743
5912
|
return false;
|
|
5744
5913
|
}
|
|
5745
5914
|
return true;
|
|
@@ -6734,14 +6903,14 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6734
6903
|
}
|
|
6735
6904
|
removeEnumValues(context, resource, { attributeName, keys }) {
|
|
6736
6905
|
resource.attributes?.forEach((attr) => {
|
|
6737
|
-
if (attr.name
|
|
6738
|
-
if (attr.type.name
|
|
6906
|
+
if (attr.name === attributeName) {
|
|
6907
|
+
if (attr.type.name === "enum") {
|
|
6739
6908
|
attr.type.values = attr.type.values.filter(
|
|
6740
6909
|
(v) => !keys.includes(v.key)
|
|
6741
6910
|
);
|
|
6742
6911
|
}
|
|
6743
|
-
if (attr.type.name
|
|
6744
|
-
if (attr.type.elementType.name
|
|
6912
|
+
if (attr.type.name === "set") {
|
|
6913
|
+
if (attr.type.elementType.name === "enum") {
|
|
6745
6914
|
attr.type.elementType.values = attr.type.elementType.values.filter(
|
|
6746
6915
|
(v) => !keys.includes(v.key)
|
|
6747
6916
|
);
|
|
@@ -6794,6 +6963,13 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6794
6963
|
changeCurrencies(context, resource, { currencies }) {
|
|
6795
6964
|
resource.currencies = currencies;
|
|
6796
6965
|
}
|
|
6966
|
+
changeCustomerSearchStatus(context, resource, { status }) {
|
|
6967
|
+
if (!resource.searchIndexing?.customers) {
|
|
6968
|
+
throw new Error("Invalid project state");
|
|
6969
|
+
}
|
|
6970
|
+
resource.searchIndexing.customers.status = status;
|
|
6971
|
+
resource.searchIndexing.customers.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6972
|
+
}
|
|
6797
6973
|
changeLanguages(context, resource, { languages }) {
|
|
6798
6974
|
resource.languages = languages;
|
|
6799
6975
|
}
|
|
@@ -6819,7 +6995,15 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6819
6995
|
resource.searchIndexing.orders.status = status;
|
|
6820
6996
|
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6821
6997
|
}
|
|
6822
|
-
changeProductSearchIndexingEnabled(context, resource, { enabled }) {
|
|
6998
|
+
changeProductSearchIndexingEnabled(context, resource, { enabled, mode }) {
|
|
6999
|
+
if (mode === "ProductsSearch") {
|
|
7000
|
+
if (!resource.searchIndexing?.productsSearch) {
|
|
7001
|
+
throw new Error("Invalid project state");
|
|
7002
|
+
}
|
|
7003
|
+
resource.searchIndexing.productsSearch.status = enabled ? "Activated" : "Deactivated";
|
|
7004
|
+
resource.searchIndexing.productsSearch.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7005
|
+
return;
|
|
7006
|
+
}
|
|
6823
7007
|
if (!resource.searchIndexing?.products) {
|
|
6824
7008
|
throw new Error("Invalid project state");
|
|
6825
7009
|
}
|