@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
@@ -1,5 +1,5 @@
1
1
  import { test } from "vitest";
2
- import { CommercetoolsMock } from "./index";
2
+ import { CommercetoolsMock } from "./index.ts";
3
3
 
4
4
  test("getRepository", async () => {
5
5
  const ctMock = new CommercetoolsMock();
package/src/projectAPI.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Config } from "./config";
2
- import { getBaseResourceProperties } from "./helpers";
3
- import type { RepositoryMap } from "./repositories";
4
- import type { GetParams } from "./repositories/abstract";
5
- import type { AbstractStorage } from "./storage";
6
- import type { ResourceMap, ResourceType } from "./types";
1
+ import type { Config } from "./config.ts";
2
+ import { getBaseResourceProperties } from "./helpers.ts";
3
+ import type { GetParams } from "./repositories/abstract.ts";
4
+ import type { RepositoryMap } from "./repositories/index.ts";
5
+ import type { AbstractStorage } from "./storage/index.ts";
6
+ import type { ResourceMap, ResourceType } from "./types.ts";
7
7
 
8
8
  export class ProjectAPI {
9
9
  private projectKey: string;
@@ -12,7 +12,7 @@ export class ProjectAPI {
12
12
 
13
13
  private _repositories: RepositoryMap;
14
14
 
15
- private config: Config;
15
+ readonly config: Config;
16
16
 
17
17
  constructor(projectKey: string, repositories: RepositoryMap, config: Config) {
18
18
  this.projectKey = projectKey;
@@ -7,17 +7,17 @@ import type {
7
7
  ResourceNotFoundError,
8
8
  UpdateAction,
9
9
  } from "@commercetools/platform-sdk";
10
- import type { Config } from "~src/config";
11
- import { CommercetoolsError } from "~src/exceptions";
12
- import { cloneObject } from "../helpers";
13
- import type { AbstractStorage } from "../storage";
10
+ import type { Config } from "#src/config.ts";
11
+ import { CommercetoolsError } from "#src/exceptions.ts";
12
+ import { cloneObject } from "../helpers.ts";
13
+ import type { AbstractStorage } from "../storage/index.ts";
14
14
  import type {
15
15
  ResourceMap,
16
16
  ResourceType,
17
17
  ShallowWritable,
18
18
  Writable,
19
- } from "./../types";
20
- import { checkConcurrentModification } from "./errors";
19
+ } from "./../types.ts";
20
+ import { checkConcurrentModification } from "./errors.ts";
21
21
 
22
22
  export type QueryParams = {
23
23
  expand?: string[];
@@ -259,9 +259,8 @@ export class AbstractUpdateHandler {
259
259
 
260
260
  for (const action of actions) {
261
261
  // Validate if this action exists
262
- // @ts-ignore
262
+ // @ts-expect-error
263
263
  if (this[action.action] === undefined) {
264
- console.info(`No handler for action ${action.action}`);
265
264
  throw new CommercetoolsError<InvalidInputError>({
266
265
  code: "InvalidInput",
267
266
  message: `Invalid action ${action.action}`,
@@ -274,11 +273,10 @@ export class AbstractUpdateHandler {
274
273
  });
275
274
  }
276
275
 
277
- // @ts-ignore
276
+ // @ts-expect-error
278
277
  const updateFunc = this[action.action].bind(this);
279
278
 
280
279
  if (!updateFunc) {
281
- console.error(`No mock implemented for update action ${action.action}`);
282
280
  throw new Error(
283
281
  `No mock implemented for update action ${action.action}`,
284
282
  );
@@ -1,12 +1,12 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import type { Config } from "~src/config";
3
- import { InMemoryStorage } from "~src/storage";
2
+ import type { Config } from "#src/config.ts";
3
+ import { InMemoryStorage } from "#src/storage/index.ts";
4
4
  import {
5
5
  AsAssociateCartRepository,
6
6
  AsAssociateOrderRepository,
7
7
  AsAssociateQuoteRequestRepository,
8
- } from "./as-associate";
9
- import { CustomerRepository } from "./customer";
8
+ } from "./as-associate.ts";
9
+ import { CustomerRepository } from "./customer/index.ts";
10
10
 
11
11
  describe("As Associate Repositories", () => {
12
12
  const storage = new InMemoryStorage();
@@ -1,6 +1,6 @@
1
- import { CartRepository } from "./cart";
2
- import { OrderRepository } from "./order";
3
- import { QuoteRequestRepository } from "./quote-request";
1
+ import { CartRepository } from "./cart/index.ts";
2
+ import { OrderRepository } from "./order/index.ts";
3
+ import { QuoteRequestRepository } from "./quote-request/index.ts";
4
4
 
5
5
  export class AsAssociateOrderRepository extends OrderRepository {}
6
6
  export class AsAssociateCartRepository extends CartRepository {}
@@ -10,16 +10,16 @@ import type {
10
10
  AssociateRoleSetPermissionsAction,
11
11
  AssociateRoleUpdateAction,
12
12
  } from "@commercetools/platform-sdk";
13
- import type { Config } from "~src/config";
14
- import { getBaseResourceProperties } from "../helpers";
15
- import type { Writable } from "../types";
16
- import type { UpdateHandlerInterface } from "./abstract";
13
+ import type { Config } from "#src/config.ts";
14
+ import { getBaseResourceProperties } from "../helpers.ts";
15
+ import type { Writable } from "../types.ts";
16
+ import type { UpdateHandlerInterface } from "./abstract.ts";
17
17
  import {
18
18
  AbstractResourceRepository,
19
19
  AbstractUpdateHandler,
20
20
  type RepositoryContext,
21
- } from "./abstract";
22
- import { createCustomFields } from "./helpers";
21
+ } from "./abstract.ts";
22
+ import { createCustomFields } from "./helpers.ts";
23
23
 
24
24
  export class AssociateRoleRepository extends AbstractResourceRepository<"associate-role"> {
25
25
  constructor(config: Config) {
@@ -79,9 +79,7 @@ class AssociateRoleUpdateHandler
79
79
  return;
80
80
  }
81
81
 
82
- resource.permissions = resource.permissions.filter((p) => {
83
- p !== permission;
84
- });
82
+ resource.permissions = resource.permissions.filter((p) => p !== permission);
85
83
  }
86
84
 
87
85
  setBuyerAssignable(
@@ -6,9 +6,9 @@ import type {
6
6
  AttributeGroupSetKeyAction,
7
7
  } from "@commercetools/platform-sdk";
8
8
  import { describe, expect, test } from "vitest";
9
- import type { Config } from "~src/config";
10
- import { InMemoryStorage } from "~src/storage";
11
- import { AttributeGroupRepository } from "./attribute-group";
9
+ import type { Config } from "#src/config.ts";
10
+ import { InMemoryStorage } from "#src/storage/index.ts";
11
+ import { AttributeGroupRepository } from "./attribute-group.ts";
12
12
 
13
13
  describe("AttributeGroup Repository", () => {
14
14
  const storage = new InMemoryStorage();
@@ -7,15 +7,15 @@ import type {
7
7
  AttributeGroupSetKeyAction,
8
8
  AttributeGroupUpdateAction,
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";
18
+ } from "./abstract.ts";
19
19
 
20
20
  export class AttributeGroupRepository extends AbstractResourceRepository<"attribute-group"> {
21
21
  constructor(config: Config) {
@@ -9,11 +9,11 @@ import type {
9
9
  DivisionDraft,
10
10
  } from "@commercetools/platform-sdk";
11
11
  import { describe, expect, test } from "vitest";
12
- import type { Config } from "~src/config";
13
- import { getBaseResourceProperties } from "~src/helpers";
14
- import { InMemoryStorage } from "~src/storage";
15
- import { BusinessUnitRepository } from "./business-unit";
16
- import { CustomerRepository } from "./customer";
12
+ import type { Config } from "#src/config.ts";
13
+ import { getBaseResourceProperties } from "#src/helpers.ts";
14
+ import { InMemoryStorage } from "#src/storage/index.ts";
15
+ import { BusinessUnitRepository } from "./business-unit.ts";
16
+ import { CustomerRepository } from "./customer/index.ts";
17
17
 
18
18
  describe("BusinessUnit Repository", () => {
19
19
  const storage = new InMemoryStorage();
@@ -126,7 +126,7 @@ describe("BusinessUnit Repository", () => {
126
126
  name: "Parent Company",
127
127
  };
128
128
 
129
- const company = repository.create({ projectKey: "dummy" }, companyDraft);
129
+ const _company = repository.create({ projectKey: "dummy" }, companyDraft);
130
130
 
131
131
  const draft: DivisionDraft = {
132
132
  key: "test-division",
@@ -1,56 +1,54 @@
1
1
  import type {
2
+ Associate,
3
+ BusinessUnit,
4
+ BusinessUnitAddAddressAction,
5
+ BusinessUnitAddAssociateAction,
2
6
  BusinessUnitAddBillingAddressIdAction,
3
7
  BusinessUnitAddShippingAddressIdAction,
8
+ BusinessUnitAddStoreAction,
9
+ BusinessUnitChangeAddressAction,
4
10
  BusinessUnitChangeApprovalRuleModeAction,
5
11
  BusinessUnitChangeAssociateAction,
6
12
  BusinessUnitChangeAssociateModeAction,
13
+ BusinessUnitChangeNameAction,
14
+ BusinessUnitChangeParentUnitAction,
7
15
  BusinessUnitChangeStatusAction,
16
+ BusinessUnitDraft,
17
+ BusinessUnitRemoveAddressAction,
8
18
  BusinessUnitRemoveAssociateAction,
9
19
  BusinessUnitRemoveBillingAddressIdAction,
10
20
  BusinessUnitRemoveShippingAddressIdAction,
11
21
  BusinessUnitSetAddressCustomFieldAction,
12
22
  BusinessUnitSetAddressCustomTypeAction,
23
+ BusinessUnitSetAssociatesAction,
24
+ BusinessUnitSetContactEmailAction,
13
25
  BusinessUnitSetCustomFieldAction,
14
26
  BusinessUnitSetCustomTypeAction,
15
27
  BusinessUnitSetDefaultBillingAddressAction,
16
28
  BusinessUnitSetDefaultShippingAddressAction,
17
- BusinessUnitUpdateAction,
18
- CompanyDraft,
19
- DivisionDraft,
20
- } from "@commercetools/platform-sdk";
21
- import type {
22
- Associate,
23
- BusinessUnit,
24
- BusinessUnitAddAddressAction,
25
- BusinessUnitAddAssociateAction,
26
- BusinessUnitAddStoreAction,
27
- BusinessUnitChangeAddressAction,
28
- BusinessUnitChangeNameAction,
29
- BusinessUnitChangeParentUnitAction,
30
- BusinessUnitDraft,
31
- BusinessUnitRemoveAddressAction,
32
- BusinessUnitSetAssociatesAction,
33
- BusinessUnitSetContactEmailAction,
34
29
  BusinessUnitSetStoreModeAction,
30
+ BusinessUnitUpdateAction,
35
31
  Company,
32
+ CompanyDraft,
36
33
  Division,
34
+ DivisionDraft,
37
35
  } from "@commercetools/platform-sdk";
38
- import type { Config } from "~src/config";
39
- import { generateRandomString, getBaseResourceProperties } from "../helpers";
40
- import type { Writable } from "../types";
41
- import type { UpdateHandlerInterface } from "./abstract";
36
+ import type { Config } from "#src/config.ts";
37
+ import { generateRandomString, getBaseResourceProperties } from "../helpers.ts";
38
+ import type { Writable } from "../types.ts";
39
+ import type { UpdateHandlerInterface } from "./abstract.ts";
42
40
  import {
43
41
  AbstractResourceRepository,
44
42
  AbstractUpdateHandler,
45
43
  type RepositoryContext,
46
- } from "./abstract";
44
+ } from "./abstract.ts";
47
45
  import {
48
46
  createAddress,
49
47
  createAssociate,
50
48
  createCustomFields,
51
49
  getBusinessUnitKeyReference,
52
50
  getStoreKeyReference,
53
- } from "./helpers";
51
+ } from "./helpers.ts";
54
52
 
55
53
  export class BusinessUnitRepository extends AbstractResourceRepository<"business-unit"> {
56
54
  constructor(config: Config) {
@@ -213,15 +211,12 @@ class BusinessUnitUpdateHandler
213
211
  }
214
212
 
215
213
  const newAddress = createAddress(
216
- address,
214
+ { ...address, id: addressId },
217
215
  context.projectKey,
218
216
  this._storage,
219
217
  );
220
218
  if (newAddress) {
221
- resource.addresses[existingAddressIndex] = {
222
- ...newAddress,
223
- id: addressId,
224
- };
219
+ resource.addresses[existingAddressIndex] = newAddress;
225
220
  }
226
221
  }
227
222
 
@@ -1,8 +1,3 @@
1
- import type {
2
- CartSetAnonymousIdAction,
3
- CartSetCustomerIdAction,
4
- CartUpdateAction,
5
- } from "@commercetools/platform-sdk";
6
1
  import type {
7
2
  Address,
8
3
  AddressDraft,
@@ -18,13 +13,15 @@ import type {
18
13
  CartRemoveDiscountCodeAction,
19
14
  CartRemoveLineItemAction,
20
15
  CartRemoveShippingMethodAction,
16
+ CartSetAnonymousIdAction,
21
17
  CartSetBillingAddressAction,
22
18
  CartSetBillingAddressCustomTypeAction,
23
19
  CartSetCountryAction,
20
+ CartSetCustomerEmailAction,
21
+ CartSetCustomerIdAction,
24
22
  CartSetCustomFieldAction,
25
23
  CartSetCustomShippingMethodAction,
26
24
  CartSetCustomTypeAction,
27
- CartSetCustomerEmailAction,
28
25
  CartSetDirectDiscountsAction,
29
26
  CartSetLineItemCustomFieldAction,
30
27
  CartSetLineItemCustomTypeAction,
@@ -35,6 +32,7 @@ import type {
35
32
  CartSetShippingAddressCustomFieldAction,
36
33
  CartSetShippingAddressCustomTypeAction,
37
34
  CartSetShippingMethodAction,
35
+ CartUpdateAction,
38
36
  CustomFields,
39
37
  GeneralError,
40
38
  ItemShippingDetails,
@@ -42,7 +40,6 @@ import type {
42
40
  Product,
43
41
  ProductPagedQueryResponse,
44
42
  ProductVariant,
45
- TaxCategoryReference,
46
43
  } from "@commercetools/platform-sdk";
47
44
  import type {
48
45
  CustomLineItem,
@@ -50,23 +47,23 @@ import type {
50
47
  } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/cart";
51
48
  import type { ShippingMethodResourceIdentifier } from "@commercetools/platform-sdk/dist/declarations/src/generated/models/shipping-method";
52
49
  import { v4 as uuidv4 } from "uuid";
53
- import { CommercetoolsError } from "~src/exceptions";
54
- import type { Writable } from "~src/types";
55
- import type { CartRepository } from ".";
56
- import type { UpdateHandlerInterface } from "../abstract";
57
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
50
+ import { CommercetoolsError } from "#src/exceptions.ts";
51
+ import type { Writable } from "#src/types.ts";
52
+ import type { UpdateHandlerInterface } from "../abstract.ts";
53
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
58
54
  import {
59
55
  createAddress,
60
56
  createCentPrecisionMoney,
61
57
  createCustomFields,
62
58
  createTypedMoney,
63
- } from "../helpers";
59
+ } from "../helpers.ts";
64
60
  import {
65
61
  calculateCartTotalPrice,
66
62
  calculateLineItemTotalPrice,
67
63
  createCustomLineItemFromDraft,
68
64
  selectPrice,
69
- } from "./helpers";
65
+ } from "./helpers.ts";
66
+ import type { CartRepository } from "./index.ts";
70
67
 
71
68
  export class CartUpdateHandler
72
69
  extends AbstractUpdateHandler
@@ -857,7 +854,7 @@ export class CartUpdateHandler
857
854
  return;
858
855
  }
859
856
 
860
- let custom: CustomFields | undefined = undefined;
857
+ let custom: CustomFields | undefined;
861
858
  if ((address as Address & AddressDraft).custom) {
862
859
  custom = createCustomFields(
863
860
  (address as Address & AddressDraft).custom,
@@ -8,14 +8,14 @@ import type {
8
8
  TaxCategoryReference,
9
9
  } from "@commercetools/platform-sdk";
10
10
  import { v4 as uuidv4 } from "uuid";
11
- import { calculateTaxedPrice } from "~src/lib/tax";
12
- import type { AbstractStorage } from "~src/storage/abstract";
11
+ import { calculateTaxedPrice } from "#src/lib/tax.ts";
12
+ import type { AbstractStorage } from "#src/storage/abstract.ts";
13
13
  import {
14
14
  createCentPrecisionMoney,
15
15
  createCustomFields,
16
16
  createTypedMoney,
17
17
  getReferenceFromResourceIdentifier,
18
- } from "../helpers";
18
+ } from "../helpers.ts";
19
19
 
20
20
  export const selectPrice = ({
21
21
  prices,
@@ -71,13 +71,13 @@ export const createCustomLineItemFromDraft = (
71
71
  )
72
72
  : undefined;
73
73
 
74
- let taxCategory: TaxCategory | undefined = undefined;
74
+ let taxCategory: TaxCategory | undefined;
75
75
  if (taxCategoryRef) {
76
76
  try {
77
77
  taxCategory =
78
78
  storage.get(projectKey, "tax-category", taxCategoryRef.id, {}) ||
79
79
  undefined;
80
- } catch (error) {
80
+ } catch (_error) {
81
81
  // Tax category not found, continue without tax calculation
82
82
  }
83
83
  }
@@ -1,14 +1,9 @@
1
- import type {
2
- Cart,
3
- CartDraft,
4
- CustomLineItemDraft,
5
- LineItem,
6
- } from "@commercetools/platform-sdk";
1
+ import type { CartDraft, LineItem } from "@commercetools/platform-sdk";
7
2
  import { beforeEach, describe, expect, test } from "vitest";
8
- import type { Config } from "~src/config";
9
- import { getBaseResourceProperties } from "~src/helpers";
10
- import { InMemoryStorage } from "~src/storage";
11
- import { CartRepository } from "./index";
3
+ import type { Config } from "#src/config.ts";
4
+ import { getBaseResourceProperties } from "#src/helpers.ts";
5
+ import { InMemoryStorage } from "#src/storage/index.ts";
6
+ import { CartRepository } from "./index.ts";
12
7
 
13
8
  describe("Cart repository", () => {
14
9
  const storage = new InMemoryStorage();
@@ -1,41 +1,36 @@
1
1
  import type {
2
2
  BusinessUnit,
3
- InvalidOperationError,
4
- MissingTaxRateForCountryError,
5
- ShippingMethodDoesNotMatchCartError,
6
- } from "@commercetools/platform-sdk";
7
- import type {
8
3
  Cart,
9
4
  CartDraft,
10
- CustomLineItem,
11
- CustomLineItemDraft,
12
5
  GeneralError,
6
+ InvalidOperationError,
13
7
  LineItem,
14
8
  LineItemDraft,
15
9
  Product,
16
10
  ProductPagedQueryResponse,
11
+ ShippingMethodDoesNotMatchCartError,
17
12
  } from "@commercetools/platform-sdk";
18
13
  import { v4 as uuidv4 } from "uuid";
19
- import type { Config } from "~src/config";
20
- import { CommercetoolsError } from "~src/exceptions";
21
- import { getBaseResourceProperties } from "~src/helpers";
22
- import { calculateTaxTotals } from "~src/lib/tax";
14
+ import type { Config } from "#src/config.ts";
15
+ import { CommercetoolsError } from "#src/exceptions.ts";
16
+ import { getBaseResourceProperties } from "#src/helpers.ts";
17
+ import { calculateTaxTotals } from "#src/lib/tax.ts";
23
18
  import {
24
19
  createShippingInfoFromMethod,
25
20
  getShippingMethodsMatchingCart,
26
- } from "~src/shipping";
27
- import type { Writable } from "~src/types";
21
+ } from "#src/shipping.ts";
22
+ import type { Writable } from "#src/types.ts";
28
23
  import {
29
24
  AbstractResourceRepository,
30
25
  type RepositoryContext,
31
- } from "../abstract";
32
- import { createAddress, createCustomFields } from "../helpers";
33
- import { CartUpdateHandler } from "./actions";
26
+ } from "../abstract.ts";
27
+ import { createAddress, createCustomFields } from "../helpers.ts";
28
+ import { CartUpdateHandler } from "./actions.ts";
34
29
  import {
35
30
  calculateCartTotalPrice,
36
31
  createCustomLineItemFromDraft,
37
32
  selectPrice,
38
- } from "./helpers";
33
+ } from "./helpers.ts";
39
34
 
40
35
  export class CartRepository extends AbstractResourceRepository<"cart"> {
41
36
  constructor(config: Config) {
@@ -59,7 +54,7 @@ export class CartRepository extends AbstractResourceRepository<"cart"> {
59
54
  });
60
55
  }
61
56
 
62
- let storedBusinessUnit: BusinessUnit | undefined = undefined;
57
+ let storedBusinessUnit: BusinessUnit | undefined;
63
58
  if (draft.businessUnit?.id || draft.businessUnit?.key) {
64
59
  storedBusinessUnit =
65
60
  this._storage.getByResourceIdentifier<"business-unit">(
@@ -14,12 +14,11 @@ import type {
14
14
  CartDiscountUpdateAction,
15
15
  InvalidOperationError,
16
16
  } from "@commercetools/platform-sdk";
17
- import type { Writable } from "~src/types";
18
- import type { UpdateHandlerInterface } from "../abstract";
19
- import { AbstractUpdateHandler, type RepositoryContext } from "../abstract";
20
-
21
- import { CommercetoolsError } from "~src/exceptions";
22
- import { getStoreKeyReference } from "~src/repositories/helpers";
17
+ import { CommercetoolsError } from "#src/exceptions.ts";
18
+ import { getStoreKeyReference } from "#src/repositories/helpers.ts";
19
+ import type { Writable } from "#src/types.ts";
20
+ import type { UpdateHandlerInterface } from "../abstract.ts";
21
+ import { AbstractUpdateHandler, type RepositoryContext } from "../abstract.ts";
23
22
 
24
23
  export class CartDiscountUpdateHandler
25
24
  extends AbstractUpdateHandler
@@ -7,18 +7,18 @@ import type {
7
7
  CartDiscountValueGiftLineItem,
8
8
  CartDiscountValueRelative,
9
9
  } from "@commercetools/platform-sdk";
10
- import type { Config } from "~src/config";
11
- import { getBaseResourceProperties } from "~src/helpers";
10
+ import type { Config } from "#src/config.ts";
11
+ import { getBaseResourceProperties } from "#src/helpers.ts";
12
12
  import {
13
13
  AbstractResourceRepository,
14
14
  type RepositoryContext,
15
- } from "../abstract";
15
+ } from "../abstract.ts";
16
16
  import {
17
17
  createCustomFields,
18
18
  createTypedMoney,
19
19
  getStoreKeyReference,
20
- } from "../helpers";
21
- import { CartDiscountUpdateHandler } from "./actions";
20
+ } from "../helpers.ts";
21
+ import { CartDiscountUpdateHandler } from "./actions.ts";
22
22
 
23
23
  export class CartDiscountRepository extends AbstractResourceRepository<"cart-discount"> {
24
24
  constructor(config: Config) {
@@ -20,10 +20,10 @@ import type {
20
20
  CategoryUpdateAction,
21
21
  } from "@commercetools/platform-sdk";
22
22
  import { v4 as uuidv4 } from "uuid";
23
- import type { Writable } from "~src/types";
24
- import type { RepositoryContext, UpdateHandlerInterface } from "../abstract";
25
- import { AbstractUpdateHandler } from "../abstract";
26
- import { createCustomFields } from "../helpers";
23
+ import type { Writable } from "#src/types.ts";
24
+ import type { RepositoryContext, UpdateHandlerInterface } from "../abstract.ts";
25
+ import { AbstractUpdateHandler } from "../abstract.ts";
26
+ import { createCustomFields } from "../helpers.ts";
27
27
 
28
28
  export class CategoryUpdateHandler
29
29
  extends AbstractUpdateHandler
@@ -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 { CategoryRepository } from "./index";
2
+ import type { Config } from "#src/config.ts";
3
+ import { InMemoryStorage } from "#src/storage/index.ts";
4
+ import { CategoryRepository } from "./index.ts";
5
5
 
6
6
  describe("Order repository", () => {
7
7
  const storage = new InMemoryStorage();
@@ -4,17 +4,17 @@ import type {
4
4
  CategoryReference,
5
5
  } from "@commercetools/platform-sdk";
6
6
  import { v4 as uuidv4 } from "uuid";
7
- import type { Config } from "~src/config";
8
- import { getBaseResourceProperties } from "~src/helpers";
9
- import { parseExpandClause } from "~src/lib/expandParser";
10
- import type { Writable } from "~src/types";
11
- import type { GetParams } from "../abstract";
7
+ import type { Config } from "#src/config.ts";
8
+ import { getBaseResourceProperties } from "#src/helpers.ts";
9
+ import { parseExpandClause } from "#src/lib/expandParser.ts";
10
+ import type { Writable } from "#src/types.ts";
11
+ import type { GetParams } from "../abstract.ts";
12
12
  import {
13
13
  AbstractResourceRepository,
14
14
  type RepositoryContext,
15
- } from "../abstract";
16
- import { createCustomFields } from "../helpers";
17
- import { CategoryUpdateHandler } from "./actions";
15
+ } from "../abstract.ts";
16
+ import { createCustomFields } from "../helpers.ts";
17
+ import { CategoryUpdateHandler } from "./actions.ts";
18
18
 
19
19
  export class CategoryRepository extends AbstractResourceRepository<"category"> {
20
20
  constructor(config: Config) {
@@ -9,10 +9,10 @@ import type {
9
9
  ChannelSetGeoLocationAction,
10
10
  } from "@commercetools/platform-sdk";
11
11
  import { describe, expect, test } from "vitest";
12
- import type { Config } from "~src/config";
13
- import { getBaseResourceProperties } from "~src/helpers";
14
- import { InMemoryStorage } from "~src/storage";
15
- import { ChannelRepository } from "./channel";
12
+ import type { Config } from "#src/config.ts";
13
+ import { getBaseResourceProperties } from "#src/helpers.ts";
14
+ import { InMemoryStorage } from "#src/storage/index.ts";
15
+ import { ChannelRepository } from "./channel.ts";
16
16
 
17
17
  describe("Channel Repository", () => {
18
18
  const storage = new InMemoryStorage();
@@ -10,16 +10,16 @@ import type {
10
10
  ChannelSetGeoLocationAction,
11
11
  ChannelUpdateAction,
12
12
  } from "@commercetools/platform-sdk";
13
- import type { Config } from "~src/config";
14
- import { getBaseResourceProperties } from "../helpers";
15
- import type { Writable } from "../types";
16
- import type { UpdateHandlerInterface } from "./abstract";
13
+ import type { Config } from "#src/config.ts";
14
+ import { getBaseResourceProperties } from "../helpers.ts";
15
+ import type { Writable } from "../types.ts";
16
+ import type { UpdateHandlerInterface } from "./abstract.ts";
17
17
  import {
18
18
  AbstractResourceRepository,
19
19
  AbstractUpdateHandler,
20
20
  type RepositoryContext,
21
- } from "./abstract";
22
- import { createAddress, createCustomFields } from "./helpers";
21
+ } from "./abstract.ts";
22
+ import { createAddress, createCustomFields } from "./helpers.ts";
23
23
 
24
24
  export class ChannelRepository extends AbstractResourceRepository<"channel"> {
25
25
  constructor(config: Config) {