@unchainedshop/core 4.8.29 → 5.0.0-alpha.10
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 +92 -546
- package/lib/bulk-exporter/createBulkExporter.d.ts +2 -2
- package/lib/bulk-exporter/createBulkExporter.js +1 -1
- package/lib/bulk-exporter/handlers/exportAssortmentsHandler.d.ts +19 -19
- package/lib/bulk-exporter/handlers/exportAssortmentsHandler.js +9 -9
- package/lib/bulk-exporter/handlers/exportFiltersHandler.d.ts +11 -11
- package/lib/bulk-exporter/handlers/exportFiltersHandler.js +5 -5
- package/lib/bulk-exporter/handlers/exportProductsHandler.d.ts +19 -19
- package/lib/bulk-exporter/handlers/exportProductsHandler.js +11 -11
- package/lib/bulk-exporter/handlers/exportUsersHandler.d.ts +17 -17
- package/lib/bulk-exporter/handlers/exportUsersHandler.js +8 -8
- package/lib/bulk-importer/createBulkImporter.d.ts +1 -1
- package/lib/bulk-importer/createBulkImporter.js +6 -6
- package/lib/bulk-importer/handlers/product/create.d.ts +135 -32
- package/lib/bulk-importer/handlers/product/create.js +33 -16
- package/lib/bulk-importer/handlers/product/update.d.ts +63 -33
- package/lib/bulk-importer/handlers/product/update.js +5 -48
- package/lib/core-index.d.ts +4 -2
- package/lib/core-index.js +5 -17
- package/lib/directors/BaseDiscountAdapter.d.ts +3 -0
- package/lib/directors/BaseDiscountDirector.d.ts +2 -2
- package/lib/directors/BaseDiscountDirector.js +12 -14
- package/lib/directors/BasePricingDirector.d.ts +2 -2
- package/lib/directors/BasePricingDirector.js +4 -7
- package/lib/directors/BaseWorker.js +3 -2
- package/lib/directors/DeliveryAdapter.js +1 -0
- package/lib/directors/DeliveryDirector.d.ts +1 -1
- package/lib/directors/DeliveryDirector.js +4 -5
- package/lib/directors/DeliveryPricingAdapter.d.ts +2 -1
- package/lib/directors/DeliveryPricingAdapter.js +2 -1
- package/lib/directors/DeliveryPricingDirector.d.ts +1 -1
- package/lib/directors/DeliveryPricingDirector.js +4 -3
- package/lib/directors/DeliveryPricingSheet.d.ts +1 -1
- package/lib/directors/DeliveryPricingSheet.js +1 -1
- package/lib/directors/EnrollmentAdapter.js +1 -1
- package/lib/directors/EnrollmentDirector.d.ts +1 -1
- package/lib/directors/EnrollmentDirector.js +5 -7
- package/lib/directors/FileDirector.d.ts +4 -4
- package/lib/directors/FileDirector.js +2 -13
- package/lib/directors/FilterAdapter.js +1 -0
- package/lib/directors/FilterDirector.d.ts +1 -1
- package/lib/directors/FilterDirector.js +6 -8
- package/lib/directors/OrderDiscountAdapter.d.ts +3 -2
- package/lib/directors/OrderDiscountAdapter.js +5 -2
- package/lib/directors/OrderDiscountDirector.js +2 -1
- package/lib/directors/OrderPricingAdapter.d.ts +2 -1
- package/lib/directors/OrderPricingAdapter.js +3 -1
- package/lib/directors/OrderPricingDirector.d.ts +4 -1
- package/lib/directors/OrderPricingDirector.js +4 -2
- package/lib/directors/OrderPricingSheet.d.ts +2 -1
- package/lib/directors/OrderPricingSheet.js +18 -18
- package/lib/directors/PaymentAdapter.js +1 -0
- package/lib/directors/PaymentDirector.d.ts +1 -1
- package/lib/directors/PaymentDirector.js +4 -5
- package/lib/directors/PaymentPricingAdapter.d.ts +2 -1
- package/lib/directors/PaymentPricingAdapter.js +2 -1
- package/lib/directors/PaymentPricingDirector.d.ts +2 -1
- package/lib/directors/PaymentPricingDirector.js +3 -2
- package/lib/directors/PaymentPricingSheet.d.ts +2 -1
- package/lib/directors/PaymentPricingSheet.js +2 -1
- package/lib/directors/ProductDiscountAdapter.d.ts +3 -2
- package/lib/directors/ProductDiscountAdapter.js +5 -2
- package/lib/directors/ProductDiscountDirector.d.ts +1 -1
- package/lib/directors/ProductDiscountDirector.js +3 -2
- package/lib/directors/ProductPricingAdapter.d.ts +2 -1
- package/lib/directors/ProductPricingAdapter.js +3 -1
- package/lib/directors/ProductPricingDirector.d.ts +3 -1
- package/lib/directors/ProductPricingDirector.js +4 -2
- package/lib/directors/ProductPricingSheet.d.ts +1 -1
- package/lib/directors/ProductPricingSheet.js +1 -1
- package/lib/directors/QuotationAdapter.js +1 -0
- package/lib/directors/QuotationDirector.d.ts +1 -1
- package/lib/directors/QuotationDirector.js +4 -7
- package/lib/directors/WarehousingAdapter.js +1 -0
- package/lib/directors/WarehousingDirector.d.ts +1 -1
- package/lib/directors/WarehousingDirector.js +19 -27
- package/lib/directors/WorkerAdapter.js +1 -0
- package/lib/directors/WorkerDirector.d.ts +2 -2
- package/lib/directors/WorkerDirector.js +3 -22
- package/lib/directors/index.d.ts +2 -0
- package/lib/directors/index.js +2 -0
- package/lib/directors/registryDirector.d.ts +2 -0
- package/lib/directors/registryDirector.js +6 -0
- package/lib/factory/index.d.ts +12 -1
- package/lib/factory/index.js +12 -1
- package/lib/factory/registerAssortmentSearchFilter.d.ts +4 -2
- package/lib/factory/registerAssortmentSearchFilter.js +18 -6
- package/lib/factory/registerInvoicePayment.d.ts +2 -2
- package/lib/factory/registerInvoicePayment.js +12 -3
- package/lib/factory/registerPhysicalWarehousing.d.ts +2 -2
- package/lib/factory/registerPhysicalWarehousing.js +12 -3
- package/lib/factory/registerPickUpDelivery.d.ts +2 -2
- package/lib/factory/registerPickUpDelivery.js +12 -3
- package/lib/factory/registerProductDiscoverabilityFilter.d.ts +4 -2
- package/lib/factory/registerProductDiscoverabilityFilter.js +18 -6
- package/lib/factory/registerProductSearchFilter.d.ts +4 -2
- package/lib/factory/registerProductSearchFilter.js +16 -6
- package/lib/factory/registerShippingDelivery.d.ts +2 -2
- package/lib/factory/registerShippingDelivery.js +12 -3
- package/lib/factory/registerVirtualWarehousing.d.ts +2 -2
- package/lib/factory/registerVirtualWarehousing.js +13 -4
- package/lib/factory/registerWorker.d.ts +2 -1
- package/lib/factory/registerWorker.js +13 -4
- package/lib/plugins/PluginRegistry.d.ts +1 -0
- package/lib/plugins/PluginRegistry.js +8 -1
- package/lib/services/checkoutOrder.js +4 -0
- package/lib/services/createDownloadStream.js +1 -1
- package/lib/services/createFileDownloadURL.js +2 -1
- package/lib/services/createSignedURL.js +2 -1
- package/lib/services/index.d.ts +14 -1
- package/lib/services/index.js +14 -1
- package/lib/services/initCartProviders.js +1 -0
- package/lib/services/linkFileService.js +1 -1
- package/lib/services/removeFiles.js +1 -1
- package/lib/services/reserveOrderDiscountsForCheckout.d.ts +5 -0
- package/lib/services/reserveOrderDiscountsForCheckout.js +34 -0
- package/lib/services/simulateProductDispatching.d.ts +3 -1
- package/lib/services/simulateProductDispatching.js +3 -3
- package/lib/services/simulateProductInventory.d.ts +3 -1
- package/lib/services/simulateProductInventory.js +3 -3
- package/lib/services/supportedDeliveryProviders.js +9 -0
- package/lib/services/supportedPaymentProviders.js +9 -0
- package/lib/services/supportedWarehousingProviders.js +9 -0
- package/lib/services/uploadFileFromStream.js +2 -1
- package/lib/services/uploadFileFromURL.js +2 -1
- package/package.json +26 -24
|
@@ -3,17 +3,36 @@ import upsertVariations, { ProductVariationSchema } from "./upsertVariations.js"
|
|
|
3
3
|
import upsertMedia from "./upsertMedia.js";
|
|
4
4
|
import { MediaSchema } from "../assortment/upsertMedia.js";
|
|
5
5
|
import convertTagsToLowerCase from "../utils/convertTagsToLowerCase.js";
|
|
6
|
-
import { ProductStatus, ProductType } from '@unchainedshop/core-products';
|
|
7
|
-
export const
|
|
8
|
-
|
|
6
|
+
import { ProductContractStandard, ProductStatus, ProductType, } from '@unchainedshop/core-products';
|
|
7
|
+
export const DateLikeSchema = z.union([
|
|
8
|
+
z.date(),
|
|
9
|
+
z.string().check(z.refine((value) => !Number.isNaN(new Date(value).getTime()), 'Invalid date')),
|
|
10
|
+
]);
|
|
11
|
+
export const ProductTokenizationSchema = z.object({
|
|
12
|
+
contractAddress: z.optional(z.string()),
|
|
13
|
+
contractStandard: z.optional(z.enum(ProductContractStandard)),
|
|
14
|
+
tokenId: z.optional(z.string()),
|
|
15
|
+
supply: z.optional(z.int().check(z.gte(0))),
|
|
16
|
+
ercMetadataProperties: z.optional(z.record(z.string(), z.any())),
|
|
17
|
+
});
|
|
18
|
+
export const ProductContentSchema = z.record(z.string(), z.object({
|
|
19
|
+
title: z.optional(z.string()),
|
|
20
|
+
subtitle: z.optional(z.string()),
|
|
21
|
+
slug: z.optional(z.string()),
|
|
22
|
+
description: z.optional(z.string()),
|
|
23
|
+
brand: z.optional(z.string()),
|
|
24
|
+
vendor: z.optional(z.string()),
|
|
25
|
+
labels: z.optional(z.array(z.string())),
|
|
26
|
+
}));
|
|
27
|
+
export const ProductSpecificationFields = {
|
|
9
28
|
sequence: z.optional(z.number()),
|
|
10
29
|
status: z.nullish(z.enum(ProductStatus)),
|
|
11
|
-
published: z.nullish(
|
|
30
|
+
published: z.nullish(DateLikeSchema),
|
|
12
31
|
tags: z.optional(z.array(z.string())),
|
|
13
32
|
commerce: z.optional(z.object({
|
|
14
33
|
pricing: z.array(z.object({
|
|
15
34
|
amount: z.number(),
|
|
16
|
-
|
|
35
|
+
minQuantity: z.optional(z.number().check(z.gte(0))),
|
|
17
36
|
isTaxable: z.optional(z.boolean()),
|
|
18
37
|
isNetPrice: z.optional(z.boolean()),
|
|
19
38
|
currencyCode: z.string().check(z.minLength(1, 'currencyCode is required')),
|
|
@@ -30,6 +49,7 @@ export const ProductCreateSpecificationSchema = z.object({
|
|
|
30
49
|
lengthInMillimeters: z.optional(z.number()),
|
|
31
50
|
widthInMillimeters: z.optional(z.number()),
|
|
32
51
|
})),
|
|
52
|
+
tokenization: z.optional(ProductTokenizationSchema),
|
|
33
53
|
bundleItems: z.optional(z.array(z.object({
|
|
34
54
|
productId: z.string(),
|
|
35
55
|
quantity: z.number(),
|
|
@@ -39,19 +59,15 @@ export const ProductCreateSpecificationSchema = z.object({
|
|
|
39
59
|
})),
|
|
40
60
|
}))),
|
|
41
61
|
meta: z.optional(z.record(z.any(), z.any())),
|
|
42
|
-
content: z.record(z.string(), z.object({
|
|
43
|
-
title: z.optional(z.string()),
|
|
44
|
-
subtitle: z.optional(z.string()),
|
|
45
|
-
slug: z.optional(z.string()),
|
|
46
|
-
description: z.optional(z.string()),
|
|
47
|
-
brand: z.optional(z.string()),
|
|
48
|
-
vendor: z.optional(z.string()),
|
|
49
|
-
labels: z.optional(z.array(z.string())),
|
|
50
|
-
})),
|
|
51
62
|
variationResolvers: z.optional(z.array(z.object({
|
|
52
63
|
vector: z.record(z.string(), z.any()),
|
|
53
64
|
productId: z.string(),
|
|
54
65
|
}))),
|
|
66
|
+
};
|
|
67
|
+
export const ProductCreateSpecificationSchema = z.object({
|
|
68
|
+
...ProductSpecificationFields,
|
|
69
|
+
type: z.enum(ProductType),
|
|
70
|
+
content: ProductContentSchema,
|
|
55
71
|
});
|
|
56
72
|
export const ProductCreatePayloadSchema = z.object({
|
|
57
73
|
_id: z.string(),
|
|
@@ -61,18 +77,19 @@ export const ProductCreatePayloadSchema = z.object({
|
|
|
61
77
|
});
|
|
62
78
|
const normalizeStatus = (status) => (status === ProductStatus.DRAFT ? null : status);
|
|
63
79
|
const transformSpecification = (specification) => {
|
|
64
|
-
const { variationResolvers: assignments, content, supply, warehousing, sequence, ...productData } = specification;
|
|
80
|
+
const { variationResolvers: assignments, content, supply, warehousing, sequence, tokenization, ...productData } = specification;
|
|
65
81
|
const tags = productData?.tags ? convertTagsToLowerCase(productData.tags) : [];
|
|
66
82
|
const proxy = assignments ? { assignments } : undefined;
|
|
67
83
|
return {
|
|
68
84
|
...productData,
|
|
85
|
+
...(sequence != null && { sequence }),
|
|
69
86
|
published: productData.published ? new Date(productData.published) : undefined,
|
|
70
87
|
...(productData.status !== undefined && { status: normalizeStatus(productData.status) }),
|
|
88
|
+
...(tokenization !== undefined && { tokenization: tokenization }),
|
|
71
89
|
tags,
|
|
72
90
|
warehousing,
|
|
73
91
|
supply,
|
|
74
92
|
proxy,
|
|
75
|
-
...(sequence != null && { sequence }),
|
|
76
93
|
};
|
|
77
94
|
};
|
|
78
95
|
export default async function createProduct(payload, { logger, createShouldUpsertIfIDExists }, unchainedAPI) {
|
|
@@ -3,18 +3,27 @@ import type { Modules } from '../../../modules.ts';
|
|
|
3
3
|
import type { Services } from '../../../services/index.ts';
|
|
4
4
|
export declare const ProductUpdateSpecificationSchema: z.ZodMiniObject<{
|
|
5
5
|
type: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
6
|
+
content: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
7
|
+
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
8
|
+
subtitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
9
|
+
slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
10
|
+
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
11
|
+
brand: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
12
|
+
vendor: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
13
|
+
labels: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
14
|
+
}, z.core.$strip>>>;
|
|
6
15
|
sequence: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
7
16
|
status: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniEnum<{
|
|
8
17
|
readonly DRAFT: "DRAFT";
|
|
9
18
|
readonly ACTIVE: "ACTIVE";
|
|
10
19
|
readonly DELETED: "DELETED";
|
|
11
20
|
}>>>;
|
|
12
|
-
published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
|
|
21
|
+
published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniUnion<readonly [z.ZodMiniDate<Date>, z.ZodMiniString<string>]>>>;
|
|
13
22
|
tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
14
23
|
commerce: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
15
24
|
pricing: z.ZodMiniArray<z.ZodMiniObject<{
|
|
16
25
|
amount: z.ZodMiniNumber<number>;
|
|
17
|
-
|
|
26
|
+
minQuantity: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
18
27
|
isTaxable: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
19
28
|
isNetPrice: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
20
29
|
currencyCode: z.ZodMiniString<string>;
|
|
@@ -31,6 +40,16 @@ export declare const ProductUpdateSpecificationSchema: z.ZodMiniObject<{
|
|
|
31
40
|
lengthInMillimeters: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
32
41
|
widthInMillimeters: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
33
42
|
}, z.core.$strip>>;
|
|
43
|
+
tokenization: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
44
|
+
contractAddress: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
45
|
+
contractStandard: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
46
|
+
readonly ERC721: "ERC721";
|
|
47
|
+
readonly ERC1155: "ERC1155";
|
|
48
|
+
}>>;
|
|
49
|
+
tokenId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
50
|
+
supply: z.ZodMiniOptional<z.ZodMiniInt>;
|
|
51
|
+
ercMetadataProperties: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>>;
|
|
52
|
+
}, z.core.$strip>>;
|
|
34
53
|
bundleItems: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
35
54
|
productId: z.ZodMiniString<string>;
|
|
36
55
|
quantity: z.ZodMiniNumber<number>;
|
|
@@ -40,15 +59,6 @@ export declare const ProductUpdateSpecificationSchema: z.ZodMiniObject<{
|
|
|
40
59
|
}, z.core.$strip>>;
|
|
41
60
|
}, z.core.$strip>>>;
|
|
42
61
|
meta: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniAny, z.ZodMiniAny>>;
|
|
43
|
-
content: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
44
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
45
|
-
subtitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
46
|
-
slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
47
|
-
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
48
|
-
brand: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
49
|
-
vendor: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
50
|
-
labels: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
51
|
-
}, z.core.$strip>>>;
|
|
52
62
|
variationResolvers: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
53
63
|
vector: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>;
|
|
54
64
|
productId: z.ZodMiniString<string>;
|
|
@@ -58,18 +68,27 @@ export declare const ProductUpdatePayloadSchema: z.ZodMiniObject<{
|
|
|
58
68
|
_id: z.ZodMiniString<string>;
|
|
59
69
|
specification: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
60
70
|
type: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
71
|
+
content: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
72
|
+
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
73
|
+
subtitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
74
|
+
slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
75
|
+
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
76
|
+
brand: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
77
|
+
vendor: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
78
|
+
labels: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
79
|
+
}, z.core.$strip>>>;
|
|
61
80
|
sequence: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
62
81
|
status: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniEnum<{
|
|
63
82
|
readonly DRAFT: "DRAFT";
|
|
64
83
|
readonly ACTIVE: "ACTIVE";
|
|
65
84
|
readonly DELETED: "DELETED";
|
|
66
85
|
}>>>;
|
|
67
|
-
published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
|
|
86
|
+
published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniUnion<readonly [z.ZodMiniDate<Date>, z.ZodMiniString<string>]>>>;
|
|
68
87
|
tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
69
88
|
commerce: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
70
89
|
pricing: z.ZodMiniArray<z.ZodMiniObject<{
|
|
71
90
|
amount: z.ZodMiniNumber<number>;
|
|
72
|
-
|
|
91
|
+
minQuantity: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
73
92
|
isTaxable: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
74
93
|
isNetPrice: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
75
94
|
currencyCode: z.ZodMiniString<string>;
|
|
@@ -86,6 +105,16 @@ export declare const ProductUpdatePayloadSchema: z.ZodMiniObject<{
|
|
|
86
105
|
lengthInMillimeters: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
87
106
|
widthInMillimeters: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
88
107
|
}, z.core.$strip>>;
|
|
108
|
+
tokenization: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
109
|
+
contractAddress: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
110
|
+
contractStandard: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
111
|
+
readonly ERC721: "ERC721";
|
|
112
|
+
readonly ERC1155: "ERC1155";
|
|
113
|
+
}>>;
|
|
114
|
+
tokenId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
115
|
+
supply: z.ZodMiniOptional<z.ZodMiniInt>;
|
|
116
|
+
ercMetadataProperties: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>>;
|
|
117
|
+
}, z.core.$strip>>;
|
|
89
118
|
bundleItems: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
90
119
|
productId: z.ZodMiniString<string>;
|
|
91
120
|
quantity: z.ZodMiniNumber<number>;
|
|
@@ -95,15 +124,6 @@ export declare const ProductUpdatePayloadSchema: z.ZodMiniObject<{
|
|
|
95
124
|
}, z.core.$strip>>;
|
|
96
125
|
}, z.core.$strip>>>;
|
|
97
126
|
meta: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniAny, z.ZodMiniAny>>;
|
|
98
|
-
content: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
99
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
100
|
-
subtitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
101
|
-
slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
102
|
-
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
103
|
-
brand: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
104
|
-
vendor: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
105
|
-
labels: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
106
|
-
}, z.core.$strip>>>;
|
|
107
127
|
variationResolvers: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
108
128
|
vector: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>;
|
|
109
129
|
productId: z.ZodMiniString<string>;
|
|
@@ -159,18 +179,27 @@ declare namespace updateProduct {
|
|
|
159
179
|
_id: z.ZodMiniString<string>;
|
|
160
180
|
specification: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
161
181
|
type: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
182
|
+
content: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
183
|
+
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
184
|
+
subtitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
185
|
+
slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
186
|
+
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
187
|
+
brand: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
188
|
+
vendor: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
189
|
+
labels: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
190
|
+
}, z.core.$strip>>>;
|
|
162
191
|
sequence: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
163
192
|
status: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniEnum<{
|
|
164
193
|
readonly DRAFT: "DRAFT";
|
|
165
194
|
readonly ACTIVE: "ACTIVE";
|
|
166
195
|
readonly DELETED: "DELETED";
|
|
167
196
|
}>>>;
|
|
168
|
-
published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniString<string>>>;
|
|
197
|
+
published: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniUnion<readonly [z.ZodMiniDate<Date>, z.ZodMiniString<string>]>>>;
|
|
169
198
|
tags: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
170
199
|
commerce: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
171
200
|
pricing: z.ZodMiniArray<z.ZodMiniObject<{
|
|
172
201
|
amount: z.ZodMiniNumber<number>;
|
|
173
|
-
|
|
202
|
+
minQuantity: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
174
203
|
isTaxable: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
175
204
|
isNetPrice: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
176
205
|
currencyCode: z.ZodMiniString<string>;
|
|
@@ -187,6 +216,16 @@ declare namespace updateProduct {
|
|
|
187
216
|
lengthInMillimeters: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
188
217
|
widthInMillimeters: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
189
218
|
}, z.core.$strip>>;
|
|
219
|
+
tokenization: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
220
|
+
contractAddress: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
221
|
+
contractStandard: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
222
|
+
readonly ERC721: "ERC721";
|
|
223
|
+
readonly ERC1155: "ERC1155";
|
|
224
|
+
}>>;
|
|
225
|
+
tokenId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
226
|
+
supply: z.ZodMiniOptional<z.ZodMiniInt>;
|
|
227
|
+
ercMetadataProperties: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>>;
|
|
228
|
+
}, z.core.$strip>>;
|
|
190
229
|
bundleItems: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
191
230
|
productId: z.ZodMiniString<string>;
|
|
192
231
|
quantity: z.ZodMiniNumber<number>;
|
|
@@ -196,15 +235,6 @@ declare namespace updateProduct {
|
|
|
196
235
|
}, z.core.$strip>>;
|
|
197
236
|
}, z.core.$strip>>>;
|
|
198
237
|
meta: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniAny, z.ZodMiniAny>>;
|
|
199
|
-
content: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
|
|
200
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
201
|
-
subtitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
202
|
-
slug: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
203
|
-
description: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
204
|
-
brand: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
205
|
-
vendor: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
206
|
-
labels: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
207
|
-
}, z.core.$strip>>>;
|
|
208
238
|
variationResolvers: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
209
239
|
vector: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>;
|
|
210
240
|
productId: z.ZodMiniString<string>;
|
|
@@ -1,57 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod/v4-mini';
|
|
2
2
|
import upsertVariations, { ProductVariationSchema } from "./upsertVariations.js";
|
|
3
3
|
import upsertMedia, { MediaSchema } from "./upsertMedia.js";
|
|
4
|
-
import createProduct, { ProductCreatePayloadSchema } from "./create.js";
|
|
4
|
+
import createProduct, { ProductContentSchema, ProductCreatePayloadSchema, ProductSpecificationFields, } from "./create.js";
|
|
5
5
|
import convertTagsToLowerCase from "../utils/convertTagsToLowerCase.js";
|
|
6
6
|
import { ProductStatus } from '@unchainedshop/core-products';
|
|
7
7
|
export const ProductUpdateSpecificationSchema = z.object({
|
|
8
|
+
...ProductSpecificationFields,
|
|
8
9
|
type: z.optional(z.string()),
|
|
9
|
-
|
|
10
|
-
status: z.nullish(z.enum(ProductStatus)),
|
|
11
|
-
published: z.nullish(z.string().check(z.refine((value) => !Number.isNaN(new Date(value).getTime()), 'Invalid date'))),
|
|
12
|
-
tags: z.optional(z.array(z.string())),
|
|
13
|
-
commerce: z.optional(z.object({
|
|
14
|
-
pricing: z.array(z.object({
|
|
15
|
-
amount: z.number(),
|
|
16
|
-
maxQuantity: z.optional(z.number()),
|
|
17
|
-
isTaxable: z.optional(z.boolean()),
|
|
18
|
-
isNetPrice: z.optional(z.boolean()),
|
|
19
|
-
currencyCode: z.string().check(z.minLength(1, 'currencyCode is required')),
|
|
20
|
-
countryCode: z.string().check(z.minLength(1, 'countryCode is required')),
|
|
21
|
-
})),
|
|
22
|
-
})),
|
|
23
|
-
warehousing: z.optional(z.object({
|
|
24
|
-
sku: z.optional(z.string()),
|
|
25
|
-
baseUnit: z.optional(z.string()),
|
|
26
|
-
})),
|
|
27
|
-
supply: z.optional(z.object({
|
|
28
|
-
weightInGram: z.optional(z.number()),
|
|
29
|
-
heightInMillimeters: z.optional(z.number()),
|
|
30
|
-
lengthInMillimeters: z.optional(z.number()),
|
|
31
|
-
widthInMillimeters: z.optional(z.number()),
|
|
32
|
-
})),
|
|
33
|
-
bundleItems: z.optional(z.array(z.object({
|
|
34
|
-
productId: z.string(),
|
|
35
|
-
quantity: z.number(),
|
|
36
|
-
configuration: z.array(z.object({
|
|
37
|
-
key: z.string(),
|
|
38
|
-
value: z.string(),
|
|
39
|
-
})),
|
|
40
|
-
}))),
|
|
41
|
-
meta: z.optional(z.record(z.any(), z.any())),
|
|
42
|
-
content: z.optional(z.record(z.string(), z.object({
|
|
43
|
-
title: z.optional(z.string()),
|
|
44
|
-
subtitle: z.optional(z.string()),
|
|
45
|
-
slug: z.optional(z.string()),
|
|
46
|
-
description: z.optional(z.string()),
|
|
47
|
-
brand: z.optional(z.string()),
|
|
48
|
-
vendor: z.optional(z.string()),
|
|
49
|
-
labels: z.optional(z.array(z.string())),
|
|
50
|
-
}))),
|
|
51
|
-
variationResolvers: z.optional(z.array(z.object({
|
|
52
|
-
vector: z.record(z.string(), z.any()),
|
|
53
|
-
productId: z.string(),
|
|
54
|
-
}))),
|
|
10
|
+
content: z.optional(ProductContentSchema),
|
|
55
11
|
});
|
|
56
12
|
export const ProductUpdatePayloadSchema = z.object({
|
|
57
13
|
_id: z.string(),
|
|
@@ -61,13 +17,14 @@ export const ProductUpdatePayloadSchema = z.object({
|
|
|
61
17
|
});
|
|
62
18
|
const normalizeStatus = (status) => (status === ProductStatus.DRAFT ? null : status);
|
|
63
19
|
const transformSpecification = (specification) => {
|
|
64
|
-
const { variationResolvers: assignments, content, supply, warehousing, ...productData } = specification;
|
|
20
|
+
const { variationResolvers: assignments, content, supply, warehousing, tokenization, ...productData } = specification;
|
|
65
21
|
const tags = productData?.tags ? convertTagsToLowerCase(productData.tags) : [];
|
|
66
22
|
const proxy = assignments ? { assignments } : undefined;
|
|
67
23
|
return {
|
|
68
24
|
...productData,
|
|
69
25
|
published: productData.published ? new Date(productData.published) : undefined,
|
|
70
26
|
...(productData.status !== undefined && { status: normalizeStatus(productData.status) }),
|
|
27
|
+
...(tokenization !== undefined && { tokenization: tokenization }),
|
|
71
28
|
tags,
|
|
72
29
|
warehousing,
|
|
73
30
|
supply,
|
package/lib/core-index.d.ts
CHANGED
|
@@ -2,13 +2,15 @@ import { type mongodb, type MigrationRepository, type ModuleInput } from '@uncha
|
|
|
2
2
|
import { type CustomServices, type Services } from './services/index.ts';
|
|
3
3
|
import { type Modules, type ModuleOptions } from './modules.ts';
|
|
4
4
|
import { type BulkImporter, type BulkImportHandler } from './bulk-importer/index.ts';
|
|
5
|
-
import type { IBaseAdapter } from '@unchainedshop/utils';
|
|
6
5
|
import { type BulkExporter, type BulkExportHandler } from './bulk-exporter/index.ts';
|
|
7
6
|
export * from './bulk-importer/index.ts';
|
|
8
7
|
export * from './services/index.ts';
|
|
9
8
|
export * from './directors/index.ts';
|
|
10
9
|
export * from './factory/index.ts';
|
|
11
10
|
export * from './bulk-exporter/index.ts';
|
|
11
|
+
export * from './plugins/PluginRegistry.ts';
|
|
12
|
+
export * from './utils/getFileAdapter.ts';
|
|
13
|
+
export { filesSettings } from '@unchainedshop/core-files';
|
|
12
14
|
export { default as schedule, type ScheduleData } from './utils/schedule.ts';
|
|
13
15
|
export interface UnchainedCoreOptions {
|
|
14
16
|
db: mongodb.Db;
|
|
@@ -33,4 +35,4 @@ export interface UnchainedCore {
|
|
|
33
35
|
bulkExporter: BulkExporter;
|
|
34
36
|
}
|
|
35
37
|
export declare const initCore: ({ db, migrationRepository, bulkImporter: bulkImporterOptions, modules: customModules, services: customServices, options, bulkExporter: bulkExporterOptions, }: UnchainedCoreOptions) => Promise<UnchainedCore>;
|
|
36
|
-
export declare const getAllAdapters: () => IBaseAdapter[];
|
|
38
|
+
export declare const getAllAdapters: () => import("@unchainedshop/utils").IBaseAdapter[];
|
package/lib/core-index.js
CHANGED
|
@@ -2,13 +2,16 @@ import {} from '@unchainedshop/mongodb';
|
|
|
2
2
|
import initServices, {} from "./services/index.js";
|
|
3
3
|
import initModules, {} from "./modules.js";
|
|
4
4
|
import createBulkImporterFactory, {} from "./bulk-importer/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { pluginRegistry } from "./plugins/PluginRegistry.js";
|
|
6
6
|
import createBulkExporterFactory, {} from "./bulk-exporter/index.js";
|
|
7
7
|
export * from "./bulk-importer/index.js";
|
|
8
8
|
export * from "./services/index.js";
|
|
9
9
|
export * from "./directors/index.js";
|
|
10
10
|
export * from "./factory/index.js";
|
|
11
11
|
export * from "./bulk-exporter/index.js";
|
|
12
|
+
export * from "./plugins/PluginRegistry.js";
|
|
13
|
+
export * from "./utils/getFileAdapter.js";
|
|
14
|
+
export { filesSettings } from '@unchainedshop/core-files';
|
|
12
15
|
export { default as schedule } from "./utils/schedule.js";
|
|
13
16
|
export const initCore = async ({ db, migrationRepository, bulkImporter: bulkImporterOptions = {}, modules: customModules = {}, services: customServices = {}, options = {}, bulkExporter: bulkExporterOptions = {}, }) => {
|
|
14
17
|
const bulkImporter = createBulkImporterFactory(db, bulkImporterOptions);
|
|
@@ -23,19 +26,4 @@ export const initCore = async ({ db, migrationRepository, bulkImporter: bulkImpo
|
|
|
23
26
|
bulkExporter,
|
|
24
27
|
};
|
|
25
28
|
};
|
|
26
|
-
export const getAllAdapters = () =>
|
|
27
|
-
const worker = WorkerDirector.getAdapters();
|
|
28
|
-
const delivery = DeliveryDirector.getAdapters();
|
|
29
|
-
const deliveryPricing = DeliveryPricingDirector.getAdapters();
|
|
30
|
-
const enrollment = EnrollmentDirector.getAdapters();
|
|
31
|
-
const filter = FilterDirector.getAdapters();
|
|
32
|
-
const orderDiscount = OrderDiscountDirector.getAdapters();
|
|
33
|
-
const orderPricing = OrderPricingDirector.getAdapters();
|
|
34
|
-
const payment = PaymentDirector.getAdapters();
|
|
35
|
-
const paymentPricing = PaymentPricingDirector.getAdapters();
|
|
36
|
-
const productDiscount = ProductDiscountDirector.getAdapters();
|
|
37
|
-
const productPricing = ProductPricingDirector.getAdapters();
|
|
38
|
-
const quotation = QuotationDirector.getAdapters();
|
|
39
|
-
const warehousing = WarehousingDirector.getAdapters();
|
|
40
|
-
return [].concat(worker, delivery, deliveryPricing, enrollment, filter, orderDiscount, orderPricing, payment, paymentPricing, productDiscount, productPricing, quotation, warehousing);
|
|
41
|
-
};
|
|
29
|
+
export const getAllAdapters = () => pluginRegistry.getAllAdapters();
|
|
@@ -31,5 +31,8 @@ export interface DiscountAdapterActions<DiscountConfiguration> {
|
|
|
31
31
|
code?: string;
|
|
32
32
|
}) => Promise<any>;
|
|
33
33
|
release: () => Promise<void>;
|
|
34
|
+
reserveForCheckout?: () => Promise<{
|
|
35
|
+
release: () => Promise<void>;
|
|
36
|
+
}>;
|
|
34
37
|
}
|
|
35
38
|
export declare const BaseDiscountAdapter: Omit<IDiscountAdapter<unknown>, 'key' | 'label' | 'version'>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import type { DiscountContext, IDiscountAdapter } from './BaseDiscountAdapter.ts';
|
|
3
3
|
import type { Modules } from '../modules.ts';
|
|
4
4
|
export type IDiscountDirector<DiscountConfiguration> = IBaseDirector<IDiscountAdapter<DiscountConfiguration>> & {
|
|
@@ -11,4 +11,4 @@ export type IDiscountDirector<DiscountConfiguration> = IBaseDirector<IDiscountAd
|
|
|
11
11
|
findSystemDiscounts: () => Promise<string[]>;
|
|
12
12
|
}>;
|
|
13
13
|
};
|
|
14
|
-
export declare const BaseDiscountDirector: <DiscountConfigurationType>(
|
|
14
|
+
export declare const BaseDiscountDirector: <DiscountConfigurationType>(adapterType: symbol) => IDiscountDirector<DiscountConfigurationType>;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const BaseDiscountDirector = (
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
...baseDirector,
|
|
8
|
-
actions: async (discountContext, unchainedAPI) => {
|
|
1
|
+
import { registryDirector } from "./registryDirector.js";
|
|
2
|
+
export const BaseDiscountDirector = (adapterType) => {
|
|
3
|
+
const director = {
|
|
4
|
+
...registryDirector(adapterType),
|
|
5
|
+
actions: async function (discountContext, unchainedAPI) {
|
|
9
6
|
const context = { ...discountContext, ...unchainedAPI };
|
|
10
7
|
return {
|
|
11
8
|
resolveDiscountAdapterFromStaticCode: async (options) => {
|
|
12
9
|
if (!context.order)
|
|
13
10
|
return null;
|
|
14
|
-
const discounts = await Promise.all(
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const discounts = await Promise.all(this.getAdapters().map(async (Adapter) => {
|
|
12
|
+
if (!(await Adapter.isManualAdditionAllowed(options?.code))) {
|
|
13
|
+
return { Adapter, isValid: false };
|
|
14
|
+
}
|
|
18
15
|
const adapter = await Adapter.actions({ context });
|
|
19
16
|
return {
|
|
20
17
|
Adapter,
|
|
@@ -23,10 +20,10 @@ export const BaseDiscountDirector = (directorName) => {
|
|
|
23
20
|
}));
|
|
24
21
|
return discounts.find(({ isValid }) => isValid === true)?.Adapter || null;
|
|
25
22
|
},
|
|
26
|
-
async
|
|
23
|
+
findSystemDiscounts: async () => {
|
|
27
24
|
if (!context.order)
|
|
28
25
|
return [];
|
|
29
|
-
const discounts = await Promise.all(
|
|
26
|
+
const discounts = await Promise.all(this.getAdapters().map(async (Adapter) => {
|
|
30
27
|
const adapter = await Adapter.actions({ context });
|
|
31
28
|
return {
|
|
32
29
|
key: Adapter.key,
|
|
@@ -41,4 +38,5 @@ export const BaseDiscountDirector = (directorName) => {
|
|
|
41
38
|
};
|
|
42
39
|
},
|
|
43
40
|
};
|
|
41
|
+
return director;
|
|
44
42
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector, PricingCalculation } from '@unchainedshop/utils';
|
|
2
2
|
import type { BasePricingAdapterContext, BasePricingContext, IPricingAdapter } from './BasePricingAdapter.ts';
|
|
3
3
|
import type { IPricingSheet } from './BasePricingSheet.ts';
|
|
4
4
|
import type { Modules } from '../modules.ts';
|
|
@@ -13,4 +13,4 @@ export type IPricingDirector<PricingContext extends BasePricingContext, Calculat
|
|
|
13
13
|
rebuildCalculation: (pricingContext: PricingContext, unchainedAPI: Context) => Promise<Calculation[]>;
|
|
14
14
|
calculationSheet: (pricingContext: PricingContext, calculation: Calculation[]) => PricingAdapterSheet;
|
|
15
15
|
};
|
|
16
|
-
export declare const BasePricingDirector: <DirectorContext extends BasePricingContext, AdapterContext extends BasePricingAdapterContext, Calculation extends PricingCalculation, PricingAdapter extends IPricingAdapter<AdapterContext, Calculation, IPricingSheet<Calculation>>>(
|
|
16
|
+
export declare const BasePricingDirector: <DirectorContext extends BasePricingContext, AdapterContext extends BasePricingAdapterContext, Calculation extends PricingCalculation, PricingAdapter extends IPricingAdapter<AdapterContext, Calculation, IPricingSheet<Calculation>>>(adapterType: symbol) => IPricingDirector<DirectorContext, Calculation, AdapterContext, IPricingSheet<Calculation>, PricingAdapter>;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
2
1
|
import { OrderDiscountDirector } from "./OrderDiscountDirector.js";
|
|
2
|
+
import { registryDirector } from "./registryDirector.js";
|
|
3
3
|
import { createLogger } from '@unchainedshop/logger';
|
|
4
4
|
const logger = createLogger('unchained:core');
|
|
5
|
-
export const BasePricingDirector = (
|
|
6
|
-
const baseDirector = BaseDirector(directorName, {
|
|
7
|
-
adapterSortKey: 'orderIndex',
|
|
8
|
-
});
|
|
5
|
+
export const BasePricingDirector = (adapterType) => {
|
|
9
6
|
const director = {
|
|
10
|
-
...
|
|
7
|
+
...registryDirector(adapterType),
|
|
11
8
|
buildPricingContext: async () => {
|
|
12
9
|
throw new Error('Method not implemented');
|
|
13
10
|
},
|
|
@@ -17,7 +14,7 @@ export const BasePricingDirector = (directorName) => {
|
|
|
17
14
|
async rebuildCalculation(pricingContext, unchainedAPI) {
|
|
18
15
|
const context = await this.buildPricingContext(pricingContext, unchainedAPI);
|
|
19
16
|
let calculation = [];
|
|
20
|
-
const Adapters =
|
|
17
|
+
const Adapters = this.getAdapters({
|
|
21
18
|
adapterFilter: (Adapter) => {
|
|
22
19
|
return Adapter.isActivatedFor(context);
|
|
23
20
|
},
|
|
@@ -48,9 +48,10 @@ export const BaseWorker = {
|
|
|
48
48
|
retries: workConfig.retries || 0,
|
|
49
49
|
};
|
|
50
50
|
if (workConfig.input) {
|
|
51
|
-
|
|
52
|
-
if (!
|
|
51
|
+
const input = await workConfig.input(workData);
|
|
52
|
+
if (!input)
|
|
53
53
|
return null;
|
|
54
|
+
workData.input = input;
|
|
54
55
|
}
|
|
55
56
|
return unchainedAPI.modules.worker.ensureOneWork(workData);
|
|
56
57
|
}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import { type DeliveryAdapterActions, type DeliveryContext, type IDeliveryAdapter } from './DeliveryAdapter.ts';
|
|
3
3
|
import type { DeliveryProvider } from '@unchainedshop/core-delivery';
|
|
4
4
|
import { type Order } from '@unchainedshop/core-orders';
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DeliveryError, } from "./DeliveryAdapter.js";
|
|
1
|
+
import { DeliveryError, DeliveryAdapter, } from "./DeliveryAdapter.js";
|
|
3
2
|
import { OrderDeliveryStatus } from '@unchainedshop/core-orders';
|
|
4
3
|
import { createLogger } from '@unchainedshop/logger';
|
|
4
|
+
import { registryDirector } from "./registryDirector.js";
|
|
5
5
|
const logger = createLogger('unchained:core');
|
|
6
|
-
const baseDirector = BaseDirector('DeliveryDirector');
|
|
7
6
|
export const DeliveryDirector = {
|
|
8
|
-
...
|
|
7
|
+
...registryDirector(DeliveryAdapter.adapterType),
|
|
9
8
|
actions: async (deliveryProvider, deliveryContext, unchainedAPI) => {
|
|
10
|
-
const Adapter =
|
|
9
|
+
const Adapter = DeliveryDirector.getAdapter(deliveryProvider.adapterKey);
|
|
11
10
|
if (!Adapter) {
|
|
12
11
|
throw new Error(`Delivery Plugin ${deliveryProvider.adapterKey} not available`);
|
|
13
12
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type BasePricingAdapterContext, type IPricingAdapter
|
|
1
|
+
import { type BasePricingAdapterContext, type IPricingAdapter } from './BasePricingAdapter.ts';
|
|
2
|
+
import type { IPricingSheet } from './BasePricingSheet.ts';
|
|
2
3
|
import type { DeliveryProvider } from '@unchainedshop/core-delivery';
|
|
3
4
|
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
4
5
|
import type { OrderDelivery, OrderDiscount, Order } from '@unchainedshop/core-orders';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DeliveryPricingSheet } from "./DeliveryPricingSheet.js";
|
|
2
|
-
import { BasePricingAdapter, } from "
|
|
2
|
+
import { BasePricingAdapter, } from "./BasePricingAdapter.js";
|
|
3
3
|
const basePricingAdapter = BasePricingAdapter();
|
|
4
4
|
export const DeliveryPricingAdapter = {
|
|
5
5
|
...basePricingAdapter,
|
|
6
|
+
adapterType: Symbol.for('unchained:adapter:pricing:delivery'),
|
|
6
7
|
isActivatedFor: () => {
|
|
7
8
|
return false;
|
|
8
9
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IPricingDirector } from '
|
|
1
|
+
import { type IPricingDirector } from './BasePricingDirector.ts';
|
|
2
2
|
import { type DeliveryPricingAdapterContext, type DeliveryPricingCalculation, type IDeliveryPricingAdapter, type IDeliveryPricingSheet } from './DeliveryPricingAdapter.ts';
|
|
3
3
|
import type { DeliveryProvider } from '@unchainedshop/core-delivery';
|
|
4
4
|
import type { Order } from '@unchainedshop/core-orders';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DeliveryPricingSheet
|
|
2
|
-
import {} from "./
|
|
3
|
-
|
|
1
|
+
import { DeliveryPricingSheet } from "./DeliveryPricingSheet.js";
|
|
2
|
+
import { BasePricingDirector } from "./BasePricingDirector.js";
|
|
3
|
+
import { DeliveryPricingAdapter, } from "./DeliveryPricingAdapter.js";
|
|
4
|
+
const baseDirector = BasePricingDirector(DeliveryPricingAdapter.adapterType);
|
|
4
5
|
export const DeliveryPricingDirector = {
|
|
5
6
|
...baseDirector,
|
|
6
7
|
async buildPricingContext(context, unchainedAPI) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PricingSheetParams } from '
|
|
1
|
+
import { type PricingSheetParams } from './BasePricingSheet.ts';
|
|
2
2
|
import type { DeliveryPricingCalculation, IDeliveryPricingSheet } from './DeliveryPricingAdapter.ts';
|
|
3
3
|
export declare const DeliveryPricingRowCategory: {
|
|
4
4
|
readonly Delivery: "DELIVERY";
|