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.
- package/LICENSE +21 -0
- package/README.md +2082 -2
- 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 +279 -3
- package/src/cloudflare/workers.d.ts +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.mts","names":[],"sources":["../../src/dsl/workflow.ts"],"mappings":";;;;;;;;;;;;;iBA0BiB;EACf,WAAW;;EAEX,SAAS;;EAET;;;;;;;;;;;;;;;;;;YAmBU;EACN;;EACA;EAAoB,WAAW;;EAC/B;EAAoB,WAAW;;iBAyCpB;;;;;;EAMf;;EAGA,SAAS;;;;;EAMT,SAAS;;;;;;EAOT,OAAO,YAAY;;EAGnB,WAAW;;EASX;;EAGA;;iBAGe,wBAAwB;EACvC,QAAQ;;;;;;;;;;;;;wBAoIM,SAAS,YAAY,qBAAqB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { semanticHash } from "../hash.mjs";
|
|
2
|
+
import { WorkflowIR } from "../ir.mjs";
|
|
3
|
+
import { captureLoc } from "../provenance.mjs";
|
|
4
|
+
import { condIR, positiveDurationIR } from "./condition.mjs";
|
|
5
|
+
import { FlowBuilderImpl } from "./flow.mjs";
|
|
6
|
+
// src/dsl/workflow.ts
|
|
7
|
+
/**
|
|
8
|
+
* Validate and compile the policy. The types already refuse a bad one; this is for a caller
|
|
9
|
+
* without them (plain JS, a value cast through `any`), so the message names what is allowed.
|
|
10
|
+
*/
|
|
11
|
+
function reentryIR(value) {
|
|
12
|
+
if (typeof value !== "object" || value === null) throw new Error("workflow(): `reentry` is required — { mode: 'never' }, { mode: 'after_exit' } or { mode: 'concurrent' }");
|
|
13
|
+
const { mode, cooldown, ...extra } = value;
|
|
14
|
+
if (mode !== "never" && mode !== "after_exit" && mode !== "concurrent") throw new Error(`workflow(): reentry.mode must be 'never', 'after_exit' or 'concurrent', got ${JSON.stringify(mode)}`);
|
|
15
|
+
const unknownKeys = Object.keys(extra);
|
|
16
|
+
if (unknownKeys.length > 0) throw new Error(`workflow(): reentry takes only \`mode\` and \`cooldown\`, got '${unknownKeys.join("', '")}'`);
|
|
17
|
+
if (mode === "never") {
|
|
18
|
+
if (cooldown !== void 0) throw new Error("workflow(): reentry { mode: 'never' } takes no cooldown — a user enters once");
|
|
19
|
+
return { mode };
|
|
20
|
+
}
|
|
21
|
+
if (cooldown === void 0) return { mode };
|
|
22
|
+
if (typeof cooldown !== "string") throw new TypeError(`workflow(): reentry.cooldown must be a duration such as '7 days', got ${JSON.stringify(cooldown)}`);
|
|
23
|
+
return {
|
|
24
|
+
mode,
|
|
25
|
+
cooldown: positiveDurationIR(cooldown, "reentry.cooldown")
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Assign node ids from the structural path (rules in ir.ts's header). Written
|
|
30
|
+
* in place into the tree toIR deep-cloned, never into the builder's own nodes.
|
|
31
|
+
*/
|
|
32
|
+
function assignIds(nodes, prefix) {
|
|
33
|
+
nodes.forEach((node, i) => {
|
|
34
|
+
const id = prefix === "" ? String(i) : `${prefix}.${i}`;
|
|
35
|
+
node.id = id;
|
|
36
|
+
switch (node.type) {
|
|
37
|
+
case "branch":
|
|
38
|
+
node.cases.forEach((c, ci) => assignIds(c.flow, `${id}.c${ci}`));
|
|
39
|
+
if (node.otherwise) assignIds(node.otherwise, `${id}.o`);
|
|
40
|
+
break;
|
|
41
|
+
case "cohort":
|
|
42
|
+
node.arms.forEach((arm) => assignIds(arm.flow, `${id}.${arm.name}`));
|
|
43
|
+
break;
|
|
44
|
+
case "wait_until": if (Array.isArray(node.onTimeout)) assignIds(node.onTimeout, `${id}.t`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Ids are derived, never authored, so a duplicate is always a compiler bug —
|
|
50
|
+
* and a silent one: assignIds writes in place, so the second write simply wins
|
|
51
|
+
* and two nodes ship as one. What that costs is concrete, because an id is the
|
|
52
|
+
* durable step name (`step.do('{id}:send')`), the message idempotency key
|
|
53
|
+
* (`{instanceId}:{id}`) and the cohort bucket seed: the twins share a
|
|
54
|
+
* checkpoint, and the second send is suppressed as a duplicate of the first.
|
|
55
|
+
* Cheap to check once at the end of the compile, so it is checked.
|
|
56
|
+
*/
|
|
57
|
+
function assertUniqueIds(nodes, seen = /* @__PURE__ */ new Set()) {
|
|
58
|
+
for (const node of nodes) {
|
|
59
|
+
if (seen.has(node.id)) throw new Error(`toIR(): node id '${node.id}' is used twice — ids are durable step names and message idempotency keys, so they must be unique`);
|
|
60
|
+
seen.add(node.id);
|
|
61
|
+
switch (node.type) {
|
|
62
|
+
case "branch":
|
|
63
|
+
for (const branchCase of node.cases) assertUniqueIds(branchCase.flow, seen);
|
|
64
|
+
if (node.otherwise) assertUniqueIds(node.otherwise, seen);
|
|
65
|
+
break;
|
|
66
|
+
case "cohort":
|
|
67
|
+
for (const arm of node.arms) assertUniqueIds(arm.flow, seen);
|
|
68
|
+
break;
|
|
69
|
+
case "wait_until": if (Array.isArray(node.onTimeout)) assertUniqueIds(node.onTimeout, seen);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
var WorkflowBuilderImpl = class extends FlowBuilderImpl {
|
|
74
|
+
options;
|
|
75
|
+
loc;
|
|
76
|
+
constructor(options, loc) {
|
|
77
|
+
super();
|
|
78
|
+
this.options = options;
|
|
79
|
+
this.loc = loc;
|
|
80
|
+
}
|
|
81
|
+
goalIR() {
|
|
82
|
+
const goal = this.options.goal;
|
|
83
|
+
if (goal === void 0) return void 0;
|
|
84
|
+
if ("__condition" in goal) return {
|
|
85
|
+
condition: condIR(goal),
|
|
86
|
+
exitOnMatch: true
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
condition: condIR(goal.condition),
|
|
90
|
+
...goal.within !== void 0 ? { within: positiveDurationIR(goal.within, "goal.within") } : {},
|
|
91
|
+
exitOnMatch: goal.exitOnMatch ?? true
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
metaIR() {
|
|
95
|
+
const { name, description } = this.options;
|
|
96
|
+
if (name === void 0 && description === void 0 && this.loc === void 0) return;
|
|
97
|
+
return {
|
|
98
|
+
...name !== void 0 ? { name } : {},
|
|
99
|
+
...description !== void 0 ? { description } : {},
|
|
100
|
+
...this.loc !== void 0 ? { loc: this.loc } : {}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
toIR() {
|
|
104
|
+
const flowNodes = structuredClone(this.nodes);
|
|
105
|
+
assignIds(flowNodes, "");
|
|
106
|
+
assertUniqueIds(flowNodes);
|
|
107
|
+
const reentry = reentryIR(this.options.reentry);
|
|
108
|
+
const goal = this.goalIR();
|
|
109
|
+
const meta = this.metaIR();
|
|
110
|
+
const body = {
|
|
111
|
+
irVersion: 3,
|
|
112
|
+
id: this.options.id,
|
|
113
|
+
...meta !== void 0 ? { meta } : {},
|
|
114
|
+
trigger: this.options.trigger.ir,
|
|
115
|
+
reentry,
|
|
116
|
+
...goal !== void 0 ? { goal } : {},
|
|
117
|
+
...this.options.exitWhen !== void 0 ? { exitWhen: condIR(this.options.exitWhen) } : {},
|
|
118
|
+
flow: flowNodes
|
|
119
|
+
};
|
|
120
|
+
return WorkflowIR.parse({
|
|
121
|
+
...body,
|
|
122
|
+
contentHash: semanticHash(body)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Workflow definition: an id, configuration (trigger / reentry / goal / exitWhen),
|
|
128
|
+
* optional labels, and chained steps.
|
|
129
|
+
*
|
|
130
|
+
* export const onboarding = workflow({
|
|
131
|
+
* id: 'onboarding',
|
|
132
|
+
* name: 'Onboarding',
|
|
133
|
+
* trigger: trigger.event(e.sign_up),
|
|
134
|
+
* reentry: { mode: 'never' },
|
|
135
|
+
* }).email(email.welcome);
|
|
136
|
+
*/
|
|
137
|
+
function workflow(definition) {
|
|
138
|
+
return new WorkflowBuilderImpl(definition, captureLoc(workflow));
|
|
139
|
+
}
|
|
140
|
+
export { workflow };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=workflow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.mjs","names":["WorkflowIRSchema"],"sources":["../../src/dsl/workflow.ts"],"sourcesContent":["import { semanticHash } from '../hash';\nimport {\n type GoalIR,\n IR_VERSION,\n type MetaIR,\n type NodeIR,\n type ReentryIR,\n type SourceLocIR,\n type WorkflowIR,\n WorkflowIR as WorkflowIRSchema,\n} from '../ir';\nimport { captureLoc } from '../provenance';\nimport type { Duration } from './base';\nimport { type Condition, condIR, positiveDurationIR } from './condition';\nimport { type FlowBuilder, FlowBuilderImpl } from './flow';\nimport type { TriggerInternal, TriggerRef } from './trigger';\n\n/**\n * The workflow — a named flow chain plus its configuration (options =\n * configuration, the chain = steps), and the compiler back half: `toIR()`\n * deep-clones the collected nodes, assigns structural-path ids, computes the\n * contentHash (metadata stripped, see hash.ts) and self-checks the result\n * against the authoritative IR schema.\n */\n\n/** Full conversion-goal configuration (customer.io's Goal & Exit semantics). */\nexport interface GoalOptions {\n condition: Condition;\n /** Attribution window: how long after entry a match still counts as a conversion. Unbounded by default. */\n within?: Duration;\n /** Exit on conversion. Defaults to true — this is what absorbs all those True→Exit arms in a UI canvas. */\n exitOnMatch?: boolean;\n}\n\n/**\n * Re-entry policy: whether a user who already entered this workflow may enter it again (README\n * \"Re-entry\"). Required, with no default, and written one way only — an object naming its `mode`:\n *\n * - `{ mode: 'never' }` — a user enters once (onboarding).\n * - `{ mode: 'after_exit' }` — again, but only once their previous instance of this workflow has\n * ended (completed, converted, exited or failed): at most one runs per user at a time.\n * - `{ mode: 'concurrent' }` — again even while a previous instance still runs.\n *\n * `cooldown` (positive) is the least time from the user's previous entry — not its exit — to the\n * next one; with `after_exit` both conditions must hold. `never` takes no cooldown. A\n * segment-triggered workflow re-enters a user only when they qualify afresh (left the segment and\n * matched again), never on every evaluation while they stay a member.\n *\n * workflow({ id: 'checkout_recovery', trigger, reentry: { mode: 'after_exit', cooldown: '7 days' } })\n */\nexport type Reentry =\n | { mode: 'never' }\n | { mode: 'after_exit'; cooldown?: Duration }\n | { mode: 'concurrent'; cooldown?: Duration };\n\n/**\n * Validate and compile the policy. The types already refuse a bad one; this is for a caller\n * without them (plain JS, a value cast through `any`), so the message names what is allowed.\n */\nfunction reentryIR(value: unknown): ReentryIR {\n if (typeof value !== 'object' || value === null) {\n throw new Error(\n \"workflow(): `reentry` is required — { mode: 'never' }, { mode: 'after_exit' } or { mode: 'concurrent' }\"\n );\n }\n const { mode, cooldown, ...extra } = value as { mode?: unknown; cooldown?: unknown };\n if (mode !== 'never' && mode !== 'after_exit' && mode !== 'concurrent') {\n throw new Error(\n `workflow(): reentry.mode must be 'never', 'after_exit' or 'concurrent', got ${JSON.stringify(mode)}`\n );\n }\n const unknownKeys = Object.keys(extra);\n if (unknownKeys.length > 0) {\n throw new Error(\n `workflow(): reentry takes only \\`mode\\` and \\`cooldown\\`, got '${unknownKeys.join(\"', '\")}'`\n );\n }\n if (mode === 'never') {\n if (cooldown !== undefined) {\n throw new Error(\n \"workflow(): reentry { mode: 'never' } takes no cooldown — a user enters once\"\n );\n }\n return { mode };\n }\n if (cooldown === undefined) return { mode };\n if (typeof cooldown !== 'string') {\n throw new TypeError(\n `workflow(): reentry.cooldown must be a duration such as '7 days', got ${JSON.stringify(cooldown)}`\n );\n }\n return { mode, cooldown: positiveDurationIR(cooldown as Duration, 'reentry.cooldown') };\n}\n\nexport interface WorkflowDefinition {\n /**\n * Wire identity — engine instances, the entry ledger and stats keys are all\n * built on it (`WorkflowIR.id`), so it is not something to rename for\n * readability; `name` is.\n */\n id: string;\n\n /** Trigger: a trigger.xxx() asset. TODO: multiple triggers. */\n trigger: TriggerRef;\n\n /**\n * Re-entry policy, required: whether a user may enter again after their first entry\n * (`Reentry`). There is no default, so a recurring workflow cannot silently enter users once.\n */\n reentry: Reentry;\n\n /**\n * Conversion goal: feeds reporting (conversion rate / attribution) and by\n * default exits on match. Checked before each node runs. Pass a condition\n * for the shorthand, or GoalOptions for the full form.\n */\n goal?: Condition | GoalOptions;\n\n /** Plain exit condition: leaving without counting as a conversion (unsubscribed, no longer eligible). Coexists with goal. */\n exitWhen?: Condition;\n\n /*\n * Everything below is human-facing metadata: it lands in IR's `meta` field\n * and is **excluded from contentHash**. Editing it neither invalidates the\n * version in-flight users are pinned to nor shows up as a change in plan.\n */\n\n /** Human label: what the studio shows instead of the id. */\n name?: string;\n\n /** One line on what this flow does (UI lists, plan output). */\n description?: string;\n}\n\nexport interface WorkflowBuilder extends FlowBuilder {\n toIR(): WorkflowIR;\n}\n\n/**\n * Assign node ids from the structural path (rules in ir.ts's header). Written\n * in place into the tree toIR deep-cloned, never into the builder's own nodes.\n */\nfunction assignIds(nodes: NodeIR[], prefix: string): void {\n nodes.forEach((node, i) => {\n const id = prefix === '' ? String(i) : `${prefix}.${i}`;\n node.id = id;\n switch (node.type) {\n case 'branch':\n node.cases.forEach((c, ci) => assignIds(c.flow, `${id}.c${ci}`));\n if (node.otherwise) assignIds(node.otherwise, `${id}.o`);\n break;\n case 'cohort':\n node.arms.forEach((arm) => assignIds(arm.flow, `${id}.${arm.name}`));\n break;\n case 'wait_until':\n if (Array.isArray(node.onTimeout)) assignIds(node.onTimeout, `${id}.t`);\n break;\n default:\n break;\n }\n });\n}\n\n/**\n * Ids are derived, never authored, so a duplicate is always a compiler bug —\n * and a silent one: assignIds writes in place, so the second write simply wins\n * and two nodes ship as one. What that costs is concrete, because an id is the\n * durable step name (`step.do('{id}:send')`), the message idempotency key\n * (`{instanceId}:{id}`) and the cohort bucket seed: the twins share a\n * checkpoint, and the second send is suppressed as a duplicate of the first.\n * Cheap to check once at the end of the compile, so it is checked.\n */\nfunction assertUniqueIds(nodes: readonly NodeIR[], seen = new Set<string>()): void {\n for (const node of nodes) {\n if (seen.has(node.id)) {\n throw new Error(\n `toIR(): node id '${node.id}' is used twice — ids are durable step names and message idempotency keys, so they must be unique`\n );\n }\n seen.add(node.id);\n switch (node.type) {\n case 'branch':\n for (const branchCase of node.cases) assertUniqueIds(branchCase.flow, seen);\n if (node.otherwise) assertUniqueIds(node.otherwise, seen);\n break;\n case 'cohort':\n for (const arm of node.arms) assertUniqueIds(arm.flow, seen);\n break;\n case 'wait_until':\n if (Array.isArray(node.onTimeout)) assertUniqueIds(node.onTimeout, seen);\n break;\n default:\n break;\n }\n }\n}\n\nclass WorkflowBuilderImpl extends FlowBuilderImpl implements WorkflowBuilder {\n constructor(\n private readonly options: WorkflowDefinition,\n /** Callsite of the workflow() call (provenance; lands in meta.loc). */\n private readonly loc: SourceLocIR | undefined\n ) {\n super();\n }\n\n private goalIR(): GoalIR | undefined {\n const goal = this.options.goal;\n if (goal === undefined) return undefined;\n if ('__condition' in goal) {\n return { condition: condIR(goal), exitOnMatch: true };\n }\n return {\n condition: condIR(goal.condition),\n ...(goal.within !== undefined\n ? { within: positiveDurationIR(goal.within, 'goal.within') }\n : {}),\n exitOnMatch: goal.exitOnMatch ?? true,\n };\n }\n\n private metaIR(): MetaIR | undefined {\n const { name, description } = this.options;\n if (name === undefined && description === undefined && this.loc === undefined) {\n return undefined;\n }\n return {\n ...(name !== undefined ? { name } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(this.loc !== undefined ? { loc: this.loc } : {}),\n };\n }\n\n toIR(): WorkflowIR {\n const flowNodes = structuredClone(this.nodes);\n assignIds(flowNodes, '');\n assertUniqueIds(flowNodes);\n const reentry = reentryIR(this.options.reentry);\n const goal = this.goalIR();\n const meta = this.metaIR();\n const body = {\n irVersion: IR_VERSION,\n id: this.options.id,\n ...(meta !== undefined ? { meta } : {}),\n trigger: (this.options.trigger as TriggerInternal).ir,\n reentry,\n ...(goal !== undefined ? { goal } : {}),\n ...(this.options.exitWhen !== undefined ? { exitWhen: condIR(this.options.exitWhen) } : {}),\n flow: flowNodes,\n };\n // semanticHash strips meta / label / reason, so metadata edits leave contentHash alone\n // Self-check: the compiler's output must pass IR's authoritative schema\n return WorkflowIRSchema.parse({ ...body, contentHash: semanticHash(body) });\n }\n}\n\n/**\n * Workflow definition: an id, configuration (trigger / reentry / goal / exitWhen),\n * optional labels, and chained steps.\n *\n * export const onboarding = workflow({\n * id: 'onboarding',\n * name: 'Onboarding',\n * trigger: trigger.event(e.sign_up),\n * reentry: { mode: 'never' },\n * }).email(email.welcome);\n */\nexport function workflow(definition: WorkflowDefinition): WorkflowBuilder {\n return new WorkflowBuilderImpl(definition, captureLoc(workflow));\n}\n"],"mappings":";;;;;;;;;;AA2DA,SAAS,UAAU,OAA2B;CAC5C,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,MAAM,IAAI,MACR,yGACF;CAEF,MAAM,EAAE,MAAM,UAAU,GAAG,UAAU;CACrC,IAAI,SAAS,WAAW,SAAS,gBAAgB,SAAS,cACxD,MAAM,IAAI,MACR,+EAA+E,KAAK,UAAU,IAAI,GACpG;CAEF,MAAM,cAAc,OAAO,KAAK,KAAK;CACrC,IAAI,YAAY,SAAS,GACvB,MAAM,IAAI,MACR,kEAAkE,YAAY,KAAK,MAAM,EAAE,EAC7F;CAEF,IAAI,SAAS,SAAS;EACpB,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MACR,8EACF;EAEF,OAAO,EAAE,KAAK;CAChB;CACA,IAAI,aAAa,KAAA,GAAW,OAAO,EAAE,KAAK;CAC1C,IAAI,OAAO,aAAa,UACtB,MAAM,IAAI,UACR,yEAAyE,KAAK,UAAU,QAAQ,GAClG;CAEF,OAAO;EAAE;EAAM,UAAU,mBAAmB,UAAsB,kBAAkB;CAAE;AACxF;;;;;AAkDA,SAAS,UAAU,OAAiB,QAAsB;CACxD,MAAM,SAAS,MAAM,MAAM;EACzB,MAAM,KAAK,WAAW,KAAK,OAAO,CAAC,IAAI,GAAG,OAAO,GAAG;EACpD,KAAK,KAAK;EACV,QAAQ,KAAK,MAAb;GACE,KAAK;IACH,KAAK,MAAM,SAAS,GAAG,OAAO,UAAU,EAAE,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC;IAC/D,IAAI,KAAK,WAAW,UAAU,KAAK,WAAW,GAAG,GAAG,GAAG;IACvD;GACF,KAAK;IACH,KAAK,KAAK,SAAS,QAAQ,UAAU,IAAI,MAAM,GAAG,GAAG,GAAG,IAAI,MAAM,CAAC;IACnE;GACF,KAAK,cACH,IAAI,MAAM,QAAQ,KAAK,SAAS,GAAG,UAAU,KAAK,WAAW,GAAG,GAAG,GAAG;EAI1E;CACF,CAAC;AACH;;;;;;;;;;AAWA,SAAS,gBAAgB,OAA0B,uBAAO,IAAI,IAAY,GAAS;CACjF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,IAAI,KAAK,EAAE,GAClB,MAAM,IAAI,MACR,oBAAoB,KAAK,GAAG,kGAC9B;EAEF,KAAK,IAAI,KAAK,EAAE;EAChB,QAAQ,KAAK,MAAb;GACE,KAAK;IACH,KAAK,MAAM,cAAc,KAAK,OAAO,gBAAgB,WAAW,MAAM,IAAI;IAC1E,IAAI,KAAK,WAAW,gBAAgB,KAAK,WAAW,IAAI;IACxD;GACF,KAAK;IACH,KAAK,MAAM,OAAO,KAAK,MAAM,gBAAgB,IAAI,MAAM,IAAI;IAC3D;GACF,KAAK,cACH,IAAI,MAAM,QAAQ,KAAK,SAAS,GAAG,gBAAgB,KAAK,WAAW,IAAI;EAI3E;CACF;AACF;AAEA,IAAM,sBAAN,cAAkC,gBAA2C;CAExD;CAEA;CAHnB,YACmB,SAEA,KACjB;EACA,MAAM;EAJW,KAAA,UAAA;EAEA,KAAA,MAAA;CAGnB;CAEQ,SAA6B;EACnC,MAAM,OAAO,KAAK,QAAQ;EAC1B,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,IAAI,iBAAiB,MACnB,OAAO;GAAE,WAAW,OAAO,IAAI;GAAG,aAAa;EAAK;EAEtD,OAAO;GACL,WAAW,OAAO,KAAK,SAAS;GAChC,GAAI,KAAK,WAAW,KAAA,IAChB,EAAE,QAAQ,mBAAmB,KAAK,QAAQ,aAAa,EAAE,IACzD,CAAC;GACL,aAAa,KAAK,eAAe;EACnC;CACF;CAEQ,SAA6B;EACnC,MAAM,EAAE,MAAM,gBAAgB,KAAK;EACnC,IAAI,SAAS,KAAA,KAAa,gBAAgB,KAAA,KAAa,KAAK,QAAQ,KAAA,GAClE;EAEF,OAAO;GACL,GAAI,SAAS,KAAA,IAAY,EAAE,KAAK,IAAI,CAAC;GACrC,GAAI,gBAAgB,KAAA,IAAY,EAAE,YAAY,IAAI,CAAC;GACnD,GAAI,KAAK,QAAQ,KAAA,IAAY,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC;EACpD;CACF;CAEA,OAAmB;EACjB,MAAM,YAAY,gBAAgB,KAAK,KAAK;EAC5C,UAAU,WAAW,EAAE;EACvB,gBAAgB,SAAS;EACzB,MAAM,UAAU,UAAU,KAAK,QAAQ,OAAO;EAC9C,MAAM,OAAO,KAAK,OAAO;EACzB,MAAM,OAAO,KAAK,OAAO;EACzB,MAAM,OAAO;GACX,WAAA;GACA,IAAI,KAAK,QAAQ;GACjB,GAAI,SAAS,KAAA,IAAY,EAAE,KAAK,IAAI,CAAC;GACrC,SAAU,KAAK,QAAQ,QAA4B;GACnD;GACA,GAAI,SAAS,KAAA,IAAY,EAAE,KAAK,IAAI,CAAC;GACrC,GAAI,KAAK,QAAQ,aAAa,KAAA,IAAY,EAAE,UAAU,OAAO,KAAK,QAAQ,QAAQ,EAAE,IAAI,CAAC;GACzF,MAAM;EACR;EAGA,OAAOA,WAAiB,MAAM;GAAE,GAAG;GAAM,aAAa,aAAa,IAAI;EAAE,CAAC;CAC5E;AACF;;;;;;;;;;;;AAaA,SAAgB,SAAS,YAAiD;CACxE,OAAO,IAAI,oBAAoB,YAAY,WAAW,QAAQ,CAAC;AACjE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react = require("react");
|
|
3
|
+
// src/email-context.ts
|
|
4
|
+
/**
|
|
5
|
+
* `sendwend/email-context` — the email being rendered, for its components: the resolved
|
|
6
|
+
* metadata (`resolveEmail`) of the template, so a shared layout renders the unsubscribe link the
|
|
7
|
+
* template resolves to instead of a URL of its own. The renderer (`sendwend/react-email`)
|
|
8
|
+
* and the studio's preview both provide it; the props stay the template's own.
|
|
9
|
+
*
|
|
10
|
+
* const { unsubscribeUrl } = useEmailContext();
|
|
11
|
+
* {unsubscribeUrl !== undefined && <Link href={unsubscribeUrl}>Unsubscribe</Link>}
|
|
12
|
+
*
|
|
13
|
+
* Browser-safe: React only — no react-dom/server, no Worker bindings.
|
|
14
|
+
*/
|
|
15
|
+
const EmailContext = (0, react.createContext)(void 0);
|
|
16
|
+
function EmailProvider({ email, children }) {
|
|
17
|
+
return (0, react.createElement)(EmailContext.Provider, { value: email }, children);
|
|
18
|
+
}
|
|
19
|
+
/** The email being rendered; throws outside a render the SDK or the studio provides. */
|
|
20
|
+
function useEmailContext() {
|
|
21
|
+
const email = (0, react.useContext)(EmailContext);
|
|
22
|
+
if (email === void 0) throw new Error("useEmailContext() is called outside an email render: render the template with sendwend/react-email's registryRenderer, or wrap it in <EmailProvider email={resolveEmail(template, config.email)}>");
|
|
23
|
+
return email;
|
|
24
|
+
}
|
|
25
|
+
exports.EmailProvider = EmailProvider;
|
|
26
|
+
exports.useEmailContext = useEmailContext;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=email-context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-context.cjs","names":["createContext","createElement","useContext"],"sources":["../src/email-context.ts"],"sourcesContent":["import { type ReactNode, createContext, createElement, useContext } from 'react';\nimport type { ResolvedEmail } from './email';\n\n/**\n * `sendwend/email-context` — the email being rendered, for its components: the resolved\n * metadata (`resolveEmail`) of the template, so a shared layout renders the unsubscribe link the\n * template resolves to instead of a URL of its own. The renderer (`sendwend/react-email`)\n * and the studio's preview both provide it; the props stay the template's own.\n *\n * const { unsubscribeUrl } = useEmailContext();\n * {unsubscribeUrl !== undefined && <Link href={unsubscribeUrl}>Unsubscribe</Link>}\n *\n * Browser-safe: React only — no react-dom/server, no Worker bindings.\n */\n\nconst EmailContext = createContext<ResolvedEmail | undefined>(undefined);\n\nexport function EmailProvider({\n email,\n children,\n}: {\n email: ResolvedEmail;\n children?: ReactNode;\n}): ReactNode {\n return createElement(EmailContext.Provider, { value: email }, children);\n}\n\n/** The email being rendered; throws outside a render the SDK or the studio provides. */\nexport function useEmailContext(): ResolvedEmail {\n const email = useContext(EmailContext);\n if (email === undefined) {\n throw new Error(\n 'useEmailContext() is called outside an email render: render the template with ' +\n \"sendwend/react-email's registryRenderer, or wrap it in <EmailProvider email={resolveEmail(template, config.email)}>\"\n );\n }\n return email;\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAM,gBAAA,GAAeA,MAAAA,cAAAA,CAAyC,KAAA,CAAS;AAEvE,SAAgB,cAAc,EAC5B,OACA,YAIY;CACZ,QAAA,GAAOC,MAAAA,cAAAA,CAAc,aAAa,UAAU,EAAE,OAAO,MAAM,GAAG,QAAQ;AACxE;;AAGA,SAAgB,kBAAiC;CAC/C,MAAM,SAAA,GAAQC,MAAAA,WAAAA,CAAW,YAAY;CACrC,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MACR,mMAEF;CAEF,OAAO;AACT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ResolvedEmail } from "./email.cjs";
|
|
3
|
+
export declare function EmailProvider({ email, children }: {
|
|
4
|
+
email: ResolvedEmail;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}): ReactNode;
|
|
7
|
+
/** The email being rendered; throws outside a render the SDK or the studio provides. */
|
|
8
|
+
export declare function useEmailContext(): ResolvedEmail;
|
|
9
|
+
//# sourceMappingURL=email-context.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-context.d.cts","names":[],"sources":["../src/email-context.ts"],"mappings":";;wBAiBgB,gBACd,OACA;EAEA,OAAO;EACP,WAAW;IACT;;wBAKY,mBAAmB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ResolvedEmail } from "./email.mjs";
|
|
3
|
+
export declare function EmailProvider({ email, children }: {
|
|
4
|
+
email: ResolvedEmail;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}): ReactNode;
|
|
7
|
+
/** The email being rendered; throws outside a render the SDK or the studio provides. */
|
|
8
|
+
export declare function useEmailContext(): ResolvedEmail;
|
|
9
|
+
//# sourceMappingURL=email-context.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-context.d.mts","names":[],"sources":["../src/email-context.ts"],"mappings":";;wBAiBgB,gBACd,OACA;EAEA,OAAO;EACP,WAAW;IACT;;wBAKY,mBAAmB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createContext, createElement, useContext } from "react";
|
|
2
|
+
// src/email-context.ts
|
|
3
|
+
/**
|
|
4
|
+
* `sendwend/email-context` — the email being rendered, for its components: the resolved
|
|
5
|
+
* metadata (`resolveEmail`) of the template, so a shared layout renders the unsubscribe link the
|
|
6
|
+
* template resolves to instead of a URL of its own. The renderer (`sendwend/react-email`)
|
|
7
|
+
* and the studio's preview both provide it; the props stay the template's own.
|
|
8
|
+
*
|
|
9
|
+
* const { unsubscribeUrl } = useEmailContext();
|
|
10
|
+
* {unsubscribeUrl !== undefined && <Link href={unsubscribeUrl}>Unsubscribe</Link>}
|
|
11
|
+
*
|
|
12
|
+
* Browser-safe: React only — no react-dom/server, no Worker bindings.
|
|
13
|
+
*/
|
|
14
|
+
const EmailContext = createContext(void 0);
|
|
15
|
+
function EmailProvider({ email, children }) {
|
|
16
|
+
return createElement(EmailContext.Provider, { value: email }, children);
|
|
17
|
+
}
|
|
18
|
+
/** The email being rendered; throws outside a render the SDK or the studio provides. */
|
|
19
|
+
function useEmailContext() {
|
|
20
|
+
const email = useContext(EmailContext);
|
|
21
|
+
if (email === void 0) throw new Error("useEmailContext() is called outside an email render: render the template with sendwend/react-email's registryRenderer, or wrap it in <EmailProvider email={resolveEmail(template, config.email)}>");
|
|
22
|
+
return email;
|
|
23
|
+
}
|
|
24
|
+
export { EmailProvider, useEmailContext };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=email-context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-context.mjs","names":[],"sources":["../src/email-context.ts"],"sourcesContent":["import { type ReactNode, createContext, createElement, useContext } from 'react';\nimport type { ResolvedEmail } from './email';\n\n/**\n * `sendwend/email-context` — the email being rendered, for its components: the resolved\n * metadata (`resolveEmail`) of the template, so a shared layout renders the unsubscribe link the\n * template resolves to instead of a URL of its own. The renderer (`sendwend/react-email`)\n * and the studio's preview both provide it; the props stay the template's own.\n *\n * const { unsubscribeUrl } = useEmailContext();\n * {unsubscribeUrl !== undefined && <Link href={unsubscribeUrl}>Unsubscribe</Link>}\n *\n * Browser-safe: React only — no react-dom/server, no Worker bindings.\n */\n\nconst EmailContext = createContext<ResolvedEmail | undefined>(undefined);\n\nexport function EmailProvider({\n email,\n children,\n}: {\n email: ResolvedEmail;\n children?: ReactNode;\n}): ReactNode {\n return createElement(EmailContext.Provider, { value: email }, children);\n}\n\n/** The email being rendered; throws outside a render the SDK or the studio provides. */\nexport function useEmailContext(): ResolvedEmail {\n const email = useContext(EmailContext);\n if (email === undefined) {\n throw new Error(\n 'useEmailContext() is called outside an email render: render the template with ' +\n \"sendwend/react-email's registryRenderer, or wrap it in <EmailProvider email={resolveEmail(template, config.email)}>\"\n );\n }\n return email;\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,eAAe,cAAyC,KAAA,CAAS;AAEvE,SAAgB,cAAc,EAC5B,OACA,YAIY;CACZ,OAAO,cAAc,aAAa,UAAU,EAAE,OAAO,MAAM,GAAG,QAAQ;AACxE;;AAGA,SAAgB,kBAAiC;CAC/C,MAAM,QAAQ,WAAW,YAAY;CACrC,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MACR,mMAEF;CAEF,OAAO;AACT"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_template_rules = require("./template-rules.cjs");
|
|
3
|
+
// src/email-sender.ts
|
|
4
|
+
/**
|
|
5
|
+
* The email channel over any transport: render → tracking applied to the HTML → the tracked
|
|
6
|
+
* links committed → the transport. The links resolve before the email exists anywhere a
|
|
7
|
+
* scanner could follow them.
|
|
8
|
+
*/
|
|
9
|
+
var EmailSender = class {
|
|
10
|
+
options;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
async send(message) {
|
|
15
|
+
if (message.channel !== "email") throw new Error(`EmailSender: unsupported channel '${message.channel}'`);
|
|
16
|
+
if (message.recipient === void 0) return {
|
|
17
|
+
delivered: false,
|
|
18
|
+
reason: "no_recipient"
|
|
19
|
+
};
|
|
20
|
+
if (!require_template_rules.isEmailAddress(message.recipient)) return {
|
|
21
|
+
delivered: false,
|
|
22
|
+
reason: "invalid_recipient"
|
|
23
|
+
};
|
|
24
|
+
const messageId = message.tracking?.messageId;
|
|
25
|
+
const { subject, html, from, replyTo, unsubscribeUrl } = await this.options.render(message.template, message.props, messageId === void 0 ? {} : { messageId });
|
|
26
|
+
const tracked = message.tracking === void 0 ? html : trackEmail(html, message.tracking, unsubscribeUrl);
|
|
27
|
+
await message.tracking?.commit?.();
|
|
28
|
+
const headers = unsubscribeHeaders(unsubscribeUrl, message.tracking?.unsubscribe);
|
|
29
|
+
await this.options.transport.send({
|
|
30
|
+
from,
|
|
31
|
+
to: message.recipient,
|
|
32
|
+
...replyTo === void 0 ? {} : { replyTo },
|
|
33
|
+
subject,
|
|
34
|
+
html: tracked,
|
|
35
|
+
...headers === void 0 ? {} : { headers },
|
|
36
|
+
idempotencyKey: message.idempotencyKey
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The list-unsubscribe headers of an email with an unsubscribe link (RFC 2369, RFC 8058), so a
|
|
42
|
+
* mail client's own unsubscribe button works — Gmail and Yahoo require one-click for bulk mail:
|
|
43
|
+
*
|
|
44
|
+
* - With a one-click endpoint (`MessageTracking.unsubscribe`, which reporting provides): the
|
|
45
|
+
* header names it, and `List-Unsubscribe-Post` says a POST there unsubscribes at once.
|
|
46
|
+
* - Without one: the header names the email's own unsubscribe link, with no one-click claim —
|
|
47
|
+
* whether that page takes a POST is the app's.
|
|
48
|
+
* - An email without an unsubscribe link (a transactional one) gets neither.
|
|
49
|
+
*
|
|
50
|
+
* Only an https URL is named: mail clients and Cloudflare Email refuse any other.
|
|
51
|
+
*/
|
|
52
|
+
function unsubscribeHeaders(unsubscribeUrl, oneClick) {
|
|
53
|
+
if (unsubscribeUrl === void 0) return void 0;
|
|
54
|
+
const https = (url) => url?.startsWith("https://") === true;
|
|
55
|
+
if (https(oneClick)) return {
|
|
56
|
+
"List-Unsubscribe": `<${oneClick}>`,
|
|
57
|
+
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click"
|
|
58
|
+
};
|
|
59
|
+
if (https(unsubscribeUrl)) return { "List-Unsubscribe": `<${unsubscribeUrl}>` };
|
|
60
|
+
}
|
|
61
|
+
const LINK = /(<a\b[^>]*?\shref\s*=\s*)(["'])(https?:\/\/[^"']+)\2/gi;
|
|
62
|
+
/**
|
|
63
|
+
* An email's tracking applied to its rendered HTML: every `http(s)` anchor routed through
|
|
64
|
+
* `link` (the original URL decoded from its attribute escaping, the tracking URL escaped back) —
|
|
65
|
+
* as the unsubscribe link when it is the one the email was rendered with, so what a click on it
|
|
66
|
+
* means is fixed when the email is sent — and the open pixel appended before `</body>`, or at the
|
|
67
|
+
* end when there is none.
|
|
68
|
+
*/
|
|
69
|
+
function trackEmail(html, tracking, unsubscribeUrl) {
|
|
70
|
+
const { link, pixel } = tracking;
|
|
71
|
+
let out = html;
|
|
72
|
+
if (link !== void 0) out = out.replace(LINK, (_, start, quote, attribute) => {
|
|
73
|
+
const url = unescapeAttribute(attribute);
|
|
74
|
+
const purpose = require_template_rules.isUnsubscribeLink(url, unsubscribeUrl) ? "unsubscribe" : "link";
|
|
75
|
+
return `${start}${quote}${escapeAttribute(link(url, purpose))}${quote}`;
|
|
76
|
+
});
|
|
77
|
+
if (pixel !== void 0) {
|
|
78
|
+
const image = `<img src="${escapeAttribute(pixel)}" width="1" height="1" alt="" style="display:block;border:0;width:1px;height:1px" />`;
|
|
79
|
+
out = /<\/body>/i.test(out) ? out.replace(/<\/body>/i, `${image}</body>`) : `${out}${image}`;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function unescapeAttribute(value) {
|
|
84
|
+
return value.replaceAll("&", "&").replaceAll(""", "\"").replaceAll("'", "'");
|
|
85
|
+
}
|
|
86
|
+
function escapeAttribute(value) {
|
|
87
|
+
return value.replaceAll("&", "&").replaceAll("\"", """);
|
|
88
|
+
}
|
|
89
|
+
exports.EmailSender = EmailSender;
|
|
90
|
+
exports.trackEmail = trackEmail;
|
|
91
|
+
exports.unsubscribeHeaders = unsubscribeHeaders;
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=email-sender.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.cjs","names":["isEmailAddress","isUnsubscribeLink"],"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,CAACA,uBAAAA,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,UAAUC,uBAAAA,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"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EmailRenderOptions, ResolvedEmail } from "./email.cjs";
|
|
2
|
+
import { MessageSender, MessageTracking, OutboundMessage, SendResult } from "./engine/ports.cjs";
|
|
3
|
+
import { ScalarIR } from "./ir.cjs";
|
|
4
|
+
import { EmailAddress } from "./template-rules.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* The email channel, split where the runtime stops mattering: `EmailSender` renders a copy,
|
|
7
|
+
* applies its tracking and commits the tracked links — the same on every host — and hands the
|
|
8
|
+
* finished email to an `EmailTransport`, the only part that knows a provider (SES, Cloudflare
|
|
9
|
+
* Email, ...). Nothing here imports a platform module, so a Worker and a Lambda share it.
|
|
10
|
+
*/
|
|
11
|
+
/** A rendered email: the template's resolved metadata (`resolveEmail`), its subject and its HTML. */
|
|
12
|
+
export interface RenderedEmail extends ResolvedEmail {
|
|
13
|
+
subject: string;
|
|
14
|
+
html: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Template renderer, injected by the app — this package's core stays free of
|
|
18
|
+
* any react-email dependency (`sendwend/react-email` ships one over a
|
|
19
|
+
* registry). The subject comes back final: it is sent exactly as written, from
|
|
20
|
+
* the template's own sender, and the unsubscribe link is the one the HTML was
|
|
21
|
+
* rendered with. `options` carries the copy's message id when reporting records one, for the
|
|
22
|
+
* preferences link (`resolveEmail`).
|
|
23
|
+
*/
|
|
24
|
+
export type EmailRenderer = (template: string, props: Record<string, ScalarIR | undefined>, options?: EmailRenderOptions) => Promise<RenderedEmail>;
|
|
25
|
+
/** A finished email, as a transport takes it: rendered, tracked, addressed. */
|
|
26
|
+
export interface EmailMessage {
|
|
27
|
+
from: EmailAddress;
|
|
28
|
+
to: string;
|
|
29
|
+
replyTo?: EmailAddress;
|
|
30
|
+
subject: string;
|
|
31
|
+
html: string;
|
|
32
|
+
/**
|
|
33
|
+
* Extra headers, already formatted: `List-Unsubscribe` and `List-Unsubscribe-Post` for an
|
|
34
|
+
* email that has an unsubscribe link (see `unsubscribeHeaders`).
|
|
35
|
+
*/
|
|
36
|
+
headers?: Readonly<Record<string, string>>;
|
|
37
|
+
/**
|
|
38
|
+
* `${instanceId}:${nodeId}`: the copy's identity, stable across retries and replays. A provider
|
|
39
|
+
* that de-duplicates on a key receives it; one that cannot (SES) still sends at least once —
|
|
40
|
+
* the window between the provider accepting the email and the step's checkpoint stays open.
|
|
41
|
+
*/
|
|
42
|
+
idempotencyKey: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* One email provider. Throwing hands the retry to the durable step; resolving means the provider
|
|
46
|
+
* accepted the email (not that it was delivered).
|
|
47
|
+
*/
|
|
48
|
+
export interface EmailTransport {
|
|
49
|
+
send(message: EmailMessage): Promise<{
|
|
50
|
+
providerMessageId?: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export interface EmailSenderOptions {
|
|
54
|
+
transport: EmailTransport;
|
|
55
|
+
render: EmailRenderer;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The email channel over any transport: render → tracking applied to the HTML → the tracked
|
|
59
|
+
* links committed → the transport. The links resolve before the email exists anywhere a
|
|
60
|
+
* scanner could follow them.
|
|
61
|
+
*/
|
|
62
|
+
export declare class EmailSender implements MessageSender {
|
|
63
|
+
private readonly options;
|
|
64
|
+
constructor(options: EmailSenderOptions);
|
|
65
|
+
send(message: OutboundMessage): Promise<void | SendResult>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The list-unsubscribe headers of an email with an unsubscribe link (RFC 2369, RFC 8058), so a
|
|
69
|
+
* mail client's own unsubscribe button works — Gmail and Yahoo require one-click for bulk mail:
|
|
70
|
+
*
|
|
71
|
+
* - With a one-click endpoint (`MessageTracking.unsubscribe`, which reporting provides): the
|
|
72
|
+
* header names it, and `List-Unsubscribe-Post` says a POST there unsubscribes at once.
|
|
73
|
+
* - Without one: the header names the email's own unsubscribe link, with no one-click claim —
|
|
74
|
+
* whether that page takes a POST is the app's.
|
|
75
|
+
* - An email without an unsubscribe link (a transactional one) gets neither.
|
|
76
|
+
*
|
|
77
|
+
* Only an https URL is named: mail clients and Cloudflare Email refuse any other.
|
|
78
|
+
*/
|
|
79
|
+
export declare function unsubscribeHeaders(unsubscribeUrl: string | undefined, oneClick: string | undefined): Record<string, string> | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* An email's tracking applied to its rendered HTML: every `http(s)` anchor routed through
|
|
82
|
+
* `link` (the original URL decoded from its attribute escaping, the tracking URL escaped back) —
|
|
83
|
+
* as the unsubscribe link when it is the one the email was rendered with, so what a click on it
|
|
84
|
+
* means is fixed when the email is sent — and the open pixel appended before `</body>`, or at the
|
|
85
|
+
* end when there is none.
|
|
86
|
+
*/
|
|
87
|
+
export declare function trackEmail(html: string, tracking: MessageTracking, unsubscribeUrl?: string): string;
|
|
88
|
+
//# sourceMappingURL=email-sender.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.d.cts","names":[],"sources":["../src/email-sender.ts"],"mappings":";;;;;;;;;;;iBAaiB,sBAAsB;EACrC;EACA;;;;;;;;;;YAWU,iBACV,kBACA,OAAO,eAAe,uBACtB,UAAU,uBACP,QAAQ;;iBAGI;EACf,MAAM;EACN;EACA,UAAU;EACV;EACA;;;;;EAKA,UAAU,SAAS;;;;;;EAMnB;;;;;;iBAOe;EACf,KAAK,SAAS,eAAe;IAAU;;;iBAGxB;EACf,WAAW;EACX,QAAQ;;;;;;;qBAQG,uBAAuB;mBACL;EAA7B,YAA6B,SAAS;EAEhC,KAAK,SAAS,kBAAkB,eAAe;;;;;;;;;;;;;;wBA6CvC,mBACd,oCACA,+BACC;;;;;;;;wBAsBa,WACd,cACA,UAAU,iBACV"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { EmailRenderOptions, ResolvedEmail } from "./email.mjs";
|
|
2
|
+
import { MessageSender, MessageTracking, OutboundMessage, SendResult } from "./engine/ports.mjs";
|
|
3
|
+
import { ScalarIR } from "./ir.mjs";
|
|
4
|
+
import { EmailAddress } from "./template-rules.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* The email channel, split where the runtime stops mattering: `EmailSender` renders a copy,
|
|
7
|
+
* applies its tracking and commits the tracked links — the same on every host — and hands the
|
|
8
|
+
* finished email to an `EmailTransport`, the only part that knows a provider (SES, Cloudflare
|
|
9
|
+
* Email, ...). Nothing here imports a platform module, so a Worker and a Lambda share it.
|
|
10
|
+
*/
|
|
11
|
+
/** A rendered email: the template's resolved metadata (`resolveEmail`), its subject and its HTML. */
|
|
12
|
+
export interface RenderedEmail extends ResolvedEmail {
|
|
13
|
+
subject: string;
|
|
14
|
+
html: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Template renderer, injected by the app — this package's core stays free of
|
|
18
|
+
* any react-email dependency (`sendwend/react-email` ships one over a
|
|
19
|
+
* registry). The subject comes back final: it is sent exactly as written, from
|
|
20
|
+
* the template's own sender, and the unsubscribe link is the one the HTML was
|
|
21
|
+
* rendered with. `options` carries the copy's message id when reporting records one, for the
|
|
22
|
+
* preferences link (`resolveEmail`).
|
|
23
|
+
*/
|
|
24
|
+
export type EmailRenderer = (template: string, props: Record<string, ScalarIR | undefined>, options?: EmailRenderOptions) => Promise<RenderedEmail>;
|
|
25
|
+
/** A finished email, as a transport takes it: rendered, tracked, addressed. */
|
|
26
|
+
export interface EmailMessage {
|
|
27
|
+
from: EmailAddress;
|
|
28
|
+
to: string;
|
|
29
|
+
replyTo?: EmailAddress;
|
|
30
|
+
subject: string;
|
|
31
|
+
html: string;
|
|
32
|
+
/**
|
|
33
|
+
* Extra headers, already formatted: `List-Unsubscribe` and `List-Unsubscribe-Post` for an
|
|
34
|
+
* email that has an unsubscribe link (see `unsubscribeHeaders`).
|
|
35
|
+
*/
|
|
36
|
+
headers?: Readonly<Record<string, string>>;
|
|
37
|
+
/**
|
|
38
|
+
* `${instanceId}:${nodeId}`: the copy's identity, stable across retries and replays. A provider
|
|
39
|
+
* that de-duplicates on a key receives it; one that cannot (SES) still sends at least once —
|
|
40
|
+
* the window between the provider accepting the email and the step's checkpoint stays open.
|
|
41
|
+
*/
|
|
42
|
+
idempotencyKey: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* One email provider. Throwing hands the retry to the durable step; resolving means the provider
|
|
46
|
+
* accepted the email (not that it was delivered).
|
|
47
|
+
*/
|
|
48
|
+
export interface EmailTransport {
|
|
49
|
+
send(message: EmailMessage): Promise<{
|
|
50
|
+
providerMessageId?: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export interface EmailSenderOptions {
|
|
54
|
+
transport: EmailTransport;
|
|
55
|
+
render: EmailRenderer;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The email channel over any transport: render → tracking applied to the HTML → the tracked
|
|
59
|
+
* links committed → the transport. The links resolve before the email exists anywhere a
|
|
60
|
+
* scanner could follow them.
|
|
61
|
+
*/
|
|
62
|
+
export declare class EmailSender implements MessageSender {
|
|
63
|
+
private readonly options;
|
|
64
|
+
constructor(options: EmailSenderOptions);
|
|
65
|
+
send(message: OutboundMessage): Promise<void | SendResult>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The list-unsubscribe headers of an email with an unsubscribe link (RFC 2369, RFC 8058), so a
|
|
69
|
+
* mail client's own unsubscribe button works — Gmail and Yahoo require one-click for bulk mail:
|
|
70
|
+
*
|
|
71
|
+
* - With a one-click endpoint (`MessageTracking.unsubscribe`, which reporting provides): the
|
|
72
|
+
* header names it, and `List-Unsubscribe-Post` says a POST there unsubscribes at once.
|
|
73
|
+
* - Without one: the header names the email's own unsubscribe link, with no one-click claim —
|
|
74
|
+
* whether that page takes a POST is the app's.
|
|
75
|
+
* - An email without an unsubscribe link (a transactional one) gets neither.
|
|
76
|
+
*
|
|
77
|
+
* Only an https URL is named: mail clients and Cloudflare Email refuse any other.
|
|
78
|
+
*/
|
|
79
|
+
export declare function unsubscribeHeaders(unsubscribeUrl: string | undefined, oneClick: string | undefined): Record<string, string> | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* An email's tracking applied to its rendered HTML: every `http(s)` anchor routed through
|
|
82
|
+
* `link` (the original URL decoded from its attribute escaping, the tracking URL escaped back) —
|
|
83
|
+
* as the unsubscribe link when it is the one the email was rendered with, so what a click on it
|
|
84
|
+
* means is fixed when the email is sent — and the open pixel appended before `</body>`, or at the
|
|
85
|
+
* end when there is none.
|
|
86
|
+
*/
|
|
87
|
+
export declare function trackEmail(html: string, tracking: MessageTracking, unsubscribeUrl?: string): string;
|
|
88
|
+
//# sourceMappingURL=email-sender.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.d.mts","names":[],"sources":["../src/email-sender.ts"],"mappings":";;;;;;;;;;;iBAaiB,sBAAsB;EACrC;EACA;;;;;;;;;;YAWU,iBACV,kBACA,OAAO,eAAe,uBACtB,UAAU,uBACP,QAAQ;;iBAGI;EACf,MAAM;EACN;EACA,UAAU;EACV;EACA;;;;;EAKA,UAAU,SAAS;;;;;;EAMnB;;;;;;iBAOe;EACf,KAAK,SAAS,eAAe;IAAU;;;iBAGxB;EACf,WAAW;EACX,QAAQ;;;;;;;qBAQG,uBAAuB;mBACL;EAA7B,YAA6B,SAAS;EAEhC,KAAK,SAAS,kBAAkB,eAAe;;;;;;;;;;;;;;wBA6CvC,mBACd,oCACA,+BACC;;;;;;;;wBAsBa,WACd,cACA,UAAU,iBACV"}
|