sendwend 0.0.0-stage → 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 (680) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2082 -2
  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 +279 -3
  680. package/src/cloudflare/workers.d.ts +44 -0
@@ -0,0 +1,169 @@
1
+ import { UserErasedError } from "../store/erasure.mjs";
2
+ import { isVisitorSubject } from "../store/identity.mjs";
3
+ import { checkEvent } from "../contract.mjs";
4
+ import "../store/index.mjs";
5
+ import { identifyUser, ingestEvent, linkVisitor, payloadSizeError } from "./ingest.mjs";
6
+ // src/host/batch.ts
7
+ function isPlainObject(value) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9
+ }
10
+ function isNonEmptyString(value) {
11
+ return typeof value === "string" && value.length > 0;
12
+ }
13
+ /** A profile value: a scalar or null (which removes the property). Nested values are not profile data. */
14
+ function isScalarOrNull(value) {
15
+ return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
16
+ }
17
+ /** How far ahead of the server's clock an event or device `ts` may be: clock skew, not the future. */
18
+ const TS_FUTURE_TOLERANCE_MS = 3e5;
19
+ const TS_ERROR = "ts must be a non-negative integer no later than 5 minutes in the future";
20
+ /**
21
+ * A caller's timestamp: epoch milliseconds, whole, not negative, and not past the skew tolerance.
22
+ * A far-future ts would put the event ahead of everything a window condition reads, and a
23
+ * fractional or unsafe one does not survive the store.
24
+ */
25
+ function isValidTs(ts) {
26
+ return typeof ts === "number" && Number.isSafeInteger(ts) && ts >= 0 && ts <= Date.now() + TS_FUTURE_TOLERANCE_MS;
27
+ }
28
+ /** What is wrong with an untrusted identity: at least one id, and a user id outside the visitors' prefix. */
29
+ function identityError(userId, visitorId) {
30
+ if (userId === void 0 && visitorId === void 0) return "userId or visitorId required";
31
+ if (userId !== void 0 && !isNonEmptyString(userId)) return "userId must be a non-empty string";
32
+ if (typeof userId === "string" && isVisitorSubject(userId)) return "userId must not start with 'visitor:'";
33
+ if (visitorId !== void 0 && !isNonEmptyString(visitorId)) return "visitorId must be a non-empty string";
34
+ }
35
+ /**
36
+ * An untrusted batch, checked whole: one bad part refuses all of it, so a producer never has half
37
+ * a report applied. Contract `mode: 'report'` logs what it would refuse and keeps the original.
38
+ */
39
+ function parseBatch(raw, validation) {
40
+ const refuse = (error) => ({
41
+ ok: false,
42
+ error
43
+ });
44
+ if (!isPlainObject(raw)) return refuse("batch must be an object");
45
+ const { userId, visitorId, profile, at, events } = raw;
46
+ const identity = identityError(userId, visitorId);
47
+ if (identity !== void 0) return refuse(identity);
48
+ if (at !== void 0 && !isValidTs(at)) return refuse(`at: ${TS_ERROR}`);
49
+ if (profile === void 0 && events === void 0) return refuse("profile or events required");
50
+ const batch = {
51
+ ...userId === void 0 ? {} : { userId },
52
+ ...visitorId === void 0 ? {} : { visitorId },
53
+ ...at === void 0 ? {} : { at }
54
+ };
55
+ const contract = validation.contract;
56
+ const report = (what, issues) => console.warn(`[workflow] contract would refuse ${what}: ${issues.map((i) => `${i.path || "(root)"}: ${i.message}`).join("; ")}`);
57
+ if (profile !== void 0) {
58
+ if (!isPlainObject(profile)) return refuse("profile must be an object");
59
+ if (!Object.values(profile).every(isScalarOrNull)) return refuse("profile values must be scalars (string, number, boolean) or null");
60
+ batch.profile = profile;
61
+ if (contract !== void 0) {
62
+ const result = contract.parseProfilePatch(profile);
63
+ if (result.ok) batch.profile = result.data;
64
+ else if (validation.mode === "report") report("the profile", result.issues);
65
+ else return {
66
+ ok: false,
67
+ error: "profile refused by the contract",
68
+ issues: result.issues
69
+ };
70
+ }
71
+ }
72
+ if (events !== void 0) {
73
+ if (!Array.isArray(events)) return refuse("events must be an array");
74
+ const parsed = [];
75
+ for (const item of events) {
76
+ if (!isPlainObject(item)) return refuse("every event must be an object");
77
+ const { event, payload, id, ts } = item;
78
+ if (!isNonEmptyString(event)) return refuse("every event needs a name");
79
+ if (event.startsWith("$")) return refuse("event names starting with $ are reserved");
80
+ if (id !== void 0 && !isNonEmptyString(id)) return refuse("an event id must be a non-empty string");
81
+ if (ts !== void 0 && !isValidTs(ts)) return refuse(TS_ERROR);
82
+ if (payload !== void 0 && !isPlainObject(payload)) return refuse("payload must be an object");
83
+ let accepted = payload;
84
+ if (contract !== void 0) {
85
+ const result = checkEvent(contract, event, payload ?? {});
86
+ const what = `event '${event}'${id === void 0 ? "" : ` (${id})`}`;
87
+ if (result.ok) accepted = result.data;
88
+ else if (validation.mode === "report") report(what, result.issues);
89
+ else return {
90
+ ok: false,
91
+ error: `${what} refused by the contract`,
92
+ issues: result.issues
93
+ };
94
+ }
95
+ const oversized = payloadSizeError(event, accepted);
96
+ if (oversized !== void 0) return refuse(oversized);
97
+ parsed.push({
98
+ event,
99
+ payload: accepted,
100
+ id,
101
+ ts
102
+ });
103
+ }
104
+ batch.events = parsed;
105
+ }
106
+ return {
107
+ ok: true,
108
+ batch
109
+ };
110
+ }
111
+ /**
112
+ * Apply a checked batch: the visitor's merge, the profile, then each event in order. Every part is idempotent (a
113
+ * property older than the stored one is skipped, an event id is stored once), so a caller retries
114
+ * a failed batch whole.
115
+ */
116
+ async function ingestBatch(env, batch, store) {
117
+ const { userId, visitorId, profile, at, events = [] } = batch;
118
+ if (userId !== void 0 && visitorId !== void 0) await linkVisitor(env, visitorId, userId, store, at);
119
+ const subject = userId ?? await store.touchVisitor(visitorId ?? "", at ?? Date.now());
120
+ const result = { events: [] };
121
+ if (profile !== void 0) result.profile = await identifyUser(env, subject, profile, store, at);
122
+ for (const { event, payload, id, ts } of events) result.events.push(await ingestEvent(env, {
123
+ userId: subject,
124
+ event,
125
+ payload,
126
+ id,
127
+ ts
128
+ }, store));
129
+ return result;
130
+ }
131
+ /** First retry after 30 s, doubling up to 15 minutes. */
132
+ function retryDelay(attempts) {
133
+ return Math.min(30 * 2 ** Math.max(attempts - 1, 0), 900);
134
+ }
135
+ /**
136
+ * Consume delivered batches one at a time. A batch for an erased user can never succeed and is
137
+ * acknowledged. Anything else that fails is retried with a backoff until the queue's
138
+ * `max_retries` hands it to its dead letter queue — a batch the contract refuses included
139
+ * (logged with the field paths, never the payload). The contract is this host's version of it:
140
+ * a producer deployed first with a new event or field sends batches the host refuses until it
141
+ * is deployed too, and acknowledging them would drop every one, profile and valid events along,
142
+ * with nothing left to replay. Retried, they pass once the host catches up; past that, the dead
143
+ * letter queue keeps them.
144
+ */
145
+ async function consumeBatches(env, messages, store, validation) {
146
+ for (const message of messages) {
147
+ const parsed = parseBatch(message.body, validation);
148
+ if (!parsed.ok) {
149
+ const issues = parsed.issues?.map((i) => `${i.path || "(root)"}: ${i.message}`).join("; ");
150
+ console.error(`[workflow queue] batch ${message.id} refused: ${parsed.error}${issues ? ` (${issues})` : ""}`);
151
+ message.retry({ delaySeconds: retryDelay(message.attempts) });
152
+ continue;
153
+ }
154
+ try {
155
+ await ingestBatch(env, parsed.batch, store);
156
+ message.ack();
157
+ } catch (error) {
158
+ if (error instanceof UserErasedError) {
159
+ message.ack();
160
+ continue;
161
+ }
162
+ console.error(`[workflow queue] batch ${message.id} failed`, error);
163
+ message.retry({ delaySeconds: retryDelay(message.attempts) });
164
+ }
165
+ }
166
+ }
167
+ export { TS_ERROR, consumeBatches, identityError, ingestBatch, isNonEmptyString, isPlainObject, isScalarOrNull, isValidTs, parseBatch };
168
+
169
+ //# sourceMappingURL=batch.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.mjs","names":[],"sources":["../../src/host/batch.ts"],"sourcesContent":["import { checkEvent } from '../contract';\nimport {\n type JourneyStore,\n type ProfileProps,\n UserErasedError,\n isVisitorSubject,\n} from '../store/index';\nimport type { IngestValidation } from './http';\nimport {\n type IdentifyResult,\n type IngestResult,\n identifyUser,\n ingestEvent,\n linkVisitor,\n payloadSizeError,\n} from './ingest';\nimport type { JourneyEnv } from './platform';\n\n/**\n * One producer report as a single unit: what the user's profile now says and what they just did.\n * The profile is merged before the first event, so a journey an event starts always finds the\n * recipient that report knew about, whichever transport carried it and whatever arrived around\n * it. The same shape travels over HTTP (`POST /ingest`) and through a queue.\n */\nexport interface JourneyBatch {\n /** The signed-in user. With `visitorId` too, that visitor is this user: they merge, once. */\n userId?: string | undefined;\n /** The visitor before sign-in: a stable id for one client, renewed when a user signs out. */\n visitorId?: string | undefined;\n profile?: ProfileProps | undefined;\n /**\n * When the profile was read (epoch ms), the Worker's clock when omitted. A property written\n * later stays: a redelivered batch cannot put an old address back.\n */\n at?: number | undefined;\n events?: readonly BatchEvent[] | undefined;\n}\n\nexport interface BatchEvent {\n event: string;\n payload?: Record<string, unknown> | undefined;\n /** The occurrence's identity: a redelivered batch records it once. */\n id?: string | undefined;\n ts?: number | undefined;\n}\n\nexport interface BatchResult {\n profile?: IdentifyResult;\n events: IngestResult[];\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\n/** A profile value: a scalar or null (which removes the property). Nested values are not profile data. */\nexport function isScalarOrNull(value: unknown): value is string | number | boolean | null {\n return (\n value === null ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n );\n}\n\n/** How far ahead of the server's clock an event or device `ts` may be: clock skew, not the future. */\nconst TS_FUTURE_TOLERANCE_MS = 5 * 60_000;\nexport const TS_ERROR = 'ts must be a non-negative integer no later than 5 minutes in the future';\n\n/**\n * A caller's timestamp: epoch milliseconds, whole, not negative, and not past the skew tolerance.\n * A far-future ts would put the event ahead of everything a window condition reads, and a\n * fractional or unsafe one does not survive the store.\n */\nexport function isValidTs(ts: unknown): ts is number {\n return (\n typeof ts === 'number' &&\n Number.isSafeInteger(ts) &&\n ts >= 0 &&\n ts <= Date.now() + TS_FUTURE_TOLERANCE_MS\n );\n}\n\n/** What is wrong with an untrusted identity: at least one id, and a user id outside the visitors' prefix. */\nexport function identityError(userId: unknown, visitorId: unknown): string | undefined {\n if (userId === undefined && visitorId === undefined) return 'userId or visitorId required';\n if (userId !== undefined && !isNonEmptyString(userId)) {\n return 'userId must be a non-empty string';\n }\n if (typeof userId === 'string' && isVisitorSubject(userId)) {\n return \"userId must not start with 'visitor:'\";\n }\n if (visitorId !== undefined && !isNonEmptyString(visitorId)) {\n return 'visitorId must be a non-empty string';\n }\n return undefined;\n}\n\nexport type ParsedBatch =\n | { ok: true; batch: JourneyBatch }\n | { ok: false; error: string; issues?: readonly { path: string; message: string }[] };\n\n/**\n * An untrusted batch, checked whole: one bad part refuses all of it, so a producer never has half\n * a report applied. Contract `mode: 'report'` logs what it would refuse and keeps the original.\n */\nexport function parseBatch(raw: unknown, validation: IngestValidation): ParsedBatch {\n const refuse = (error: string): ParsedBatch => ({ ok: false, error });\n if (!isPlainObject(raw)) return refuse('batch must be an object');\n const { userId, visitorId, profile, at, events } = raw;\n const identity = identityError(userId, visitorId);\n if (identity !== undefined) return refuse(identity);\n if (at !== undefined && !isValidTs(at)) return refuse(`at: ${TS_ERROR}`);\n if (profile === undefined && events === undefined) return refuse('profile or events required');\n\n const batch: JourneyBatch = {\n ...(userId === undefined ? {} : { userId: userId as string }),\n ...(visitorId === undefined ? {} : { visitorId: visitorId as string }),\n ...(at === undefined ? {} : { at }),\n };\n const contract = validation.contract;\n const report = (what: string, issues: readonly { path: string; message: string }[]) =>\n console.warn(\n `[workflow] contract would refuse ${what}: ${issues\n .map((i) => `${i.path || '(root)'}: ${i.message}`)\n .join('; ')}`\n );\n\n if (profile !== undefined) {\n if (!isPlainObject(profile)) return refuse('profile must be an object');\n if (!Object.values(profile).every(isScalarOrNull)) {\n return refuse('profile values must be scalars (string, number, boolean) or null');\n }\n batch.profile = profile as ProfileProps;\n if (contract !== undefined) {\n const result = contract.parseProfilePatch(profile);\n if (result.ok) batch.profile = result.data as ProfileProps;\n else if (validation.mode === 'report') report('the profile', result.issues);\n else return { ok: false, error: 'profile refused by the contract', issues: result.issues };\n }\n }\n\n if (events !== undefined) {\n if (!Array.isArray(events)) return refuse('events must be an array');\n const parsed: BatchEvent[] = [];\n for (const item of events as unknown[]) {\n if (!isPlainObject(item)) return refuse('every event must be an object');\n const { event, payload, id, ts } = item;\n if (!isNonEmptyString(event)) return refuse('every event needs a name');\n if (event.startsWith('$')) return refuse('event names starting with $ are reserved');\n if (id !== undefined && !isNonEmptyString(id)) {\n return refuse('an event id must be a non-empty string');\n }\n if (ts !== undefined && !isValidTs(ts)) return refuse(TS_ERROR);\n if (payload !== undefined && !isPlainObject(payload)) {\n return refuse('payload must be an object');\n }\n let accepted = payload;\n if (contract !== undefined) {\n const result = checkEvent(contract, event, payload ?? {});\n const what = `event '${event}'${id === undefined ? '' : ` (${id})`}`;\n if (result.ok) accepted = result.data;\n else if (validation.mode === 'report') report(what, result.issues);\n else return { ok: false, error: `${what} refused by the contract`, issues: result.issues };\n }\n const oversized = payloadSizeError(event, accepted);\n if (oversized !== undefined) return refuse(oversized);\n parsed.push({ event, payload: accepted, id, ts });\n }\n batch.events = parsed;\n }\n return { ok: true, batch };\n}\n\n/**\n * Apply a checked batch: the visitor's merge, the profile, then each event in order. Every part is idempotent (a\n * property older than the stored one is skipped, an event id is stored once), so a caller retries\n * a failed batch whole.\n */\nexport async function ingestBatch(\n env: JourneyEnv,\n batch: JourneyBatch,\n store: JourneyStore\n): Promise<BatchResult> {\n const { userId, visitorId, profile, at, events = [] } = batch;\n if (userId !== undefined && visitorId !== undefined) {\n await linkVisitor(env, visitorId, userId, store, at);\n }\n // A late report of a visitor who has signed in since reaches the user\n const subject = userId ?? (await store.touchVisitor(visitorId ?? '', at ?? Date.now()));\n const result: BatchResult = { events: [] };\n if (profile !== undefined) result.profile = await identifyUser(env, subject, profile, store, at);\n for (const { event, payload, id, ts } of events) {\n result.events.push(await ingestEvent(env, { userId: subject, event, payload, id, ts }, store));\n }\n return result;\n}\n\n/** A delivered queue message (the subset of the Cloudflare Queues `Message` used). */\nexport interface QueueMessageLike {\n id: string;\n body: unknown;\n /** Delivery attempts so far, this one included. */\n attempts: number;\n ack(): void;\n retry(options?: { delaySeconds?: number }): void;\n}\n\n/** First retry after 30 s, doubling up to 15 minutes. */\nfunction retryDelay(attempts: number): number {\n return Math.min(30 * 2 ** Math.max(attempts - 1, 0), 900);\n}\n\n/**\n * Consume delivered batches one at a time. A batch for an erased user can never succeed and is\n * acknowledged. Anything else that fails is retried with a backoff until the queue's\n * `max_retries` hands it to its dead letter queue — a batch the contract refuses included\n * (logged with the field paths, never the payload). The contract is this host's version of it:\n * a producer deployed first with a new event or field sends batches the host refuses until it\n * is deployed too, and acknowledging them would drop every one, profile and valid events along,\n * with nothing left to replay. Retried, they pass once the host catches up; past that, the dead\n * letter queue keeps them.\n */\nexport async function consumeBatches(\n env: JourneyEnv,\n messages: readonly QueueMessageLike[],\n store: JourneyStore,\n validation: IngestValidation\n): Promise<void> {\n for (const message of messages) {\n const parsed = parseBatch(message.body, validation);\n if (!parsed.ok) {\n const issues = parsed.issues?.map((i) => `${i.path || '(root)'}: ${i.message}`).join('; ');\n console.error(\n `[workflow queue] batch ${message.id} refused: ${parsed.error}${issues ? ` (${issues})` : ''}`\n );\n message.retry({ delaySeconds: retryDelay(message.attempts) });\n continue;\n }\n try {\n await ingestBatch(env, parsed.batch, store);\n message.ack();\n } catch (error) {\n if (error instanceof UserErasedError) {\n message.ack();\n continue;\n }\n console.error(`[workflow queue] batch ${message.id} failed`, error);\n message.retry({ delaySeconds: retryDelay(message.attempts) });\n }\n }\n}\n"],"mappings":";;;;;;AAmDA,SAAgB,cAAc,OAAkD;CAC9E,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAgB,iBAAiB,OAAiC;CAChE,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS;AACrD;;AAGA,SAAgB,eAAe,OAA2D;CACxF,OACE,UAAU,QACV,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAA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d,MAAM,SAAS,OAAO,QAAQ,KAAK,MAAM,GAAG,EAAE,QAAQ,SAAS,IAAI,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI;GACzF,QAAQ,MACN,0BAA0B,QAAQ,GAAG,YAAY,OAAO,QAAQ,SAAS,KAAK,OAAO,KAAK,IAC5F;GACA,QAAQ,MAAM,EAAE,cAAc,WAAW,QAAQ,QAAQ,EAAE,CAAC;GAC5D;EACF;EACA,IAAI;GACF,MAAM,YAAY,KAAK,OAAO,OAAO,KAAK;GAC1C,QAAQ,IAAI;EACd,SAAS,OAAO;GACd,IAAI,iBAAiB,iBAAiB;IACpC,QAAQ,IAAI;IACZ;GACF;GACA,QAAQ,MAAM,0BAA0B,QAAQ,GAAG,UAAU,KAAK;GAClE,QAAQ,MAAM,EAAE,cAAc,WAAW,QAAQ,QAAQ,EAAE,CAAC;EAC9D;CACF;AACF"}
@@ -0,0 +1,256 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_buffer = require("node:buffer");
3
+ const require_apns = require("../apns.cjs");
4
+ const require_config = require("../config.cjs");
5
+ const require_email_sender = require("../email-sender.cjs");
6
+ const require_engine_retry = require("../engine/retry.cjs");
7
+ const require_fcm = require("../fcm.cjs");
8
+ const require_push = require("../push.cjs");
9
+ const require_react_email = require("../react-email.cjs");
10
+ const require_runtime = require("../runtime.cjs");
11
+ const require_templates = require("../templates.cjs");
12
+ const require_webhooks = require("../webhooks.cjs");
13
+ const require_webpush = require("../webpush.cjs");
14
+ const require_host_senders = require("./senders.cjs");
15
+ // src/host/channels.ts
16
+ /**
17
+ * The outlets a `JourneyConfig` describes, assembled against the environment:
18
+ * email through the host's transport (SES, Cloudflare Email, ...) with each template's addresses, iOS pushes
19
+ * straight to APNs with the configured key (the `.p8` from
20
+ * `APNS_PRIVATE_KEY_BASE64`), Android pushes through FCM with the service
21
+ * account from `GOOGLE_APPLICATION_CREDENTIALS_BASE64`. A channel the config
22
+ * leaves out is simply absent, and a journey that sends on it fails that step
23
+ * with a message saying so — rather than the host having to spell out every
24
+ * sender by hand.
25
+ */
26
+ /** Which config entry applies: wrangler's `ENVIRONMENT` var, production when unset. */
27
+ function journeyMode(env) {
28
+ return env.ENVIRONMENT ?? "production";
29
+ }
30
+ let relayIgnoredLogged = false;
31
+ /**
32
+ * Where APNs requests go: the dev relay `APNS_RELAY_ORIGIN` names, except in production. The relay
33
+ * sees the provider JWT, so a production deploy that inherited the variable (a copied `.dev.vars`,
34
+ * a leftover `vars` entry) goes straight to APNs rather than hand the credential to whatever
35
+ * answers there, and says so once.
36
+ */
37
+ function apnsRelayOrigin(env, mode) {
38
+ const origin = env.APNS_RELAY_ORIGIN;
39
+ if (origin === void 0 || mode !== "production") return origin;
40
+ if (!relayIgnoredLogged) {
41
+ relayIgnoredLogged = true;
42
+ console.error(`[workflow] APNS_RELAY_ORIGIN (${origin}) is ignored in production: APNs is called directly. The relay is for wrangler dev only; unset it in this environment.`);
43
+ }
44
+ }
45
+ /** The runtime options for this environment's mode. */
46
+ function runtimeFromConfig(config, env) {
47
+ return require_runtime.resolveRuntime(config?.runtime, journeyMode(env));
48
+ }
49
+ /**
50
+ * A sender that fails every message with the reason the channel cannot deliver — for good: the
51
+ * configuration is the same on every attempt, so the step does not retry into it.
52
+ */
53
+ function unavailable(reason) {
54
+ return { async send(message) {
55
+ throw new require_engine_retry.PermanentError(`cannot send '${message.template}' on ${message.channel}: ${reason}`, { reason: "not_configured" });
56
+ } };
57
+ }
58
+ function requireSecret(env, name) {
59
+ const value = env[name];
60
+ if (typeof value !== "string" || value.length === 0) throw new require_engine_retry.PermanentError(`${name} is not set: the environment must hold it for the configured channel`, { reason: "not_configured" });
61
+ return value;
62
+ }
63
+ function createProviderCache() {
64
+ const credentials = /* @__PURE__ */ new Map();
65
+ return { get(key, build) {
66
+ if (!credentials.has(key)) credentials.set(key, build());
67
+ return credentials.get(key);
68
+ } };
69
+ }
70
+ /** A number for each fetch implementation, so a credential minted through one is not reused with another. */
71
+ const identities = /* @__PURE__ */ new WeakMap();
72
+ let nextIdentity = 1;
73
+ function identity(value) {
74
+ if (value === void 0) return "global";
75
+ let id = identities.get(value);
76
+ if (id === void 0) {
77
+ id = nextIdentity++;
78
+ identities.set(value, id);
79
+ }
80
+ return String(id);
81
+ }
82
+ /** The first 8 hex of the secret's SHA-256: enough to tell a rotation apart, nothing of the secret. */
83
+ async function secretDigest(secret) {
84
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secret));
85
+ return node_buffer.Buffer.from(digest.slice(0, 4)).toString("hex");
86
+ }
87
+ /**
88
+ * A sender built on its first message, then kept for this call. `build` reads the secrets (and
89
+ * so may throw a `PermanentError` naming the missing variable): a platform's secret is only
90
+ * required when something is actually sent there, so a journey that only emails must not fail
91
+ * because the APNs key is missing from a local `.dev.vars`. A build that failed is not kept.
92
+ */
93
+ function lazy(build) {
94
+ let sender;
95
+ return { async send(message) {
96
+ sender ??= build().catch((error) => {
97
+ sender = void 0;
98
+ throw error;
99
+ });
100
+ return (await sender).send(message);
101
+ } };
102
+ }
103
+ function channelsFromConfig(config, env, options = {}) {
104
+ const mode = journeyMode(env);
105
+ const providers = options.providers ?? createProviderCache();
106
+ const email = () => {
107
+ const registry = config.templates?.email;
108
+ if (registry === void 0) return unavailable("no email templates are registered");
109
+ const transport = options.email;
110
+ if (transport === void 0) return unavailable("no email transport is configured (the host's `email` option)");
111
+ return new require_email_sender.EmailSender({
112
+ transport,
113
+ render: require_react_email.registryRenderer(registry, config.email)
114
+ });
115
+ };
116
+ const push = () => {
117
+ const registry = config.templates?.push;
118
+ if (registry === void 0) return unavailable("no push templates are registered");
119
+ const render = require_push.registryPushRenderer(registry);
120
+ /**
121
+ * A token the provider reports as gone is handed to the host (nothing left to deliver to).
122
+ * Done here, per run, on the settled result, so the credential cached across runs (see
123
+ * `ProviderCache`) never holds a run's store.
124
+ */
125
+ const { store } = options;
126
+ const onDeadToken = options.onDeadToken ?? (store === void 0 ? void 0 : (token) => store.removeDevice(token));
127
+ const dropDeadTokens = (provider, deadTokenReasons) => ({ async send(message) {
128
+ const result = await provider.send(message);
129
+ if (result !== void 0 && deadTokenReasons.has(result.reason) && message.device !== void 0) await onDeadToken?.(message.device.token);
130
+ return result;
131
+ } });
132
+ const platforms = {};
133
+ const apns = config.apns;
134
+ if (apns !== void 0) {
135
+ const apnsFetch = options.apnsFetch ?? options.fetch;
136
+ const environment = require_config.apnsEnvironment(apns, mode);
137
+ platforms.ios = dropDeadTokens(lazy(async () => {
138
+ const secret = requireSecret(env, "APNS_PRIVATE_KEY_BASE64");
139
+ const credentials = providers.get(JSON.stringify([
140
+ "apns",
141
+ apns.keyId,
142
+ apns.teamId,
143
+ await secretDigest(secret)
144
+ ]), () => new require_apns.ApnsProviderToken({
145
+ keyId: apns.keyId,
146
+ teamId: apns.teamId,
147
+ privateKey: require_apns.apnsKeyFromBase64(secret)
148
+ }));
149
+ const origin = apnsRelayOrigin(env, mode);
150
+ return new require_apns.ApnsPushSender({
151
+ credentials,
152
+ topic: apns.topic,
153
+ environment,
154
+ render,
155
+ ...origin === void 0 ? {} : { origin },
156
+ ...apnsFetch === void 0 ? {} : { fetch: apnsFetch }
157
+ });
158
+ }), require_apns.DEAD_TOKEN_REASONS);
159
+ }
160
+ const fcm = config.fcm;
161
+ if (fcm !== void 0) platforms.android = dropDeadTokens(lazy(async () => {
162
+ const secret = requireSecret(env, "GOOGLE_APPLICATION_CREDENTIALS_BASE64");
163
+ const serviceAccount = require_fcm.serviceAccountFromBase64(secret);
164
+ const credentials = providers.get(JSON.stringify([
165
+ "fcm",
166
+ serviceAccount.client_email,
167
+ serviceAccount.project_id,
168
+ identity(options.fetch),
169
+ await secretDigest(secret)
170
+ ]), () => new require_fcm.FcmAccessToken({
171
+ serviceAccount,
172
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
173
+ }));
174
+ return new require_fcm.FcmPushSender({
175
+ credentials,
176
+ render,
177
+ ...fcm.androidChannelId === void 0 ? {} : { android: { channel_id: fcm.androidChannelId } },
178
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
179
+ });
180
+ }), require_fcm.DEAD_TOKEN_REASONS);
181
+ const webPush = config.webPush;
182
+ if (webPush !== void 0) platforms.web = dropDeadTokens(lazy(async () => {
183
+ const publicKey = requireSecret(env, "VAPID_PUBLIC_KEY");
184
+ const privateKey = requireSecret(env, "VAPID_PRIVATE_KEY");
185
+ const credentials = providers.get(JSON.stringify([
186
+ "vapid",
187
+ webPush.subject,
188
+ publicKey,
189
+ await secretDigest(privateKey)
190
+ ]), () => new require_webpush.VapidSigner({
191
+ subject: webPush.subject,
192
+ publicKey,
193
+ privateKey
194
+ }));
195
+ return new require_webpush.WebPushSender({
196
+ credentials,
197
+ render,
198
+ pushServices: webPush.pushServices,
199
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
200
+ });
201
+ }), require_webpush.DEAD_TOKEN_REASONS);
202
+ if (Object.keys(platforms).length === 0) return unavailable("none of apns, fcm or webPush is configured");
203
+ return require_host_senders.routeByPlatform(platforms);
204
+ };
205
+ /**
206
+ * A webhook template's URL, read from the environment the Worker validated at startup (its
207
+ * `env` schema): a template whose variable is unset fails the step, naming the template.
208
+ */
209
+ const webhookUrl = (channel, template) => {
210
+ const url = template.webhook(env);
211
+ if (typeof url !== "string" || url === "") throw new require_engine_retry.PermanentError(`${channel} template '${template.id}': its webhook URL is not set in the environment`, { reason: "not_configured" });
212
+ return url;
213
+ };
214
+ const discord = () => {
215
+ const registry = config.templates?.discord;
216
+ if (registry === void 0) return unavailable("no discord templates are registered");
217
+ const index = require_templates.indexTemplates("discord", registry);
218
+ return new require_webhooks.DiscordWebhookSender({
219
+ render: (id, props) => {
220
+ const template = require_templates.lookupTemplate(index, "discord", id);
221
+ return {
222
+ url: webhookUrl("discord", template),
223
+ content: require_templates.renderDiscordContent(template, props)
224
+ };
225
+ },
226
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
227
+ });
228
+ };
229
+ const slack = () => {
230
+ const registry = config.templates?.slack;
231
+ if (registry === void 0) return unavailable("no slack templates are registered");
232
+ const index = require_templates.indexTemplates("slack", registry);
233
+ return new require_webhooks.SlackWebhookSender({
234
+ render: (id, props) => {
235
+ const template = require_templates.lookupTemplate(index, "slack", id);
236
+ return {
237
+ url: webhookUrl("slack", template),
238
+ content: require_templates.renderSlackContent(template, props)
239
+ };
240
+ },
241
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch }
242
+ });
243
+ };
244
+ return require_host_senders.routeByChannel({
245
+ email: email(),
246
+ push: push(),
247
+ discord: discord(),
248
+ slack: slack()
249
+ });
250
+ }
251
+ exports.channelsFromConfig = channelsFromConfig;
252
+ exports.createProviderCache = createProviderCache;
253
+ exports.journeyMode = journeyMode;
254
+ exports.runtimeFromConfig = runtimeFromConfig;
255
+
256
+ //# sourceMappingURL=channels.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels.cjs","names":["resolveRuntime","PermanentError","Buffer","EmailSender","registryRenderer","registryPushRenderer","apnsEnvironment","ApnsProviderToken","apnsKeyFromBase64","ApnsPushSender","APNS_DEAD_TOKEN_REASONS","serviceAccountFromBase64","FcmAccessToken","FcmPushSender","FCM_DEAD_TOKEN_REASONS","VapidSigner","WebPushSender","WEB_PUSH_DEAD_TOKEN_REASONS","routeByPlatform","indexTemplates","DiscordWebhookSender","lookupTemplate","renderDiscordContent","SlackWebhookSender","renderSlackContent","routeByChannel"],"sources":["../../src/host/channels.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\nimport {\n DEAD_TOKEN_REASONS as APNS_DEAD_TOKEN_REASONS,\n ApnsProviderToken,\n ApnsPushSender,\n apnsKeyFromBase64,\n} from '../apns';\nimport { type JourneyConfig, apnsEnvironment } from '../config';\nimport { EmailSender, type EmailTransport } from '../email-sender';\nimport type { MessageSender } from '../engine/ports';\nimport { PermanentError } from '../engine/retry';\nimport {\n DEAD_TOKEN_REASONS as FCM_DEAD_TOKEN_REASONS,\n FcmAccessToken,\n FcmPushSender,\n serviceAccountFromBase64,\n} from '../fcm';\nimport { registryPushRenderer } from '../push';\nimport { registryRenderer } from '../react-email';\nimport { type JourneyMode, type JourneyRuntimeOptions, resolveRuntime } from '../runtime';\nimport type { JourneyStore } from '../store/index';\nimport {\n type DiscordTemplate,\n type SlackTemplate,\n indexTemplates,\n lookupTemplate,\n renderDiscordContent,\n renderSlackContent,\n} from '../templates';\nimport { DiscordWebhookSender, SlackWebhookSender } from '../webhooks';\nimport {\n VapidSigner,\n DEAD_TOKEN_REASONS as WEB_PUSH_DEAD_TOKEN_REASONS,\n WebPushSender,\n} from '../webpush';\nimport type { JourneyEnv } from './platform';\nimport { routeByChannel, routeByPlatform } from './senders';\n\n/**\n * The outlets a `JourneyConfig` describes, assembled against the environment:\n * email through the host's transport (SES, Cloudflare Email, ...) with each template's addresses, iOS pushes\n * straight to APNs with the configured key (the `.p8` from\n * `APNS_PRIVATE_KEY_BASE64`), Android pushes through FCM with the service\n * account from `GOOGLE_APPLICATION_CREDENTIALS_BASE64`. A channel the config\n * leaves out is simply absent, and a journey that sends on it fails that step\n * with a message saying so — rather than the host having to spell out every\n * sender by hand.\n */\n\n/** Which config entry applies: wrangler's `ENVIRONMENT` var, production when unset. */\nexport function journeyMode(env: JourneyEnv): JourneyMode {\n return env.ENVIRONMENT ?? 'production';\n}\n\nlet relayIgnoredLogged = false;\n\n/**\n * Where APNs requests go: the dev relay `APNS_RELAY_ORIGIN` names, except in production. The relay\n * sees the provider JWT, so a production deploy that inherited the variable (a copied `.dev.vars`,\n * a leftover `vars` entry) goes straight to APNs rather than hand the credential to whatever\n * answers there, and says so once.\n */\nfunction apnsRelayOrigin(env: JourneyEnv, mode: JourneyMode): string | undefined {\n const origin = env.APNS_RELAY_ORIGIN;\n if (origin === undefined || mode !== 'production') return origin;\n if (!relayIgnoredLogged) {\n relayIgnoredLogged = true;\n console.error(\n `[workflow] APNS_RELAY_ORIGIN (${origin}) is ignored in production: APNs is called directly. The relay is for wrangler dev only; unset it in this environment.`\n );\n }\n return undefined;\n}\n\n/** The runtime options for this environment's mode. */\nexport function runtimeFromConfig(\n config: Pick<JourneyConfig, 'runtime'> | undefined,\n env: JourneyEnv\n): Required<JourneyRuntimeOptions> {\n return resolveRuntime(config?.runtime, journeyMode(env));\n}\n\n/**\n * A sender that fails every message with the reason the channel cannot deliver — for good: the\n * configuration is the same on every attempt, so the step does not retry into it.\n */\nfunction unavailable(reason: string): MessageSender {\n return {\n async send(message) {\n throw new PermanentError(\n `cannot send '${message.template}' on ${message.channel}: ${reason}`,\n { reason: 'not_configured' }\n );\n },\n };\n}\n\nfunction requireSecret(\n env: JourneyEnv,\n name:\n | 'APNS_PRIVATE_KEY_BASE64'\n | 'GOOGLE_APPLICATION_CREDENTIALS_BASE64'\n | 'VAPID_PUBLIC_KEY'\n | 'VAPID_PRIVATE_KEY'\n): string {\n const value = env[name];\n if (typeof value !== 'string' || value.length === 0) {\n // Missing on this attempt, missing on the next: the deployment has to change, not the step\n throw new PermanentError(\n `${name} is not set: the environment must hold it for the configured channel`,\n { reason: 'not_configured' }\n );\n }\n return value;\n}\n\n/**\n * The provider credentials — `ApnsProviderToken`, `FcmAccessToken`, `VapidSigner` — for as long\n * as the host lives. `channelsFromConfig` runs once per workflow run (every wake of every\n * instance) and builds the senders anew each time; what must outlive the run is the credential\n * state they hold: the APNs provider JWT must be reused for at least 20 minutes (Apple answers a\n * sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`), the FCM access\n * token is good for an hour, the VAPID key import is wasted work twice.\n *\n * The cache is the host's (`createJourneyHost` makes one and hands it to every run), not the\n * run's `env`: a Lambda invocation builds a fresh env object for each run (its instance port is\n * in it), so a cache keyed on env would miss on every wake. Inside, the key names the provider,\n * the ids that identify the key and a digest of the secret — so a rotated secret or a reloaded\n * host mints a new credential instead of reusing the old, and the secret itself is in no key and\n * no log. Nothing that shapes the sender (topic, environment, relay, registry, store) is in it:\n * the sender is built per call around the shared credential.\n */\nexport interface ProviderCache {\n /** The credential under `key`, built on the first call and returned as is after that. */\n get<T>(key: string, build: () => T): T;\n}\n\nexport function createProviderCache(): ProviderCache {\n const credentials = new Map<string, unknown>();\n return {\n get<T>(key: string, build: () => T): T {\n if (!credentials.has(key)) credentials.set(key, build());\n return credentials.get(key) as T;\n },\n };\n}\n\n/** A number for each fetch implementation, so a credential minted through one is not reused with another. */\nconst identities = new WeakMap<object, number>();\nlet nextIdentity = 1;\nfunction identity(value: object | undefined): string {\n if (value === undefined) return 'global';\n let id = identities.get(value);\n if (id === undefined) {\n id = nextIdentity++;\n identities.set(value, id);\n }\n return String(id);\n}\n\n/** The first 8 hex of the secret's SHA-256: enough to tell a rotation apart, nothing of the secret. */\nasync function secretDigest(secret: string): Promise<string> {\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(secret));\n return Buffer.from(digest.slice(0, 4)).toString('hex');\n}\n\n/**\n * A sender built on its first message, then kept for this call. `build` reads the secrets (and\n * so may throw a `PermanentError` naming the missing variable): a platform's secret is only\n * required when something is actually sent there, so a journey that only emails must not fail\n * because the APNs key is missing from a local `.dev.vars`. A build that failed is not kept.\n */\nfunction lazy(build: () => Promise<MessageSender>): MessageSender {\n let sender: Promise<MessageSender> | undefined;\n return {\n async send(message) {\n sender ??= build().catch((error: unknown) => {\n sender = undefined;\n throw error;\n });\n return (await sender).send(message);\n },\n };\n}\n\n/** The channels slice of the config — what `channelsFromConfig` reads. */\nexport type ChannelsConfig = Pick<\n JourneyConfig,\n 'templates' | 'email' | 'apns' | 'fcm' | 'webPush' | 'runtime'\n>;\n\nexport function channelsFromConfig(\n config: ChannelsConfig,\n env: JourneyEnv,\n options: {\n /**\n * What to do with a token APNs / FCM / a push service reports as gone. The host forgets the\n * device and wakes the waits that read devices (`removeDevice`); sending knows neither.\n */\n onDeadToken?: ((token: string) => Promise<unknown>) | undefined;\n /**\n * Without `onDeadToken`: the store a dead token is removed from. The token is forgotten, but\n * the waits that read devices are not woken — pass `onDeadToken` for that.\n */\n store?: JourneyStore | undefined;\n /** Where finished emails go — the host's choice, independent of where the workflow runs. */\n email?: EmailTransport | undefined;\n fetch?: typeof fetch;\n /** APNs is HTTP/2 only: a Node host passes an HTTP/2 fetch here (its own fetch cannot). */\n apnsFetch?: typeof fetch | undefined;\n /**\n * Where the provider credentials live across runs (`createProviderCache`): the host's, made\n * once with it. Without one, this call's credentials are its own — nothing is reused.\n */\n providers?: ProviderCache | undefined;\n } = {}\n): MessageSender {\n const mode = journeyMode(env);\n const providers = options.providers ?? createProviderCache();\n\n const email = (): MessageSender => {\n const registry = config.templates?.email;\n if (registry === undefined) return unavailable('no email templates are registered');\n const transport = options.email;\n if (transport === undefined) {\n return unavailable(\"no email transport is configured (the host's `email` option)\");\n }\n // Each template names its own sender: there is no global one to require\n return new EmailSender({ transport, render: registryRenderer(registry, config.email) });\n };\n\n const push = (): MessageSender => {\n const registry = config.templates?.push;\n if (registry === undefined) return unavailable('no push templates are registered');\n const render = registryPushRenderer(registry);\n /**\n * A token the provider reports as gone is handed to the host (nothing left to deliver to).\n * Done here, per run, on the settled result, so the credential cached across runs (see\n * `ProviderCache`) never holds a run's store.\n */\n const { store } = options;\n const onDeadToken =\n options.onDeadToken ??\n (store === undefined ? undefined : (token: string) => store.removeDevice(token));\n const dropDeadTokens = (\n provider: MessageSender,\n deadTokenReasons: ReadonlySet<string>\n ): MessageSender => ({\n async send(message) {\n const result = await provider.send(message);\n if (\n result !== undefined &&\n deadTokenReasons.has(result.reason) &&\n message.device !== undefined\n ) {\n await onDeadToken?.(message.device.token);\n }\n return result;\n },\n });\n const platforms: Record<string, MessageSender> = {};\n const apns = config.apns;\n if (apns !== undefined) {\n const apnsFetch = options.apnsFetch ?? options.fetch;\n const environment = apnsEnvironment(apns, mode);\n platforms.ios = dropDeadTokens(\n lazy(async () => {\n const secret = requireSecret(env, 'APNS_PRIVATE_KEY_BASE64');\n const credentials = providers.get(\n JSON.stringify(['apns', apns.keyId, apns.teamId, await secretDigest(secret)]),\n () =>\n new ApnsProviderToken({\n keyId: apns.keyId,\n teamId: apns.teamId,\n privateKey: apnsKeyFromBase64(secret),\n })\n );\n const origin = apnsRelayOrigin(env, mode);\n return new ApnsPushSender({\n credentials,\n topic: apns.topic,\n environment,\n render,\n ...(origin === undefined ? {} : { origin }),\n ...(apnsFetch === undefined ? {} : { fetch: apnsFetch }),\n });\n }),\n APNS_DEAD_TOKEN_REASONS\n );\n }\n const fcm = config.fcm;\n if (fcm !== undefined) {\n platforms.android = dropDeadTokens(\n lazy(async () => {\n const secret = requireSecret(env, 'GOOGLE_APPLICATION_CREDENTIALS_BASE64');\n const serviceAccount = serviceAccountFromBase64(secret);\n // The token endpoint is called through the fetch: another fetch is another credential\n const credentials = providers.get(\n JSON.stringify([\n 'fcm',\n serviceAccount.client_email,\n serviceAccount.project_id,\n identity(options.fetch),\n await secretDigest(secret),\n ]),\n () =>\n new FcmAccessToken({\n serviceAccount,\n ...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n })\n );\n return new FcmPushSender({\n credentials,\n render,\n ...(fcm.androidChannelId === undefined\n ? {}\n : { android: { channel_id: fcm.androidChannelId } }),\n ...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n });\n }),\n FCM_DEAD_TOKEN_REASONS\n );\n }\n const webPush = config.webPush;\n if (webPush !== undefined) {\n platforms.web = dropDeadTokens(\n lazy(async () => {\n const publicKey = requireSecret(env, 'VAPID_PUBLIC_KEY');\n const privateKey = requireSecret(env, 'VAPID_PRIVATE_KEY');\n const credentials = providers.get(\n JSON.stringify(['vapid', webPush.subject, publicKey, await secretDigest(privateKey)]),\n () => new VapidSigner({ subject: webPush.subject, publicKey, privateKey })\n );\n return new WebPushSender({\n credentials,\n render,\n pushServices: webPush.pushServices,\n ...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n });\n }),\n WEB_PUSH_DEAD_TOKEN_REASONS\n );\n }\n if (Object.keys(platforms).length === 0)\n return unavailable('none of apns, fcm or webPush is configured');\n return routeByPlatform(platforms);\n };\n\n /**\n * A webhook template's URL, read from the environment the Worker validated at startup (its\n * `env` schema): a template whose variable is unset fails the step, naming the template.\n */\n const webhookUrl = (channel: 'discord' | 'slack', template: DiscordTemplate | SlackTemplate) => {\n const url = template.webhook(env as unknown as Record<string, unknown>);\n if (typeof url !== 'string' || url === '') {\n throw new PermanentError(\n `${channel} template '${template.id}': its webhook URL is not set in the environment`,\n { reason: 'not_configured' }\n );\n }\n return url;\n };\n\n const discord = (): MessageSender => {\n const registry = config.templates?.discord;\n if (registry === undefined) return unavailable('no discord templates are registered');\n const index = indexTemplates('discord', registry);\n return new DiscordWebhookSender({\n render: (id, props) => {\n const template = lookupTemplate(index, 'discord', id);\n return {\n url: webhookUrl('discord', template),\n content: renderDiscordContent(template, props),\n };\n },\n ...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n });\n };\n\n const slack = (): MessageSender => {\n const registry = config.templates?.slack;\n if (registry === undefined) return unavailable('no slack templates are registered');\n const index = indexTemplates('slack', registry);\n return new SlackWebhookSender({\n render: (id, props) => {\n const template = lookupTemplate(index, 'slack', id);\n return { url: webhookUrl('slack', template), content: renderSlackContent(template, props) };\n },\n ...(options.fetch === undefined ? {} : { fetch: options.fetch }),\n });\n };\n\n return routeByChannel({ email: email(), push: push(), discord: discord(), slack: slack() });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,YAAY,KAA8B;CACxD,OAAO,IAAI,eAAe;AAC5B;AAEA,IAAI,qBAAqB;;;;;;;AAQzB,SAAS,gBAAgB,KAAiB,MAAuC;CAC/E,MAAM,SAAS,IAAI;CACnB,IAAI,WAAW,KAAA,KAAa,SAAS,cAAc,OAAO;CAC1D,IAAI,CAAC,oBAAoB;EACvB,qBAAqB;EACrB,QAAQ,MACN,iCAAiC,OAAO,uHAC1C;CACF;AAEF;;AAGA,SAAgB,kBACd,QACA,KACiC;CACjC,OAAOA,gBAAAA,eAAe,QAAQ,SAAS,YAAY,GAAG,CAAC;AACzD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AA6B;EACjC,MAAM,WAAW,OAAO,WAAW;EACnC,IAAI,aAAa,KAAA,GAAW,OAAO,YAAY,mCAAmC;EAClF,MAAM,QAAQH,kBAAAA,eAAe,SAAS,QAAQ;EAC9C,OAAO,IAAII,iBAAAA,mBAAmB;GAC5B,SAAS,IAAI,UAAU;IACrB,MAAM,WAAWF,kBAAAA,eAAe,OAAO,SAAS,EAAE;IAClD,OAAO;KAAE,KAAK,WAAW,SAAS,QAAQ;KAAG,SAASG,kBAAAA,mBAAmB,UAAU,KAAK;IAAE;GAC5F;GACA,GAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM;EAChE,CAAC;CACH;CAEA,OAAOC,qBAAAA,eAAe;EAAE,OAAO,MAAM;EAAG,MAAM,KAAK;EAAG,SAAS,QAAQ;EAAG,OAAO,MAAM;CAAE,CAAC;AAC5F"}
@@ -0,0 +1,66 @@
1
+ import { JourneyConfig } from "../config.cjs";
2
+ import { EmailTransport } from "../email-sender.cjs";
3
+ import { MessageSender } from "../engine/ports.cjs";
4
+ import { JourneyMode, JourneyRuntimeOptions } from "../runtime.cjs";
5
+ import { JourneyStore } from "../store/index.cjs";
6
+ import { JourneyEnv } from "./platform.cjs";
7
+ /**
8
+ * The outlets a `JourneyConfig` describes, assembled against the environment:
9
+ * email through the host's transport (SES, Cloudflare Email, ...) with each template's addresses, iOS pushes
10
+ * straight to APNs with the configured key (the `.p8` from
11
+ * `APNS_PRIVATE_KEY_BASE64`), Android pushes through FCM with the service
12
+ * account from `GOOGLE_APPLICATION_CREDENTIALS_BASE64`. A channel the config
13
+ * leaves out is simply absent, and a journey that sends on it fails that step
14
+ * with a message saying so — rather than the host having to spell out every
15
+ * sender by hand.
16
+ */
17
+ /** Which config entry applies: wrangler's `ENVIRONMENT` var, production when unset. */
18
+ export declare function journeyMode(env: JourneyEnv): JourneyMode;
19
+ /** The runtime options for this environment's mode. */
20
+ export declare function runtimeFromConfig(config: Pick<JourneyConfig, 'runtime'> | undefined, env: JourneyEnv): Required<JourneyRuntimeOptions>;
21
+ /**
22
+ * The provider credentials — `ApnsProviderToken`, `FcmAccessToken`, `VapidSigner` — for as long
23
+ * as the host lives. `channelsFromConfig` runs once per workflow run (every wake of every
24
+ * instance) and builds the senders anew each time; what must outlive the run is the credential
25
+ * state they hold: the APNs provider JWT must be reused for at least 20 minutes (Apple answers a
26
+ * sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`), the FCM access
27
+ * token is good for an hour, the VAPID key import is wasted work twice.
28
+ *
29
+ * The cache is the host's (`createJourneyHost` makes one and hands it to every run), not the
30
+ * run's `env`: a Lambda invocation builds a fresh env object for each run (its instance port is
31
+ * in it), so a cache keyed on env would miss on every wake. Inside, the key names the provider,
32
+ * the ids that identify the key and a digest of the secret — so a rotated secret or a reloaded
33
+ * host mints a new credential instead of reusing the old, and the secret itself is in no key and
34
+ * no log. Nothing that shapes the sender (topic, environment, relay, registry, store) is in it:
35
+ * the sender is built per call around the shared credential.
36
+ */
37
+ export interface ProviderCache {
38
+ /** The credential under `key`, built on the first call and returned as is after that. */
39
+ get<T>(key: string, build: () => T): T;
40
+ }
41
+ export declare function createProviderCache(): ProviderCache;
42
+ /** The channels slice of the config — what `channelsFromConfig` reads. */
43
+ export type ChannelsConfig = Pick<JourneyConfig, 'templates' | 'email' | 'apns' | 'fcm' | 'webPush' | 'runtime'>;
44
+ export declare function channelsFromConfig(config: ChannelsConfig, env: JourneyEnv, options?: {
45
+ /**
46
+ * What to do with a token APNs / FCM / a push service reports as gone. The host forgets the
47
+ * device and wakes the waits that read devices (`removeDevice`); sending knows neither.
48
+ */
49
+ onDeadToken?: ((token: string) => Promise<unknown>) | undefined;
50
+ /**
51
+ * Without `onDeadToken`: the store a dead token is removed from. The token is forgotten, but
52
+ * the waits that read devices are not woken — pass `onDeadToken` for that.
53
+ */
54
+ store?: JourneyStore | undefined;
55
+ /** Where finished emails go — the host's choice, independent of where the workflow runs. */
56
+ email?: EmailTransport | undefined;
57
+ fetch?: typeof fetch;
58
+ /** APNs is HTTP/2 only: a Node host passes an HTTP/2 fetch here (its own fetch cannot). */
59
+ apnsFetch?: typeof fetch | undefined;
60
+ /**
61
+ * Where the provider credentials live across runs (`createProviderCache`): the host's, made
62
+ * once with it. Without one, this call's credentials are its own — nothing is reused.
63
+ */
64
+ providers?: ProviderCache | undefined;
65
+ }): MessageSender;
66
+ //# sourceMappingURL=channels.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels.d.cts","names":[],"sources":["../../src/host/channels.ts"],"mappings":";;;;;;;;;;;;;;;;;wBAkDgB,YAAY,KAAK,aAAa;;wBAyB9B,kBACd,QAAQ,KAAK,uCACb,KAAK,aACJ,SAAS;;;;;;;;;;;;;;;;;iBAsDK;;EAEf,IAAI,GAAG,aAAa,aAAa,IAAI;;wBAGvB,uBAAuB;;YAiD3B,iBAAiB,KAC3B;wBAIc,mBACd,QAAQ,gBACR,KAAK,YACL;;;;;EAKE,gBAAgB,kBAAkB;;;;;EAKlC,QAAQ;;EAER,QAAQ;EACR,eAAe;;EAEf,mBAAmB;;;;;EAKnB,YAAY;IAEb"}
@@ -0,0 +1,66 @@
1
+ import { JourneyConfig } from "../config.mjs";
2
+ import { EmailTransport } from "../email-sender.mjs";
3
+ import { MessageSender } from "../engine/ports.mjs";
4
+ import { JourneyMode, JourneyRuntimeOptions } from "../runtime.mjs";
5
+ import { JourneyStore } from "../store/index.mjs";
6
+ import { JourneyEnv } from "./platform.mjs";
7
+ /**
8
+ * The outlets a `JourneyConfig` describes, assembled against the environment:
9
+ * email through the host's transport (SES, Cloudflare Email, ...) with each template's addresses, iOS pushes
10
+ * straight to APNs with the configured key (the `.p8` from
11
+ * `APNS_PRIVATE_KEY_BASE64`), Android pushes through FCM with the service
12
+ * account from `GOOGLE_APPLICATION_CREDENTIALS_BASE64`. A channel the config
13
+ * leaves out is simply absent, and a journey that sends on it fails that step
14
+ * with a message saying so — rather than the host having to spell out every
15
+ * sender by hand.
16
+ */
17
+ /** Which config entry applies: wrangler's `ENVIRONMENT` var, production when unset. */
18
+ export declare function journeyMode(env: JourneyEnv): JourneyMode;
19
+ /** The runtime options for this environment's mode. */
20
+ export declare function runtimeFromConfig(config: Pick<JourneyConfig, 'runtime'> | undefined, env: JourneyEnv): Required<JourneyRuntimeOptions>;
21
+ /**
22
+ * The provider credentials — `ApnsProviderToken`, `FcmAccessToken`, `VapidSigner` — for as long
23
+ * as the host lives. `channelsFromConfig` runs once per workflow run (every wake of every
24
+ * instance) and builds the senders anew each time; what must outlive the run is the credential
25
+ * state they hold: the APNs provider JWT must be reused for at least 20 minutes (Apple answers a
26
+ * sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`), the FCM access
27
+ * token is good for an hour, the VAPID key import is wasted work twice.
28
+ *
29
+ * The cache is the host's (`createJourneyHost` makes one and hands it to every run), not the
30
+ * run's `env`: a Lambda invocation builds a fresh env object for each run (its instance port is
31
+ * in it), so a cache keyed on env would miss on every wake. Inside, the key names the provider,
32
+ * the ids that identify the key and a digest of the secret — so a rotated secret or a reloaded
33
+ * host mints a new credential instead of reusing the old, and the secret itself is in no key and
34
+ * no log. Nothing that shapes the sender (topic, environment, relay, registry, store) is in it:
35
+ * the sender is built per call around the shared credential.
36
+ */
37
+ export interface ProviderCache {
38
+ /** The credential under `key`, built on the first call and returned as is after that. */
39
+ get<T>(key: string, build: () => T): T;
40
+ }
41
+ export declare function createProviderCache(): ProviderCache;
42
+ /** The channels slice of the config — what `channelsFromConfig` reads. */
43
+ export type ChannelsConfig = Pick<JourneyConfig, 'templates' | 'email' | 'apns' | 'fcm' | 'webPush' | 'runtime'>;
44
+ export declare function channelsFromConfig(config: ChannelsConfig, env: JourneyEnv, options?: {
45
+ /**
46
+ * What to do with a token APNs / FCM / a push service reports as gone. The host forgets the
47
+ * device and wakes the waits that read devices (`removeDevice`); sending knows neither.
48
+ */
49
+ onDeadToken?: ((token: string) => Promise<unknown>) | undefined;
50
+ /**
51
+ * Without `onDeadToken`: the store a dead token is removed from. The token is forgotten, but
52
+ * the waits that read devices are not woken — pass `onDeadToken` for that.
53
+ */
54
+ store?: JourneyStore | undefined;
55
+ /** Where finished emails go — the host's choice, independent of where the workflow runs. */
56
+ email?: EmailTransport | undefined;
57
+ fetch?: typeof fetch;
58
+ /** APNs is HTTP/2 only: a Node host passes an HTTP/2 fetch here (its own fetch cannot). */
59
+ apnsFetch?: typeof fetch | undefined;
60
+ /**
61
+ * Where the provider credentials live across runs (`createProviderCache`): the host's, made
62
+ * once with it. Without one, this call's credentials are its own — nothing is reused.
63
+ */
64
+ providers?: ProviderCache | undefined;
65
+ }): MessageSender;
66
+ //# sourceMappingURL=channels.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channels.d.mts","names":[],"sources":["../../src/host/channels.ts"],"mappings":";;;;;;;;;;;;;;;;;wBAkDgB,YAAY,KAAK,aAAa;;wBAyB9B,kBACd,QAAQ,KAAK,uCACb,KAAK,aACJ,SAAS;;;;;;;;;;;;;;;;;iBAsDK;;EAEf,IAAI,GAAG,aAAa,aAAa,IAAI;;wBAGvB,uBAAuB;;YAiD3B,iBAAiB,KAC3B;wBAIc,mBACd,QAAQ,gBACR,KAAK,YACL;;;;;EAKE,gBAAgB,kBAAkB;;;;;EAKlC,QAAQ;;EAER,QAAQ;EACR,eAAe;;EAEf,mBAAmB;;;;;EAKnB,YAAY;IAEb"}