@labdigital/commercetools-mock 2.37.0 → 2.39.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 +216 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +216 -80
- package/dist/index.js.map +1 -1
- package/package.json +10 -9
- 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 +2 -1
- package/src/oauth/server.ts +5 -8
- 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 +14 -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 +4 -8
- 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.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 +6 -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 = [];
|
|
@@ -452,7 +452,7 @@ var nestedLookup = (obj, path) => {
|
|
|
452
452
|
let val = obj;
|
|
453
453
|
for (let i = 0; i < parts.length; i++) {
|
|
454
454
|
const part = parts[i];
|
|
455
|
-
if (val
|
|
455
|
+
if (val === void 0) {
|
|
456
456
|
return void 0;
|
|
457
457
|
}
|
|
458
458
|
val = val[part];
|
|
@@ -460,7 +460,7 @@ var nestedLookup = (obj, path) => {
|
|
|
460
460
|
return val;
|
|
461
461
|
};
|
|
462
462
|
var queryParamsArray = (input) => {
|
|
463
|
-
if (input
|
|
463
|
+
if (input === void 0) {
|
|
464
464
|
return void 0;
|
|
465
465
|
}
|
|
466
466
|
const values = Array.isArray(input) ? input : [input];
|
|
@@ -559,7 +559,7 @@ var parseExpandClause = (clause) => {
|
|
|
559
559
|
}
|
|
560
560
|
const match = result.element.match(/\[([^\]+])]/);
|
|
561
561
|
if (match) {
|
|
562
|
-
result.index = match[1] === "*" ? "*" : parseInt(match[1], 10);
|
|
562
|
+
result.index = match[1] === "*" ? "*" : Number.parseInt(match[1], 10);
|
|
563
563
|
result.element = result.element.substring(0, match.index);
|
|
564
564
|
}
|
|
565
565
|
return result;
|
|
@@ -1343,7 +1343,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
1343
1343
|
return (obj, vars) => {
|
|
1344
1344
|
const value = resolveValue(obj, left);
|
|
1345
1345
|
const other = resolveSymbol(expr, vars);
|
|
1346
|
-
if (typeof value
|
|
1346
|
+
if (typeof value !== "string") {
|
|
1347
1347
|
throw new PredicateError(
|
|
1348
1348
|
`The field '${left.value}' does not support this expression.`
|
|
1349
1349
|
);
|
|
@@ -1781,7 +1781,7 @@ var AbstractRepository = class {
|
|
|
1781
1781
|
version,
|
|
1782
1782
|
actions
|
|
1783
1783
|
);
|
|
1784
|
-
if (resource.version
|
|
1784
|
+
if (resource.version !== updatedResource.version) {
|
|
1785
1785
|
this.saveUpdate(context, version, updatedResource);
|
|
1786
1786
|
}
|
|
1787
1787
|
const result = this.postProcessResource(context, updatedResource);
|
|
@@ -1888,6 +1888,19 @@ var AbstractUpdateHandler = class {
|
|
|
1888
1888
|
const updatedResource = cloneObject(resource);
|
|
1889
1889
|
const identifier = resource.id ? resource.id : resource.key;
|
|
1890
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
|
+
}
|
|
1891
1904
|
const updateFunc = this[action.action].bind(this);
|
|
1892
1905
|
if (!updateFunc) {
|
|
1893
1906
|
console.error(`No mock implemented for update action ${action.action}`);
|
|
@@ -3158,6 +3171,11 @@ var CartDiscountUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3158
3171
|
setKey(context, resource, { key }) {
|
|
3159
3172
|
resource.key = key;
|
|
3160
3173
|
}
|
|
3174
|
+
setStores(context, resource, { stores }) {
|
|
3175
|
+
resource.stores = stores?.map(
|
|
3176
|
+
(s) => getStoreKeyReference(s, context.projectKey, this._storage)
|
|
3177
|
+
);
|
|
3178
|
+
}
|
|
3161
3179
|
setValidFrom(context, resource, { validFrom }) {
|
|
3162
3180
|
resource.validFrom = validFrom;
|
|
3163
3181
|
}
|
|
@@ -3554,6 +3572,7 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3554
3572
|
};
|
|
3555
3573
|
|
|
3556
3574
|
// src/repositories/customer/actions.ts
|
|
3575
|
+
import assert2 from "node:assert";
|
|
3557
3576
|
var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
3558
3577
|
addAddress(_context, resource, { address }) {
|
|
3559
3578
|
resource.addresses.push({
|
|
@@ -3562,67 +3581,35 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3562
3581
|
});
|
|
3563
3582
|
}
|
|
3564
3583
|
addBillingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3565
|
-
const address =
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3570
|
-
});
|
|
3571
|
-
if (!address) {
|
|
3572
|
-
throw new CommercetoolsError(
|
|
3573
|
-
{
|
|
3574
|
-
code: "InvalidInput",
|
|
3575
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3576
|
-
},
|
|
3577
|
-
400
|
|
3578
|
-
);
|
|
3584
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3585
|
+
assert2(address?.id);
|
|
3586
|
+
if (resource.billingAddressIds === void 0) {
|
|
3587
|
+
resource.billingAddressIds = [];
|
|
3579
3588
|
}
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
resource.billingAddressIds.push(billingAddressId);
|
|
3583
|
-
} else if (address) {
|
|
3584
|
-
resource.billingAddressIds = [billingAddressId];
|
|
3589
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3590
|
+
resource.billingAddressIds.push(address.id);
|
|
3585
3591
|
}
|
|
3586
3592
|
}
|
|
3587
3593
|
addShippingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3588
|
-
const address =
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3593
|
-
});
|
|
3594
|
-
if (!address) {
|
|
3595
|
-
throw new CommercetoolsError(
|
|
3596
|
-
{
|
|
3597
|
-
code: "InvalidInput",
|
|
3598
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3599
|
-
},
|
|
3600
|
-
400
|
|
3601
|
-
);
|
|
3594
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3595
|
+
assert2(address?.id);
|
|
3596
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3597
|
+
resource.shippingAddressIds = [];
|
|
3602
3598
|
}
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
resource.shippingAddressIds.push(shippingAddressId);
|
|
3606
|
-
} else if (address) {
|
|
3607
|
-
resource.shippingAddressIds = [shippingAddressId];
|
|
3599
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3600
|
+
resource.shippingAddressIds.push(address.id);
|
|
3608
3601
|
}
|
|
3602
|
+
return resource;
|
|
3603
|
+
}
|
|
3604
|
+
addStore(context, resource, action) {
|
|
3605
|
+
throw new Error("Method not implemented.");
|
|
3609
3606
|
}
|
|
3610
3607
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3611
|
-
const
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
});
|
|
3617
|
-
if (oldAddressIndex === -1) {
|
|
3618
|
-
throw new CommercetoolsError(
|
|
3619
|
-
{
|
|
3620
|
-
code: "InvalidInput",
|
|
3621
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3622
|
-
},
|
|
3623
|
-
400
|
|
3624
|
-
);
|
|
3625
|
-
}
|
|
3608
|
+
const current = this._findAddress(resource, addressId, addressKey, true);
|
|
3609
|
+
assert2(current?.id);
|
|
3610
|
+
const oldAddressIndex = resource.addresses.findIndex(
|
|
3611
|
+
(a) => a.id === current.id
|
|
3612
|
+
);
|
|
3626
3613
|
const newAddress = createAddress(
|
|
3627
3614
|
address,
|
|
3628
3615
|
context.projectKey,
|
|
@@ -3638,6 +3625,55 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3638
3625
|
changeEmail(_context, resource, { email }) {
|
|
3639
3626
|
resource.email = email;
|
|
3640
3627
|
}
|
|
3628
|
+
removeAddress(context, resource, action) {
|
|
3629
|
+
const address = this._findAddress(
|
|
3630
|
+
resource,
|
|
3631
|
+
action.addressId,
|
|
3632
|
+
action.addressKey,
|
|
3633
|
+
true
|
|
3634
|
+
);
|
|
3635
|
+
assert2(address?.id);
|
|
3636
|
+
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
3637
|
+
}
|
|
3638
|
+
removeBillingAddressId(context, resource, action) {
|
|
3639
|
+
const address = this._findAddress(
|
|
3640
|
+
resource,
|
|
3641
|
+
action.addressId,
|
|
3642
|
+
action.addressKey,
|
|
3643
|
+
true
|
|
3644
|
+
);
|
|
3645
|
+
assert2(address?.id);
|
|
3646
|
+
resource.billingAddressIds = resource.billingAddressIds?.filter(
|
|
3647
|
+
(id) => id !== address.id
|
|
3648
|
+
);
|
|
3649
|
+
if (resource.defaultBillingAddressId === address.id) {
|
|
3650
|
+
resource.defaultBillingAddressId = void 0;
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
removeShippingAddressId(context, resource, action) {
|
|
3654
|
+
const address = this._findAddress(
|
|
3655
|
+
resource,
|
|
3656
|
+
action.addressId,
|
|
3657
|
+
action.addressKey,
|
|
3658
|
+
true
|
|
3659
|
+
);
|
|
3660
|
+
assert2(address?.id);
|
|
3661
|
+
resource.shippingAddressIds = resource.shippingAddressIds?.filter(
|
|
3662
|
+
(id) => id !== address.id
|
|
3663
|
+
);
|
|
3664
|
+
if (resource.defaultShippingAddressId === address.id) {
|
|
3665
|
+
resource.defaultShippingAddressId = void 0;
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
removeStore(context, resource, action) {
|
|
3669
|
+
throw new Error("Method not implemented.");
|
|
3670
|
+
}
|
|
3671
|
+
setAddressCustomField(context, resource, action) {
|
|
3672
|
+
throw new Error("Method not implemented.");
|
|
3673
|
+
}
|
|
3674
|
+
setAddressCustomType(context, resource, action) {
|
|
3675
|
+
throw new Error("Method not implemented.");
|
|
3676
|
+
}
|
|
3641
3677
|
setAuthenticationMode(_context, resource, { authMode, password }) {
|
|
3642
3678
|
if (resource.authenticationMode === authMode) {
|
|
3643
3679
|
throw new CommercetoolsError(
|
|
@@ -3669,6 +3705,25 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3669
3705
|
setCompanyName(_context, resource, { companyName }) {
|
|
3670
3706
|
resource.companyName = companyName;
|
|
3671
3707
|
}
|
|
3708
|
+
setCustomerGroup(context, resource, action) {
|
|
3709
|
+
if (!action.customerGroup) {
|
|
3710
|
+
throw new CommercetoolsError(
|
|
3711
|
+
{
|
|
3712
|
+
code: "InvalidOperation",
|
|
3713
|
+
message: "CustomerGroup is required."
|
|
3714
|
+
},
|
|
3715
|
+
400
|
|
3716
|
+
);
|
|
3717
|
+
}
|
|
3718
|
+
const group = this._storage.getByResourceIdentifier(
|
|
3719
|
+
context.projectKey,
|
|
3720
|
+
action.customerGroup
|
|
3721
|
+
);
|
|
3722
|
+
resource.customerGroup = {
|
|
3723
|
+
typeId: "customer-group",
|
|
3724
|
+
id: group.id
|
|
3725
|
+
};
|
|
3726
|
+
}
|
|
3672
3727
|
setCustomerNumber(_context, resource, { customerNumber }) {
|
|
3673
3728
|
if (resource.customerNumber) {
|
|
3674
3729
|
throw new Error(
|
|
@@ -3694,6 +3749,41 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3694
3749
|
resource.custom = void 0;
|
|
3695
3750
|
}
|
|
3696
3751
|
}
|
|
3752
|
+
setDateOfBirth(context, resource, action) {
|
|
3753
|
+
resource.dateOfBirth = action.dateOfBirth;
|
|
3754
|
+
}
|
|
3755
|
+
setDefaultBillingAddress(context, resource, action) {
|
|
3756
|
+
const address = this._findAddress(
|
|
3757
|
+
resource,
|
|
3758
|
+
action.addressId,
|
|
3759
|
+
action.addressKey,
|
|
3760
|
+
true
|
|
3761
|
+
);
|
|
3762
|
+
assert2(address?.id);
|
|
3763
|
+
resource.defaultBillingAddressId = address.id;
|
|
3764
|
+
if (resource.billingAddressIds === void 0) {
|
|
3765
|
+
resource.billingAddressIds = [];
|
|
3766
|
+
}
|
|
3767
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3768
|
+
resource.billingAddressIds.push(address.id);
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
setDefaultShippingAddress(context, resource, action) {
|
|
3772
|
+
const address = this._findAddress(
|
|
3773
|
+
resource,
|
|
3774
|
+
action.addressId,
|
|
3775
|
+
action.addressKey,
|
|
3776
|
+
true
|
|
3777
|
+
);
|
|
3778
|
+
assert2(address?.id);
|
|
3779
|
+
resource.defaultShippingAddressId = address.id;
|
|
3780
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3781
|
+
resource.shippingAddressIds = [];
|
|
3782
|
+
}
|
|
3783
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3784
|
+
resource.shippingAddressIds.push(address.id);
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3697
3787
|
setExternalId(_context, resource, { externalId }) {
|
|
3698
3788
|
resource.externalId = externalId;
|
|
3699
3789
|
}
|
|
@@ -3709,12 +3799,58 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3709
3799
|
setLocale(_context, resource, { locale }) {
|
|
3710
3800
|
resource.locale = locale;
|
|
3711
3801
|
}
|
|
3802
|
+
setMiddleName(context, resource, action) {
|
|
3803
|
+
resource.middleName = action.middleName;
|
|
3804
|
+
}
|
|
3712
3805
|
setSalutation(_context, resource, { salutation }) {
|
|
3713
3806
|
resource.salutation = salutation;
|
|
3714
3807
|
}
|
|
3808
|
+
setStores(context, resource, action) {
|
|
3809
|
+
throw new Error("Method not implemented.");
|
|
3810
|
+
}
|
|
3811
|
+
setTitle(context, resource, action) {
|
|
3812
|
+
resource.title = action.title;
|
|
3813
|
+
}
|
|
3715
3814
|
setVatId(_context, resource, { vatId }) {
|
|
3716
3815
|
resource.vatId = vatId;
|
|
3717
3816
|
}
|
|
3817
|
+
_findAddress(resource, addressId, addressKey, required = false) {
|
|
3818
|
+
if (addressKey) {
|
|
3819
|
+
const address = resource.addresses.find((a) => a.key === addressKey);
|
|
3820
|
+
if (!address) {
|
|
3821
|
+
throw new CommercetoolsError(
|
|
3822
|
+
{
|
|
3823
|
+
code: "InvalidOperation",
|
|
3824
|
+
message: `Customer does not contain an address with the key ${addressKey}.`
|
|
3825
|
+
},
|
|
3826
|
+
400
|
|
3827
|
+
);
|
|
3828
|
+
}
|
|
3829
|
+
return address;
|
|
3830
|
+
}
|
|
3831
|
+
if (addressId) {
|
|
3832
|
+
const address = resource.addresses.find((a) => a.id === addressId);
|
|
3833
|
+
if (!address) {
|
|
3834
|
+
throw new CommercetoolsError(
|
|
3835
|
+
{
|
|
3836
|
+
code: "InvalidOperation",
|
|
3837
|
+
message: `Customer does not contain an address with the id ${addressId}.`
|
|
3838
|
+
},
|
|
3839
|
+
400
|
|
3840
|
+
);
|
|
3841
|
+
}
|
|
3842
|
+
return address;
|
|
3843
|
+
}
|
|
3844
|
+
if (required) {
|
|
3845
|
+
throw new CommercetoolsError(
|
|
3846
|
+
{
|
|
3847
|
+
code: "InvalidOperation",
|
|
3848
|
+
message: "One of address 'addressId' or 'addressKey' is required."
|
|
3849
|
+
},
|
|
3850
|
+
400
|
|
3851
|
+
);
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3718
3854
|
};
|
|
3719
3855
|
|
|
3720
3856
|
// src/repositories/customer/index.ts
|
|
@@ -3766,8 +3902,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3766
3902
|
]
|
|
3767
3903
|
});
|
|
3768
3904
|
};
|
|
3769
|
-
const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3770
|
-
const defaultShippingAddressId = draft.defaultShippingAddress ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3905
|
+
const defaultBillingAddressId = draft.defaultBillingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3906
|
+
const defaultShippingAddressId = draft.defaultShippingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3771
3907
|
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
3772
3908
|
(addressId) => lookupAdressId(addresses, addressId)
|
|
3773
3909
|
) ?? [];
|
|
@@ -4070,7 +4206,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
4070
4206
|
extension,
|
|
4071
4207
|
"destination.authentication.headerValue"
|
|
4072
4208
|
);
|
|
4073
|
-
} else if (extension.destination.type
|
|
4209
|
+
} else if (extension.destination.type === "AWSLambda") {
|
|
4074
4210
|
return maskSecretValue(resource, "destination.accessSecret");
|
|
4075
4211
|
}
|
|
4076
4212
|
}
|
|
@@ -4237,13 +4373,13 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
4237
4373
|
};
|
|
4238
4374
|
|
|
4239
4375
|
// src/repositories/my-order.ts
|
|
4240
|
-
import
|
|
4376
|
+
import assert5 from "assert";
|
|
4241
4377
|
|
|
4242
4378
|
// src/repositories/order/index.ts
|
|
4243
|
-
import
|
|
4379
|
+
import assert4 from "assert";
|
|
4244
4380
|
|
|
4245
4381
|
// src/repositories/order/actions.ts
|
|
4246
|
-
import
|
|
4382
|
+
import assert3 from "assert";
|
|
4247
4383
|
var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
4248
4384
|
addPayment(context, resource, { payment }) {
|
|
4249
4385
|
const resolvedPayment = this._storage.getByResourceIdentifier(
|
|
@@ -4343,7 +4479,7 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
4343
4479
|
}
|
|
4344
4480
|
}
|
|
4345
4481
|
setDeliveryCustomField(context, resource, { deliveryId, name, value }) {
|
|
4346
|
-
|
|
4482
|
+
assert3(resource.shippingInfo, "shippingInfo is not defined");
|
|
4347
4483
|
if (Array.isArray(resource.shippingInfo.deliveries)) {
|
|
4348
4484
|
resource.shippingInfo.deliveries.map((delivery) => {
|
|
4349
4485
|
if (delivery.id !== deliveryId) throw "No matching delivery id found";
|
|
@@ -4438,7 +4574,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4438
4574
|
this.actions = new OrderUpdateHandler(storage);
|
|
4439
4575
|
}
|
|
4440
4576
|
create(context, draft) {
|
|
4441
|
-
|
|
4577
|
+
assert4(draft.cart, "draft.cart is missing");
|
|
4442
4578
|
return this.createFromCart(
|
|
4443
4579
|
context,
|
|
4444
4580
|
{
|
|
@@ -4493,7 +4629,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4493
4629
|
return this.saveNew(context, resource);
|
|
4494
4630
|
}
|
|
4495
4631
|
import(context, draft) {
|
|
4496
|
-
|
|
4632
|
+
assert4(this, "OrderRepository not valid");
|
|
4497
4633
|
const resource = {
|
|
4498
4634
|
...getBaseResourceProperties(),
|
|
4499
4635
|
billingAddress: createAddress(
|
|
@@ -4636,7 +4772,7 @@ var OrderRepository = class extends AbstractResourceRepository {
|
|
|
4636
4772
|
// src/repositories/my-order.ts
|
|
4637
4773
|
var MyOrderRepository = class extends OrderRepository {
|
|
4638
4774
|
create(context, draft) {
|
|
4639
|
-
|
|
4775
|
+
assert5(draft.id, "draft.id is missing");
|
|
4640
4776
|
const cartIdentifier = {
|
|
4641
4777
|
id: draft.id,
|
|
4642
4778
|
typeId: "cart"
|
|
@@ -4887,12 +5023,12 @@ var parseFilter = (filter) => {
|
|
|
4887
5023
|
if (unique.size > 1) {
|
|
4888
5024
|
throw new Error("Invalid expression");
|
|
4889
5025
|
}
|
|
4890
|
-
if (expressions.some((expr) => expr.type
|
|
5026
|
+
if (expressions.some((expr) => expr.type === "Symbol")) {
|
|
4891
5027
|
return {
|
|
4892
5028
|
source: left,
|
|
4893
5029
|
type: "FilterExpression",
|
|
4894
5030
|
children: expressions.map((e) => {
|
|
4895
|
-
if (e.type
|
|
5031
|
+
if (e.type !== "Symbol") {
|
|
4896
5032
|
throw new Error("Invalid expression");
|
|
4897
5033
|
}
|
|
4898
5034
|
return {
|
|
@@ -4990,7 +5126,7 @@ var generateMatchFunc2 = (filter) => {
|
|
|
4990
5126
|
if (!result) {
|
|
4991
5127
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
4992
5128
|
}
|
|
4993
|
-
if (result.type
|
|
5129
|
+
if (result.type === "TermExpression") {
|
|
4994
5130
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
4995
5131
|
}
|
|
4996
5132
|
return (obj) => {
|
|
@@ -5254,7 +5390,7 @@ var applyPriceSelector = (products, selector, noScopedPrice = false) => {
|
|
|
5254
5390
|
const variants = [
|
|
5255
5391
|
product.masterVariant,
|
|
5256
5392
|
...product.variants ?? []
|
|
5257
|
-
].filter((x) => x
|
|
5393
|
+
].filter((x) => x !== void 0);
|
|
5258
5394
|
for (const variant of variants) {
|
|
5259
5395
|
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
5260
5396
|
if (scopedPrices.length > 0) {
|
|
@@ -5723,7 +5859,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5723
5859
|
);
|
|
5724
5860
|
const foundCategory = data.categories.find(
|
|
5725
5861
|
(productCategory) => {
|
|
5726
|
-
if (productCategory.id
|
|
5862
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5727
5863
|
return productCategory;
|
|
5728
5864
|
}
|
|
5729
5865
|
return false;
|
|
@@ -5740,7 +5876,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5740
5876
|
}
|
|
5741
5877
|
data.categories = data.categories.filter(
|
|
5742
5878
|
(productCategory) => {
|
|
5743
|
-
if (productCategory.id
|
|
5879
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5744
5880
|
return false;
|
|
5745
5881
|
}
|
|
5746
5882
|
return true;
|
|
@@ -6735,14 +6871,14 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6735
6871
|
}
|
|
6736
6872
|
removeEnumValues(context, resource, { attributeName, keys }) {
|
|
6737
6873
|
resource.attributes?.forEach((attr) => {
|
|
6738
|
-
if (attr.name
|
|
6739
|
-
if (attr.type.name
|
|
6874
|
+
if (attr.name === attributeName) {
|
|
6875
|
+
if (attr.type.name === "enum") {
|
|
6740
6876
|
attr.type.values = attr.type.values.filter(
|
|
6741
6877
|
(v) => !keys.includes(v.key)
|
|
6742
6878
|
);
|
|
6743
6879
|
}
|
|
6744
|
-
if (attr.type.name
|
|
6745
|
-
if (attr.type.elementType.name
|
|
6880
|
+
if (attr.type.name === "set") {
|
|
6881
|
+
if (attr.type.elementType.name === "enum") {
|
|
6746
6882
|
attr.type.elementType.values = attr.type.elementType.values.filter(
|
|
6747
6883
|
(v) => !keys.includes(v.key)
|
|
6748
6884
|
);
|