@unchainedshop/core 3.0.0-rc1 → 3.0.0-rc10
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/lib/directors/BaseDiscountAdapter.d.ts +9 -11
- package/lib/directors/BaseDiscountAdapter.d.ts.map +1 -1
- package/lib/directors/BaseDiscountAdapter.js.map +1 -1
- package/lib/directors/BaseDiscountDirector.d.ts +7 -4
- package/lib/directors/BaseDiscountDirector.d.ts.map +1 -1
- package/lib/directors/BaseDiscountDirector.js.map +1 -1
- package/lib/directors/BasePricingAdapter.d.ts +1 -6
- package/lib/directors/BasePricingAdapter.d.ts.map +1 -1
- package/lib/directors/BasePricingAdapter.js.map +1 -1
- package/lib/directors/BasePricingDirector.d.ts.map +1 -1
- package/lib/directors/BasePricingDirector.js +2 -2
- package/lib/directors/BasePricingDirector.js.map +1 -1
- package/lib/directors/EnrollmentAdapter.d.ts +1 -1
- package/lib/directors/EnrollmentAdapter.d.ts.map +1 -1
- package/lib/directors/EnrollmentAdapter.js +2 -2
- package/lib/directors/EnrollmentAdapter.js.map +1 -1
- package/lib/directors/FilterDirector.d.ts.map +1 -1
- package/lib/directors/FilterDirector.js +4 -4
- package/lib/directors/FilterDirector.js.map +1 -1
- package/lib/directors/OrderDiscountAdapter.d.ts +1 -1
- package/lib/directors/OrderDiscountAdapter.d.ts.map +1 -1
- package/lib/directors/OrderDiscountDirector.d.ts +1 -1
- package/lib/directors/OrderDiscountDirector.d.ts.map +1 -1
- package/lib/directors/OrderDiscountDirector.js.map +1 -1
- package/lib/directors/ProductDiscountAdapter.d.ts +1 -1
- package/lib/directors/ProductDiscountAdapter.d.ts.map +1 -1
- package/lib/directors/ProductDiscountDirector.d.ts +1 -1
- package/lib/directors/ProductDiscountDirector.d.ts.map +1 -1
- package/lib/directors/ProductDiscountDirector.js.map +1 -1
- package/lib/directors/ProductPricingAdapter.d.ts +2 -0
- package/lib/directors/ProductPricingAdapter.d.ts.map +1 -1
- package/lib/directors/ProductPricingAdapter.js.map +1 -1
- package/lib/directors/ProductPricingSheet.d.ts +2 -5
- package/lib/directors/ProductPricingSheet.d.ts.map +1 -1
- package/lib/directors/ProductPricingSheet.js.map +1 -1
- package/lib/directors/WarehousingDirector.d.ts +4 -1
- package/lib/directors/WarehousingDirector.d.ts.map +1 -1
- package/lib/directors/WarehousingDirector.js.map +1 -1
- package/lib/modules.d.ts +0 -2
- package/lib/modules.d.ts.map +1 -1
- package/lib/modules.js +0 -6
- package/lib/modules.js.map +1 -1
- package/lib/services/activateEnrollment.js +1 -1
- package/lib/services/activateEnrollment.js.map +1 -1
- package/lib/services/deleteUser.js +2 -2
- package/lib/services/deleteUser.js.map +1 -1
- package/lib/services/findOrInitCart.d.ts +9 -0
- package/lib/services/findOrInitCart.d.ts.map +1 -0
- package/lib/services/findOrInitCart.js +15 -0
- package/lib/services/findOrInitCart.js.map +1 -0
- package/lib/services/index.d.ts +9 -1
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +8 -0
- package/lib/services/index.js.map +1 -1
- package/lib/services/initializeEnrollment.js +1 -1
- package/lib/services/initializeEnrollment.js.map +1 -1
- package/lib/services/loadFilterOptions.d.ts.map +1 -1
- package/lib/services/loadFilterOptions.js +1 -2
- package/lib/services/loadFilterOptions.js.map +1 -1
- package/lib/services/loadFilters.js +2 -2
- package/lib/services/loadFilters.js.map +1 -1
- package/lib/services/migrateOrderCart.js +2 -2
- package/lib/services/migrateOrderCart.js.map +1 -1
- package/lib/services/nextUserCart.d.ts +1 -1
- package/lib/services/nextUserCart.d.ts.map +1 -1
- package/lib/services/nextUserCart.js +1 -1
- package/lib/services/nextUserCart.js.map +1 -1
- package/lib/services/processQuotation.js +1 -1
- package/lib/services/processQuotation.js.map +1 -1
- package/lib/services/simulateProductDispatching.d.ts +15 -0
- package/lib/services/simulateProductDispatching.d.ts.map +1 -0
- package/lib/services/simulateProductDispatching.js +30 -0
- package/lib/services/simulateProductDispatching.js.map +1 -0
- package/lib/services/simulateProductInventory.d.ts +15 -0
- package/lib/services/simulateProductInventory.d.ts.map +1 -0
- package/lib/services/simulateProductInventory.js +29 -0
- package/lib/services/simulateProductInventory.js.map +1 -0
- package/lib/services/simulateProductPricing.d.ts +12 -0
- package/lib/services/simulateProductPricing.d.ts.map +1 -0
- package/lib/services/simulateProductPricing.js +8 -0
- package/lib/services/simulateProductPricing.js.map +1 -0
- package/lib/services/terminateEnrollment.js +1 -1
- package/lib/services/terminateEnrollment.js.map +1 -1
- package/package.json +24 -23
- package/src/directors/BaseDiscountAdapter.ts +7 -8
- package/src/directors/BaseDiscountDirector.ts +8 -7
- package/src/directors/BasePricingAdapter.ts +1 -3
- package/src/directors/BasePricingDirector.ts +3 -2
- package/src/directors/EnrollmentAdapter.ts +7 -3
- package/src/directors/FilterDirector.ts +4 -4
- package/src/directors/OrderDiscountAdapter.ts +1 -1
- package/src/directors/OrderDiscountDirector.ts +2 -3
- package/src/directors/ProductDiscountAdapter.ts +1 -1
- package/src/directors/ProductDiscountDirector.ts +2 -3
- package/src/directors/ProductPricingAdapter.ts +2 -0
- package/src/directors/ProductPricingSheet.ts +2 -5
- package/src/directors/WarehousingDirector.ts +2 -1
- package/src/modules.ts +0 -7
- package/src/services/activateEnrollment.ts +1 -1
- package/src/services/deleteUser.ts +2 -2
- package/src/services/findOrInitCart.ts +29 -0
- package/src/services/index.ts +15 -1
- package/src/services/initializeEnrollment.ts +1 -1
- package/src/services/loadFilterOptions.ts +1 -2
- package/src/services/loadFilters.ts +2 -2
- package/src/services/migrateOrderCart.ts +2 -2
- package/src/services/nextUserCart.ts +2 -2
- package/src/services/processQuotation.ts +1 -1
- package/src/services/simulateProductDispatching.ts +59 -0
- package/src/services/simulateProductInventory.ts +56 -0
- package/src/services/simulateProductPricing.ts +20 -0
- package/src/services/terminateEnrollment.ts +1 -1
- package/lib/core-index_BACKUP_57582.d.ts +0 -26
- package/lib/core-index_BACKUP_57582.d.ts.map +0 -1
- package/lib/core-index_BACKUP_57582.js +0 -30
- package/lib/core-index_BACKUP_57582.js.map +0 -1
- package/lib/core-index_BASE_57582.d.ts +0 -74
- package/lib/core-index_BASE_57582.d.ts.map +0 -1
- package/lib/core-index_BASE_57582.js +0 -145
- package/lib/core-index_BASE_57582.js.map +0 -1
- package/lib/core-index_LOCAL_57582.d.ts +0 -26
- package/lib/core-index_LOCAL_57582.d.ts.map +0 -1
- package/lib/core-index_LOCAL_57582.js +0 -31
- package/lib/core-index_LOCAL_57582.js.map +0 -1
- package/lib/core-index_REMOTE_57582.d.ts +0 -74
- package/lib/core-index_REMOTE_57582.d.ts.map +0 -1
- package/lib/core-index_REMOTE_57582.js +0 -146
- package/lib/core-index_REMOTE_57582.js.map +0 -1
- package/lib/services/createDownloadStreamService.d.ts +0 -11
- package/lib/services/createDownloadStreamService.d.ts.map +0 -1
- package/lib/services/createDownloadStreamService.js +0 -9
- package/lib/services/createDownloadStreamService.js.map +0 -1
- package/lib/services/createSignedURLService.d.ts +0 -13
- package/lib/services/createSignedURLService.d.ts.map +0 -1
- package/lib/services/createSignedURLService.js +0 -14
- package/lib/services/createSignedURLService.js.map +0 -1
- package/lib/services/deleteUserCartService.d.ts +0 -6
- package/lib/services/deleteUserCartService.d.ts.map +0 -1
- package/lib/services/deleteUserCartService.js +0 -20
- package/lib/services/deleteUserCartService.js.map +0 -1
- package/lib/services/deleteUserCarts.d.ts +0 -5
- package/lib/services/deleteUserCarts.d.ts.map +0 -1
- package/lib/services/deleteUserCarts.js +0 -18
- package/lib/services/deleteUserCarts.js.map +0 -1
- package/lib/services/deleteUserCartsService.d.ts +0 -5
- package/lib/services/deleteUserCartsService.d.ts.map +0 -1
- package/lib/services/deleteUserCartsService.js +0 -18
- package/lib/services/deleteUserCartsService.js.map +0 -1
- package/lib/services/index_BACKUP_58089.d.ts +0 -246
- package/lib/services/index_BACKUP_58089.d.ts.map +0 -1
- package/lib/services/index_BACKUP_58089.js +0 -103
- package/lib/services/index_BACKUP_58089.js.map +0 -1
- package/lib/services/index_BASE_58089.d.ts +0 -31
- package/lib/services/index_BASE_58089.d.ts.map +0 -1
- package/lib/services/index_BASE_58089.js +0 -42
- package/lib/services/index_BASE_58089.js.map +0 -1
- package/lib/services/index_LOCAL_58089.d.ts +0 -246
- package/lib/services/index_LOCAL_58089.d.ts.map +0 -1
- package/lib/services/index_LOCAL_58089.js +0 -103
- package/lib/services/index_LOCAL_58089.js.map +0 -1
- package/lib/services/index_REMOTE_58089.d.ts +0 -34
- package/lib/services/index_REMOTE_58089.d.ts.map +0 -1
- package/lib/services/index_REMOTE_58089.js +0 -44
- package/lib/services/index_REMOTE_58089.js.map +0 -1
- package/lib/services/migrateBookmarksService.d.ts +0 -13
- package/lib/services/migrateBookmarksService.d.ts.map +0 -1
- package/lib/services/migrateBookmarksService.js +0 -26
- package/lib/services/migrateBookmarksService.js.map +0 -1
- package/lib/services/migrateOrderCartService.d.ts +0 -23
- package/lib/services/migrateOrderCartService.d.ts.map +0 -1
- package/lib/services/migrateOrderCartService.js +0 -32
- package/lib/services/migrateOrderCartService.js.map +0 -1
- package/lib/services/migrateUserDataService.d.ts +0 -19
- package/lib/services/migrateUserDataService.d.ts.map +0 -1
- package/lib/services/migrateUserDataService.js +0 -18
- package/lib/services/migrateUserDataService.js.map +0 -1
- package/lib/services/nextUserCartService.d.ts +0 -22
- package/lib/services/nextUserCartService.d.ts.map +0 -1
- package/lib/services/nextUserCartService.js +0 -35
- package/lib/services/nextUserCartService.js.map +0 -1
- package/lib/services/removeFilesService.d.ts +0 -10
- package/lib/services/removeFilesService.d.ts.map +0 -1
- package/lib/services/removeFilesService.js +0 -20
- package/lib/services/removeFilesService.js.map +0 -1
- package/lib/services/removeProductService.d.ts +0 -20
- package/lib/services/removeProductService.d.ts.map +0 -1
- package/lib/services/removeProductService.js +0 -27
- package/lib/services/removeProductService.js.map +0 -1
- package/lib/services/updateCalculationService.d.ts +0 -17
- package/lib/services/updateCalculationService.d.ts.map +0 -1
- package/lib/services/updateCalculationService.js +0 -68
- package/lib/services/updateCalculationService.js.map +0 -1
- package/lib/services/updateUserAvatarAfterUploadService.d.ts +0 -18
- package/lib/services/updateUserAvatarAfterUploadService.d.ts.map +0 -1
- package/lib/services/updateUserAvatarAfterUploadService.js +0 -25
- package/lib/services/updateUserAvatarAfterUploadService.js.map +0 -1
- package/lib/services/uploadFileFromStreamService.d.ts +0 -12
- package/lib/services/uploadFileFromStreamService.d.ts.map +0 -1
- package/lib/services/uploadFileFromStreamService.js +0 -10
- package/lib/services/uploadFileFromStreamService.js.map +0 -1
- package/lib/services/uploadFileFromURLService.d.ts +0 -17
- package/lib/services/uploadFileFromURLService.d.ts.map +0 -1
- package/lib/services/uploadFileFromURLService.js +0 -10
- package/lib/services/uploadFileFromURLService.js.map +0 -1
- package/lib/types.d.ts +0 -4
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -5
- package/lib/types.js.map +0 -1
|
@@ -2,20 +2,22 @@ import { log, LogLevel } from '@unchainedshop/logger';
|
|
|
2
2
|
import { IBaseAdapter } from '@unchainedshop/utils';
|
|
3
3
|
import { IPricingSheet } from './BasePricingSheet.js';
|
|
4
4
|
import { PricingCalculation } from '@unchainedshop/utils';
|
|
5
|
+
import { Order, OrderDiscount } from '@unchainedshop/core-orders';
|
|
6
|
+
import { Modules } from '../modules.js';
|
|
5
7
|
export interface DiscountContext {
|
|
6
8
|
code?: string;
|
|
7
|
-
orderDiscount?:
|
|
8
|
-
order?:
|
|
9
|
+
orderDiscount?: OrderDiscount;
|
|
10
|
+
order?: Order;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
export type IDiscountAdapter<DiscountConfiguration
|
|
13
|
+
export type IDiscountAdapter<DiscountConfiguration> = IBaseAdapter & {
|
|
12
14
|
orderIndex: number;
|
|
13
15
|
|
|
14
16
|
isManualAdditionAllowed: (code: string) => Promise<boolean>;
|
|
15
17
|
isManualRemovalAllowed: () => Promise<boolean>;
|
|
16
18
|
|
|
17
19
|
actions: (params: {
|
|
18
|
-
context: DiscountContext &
|
|
20
|
+
context: DiscountContext & { modules: Modules };
|
|
19
21
|
}) => Promise<DiscountAdapterActions<DiscountConfiguration>>;
|
|
20
22
|
};
|
|
21
23
|
|
|
@@ -32,10 +34,7 @@ export interface DiscountAdapterActions<DiscountConfiguration> {
|
|
|
32
34
|
release: () => Promise<void>;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
export const BaseDiscountAdapter: Omit<
|
|
36
|
-
IDiscountAdapter<unknown, unknown>,
|
|
37
|
-
'key' | 'label' | 'version'
|
|
38
|
-
> = {
|
|
37
|
+
export const BaseDiscountAdapter: Omit<IDiscountAdapter<unknown>, 'key' | 'label' | 'version'> = {
|
|
39
38
|
orderIndex: 0,
|
|
40
39
|
|
|
41
40
|
isManualAdditionAllowed: async () => {
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { BaseDirector, IBaseDirector } from '@unchainedshop/utils';
|
|
2
2
|
import { DiscountContext, IDiscountAdapter } from './BaseDiscountAdapter.js';
|
|
3
|
+
import { Modules } from '../modules.js';
|
|
3
4
|
|
|
4
|
-
export type IDiscountDirector<DiscountConfiguration
|
|
5
|
-
IDiscountAdapter<DiscountConfiguration
|
|
5
|
+
export type IDiscountDirector<DiscountConfiguration> = IBaseDirector<
|
|
6
|
+
IDiscountAdapter<DiscountConfiguration>
|
|
6
7
|
> & {
|
|
7
8
|
actions: (
|
|
8
9
|
discountContext: DiscountContext,
|
|
9
|
-
unchainedAPI:
|
|
10
|
+
unchainedAPI: { modules: Modules },
|
|
10
11
|
) => Promise<{
|
|
11
12
|
resolveDiscountAdapterFromStaticCode: (params: {
|
|
12
13
|
code: string;
|
|
13
|
-
}) => Promise<IDiscountAdapter<DiscountConfiguration
|
|
14
|
+
}) => Promise<IDiscountAdapter<DiscountConfiguration>>;
|
|
14
15
|
findSystemDiscounts: () => Promise<Array<string>>;
|
|
15
16
|
}>;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
export const BaseDiscountDirector = <DiscountConfigurationType
|
|
19
|
+
export const BaseDiscountDirector = <DiscountConfigurationType>(
|
|
19
20
|
directorName: string,
|
|
20
|
-
): IDiscountDirector<DiscountConfigurationType
|
|
21
|
-
const baseDirector = BaseDirector<IDiscountAdapter<DiscountConfigurationType
|
|
21
|
+
): IDiscountDirector<DiscountConfigurationType> => {
|
|
22
|
+
const baseDirector = BaseDirector<IDiscountAdapter<DiscountConfigurationType>>(directorName, {
|
|
22
23
|
adapterSortKey: 'orderIndex',
|
|
23
24
|
});
|
|
24
25
|
|
|
@@ -2,12 +2,10 @@ import { createLogger } from '@unchainedshop/logger';
|
|
|
2
2
|
import { IPricingSheet } from './BasePricingSheet.js';
|
|
3
3
|
import { IBaseAdapter, PricingCalculation } from '@unchainedshop/utils';
|
|
4
4
|
import { Discount } from './BasePricingDirector.js';
|
|
5
|
+
import { Order, OrderDiscount } from '@unchainedshop/core-orders';
|
|
5
6
|
|
|
6
7
|
const logger = createLogger('unchained:core');
|
|
7
8
|
|
|
8
|
-
type Order = { _id?: string };
|
|
9
|
-
type OrderDiscount = { _id?: string };
|
|
10
|
-
|
|
11
9
|
interface IDiscountableItem {
|
|
12
10
|
_id?: string;
|
|
13
11
|
orderId?: string;
|
|
@@ -74,7 +74,7 @@ export const BasePricingDirector = <
|
|
|
74
74
|
},
|
|
75
75
|
|
|
76
76
|
async rebuildCalculation(pricingContext, unchainedAPI) {
|
|
77
|
-
const context = await
|
|
77
|
+
const context = await director.buildPricingContext(pricingContext, unchainedAPI);
|
|
78
78
|
|
|
79
79
|
let calculation: Array<Calculation> = [];
|
|
80
80
|
|
|
@@ -95,6 +95,7 @@ export const BasePricingDirector = <
|
|
|
95
95
|
});
|
|
96
96
|
const DiscountAdapter = OrderDiscountDirector.getAdapter(orderDiscount.discountKey);
|
|
97
97
|
if (!DiscountAdapter) return null;
|
|
98
|
+
|
|
98
99
|
const adapter = await DiscountAdapter.actions({
|
|
99
100
|
context: { order, orderDiscount, code: orderDiscount.code, ...unchainedAPI },
|
|
100
101
|
});
|
|
@@ -115,7 +116,7 @@ export const BasePricingDirector = <
|
|
|
115
116
|
const adapter = Adapter.actions({
|
|
116
117
|
context,
|
|
117
118
|
calculationSheet: this.calculationSheet(pricingContext, calculation),
|
|
118
|
-
discounts: discounts.filter((
|
|
119
|
+
discounts: discounts.filter((d) => d?.configuration !== null),
|
|
119
120
|
});
|
|
120
121
|
|
|
121
122
|
const nextCalculationResult = await adapter.calculate();
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { IBaseAdapter } from '@unchainedshop/utils';
|
|
2
2
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
Enrollment,
|
|
5
|
+
EnrollmentPeriod,
|
|
6
|
+
EnrollmentPlan,
|
|
7
|
+
addToDate,
|
|
8
|
+
} from '@unchainedshop/core-enrollments';
|
|
5
9
|
import type { Product, ProductPlan } from '@unchainedshop/core-products';
|
|
6
10
|
import type { OrderPosition } from '@unchainedshop/core-orders';
|
|
7
11
|
|
|
@@ -41,7 +45,7 @@ export const periodForReferenceDate = (referenceDate: Date, intervalCount = 1, i
|
|
|
41
45
|
|
|
42
46
|
return {
|
|
43
47
|
start,
|
|
44
|
-
end:
|
|
48
|
+
end: addToDate(start, {
|
|
45
49
|
[lowerCaseInterval]: intervalCount,
|
|
46
50
|
}),
|
|
47
51
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { BaseDirector, IBaseDirector
|
|
2
|
+
import { BaseDirector, IBaseDirector } from '@unchainedshop/utils';
|
|
3
3
|
import { FilterAdapterActions, FilterContext, IFilterAdapter } from './FilterAdapter.js';
|
|
4
4
|
import {
|
|
5
5
|
Filter,
|
|
@@ -227,7 +227,7 @@ export const FilterDirector: IFilterDirector = {
|
|
|
227
227
|
unchainedAPI,
|
|
228
228
|
);
|
|
229
229
|
|
|
230
|
-
return
|
|
230
|
+
return productIdSet.intersection(new Set(filterOptionProductIds));
|
|
231
231
|
},
|
|
232
232
|
Promise.resolve(new Set(productIds)),
|
|
233
233
|
);
|
|
@@ -252,7 +252,7 @@ export const FilterDirector: IFilterDirector = {
|
|
|
252
252
|
unchainedAPI,
|
|
253
253
|
);
|
|
254
254
|
|
|
255
|
-
const examinedProductIdSet =
|
|
255
|
+
const examinedProductIdSet = new Set(allProductIds).intersection(new Set(filteredProductIds));
|
|
256
256
|
const values = filterQueryParsed[filter.key];
|
|
257
257
|
|
|
258
258
|
// The filteredProductIdSet is a set of product id's that:
|
|
@@ -275,7 +275,7 @@ export const FilterDirector: IFilterDirector = {
|
|
|
275
275
|
},
|
|
276
276
|
unchainedAPI,
|
|
277
277
|
);
|
|
278
|
-
return
|
|
278
|
+
return productIdSet.intersection(new Set(otherFilterProductIds));
|
|
279
279
|
},
|
|
280
280
|
Promise.resolve(new Set(examinedProductIdSet)),
|
|
281
281
|
);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BaseDiscountDirector } from './BaseDiscountDirector.js';
|
|
2
2
|
import { OrderDiscountConfiguration } from './OrderDiscountConfiguration.js';
|
|
3
3
|
|
|
4
|
-
export const OrderDiscountDirector =
|
|
5
|
-
'OrderDiscountDirector'
|
|
6
|
-
);
|
|
4
|
+
export const OrderDiscountDirector =
|
|
5
|
+
BaseDiscountDirector<OrderDiscountConfiguration>('OrderDiscountDirector');
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseDiscountDirector, ProductDiscountConfiguration } from '../directors/index.js';
|
|
2
2
|
|
|
3
|
-
export const ProductDiscountDirector =
|
|
4
|
-
'ProductDiscountDirector'
|
|
5
|
-
);
|
|
3
|
+
export const ProductDiscountDirector =
|
|
4
|
+
BaseDiscountDirector<ProductDiscountConfiguration>('ProductDiscountDirector');
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
IPricingAdapter,
|
|
10
10
|
} from '../directors/index.js';
|
|
11
11
|
import { Modules } from '../modules.js';
|
|
12
|
+
import { User } from '@unchainedshop/core-users';
|
|
12
13
|
|
|
13
14
|
export interface ProductPricingAdapterContext extends BasePricingAdapterContext {
|
|
14
15
|
country: string;
|
|
@@ -17,6 +18,7 @@ export interface ProductPricingAdapterContext extends BasePricingAdapterContext
|
|
|
17
18
|
quantity: number;
|
|
18
19
|
configuration: Array<ProductConfiguration>;
|
|
19
20
|
order?: Order;
|
|
21
|
+
user?: User;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export type IProductPricingAdapter<DiscountConfiguration = unknown> = IPricingAdapter<
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PricingCalculation } from '@unchainedshop/utils';
|
|
1
|
+
import { Price, PricingCalculation } from '@unchainedshop/utils';
|
|
2
2
|
|
|
3
3
|
import { BasePricingSheet, IPricingSheet, PricingSheetParams } from '../directors/index.js';
|
|
4
4
|
|
|
@@ -33,10 +33,7 @@ export interface IProductPricingSheet extends IPricingSheet<ProductPricingCalcul
|
|
|
33
33
|
meta?: any;
|
|
34
34
|
}) => void;
|
|
35
35
|
|
|
36
|
-
unitPrice: (params?: { useNetPrice: boolean }) =>
|
|
37
|
-
amount: number;
|
|
38
|
-
currency: string;
|
|
39
|
-
};
|
|
36
|
+
unitPrice: (params?: { useNetPrice: boolean }) => Price;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
export const ProductPricingSheet = (
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
WarehousingContext,
|
|
11
11
|
WarehousingError,
|
|
12
12
|
} from '../directors/index.js';
|
|
13
|
+
import { Modules } from '../modules.js';
|
|
13
14
|
|
|
14
15
|
export type EstimatedDispatch = {
|
|
15
16
|
shipping?: Date;
|
|
@@ -40,7 +41,7 @@ export type IWarehousingDirector = IBaseDirector<IWarehousingAdapter> & {
|
|
|
40
41
|
actions: (
|
|
41
42
|
warehousingProvider: WarehousingProvider,
|
|
42
43
|
warehousingContext: WarehousingContext,
|
|
43
|
-
unchainedAPI,
|
|
44
|
+
unchainedAPI: { modules: Modules },
|
|
44
45
|
) => Promise<{
|
|
45
46
|
configurationError: () => WarehousingError;
|
|
46
47
|
isActive: () => boolean;
|
package/src/modules.ts
CHANGED
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
FiltersSettingsOptions,
|
|
25
25
|
} from '@unchainedshop/core-filters';
|
|
26
26
|
import { configureLanguagesModule, LanguagesModule } from '@unchainedshop/core-languages';
|
|
27
|
-
import { configureMessagingModule, MessagingModule } from '@unchainedshop/core-messaging';
|
|
28
27
|
import { configureOrdersModule, OrdersModule, OrdersSettingsOptions } from '@unchainedshop/core-orders';
|
|
29
28
|
import {
|
|
30
29
|
configurePaymentModule,
|
|
@@ -57,7 +56,6 @@ export interface Modules {
|
|
|
57
56
|
files: FilesModule;
|
|
58
57
|
filters: FiltersModule;
|
|
59
58
|
languages: LanguagesModule;
|
|
60
|
-
messaging: MessagingModule;
|
|
61
59
|
orders: OrdersModule;
|
|
62
60
|
payment: PaymentModule;
|
|
63
61
|
products: ProductsModule;
|
|
@@ -143,10 +141,6 @@ const initModules = async (
|
|
|
143
141
|
db,
|
|
144
142
|
migrationRepository,
|
|
145
143
|
});
|
|
146
|
-
const messaging = await configureMessagingModule({
|
|
147
|
-
db,
|
|
148
|
-
migrationRepository,
|
|
149
|
-
});
|
|
150
144
|
const orders = await configureOrdersModule({
|
|
151
145
|
db,
|
|
152
146
|
options: options.orders,
|
|
@@ -192,7 +186,6 @@ const initModules = async (
|
|
|
192
186
|
files,
|
|
193
187
|
filters,
|
|
194
188
|
languages,
|
|
195
|
-
messaging,
|
|
196
189
|
orders,
|
|
197
190
|
payment,
|
|
198
191
|
products,
|
|
@@ -11,13 +11,13 @@ export async function deleteUserService(this: Modules, { userId }: { userId: str
|
|
|
11
11
|
|
|
12
12
|
const carts = await this.orders.findOrders({ userId, status: null });
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
await Array.fromAsync(carts, async (userCart) => {
|
|
15
15
|
await this.orders.positions.deleteOrderPositions(userCart?._id);
|
|
16
16
|
await this.orders.payments.deleteOrderPayments(userCart?._id);
|
|
17
17
|
await this.orders.deliveries.deleteOrderDeliveries(userCart?._id);
|
|
18
18
|
await this.orders.discounts.deleteOrderDiscounts(userCart?._id);
|
|
19
19
|
await this.orders.delete(userCart?._id);
|
|
20
|
-
}
|
|
20
|
+
});
|
|
21
21
|
|
|
22
22
|
const ordersCount = await this.orders.count({ userId, includeCarts: true });
|
|
23
23
|
const quotationsCount = await this.quotations.count({ userId });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { User } from '@unchainedshop/core-users';
|
|
2
|
+
import { Order } from '@unchainedshop/core-orders';
|
|
3
|
+
import { Modules } from '../modules.js';
|
|
4
|
+
import { nextUserCartService } from './nextUserCart.js';
|
|
5
|
+
|
|
6
|
+
export async function findOrInitCartService(
|
|
7
|
+
this: Modules,
|
|
8
|
+
{
|
|
9
|
+
user,
|
|
10
|
+
countryCode,
|
|
11
|
+
orderId,
|
|
12
|
+
}: {
|
|
13
|
+
user: User;
|
|
14
|
+
countryCode: string;
|
|
15
|
+
orderId?: string;
|
|
16
|
+
},
|
|
17
|
+
) {
|
|
18
|
+
if (orderId) {
|
|
19
|
+
const order = await this.orders.findOrder({ orderId });
|
|
20
|
+
if (!order) return null;
|
|
21
|
+
return order;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return nextUserCartService.bind(this)({
|
|
25
|
+
user,
|
|
26
|
+
countryCode,
|
|
27
|
+
forceCartCreation: true,
|
|
28
|
+
}) as Order;
|
|
29
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Modules } from '../modules.js';
|
|
1
2
|
import { migrateUserDataService } from './migrateUserData.js';
|
|
2
3
|
import { updateUserAvatarAfterUploadService } from './updateUserAvatarAfterUpload.js';
|
|
3
4
|
import { linkFileService } from './linkFileService.js';
|
|
@@ -39,7 +40,10 @@ import { verifyQuotationService } from './verifyQuotation.js';
|
|
|
39
40
|
import { loadFiltersService } from './loadFilters.js';
|
|
40
41
|
import { loadFilterOptionsService } from './loadFilterOptions.js';
|
|
41
42
|
import { ercMetadataService } from './ercMetadata.js';
|
|
42
|
-
import {
|
|
43
|
+
import { simulateProductPricingService } from './simulateProductPricing.js';
|
|
44
|
+
import { simulateProductDispatchingService } from './simulateProductDispatching.js';
|
|
45
|
+
import { simulateProductInventoryService } from './simulateProductInventory.js';
|
|
46
|
+
import { findOrInitCartService } from './findOrInitCart.js';
|
|
43
47
|
|
|
44
48
|
// TODO: Auto-Inject Unchained API as last parameter
|
|
45
49
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
|
|
@@ -89,6 +93,7 @@ export default function initServices(
|
|
|
89
93
|
>,
|
|
90
94
|
migrateOrderCarts: migrateOrderCartsService as Bound<typeof migrateOrderCartsService>,
|
|
91
95
|
nextUserCart: nextUserCartService as Bound<typeof nextUserCartService>,
|
|
96
|
+
findOrInitCart: findOrInitCartService as Bound<typeof findOrInitCartService>,
|
|
92
97
|
initCartProviders: initCartProvidersService as Bound<typeof initCartProvidersService>,
|
|
93
98
|
updateCalculation: updateCalculationService as Bound<typeof updateCalculationService>,
|
|
94
99
|
supportedDeliveryProviders: supportedDeliveryProvidersService as Bound<
|
|
@@ -110,6 +115,15 @@ export default function initServices(
|
|
|
110
115
|
>,
|
|
111
116
|
},
|
|
112
117
|
products: {
|
|
118
|
+
simulateProductPricing: simulateProductPricingService as Bound<
|
|
119
|
+
typeof simulateProductPricingService
|
|
120
|
+
>,
|
|
121
|
+
simulateProductDispatching: simulateProductDispatchingService as Bound<
|
|
122
|
+
typeof simulateProductDispatchingService
|
|
123
|
+
>,
|
|
124
|
+
simulateProductInventory: simulateProductInventoryService as Bound<
|
|
125
|
+
typeof simulateProductInventoryService
|
|
126
|
+
>,
|
|
113
127
|
removeProduct: removeProductService as Bound<typeof removeProductService>,
|
|
114
128
|
},
|
|
115
129
|
users: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FilterType, Filter, SearchQuery } from '@unchainedshop/core-filters';
|
|
2
|
-
import { intersectSet } from '@unchainedshop/utils';
|
|
3
2
|
import { Modules } from '../modules.js';
|
|
4
3
|
import { FilterDirector, parseQueryArray } from '../directors/FilterDirector.js';
|
|
5
4
|
|
|
@@ -28,7 +27,7 @@ export async function loadFilterOptionsService(
|
|
|
28
27
|
},
|
|
29
28
|
{ modules: this },
|
|
30
29
|
);
|
|
31
|
-
const filteredProductIdSet =
|
|
30
|
+
const filteredProductIdSet = productIdSet.intersection(new Set(filterOptionProductIds));
|
|
32
31
|
|
|
33
32
|
const normalizedValues = values && this.filters.parse(filter, values, [value]);
|
|
34
33
|
const isSelected = normalizedValues && normalizedValues.indexOf(value) !== -1;
|
|
@@ -19,7 +19,7 @@ export async function loadFiltersService(
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
const extractedFilterIds = (filterSelector?._id as any)?.$in || [];
|
|
22
|
-
const sortedFilters = otherFilters.
|
|
22
|
+
const sortedFilters = otherFilters.toSorted((left, right) => {
|
|
23
23
|
const leftIndex = extractedFilterIds.indexOf(left._id);
|
|
24
24
|
const rightIndex = extractedFilterIds.indexOf(right._id);
|
|
25
25
|
return leftIndex - rightIndex;
|
|
@@ -34,7 +34,7 @@ export async function loadFiltersService(
|
|
|
34
34
|
searchQuery,
|
|
35
35
|
forceLiveCollection,
|
|
36
36
|
allProductIds: productIds,
|
|
37
|
-
otherFilters,
|
|
37
|
+
otherFilters: sortedFilters,
|
|
38
38
|
},
|
|
39
39
|
{ modules: this },
|
|
40
40
|
);
|
|
@@ -16,11 +16,11 @@ export async function migrateOrderCartsService(
|
|
|
16
16
|
},
|
|
17
17
|
) {
|
|
18
18
|
const fromCart = await this.orders.cart({
|
|
19
|
-
countryContext,
|
|
19
|
+
countryCode: countryContext,
|
|
20
20
|
userId: fromUserId,
|
|
21
21
|
});
|
|
22
22
|
const toCart = await this.orders.cart({
|
|
23
|
-
countryContext,
|
|
23
|
+
countryCode: countryContext,
|
|
24
24
|
userId: toUserId,
|
|
25
25
|
});
|
|
26
26
|
|
|
@@ -14,12 +14,12 @@ export async function nextUserCartService(
|
|
|
14
14
|
}: {
|
|
15
15
|
user: User;
|
|
16
16
|
orderNumber?: string;
|
|
17
|
-
countryCode
|
|
17
|
+
countryCode: string;
|
|
18
18
|
forceCartCreation?: boolean;
|
|
19
19
|
},
|
|
20
20
|
) {
|
|
21
21
|
const cart = await this.orders.cart({
|
|
22
|
-
|
|
22
|
+
countryCode,
|
|
23
23
|
orderNumber,
|
|
24
24
|
userId: user._id,
|
|
25
25
|
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DeliveryProvider } from '@unchainedshop/core-delivery';
|
|
2
|
+
import { Modules } from '../modules.js';
|
|
3
|
+
import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.js';
|
|
4
|
+
import { Product } from '@unchainedshop/core-products';
|
|
5
|
+
import { EstimatedDispatch, WarehousingDirector } from '../directors/WarehousingDirector.js';
|
|
6
|
+
import { WarehousingContext } from '../directors/WarehousingAdapter.js';
|
|
7
|
+
import { WarehousingProvider } from '@unchainedshop/core-warehousing';
|
|
8
|
+
|
|
9
|
+
export async function simulateProductDispatchingService(
|
|
10
|
+
this: Modules,
|
|
11
|
+
{
|
|
12
|
+
deliveryProviders,
|
|
13
|
+
product,
|
|
14
|
+
quantity,
|
|
15
|
+
referenceDate,
|
|
16
|
+
}: {
|
|
17
|
+
product: Product;
|
|
18
|
+
deliveryProviders: DeliveryProvider[];
|
|
19
|
+
quantity?: number;
|
|
20
|
+
referenceDate?: Date;
|
|
21
|
+
},
|
|
22
|
+
) {
|
|
23
|
+
return deliveryProviders.reduce<
|
|
24
|
+
Promise<Array<WarehousingContext & EstimatedDispatch & { warehousingProvider: WarehousingProvider }>>
|
|
25
|
+
>(async (oldResult, deliveryProvider) => {
|
|
26
|
+
const result = await oldResult;
|
|
27
|
+
|
|
28
|
+
const warehousingProviders: WarehousingProvider[] = await supportedWarehousingProvidersService.bind(
|
|
29
|
+
this,
|
|
30
|
+
)({
|
|
31
|
+
product,
|
|
32
|
+
deliveryProvider,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const mappedWarehousingProviders = await Promise.all(
|
|
36
|
+
warehousingProviders.map(async (warehousingProvider) => {
|
|
37
|
+
const warehousingContext: WarehousingContext = {
|
|
38
|
+
deliveryProvider,
|
|
39
|
+
product,
|
|
40
|
+
quantity,
|
|
41
|
+
referenceDate,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const director = await WarehousingDirector.actions(warehousingProvider, warehousingContext, {
|
|
45
|
+
modules: this,
|
|
46
|
+
});
|
|
47
|
+
const dispatch = await director.estimatedDispatch();
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
warehousingProvider,
|
|
51
|
+
...warehousingContext,
|
|
52
|
+
...dispatch,
|
|
53
|
+
};
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return result.concat(result, mappedWarehousingProviders);
|
|
58
|
+
}, Promise.resolve([]));
|
|
59
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DeliveryProvider } from '@unchainedshop/core-delivery';
|
|
2
|
+
import { Modules } from '../modules.js';
|
|
3
|
+
import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.js';
|
|
4
|
+
import { Product } from '@unchainedshop/core-products';
|
|
5
|
+
import { EstimatedStock, WarehousingDirector } from '../directors/WarehousingDirector.js';
|
|
6
|
+
import { WarehousingContext } from '../directors/WarehousingAdapter.js';
|
|
7
|
+
import { WarehousingProvider } from '@unchainedshop/core-warehousing';
|
|
8
|
+
|
|
9
|
+
export async function simulateProductInventoryService(
|
|
10
|
+
this: Modules,
|
|
11
|
+
{
|
|
12
|
+
deliveryProviders,
|
|
13
|
+
product,
|
|
14
|
+
referenceDate,
|
|
15
|
+
}: {
|
|
16
|
+
product: Product;
|
|
17
|
+
deliveryProviders: DeliveryProvider[];
|
|
18
|
+
referenceDate?: Date;
|
|
19
|
+
},
|
|
20
|
+
) {
|
|
21
|
+
return deliveryProviders.reduce<
|
|
22
|
+
Promise<Array<WarehousingContext & EstimatedStock & { warehousingProvider: WarehousingProvider }>>
|
|
23
|
+
>(async (oldResult, deliveryProvider) => {
|
|
24
|
+
const result = await oldResult;
|
|
25
|
+
|
|
26
|
+
const warehousingProviders: WarehousingProvider[] = await supportedWarehousingProvidersService.bind(
|
|
27
|
+
this,
|
|
28
|
+
)({
|
|
29
|
+
product,
|
|
30
|
+
deliveryProvider,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const mappedWarehousingProviders = await Promise.all(
|
|
34
|
+
warehousingProviders.map(async (warehousingProvider) => {
|
|
35
|
+
const warehousingContext: WarehousingContext = {
|
|
36
|
+
deliveryProvider,
|
|
37
|
+
product,
|
|
38
|
+
referenceDate,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const director = await WarehousingDirector.actions(warehousingProvider, warehousingContext, {
|
|
42
|
+
modules: this,
|
|
43
|
+
});
|
|
44
|
+
const stock = await director.estimatedStock();
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
warehousingProvider,
|
|
48
|
+
...warehousingContext,
|
|
49
|
+
...stock,
|
|
50
|
+
};
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return result.concat(result, mappedWarehousingProviders);
|
|
55
|
+
}, Promise.resolve([]));
|
|
56
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Product, ProductConfiguration } from '@unchainedshop/core-products';
|
|
2
|
+
import { ProductPricingDirector } from '../core-index.js';
|
|
3
|
+
import { User } from '@unchainedshop/core-users';
|
|
4
|
+
import { Modules } from '../modules.js';
|
|
5
|
+
|
|
6
|
+
export async function simulateProductPricingService(
|
|
7
|
+
this: Modules,
|
|
8
|
+
pricingContext: {
|
|
9
|
+
product: Product;
|
|
10
|
+
user: User;
|
|
11
|
+
country: string;
|
|
12
|
+
currency: string;
|
|
13
|
+
quantity: number;
|
|
14
|
+
configuration?: Array<ProductConfiguration>;
|
|
15
|
+
},
|
|
16
|
+
) {
|
|
17
|
+
const calculated = await ProductPricingDirector.rebuildCalculation(pricingContext, { modules: this });
|
|
18
|
+
if (!calculated || !calculated.length) return null;
|
|
19
|
+
return ProductPricingDirector.calculationSheet(pricingContext, calculated);
|
|
20
|
+
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { mongodb, MigrationRepository, ModuleInput } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Services } from './services/index.js';
|
|
3
|
-
import { Modules, ModuleOptions } from './modules.js';
|
|
4
|
-
export * from './services/index.js';
|
|
5
|
-
export * from './directors/index.js';
|
|
6
|
-
export interface BulkImporter {
|
|
7
|
-
createBulkImporter: (options: any) => any;
|
|
8
|
-
}
|
|
9
|
-
export interface UnchainedCoreOptions {
|
|
10
|
-
db: mongodb.Db;
|
|
11
|
-
migrationRepository: MigrationRepository<UnchainedCore>;
|
|
12
|
-
bulkImporter: any;
|
|
13
|
-
modules?: Record<string, {
|
|
14
|
-
configure: (params: ModuleInput<any>) => any;
|
|
15
|
-
}>;
|
|
16
|
-
services?: Record<string, any>;
|
|
17
|
-
options?: ModuleOptions;
|
|
18
|
-
}
|
|
19
|
-
export interface UnchainedCore {
|
|
20
|
-
modules: Modules;
|
|
21
|
-
services: Services;
|
|
22
|
-
bulkImporter: BulkImporter;
|
|
23
|
-
options: ModuleOptions;
|
|
24
|
-
}
|
|
25
|
-
export declare const initCore: ({ db, migrationRepository, bulkImporter, modules, services, options, }: UnchainedCoreOptions) => Promise<UnchainedCore>;
|
|
26
|
-
//# sourceMappingURL=core-index_BACKUP_57582.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core-index_BACKUP_57582.d.ts","sourceRoot":"","sources":["../src/core-index_BACKUP_57582.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAwB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAoB,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEnE,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,kBAAkB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,GAAG,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,OAAO,CAAC,EAAE,CAAC;IACf,mBAAmB,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACxD,YAAY,EAAE,GAAG,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CACd,MAAM,EACN;QACE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;KAC9C,CACF,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,eAAO,MAAM,QAAQ,2EAOlB,oBAAoB,KAAG,OAAO,CAAC,aAAa,CAoH9C,CAAC"}
|