@unchainedshop/core-delivery 3.0.0-alpha7 → 3.0.0-rc2
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/db/DeliveryProvidersCollection.d.ts +30 -2
- package/lib/db/DeliveryProvidersCollection.d.ts.map +1 -1
- package/lib/db/DeliveryProvidersCollection.js +5 -0
- package/lib/db/DeliveryProvidersCollection.js.map +1 -1
- package/lib/delivery-index.d.ts +1 -8
- package/lib/delivery-index.d.ts.map +1 -1
- package/lib/delivery-index.js +1 -8
- package/lib/delivery-index.js.map +1 -1
- package/lib/delivery-settings.d.ts +7 -5
- package/lib/delivery-settings.d.ts.map +1 -1
- package/lib/delivery-settings.js.map +1 -1
- package/lib/director/DeliveryPricingAdapter.d.ts +2 -2
- package/lib/director/DeliveryPricingAdapter.d.ts.map +1 -1
- package/lib/director/DeliveryPricingDirector.d.ts +3 -3
- package/lib/director/DeliveryPricingDirector.d.ts.map +1 -1
- package/lib/module/configureDeliveryModule.d.ts +20 -39
- package/lib/module/configureDeliveryModule.d.ts.map +1 -1
- package/lib/module/configureDeliveryModule.js +1 -81
- package/lib/module/configureDeliveryModule.js.map +1 -1
- package/lib/types.d.ts +9 -13
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/package.json +10 -12
- package/src/db/DeliveryProvidersCollection.ts +32 -2
- package/src/delivery-index.ts +1 -10
- package/src/delivery-settings.ts +11 -5
- package/src/module/configureDeliveryModule.ts +28 -187
- package/tsconfig.json +5 -7
- package/src/director/DeliveryAdapter.ts +0 -56
- package/src/director/DeliveryDirector.ts +0 -76
- package/src/director/DeliveryError.ts +0 -6
- package/src/director/DeliveryPricingAdapter.ts +0 -86
- package/src/director/DeliveryPricingDirector.ts +0 -99
- package/src/director/DeliveryPricingSheet.ts +0 -87
- package/src/director/DeliveryProviderType.ts +0 -4
- package/src/types.ts +0 -115
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { BasePricingSheet } from '@unchainedshop/utils';
|
|
2
|
-
import { IBasePricingSheet, PricingSheetParams } from '@unchainedshop/utils';
|
|
3
|
-
import { DeliveryPricingCalculation, IDeliveryPricingSheet } from './DeliveryPricingAdapter.js';
|
|
4
|
-
|
|
5
|
-
export enum DeliveryPricingRowCategory {
|
|
6
|
-
Delivery = 'DELIVERY',
|
|
7
|
-
Discount = 'DISCOUNT',
|
|
8
|
-
Tax = 'TAX',
|
|
9
|
-
Item = 'ITEM', // Propably unused
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const DeliveryPricingSheet = (
|
|
13
|
-
params: PricingSheetParams<DeliveryPricingCalculation>,
|
|
14
|
-
): IDeliveryPricingSheet => {
|
|
15
|
-
const basePricingSheet: IBasePricingSheet<DeliveryPricingCalculation> = BasePricingSheet(params);
|
|
16
|
-
|
|
17
|
-
const pricingSheet: IDeliveryPricingSheet = {
|
|
18
|
-
...basePricingSheet,
|
|
19
|
-
|
|
20
|
-
addDiscount({ amount, isTaxable, isNetPrice, discountId, meta }) {
|
|
21
|
-
basePricingSheet.calculation.push({
|
|
22
|
-
category: DeliveryPricingRowCategory.Discount,
|
|
23
|
-
amount,
|
|
24
|
-
isTaxable,
|
|
25
|
-
isNetPrice,
|
|
26
|
-
discountId,
|
|
27
|
-
meta,
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
addFee({ amount, isTaxable, isNetPrice, meta }) {
|
|
32
|
-
basePricingSheet.calculation.push({
|
|
33
|
-
amount,
|
|
34
|
-
category: DeliveryPricingRowCategory.Delivery,
|
|
35
|
-
isNetPrice,
|
|
36
|
-
isTaxable,
|
|
37
|
-
meta,
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
addTax({ amount, rate, meta }) {
|
|
42
|
-
basePricingSheet.calculation.push({
|
|
43
|
-
amount,
|
|
44
|
-
category: DeliveryPricingRowCategory.Tax,
|
|
45
|
-
isNetPrice: false,
|
|
46
|
-
isTaxable: false,
|
|
47
|
-
meta,
|
|
48
|
-
rate,
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
taxSum(filter) {
|
|
53
|
-
return basePricingSheet.sum({
|
|
54
|
-
category: DeliveryPricingRowCategory.Tax,
|
|
55
|
-
...(filter || {}),
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
discountPrices(explicitDiscountId) {
|
|
60
|
-
const discountIds = pricingSheet
|
|
61
|
-
.filterBy({
|
|
62
|
-
category: DeliveryPricingRowCategory.Discount,
|
|
63
|
-
discountId: explicitDiscountId,
|
|
64
|
-
})
|
|
65
|
-
.map(({ discountId }) => discountId);
|
|
66
|
-
|
|
67
|
-
return [...new Set(discountIds)]
|
|
68
|
-
.map((discountId) => {
|
|
69
|
-
const { currency, amount } = basePricingSheet.total({
|
|
70
|
-
category: DeliveryPricingRowCategory.Discount,
|
|
71
|
-
discountId,
|
|
72
|
-
});
|
|
73
|
-
if (!amount) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
discountId,
|
|
78
|
-
amount: Math.round(amount),
|
|
79
|
-
currency,
|
|
80
|
-
};
|
|
81
|
-
})
|
|
82
|
-
.filter(Boolean);
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
return pricingSheet;
|
|
87
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import type { Work } from '@unchainedshop/core-worker';
|
|
2
|
-
import type { TimestampFields } from '@unchainedshop/mongodb';
|
|
3
|
-
import type { User } from '@unchainedshop/core-users';
|
|
4
|
-
|
|
5
|
-
import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils';
|
|
6
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
7
|
-
import { Order } from '@unchainedshop/core-orders';
|
|
8
|
-
import { OrderDelivery } from '@unchainedshop/core-orders';
|
|
9
|
-
import { OrderPosition } from '@unchainedshop/core-orders';
|
|
10
|
-
import { Product } from '@unchainedshop/core-products';
|
|
11
|
-
import { WarehousingProvider } from '@unchainedshop/core-warehousing';
|
|
12
|
-
|
|
13
|
-
export enum DeliveryProviderType {
|
|
14
|
-
SHIPPING = 'SHIPPING',
|
|
15
|
-
PICKUP = 'PICKUP',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type DeliveryConfiguration = Array<{
|
|
19
|
-
key: string;
|
|
20
|
-
value: string;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export type DeliveryProvider = {
|
|
24
|
-
_id?: string;
|
|
25
|
-
type: DeliveryProviderType;
|
|
26
|
-
adapterKey: string;
|
|
27
|
-
configuration: DeliveryConfiguration;
|
|
28
|
-
} & TimestampFields;
|
|
29
|
-
|
|
30
|
-
export type DeliveryProviderQuery = {
|
|
31
|
-
type?: DeliveryProviderType;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export enum DeliveryError {
|
|
35
|
-
ADAPTER_NOT_FOUND = 'ADAPTER_NOT_FOUND',
|
|
36
|
-
NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
|
|
37
|
-
INCOMPLETE_CONFIGURATION = 'INCOMPLETE_CONFIGURATION',
|
|
38
|
-
WRONG_CREDENTIALS = 'WRONG_CREDENTIALS',
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface DeliveryContext {
|
|
42
|
-
country?: string;
|
|
43
|
-
deliveryProvider?: DeliveryProvider;
|
|
44
|
-
order?: Order;
|
|
45
|
-
orderDelivery?: OrderDelivery;
|
|
46
|
-
orderPosition?: OrderPosition;
|
|
47
|
-
product?: Product;
|
|
48
|
-
quantity?: number;
|
|
49
|
-
referenceDate?: Date;
|
|
50
|
-
transactionContext?: any;
|
|
51
|
-
user?: User;
|
|
52
|
-
warehousingProvider?: WarehousingProvider;
|
|
53
|
-
warehousingThroughputTime?: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type DeliveryAdapterContext = DeliveryContext & UnchainedCore;
|
|
57
|
-
|
|
58
|
-
export interface DeliveryLocation {
|
|
59
|
-
_id: string;
|
|
60
|
-
name: string;
|
|
61
|
-
address: {
|
|
62
|
-
addressLine: string;
|
|
63
|
-
addressLine2?: string;
|
|
64
|
-
postalCode: string;
|
|
65
|
-
countryCode: string;
|
|
66
|
-
city: string;
|
|
67
|
-
};
|
|
68
|
-
geoPoint: {
|
|
69
|
-
latitude: number;
|
|
70
|
-
longitude: number;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface DeliveryAdapterActions {
|
|
75
|
-
configurationError: (transactionContext?: any) => DeliveryError;
|
|
76
|
-
estimatedDeliveryThroughput: (warehousingThroughputTime: number) => Promise<number>;
|
|
77
|
-
isActive: () => boolean;
|
|
78
|
-
isAutoReleaseAllowed: () => boolean;
|
|
79
|
-
pickUpLocationById: (locationId: string) => Promise<DeliveryLocation>;
|
|
80
|
-
pickUpLocations: () => Promise<Array<DeliveryLocation>>;
|
|
81
|
-
send: () => Promise<boolean | Work>;
|
|
82
|
-
}
|
|
83
|
-
export type IDeliveryAdapter = IBaseAdapter & {
|
|
84
|
-
initialConfiguration: DeliveryConfiguration;
|
|
85
|
-
|
|
86
|
-
typeSupported: (type: DeliveryProviderType) => boolean;
|
|
87
|
-
|
|
88
|
-
actions: (config: DeliveryConfiguration, context: DeliveryAdapterContext) => DeliveryAdapterActions;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export type IDeliveryDirector = IBaseDirector<IDeliveryAdapter> & {
|
|
92
|
-
actions: (
|
|
93
|
-
deliveryProvider: DeliveryProvider,
|
|
94
|
-
deliveryContext: DeliveryContext,
|
|
95
|
-
unchainedAPI: UnchainedCore,
|
|
96
|
-
) => Promise<DeliveryAdapterActions>;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/*
|
|
100
|
-
* Module
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
export interface DeliveryInterface {
|
|
104
|
-
_id: string;
|
|
105
|
-
label: string;
|
|
106
|
-
version: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export type FilterProviders = (
|
|
110
|
-
params: {
|
|
111
|
-
providers: Array<DeliveryProvider>;
|
|
112
|
-
order: Order;
|
|
113
|
-
},
|
|
114
|
-
unchainedAPI: UnchainedCore,
|
|
115
|
-
) => Promise<Array<DeliveryProvider>>;
|