sendwend 0.0.1 → 12.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2065 -22
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/apns-relay.cjs +91 -0
- package/dist/apns-relay.cjs.map +1 -0
- package/dist/apns-relay.d.cts +26 -0
- package/dist/apns-relay.d.cts.map +1 -0
- package/dist/apns-relay.d.mts +26 -0
- package/dist/apns-relay.d.mts.map +1 -0
- package/dist/apns-relay.mjs +90 -0
- package/dist/apns-relay.mjs.map +1 -0
- package/dist/apns.cjs +215 -0
- package/dist/apns.cjs.map +1 -0
- package/dist/apns.d.cts +110 -0
- package/dist/apns.d.cts.map +1 -0
- package/dist/apns.d.mts +110 -0
- package/dist/apns.d.mts.map +1 -0
- package/dist/apns.mjs +207 -0
- package/dist/apns.mjs.map +1 -0
- package/dist/aws/engine-step.cjs +105 -0
- package/dist/aws/engine-step.cjs.map +1 -0
- package/dist/aws/engine-step.d.cts +42 -0
- package/dist/aws/engine-step.d.cts.map +1 -0
- package/dist/aws/engine-step.d.mts +42 -0
- package/dist/aws/engine-step.d.mts.map +1 -0
- package/dist/aws/engine-step.mjs +103 -0
- package/dist/aws/engine-step.mjs.map +1 -0
- package/dist/aws/function-url.cjs +53 -0
- package/dist/aws/function-url.cjs.map +1 -0
- package/dist/aws/function-url.d.cts +36 -0
- package/dist/aws/function-url.d.cts.map +1 -0
- package/dist/aws/function-url.d.mts +36 -0
- package/dist/aws/function-url.d.mts.map +1 -0
- package/dist/aws/function-url.mjs +50 -0
- package/dist/aws/function-url.mjs.map +1 -0
- package/dist/aws/index.cjs +232 -0
- package/dist/aws/index.cjs.map +1 -0
- package/dist/aws/index.d.cts +73 -0
- package/dist/aws/index.d.cts.map +1 -0
- package/dist/aws/index.d.mts +73 -0
- package/dist/aws/index.d.mts.map +1 -0
- package/dist/aws/index.mjs +218 -0
- package/dist/aws/index.mjs.map +1 -0
- package/dist/aws/instances.cjs +218 -0
- package/dist/aws/instances.cjs.map +1 -0
- package/dist/aws/instances.d.cts +102 -0
- package/dist/aws/instances.d.cts.map +1 -0
- package/dist/aws/instances.d.mts +102 -0
- package/dist/aws/instances.d.mts.map +1 -0
- package/dist/aws/instances.mjs +214 -0
- package/dist/aws/instances.mjs.map +1 -0
- package/dist/aws/lambda-api.cjs +86 -0
- package/dist/aws/lambda-api.cjs.map +1 -0
- package/dist/aws/lambda-api.d.cts +41 -0
- package/dist/aws/lambda-api.d.cts.map +1 -0
- package/dist/aws/lambda-api.d.mts +41 -0
- package/dist/aws/lambda-api.d.mts.map +1 -0
- package/dist/aws/lambda-api.mjs +85 -0
- package/dist/aws/lambda-api.mjs.map +1 -0
- package/dist/client.cjs +216 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +193 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.mts +193 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +212 -0
- package/dist/client.mjs.map +1 -0
- package/dist/cloudflare/bindings.cjs +49 -0
- package/dist/cloudflare/bindings.cjs.map +1 -0
- package/dist/cloudflare/bindings.d.cts +31 -0
- package/dist/cloudflare/bindings.d.cts.map +1 -0
- package/dist/cloudflare/bindings.d.mts +31 -0
- package/dist/cloudflare/bindings.d.mts.map +1 -0
- package/dist/cloudflare/bindings.mjs +46 -0
- package/dist/cloudflare/bindings.mjs.map +1 -0
- package/dist/cloudflare/index.cjs +73 -0
- package/dist/cloudflare/index.d.cts +25 -0
- package/dist/cloudflare/index.d.mts +25 -0
- package/dist/cloudflare/index.mjs +20 -0
- package/dist/cloudflare/runner.cjs +200 -0
- package/dist/cloudflare/runner.cjs.map +1 -0
- package/dist/cloudflare/runner.d.cts +83 -0
- package/dist/cloudflare/runner.d.cts.map +1 -0
- package/dist/cloudflare/runner.d.mts +83 -0
- package/dist/cloudflare/runner.d.mts.map +1 -0
- package/dist/cloudflare/runner.mjs +199 -0
- package/dist/cloudflare/runner.mjs.map +1 -0
- package/dist/cloudflare/worker.cjs +106 -0
- package/dist/cloudflare/worker.cjs.map +1 -0
- package/dist/cloudflare/worker.d.cts +52 -0
- package/dist/cloudflare/worker.d.cts.map +1 -0
- package/dist/cloudflare/worker.d.mts +52 -0
- package/dist/cloudflare/worker.d.mts.map +1 -0
- package/dist/cloudflare/worker.mjs +104 -0
- package/dist/cloudflare/worker.mjs.map +1 -0
- package/dist/cloudflare/workers.d.cjs +0 -0
- package/dist/cloudflare/workers.d.cts +42 -0
- package/dist/cloudflare/workers.d.cts.map +1 -0
- package/dist/cloudflare/workers.d.mts +42 -0
- package/dist/cloudflare/workers.d.mts.map +1 -0
- package/dist/config.cjs +257 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +184 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +184 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +246 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract.cjs +222 -0
- package/dist/contract.cjs.map +1 -0
- package/dist/contract.d.cts +110 -0
- package/dist/contract.d.cts.map +1 -0
- package/dist/contract.d.mts +110 -0
- package/dist/contract.d.mts.map +1 -0
- package/dist/contract.mjs +216 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/date-time.cjs +22 -0
- package/dist/date-time.cjs.map +1 -0
- package/dist/date-time.d.cts +10 -0
- package/dist/date-time.d.cts.map +1 -0
- package/dist/date-time.d.mts +10 -0
- package/dist/date-time.d.mts.map +1 -0
- package/dist/date-time.mjs +21 -0
- package/dist/date-time.mjs.map +1 -0
- package/dist/dsl/action.cjs +25 -0
- package/dist/dsl/action.cjs.map +1 -0
- package/dist/dsl/action.d.cts +63 -0
- package/dist/dsl/action.d.cts.map +1 -0
- package/dist/dsl/action.d.mts +63 -0
- package/dist/dsl/action.d.mts.map +1 -0
- package/dist/dsl/action.mjs +24 -0
- package/dist/dsl/action.mjs.map +1 -0
- package/dist/dsl/base.cjs +33 -0
- package/dist/dsl/base.cjs.map +1 -0
- package/dist/dsl/base.d.cts +43 -0
- package/dist/dsl/base.d.cts.map +1 -0
- package/dist/dsl/base.d.mts +43 -0
- package/dist/dsl/base.d.mts.map +1 -0
- package/dist/dsl/base.mjs +29 -0
- package/dist/dsl/base.mjs.map +1 -0
- package/dist/dsl/bundle.cjs +287 -0
- package/dist/dsl/bundle.cjs.map +1 -0
- package/dist/dsl/bundle.d.cts +33 -0
- package/dist/dsl/bundle.d.cts.map +1 -0
- package/dist/dsl/bundle.d.mts +33 -0
- package/dist/dsl/bundle.d.mts.map +1 -0
- package/dist/dsl/bundle.mjs +284 -0
- package/dist/dsl/bundle.mjs.map +1 -0
- package/dist/dsl/condition.cjs +200 -0
- package/dist/dsl/condition.cjs.map +1 -0
- package/dist/dsl/condition.d.cts +151 -0
- package/dist/dsl/condition.d.cts.map +1 -0
- package/dist/dsl/condition.d.mts +151 -0
- package/dist/dsl/condition.d.mts.map +1 -0
- package/dist/dsl/condition.mjs +178 -0
- package/dist/dsl/condition.mjs.map +1 -0
- package/dist/dsl/flow.cjs +335 -0
- package/dist/dsl/flow.cjs.map +1 -0
- package/dist/dsl/flow.d.cts +278 -0
- package/dist/dsl/flow.d.cts.map +1 -0
- package/dist/dsl/flow.d.mts +278 -0
- package/dist/dsl/flow.d.mts.map +1 -0
- package/dist/dsl/flow.mjs +331 -0
- package/dist/dsl/flow.mjs.map +1 -0
- package/dist/dsl/index.cjs +37 -0
- package/dist/dsl/index.d.cts +34 -0
- package/dist/dsl/index.d.mts +34 -0
- package/dist/dsl/index.mjs +9 -0
- package/dist/dsl/refs.cjs +101 -0
- package/dist/dsl/refs.cjs.map +1 -0
- package/dist/dsl/refs.d.cts +127 -0
- package/dist/dsl/refs.d.cts.map +1 -0
- package/dist/dsl/refs.d.mts +127 -0
- package/dist/dsl/refs.d.mts.map +1 -0
- package/dist/dsl/refs.mjs +93 -0
- package/dist/dsl/refs.mjs.map +1 -0
- package/dist/dsl/template.cjs +19 -0
- package/dist/dsl/template.cjs.map +1 -0
- package/dist/dsl/template.d.cts +30 -0
- package/dist/dsl/template.d.cts.map +1 -0
- package/dist/dsl/template.d.mts +30 -0
- package/dist/dsl/template.d.mts.map +1 -0
- package/dist/dsl/template.mjs +18 -0
- package/dist/dsl/template.mjs.map +1 -0
- package/dist/dsl/trigger.cjs +53 -0
- package/dist/dsl/trigger.cjs.map +1 -0
- package/dist/dsl/trigger.d.cts +112 -0
- package/dist/dsl/trigger.d.cts.map +1 -0
- package/dist/dsl/trigger.d.mts +112 -0
- package/dist/dsl/trigger.d.mts.map +1 -0
- package/dist/dsl/trigger.mjs +52 -0
- package/dist/dsl/trigger.mjs.map +1 -0
- package/dist/dsl/workflow.cjs +143 -0
- package/dist/dsl/workflow.cjs.map +1 -0
- package/dist/dsl/workflow.d.cts +88 -0
- package/dist/dsl/workflow.d.cts.map +1 -0
- package/dist/dsl/workflow.d.mts +88 -0
- package/dist/dsl/workflow.d.mts.map +1 -0
- package/dist/dsl/workflow.mjs +142 -0
- package/dist/dsl/workflow.mjs.map +1 -0
- package/dist/email-context.cjs +28 -0
- package/dist/email-context.cjs.map +1 -0
- package/dist/email-context.d.cts +9 -0
- package/dist/email-context.d.cts.map +1 -0
- package/dist/email-context.d.mts +9 -0
- package/dist/email-context.d.mts.map +1 -0
- package/dist/email-context.mjs +26 -0
- package/dist/email-context.mjs.map +1 -0
- package/dist/email-sender.cjs +93 -0
- package/dist/email-sender.cjs.map +1 -0
- package/dist/email-sender.d.cts +88 -0
- package/dist/email-sender.d.cts.map +1 -0
- package/dist/email-sender.d.mts +88 -0
- package/dist/email-sender.d.mts.map +1 -0
- package/dist/email-sender.mjs +90 -0
- package/dist/email-sender.mjs.map +1 -0
- package/dist/email.cjs +73 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +59 -0
- package/dist/email.d.cts.map +1 -0
- package/dist/email.d.mts +59 -0
- package/dist/email.d.mts.map +1 -0
- package/dist/email.mjs +68 -0
- package/dist/email.mjs.map +1 -0
- package/dist/engine/actions.cjs +19 -0
- package/dist/engine/actions.cjs.map +1 -0
- package/dist/engine/actions.d.cts +27 -0
- package/dist/engine/actions.d.cts.map +1 -0
- package/dist/engine/actions.d.mts +27 -0
- package/dist/engine/actions.d.mts.map +1 -0
- package/dist/engine/actions.mjs +18 -0
- package/dist/engine/actions.mjs.map +1 -0
- package/dist/engine/bucket.cjs +71 -0
- package/dist/engine/bucket.cjs.map +1 -0
- package/dist/engine/bucket.d.cts +30 -0
- package/dist/engine/bucket.d.cts.map +1 -0
- package/dist/engine/bucket.d.mts +30 -0
- package/dist/engine/bucket.d.mts.map +1 -0
- package/dist/engine/bucket.mjs +68 -0
- package/dist/engine/bucket.mjs.map +1 -0
- package/dist/engine/condition.cjs +199 -0
- package/dist/engine/condition.cjs.map +1 -0
- package/dist/engine/condition.d.cts +76 -0
- package/dist/engine/condition.d.cts.map +1 -0
- package/dist/engine/condition.d.mts +76 -0
- package/dist/engine/condition.d.mts.map +1 -0
- package/dist/engine/condition.mjs +192 -0
- package/dist/engine/condition.mjs.map +1 -0
- package/dist/engine/duration.cjs +33 -0
- package/dist/engine/duration.cjs.map +1 -0
- package/dist/engine/duration.d.cts +3 -0
- package/dist/engine/duration.d.cts.map +1 -0
- package/dist/engine/duration.d.mts +3 -0
- package/dist/engine/duration.d.mts.map +1 -0
- package/dist/engine/duration.mjs +32 -0
- package/dist/engine/duration.mjs.map +1 -0
- package/dist/engine/index.cjs +33 -0
- package/dist/engine/index.d.cts +10 -0
- package/dist/engine/index.d.mts +10 -0
- package/dist/engine/index.mjs +9 -0
- package/dist/engine/interpreter.cjs +613 -0
- package/dist/engine/interpreter.cjs.map +1 -0
- package/dist/engine/interpreter.d.cts +4 -0
- package/dist/engine/interpreter.d.cts.map +1 -0
- package/dist/engine/interpreter.d.mts +4 -0
- package/dist/engine/interpreter.d.mts.map +1 -0
- package/dist/engine/interpreter.mjs +612 -0
- package/dist/engine/interpreter.mjs.map +1 -0
- package/dist/engine/ports.cjs +0 -0
- package/dist/engine/ports.d.cts +373 -0
- package/dist/engine/ports.d.cts.map +1 -0
- package/dist/engine/ports.d.mts +373 -0
- package/dist/engine/ports.d.mts.map +1 -0
- package/dist/engine/ports.mjs +1 -0
- package/dist/engine/recipient.cjs +22 -0
- package/dist/engine/recipient.cjs.map +1 -0
- package/dist/engine/recipient.d.cts +11 -0
- package/dist/engine/recipient.d.cts.map +1 -0
- package/dist/engine/recipient.d.mts +11 -0
- package/dist/engine/recipient.d.mts.map +1 -0
- package/dist/engine/recipient.mjs +21 -0
- package/dist/engine/recipient.mjs.map +1 -0
- package/dist/engine/retry.cjs +106 -0
- package/dist/engine/retry.cjs.map +1 -0
- package/dist/engine/retry.d.cts +73 -0
- package/dist/engine/retry.d.cts.map +1 -0
- package/dist/engine/retry.d.mts +73 -0
- package/dist/engine/retry.d.mts.map +1 -0
- package/dist/engine/retry.mjs +98 -0
- package/dist/engine/retry.mjs.map +1 -0
- package/dist/engine/time-scale.cjs +153 -0
- package/dist/engine/time-scale.cjs.map +1 -0
- package/dist/engine/time-scale.d.cts +41 -0
- package/dist/engine/time-scale.d.cts.map +1 -0
- package/dist/engine/time-scale.d.mts +41 -0
- package/dist/engine/time-scale.d.mts.map +1 -0
- package/dist/engine/time-scale.mjs +150 -0
- package/dist/engine/time-scale.mjs.map +1 -0
- package/dist/engine/time-window.cjs +148 -0
- package/dist/engine/time-window.cjs.map +1 -0
- package/dist/engine/time-window.d.cts +20 -0
- package/dist/engine/time-window.d.cts.map +1 -0
- package/dist/engine/time-window.d.mts +20 -0
- package/dist/engine/time-window.d.mts.map +1 -0
- package/dist/engine/time-window.mjs +146 -0
- package/dist/engine/time-window.mjs.map +1 -0
- package/dist/fcm.cjs +208 -0
- package/dist/fcm.cjs.map +1 -0
- package/dist/fcm.d.cts +89 -0
- package/dist/fcm.d.cts.map +1 -0
- package/dist/fcm.d.mts +89 -0
- package/dist/fcm.d.mts.map +1 -0
- package/dist/fcm.mjs +202 -0
- package/dist/fcm.mjs.map +1 -0
- package/dist/hash.cjs +244 -0
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.d.cts +28 -0
- package/dist/hash.d.cts.map +1 -0
- package/dist/hash.d.mts +28 -0
- package/dist/hash.d.mts.map +1 -0
- package/dist/hash.mjs +238 -0
- package/dist/hash.mjs.map +1 -0
- package/dist/host/auth.cjs +48 -0
- package/dist/host/auth.cjs.map +1 -0
- package/dist/host/auth.d.cts +33 -0
- package/dist/host/auth.d.cts.map +1 -0
- package/dist/host/auth.d.mts +33 -0
- package/dist/host/auth.d.mts.map +1 -0
- package/dist/host/auth.mjs +45 -0
- package/dist/host/auth.mjs.map +1 -0
- package/dist/host/batch.cjs +178 -0
- package/dist/host/batch.cjs.map +1 -0
- package/dist/host/batch.d.cts +92 -0
- package/dist/host/batch.d.cts.map +1 -0
- package/dist/host/batch.d.mts +92 -0
- package/dist/host/batch.d.mts.map +1 -0
- package/dist/host/batch.mjs +169 -0
- package/dist/host/batch.mjs.map +1 -0
- package/dist/host/channels.cjs +256 -0
- package/dist/host/channels.cjs.map +1 -0
- package/dist/host/channels.d.cts +66 -0
- package/dist/host/channels.d.cts.map +1 -0
- package/dist/host/channels.d.mts +66 -0
- package/dist/host/channels.d.mts.map +1 -0
- package/dist/host/channels.mjs +252 -0
- package/dist/host/channels.mjs.map +1 -0
- package/dist/host/execute.cjs +102 -0
- package/dist/host/execute.cjs.map +1 -0
- package/dist/host/execute.d.cts +38 -0
- package/dist/host/execute.d.cts.map +1 -0
- package/dist/host/execute.d.mts +38 -0
- package/dist/host/execute.d.mts.map +1 -0
- package/dist/host/execute.mjs +101 -0
- package/dist/host/execute.mjs.map +1 -0
- package/dist/host/fresh-read.cjs +29 -0
- package/dist/host/fresh-read.cjs.map +1 -0
- package/dist/host/fresh-read.d.cts +16 -0
- package/dist/host/fresh-read.d.cts.map +1 -0
- package/dist/host/fresh-read.d.mts +16 -0
- package/dist/host/fresh-read.d.mts.map +1 -0
- package/dist/host/fresh-read.mjs +28 -0
- package/dist/host/fresh-read.mjs.map +1 -0
- package/dist/host/http.cjs +393 -0
- package/dist/host/http.cjs.map +1 -0
- package/dist/host/http.d.cts +61 -0
- package/dist/host/http.d.cts.map +1 -0
- package/dist/host/http.d.mts +61 -0
- package/dist/host/http.d.mts.map +1 -0
- package/dist/host/http.mjs +389 -0
- package/dist/host/http.mjs.map +1 -0
- package/dist/host/ingest.cjs +1210 -0
- package/dist/host/ingest.cjs.map +1 -0
- package/dist/host/ingest.d.cts +497 -0
- package/dist/host/ingest.d.cts.map +1 -0
- package/dist/host/ingest.d.mts +497 -0
- package/dist/host/ingest.d.mts.map +1 -0
- package/dist/host/ingest.mjs +1172 -0
- package/dist/host/ingest.mjs.map +1 -0
- package/dist/host/journey-host.cjs +223 -0
- package/dist/host/journey-host.cjs.map +1 -0
- package/dist/host/journey-host.d.cts +118 -0
- package/dist/host/journey-host.d.cts.map +1 -0
- package/dist/host/journey-host.d.mts +118 -0
- package/dist/host/journey-host.d.mts.map +1 -0
- package/dist/host/journey-host.mjs +219 -0
- package/dist/host/journey-host.mjs.map +1 -0
- package/dist/host/platform.cjs +20 -0
- package/dist/host/platform.cjs.map +1 -0
- package/dist/host/platform.d.cts +120 -0
- package/dist/host/platform.d.cts.map +1 -0
- package/dist/host/platform.d.mts +120 -0
- package/dist/host/platform.d.mts.map +1 -0
- package/dist/host/platform.mjs +18 -0
- package/dist/host/platform.mjs.map +1 -0
- package/dist/host/senders.cjs +71 -0
- package/dist/host/senders.cjs.map +1 -0
- package/dist/host/senders.d.cts +34 -0
- package/dist/host/senders.d.cts.map +1 -0
- package/dist/host/senders.d.mts +34 -0
- package/dist/host/senders.d.mts.map +1 -0
- package/dist/host/senders.mjs +67 -0
- package/dist/host/senders.mjs.map +1 -0
- package/dist/host/workflow-cache.cjs +47 -0
- package/dist/host/workflow-cache.cjs.map +1 -0
- package/dist/host/workflow-cache.d.cts +21 -0
- package/dist/host/workflow-cache.d.cts.map +1 -0
- package/dist/host/workflow-cache.d.mts +21 -0
- package/dist/host/workflow-cache.d.mts.map +1 -0
- package/dist/host/workflow-cache.mjs +46 -0
- package/dist/host/workflow-cache.mjs.map +1 -0
- package/dist/http2-client.cjs +89 -0
- package/dist/http2-client.cjs.map +1 -0
- package/dist/http2-client.d.cts +45 -0
- package/dist/http2-client.d.cts.map +1 -0
- package/dist/http2-client.d.mts +45 -0
- package/dist/http2-client.d.mts.map +1 -0
- package/dist/http2-client.mjs +87 -0
- package/dist/http2-client.mjs.map +1 -0
- package/dist/index.cjs +130 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.mjs +20 -0
- package/dist/inflight.cjs +116 -0
- package/dist/inflight.cjs.map +1 -0
- package/dist/inflight.d.cts +49 -0
- package/dist/inflight.d.cts.map +1 -0
- package/dist/inflight.d.mts +49 -0
- package/dist/inflight.d.mts.map +1 -0
- package/dist/inflight.mjs +113 -0
- package/dist/inflight.mjs.map +1 -0
- package/dist/ir.cjs +429 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +593 -0
- package/dist/ir.d.cts.map +1 -0
- package/dist/ir.d.mts +593 -0
- package/dist/ir.d.mts.map +1 -0
- package/dist/ir.mjs +404 -0
- package/dist/ir.mjs.map +1 -0
- package/dist/jwt.cjs +17 -0
- package/dist/jwt.cjs.map +1 -0
- package/dist/jwt.d.cts +7 -0
- package/dist/jwt.d.cts.map +1 -0
- package/dist/jwt.d.mts +7 -0
- package/dist/jwt.d.mts.map +1 -0
- package/dist/jwt.mjs +15 -0
- package/dist/jwt.mjs.map +1 -0
- package/dist/node/index.cjs +231 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +59 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts +59 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.mjs +225 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/node/runs.cjs +222 -0
- package/dist/node/runs.cjs.map +1 -0
- package/dist/node/runs.d.cts +93 -0
- package/dist/node/runs.d.cts.map +1 -0
- package/dist/node/runs.d.mts +93 -0
- package/dist/node/runs.d.mts.map +1 -0
- package/dist/node/runs.mjs +221 -0
- package/dist/node/runs.mjs.map +1 -0
- package/dist/node/runtime.cjs +351 -0
- package/dist/node/runtime.cjs.map +1 -0
- package/dist/node/runtime.d.cts +96 -0
- package/dist/node/runtime.d.cts.map +1 -0
- package/dist/node/runtime.d.mts +96 -0
- package/dist/node/runtime.d.mts.map +1 -0
- package/dist/node/runtime.mjs +348 -0
- package/dist/node/runtime.mjs.map +1 -0
- package/dist/plan.cjs +221 -0
- package/dist/plan.cjs.map +1 -0
- package/dist/plan.d.cts +68 -0
- package/dist/plan.d.cts.map +1 -0
- package/dist/plan.d.mts +68 -0
- package/dist/plan.d.mts.map +1 -0
- package/dist/plan.mjs +218 -0
- package/dist/plan.mjs.map +1 -0
- package/dist/postgres-js.cjs +51 -0
- package/dist/postgres-js.cjs.map +1 -0
- package/dist/postgres-js.d.cts +32 -0
- package/dist/postgres-js.d.cts.map +1 -0
- package/dist/postgres-js.d.mts +32 -0
- package/dist/postgres-js.d.mts.map +1 -0
- package/dist/postgres-js.mjs +46 -0
- package/dist/postgres-js.mjs.map +1 -0
- package/dist/provenance.cjs +66 -0
- package/dist/provenance.cjs.map +1 -0
- package/dist/provenance.d.cts +40 -0
- package/dist/provenance.d.cts.map +1 -0
- package/dist/provenance.d.mts +40 -0
- package/dist/provenance.d.mts.map +1 -0
- package/dist/provenance.mjs +64 -0
- package/dist/provenance.mjs.map +1 -0
- package/dist/push.cjs +11 -0
- package/dist/push.cjs.map +1 -0
- package/dist/push.d.cts +14 -0
- package/dist/push.d.cts.map +1 -0
- package/dist/push.d.mts +14 -0
- package/dist/push.d.mts.map +1 -0
- package/dist/push.mjs +10 -0
- package/dist/push.mjs.map +1 -0
- package/dist/react-email.cjs +56 -0
- package/dist/react-email.cjs.map +1 -0
- package/dist/react-email.d.cts +5 -0
- package/dist/react-email.d.cts.map +1 -0
- package/dist/react-email.d.mts +5 -0
- package/dist/react-email.d.mts.map +1 -0
- package/dist/react-email.mjs +55 -0
- package/dist/react-email.mjs.map +1 -0
- package/dist/reporting/classify.cjs +46 -0
- package/dist/reporting/classify.cjs.map +1 -0
- package/dist/reporting/classify.d.cts +65 -0
- package/dist/reporting/classify.d.cts.map +1 -0
- package/dist/reporting/classify.d.mts +65 -0
- package/dist/reporting/classify.d.mts.map +1 -0
- package/dist/reporting/classify.mjs +42 -0
- package/dist/reporting/classify.mjs.map +1 -0
- package/dist/reporting/observer.cjs +137 -0
- package/dist/reporting/observer.cjs.map +1 -0
- package/dist/reporting/observer.d.cts +31 -0
- package/dist/reporting/observer.d.cts.map +1 -0
- package/dist/reporting/observer.d.mts +31 -0
- package/dist/reporting/observer.d.mts.map +1 -0
- package/dist/reporting/observer.mjs +134 -0
- package/dist/reporting/observer.mjs.map +1 -0
- package/dist/reporting/tracking.cjs +185 -0
- package/dist/reporting/tracking.cjs.map +1 -0
- package/dist/reporting/tracking.d.cts +63 -0
- package/dist/reporting/tracking.d.cts.map +1 -0
- package/dist/reporting/tracking.d.mts +63 -0
- package/dist/reporting/tracking.d.mts.map +1 -0
- package/dist/reporting/tracking.mjs +182 -0
- package/dist/reporting/tracking.mjs.map +1 -0
- package/dist/runtime.cjs +18 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +44 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.mts +44 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +17 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/store/condition-sql.cjs +145 -0
- package/dist/store/condition-sql.cjs.map +1 -0
- package/dist/store/condition-sql.d.cts +38 -0
- package/dist/store/condition-sql.d.cts.map +1 -0
- package/dist/store/condition-sql.d.mts +38 -0
- package/dist/store/condition-sql.d.mts.map +1 -0
- package/dist/store/condition-sql.mjs +144 -0
- package/dist/store/condition-sql.mjs.map +1 -0
- package/dist/store/erasure.cjs +21 -0
- package/dist/store/erasure.cjs.map +1 -0
- package/dist/store/erasure.d.cts +16 -0
- package/dist/store/erasure.d.cts.map +1 -0
- package/dist/store/erasure.d.mts +16 -0
- package/dist/store/erasure.d.mts.map +1 -0
- package/dist/store/erasure.mjs +20 -0
- package/dist/store/erasure.mjs.map +1 -0
- package/dist/store/facts.cjs +79 -0
- package/dist/store/facts.cjs.map +1 -0
- package/dist/store/facts.d.cts +41 -0
- package/dist/store/facts.d.cts.map +1 -0
- package/dist/store/facts.d.mts +41 -0
- package/dist/store/facts.d.mts.map +1 -0
- package/dist/store/facts.mjs +77 -0
- package/dist/store/facts.mjs.map +1 -0
- package/dist/store/identity.cjs +34 -0
- package/dist/store/identity.cjs.map +1 -0
- package/dist/store/identity.d.cts +13 -0
- package/dist/store/identity.d.cts.map +1 -0
- package/dist/store/identity.d.mts +13 -0
- package/dist/store/identity.d.mts.map +1 -0
- package/dist/store/identity.mjs +30 -0
- package/dist/store/identity.mjs.map +1 -0
- package/dist/store/index.cjs +35 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.cts +766 -0
- package/dist/store/index.d.cts.map +1 -0
- package/dist/store/index.d.mts +766 -0
- package/dist/store/index.d.mts.map +1 -0
- package/dist/store/index.mjs +22 -0
- package/dist/store/index.mjs.map +1 -0
- package/dist/store/postgres-reporting.cjs +327 -0
- package/dist/store/postgres-reporting.cjs.map +1 -0
- package/dist/store/postgres-reporting.d.cts +95 -0
- package/dist/store/postgres-reporting.d.cts.map +1 -0
- package/dist/store/postgres-reporting.d.mts +95 -0
- package/dist/store/postgres-reporting.d.mts.map +1 -0
- package/dist/store/postgres-reporting.mjs +326 -0
- package/dist/store/postgres-reporting.mjs.map +1 -0
- package/dist/store/postgres.cjs +1173 -0
- package/dist/store/postgres.cjs.map +1 -0
- package/dist/store/postgres.d.cts +199 -0
- package/dist/store/postgres.d.cts.map +1 -0
- package/dist/store/postgres.d.mts +199 -0
- package/dist/store/postgres.d.mts.map +1 -0
- package/dist/store/postgres.mjs +1170 -0
- package/dist/store/postgres.mjs.map +1 -0
- package/dist/store/sql.cjs +24 -0
- package/dist/store/sql.cjs.map +1 -0
- package/dist/store/sql.d.cts +26 -0
- package/dist/store/sql.d.cts.map +1 -0
- package/dist/store/sql.d.mts +26 -0
- package/dist/store/sql.d.mts.map +1 -0
- package/dist/store/sql.mjs +23 -0
- package/dist/store/sql.mjs.map +1 -0
- package/dist/store/tables.cjs +660 -0
- package/dist/store/tables.cjs.map +1 -0
- package/dist/store/tables.d.cts +103 -0
- package/dist/store/tables.d.cts.map +1 -0
- package/dist/store/tables.d.mts +103 -0
- package/dist/store/tables.d.mts.map +1 -0
- package/dist/store/tables.mjs +653 -0
- package/dist/store/tables.mjs.map +1 -0
- package/dist/store/user-lock.cjs +42 -0
- package/dist/store/user-lock.cjs.map +1 -0
- package/dist/store/user-lock.d.cts +30 -0
- package/dist/store/user-lock.d.cts.map +1 -0
- package/dist/store/user-lock.d.mts +30 -0
- package/dist/store/user-lock.d.mts.map +1 -0
- package/dist/store/user-lock.mjs +39 -0
- package/dist/store/user-lock.mjs.map +1 -0
- package/dist/template-rules.cjs +94 -0
- package/dist/template-rules.cjs.map +1 -0
- package/dist/template-rules.d.cts +80 -0
- package/dist/template-rules.d.cts.map +1 -0
- package/dist/template-rules.d.mts +80 -0
- package/dist/template-rules.d.mts.map +1 -0
- package/dist/template-rules.mjs +86 -0
- package/dist/template-rules.mjs.map +1 -0
- package/dist/templates.cjs +375 -0
- package/dist/templates.cjs.map +1 -0
- package/dist/templates.d.cts +358 -0
- package/dist/templates.d.cts.map +1 -0
- package/dist/templates.d.mts +358 -0
- package/dist/templates.d.mts.map +1 -0
- package/dist/templates.mjs +353 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/transports/cloudflare-email.cjs +69 -0
- package/dist/transports/cloudflare-email.cjs.map +1 -0
- package/dist/transports/cloudflare-email.d.cts +63 -0
- package/dist/transports/cloudflare-email.d.cts.map +1 -0
- package/dist/transports/cloudflare-email.d.mts +63 -0
- package/dist/transports/cloudflare-email.d.mts.map +1 -0
- package/dist/transports/cloudflare-email.mjs +67 -0
- package/dist/transports/cloudflare-email.mjs.map +1 -0
- package/dist/transports/ses.cjs +142 -0
- package/dist/transports/ses.cjs.map +1 -0
- package/dist/transports/ses.d.cts +49 -0
- package/dist/transports/ses.d.cts.map +1 -0
- package/dist/transports/ses.d.mts +49 -0
- package/dist/transports/ses.d.mts.map +1 -0
- package/dist/transports/ses.mjs +139 -0
- package/dist/transports/ses.mjs.map +1 -0
- package/dist/transports/sigv4.cjs +86 -0
- package/dist/transports/sigv4.cjs.map +1 -0
- package/dist/transports/sigv4.d.cts +25 -0
- package/dist/transports/sigv4.d.cts.map +1 -0
- package/dist/transports/sigv4.d.mts +25 -0
- package/dist/transports/sigv4.d.mts.map +1 -0
- package/dist/transports/sigv4.mjs +85 -0
- package/dist/transports/sigv4.mjs.map +1 -0
- package/dist/webhooks.cjs +97 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +23 -0
- package/dist/webhooks.d.cts.map +1 -0
- package/dist/webhooks.d.mts +23 -0
- package/dist/webhooks.d.mts.map +1 -0
- package/dist/webhooks.mjs +95 -0
- package/dist/webhooks.mjs.map +1 -0
- package/dist/webpush.cjs +361 -0
- package/dist/webpush.cjs.map +1 -0
- package/dist/webpush.d.cts +135 -0
- package/dist/webpush.d.cts.map +1 -0
- package/dist/webpush.d.mts +135 -0
- package/dist/webpush.d.mts.map +1 -0
- package/dist/webpush.mjs +350 -0
- package/dist/webpush.mjs.map +1 -0
- package/package.json +270 -31
- package/src/cloudflare/workers.d.ts +44 -0
- package/index.cjs +0 -18
- package/index.d.cts +0 -4
- package/index.d.mts +0 -4
- package/index.mjs +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { isEmailAddress, isUnsubscribeLink } from "./template-rules.mjs";
|
|
2
|
+
// src/email-sender.ts
|
|
3
|
+
/**
|
|
4
|
+
* The email channel over any transport: render → tracking applied to the HTML → the tracked
|
|
5
|
+
* links committed → the transport. The links resolve before the email exists anywhere a
|
|
6
|
+
* scanner could follow them.
|
|
7
|
+
*/
|
|
8
|
+
var EmailSender = class {
|
|
9
|
+
options;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
async send(message) {
|
|
14
|
+
if (message.channel !== "email") throw new Error(`EmailSender: unsupported channel '${message.channel}'`);
|
|
15
|
+
if (message.recipient === void 0) return {
|
|
16
|
+
delivered: false,
|
|
17
|
+
reason: "no_recipient"
|
|
18
|
+
};
|
|
19
|
+
if (!isEmailAddress(message.recipient)) return {
|
|
20
|
+
delivered: false,
|
|
21
|
+
reason: "invalid_recipient"
|
|
22
|
+
};
|
|
23
|
+
const messageId = message.tracking?.messageId;
|
|
24
|
+
const { subject, html, from, replyTo, unsubscribeUrl } = await this.options.render(message.template, message.props, messageId === void 0 ? {} : { messageId });
|
|
25
|
+
const tracked = message.tracking === void 0 ? html : trackEmail(html, message.tracking, unsubscribeUrl);
|
|
26
|
+
await message.tracking?.commit?.();
|
|
27
|
+
const headers = unsubscribeHeaders(unsubscribeUrl, message.tracking?.unsubscribe);
|
|
28
|
+
await this.options.transport.send({
|
|
29
|
+
from,
|
|
30
|
+
to: message.recipient,
|
|
31
|
+
...replyTo === void 0 ? {} : { replyTo },
|
|
32
|
+
subject,
|
|
33
|
+
html: tracked,
|
|
34
|
+
...headers === void 0 ? {} : { headers },
|
|
35
|
+
idempotencyKey: message.idempotencyKey
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The list-unsubscribe headers of an email with an unsubscribe link (RFC 2369, RFC 8058), so a
|
|
41
|
+
* mail client's own unsubscribe button works — Gmail and Yahoo require one-click for bulk mail:
|
|
42
|
+
*
|
|
43
|
+
* - With a one-click endpoint (`MessageTracking.unsubscribe`, which reporting provides): the
|
|
44
|
+
* header names it, and `List-Unsubscribe-Post` says a POST there unsubscribes at once.
|
|
45
|
+
* - Without one: the header names the email's own unsubscribe link, with no one-click claim —
|
|
46
|
+
* whether that page takes a POST is the app's.
|
|
47
|
+
* - An email without an unsubscribe link (a transactional one) gets neither.
|
|
48
|
+
*
|
|
49
|
+
* Only an https URL is named: mail clients and Cloudflare Email refuse any other.
|
|
50
|
+
*/
|
|
51
|
+
function unsubscribeHeaders(unsubscribeUrl, oneClick) {
|
|
52
|
+
if (unsubscribeUrl === void 0) return void 0;
|
|
53
|
+
const https = (url) => url?.startsWith("https://") === true;
|
|
54
|
+
if (https(oneClick)) return {
|
|
55
|
+
"List-Unsubscribe": `<${oneClick}>`,
|
|
56
|
+
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click"
|
|
57
|
+
};
|
|
58
|
+
if (https(unsubscribeUrl)) return { "List-Unsubscribe": `<${unsubscribeUrl}>` };
|
|
59
|
+
}
|
|
60
|
+
const LINK = /(<a\b[^>]*?\shref\s*=\s*)(["'])(https?:\/\/[^"']+)\2/gi;
|
|
61
|
+
/**
|
|
62
|
+
* An email's tracking applied to its rendered HTML: every `http(s)` anchor routed through
|
|
63
|
+
* `link` (the original URL decoded from its attribute escaping, the tracking URL escaped back) —
|
|
64
|
+
* as the unsubscribe link when it is the one the email was rendered with, so what a click on it
|
|
65
|
+
* means is fixed when the email is sent — and the open pixel appended before `</body>`, or at the
|
|
66
|
+
* end when there is none.
|
|
67
|
+
*/
|
|
68
|
+
function trackEmail(html, tracking, unsubscribeUrl) {
|
|
69
|
+
const { link, pixel } = tracking;
|
|
70
|
+
let out = html;
|
|
71
|
+
if (link !== void 0) out = out.replace(LINK, (_, start, quote, attribute) => {
|
|
72
|
+
const url = unescapeAttribute(attribute);
|
|
73
|
+
const purpose = isUnsubscribeLink(url, unsubscribeUrl) ? "unsubscribe" : "link";
|
|
74
|
+
return `${start}${quote}${escapeAttribute(link(url, purpose))}${quote}`;
|
|
75
|
+
});
|
|
76
|
+
if (pixel !== void 0) {
|
|
77
|
+
const image = `<img src="${escapeAttribute(pixel)}" width="1" height="1" alt="" style="display:block;border:0;width:1px;height:1px" />`;
|
|
78
|
+
out = /<\/body>/i.test(out) ? out.replace(/<\/body>/i, `${image}</body>`) : `${out}${image}`;
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
function unescapeAttribute(value) {
|
|
83
|
+
return value.replaceAll("&", "&").replaceAll(""", "\"").replaceAll("'", "'");
|
|
84
|
+
}
|
|
85
|
+
function escapeAttribute(value) {
|
|
86
|
+
return value.replaceAll("&", "&").replaceAll("\"", """);
|
|
87
|
+
}
|
|
88
|
+
export { EmailSender, trackEmail, unsubscribeHeaders };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=email-sender.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.mjs","names":[],"sources":["../src/email-sender.ts"],"sourcesContent":["import type { EmailRenderOptions, ResolvedEmail } from './email';\nimport type { MessageSender, MessageTracking, OutboundMessage, SendResult } from './engine/ports';\nimport type { ScalarIR } from './ir';\nimport { type EmailAddress, isEmailAddress, isUnsubscribeLink } from './template-rules';\n\n/**\n * The email channel, split where the runtime stops mattering: `EmailSender` renders a copy,\n * applies its tracking and commits the tracked links — the same on every host — and hands the\n * finished email to an `EmailTransport`, the only part that knows a provider (SES, Cloudflare\n * Email, ...). Nothing here imports a platform module, so a Worker and a Lambda share it.\n */\n\n/** A rendered email: the template's resolved metadata (`resolveEmail`), its subject and its HTML. */\nexport interface RenderedEmail extends ResolvedEmail {\n subject: string;\n html: string;\n}\n\n/**\n * Template renderer, injected by the app — this package's core stays free of\n * any react-email dependency (`sendwend/react-email` ships one over a\n * registry). The subject comes back final: it is sent exactly as written, from\n * the template's own sender, and the unsubscribe link is the one the HTML was\n * rendered with. `options` carries the copy's message id when reporting records one, for the\n * preferences link (`resolveEmail`).\n */\nexport type EmailRenderer = (\n template: string,\n props: Record<string, ScalarIR | undefined>,\n options?: EmailRenderOptions\n) => Promise<RenderedEmail>;\n\n/** A finished email, as a transport takes it: rendered, tracked, addressed. */\nexport interface EmailMessage {\n from: EmailAddress;\n to: string;\n replyTo?: EmailAddress;\n subject: string;\n html: string;\n /**\n * Extra headers, already formatted: `List-Unsubscribe` and `List-Unsubscribe-Post` for an\n * email that has an unsubscribe link (see `unsubscribeHeaders`).\n */\n headers?: Readonly<Record<string, string>>;\n /**\n * `${instanceId}:${nodeId}`: the copy's identity, stable across retries and replays. A provider\n * that de-duplicates on a key receives it; one that cannot (SES) still sends at least once —\n * the window between the provider accepting the email and the step's checkpoint stays open.\n */\n idempotencyKey: string;\n}\n\n/**\n * One email provider. Throwing hands the retry to the durable step; resolving means the provider\n * accepted the email (not that it was delivered).\n */\nexport interface EmailTransport {\n send(message: EmailMessage): Promise<{ providerMessageId?: string }>;\n}\n\nexport interface EmailSenderOptions {\n transport: EmailTransport;\n render: EmailRenderer;\n}\n\n/**\n * The email channel over any transport: render → tracking applied to the HTML → the tracked\n * links committed → the transport. The links resolve before the email exists anywhere a\n * scanner could follow them.\n */\nexport class EmailSender implements MessageSender {\n constructor(private readonly options: EmailSenderOptions) {}\n\n async send(message: OutboundMessage): Promise<void | SendResult> {\n if (message.channel !== 'email') {\n throw new Error(`EmailSender: unsupported channel '${message.channel}'`);\n }\n // A user with no usable address is a fact about that user, not a fault worth retrying: the\n // copy settles undelivered and the journey goes on, the way a push with no device is skipped.\n // Throwing here burned the step's retries and then failed the whole instance.\n if (message.recipient === undefined) return { delivered: false, reason: 'no_recipient' };\n if (!isEmailAddress(message.recipient)) {\n return { delivered: false, reason: 'invalid_recipient' };\n }\n const messageId = message.tracking?.messageId;\n const { subject, html, from, replyTo, unsubscribeUrl } = await this.options.render(\n message.template,\n message.props,\n messageId === undefined ? {} : { messageId }\n );\n const tracked =\n message.tracking === undefined ? html : trackEmail(html, message.tracking, unsubscribeUrl);\n await message.tracking?.commit?.();\n const headers = unsubscribeHeaders(unsubscribeUrl, message.tracking?.unsubscribe);\n await this.options.transport.send({\n from,\n to: message.recipient,\n ...(replyTo === undefined ? {} : { replyTo }),\n subject,\n html: tracked,\n ...(headers === undefined ? {} : { headers }),\n idempotencyKey: message.idempotencyKey,\n });\n }\n}\n\n/**\n * The list-unsubscribe headers of an email with an unsubscribe link (RFC 2369, RFC 8058), so a\n * mail client's own unsubscribe button works — Gmail and Yahoo require one-click for bulk mail:\n *\n * - With a one-click endpoint (`MessageTracking.unsubscribe`, which reporting provides): the\n * header names it, and `List-Unsubscribe-Post` says a POST there unsubscribes at once.\n * - Without one: the header names the email's own unsubscribe link, with no one-click claim —\n * whether that page takes a POST is the app's.\n * - An email without an unsubscribe link (a transactional one) gets neither.\n *\n * Only an https URL is named: mail clients and Cloudflare Email refuse any other.\n */\nexport function unsubscribeHeaders(\n unsubscribeUrl: string | undefined,\n oneClick: string | undefined\n): Record<string, string> | undefined {\n if (unsubscribeUrl === undefined) return undefined;\n const https = (url: string | undefined) => url?.startsWith('https://') === true;\n if (https(oneClick)) {\n return {\n 'List-Unsubscribe': `<${oneClick}>`,\n 'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click',\n };\n }\n if (https(unsubscribeUrl)) return { 'List-Unsubscribe': `<${unsubscribeUrl}>` };\n return undefined;\n}\n\nconst LINK = /(<a\\b[^>]*?\\shref\\s*=\\s*)([\"'])(https?:\\/\\/[^\"']+)\\2/gi;\n\n/**\n * An email's tracking applied to its rendered HTML: every `http(s)` anchor routed through\n * `link` (the original URL decoded from its attribute escaping, the tracking URL escaped back) —\n * as the unsubscribe link when it is the one the email was rendered with, so what a click on it\n * means is fixed when the email is sent — and the open pixel appended before `</body>`, or at the\n * end when there is none.\n */\nexport function trackEmail(\n html: string,\n tracking: MessageTracking,\n unsubscribeUrl?: string\n): string {\n const { link, pixel } = tracking;\n let out = html;\n if (link !== undefined) {\n out = out.replace(LINK, (_, start: string, quote: string, attribute: string) => {\n const url = unescapeAttribute(attribute);\n const purpose = isUnsubscribeLink(url, unsubscribeUrl) ? 'unsubscribe' : 'link';\n return `${start}${quote}${escapeAttribute(link(url, purpose))}${quote}`;\n });\n }\n if (pixel !== undefined) {\n const image = `<img src=\"${escapeAttribute(pixel)}\" width=\"1\" height=\"1\" alt=\"\" style=\"display:block;border:0;width:1px;height:1px\" />`;\n out = /<\\/body>/i.test(out) ? out.replace(/<\\/body>/i, `${image}</body>`) : `${out}${image}`;\n }\n return out;\n}\n\nfunction unescapeAttribute(value: string): string {\n return value.replaceAll('&', '&').replaceAll('"', '\"').replaceAll(''', \"'\");\n}\n\nfunction escapeAttribute(value: string): string {\n return value.replaceAll('&', '&').replaceAll('\"', '"');\n}\n"],"mappings":";;;;;;;AAsEA,IAAa,cAAb,MAAkD;CACnB;CAA7B,YAA6B,SAA6B;EAA7B,KAAA,UAAA;CAA8B;CAE3D,MAAM,KAAK,SAAsD;EAC/D,IAAI,QAAQ,YAAY,SACtB,MAAM,IAAI,MAAM,qCAAqC,QAAQ,QAAQ,EAAE;EAKzE,IAAI,QAAQ,cAAc,KAAA,GAAW,OAAO;GAAE,WAAW;GAAO,QAAQ;EAAe;EACvF,IAAI,CAAC,eAAe,QAAQ,SAAS,GACnC,OAAO;GAAE,WAAW;GAAO,QAAQ;EAAoB;EAEzD,MAAM,YAAY,QAAQ,UAAU;EACpC,MAAM,EAAE,SAAS,MAAM,MAAM,SAAS,mBAAmB,MAAM,KAAK,QAAQ,OAC1E,QAAQ,UACR,QAAQ,OACR,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,CAC7C;EACA,MAAM,UACJ,QAAQ,aAAa,KAAA,IAAY,OAAO,WAAW,MAAM,QAAQ,UAAU,cAAc;EAC3F,MAAM,QAAQ,UAAU,SAAS;EACjC,MAAM,UAAU,mBAAmB,gBAAgB,QAAQ,UAAU,WAAW;EAChF,MAAM,KAAK,QAAQ,UAAU,KAAK;GAChC;GACA,IAAI,QAAQ;GACZ,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;GAC3C;GACA,MAAM;GACN,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;GAC3C,gBAAgB,QAAQ;EAC1B,CAAC;CACH;AACF;;;;;;;;;;;;;AAcA,SAAgB,mBACd,gBACA,UACoC;CACpC,IAAI,mBAAmB,KAAA,GAAW,OAAO,KAAA;CACzC,MAAM,SAAS,QAA4B,KAAK,WAAW,UAAU,MAAM;CAC3E,IAAI,MAAM,QAAQ,GAChB,OAAO;EACL,oBAAoB,IAAI,SAAS;EACjC,yBAAyB;CAC3B;CAEF,IAAI,MAAM,cAAc,GAAG,OAAO,EAAE,oBAAoB,IAAI,eAAe,GAAG;AAEhF;AAEA,MAAM,OAAO;;;;;;;;AASb,SAAgB,WACd,MACA,UACA,gBACQ;CACR,MAAM,EAAE,MAAM,UAAU;CACxB,IAAI,MAAM;CACV,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,QAAQ,OAAO,GAAG,OAAe,OAAe,cAAsB;EAC9E,MAAM,MAAM,kBAAkB,SAAS;EACvC,MAAM,UAAU,kBAAkB,KAAK,cAAc,IAAI,gBAAgB;EACzE,OAAO,GAAG,QAAQ,QAAQ,gBAAgB,KAAK,KAAK,OAAO,CAAC,IAAI;CAClE,CAAC;CAEH,IAAI,UAAU,KAAA,GAAW;EACvB,MAAM,QAAQ,aAAa,gBAAgB,KAAK,EAAE;EAClD,MAAM,YAAY,KAAK,GAAG,IAAI,IAAI,QAAQ,aAAa,GAAG,MAAM,QAAQ,IAAI,GAAG,MAAM;CACvF;CACA,OAAO;AACT;AAEA,SAAS,kBAAkB,OAAuB;CAChD,OAAO,MAAM,WAAW,SAAS,GAAG,CAAC,CAAC,WAAW,UAAU,IAAG,CAAC,CAAC,WAAW,UAAU,GAAG;AAC1F;AAEA,SAAS,gBAAgB,OAAuB;CAC9C,OAAO,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC,WAAW,MAAK,QAAQ;AAChE"}
|
package/dist/email.cjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// src/email.ts
|
|
3
|
+
/**
|
|
4
|
+
* Email metadata: who a template's email comes from, where replies go, and the unsubscribe and
|
|
5
|
+
* preference links its layout carries. Each `emailTemplate` declares its own `from` (and
|
|
6
|
+
* `replyTo`, if replies should go elsewhere) and says what it is: a `topic` the recipient may
|
|
7
|
+
* unsubscribe from, or `transactional: true`. A topic email's unsubscribe link is the template's
|
|
8
|
+
* `unsubscribeUrl`, else the config's `email.unsubscribeUrl`, else none; its preferences link is
|
|
9
|
+
* the config's `email.preferencesUrl` with the copy's message id, when the copy has one (reporting
|
|
10
|
+
* on); a transactional email never has either, whatever the config says. `resolveEmail` is that
|
|
11
|
+
* rule, and the sender, the renderer, the Worker's preview and the studio all go through it. No
|
|
12
|
+
* React and no I/O here, so a browser can import it.
|
|
13
|
+
*/
|
|
14
|
+
/** `Name <email>`, or the bare address. */
|
|
15
|
+
function formatEmailAddress(address) {
|
|
16
|
+
if (typeof address === "string") return address;
|
|
17
|
+
return address.name === void 0 ? address.email : `${address.name} <${address.email}>`;
|
|
18
|
+
}
|
|
19
|
+
const ASCII = /^[\x20-\x7e]*$/;
|
|
20
|
+
const SPECIALS = /[()<>[\]:;@\\,."]/;
|
|
21
|
+
/**
|
|
22
|
+
* An address as a mail API reads it (RFC 5322): a display name with specials is quoted, one
|
|
23
|
+
* outside ASCII is a MIME encoded-word — raw non-ASCII names are refused (SES), and an unquoted
|
|
24
|
+
* comma splits the address in two.
|
|
25
|
+
*/
|
|
26
|
+
function mimeAddress(address) {
|
|
27
|
+
if (typeof address === "string") return address;
|
|
28
|
+
const { email, name } = address;
|
|
29
|
+
if (name === void 0 || name === "") return email;
|
|
30
|
+
if (!ASCII.test(name)) {
|
|
31
|
+
const bytes = new TextEncoder().encode(name);
|
|
32
|
+
let binary = "";
|
|
33
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
34
|
+
return `=?UTF-8?B?${btoa(binary)}?= <${email}>`;
|
|
35
|
+
}
|
|
36
|
+
if (SPECIALS.test(name)) return `"${name.replace(/(["\\])/g, "\\$1")}" <${email}>`;
|
|
37
|
+
return `${name} <${email}>`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The message id a preview renders with: the preferences link shows in the studio and
|
|
41
|
+
* `GET /preview`, pointing at a copy that does not exist.
|
|
42
|
+
*/
|
|
43
|
+
const PREVIEW_MESSAGE_ID = "00000000-0000-0000-0000-000000000000";
|
|
44
|
+
/**
|
|
45
|
+
* The template's metadata, its `unsubscribeUrl` falling back to the config's, and the
|
|
46
|
+
* preferences link built from the config's page and the copy's message id — for a topic email; a
|
|
47
|
+
* transactional one resolves to neither link. Leaves the inputs untouched.
|
|
48
|
+
*/
|
|
49
|
+
function resolveEmail(template, config, options = {}) {
|
|
50
|
+
const topical = template.topic !== null;
|
|
51
|
+
const unsubscribeUrl = topical ? template.unsubscribeUrl ?? config?.unsubscribeUrl : void 0;
|
|
52
|
+
const preferencesUrl = topical && config?.preferencesUrl !== void 0 && options.messageId !== void 0 ? preferencesLink(config.preferencesUrl, options.messageId) : void 0;
|
|
53
|
+
return {
|
|
54
|
+
from: template.from,
|
|
55
|
+
topic: template.topic,
|
|
56
|
+
...template.replyTo === void 0 ? {} : { replyTo: template.replyTo },
|
|
57
|
+
...unsubscribeUrl === void 0 ? {} : { unsubscribeUrl },
|
|
58
|
+
...preferencesUrl === void 0 ? {} : { preferencesUrl }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The preference page's URL for one copy: `m=<message id>` set on its query, the rest of it kept. */
|
|
62
|
+
function preferencesLink(preferencesUrl, messageId) {
|
|
63
|
+
const url = new URL(preferencesUrl);
|
|
64
|
+
url.searchParams.set("m", messageId);
|
|
65
|
+
return url.toString();
|
|
66
|
+
}
|
|
67
|
+
exports.PREVIEW_MESSAGE_ID = PREVIEW_MESSAGE_ID;
|
|
68
|
+
exports.formatEmailAddress = formatEmailAddress;
|
|
69
|
+
exports.mimeAddress = mimeAddress;
|
|
70
|
+
exports.preferencesLink = preferencesLink;
|
|
71
|
+
exports.resolveEmail = resolveEmail;
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=email.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.cjs","names":[],"sources":["../src/email.ts"],"sourcesContent":["import type { EmailAddress, EmailConfig } from './template-rules';\nimport type { EmailTemplate } from './templates';\n\n/**\n * Email metadata: who a template's email comes from, where replies go, and the unsubscribe and\n * preference links its layout carries. Each `emailTemplate` declares its own `from` (and\n * `replyTo`, if replies should go elsewhere) and says what it is: a `topic` the recipient may\n * unsubscribe from, or `transactional: true`. A topic email's unsubscribe link is the template's\n * `unsubscribeUrl`, else the config's `email.unsubscribeUrl`, else none; its preferences link is\n * the config's `email.preferencesUrl` with the copy's message id, when the copy has one (reporting\n * on); a transactional email never has either, whatever the config says. `resolveEmail` is that\n * rule, and the sender, the renderer, the Worker's preview and the studio all go through it. No\n * React and no I/O here, so a browser can import it.\n */\n\n/** `Name <email>`, or the bare address. */\nexport function formatEmailAddress(address: EmailAddress): string {\n if (typeof address === 'string') return address;\n return address.name === undefined ? address.email : `${address.name} <${address.email}>`;\n}\n\nconst ASCII = /^[\\x20-\\x7e]*$/;\nconst SPECIALS = /[()<>[\\]:;@\\\\,.\"]/;\n\n/**\n * An address as a mail API reads it (RFC 5322): a display name with specials is quoted, one\n * outside ASCII is a MIME encoded-word — raw non-ASCII names are refused (SES), and an unquoted\n * comma splits the address in two.\n */\nexport function mimeAddress(address: EmailAddress): string {\n if (typeof address === 'string') return address;\n const { email, name } = address;\n if (name === undefined || name === '') return email;\n if (!ASCII.test(name)) {\n const bytes = new TextEncoder().encode(name);\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return `=?UTF-8?B?${btoa(binary)}?= <${email}>`;\n }\n if (SPECIALS.test(name)) return `\"${name.replace(/([\"\\\\])/g, '\\\\$1')}\" <${email}>`;\n return `${name} <${email}>`;\n}\n\n/** One template's email metadata, resolved against the config. */\nexport interface ResolvedEmail {\n from: EmailAddress;\n /** The template's subscription topic; null for a transactional email. */\n topic: string | null;\n /** Absent when the template names none: the email goes out without a Reply-To. */\n replyTo?: EmailAddress;\n /**\n * Absent when the email is transactional, or neither the template nor the config names one:\n * the email has no unsubscribe link.\n */\n unsubscribeUrl?: string;\n /**\n * The config's `preferencesUrl` with this copy's message id as `m`. Absent when the email is\n * transactional, the config names no page, or the copy has no message id (reporting off): the\n * email has no preferences link, and a layout renders none.\n */\n preferencesUrl?: string;\n}\n\n/** What a render knows of the copy beyond the template: its message id, when reporting records one. */\nexport interface EmailRenderOptions {\n /** The copy's id in the reporting tables — what `/t/...` and `/subscriptions/by-message` key on. */\n messageId?: string | undefined;\n}\n\n/**\n * The message id a preview renders with: the preferences link shows in the studio and\n * `GET /preview`, pointing at a copy that does not exist.\n */\nexport const PREVIEW_MESSAGE_ID = '00000000-0000-0000-0000-000000000000';\n\n/**\n * The template's metadata, its `unsubscribeUrl` falling back to the config's, and the\n * preferences link built from the config's page and the copy's message id — for a topic email; a\n * transactional one resolves to neither link. Leaves the inputs untouched.\n */\nexport function resolveEmail(\n template: Pick<EmailTemplate, 'from' | 'replyTo' | 'unsubscribeUrl' | 'topic'>,\n config?: EmailConfig,\n options: EmailRenderOptions = {}\n): ResolvedEmail {\n const topical = template.topic !== null;\n const unsubscribeUrl = topical ? (template.unsubscribeUrl ?? config?.unsubscribeUrl) : undefined;\n const preferencesUrl =\n topical && config?.preferencesUrl !== undefined && options.messageId !== undefined\n ? preferencesLink(config.preferencesUrl, options.messageId)\n : undefined;\n return {\n from: template.from,\n topic: template.topic,\n ...(template.replyTo === undefined ? {} : { replyTo: template.replyTo }),\n ...(unsubscribeUrl === undefined ? {} : { unsubscribeUrl }),\n ...(preferencesUrl === undefined ? {} : { preferencesUrl }),\n };\n}\n\n/** The preference page's URL for one copy: `m=<message id>` set on its query, the rest of it kept. */\nexport function preferencesLink(preferencesUrl: string, messageId: string): string {\n const url = new URL(preferencesUrl);\n url.searchParams.set('m', messageId);\n return url.toString();\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,SAA+B;CAChE,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,OAAO,QAAQ,SAAS,KAAA,IAAY,QAAQ,QAAQ,GAAG,QAAQ,KAAK,IAAI,QAAQ,MAAM;AACxF;AAEA,MAAM,QAAQ;AACd,MAAM,WAAW;;;;;;AAOjB,SAAgB,YAAY,SAA+B;CACzD,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,EAAE,OAAO,SAAS;CACxB,IAAI,SAAS,KAAA,KAAa,SAAS,IAAI,OAAO;CAC9C,IAAI,CAAC,MAAM,KAAK,IAAI,GAAG;EACrB,MAAM,QAAQ,IAAI,YAAY,CAAC,CAAC,OAAO,IAAI;EAC3C,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,OAAO,UAAU,OAAO,aAAa,IAAI;EAC5D,OAAO,aAAa,KAAK,MAAM,EAAE,MAAM,MAAM;CAC/C;CACA,IAAI,SAAS,KAAK,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,YAAY,MAAM,EAAE,KAAK,MAAM;CAChF,OAAO,GAAG,KAAK,IAAI,MAAM;AAC3B;;;;;AAgCA,MAAa,qBAAqB;;;;;;AAOlC,SAAgB,aACd,UACA,QACA,UAA8B,CAAC,GAChB;CACf,MAAM,UAAU,SAAS,UAAU;CACnC,MAAM,iBAAiB,UAAW,SAAS,kBAAkB,QAAQ,iBAAkB,KAAA;CACvF,MAAM,iBACJ,WAAW,QAAQ,mBAAmB,KAAA,KAAa,QAAQ,cAAc,KAAA,IACrE,gBAAgB,OAAO,gBAAgB,QAAQ,SAAS,IACxD,KAAA;CACN,OAAO;EACL,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,GAAI,SAAS,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,SAAS,QAAQ;EACtE,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;EACzD,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;CAC3D;AACF;;AAGA,SAAgB,gBAAgB,gBAAwB,WAA2B;CACjF,MAAM,MAAM,IAAI,IAAI,cAAc;CAClC,IAAI,aAAa,IAAI,KAAK,SAAS;CACnC,OAAO,IAAI,SAAS;AACtB"}
|
package/dist/email.d.cts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EmailAddress, EmailConfig } from "./template-rules.cjs";
|
|
2
|
+
import { EmailTemplate } from "./templates.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Email metadata: who a template's email comes from, where replies go, and the unsubscribe and
|
|
5
|
+
* preference links its layout carries. Each `emailTemplate` declares its own `from` (and
|
|
6
|
+
* `replyTo`, if replies should go elsewhere) and says what it is: a `topic` the recipient may
|
|
7
|
+
* unsubscribe from, or `transactional: true`. A topic email's unsubscribe link is the template's
|
|
8
|
+
* `unsubscribeUrl`, else the config's `email.unsubscribeUrl`, else none; its preferences link is
|
|
9
|
+
* the config's `email.preferencesUrl` with the copy's message id, when the copy has one (reporting
|
|
10
|
+
* on); a transactional email never has either, whatever the config says. `resolveEmail` is that
|
|
11
|
+
* rule, and the sender, the renderer, the Worker's preview and the studio all go through it. No
|
|
12
|
+
* React and no I/O here, so a browser can import it.
|
|
13
|
+
*/
|
|
14
|
+
/** `Name <email>`, or the bare address. */
|
|
15
|
+
export declare function formatEmailAddress(address: EmailAddress): string;
|
|
16
|
+
/**
|
|
17
|
+
* An address as a mail API reads it (RFC 5322): a display name with specials is quoted, one
|
|
18
|
+
* outside ASCII is a MIME encoded-word — raw non-ASCII names are refused (SES), and an unquoted
|
|
19
|
+
* comma splits the address in two.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mimeAddress(address: EmailAddress): string;
|
|
22
|
+
/** One template's email metadata, resolved against the config. */
|
|
23
|
+
export interface ResolvedEmail {
|
|
24
|
+
from: EmailAddress;
|
|
25
|
+
/** The template's subscription topic; null for a transactional email. */
|
|
26
|
+
topic: string | null;
|
|
27
|
+
/** Absent when the template names none: the email goes out without a Reply-To. */
|
|
28
|
+
replyTo?: EmailAddress;
|
|
29
|
+
/**
|
|
30
|
+
* Absent when the email is transactional, or neither the template nor the config names one:
|
|
31
|
+
* the email has no unsubscribe link.
|
|
32
|
+
*/
|
|
33
|
+
unsubscribeUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The config's `preferencesUrl` with this copy's message id as `m`. Absent when the email is
|
|
36
|
+
* transactional, the config names no page, or the copy has no message id (reporting off): the
|
|
37
|
+
* email has no preferences link, and a layout renders none.
|
|
38
|
+
*/
|
|
39
|
+
preferencesUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
/** What a render knows of the copy beyond the template: its message id, when reporting records one. */
|
|
42
|
+
export interface EmailRenderOptions {
|
|
43
|
+
/** The copy's id in the reporting tables — what `/t/...` and `/subscriptions/by-message` key on. */
|
|
44
|
+
messageId?: string | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The message id a preview renders with: the preferences link shows in the studio and
|
|
48
|
+
* `GET /preview`, pointing at a copy that does not exist.
|
|
49
|
+
*/
|
|
50
|
+
export declare const PREVIEW_MESSAGE_ID = "00000000-0000-0000-0000-000000000000";
|
|
51
|
+
/**
|
|
52
|
+
* The template's metadata, its `unsubscribeUrl` falling back to the config's, and the
|
|
53
|
+
* preferences link built from the config's page and the copy's message id — for a topic email; a
|
|
54
|
+
* transactional one resolves to neither link. Leaves the inputs untouched.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveEmail(template: Pick<EmailTemplate, 'from' | 'replyTo' | 'unsubscribeUrl' | 'topic'>, config?: EmailConfig, options?: EmailRenderOptions): ResolvedEmail;
|
|
57
|
+
/** The preference page's URL for one copy: `m=<message id>` set on its query, the rest of it kept. */
|
|
58
|
+
export declare function preferencesLink(preferencesUrl: string, messageId: string): string;
|
|
59
|
+
//# sourceMappingURL=email.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.cts","names":[],"sources":["../src/email.ts"],"mappings":";;;;;;;;;;;;;;wBAgBgB,mBAAmB,SAAS;;;;;;wBAa5B,YAAY,SAAS;;iBAepB;EACf,MAAM;;EAEN;;EAEA,UAAU;;;;;EAKV;;;;;;EAMA;;;iBAIe;;EAEf;;;;;;qBAOW;;;;;;wBAOG,aACd,UAAU,KAAK,iEACf,SAAS,aACT,UAAS,qBACR;;wBAiBa,gBAAgB,wBAAwB"}
|
package/dist/email.d.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EmailAddress, EmailConfig } from "./template-rules.mjs";
|
|
2
|
+
import { EmailTemplate } from "./templates.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Email metadata: who a template's email comes from, where replies go, and the unsubscribe and
|
|
5
|
+
* preference links its layout carries. Each `emailTemplate` declares its own `from` (and
|
|
6
|
+
* `replyTo`, if replies should go elsewhere) and says what it is: a `topic` the recipient may
|
|
7
|
+
* unsubscribe from, or `transactional: true`. A topic email's unsubscribe link is the template's
|
|
8
|
+
* `unsubscribeUrl`, else the config's `email.unsubscribeUrl`, else none; its preferences link is
|
|
9
|
+
* the config's `email.preferencesUrl` with the copy's message id, when the copy has one (reporting
|
|
10
|
+
* on); a transactional email never has either, whatever the config says. `resolveEmail` is that
|
|
11
|
+
* rule, and the sender, the renderer, the Worker's preview and the studio all go through it. No
|
|
12
|
+
* React and no I/O here, so a browser can import it.
|
|
13
|
+
*/
|
|
14
|
+
/** `Name <email>`, or the bare address. */
|
|
15
|
+
export declare function formatEmailAddress(address: EmailAddress): string;
|
|
16
|
+
/**
|
|
17
|
+
* An address as a mail API reads it (RFC 5322): a display name with specials is quoted, one
|
|
18
|
+
* outside ASCII is a MIME encoded-word — raw non-ASCII names are refused (SES), and an unquoted
|
|
19
|
+
* comma splits the address in two.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mimeAddress(address: EmailAddress): string;
|
|
22
|
+
/** One template's email metadata, resolved against the config. */
|
|
23
|
+
export interface ResolvedEmail {
|
|
24
|
+
from: EmailAddress;
|
|
25
|
+
/** The template's subscription topic; null for a transactional email. */
|
|
26
|
+
topic: string | null;
|
|
27
|
+
/** Absent when the template names none: the email goes out without a Reply-To. */
|
|
28
|
+
replyTo?: EmailAddress;
|
|
29
|
+
/**
|
|
30
|
+
* Absent when the email is transactional, or neither the template nor the config names one:
|
|
31
|
+
* the email has no unsubscribe link.
|
|
32
|
+
*/
|
|
33
|
+
unsubscribeUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The config's `preferencesUrl` with this copy's message id as `m`. Absent when the email is
|
|
36
|
+
* transactional, the config names no page, or the copy has no message id (reporting off): the
|
|
37
|
+
* email has no preferences link, and a layout renders none.
|
|
38
|
+
*/
|
|
39
|
+
preferencesUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
/** What a render knows of the copy beyond the template: its message id, when reporting records one. */
|
|
42
|
+
export interface EmailRenderOptions {
|
|
43
|
+
/** The copy's id in the reporting tables — what `/t/...` and `/subscriptions/by-message` key on. */
|
|
44
|
+
messageId?: string | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The message id a preview renders with: the preferences link shows in the studio and
|
|
48
|
+
* `GET /preview`, pointing at a copy that does not exist.
|
|
49
|
+
*/
|
|
50
|
+
export declare const PREVIEW_MESSAGE_ID = "00000000-0000-0000-0000-000000000000";
|
|
51
|
+
/**
|
|
52
|
+
* The template's metadata, its `unsubscribeUrl` falling back to the config's, and the
|
|
53
|
+
* preferences link built from the config's page and the copy's message id — for a topic email; a
|
|
54
|
+
* transactional one resolves to neither link. Leaves the inputs untouched.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveEmail(template: Pick<EmailTemplate, 'from' | 'replyTo' | 'unsubscribeUrl' | 'topic'>, config?: EmailConfig, options?: EmailRenderOptions): ResolvedEmail;
|
|
57
|
+
/** The preference page's URL for one copy: `m=<message id>` set on its query, the rest of it kept. */
|
|
58
|
+
export declare function preferencesLink(preferencesUrl: string, messageId: string): string;
|
|
59
|
+
//# sourceMappingURL=email.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.d.mts","names":[],"sources":["../src/email.ts"],"mappings":";;;;;;;;;;;;;;wBAgBgB,mBAAmB,SAAS;;;;;;wBAa5B,YAAY,SAAS;;iBAepB;EACf,MAAM;;EAEN;;EAEA,UAAU;;;;;EAKV;;;;;;EAMA;;;iBAIe;;EAEf;;;;;;qBAOW;;;;;;wBAOG,aACd,UAAU,KAAK,iEACf,SAAS,aACT,UAAS,qBACR;;wBAiBa,gBAAgB,wBAAwB"}
|
package/dist/email.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/email.ts
|
|
2
|
+
/**
|
|
3
|
+
* Email metadata: who a template's email comes from, where replies go, and the unsubscribe and
|
|
4
|
+
* preference links its layout carries. Each `emailTemplate` declares its own `from` (and
|
|
5
|
+
* `replyTo`, if replies should go elsewhere) and says what it is: a `topic` the recipient may
|
|
6
|
+
* unsubscribe from, or `transactional: true`. A topic email's unsubscribe link is the template's
|
|
7
|
+
* `unsubscribeUrl`, else the config's `email.unsubscribeUrl`, else none; its preferences link is
|
|
8
|
+
* the config's `email.preferencesUrl` with the copy's message id, when the copy has one (reporting
|
|
9
|
+
* on); a transactional email never has either, whatever the config says. `resolveEmail` is that
|
|
10
|
+
* rule, and the sender, the renderer, the Worker's preview and the studio all go through it. No
|
|
11
|
+
* React and no I/O here, so a browser can import it.
|
|
12
|
+
*/
|
|
13
|
+
/** `Name <email>`, or the bare address. */
|
|
14
|
+
function formatEmailAddress(address) {
|
|
15
|
+
if (typeof address === "string") return address;
|
|
16
|
+
return address.name === void 0 ? address.email : `${address.name} <${address.email}>`;
|
|
17
|
+
}
|
|
18
|
+
const ASCII = /^[\x20-\x7e]*$/;
|
|
19
|
+
const SPECIALS = /[()<>[\]:;@\\,."]/;
|
|
20
|
+
/**
|
|
21
|
+
* An address as a mail API reads it (RFC 5322): a display name with specials is quoted, one
|
|
22
|
+
* outside ASCII is a MIME encoded-word — raw non-ASCII names are refused (SES), and an unquoted
|
|
23
|
+
* comma splits the address in two.
|
|
24
|
+
*/
|
|
25
|
+
function mimeAddress(address) {
|
|
26
|
+
if (typeof address === "string") return address;
|
|
27
|
+
const { email, name } = address;
|
|
28
|
+
if (name === void 0 || name === "") return email;
|
|
29
|
+
if (!ASCII.test(name)) {
|
|
30
|
+
const bytes = new TextEncoder().encode(name);
|
|
31
|
+
let binary = "";
|
|
32
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
33
|
+
return `=?UTF-8?B?${btoa(binary)}?= <${email}>`;
|
|
34
|
+
}
|
|
35
|
+
if (SPECIALS.test(name)) return `"${name.replace(/(["\\])/g, "\\$1")}" <${email}>`;
|
|
36
|
+
return `${name} <${email}>`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The message id a preview renders with: the preferences link shows in the studio and
|
|
40
|
+
* `GET /preview`, pointing at a copy that does not exist.
|
|
41
|
+
*/
|
|
42
|
+
const PREVIEW_MESSAGE_ID = "00000000-0000-0000-0000-000000000000";
|
|
43
|
+
/**
|
|
44
|
+
* The template's metadata, its `unsubscribeUrl` falling back to the config's, and the
|
|
45
|
+
* preferences link built from the config's page and the copy's message id — for a topic email; a
|
|
46
|
+
* transactional one resolves to neither link. Leaves the inputs untouched.
|
|
47
|
+
*/
|
|
48
|
+
function resolveEmail(template, config, options = {}) {
|
|
49
|
+
const topical = template.topic !== null;
|
|
50
|
+
const unsubscribeUrl = topical ? template.unsubscribeUrl ?? config?.unsubscribeUrl : void 0;
|
|
51
|
+
const preferencesUrl = topical && config?.preferencesUrl !== void 0 && options.messageId !== void 0 ? preferencesLink(config.preferencesUrl, options.messageId) : void 0;
|
|
52
|
+
return {
|
|
53
|
+
from: template.from,
|
|
54
|
+
topic: template.topic,
|
|
55
|
+
...template.replyTo === void 0 ? {} : { replyTo: template.replyTo },
|
|
56
|
+
...unsubscribeUrl === void 0 ? {} : { unsubscribeUrl },
|
|
57
|
+
...preferencesUrl === void 0 ? {} : { preferencesUrl }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The preference page's URL for one copy: `m=<message id>` set on its query, the rest of it kept. */
|
|
61
|
+
function preferencesLink(preferencesUrl, messageId) {
|
|
62
|
+
const url = new URL(preferencesUrl);
|
|
63
|
+
url.searchParams.set("m", messageId);
|
|
64
|
+
return url.toString();
|
|
65
|
+
}
|
|
66
|
+
export { PREVIEW_MESSAGE_ID, formatEmailAddress, mimeAddress, preferencesLink, resolveEmail };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=email.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.mjs","names":[],"sources":["../src/email.ts"],"sourcesContent":["import type { EmailAddress, EmailConfig } from './template-rules';\nimport type { EmailTemplate } from './templates';\n\n/**\n * Email metadata: who a template's email comes from, where replies go, and the unsubscribe and\n * preference links its layout carries. Each `emailTemplate` declares its own `from` (and\n * `replyTo`, if replies should go elsewhere) and says what it is: a `topic` the recipient may\n * unsubscribe from, or `transactional: true`. A topic email's unsubscribe link is the template's\n * `unsubscribeUrl`, else the config's `email.unsubscribeUrl`, else none; its preferences link is\n * the config's `email.preferencesUrl` with the copy's message id, when the copy has one (reporting\n * on); a transactional email never has either, whatever the config says. `resolveEmail` is that\n * rule, and the sender, the renderer, the Worker's preview and the studio all go through it. No\n * React and no I/O here, so a browser can import it.\n */\n\n/** `Name <email>`, or the bare address. */\nexport function formatEmailAddress(address: EmailAddress): string {\n if (typeof address === 'string') return address;\n return address.name === undefined ? address.email : `${address.name} <${address.email}>`;\n}\n\nconst ASCII = /^[\\x20-\\x7e]*$/;\nconst SPECIALS = /[()<>[\\]:;@\\\\,.\"]/;\n\n/**\n * An address as a mail API reads it (RFC 5322): a display name with specials is quoted, one\n * outside ASCII is a MIME encoded-word — raw non-ASCII names are refused (SES), and an unquoted\n * comma splits the address in two.\n */\nexport function mimeAddress(address: EmailAddress): string {\n if (typeof address === 'string') return address;\n const { email, name } = address;\n if (name === undefined || name === '') return email;\n if (!ASCII.test(name)) {\n const bytes = new TextEncoder().encode(name);\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return `=?UTF-8?B?${btoa(binary)}?= <${email}>`;\n }\n if (SPECIALS.test(name)) return `\"${name.replace(/([\"\\\\])/g, '\\\\$1')}\" <${email}>`;\n return `${name} <${email}>`;\n}\n\n/** One template's email metadata, resolved against the config. */\nexport interface ResolvedEmail {\n from: EmailAddress;\n /** The template's subscription topic; null for a transactional email. */\n topic: string | null;\n /** Absent when the template names none: the email goes out without a Reply-To. */\n replyTo?: EmailAddress;\n /**\n * Absent when the email is transactional, or neither the template nor the config names one:\n * the email has no unsubscribe link.\n */\n unsubscribeUrl?: string;\n /**\n * The config's `preferencesUrl` with this copy's message id as `m`. Absent when the email is\n * transactional, the config names no page, or the copy has no message id (reporting off): the\n * email has no preferences link, and a layout renders none.\n */\n preferencesUrl?: string;\n}\n\n/** What a render knows of the copy beyond the template: its message id, when reporting records one. */\nexport interface EmailRenderOptions {\n /** The copy's id in the reporting tables — what `/t/...` and `/subscriptions/by-message` key on. */\n messageId?: string | undefined;\n}\n\n/**\n * The message id a preview renders with: the preferences link shows in the studio and\n * `GET /preview`, pointing at a copy that does not exist.\n */\nexport const PREVIEW_MESSAGE_ID = '00000000-0000-0000-0000-000000000000';\n\n/**\n * The template's metadata, its `unsubscribeUrl` falling back to the config's, and the\n * preferences link built from the config's page and the copy's message id — for a topic email; a\n * transactional one resolves to neither link. Leaves the inputs untouched.\n */\nexport function resolveEmail(\n template: Pick<EmailTemplate, 'from' | 'replyTo' | 'unsubscribeUrl' | 'topic'>,\n config?: EmailConfig,\n options: EmailRenderOptions = {}\n): ResolvedEmail {\n const topical = template.topic !== null;\n const unsubscribeUrl = topical ? (template.unsubscribeUrl ?? config?.unsubscribeUrl) : undefined;\n const preferencesUrl =\n topical && config?.preferencesUrl !== undefined && options.messageId !== undefined\n ? preferencesLink(config.preferencesUrl, options.messageId)\n : undefined;\n return {\n from: template.from,\n topic: template.topic,\n ...(template.replyTo === undefined ? {} : { replyTo: template.replyTo }),\n ...(unsubscribeUrl === undefined ? {} : { unsubscribeUrl }),\n ...(preferencesUrl === undefined ? {} : { preferencesUrl }),\n };\n}\n\n/** The preference page's URL for one copy: `m=<message id>` set on its query, the rest of it kept. */\nexport function preferencesLink(preferencesUrl: string, messageId: string): string {\n const url = new URL(preferencesUrl);\n url.searchParams.set('m', messageId);\n return url.toString();\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,SAA+B;CAChE,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,OAAO,QAAQ,SAAS,KAAA,IAAY,QAAQ,QAAQ,GAAG,QAAQ,KAAK,IAAI,QAAQ,MAAM;AACxF;AAEA,MAAM,QAAQ;AACd,MAAM,WAAW;;;;;;AAOjB,SAAgB,YAAY,SAA+B;CACzD,IAAI,OAAO,YAAY,UAAU,OAAO;CACxC,MAAM,EAAE,OAAO,SAAS;CACxB,IAAI,SAAS,KAAA,KAAa,SAAS,IAAI,OAAO;CAC9C,IAAI,CAAC,MAAM,KAAK,IAAI,GAAG;EACrB,MAAM,QAAQ,IAAI,YAAY,CAAC,CAAC,OAAO,IAAI;EAC3C,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,OAAO,UAAU,OAAO,aAAa,IAAI;EAC5D,OAAO,aAAa,KAAK,MAAM,EAAE,MAAM,MAAM;CAC/C;CACA,IAAI,SAAS,KAAK,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,YAAY,MAAM,EAAE,KAAK,MAAM;CAChF,OAAO,GAAG,KAAK,IAAI,MAAM;AAC3B;;;;;AAgCA,MAAa,qBAAqB;;;;;;AAOlC,SAAgB,aACd,UACA,QACA,UAA8B,CAAC,GAChB;CACf,MAAM,UAAU,SAAS,UAAU;CACnC,MAAM,iBAAiB,UAAW,SAAS,kBAAkB,QAAQ,iBAAkB,KAAA;CACvF,MAAM,iBACJ,WAAW,QAAQ,mBAAmB,KAAA,KAAa,QAAQ,cAAc,KAAA,IACrE,gBAAgB,OAAO,gBAAgB,QAAQ,SAAS,IACxD,KAAA;CACN,OAAO;EACL,MAAM,SAAS;EACf,OAAO,SAAS;EAChB,GAAI,SAAS,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,SAAS,QAAQ;EACtE,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;EACzD,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;CAC3D;AACF;;AAGA,SAAgB,gBAAgB,gBAAwB,WAA2B;CACjF,MAAM,MAAM,IAAI,IAAI,cAAc;CAClC,IAAI,aAAa,IAAI,KAAK,SAAS;CACnC,OAAO,IAAI,SAAS;AACtB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// src/engine/actions.ts
|
|
3
|
+
var RegistryActionInvoker = class {
|
|
4
|
+
registry;
|
|
5
|
+
constructor(actions) {
|
|
6
|
+
this.registry = new Map(actions.map((a) => [a.name, a]));
|
|
7
|
+
}
|
|
8
|
+
async invoke(invocation) {
|
|
9
|
+
const registered = this.registry.get(invocation.action);
|
|
10
|
+
if (registered === void 0) throw new Error(`action '${invocation.action}' is not registered in this runtime — was it removed from the deployed bundle while workflows still reference it?`);
|
|
11
|
+
await registered.handler(invocation.args, {
|
|
12
|
+
userId: invocation.userId,
|
|
13
|
+
idempotencyKey: invocation.idempotencyKey
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.RegistryActionInvoker = RegistryActionInvoker;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=actions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.cjs","names":[],"sources":["../../src/engine/actions.ts"],"sourcesContent":["import type { ScalarIR } from '../ir';\nimport type { ActionInvocation, ActionInvoker } from './ports';\n\n/**\n * The default ActionInvoker: a name → handler registry (the runtime half of\n * the dual-plane model — IR carries identity, the deployed bundle carries\n * code). Adapter-agnostic: the Cloudflare runner uses it and an AWS adapter\n * would too.\n */\n\n/**\n * What the registry stores — structurally satisfied by the DSL's ActionRef,\n * so the same `action(...)` objects the workflows reference are registered\n * directly, exactly like createMessageSender overrides plug in senders.\n */\nexport interface RegisteredAction {\n readonly name: string;\n /** Method syntax on purpose: accepts ActionRef handlers with narrower arg types. */\n handler(\n args: Record<string, ScalarIR | undefined>,\n ctx: { userId: string; idempotencyKey: string }\n ): Promise<void> | void;\n}\n\nexport class RegistryActionInvoker implements ActionInvoker {\n private readonly registry: ReadonlyMap<string, RegisteredAction>;\n\n constructor(actions: readonly RegisteredAction[]) {\n this.registry = new Map(actions.map((a) => [a.name, a]));\n }\n\n async invoke(invocation: ActionInvocation): Promise<void> {\n const registered = this.registry.get(invocation.action);\n if (registered === undefined) {\n throw new Error(\n `action '${invocation.action}' is not registered in this runtime — was it removed from the deployed bundle while workflows still reference it?`\n );\n }\n // The key is forwarded, not consumed here: this invoker has no state to\n // de-duplicate against, and the step body it runs inside is replayed — the\n // handler is the only place that can collapse the duplicate side effect.\n await registered.handler(invocation.args, {\n userId: invocation.userId,\n idempotencyKey: invocation.idempotencyKey,\n });\n }\n}\n"],"mappings":";;AAwBA,IAAa,wBAAb,MAA4D;CACzC;CAEjB,YAAY,SAAsC;EAChD,KAAK,WAAW,IAAI,IAAI,QAAQ,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CACzD;CAEA,MAAM,OAAO,YAA6C;EACxD,MAAM,aAAa,KAAK,SAAS,IAAI,WAAW,MAAM;EACtD,IAAI,eAAe,KAAA,GACjB,MAAM,IAAI,MACR,WAAW,WAAW,OAAO,kHAC/B;EAKF,MAAM,WAAW,QAAQ,WAAW,MAAM;GACxC,QAAQ,WAAW;GACnB,gBAAgB,WAAW;EAC7B,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ScalarIR } from "../ir.cjs";
|
|
2
|
+
import { ActionInvocation, ActionInvoker } from "./ports.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* The default ActionInvoker: a name → handler registry (the runtime half of
|
|
5
|
+
* the dual-plane model — IR carries identity, the deployed bundle carries
|
|
6
|
+
* code). Adapter-agnostic: the Cloudflare runner uses it and an AWS adapter
|
|
7
|
+
* would too.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* What the registry stores — structurally satisfied by the DSL's ActionRef,
|
|
11
|
+
* so the same `action(...)` objects the workflows reference are registered
|
|
12
|
+
* directly, exactly like createMessageSender overrides plug in senders.
|
|
13
|
+
*/
|
|
14
|
+
export interface RegisteredAction {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** Method syntax on purpose: accepts ActionRef handlers with narrower arg types. */
|
|
17
|
+
handler(args: Record<string, ScalarIR | undefined>, ctx: {
|
|
18
|
+
userId: string;
|
|
19
|
+
idempotencyKey: string;
|
|
20
|
+
}): Promise<void> | void;
|
|
21
|
+
}
|
|
22
|
+
export declare class RegistryActionInvoker implements ActionInvoker {
|
|
23
|
+
private readonly registry;
|
|
24
|
+
constructor(actions: readonly RegisteredAction[]);
|
|
25
|
+
invoke(invocation: ActionInvocation): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=actions.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.cts","names":[],"sources":["../../src/engine/actions.ts"],"mappings":";;;;;;;;;;;;;iBAeiB;WACN;;EAET,QACE,MAAM,eAAe,uBACrB;IAAO;IAAgB;MACtB;;qBAGQ,iCAAiC;mBAC3B;EAEjB,YAAY,kBAAkB;EAIxB,OAAO,YAAY,mBAAmB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ScalarIR } from "../ir.mjs";
|
|
2
|
+
import { ActionInvocation, ActionInvoker } from "./ports.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The default ActionInvoker: a name → handler registry (the runtime half of
|
|
5
|
+
* the dual-plane model — IR carries identity, the deployed bundle carries
|
|
6
|
+
* code). Adapter-agnostic: the Cloudflare runner uses it and an AWS adapter
|
|
7
|
+
* would too.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* What the registry stores — structurally satisfied by the DSL's ActionRef,
|
|
11
|
+
* so the same `action(...)` objects the workflows reference are registered
|
|
12
|
+
* directly, exactly like createMessageSender overrides plug in senders.
|
|
13
|
+
*/
|
|
14
|
+
export interface RegisteredAction {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** Method syntax on purpose: accepts ActionRef handlers with narrower arg types. */
|
|
17
|
+
handler(args: Record<string, ScalarIR | undefined>, ctx: {
|
|
18
|
+
userId: string;
|
|
19
|
+
idempotencyKey: string;
|
|
20
|
+
}): Promise<void> | void;
|
|
21
|
+
}
|
|
22
|
+
export declare class RegistryActionInvoker implements ActionInvoker {
|
|
23
|
+
private readonly registry;
|
|
24
|
+
constructor(actions: readonly RegisteredAction[]);
|
|
25
|
+
invoke(invocation: ActionInvocation): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=actions.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.mts","names":[],"sources":["../../src/engine/actions.ts"],"mappings":";;;;;;;;;;;;;iBAeiB;WACN;;EAET,QACE,MAAM,eAAe,uBACrB;IAAO;IAAgB;MACtB;;qBAGQ,iCAAiC;mBAC3B;EAEjB,YAAY,kBAAkB;EAIxB,OAAO,YAAY,mBAAmB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/engine/actions.ts
|
|
2
|
+
var RegistryActionInvoker = class {
|
|
3
|
+
registry;
|
|
4
|
+
constructor(actions) {
|
|
5
|
+
this.registry = new Map(actions.map((a) => [a.name, a]));
|
|
6
|
+
}
|
|
7
|
+
async invoke(invocation) {
|
|
8
|
+
const registered = this.registry.get(invocation.action);
|
|
9
|
+
if (registered === void 0) throw new Error(`action '${invocation.action}' is not registered in this runtime — was it removed from the deployed bundle while workflows still reference it?`);
|
|
10
|
+
await registered.handler(invocation.args, {
|
|
11
|
+
userId: invocation.userId,
|
|
12
|
+
idempotencyKey: invocation.idempotencyKey
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export { RegistryActionInvoker };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=actions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.mjs","names":[],"sources":["../../src/engine/actions.ts"],"sourcesContent":["import type { ScalarIR } from '../ir';\nimport type { ActionInvocation, ActionInvoker } from './ports';\n\n/**\n * The default ActionInvoker: a name → handler registry (the runtime half of\n * the dual-plane model — IR carries identity, the deployed bundle carries\n * code). Adapter-agnostic: the Cloudflare runner uses it and an AWS adapter\n * would too.\n */\n\n/**\n * What the registry stores — structurally satisfied by the DSL's ActionRef,\n * so the same `action(...)` objects the workflows reference are registered\n * directly, exactly like createMessageSender overrides plug in senders.\n */\nexport interface RegisteredAction {\n readonly name: string;\n /** Method syntax on purpose: accepts ActionRef handlers with narrower arg types. */\n handler(\n args: Record<string, ScalarIR | undefined>,\n ctx: { userId: string; idempotencyKey: string }\n ): Promise<void> | void;\n}\n\nexport class RegistryActionInvoker implements ActionInvoker {\n private readonly registry: ReadonlyMap<string, RegisteredAction>;\n\n constructor(actions: readonly RegisteredAction[]) {\n this.registry = new Map(actions.map((a) => [a.name, a]));\n }\n\n async invoke(invocation: ActionInvocation): Promise<void> {\n const registered = this.registry.get(invocation.action);\n if (registered === undefined) {\n throw new Error(\n `action '${invocation.action}' is not registered in this runtime — was it removed from the deployed bundle while workflows still reference it?`\n );\n }\n // The key is forwarded, not consumed here: this invoker has no state to\n // de-duplicate against, and the step body it runs inside is replayed — the\n // handler is the only place that can collapse the duplicate side effect.\n await registered.handler(invocation.args, {\n userId: invocation.userId,\n idempotencyKey: invocation.idempotencyKey,\n });\n }\n}\n"],"mappings":";AAwBA,IAAa,wBAAb,MAA4D;CACzC;CAEjB,YAAY,SAAsC;EAChD,KAAK,WAAW,IAAI,IAAI,QAAQ,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CACzD;CAEA,MAAM,OAAO,YAA6C;EACxD,MAAM,aAAa,KAAK,SAAS,IAAI,WAAW,MAAM;EACtD,IAAI,eAAe,KAAA,GACjB,MAAM,IAAI,MACR,WAAW,WAAW,OAAO,kHAC/B;EAKF,MAAM,WAAW,QAAQ,WAAW,MAAM;GACxC,QAAQ,WAAW;GACnB,gBAAgB,WAAW;EAC7B,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// src/engine/bucket.ts
|
|
3
|
+
/**
|
|
4
|
+
* Cohort bucketing — deterministic assignment of a user to an A/B arm.
|
|
5
|
+
*
|
|
6
|
+
* MurmurHash3 (x86, 32-bit, seed 0) over the UTF-8 bytes of the key, the same
|
|
7
|
+
* construction A/B systems like Unleash use: excellent avalanche behaviour
|
|
8
|
+
* (sequential user ids spread evenly, where FNV-1a showed low-bit bias) and a
|
|
9
|
+
* frozen, widely cross-checked algorithm. Hand-written on purpose: the engine
|
|
10
|
+
* core stays dependency-free, and the known-answer tests pin this
|
|
11
|
+
* implementation against the reference vectors — a stronger guarantee than
|
|
12
|
+
* trusting an npm package's variant.
|
|
13
|
+
*
|
|
14
|
+
* The bucket function is a permanent contract: changing it reshuffles every
|
|
15
|
+
* in-flight cohort, so it must never change once production traffic exists.
|
|
16
|
+
*/
|
|
17
|
+
/** MurmurHash3 x86 32-bit over raw bytes; seed 0. Returns an unsigned 32-bit integer. */
|
|
18
|
+
function murmur3(bytes, seed = 0) {
|
|
19
|
+
const c1 = 0xcc9e2d51;
|
|
20
|
+
const c2 = 461845907;
|
|
21
|
+
let h = seed >>> 0;
|
|
22
|
+
const tail = bytes.length & -4;
|
|
23
|
+
for (let i = 0; i < tail; i += 4) {
|
|
24
|
+
let k = bytes[i] | bytes[i + 1] << 8 | bytes[i + 2] << 16 | bytes[i + 3] << 24;
|
|
25
|
+
k = Math.imul(k, c1);
|
|
26
|
+
k = k << 15 | k >>> 17;
|
|
27
|
+
k = Math.imul(k, c2);
|
|
28
|
+
h ^= k;
|
|
29
|
+
h = h << 13 | h >>> 19;
|
|
30
|
+
h = Math.imul(h, 5) + 0xe6546b64 >>> 0;
|
|
31
|
+
}
|
|
32
|
+
let k = 0;
|
|
33
|
+
const remainder = bytes.length & 3;
|
|
34
|
+
if (remainder === 3) k ^= bytes[tail + 2] << 16;
|
|
35
|
+
if (remainder >= 2) k ^= bytes[tail + 1] << 8;
|
|
36
|
+
if (remainder >= 1) {
|
|
37
|
+
k ^= bytes[tail];
|
|
38
|
+
k = Math.imul(k, c1);
|
|
39
|
+
k = k << 15 | k >>> 17;
|
|
40
|
+
k = Math.imul(k, c2);
|
|
41
|
+
h ^= k;
|
|
42
|
+
}
|
|
43
|
+
h ^= bytes.length;
|
|
44
|
+
h ^= h >>> 16;
|
|
45
|
+
h = Math.imul(h, 0x85ebca6b);
|
|
46
|
+
h ^= h >>> 13;
|
|
47
|
+
h = Math.imul(h, 0xc2b2ae35);
|
|
48
|
+
h ^= h >>> 16;
|
|
49
|
+
return h >>> 0;
|
|
50
|
+
}
|
|
51
|
+
const utf8 = new TextEncoder();
|
|
52
|
+
/**
|
|
53
|
+
* Bucket resolution: basis points, i.e. hundredths of a percent. Weights are
|
|
54
|
+
* compared on the same integer grid (weight% × 100), so fractional splits like
|
|
55
|
+
* 33.3/33.3/33.4 are honoured exactly and the whole path stays float-free —
|
|
56
|
+
* the Optimizely/Statsig construction.
|
|
57
|
+
*/
|
|
58
|
+
const BUCKET_RESOLUTION = 1e4;
|
|
59
|
+
/**
|
|
60
|
+
* Map a bucketing key (`${userId}:${cohortKey}`) to [0, 10000). Keys hash
|
|
61
|
+
* their UTF-8 bytes, so results agree with any standard Murmur3 implementation
|
|
62
|
+
* regardless of the user id's alphabet.
|
|
63
|
+
*/
|
|
64
|
+
function hashToBucket(input) {
|
|
65
|
+
return murmur3(utf8.encode(input)) % BUCKET_RESOLUTION;
|
|
66
|
+
}
|
|
67
|
+
exports.BUCKET_RESOLUTION = BUCKET_RESOLUTION;
|
|
68
|
+
exports.hashToBucket = hashToBucket;
|
|
69
|
+
exports.murmur3 = murmur3;
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=bucket.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket.cjs","names":[],"sources":["../../src/engine/bucket.ts"],"sourcesContent":["/**\n * Cohort bucketing — deterministic assignment of a user to an A/B arm.\n *\n * MurmurHash3 (x86, 32-bit, seed 0) over the UTF-8 bytes of the key, the same\n * construction A/B systems like Unleash use: excellent avalanche behaviour\n * (sequential user ids spread evenly, where FNV-1a showed low-bit bias) and a\n * frozen, widely cross-checked algorithm. Hand-written on purpose: the engine\n * core stays dependency-free, and the known-answer tests pin this\n * implementation against the reference vectors — a stronger guarantee than\n * trusting an npm package's variant.\n *\n * The bucket function is a permanent contract: changing it reshuffles every\n * in-flight cohort, so it must never change once production traffic exists.\n */\n\n/** MurmurHash3 x86 32-bit over raw bytes; seed 0. Returns an unsigned 32-bit integer. */\nexport function murmur3(bytes: Uint8Array, seed = 0): number {\n const c1 = 0xcc9e2d51;\n const c2 = 0x1b873593;\n let h = seed >>> 0;\n\n const tail = bytes.length & ~3;\n for (let i = 0; i < tail; i += 4) {\n let k = bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24);\n k = Math.imul(k, c1);\n k = (k << 15) | (k >>> 17);\n k = Math.imul(k, c2);\n h ^= k;\n h = (h << 13) | (h >>> 19);\n h = (Math.imul(h, 5) + 0xe6546b64) >>> 0;\n }\n\n let k = 0;\n const remainder = bytes.length & 3;\n if (remainder === 3) k ^= bytes[tail + 2] << 16;\n if (remainder >= 2) k ^= bytes[tail + 1] << 8;\n if (remainder >= 1) {\n k ^= bytes[tail];\n k = Math.imul(k, c1);\n k = (k << 15) | (k >>> 17);\n k = Math.imul(k, c2);\n h ^= k;\n }\n\n h ^= bytes.length;\n h ^= h >>> 16;\n h = Math.imul(h, 0x85ebca6b);\n h ^= h >>> 13;\n h = Math.imul(h, 0xc2b2ae35);\n h ^= h >>> 16;\n return h >>> 0;\n}\n\nconst utf8 = new TextEncoder();\n\n/**\n * Bucket resolution: basis points, i.e. hundredths of a percent. Weights are\n * compared on the same integer grid (weight% × 100), so fractional splits like\n * 33.3/33.3/33.4 are honoured exactly and the whole path stays float-free —\n * the Optimizely/Statsig construction.\n */\nexport const BUCKET_RESOLUTION = 10_000;\n\n/**\n * Map a bucketing key (`${userId}:${cohortKey}`) to [0, 10000). Keys hash\n * their UTF-8 bytes, so results agree with any standard Murmur3 implementation\n * regardless of the user id's alphabet.\n */\nexport function hashToBucket(input: string): number {\n return murmur3(utf8.encode(input)) % BUCKET_RESOLUTION;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAgB,QAAQ,OAAmB,OAAO,GAAW;CAC3D,MAAM,KAAK;CACX,MAAM,KAAK;CACX,IAAI,IAAI,SAAS;CAEjB,MAAM,OAAO,MAAM,SAAS;CAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG;EAChC,IAAI,IAAI,MAAM,KAAM,MAAM,IAAI,MAAM,IAAM,MAAM,IAAI,MAAM,KAAO,MAAM,IAAI,MAAM;EACjF,IAAI,KAAK,KAAK,GAAG,EAAE;EACnB,IAAK,KAAK,KAAO,MAAM;EACvB,IAAI,KAAK,KAAK,GAAG,EAAE;EACnB,KAAK;EACL,IAAK,KAAK,KAAO,MAAM;EACvB,IAAK,KAAK,KAAK,GAAG,CAAC,IAAI,eAAgB;CACzC;CAEA,IAAI,IAAI;CACR,MAAM,YAAY,MAAM,SAAS;CACjC,IAAI,cAAc,GAAG,KAAK,MAAM,OAAO,MAAM;CAC7C,IAAI,aAAa,GAAG,KAAK,MAAM,OAAO,MAAM;CAC5C,IAAI,aAAa,GAAG;EAClB,KAAK,MAAM;EACX,IAAI,KAAK,KAAK,GAAG,EAAE;EACnB,IAAK,KAAK,KAAO,MAAM;EACvB,IAAI,KAAK,KAAK,GAAG,EAAE;EACnB,KAAK;CACP;CAEA,KAAK,MAAM;CACX,KAAK,MAAM;CACX,IAAI,KAAK,KAAK,GAAG,UAAU;CAC3B,KAAK,MAAM;CACX,IAAI,KAAK,KAAK,GAAG,UAAU;CAC3B,KAAK,MAAM;CACX,OAAO,MAAM;AACf;AAEA,MAAM,OAAO,IAAI,YAAY;;;;;;;AAQ7B,MAAa,oBAAoB;;;;;;AAOjC,SAAgB,aAAa,OAAuB;CAClD,OAAO,QAAQ,KAAK,OAAO,KAAK,CAAC,IAAI;AACvC"}
|