@unchainedshop/core-delivery 2.0.0-beta8 → 2.0.0-beta9
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/jest.config.js +9 -0
- package/lib/db/DeliveryProvidersSchema.js +0 -1
- package/lib/db/DeliveryProvidersSchema.js.map +1 -1
- package/lib/director/DeliveryDirector.js +2 -2
- package/lib/director/DeliveryDirector.js.map +1 -1
- package/lib/director/DeliveryPricingDirector.js +6 -6
- package/lib/director/DeliveryPricingDirector.js.map +1 -1
- package/lib/module/configureDeliveryModule.d.ts +5 -1
- package/lib/module/configureDeliveryModule.js +26 -26
- package/lib/module/configureDeliveryModule.js.map +1 -1
- package/package.json +10 -9
- package/src/db/DeliveryProvidersSchema.js +0 -1
- package/src/director/DeliveryDirector.ts +2 -2
- package/src/director/DeliveryPricingDirector.ts +6 -6
- package/src/module/configureDeliveryModule.ts +30 -34
- package/tests/delivery-index.test.ts +12 -19
package/jest.config.js
CHANGED
|
@@ -3,7 +3,6 @@ import SimpleSchema from 'simpl-schema';
|
|
|
3
3
|
export const DeliveryProvidersSchema = new SimpleSchema({
|
|
4
4
|
type: { type: String, required: true },
|
|
5
5
|
adapterKey: { type: String, required: true },
|
|
6
|
-
authorId: { type: String, required: true },
|
|
7
6
|
configuration: { type: Array },
|
|
8
7
|
'configuration.$': { type: Object },
|
|
9
8
|
'configuration.$.key': { type: String },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeliveryProvidersSchema.js","sourceRoot":"","sources":["../../src/db/DeliveryProvidersSchema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,YAAY,CACrD;IACE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC5C,
|
|
1
|
+
{"version":3,"file":"DeliveryProvidersSchema.js","sourceRoot":"","sources":["../../src/db/DeliveryProvidersSchema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,YAAY,CACrD;IACE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;IAC9B,iBAAiB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACnC,qBAAqB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACvC,uBAAuB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IACzC,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
|
|
@@ -4,9 +4,9 @@ import { DeliveryError } from './DeliveryError';
|
|
|
4
4
|
const baseDirector = BaseDirector('DeliveryDirector');
|
|
5
5
|
export const DeliveryDirector = {
|
|
6
6
|
...baseDirector,
|
|
7
|
-
actions: async (deliveryProvider, deliveryContext,
|
|
7
|
+
actions: async (deliveryProvider, deliveryContext, unchainedAPI) => {
|
|
8
8
|
const Adapter = baseDirector.getAdapter(deliveryProvider.adapterKey);
|
|
9
|
-
const context = { ...deliveryContext, ...
|
|
9
|
+
const context = { ...deliveryContext, ...unchainedAPI };
|
|
10
10
|
const adapter = Adapter.actions(deliveryProvider.configuration, context);
|
|
11
11
|
return {
|
|
12
12
|
configurationError: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeliveryDirector.js","sourceRoot":"","sources":["../../src/director/DeliveryDirector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,YAAY,GAAG,YAAY,CAAmB,kBAAkB,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,gBAAgB,GAAsB;IACjD,GAAG,YAAY;IAEf,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"DeliveryDirector.js","sourceRoot":"","sources":["../../src/director/DeliveryDirector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,YAAY,GAAG,YAAY,CAAmB,kBAAkB,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,gBAAgB,GAAsB;IACjD,GAAG,YAAY;IAEf,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,YAAY,EAAE,EAAE;QACjE,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAErE,MAAM,OAAO,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,YAAY,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAEzE,OAAO;YACL,kBAAkB,EAAE,GAAG,EAAE;gBACvB,IAAI;oBACF,OAAO,OAAO,CAAC,kBAAkB,EAAE,CAAC;iBACrC;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO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AAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -3,13 +3,13 @@ import { DeliveryPricingSheet } from './DeliveryPricingSheet';
|
|
|
3
3
|
const baseDirector = BasePricingDirector('DeliveryPricingDirector');
|
|
4
4
|
export const DeliveryPricingDirector = {
|
|
5
5
|
...baseDirector,
|
|
6
|
-
async buildPricingContext({ item, ...context },
|
|
7
|
-
const { modules } =
|
|
6
|
+
async buildPricingContext({ item, ...context }, unchainedAPI) {
|
|
7
|
+
const { modules } = unchainedAPI;
|
|
8
8
|
if (!item)
|
|
9
9
|
return {
|
|
10
10
|
discounts: [],
|
|
11
11
|
...context,
|
|
12
|
-
...
|
|
12
|
+
...unchainedAPI,
|
|
13
13
|
};
|
|
14
14
|
const order = await modules.orders.findOrder({
|
|
15
15
|
orderId: item.orderId,
|
|
@@ -25,7 +25,7 @@ export const DeliveryPricingDirector = {
|
|
|
25
25
|
country: order.countryCode,
|
|
26
26
|
currency: order.currency,
|
|
27
27
|
...context,
|
|
28
|
-
...
|
|
28
|
+
...unchainedAPI,
|
|
29
29
|
order,
|
|
30
30
|
orderDelivery: item,
|
|
31
31
|
provider,
|
|
@@ -33,8 +33,8 @@ export const DeliveryPricingDirector = {
|
|
|
33
33
|
discounts,
|
|
34
34
|
};
|
|
35
35
|
},
|
|
36
|
-
async actions(pricingContext,
|
|
37
|
-
const actions = await baseDirector.actions(pricingContext,
|
|
36
|
+
async actions(pricingContext, unchainedAPI) {
|
|
37
|
+
const actions = await baseDirector.actions(pricingContext, unchainedAPI, this.buildPricingContext);
|
|
38
38
|
return {
|
|
39
39
|
...actions,
|
|
40
40
|
calculationSheet() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeliveryPricingDirector.js","sourceRoot":"","sources":["../../src/director/DeliveryPricingDirector.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM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,OAAO;SACtB,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,WAAW;YAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,GAAG,OAAO;YACV,GAAG,YAAY;YACf,KAAK;YACL,aAAa,EAAE,IAAI;YACnB,QAAQ;YACR,IAAI;YACJ,SAAS;SACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,YAAY;QACxC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACnG,OAAO;YACL,GAAG,OAAO;YACV,gBAAgB;gBACd,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;gBACrC,OAAO,oBAAoB,CAAC;oBAC1B,WAAW,EAAE,OAAO,CAAC,cAAc,EAAE;oBACrC,QAAQ,EAAE,OAAO,CAAC,QAAQ;iBAC3B,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { ModuleInput } from '@unchainedshop/types/core';
|
|
2
|
-
import { DeliveryModule, DeliverySettingsOptions } from '@unchainedshop/types/delivery';
|
|
2
|
+
import { DeliveryModule, DeliveryProviderQuery, DeliverySettingsOptions } from '@unchainedshop/types/delivery';
|
|
3
|
+
export declare const buildFindSelector: ({ type }?: DeliveryProviderQuery) => {
|
|
4
|
+
deleted: any;
|
|
5
|
+
type?: import("@unchainedshop/types/delivery").DeliveryProviderType;
|
|
6
|
+
};
|
|
3
7
|
export declare const configureDeliveryModule: ({ db, options: deliveryOptions, }: ModuleInput<DeliverySettingsOptions>) => Promise<DeliveryModule>;
|
|
@@ -15,7 +15,7 @@ const asyncFilter = async (arr, predicate) => {
|
|
|
15
15
|
const results = await Promise.all(arr.map(predicate));
|
|
16
16
|
return arr.filter((_v, index) => results[index]);
|
|
17
17
|
};
|
|
18
|
-
const buildFindSelector = ({ type } = {}) => {
|
|
18
|
+
export const buildFindSelector = ({ type } = {}) => {
|
|
19
19
|
return { ...(type ? { type } : {}), deleted: null };
|
|
20
20
|
};
|
|
21
21
|
export const configureDeliveryModule = async ({ db, options: deliveryOptions = {}, }) => {
|
|
@@ -23,9 +23,9 @@ export const configureDeliveryModule = async ({ db, options: deliveryOptions = {
|
|
|
23
23
|
deliverySettings.configureSettings(deliveryOptions);
|
|
24
24
|
const DeliveryProviders = await DeliveryProvidersCollection(db);
|
|
25
25
|
const mutations = generateDbMutations(DeliveryProviders, DeliveryProvidersSchema);
|
|
26
|
-
const getDeliveryAdapter = async (deliveryProviderId, deliveryContext,
|
|
26
|
+
const getDeliveryAdapter = async (deliveryProviderId, deliveryContext, unchainedAPI) => {
|
|
27
27
|
const provider = await DeliveryProviders.findOne(generateDbFilterById(deliveryProviderId), {});
|
|
28
|
-
return DeliveryDirector.actions(provider, deliveryContext,
|
|
28
|
+
return DeliveryDirector.actions(provider, deliveryContext, unchainedAPI);
|
|
29
29
|
};
|
|
30
30
|
return {
|
|
31
31
|
// Queries
|
|
@@ -57,11 +57,11 @@ export const configureDeliveryModule = async ({ db, options: deliveryOptions = {
|
|
|
57
57
|
version: Adapter.version,
|
|
58
58
|
}));
|
|
59
59
|
},
|
|
60
|
-
findSupported: async (deliveryContext,
|
|
60
|
+
findSupported: async (deliveryContext, unchainedAPI) => {
|
|
61
61
|
const foundProviders = await DeliveryProviders.find(buildFindSelector({})).toArray();
|
|
62
62
|
const providers = await asyncFilter(foundProviders, async (provider) => {
|
|
63
63
|
try {
|
|
64
|
-
const director = await DeliveryDirector.actions(provider, deliveryContext,
|
|
64
|
+
const director = await DeliveryDirector.actions(provider, deliveryContext, unchainedAPI);
|
|
65
65
|
return director.isActive();
|
|
66
66
|
}
|
|
67
67
|
catch {
|
|
@@ -71,65 +71,65 @@ export const configureDeliveryModule = async ({ db, options: deliveryOptions = {
|
|
|
71
71
|
return deliverySettings.filterSupportedProviders({
|
|
72
72
|
providers,
|
|
73
73
|
order: deliveryContext.order,
|
|
74
|
-
},
|
|
74
|
+
}, unchainedAPI);
|
|
75
75
|
},
|
|
76
|
-
determineDefault: async (deliveryProviders, deliveryContext,
|
|
76
|
+
determineDefault: async (deliveryProviders, deliveryContext, unchainedAPI) => {
|
|
77
77
|
return deliverySettings.determineDefaultProvider({
|
|
78
78
|
providers: deliveryProviders,
|
|
79
79
|
...deliveryContext,
|
|
80
|
-
},
|
|
80
|
+
}, unchainedAPI);
|
|
81
81
|
},
|
|
82
|
-
configurationError: async (deliveryProvider,
|
|
83
|
-
const director = await DeliveryDirector.actions(deliveryProvider, {},
|
|
82
|
+
configurationError: async (deliveryProvider, unchainedAPI) => {
|
|
83
|
+
const director = await DeliveryDirector.actions(deliveryProvider, {}, unchainedAPI);
|
|
84
84
|
return director.configurationError();
|
|
85
85
|
},
|
|
86
|
-
isActive: async (deliveryProvider,
|
|
87
|
-
const director = await DeliveryDirector.actions(deliveryProvider, {},
|
|
86
|
+
isActive: async (deliveryProvider, unchainedAPI) => {
|
|
87
|
+
const director = await DeliveryDirector.actions(deliveryProvider, {}, unchainedAPI);
|
|
88
88
|
return Boolean(director.isActive());
|
|
89
89
|
},
|
|
90
|
-
isAutoReleaseAllowed: async (deliveryProvider,
|
|
91
|
-
const director = await DeliveryDirector.actions(deliveryProvider, {},
|
|
90
|
+
isAutoReleaseAllowed: async (deliveryProvider, unchainedAPI) => {
|
|
91
|
+
const director = await DeliveryDirector.actions(deliveryProvider, {}, unchainedAPI);
|
|
92
92
|
return Boolean(director.isAutoReleaseAllowed());
|
|
93
93
|
},
|
|
94
|
-
calculate: async (pricingContext,
|
|
95
|
-
const pricing = await DeliveryPricingDirector.actions(pricingContext,
|
|
94
|
+
calculate: async (pricingContext, unchainedAPI) => {
|
|
95
|
+
const pricing = await DeliveryPricingDirector.actions(pricingContext, unchainedAPI);
|
|
96
96
|
return pricing.calculate();
|
|
97
97
|
},
|
|
98
|
-
send: async (deliveryProviderId, deliveryContext,
|
|
99
|
-
const adapter = await getDeliveryAdapter(deliveryProviderId, deliveryContext,
|
|
98
|
+
send: async (deliveryProviderId, deliveryContext, unchainedAPI) => {
|
|
99
|
+
const adapter = await getDeliveryAdapter(deliveryProviderId, deliveryContext, unchainedAPI);
|
|
100
100
|
return adapter.send();
|
|
101
101
|
},
|
|
102
102
|
pricingSheet: (params) => {
|
|
103
103
|
return DeliveryPricingSheet(params);
|
|
104
104
|
},
|
|
105
105
|
// Mutations
|
|
106
|
-
create: async (doc
|
|
106
|
+
create: async (doc) => {
|
|
107
107
|
const Adapter = DeliveryDirector.getAdapter(doc.adapterKey);
|
|
108
108
|
if (!Adapter)
|
|
109
109
|
return null;
|
|
110
110
|
const deliveryProviderId = await mutations.create({
|
|
111
111
|
configuration: Adapter.initialConfiguration,
|
|
112
112
|
...doc,
|
|
113
|
-
}
|
|
113
|
+
});
|
|
114
114
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(deliveryProviderId), {});
|
|
115
115
|
await emit('DELIVERY_PROVIDER_CREATE', { deliveryProvider });
|
|
116
116
|
return deliveryProvider;
|
|
117
117
|
},
|
|
118
|
-
update: async (_id, doc
|
|
119
|
-
await mutations.update(_id, doc
|
|
118
|
+
update: async (_id, doc) => {
|
|
119
|
+
await mutations.update(_id, doc);
|
|
120
120
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(_id), {});
|
|
121
121
|
await emit('DELIVERY_PROVIDER_UPDATE', { deliveryProvider });
|
|
122
122
|
return deliveryProvider;
|
|
123
123
|
},
|
|
124
|
-
delete: async (_id
|
|
125
|
-
await mutations.delete(_id
|
|
124
|
+
delete: async (_id) => {
|
|
125
|
+
await mutations.delete(_id);
|
|
126
126
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(_id), {});
|
|
127
127
|
await emit('DELIVERY_PROVIDER_REMOVE', { deliveryProvider });
|
|
128
128
|
return deliveryProvider;
|
|
129
129
|
},
|
|
130
|
-
deletePermanently: async (_id
|
|
130
|
+
deletePermanently: async (_id) => {
|
|
131
131
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(_id), {});
|
|
132
|
-
await mutations.deletePermanently(_id
|
|
132
|
+
await mutations.deletePermanently(_id);
|
|
133
133
|
return deliveryProvider;
|
|
134
134
|
},
|
|
135
135
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureDeliveryModule.js","sourceRoot":"","sources":["../../src/module/configureDeliveryModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configureDeliveryModule.js","sourceRoot":"","sources":["../../src/module/configureDeliveryModule.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,MAAM,wBAAwB,GAAa;IACzC,0BAA0B;IAC1B,0BAA0B;IAC1B,0BAA0B;CAC3B,CAAC;AAEF,MAAM,WAAW,GAAG,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAEtD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,K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
|
6
6
|
".": "./lib/delivery-index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"clean": "rm -rf lib",
|
|
13
13
|
"build": "npm run clean && tsc",
|
|
14
14
|
"watch": "tsc -w",
|
|
15
|
-
"test": "jest --
|
|
15
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
16
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -30,16 +31,16 @@
|
|
|
30
31
|
},
|
|
31
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@unchainedshop/events": "^2.0.0-
|
|
34
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
35
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
36
|
-
"simpl-schema": "^3.0
|
|
34
|
+
"@unchainedshop/events": "^2.0.0-beta9",
|
|
35
|
+
"@unchainedshop/logger": "^2.0.0-beta9",
|
|
36
|
+
"@unchainedshop/utils": "^2.0.0-beta9",
|
|
37
|
+
"simpl-schema": "^3.2.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^18.11.
|
|
40
|
-
"@unchainedshop/types": "^2.0.0-
|
|
40
|
+
"@types/node": "^18.11.12",
|
|
41
|
+
"@unchainedshop/types": "^2.0.0-beta9",
|
|
41
42
|
"jest": "^29.3.1",
|
|
42
43
|
"ts-jest": "^29.0.3",
|
|
43
|
-
"typescript": "^4.9.
|
|
44
|
+
"typescript": "^4.9.4"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -5,7 +5,6 @@ export const DeliveryProvidersSchema = new SimpleSchema(
|
|
|
5
5
|
{
|
|
6
6
|
type: { type: String, required: true },
|
|
7
7
|
adapterKey: { type: String, required: true },
|
|
8
|
-
authorId: { type: String, required: true },
|
|
9
8
|
configuration: { type: Array },
|
|
10
9
|
'configuration.$': { type: Object },
|
|
11
10
|
'configuration.$.key': { type: String },
|
|
@@ -8,10 +8,10 @@ const baseDirector = BaseDirector<IDeliveryAdapter>('DeliveryDirector');
|
|
|
8
8
|
export const DeliveryDirector: IDeliveryDirector = {
|
|
9
9
|
...baseDirector,
|
|
10
10
|
|
|
11
|
-
actions: async (deliveryProvider, deliveryContext,
|
|
11
|
+
actions: async (deliveryProvider, deliveryContext, unchainedAPI) => {
|
|
12
12
|
const Adapter = baseDirector.getAdapter(deliveryProvider.adapterKey);
|
|
13
13
|
|
|
14
|
-
const context = { ...deliveryContext, ...
|
|
14
|
+
const context = { ...deliveryContext, ...unchainedAPI };
|
|
15
15
|
const adapter = Adapter.actions(deliveryProvider.configuration, context);
|
|
16
16
|
|
|
17
17
|
return {
|
|
@@ -18,14 +18,14 @@ const baseDirector = BasePricingDirector<
|
|
|
18
18
|
export const DeliveryPricingDirector: IDeliveryPricingDirector = {
|
|
19
19
|
...baseDirector,
|
|
20
20
|
|
|
21
|
-
async buildPricingContext({ item, ...context },
|
|
22
|
-
const { modules } =
|
|
21
|
+
async buildPricingContext({ item, ...context }, unchainedAPI) {
|
|
22
|
+
const { modules } = unchainedAPI;
|
|
23
23
|
|
|
24
24
|
if (!item)
|
|
25
25
|
return {
|
|
26
26
|
discounts: [],
|
|
27
27
|
...context,
|
|
28
|
-
...
|
|
28
|
+
...unchainedAPI,
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
const order = await modules.orders.findOrder({
|
|
@@ -43,7 +43,7 @@ export const DeliveryPricingDirector: IDeliveryPricingDirector = {
|
|
|
43
43
|
country: order.countryCode,
|
|
44
44
|
currency: order.currency,
|
|
45
45
|
...context,
|
|
46
|
-
...
|
|
46
|
+
...unchainedAPI,
|
|
47
47
|
order,
|
|
48
48
|
orderDelivery: item,
|
|
49
49
|
provider,
|
|
@@ -52,8 +52,8 @@ export const DeliveryPricingDirector: IDeliveryPricingDirector = {
|
|
|
52
52
|
};
|
|
53
53
|
},
|
|
54
54
|
|
|
55
|
-
async actions(pricingContext,
|
|
56
|
-
const actions = await baseDirector.actions(pricingContext,
|
|
55
|
+
async actions(pricingContext, unchainedAPI) {
|
|
56
|
+
const actions = await baseDirector.actions(pricingContext, unchainedAPI, this.buildPricingContext);
|
|
57
57
|
return {
|
|
58
58
|
...actions,
|
|
59
59
|
calculationSheet() {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/core';
|
|
1
|
+
import { ModuleInput, ModuleMutations, UnchainedCore } from '@unchainedshop/types/core';
|
|
3
2
|
import {
|
|
4
3
|
DeliveryContext,
|
|
5
4
|
DeliveryModule,
|
|
@@ -28,7 +27,7 @@ const asyncFilter = async (arr, predicate) => {
|
|
|
28
27
|
return arr.filter((_v, index) => results[index]);
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
const buildFindSelector = ({ type }: DeliveryProviderQuery = {}) => {
|
|
30
|
+
export const buildFindSelector = ({ type }: DeliveryProviderQuery = {}) => {
|
|
32
31
|
return { ...(type ? { type } : {}), deleted: null };
|
|
33
32
|
};
|
|
34
33
|
|
|
@@ -50,11 +49,11 @@ export const configureDeliveryModule = async ({
|
|
|
50
49
|
const getDeliveryAdapter = async (
|
|
51
50
|
deliveryProviderId: string,
|
|
52
51
|
deliveryContext: DeliveryContext,
|
|
53
|
-
|
|
52
|
+
unchainedAPI: UnchainedCore,
|
|
54
53
|
) => {
|
|
55
54
|
const provider = await DeliveryProviders.findOne(generateDbFilterById(deliveryProviderId), {});
|
|
56
55
|
|
|
57
|
-
return DeliveryDirector.actions(provider, deliveryContext,
|
|
56
|
+
return DeliveryDirector.actions(provider, deliveryContext, unchainedAPI);
|
|
58
57
|
};
|
|
59
58
|
|
|
60
59
|
return {
|
|
@@ -100,13 +99,13 @@ export const configureDeliveryModule = async ({
|
|
|
100
99
|
}));
|
|
101
100
|
},
|
|
102
101
|
|
|
103
|
-
findSupported: async (deliveryContext,
|
|
102
|
+
findSupported: async (deliveryContext, unchainedAPI) => {
|
|
104
103
|
const foundProviders = await DeliveryProviders.find(buildFindSelector({})).toArray();
|
|
105
104
|
const providers: DeliveryProvider[] = await asyncFilter(
|
|
106
105
|
foundProviders,
|
|
107
106
|
async (provider: DeliveryProvider) => {
|
|
108
107
|
try {
|
|
109
|
-
const director = await DeliveryDirector.actions(provider, deliveryContext,
|
|
108
|
+
const director = await DeliveryDirector.actions(provider, deliveryContext, unchainedAPI);
|
|
110
109
|
return director.isActive();
|
|
111
110
|
} catch {
|
|
112
111
|
return false;
|
|
@@ -119,42 +118,42 @@ export const configureDeliveryModule = async ({
|
|
|
119
118
|
providers,
|
|
120
119
|
order: deliveryContext.order,
|
|
121
120
|
},
|
|
122
|
-
|
|
121
|
+
unchainedAPI,
|
|
123
122
|
);
|
|
124
123
|
},
|
|
125
124
|
|
|
126
|
-
determineDefault: async (deliveryProviders, deliveryContext,
|
|
125
|
+
determineDefault: async (deliveryProviders, deliveryContext, unchainedAPI) => {
|
|
127
126
|
return deliverySettings.determineDefaultProvider(
|
|
128
127
|
{
|
|
129
128
|
providers: deliveryProviders,
|
|
130
129
|
...deliveryContext,
|
|
131
130
|
},
|
|
132
|
-
|
|
131
|
+
unchainedAPI,
|
|
133
132
|
);
|
|
134
133
|
},
|
|
135
134
|
|
|
136
|
-
configurationError: async (deliveryProvider,
|
|
137
|
-
const director = await DeliveryDirector.actions(deliveryProvider, {},
|
|
135
|
+
configurationError: async (deliveryProvider, unchainedAPI) => {
|
|
136
|
+
const director = await DeliveryDirector.actions(deliveryProvider, {}, unchainedAPI);
|
|
138
137
|
return director.configurationError();
|
|
139
138
|
},
|
|
140
139
|
|
|
141
|
-
isActive: async (deliveryProvider,
|
|
142
|
-
const director = await DeliveryDirector.actions(deliveryProvider, {},
|
|
140
|
+
isActive: async (deliveryProvider, unchainedAPI) => {
|
|
141
|
+
const director = await DeliveryDirector.actions(deliveryProvider, {}, unchainedAPI);
|
|
143
142
|
return Boolean(director.isActive());
|
|
144
143
|
},
|
|
145
144
|
|
|
146
|
-
isAutoReleaseAllowed: async (deliveryProvider,
|
|
147
|
-
const director = await DeliveryDirector.actions(deliveryProvider, {},
|
|
145
|
+
isAutoReleaseAllowed: async (deliveryProvider, unchainedAPI) => {
|
|
146
|
+
const director = await DeliveryDirector.actions(deliveryProvider, {}, unchainedAPI);
|
|
148
147
|
return Boolean(director.isAutoReleaseAllowed());
|
|
149
148
|
},
|
|
150
149
|
|
|
151
|
-
calculate: async (pricingContext,
|
|
152
|
-
const pricing = await DeliveryPricingDirector.actions(pricingContext,
|
|
150
|
+
calculate: async (pricingContext, unchainedAPI) => {
|
|
151
|
+
const pricing = await DeliveryPricingDirector.actions(pricingContext, unchainedAPI);
|
|
153
152
|
return pricing.calculate();
|
|
154
153
|
},
|
|
155
154
|
|
|
156
|
-
send: async (deliveryProviderId, deliveryContext,
|
|
157
|
-
const adapter = await getDeliveryAdapter(deliveryProviderId, deliveryContext,
|
|
155
|
+
send: async (deliveryProviderId, deliveryContext, unchainedAPI) => {
|
|
156
|
+
const adapter = await getDeliveryAdapter(deliveryProviderId, deliveryContext, unchainedAPI);
|
|
158
157
|
return adapter.send();
|
|
159
158
|
},
|
|
160
159
|
|
|
@@ -163,17 +162,14 @@ export const configureDeliveryModule = async ({
|
|
|
163
162
|
},
|
|
164
163
|
|
|
165
164
|
// Mutations
|
|
166
|
-
create: async (doc
|
|
165
|
+
create: async (doc) => {
|
|
167
166
|
const Adapter = DeliveryDirector.getAdapter(doc.adapterKey);
|
|
168
167
|
if (!Adapter) return null;
|
|
169
168
|
|
|
170
|
-
const deliveryProviderId = await mutations.create(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
userId,
|
|
176
|
-
);
|
|
169
|
+
const deliveryProviderId = await mutations.create({
|
|
170
|
+
configuration: Adapter.initialConfiguration,
|
|
171
|
+
...doc,
|
|
172
|
+
});
|
|
177
173
|
const deliveryProvider = await DeliveryProviders.findOne(
|
|
178
174
|
generateDbFilterById(deliveryProviderId),
|
|
179
175
|
{},
|
|
@@ -182,23 +178,23 @@ export const configureDeliveryModule = async ({
|
|
|
182
178
|
return deliveryProvider;
|
|
183
179
|
},
|
|
184
180
|
|
|
185
|
-
update: async (_id: string, doc: DeliveryProvider
|
|
186
|
-
await mutations.update(_id, doc
|
|
181
|
+
update: async (_id: string, doc: DeliveryProvider) => {
|
|
182
|
+
await mutations.update(_id, doc);
|
|
187
183
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(_id), {});
|
|
188
184
|
await emit('DELIVERY_PROVIDER_UPDATE', { deliveryProvider });
|
|
189
185
|
return deliveryProvider;
|
|
190
186
|
},
|
|
191
187
|
|
|
192
|
-
delete: async (_id
|
|
193
|
-
await mutations.delete(_id
|
|
188
|
+
delete: async (_id) => {
|
|
189
|
+
await mutations.delete(_id);
|
|
194
190
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(_id), {});
|
|
195
191
|
await emit('DELIVERY_PROVIDER_REMOVE', { deliveryProvider });
|
|
196
192
|
return deliveryProvider;
|
|
197
193
|
},
|
|
198
194
|
|
|
199
|
-
deletePermanently: async (_id
|
|
195
|
+
deletePermanently: async (_id) => {
|
|
200
196
|
const deliveryProvider = await DeliveryProviders.findOne(generateDbFilterById(_id), {});
|
|
201
|
-
await mutations.deletePermanently(_id
|
|
197
|
+
await mutations.deletePermanently(_id);
|
|
202
198
|
return deliveryProvider;
|
|
203
199
|
},
|
|
204
200
|
};
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { configureDeliveryModule } from '../src/delivery-index';
|
|
1
|
+
import { DeliveryProviderType } from "../src/director/DeliveryProviderType";
|
|
2
|
+
import { buildFindSelector } from "../src/module/configureDeliveryModule";
|
|
4
3
|
|
|
5
|
-
describe('
|
|
6
|
-
|
|
4
|
+
describe('Delivery', () => {
|
|
5
|
+
describe('buildFindSelector', () => {
|
|
6
|
+
it('Return correct filter object when passed no argument', async () => {
|
|
7
|
+
expect(buildFindSelector({})).toEqual({ deleted: null })
|
|
8
|
+
});
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it('Check Delivery module', async () => {
|
|
14
|
-
assert.ok(module);
|
|
15
|
-
assert.isFunction(module.findProvider);
|
|
16
|
-
assert.isFunction(module.findDelivery);
|
|
17
|
-
assert.isFunction(module.providerExists);
|
|
18
|
-
assert.isFunction(module.create);
|
|
19
|
-
assert.isFunction(module.update);
|
|
20
|
-
assert.isFunction(module.delete);
|
|
21
|
-
});
|
|
10
|
+
it('Return correct filter object when passed no argument', async () => {
|
|
11
|
+
expect(buildFindSelector({type: DeliveryProviderType.PICKUP})).toEqual({ type: 'PICKUP', deleted: null })
|
|
12
|
+
});
|
|
13
|
+
})
|
|
14
|
+
|
|
22
15
|
});
|