@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,270 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Carry types from your database schema through route handlers to the UI.'
|
|
3
|
+
outline: deep
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Type Safety
|
|
7
|
+
|
|
8
|
+
bwf infers types from your database schema and route handlers. When you change a field, TypeScript shows which queries, requests, and components need to change.
|
|
9
|
+
|
|
10
|
+
## The Type Pipeline
|
|
11
|
+
|
|
12
|
+
<img src="./type-pipeline.svg" alt="Type pipeline: Drizzle schema flows to DB types, then into route handlers and the typed fetch client" style="max-width: 720px; width: 100%;" />
|
|
13
|
+
|
|
14
|
+
1. **Database types** come from your [Drizzle schema](./database.md#schema-definition). Column types are known at compile time.
|
|
15
|
+
2. **Route handlers:** return types and validator schemas become the generated `RouteMap`, which the [typed fetch](./typed-fetch) client consumes.
|
|
16
|
+
|
|
17
|
+
All generated types live in `.bwf/` and update automatically when source files or schema change.
|
|
18
|
+
|
|
19
|
+
## Database → Handler → Client
|
|
20
|
+
|
|
21
|
+
Types flow from your Drizzle schema through handlers to the client without any manual annotations:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// routes/api/users.ts
|
|
25
|
+
export const GET = defineHandler(async (c) => {
|
|
26
|
+
return db.select({ name: users.name, email: users.email }).from(users);
|
|
27
|
+
// ↑ return type inferred from schema columns
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const POST = defineHandler.withValidator({
|
|
31
|
+
body: insertUserSchema, // ← derived from Drizzle schema
|
|
32
|
+
})(async (c, { body }) => {
|
|
33
|
+
return db.insert(users).values(body).returning();
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// Client: types inferred from handlers above
|
|
39
|
+
const users = await fetch('/api/users');
|
|
40
|
+
// ↑ { name: string; email: string }[]
|
|
41
|
+
|
|
42
|
+
await fetch('/api/users', {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
body: { name: 'Alice', email: 'alice@example.com' }, // ← typed from validator
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The Drizzle schema defines database columns, runtime validation, handler input types, and client-side type checking all at once. For endpoints that don't map to a table, use any [Standard Schema](./server-routing.md#manual-validators) library.
|
|
49
|
+
|
|
50
|
+
## Typed URLs and Navigation
|
|
51
|
+
|
|
52
|
+
To build the URL of an API route, pass its route pattern and parameters to `routeUrl()`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { routeUrl } from '@builtbyfriends/bwf/routes';
|
|
56
|
+
|
|
57
|
+
const url = routeUrl('/api/users/[id]', {
|
|
58
|
+
params: { id: 42 },
|
|
59
|
+
query: { fields: 'name' },
|
|
60
|
+
});
|
|
61
|
+
// /api/users/42?fields=name
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
TypeScript checks the route and required parameter names. Patterns follow your filenames: `routes/api/users/[id].ts` uses `/api/users/[id]`.
|
|
65
|
+
|
|
66
|
+
Parameters accept strings or numbers and are URL-encoded for you. Query values can be strings, numbers, booleans, or arrays. Arrays become repeated keys; `null` and `undefined` values are omitted.
|
|
67
|
+
|
|
68
|
+
The same bracket patterns work with typed `fetch()` and WebSocket `connect()`.
|
|
69
|
+
|
|
70
|
+
Pass the returned string to `fetch()`, an `<a>`, or `c.redirect()`. For `c.redirect()` and `c.rewrite()`, you can pass a destination object directly:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import type { RouteDestination } from '@builtbyfriends/bwf/routes';
|
|
74
|
+
|
|
75
|
+
const user = {
|
|
76
|
+
pathname: '/api/users/[id]',
|
|
77
|
+
params: { id: 42 },
|
|
78
|
+
query: { fields: 'name' },
|
|
79
|
+
} satisfies RouteDestination;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Destination objects check and encode parameters just like `routeUrl()`. See [Rewrites](../reference/api/rewrites.md#c-rewrite-destination) for server navigation.
|
|
83
|
+
|
|
84
|
+
For a catch-all route such as `routes/files/[...path].ts`, use `/files/[...path]` and pass the full path as one value:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
routeUrl('/files/[...path]', { params: { path: 'docs/get started' } });
|
|
88
|
+
// /files/docs/get%20started
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
For an unnamed catch-all (`[...]`), pass its value under the `'*'` key:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
routeUrl('/files/[...]', { params: { '*': 'docs/get started' } });
|
|
95
|
+
// /files/docs/get%20started
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Checked URL strings
|
|
99
|
+
|
|
100
|
+
Enable [`routing.typedRoutes`](../reference/config.md#routing-typedroutes) to catch misspelled URLs in redirects, rewrites, and stream clients. Apps created with `bwf init` already have it enabled. For an existing app:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
// bwf.config.ts
|
|
104
|
+
import { defineConfig } from '@builtbyfriends/bwf/config';
|
|
105
|
+
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
routing: { typedRoutes: true },
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
A string must then match one of your routes, optionally followed by a query string or hash:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
c.redirect('/api/health');
|
|
115
|
+
c.redirect(`/api/users/${user.id}?fields=name`);
|
|
116
|
+
c.redirect('/api/helth'); // Type error: no route matches
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Redirects also accept same-page queries and hashes (`?page=2`, `#comments`), and `http://`, `https://`, `mailto:`, and `tel:` URLs. Use absolute paths within your app; relative paths such as `../settings` are rejected. Static path segments accept raw text such as `/café menu` or uppercase percent encoding such as `/caf%C3%A9%20menu`.
|
|
120
|
+
|
|
121
|
+
String checks use TypeScript patterns, which don't validate individual dynamic segments. For example, `/users/[id]` also accepts `/users/` and `/users/42/edit`. A root dynamic route can accept `//example.com`. Prefer `routeUrl()` to encode parameters, and validate untrusted URLs at runtime.
|
|
122
|
+
|
|
123
|
+
The [SSE](./sse.md#client) and [live stream](./live.md#subscribe-from-the-browser) clients accept route URLs and external `http://` or `https://` URLs. Same-page links, `mailto:`, `tel:`, and `ws://` aren't stream destinations.
|
|
124
|
+
|
|
125
|
+
`c.redirect()` also accepts a `URL` or destination object. For a URL from a provider SDK, your CMS, or `public/`, use `as Href` to skip the type check:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { routeUrl, type Href } from '@builtbyfriends/bwf/routes';
|
|
129
|
+
|
|
130
|
+
declare const id: string;
|
|
131
|
+
declare const dynamic: string;
|
|
132
|
+
|
|
133
|
+
c.redirect('/about');
|
|
134
|
+
c.redirect(routeUrl('/users/[id]', { params: { id } }));
|
|
135
|
+
c.redirect({ pathname: '/users/[id]', params: { id } });
|
|
136
|
+
c.redirect('https://example.com/login');
|
|
137
|
+
c.redirect(new URL('https://example.com/login'));
|
|
138
|
+
c.redirect(dynamic as Href);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Cast only URLs you trust. Validate request values such as `?redirectTo=` before redirecting; see [`c.redirect()`](../reference/api/rewrites.md#c-rewrite-destination) for an example.
|
|
142
|
+
|
|
143
|
+
`@builtbyfriends/bwf/routes` exports two types for these strings:
|
|
144
|
+
|
|
145
|
+
- `RouteUrl`: the URL of one of your routes. `routeUrl()` returns it, and `c.rewrite()` accepts it.
|
|
146
|
+
- `Href`: anything `c.redirect()` can point to: a `RouteUrl`, a same-page query or hash, or an external URL.
|
|
147
|
+
|
|
148
|
+
Use these types for URLs you check at runtime:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import type { Href, RouteUrl } from '@builtbyfriends/bwf/routes';
|
|
152
|
+
|
|
153
|
+
c.rewrite(post.path as RouteUrl);
|
|
154
|
+
c.redirect(user.website as Href);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The dev server keeps route types up to date. After changing `routing.typedRoutes`, restart it or run `bwf prepare`. For CI and standalone typechecking, follow [Setup](#setup). See the [API reference](../reference/api/types.md#nosam-routes) for the URL helper and route types.
|
|
158
|
+
|
|
159
|
+
## What Gets Checked
|
|
160
|
+
|
|
161
|
+
| Layer | What's type-checked |
|
|
162
|
+
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
163
|
+
| Database | Table columns, value types, insert/update shapes from Drizzle schema |
|
|
164
|
+
| Handlers | `c.env` bindings, validator input, return type |
|
|
165
|
+
| Fetch client | Route paths, HTTP methods, `body`/`query`/`params`, response type |
|
|
166
|
+
| Navigation | Route patterns and required parameter names and values in `routeUrl()` and destination objects |
|
|
167
|
+
| Rewrites | With `routing.typedRoutes`, URL strings in `c.rewrite()` and SSE and live stream clients |
|
|
168
|
+
| `c.redirect` | With `routing.typedRoutes`, route URLs, same-page queries and hashes, destination objects, `URL` values, and `http://`, `https://`, `mailto:`, and `tel:` literals. A string TypeScript cannot check needs `as Href`. |
|
|
169
|
+
|
|
170
|
+
## Serialization
|
|
171
|
+
|
|
172
|
+
The typed fetch client reflects JSON serialization:
|
|
173
|
+
|
|
174
|
+
| Source type or value | Client type or behavior |
|
|
175
|
+
| --------------------------------------------------- | --------------------------------------------------------------- |
|
|
176
|
+
| `string`, `number`, `boolean`, `null` | unchanged |
|
|
177
|
+
| `Date` | `string` |
|
|
178
|
+
| Arrays and tuples, including readonly types | recursively serialized, preserving tuple shape and readonly |
|
|
179
|
+
| `undefined`, functions, or symbols in an array | `null` |
|
|
180
|
+
| `undefined`, functions, or symbols as object values | property omitted |
|
|
181
|
+
| Symbol-keyed object properties | omitted |
|
|
182
|
+
| `Response` | excluded from the inferred JSON type; passed through at runtime |
|
|
183
|
+
| `bigint` | unsupported by JSON |
|
|
184
|
+
|
|
185
|
+
Object properties whose values may be omitted become optional in the client type. For example, a handler returning `{ label: string | undefined }` produces `{ label?: string }`.
|
|
186
|
+
|
|
187
|
+
## Context Variables
|
|
188
|
+
|
|
189
|
+
Middleware and handlers share typed data through Hono's context variables. Augment `CloudContextVariables` to define your own:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
// middleware/01.auth.ts
|
|
193
|
+
declare module '@builtbyfriends/bwf' {
|
|
194
|
+
interface CloudContextVariables {
|
|
195
|
+
requestId: string;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export default defineMiddleware(async (c, next) => {
|
|
200
|
+
c.set('requestId', crypto.randomUUID());
|
|
201
|
+
await next();
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Now `c.get("requestId")` returns `string` everywhere, with no assertion needed. Multiple augmentations across files are [merged together](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).
|
|
206
|
+
|
|
207
|
+
## Custom Binding Types
|
|
208
|
+
|
|
209
|
+
For native Cloudflare deployments, declare a binding in `bwf.config.ts` to give `c.env` its type. For example, add a [rate limiter](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/):
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
// bwf.config.ts
|
|
213
|
+
import { defineConfig } from '@builtbyfriends/bwf/config';
|
|
214
|
+
|
|
215
|
+
export default defineConfig({
|
|
216
|
+
cloudflare: {
|
|
217
|
+
ratelimits: [
|
|
218
|
+
{ name: 'MY_RATE_LIMITER', namespace_id: '1001', simple: { limit: 10, period: 60 } },
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Run `bwf prepare`, or start the dev server, to use the binding without a type assertion:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import { defineHandler } from '@builtbyfriends/bwf';
|
|
228
|
+
|
|
229
|
+
export const GET = defineHandler(async (c) => {
|
|
230
|
+
const { success } = await c.env.MY_RATE_LIMITER.limit({ key: 'example' });
|
|
231
|
+
return { success };
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Service bindings use `Fetcher`, Durable Objects use `DurableObjectNamespace`, and other bindings use their standard Cloudflare types. For RPC methods or other specialized types, augment `CloudBindings` in a file included by your tsconfig:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import type {} from '@builtbyfriends/bwf';
|
|
239
|
+
|
|
240
|
+
declare module '@builtbyfriends/bwf' {
|
|
241
|
+
interface CloudBindings {
|
|
242
|
+
AUTH: Fetcher & { check(): Promise<boolean> };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Augmentation can refine a generated binding or add one you provide separately. Values declared in `env.ts` keep their schema types. These types apply to bwf's `c.env`; for `cloudflare:workers`, use your framework's binding types.
|
|
248
|
+
|
|
249
|
+
## Setup
|
|
250
|
+
|
|
251
|
+
Extend the generated tsconfig in your project:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"extends": "./.bwf/tsconfig.json",
|
|
256
|
+
"compilerOptions": {
|
|
257
|
+
"target": "ES2022",
|
|
258
|
+
"module": "ES2022",
|
|
259
|
+
"moduleResolution": "bundler",
|
|
260
|
+
"strict": true,
|
|
261
|
+
"jsx": "react-jsx",
|
|
262
|
+
"types": ["@builtbyfriends/bwf/env"]
|
|
263
|
+
},
|
|
264
|
+
"include": ["src", "routes", "middleware", "crons", "queues"]
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
If you already have a TypeScript config, run `bwf init --tsconfig` to add bwf types while preserving your settings.
|
|
269
|
+
|
|
270
|
+
Run `bwf prepare` in CI or after a fresh clone, or let `vite dev` / `vite build` generate the `.bwf/` files during normal app workflows.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Call your API from the client with a typed fetch that checks paths, request bodies, and response types.'
|
|
3
|
+
outline: deep
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Typed Fetch
|
|
7
|
+
|
|
8
|
+
Import `fetch` from `@builtbyfriends/bwf/client` for route autocomplete, checked request bodies, and inferred response types.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { fetch } from '@builtbyfriends/bwf/client';
|
|
14
|
+
|
|
15
|
+
// GET: return type inferred from your handler
|
|
16
|
+
const users = await fetch('/api/users');
|
|
17
|
+
|
|
18
|
+
// POST: body type-checked against your handler's validator
|
|
19
|
+
await fetch('/api/users', {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
body: { name: 'Alice', email: 'alice@example.com' },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Dynamic params interpolated from the route pattern
|
|
25
|
+
const user = await fetch('/api/users/[id]', {
|
|
26
|
+
params: { id: '42' },
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Route patterns use the same brackets as your filenames.
|
|
31
|
+
|
|
32
|
+
## What Gets Type-Checked
|
|
33
|
+
|
|
34
|
+
The client constrains every part of the request:
|
|
35
|
+
|
|
36
|
+
- **Paths:** only routes defined in `routes/` are accepted. Typos fail at compile time.
|
|
37
|
+
- **Methods:** only methods exported from the route file are allowed. If a file only exports `GET`, passing `method: "POST"` is an error.
|
|
38
|
+
- **Body, query, params:** when your handler uses [`defineHandler.withValidator()`](./server-routing.md#validation), validator schemas become the input types and the client enforces them at the call site.
|
|
39
|
+
- **Response type:** the return type matches what your handler returns after [JSON serialization](./type-safety.md#serialization).
|
|
40
|
+
|
|
41
|
+
Omitting `method` sends GET. For a route without a GET handler, specify a supported method, such as `{ method: 'POST' }`.
|
|
42
|
+
|
|
43
|
+
## Query Parameters
|
|
44
|
+
|
|
45
|
+
Pass `query` for GET requests with search parameters:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// routes/api/search.ts
|
|
49
|
+
export const GET = defineHandler.withValidator({
|
|
50
|
+
query: z.object({ q: z.string(), page: z.string().optional() }),
|
|
51
|
+
})((c, { query }) => {
|
|
52
|
+
return { results: [], term: query.q };
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Client: query is type-checked
|
|
56
|
+
const data = await fetch('/api/search', {
|
|
57
|
+
query: { q: 'hello' },
|
|
58
|
+
});
|
|
59
|
+
// data: { results: never[]; term: string }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Error Handling
|
|
63
|
+
|
|
64
|
+
Non-2xx responses throw a `FetchError`:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { fetch, FetchError } from '@builtbyfriends/bwf/client';
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
await fetch('/api/users/[id]', { params: { id: '999' } });
|
|
71
|
+
} catch (e) {
|
|
72
|
+
if (e instanceof FetchError) {
|
|
73
|
+
console.log(e.status); // 404
|
|
74
|
+
console.log(e.data); // parsed response body
|
|
75
|
+
console.log(e.response); // raw Response
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Options
|
|
81
|
+
|
|
82
|
+
| Option | Type | Description |
|
|
83
|
+
| --------- | ------------------------ | ---------------------------------------------------------- |
|
|
84
|
+
| `method` | `string` | HTTP method. Defaults to `"GET"`. |
|
|
85
|
+
| `body` | `object` | Request body (auto-serialized as JSON). |
|
|
86
|
+
| `query` | `Record<string, string>` | Query string parameters. |
|
|
87
|
+
| `params` | `Record<string, string>` | URL path parameters (`[id]` segments). |
|
|
88
|
+
| `headers` | `HeadersInit` | Additional request headers. |
|
|
89
|
+
| `signal` | `AbortSignal` | Abort signal. |
|
|
90
|
+
| `baseURL` | `string` | Base URL prepended to the path. Useful for external calls. |
|
|
91
|
+
| `retry` | `number` | Number of retry attempts (default: 1 for GET). |
|
|
92
|
+
| `timeout` | `number` | Request timeout in milliseconds. |
|
|
93
|
+
|
|
94
|
+
## Server-Side Fetch
|
|
95
|
+
|
|
96
|
+
`fetch()` also works in route handlers. Calls to your app run without an HTTP round-trip.
|
|
97
|
+
|
|
98
|
+
Server-side calls to your app forward the incoming request's `cookie` and `authorization` headers. Explicit headers take precedence. For an external `baseURL`, supply authentication headers explicitly.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 'Send typed messages between the server and connected clients. Each route keeps its state in a Durable Object.'
|
|
3
|
+
outline: deep
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# WebSockets
|
|
7
|
+
|
|
8
|
+
Create a `.ws.ts` route to send typed messages between your server and connected clients. Each route instance has its own Cloudflare Durable Object for shared state. WebSocket routes require the Cloudflare target.
|
|
9
|
+
|
|
10
|
+
For example, `/rooms/[id]` gives each chat room its own instance. Use it for chat, presence, collaborative documents, or notifications.
|
|
11
|
+
|
|
12
|
+
## Route files
|
|
13
|
+
|
|
14
|
+
Create WebSocket routes in `routes/` using `.ws.ts`, `.ws.tsx`, `.ws.js`, `.ws.jsx`, `.ws.mts`, or `.ws.mjs`:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
routes/
|
|
18
|
+
chat/[room].ws.ts
|
|
19
|
+
notifications.ws.ts
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Use `.ws.tsx` or `.ws.jsx` when a handler contains JSX, such as rendering HTML fragments to send to connected clients. See [JSX handlers](./server-routing.md#jsx-handlers) for the JSX runtime.
|
|
23
|
+
|
|
24
|
+
Filename rules match regular server routes:
|
|
25
|
+
|
|
26
|
+
- `index.ws.ts` becomes the parent path
|
|
27
|
+
- `[id].ws.ts` adds a dynamic `[id]` segment
|
|
28
|
+
- `[...slug].ws.ts` becomes a catch-all
|
|
29
|
+
- route groups like `(marketing)/chat.ws.ts` are ignored in the URL
|
|
30
|
+
- `chat.dev.ws.ts` / `chat.prod.ws.ts` restrict the route to one environment
|
|
31
|
+
|
|
32
|
+
Place the environment suffix **before** `.ws`, as in `chat.dev.ws.ts`.
|
|
33
|
+
|
|
34
|
+
## `defineRoom()`
|
|
35
|
+
|
|
36
|
+
Use `defineRoom()` when clients should share a room or document identified by the route.
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineRoom } from '@builtbyfriends/bwf/ws';
|
|
40
|
+
// routes/chat/[room].ws.ts
|
|
41
|
+
import * as v from 'valibot';
|
|
42
|
+
|
|
43
|
+
const ClientMessage = v.variant('type', [
|
|
44
|
+
v.object({ type: v.literal('chat.message'), text: v.string() }),
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
const ServerMessage = v.variant('type', [
|
|
48
|
+
v.object({
|
|
49
|
+
type: v.literal('chat.message'),
|
|
50
|
+
id: v.string(),
|
|
51
|
+
text: v.string(),
|
|
52
|
+
userId: v.string(),
|
|
53
|
+
}),
|
|
54
|
+
v.object({ type: v.literal('chat.joined'), userId: v.string() }),
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
export default defineRoom({
|
|
58
|
+
messages: {
|
|
59
|
+
client: ClientMessage,
|
|
60
|
+
server: ServerMessage,
|
|
61
|
+
},
|
|
62
|
+
onBeforeConnect(ctx) {
|
|
63
|
+
if (!ctx.user) {
|
|
64
|
+
return new Response('Unauthorized', { status: 401 });
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
async onConnect(ctx) {
|
|
68
|
+
await ctx.room.broadcast({ type: 'chat.joined', userId: ctx.user!.id }, [ctx.connection.id]);
|
|
69
|
+
},
|
|
70
|
+
async onMessage(ctx, event) {
|
|
71
|
+
await ctx.room.broadcast({
|
|
72
|
+
type: 'chat.message',
|
|
73
|
+
id: crypto.randomUUID(),
|
|
74
|
+
text: event.text,
|
|
75
|
+
userId: ctx.user!.id,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`defineRoom()` adds room helpers to the hook context:
|
|
82
|
+
|
|
83
|
+
- `ctx.room.broadcast(event, excludeIds?)`
|
|
84
|
+
- `ctx.room.getConnections()`
|
|
85
|
+
- `ctx.room.getConnection(id)`
|
|
86
|
+
- `ctx.connection.send(event)`
|
|
87
|
+
- `ctx.connection.close(code?, reason?)`
|
|
88
|
+
- `ctx.connection.setState(data)`
|
|
89
|
+
|
|
90
|
+
## `defineWebSocket()`
|
|
91
|
+
|
|
92
|
+
Use `defineWebSocket()` when each connection is handled independently instead of as a shared room.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { defineWebSocket } from '@builtbyfriends/bwf/ws';
|
|
96
|
+
// routes/notifications.ws.ts
|
|
97
|
+
import * as v from 'valibot';
|
|
98
|
+
|
|
99
|
+
export default defineWebSocket({
|
|
100
|
+
messages: {
|
|
101
|
+
client: v.object({ type: v.literal('notifications.ack'), id: v.string() }),
|
|
102
|
+
server: v.object({ type: v.literal('notifications.item'), title: v.string() }),
|
|
103
|
+
},
|
|
104
|
+
onBeforeConnect(ctx) {
|
|
105
|
+
if (!ctx.user) {
|
|
106
|
+
return new Response('Unauthorized', { status: 401 });
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
async onConnect(ctx) {
|
|
110
|
+
await ctx.socket.send({ type: 'notifications.item', title: 'Connected' });
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Client
|
|
116
|
+
|
|
117
|
+
Use `connect()` from `@builtbyfriends/bwf/ws` on the client:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { connect } from '@builtbyfriends/bwf/ws';
|
|
121
|
+
|
|
122
|
+
const socket = connect('/chat/[room]', {
|
|
123
|
+
params: { room: 'general' },
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
socket.on('message', (event) => {
|
|
127
|
+
if (event.type === 'chat.message') {
|
|
128
|
+
console.log(event.text);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
socket.send({ type: 'chat.message', text: 'hello' });
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`connect()` resolves relative URLs against the current origin and automatically uses `ws:` or `wss:`. It also buffers messages until the socket opens and reconnects by default.
|
|
136
|
+
|
|
137
|
+
## Typed messages
|
|
138
|
+
|
|
139
|
+
Define schemas for messages sent by the client and server:
|
|
140
|
+
|
|
141
|
+
- `messages.client` validates what the browser may send
|
|
142
|
+
- `messages.server` validates what the server may send
|
|
143
|
+
- `onMessage()` receives the parsed, validated client event
|
|
144
|
+
- `ctx.room.broadcast()`, `ctx.connection.send()`, and `ctx.socket.send()` are typed from `messages.server`
|
|
145
|
+
- `connect()` infers route params, outgoing client messages, and incoming server messages from generated route types
|
|
146
|
+
|
|
147
|
+
Messages are JSON events. Raw string and binary messages are not supported.
|
|
148
|
+
|
|
149
|
+
## Authentication
|
|
150
|
+
|
|
151
|
+
When bwf auth is enabled, every WebSocket hook receives the current user as `ctx.user`, or `null` for an anonymous connection. Use `onBeforeConnect` to reject unauthenticated clients.
|
|
152
|
+
|
|
153
|
+
Connections from another origin are anonymous unless that origin is in your auth `trustedOrigins`. If you read your own cookies from `ctx.request` in `onBeforeConnect`, check its `Origin` header yourself.
|
|
154
|
+
|
|
155
|
+
`ctx.user` is resolved when the socket connects and stays the same for that connection, even if the user later signs out or the session is revoked. For actions that must respect a ban or role change, re-check your own records in `onMessage` and close the connection with `ctx.connection.close()` in rooms or `ctx.socket.close()` in `defineWebSocket()`.
|
|
156
|
+
|
|
157
|
+
## Hooks
|
|
158
|
+
|
|
159
|
+
Both `defineRoom()` and `defineWebSocket()` support:
|
|
160
|
+
|
|
161
|
+
- `onBeforeConnect(ctx)`: return a `Response` to reject the upgrade
|
|
162
|
+
- `onConnect(ctx)`: runs after the socket is accepted
|
|
163
|
+
- `onMessage(ctx, event)`: receives the validated client event
|
|
164
|
+
- `onClose(ctx, details)`: receives `{ code, reason, wasClean }`
|
|
165
|
+
- `onRequest(ctx)`: handles ordinary HTTP requests to the same path
|
|
166
|
+
|
|
167
|
+
bwf completes the WebSocket close handshake automatically. Use `onClose` for application cleanup;
|
|
168
|
+
you do not need to close the socket again in this hook.
|
|
169
|
+
|
|
170
|
+
Every hook receives a context with:
|
|
171
|
+
|
|
172
|
+
- `ctx.id`: deterministic route instance id
|
|
173
|
+
- `ctx.params`: matched route params
|
|
174
|
+
- `ctx.user`: resolved auth user or `null`
|
|
175
|
+
- `ctx.request`: the HTTP request in `onBeforeConnect`, `onConnect`, and `onRequest`. In `onMessage` and `onClose`, it is a placeholder without headers, cookies, or query. To keep request data, save it in `onConnect` with `ctx.connection.setState()` in rooms or `ctx.socket.setState()` in `defineWebSocket()`. Read it later from `ctx.connection.state` or `ctx.socket.state`.
|
|
176
|
+
- `ctx.env`
|
|
177
|
+
- `ctx.storage`
|
|
178
|
+
|
|
179
|
+
If a route does not define `onRequest()`, non-WebSocket requests return `426 Upgrade Required`.
|
|
180
|
+
|
|
181
|
+
## Move a route while keeping its state
|
|
182
|
+
|
|
183
|
+
Before moving a deployed route, run `bwf info`. For `routes/chat/[room].ws.ts`, the output includes:
|
|
184
|
+
|
|
185
|
+
```text
|
|
186
|
+
To preserve this resource when moving its code, add this to 'defineRoom':
|
|
187
|
+
name: "chat-room",
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Add the displayed name to your existing definition:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
export default defineRoom({
|
|
194
|
+
name: 'chat-room',
|
|
195
|
+
messages: { client: ClientMessage, server: ServerMessage },
|
|
196
|
+
// Keep your existing hooks.
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Move the file to `routes/rooms/[room].ws.ts`, update clients to connect to `/rooms/[room]`, and deploy normally. Keep the same parameter names and values: room `general` still uses its existing storage. The Worker class, binding, and migration history stay the same on both Cloudflare and bwf platform deployments.
|
|
201
|
+
|
|
202
|
+
Both `defineRoom()` and `defineWebSocket()` accept optional `name`. Use a static string, inline or in a local `const`. Each route must produce a distinct Worker class; changing the name selects a different resource. If you already moved a route, `bwf info` also shows unmatched identities recorded in `bwf.lock.json`. Identify the original resource before adopting its suggested name; otherwise restore the original source and discover the name there.
|
|
203
|
+
|
|
204
|
+
### Rename a route parameter
|
|
205
|
+
|
|
206
|
+
By default, the instance key includes parameter names. `/chat/[room]` with `room: 'general'` uses `room=general`; a route without parameters uses `default`. Multiple parameters are joined in route order, for example `team=acme&room=general`. If a multi-parameter route has a value containing `&`, its key uses a versioned encoding to keep rooms separate.
|
|
207
|
+
|
|
208
|
+
If you also rename `[room]` to `[id]`, preserve the old key explicitly:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
// routes/rooms/[id].ws.ts
|
|
212
|
+
export default defineRoom({
|
|
213
|
+
name: 'chat-room',
|
|
214
|
+
key: ({ params }) => `room=${params.id}`,
|
|
215
|
+
messages: { client: ClientMessage, server: ServerMessage },
|
|
216
|
+
// Keep your existing hooks.
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Clients now connect to `/rooms/[id]` with `params: { id: 'general' }`. The key remains `room=general`, so storage and `ctx.id` stay the same. Returning only `params.id` would select a different instance.
|
|
221
|
+
|
|
222
|
+
`key` is optional on both WebSocket helpers. It must return a string synchronously and consistently for the same parameters. Preserve the complete old key when migrating multiple parameters. Keep the callback stable after deployment.
|
|
223
|
+
|
|
224
|
+
## Constraints
|
|
225
|
+
|
|
226
|
+
Each socket connects to one route instance. To switch rooms, close the current connection and open another. For publishing to multiple topics, see [Live Event Streams](./live.md).
|
|
227
|
+
|
|
228
|
+
## Deployment
|
|
229
|
+
|
|
230
|
+
WebSocket routes work on Cloudflare and bwf platform deployments. Commit `bwf.lock.json` when bwf adds a binding or migration. Do not delete or reorder deployed migration steps.
|