@labdigital/commercetools-mock 2.60.0 → 2.61.1

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 (223) hide show
  1. package/dist/{index.d.ts → index.d.mts} +154 -275
  2. package/dist/{index.js → index.mjs} +255 -359
  3. package/dist/index.mjs.map +1 -0
  4. package/package.json +30 -18
  5. package/src/config.ts +1 -1
  6. package/src/ctMock.test.ts +1 -1
  7. package/src/ctMock.ts +22 -21
  8. package/src/index.test.ts +1 -1
  9. package/src/index.ts +3 -3
  10. package/src/lib/haversine.test.ts +2 -2
  11. package/src/lib/masking.ts +1 -1
  12. package/src/lib/parser.ts +2 -2
  13. package/src/lib/password.ts +1 -1
  14. package/src/lib/predicateParser.test.ts +1 -1
  15. package/src/lib/predicateParser.ts +4 -4
  16. package/src/lib/product-review-statistics.test.ts +4 -8
  17. package/src/lib/productSearchFilter.test.ts +3 -3
  18. package/src/lib/productSearchFilter.ts +6 -6
  19. package/src/lib/projectionSearchFilter.test.ts +3 -3
  20. package/src/lib/projectionSearchFilter.ts +4 -4
  21. package/src/lib/review-statistics.ts +1 -1
  22. package/src/lib/searchQueryTypeChecker.test.ts +3 -3
  23. package/src/lib/searchQueryTypeChecker.ts +8 -4
  24. package/src/lib/tax.test.ts +3 -3
  25. package/src/lib/tax.ts +3 -3
  26. package/src/oauth/server.test.ts +7 -7
  27. package/src/oauth/server.ts +7 -7
  28. package/src/priceSelector.test.ts +1 -1
  29. package/src/priceSelector.ts +2 -2
  30. package/src/product-projection-search.ts +10 -12
  31. package/src/product-search-availability.test.ts +1 -1
  32. package/src/product-search.ts +6 -7
  33. package/src/projectAPI.test.ts +1 -1
  34. package/src/projectAPI.ts +7 -7
  35. package/src/repositories/abstract.ts +8 -10
  36. package/src/repositories/as-associate.test.ts +4 -4
  37. package/src/repositories/as-associate.ts +3 -3
  38. package/src/repositories/associate-role.ts +7 -9
  39. package/src/repositories/attribute-group.test.ts +3 -3
  40. package/src/repositories/attribute-group.ts +5 -5
  41. package/src/repositories/business-unit.test.ts +6 -6
  42. package/src/repositories/business-unit.ts +23 -28
  43. package/src/repositories/cart/actions.ts +12 -15
  44. package/src/repositories/cart/helpers.ts +5 -5
  45. package/src/repositories/cart/index.test.ts +5 -10
  46. package/src/repositories/cart/index.ts +13 -18
  47. package/src/repositories/cart-discount/actions.ts +5 -6
  48. package/src/repositories/cart-discount/index.ts +5 -5
  49. package/src/repositories/category/actions.ts +4 -4
  50. package/src/repositories/category/index.test.ts +3 -3
  51. package/src/repositories/category/index.ts +8 -8
  52. package/src/repositories/channel.test.ts +4 -4
  53. package/src/repositories/channel.ts +6 -6
  54. package/src/repositories/custom-object.ts +11 -8
  55. package/src/repositories/customer/actions.ts +11 -14
  56. package/src/repositories/customer/index.test.ts +3 -3
  57. package/src/repositories/customer/index.ts +12 -9
  58. package/src/repositories/customer-group.test.ts +4 -4
  59. package/src/repositories/customer-group.ts +6 -6
  60. package/src/repositories/discount-code/actions.ts +4 -4
  61. package/src/repositories/discount-code/index.ts +5 -5
  62. package/src/repositories/discount-group/actions.ts +3 -4
  63. package/src/repositories/discount-group/index.ts +4 -4
  64. package/src/repositories/errors.ts +1 -1
  65. package/src/repositories/extension.test.ts +3 -3
  66. package/src/repositories/extension.ts +6 -6
  67. package/src/repositories/helpers.test.ts +25 -0
  68. package/src/repositories/helpers.ts +14 -12
  69. package/src/repositories/index.test.ts +3 -3
  70. package/src/repositories/index.ts +43 -43
  71. package/src/repositories/inventory-entry/actions.ts +15 -3
  72. package/src/repositories/inventory-entry/index.ts +5 -5
  73. package/src/repositories/my-customer.ts +5 -5
  74. package/src/repositories/my-order.ts +2 -2
  75. package/src/repositories/my-quote-request.ts +1 -1
  76. package/src/repositories/order/actions.ts +8 -9
  77. package/src/repositories/order/index.test.ts +8 -9
  78. package/src/repositories/order/index.ts +16 -17
  79. package/src/repositories/order-edit.ts +4 -4
  80. package/src/repositories/payment/actions.ts +6 -6
  81. package/src/repositories/payment/helpers.ts +3 -3
  82. package/src/repositories/payment/index.ts +7 -7
  83. package/src/repositories/product/actions.ts +7 -7
  84. package/src/repositories/product/helpers.ts +4 -4
  85. package/src/repositories/product/index.ts +13 -13
  86. package/src/repositories/product-discount.ts +9 -6
  87. package/src/repositories/product-projection.ts +7 -7
  88. package/src/repositories/product-selection.ts +9 -6
  89. package/src/repositories/product-tailoring.ts +6 -3
  90. package/src/repositories/product-type.ts +8 -5
  91. package/src/repositories/project.ts +5 -5
  92. package/src/repositories/quote/actions.ts +6 -6
  93. package/src/repositories/quote/index.ts +5 -5
  94. package/src/repositories/quote-request/actions.ts +6 -6
  95. package/src/repositories/quote-request/index.test.ts +3 -3
  96. package/src/repositories/quote-request/index.ts +5 -5
  97. package/src/repositories/quote-staged/actions.ts +6 -6
  98. package/src/repositories/quote-staged/index.ts +5 -5
  99. package/src/repositories/recurrence-policy/actions.ts +3 -3
  100. package/src/repositories/recurrence-policy/index.ts +4 -8
  101. package/src/repositories/recurring-order/actions.ts +3 -3
  102. package/src/repositories/recurring-order/index.ts +5 -5
  103. package/src/repositories/review.test.ts +5 -5
  104. package/src/repositories/review.ts +10 -9
  105. package/src/repositories/shipping-method/actions.ts +7 -9
  106. package/src/repositories/shipping-method/helpers.ts +1 -1
  107. package/src/repositories/shipping-method/index.ts +8 -8
  108. package/src/repositories/shopping-list/actions.ts +5 -5
  109. package/src/repositories/shopping-list/index.ts +7 -7
  110. package/src/repositories/standalone-price.ts +9 -6
  111. package/src/repositories/state.ts +9 -6
  112. package/src/repositories/store.ts +10 -7
  113. package/src/repositories/subscription.test.ts +3 -3
  114. package/src/repositories/subscription.ts +9 -6
  115. package/src/repositories/tax-category/actions.ts +4 -4
  116. package/src/repositories/tax-category/index.ts +6 -6
  117. package/src/repositories/type/actions.ts +4 -4
  118. package/src/repositories/type/index.ts +5 -5
  119. package/src/repositories/zone.test.ts +3 -3
  120. package/src/repositories/zone.ts +8 -5
  121. package/src/server.ts +4 -3
  122. package/src/services/abstract.ts +5 -5
  123. package/src/services/as-associate-cart.test.ts +1 -1
  124. package/src/services/as-associate-cart.ts +2 -2
  125. package/src/services/as-associate-order.test.ts +1 -1
  126. package/src/services/as-associate-order.ts +2 -2
  127. package/src/services/as-associate-quote-request.ts +2 -3
  128. package/src/services/as-associate.test.ts +1 -1
  129. package/src/services/as-associate.ts +4 -4
  130. package/src/services/associate-roles.test.ts +1 -1
  131. package/src/services/associate-roles.ts +2 -2
  132. package/src/services/attribute-group.test.ts +1 -1
  133. package/src/services/attribute-group.ts +2 -2
  134. package/src/services/business-units.test.ts +5 -5
  135. package/src/services/business-units.ts +2 -2
  136. package/src/services/cart-discount.ts +2 -2
  137. package/src/services/cart.test.ts +7 -3
  138. package/src/services/cart.ts +4 -5
  139. package/src/services/category.test.ts +1 -1
  140. package/src/services/category.ts +2 -2
  141. package/src/services/channel.test.ts +1 -1
  142. package/src/services/channel.ts +2 -2
  143. package/src/services/custom-object.test.ts +2 -2
  144. package/src/services/custom-object.ts +3 -3
  145. package/src/services/customer-group.test.ts +1 -1
  146. package/src/services/customer-group.ts +2 -2
  147. package/src/services/customer.test.ts +3 -3
  148. package/src/services/customer.ts +4 -5
  149. package/src/services/discount-code.test.ts +1 -1
  150. package/src/services/discount-code.ts +2 -2
  151. package/src/services/discount-group.test.ts +1 -1
  152. package/src/services/discount-group.ts +2 -2
  153. package/src/services/extension.test.ts +1 -1
  154. package/src/services/extension.ts +2 -2
  155. package/src/services/index.ts +44 -44
  156. package/src/services/inventory-entry.test.ts +16 -1
  157. package/src/services/inventory-entry.ts +2 -2
  158. package/src/services/my-business-unit.test.ts +1 -1
  159. package/src/services/my-business-unit.ts +2 -2
  160. package/src/services/my-cart.test.ts +1 -1
  161. package/src/services/my-cart.ts +2 -2
  162. package/src/services/my-customer.test.ts +2 -2
  163. package/src/services/my-customer.ts +6 -6
  164. package/src/services/my-order.ts +2 -2
  165. package/src/services/my-payment.test.ts +1 -1
  166. package/src/services/my-payment.ts +2 -2
  167. package/src/services/my-shopping-list.ts +2 -2
  168. package/src/services/order.test.ts +4 -11
  169. package/src/services/order.ts +4 -4
  170. package/src/services/payment.test.ts +1 -1
  171. package/src/services/payment.ts +2 -2
  172. package/src/services/product-discount.test.ts +1 -1
  173. package/src/services/product-discount.ts +2 -2
  174. package/src/services/product-projection.test.ts +2 -2
  175. package/src/services/product-projection.ts +4 -4
  176. package/src/services/product-selection.test.ts +1 -1
  177. package/src/services/product-selection.ts +2 -2
  178. package/src/services/product-type.test.ts +1 -1
  179. package/src/services/product-type.ts +2 -2
  180. package/src/services/product.test.ts +1 -1
  181. package/src/services/product.ts +3 -3
  182. package/src/services/project.test.ts +1 -1
  183. package/src/services/project.ts +4 -4
  184. package/src/services/quote-request.test.ts +2 -2
  185. package/src/services/quote-request.ts +2 -2
  186. package/src/services/quote-staged.ts +2 -2
  187. package/src/services/quote.ts +2 -2
  188. package/src/services/recurrence-policy.test.ts +1 -1
  189. package/src/services/recurrence-policy.ts +2 -2
  190. package/src/services/recurring-order.test.ts +1 -1
  191. package/src/services/recurring-order.ts +2 -2
  192. package/src/services/reviews.test.ts +1 -1
  193. package/src/services/reviews.ts +2 -2
  194. package/src/services/shipping-method.test.ts +2 -2
  195. package/src/services/shipping-method.ts +4 -4
  196. package/src/services/shopping-list.test.ts +1 -1
  197. package/src/services/shopping-list.ts +2 -2
  198. package/src/services/standalone-price.test.ts +1 -1
  199. package/src/services/standalone-price.ts +2 -2
  200. package/src/services/state.test.ts +1 -1
  201. package/src/services/state.ts +2 -2
  202. package/src/services/store.test.ts +1 -1
  203. package/src/services/store.ts +2 -2
  204. package/src/services/subscription.test.ts +1 -1
  205. package/src/services/subscription.ts +2 -2
  206. package/src/services/tax-category.test.ts +1 -1
  207. package/src/services/tax-category.ts +2 -2
  208. package/src/services/type.test.ts +1 -1
  209. package/src/services/type.ts +2 -2
  210. package/src/services/zone.test.ts +1 -1
  211. package/src/services/zone.ts +2 -2
  212. package/src/shipping.test.ts +1 -1
  213. package/src/shipping.ts +8 -8
  214. package/src/storage/abstract.ts +1 -1
  215. package/src/storage/in-memory.ts +15 -17
  216. package/src/storage/index.ts +2 -2
  217. package/src/testing/business-unit.ts +1 -2
  218. package/src/testing/customer.ts +1 -1
  219. package/src/testing/type.ts +1 -1
  220. package/src/types.ts +1 -1
  221. package/src/validate.ts +1 -1
  222. package/dist/index.d.ts.map +0 -1
  223. package/dist/index.js.map +0 -1
@@ -3,13 +3,16 @@ import type {
3
3
  CustomObjectDraft,
4
4
  InvalidOperationError,
5
5
  } from "@commercetools/platform-sdk";
6
- import type { Config } from "~src/config";
7
- import { CommercetoolsError } from "~src/exceptions";
8
- import { cloneObject, getBaseResourceProperties } from "../helpers";
9
- import type { Writable } from "../types";
10
- import type { QueryParams } from "./abstract";
11
- import { AbstractResourceRepository, type RepositoryContext } from "./abstract";
12
- import { checkConcurrentModification } from "./errors";
6
+ import type { Config } from "#src/config.ts";
7
+ import { CommercetoolsError } from "#src/exceptions.ts";
8
+ import { cloneObject, getBaseResourceProperties } from "../helpers.ts";
9
+ import type { Writable } from "../types.ts";
10
+ import type { QueryParams } from "./abstract.ts";
11
+ import {
12
+ AbstractResourceRepository,
13
+ type RepositoryContext,
14
+ } from "./abstract.ts";
15
+ import { checkConcurrentModification } from "./errors.ts";
13
16
 
14
17
  export class CustomObjectRepository extends AbstractResourceRepository<"key-value-document"> {
15
18
  constructor(config: Config) {
@@ -88,7 +91,7 @@ export class CustomObjectRepository extends AbstractResourceRepository<"key-valu
88
91
  where: whereClause,
89
92
  });
90
93
 
91
- // @ts-ignore
94
+ // @ts-expect-error
92
95
  result.results = result.results.map((r) =>
93
96
  this.postProcessResource(context, r as CustomObject, {
94
97
  expand: params.expand,
@@ -17,10 +17,10 @@ import type {
17
17
  CustomerSetAddressCustomTypeAction,
18
18
  CustomerSetAuthenticationModeAction,
19
19
  CustomerSetCompanyNameAction,
20
- CustomerSetCustomFieldAction,
21
- CustomerSetCustomTypeAction,
22
20
  CustomerSetCustomerGroupAction,
23
21
  CustomerSetCustomerNumberAction,
22
+ CustomerSetCustomFieldAction,
23
+ CustomerSetCustomTypeAction,
24
24
  CustomerSetDateOfBirthAction,
25
25
  CustomerSetDefaultBillingAddressAction,
26
26
  CustomerSetDefaultShippingAddressAction,
@@ -39,13 +39,13 @@ import type {
39
39
  InvalidJsonInputError,
40
40
  InvalidOperationError,
41
41
  } from "@commercetools/platform-sdk";
42
- import { CommercetoolsError } from "~src/exceptions";
43
- import { generateRandomString } from "~src/helpers";
44
- import { hashPassword } from "~src/lib/password";
45
- import type { Writable } from "~src/types";
46
- import type { UpdateHandlerInterface } from "../abstract";
47
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
48
- import { createAddress, createCustomFields } from "../helpers";
42
+ import { CommercetoolsError } from "#src/exceptions.ts";
43
+ import { generateRandomString } from "#src/helpers.ts";
44
+ import { hashPassword } from "#src/lib/password.ts";
45
+ import type { Writable } from "#src/types.ts";
46
+ import type { UpdateHandlerInterface } from "../abstract.ts";
47
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
48
+ import { createAddress, createCustomFields } from "../helpers.ts";
49
49
 
50
50
  export class CustomerUpdateHandler
51
51
  extends AbstractUpdateHandler
@@ -118,16 +118,13 @@ export class CustomerUpdateHandler
118
118
  );
119
119
 
120
120
  const newAddress = createAddress(
121
- address,
121
+ { ...address, id: current.id },
122
122
  context.projectKey,
123
123
  this._storage,
124
124
  );
125
125
 
126
126
  if (newAddress) {
127
- resource.addresses[oldAddressIndex] = {
128
- id: addressId,
129
- ...newAddress,
130
- };
127
+ resource.addresses[oldAddressIndex] = newAddress;
131
128
  }
132
129
  }
133
130
 
@@ -1,8 +1,8 @@
1
1
  import type { Store } from "@commercetools/platform-sdk";
2
2
  import { describe, expect, test } from "vitest";
3
- import type { Config } from "~src/config";
4
- import { InMemoryStorage } from "~src/storage";
5
- import { CustomerRepository } from "./index";
3
+ import type { Config } from "#src/config.ts";
4
+ import { InMemoryStorage } from "#src/storage/index.ts";
5
+ import { CustomerRepository } from "./index.ts";
6
6
 
7
7
  describe("Customer repository", () => {
8
8
  const storage = new InMemoryStorage();
@@ -13,22 +13,25 @@ import type {
13
13
  StoreKeyReference,
14
14
  StoreResourceIdentifier,
15
15
  } from "@commercetools/platform-sdk";
16
- import type { Config } from "~src/config";
17
- import { CommercetoolsError } from "~src/exceptions";
18
- import { generateRandomString, getBaseResourceProperties } from "~src/helpers";
16
+ import type { Config } from "#src/config.ts";
17
+ import { CommercetoolsError } from "#src/exceptions.ts";
18
+ import {
19
+ generateRandomString,
20
+ getBaseResourceProperties,
21
+ } from "#src/helpers.ts";
19
22
  import {
20
23
  createEmailVerifyToken,
21
24
  createPasswordResetToken,
22
25
  hashPassword,
23
26
  validatePasswordResetToken,
24
- } from "~src/lib/password";
25
- import type { ResourceMap, ShallowWritable, Writable } from "~src/types";
27
+ } from "#src/lib/password.ts";
28
+ import type { ResourceMap, ShallowWritable, Writable } from "#src/types.ts";
26
29
  import {
27
30
  AbstractResourceRepository,
28
31
  type RepositoryContext,
29
- } from "../abstract";
30
- import { createCustomFields } from "../helpers";
31
- import { CustomerUpdateHandler } from "./actions";
32
+ } from "../abstract.ts";
33
+ import { createCustomFields } from "../helpers.ts";
34
+ import { CustomerUpdateHandler } from "./actions.ts";
32
35
 
33
36
  export class CustomerRepository extends AbstractResourceRepository<"customer"> {
34
37
  constructor(config: Config) {
@@ -176,7 +179,7 @@ export class CustomerRepository extends AbstractResourceRepository<"customer"> {
176
179
 
177
180
  const ttlMinutes = request.ttlMinutes ?? 34560; // 34560 is CT default
178
181
 
179
- const expiresAt = new Date(new Date().getTime() + ttlMinutes * 60 * 1000);
182
+ const expiresAt = new Date(Date.now() + ttlMinutes * 60 * 1000);
180
183
  const customer = results.results[0] as Customer;
181
184
  const rest = getBaseResourceProperties();
182
185
 
@@ -6,10 +6,10 @@ import type {
6
6
  CustomerGroupSetKeyAction,
7
7
  } from "@commercetools/platform-sdk";
8
8
  import { describe, expect, test } from "vitest";
9
- import type { Config } from "~src/config";
10
- import { getBaseResourceProperties } from "~src/helpers";
11
- import { InMemoryStorage } from "~src/storage";
12
- import { CustomerGroupRepository } from "./customer-group";
9
+ import type { Config } from "#src/config.ts";
10
+ import { getBaseResourceProperties } from "#src/helpers.ts";
11
+ import { InMemoryStorage } from "#src/storage/index.ts";
12
+ import { CustomerGroupRepository } from "./customer-group.ts";
13
13
 
14
14
  describe("CustomerGroup Repository", () => {
15
15
  const storage = new InMemoryStorage();
@@ -7,16 +7,16 @@ import type {
7
7
  CustomerGroupSetKeyAction,
8
8
  CustomerGroupUpdateAction,
9
9
  } from "@commercetools/platform-sdk";
10
- import type { Config } from "~src/config";
11
- import { getBaseResourceProperties } from "../helpers";
12
- import type { Writable } from "../types";
13
- import type { UpdateHandlerInterface } from "./abstract";
10
+ import type { Config } from "#src/config.ts";
11
+ import { getBaseResourceProperties } from "../helpers.ts";
12
+ import type { Writable } from "../types.ts";
13
+ import type { UpdateHandlerInterface } from "./abstract.ts";
14
14
  import {
15
15
  AbstractResourceRepository,
16
16
  AbstractUpdateHandler,
17
17
  type RepositoryContext,
18
- } from "./abstract";
19
- import { createCustomFields } from "./helpers";
18
+ } from "./abstract.ts";
19
+ import { createCustomFields } from "./helpers.ts";
20
20
 
21
21
  export class CustomerGroupRepository extends AbstractResourceRepository<"customer-group"> {
22
22
  constructor(config: Config) {
@@ -15,10 +15,10 @@ import type {
15
15
  DiscountCodeSetValidUntilAction,
16
16
  DiscountCodeUpdateAction,
17
17
  } from "@commercetools/platform-sdk";
18
- import type { Writable } from "~src/types";
19
- import type { UpdateHandlerInterface } from "../abstract";
20
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
21
- import { createCustomFields } from "../helpers";
18
+ import type { Writable } from "#src/types.ts";
19
+ import type { UpdateHandlerInterface } from "../abstract.ts";
20
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
21
+ import { createCustomFields } from "../helpers.ts";
22
22
 
23
23
  export class DiscountCodeUpdateHandler
24
24
  extends AbstractUpdateHandler
@@ -3,14 +3,14 @@ import type {
3
3
  DiscountCode,
4
4
  DiscountCodeDraft,
5
5
  } from "@commercetools/platform-sdk";
6
- import type { Config } from "~src/config";
7
- import { getBaseResourceProperties } from "~src/helpers";
6
+ import type { Config } from "#src/config.ts";
7
+ import { getBaseResourceProperties } from "#src/helpers.ts";
8
8
  import {
9
9
  AbstractResourceRepository,
10
10
  type RepositoryContext,
11
- } from "../abstract";
12
- import { createCustomFields } from "../helpers";
13
- import { DiscountCodeUpdateHandler } from "./actions";
11
+ } from "../abstract.ts";
12
+ import { createCustomFields } from "../helpers.ts";
13
+ import { DiscountCodeUpdateHandler } from "./actions.ts";
14
14
 
15
15
  export class DiscountCodeRepository extends AbstractResourceRepository<"discount-code"> {
16
16
  constructor(config: Config) {
@@ -6,10 +6,9 @@ import type {
6
6
  DiscountGroupSetSortOrderAction,
7
7
  DiscountGroupUpdateAction,
8
8
  } from "@commercetools/platform-sdk";
9
- import type { Writable } from "~src/types";
10
- import type { UpdateHandlerInterface } from "../abstract";
11
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
12
- import { createCustomFields } from "../helpers";
9
+ import type { Writable } from "#src/types.ts";
10
+ import type { UpdateHandlerInterface } from "../abstract.ts";
11
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
13
12
 
14
13
  export class DiscountGroupUpdateHandler
15
14
  extends AbstractUpdateHandler
@@ -2,13 +2,13 @@ import type {
2
2
  DiscountGroup,
3
3
  DiscountGroupDraft,
4
4
  } from "@commercetools/platform-sdk";
5
- import type { Config } from "~src/config";
6
- import { getBaseResourceProperties } from "~src/helpers";
5
+ import type { Config } from "#src/config.ts";
6
+ import { getBaseResourceProperties } from "#src/helpers.ts";
7
7
  import {
8
8
  AbstractResourceRepository,
9
9
  type RepositoryContext,
10
- } from "../abstract";
11
- import { DiscountGroupUpdateHandler } from "./actions";
10
+ } from "../abstract.ts";
11
+ import { DiscountGroupUpdateHandler } from "./actions.ts";
12
12
 
13
13
  export class DiscountGroupRepository extends AbstractResourceRepository<"discount-group"> {
14
14
  constructor(config: Config) {
@@ -1,5 +1,5 @@
1
1
  import type { ConcurrentModificationError } from "@commercetools/platform-sdk";
2
- import { CommercetoolsError } from "~src/exceptions";
2
+ import { CommercetoolsError } from "#src/exceptions.ts";
3
3
 
4
4
  export const checkConcurrentModification = (
5
5
  currentVersion: number,
@@ -7,9 +7,9 @@ import type {
7
7
  ExtensionSetTimeoutInMsAction,
8
8
  } from "@commercetools/platform-sdk";
9
9
  import { describe, expect, test } from "vitest";
10
- import type { Config } from "~src/config";
11
- import { InMemoryStorage } from "~src/storage";
12
- import { ExtensionRepository } from "./extension";
10
+ import type { Config } from "#src/config.ts";
11
+ import { InMemoryStorage } from "#src/storage/index.ts";
12
+ import { ExtensionRepository } from "./extension.ts";
13
13
 
14
14
  describe("Extension Repository", () => {
15
15
  const storage = new InMemoryStorage();
@@ -7,16 +7,16 @@ import type {
7
7
  ExtensionSetTimeoutInMsAction,
8
8
  ExtensionUpdateAction,
9
9
  } from "@commercetools/platform-sdk";
10
- import type { Config } from "~src/config";
11
- import { getBaseResourceProperties } from "../helpers";
12
- import { maskSecretValue } from "../lib/masking";
13
- import type { Writable } from "../types";
14
- import type { UpdateHandlerInterface } from "./abstract";
10
+ import type { Config } from "#src/config.ts";
11
+ import { getBaseResourceProperties } from "../helpers.ts";
12
+ import { maskSecretValue } from "../lib/masking.ts";
13
+ import type { Writable } from "../types.ts";
14
+ import type { UpdateHandlerInterface } from "./abstract.ts";
15
15
  import {
16
16
  AbstractResourceRepository,
17
17
  AbstractUpdateHandler,
18
18
  type RepositoryContext,
19
- } from "./abstract";
19
+ } from "./abstract.ts";
20
20
 
21
21
  export class ExtensionRepository extends AbstractResourceRepository<"extension"> {
22
22
  constructor(config: Config) {
@@ -0,0 +1,25 @@
1
+ import type { BaseAddress } from "@commercetools/platform-sdk";
2
+ import { describe, expect, test } from "vitest";
3
+ import { InMemoryStorage } from "#src/storage/index.ts";
4
+ import { createAddress } from "./helpers.ts";
5
+
6
+ describe("Helpers", () => {
7
+ const storage = new InMemoryStorage();
8
+ const projectKey = "test-project";
9
+
10
+ describe("createAddress", () => {
11
+ test("should generate random id when id is not provided", () => {
12
+ const baseAddress: BaseAddress = {
13
+ country: "US",
14
+ streetName: "Test Street",
15
+ city: "Test City",
16
+ };
17
+
18
+ const result = createAddress(baseAddress, projectKey, storage);
19
+ expect(result).toBeDefined();
20
+ expect(result?.id).toBeDefined();
21
+ expect(typeof result?.id).toBe("string");
22
+ expect(result?.id).toMatch(/^[a-z0-9]{8}$/);
23
+ });
24
+ });
25
+ });
@@ -1,19 +1,17 @@
1
1
  import type {
2
- AssociateRoleReference,
3
- BusinessUnitKeyReference,
4
- BusinessUnitReference,
5
- BusinessUnitResourceIdentifier,
6
- RoundingMode,
7
- } from "@commercetools/platform-sdk";
8
- import type {
2
+ _Money,
9
3
  Address,
10
4
  Associate,
11
5
  AssociateDraft,
12
6
  AssociateRoleAssignment,
13
7
  AssociateRoleAssignmentDraft,
14
8
  AssociateRoleKeyReference,
9
+ AssociateRoleReference,
15
10
  AssociateRoleResourceIdentifier,
16
11
  BaseAddress,
12
+ BusinessUnitKeyReference,
13
+ BusinessUnitReference,
14
+ BusinessUnitResourceIdentifier,
17
15
  CentPrecisionMoney,
18
16
  CustomFields,
19
17
  CustomFieldsDraft,
@@ -25,19 +23,19 @@ import type {
25
23
  Reference,
26
24
  ReferencedResourceNotFoundError,
27
25
  ResourceIdentifier,
26
+ RoundingMode,
28
27
  Store,
29
28
  StoreKeyReference,
30
29
  StoreReference,
31
30
  StoreResourceIdentifier,
32
31
  Type,
33
- _Money,
34
32
  } from "@commercetools/platform-sdk";
35
33
  import { Decimal } from "decimal.js/decimal";
36
34
  import type { Request } from "express";
37
35
  import { v4 as uuidv4 } from "uuid";
38
- import { CommercetoolsError } from "~src/exceptions";
39
- import type { AbstractStorage } from "../storage";
40
- import type { RepositoryContext } from "./abstract";
36
+ import { CommercetoolsError } from "#src/exceptions.ts";
37
+ import type { AbstractStorage } from "../storage/index.ts";
38
+ import type { RepositoryContext } from "./abstract.ts";
41
39
 
42
40
  export const createAddress = (
43
41
  base: BaseAddress | undefined,
@@ -50,8 +48,13 @@ export const createAddress = (
50
48
  throw new Error("Country is required");
51
49
  }
52
50
 
51
+ // Generate a random 8-character alphanumeric string
52
+ // which is what addresses use instead of uuid
53
+ const generateRandomId = (): string =>
54
+ Math.random().toString(36).substring(2, 10).padEnd(8, "0");
53
55
  return {
54
56
  ...base,
57
+ id: base.id ?? generateRandomId(),
55
58
  };
56
59
  };
57
60
 
@@ -206,7 +209,6 @@ export const getReferenceFromResourceIdentifier = <T extends Reference>(
206
209
  throw new CommercetoolsError<ReferencedResourceNotFoundError>(
207
210
  {
208
211
  code: "ReferencedResourceNotFound",
209
- // @ts-ignore
210
212
  typeId: resourceIdentifier.typeId,
211
213
  message: `The referenced object of type '${resourceIdentifier.typeId}' with '${errIdentifier}' was not found. It either doesn't exist, or it can't be accessed from this endpoint (e.g., if the endpoint filters by store or customer account).`,
212
214
  },
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import type { Config } from "~src/config";
3
- import { InMemoryStorage } from "~src/storage";
4
- import { createRepositories } from "./index";
2
+ import type { Config } from "#src/config.ts";
3
+ import { InMemoryStorage } from "#src/storage/index.ts";
4
+ import { createRepositories } from "./index.ts";
5
5
 
6
6
  describe("Repository Index", () => {
7
7
  const storage = new InMemoryStorage();
@@ -1,50 +1,50 @@
1
- import type { Config } from "~src/config";
2
- import { ProductTailoringRepository } from "~src/repositories/product-tailoring";
1
+ import type { Config } from "#src/config.ts";
2
+ import { ProductTailoringRepository } from "#src/repositories/product-tailoring.ts";
3
3
  import {
4
4
  AsAssociateCartRepository,
5
5
  AsAssociateOrderRepository,
6
6
  AsAssociateQuoteRequestRepository,
7
- } from "./as-associate";
8
- import { AssociateRoleRepository } from "./associate-role";
9
- import { AttributeGroupRepository } from "./attribute-group";
10
- import { BusinessUnitRepository } from "./business-unit";
11
- import { CartRepository } from "./cart";
12
- import { CartDiscountRepository } from "./cart-discount";
13
- import { CategoryRepository } from "./category";
14
- import { ChannelRepository } from "./channel";
15
- import { CustomObjectRepository } from "./custom-object";
16
- import { CustomerRepository } from "./customer";
17
- import { CustomerGroupRepository } from "./customer-group";
18
- import { DiscountCodeRepository } from "./discount-code";
19
- import { DiscountGroupRepository } from "./discount-group";
20
- import { ExtensionRepository } from "./extension";
21
- import { InventoryEntryRepository } from "./inventory-entry";
22
- import { MyCustomerRepository } from "./my-customer";
23
- import { MyOrderRepository } from "./my-order";
24
- import { OrderRepository } from "./order";
25
- import { OrderEditRepository } from "./order-edit";
26
- import { PaymentRepository } from "./payment";
27
- import { ProductRepository } from "./product";
28
- import { ProductDiscountRepository } from "./product-discount";
29
- import { ProductProjectionRepository } from "./product-projection";
30
- import { ProductSelectionRepository } from "./product-selection";
31
- import { ProductTypeRepository } from "./product-type";
32
- import { ProjectRepository } from "./project";
33
- import { QuoteRepository } from "./quote";
34
- import { QuoteRequestRepository } from "./quote-request";
35
- import { StagedQuoteRepository } from "./quote-staged";
36
- import { RecurrencePolicyRepository } from "./recurrence-policy";
37
- import { RecurringOrderRepository } from "./recurring-order";
38
- import { ReviewRepository } from "./review";
39
- import { ShippingMethodRepository } from "./shipping-method";
40
- import { ShoppingListRepository } from "./shopping-list";
41
- import { StandAlonePriceRepository } from "./standalone-price";
42
- import { StateRepository } from "./state";
43
- import { StoreRepository } from "./store";
44
- import { SubscriptionRepository } from "./subscription";
45
- import { TaxCategoryRepository } from "./tax-category";
46
- import { TypeRepository } from "./type";
47
- import { ZoneRepository } from "./zone";
7
+ } from "./as-associate.ts";
8
+ import { AssociateRoleRepository } from "./associate-role.ts";
9
+ import { AttributeGroupRepository } from "./attribute-group.ts";
10
+ import { BusinessUnitRepository } from "./business-unit.ts";
11
+ import { CartRepository } from "./cart/index.ts";
12
+ import { CartDiscountRepository } from "./cart-discount/index.ts";
13
+ import { CategoryRepository } from "./category/index.ts";
14
+ import { ChannelRepository } from "./channel.ts";
15
+ import { CustomObjectRepository } from "./custom-object.ts";
16
+ import { CustomerRepository } from "./customer/index.ts";
17
+ import { CustomerGroupRepository } from "./customer-group.ts";
18
+ import { DiscountCodeRepository } from "./discount-code/index.ts";
19
+ import { DiscountGroupRepository } from "./discount-group/index.ts";
20
+ import { ExtensionRepository } from "./extension.ts";
21
+ import { InventoryEntryRepository } from "./inventory-entry/index.ts";
22
+ import { MyCustomerRepository } from "./my-customer.ts";
23
+ import { MyOrderRepository } from "./my-order.ts";
24
+ import { OrderRepository } from "./order/index.ts";
25
+ import { OrderEditRepository } from "./order-edit.ts";
26
+ import { PaymentRepository } from "./payment/index.ts";
27
+ import { ProductRepository } from "./product/index.ts";
28
+ import { ProductDiscountRepository } from "./product-discount.ts";
29
+ import { ProductProjectionRepository } from "./product-projection.ts";
30
+ import { ProductSelectionRepository } from "./product-selection.ts";
31
+ import { ProductTypeRepository } from "./product-type.ts";
32
+ import { ProjectRepository } from "./project.ts";
33
+ import { QuoteRepository } from "./quote/index.ts";
34
+ import { QuoteRequestRepository } from "./quote-request/index.ts";
35
+ import { StagedQuoteRepository } from "./quote-staged/index.ts";
36
+ import { RecurrencePolicyRepository } from "./recurrence-policy/index.ts";
37
+ import { RecurringOrderRepository } from "./recurring-order/index.ts";
38
+ import { ReviewRepository } from "./review.ts";
39
+ import { ShippingMethodRepository } from "./shipping-method/index.ts";
40
+ import { ShoppingListRepository } from "./shopping-list/index.ts";
41
+ import { StandAlonePriceRepository } from "./standalone-price.ts";
42
+ import { StateRepository } from "./state.ts";
43
+ import { StoreRepository } from "./store.ts";
44
+ import { SubscriptionRepository } from "./subscription.ts";
45
+ import { TaxCategoryRepository } from "./tax-category/index.ts";
46
+ import { TypeRepository } from "./type/index.ts";
47
+ import { ZoneRepository } from "./zone.ts";
48
48
 
49
49
  export type RepositoryMap = ReturnType<typeof createRepositories>;
50
50
 
@@ -1,15 +1,16 @@
1
1
  import type {
2
2
  InventoryEntry,
3
3
  InventoryEntryChangeQuantityAction,
4
+ InventoryEntryRemoveQuantityAction,
4
5
  InventoryEntrySetCustomFieldAction,
5
6
  InventoryEntrySetCustomTypeAction,
6
7
  InventoryEntrySetExpectedDeliveryAction,
7
8
  InventoryEntrySetRestockableInDaysAction,
8
9
  InventoryEntryUpdateAction,
9
10
  } from "@commercetools/platform-sdk";
10
- import type { Writable } from "~src/types";
11
- import type { UpdateHandlerInterface } from "../abstract";
12
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
11
+ import type { Writable } from "#src/types.ts";
12
+ import type { UpdateHandlerInterface } from "../abstract.ts";
13
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
13
14
 
14
15
  export class InventoryEntryUpdateHandler
15
16
  extends AbstractUpdateHandler
@@ -26,6 +27,17 @@ export class InventoryEntryUpdateHandler
26
27
  resource.availableQuantity = quantity;
27
28
  }
28
29
 
30
+ removeQuantity(
31
+ context: RepositoryContext,
32
+ resource: Writable<InventoryEntry>,
33
+ { quantity }: InventoryEntryRemoveQuantityAction,
34
+ ) {
35
+ const newQuantity = Math.max(0, resource.quantityOnStock - quantity);
36
+ resource.quantityOnStock = newQuantity;
37
+ // don't know active reservations so just set to same value
38
+ resource.availableQuantity = newQuantity;
39
+ }
40
+
29
41
  setCustomField(
30
42
  context: RepositoryContext,
31
43
  resource: InventoryEntry,
@@ -2,14 +2,14 @@ import type {
2
2
  InventoryEntry,
3
3
  InventoryEntryDraft,
4
4
  } from "@commercetools/platform-sdk";
5
- import type { Config } from "~src/config";
6
- import { getBaseResourceProperties } from "~src/helpers";
5
+ import type { Config } from "#src/config.ts";
6
+ import { getBaseResourceProperties } from "#src/helpers.ts";
7
7
  import {
8
8
  AbstractResourceRepository,
9
9
  type RepositoryContext,
10
- } from "../abstract";
11
- import { createCustomFields } from "../helpers";
12
- import { InventoryEntryUpdateHandler } from "./actions";
10
+ } from "../abstract.ts";
11
+ import { createCustomFields } from "../helpers.ts";
12
+ import { InventoryEntryUpdateHandler } from "./actions.ts";
13
13
 
14
14
  export class InventoryEntryRepository extends AbstractResourceRepository<"inventory-entry"> {
15
15
  constructor(config: Config) {
@@ -5,11 +5,11 @@ import type {
5
5
  MyCustomerEmailVerify,
6
6
  ResourceNotFoundError,
7
7
  } from "@commercetools/platform-sdk";
8
- import { CommercetoolsError } from "~src/exceptions";
9
- import { hashPassword, validateEmailVerifyToken } from "../lib/password";
10
- import type { Writable } from "../types";
11
- import type { RepositoryContext } from "./abstract";
12
- import { CustomerRepository } from "./customer";
8
+ import { CommercetoolsError } from "#src/exceptions.ts";
9
+ import { hashPassword, validateEmailVerifyToken } from "../lib/password.ts";
10
+ import type { Writable } from "../types.ts";
11
+ import type { RepositoryContext } from "./abstract.ts";
12
+ import { CustomerRepository } from "./customer/index.ts";
13
13
 
14
14
  export class MyCustomerRepository extends CustomerRepository {
15
15
  changePassword(
@@ -4,8 +4,8 @@ import type {
4
4
  MyOrderFromCartDraft,
5
5
  Order,
6
6
  } from "@commercetools/platform-sdk";
7
- import type { RepositoryContext } from "./abstract";
8
- import { OrderRepository } from "./order";
7
+ import type { RepositoryContext } from "./abstract.ts";
8
+ import { OrderRepository } from "./order/index.ts";
9
9
 
10
10
  export class MyOrderRepository extends OrderRepository {
11
11
  create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order {
@@ -1,3 +1,3 @@
1
- import { QuoteRequestRepository } from "./quote-request";
1
+ import { QuoteRequestRepository } from "./quote-request/index.ts";
2
2
 
3
3
  export class MyQuoteRequestRepository extends QuoteRequestRepository {}
@@ -9,11 +9,10 @@ import type {
9
9
  OrderChangePaymentStateAction,
10
10
  OrderChangeShipmentStateAction,
11
11
  OrderSetBillingAddressAction,
12
- OrderSetCustomFieldAction,
13
- OrderSetCustomLineItemCustomTypeAction,
14
- OrderSetCustomTypeAction,
15
12
  OrderSetCustomerEmailAction,
16
13
  OrderSetCustomerIdAction,
14
+ OrderSetCustomFieldAction,
15
+ OrderSetCustomTypeAction,
17
16
  OrderSetDeliveryCustomFieldAction,
18
17
  OrderSetLineItemCustomFieldAction,
19
18
  OrderSetLineItemCustomTypeAction,
@@ -31,12 +30,12 @@ import type {
31
30
  Store,
32
31
  SyncInfo,
33
32
  } from "@commercetools/platform-sdk";
34
- import { CommercetoolsError } from "~src/exceptions";
35
- import { getBaseResourceProperties } from "~src/helpers";
36
- import type { Writable } from "~src/types";
37
- import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
38
- import { AbstractUpdateHandler } from "../abstract";
39
- import { createAddress } from "../helpers";
33
+ import { CommercetoolsError } from "#src/exceptions.ts";
34
+ import { getBaseResourceProperties } from "#src/helpers.ts";
35
+ import type { Writable } from "#src/types.ts";
36
+ import type { RepositoryContext, UpdateHandlerInterface } from "../abstract.ts";
37
+ import { AbstractUpdateHandler } from "../abstract.ts";
38
+ import { createAddress } from "../helpers.ts";
40
39
 
41
40
  export class OrderUpdateHandler
42
41
  extends AbstractUpdateHandler