@unchainedshop/core 5.0.0-alpha.1 → 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.js +1 -1
- package/lib/bulk-exporter/handlers/exportProductsHandler.js +2 -2
- 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/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/EnrollmentAdapter.js +0 -1
- package/lib/directors/EnrollmentDirector.d.ts +1 -1
- package/lib/directors/EnrollmentDirector.js +3 -15
- 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 +17 -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/ProductDiscountDirector.d.ts +1 -15
- package/lib/directors/ProductDiscountDirector.js +1 -13
- package/lib/directors/ProductPricingDirector.js +1 -10
- 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 +18 -0
- package/lib/factory/registerEnrollment.js +43 -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 +12 -0
- package/lib/factory/registerQuotation.js +52 -0
- package/lib/factory/registerVirtualWarehousing.js +1 -1
- package/lib/factory/registerWorker.js +1 -1
- package/lib/plugins/PluginRegistry.d.ts +1 -0
- package/lib/plugins/PluginRegistry.js +11 -2
- 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/checkoutOrder.js +4 -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/deleteDeadCarts.d.ts +2 -0
- package/lib/services/deleteDeadCarts.js +17 -0
- package/lib/services/deleteUser.js +2 -5
- package/lib/services/index.d.ts +24 -1
- package/lib/services/index.js +24 -1
- package/lib/services/initCartProviders.js +1 -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/processEnrollment.js +2 -1
- package/lib/services/processOrder.js +3 -2
- 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/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/updateCalculation.js +2 -1
- 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 +7 -8
- package/package.json +29 -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
|
},
|
|
@@ -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) {
|
|
@@ -1,4 +1,4 @@
|
|
|
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
4
|
import type { Product } from '@unchainedshop/core-products';
|
|
@@ -1,11 +1,7 @@
|
|
|
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";
|
|
5
4
|
const logger = createLogger('unchained:core');
|
|
6
|
-
const baseDirector = BaseDirector('EnrollmentDirector', {
|
|
7
|
-
adapterSortKey: 'orderIndex',
|
|
8
|
-
});
|
|
9
5
|
const findAppropriateAdapters = (productPlan) => EnrollmentDirector.getAdapters({
|
|
10
6
|
adapterFilter: (Adapter) => {
|
|
11
7
|
const activated = Adapter.isActivatedFor(productPlan);
|
|
@@ -16,15 +12,7 @@ const findAppropriateAdapters = (productPlan) => EnrollmentDirector.getAdapters(
|
|
|
16
12
|
},
|
|
17
13
|
});
|
|
18
14
|
export const EnrollmentDirector = {
|
|
19
|
-
...
|
|
20
|
-
getAdapter: (key) => {
|
|
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
|
-
},
|
|
15
|
+
...registryDirector(EnrollmentAdapter.adapterType),
|
|
28
16
|
transformOrderItemToEnrollment: async ({ orderPosition, product }, doc, unchainedAPI) => {
|
|
29
17
|
const Adapter = findAppropriateAdapters(product.plan)?.[0];
|
|
30
18
|
if (!Adapter) {
|
|
@@ -34,7 +22,7 @@ export const EnrollmentDirector = {
|
|
|
34
22
|
return {
|
|
35
23
|
...doc,
|
|
36
24
|
...enrollmentPlan,
|
|
37
|
-
configuration: [],
|
|
25
|
+
configuration: enrollmentPlan.configuration ?? [],
|
|
38
26
|
};
|
|
39
27
|
},
|
|
40
28
|
actions: async (enrollmentContext, unchainedAPI) => {
|
|
@@ -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);
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { OrderPricingSheet, } from "./OrderPricingSheet.js";
|
|
2
2
|
import { OrderPricingAdapter, } from "./OrderPricingAdapter.js";
|
|
3
3
|
import { BasePricingDirector } from "./BasePricingDirector.js";
|
|
4
|
-
|
|
5
|
-
const baseDirector = BasePricingDirector('OrderPricingDirector');
|
|
4
|
+
const baseDirector = BasePricingDirector(OrderPricingAdapter.adapterType);
|
|
6
5
|
export const OrderPricingDirector = {
|
|
7
6
|
...baseDirector,
|
|
8
|
-
getAdapter: (key) => {
|
|
9
|
-
const adapters = pluginRegistry.getAdapters(OrderPricingAdapter.adapterType);
|
|
10
|
-
return adapters.find((adapter) => adapter.key === key) || null;
|
|
11
|
-
},
|
|
12
|
-
getAdapters: ({ adapterFilter } = {}) => {
|
|
13
|
-
const adapters = pluginRegistry.getAdapters(OrderPricingAdapter.adapterType);
|
|
14
|
-
return adapters.filter(adapterFilter || (() => true));
|
|
15
|
-
},
|
|
16
7
|
buildPricingContext: async (context, unchainedAPI) => {
|
|
17
8
|
const { modules } = unchainedAPI;
|
|
18
9
|
const { order, currencyCode } = context;
|
|
@@ -33,5 +33,6 @@ export interface IOrderPricingSheet extends IPricingSheet<OrderPricingCalculatio
|
|
|
33
33
|
taxAmount: number;
|
|
34
34
|
meta?: any;
|
|
35
35
|
}) => void;
|
|
36
|
+
discountSum: (discountId?: string) => number;
|
|
36
37
|
}
|
|
37
38
|
export declare const OrderPricingSheet: (params: PricingSheetParams<OrderPricingCalculation>) => IOrderPricingSheet;
|
|
@@ -15,6 +15,7 @@ export const OrderPricingSheet = (params) => {
|
|
|
15
15
|
amount: taxAmount,
|
|
16
16
|
baseCategory: category,
|
|
17
17
|
discountId,
|
|
18
|
+
isNetPrice: false,
|
|
18
19
|
meta,
|
|
19
20
|
});
|
|
20
21
|
}
|
|
@@ -25,6 +26,7 @@ export const OrderPricingSheet = (params) => {
|
|
|
25
26
|
basePricingSheet.calculation.push({
|
|
26
27
|
category: OrderPricingRowCategory.Items,
|
|
27
28
|
amount,
|
|
29
|
+
isNetPrice: true,
|
|
28
30
|
meta,
|
|
29
31
|
});
|
|
30
32
|
addTaxIfAvailabile(OrderPricingRowCategory.Items, taxAmount, meta);
|
|
@@ -34,6 +36,7 @@ export const OrderPricingSheet = (params) => {
|
|
|
34
36
|
category: OrderPricingRowCategory.Discounts,
|
|
35
37
|
amount,
|
|
36
38
|
discountId,
|
|
39
|
+
isNetPrice: true,
|
|
37
40
|
meta,
|
|
38
41
|
});
|
|
39
42
|
addTaxIfAvailabile(OrderPricingRowCategory.Discounts, taxAmount, meta, discountId);
|
|
@@ -42,6 +45,7 @@ export const OrderPricingSheet = (params) => {
|
|
|
42
45
|
basePricingSheet.calculation.push({
|
|
43
46
|
category: OrderPricingRowCategory.Delivery,
|
|
44
47
|
amount,
|
|
48
|
+
isNetPrice: true,
|
|
45
49
|
meta,
|
|
46
50
|
});
|
|
47
51
|
addTaxIfAvailabile(OrderPricingRowCategory.Delivery, taxAmount, meta);
|
|
@@ -50,6 +54,7 @@ export const OrderPricingSheet = (params) => {
|
|
|
50
54
|
basePricingSheet.calculation.push({
|
|
51
55
|
category: OrderPricingRowCategory.Payment,
|
|
52
56
|
amount,
|
|
57
|
+
isNetPrice: true,
|
|
53
58
|
meta,
|
|
54
59
|
});
|
|
55
60
|
addTaxIfAvailabile(OrderPricingRowCategory.Payment, taxAmount, meta);
|
|
@@ -60,20 +65,11 @@ export const OrderPricingSheet = (params) => {
|
|
|
60
65
|
...(filter || {}),
|
|
61
66
|
});
|
|
62
67
|
},
|
|
63
|
-
|
|
64
|
-
return basePricingSheet.sum(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
total({ category, useNetPrice, discountId } = { useNetPrice: false }) {
|
|
70
|
-
const taxAmount = this.taxSum({ baseCategory: category, discountId });
|
|
71
|
-
const amount = this.sum({ category, discountId }) - taxAmount;
|
|
72
|
-
const netAmount = !category ? amount - taxAmount : amount;
|
|
73
|
-
return {
|
|
74
|
-
amount: Math.round(useNetPrice ? netAmount : netAmount + taxAmount),
|
|
75
|
-
currencyCode: this.currencyCode,
|
|
76
|
-
};
|
|
68
|
+
discountSum(discountId) {
|
|
69
|
+
return basePricingSheet.sum({
|
|
70
|
+
category: OrderPricingRowCategory.Discounts,
|
|
71
|
+
discountId,
|
|
72
|
+
});
|
|
77
73
|
},
|
|
78
74
|
discountPrices(explicitDiscountId) {
|
|
79
75
|
const discountIds = pricingSheet
|
|
@@ -85,17 +81,21 @@ export const OrderPricingSheet = (params) => {
|
|
|
85
81
|
.filter(Boolean);
|
|
86
82
|
return [...new Set(discountIds)]
|
|
87
83
|
.map((discountId) => {
|
|
88
|
-
const amount =
|
|
84
|
+
const amount = pricingSheet.sum({
|
|
89
85
|
category: OrderPricingRowCategory.Discounts,
|
|
90
86
|
discountId,
|
|
91
|
-
})
|
|
87
|
+
}) +
|
|
88
|
+
pricingSheet.taxSum({
|
|
89
|
+
baseCategory: OrderPricingRowCategory.Discounts,
|
|
90
|
+
discountId,
|
|
91
|
+
});
|
|
92
92
|
if (!amount) {
|
|
93
93
|
return null;
|
|
94
94
|
}
|
|
95
95
|
return {
|
|
96
96
|
discountId,
|
|
97
97
|
amount: Math.round(amount),
|
|
98
|
-
currencyCode:
|
|
98
|
+
currencyCode: pricingSheet.currencyCode,
|
|
99
99
|
};
|
|
100
100
|
})
|
|
101
101
|
.filter(Boolean);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import { type IPaymentActions, type IPaymentAdapter, type PaymentContext } from './PaymentAdapter.ts';
|
|
3
3
|
import type { PaymentProvider } from '@unchainedshop/core-payment';
|
|
4
4
|
import { type Order, type OrderPayment } from '@unchainedshop/core-orders';
|