@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.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 {
|
|
@@ -489,7 +489,7 @@ var nestedLookup = (obj, path) => {
|
|
|
489
489
|
let val = obj;
|
|
490
490
|
for (let i = 0; i < parts.length; i++) {
|
|
491
491
|
const part = parts[i];
|
|
492
|
-
if (val
|
|
492
|
+
if (val === void 0) {
|
|
493
493
|
return void 0;
|
|
494
494
|
}
|
|
495
495
|
val = val[part];
|
|
@@ -497,7 +497,7 @@ var nestedLookup = (obj, path) => {
|
|
|
497
497
|
return val;
|
|
498
498
|
};
|
|
499
499
|
var queryParamsArray = (input) => {
|
|
500
|
-
if (input
|
|
500
|
+
if (input === void 0) {
|
|
501
501
|
return void 0;
|
|
502
502
|
}
|
|
503
503
|
const values = Array.isArray(input) ? input : [input];
|
|
@@ -596,7 +596,7 @@ var parseExpandClause = (clause) => {
|
|
|
596
596
|
}
|
|
597
597
|
const match = result.element.match(/\[([^\]+])]/);
|
|
598
598
|
if (match) {
|
|
599
|
-
result.index = match[1] === "*" ? "*" : parseInt(match[1], 10);
|
|
599
|
+
result.index = match[1] === "*" ? "*" : Number.parseInt(match[1], 10);
|
|
600
600
|
result.element = result.element.substring(0, match.index);
|
|
601
601
|
}
|
|
602
602
|
return result;
|
|
@@ -1380,7 +1380,7 @@ var generateMatchFunc = (predicate) => {
|
|
|
1380
1380
|
return (obj, vars) => {
|
|
1381
1381
|
const value = resolveValue(obj, left);
|
|
1382
1382
|
const other = resolveSymbol(expr, vars);
|
|
1383
|
-
if (typeof value
|
|
1383
|
+
if (typeof value !== "string") {
|
|
1384
1384
|
throw new PredicateError(
|
|
1385
1385
|
`The field '${left.value}' does not support this expression.`
|
|
1386
1386
|
);
|
|
@@ -1818,7 +1818,7 @@ var AbstractRepository = class {
|
|
|
1818
1818
|
version,
|
|
1819
1819
|
actions
|
|
1820
1820
|
);
|
|
1821
|
-
if (resource.version
|
|
1821
|
+
if (resource.version !== updatedResource.version) {
|
|
1822
1822
|
this.saveUpdate(context, version, updatedResource);
|
|
1823
1823
|
}
|
|
1824
1824
|
const result = this.postProcessResource(context, updatedResource);
|
|
@@ -1925,6 +1925,19 @@ var AbstractUpdateHandler = class {
|
|
|
1925
1925
|
const updatedResource = cloneObject(resource);
|
|
1926
1926
|
const identifier = resource.id ? resource.id : resource.key;
|
|
1927
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
|
+
}
|
|
1928
1941
|
const updateFunc = this[action.action].bind(this);
|
|
1929
1942
|
if (!updateFunc) {
|
|
1930
1943
|
console.error(`No mock implemented for update action ${action.action}`);
|
|
@@ -3195,6 +3208,11 @@ var CartDiscountUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3195
3208
|
setKey(context, resource, { key }) {
|
|
3196
3209
|
resource.key = key;
|
|
3197
3210
|
}
|
|
3211
|
+
setStores(context, resource, { stores }) {
|
|
3212
|
+
resource.stores = stores?.map(
|
|
3213
|
+
(s) => getStoreKeyReference(s, context.projectKey, this._storage)
|
|
3214
|
+
);
|
|
3215
|
+
}
|
|
3198
3216
|
setValidFrom(context, resource, { validFrom }) {
|
|
3199
3217
|
resource.validFrom = validFrom;
|
|
3200
3218
|
}
|
|
@@ -3591,6 +3609,7 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3591
3609
|
};
|
|
3592
3610
|
|
|
3593
3611
|
// src/repositories/customer/actions.ts
|
|
3612
|
+
var import_node_assert = __toESM(require("assert"), 1);
|
|
3594
3613
|
var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
3595
3614
|
addAddress(_context, resource, { address }) {
|
|
3596
3615
|
resource.addresses.push({
|
|
@@ -3599,67 +3618,35 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3599
3618
|
});
|
|
3600
3619
|
}
|
|
3601
3620
|
addBillingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3602
|
-
const address =
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3607
|
-
});
|
|
3608
|
-
if (!address) {
|
|
3609
|
-
throw new CommercetoolsError(
|
|
3610
|
-
{
|
|
3611
|
-
code: "InvalidInput",
|
|
3612
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3613
|
-
},
|
|
3614
|
-
400
|
|
3615
|
-
);
|
|
3621
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3622
|
+
(0, import_node_assert.default)(address?.id);
|
|
3623
|
+
if (resource.billingAddressIds === void 0) {
|
|
3624
|
+
resource.billingAddressIds = [];
|
|
3616
3625
|
}
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
resource.billingAddressIds.push(billingAddressId);
|
|
3620
|
-
} else if (address) {
|
|
3621
|
-
resource.billingAddressIds = [billingAddressId];
|
|
3626
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3627
|
+
resource.billingAddressIds.push(address.id);
|
|
3622
3628
|
}
|
|
3623
3629
|
}
|
|
3624
3630
|
addShippingAddressId(_context, resource, { addressId, addressKey }) {
|
|
3625
|
-
const address =
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3630
|
-
});
|
|
3631
|
-
if (!address) {
|
|
3632
|
-
throw new CommercetoolsError(
|
|
3633
|
-
{
|
|
3634
|
-
code: "InvalidInput",
|
|
3635
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3636
|
-
},
|
|
3637
|
-
400
|
|
3638
|
-
);
|
|
3631
|
+
const address = this._findAddress(resource, addressId, addressKey, true);
|
|
3632
|
+
(0, import_node_assert.default)(address?.id);
|
|
3633
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3634
|
+
resource.shippingAddressIds = [];
|
|
3639
3635
|
}
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
resource.shippingAddressIds.push(shippingAddressId);
|
|
3643
|
-
} else if (address) {
|
|
3644
|
-
resource.shippingAddressIds = [shippingAddressId];
|
|
3636
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3637
|
+
resource.shippingAddressIds.push(address.id);
|
|
3645
3638
|
}
|
|
3639
|
+
return resource;
|
|
3640
|
+
}
|
|
3641
|
+
addStore(context, resource, action) {
|
|
3642
|
+
throw new Error("Method not implemented.");
|
|
3646
3643
|
}
|
|
3647
3644
|
changeAddress(context, resource, { addressId, addressKey, address }) {
|
|
3648
|
-
const
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
});
|
|
3654
|
-
if (oldAddressIndex === -1) {
|
|
3655
|
-
throw new CommercetoolsError(
|
|
3656
|
-
{
|
|
3657
|
-
code: "InvalidInput",
|
|
3658
|
-
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3659
|
-
},
|
|
3660
|
-
400
|
|
3661
|
-
);
|
|
3662
|
-
}
|
|
3645
|
+
const current = this._findAddress(resource, addressId, addressKey, true);
|
|
3646
|
+
(0, import_node_assert.default)(current?.id);
|
|
3647
|
+
const oldAddressIndex = resource.addresses.findIndex(
|
|
3648
|
+
(a) => a.id === current.id
|
|
3649
|
+
);
|
|
3663
3650
|
const newAddress = createAddress(
|
|
3664
3651
|
address,
|
|
3665
3652
|
context.projectKey,
|
|
@@ -3675,6 +3662,55 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3675
3662
|
changeEmail(_context, resource, { email }) {
|
|
3676
3663
|
resource.email = email;
|
|
3677
3664
|
}
|
|
3665
|
+
removeAddress(context, resource, action) {
|
|
3666
|
+
const address = this._findAddress(
|
|
3667
|
+
resource,
|
|
3668
|
+
action.addressId,
|
|
3669
|
+
action.addressKey,
|
|
3670
|
+
true
|
|
3671
|
+
);
|
|
3672
|
+
(0, import_node_assert.default)(address?.id);
|
|
3673
|
+
resource.addresses = resource.addresses.filter((a) => a.id !== address.id);
|
|
3674
|
+
}
|
|
3675
|
+
removeBillingAddressId(context, resource, action) {
|
|
3676
|
+
const address = this._findAddress(
|
|
3677
|
+
resource,
|
|
3678
|
+
action.addressId,
|
|
3679
|
+
action.addressKey,
|
|
3680
|
+
true
|
|
3681
|
+
);
|
|
3682
|
+
(0, import_node_assert.default)(address?.id);
|
|
3683
|
+
resource.billingAddressIds = resource.billingAddressIds?.filter(
|
|
3684
|
+
(id) => id !== address.id
|
|
3685
|
+
);
|
|
3686
|
+
if (resource.defaultBillingAddressId === address.id) {
|
|
3687
|
+
resource.defaultBillingAddressId = void 0;
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
removeShippingAddressId(context, resource, action) {
|
|
3691
|
+
const address = this._findAddress(
|
|
3692
|
+
resource,
|
|
3693
|
+
action.addressId,
|
|
3694
|
+
action.addressKey,
|
|
3695
|
+
true
|
|
3696
|
+
);
|
|
3697
|
+
(0, import_node_assert.default)(address?.id);
|
|
3698
|
+
resource.shippingAddressIds = resource.shippingAddressIds?.filter(
|
|
3699
|
+
(id) => id !== address.id
|
|
3700
|
+
);
|
|
3701
|
+
if (resource.defaultShippingAddressId === address.id) {
|
|
3702
|
+
resource.defaultShippingAddressId = void 0;
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
removeStore(context, resource, action) {
|
|
3706
|
+
throw new Error("Method not implemented.");
|
|
3707
|
+
}
|
|
3708
|
+
setAddressCustomField(context, resource, action) {
|
|
3709
|
+
throw new Error("Method not implemented.");
|
|
3710
|
+
}
|
|
3711
|
+
setAddressCustomType(context, resource, action) {
|
|
3712
|
+
throw new Error("Method not implemented.");
|
|
3713
|
+
}
|
|
3678
3714
|
setAuthenticationMode(_context, resource, { authMode, password }) {
|
|
3679
3715
|
if (resource.authenticationMode === authMode) {
|
|
3680
3716
|
throw new CommercetoolsError(
|
|
@@ -3706,6 +3742,25 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3706
3742
|
setCompanyName(_context, resource, { companyName }) {
|
|
3707
3743
|
resource.companyName = companyName;
|
|
3708
3744
|
}
|
|
3745
|
+
setCustomerGroup(context, resource, action) {
|
|
3746
|
+
if (!action.customerGroup) {
|
|
3747
|
+
throw new CommercetoolsError(
|
|
3748
|
+
{
|
|
3749
|
+
code: "InvalidOperation",
|
|
3750
|
+
message: "CustomerGroup is required."
|
|
3751
|
+
},
|
|
3752
|
+
400
|
|
3753
|
+
);
|
|
3754
|
+
}
|
|
3755
|
+
const group = this._storage.getByResourceIdentifier(
|
|
3756
|
+
context.projectKey,
|
|
3757
|
+
action.customerGroup
|
|
3758
|
+
);
|
|
3759
|
+
resource.customerGroup = {
|
|
3760
|
+
typeId: "customer-group",
|
|
3761
|
+
id: group.id
|
|
3762
|
+
};
|
|
3763
|
+
}
|
|
3709
3764
|
setCustomerNumber(_context, resource, { customerNumber }) {
|
|
3710
3765
|
if (resource.customerNumber) {
|
|
3711
3766
|
throw new Error(
|
|
@@ -3731,6 +3786,41 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3731
3786
|
resource.custom = void 0;
|
|
3732
3787
|
}
|
|
3733
3788
|
}
|
|
3789
|
+
setDateOfBirth(context, resource, action) {
|
|
3790
|
+
resource.dateOfBirth = action.dateOfBirth;
|
|
3791
|
+
}
|
|
3792
|
+
setDefaultBillingAddress(context, resource, action) {
|
|
3793
|
+
const address = this._findAddress(
|
|
3794
|
+
resource,
|
|
3795
|
+
action.addressId,
|
|
3796
|
+
action.addressKey,
|
|
3797
|
+
true
|
|
3798
|
+
);
|
|
3799
|
+
(0, import_node_assert.default)(address?.id);
|
|
3800
|
+
resource.defaultBillingAddressId = address.id;
|
|
3801
|
+
if (resource.billingAddressIds === void 0) {
|
|
3802
|
+
resource.billingAddressIds = [];
|
|
3803
|
+
}
|
|
3804
|
+
if (!resource.billingAddressIds.includes(address.id)) {
|
|
3805
|
+
resource.billingAddressIds.push(address.id);
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
setDefaultShippingAddress(context, resource, action) {
|
|
3809
|
+
const address = this._findAddress(
|
|
3810
|
+
resource,
|
|
3811
|
+
action.addressId,
|
|
3812
|
+
action.addressKey,
|
|
3813
|
+
true
|
|
3814
|
+
);
|
|
3815
|
+
(0, import_node_assert.default)(address?.id);
|
|
3816
|
+
resource.defaultShippingAddressId = address.id;
|
|
3817
|
+
if (resource.shippingAddressIds === void 0) {
|
|
3818
|
+
resource.shippingAddressIds = [];
|
|
3819
|
+
}
|
|
3820
|
+
if (!resource.shippingAddressIds.includes(address.id)) {
|
|
3821
|
+
resource.shippingAddressIds.push(address.id);
|
|
3822
|
+
}
|
|
3823
|
+
}
|
|
3734
3824
|
setExternalId(_context, resource, { externalId }) {
|
|
3735
3825
|
resource.externalId = externalId;
|
|
3736
3826
|
}
|
|
@@ -3746,12 +3836,58 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3746
3836
|
setLocale(_context, resource, { locale }) {
|
|
3747
3837
|
resource.locale = locale;
|
|
3748
3838
|
}
|
|
3839
|
+
setMiddleName(context, resource, action) {
|
|
3840
|
+
resource.middleName = action.middleName;
|
|
3841
|
+
}
|
|
3749
3842
|
setSalutation(_context, resource, { salutation }) {
|
|
3750
3843
|
resource.salutation = salutation;
|
|
3751
3844
|
}
|
|
3845
|
+
setStores(context, resource, action) {
|
|
3846
|
+
throw new Error("Method not implemented.");
|
|
3847
|
+
}
|
|
3848
|
+
setTitle(context, resource, action) {
|
|
3849
|
+
resource.title = action.title;
|
|
3850
|
+
}
|
|
3752
3851
|
setVatId(_context, resource, { vatId }) {
|
|
3753
3852
|
resource.vatId = vatId;
|
|
3754
3853
|
}
|
|
3854
|
+
_findAddress(resource, addressId, addressKey, required = false) {
|
|
3855
|
+
if (addressKey) {
|
|
3856
|
+
const address = resource.addresses.find((a) => a.key === addressKey);
|
|
3857
|
+
if (!address) {
|
|
3858
|
+
throw new CommercetoolsError(
|
|
3859
|
+
{
|
|
3860
|
+
code: "InvalidOperation",
|
|
3861
|
+
message: `Customer does not contain an address with the key ${addressKey}.`
|
|
3862
|
+
},
|
|
3863
|
+
400
|
|
3864
|
+
);
|
|
3865
|
+
}
|
|
3866
|
+
return address;
|
|
3867
|
+
}
|
|
3868
|
+
if (addressId) {
|
|
3869
|
+
const address = resource.addresses.find((a) => a.id === addressId);
|
|
3870
|
+
if (!address) {
|
|
3871
|
+
throw new CommercetoolsError(
|
|
3872
|
+
{
|
|
3873
|
+
code: "InvalidOperation",
|
|
3874
|
+
message: `Customer does not contain an address with the id ${addressId}.`
|
|
3875
|
+
},
|
|
3876
|
+
400
|
|
3877
|
+
);
|
|
3878
|
+
}
|
|
3879
|
+
return address;
|
|
3880
|
+
}
|
|
3881
|
+
if (required) {
|
|
3882
|
+
throw new CommercetoolsError(
|
|
3883
|
+
{
|
|
3884
|
+
code: "InvalidOperation",
|
|
3885
|
+
message: "One of address 'addressId' or 'addressKey' is required."
|
|
3886
|
+
},
|
|
3887
|
+
400
|
|
3888
|
+
);
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3755
3891
|
};
|
|
3756
3892
|
|
|
3757
3893
|
// src/repositories/customer/index.ts
|
|
@@ -3803,8 +3939,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3803
3939
|
]
|
|
3804
3940
|
});
|
|
3805
3941
|
};
|
|
3806
|
-
const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3807
|
-
const defaultShippingAddressId = draft.defaultShippingAddress ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3942
|
+
const defaultBillingAddressId = draft.defaultBillingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
|
|
3943
|
+
const defaultShippingAddressId = draft.defaultShippingAddress !== void 0 ? lookupAdressId(addresses, draft.defaultShippingAddress) : void 0;
|
|
3808
3944
|
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
3809
3945
|
(addressId) => lookupAdressId(addresses, addressId)
|
|
3810
3946
|
) ?? [];
|
|
@@ -4107,7 +4243,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
|
|
|
4107
4243
|
extension,
|
|
4108
4244
|
"destination.authentication.headerValue"
|
|
4109
4245
|
);
|
|
4110
|
-
} else if (extension.destination.type
|
|
4246
|
+
} else if (extension.destination.type === "AWSLambda") {
|
|
4111
4247
|
return maskSecretValue(resource, "destination.accessSecret");
|
|
4112
4248
|
}
|
|
4113
4249
|
}
|
|
@@ -4924,12 +5060,12 @@ var parseFilter = (filter) => {
|
|
|
4924
5060
|
if (unique.size > 1) {
|
|
4925
5061
|
throw new Error("Invalid expression");
|
|
4926
5062
|
}
|
|
4927
|
-
if (expressions.some((expr) => expr.type
|
|
5063
|
+
if (expressions.some((expr) => expr.type === "Symbol")) {
|
|
4928
5064
|
return {
|
|
4929
5065
|
source: left,
|
|
4930
5066
|
type: "FilterExpression",
|
|
4931
5067
|
children: expressions.map((e) => {
|
|
4932
|
-
if (e.type
|
|
5068
|
+
if (e.type !== "Symbol") {
|
|
4933
5069
|
throw new Error("Invalid expression");
|
|
4934
5070
|
}
|
|
4935
5071
|
return {
|
|
@@ -5027,7 +5163,7 @@ var generateMatchFunc2 = (filter) => {
|
|
|
5027
5163
|
if (!result) {
|
|
5028
5164
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
5029
5165
|
}
|
|
5030
|
-
if (result.type
|
|
5166
|
+
if (result.type === "TermExpression") {
|
|
5031
5167
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
5032
5168
|
}
|
|
5033
5169
|
return (obj) => {
|
|
@@ -5291,7 +5427,7 @@ var applyPriceSelector = (products, selector, noScopedPrice = false) => {
|
|
|
5291
5427
|
const variants = [
|
|
5292
5428
|
product.masterVariant,
|
|
5293
5429
|
...product.variants ?? []
|
|
5294
|
-
].filter((x) => x
|
|
5430
|
+
].filter((x) => x !== void 0);
|
|
5295
5431
|
for (const variant of variants) {
|
|
5296
5432
|
const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
|
|
5297
5433
|
if (scopedPrices.length > 0) {
|
|
@@ -5760,7 +5896,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5760
5896
|
);
|
|
5761
5897
|
const foundCategory = data.categories.find(
|
|
5762
5898
|
(productCategory) => {
|
|
5763
|
-
if (productCategory.id
|
|
5899
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5764
5900
|
return productCategory;
|
|
5765
5901
|
}
|
|
5766
5902
|
return false;
|
|
@@ -5777,7 +5913,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5777
5913
|
}
|
|
5778
5914
|
data.categories = data.categories.filter(
|
|
5779
5915
|
(productCategory) => {
|
|
5780
|
-
if (productCategory.id
|
|
5916
|
+
if (productCategory.id === resolvedCategory.id) {
|
|
5781
5917
|
return false;
|
|
5782
5918
|
}
|
|
5783
5919
|
return true;
|
|
@@ -6772,14 +6908,14 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6772
6908
|
}
|
|
6773
6909
|
removeEnumValues(context, resource, { attributeName, keys }) {
|
|
6774
6910
|
resource.attributes?.forEach((attr) => {
|
|
6775
|
-
if (attr.name
|
|
6776
|
-
if (attr.type.name
|
|
6911
|
+
if (attr.name === attributeName) {
|
|
6912
|
+
if (attr.type.name === "enum") {
|
|
6777
6913
|
attr.type.values = attr.type.values.filter(
|
|
6778
6914
|
(v) => !keys.includes(v.key)
|
|
6779
6915
|
);
|
|
6780
6916
|
}
|
|
6781
|
-
if (attr.type.name
|
|
6782
|
-
if (attr.type.elementType.name
|
|
6917
|
+
if (attr.type.name === "set") {
|
|
6918
|
+
if (attr.type.elementType.name === "enum") {
|
|
6783
6919
|
attr.type.elementType.values = attr.type.elementType.values.filter(
|
|
6784
6920
|
(v) => !keys.includes(v.key)
|
|
6785
6921
|
);
|