@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.
- package/dist/{index.d.ts → index.d.mts} +154 -275
- package/dist/{index.js → index.mjs} +255 -359
- 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 +3 -3
- package/src/lib/tax.ts +3 -3
- 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 +23 -28
- package/src/repositories/cart/actions.ts +12 -15
- package/src/repositories/cart/helpers.ts +5 -5
- package/src/repositories/cart/index.test.ts +5 -10
- package/src/repositories/cart/index.ts +13 -18
- 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 +11 -14
- 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.test.ts +25 -0
- package/src/repositories/helpers.ts +14 -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 +8 -9
- package/src/repositories/order/index.ts +16 -17
- 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 +7 -3
- 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/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) {
|
|
@@ -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 "
|
|
54
|
-
import type { Writable } from "
|
|
55
|
-
import type {
|
|
56
|
-
import type
|
|
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
|
|
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 "
|
|
12
|
-
import type { AbstractStorage } from "
|
|
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
|
|
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 (
|
|
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 "
|
|
9
|
-
import { getBaseResourceProperties } from "
|
|
10
|
-
import { InMemoryStorage } from "
|
|
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 "
|
|
20
|
-
import { CommercetoolsError } from "
|
|
21
|
-
import { getBaseResourceProperties } from "
|
|
22
|
-
import { calculateTaxTotals } from "
|
|
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 "
|
|
27
|
-
import type { Writable } from "
|
|
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
|
|
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
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
import {
|
|
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 "
|
|
11
|
-
import { getBaseResourceProperties } from "
|
|
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 "
|
|
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 "
|
|
3
|
-
import { InMemoryStorage } from "
|
|
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 "
|
|
8
|
-
import { getBaseResourceProperties } from "
|
|
9
|
-
import { parseExpandClause } from "
|
|
10
|
-
import type { Writable } from "
|
|
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 "
|
|
13
|
-
import { getBaseResourceProperties } from "
|
|
14
|
-
import { InMemoryStorage } from "
|
|
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 "
|
|
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) {
|