@teleporthq/teleport-plugin-next-workflows 0.43.65 → 0.43.67

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 (305) hide show
  1. package/__tests__/_helpers/bind-workflow-utils.ts +30 -0
  2. package/__tests__/_helpers/run-generated-middleware.ts +11 -2
  3. package/__tests__/admin-form-row-hydration.test.ts +55 -0
  4. package/__tests__/cart-clear-db-mirror.test.ts +12 -0
  5. package/__tests__/cart-get-total-regional-pricing.test.ts +166 -0
  6. package/__tests__/client-config-redaction.test.ts +53 -0
  7. package/__tests__/continue-on-error.test.ts +119 -0
  8. package/__tests__/email-locale-module.test.ts +323 -0
  9. package/__tests__/email-locale-senders.test.ts +268 -0
  10. package/__tests__/invoice-delivery-fee.test.ts +104 -0
  11. package/__tests__/invoice-regional-tax.test.ts +126 -0
  12. package/__tests__/locale-aware-redirects.test.ts +355 -0
  13. package/__tests__/navigation-go-to-page.test.ts +43 -0
  14. package/__tests__/node-handler-file-inline-map.test.ts +29 -3
  15. package/__tests__/payment-redirect-and-order-notification.test.ts +6 -0
  16. package/__tests__/paypal-webhook-order-notification.test.ts +41 -0
  17. package/__tests__/resolve-config-localized-templates.test.ts +262 -0
  18. package/__tests__/sent-email-log-module.test.ts +381 -0
  19. package/__tests__/sent-email-log-wiring.test.ts +267 -0
  20. package/dist/cjs/account-delete-route-generator.d.ts +20 -0
  21. package/dist/cjs/account-delete-route-generator.d.ts.map +1 -1
  22. package/dist/cjs/account-delete-route-generator.js +29 -26
  23. package/dist/cjs/account-delete-route-generator.js.map +1 -1
  24. package/dist/cjs/api-route-generator.d.ts.map +1 -1
  25. package/dist/cjs/api-route-generator.js +57 -11
  26. package/dist/cjs/api-route-generator.js.map +1 -1
  27. package/dist/cjs/auth-generator.d.ts +2 -1
  28. package/dist/cjs/auth-generator.d.ts.map +1 -1
  29. package/dist/cjs/auth-generator.js +55 -18
  30. package/dist/cjs/auth-generator.js.map +1 -1
  31. package/dist/cjs/data-api-route-generator.d.ts.map +1 -1
  32. package/dist/cjs/data-api-route-generator.js +19 -0
  33. package/dist/cjs/data-api-route-generator.js.map +1 -1
  34. package/dist/cjs/email-locale/email-locale-code.d.ts +25 -0
  35. package/dist/cjs/email-locale/email-locale-code.d.ts.map +1 -0
  36. package/dist/cjs/email-locale/email-locale-code.js +228 -0
  37. package/dist/cjs/email-locale/email-locale-code.js.map +1 -0
  38. package/dist/cjs/email-locale/email-locale-scope.d.ts +46 -0
  39. package/dist/cjs/email-locale/email-locale-scope.d.ts.map +1 -0
  40. package/dist/cjs/email-locale/email-locale-scope.js +51 -0
  41. package/dist/cjs/email-locale/email-locale-scope.js.map +1 -0
  42. package/dist/cjs/email-locale/index.d.ts +11 -0
  43. package/dist/cjs/email-locale/index.d.ts.map +1 -0
  44. package/dist/cjs/email-locale/index.js +40 -0
  45. package/dist/cjs/email-locale/index.js.map +1 -0
  46. package/dist/cjs/executor-generator.d.ts +11 -1
  47. package/dist/cjs/executor-generator.d.ts.map +1 -1
  48. package/dist/cjs/executor-generator.js +49 -7
  49. package/dist/cjs/executor-generator.js.map +1 -1
  50. package/dist/cjs/index.d.ts +2 -0
  51. package/dist/cjs/index.d.ts.map +1 -1
  52. package/dist/cjs/index.js +9 -1
  53. package/dist/cjs/index.js.map +1 -1
  54. package/dist/cjs/invoice/api-routes-code.d.ts.map +1 -1
  55. package/dist/cjs/invoice/api-routes-code.js +55 -6
  56. package/dist/cjs/invoice/api-routes-code.js.map +1 -1
  57. package/dist/cjs/invoice/email-sender-code.d.ts.map +1 -1
  58. package/dist/cjs/invoice/email-sender-code.js +72 -31
  59. package/dist/cjs/invoice/email-sender-code.js.map +1 -1
  60. package/dist/cjs/invoice/index.d.ts +1 -4
  61. package/dist/cjs/invoice/index.d.ts.map +1 -1
  62. package/dist/cjs/invoice/index.js +8 -19
  63. package/dist/cjs/invoice/index.js.map +1 -1
  64. package/dist/cjs/invoice/invoice-html-code.d.ts.map +1 -1
  65. package/dist/cjs/invoice/invoice-html-code.js +31 -8
  66. package/dist/cjs/invoice/invoice-html-code.js.map +1 -1
  67. package/dist/cjs/invoice/regional-invoice-tax-code.d.ts +25 -0
  68. package/dist/cjs/invoice/regional-invoice-tax-code.d.ts.map +1 -0
  69. package/dist/cjs/invoice/regional-invoice-tax-code.js +116 -0
  70. package/dist/cjs/invoice/regional-invoice-tax-code.js.map +1 -0
  71. package/dist/cjs/invoice/resolve-data-source.d.ts +6 -0
  72. package/dist/cjs/invoice/resolve-data-source.d.ts.map +1 -0
  73. package/dist/cjs/invoice/resolve-data-source.js +23 -0
  74. package/dist/cjs/invoice/resolve-data-source.js.map +1 -0
  75. package/dist/cjs/nodes/account/account-delete-current.d.ts.map +1 -1
  76. package/dist/cjs/nodes/account/account-delete-current.js +10 -3
  77. package/dist/cjs/nodes/account/account-delete-current.js.map +1 -1
  78. package/dist/cjs/nodes/account/account-login.d.ts.map +1 -1
  79. package/dist/cjs/nodes/account/account-login.js +3 -1
  80. package/dist/cjs/nodes/account/account-login.js.map +1 -1
  81. package/dist/cjs/nodes/account/account-logout.d.ts.map +1 -1
  82. package/dist/cjs/nodes/account/account-logout.js +4 -2
  83. package/dist/cjs/nodes/account/account-logout.js.map +1 -1
  84. package/dist/cjs/nodes/account/account-signup.d.ts.map +1 -1
  85. package/dist/cjs/nodes/account/account-signup.js +12 -2
  86. package/dist/cjs/nodes/account/account-signup.js.map +1 -1
  87. package/dist/cjs/nodes/account/account-social-login.d.ts.map +1 -1
  88. package/dist/cjs/nodes/account/account-social-login.js +4 -2
  89. package/dist/cjs/nodes/account/account-social-login.js.map +1 -1
  90. package/dist/cjs/nodes/cart/cart-clear.d.ts.map +1 -1
  91. package/dist/cjs/nodes/cart/cart-clear.js +6 -0
  92. package/dist/cjs/nodes/cart/cart-clear.js.map +1 -1
  93. package/dist/cjs/nodes/cart/cart-get-total.d.ts.map +1 -1
  94. package/dist/cjs/nodes/cart/cart-get-total.js +81 -5
  95. package/dist/cjs/nodes/cart/cart-get-total.js.map +1 -1
  96. package/dist/cjs/nodes/data/data-create-item.d.ts.map +1 -1
  97. package/dist/cjs/nodes/data/data-create-item.js +16 -0
  98. package/dist/cjs/nodes/data/data-create-item.js.map +1 -1
  99. package/dist/cjs/nodes/ecommerce/ecommerce-generate-invoice.d.ts.map +1 -1
  100. package/dist/cjs/nodes/ecommerce/ecommerce-generate-invoice.js +6 -0
  101. package/dist/cjs/nodes/ecommerce/ecommerce-generate-invoice.js.map +1 -1
  102. package/dist/cjs/nodes/navigation/navigation-go-to-page.d.ts.map +1 -1
  103. package/dist/cjs/nodes/navigation/navigation-go-to-page.js +4 -1
  104. package/dist/cjs/nodes/navigation/navigation-go-to-page.js.map +1 -1
  105. package/dist/cjs/nodes/navigation/navigation-navigate-to-url.d.ts.map +1 -1
  106. package/dist/cjs/nodes/navigation/navigation-navigate-to-url.js +5 -2
  107. package/dist/cjs/nodes/navigation/navigation-navigate-to-url.js.map +1 -1
  108. package/dist/cjs/nodes/payment/payment-charge-user.d.ts.map +1 -1
  109. package/dist/cjs/nodes/payment/payment-charge-user.js +7 -2
  110. package/dist/cjs/nodes/payment/payment-charge-user.js.map +1 -1
  111. package/dist/cjs/segment-splitter.d.ts +1 -1
  112. package/dist/cjs/segment-splitter.d.ts.map +1 -1
  113. package/dist/cjs/segment-splitter.js +29 -2
  114. package/dist/cjs/segment-splitter.js.map +1 -1
  115. package/dist/cjs/sent-email-log/index.d.ts +16 -0
  116. package/dist/cjs/sent-email-log/index.d.ts.map +1 -0
  117. package/dist/cjs/sent-email-log/index.js +53 -0
  118. package/dist/cjs/sent-email-log/index.js.map +1 -0
  119. package/dist/cjs/sent-email-log/sent-email-log-code.d.ts +4 -0
  120. package/dist/cjs/sent-email-log/sent-email-log-code.d.ts.map +1 -0
  121. package/dist/cjs/sent-email-log/sent-email-log-code.js +415 -0
  122. package/dist/cjs/sent-email-log/sent-email-log-code.js.map +1 -0
  123. package/dist/cjs/sent-email-log/sent-email-log-scope.d.ts +21 -0
  124. package/dist/cjs/sent-email-log/sent-email-log-scope.d.ts.map +1 -0
  125. package/dist/cjs/sent-email-log/sent-email-log-scope.js +36 -0
  126. package/dist/cjs/sent-email-log/sent-email-log-scope.js.map +1 -0
  127. package/dist/cjs/transactional-email-code.d.ts +39 -1
  128. package/dist/cjs/transactional-email-code.d.ts.map +1 -1
  129. package/dist/cjs/transactional-email-code.js +86 -12
  130. package/dist/cjs/transactional-email-code.js.map +1 -1
  131. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  132. package/dist/cjs/webhook-generator.d.ts.map +1 -1
  133. package/dist/cjs/webhook-generator.js +9 -2
  134. package/dist/cjs/webhook-generator.js.map +1 -1
  135. package/dist/cjs/workflow-component-plugin.js +4 -3
  136. package/dist/cjs/workflow-component-plugin.js.map +1 -1
  137. package/dist/cjs/workflow-project-plugin.d.ts.map +1 -1
  138. package/dist/cjs/workflow-project-plugin.js +31 -3
  139. package/dist/cjs/workflow-project-plugin.js.map +1 -1
  140. package/dist/cjs/workflow-utils-alias.d.ts +21 -0
  141. package/dist/cjs/workflow-utils-alias.d.ts.map +1 -0
  142. package/dist/cjs/workflow-utils-alias.js +27 -0
  143. package/dist/cjs/workflow-utils-alias.js.map +1 -0
  144. package/dist/esm/account-delete-route-generator.d.ts +20 -0
  145. package/dist/esm/account-delete-route-generator.d.ts.map +1 -1
  146. package/dist/esm/account-delete-route-generator.js +30 -27
  147. package/dist/esm/account-delete-route-generator.js.map +1 -1
  148. package/dist/esm/api-route-generator.d.ts.map +1 -1
  149. package/dist/esm/api-route-generator.js +57 -11
  150. package/dist/esm/api-route-generator.js.map +1 -1
  151. package/dist/esm/auth-generator.d.ts +2 -1
  152. package/dist/esm/auth-generator.d.ts.map +1 -1
  153. package/dist/esm/auth-generator.js +56 -19
  154. package/dist/esm/auth-generator.js.map +1 -1
  155. package/dist/esm/data-api-route-generator.d.ts.map +1 -1
  156. package/dist/esm/data-api-route-generator.js +19 -0
  157. package/dist/esm/data-api-route-generator.js.map +1 -1
  158. package/dist/esm/email-locale/email-locale-code.d.ts +25 -0
  159. package/dist/esm/email-locale/email-locale-code.d.ts.map +1 -0
  160. package/dist/esm/email-locale/email-locale-code.js +222 -0
  161. package/dist/esm/email-locale/email-locale-code.js.map +1 -0
  162. package/dist/esm/email-locale/email-locale-scope.d.ts +46 -0
  163. package/dist/esm/email-locale/email-locale-scope.d.ts.map +1 -0
  164. package/dist/esm/email-locale/email-locale-scope.js +47 -0
  165. package/dist/esm/email-locale/email-locale-scope.js.map +1 -0
  166. package/dist/esm/email-locale/index.d.ts +11 -0
  167. package/dist/esm/email-locale/index.d.ts.map +1 -0
  168. package/dist/esm/email-locale/index.js +28 -0
  169. package/dist/esm/email-locale/index.js.map +1 -0
  170. package/dist/esm/executor-generator.d.ts +11 -1
  171. package/dist/esm/executor-generator.d.ts.map +1 -1
  172. package/dist/esm/executor-generator.js +49 -7
  173. package/dist/esm/executor-generator.js.map +1 -1
  174. package/dist/esm/index.d.ts +2 -0
  175. package/dist/esm/index.d.ts.map +1 -1
  176. package/dist/esm/index.js +2 -0
  177. package/dist/esm/index.js.map +1 -1
  178. package/dist/esm/invoice/api-routes-code.d.ts.map +1 -1
  179. package/dist/esm/invoice/api-routes-code.js +55 -6
  180. package/dist/esm/invoice/api-routes-code.js.map +1 -1
  181. package/dist/esm/invoice/email-sender-code.d.ts.map +1 -1
  182. package/dist/esm/invoice/email-sender-code.js +72 -31
  183. package/dist/esm/invoice/email-sender-code.js.map +1 -1
  184. package/dist/esm/invoice/index.d.ts +1 -4
  185. package/dist/esm/invoice/index.d.ts.map +1 -1
  186. package/dist/esm/invoice/index.js +7 -18
  187. package/dist/esm/invoice/index.js.map +1 -1
  188. package/dist/esm/invoice/invoice-html-code.d.ts.map +1 -1
  189. package/dist/esm/invoice/invoice-html-code.js +31 -8
  190. package/dist/esm/invoice/invoice-html-code.js.map +1 -1
  191. package/dist/esm/invoice/regional-invoice-tax-code.d.ts +25 -0
  192. package/dist/esm/invoice/regional-invoice-tax-code.d.ts.map +1 -0
  193. package/dist/esm/invoice/regional-invoice-tax-code.js +113 -0
  194. package/dist/esm/invoice/regional-invoice-tax-code.js.map +1 -0
  195. package/dist/esm/invoice/resolve-data-source.d.ts +6 -0
  196. package/dist/esm/invoice/resolve-data-source.d.ts.map +1 -0
  197. package/dist/esm/invoice/resolve-data-source.js +19 -0
  198. package/dist/esm/invoice/resolve-data-source.js.map +1 -0
  199. package/dist/esm/nodes/account/account-delete-current.d.ts.map +1 -1
  200. package/dist/esm/nodes/account/account-delete-current.js +10 -3
  201. package/dist/esm/nodes/account/account-delete-current.js.map +1 -1
  202. package/dist/esm/nodes/account/account-login.d.ts.map +1 -1
  203. package/dist/esm/nodes/account/account-login.js +3 -1
  204. package/dist/esm/nodes/account/account-login.js.map +1 -1
  205. package/dist/esm/nodes/account/account-logout.d.ts.map +1 -1
  206. package/dist/esm/nodes/account/account-logout.js +4 -2
  207. package/dist/esm/nodes/account/account-logout.js.map +1 -1
  208. package/dist/esm/nodes/account/account-signup.d.ts.map +1 -1
  209. package/dist/esm/nodes/account/account-signup.js +12 -2
  210. package/dist/esm/nodes/account/account-signup.js.map +1 -1
  211. package/dist/esm/nodes/account/account-social-login.d.ts.map +1 -1
  212. package/dist/esm/nodes/account/account-social-login.js +4 -2
  213. package/dist/esm/nodes/account/account-social-login.js.map +1 -1
  214. package/dist/esm/nodes/cart/cart-clear.d.ts.map +1 -1
  215. package/dist/esm/nodes/cart/cart-clear.js +6 -0
  216. package/dist/esm/nodes/cart/cart-clear.js.map +1 -1
  217. package/dist/esm/nodes/cart/cart-get-total.d.ts.map +1 -1
  218. package/dist/esm/nodes/cart/cart-get-total.js +81 -5
  219. package/dist/esm/nodes/cart/cart-get-total.js.map +1 -1
  220. package/dist/esm/nodes/data/data-create-item.d.ts.map +1 -1
  221. package/dist/esm/nodes/data/data-create-item.js +16 -0
  222. package/dist/esm/nodes/data/data-create-item.js.map +1 -1
  223. package/dist/esm/nodes/ecommerce/ecommerce-generate-invoice.d.ts.map +1 -1
  224. package/dist/esm/nodes/ecommerce/ecommerce-generate-invoice.js +6 -0
  225. package/dist/esm/nodes/ecommerce/ecommerce-generate-invoice.js.map +1 -1
  226. package/dist/esm/nodes/navigation/navigation-go-to-page.d.ts.map +1 -1
  227. package/dist/esm/nodes/navigation/navigation-go-to-page.js +4 -1
  228. package/dist/esm/nodes/navigation/navigation-go-to-page.js.map +1 -1
  229. package/dist/esm/nodes/navigation/navigation-navigate-to-url.d.ts.map +1 -1
  230. package/dist/esm/nodes/navigation/navigation-navigate-to-url.js +5 -2
  231. package/dist/esm/nodes/navigation/navigation-navigate-to-url.js.map +1 -1
  232. package/dist/esm/nodes/payment/payment-charge-user.d.ts.map +1 -1
  233. package/dist/esm/nodes/payment/payment-charge-user.js +7 -2
  234. package/dist/esm/nodes/payment/payment-charge-user.js.map +1 -1
  235. package/dist/esm/segment-splitter.d.ts +1 -1
  236. package/dist/esm/segment-splitter.d.ts.map +1 -1
  237. package/dist/esm/segment-splitter.js +29 -2
  238. package/dist/esm/segment-splitter.js.map +1 -1
  239. package/dist/esm/sent-email-log/index.d.ts +16 -0
  240. package/dist/esm/sent-email-log/index.d.ts.map +1 -0
  241. package/dist/esm/sent-email-log/index.js +45 -0
  242. package/dist/esm/sent-email-log/index.js.map +1 -0
  243. package/dist/esm/sent-email-log/sent-email-log-code.d.ts +4 -0
  244. package/dist/esm/sent-email-log/sent-email-log-code.d.ts.map +1 -0
  245. package/dist/esm/sent-email-log/sent-email-log-code.js +411 -0
  246. package/dist/esm/sent-email-log/sent-email-log-code.js.map +1 -0
  247. package/dist/esm/sent-email-log/sent-email-log-scope.d.ts +21 -0
  248. package/dist/esm/sent-email-log/sent-email-log-scope.d.ts.map +1 -0
  249. package/dist/esm/sent-email-log/sent-email-log-scope.js +31 -0
  250. package/dist/esm/sent-email-log/sent-email-log-scope.js.map +1 -0
  251. package/dist/esm/transactional-email-code.d.ts +39 -1
  252. package/dist/esm/transactional-email-code.d.ts.map +1 -1
  253. package/dist/esm/transactional-email-code.js +81 -10
  254. package/dist/esm/transactional-email-code.js.map +1 -1
  255. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  256. package/dist/esm/webhook-generator.d.ts.map +1 -1
  257. package/dist/esm/webhook-generator.js +9 -2
  258. package/dist/esm/webhook-generator.js.map +1 -1
  259. package/dist/esm/workflow-component-plugin.js +4 -3
  260. package/dist/esm/workflow-component-plugin.js.map +1 -1
  261. package/dist/esm/workflow-project-plugin.d.ts.map +1 -1
  262. package/dist/esm/workflow-project-plugin.js +32 -4
  263. package/dist/esm/workflow-project-plugin.js.map +1 -1
  264. package/dist/esm/workflow-utils-alias.d.ts +21 -0
  265. package/dist/esm/workflow-utils-alias.d.ts.map +1 -0
  266. package/dist/esm/workflow-utils-alias.js +21 -0
  267. package/dist/esm/workflow-utils-alias.js.map +1 -0
  268. package/package.json +4 -4
  269. package/src/account-delete-route-generator.ts +36 -7
  270. package/src/api-route-generator.ts +64 -11
  271. package/src/auth-generator.ts +63 -18
  272. package/src/data-api-route-generator.ts +19 -0
  273. package/src/email-locale/email-locale-code.ts +239 -0
  274. package/src/email-locale/email-locale-scope.ts +65 -0
  275. package/src/email-locale/index.ts +46 -0
  276. package/src/executor-generator.ts +65 -7
  277. package/src/index.ts +8 -0
  278. package/src/invoice/api-routes-code.ts +65 -6
  279. package/src/invoice/email-sender-code.ts +72 -31
  280. package/src/invoice/index.ts +7 -23
  281. package/src/invoice/invoice-html-code.ts +31 -8
  282. package/src/invoice/regional-invoice-tax-code.ts +112 -0
  283. package/src/invoice/resolve-data-source.ts +25 -0
  284. package/src/nodes/account/account-delete-current.ts +10 -3
  285. package/src/nodes/account/account-login.ts +3 -1
  286. package/src/nodes/account/account-logout.ts +4 -2
  287. package/src/nodes/account/account-signup.ts +12 -2
  288. package/src/nodes/account/account-social-login.ts +7 -2
  289. package/src/nodes/cart/cart-clear.ts +6 -0
  290. package/src/nodes/cart/cart-get-total.ts +94 -5
  291. package/src/nodes/data/data-create-item.ts +16 -0
  292. package/src/nodes/ecommerce/ecommerce-generate-invoice.ts +6 -0
  293. package/src/nodes/navigation/navigation-go-to-page.ts +5 -1
  294. package/src/nodes/navigation/navigation-navigate-to-url.ts +6 -2
  295. package/src/nodes/payment/payment-charge-user.ts +13 -2
  296. package/src/nodes/workflow-utils-global.d.ts +12 -0
  297. package/src/segment-splitter.ts +33 -2
  298. package/src/sent-email-log/index.ts +57 -0
  299. package/src/sent-email-log/sent-email-log-code.ts +419 -0
  300. package/src/sent-email-log/sent-email-log-scope.ts +36 -0
  301. package/src/transactional-email-code.ts +112 -4
  302. package/src/webhook-generator.ts +11 -2
  303. package/src/workflow-component-plugin.ts +4 -3
  304. package/src/workflow-project-plugin.ts +36 -4
  305. package/src/workflow-utils-alias.ts +26 -0
@@ -2,12 +2,15 @@ import {
2
2
  UIDLAuthentication,
3
3
  UIDLAuthTableColumn,
4
4
  UIDLCustomUserProperty,
5
+ UIDLLocalizedEmailTemplates,
5
6
  DataSourceType,
6
7
  } from '@teleporthq/teleport-types'
7
8
  import {
8
9
  SUPPORTED_EMAIL_PROVIDERS,
9
10
  generateProviderSendFunction,
10
11
  generateFillTemplateFn,
12
+ generateEmailLocaleRequire,
13
+ generateLocalizedEmailCopyFn,
11
14
  WELCOME_EMAIL_CONFIG_KEYS,
12
15
  } from './transactional-email-code'
13
16
  import { generateSessionTokenResolverCode } from './session-cookie-resolver'
@@ -1072,6 +1075,9 @@ export interface WelcomeEmailOptions {
1072
1075
  emailSecretEnvName?: string | null
1073
1076
  emailSubject?: string
1074
1077
  emailBodyHtml?: string
1078
+ // Per-language copies of the subject/body (main language excluded); the
1079
+ // route sends the copy matching the language the signup came from.
1080
+ localizedTemplates?: UIDLLocalizedEmailTemplates
1075
1081
  siteName?: string
1076
1082
  }
1077
1083
 
@@ -1108,22 +1114,39 @@ const WELCOME_EMAIL_FROM = ${JSON.stringify(welcome.fromEmail || '')};
1108
1114
  const WELCOME_EMAIL_SECRET_ENV_NAME = ${JSON.stringify(welcome.emailSecretEnvName || '')};
1109
1115
  const WELCOME_EMAIL_SUBJECT = ${JSON.stringify(welcome.emailSubject || 'Welcome')};
1110
1116
  const WELCOME_EMAIL_BODY_HTML = ${JSON.stringify(welcome.emailBodyHtml || '')};
1117
+ const WELCOME_EMAIL_LOCALIZED = ${JSON.stringify(welcome.localizedTemplates || {})};
1111
1118
  const WELCOME_EMAIL_SITE_NAME = ${JSON.stringify(welcome.siteName || '')};
1119
+ ${generateEmailLocaleRequire('../../..')}
1112
1120
 
1113
1121
  ${generateFillTemplateFn()}
1114
1122
 
1115
- ${generateProviderSendFunction(welcomeProvider)}
1116
-
1117
- async function sendWelcomeEmail(toEmail, tokenValues) {
1123
+ ${generateLocalizedEmailCopyFn({
1124
+ fnName: 'resolveWelcomeEmailCopy',
1125
+ subjectConst: 'WELCOME_EMAIL_SUBJECT',
1126
+ bodyConst: 'WELCOME_EMAIL_BODY_HTML',
1127
+ localizedConst: 'WELCOME_EMAIL_LOCALIZED',
1128
+ })}
1129
+
1130
+ ${generateProviderSendFunction(welcomeProvider, {
1131
+ emailType: 'welcome',
1132
+ source: 'signup',
1133
+ sourceRef: 'api/auth/signup',
1134
+ relativePrefix: '../../..',
1135
+ })}
1136
+
1137
+ // \`locale\` is the language of the signup page (see resolveRequestLocale);
1138
+ // the email goes out in that language's copy when the template has one.
1139
+ async function sendWelcomeEmail(toEmail, tokenValues, userId, locale) {
1118
1140
  if (!WELCOME_EMAIL_PROVIDER || !WELCOME_EMAIL_BODY_HTML || !toEmail) { return; }
1119
1141
  var apiKey = WELCOME_EMAIL_SECRET_ENV_NAME ? process.env[WELCOME_EMAIL_SECRET_ENV_NAME] : '';
1120
1142
  if (apiKey && String(apiKey).indexOf('teleporthq.secrets.') === 0) { apiKey = ''; }
1121
1143
  if (!apiKey) { console.warn('[account-signup] welcome email skipped: credential not set'); return; }
1122
1144
  var from = WELCOME_EMAIL_FROM || process.env.EMAIL_FROM || '';
1123
1145
  if (!from) { console.warn('[account-signup] welcome email skipped: sender not configured'); return; }
1124
- var subject = fillTemplate(WELCOME_EMAIL_SUBJECT, tokenValues);
1125
- var html = fillTemplate(WELCOME_EMAIL_BODY_HTML, tokenValues);
1126
- await __sendProviderEmail({ from: from, to: toEmail, subject: subject, html: html, apiKey: apiKey });
1146
+ var copy = resolveWelcomeEmailCopy(locale);
1147
+ var subject = fillTemplate(copy.subject, tokenValues);
1148
+ var html = fillTemplate(copy.body, tokenValues);
1149
+ await __sendProviderEmail({ from: from, to: toEmail, subject: subject, html: html, apiKey: apiKey, tokenValues: tokenValues, userId: userId });
1127
1150
  }
1128
1151
  `
1129
1152
 
@@ -1162,11 +1185,17 @@ async function sendWelcomeEmail(toEmail, tokenValues) {
1162
1185
  userName: name || (newUser && newUser.name) || 'there',
1163
1186
  userEmail: email,
1164
1187
  siteName: __welcomeSiteName,
1165
- });
1188
+ }, newUser && newUser.id, __emailLocale.resolveRequestLocale(req));
1166
1189
  } catch (welcomeErr) {
1167
1190
  console.error('[account-signup] welcome email failed:', welcomeErr && welcomeErr.message ? welcomeErr.message : welcomeErr);
1168
1191
  }
1169
-
1192
+ ${
1193
+ welcomeProvider
1194
+ ? ` // Land the welcome email's ledger row before replying.
1195
+ if (typeof __sentEmailLog !== 'undefined') { await __sentEmailLog.settleSentEmailLog(); }
1196
+ `
1197
+ : ''
1198
+ }
1170
1199
  res.status(201).json({ user: sanitizeUser(newUser) });`
1171
1200
  } else {
1172
1201
  createUserCall = ` res.status(501).json({ error: 'No data source configured for user storage' });`
@@ -1459,6 +1488,28 @@ function isSelfGuardedPath(pathname) {
1459
1488
  return false;
1460
1489
  }
1461
1490
 
1491
+ // The visitor's language is a prefix on the request path that Next.js strips
1492
+ // before this middleware runs: for "/es/orders" \`nextUrl.pathname\` is
1493
+ // "/orders" and \`nextUrl.locale\` is "es". A redirect built from the bare
1494
+ // pathname would drop the visitor onto the default-language page, so every
1495
+ // redirect — and the callbackUrl it carries — puts the prefix back. The
1496
+ // default language is served unprefixed; a project without languages has no
1497
+ // locale at all and keeps the path as it is.
1498
+ function localizePathname(request, pathname) {
1499
+ var locale = request.nextUrl.locale;
1500
+ var defaultLocale = request.nextUrl.defaultLocale;
1501
+ if (!locale || !defaultLocale || locale === defaultLocale) return pathname;
1502
+ return '/' + locale + (pathname === '/' ? '' : pathname);
1503
+ }
1504
+
1505
+ function redirectWithinLocale(request, pathname, callbackPath) {
1506
+ var target = new URL(localizePathname(request, pathname), request.url);
1507
+ if (callbackPath) {
1508
+ target.searchParams.set('callbackUrl', localizePathname(request, callbackPath));
1509
+ }
1510
+ return NextResponse.redirect(target);
1511
+ }
1512
+
1462
1513
  // Where to send an authenticated user who lacks the required role. Normally the
1463
1514
  // home page ("you don't have access, here's the public site"). But when "/" is
1464
1515
  // itself a protected page (e.g. an admin dashboard published at the root), a
@@ -1466,11 +1517,9 @@ function isSelfGuardedPath(pathname) {
1466
1517
  // the sign-in page (with a callbackUrl) in that case.
1467
1518
  function roleDeniedRedirect(request, pathname) {
1468
1519
  if (pathname !== '/' && !protectedRoutes['/']) {
1469
- return NextResponse.redirect(new URL('/', request.url));
1520
+ return redirectWithinLocale(request, '/');
1470
1521
  }
1471
- var deniedUrl = new URL('${signInRoute}', request.url);
1472
- deniedUrl.searchParams.set('callbackUrl', pathname);
1473
- return NextResponse.redirect(deniedUrl);
1522
+ return redirectWithinLocale(request, '${signInRoute}', pathname);
1474
1523
  }
1475
1524
 
1476
1525
  async function middleware(request) {
@@ -1570,9 +1619,7 @@ async function middleware(request) {
1570
1619
  }
1571
1620
 
1572
1621
  if (matchedProtection.requiresAuth && !sessionUser) {
1573
- var signInUrl = new URL('${signInRoute}', request.url);
1574
- signInUrl.searchParams.set('callbackUrl', pathname);
1575
- return NextResponse.redirect(signInUrl);
1622
+ return redirectWithinLocale(request, '${signInRoute}', pathname);
1576
1623
  }
1577
1624
 
1578
1625
  // Role enforcement uses whichever source resolved the user (decoded JWT or the
@@ -1581,9 +1628,7 @@ async function middleware(request) {
1581
1628
  var allowedRoles = matchedProtection.allowedRoles || [];
1582
1629
  if (allowedRoles.length > 0) {
1583
1630
  if (!sessionUser) {
1584
- var signInUrl2 = new URL('${signInRoute}', request.url);
1585
- signInUrl2.searchParams.set('callbackUrl', pathname);
1586
- return NextResponse.redirect(signInUrl2);
1631
+ return redirectWithinLocale(request, '${signInRoute}', pathname);
1587
1632
  }
1588
1633
  var userRole = getUserRoleFromToken(sessionUser);
1589
1634
  if (userRole == null || allowedRoles.indexOf(userRole) < 0) {
@@ -524,6 +524,24 @@ async function getColumnTypes(client, tableName) {
524
524
  } catch(e) { return {}; }
525
525
  }
526
526
 
527
+ // Tables whose rows remember the language of the storefront they were
528
+ // written from, so the emails about them can be sent in it later (by a cron,
529
+ // a webhook, an admin action — none of which run in the buyer's language).
530
+ // The column is stamped ONLY when the table actually has it: a store
531
+ // provisioned before the column existed keeps inserting exactly as before.
532
+ var LOCALE_STAMPED_TABLES = { teleport_orders: 1 };
533
+ var LOCALE_COLUMN = 'locale';
534
+
535
+ function stampRequestLocale(tableName, entries, colTypes, requestLocale) {
536
+ if (!LOCALE_STAMPED_TABLES[tableName]) return entries;
537
+ if (typeof requestLocale !== 'string' || !requestLocale) return entries;
538
+ if (!colTypes[LOCALE_COLUMN]) return entries;
539
+ for (var i = 0; i < entries.length; i++) {
540
+ if (entries[i][0] === LOCALE_COLUMN) return entries;
541
+ }
542
+ return entries.concat([[LOCALE_COLUMN, requestLocale.slice(0, 10)]]);
543
+ }
544
+
527
545
  async function handleCreate(client, body) {
528
546
  var tableName = body.tableName;
529
547
  var columnMappings = body.columnMappings || {};
@@ -550,6 +568,7 @@ async function handleCreate(client, body) {
550
568
  }
551
569
 
552
570
  var colTypes = await getColumnTypes(client, tableName);
571
+ entries = stampRequestLocale(tableName, entries, colTypes, body.__requestLocale);
553
572
 
554
573
  var TEXT_TYPES = { 'character varying': 1, 'text': 1, 'char': 1, 'character': 1, 'varchar': 1, 'name': 1 };
555
574
  var columns = entries.map(function(e) { return e[0]; });
@@ -0,0 +1,239 @@
1
+ import {
2
+ EMAIL_LOCALE_CONFIG_KEY,
3
+ EMAIL_LOCALE_HEADER,
4
+ EmailLocaleConfig,
5
+ LOCALIZED_TEMPLATES_CONFIG_KEY,
6
+ NEXT_LOCALE_COOKIE,
7
+ WORKFLOW_CONTEXT_LOCALE_KEY,
8
+ } from './email-locale-scope'
9
+
10
+ /**
11
+ * The locale helpers every generated email sender and every generated
12
+ * navigation runs. Emitted twice from this one source: as the standalone
13
+ * `utils/email/email-locale.js` module (the account routes, the invoice
14
+ * sender, the cart route and the cart provider use it) and inlined into the
15
+ * workflow runtime (`runtime-utils.js`), which is bundled for the browser as
16
+ * well and must not depend on a sibling file being resolvable.
17
+ *
18
+ * Every function is total: an unknown or missing locale resolves to the
19
+ * project's default language, so a sender can never pick a template that does
20
+ * not exist and a navigation can never be sent to a locale the app does not
21
+ * serve.
22
+ */
23
+ export const generateEmailLocaleHelpersCode = (config: EmailLocaleConfig): string => `
24
+ var EMAIL_LOCALES = ${JSON.stringify(config.locales)};
25
+ var DEFAULT_EMAIL_LOCALE = ${JSON.stringify(config.defaultLocale)};
26
+ var EMAIL_LOCALE_HEADER = ${JSON.stringify(EMAIL_LOCALE_HEADER)};
27
+ var NEXT_LOCALE_COOKIE = ${JSON.stringify(NEXT_LOCALE_COOKIE)};
28
+
29
+ // The project locale a raw value names, or null. Case-insensitive so a
30
+ // visitor-supplied "ES" still matches, but always answers the canonical code.
31
+ function normalizeEmailLocale(value) {
32
+ if (typeof value !== 'string') return null;
33
+ var trimmed = value.trim();
34
+ if (!trimmed) return null;
35
+ var lower = trimmed.toLowerCase();
36
+ for (var i = 0; i < EMAIL_LOCALES.length; i++) {
37
+ if (String(EMAIL_LOCALES[i]).toLowerCase() === lower) return EMAIL_LOCALES[i];
38
+ }
39
+ return null;
40
+ }
41
+
42
+ function readCookieValue(cookieHeader, name) {
43
+ if (typeof cookieHeader !== 'string' || !cookieHeader) return null;
44
+ var parts = cookieHeader.split(';');
45
+ for (var i = 0; i < parts.length; i++) {
46
+ var pair = parts[i].trim();
47
+ var eq = pair.indexOf('=');
48
+ if (eq === -1) continue;
49
+ if (pair.slice(0, eq).trim() !== name) continue;
50
+ try { return decodeURIComponent(pair.slice(eq + 1).trim()); } catch (e) { return pair.slice(eq + 1).trim(); }
51
+ }
52
+ return null;
53
+ }
54
+
55
+ // The locale prefix of a localized page path ("/es/checkout" → "es"). The
56
+ // default language is served unprefixed, which resolves to null here and to
57
+ // the default further down.
58
+ function localeFromPathname(pathname) {
59
+ if (typeof pathname !== 'string') return null;
60
+ var segments = pathname.split('/');
61
+ for (var i = 0; i < segments.length; i++) {
62
+ if (segments[i]) return normalizeEmailLocale(segments[i]);
63
+ }
64
+ return null;
65
+ }
66
+
67
+ function firstHeaderValue(value) {
68
+ return Array.isArray(value) ? value[0] : value;
69
+ }
70
+
71
+ // The language of the page a request came from: the explicit header the
72
+ // generated client runtime sends, else the locale prefix of the referring page
73
+ // (the page the browser is actually on), else the Next.js locale cookie (a
74
+ // stored preference, which a request without a referer is all we have), else
75
+ // the default language.
76
+ function resolveRequestLocale(req) {
77
+ var headers = req && req.headers ? req.headers : null;
78
+ if (!headers) return DEFAULT_EMAIL_LOCALE;
79
+ var fromHeader = normalizeEmailLocale(firstHeaderValue(headers[EMAIL_LOCALE_HEADER]));
80
+ if (fromHeader) return fromHeader;
81
+ var referer = firstHeaderValue(headers.referer || headers.referrer);
82
+ if (typeof referer === 'string' && referer) {
83
+ try {
84
+ var fromReferer = localeFromPathname(new URL(referer).pathname);
85
+ if (fromReferer) return fromReferer;
86
+ } catch (e) { /* not an absolute URL — nothing to read */ }
87
+ }
88
+ var fromCookie = normalizeEmailLocale(readCookieValue(firstHeaderValue(headers.cookie), NEXT_LOCALE_COOKIE));
89
+ if (fromCookie) return fromCookie;
90
+ return DEFAULT_EMAIL_LOCALE;
91
+ }
92
+
93
+ // The locale of the page the browser is on, read LIVE off the Next.js router.
94
+ // After a client-side language switch the page data
95
+ // (window.__NEXT_DATA__.locale) still names the locale the document was
96
+ // served in, while the router — and the <html lang> attribute it keeps in
97
+ // sync on every transition — already name the one the visitor switched to.
98
+ // Null outside a browser, or when no candidate is a project locale.
99
+ function getClientLocale() {
100
+ if (typeof window === 'undefined') return null;
101
+ var candidates = [];
102
+ try { candidates.push(window.next && window.next.router && window.next.router.locale); } catch (e) { /* router not mounted */ }
103
+ try { candidates.push(document.documentElement && document.documentElement.lang); } catch (e) { /* no document */ }
104
+ try { candidates.push(window.__NEXT_DATA__ && window.__NEXT_DATA__.locale); } catch (e) { /* no page data */ }
105
+ for (var i = 0; i < candidates.length; i++) {
106
+ var resolved = normalizeEmailLocale(candidates[i]);
107
+ if (resolved) return resolved;
108
+ }
109
+ return null;
110
+ }
111
+
112
+ // The href a navigation should use so the visitor stays in \`locale\`. Next.js
113
+ // serves the default language unprefixed and every other language under
114
+ // "/<locale>", so a site-relative page path gets that prefix. Left untouched:
115
+ // anything that is not a site-relative path (an external URL, a hash, a
116
+ // mailto:), an API route or a Next.js internal path (never localized), a file
117
+ // served from /public (not served under a locale prefix) and a path that
118
+ // already names a project locale. The default language, an unknown locale and
119
+ // a project without languages all leave the href as it is.
120
+ function localizeHref(href, locale) {
121
+ if (typeof href !== 'string' || href.charAt(0) !== '/' || href.charAt(1) === '/') return href;
122
+ var resolved = normalizeEmailLocale(locale);
123
+ if (!resolved || resolved === DEFAULT_EMAIL_LOCALE) return href;
124
+ var pathEnd = href.length;
125
+ var queryStart = href.indexOf('?');
126
+ if (queryStart !== -1) pathEnd = queryStart;
127
+ var hashStart = href.indexOf('#');
128
+ if (hashStart !== -1 && hashStart < pathEnd) pathEnd = hashStart;
129
+ var pathname = href.slice(0, pathEnd);
130
+ if (pathname === '/api' || pathname.indexOf('/api/') === 0) return href;
131
+ if (pathname.indexOf('/_next/') === 0) return href;
132
+ if (/\\.[A-Za-z0-9]{1,5}$/.test(pathname)) return href;
133
+ if (localeFromPathname(pathname)) return href;
134
+ return '/' + resolved + (pathname === '/' ? '' : pathname) + href.slice(pathEnd);
135
+ }
136
+
137
+ // The copy of a template that goes out in \`locale\`: its own body, its own
138
+ // subject when it has one (else the base subject), or the base copy for the
139
+ // default language and for any language that has no copy.
140
+ function pickLocalizedTemplate(base, localized, locale) {
141
+ var baseCopy = base || {};
142
+ var resolved = normalizeEmailLocale(locale) || DEFAULT_EMAIL_LOCALE;
143
+ var fallback = { subject: baseCopy.subject, body: baseCopy.body, locale: DEFAULT_EMAIL_LOCALE };
144
+ if (!resolved || resolved === DEFAULT_EMAIL_LOCALE) return fallback;
145
+ if (!localized || typeof localized !== 'object') return fallback;
146
+ var copy = localized[resolved];
147
+ if (!copy || typeof copy !== 'object' || typeof copy.body !== 'string' || !copy.body) return fallback;
148
+ return {
149
+ subject: typeof copy.subject === 'string' && copy.subject ? copy.subject : baseCopy.subject,
150
+ body: copy.body,
151
+ locale: resolved,
152
+ };
153
+ }
154
+ `
155
+
156
+ /**
157
+ * The runtime-only helpers, on top of the shared ones: how a workflow run
158
+ * learns its locale and how an email node's config resolves the language it
159
+ * sends in. Inlined into \`runtime-utils.js\` right after
160
+ * \`generateEmailLocaleHelpersCode\`.
161
+ */
162
+ export const generateWorkflowLocaleHelpersCode = (): string => `
163
+ // The locale a server route runs a segment in: the one the client runtime put
164
+ // on the context (validated — it crossed the network), else the request's.
165
+ function resolveWorkflowLocale(req, incomingContext) {
166
+ var fromContext = incomingContext ? normalizeEmailLocale(incomingContext[${JSON.stringify(
167
+ WORKFLOW_CONTEXT_LOCALE_KEY
168
+ )}]) : null;
169
+ return fromContext || resolveRequestLocale(req);
170
+ }
171
+
172
+ // The language an email node sends in. A config that BINDS the locale (the
173
+ // order's, the cart's) is authoritative even when the binding resolved to
174
+ // nothing — the request locale belongs to whoever triggered the workflow, which
175
+ // for an admin action is not the recipient. Otherwise the run's locale, then
176
+ // the default language.
177
+ function resolveEmailLocale(resolvedConfig, context) {
178
+ var config = resolvedConfig || {};
179
+ if (Object.prototype.hasOwnProperty.call(config, ${JSON.stringify(EMAIL_LOCALE_CONFIG_KEY)})) {
180
+ return normalizeEmailLocale(config[${JSON.stringify(
181
+ EMAIL_LOCALE_CONFIG_KEY
182
+ )}]) || DEFAULT_EMAIL_LOCALE;
183
+ }
184
+ var fromRun = context ? normalizeEmailLocale(context[${JSON.stringify(
185
+ WORKFLOW_CONTEXT_LOCALE_KEY
186
+ )}]) : null;
187
+ return fromRun || DEFAULT_EMAIL_LOCALE;
188
+ }
189
+
190
+ // Swaps a component-bodied email node's body/subject for the copy of the
191
+ // language it sends in, then drops the per-language map and the binding so
192
+ // neither reaches a provider handler or the sent-email ledger. Runs BEFORE the
193
+ // {{token}} fill: the copies carry the same merge fields as the base body.
194
+ function applyLocalizedEmailTemplate(resolvedConfig, context) {
195
+ var localized = resolvedConfig[${JSON.stringify(LOCALIZED_TEMPLATES_CONFIG_KEY)}];
196
+ var hasLocalized = !!localized && typeof localized === 'object';
197
+ var hasBinding = Object.prototype.hasOwnProperty.call(resolvedConfig, ${JSON.stringify(
198
+ EMAIL_LOCALE_CONFIG_KEY
199
+ )});
200
+ if (!hasLocalized && !hasBinding) return;
201
+ if (hasLocalized) {
202
+ var picked = pickLocalizedTemplate(
203
+ { subject: resolvedConfig.subject, body: resolvedConfig.body },
204
+ localized,
205
+ resolveEmailLocale(resolvedConfig, context)
206
+ );
207
+ if (typeof picked.body === 'string') resolvedConfig.body = picked.body;
208
+ if (typeof picked.subject === 'string') resolvedConfig.subject = picked.subject;
209
+ delete resolvedConfig[${JSON.stringify(LOCALIZED_TEMPLATES_CONFIG_KEY)}];
210
+ }
211
+ if (hasBinding) delete resolvedConfig[${JSON.stringify(EMAIL_LOCALE_CONFIG_KEY)}];
212
+ }
213
+ `
214
+
215
+ /** `utils/email/email-locale.js` — the shared helpers as a CommonJS module. */
216
+ export const generateEmailLocaleModuleCode = (config: EmailLocaleConfig): string => `/**
217
+ * Email locale resolution.
218
+ *
219
+ * A customer email goes out in the language of the page it was triggered from;
220
+ * the store owner's notifications always use the project's main language. This
221
+ * module answers "which locale?" for the senders that live outside the workflow
222
+ * runtime (the account routes, the invoice sender, the cart route) — the
223
+ * runtime carries the same helpers inline.
224
+ *
225
+ * Auto-generated. Edit the generator at
226
+ * teleport-plugin-next-workflows/src/email-locale/email-locale-code.ts.
227
+ */
228
+ ${generateEmailLocaleHelpersCode(config)}
229
+ module.exports = {
230
+ EMAIL_LOCALES: EMAIL_LOCALES,
231
+ DEFAULT_EMAIL_LOCALE: DEFAULT_EMAIL_LOCALE,
232
+ EMAIL_LOCALE_HEADER: EMAIL_LOCALE_HEADER,
233
+ normalizeEmailLocale: normalizeEmailLocale,
234
+ resolveRequestLocale: resolveRequestLocale,
235
+ getClientLocale: getClientLocale,
236
+ localizeHref: localizeHref,
237
+ pickLocalizedTemplate: pickLocalizedTemplate,
238
+ };
239
+ `
@@ -0,0 +1,65 @@
1
+ import { ProjectUIDL } from '@teleporthq/teleport-types'
2
+
3
+ /**
4
+ * The vocabulary every generated email sender shares to decide WHICH language a
5
+ * customer email goes out in. The module itself is emitted by
6
+ * `ensureEmailLocaleModule` (see `index.ts`); this file only holds the names
7
+ * the route generators, the workflow runtime and the UIDL mapper agree on.
8
+ */
9
+
10
+ export const EMAIL_LOCALE_FILE_KEY = 'email-locale'
11
+ export const EMAIL_LOCALE_PATH = ['utils', 'email']
12
+ export const EMAIL_LOCALE_FILE_NAME = 'email-locale'
13
+
14
+ /**
15
+ * Request header the generated client runtime sends with every call to the
16
+ * app's own API routes, carrying the locale of the page the visitor is on.
17
+ */
18
+ export const EMAIL_LOCALE_HEADER = 'x-teleport-locale'
19
+
20
+ /** The cookie Next.js reads for locale detection; honoured as a fallback. */
21
+ export const NEXT_LOCALE_COOKIE = 'NEXT_LOCALE'
22
+
23
+ /**
24
+ * Export-only node config key written by the editor's domain→UIDL mapper on a
25
+ * component-bodied email node: the per-language copies of its body/subject,
26
+ * keyed by locale short code (main language excluded). Consumed by the runtime
27
+ * (`resolveConfig`) and never by a handler.
28
+ */
29
+ export const LOCALIZED_TEMPLATES_CONFIG_KEY = 'localizedTemplates'
30
+
31
+ /**
32
+ * Node config key that pins an email to a language independently of the
33
+ * request: a lifecycle email bound to the order's stored locale, a reminder
34
+ * bound to the cart's. When the key is present its resolved value is
35
+ * authoritative — an empty one means the default language, never the locale of
36
+ * whoever triggered the workflow (an admin shipping an order is not the buyer).
37
+ */
38
+ export const EMAIL_LOCALE_CONFIG_KEY = 'emailLocale'
39
+
40
+ /** Workflow-context key carrying the request locale through a run. */
41
+ export const WORKFLOW_CONTEXT_LOCALE_KEY = '__locale'
42
+
43
+ /**
44
+ * The locales the generated app serves, as the email senders need them: the
45
+ * full list to validate an incoming value against and the default to fall back
46
+ * to. A project without internationalization has no locales at all — every
47
+ * sender then keeps its single template and nothing is ever localized.
48
+ */
49
+ export interface EmailLocaleConfig {
50
+ locales: string[]
51
+ defaultLocale: string
52
+ }
53
+
54
+ export const resolveEmailLocaleConfig = (uidl: ProjectUIDL): EmailLocaleConfig => {
55
+ const i18n = uidl.internationalization
56
+ if (!i18n) {
57
+ return { locales: [], defaultLocale: '' }
58
+ }
59
+ const defaultLocale = i18n.main?.locale || ''
60
+ const locales = Object.keys(i18n.languages || {})
61
+ if (defaultLocale && locales.indexOf(defaultLocale) === -1) {
62
+ locales.unshift(defaultLocale)
63
+ }
64
+ return { locales, defaultLocale }
65
+ }
@@ -0,0 +1,46 @@
1
+ import { FileType, ProjectPluginStructure } from '@teleporthq/teleport-types'
2
+ import { generateEmailLocaleModuleCode } from './email-locale-code'
3
+ import {
4
+ EMAIL_LOCALE_FILE_KEY,
5
+ EMAIL_LOCALE_FILE_NAME,
6
+ EMAIL_LOCALE_PATH,
7
+ resolveEmailLocaleConfig,
8
+ } from './email-locale-scope'
9
+
10
+ export {
11
+ EMAIL_LOCALE_CONFIG_KEY,
12
+ EMAIL_LOCALE_HEADER,
13
+ EmailLocaleConfig,
14
+ LOCALIZED_TEMPLATES_CONFIG_KEY,
15
+ WORKFLOW_CONTEXT_LOCALE_KEY,
16
+ resolveEmailLocaleConfig,
17
+ } from './email-locale-scope'
18
+ export {
19
+ generateEmailLocaleHelpersCode,
20
+ generateEmailLocaleModuleCode,
21
+ generateWorkflowLocaleHelpersCode,
22
+ } from './email-locale-code'
23
+
24
+ /**
25
+ * Writes `utils/email/email-locale.js` into the project, once. Like the
26
+ * sent-email ledger, every emitter of a send path that lives outside the
27
+ * workflow runtime calls this right where it emits the `require`, so the file
28
+ * exists exactly when something needs it, whichever plugin ran first.
29
+ */
30
+ export const ensureEmailLocaleModule = (structure: ProjectPluginStructure): void => {
31
+ const { files, uidl } = structure
32
+ if (files.has(EMAIL_LOCALE_FILE_KEY)) {
33
+ return
34
+ }
35
+
36
+ files.set(EMAIL_LOCALE_FILE_KEY, {
37
+ path: EMAIL_LOCALE_PATH,
38
+ files: [
39
+ {
40
+ name: EMAIL_LOCALE_FILE_NAME,
41
+ fileType: FileType.JS,
42
+ content: generateEmailLocaleModuleCode(resolveEmailLocaleConfig(uidl)),
43
+ },
44
+ ],
45
+ })
46
+ }