@unchainedshop/platform 4.3.4 → 4.5.0

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 (114) hide show
  1. package/README.md +149 -2
  2. package/lib/migrations/createMigrationRunner.d.ts +0 -1
  3. package/lib/migrations/createMigrationRunner.js +0 -3
  4. package/lib/migrations/migrationRepository.d.ts +1 -2
  5. package/lib/migrations/migrationRepository.js +1 -1
  6. package/lib/migrations/runMigrations.d.ts +2 -3
  7. package/lib/migrations/runMigrations.js +1 -2
  8. package/lib/platform-index.d.ts +3 -5
  9. package/lib/platform-index.js +3 -5
  10. package/lib/setup/setupAccounts.d.ts +1 -2
  11. package/lib/setup/setupAccounts.js +0 -1
  12. package/lib/setup/setupTemplates.d.ts +11 -11
  13. package/lib/setup/setupTemplates.js +16 -19
  14. package/lib/setup/setupUploadHandlers.d.ts +1 -2
  15. package/lib/setup/setupUploadHandlers.js +0 -1
  16. package/lib/setup/setupWorkqueue.d.ts +2 -3
  17. package/lib/setup/setupWorkqueue.js +1 -7
  18. package/lib/startPlatform.d.ts +6 -7
  19. package/lib/startPlatform.js +10 -20
  20. package/lib/templates/index.d.ts +8 -9
  21. package/lib/templates/index.js +8 -9
  22. package/lib/templates/order-parser/getOrderPositionsData.d.ts +2 -3
  23. package/lib/templates/order-parser/getOrderPositionsData.js +0 -1
  24. package/lib/templates/order-parser/getOrderSummaryData.d.ts +2 -3
  25. package/lib/templates/order-parser/getOrderSummaryData.js +0 -1
  26. package/lib/templates/order-parser/index.d.ts +4 -5
  27. package/lib/templates/order-parser/index.js +2 -3
  28. package/lib/templates/resolveAccountActionTemplate.d.ts +1 -2
  29. package/lib/templates/resolveAccountActionTemplate.js +0 -2
  30. package/lib/templates/resolveEnrollmentStatusTemplate.d.ts +1 -2
  31. package/lib/templates/resolveEnrollmentStatusTemplate.js +0 -1
  32. package/lib/templates/resolveErrorReportTemplate.d.ts +1 -2
  33. package/lib/templates/resolveErrorReportTemplate.js +0 -1
  34. package/lib/templates/resolveForwardDeliveryTemplate.d.ts +1 -2
  35. package/lib/templates/resolveForwardDeliveryTemplate.js +1 -2
  36. package/lib/templates/resolveOrderConfirmationTemplate.d.ts +1 -2
  37. package/lib/templates/resolveOrderConfirmationTemplate.js +1 -2
  38. package/lib/templates/resolveOrderRejectionTemplate.d.ts +1 -2
  39. package/lib/templates/resolveOrderRejectionTemplate.js +1 -2
  40. package/lib/templates/resolveQuotationStatusTemplate.d.ts +1 -2
  41. package/lib/templates/resolveQuotationStatusTemplate.js +0 -1
  42. package/package.json +17 -16
  43. package/lib/context/index.d.ts +0 -2
  44. package/lib/context/index.d.ts.map +0 -1
  45. package/lib/context/index.js +0 -2
  46. package/lib/context/index.js.map +0 -1
  47. package/lib/context/setAccessToken.d.ts +0 -4
  48. package/lib/context/setAccessToken.d.ts.map +0 -1
  49. package/lib/context/setAccessToken.js +0 -12
  50. package/lib/context/setAccessToken.js.map +0 -1
  51. package/lib/migrations/createMigrationRunner.d.ts.map +0 -1
  52. package/lib/migrations/createMigrationRunner.js.map +0 -1
  53. package/lib/migrations/migrationRepository.d.ts.map +0 -1
  54. package/lib/migrations/migrationRepository.js.map +0 -1
  55. package/lib/migrations/runMigrations.d.ts.map +0 -1
  56. package/lib/migrations/runMigrations.js.map +0 -1
  57. package/lib/platform-index.d.ts.map +0 -1
  58. package/lib/platform-index.js.map +0 -1
  59. package/lib/setup/setupAccounts.d.ts.map +0 -1
  60. package/lib/setup/setupAccounts.js.map +0 -1
  61. package/lib/setup/setupTemplates.d.ts.map +0 -1
  62. package/lib/setup/setupTemplates.js.map +0 -1
  63. package/lib/setup/setupUploadHandlers.d.ts.map +0 -1
  64. package/lib/setup/setupUploadHandlers.js.map +0 -1
  65. package/lib/setup/setupWorkqueue.d.ts.map +0 -1
  66. package/lib/setup/setupWorkqueue.js.map +0 -1
  67. package/lib/startPlatform.d.ts.map +0 -1
  68. package/lib/startPlatform.js.map +0 -1
  69. package/lib/templates/index.d.ts.map +0 -1
  70. package/lib/templates/index.js.map +0 -1
  71. package/lib/templates/order-parser/getOrderPositionsData.d.ts.map +0 -1
  72. package/lib/templates/order-parser/getOrderPositionsData.js.map +0 -1
  73. package/lib/templates/order-parser/getOrderSummaryData.d.ts.map +0 -1
  74. package/lib/templates/order-parser/getOrderSummaryData.js.map +0 -1
  75. package/lib/templates/order-parser/index.d.ts.map +0 -1
  76. package/lib/templates/order-parser/index.js.map +0 -1
  77. package/lib/templates/resolveAccountActionTemplate.d.ts.map +0 -1
  78. package/lib/templates/resolveAccountActionTemplate.js.map +0 -1
  79. package/lib/templates/resolveEnrollmentStatusTemplate.d.ts.map +0 -1
  80. package/lib/templates/resolveEnrollmentStatusTemplate.js.map +0 -1
  81. package/lib/templates/resolveErrorReportTemplate.d.ts.map +0 -1
  82. package/lib/templates/resolveErrorReportTemplate.js.map +0 -1
  83. package/lib/templates/resolveForwardDeliveryTemplate.d.ts.map +0 -1
  84. package/lib/templates/resolveForwardDeliveryTemplate.js.map +0 -1
  85. package/lib/templates/resolveOrderConfirmationTemplate.d.ts.map +0 -1
  86. package/lib/templates/resolveOrderConfirmationTemplate.js.map +0 -1
  87. package/lib/templates/resolveOrderRejectionTemplate.d.ts.map +0 -1
  88. package/lib/templates/resolveOrderRejectionTemplate.js.map +0 -1
  89. package/lib/templates/resolveQuotationStatusTemplate.d.ts.map +0 -1
  90. package/lib/templates/resolveQuotationStatusTemplate.js.map +0 -1
  91. package/src/context/index.ts +0 -1
  92. package/src/context/setAccessToken.ts +0 -22
  93. package/src/migrations/createMigrationRunner.ts +0 -65
  94. package/src/migrations/migrationRepository.ts +0 -22
  95. package/src/migrations/runMigrations.ts +0 -68
  96. package/src/platform-index.ts +0 -19
  97. package/src/setup/setupAccounts.ts +0 -11
  98. package/src/setup/setupTemplates.ts +0 -67
  99. package/src/setup/setupUploadHandlers.ts +0 -22
  100. package/src/setup/setupWorkqueue.ts +0 -104
  101. package/src/startPlatform.ts +0 -128
  102. package/src/templates/index.ts +0 -9
  103. package/src/templates/order-parser/getOrderPositionsData.ts +0 -50
  104. package/src/templates/order-parser/getOrderSummaryData.ts +0 -91
  105. package/src/templates/order-parser/index.ts +0 -65
  106. package/src/templates/resolveAccountActionTemplate.ts +0 -127
  107. package/src/templates/resolveEnrollmentStatusTemplate.ts +0 -34
  108. package/src/templates/resolveErrorReportTemplate.ts +0 -47
  109. package/src/templates/resolveForwardDeliveryTemplate.ts +0 -42
  110. package/src/templates/resolveOrderConfirmationTemplate.ts +0 -40
  111. package/src/templates/resolveOrderRejectionTemplate.ts +0 -41
  112. package/src/templates/resolveQuotationStatusTemplate.ts +0 -45
  113. package/tests/platform-index.test.ts +0 -7
  114. package/tsconfig.json +0 -9
@@ -1,127 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
-
3
- const { EMAIL_FROM, EMAIL_WEBSITE_URL, EMAIL_WEBSITE_NAME } = process.env;
4
-
5
- const verifyEmailEnglishConfig = {
6
- buttonText: 'Verify email address',
7
- message: 'We need to ensure that this email is yours as a commercial partner.',
8
- subject: `${EMAIL_WEBSITE_NAME}: Verify your email address`,
9
- };
10
-
11
- const passwordChangedEmailEnglishConfig = {
12
- message: `
13
- Your account password has been successfully changed.\n
14
- `,
15
- subject: `${EMAIL_WEBSITE_NAME}: Your password has been changed`,
16
- };
17
-
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
- };
38
-
39
- const emailConfig = {
40
- 'enroll-account': {
41
- url: (token) => `${EMAIL_WEBSITE_URL}/enroll-account?token=${token}`,
42
- en: {
43
- buttonText: 'Set password',
44
- message: `${EMAIL_WEBSITE_NAME} has set up an user account for you. Please click below to set up a password and to finish the registration.`,
45
- subject: `${EMAIL_WEBSITE_NAME}: You got a new account`,
46
- },
47
- de: {
48
- buttonText: 'Passwort setzen',
49
- message: `${EMAIL_WEBSITE_NAME} hat für dich ein Benutzerkonto angelegt. Bitte klicke unten um ein Passwort zu setzen und damit die Registrierung abzuschliessen.`,
50
- subject: `${EMAIL_WEBSITE_NAME}: Für dich wurde ein Konto eingerichtet`,
51
- },
52
- fr: {
53
- buttonText: 'Set password',
54
- message: `${EMAIL_WEBSITE_NAME} has set up an user account for you. Please click below to set up a password and to finish the registration.`,
55
- subject: `${EMAIL_WEBSITE_NAME}: You got a new account`,
56
- },
57
- },
58
- 'reset-password': {
59
- url: (token) => `${EMAIL_WEBSITE_URL}/reset-password?token=${token}`,
60
- en: {
61
- buttonText: 'Set new password',
62
- message: `
63
- Click on „Set new password". If you don’t want to set a new password, just ignore this email.\n
64
- `,
65
- subject: `${EMAIL_WEBSITE_NAME}: Set password`,
66
- },
67
- de: {
68
- buttonText: 'Neues Passwort setzen',
69
- message: `
70
- Klicke auf „Neues Passwort setzen", um ein neues Passwort anzulegen.\n
71
- Falls du dein Passwort nicht zurücksetzen möchtest, ignoriere dieses E-Mail einfach.\n
72
- `,
73
- subject: `${EMAIL_WEBSITE_NAME}: Passwort zurücksetzen`,
74
- },
75
- fr: {
76
- buttonText: 'Set new password',
77
- message: `
78
- Click on „Set new password". If you don’t want to set a new password, just ignore this email.\n
79
- `,
80
- subject: `${EMAIL_WEBSITE_NAME}: Set password`,
81
- },
82
- },
83
- 'verify-email': {
84
- url: (token) => `${EMAIL_WEBSITE_URL}/verify-email?token=${token}`,
85
- en: verifyEmailEnglishConfig,
86
- de: verifyEmailEnglishConfig,
87
- fr: verifyEmailEnglishConfig,
88
- },
89
- '': {
90
- // password changed!
91
- url: () => null,
92
- en: passwordChangedEmailEnglishConfig,
93
- de: passwordChangedEmailEnglishConfig,
94
- fr: passwordChangedEmailEnglishConfig,
95
- },
96
- };
97
-
98
- export const resolveAccountActionTemplate: TemplateResolver = async (
99
- { userId, action, recipientEmail, token },
100
- { modules },
101
- ) => {
102
- if (!token || !action) return [];
103
-
104
- const user = await modules.users.findUserById(userId);
105
- const locale = modules.users.userLocale(user);
106
-
107
- const { url } = emailConfig[action];
108
- const { subject, message, buttonText } = emailConfig[action][locale.language];
109
-
110
- const text = buildTextTemplate({
111
- buttonText,
112
- message,
113
- url: url(token),
114
- });
115
-
116
- return [
117
- {
118
- type: 'EMAIL',
119
- input: {
120
- from: EMAIL_FROM || 'noreply@unchained.local',
121
- to: recipientEmail || modules.users.primaryEmail(user)?.address,
122
- subject,
123
- text,
124
- },
125
- },
126
- ];
127
- };
@@ -1,34 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
-
3
- const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
4
-
5
- export const resolveEnrollmentStatusTemplate: TemplateResolver = async ({ enrollmentId }, context) => {
6
- const { modules } = context;
7
- const enrollment = await modules.enrollments.findEnrollment({ enrollmentId });
8
- const user = await modules.users.findUserById(enrollment.userId);
9
-
10
- const subject = `${EMAIL_WEBSITE_NAME}: Updated Enrollment / ${enrollment.enrollmentNumber}`;
11
- const url = `${EMAIL_WEBSITE_URL}/enrollment?_id=${enrollment._id}`;
12
-
13
- const text = `
14
- ${subject}\n
15
- \n
16
- Status: ${enrollment.status}
17
- \n
18
- -----------------\n
19
- Show: ${url}\n
20
- -----------------\n
21
- `;
22
-
23
- return [
24
- {
25
- type: 'EMAIL',
26
- input: {
27
- from: EMAIL_FROM || 'noreply@unchained.local',
28
- to: modules.users.primaryEmail(user)?.address,
29
- subject,
30
- text,
31
- },
32
- },
33
- ];
34
- };
@@ -1,47 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
- import { stringify } from 'safe-stable-stringify';
3
-
4
- const {
5
- EMAIL_FROM = 'noreply@unchained.local',
6
- EMAIL_ERROR_REPORT_RECIPIENT = 'support@unchained.local',
7
- EMAIL_WEBSITE_NAME = 'Unchained',
8
- ROOT_URL,
9
- } = process.env;
10
-
11
- const formatWorkItems = (workItems) => {
12
- return workItems
13
- .map(({ _id, type, started, error }) => {
14
- const stringifiedErrors = stringify(error, null, 2);
15
- return `${new Date(started).toLocaleString()} ${type} (${_id}): ${stringifiedErrors}`;
16
- })
17
- .join('\n');
18
- };
19
-
20
- const resolveErrorReportTemplate: TemplateResolver = async ({ workItems }) => {
21
- const content = formatWorkItems(workItems);
22
-
23
- const text = `
24
- -------------------------
25
- Unchained Endpoint: ${ROOT_URL}
26
- Shop Name: ${EMAIL_WEBSITE_NAME}
27
- -------------------------
28
-
29
- ${content}
30
- `;
31
-
32
- return [
33
- {
34
- type: 'EMAIL',
35
- input: {
36
- from: EMAIL_FROM || 'noreply@unchained.local',
37
- to: EMAIL_ERROR_REPORT_RECIPIENT,
38
- subject: `${EMAIL_WEBSITE_NAME}: Queue Errors`,
39
- text,
40
- },
41
- },
42
- ];
43
- };
44
-
45
- export { resolveErrorReportTemplate };
46
-
47
- export default resolveErrorReportTemplate;
@@ -1,42 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
- import { systemLocale } from '@unchainedshop/utils';
3
- import { transformOrderToText } from './order-parser/index.js';
4
-
5
- const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
6
-
7
- export const resolveForwardDeliveryTemplate: TemplateResolver = async ({ config, orderId }, context) => {
8
- const { modules } = context;
9
- const order = await modules.orders.findOrder({ orderId });
10
-
11
- const configObject = config.reduce((acc, { key, value }) => {
12
- return {
13
- ...acc,
14
- [key]: value,
15
- };
16
- }, {});
17
-
18
- const subject = `${EMAIL_WEBSITE_NAME} Order ${order.orderNumber}`;
19
-
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
- `;
29
-
30
- return [
31
- {
32
- type: 'EMAIL',
33
- input: {
34
- from: `${EMAIL_WEBSITE_NAME} <${configObject.from || EMAIL_FROM || 'noreply@unchained.local'}>`,
35
- to: configObject.to || 'orders@unchained.local',
36
- cc: configObject.cc,
37
- subject,
38
- text,
39
- },
40
- },
41
- ];
42
- };
@@ -1,40 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
- import { transformOrderToText } from './order-parser/index.js';
3
-
4
- const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
5
-
6
- export const resolveOrderConfirmationTemplate: TemplateResolver<{
7
- orderId: string;
8
- locale: string;
9
- }> = async ({ orderId, locale }, context) => {
10
- const { modules } = context;
11
- const order = await modules.orders.findOrder({ orderId });
12
-
13
- if (order.status === 'PENDING') {
14
- return [];
15
- }
16
-
17
- const subject = `Order ${order.orderNumber}`;
18
-
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
- `;
28
-
29
- return [
30
- {
31
- type: 'EMAIL',
32
- input: {
33
- from: `${EMAIL_WEBSITE_NAME} <${EMAIL_FROM || 'noreply@unchained.local'}>`,
34
- to: order.contact.emailAddress,
35
- subject,
36
- text,
37
- },
38
- },
39
- ];
40
- };
@@ -1,41 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
- import { transformOrderToText } from './order-parser/index.js';
3
-
4
- const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
5
-
6
- export const resolveOrderRejectionTemplate: TemplateResolver = async ({ orderId, locale }, context) => {
7
- const { modules } = context;
8
- const order = await modules.orders.findOrder({ orderId });
9
-
10
- if (order.status !== 'REJECTED') {
11
- return [];
12
- }
13
-
14
- const subject = `Order rejected ${order.orderNumber}`;
15
-
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
- `;
29
-
30
- return [
31
- {
32
- type: 'EMAIL',
33
- input: {
34
- from: `${EMAIL_WEBSITE_NAME} <${EMAIL_FROM || 'noreply@unchained.local'}>`,
35
- to: order.contact.emailAddress,
36
- subject,
37
- text,
38
- },
39
- },
40
- ];
41
- };
@@ -1,45 +0,0 @@
1
- import { TemplateResolver } from '@unchainedshop/core';
2
-
3
- const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
4
-
5
- export const resolveQuotationStatusTemplate: TemplateResolver = async ({ quotationId }, { modules }) => {
6
- const quotation = await modules.quotations.findQuotation({ quotationId });
7
- const user = await modules.users.findUserById(quotation.userId);
8
- const attachments = (
9
- await modules.files.findFiles(
10
- { 'meta.quotationId': quotation._id, 'meta.type': 'PROPOSAL' },
11
- { sort: { 'meta.date': -1 } },
12
- )
13
- )
14
- .filter(Boolean)
15
- .map((file) => ({
16
- filename: `${quotation.quotationNumber}_${file.name}`,
17
- path: file.url,
18
- }));
19
-
20
- const subject = `${EMAIL_WEBSITE_NAME}: Updated Quotation / ${quotation.quotationNumber}`;
21
- const url = `${EMAIL_WEBSITE_URL}/quotation?_id=${quotation._id}`;
22
-
23
- const text = `
24
- ${subject}\n
25
- \n
26
- Status: ${quotation.status}
27
- \n
28
- -----------------\n
29
- Show: ${url}\n
30
- -----------------\n
31
- `;
32
-
33
- return [
34
- {
35
- type: 'EMAIL',
36
- input: {
37
- from: EMAIL_FROM,
38
- to: modules.users.primaryEmail(user)?.address,
39
- subject,
40
- text,
41
- attachments,
42
- },
43
- },
44
- ];
45
- };
@@ -1,7 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- describe('Platform', () => {
4
- it('Init', () => {
5
- assert(true);
6
- });
7
- });
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../shared/base.tsconfig.json",
3
- "compilerOptions": {
4
- "declarationDir": "./lib",
5
- "rootDir": "./src",
6
- "outDir": "./lib"
7
- },
8
- "exclude": ["**/*.test.ts", "**/*.test.js", "tests", "lib"]
9
- }