@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
|
@@ -18,12 +18,12 @@ export const periodForReferenceDate = (referenceDate, intervalCount = 1, interva
|
|
|
18
18
|
};
|
|
19
19
|
export const EnrollmentAdapter = {
|
|
20
20
|
...BaseAdapter,
|
|
21
|
+
adapterType: Symbol.for('unchained:adapter:enrollment'),
|
|
21
22
|
isActivatedFor: () => {
|
|
22
23
|
return false;
|
|
23
24
|
},
|
|
24
25
|
transformOrderItemToEnrollmentPlan: async (item) => {
|
|
25
26
|
return {
|
|
26
|
-
configuration: item.configuration,
|
|
27
27
|
productId: item.productId,
|
|
28
28
|
quantity: item.quantity,
|
|
29
29
|
};
|
|
@@ -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,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnrollmentAdapter } from "./EnrollmentAdapter.js";
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import { registryDirector } from "./registryDirector.js";
|
|
3
4
|
const logger = createLogger('unchained:core');
|
|
4
|
-
const
|
|
5
|
-
adapterSortKey: 'orderIndex',
|
|
6
|
-
});
|
|
7
|
-
const findAppropriateAdapters = (productPlan) => baseDirector.getAdapters({
|
|
5
|
+
const findAppropriateAdapters = (productPlan) => EnrollmentDirector.getAdapters({
|
|
8
6
|
adapterFilter: (Adapter) => {
|
|
9
7
|
const activated = Adapter.isActivatedFor(productPlan);
|
|
10
8
|
if (!activated) {
|
|
@@ -14,7 +12,7 @@ const findAppropriateAdapters = (productPlan) => baseDirector.getAdapters({
|
|
|
14
12
|
},
|
|
15
13
|
});
|
|
16
14
|
export const EnrollmentDirector = {
|
|
17
|
-
...
|
|
15
|
+
...registryDirector(EnrollmentAdapter.adapterType),
|
|
18
16
|
transformOrderItemToEnrollment: async ({ orderPosition, product }, doc, unchainedAPI) => {
|
|
19
17
|
const Adapter = findAppropriateAdapters(product.plan)?.[0];
|
|
20
18
|
if (!Adapter) {
|
|
@@ -24,7 +22,7 @@ export const EnrollmentDirector = {
|
|
|
24
22
|
return {
|
|
25
23
|
...doc,
|
|
26
24
|
...enrollmentPlan,
|
|
27
|
-
configuration: [],
|
|
25
|
+
configuration: enrollmentPlan.configuration ?? [],
|
|
28
26
|
};
|
|
29
27
|
},
|
|
30
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,18 +1,16 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
3
2
|
import { filterCacheGeneration, filtersSettings, FilterType, } from '@unchainedshop/core-filters';
|
|
3
|
+
import { registryDirector } from "./registryDirector.js";
|
|
4
|
+
import { FilterAdapter } from "./FilterAdapter.js";
|
|
4
5
|
export const parseQueryArray = (query) => (query || []).reduce((accumulator, { key, value }) => ({
|
|
5
6
|
...accumulator,
|
|
6
7
|
[key]: accumulator[key] ? accumulator[key].concat(value) : [value],
|
|
7
8
|
}), {});
|
|
8
|
-
const baseDirector = BaseDirector('FilterDirector', {
|
|
9
|
-
adapterSortKey: 'orderIndex',
|
|
10
|
-
});
|
|
11
9
|
export const FilterDirector = {
|
|
12
|
-
...
|
|
10
|
+
...registryDirector(FilterAdapter.adapterType),
|
|
13
11
|
actions: async (filterContext, unchainedAPI) => {
|
|
14
12
|
const context = { ...filterContext, ...unchainedAPI };
|
|
15
|
-
const adapters =
|
|
13
|
+
const adapters = FilterDirector.getAdapters().map((Adapter) => Adapter.actions(context));
|
|
16
14
|
const reduceAdapters = (reducer, initialValue) => {
|
|
17
15
|
if (adapters.length === 0) {
|
|
18
16
|
return initialValue;
|
|
@@ -116,7 +114,7 @@ export const FilterDirector = {
|
|
|
116
114
|
includeInactive: true,
|
|
117
115
|
})
|
|
118
116
|
: [];
|
|
119
|
-
const
|
|
117
|
+
const intersectedProductIds = await filters.reduce(async (productIdSetPromise, filter) => {
|
|
120
118
|
const productIdSet = await productIdSetPromise;
|
|
121
119
|
if (!parsedFilterQuery[filter.key])
|
|
122
120
|
return productIdSet;
|
|
@@ -127,7 +125,7 @@ export const FilterDirector = {
|
|
|
127
125
|
}, unchainedAPI);
|
|
128
126
|
return productIdSet.intersection(filterOptionProductIds);
|
|
129
127
|
}, Promise.resolve(new Set(productIds)));
|
|
130
|
-
return
|
|
128
|
+
return [...intersectedProductIds];
|
|
131
129
|
},
|
|
132
130
|
async filterFacets(filter, params, unchainedAPI) {
|
|
133
131
|
const { allProductIdSet, searchQuery, forceLiveCollection, otherFilters } = params;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { type IDiscountAdapter
|
|
2
|
-
|
|
1
|
+
import { type IDiscountAdapter } from './BaseDiscountAdapter.ts';
|
|
2
|
+
import type { OrderDiscountConfiguration } from './OrderDiscountConfiguration.ts';
|
|
3
|
+
export declare const OrderDiscountAdapter: Omit<IDiscountAdapter<OrderDiscountConfiguration>, 'key' | 'label' | 'version'>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { BaseDiscountAdapter
|
|
2
|
-
export const OrderDiscountAdapter =
|
|
1
|
+
import { BaseDiscountAdapter } from "./BaseDiscountAdapter.js";
|
|
2
|
+
export const OrderDiscountAdapter = {
|
|
3
|
+
...BaseDiscountAdapter,
|
|
4
|
+
adapterType: Symbol.for('unchained:adapter:discount:order'),
|
|
5
|
+
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { BaseDiscountDirector } from "./BaseDiscountDirector.js";
|
|
2
|
-
|
|
2
|
+
import { OrderDiscountAdapter } from "./OrderDiscountAdapter.js";
|
|
3
|
+
export const OrderDiscountDirector = BaseDiscountDirector(OrderDiscountAdapter.adapterType);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type IOrderPricingSheet, type OrderPricingCalculation
|
|
1
|
+
import { type IOrderPricingSheet, type OrderPricingCalculation } from './OrderPricingSheet.ts';
|
|
2
|
+
import { type IPricingAdapter, type BasePricingAdapterContext } from './BasePricingAdapter.ts';
|
|
2
3
|
import type { Order, OrderDelivery, OrderDiscount, OrderPayment, OrderPosition } from '@unchainedshop/core-orders';
|
|
3
4
|
import type { User } from '@unchainedshop/core-users';
|
|
4
5
|
import type { Modules } from '../modules.ts';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { OrderPricingSheet,
|
|
1
|
+
import { OrderPricingSheet, } from "./OrderPricingSheet.js";
|
|
2
|
+
import { BasePricingAdapter, } from "./BasePricingAdapter.js";
|
|
2
3
|
const basePricingAdapter = BasePricingAdapter();
|
|
3
4
|
export const OrderPricingAdapter = {
|
|
4
5
|
...basePricingAdapter,
|
|
6
|
+
adapterType: Symbol.for('unchained:adapter:pricing:order'),
|
|
5
7
|
isActivatedFor: () => {
|
|
6
8
|
return false;
|
|
7
9
|
},
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { type IOrderPricingSheet, type OrderPricingCalculation
|
|
1
|
+
import { type IOrderPricingSheet, type OrderPricingCalculation } from './OrderPricingSheet.ts';
|
|
2
|
+
import { type IOrderPricingAdapter, type OrderPricingAdapterContext } from './OrderPricingAdapter.ts';
|
|
3
|
+
import { type IPricingDirector } from './BasePricingDirector.ts';
|
|
4
|
+
import type { PricingDiscount } from './BasePricingSheet.ts';
|
|
2
5
|
import type { Order, OrderDelivery, OrderPayment, OrderPosition } from '@unchainedshop/core-orders';
|
|
3
6
|
export interface OrderPricingContext {
|
|
4
7
|
currencyCode: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { OrderPricingSheet,
|
|
2
|
-
|
|
1
|
+
import { OrderPricingSheet, } from "./OrderPricingSheet.js";
|
|
2
|
+
import { OrderPricingAdapter, } from "./OrderPricingAdapter.js";
|
|
3
|
+
import { BasePricingDirector } from "./BasePricingDirector.js";
|
|
4
|
+
const baseDirector = BasePricingDirector(OrderPricingAdapter.adapterType);
|
|
3
5
|
export const OrderPricingDirector = {
|
|
4
6
|
...baseDirector,
|
|
5
7
|
buildPricingContext: async (context, unchainedAPI) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
2
|
-
import { type IPricingSheet, type PricingSheetParams } from '
|
|
2
|
+
import { type IPricingSheet, type PricingSheetParams } from './BasePricingSheet.ts';
|
|
3
3
|
export interface OrderPricingCalculation extends PricingCalculation {
|
|
4
4
|
discountId?: string;
|
|
5
5
|
}
|
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePricingSheet, } from "
|
|
1
|
+
import { BasePricingSheet, } from "./BasePricingSheet.js";
|
|
2
2
|
export const OrderPricingRowCategory = {
|
|
3
3
|
Items: 'ITEMS',
|
|
4
4
|
Discounts: 'DISCOUNTS',
|
|
@@ -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';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
2
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
import { PaymentError, } from "./PaymentAdapter.js";
|
|
2
|
+
import { PaymentError, PaymentAdapter, } from "./PaymentAdapter.js";
|
|
4
3
|
import { OrderPaymentStatus } from '@unchainedshop/core-orders';
|
|
4
|
+
import { registryDirector } from "./registryDirector.js";
|
|
5
5
|
const buildPaymentProviderActionsContext = (orderPayment, { transactionContext, ...rest }) => ({
|
|
6
6
|
...rest,
|
|
7
7
|
orderPayment,
|
|
@@ -11,11 +11,10 @@ const buildPaymentProviderActionsContext = (orderPayment, { transactionContext,
|
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
13
|
const logger = createLogger('unchained:core:payment');
|
|
14
|
-
const baseDirector = BaseDirector('PaymentDirector');
|
|
15
14
|
export const PaymentDirector = {
|
|
16
|
-
...
|
|
15
|
+
...registryDirector(PaymentAdapter.adapterType),
|
|
17
16
|
actions: async (paymentProvider, paymentContext, unchainedAPI) => {
|
|
18
|
-
const Adapter =
|
|
17
|
+
const Adapter = PaymentDirector.getAdapter(paymentProvider.adapterKey);
|
|
19
18
|
if (!Adapter) {
|
|
20
19
|
throw new Error(`Payment Plugin ${paymentProvider.adapterKey} not available`);
|
|
21
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
2
|
-
import { type BasePricingAdapterContext, type IPricingAdapter
|
|
2
|
+
import { type BasePricingAdapterContext, type IPricingAdapter } from './BasePricingAdapter.ts';
|
|
3
|
+
import type { IPricingSheet } from './BasePricingSheet.ts';
|
|
3
4
|
import type { PaymentProvider } from '@unchainedshop/core-payment';
|
|
4
5
|
import type { OrderDiscount, OrderPayment, Order } from '@unchainedshop/core-orders';
|
|
5
6
|
import type { User } from '@unchainedshop/core-users';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BasePricingAdapter, } from "
|
|
1
|
+
import { BasePricingAdapter, } from "./BasePricingAdapter.js";
|
|
2
2
|
import { PaymentPricingSheet } from "./PaymentPricingSheet.js";
|
|
3
3
|
const basePricingAdapter = BasePricingAdapter();
|
|
4
4
|
export const PaymentPricingAdapter = {
|
|
5
5
|
...basePricingAdapter,
|
|
6
|
+
adapterType: Symbol.for('unchained:adapter:pricing:payment'),
|
|
6
7
|
isActivatedFor: () => {
|
|
7
8
|
return false;
|
|
8
9
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type IPricingDirector
|
|
1
|
+
import { type IPricingDirector } from './BasePricingDirector.ts';
|
|
2
|
+
import { type IPaymentPricingAdapter, type IPaymentPricingSheet, type PaymentPricingAdapterContext, type PaymentPricingCalculation } from './PaymentPricingAdapter.ts';
|
|
2
3
|
import type { PaymentProvider } from '@unchainedshop/core-payment';
|
|
3
4
|
import type { OrderPayment, Order } from '@unchainedshop/core-orders';
|
|
4
5
|
import type { User } from '@unchainedshop/core-users';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BasePricingDirector
|
|
1
|
+
import { BasePricingDirector } from "./BasePricingDirector.js";
|
|
2
|
+
import { PaymentPricingAdapter, } from "./PaymentPricingAdapter.js";
|
|
2
3
|
import { PaymentPricingSheet } from "./PaymentPricingSheet.js";
|
|
3
|
-
const baseDirector = BasePricingDirector(
|
|
4
|
+
const baseDirector = BasePricingDirector(PaymentPricingAdapter.adapterType);
|
|
4
5
|
export const PaymentPricingDirector = {
|
|
5
6
|
...baseDirector,
|
|
6
7
|
async buildPricingContext(context, unchainedAPI) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type PaymentPricingCalculation, type IPaymentPricingSheet
|
|
1
|
+
import { type PaymentPricingCalculation, type IPaymentPricingSheet } from './PaymentPricingAdapter.ts';
|
|
2
|
+
import { type PricingSheetParams } from './BasePricingSheet.ts';
|
|
2
3
|
export declare const PaymentPricingRowCategory: {
|
|
3
4
|
readonly Item: "ITEM";
|
|
4
5
|
readonly Payment: "PAYMENT";
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { type IDiscountAdapter
|
|
2
|
-
|
|
1
|
+
import { type IDiscountAdapter } from './BaseDiscountAdapter.ts';
|
|
2
|
+
import type { ProductDiscountConfiguration } from './ProductDiscountConfiguration.ts';
|
|
3
|
+
export declare const ProductDiscountAdapter: Omit<IDiscountAdapter<ProductDiscountConfiguration>, 'key' | 'label' | 'version'>;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import { BaseDiscountAdapter
|
|
2
|
-
export const ProductDiscountAdapter =
|
|
1
|
+
import { BaseDiscountAdapter } from "./BaseDiscountAdapter.js";
|
|
2
|
+
export const ProductDiscountAdapter = {
|
|
3
|
+
...BaseDiscountAdapter,
|
|
4
|
+
adapterType: Symbol.for('unchained:adapter:discount:product'),
|
|
5
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ProductDiscountConfiguration } from './ProductDiscountConfiguration.ts';
|
|
2
2
|
export declare const ProductDiscountDirector: import("./BaseDiscountDirector.ts").IDiscountDirector<ProductDiscountConfiguration>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { BaseDiscountDirector } from "
|
|
2
|
-
|
|
1
|
+
import { BaseDiscountDirector } from "./BaseDiscountDirector.js";
|
|
2
|
+
import { ProductDiscountAdapter } from "./ProductDiscountAdapter.js";
|
|
3
|
+
export const ProductDiscountDirector = BaseDiscountDirector(ProductDiscountAdapter.adapterType);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Product, ProductConfiguration } from '@unchainedshop/core-products';
|
|
2
2
|
import type { Order } from '@unchainedshop/core-orders';
|
|
3
|
-
import { type IProductPricingSheet, type ProductPricingCalculation
|
|
3
|
+
import { type IProductPricingSheet, type ProductPricingCalculation } from './ProductPricingSheet.ts';
|
|
4
|
+
import { type BasePricingAdapterContext, type IPricingAdapter } from './BasePricingAdapter.ts';
|
|
4
5
|
import type { Modules } from '../modules.ts';
|
|
5
6
|
import type { User } from '@unchainedshop/core-users';
|
|
6
7
|
export interface ProductPricingAdapterContext extends BasePricingAdapterContext {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ProductPricingSheet,
|
|
1
|
+
import { ProductPricingSheet, } from "./ProductPricingSheet.js";
|
|
2
|
+
import { BasePricingAdapter, } from "./BasePricingAdapter.js";
|
|
2
3
|
const basePricingAdapter = BasePricingAdapter();
|
|
3
4
|
export const ProductPricingAdapter = {
|
|
4
5
|
...basePricingAdapter,
|
|
6
|
+
adapterType: Symbol.for('unchained:adapter:pricing:product'),
|
|
5
7
|
isActivatedFor: () => {
|
|
6
8
|
return false;
|
|
7
9
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Product, ProductConfiguration } from '@unchainedshop/core-products';
|
|
2
2
|
import type { User } from '@unchainedshop/core-users';
|
|
3
3
|
import type { Order, OrderDiscount, OrderPosition } from '@unchainedshop/core-orders';
|
|
4
|
-
import { type IProductPricingSheet, type ProductPricingCalculation
|
|
4
|
+
import { type IProductPricingSheet, type ProductPricingCalculation } from './ProductPricingSheet.ts';
|
|
5
|
+
import { type IProductPricingAdapter, type ProductPricingAdapterContext } from './ProductPricingAdapter.ts';
|
|
6
|
+
import { type IPricingDirector } from './BasePricingDirector.ts';
|
|
5
7
|
export type ProductPricingContext = {
|
|
6
8
|
currencyCode: string;
|
|
7
9
|
countryCode: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ProductPricingSheet,
|
|
2
|
-
|
|
1
|
+
import { ProductPricingSheet, } from "./ProductPricingSheet.js";
|
|
2
|
+
import { ProductPricingAdapter, } from "./ProductPricingAdapter.js";
|
|
3
|
+
import { BasePricingDirector } from "./BasePricingDirector.js";
|
|
4
|
+
const baseDirector = BasePricingDirector(ProductPricingAdapter.adapterType);
|
|
3
5
|
export const ProductPricingDirector = {
|
|
4
6
|
...baseDirector,
|
|
5
7
|
async buildPricingContext(context, unchainedAPI) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Price, PricingCalculation } from '@unchainedshop/utils';
|
|
2
|
-
import { type IPricingSheet, type PricingSheetParams } from '
|
|
2
|
+
import { type IPricingSheet, type PricingSheetParams } from './BasePricingSheet.ts';
|
|
3
3
|
export interface ProductPricingCalculation extends PricingCalculation {
|
|
4
4
|
discountId?: string;
|
|
5
5
|
isTaxable: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import { type IQuotationAdapter, type QuotationAdapterActions, type QuotationContext } from './QuotationAdapter.ts';
|
|
3
3
|
export type IQuotationDirector = IBaseDirector<IQuotationAdapter> & {
|
|
4
4
|
actions: (quotationContext: QuotationContext, unchainedAPI: any) => Promise<QuotationAdapterActions>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { QuotationError, } from "./QuotationAdapter.js";
|
|
1
|
+
import { QuotationError, QuotationAdapter, } from "./QuotationAdapter.js";
|
|
3
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import { registryDirector } from "./registryDirector.js";
|
|
4
4
|
const logger = createLogger('unchained:core');
|
|
5
|
-
const
|
|
6
|
-
adapterSortKey: 'orderIndex',
|
|
7
|
-
});
|
|
8
|
-
const findAppropriateAdapters = (quotationContext, unchainedAPI) => baseDirector.getAdapters({
|
|
5
|
+
const findAppropriateAdapters = (quotationContext, unchainedAPI) => QuotationDirector.getAdapters({
|
|
9
6
|
adapterFilter: (Adapter) => {
|
|
10
7
|
const activated = Adapter.isActivatedFor(quotationContext, unchainedAPI);
|
|
11
8
|
if (!activated) {
|
|
@@ -15,7 +12,7 @@ const findAppropriateAdapters = (quotationContext, unchainedAPI) => baseDirector
|
|
|
15
12
|
},
|
|
16
13
|
});
|
|
17
14
|
export const QuotationDirector = {
|
|
18
|
-
...
|
|
15
|
+
...registryDirector(QuotationAdapter.adapterType),
|
|
19
16
|
actions: async (quotationContext, unchainedAPI) => {
|
|
20
17
|
const context = { ...quotationContext, ...unchainedAPI };
|
|
21
18
|
const Adapter = findAppropriateAdapters(quotationContext, unchainedAPI)?.shift();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import type { WarehousingProvider, TokenSurrogate } from '@unchainedshop/core-warehousing';
|
|
3
|
-
import { type IWarehousingAdapter, type WarehousingContext, WarehousingError } from '
|
|
3
|
+
import { type IWarehousingAdapter, type WarehousingContext, WarehousingError } from './WarehousingAdapter.ts';
|
|
4
4
|
import type { Modules } from '../modules.ts';
|
|
5
5
|
export interface EstimatedDispatch {
|
|
6
6
|
shipping?: Date;
|