@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.js
CHANGED
|
@@ -56,7 +56,7 @@ var validatePasswordResetToken = (token) => {
|
|
|
56
56
|
if (secret !== PWRESET_SECRET) {
|
|
57
57
|
return void 0;
|
|
58
58
|
}
|
|
59
|
-
if (parseInt(time) < (/* @__PURE__ */ new Date()).getTime()) {
|
|
59
|
+
if (Number.parseInt(time) < (/* @__PURE__ */ new Date()).getTime()) {
|
|
60
60
|
return void 0;
|
|
61
61
|
}
|
|
62
62
|
return customerId;
|
|
@@ -81,7 +81,7 @@ var getBearerToken = (request) => {
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
// src/oauth/store.ts
|
|
84
|
-
import { randomBytes } from "crypto";
|
|
84
|
+
import { randomBytes } from "node:crypto";
|
|
85
85
|
import { v4 as uuidv42 } from "uuid";
|
|
86
86
|
var OAuth2Store = class {
|
|
87
87
|
tokens = [];
|
|
@@ -367,15 +367,47 @@ var OAuth2Server = class {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
async inStoreCustomerTokenHandler(request, response, next) {
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
const projectKey = request.params.projectKey;
|
|
371
|
+
const storeKey = request.params.storeKey;
|
|
372
|
+
const grantType = request.query.grant_type || request.body.grant_type;
|
|
373
|
+
if (!grantType) {
|
|
374
|
+
return next(
|
|
375
|
+
new CommercetoolsError(
|
|
376
|
+
{
|
|
377
|
+
code: "invalid_request",
|
|
378
|
+
message: "Missing required parameter: grant_type."
|
|
379
|
+
},
|
|
380
|
+
400
|
|
381
|
+
)
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
if (grantType === "password") {
|
|
385
|
+
const username = request.query.username || request.body.username;
|
|
386
|
+
const password = hashPassword(
|
|
387
|
+
request.query.password || request.body.password
|
|
388
|
+
);
|
|
389
|
+
const scope = request.query.scope?.toString() || request.body.scope?.toString();
|
|
390
|
+
const result = this.customerRepository.query(
|
|
391
|
+
{ projectKey, storeKey },
|
|
372
392
|
{
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
393
|
+
where: [`email = "${username}"`, `password = "${password}"`]
|
|
394
|
+
}
|
|
395
|
+
);
|
|
396
|
+
if (result.count === 0) {
|
|
397
|
+
return next(
|
|
398
|
+
new CommercetoolsError(
|
|
399
|
+
{
|
|
400
|
+
code: "invalid_customer_account_credentials",
|
|
401
|
+
message: "Customer account with the given credentials not found."
|
|
402
|
+
},
|
|
403
|
+
400
|
|
404
|
+
)
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
const customer = result.results[0];
|
|
408
|
+
const token = this.store.getCustomerToken(projectKey, customer.id, scope);
|
|
409
|
+
return response.status(200).send(token);
|
|
410
|
+
}
|
|
379
411
|
}
|
|
380
412
|
async anonymousTokenHandler(request, response, next) {
|
|
381
413
|
const projectKey = request.params.projectKey;
|
|
@@ -420,7 +452,7 @@ var nestedLookup = (obj, path) => {
|
|
|
420
452
|
let val = obj;
|
|
421
453
|
for (let i = 0; i < parts.length; i++) {
|
|
422
454
|
const part = parts[i];
|
|
423
|
-
if (val
|
|
455
|
+
if (val === void 0) {
|
|
424
456
|
return void 0;
|
|
425
457
|
}
|
|
426
458
|
val = val[part];
|
|
@@ -428,7 +460,7 @@ var nestedLookup = (obj, path) => {
|
|
|
428
460
|
return val;
|
|
429
461
|
};
|
|
430
462
|
var queryParamsArray = (input) => {
|
|
431
|
-
if (input
|
|
463
|
+
if (input === void 0) {
|
|
432
464
|
return void 0;
|
|
433
465
|
}
|
|
434
466
|
const values = Array.isArray(input) ? input : [input];
|
|
@@ -527,7 +559,7 @@ var parseExpandClause = (clause) => {
|
|
|
527
559
|
}
|
|
528
560
|
const match = result.element.match(/\[([^\]+])]/);
|
|
529
561
|
if (match) {
|
|
530
|
-
result.index = match[1] === "*" ? "*" : parseInt(match[1], 10);
|
|
562
|
+
result.index = match[1] === "*" ? "*" : Number.parseInt(match[1], 10);
|
|
531
563
|
result.element = result.element.substring(0, match.index);
|
|
532
564
|
}
|
|
533
565
|
return result;
|
|
@@ -1311,7 +1343,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
1311
1343
|
return (obj, vars) => {
|
|
1312
1344
|
const value = resolveValue(obj, left);
|
|
1313
1345
|
const other = resolveSymbol(expr, vars);
|
|
1314
|
-
if (typeof value
|
|
1346
|
+
if (typeof value !== "string") {
|
|
1315
1347
|
throw new PredicateError(
|
|
1316
1348
|
`The field '${left.value}' does not support this expression.`
|
|
1317
1349
|
);
|
|
@@ -1400,8 +1432,14 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1400
1432
|
products: {
|
|
1401
1433
|
status: "Deactivated"
|
|
1402
1434
|
},
|
|
1435
|
+
productsSearch: {
|
|
1436
|
+
status: "Deactivated"
|
|
1437
|
+
},
|
|
1403
1438
|
orders: {
|
|
1404
1439
|
status: "Deactivated"
|
|
1440
|
+
},
|
|
1441
|
+
customers: {
|
|
1442
|
+
status: "Deactivated"
|
|
1405
1443
|
}
|
|
1406
1444
|
},
|
|
1407
1445
|
version: 1
|
|
@@ -1743,7 +1781,7 @@ var AbstractRepository = class {
|
|
|
1743
1781
|
version,
|
|
1744
1782
|
actions
|
|
1745
1783
|
);
|
|
1746
|
-
if (resource.version
|
|
1784
|
+
if (resource.version !== updatedResource.version) {
|
|
1747
1785
|
this.saveUpdate(context, version, updatedResource);
|
|
1748
1786
|
}
|
|
1749
1787
|
const result = this.postProcessResource(context, updatedResource);
|
|
@@ -1850,6 +1888,19 @@ var AbstractUpdateHandler = class {
|
|
|
1850
1888
|
const updatedResource = cloneObject(resource);
|
|
1851
1889
|
const identifier = resource.id ? resource.id : resource.key;
|
|
1852
1890
|
for (const action of actions) {
|
|
1891
|
+
if (this[action.action] === void 0) {
|
|
1892
|
+
console.info(`No handler for action ${action.action}`);
|
|
1893
|
+
throw new CommercetoolsError({
|
|
1894
|
+
code: "InvalidInput",
|
|
1895
|
+
message: `Invalid action ${action.action}`,
|
|
1896
|
+
errors: [
|
|
1897
|
+
{
|
|
1898
|
+
code: "InvalidInput",
|
|
1899
|
+
message: `Invalid action ${action.action}`
|
|
1900
|
+
}
|
|
1901
|
+
]
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1853
1904
|
const updateFunc = this[action.action].bind(this);
|
|
1854
1905
|
if (!updateFunc) {
|
|
1855
1906
|
console.error(`No mock implemented for update action ${action.action}`);
|
|
@@ -3516,6 +3567,7 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3516
3567
|
};
|
|
3517
3568
|
|
|
3518
3569
|
// src/repositories/customer/actions.ts
|
|
3570
|
+
import assert2 from "node:assert";
|
|
3519
3571
|
var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
3520
3572
|
addAddress(_context, resource, { address }) {
|
|
3521
3573
|
resource.addresses.push({
|
|
@@ -3524,67 +3576,35 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3524
3576
|
});
|
|
3525
3577
|
}
|
|
3526
3578
|
addBillingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3527
|
-
const address =
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3532
|
-
});
|
|
3533
|
-
if (!address) {
|
|
3534
|
-
throw new CommercetoolsError(
|
|
3535
|
-
{
|
|
3536
|
-
code: "InvalidInput",
|
|
3537
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3538
|
-
},
|
|
3539
|
-
400
|
|
3540
|
-
);
|
|
3579
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3580
|
+
assert2(address?.id);
|
|
3581
|
+
if (resource.billingAddressIds === void 0) {
|
|
3582
|
+
resource.billingAddressIds = [];
|
|
3541
3583
|
}
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
resource.billingAddressIds.push(billingAddressId);
|
|
3545
|
-
} else if (address) {
|
|
3546
|
-
resource.billingAddressIds = [billingAddressId];
|
|
3584
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3585
|
+
resource.billingAddressIds.push(address.id);
|
|
3547
3586
|
}
|
|
3548
3587
|
}
|
|
3549
3588
|
addShippingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3550
|
-
const address =
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3555
|
-
});
|
|
3556
|
-
if (!address) {
|
|
3557
|
-
throw new CommercetoolsError(
|
|
3558
|
-
{
|
|
3559
|
-
code: "InvalidInput",
|
|
3560
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3561
|
-
},
|
|
3562
|
-
400
|
|
3563
|
-
);
|
|
3589
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3590
|
+
assert2(address?.id);
|
|
3591
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3592
|
+
resource.shippingAddressIds = [];
|
|
3564
3593
|
}
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
resource.shippingAddressIds.push(shippingAddressId);
|
|
3568
|
-
} else if (address) {
|
|
3569
|
-
resource.shippingAddressIds = [shippingAddressId];
|
|
3594
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3595
|
+
resource.shippingAddressIds.push(address.id);
|
|
3570
3596
|
}
|
|
3597
|
+
return resource;
|
|
3598
|
+
}
|
|
3599
|
+
addStore(context, resource, action) {
|
|
3600
|
+
throw new Error("Method not implemented.");
|
|
3571
3601
|
}
|
|
3572
3602
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3573
|
-
const
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
});
|
|
3579
|
-
if (oldAddressIndex === -1) {
|
|
3580
|
-
throw new CommercetoolsError(
|
|
3581
|
-
{
|
|
3582
|
-
code: "InvalidInput",
|
|
3583
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3584
|
-
},
|
|
3585
|
-
400
|
|
3586
|
-
);
|
|
3587
|
-
}
|
|
3603
|
+
const current = this._findAddress(resource, addressId, addressKey, true);
|
|
3604
|
+
assert2(current?.id);
|
|
3605
|
+
const oldAddressIndex = resource.addresses.findIndex(
|
|
3606
|
+
(a) => a.id === current.id
|
|
3607
|
+
);
|
|
3588
3608
|
const newAddress = createAddress(
|
|
3589
3609
|
address,
|
|
3590
3610
|
context.projectKey,
|
|
@@ -3600,6 +3620,55 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3600
3620
|
changeEmail(_context, resource, { email }) {
|
|
3601
3621
|
resource.email = email;
|
|
3602
3622
|
}
|
|
3623
|
+
removeAddress(context, resource, action) {
|
|
3624
|
+
const address = this._findAddress(
|
|
3625
|
+
resource,
|
|
3626
|
+
action.addressId,
|
|
3627
|
+
action.addressKey,
|
|
3628
|
+
true
|
|
3629
|
+
);
|
|
3630
|
+
assert2(address?.id);
|
|
3631
|
+
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
3632
|
+
}
|
|
3633
|
+
removeBillingAddressId(context, resource, action) {
|
|
3634
|
+
const address = this._findAddress(
|
|
3635
|
+
resource,
|
|
3636
|
+
action.addressId,
|
|
3637
|
+
action.addressKey,
|
|
3638
|
+
true
|
|
3639
|
+
);
|
|
3640
|
+
assert2(address?.id);
|
|
3641
|
+
resource.billingAddressIds = resource.billingAddressIds?.filter(
|
|
3642
|
+
(id) => id !== address.id
|
|
3643
|
+
);
|
|
3644
|
+
if (resource.defaultBillingAddressId === address.id) {
|
|
3645
|
+
resource.defaultBillingAddressId = void 0;
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
removeShippingAddressId(context, resource, action) {
|
|
3649
|
+
const address = this._findAddress(
|
|
3650
|
+
resource,
|
|
3651
|
+
action.addressId,
|
|
3652
|
+
action.addressKey,
|
|
3653
|
+
true
|
|
3654
|
+
);
|
|
3655
|
+
assert2(address?.id);
|
|
3656
|
+
resource.shippingAddressIds = resource.shippingAddressIds?.filter(
|
|
3657
|
+
(id) => id !== address.id
|
|
3658
|
+
);
|
|
3659
|
+
if (resource.defaultShippingAddressId === address.id) {
|
|
3660
|
+
resource.defaultShippingAddressId = void 0;
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
removeStore(context, resource, action) {
|
|
3664
|
+
throw new Error("Method not implemented.");
|
|
3665
|
+
}
|
|
3666
|
+
setAddressCustomField(context, resource, action) {
|
|
3667
|
+
throw new Error("Method not implemented.");
|
|
3668
|
+
}
|
|
3669
|
+
setAddressCustomType(context, resource, action) {
|
|
3670
|
+
throw new Error("Method not implemented.");
|
|
3671
|
+
}
|
|
3603
3672
|
setAuthenticationMode(_context, resource, { authMode, password }) {
|
|
3604
3673
|
if (resource.authenticationMode === authMode) {
|
|
3605
3674
|
throw new CommercetoolsError(
|
|
@@ -3631,6 +3700,25 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3631
3700
|
setCompanyName(_context, resource, { companyName }) {
|
|
3632
3701
|
resource.companyName = companyName;
|
|
3633
3702
|
}
|
|
3703
|
+
setCustomerGroup(context, resource, action) {
|
|
3704
|
+
if (!action.customerGroup) {
|
|
3705
|
+
throw new CommercetoolsError(
|
|
3706
|
+
{
|
|
3707
|
+
code: "InvalidOperation",
|
|
3708
|
+
message: "CustomerGroup is required."
|
|
3709
|
+
},
|
|
3710
|
+
400
|
|
3711
|
+
);
|
|
3712
|
+
}
|
|
3713
|
+
const group = this._storage.getByResourceIdentifier(
|
|
3714
|
+
context.projectKey,
|
|
3715
|
+
action.customerGroup
|
|
3716
|
+
);
|
|
3717
|
+
resource.customerGroup = {
|
|
3718
|
+
typeId: "customer-group",
|
|
3719
|
+
id: group.id
|
|
3720
|
+
};
|
|
3721
|
+
}
|
|
3634
3722
|
setCustomerNumber(_context, resource, { customerNumber }) {
|
|
3635
3723
|
if (resource.customerNumber) {
|
|
3636
3724
|
throw new Error(
|
|
@@ -3656,6 +3744,41 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3656
3744
|
resource.custom = void 0;
|
|
3657
3745
|
}
|
|
3658
3746
|
}
|
|
3747
|
+
setDateOfBirth(context, resource, action) {
|
|
3748
|
+
resource.dateOfBirth = action.dateOfBirth;
|
|
3749
|
+
}
|
|
3750
|
+
setDefaultBillingAddress(context, resource, action) {
|
|
3751
|
+
const address = this._findAddress(
|
|
3752
|
+
resource,
|
|
3753
|
+
action.addressId,
|
|
3754
|
+
action.addressKey,
|
|
3755
|
+
true
|
|
3756
|
+
);
|
|
3757
|
+
assert2(address?.id);
|
|
3758
|
+
resource.defaultBillingAddressId = address.id;
|
|
3759
|
+
if (resource.billingAddressIds === void 0) {
|
|
3760
|
+
resource.billingAddressIds = [];
|
|
3761
|
+
}
|
|
3762
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3763
|
+
resource.billingAddressIds.push(address.id);
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
setDefaultShippingAddress(context, resource, action) {
|
|
3767
|
+
const address = this._findAddress(
|
|
3768
|
+
resource,
|
|
3769
|
+
action.addressId,
|
|
3770
|
+
action.addressKey,
|
|
3771
|
+
true
|
|
3772
|
+
);
|
|
3773
|
+
assert2(address?.id);
|
|
3774
|
+
resource.defaultShippingAddressId = address.id;
|
|
3775
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3776
|
+
resource.shippingAddressIds = [];
|
|
3777
|
+
}
|
|
3778
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3779
|
+
resource.shippingAddressIds.push(address.id);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3659
3782
|
setExternalId(_context, resource, { externalId }) {
|
|
3660
3783
|
resource.externalId = externalId;
|
|
3661
3784
|
}
|
|
@@ -3671,12 +3794,58 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3671
3794
|
setLocale(_context, resource, { locale }) {
|
|
3672
3795
|
resource.locale = locale;
|
|
3673
3796
|
}
|
|
3797
|
+
setMiddleName(context, resource, action) {
|
|
3798
|
+
resource.middleName = action.middleName;
|
|
3799
|
+
}
|
|
3674
3800
|
setSalutation(_context, resource, { salutation }) {
|
|
3675
3801
|
resource.salutation = salutation;
|
|
3676
3802
|
}
|
|
3803
|
+
setStores(context, resource, action) {
|
|
3804
|
+
throw new Error("Method not implemented.");
|
|
3805
|
+
}
|
|
3806
|
+
setTitle(context, resource, action) {
|
|
3807
|
+
resource.title = action.title;
|
|
3808
|
+
}
|
|
3677
3809
|
setVatId(_context, resource, { vatId }) {
|
|
3678
3810
|
resource.vatId = vatId;
|
|
3679
3811
|
}
|
|
3812
|
+
_findAddress(resource, addressId, addressKey, required = false) {
|
|
3813
|
+
if (addressKey) {
|
|
3814
|
+
const address = resource.addresses.find((a) => a.key === addressKey);
|
|
3815
|
+
if (!address) {
|
|
3816
|
+
throw new CommercetoolsError(
|
|
3817
|
+
{
|
|
3818
|
+
code: "InvalidOperation",
|
|
3819
|
+
message: `Customer does not contain an address with the key ${addressKey}.`
|
|
3820
|
+
},
|
|
3821
|
+
400
|
|
3822
|
+
);
|
|
3823
|
+
}
|
|
3824
|
+
return address;
|
|
3825
|
+
}
|
|
3826
|
+
if (addressId) {
|
|
3827
|
+
const address = resource.addresses.find((a) => a.id === addressId);
|
|
3828
|
+
if (!address) {
|
|
3829
|
+
throw new CommercetoolsError(
|
|
3830
|
+
{
|
|
3831
|
+
code: "InvalidOperation",
|
|
3832
|
+
message: `Customer does not contain an address with the id ${addressId}.`
|
|
3833
|
+
},
|
|
3834
|
+
400
|
|
3835
|
+
);
|
|
3836
|
+
}
|
|
3837
|
+
return address;
|
|
3838
|
+
}
|
|
3839
|
+
if (required) {
|
|
3840
|
+
throw new CommercetoolsError(
|
|
3841
|
+
{
|
|
3842
|
+
code: "InvalidOperation",
|
|
3843
|
+
message: "One of address 'addressId' or 'addressKey' is required."
|
|
3844
|
+
},
|
|
3845
|
+
400
|
|
3846
|
+
);
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3680
3849
|
};
|
|
3681
3850
|
|
|
3682
3851
|
// src/repositories/customer/index.ts
|
|
@@ -3728,8 +3897,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3728
3897
|
]
|
|
3729
3898
|
});
|
|
3730
3899
|
};
|
|
3731
|
-
const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3732
|
-
const defaultShippingAddressId = draft.defaultShippingAddress ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3900
|
+
const defaultBillingAddressId = draft.defaultBillingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3901
|
+
const defaultShippingAddressId = draft.defaultShippingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3733
3902
|
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
3734
3903
|
(addressId) => lookupAdressId(addresses, addressId)
|
|
3735
3904
|
) ?? [];
|
|
@@ -4032,7 +4201,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
4032
4201
|
extension,
|
|
4033
4202
|
"destination.authentication.headerValue"
|
|
4034
4203
|
);
|
|
4035
|
-
} else if (extension.destination.type
|
|
4204
|
+
} else if (extension.destination.type === "AWSLambda") {
|
|
4036
4205
|
return maskSecretValue(resource, "destination.accessSecret");
|
|
4037
4206
|
}
|
|
4038
4207
|
}
|
|
@@ -4199,13 +4368,13 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
4199
4368
|
};
|
|
4200
4369
|
|
|
4201
4370
|
// src/repositories/my-order.ts
|
|
4202
|
-
import
|
|
4371
|
+
import assert5 from "assert";
|
|
4203
4372
|
|
|
4204
4373
|
// src/repositories/order/index.ts
|
|
4205
|
-
import
|
|
4374
|
+
import assert4 from "assert";
|
|
4206
4375
|
|
|
4207
4376
|
// src/repositories/order/actions.ts
|
|
4208
|
-
import
|
|
4377
|
+
import assert3 from "assert";
|
|
4209
4378
|
var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
4210
4379
|
addPayment(context, resource, { payment }) {
|
|
4211
4380
|
const resolvedPayment = this._storage.getByResourceIdentifier(
|
|
@@ -4305,7 +4474,7 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
4305
4474
|
}
|
|
4306
4475
|
}
|
|
4307
4476
|
setDeliveryCustomField(context, resource, { deliveryId, name, value }) {
|
|
4308
|
-
|
|
4477
|
+
assert3(resource.shippingInfo, "shippingInfo is not defined");
|
|
4309
4478
|
if (Array.isArray(resource.shippingInfo.deliveries)) {
|
|
4310
4479
|
resource.shippingInfo.deliveries.map((delivery) => {
|
|
4311
4480
|
if (delivery.id !== deliveryId) throw "No matching delivery id found";
|
|
@@ -4400,7 +4569,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4400
4569
|
this.actions = new OrderUpdateHandler(storage);
|
|
4401
4570
|
}
|
|
4402
4571
|
create(context, draft) {
|
|
4403
|
-
|
|
4572
|
+
assert4(draft.cart, "draft.cart is missing");
|
|
4404
4573
|
return this.createFromCart(
|
|
4405
4574
|
context,
|
|
4406
4575
|
{
|
|
@@ -4455,7 +4624,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4455
4624
|
return this.saveNew(context, resource);
|
|
4456
4625
|
}
|
|
4457
4626
|
import(context, draft) {
|
|
4458
|
-
|
|
4627
|
+
assert4(this, "OrderRepository not valid");
|
|
4459
4628
|
const resource = {
|
|
4460
4629
|
...getBaseResourceProperties(),
|
|
4461
4630
|
billingAddress: createAddress(
|
|
@@ -4598,7 +4767,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4598
4767
|
// src/repositories/my-order.ts
|
|
4599
4768
|
var MyOrderRepository = class extends OrderRepository {
|
|
4600
4769
|
create(context, draft) {
|
|
4601
|
-
|
|
4770
|
+
assert5(draft.id, "draft.id is missing");
|
|
4602
4771
|
const cartIdentifier = {
|
|
4603
4772
|
id: draft.id,
|
|
4604
4773
|
typeId: "cart"
|
|
@@ -4849,12 +5018,12 @@ var parseFilter = (filter) => {
|
|
|
4849
5018
|
if (unique.size > 1) {
|
|
4850
5019
|
throw new Error("Invalid expression");
|
|
4851
5020
|
}
|
|
4852
|
-
if (expressions.some((expr) => expr.type
|
|
5021
|
+
if (expressions.some((expr) => expr.type === "Symbol")) {
|
|
4853
5022
|
return {
|
|
4854
5023
|
source: left,
|
|
4855
5024
|
type: "FilterExpression",
|
|
4856
5025
|
children: expressions.map((e) => {
|
|
4857
|
-
if (e.type
|
|
5026
|
+
if (e.type !== "Symbol") {
|
|
4858
5027
|
throw new Error("Invalid expression");
|
|
4859
5028
|
}
|
|
4860
5029
|
return {
|
|
@@ -4952,7 +5121,7 @@ var generateMatchFunc2 = (filter) => {
|
|
|
4952
5121
|
if (!result) {
|
|
4953
5122
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
4954
5123
|
}
|
|
4955
|
-
if (result.type
|
|
5124
|
+
if (result.type === "TermExpression") {
|
|
4956
5125
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
4957
5126
|
}
|
|
4958
5127
|
return (obj) => {
|
|
@@ -5216,7 +5385,7 @@ var applyPriceSelector = (products, selector, noScopedPrice = false) => {
|
|
|
5216
5385
|
const variants = [
|
|
5217
5386
|
product.masterVariant,
|
|
5218
5387
|
...product.variants ?? []
|
|
5219
|
-
].filter((x) => x
|
|
5388
|
+
].filter((x) => x !== void 0);
|
|
5220
5389
|
for (const variant of variants) {
|
|
5221
5390
|
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
5222
5391
|
if (scopedPrices.length > 0) {
|
|
@@ -5685,7 +5854,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5685
5854
|
);
|
|
5686
5855
|
const foundCategory = data.categories.find(
|
|
5687
5856
|
(productCategory) => {
|
|
5688
|
-
if (productCategory.id
|
|
5857
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5689
5858
|
return productCategory;
|
|
5690
5859
|
}
|
|
5691
5860
|
return false;
|
|
@@ -5702,7 +5871,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5702
5871
|
}
|
|
5703
5872
|
data.categories = data.categories.filter(
|
|
5704
5873
|
(productCategory) => {
|
|
5705
|
-
if (productCategory.id
|
|
5874
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5706
5875
|
return false;
|
|
5707
5876
|
}
|
|
5708
5877
|
return true;
|
|
@@ -6697,14 +6866,14 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6697
6866
|
}
|
|
6698
6867
|
removeEnumValues(context, resource, { attributeName, keys }) {
|
|
6699
6868
|
resource.attributes?.forEach((attr) => {
|
|
6700
|
-
if (attr.name
|
|
6701
|
-
if (attr.type.name
|
|
6869
|
+
if (attr.name === attributeName) {
|
|
6870
|
+
if (attr.type.name === "enum") {
|
|
6702
6871
|
attr.type.values = attr.type.values.filter(
|
|
6703
6872
|
(v) => !keys.includes(v.key)
|
|
6704
6873
|
);
|
|
6705
6874
|
}
|
|
6706
|
-
if (attr.type.name
|
|
6707
|
-
if (attr.type.elementType.name
|
|
6875
|
+
if (attr.type.name === "set") {
|
|
6876
|
+
if (attr.type.elementType.name === "enum") {
|
|
6708
6877
|
attr.type.elementType.values = attr.type.elementType.values.filter(
|
|
6709
6878
|
(v) => !keys.includes(v.key)
|
|
6710
6879
|
);
|
|
@@ -6757,6 +6926,13 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6757
6926
|
changeCurrencies(context, resource, { currencies }) {
|
|
6758
6927
|
resource.currencies = currencies;
|
|
6759
6928
|
}
|
|
6929
|
+
changeCustomerSearchStatus(context, resource, { status }) {
|
|
6930
|
+
if (!resource.searchIndexing?.customers) {
|
|
6931
|
+
throw new Error("Invalid project state");
|
|
6932
|
+
}
|
|
6933
|
+
resource.searchIndexing.customers.status = status;
|
|
6934
|
+
resource.searchIndexing.customers.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6935
|
+
}
|
|
6760
6936
|
changeLanguages(context, resource, { languages }) {
|
|
6761
6937
|
resource.languages = languages;
|
|
6762
6938
|
}
|
|
@@ -6782,7 +6958,15 @@ var ProjectUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6782
6958
|
resource.searchIndexing.orders.status = status;
|
|
6783
6959
|
resource.searchIndexing.orders.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6784
6960
|
}
|
|
6785
|
-
changeProductSearchIndexingEnabled(context, resource, { enabled }) {
|
|
6961
|
+
changeProductSearchIndexingEnabled(context, resource, { enabled, mode }) {
|
|
6962
|
+
if (mode === "ProductsSearch") {
|
|
6963
|
+
if (!resource.searchIndexing?.productsSearch) {
|
|
6964
|
+
throw new Error("Invalid project state");
|
|
6965
|
+
}
|
|
6966
|
+
resource.searchIndexing.productsSearch.status = enabled ? "Activated" : "Deactivated";
|
|
6967
|
+
resource.searchIndexing.productsSearch.lastModifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6968
|
+
return;
|
|
6969
|
+
}
|
|
6786
6970
|
if (!resource.searchIndexing?.products) {
|
|
6787
6971
|
throw new Error("Invalid project state");
|
|
6788
6972
|
}
|