@unchainedshop/core 5.0.0-alpha.1 → 5.0.0-alpha.11
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.js +1 -1
- package/lib/bulk-exporter/handlers/exportProductsHandler.js +2 -2
- package/lib/bulk-exporter/handlers/exportUsersHandler.js +1 -0
- package/lib/bulk-importer/handlers/assortment/create.js +1 -3
- package/lib/bulk-importer/handlers/assortment/update.js +1 -1
- package/lib/bulk-importer/handlers/product/create.d.ts +150 -35
- package/lib/bulk-importer/handlers/product/create.js +35 -16
- package/lib/bulk-importer/handlers/product/update.d.ts +78 -36
- package/lib/bulk-importer/handlers/product/update.js +8 -48
- package/lib/core-index.d.ts +1 -2
- package/lib/core-index.js +2 -18
- package/lib/directors/BaseDiscountAdapter.d.ts +3 -0
- package/lib/directors/BaseDiscountDirector.d.ts +2 -2
- package/lib/directors/BaseDiscountDirector.js +7 -9
- package/lib/directors/BasePricingDirector.d.ts +2 -2
- package/lib/directors/BasePricingDirector.js +3 -6
- package/lib/directors/BasePricingSheet.d.ts +2 -0
- package/lib/directors/BaseWorker.js +3 -2
- package/lib/directors/DeliveryDirector.d.ts +1 -1
- package/lib/directors/DeliveryDirector.js +2 -12
- package/lib/directors/DeliveryPricingDirector.js +1 -10
- package/lib/directors/DeliveryPricingSheet.js +9 -4
- package/lib/directors/EnrollmentAdapter.d.ts +11 -1
- package/lib/directors/EnrollmentAdapter.js +7 -2
- package/lib/directors/EnrollmentDirector.d.ts +3 -2
- package/lib/directors/EnrollmentDirector.js +9 -19
- package/lib/directors/FileDirector.d.ts +4 -4
- package/lib/directors/FileDirector.js +2 -13
- package/lib/directors/FilterDirector.d.ts +1 -1
- package/lib/directors/FilterDirector.js +25 -32
- package/lib/directors/OrderDiscountDirector.d.ts +1 -15
- package/lib/directors/OrderDiscountDirector.js +1 -13
- package/lib/directors/OrderPricingDirector.js +1 -10
- package/lib/directors/OrderPricingSheet.d.ts +1 -0
- package/lib/directors/OrderPricingSheet.js +16 -17
- package/lib/directors/PaymentDirector.d.ts +1 -1
- package/lib/directors/PaymentDirector.js +2 -12
- package/lib/directors/PaymentPricingDirector.js +1 -10
- package/lib/directors/PaymentPricingSheet.js +9 -4
- package/lib/directors/ProductDiscountDirector.d.ts +1 -15
- package/lib/directors/ProductDiscountDirector.js +1 -13
- package/lib/directors/ProductPricingAdapter.d.ts +1 -0
- package/lib/directors/ProductPricingDirector.js +2 -10
- package/lib/directors/ProductPricingSheet.js +7 -4
- package/lib/directors/QuotationAdapter.js +5 -2
- package/lib/directors/QuotationDirector.d.ts +1 -1
- package/lib/directors/QuotationDirector.js +2 -14
- package/lib/directors/WarehousingDirector.js +16 -34
- package/lib/directors/WorkerDirector.d.ts +7 -1
- package/lib/directors/WorkerDirector.js +29 -29
- package/lib/directors/registryDirector.d.ts +2 -0
- package/lib/directors/registryDirector.js +6 -0
- package/lib/errors.d.ts +1 -0
- package/lib/errors.js +5 -0
- package/lib/factory/index.d.ts +12 -1
- package/lib/factory/index.js +12 -1
- package/lib/factory/registerAssortmentSearchFilter.d.ts +2 -1
- package/lib/factory/registerAssortmentSearchFilter.js +6 -3
- package/lib/factory/registerDeliveryPricing.d.ts +7 -0
- package/lib/factory/registerDeliveryPricing.js +30 -0
- package/lib/factory/registerDeliveryProvider.d.ts +12 -0
- package/lib/factory/registerDeliveryProvider.js +46 -0
- package/lib/factory/registerEnrollment.d.ts +25 -0
- package/lib/factory/registerEnrollment.js +41 -0
- package/lib/factory/registerFileAdapter.d.ts +17 -0
- package/lib/factory/registerFileAdapter.js +24 -0
- package/lib/factory/registerOrderDiscount.d.ts +13 -0
- package/lib/factory/registerOrderDiscount.js +39 -0
- package/lib/factory/registerOrderPricing.d.ts +7 -0
- package/lib/factory/registerOrderPricing.js +30 -0
- package/lib/factory/registerPaymentPricing.d.ts +7 -0
- package/lib/factory/registerPaymentPricing.js +30 -0
- package/lib/factory/registerPaymentProvider.d.ts +15 -0
- package/lib/factory/registerPaymentProvider.js +53 -0
- package/lib/factory/registerProductDiscount.d.ts +20 -0
- package/lib/factory/registerProductDiscount.js +47 -0
- package/lib/factory/registerProductDiscoverabilityFilter.d.ts +2 -1
- package/lib/factory/registerProductDiscoverabilityFilter.js +6 -3
- package/lib/factory/registerProductPricing.d.ts +7 -0
- package/lib/factory/registerProductPricing.js +30 -0
- package/lib/factory/registerProductSearchFilter.d.ts +2 -1
- package/lib/factory/registerProductSearchFilter.js +4 -3
- package/lib/factory/registerQuotation.d.ts +13 -0
- package/lib/factory/registerQuotation.js +53 -0
- package/lib/factory/registerVirtualWarehousing.js +1 -1
- package/lib/factory/registerWorker.js +1 -1
- package/lib/plugins/PluginRegistry.d.ts +2 -1
- package/lib/plugins/PluginRegistry.js +19 -4
- package/lib/services/addCartQuotation.d.ts +9 -13
- package/lib/services/addCartQuotation.js +43 -38
- package/lib/services/addMultipleCartProducts.js +3 -2
- package/lib/services/bulkAssignProductsToAssortment.d.ts +8 -0
- package/lib/services/bulkAssignProductsToAssortment.js +11 -0
- package/lib/services/bulkDeleteUsers.d.ts +7 -0
- package/lib/services/bulkDeleteUsers.js +11 -0
- package/lib/services/bulkRemoveFilters.d.ts +7 -0
- package/lib/services/bulkRemoveFilters.js +10 -0
- package/lib/services/bulkRemoveProducts.d.ts +7 -0
- package/lib/services/bulkRemoveProducts.js +23 -0
- package/lib/services/bulkSetFilterActive.d.ts +8 -0
- package/lib/services/bulkSetFilterActive.js +12 -0
- package/lib/services/calculateDiscountTotal.d.ts +5 -1
- package/lib/services/calculateDiscountTotal.js +36 -28
- package/lib/services/checkoutOrder.js +8 -0
- package/lib/services/createFilter.d.ts +3 -0
- package/lib/services/createFilter.js +6 -0
- package/lib/services/createFilterOption.d.ts +5 -0
- package/lib/services/createFilterOption.js +8 -0
- package/lib/services/createSignedURL.js +2 -1
- package/lib/services/deleteCart.d.ts +2 -0
- package/lib/services/deleteCart.js +7 -0
- package/lib/services/deleteUser.js +2 -5
- package/lib/services/index.d.ts +32 -1
- package/lib/services/index.js +32 -1
- package/lib/services/initCartProviders.js +1 -0
- package/lib/services/initializeEnrollment.d.ts +1 -1
- package/lib/services/initializeEnrollment.js +11 -0
- package/lib/services/isTokenInvalidateable.d.ts +3 -1
- package/lib/services/isTokenInvalidateable.js +2 -2
- package/lib/services/loadFilterOptions.js +3 -3
- package/lib/services/migrateOrderCart.js +2 -2
- package/lib/services/migrateUserData.js +3 -0
- package/lib/services/processEnrollment.js +8 -4
- package/lib/services/processOrder.js +7 -6
- package/lib/services/processQuotation.js +11 -13
- package/lib/services/proposeQuotation.js +3 -0
- package/lib/services/removeFilterOption.d.ts +6 -0
- package/lib/services/removeFilterOption.js +8 -0
- package/lib/services/removeProduct.js +2 -1
- package/lib/services/reserveOrderDiscountsForCheckout.d.ts +5 -0
- package/lib/services/reserveOrderDiscountsForCheckout.js +34 -0
- package/lib/services/reserveOrderQuotationsForCheckout.d.ts +8 -0
- package/lib/services/reserveOrderQuotationsForCheckout.js +49 -0
- package/lib/services/simulateConfigurablePriceRange.js +1 -1
- package/lib/services/simulateDeliveryPricing.js +1 -1
- package/lib/services/simulatePaymentPricing.js +1 -1
- 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/suspendEnrollment.d.ts +5 -0
- package/lib/services/suspendEnrollment.js +21 -0
- package/lib/services/terminateEnrollment.d.ts +6 -2
- package/lib/services/terminateEnrollment.js +27 -7
- package/lib/services/updateCalculation.js +2 -1
- package/lib/services/updateCartItem.d.ts +7 -7
- package/lib/services/updateCartItem.js +28 -25
- package/lib/services/updateEnrollmentPlan.d.ts +5 -0
- package/lib/services/updateEnrollmentPlan.js +26 -0
- package/lib/services/updateFilter.d.ts +3 -0
- package/lib/services/updateFilter.js +8 -0
- package/lib/services/uploadFileFromStream.js +2 -1
- package/lib/services/validateOrder.js +13 -9
- package/package.json +29 -23
- package/lib/errors/common.d.ts +0 -568
- package/lib/errors/common.js +0 -789
- package/lib/errors/index.d.ts +0 -1
- package/lib/errors/index.js +0 -1
- package/lib/services/addCartDiscount.d.ts +0 -10
- package/lib/services/addCartDiscount.js +0 -27
- package/lib/services/addCartItem.d.ts +0 -15
- package/lib/services/addCartItem.js +0 -41
- package/lib/services/addEmail.d.ts +0 -7
- package/lib/services/addEmail.js +0 -17
- package/lib/services/addProductAssignment.d.ts +0 -3
- package/lib/services/addProductAssignment.js +0 -63
- package/lib/services/authenticateWithPassword.d.ts +0 -15
- package/lib/services/authenticateWithPassword.js +0 -34
- package/lib/services/changePassword.d.ts +0 -10
- package/lib/services/changePassword.js +0 -19
- package/lib/services/countOrdersWithFilters.d.ts +0 -3
- package/lib/services/countOrdersWithFilters.js +0 -25
- package/lib/services/createAssortment.d.ts +0 -7
- package/lib/services/createAssortment.js +0 -10
- package/lib/services/createBookmark.d.ts +0 -8
- package/lib/services/createBookmark.js +0 -21
- package/lib/services/createDeliveryProvider.d.ts +0 -6
- package/lib/services/createDeliveryProvider.js +0 -19
- package/lib/services/createEnrollment.d.ts +0 -17
- package/lib/services/createEnrollment.js +0 -33
- package/lib/services/createProduct.d.ts +0 -7
- package/lib/services/createProduct.js +0 -8
- package/lib/services/createProductBundleItem.d.ts +0 -5
- package/lib/services/createProductBundleItem.js +0 -25
- package/lib/services/createProductReview.d.ts +0 -8
- package/lib/services/createProductReview.js +0 -12
- package/lib/services/deliverOrder.d.ts +0 -5
- package/lib/services/deliverOrder.js +0 -26
- package/lib/services/findActiveWorkTypes.d.ts +0 -2
- package/lib/services/findActiveWorkTypes.js +0 -6
- package/lib/services/findDeliveryInterfaces.d.ts +0 -7
- package/lib/services/findDeliveryInterfaces.js +0 -13
- package/lib/services/findOrdersWithFilters.d.ts +0 -9
- package/lib/services/findOrdersWithFilters.js +0 -25
- package/lib/services/findPaymentInterfaces.d.ts +0 -7
- package/lib/services/findPaymentInterfaces.js +0 -13
- package/lib/services/findWarehousingInterfaces.d.ts +0 -7
- package/lib/services/findWarehousingInterfaces.js +0 -13
- package/lib/services/getDeliveryDiscounts.d.ts +0 -8
- package/lib/services/getDeliveryDiscounts.js +0 -14
- package/lib/services/getPaymentDiscounts.d.ts +0 -8
- package/lib/services/getPaymentDiscounts.js +0 -14
- package/lib/services/getShopInfo.d.ts +0 -25
- package/lib/services/getShopInfo.js +0 -47
- package/lib/services/impersonateUser.d.ts +0 -8
- package/lib/services/impersonateUser.js +0 -20
- package/lib/services/loginAsGuest.d.ts +0 -10
- package/lib/services/loginAsGuest.js +0 -19
- package/lib/services/obfuscateWorkerData.d.ts +0 -4
- package/lib/services/obfuscateWorkerData.js +0 -4
- package/lib/services/orderPricingAccessors.d.ts +0 -18
- package/lib/services/orderPricingAccessors.js +0 -29
- package/lib/services/payOrder.d.ts +0 -5
- package/lib/services/payOrder.js +0 -25
- package/lib/services/registerUser.d.ts +0 -14
- package/lib/services/registerUser.js +0 -44
- package/lib/services/removeBookmark.d.ts +0 -6
- package/lib/services/removeBookmark.js +0 -10
- package/lib/services/removeCartItem.d.ts +0 -6
- package/lib/services/removeCartItem.js +0 -19
- package/lib/services/resetPasswordWithMigration.d.ts +0 -14
- package/lib/services/resetPasswordWithMigration.js +0 -31
- package/lib/services/resolveWorkType.d.ts +0 -1
- package/lib/services/resolveWorkType.js +0 -7
- package/lib/services/searchProductsWithAssortment.d.ts +0 -19
- package/lib/services/searchProductsWithAssortment.js +0 -17
- package/lib/services/toggleBookmark.d.ts +0 -8
- package/lib/services/toggleBookmark.js +0 -33
- package/lib/services/updateCart.d.ts +0 -15
- package/lib/services/updateCart.js +0 -27
- package/lib/services/updateEnrollment.d.ts +0 -13
- package/lib/services/updateEnrollment.js +0 -36
- package/lib/services/verifyEmailWithMigration.d.ts +0 -15
- package/lib/services/verifyEmailWithMigration.js +0 -23
|
@@ -1,56 +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
|
+
import { ProductStatus } from '@unchainedshop/core-products';
|
|
6
7
|
export const ProductUpdateSpecificationSchema = z.object({
|
|
8
|
+
...ProductSpecificationFields,
|
|
7
9
|
type: z.optional(z.string()),
|
|
8
|
-
|
|
9
|
-
status: z.nullable(z.optional(z.string())),
|
|
10
|
-
published: z.nullish(z.iso.datetime()),
|
|
11
|
-
tags: z.optional(z.array(z.string())),
|
|
12
|
-
commerce: z.optional(z.object({
|
|
13
|
-
pricing: z.array(z.object({
|
|
14
|
-
amount: z.number(),
|
|
15
|
-
maxQuantity: z.optional(z.number()),
|
|
16
|
-
isTaxable: z.optional(z.boolean()),
|
|
17
|
-
isNetPrice: z.optional(z.boolean()),
|
|
18
|
-
currencyCode: z.string().check(z.minLength(1, 'currencyCode is required')),
|
|
19
|
-
countryCode: z.string().check(z.minLength(1, 'countryCode is required')),
|
|
20
|
-
})),
|
|
21
|
-
})),
|
|
22
|
-
warehousing: z.optional(z.object({
|
|
23
|
-
sku: z.optional(z.string()),
|
|
24
|
-
baseUnit: z.optional(z.string()),
|
|
25
|
-
})),
|
|
26
|
-
supply: z.optional(z.object({
|
|
27
|
-
weightInGram: z.optional(z.number()),
|
|
28
|
-
heightInMillimeters: z.optional(z.number()),
|
|
29
|
-
lengthInMillimeters: z.optional(z.number()),
|
|
30
|
-
widthInMillimeters: z.optional(z.number()),
|
|
31
|
-
})),
|
|
32
|
-
bundleItems: z.optional(z.array(z.object({
|
|
33
|
-
productId: z.string(),
|
|
34
|
-
quantity: z.number(),
|
|
35
|
-
configuration: z.array(z.object({
|
|
36
|
-
key: z.string(),
|
|
37
|
-
value: z.string(),
|
|
38
|
-
})),
|
|
39
|
-
}))),
|
|
40
|
-
meta: z.optional(z.record(z.any(), z.any())),
|
|
41
|
-
content: z.optional(z.record(z.string(), z.object({
|
|
42
|
-
title: z.optional(z.string()),
|
|
43
|
-
subtitle: z.optional(z.string()),
|
|
44
|
-
slug: z.optional(z.string()),
|
|
45
|
-
description: z.optional(z.string()),
|
|
46
|
-
brand: z.optional(z.string()),
|
|
47
|
-
vendor: z.optional(z.string()),
|
|
48
|
-
labels: z.optional(z.array(z.string())),
|
|
49
|
-
}))),
|
|
50
|
-
variationResolvers: z.optional(z.array(z.object({
|
|
51
|
-
vector: z.record(z.string(), z.any()),
|
|
52
|
-
productId: z.string(),
|
|
53
|
-
}))),
|
|
10
|
+
content: z.optional(ProductContentSchema),
|
|
54
11
|
});
|
|
55
12
|
export const ProductUpdatePayloadSchema = z.object({
|
|
56
13
|
_id: z.string(),
|
|
@@ -58,13 +15,16 @@ export const ProductUpdatePayloadSchema = z.object({
|
|
|
58
15
|
media: z.optional(z.array(MediaSchema)),
|
|
59
16
|
variations: z.optional(z.array(ProductVariationSchema)),
|
|
60
17
|
});
|
|
18
|
+
const normalizeStatus = (status) => (status === ProductStatus.DRAFT ? null : status);
|
|
61
19
|
const transformSpecification = (specification) => {
|
|
62
|
-
const { variationResolvers: assignments, content, supply, warehousing, ...productData } = specification;
|
|
20
|
+
const { variationResolvers: assignments, content, supply, warehousing, tokenization, ...productData } = specification;
|
|
63
21
|
const tags = productData?.tags ? convertTagsToLowerCase(productData.tags) : [];
|
|
64
22
|
const proxy = assignments ? { assignments } : undefined;
|
|
65
23
|
return {
|
|
66
24
|
...productData,
|
|
67
25
|
published: productData.published ? new Date(productData.published) : undefined,
|
|
26
|
+
...(productData.status !== undefined && { status: normalizeStatus(productData.status) }),
|
|
27
|
+
...(tokenization !== undefined && { tokenization: tokenization }),
|
|
68
28
|
tags,
|
|
69
29
|
warehousing,
|
|
70
30
|
supply,
|
package/lib/core-index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ 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';
|
|
@@ -36,4 +35,4 @@ export interface UnchainedCore {
|
|
|
36
35
|
bulkExporter: BulkExporter;
|
|
37
36
|
}
|
|
38
37
|
export declare const initCore: ({ db, migrationRepository, bulkImporter: bulkImporterOptions, modules: customModules, services: customServices, options, bulkExporter: bulkExporterOptions, }: UnchainedCoreOptions) => Promise<UnchainedCore>;
|
|
39
|
-
export declare const getAllAdapters: () => IBaseAdapter[];
|
|
38
|
+
export declare const getAllAdapters: () => import("@unchainedshop/utils").IBaseAdapter[];
|
package/lib/core-index.js
CHANGED
|
@@ -2,7 +2,7 @@ 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";
|
|
@@ -26,20 +26,4 @@ export const initCore = async ({ db, migrationRepository, bulkImporter: bulkImpo
|
|
|
26
26
|
bulkExporter,
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
export const getAllAdapters = () =>
|
|
30
|
-
const worker = WorkerDirector.getAdapters();
|
|
31
|
-
const delivery = DeliveryDirector.getAdapters();
|
|
32
|
-
const deliveryPricing = DeliveryPricingDirector.getAdapters();
|
|
33
|
-
const enrollment = EnrollmentDirector.getAdapters();
|
|
34
|
-
const file = FileDirector.getAdapters();
|
|
35
|
-
const filter = FilterDirector.getAdapters();
|
|
36
|
-
const orderDiscount = OrderDiscountDirector.getAdapters();
|
|
37
|
-
const orderPricing = OrderPricingDirector.getAdapters();
|
|
38
|
-
const payment = PaymentDirector.getAdapters();
|
|
39
|
-
const paymentPricing = PaymentPricingDirector.getAdapters();
|
|
40
|
-
const productDiscount = ProductDiscountDirector.getAdapters();
|
|
41
|
-
const productPricing = ProductPricingDirector.getAdapters();
|
|
42
|
-
const quotation = QuotationDirector.getAdapters();
|
|
43
|
-
const warehousing = WarehousingDirector.getAdapters();
|
|
44
|
-
return [].concat(worker, delivery, deliveryPricing, enrollment, file, filter, orderDiscount, orderPricing, payment, paymentPricing, productDiscount, productPricing, quotation, warehousing);
|
|
45
|
-
};
|
|
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,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const BaseDiscountDirector = (
|
|
3
|
-
const baseDirector = BaseDirector(directorName, {
|
|
4
|
-
adapterSortKey: 'orderIndex',
|
|
5
|
-
});
|
|
1
|
+
import { registryDirector } from "./registryDirector.js";
|
|
2
|
+
export const BaseDiscountDirector = (adapterType) => {
|
|
6
3
|
const director = {
|
|
7
|
-
...
|
|
4
|
+
...registryDirector(adapterType),
|
|
8
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(this.getAdapters()
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const discounts = await Promise.all(this.getAdapters().map(async (Adapter) => {
|
|
12
|
+
if (!(await Adapter.isManualAdditionAllowed(options?.code))) {
|
|
13
|
+
return { Adapter, isValid: false };
|
|
14
|
+
}
|
|
17
15
|
const adapter = await Adapter.actions({ context });
|
|
18
16
|
return {
|
|
19
17
|
Adapter,
|
|
@@ -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
|
},
|
|
@@ -3,6 +3,8 @@ export interface PricingDiscount {
|
|
|
3
3
|
discountId: string;
|
|
4
4
|
amount: number;
|
|
5
5
|
currencyCode: string;
|
|
6
|
+
isTaxable: boolean;
|
|
7
|
+
isNetPrice: boolean;
|
|
6
8
|
}
|
|
7
9
|
export interface IPricingSheet<Calculation extends PricingCalculation> extends IBasePricingSheet<Calculation> {
|
|
8
10
|
discountPrices: (discountId?: string) => PricingDiscount[];
|
|
@@ -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,20 +1,10 @@
|
|
|
1
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
2
1
|
import { DeliveryError, DeliveryAdapter, } from "./DeliveryAdapter.js";
|
|
3
2
|
import { OrderDeliveryStatus } from '@unchainedshop/core-orders';
|
|
4
3
|
import { createLogger } from '@unchainedshop/logger';
|
|
5
|
-
import {
|
|
4
|
+
import { registryDirector } from "./registryDirector.js";
|
|
6
5
|
const logger = createLogger('unchained:core');
|
|
7
|
-
const baseDirector = BaseDirector('DeliveryDirector');
|
|
8
6
|
export const DeliveryDirector = {
|
|
9
|
-
...
|
|
10
|
-
getAdapter: (key) => {
|
|
11
|
-
const adapters = pluginRegistry.getAdapters(DeliveryAdapter.adapterType);
|
|
12
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
13
|
-
},
|
|
14
|
-
getAdapters: ({ adapterFilter } = {}) => {
|
|
15
|
-
const adapters = pluginRegistry.getAdapters(DeliveryAdapter.adapterType);
|
|
16
|
-
return adapters.filter(adapterFilter || (() => true));
|
|
17
|
-
},
|
|
7
|
+
...registryDirector(DeliveryAdapter.adapterType),
|
|
18
8
|
actions: async (deliveryProvider, deliveryContext, unchainedAPI) => {
|
|
19
9
|
const Adapter = DeliveryDirector.getAdapter(deliveryProvider.adapterKey);
|
|
20
10
|
if (!Adapter) {
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { DeliveryPricingSheet } from "./DeliveryPricingSheet.js";
|
|
2
2
|
import { BasePricingDirector } from "./BasePricingDirector.js";
|
|
3
3
|
import { DeliveryPricingAdapter, } from "./DeliveryPricingAdapter.js";
|
|
4
|
-
|
|
5
|
-
const baseDirector = BasePricingDirector('DeliveryPricingDirector');
|
|
4
|
+
const baseDirector = BasePricingDirector(DeliveryPricingAdapter.adapterType);
|
|
6
5
|
export const DeliveryPricingDirector = {
|
|
7
6
|
...baseDirector,
|
|
8
|
-
getAdapter: (key) => {
|
|
9
|
-
const adapters = pluginRegistry.getAdapters(DeliveryPricingAdapter.adapterType);
|
|
10
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
11
|
-
},
|
|
12
|
-
getAdapters: ({ adapterFilter } = {}) => {
|
|
13
|
-
const adapters = pluginRegistry.getAdapters(DeliveryPricingAdapter.adapterType);
|
|
14
|
-
return adapters.filter(adapterFilter || (() => true));
|
|
15
|
-
},
|
|
16
7
|
async buildPricingContext(context, unchainedAPI) {
|
|
17
8
|
const { modules } = unchainedAPI;
|
|
18
9
|
if ('item' in context) {
|
|
@@ -28,10 +28,12 @@ export const DeliveryPricingSheet = (params) => {
|
|
|
28
28
|
meta,
|
|
29
29
|
});
|
|
30
30
|
},
|
|
31
|
-
addTax({ amount, rate, meta }) {
|
|
31
|
+
addTax({ amount, rate, baseCategory, discountId, meta }) {
|
|
32
32
|
basePricingSheet.calculation.push({
|
|
33
33
|
amount,
|
|
34
34
|
category: DeliveryPricingRowCategory.Tax,
|
|
35
|
+
baseCategory,
|
|
36
|
+
discountId,
|
|
35
37
|
isNetPrice: false,
|
|
36
38
|
isTaxable: false,
|
|
37
39
|
meta,
|
|
@@ -54,17 +56,20 @@ export const DeliveryPricingSheet = (params) => {
|
|
|
54
56
|
.filter(Boolean);
|
|
55
57
|
return [...new Set(discountIds)]
|
|
56
58
|
.map((discountId) => {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
+
const taxAmount = pricingSheet.taxSum({
|
|
60
|
+
baseCategory: DeliveryPricingRowCategory.Discount,
|
|
59
61
|
discountId,
|
|
60
62
|
});
|
|
63
|
+
const amount = pricingSheet.sum({ category: DeliveryPricingRowCategory.Discount, discountId }) + taxAmount;
|
|
61
64
|
if (!amount) {
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
64
67
|
return {
|
|
65
68
|
discountId,
|
|
66
69
|
amount: Math.round(amount),
|
|
67
|
-
currencyCode,
|
|
70
|
+
currencyCode: pricingSheet.currencyCode,
|
|
71
|
+
isTaxable: taxAmount !== 0,
|
|
72
|
+
isNetPrice: false,
|
|
68
73
|
};
|
|
69
74
|
})
|
|
70
75
|
.filter(Boolean);
|
|
@@ -2,6 +2,7 @@ import { type IBaseAdapter } from '@unchainedshop/utils';
|
|
|
2
2
|
import { type Enrollment, type EnrollmentOrderPositionTemplate, type EnrollmentPeriod, type EnrollmentPlan } from '@unchainedshop/core-enrollments';
|
|
3
3
|
import type { Product, ProductPlan } from '@unchainedshop/core-products';
|
|
4
4
|
import type { OrderPosition } from '@unchainedshop/core-orders';
|
|
5
|
+
import type { Modules } from '../modules.ts';
|
|
5
6
|
export interface EnrollmentContext {
|
|
6
7
|
enrollment: Enrollment;
|
|
7
8
|
product: Product;
|
|
@@ -16,11 +17,20 @@ export interface EnrollmentAdapterActions {
|
|
|
16
17
|
isOverdue: () => Promise<boolean>;
|
|
17
18
|
isValidForActivation: () => Promise<boolean>;
|
|
18
19
|
nextPeriod: () => Promise<EnrollmentPeriod | null>;
|
|
20
|
+
terminationDate: (params: {
|
|
21
|
+
referenceDate: Date;
|
|
22
|
+
}) => Promise<Date | null>;
|
|
23
|
+
transformPlanToNewPlan: (params: {
|
|
24
|
+
plan: EnrollmentPlan;
|
|
25
|
+
}) => Promise<EnrollmentPlan | null>;
|
|
19
26
|
}
|
|
20
27
|
export type IEnrollmentAdapter = IBaseAdapter & {
|
|
28
|
+
orderIndex?: number;
|
|
21
29
|
isActivatedFor: (productPlan?: ProductPlan) => boolean;
|
|
22
30
|
transformOrderItemToEnrollmentPlan: (orderPosition: OrderPosition, unchainedAPI: any) => Promise<EnrollmentPlan>;
|
|
23
|
-
actions: (params: EnrollmentContext
|
|
31
|
+
actions: (params: EnrollmentContext & {
|
|
32
|
+
modules: Modules;
|
|
33
|
+
}) => EnrollmentAdapterActions;
|
|
24
34
|
};
|
|
25
35
|
export declare const periodForReferenceDate: (referenceDate: Date, intervalCount?: number, interval?: string) => {
|
|
26
36
|
start: Date;
|
|
@@ -24,7 +24,6 @@ export const EnrollmentAdapter = {
|
|
|
24
24
|
},
|
|
25
25
|
transformOrderItemToEnrollmentPlan: async (item) => {
|
|
26
26
|
return {
|
|
27
|
-
configuration: item.configuration,
|
|
28
27
|
productId: item.productId,
|
|
29
28
|
quantity: item.quantity,
|
|
30
29
|
};
|
|
@@ -57,11 +56,17 @@ export const EnrollmentAdapter = {
|
|
|
57
56
|
}
|
|
58
57
|
return acc;
|
|
59
58
|
}, referenceDate);
|
|
60
|
-
|
|
59
|
+
const period = {
|
|
61
60
|
...periodForReferenceDate(lastEnd, plan.billingIntervalCount, plan.billingInterval),
|
|
62
61
|
isTrial: false,
|
|
63
62
|
};
|
|
63
|
+
if (enrollment?.expires && period.start.getTime() >= new Date(enrollment.expires).getTime()) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return period;
|
|
64
67
|
},
|
|
68
|
+
terminationDate: async ({ referenceDate }) => referenceDate,
|
|
69
|
+
transformPlanToNewPlan: async () => null,
|
|
65
70
|
};
|
|
66
71
|
},
|
|
67
72
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import type { EnrollmentAdapterActions, EnrollmentContext, IEnrollmentAdapter } from './EnrollmentAdapter.ts';
|
|
3
3
|
import type { OrderPosition } from '@unchainedshop/core-orders';
|
|
4
|
-
import type { Product } from '@unchainedshop/core-products';
|
|
4
|
+
import type { Product, ProductPlan } from '@unchainedshop/core-products';
|
|
5
5
|
import type { Enrollment } from '@unchainedshop/core-enrollments';
|
|
6
6
|
import type { Modules } from '../modules.ts';
|
|
7
7
|
export type IEnrollmentDirector = IBaseDirector<IEnrollmentAdapter> & {
|
|
@@ -9,6 +9,7 @@ export type IEnrollmentDirector = IBaseDirector<IEnrollmentAdapter> & {
|
|
|
9
9
|
orderPosition: OrderPosition;
|
|
10
10
|
product: Product;
|
|
11
11
|
}, doc: Omit<Enrollment, 'configuration' | 'productId' | 'quantity' | 'status' | 'periods' | 'log' | '_id' | 'created'>, unchainedAPI: any) => Promise<Omit<Enrollment, 'status' | 'periods' | 'log' | '_id' | 'created'> & Pick<Partial<Enrollment>, '_id' | 'created'>>;
|
|
12
|
+
findSupportedAdapter: (productPlan?: ProductPlan) => IEnrollmentAdapter | null;
|
|
12
13
|
actions: (enrollmentContext: EnrollmentContext, unchainedAPI: {
|
|
13
14
|
modules: Modules;
|
|
14
15
|
}) => Promise<EnrollmentAdapterActions>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
2
1
|
import { EnrollmentAdapter } from "./EnrollmentAdapter.js";
|
|
3
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
4
|
-
import {
|
|
3
|
+
import { registryDirector } from "./registryDirector.js";
|
|
4
|
+
import { createServiceError } from "../errors.js";
|
|
5
5
|
const logger = createLogger('unchained:core');
|
|
6
|
-
const baseDirector = BaseDirector('EnrollmentDirector', {
|
|
7
|
-
adapterSortKey: 'orderIndex',
|
|
8
|
-
});
|
|
9
6
|
const findAppropriateAdapters = (productPlan) => EnrollmentDirector.getAdapters({
|
|
10
7
|
adapterFilter: (Adapter) => {
|
|
11
8
|
const activated = Adapter.isActivatedFor(productPlan);
|
|
@@ -16,32 +13,25 @@ const findAppropriateAdapters = (productPlan) => EnrollmentDirector.getAdapters(
|
|
|
16
13
|
},
|
|
17
14
|
});
|
|
18
15
|
export const EnrollmentDirector = {
|
|
19
|
-
...
|
|
20
|
-
|
|
21
|
-
const adapters = pluginRegistry.getAdapters(EnrollmentAdapter.adapterType);
|
|
22
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
23
|
-
},
|
|
24
|
-
getAdapters: ({ adapterFilter } = {}) => {
|
|
25
|
-
const adapters = pluginRegistry.getAdapters(EnrollmentAdapter.adapterType);
|
|
26
|
-
return adapters.filter(adapterFilter || (() => true));
|
|
27
|
-
},
|
|
16
|
+
...registryDirector(EnrollmentAdapter.adapterType),
|
|
17
|
+
findSupportedAdapter: (productPlan) => findAppropriateAdapters(productPlan)?.[0] || null,
|
|
28
18
|
transformOrderItemToEnrollment: async ({ orderPosition, product }, doc, unchainedAPI) => {
|
|
29
|
-
const Adapter =
|
|
19
|
+
const Adapter = EnrollmentDirector.findSupportedAdapter(product.plan);
|
|
30
20
|
if (!Adapter) {
|
|
31
|
-
throw
|
|
21
|
+
throw createServiceError('EnrollmentPlanNotSupportedError', 'No suitable enrollment plugin available for this item');
|
|
32
22
|
}
|
|
33
23
|
const enrollmentPlan = await Adapter.transformOrderItemToEnrollmentPlan(orderPosition, unchainedAPI);
|
|
34
24
|
return {
|
|
35
25
|
...doc,
|
|
36
26
|
...enrollmentPlan,
|
|
37
|
-
configuration: [],
|
|
27
|
+
configuration: enrollmentPlan.configuration ?? [],
|
|
38
28
|
};
|
|
39
29
|
},
|
|
40
30
|
actions: async (enrollmentContext, unchainedAPI) => {
|
|
41
31
|
const context = { ...enrollmentContext, ...unchainedAPI };
|
|
42
|
-
const Adapter =
|
|
32
|
+
const Adapter = EnrollmentDirector.findSupportedAdapter(enrollmentContext.product.plan);
|
|
43
33
|
if (!Adapter) {
|
|
44
|
-
throw
|
|
34
|
+
throw createServiceError('EnrollmentPlanNotSupportedError', 'No suitable enrollment plugin available for this plan configuration');
|
|
45
35
|
}
|
|
46
36
|
const adapter = Adapter.actions(context);
|
|
47
37
|
return adapter;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { IFileAdapter, UploadedFile } from '@unchainedshop/core-files';
|
|
2
2
|
export type UploadFileCallback<UnchainedAPI = unknown> = (file: UploadedFile, unchainedAPI: UnchainedAPI) => Promise<void>;
|
|
3
3
|
export declare const FileDirector: {
|
|
4
|
-
getAdapter: (key: string) => IFileAdapter<unknown> | null;
|
|
5
|
-
getAdapters: (options?: {
|
|
6
|
-
adapterFilter?: (adapter: IFileAdapter) => boolean;
|
|
7
|
-
}) => IFileAdapter<unknown>[];
|
|
8
4
|
registerFileUploadCallback<UnchainedAPI>(directoryName: string, fn: UploadFileCallback<UnchainedAPI>): void;
|
|
9
5
|
getFileUploadCallback(directoryName: string): UploadFileCallback<unknown> | null;
|
|
6
|
+
getAdapters: (options?: {
|
|
7
|
+
adapterFilter?: ((adapter: IFileAdapter<unknown>) => boolean) | undefined;
|
|
8
|
+
} | undefined) => IFileAdapter<unknown>[];
|
|
9
|
+
getAdapter: (key: string) => IFileAdapter<unknown> | null;
|
|
10
10
|
};
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
2
1
|
import { FileAdapter } from '@unchainedshop/core-files';
|
|
3
|
-
import {
|
|
2
|
+
import { registryDirector } from "./registryDirector.js";
|
|
4
3
|
const FileUploadRegistry = new Map();
|
|
5
|
-
const baseDirector = BaseDirector('FileDirector');
|
|
6
4
|
export const FileDirector = {
|
|
7
|
-
...
|
|
8
|
-
getAdapter: (key) => {
|
|
9
|
-
const adapters = pluginRegistry.getAdapters(FileAdapter.adapterType);
|
|
10
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
11
|
-
},
|
|
12
|
-
getAdapters: (options) => {
|
|
13
|
-
const { adapterFilter } = options || {};
|
|
14
|
-
const adapters = pluginRegistry.getAdapters(FileAdapter.adapterType);
|
|
15
|
-
return adapters.filter(adapterFilter || (() => true));
|
|
16
|
-
},
|
|
5
|
+
...registryDirector(FileAdapter.adapterType),
|
|
17
6
|
registerFileUploadCallback(directoryName, fn) {
|
|
18
7
|
if (!FileUploadRegistry.has(directoryName)) {
|
|
19
8
|
FileUploadRegistry.set(directoryName, fn);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import type { FilterAdapterActions, FilterContext, IFilterAdapter } from './FilterAdapter.ts';
|
|
3
3
|
import { type Filter, type SearchConfiguration, type SearchFilterQuery, type SearchQuery } from '@unchainedshop/core-filters';
|
|
4
4
|
import type { Modules } from '../modules.ts';
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
2
|
+
import { filterCacheGeneration, filtersSettings, FilterType, } from '@unchainedshop/core-filters';
|
|
3
|
+
import { registryDirector } from "./registryDirector.js";
|
|
5
4
|
import { FilterAdapter } from "./FilterAdapter.js";
|
|
6
5
|
export const parseQueryArray = (query) => (query || []).reduce((accumulator, { key, value }) => ({
|
|
7
6
|
...accumulator,
|
|
8
7
|
[key]: accumulator[key] ? accumulator[key].concat(value) : [value],
|
|
9
8
|
}), {});
|
|
10
|
-
const baseDirector = BaseDirector('FilterDirector', {
|
|
11
|
-
adapterSortKey: 'orderIndex',
|
|
12
|
-
});
|
|
13
9
|
export const FilterDirector = {
|
|
14
|
-
...
|
|
15
|
-
getAdapter: (key) => {
|
|
16
|
-
const adapters = pluginRegistry.getAdapters(FilterAdapter.adapterType);
|
|
17
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
18
|
-
},
|
|
19
|
-
getAdapters: ({ adapterFilter } = {}) => {
|
|
20
|
-
const adapters = pluginRegistry.getAdapters(FilterAdapter.adapterType);
|
|
21
|
-
return adapters.filter(adapterFilter || (() => true));
|
|
22
|
-
},
|
|
10
|
+
...registryDirector(FilterAdapter.adapterType),
|
|
23
11
|
actions: async (filterContext, unchainedAPI) => {
|
|
24
12
|
const context = { ...filterContext, ...unchainedAPI };
|
|
25
13
|
const adapters = FilterDirector.getAdapters().map((Adapter) => Adapter.actions(context));
|
|
@@ -80,18 +68,19 @@ export const FilterDirector = {
|
|
|
80
68
|
},
|
|
81
69
|
async buildProductIdMap(filter, unchainedAPI) {
|
|
82
70
|
const allProductIds = await this.findProductIds(filter, {}, unchainedAPI);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
71
|
+
if (filter.type === FilterType.SWITCH) {
|
|
72
|
+
return [
|
|
73
|
+
allProductIds,
|
|
74
|
+
{
|
|
75
|
+
true: await this.findProductIds(filter, { value: true }, unchainedAPI),
|
|
76
|
+
false: await this.findProductIds(filter, { value: { $in: [null, false] } }, unchainedAPI),
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
const productIdsMap = Object.create(null);
|
|
81
|
+
for (const option of filter.options || []) {
|
|
82
|
+
productIdsMap[option] = await this.findProductIds(filter, { value: option }, unchainedAPI);
|
|
83
|
+
}
|
|
95
84
|
return [allProductIds, productIdsMap];
|
|
96
85
|
},
|
|
97
86
|
async filterProductIds(filter, { values, forceLiveCollection }, unchainedAPI) {
|
|
@@ -102,11 +91,13 @@ export const FilterDirector = {
|
|
|
102
91
|
return new Set(allProductIds);
|
|
103
92
|
const result = new Set();
|
|
104
93
|
for (const key of filteredKeys) {
|
|
94
|
+
if (!Object.hasOwn(keyToProductIdMap, key))
|
|
95
|
+
continue;
|
|
105
96
|
const additionalValues = keyToProductIdMap[key];
|
|
106
|
-
if (additionalValues)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
if (!additionalValues)
|
|
98
|
+
continue;
|
|
99
|
+
for (const val of additionalValues)
|
|
100
|
+
result.add(val);
|
|
110
101
|
}
|
|
111
102
|
return result;
|
|
112
103
|
},
|
|
@@ -175,6 +166,8 @@ export const FilterDirector = {
|
|
|
175
166
|
if (!filter)
|
|
176
167
|
return;
|
|
177
168
|
const [productIds, productIdMap] = await this.buildProductIdMap(filter, unchainedAPI);
|
|
178
|
-
await
|
|
169
|
+
if (!(await unchainedAPI.modules.filters.filterExists({ filterId: filter._id })))
|
|
170
|
+
return;
|
|
171
|
+
await filtersSettings.setCachedProductIds(filter._id, productIds, productIdMap, filterCacheGeneration(filter));
|
|
179
172
|
},
|
|
180
173
|
};
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import type { IDiscountAdapter } from './BaseDiscountAdapter.ts';
|
|
2
1
|
import type { OrderDiscountConfiguration } from './OrderDiscountConfiguration.ts';
|
|
3
|
-
export declare const OrderDiscountDirector:
|
|
4
|
-
getAdapter: (key: string) => IDiscountAdapter<OrderDiscountConfiguration> | null;
|
|
5
|
-
getAdapters: (options?: {
|
|
6
|
-
adapterFilter?: (adapter: any) => boolean;
|
|
7
|
-
}) => IDiscountAdapter<OrderDiscountConfiguration>[];
|
|
8
|
-
actions: (discountContext: import("./BaseDiscountAdapter.ts").DiscountContext, unchainedAPI: {
|
|
9
|
-
modules: import("../modules.ts").Modules;
|
|
10
|
-
}) => Promise<{
|
|
11
|
-
resolveDiscountAdapterFromStaticCode: (params: {
|
|
12
|
-
code: string;
|
|
13
|
-
}) => Promise<IDiscountAdapter<OrderDiscountConfiguration> | null>;
|
|
14
|
-
findSystemDiscounts: () => Promise<string[]>;
|
|
15
|
-
}>;
|
|
16
|
-
};
|
|
2
|
+
export declare const OrderDiscountDirector: import("./BaseDiscountDirector.ts").IDiscountDirector<OrderDiscountConfiguration>;
|
|
@@ -1,15 +1,3 @@
|
|
|
1
1
|
import { BaseDiscountDirector } from "./BaseDiscountDirector.js";
|
|
2
2
|
import { OrderDiscountAdapter } from "./OrderDiscountAdapter.js";
|
|
3
|
-
|
|
4
|
-
const baseDirector = BaseDiscountDirector('OrderDiscountDirector');
|
|
5
|
-
export const OrderDiscountDirector = {
|
|
6
|
-
...baseDirector,
|
|
7
|
-
getAdapter: (key) => {
|
|
8
|
-
const adapters = pluginRegistry.getAdapters(OrderDiscountAdapter.adapterType);
|
|
9
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
10
|
-
},
|
|
11
|
-
getAdapters: (options) => {
|
|
12
|
-
const adapters = pluginRegistry.getAdapters(OrderDiscountAdapter.adapterType);
|
|
13
|
-
return adapters.filter(options?.adapterFilter || (() => true));
|
|
14
|
-
},
|
|
15
|
-
};
|
|
3
|
+
export const OrderDiscountDirector = BaseDiscountDirector(OrderDiscountAdapter.adapterType);
|