@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.
- package/dist/{index.d.ts → index.d.mts} +154 -275
- package/dist/{index.js → index.mjs} +413 -401
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -18
- package/src/config.ts +1 -1
- package/src/ctMock.test.ts +1 -1
- package/src/ctMock.ts +22 -21
- package/src/index.test.ts +1 -1
- package/src/index.ts +3 -3
- package/src/lib/haversine.test.ts +2 -2
- package/src/lib/masking.ts +1 -1
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +1 -1
- package/src/lib/predicateParser.test.ts +1 -1
- package/src/lib/predicateParser.ts +4 -4
- package/src/lib/product-review-statistics.test.ts +4 -8
- package/src/lib/productSearchFilter.test.ts +3 -3
- package/src/lib/productSearchFilter.ts +6 -6
- package/src/lib/projectionSearchFilter.test.ts +3 -3
- package/src/lib/projectionSearchFilter.ts +4 -4
- package/src/lib/review-statistics.ts +1 -1
- package/src/lib/searchQueryTypeChecker.test.ts +3 -3
- package/src/lib/searchQueryTypeChecker.ts +8 -4
- package/src/lib/tax.test.ts +119 -0
- package/src/lib/tax.ts +186 -0
- package/src/oauth/server.test.ts +7 -7
- package/src/oauth/server.ts +7 -7
- package/src/priceSelector.test.ts +1 -1
- package/src/priceSelector.ts +2 -2
- package/src/product-projection-search.ts +10 -12
- package/src/product-search-availability.test.ts +1 -1
- package/src/product-search.ts +6 -7
- package/src/projectAPI.test.ts +1 -1
- package/src/projectAPI.ts +7 -7
- package/src/repositories/abstract.ts +8 -10
- package/src/repositories/as-associate.test.ts +4 -4
- package/src/repositories/as-associate.ts +3 -3
- package/src/repositories/associate-role.ts +7 -9
- package/src/repositories/attribute-group.test.ts +3 -3
- package/src/repositories/attribute-group.ts +5 -5
- package/src/repositories/business-unit.test.ts +6 -6
- package/src/repositories/business-unit.ts +21 -23
- package/src/repositories/cart/actions.ts +79 -15
- package/src/repositories/cart/helpers.ts +5 -84
- package/src/repositories/cart/index.test.ts +53 -10
- package/src/repositories/cart/index.ts +17 -21
- package/src/repositories/cart-discount/actions.ts +5 -6
- package/src/repositories/cart-discount/index.ts +5 -5
- package/src/repositories/category/actions.ts +4 -4
- package/src/repositories/category/index.test.ts +3 -3
- package/src/repositories/category/index.ts +8 -8
- package/src/repositories/channel.test.ts +4 -4
- package/src/repositories/channel.ts +6 -6
- package/src/repositories/custom-object.ts +11 -8
- package/src/repositories/customer/actions.ts +9 -9
- package/src/repositories/customer/index.test.ts +3 -3
- package/src/repositories/customer/index.ts +12 -9
- package/src/repositories/customer-group.test.ts +4 -4
- package/src/repositories/customer-group.ts +6 -6
- package/src/repositories/discount-code/actions.ts +4 -4
- package/src/repositories/discount-code/index.ts +5 -5
- package/src/repositories/discount-group/actions.ts +3 -4
- package/src/repositories/discount-group/index.ts +4 -4
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.test.ts +3 -3
- package/src/repositories/extension.ts +6 -6
- package/src/repositories/helpers.ts +9 -12
- package/src/repositories/index.test.ts +3 -3
- package/src/repositories/index.ts +43 -43
- package/src/repositories/inventory-entry/actions.ts +15 -3
- package/src/repositories/inventory-entry/index.ts +5 -5
- package/src/repositories/my-customer.ts +5 -5
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/my-quote-request.ts +1 -1
- package/src/repositories/order/actions.ts +8 -9
- package/src/repositories/order/index.test.ts +191 -9
- package/src/repositories/order/index.ts +63 -21
- package/src/repositories/order-edit.ts +4 -4
- package/src/repositories/payment/actions.ts +6 -6
- package/src/repositories/payment/helpers.ts +3 -3
- package/src/repositories/payment/index.ts +7 -7
- package/src/repositories/product/actions.ts +7 -7
- package/src/repositories/product/helpers.ts +4 -4
- package/src/repositories/product/index.ts +13 -13
- package/src/repositories/product-discount.ts +9 -6
- package/src/repositories/product-projection.ts +7 -7
- package/src/repositories/product-selection.ts +9 -6
- package/src/repositories/product-tailoring.ts +6 -3
- package/src/repositories/product-type.ts +8 -5
- package/src/repositories/project.ts +5 -5
- package/src/repositories/quote/actions.ts +6 -6
- package/src/repositories/quote/index.ts +5 -5
- package/src/repositories/quote-request/actions.ts +6 -6
- package/src/repositories/quote-request/index.test.ts +3 -3
- package/src/repositories/quote-request/index.ts +5 -5
- package/src/repositories/quote-staged/actions.ts +6 -6
- package/src/repositories/quote-staged/index.ts +5 -5
- package/src/repositories/recurrence-policy/actions.ts +3 -3
- package/src/repositories/recurrence-policy/index.ts +4 -8
- package/src/repositories/recurring-order/actions.ts +3 -3
- package/src/repositories/recurring-order/index.ts +5 -5
- package/src/repositories/review.test.ts +5 -5
- package/src/repositories/review.ts +10 -9
- package/src/repositories/shipping-method/actions.ts +7 -9
- package/src/repositories/shipping-method/helpers.ts +1 -1
- package/src/repositories/shipping-method/index.ts +8 -8
- package/src/repositories/shopping-list/actions.ts +5 -5
- package/src/repositories/shopping-list/index.ts +7 -7
- package/src/repositories/standalone-price.ts +9 -6
- package/src/repositories/state.ts +9 -6
- package/src/repositories/store.ts +10 -7
- package/src/repositories/subscription.test.ts +3 -3
- package/src/repositories/subscription.ts +9 -6
- package/src/repositories/tax-category/actions.ts +4 -4
- package/src/repositories/tax-category/index.ts +6 -6
- package/src/repositories/type/actions.ts +4 -4
- package/src/repositories/type/index.ts +5 -5
- package/src/repositories/zone.test.ts +3 -3
- package/src/repositories/zone.ts +8 -5
- package/src/server.ts +4 -3
- package/src/services/abstract.ts +5 -5
- package/src/services/as-associate-cart.test.ts +1 -1
- package/src/services/as-associate-cart.ts +2 -2
- package/src/services/as-associate-order.test.ts +1 -1
- package/src/services/as-associate-order.ts +2 -2
- package/src/services/as-associate-quote-request.ts +2 -3
- package/src/services/as-associate.test.ts +1 -1
- package/src/services/as-associate.ts +4 -4
- package/src/services/associate-roles.test.ts +1 -1
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.test.ts +1 -1
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +5 -5
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.ts +2 -2
- package/src/services/cart.test.ts +213 -2
- package/src/services/cart.ts +4 -5
- package/src/services/category.test.ts +1 -1
- package/src/services/category.ts +2 -2
- package/src/services/channel.test.ts +1 -1
- package/src/services/channel.ts +2 -2
- package/src/services/custom-object.test.ts +2 -2
- package/src/services/custom-object.ts +3 -3
- package/src/services/customer-group.test.ts +1 -1
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +3 -3
- package/src/services/customer.ts +4 -5
- package/src/services/discount-code.test.ts +1 -1
- package/src/services/discount-code.ts +2 -2
- package/src/services/discount-group.test.ts +1 -1
- package/src/services/discount-group.ts +2 -2
- package/src/services/extension.test.ts +1 -1
- package/src/services/extension.ts +2 -2
- package/src/services/index.ts +44 -44
- package/src/services/inventory-entry.test.ts +16 -1
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.test.ts +1 -1
- package/src/services/my-business-unit.ts +2 -2
- package/src/services/my-cart.test.ts +1 -1
- package/src/services/my-cart.ts +2 -2
- package/src/services/my-customer.test.ts +2 -2
- package/src/services/my-customer.ts +6 -6
- package/src/services/my-order.ts +2 -2
- package/src/services/my-payment.test.ts +1 -1
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.test.ts +4 -11
- package/src/services/order.ts +4 -4
- package/src/services/payment.test.ts +1 -1
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.test.ts +1 -1
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +2 -2
- package/src/services/product-projection.ts +4 -4
- package/src/services/product-selection.test.ts +1 -1
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.test.ts +1 -1
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +3 -3
- package/src/services/project.test.ts +1 -1
- package/src/services/project.ts +4 -4
- package/src/services/quote-request.test.ts +2 -2
- package/src/services/quote-request.ts +2 -2
- package/src/services/quote-staged.ts +2 -2
- package/src/services/quote.ts +2 -2
- package/src/services/recurrence-policy.test.ts +1 -1
- package/src/services/recurrence-policy.ts +2 -2
- package/src/services/recurring-order.test.ts +1 -1
- package/src/services/recurring-order.ts +2 -2
- package/src/services/reviews.test.ts +1 -1
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.test.ts +2 -2
- package/src/services/shipping-method.ts +4 -4
- package/src/services/shopping-list.test.ts +1 -1
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.test.ts +1 -1
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.test.ts +1 -1
- package/src/services/state.ts +2 -2
- package/src/services/store.test.ts +1 -1
- package/src/services/store.ts +2 -2
- package/src/services/subscription.test.ts +1 -1
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.test.ts +1 -1
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.test.ts +1 -1
- package/src/services/type.ts +2 -2
- package/src/services/zone.test.ts +1 -1
- package/src/services/zone.ts +2 -2
- package/src/shipping.test.ts +1 -1
- package/src/shipping.ts +8 -8
- package/src/storage/abstract.ts +1 -1
- package/src/storage/in-memory.ts +15 -17
- package/src/storage/index.ts +2 -2
- package/src/testing/business-unit.ts +1 -2
- package/src/testing/customer.ts +1 -1
- package/src/testing/type.ts +1 -1
- package/src/types.ts +1 -1
- package/src/validate.ts +1 -1
- package/dist/index.d.ts.map +0 -1
- 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
|
+
};
|
package/src/oauth/server.test.ts
CHANGED
|
@@ -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 "
|
|
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;
|
package/src/oauth/server.ts
CHANGED
|
@@ -6,13 +6,13 @@ import express, {
|
|
|
6
6
|
type Request,
|
|
7
7
|
type Response,
|
|
8
8
|
} from "express";
|
|
9
|
-
import type { AuthError, InvalidRequestError } from "
|
|
10
|
-
import { CommercetoolsError } from "
|
|
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;
|
package/src/priceSelector.ts
CHANGED
|
@@ -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-
|
|
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();
|
package/src/product-search.ts
CHANGED
|
@@ -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",
|
package/src/projectAPI.test.ts
CHANGED
package/src/projectAPI.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Config } from "./config";
|
|
2
|
-
import { getBaseResourceProperties } from "./helpers";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
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
|
-
|
|
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 "
|
|
11
|
-
import { CommercetoolsError } from "
|
|
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-
|
|
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-
|
|
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 "
|
|
3
|
-
import { InMemoryStorage } from "
|
|
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 "
|
|
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 "
|
|
10
|
-
import { InMemoryStorage } from "
|
|
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 "
|
|
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 "
|
|
13
|
-
import { getBaseResourceProperties } from "
|
|
14
|
-
import { InMemoryStorage } from "
|
|
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
|
|
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 "
|
|
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) {
|