@unchainedshop/platform 3.0.0-rc1 → 3.0.0-rc10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/bulk-importer/createBulkImporter.d.ts +4 -0
  2. package/lib/bulk-importer/createBulkImporter.d.ts.map +1 -1
  3. package/lib/bulk-importer/createBulkImporter.js +1 -0
  4. package/lib/bulk-importer/createBulkImporter.js.map +1 -1
  5. package/lib/migrations/migrationRepository.js +1 -1
  6. package/lib/migrations/migrationRepository.js.map +1 -1
  7. package/lib/platform-index.d.ts +2 -0
  8. package/lib/platform-index.d.ts.map +1 -1
  9. package/lib/platform-index.js +2 -0
  10. package/lib/platform-index.js.map +1 -1
  11. package/lib/setup/setupTemplates.js +1 -1
  12. package/lib/setup/setupTemplates.js.map +1 -1
  13. package/lib/templates/index.d.ts +9 -0
  14. package/lib/templates/index.d.ts.map +1 -0
  15. package/lib/templates/index.js +9 -0
  16. package/lib/templates/index.js.map +1 -0
  17. package/lib/templates/order-parser/getOrderPositionsData.d.ts +2 -5
  18. package/lib/templates/order-parser/getOrderPositionsData.d.ts.map +1 -1
  19. package/lib/templates/order-parser/getOrderPositionsData.js +2 -2
  20. package/lib/templates/order-parser/getOrderPositionsData.js.map +1 -1
  21. package/lib/templates/order-parser/getOrderSummaryData.d.ts.map +1 -1
  22. package/lib/templates/order-parser/getOrderSummaryData.js +4 -5
  23. package/lib/templates/order-parser/getOrderSummaryData.js.map +1 -1
  24. package/lib/templates/order-parser/index.d.ts +5 -1
  25. package/lib/templates/order-parser/index.d.ts.map +1 -1
  26. package/lib/templates/order-parser/index.js +4 -4
  27. package/lib/templates/order-parser/index.js.map +1 -1
  28. package/lib/templates/resolveAccountActionTemplate.d.ts.map +1 -1
  29. package/lib/templates/resolveAccountActionTemplate.js +4 -3
  30. package/lib/templates/resolveAccountActionTemplate.js.map +1 -1
  31. package/lib/templates/resolveEnrollmentStatusTemplate.d.ts.map +1 -1
  32. package/lib/templates/resolveEnrollmentStatusTemplate.js +4 -3
  33. package/lib/templates/resolveEnrollmentStatusTemplate.js.map +1 -1
  34. package/lib/templates/resolveErrorReportTemplate.d.ts.map +1 -1
  35. package/lib/templates/resolveErrorReportTemplate.js +10 -9
  36. package/lib/templates/resolveErrorReportTemplate.js.map +1 -1
  37. package/lib/templates/resolveForwardDeliveryTemplate.d.ts.map +1 -1
  38. package/lib/templates/resolveForwardDeliveryTemplate.js +4 -3
  39. package/lib/templates/resolveForwardDeliveryTemplate.js.map +1 -1
  40. package/lib/templates/resolveOrderConfirmationTemplate.d.ts.map +1 -1
  41. package/lib/templates/resolveOrderConfirmationTemplate.js +4 -3
  42. package/lib/templates/resolveOrderConfirmationTemplate.js.map +1 -1
  43. package/lib/templates/resolveOrderRejectionTemplate.d.ts.map +1 -1
  44. package/lib/templates/resolveOrderRejectionTemplate.js +4 -3
  45. package/lib/templates/resolveOrderRejectionTemplate.js.map +1 -1
  46. package/lib/templates/resolveQuotationStatusTemplate.d.ts.map +1 -1
  47. package/lib/templates/resolveQuotationStatusTemplate.js +4 -3
  48. package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -1
  49. package/package.json +20 -12
  50. package/src/bulk-importer/createBulkImporter.ts +2 -0
  51. package/src/migrations/migrationRepository.ts +1 -1
  52. package/src/platform-index.ts +2 -0
  53. package/src/setup/setupTemplates.ts +1 -1
  54. package/src/templates/index.ts +9 -0
  55. package/src/templates/order-parser/getOrderPositionsData.ts +3 -3
  56. package/src/templates/order-parser/getOrderSummaryData.ts +6 -5
  57. package/src/templates/order-parser/index.ts +18 -11
  58. package/src/templates/resolveAccountActionTemplate.ts +13 -7
  59. package/src/templates/resolveEnrollmentStatusTemplate.ts +13 -8
  60. package/src/templates/resolveErrorReportTemplate.ts +15 -9
  61. package/src/templates/resolveForwardDeliveryTemplate.ts +12 -6
  62. package/src/templates/resolveOrderConfirmationTemplate.ts +12 -6
  63. package/src/templates/resolveOrderRejectionTemplate.ts +12 -6
  64. package/src/templates/resolveQuotationStatusTemplate.ts +13 -7
  65. package/lib/templates/order-parser/formatAddress.d.ts +0 -3
  66. package/lib/templates/order-parser/formatAddress.d.ts.map +0 -1
  67. package/lib/templates/order-parser/formatAddress.js +0 -14
  68. package/lib/templates/order-parser/formatAddress.js.map +0 -1
  69. package/lib/templates/order-parser/formatPrice.d.ts +0 -6
  70. package/lib/templates/order-parser/formatPrice.d.ts.map +0 -1
  71. package/lib/templates/order-parser/formatPrice.js +0 -6
  72. package/lib/templates/order-parser/formatPrice.js.map +0 -1
  73. package/src/templates/order-parser/formatAddress.ts +0 -15
  74. package/src/templates/order-parser/formatPrice.ts +0 -6
@@ -1,3 +1,4 @@
1
+ import mustache from 'mustache';
1
2
  const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
2
3
  const textTemplate = `
3
4
  {{subject}}\n
@@ -18,12 +19,12 @@ export const resolveQuotationStatusTemplate = async ({ quotationId, locale }, {
18
19
  path: file.url,
19
20
  }));
20
21
  const subject = `${EMAIL_WEBSITE_NAME}: Updated Quotation / ${quotation.quotationNumber}`;
21
- const data = {
22
+ const text = mustache.render(textTemplate, {
22
23
  locale,
23
24
  quotation,
24
25
  subject,
25
26
  url: `${EMAIL_WEBSITE_URL}/quotation?_id=${quotation._id}`,
26
- };
27
+ }, undefined, { escape: (t) => t });
27
28
  return [
28
29
  {
29
30
  type: 'EMAIL',
@@ -31,7 +32,7 @@ export const resolveQuotationStatusTemplate = async ({ quotationId, locale }, {
31
32
  from: EMAIL_FROM,
32
33
  to: modules.users.primaryEmail(user)?.address,
33
34
  subject,
34
- text: modules.messaging.renderToText(textTemplate, data),
35
+ text,
35
36
  attachments,
36
37
  },
37
38
  },
@@ -1 +1 @@
1
- {"version":3,"file":"resolveQuotationStatusTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveQuotationStatusTemplate.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,UAAU,EAAE,kBAAkB,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,IAAI,GAAG,QAAQ,CAAC,MAAM,CAC1B,YAAY,EACZ;QACE,MAAM;QACN,SAAS;QACT,OAAO;QACP,GAAG,EAAE,GAAG,iBAAiB,kBAAkB,SAAS,CAAC,GAAG,EAAE;KAC3D,EACD,SAAS,EACT,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CACrB,CAAC;IAEF,OAAO;QACL;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;gBAChB,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO;gBAC7C,OAAO;gBACP,IAAI;gBACJ,WAAW;aACZ;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/platform",
3
- "version": "3.0.0-rc1",
3
+ "version": "3.0.0-rc10",
4
4
  "main": "lib/platform-index.js",
5
5
  "types": "lib/platform-index.d.ts",
6
6
  "type": "module",
@@ -21,26 +21,34 @@
21
21
  "ecommerce",
22
22
  "core"
23
23
  ],
24
- "author": "Joël Meiller",
24
+ "authors": [
25
+ "Joël Meiller",
26
+ "Pascal Kaufmann"
27
+ ],
25
28
  "license": "EUPL-1.2",
26
29
  "bugs": {
27
30
  "url": "https://github.com/unchainedshop/unchained/issues"
28
31
  },
29
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
+ "engines": {
34
+ "node": ">=22.0.0"
35
+ },
30
36
  "dependencies": {
31
- "@unchainedshop/api": "^3.0.0-rc1",
32
- "@unchainedshop/core": "^3.0.0-rc1",
33
- "@unchainedshop/events": "^3.0.0-rc1",
34
- "@unchainedshop/file-upload": "^3.0.0-rc1",
35
- "@unchainedshop/logger": "^3.0.0-rc1",
36
- "@unchainedshop/mongodb": "^3.0.0-rc1",
37
- "@unchainedshop/plugins": "^3.0.0-rc1",
38
- "@unchainedshop/roles": "^3.0.0-rc1",
39
- "@unchainedshop/utils": "^3.0.0-rc1"
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"
40
48
  },
41
49
  "devDependencies": {
50
+ "@types/mustache": "^4.2.5",
42
51
  "@types/node": "^22.10.2",
43
- "cross-env": "^7.0.3",
44
52
  "jest": "^29.7.0",
45
53
  "ts-jest": "^29.2.5",
46
54
  "typescript": "^5.7.2"
@@ -132,3 +132,5 @@ export const createBulkImporterFactory = (db, bulkImporterOptions: any): BulkImp
132
132
  createBulkImporter,
133
133
  };
134
134
  };
135
+
136
+ export { AssortmentHandlers, ProductHandlers, FilterHandlers };
@@ -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()].sort((left, right) => {
12
+ return [...migrations.values()].toSorted((left, right) => {
13
13
  return left.id - right.id;
14
14
  });
15
15
  },
@@ -1,2 +1,4 @@
1
1
  export * from './startPlatform.js';
2
2
  export * from './context/index.js';
3
+ export * from './bulk-importer/createBulkImporter.js';
4
+ export * from './templates/index.js';
@@ -73,7 +73,7 @@ export const setupTemplates = (unchainedAPI: UnchainedCore) => {
73
73
  type: 'MESSAGE',
74
74
  retries: 0,
75
75
  input: {
76
- locale,
76
+ locale: locale.baseName,
77
77
  template: MessageTypes.ORDER_REJECTION,
78
78
  orderId: order._id,
79
79
  },
@@ -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,17 +1,17 @@
1
1
  import { UnchainedCore } from '@unchainedshop/core';
2
2
  import { Order } from '@unchainedshop/core-orders';
3
- import formatPrice from './formatPrice.js';
4
3
  import { ProductPricingSheet } from '@unchainedshop/core';
4
+ import { ch } from '@unchainedshop/utils';
5
5
 
6
6
  type PriceFormatter = ({ amount, currency }: { amount: number; currency: string }) => string;
7
7
 
8
8
  export const getOrderPositionsData = async (
9
9
  order: Order,
10
- params: { locale?: string; useNetPrice?: boolean; format?: PriceFormatter },
10
+ params: { locale: string; useNetPrice?: boolean; format?: PriceFormatter },
11
11
  context: UnchainedCore,
12
12
  ) => {
13
13
  const { modules } = context;
14
- const { useNetPrice, format = formatPrice } = params || {};
14
+ const { useNetPrice, format = ch.priceToString } = params || {};
15
15
  const orderPositions = await modules.orders.positions.findOrderPositions({
16
16
  orderId: order._id,
17
17
  });
@@ -1,7 +1,6 @@
1
1
  import { Order } from '@unchainedshop/core-orders';
2
2
  import { UnchainedCore, OrderPricingSheet, OrderPricingRowCategory } from '@unchainedshop/core';
3
- import formatPrice from './formatPrice.js';
4
- import { formatAddress } from './formatAddress.js';
3
+ import { ch } from '@unchainedshop/utils';
5
4
 
6
5
  type PriceFormatter = ({ amount, currency }: { amount: number; currency: string }) => string;
7
6
 
@@ -11,7 +10,7 @@ export const getOrderSummaryData = async (
11
10
  context: UnchainedCore,
12
11
  ) => {
13
12
  const { modules } = context;
14
- const { useNetPrice, format = formatPrice } = params || {};
13
+ const { useNetPrice, format = ch.priceToString } = params || {};
15
14
  const orderDelivery = await modules.orders.deliveries.findDelivery({
16
15
  orderDeliveryId: order.deliveryId,
17
16
  });
@@ -25,8 +24,10 @@ export const getOrderSummaryData = async (
25
24
  deliveryProviderId: orderDelivery.deliveryProviderId,
26
25
  });
27
26
 
28
- const deliveryAddress = formatAddress(orderDelivery?.context?.deliveryAddress || order.billingAddress);
29
- const billingAddress = formatAddress(order.billingAddress);
27
+ const deliveryAddress = ch.addressToString(
28
+ orderDelivery?.context?.deliveryAddress || order.billingAddress,
29
+ );
30
+ const billingAddress = ch.addressToString(order.billingAddress);
30
31
  const orderPricing = OrderPricingSheet({
31
32
  calculation: order.calculation,
32
33
  currency: order.currency,
@@ -1,6 +1,9 @@
1
- import { Order } from '@unchainedshop/core-orders';
2
1
  import { getOrderPositionsData } from './getOrderPositionsData.js';
3
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';
4
7
 
5
8
  const textTemplate = `Order number: {{orderNumber}}
6
9
  Ordered: {{orderDate}}
@@ -34,15 +37,19 @@ Total: {{summary.prices.gross}}
34
37
 
35
38
  export const transformOrderToText = async (
36
39
  { order, locale }: { order: Order; locale: string },
37
- context,
40
+ context: UnchainedCore,
38
41
  ) => {
39
- const { modules } = context;
40
- const data = {
41
- orderDate: new Date(order.ordered).toLocaleString(),
42
- orderNumber: order.orderNumber,
43
- summary: await getOrderSummaryData(order, { locale }, context),
44
- positions: await getOrderPositionsData(order, { locale }, context),
45
- };
46
-
47
- return modules.messaging.renderToText(textTemplate, data);
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
+ );
48
53
  };
54
+
55
+ export { getOrderPositionsData, getOrderSummaryData };
@@ -1,4 +1,5 @@
1
1
  import { TemplateResolver } from '@unchainedshop/core';
2
+ import mustache from 'mustache';
2
3
 
3
4
  const { EMAIL_FROM, EMAIL_WEBSITE_URL, EMAIL_WEBSITE_NAME } = process.env;
4
5
 
@@ -96,12 +97,17 @@ export const resolveAccountActionTemplate: TemplateResolver = async (
96
97
  const { url } = emailConfig[action];
97
98
  const { subject, message, buttonText } = emailConfig[action][locale.language];
98
99
 
99
- const data = {
100
- buttonText,
101
- message,
102
- subject,
103
- url: url(token),
104
- };
100
+ const text = mustache.render(
101
+ textTemplate,
102
+ {
103
+ buttonText,
104
+ message,
105
+ subject,
106
+ url: url(token),
107
+ },
108
+ undefined,
109
+ { escape: (t) => t },
110
+ );
105
111
 
106
112
  return [
107
113
  {
@@ -110,7 +116,7 @@ export const resolveAccountActionTemplate: TemplateResolver = async (
110
116
  from: EMAIL_FROM || 'noreply@unchained.local',
111
117
  to: recipientEmail || modules.users.primaryEmail(user)?.address,
112
118
  subject,
113
- text: modules.messaging.renderToText(textTemplate, data),
119
+ text,
114
120
  },
115
121
  },
116
122
  ];
@@ -1,5 +1,5 @@
1
1
  import { TemplateResolver } from '@unchainedshop/core';
2
-
2
+ import mustache from 'mustache';
3
3
  const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
4
4
 
5
5
  const textTemplate = `
@@ -22,12 +22,17 @@ export const resolveEnrollmentStatusTemplate: TemplateResolver = async (
22
22
 
23
23
  const subject = `${EMAIL_WEBSITE_NAME}: Updated Enrollment / ${enrollment.enrollmentNumber}`;
24
24
 
25
- const data = {
26
- enrollment,
27
- locale,
28
- subject,
29
- url: `${EMAIL_WEBSITE_URL}/enrollment?_id=${enrollment._id}`,
30
- };
25
+ const text = mustache.render(
26
+ textTemplate,
27
+ {
28
+ enrollment,
29
+ locale,
30
+ subject,
31
+ url: `${EMAIL_WEBSITE_URL}/enrollment?_id=${enrollment._id}`,
32
+ },
33
+ undefined,
34
+ { escape: (t) => t },
35
+ );
31
36
 
32
37
  return [
33
38
  {
@@ -36,7 +41,7 @@ export const resolveEnrollmentStatusTemplate: TemplateResolver = async (
36
41
  from: EMAIL_FROM || 'noreply@unchained.local',
37
42
  to: modules.users.primaryEmail(user)?.address,
38
43
  subject,
39
- text: modules.messaging.renderToText(textTemplate, data),
44
+ text,
40
45
  },
41
46
  },
42
47
  ];
@@ -1,5 +1,6 @@
1
1
  import { TemplateResolver } from '@unchainedshop/core';
2
- import util from 'util';
2
+ import { stringify } from 'safe-stable-stringify';
3
+ import mustache from 'mustache';
3
4
 
4
5
  const {
5
6
  EMAIL_FROM = 'noreply@unchained.local',
@@ -11,7 +12,7 @@ const {
11
12
  const formatWorkItems = (workItems) => {
12
13
  return workItems
13
14
  .map(({ _id, type, started, error }) => {
14
- const stringifiedErrors = util.inspect(error, false, 10, false);
15
+ const stringifiedErrors = stringify(error, null, 2);
15
16
  return `${new Date(started).toLocaleString()} ${type} (${_id}): ${stringifiedErrors}`;
16
17
  })
17
18
  .join('\n');
@@ -26,8 +27,17 @@ Shop Name: {{name}}
26
27
  {{content}}
27
28
  `;
28
29
 
29
- const resolveErrorReportTemplate: TemplateResolver = async ({ workItems }, context) => {
30
- const { modules } = context;
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
+ );
31
41
 
32
42
  return [
33
43
  {
@@ -36,11 +46,7 @@ const resolveErrorReportTemplate: TemplateResolver = async ({ workItems }, conte
36
46
  from: EMAIL_FROM || 'noreply@unchained.local',
37
47
  to: EMAIL_ERROR_REPORT_RECIPIENT,
38
48
  subject: `${EMAIL_WEBSITE_NAME}: Queue Errors`,
39
- text: modules.messaging.renderToText(textTemplate, {
40
- endpoint: ROOT_URL,
41
- content: formatWorkItems(workItems),
42
- name: EMAIL_WEBSITE_NAME,
43
- }),
49
+ text,
44
50
  },
45
51
  },
46
52
  ];
@@ -1,6 +1,7 @@
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';
4
5
 
5
6
  const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
6
7
 
@@ -25,11 +26,16 @@ export const resolveForwardDeliveryTemplate: TemplateResolver = async ({ config,
25
26
 
26
27
  const subject = `${EMAIL_WEBSITE_NAME} Order ${order.orderNumber}`;
27
28
 
28
- const data = {
29
- shopName: EMAIL_WEBSITE_NAME,
30
- shopUrl: EMAIL_WEBSITE_URL,
31
- orderDetails: await transformOrderToText({ order, locale: systemLocale.baseName }, context),
32
- };
29
+ const text = mustache.render(
30
+ textTemplate,
31
+ {
32
+ shopName: EMAIL_WEBSITE_NAME,
33
+ shopUrl: EMAIL_WEBSITE_URL,
34
+ orderDetails: await transformOrderToText({ order, locale: systemLocale.baseName }, context),
35
+ },
36
+ undefined,
37
+ { escape: (t) => t },
38
+ );
33
39
 
34
40
  return [
35
41
  {
@@ -39,7 +45,7 @@ export const resolveForwardDeliveryTemplate: TemplateResolver = async ({ config,
39
45
  to: configObject.to || 'orders@unchained.local',
40
46
  cc: configObject.cc,
41
47
  subject,
42
- text: modules.messaging.renderToText(textTemplate, data),
48
+ text,
43
49
  },
44
50
  },
45
51
  ];
@@ -1,5 +1,6 @@
1
1
  import { TemplateResolver } from '@unchainedshop/core';
2
2
  import { transformOrderToText } from './order-parser/index.js';
3
+ import mustache from 'mustache';
3
4
 
4
5
  const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
5
6
 
@@ -24,11 +25,16 @@ export const resolveOrderConfirmationTemplate: TemplateResolver<{
24
25
 
25
26
  const subject = `Order ${order.orderNumber}`;
26
27
 
27
- const data = {
28
- shopName: EMAIL_WEBSITE_NAME,
29
- shopUrl: EMAIL_WEBSITE_URL,
30
- orderDetails: await transformOrderToText({ order, locale }, context),
31
- };
28
+ const text = mustache.render(
29
+ textTemplate,
30
+ {
31
+ shopName: EMAIL_WEBSITE_NAME,
32
+ shopUrl: EMAIL_WEBSITE_URL,
33
+ orderDetails: await transformOrderToText({ order, locale }, context),
34
+ },
35
+ undefined,
36
+ { escape: (t) => t },
37
+ );
32
38
 
33
39
  return [
34
40
  {
@@ -37,7 +43,7 @@ export const resolveOrderConfirmationTemplate: TemplateResolver<{
37
43
  from: `${EMAIL_WEBSITE_NAME} <${EMAIL_FROM || 'noreply@unchained.local'}>`,
38
44
  to: order.contact.emailAddress,
39
45
  subject,
40
- text: modules.messaging.renderToText(textTemplate, data),
46
+ text,
41
47
  },
42
48
  },
43
49
  ];
@@ -1,5 +1,6 @@
1
1
  import { TemplateResolver } from '@unchainedshop/core';
2
2
  import { transformOrderToText } from './order-parser/index.js';
3
+ import mustache from 'mustache';
3
4
 
4
5
  const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
5
6
 
@@ -25,11 +26,16 @@ export const resolveOrderRejectionTemplate: TemplateResolver = async ({ orderId,
25
26
 
26
27
  const subject = `Order rejected ${order.orderNumber}`;
27
28
 
28
- const data = {
29
- shopName: EMAIL_WEBSITE_NAME,
30
- shopUrl: EMAIL_WEBSITE_URL,
31
- orderDetails: await transformOrderToText({ order, locale }, context),
32
- };
29
+ const text = mustache.render(
30
+ textTemplate,
31
+ {
32
+ shopName: EMAIL_WEBSITE_NAME,
33
+ shopUrl: EMAIL_WEBSITE_URL,
34
+ orderDetails: await transformOrderToText({ order, locale }, context),
35
+ },
36
+ undefined,
37
+ { escape: (t) => t },
38
+ );
33
39
 
34
40
  return [
35
41
  {
@@ -38,7 +44,7 @@ export const resolveOrderRejectionTemplate: TemplateResolver = async ({ orderId,
38
44
  from: `${EMAIL_WEBSITE_NAME} <${EMAIL_FROM || 'noreply@unchained.local'}>`,
39
45
  to: order.contact.emailAddress,
40
46
  subject,
41
- text: modules.messaging.renderToText(textTemplate, data),
47
+ text,
42
48
  },
43
49
  },
44
50
  ];
@@ -1,4 +1,5 @@
1
1
  import { TemplateResolver } from '@unchainedshop/core';
2
+ import mustache from 'mustache';
2
3
 
3
4
  const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
4
5
 
@@ -32,12 +33,17 @@ export const resolveQuotationStatusTemplate: TemplateResolver = async (
32
33
 
33
34
  const subject = `${EMAIL_WEBSITE_NAME}: Updated Quotation / ${quotation.quotationNumber}`;
34
35
 
35
- const data = {
36
- locale,
37
- quotation,
38
- subject,
39
- url: `${EMAIL_WEBSITE_URL}/quotation?_id=${quotation._id}`,
40
- };
36
+ const text = mustache.render(
37
+ textTemplate,
38
+ {
39
+ locale,
40
+ quotation,
41
+ subject,
42
+ url: `${EMAIL_WEBSITE_URL}/quotation?_id=${quotation._id}`,
43
+ },
44
+ undefined,
45
+ { escape: (t) => t },
46
+ );
41
47
 
42
48
  return [
43
49
  {
@@ -46,7 +52,7 @@ export const resolveQuotationStatusTemplate: TemplateResolver = async (
46
52
  from: EMAIL_FROM,
47
53
  to: modules.users.primaryEmail(user)?.address,
48
54
  subject,
49
- text: modules.messaging.renderToText(textTemplate, data),
55
+ text,
50
56
  attachments,
51
57
  },
52
58
  },
@@ -1,3 +0,0 @@
1
- import { Address } from '@unchainedshop/mongodb';
2
- export declare const formatAddress: (address: Address) => string;
3
- //# sourceMappingURL=formatAddress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatAddress.d.ts","sourceRoot":"","sources":["../../../src/templates/order-parser/formatAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,eAAO,MAAM,aAAa,YAAa,OAAO,WAY7C,CAAC"}
@@ -1,14 +0,0 @@
1
- export const formatAddress = (address) => {
2
- return [
3
- [address.firstName, address.lastName].filter(Boolean).join(' '),
4
- address.company,
5
- address.addressLine,
6
- address.addressLine2,
7
- [address.postalCode, address.city].filter(Boolean).join(' '),
8
- address.regionCode,
9
- [address.countryCode].filter(Boolean).join(''),
10
- ]
11
- .filter(Boolean)
12
- .join('\n');
13
- };
14
- //# sourceMappingURL=formatAddress.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatAddress.js","sourceRoot":"","sources":["../../../src/templates/order-parser/formatAddress.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,EAAE;IAChD,OAAO;QACL,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/D,OAAO,CAAC,OAAO;QACf,OAAO,CAAC,WAAW;QACnB,OAAO,CAAC,YAAY;QACpB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAC5D,OAAO,CAAC,UAAU;QAClB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;KAC/C;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const formatPrice: ({ amount, currency }: {
2
- amount: number;
3
- currency: string;
4
- }) => string;
5
- export default formatPrice;
6
- //# sourceMappingURL=formatPrice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatPrice.d.ts","sourceRoot":"","sources":["../../../src/templates/order-parser/formatPrice.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,yBAA0B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,WAGrF,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,6 +0,0 @@
1
- export const formatPrice = ({ amount, currency }) => {
2
- const fixedPrice = amount / 100;
3
- return `${currency} ${fixedPrice}`;
4
- };
5
- export default formatPrice;
6
- //# sourceMappingURL=formatPrice.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatPrice.js","sourceRoot":"","sources":["../../../src/templates/order-parser/formatPrice.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAwC,EAAE,EAAE;IACxF,MAAM,UAAU,GAAG,MAAM,GAAG,GAAG,CAAC;IAChC,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,15 +0,0 @@
1
- import { Address } from '@unchainedshop/mongodb';
2
-
3
- export const formatAddress = (address: Address) => {
4
- return [
5
- [address.firstName, address.lastName].filter(Boolean).join(' '),
6
- address.company,
7
- address.addressLine,
8
- address.addressLine2,
9
- [address.postalCode, address.city].filter(Boolean).join(' '),
10
- address.regionCode,
11
- [address.countryCode].filter(Boolean).join(''),
12
- ]
13
- .filter(Boolean)
14
- .join('\n');
15
- };
@@ -1,6 +0,0 @@
1
- export const formatPrice = ({ amount, currency }: { amount: number; currency: string }) => {
2
- const fixedPrice = amount / 100;
3
- return `${currency} ${fixedPrice}`;
4
- };
5
-
6
- export default formatPrice;