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,110 @@
1
+ import { MessageSender, OutboundMessage, SendResult } from "./engine/ports.cjs";
2
+ import "./engine/index.cjs";
3
+ import { PushRenderer } from "./push.cjs";
4
+ /**
5
+ * `sendwend/apns` — iOS push delivery straight to the Apple Push
6
+ * Notification service, token-based (an APNs auth key, the `.p8` file from the
7
+ * developer portal). No Firebase in between: the app registers the APNs device
8
+ * token in its own device table, and the host's DeviceDirectory hands it to the
9
+ * engine, which sends one message per device.
10
+ * No dependencies: the provider JWT is ES256-signed with WebCrypto.
11
+ *
12
+ * APNs speaks HTTP/2 only. A deployed Worker's `fetch` negotiates it, but
13
+ * workerd under `wrangler dev` does not (the connection is dropped), so a local
14
+ * host points `origin` at the Node relay in `sendwend/apns-relay`.
15
+ */
16
+ /** The APNs auth key — the `.p8` file from the developer portal, and the ids that name it. */
17
+ export interface ApnsProviderTokenOptions {
18
+ /** The key's 10-character id, shown next to it in the developer portal. */
19
+ keyId: string;
20
+ /** The Apple Developer team id. */
21
+ teamId: string;
22
+ /** The `.p8` file's contents: PEM, `-----BEGIN PRIVATE KEY-----` (PKCS #8, P-256). */
23
+ privateKey: string;
24
+ }
25
+ export interface ApnsPushOptions {
26
+ /** The provider token the requests are signed with — shared by every sender on the same key. */
27
+ credentials: ApnsProviderToken;
28
+ /** The app's bundle id — APNs's `apns-topic`. */
29
+ topic: string;
30
+ /**
31
+ * Which APNs environment the device tokens come from: `sandbox` for builds
32
+ * signed with `aps-environment: development` (Xcode, the simulator),
33
+ * `production` for App Store and TestFlight builds. A token from one is
34
+ * `BadDeviceToken` on the other.
35
+ */
36
+ environment: 'sandbox' | 'production';
37
+ render: PushRenderer;
38
+ /**
39
+ * POST here instead of Apple's host — the dev relay, which forwards over
40
+ * HTTP/2. The real host still travels along (`apns-relay-upstream`), so the
41
+ * relay needs no configuration of its own.
42
+ */
43
+ origin?: string;
44
+ /** Fetch implementation (defaults to the global one). */
45
+ fetch?: typeof fetch;
46
+ }
47
+ export declare const APNS_HOSTS: {
48
+ readonly sandbox: 'https://api.sandbox.push.apple.com';
49
+ readonly production: 'https://api.push.apple.com';
50
+ };
51
+ /**
52
+ * How an APNs answer is classified, after Apple's response table
53
+ * (https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns):
54
+ *
55
+ * - dead token: HTTP 410 `Unregistered` (the app was removed, or the token is inactive for the
56
+ * topic) and 400 `ExpiredToken`. The device will never deliver again, so the copy settles
57
+ * undelivered and the host forgets the token.
58
+ * - undelivered, device kept: 400 `BadDeviceToken` and 400 `DeviceTokenNotForTopic`. Apple gives
59
+ * the first for a malformed token but just as well for a token of the other environment (a
60
+ * sandbox build pushed through the production host), and the second for a token of another
61
+ * app (another bundle id: a development build registered against this backend). Either is
62
+ * about this one device — unless the deployment's own environment or topic is wrong, when
63
+ * every device answers so. The copy settles with the reason, so the report shows it; nothing
64
+ * is deleted on a guess, and the user's other devices and the rest of the journey go on.
65
+ * - configuration: the topic, certificate or provider key is wrong. Every device on this app
66
+ * would answer the same, so it is a `PermanentError` and the devices are kept — they are fine,
67
+ * the deployment is not.
68
+ * - transient: 429 (`TooManyRequests`, `TooManyProviderTokenUpdates`), 5xx (`InternalServerError`,
69
+ * `ServiceUnavailable`, `Shutdown`) and 403 `ExpiredProviderToken`, which a fresh token fixes.
70
+ * - everything else (400 `BadMessageId`, `BadPriority`, `PayloadEmpty`, 413 `PayloadTooLarge`,
71
+ * 404 `BadPath`, 405 `MethodNotAllowed`, …) is this request itself: a `PermanentError`.
72
+ */
73
+ export declare const DEAD_TOKEN_REASONS: ReadonlySet<string>;
74
+ /**
75
+ * The copy's identity on the wire: a canonical UUID derived from the idempotency key (SHA-256, the
76
+ * first 16 bytes laid out as an RFC 9562 v8 UUID). The same on every attempt, so a resend of the
77
+ * same copy carries the same `apns-id` and — as `apns-collapse-id`, which is limited to 64 bytes —
78
+ * collapses onto the first notification. The whole key is hashed: cut to 64 bytes it would lose
79
+ * the node id at its end, and two nodes of one instance would collapse into one notification.
80
+ */
81
+ export declare function apnsIdFromKey(idempotencyKey: string): Promise<string>;
82
+ /**
83
+ * The provider JWT for one APNs auth key, signed once and reused for `TOKEN_TTL_MS`: Apple
84
+ * answers a sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`. Concurrent
85
+ * callers on a fresh or aged token share the one signing in flight, and a signing that failed is
86
+ * not kept, so the next call tries again. One instance serves every sender built on the key — a
87
+ * host keeps it across runs, and builds the senders per run.
88
+ */
89
+ export declare class ApnsProviderToken {
90
+ private readonly options;
91
+ private signed;
92
+ private signing;
93
+ constructor(options: ApnsProviderTokenOptions);
94
+ /** The current token, signed now if there is none or it has aged out. */
95
+ token(now?: number): Promise<string>;
96
+ /** Forget the token: APNs refused it (`ExpiredProviderToken`), so the next call signs a new one. */
97
+ invalidate(): void;
98
+ }
99
+ export declare class ApnsPushSender implements MessageSender {
100
+ private readonly options;
101
+ constructor(options: ApnsPushOptions);
102
+ send(message: OutboundMessage): Promise<void | SendResult>;
103
+ }
104
+ /** APNs error bodies are `{ "reason": "…" }`. */
105
+ export declare function apnsReason(body: string): string;
106
+ /** ES256-sign the APNs provider token: header `kid`, claims `iss` (team) and `iat`. */
107
+ export declare function signApnsJwt(key: ApnsProviderTokenOptions, nowMs?: number): Promise<string>;
108
+ /** The `.p8` as it is usually shipped in a secret: base64 of the file. */
109
+ export declare function apnsKeyFromBase64(value: string): string;
110
+ //# sourceMappingURL=apns.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apns.d.cts","names":[],"sources":["../src/apns.ts"],"mappings":";;;;;;;;;;;;;;;;iBAoBiB;;EAEf;;EAEA;;EAEA;;iBAGe;;EAEf,aAAa;;EAEb;;;;;;;EAOA;EACA,QAAQ;;;;;;EAMR;;EAEA,eAAe;;qBAGJ;WACX;WACA;;;;;;;;;;;;;;;;;;;;;;;;qBAyBW,oBAAoB;;;;;;;;wBAwBX,cAAc,yBAAyB;;;;;;;;qBAqBhD;mBAIkB;UAHrB;UACA;EAER,YAA6B,SAAS;;EAGhC,MAAM,eAAmB;;EAgB/B;;qBAKW,0BAA0B;mBACR;EAA7B,YAA6B,SAAS;EAEhC,KAAK,SAAS,kBAAkB,eAAe;;;wBAsFvC,WAAW;;wBAUL,YACpB,KAAK,0BACL,iBACC;;wBAoBa,kBAAkB"}
@@ -0,0 +1,110 @@
1
+ import { MessageSender, OutboundMessage, SendResult } from "./engine/ports.mjs";
2
+ import "./engine/index.mjs";
3
+ import { PushRenderer } from "./push.mjs";
4
+ /**
5
+ * `sendwend/apns` — iOS push delivery straight to the Apple Push
6
+ * Notification service, token-based (an APNs auth key, the `.p8` file from the
7
+ * developer portal). No Firebase in between: the app registers the APNs device
8
+ * token in its own device table, and the host's DeviceDirectory hands it to the
9
+ * engine, which sends one message per device.
10
+ * No dependencies: the provider JWT is ES256-signed with WebCrypto.
11
+ *
12
+ * APNs speaks HTTP/2 only. A deployed Worker's `fetch` negotiates it, but
13
+ * workerd under `wrangler dev` does not (the connection is dropped), so a local
14
+ * host points `origin` at the Node relay in `sendwend/apns-relay`.
15
+ */
16
+ /** The APNs auth key — the `.p8` file from the developer portal, and the ids that name it. */
17
+ export interface ApnsProviderTokenOptions {
18
+ /** The key's 10-character id, shown next to it in the developer portal. */
19
+ keyId: string;
20
+ /** The Apple Developer team id. */
21
+ teamId: string;
22
+ /** The `.p8` file's contents: PEM, `-----BEGIN PRIVATE KEY-----` (PKCS #8, P-256). */
23
+ privateKey: string;
24
+ }
25
+ export interface ApnsPushOptions {
26
+ /** The provider token the requests are signed with — shared by every sender on the same key. */
27
+ credentials: ApnsProviderToken;
28
+ /** The app's bundle id — APNs's `apns-topic`. */
29
+ topic: string;
30
+ /**
31
+ * Which APNs environment the device tokens come from: `sandbox` for builds
32
+ * signed with `aps-environment: development` (Xcode, the simulator),
33
+ * `production` for App Store and TestFlight builds. A token from one is
34
+ * `BadDeviceToken` on the other.
35
+ */
36
+ environment: 'sandbox' | 'production';
37
+ render: PushRenderer;
38
+ /**
39
+ * POST here instead of Apple's host — the dev relay, which forwards over
40
+ * HTTP/2. The real host still travels along (`apns-relay-upstream`), so the
41
+ * relay needs no configuration of its own.
42
+ */
43
+ origin?: string;
44
+ /** Fetch implementation (defaults to the global one). */
45
+ fetch?: typeof fetch;
46
+ }
47
+ export declare const APNS_HOSTS: {
48
+ readonly sandbox: 'https://api.sandbox.push.apple.com';
49
+ readonly production: 'https://api.push.apple.com';
50
+ };
51
+ /**
52
+ * How an APNs answer is classified, after Apple's response table
53
+ * (https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns):
54
+ *
55
+ * - dead token: HTTP 410 `Unregistered` (the app was removed, or the token is inactive for the
56
+ * topic) and 400 `ExpiredToken`. The device will never deliver again, so the copy settles
57
+ * undelivered and the host forgets the token.
58
+ * - undelivered, device kept: 400 `BadDeviceToken` and 400 `DeviceTokenNotForTopic`. Apple gives
59
+ * the first for a malformed token but just as well for a token of the other environment (a
60
+ * sandbox build pushed through the production host), and the second for a token of another
61
+ * app (another bundle id: a development build registered against this backend). Either is
62
+ * about this one device — unless the deployment's own environment or topic is wrong, when
63
+ * every device answers so. The copy settles with the reason, so the report shows it; nothing
64
+ * is deleted on a guess, and the user's other devices and the rest of the journey go on.
65
+ * - configuration: the topic, certificate or provider key is wrong. Every device on this app
66
+ * would answer the same, so it is a `PermanentError` and the devices are kept — they are fine,
67
+ * the deployment is not.
68
+ * - transient: 429 (`TooManyRequests`, `TooManyProviderTokenUpdates`), 5xx (`InternalServerError`,
69
+ * `ServiceUnavailable`, `Shutdown`) and 403 `ExpiredProviderToken`, which a fresh token fixes.
70
+ * - everything else (400 `BadMessageId`, `BadPriority`, `PayloadEmpty`, 413 `PayloadTooLarge`,
71
+ * 404 `BadPath`, 405 `MethodNotAllowed`, …) is this request itself: a `PermanentError`.
72
+ */
73
+ export declare const DEAD_TOKEN_REASONS: ReadonlySet<string>;
74
+ /**
75
+ * The copy's identity on the wire: a canonical UUID derived from the idempotency key (SHA-256, the
76
+ * first 16 bytes laid out as an RFC 9562 v8 UUID). The same on every attempt, so a resend of the
77
+ * same copy carries the same `apns-id` and — as `apns-collapse-id`, which is limited to 64 bytes —
78
+ * collapses onto the first notification. The whole key is hashed: cut to 64 bytes it would lose
79
+ * the node id at its end, and two nodes of one instance would collapse into one notification.
80
+ */
81
+ export declare function apnsIdFromKey(idempotencyKey: string): Promise<string>;
82
+ /**
83
+ * The provider JWT for one APNs auth key, signed once and reused for `TOKEN_TTL_MS`: Apple
84
+ * answers a sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`. Concurrent
85
+ * callers on a fresh or aged token share the one signing in flight, and a signing that failed is
86
+ * not kept, so the next call tries again. One instance serves every sender built on the key — a
87
+ * host keeps it across runs, and builds the senders per run.
88
+ */
89
+ export declare class ApnsProviderToken {
90
+ private readonly options;
91
+ private signed;
92
+ private signing;
93
+ constructor(options: ApnsProviderTokenOptions);
94
+ /** The current token, signed now if there is none or it has aged out. */
95
+ token(now?: number): Promise<string>;
96
+ /** Forget the token: APNs refused it (`ExpiredProviderToken`), so the next call signs a new one. */
97
+ invalidate(): void;
98
+ }
99
+ export declare class ApnsPushSender implements MessageSender {
100
+ private readonly options;
101
+ constructor(options: ApnsPushOptions);
102
+ send(message: OutboundMessage): Promise<void | SendResult>;
103
+ }
104
+ /** APNs error bodies are `{ "reason": "…" }`. */
105
+ export declare function apnsReason(body: string): string;
106
+ /** ES256-sign the APNs provider token: header `kid`, claims `iss` (team) and `iat`. */
107
+ export declare function signApnsJwt(key: ApnsProviderTokenOptions, nowMs?: number): Promise<string>;
108
+ /** The `.p8` as it is usually shipped in a secret: base64 of the file. */
109
+ export declare function apnsKeyFromBase64(value: string): string;
110
+ //# sourceMappingURL=apns.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apns.d.mts","names":[],"sources":["../src/apns.ts"],"mappings":";;;;;;;;;;;;;;;;iBAoBiB;;EAEf;;EAEA;;EAEA;;iBAGe;;EAEf,aAAa;;EAEb;;;;;;;EAOA;EACA,QAAQ;;;;;;EAMR;;EAEA,eAAe;;qBAGJ;WACX;WACA;;;;;;;;;;;;;;;;;;;;;;;;qBAyBW,oBAAoB;;;;;;;;wBAwBX,cAAc,yBAAyB;;;;;;;;qBAqBhD;mBAIkB;UAHrB;UACA;EAER,YAA6B,SAAS;;EAGhC,MAAM,eAAmB;;EAgB/B;;qBAKW,0BAA0B;mBACR;EAA7B,YAA6B,SAAS;EAEhC,KAAK,SAAS,kBAAkB,eAAe;;;wBAsFvC,WAAW;;wBAUL,YACpB,KAAK,0BACL,iBACC;;wBAoBa,kBAAkB"}
package/dist/apns.mjs ADDED
@@ -0,0 +1,207 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { PermanentError, isRetryableStatus } from "./engine/retry.mjs";
3
+ import { base64url, pemToDer } from "./jwt.mjs";
4
+ // src/apns.ts
5
+ const APNS_HOSTS = {
6
+ sandbox: "https://api.sandbox.push.apple.com",
7
+ production: "https://api.push.apple.com"
8
+ };
9
+ /**
10
+ * How an APNs answer is classified, after Apple's response table
11
+ * (https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns):
12
+ *
13
+ * - dead token: HTTP 410 `Unregistered` (the app was removed, or the token is inactive for the
14
+ * topic) and 400 `ExpiredToken`. The device will never deliver again, so the copy settles
15
+ * undelivered and the host forgets the token.
16
+ * - undelivered, device kept: 400 `BadDeviceToken` and 400 `DeviceTokenNotForTopic`. Apple gives
17
+ * the first for a malformed token but just as well for a token of the other environment (a
18
+ * sandbox build pushed through the production host), and the second for a token of another
19
+ * app (another bundle id: a development build registered against this backend). Either is
20
+ * about this one device — unless the deployment's own environment or topic is wrong, when
21
+ * every device answers so. The copy settles with the reason, so the report shows it; nothing
22
+ * is deleted on a guess, and the user's other devices and the rest of the journey go on.
23
+ * - configuration: the topic, certificate or provider key is wrong. Every device on this app
24
+ * would answer the same, so it is a `PermanentError` and the devices are kept — they are fine,
25
+ * the deployment is not.
26
+ * - transient: 429 (`TooManyRequests`, `TooManyProviderTokenUpdates`), 5xx (`InternalServerError`,
27
+ * `ServiceUnavailable`, `Shutdown`) and 403 `ExpiredProviderToken`, which a fresh token fixes.
28
+ * - everything else (400 `BadMessageId`, `BadPriority`, `PayloadEmpty`, 413 `PayloadTooLarge`,
29
+ * 404 `BadPath`, 405 `MethodNotAllowed`, …) is this request itself: a `PermanentError`.
30
+ */
31
+ const DEAD_TOKEN_REASONS = /* @__PURE__ */ new Set(["Unregistered", "ExpiredToken"]);
32
+ /** This one token is refused, and may be fine elsewhere: the copy settles and the device is kept. */
33
+ const DEVICE_REASONS = /* @__PURE__ */ new Set(["BadDeviceToken", "DeviceTokenNotForTopic"]);
34
+ /** The app's topic, certificate or provider key is wrong: the request is refused for every device. */
35
+ const CONFIGURATION_REASONS = /* @__PURE__ */ new Set([
36
+ "TopicDisallowed",
37
+ "BadTopic",
38
+ "MissingTopic",
39
+ "BadCertificate",
40
+ "BadCertificateEnvironment",
41
+ "Forbidden",
42
+ "InvalidProviderToken",
43
+ "MissingProviderToken"
44
+ ]);
45
+ /**
46
+ * The copy's identity on the wire: a canonical UUID derived from the idempotency key (SHA-256, the
47
+ * first 16 bytes laid out as an RFC 9562 v8 UUID). The same on every attempt, so a resend of the
48
+ * same copy carries the same `apns-id` and — as `apns-collapse-id`, which is limited to 64 bytes —
49
+ * collapses onto the first notification. The whole key is hashed: cut to 64 bytes it would lose
50
+ * the node id at its end, and two nodes of one instance would collapse into one notification.
51
+ */
52
+ async function apnsIdFromKey(idempotencyKey) {
53
+ const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(idempotencyKey))).slice(0, 16);
54
+ bytes[6] = bytes[6] & 15 | 128;
55
+ bytes[8] = bytes[8] & 63 | 128;
56
+ const hex = Buffer.from(bytes).toString("hex");
57
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
58
+ }
59
+ /** Apple: reuse a provider token for at least 20 minutes, never past 60. */
60
+ const TOKEN_TTL_MS = 3e6;
61
+ /**
62
+ * The provider JWT for one APNs auth key, signed once and reused for `TOKEN_TTL_MS`: Apple
63
+ * answers a sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`. Concurrent
64
+ * callers on a fresh or aged token share the one signing in flight, and a signing that failed is
65
+ * not kept, so the next call tries again. One instance serves every sender built on the key — a
66
+ * host keeps it across runs, and builds the senders per run.
67
+ */
68
+ var ApnsProviderToken = class {
69
+ options;
70
+ signed;
71
+ signing;
72
+ constructor(options) {
73
+ this.options = options;
74
+ }
75
+ /** The current token, signed now if there is none or it has aged out. */
76
+ async token(now = Date.now()) {
77
+ if (this.signed !== void 0 && now - this.signed.issuedAt < TOKEN_TTL_MS) return this.signed.value;
78
+ this.signing ??= signApnsJwt(this.options, now).then((value) => {
79
+ this.signed = {
80
+ value,
81
+ issuedAt: now
82
+ };
83
+ return value;
84
+ }).finally(() => {
85
+ this.signing = void 0;
86
+ });
87
+ return this.signing;
88
+ }
89
+ /** Forget the token: APNs refused it (`ExpiredProviderToken`), so the next call signs a new one. */
90
+ invalidate() {
91
+ this.signed = void 0;
92
+ }
93
+ };
94
+ var ApnsPushSender = class {
95
+ options;
96
+ constructor(options) {
97
+ this.options = options;
98
+ }
99
+ async send(message) {
100
+ if (message.channel !== "push") throw new Error(`ApnsPushSender: unsupported channel '${message.channel}'`);
101
+ if (message.recipient === void 0) throw new Error(`ApnsPushSender: no push token for user '${message.userId}'`);
102
+ const { title, body, image, url } = await this.options.render(message.template, message.props);
103
+ const mutable = image !== void 0 || message.tracking?.data?.delivered_url !== void 0;
104
+ const upstream = APNS_HOSTS[this.options.environment];
105
+ const origin = this.options.origin ?? upstream;
106
+ const doFetch = this.options.fetch ?? fetch;
107
+ const copyId = await apnsIdFromKey(message.idempotencyKey);
108
+ const response = await doFetch(`${origin}/3/device/${message.recipient}`, {
109
+ method: "POST",
110
+ headers: {
111
+ authorization: `bearer ${await this.options.credentials.token()}`,
112
+ "apns-topic": this.options.topic,
113
+ "apns-push-type": "alert",
114
+ "apns-priority": "10",
115
+ "apns-id": copyId,
116
+ "apns-collapse-id": copyId,
117
+ "content-type": "application/json",
118
+ ...this.options.origin === void 0 ? {} : { "apns-relay-upstream": upstream }
119
+ },
120
+ body: JSON.stringify({
121
+ aps: {
122
+ alert: {
123
+ title,
124
+ body
125
+ },
126
+ sound: "default",
127
+ ...mutable ? { "mutable-content": 1 } : {}
128
+ },
129
+ template: message.template,
130
+ idempotencyKey: message.idempotencyKey,
131
+ ...image === void 0 ? {} : { image },
132
+ ...url === void 0 ? {} : { url },
133
+ ...message.tracking?.data
134
+ })
135
+ });
136
+ if (response.ok) return;
137
+ const text = await response.text();
138
+ const { status } = response;
139
+ const reason = apnsReason(text) || (status === 410 ? "Unregistered" : "");
140
+ if (status === 410 || DEAD_TOKEN_REASONS.has(reason)) {
141
+ console.warn(`[apns] token gone for user ${message.userId}: ${reason}`);
142
+ return {
143
+ delivered: false,
144
+ reason
145
+ };
146
+ }
147
+ if (DEVICE_REASONS.has(reason)) {
148
+ console.warn(`[apns] refused for user ${message.userId}: ${status} ${reason}`);
149
+ return {
150
+ delivered: false,
151
+ reason
152
+ };
153
+ }
154
+ if (reason === "ExpiredProviderToken") {
155
+ this.options.credentials.invalidate();
156
+ throw new Error(`APNs send failed: ${status} ${reason} (provider token renewed for the retry)`);
157
+ }
158
+ if (CONFIGURATION_REASONS.has(reason)) throw new PermanentError(`APNs refused the request for topic '${this.options.topic}' (${this.options.environment}): ${status} ${reason}`, { reason });
159
+ if (isRetryableStatus(status)) throw new Error(`APNs send failed: ${status} ${reason || text}`);
160
+ throw new PermanentError(`APNs refused the request: ${status} ${reason || text}`, { reason: reason || `Refused${status}` });
161
+ }
162
+ };
163
+ /** APNs error bodies are `{ "reason": "…" }`. */
164
+ function apnsReason(body) {
165
+ try {
166
+ return JSON.parse(body).reason ?? "";
167
+ } catch {
168
+ return "";
169
+ }
170
+ }
171
+ /** ES256-sign the APNs provider token: header `kid`, claims `iss` (team) and `iat`. */
172
+ async function signApnsJwt(key, nowMs = Date.now()) {
173
+ const header = base64url(JSON.stringify({
174
+ alg: "ES256",
175
+ kid: key.keyId
176
+ }));
177
+ const claims = base64url(JSON.stringify({
178
+ iss: key.teamId,
179
+ iat: Math.floor(nowMs / 1e3)
180
+ }));
181
+ const cryptoKey = await crypto.subtle.importKey("pkcs8", pemToDer(key.privateKey), {
182
+ name: "ECDSA",
183
+ namedCurve: "P-256"
184
+ }, false, ["sign"]);
185
+ const signature = await crypto.subtle.sign({
186
+ name: "ECDSA",
187
+ hash: "SHA-256"
188
+ }, cryptoKey, new TextEncoder().encode(`${header}.${claims}`));
189
+ return `${header}.${claims}.${base64url(new Uint8Array(signature))}`;
190
+ }
191
+ /** The `.p8` as it is usually shipped in a secret: base64 of the file. */
192
+ function apnsKeyFromBase64(value) {
193
+ let pem;
194
+ try {
195
+ pem = Buffer.from(value, "base64").toString();
196
+ } catch (error) {
197
+ throw new PermanentError("APNs key is not base64 (expected the .p8 file, base64-encoded)", {
198
+ reason: "bad_credentials",
199
+ cause: error
200
+ });
201
+ }
202
+ if (!pem.includes("-----BEGIN PRIVATE KEY-----")) throw new PermanentError("APNs key is not a PKCS #8 PEM (.p8) file", { reason: "bad_credentials" });
203
+ return pem;
204
+ }
205
+ export { APNS_HOSTS, ApnsProviderToken, ApnsPushSender, DEAD_TOKEN_REASONS, apnsIdFromKey, apnsKeyFromBase64, apnsReason, signApnsJwt };
206
+
207
+ //# sourceMappingURL=apns.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apns.mjs","names":[],"sources":["../src/apns.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\nimport type { MessageSender, OutboundMessage, SendResult } from './engine';\nimport { PermanentError, isRetryableStatus } from './engine/retry';\nimport { base64url, pemToDer } from './jwt';\nimport type { PushRenderer } from './push';\n\n/**\n * `sendwend/apns` — iOS push delivery straight to the Apple Push\n * Notification service, token-based (an APNs auth key, the `.p8` file from the\n * developer portal). No Firebase in between: the app registers the APNs device\n * token in its own device table, and the host's DeviceDirectory hands it to the\n * engine, which sends one message per device.\n * No dependencies: the provider JWT is ES256-signed with WebCrypto.\n *\n * APNs speaks HTTP/2 only. A deployed Worker's `fetch` negotiates it, but\n * workerd under `wrangler dev` does not (the connection is dropped), so a local\n * host points `origin` at the Node relay in `sendwend/apns-relay`.\n */\n\n/** The APNs auth key — the `.p8` file from the developer portal, and the ids that name it. */\nexport interface ApnsProviderTokenOptions {\n /** The key's 10-character id, shown next to it in the developer portal. */\n keyId: string;\n /** The Apple Developer team id. */\n teamId: string;\n /** The `.p8` file's contents: PEM, `-----BEGIN PRIVATE KEY-----` (PKCS #8, P-256). */\n privateKey: string;\n}\n\nexport interface ApnsPushOptions {\n /** The provider token the requests are signed with — shared by every sender on the same key. */\n credentials: ApnsProviderToken;\n /** The app's bundle id — APNs's `apns-topic`. */\n topic: string;\n /**\n * Which APNs environment the device tokens come from: `sandbox` for builds\n * signed with `aps-environment: development` (Xcode, the simulator),\n * `production` for App Store and TestFlight builds. A token from one is\n * `BadDeviceToken` on the other.\n */\n environment: 'sandbox' | 'production';\n render: PushRenderer;\n /**\n * POST here instead of Apple's host — the dev relay, which forwards over\n * HTTP/2. The real host still travels along (`apns-relay-upstream`), so the\n * relay needs no configuration of its own.\n */\n origin?: string;\n /** Fetch implementation (defaults to the global one). */\n fetch?: typeof fetch;\n}\n\nexport const APNS_HOSTS = {\n sandbox: 'https://api.sandbox.push.apple.com',\n production: 'https://api.push.apple.com',\n} as const;\n\n/**\n * How an APNs answer is classified, after Apple's response table\n * (https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns):\n *\n * - dead token: HTTP 410 `Unregistered` (the app was removed, or the token is inactive for the\n * topic) and 400 `ExpiredToken`. The device will never deliver again, so the copy settles\n * undelivered and the host forgets the token.\n * - undelivered, device kept: 400 `BadDeviceToken` and 400 `DeviceTokenNotForTopic`. Apple gives\n * the first for a malformed token but just as well for a token of the other environment (a\n * sandbox build pushed through the production host), and the second for a token of another\n * app (another bundle id: a development build registered against this backend). Either is\n * about this one device — unless the deployment's own environment or topic is wrong, when\n * every device answers so. The copy settles with the reason, so the report shows it; nothing\n * is deleted on a guess, and the user's other devices and the rest of the journey go on.\n * - configuration: the topic, certificate or provider key is wrong. Every device on this app\n * would answer the same, so it is a `PermanentError` and the devices are kept — they are fine,\n * the deployment is not.\n * - transient: 429 (`TooManyRequests`, `TooManyProviderTokenUpdates`), 5xx (`InternalServerError`,\n * `ServiceUnavailable`, `Shutdown`) and 403 `ExpiredProviderToken`, which a fresh token fixes.\n * - everything else (400 `BadMessageId`, `BadPriority`, `PayloadEmpty`, 413 `PayloadTooLarge`,\n * 404 `BadPath`, 405 `MethodNotAllowed`, …) is this request itself: a `PermanentError`.\n */\nexport const DEAD_TOKEN_REASONS: ReadonlySet<string> = new Set(['Unregistered', 'ExpiredToken']);\n\n/** This one token is refused, and may be fine elsewhere: the copy settles and the device is kept. */\nconst DEVICE_REASONS: ReadonlySet<string> = new Set(['BadDeviceToken', 'DeviceTokenNotForTopic']);\n\n/** The app's topic, certificate or provider key is wrong: the request is refused for every device. */\nconst CONFIGURATION_REASONS: ReadonlySet<string> = new Set([\n 'TopicDisallowed',\n 'BadTopic',\n 'MissingTopic',\n 'BadCertificate',\n 'BadCertificateEnvironment',\n 'Forbidden',\n 'InvalidProviderToken',\n 'MissingProviderToken',\n]);\n\n/**\n * The copy's identity on the wire: a canonical UUID derived from the idempotency key (SHA-256, the\n * first 16 bytes laid out as an RFC 9562 v8 UUID). The same on every attempt, so a resend of the\n * same copy carries the same `apns-id` and — as `apns-collapse-id`, which is limited to 64 bytes —\n * collapses onto the first notification. The whole key is hashed: cut to 64 bytes it would lose\n * the node id at its end, and two nodes of one instance would collapse into one notification.\n */\nexport async function apnsIdFromKey(idempotencyKey: string): Promise<string> {\n const digest = new Uint8Array(\n await crypto.subtle.digest('SHA-256', new TextEncoder().encode(idempotencyKey))\n );\n const bytes = digest.slice(0, 16);\n bytes[6] = (bytes[6] & 0x0f) | 0x80; // version 8: custom, deterministic\n bytes[8] = (bytes[8] & 0x3f) | 0x80; // RFC 4122 variant\n const hex = Buffer.from(bytes).toString('hex');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/** Apple: reuse a provider token for at least 20 minutes, never past 60. */\nconst TOKEN_TTL_MS = 50 * 60_000;\n\n/**\n * The provider JWT for one APNs auth key, signed once and reused for `TOKEN_TTL_MS`: Apple\n * answers a sender that re-signs on every push with 429 `TooManyProviderTokenUpdates`. Concurrent\n * callers on a fresh or aged token share the one signing in flight, and a signing that failed is\n * not kept, so the next call tries again. One instance serves every sender built on the key — a\n * host keeps it across runs, and builds the senders per run.\n */\nexport class ApnsProviderToken {\n private signed: { value: string; issuedAt: number } | undefined;\n private signing: Promise<string> | undefined;\n\n constructor(private readonly options: ApnsProviderTokenOptions) {}\n\n /** The current token, signed now if there is none or it has aged out. */\n async token(now = Date.now()): Promise<string> {\n if (this.signed !== undefined && now - this.signed.issuedAt < TOKEN_TTL_MS) {\n return this.signed.value;\n }\n this.signing ??= signApnsJwt(this.options, now)\n .then((value) => {\n this.signed = { value, issuedAt: now };\n return value;\n })\n .finally(() => {\n this.signing = undefined;\n });\n return this.signing;\n }\n\n /** Forget the token: APNs refused it (`ExpiredProviderToken`), so the next call signs a new one. */\n invalidate(): void {\n this.signed = undefined;\n }\n}\n\nexport class ApnsPushSender implements MessageSender {\n constructor(private readonly options: ApnsPushOptions) {}\n\n async send(message: OutboundMessage): Promise<void | SendResult> {\n if (message.channel !== 'push') {\n throw new Error(`ApnsPushSender: unsupported channel '${message.channel}'`);\n }\n if (message.recipient === undefined) {\n throw new Error(`ApnsPushSender: no push token for user '${message.userId}'`);\n }\n const { title, body, image, url } = await this.options.render(message.template, message.props);\n // A notification service extension runs only for a mutable push: it attaches the image and\n // reports the device delivery (`delivered_url`)\n const mutable = image !== undefined || message.tracking?.data?.delivered_url !== undefined;\n const upstream = APNS_HOSTS[this.options.environment];\n const origin = this.options.origin ?? upstream;\n const doFetch = this.options.fetch ?? fetch;\n\n const copyId = await apnsIdFromKey(message.idempotencyKey);\n const response = await doFetch(`${origin}/3/device/${message.recipient}`, {\n method: 'POST',\n headers: {\n authorization: `bearer ${await this.options.credentials.token()}`,\n 'apns-topic': this.options.topic,\n 'apns-push-type': 'alert',\n 'apns-priority': '10',\n // A resend of the same copy (an at-least-once retry after APNs accepted the first attempt)\n // carries the same id and collapses onto the first notification instead of showing twice\n 'apns-id': copyId,\n 'apns-collapse-id': copyId,\n 'content-type': 'application/json',\n ...(this.options.origin === undefined ? {} : { 'apns-relay-upstream': upstream }),\n },\n body: JSON.stringify({\n aps: {\n alert: { title, body },\n sound: 'default',\n ...(mutable ? { 'mutable-content': 1 } : {}),\n },\n // The template key travels so the app can route a tap; the idempotency\n // key lets the app de-duplicate a redelivered push.\n template: message.template,\n idempotencyKey: message.idempotencyKey,\n ...(image === undefined ? {} : { image }),\n ...(url === undefined ? {} : { url }),\n ...message.tracking?.data,\n }),\n });\n if (response.ok) return;\n\n const text = await response.text();\n const { status } = response;\n // A 410 without a body is still \"unregistered\": settle it under that reason\n const reason = apnsReason(text) || (status === 410 ? 'Unregistered' : '');\n if (status === 410 || DEAD_TOKEN_REASONS.has(reason)) {\n // A dead token is a fact about the recipient, not a transient failure:\n // report it and move on, so the step does not retry into the same wall.\n console.warn(`[apns] token gone for user ${message.userId}: ${reason}`);\n return { delivered: false, reason };\n }\n if (DEVICE_REASONS.has(reason)) {\n // The token, its environment or its app: settled so the report says which device, nothing\n // deleted, and one device's refusal does not end the journey for the others\n console.warn(`[apns] refused for user ${message.userId}: ${status} ${reason}`);\n return { delivered: false, reason };\n }\n if (reason === 'ExpiredProviderToken') {\n // The token aged out (clock skew, a long-lived isolate): sign a new one on the retry\n this.options.credentials.invalidate();\n throw new Error(\n `APNs send failed: ${status} ${reason} (provider token renewed for the retry)`\n );\n }\n if (CONFIGURATION_REASONS.has(reason)) {\n throw new PermanentError(\n `APNs refused the request for topic '${this.options.topic}' (${this.options.environment}): ${status} ${reason}`,\n { reason }\n );\n }\n if (isRetryableStatus(status)) {\n throw new Error(`APNs send failed: ${status} ${reason || text}`);\n }\n throw new PermanentError(`APNs refused the request: ${status} ${reason || text}`, {\n reason: reason || `Refused${status}`,\n });\n }\n}\n\n/** APNs error bodies are `{ \"reason\": \"…\" }`. */\nexport function apnsReason(body: string): string {\n try {\n const parsed = JSON.parse(body) as { reason?: string };\n return parsed.reason ?? '';\n } catch {\n return '';\n }\n}\n\n/** ES256-sign the APNs provider token: header `kid`, claims `iss` (team) and `iat`. */\nexport async function signApnsJwt(\n key: ApnsProviderTokenOptions,\n nowMs = Date.now()\n): Promise<string> {\n const header = base64url(JSON.stringify({ alg: 'ES256', kid: key.keyId }));\n const claims = base64url(JSON.stringify({ iss: key.teamId, iat: Math.floor(nowMs / 1000) }));\n const cryptoKey = await crypto.subtle.importKey(\n 'pkcs8',\n pemToDer(key.privateKey),\n { name: 'ECDSA', namedCurve: 'P-256' },\n false,\n ['sign']\n );\n // WebCrypto's ECDSA signature is the raw r‖s pair, which is exactly JWS's ES256 encoding.\n const signature = await crypto.subtle.sign(\n { name: 'ECDSA', hash: 'SHA-256' },\n cryptoKey,\n new TextEncoder().encode(`${header}.${claims}`)\n );\n return `${header}.${claims}.${base64url(new Uint8Array(signature))}`;\n}\n\n/** The `.p8` as it is usually shipped in a secret: base64 of the file. */\nexport function apnsKeyFromBase64(value: string): string {\n let pem: string;\n try {\n pem = Buffer.from(value, 'base64').toString();\n } catch (error) {\n // A secret that is not base64 is the same on every attempt: not worth a retry\n throw new PermanentError('APNs key is not base64 (expected the .p8 file, base64-encoded)', {\n reason: 'bad_credentials',\n cause: error,\n });\n }\n if (!pem.includes('-----BEGIN PRIVATE KEY-----')) {\n throw new PermanentError('APNs key is not a PKCS #8 PEM (.p8) file', {\n reason: 'bad_credentials',\n });\n }\n return pem;\n}\n"],"mappings":"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"}
@@ -0,0 +1,105 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _aws_durable_execution_sdk_js = require("@aws/durable-execution-sdk-js");
3
+ const require_engine_retry = require("../engine/retry.cjs");
4
+ const require_store_identity = require("../store/identity.cjs");
5
+ require("../store/index.cjs");
6
+ // src/aws/engine-step.ts
7
+ /**
8
+ * EngineStep over a Lambda durable execution.
9
+ *
10
+ * Steps, sleeps and wakes map onto the SDK's `step`, `wait` and callbacks. A wake handle is a
11
+ * callback, which is one-shot, so every wait arms a fresh one (the interpreter subscribes on
12
+ * every attempt): created where the durable context allows it — outside any step, so its id
13
+ * replays — then recorded in Postgres together with the subscription rows, numbered by a
14
+ * generation so a late wake or cleanup of an older wait cannot touch a newer one. The callback
15
+ * is only a hint; the facts the wait re-checks are Postgres'.
16
+ */
17
+ /** What the step retries, bounded: 6 attempts with exponential backoff up to a minute. */
18
+ function stepRetry(error, attempt) {
19
+ if (!require_engine_retry.isRetryable(error) || attempt >= 6) return { shouldRetry: false };
20
+ return {
21
+ shouldRetry: true,
22
+ delay: { seconds: Math.min(60, 2 ** attempt) }
23
+ };
24
+ }
25
+ var AwsEngineStep = class {
26
+ context;
27
+ store;
28
+ executions;
29
+ lambda;
30
+ userId;
31
+ instanceId;
32
+ generation = 0;
33
+ armed;
34
+ constructor(context, store, executions, lambda, userId, instanceId) {
35
+ this.context = context;
36
+ this.store = store;
37
+ this.executions = executions;
38
+ this.lambda = lambda;
39
+ this.userId = userId;
40
+ this.instanceId = instanceId;
41
+ }
42
+ do(name, fn) {
43
+ return this.context.step(name, () => fn(), { retryStrategy: stepRetry });
44
+ }
45
+ async sleep(name, ms) {
46
+ if (!(ms > 0)) return;
47
+ await this.context.wait(name, { seconds: Math.ceil(ms / 1e3) });
48
+ }
49
+ async subscribe(name, events, options = {}) {
50
+ const generation = ++this.generation;
51
+ const { deadlineMs } = options;
52
+ const seconds = deadlineMs === void 0 ? void 0 : await this.context.step(`${name}:timeout`, async () => Math.max(1, Math.ceil((deadlineMs - Date.now()) / 1e3)));
53
+ const [promise, callbackId] = await this.context.createCallback(`${name}:callback`, seconds === void 0 ? {} : { timeout: { seconds } });
54
+ const previous = this.armed;
55
+ this.armed = {
56
+ promise,
57
+ callbackId,
58
+ generation,
59
+ settled: false
60
+ };
61
+ await this.context.step(name, async () => {
62
+ const owner = await require_store_identity.instanceOwner(this.store, this.instanceId, this.userId);
63
+ await this.store.subscribe(this.instanceId, owner, events, Date.now());
64
+ await this.executions.armCallback(this.instanceId, {
65
+ id: callbackId,
66
+ generation,
67
+ deadlineAt: deadlineMs
68
+ });
69
+ if (previous !== void 0 && !previous.settled) await this.lambda.completeCallback(previous.callbackId, "{}");
70
+ }, { retryStrategy: stepRetry });
71
+ if (previous !== void 0) previous.settled = true;
72
+ }
73
+ async unsubscribe(name) {
74
+ const armed = this.armed;
75
+ await this.context.step(name, async () => {
76
+ await this.store.unsubscribe(this.instanceId);
77
+ if (armed === void 0) return;
78
+ await this.executions.clearCallback(this.instanceId, armed.generation);
79
+ if (!armed.settled) await this.lambda.completeCallback(armed.callbackId, "{}");
80
+ }, { retryStrategy: stepRetry });
81
+ if (armed !== void 0) armed.settled = true;
82
+ this.armed = void 0;
83
+ }
84
+ /**
85
+ * The timeout is ignored on purpose: the callback's own timeout was set from the deadline
86
+ * when it was armed (`subscribe`), and only its expiry says the wait timed out.
87
+ */
88
+ async waitForWake(name, _wait) {
89
+ const armed = this.armed;
90
+ if (armed === void 0) throw new Error(`waitForWake '${name}' without a subscribe: nothing is armed to wake it`);
91
+ try {
92
+ await armed.promise;
93
+ return "event";
94
+ } catch (error) {
95
+ if (error instanceof _aws_durable_execution_sdk_js.CallbackTimeoutError) return "timeout";
96
+ throw error;
97
+ } finally {
98
+ armed.settled = true;
99
+ }
100
+ }
101
+ };
102
+ exports.AwsEngineStep = AwsEngineStep;
103
+ exports.stepRetry = stepRetry;
104
+
105
+ //# sourceMappingURL=engine-step.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-step.cjs","names":["isRetryable","instanceOwner","CallbackTimeoutError"],"sources":["../../src/aws/engine-step.ts"],"sourcesContent":["import {\n CallbackTimeoutError,\n type DurableContext,\n type DurablePromise,\n type RetryDecision,\n} from '@aws/durable-execution-sdk-js';\nimport type { EngineStep } from '../engine/ports';\nimport { isRetryable } from '../engine/retry';\nimport { type ExecutionRegistry, type JourneyStore, instanceOwner } from '../store/index';\nimport type { LambdaApi } from './lambda-api';\n\n/**\n * EngineStep over a Lambda durable execution.\n *\n * Steps, sleeps and wakes map onto the SDK's `step`, `wait` and callbacks. A wake handle is a\n * callback, which is one-shot, so every wait arms a fresh one (the interpreter subscribes on\n * every attempt): created where the durable context allows it — outside any step, so its id\n * replays — then recorded in Postgres together with the subscription rows, numbered by a\n * generation so a late wake or cleanup of an older wait cannot touch a newer one. The callback\n * is only a hint; the facts the wait re-checks are Postgres'.\n */\n\n/** What the step retries, bounded: 6 attempts with exponential backoff up to a minute. */\nexport function stepRetry(error: Error, attempt: number): RetryDecision {\n if (!isRetryable(error) || attempt >= 6) return { shouldRetry: false };\n return { shouldRetry: true, delay: { seconds: Math.min(60, 2 ** attempt) } };\n}\n\ninterface Armed {\n promise: DurablePromise<string>;\n callbackId: string;\n generation: number;\n /** The wait consumed it (woken or timed out): there is nothing left to close. */\n settled: boolean;\n}\n\nexport class AwsEngineStep implements EngineStep {\n private generation = 0;\n private armed: Armed | undefined;\n\n constructor(\n private readonly context: DurableContext,\n private readonly store: JourneyStore,\n private readonly executions: ExecutionRegistry,\n private readonly lambda: LambdaApi,\n private readonly userId: string,\n private readonly instanceId: string\n ) {}\n\n do<T>(name: string, fn: () => Promise<T>): Promise<T> {\n return this.context.step(name, () => fn(), { retryStrategy: stepRetry });\n }\n\n async sleep(name: string, ms: number): Promise<void> {\n // A wait is whole seconds: rounded up, so it never ends early; nothing to wait at zero\n if (!(ms > 0)) return;\n await this.context.wait(name, { seconds: Math.ceil(ms / 1000) });\n }\n\n async subscribe(\n name: string,\n events: readonly string[],\n options: { deadlineMs?: number } = {}\n ): Promise<void> {\n const generation = ++this.generation;\n const { deadlineMs } = options;\n // The callback's own timeout is the wait's deadline: fixed when it is created\n const seconds =\n deadlineMs === undefined\n ? undefined\n : await this.context.step(`${name}:timeout`, async () =>\n Math.max(1, Math.ceil((deadlineMs - Date.now()) / 1000))\n );\n const [promise, callbackId] = await this.context.createCallback(\n `${name}:callback`,\n seconds === undefined ? {} : { timeout: { seconds } }\n );\n const previous = this.armed;\n this.armed = { promise, callbackId, generation, settled: false };\n await this.context.step(\n name,\n async () => {\n // Rows first, then the callback: a wake that lands in between finds the rows and the\n // callback of the last wait — its completion is refused, and this wait checks the facts\n const owner = await instanceOwner(this.store, this.instanceId, this.userId);\n await this.store.subscribe(this.instanceId, owner, events, Date.now());\n await this.executions.armCallback(this.instanceId, {\n id: callbackId,\n generation,\n deadlineAt: deadlineMs,\n });\n if (previous !== undefined && !previous.settled) {\n await this.lambda.completeCallback(previous.callbackId, '{}');\n }\n },\n { retryStrategy: stepRetry }\n );\n if (previous !== undefined) previous.settled = true;\n }\n\n async unsubscribe(name: string): Promise<void> {\n const armed = this.armed;\n await this.context.step(\n name,\n async () => {\n await this.store.unsubscribe(this.instanceId);\n if (armed === undefined) return;\n await this.executions.clearCallback(this.instanceId, armed.generation);\n // The condition held before the wait parked: its callback is closed through the public\n // API (a closed one answers false), rather than left open until it times out\n if (!armed.settled) await this.lambda.completeCallback(armed.callbackId, '{}');\n },\n { retryStrategy: stepRetry }\n );\n if (armed !== undefined) armed.settled = true;\n this.armed = undefined;\n }\n\n /**\n * The timeout is ignored on purpose: the callback's own timeout was set from the deadline\n * when it was armed (`subscribe`), and only its expiry says the wait timed out.\n */\n async waitForWake(\n name: string,\n _wait: { timeoutMs: number; deadlineMs: number }\n ): Promise<'event' | 'timeout'> {\n const armed = this.armed;\n if (armed === undefined) {\n throw new Error(`waitForWake '${name}' without a subscribe: nothing is armed to wake it`);\n }\n try {\n await armed.promise;\n return 'event';\n } catch (error) {\n // Only the callback's own expiry is a timeout; any other failure is a failure\n if (error instanceof CallbackTimeoutError) return 'timeout';\n throw error;\n } finally {\n armed.settled = true;\n }\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1,42 @@
1
+ import { DurableContext, RetryDecision } from "@aws/durable-execution-sdk-js";
2
+ import { EngineStep } from "../engine/ports.cjs";
3
+ import { ExecutionRegistry, JourneyStore } from "../store/index.cjs";
4
+ import { LambdaApi } from "./lambda-api.cjs";
5
+ /**
6
+ * EngineStep over a Lambda durable execution.
7
+ *
8
+ * Steps, sleeps and wakes map onto the SDK's `step`, `wait` and callbacks. A wake handle is a
9
+ * callback, which is one-shot, so every wait arms a fresh one (the interpreter subscribes on
10
+ * every attempt): created where the durable context allows it — outside any step, so its id
11
+ * replays — then recorded in Postgres together with the subscription rows, numbered by a
12
+ * generation so a late wake or cleanup of an older wait cannot touch a newer one. The callback
13
+ * is only a hint; the facts the wait re-checks are Postgres'.
14
+ */
15
+ /** What the step retries, bounded: 6 attempts with exponential backoff up to a minute. */
16
+ export declare function stepRetry(error: Error, attempt: number): RetryDecision;
17
+ export declare class AwsEngineStep implements EngineStep {
18
+ private readonly context;
19
+ private readonly store;
20
+ private readonly executions;
21
+ private readonly lambda;
22
+ private readonly userId;
23
+ private readonly instanceId;
24
+ private generation;
25
+ private armed;
26
+ constructor(context: DurableContext, store: JourneyStore, executions: ExecutionRegistry, lambda: LambdaApi, userId: string, instanceId: string);
27
+ do<T>(name: string, fn: () => Promise<T>): Promise<T>;
28
+ sleep(name: string, ms: number): Promise<void>;
29
+ subscribe(name: string, events: readonly string[], options?: {
30
+ deadlineMs?: number;
31
+ }): Promise<void>;
32
+ unsubscribe(name: string): Promise<void>;
33
+ /**
34
+ * The timeout is ignored on purpose: the callback's own timeout was set from the deadline
35
+ * when it was armed (`subscribe`), and only its expiry says the wait timed out.
36
+ */
37
+ waitForWake(name: string, _wait: {
38
+ timeoutMs: number;
39
+ deadlineMs: number;
40
+ }): Promise<'event' | 'timeout'>;
41
+ }
42
+ //# sourceMappingURL=engine-step.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-step.d.cts","names":[],"sources":["../../src/aws/engine-step.ts"],"mappings":";;;;;;;;;;;;;;;wBAuBgB,UAAU,OAAO,OAAO,kBAAkB;qBAa7C,yBAAyB;mBAKjB;mBACA;mBACA;mBACA;mBACA;mBACA;UATX;UACA;EAER,YACmB,SAAS,gBACT,OAAO,cACP,YAAY,mBACZ,QAAQ,WACR,gBACA;EAGnB,GAAG,GAAG,cAAc,UAAU,QAAQ,KAAK,QAAQ;EAI7C,MAAM,cAAc,aAAa;EAMjC,UACJ,cACA,2BACA;IAAW;MACV;EAqCG,YAAY,eAAe;;;;;EAsB3B,YACJ,cACA;IAAS;IAAmB;MAC3B"}