@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
@@ -1,4 +1,22 @@
1
- export const generateSharedRuntimeUtilsCode = (): string => {
1
+ import {
2
+ EmailLocaleConfig,
3
+ generateEmailLocaleHelpersCode,
4
+ generateWorkflowLocaleHelpersCode,
5
+ } from './email-locale'
6
+
7
+ export interface SharedRuntimeUtilsOptions {
8
+ /**
9
+ * The project's locales, baked in so the runtime can validate the locale a
10
+ * request or the browser reports and pick the matching copy of a localized
11
+ * email. Absent (a project without internationalization): no locale is ever
12
+ * recognised and every email keeps its single template.
13
+ */
14
+ emailLocales?: EmailLocaleConfig
15
+ }
16
+
17
+ const NO_EMAIL_LOCALES: EmailLocaleConfig = { locales: [], defaultLocale: '' }
18
+
19
+ export const generateSharedRuntimeUtilsCode = (options: SharedRuntimeUtilsOptions = {}): string => {
2
20
  return `/**
3
21
  * Workflow Runtime Utilities
4
22
  *
@@ -8,7 +26,8 @@ export const generateSharedRuntimeUtilsCode = (): string => {
8
26
  * - executeNodes: Executes a sequence of workflow nodes
9
27
  * - executeWorkflow: Main workflow execution entry point
10
28
  */
11
-
29
+ ${generateEmailLocaleHelpersCode(options.emailLocales || NO_EMAIL_LOCALES)}
30
+ ${generateWorkflowLocaleHelpersCode()}
12
31
  function resolveValue(value, context) {
13
32
  if (value === null || value === undefined) return value;
14
33
  if (Array.isArray(value)) {
@@ -522,6 +541,11 @@ function resolveConfig(config, context) {
522
541
  //
523
542
  // Runs after resolution on purpose: \`templateParams[].value\` is itself a
524
543
  // workflow-context ref that the loop above has just resolved.
544
+ //
545
+ // The language is chosen first, for the same reason: a customer email carries
546
+ // one copy per project language, and the copy has to be picked before its
547
+ // tokens are filled.
548
+ applyLocalizedEmailTemplate(resolved, context);
525
549
  if (Array.isArray(resolved.templateParams)) {
526
550
  if (typeof resolved.body === 'string') {
527
551
  resolved.body = applyTemplateParams(resolved.body, resolved.templateParams);
@@ -651,6 +675,12 @@ async function executeWorkflow(workflowConfig, triggerContext, nodeHandlers, opt
651
675
  if (triggerContext && triggerContext.triggerElement) {
652
676
  context.triggerElement = triggerContext.triggerElement;
653
677
  }
678
+ // The language of the page this run started on, carried to every server
679
+ // segment (the context crosses whole) so a customer email can be sent in it.
680
+ var runLocale = getClientLocale();
681
+ if (runLocale) {
682
+ context.__locale = runLocale;
683
+ }
654
684
 
655
685
  const callServerSegment = options.callServerSegment;
656
686
 
@@ -750,6 +780,15 @@ function isFireAndForgetNode(node) {
750
780
  return !!node.config && node.config.awaitResult === false;
751
781
  }
752
782
 
783
+ // A node the author marked \`continueOnError\`: a failed RESULT ({ success:
784
+ // false } / { error }) is published under the node's id like any other result
785
+ // instead of aborting the workflow, so a later if-statement can read
786
+ // \`success\` and warn. Only an explicit \`true\` opts in. A handler that THROWS
787
+ // still aborts — every provider handler reports failure as a result.
788
+ function continuesOnError(node) {
789
+ return !!(node && node.config && node.config.continueOnError === true);
790
+ }
791
+
753
792
  // Starts a fire-and-forget node and returns a promise that ALWAYS resolves.
754
793
  // The workflow has already moved on, so a failure here can neither abort it nor
755
794
  // reach the error handler — it is reported to the console and swallowed, which
@@ -791,10 +830,13 @@ async function settlePendingNodePromises(context) {
791
830
  for (var pass = 0; pass < 5; pass++) {
792
831
  var pending = context.__pendingNodePromises;
793
832
  if (!pending || pending.length === 0) return;
794
- context.__pendingNodePromises = [];
833
+ // Drained IN PLACE, never by swapping in a fresh array: a parallel branch
834
+ // that is still running holds a reference to this very array (its context
835
+ // is a shallow copy) and must keep landing on the queue the route drains.
836
+ var batch = pending.splice(0, pending.length);
795
837
  // Every entry swallows its own rejection (see startFireAndForgetNode), so
796
838
  // this can never reject.
797
- await Promise.all(pending);
839
+ await Promise.all(batch);
798
840
  }
799
841
  }
800
842
 
@@ -918,7 +960,7 @@ async function executeNodes(nodes, edges, context, nodeHandlers, workflowConfig,
918
960
  await executeNodes(onStreamNodes, edges, context, nodeHandlers, workflowConfig, callServerSegment, executionId);
919
961
  }
920
962
  });
921
- if (isFatalNodeResult(streamResult)) {
963
+ if (isFatalNodeResult(streamResult) && !continuesOnError(node)) {
922
964
  throw new Error(fatalNodeResultMessage(streamResult));
923
965
  }
924
966
  context[node.id] = streamResult;
@@ -977,7 +1019,7 @@ async function executeNodes(nodes, edges, context, nodeHandlers, workflowConfig,
977
1019
  throw earlyErr;
978
1020
  }
979
1021
 
980
- if (isFatalNodeResult(result)) {
1022
+ if (isFatalNodeResult(result) && !continuesOnError(node)) {
981
1023
  throw new Error(fatalNodeResultMessage(result));
982
1024
  }
983
1025
 
@@ -1276,6 +1318,13 @@ function internalRequestHeaders(req) {
1276
1318
 
1277
1319
  module.exports = {
1278
1320
  internalRequestHeaders,
1321
+ normalizeEmailLocale,
1322
+ resolveRequestLocale,
1323
+ resolveWorkflowLocale,
1324
+ resolveEmailLocale,
1325
+ getClientLocale,
1326
+ localizeHref,
1327
+ pickLocalizedTemplate,
1279
1328
  resolveValue,
1280
1329
  resolveSecret,
1281
1330
  resolveConfig,
@@ -1299,6 +1348,7 @@ module.exports = {
1299
1348
  isStreamingAINode,
1300
1349
  isFatalNodeResult,
1301
1350
  fatalNodeResultMessage,
1351
+ continuesOnError,
1302
1352
  isFireAndForgetNode,
1303
1353
  startFireAndForgetNode,
1304
1354
  registerPendingNodePromise,
@@ -1545,6 +1595,11 @@ function buildContext(workflowConfig, triggerContext) {
1545
1595
  if (triggerContext.__dynamicRouteParam) context.__dynamicRouteParam = triggerContext.__dynamicRouteParam;
1546
1596
  if (triggerContext.triggerElement) context.triggerElement = triggerContext.triggerElement;
1547
1597
  }
1598
+ // See executeWorkflow: the page's language travels with the run.
1599
+ var runLocale = utils.getClientLocale();
1600
+ if (runLocale) {
1601
+ context.__locale = runLocale;
1602
+ }
1548
1603
  return context;
1549
1604
  }
1550
1605
 
@@ -1872,7 +1927,10 @@ async function executeWorkflowWithSegments(workflowConfig, triggerContext, clien
1872
1927
  if (__terminalResult) {
1873
1928
  var __redirectUrl = __terminalResult.__redirectUrl;
1874
1929
  if (typeof __redirectUrl === 'string' && __redirectUrl.length > 0 && typeof window !== 'undefined' && window.location) {
1875
- window.location.href = __redirectUrl;
1930
+ // A site-relative target keeps the visitor in the language of the
1931
+ // page the run started on (the provider's hosted page is absolute
1932
+ // and passes through untouched).
1933
+ window.location.href = utils.localizeHref(__redirectUrl, context.__locale);
1876
1934
  }
1877
1935
  break;
1878
1936
  }
package/src/index.ts CHANGED
@@ -21,6 +21,14 @@ export {
21
21
  } from './api-route-generator'
22
22
  export { generateTriggerCode } from './trigger-generator'
23
23
  export { generatePgClientCode } from './pg-client-code'
24
+ export { ensureSentEmailLogModule } from './sent-email-log'
25
+ export {
26
+ ensureEmailLocaleModule,
27
+ EMAIL_LOCALE_CONFIG_KEY,
28
+ EMAIL_LOCALE_HEADER,
29
+ LOCALIZED_TEMPLATES_CONFIG_KEY,
30
+ resolveEmailLocaleConfig,
31
+ } from './email-locale'
24
32
  export {
25
33
  SESSION_TOKEN_RESOLVER_FN,
26
34
  generateSessionTokenResolverCode,
@@ -1,4 +1,5 @@
1
1
  import { UIDLInvoiceSettings } from '@teleporthq/teleport-types'
2
+ import { REGIONAL_INVOICE_TAX_CODE } from './regional-invoice-tax-code'
2
3
 
3
4
  export const generateInvoiceGenerateRouteCode = (settings: UIDLInvoiceSettings): string => {
4
5
  const prefix = settings.invoicePrefix || 'INV-'
@@ -20,7 +21,13 @@ export const generateInvoiceGenerateRouteCode = (settings: UIDLInvoiceSettings):
20
21
 
21
22
  var dataAccess = require('../../../utils/invoices/data-access');
22
23
  var pdfGenerator = require('../../../utils/invoices/pdf-generator');
23
- ${emailEnabled ? `var emailSender = require('../../../utils/invoices/email-sender');` : ''}
24
+ ${
25
+ emailEnabled
26
+ ? `var emailSender = require('../../../utils/invoices/email-sender');
27
+ var sentEmailLog = require('../../../utils/email/sent-email-log');
28
+ var emailLocale = require('../../../utils/email/email-locale');`
29
+ : ''
30
+ }
24
31
 
25
32
  var INVOICE_PREFIX = ${JSON.stringify(prefix)};
26
33
  var DEFAULT_TAX_RATE = ${defaultTaxRate};
@@ -28,6 +35,7 @@ var DEFAULT_CURRENCY = "USD";
28
35
  var SHOW_DISCOUNT = ${showDiscount};
29
36
  var TAX_INCLUDED_IN_PRICE = ${taxIncludedInPrice};
30
37
  var TEMPLATE_DOCUMENT = ${templateDocumentJson};
38
+ ${REGIONAL_INVOICE_TAX_CODE}
31
39
 
32
40
  // Runtime storage configuration. When all three are set, the generated PDF
33
41
  // is also POSTed to the storage worker so consumers (e.g. the payment
@@ -285,6 +293,9 @@ module.exports = async function handler(req, res) {
285
293
  : hydratedItems.map(function (row) {
286
294
  return {
287
295
  productId: row.product_id || row.productId || null,
296
+ // Paired with \`productId\` to find the rate a line was charged at
297
+ // on an order priced by region (see resolveRegionalInvoiceTax).
298
+ variantId: row.variant_id || row.variantId || null,
288
299
  name: row.product_name || row.name || 'Item',
289
300
  variantLabel: row.variant_label || row.variantLabel || null,
290
301
  variantSwatches: row.variant_swatches || row.variantSwatches || null,
@@ -381,6 +392,28 @@ module.exports = async function handler(req, res) {
381
392
  }
382
393
  var total = goodsTotal + shippingAmount;
383
394
 
395
+ // An order priced by region records the rate each line was charged at, so
396
+ // its invoice is computed from that record instead of the store default.
397
+ // A caller that states its own \`taxRate\` keeps the single-rate path.
398
+ var taxIncludedInPrice = TAX_INCLUDED_IN_PRICE;
399
+ var regionalTaxBreakdown = body.taxRate == null
400
+ ? parseOrderTaxBreakdown(orderShippingSource.tax_breakdown)
401
+ : null;
402
+ if (regionalTaxBreakdown) {
403
+ var regionalTax = resolveRegionalInvoiceTax(regionalTaxBreakdown, items, discountAmount, shippingAmount);
404
+ taxRate = regionalTax.taxRate;
405
+ taxIncludedInPrice = regionalTax.taxIncluded;
406
+ subtotal = regionalTax.subtotal;
407
+ taxAmount = regionalTax.taxAmount;
408
+ shippingAmount = regionalTax.shippingNet;
409
+ total = regionalTax.total;
410
+ for (var ti = 0; ti < items.length; ti++) {
411
+ items[ti].taxRate = regionalTax.itemTax[ti].rate;
412
+ items[ti].taxIncluded = regionalTax.itemTax[ti].included;
413
+ items[ti].taxAmount = regionalTax.itemTax[ti].amount;
414
+ }
415
+ }
416
+
384
417
  // Cross-check against the amount the order was actually placed for. The
385
418
  // invoice is built from line items, the order carries the charged total,
386
419
  // and the two must agree — when they don't, the invoice is being written
@@ -446,7 +479,19 @@ module.exports = async function handler(req, res) {
446
479
  var fallbackPaymentProvider = orderRow.payment_provider || '';
447
480
  var fallbackPaymentIntentId = orderRow.payment_intent_id || '';
448
481
  var fallbackNotes = orderRow.notes || '';
449
-
482
+ ${
483
+ emailEnabled
484
+ ? `
485
+ // The language the invoice email goes out in: the one stamped on the
486
+ // order at checkout (the buyer's storefront), else the one the caller
487
+ // named, else the language of the request itself. A cron or a webhook
488
+ // has neither of the last two and lands on the store's main language.
489
+ var invoiceLocale = emailLocale.normalizeEmailLocale(orderRow.locale)
490
+ || emailLocale.normalizeEmailLocale(body.locale)
491
+ || emailLocale.resolveRequestLocale(req);
492
+ `
493
+ : ''
494
+ }
450
495
  var invoiceData = {
451
496
  id: body.id || require('crypto').randomUUID(),
452
497
  invoiceNumber: invoiceNumber,
@@ -455,7 +500,9 @@ module.exports = async function handler(req, res) {
455
500
  dueDate: dueDate,
456
501
  paidAt: body.paidAt || null,
457
502
  customerName: body.customerName || fallbackCustomerName || '',
458
- customerEmail: body.customerEmail || fallbackCustomerEmail || '',
503
+ customerEmail: body.customerEmail || fallbackCustomerEmail || '',${
504
+ emailEnabled ? '\n locale: invoiceLocale,' : ''
505
+ }
459
506
  customerAddress: body.customerAddress || fallbackCustomerAddress || '',
460
507
  customerCity: body.customerCity || fallbackCustomerCity || '',
461
508
  customerState: body.customerState || fallbackCustomerState || '',
@@ -483,7 +530,7 @@ module.exports = async function handler(req, res) {
483
530
  // this flag the builder can't tell whether the stored unitPrice is
484
531
  // a net (added on top) or a gross (included in price) value, and
485
532
  // the line-item table renders blank cells.
486
- taxIncludedInPrice: TAX_INCLUDED_IN_PRICE,
533
+ taxIncludedInPrice: taxIncludedInPrice,
487
534
  discountAmount: Math.round(discountAmount * 100) / 100,
488
535
  // Delivery fee, surfaced so the PDF/HTML renderer can print its own line
489
536
  // and the merchant's template can bind \`invoice.shippingAmount\`.
@@ -604,7 +651,14 @@ ${
604
651
  currency: currency,
605
652
  });
606
653
 
607
- res.status(200).json({
654
+ ${
655
+ emailEnabled
656
+ ? ` // The email's ledger row is written in the background — land it before
657
+ // replying, a serverless function may be frozen the instant it responds.
658
+ await sentEmailLog.settleSentEmailLog();
659
+ `
660
+ : ''
661
+ } res.status(200).json({
608
662
  success: true,
609
663
  invoiceId: invoiceData.id,
610
664
  invoiceNumber: invoiceNumber,
@@ -624,7 +678,12 @@ ${
624
678
  });
625
679
  } catch (error) {
626
680
  console.error('[invoice] Generation threw:', error && error.stack ? error.stack : error);
627
- res.status(500).json({ success: false, error: error.message || 'Failed to generate invoice' });
681
+ ${
682
+ emailEnabled
683
+ ? ` await sentEmailLog.settleSentEmailLog();
684
+ `
685
+ : ''
686
+ } res.status(500).json({ success: false, error: error.message || 'Failed to generate invoice' });
628
687
  }
629
688
  };
630
689
  `
@@ -10,16 +10,29 @@ export const generateEmailSenderCode = (emailDelivery: UIDLInvoiceEmailDelivery)
10
10
  const fromName = emailDelivery.fromName || ''
11
11
  const subjectTemplate = emailDelivery.subject || 'Invoice {{invoiceNumber}}'
12
12
  const bodyTemplate = emailDelivery.body || '<p>Please find your invoice attached.</p>'
13
+ const localizedTemplates = emailDelivery.localizedTemplates || {}
13
14
 
14
15
  return `/**
15
16
  * Invoice Email Sender
16
17
  * Provider: ${emailDelivery.provider}
18
+ *
19
+ * \`sendInvoiceEmail\` is the public entry: it builds the message once, hands
20
+ * it to the provider function and records the attempt in the sent-email
21
+ * ledger. The provider function never builds the message itself, so the row
22
+ * carries exactly the subject and body that went out.
17
23
  */
18
24
 
19
25
  var pdfGenerator = require('./pdf-generator');
26
+ var sentEmailLog = require('../email/sent-email-log');
27
+ var emailLocale = require('../email/email-locale');
20
28
  var replacePlaceholders = pdfGenerator.replacePlaceholders;
21
29
 
22
30
  var SECRET_KEYS = ${secretKeysJson};
31
+ var SUBJECT_TEMPLATE = ${JSON.stringify(subjectTemplate)};
32
+ var BODY_TEMPLATE = ${JSON.stringify(bodyTemplate)};
33
+ // Per-language copies of the subject/body (main language excluded), chosen by
34
+ // the locale the generate route resolved for the invoice (the order's).
35
+ var LOCALIZED_TEMPLATES = ${JSON.stringify(localizedTemplates)};
23
36
 
24
37
  function resolveSecretKey(keyName) {
25
38
  var envName = SECRET_KEYS[keyName];
@@ -30,16 +43,62 @@ function resolveSecretKey(keyName) {
30
43
 
31
44
  function buildEmailData(invoiceData) {
32
45
  var data = pdfGenerator.buildDataContext(invoiceData);
46
+ var copy = emailLocale.pickLocalizedTemplate(
47
+ { subject: SUBJECT_TEMPLATE, body: BODY_TEMPLATE },
48
+ LOCALIZED_TEMPLATES,
49
+ invoiceData.locale
50
+ );
33
51
  return {
34
- subject: replacePlaceholders(${JSON.stringify(subjectTemplate)}, data),
35
- body: replacePlaceholders(${JSON.stringify(bodyTemplate)}, data),
52
+ subject: replacePlaceholders(copy.subject, data),
53
+ body: replacePlaceholders(copy.body, data),
36
54
  to: invoiceData.customerEmail || '',
37
55
  from: ${JSON.stringify(fromName ? `${fromName} <${fromEmail}>` : fromEmail)},
56
+ templateData: data,
38
57
  };
39
58
  }
40
59
 
60
+ function attachmentName(invoiceData) {
61
+ return (invoiceData.invoiceNumber || 'invoice') + '.pdf';
62
+ }
63
+
41
64
  ${generateProviderSendFunction(emailDelivery.provider)}
42
65
 
66
+ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
67
+ var emailData = buildEmailData(invoiceData);
68
+ if (!emailData.to) return { success: false, error: 'No customer email provided' };
69
+ var result;
70
+ try {
71
+ result = await sendInvoiceEmailWithProvider(emailData, invoiceData, pdfBuffer);
72
+ } catch (err) {
73
+ result = { success: false, error: err && err.message ? err.message : String(err) };
74
+ }
75
+ sentEmailLog.recordSentEmail({
76
+ emailType: 'invoice-email',
77
+ audience: 'customer',
78
+ to: emailData.to,
79
+ from: emailData.from,
80
+ subject: emailData.subject,
81
+ html: emailData.body,
82
+ payload: emailData.templateData,
83
+ attachments: [{
84
+ filename: attachmentName(invoiceData),
85
+ contentType: 'application/pdf',
86
+ sizeBytes: pdfBuffer && pdfBuffer.length ? pdfBuffer.length : null,
87
+ url: invoiceData.pdfUrl || null,
88
+ }],
89
+ provider: ${JSON.stringify(emailDelivery.provider)},
90
+ providerMessageId: result && result.messageId,
91
+ status: result && result.success ? 'sent' : 'failed',
92
+ error: result && !result.success ? result.error : null,
93
+ source: 'invoice',
94
+ sourceRef: 'api/invoices/generate',
95
+ orderId: invoiceData.orderId,
96
+ referenceType: 'invoice',
97
+ referenceId: invoiceData.id,
98
+ });
99
+ return result;
100
+ }
101
+
43
102
  module.exports = { sendInvoiceEmail };
44
103
  `
45
104
  }
@@ -48,22 +107,19 @@ function generateProviderSendFunction(provider: string): string {
48
107
  switch (provider) {
49
108
  case 'resend':
50
109
  return `
51
- async function sendInvoiceEmail(invoiceData, pdfBuffer) {
110
+ async function sendInvoiceEmailWithProvider(emailData, invoiceData, pdfBuffer) {
52
111
  try {
53
112
  var Resend = require('resend').Resend;
54
113
  var apiKey = resolveSecretKey('apiKey');
55
114
  if (!apiKey) return { success: false, error: 'Resend API key not configured' };
56
115
  var resend = new Resend(apiKey);
57
- var emailData = buildEmailData(invoiceData);
58
- if (!emailData.to) return { success: false, error: 'No customer email provided' };
59
-
60
116
  var payload = {
61
117
  from: emailData.from,
62
118
  to: [emailData.to],
63
119
  subject: emailData.subject,
64
120
  html: emailData.body,
65
121
  attachments: [{
66
- filename: (invoiceData.invoiceNumber || 'invoice') + '.pdf',
122
+ filename: attachmentName(invoiceData),
67
123
  content: pdfBuffer.toString('base64'),
68
124
  }],
69
125
  };
@@ -77,15 +133,12 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
77
133
 
78
134
  case 'sendgrid':
79
135
  return `
80
- async function sendInvoiceEmail(invoiceData, pdfBuffer) {
136
+ async function sendInvoiceEmailWithProvider(emailData, invoiceData, pdfBuffer) {
81
137
  try {
82
138
  var sgMail = require('@sendgrid/mail');
83
139
  var apiKey = resolveSecretKey('apiKey');
84
140
  if (!apiKey) return { success: false, error: 'SendGrid API key not configured' };
85
141
  sgMail.setApiKey(apiKey);
86
- var emailData = buildEmailData(invoiceData);
87
- if (!emailData.to) return { success: false, error: 'No customer email provided' };
88
-
89
142
  var msg = {
90
143
  to: emailData.to,
91
144
  from: emailData.from,
@@ -93,7 +146,7 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
93
146
  html: emailData.body,
94
147
  attachments: [{
95
148
  content: pdfBuffer.toString('base64'),
96
- filename: (invoiceData.invoiceNumber || 'invoice') + '.pdf',
149
+ filename: attachmentName(invoiceData),
97
150
  type: 'application/pdf',
98
151
  disposition: 'attachment',
99
152
  }],
@@ -107,7 +160,7 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
107
160
 
108
161
  case 'mailgun':
109
162
  return `
110
- async function sendInvoiceEmail(invoiceData, pdfBuffer) {
163
+ async function sendInvoiceEmailWithProvider(emailData, invoiceData, pdfBuffer) {
111
164
  try {
112
165
  var Mailgun = require('mailgun.js');
113
166
  var formData = require('form-data');
@@ -118,9 +171,6 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
118
171
 
119
172
  var mailgun = new Mailgun(formData);
120
173
  var mg = mailgun.client({ username: 'api', key: apiKey });
121
- var emailData = buildEmailData(invoiceData);
122
- if (!emailData.to) return { success: false, error: 'No customer email provided' };
123
-
124
174
  var msg = {
125
175
  from: emailData.from,
126
176
  to: [emailData.to],
@@ -128,7 +178,7 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
128
178
  html: emailData.body,
129
179
  attachment: [{
130
180
  data: pdfBuffer,
131
- filename: (invoiceData.invoiceNumber || 'invoice') + '.pdf',
181
+ filename: attachmentName(invoiceData),
132
182
  contentType: 'application/pdf',
133
183
  }],
134
184
  };
@@ -141,22 +191,19 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
141
191
 
142
192
  case 'postmark':
143
193
  return `
144
- async function sendInvoiceEmail(invoiceData, pdfBuffer) {
194
+ async function sendInvoiceEmailWithProvider(emailData, invoiceData, pdfBuffer) {
145
195
  try {
146
196
  var postmark = require('postmark');
147
197
  var serverToken = resolveSecretKey('serverToken');
148
198
  if (!serverToken) return { success: false, error: 'Postmark server token not configured' };
149
199
  var client = new postmark.ServerClient(serverToken);
150
- var emailData = buildEmailData(invoiceData);
151
- if (!emailData.to) return { success: false, error: 'No customer email provided' };
152
-
153
200
  var msg = {
154
201
  From: emailData.from,
155
202
  To: emailData.to,
156
203
  Subject: emailData.subject,
157
204
  HtmlBody: emailData.body,
158
205
  Attachments: [{
159
- Name: (invoiceData.invoiceNumber || 'invoice') + '.pdf',
206
+ Name: attachmentName(invoiceData),
160
207
  Content: pdfBuffer.toString('base64'),
161
208
  ContentType: 'application/pdf',
162
209
  }],
@@ -190,7 +237,7 @@ function parseFromString(from) {
190
237
  return { name: '', email: str };
191
238
  }
192
239
 
193
- async function sendInvoiceEmail(invoiceData, pdfBuffer) {
240
+ async function sendInvoiceEmailWithProvider(emailData, invoiceData, pdfBuffer) {
194
241
  var invoiceNumber = invoiceData && invoiceData.invoiceNumber ? invoiceData.invoiceNumber : '(no number)';
195
242
  try {
196
243
  console.info('[invoice-email][mailersend] begin — invoice=' + invoiceNumber +
@@ -201,12 +248,6 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
201
248
  console.error('[invoice-email][mailersend] skip — API key not configured (set \`apiKey\` secret or INVOICE_MAILERSEND_APIKEY env)');
202
249
  return { success: false, error: 'MailerSend API key not configured' };
203
250
  }
204
- var emailData = buildEmailData(invoiceData);
205
- if (!emailData.to) {
206
- console.error('[invoice-email][mailersend] skip — invoiceData.customerEmail is empty (order hydrating yielded no billing_email; set it on the order row or pass customerEmail in the generate payload)');
207
- return { success: false, error: 'No customer email provided' };
208
- }
209
-
210
251
  var MailerSend = require('mailersend').MailerSend;
211
252
  var EmailParams = require('mailersend').EmailParams;
212
253
  var Sender = require('mailersend').Sender;
@@ -224,7 +265,7 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
224
265
 
225
266
  var attachment = new Attachment(
226
267
  pdfBuffer.toString('base64'),
227
- (invoiceData.invoiceNumber || 'invoice') + '.pdf',
268
+ attachmentName(invoiceData),
228
269
  'attachment'
229
270
  );
230
271
 
@@ -267,7 +308,7 @@ async function sendInvoiceEmail(invoiceData, pdfBuffer) {
267
308
 
268
309
  default:
269
310
  return `
270
- async function sendInvoiceEmail() {
311
+ async function sendInvoiceEmailWithProvider() {
271
312
  return { success: false, error: 'Unsupported email provider: ${provider}' };
272
313
  }`
273
314
  }
@@ -9,6 +9,8 @@ import { generateEmailSenderCode, getEmailProviderDependencies } from './email-s
9
9
  import { generateDataAccessCode, getRecordMappingCode } from './data-access-code'
10
10
  import { generateInvoiceGenerateRouteCode, generateInvoicePdfRouteCode } from './api-routes-code'
11
11
  import { getDatabaseDriverDependencies } from '../auth-generator'
12
+ import { ensureSentEmailLogModule } from '../sent-email-log'
13
+ import { ensureEmailLocaleModule } from '../email-locale'
12
14
 
13
15
  export const generateInvoiceFiles = (
14
16
  invoiceSettings: UIDLInvoiceSettings,
@@ -67,6 +69,10 @@ export const generateInvoiceFiles = (
67
69
  })
68
70
 
69
71
  if (invoiceSettings.emailDelivery?.enabled) {
72
+ // The sender records every attempt in the sent-email ledger and picks the
73
+ // buyer's language through the shared locale module.
74
+ ensureSentEmailLogModule(structure)
75
+ ensureEmailLocaleModule(structure)
70
76
  const emailSenderCode = generateEmailSenderCode(invoiceSettings.emailDelivery)
71
77
  files.set('invoice-email-sender', {
72
78
  path: ['utils', 'invoices'],
@@ -156,26 +162,4 @@ export const generateInvoiceFiles = (
156
162
  }
157
163
  }
158
164
 
159
- export const resolveInvoiceDataSource = (
160
- structure: ProjectPluginStructure
161
- ): { dataSourceType: DataSourceType | null; dataSourceConfig: Record<string, unknown> | null } => {
162
- const { uidl } = structure
163
-
164
- if (!uidl.dataSources) {
165
- return { dataSourceType: null, dataSourceConfig: null }
166
- }
167
-
168
- if (uidl.authentication?.dataSourceId) {
169
- const ds = uidl.dataSources[uidl.authentication.dataSourceId]
170
- if (ds) {
171
- return { dataSourceType: ds.type, dataSourceConfig: ds.config }
172
- }
173
- }
174
-
175
- const dsEntries = Object.values(uidl.dataSources)
176
- if (dsEntries.length > 0) {
177
- return { dataSourceType: dsEntries[0].type, dataSourceConfig: dsEntries[0].config }
178
- }
179
-
180
- return { dataSourceType: null, dataSourceConfig: null }
181
- }
165
+ export { resolveInvoiceDataSource } from './resolve-data-source'