@unchainedshop/platform 1.1.3

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 (196) hide show
  1. package/README.md +3 -0
  2. package/lib/bulk-importer/createBulkImporter.d.ts +4 -0
  3. package/lib/bulk-importer/createBulkImporter.js +102 -0
  4. package/lib/bulk-importer/createBulkImporter.js.map +1 -0
  5. package/lib/bulk-importer/handlers/assortment/create.d.ts +11 -0
  6. package/lib/bulk-importer/handlers/assortment/create.js +59 -0
  7. package/lib/bulk-importer/handlers/assortment/create.js.map +1 -0
  8. package/lib/bulk-importer/handlers/assortment/index.d.ts +3 -0
  9. package/lib/bulk-importer/handlers/assortment/index.js +4 -0
  10. package/lib/bulk-importer/handlers/assortment/index.js.map +1 -0
  11. package/lib/bulk-importer/handlers/assortment/remove.d.ts +9 -0
  12. package/lib/bulk-importer/handlers/assortment/remove.js +13 -0
  13. package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -0
  14. package/lib/bulk-importer/handlers/assortment/update.d.ts +10 -0
  15. package/lib/bulk-importer/handlers/assortment/update.js +61 -0
  16. package/lib/bulk-importer/handlers/assortment/update.js.map +1 -0
  17. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +7 -0
  18. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +30 -0
  19. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -0
  20. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.d.ts +7 -0
  21. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js +9 -0
  22. package/lib/bulk-importer/handlers/assortment/upsertAssortmentContent.js.map +1 -0
  23. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +7 -0
  24. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +29 -0
  25. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -0
  26. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +7 -0
  27. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +32 -0
  28. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -0
  29. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +7 -0
  30. package/lib/bulk-importer/handlers/assortment/upsertMedia.js +67 -0
  31. package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -0
  32. package/lib/bulk-importer/handlers/filter/create.d.ts +11 -0
  33. package/lib/bulk-importer/handlers/filter/create.js +42 -0
  34. package/lib/bulk-importer/handlers/filter/create.js.map +1 -0
  35. package/lib/bulk-importer/handlers/filter/index.d.ts +3 -0
  36. package/lib/bulk-importer/handlers/filter/index.js +4 -0
  37. package/lib/bulk-importer/handlers/filter/index.js.map +1 -0
  38. package/lib/bulk-importer/handlers/filter/remove.d.ts +9 -0
  39. package/lib/bulk-importer/handlers/filter/remove.js +14 -0
  40. package/lib/bulk-importer/handlers/filter/remove.js.map +1 -0
  41. package/lib/bulk-importer/handlers/filter/update.d.ts +10 -0
  42. package/lib/bulk-importer/handlers/filter/update.js +34 -0
  43. package/lib/bulk-importer/handlers/filter/update.js.map +1 -0
  44. package/lib/bulk-importer/handlers/filter/upsertFilterContent.d.ts +13 -0
  45. package/lib/bulk-importer/handlers/filter/upsertFilterContent.js +6 -0
  46. package/lib/bulk-importer/handlers/filter/upsertFilterContent.js.map +1 -0
  47. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.d.ts +5 -0
  48. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js +8 -0
  49. package/lib/bulk-importer/handlers/filter/upsertFilterOptionContent.js.map +1 -0
  50. package/lib/bulk-importer/handlers/product/create.d.ts +11 -0
  51. package/lib/bulk-importer/handlers/product/create.js +51 -0
  52. package/lib/bulk-importer/handlers/product/create.js.map +1 -0
  53. package/lib/bulk-importer/handlers/product/index.d.ts +3 -0
  54. package/lib/bulk-importer/handlers/product/index.js +4 -0
  55. package/lib/bulk-importer/handlers/product/index.js.map +1 -0
  56. package/lib/bulk-importer/handlers/product/remove.d.ts +9 -0
  57. package/lib/bulk-importer/handlers/product/remove.js +14 -0
  58. package/lib/bulk-importer/handlers/product/remove.js.map +1 -0
  59. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.d.ts +2 -0
  60. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js +13 -0
  61. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js.map +1 -0
  62. package/lib/bulk-importer/handlers/product/update.d.ts +10 -0
  63. package/lib/bulk-importer/handlers/product/update.js +48 -0
  64. package/lib/bulk-importer/handlers/product/update.js.map +1 -0
  65. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +6 -0
  66. package/lib/bulk-importer/handlers/product/upsertMedia.js +69 -0
  67. package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -0
  68. package/lib/bulk-importer/handlers/product/upsertProductContent.d.ts +6 -0
  69. package/lib/bulk-importer/handlers/product/upsertProductContent.js +9 -0
  70. package/lib/bulk-importer/handlers/product/upsertProductContent.js.map +1 -0
  71. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +6 -0
  72. package/lib/bulk-importer/handlers/product/upsertVariations.js +39 -0
  73. package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -0
  74. package/lib/context/index.d.ts +2 -0
  75. package/lib/context/index.js +3 -0
  76. package/lib/context/index.js.map +1 -0
  77. package/lib/context/setAccessToken.d.ts +3 -0
  78. package/lib/context/setAccessToken.js +10 -0
  79. package/lib/context/setAccessToken.js.map +1 -0
  80. package/lib/context/withAccessToken.d.ts +2 -0
  81. package/lib/context/withAccessToken.js +33 -0
  82. package/lib/context/withAccessToken.js.map +1 -0
  83. package/lib/migrations/createMigrationRunner.d.ts +14 -0
  84. package/lib/migrations/createMigrationRunner.js +49 -0
  85. package/lib/migrations/createMigrationRunner.js.map +1 -0
  86. package/lib/migrations/migrationRepository.d.ts +3 -0
  87. package/lib/migrations/migrationRepository.js +16 -0
  88. package/lib/migrations/migrationRepository.js.map +1 -0
  89. package/lib/migrations/runMigrations.d.ts +7 -0
  90. package/lib/migrations/runMigrations.js +47 -0
  91. package/lib/migrations/runMigrations.js.map +1 -0
  92. package/lib/platform-index.d.ts +2 -0
  93. package/lib/platform-index.js +3 -0
  94. package/lib/platform-index.js.map +1 -0
  95. package/lib/setup/generateEventTypeDefs.d.ts +1 -0
  96. package/lib/setup/generateEventTypeDefs.js +9 -0
  97. package/lib/setup/generateEventTypeDefs.js.map +1 -0
  98. package/lib/setup/generateRoleActionTypeDefs.d.ts +1 -0
  99. package/lib/setup/generateRoleActionTypeDefs.js +9 -0
  100. package/lib/setup/generateRoleActionTypeDefs.js.map +1 -0
  101. package/lib/setup/generateWorkTypeDefs.d.ts +1 -0
  102. package/lib/setup/generateWorkTypeDefs.js +11 -0
  103. package/lib/setup/generateWorkTypeDefs.js.map +1 -0
  104. package/lib/setup/setupAccounts.d.ts +2 -0
  105. package/lib/setup/setupAccounts.js +91 -0
  106. package/lib/setup/setupAccounts.js.map +1 -0
  107. package/lib/setup/setupAutoScheduling.d.ts +1 -0
  108. package/lib/setup/setupAutoScheduling.js +5 -0
  109. package/lib/setup/setupAutoScheduling.js.map +1 -0
  110. package/lib/setup/setupCarts.d.ts +3 -0
  111. package/lib/setup/setupCarts.js +14 -0
  112. package/lib/setup/setupCarts.js.map +1 -0
  113. package/lib/setup/setupTemplates.d.ts +1 -0
  114. package/lib/setup/setupTemplates.js +17 -0
  115. package/lib/setup/setupTemplates.js.map +1 -0
  116. package/lib/setup/setupWorkqueue.d.ts +6 -0
  117. package/lib/setup/setupWorkqueue.js +11 -0
  118. package/lib/setup/setupWorkqueue.js.map +1 -0
  119. package/lib/startPlatform.d.ts +8 -0
  120. package/lib/startPlatform.js +105 -0
  121. package/lib/startPlatform.js.map +1 -0
  122. package/lib/templates/resolveAccountActionTemplate.d.ts +2 -0
  123. package/lib/templates/resolveAccountActionTemplate.js +131 -0
  124. package/lib/templates/resolveAccountActionTemplate.js.map +1 -0
  125. package/lib/templates/resolveEnrollmentStatusTemplate.d.ts +2 -0
  126. package/lib/templates/resolveEnrollmentStatusTemplate.js +34 -0
  127. package/lib/templates/resolveEnrollmentStatusTemplate.js.map +1 -0
  128. package/lib/templates/resolveForwardDeliveryTemplate.d.ts +2 -0
  129. package/lib/templates/resolveForwardDeliveryTemplate.js +114 -0
  130. package/lib/templates/resolveForwardDeliveryTemplate.js.map +1 -0
  131. package/lib/templates/resolveOrderConfirmationTemplate.d.ts +2 -0
  132. package/lib/templates/resolveOrderConfirmationTemplate.js +111 -0
  133. package/lib/templates/resolveOrderConfirmationTemplate.js.map +1 -0
  134. package/lib/templates/resolveOrderRejectionTemplate.d.ts +2 -0
  135. package/lib/templates/resolveOrderRejectionTemplate.js +77 -0
  136. package/lib/templates/resolveOrderRejectionTemplate.js.map +1 -0
  137. package/lib/templates/resolveQuotationStatusTemplate.d.ts +2 -0
  138. package/lib/templates/resolveQuotationStatusTemplate.js +40 -0
  139. package/lib/templates/resolveQuotationStatusTemplate.js.map +1 -0
  140. package/lib/templates/utils/getOrderAttachmentsData.d.ts +8 -0
  141. package/lib/templates/utils/getOrderAttachmentsData.js +28 -0
  142. package/lib/templates/utils/getOrderAttachmentsData.js.map +1 -0
  143. package/lib/templates/utils/getOrderPositionsData.d.ts +6 -0
  144. package/lib/templates/utils/getOrderPositionsData.js +32 -0
  145. package/lib/templates/utils/getOrderPositionsData.js.map +1 -0
  146. package/package.json +58 -0
  147. package/src/bulk-importer/createBulkImporter.ts +120 -0
  148. package/src/bulk-importer/handlers/assortment/create.ts +86 -0
  149. package/src/bulk-importer/handlers/assortment/index.js +3 -0
  150. package/src/bulk-importer/handlers/assortment/remove.ts +15 -0
  151. package/src/bulk-importer/handlers/assortment/update.ts +85 -0
  152. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +51 -0
  153. package/src/bulk-importer/handlers/assortment/upsertAssortmentContent.ts +20 -0
  154. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +39 -0
  155. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +55 -0
  156. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +99 -0
  157. package/src/bulk-importer/handlers/filter/create.ts +62 -0
  158. package/src/bulk-importer/handlers/filter/index.js +3 -0
  159. package/src/bulk-importer/handlers/filter/remove.ts +16 -0
  160. package/src/bulk-importer/handlers/filter/update.ts +49 -0
  161. package/src/bulk-importer/handlers/filter/upsertFilterContent.ts +17 -0
  162. package/src/bulk-importer/handlers/filter/upsertFilterOptionContent.ts +21 -0
  163. package/src/bulk-importer/handlers/product/create.ts +73 -0
  164. package/src/bulk-importer/handlers/product/index.js +3 -0
  165. package/src/bulk-importer/handlers/product/remove.ts +17 -0
  166. package/src/bulk-importer/handlers/product/transformSpecificationToProductStructure.js +19 -0
  167. package/src/bulk-importer/handlers/product/update.ts +65 -0
  168. package/src/bulk-importer/handlers/product/upsertMedia.ts +97 -0
  169. package/src/bulk-importer/handlers/product/upsertProductContent.ts +23 -0
  170. package/src/bulk-importer/handlers/product/upsertVariations.ts +77 -0
  171. package/src/context/index.ts +2 -0
  172. package/src/context/setAccessToken.ts +15 -0
  173. package/src/context/withAccessToken.ts +34 -0
  174. package/src/migrations/createMigrationRunner.js +61 -0
  175. package/src/migrations/migrationRepository.ts +18 -0
  176. package/src/migrations/runMigrations.ts +64 -0
  177. package/src/platform-index.ts +2 -0
  178. package/src/setup/generateEventTypeDefs.js +9 -0
  179. package/src/setup/generateRoleActionTypeDefs.js +9 -0
  180. package/src/setup/generateWorkTypeDefs.js +11 -0
  181. package/src/setup/setupAccounts.ts +129 -0
  182. package/src/setup/setupAutoScheduling.ts +5 -0
  183. package/src/setup/setupCarts.ts +27 -0
  184. package/src/setup/setupTemplates.ts +17 -0
  185. package/src/setup/setupWorkqueue.ts +17 -0
  186. package/src/startPlatform.ts +145 -0
  187. package/src/templates/resolveAccountActionTemplate.ts +144 -0
  188. package/src/templates/resolveEnrollmentStatusTemplate.ts +43 -0
  189. package/src/templates/resolveForwardDeliveryTemplate.ts +128 -0
  190. package/src/templates/resolveOrderConfirmationTemplate.ts +133 -0
  191. package/src/templates/resolveOrderRejectionTemplate.ts +85 -0
  192. package/src/templates/resolveQuotationStatusTemplate.ts +54 -0
  193. package/src/templates/utils/getOrderAttachmentsData.ts +47 -0
  194. package/src/templates/utils/getOrderPositionsData.ts +49 -0
  195. package/tsconfig.build.json +26 -0
  196. package/tsconfig.json +8 -0
@@ -0,0 +1,131 @@
1
+ const { EMAIL_FROM, EMAIL_WEBSITE_URL, EMAIL_WEBSITE_NAME } = process.env;
2
+ const mjmlTemplate = `
3
+ <mjml>
4
+ <mj-body background-color="#FAFAFA">
5
+ <mj-section padding-bottom="32px" background-color="#fcfcfc">
6
+ <mj-column width="100%">
7
+ <mj-text align="center" font-size="20px" color="#232323" font-family="Helvetica Neue" font-weight="200">
8
+ <h2>{{subject}}</h2>
9
+ </mj-text>
10
+ <mj-text align="left" font-size="20px" color="#232323" font-family="Helvetica Neue" font-weight="200">
11
+ <span>{{message}}</span><br/>
12
+ </mj-text>
13
+ </mj-column>
14
+ </mj-section>
15
+
16
+ <mj-section padding-bottom="20px" background-color="#f3f3f3">
17
+ <mj-column>
18
+ <mj-button href="{{url}}" font-family="Helvetica" background-color="#31302E" color="white">
19
+ {{buttonText}}
20
+ </mj-button>
21
+ <mj-spacer/>
22
+ </mj-column>
23
+ </mj-section>
24
+ </mj-body>
25
+ </mjml>
26
+ `;
27
+ const verifyEmailEnglishConfig = {
28
+ buttonText: 'Verify email address',
29
+ message: 'We need to ensure that this email is yours as a commercial partner.',
30
+ subject: `${EMAIL_WEBSITE_NAME}: Verify your email address`,
31
+ };
32
+ const passwordChangedEmailEnglishConfig = {
33
+ message: `
34
+ Your account password has been successfully changed.\n
35
+ `,
36
+ subject: `${EMAIL_WEBSITE_NAME}: Your password has been changed`,
37
+ };
38
+ const textTemplate = `
39
+ {{message}}
40
+ {{#url}}
41
+ \n
42
+ -----------------\n
43
+ {{buttonText}}: {{url}}\n
44
+ -----------------\n
45
+ {{/url}}
46
+ `;
47
+ const emailConfig = {
48
+ 'enroll-account': {
49
+ url: (token) => `${EMAIL_WEBSITE_URL}/enroll-account?token=${token}`,
50
+ en: {
51
+ buttonText: 'Set password',
52
+ 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.`,
53
+ subject: `${EMAIL_WEBSITE_NAME}: You got a new account`,
54
+ },
55
+ de: {
56
+ buttonText: 'Passwort setzen',
57
+ message: `${EMAIL_WEBSITE_NAME} hat für dich ein Benutzerkonto angelegt. Bitte klicke unten um ein Passwort zu setzen und damit die Registrierung abzuschliessen.`,
58
+ subject: `${EMAIL_WEBSITE_NAME}: Für dich wurde ein Konto eingerichtet`,
59
+ },
60
+ fr: {
61
+ buttonText: 'Set password',
62
+ 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.`,
63
+ subject: `${EMAIL_WEBSITE_NAME}: You got a new account`,
64
+ },
65
+ },
66
+ 'reset-password': {
67
+ url: (token) => `${EMAIL_WEBSITE_URL}/reset-password?token=${token}`,
68
+ en: {
69
+ buttonText: 'Set new password',
70
+ message: `
71
+ Click on „Set new password". If you don’t want to set a new password, just ignore this email.\n
72
+ `,
73
+ subject: `${EMAIL_WEBSITE_NAME}: Set password`,
74
+ },
75
+ de: {
76
+ buttonText: 'Neues Passwort setzen',
77
+ message: `
78
+ Klicke auf „Neues Passwort setzen", um ein neues Passwort anzulegen.\n
79
+ Falls du dein Passwort nicht zurücksetzen möchtest, ignoriere dieses E-Mail einfach.\n
80
+ `,
81
+ subject: `${EMAIL_WEBSITE_NAME}: Passwort zurücksetzen`,
82
+ },
83
+ fr: {
84
+ buttonText: 'Set new password',
85
+ message: `
86
+ Click on „Set new password". If you don’t want to set a new password, just ignore this email.\n
87
+ `,
88
+ subject: `${EMAIL_WEBSITE_NAME}: Set password`,
89
+ },
90
+ },
91
+ 'verify-email': {
92
+ url: (token) => `${EMAIL_WEBSITE_URL}/verify-email?token=${token}`,
93
+ en: verifyEmailEnglishConfig,
94
+ de: verifyEmailEnglishConfig,
95
+ fr: verifyEmailEnglishConfig,
96
+ },
97
+ '': {
98
+ // password changed!
99
+ url: () => null,
100
+ en: passwordChangedEmailEnglishConfig,
101
+ de: passwordChangedEmailEnglishConfig,
102
+ fr: passwordChangedEmailEnglishConfig,
103
+ },
104
+ };
105
+ export const resolveAccountActionTemplate = async ({ userId, action, recipientEmail, token }, { modules }) => {
106
+ if (!token || !action)
107
+ return [];
108
+ const user = await modules.users.findUserById(userId);
109
+ const locale = modules.users.userLocale(user);
110
+ const { url } = emailConfig[action];
111
+ const { subject, message, buttonText } = emailConfig[action][locale.language];
112
+ const data = {
113
+ buttonText,
114
+ message,
115
+ subject,
116
+ url: url(token),
117
+ };
118
+ return [
119
+ {
120
+ type: 'EMAIL',
121
+ input: {
122
+ from: EMAIL_FROM || 'noreply@unchained.local',
123
+ to: recipientEmail || modules.users.primaryEmail(user)?.address,
124
+ subject,
125
+ text: modules.messaging.renderToText(textTemplate, data),
126
+ html: modules.messaging.renderMjmlToHtml(mjmlTemplate, data),
127
+ },
128
+ },
129
+ ];
130
+ };
131
+ //# sourceMappingURL=resolveAccountActionTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveAccountActionTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveAccountActionTemplate.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE1E,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwBpB,CAAC;AAEF,MAAM,wBAAwB,GAAG;IAC/B,UAAU,EAAE,sBAAsB;IAClC,OAAO,EAAE,qEAAqE;IAC9E,OAAO,EAAE,GAAG,kBAAkB,6BAA6B;CAC5D,CAA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AS,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC;aAC7D;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { TemplateResolver } from '@unchainedshop/types/messaging';
2
+ export declare const resolveEnrollmentStatusTemplate: TemplateResolver;
@@ -0,0 +1,34 @@
1
+ const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
2
+ const textTemplate = `
3
+ {{subject}}\n
4
+ \n
5
+ Status: {{enrollment.status}}
6
+ \n
7
+ -----------------\n
8
+ Show: {{url}}\n
9
+ -----------------\n
10
+ `;
11
+ export const resolveEnrollmentStatusTemplate = async ({ enrollmentId, locale }, context) => {
12
+ const { modules } = context;
13
+ const enrollment = await modules.enrollments.findEnrollment({ enrollmentId });
14
+ const user = await modules.users.findUserById(enrollment.userId);
15
+ const subject = `${EMAIL_WEBSITE_NAME}: Updated Enrollment / ${enrollment.enrollmentNumber}`;
16
+ const data = {
17
+ enrollment,
18
+ locale,
19
+ subject,
20
+ url: `${EMAIL_WEBSITE_URL}/enrollment?_id=${enrollment._id}`,
21
+ };
22
+ return [
23
+ {
24
+ type: 'EMAIL',
25
+ input: {
26
+ from: EMAIL_FROM || 'noreply@unchained.local',
27
+ to: modules.users.primaryEmail(user)?.address,
28
+ subject,
29
+ text: modules.messaging.renderToText(textTemplate, data),
30
+ },
31
+ },
32
+ ];
33
+ };
34
+ //# sourceMappingURL=resolveEnrollmentStatusTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveEnrollmentStatusTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveEnrollmentStatusTemplate.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE1E,MAAM,YAAY,GAAG;;;;;;;;CAQpB,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAqB,KAAK,EACpE,EAAE,YAAY,EAAE,MAAM,EAAE,EACxB,OAAO,EACP,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAEjE,MAAM,OAAO,GAAG,GAAG,kBAAkB,0BAA0B,UAAU,CAAC,gBAAgB,EAAE,CAAC;IAE7F,MAAM,IAAI,GAAG;QACX,UAAU;QACV,MAAM;QACN,OAAO;QACP,GAAG,EAAE,GAAG,iBAAiB,mBAAmB,UAAU,CAAC,GAAG,EAAE;KAC7D,CAAC;IAEF,OAAO;QACL;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU,IAAI,yBAAyB;gBAC7C,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO;gBAC7C,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC;aACzD;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { TemplateResolver } from '@unchainedshop/types/messaging';
2
+ export declare const resolveForwardDeliveryTemplate: TemplateResolver;
@@ -0,0 +1,114 @@
1
+ import moment from 'moment';
2
+ import { systemLocale } from '@unchainedshop/utils';
3
+ import { getOrderAttachmentsData } from './utils/getOrderAttachmentsData';
4
+ import { getOrderPositionsData } from './utils/getOrderPositionsData';
5
+ const { EMAIL_FROM, EMAIL_WEBSITE_NAME, ROOT_URL } = process.env;
6
+ const mjmlTemplate = `
7
+ <mjml>
8
+ <mj-body background-color="#FAFAFA">
9
+ <mj-section padding-bottom="32px" background-color="#fcfcfc">
10
+ <mj-column width="100%">
11
+ <mj-text align="center" font-size="20px" color="#232323" font-family="Helvetica Neue" font-weight="200">
12
+ <h2 >{{subject}}</h2>
13
+ </mj-text>
14
+ <mj-text align="left" font-size="20px" color="#232323" font-family="Helvetica Neue" font-weight="200">
15
+ <span>Order number: {{orderNumber}}</span><br/>
16
+ <span>Order date: {{orderDate}}</span>
17
+ <a href="{{controlpanelLink}}">{{controlpanelLink}}</a>
18
+ </mj-text>
19
+ <mj-text align="left" font-size="20px" color="#232323">Delivery address</mj-text>
20
+ <mj-text align="left">
21
+ {{address.firstName}} {{address.lastName}}<br/>
22
+ {{address.company}}<br/>
23
+ {{address.addressLine}}<br/>
24
+ {{address.addressLine2}}<br/>
25
+ {{address.postalCode}} {{address.city}} {{address.regionCode}}<br/>
26
+ {{address.countryCode}}<br/>
27
+ </mj-text>
28
+ <mj-divider border-width="1px" border-style="dashed" border-color="lightgrey" />
29
+ <mj-text align="left" font-size="20px" color="#232323">Articles</mj-text>
30
+ <mj-table>
31
+ <tr style="border-bottom:1px solid #ecedee;text-align:left;padding:15px 0;">
32
+ <th style="padding: 0 15px 0 0;">Article</th>
33
+ <th style="padding: 0 15px;">Quantity</th>
34
+ </tr>
35
+ {{#items}}
36
+ <tr>
37
+ <td style="padding: 0 15px 0 0;">{{sku}} - {{name}}</td>
38
+ <td style="padding: 0 15px;">{{quantity}}</td>
39
+ </tr>
40
+ {{/items}}
41
+ </mj-table>
42
+ </mj-column>
43
+ </mj-section>
44
+ </mj-body>
45
+ </mjml>
46
+ `;
47
+ const textTemplate = `
48
+ {{subject}}\n
49
+ \n
50
+ Order number: {{orderNumber}}\n
51
+ Order date: {{orderDate}}\n
52
+ Link: {{controlpanelLink}}\n
53
+ \n
54
+ Delivery address:\n
55
+ -----------------\n
56
+ {{address.firstName}} {{address.lastName}}\n
57
+ {{address.company}}\n
58
+ {{address.addressLine}}\n
59
+ {{address.addressLine2}}\n
60
+ {{address.postalCode}} {{address.city}}\n
61
+ {{address.regionCode}}\n
62
+ {{address.countryCode}}\n
63
+ \n
64
+ Articles:\n
65
+ -----------------\n
66
+ {{#items}}
67
+ * {{sku}} - {{name}} CHF {{price}} {{quantity}}\n
68
+ {{/items}}
69
+ `;
70
+ export const resolveForwardDeliveryTemplate = async ({ config, orderId, transactionContext }, context) => {
71
+ const { modules } = context;
72
+ const order = await modules.orders.findOrder({ orderId });
73
+ const orderPricing = modules.orders.pricingSheet(order);
74
+ const momentDate = moment(order.ordered);
75
+ momentDate.locale(systemLocale.normalized);
76
+ const orderDate = momentDate.format('lll');
77
+ const attachments = await getOrderAttachmentsData(order, { fileType: 'DELIVERY_NOTE' }, context);
78
+ const address = transactionContext?.address || order.billingAddress;
79
+ const configObject = config.reduce((acc, { key, value }) => {
80
+ return {
81
+ ...acc,
82
+ [key]: value,
83
+ };
84
+ }, {});
85
+ const subject = `${EMAIL_WEBSITE_NAME}: New Order / ${order.orderNumber}`;
86
+ const controlpanelLink = `${ROOT_URL}/orders/view/?_id=${order._id}`;
87
+ const data = {
88
+ contact: order.contact || {},
89
+ controlpanelLink,
90
+ items: getOrderPositionsData(order, { locale: systemLocale }, context),
91
+ orderDate,
92
+ orderNumber: order.orderNumber,
93
+ shopName: EMAIL_WEBSITE_NAME,
94
+ subject,
95
+ total: orderPricing.total({ useNetPrice: false }).amount / 100,
96
+ ...configObject,
97
+ address,
98
+ };
99
+ return [
100
+ {
101
+ type: 'EMAIL',
102
+ input: {
103
+ from: configObject.from || EMAIL_FROM || 'noreply@unchained.local',
104
+ to: configObject.to || 'orders@unchained.local',
105
+ cc: configObject.cc,
106
+ subject,
107
+ text: modules.messaging.renderToText(textTemplate, data),
108
+ html: modules.messaging.renderMjmlToHtml(mjmlTemplate, data),
109
+ attachments,
110
+ },
111
+ },
112
+ ];
113
+ };
114
+ //# sourceMappingURL=resolveForwardDeliveryTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveForwardDeliveryTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveForward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/messaging';
2
+ export declare const resolveOrderConfirmationTemplate: TemplateResolver;
@@ -0,0 +1,111 @@
1
+ import { OrderPricingRowCategory } from '@unchainedshop/types/orders.pricing';
2
+ import { getOrderAttachmentsData } from './utils/getOrderAttachmentsData';
3
+ import { getOrderPositionsData } from './utils/getOrderPositionsData';
4
+ const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
5
+ const mjmlTemplate = `
6
+ <mjml>
7
+ <mj-body background-color="#FAFAFA">
8
+ <mj-section padding-bottom="32px" background-color="#FFFFFF">
9
+ <mj-column width="100%">
10
+ <mj-text font-size="20px" color="#232323" font-family="Helvetica Neue" font-weight="400">
11
+ <h2>{{subject}}</h2>
12
+ </mj-text>
13
+ <mj-text font-size="20px" color="#232323" font-family="Helvetica Neue">
14
+ <p>{{thankyou}} <a style="color:#2CAADF" href="{{shopUrl}}">{{shopName}}</a></p>
15
+ </mj-text>
16
+ </mj-column>
17
+ </mj-section>
18
+
19
+ <mj-section padding-bottom="20px" background-color="#F3F3F3">
20
+ <mj-column>
21
+ <mj-button href="{{url}}" font-family="Helvetica" background-color="#31302E" color="#FFFFFF">
22
+ {{buttonText}}
23
+ </mj-button>
24
+ </mj-column>
25
+ </mj-section>
26
+ </mj-body>
27
+ </mjml>
28
+ `;
29
+ const textTemplate = `
30
+ {{subject}}\n
31
+ \n
32
+ {{thankyou}}\n
33
+ \n
34
+ -----------------\n
35
+ {{buttonText}}: {{url}}\n
36
+ -----------------\n
37
+ `;
38
+ const texts = {
39
+ en: {
40
+ buttonText: 'Follow purchase order status',
41
+ thankyou: 'Thank you for your order on',
42
+ subject: `${EMAIL_WEBSITE_NAME}: Order confirmation`,
43
+ },
44
+ de: {
45
+ buttonText: 'Bestellstatus verfolgen',
46
+ thankyou: 'Vielen Dank für deine Bestellung bei',
47
+ subject: `${EMAIL_WEBSITE_NAME}: Bestellbestätigung`,
48
+ },
49
+ fr: {
50
+ buttonText: 'Follow purchase order status',
51
+ thankyou: 'Thank you for your order on',
52
+ subject: `${EMAIL_WEBSITE_NAME}: Order confirmation`,
53
+ },
54
+ };
55
+ export const resolveOrderConfirmationTemplate = async ({ orderId, locale }, context) => {
56
+ const { modules } = context;
57
+ const order = await modules.orders.findOrder({ orderId });
58
+ if (order.status === 'PENDING') {
59
+ return [];
60
+ }
61
+ const formatPrice = (price) => {
62
+ const fixedPrice = price / 100;
63
+ return `${order.currency} ${fixedPrice}`;
64
+ };
65
+ // TODO: If order.status is PENDING, we should only send the user
66
+ // a notice that we have received the order but not confirming it
67
+ const attachments = await getOrderAttachmentsData(order, { fileType: 'ORDER_CONFIRMATION' }, context);
68
+ const orderPricing = modules.orders.pricingSheet(order);
69
+ const { subject } = texts[locale.language];
70
+ const data = {
71
+ ...texts[locale.language],
72
+ shopName: EMAIL_WEBSITE_NAME,
73
+ shopUrl: EMAIL_WEBSITE_URL,
74
+ subject,
75
+ url: `${EMAIL_WEBSITE_URL}/order?_id=${order._id}`,
76
+ summary: {
77
+ items: formatPrice(orderPricing.total({
78
+ category: OrderPricingRowCategory.Items,
79
+ useNetPrice: false,
80
+ }).amount),
81
+ taxes: formatPrice(orderPricing.total({
82
+ category: OrderPricingRowCategory.Taxes,
83
+ useNetPrice: false,
84
+ }).amount),
85
+ delivery: formatPrice(orderPricing.total({
86
+ category: OrderPricingRowCategory.Delivery,
87
+ useNetPrice: false,
88
+ }).amount),
89
+ payment: formatPrice(orderPricing.total({
90
+ category: OrderPricingRowCategory.Payment,
91
+ useNetPrice: false,
92
+ }).amount),
93
+ gross: formatPrice(orderPricing.total({ useNetPrice: false }).amount),
94
+ },
95
+ positions: getOrderPositionsData(order, { locale }, context),
96
+ };
97
+ return [
98
+ {
99
+ type: 'EMAIL',
100
+ input: {
101
+ from: EMAIL_FROM || 'orders@unchained.local',
102
+ to: order.contact.emailAddress,
103
+ subject,
104
+ text: modules.messaging.renderToText(textTemplate, data),
105
+ html: modules.messaging.renderMjmlToHtml(mjmlTemplate, data),
106
+ attachments,
107
+ },
108
+ },
109
+ ];
110
+ };
111
+ //# sourceMappingURL=resolveOrderConfirmationTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveOrderConfirmationTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveOrderConfirmationTemplate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE1E,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBpB,CAAC;AAEF,MAAM,YAAY,GAAG;;;;;;;;CAQpB,CAAC;AAEF,MAAM,KAAK,GAAG;IACZ,EAAE,EAAE;QACF,UAAU,EAAE,8BAA8B;QAC1C,QAAQ,EAAE,6BAA6B;QACvC,OAAO,EAAE,GAAG,kBAAkB,sBAAsB;KACrD;IACD,EAAE,EAAE;QACF,UAAU,EAAE,yBAAyB;QACrC,QAAQ,EAAE,sCAAsC;QAChD,OAAO,EAAE,GAAG,kBAAkB,sBAAsB;KACrD;IACD,EAAE,EAAE;QACF,UAAU,EAAE,8BAA8B;QAC1C,QAAQ,EAAE,6BAA6B;QACvC,OAAO,EAAE,GAAG,kBAAkB,sBAAsB;KACrD;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAqB,KAAK,EACrE,EAAE,OAAO,EAAE,MAAM,EAAE,EACnB,OAAO,EACP,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAE1D,IAAI,KAAK,CAAC,MAAM,KAAK,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AAK,CAAC;gBACjB,QAAQ,EAAE,uBAAuB,CAAC,OAAO;gBACzC,WAAW,EAAE,KAAK;aACnB,CAAC,CAAC,MAAM,CACV;YACD,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;SACtE;QACD,SAAS,EAAE,qBAAqB,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC;KAC7D,CAAC;IACF,OAAO;QACL;YACE,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU,IAAI,wBAAwB;gBAC5C,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,YAAY;gBAC9B,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC;gBACxD,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC;gBAC5D,WAAW;aACZ;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { TemplateResolver } from '@unchainedshop/types/messaging';
2
+ export declare const resolveOrderRejectionTemplate: TemplateResolver;
@@ -0,0 +1,77 @@
1
+ const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
2
+ const mjmlTemplate = `
3
+ <mjml>
4
+ <mj-body background-color="#FAFAFA">
5
+ <mj-section padding-bottom="32px" background-color="#FFFFFF">
6
+ <mj-column width="100%">
7
+ <mj-text font-size="20px" color="#232323" font-family="Helvetica Neue" font-weight="400">
8
+ <h2>{{subject}}</h2>
9
+ </mj-text>
10
+ <mj-text font-size="20px" color="#232323" font-family="Helvetica Neue">
11
+ <p>{{rejection}}</p>
12
+ </mj-text>
13
+ </mj-column>
14
+ </mj-section>
15
+
16
+ <mj-section padding-bottom="20px" background-color="#F3F3F3">
17
+ <mj-column>
18
+ <mj-button href="{{url}}" font-family="Helvetica" background-color="#31302E" color="#FFFFFF">
19
+ {{buttonText}}
20
+ </mj-button>
21
+ </mj-column>
22
+ </mj-section>
23
+ </mj-body>
24
+ </mjml>
25
+ `;
26
+ const textTemplate = `
27
+ {{subject}}\n
28
+ \n
29
+ {{rejection}}\n
30
+ \n
31
+ -----------------\n
32
+ {{buttonText}}: {{url}}\n
33
+ -----------------\n
34
+ `;
35
+ const texts = {
36
+ en: {
37
+ buttonText: 'Details are available at',
38
+ rejection: 'Your order was cancelled.',
39
+ subject: `${EMAIL_WEBSITE_NAME}: Order cancelled`,
40
+ },
41
+ de: {
42
+ buttonText: 'Details abrufen',
43
+ rejection: 'Deine Bestellung wurde storniert',
44
+ subject: `${EMAIL_WEBSITE_NAME}: Bestellung storniert`,
45
+ },
46
+ fr: {
47
+ buttonText: 'Details are available at',
48
+ rejection: 'Your order was cancelled.',
49
+ subject: `${EMAIL_WEBSITE_NAME}: Order cancelled`,
50
+ },
51
+ };
52
+ export const resolveOrderRejectionTemplate = async ({ orderId, locale }, context) => {
53
+ const { modules } = context;
54
+ const order = await modules.orders.findOrder({ orderId });
55
+ if (order.status !== 'REJECTED') {
56
+ return [];
57
+ }
58
+ const { subject } = texts[locale.language];
59
+ const data = {
60
+ ...texts[locale.language],
61
+ subject,
62
+ url: `${EMAIL_WEBSITE_URL}/order?_id=${order._id}`,
63
+ };
64
+ return [
65
+ {
66
+ type: 'EMAIL',
67
+ input: {
68
+ from: EMAIL_FROM || 'orders@unchained.local',
69
+ to: order.contact.emailAddress,
70
+ subject,
71
+ text: modules.messaging.renderToText(textTemplate, data),
72
+ html: modules.messaging.renderMjmlToHtml(mjmlTemplate, data),
73
+ },
74
+ },
75
+ ];
76
+ };
77
+ //# sourceMappingURL=resolveOrderRejectionTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveOrderRejectionTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveOrderRejectionTemplate.ts"],"names":[],"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,UAAU,IAAI,wBAAwB;gBAC5C,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,YAAY;gBAC9B,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC;gBACxD,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC;aAC7D;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { TemplateResolver } from '@unchainedshop/types/messaging';
2
+ export declare const resolveQuotationStatusTemplate: TemplateResolver;
@@ -0,0 +1,40 @@
1
+ const { EMAIL_FROM, EMAIL_WEBSITE_NAME, EMAIL_WEBSITE_URL } = process.env;
2
+ const textTemplate = `
3
+ {{subject}}\n
4
+ \n
5
+ Status: {{quotation.status}}
6
+ \n
7
+ -----------------\n
8
+ Show: {{url}}\n
9
+ -----------------\n
10
+ `;
11
+ export const resolveQuotationStatusTemplate = async ({ quotationId, locale }, { modules }) => {
12
+ const quotation = await modules.quotations.findQuotation({ quotationId });
13
+ const user = await modules.users.findUserById(quotation.userId);
14
+ const attachments = (await modules.files.findFilesByMetaData({ meta: { quotationId: quotation._id, type: 'PROPOSAL ' } }, { sort: { 'meta.date': -1 } }))
15
+ .filter(Boolean)
16
+ .map((file) => ({
17
+ filename: `${quotation.quotationNumber}_${file.name}`,
18
+ path: file.url,
19
+ }));
20
+ const subject = `${EMAIL_WEBSITE_NAME}: Updated Quotation / ${quotation.quotationNumber}`;
21
+ const data = {
22
+ locale,
23
+ quotation,
24
+ subject,
25
+ url: `${EMAIL_WEBSITE_URL}/quotation?_id=${quotation._id}`,
26
+ };
27
+ return [
28
+ {
29
+ type: 'EMAIL',
30
+ input: {
31
+ from: EMAIL_FROM,
32
+ to: modules.users.primaryEmail(user)?.address,
33
+ subject,
34
+ text: modules.messaging.renderToText(textTemplate, data),
35
+ attachments,
36
+ },
37
+ },
38
+ ];
39
+ };
40
+ //# sourceMappingURL=resolveQuotationStatusTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveQuotationStatusTemplate.js","sourceRoot":"","sources":["../../src/templates/resolveQuotationStatusTemplate.ts"],"names":[],"mappings":"AAEA,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE1E,MAAM,YAAY,GAAG;;;;;;;;CAQpB,CAAC;AAEF,MAAM,CAAC,MAAM,8BAA8B,GAAqB,KAAK,EACnE,EAAE,WAAW,EAAE,MAAM,EAAE,EACvB,EAAE,OAAO,EAAE,EACX,EAAE;IACF,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,CAClB,MAAM,OAAO,CAAC,KAAK,CAAC,mBAAmB,CACrC,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAC3D,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAC9B,CACF;SACE,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACd,QAAQ,EAAE,GAAG,SAAS,CAAC,eAAe,IAAI,IAAI,CAAC,IAAI,EAAE;QACrD,IAAI,EAAE,IAAI,CAAC,GAAG;KACf,CAAC,CAAC,CAAC;IAEN,MAAM,OAAO,GAAG,GAAG,kBAAkB,yBAAyB,SAAS,CAAC,eAAe,EAAE,CAAC;IAE1F,MAAM,IAAI,GAAG;QACX,MAAM;QACN,SAAS;QACT,OAAO;QACP,GAAG,EAAE,GAAG,iBAAiB,kBAAkB,SAAS,CAAC,GAAG,EAAE;KAC3D,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,EAAE,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC;gBACxD,WAAW;aACZ;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Context } from '@unchainedshop/types/api';
2
+ import { Order } from '@unchainedshop/types/orders';
3
+ export declare const getOrderAttachmentsData: (order: Order, params: {
4
+ fileType: string;
5
+ }, { modules }: Context) => Promise<{
6
+ filename: string;
7
+ path: any;
8
+ }[]>;
@@ -0,0 +1,28 @@
1
+ export const getOrderAttachmentsData = async (order, params, { modules }) => {
2
+ const orderId = order._id;
3
+ const attachments = [];
4
+ const orderFiles = await modules.files.findFilesByMetaData({
5
+ meta: { orderId: order._id, type: params.fileType },
6
+ }, { limit: 1 });
7
+ attachments.concat(orderFiles);
8
+ const payment = await modules.orders.payments.findOrderPayment({
9
+ orderPaymentId: order.paymentId,
10
+ }, { limit: 1 });
11
+ if (modules.orders.payments.isBlockingOrderFullfillment(payment)) {
12
+ const invoices = await modules.files.findFilesByMetaData({
13
+ meta: { orderId, type: 'INVOICE' },
14
+ }, { limit: 1 });
15
+ attachments.concat(invoices);
16
+ }
17
+ else {
18
+ const receipts = await modules.files.findFilesByMetaData({
19
+ meta: { orderId, type: 'RECEIPT' },
20
+ }, { limit: 1 });
21
+ attachments.concat(receipts);
22
+ }
23
+ return attachments.map((file) => ({
24
+ filename: `${order.orderNumber}_${file.name}`,
25
+ path: file.path,
26
+ }));
27
+ };
28
+ //# sourceMappingURL=getOrderAttachmentsData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getOrderAttachmentsData.js","sourceR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C;KAC9B;IAED,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAChC,QAAQ,EAAE,GAAG,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE;QAC7C,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Context } from '@unchainedshop/types/api';
2
+ import { Locale } from '@unchainedshop/types/common';
3
+ import { Order } from '@unchainedshop/types/orders';
4
+ export declare const getOrderPositionsData: (order: Order, params: {
5
+ locale?: Locale;
6
+ }, context: Context) => Promise<void>;
@@ -0,0 +1,32 @@
1
+ export const getOrderPositionsData = async (order, params, context) => {
2
+ const { modules } = context;
3
+ const orderPositions = await modules.orders.positions.findOrderPositions({
4
+ orderId: order._id,
5
+ });
6
+ const formatPrice = (price) => {
7
+ const fixedPrice = price / 100;
8
+ return `${order.currency} ${fixedPrice}`;
9
+ };
10
+ await Promise.all(orderPositions.map(async (orderPosition) => {
11
+ const productTexts = await modules.products.texts.findLocalizedText({
12
+ productId: orderPosition.productId,
13
+ locale: params.locale?.normalized,
14
+ });
15
+ const originalProductTexts = await modules.products.texts.findLocalizedText({
16
+ productId: orderPosition.originalProductId,
17
+ locale: params.locale?.normalized,
18
+ });
19
+ const productTitle = productTexts?.title; // deprecated
20
+ const positionPricing = modules.orders.positions.pricingSheet(orderPosition, order.currency, context);
21
+ const total = formatPrice(positionPricing.sum());
22
+ const { quantity } = positionPricing;
23
+ return {
24
+ originalProductTexts,
25
+ product: productTitle,
26
+ productTexts,
27
+ quantity,
28
+ total,
29
+ };
30
+ }));
31
+ };
32
+ //# sourceMappingURL=getOrderPositionsData.js.map