@builtbyfriends/bwf 0.0.0-stage → 1.9.1
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/AGENTS_TEMPLATE.md +4 -0
- package/LICENSE +22 -0
- package/README.md +48 -2
- package/dist/account-cmd-Cj0I2_bJ.mjs +45 -0
- package/dist/agents-BLiMq9E1.mjs +113 -0
- package/dist/application-analysis-C9Ck2Yeg.mjs +1498 -0
- package/dist/application-routing-DbR-W5lG.mjs +25 -0
- package/dist/atomic-write-DA6eD1Kp.mjs +17 -0
- package/dist/auth-BKsUmWbT.d.mts +77 -0
- package/dist/auth-DkvoW5hB.mjs +33 -0
- package/dist/auth-aKyIWkdS.mjs +1 -0
- package/dist/auth-client-6-Ft9i9T.d.mts +5 -0
- package/dist/auth-client-DwCdwKbw.mjs +5 -0
- package/dist/auth-client-react-CJdeErvM.mjs +5 -0
- package/dist/auth-client-react-DvQLe5Zb.d.mts +5 -0
- package/dist/auth-link-D-DddkCQ.mjs +26 -0
- package/dist/auth-migrations-DDeifS3v.mjs +206 -0
- package/dist/auth-router-tWzIwf8f.mjs +66 -0
- package/dist/auth-xnkmpZUl.mjs +311 -0
- package/dist/base64-ikl9yBy3.mjs +15 -0
- package/dist/better-auth-shared-Br6TNaYJ.mjs +473 -0
- package/dist/better-auth-shared-CsBNvPOU.d.mts +56 -0
- package/dist/build-cmd-BnZezraT.mjs +153 -0
- package/dist/build-output-dir-Clj_unKN.mjs +402 -0
- package/dist/cancel-deploy-DKAj5U1Z.mjs +57 -0
- package/dist/cf-access-Bhz9wX6p.mjs +131 -0
- package/dist/cf-access-CUP5L08W.mjs +67 -0
- package/dist/cf-build-output-DA6uJomQ.mjs +1 -0
- package/dist/cf-build-output-DNQTwMNU.mjs +438 -0
- package/dist/cf-command-values-2kOtxMo1.mjs +26 -0
- package/dist/cf-config-migrate-COOCi4Ge.mjs +330 -0
- package/dist/cf-worker-settings-CIh4t_yG.mjs +41 -0
- package/dist/cli/cli.d.mts +1 -0
- package/dist/cli/cli.mjs +88 -0
- package/dist/cli/cloudflare-operation-process.d.mts +1 -0
- package/dist/cli/cloudflare-operation-process.mjs +1284 -0
- package/dist/cli/env-schema-probe.d.mts +43 -0
- package/dist/cli/env-schema-probe.mjs +165 -0
- package/dist/cli-main-HeXRQml6.mjs +1846 -0
- package/dist/client-D3D5RM5h.mjs +940 -0
- package/dist/client-VF2Nzc7Z.mjs +1 -0
- package/dist/cloudflare-auth-jb-1e43r.mjs +152 -0
- package/dist/cloudflare-cmd-B62t8Fm-.mjs +59 -0
- package/dist/cloudflare-config-i8yanry0.mjs +186 -0
- package/dist/cloudflare-connect-x7IsYghw.mjs +55 -0
- package/dist/cloudflare-operations-BeK7bhnP.mjs +627 -0
- package/dist/cloudflare-operations-C3Uu0Emj.mjs +1 -0
- package/dist/cloudflare-process-Cc6oiJqk.mjs +309 -0
- package/dist/cloudflare-user-output-CqONaAbP.mjs +19 -0
- package/dist/collect-8i0wU63d.mjs +1 -0
- package/dist/collect-C6Blu9yw.mjs +48 -0
- package/dist/config-CN_RFRkS.mjs +86 -0
- package/dist/config-D5G-Tx6o.mjs +1 -0
- package/dist/config-DOaFIK3w.mjs +88 -0
- package/dist/config-entry.d.mts +202 -0
- package/dist/config-entry.mjs +6 -0
- package/dist/config-tNx0HlFv.mjs +516 -0
- package/dist/connect-hLPNppu3.mjs +84 -0
- package/dist/create-project-B35ux-LA.mjs +126 -0
- package/dist/create-project-tJ1KwNss.mjs +1 -0
- package/dist/database-provider-DkZo4VwN.mjs +5 -0
- package/dist/database-provider.d.mts +25 -0
- package/dist/database-provider.mjs +1 -0
- package/dist/db-BH_md90k.mjs +1735 -0
- package/dist/delete-BSKI7V23.mjs +65 -0
- package/dist/deploy-C8KHBNsh.mjs +6512 -0
- package/dist/deploy-DCZBr7Ey.mjs +2 -0
- package/dist/deploy.d.mts +31 -0
- package/dist/deploy.mjs +118 -0
- package/dist/dev-inbox-I0nqTCdf.mjs +216 -0
- package/dist/discover-DJPmQcL5.mjs +36 -0
- package/dist/discover-EVuydEoM.mjs +1 -0
- package/dist/dist-B6eN80gc.mjs +1612 -0
- package/dist/dist-Cp4b1_T9.mjs +1 -0
- package/dist/dist-DMYe8CZJ.mjs +48 -0
- package/dist/dist-STQXl8ck.mjs +1878 -0
- package/dist/domain-C4ZhEiFG.mjs +149 -0
- package/dist/dotenv-4NdUCXbB.mjs +156 -0
- package/dist/drizzle-DqVFXtlc.mjs +306 -0
- package/dist/drizzle-Ds5P0n-S.mjs +1 -0
- package/dist/edge.d.mts +2 -0
- package/dist/edge.mjs +1 -0
- package/dist/email-B3TWga7x.mjs +742 -0
- package/dist/email-C_ATvNIG.mjs +2865 -0
- package/dist/email-cloudflare-DuAc9zny.mjs +854 -0
- package/dist/email-protocol-CZ0bAkI8.mjs +81 -0
- package/dist/env-CTAo8ifZ.mjs +73 -0
- package/dist/env-DUyTzroe.mjs +88 -0
- package/dist/env-Dl4Wggec.mjs +71 -0
- package/dist/env-helpers-BX0APszT.mjs +135 -0
- package/dist/env-helpers-U56xuFgL.d.mts +20 -0
- package/dist/env-mask-BsHxq3R8.mjs +46 -0
- package/dist/env-public-Cw_xPi1D.d.mts +119 -0
- package/dist/env-raw-Bo6TtrHU.mjs +41 -0
- package/dist/env-types-Bg-dTh8u.mjs +56 -0
- package/dist/env-validation-BufZConV.mjs +488 -0
- package/dist/env-validation-DPqDo4DU.mjs +1 -0
- package/dist/fetch-CBgyyhzm.d.mts +87 -0
- package/dist/fetch-error-DmlRM6e4.mjs +264 -0
- package/dist/fetch-stream-2GUN3YN1.mjs +102 -0
- package/dist/fetch-stream-bUXynOyZ.d.mts +32 -0
- package/dist/fetch-tpPiSK10.mjs +25 -0
- package/dist/gen-dc13IRXh.mjs +509 -0
- package/dist/gen-kQqhFyOP.mjs +1 -0
- package/dist/generate-BgtlYpKg.mjs +1 -0
- package/dist/generate-Da9mWKzU.mjs +80 -0
- package/dist/generated-wrangler-config-CoDaaFsA.mjs +17 -0
- package/dist/git-metadata-Cukp5kV5.mjs +82 -0
- package/dist/github-cmd-DT5Onu6E.mjs +690 -0
- package/dist/handler-CJ7DiiRF.mjs +161 -0
- package/dist/handler-CVsIfRv7.d.mts +279 -0
- package/dist/help-Bpv6Qeqn.mjs +1946 -0
- package/dist/help-CfZ4Bsw5.mjs +1 -0
- package/dist/inbound-CqubE-9T.d.mts +311 -0
- package/dist/inbound-lHugZPuK.mjs +509 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.mjs +4163 -0
- package/dist/info-CLQoCenb.mjs +109 -0
- package/dist/init-DRUR0j8C.mjs +2486 -0
- package/dist/limits-CMmYT2l8.d.mts +16 -0
- package/dist/limits-D27Lp6FP.mjs +46 -0
- package/dist/link-DinwJnon.mjs +52 -0
- package/dist/list-B84t4BhW.mjs +130 -0
- package/dist/live-Dui0-aj_.d.mts +105 -0
- package/dist/live-saC8barp.mjs +410 -0
- package/dist/load-user-env-g0ahkZcj.mjs +34 -0
- package/dist/local-d1-C3EeOV7-.mjs +103 -0
- package/dist/log-JDnPc0cF.mjs +23 -0
- package/dist/login-Bl5lH8nH.mjs +87 -0
- package/dist/login-DoI7AsbY.mjs +1 -0
- package/dist/logs-CaT2N2f7.mjs +129 -0
- package/dist/migrate-CbGscX-V.mjs +125 -0
- package/dist/migrate-Ce3JKLVs.mjs +1 -0
- package/dist/migration-handler-22qiuWPq.mjs +469 -0
- package/dist/migration-handler-Bb2BJh6g.d.mts +38 -0
- package/dist/mime-BMUN_QKG.mjs +1004 -0
- package/dist/mysql-migration-sql-CNuBSqdx.mjs +239 -0
- package/dist/neon-CJzQSycr.mjs +52 -0
- package/dist/node-tfv-3v0V.mjs +64 -0
- package/dist/operator-ai-logging-Ay7M4KWw.mjs +121 -0
- package/dist/operator-args-BFg32YyY.mjs +722 -0
- package/dist/operator-auth-DdYZYEkO.mjs +47 -0
- package/dist/operator-client-DBujdELO.mjs +82 -0
- package/dist/operator-cmd-C73WWJBl.mjs +443 -0
- package/dist/operator-cmd-CdZytuAF.mjs +1 -0
- package/dist/output-Bb34lF0w.mjs +173 -0
- package/dist/output-CVolXKC1.mjs +1 -0
- package/dist/package-DO4d3Qz5.mjs +1444 -0
- package/dist/package-json-DvS6IFRv.mjs +43 -0
- package/dist/pg-DoyPxa_X.mjs +15 -0
- package/dist/picocolors-D1NxSLw-.mjs +71 -0
- package/dist/plan-BHNt1QhK.mjs +1 -0
- package/dist/plan-DX4_-OM5.mjs +58 -0
- package/dist/platform-args-NI_vfWvD.mjs +538 -0
- package/dist/platform-args-ZC1-A1N9.mjs +1 -0
- package/dist/platform-auth-config-d-lY5-aY.mjs +371 -0
- package/dist/platform-auth-protection-Dhw7lUCk.mjs +231 -0
- package/dist/platform-auth-recovery-DaCc0tlx.mjs +309 -0
- package/dist/platform-cmd-5Ry-C9im.mjs +193 -0
- package/dist/platform-cmd-5oZq91lI.mjs +1 -0
- package/dist/platform-discovery-Bxg9aZXU.mjs +40 -0
- package/dist/platform-domain-DLVdGvGG.mjs +256 -0
- package/dist/platform-lifecycle-CUgjipXO.mjs +1 -0
- package/dist/platform-lifecycle-fRt5VMls.mjs +8928 -0
- package/dist/platform-management-5hEsRfR2.mjs +1 -0
- package/dist/platform-management-Djh1hzLP.mjs +1607 -0
- package/dist/platform-plans-config-CkbUKFpm.mjs +447 -0
- package/dist/platform-recovery-Cghx7FCR.mjs +96 -0
- package/dist/platform-registry-x1m9HBxf.mjs +450 -0
- package/dist/platform-runtime-logs-kkoiYFpF.mjs +72 -0
- package/dist/platform-setup-SfwCwnZg.mjs +306 -0
- package/dist/prepare-B9mB47T5.mjs +84 -0
- package/dist/prepare-DNIq07so.mjs +13 -0
- package/dist/prepare-LHkyJqxi.mjs +1 -0
- package/dist/project-CC7eN00D.mjs +141 -0
- package/dist/project-DcSd4BeI.mjs +1 -0
- package/dist/project-cmd-DTF19-fC.mjs +109 -0
- package/dist/project-paths-iXHKRTTQ.mjs +159 -0
- package/dist/project-slug-BUy0lmyR.mjs +1 -0
- package/dist/project-slug-CO6ci9XG.mjs +7 -0
- package/dist/project-team-CvdLhDF2.mjs +129 -0
- package/dist/project-token-CwZdUEGu.mjs +70 -0
- package/dist/project-tsconfig-P9X952KG.mjs +98 -0
- package/dist/project-zero-trust-CKDoPdN1.mjs +64 -0
- package/dist/providers-Cd3c7wi0.mjs +64 -0
- package/dist/providers-Df69hb_X.d.mts +5 -0
- package/dist/provision-DGlFJ3T9.mjs +1 -0
- package/dist/provision-mYVLuQiy.mjs +1814 -0
- package/dist/queues-Bc3FsBQT.d.mts +5 -0
- package/dist/r2-conditions-DSLmkiR5.mjs +60 -0
- package/dist/requests-DNhfyF3l.mjs +52 -0
- package/dist/resolve-project-BCsAMDRA.mjs +47 -0
- package/dist/resolve-project-DhU9_lIo.mjs +1 -0
- package/dist/resource-name-DlJ9QXzg.mjs +10 -0
- package/dist/response-HmNjB30w.mjs +29 -0
- package/dist/rollback-BvCHol52.mjs +150 -0
- package/dist/rolldown-runtime-uD8oG6U2.mjs +24 -0
- package/dist/route-types-CRWhr93D.mjs +592 -0
- package/dist/route-url-BIDZT78M.mjs +58 -0
- package/dist/route-url-Bla3Upsy.d.mts +42 -0
- package/dist/routes-stub.d.mts +24 -0
- package/dist/routes-stub.mjs +1 -0
- package/dist/routing-assets-CSheDWWM.mjs +54 -0
- package/dist/rpc-DcByS_q0.d.mts +39 -0
- package/dist/rpc-DtxIN9Tv.mjs +19 -0
- package/dist/runner-CPerdjIl.mjs +163 -0
- package/dist/runner-CUNtS5x7.mjs +1 -0
- package/dist/runner-mysql-7aA5hGoM.mjs +145 -0
- package/dist/runner-mysql-DrMKw203.mjs +1 -0
- package/dist/runner-pg-2pjltt0t.mjs +1 -0
- package/dist/runner-pg-mYc75KfH.mjs +61 -0
- package/dist/runtime/ai.d.mts +50 -0
- package/dist/runtime/ai.mjs +455 -0
- package/dist/runtime/auth-client-react.d.mts +2 -0
- package/dist/runtime/auth-client-react.mjs +1 -0
- package/dist/runtime/auth-client.d.mts +2 -0
- package/dist/runtime/auth-client.mjs +1 -0
- package/dist/runtime/auth.d.mts +2 -0
- package/dist/runtime/auth.mjs +1 -0
- package/dist/runtime/better-auth-mysql.d.mts +5 -0
- package/dist/runtime/better-auth-mysql.mjs +21 -0
- package/dist/runtime/better-auth-pg.d.mts +5 -0
- package/dist/runtime/better-auth-pg.mjs +21 -0
- package/dist/runtime/better-auth.d.mts +6 -0
- package/dist/runtime/better-auth.mjs +22 -0
- package/dist/runtime/client-react.d.mts +5 -0
- package/dist/runtime/client-react.mjs +5 -0
- package/dist/runtime/client.d.mts +5 -0
- package/dist/runtime/client.mjs +5 -0
- package/dist/runtime/db-mysql.d.mts +2 -0
- package/dist/runtime/db-mysql.mjs +1 -0
- package/dist/runtime/db-pg.d.mts +2 -0
- package/dist/runtime/db-pg.mjs +1 -0
- package/dist/runtime/db.d.mts +17 -0
- package/dist/runtime/db.mjs +36 -0
- package/dist/runtime/drizzle-arktype.d.mts +1 -0
- package/dist/runtime/drizzle-arktype.mjs +2 -0
- package/dist/runtime/drizzle-valibot.d.mts +1 -0
- package/dist/runtime/drizzle-valibot.mjs +2 -0
- package/dist/runtime/drizzle-zod.d.mts +1 -0
- package/dist/runtime/drizzle-zod.mjs +2 -0
- package/dist/runtime/durable.d.mts +64 -0
- package/dist/runtime/durable.mjs +165 -0
- package/dist/runtime/email/testing.d.mts +108 -0
- package/dist/runtime/email/testing.mjs +268 -0
- package/dist/runtime/email-protocol.d.mts +25 -0
- package/dist/runtime/email-protocol.mjs +1 -0
- package/dist/runtime/email.d.mts +26 -0
- package/dist/runtime/email.mjs +524 -0
- package/dist/runtime/env-public-client.d.mts +19 -0
- package/dist/runtime/env-public-client.mjs +55 -0
- package/dist/runtime/env-public.d.mts +4 -0
- package/dist/runtime/env-public.mjs +277 -0
- package/dist/runtime/env.d.mts +12 -0
- package/dist/runtime/env.mjs +1 -0
- package/dist/runtime/fetch-server.d.mts +6 -0
- package/dist/runtime/fetch-server.mjs +29 -0
- package/dist/runtime/fetch-stream.d.mts +3 -0
- package/dist/runtime/fetch-stream.mjs +3 -0
- package/dist/runtime/fetch.d.mts +2 -0
- package/dist/runtime/fetch.mjs +3 -0
- package/dist/runtime/handler.d.mts +3 -0
- package/dist/runtime/handler.mjs +1 -0
- package/dist/runtime/kv.d.mts +45 -0
- package/dist/runtime/kv.mjs +103 -0
- package/dist/runtime/limits.d.mts +2 -0
- package/dist/runtime/limits.mjs +1 -0
- package/dist/runtime/live-client.d.mts +40 -0
- package/dist/runtime/live-client.mjs +282 -0
- package/dist/runtime/live-server.d.mts +11 -0
- package/dist/runtime/live-server.mjs +419 -0
- package/dist/runtime/live.d.mts +3 -0
- package/dist/runtime/live.mjs +1 -0
- package/dist/runtime/log.d.mts +24 -0
- package/dist/runtime/log.mjs +57 -0
- package/dist/runtime/migration-handler-mysql.d.mts +2 -0
- package/dist/runtime/migration-handler-mysql.mjs +111 -0
- package/dist/runtime/migration-handler-pg.d.mts +2 -0
- package/dist/runtime/migration-handler-pg.mjs +94 -0
- package/dist/runtime/migration-handler.d.mts +2 -0
- package/dist/runtime/migration-handler.mjs +1 -0
- package/dist/runtime/procedure.d.mts +27 -0
- package/dist/runtime/procedure.mjs +36 -0
- package/dist/runtime/procedures.d.mts +24 -0
- package/dist/runtime/procedures.mjs +56 -0
- package/dist/runtime/queues.d.mts +2 -0
- package/dist/runtime/queues.mjs +8 -0
- package/dist/runtime/remote/binding-handler.d.mts +11 -0
- package/dist/runtime/remote/binding-handler.mjs +227 -0
- package/dist/runtime/remote/index.d.mts +12 -0
- package/dist/runtime/remote/index.mjs +467 -0
- package/dist/runtime/response.d.mts +11 -0
- package/dist/runtime/response.mjs +1 -0
- package/dist/runtime/route-url.d.mts +2 -0
- package/dist/runtime/route-url.mjs +1 -0
- package/dist/runtime/routing.d.mts +53 -0
- package/dist/runtime/routing.mjs +425 -0
- package/dist/runtime/rpc-react.d.mts +16 -0
- package/dist/runtime/rpc-react.mjs +50 -0
- package/dist/runtime/rpc.d.mts +2 -0
- package/dist/runtime/rpc.mjs +1 -0
- package/dist/runtime/sandbox-container.d.mts +3 -0
- package/dist/runtime/sandbox-container.mjs +1 -0
- package/dist/runtime/sandbox.d.mts +5 -0
- package/dist/runtime/sandbox.mjs +196 -0
- package/dist/runtime/schema-d1.d.mts +1 -0
- package/dist/runtime/schema-d1.mjs +2 -0
- package/dist/runtime/schema-mysql.d.mts +1 -0
- package/dist/runtime/schema-mysql.mjs +2 -0
- package/dist/runtime/schema-pg.d.mts +1 -0
- package/dist/runtime/schema-pg.mjs +2 -0
- package/dist/runtime/seed.d.mts +34 -0
- package/dist/runtime/seed.mjs +5 -0
- package/dist/runtime/sse-client.d.mts +31 -0
- package/dist/runtime/sse-client.mjs +42 -0
- package/dist/runtime/sse.d.mts +32 -0
- package/dist/runtime/sse.mjs +1 -0
- package/dist/runtime/storage.d.mts +4 -0
- package/dist/runtime/storage.mjs +13 -0
- package/dist/runtime/validator.d.mts +2 -0
- package/dist/runtime/validator.mjs +1 -0
- package/dist/runtime/ws-server.d.mts +26 -0
- package/dist/runtime/ws-server.mjs +297 -0
- package/dist/runtime/ws.d.mts +2 -0
- package/dist/runtime/ws.mjs +108 -0
- package/dist/sandbox-CWDjoEG2.d.mts +50 -0
- package/dist/sandbox-container-BqamdFCx.d.mts +73 -0
- package/dist/sandbox-container-d1AHLpgn.mjs +291 -0
- package/dist/secret-DCF9RXTc.mjs +146 -0
- package/dist/skills-Dr3AjuBF.mjs +63 -0
- package/dist/sqlite-validation-CLJXXN93.mjs +24 -0
- package/dist/sse-CxR30yMF.mjs +174 -0
- package/dist/standard-schema-CuDawHOC.d.mts +40 -0
- package/dist/static-asset-marker-mWMX2dLa.mjs +38 -0
- package/dist/subcommand-prompt-B9yUo--u.mjs +370 -0
- package/dist/terminal-log-text-DNsWJREL.mjs +31 -0
- package/dist/types-D7-4tBu7.d.mts +1 -0
- package/dist/untrusted-env-lL7RkYiC.mjs +50 -0
- package/dist/validate-B-zsjhiz.mjs +162 -0
- package/dist/validate-DbqGdPPY.mjs +1 -0
- package/dist/validator-8-NZs2Xr.mjs +168 -0
- package/dist/version-metadata-DsSoNsKJ.mjs +23 -0
- package/dist/wrangler-DU784Dkf.mjs +1452 -0
- package/dist/wrangler-Rr9_76DQ.mjs +1 -0
- package/dist/ws-Q_osq9VK.d.mts +137 -0
- package/dist/yarn-pnp-DgWbE7z5.mjs +91 -0
- package/docs/guide/ai.md +273 -0
- package/docs/guide/app-types.md +101 -0
- package/docs/guide/auth.md +255 -0
- package/docs/guide/database/d1.md +86 -0
- package/docs/guide/database/mysql.md +72 -0
- package/docs/guide/database/postgresql.md +94 -0
- package/docs/guide/database.md +454 -0
- package/docs/guide/deployment.md +124 -0
- package/docs/guide/durable-state.md +192 -0
- package/docs/guide/edge/headers.md +47 -0
- package/docs/guide/edge/redirects.md +85 -0
- package/docs/guide/edge/rewrites.md +119 -0
- package/docs/guide/edge/static-assets.md +94 -0
- package/docs/guide/email/domains.md +119 -0
- package/docs/guide/email/receiving.md +142 -0
- package/docs/guide/email/sending.md +262 -0
- package/docs/guide/email.md +23 -0
- package/docs/guide/env-vars.md +115 -0
- package/docs/guide/index.md +37 -0
- package/docs/guide/jobs.md +80 -0
- package/docs/guide/kv.md +100 -0
- package/docs/guide/live.md +181 -0
- package/docs/guide/platform/administration/access.md +165 -0
- package/docs/guide/platform/administration/connected-apps.md +84 -0
- package/docs/guide/platform/administration/email.md +169 -0
- package/docs/guide/platform/administration/operations.md +100 -0
- package/docs/guide/platform/administration/plans.md +156 -0
- package/docs/guide/platform/administration/projects.md +74 -0
- package/docs/guide/platform/administration/zero-trust.md +205 -0
- package/docs/guide/platform/development/local.md +122 -0
- package/docs/guide/platform/development/runtime.md +115 -0
- package/docs/guide/platform/development/schema-ci.md +44 -0
- package/docs/guide/platform/installation/ci.md +62 -0
- package/docs/guide/platform/installation/credentials.md +140 -0
- package/docs/guide/platform/installation/domains.md +120 -0
- package/docs/guide/platform/installation/first-deployment.md +95 -0
- package/docs/guide/platform/installation/maintenance.md +250 -0
- package/docs/guide/platform/installation/prerequisites.md +176 -0
- package/docs/guide/platform/installation/setup.md +300 -0
- package/docs/guide/platform/installation/uninstall.md +110 -0
- package/docs/guide/platform-administration.md +19 -0
- package/docs/guide/platform-development.md +16 -0
- package/docs/guide/procedures.md +48 -0
- package/docs/guide/project-collaboration.md +99 -0
- package/docs/guide/queues.md +149 -0
- package/docs/guide/quickstart.md +129 -0
- package/docs/guide/remote-dev.md +67 -0
- package/docs/guide/sandboxes.md +134 -0
- package/docs/guide/self-hosted-platform.md +45 -0
- package/docs/guide/server-routing.md +283 -0
- package/docs/guide/sse.md +174 -0
- package/docs/guide/storage.md +82 -0
- package/docs/guide/testing.md +64 -0
- package/docs/guide/type-safety.md +270 -0
- package/docs/guide/typed-fetch.md +98 -0
- package/docs/guide/websockets.md +230 -0
- package/docs/index.md +102 -0
- package/docs/integrations/agents.md +38 -0
- package/docs/integrations/cloudflare.md +241 -0
- package/docs/integrations/hono.md +127 -0
- package/docs/reference/api/auth.md +195 -0
- package/docs/reference/api/client.md +90 -0
- package/docs/reference/api/database.md +118 -0
- package/docs/reference/api/deploy.md +63 -0
- package/docs/reference/api/durable.md +47 -0
- package/docs/reference/api/env.md +51 -0
- package/docs/reference/api/handlers.md +189 -0
- package/docs/reference/api/plugin.md +40 -0
- package/docs/reference/api/resources.md +116 -0
- package/docs/reference/api/rewrites.md +111 -0
- package/docs/reference/api/types.md +126 -0
- package/docs/reference/api.md +71 -0
- package/docs/reference/cli/auth.md +87 -0
- package/docs/reference/cli/database.md +159 -0
- package/docs/reference/cli/deploy.md +117 -0
- package/docs/reference/cli/domains.md +42 -0
- package/docs/reference/cli/email.md +145 -0
- package/docs/reference/cli/generate.md +113 -0
- package/docs/reference/cli/github.md +181 -0
- package/docs/reference/cli/platform-config.md +93 -0
- package/docs/reference/cli/platform-email.md +81 -0
- package/docs/reference/cli/platform-installation.md +166 -0
- package/docs/reference/cli/platform-operations.md +90 -0
- package/docs/reference/cli/platform-users.md +159 -0
- package/docs/reference/cli/platform-zero-trust.md +60 -0
- package/docs/reference/cli/platform.md +78 -0
- package/docs/reference/cli/project.md +208 -0
- package/docs/reference/cli/secrets.md +79 -0
- package/docs/reference/cli/setup.md +88 -0
- package/docs/reference/cli.md +115 -0
- package/docs/reference/config.md +478 -0
- package/docs/reference/resource-inference.md +72 -0
- package/docs/reference/structure.md +138 -0
- package/package.json +389 -3
- package/sandbox.Dockerfile +4 -0
- package/schema.json +353 -0
- package/skills/bwf/SKILL.md +100 -0
- package/skills/migrate-vite-cloudflare-to-bwf/SKILL.md +53 -0
- package/templates/assets/bwf.svg +5 -0
- package/templates/assets/icons.svg +49 -0
- package/templates/assets/react.svg +1 -0
- package/templates/assets/stack.svg +35 -0
|
@@ -0,0 +1,1004 @@
|
|
|
1
|
+
import { n as bytesToBase64 } from "./base64-ikl9yBy3.mjs";
|
|
2
|
+
import { validate } from "email-validator";
|
|
3
|
+
// src/runtime/email/threading.ts
|
|
4
|
+
/**
|
|
5
|
+
* Header-value checks shared by the MIME builder and the reply path, and the
|
|
6
|
+
* best-effort cleaning of `In-Reply-To` / `References` ids. Thread ids usually
|
|
7
|
+
* come from remote mail, so an id that cannot be sent is left out instead of
|
|
8
|
+
* failing the message. No imports, so both `mime.ts` and `inbound.ts` can use it.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Index of the first C0 control other than HTAB, or DEL; -1 when there is
|
|
12
|
+
* none. HTAB is folding whitespace (RFC 5322 §3.2.2).
|
|
13
|
+
*/
|
|
14
|
+
function indexOfControl(value) {
|
|
15
|
+
for (let i = 0; i < value.length; i++) {
|
|
16
|
+
const c = value.charCodeAt(i);
|
|
17
|
+
if (c < 32 && c !== 9 || c === 127) return i;
|
|
18
|
+
}
|
|
19
|
+
return -1;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `value` without leading or trailing SP and HTAB, the only whitespace a
|
|
23
|
+
* `Headers` value is trimmed of. `String#trim` would also strip U+00A0.
|
|
24
|
+
*/
|
|
25
|
+
function trimFws(value) {
|
|
26
|
+
let start = 0;
|
|
27
|
+
let end = value.length;
|
|
28
|
+
while (start < end && (value.charCodeAt(start) === 32 || value.charCodeAt(start) === 9)) start++;
|
|
29
|
+
while (end > start && (value.charCodeAt(end - 1) === 32 || value.charCodeAt(end - 1) === 9)) end--;
|
|
30
|
+
return value.slice(start, end);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether `Name: value` fits RFC 5322's 998-octet line once folded. It
|
|
34
|
+
* follows `foldHeader`: a fold point is SP or HTAB outside a quoted string,
|
|
35
|
+
* so the widest run between fold points decides.
|
|
36
|
+
*/
|
|
37
|
+
function fitsHeaderLine(name, value) {
|
|
38
|
+
if (!value) return false;
|
|
39
|
+
const budget = 998 - (name.length + 2);
|
|
40
|
+
let run = 0;
|
|
41
|
+
let inQuotes = false;
|
|
42
|
+
let escape = false;
|
|
43
|
+
for (let i = 0; i < value.length; i++) {
|
|
44
|
+
const c = value.charCodeAt(i);
|
|
45
|
+
if (escape) escape = false;
|
|
46
|
+
else if (c === 92 && inQuotes) escape = true;
|
|
47
|
+
else if (c === 34) inQuotes = !inQuotes;
|
|
48
|
+
else if ((c === 32 || c === 9) && !inQuotes) {
|
|
49
|
+
run = 0;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (c < 128) run += 1;
|
|
53
|
+
else if (c < 2048) run += 2;
|
|
54
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < value.length && (value.charCodeAt(i + 1) & 64512) === 56320) {
|
|
55
|
+
run += 4;
|
|
56
|
+
i++;
|
|
57
|
+
} else run += 3;
|
|
58
|
+
if (run > budget) return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Longest `References` value, in UTF-16 code units. 8 KiB keeps any real
|
|
64
|
+
* thread whole; past it the newest ids are kept, since mail clients thread on
|
|
65
|
+
* any id they recognise and the parent is `In-Reply-To`.
|
|
66
|
+
*/
|
|
67
|
+
const MAX_REFERENCES_CHARS = 8192;
|
|
68
|
+
/**
|
|
69
|
+
* The newest whole ids of `chain` that fit `budget` code units, without the
|
|
70
|
+
* ids that hold a control character.
|
|
71
|
+
*/
|
|
72
|
+
function newestIds(chain, budget) {
|
|
73
|
+
if (chain.length > budget) {
|
|
74
|
+
let cut = chain.length - budget;
|
|
75
|
+
while (cut < chain.length) {
|
|
76
|
+
const c = chain.charCodeAt(cut);
|
|
77
|
+
if (c === 32 || c === 9) break;
|
|
78
|
+
cut++;
|
|
79
|
+
}
|
|
80
|
+
chain = chain.slice(cut);
|
|
81
|
+
}
|
|
82
|
+
return dropControlIds(chain);
|
|
83
|
+
}
|
|
84
|
+
/** `chain` without the ids that hold a control character, joined by single spaces. */
|
|
85
|
+
function dropControlIds(chain) {
|
|
86
|
+
if (indexOfControl(chain) === -1) return chain;
|
|
87
|
+
const kept = [];
|
|
88
|
+
let start = -1;
|
|
89
|
+
let tainted = false;
|
|
90
|
+
for (let i = 0; i <= chain.length; i++) {
|
|
91
|
+
const c = i < chain.length ? chain.charCodeAt(i) : 32;
|
|
92
|
+
if (c === 32 || c === 9) {
|
|
93
|
+
if (start >= 0 && !tainted) kept.push(chain.slice(start, i));
|
|
94
|
+
start = -1;
|
|
95
|
+
tainted = false;
|
|
96
|
+
} else {
|
|
97
|
+
if (start < 0) start = i;
|
|
98
|
+
if (c < 32 || c === 127) tainted = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return kept.join(" ");
|
|
102
|
+
}
|
|
103
|
+
/** `id` when it fits one `name:` line and holds no control character, else `''`. */
|
|
104
|
+
function threadingId(name, id) {
|
|
105
|
+
return fitsHeaderLine(name, id) && indexOfControl(id) === -1 ? id : "";
|
|
106
|
+
}
|
|
107
|
+
/** `References` cut to its newest whole ids, or `''` when an id cannot fit a line. */
|
|
108
|
+
function threadingReferences(chain) {
|
|
109
|
+
const kept = newestIds(chain, MAX_REFERENCES_CHARS).trim();
|
|
110
|
+
return fitsHeaderLine("References", kept) ? kept : "";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A reply's `References`, or `''`: the inbound chain plus the parent's id,
|
|
114
|
+
* trimmed to its newest whole ids, or the parent's id alone when an id
|
|
115
|
+
* cannot fit a line. `messageId` was already checked with `threadingId`.
|
|
116
|
+
*/
|
|
117
|
+
function replyReferences(originalReferences, messageId) {
|
|
118
|
+
const parent = messageId ? ` ${messageId}` : "";
|
|
119
|
+
const chain = `${newestIds(originalReferences, MAX_REFERENCES_CHARS - parent.length)}${parent}`.trim();
|
|
120
|
+
return fitsHeaderLine("References", chain) ? chain : messageId;
|
|
121
|
+
}
|
|
122
|
+
// src/runtime/email/mime.ts
|
|
123
|
+
/**
|
|
124
|
+
* Minimal RFC 5322 / 2047 / 2045 MIME builder for the bwf/email runtime.
|
|
125
|
+
*
|
|
126
|
+
* Scope is intentionally narrow — text/plain, text/html, multipart/alternative,
|
|
127
|
+
* and multipart/mixed for attachments — covering >95% of transactional sends.
|
|
128
|
+
* Inline images use multipart/related when both attachments and html are present.
|
|
129
|
+
*/
|
|
130
|
+
/** Encoded outbound MIME ceiling, separate from the 10 MiB inbound limit. */
|
|
131
|
+
const MAX_MESSAGE_BYTES = 5242880;
|
|
132
|
+
/**
|
|
133
|
+
* Total attachment bytes `normalizeEmail` will materialize: base64 of more
|
|
134
|
+
* than 3/4 of `MAX_MESSAGE_BYTES` cannot fit. Charged before each copy so an
|
|
135
|
+
* oversize set fails with `MIME_ERROR` instead of exhausting the isolate;
|
|
136
|
+
* `buildMime`'s final size check stays authoritative.
|
|
137
|
+
*/
|
|
138
|
+
const MAX_ATTACHMENT_BYTES_TOTAL = Math.floor(MAX_MESSAGE_BYTES * 3 / 4);
|
|
139
|
+
/** Maximum serialized size of app-defined top-level MIME fields. */
|
|
140
|
+
const MAX_CUSTOM_HEADER_BYTES = 16384;
|
|
141
|
+
const CRLF = "\r\n";
|
|
142
|
+
const ASCII_PRINTABLE = /^[\x20-\x7e]*$/;
|
|
143
|
+
const HEADER_NAME = /^[!-9;-~]+$/;
|
|
144
|
+
function rejectCRLF(field, value) {
|
|
145
|
+
for (let i = 0; i < value.length; i++) {
|
|
146
|
+
const c = value.charCodeAt(i);
|
|
147
|
+
if (c === 13 || c === 10 || c === 0) throw new MimeError("MIME_ERROR", `${field}: must not contain CR, LF, or NUL.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Refuse a control in a value rendered verbatim into a header (an
|
|
152
|
+
* attachment's filename, media type and Content-ID). Names the code point,
|
|
153
|
+
* never the value.
|
|
154
|
+
*/
|
|
155
|
+
function rejectControls(field, value) {
|
|
156
|
+
const i = indexOfControl(value);
|
|
157
|
+
if (i !== -1) throw new MimeError("MIME_ERROR", `${field} contains a control character (U+${value.charCodeAt(i).toString(16).toUpperCase().padStart(4, "0")}).`);
|
|
158
|
+
}
|
|
159
|
+
/** RFC 2045 §5.1 `tspecials`: what a `token` may not contain besides SPACE and CTLs. */
|
|
160
|
+
const TSPECIALS = "()<>@,;:\\\"/[]?=";
|
|
161
|
+
/** RFC 2045 §5.1 `token` character: printable US-ASCII less SPACE and `tspecials`. */
|
|
162
|
+
function isTokenChar(c) {
|
|
163
|
+
return c > 32 && c < 127 && !TSPECIALS.includes(String.fromCharCode(c));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Refuse a media type that is not RFC 2045 §5.1 `type "/" subtype *(";"
|
|
167
|
+
* parameter)`: it is written verbatim before the builder's `name=`, so an
|
|
168
|
+
* unterminated quote would swallow it. WSP is allowed only around `;`. A
|
|
169
|
+
* `name` parameter or a repeated attribute is refused (RFC 6838 §4.3).
|
|
170
|
+
*/
|
|
171
|
+
function validateMediaType(field, value) {
|
|
172
|
+
const syntax = () => new MimeError("MIME_ERROR", `${field} is not a valid media type (RFC 2045 §5.1: type/subtype, then ; attribute=value parameters).`);
|
|
173
|
+
const n = value.length;
|
|
174
|
+
let i = 0;
|
|
175
|
+
/** Advance over a `token`; the number of characters consumed. */
|
|
176
|
+
const token = () => {
|
|
177
|
+
const start = i;
|
|
178
|
+
while (i < n && isTokenChar(value.charCodeAt(i))) i++;
|
|
179
|
+
return i - start;
|
|
180
|
+
};
|
|
181
|
+
const wsp = () => {
|
|
182
|
+
while (i < n && (value[i] === " " || value[i] === " ")) i++;
|
|
183
|
+
};
|
|
184
|
+
if (token() === 0 || value[i] !== "/") throw syntax();
|
|
185
|
+
i++;
|
|
186
|
+
if (token() === 0) throw syntax();
|
|
187
|
+
const seen = /* @__PURE__ */ new Set();
|
|
188
|
+
while (i < n) {
|
|
189
|
+
wsp();
|
|
190
|
+
if (value[i] !== ";") throw syntax();
|
|
191
|
+
i++;
|
|
192
|
+
wsp();
|
|
193
|
+
const start = i;
|
|
194
|
+
if (token() === 0 || value[i] !== "=") throw syntax();
|
|
195
|
+
const attribute = value.slice(start, i).toLowerCase();
|
|
196
|
+
i++;
|
|
197
|
+
if (value[i] === "\"") {
|
|
198
|
+
i++;
|
|
199
|
+
for (;;) {
|
|
200
|
+
if (i >= n) throw syntax();
|
|
201
|
+
const ch = value[i++];
|
|
202
|
+
if (ch === "\"") break;
|
|
203
|
+
if (ch === "\\") {
|
|
204
|
+
if (i >= n) throw syntax();
|
|
205
|
+
i++;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} else if (token() === 0) throw syntax();
|
|
209
|
+
if (attribute === "name") throw new MimeError("MIME_ERROR", `${field} must not carry a name= parameter; the builder adds name="<filename>" itself.`);
|
|
210
|
+
if (seen.has(attribute)) throw new MimeError("MIME_ERROR", `${field} gives the same parameter twice; attribute names are case-insensitive and each may appear once (RFC 6838 §4.3).`);
|
|
211
|
+
seen.add(attribute);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** RFC 5322 §3.2.3 `atext` besides ALPHA and DIGIT. */
|
|
215
|
+
const ATEXT_SYMBOLS = "!#$%&'*+-/=?^_`{|}~";
|
|
216
|
+
/** RFC 5322 §3.2.3 `atext` character. */
|
|
217
|
+
function isAtext(c) {
|
|
218
|
+
return c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || ATEXT_SYMBOLS.includes(String.fromCharCode(c));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Refuse a Content-ID that would not render as an RFC 5322 §3.6.4 `msg-id`
|
|
222
|
+
* of strict `dot-atom-text`. Unlike `msg-id`, the `@` part and the angle
|
|
223
|
+
* brackets are optional: `cid:logo` resolves against `<logo>` (RFC 2392).
|
|
224
|
+
*/
|
|
225
|
+
function validateContentId(field, value) {
|
|
226
|
+
const syntax = () => new MimeError("MIME_ERROR", `${field} is not a valid Content-ID (RFC 5322 §3.6.4 msg-id: an identifier of atext, "." and "@", optionally in one pair of angle brackets).`);
|
|
227
|
+
let i = 0;
|
|
228
|
+
let end = value.length;
|
|
229
|
+
if (value[0] === "<") {
|
|
230
|
+
if (end < 2 || value[end - 1] !== ">") throw syntax();
|
|
231
|
+
i = 1;
|
|
232
|
+
end--;
|
|
233
|
+
}
|
|
234
|
+
/** Advance over a `dot-atom-text`; false when there is none, or a dot is misplaced. */
|
|
235
|
+
const dotAtomText = () => {
|
|
236
|
+
let run = 0;
|
|
237
|
+
for (; i < end; i++) {
|
|
238
|
+
const c = value.charCodeAt(i);
|
|
239
|
+
if (isAtext(c)) run++;
|
|
240
|
+
else if (c === 46 && run > 0) run = 0;
|
|
241
|
+
else break;
|
|
242
|
+
}
|
|
243
|
+
return run > 0;
|
|
244
|
+
};
|
|
245
|
+
if (!dotAtomText()) throw syntax();
|
|
246
|
+
if (i < end) {
|
|
247
|
+
if (value[i] !== "@") throw syntax();
|
|
248
|
+
i++;
|
|
249
|
+
if (!dotAtomText()) throw syntax();
|
|
250
|
+
}
|
|
251
|
+
if (i !== end) throw syntax();
|
|
252
|
+
}
|
|
253
|
+
const COMMON_TYPES = {
|
|
254
|
+
txt: "text/plain",
|
|
255
|
+
html: "text/html",
|
|
256
|
+
htm: "text/html",
|
|
257
|
+
css: "text/css",
|
|
258
|
+
csv: "text/csv",
|
|
259
|
+
pdf: "application/pdf",
|
|
260
|
+
json: "application/json",
|
|
261
|
+
xml: "application/xml",
|
|
262
|
+
zip: "application/zip",
|
|
263
|
+
png: "image/png",
|
|
264
|
+
jpg: "image/jpeg",
|
|
265
|
+
jpeg: "image/jpeg",
|
|
266
|
+
gif: "image/gif",
|
|
267
|
+
webp: "image/webp",
|
|
268
|
+
svg: "image/svg+xml",
|
|
269
|
+
ico: "image/x-icon",
|
|
270
|
+
ics: "text/calendar",
|
|
271
|
+
eml: "message/rfc822"
|
|
272
|
+
};
|
|
273
|
+
function inferContentType(filename) {
|
|
274
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? "";
|
|
275
|
+
return COMMON_TYPES[ext] ?? "application/octet-stream";
|
|
276
|
+
}
|
|
277
|
+
var MimeError = class extends Error {
|
|
278
|
+
code;
|
|
279
|
+
constructor(code, message) {
|
|
280
|
+
super(message);
|
|
281
|
+
this.name = "MimeError";
|
|
282
|
+
this.code = code;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
function fieldErrorCode(field) {
|
|
286
|
+
if (field === "from") return "INVALID_FROM";
|
|
287
|
+
if (field === "to") return "INVALID_TO";
|
|
288
|
+
return "MIME_ERROR";
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Validate one parsed address and optional display name, throwing a
|
|
292
|
+
* `MimeError` for `field`. The address rule is `email-validator`, the one
|
|
293
|
+
* the platform router applies, so a recorded action is never dropped for its
|
|
294
|
+
* shape. The message never echoes the address.
|
|
295
|
+
*/
|
|
296
|
+
function validateAddressParts(field, email, name) {
|
|
297
|
+
if (email.length > 320) throw new MimeError(fieldErrorCode(field), `${field}: address is ${email.length} characters, over the 320-character limit.`);
|
|
298
|
+
if (!validate(email)) throw new MimeError(fieldErrorCode(field), `${field}: address is not a valid email address (ASCII local part and dotted domain, RFC 5322 dot-atom; at most 64 characters before the '@' and 254 in total).`);
|
|
299
|
+
if (name !== void 0) {
|
|
300
|
+
rejectCRLF(`${field} display name`, name);
|
|
301
|
+
if (ASCII_PRINTABLE.test(name) && RFC5322_SPECIALS.test(name) && name.length + QUOTED_NAME_LINE_OVERHEAD > MAX_LINE_OCTETS) throw new MimeError(fieldErrorCode(field), `${field}: display name is ${name.length} characters and must be quoted, which cannot be folded, so its line would exceed the ${MAX_LINE_OCTETS}-octet limit in RFC 5322 §2.1.1. Shorten it.`);
|
|
302
|
+
if (name.includes("@")) throw new MimeError(fieldErrorCode(field), `${field}: display name '${name}' must not contain '@' (likely a malformed address).`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Undo quoted-pairs (`\x` → `x`) in a quoted display name so `formatAddress`
|
|
307
|
+
* escapes it once. A counting pass and an exact buffer, not a global-regex
|
|
308
|
+
* replace, which allocates per match on an unbounded name.
|
|
309
|
+
*/
|
|
310
|
+
function unquotePairs(text) {
|
|
311
|
+
const first = text.indexOf("\\");
|
|
312
|
+
if (first === -1) return text;
|
|
313
|
+
let pairs = 0;
|
|
314
|
+
for (let i = first; i < text.length; i++) if (text.charCodeAt(i) === 92) {
|
|
315
|
+
pairs++;
|
|
316
|
+
i++;
|
|
317
|
+
}
|
|
318
|
+
const out = new Uint16Array(text.length - pairs);
|
|
319
|
+
let n = 0;
|
|
320
|
+
for (let i = 0; i < text.length; i++) {
|
|
321
|
+
let c = text.charCodeAt(i);
|
|
322
|
+
if (c === 92) c = text.charCodeAt(++i);
|
|
323
|
+
out[n++] = c;
|
|
324
|
+
}
|
|
325
|
+
return codeUnitsToString(out);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Parse one address — a bare `email@domain` or `Display Name <email@domain>`
|
|
329
|
+
* — into its parts, throwing a `MimeError` for `field` on anything else.
|
|
330
|
+
* Exported so `bwf.config.ts` `email.from` is validated by the same rules
|
|
331
|
+
* the runtime applies to `from` at send time.
|
|
332
|
+
*/
|
|
333
|
+
function parseAddress(value, field) {
|
|
334
|
+
if (typeof value === "string") {
|
|
335
|
+
rejectCRLF(`${field} address`, value);
|
|
336
|
+
const quoted = value.match(/^\s*"((?:[^"\\]|\\.)*)"\s*<\s*([^>\s]+)\s*>\s*$/);
|
|
337
|
+
const angle = quoted ?? value.match(/^\s*(?:([^"<\s](?:[^"<]*[^"<\s])?)\s*)?<\s*([^>\s]+)\s*>\s*$/);
|
|
338
|
+
if (angle) {
|
|
339
|
+
const name = (quoted ? unquotePairs(angle[1] ?? "") : angle[1])?.trim();
|
|
340
|
+
const email = angle[2];
|
|
341
|
+
validateAddressParts(field, email, name);
|
|
342
|
+
return name ? {
|
|
343
|
+
email,
|
|
344
|
+
name
|
|
345
|
+
} : { email };
|
|
346
|
+
}
|
|
347
|
+
const trimmed = value.trim();
|
|
348
|
+
validateAddressParts(field, trimmed);
|
|
349
|
+
return { email: trimmed };
|
|
350
|
+
}
|
|
351
|
+
validateAddressParts(field, value.email ?? "", value.name);
|
|
352
|
+
return value.name ? {
|
|
353
|
+
email: value.email,
|
|
354
|
+
name: value.name
|
|
355
|
+
} : { email: value.email };
|
|
356
|
+
}
|
|
357
|
+
function parseAddresses(value, field) {
|
|
358
|
+
return (Array.isArray(value) ? value : [value]).map((entry) => parseAddress(entry, field));
|
|
359
|
+
}
|
|
360
|
+
/** Entries in one recipient field, counted the way `parseAddresses` will see them. */
|
|
361
|
+
function countRecipients(value) {
|
|
362
|
+
if (!value) return 0;
|
|
363
|
+
return Array.isArray(value) ? value.length : 1;
|
|
364
|
+
}
|
|
365
|
+
/** Same `exceeds Cloudflare limit of <N> bytes` tail as `buildMime`'s size error. */
|
|
366
|
+
function attachmentsTooLargeError(bytes) {
|
|
367
|
+
return new MimeError("MIME_ERROR", `email: attachment size ${bytes} bytes exceeds Cloudflare limit of ${MAX_ATTACHMENT_BYTES_TOTAL} bytes.`);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Size of `content` without materializing it. A string's `length` is a lower
|
|
371
|
+
* bound on its UTF-8 size; an unsupported type reports 0 for `toBytes` to
|
|
372
|
+
* reject.
|
|
373
|
+
*/
|
|
374
|
+
function declaredSize(content) {
|
|
375
|
+
if (content instanceof Uint8Array) return content.byteLength;
|
|
376
|
+
if (content instanceof ArrayBuffer) return content.byteLength;
|
|
377
|
+
if (typeof Blob !== "undefined" && content instanceof Blob) return content.size;
|
|
378
|
+
if (typeof content === "string") return content.length;
|
|
379
|
+
return 0;
|
|
380
|
+
}
|
|
381
|
+
async function toBytes(content) {
|
|
382
|
+
if (content instanceof Uint8Array) return content;
|
|
383
|
+
if (content instanceof ArrayBuffer) return new Uint8Array(content);
|
|
384
|
+
if (typeof Blob !== "undefined" && content instanceof Blob) return new Uint8Array(await content.arrayBuffer());
|
|
385
|
+
if (typeof content === "string") return new TextEncoder().encode(content);
|
|
386
|
+
throw new MimeError("MIME_ERROR", "attachment content must be string, Uint8Array, ArrayBuffer, or Blob.");
|
|
387
|
+
}
|
|
388
|
+
async function normalizeAttachment(att) {
|
|
389
|
+
if (!att.filename) throw new MimeError("MIME_ERROR", "attachment: missing filename.");
|
|
390
|
+
rejectCRLF("attachment filename", att.filename);
|
|
391
|
+
if (att.filename.length + QUOTED_FILENAME_LINE_OVERHEAD > MAX_LINE_OCTETS) throw new MimeError("MIME_ERROR", `attachment filename is ${att.filename.length} characters; a quoted \`filename=\` parameter cannot be folded, so its line would exceed the ${MAX_LINE_OCTETS}-octet limit in RFC 5322 §2.1.1. Shorten the filename.`);
|
|
392
|
+
rejectControls("attachment filename", att.filename);
|
|
393
|
+
if (att.contentType !== void 0) {
|
|
394
|
+
rejectCRLF("attachment contentType", att.contentType);
|
|
395
|
+
if (att.contentType.length + CONTENT_TYPE_LINE_OVERHEAD > MAX_LINE_OCTETS) throw new MimeError("MIME_ERROR", `attachment contentType is ${att.contentType.length} characters; at most ${MAX_LINE_OCTETS - CONTENT_TYPE_LINE_OVERHEAD} fit on the Content-Type line under the ${MAX_LINE_OCTETS}-octet limit in RFC 5322 §2.1.1. Shorten it.`);
|
|
396
|
+
rejectControls("attachment contentType", att.contentType);
|
|
397
|
+
validateMediaType("attachment contentType", att.contentType);
|
|
398
|
+
}
|
|
399
|
+
if (att.contentId !== void 0) {
|
|
400
|
+
rejectCRLF("attachment contentId", att.contentId);
|
|
401
|
+
const brackets = att.contentId.startsWith("<") ? 0 : 2;
|
|
402
|
+
if (att.contentId.length + brackets + CONTENT_ID_LINE_OVERHEAD > MAX_LINE_OCTETS) throw new MimeError("MIME_ERROR", `attachment contentId is ${att.contentId.length} characters; at most ${MAX_LINE_OCTETS - CONTENT_ID_LINE_OVERHEAD - brackets} fit on the Content-ID line under the ${MAX_LINE_OCTETS}-octet limit in RFC 5322 §2.1.1. Shorten it.`);
|
|
403
|
+
rejectControls("attachment contentId", att.contentId);
|
|
404
|
+
validateContentId("attachment contentId", att.contentId);
|
|
405
|
+
}
|
|
406
|
+
if (att.disposition !== void 0 && att.disposition !== "attachment" && att.disposition !== "inline") throw new MimeError("MIME_ERROR", "attachment disposition must be 'attachment' or 'inline'.");
|
|
407
|
+
const bytes = await toBytes(att.content);
|
|
408
|
+
return {
|
|
409
|
+
filename: att.filename,
|
|
410
|
+
contentType: att.contentType ?? inferContentType(att.filename),
|
|
411
|
+
bytes,
|
|
412
|
+
contentId: att.contentId,
|
|
413
|
+
disposition: att.disposition ?? (att.contentId ? "inline" : "attachment")
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Validate inputs and produce a normalized email shape that can be handed to
|
|
418
|
+
* the MIME builder, the dev inbox, or the test harness without re-parsing.
|
|
419
|
+
*/
|
|
420
|
+
async function normalizeEmail(opts) {
|
|
421
|
+
if (!opts.text && !opts.html) throw new MimeError("MIME_ERROR", "email: at least one of 'text' or 'html' is required.");
|
|
422
|
+
if (opts.subject !== void 0) rejectCRLF("subject", opts.subject);
|
|
423
|
+
if (opts.headers) {
|
|
424
|
+
let headerInputBytes = 0;
|
|
425
|
+
let headerBytes = 0;
|
|
426
|
+
const encoder = new TextEncoder();
|
|
427
|
+
for (const [name, value] of Object.entries(opts.headers)) {
|
|
428
|
+
if (!HEADER_NAME.test(name)) throw new MimeError("MIME_ERROR", `headers: '${name}' is not a valid RFC 5322 header name.`);
|
|
429
|
+
if (name.length + HEADER_NAME_LINE_OVERHEAD > MAX_LINE_OCTETS) throw new MimeError("MIME_ERROR", `headers: a header name is ${name.length} characters; a field name cannot be folded, so its line would exceed the ${MAX_LINE_OCTETS}-octet limit in RFC 5322 §2.1.1. Shorten the name.`);
|
|
430
|
+
if (headerInputBytes + name.length + value.length + 4 > MAX_CUSTOM_HEADER_BYTES) throw new MimeError("MIME_ERROR", "email: custom headers exceed the 16 KiB limit.");
|
|
431
|
+
headerInputBytes += name.length + encoder.encode(value).byteLength + 4;
|
|
432
|
+
if (headerInputBytes > MAX_CUSTOM_HEADER_BYTES) throw new MimeError("MIME_ERROR", "email: custom headers exceed the 16 KiB limit.");
|
|
433
|
+
rejectCRLF(`header '${name}'`, value);
|
|
434
|
+
if (RESERVED_HEADERS.has(name.toLowerCase())) continue;
|
|
435
|
+
if (headerBytes + name.length + CUSTOM_HEADER_FRAMING_OCTETS + minHeaderValueOctets(value) > MAX_CUSTOM_HEADER_BYTES) throw new MimeError("MIME_ERROR", "email: custom headers exceed the 16 KiB limit.");
|
|
436
|
+
headerBytes += foldHeader(name, encodeWord(value)).length + 2;
|
|
437
|
+
if (headerBytes > MAX_CUSTOM_HEADER_BYTES) throw new MimeError("MIME_ERROR", "email: custom headers exceed the 16 KiB limit.");
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const recipientCount = countRecipients(opts.to) + countRecipients(opts.cc) + countRecipients(opts.bcc);
|
|
441
|
+
if (recipientCount > 50) throw new MimeError("INVALID_TO", `email: too many recipients (max 50, got ${recipientCount}) across 'to', 'cc' and 'bcc'.`);
|
|
442
|
+
const from = parseAddress(opts.from, "from");
|
|
443
|
+
const to = parseAddresses(opts.to, "to");
|
|
444
|
+
if (to.length === 0) throw new MimeError("INVALID_TO", "email: 'to' must include at least one recipient.");
|
|
445
|
+
const cc = opts.cc ? parseAddresses(opts.cc, "cc") : [];
|
|
446
|
+
const bcc = opts.bcc ? parseAddresses(opts.bcc, "bcc") : [];
|
|
447
|
+
const replyTo = opts.replyTo ? parseAddress(opts.replyTo, "replyTo") : void 0;
|
|
448
|
+
const attachmentList = opts.attachments ?? [];
|
|
449
|
+
if (!Array.isArray(attachmentList)) throw new MimeError("MIME_ERROR", "email: attachments must be an array.");
|
|
450
|
+
if (attachmentList.length > 43690) throw new MimeError("MIME_ERROR", `email: too many attachments (max ${MAX_ATTACHMENTS}, got ${attachmentList.length}).`);
|
|
451
|
+
const attachments = [];
|
|
452
|
+
let attachmentBytes = 0;
|
|
453
|
+
for (const att of attachmentList) {
|
|
454
|
+
const declared = declaredSize(att.content);
|
|
455
|
+
if (attachmentBytes + declared > MAX_ATTACHMENT_BYTES_TOTAL) throw attachmentsTooLargeError(attachmentBytes + declared);
|
|
456
|
+
const normalized = await normalizeAttachment(att);
|
|
457
|
+
attachmentBytes += normalized.bytes.byteLength;
|
|
458
|
+
if (attachmentBytes > MAX_ATTACHMENT_BYTES_TOTAL) throw attachmentsTooLargeError(attachmentBytes);
|
|
459
|
+
attachments.push(normalized);
|
|
460
|
+
}
|
|
461
|
+
const threading = normalizeThreading(opts.threading);
|
|
462
|
+
return {
|
|
463
|
+
from,
|
|
464
|
+
to,
|
|
465
|
+
cc,
|
|
466
|
+
bcc,
|
|
467
|
+
replyTo,
|
|
468
|
+
subject: opts.subject ?? "",
|
|
469
|
+
text: opts.text,
|
|
470
|
+
html: opts.html,
|
|
471
|
+
headers: opts.headers ? { ...opts.headers } : {},
|
|
472
|
+
attachments,
|
|
473
|
+
threading
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* `threading` from `sendEmail`, `createEmail` or `replyEmail`. A value that is
|
|
478
|
+
* not a string is a caller error. Thread ids often come from remote mail, so a
|
|
479
|
+
* bad id never fails the email: an `inReplyTo` with a control character or
|
|
480
|
+
* too long for one line is left out, and a `references` chain that cannot be
|
|
481
|
+
* sent falls back to `inReplyTo`.
|
|
482
|
+
*/
|
|
483
|
+
function normalizeThreading(threading) {
|
|
484
|
+
if (threading === void 0) return;
|
|
485
|
+
if (typeof threading !== "object" || threading === null || Array.isArray(threading)) throw new MimeError("MIME_ERROR", "threading: must be an object.");
|
|
486
|
+
const { inReplyTo = "", references = "" } = threading;
|
|
487
|
+
if (typeof inReplyTo !== "string") throw new MimeError("MIME_ERROR", "threading.inReplyTo: must be a string.");
|
|
488
|
+
if (typeof references !== "string") throw new MimeError("MIME_ERROR", "threading.references: must be a string.");
|
|
489
|
+
const parent = threadingId("In-Reply-To", trimFws(inReplyTo));
|
|
490
|
+
const chain = threadingReferences(references) || parent;
|
|
491
|
+
if (!parent && !chain) return;
|
|
492
|
+
return {
|
|
493
|
+
...parent ? { inReplyTo: parent } : {},
|
|
494
|
+
...chain ? { references: chain } : {}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* RFC 2047 §2: a 75-character encoded-word less `=?UTF-8?B?` and `?=` leaves
|
|
499
|
+
* 63 characters of base64, so 45 source bytes.
|
|
500
|
+
*/
|
|
501
|
+
const ENCODED_WORD_PAYLOAD_BYTES = 45;
|
|
502
|
+
/**
|
|
503
|
+
* RFC 2047 B encoded-words for non-ASCII header text, space-separated so
|
|
504
|
+
* `foldHeader` can fold between them.
|
|
505
|
+
*/
|
|
506
|
+
function encodeWord(text) {
|
|
507
|
+
if (ASCII_PRINTABLE.test(text)) return text;
|
|
508
|
+
const encoder = new TextEncoder();
|
|
509
|
+
const pending = /* @__PURE__ */ new Uint8Array(49);
|
|
510
|
+
let length = 0;
|
|
511
|
+
const words = [];
|
|
512
|
+
const flush = () => {
|
|
513
|
+
if (length > 0) {
|
|
514
|
+
words.push(`=?UTF-8?B?${bytesToBase64(pending.subarray(0, length))}?=`);
|
|
515
|
+
length = 0;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
for (const char of text) {
|
|
519
|
+
const bytes = encoder.encode(char);
|
|
520
|
+
if (length > 0 && length + bytes.length > ENCODED_WORD_PAYLOAD_BYTES) flush();
|
|
521
|
+
pending.set(bytes, length);
|
|
522
|
+
length += bytes.length;
|
|
523
|
+
}
|
|
524
|
+
flush();
|
|
525
|
+
return words.join(" ");
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* RFC 5322 §3.2.3 `specials`, in the RFC's order: an ASCII display name with
|
|
529
|
+
* any of them must be quoted (an unquoted `Dr. Smith` is obsolete syntax).
|
|
530
|
+
*/
|
|
531
|
+
const RFC5322_SPECIALS = /[()<>[\]:;@\\,."]/;
|
|
532
|
+
function formatAddress(addr) {
|
|
533
|
+
if (!addr.name) return addr.email;
|
|
534
|
+
if (!ASCII_PRINTABLE.test(addr.name)) return `${encodeWord(addr.name)} <${addr.email}>`;
|
|
535
|
+
if (RFC5322_SPECIALS.test(addr.name)) return `"${quoteParam(addr.name)}" <${addr.email}>`;
|
|
536
|
+
return `${addr.name} <${addr.email}>`;
|
|
537
|
+
}
|
|
538
|
+
function formatAddressList(addrs) {
|
|
539
|
+
return addrs.map(formatAddress).join(", ");
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Soft-fold a header at 76 columns (RFC 2047 §2): at `, ` outside quotes
|
|
543
|
+
* first, then at unquoted whitespace. A token longer than a line keeps its
|
|
544
|
+
* own line, since RFC 5322 folds only at WSP. One pass that keeps only the
|
|
545
|
+
* output; per-token allocation would exhaust the isolate on a large subject.
|
|
546
|
+
*/
|
|
547
|
+
function foldHeader(name, value) {
|
|
548
|
+
const line = `${name}: ${value}`;
|
|
549
|
+
if (line.length <= 78) return line;
|
|
550
|
+
const MAX_LINE = 76;
|
|
551
|
+
const lines = [];
|
|
552
|
+
let current = [`${name}:`];
|
|
553
|
+
let lineLen = name.length + 1;
|
|
554
|
+
let chunks = 0;
|
|
555
|
+
const emit = (text, comma) => {
|
|
556
|
+
chunks++;
|
|
557
|
+
const piece = comma ? `${text},` : text;
|
|
558
|
+
if (piece.length > 0 && lineLen + 1 + piece.length > MAX_LINE) {
|
|
559
|
+
lines.push(current.join(" "));
|
|
560
|
+
current = ["", piece];
|
|
561
|
+
lineLen = 1 + piece.length;
|
|
562
|
+
} else {
|
|
563
|
+
current.push(piece);
|
|
564
|
+
lineLen += 1 + piece.length;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
let tokenStart = -1;
|
|
568
|
+
let heldStart = -1;
|
|
569
|
+
let heldEnd = -1;
|
|
570
|
+
const endToken = (i) => {
|
|
571
|
+
if (tokenStart < 0) return;
|
|
572
|
+
if (heldStart >= 0) emit(value.slice(heldStart, heldEnd), false);
|
|
573
|
+
heldStart = tokenStart;
|
|
574
|
+
heldEnd = i;
|
|
575
|
+
tokenStart = -1;
|
|
576
|
+
};
|
|
577
|
+
const endPart = (isLast) => {
|
|
578
|
+
if (heldStart >= 0) {
|
|
579
|
+
emit(value.slice(heldStart, heldEnd), !isLast);
|
|
580
|
+
heldStart = -1;
|
|
581
|
+
} else emit("", !isLast);
|
|
582
|
+
};
|
|
583
|
+
let inQuotes = false;
|
|
584
|
+
let escape = false;
|
|
585
|
+
for (let i = 0; i < value.length; i++) {
|
|
586
|
+
const ch = value[i];
|
|
587
|
+
if (escape) {
|
|
588
|
+
escape = false;
|
|
589
|
+
if (tokenStart < 0) tokenStart = i;
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (ch === "\\" && inQuotes) {
|
|
593
|
+
escape = true;
|
|
594
|
+
if (tokenStart < 0) tokenStart = i;
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
if (ch === "\"") {
|
|
598
|
+
inQuotes = !inQuotes;
|
|
599
|
+
if (tokenStart < 0) tokenStart = i;
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
if (!inQuotes && ch === "," && value[i + 1] === " ") {
|
|
603
|
+
endToken(i);
|
|
604
|
+
endPart(false);
|
|
605
|
+
i++;
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
if (!inQuotes && (ch === " " || ch === " ")) {
|
|
609
|
+
endToken(i);
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (tokenStart < 0) tokenStart = i;
|
|
613
|
+
}
|
|
614
|
+
endToken(value.length);
|
|
615
|
+
endPart(true);
|
|
616
|
+
if (chunks <= 1) return line;
|
|
617
|
+
lines.push(current.join(" "));
|
|
618
|
+
return lines.join(CRLF);
|
|
619
|
+
}
|
|
620
|
+
/** RFC 5322 §2.1.1: each line MUST be at most 998 octets, excluding CRLF. */
|
|
621
|
+
const MAX_LINE_OCTETS = 998;
|
|
622
|
+
/** ` filename="` + `"`: the shortest line a quoted filename parameter can fold onto. */
|
|
623
|
+
const QUOTED_FILENAME_LINE_OVERHEAD = 12;
|
|
624
|
+
/**
|
|
625
|
+
* ` ` + `;`: the shortest line the media type can fold onto as one token
|
|
626
|
+
* (conservative for several parameters).
|
|
627
|
+
*/
|
|
628
|
+
const CONTENT_TYPE_LINE_OVERHEAD = 2;
|
|
629
|
+
/** `Content-ID: `: the id is one token and cannot fold off this line. */
|
|
630
|
+
const CONTENT_ID_LINE_OVERHEAD = 12;
|
|
631
|
+
/** ` "` + `"`: the shortest line a quoted display name can fold onto. */
|
|
632
|
+
const QUOTED_NAME_LINE_OVERHEAD = 3;
|
|
633
|
+
/** `:` alone: the shortest line a header name can sit on, its value folded onto the next. */
|
|
634
|
+
const HEADER_NAME_LINE_OVERHEAD = 1;
|
|
635
|
+
/**
|
|
636
|
+
* First CRLF-delimited line over the octet limit, counted in UTF-8 without
|
|
637
|
+
* allocating. Every line is scanned because part headers live in the body;
|
|
638
|
+
* encoded body content never trips it.
|
|
639
|
+
*/
|
|
640
|
+
function findOverlongLine(text) {
|
|
641
|
+
let index = 0;
|
|
642
|
+
let octets = 0;
|
|
643
|
+
for (let i = 0; i < text.length; i++) {
|
|
644
|
+
const c = text.charCodeAt(i);
|
|
645
|
+
if (c === 13 && text.charCodeAt(i + 1) === 10) {
|
|
646
|
+
if (octets > MAX_LINE_OCTETS) return {
|
|
647
|
+
index,
|
|
648
|
+
octets
|
|
649
|
+
};
|
|
650
|
+
index++;
|
|
651
|
+
octets = 0;
|
|
652
|
+
i++;
|
|
653
|
+
} else if (c < 128) octets += 1;
|
|
654
|
+
else if (c < 2048) octets += 2;
|
|
655
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < text.length) {
|
|
656
|
+
const d = text.charCodeAt(i + 1);
|
|
657
|
+
if (d >= 56320 && d <= 57343) {
|
|
658
|
+
octets += 4;
|
|
659
|
+
i++;
|
|
660
|
+
} else octets += 3;
|
|
661
|
+
} else octets += 3;
|
|
662
|
+
}
|
|
663
|
+
return octets > MAX_LINE_OCTETS ? {
|
|
664
|
+
index,
|
|
665
|
+
octets
|
|
666
|
+
} : void 0;
|
|
667
|
+
}
|
|
668
|
+
/** Escape `\` and `"` as quoted-pairs (RFC 5322 §3.2.4), backslash first. */
|
|
669
|
+
function quoteParam(value) {
|
|
670
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
671
|
+
}
|
|
672
|
+
/** `<prefix>_<base36 time><16 random hex>`. */
|
|
673
|
+
function newId(prefix) {
|
|
674
|
+
const bytes = /* @__PURE__ */ new Uint8Array(8);
|
|
675
|
+
crypto.getRandomValues(bytes);
|
|
676
|
+
let hex = "";
|
|
677
|
+
for (const b of bytes) hex += b.toString(16).padStart(2, "0");
|
|
678
|
+
return `${prefix}_${Date.now().toString(36)}${hex}`;
|
|
679
|
+
}
|
|
680
|
+
function base64Wrapped(bytes) {
|
|
681
|
+
const encoded = bytesToBase64(bytes);
|
|
682
|
+
const lines = [];
|
|
683
|
+
for (let i = 0; i < encoded.length; i += 76) lines.push(encoded.slice(i, i + 76));
|
|
684
|
+
return lines.join(CRLF);
|
|
685
|
+
}
|
|
686
|
+
function quotedPrintable(text) {
|
|
687
|
+
const bytes = new TextEncoder().encode(text);
|
|
688
|
+
const out = new Uint8Array(Math.ceil(bytes.length * 3 * (76 / 73)) + 8);
|
|
689
|
+
let n = 0;
|
|
690
|
+
let lineLen = 0;
|
|
691
|
+
const HEX = "0123456789ABCDEF";
|
|
692
|
+
const put = (c) => {
|
|
693
|
+
out[n++] = c;
|
|
694
|
+
};
|
|
695
|
+
const flush = (c0, c1, c2) => {
|
|
696
|
+
const width = c2 !== void 0 ? 3 : c1 !== void 0 ? 2 : 1;
|
|
697
|
+
if (lineLen + width > 75) {
|
|
698
|
+
put(61);
|
|
699
|
+
put(13);
|
|
700
|
+
put(10);
|
|
701
|
+
lineLen = 0;
|
|
702
|
+
}
|
|
703
|
+
put(c0);
|
|
704
|
+
if (c1 !== void 0) put(c1);
|
|
705
|
+
if (c2 !== void 0) put(c2);
|
|
706
|
+
lineLen += width;
|
|
707
|
+
};
|
|
708
|
+
const quote = (b) => flush(61, HEX.charCodeAt(b >> 4), HEX.charCodeAt(b & 15));
|
|
709
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
710
|
+
const b = bytes[i];
|
|
711
|
+
if (b === 10) {
|
|
712
|
+
put(13);
|
|
713
|
+
put(10);
|
|
714
|
+
lineLen = 0;
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (b === 13) {
|
|
718
|
+
if (bytes[i + 1] === 10) continue;
|
|
719
|
+
put(13);
|
|
720
|
+
put(10);
|
|
721
|
+
lineLen = 0;
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
if (b === 32 || b === 9) {
|
|
725
|
+
if (i === bytes.length - 1 || bytes[i + 1] === 10 || bytes[i + 1] === 13) quote(b);
|
|
726
|
+
else flush(b);
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
if (b === 61 || b < 32 || b > 126) {
|
|
730
|
+
quote(b);
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
flush(b);
|
|
734
|
+
}
|
|
735
|
+
return codeUnitsToString(out.subarray(0, n));
|
|
736
|
+
}
|
|
737
|
+
/** One character per code unit, in 32K chunks to stay under the call-argument limit. */
|
|
738
|
+
function codeUnitsToString(units) {
|
|
739
|
+
let s = "";
|
|
740
|
+
const chunk = 32768;
|
|
741
|
+
for (let i = 0; i < units.length; i += chunk) s += String.fromCharCode(...units.subarray(i, i + chunk));
|
|
742
|
+
return s;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Whether a body needs quoted-printable: anything outside printable ASCII
|
|
746
|
+
* (a bare CR included) or a line over 990 characters. One pass without
|
|
747
|
+
* allocation.
|
|
748
|
+
*/
|
|
749
|
+
function needsQuotedPrintable(text) {
|
|
750
|
+
let lineLen = 0;
|
|
751
|
+
for (let i = 0; i < text.length; i++) {
|
|
752
|
+
const c = text.charCodeAt(i);
|
|
753
|
+
if (c === 10) {
|
|
754
|
+
lineLen = 0;
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
if (c === 13) {
|
|
758
|
+
if (text.charCodeAt(i + 1) === 10) continue;
|
|
759
|
+
return true;
|
|
760
|
+
}
|
|
761
|
+
if (c < 32 || c > 126) return true;
|
|
762
|
+
lineLen++;
|
|
763
|
+
if (lineLen > 990) return true;
|
|
764
|
+
}
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* `text` with each bare LF widened to CRLF. Called only when every character
|
|
769
|
+
* is one byte, so a counting pass sizes the buffer exactly; a global-regex
|
|
770
|
+
* replace would allocate per line.
|
|
771
|
+
*/
|
|
772
|
+
function to7bitBody(text) {
|
|
773
|
+
let bare = 0;
|
|
774
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) === 10 && (i === 0 || text.charCodeAt(i - 1) !== 13)) bare++;
|
|
775
|
+
if (bare === 0) return text;
|
|
776
|
+
const out = new Uint8Array(text.length + bare);
|
|
777
|
+
let n = 0;
|
|
778
|
+
for (let i = 0; i < text.length; i++) {
|
|
779
|
+
const c = text.charCodeAt(i);
|
|
780
|
+
if (c === 10 && (i === 0 || text.charCodeAt(i - 1) !== 13)) out[n++] = 13;
|
|
781
|
+
out[n++] = c;
|
|
782
|
+
}
|
|
783
|
+
return codeUnitsToString(out);
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Lower bound on `text`'s rendered octets, without allocating: ASCII is at
|
|
787
|
+
* least 1 octet and each non-ASCII UTF-8 byte is `=XX`.
|
|
788
|
+
*/
|
|
789
|
+
function minBodyOctets(text) {
|
|
790
|
+
let octets = 0;
|
|
791
|
+
for (let i = 0; i < text.length; i++) {
|
|
792
|
+
const c = text.charCodeAt(i);
|
|
793
|
+
if (c < 128) octets += 1;
|
|
794
|
+
else if (c < 2048) octets += 6;
|
|
795
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < text.length) {
|
|
796
|
+
const d = text.charCodeAt(i + 1);
|
|
797
|
+
if (d >= 56320 && d <= 57343) {
|
|
798
|
+
octets += 12;
|
|
799
|
+
i++;
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
octets += 9;
|
|
803
|
+
} else octets += 9;
|
|
804
|
+
}
|
|
805
|
+
return octets;
|
|
806
|
+
}
|
|
807
|
+
/** Octets a base64 body of `n` bytes occupies at 76 columns, excluding CRLF. */
|
|
808
|
+
function base64Octets(n) {
|
|
809
|
+
return Math.ceil(n / 3) * 4;
|
|
810
|
+
}
|
|
811
|
+
function renderPart(part) {
|
|
812
|
+
return part.headers.map(([k, v]) => foldHeader(k, v)).join(CRLF) + "\r\n\r\n" + part.body;
|
|
813
|
+
}
|
|
814
|
+
function buildBodyPart(contentType, body) {
|
|
815
|
+
const useQp = needsQuotedPrintable(body);
|
|
816
|
+
return {
|
|
817
|
+
headers: [["Content-Type", `${contentType}; charset=UTF-8`], ["Content-Transfer-Encoding", useQp ? "quoted-printable" : "7bit"]],
|
|
818
|
+
body: useQp ? quotedPrintable(body) : to7bitBody(body)
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
function buildAttachmentPart(att) {
|
|
822
|
+
const headers = [
|
|
823
|
+
["Content-Type", `${att.contentType}; name="${quoteParam(att.filename)}"`],
|
|
824
|
+
["Content-Transfer-Encoding", "base64"],
|
|
825
|
+
["Content-Disposition", `${att.disposition}; filename="${quoteParam(att.filename)}"`]
|
|
826
|
+
];
|
|
827
|
+
if (att.contentId) {
|
|
828
|
+
const cid = att.contentId.startsWith("<") ? att.contentId : `<${att.contentId}>`;
|
|
829
|
+
headers.push(["Content-ID", cid]);
|
|
830
|
+
}
|
|
831
|
+
return {
|
|
832
|
+
headers,
|
|
833
|
+
body: base64Wrapped(att.bytes)
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
function makeBoundary(prefix) {
|
|
837
|
+
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
838
|
+
crypto.getRandomValues(bytes);
|
|
839
|
+
return `=_nosam_${prefix}_${bytesToBase64(bytes).replace(/[+/=]/g, "")}`;
|
|
840
|
+
}
|
|
841
|
+
function wrapMultipart(type, parts) {
|
|
842
|
+
const boundary = makeBoundary(type);
|
|
843
|
+
return {
|
|
844
|
+
headers: [["Content-Type", `multipart/${type}; boundary="${boundary}"`]],
|
|
845
|
+
body: parts.map((p) => `--${boundary}${CRLF}${renderPart(p)}`).join(CRLF) + `${CRLF}--${boundary}--${CRLF}`
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
const RESERVED_HEADERS = /* @__PURE__ */ new Set([
|
|
849
|
+
"from",
|
|
850
|
+
"to",
|
|
851
|
+
"cc",
|
|
852
|
+
"bcc",
|
|
853
|
+
"subject",
|
|
854
|
+
"reply-to",
|
|
855
|
+
"date",
|
|
856
|
+
"message-id",
|
|
857
|
+
"in-reply-to",
|
|
858
|
+
"references",
|
|
859
|
+
"mime-version",
|
|
860
|
+
"content-type",
|
|
861
|
+
"content-transfer-encoding",
|
|
862
|
+
"content-disposition"
|
|
863
|
+
]);
|
|
864
|
+
/**
|
|
865
|
+
* Lower bound on one rendered header value, without allocating. Printable
|
|
866
|
+
* ASCII counts its non-WSP characters (folding may collapse WSP runs);
|
|
867
|
+
* anything else is B-encoded whole, at least 4/3 of its UTF-8 bytes plus 12
|
|
868
|
+
* octets of framing per 45-byte word.
|
|
869
|
+
*/
|
|
870
|
+
function minHeaderValueOctets(value) {
|
|
871
|
+
let utf8 = 0;
|
|
872
|
+
let visible = 0;
|
|
873
|
+
let encoded = false;
|
|
874
|
+
for (let i = 0; i < value.length; i++) {
|
|
875
|
+
const c = value.charCodeAt(i);
|
|
876
|
+
if (c < 128) {
|
|
877
|
+
utf8 += 1;
|
|
878
|
+
if (c === 32 || c === 9) continue;
|
|
879
|
+
if (c < 32 || c === 127) encoded = true;
|
|
880
|
+
visible += 1;
|
|
881
|
+
} else {
|
|
882
|
+
encoded = true;
|
|
883
|
+
if (c < 2048) utf8 += 2;
|
|
884
|
+
else if (c >= 55296 && c <= 56319 && i + 1 < value.length) {
|
|
885
|
+
const d = value.charCodeAt(i + 1);
|
|
886
|
+
if (d >= 56320 && d <= 57343) {
|
|
887
|
+
utf8 += 4;
|
|
888
|
+
i++;
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
utf8 += 3;
|
|
892
|
+
} else utf8 += 3;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (!encoded) return visible;
|
|
896
|
+
return Math.floor(utf8 * 4 / 3) + 12 * Math.floor(utf8 / ENCODED_WORD_PAYLOAD_BYTES);
|
|
897
|
+
}
|
|
898
|
+
/** Lower bound on one rendered address: its display name, plus the address itself verbatim. */
|
|
899
|
+
function minAddressOctets(addr) {
|
|
900
|
+
return addr.email.length + (addr.name ? minHeaderValueOctets(addr.name) : 0);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Lower bound on a value rendered verbatim (threading ids, media type,
|
|
904
|
+
* Content-ID): one octet per non-WSP code unit. `minHeaderValueOctets` would
|
|
905
|
+
* overshoot, since these are raw UTF-8, not encoded-words.
|
|
906
|
+
*/
|
|
907
|
+
function minVerbatimOctets(value) {
|
|
908
|
+
let octets = 0;
|
|
909
|
+
for (let i = 0; i < value.length; i++) {
|
|
910
|
+
const c = value.charCodeAt(i);
|
|
911
|
+
if (c !== 32 && c !== 9) octets += 1;
|
|
912
|
+
}
|
|
913
|
+
return octets;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Framing every attachment part costs with empty values. The random boundary
|
|
917
|
+
* suffix has no provable minimum, so it is not counted.
|
|
918
|
+
*/
|
|
919
|
+
const ATTACHMENT_PART_MIN_OCTETS = 118;
|
|
920
|
+
/**
|
|
921
|
+
* Cap on the attachment count, checked before any entry is normalized:
|
|
922
|
+
* zero-byte entries never advance the byte total. It is the most parts
|
|
923
|
+
* `buildMime`'s size projection can admit, so it refuses nothing that fits.
|
|
924
|
+
*/
|
|
925
|
+
const MAX_ATTACHMENTS = Math.floor(MAX_MESSAGE_BYTES / 120);
|
|
926
|
+
/** `: ` and the CRLF around a custom header value; exact once the name is counted. */
|
|
927
|
+
const CUSTOM_HEADER_FRAMING_OCTETS = 4;
|
|
928
|
+
/**
|
|
929
|
+
* Lower bound on every header rendered from caller values. Bcc and reserved
|
|
930
|
+
* custom headers never render, and the fixed framing of bwf's own headers
|
|
931
|
+
* is omitted. A custom header's name and framing, and each attachment part's
|
|
932
|
+
* framing and filename (twice), are charged: a message of many empty headers
|
|
933
|
+
* or attachments is all framing.
|
|
934
|
+
*/
|
|
935
|
+
function minHeaderOctets(email) {
|
|
936
|
+
let octets = minHeaderValueOctets(email.subject);
|
|
937
|
+
for (const [name, value] of Object.entries(email.headers)) if (!RESERVED_HEADERS.has(name.toLowerCase())) octets += name.length + CUSTOM_HEADER_FRAMING_OCTETS + minHeaderValueOctets(value);
|
|
938
|
+
octets += minAddressOctets(email.from);
|
|
939
|
+
for (const addr of email.to) octets += minAddressOctets(addr);
|
|
940
|
+
for (const addr of email.cc) octets += minAddressOctets(addr);
|
|
941
|
+
if (email.replyTo) octets += minAddressOctets(email.replyTo);
|
|
942
|
+
if (email.threading?.inReplyTo) octets += minVerbatimOctets(email.threading.inReplyTo);
|
|
943
|
+
if (email.threading?.references) octets += minVerbatimOctets(email.threading.references);
|
|
944
|
+
for (const att of email.attachments) {
|
|
945
|
+
octets += ATTACHMENT_PART_MIN_OCTETS + 2 * att.filename.length;
|
|
946
|
+
octets += minVerbatimOctets(att.contentType);
|
|
947
|
+
if (att.contentId) octets += minVerbatimOctets(att.contentId);
|
|
948
|
+
}
|
|
949
|
+
return octets;
|
|
950
|
+
}
|
|
951
|
+
function generateMessageId(fromEmail) {
|
|
952
|
+
const domain = fromEmail.split("@")[1] ?? "localhost";
|
|
953
|
+
const bytes = /* @__PURE__ */ new Uint8Array(12);
|
|
954
|
+
crypto.getRandomValues(bytes);
|
|
955
|
+
return `<${bytesToBase64(bytes).replace(/[+/=]/g, "")}@${domain}>`;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Build the raw RFC 5322 message body. Returns the message bytes plus the
|
|
959
|
+
* generated Message-ID header so callers can surface it in the result.
|
|
960
|
+
*/
|
|
961
|
+
function buildMime(email) {
|
|
962
|
+
const projected = minHeaderOctets(email) + (email.text ? minBodyOctets(email.text) : 0) + (email.html ? minBodyOctets(email.html) : 0) + email.attachments.reduce((sum, a) => sum + base64Octets(a.bytes.byteLength), 0);
|
|
963
|
+
if (projected > 5242880) throw new MimeError("MIME_ERROR", `email: message is at least ${projected} bytes once encoded, which exceeds Cloudflare limit of ${MAX_MESSAGE_BYTES} bytes.`);
|
|
964
|
+
const messageId = generateMessageId(email.from.email);
|
|
965
|
+
const topHeaders = [
|
|
966
|
+
["Date", (/* @__PURE__ */ new Date()).toUTCString().replace("GMT", "+0000")],
|
|
967
|
+
["From", formatAddress(email.from)],
|
|
968
|
+
["To", formatAddressList(email.to)]
|
|
969
|
+
];
|
|
970
|
+
if (email.cc.length > 0) topHeaders.push(["Cc", formatAddressList(email.cc)]);
|
|
971
|
+
if (email.replyTo) topHeaders.push(["Reply-To", formatAddress(email.replyTo)]);
|
|
972
|
+
topHeaders.push(["Subject", encodeWord(email.subject)]);
|
|
973
|
+
topHeaders.push(["Message-ID", messageId]);
|
|
974
|
+
if (email.threading?.inReplyTo) topHeaders.push(["In-Reply-To", email.threading.inReplyTo]);
|
|
975
|
+
if (email.threading?.references) topHeaders.push(["References", email.threading.references]);
|
|
976
|
+
topHeaders.push(["MIME-Version", "1.0"]);
|
|
977
|
+
for (const [name, value] of Object.entries(email.headers)) {
|
|
978
|
+
if (RESERVED_HEADERS.has(name.toLowerCase())) continue;
|
|
979
|
+
topHeaders.push([name, encodeWord(value)]);
|
|
980
|
+
}
|
|
981
|
+
const textPart = email.text ? buildBodyPart("text/plain", email.text) : void 0;
|
|
982
|
+
const htmlPart = email.html ? buildBodyPart("text/html", email.html) : void 0;
|
|
983
|
+
let bodyPart;
|
|
984
|
+
if (textPart && htmlPart) bodyPart = wrapMultipart("alternative", [textPart, htmlPart]);
|
|
985
|
+
else bodyPart = textPart ?? htmlPart;
|
|
986
|
+
if (email.attachments.length > 0) {
|
|
987
|
+
const inlineAttachments = email.attachments.filter((a) => a.disposition === "inline");
|
|
988
|
+
const fileAttachments = email.attachments.filter((a) => a.disposition !== "inline");
|
|
989
|
+
if (inlineAttachments.length > 0 && htmlPart) bodyPart = wrapMultipart("related", [bodyPart, ...inlineAttachments.map(buildAttachmentPart)]);
|
|
990
|
+
else fileAttachments.push(...inlineAttachments);
|
|
991
|
+
if (fileAttachments.length > 0) bodyPart = wrapMultipart("mixed", [bodyPart, ...fileAttachments.map(buildAttachmentPart)]);
|
|
992
|
+
}
|
|
993
|
+
for (const [k, v] of bodyPart.headers) topHeaders.push([k, v]);
|
|
994
|
+
const rawText = topHeaders.map(([k, v]) => foldHeader(k, v)).join(CRLF) + "\r\n\r\n" + bodyPart.body;
|
|
995
|
+
const raw = new TextEncoder().encode(rawText);
|
|
996
|
+
const overlong = findOverlongLine(rawText);
|
|
997
|
+
if (overlong !== void 0) throw new MimeError("MIME_ERROR", `email: header line ${overlong.index + 1} is ${overlong.octets} octets, over the ${MAX_LINE_OCTETS}-octet limit in RFC 5322 §2.1.1. A value with no whitespace cannot be folded — shorten it, or move it into the body.`);
|
|
998
|
+
if (raw.byteLength > 5242880) throw new MimeError("MIME_ERROR", `email: message size ${raw.byteLength} bytes exceeds Cloudflare limit of ${MAX_MESSAGE_BYTES} bytes.`);
|
|
999
|
+
return {
|
|
1000
|
+
raw,
|
|
1001
|
+
messageId
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
export { normalizeEmail as a, fitsHeaderLine as c, newId as i, replyReferences as l, MimeError as n, parseAddress as o, buildMime as r, validateAddressParts as s, MAX_MESSAGE_BYTES as t, threadingId as u };
|