@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
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { BaseDirector } from '@unchainedshop/utils';
|
|
2
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
2
|
const logger = createLogger('unchained:core');
|
|
4
|
-
import { DeliveryDirector
|
|
3
|
+
import { DeliveryDirector } from "./DeliveryDirector.js";
|
|
4
|
+
import { WarehousingError, WarehousingAdapter, } from "./WarehousingAdapter.js";
|
|
5
|
+
import { registryDirector } from "./registryDirector.js";
|
|
5
6
|
const getReferenceDate = (context) => {
|
|
6
7
|
return context && context.referenceDate ? context.referenceDate : new Date();
|
|
7
8
|
};
|
|
8
|
-
const baseDirector = BaseDirector('WarehousingDirector', {
|
|
9
|
-
adapterSortKey: 'orderIndex',
|
|
10
|
-
});
|
|
11
9
|
export const WarehousingDirector = {
|
|
12
|
-
...
|
|
10
|
+
...registryDirector(WarehousingAdapter.adapterType),
|
|
13
11
|
actions: async (warehousingProvider, warehousingContext, unchainedAPI) => {
|
|
14
|
-
const Adapter =
|
|
12
|
+
const Adapter = WarehousingDirector.getAdapter(warehousingProvider.adapterKey);
|
|
15
13
|
if (!Adapter) {
|
|
16
14
|
throw new Error(`Warehousing Plugin ${warehousingProvider.adapterKey} not available`);
|
|
17
15
|
}
|
|
@@ -135,29 +133,23 @@ export const WarehousingDirector = {
|
|
|
135
133
|
};
|
|
136
134
|
},
|
|
137
135
|
async tokenMetadata(virtualProviders, warehousingContext, unchainedAPI) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (last)
|
|
141
|
-
return last;
|
|
142
|
-
const currentDirector = await WarehousingDirector.actions(provider, warehousingContext, unchainedAPI);
|
|
143
|
-
const isActive = await currentDirector.isActive();
|
|
144
|
-
if (isActive) {
|
|
145
|
-
return currentDirector.tokenMetadata(warehousingContext.token.tokenSerialNumber);
|
|
146
|
-
}
|
|
136
|
+
const activeActions = await findFirstActiveActions(virtualProviders, warehousingContext, unchainedAPI);
|
|
137
|
+
if (!activeActions)
|
|
147
138
|
return null;
|
|
148
|
-
|
|
139
|
+
return activeActions.tokenMetadata(warehousingContext.token.tokenSerialNumber);
|
|
149
140
|
},
|
|
150
141
|
async isInvalidateable(virtualProviders, warehousingContext, unchainedAPI) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (last)
|
|
154
|
-
return last;
|
|
155
|
-
const currentDirector = await WarehousingDirector.actions(provider, warehousingContext, unchainedAPI);
|
|
156
|
-
const isActive = await currentDirector.isActive();
|
|
157
|
-
if (isActive) {
|
|
158
|
-
return currentDirector.isInvalidateable(warehousingContext.token.tokenSerialNumber);
|
|
159
|
-
}
|
|
142
|
+
const activeActions = await findFirstActiveActions(virtualProviders, warehousingContext, unchainedAPI);
|
|
143
|
+
if (!activeActions)
|
|
160
144
|
return null;
|
|
161
|
-
|
|
145
|
+
return activeActions.isInvalidateable(warehousingContext.token.tokenSerialNumber);
|
|
162
146
|
},
|
|
163
147
|
};
|
|
148
|
+
async function findFirstActiveActions(virtualProviders, warehousingContext, unchainedAPI) {
|
|
149
|
+
for (const provider of virtualProviders) {
|
|
150
|
+
const currentActions = await WarehousingDirector.actions(provider, warehousingContext, unchainedAPI);
|
|
151
|
+
if (currentActions.isActive())
|
|
152
|
+
return currentActions;
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Work, WorkData, WorkResult } from '@unchainedshop/core-worker';
|
|
2
|
-
import {
|
|
2
|
+
import type { IBaseDirector } from '@unchainedshop/utils';
|
|
3
3
|
import type { ScheduleData } from '../utils/schedule.ts';
|
|
4
|
-
import type
|
|
4
|
+
import { type IWorkerAdapter } from './WorkerAdapter.ts';
|
|
5
5
|
import type { Modules } from '../modules.ts';
|
|
6
6
|
export type WorkScheduleConfiguration = Pick<WorkData, 'timeout' | 'retries' | 'priority' | 'worker' | 'scheduleId'> & {
|
|
7
7
|
type: string;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkerAdapter } from "./WorkerAdapter.js";
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import { registryDirector } from "./registryDirector.js";
|
|
3
4
|
const logger = createLogger('unchained:core');
|
|
4
5
|
const AutoScheduleMap = new Map();
|
|
5
|
-
const baseDirector = BaseDirector('WorkerDirector', {
|
|
6
|
-
adapterKeyField: 'key',
|
|
7
|
-
});
|
|
8
6
|
export const WorkerDirector = {
|
|
9
|
-
...
|
|
7
|
+
...registryDirector(WorkerAdapter.adapterType),
|
|
10
8
|
getActivePluginTypes: ({ external } = {}) => {
|
|
11
9
|
return WorkerDirector.getAdapters()
|
|
12
10
|
.filter((adapter) => {
|
|
@@ -16,26 +14,9 @@ export const WorkerDirector = {
|
|
|
16
14
|
})
|
|
17
15
|
.map((adapter) => adapter.type);
|
|
18
16
|
},
|
|
19
|
-
registerAdapter: (Adapter) => {
|
|
20
|
-
if (WorkerDirector.getAdapterByType(Adapter.type))
|
|
21
|
-
throw new Error(`WorkerDirector: There is already a adapter registered with type: ${Adapter.type}`);
|
|
22
|
-
baseDirector.registerAdapter(Adapter);
|
|
23
|
-
},
|
|
24
17
|
disableAutoscheduling: (type) => {
|
|
25
18
|
AutoScheduleMap.delete(type);
|
|
26
19
|
},
|
|
27
|
-
unregisterAdapter: (key) => {
|
|
28
|
-
const adapter = WorkerDirector.getAdapter(key);
|
|
29
|
-
const result = baseDirector.unregisterAdapter(key);
|
|
30
|
-
if (adapter) {
|
|
31
|
-
AutoScheduleMap.forEach((workItemConfiguration, scheduleId) => {
|
|
32
|
-
if (workItemConfiguration.type === adapter.type) {
|
|
33
|
-
AutoScheduleMap.delete(scheduleId);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
},
|
|
39
20
|
configureAutoscheduling: (workItemConfiguration) => {
|
|
40
21
|
AutoScheduleMap.set(workItemConfiguration.scheduleId || workItemConfiguration.type, workItemConfiguration);
|
|
41
22
|
},
|
package/lib/directors/index.d.ts
CHANGED
|
@@ -39,4 +39,6 @@ export * from './FailedRescheduler.ts';
|
|
|
39
39
|
export * from './BaseWorker.ts';
|
|
40
40
|
export * from './QuotationAdapter.ts';
|
|
41
41
|
export * from './QuotationDirector.ts';
|
|
42
|
+
export * from './FileDirector.ts';
|
|
43
|
+
export { type IFileAdapter, FileAdapter } from '@unchainedshop/core-files';
|
|
42
44
|
export * from './MessagingDirector.ts';
|
package/lib/directors/index.js
CHANGED
|
@@ -39,4 +39,6 @@ export * from "./FailedRescheduler.js";
|
|
|
39
39
|
export * from "./BaseWorker.js";
|
|
40
40
|
export * from "./QuotationAdapter.js";
|
|
41
41
|
export * from "./QuotationDirector.js";
|
|
42
|
+
export * from "./FileDirector.js";
|
|
43
|
+
export { FileAdapter } from '@unchainedshop/core-files';
|
|
42
44
|
export * from "./MessagingDirector.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
2
|
+
export const registryDirector = (adapterType) => ({
|
|
3
|
+
getAdapter: (key) => pluginRegistry.getAdapters(adapterType).find((adapter) => adapter.key === key) ||
|
|
4
|
+
null,
|
|
5
|
+
getAdapters: ({ adapterFilter } = {}) => pluginRegistry.getAdapters(adapterType).filter(adapterFilter || (() => true)),
|
|
6
|
+
});
|
package/lib/factory/index.d.ts
CHANGED
|
@@ -7,4 +7,15 @@ import registerVirtualWarehousing from './registerVirtualWarehousing.ts';
|
|
|
7
7
|
import registerProductSearchFilter from './registerProductSearchFilter.ts';
|
|
8
8
|
import registerAssortmentSearchFilter from './registerAssortmentSearchFilter.ts';
|
|
9
9
|
import registerInvoicePayment from './registerInvoicePayment.ts';
|
|
10
|
-
|
|
10
|
+
import registerPaymentProvider from './registerPaymentProvider.ts';
|
|
11
|
+
import registerDeliveryProvider from './registerDeliveryProvider.ts';
|
|
12
|
+
import registerProductPricing from './registerProductPricing.ts';
|
|
13
|
+
import registerOrderPricing from './registerOrderPricing.ts';
|
|
14
|
+
import registerPaymentPricing from './registerPaymentPricing.ts';
|
|
15
|
+
import registerDeliveryPricing from './registerDeliveryPricing.ts';
|
|
16
|
+
import registerProductDiscount from './registerProductDiscount.ts';
|
|
17
|
+
import registerOrderDiscount from './registerOrderDiscount.ts';
|
|
18
|
+
import registerFileAdapter from './registerFileAdapter.ts';
|
|
19
|
+
import registerQuotation from './registerQuotation.ts';
|
|
20
|
+
import registerEnrollment from './registerEnrollment.ts';
|
|
21
|
+
export { registerProductDiscoverabilityFilter, registerPickUpDelivery, registerShippingDelivery, registerInvoicePayment, registerWorker, registerPhysicalWarehousing, registerVirtualWarehousing, registerProductSearchFilter, registerAssortmentSearchFilter, registerPaymentProvider, registerDeliveryProvider, registerProductPricing, registerOrderPricing, registerPaymentPricing, registerDeliveryPricing, registerProductDiscount, registerOrderDiscount, registerFileAdapter, registerQuotation, registerEnrollment, };
|
package/lib/factory/index.js
CHANGED
|
@@ -7,4 +7,15 @@ import registerVirtualWarehousing from "./registerVirtualWarehousing.js";
|
|
|
7
7
|
import registerProductSearchFilter from "./registerProductSearchFilter.js";
|
|
8
8
|
import registerAssortmentSearchFilter from "./registerAssortmentSearchFilter.js";
|
|
9
9
|
import registerInvoicePayment from "./registerInvoicePayment.js";
|
|
10
|
-
|
|
10
|
+
import registerPaymentProvider from "./registerPaymentProvider.js";
|
|
11
|
+
import registerDeliveryProvider from "./registerDeliveryProvider.js";
|
|
12
|
+
import registerProductPricing from "./registerProductPricing.js";
|
|
13
|
+
import registerOrderPricing from "./registerOrderPricing.js";
|
|
14
|
+
import registerPaymentPricing from "./registerPaymentPricing.js";
|
|
15
|
+
import registerDeliveryPricing from "./registerDeliveryPricing.js";
|
|
16
|
+
import registerProductDiscount from "./registerProductDiscount.js";
|
|
17
|
+
import registerOrderDiscount from "./registerOrderDiscount.js";
|
|
18
|
+
import registerFileAdapter from "./registerFileAdapter.js";
|
|
19
|
+
import registerQuotation from "./registerQuotation.js";
|
|
20
|
+
import registerEnrollment from "./registerEnrollment.js";
|
|
21
|
+
export { registerProductDiscoverabilityFilter, registerPickUpDelivery, registerShippingDelivery, registerInvoicePayment, registerWorker, registerPhysicalWarehousing, registerVirtualWarehousing, registerProductSearchFilter, registerAssortmentSearchFilter, registerPaymentProvider, registerDeliveryProvider, registerProductPricing, registerOrderPricing, registerPaymentPricing, registerDeliveryPricing, registerProductDiscount, registerOrderDiscount, registerFileAdapter, registerQuotation, registerEnrollment, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { SearchQuery } from '@unchainedshop/core-filters';
|
|
2
|
-
|
|
2
|
+
import { type IPlugin } from '../core-index.ts';
|
|
3
|
+
export default function registerAssortmentSearchFilter({ adapterId, orderIndex, search, }: {
|
|
4
|
+
adapterId?: string;
|
|
3
5
|
orderIndex?: number;
|
|
4
6
|
search: (params: SearchQuery & {
|
|
5
7
|
queryString: string;
|
|
6
8
|
locale: Intl.Locale;
|
|
7
9
|
}) => Promise<string[]>;
|
|
8
|
-
}):
|
|
10
|
+
}): IPlugin;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { FilterAdapter
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { FilterAdapter } from "../core-index.js";
|
|
2
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
|
+
export default function registerAssortmentSearchFilter({ adapterId, orderIndex = 0, search, }) {
|
|
4
|
+
const id = adapterId ?? crypto.randomUUID();
|
|
5
|
+
const adapter = {
|
|
4
6
|
...FilterAdapter,
|
|
5
|
-
key: `shop.unchained.filters.assortment-search-${
|
|
6
|
-
label:
|
|
7
|
+
key: `shop.unchained.filters.assortment-search-${id}`,
|
|
8
|
+
label: adapterId
|
|
9
|
+
? `Assortment Search Filter: ${adapterId}`
|
|
10
|
+
: 'Assortment Search Filter (auto-generated)',
|
|
7
11
|
version: '1.0.0',
|
|
8
12
|
orderIndex,
|
|
9
13
|
actions: (params) => {
|
|
@@ -19,5 +23,13 @@ export default function registerAssortmentSearchFilter({ orderIndex = 0, search,
|
|
|
19
23
|
},
|
|
20
24
|
};
|
|
21
25
|
},
|
|
22
|
-
}
|
|
26
|
+
};
|
|
27
|
+
const plugin = {
|
|
28
|
+
key: adapter.key,
|
|
29
|
+
label: adapter.label,
|
|
30
|
+
version: adapter.version,
|
|
31
|
+
adapters: [adapter],
|
|
32
|
+
};
|
|
33
|
+
pluginRegistry.register(plugin);
|
|
34
|
+
return plugin;
|
|
23
35
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PaymentConfiguration } from '@unchainedshop/core-payment';
|
|
2
|
-
import { type PaymentContext, type PaymentChargeActionResult } from '../core-index.ts';
|
|
2
|
+
import { type PaymentContext, type PaymentChargeActionResult, type IPlugin } from '../core-index.ts';
|
|
3
3
|
export default function registerInvoicePayment({ adapterId, active, payLaterAllowed, charge, }: {
|
|
4
4
|
adapterId: string;
|
|
5
5
|
active?: boolean;
|
|
6
6
|
payLaterAllowed?: boolean;
|
|
7
7
|
charge: false | ((configuration: PaymentConfiguration, context: PaymentContext) => Promise<PaymentChargeActionResult | false>);
|
|
8
|
-
}):
|
|
8
|
+
}): IPlugin;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { PaymentAdapter,
|
|
1
|
+
import { PaymentAdapter, } from "../core-index.js";
|
|
2
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
2
3
|
import { PaymentProviderType } from '@unchainedshop/core-payment';
|
|
3
4
|
export default function registerInvoicePayment({ adapterId, active, payLaterAllowed, charge, }) {
|
|
4
|
-
|
|
5
|
+
const adapter = {
|
|
5
6
|
...PaymentAdapter,
|
|
6
7
|
key: `shop.unchained.payment.invoice-${adapterId}`,
|
|
7
8
|
label: 'Invoice Payment: ' + adapterId,
|
|
@@ -27,5 +28,13 @@ export default function registerInvoicePayment({ adapterId, active, payLaterAllo
|
|
|
27
28
|
},
|
|
28
29
|
};
|
|
29
30
|
},
|
|
30
|
-
}
|
|
31
|
+
};
|
|
32
|
+
const plugin = {
|
|
33
|
+
key: adapter.key,
|
|
34
|
+
label: adapter.label,
|
|
35
|
+
version: adapter.version,
|
|
36
|
+
adapters: [adapter],
|
|
37
|
+
};
|
|
38
|
+
pluginRegistry.register(plugin);
|
|
39
|
+
return plugin;
|
|
31
40
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { WarehousingConfiguration } from '@unchainedshop/core-warehousing';
|
|
2
|
-
import { type WarehousingContext } from '../core-index.ts';
|
|
2
|
+
import { type WarehousingContext, type IPlugin } from '../core-index.ts';
|
|
3
3
|
export default function registerPhysicalWarehousing({ adapterId, orderIndex, stock, productionTime, commissioningTime, }: {
|
|
4
4
|
adapterId: string;
|
|
5
5
|
orderIndex?: number;
|
|
6
6
|
stock?: number | ((referenceDate: Date, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<number>);
|
|
7
7
|
productionTime?: number | ((quantityToProduct: number, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<number>);
|
|
8
8
|
commissioningTime?: number | ((quantity: number, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<number>);
|
|
9
|
-
}):
|
|
9
|
+
}): IPlugin;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
|
|
2
|
-
import { WarehousingAdapter,
|
|
2
|
+
import { WarehousingAdapter, } from "../core-index.js";
|
|
3
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
4
|
export default function registerPhysicalWarehousing({ adapterId, orderIndex = 0, stock, productionTime, commissioningTime, }) {
|
|
4
|
-
|
|
5
|
+
const adapter = {
|
|
5
6
|
...WarehousingAdapter,
|
|
6
7
|
key: 'shop.unchained.warehousing.physical.' + adapterId,
|
|
7
8
|
label: 'Physical Warehousing: ' + adapterId,
|
|
@@ -49,5 +50,13 @@ export default function registerPhysicalWarehousing({ adapterId, orderIndex = 0,
|
|
|
49
50
|
},
|
|
50
51
|
};
|
|
51
52
|
},
|
|
52
|
-
}
|
|
53
|
+
};
|
|
54
|
+
const plugin = {
|
|
55
|
+
key: adapter.key,
|
|
56
|
+
label: adapter.label,
|
|
57
|
+
version: adapter.version,
|
|
58
|
+
adapters: [adapter],
|
|
59
|
+
};
|
|
60
|
+
pluginRegistry.register(plugin);
|
|
61
|
+
return plugin;
|
|
53
62
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DeliveryConfiguration, type DeliveryLocation } from '@unchainedshop/core-delivery';
|
|
2
|
-
import { type DeliveryContext } from '../core-index.ts';
|
|
2
|
+
import { type DeliveryContext, type IPlugin } from '../core-index.ts';
|
|
3
3
|
import type { Work } from '@unchainedshop/core-worker';
|
|
4
4
|
export default function registerPickUpDelivery({ adapterId, locations, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }: {
|
|
5
5
|
adapterId: string;
|
|
@@ -8,4 +8,4 @@ export default function registerPickUpDelivery({ adapterId, locations, active, a
|
|
|
8
8
|
estimatedDeliveryThroughput?: (warehousingThroughputTime: number, context: DeliveryContext) => Promise<number | null>;
|
|
9
9
|
send: boolean | ((configuration: DeliveryConfiguration, context: DeliveryContext) => Promise<boolean | Work>);
|
|
10
10
|
locations: DeliveryLocation[] | ((context: DeliveryContext) => Promise<DeliveryLocation[]>);
|
|
11
|
-
}):
|
|
11
|
+
}): IPlugin;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DeliveryProviderType, } from '@unchainedshop/core-delivery';
|
|
2
|
-
import { DeliveryAdapter,
|
|
2
|
+
import { DeliveryAdapter, } from "../core-index.js";
|
|
3
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
4
|
export default function registerPickUpDelivery({ adapterId, locations, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }) {
|
|
4
|
-
|
|
5
|
+
const adapter = {
|
|
5
6
|
...DeliveryAdapter,
|
|
6
7
|
key: `shop.unchained.delivery.pickup-${adapterId}`,
|
|
7
8
|
label: 'PickUp Delivery: ' + adapterId,
|
|
@@ -41,5 +42,13 @@ export default function registerPickUpDelivery({ adapterId, locations, active, a
|
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
},
|
|
44
|
-
}
|
|
45
|
+
};
|
|
46
|
+
const plugin = {
|
|
47
|
+
key: adapter.key,
|
|
48
|
+
label: adapter.label,
|
|
49
|
+
version: adapter.version,
|
|
50
|
+
adapters: [adapter],
|
|
51
|
+
};
|
|
52
|
+
pluginRegistry.register(plugin);
|
|
53
|
+
return plugin;
|
|
45
54
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { type IPlugin } from '../core-index.ts';
|
|
2
|
+
export default function registerProductDiscoverabilityFilter({ adapterId, orderIndex, hiddenTagValue, }: {
|
|
3
|
+
adapterId?: string;
|
|
2
4
|
orderIndex?: number;
|
|
3
5
|
hiddenTagValue?: string;
|
|
4
|
-
}):
|
|
6
|
+
}): IPlugin;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { FilterAdapter
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { FilterAdapter } from "../core-index.js";
|
|
2
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
|
+
export default function registerProductDiscoverabilityFilter({ adapterId, orderIndex = 0, hiddenTagValue = 'hidden', }) {
|
|
4
|
+
const id = adapterId ?? crypto.randomUUID();
|
|
5
|
+
const adapter = {
|
|
4
6
|
...FilterAdapter,
|
|
5
|
-
key: `shop.unchained.filters.product-discoverability-${
|
|
6
|
-
label:
|
|
7
|
+
key: `shop.unchained.filters.product-discoverability-${id}`,
|
|
8
|
+
label: adapterId
|
|
9
|
+
? `Product Discoverability Filter: ${adapterId}`
|
|
10
|
+
: 'Product Discoverability Filter (auto-generated)',
|
|
7
11
|
version: '1.0.0',
|
|
8
12
|
orderIndex,
|
|
9
13
|
actions: (params) => {
|
|
@@ -22,5 +26,13 @@ export default function registerProductDiscoverabilityFilter({ orderIndex = 0, h
|
|
|
22
26
|
},
|
|
23
27
|
};
|
|
24
28
|
},
|
|
25
|
-
}
|
|
29
|
+
};
|
|
30
|
+
const plugin = {
|
|
31
|
+
key: adapter.key,
|
|
32
|
+
label: adapter.label,
|
|
33
|
+
version: adapter.version,
|
|
34
|
+
adapters: [adapter],
|
|
35
|
+
};
|
|
36
|
+
pluginRegistry.register(plugin);
|
|
37
|
+
return plugin;
|
|
26
38
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { SearchQuery } from '@unchainedshop/core-filters';
|
|
2
|
-
|
|
2
|
+
import { type IPlugin } from '../core-index.ts';
|
|
3
|
+
export default function registerProductSearchFilter({ adapterId, orderIndex, search, }: {
|
|
4
|
+
adapterId?: string;
|
|
3
5
|
orderIndex?: number;
|
|
4
6
|
search: (params: SearchQuery & {
|
|
5
7
|
queryString: string;
|
|
6
8
|
locale: Intl.Locale;
|
|
7
9
|
}) => Promise<string[]>;
|
|
8
|
-
}):
|
|
10
|
+
}): IPlugin;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { FilterAdapter
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { FilterAdapter } from "../core-index.js";
|
|
2
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
|
+
export default function registerProductSearchFilter({ adapterId, orderIndex = 0, search, }) {
|
|
4
|
+
const id = adapterId ?? crypto.randomUUID();
|
|
5
|
+
const adapter = {
|
|
4
6
|
...FilterAdapter,
|
|
5
|
-
key: `shop.unchained.filters.product-search-${
|
|
6
|
-
label: 'Product Search Filter (auto-generated)',
|
|
7
|
+
key: `shop.unchained.filters.product-search-${id}`,
|
|
8
|
+
label: adapterId ? `Product Search Filter: ${adapterId}` : 'Product Search Filter (auto-generated)',
|
|
7
9
|
version: '1.0.0',
|
|
8
10
|
orderIndex,
|
|
9
11
|
actions: (params) => {
|
|
@@ -19,5 +21,13 @@ export default function registerProductSearchFilter({ orderIndex = 0, search, })
|
|
|
19
21
|
},
|
|
20
22
|
};
|
|
21
23
|
},
|
|
22
|
-
}
|
|
24
|
+
};
|
|
25
|
+
const plugin = {
|
|
26
|
+
key: adapter.key,
|
|
27
|
+
label: adapter.label,
|
|
28
|
+
version: adapter.version,
|
|
29
|
+
adapters: [adapter],
|
|
30
|
+
};
|
|
31
|
+
pluginRegistry.register(plugin);
|
|
32
|
+
return plugin;
|
|
23
33
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DeliveryConfiguration } from '@unchainedshop/core-delivery';
|
|
2
|
-
import { type DeliveryContext } from '../core-index.ts';
|
|
2
|
+
import { type DeliveryContext, type IPlugin } from '../core-index.ts';
|
|
3
3
|
import type { Work } from '@unchainedshop/core-worker';
|
|
4
4
|
export default function registerShippingDelivery({ adapterId, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }: {
|
|
5
5
|
adapterId: string;
|
|
@@ -7,4 +7,4 @@ export default function registerShippingDelivery({ adapterId, active, autoReleas
|
|
|
7
7
|
autoReleaseAllowed?: boolean;
|
|
8
8
|
estimatedDeliveryThroughput?: (warehousingThroughputTime: number, context: DeliveryContext) => Promise<number | null>;
|
|
9
9
|
send: boolean | ((configuration: DeliveryConfiguration, context: DeliveryContext) => Promise<boolean | Work>);
|
|
10
|
-
}):
|
|
10
|
+
}): IPlugin;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DeliveryProviderType } from '@unchainedshop/core-delivery';
|
|
2
|
-
import { DeliveryAdapter,
|
|
2
|
+
import { DeliveryAdapter, } from "../core-index.js";
|
|
3
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
4
|
export default function registerShippingDelivery({ adapterId, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }) {
|
|
4
|
-
|
|
5
|
+
const adapter = {
|
|
5
6
|
...DeliveryAdapter,
|
|
6
7
|
key: `shop.unchained.delivery.shipping-${adapterId}`,
|
|
7
8
|
label: 'Shipping Delivery: ' + adapterId,
|
|
@@ -33,5 +34,13 @@ export default function registerShippingDelivery({ adapterId, active, autoReleas
|
|
|
33
34
|
},
|
|
34
35
|
};
|
|
35
36
|
},
|
|
36
|
-
}
|
|
37
|
+
};
|
|
38
|
+
const plugin = {
|
|
39
|
+
key: adapter.key,
|
|
40
|
+
label: adapter.label,
|
|
41
|
+
version: adapter.version,
|
|
42
|
+
adapters: [adapter],
|
|
43
|
+
};
|
|
44
|
+
pluginRegistry.register(plugin);
|
|
45
|
+
return plugin;
|
|
37
46
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TokenSurrogate, type WarehousingConfiguration } from '@unchainedshop/core-warehousing';
|
|
2
|
-
import { type WarehousingContext } from '../core-index.ts';
|
|
2
|
+
import { type WarehousingContext, type IPlugin } from '../core-index.ts';
|
|
3
3
|
export default function registerVirtualWarehousing<Metadata = Record<string, any>>({ adapterId, orderIndex, stock, tokenize, tokenMetadata, isInvalidateable, }: {
|
|
4
4
|
adapterId: string;
|
|
5
5
|
orderIndex?: number;
|
|
@@ -7,4 +7,4 @@ export default function registerVirtualWarehousing<Metadata = Record<string, any
|
|
|
7
7
|
tokenize: (configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<Omit<TokenSurrogate, 'userId' | 'productId' | 'orderPositionId'>[]>;
|
|
8
8
|
tokenMetadata?: (serialNumber: string, referenceDate: Date, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<Metadata>;
|
|
9
9
|
isInvalidateable?: (serialNumber: string, referenceDate: Date, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<boolean>;
|
|
10
|
-
}):
|
|
10
|
+
}): IPlugin;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { WarehousingProviderType, } from '@unchainedshop/core-warehousing';
|
|
2
|
-
import { WarehousingAdapter,
|
|
2
|
+
import { WarehousingAdapter, } from "../core-index.js";
|
|
3
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
3
4
|
export default function registerVirtualWarehousing({ adapterId, orderIndex = 0, stock, tokenize, tokenMetadata, isInvalidateable, }) {
|
|
4
|
-
|
|
5
|
+
const adapter = {
|
|
5
6
|
...WarehousingAdapter,
|
|
6
7
|
key: 'shop.unchained.warehousing.virtual.' + adapterId,
|
|
7
|
-
label: 'Virtual
|
|
8
|
+
label: 'Virtual Warehousing: ' + adapterId,
|
|
8
9
|
version: '1.0.0',
|
|
9
10
|
orderIndex,
|
|
10
11
|
initialConfiguration: [{ key: 'shipping-hub', value: 'Shipping Hub' }],
|
|
@@ -46,5 +47,13 @@ export default function registerVirtualWarehousing({ adapterId, orderIndex = 0,
|
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
},
|
|
49
|
-
}
|
|
50
|
+
};
|
|
51
|
+
const plugin = {
|
|
52
|
+
key: adapter.key,
|
|
53
|
+
label: adapter.label,
|
|
54
|
+
version: adapter.version,
|
|
55
|
+
adapters: [adapter],
|
|
56
|
+
};
|
|
57
|
+
pluginRegistry.register(plugin);
|
|
58
|
+
return plugin;
|
|
50
59
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type IPlugin } from '../core-index.ts';
|
|
1
2
|
export default function registerWorker<Input = any, Result = any>({ type, external, maxParallelAllocations, process, }: {
|
|
2
3
|
type: string;
|
|
3
4
|
external?: boolean;
|
|
4
5
|
maxParallelAllocations?: number;
|
|
5
6
|
process?: (input: Input, workId: string) => Promise<Result>;
|
|
6
|
-
}):
|
|
7
|
+
}): IPlugin;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { WorkerAdapter
|
|
1
|
+
import { WorkerAdapter } from "../core-index.js";
|
|
2
|
+
import { pluginRegistry } from "../plugins/PluginRegistry.js";
|
|
2
3
|
export default function registerWorker({ type, external, maxParallelAllocations, process, }) {
|
|
3
|
-
|
|
4
|
+
const adapter = {
|
|
4
5
|
...WorkerAdapter,
|
|
5
6
|
key: 'shop.unchained.worker.' + type.toLowerCase(),
|
|
6
7
|
label: 'Worker: ' + type,
|
|
7
|
-
version: '1.0',
|
|
8
|
+
version: '1.0.0',
|
|
8
9
|
external: external ?? false,
|
|
9
10
|
maxParallelAllocations,
|
|
10
11
|
type,
|
|
@@ -30,5 +31,13 @@ export default function registerWorker({ type, external, maxParallelAllocations,
|
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
|
-
}
|
|
34
|
+
};
|
|
35
|
+
const plugin = {
|
|
36
|
+
key: adapter.key,
|
|
37
|
+
label: adapter.label,
|
|
38
|
+
version: adapter.version,
|
|
39
|
+
adapters: [adapter],
|
|
40
|
+
};
|
|
41
|
+
pluginRegistry.register(plugin);
|
|
42
|
+
return plugin;
|
|
34
43
|
}
|
|
@@ -5,9 +5,11 @@ class PluginRegistry {
|
|
|
5
5
|
moduleFactories = [];
|
|
6
6
|
skippedPlugins = new Set();
|
|
7
7
|
register(plugin) {
|
|
8
|
-
|
|
8
|
+
const registered = this.plugins.get(plugin.key);
|
|
9
|
+
if (registered) {
|
|
9
10
|
logger.warn(`Plugin ${plugin.key} already registered, skipping`, {
|
|
10
11
|
label: plugin.label,
|
|
12
|
+
registeredLabel: registered.label,
|
|
11
13
|
});
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
@@ -103,6 +105,11 @@ class PluginRegistry {
|
|
|
103
105
|
}
|
|
104
106
|
return result.toSorted((left, right) => (left.orderIndex ?? 0) - (right.orderIndex ?? 0));
|
|
105
107
|
}
|
|
108
|
+
getAllAdapters() {
|
|
109
|
+
return this.getAllPlugins()
|
|
110
|
+
.filter((plugin) => !this.skippedPlugins.has(plugin.key))
|
|
111
|
+
.flatMap((plugin) => plugin.adapters ?? []);
|
|
112
|
+
}
|
|
106
113
|
hasPlugin(key) {
|
|
107
114
|
return this.plugins.has(key);
|
|
108
115
|
}
|
|
@@ -2,6 +2,7 @@ import { OrderStatus } from '@unchainedshop/core-orders';
|
|
|
2
2
|
import { nextUserCartService } from "./nextUserCart.js";
|
|
3
3
|
import { validateOrderService } from "./validateOrder.js";
|
|
4
4
|
import { processOrderService } from "./processOrder.js";
|
|
5
|
+
import { reserveOrderDiscountsForCheckout } from "./reserveOrderDiscountsForCheckout.js";
|
|
5
6
|
export async function checkoutOrderService(orderId, transactionContext) {
|
|
6
7
|
const order = await this.orders.findOrder({ orderId });
|
|
7
8
|
if (!order)
|
|
@@ -10,7 +11,9 @@ export async function checkoutOrderService(orderId, transactionContext) {
|
|
|
10
11
|
return order;
|
|
11
12
|
await validateOrderService.bind(this)(order);
|
|
12
13
|
const lock = await this.orders.acquireLock(order._id, 'checkout');
|
|
14
|
+
let discounts;
|
|
13
15
|
try {
|
|
16
|
+
discounts = await reserveOrderDiscountsForCheckout.call(this, order);
|
|
14
17
|
const processedOrder = await processOrderService.bind(this)(order, transactionContext);
|
|
15
18
|
if (processedOrder.billingAddress) {
|
|
16
19
|
await this.users.updateLastBillingAddress(processedOrder.userId, processedOrder.billingAddress);
|
|
@@ -27,6 +30,7 @@ export async function checkoutOrderService(orderId, transactionContext) {
|
|
|
27
30
|
return processedOrder;
|
|
28
31
|
}
|
|
29
32
|
finally {
|
|
33
|
+
await discounts?.release();
|
|
30
34
|
await lock.release();
|
|
31
35
|
}
|
|
32
36
|
}
|