@labdigital/commercetools-mock 2.59.1 → 2.61.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 (222) hide show
  1. package/dist/{index.d.ts → index.d.mts} +154 -275
  2. package/dist/{index.js → index.mjs} +413 -401
  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 +119 -0
  25. package/src/lib/tax.ts +186 -0
  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 +21 -23
  43. package/src/repositories/cart/actions.ts +79 -15
  44. package/src/repositories/cart/helpers.ts +5 -84
  45. package/src/repositories/cart/index.test.ts +53 -10
  46. package/src/repositories/cart/index.ts +17 -21
  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 +9 -9
  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.ts +9 -12
  68. package/src/repositories/index.test.ts +3 -3
  69. package/src/repositories/index.ts +43 -43
  70. package/src/repositories/inventory-entry/actions.ts +15 -3
  71. package/src/repositories/inventory-entry/index.ts +5 -5
  72. package/src/repositories/my-customer.ts +5 -5
  73. package/src/repositories/my-order.ts +2 -2
  74. package/src/repositories/my-quote-request.ts +1 -1
  75. package/src/repositories/order/actions.ts +8 -9
  76. package/src/repositories/order/index.test.ts +191 -9
  77. package/src/repositories/order/index.ts +63 -21
  78. package/src/repositories/order-edit.ts +4 -4
  79. package/src/repositories/payment/actions.ts +6 -6
  80. package/src/repositories/payment/helpers.ts +3 -3
  81. package/src/repositories/payment/index.ts +7 -7
  82. package/src/repositories/product/actions.ts +7 -7
  83. package/src/repositories/product/helpers.ts +4 -4
  84. package/src/repositories/product/index.ts +13 -13
  85. package/src/repositories/product-discount.ts +9 -6
  86. package/src/repositories/product-projection.ts +7 -7
  87. package/src/repositories/product-selection.ts +9 -6
  88. package/src/repositories/product-tailoring.ts +6 -3
  89. package/src/repositories/product-type.ts +8 -5
  90. package/src/repositories/project.ts +5 -5
  91. package/src/repositories/quote/actions.ts +6 -6
  92. package/src/repositories/quote/index.ts +5 -5
  93. package/src/repositories/quote-request/actions.ts +6 -6
  94. package/src/repositories/quote-request/index.test.ts +3 -3
  95. package/src/repositories/quote-request/index.ts +5 -5
  96. package/src/repositories/quote-staged/actions.ts +6 -6
  97. package/src/repositories/quote-staged/index.ts +5 -5
  98. package/src/repositories/recurrence-policy/actions.ts +3 -3
  99. package/src/repositories/recurrence-policy/index.ts +4 -8
  100. package/src/repositories/recurring-order/actions.ts +3 -3
  101. package/src/repositories/recurring-order/index.ts +5 -5
  102. package/src/repositories/review.test.ts +5 -5
  103. package/src/repositories/review.ts +10 -9
  104. package/src/repositories/shipping-method/actions.ts +7 -9
  105. package/src/repositories/shipping-method/helpers.ts +1 -1
  106. package/src/repositories/shipping-method/index.ts +8 -8
  107. package/src/repositories/shopping-list/actions.ts +5 -5
  108. package/src/repositories/shopping-list/index.ts +7 -7
  109. package/src/repositories/standalone-price.ts +9 -6
  110. package/src/repositories/state.ts +9 -6
  111. package/src/repositories/store.ts +10 -7
  112. package/src/repositories/subscription.test.ts +3 -3
  113. package/src/repositories/subscription.ts +9 -6
  114. package/src/repositories/tax-category/actions.ts +4 -4
  115. package/src/repositories/tax-category/index.ts +6 -6
  116. package/src/repositories/type/actions.ts +4 -4
  117. package/src/repositories/type/index.ts +5 -5
  118. package/src/repositories/zone.test.ts +3 -3
  119. package/src/repositories/zone.ts +8 -5
  120. package/src/server.ts +4 -3
  121. package/src/services/abstract.ts +5 -5
  122. package/src/services/as-associate-cart.test.ts +1 -1
  123. package/src/services/as-associate-cart.ts +2 -2
  124. package/src/services/as-associate-order.test.ts +1 -1
  125. package/src/services/as-associate-order.ts +2 -2
  126. package/src/services/as-associate-quote-request.ts +2 -3
  127. package/src/services/as-associate.test.ts +1 -1
  128. package/src/services/as-associate.ts +4 -4
  129. package/src/services/associate-roles.test.ts +1 -1
  130. package/src/services/associate-roles.ts +2 -2
  131. package/src/services/attribute-group.test.ts +1 -1
  132. package/src/services/attribute-group.ts +2 -2
  133. package/src/services/business-units.test.ts +5 -5
  134. package/src/services/business-units.ts +2 -2
  135. package/src/services/cart-discount.ts +2 -2
  136. package/src/services/cart.test.ts +213 -2
  137. package/src/services/cart.ts +4 -5
  138. package/src/services/category.test.ts +1 -1
  139. package/src/services/category.ts +2 -2
  140. package/src/services/channel.test.ts +1 -1
  141. package/src/services/channel.ts +2 -2
  142. package/src/services/custom-object.test.ts +2 -2
  143. package/src/services/custom-object.ts +3 -3
  144. package/src/services/customer-group.test.ts +1 -1
  145. package/src/services/customer-group.ts +2 -2
  146. package/src/services/customer.test.ts +3 -3
  147. package/src/services/customer.ts +4 -5
  148. package/src/services/discount-code.test.ts +1 -1
  149. package/src/services/discount-code.ts +2 -2
  150. package/src/services/discount-group.test.ts +1 -1
  151. package/src/services/discount-group.ts +2 -2
  152. package/src/services/extension.test.ts +1 -1
  153. package/src/services/extension.ts +2 -2
  154. package/src/services/index.ts +44 -44
  155. package/src/services/inventory-entry.test.ts +16 -1
  156. package/src/services/inventory-entry.ts +2 -2
  157. package/src/services/my-business-unit.test.ts +1 -1
  158. package/src/services/my-business-unit.ts +2 -2
  159. package/src/services/my-cart.test.ts +1 -1
  160. package/src/services/my-cart.ts +2 -2
  161. package/src/services/my-customer.test.ts +2 -2
  162. package/src/services/my-customer.ts +6 -6
  163. package/src/services/my-order.ts +2 -2
  164. package/src/services/my-payment.test.ts +1 -1
  165. package/src/services/my-payment.ts +2 -2
  166. package/src/services/my-shopping-list.ts +2 -2
  167. package/src/services/order.test.ts +4 -11
  168. package/src/services/order.ts +4 -4
  169. package/src/services/payment.test.ts +1 -1
  170. package/src/services/payment.ts +2 -2
  171. package/src/services/product-discount.test.ts +1 -1
  172. package/src/services/product-discount.ts +2 -2
  173. package/src/services/product-projection.test.ts +2 -2
  174. package/src/services/product-projection.ts +4 -4
  175. package/src/services/product-selection.test.ts +1 -1
  176. package/src/services/product-selection.ts +2 -2
  177. package/src/services/product-type.test.ts +1 -1
  178. package/src/services/product-type.ts +2 -2
  179. package/src/services/product.test.ts +1 -1
  180. package/src/services/product.ts +3 -3
  181. package/src/services/project.test.ts +1 -1
  182. package/src/services/project.ts +4 -4
  183. package/src/services/quote-request.test.ts +2 -2
  184. package/src/services/quote-request.ts +2 -2
  185. package/src/services/quote-staged.ts +2 -2
  186. package/src/services/quote.ts +2 -2
  187. package/src/services/recurrence-policy.test.ts +1 -1
  188. package/src/services/recurrence-policy.ts +2 -2
  189. package/src/services/recurring-order.test.ts +1 -1
  190. package/src/services/recurring-order.ts +2 -2
  191. package/src/services/reviews.test.ts +1 -1
  192. package/src/services/reviews.ts +2 -2
  193. package/src/services/shipping-method.test.ts +2 -2
  194. package/src/services/shipping-method.ts +4 -4
  195. package/src/services/shopping-list.test.ts +1 -1
  196. package/src/services/shopping-list.ts +2 -2
  197. package/src/services/standalone-price.test.ts +1 -1
  198. package/src/services/standalone-price.ts +2 -2
  199. package/src/services/state.test.ts +1 -1
  200. package/src/services/state.ts +2 -2
  201. package/src/services/store.test.ts +1 -1
  202. package/src/services/store.ts +2 -2
  203. package/src/services/subscription.test.ts +1 -1
  204. package/src/services/subscription.ts +2 -2
  205. package/src/services/tax-category.test.ts +1 -1
  206. package/src/services/tax-category.ts +2 -2
  207. package/src/services/type.test.ts +1 -1
  208. package/src/services/type.ts +2 -2
  209. package/src/services/zone.test.ts +1 -1
  210. package/src/services/zone.ts +2 -2
  211. package/src/shipping.test.ts +1 -1
  212. package/src/shipping.ts +8 -8
  213. package/src/storage/abstract.ts +1 -1
  214. package/src/storage/in-memory.ts +15 -17
  215. package/src/storage/index.ts +2 -2
  216. package/src/testing/business-unit.ts +1 -2
  217. package/src/testing/customer.ts +1 -1
  218. package/src/testing/type.ts +1 -1
  219. package/src/types.ts +1 -1
  220. package/src/validate.ts +1 -1
  221. package/dist/index.d.ts.map +0 -1
  222. package/dist/index.js.map +0 -1
package/src/lib/tax.ts ADDED
@@ -0,0 +1,186 @@
1
+ import type {
2
+ Cart,
3
+ TaxCategory,
4
+ TaxedItemPrice,
5
+ TaxedPrice,
6
+ TaxPortion,
7
+ TaxRate,
8
+ } from "@commercetools/platform-sdk";
9
+ import { createCentPrecisionMoney } from "#src/repositories/helpers.ts";
10
+
11
+ type TaxableResource = Pick<
12
+ Cart,
13
+ "lineItems" | "customLineItems" | "shippingInfo" | "totalPrice"
14
+ >;
15
+
16
+ export const calculateTaxTotals = (
17
+ resource: TaxableResource,
18
+ ): {
19
+ taxedPrice?: TaxedPrice;
20
+ taxedShippingPrice?: TaxedItemPrice;
21
+ } => {
22
+ const taxedItemPrices: TaxedItemPrice[] = [];
23
+
24
+ resource.lineItems.forEach((item) => {
25
+ if (item.taxedPrice) {
26
+ taxedItemPrices.push(item.taxedPrice);
27
+ }
28
+ });
29
+
30
+ resource.customLineItems.forEach((item) => {
31
+ if (item.taxedPrice) {
32
+ taxedItemPrices.push(item.taxedPrice);
33
+ }
34
+ });
35
+
36
+ let taxedShippingPrice: TaxedItemPrice | undefined;
37
+ if (resource.shippingInfo?.taxedPrice) {
38
+ taxedShippingPrice = resource.shippingInfo.taxedPrice;
39
+ taxedItemPrices.push(resource.shippingInfo.taxedPrice);
40
+ }
41
+
42
+ if (!taxedItemPrices.length) {
43
+ return {
44
+ taxedPrice: undefined,
45
+ taxedShippingPrice,
46
+ };
47
+ }
48
+
49
+ const currencyCode = resource.totalPrice.currencyCode;
50
+ const toMoney = (centAmount: number) =>
51
+ createCentPrecisionMoney({
52
+ currencyCode,
53
+ centAmount,
54
+ });
55
+
56
+ let totalNet = 0;
57
+ let totalGross = 0;
58
+ let totalTax = 0;
59
+
60
+ const taxPortionsByRate = new Map<
61
+ string,
62
+ { rate: number; name?: string; centAmount: number }
63
+ >();
64
+
65
+ taxedItemPrices.forEach((price) => {
66
+ totalNet += price.totalNet.centAmount;
67
+ totalGross += price.totalGross.centAmount;
68
+ const priceTax = price.totalTax
69
+ ? price.totalTax.centAmount
70
+ : price.totalGross.centAmount - price.totalNet.centAmount;
71
+ totalTax += Math.max(priceTax, 0);
72
+
73
+ price.taxPortions?.forEach((portion) => {
74
+ const key = `${portion.rate}-${portion.name ?? ""}`;
75
+ const existing = taxPortionsByRate.get(key) ?? {
76
+ rate: portion.rate,
77
+ name: portion.name,
78
+ centAmount: 0,
79
+ };
80
+ existing.centAmount += portion.amount.centAmount;
81
+ taxPortionsByRate.set(key, existing);
82
+ });
83
+ });
84
+
85
+ const taxPortions: TaxPortion[] = Array.from(taxPortionsByRate.values()).map(
86
+ (portion) => ({
87
+ rate: portion.rate,
88
+ name: portion.name,
89
+ amount: toMoney(portion.centAmount),
90
+ }),
91
+ );
92
+
93
+ return {
94
+ taxedPrice: {
95
+ totalNet: toMoney(totalNet),
96
+ totalGross: toMoney(totalGross),
97
+ taxPortions,
98
+ totalTax: totalTax > 0 ? toMoney(totalTax) : undefined,
99
+ },
100
+ taxedShippingPrice,
101
+ };
102
+ };
103
+
104
+ export const buildTaxedPriceFromRate = (
105
+ amount: number,
106
+ currencyCode: string,
107
+ taxRate?: TaxRate,
108
+ ): TaxedItemPrice | undefined => {
109
+ if (!taxRate) {
110
+ return undefined;
111
+ }
112
+
113
+ const toMoney = (centAmount: number) =>
114
+ createCentPrecisionMoney({
115
+ type: "centPrecision",
116
+ currencyCode,
117
+ centAmount,
118
+ });
119
+
120
+ let netAmount: number;
121
+ let grossAmount: number;
122
+ let taxAmount: number;
123
+
124
+ if (taxRate.includedInPrice) {
125
+ grossAmount = amount;
126
+ taxAmount = Math.round(
127
+ (grossAmount * taxRate.amount) / (1 + taxRate.amount),
128
+ );
129
+ netAmount = grossAmount - taxAmount;
130
+ } else {
131
+ netAmount = amount;
132
+ taxAmount = Math.round(netAmount * taxRate.amount);
133
+ grossAmount = netAmount + taxAmount;
134
+ }
135
+
136
+ return {
137
+ totalNet: toMoney(netAmount),
138
+ totalGross: toMoney(grossAmount),
139
+ totalTax: taxAmount > 0 ? toMoney(taxAmount) : undefined,
140
+ taxPortions:
141
+ taxAmount > 0
142
+ ? [
143
+ {
144
+ rate: taxRate.amount,
145
+ name: taxRate.name,
146
+ amount: toMoney(taxAmount),
147
+ },
148
+ ]
149
+ : [],
150
+ };
151
+ };
152
+
153
+ export const calculateTaxedPriceFromRate = (
154
+ amount: number,
155
+ currencyCode: string,
156
+ taxRate?: TaxRate,
157
+ ): TaxedItemPrice | undefined =>
158
+ buildTaxedPriceFromRate(amount, currencyCode, taxRate);
159
+
160
+ export const calculateTaxedPrice = (
161
+ amount: number,
162
+ taxCategory: TaxCategory | undefined,
163
+ currency: string,
164
+ country: string | undefined,
165
+ ): TaxedPrice | undefined => {
166
+ if (!taxCategory || !taxCategory.rates.length) {
167
+ return undefined;
168
+ }
169
+
170
+ const taxRate =
171
+ taxCategory.rates.find(
172
+ (rate) => !rate.country || rate.country === country,
173
+ ) || taxCategory.rates[0];
174
+
175
+ const taxedItemPrice = buildTaxedPriceFromRate(amount, currency, taxRate);
176
+ if (!taxedItemPrice) {
177
+ return undefined;
178
+ }
179
+
180
+ return {
181
+ totalNet: taxedItemPrice.totalNet,
182
+ totalGross: taxedItemPrice.totalGross,
183
+ taxPortions: taxedItemPrice.taxPortions,
184
+ totalTax: taxedItemPrice.totalTax,
185
+ };
186
+ };
@@ -1,13 +1,13 @@
1
1
  import express from "express";
2
2
  import supertest from "supertest";
3
3
  import { beforeEach, describe, expect, it } from "vitest";
4
- import type { Config } from "~src/config";
5
- import { getBaseResourceProperties } from "../helpers";
6
- import { hashPassword } from "../lib/password";
7
- import { CustomerRepository } from "../repositories/customer";
8
- import type { AbstractStorage } from "../storage";
9
- import { InMemoryStorage } from "../storage";
10
- import { OAuth2Server } from "./server";
4
+ import type { Config } from "#src/config.ts";
5
+ import { getBaseResourceProperties } from "../helpers.ts";
6
+ import { hashPassword } from "../lib/password.ts";
7
+ import { CustomerRepository } from "../repositories/customer/index.ts";
8
+ import type { AbstractStorage } from "../storage/index.ts";
9
+ import { InMemoryStorage } from "../storage/index.ts";
10
+ import { OAuth2Server } from "./server.ts";
11
11
 
12
12
  describe("OAuth2Server", () => {
13
13
  let app: express.Express;
@@ -6,13 +6,13 @@ import express, {
6
6
  type Request,
7
7
  type Response,
8
8
  } from "express";
9
- import type { AuthError, InvalidRequestError } from "~src/exceptions";
10
- import { CommercetoolsError } from "~src/exceptions";
11
- import { hashPassword } from "../lib/password";
12
- import type { CustomerRepository } from "../repositories/customer";
13
- import type { InvalidClientError, UnsupportedGrantType } from "./errors";
14
- import { getBearerToken } from "./helpers";
15
- import { OAuth2Store } from "./store";
9
+ import type { AuthError, InvalidRequestError } from "#src/exceptions.ts";
10
+ import { CommercetoolsError } from "#src/exceptions.ts";
11
+ import { hashPassword } from "../lib/password.ts";
12
+ import type { CustomerRepository } from "../repositories/customer/index.ts";
13
+ import type { InvalidClientError, UnsupportedGrantType } from "./errors.ts";
14
+ import { getBearerToken } from "./helpers.ts";
15
+ import { OAuth2Store } from "./store.ts";
16
16
 
17
17
  type AuthRequest = Request & {
18
18
  credentials?: {
@@ -1,6 +1,6 @@
1
1
  import type { ProductProjection } from "@commercetools/platform-sdk";
2
2
  import { beforeEach, describe, expect, test } from "vitest";
3
- import { applyPriceSelector } from "./priceSelector";
3
+ import { applyPriceSelector } from "./priceSelector.ts";
4
4
 
5
5
  describe("priceSelector", () => {
6
6
  let product: ProductProjection;
@@ -4,8 +4,8 @@ import type {
4
4
  ProductProjection,
5
5
  ProductVariant,
6
6
  } from "@commercetools/platform-sdk";
7
- import { CommercetoolsError } from "./exceptions";
8
- import type { Writable } from "./types";
7
+ import { CommercetoolsError } from "./exceptions.ts";
8
+ import type { Writable } from "./types.ts";
9
9
 
10
10
  export type PriceSelector = {
11
11
  currency?: string;
@@ -3,30 +3,29 @@ import type {
3
3
  FilteredFacetResult,
4
4
  InvalidInputError,
5
5
  Product,
6
- ProductData,
7
6
  ProductProjection,
8
7
  ProductProjectionPagedSearchResponse,
9
8
  QueryParam,
10
9
  RangeFacetResult,
11
10
  TermFacetResult,
12
11
  } from "@commercetools/platform-sdk";
13
- import type { Config } from "./config";
14
- import { CommercetoolsError } from "./exceptions";
15
- import { nestedLookup } from "./helpers";
12
+ import type { Config } from "./config.ts";
13
+ import { CommercetoolsError } from "./exceptions.ts";
14
+ import { nestedLookup } from "./helpers.ts";
16
15
  import type {
17
16
  FilterExpression,
18
17
  RangeExpression,
19
- } from "./lib/projectionSearchFilter";
18
+ } from "./lib/projectionSearchFilter.ts";
20
19
  import {
21
20
  generateFacetFunc,
22
21
  getVariants,
23
22
  parseFilterExpression,
24
23
  resolveVariantValue,
25
- } from "./lib/projectionSearchFilter";
26
- import { ReviewStatisticsService } from "./lib/review-statistics";
27
- import { applyPriceSelector } from "./priceSelector";
28
- import type { AbstractStorage } from "./storage";
29
- import type { Writable } from "./types";
24
+ } from "./lib/projectionSearchFilter.ts";
25
+ import { ReviewStatisticsService } from "./lib/review-statistics.ts";
26
+ import { applyPriceSelector } from "./priceSelector.ts";
27
+ import type { AbstractStorage } from "./storage/index.ts";
28
+ import type { Writable } from "./types.ts";
30
29
 
31
30
  export type ProductProjectionSearchParams = {
32
31
  fuzzy?: boolean;
@@ -94,7 +93,6 @@ export class ProductProjectionSearch {
94
93
  filters.every((f) => f(resource, markMatchingVariant)),
95
94
  );
96
95
  } catch (err) {
97
- console.error(err);
98
96
  throw new CommercetoolsError<InvalidInputError>(
99
97
  {
100
98
  code: "InvalidInput",
@@ -364,7 +362,7 @@ export class ProductProjectionSearch {
364
362
  }) || [];
365
363
  const data: RangeFacetResult = {
366
364
  type: "range",
367
- // @ts-ignore
365
+ // @ts-expect-error
368
366
  dataType: "number",
369
367
  ranges: counts,
370
368
  };
@@ -6,7 +6,7 @@ import type {
6
6
  } from "@commercetools/platform-sdk";
7
7
  import supertest from "supertest";
8
8
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
9
- import { CommercetoolsMock } from "./index";
9
+ import { CommercetoolsMock } from "./index.ts";
10
10
 
11
11
  describe("Product Search - Availability Filtering", () => {
12
12
  const ctMock = new CommercetoolsMock();
@@ -6,12 +6,12 @@ import type {
6
6
  ProductSearchRequest,
7
7
  ProductSearchResult,
8
8
  } from "@commercetools/platform-sdk";
9
- import type { Config } from "./config";
10
- import { CommercetoolsError } from "./exceptions";
11
- import { parseSearchQuery } from "./lib/productSearchFilter";
12
- import { validateSearchQuery } from "./lib/searchQueryTypeChecker";
13
- import { applyPriceSelector } from "./priceSelector";
14
- import type { AbstractStorage } from "./storage";
9
+ import type { Config } from "./config.ts";
10
+ import { CommercetoolsError } from "./exceptions.ts";
11
+ import { parseSearchQuery } from "./lib/productSearchFilter.ts";
12
+ import { validateSearchQuery } from "./lib/searchQueryTypeChecker.ts";
13
+ import { applyPriceSelector } from "./priceSelector.ts";
14
+ import type { AbstractStorage } from "./storage/index.ts";
15
15
 
16
16
  interface ProductSearchVariantAvailability {
17
17
  isOnStock: boolean;
@@ -78,7 +78,6 @@ export class ProductSearch {
78
78
  matchFunc(resource, markMatchingVariant),
79
79
  );
80
80
  } catch (err) {
81
- console.error(err);
82
81
  throw new CommercetoolsError<InvalidInputError>(
83
82
  {
84
83
  code: "InvalidInput",
@@ -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) {