@labdigital/commercetools-mock 2.37.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.
Files changed (130) hide show
  1. package/dist/index.cjs +211 -80
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +211 -80
  4. package/dist/index.js.map +1 -1
  5. package/package.json +10 -9
  6. package/src/ctMock.ts +10 -6
  7. package/src/helpers.ts +4 -4
  8. package/src/index.ts +2 -1
  9. package/src/lib/expandParser.ts +1 -1
  10. package/src/lib/haversine.test.ts +2 -1
  11. package/src/lib/password.ts +2 -2
  12. package/src/lib/predicateParser.ts +1 -1
  13. package/src/lib/productSearchFilter.test.ts +4 -1
  14. package/src/lib/projectionSearchFilter.ts +3 -3
  15. package/src/oauth/helpers.ts +1 -1
  16. package/src/oauth/server.test.ts +2 -1
  17. package/src/oauth/server.ts +5 -8
  18. package/src/oauth/store.ts +1 -1
  19. package/src/priceSelector.ts +1 -1
  20. package/src/product-projection-search.ts +4 -2
  21. package/src/product-search.ts +2 -2
  22. package/src/projectAPI.ts +4 -4
  23. package/src/repositories/abstract.ts +20 -3
  24. package/src/repositories/associate-role.ts +3 -3
  25. package/src/repositories/attribute-group.ts +3 -3
  26. package/src/repositories/business-unit.ts +6 -4
  27. package/src/repositories/cart/actions.ts +6 -7
  28. package/src/repositories/cart/helpers.ts +1 -1
  29. package/src/repositories/cart/index.ts +1 -1
  30. package/src/repositories/cart-discount/actions.ts +2 -5
  31. package/src/repositories/cart-discount/index.ts +1 -1
  32. package/src/repositories/category/actions.ts +4 -7
  33. package/src/repositories/category/index.ts +3 -3
  34. package/src/repositories/channel.ts +2 -2
  35. package/src/repositories/custom-object.ts +3 -6
  36. package/src/repositories/customer/actions.ts +272 -68
  37. package/src/repositories/customer/index.ts +10 -8
  38. package/src/repositories/customer-group.ts +2 -2
  39. package/src/repositories/discount-code/actions.ts +2 -5
  40. package/src/repositories/discount-code/index.ts +1 -1
  41. package/src/repositories/extension.ts +3 -3
  42. package/src/repositories/helpers.ts +4 -2
  43. package/src/repositories/index.ts +1 -1
  44. package/src/repositories/inventory-entry/actions.ts +2 -5
  45. package/src/repositories/inventory-entry/index.ts +1 -1
  46. package/src/repositories/my-customer.ts +2 -2
  47. package/src/repositories/order/actions.ts +2 -5
  48. package/src/repositories/order/index.ts +3 -6
  49. package/src/repositories/order-edit.ts +3 -2
  50. package/src/repositories/payment/actions.ts +2 -5
  51. package/src/repositories/payment/helpers.ts +6 -3
  52. package/src/repositories/payment/index.ts +3 -2
  53. package/src/repositories/product/actions.ts +2 -2
  54. package/src/repositories/product/helpers.ts +4 -4
  55. package/src/repositories/product/index.ts +3 -2
  56. package/src/repositories/product-discount.ts +3 -7
  57. package/src/repositories/product-projection.ts +2 -5
  58. package/src/repositories/product-selection.ts +3 -7
  59. package/src/repositories/product-tailoring.ts +3 -7
  60. package/src/repositories/product-type.ts +7 -11
  61. package/src/repositories/project.ts +4 -8
  62. package/src/repositories/quote-request.ts +3 -2
  63. package/src/repositories/quote.ts +3 -2
  64. package/src/repositories/review.ts +6 -3
  65. package/src/repositories/shipping-method/actions.ts +5 -6
  66. package/src/repositories/shipping-method/helpers.ts +4 -1
  67. package/src/repositories/shipping-method/index.ts +3 -6
  68. package/src/repositories/shopping-list/actions.ts +3 -6
  69. package/src/repositories/shopping-list/index.ts +4 -3
  70. package/src/repositories/staged-quote.ts +3 -2
  71. package/src/repositories/standalone-price.ts +3 -7
  72. package/src/repositories/state.ts +3 -7
  73. package/src/repositories/store.ts +3 -7
  74. package/src/repositories/subscription.ts +4 -8
  75. package/src/repositories/tax-category/actions.ts +2 -1
  76. package/src/repositories/tax-category/helpers.ts +1 -1
  77. package/src/repositories/tax-category/index.ts +3 -2
  78. package/src/repositories/type/actions.ts +2 -1
  79. package/src/repositories/type/index.ts +3 -2
  80. package/src/repositories/zone.ts +3 -7
  81. package/src/services/abstract.ts +2 -2
  82. package/src/services/associate-roles.test.ts +1 -1
  83. package/src/services/associate-roles.ts +2 -2
  84. package/src/services/attribute-group.ts +2 -2
  85. package/src/services/business-units.test.ts +1 -1
  86. package/src/services/business-units.ts +2 -2
  87. package/src/services/cart-discount.test.ts +1 -1
  88. package/src/services/cart-discount.ts +2 -2
  89. package/src/services/category.ts +2 -2
  90. package/src/services/channel.ts +2 -2
  91. package/src/services/customer-group.ts +2 -2
  92. package/src/services/customer.test.ts +422 -132
  93. package/src/services/customer.ts +4 -3
  94. package/src/services/discount-code.ts +2 -2
  95. package/src/services/extension.ts +2 -2
  96. package/src/services/index.ts +1 -1
  97. package/src/services/inventory-entry.ts +2 -2
  98. package/src/services/my-business-unit.ts +1 -1
  99. package/src/services/my-cart.ts +3 -2
  100. package/src/services/my-customer.ts +4 -3
  101. package/src/services/my-order.ts +1 -1
  102. package/src/services/my-payment.ts +2 -2
  103. package/src/services/my-shopping-list.ts +2 -2
  104. package/src/services/order.ts +2 -2
  105. package/src/services/payment.ts +2 -2
  106. package/src/services/product-discount.ts +2 -2
  107. package/src/services/product-projection.test.ts +1 -1
  108. package/src/services/product-projection.ts +2 -2
  109. package/src/services/product-selection.ts +2 -2
  110. package/src/services/product-type.ts +2 -2
  111. package/src/services/product.test.ts +1 -1
  112. package/src/services/product.ts +2 -2
  113. package/src/services/project.ts +3 -3
  114. package/src/services/reviews.ts +2 -2
  115. package/src/services/shipping-method.ts +2 -2
  116. package/src/services/shopping-list.test.ts +1 -1
  117. package/src/services/shopping-list.ts +2 -2
  118. package/src/services/standalone-price.ts +2 -2
  119. package/src/services/state.ts +2 -2
  120. package/src/services/store.ts +2 -2
  121. package/src/services/subscription.ts +2 -2
  122. package/src/services/tax-category.ts +2 -2
  123. package/src/services/type.ts +2 -2
  124. package/src/services/zone.ts +2 -2
  125. package/src/shipping.test.ts +1 -1
  126. package/src/shipping.ts +3 -3
  127. package/src/storage/abstract.ts +5 -1
  128. package/src/storage/in-memory.ts +6 -8
  129. package/src/types.ts +2 -2
  130. 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 import_crypto = require("crypto");
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, import_crypto.randomBytes)(16).toString("base64"),
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, import_crypto.randomBytes)(16).toString("base64")}`
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, import_crypto.randomBytes)(16).toString("base64"),
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, import_crypto.randomBytes)(16).toString("base64")}`
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, import_crypto.randomBytes)(16).toString("base64"),
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, import_crypto.randomBytes)(16).toString("base64")}`
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, import_crypto.randomBytes)(16).toString("base64")
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 == void 0) {
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 == void 0) {
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 != "string") {
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 != updatedResource.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}`);
@@ -3591,6 +3604,7 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
3591
3604
  };
3592
3605
 
3593
3606
  // src/repositories/customer/actions.ts
3607
+ var import_node_assert = __toESM(require("assert"), 1);
3594
3608
  var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3595
3609
  addAddress(_context, resource, { address }) {
3596
3610
  resource.addresses.push({
@@ -3599,67 +3613,35 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3599
3613
  });
3600
3614
  }
3601
3615
  addBillingAddressId(_context, resource, { addressId, addressKey }) {
3602
- const address = resource.addresses.find((a) => {
3603
- if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
3604
- return true;
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
- );
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 = [];
3616
3620
  }
3617
- const billingAddressId = String(address.id);
3618
- if (resource.billingAddressIds?.length) {
3619
- resource.billingAddressIds.push(billingAddressId);
3620
- } else if (address) {
3621
- resource.billingAddressIds = [billingAddressId];
3621
+ if (!resource.billingAddressIds.includes(address.id)) {
3622
+ resource.billingAddressIds.push(address.id);
3622
3623
  }
3623
3624
  }
3624
3625
  addShippingAddressId(_context, resource, { addressId, addressKey }) {
3625
- const address = resource.addresses.find((a) => {
3626
- if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
3627
- return true;
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
- );
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 = [];
3639
3630
  }
3640
- const shippingAddressId = String(address.id);
3641
- if (resource.shippingAddressIds?.length) {
3642
- resource.shippingAddressIds.push(shippingAddressId);
3643
- } else if (address) {
3644
- resource.shippingAddressIds = [shippingAddressId];
3631
+ if (!resource.shippingAddressIds.includes(address.id)) {
3632
+ resource.shippingAddressIds.push(address.id);
3645
3633
  }
3634
+ return resource;
3635
+ }
3636
+ addStore(context, resource, action) {
3637
+ throw new Error("Method not implemented.");
3646
3638
  }
3647
3639
  changeAddress(context, resource, { addressId, addressKey, address }) {
3648
- const oldAddressIndex = resource.addresses.findIndex((a) => {
3649
- if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
3650
- return true;
3651
- }
3652
- return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
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
- }
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
+ );
3663
3645
  const newAddress = createAddress(
3664
3646
  address,
3665
3647
  context.projectKey,
@@ -3675,6 +3657,55 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3675
3657
  changeEmail(_context, resource, { email }) {
3676
3658
  resource.email = email;
3677
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
+ }
3678
3709
  setAuthenticationMode(_context, resource, { authMode, password }) {
3679
3710
  if (resource.authenticationMode === authMode) {
3680
3711
  throw new CommercetoolsError(
@@ -3706,6 +3737,25 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3706
3737
  setCompanyName(_context, resource, { companyName }) {
3707
3738
  resource.companyName = companyName;
3708
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
+ }
3709
3759
  setCustomerNumber(_context, resource, { customerNumber }) {
3710
3760
  if (resource.customerNumber) {
3711
3761
  throw new Error(
@@ -3731,6 +3781,41 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3731
3781
  resource.custom = void 0;
3732
3782
  }
3733
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
+ }
3734
3819
  setExternalId(_context, resource, { externalId }) {
3735
3820
  resource.externalId = externalId;
3736
3821
  }
@@ -3746,12 +3831,58 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3746
3831
  setLocale(_context, resource, { locale }) {
3747
3832
  resource.locale = locale;
3748
3833
  }
3834
+ setMiddleName(context, resource, action) {
3835
+ resource.middleName = action.middleName;
3836
+ }
3749
3837
  setSalutation(_context, resource, { salutation }) {
3750
3838
  resource.salutation = salutation;
3751
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
+ }
3752
3846
  setVatId(_context, resource, { vatId }) {
3753
3847
  resource.vatId = vatId;
3754
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
+ }
3755
3886
  };
3756
3887
 
3757
3888
  // src/repositories/customer/index.ts
@@ -3803,8 +3934,8 @@ var CustomerRepository = class extends AbstractResourceRepository {
3803
3934
  ]
3804
3935
  });
3805
3936
  };
3806
- const defaultBillingAddressId = draft.defaultBillingAddress ? lookupAdressId(addresses, draft.defaultBillingAddress) : void 0;
3807
- 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;
3808
3939
  const shippingAddressIds = draft.shippingAddresses?.map(
3809
3940
  (addressId) => lookupAdressId(addresses, addressId)
3810
3941
  ) ?? [];
@@ -4107,7 +4238,7 @@ var ExtensionRepository = class extends AbstractResourceRepository {
4107
4238
  extension,
4108
4239
  "destination.authentication.headerValue"
4109
4240
  );
4110
- } else if (extension.destination.type == "AWSLambda") {
4241
+ } else if (extension.destination.type === "AWSLambda") {
4111
4242
  return maskSecretValue(resource, "destination.accessSecret");
4112
4243
  }
4113
4244
  }
@@ -4924,12 +5055,12 @@ var parseFilter = (filter) => {
4924
5055
  if (unique.size > 1) {
4925
5056
  throw new Error("Invalid expression");
4926
5057
  }
4927
- if (expressions.some((expr) => expr.type == "Symbol")) {
5058
+ if (expressions.some((expr) => expr.type === "Symbol")) {
4928
5059
  return {
4929
5060
  source: left,
4930
5061
  type: "FilterExpression",
4931
5062
  children: expressions.map((e) => {
4932
- if (e.type != "Symbol") {
5063
+ if (e.type !== "Symbol") {
4933
5064
  throw new Error("Invalid expression");
4934
5065
  }
4935
5066
  return {
@@ -5027,7 +5158,7 @@ var generateMatchFunc2 = (filter) => {
5027
5158
  if (!result) {
5028
5159
  throw new Error(`Syntax error while parsing '${filter}'.`);
5029
5160
  }
5030
- if (result.type == "TermExpression") {
5161
+ if (result.type === "TermExpression") {
5031
5162
  throw new Error(`Syntax error while parsing '${filter}'.`);
5032
5163
  }
5033
5164
  return (obj) => {
@@ -5291,7 +5422,7 @@ var applyPriceSelector = (products, selector, noScopedPrice = false) => {
5291
5422
  const variants = [
5292
5423
  product.masterVariant,
5293
5424
  ...product.variants ?? []
5294
- ].filter((x) => x != void 0);
5425
+ ].filter((x) => x !== void 0);
5295
5426
  for (const variant of variants) {
5296
5427
  const scopedPrices = variant.prices?.filter((p) => priceSelectorFilter(p, selector)) ?? [];
5297
5428
  if (scopedPrices.length > 0) {
@@ -5760,7 +5891,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
5760
5891
  );
5761
5892
  const foundCategory = data.categories.find(
5762
5893
  (productCategory) => {
5763
- if (productCategory.id == resolvedCategory.id) {
5894
+ if (productCategory.id === resolvedCategory.id) {
5764
5895
  return productCategory;
5765
5896
  }
5766
5897
  return false;
@@ -5777,7 +5908,7 @@ var ProductUpdateHandler = class extends AbstractUpdateHandler {
5777
5908
  }
5778
5909
  data.categories = data.categories.filter(
5779
5910
  (productCategory) => {
5780
- if (productCategory.id == resolvedCategory.id) {
5911
+ if (productCategory.id === resolvedCategory.id) {
5781
5912
  return false;
5782
5913
  }
5783
5914
  return true;
@@ -6772,14 +6903,14 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
6772
6903
  }
6773
6904
  removeEnumValues(context, resource, { attributeName, keys }) {
6774
6905
  resource.attributes?.forEach((attr) => {
6775
- if (attr.name == attributeName) {
6776
- if (attr.type.name == "enum") {
6906
+ if (attr.name === attributeName) {
6907
+ if (attr.type.name === "enum") {
6777
6908
  attr.type.values = attr.type.values.filter(
6778
6909
  (v) => !keys.includes(v.key)
6779
6910
  );
6780
6911
  }
6781
- if (attr.type.name == "set") {
6782
- if (attr.type.elementType.name == "enum") {
6912
+ if (attr.type.name === "set") {
6913
+ if (attr.type.elementType.name === "enum") {
6783
6914
  attr.type.elementType.values = attr.type.elementType.values.filter(
6784
6915
  (v) => !keys.includes(v.key)
6785
6916
  );