@unchainedshop/platform 3.0.0-alpha7 → 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/bulk-importer/createBulkImporter.d.ts +4 -1
- package/lib/bulk-importer/createBulkImporter.d.ts.map +1 -1
- package/lib/bulk-importer/createBulkImporter.js +13 -15
- package/lib/bulk-importer/createBulkImporter.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/create.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/filter/create.js +2 -2
- package/lib/bulk-importer/handlers/filter/create.js.map +1 -1
- package/lib/bulk-importer/handlers/filter/update.d.ts.map +1 -1
- package/lib/bulk-importer/handlers/filter/update.js +1 -1
- package/lib/bulk-importer/handlers/filter/update.js.map +1 -1
- package/lib/bulk-importer/handlers/product/remove.js +1 -1
- package/lib/bulk-importer/handlers/product/remove.js.map +1 -1
- package/lib/bulk-importer/upsertAsset.d.ts.map +1 -1
- package/lib/bulk-importer/upsertAsset.js +1 -1
- package/lib/bulk-importer/upsertAsset.js.map +1 -1
- package/lib/context/setAccessToken.js +2 -2
- package/lib/context/setAccessToken.js.map +1 -1
- package/lib/migrations/migrationRepository.js +1 -1
- package/lib/migrations/migrationRepository.js.map +1 -1
- package/lib/migrations/runMigrations.js +2 -2
- package/lib/migrations/runMigrations.js.map +1 -1
- package/lib/platform-index.d.ts +2 -0
- package/lib/platform-index.d.ts.map +1 -1
- package/lib/platform-index.js +2 -0
- package/lib/platform-index.js.map +1 -1
- package/lib/setup/setupCarts.d.ts.map +1 -1
- package/lib/setup/setupCarts.js +5 -2
- package/lib/setup/setupCarts.js.map +1 -1
- package/lib/setup/setupTemplates.d.ts.map +1 -1
- package/lib/setup/setupTemplates.js +4 -4
- package/lib/setup/setupTemplates.js.map +1 -1
- package/lib/setup/setupUploadHandlers.d.ts +3 -0
- package/lib/setup/setupUploadHandlers.d.ts.map +1 -0
- package/lib/setup/setupUploadHandlers.js +19 -0
- package/lib/setup/setupUploadHandlers.js.map +1 -0
- package/lib/setup/setupWorkqueue.d.ts +3 -2
- package/lib/setup/setupWorkqueue.d.ts.map +1 -1
- package/lib/setup/setupWorkqueue.js +3 -1
- package/lib/setup/setupWorkqueue.js.map +1 -1
- package/lib/startPlatform.d.ts.map +1 -1
- package/lib/startPlatform.js +5 -2
- package/lib/startPlatform.js.map +1 -1
- package/lib/templates/index.d.ts +9 -0
- package/lib/templates/index.d.ts.map +1 -0
- package/lib/templates/index.js +9 -0
- package/lib/templates/index.js.map +1 -0
- package/lib/templates/order-parser/getOrderPositionsData.d.ts +2 -6
- package/lib/templates/order-parser/getOrderPositionsData.d.ts.map +1 -1
- package/lib/templates/order-parser/getOrderPositionsData.js +8 -8
- package/lib/templates/order-parser/getOrderPositionsData.js.map +1 -1
- package/lib/templates/order-parser/getOrderSummaryData.d.ts +2 -2
- package/lib/templates/order-parser/getOrderSummaryData.d.ts.map +1 -1
- package/lib/templates/order-parser/getOrderSummaryData.js +9 -7
- package/lib/templates/order-parser/getOrderSummaryData.js.map +1 -1
- package/lib/templates/order-parser/index.d.ts +8 -3
- package/lib/templates/order-parser/index.d.ts.map +1 -1
- package/lib/templates/order-parser/index.js +4 -4
- package/lib/templates/order-parser/index.js.map +1 -1
- package/lib/templates/resolveAccountActionTemplate.d.ts +1 -1
- package/lib/templates/resolveAccountActionTemplate.d.ts.map +1 -1
- package/lib/templates/resolveAccountActionTemplate.js +4 -3
- package/lib/templates/resolveAccountActionTemplate.js.map +1 -1
- package/lib/templates/resolveEnrollmentStatusTemplate.d.ts +1 -1
- package/lib/templates/resolveEnrollmentStatusTemplate.d.ts.map +1 -1
- package/lib/templates/resolveEnrollmentStatusTemplate.js +4 -3
- package/lib/templates/resolveEnrollmentStatusTemplate.js.map +1 -1
- package/lib/templates/resolveErrorReportTemplate.d.ts +1 -1
- package/lib/templates/resolveErrorReportTemplate.d.ts.map +1 -1
- package/lib/templates/resolveErrorReportTemplate.js +10 -9
- package/lib/templates/resolveErrorReportTemplate.js.map +1 -1
- package/lib/templates/resolveForwardDeliveryTemplate.d.ts +1 -1
- package/lib/templates/resolveForwardDeliveryTemplate.d.ts.map +1 -1
- package/lib/templates/resolveForwardDeliveryTemplate.js +5 -4
- package/lib/templates/resolveForwardDeliveryTemplate.js.map +1 -1
- package/lib/templates/resolveOrderConfirmationTemplate.d.ts +5 -2
- package/lib/templates/resolveOrderConfirmationTemplate.d.ts.map +1 -1
- package/lib/templates/resolveOrderConfirmationTemplate.js +4 -3
- package/lib/templates/resolveOrderConfirmationTemplate.js.map +1 -1
- package/lib/templates/resolveOrderRejectionTemplate.d.ts +1 -1
- package/lib/templates/resolveOrderRejectionTemplate.d.ts.map +1 -1
- package/lib/templates/resolveOrderRejectionTemplate.js +4 -3
- package/lib/templates/resolveOrderRejectionTemplate.js.map +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.d.ts +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.d.ts.map +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.js +4 -3
- package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -1
- package/package.json +25 -23
- package/src/bulk-importer/createBulkImporter.ts +16 -21
- package/src/bulk-importer/handlers/filter/create.ts +9 -18
- package/src/bulk-importer/handlers/filter/update.ts +4 -9
- package/src/bulk-importer/handlers/product/remove.ts +1 -1
- package/src/bulk-importer/upsertAsset.ts +9 -12
- package/src/context/setAccessToken.ts +2 -2
- package/src/migrations/migrationRepository.ts +1 -1
- package/src/migrations/runMigrations.ts +2 -2
- package/src/platform-index.ts +2 -0
- package/src/setup/setupCarts.ts +10 -9
- package/src/setup/setupTemplates.ts +5 -6
- package/src/setup/setupUploadHandlers.ts +22 -0
- package/src/setup/setupWorkqueue.ts +5 -9
- package/src/startPlatform.ts +6 -2
- package/src/templates/index.ts +9 -0
- package/src/templates/order-parser/getOrderPositionsData.ts +10 -13
- package/src/templates/order-parser/getOrderSummaryData.ts +12 -9
- package/src/templates/order-parser/index.ts +21 -10
- package/src/templates/resolveAccountActionTemplate.ts +14 -8
- package/src/templates/resolveEnrollmentStatusTemplate.ts +14 -9
- package/src/templates/resolveErrorReportTemplate.ts +16 -10
- package/src/templates/resolveForwardDeliveryTemplate.ts +13 -7
- package/src/templates/resolveOrderConfirmationTemplate.ts +17 -11
- package/src/templates/resolveOrderRejectionTemplate.ts +13 -7
- package/src/templates/resolveQuotationStatusTemplate.ts +14 -8
- package/tsconfig.json +5 -7
- package/lib/templates/order-parser/formatAddress.d.ts +0 -3
- package/lib/templates/order-parser/formatAddress.d.ts.map +0 -1
- package/lib/templates/order-parser/formatAddress.js +0 -14
- package/lib/templates/order-parser/formatAddress.js.map +0 -1
- package/lib/templates/order-parser/formatPrice.d.ts +0 -6
- package/lib/templates/order-parser/formatPrice.d.ts.map +0 -1
- package/lib/templates/order-parser/formatPrice.js +0 -6
- package/lib/templates/order-parser/formatPrice.js.map +0 -1
- package/src/templates/order-parser/formatAddress.ts +0 -15
- package/src/templates/order-parser/formatPrice.ts +0 -6
package/package.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/platform",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc10",
|
|
4
4
|
"main": "lib/platform-index.js",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": "./lib/platform-index.js",
|
|
7
|
-
"./*": "./lib/*"
|
|
8
|
-
},
|
|
9
5
|
"types": "lib/platform-index.d.ts",
|
|
10
6
|
"type": "module",
|
|
11
7
|
"scripts": {
|
|
12
|
-
"clean": "
|
|
13
|
-
"
|
|
8
|
+
"clean": "tsc -b --clean",
|
|
9
|
+
"build": "tsc -b",
|
|
10
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
14
11
|
"watch": "tsc -w",
|
|
15
12
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
16
13
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
@@ -24,31 +21,36 @@
|
|
|
24
21
|
"ecommerce",
|
|
25
22
|
"core"
|
|
26
23
|
],
|
|
27
|
-
"
|
|
24
|
+
"authors": [
|
|
25
|
+
"Joël Meiller",
|
|
26
|
+
"Pascal Kaufmann"
|
|
27
|
+
],
|
|
28
28
|
"license": "EUPL-1.2",
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/unchainedshop/unchained/issues"
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22.0.0"
|
|
35
|
+
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/api": "^3.0.0-
|
|
35
|
-
"@unchainedshop/core": "^3.0.0-
|
|
36
|
-
"@unchainedshop/events": "^3.0.0-
|
|
37
|
-
"@unchainedshop/file-upload": "^3.0.0-
|
|
38
|
-
"@unchainedshop/logger": "^3.0.0-
|
|
39
|
-
"@unchainedshop/mongodb": "^3.0.0-
|
|
40
|
-
"@unchainedshop/plugins": "^3.0.0-
|
|
41
|
-
"@unchainedshop/roles": "^3.0.0-
|
|
42
|
-
"@unchainedshop/utils": "^3.0.0-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"moniker": "0.1.2"
|
|
37
|
+
"@unchainedshop/api": "^3.0.0-rc10",
|
|
38
|
+
"@unchainedshop/core": "^3.0.0-rc10",
|
|
39
|
+
"@unchainedshop/events": "^3.0.0-rc10",
|
|
40
|
+
"@unchainedshop/file-upload": "^3.0.0-rc10",
|
|
41
|
+
"@unchainedshop/logger": "^3.0.0-rc10",
|
|
42
|
+
"@unchainedshop/mongodb": "^3.0.0-rc10",
|
|
43
|
+
"@unchainedshop/plugins": "^3.0.0-rc10",
|
|
44
|
+
"@unchainedshop/roles": "^3.0.0-rc10",
|
|
45
|
+
"@unchainedshop/utils": "^3.0.0-rc10",
|
|
46
|
+
"mustache": "^4.2.0",
|
|
47
|
+
"safe-stable-stringify": "^2.5.0"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@types/
|
|
49
|
-
"
|
|
50
|
+
"@types/mustache": "^4.2.5",
|
|
51
|
+
"@types/node": "^22.10.2",
|
|
50
52
|
"jest": "^29.7.0",
|
|
51
53
|
"ts-jest": "^29.2.5",
|
|
52
|
-
"typescript": "^5.
|
|
54
|
+
"typescript": "^5.7.2"
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -3,6 +3,9 @@ import { BulkImporter, UnchainedCore } from '@unchainedshop/core';
|
|
|
3
3
|
import * as AssortmentHandlers from './handlers/assortment/index.js';
|
|
4
4
|
import * as FilterHandlers from './handlers/filter/index.js';
|
|
5
5
|
import * as ProductHandlers from './handlers/product/index.js';
|
|
6
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
7
|
+
|
|
8
|
+
const logger = createLogger('unchained:bulk-import');
|
|
6
9
|
|
|
7
10
|
export type BulkImportOperationResult = {
|
|
8
11
|
entity: string;
|
|
@@ -16,7 +19,6 @@ export type BulkImportOperation = (
|
|
|
16
19
|
createShouldUpsertIfIDExists?: boolean;
|
|
17
20
|
updateShouldUpsertIfIDNotExists?: boolean;
|
|
18
21
|
skipCacheInvalidation?: boolean;
|
|
19
|
-
logger?: any;
|
|
20
22
|
},
|
|
21
23
|
unchainedAPI: UnchainedCore,
|
|
22
24
|
) => Promise<BulkImportOperationResult>;
|
|
@@ -54,12 +56,8 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
|
|
|
54
56
|
const bulkOperations = {};
|
|
55
57
|
const preparationIssues = [];
|
|
56
58
|
const processedOperations = {};
|
|
57
|
-
const {
|
|
58
|
-
|
|
59
|
-
createShouldUpsertIfIDExists,
|
|
60
|
-
skipCacheInvalidation,
|
|
61
|
-
updateShouldUpsertIfIDNotExists,
|
|
62
|
-
} = options;
|
|
59
|
+
const { createShouldUpsertIfIDExists, skipCacheInvalidation, updateShouldUpsertIfIDNotExists } =
|
|
60
|
+
options;
|
|
63
61
|
|
|
64
62
|
const bulk = (collectionName: string) => {
|
|
65
63
|
const Collection = db.collection(collectionName);
|
|
@@ -68,7 +66,7 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
|
|
|
68
66
|
return bulkOperations[collectionName];
|
|
69
67
|
};
|
|
70
68
|
|
|
71
|
-
logger.
|
|
69
|
+
logger.debug(
|
|
72
70
|
`Configure event import with options: createShouldUpsertIfIDExists=${createShouldUpsertIfIDExists} updateShouldUpsertIfIDNotExists=${updateShouldUpsertIfIDNotExists} skipCacheInvalidation=${skipCacheInvalidation}`,
|
|
73
71
|
);
|
|
74
72
|
|
|
@@ -81,19 +79,16 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
|
|
|
81
79
|
|
|
82
80
|
const payloadId = event.payload?._id || 'global';
|
|
83
81
|
|
|
84
|
-
logger.
|
|
85
|
-
logger.profile(`${operation} ${entity} ${payloadId} [DONE]`, {
|
|
86
|
-
level: 'verbose',
|
|
87
|
-
});
|
|
82
|
+
logger.debug(`${operation} ${entity} ${payloadId} [PREPARE]`);
|
|
88
83
|
|
|
89
84
|
try {
|
|
90
|
-
await handler(event.payload, { bulk, ...options }, unchainedAPI);
|
|
85
|
+
await handler(event.payload, { bulk, logger, ...options }, unchainedAPI);
|
|
91
86
|
if (!processedOperations[entity]) processedOperations[entity] = {};
|
|
92
87
|
if (!processedOperations[entity][operation]) processedOperations[entity][operation] = [];
|
|
93
88
|
processedOperations[entity][operation].push(payloadId);
|
|
94
|
-
logger.
|
|
89
|
+
logger.debug(`${operation} ${entity} ${payloadId} [SUCCESS]`);
|
|
95
90
|
} catch (e) {
|
|
96
|
-
logger.
|
|
91
|
+
logger.debug(`${operation} ${entity} ${payloadId} [FAILED]`, e);
|
|
97
92
|
preparationIssues.push({
|
|
98
93
|
operation,
|
|
99
94
|
entity,
|
|
@@ -102,13 +97,11 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
|
|
|
102
97
|
errorMessage: e.message,
|
|
103
98
|
});
|
|
104
99
|
} finally {
|
|
105
|
-
logger.
|
|
106
|
-
level: 'verbose',
|
|
107
|
-
});
|
|
100
|
+
logger.debug(`${operation} ${entity} ${payloadId} [DONE]`);
|
|
108
101
|
}
|
|
109
102
|
},
|
|
110
103
|
execute: async () => {
|
|
111
|
-
logger.
|
|
104
|
+
logger.debug(`Execute bulk operations for: ${Object.keys(bulkOperations).join(', ')}`);
|
|
112
105
|
|
|
113
106
|
const processedBulkOperations = await Promise.allSettled(
|
|
114
107
|
Object.values(bulkOperations).map(async (o: any) => o.execute()),
|
|
@@ -124,13 +117,13 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
|
|
|
124
117
|
const errors = { preparationIssues };
|
|
125
118
|
return [operationResults, errors];
|
|
126
119
|
}
|
|
127
|
-
logger.
|
|
120
|
+
logger.debug(`Import finished without errors`);
|
|
128
121
|
return [operationResults, null];
|
|
129
122
|
},
|
|
130
123
|
invalidateCaches: async (unchainedAPI: UnchainedCore) => {
|
|
131
124
|
if (skipCacheInvalidation) return;
|
|
132
125
|
await unchainedAPI.modules.assortments.invalidateCache({}, { skipUpstreamTraversal: true });
|
|
133
|
-
await unchainedAPI.
|
|
126
|
+
await unchainedAPI.services.filters.invalidateFilterCache();
|
|
134
127
|
},
|
|
135
128
|
};
|
|
136
129
|
};
|
|
@@ -139,3 +132,5 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
|
|
|
139
132
|
createBulkImporter,
|
|
140
133
|
};
|
|
141
134
|
};
|
|
135
|
+
|
|
136
|
+
export { AssortmentHandlers, ProductHandlers, FilterHandlers };
|
|
@@ -16,28 +16,19 @@ export default async function createFilter(
|
|
|
16
16
|
|
|
17
17
|
logger.debug('create filter object', specification);
|
|
18
18
|
try {
|
|
19
|
-
await unchainedAPI.modules.filters.create(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
unchainedAPI,
|
|
26
|
-
{ skipInvalidation: true },
|
|
27
|
-
);
|
|
19
|
+
await unchainedAPI.modules.filters.create({
|
|
20
|
+
...filterData,
|
|
21
|
+
_id,
|
|
22
|
+
options: options?.map((option) => option.value) || [],
|
|
23
|
+
});
|
|
28
24
|
} catch (e) {
|
|
29
25
|
if (!createShouldUpsertIfIDExists) throw e;
|
|
30
26
|
|
|
31
27
|
logger.debug('entity already exists, falling back to update', specification);
|
|
32
|
-
await modules.filters.update(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
options: options?.map((option) => option.value) || [],
|
|
37
|
-
},
|
|
38
|
-
unchainedAPI,
|
|
39
|
-
{ skipInvalidation: true },
|
|
40
|
-
);
|
|
28
|
+
await modules.filters.update(_id, {
|
|
29
|
+
...filterData,
|
|
30
|
+
options: options?.map((option) => option.value) || [],
|
|
31
|
+
});
|
|
41
32
|
}
|
|
42
33
|
|
|
43
34
|
if (!(await modules.filters.filterExists({ filterId: _id }))) {
|
|
@@ -20,15 +20,10 @@ export default async function updateFilter(
|
|
|
20
20
|
|
|
21
21
|
if (specification) {
|
|
22
22
|
logger.debug('update filter object', specification);
|
|
23
|
-
await modules.filters.update(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
options: options?.map((option) => option.value) || [],
|
|
28
|
-
},
|
|
29
|
-
unchainedAPI,
|
|
30
|
-
{ skipInvalidation: true },
|
|
31
|
-
);
|
|
23
|
+
await modules.filters.update(_id, {
|
|
24
|
+
...filterData,
|
|
25
|
+
options: options?.map((option) => option.value) || [],
|
|
26
|
+
});
|
|
32
27
|
}
|
|
33
28
|
|
|
34
29
|
if (content) {
|
|
@@ -5,7 +5,7 @@ export default async function removeProduct(payload: any, { logger }, unchainedA
|
|
|
5
5
|
const { _id } = payload;
|
|
6
6
|
logger.debug(`remove product ${_id}`);
|
|
7
7
|
|
|
8
|
-
await services.products.removeProduct({ productId: _id }
|
|
8
|
+
await services.products.removeProduct({ productId: _id });
|
|
9
9
|
|
|
10
10
|
return {
|
|
11
11
|
entity: 'PRODUCT',
|
|
@@ -20,19 +20,16 @@ const upsertAsset = async (
|
|
|
20
20
|
return updatedFile;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const assetObject = await services.files.uploadFileFromURL(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
headers,
|
|
31
|
-
},
|
|
32
|
-
meta,
|
|
23
|
+
const assetObject = await services.files.uploadFileFromURL({
|
|
24
|
+
directoryName,
|
|
25
|
+
fileInput: {
|
|
26
|
+
fileLink: url,
|
|
27
|
+
fileName,
|
|
28
|
+
fileId,
|
|
29
|
+
headers,
|
|
33
30
|
},
|
|
34
|
-
|
|
35
|
-
);
|
|
31
|
+
meta,
|
|
32
|
+
});
|
|
36
33
|
|
|
37
34
|
if (!assetObject) throw new Error('Media not created');
|
|
38
35
|
return assetObject;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
-
import
|
|
2
|
+
import { sha256 } from '@unchainedshop/utils';
|
|
3
3
|
|
|
4
4
|
export default async (
|
|
5
5
|
unchainedAPI: UnchainedCore,
|
|
6
6
|
username: string,
|
|
7
7
|
plainSecret: string,
|
|
8
8
|
): Promise<void> => {
|
|
9
|
-
const secret =
|
|
9
|
+
const secret = await sha256(`${username}:${plainSecret}`);
|
|
10
10
|
|
|
11
11
|
await unchainedAPI.modules.users.updateUser(
|
|
12
12
|
{ username },
|
|
@@ -9,7 +9,7 @@ export const createMigrationRepository = (db: mongodb.Db): MigrationRepository =
|
|
|
9
9
|
migrations.set(migration.id, migration);
|
|
10
10
|
},
|
|
11
11
|
allMigrations: () => {
|
|
12
|
-
return [...migrations.values()].
|
|
12
|
+
return [...migrations.values()].toSorted((left, right) => {
|
|
13
13
|
return left.id - right.id;
|
|
14
14
|
});
|
|
15
15
|
},
|
|
@@ -17,7 +17,7 @@ export const runMigrations = async ({
|
|
|
17
17
|
const findCurrentId = async () => {
|
|
18
18
|
const last = await LastMigration.findOne({ category: 'unchained' }, { sort: { _id: -1 } });
|
|
19
19
|
const id = last ? last._id : 0;
|
|
20
|
-
logger.
|
|
20
|
+
logger.info(`Most recent migration id: ${id}`);
|
|
21
21
|
return id;
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -36,7 +36,7 @@ export const runMigrations = async ({
|
|
|
36
36
|
upsert: true,
|
|
37
37
|
},
|
|
38
38
|
);
|
|
39
|
-
logger.
|
|
39
|
+
logger.info(`Migrated '${action}' to ${id}`);
|
|
40
40
|
return id;
|
|
41
41
|
};
|
|
42
42
|
|
package/src/platform-index.ts
CHANGED
package/src/setup/setupCarts.ts
CHANGED
|
@@ -9,10 +9,14 @@ const { UNCHAINED_DISABLE_PROVIDER_INVALIDATION, UNCHAINED_ASSIGN_CART_FOR_USERS
|
|
|
9
9
|
|
|
10
10
|
export const setupCarts = async (unchainedAPI: UnchainedCore, options: SetupCartsOptions = {}) => {
|
|
11
11
|
if (options.invalidateProviders ?? !UNCHAINED_DISABLE_PROVIDER_INVALIDATION) {
|
|
12
|
-
await unchainedAPI.modules.orders.
|
|
13
|
-
unchainedAPI,
|
|
12
|
+
const orders = await unchainedAPI.modules.orders.findCartsToInvalidate(
|
|
14
13
|
options.providerInvalidationMaxAgeDays,
|
|
15
14
|
);
|
|
15
|
+
await Promise.allSettled(
|
|
16
|
+
orders.map(async (order) => {
|
|
17
|
+
await unchainedAPI.services.orders.updateCalculation(order._id);
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
if (options.assignCartForUsers ?? Boolean(UNCHAINED_ASSIGN_CART_FOR_USERS)) {
|
|
@@ -21,13 +25,10 @@ export const setupCarts = async (unchainedAPI: UnchainedCore, options: SetupCart
|
|
|
21
25
|
await Promise.all(
|
|
22
26
|
users.map((user) => {
|
|
23
27
|
const locale = unchainedAPI.modules.users.userLocale(user);
|
|
24
|
-
return unchainedAPI.services.orders.nextUserCart(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
unchainedAPI,
|
|
30
|
-
);
|
|
28
|
+
return unchainedAPI.services.orders.nextUserCart({
|
|
29
|
+
user,
|
|
30
|
+
countryCode: locale.region,
|
|
31
|
+
});
|
|
31
32
|
}),
|
|
32
33
|
);
|
|
33
34
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { MessagingDirector } from '@unchainedshop/core
|
|
2
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
1
|
+
import { MessagingDirector, UnchainedCore } from '@unchainedshop/core';
|
|
3
2
|
import { subscribe } from '@unchainedshop/events';
|
|
4
3
|
import { Order, OrderStatus } from '@unchainedshop/core-orders';
|
|
5
|
-
import { RawPayloadType } from '@unchainedshop/events
|
|
4
|
+
import { RawPayloadType } from '@unchainedshop/events';
|
|
6
5
|
import { resolveOrderRejectionTemplate } from '../templates/resolveOrderRejectionTemplate.js';
|
|
7
6
|
import { resolveAccountActionTemplate } from '../templates/resolveAccountActionTemplate.js';
|
|
8
7
|
import { resolveForwardDeliveryTemplate } from '../templates/resolveForwardDeliveryTemplate.js';
|
|
@@ -41,7 +40,7 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
|
|
|
41
40
|
type: 'MESSAGE',
|
|
42
41
|
retries: 0,
|
|
43
42
|
input: {
|
|
44
|
-
locale,
|
|
43
|
+
locale: locale.baseName,
|
|
45
44
|
template: MessageTypes.ORDER_CONFIRMATION,
|
|
46
45
|
orderId: order._id,
|
|
47
46
|
},
|
|
@@ -58,7 +57,7 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
|
|
|
58
57
|
type: 'MESSAGE',
|
|
59
58
|
retries: 0,
|
|
60
59
|
input: {
|
|
61
|
-
locale,
|
|
60
|
+
locale: locale.baseName,
|
|
62
61
|
template: MessageTypes.ORDER_CONFIRMATION,
|
|
63
62
|
orderId: order._id,
|
|
64
63
|
},
|
|
@@ -74,7 +73,7 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
|
|
|
74
73
|
type: 'MESSAGE',
|
|
75
74
|
retries: 0,
|
|
76
75
|
input: {
|
|
77
|
-
locale,
|
|
76
|
+
locale: locale.baseName,
|
|
78
77
|
template: MessageTypes.ORDER_REJECTION,
|
|
79
78
|
orderId: order._id,
|
|
80
79
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
+
import { FileDirector } from '@unchainedshop/file-upload';
|
|
3
|
+
|
|
4
|
+
export const setupUploadHandlers = ({ services, modules }: UnchainedCore) => {
|
|
5
|
+
FileDirector.registerFileUploadCallback('user-avatars', async (file) => {
|
|
6
|
+
return services.users.updateUserAvatarAfterUpload({ file });
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
FileDirector.registerFileUploadCallback('product-media', async (file) => {
|
|
10
|
+
await modules.products.media.create({
|
|
11
|
+
productId: file.meta?.productId as string,
|
|
12
|
+
mediaId: file._id,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
FileDirector.registerFileUploadCallback('assortment-media', async (file) => {
|
|
17
|
+
await modules.assortments.media.create({
|
|
18
|
+
assortmentId: file.meta.assortmentId as string,
|
|
19
|
+
mediaId: file._id,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EventListenerWorker,
|
|
3
|
-
FailedRescheduler,
|
|
4
|
-
IntervalWorker,
|
|
5
|
-
WorkerSchedule,
|
|
6
|
-
WorkData,
|
|
7
|
-
} from '@unchainedshop/core-worker';
|
|
8
1
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
9
|
-
|
|
2
|
+
import { EventListenerWorker } from '@unchainedshop/plugins/worker/EventListenerWorker.js';
|
|
3
|
+
import { IntervalWorker, IntervalWorkerParams } from '@unchainedshop/plugins/worker/IntervalWorker.js';
|
|
4
|
+
import { FailedRescheduler } from '@unchainedshop/plugins/worker/FailedRescheduler.js';
|
|
5
|
+
import { WorkData } from '@unchainedshop/core-worker';
|
|
10
6
|
export interface SetupWorkqueueOptions {
|
|
11
7
|
batchCount?: number;
|
|
12
8
|
disableWorker?: boolean;
|
|
13
|
-
schedule?:
|
|
9
|
+
schedule?: IntervalWorkerParams['schedule'];
|
|
14
10
|
workerId?: string;
|
|
15
11
|
retryInput?: (
|
|
16
12
|
workData: WorkData,
|
package/src/startPlatform.ts
CHANGED
|
@@ -4,10 +4,11 @@ import { initDb, mongodb } from '@unchainedshop/mongodb';
|
|
|
4
4
|
import { createLogger } from '@unchainedshop/logger';
|
|
5
5
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
6
6
|
import { getRegisteredEvents } from '@unchainedshop/events';
|
|
7
|
-
import { WorkerDirector } from '@unchainedshop/core
|
|
7
|
+
import { WorkerDirector } from '@unchainedshop/core';
|
|
8
8
|
import { BulkImportHandler, createBulkImporterFactory } from './bulk-importer/createBulkImporter.js';
|
|
9
9
|
import { runMigrations } from './migrations/runMigrations.js';
|
|
10
10
|
import { setupAccounts } from './setup/setupAccounts.js';
|
|
11
|
+
import { setupUploadHandlers } from './setup/setupUploadHandlers.js';
|
|
11
12
|
import { SetupCartsOptions, setupCarts } from './setup/setupCarts.js';
|
|
12
13
|
import { setupTemplates, MessageTypes } from './setup/setupTemplates.js';
|
|
13
14
|
import { SetupWorkqueueOptions, setupWorkqueue } from './setup/setupWorkqueue.js';
|
|
@@ -99,6 +100,9 @@ export const startPlatform = async ({
|
|
|
99
100
|
// Setup email templates
|
|
100
101
|
setupTemplates(unchainedAPI);
|
|
101
102
|
|
|
103
|
+
// Setup file upload handlers
|
|
104
|
+
setupUploadHandlers(unchainedAPI);
|
|
105
|
+
|
|
102
106
|
// Start the graphQL server
|
|
103
107
|
const graphqlHandler = await startAPIServer({
|
|
104
108
|
unchainedAPI,
|
|
@@ -117,7 +121,7 @@ export const startPlatform = async ({
|
|
|
117
121
|
|
|
118
122
|
// Setup filter cache
|
|
119
123
|
if (!workQueueOptions?.skipInvalidationOnStartup) {
|
|
120
|
-
setImmediate(() => unchainedAPI.
|
|
124
|
+
setImmediate(() => unchainedAPI.services.filters.invalidateFilterCache());
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
return { unchainedAPI, graphqlHandler, db };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { resolveOrderRejectionTemplate } from './resolveOrderRejectionTemplate.js';
|
|
2
|
+
export { resolveAccountActionTemplate } from './resolveAccountActionTemplate.js';
|
|
3
|
+
export { resolveForwardDeliveryTemplate } from './resolveForwardDeliveryTemplate.js';
|
|
4
|
+
export { resolveOrderConfirmationTemplate } from './resolveOrderConfirmationTemplate.js';
|
|
5
|
+
export { resolveQuotationStatusTemplate } from './resolveQuotationStatusTemplate.js';
|
|
6
|
+
export { resolveEnrollmentStatusTemplate } from './resolveEnrollmentStatusTemplate.js';
|
|
7
|
+
export { resolveErrorReportTemplate } from './resolveErrorReportTemplate.js';
|
|
8
|
+
|
|
9
|
+
export * as parser from './order-parser/index.js';
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
2
|
import { Order } from '@unchainedshop/core-orders';
|
|
3
|
-
import
|
|
3
|
+
import { ProductPricingSheet } from '@unchainedshop/core';
|
|
4
|
+
import { ch } from '@unchainedshop/utils';
|
|
4
5
|
|
|
5
6
|
type PriceFormatter = ({ amount, currency }: { amount: number; currency: string }) => string;
|
|
6
7
|
|
|
7
8
|
export const getOrderPositionsData = async (
|
|
8
9
|
order: Order,
|
|
9
|
-
params: { locale
|
|
10
|
+
params: { locale: string; useNetPrice?: boolean; format?: PriceFormatter },
|
|
10
11
|
context: UnchainedCore,
|
|
11
12
|
) => {
|
|
12
13
|
const { modules } = context;
|
|
13
|
-
const { useNetPrice, format =
|
|
14
|
+
const { useNetPrice, format = ch.priceToString } = params || {};
|
|
14
15
|
const orderPositions = await modules.orders.positions.findOrderPositions({
|
|
15
16
|
orderId: order._id,
|
|
16
17
|
});
|
|
@@ -19,18 +20,15 @@ export const getOrderPositionsData = async (
|
|
|
19
20
|
orderPositions.map(async (orderPosition) => {
|
|
20
21
|
const productTexts = await modules.products.texts.findLocalizedText({
|
|
21
22
|
productId: orderPosition.productId,
|
|
22
|
-
locale: params.locale
|
|
23
|
+
locale: params.locale,
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
const positionPricing = ProductPricingSheet({
|
|
27
|
+
calculation: orderPosition.calculation,
|
|
28
|
+
currency: order.currency,
|
|
29
|
+
quantity: orderPosition.quantity,
|
|
27
30
|
});
|
|
28
31
|
|
|
29
|
-
const positionPricing = modules.orders.positions.pricingSheet(
|
|
30
|
-
orderPosition,
|
|
31
|
-
order.currency,
|
|
32
|
-
context,
|
|
33
|
-
);
|
|
34
32
|
const total = positionPricing.total({ useNetPrice });
|
|
35
33
|
const unitPrice = positionPricing.unitPrice({ useNetPrice });
|
|
36
34
|
|
|
@@ -38,7 +36,6 @@ export const getOrderPositionsData = async (
|
|
|
38
36
|
return {
|
|
39
37
|
productId: orderPosition.productId,
|
|
40
38
|
configuration: orderPosition.configuration,
|
|
41
|
-
originalProductTexts,
|
|
42
39
|
productTexts,
|
|
43
40
|
quantity,
|
|
44
41
|
rawPrices: {
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
1
|
import { Order } from '@unchainedshop/core-orders';
|
|
3
|
-
import { OrderPricingRowCategory } from '@unchainedshop/core
|
|
4
|
-
import
|
|
5
|
-
import { formatAddress } from './formatAddress.js';
|
|
2
|
+
import { UnchainedCore, OrderPricingSheet, OrderPricingRowCategory } from '@unchainedshop/core';
|
|
3
|
+
import { ch } from '@unchainedshop/utils';
|
|
6
4
|
|
|
7
5
|
type PriceFormatter = ({ amount, currency }: { amount: number; currency: string }) => string;
|
|
8
6
|
|
|
9
7
|
export const getOrderSummaryData = async (
|
|
10
8
|
order: Order,
|
|
11
|
-
params: { locale?:
|
|
9
|
+
params: { locale?: string; useNetPrice?: boolean; format?: PriceFormatter },
|
|
12
10
|
context: UnchainedCore,
|
|
13
11
|
) => {
|
|
14
12
|
const { modules } = context;
|
|
15
|
-
const { useNetPrice, format =
|
|
13
|
+
const { useNetPrice, format = ch.priceToString } = params || {};
|
|
16
14
|
const orderDelivery = await modules.orders.deliveries.findDelivery({
|
|
17
15
|
orderDeliveryId: order.deliveryId,
|
|
18
16
|
});
|
|
@@ -26,9 +24,14 @@ export const getOrderSummaryData = async (
|
|
|
26
24
|
deliveryProviderId: orderDelivery.deliveryProviderId,
|
|
27
25
|
});
|
|
28
26
|
|
|
29
|
-
const deliveryAddress =
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const deliveryAddress = ch.addressToString(
|
|
28
|
+
orderDelivery?.context?.deliveryAddress || order.billingAddress,
|
|
29
|
+
);
|
|
30
|
+
const billingAddress = ch.addressToString(order.billingAddress);
|
|
31
|
+
const orderPricing = OrderPricingSheet({
|
|
32
|
+
calculation: order.calculation,
|
|
33
|
+
currency: order.currency,
|
|
34
|
+
});
|
|
32
35
|
|
|
33
36
|
const paymentTotal = orderPricing.total({
|
|
34
37
|
category: OrderPricingRowCategory.Payment,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { getOrderPositionsData } from './getOrderPositionsData.js';
|
|
2
2
|
import { getOrderSummaryData } from './getOrderSummaryData.js';
|
|
3
|
+
import { Order } from '@unchainedshop/core-orders';
|
|
4
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
5
|
+
|
|
6
|
+
import mustache from 'mustache';
|
|
3
7
|
|
|
4
8
|
const textTemplate = `Order number: {{orderNumber}}
|
|
5
9
|
Ordered: {{orderDate}}
|
|
@@ -31,14 +35,21 @@ Total: {{summary.prices.gross}}
|
|
|
31
35
|
{{/summary.rawPrices.taxes.amount}}
|
|
32
36
|
`;
|
|
33
37
|
|
|
34
|
-
export const transformOrderToText = async (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
export const transformOrderToText = async (
|
|
39
|
+
{ order, locale }: { order: Order; locale: string },
|
|
40
|
+
context: UnchainedCore,
|
|
41
|
+
) => {
|
|
42
|
+
return mustache.render(
|
|
43
|
+
textTemplate,
|
|
44
|
+
{
|
|
45
|
+
orderDate: new Date(order.ordered).toLocaleString(),
|
|
46
|
+
orderNumber: order.orderNumber,
|
|
47
|
+
summary: await getOrderSummaryData(order, { locale }, context),
|
|
48
|
+
positions: await getOrderPositionsData(order, { locale }, context),
|
|
49
|
+
},
|
|
50
|
+
undefined,
|
|
51
|
+
{ escape: (t) => t },
|
|
52
|
+
);
|
|
44
53
|
};
|
|
54
|
+
|
|
55
|
+
export { getOrderPositionsData, getOrderSummaryData };
|