@labdigital/commercetools-mock 2.66.0 → 3.0.0-beta.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/README.md +31 -8
- package/dist/abstract-BKFcva6S.mjs +1044 -0
- package/dist/abstract-BKFcva6S.mjs.map +1 -0
- package/dist/config-BcNSzPZz.d.mts +1718 -0
- package/dist/index.d.mts +50 -1633
- package/dist/index.mjs +3769 -2653
- package/dist/index.mjs.map +1 -1
- package/dist/storage/sqlite.d.mts +59 -0
- package/dist/storage/sqlite.mjs +234 -0
- package/dist/storage/sqlite.mjs.map +1 -0
- package/package.json +26 -29
- package/src/ctMock.ts +125 -136
- package/src/helpers.ts +14 -6
- package/src/index.ts +5 -0
- package/src/lib/masking.ts +4 -5
- package/src/lib/product-review-statistics.test.ts +257 -294
- package/src/lib/review-statistics.ts +17 -4
- package/src/oauth/helpers.ts +7 -4
- package/src/oauth/server.test.ts +102 -62
- package/src/oauth/server.ts +215 -213
- package/src/oauth/store.ts +20 -6
- package/src/orderSearch.ts +3 -3
- package/src/product-projection-search.ts +38 -20
- package/src/product-search-availability.test.ts +31 -52
- package/src/product-search.ts +19 -10
- package/src/projectAPI.ts +6 -22
- package/src/repositories/abstract.ts +182 -48
- package/src/repositories/as-associate.test.ts +19 -19
- package/src/repositories/associate-role.ts +12 -23
- package/src/repositories/attribute-group.test.ts +23 -23
- package/src/repositories/attribute-group.ts +6 -4
- package/src/repositories/business-unit.test.ts +63 -57
- package/src/repositories/business-unit.ts +107 -55
- package/src/repositories/cart/actions.ts +96 -65
- package/src/repositories/cart/helpers.ts +15 -11
- package/src/repositories/cart/index.test.ts +136 -30
- package/src/repositories/cart/index.ts +76 -59
- package/src/repositories/cart-discount/actions.ts +12 -44
- package/src/repositories/cart-discount/index.ts +20 -8
- package/src/repositories/category/actions.ts +27 -27
- package/src/repositories/category/index.test.ts +13 -9
- package/src/repositories/category/index.ts +40 -23
- package/src/repositories/channel.test.ts +53 -51
- package/src/repositories/channel.ts +12 -22
- package/src/repositories/custom-object.ts +34 -25
- package/src/repositories/customer/actions.ts +47 -25
- package/src/repositories/customer/index.test.ts +11 -11
- package/src/repositories/customer/index.ts +65 -35
- package/src/repositories/customer-group.test.ts +44 -42
- package/src/repositories/customer-group.ts +12 -22
- package/src/repositories/discount-code/actions.ts +3 -19
- package/src/repositories/discount-code/index.ts +9 -4
- package/src/repositories/discount-group/index.ts +8 -3
- package/src/repositories/extension.test.ts +27 -27
- package/src/repositories/extension.ts +10 -5
- package/src/repositories/helpers.ts +126 -47
- package/src/repositories/inventory-entry/actions.ts +3 -24
- package/src/repositories/inventory-entry/index.ts +19 -11
- package/src/repositories/my-customer.ts +13 -12
- package/src/repositories/my-order.ts +5 -2
- package/src/repositories/order/actions.ts +84 -56
- package/src/repositories/order/index.test.ts +36 -31
- package/src/repositories/order/index.ts +83 -49
- package/src/repositories/order-edit.ts +8 -3
- package/src/repositories/payment/actions.ts +64 -44
- package/src/repositories/payment/helpers.ts +3 -3
- package/src/repositories/payment/index.ts +28 -12
- package/src/repositories/product/actions.ts +133 -98
- package/src/repositories/product/helpers.ts +29 -16
- package/src/repositories/product/index.ts +42 -25
- package/src/repositories/product-discount.ts +6 -4
- package/src/repositories/product-projection.ts +41 -21
- package/src/repositories/product-selection.ts +8 -15
- package/src/repositories/product-tailoring.ts +22 -3
- package/src/repositories/product-type.ts +45 -4
- package/src/repositories/project.ts +57 -13
- package/src/repositories/quote/actions.ts +5 -28
- package/src/repositories/quote/index.ts +29 -6
- package/src/repositories/quote-request/actions.ts +5 -28
- package/src/repositories/quote-request/index.test.ts +3 -3
- package/src/repositories/quote-request/index.ts +31 -11
- package/src/repositories/quote-staged/actions.ts +5 -28
- package/src/repositories/quote-staged/index.ts +22 -8
- package/src/repositories/recurrence-policy/index.ts +6 -4
- package/src/repositories/recurring-order/actions.ts +7 -32
- package/src/repositories/recurring-order/index.ts +8 -6
- package/src/repositories/review.test.ts +147 -142
- package/src/repositories/review.ts +31 -37
- package/src/repositories/shipping-method/actions.ts +11 -28
- package/src/repositories/shipping-method/index.ts +26 -15
- package/src/repositories/shopping-list/actions.ts +21 -31
- package/src/repositories/shopping-list/index.ts +44 -22
- package/src/repositories/standalone-price.ts +6 -4
- package/src/repositories/state.ts +15 -9
- package/src/repositories/store.ts +21 -32
- package/src/repositories/subscription.test.ts +22 -22
- package/src/repositories/subscription.ts +8 -3
- package/src/repositories/tax-category/index.ts +8 -3
- package/src/repositories/type/actions.ts +21 -3
- package/src/repositories/type/index.ts +5 -3
- package/src/repositories/zone.test.ts +112 -77
- package/src/repositories/zone.ts +5 -3
- package/src/schemas/generated/associate-role.ts +13 -0
- package/src/schemas/generated/attribute-group.ts +12 -0
- package/src/schemas/generated/business-unit.ts +38 -0
- package/src/schemas/generated/cart-discount.ts +33 -0
- package/src/schemas/generated/cart.ts +61 -0
- package/src/schemas/generated/category.ts +25 -0
- package/src/schemas/generated/channel.ts +21 -0
- package/src/schemas/generated/common.ts +1372 -0
- package/src/schemas/generated/custom-object.ts +11 -0
- package/src/schemas/generated/customer-group.ts +11 -0
- package/src/schemas/generated/customer.ts +47 -0
- package/src/schemas/generated/discount-code.ts +25 -0
- package/src/schemas/generated/discount-group.ts +13 -0
- package/src/schemas/generated/extension.ts +15 -0
- package/src/schemas/generated/index.ts +42 -0
- package/src/schemas/generated/inventory-entry.ts +20 -0
- package/src/schemas/generated/my-quote-request.ts +10 -0
- package/src/schemas/generated/order-edit.ts +18 -0
- package/src/schemas/generated/order-from-cart.ts +25 -0
- package/src/schemas/generated/payment.ts +30 -0
- package/src/schemas/generated/product-discount.ts +20 -0
- package/src/schemas/generated/product-selection.ts +18 -0
- package/src/schemas/generated/product-tailoring.ts +26 -0
- package/src/schemas/generated/product-type.ts +12 -0
- package/src/schemas/generated/product.ts +37 -0
- package/src/schemas/generated/quote-request.ts +19 -0
- package/src/schemas/generated/quote.ts +18 -0
- package/src/schemas/generated/recurrence-policy.ts +15 -0
- package/src/schemas/generated/recurring-order.ts +19 -0
- package/src/schemas/generated/review.ts +24 -0
- package/src/schemas/generated/shipping-method.ts +24 -0
- package/src/schemas/generated/shopping-list.ts +28 -0
- package/src/schemas/generated/staged-quote.ts +18 -0
- package/src/schemas/generated/standalone-price.ts +32 -0
- package/src/schemas/generated/state.ts +20 -0
- package/src/schemas/generated/store.ts +23 -0
- package/src/schemas/generated/subscription.ts +20 -0
- package/src/schemas/generated/tax-category.ts +12 -0
- package/src/schemas/generated/type.ts +17 -0
- package/src/schemas/generated/zone.ts +12 -0
- package/src/schemas/update-request.ts +3 -5
- package/src/server.ts +32 -4
- package/src/services/abstract.ts +207 -101
- package/src/services/as-associate-cart.test.ts +28 -36
- package/src/services/as-associate-cart.ts +15 -12
- package/src/services/as-associate-order.test.ts +33 -40
- package/src/services/as-associate-order.ts +15 -12
- package/src/services/as-associate-quote-request.ts +15 -12
- package/src/services/as-associate-shopping-list.test.ts +25 -35
- package/src/services/as-associate-shopping-list.ts +15 -12
- package/src/services/as-associate.test.ts +21 -15
- package/src/services/as-associate.ts +23 -22
- package/src/services/associate-roles.test.ts +16 -22
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.test.ts +40 -44
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +227 -163
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.test.ts +253 -187
- package/src/services/cart-discount.ts +2 -2
- package/src/services/cart.test.ts +833 -832
- package/src/services/cart.ts +31 -12
- package/src/services/category.test.ts +208 -130
- package/src/services/category.ts +2 -2
- package/src/services/channel.test.ts +39 -44
- package/src/services/channel.ts +2 -2
- package/src/services/custom-object.test.ts +103 -79
- package/src/services/custom-object.ts +106 -38
- package/src/services/customer-group.test.ts +39 -44
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +357 -292
- package/src/services/customer.ts +70 -23
- package/src/services/discount-code.test.ts +57 -68
- package/src/services/discount-code.ts +2 -2
- package/src/services/discount-group.test.ts +111 -134
- package/src/services/discount-group.ts +2 -2
- package/src/services/draft-validation.test.ts +255 -0
- package/src/services/extension.test.ts +39 -44
- package/src/services/extension.ts +2 -2
- package/src/services/inventory-entry.test.ts +106 -87
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.test.ts +82 -112
- package/src/services/my-business-unit.ts +25 -19
- package/src/services/my-cart.test.ts +46 -41
- package/src/services/my-cart.ts +32 -28
- package/src/services/my-customer.test.ts +153 -88
- package/src/services/my-customer.ts +130 -61
- package/src/services/my-order.ts +15 -12
- package/src/services/my-payment.test.ts +30 -24
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.test.ts +332 -276
- package/src/services/order.ts +45 -27
- package/src/services/payment.test.ts +31 -29
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.test.ts +39 -46
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +176 -166
- package/src/services/product-projection.ts +31 -15
- package/src/services/product-selection.test.ts +17 -9
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.test.ts +80 -21
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +569 -534
- package/src/services/product.ts +14 -7
- package/src/services/project.test.ts +22 -12
- package/src/services/project.ts +28 -13
- package/src/services/quote-request.test.ts +36 -39
- 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 +114 -139
- package/src/services/recurrence-policy.ts +2 -2
- package/src/services/recurring-order.test.ts +149 -194
- package/src/services/recurring-order.ts +2 -2
- package/src/services/reviews.test.ts +127 -106
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.test.ts +96 -125
- package/src/services/shipping-method.ts +24 -12
- package/src/services/shopping-list.test.ts +183 -141
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.test.ts +60 -46
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.test.ts +20 -25
- package/src/services/state.ts +2 -2
- package/src/services/store.test.ts +26 -45
- package/src/services/store.ts +2 -2
- package/src/services/subscription.test.ts +39 -44
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.test.ts +33 -36
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.test.ts +45 -44
- package/src/services/type.ts +2 -2
- package/src/services/zone.test.ts +40 -44
- package/src/services/zone.ts +2 -2
- package/src/shipping.ts +41 -11
- package/src/storage/abstract.ts +248 -17
- package/src/storage/in-memory.ts +147 -290
- package/src/storage/sqlite.ts +429 -0
- package/src/storage/storage-map.ts +75 -0
- package/src/storage/storage.test-helpers.ts +97 -0
- package/src/storage/storage.test.ts +802 -0
- package/src/testing/associate-role.ts +28 -0
- package/src/testing/attribute-group.ts +27 -0
- package/src/testing/business-unit.ts +9 -8
- package/src/testing/cart-discount.ts +34 -0
- package/src/testing/cart.ts +20 -0
- package/src/testing/category.ts +25 -0
- package/src/testing/channel.ts +23 -0
- package/src/testing/custom-object.ts +27 -0
- package/src/testing/customer-group.ts +26 -0
- package/src/testing/customer.ts +36 -33
- package/src/testing/discount-code.ts +29 -0
- package/src/testing/discount-group.ts +27 -0
- package/src/testing/extension.ts +32 -0
- package/src/testing/index.ts +33 -0
- package/src/testing/inventory-entry.ts +26 -0
- package/src/testing/order.ts +27 -0
- package/src/testing/payment.ts +23 -0
- package/src/testing/product-discount.ts +33 -0
- package/src/testing/product-selection.ts +28 -0
- package/src/testing/product-type.ts +27 -0
- package/src/testing/product.ts +38 -0
- package/src/testing/quote-request.ts +29 -0
- package/src/testing/recurrence-policy.ts +33 -0
- package/src/testing/recurring-order.ts +32 -0
- package/src/testing/review.ts +24 -0
- package/src/testing/shipping-method.ts +31 -0
- package/src/testing/shopping-list.ts +25 -0
- package/src/testing/standalone-price.ts +31 -0
- package/src/testing/state.ts +21 -0
- package/src/testing/store.ts +26 -0
- package/src/testing/subscription.ts +38 -0
- package/src/testing/tax-category.ts +27 -0
- package/src/testing/type.ts +9 -6
- package/src/testing/zone.ts +22 -0
- package/src/validate.test.ts +122 -0
- package/src/validate.ts +78 -7
- package/src/.env +0 -0
|
@@ -1,44 +1,52 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ChannelReference,
|
|
2
3
|
InventoryEntry,
|
|
3
4
|
InventoryEntryDraft,
|
|
4
5
|
} from "@commercetools/platform-sdk";
|
|
5
6
|
import type { Config } from "#src/config.ts";
|
|
6
7
|
import { getBaseResourceProperties } from "#src/helpers.ts";
|
|
8
|
+
import { InventoryEntryDraftSchema } from "#src/schemas/generated/inventory-entry.ts";
|
|
7
9
|
import {
|
|
8
10
|
AbstractResourceRepository,
|
|
9
11
|
type RepositoryContext,
|
|
10
12
|
} from "../abstract.ts";
|
|
11
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
createCustomFields,
|
|
15
|
+
getReferenceFromResourceIdentifier,
|
|
16
|
+
} from "../helpers.ts";
|
|
12
17
|
import { InventoryEntryUpdateHandler } from "./actions.ts";
|
|
13
18
|
|
|
14
19
|
export class InventoryEntryRepository extends AbstractResourceRepository<"inventory-entry"> {
|
|
15
20
|
constructor(config: Config) {
|
|
16
21
|
super("inventory-entry", config);
|
|
17
22
|
this.actions = new InventoryEntryUpdateHandler(config.storage);
|
|
23
|
+
this.draftSchema = InventoryEntryDraftSchema;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
create(
|
|
26
|
+
async create(
|
|
21
27
|
context: RepositoryContext,
|
|
22
28
|
draft: InventoryEntryDraft,
|
|
23
|
-
): InventoryEntry {
|
|
29
|
+
): Promise<InventoryEntry> {
|
|
24
30
|
const resource: InventoryEntry = {
|
|
25
|
-
...getBaseResourceProperties(),
|
|
31
|
+
...getBaseResourceProperties(context.clientId),
|
|
26
32
|
sku: draft.sku,
|
|
27
33
|
quantityOnStock: draft.quantityOnStock,
|
|
28
34
|
availableQuantity: draft.quantityOnStock,
|
|
29
35
|
expectedDelivery: draft.expectedDelivery,
|
|
30
36
|
restockableInDays: draft.restockableInDays,
|
|
31
|
-
supplyChannel:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
supplyChannel: draft.supplyChannel
|
|
38
|
+
? await getReferenceFromResourceIdentifier<ChannelReference>(
|
|
39
|
+
draft.supplyChannel,
|
|
40
|
+
context.projectKey,
|
|
41
|
+
this._storage,
|
|
42
|
+
)
|
|
43
|
+
: undefined,
|
|
44
|
+
custom: await createCustomFields(
|
|
37
45
|
draft.custom,
|
|
38
46
|
context.projectKey,
|
|
39
47
|
this._storage,
|
|
40
48
|
),
|
|
41
49
|
};
|
|
42
|
-
return this.saveNew(context, resource);
|
|
50
|
+
return await this.saveNew(context, resource);
|
|
43
51
|
}
|
|
44
52
|
}
|
|
@@ -12,14 +12,14 @@ import type { RepositoryContext } from "./abstract.ts";
|
|
|
12
12
|
import { CustomerRepository } from "./customer/index.ts";
|
|
13
13
|
|
|
14
14
|
export class MyCustomerRepository extends CustomerRepository {
|
|
15
|
-
changePassword(
|
|
15
|
+
async changePassword(
|
|
16
16
|
context: RepositoryContext,
|
|
17
17
|
changePassword: MyCustomerChangePassword,
|
|
18
18
|
) {
|
|
19
19
|
const { currentPassword, newPassword } = changePassword;
|
|
20
20
|
const encodedPassword = hashPassword(currentPassword);
|
|
21
21
|
|
|
22
|
-
const result = this._storage.query(context.projectKey, "customer", {
|
|
22
|
+
const result = await this._storage.query(context.projectKey, "customer", {
|
|
23
23
|
where: [`password = "${encodedPassword}"`],
|
|
24
24
|
});
|
|
25
25
|
if (result.count === 0) {
|
|
@@ -41,11 +41,11 @@ export class MyCustomerRepository extends CustomerRepository {
|
|
|
41
41
|
customer.version += 1;
|
|
42
42
|
|
|
43
43
|
// Update storage
|
|
44
|
-
this._storage.add(context.projectKey, "customer", customer);
|
|
44
|
+
await this._storage.add(context.projectKey, "customer", customer);
|
|
45
45
|
return customer;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
confirmEmail(
|
|
48
|
+
async confirmEmail(
|
|
49
49
|
context: RepositoryContext,
|
|
50
50
|
resetPassword: MyCustomerEmailVerify,
|
|
51
51
|
) {
|
|
@@ -59,11 +59,11 @@ export class MyCustomerRepository extends CustomerRepository {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const customer = this._storage.get(
|
|
62
|
+
const customer = (await this._storage.get(
|
|
63
63
|
context.projectKey,
|
|
64
64
|
"customer",
|
|
65
65
|
customerId,
|
|
66
|
-
) as Writable<Customer> | undefined;
|
|
66
|
+
)) as Writable<Customer> | undefined;
|
|
67
67
|
|
|
68
68
|
if (!customer) {
|
|
69
69
|
throw new CommercetoolsError<ResourceNotFoundError>({
|
|
@@ -76,30 +76,31 @@ export class MyCustomerRepository extends CustomerRepository {
|
|
|
76
76
|
customer.version += 1;
|
|
77
77
|
|
|
78
78
|
// Update storage
|
|
79
|
-
this._storage.add(context.projectKey, "customer", customer);
|
|
79
|
+
await this._storage.add(context.projectKey, "customer", customer);
|
|
80
80
|
return customer;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
deleteMe(context: RepositoryContext): Customer | undefined {
|
|
83
|
+
async deleteMe(context: RepositoryContext): Promise<Customer | undefined> {
|
|
84
84
|
// grab the first customer you can find for now. In the future we should
|
|
85
85
|
// use the customer id from the scope of the token
|
|
86
|
-
const results = this._storage.query(
|
|
86
|
+
const results = await this._storage.query(
|
|
87
87
|
context.projectKey,
|
|
88
88
|
this.getTypeId(),
|
|
89
89
|
{},
|
|
90
90
|
);
|
|
91
91
|
|
|
92
92
|
if (results.count > 0) {
|
|
93
|
-
|
|
93
|
+
const deleted = await this.delete(context, results.results[0].id);
|
|
94
|
+
return deleted as Customer;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
getMe(context: RepositoryContext): Customer | undefined {
|
|
100
|
+
async getMe(context: RepositoryContext): Promise<Customer | undefined> {
|
|
100
101
|
// grab the first customer you can find for now. In the future we should
|
|
101
102
|
// use the customer id from the scope of the token
|
|
102
|
-
const results = this._storage.query(
|
|
103
|
+
const results = await this._storage.query(
|
|
103
104
|
context.projectKey,
|
|
104
105
|
this.getTypeId(),
|
|
105
106
|
{},
|
|
@@ -8,12 +8,15 @@ import type { RepositoryContext } from "./abstract.ts";
|
|
|
8
8
|
import { OrderRepository } from "./order/index.ts";
|
|
9
9
|
|
|
10
10
|
export class MyOrderRepository extends OrderRepository {
|
|
11
|
-
create(
|
|
11
|
+
async create(
|
|
12
|
+
context: RepositoryContext,
|
|
13
|
+
draft: MyOrderFromCartDraft,
|
|
14
|
+
): Promise<Order> {
|
|
12
15
|
assert(draft.id, "draft.id is missing");
|
|
13
16
|
const cartIdentifier = {
|
|
14
17
|
id: draft.id,
|
|
15
18
|
typeId: "cart",
|
|
16
19
|
} as CartReference;
|
|
17
|
-
return this.createFromCart(context, cartIdentifier);
|
|
20
|
+
return await this.createFromCart(context, cartIdentifier);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
CustomLineItemReturnItem,
|
|
3
3
|
Delivery,
|
|
4
4
|
GeneralError,
|
|
5
|
+
InvalidOperationError,
|
|
5
6
|
LineItemReturnItem,
|
|
6
7
|
Order,
|
|
7
8
|
OrderAddDeliveryAction,
|
|
@@ -28,6 +29,9 @@ import type {
|
|
|
28
29
|
OrderUpdateAction,
|
|
29
30
|
OrderUpdateSyncInfoAction,
|
|
30
31
|
Parcel,
|
|
32
|
+
ReferencedResourceNotFoundError,
|
|
33
|
+
RequiredFieldError,
|
|
34
|
+
ResourceNotFoundError,
|
|
31
35
|
ReturnInfo,
|
|
32
36
|
State,
|
|
33
37
|
Store,
|
|
@@ -44,17 +48,21 @@ export class OrderUpdateHandler
|
|
|
44
48
|
extends AbstractUpdateHandler
|
|
45
49
|
implements Partial<UpdateHandlerInterface<Order, OrderUpdateAction>>
|
|
46
50
|
{
|
|
47
|
-
addPayment(
|
|
51
|
+
async addPayment(
|
|
48
52
|
context: RepositoryContext,
|
|
49
53
|
resource: Writable<Order>,
|
|
50
54
|
{ payment }: OrderAddPaymentAction,
|
|
51
55
|
) {
|
|
52
|
-
const resolvedPayment = this._storage.getByResourceIdentifier(
|
|
56
|
+
const resolvedPayment = await this._storage.getByResourceIdentifier(
|
|
53
57
|
context.projectKey,
|
|
54
58
|
payment,
|
|
55
59
|
);
|
|
56
60
|
if (!resolvedPayment) {
|
|
57
|
-
throw new
|
|
61
|
+
throw new CommercetoolsError<ReferencedResourceNotFoundError>({
|
|
62
|
+
code: "ReferencedResourceNotFound",
|
|
63
|
+
message: `Payment ${payment.id} not found`,
|
|
64
|
+
typeId: "payment",
|
|
65
|
+
});
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
if (!resource.paymentInfo) {
|
|
@@ -69,7 +77,7 @@ export class OrderUpdateHandler
|
|
|
69
77
|
});
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
addReturnInfo(
|
|
80
|
+
async addReturnInfo(
|
|
73
81
|
context: RepositoryContext,
|
|
74
82
|
resource: Writable<Order>,
|
|
75
83
|
info: OrderAddReturnInfoAction,
|
|
@@ -78,15 +86,15 @@ export class OrderUpdateHandler
|
|
|
78
86
|
resource.returnInfo = [];
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
const
|
|
82
|
-
|
|
89
|
+
const items = await Promise.all(
|
|
90
|
+
info.items.map(async (item) => {
|
|
83
91
|
const common = {
|
|
84
92
|
...getBaseResourceProperties(),
|
|
85
93
|
quantity: item.quantity,
|
|
86
94
|
paymentState: "Initial",
|
|
87
95
|
shipmentState: item.shipmentState ?? "Advised",
|
|
88
96
|
comment: item.comment,
|
|
89
|
-
custom: createCustomFields(
|
|
97
|
+
custom: await createCustomFields(
|
|
90
98
|
item.custom,
|
|
91
99
|
context.projectKey,
|
|
92
100
|
this._storage,
|
|
@@ -105,6 +113,10 @@ export class OrderUpdateHandler
|
|
|
105
113
|
lineItemId: item.customLineItemId || item.lineItemId,
|
|
106
114
|
} as LineItemReturnItem;
|
|
107
115
|
}),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const resolved: ReturnInfo = {
|
|
119
|
+
items,
|
|
108
120
|
returnTrackingId: info.returnTrackingId,
|
|
109
121
|
returnDate: info.returnDate,
|
|
110
122
|
};
|
|
@@ -169,61 +181,52 @@ export class OrderUpdateHandler
|
|
|
169
181
|
resource: Order,
|
|
170
182
|
{ name, value }: OrderSetCustomFieldAction,
|
|
171
183
|
) {
|
|
172
|
-
|
|
173
|
-
throw new Error("Resource has no custom field");
|
|
174
|
-
}
|
|
175
|
-
resource.custom.fields[name] = value;
|
|
184
|
+
this._setCustomFieldValues(resource, { name, value });
|
|
176
185
|
}
|
|
177
186
|
|
|
178
|
-
setCustomType(
|
|
187
|
+
async setCustomType(
|
|
179
188
|
context: RepositoryContext,
|
|
180
189
|
resource: Writable<Order>,
|
|
181
190
|
{ type, fields }: OrderSetCustomTypeAction,
|
|
182
191
|
) {
|
|
183
|
-
|
|
184
|
-
resource.custom = undefined;
|
|
185
|
-
} else {
|
|
186
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
187
|
-
context.projectKey,
|
|
188
|
-
type,
|
|
189
|
-
);
|
|
190
|
-
if (!resolvedType) {
|
|
191
|
-
throw new Error(`Type ${type} not found`);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
resource.custom = {
|
|
195
|
-
type: {
|
|
196
|
-
typeId: "type",
|
|
197
|
-
id: resolvedType.id,
|
|
198
|
-
},
|
|
199
|
-
fields: fields || {},
|
|
200
|
-
};
|
|
201
|
-
}
|
|
192
|
+
await this._setCustomType(context, resource, { type, fields });
|
|
202
193
|
}
|
|
203
194
|
|
|
204
|
-
addDelivery(
|
|
195
|
+
async addDelivery(
|
|
205
196
|
context: RepositoryContext,
|
|
206
197
|
resource: Writable<Order>,
|
|
207
198
|
{ action, items, ...deliveryDraft }: OrderAddDeliveryAction,
|
|
208
199
|
) {
|
|
209
200
|
if (!resource.shippingInfo) {
|
|
210
|
-
throw new
|
|
201
|
+
throw new CommercetoolsError<InvalidOperationError>({
|
|
202
|
+
code: "InvalidOperation",
|
|
203
|
+
message: "Resource has no shipping info",
|
|
204
|
+
});
|
|
211
205
|
}
|
|
212
206
|
|
|
213
207
|
if (!items) {
|
|
214
|
-
throw new
|
|
208
|
+
throw new CommercetoolsError<RequiredFieldError>({
|
|
209
|
+
code: "RequiredField",
|
|
210
|
+
message: "Delivery items are required",
|
|
211
|
+
field: "items",
|
|
212
|
+
});
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
if (!resource.shippingInfo.deliveries) {
|
|
218
216
|
resource.shippingInfo.deliveries = [];
|
|
219
217
|
}
|
|
220
218
|
|
|
221
|
-
const parcels: Parcel[] =
|
|
222
|
-
deliveryDraft.parcels?.map((p) => ({
|
|
219
|
+
const parcels: Parcel[] = await Promise.all(
|
|
220
|
+
deliveryDraft.parcels?.map(async (p) => ({
|
|
223
221
|
...getBaseResourceProperties(),
|
|
224
222
|
...p,
|
|
225
|
-
custom: createCustomFields(
|
|
226
|
-
|
|
223
|
+
custom: await createCustomFields(
|
|
224
|
+
p.custom,
|
|
225
|
+
context.projectKey,
|
|
226
|
+
this._storage,
|
|
227
|
+
),
|
|
228
|
+
})) ?? [],
|
|
229
|
+
);
|
|
227
230
|
|
|
228
231
|
const delivery: Delivery = {
|
|
229
232
|
...getBaseResourceProperties(),
|
|
@@ -235,7 +238,7 @@ export class OrderUpdateHandler
|
|
|
235
238
|
context.projectKey,
|
|
236
239
|
this._storage,
|
|
237
240
|
),
|
|
238
|
-
custom: createCustomFields(
|
|
241
|
+
custom: await createCustomFields(
|
|
239
242
|
deliveryDraft.custom,
|
|
240
243
|
context.projectKey,
|
|
241
244
|
this._storage,
|
|
@@ -251,7 +254,10 @@ export class OrderUpdateHandler
|
|
|
251
254
|
{ deliveryId, name, value }: OrderSetDeliveryCustomFieldAction,
|
|
252
255
|
) {
|
|
253
256
|
if (!resource.shippingInfo) {
|
|
254
|
-
throw new
|
|
257
|
+
throw new CommercetoolsError<InvalidOperationError>({
|
|
258
|
+
code: "InvalidOperation",
|
|
259
|
+
message: "Resource has no shipping info",
|
|
260
|
+
});
|
|
255
261
|
}
|
|
256
262
|
|
|
257
263
|
for (const delivery of resource.shippingInfo.deliveries || []) {
|
|
@@ -283,13 +289,16 @@ export class OrderUpdateHandler
|
|
|
283
289
|
}
|
|
284
290
|
|
|
285
291
|
if (!lineItem.custom) {
|
|
286
|
-
throw new
|
|
292
|
+
throw new CommercetoolsError<InvalidOperationError>({
|
|
293
|
+
code: "InvalidOperation",
|
|
294
|
+
message: "Resource has no custom field",
|
|
295
|
+
});
|
|
287
296
|
}
|
|
288
297
|
|
|
289
298
|
lineItem.custom.fields[name] = value;
|
|
290
299
|
}
|
|
291
300
|
|
|
292
|
-
setLineItemCustomType(
|
|
301
|
+
async setLineItemCustomType(
|
|
293
302
|
context: RepositoryContext,
|
|
294
303
|
resource: Writable<Order>,
|
|
295
304
|
{ lineItemId, lineItemKey, type, fields }: OrderSetLineItemCustomTypeAction,
|
|
@@ -313,12 +322,16 @@ export class OrderUpdateHandler
|
|
|
313
322
|
if (!type) {
|
|
314
323
|
lineItem.custom = undefined;
|
|
315
324
|
} else {
|
|
316
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
325
|
+
const resolvedType = await this._storage.getByResourceIdentifier(
|
|
317
326
|
context.projectKey,
|
|
318
327
|
type,
|
|
319
328
|
);
|
|
320
329
|
if (!resolvedType) {
|
|
321
|
-
throw new
|
|
330
|
+
throw new CommercetoolsError<ReferencedResourceNotFoundError>({
|
|
331
|
+
code: "ReferencedResourceNotFound",
|
|
332
|
+
message: `Type ${type} not found`,
|
|
333
|
+
typeId: "type",
|
|
334
|
+
});
|
|
322
335
|
}
|
|
323
336
|
|
|
324
337
|
lineItem.custom = {
|
|
@@ -353,7 +366,10 @@ export class OrderUpdateHandler
|
|
|
353
366
|
{ parcelId, name, value }: OrderSetParcelCustomFieldAction,
|
|
354
367
|
) {
|
|
355
368
|
if (!resource.shippingInfo) {
|
|
356
|
-
throw new
|
|
369
|
+
throw new CommercetoolsError<InvalidOperationError>({
|
|
370
|
+
code: "InvalidOperation",
|
|
371
|
+
message: "Resource has no shipping info",
|
|
372
|
+
});
|
|
357
373
|
}
|
|
358
374
|
|
|
359
375
|
for (const delivery of resource.shippingInfo.deliveries || []) {
|
|
@@ -385,18 +401,22 @@ export class OrderUpdateHandler
|
|
|
385
401
|
);
|
|
386
402
|
}
|
|
387
403
|
|
|
388
|
-
setStore(
|
|
404
|
+
async setStore(
|
|
389
405
|
context: RepositoryContext,
|
|
390
406
|
resource: Writable<Order>,
|
|
391
407
|
{ store }: OrderSetStoreAction,
|
|
392
408
|
) {
|
|
393
409
|
if (!store) return;
|
|
394
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
410
|
+
const resolvedType = await this._storage.getByResourceIdentifier(
|
|
395
411
|
context.projectKey,
|
|
396
412
|
store,
|
|
397
413
|
);
|
|
398
414
|
if (!resolvedType) {
|
|
399
|
-
throw new
|
|
415
|
+
throw new CommercetoolsError<ReferencedResourceNotFoundError>({
|
|
416
|
+
code: "ReferencedResourceNotFound",
|
|
417
|
+
message: `No store found with key=${store.key}`,
|
|
418
|
+
typeId: "store",
|
|
419
|
+
});
|
|
400
420
|
}
|
|
401
421
|
|
|
402
422
|
const storeReference = resolvedType as Store;
|
|
@@ -406,19 +426,23 @@ export class OrderUpdateHandler
|
|
|
406
426
|
};
|
|
407
427
|
}
|
|
408
428
|
|
|
409
|
-
transitionState(
|
|
429
|
+
async transitionState(
|
|
410
430
|
context: RepositoryContext,
|
|
411
431
|
resource: Writable<Order>,
|
|
412
432
|
{ state }: OrderTransitionStateAction,
|
|
413
433
|
) {
|
|
414
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
434
|
+
const resolvedType = (await this._storage.getByResourceIdentifier(
|
|
415
435
|
context.projectKey,
|
|
416
436
|
state,
|
|
417
|
-
) as State | null;
|
|
437
|
+
)) as State | null;
|
|
418
438
|
|
|
419
439
|
if (!resolvedType) {
|
|
420
|
-
throw new
|
|
421
|
-
|
|
440
|
+
throw new CommercetoolsError<ResourceNotFoundError>(
|
|
441
|
+
{
|
|
442
|
+
code: "ResourceNotFound",
|
|
443
|
+
message: `No state found with key=${state.key} or id=${state.key}`,
|
|
444
|
+
},
|
|
445
|
+
404,
|
|
422
446
|
);
|
|
423
447
|
}
|
|
424
448
|
|
|
@@ -429,18 +453,22 @@ export class OrderUpdateHandler
|
|
|
429
453
|
};
|
|
430
454
|
}
|
|
431
455
|
|
|
432
|
-
updateSyncInfo(
|
|
456
|
+
async updateSyncInfo(
|
|
433
457
|
context: RepositoryContext,
|
|
434
458
|
resource: Writable<Order>,
|
|
435
459
|
{ channel, externalId, syncedAt }: OrderUpdateSyncInfoAction,
|
|
436
460
|
) {
|
|
437
461
|
if (!channel) return;
|
|
438
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
462
|
+
const resolvedType = await this._storage.getByResourceIdentifier(
|
|
439
463
|
context.projectKey,
|
|
440
464
|
channel,
|
|
441
465
|
);
|
|
442
466
|
if (!resolvedType) {
|
|
443
|
-
throw new
|
|
467
|
+
throw new CommercetoolsError<ReferencedResourceNotFoundError>({
|
|
468
|
+
code: "ReferencedResourceNotFound",
|
|
469
|
+
message: `Channel ${channel} not found`,
|
|
470
|
+
typeId: "channel",
|
|
471
|
+
});
|
|
444
472
|
}
|
|
445
473
|
|
|
446
474
|
const syncData: SyncInfo = {
|