sendwend 0.0.1 → 12.7.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 (684) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2065 -22
  3. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  4. package/dist/apns-relay.cjs +91 -0
  5. package/dist/apns-relay.cjs.map +1 -0
  6. package/dist/apns-relay.d.cts +26 -0
  7. package/dist/apns-relay.d.cts.map +1 -0
  8. package/dist/apns-relay.d.mts +26 -0
  9. package/dist/apns-relay.d.mts.map +1 -0
  10. package/dist/apns-relay.mjs +90 -0
  11. package/dist/apns-relay.mjs.map +1 -0
  12. package/dist/apns.cjs +215 -0
  13. package/dist/apns.cjs.map +1 -0
  14. package/dist/apns.d.cts +110 -0
  15. package/dist/apns.d.cts.map +1 -0
  16. package/dist/apns.d.mts +110 -0
  17. package/dist/apns.d.mts.map +1 -0
  18. package/dist/apns.mjs +207 -0
  19. package/dist/apns.mjs.map +1 -0
  20. package/dist/aws/engine-step.cjs +105 -0
  21. package/dist/aws/engine-step.cjs.map +1 -0
  22. package/dist/aws/engine-step.d.cts +42 -0
  23. package/dist/aws/engine-step.d.cts.map +1 -0
  24. package/dist/aws/engine-step.d.mts +42 -0
  25. package/dist/aws/engine-step.d.mts.map +1 -0
  26. package/dist/aws/engine-step.mjs +103 -0
  27. package/dist/aws/engine-step.mjs.map +1 -0
  28. package/dist/aws/function-url.cjs +53 -0
  29. package/dist/aws/function-url.cjs.map +1 -0
  30. package/dist/aws/function-url.d.cts +36 -0
  31. package/dist/aws/function-url.d.cts.map +1 -0
  32. package/dist/aws/function-url.d.mts +36 -0
  33. package/dist/aws/function-url.d.mts.map +1 -0
  34. package/dist/aws/function-url.mjs +50 -0
  35. package/dist/aws/function-url.mjs.map +1 -0
  36. package/dist/aws/index.cjs +232 -0
  37. package/dist/aws/index.cjs.map +1 -0
  38. package/dist/aws/index.d.cts +73 -0
  39. package/dist/aws/index.d.cts.map +1 -0
  40. package/dist/aws/index.d.mts +73 -0
  41. package/dist/aws/index.d.mts.map +1 -0
  42. package/dist/aws/index.mjs +218 -0
  43. package/dist/aws/index.mjs.map +1 -0
  44. package/dist/aws/instances.cjs +218 -0
  45. package/dist/aws/instances.cjs.map +1 -0
  46. package/dist/aws/instances.d.cts +102 -0
  47. package/dist/aws/instances.d.cts.map +1 -0
  48. package/dist/aws/instances.d.mts +102 -0
  49. package/dist/aws/instances.d.mts.map +1 -0
  50. package/dist/aws/instances.mjs +214 -0
  51. package/dist/aws/instances.mjs.map +1 -0
  52. package/dist/aws/lambda-api.cjs +86 -0
  53. package/dist/aws/lambda-api.cjs.map +1 -0
  54. package/dist/aws/lambda-api.d.cts +41 -0
  55. package/dist/aws/lambda-api.d.cts.map +1 -0
  56. package/dist/aws/lambda-api.d.mts +41 -0
  57. package/dist/aws/lambda-api.d.mts.map +1 -0
  58. package/dist/aws/lambda-api.mjs +85 -0
  59. package/dist/aws/lambda-api.mjs.map +1 -0
  60. package/dist/client.cjs +216 -0
  61. package/dist/client.cjs.map +1 -0
  62. package/dist/client.d.cts +193 -0
  63. package/dist/client.d.cts.map +1 -0
  64. package/dist/client.d.mts +193 -0
  65. package/dist/client.d.mts.map +1 -0
  66. package/dist/client.mjs +212 -0
  67. package/dist/client.mjs.map +1 -0
  68. package/dist/cloudflare/bindings.cjs +49 -0
  69. package/dist/cloudflare/bindings.cjs.map +1 -0
  70. package/dist/cloudflare/bindings.d.cts +31 -0
  71. package/dist/cloudflare/bindings.d.cts.map +1 -0
  72. package/dist/cloudflare/bindings.d.mts +31 -0
  73. package/dist/cloudflare/bindings.d.mts.map +1 -0
  74. package/dist/cloudflare/bindings.mjs +46 -0
  75. package/dist/cloudflare/bindings.mjs.map +1 -0
  76. package/dist/cloudflare/index.cjs +73 -0
  77. package/dist/cloudflare/index.d.cts +25 -0
  78. package/dist/cloudflare/index.d.mts +25 -0
  79. package/dist/cloudflare/index.mjs +20 -0
  80. package/dist/cloudflare/runner.cjs +200 -0
  81. package/dist/cloudflare/runner.cjs.map +1 -0
  82. package/dist/cloudflare/runner.d.cts +83 -0
  83. package/dist/cloudflare/runner.d.cts.map +1 -0
  84. package/dist/cloudflare/runner.d.mts +83 -0
  85. package/dist/cloudflare/runner.d.mts.map +1 -0
  86. package/dist/cloudflare/runner.mjs +199 -0
  87. package/dist/cloudflare/runner.mjs.map +1 -0
  88. package/dist/cloudflare/worker.cjs +106 -0
  89. package/dist/cloudflare/worker.cjs.map +1 -0
  90. package/dist/cloudflare/worker.d.cts +52 -0
  91. package/dist/cloudflare/worker.d.cts.map +1 -0
  92. package/dist/cloudflare/worker.d.mts +52 -0
  93. package/dist/cloudflare/worker.d.mts.map +1 -0
  94. package/dist/cloudflare/worker.mjs +104 -0
  95. package/dist/cloudflare/worker.mjs.map +1 -0
  96. package/dist/cloudflare/workers.d.cjs +0 -0
  97. package/dist/cloudflare/workers.d.cts +42 -0
  98. package/dist/cloudflare/workers.d.cts.map +1 -0
  99. package/dist/cloudflare/workers.d.mts +42 -0
  100. package/dist/cloudflare/workers.d.mts.map +1 -0
  101. package/dist/config.cjs +257 -0
  102. package/dist/config.cjs.map +1 -0
  103. package/dist/config.d.cts +184 -0
  104. package/dist/config.d.cts.map +1 -0
  105. package/dist/config.d.mts +184 -0
  106. package/dist/config.d.mts.map +1 -0
  107. package/dist/config.mjs +246 -0
  108. package/dist/config.mjs.map +1 -0
  109. package/dist/contract.cjs +222 -0
  110. package/dist/contract.cjs.map +1 -0
  111. package/dist/contract.d.cts +110 -0
  112. package/dist/contract.d.cts.map +1 -0
  113. package/dist/contract.d.mts +110 -0
  114. package/dist/contract.d.mts.map +1 -0
  115. package/dist/contract.mjs +216 -0
  116. package/dist/contract.mjs.map +1 -0
  117. package/dist/date-time.cjs +22 -0
  118. package/dist/date-time.cjs.map +1 -0
  119. package/dist/date-time.d.cts +10 -0
  120. package/dist/date-time.d.cts.map +1 -0
  121. package/dist/date-time.d.mts +10 -0
  122. package/dist/date-time.d.mts.map +1 -0
  123. package/dist/date-time.mjs +21 -0
  124. package/dist/date-time.mjs.map +1 -0
  125. package/dist/dsl/action.cjs +25 -0
  126. package/dist/dsl/action.cjs.map +1 -0
  127. package/dist/dsl/action.d.cts +63 -0
  128. package/dist/dsl/action.d.cts.map +1 -0
  129. package/dist/dsl/action.d.mts +63 -0
  130. package/dist/dsl/action.d.mts.map +1 -0
  131. package/dist/dsl/action.mjs +24 -0
  132. package/dist/dsl/action.mjs.map +1 -0
  133. package/dist/dsl/base.cjs +33 -0
  134. package/dist/dsl/base.cjs.map +1 -0
  135. package/dist/dsl/base.d.cts +43 -0
  136. package/dist/dsl/base.d.cts.map +1 -0
  137. package/dist/dsl/base.d.mts +43 -0
  138. package/dist/dsl/base.d.mts.map +1 -0
  139. package/dist/dsl/base.mjs +29 -0
  140. package/dist/dsl/base.mjs.map +1 -0
  141. package/dist/dsl/bundle.cjs +287 -0
  142. package/dist/dsl/bundle.cjs.map +1 -0
  143. package/dist/dsl/bundle.d.cts +33 -0
  144. package/dist/dsl/bundle.d.cts.map +1 -0
  145. package/dist/dsl/bundle.d.mts +33 -0
  146. package/dist/dsl/bundle.d.mts.map +1 -0
  147. package/dist/dsl/bundle.mjs +284 -0
  148. package/dist/dsl/bundle.mjs.map +1 -0
  149. package/dist/dsl/condition.cjs +200 -0
  150. package/dist/dsl/condition.cjs.map +1 -0
  151. package/dist/dsl/condition.d.cts +151 -0
  152. package/dist/dsl/condition.d.cts.map +1 -0
  153. package/dist/dsl/condition.d.mts +151 -0
  154. package/dist/dsl/condition.d.mts.map +1 -0
  155. package/dist/dsl/condition.mjs +178 -0
  156. package/dist/dsl/condition.mjs.map +1 -0
  157. package/dist/dsl/flow.cjs +335 -0
  158. package/dist/dsl/flow.cjs.map +1 -0
  159. package/dist/dsl/flow.d.cts +278 -0
  160. package/dist/dsl/flow.d.cts.map +1 -0
  161. package/dist/dsl/flow.d.mts +278 -0
  162. package/dist/dsl/flow.d.mts.map +1 -0
  163. package/dist/dsl/flow.mjs +331 -0
  164. package/dist/dsl/flow.mjs.map +1 -0
  165. package/dist/dsl/index.cjs +37 -0
  166. package/dist/dsl/index.d.cts +34 -0
  167. package/dist/dsl/index.d.mts +34 -0
  168. package/dist/dsl/index.mjs +9 -0
  169. package/dist/dsl/refs.cjs +101 -0
  170. package/dist/dsl/refs.cjs.map +1 -0
  171. package/dist/dsl/refs.d.cts +127 -0
  172. package/dist/dsl/refs.d.cts.map +1 -0
  173. package/dist/dsl/refs.d.mts +127 -0
  174. package/dist/dsl/refs.d.mts.map +1 -0
  175. package/dist/dsl/refs.mjs +93 -0
  176. package/dist/dsl/refs.mjs.map +1 -0
  177. package/dist/dsl/template.cjs +19 -0
  178. package/dist/dsl/template.cjs.map +1 -0
  179. package/dist/dsl/template.d.cts +30 -0
  180. package/dist/dsl/template.d.cts.map +1 -0
  181. package/dist/dsl/template.d.mts +30 -0
  182. package/dist/dsl/template.d.mts.map +1 -0
  183. package/dist/dsl/template.mjs +18 -0
  184. package/dist/dsl/template.mjs.map +1 -0
  185. package/dist/dsl/trigger.cjs +53 -0
  186. package/dist/dsl/trigger.cjs.map +1 -0
  187. package/dist/dsl/trigger.d.cts +112 -0
  188. package/dist/dsl/trigger.d.cts.map +1 -0
  189. package/dist/dsl/trigger.d.mts +112 -0
  190. package/dist/dsl/trigger.d.mts.map +1 -0
  191. package/dist/dsl/trigger.mjs +52 -0
  192. package/dist/dsl/trigger.mjs.map +1 -0
  193. package/dist/dsl/workflow.cjs +143 -0
  194. package/dist/dsl/workflow.cjs.map +1 -0
  195. package/dist/dsl/workflow.d.cts +88 -0
  196. package/dist/dsl/workflow.d.cts.map +1 -0
  197. package/dist/dsl/workflow.d.mts +88 -0
  198. package/dist/dsl/workflow.d.mts.map +1 -0
  199. package/dist/dsl/workflow.mjs +142 -0
  200. package/dist/dsl/workflow.mjs.map +1 -0
  201. package/dist/email-context.cjs +28 -0
  202. package/dist/email-context.cjs.map +1 -0
  203. package/dist/email-context.d.cts +9 -0
  204. package/dist/email-context.d.cts.map +1 -0
  205. package/dist/email-context.d.mts +9 -0
  206. package/dist/email-context.d.mts.map +1 -0
  207. package/dist/email-context.mjs +26 -0
  208. package/dist/email-context.mjs.map +1 -0
  209. package/dist/email-sender.cjs +93 -0
  210. package/dist/email-sender.cjs.map +1 -0
  211. package/dist/email-sender.d.cts +88 -0
  212. package/dist/email-sender.d.cts.map +1 -0
  213. package/dist/email-sender.d.mts +88 -0
  214. package/dist/email-sender.d.mts.map +1 -0
  215. package/dist/email-sender.mjs +90 -0
  216. package/dist/email-sender.mjs.map +1 -0
  217. package/dist/email.cjs +73 -0
  218. package/dist/email.cjs.map +1 -0
  219. package/dist/email.d.cts +59 -0
  220. package/dist/email.d.cts.map +1 -0
  221. package/dist/email.d.mts +59 -0
  222. package/dist/email.d.mts.map +1 -0
  223. package/dist/email.mjs +68 -0
  224. package/dist/email.mjs.map +1 -0
  225. package/dist/engine/actions.cjs +19 -0
  226. package/dist/engine/actions.cjs.map +1 -0
  227. package/dist/engine/actions.d.cts +27 -0
  228. package/dist/engine/actions.d.cts.map +1 -0
  229. package/dist/engine/actions.d.mts +27 -0
  230. package/dist/engine/actions.d.mts.map +1 -0
  231. package/dist/engine/actions.mjs +18 -0
  232. package/dist/engine/actions.mjs.map +1 -0
  233. package/dist/engine/bucket.cjs +71 -0
  234. package/dist/engine/bucket.cjs.map +1 -0
  235. package/dist/engine/bucket.d.cts +30 -0
  236. package/dist/engine/bucket.d.cts.map +1 -0
  237. package/dist/engine/bucket.d.mts +30 -0
  238. package/dist/engine/bucket.d.mts.map +1 -0
  239. package/dist/engine/bucket.mjs +68 -0
  240. package/dist/engine/bucket.mjs.map +1 -0
  241. package/dist/engine/condition.cjs +199 -0
  242. package/dist/engine/condition.cjs.map +1 -0
  243. package/dist/engine/condition.d.cts +76 -0
  244. package/dist/engine/condition.d.cts.map +1 -0
  245. package/dist/engine/condition.d.mts +76 -0
  246. package/dist/engine/condition.d.mts.map +1 -0
  247. package/dist/engine/condition.mjs +192 -0
  248. package/dist/engine/condition.mjs.map +1 -0
  249. package/dist/engine/duration.cjs +33 -0
  250. package/dist/engine/duration.cjs.map +1 -0
  251. package/dist/engine/duration.d.cts +3 -0
  252. package/dist/engine/duration.d.cts.map +1 -0
  253. package/dist/engine/duration.d.mts +3 -0
  254. package/dist/engine/duration.d.mts.map +1 -0
  255. package/dist/engine/duration.mjs +32 -0
  256. package/dist/engine/duration.mjs.map +1 -0
  257. package/dist/engine/index.cjs +33 -0
  258. package/dist/engine/index.d.cts +10 -0
  259. package/dist/engine/index.d.mts +10 -0
  260. package/dist/engine/index.mjs +9 -0
  261. package/dist/engine/interpreter.cjs +613 -0
  262. package/dist/engine/interpreter.cjs.map +1 -0
  263. package/dist/engine/interpreter.d.cts +4 -0
  264. package/dist/engine/interpreter.d.cts.map +1 -0
  265. package/dist/engine/interpreter.d.mts +4 -0
  266. package/dist/engine/interpreter.d.mts.map +1 -0
  267. package/dist/engine/interpreter.mjs +612 -0
  268. package/dist/engine/interpreter.mjs.map +1 -0
  269. package/dist/engine/ports.cjs +0 -0
  270. package/dist/engine/ports.d.cts +373 -0
  271. package/dist/engine/ports.d.cts.map +1 -0
  272. package/dist/engine/ports.d.mts +373 -0
  273. package/dist/engine/ports.d.mts.map +1 -0
  274. package/dist/engine/ports.mjs +1 -0
  275. package/dist/engine/recipient.cjs +22 -0
  276. package/dist/engine/recipient.cjs.map +1 -0
  277. package/dist/engine/recipient.d.cts +11 -0
  278. package/dist/engine/recipient.d.cts.map +1 -0
  279. package/dist/engine/recipient.d.mts +11 -0
  280. package/dist/engine/recipient.d.mts.map +1 -0
  281. package/dist/engine/recipient.mjs +21 -0
  282. package/dist/engine/recipient.mjs.map +1 -0
  283. package/dist/engine/retry.cjs +106 -0
  284. package/dist/engine/retry.cjs.map +1 -0
  285. package/dist/engine/retry.d.cts +73 -0
  286. package/dist/engine/retry.d.cts.map +1 -0
  287. package/dist/engine/retry.d.mts +73 -0
  288. package/dist/engine/retry.d.mts.map +1 -0
  289. package/dist/engine/retry.mjs +98 -0
  290. package/dist/engine/retry.mjs.map +1 -0
  291. package/dist/engine/time-scale.cjs +153 -0
  292. package/dist/engine/time-scale.cjs.map +1 -0
  293. package/dist/engine/time-scale.d.cts +41 -0
  294. package/dist/engine/time-scale.d.cts.map +1 -0
  295. package/dist/engine/time-scale.d.mts +41 -0
  296. package/dist/engine/time-scale.d.mts.map +1 -0
  297. package/dist/engine/time-scale.mjs +150 -0
  298. package/dist/engine/time-scale.mjs.map +1 -0
  299. package/dist/engine/time-window.cjs +148 -0
  300. package/dist/engine/time-window.cjs.map +1 -0
  301. package/dist/engine/time-window.d.cts +20 -0
  302. package/dist/engine/time-window.d.cts.map +1 -0
  303. package/dist/engine/time-window.d.mts +20 -0
  304. package/dist/engine/time-window.d.mts.map +1 -0
  305. package/dist/engine/time-window.mjs +146 -0
  306. package/dist/engine/time-window.mjs.map +1 -0
  307. package/dist/fcm.cjs +208 -0
  308. package/dist/fcm.cjs.map +1 -0
  309. package/dist/fcm.d.cts +89 -0
  310. package/dist/fcm.d.cts.map +1 -0
  311. package/dist/fcm.d.mts +89 -0
  312. package/dist/fcm.d.mts.map +1 -0
  313. package/dist/fcm.mjs +202 -0
  314. package/dist/fcm.mjs.map +1 -0
  315. package/dist/hash.cjs +244 -0
  316. package/dist/hash.cjs.map +1 -0
  317. package/dist/hash.d.cts +28 -0
  318. package/dist/hash.d.cts.map +1 -0
  319. package/dist/hash.d.mts +28 -0
  320. package/dist/hash.d.mts.map +1 -0
  321. package/dist/hash.mjs +238 -0
  322. package/dist/hash.mjs.map +1 -0
  323. package/dist/host/auth.cjs +48 -0
  324. package/dist/host/auth.cjs.map +1 -0
  325. package/dist/host/auth.d.cts +33 -0
  326. package/dist/host/auth.d.cts.map +1 -0
  327. package/dist/host/auth.d.mts +33 -0
  328. package/dist/host/auth.d.mts.map +1 -0
  329. package/dist/host/auth.mjs +45 -0
  330. package/dist/host/auth.mjs.map +1 -0
  331. package/dist/host/batch.cjs +178 -0
  332. package/dist/host/batch.cjs.map +1 -0
  333. package/dist/host/batch.d.cts +92 -0
  334. package/dist/host/batch.d.cts.map +1 -0
  335. package/dist/host/batch.d.mts +92 -0
  336. package/dist/host/batch.d.mts.map +1 -0
  337. package/dist/host/batch.mjs +169 -0
  338. package/dist/host/batch.mjs.map +1 -0
  339. package/dist/host/channels.cjs +256 -0
  340. package/dist/host/channels.cjs.map +1 -0
  341. package/dist/host/channels.d.cts +66 -0
  342. package/dist/host/channels.d.cts.map +1 -0
  343. package/dist/host/channels.d.mts +66 -0
  344. package/dist/host/channels.d.mts.map +1 -0
  345. package/dist/host/channels.mjs +252 -0
  346. package/dist/host/channels.mjs.map +1 -0
  347. package/dist/host/execute.cjs +102 -0
  348. package/dist/host/execute.cjs.map +1 -0
  349. package/dist/host/execute.d.cts +38 -0
  350. package/dist/host/execute.d.cts.map +1 -0
  351. package/dist/host/execute.d.mts +38 -0
  352. package/dist/host/execute.d.mts.map +1 -0
  353. package/dist/host/execute.mjs +101 -0
  354. package/dist/host/execute.mjs.map +1 -0
  355. package/dist/host/fresh-read.cjs +29 -0
  356. package/dist/host/fresh-read.cjs.map +1 -0
  357. package/dist/host/fresh-read.d.cts +16 -0
  358. package/dist/host/fresh-read.d.cts.map +1 -0
  359. package/dist/host/fresh-read.d.mts +16 -0
  360. package/dist/host/fresh-read.d.mts.map +1 -0
  361. package/dist/host/fresh-read.mjs +28 -0
  362. package/dist/host/fresh-read.mjs.map +1 -0
  363. package/dist/host/http.cjs +393 -0
  364. package/dist/host/http.cjs.map +1 -0
  365. package/dist/host/http.d.cts +61 -0
  366. package/dist/host/http.d.cts.map +1 -0
  367. package/dist/host/http.d.mts +61 -0
  368. package/dist/host/http.d.mts.map +1 -0
  369. package/dist/host/http.mjs +389 -0
  370. package/dist/host/http.mjs.map +1 -0
  371. package/dist/host/ingest.cjs +1210 -0
  372. package/dist/host/ingest.cjs.map +1 -0
  373. package/dist/host/ingest.d.cts +497 -0
  374. package/dist/host/ingest.d.cts.map +1 -0
  375. package/dist/host/ingest.d.mts +497 -0
  376. package/dist/host/ingest.d.mts.map +1 -0
  377. package/dist/host/ingest.mjs +1172 -0
  378. package/dist/host/ingest.mjs.map +1 -0
  379. package/dist/host/journey-host.cjs +223 -0
  380. package/dist/host/journey-host.cjs.map +1 -0
  381. package/dist/host/journey-host.d.cts +118 -0
  382. package/dist/host/journey-host.d.cts.map +1 -0
  383. package/dist/host/journey-host.d.mts +118 -0
  384. package/dist/host/journey-host.d.mts.map +1 -0
  385. package/dist/host/journey-host.mjs +219 -0
  386. package/dist/host/journey-host.mjs.map +1 -0
  387. package/dist/host/platform.cjs +20 -0
  388. package/dist/host/platform.cjs.map +1 -0
  389. package/dist/host/platform.d.cts +120 -0
  390. package/dist/host/platform.d.cts.map +1 -0
  391. package/dist/host/platform.d.mts +120 -0
  392. package/dist/host/platform.d.mts.map +1 -0
  393. package/dist/host/platform.mjs +18 -0
  394. package/dist/host/platform.mjs.map +1 -0
  395. package/dist/host/senders.cjs +71 -0
  396. package/dist/host/senders.cjs.map +1 -0
  397. package/dist/host/senders.d.cts +34 -0
  398. package/dist/host/senders.d.cts.map +1 -0
  399. package/dist/host/senders.d.mts +34 -0
  400. package/dist/host/senders.d.mts.map +1 -0
  401. package/dist/host/senders.mjs +67 -0
  402. package/dist/host/senders.mjs.map +1 -0
  403. package/dist/host/workflow-cache.cjs +47 -0
  404. package/dist/host/workflow-cache.cjs.map +1 -0
  405. package/dist/host/workflow-cache.d.cts +21 -0
  406. package/dist/host/workflow-cache.d.cts.map +1 -0
  407. package/dist/host/workflow-cache.d.mts +21 -0
  408. package/dist/host/workflow-cache.d.mts.map +1 -0
  409. package/dist/host/workflow-cache.mjs +46 -0
  410. package/dist/host/workflow-cache.mjs.map +1 -0
  411. package/dist/http2-client.cjs +89 -0
  412. package/dist/http2-client.cjs.map +1 -0
  413. package/dist/http2-client.d.cts +45 -0
  414. package/dist/http2-client.d.cts.map +1 -0
  415. package/dist/http2-client.d.mts +45 -0
  416. package/dist/http2-client.d.mts.map +1 -0
  417. package/dist/http2-client.mjs +87 -0
  418. package/dist/http2-client.mjs.map +1 -0
  419. package/dist/index.cjs +130 -0
  420. package/dist/index.d.cts +21 -0
  421. package/dist/index.d.mts +21 -0
  422. package/dist/index.mjs +20 -0
  423. package/dist/inflight.cjs +116 -0
  424. package/dist/inflight.cjs.map +1 -0
  425. package/dist/inflight.d.cts +49 -0
  426. package/dist/inflight.d.cts.map +1 -0
  427. package/dist/inflight.d.mts +49 -0
  428. package/dist/inflight.d.mts.map +1 -0
  429. package/dist/inflight.mjs +113 -0
  430. package/dist/inflight.mjs.map +1 -0
  431. package/dist/ir.cjs +429 -0
  432. package/dist/ir.cjs.map +1 -0
  433. package/dist/ir.d.cts +593 -0
  434. package/dist/ir.d.cts.map +1 -0
  435. package/dist/ir.d.mts +593 -0
  436. package/dist/ir.d.mts.map +1 -0
  437. package/dist/ir.mjs +404 -0
  438. package/dist/ir.mjs.map +1 -0
  439. package/dist/jwt.cjs +17 -0
  440. package/dist/jwt.cjs.map +1 -0
  441. package/dist/jwt.d.cts +7 -0
  442. package/dist/jwt.d.cts.map +1 -0
  443. package/dist/jwt.d.mts +7 -0
  444. package/dist/jwt.d.mts.map +1 -0
  445. package/dist/jwt.mjs +15 -0
  446. package/dist/jwt.mjs.map +1 -0
  447. package/dist/node/index.cjs +231 -0
  448. package/dist/node/index.cjs.map +1 -0
  449. package/dist/node/index.d.cts +59 -0
  450. package/dist/node/index.d.cts.map +1 -0
  451. package/dist/node/index.d.mts +59 -0
  452. package/dist/node/index.d.mts.map +1 -0
  453. package/dist/node/index.mjs +225 -0
  454. package/dist/node/index.mjs.map +1 -0
  455. package/dist/node/runs.cjs +222 -0
  456. package/dist/node/runs.cjs.map +1 -0
  457. package/dist/node/runs.d.cts +93 -0
  458. package/dist/node/runs.d.cts.map +1 -0
  459. package/dist/node/runs.d.mts +93 -0
  460. package/dist/node/runs.d.mts.map +1 -0
  461. package/dist/node/runs.mjs +221 -0
  462. package/dist/node/runs.mjs.map +1 -0
  463. package/dist/node/runtime.cjs +351 -0
  464. package/dist/node/runtime.cjs.map +1 -0
  465. package/dist/node/runtime.d.cts +96 -0
  466. package/dist/node/runtime.d.cts.map +1 -0
  467. package/dist/node/runtime.d.mts +96 -0
  468. package/dist/node/runtime.d.mts.map +1 -0
  469. package/dist/node/runtime.mjs +348 -0
  470. package/dist/node/runtime.mjs.map +1 -0
  471. package/dist/plan.cjs +221 -0
  472. package/dist/plan.cjs.map +1 -0
  473. package/dist/plan.d.cts +68 -0
  474. package/dist/plan.d.cts.map +1 -0
  475. package/dist/plan.d.mts +68 -0
  476. package/dist/plan.d.mts.map +1 -0
  477. package/dist/plan.mjs +218 -0
  478. package/dist/plan.mjs.map +1 -0
  479. package/dist/postgres-js.cjs +51 -0
  480. package/dist/postgres-js.cjs.map +1 -0
  481. package/dist/postgres-js.d.cts +32 -0
  482. package/dist/postgres-js.d.cts.map +1 -0
  483. package/dist/postgres-js.d.mts +32 -0
  484. package/dist/postgres-js.d.mts.map +1 -0
  485. package/dist/postgres-js.mjs +46 -0
  486. package/dist/postgres-js.mjs.map +1 -0
  487. package/dist/provenance.cjs +66 -0
  488. package/dist/provenance.cjs.map +1 -0
  489. package/dist/provenance.d.cts +40 -0
  490. package/dist/provenance.d.cts.map +1 -0
  491. package/dist/provenance.d.mts +40 -0
  492. package/dist/provenance.d.mts.map +1 -0
  493. package/dist/provenance.mjs +64 -0
  494. package/dist/provenance.mjs.map +1 -0
  495. package/dist/push.cjs +11 -0
  496. package/dist/push.cjs.map +1 -0
  497. package/dist/push.d.cts +14 -0
  498. package/dist/push.d.cts.map +1 -0
  499. package/dist/push.d.mts +14 -0
  500. package/dist/push.d.mts.map +1 -0
  501. package/dist/push.mjs +10 -0
  502. package/dist/push.mjs.map +1 -0
  503. package/dist/react-email.cjs +56 -0
  504. package/dist/react-email.cjs.map +1 -0
  505. package/dist/react-email.d.cts +5 -0
  506. package/dist/react-email.d.cts.map +1 -0
  507. package/dist/react-email.d.mts +5 -0
  508. package/dist/react-email.d.mts.map +1 -0
  509. package/dist/react-email.mjs +55 -0
  510. package/dist/react-email.mjs.map +1 -0
  511. package/dist/reporting/classify.cjs +46 -0
  512. package/dist/reporting/classify.cjs.map +1 -0
  513. package/dist/reporting/classify.d.cts +65 -0
  514. package/dist/reporting/classify.d.cts.map +1 -0
  515. package/dist/reporting/classify.d.mts +65 -0
  516. package/dist/reporting/classify.d.mts.map +1 -0
  517. package/dist/reporting/classify.mjs +42 -0
  518. package/dist/reporting/classify.mjs.map +1 -0
  519. package/dist/reporting/observer.cjs +137 -0
  520. package/dist/reporting/observer.cjs.map +1 -0
  521. package/dist/reporting/observer.d.cts +31 -0
  522. package/dist/reporting/observer.d.cts.map +1 -0
  523. package/dist/reporting/observer.d.mts +31 -0
  524. package/dist/reporting/observer.d.mts.map +1 -0
  525. package/dist/reporting/observer.mjs +134 -0
  526. package/dist/reporting/observer.mjs.map +1 -0
  527. package/dist/reporting/tracking.cjs +185 -0
  528. package/dist/reporting/tracking.cjs.map +1 -0
  529. package/dist/reporting/tracking.d.cts +63 -0
  530. package/dist/reporting/tracking.d.cts.map +1 -0
  531. package/dist/reporting/tracking.d.mts +63 -0
  532. package/dist/reporting/tracking.d.mts.map +1 -0
  533. package/dist/reporting/tracking.mjs +182 -0
  534. package/dist/reporting/tracking.mjs.map +1 -0
  535. package/dist/runtime.cjs +18 -0
  536. package/dist/runtime.cjs.map +1 -0
  537. package/dist/runtime.d.cts +44 -0
  538. package/dist/runtime.d.cts.map +1 -0
  539. package/dist/runtime.d.mts +44 -0
  540. package/dist/runtime.d.mts.map +1 -0
  541. package/dist/runtime.mjs +17 -0
  542. package/dist/runtime.mjs.map +1 -0
  543. package/dist/store/condition-sql.cjs +145 -0
  544. package/dist/store/condition-sql.cjs.map +1 -0
  545. package/dist/store/condition-sql.d.cts +38 -0
  546. package/dist/store/condition-sql.d.cts.map +1 -0
  547. package/dist/store/condition-sql.d.mts +38 -0
  548. package/dist/store/condition-sql.d.mts.map +1 -0
  549. package/dist/store/condition-sql.mjs +144 -0
  550. package/dist/store/condition-sql.mjs.map +1 -0
  551. package/dist/store/erasure.cjs +21 -0
  552. package/dist/store/erasure.cjs.map +1 -0
  553. package/dist/store/erasure.d.cts +16 -0
  554. package/dist/store/erasure.d.cts.map +1 -0
  555. package/dist/store/erasure.d.mts +16 -0
  556. package/dist/store/erasure.d.mts.map +1 -0
  557. package/dist/store/erasure.mjs +20 -0
  558. package/dist/store/erasure.mjs.map +1 -0
  559. package/dist/store/facts.cjs +79 -0
  560. package/dist/store/facts.cjs.map +1 -0
  561. package/dist/store/facts.d.cts +41 -0
  562. package/dist/store/facts.d.cts.map +1 -0
  563. package/dist/store/facts.d.mts +41 -0
  564. package/dist/store/facts.d.mts.map +1 -0
  565. package/dist/store/facts.mjs +77 -0
  566. package/dist/store/facts.mjs.map +1 -0
  567. package/dist/store/identity.cjs +34 -0
  568. package/dist/store/identity.cjs.map +1 -0
  569. package/dist/store/identity.d.cts +13 -0
  570. package/dist/store/identity.d.cts.map +1 -0
  571. package/dist/store/identity.d.mts +13 -0
  572. package/dist/store/identity.d.mts.map +1 -0
  573. package/dist/store/identity.mjs +30 -0
  574. package/dist/store/identity.mjs.map +1 -0
  575. package/dist/store/index.cjs +35 -0
  576. package/dist/store/index.cjs.map +1 -0
  577. package/dist/store/index.d.cts +766 -0
  578. package/dist/store/index.d.cts.map +1 -0
  579. package/dist/store/index.d.mts +766 -0
  580. package/dist/store/index.d.mts.map +1 -0
  581. package/dist/store/index.mjs +22 -0
  582. package/dist/store/index.mjs.map +1 -0
  583. package/dist/store/postgres-reporting.cjs +327 -0
  584. package/dist/store/postgres-reporting.cjs.map +1 -0
  585. package/dist/store/postgres-reporting.d.cts +95 -0
  586. package/dist/store/postgres-reporting.d.cts.map +1 -0
  587. package/dist/store/postgres-reporting.d.mts +95 -0
  588. package/dist/store/postgres-reporting.d.mts.map +1 -0
  589. package/dist/store/postgres-reporting.mjs +326 -0
  590. package/dist/store/postgres-reporting.mjs.map +1 -0
  591. package/dist/store/postgres.cjs +1173 -0
  592. package/dist/store/postgres.cjs.map +1 -0
  593. package/dist/store/postgres.d.cts +199 -0
  594. package/dist/store/postgres.d.cts.map +1 -0
  595. package/dist/store/postgres.d.mts +199 -0
  596. package/dist/store/postgres.d.mts.map +1 -0
  597. package/dist/store/postgres.mjs +1170 -0
  598. package/dist/store/postgres.mjs.map +1 -0
  599. package/dist/store/sql.cjs +24 -0
  600. package/dist/store/sql.cjs.map +1 -0
  601. package/dist/store/sql.d.cts +26 -0
  602. package/dist/store/sql.d.cts.map +1 -0
  603. package/dist/store/sql.d.mts +26 -0
  604. package/dist/store/sql.d.mts.map +1 -0
  605. package/dist/store/sql.mjs +23 -0
  606. package/dist/store/sql.mjs.map +1 -0
  607. package/dist/store/tables.cjs +660 -0
  608. package/dist/store/tables.cjs.map +1 -0
  609. package/dist/store/tables.d.cts +103 -0
  610. package/dist/store/tables.d.cts.map +1 -0
  611. package/dist/store/tables.d.mts +103 -0
  612. package/dist/store/tables.d.mts.map +1 -0
  613. package/dist/store/tables.mjs +653 -0
  614. package/dist/store/tables.mjs.map +1 -0
  615. package/dist/store/user-lock.cjs +42 -0
  616. package/dist/store/user-lock.cjs.map +1 -0
  617. package/dist/store/user-lock.d.cts +30 -0
  618. package/dist/store/user-lock.d.cts.map +1 -0
  619. package/dist/store/user-lock.d.mts +30 -0
  620. package/dist/store/user-lock.d.mts.map +1 -0
  621. package/dist/store/user-lock.mjs +39 -0
  622. package/dist/store/user-lock.mjs.map +1 -0
  623. package/dist/template-rules.cjs +94 -0
  624. package/dist/template-rules.cjs.map +1 -0
  625. package/dist/template-rules.d.cts +80 -0
  626. package/dist/template-rules.d.cts.map +1 -0
  627. package/dist/template-rules.d.mts +80 -0
  628. package/dist/template-rules.d.mts.map +1 -0
  629. package/dist/template-rules.mjs +86 -0
  630. package/dist/template-rules.mjs.map +1 -0
  631. package/dist/templates.cjs +375 -0
  632. package/dist/templates.cjs.map +1 -0
  633. package/dist/templates.d.cts +358 -0
  634. package/dist/templates.d.cts.map +1 -0
  635. package/dist/templates.d.mts +358 -0
  636. package/dist/templates.d.mts.map +1 -0
  637. package/dist/templates.mjs +353 -0
  638. package/dist/templates.mjs.map +1 -0
  639. package/dist/transports/cloudflare-email.cjs +69 -0
  640. package/dist/transports/cloudflare-email.cjs.map +1 -0
  641. package/dist/transports/cloudflare-email.d.cts +63 -0
  642. package/dist/transports/cloudflare-email.d.cts.map +1 -0
  643. package/dist/transports/cloudflare-email.d.mts +63 -0
  644. package/dist/transports/cloudflare-email.d.mts.map +1 -0
  645. package/dist/transports/cloudflare-email.mjs +67 -0
  646. package/dist/transports/cloudflare-email.mjs.map +1 -0
  647. package/dist/transports/ses.cjs +142 -0
  648. package/dist/transports/ses.cjs.map +1 -0
  649. package/dist/transports/ses.d.cts +49 -0
  650. package/dist/transports/ses.d.cts.map +1 -0
  651. package/dist/transports/ses.d.mts +49 -0
  652. package/dist/transports/ses.d.mts.map +1 -0
  653. package/dist/transports/ses.mjs +139 -0
  654. package/dist/transports/ses.mjs.map +1 -0
  655. package/dist/transports/sigv4.cjs +86 -0
  656. package/dist/transports/sigv4.cjs.map +1 -0
  657. package/dist/transports/sigv4.d.cts +25 -0
  658. package/dist/transports/sigv4.d.cts.map +1 -0
  659. package/dist/transports/sigv4.d.mts +25 -0
  660. package/dist/transports/sigv4.d.mts.map +1 -0
  661. package/dist/transports/sigv4.mjs +85 -0
  662. package/dist/transports/sigv4.mjs.map +1 -0
  663. package/dist/webhooks.cjs +97 -0
  664. package/dist/webhooks.cjs.map +1 -0
  665. package/dist/webhooks.d.cts +23 -0
  666. package/dist/webhooks.d.cts.map +1 -0
  667. package/dist/webhooks.d.mts +23 -0
  668. package/dist/webhooks.d.mts.map +1 -0
  669. package/dist/webhooks.mjs +95 -0
  670. package/dist/webhooks.mjs.map +1 -0
  671. package/dist/webpush.cjs +361 -0
  672. package/dist/webpush.cjs.map +1 -0
  673. package/dist/webpush.d.cts +135 -0
  674. package/dist/webpush.d.cts.map +1 -0
  675. package/dist/webpush.d.mts +135 -0
  676. package/dist/webpush.d.mts.map +1 -0
  677. package/dist/webpush.mjs +350 -0
  678. package/dist/webpush.mjs.map +1 -0
  679. package/package.json +270 -31
  680. package/src/cloudflare/workers.d.ts +44 -0
  681. package/index.cjs +0 -18
  682. package/index.d.cts +0 -4
  683. package/index.d.mts +0 -4
  684. package/index.mjs +0 -1
@@ -0,0 +1,86 @@
1
+ // src/template-rules.ts
2
+ const ADDRESS = /^[^\s@<>]+@[^\s@<>]+$/;
3
+ /** Whether `value` is a bare `user@host` address — the shape a profile's email must have to be sent to. */
4
+ function isEmailAddress(value) {
5
+ return ADDRESS.test(value);
6
+ }
7
+ /** Throws naming `where` when `address` is neither `user@host` nor `{ email: 'user@host', name? }`. */
8
+ function assertEmailAddress(address, where) {
9
+ const email = typeof address === "object" && address !== null ? address.email : address;
10
+ const name = typeof address === "object" && address !== null ? address.name : void 0;
11
+ if (typeof email !== "string" || !ADDRESS.test(email)) throw new TypeError(`${where} must be an email address or { email, name? }`);
12
+ if (name !== void 0 && typeof name !== "string") throw new TypeError(`${where}.name must be a string`);
13
+ }
14
+ /** Throws naming `where` unless `url` is an absolute http(s) URL; '' and null are not a way to leave it out. */
15
+ function assertHttpUrl(url, where) {
16
+ let parsed;
17
+ try {
18
+ parsed = typeof url === "string" ? new URL(url) : void 0;
19
+ } catch {
20
+ parsed = void 0;
21
+ }
22
+ if (parsed === void 0 || parsed.protocol !== "https:" && parsed.protocol !== "http:") throw new TypeError(`${where} must be an http(s) URL (leave it out for none)`);
23
+ }
24
+ /** `assertHttpUrl`, under its earlier name. */
25
+ const assertUnsubscribeUrl = assertHttpUrl;
26
+ /** The config's `email` and every registered template's metadata; throws on the first invalid value. */
27
+ function assertEmailConfig(config, templates) {
28
+ if (Object.hasOwn(config, "emails")) throw new TypeError("the config's `emails` is gone: `from` and `replyTo` are declared on each emailTemplate, and the rest moved to `email: { unsubscribeUrl, preferencesUrl, tracking }`");
29
+ const email = config.email;
30
+ if (email !== void 0) {
31
+ if (email.unsubscribeUrl !== void 0) assertHttpUrl(email.unsubscribeUrl, "email.unsubscribeUrl");
32
+ if (email.preferencesUrl !== void 0) {
33
+ assertHttpUrl(email.preferencesUrl, "email.preferencesUrl");
34
+ if (isUnsubscribeLink(email.preferencesUrl, email.unsubscribeUrl)) throw new TypeError("email.preferencesUrl must not share its origin and path with email.unsubscribeUrl: the sender would track the preferences link as the unsubscribe link");
35
+ }
36
+ const quick = email.tracking?.quickClickMs;
37
+ if (quick !== void 0 && !(typeof quick === "number" && Number.isFinite(quick) && quick >= 0)) throw new TypeError("email.tracking.quickClickMs must be a non-negative number");
38
+ }
39
+ for (const template of templates) {
40
+ const where = `email template '${template.id}'`;
41
+ assertEmailMetadata(template, where, true);
42
+ if (email?.preferencesUrl !== void 0 && isUnsubscribeLink(email.preferencesUrl, template.unsubscribeUrl)) throw new TypeError(`${where}: its unsubscribeUrl shares its origin and path with email.preferencesUrl, so the sender would track the preferences link as the unsubscribe link`);
43
+ }
44
+ }
45
+ /**
46
+ * A template's own `from` / `replyTo` / `unsubscribeUrl` and what it is (`topic` or
47
+ * `transactional: true`), as `emailTemplate` checks them — and `compileConfig` again, for a
48
+ * definition that did not come through `emailTemplate`. A declared template carries `topic`
49
+ * (a string, or null for transactional); a definition carries one of the two options.
50
+ */
51
+ function assertEmailMetadata(template, where, declared = false) {
52
+ assertEmailAddress(template.from, `${where}: from`);
53
+ if (template.replyTo !== void 0) assertEmailAddress(template.replyTo, `${where}: replyTo`);
54
+ if (template.unsubscribeUrl !== void 0) assertHttpUrl(template.unsubscribeUrl, `${where}: unsubscribeUrl`);
55
+ if (assertTemplateTopic(template, where, "email", declared) && template.unsubscribeUrl !== void 0) throw new TypeError(`${where}: a transactional email has no unsubscribe link, so it takes no 'unsubscribeUrl'`);
56
+ }
57
+ /**
58
+ * What a template is — `topic: <id>` or `transactional: true`, one of the two — as `emailTemplate`
59
+ * and `pushTemplate` check their argument and `compileConfig` checks a declared template (where
60
+ * `topic: null` is transactional). Answers whether the template is transactional. Whether the
61
+ * topic is one the contract declares is `compileConfig`'s check, where the contract is at hand.
62
+ */
63
+ function assertTemplateTopic(template, where, channel, declared = false) {
64
+ const { topic } = template;
65
+ const transactional = template.transactional === true || declared && topic === null;
66
+ if (template.transactional !== void 0 && template.transactional !== true) throw new TypeError(`${where}: 'transactional' must be the literal true (leave it out for a topic ${channel})`);
67
+ const hasTopic = topic !== void 0 && topic !== null;
68
+ if (hasTopic && (typeof topic !== "string" || topic.trim() === "")) throw new TypeError(`${where}: 'topic' must be a topic id the contract declares`);
69
+ if (hasTopic && transactional) throw new TypeError(`${where}: give either 'topic' or 'transactional: true', not both`);
70
+ if (!hasTopic && !transactional) throw new TypeError(`${where}: every ${channel} template says what it is — 'topic: <id>' (one the contract's subscriptions.topics declares) or 'transactional: true'`);
71
+ return transactional;
72
+ }
73
+ /** The unsubscribe link may carry its own query (a token, a list): the path names it. */
74
+ function isUnsubscribeLink(url, unsubscribeUrl) {
75
+ if (unsubscribeUrl === void 0) return false;
76
+ try {
77
+ const a = new URL(url);
78
+ const b = new URL(unsubscribeUrl);
79
+ return a.origin === b.origin && a.pathname === b.pathname;
80
+ } catch {
81
+ return false;
82
+ }
83
+ }
84
+ export { assertEmailAddress, assertEmailConfig, assertEmailMetadata, assertHttpUrl, assertTemplateTopic, assertUnsubscribeUrl, isEmailAddress, isUnsubscribeLink };
85
+
86
+ //# sourceMappingURL=template-rules.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-rules.mjs","names":[],"sources":["../src/template-rules.ts"],"sourcesContent":["import type { EmailTemplate } from './templates';\n\n/**\n * What a config and its templates may declare, and the checks that hold them to it: an email\n * address, an http(s) link, the config's `email` block, a template's own email metadata, and\n * what kind of message a template is (a `topic` or `transactional`). Declarations only — how an\n * email is resolved and rendered from them is `email.ts`. No React and no I/O here, so a browser\n * can import it.\n */\n\n/** An address as the transports take it: bare, or with a display name. */\nexport type EmailAddress = string | { email: string; name?: string };\n\n/** The config's `email`: what every email template shares. */\nexport interface EmailConfig {\n /**\n * The unsubscribe link of every email template that names none of its own. The layout reads it\n * with `useEmailContext()`; sent, it is tracked like every link, but following it shows a\n * confirmation page, and only the confirmation (a POST no link scanner sends) unsubscribes.\n */\n unsubscribeUrl?: string;\n /**\n * The app's email preference page. A topic email sent with reporting on links to it with the\n * copy's message id as the `m` query parameter (`useEmailContext().preferencesUrl`), and the\n * page reads and sets the recipient's subscriptions by that id — no sign-in — through\n * `GET` / `PUT /subscriptions/by-message/:messageId` (`JourneyClient.getSubscriptionsByMessage`\n * / `setSubscriptionsByMessage`). Tracked as an ordinary link; it must not share its origin and\n * path with `unsubscribeUrl`, which would make it the unsubscribe link instead.\n */\n preferencesUrl?: string;\n /** How the Worker tells a person's opens and clicks from a machine's (see the reporting classifier). */\n tracking?: {\n /**\n * An open or click this many milliseconds after delivery is a weak machine signal — machine\n * only together with another (a second link within seconds); 1000 by default. A person\n * tapping a mail notification can click within a few seconds, so keep it short.\n */\n quickClickMs?: number;\n };\n}\n\nconst ADDRESS = /^[^\\s@<>]+@[^\\s@<>]+$/;\n\n/** Whether `value` is a bare `user@host` address — the shape a profile's email must have to be sent to. */\nexport function isEmailAddress(value: string): boolean {\n return ADDRESS.test(value);\n}\n\n/** Throws naming `where` when `address` is neither `user@host` nor `{ email: 'user@host', name? }`. */\nexport function assertEmailAddress(address: unknown, where: string): void {\n const email =\n typeof address === 'object' && address !== null\n ? (address as { email?: unknown }).email\n : address;\n const name =\n typeof address === 'object' && address !== null\n ? (address as { name?: unknown }).name\n : undefined;\n if (typeof email !== 'string' || !ADDRESS.test(email)) {\n throw new TypeError(`${where} must be an email address or { email, name? }`);\n }\n if (name !== undefined && typeof name !== 'string') {\n throw new TypeError(`${where}.name must be a string`);\n }\n}\n\n/** Throws naming `where` unless `url` is an absolute http(s) URL; '' and null are not a way to leave it out. */\nexport function assertHttpUrl(url: unknown, where: string): void {\n let parsed: URL | undefined;\n try {\n parsed = typeof url === 'string' ? new URL(url) : undefined;\n } catch {\n parsed = undefined;\n }\n if (parsed === undefined || (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')) {\n throw new TypeError(`${where} must be an http(s) URL (leave it out for none)`);\n }\n}\n\n/** `assertHttpUrl`, under its earlier name. */\nexport const assertUnsubscribeUrl: typeof assertHttpUrl = assertHttpUrl;\n\n/** The config's `email` and every registered template's metadata; throws on the first invalid value. */\nexport function assertEmailConfig(\n config: { email?: EmailConfig },\n templates: Iterable<EmailTemplate>\n): void {\n if (Object.hasOwn(config, 'emails')) {\n throw new TypeError(\n \"the config's `emails` is gone: `from` and `replyTo` are declared on each emailTemplate, \" +\n 'and the rest moved to `email: { unsubscribeUrl, preferencesUrl, tracking }`'\n );\n }\n const email = config.email;\n if (email !== undefined) {\n if (email.unsubscribeUrl !== undefined) {\n assertHttpUrl(email.unsubscribeUrl, 'email.unsubscribeUrl');\n }\n if (email.preferencesUrl !== undefined) {\n assertHttpUrl(email.preferencesUrl, 'email.preferencesUrl');\n // The sender tells the unsubscribe link from the others by origin and path: a preference\n // page at the same address would be tracked as the unsubscribe link and land on `/t/u`\n if (isUnsubscribeLink(email.preferencesUrl, email.unsubscribeUrl)) {\n throw new TypeError(\n 'email.preferencesUrl must not share its origin and path with email.unsubscribeUrl: ' +\n 'the sender would track the preferences link as the unsubscribe link'\n );\n }\n }\n const quick = email.tracking?.quickClickMs;\n if (\n quick !== undefined &&\n !(typeof quick === 'number' && Number.isFinite(quick) && quick >= 0)\n ) {\n throw new TypeError('email.tracking.quickClickMs must be a non-negative number');\n }\n }\n for (const template of templates) {\n const where = `email template '${template.id}'`;\n assertEmailMetadata(template, where, true);\n if (\n email?.preferencesUrl !== undefined &&\n isUnsubscribeLink(email.preferencesUrl, template.unsubscribeUrl)\n ) {\n throw new TypeError(\n `${where}: its unsubscribeUrl shares its origin and path with email.preferencesUrl, so ` +\n 'the sender would track the preferences link as the unsubscribe link'\n );\n }\n }\n}\n\n/**\n * A template's own `from` / `replyTo` / `unsubscribeUrl` and what it is (`topic` or\n * `transactional: true`), as `emailTemplate` checks them — and `compileConfig` again, for a\n * definition that did not come through `emailTemplate`. A declared template carries `topic`\n * (a string, or null for transactional); a definition carries one of the two options.\n */\nexport function assertEmailMetadata(\n template: {\n from?: unknown;\n replyTo?: unknown;\n unsubscribeUrl?: unknown;\n topic?: unknown;\n transactional?: unknown;\n },\n where: string,\n /** True for a declared template (`topic: string | null`), false for `emailTemplate`'s argument. */\n declared = false\n): void {\n assertEmailAddress(template.from, `${where}: from`);\n if (template.replyTo !== undefined) assertEmailAddress(template.replyTo, `${where}: replyTo`);\n if (template.unsubscribeUrl !== undefined) {\n assertHttpUrl(template.unsubscribeUrl, `${where}: unsubscribeUrl`);\n }\n const transactional = assertTemplateTopic(template, where, 'email', declared);\n if (transactional && template.unsubscribeUrl !== undefined) {\n throw new TypeError(\n `${where}: a transactional email has no unsubscribe link, so it takes no 'unsubscribeUrl'`\n );\n }\n}\n\n/**\n * What a template is — `topic: <id>` or `transactional: true`, one of the two — as `emailTemplate`\n * and `pushTemplate` check their argument and `compileConfig` checks a declared template (where\n * `topic: null` is transactional). Answers whether the template is transactional. Whether the\n * topic is one the contract declares is `compileConfig`'s check, where the contract is at hand.\n */\nexport function assertTemplateTopic(\n template: { topic?: unknown; transactional?: unknown },\n where: string,\n channel: 'email' | 'push',\n declared = false\n): boolean {\n const { topic } = template;\n // A declared template says `topic: null` for transactional; a definition says `transactional: true`\n const transactional = template.transactional === true || (declared && topic === null);\n if (template.transactional !== undefined && template.transactional !== true) {\n throw new TypeError(\n `${where}: 'transactional' must be the literal true (leave it out for a topic ${channel})`\n );\n }\n const hasTopic = topic !== undefined && topic !== null;\n if (hasTopic && (typeof topic !== 'string' || topic.trim() === '')) {\n throw new TypeError(`${where}: 'topic' must be a topic id the contract declares`);\n }\n if (hasTopic && transactional) {\n throw new TypeError(`${where}: give either 'topic' or 'transactional: true', not both`);\n }\n if (!hasTopic && !transactional) {\n throw new TypeError(\n `${where}: every ${channel} template says what it is — 'topic: <id>' (one the contract's subscriptions.topics declares) or 'transactional: true'`\n );\n }\n return transactional;\n}\n\n/** The unsubscribe link may carry its own query (a token, a list): the path names it. */\nexport function isUnsubscribeLink(url: string, unsubscribeUrl: string | undefined): boolean {\n if (unsubscribeUrl === undefined) return false;\n try {\n const a = new URL(url);\n const b = new URL(unsubscribeUrl);\n return a.origin === b.origin && a.pathname === b.pathname;\n } catch {\n return false;\n }\n}\n"],"mappings":";AAyCA,MAAM,UAAU;;AAGhB,SAAgB,eAAe,OAAwB;CACrD,OAAO,QAAQ,KAAK,KAAK;AAC3B;;AAGA,SAAgB,mBAAmB,SAAkB,OAAqB;CACxE,MAAM,QACJ,OAAO,YAAY,YAAY,YAAY,OACtC,QAAgC,QACjC;CACN,MAAM,OACJ,OAAO,YAAY,YAAY,YAAY,OACtC,QAA+B,OAChC,KAAA;CACN,IAAI,OAAO,UAAU,YAAY,CAAC,QAAQ,KAAK,KAAK,GAClD,MAAM,IAAI,UAAU,GAAG,MAAM,8CAA8C;CAE7E,IAAI,SAAS,KAAA,KAAa,OAAO,SAAS,UACxC,MAAM,IAAI,UAAU,GAAG,MAAM,uBAAuB;AAExD;;AAGA,SAAgB,cAAc,KAAc,OAAqB;CAC/D,IAAI;CACJ,IAAI;EACF,SAAS,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI,KAAA;CACpD,QAAQ;EACN,SAAS,KAAA;CACX;CACA,IAAI,WAAW,KAAA,KAAc,OAAO,aAAa,YAAY,OAAO,aAAa,SAC/E,MAAM,IAAI,UAAU,GAAG,MAAM,gDAAgD;AAEjF;;AAGA,MAAa,uBAA6C;;AAG1D,SAAgB,kBACd,QACA,WACM;CACN,IAAI,OAAO,OAAO,QAAQ,QAAQ,GAChC,MAAM,IAAI,UACR,qKAEF;CAEF,MAAM,QAAQ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MAAM,uEAAuE,QAAQ,EAC1F;CAEF,MAAM,WAAW,UAAU,KAAA,KAAa,UAAU;CAClD,IAAI,aAAa,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAC7D,MAAM,IAAI,UAAU,GAAG,MAAM,mDAAmD;CAElF,IAAI,YAAY,eACd,MAAM,IAAI,UAAU,GAAG,MAAM,yDAAyD;CAExF,IAAI,CAAC,YAAY,CAAC,eAChB,MAAM,IAAI,UACR,GAAG,MAAM,UAAU,QAAQ,sHAC7B;CAEF,OAAO;AACT;;AAGA,SAAgB,kBAAkB,KAAa,gBAA6C;CAC1F,IAAI,mBAAmB,KAAA,GAAW,OAAO;CACzC,IAAI;EACF,MAAM,IAAI,IAAI,IAAI,GAAG;EACrB,MAAM,IAAI,IAAI,IAAI,cAAc;EAChC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE;CACnD,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -0,0 +1,375 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
+ let zod_mini = require("zod/mini");
4
+ const require_template_rules = require("./template-rules.cjs");
5
+ zod_mini = require_runtime.__toESM(zod_mini, 1);
6
+ // src/templates.ts
7
+ /** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */
8
+ function discordTemplate(definition) {
9
+ assertTemplateId(definition.id, "discordTemplate");
10
+ assertSupportedSchema(definition.props, definition.title);
11
+ parsePreview(definition.props, definition.preview, "discord", definition.title);
12
+ return {
13
+ kind: "discord-template",
14
+ version: 1,
15
+ ...definition
16
+ };
17
+ }
18
+ /** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */
19
+ function slackTemplate(definition) {
20
+ assertTemplateId(definition.id, "slackTemplate");
21
+ assertSupportedSchema(definition.props, definition.title);
22
+ parsePreview(definition.props, definition.preview, "slack", definition.title);
23
+ return {
24
+ kind: "slack-template",
25
+ version: 1,
26
+ ...definition
27
+ };
28
+ }
29
+ /**
30
+ * Declare an email template: with a `topic` the contract declares, or `transactional: true`
31
+ * (then `T` is `never`, and the template's `topic` is null). Throws when neither (or both) is
32
+ * given, a transactional template carries an `unsubscribeUrl`, `from` is missing or invalid,
33
+ * `replyTo` or `unsubscribeUrl` is invalid, `props` uses an unsupported schema or `preview` does
34
+ * not parse. Whether the topic is one the contract declares is checked by `compileConfig`,
35
+ * where the contract is at hand — or at the template itself by `templatesFor(contract)`'s
36
+ * `emailTemplate`, the form to prefer in a project with a contract.
37
+ */
38
+ function emailTemplate(definition) {
39
+ return declareEmail(definition, void 0);
40
+ }
41
+ /**
42
+ * Declare a push template: with a `topic` the contract declares (the user can opt out of it in
43
+ * the app — App Store Review Guideline 4.5.4 requires that for marketing pushes), or
44
+ * `transactional: true` (then `T` is `never`, and the template's `topic` is null). Throws when
45
+ * neither (or both) is given, `props` uses an unsupported schema or `preview` does not parse.
46
+ * Whether the topic is one the contract declares is checked by `compileConfig`, where the
47
+ * contract is at hand — or at the template itself by `templatesFor(contract)`'s `pushTemplate`.
48
+ */
49
+ function pushTemplate(definition) {
50
+ return declarePush(definition, void 0);
51
+ }
52
+ /**
53
+ * The template factories bound to a contract: the same `emailTemplate` and `pushTemplate`, with
54
+ * the topic typed by the contract's `subscriptions.topics` — so a topic the contract does not
55
+ * declare is an error at the template's own `topic` line (in the editor, and when the module
56
+ * loads), not a type chain at the config's `templates` where the registry meets the contract.
57
+ * The form to use wherever a contract exists:
58
+ *
59
+ * const { emailTemplate, pushTemplate } = templatesFor(contract);
60
+ *
61
+ * The bare `emailTemplate` / `pushTemplate` stay for a project without a contract (transactional
62
+ * templates only) and for the compile, which checks every template again.
63
+ */
64
+ function templatesFor(contract) {
65
+ return {
66
+ emailTemplate: (definition) => declareEmail(definition, contract),
67
+ pushTemplate: (definition) => declarePush(definition, contract)
68
+ };
69
+ }
70
+ function declareEmail(definition, contract) {
71
+ assertTemplateId(definition.id, "emailTemplate");
72
+ const where = `emailTemplate('${definition.id}')`;
73
+ require_template_rules.assertEmailMetadata(definition, where);
74
+ assertDeclaredTopic(definition, where, contract);
75
+ assertSupportedSchema(definition.props, definition.title);
76
+ parsePreview(definition.props, definition.preview, "email", definition.title);
77
+ const { topic, transactional, ...rest } = definition;
78
+ return {
79
+ kind: "email-template",
80
+ version: 1,
81
+ ...rest,
82
+ topic: topic ?? null
83
+ };
84
+ }
85
+ function declarePush(definition, contract) {
86
+ assertTemplateId(definition.id, "pushTemplate");
87
+ const where = `pushTemplate('${definition.id}')`;
88
+ require_template_rules.assertTemplateTopic(definition, where, "push");
89
+ assertDeclaredTopic(definition, where, contract);
90
+ assertSupportedSchema(definition.props, definition.title);
91
+ parsePreview(definition.props, definition.preview, "push", definition.title);
92
+ const { topic, transactional, ...rest } = definition;
93
+ return {
94
+ kind: "push-template",
95
+ version: 1,
96
+ ...rest,
97
+ topic: topic ?? null
98
+ };
99
+ }
100
+ /** With a contract at hand (`templatesFor`), a topic it does not declare fails here, naming the list. */
101
+ function assertDeclaredTopic(definition, where, contract) {
102
+ const { topic } = definition;
103
+ if (contract === void 0 || typeof topic !== "string" || contract.topics.includes(topic)) return;
104
+ const list = contract.topics.length === 0 ? "the contract declares no topics (defineContract({ subscriptions: { topics: [...] } }))" : `the contract declares ${contract.topics.map((t) => `'${t}'`).join(", ")}`;
105
+ throw new TypeError(`${where}: topic '${topic}' is not declared — ${list}`);
106
+ }
107
+ function assertTemplateId(id, factory) {
108
+ if (!isTemplateId(id)) throw new TypeError(`${factory}(): 'id' must be a non-empty string`);
109
+ }
110
+ function isTemplateId(id) {
111
+ return typeof id === "string" && id.trim() !== "";
112
+ }
113
+ function isEmailTemplate(value) {
114
+ return isMarked(value, "email-template");
115
+ }
116
+ function isPushTemplate(value) {
117
+ return isMarked(value, "push-template");
118
+ }
119
+ function isDiscordTemplate(value) {
120
+ return isMarked(value, "discord-template");
121
+ }
122
+ function isSlackTemplate(value) {
123
+ return isMarked(value, "slack-template");
124
+ }
125
+ const CHANNEL_OF = {
126
+ "email-template": "email",
127
+ "push-template": "push",
128
+ "discord-template": "discord",
129
+ "slack-template": "slack"
130
+ };
131
+ function isMarked(value, kind) {
132
+ return typeof value === "object" && value !== null && value.kind === kind && value.version === 1;
133
+ }
134
+ /** Any template definition, whatever its channel. */
135
+ function isTemplate(value) {
136
+ return typeof value === "object" && value !== null && Object.hasOwn(CHANNEL_OF, value.kind) && value.version === 1;
137
+ }
138
+ const IS_TEMPLATE = {
139
+ email: isEmailTemplate,
140
+ push: isPushTemplate,
141
+ discord: isDiscordTemplate,
142
+ slack: isSlackTemplate
143
+ };
144
+ /**
145
+ * A channel's registry by template id — how everything that turns an id back into a definition
146
+ * (the compiler, the validator, the renderers, the senders, the studio) looks it up. Throws when
147
+ * an entry is not a template of the channel, has no id, or shares its id with another entry: an id
148
+ * is registered once per channel, so two registrations (even of the same object) are an error,
149
+ * not a silent last-wins. Insertion order is the registry's.
150
+ */
151
+ function indexTemplates(channel, registry) {
152
+ const index = /* @__PURE__ */ new Map();
153
+ const paths = /* @__PURE__ */ new Map();
154
+ for (const [name, entry] of Object.entries(registry ?? {})) {
155
+ const path = `templates.${channel}.${name}`;
156
+ if (!IS_TEMPLATE[channel](entry)) throw new TypeError(`${path} is not a ${channel} template`);
157
+ const id = entry.id;
158
+ if (!isTemplateId(id)) throw new TypeError(`${path} has no id`);
159
+ const previous = paths.get(id);
160
+ if (previous !== void 0) throw new TypeError(`${channel} template id '${id}' is registered twice: ${previous} and ${path}`);
161
+ paths.set(id, path);
162
+ index.set(id, entry);
163
+ }
164
+ return index;
165
+ }
166
+ /** A registered template by id; throws naming the channel and id when there is none. */
167
+ function lookupTemplate(index, channel, id) {
168
+ const template = index.get(id);
169
+ if (template === void 0) throw new Error(`${channel} template '${id}' is not registered`);
170
+ return template;
171
+ }
172
+ /**
173
+ * A template refused its input (`phase: 'props'` — the component/content was
174
+ * never called) or its content function returned something that is not a
175
+ * notification (`phase: 'content'` — called, but nothing is sent). Never a
176
+ * provider failure: a sender must not read it as a dead device token.
177
+ */
178
+ var TemplateValidationError = class extends Error {
179
+ channel;
180
+ template;
181
+ phase;
182
+ issues;
183
+ name = "TemplateValidationError";
184
+ constructor(channel, template, phase, issues) {
185
+ super(`${channel} template '${template}' ${phase === "props" ? "rejected its props" : "returned invalid content"}: ${issues.map((i) => `${i.path || "(root)"} ${i.message}`).join("; ")}`);
186
+ this.channel = channel;
187
+ this.template = template;
188
+ this.phase = phase;
189
+ this.issues = issues;
190
+ }
191
+ };
192
+ function issuesOf(error) {
193
+ return error.issues.map((issue) => ({
194
+ path: issue.path.map(String).join("."),
195
+ message: issue.message
196
+ }));
197
+ }
198
+ /**
199
+ * Parse message props against a template's schema and return the parsed value
200
+ * — the only value anything downstream may use. Throws TemplateValidationError.
201
+ */
202
+ function parseTemplateProps(template, props) {
203
+ const channel = CHANNEL_OF[template.kind];
204
+ const result = zod_mini.safeParse(template.props, props);
205
+ if (!result.success) throw new TemplateValidationError(channel, template.id, "props", issuesOf(result.error));
206
+ return result.data;
207
+ }
208
+ const pushContentSchema = zod_mini.strictObject({
209
+ title: zod_mini.string(),
210
+ body: zod_mini.string(),
211
+ image: zod_mini.optional(zod_mini.string()),
212
+ url: zod_mini.optional(zod_mini.string())
213
+ });
214
+ /** Run a push template's content over parsed props and check the notification it returns. */
215
+ function renderPushContent(template, props) {
216
+ const parsed = parseTemplateProps(template, props);
217
+ const output = template.content(parsed);
218
+ const result = zod_mini.safeParse(pushContentSchema, output);
219
+ if (!result.success) throw new TemplateValidationError("push", template.id, "content", issuesOf(result.error));
220
+ return result.data;
221
+ }
222
+ /**
223
+ * What a Discord webhook accepts at all: something to show (content, an embed, a poll or
224
+ * components) and content within Discord's 2000 characters. The rest of the body is Discord's to
225
+ * judge; its types come from `discord-api-types`.
226
+ */
227
+ const discordContentSchema = zod_mini.looseObject({
228
+ content: zod_mini.optional(zod_mini.string().check(zod_mini.maxLength(2e3))),
229
+ embeds: zod_mini.optional(zod_mini.array(zod_mini.looseObject({})))
230
+ });
231
+ const slackContentSchema = zod_mini.looseObject({
232
+ text: zod_mini.string().check(zod_mini.minLength(1)),
233
+ blocks: zod_mini.optional(zod_mini.array(zod_mini.looseObject({ type: zod_mini.string() })))
234
+ });
235
+ /** Run a Discord template's content over parsed props and check the message it returns. */
236
+ function renderDiscordContent(template, props) {
237
+ const output = template.content(parseTemplateProps(template, props));
238
+ const result = zod_mini.safeParse(discordContentSchema, output);
239
+ const empty = result.success && !result.data.content && (result.data.embeds?.length ?? 0) === 0 && output.poll === void 0 && (output.components?.length ?? 0) === 0;
240
+ if (!result.success || empty) {
241
+ const issues = result.success ? [{
242
+ path: "",
243
+ message: "a Discord message needs content, an embed, a poll or components"
244
+ }] : issuesOf(result.error);
245
+ throw new TemplateValidationError("discord", template.id, "content", issues);
246
+ }
247
+ return output;
248
+ }
249
+ /** Run a Slack template's content over parsed props and check the message it returns. */
250
+ function renderSlackContent(template, props) {
251
+ const output = template.content(parseTemplateProps(template, props));
252
+ const result = zod_mini.safeParse(slackContentSchema, output);
253
+ if (!result.success) throw new TemplateValidationError("slack", template.id, "content", issuesOf(result.error));
254
+ return output;
255
+ }
256
+ function parsePreview(schema, preview, channel, title) {
257
+ const result = zod_mini.safeParse(schema, preview);
258
+ if (!result.success) throw new TemplateValidationError(channel, title, "props", issuesOf(result.error).map((i) => Object.assign(i, { message: `preview: ${i.message}` })));
259
+ }
260
+ const SCALAR_TYPES = /* @__PURE__ */ new Set([
261
+ "string",
262
+ "number",
263
+ "boolean",
264
+ "enum"
265
+ ]);
266
+ /** Throws when `schema` is outside the v1 subset (see the header). */
267
+ function assertSupportedSchema(schema, where) {
268
+ const fail = (reason) => {
269
+ throw new TypeError(`template '${where}': unsupported props schema — ${reason}`);
270
+ };
271
+ const def = schema?._zod?.def;
272
+ if (def?.type !== "object") fail("props must be a z.strictObject({...})");
273
+ const object = def;
274
+ if (object.catchall?._zod.def.type !== "never") fail("props must be strict (z.strictObject): unknown fields would be dropped or passed through");
275
+ rejectCustomChecks(object, where, fail);
276
+ for (const [field, value] of Object.entries(object.shape)) {
277
+ let fieldDef = value._zod.def;
278
+ if (fieldDef.type === "optional") {
279
+ rejectCustomChecks(fieldDef, `${where}.${field}`, fail);
280
+ fieldDef = fieldDef.innerType._zod.def;
281
+ }
282
+ if (fieldDef.type === "literal") {
283
+ if (!fieldDef.values.every((v) => [
284
+ "string",
285
+ "number",
286
+ "boolean"
287
+ ].includes(typeof v))) fail(`field '${field}' is a literal of a non-scalar value`);
288
+ } else if (!SCALAR_TYPES.has(fieldDef.type)) fail(`field '${field}' is ${fieldDef.type}; only string, number, boolean, enum and literal fields (optionally .optional()) are supported`);
289
+ if (fieldDef.coerce === true) fail(`field '${field}' coerces its input (z.coerce), which would change what the props mean`);
290
+ rejectCustomChecks(fieldDef, `${where}.${field}`, fail);
291
+ }
292
+ }
293
+ /**
294
+ * Checks the subset refuses: `custom` runs arbitrary code (`.refine()`), and
295
+ * `overwrite` changes the value (`.overwrite()`, `.trim()`, `.toLowerCase()`…)
296
+ * — the props are parsed more than once on the way to a send (the validator,
297
+ * then the renderer), so a value-changing check would apply twice and the
298
+ * email would differ from the preview.
299
+ */
300
+ function rejectCustomChecks(def, where, fail) {
301
+ for (const check of def.checks ?? []) {
302
+ if (check._zod.def.check === "custom") fail(`'${where}' uses a custom refinement, which the template subset does not support`);
303
+ if (check._zod.def.check === "overwrite") fail(`'${where}' changes the value (.overwrite, .trim, .toLowerCase, …), which the template subset does not support`);
304
+ }
305
+ }
306
+ /**
307
+ * The engine's MessageValidator over the template registries: the message's
308
+ * props are parsed by its template (the parsed value is what gets sent); a
309
+ * push's content is also run once and checked, so an invalid notification
310
+ * stops the send before any device; Discord and Slack content likewise. Channels without a
311
+ * registry here (sms, …) pass through to their app-supplied senders.
312
+ */
313
+ function registryValidator(registry) {
314
+ const email = indexTemplates("email", registry.email);
315
+ const push = indexTemplates("push", registry.push);
316
+ const discord = indexTemplates("discord", registry.discord);
317
+ const slack = indexTemplates("slack", registry.slack);
318
+ return {
319
+ validate({ channel, template, props }) {
320
+ if (channel === "email") return parseTemplateProps(lookupTemplate(email, "email", template), props);
321
+ if (channel === "push") {
322
+ const entry = lookupTemplate(push, "push", template);
323
+ renderPushContent(entry, props);
324
+ return parseTemplateProps(entry, props);
325
+ }
326
+ if (channel === "discord") {
327
+ const entry = lookupTemplate(discord, "discord", template);
328
+ renderDiscordContent(entry, props);
329
+ return parseTemplateProps(entry, props);
330
+ }
331
+ if (channel === "slack") {
332
+ const entry = lookupTemplate(slack, "slack", template);
333
+ renderSlackContent(entry, props);
334
+ return parseTemplateProps(entry, props);
335
+ }
336
+ return props;
337
+ },
338
+ describe({ channel, template }) {
339
+ const resend = (entry) => entry.redelivery === "resend" ? { redelivery: "resend" } : {};
340
+ if (channel === "email" || channel === "push") {
341
+ const entry = (channel === "email" ? email : push).get(template);
342
+ return entry === void 0 ? void 0 : {
343
+ topic: entry.topic,
344
+ ...resend(entry)
345
+ };
346
+ }
347
+ if (channel === "discord" || channel === "slack") {
348
+ const entry = (channel === "discord" ? discord : slack).get(template);
349
+ return entry === void 0 ? void 0 : resend(entry);
350
+ }
351
+ }
352
+ };
353
+ }
354
+ exports.CHANNEL_OF = CHANNEL_OF;
355
+ exports.TemplateValidationError = TemplateValidationError;
356
+ exports.assertSupportedSchema = assertSupportedSchema;
357
+ exports.discordTemplate = discordTemplate;
358
+ exports.emailTemplate = emailTemplate;
359
+ exports.indexTemplates = indexTemplates;
360
+ exports.isDiscordTemplate = isDiscordTemplate;
361
+ exports.isEmailTemplate = isEmailTemplate;
362
+ exports.isPushTemplate = isPushTemplate;
363
+ exports.isSlackTemplate = isSlackTemplate;
364
+ exports.isTemplate = isTemplate;
365
+ exports.lookupTemplate = lookupTemplate;
366
+ exports.parseTemplateProps = parseTemplateProps;
367
+ exports.pushTemplate = pushTemplate;
368
+ exports.registryValidator = registryValidator;
369
+ exports.renderDiscordContent = renderDiscordContent;
370
+ exports.renderPushContent = renderPushContent;
371
+ exports.renderSlackContent = renderSlackContent;
372
+ exports.slackTemplate = slackTemplate;
373
+ exports.templatesFor = templatesFor;
374
+
375
+ //# sourceMappingURL=templates.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.cjs","names":["assertEmailMetadata","assertTemplateTopic","z"],"sources":["../src/templates.ts"],"sourcesContent":["import type { Block, KnownBlock } from '@slack/types';\nimport type { RESTPostAPIWebhookWithTokenJSONBody } from 'discord-api-types/v10';\nimport * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport type { Contract, Topic } from './contract';\nimport type { ScalarIR } from './ir';\nimport { type EmailAddress, assertEmailMetadata, assertTemplateTopic } from './template-rules';\n\n/**\n * Template definitions — `emailTemplate`, `pushTemplate`, `discordTemplate` and `slackTemplate`. One\n * object per template, identified by its own `id` (unique per channel): workflows take the\n * definition itself (`.email(welcome, props)`), the config registers it, and the IR, the manifest,\n * the senders and the studio all find it by that id. Its Zod `props` schema is the only source of the\n * props type: the DSL's `.email()/.push()` arguments, the `preview`, and the\n * `component`/`content` parameter are all derived from it, and every render\n * parses the props against it first (types alone check nothing at run time).\n *\n * Kept free of React and of any renderer: the definitions are plain data plus\n * a function, so the DSL, the Worker and the studio can all import them; the\n * React rendering lives in `sendwend/react-email`.\n *\n * Supported schemas (v1): a strict object (`z.strictObject`) whose fields are\n * string / number / boolean — optionally as enums or literals, optionally\n * `.optional()`, with the built-in checks (min, email, …). That is exactly\n * what IR message props can carry, and it keeps input and output identical, so\n * producer, studio and sender never disagree about a transformed value.\n * Anything else (nested objects, arrays, null, default/transform/coerce,\n * custom refinements) is rejected when the template is declared.\n */\n\n/** A strict Zod object schema of scalar fields — the accepted shape of `props`. */\nexport type PropsSchema = core.$ZodObject;\n\n/** What a push template's `content` returns: the notification itself. */\nexport interface PushContent {\n title: string;\n body: string;\n /** Rich image URL (iOS attachment / Android BigPicture). */\n image?: string;\n /** Where a tap leads: the page a browser push opens (the site's root when absent). */\n url?: string;\n}\n\n/** A Discord webhook message (`discord-api-types`): content, embeds, username, allowed mentions… */\nexport type DiscordContent = RESTPostAPIWebhookWithTokenJSONBody;\n\n/** A Slack incoming-webhook message: the fallback `text` and, usually, Block Kit `blocks`. */\nexport interface SlackContent {\n /** Shown in notifications and wherever blocks cannot be; required even with blocks. */\n text: string;\n blocks?: (KnownBlock | Block)[];\n username?: string;\n icon_emoji?: string;\n icon_url?: string;\n mrkdwn?: boolean;\n unfurl_links?: boolean;\n unfurl_media?: boolean;\n}\n\n/** The channels a template can be declared for. */\nexport type TemplateChannel = 'email' | 'push' | 'discord' | 'slack';\n\ninterface TemplateBase<S extends PropsSchema> {\n /**\n * Wire identity, unique per channel: message nodes, the template manifest, every send and the\n * studio's preview links name the template by it. Not something to rename for readability —\n * `title` is; the property a registry holds it under is only a JavaScript name.\n */\n readonly id: string;\n /** Display name in the studio (not the email subject, not the notification title). */\n readonly title: string;\n readonly description?: string | undefined;\n readonly props: S;\n /** Sample props for the studio; parsed against `props` when the template is declared. */\n readonly preview: core.input<S>;\n /**\n * What a replayed send step does with a copy an earlier run handed to the transport but never\n * confirmed (the run died in between, so the copy may or may not have gone out):\n *\n * - `'skip'` (default): treat it as delivered and do not send it again — at most once. Right\n * for every marketing and lifecycle message: a duplicate costs spam complaints, unsubscribes\n * and sender reputation, while a lost nudge is invisible and the journey has later steps.\n * - `'resend'`: send it again — at least once, a duplicate possible. Only for a transactional\n * template that must arrive (a receipt, a dispute notice, a reply the user is waiting for),\n * where a second copy is a nuisance and a missing one is a failure.\n *\n * A send that fails for sure (the transport throws, a 5xx, a 429) is retried whatever this says.\n */\n readonly redelivery?: 'skip' | 'resend' | undefined;\n}\n\n/**\n * Who an email comes from and where it leads: declared on each template, never inherited from a\n * global sender. Metadata, not props — the component never receives it; its layout reads the\n * resolved unsubscribe link with `useEmailContext()` (`sendwend/email-context`).\n */\nexport interface EmailMetadata {\n readonly from: EmailAddress;\n /** Where replies go; left out, the email has no Reply-To (it is not `from`, and not inherited). */\n readonly replyTo?: EmailAddress | undefined;\n /** This template's unsubscribe link; left out, the config's `email.unsubscribeUrl` (if any). */\n readonly unsubscribeUrl?: string | undefined;\n}\n\n/**\n * What kind of message a template is, by type: a `topic` the contract declares (a user can opt\n * out of it, per channel), or `transactional: true` (a receipt, a code, an invite: sent whatever\n * the user opted out of). One of the two, never neither.\n *\n * The slots nothing real fits are string-literal types that read as the error: an editor\n * reports a mistake at the property itself (\"Type 'true' is not assignable to type 'give\n * either …'\"), and the third member catches a template that says neither, with the property\n * it reports missing naming both options. Written out in full (no aliases): TypeScript prints\n * an alias by name, and the point is the text.\n */\nexport type TemplateTopic<T extends string = string> =\n | {\n readonly topic: T;\n readonly transactional?: \"give either 'topic' or 'transactional: true', not both\";\n }\n | {\n readonly transactional: true;\n readonly topic?: \"a topic the contract declares, or none: 'topic' and 'transactional: true' are exclusive\";\n }\n | {\n readonly 'topic | transactional': \"every template says what it is: 'topic: <id>' (one the contract declares) or 'transactional: true'\";\n readonly topic?: never;\n readonly transactional?: never;\n };\n\n/**\n * The email form of `TemplateTopic`: a topic email carries the unsubscribe link and the\n * `List-Unsubscribe` headers; a transactional one has no link — so no `unsubscribeUrl` either,\n * which the type says in its own words.\n */\nexport type EmailTemplateTopic<T extends string = string> =\n | {\n readonly topic: T;\n readonly transactional?: \"give either 'topic' or 'transactional: true', not both\";\n readonly unsubscribeUrl?: string;\n }\n | {\n readonly transactional: true;\n readonly topic?: \"a topic the contract declares, or none: 'topic' and 'transactional: true' are exclusive\";\n readonly unsubscribeUrl?: \"a transactional email has no unsubscribe link, so it takes no 'unsubscribeUrl'\";\n }\n | {\n readonly 'topic | transactional': \"every template says what it is: 'topic: <id>' (one the contract declares) or 'transactional: true'\";\n readonly topic?: never;\n readonly transactional?: never;\n readonly unsubscribeUrl?: string;\n };\n\n/**\n * `T` is the template's topic (`never` for a transactional one): a registry typed by the\n * contract's topics (`defineConfig({ contract, templates })`) accepts only templates whose topic\n * the contract declares.\n */\nexport interface EmailTemplate<S extends PropsSchema = PropsSchema, T extends string = string>\n extends TemplateBase<S>, EmailMetadata {\n readonly kind: 'email-template';\n readonly version: 1;\n readonly subject: string;\n /** The subscription topic the email belongs to; null for a transactional email. */\n readonly topic: T | null;\n /** The email body: a component over the parsed props (rendered by `sendwend/react-email`). */\n readonly component: (props: Readonly<core.output<S>>) => unknown;\n}\n\n/**\n * `T` is the template's topic (`never` for a transactional one): a registry typed by the\n * contract's topics accepts only push templates whose topic the contract declares.\n */\nexport interface PushTemplate<\n S extends PropsSchema = PropsSchema,\n T extends string = string,\n> extends TemplateBase<S> {\n readonly kind: 'push-template';\n readonly version: 1;\n /** The subscription topic the push belongs to; null for a transactional push. */\n readonly topic: T | null;\n /** The notification, from the parsed props. Synchronous and pure; its result is checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => PushContent;\n}\n\n/**\n * A message posted to a team channel through an incoming webhook (Discord, Slack). The webhook\n * URL is a secret, so it lives in the Worker's environment and the template reads it from there\n * at send time: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`, with `Env` the host's\n * zod-validated environment (`journeyWorker({ env: schema })`). The studio never calls it.\n */\ninterface WebhookTemplateBase<S extends PropsSchema, Env> extends TemplateBase<S> {\n readonly version: 1;\n // A method, so a template typed by the host's Env still fits a registry of any Env\n webhook(env: Env): string | undefined;\n}\n\nexport interface DiscordTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'discord-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => DiscordContent;\n}\n\nexport interface SlackTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'slack-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => SlackContent;\n}\n\n/** Strips a Promise return out of the accepted callback types: async content is rejected at the type level. */\ntype Sync<T> = T extends Promise<unknown> ? never : T;\n\nexport interface EmailTemplateBase<S extends PropsSchema> {\n id: string;\n title: string;\n description?: string;\n from: EmailAddress;\n replyTo?: EmailAddress;\n props: S;\n subject: string;\n preview: NoInfer<core.input<S>>;\n component: (props: NoInfer<Readonly<core.output<S>>>) => unknown;\n /** See `TemplateBase.redelivery`: `'resend'` opts the template into at-least-once. */\n redelivery?: 'skip' | 'resend';\n}\n\n/** `emailTemplate`'s argument: the metadata, the props schema and the body, plus `topic` or `transactional: true`. */\nexport type EmailTemplateDefinition<\n S extends PropsSchema,\n T extends string = string,\n> = EmailTemplateBase<S> & EmailTemplateTopic<T>;\n\nexport interface PushTemplateBase<S extends PropsSchema, R> {\n id: string;\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<R> & PushContent;\n /** See `TemplateBase.redelivery`: `'resend'` opts the template into at-least-once. */\n redelivery?: 'skip' | 'resend';\n}\n\n/** `pushTemplate`'s argument: the props schema and the notification, plus `topic` or `transactional: true`. */\nexport type PushTemplateDefinition<\n S extends PropsSchema,\n R,\n T extends string = string,\n> = PushTemplateBase<S, R> & TemplateTopic<T>;\n\nexport interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {\n id: string;\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n /** The webhook URL, read from the Worker's environment when a message is sent. */\n webhook: (env: Env) => string | undefined;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<C>;\n /** See `TemplateBase.redelivery`: `'resend'` opts the template into at-least-once. */\n redelivery?: 'skip' | 'resend';\n}\n\n/** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function discordTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, DiscordContent>\n): DiscordTemplate<S, Env> {\n assertTemplateId(definition.id, 'discordTemplate');\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'discord', definition.title);\n return { kind: 'discord-template', version: 1, ...definition };\n}\n\n/** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function slackTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, SlackContent>\n): SlackTemplate<S, Env> {\n assertTemplateId(definition.id, 'slackTemplate');\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'slack', definition.title);\n return { kind: 'slack-template', version: 1, ...definition };\n}\n\n/**\n * Declare an email template: with a `topic` the contract declares, or `transactional: true`\n * (then `T` is `never`, and the template's `topic` is null). Throws when neither (or both) is\n * given, a transactional template carries an `unsubscribeUrl`, `from` is missing or invalid,\n * `replyTo` or `unsubscribeUrl` is invalid, `props` uses an unsupported schema or `preview` does\n * not parse. Whether the topic is one the contract declares is checked by `compileConfig`,\n * where the contract is at hand — or at the template itself by `templatesFor(contract)`'s\n * `emailTemplate`, the form to prefer in a project with a contract.\n */\nexport function emailTemplate<S extends PropsSchema, T extends string = never>(\n definition: EmailTemplateDefinition<S, T>\n): EmailTemplate<S, T> {\n return declareEmail(definition, undefined);\n}\n\n/**\n * Declare a push template: with a `topic` the contract declares (the user can opt out of it in\n * the app — App Store Review Guideline 4.5.4 requires that for marketing pushes), or\n * `transactional: true` (then `T` is `never`, and the template's `topic` is null). Throws when\n * neither (or both) is given, `props` uses an unsupported schema or `preview` does not parse.\n * Whether the topic is one the contract declares is checked by `compileConfig`, where the\n * contract is at hand — or at the template itself by `templatesFor(contract)`'s `pushTemplate`.\n */\nexport function pushTemplate<\n S extends PropsSchema,\n R extends PushContent,\n T extends string = never,\n>(definition: PushTemplateDefinition<S, R, T>): PushTemplate<S, T> {\n return declarePush(definition, undefined);\n}\n\n/**\n * The template factories bound to a contract: the same `emailTemplate` and `pushTemplate`, with\n * the topic typed by the contract's `subscriptions.topics` — so a topic the contract does not\n * declare is an error at the template's own `topic` line (in the editor, and when the module\n * loads), not a type chain at the config's `templates` where the registry meets the contract.\n * The form to use wherever a contract exists:\n *\n * const { emailTemplate, pushTemplate } = templatesFor(contract);\n *\n * The bare `emailTemplate` / `pushTemplate` stay for a project without a contract (transactional\n * templates only) and for the compile, which checks every template again.\n */\nexport function templatesFor<C extends Contract>(\n contract: C\n): {\n // Properties, not methods: the factories are meant to be destructured\n emailTemplate: <S extends PropsSchema, T extends Topic<C> = never>(\n definition: EmailTemplateDefinition<S, T>\n ) => EmailTemplate<S, T>;\n pushTemplate: <S extends PropsSchema, R extends PushContent, T extends Topic<C> = never>(\n definition: PushTemplateDefinition<S, R, T>\n ) => PushTemplate<S, T>;\n} {\n return {\n emailTemplate: (definition) => declareEmail(definition, contract),\n pushTemplate: (definition) => declarePush(definition, contract),\n };\n}\n\nfunction declareEmail<S extends PropsSchema, T extends string>(\n definition: EmailTemplateDefinition<S, T>,\n contract: Contract | undefined\n): EmailTemplate<S, T> {\n assertTemplateId(definition.id, 'emailTemplate');\n const where = `emailTemplate('${definition.id}')`;\n assertEmailMetadata(definition, where);\n assertDeclaredTopic(definition, where, contract);\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'email', definition.title);\n const { topic, transactional, ...rest } = definition as EmailTemplateBase<S> & {\n topic?: T;\n transactional?: true;\n unsubscribeUrl?: string;\n };\n void transactional;\n return { kind: 'email-template', version: 1, ...rest, topic: topic ?? null };\n}\n\nfunction declarePush<S extends PropsSchema, R extends PushContent, T extends string>(\n definition: PushTemplateDefinition<S, R, T>,\n contract: Contract | undefined\n): PushTemplate<S, T> {\n assertTemplateId(definition.id, 'pushTemplate');\n const where = `pushTemplate('${definition.id}')`;\n assertTemplateTopic(definition, where, 'push');\n assertDeclaredTopic(definition, where, contract);\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'push', definition.title);\n const { topic, transactional, ...rest } = definition as PushTemplateBase<S, R> & {\n topic?: T;\n transactional?: true;\n };\n void transactional;\n return {\n kind: 'push-template',\n version: 1,\n ...rest,\n topic: topic ?? null,\n } as unknown as PushTemplate<S, T>;\n}\n\n/** With a contract at hand (`templatesFor`), a topic it does not declare fails here, naming the list. */\nfunction assertDeclaredTopic(\n definition: { topic?: unknown },\n where: string,\n contract: Contract | undefined\n): void {\n const { topic } = definition;\n // `includes`, not the predicate: narrowing `string` by a `topic is string` leaves `never`\n if (contract === undefined || typeof topic !== 'string' || contract.topics.includes(topic))\n return;\n const list =\n contract.topics.length === 0\n ? 'the contract declares no topics (defineContract({ subscriptions: { topics: [...] } }))'\n : `the contract declares ${contract.topics.map((t) => `'${t}'`).join(', ')}`;\n throw new TypeError(`${where}: topic '${topic}' is not declared — ${list}`);\n}\n\nfunction assertTemplateId(id: unknown, factory: string): void {\n if (!isTemplateId(id)) {\n throw new TypeError(`${factory}(): 'id' must be a non-empty string`);\n }\n}\n\nfunction isTemplateId(id: unknown): id is string {\n return typeof id === 'string' && id.trim() !== '';\n}\n\nexport function isEmailTemplate(value: unknown): value is EmailTemplate {\n return isMarked(value, 'email-template');\n}\n\nexport function isPushTemplate(value: unknown): value is PushTemplate {\n return isMarked(value, 'push-template');\n}\n\nexport function isDiscordTemplate(value: unknown): value is DiscordTemplate {\n return isMarked(value, 'discord-template');\n}\n\nexport function isSlackTemplate(value: unknown): value is SlackTemplate {\n return isMarked(value, 'slack-template');\n}\n\n/** Any declared template. */\nexport type AnyTemplate = EmailTemplate | PushTemplate | DiscordTemplate | SlackTemplate;\n\nexport const CHANNEL_OF: Record<AnyTemplate['kind'], TemplateChannel> = {\n 'email-template': 'email',\n 'push-template': 'push',\n 'discord-template': 'discord',\n 'slack-template': 'slack',\n};\n\nfunction isMarked(value: unknown, kind: string): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === kind &&\n (value as { version?: unknown }).version === 1\n );\n}\n\n/** Any template definition, whatever its channel. */\nexport function isTemplate(value: unknown): value is AnyTemplate {\n return (\n typeof value === 'object' &&\n value !== null &&\n Object.hasOwn(CHANNEL_OF, (value as { kind?: unknown }).kind as string) &&\n (value as { version?: unknown }).version === 1\n );\n}\n\n/* --------------------------------- registry -------------------------------- */\n\n/**\n * The template registry: per channel, the definitions the project registers. Each channel is a\n * plain object whose property names are JavaScript names only — a template is identified by its\n * own `id` (`indexTemplates`).\n */\nexport interface TemplateRegistry<T extends string = string> {\n /** Email templates; typed by the contract's topics under `defineConfig({ contract, templates })`. */\n readonly email?: Readonly<Record<string, EmailTemplate<PropsSchema, T>>>;\n /** Push templates; typed by the contract's topics the same way. */\n readonly push?: Readonly<Record<string, PushTemplate<PropsSchema, T>>>;\n /** Discord webhook templates, each typed by the host's Env its `webhook` reads. */\n readonly discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>>;\n readonly slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>>;\n}\n\n/** The template a channel's registry holds. */\nexport interface ChannelTemplate {\n email: EmailTemplate;\n push: PushTemplate;\n discord: DiscordTemplate;\n slack: SlackTemplate;\n}\n\nconst IS_TEMPLATE: Record<TemplateChannel, (value: unknown) => boolean> = {\n email: isEmailTemplate,\n push: isPushTemplate,\n discord: isDiscordTemplate,\n slack: isSlackTemplate,\n};\n\n/**\n * A channel's registry by template id — how everything that turns an id back into a definition\n * (the compiler, the validator, the renderers, the senders, the studio) looks it up. Throws when\n * an entry is not a template of the channel, has no id, or shares its id with another entry: an id\n * is registered once per channel, so two registrations (even of the same object) are an error,\n * not a silent last-wins. Insertion order is the registry's.\n */\nexport function indexTemplates<C extends TemplateChannel>(\n channel: C,\n registry: Readonly<Record<string, unknown>> | undefined\n): ReadonlyMap<string, ChannelTemplate[C]> {\n const index = new Map<string, ChannelTemplate[C]>();\n const paths = new Map<string, string>();\n for (const [name, entry] of Object.entries(registry ?? {})) {\n const path = `templates.${channel}.${name}`;\n if (!IS_TEMPLATE[channel](entry)) {\n throw new TypeError(`${path} is not a ${channel} template`);\n }\n const id = (entry as AnyTemplate).id;\n if (!isTemplateId(id)) throw new TypeError(`${path} has no id`);\n const previous = paths.get(id);\n if (previous !== undefined) {\n throw new TypeError(\n `${channel} template id '${id}' is registered twice: ${previous} and ${path}`\n );\n }\n paths.set(id, path);\n index.set(id, entry as ChannelTemplate[C]);\n }\n return index;\n}\n\n/** A registered template by id; throws naming the channel and id when there is none. */\nexport function lookupTemplate<T>(index: ReadonlyMap<string, T>, channel: string, id: string): T {\n const template = index.get(id);\n if (template === undefined) throw new Error(`${channel} template '${id}' is not registered`);\n return template;\n}\n\n/* ------------------------------- validation -------------------------------- */\n\n/** One failed field, with the dotted path the studio and the logs show. */\nexport interface TemplateIssue {\n path: string;\n message: string;\n}\n\n/**\n * A template refused its input (`phase: 'props'` — the component/content was\n * never called) or its content function returned something that is not a\n * notification (`phase: 'content'` — called, but nothing is sent). Never a\n * provider failure: a sender must not read it as a dead device token.\n */\nexport class TemplateValidationError extends Error {\n override readonly name = 'TemplateValidationError';\n constructor(\n readonly channel: TemplateChannel,\n readonly template: string,\n readonly phase: 'props' | 'content',\n readonly issues: TemplateIssue[]\n ) {\n super(\n `${channel} template '${template}' ${phase === 'props' ? 'rejected its props' : 'returned invalid content'}: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n }\n}\n\nfunction issuesOf(error: core.$ZodError): TemplateIssue[] {\n return error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n}\n\n/**\n * Parse message props against a template's schema and return the parsed value\n * — the only value anything downstream may use. Throws TemplateValidationError.\n */\nexport function parseTemplateProps<S extends PropsSchema>(\n template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>,\n props: Record<string, unknown>\n): core.output<S> {\n const channel = CHANNEL_OF[template.kind];\n const result = z.safeParse(template.props, props);\n if (!result.success) {\n throw new TemplateValidationError(channel, template.id, 'props', issuesOf(result.error));\n }\n return result.data;\n}\n\nconst pushContentSchema = z.strictObject({\n title: z.string(),\n body: z.string(),\n image: z.optional(z.string()),\n url: z.optional(z.string()),\n});\n\n/** Run a push template's content over parsed props and check the notification it returns. */\nexport function renderPushContent(\n template: PushTemplate,\n props: Record<string, unknown>\n): PushContent {\n const parsed = parseTemplateProps(template, props);\n const output: unknown = template.content(parsed);\n // A Promise (async content smuggled past the types) is an object without title/body: refused here\n const result = z.safeParse(pushContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('push', template.id, 'content', issuesOf(result.error));\n }\n return result.data;\n}\n\n/**\n * What a Discord webhook accepts at all: something to show (content, an embed, a poll or\n * components) and content within Discord's 2000 characters. The rest of the body is Discord's to\n * judge; its types come from `discord-api-types`.\n */\nconst discordContentSchema = z.looseObject({\n content: z.optional(z.string().check(z.maxLength(2000))),\n embeds: z.optional(z.array(z.looseObject({}))),\n});\n\nconst slackContentSchema = z.looseObject({\n text: z.string().check(z.minLength(1)),\n blocks: z.optional(z.array(z.looseObject({ type: z.string() }))),\n});\n\n/** Run a Discord template's content over parsed props and check the message it returns. */\nexport function renderDiscordContent(\n template: DiscordTemplate,\n props: Record<string, unknown>\n): DiscordContent {\n const output: unknown = template.content(parseTemplateProps(template, props));\n const result = z.safeParse(discordContentSchema, output);\n const empty =\n result.success &&\n !result.data.content &&\n (result.data.embeds?.length ?? 0) === 0 &&\n (output as { poll?: unknown; components?: unknown[] }).poll === undefined &&\n ((output as { components?: unknown[] }).components?.length ?? 0) === 0;\n if (!result.success || empty) {\n const issues = result.success\n ? [{ path: '', message: 'a Discord message needs content, an embed, a poll or components' }]\n : issuesOf(result.error);\n throw new TemplateValidationError('discord', template.id, 'content', issues);\n }\n return output as DiscordContent;\n}\n\n/** Run a Slack template's content over parsed props and check the message it returns. */\nexport function renderSlackContent(\n template: SlackTemplate,\n props: Record<string, unknown>\n): SlackContent {\n const output: unknown = template.content(parseTemplateProps(template, props));\n const result = z.safeParse(slackContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('slack', template.id, 'content', issuesOf(result.error));\n }\n return output as SlackContent;\n}\n\nfunction parsePreview(\n schema: PropsSchema,\n preview: unknown,\n channel: TemplateChannel,\n title: string\n) {\n const result = z.safeParse(schema, preview);\n if (!result.success) {\n throw new TemplateValidationError(\n channel,\n title,\n 'props',\n issuesOf(result.error).map((i) => Object.assign(i, { message: `preview: ${i.message}` }))\n );\n }\n}\n\n/* ---------------------------- supported schemas ---------------------------- */\n\nconst SCALAR_TYPES = new Set(['string', 'number', 'boolean', 'enum']);\n\n/** Throws when `schema` is outside the v1 subset (see the header). */\nexport function assertSupportedSchema(schema: unknown, where: string): void {\n const fail = (reason: string): never => {\n throw new TypeError(`template '${where}': unsupported props schema — ${reason}`);\n };\n const def = (schema as { _zod?: { def?: core.$ZodTypeDef } } | null | undefined)?._zod?.def;\n if (def?.type !== 'object') fail('props must be a z.strictObject({...})');\n const object = def as core.$ZodObjectDef;\n if (object.catchall?._zod.def.type !== 'never') {\n fail(\n 'props must be strict (z.strictObject): unknown fields would be dropped or passed through'\n );\n }\n rejectCustomChecks(object, where, fail);\n for (const [field, value] of Object.entries(object.shape)) {\n let fieldDef = value._zod.def;\n if (fieldDef.type === 'optional') {\n // The wrapper carries checks of its own (`.optional().overwrite(...)`): refuse them too\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n fieldDef = (fieldDef as core.$ZodOptionalDef).innerType._zod.def;\n }\n if (fieldDef.type === 'literal') {\n const values = (fieldDef as core.$ZodLiteralDef<core.util.Literal>).values;\n if (!values.every((v) => ['string', 'number', 'boolean'].includes(typeof v))) {\n fail(`field '${field}' is a literal of a non-scalar value`);\n }\n } else if (!SCALAR_TYPES.has(fieldDef.type)) {\n fail(\n `field '${field}' is ${fieldDef.type}; only string, number, boolean, enum and literal fields (optionally .optional()) are supported`\n );\n }\n if ((fieldDef as { coerce?: boolean }).coerce === true) {\n fail(`field '${field}' coerces its input (z.coerce), which would change what the props mean`);\n }\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n }\n}\n\n/**\n * Checks the subset refuses: `custom` runs arbitrary code (`.refine()`), and\n * `overwrite` changes the value (`.overwrite()`, `.trim()`, `.toLowerCase()`…)\n * — the props are parsed more than once on the way to a send (the validator,\n * then the renderer), so a value-changing check would apply twice and the\n * email would differ from the preview.\n */\nfunction rejectCustomChecks(def: core.$ZodTypeDef, where: string, fail: (reason: string) => never) {\n for (const check of def.checks ?? []) {\n if (check._zod.def.check === 'custom') {\n fail(`'${where}' uses a custom refinement, which the template subset does not support`);\n }\n if (check._zod.def.check === 'overwrite') {\n fail(\n `'${where}' changes the value (.overwrite, .trim, .toLowerCase, …), which the template subset does not support`\n );\n }\n }\n}\n\n/** The scalar props a template accepts, as the IR resolves them before parsing. */\nexport type ResolvedProps = Record<string, ScalarIR | undefined>;\n\n/**\n * The engine's MessageValidator over the template registries: the message's\n * props are parsed by its template (the parsed value is what gets sent); a\n * push's content is also run once and checked, so an invalid notification\n * stops the send before any device; Discord and Slack content likewise. Channels without a\n * registry here (sms, …) pass through to their app-supplied senders.\n */\nexport function registryValidator(registry: TemplateRegistry): {\n validate(message: { channel: string; template: string; props: ResolvedProps }): ResolvedProps;\n describe(message: {\n channel: string;\n template: string;\n }): { topic?: string | null; redelivery?: 'resend' } | undefined;\n} {\n const email = indexTemplates('email', registry.email);\n const push = indexTemplates('push', registry.push);\n const discord = indexTemplates('discord', registry.discord);\n const slack = indexTemplates('slack', registry.slack);\n return {\n validate({ channel, template, props }) {\n if (channel === 'email') {\n const entry = lookupTemplate(email, 'email', template);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n if (channel === 'push') {\n const entry = lookupTemplate(push, 'push', template);\n renderPushContent(entry, props);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n if (channel === 'discord') {\n const entry = lookupTemplate(discord, 'discord', template);\n renderDiscordContent(entry, props);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n if (channel === 'slack') {\n const entry = lookupTemplate(slack, 'slack', template);\n renderSlackContent(entry, props);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n return props;\n },\n describe({ channel, template }) {\n const resend = (entry: { redelivery?: 'skip' | 'resend' | undefined }) =>\n entry.redelivery === 'resend' ? { redelivery: 'resend' as const } : {};\n if (channel === 'email' || channel === 'push') {\n const entry = (channel === 'email' ? email : push).get(template);\n return entry === undefined ? undefined : { topic: entry.topic, ...resend(entry) };\n }\n if (channel === 'discord' || channel === 'slack') {\n const entry = (channel === 'discord' ? discord : slack).get(template);\n return entry === undefined ? undefined : resend(entry);\n }\n return undefined;\n },\n };\n}\n"],"mappings":";;;;;;;AA8QA,SAAgB,gBACd,YACyB;CACzB,iBAAiB,WAAW,IAAI,iBAAiB;CACjD,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,WAAW,WAAW,KAAK;CAC9E,OAAO;EAAE,MAAM;EAAoB,SAAS;EAAG,GAAG;CAAW;AAC/D;;AAGA,SAAgB,cACd,YACuB;CACvB,iBAAiB,WAAW,IAAI,eAAe;CAC/C,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,SAAS,WAAW,KAAK;CAC5E,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAG,GAAG;CAAW;AAC7D;;;;;;;;;;AAWA,SAAgB,cACd,YACqB;CACrB,OAAO,aAAa,YAAY,KAAA,CAAS;AAC3C;;;;;;;;;AAUA,SAAgB,aAId,YAAiE;CACjE,OAAO,YAAY,YAAY,KAAA,CAAS;AAC1C;;;;;;;;;;;;;AAcA,SAAgB,aACd,UASA;CACA,OAAO;EACL,gBAAgB,eAAe,aAAa,YAAY,QAAQ;EAChE,eAAe,eAAe,YAAY,YAAY,QAAQ;CAChE;AACF;AAEA,SAAS,aACP,YACA,UACqB;CACrB,iBAAiB,WAAW,IAAI,eAAe;CAC/C,MAAM,QAAQ,kBAAkB,WAAW,GAAG;CAC9CA,uBAAAA,oBAAoB,YAAY,KAAK;CACrC,oBAAoB,YAAY,OAAO,QAAQ;CAC/C,s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