@unchainedshop/platform 4.0.0-rc.2 → 4.0.0-rc.21
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 +5 -3
- package/lib/bulk-importer/createBulkImporter.d.ts.map +1 -1
- package/lib/bulk-importer/createBulkImporter.js.map +1 -1
- package/lib/context/withAccessToken.d.ts +4 -0
- package/lib/context/withAccessToken.d.ts.map +1 -0
- package/lib/context/withAccessToken.js +42 -0
- package/lib/context/withAccessToken.js.map +1 -0
- package/lib/migrations/createMigrationRunner.d.ts +1 -1
- package/lib/migrations/migrationRepository.d.ts.map +1 -1
- package/lib/migrations/migrationRepository.js +3 -0
- package/lib/migrations/migrationRepository.js.map +1 -1
- package/lib/migrations/runMigrations.d.ts.map +1 -1
- package/lib/migrations/runMigrations.js.map +1 -1
- package/lib/platform-index.d.ts +1 -1
- package/lib/platform-index.d.ts.map +1 -1
- package/lib/platform-index.js +1 -1
- package/lib/platform-index.js.map +1 -1
- package/lib/setup/setupAccounts.d.ts.map +1 -1
- package/lib/setup/setupAccounts.js +3 -8
- package/lib/setup/setupAccounts.js.map +1 -1
- package/lib/setup/setupTemplates.d.ts.map +1 -1
- package/lib/setup/setupTemplates.js +9 -24
- package/lib/setup/setupTemplates.js.map +1 -1
- package/lib/setup/setupUploadHandlers.js +1 -1
- package/lib/setup/setupUploadHandlers.js.map +1 -1
- package/lib/setup/setupWorkqueue.d.ts +3 -2
- package/lib/setup/setupWorkqueue.d.ts.map +1 -1
- package/lib/setup/setupWorkqueue.js +12 -3
- package/lib/setup/setupWorkqueue.js.map +1 -1
- package/lib/startPlatform.d.ts +2 -6
- package/lib/startPlatform.d.ts.map +1 -1
- package/lib/startPlatform.js +12 -18
- package/lib/startPlatform.js.map +1 -1
- package/lib/templates/order-parser/formatAddress.d.ts +3 -0
- package/lib/templates/order-parser/formatAddress.d.ts.map +1 -0
- package/lib/templates/order-parser/formatAddress.js +14 -0
- package/lib/templates/order-parser/formatAddress.js.map +1 -0
- package/lib/templates/order-parser/formatPrice.d.ts +6 -0
- package/lib/templates/order-parser/formatPrice.d.ts.map +1 -0
- package/lib/templates/order-parser/formatPrice.js +6 -0
- package/lib/templates/order-parser/formatPrice.js.map +1 -0
- package/lib/templates/order-parser/getOrderPositionsData.d.ts +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 +14 -8
- package/lib/templates/order-parser/getOrderSummaryData.js.map +1 -1
- package/lib/templates/order-parser/index.d.ts.map +1 -1
- package/lib/templates/order-parser/index.js +50 -36
- package/lib/templates/order-parser/index.js.map +1 -1
- package/lib/templates/resolveAccountActionTemplate.d.ts.map +1 -1
- package/lib/templates/resolveAccountActionTemplate.js +13 -13
- package/lib/templates/resolveAccountActionTemplate.js.map +1 -1
- package/lib/templates/resolveEnrollmentStatusTemplate.d.ts.map +1 -1
- package/lib/templates/resolveEnrollmentStatusTemplate.js +10 -16
- package/lib/templates/resolveEnrollmentStatusTemplate.js.map +1 -1
- package/lib/templates/resolveErrorReportTemplate.d.ts.map +1 -1
- package/lib/templates/resolveErrorReportTemplate.js +6 -11
- package/lib/templates/resolveErrorReportTemplate.js.map +1 -1
- package/lib/templates/resolveForwardDeliveryTemplate.d.ts.map +1 -1
- package/lib/templates/resolveForwardDeliveryTemplate.js +8 -13
- package/lib/templates/resolveForwardDeliveryTemplate.js.map +1 -1
- package/lib/templates/resolveOrderConfirmationTemplate.d.ts.map +1 -1
- package/lib/templates/resolveOrderConfirmationTemplate.js +8 -13
- package/lib/templates/resolveOrderConfirmationTemplate.js.map +1 -1
- package/lib/templates/resolveOrderRejectionTemplate.d.ts.map +1 -1
- package/lib/templates/resolveOrderRejectionTemplate.js +11 -16
- package/lib/templates/resolveOrderRejectionTemplate.js.map +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.d.ts.map +1 -1
- package/lib/templates/resolveQuotationStatusTemplate.js +11 -17
- package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -1
- package/package.json +14 -15
- package/src/migrations/migrationRepository.ts +5 -0
- package/src/migrations/runMigrations.ts +6 -1
- package/src/platform-index.ts +1 -1
- package/src/setup/setupAccounts.ts +3 -8
- package/src/setup/setupTemplates.ts +9 -24
- package/src/setup/setupUploadHandlers.ts +1 -1
- package/src/setup/setupWorkqueue.ts +13 -4
- package/src/startPlatform.ts +15 -23
- package/src/templates/order-parser/getOrderSummaryData.ts +18 -8
- package/src/templates/order-parser/index.ts +53 -43
- package/src/templates/resolveAccountActionTemplate.ts +25 -21
- package/src/templates/resolveEnrollmentStatusTemplate.ts +12 -26
- package/src/templates/resolveErrorReportTemplate.ts +7 -17
- package/src/templates/resolveForwardDeliveryTemplate.ts +9 -19
- package/src/templates/resolveOrderConfirmationTemplate.ts +9 -19
- package/src/templates/resolveOrderRejectionTemplate.ts +13 -23
- package/src/templates/resolveQuotationStatusTemplate.ts +11 -26
- package/src/bulk-importer/createBulkImporter.ts +0 -134
- package/src/bulk-importer/handlers/assortment/create.ts +0 -86
- package/src/bulk-importer/handlers/assortment/index.ts +0 -3
- package/src/bulk-importer/handlers/assortment/remove.ts +0 -15
- package/src/bulk-importer/handlers/assortment/update.ts +0 -88
- package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +0 -49
- package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +0 -42
- package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +0 -50
- package/src/bulk-importer/handlers/assortment/upsertMedia.ts +0 -54
- package/src/bulk-importer/handlers/filter/create.ts +0 -76
- package/src/bulk-importer/handlers/filter/index.ts +0 -3
- package/src/bulk-importer/handlers/filter/remove.ts +0 -16
- package/src/bulk-importer/handlers/filter/update.ts +0 -67
- package/src/bulk-importer/handlers/product/create.ts +0 -69
- package/src/bulk-importer/handlers/product/index.ts +0 -3
- package/src/bulk-importer/handlers/product/remove.ts +0 -16
- package/src/bulk-importer/handlers/product/transformSpecificationToProductStructure.ts +0 -22
- package/src/bulk-importer/handlers/product/update.ts +0 -65
- package/src/bulk-importer/handlers/product/upsertMedia.ts +0 -60
- package/src/bulk-importer/handlers/product/upsertVariations.ts +0 -68
- package/src/bulk-importer/handlers/utils/convertTagsToLowerCase.ts +0 -4
- package/src/bulk-importer/upsertAsset.ts +0 -41
|
@@ -3,14 +3,9 @@ import { subscribe } from '@unchainedshop/events';
|
|
|
3
3
|
|
|
4
4
|
export const setupAccounts = (unchainedAPI: UnchainedCore) => {
|
|
5
5
|
subscribe('USER_ACCOUNT_ACTION', async ({ payload }: { payload: any }) => {
|
|
6
|
-
await unchainedAPI.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
input: {
|
|
10
|
-
template: 'ACCOUNT_ACTION',
|
|
11
|
-
recipientEmail: payload.address,
|
|
12
|
-
...payload,
|
|
13
|
-
},
|
|
6
|
+
await unchainedAPI.services.worker.addMessage('ACCOUNT_ACTION', {
|
|
7
|
+
recipientEmail: payload.address,
|
|
8
|
+
...payload,
|
|
14
9
|
});
|
|
15
10
|
});
|
|
16
11
|
};
|
|
@@ -36,14 +36,9 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
|
|
|
36
36
|
|
|
37
37
|
if (order.status === OrderStatus.PENDING) {
|
|
38
38
|
// We only send the "confirmation" when pending, else we let the other events handle it
|
|
39
|
-
await unchainedAPI.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
input: {
|
|
43
|
-
locale: locale.baseName,
|
|
44
|
-
template: MessageTypes.ORDER_CONFIRMATION,
|
|
45
|
-
orderId: order._id,
|
|
46
|
-
},
|
|
39
|
+
await unchainedAPI.services.worker.addMessage(MessageTypes.ORDER_CONFIRMATION, {
|
|
40
|
+
locale: locale.baseName,
|
|
41
|
+
orderId: order._id,
|
|
47
42
|
});
|
|
48
43
|
}
|
|
49
44
|
});
|
|
@@ -53,14 +48,9 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
|
|
|
53
48
|
const user = await unchainedAPI.modules.users.findUserById(order.userId);
|
|
54
49
|
const locale = unchainedAPI.modules.users.userLocale(user);
|
|
55
50
|
|
|
56
|
-
await unchainedAPI.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
input: {
|
|
60
|
-
locale: locale.baseName,
|
|
61
|
-
template: MessageTypes.ORDER_CONFIRMATION,
|
|
62
|
-
orderId: order._id,
|
|
63
|
-
},
|
|
51
|
+
await unchainedAPI.services.worker.addMessage(MessageTypes.ORDER_CONFIRMATION, {
|
|
52
|
+
locale: locale.baseName,
|
|
53
|
+
orderId: order._id,
|
|
64
54
|
});
|
|
65
55
|
});
|
|
66
56
|
|
|
@@ -69,14 +59,9 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
|
|
|
69
59
|
const user = await unchainedAPI.modules.users.findUserById(order.userId);
|
|
70
60
|
const locale = unchainedAPI.modules.users.userLocale(user);
|
|
71
61
|
|
|
72
|
-
await unchainedAPI.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
input: {
|
|
76
|
-
locale: locale.baseName,
|
|
77
|
-
template: MessageTypes.ORDER_REJECTION,
|
|
78
|
-
orderId: order._id,
|
|
79
|
-
},
|
|
62
|
+
await unchainedAPI.services.worker.addMessage(MessageTypes.ORDER_REJECTION, {
|
|
63
|
+
locale: locale.baseName,
|
|
64
|
+
orderId: order._id,
|
|
80
65
|
});
|
|
81
66
|
});
|
|
82
67
|
};
|
|
@@ -15,7 +15,7 @@ export const setupUploadHandlers = ({ services, modules }: UnchainedCore) => {
|
|
|
15
15
|
|
|
16
16
|
FileDirector.registerFileUploadCallback('assortment-media', async (file) => {
|
|
17
17
|
await modules.assortments.media.create({
|
|
18
|
-
assortmentId: file.meta
|
|
18
|
+
assortmentId: file.meta?.assortmentId as string,
|
|
19
19
|
mediaId: file._id,
|
|
20
20
|
});
|
|
21
21
|
});
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '@unchainedshop/core';
|
|
11
11
|
import { runMigrations } from '../migrations/runMigrations.js';
|
|
12
12
|
import { MigrationRepository } from '@unchainedshop/mongodb';
|
|
13
|
+
import { setImmediate } from 'node:timers/promises';
|
|
13
14
|
|
|
14
15
|
export type WorkQueueQueueManager = IWorker<any> | IScheduler<any>;
|
|
15
16
|
export interface SetupWorkqueueOptions extends IntervalWorkerParams, FailedReschedulerParams {
|
|
@@ -35,14 +36,14 @@ export const defaultQueueManagers: WorkQueueQueueManager[] = [
|
|
|
35
36
|
|
|
36
37
|
export const queueWorkers: any[] = [];
|
|
37
38
|
|
|
38
|
-
export
|
|
39
|
+
export async function setupWorkqueue({
|
|
39
40
|
unchainedAPI,
|
|
40
41
|
migrationRepository,
|
|
41
42
|
...workQueueOptions
|
|
42
43
|
}: {
|
|
43
44
|
unchainedAPI: UnchainedCore;
|
|
44
45
|
migrationRepository: MigrationRepository<UnchainedCore>;
|
|
45
|
-
} & SetupWorkqueueOptions)
|
|
46
|
+
} & SetupWorkqueueOptions) {
|
|
46
47
|
if (workQueueOptions.disableWorker || UNCHAINED_DISABLE_WORKER) return;
|
|
47
48
|
|
|
48
49
|
// Run migrations
|
|
@@ -74,6 +75,7 @@ export const setupWorkqueue = async ({
|
|
|
74
75
|
await Promise.all(
|
|
75
76
|
users.map((user) => {
|
|
76
77
|
const locale = unchainedAPI.modules.users.userLocale(user);
|
|
78
|
+
if (!locale.region) return null;
|
|
77
79
|
return unchainedAPI.services.orders.nextUserCart({
|
|
78
80
|
user,
|
|
79
81
|
countryCode: locale.region,
|
|
@@ -84,6 +86,13 @@ export const setupWorkqueue = async ({
|
|
|
84
86
|
|
|
85
87
|
// Setup filter cache
|
|
86
88
|
if (!workQueueOptions?.skipInvalidationOnStartup) {
|
|
87
|
-
setImmediate(() => unchainedAPI.services.filters.invalidateFilterCache());
|
|
89
|
+
await setImmediate(async () => unchainedAPI.services.filters.invalidateFilterCache());
|
|
88
90
|
}
|
|
89
|
-
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function stopWorkqueue() {
|
|
94
|
+
queueWorkers.forEach((worker) => {
|
|
95
|
+
worker?.stop();
|
|
96
|
+
});
|
|
97
|
+
queueWorkers.length = 0;
|
|
98
|
+
}
|
package/src/startPlatform.ts
CHANGED
|
@@ -3,22 +3,19 @@ import { initCore, UnchainedCoreOptions } from '@unchainedshop/core';
|
|
|
3
3
|
import { initDb, mongodb, stopDb } from '@unchainedshop/mongodb';
|
|
4
4
|
import { defaultLogger } from '@unchainedshop/logger';
|
|
5
5
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
6
|
-
import { BulkImportHandler, createBulkImporterFactory } from './bulk-importer/createBulkImporter.js';
|
|
7
6
|
import { setupAccounts } from './setup/setupAccounts.js';
|
|
8
7
|
import { setupUploadHandlers } from './setup/setupUploadHandlers.js';
|
|
9
8
|
import { setupTemplates, MessageTypes } from './setup/setupTemplates.js';
|
|
10
|
-
import { SetupWorkqueueOptions, setupWorkqueue } from './setup/setupWorkqueue.js';
|
|
9
|
+
import { SetupWorkqueueOptions, stopWorkqueue, setupWorkqueue } from './setup/setupWorkqueue.js';
|
|
11
10
|
import { createMigrationRepository } from './migrations/migrationRepository.js';
|
|
12
11
|
import { IRoleOptionConfig } from '@unchainedshop/roles';
|
|
12
|
+
|
|
13
13
|
export { MessageTypes };
|
|
14
14
|
|
|
15
15
|
export type PlatformOptions = {
|
|
16
|
-
bulkImporter?: {
|
|
17
|
-
handlers?: Record<string, BulkImportHandler>;
|
|
18
|
-
};
|
|
19
16
|
rolesOptions?: IRoleOptionConfig;
|
|
20
17
|
workQueueOptions?: SetupWorkqueueOptions;
|
|
21
|
-
} & Omit<UnchainedCoreOptions, '
|
|
18
|
+
} & Omit<UnchainedCoreOptions, 'migrationRepository' | 'db'> &
|
|
22
19
|
Omit<UnchainedServerOptions, 'roles' | 'unchainedAPI'>;
|
|
23
20
|
|
|
24
21
|
const REQUIRED_ENV_VARIABLES = [
|
|
@@ -50,8 +47,8 @@ export const startPlatform = async ({
|
|
|
50
47
|
modules,
|
|
51
48
|
services,
|
|
52
49
|
options,
|
|
53
|
-
rolesOptions
|
|
54
|
-
bulkImporter
|
|
50
|
+
rolesOptions,
|
|
51
|
+
bulkImporter,
|
|
55
52
|
workQueueOptions,
|
|
56
53
|
...arbitraryAPIServerConfiguration
|
|
57
54
|
}: PlatformOptions): Promise<{
|
|
@@ -62,14 +59,13 @@ export const startPlatform = async ({
|
|
|
62
59
|
exitOnMissingEnvironmentVariables();
|
|
63
60
|
existOnInvalidEnvironmentVariables();
|
|
64
61
|
|
|
65
|
-
const configuredRoles = roles.configureRoles(rolesOptions);
|
|
62
|
+
const configuredRoles = roles.configureRoles(rolesOptions || {});
|
|
66
63
|
|
|
67
64
|
// Configure database
|
|
68
65
|
const db = await initDb();
|
|
69
66
|
|
|
70
67
|
// Prepare Migrations
|
|
71
68
|
const migrationRepository = createMigrationRepository(db);
|
|
72
|
-
const bulkImporter = createBulkImporterFactory(db, bulkImporterOptions);
|
|
73
69
|
|
|
74
70
|
// Initialise core api using the database
|
|
75
71
|
const unchainedAPI = await initCore({
|
|
@@ -109,23 +105,19 @@ export const startPlatform = async ({
|
|
|
109
105
|
});
|
|
110
106
|
defaultLogger.info(`Unchained Engine running`, { version: packageJson.version });
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
defaultLogger.
|
|
108
|
+
const cleanup = (signal) => async () => {
|
|
109
|
+
defaultLogger.debug('Stopping Workqueue', { signal });
|
|
110
|
+
stopWorkqueue();
|
|
111
|
+
defaultLogger.debug('Stopping GraphQL server', { signal });
|
|
114
112
|
await graphqlHandler.dispose();
|
|
115
|
-
defaultLogger.
|
|
113
|
+
defaultLogger.debug('Stopping DB Connection', { signal });
|
|
116
114
|
await stopDb();
|
|
117
|
-
defaultLogger.
|
|
115
|
+
defaultLogger.debug(`Unchained Engine exiting`, { signal, version: packageJson.version });
|
|
118
116
|
process.exit(0);
|
|
119
|
-
}
|
|
117
|
+
};
|
|
120
118
|
|
|
121
|
-
process.on('
|
|
122
|
-
|
|
123
|
-
await graphqlHandler.dispose();
|
|
124
|
-
defaultLogger.info('Stopping DB Connection (SIGINT)');
|
|
125
|
-
await stopDb();
|
|
126
|
-
defaultLogger.info(`Unchained Engine stopped`, { version: packageJson.version });
|
|
127
|
-
process.exit(0);
|
|
128
|
-
});
|
|
119
|
+
process.on('SIGTERM', cleanup('SIGTERM'));
|
|
120
|
+
process.on('SIGINT', cleanup('SIGINT'));
|
|
129
121
|
|
|
130
122
|
return { unchainedAPI, graphqlHandler, db };
|
|
131
123
|
};
|
|
@@ -11,12 +11,22 @@ export const getOrderSummaryData = async (
|
|
|
11
11
|
) => {
|
|
12
12
|
const { modules } = context;
|
|
13
13
|
const { useNetPrice, format = ch.priceToString } = params || {};
|
|
14
|
-
const orderDelivery =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const orderDelivery =
|
|
15
|
+
order.deliveryId &&
|
|
16
|
+
(await modules.orders.deliveries.findDelivery({
|
|
17
|
+
orderDeliveryId: order.deliveryId,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
if (!orderDelivery) throw new Error('Order delivery not found');
|
|
21
|
+
|
|
22
|
+
const orderPayment =
|
|
23
|
+
order.paymentId &&
|
|
24
|
+
(await modules.orders.payments.findOrderPayment({
|
|
25
|
+
orderPaymentId: order.paymentId,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
if (!orderPayment) throw new Error('Order payment not found');
|
|
29
|
+
|
|
20
30
|
const paymentProvider = await modules.payment.paymentProviders.findProvider({
|
|
21
31
|
paymentProviderId: orderPayment.paymentProviderId,
|
|
22
32
|
});
|
|
@@ -55,8 +65,8 @@ export const getOrderSummaryData = async (
|
|
|
55
65
|
|
|
56
66
|
const total = orderPricing.total({ useNetPrice });
|
|
57
67
|
|
|
58
|
-
const payment = paymentProvider
|
|
59
|
-
const delivery = deliveryProvider
|
|
68
|
+
const payment = paymentProvider?.adapterKey;
|
|
69
|
+
const delivery = deliveryProvider?.adapterKey;
|
|
60
70
|
|
|
61
71
|
return {
|
|
62
72
|
rawPrices: {
|
|
@@ -3,53 +3,63 @@ import { getOrderSummaryData } from './getOrderSummaryData.js';
|
|
|
3
3
|
import { Order } from '@unchainedshop/core-orders';
|
|
4
4
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
5
5
|
|
|
6
|
-
import mustache from 'mustache';
|
|
7
|
-
|
|
8
|
-
const textTemplate = `Order number: {{orderNumber}}
|
|
9
|
-
Ordered: {{orderDate}}
|
|
10
|
-
Payment method: {{summary.payment}}
|
|
11
|
-
Delivery method: {{summary.delivery}}
|
|
12
|
-
|
|
13
|
-
Delivery address:
|
|
14
|
-
{{summary.deliveryAddress}}
|
|
15
|
-
|
|
16
|
-
Billing address:
|
|
17
|
-
{{summary.billingAddress}}
|
|
18
|
-
|
|
19
|
-
Order Details:
|
|
20
|
-
|
|
21
|
-
Items:
|
|
22
|
-
{{#positions}}
|
|
23
|
-
* {{quantity}} {{productTexts.title}}: {{total}}
|
|
24
|
-
{{/positions}}
|
|
25
|
-
|
|
26
|
-
{{#summary.rawPrices.delivery.amount}}
|
|
27
|
-
Delivery Fees: {{summary.prices.delivery}}
|
|
28
|
-
{{/summary.rawPrices.delivery.amount}}
|
|
29
|
-
{{#summary.rawPrices.payment.amount}}
|
|
30
|
-
Payment Fees: {{summary.prices.payment}}
|
|
31
|
-
{{/summary.rawPrices.payment.amount}}
|
|
32
|
-
Total: {{summary.prices.gross}}
|
|
33
|
-
{{#summary.rawPrices.taxes.amount}}
|
|
34
|
-
(VAT included: {{summary.prices.taxes}})
|
|
35
|
-
{{/summary.rawPrices.taxes.amount}}
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
6
|
export const transformOrderToText = async (
|
|
39
7
|
{ order, locale }: { order: Order; locale: Intl.Locale },
|
|
40
8
|
context: UnchainedCore,
|
|
41
9
|
) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
10
|
+
const orderDate = new Date(order.ordered!).toLocaleString();
|
|
11
|
+
const orderNumber = order.orderNumber;
|
|
12
|
+
const summary = await getOrderSummaryData(order, { locale }, context);
|
|
13
|
+
const positions = await getOrderPositionsData(order, { locale }, context);
|
|
14
|
+
|
|
15
|
+
const positionsText = positions
|
|
16
|
+
.map((pos) => ` ${pos.quantity}x ${pos.productTexts.title} ${pos.total}`)
|
|
17
|
+
.join('\n');
|
|
18
|
+
|
|
19
|
+
const subtotalText = summary.rawPrices.items.amount ? ` Subtotal ${summary.prices.items}\n` : '';
|
|
20
|
+
const deliveryFeesText = summary.rawPrices.delivery.amount
|
|
21
|
+
? ` Delivery ${summary.prices.delivery}\n`
|
|
22
|
+
: '';
|
|
23
|
+
const paymentFeesText = summary.rawPrices.payment.amount
|
|
24
|
+
? ` Payment ${summary.prices.payment}\n`
|
|
25
|
+
: '';
|
|
26
|
+
const totalLine = ` ${'─'.repeat(50)}\n Order Total ${summary.prices.gross}`;
|
|
27
|
+
const taxesText = summary.rawPrices.taxes.amount ? `\n (incl. VAT ${summary.prices.taxes})` : '';
|
|
28
|
+
|
|
29
|
+
return `═════════════════════════════════════════════════════
|
|
30
|
+
ORDER CONFIRMATION
|
|
31
|
+
═════════════════════════════════════════════════════
|
|
32
|
+
|
|
33
|
+
Order Number: ${orderNumber}
|
|
34
|
+
Order Date: ${orderDate}
|
|
35
|
+
|
|
36
|
+
─────────────────────────────────────────────────────
|
|
37
|
+
DELIVERY INFORMATION
|
|
38
|
+
─────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
Delivery Method: ${summary.delivery}
|
|
41
|
+
|
|
42
|
+
Delivery Address:
|
|
43
|
+
${summary.deliveryAddress}
|
|
44
|
+
|
|
45
|
+
─────────────────────────────────────────────────────
|
|
46
|
+
PAYMENT INFORMATION
|
|
47
|
+
─────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
Payment Method: ${summary.payment}
|
|
50
|
+
|
|
51
|
+
Billing Address:
|
|
52
|
+
${summary.billingAddress}
|
|
53
|
+
|
|
54
|
+
─────────────────────────────────────────────────────
|
|
55
|
+
ORDER DETAILS
|
|
56
|
+
─────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
${positionsText}
|
|
59
|
+
|
|
60
|
+
${subtotalText}${deliveryFeesText}${paymentFeesText}${totalLine}${taxesText}
|
|
61
|
+
═════════════════════════════════════════════════════
|
|
62
|
+
`;
|
|
53
63
|
};
|
|
54
64
|
|
|
55
65
|
export { getOrderPositionsData, getOrderSummaryData };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TemplateResolver } from '@unchainedshop/core';
|
|
2
|
-
import mustache from 'mustache';
|
|
3
2
|
|
|
4
3
|
const { EMAIL_FROM, EMAIL_WEBSITE_URL, EMAIL_WEBSITE_NAME } = process.env;
|
|
5
4
|
|
|
@@ -16,15 +15,26 @@ const passwordChangedEmailEnglishConfig = {
|
|
|
16
15
|
subject: `${EMAIL_WEBSITE_NAME}: Your password has been changed`,
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
const buildTextTemplate = ({
|
|
19
|
+
message,
|
|
20
|
+
buttonText,
|
|
21
|
+
url,
|
|
22
|
+
}: {
|
|
23
|
+
message: string;
|
|
24
|
+
buttonText: string;
|
|
25
|
+
url: string | null;
|
|
26
|
+
}) => {
|
|
27
|
+
const urlSection = url
|
|
28
|
+
? `
|
|
29
|
+
|
|
30
|
+
-----------------
|
|
31
|
+
${buttonText}: ${url}
|
|
32
|
+
-----------------
|
|
33
|
+
`
|
|
34
|
+
: '';
|
|
35
|
+
|
|
36
|
+
return ` ${message}${urlSection}`;
|
|
37
|
+
};
|
|
28
38
|
|
|
29
39
|
const emailConfig = {
|
|
30
40
|
'enroll-account': {
|
|
@@ -97,17 +107,11 @@ export const resolveAccountActionTemplate: TemplateResolver = async (
|
|
|
97
107
|
const { url } = emailConfig[action];
|
|
98
108
|
const { subject, message, buttonText } = emailConfig[action][locale.language];
|
|
99
109
|
|
|
100
|
-
const text =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
subject,
|
|
106
|
-
url: url(token),
|
|
107
|
-
},
|
|
108
|
-
undefined,
|
|
109
|
-
{ escape: (t) => t },
|
|
110
|
-
);
|
|
110
|
+
const text = buildTextTemplate({
|
|
111
|
+
buttonText,
|
|
112
|
+
message,
|
|
113
|
+
url: url(token),
|
|
114
|
+
});
|
|
111
115
|
|
|
112
116
|
return [
|
|
113
117
|
{
|
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
import { TemplateResolver } from '@unchainedshop/core';
|
|
2
|
-
import mustache from 'mustache';
|
|
3
|
-
const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
{{subject}}\n
|
|
7
|
-
\n
|
|
8
|
-
Status: {{enrollment.status}}
|
|
9
|
-
\n
|
|
10
|
-
-----------------\n
|
|
11
|
-
Show: {{url}}\n
|
|
12
|
-
-----------------\n
|
|
13
|
-
`;
|
|
3
|
+
const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
|
|
14
4
|
|
|
15
|
-
export const resolveEnrollmentStatusTemplate: TemplateResolver = async (
|
|
16
|
-
{ enrollmentId, locale },
|
|
17
|
-
context,
|
|
18
|
-
) => {
|
|
5
|
+
export const resolveEnrollmentStatusTemplate: TemplateResolver = async ({ enrollmentId }, context) => {
|
|
19
6
|
const { modules } = context;
|
|
20
7
|
const enrollment = await modules.enrollments.findEnrollment({ enrollmentId });
|
|
21
8
|
const user = await modules.users.findUserById(enrollment.userId);
|
|
22
9
|
|
|
23
10
|
const subject = `${EMAIL_WEBSITE_NAME}: Updated Enrollment / ${enrollment.enrollmentNumber}`;
|
|
11
|
+
const url = `${EMAIL_WEBSITE_URL}/enrollment?_id=${enrollment._id}`;
|
|
24
12
|
|
|
25
|
-
const text =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{ escape: (t) => t },
|
|
35
|
-
);
|
|
13
|
+
const text = `
|
|
14
|
+
${subject}\n
|
|
15
|
+
\n
|
|
16
|
+
Status: ${enrollment.status}
|
|
17
|
+
\n
|
|
18
|
+
-----------------\n
|
|
19
|
+
Show: ${url}\n
|
|
20
|
+
-----------------\n
|
|
21
|
+
`;
|
|
36
22
|
|
|
37
23
|
return [
|
|
38
24
|
{
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TemplateResolver } from '@unchainedshop/core';
|
|
2
2
|
import { stringify } from 'safe-stable-stringify';
|
|
3
|
-
import mustache from 'mustache';
|
|
4
3
|
|
|
5
4
|
const {
|
|
6
5
|
EMAIL_FROM = 'noreply@unchained.local',
|
|
@@ -18,27 +17,18 @@ const formatWorkItems = (workItems) => {
|
|
|
18
17
|
.join('\n');
|
|
19
18
|
};
|
|
20
19
|
|
|
21
|
-
const
|
|
20
|
+
const resolveErrorReportTemplate: TemplateResolver = async ({ workItems }) => {
|
|
21
|
+
const content = formatWorkItems(workItems);
|
|
22
|
+
|
|
23
|
+
const text = `
|
|
22
24
|
-------------------------
|
|
23
|
-
Unchained Endpoint: {
|
|
24
|
-
Shop Name: {
|
|
25
|
+
Unchained Endpoint: ${ROOT_URL}
|
|
26
|
+
Shop Name: ${EMAIL_WEBSITE_NAME}
|
|
25
27
|
-------------------------
|
|
26
28
|
|
|
27
|
-
{
|
|
29
|
+
${content}
|
|
28
30
|
`;
|
|
29
31
|
|
|
30
|
-
const resolveErrorReportTemplate: TemplateResolver = async ({ workItems }) => {
|
|
31
|
-
const text = mustache.render(
|
|
32
|
-
textTemplate,
|
|
33
|
-
{
|
|
34
|
-
endpoint: ROOT_URL,
|
|
35
|
-
content: formatWorkItems(workItems),
|
|
36
|
-
name: EMAIL_WEBSITE_NAME,
|
|
37
|
-
},
|
|
38
|
-
undefined,
|
|
39
|
-
{ escape: (t) => t },
|
|
40
|
-
);
|
|
41
|
-
|
|
42
32
|
return [
|
|
43
33
|
{
|
|
44
34
|
type: 'EMAIL',
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import { TemplateResolver } from '@unchainedshop/core';
|
|
2
2
|
import { systemLocale } from '@unchainedshop/utils';
|
|
3
3
|
import { transformOrderToText } from './order-parser/index.js';
|
|
4
|
-
import mustache from 'mustache';
|
|
5
4
|
|
|
6
5
|
const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
|
|
7
6
|
|
|
8
|
-
const textTemplate = `
|
|
9
|
-
New Order received:
|
|
10
|
-
|
|
11
|
-
{{orderDetails}}
|
|
12
|
-
|
|
13
|
-
{{shopName}}: {{shopUrl}}
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
7
|
export const resolveForwardDeliveryTemplate: TemplateResolver = async ({ config, orderId }, context) => {
|
|
17
8
|
const { modules } = context;
|
|
18
9
|
const order = await modules.orders.findOrder({ orderId });
|
|
@@ -26,16 +17,15 @@ export const resolveForwardDeliveryTemplate: TemplateResolver = async ({ config,
|
|
|
26
17
|
|
|
27
18
|
const subject = `${EMAIL_WEBSITE_NAME} Order ${order.orderNumber}`;
|
|
28
19
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
20
|
+
const orderDetails = await transformOrderToText({ order, locale: systemLocale }, context);
|
|
21
|
+
|
|
22
|
+
const text = `
|
|
23
|
+
New Order received:
|
|
24
|
+
|
|
25
|
+
${orderDetails}
|
|
26
|
+
|
|
27
|
+
${EMAIL_WEBSITE_NAME}: ${EMAIL_WEBSITE_URL}
|
|
28
|
+
`;
|
|
39
29
|
|
|
40
30
|
return [
|
|
41
31
|
{
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { TemplateResolver } from '@unchainedshop/core';
|
|
2
2
|
import { transformOrderToText } from './order-parser/index.js';
|
|
3
|
-
import mustache from 'mustache';
|
|
4
3
|
|
|
5
4
|
const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
|
|
6
5
|
|
|
7
|
-
const textTemplate = `
|
|
8
|
-
Thank you very much for your order.
|
|
9
|
-
|
|
10
|
-
{{orderDetails}}
|
|
11
|
-
|
|
12
|
-
{{shopName}}: {{shopUrl}}
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
6
|
export const resolveOrderConfirmationTemplate: TemplateResolver<{
|
|
16
7
|
orderId: string;
|
|
17
8
|
locale: string;
|
|
@@ -25,16 +16,15 @@ export const resolveOrderConfirmationTemplate: TemplateResolver<{
|
|
|
25
16
|
|
|
26
17
|
const subject = `Order ${order.orderNumber}`;
|
|
27
18
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
19
|
+
const orderDetails = await transformOrderToText({ order, locale: new Intl.Locale(locale) }, context);
|
|
20
|
+
|
|
21
|
+
const text = `
|
|
22
|
+
Thank you very much for your order.
|
|
23
|
+
|
|
24
|
+
${orderDetails}
|
|
25
|
+
|
|
26
|
+
${EMAIL_WEBSITE_NAME}: ${EMAIL_WEBSITE_URL}
|
|
27
|
+
`;
|
|
38
28
|
|
|
39
29
|
return [
|
|
40
30
|
{
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { TemplateResolver } from '@unchainedshop/core';
|
|
2
2
|
import { transformOrderToText } from './order-parser/index.js';
|
|
3
|
-
import mustache from 'mustache';
|
|
4
3
|
|
|
5
4
|
const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
|
|
6
5
|
|
|
7
|
-
const textTemplate = `
|
|
8
|
-
I'm sorry we can't confirm your order.
|
|
9
|
-
|
|
10
|
-
This can happen when the payment was not successful or the order was manually canceled because of product availability or fullfillment issues.
|
|
11
|
-
|
|
12
|
-
The order in question is:
|
|
13
|
-
|
|
14
|
-
{{orderDetails}}
|
|
15
|
-
|
|
16
|
-
{{shopName}}: {{shopUrl}}
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
6
|
export const resolveOrderRejectionTemplate: TemplateResolver = async ({ orderId, locale }, context) => {
|
|
20
7
|
const { modules } = context;
|
|
21
8
|
const order = await modules.orders.findOrder({ orderId });
|
|
@@ -26,16 +13,19 @@ export const resolveOrderRejectionTemplate: TemplateResolver = async ({ orderId,
|
|
|
26
13
|
|
|
27
14
|
const subject = `Order rejected ${order.orderNumber}`;
|
|
28
15
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const orderDetails = await transformOrderToText({ order, locale: new Intl.Locale(locale) }, context);
|
|
17
|
+
|
|
18
|
+
const text = `
|
|
19
|
+
I'm sorry we can't confirm your order.
|
|
20
|
+
|
|
21
|
+
This can happen when the payment was not successful or the order was manually canceled because of product availability or fullfillment issues.
|
|
22
|
+
|
|
23
|
+
The order in question is:
|
|
24
|
+
|
|
25
|
+
${orderDetails}
|
|
26
|
+
|
|
27
|
+
${EMAIL_WEBSITE_NAME}: ${EMAIL_WEBSITE_URL}
|
|
28
|
+
`;
|
|
39
29
|
|
|
40
30
|
return [
|
|
41
31
|
{
|