void 1.11.0 → 1.12.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/dist/{account-cmd-Bbr5cHjm.mjs → account-cmd-BU1Fy_Bf.mjs} +6 -6
- package/dist/{agents-DRo8gzni.mjs → agents-64FnLwxP.mjs} +6 -5
- package/dist/{application-analysis-XyUuNqYA.mjs → application-analysis-DVeN8yoi.mjs} +48 -22
- package/dist/{application-routing-DATqynKH.mjs → application-routing-KKw4Y84h.mjs} +1 -1
- package/dist/{assets-DZBd7yqh.mjs → assets-Br6_BeFJ.mjs} +34 -27
- package/dist/{ast-Cv0JwXqb.mjs → ast-BkPQu7A0.mjs} +5 -1
- package/dist/{auth-BN0NU9dz.mjs → auth-A7cZ8aXA.mjs} +1 -1
- package/dist/{auth-CCk9Seol.mjs → auth-CqwJwItO.mjs} +24 -12
- package/dist/{auth-link-CVxoyU81.mjs → auth-link-Duu2NvN5.mjs} +6 -6
- package/dist/{auth-router-ChXKduRM.mjs → auth-router-vgtOdb9j.mjs} +5 -5
- package/dist/{better-auth-shared-B8W8tZxP.d.mts → better-auth-shared-BS3pDQbT.d.mts} +6 -6
- package/dist/{better-auth-shared-DRHo5FoG.mjs → better-auth-shared-BcqDt-37.mjs} +7 -2
- package/dist/{build-cmd-C3b13rRf.mjs → build-cmd-B7OJ0U5R.mjs} +13 -12
- package/dist/build-id-4IV4hC1-.mjs +13 -0
- package/dist/{cache-B1WzZV60.mjs → cache-wSpi3aeM.mjs} +6 -6
- package/dist/{cancel-deploy-BggXixU_.mjs → cancel-deploy-DMWzkAlb.mjs} +5 -5
- package/dist/{cf-access-Dnyw8KFY.mjs → cf-access-DHklo7Rg.mjs} +41 -23
- package/dist/{cf-access-pejlJmuy.mjs → cf-access-DmkKPcAI.mjs} +0 -8
- package/dist/{cf-build-output-bBx1gDll.mjs → cf-build-output-Cso7Vh-t.mjs} +31 -27
- package/dist/cf-build-output-Wpk_e5CI.mjs +1 -0
- package/dist/{cf-command-values-Ccl-zRhl.mjs → cf-command-values-5BPBRc9Z.mjs} +1 -1
- package/dist/cf-config-migrate-D271BTiw.mjs +1664 -0
- package/dist/{cf-worker-settings-CARs4Wy9.mjs → cf-worker-settings-BBdlhm9U.mjs} +1 -1
- package/dist/cli/cli.mjs +1 -1
- package/dist/cli/cloudflare-operation-process.mjs +17 -14
- package/dist/cli/db-execute-process.d.mts +2 -0
- package/dist/cli/db-execute-process.mjs +57 -0
- package/dist/cli/env-schema-probe.d.mts +3 -1
- package/dist/cli/env-schema-probe.mjs +7 -8
- package/dist/{cli-main-DW09sVsT.mjs → cli-main-BrChcpE3.mjs} +152 -405
- package/dist/{client-DF6U7KLP.mjs → client-DE2m2ldh.mjs} +186 -17
- package/dist/{client-DGfZTE4V.mjs → client-eLZwqkPH.mjs} +1 -1
- package/dist/{cloudflare-auth-pNvmT6kL.mjs → cloudflare-auth-eWfhdZCk.mjs} +1 -1
- package/dist/{cloudflare-cmd-BOhToob3.mjs → cloudflare-cmd-SsFlJe2B.mjs} +7 -8
- package/dist/{cloudflare-config-D1dMHbvz.mjs → cloudflare-config-D9UFH_A5.mjs} +2 -2
- package/dist/{cloudflare-connect-DTrsIBAa.mjs → cloudflare-connect-BgpHcSg3.mjs} +3 -3
- package/dist/{cloudflare-operations-DmqtzoX4.mjs → cloudflare-operations-BIRQkYwL.mjs} +26 -28
- package/dist/cloudflare-operations-ByjFGats.mjs +1 -0
- package/dist/cloudflare-process-60r4Z2Zf.mjs +671 -0
- package/dist/cloudflare-user-output-CCR99eQY.mjs +19 -0
- package/dist/collect-B6nlSnsb.mjs +1 -0
- package/dist/{collect-C6Blu9yw.mjs → collect-rNLybAnF.mjs} +3 -3
- package/dist/{config-Do7gJI3T.mjs → config-BFX5ZB1J.mjs} +5 -4
- package/dist/{config-CeZd67L0.mjs → config-BSoW3QCB.mjs} +5 -5
- package/dist/{config-DYW2TBgz.d.mts → config-DA6ZbLXO.d.mts} +1 -1
- package/dist/{config-dMSpL-ml.mjs → config-DtjrUtPo.mjs} +1 -1
- package/dist/{config-BmvqLnbi.mjs → config-Dv5jri1-.mjs} +4 -4
- package/dist/config-entry.d.mts +1 -1
- package/dist/{connect-B3bKxRzX.mjs → connect-D0V0o40j.mjs} +9 -9
- package/dist/{create-project-DLUlxmf5.mjs → create-project-8FdN6D2i.mjs} +7 -6
- package/dist/{create-project-By7ymK7F.mjs → create-project-CbuDH5Hv.mjs} +1 -1
- package/dist/{db-3qsP21pH.mjs → db-BNPIjLkK.mjs} +1450 -154
- package/dist/db-args-BvMwAber.mjs +1 -0
- package/dist/db-args-CiQVg8SJ.mjs +321 -0
- package/dist/db-seed-loader-Bcz_SutQ.mjs +253 -0
- package/dist/{db-types-DC7KJLx2.mjs → db-types-B4Cf9dzR.mjs} +1 -1
- package/dist/{delete-HbFqgEFC.mjs → delete-WtLEfap2.mjs} +6 -6
- package/dist/{deploy-2QjsBEGw.mjs → deploy-BgSbagIP.mjs} +218 -553
- package/dist/deploy-Do6FWqon.mjs +2 -0
- package/dist/{deploy-managed-static-JoNP3cec.mjs → deploy-managed-static-BWBsxOww.mjs} +115 -194
- package/dist/deploy-security-notice-IRGy6Edf.mjs +192 -0
- package/dist/{deploy-transport-QAkhJYRI.mjs → deploy-transport-BKP_oV9q.mjs} +4 -4
- package/dist/deploy.mjs +9 -9
- package/dist/{dev-inbox-BiamQEAa.mjs → dev-inbox-ClVjKEHy.mjs} +1 -1
- package/dist/direct-r2-upload-DFXLWfXV.mjs +204 -0
- package/dist/discover-D2KGP3cR.mjs +1 -0
- package/dist/{discover-Vd18lHsj.mjs → discover-IcspacCg.mjs} +1 -1
- package/dist/{dispatch-BlOYh1Vc.mjs → dispatch-DIhDA3NI.mjs} +11 -10
- package/dist/{dist-Cp4b1_T9.mjs → dist-C47zy_kJ.mjs} +1 -1
- package/dist/{dist-STQXl8ck.mjs → dist-Cr_xGE_K.mjs} +73 -38
- package/dist/{domain-COkVSfII.mjs → domain-mweyYXSw.mjs} +8 -10
- package/dist/{dotenv-CEI8hapP.mjs → dotenv-BG6RQavH.mjs} +2 -2
- package/dist/{drizzle-BXVOa6Jg.mjs → drizzle-BJDMPrj7.mjs} +3 -4
- package/dist/{drizzle-CvSGrvdl.mjs → drizzle-CQ5jWuDL.mjs} +1 -1
- package/dist/{email-Dj02fLgQ.mjs → email-DcQNP40O.mjs} +33 -30
- package/dist/{email-cloudflare-DDknDAgp.mjs → email-cloudflare-DeYH3Ke7.mjs} +29 -38
- package/dist/{email-pattern-BYr-EFq5.mjs → email-pattern-bRna9MOJ.mjs} +2 -2
- package/dist/{entry-DMgR7XOf.mjs → entry-Bwb9ev8K.mjs} +13 -10
- package/dist/{env-BA7e5yzp.mjs → env-DaAoYR2-.mjs} +8 -8
- package/dist/{env-UqS-21xi.mjs → env-EjHqc7m9.mjs} +1 -1
- package/dist/{env-types-WEZw5D-r.mjs → env-types-D2hBodXP.mjs} +2 -19
- package/dist/{env-validation-DfJ9Fzfa.mjs → env-validation-D-v5_CWL.mjs} +13 -13
- package/dist/{env-validation-ly_Q9Kgd.mjs → env-validation-j9pjCDfA.mjs} +1 -1
- package/dist/{error-pages-QNeBXiRR.mjs → error-pages-GORL6F_e.mjs} +1 -1
- package/dist/{fetch-CbI6lNnk.d.mts → fetch-CczQyIed.d.mts} +1 -1
- package/dist/{fetch-DdK9eGin.mjs → fetch-CiEsvjpP.mjs} +1 -1
- package/dist/{fetch-stream-DQAavFdm.mjs → fetch-stream-BIG5lHW6.mjs} +3 -4
- package/dist/{fetch-stream-DoED9atq.d.mts → fetch-stream-DRX8-83b.d.mts} +2 -2
- package/dist/{gen-EMpnzNGz.mjs → gen-aOtHhZLD.mjs} +21 -18
- package/dist/gen-vhBDHs3q.mjs +1 -0
- package/dist/{generate-BOp1g1H_.mjs → generate-C3ZAqCy-.mjs} +1 -1
- package/dist/{generate-CWb8aOsm.mjs → generate-Dq2Bgw75.mjs} +6 -6
- package/dist/{git-metadata-Cukp5kV5.mjs → git-metadata-BEokJ6US.mjs} +1 -1
- package/dist/{github-cmd-8bXgJNAQ.mjs → github-cmd-BR19Ffdz.mjs} +14 -9
- package/dist/{handler-w_FAiIRu.mjs → handler-DCrDLzw2.mjs} +3 -3
- package/dist/has-own-key-D9QEnAkF.mjs +5 -0
- package/dist/{head-0o0QoREY.mjs → head-BwQ5kgqt.mjs} +5 -4
- package/dist/{head-CVO92KEx.d.mts → head-fUp8n_QJ.d.mts} +9 -4
- package/dist/{headers-BjgvlY29.mjs → headers-DqBsjDxg.mjs} +7 -7
- package/dist/{help-DCQKp3Kp.mjs → help-DvClCzqL.mjs} +138 -60
- package/dist/help-fKPzcTJv.mjs +1 -0
- package/dist/{inbound-BHt4dIlL.d.mts → inbound-CwgZSqFI.d.mts} +9 -3
- package/dist/{inbound--OF7zkwX.mjs → inbound-feMn1Rxx.mjs} +7 -7
- package/dist/{index-CmqHYj2R.d.mts → index-8cAgNdb6.d.mts} +1 -1
- package/dist/{index-BTmhCDbw.d.mts → index-BQ5qYiAw.d.mts} +2 -2
- package/dist/{index-BESZTC1z.d.mts → index-BYcWajVp.d.mts} +2 -1
- package/dist/{index-BXdP39qx.d.mts → index-Dn2mkPr2.d.mts} +24 -23
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +344 -637
- package/dist/{info--jdAIsJN.mjs → info-P6MBiVJi.mjs} +4 -4
- package/dist/{init-BLZvktk_.mjs → init-C8YpkGIP.mjs} +124 -345
- package/dist/installed-packages-tfmYd-cC.mjs +198 -0
- package/dist/{isr-config-Czzb4mIq.mjs → isr-config-DiTnL9Tb.mjs} +5 -5
- package/dist/{link-DPJ4jN7y.mjs → link-Dyz9IGcM.mjs} +7 -7
- package/dist/{list-B-au6xJt.mjs → list-VGYBMjmx.mjs} +11 -7
- package/dist/{live-DvtxTUhW.mjs → live-dvGThbwy.mjs} +14 -17
- package/dist/{load-user-env-BltIJLtl.mjs → load-user-env-B8qC0Q2Y.mjs} +1 -1
- package/dist/{local-d1-C6xn26Nl.mjs → local-d1-CYOYkVwO.mjs} +3 -3
- package/dist/{login-p1_BMgXg.mjs → login-CWFr-G2I.mjs} +8 -6
- package/dist/login-DECm3e9b.mjs +1 -0
- package/dist/{logs-UNH3vQeX.mjs → logs-kS1wuR4b.mjs} +9 -9
- package/dist/{migrate-9dlt6Mxu.mjs → migrate-BNZL1hee.mjs} +9 -10
- package/dist/migrate-C9aoWLvY.mjs +1 -0
- package/dist/{migrations-Cbns2RAm.mjs → migrations-CUHhX65Y.mjs} +5 -5
- package/dist/{mime-BGoZ8ZLL.mjs → mime-Btw9R3CC.mjs} +26 -12
- package/dist/module-references-DWQmO6TW.mjs +27 -0
- package/dist/mysql-lock-D8xtnI-D.mjs +145 -0
- package/dist/mysql-sql-BIE7bc4Z.mjs +124 -0
- package/dist/nitro.d.mts +3 -0
- package/dist/nitro.mjs +14 -5
- package/dist/{node-DqkiQujF.mjs → node-DVJWfV6s.mjs} +6 -6
- package/dist/{operator-ai-logging-BQ6mOgQs.mjs → operator-ai-logging-DD0n6zc2.mjs} +11 -10
- package/dist/operator-args-nvetCWuz.mjs +1499 -0
- package/dist/{operator-auth-CD3pap65.mjs → operator-auth-DMvn-y9X.mjs} +2 -2
- package/dist/{operator-client-XvXTkea6.mjs → operator-client-dFNnXfyB.mjs} +6 -5
- package/dist/operator-cmd-CVfK5U0B.mjs +1 -0
- package/dist/{operator-cmd-CKbZbNKn.mjs → operator-cmd-a7yOf2tH.mjs} +33 -13
- package/dist/operator-security-D5MToU0p.mjs +263 -0
- package/dist/{output-Bc8ixgPF.mjs → output-BZLnu0z8.mjs} +13 -3
- package/dist/output-D7K9TWIA.mjs +1 -0
- package/dist/{package-json-DvS6IFRv.mjs → package-json-4xUI3xLz.mjs} +1 -1
- package/dist/pages/client.d.mts +53 -30
- package/dist/pages/client.mjs +168 -38
- package/dist/pages/head.d.mts +1 -1
- package/dist/pages/head.mjs +1 -1
- package/dist/pages/index.d.mts +8 -2
- package/dist/pages/index.mjs +283 -13
- package/dist/pages/islands-plugin.d.mts +26 -8
- package/dist/pages/islands-plugin.mjs +61 -22
- package/dist/pages/protocol.d.mts +2 -2
- package/dist/pages/protocol.mjs +1 -1
- package/dist/pages/serialize.mjs +1 -1
- package/dist/{pgpass-CEtnBOZO.mjs → pgpass-BLPoYN9_.mjs} +3 -2
- package/dist/platform-args-CMwMoiLp.mjs +1 -0
- package/dist/{platform-args-DQSMW4EP.mjs → platform-args-CvZSuhYS.mjs} +37 -9
- package/dist/{platform-auth-config-D80AKe72.mjs → platform-auth-config-CpszX-Ne.mjs} +26 -23
- package/dist/{platform-auth-protection-k1Ox-u9T.mjs → platform-auth-protection-DA6Tw8Og.mjs} +10 -10
- package/dist/{platform-auth-recovery-D-hKehPy.mjs → platform-auth-recovery-Cztrb1JC.mjs} +11 -9
- package/dist/{platform-cmd-DQ0Wi61H.mjs → platform-cmd-m6Asj6nO.mjs} +11 -11
- package/dist/{platform-cmd-Dtz5lw7R.mjs → platform-cmd-u1j88ggF.mjs} +1 -1
- package/dist/{platform-discovery-B0eZjZ3B.mjs → platform-discovery-CLxtixHJ.mjs} +1 -1
- package/dist/{platform-domain-BMGS4l74.mjs → platform-domain-DJSznNTA.mjs} +14 -10
- package/dist/{platform-lifecycle-y4AfmC7M.mjs → platform-lifecycle-BC-9p58d.mjs} +1 -1
- package/dist/{platform-lifecycle-BCkNQNsQ.mjs → platform-lifecycle-GFeXv3NC.mjs} +802 -207
- package/dist/platform-management-BwHkz46V.mjs +1 -0
- package/dist/{platform-management-Cj2aXFqD.mjs → platform-management-DX1zINou.mjs} +227 -58
- package/dist/{platform-plans-config-CrUUzEl9.mjs → platform-plans-config-DiydtNKY.mjs} +112 -35
- package/dist/{platform-recovery-DKZnALHI.mjs → platform-recovery-CnzBbudV.mjs} +5 -5
- package/dist/{platform-registry-DZ_2Xuqd.mjs → platform-registry-DHH6fivm.mjs} +6 -5
- package/dist/{platform-setup-CKmSEb1J.mjs → platform-setup-Lph9i-rh.mjs} +26 -12
- package/dist/{plugin-inference-B_urWd5Z.mjs → plugin-inference-COlq96WJ.mjs} +28 -53
- package/dist/prepare-DcwigRUS.mjs +1 -0
- package/dist/{prepare-CU7SZieQ.mjs → prepare-WvijE289.mjs} +3 -3
- package/dist/{prepare-vCdm5moJ.mjs → prepare-co1o1FFd.mjs} +12 -12
- package/dist/{project-cmd-B4cgPSi4.mjs → project-cmd-BWJTplpc.mjs} +30 -24
- package/dist/{project-CLwxcEdq.mjs → project-dh9431bN.mjs} +2 -2
- package/dist/{project-paths-CUhCPMpK.mjs → project-paths-2ENfCCih.mjs} +4 -3
- package/dist/project-security-BV1xfj1K.mjs +1 -0
- package/dist/project-security-CY_aahvW.mjs +1340 -0
- package/dist/{project-team-BdX6anO3.mjs → project-team-BlIFXlmT.mjs} +8 -8
- package/dist/{project-token-C1rcq8Xb.mjs → project-token-CMsB7I1-.mjs} +6 -6
- package/dist/{project-tsconfig-MyRJgufB.mjs → project-tsconfig-BOA4ym99.mjs} +25 -5
- package/dist/{project-DVsTAWFh.mjs → project-uXKua1it.mjs} +1 -1
- package/dist/project-zero-trust-BI6pdpx4.mjs +210 -0
- package/dist/{protocol-W5EQcIzN.mjs → protocol-4rEnumif.mjs} +15 -8
- package/dist/{protocol-BlAiF-hc.d.mts → protocol-ERy-n3jf.d.mts} +7 -4
- package/dist/{provision-DWnnKdT-.mjs → provision-Bh44omGA.mjs} +30 -22
- package/dist/{provision-CGI-T0mq.mjs → provision-DFv7SJDn.mjs} +1 -1
- package/dist/{public-B80SwOFp.d.mts → public-DB9C2Cy_.d.mts} +5 -2
- package/dist/{raw-7pQirZpQ.mjs → raw-5rak34QN.mjs} +2 -1
- package/dist/{redirect-Dqb4fEc5.mjs → redirect-Dyvuil0Q.mjs} +6 -3
- package/dist/{requests-D6MaLS_Y.mjs → requests-CfmJxNYg.mjs} +6 -6
- package/dist/{resolve-project-Da3OgCU1.mjs → resolve-project-8WZ3iVmr.mjs} +3 -3
- package/dist/resolve-project-YsTH-U9I.mjs +1 -0
- package/dist/{rollback-Bs8I8PF8.mjs → rollback-DL5HuAsM.mjs} +16 -7
- package/dist/route-types-CSed9-Dp.mjs +435 -0
- package/dist/{route-url-BBdkU7rb.mjs → route-url-B41eQ8QI.mjs} +1 -1
- package/dist/{route-url-Di1kB8D_.d.mts → route-url-Bd6IX-JZ.d.mts} +2 -1
- package/dist/routes-stub.d.mts +1 -1
- package/dist/routes-stub.mjs +1 -1
- package/dist/{runner-CTk21HrO.mjs → runner-Bf94YVJK.mjs} +1 -1
- package/dist/{runner-CMZb7jNU.mjs → runner-CeguHWJx.mjs} +3 -2
- package/dist/{runner-mysql-CJ-HyqxV.mjs → runner-mysql-D549vGGm.mjs} +14 -9
- package/dist/{runner-mysql-C_PrAUTm.mjs → runner-mysql-DOjbj-N1.mjs} +1 -1
- package/dist/{runner-pg-mYc75KfH.mjs → runner-pg-Buzw17hl.mjs} +1 -1
- package/dist/{runner-pg-2pjltt0t.mjs → runner-pg-DMJquR3d.mjs} +1 -1
- package/dist/runtime/ai/index.mjs +2 -2
- package/dist/runtime/auth/better-auth-d1.d.mts +1 -1
- package/dist/runtime/auth/better-auth-d1.mjs +2 -2
- package/dist/runtime/auth/better-auth-mysql.d.mts +1 -1
- package/dist/runtime/auth/better-auth-mysql.mjs +2 -2
- package/dist/runtime/auth/better-auth-postgres.d.mts +1 -1
- package/dist/runtime/auth/better-auth-postgres.mjs +3 -3
- package/dist/runtime/client/fetch-server.d.mts +1 -1
- package/dist/runtime/client/fetch-server.mjs +2 -2
- package/dist/runtime/client/fetch-stream.d.mts +2 -2
- package/dist/runtime/client/fetch-stream.mjs +1 -1
- package/dist/runtime/client/fetch.d.mts +1 -1
- package/dist/runtime/client/fetch.mjs +1 -1
- package/dist/runtime/client/index.d.mts +2 -2
- package/dist/runtime/client/index.mjs +2 -2
- package/dist/runtime/client/react.d.mts +2 -2
- package/dist/runtime/client/react.mjs +2 -2
- package/dist/runtime/client/solid.d.mts +2 -2
- package/dist/runtime/client/solid.mjs +2 -2
- package/dist/runtime/client/svelte.d.mts +2 -2
- package/dist/runtime/client/svelte.mjs +2 -2
- package/dist/runtime/client/vue.d.mts +2 -2
- package/dist/runtime/client/vue.mjs +2 -2
- package/dist/runtime/db/index.d.mts +1 -1
- package/dist/runtime/db/index.mjs +3 -3
- package/dist/runtime/db/migrations/mysql-handler.mjs +2 -1
- package/dist/runtime/db/migrations/postgres-handler.mjs +1 -1
- package/dist/runtime/db/session.d.mts +1 -1
- package/dist/runtime/db/session.mjs +1 -1
- package/dist/runtime/durable/index.mjs +7 -5
- package/dist/runtime/email/index.d.mts +1 -1
- package/dist/runtime/email/index.mjs +14 -11
- package/dist/runtime/email/testing.d.mts +1 -1
- package/dist/runtime/email/testing.mjs +4 -4
- package/dist/runtime/env/public-client.d.mts +4 -1
- package/dist/runtime/env/public.d.mts +1 -1
- package/dist/runtime/env/public.mjs +2 -2
- package/dist/runtime/env/runtime.mjs +1 -1
- package/dist/runtime/handler/index.d.mts +1 -1
- package/dist/runtime/handler/index.mjs +1 -1
- package/dist/runtime/handler/validator.d.mts +1 -1
- package/dist/runtime/handler/validator.mjs +1 -1
- package/dist/runtime/isr/index.mjs +1 -1
- package/dist/runtime/kv/index.mjs +1 -1
- package/dist/runtime/live/client.d.mts +2 -2
- package/dist/runtime/live/client.mjs +7 -7
- package/dist/runtime/live/index.d.mts +1 -1
- package/dist/runtime/live/index.mjs +1 -1
- package/dist/runtime/live/server.mjs +3 -3
- package/dist/runtime/queues/index.mjs +2 -2
- package/dist/runtime/remote/index.d.mts +5 -1
- package/dist/runtime/remote/index.mjs +10 -9
- package/dist/runtime/routing/index.d.mts +11 -12
- package/dist/runtime/routing/index.mjs +69 -65
- package/dist/runtime/routing/route-url.d.mts +1 -1
- package/dist/runtime/routing/route-url.mjs +1 -1
- package/dist/runtime/sandbox/index.d.mts +1 -1
- package/dist/runtime/sandbox/index.mjs +2 -2
- package/dist/runtime/sse/client.d.mts +1 -1
- package/dist/runtime/sse/index.mjs +1 -1
- package/dist/runtime/storage/index.mjs +1 -1
- package/dist/runtime/ws/index.d.mts +1 -1
- package/dist/runtime/ws/index.mjs +3 -2
- package/dist/runtime/ws/room.d.mts +1 -1
- package/dist/runtime/ws/room.mjs +2 -2
- package/dist/runtime/ws/server.d.mts +2 -2
- package/dist/runtime/ws/server.mjs +1 -1
- package/dist/{runtime-zDDinDI5.mjs → runtime-C_VPIJBF.mjs} +1 -1
- package/dist/{scan-LjuG3vfA.mjs → scan-Ct_SEzH4.mjs} +36 -29
- package/dist/{secret-DdUs8AuR.mjs → secret-C-WBaUSS.mjs} +11 -10
- package/dist/security-api-types-CU7zQtr_.mjs +9 -0
- package/dist/security-sarif-ClyYwtAW.mjs +123 -0
- package/dist/{serialize-Pf-CIQK_.mjs → serialize-BmB4BfKu.mjs} +1 -1
- package/dist/{server-CfUbeOjx.mjs → server-T-4mn8zy.mjs} +5 -4
- package/dist/{session-Cw8-b8Um.mjs → session-BT8XDkvL.mjs} +1 -1
- package/dist/{session-DgNrdNh_.d.mts → session-ouZYD7zb.d.mts} +1 -1
- package/dist/{skills-B40svMBE.mjs → skills-C-csz78e.mjs} +3 -3
- package/dist/{sse-BXnTfcf3.mjs → sse-D3ab0YQT.mjs} +16 -13
- package/dist/{static-exports-DFkzL-NX.mjs → static-exports-s7P86Ngp.mjs} +3 -3
- package/dist/{subcommand-prompt-D-m3Umap.mjs → subcommand-prompt-B4LOLosl.mjs} +31 -21
- package/dist/sveltekit.mjs +1 -1
- package/dist/{terminal-log-text-DNsWJREL.mjs → terminal-log-text-CfS2JKM6.mjs} +1 -1
- package/dist/{url-DaehRGKR.mjs → url-DBQluotE.mjs} +4 -1
- package/dist/validate-CZYUIfR-.mjs +1 -0
- package/dist/{validate-Ddzl-IwT.mjs → validate-CtBWCzez.mjs} +7 -4
- package/dist/{validator-Duafcnh7.mjs → validator-Dfh9kCDm.mjs} +5 -5
- package/dist/{version-metadata-k6KFiyWt.mjs → version-metadata-DqgLa6gc.mjs} +1 -1
- package/dist/{wrangler-v2BmVchV.mjs → wrangler-DVe5KV5G.mjs} +49 -46
- package/dist/wrangler-Dq269bjx.mjs +1 -0
- package/dist/{wrapper-eh6MpBZA.mjs → wrapper-CcMYpOS8.mjs} +45 -171
- package/docs/guide/app-types.md +1 -1
- package/docs/guide/auth.md +2 -16
- package/docs/guide/database.md +2 -0
- package/docs/guide/email/domains.md +1 -1
- package/docs/guide/email/sending.md +18 -1
- package/docs/guide/jobs.md +1 -1
- package/docs/guide/pages-routing/actions-and-forms.md +40 -19
- package/docs/guide/pages-routing/errors.md +3 -1
- package/docs/guide/pages-routing/head.md +20 -2
- package/docs/guide/pages-routing/overview.md +20 -0
- package/docs/guide/platform/administration/plans.md +13 -0
- package/docs/guide/platform/administration/security-audits.md +213 -0
- package/docs/guide/platform/administration/zero-trust.md +7 -1
- package/docs/guide/platform/installation/ci.md +1 -1
- package/docs/guide/platform/installation/credentials.md +23 -20
- package/docs/guide/platform/installation/maintenance.md +11 -5
- package/docs/guide/platform/installation/prerequisites.md +1 -1
- package/docs/guide/platform/installation/uninstall.md +2 -0
- package/docs/guide/platform-administration.md +1 -0
- package/docs/guide/queues.md +1 -1
- package/docs/guide/self-hosted-platform.md +14 -13
- package/docs/guide/type-safety.md +1 -1
- package/docs/integrations/cloudflare.md +3 -1
- package/docs/integrations/frameworks/sveltekit.md +1 -1
- package/docs/reference/api/handlers.md +3 -3
- package/docs/reference/api/pages.md +4 -0
- package/docs/reference/api/types.md +11 -1
- package/docs/reference/cli/database.md +42 -6
- package/docs/reference/cli/deploy.md +5 -1
- package/docs/reference/cli/domains.md +1 -1
- package/docs/reference/cli/platform-config.md +5 -3
- package/docs/reference/cli/platform-installation.md +29 -28
- package/docs/reference/cli/platform-security.md +98 -0
- package/docs/reference/cli/platform-zero-trust.md +6 -3
- package/docs/reference/cli/platform.md +1 -0
- package/docs/reference/cli/project.md +57 -0
- package/docs/reference/cli/setup.md +4 -0
- package/docs/reference/cli.md +3 -1
- package/docs/reference/config.md +2 -2
- package/package.json +30 -27
- package/skills/void/SKILL.md +7 -0
- package/dist/cf-build-output-D3_x71H6.mjs +0 -1
- package/dist/cf-config-migrate-CHtnM3_C.mjs +0 -348
- package/dist/cloudflare-operations-BditDbcd.mjs +0 -1
- package/dist/cloudflare-process-wcnaQ5JG.mjs +0 -392
- package/dist/cloudflare-user-output-zEwuGrEJ.mjs +0 -19
- package/dist/collect-8i0wU63d.mjs +0 -1
- package/dist/deploy-DiFfBu8g.mjs +0 -2
- package/dist/discover-Diq0l6TZ.mjs +0 -1
- package/dist/gen-CuANrEzy.mjs +0 -1
- package/dist/help-7EzLA1qP.mjs +0 -1
- package/dist/login-apwve7WD.mjs +0 -1
- package/dist/migrate-BzRplq7m.mjs +0 -1
- package/dist/mysql-sql-SlpS6OMg.mjs +0 -239
- package/dist/operator-args-BCCohcz3.mjs +0 -722
- package/dist/operator-cmd-D42knxMz.mjs +0 -1
- package/dist/output-D4UOUifX.mjs +0 -1
- package/dist/platform-args-Rgp86xa7.mjs +0 -1
- package/dist/platform-management-CRzeC70H.mjs +0 -1
- package/dist/prepare-C2MTqfFv.mjs +0 -1
- package/dist/project-zero-trust-CS02LrlK.mjs +0 -64
- package/dist/resolve-project-C5wC-Hoi.mjs +0 -1
- package/dist/route-types-CrODgORq.mjs +0 -655
- package/dist/validate-DY1U9rET.mjs +0 -1
- package/dist/wrangler-BPIAJdxA.mjs +0 -1
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { A as confirm, H as outro, K as select, L as log, U as password, X as text$1, tt as isCancel, z as multiselect } from "./dist-
|
|
1
|
+
import { A as confirm, H as outro, K as select, L as log, U as password, X as text$1, tt as isCancel, z as multiselect } from "./dist-Cr_xGE_K.mjs";
|
|
2
2
|
import { a as join, c as resolve, n as dirname } from "./dist-DMYe8CZJ.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { o as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { t as
|
|
3
|
+
import { t as Buffer } from "./node-buffer-D7kgjaDs.mjs";
|
|
4
|
+
import { a as createSpinner, f as formatUrl, g as note, h as import_picocolors, i as cliCommandName, p as getErrorMessage, y as printSuccess } from "./output-BZLnu0z8.mjs";
|
|
5
|
+
import { t as cfAccessHeaders } from "./cf-access-DmkKPcAI.mjs";
|
|
6
|
+
import { _ as resolvePinnedApiBaseUrl, o as createDefaultRunWrangler } from "./provision-Bh44omGA.mjs";
|
|
7
|
+
import { a as platformManagementSetupPage, c as platformSetupLink, d as planWritesDns, i as platformInstallCommandArguments, l as platformSetupPages, n as formatPlatformSetupPlan, o as platformPromptAnswer, r as openPlatformSetupPage, s as platformSetupFieldHelp, t as formatPlatformInstallCommand, u as planCreatesZone } from "./platform-setup-Lph9i-rh.mjs";
|
|
8
|
+
import { o as runCloudflareAuthCommand } from "./cloudflare-auth-eWfhdZCk.mjs";
|
|
9
|
+
import { l as resolveCloudflareOperationArgv } from "./cloudflare-process-60r4Z2Zf.mjs";
|
|
10
|
+
import { S as writePendingInstallationSecrets, a as latestPlatformWorkerCutoverGeneration, c as normalizePlatformApiUrl, d as platformRegistryDirectory, f as platformWorkerSecretUpdateIntentState, h as readPendingInstallationSecrets, m as readInstallationRecoverySecrets, n as assertPlatformInstallationSlugAvailable, o as listInstallationManifests, p as promoteInstallationSecrets, t as acquirePlatformLifecycleLock, v as resolveInstallationManifest, x as writeInstallationManifest, y as savePlatformConnection } from "./platform-registry-DHH6fivm.mjs";
|
|
11
|
+
import { t as hasOwnKey } from "./has-own-key-D9QEnAkF.mjs";
|
|
12
|
+
import { t as ensurePlatformAccessToken } from "./cf-access-DHklo7Rg.mjs";
|
|
11
13
|
import { i as updateProjectWorkerRuntimeLogs, n as assertPlatformRuntimeLogsSupported, r as shouldUpdateProjectWorkerRuntimeLogs } from "./platform-runtime-logs-CdJGnk3f.mjs";
|
|
12
|
-
import { r as assertPlatformStorageSupported, t as parsePlatformArgs } from "./platform-args-
|
|
14
|
+
import { r as assertPlatformStorageSupported, t as parsePlatformArgs } from "./platform-args-CvZSuhYS.mjs";
|
|
13
15
|
import { t as writeFileAtomic } from "./atomic-write-DA6eD1Kp.mjs";
|
|
14
16
|
import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
15
17
|
import { fileURLToPath } from "node:url";
|
|
@@ -26,15 +28,106 @@ import { createDefaultPlanCatalog, parsePlatformPlanCatalog } from "@void/platfo
|
|
|
26
28
|
import { AI_LOGGING_ORPHAN_GRACE_MS, PLAN_AI_LOGGING_SETTING, aiLoggingClearedKey, aiLoggingClearedMarker, aiLoggingKey, isPublishedAiLoggingMode, parseAiLoggingKeyMetadata, parsePlanAiLoggingSettings, planAiLogging, resolveAiLogging } from "@void/platform/ai-logging";
|
|
27
29
|
import { PLATFORM_ADMIN_ASSETS_DIRECTORY, platformDatabaseSchemaDigest, resolvePlatformRuntime } from "@void/platform/installer";
|
|
28
30
|
import { request as request$1 } from "node:https";
|
|
31
|
+
// src/cli/platform-credential-label.ts
|
|
32
|
+
const PLATFORM_RUNTIME_TOKEN_VARIABLE = "VOID_PLATFORM_RUNTIME_CLOUDFLARE_API_TOKEN";
|
|
33
|
+
const PLATFORM_AI_GATEWAY_PERMISSION = "Account → AI Gateway → Edit";
|
|
34
|
+
const PLATFORM_WORKERS_PERMISSION = "Account → Workers → Admin";
|
|
35
|
+
/** For example `management token from CLOUDFLARE_API_TOKEN`. */
|
|
36
|
+
function describePlatformCredential(label) {
|
|
37
|
+
if (label.source === "oauth") return "Cloudflare browser login";
|
|
38
|
+
const kind = credentialKind(label);
|
|
39
|
+
switch (label.source) {
|
|
40
|
+
case "environment": return `${kind} from ${fixVariable(label)}`;
|
|
41
|
+
case "saved": return `${kind} saved on this machine`;
|
|
42
|
+
case "entered": return `${kind} you entered`;
|
|
43
|
+
default: return kind;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What to tell the operator after Cloudflare answered 401 or 403 to one
|
|
48
|
+
* request made with this credential.
|
|
49
|
+
*/
|
|
50
|
+
function platformCredentialHelp(label, status, requestPath) {
|
|
51
|
+
const permission = requestPath ? cloudflarePermissionForPath(requestPath) : void 0;
|
|
52
|
+
if (label.aiGatewayFor) return `${aiGatewayStandIn(label)} ${credentialAdvice(label, status, permission ? [permission] : [])}`;
|
|
53
|
+
if (label.source === "oauth" && permission === "Account → AI Gateway → Edit") return browserLoginAiGatewayHelp();
|
|
54
|
+
return `Void used the ${describePlatformCredential(label)}. ${credentialAdvice(label, status, permission ? [permission] : [])}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One message for every check Cloudflare denied to one credential: the list
|
|
58
|
+
* of missing permissions, then what to do.
|
|
59
|
+
*/
|
|
60
|
+
function formatPlatformCredentialDenials(label, denials) {
|
|
61
|
+
const lines = [...new Set(denials.map((denial) => `- ${denial.permission} (HTTP ${denial.status}${denial.request ? `; ${denial.request}` : ""})`))];
|
|
62
|
+
const help = [];
|
|
63
|
+
if (label.aiGatewayFor) help.push(aiGatewayStandIn(label));
|
|
64
|
+
const rest = label.source === "oauth" ? denials.filter((denial) => denial.permission !== PLATFORM_AI_GATEWAY_PERMISSION) : denials;
|
|
65
|
+
if (rest.length < denials.length) help.push(browserLoginAiGatewayHelp());
|
|
66
|
+
if (rest.some((denial) => denial.status === 401)) help.push(credentialAdvice(label, 401, []));
|
|
67
|
+
const forbidden = [...new Set(rest.filter((denial) => denial.status !== 401).map((denial) => denial.permission))];
|
|
68
|
+
if (forbidden.length > 0) help.push(credentialAdvice(label, 403, forbidden));
|
|
69
|
+
return `Cloudflare denied the ${describePlatformCredential(label)}:\n${lines.join("\n")}\n${help.join(" ")}`;
|
|
70
|
+
}
|
|
71
|
+
/** The Cloudflare permission a request path needs, when Void knows it. */
|
|
72
|
+
function cloudflarePermissionForPath(requestPath) {
|
|
73
|
+
const parts = requestPath.split("?")[0].split("/").filter(Boolean);
|
|
74
|
+
if (parts[0] === "accounts") {
|
|
75
|
+
if (parts.length === 1) return "Account → Account Settings → Read";
|
|
76
|
+
const area = parts[2];
|
|
77
|
+
if (area === "ai-gateway") return PLATFORM_AI_GATEWAY_PERMISSION;
|
|
78
|
+
if (area === "storage" && parts[3] === "kv") return "Account → Workers KV Storage → Edit";
|
|
79
|
+
if (area === "r2") return "Account → Workers R2 Storage → Edit";
|
|
80
|
+
if (area === "queues") return "Account → Queues → Edit";
|
|
81
|
+
if (area === "hyperdrive") return "Account → Hyperdrive → Edit";
|
|
82
|
+
if (area === "workers") return PLATFORM_WORKERS_PERMISSION;
|
|
83
|
+
if (area === "email" && parts[3] === "routing") return "Account → Email Routing Addresses → Edit";
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (parts[0] === "zones") {
|
|
87
|
+
if (parts.length <= 2) return "Zone → Zone → Read";
|
|
88
|
+
const area = parts[2];
|
|
89
|
+
if (area === "workers" && parts[3] === "routes") return "Zone → Workers Routes → Write";
|
|
90
|
+
if (area === "dns_records") return "Zone → DNS → Edit";
|
|
91
|
+
if (area === "purge_cache") return "Zone → Cache Purge → Purge";
|
|
92
|
+
if (area === "custom_hostnames") return "Zone → SSL and Certificates → Edit";
|
|
93
|
+
if (area === "email" && parts[3] === "routing") return parts[4] === "rules" ? "Zone → Email Routing Rules → Edit" : "Zone → Zone Settings → Edit";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function credentialKind(label) {
|
|
97
|
+
return label.role === "runtime" ? "runtime token" : "management token";
|
|
98
|
+
}
|
|
99
|
+
/** The variable that replaces this credential. */
|
|
100
|
+
function fixVariable(label) {
|
|
101
|
+
if (label.role === "runtime") return PLATFORM_RUNTIME_TOKEN_VARIABLE;
|
|
102
|
+
return label.source === "environment" && label.environmentVariable || "CLOUDFLARE_API_TOKEN";
|
|
103
|
+
}
|
|
104
|
+
function credentialAdvice(label, status, permissions) {
|
|
105
|
+
const variable = fixVariable(label);
|
|
106
|
+
const kind = credentialKind(label);
|
|
107
|
+
if (status === 401) return label.source === "oauth" ? "HTTP 401 means the browser login is no longer valid. Run `void cloudflare login` again, or set CLOUDFLARE_API_TOKEN to a management token for this account, then retry." : `HTTP 401 means Cloudflare did not accept the token: it is not valid, has expired, or was replaced. Set ${variable} to a valid ${kind}, then retry.`;
|
|
108
|
+
const missing = permissions.length > 1 ? "the permissions listed above" : permissions[0] ?? "a permission this request needs";
|
|
109
|
+
const them = permissions.length > 1 ? "them" : "it";
|
|
110
|
+
return label.source === "oauth" ? `HTTP 403 means browser login does not grant ${missing}. Set CLOUDFLARE_API_TOKEN to a management token with ${them} for this account, then retry.` : `HTTP 403 means the token works but is missing ${missing}, or is not scoped to this account or zone. Add ${them} to the token in the Cloudflare dashboard (the token value stays the same), or set ${variable} to a ${kind} that has ${them}, then retry.`;
|
|
111
|
+
}
|
|
112
|
+
function aiGatewayStandIn(label) {
|
|
113
|
+
const name = describePlatformCredential(label);
|
|
114
|
+
return label.aiGatewayFor?.source === "oauth" ? `Browser login cannot use AI Gateway, so Void used the ${name} for it. Fix the runtime token (${PLATFORM_RUNTIME_TOKEN_VARIABLE}), or set CLOUDFLARE_API_TOKEN to a management token with ${PLATFORM_AI_GATEWAY_PERMISSION}.` : `Void used the ${name} for AI Gateway. Fix the runtime token.`;
|
|
115
|
+
}
|
|
116
|
+
function browserLoginAiGatewayHelp() {
|
|
117
|
+
return `Browser login cannot use AI Gateway. Set ${PLATFORM_RUNTIME_TOKEN_VARIABLE} to the platform runtime token, or set CLOUDFLARE_API_TOKEN to a management token with ${PLATFORM_AI_GATEWAY_PERMISSION}, then retry.`;
|
|
118
|
+
}
|
|
29
119
|
// src/cli/platform-cloudflare.ts
|
|
30
120
|
var PlatformCloudflareApiError = class extends Error {
|
|
31
121
|
status;
|
|
32
122
|
requestPath;
|
|
33
|
-
|
|
123
|
+
/** The credential Cloudflare rejected, when the client knows it. */
|
|
124
|
+
credential;
|
|
125
|
+
constructor(message, status, requestPath, credential) {
|
|
34
126
|
super(message);
|
|
35
127
|
this.name = "PlatformCloudflareApiError";
|
|
36
128
|
this.status = status;
|
|
37
129
|
this.requestPath = requestPath;
|
|
130
|
+
if (credential) this.credential = credential;
|
|
38
131
|
}
|
|
39
132
|
};
|
|
40
133
|
var PlatformCloudflarePrerequisiteError = class extends PlatformCloudflareApiError {
|
|
@@ -64,39 +157,59 @@ var PlatformWorkerRoutesChangedError = class extends Error {
|
|
|
64
157
|
var PlatformRuntimeTokenEmailPermissionError = class extends Error {
|
|
65
158
|
/** Cloudflare answered HTTP 401 at least once: it did not accept the token. */
|
|
66
159
|
tokenNotValid;
|
|
67
|
-
|
|
160
|
+
/** Each email check Cloudflare denied. */
|
|
161
|
+
denials;
|
|
162
|
+
constructor(message, tokenNotValid, options, denials = []) {
|
|
68
163
|
super(message, options);
|
|
69
164
|
this.name = "PlatformRuntimeTokenEmailPermissionError";
|
|
70
165
|
this.tokenNotValid = tokenNotValid;
|
|
166
|
+
this.denials = denials;
|
|
71
167
|
}
|
|
72
168
|
};
|
|
73
169
|
/** Largest number of pairs or keys one KV bulk request accepts. */
|
|
74
170
|
const KV_BULK_LIMIT = 1e4;
|
|
75
171
|
async function verifyPlatformRuntimeTokenPermissions(client, input) {
|
|
76
|
-
|
|
77
|
-
|
|
172
|
+
const credential = input.credential ?? { role: "runtime" };
|
|
173
|
+
const denials = [];
|
|
174
|
+
let emailDenial;
|
|
175
|
+
const deniedError = () => denials.length === 0 ? emailDenial : new Error(`platform: ${formatPlatformCredentialDenials(credential, [...denials, ...emailDenial?.denials ?? []])}`, { cause: denials[0].error });
|
|
176
|
+
const check = async (permission, action) => {
|
|
177
|
+
try {
|
|
178
|
+
await action();
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof PlatformCloudflareApiError && (error.status === 401 || error.status === 403)) {
|
|
181
|
+
denials.push({
|
|
182
|
+
error,
|
|
183
|
+
permission,
|
|
184
|
+
status: error.status
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
throw deniedError() ?? runtimeTokenPreflightError(permission, error, credential);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
await check("Account → Hyperdrive → Write", () => client.listHyperdriveConfigs(input.accountId));
|
|
192
|
+
if (input.emailZoneId) try {
|
|
193
|
+
await verifyPlatformRuntimeTokenEmailPermissions(client, {
|
|
194
|
+
accountId: input.accountId,
|
|
195
|
+
credential,
|
|
196
|
+
zoneId: input.emailZoneId
|
|
197
|
+
});
|
|
78
198
|
} catch (error) {
|
|
79
|
-
|
|
199
|
+
if (!(error instanceof PlatformRuntimeTokenEmailPermissionError)) throw error;
|
|
200
|
+
emailDenial = error;
|
|
80
201
|
}
|
|
81
|
-
if (input.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!input.zoneId) return;
|
|
86
|
-
const probeUrl = `https://${input.applicationDomain}/.well-known/void/runtime-token-preflight-${randomUUID()}`;
|
|
87
|
-
try {
|
|
88
|
-
await client.request(`/zones/${encodeURIComponent(input.zoneId)}/purge_cache`, {
|
|
202
|
+
if (input.zoneId) {
|
|
203
|
+
const zoneId = input.zoneId;
|
|
204
|
+
const probeUrl = `https://${input.applicationDomain}/.well-known/void/runtime-token-preflight-${randomUUID()}`;
|
|
205
|
+
await check("Zone → Cache Purge → Purge", () => client.request(`/zones/${encodeURIComponent(zoneId)}/purge_cache`, {
|
|
89
206
|
body: JSON.stringify({ files: [probeUrl] }),
|
|
90
207
|
method: "POST"
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
throw runtimeTokenPreflightError("Zone → Cache Purge → Purge", error);
|
|
94
|
-
}
|
|
95
|
-
if (input.customDomains) try {
|
|
96
|
-
await client.request(`/zones/${encodeURIComponent(input.zoneId)}/custom_hostnames?per_page=1`);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
throw runtimeTokenPreflightError("Zone → SSL and Certificates → Edit", error);
|
|
208
|
+
}));
|
|
209
|
+
if (input.customDomains) await check("Zone → SSL and Certificates → Edit", () => client.request(`/zones/${encodeURIComponent(zoneId)}/custom_hostnames?per_page=1`));
|
|
99
210
|
}
|
|
211
|
+
const denied = deniedError();
|
|
212
|
+
if (denied) throw denied;
|
|
100
213
|
}
|
|
101
214
|
/**
|
|
102
215
|
* Shared email setup uses the runtime token after the platform pauses traffic.
|
|
@@ -112,26 +225,34 @@ async function verifyPlatformRuntimeTokenEmailPermissions(client, input) {
|
|
|
112
225
|
["Zone → Email Routing Rules → Edit", `${zone}/email/routing/rules?per_page=5`],
|
|
113
226
|
["Account → Email Routing Addresses → Edit", `/accounts/${encodeURIComponent(input.accountId)}/email/routing/addresses?per_page=5`]
|
|
114
227
|
];
|
|
115
|
-
const
|
|
228
|
+
const denials = [];
|
|
116
229
|
let denial;
|
|
117
230
|
let tokenNotValid = false;
|
|
118
231
|
for (const [permission, path] of probes) try {
|
|
119
232
|
await client.request(path);
|
|
120
233
|
} catch (error) {
|
|
121
234
|
if (error instanceof PlatformCloudflareApiError && (error.status === 401 || error.status === 403)) {
|
|
122
|
-
|
|
235
|
+
denials.push({
|
|
236
|
+
permission,
|
|
237
|
+
status: error.status
|
|
238
|
+
});
|
|
123
239
|
denial ??= error;
|
|
124
240
|
tokenNotValid ||= error.status === 401;
|
|
125
241
|
}
|
|
126
242
|
}
|
|
127
243
|
if (denial) {
|
|
128
|
-
const denied = `Cloudflare denied: ${
|
|
129
|
-
|
|
244
|
+
const denied = `Cloudflare denied: ${denials.map((entry) => entry.permission).join(", ")} (HTTP ${denial.status}).`;
|
|
245
|
+
const name = describePlatformCredential(input.savedToken ? {
|
|
246
|
+
role: "runtime",
|
|
247
|
+
source: "saved"
|
|
248
|
+
} : input.credential ?? { role: "runtime" });
|
|
249
|
+
throw new PlatformRuntimeTokenEmailPermissionError(input.savedToken ? `platform: The ${name} cannot use platform email. ${denied} Void checked this token because VOID_PLATFORM_RUNTIME_CLOUDFLARE_API_TOKEN is not set. If the platform uses a different runtime token, set VOID_PLATFORM_RUNTIME_CLOUDFLARE_API_TOKEN to that token, and Void checks that token instead. Otherwise, check that the zone permissions of the saved token include the email zone ${input.zoneId}. To add a missing permission, edit the token in the Cloudflare dashboard. The token value stays the same. Then run the command again.` : `platform: The ${name} cannot use platform email. ${denied} Check that the token is valid and that its zone permissions include the email zone ${input.zoneId}. To add a missing permission, edit the token in the Cloudflare dashboard. The token value stays the same. Or set VOID_PLATFORM_RUNTIME_CLOUDFLARE_API_TOKEN to a valid token that has these permissions. Then run the command again.`, tokenNotValid, { cause: denial }, denials);
|
|
130
250
|
}
|
|
131
251
|
}
|
|
132
|
-
function runtimeTokenPreflightError(permission, cause) {
|
|
252
|
+
function runtimeTokenPreflightError(permission, cause, credential) {
|
|
133
253
|
const status = cause instanceof PlatformCloudflareApiError ? cause.status : null;
|
|
134
|
-
const
|
|
254
|
+
const name = describePlatformCredential(credential);
|
|
255
|
+
const message = status === 429 ? `Cloudflare rate-limited the check of the ${name} for ${permission} (HTTP 429). Retry shortly; this does not mean the token is missing a permission.` : `Could not complete the check of the ${name} for ${permission}${status === null ? "" : ` (Cloudflare HTTP ${status})`}. Retry the check; this failure does not establish that a permission is missing.`;
|
|
135
256
|
return new Error(`platform: ${message}`, { cause });
|
|
136
257
|
}
|
|
137
258
|
var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
@@ -139,36 +260,46 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
139
260
|
#fetcher;
|
|
140
261
|
#token;
|
|
141
262
|
#aiGatewayClient;
|
|
263
|
+
#credential;
|
|
142
264
|
constructor(token, options) {
|
|
143
265
|
if (!token) throw new Error("platform: CLOUDFLARE_API_TOKEN is required. The installed control plane also uses this scoped token to provision app resources.");
|
|
144
266
|
this.#token = token;
|
|
145
267
|
this.apiBaseUrl = (options?.apiBase ?? resolvePinnedApiBaseUrl()).replace(/\/+$/, "");
|
|
146
268
|
this.#fetcher = options?.fetcher ?? fetch;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
269
|
+
this.#credential = options?.credential;
|
|
270
|
+
if (options?.aiGatewayToken) {
|
|
271
|
+
const aiGatewayCredential = options.aiGatewayCredential ?? { role: "runtime" };
|
|
272
|
+
this.#aiGatewayClient = new PlatformCloudflareClient(options.aiGatewayToken, {
|
|
273
|
+
apiBase: this.apiBaseUrl,
|
|
274
|
+
fetcher: this.#fetcher,
|
|
275
|
+
credential: {
|
|
276
|
+
...aiGatewayCredential,
|
|
277
|
+
aiGatewayFor: this.#credential ?? { role: "management" }
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
151
281
|
}
|
|
152
282
|
/** Keep operator auth for infrastructure; use the existing runtime credential only for AI Gateway. */
|
|
153
|
-
withAiGatewayToken(token) {
|
|
283
|
+
withAiGatewayToken(token, credential) {
|
|
154
284
|
return new PlatformCloudflareClient(this.#token, {
|
|
155
285
|
apiBase: this.apiBaseUrl,
|
|
156
286
|
fetcher: this.#fetcher,
|
|
157
|
-
aiGatewayToken: token
|
|
287
|
+
aiGatewayToken: token,
|
|
288
|
+
...credential ? { aiGatewayCredential: credential } : {},
|
|
289
|
+
...this.#credential ? { credential: this.#credential } : {}
|
|
158
290
|
});
|
|
159
291
|
}
|
|
160
292
|
async request(path, init) {
|
|
161
293
|
return (await this.#requestEnvelope(path, init)).result;
|
|
162
294
|
}
|
|
163
295
|
async #requestEnvelope(path, init) {
|
|
296
|
+
const headers = new Headers(init?.headers);
|
|
297
|
+
if (!headers.has("Accept")) headers.set("Accept", "application/json");
|
|
298
|
+
if (!headers.has("Authorization")) headers.set("Authorization", `Bearer ${this.#token}`);
|
|
299
|
+
if (typeof init?.body === "string" && !headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
164
300
|
const response = await this.#fetcher(`${this.apiBaseUrl}${path}`, {
|
|
165
301
|
...init,
|
|
166
|
-
headers
|
|
167
|
-
Accept: "application/json",
|
|
168
|
-
Authorization: `Bearer ${this.#token}`,
|
|
169
|
-
...typeof init?.body === "string" ? { "Content-Type": "application/json" } : {},
|
|
170
|
-
...init?.headers
|
|
171
|
-
},
|
|
302
|
+
headers,
|
|
172
303
|
signal: init?.signal ?? AbortSignal.timeout(3e4),
|
|
173
304
|
redirect: "manual"
|
|
174
305
|
});
|
|
@@ -181,7 +312,7 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
181
312
|
if (!response.ok || envelope.success !== true || envelope.result === void 0) {
|
|
182
313
|
const details = cloudflareErrorDetails(envelope, response.status);
|
|
183
314
|
const requestPath = path.split("?")[0];
|
|
184
|
-
const error =
|
|
315
|
+
const error = this.#apiError(`Cloudflare API error: ${details} (HTTP ${response.status}; ${init?.method ?? "GET"} ${requestPath}).`, response.status, requestPath);
|
|
185
316
|
const prerequisite = cloudflarePrerequisiteHelp(envelope, response.status, requestPath);
|
|
186
317
|
if (prerequisite) throw new PlatformCloudflarePrerequisiteError(prerequisite, error);
|
|
187
318
|
throw error;
|
|
@@ -191,6 +322,15 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
191
322
|
resultInfo: envelope.result_info
|
|
192
323
|
};
|
|
193
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* An API error that, on 401 or 403, names the credential Cloudflare
|
|
327
|
+
* rejected and how to fix it. The error keeps its class, status and path:
|
|
328
|
+
* callers decide on those.
|
|
329
|
+
*/
|
|
330
|
+
#apiError(message, status, requestPath) {
|
|
331
|
+
const credential = this.#credential && (status === 401 || status === 403) ? this.#credential : void 0;
|
|
332
|
+
return new PlatformCloudflareApiError(credential ? `${message} ${platformCredentialHelp(credential, status, requestPath)}` : message, status, requestPath, credential);
|
|
333
|
+
}
|
|
194
334
|
async listAccounts() {
|
|
195
335
|
const entries = [];
|
|
196
336
|
for (let page = 1;; page++) {
|
|
@@ -209,9 +349,10 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
209
349
|
try {
|
|
210
350
|
result = await this.request(`/accounts/${encodeURIComponent(accountId)}/workers/subdomain`);
|
|
211
351
|
} catch (error) {
|
|
212
|
-
const
|
|
352
|
+
const apiError = error instanceof PlatformCloudflareApiError ? error : void 0;
|
|
353
|
+
const status = apiError?.status ?? null;
|
|
213
354
|
const reason = status === null ? "the request failed" : `HTTP ${status}`;
|
|
214
|
-
const guidance = status === 401 || status === 403 ? "Check your Cloudflare login or API token permissions for this account, then rerun the command." : status === 404 ? `Open ${setupUrl} once to provision your account for Workers automatically, then retry the install.` : "Rerun the command. If the dashboard already shows a subdomain, no Workers onboarding change is needed.";
|
|
355
|
+
const guidance = status === 401 || status === 403 ? apiError?.credential ? platformCredentialHelp(apiError.credential, status, apiError.requestPath) : "Check your Cloudflare login or API token permissions for this account, then rerun the command." : status === 404 ? `Open ${setupUrl} once to provision your account for Workers automatically, then retry the install.` : "Rerun the command. If the dashboard already shows a subdomain, no Workers onboarding change is needed.";
|
|
215
356
|
throw new Error(`platform: Could not read the workers.dev subdomain for account ${accountId} (${reason}). ${guidance}`, { cause: error });
|
|
216
357
|
}
|
|
217
358
|
if (typeof result?.subdomain !== "string" || result.subdomain.trim() === "") throw new Error(`platform: This Cloudflare account does not have a workers.dev subdomain. Open ${setupUrl}, finish Workers onboarding, choose a subdomain, and rerun the command.`);
|
|
@@ -553,6 +694,12 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
553
694
|
body: JSON.stringify({ caching: { disabled: true } })
|
|
554
695
|
});
|
|
555
696
|
}
|
|
697
|
+
async setHyperdriveOriginConnectionLimit(accountId, id, limit) {
|
|
698
|
+
await this.request(`/accounts/${encodeURIComponent(accountId)}/hyperdrive/configs/${encodeURIComponent(id)}`, {
|
|
699
|
+
method: "PATCH",
|
|
700
|
+
body: JSON.stringify({ origin_connection_limit: limit })
|
|
701
|
+
});
|
|
702
|
+
}
|
|
556
703
|
async putKvValue(accountId, namespaceId, key, value) {
|
|
557
704
|
await this.request(`/accounts/${encodeURIComponent(accountId)}/storage/kv/namespaces/${encodeURIComponent(namespaceId)}/values/${encodeURIComponent(key)}`, {
|
|
558
705
|
method: "PUT",
|
|
@@ -602,16 +749,18 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
602
749
|
}), "delete");
|
|
603
750
|
}
|
|
604
751
|
async getKvValue(accountId, namespaceId, key) {
|
|
605
|
-
const
|
|
752
|
+
const path = `/accounts/${encodeURIComponent(accountId)}/storage/kv/namespaces/${encodeURIComponent(namespaceId)}/values/${encodeURIComponent(key)}`;
|
|
753
|
+
const response = await this.#fetcher(`${this.apiBaseUrl}${path}`, {
|
|
606
754
|
headers: { Authorization: `Bearer ${this.#token}` },
|
|
607
755
|
signal: AbortSignal.timeout(3e4)
|
|
608
756
|
});
|
|
609
757
|
if (response.status === 404) return null;
|
|
610
|
-
if (!response.ok) throw
|
|
758
|
+
if (!response.ok) throw this.#apiError(`Cloudflare API error reading the installation manifest (HTTP ${response.status}).`, response.status, path);
|
|
611
759
|
return response.text();
|
|
612
760
|
}
|
|
613
761
|
async putR2Object(accountId, bucketName, key, value) {
|
|
614
|
-
const
|
|
762
|
+
const path = `/accounts/${encodeURIComponent(accountId)}/r2/buckets/${encodeURIComponent(bucketName)}/objects/${encodeR2ObjectKey(key)}`;
|
|
763
|
+
const response = await this.#fetcher(`${this.apiBaseUrl}${path}`, {
|
|
615
764
|
body: value,
|
|
616
765
|
headers: {
|
|
617
766
|
Authorization: `Bearer ${this.#token}`,
|
|
@@ -620,15 +769,16 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
620
769
|
method: "PUT",
|
|
621
770
|
signal: AbortSignal.timeout(3e4)
|
|
622
771
|
});
|
|
623
|
-
if (!response.ok) throw
|
|
772
|
+
if (!response.ok) throw this.#apiError(`Cloudflare API error writing the R2 ownership marker (HTTP ${response.status}).`, response.status, path);
|
|
624
773
|
}
|
|
625
774
|
async getR2Object(accountId, bucketName, key) {
|
|
626
|
-
const
|
|
775
|
+
const path = `/accounts/${encodeURIComponent(accountId)}/r2/buckets/${encodeURIComponent(bucketName)}/objects/${encodeR2ObjectKey(key)}`;
|
|
776
|
+
const response = await this.#fetcher(`${this.apiBaseUrl}${path}`, {
|
|
627
777
|
headers: { Authorization: `Bearer ${this.#token}` },
|
|
628
778
|
signal: AbortSignal.timeout(3e4)
|
|
629
779
|
});
|
|
630
780
|
if (response.status === 404) return null;
|
|
631
|
-
if (!response.ok) throw
|
|
781
|
+
if (!response.ok) throw this.#apiError(`Cloudflare API error reading the R2 ownership marker (HTTP ${response.status}).`, response.status, path);
|
|
632
782
|
return response.text();
|
|
633
783
|
}
|
|
634
784
|
async deleteR2Object(accountId, bucketName, key) {
|
|
@@ -675,7 +825,8 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
675
825
|
for (;;) {
|
|
676
826
|
const query = new URLSearchParams({ per_page: "1000" });
|
|
677
827
|
if (cursor) query.set("cursor", cursor);
|
|
678
|
-
const
|
|
828
|
+
const path = `/accounts/${encodeURIComponent(accountId)}/r2/buckets/${encodeURIComponent(bucketName)}/objects`;
|
|
829
|
+
const response = await this.#fetcher(`${this.apiBaseUrl}${path}?${query}`, {
|
|
679
830
|
headers: {
|
|
680
831
|
Accept: "application/json",
|
|
681
832
|
Authorization: `Bearer ${this.#token}`
|
|
@@ -684,7 +835,10 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
684
835
|
});
|
|
685
836
|
if (response.status === 404) return;
|
|
686
837
|
const envelope = await response.json();
|
|
687
|
-
if (!response.ok || envelope.success !== true || !Array.isArray(envelope.result))
|
|
838
|
+
if (!response.ok || envelope.success !== true || !Array.isArray(envelope.result)) {
|
|
839
|
+
const details = envelope.errors?.map((error) => error.message).filter(Boolean).join(", ") || `HTTP ${response.status}`;
|
|
840
|
+
throw this.#apiError(`Cloudflare API error listing R2 objects: ${details}`, response.status, path);
|
|
841
|
+
}
|
|
688
842
|
const keys = envelope.result.map((object) => requiredString(object.key, "R2 object key")).filter((key) => !preservedKeys.has(key));
|
|
689
843
|
if (keys.length > 0) await beforeDelete?.();
|
|
690
844
|
for (let offset = 0; offset < keys.length; offset += 1e3) await this.deleteR2Objects(accountId, bucketName, keys.slice(offset, offset + 1e3));
|
|
@@ -728,13 +882,13 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
728
882
|
signal: AbortSignal.timeout(3e4)
|
|
729
883
|
});
|
|
730
884
|
if (response.status === 404) return;
|
|
731
|
-
let envelope
|
|
885
|
+
let envelope;
|
|
732
886
|
try {
|
|
733
887
|
envelope = await response.json();
|
|
734
888
|
} catch {
|
|
735
889
|
envelope = { success: response.ok };
|
|
736
890
|
}
|
|
737
|
-
if (!response.ok || envelope.success !== true) throw
|
|
891
|
+
if (!response.ok || envelope.success !== true) throw this.#apiError(`Cloudflare API error: ${cloudflareErrorDetails(envelope, response.status)} (HTTP ${response.status}; DELETE ${path}).`, response.status, path);
|
|
738
892
|
}
|
|
739
893
|
async deleteWorkerRoute(zoneId, routeId) {
|
|
740
894
|
await this.#deleteIfPresent(`/zones/${encodeURIComponent(zoneId)}/workers/routes/${encodeURIComponent(routeId)}`);
|
|
@@ -819,10 +973,10 @@ var PlatformCloudflareClient = class PlatformCloudflareClient {
|
|
|
819
973
|
entries.push(...result);
|
|
820
974
|
if (result.length < 50) break;
|
|
821
975
|
}
|
|
822
|
-
return entries.
|
|
976
|
+
return entries.flatMap((entry) => !(Array.isArray(entry.matchers) ? entry.matchers : []).some((matcher) => matcher?.type === "all") ? [{
|
|
823
977
|
id: requiredString(entry.id ?? entry.tag, "Email Routing rule id"),
|
|
824
978
|
...parseEmailRoutingTarget(entry)
|
|
825
|
-
})
|
|
979
|
+
}] : []);
|
|
826
980
|
}
|
|
827
981
|
async deleteEmailRoutingRule(zoneId, ruleId) {
|
|
828
982
|
await this.#deleteIfPresent(`/zones/${encodeURIComponent(zoneId)}/email/routing/rules/${encodeURIComponent(ruleId)}`);
|
|
@@ -993,16 +1147,16 @@ function parseHyperdriveConfig(value) {
|
|
|
993
1147
|
user: typeof record.user === "string" && record.user ? record.user : null
|
|
994
1148
|
};
|
|
995
1149
|
let parsedOrigin;
|
|
996
|
-
if (record.service_id
|
|
1150
|
+
if (record.service_id !== null && record.service_id !== void 0) {
|
|
997
1151
|
const serviceId = requiredString(record.service_id, "Hyperdrive origin service ID");
|
|
998
|
-
if (record.host
|
|
1152
|
+
if (record.host !== null && record.host !== void 0 || record.port !== null && record.port !== void 0 || record.access_client_id !== null && record.access_client_id !== void 0) throw new Error("platform: Cloudflare Hyperdrive config mixes Workers VPC and host origin fields.");
|
|
999
1153
|
parsedOrigin = {
|
|
1000
1154
|
...database,
|
|
1001
1155
|
serviceId
|
|
1002
1156
|
};
|
|
1003
1157
|
} else {
|
|
1004
1158
|
const accessClientId = typeof record.access_client_id === "string" && record.access_client_id ? record.access_client_id : void 0;
|
|
1005
|
-
const port = accessClientId && record.port
|
|
1159
|
+
const port = accessClientId && (record.port === null || record.port === void 0) ? null : typeof record.port === "number" || typeof record.port === "string" ? Number(record.port) : NaN;
|
|
1006
1160
|
if (port !== null && (!Number.isInteger(port) || port <= 0 || port > 65535)) throw new Error("platform: Cloudflare Hyperdrive config has an invalid origin port.");
|
|
1007
1161
|
parsedOrigin = {
|
|
1008
1162
|
...database,
|
|
@@ -1015,7 +1169,8 @@ function parseHyperdriveConfig(value) {
|
|
|
1015
1169
|
id: requiredString(value.id, "Hyperdrive id"),
|
|
1016
1170
|
name: requiredString(value.name, "Hyperdrive name"),
|
|
1017
1171
|
cachingDisabled: !!value.caching && typeof value.caching === "object" && !Array.isArray(value.caching) && value.caching.disabled === true,
|
|
1018
|
-
origin: parsedOrigin
|
|
1172
|
+
origin: parsedOrigin,
|
|
1173
|
+
...typeof value.origin_connection_limit === "number" && Number.isInteger(value.origin_connection_limit) && value.origin_connection_limit > 0 ? { originConnectionLimit: value.origin_connection_limit } : {}
|
|
1019
1174
|
};
|
|
1020
1175
|
}
|
|
1021
1176
|
// src/cli/platform-access-provision.ts
|
|
@@ -1032,7 +1187,7 @@ function platformAccessIdentityProvider(provider) {
|
|
|
1032
1187
|
const name = provider.name;
|
|
1033
1188
|
return {
|
|
1034
1189
|
id,
|
|
1035
|
-
name: name
|
|
1190
|
+
name: name === null || name === void 0 || typeof name === "string" && !name.trim() ? id : text(name, "identity provider name")
|
|
1036
1191
|
};
|
|
1037
1192
|
}
|
|
1038
1193
|
function ids(value) {
|
|
@@ -1143,7 +1298,7 @@ function platformAccessPublicDestinations(application) {
|
|
|
1143
1298
|
})];
|
|
1144
1299
|
}
|
|
1145
1300
|
function platformAccessOverlapsOrigin(destination, origin) {
|
|
1146
|
-
const pattern = "^" + destination.split("/")[0].split("*").map((part) => part.
|
|
1301
|
+
const pattern = "^" + destination.split("/")[0].split("*").map((part) => part.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)).join(".*") + "$";
|
|
1147
1302
|
return new RegExp(pattern, "i").test(new URL(origin).hostname);
|
|
1148
1303
|
}
|
|
1149
1304
|
/** Whether an application path-covers, or exactly covers, any protected platform origin. */
|
|
@@ -1212,16 +1367,17 @@ async function provisionPlatformAccess(client, input, previous, save) {
|
|
|
1212
1367
|
const inventory = await client.list("apps");
|
|
1213
1368
|
const tokenInventory = input.protection ? await client.list("service_tokens") : [];
|
|
1214
1369
|
if (input.protection?.applicationId && !input.serviceToken) throw new Error("platform: Connecting an existing protection application requires its admitted service token.");
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1370
|
+
const { serviceToken } = input;
|
|
1371
|
+
if (serviceToken) {
|
|
1372
|
+
const token = tokenInventory.find((token) => token.id === serviceToken.id);
|
|
1373
|
+
if (!token || token.client_id !== serviceToken.clientId || token.enabled === false || typeof token.expires_at === "string" && Date.parse(token.expires_at) <= Date.now()) throw new Error("platform: The selected Access service token is unavailable, expired, or belongs to another client.");
|
|
1218
1374
|
const prior = state.resources["service-token"];
|
|
1219
1375
|
state.resources["service-token"] = {
|
|
1220
|
-
id:
|
|
1376
|
+
id: serviceToken.id,
|
|
1221
1377
|
name: text(token.name, "service token name"),
|
|
1222
1378
|
fingerprint: fingerprint({ origins }),
|
|
1223
1379
|
pending: false,
|
|
1224
|
-
adopted: prior?.id ===
|
|
1380
|
+
adopted: prior?.id === serviceToken.id ? prior.adopted : true
|
|
1225
1381
|
};
|
|
1226
1382
|
save(state);
|
|
1227
1383
|
}
|
|
@@ -1399,13 +1555,15 @@ async function provisionPlatformAccess(client, input, previous, save) {
|
|
|
1399
1555
|
const covered = platformAccessPublicDestinations(app);
|
|
1400
1556
|
if (origins.some((origin) => !covered.includes(new URL(origin).hostname))) throw new Error("platform: Access must protect both the API and proxy origins without path exclusions.");
|
|
1401
1557
|
const audience = text(app.aud, "application audience");
|
|
1402
|
-
|
|
1558
|
+
const protection = parsePlatformAccessProtection({
|
|
1403
1559
|
teamDomain: inspected.teamDomain,
|
|
1404
1560
|
applications: origins.map((origin) => ({
|
|
1405
1561
|
origin,
|
|
1406
1562
|
audience
|
|
1407
1563
|
}))
|
|
1408
1564
|
});
|
|
1565
|
+
if (!protection) throw new Error("platform: The Access protection configuration is missing.");
|
|
1566
|
+
output.protection = protection;
|
|
1409
1567
|
output.credentials = Object.fromEntries(origins.map((origin) => [origin, {
|
|
1410
1568
|
CF_ACCESS_CLIENT_ID: service.clientId,
|
|
1411
1569
|
CF_ACCESS_CLIENT_SECRET: service.clientSecret
|
|
@@ -1497,6 +1655,7 @@ async function selectCompanyAccessPolicies(client, initialPolicies, accountId, m
|
|
|
1497
1655
|
placeholder: "example.com",
|
|
1498
1656
|
validate: (value) => companyEmailDomains(value ?? "") ? void 0 : "Enter up to 10 email domains, such as example.com."
|
|
1499
1657
|
})));
|
|
1658
|
+
if (!domains) throw new Error("platform: Enter up to 10 email domains, such as example.com.");
|
|
1500
1659
|
const name = `Emails ending in @${domains[0]}${domains.length > 1 ? ` and ${domains.length - 1} more` : ""}`;
|
|
1501
1660
|
try {
|
|
1502
1661
|
const created = await client.create("policies", {
|
|
@@ -1825,27 +1984,50 @@ async function preparePlatformAccessSetup(input) {
|
|
|
1825
1984
|
return result;
|
|
1826
1985
|
}
|
|
1827
1986
|
// src/cli/platform-auth.ts
|
|
1987
|
+
/** The label of the operator credential, so Cloudflare errors can name it. */
|
|
1988
|
+
function platformOperatorCredentialLabel(credential) {
|
|
1989
|
+
return {
|
|
1990
|
+
role: "management",
|
|
1991
|
+
source: credential.source,
|
|
1992
|
+
...credential.environmentVariable ? { environmentVariable: credential.environmentVariable } : {}
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1828
1995
|
/** Use the selected credential for read-only checks before taking lifecycle locks. */
|
|
1829
1996
|
async function verifyPlatformCloudflareCredential(client, input) {
|
|
1830
|
-
const
|
|
1831
|
-
const
|
|
1832
|
-
const
|
|
1997
|
+
const label = platformOperatorCredentialLabel(input);
|
|
1998
|
+
const name = describePlatformCredential(label);
|
|
1999
|
+
const retry = input.source === "oauth" ? "Run `void cloudflare login`, or set CLOUDFLARE_API_TOKEN for this account, then retry." : `Set ${input.environmentVariable ?? "CLOUDFLARE_API_TOKEN"} for this account, then retry.`;
|
|
2000
|
+
const denials = [];
|
|
2001
|
+
let firstDenial;
|
|
2002
|
+
const deniedError = (denial) => new Error(`platform: ${formatPlatformCredentialDenials(label, denials)}`, { cause: denial });
|
|
2003
|
+
const check = async (what, permission, action, allowMissing = false) => {
|
|
1833
2004
|
try {
|
|
1834
2005
|
await action();
|
|
2006
|
+
return true;
|
|
1835
2007
|
} catch (cause) {
|
|
1836
2008
|
const status = cause instanceof PlatformCloudflareApiError ? cause.status : null;
|
|
1837
|
-
if (status === 404 && allowMissing) return;
|
|
1838
|
-
|
|
1839
|
-
|
|
2009
|
+
if (status === 404 && allowMissing) return true;
|
|
2010
|
+
if (status === 401 || status === 403) {
|
|
2011
|
+
denials.push({
|
|
2012
|
+
permission,
|
|
2013
|
+
request: what,
|
|
2014
|
+
status
|
|
2015
|
+
});
|
|
2016
|
+
firstDenial ??= cause;
|
|
2017
|
+
return false;
|
|
2018
|
+
}
|
|
2019
|
+
const detail = status === 404 ? "Check the bucket name and account scope before retrying." : status === 429 ? "Cloudflare rate-limited this check. Retry shortly." : "Retry the command after Cloudflare connectivity is restored.";
|
|
2020
|
+
if (firstDenial) throw deniedError(firstDenial);
|
|
2021
|
+
throw new Error(`platform: ${what} is unavailable${status === null ? "" : ` (HTTP ${status})`} using the ${name}. ${detail}`, { cause });
|
|
1840
2022
|
}
|
|
1841
2023
|
};
|
|
1842
2024
|
let accounts = [];
|
|
1843
|
-
await check("Cloudflare account access", "Account → Account Settings → Read", async () => {
|
|
2025
|
+
if (await check("Cloudflare account access", "Account → Account Settings → Read", async () => {
|
|
1844
2026
|
accounts = await client.listAccounts();
|
|
1845
|
-
});
|
|
1846
|
-
|
|
1847
|
-
await check(
|
|
1848
|
-
|
|
2027
|
+
}) && !accounts.some((account) => account.id === input.account.id)) throw new Error(`platform: The ${name} cannot access Cloudflare account ${JSON.stringify(input.account.name)} (${input.account.id}). ${retry}`);
|
|
2028
|
+
await check("Cloudflare Workers access", PLATFORM_WORKERS_PERMISSION, () => client.listWorkerNames(input.account.id));
|
|
2029
|
+
for (const bucket of new Set(input.r2Buckets)) await check(`R2 bucket ${JSON.stringify(bucket)}`, "Account → Workers R2 Storage → Edit", () => client.request(`/accounts/${encodeURIComponent(input.account.id)}/r2/buckets/${encodeURIComponent(bucket)}`), input.allowMissingR2Buckets);
|
|
2030
|
+
if (firstDenial) throw deniedError(firstDenial);
|
|
1849
2031
|
}
|
|
1850
2032
|
/** Check Access inventory permissions before the installer starts provisioning. */
|
|
1851
2033
|
async function verifyPlatformManagementAccess(client, accountId, access) {
|
|
@@ -1925,11 +2107,14 @@ async function resolvePlatformCloudflareCredentialWithInput(readInput, dependenc
|
|
|
1925
2107
|
}
|
|
1926
2108
|
}
|
|
1927
2109
|
async function readExistingCredential(dependencies, runWrangler) {
|
|
1928
|
-
const
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2110
|
+
for (const environmentVariable of ["CLOUDFLARE_API_TOKEN", "CF_API_TOKEN"]) {
|
|
2111
|
+
const environmentToken = process.env[environmentVariable]?.trim();
|
|
2112
|
+
if (environmentToken) return {
|
|
2113
|
+
source: "environment",
|
|
2114
|
+
environmentVariable,
|
|
2115
|
+
token: environmentToken
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
1933
2118
|
const savedManagementToken = dependencies.savedManagementToken?.trim();
|
|
1934
2119
|
if (savedManagementToken) return {
|
|
1935
2120
|
source: "saved",
|
|
@@ -1963,7 +2148,7 @@ async function readInputs(client) {
|
|
|
1963
2148
|
catalog = savedCatalog === void 0 || savedCatalog === null ? createDefaultPlanCatalog("custom") : parsePlatformPlanCatalog(savedCatalog);
|
|
1964
2149
|
settings = parsePlanAiLoggingSettings(saved.get(PLAN_AI_LOGGING_SETTING));
|
|
1965
2150
|
} catch (error) {
|
|
1966
|
-
throw new Error(`platform: The saved plan settings are not valid for this platform version, so AI logging settings cannot be published. If a newer platform release saved them, upgrade to that release again. (${error instanceof Error ? error.message : String(error)})
|
|
2151
|
+
throw new Error(`platform: The saved plan settings are not valid for this platform version, so AI logging settings cannot be published. If a newer platform release saved them, upgrade to that release again. (${error instanceof Error ? error.message : String(error)})`, { cause: error });
|
|
1967
2152
|
}
|
|
1968
2153
|
return {
|
|
1969
2154
|
catalog,
|
|
@@ -2387,13 +2572,16 @@ function readPlatformHyperdriveSelection(checkpoint) {
|
|
|
2387
2572
|
}
|
|
2388
2573
|
return parsePlatformHyperdriveSelection(value);
|
|
2389
2574
|
}
|
|
2575
|
+
const nonempty = (value) => typeof value === "string" && value.trim() !== "";
|
|
2390
2576
|
function parsePlatformHyperdriveSelection(value) {
|
|
2391
2577
|
const selected = value;
|
|
2392
|
-
|
|
2393
|
-
|
|
2578
|
+
if (!selected || typeof selected !== "object" || Array.isArray(selected) || !nonempty(selected.id) || !nonempty(selected.user) || selected.name !== void 0 && (typeof selected.name !== "string" || !selected.name) || selected.database !== void 0 && (typeof selected.database !== "string" || !selected.database)) throw new Error("platform: The saved Hyperdrive selection is invalid.");
|
|
2579
|
+
const { host, serviceId } = selected;
|
|
2580
|
+
const origin = serviceId === void 0 && typeof host === "string" && host.trim() !== "" ? { host } : typeof serviceId === "string" && serviceId.trim() !== "" && host === void 0 ? { serviceId } : void 0;
|
|
2581
|
+
if (!origin) throw new Error("platform: The saved Hyperdrive selection is invalid.");
|
|
2394
2582
|
return {
|
|
2395
2583
|
id: selected.id,
|
|
2396
|
-
...
|
|
2584
|
+
...origin,
|
|
2397
2585
|
user: selected.user,
|
|
2398
2586
|
...selected.name ? { name: selected.name } : {},
|
|
2399
2587
|
...selected.database ? { database: selected.database } : {}
|
|
@@ -2521,7 +2709,7 @@ async function startConditionalWorkerCreateProxy(upstreamApiBaseUrl, accountId,
|
|
|
2521
2709
|
const createQuery = [...incomingUrl.searchParams];
|
|
2522
2710
|
const supportedCreateQuery = new Set(createQuery.map(([key]) => key)).size === createQuery.length && createQuery.every(([key, value]) => key === "excludeScript" && value === "true" || key === "bindings_inherit" && value === "strict");
|
|
2523
2711
|
const isConditionalCreate = incoming.method === "PUT" && incomingUrl.pathname === expectedPath && supportedCreateQuery;
|
|
2524
|
-
const isTopLevelWorkerUpload = incoming.method === "PUT" && new RegExp(`^${basePath.
|
|
2712
|
+
const isTopLevelWorkerUpload = incoming.method === "PUT" && new RegExp(`^${basePath.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)}/accounts/[^/]+/workers/scripts/[^/]+$`).test(incomingUrl.pathname);
|
|
2525
2713
|
const isReadOnly = incoming.method === "GET" || incoming.method === "HEAD" || incoming.method === "OPTIONS";
|
|
2526
2714
|
const isAssetUploadSession = incoming.method === "POST" && incomingUrl.pathname === `${expectedPath}/assets-upload-session` && incomingUrl.search === "";
|
|
2527
2715
|
const isAssetUpload = incoming.method === "POST" && state.assetSessionStarted && (incomingUrl.pathname === assetUploadPath && incomingUrl.search === "?base64=true" || incomingUrl.search === "" && incomingUrl.pathname.startsWith(`${assetUploadPath}/`) && /^[0-9a-f]{32}$/.test(incomingUrl.pathname.slice(assetUploadPath.length + 1)));
|
|
@@ -2593,6 +2781,24 @@ async function runPlatformWranglerForConditionalCreate(operation, accountId, cwd
|
|
|
2593
2781
|
return withConditionalPlatformWorkerCreate(accountId, workerName, (apiBaseUrl) => runPlatformWranglerAtApiBase(operation, accountId, cwd, capture, apiBaseUrl, false, apiToken), upstreamApiBaseUrl);
|
|
2594
2782
|
}
|
|
2595
2783
|
// src/cli/platform-plan.ts
|
|
2784
|
+
/** Group denied plan reads by the credential Cloudflare rejected. */
|
|
2785
|
+
function formatPlanDenials(denied) {
|
|
2786
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2787
|
+
for (const error of denied) {
|
|
2788
|
+
const key = error.credential ? JSON.stringify(error.credential) : "";
|
|
2789
|
+
const group = groups.get(key) ?? {
|
|
2790
|
+
label: error.credential,
|
|
2791
|
+
errors: []
|
|
2792
|
+
};
|
|
2793
|
+
group.errors.push(error);
|
|
2794
|
+
groups.set(key, group);
|
|
2795
|
+
}
|
|
2796
|
+
return [...groups.values()].map(({ label, errors }) => label ? formatPlatformCredentialDenials(label, errors.map((error) => ({
|
|
2797
|
+
permission: (error.requestPath ? cloudflarePermissionForPath(error.requestPath) : void 0) ?? "a permission this read needs",
|
|
2798
|
+
request: `GET ${error.requestPath ?? ""}`,
|
|
2799
|
+
status: error.status
|
|
2800
|
+
}))) : [...new Set(errors.map((error) => error.message))].join("\n"));
|
|
2801
|
+
}
|
|
2596
2802
|
async function createPlatformInstallPlan(client, input, existing, options) {
|
|
2597
2803
|
const dashboardUrl = input.dashboardUrl !== void 0 ? normalizePlatformDashboardUrl(input.dashboardUrl) : existing ? existing.deployment.controlPlane.dashboardUrl ?? (existing.endpoints.dashboardUrl ? normalizePlatformDashboardUrl(existing.endpoints.dashboardUrl) : null) ?? platformDashboardUrl(existing.deployment) : null;
|
|
2598
2804
|
const account = resolveAccount(await client.listAccounts(), input.accountId);
|
|
@@ -2629,7 +2835,8 @@ async function createPlatformInstallPlan(client, input, existing, options) {
|
|
|
2629
2835
|
googleOAuth: input.authentication.providers.includes("google")
|
|
2630
2836
|
} : {},
|
|
2631
2837
|
...enableEmail ? { email: true } : {},
|
|
2632
|
-
...input.customDomains ? { customDomains: true } : {}
|
|
2838
|
+
...input.customDomains ? { customDomains: true } : {},
|
|
2839
|
+
...input.securityAudits ? { securityAudits: true } : {}
|
|
2633
2840
|
};
|
|
2634
2841
|
if (capabilities.customDomains && (testing || !input.dedicatedZone)) throw new Error("platform: Custom domains need a dedicated application zone. Install with a domain and --dedicated-zone.");
|
|
2635
2842
|
if (capabilities.email && options?.includeEmailGateway !== false && !enableEmail) throw new Error("platform: Email-enabled installations require VOID_EMAIL_SENDER_DOMAIN and VOID_EMAIL_SHARED_ZONE_ID before deploying this runtime.");
|
|
@@ -2692,6 +2899,14 @@ async function createPlatformInstallPlan(client, input, existing, options) {
|
|
|
2692
2899
|
email: true
|
|
2693
2900
|
}
|
|
2694
2901
|
} : existingWithCustomDomains;
|
|
2902
|
+
const existingWithSecurityAudits = existing && deployment.capabilities.securityAudits && !existing.deployment.capabilities.securityAudits ? {
|
|
2903
|
+
...existingWithEmail,
|
|
2904
|
+
capabilities: {
|
|
2905
|
+
...existingWithEmail.capabilities,
|
|
2906
|
+
securityAudits: true
|
|
2907
|
+
},
|
|
2908
|
+
schemaVersion: deployment.schemaVersion
|
|
2909
|
+
} : existingWithEmail;
|
|
2695
2910
|
const comparable = (value) => {
|
|
2696
2911
|
if (!options?.allowRuntimeLogsChange && !options?.allowStorageLocationChange) return JSON.stringify(value);
|
|
2697
2912
|
const comparableValue = { ...value };
|
|
@@ -2702,7 +2917,7 @@ async function createPlatformInstallPlan(client, input, existing, options) {
|
|
|
2702
2917
|
schemaVersion: void 0
|
|
2703
2918
|
});
|
|
2704
2919
|
};
|
|
2705
|
-
if (existing && (comparable(
|
|
2920
|
+
if (existing && (comparable(existingWithSecurityAudits) !== comparable(deploymentWithoutEmailZone) || recordedEmailZone !== void 0 && recordedEmailZone !== configuredEmailZone || recordedSenderDomain !== void 0 && recordedSenderDomain !== configuredSenderDomain)) throw new Error(`platform: --resume inputs do not match installation ${existing.id}. Use its recorded configuration.`);
|
|
2706
2921
|
const names = deployment.resources;
|
|
2707
2922
|
const wildcardHostname = `*.${deployment.application.baseDomain}`;
|
|
2708
2923
|
const zone = testing ? null : await client.findZone(account.id, deployment.application.zoneName);
|
|
@@ -2726,24 +2941,31 @@ async function createPlatformInstallPlan(client, input, existing, options) {
|
|
|
2726
2941
|
throw error;
|
|
2727
2942
|
});
|
|
2728
2943
|
const prerequisites = [];
|
|
2729
|
-
const
|
|
2730
|
-
|
|
2731
|
-
prerequisites.push(error);
|
|
2944
|
+
const denials = [];
|
|
2945
|
+
const settle = (slot, read) => read.catch((error) => {
|
|
2946
|
+
if (error instanceof PlatformCloudflarePrerequisiteError) prerequisites.push(error);
|
|
2947
|
+
else if (error instanceof PlatformCloudflareApiError && (error.status === 401 || error.status === 403)) denials[slot] = error;
|
|
2948
|
+
else throw error;
|
|
2732
2949
|
return [];
|
|
2733
|
-
};
|
|
2950
|
+
});
|
|
2734
2951
|
const [aiGateways, routingKv, isrKv, legacyKv, r2Buckets, usageQueues, cronQueues, deploymentQueues, dispatchNamespaces, hyperdrives, workers] = await Promise.all([
|
|
2735
|
-
gatewayInventory,
|
|
2736
|
-
client.listKvNamespaces(account.id, names.routingKv),
|
|
2737
|
-
client.listKvNamespaces(account.id, names.isrCacheKv),
|
|
2738
|
-
client.listKvNamespaces(account.id, names.legacyAssetsKv),
|
|
2739
|
-
client.listR2Buckets(account.id)
|
|
2740
|
-
client.listQueues(account.id, names.usageQueue),
|
|
2741
|
-
client.listQueues(account.id, names.cronQueue),
|
|
2742
|
-
options?.deploymentExecution ?? existing?.resources.some((resource) => resource.key === "deployment-queue") ? client.listQueues(account.id, names.deploymentQueue) : Promise.resolve([]),
|
|
2743
|
-
client.listDispatchNamespaces(account.id)
|
|
2744
|
-
client.listHyperdriveConfigs(account.id),
|
|
2745
|
-
client.listWorkerNames(account.id)
|
|
2952
|
+
settle(0, gatewayInventory),
|
|
2953
|
+
settle(1, client.listKvNamespaces(account.id, names.routingKv)),
|
|
2954
|
+
settle(2, client.listKvNamespaces(account.id, names.isrCacheKv)),
|
|
2955
|
+
settle(3, client.listKvNamespaces(account.id, names.legacyAssetsKv)),
|
|
2956
|
+
settle(4, client.listR2Buckets(account.id)),
|
|
2957
|
+
settle(5, client.listQueues(account.id, names.usageQueue)),
|
|
2958
|
+
settle(6, client.listQueues(account.id, names.cronQueue)),
|
|
2959
|
+
options?.deploymentExecution ?? existing?.resources.some((resource) => resource.key === "deployment-queue") ? settle(7, client.listQueues(account.id, names.deploymentQueue)) : Promise.resolve([]),
|
|
2960
|
+
settle(8, client.listDispatchNamespaces(account.id)),
|
|
2961
|
+
settle(9, client.listHyperdriveConfigs(account.id)),
|
|
2962
|
+
settle(10, client.listWorkerNames(account.id))
|
|
2746
2963
|
]);
|
|
2964
|
+
const denied = denials.filter((error) => error !== void 0);
|
|
2965
|
+
if (denied.length > 0) {
|
|
2966
|
+
if (denied.length === 1 && prerequisites.length === 0) throw denied[0];
|
|
2967
|
+
throw new AggregateError([...denied, ...prerequisites], `platform: Cloudflare denied reads the plan needs.\n\n${[...formatPlanDenials(denied), ...prerequisites.map((error) => error.message)].join("\n\n")}`, { cause: denied[0] });
|
|
2968
|
+
}
|
|
2747
2969
|
if (prerequisites.length === 1) throw prerequisites[0];
|
|
2748
2970
|
if (prerequisites.length > 1) throw new AggregateError(prerequisites, `platform: Cloudflare account prerequisites are missing:\n\n${prerequisites.map((error) => error.message).join("\n\n")}`);
|
|
2749
2971
|
const dnsRecords = zone ? await listZoneDnsRecords(client, zone, wildcardHostname) : [];
|
|
@@ -2932,7 +3154,7 @@ async function createPlatformInstallPlan(client, input, existing, options) {
|
|
|
2932
3154
|
});
|
|
2933
3155
|
const resolvedResources = { ...deployment.resources };
|
|
2934
3156
|
for (const action of actions) {
|
|
2935
|
-
const resourceKey = RESOURCE_NAME_KEY_BY_ACTION[action.key];
|
|
3157
|
+
const resourceKey = hasOwnKey(RESOURCE_NAME_KEY_BY_ACTION, action.key) ? RESOURCE_NAME_KEY_BY_ACTION[action.key] : void 0;
|
|
2936
3158
|
if (resourceKey && action.name !== resolvedResources[resourceKey]) resolvedResources[resourceKey] = action.name;
|
|
2937
3159
|
}
|
|
2938
3160
|
const resolvedDeployment = createPlatformDeploymentManifest({
|
|
@@ -3094,7 +3316,7 @@ function addNamedPlan(context, target) {
|
|
|
3094
3316
|
});
|
|
3095
3317
|
return;
|
|
3096
3318
|
}
|
|
3097
|
-
if (
|
|
3319
|
+
if (existing && recorded?.state === "ready") {
|
|
3098
3320
|
if (options?.repairMissing && recorded.ownership === "created") {
|
|
3099
3321
|
actions.push({
|
|
3100
3322
|
action: "create",
|
|
@@ -3191,7 +3413,7 @@ function isLegacyUniqueProvisionAttempt(manifest, key, kind, name) {
|
|
|
3191
3413
|
const resourceSlug = resourceSlugForManifest(manifest);
|
|
3192
3414
|
if (resourceSlug === manifest.deployment.installationSlug) return false;
|
|
3193
3415
|
const expectedNames = createPlatformResourceNames(resourceSlug);
|
|
3194
|
-
const resourceKey = RESOURCE_NAME_KEY_BY_ACTION[key];
|
|
3416
|
+
const resourceKey = hasOwnKey(RESOURCE_NAME_KEY_BY_ACTION, key) ? RESOURCE_NAME_KEY_BY_ACTION[key] : void 0;
|
|
3195
3417
|
if (!resourceKey) return false;
|
|
3196
3418
|
const expectedName = expectedNames[resourceKey];
|
|
3197
3419
|
const uniquePrefix = expectedName.slice(0, expectedName.lastIndexOf("-") + 1);
|
|
@@ -3664,12 +3886,16 @@ var PlatformWorkerRecoveryIncompleteError = class extends Error {
|
|
|
3664
3886
|
}
|
|
3665
3887
|
};
|
|
3666
3888
|
// src/cli/platform-installer-secrets.ts
|
|
3889
|
+
const required = (value, name) => {
|
|
3890
|
+
if (!value) throw new Error(`platform: ${name} is required to install the platform.`);
|
|
3891
|
+
return value;
|
|
3892
|
+
};
|
|
3667
3893
|
function createPlatformInstallationSecrets(input) {
|
|
3668
3894
|
const checkpoint = input.checkpoint ?? {};
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
}
|
|
3895
|
+
if (!input.r2AccessKeyId !== !input.r2SecretAccessKey) {
|
|
3896
|
+
const [given, missing] = input.r2AccessKeyId ? ["VOID_PLATFORM_R2_ACCESS_KEY_ID", "VOID_PLATFORM_R2_SECRET_ACCESS_KEY"] : ["VOID_PLATFORM_R2_SECRET_ACCESS_KEY", "VOID_PLATFORM_R2_ACCESS_KEY_ID"];
|
|
3897
|
+
throw new Error(`platform: ${given} is set but ${missing} is not. Set VOID_PLATFORM_R2_ACCESS_KEY_ID and VOID_PLATFORM_R2_SECRET_ACCESS_KEY together, even if only the secret changed.`);
|
|
3898
|
+
}
|
|
3673
3899
|
const existingInstallation = input.existingInstallation === true;
|
|
3674
3900
|
const generateIdentityKeys = input.generateIdentityKeys === true && !existingInstallation;
|
|
3675
3901
|
const restoredIdentity = (explicit, name) => existingInstallation ? checkpoint[name] || explicit || "" : explicit || checkpoint[name] || "";
|
|
@@ -4079,9 +4305,9 @@ async function readPlatformWorkerDeployments(configPath, accountId, workerName,
|
|
|
4079
4305
|
versions
|
|
4080
4306
|
}));
|
|
4081
4307
|
}
|
|
4308
|
+
const normalize = (deployment) => deployment.versions.filter((version) => version.percentage > 0).map((version) => `${version.versionId}@${version.percentage}`).sort();
|
|
4082
4309
|
function samePlatformWorkerTraffic(left, right) {
|
|
4083
4310
|
if (!left) return false;
|
|
4084
|
-
const normalize = (deployment) => deployment.versions.filter((version) => version.percentage > 0).map((version) => `${version.versionId}@${version.percentage}`).sort();
|
|
4085
4311
|
return JSON.stringify(normalize(left)) === JSON.stringify(normalize(right));
|
|
4086
4312
|
}
|
|
4087
4313
|
function deploymentRunsOnlyVersion(deployment, versionId) {
|
|
@@ -4419,13 +4645,13 @@ async function platformWorkerLiveTriggersMatch(options) {
|
|
|
4419
4645
|
const worker = record(workerValue);
|
|
4420
4646
|
const subdomain = record(worker?.subdomain);
|
|
4421
4647
|
const schedules = record(schedulesValue)?.schedules;
|
|
4422
|
-
|
|
4648
|
+
const references = record(worker?.references)?.queues;
|
|
4649
|
+
if (worker?.name !== workerName || !subdomain || !desired.preserveWorkersDev && subdomain.enabled !== desired.workers_dev || !desired.preservePreviewUrls && subdomain.previews_enabled !== desired.preview_urls || !Array.isArray(schedules) || !Array.isArray(references) || !Array.isArray(workflowsValue) || workflowsValue.length >= 100 || !Array.isArray(nextWorkflowsValue) || nextWorkflowsValue.length !== 0) return false;
|
|
4423
4650
|
const liveCrons = schedules.map((entry) => record(entry)?.cron);
|
|
4424
4651
|
if (!liveCrons.every((cron) => typeof cron === "string") || !sameStrings(liveCrons, desired.crons) || workflowsValue.some((entry) => {
|
|
4425
4652
|
const workflow = record(entry);
|
|
4426
4653
|
return !workflow || typeof workflow.script_name !== "string" || workflow.script_name === workerName;
|
|
4427
4654
|
})) return false;
|
|
4428
|
-
const references = record(worker.references).queues;
|
|
4429
4655
|
if (references.length !== queues.length) return false;
|
|
4430
4656
|
const matched = /* @__PURE__ */ new Set();
|
|
4431
4657
|
const consumers = await Promise.all(references.map(async (value) => {
|
|
@@ -4473,8 +4699,9 @@ async function recoverInterruptedPlatformWorkerCutover(input) {
|
|
|
4473
4699
|
"emailGateway",
|
|
4474
4700
|
"proxy",
|
|
4475
4701
|
"api"
|
|
4476
|
-
]
|
|
4702
|
+
]) {
|
|
4477
4703
|
const snapshot = interruptedCutover.staged.get(key);
|
|
4704
|
+
if (!snapshot) continue;
|
|
4478
4705
|
const preservedRoutes = dependencies.recoverWorkerCutover ? [] : await inventoryUnmanagedPlatformWorkerTraffic(dependencies.client, plan, snapshot.workerName);
|
|
4479
4706
|
const recoveryConfig = mergePlatformWorkerTrafficConfig({
|
|
4480
4707
|
...configs[key],
|
|
@@ -4830,9 +5057,11 @@ async function deployPlatformWorker(config, secrets, options) {
|
|
|
4830
5057
|
await options.onStaged(previousVersionId, uploadedVersionId, previousTriggers);
|
|
4831
5058
|
await options.onReadyForActivation?.();
|
|
4832
5059
|
await options.waitForPriorWorker?.();
|
|
5060
|
+
const knownDeploymentIds = /* @__PURE__ */ new Set();
|
|
4833
5061
|
if (options.workerExisted) {
|
|
4834
5062
|
const deploymentsBeforeActivation = await readPlatformWorkerDeployments(configPath, accountId, workerName, readRunner);
|
|
4835
5063
|
if (deploymentsBeforeActivation[0]?.id !== previousDeploymentId || !deploymentRunsOnlyVersion(deploymentsBeforeActivation[0], previousVersionId)) throw new Error(`platform: Worker ${workerName} changed concurrently before activation; refusing to overwrite it.`);
|
|
5064
|
+
for (const deployment of deploymentsBeforeActivation) knownDeploymentIds.add(deployment.id);
|
|
4836
5065
|
activatedVersionId = uploadedVersionId;
|
|
4837
5066
|
assertCleanPlatformWrangler(await options.runner({
|
|
4838
5067
|
type: "versions.deploy",
|
|
@@ -4846,12 +5075,16 @@ async function deployPlatformWorker(config, secrets, options) {
|
|
|
4846
5075
|
}
|
|
4847
5076
|
const readDeploymentHistory = () => readPlatformWorkerDeployments(configPath, accountId, workerName, readRunner);
|
|
4848
5077
|
let deploymentsAfterActivation = await readDeploymentHistory();
|
|
5078
|
+
const headIsStale = () => {
|
|
5079
|
+
const head = deploymentsAfterActivation[0];
|
|
5080
|
+
return head === void 0 || knownDeploymentIds.has(head.id);
|
|
5081
|
+
};
|
|
4849
5082
|
for (const wait of [
|
|
4850
5083
|
250,
|
|
4851
5084
|
500,
|
|
4852
5085
|
1e3
|
|
4853
5086
|
]) {
|
|
4854
|
-
if (
|
|
5087
|
+
if (!headIsStale()) break;
|
|
4855
5088
|
await setTimeout$1(wait);
|
|
4856
5089
|
try {
|
|
4857
5090
|
deploymentsAfterActivation = await readDeploymentHistory();
|
|
@@ -4860,9 +5093,10 @@ async function deployPlatformWorker(config, secrets, options) {
|
|
|
4860
5093
|
throw new PlatformWorkerRecoveryIncompleteError(`platform: Void could not confirm activation of ${workerName} because rereading its deployment history failed: ${getErrorMessage(cause)}`, { cause });
|
|
4861
5094
|
}
|
|
4862
5095
|
}
|
|
4863
|
-
if (
|
|
5096
|
+
if (headIsStale()) {
|
|
5097
|
+
const head = deploymentsAfterActivation[0];
|
|
4864
5098
|
activatedVersionId = null;
|
|
4865
|
-
throw new PlatformWorkerRecoveryIncompleteError(`platform: Void could not confirm activation of ${workerName} because Cloudflare still reports the previous deployment.`);
|
|
5099
|
+
throw new PlatformWorkerRecoveryIncompleteError(`platform: Void could not confirm activation of ${workerName} because Cloudflare ${head === void 0 ? "lists no deployments for it yet" : head.id === previousDeploymentId ? "still reports the previous deployment" : `still reports older deployment ${head.id}`}.`);
|
|
4866
5100
|
}
|
|
4867
5101
|
const lineage = classifyPlatformWorkerDeploymentLineage(deploymentsAfterActivation, uploadedVersionId, previousDeploymentId);
|
|
4868
5102
|
if (lineage.kind === "concurrent-after") {
|
|
@@ -4913,10 +5147,11 @@ async function deployPlatformWorker(config, secrets, options) {
|
|
|
4913
5147
|
if (nextTraffic.customDomains.length > 0) await options.publishCustomDomains(workerName, nextTraffic.customDomains);
|
|
4914
5148
|
if (options.managedRoutes.length > 0) await options.publishRoutes(workerName, options.managedRoutes);
|
|
4915
5149
|
await options.onTrafficPublished();
|
|
5150
|
+
const committedVersionId = uploadedVersionId;
|
|
4916
5151
|
const rollback = () => rollbackPlatformWorker({
|
|
4917
5152
|
accountId,
|
|
4918
5153
|
activatedDeploymentId,
|
|
4919
|
-
activatedVersionId:
|
|
5154
|
+
activatedVersionId: committedVersionId,
|
|
4920
5155
|
config,
|
|
4921
5156
|
nextTriggers,
|
|
4922
5157
|
previousConfig: options.previousConfig,
|
|
@@ -5094,7 +5329,10 @@ async function restorePlatformWorkerDeployment(input) {
|
|
|
5094
5329
|
}
|
|
5095
5330
|
// src/cli/platform-install-workers.ts
|
|
5096
5331
|
function platformWorkerAction(workerActions, key) {
|
|
5097
|
-
|
|
5332
|
+
const resourceKey = platformWorkerResourceKey(key);
|
|
5333
|
+
const action = workerActions.find((entry) => entry.key === resourceKey);
|
|
5334
|
+
if (!action) throw new Error(`platform: The plan is missing the ${resourceKey} Worker action.`);
|
|
5335
|
+
return action;
|
|
5098
5336
|
}
|
|
5099
5337
|
/** Deploy callbacks shared by the upload and enable phases for one platform Worker. */
|
|
5100
5338
|
function platformWorkerDeployCallbacks(input) {
|
|
@@ -5168,10 +5406,12 @@ async function uploadInstallationWorkers(input) {
|
|
|
5168
5406
|
const uploadWaiters = [];
|
|
5169
5407
|
const acquireUploadSlot = async () => {
|
|
5170
5408
|
if (uploadFailure !== void 0) throw uploadFailure;
|
|
5171
|
-
if (availableUploadSlots === 0) await new Promise((resolve, reject) =>
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5409
|
+
if (availableUploadSlots === 0) await new Promise((resolve, reject) => {
|
|
5410
|
+
uploadWaiters.push({
|
|
5411
|
+
resolve,
|
|
5412
|
+
reject
|
|
5413
|
+
});
|
|
5414
|
+
});
|
|
5175
5415
|
else availableUploadSlots--;
|
|
5176
5416
|
return (failure) => {
|
|
5177
5417
|
if (failure !== void 0 && uploadFailure === void 0) {
|
|
@@ -5326,12 +5566,13 @@ async function verifyPlatformHealth(apiUrl, installationId, proxyUrl, applicatio
|
|
|
5326
5566
|
}
|
|
5327
5567
|
};
|
|
5328
5568
|
const dispatchUrl = dispatchOrigin ?? `https://${PLATFORM_HEALTH_HOSTNAME_LABEL}.${applicationBaseDomain}`;
|
|
5569
|
+
const emailGatewayHealthUrl = context?.emailGatewayUrl ? context.emailGatewayUrl + "/health" : void 0;
|
|
5329
5570
|
const [health, discovery, proxy, dispatch, emailGateway] = await Promise.all([
|
|
5330
5571
|
request(`${apiUrl}/health`),
|
|
5331
5572
|
request(`${apiUrl}/.well-known/void-platform`),
|
|
5332
5573
|
request(`${proxyUrl}/health`),
|
|
5333
5574
|
request(`${dispatchUrl}/health`),
|
|
5334
|
-
|
|
5575
|
+
emailGatewayHealthUrl ? request(emailGatewayHealthUrl) : void 0
|
|
5335
5576
|
]);
|
|
5336
5577
|
if (!health.ok) throw await platformProbeFailure("Health check", `${apiUrl}/health`, health, context);
|
|
5337
5578
|
if (!discovery.ok) throw await platformProbeFailure("Discovery check", `${apiUrl}/.well-known/void-platform`, discovery, context);
|
|
@@ -5341,8 +5582,8 @@ async function verifyPlatformHealth(apiUrl, installationId, proxyUrl, applicatio
|
|
|
5341
5582
|
if ((body.usageProtocolVersion ?? 0) !== usageProtocolVersion) throw new Error("platform: Deployed API usage protocol does not match this runtime. Traffic remains disabled.");
|
|
5342
5583
|
if (!proxy.ok) throw await platformProbeFailure("Proxy health check", `${proxyUrl}/health`, proxy, context);
|
|
5343
5584
|
if (!dispatch.ok) throw await platformProbeFailure("Dispatch health check", `${dispatchUrl}/health`, dispatch, context);
|
|
5344
|
-
if (emailGateway) {
|
|
5345
|
-
if (!emailGateway.ok) throw await platformProbeFailure("Email gateway health check",
|
|
5585
|
+
if (emailGateway && emailGatewayHealthUrl) {
|
|
5586
|
+
if (!emailGateway.ok) throw await platformProbeFailure("Email gateway health check", emailGatewayHealthUrl, emailGateway, context);
|
|
5346
5587
|
const identity = await emailGateway.json();
|
|
5347
5588
|
if (identity?.installationId !== installationId || identity.platformVersion !== platformVersion || identity.emailProtocolVersion !== 1) throw new Error("platform: Deployed email gateway identity, version, or protocol does not match this installation.");
|
|
5348
5589
|
}
|
|
@@ -5396,6 +5637,7 @@ const sharedEmailStepPermissions = /* @__PURE__ */ new Map([
|
|
|
5396
5637
|
["inbound_probe", "Zone → Zone Settings → Edit"],
|
|
5397
5638
|
["sending_onboard", "Account → Email Sending → Edit"]
|
|
5398
5639
|
]);
|
|
5640
|
+
const code = (value) => typeof value === "string" && /^[a-z][a-z0-9_-]{0,63}$/.test(value) ? value : null;
|
|
5399
5641
|
async function bootstrapPlatformSharedEmail(apiUrl, healthProbeToken, fetcher = fetch) {
|
|
5400
5642
|
const deadline = Date.now() + 3e5;
|
|
5401
5643
|
let operationId = null;
|
|
@@ -5403,7 +5645,9 @@ async function bootstrapPlatformSharedEmail(apiUrl, healthProbeToken, fetcher =
|
|
|
5403
5645
|
const waitForProgress = async () => {
|
|
5404
5646
|
const remaining = deadline - Date.now();
|
|
5405
5647
|
if (remaining <= 0) throw timedOut();
|
|
5406
|
-
await new Promise((resolve) =>
|
|
5648
|
+
await new Promise((resolve) => {
|
|
5649
|
+
setTimeout(resolve, Math.min(1e3, remaining));
|
|
5650
|
+
});
|
|
5407
5651
|
};
|
|
5408
5652
|
let response;
|
|
5409
5653
|
let value;
|
|
@@ -5448,14 +5692,13 @@ async function bootstrapPlatformSharedEmail(apiUrl, healthProbeToken, fetcher =
|
|
|
5448
5692
|
200,
|
|
5449
5693
|
202,
|
|
5450
5694
|
503
|
|
5451
|
-
].includes(response.status) && status?.version === 1 && status.state === "incomplete" && observedOperationId && (status.operationStatus === "pending" || status.operationStatus === "running") && status.failureCode
|
|
5695
|
+
].includes(response.status) && status?.version === 1 && status.state === "incomplete" && observedOperationId && (status.operationStatus === "pending" || status.operationStatus === "running") && (status.failureCode === null || status.failureCode === void 0)) {
|
|
5452
5696
|
await waitForProgress();
|
|
5453
5697
|
continue;
|
|
5454
5698
|
}
|
|
5455
5699
|
break;
|
|
5456
5700
|
}
|
|
5457
|
-
if (!response.ok || status?.version !== 1 || status.state !== "ready" || operationId === null || status.operationId !== operationId || status.operationStatus
|
|
5458
|
-
const code = (value) => typeof value === "string" && /^[a-z][a-z0-9_-]{0,63}$/.test(value) ? value : null;
|
|
5701
|
+
if (!response.ok || status?.version !== 1 || status.state !== "ready" || operationId === null || status.operationId !== operationId || status.operationStatus !== null && status.operationStatus !== void 0 && status.operationStatus !== "completed" || status.failureCode !== null && status.failureCode !== void 0) {
|
|
5459
5702
|
const operationStatus = code(status?.operationStatus);
|
|
5460
5703
|
const operationId = typeof status?.operationId === "string" && /^[A-Za-z0-9_-]{1,100}$/.test(status.operationId) ? status.operationId : null;
|
|
5461
5704
|
const details = operationId ? [`Operation ${operationId}: ${operationStatus ?? "incomplete"}.`] : operationStatus ? [`Operation status: ${operationStatus}.`] : [];
|
|
@@ -5601,7 +5844,7 @@ function platformAccessHealthTargets(plan) {
|
|
|
5601
5844
|
}
|
|
5602
5845
|
async function verifyHealthException(access, app, destination) {
|
|
5603
5846
|
const destinations = platformAccessPublicDestinations(app);
|
|
5604
|
-
if (typeof app.id !== "string" || !app.id || app.type !== "self_hosted" || app.domain !== destination || !destinations.length || destinations.some((value) => value !== destination) || app.destinations !== void 0 && (!Array.isArray(app.destinations) || app.destinations.some((value) => !value || value.type !== "public" || value.uri !== destination)) || app.target_criteria
|
|
5847
|
+
if (typeof app.id !== "string" || !app.id || app.type !== "self_hosted" || app.domain !== destination || !destinations.length || destinations.some((value) => value !== destination) || app.destinations !== void 0 && (!Array.isArray(app.destinations) || app.destinations.some((value) => !value || value.type !== "public" || value.uri !== destination)) || app.target_criteria !== null && app.target_criteria !== void 0 && (!Array.isArray(app.target_criteria) || app.target_criteria.length > 0)) throw new Error(`platform: The Access health exception must cover only ${destination}.`);
|
|
5605
5848
|
const policies = await access.list(`apps/${encodeURIComponent(app.id)}/policies`);
|
|
5606
5849
|
const policy = policies[0];
|
|
5607
5850
|
if (policies.length !== 1 || policy?.decision !== "bypass" || JSON.stringify(policy.include) !== "[{\"everyone\":{}}]" || policy.require !== void 0 && (!Array.isArray(policy.require) || policy.require.length > 0) || policy.exclude !== void 0 && (!Array.isArray(policy.exclude) || policy.exclude.length > 0)) throw new Error(`platform: The Access policy for ${destination} does not match the reserved health-check exception.`);
|
|
@@ -5618,8 +5861,9 @@ async function ensurePlatformAccessHealthChecks(input) {
|
|
|
5618
5861
|
const accountId = input.plan.account.id;
|
|
5619
5862
|
const identityAccountId = spec.accountId ?? accountId;
|
|
5620
5863
|
const token = appAccess?.managed ? appAccess.apiToken : identityAccountId === accountId ? process.env.VOID_PLATFORM_ACCESS_SETUP_TOKEN || input.checkpoint.accessManagementToken : void 0;
|
|
5621
|
-
|
|
5622
|
-
|
|
5864
|
+
const accessClient = token ? new PlatformCloudflareClient(token, { apiBase: input.client.apiBaseUrl }) : input.client.request ? { request: input.client.request.bind(input.client) } : void 0;
|
|
5865
|
+
if (!accessClient) throw new Error("platform: Access management is required to configure the reserved health endpoints.");
|
|
5866
|
+
const access = new PlatformAccessClient(accessClient, accountId);
|
|
5623
5867
|
const nonce = createHash("sha256").update(`void-access-health:${input.manifest.ownershipNonce}`).digest("hex").slice(0, 32);
|
|
5624
5868
|
const state = input.checkpoint.accessHealthProvisioningJson ? JSON.parse(input.checkpoint.accessHealthProvisioningJson) : {
|
|
5625
5869
|
version: 1,
|
|
@@ -5741,7 +5985,7 @@ async function verifyInstalledPlatformAccessProtection(input) {
|
|
|
5741
5985
|
}
|
|
5742
5986
|
const existingWorkers = input.plan.actions.filter((action) => action.kind === "worker" && action.action === "update").map((action) => action.name);
|
|
5743
5987
|
if (existingWorkers.length) {
|
|
5744
|
-
const { verifyProtectionWorkerOrigins } = await import("./platform-auth-protection-
|
|
5988
|
+
const { verifyProtectionWorkerOrigins } = await import("./platform-auth-protection-DA6Tw8Og.mjs");
|
|
5745
5989
|
await verifyProtectionWorkerOrigins({
|
|
5746
5990
|
request: input.client.request.bind(input.client),
|
|
5747
5991
|
listWorkerDomains: input.client.listWorkerDomains.bind(input.client),
|
|
@@ -5947,6 +6191,32 @@ async function prepareInstallationAuthentication(input) {
|
|
|
5947
6191
|
}
|
|
5948
6192
|
}
|
|
5949
6193
|
}
|
|
6194
|
+
/** Cloudflare does not accept an origin connection limit below this. */
|
|
6195
|
+
const HYPERDRIVE_MIN_ORIGIN_CONNECTIONS = 5;
|
|
6196
|
+
/** The Hyperdrive origin limit that leaves the direct-connection reserve free. */
|
|
6197
|
+
function platformHyperdriveConnectionLimit(connectionSlots) {
|
|
6198
|
+
return Math.max(HYPERDRIVE_MIN_ORIGIN_CONNECTIONS, connectionSlots - 5);
|
|
6199
|
+
}
|
|
6200
|
+
/**
|
|
6201
|
+
* Hyperdrive's default origin limit can exceed what a small database accepts. Once the
|
|
6202
|
+
* pool fills every slot, direct connections (upgrade, repair, `psql`) fail with 53300.
|
|
6203
|
+
* Lower the limit on the Hyperdrive this installation created; only warn for an adopted one,
|
|
6204
|
+
* which its owner manages. Never raise a limit, so the value stays within the account plan.
|
|
6205
|
+
*/
|
|
6206
|
+
async function fitPlatformHyperdriveToDatabase(input) {
|
|
6207
|
+
const { client, accountId, resource, readConnectionSlots, onProgress } = input;
|
|
6208
|
+
if (!readConnectionSlots || resource.kind !== "hyperdrive") return;
|
|
6209
|
+
const connectionSlots = await readConnectionSlots();
|
|
6210
|
+
const limit = platformHyperdriveConnectionLimit(connectionSlots);
|
|
6211
|
+
const current = (await client.getHyperdriveConfig(accountId, resource.id)).originConnectionLimit;
|
|
6212
|
+
if (current === void 0 || current <= limit) return;
|
|
6213
|
+
if (resource.ownership !== "created") {
|
|
6214
|
+
onProgress?.(`Warning: Hyperdrive ${resource.name} may open ${current} database connections, but the database accepts ${connectionSlots}. Set its origin connection limit to ${limit} or lower so upgrades and other direct connections can still connect.`);
|
|
6215
|
+
return;
|
|
6216
|
+
}
|
|
6217
|
+
onProgress?.(`Lowering the Hyperdrive origin connection limit from ${current} to ${limit} to fit the database's ${connectionSlots} connections`);
|
|
6218
|
+
await client.setHyperdriveOriginConnectionLimit(accountId, resource.id, limit);
|
|
6219
|
+
}
|
|
5950
6220
|
// src/cli/platform-installer-runtime.ts
|
|
5951
6221
|
function loadPlatformRuntime(customRuntimeDirectory) {
|
|
5952
6222
|
const runtime = resolvePlatformRuntime(customRuntimeDirectory || void 0);
|
|
@@ -5960,7 +6230,7 @@ function verifyRuntimeArtifacts(runtimeDirectory, manifest) {
|
|
|
5960
6230
|
try {
|
|
5961
6231
|
contents = readFileSync(path);
|
|
5962
6232
|
} catch (error) {
|
|
5963
|
-
throw new Error(`platform: Runtime artifact is missing: ${getErrorMessage(error)}
|
|
6233
|
+
throw new Error(`platform: Runtime artifact is missing: ${getErrorMessage(error)}`, { cause: error });
|
|
5964
6234
|
}
|
|
5965
6235
|
if (contents.byteLength !== artifact.size || hash(contents) !== artifact.sha256) throw new Error(`platform: Runtime artifact failed integrity verification: ${path}.`);
|
|
5966
6236
|
}
|
|
@@ -5972,7 +6242,7 @@ function verifyPlatformDatabaseArtifacts(runtimeDirectory, database) {
|
|
|
5972
6242
|
try {
|
|
5973
6243
|
journal = readFileSync(journalPath);
|
|
5974
6244
|
} catch (error) {
|
|
5975
|
-
throw new Error(`platform: Runtime database migration journal is missing: ${getErrorMessage(error)}
|
|
6245
|
+
throw new Error(`platform: Runtime database migration journal is missing: ${getErrorMessage(error)}`, { cause: error });
|
|
5976
6246
|
}
|
|
5977
6247
|
if (hash(journal) !== database.journalSha256) throw new Error(`platform: Runtime database migration journal failed integrity verification: ${journalPath}.`);
|
|
5978
6248
|
for (const migration of database.migrations) {
|
|
@@ -5981,7 +6251,7 @@ function verifyPlatformDatabaseArtifacts(runtimeDirectory, database) {
|
|
|
5981
6251
|
try {
|
|
5982
6252
|
contents = readFileSync(path);
|
|
5983
6253
|
} catch (error) {
|
|
5984
|
-
throw new Error(`platform: Runtime database migration is missing: ${getErrorMessage(error)}
|
|
6254
|
+
throw new Error(`platform: Runtime database migration is missing: ${getErrorMessage(error)}`, { cause: error });
|
|
5985
6255
|
}
|
|
5986
6256
|
if (hash(contents) !== migration.sha256) throw new Error(`platform: Runtime database migration failed integrity verification: ${path}.`);
|
|
5987
6257
|
}
|
|
@@ -6272,14 +6542,14 @@ function platformDatabaseClientUrl(databaseUrl) {
|
|
|
6272
6542
|
url.searchParams.set("sslmode", "verify-full");
|
|
6273
6543
|
return url.toString();
|
|
6274
6544
|
}
|
|
6275
|
-
async function withPlatformDatabasePool(databaseUrl,
|
|
6545
|
+
async function withPlatformDatabasePool(databaseUrl, run) {
|
|
6276
6546
|
const { Pool } = await import("pg");
|
|
6277
6547
|
const pool = new Pool({
|
|
6278
6548
|
connectionString: platformDatabaseClientUrl(databaseUrl),
|
|
6279
6549
|
max: 1
|
|
6280
6550
|
});
|
|
6281
6551
|
try {
|
|
6282
|
-
return await
|
|
6552
|
+
return await run(pool);
|
|
6283
6553
|
} finally {
|
|
6284
6554
|
await pool.end();
|
|
6285
6555
|
}
|
|
@@ -6294,26 +6564,43 @@ function claimPlatformDatabase(databaseUrl, installationId, ownershipNonce) {
|
|
|
6294
6564
|
}
|
|
6295
6565
|
});
|
|
6296
6566
|
}
|
|
6567
|
+
/** The error a lifecycle-lock operation fails with once pg reported the held client closed. */
|
|
6568
|
+
function lostLockConnectionError(cause) {
|
|
6569
|
+
return new Error(`platform: The PostgreSQL connection that holds the lifecycle lock was closed (${cause.message}). Rerun the command to continue.`, { cause });
|
|
6570
|
+
}
|
|
6297
6571
|
async function acquirePlatformDatabaseLifecycleLock(databaseUrl, installationId, ownershipNonce) {
|
|
6298
6572
|
const { Pool } = await import("pg");
|
|
6299
6573
|
const pool = new Pool({
|
|
6300
6574
|
connectionString: platformDatabaseClientUrl(databaseUrl),
|
|
6301
6575
|
max: 1
|
|
6302
6576
|
});
|
|
6577
|
+
pool.on("error", () => {});
|
|
6303
6578
|
const client = await pool.connect();
|
|
6579
|
+
let lost;
|
|
6580
|
+
client.on("error", (error) => {
|
|
6581
|
+
lost ??= error;
|
|
6582
|
+
});
|
|
6583
|
+
const connection = { query: async (sql, values) => {
|
|
6584
|
+
if (lost) throw lostLockConnectionError(lost);
|
|
6585
|
+
try {
|
|
6586
|
+
return await client.query(sql, values ? [...values] : void 0);
|
|
6587
|
+
} catch (error) {
|
|
6588
|
+
throw lost ? lostLockConnectionError(lost) : error;
|
|
6589
|
+
}
|
|
6590
|
+
} };
|
|
6304
6591
|
try {
|
|
6305
|
-
const releaseConnectionLock = await acquirePlatformDatabaseLifecycleLockConnection(
|
|
6592
|
+
const releaseConnectionLock = await acquirePlatformDatabaseLifecycleLockConnection(connection, installationId, ownershipNonce);
|
|
6306
6593
|
const release = async () => {
|
|
6307
6594
|
try {
|
|
6308
|
-
await releaseConnectionLock();
|
|
6595
|
+
if (!lost) await releaseConnectionLock();
|
|
6309
6596
|
} finally {
|
|
6310
|
-
client.release();
|
|
6597
|
+
client.release(lost);
|
|
6311
6598
|
await pool.end();
|
|
6312
6599
|
}
|
|
6313
6600
|
};
|
|
6314
6601
|
return Object.assign(release, releaseConnectionLock);
|
|
6315
6602
|
} catch (error) {
|
|
6316
|
-
client.release();
|
|
6603
|
+
client.release(lost);
|
|
6317
6604
|
await pool.end();
|
|
6318
6605
|
throw error;
|
|
6319
6606
|
}
|
|
@@ -6324,7 +6611,7 @@ async function readPlatformDatabaseLifecycleManifest(databaseUrl, installationId
|
|
|
6324
6611
|
return await readPlatformDatabaseLifecycleManifestConnection(pool, installationId, ownershipNonce);
|
|
6325
6612
|
} catch (error) {
|
|
6326
6613
|
if (error instanceof Error && error.message.startsWith("platform:")) throw error;
|
|
6327
|
-
throw new Error(`platform: Could not read the PostgreSQL lifecycle checkpoint: ${error instanceof Error ? error.message : String(error)}
|
|
6614
|
+
throw new Error(`platform: Could not read the PostgreSQL lifecycle checkpoint: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
6328
6615
|
}
|
|
6329
6616
|
});
|
|
6330
6617
|
}
|
|
@@ -6361,6 +6648,21 @@ async function readPlatformProjectSlugsConnection(client) {
|
|
|
6361
6648
|
if ((await client.query(`SELECT to_regclass('public.projects') IS NOT NULL AS "present"`)).rows[0]?.present !== true) return [];
|
|
6362
6649
|
return (await client.query("SELECT \"slug\" FROM \"projects\" ORDER BY \"slug\"")).rows.map((row) => row.slug);
|
|
6363
6650
|
}
|
|
6651
|
+
/**
|
|
6652
|
+
* Connections the server accepts from roles without SUPERUSER. PostgreSQL 16 added
|
|
6653
|
+
* reserved_connections; older servers report it as missing, which counts as zero.
|
|
6654
|
+
*/
|
|
6655
|
+
async function readPlatformDatabaseConnectionSlotsConnection(client) {
|
|
6656
|
+
const row = (await client.query(`SELECT current_setting('max_connections')::int AS "max",
|
|
6657
|
+
current_setting('superuser_reserved_connections')::int AS "superuser",
|
|
6658
|
+
COALESCE(current_setting('reserved_connections', true), '0')::int AS "reserved"`)).rows[0];
|
|
6659
|
+
if (!row || ![
|
|
6660
|
+
row.max,
|
|
6661
|
+
row.superuser,
|
|
6662
|
+
row.reserved
|
|
6663
|
+
].every(Number.isInteger)) throw new Error("platform: Could not read the PostgreSQL connection limit.");
|
|
6664
|
+
return Math.max(0, row.max - row.superuser - row.reserved);
|
|
6665
|
+
}
|
|
6364
6666
|
async function inspectPlatformDatabaseStateConnection(client, database) {
|
|
6365
6667
|
const relation = await client.query(`SELECT to_regclass('"drizzle"."__drizzle_migrations"')::text AS "relation"`);
|
|
6366
6668
|
if (relation.rows.length === 0 || relation.rows[0]?.relation === null) return {
|
|
@@ -6466,7 +6768,7 @@ async function acquirePlatformDatabaseLifecycleLockConnection(client, installati
|
|
|
6466
6768
|
} catch (error) {
|
|
6467
6769
|
await client.query("SELECT pg_advisory_unlock(hashtextextended($1, 0))", [lockIdentity]);
|
|
6468
6770
|
if (error instanceof Error && error.message.startsWith("platform:")) throw error;
|
|
6469
|
-
throw new Error(`platform: The PostgreSQL lifecycle checkpoint is invalid: ${error instanceof Error ? error.message : String(error)}
|
|
6771
|
+
throw new Error(`platform: The PostgreSQL lifecycle checkpoint is invalid: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
6470
6772
|
}
|
|
6471
6773
|
let released = false;
|
|
6472
6774
|
const release = async () => {
|
|
@@ -6489,6 +6791,7 @@ async function acquirePlatformDatabaseLifecycleLockConnection(client, installati
|
|
|
6489
6791
|
release.readAdministratorSetup = () => readPlatformAdministratorSetupConnection(client);
|
|
6490
6792
|
release.readProjectZeroTrust = () => readPlatformProjectZeroTrustStateConnection(client);
|
|
6491
6793
|
release.readProjects = () => readPlatformProjectSlugsConnection(client);
|
|
6794
|
+
release.readConnectionSlots = () => readPlatformDatabaseConnectionSlotsConnection(client);
|
|
6492
6795
|
release.publishAiLogging = (kv, onProgress) => projectPlatformAiLoggingConnection(client, kv, { onProgress });
|
|
6493
6796
|
release.lockProjectZeroTrust = () => lockPlatformProjectZeroTrustConnection(client);
|
|
6494
6797
|
release.fenceProjectZeroTrust = () => fencePlatformProjectZeroTrustConnection(client);
|
|
@@ -6525,6 +6828,16 @@ async function readSandboxDrainTable(client) {
|
|
|
6525
6828
|
AND column_name = 'admission_protocol'
|
|
6526
6829
|
) AS "present"`)).rows[0]?.present === true };
|
|
6527
6830
|
}
|
|
6831
|
+
const classify = (row) => {
|
|
6832
|
+
if (!row) return null;
|
|
6833
|
+
const cursor = row.cursor;
|
|
6834
|
+
if (!row.generation || row.admission_protocol !== 0 && row.admission_protocol !== 2 && row.admission_protocol !== 3 || !row.started_at || !row.updated_at || row.state !== "draining" && row.state !== "complete" || row.phase !== "deployments" && row.phase !== "resources" || !cursor || cursor.pass !== "1" && cursor.pass !== "2" || row.state === "complete" && (!row.completed_at || row.phase !== "resources" || cursor.pass !== "2") || row.state === "draining" && row.completed_at !== null) throw new Error("platform: The authoritative sandbox-drain database checkpoint is invalid. Traffic remains disabled.");
|
|
6835
|
+
return {
|
|
6836
|
+
admissionProtocol: row.admission_protocol,
|
|
6837
|
+
generation: row.generation,
|
|
6838
|
+
state: row.state === "complete" ? "complete" : "pending"
|
|
6839
|
+
};
|
|
6840
|
+
};
|
|
6528
6841
|
async function preparePlatformSandboxDrainConnection(client, requiredAdmissionProtocol = 0) {
|
|
6529
6842
|
const table = await readSandboxDrainTable(client);
|
|
6530
6843
|
if (!table) throw new Error("platform: Runtime declares sandbox-drain safety but its database checkpoint table is missing.");
|
|
@@ -6533,17 +6846,8 @@ async function preparePlatformSandboxDrainConnection(client, requiredAdmissionPr
|
|
|
6533
6846
|
const readCheckpoint = () => client.query(`SELECT ${hasAdmissionColumn ? "\"admission_protocol\"" : "0 AS \"admission_protocol\""}, "generation", "state", "phase", "cursor", "started_at", "updated_at", "completed_at"
|
|
6534
6847
|
FROM "sandbox_drain_checkpoints"
|
|
6535
6848
|
WHERE "singleton" = true`);
|
|
6536
|
-
const
|
|
6537
|
-
|
|
6538
|
-
const cursor = row.cursor;
|
|
6539
|
-
if (!row.generation || row.admission_protocol !== 0 && row.admission_protocol !== 2 && row.admission_protocol !== 3 || !row.started_at || !row.updated_at || row.state !== "draining" && row.state !== "complete" || row.phase !== "deployments" && row.phase !== "resources" || !cursor || cursor.pass !== "1" && cursor.pass !== "2" || row.state === "complete" && (!row.completed_at || row.phase !== "resources" || cursor.pass !== "2") || row.state === "draining" && row.completed_at !== null) throw new Error("platform: The authoritative sandbox-drain database checkpoint is invalid. Traffic remains disabled.");
|
|
6540
|
-
return {
|
|
6541
|
-
admissionProtocol: row.admission_protocol,
|
|
6542
|
-
generation: row.generation,
|
|
6543
|
-
state: row.state === "complete" ? "complete" : "pending"
|
|
6544
|
-
};
|
|
6545
|
-
};
|
|
6546
|
-
const existingState = classify((await readCheckpoint()).rows[0]);
|
|
6849
|
+
const existing = await readCheckpoint();
|
|
6850
|
+
const existingState = classify(existing.rows[0]);
|
|
6547
6851
|
if (existingState && (requiredAdmissionProtocol === 0 || existingState.admissionProtocol >= requiredAdmissionProtocol)) return existingState;
|
|
6548
6852
|
if (requiredAdmissionProtocol >= 2) {
|
|
6549
6853
|
if (existingState && existingState.admissionProtocol >= 2) {
|
|
@@ -6622,7 +6926,8 @@ async function preparePlatformSandboxDrainConnection(client, requiredAdmissionPr
|
|
|
6622
6926
|
phase,
|
|
6623
6927
|
cursor
|
|
6624
6928
|
]);
|
|
6625
|
-
const
|
|
6929
|
+
const checkpoint = await readCheckpoint();
|
|
6930
|
+
const preparedState = classify(checkpoint.rows[0]);
|
|
6626
6931
|
if (!preparedState) throw new Error("platform: The sandbox-drain database checkpoint could not be established.");
|
|
6627
6932
|
return preparedState;
|
|
6628
6933
|
}
|
|
@@ -6643,7 +6948,7 @@ async function readRequiredPlatformSafetyProtocols(client) {
|
|
|
6643
6948
|
) AS "required", (SELECT "admission_protocol" FROM "sandbox_drain_checkpoints"
|
|
6644
6949
|
WHERE "singleton" = true) AS "protocol"`);
|
|
6645
6950
|
if (admission.rows[0]?.required === true) {
|
|
6646
|
-
if (admission.rows[0].protocol
|
|
6951
|
+
if (admission.rows[0].protocol !== null && admission.rows[0].protocol !== void 0 && admission.rows[0].protocol > 3) throw new Error("platform: The database requires a newer Sandbox controller protocol.");
|
|
6647
6952
|
return { sandboxDrain: admission.rows[0].protocol === 3 ? 3 : 2 };
|
|
6648
6953
|
}
|
|
6649
6954
|
}
|
|
@@ -6702,6 +7007,7 @@ async function provisionInstallationServices(input) {
|
|
|
6702
7007
|
const { state, now, releaseDatabaseLock, dependencies, writeRemoteInstallationCheckpoint, checkpointOperation, externalHyperdriveOriginHash, runtime, runtimeDirectory, sourcePlatformVersion, hadPriorWorkers } = input;
|
|
6703
7008
|
const { plan, secrets } = state;
|
|
6704
7009
|
const routingAction = plan.actions.find((action) => action.key === "routing-kv");
|
|
7010
|
+
if (!routingAction) throw new Error("platform: The plan is missing the routing checkpoint action.");
|
|
6705
7011
|
if (routingAction.action === "adopt") throw new Error("platform: The routing checkpoint cannot be adopted.");
|
|
6706
7012
|
if (routingAction.action === "reuse") {
|
|
6707
7013
|
if (!state.manifest.resources.some((resource) => resource.key === routingAction.key) && routingAction.id) {
|
|
@@ -6756,6 +7062,13 @@ async function provisionInstallationServices(input) {
|
|
|
6756
7062
|
const authenticationDatabase = state.manifest.resources.find((resource) => resource.key === "hyperdrive");
|
|
6757
7063
|
if (!authenticationDatabase) throw new Error("platform: The authentication database resource is missing.");
|
|
6758
7064
|
await verifyPlatformAuthenticationDatabase(dependencies.client, plan.account.id, authenticationDatabase, secrets.databaseUrl);
|
|
7065
|
+
await fitPlatformHyperdriveToDatabase({
|
|
7066
|
+
client: dependencies.client,
|
|
7067
|
+
accountId: plan.account.id,
|
|
7068
|
+
resource: authenticationDatabase,
|
|
7069
|
+
readConnectionSlots: releaseDatabaseLock.readConnectionSlots,
|
|
7070
|
+
onProgress: dependencies.onProgress
|
|
7071
|
+
});
|
|
6759
7072
|
state.manifest = await preparePlatformDatabaseSchema(state.manifest, runtime, runtimeDirectory, sourcePlatformVersion, hadPriorWorkers, plan, dependencies, releaseDatabaseLock, now, writeRemoteInstallationCheckpoint, (next) => {
|
|
6760
7073
|
state.manifest = next;
|
|
6761
7074
|
});
|
|
@@ -6770,7 +7083,7 @@ async function provisionInstallationServices(input) {
|
|
|
6770
7083
|
const targetSandboxDrainProtocol = runtime.safetyProtocols.sandboxDrain;
|
|
6771
7084
|
const prepareSandboxDrain = dependencies.prepareSandboxDrain ?? releaseDatabaseLock.prepareSandboxDrain;
|
|
6772
7085
|
if (targetSandboxDrainProtocol >= 1 && !prepareSandboxDrain) throw new Error("platform: The PostgreSQL lifecycle lock cannot establish the sandbox-drain safety checkpoint.");
|
|
6773
|
-
const sandboxDrainPreparation = targetSandboxDrainProtocol >= 1 ? await prepareSandboxDrain(targetSandboxDrainProtocol >= 3 ? 3 : targetSandboxDrainProtocol >= 2 ? 2 : 0) : null;
|
|
7086
|
+
const sandboxDrainPreparation = targetSandboxDrainProtocol >= 1 && prepareSandboxDrain ? await prepareSandboxDrain(targetSandboxDrainProtocol >= 3 ? 3 : targetSandboxDrainProtocol >= 2 ? 2 : 0) : null;
|
|
6774
7087
|
if (sandboxDrainPreparation && sandboxDrainPreparation.admissionProtocol < targetSandboxDrainProtocol) throw new Error("platform: The database did not arm the Sandbox admission protocol required by this runtime.");
|
|
6775
7088
|
const sandboxDrainState = sandboxDrainPreparation?.state ?? "complete";
|
|
6776
7089
|
if (targetSandboxDrainProtocol >= 1 && (state.manifest.safetyProtocols?.sandboxDrain ?? 0) < targetSandboxDrainProtocol) {
|
|
@@ -6849,6 +7162,244 @@ function readLatestWorkerGeneration(manifest) {
|
|
|
6849
7162
|
function hasCompleteWorkerSecretReplacement(updates, requiresEmailSigningSecret) {
|
|
6850
7163
|
return PLATFORM_WORKER_SECRET_UPDATE_NAMES.every((name) => name === "EMAIL_SIGNING_SECRET" && !requiresEmailSigningSecret || typeof updates[name] === "string" && updates[name] !== "");
|
|
6851
7164
|
}
|
|
7165
|
+
// src/cli/platform-security-audits.ts
|
|
7166
|
+
/**
|
|
7167
|
+
* A runtime without the scanner classes must not be paired with the capability: the
|
|
7168
|
+
* API would report security audits as installed and have nothing to run them.
|
|
7169
|
+
*/
|
|
7170
|
+
function assertPlatformSecurityAuditsSupported(deployment, runtime) {
|
|
7171
|
+
if (deployment.capabilities.securityAudits && runtime.securityAudits !== 1) throw new Error("platform: This platform runtime does not include security audits. Use a current packaged runtime, or leave out --security-audits.");
|
|
7172
|
+
}
|
|
7173
|
+
const OWNER_BINDING = "__VOID_SECURITY_SCANNER_OWNER";
|
|
7174
|
+
const PROTOCOL = 1;
|
|
7175
|
+
/** Engines A and C each have a container application and a copied image (API M13b). */
|
|
7176
|
+
const ENGINES = [{
|
|
7177
|
+
slug: "engine-a",
|
|
7178
|
+
binding: "SCANNER_ENGINE_A"
|
|
7179
|
+
}, {
|
|
7180
|
+
slug: "engine-c",
|
|
7181
|
+
binding: "SCANNER_ENGINE_C"
|
|
7182
|
+
}];
|
|
7183
|
+
function securityScannerNames(installationId) {
|
|
7184
|
+
const suffix = createHash("sha256").update(`void-security-scanner:${installationId}`).digest("hex").slice(0, 12);
|
|
7185
|
+
const engine = (slug) => ({
|
|
7186
|
+
application: `void-security-scanner-${slug}-${suffix}`,
|
|
7187
|
+
repository: `void-security-scanner-${slug}-${suffix}`
|
|
7188
|
+
});
|
|
7189
|
+
return {
|
|
7190
|
+
worker: `void-security-scanner-${suffix}`,
|
|
7191
|
+
application: `void-security-scanner-${suffix}`,
|
|
7192
|
+
gate: `void-security-scanner-gate-${suffix}`,
|
|
7193
|
+
copyNamespace: `void-security-copies-${suffix}`,
|
|
7194
|
+
copySandbox: `void-security-copy-sandbox-${suffix}`,
|
|
7195
|
+
copyPrefix: `void-sec-copy-${suffix}-`,
|
|
7196
|
+
engines: {
|
|
7197
|
+
"engine-a": engine("engine-a"),
|
|
7198
|
+
"engine-c": engine("engine-c")
|
|
7199
|
+
}
|
|
7200
|
+
};
|
|
7201
|
+
}
|
|
7202
|
+
function ownerMarker(installationId) {
|
|
7203
|
+
return JSON.stringify({
|
|
7204
|
+
protocol: PROTOCOL,
|
|
7205
|
+
installation: installationId
|
|
7206
|
+
});
|
|
7207
|
+
}
|
|
7208
|
+
function plainText(bindings) {
|
|
7209
|
+
return bindings.find((binding) => binding.type === "plain_text" && binding.name === OWNER_BINDING)?.text;
|
|
7210
|
+
}
|
|
7211
|
+
/** `undefined` when Cloudflare answers 404, or 403 too when `forbiddenOk`. */
|
|
7212
|
+
async function optional(read, forbiddenOk = false) {
|
|
7213
|
+
try {
|
|
7214
|
+
return await read();
|
|
7215
|
+
} catch (error) {
|
|
7216
|
+
if (error instanceof PlatformCloudflareApiError && (error.status === 404 || forbiddenOk && error.status === 403)) return;
|
|
7217
|
+
throw error;
|
|
7218
|
+
}
|
|
7219
|
+
}
|
|
7220
|
+
async function deleteIfPresent(client, path) {
|
|
7221
|
+
await optional(() => client.request(path, { method: "DELETE" }));
|
|
7222
|
+
}
|
|
7223
|
+
const REGISTRY = "registry.cloudflare.com";
|
|
7224
|
+
const MANIFEST_ACCEPT = ["application/vnd.oci.image.manifest.v1+json", "application/vnd.docker.distribution.manifest.v2+json"].join(", ");
|
|
7225
|
+
/**
|
|
7226
|
+
* Removes every manifest in the engine image repositories the API copied into this
|
|
7227
|
+
* account (one per engine, named per installation), then the unreferenced layers.
|
|
7228
|
+
* Returns whether anything was removed.
|
|
7229
|
+
*/
|
|
7230
|
+
async function deleteScannerImages(client, registryFetch, account, repositories, controllerExists) {
|
|
7231
|
+
const read = () => client.request(`/accounts/${encodeURIComponent(account)}/containers/registries/${REGISTRY}/credentials`, {
|
|
7232
|
+
method: "POST",
|
|
7233
|
+
body: JSON.stringify({
|
|
7234
|
+
expiration_minutes: 15,
|
|
7235
|
+
permissions: ["push", "pull"]
|
|
7236
|
+
})
|
|
7237
|
+
});
|
|
7238
|
+
const credentials = controllerExists ? await read() : await optional(read, true);
|
|
7239
|
+
if (!credentials || typeof credentials.username !== "string" || typeof credentials.password !== "string") return false;
|
|
7240
|
+
const auth = `Basic ${Buffer.from(`${credentials.username}:${credentials.password}`).toString("base64")}`;
|
|
7241
|
+
const call = async (url, init = {}) => {
|
|
7242
|
+
const headers = new Headers(init.headers);
|
|
7243
|
+
if (!headers.has("Authorization")) headers.set("Authorization", auth);
|
|
7244
|
+
if (!headers.has("Accept")) headers.set("Accept", MANIFEST_ACCEPT);
|
|
7245
|
+
return registryFetch(url, {
|
|
7246
|
+
...init,
|
|
7247
|
+
headers,
|
|
7248
|
+
signal: AbortSignal.timeout(3e4)
|
|
7249
|
+
});
|
|
7250
|
+
};
|
|
7251
|
+
let removed = false;
|
|
7252
|
+
for (const repository of repositories) {
|
|
7253
|
+
const base = `https://${REGISTRY}/v2/${account}/${repository}`;
|
|
7254
|
+
const list = await call(`${base}/tags/list`);
|
|
7255
|
+
if (list.status === 404) {
|
|
7256
|
+
await list.body?.cancel();
|
|
7257
|
+
continue;
|
|
7258
|
+
}
|
|
7259
|
+
if (!list.ok) {
|
|
7260
|
+
await list.body?.cancel();
|
|
7261
|
+
throw new Error(`platform: Listing the security scanner images failed (HTTP ${list.status}).`);
|
|
7262
|
+
}
|
|
7263
|
+
const { tags } = await list.json();
|
|
7264
|
+
for (const tag of Array.isArray(tags) ? tags : []) {
|
|
7265
|
+
if (typeof tag !== "string") continue;
|
|
7266
|
+
const head = await call(`${base}/manifests/${encodeURIComponent(tag)}`, { method: "HEAD" });
|
|
7267
|
+
await head.body?.cancel();
|
|
7268
|
+
if (head.status === 404) continue;
|
|
7269
|
+
const digest = head.headers.get("docker-content-digest");
|
|
7270
|
+
if (head.status !== 200 || !digest) throw new Error(`platform: Reading security scanner image ${repository}:${tag} failed (HTTP ${head.status}).`);
|
|
7271
|
+
const deleted = await call(`${base}/manifests/${digest}`, { method: "DELETE" });
|
|
7272
|
+
await deleted.body?.cancel();
|
|
7273
|
+
if (!deleted.ok && deleted.status !== 404) throw new Error(`platform: Deleting a security scanner image failed (HTTP ${deleted.status}).`);
|
|
7274
|
+
removed = true;
|
|
7275
|
+
}
|
|
7276
|
+
}
|
|
7277
|
+
if (removed) {
|
|
7278
|
+
const gc = await call(`https://${REGISTRY}/v2/gc/layers`, { method: "PUT" });
|
|
7279
|
+
await gc.body?.cancel();
|
|
7280
|
+
if (!gc.ok) throw new Error(`platform: The registry layer cleanup failed (HTTP ${gc.status}).`);
|
|
7281
|
+
}
|
|
7282
|
+
return removed;
|
|
7283
|
+
}
|
|
7284
|
+
const COPY_PAGE = 100;
|
|
7285
|
+
/**
|
|
7286
|
+
* The copy namespace (Cloudflare deletes any copy still in it), the stores a failed scan
|
|
7287
|
+
* left (the API's hourly sweep stops with the platform; a copy bucket may hold what the
|
|
7288
|
+
* scanned app wrote, and only an empty bucket can be deleted), then the copy sandbox, the
|
|
7289
|
+
* namespace's outbound Worker. Run after the controller, the only Worker that binds them.
|
|
7290
|
+
* The sandbox carries the ownership marker; the rest is named per installation, like the images.
|
|
7291
|
+
*/
|
|
7292
|
+
async function deleteRuntimeCopies(client, accountId, names, marker, controllerExists, kept) {
|
|
7293
|
+
const base = `/accounts/${encodeURIComponent(accountId)}`;
|
|
7294
|
+
const read = (path) => optional(() => client.request(path), !controllerExists);
|
|
7295
|
+
const sandboxPath = `${base}/workers/scripts/${names.copySandbox}`;
|
|
7296
|
+
const sandbox = await read(`${sandboxPath}/settings`);
|
|
7297
|
+
if (sandbox && plainText(sandbox.bindings) !== marker) {
|
|
7298
|
+
kept.push(`security copy sandbox ${names.copySandbox}`);
|
|
7299
|
+
return false;
|
|
7300
|
+
}
|
|
7301
|
+
const mine = (name) => typeof name === "string" && name.startsWith(names.copyPrefix);
|
|
7302
|
+
const pages = async (path, take) => {
|
|
7303
|
+
const found = [];
|
|
7304
|
+
for (let page = 1; page <= 50; page++) {
|
|
7305
|
+
const rows = await read(`${path}per_page=${COPY_PAGE}&page=${page}`) ?? [];
|
|
7306
|
+
found.push(...rows.flatMap((row) => take(row) ?? []));
|
|
7307
|
+
if (rows.length < COPY_PAGE) break;
|
|
7308
|
+
}
|
|
7309
|
+
return found;
|
|
7310
|
+
};
|
|
7311
|
+
const namespacePath = `${base}/workers/dispatch/namespaces/${names.copyNamespace}`;
|
|
7312
|
+
const namespace = await read(namespacePath);
|
|
7313
|
+
const prefix = encodeURIComponent(names.copyPrefix);
|
|
7314
|
+
const buckets = ((await read(`${base}/r2/buckets?name_contains=${prefix}&per_page=1000`))?.buckets ?? []).flatMap((bucket) => mine(bucket.name) ? [bucket.name] : []);
|
|
7315
|
+
const stores = [
|
|
7316
|
+
...await pages(`${base}/d1/database?name=${prefix}&`, (row) => mine(row.name) && typeof row.uuid === "string" ? `d1/database/${row.uuid}` : void 0),
|
|
7317
|
+
...await pages(`${base}/storage/kv/namespaces?`, (row) => mine(row.title) && typeof row.id === "string" ? `storage/kv/namespaces/${row.id}` : void 0),
|
|
7318
|
+
...buckets.map((bucket) => `r2/buckets/${bucket}`)
|
|
7319
|
+
];
|
|
7320
|
+
if (namespace !== void 0) await deleteIfPresent(client, namespacePath);
|
|
7321
|
+
for (const bucket of buckets) await client.emptyR2Bucket(accountId, bucket);
|
|
7322
|
+
for (const store of stores) await deleteIfPresent(client, `${base}/${store}`);
|
|
7323
|
+
if (sandbox) await deleteIfPresent(client, sandboxPath);
|
|
7324
|
+
return namespace !== void 0 || stores.length > 0 || sandbox !== void 0;
|
|
7325
|
+
}
|
|
7326
|
+
/**
|
|
7327
|
+
* Uninstall: the gate first (nothing can call in), then the container applications, the
|
|
7328
|
+
* controller Worker, the runtime copies and the engine images. A Worker or application must
|
|
7329
|
+
* carry this installation's ownership marker; one that is not ours is left alone and reported.
|
|
7330
|
+
*/
|
|
7331
|
+
async function deletePlatformSecurityScanner(client, manifest, registryFetch = (input, init) => fetch(input, init)) {
|
|
7332
|
+
if (!manifest.deployment.capabilities.securityAudits) return {
|
|
7333
|
+
deleted: [],
|
|
7334
|
+
kept: []
|
|
7335
|
+
};
|
|
7336
|
+
const account = encodeURIComponent(manifest.account.id);
|
|
7337
|
+
const names = securityScannerNames(manifest.id);
|
|
7338
|
+
const marker = ownerMarker(manifest.id);
|
|
7339
|
+
const deleted = [];
|
|
7340
|
+
const kept = [];
|
|
7341
|
+
const gatePath = `/accounts/${account}/workers/dispatch/namespaces/${encodeURIComponent(manifest.deployment.resources.dispatchNamespace)}/scripts/${names.gate}`;
|
|
7342
|
+
if (await optional(() => client.request(gatePath)) !== void 0) {
|
|
7343
|
+
if (plainText(await client.request(`${gatePath}/bindings`)) === marker) {
|
|
7344
|
+
await deleteIfPresent(client, gatePath);
|
|
7345
|
+
deleted.push("gate");
|
|
7346
|
+
} else kept.push(`security scanner gate ${names.gate}`);
|
|
7347
|
+
}
|
|
7348
|
+
const workerPath = `/accounts/${account}/workers/scripts/${names.worker}`;
|
|
7349
|
+
const settings = await optional(() => client.request(`${workerPath}/settings`));
|
|
7350
|
+
const targets = [{
|
|
7351
|
+
name: names.application,
|
|
7352
|
+
binding: "SCANNER"
|
|
7353
|
+
}, ...ENGINES.map((engine) => ({
|
|
7354
|
+
name: names.engines[engine.slug].application,
|
|
7355
|
+
binding: engine.binding
|
|
7356
|
+
}))];
|
|
7357
|
+
const found = [];
|
|
7358
|
+
for (const target of targets) {
|
|
7359
|
+
const listApplications = () => client.request(`/accounts/${account}/containers/applications?name=${encodeURIComponent(target.name)}`);
|
|
7360
|
+
const application = (settings ? await listApplications() : await optional(listApplications, true) ?? []).find((entry) => entry.name === target.name);
|
|
7361
|
+
if (application) found.push({
|
|
7362
|
+
...target,
|
|
7363
|
+
id: application.id,
|
|
7364
|
+
namespace: application.durable_objects?.namespace_id
|
|
7365
|
+
});
|
|
7366
|
+
}
|
|
7367
|
+
const repositories = ENGINES.map((engine) => names.engines[engine.slug].repository);
|
|
7368
|
+
if (!settings) {
|
|
7369
|
+
for (const application of found) kept.push(`security scanner container application ${application.name}`);
|
|
7370
|
+
if (await deleteRuntimeCopies(client, manifest.account.id, names, marker, false, kept)) deleted.push("runtime copies");
|
|
7371
|
+
if (await deleteScannerImages(client, registryFetch, manifest.account.id, repositories, false)) deleted.push("scanner images");
|
|
7372
|
+
return {
|
|
7373
|
+
deleted,
|
|
7374
|
+
kept
|
|
7375
|
+
};
|
|
7376
|
+
}
|
|
7377
|
+
if (plainText(settings.bindings) !== marker) {
|
|
7378
|
+
kept.push(`security scanner controller ${names.worker}`);
|
|
7379
|
+
for (const application of found) kept.push(`security scanner container application ${application.name}`);
|
|
7380
|
+
return {
|
|
7381
|
+
deleted,
|
|
7382
|
+
kept
|
|
7383
|
+
};
|
|
7384
|
+
}
|
|
7385
|
+
let removedApplication = false;
|
|
7386
|
+
for (const application of found) {
|
|
7387
|
+
const namespace = settings.bindings.find((binding) => binding.type === "durable_object_namespace" && binding.name === application.binding)?.namespace_id;
|
|
7388
|
+
if (namespace !== void 0 && application.namespace === namespace) {
|
|
7389
|
+
await deleteIfPresent(client, `/accounts/${account}/containers/applications/${application.id}`);
|
|
7390
|
+
removedApplication = true;
|
|
7391
|
+
} else kept.push(`security scanner container application ${application.name}`);
|
|
7392
|
+
}
|
|
7393
|
+
if (removedApplication) deleted.push("container application");
|
|
7394
|
+
await deleteIfPresent(client, workerPath);
|
|
7395
|
+
deleted.push("controller");
|
|
7396
|
+
if (await deleteRuntimeCopies(client, manifest.account.id, names, marker, true, kept)) deleted.push("runtime copies");
|
|
7397
|
+
if (await deleteScannerImages(client, registryFetch, manifest.account.id, repositories, true)) deleted.push("scanner images");
|
|
7398
|
+
return {
|
|
7399
|
+
deleted,
|
|
7400
|
+
kept
|
|
7401
|
+
};
|
|
7402
|
+
}
|
|
6852
7403
|
// src/cli/platform-installer.ts
|
|
6853
7404
|
async function recoverFailedPlatformInstallation(error, state) {
|
|
6854
7405
|
const { plan, dependencies, workerTrafficGuarded, workerDeploymentCommitted, workerRollbacks, authenticationEnforcementActive, authenticationProtocolTransition, workerCutoverGeneration, previousPublicEndpoints, operationStarted, now, writeRemoteInstallationCheckpoint } = state;
|
|
@@ -6902,6 +7453,7 @@ async function installPlatform(plan, secrets, existing, dependencies) {
|
|
|
6902
7453
|
const runtime = resolvedRuntime.manifest;
|
|
6903
7454
|
if (plan.deployment.appAccess && runtime.appAccessSetup !== 1) throw new Error("platform: This runtime does not support the installation’s app access setup.");
|
|
6904
7455
|
assertPlatformRuntimeLogsSupported(plan.deployment, runtime);
|
|
7456
|
+
assertPlatformSecurityAuditsSupported(plan.deployment, runtime);
|
|
6905
7457
|
assertPlatformStorageSupported(plan.deployment, runtime);
|
|
6906
7458
|
const hasEmailGatewayArtifact = runtime.artifacts.emailGateway !== void 0;
|
|
6907
7459
|
if (existing?.steps.some((step) => step.key === "private-previews-initialized:v1") && runtime.privatePreviews !== 1) throw new Error("platform: This installation has private previews. Use a runtime with private preview support.");
|
|
@@ -7124,6 +7676,7 @@ async function installPlatform(plan, secrets, existing, dependencies) {
|
|
|
7124
7676
|
deployment: state.plan.deployment,
|
|
7125
7677
|
deploymentExecution: runtime.deploymentExecution,
|
|
7126
7678
|
healthProbeToken: createPlatformHealthProbeToken(state.manifest.ownershipNonce),
|
|
7679
|
+
securityScanScheduler: runtime.securityAudits === 1,
|
|
7127
7680
|
installationId: state.manifest.id,
|
|
7128
7681
|
ownershipNonce: state.manifest.ownershipNonce,
|
|
7129
7682
|
platformVersion: version,
|
|
@@ -7145,7 +7698,10 @@ async function installPlatform(plan, secrets, existing, dependencies) {
|
|
|
7145
7698
|
publicEndpoints: !preserveDisabled,
|
|
7146
7699
|
trafficState: preserveDisabled ? "staging" : "enabled"
|
|
7147
7700
|
});
|
|
7148
|
-
const outsideChangeConfigs = workerKeys.
|
|
7701
|
+
const outsideChangeConfigs = workerKeys.flatMap((key) => {
|
|
7702
|
+
const config = enabledConfigs[key];
|
|
7703
|
+
return dependencies.replaceOutsideChanges?.includes(String(config.name)) ? [config] : [];
|
|
7704
|
+
});
|
|
7149
7705
|
if (outsideChangeConfigs.length > 0) await dependencies.uploadOutsideChanges?.(outsideChangeConfigs);
|
|
7150
7706
|
if (requiresTrafficGuard) {
|
|
7151
7707
|
await dependencies.client.putKvValue(state.plan.account.id, requireId(ids, "routing-kv"), PLATFORM_DISABLED_KEY, PLATFORM_DISABLED_VALUE);
|
|
@@ -7319,14 +7875,16 @@ async function installPlatform(plan, secrets, existing, dependencies) {
|
|
|
7319
7875
|
await writeRemoteInstallationCheckpoint(dependencies.client, state.plan, state.manifest);
|
|
7320
7876
|
}
|
|
7321
7877
|
if (state.plan.deployment.appAccess && !state.manifest.steps.some((step) => step.key === "app-access-initialized:v1")) {
|
|
7878
|
+
const { appAccessSetupJson, appAccessSetupToken } = state.secrets;
|
|
7879
|
+
if (!appAccessSetupJson || !appAccessSetupToken) throw new Error("platform: The deployed-app access setup material is missing.");
|
|
7322
7880
|
dependencies.onProgress?.("Configuring and verifying deployed-app access");
|
|
7323
7881
|
try {
|
|
7324
7882
|
await (dependencies.initializeAppAccess ?? initializeInstalledAppAccess)({
|
|
7325
7883
|
apiUrl: state.plan.apiUrl,
|
|
7326
7884
|
installationId: state.manifest.id,
|
|
7327
7885
|
probeToken: createPlatformHealthProbeToken(state.manifest.ownershipNonce),
|
|
7328
|
-
setupJson:
|
|
7329
|
-
setupToken:
|
|
7886
|
+
setupJson: appAccessSetupJson,
|
|
7887
|
+
setupToken: appAccessSetupToken
|
|
7330
7888
|
});
|
|
7331
7889
|
} catch (error) {
|
|
7332
7890
|
if (error instanceof PlatformAppAccessCredentialError) {
|
|
@@ -7344,7 +7902,7 @@ async function installPlatform(plan, secrets, existing, dependencies) {
|
|
|
7344
7902
|
state.manifest = recordInstallationStep(state.manifest, {
|
|
7345
7903
|
key: "app-access-initialized:v1",
|
|
7346
7904
|
completedAt: now(),
|
|
7347
|
-
resultHash: hash(
|
|
7905
|
+
resultHash: hash(appAccessSetupJson)
|
|
7348
7906
|
}, now());
|
|
7349
7907
|
writeInstallationManifest(state.manifest);
|
|
7350
7908
|
await writeRemoteInstallationCheckpoint(dependencies.client, state.plan, state.manifest);
|
|
@@ -7390,6 +7948,7 @@ async function installPlatform(plan, secrets, existing, dependencies) {
|
|
|
7390
7948
|
zoneNameServers: zone?.nameServers ?? []
|
|
7391
7949
|
};
|
|
7392
7950
|
}
|
|
7951
|
+
if (!prepareSandboxDrain) throw new Error("platform: No sandbox drain checkpoint. Traffic remains disabled.");
|
|
7393
7952
|
if ((await prepareSandboxDrain()).state !== "complete") throw new Error("platform: Sandbox drain completion changed while it was being verified. Traffic remains disabled.");
|
|
7394
7953
|
}
|
|
7395
7954
|
const emailOperationId = (await enableInstallationServices({
|
|
@@ -7483,12 +8042,11 @@ async function selectInstallationAuthentication(file, recorded, choices = {}) {
|
|
|
7483
8042
|
if (file) {
|
|
7484
8043
|
const input = JSON.parse(await readFile(file, "utf8"));
|
|
7485
8044
|
if (!input || typeof input !== "object" || Array.isArray(input) || !("connections" in input) || !Array.isArray(input.connections) || !input.connections.length || input.connections.length > 32) throw new Error("platform: An authentication file must define between 1 and 32 connections.");
|
|
7486
|
-
|
|
7487
|
-
if (entries.some((entry) => !entry || typeof entry !== "object" || !entry.configuration || typeof entry.configuration !== "object" || Array.isArray(entry.configuration) || !PLATFORM_LOGIN_KINDS.includes(entry.configuration.kind) || entry.clientSecret !== void 0 || entry.configuration.clientSecret !== void 0)) throw new Error("platform: Each connection needs a supported configuration and a clientSecretEnv reference; plaintext secrets are not accepted in the file.");
|
|
8045
|
+
if (input.connections.some((entry) => !entry || typeof entry !== "object" || !entry.configuration || typeof entry.configuration !== "object" || Array.isArray(entry.configuration) || !PLATFORM_LOGIN_KINDS.includes(entry.configuration.kind) || entry.clientSecret !== void 0 || entry.configuration.clientSecret !== void 0)) throw new Error("platform: Each connection needs a supported configuration and a clientSecretEnv reference; plaintext secrets are not accepted in the file.");
|
|
7488
8046
|
const selected = input;
|
|
7489
8047
|
if (selected.cloudflareAccess !== void 0) selected.cloudflareAccess = parsePlatformAccessSetupSpec(selected.cloudflareAccess);
|
|
7490
8048
|
const authentication = {
|
|
7491
|
-
providers: [...new Set(
|
|
8049
|
+
providers: [...new Set(selected.connections.map((entry) => entry.configuration.kind))],
|
|
7492
8050
|
configurable: true,
|
|
7493
8051
|
...selected.protection ? { accessProtection: true } : {}
|
|
7494
8052
|
};
|
|
@@ -7556,9 +8114,11 @@ async function collectInstallationAuthentication(selection, plan, checkpoint, sa
|
|
|
7556
8114
|
}));
|
|
7557
8115
|
const connections = [];
|
|
7558
8116
|
const accessEntry = entries.find((entry) => entry.configuration.kind === "cloudflare-access");
|
|
7559
|
-
const
|
|
8117
|
+
const prepareAccess = access && (selection.authentication.accessProtection || accessEntry && (!selection.file || selection.file.cloudflareAccess));
|
|
8118
|
+
const dashboardUrl = prepareAccess ? platformDashboardUrl(plan.deployment) : void 0;
|
|
8119
|
+
const prepared = access && prepareAccess ? await preparePlatformAccessSetup({
|
|
7560
8120
|
plan,
|
|
7561
|
-
...
|
|
8121
|
+
...dashboardUrl ? { additionalOrigins: [dashboardUrl] } : {},
|
|
7562
8122
|
ownershipNonce: access.ownershipNonce,
|
|
7563
8123
|
protection: !!selection.authentication.accessProtection,
|
|
7564
8124
|
...accessEntry ? { login: {
|
|
@@ -7706,16 +8266,18 @@ function authenticationSetupRequestHash(setupJson) {
|
|
|
7706
8266
|
const { resetPending: _, ...configuration } = parsePlatformAuthenticationSetup(JSON.parse(setupJson));
|
|
7707
8267
|
return createHash("sha256").update(JSON.stringify(configuration)).digest("hex");
|
|
7708
8268
|
}
|
|
8269
|
+
const connections = (entries) => entries.map(({ configuration: { id, kind } }) => JSON.stringify([id || defaultConnectionId(kind), kind])).sort().join("\n");
|
|
7709
8270
|
/**
|
|
7710
8271
|
* Read a repair login file. It may change login settings, not methods or Access
|
|
7711
8272
|
* protection: it lists the same connection IDs and kinds as the saved setup.
|
|
7712
8273
|
*/
|
|
7713
8274
|
async function readLoginReplacementFile(file, authentication, setupJson) {
|
|
7714
8275
|
const selection = await selectInstallationAuthentication(file);
|
|
8276
|
+
const selected = selection.file;
|
|
8277
|
+
if (!selected) throw new Error("platform: Repair requires a login settings file.");
|
|
7715
8278
|
const installed = parsePlatformAuthenticationSetup(JSON.parse(setupJson)).connections;
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
return selection.file;
|
|
8279
|
+
if (connections(selected.connections) !== connections(installed) || !!selection.authentication.accessProtection !== !!authentication.accessProtection) throw new Error(`platform: Repair changes login settings, not which login methods or Access protection the platform uses. List each installed connection with its ID: ${installed.map(({ configuration }) => configuration.id).join(", ")}.`);
|
|
8280
|
+
return selected;
|
|
7719
8281
|
}
|
|
7720
8282
|
/**
|
|
7721
8283
|
* New login settings for a first administrator setup that is still pending,
|
|
@@ -7805,7 +8367,7 @@ function unreadablePlatformWorker(workerName, error) {
|
|
|
7805
8367
|
return new Error([
|
|
7806
8368
|
`platform: Void cannot read the platform Worker ${workerName} (${answer}), so it cannot find changes made outside Void.`,
|
|
7807
8369
|
NO_WORKER_CHANGED,
|
|
7808
|
-
status === 401 || status === 403 ?
|
|
8370
|
+
status === 401 || status === 403 ? `Make sure that the Cloudflare API token has ${PLATFORM_WORKERS_PERMISSION} for this account. Then run the command again.` : "Run the command again."
|
|
7809
8371
|
].join(" "), { cause: error });
|
|
7810
8372
|
}
|
|
7811
8373
|
/**
|
|
@@ -8007,7 +8569,7 @@ function readSavedPlatformInstallPlan(path, id) {
|
|
|
8007
8569
|
return plan;
|
|
8008
8570
|
} catch (error) {
|
|
8009
8571
|
if (error.code === "ENOENT") throw error;
|
|
8010
|
-
throw new Error(`platform: Invalid saved installation plan ${path}: ${error instanceof Error ? error.message : String(error)}
|
|
8572
|
+
throw new Error(`platform: Invalid saved installation plan ${path}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
8011
8573
|
}
|
|
8012
8574
|
}
|
|
8013
8575
|
function findSavedPlatformInstallPlan(account, name, directory = platformRegistryDirectory()) {
|
|
@@ -8100,17 +8662,23 @@ function resolvePlatformInstallDatabaseUrl(checkpoint, manifest = null) {
|
|
|
8100
8662
|
}
|
|
8101
8663
|
return explicit || recorded;
|
|
8102
8664
|
}
|
|
8665
|
+
const assertNewNameAvailable = (slug) => {
|
|
8666
|
+
const collision = listInstallationManifests().find((manifest) => manifest.status !== "uninstalled" && manifest.deployment.installationSlug === slug);
|
|
8667
|
+
if (collision && !isPlatformInstallInProgress(collision)) throw new Error(`platform: ${collision.deployment.displayName} (${slug}) already exists (${collision.status}). Run \`void platform status ${collision.id}\` to inspect it.`);
|
|
8668
|
+
assertPlatformInstallationSlugAvailable(slug);
|
|
8669
|
+
};
|
|
8103
8670
|
async function runPlatformLifecycleCommand(commandArgs) {
|
|
8104
8671
|
if (commandArgs.subcommand === "domain") {
|
|
8105
|
-
const { runPlatformDomainCommand } = await import("./platform-domain-
|
|
8672
|
+
const { runPlatformDomainCommand } = await import("./platform-domain-DJSznNTA.mjs");
|
|
8106
8673
|
await runPlatformDomainCommand(commandArgs);
|
|
8107
8674
|
return;
|
|
8108
8675
|
}
|
|
8109
8676
|
if (commandArgs.subcommand === "discover") {
|
|
8110
8677
|
log.step("Preparing platform discovery");
|
|
8111
|
-
const
|
|
8678
|
+
const credential = await resolvePlatformCloudflareCredential();
|
|
8679
|
+
const client = new PlatformCloudflareClient(credential.token, { credential: platformOperatorCredentialLabel(credential) });
|
|
8112
8680
|
const accountId = await selectAccount(await withPlatformProgress("Reading Cloudflare accounts", () => readAccounts(client)), commandArgs.account);
|
|
8113
|
-
const { recoverPlatformInstallations } = await import("./platform-recovery-
|
|
8681
|
+
const { recoverPlatformInstallations } = await import("./platform-recovery-CnzBbudV.mjs");
|
|
8114
8682
|
const recovered = await withPlatformProgress("Discovering platform installations", () => recoverPlatformInstallations(client, accountId, void 0, commandArgs.selector));
|
|
8115
8683
|
if (recovered.length === 0) {
|
|
8116
8684
|
log.info(`No recoverable Void platform installations were found in ${accountId}.`);
|
|
@@ -8121,7 +8689,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8121
8689
|
return;
|
|
8122
8690
|
}
|
|
8123
8691
|
if (commandArgs.subcommand !== "install") {
|
|
8124
|
-
const { runInstalledPlatformCommand } = await import("./platform-management-
|
|
8692
|
+
const { runInstalledPlatformCommand } = await import("./platform-management-BwHkz46V.mjs");
|
|
8125
8693
|
await runInstalledPlatformCommand(commandArgs);
|
|
8126
8694
|
return;
|
|
8127
8695
|
}
|
|
@@ -8143,15 +8711,10 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8143
8711
|
selectedInstall = true;
|
|
8144
8712
|
selectedDraft = isPlatformSetupDraft(manifest);
|
|
8145
8713
|
};
|
|
8146
|
-
const assertNewNameAvailable = (slug) => {
|
|
8147
|
-
const collision = listInstallationManifests().find((manifest) => manifest.status !== "uninstalled" && manifest.deployment.installationSlug === slug);
|
|
8148
|
-
if (collision && !isPlatformInstallInProgress(collision)) throw new Error(`platform: ${collision.deployment.displayName} (${slug}) already exists (${collision.status}). Run \`void platform status ${collision.id}\` to inspect it.`);
|
|
8149
|
-
assertPlatformInstallationSlugAvailable(slug);
|
|
8150
|
-
};
|
|
8151
8714
|
if (!args.resume && process.stdin.isTTY) {
|
|
8152
8715
|
const installs = resumableInstalls().filter((manifest) => !args.name || manifest.deployment.installationSlug === normalizeInstallationSlug(args.name));
|
|
8153
8716
|
const manifests = listInstallationManifests();
|
|
8154
|
-
const savedPlans = !args.applicationDomain && !args.workersDev && !args.zone && !args.displayName && !args.hyperdrive && !args.controlPlaneDomain && !args.noControlPlaneDomain && !args.authConfig && !args.loginMethods && !args.runtime && args.accessProtection === void 0 && args.appAccess === void 0 && !args.dedicatedZoneSpecified && args.dashboardUrl === void 0 && !args.customDomains && args.runtimeLogs === void 0 && args.storageLocation === void 0 ? listSavedPlatformInstallPlans().filter((saved) => (!args.name || saved.args.name === normalizeInstallationSlug(args.name)) && (!args.account || saved.args.account === args.account || saved.accountName.toLowerCase() === args.account.toLowerCase()) && !manifests.some((manifest) => manifest.status !== "uninstalled" && manifest.account.id === saved.args.account && manifest.deployment.installationSlug === saved.args.name)) : [];
|
|
8717
|
+
const savedPlans = !args.applicationDomain && !args.workersDev && !args.zone && !args.displayName && !args.hyperdrive && !args.controlPlaneDomain && !args.noControlPlaneDomain && !args.authConfig && !args.loginMethods && !args.runtime && args.accessProtection === void 0 && args.appAccess === void 0 && !args.dedicatedZoneSpecified && args.dashboardUrl === void 0 && !args.customDomains && !args.securityAudits && args.runtimeLogs === void 0 && args.storageLocation === void 0 ? listSavedPlatformInstallPlans().filter((saved) => (!args.name || saved.args.name === normalizeInstallationSlug(args.name)) && (!args.account || saved.args.account === args.account || saved.accountName.toLowerCase() === args.account.toLowerCase()) && !manifests.some((manifest) => manifest.status !== "uninstalled" && manifest.account.id === saved.args.account && manifest.deployment.installationSlug === saved.args.name)) : [];
|
|
8155
8718
|
if (installs.length > 0 || savedPlans.length > 0) {
|
|
8156
8719
|
const choice = await select({
|
|
8157
8720
|
message: "Continue a previous platform install?",
|
|
@@ -8238,12 +8801,12 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8238
8801
|
if (existing.endpoints.apiUrl && !readPendingInstallationSecrets(existing)) throw new Error(`platform: Installation ${existing.id} has already been deployed. Use \`void platform repair ${existing.id}\` or \`void platform upgrade ${existing.id}\` instead.`);
|
|
8239
8802
|
return existing.deployment.installationSlug;
|
|
8240
8803
|
});
|
|
8241
|
-
let client = new PlatformCloudflareClient(operatorCredential.token);
|
|
8804
|
+
let client = new PlatformCloudflareClient(operatorCredential.token, { credential: platformOperatorCredentialLabel(operatorCredential) });
|
|
8242
8805
|
const accounts = await withPlatformProgress("Reading Cloudflare accounts", () => readAccounts(client));
|
|
8243
8806
|
const accountId = existing ? existing.account.id : await selectAccount(accounts, args.account);
|
|
8244
8807
|
if (existing && args.account && await selectAccount(accounts, args.account) !== existing.account.id) throw new Error("platform: The installation belongs to a different Cloudflare account.");
|
|
8245
8808
|
const recorded = existing?.deployment;
|
|
8246
|
-
if (existing && isPlatformSetupDraft(existing) && (args.applicationDomain && normalizeApplicationDomain(args.applicationDomain) !== recorded.application.baseDomain || args.zone && normalizeApplicationDomain(args.zone) !== recorded.application.zoneName || args.workersDev && !!recorded.application.zoneName || args.controlPlaneDomain && normalizeApplicationDomain(args.controlPlaneDomain) !== recorded.controlPlane.apiHostname || args.dedicatedZone && !recorded.application.dedicatedZone)) throw new Error("platform: These options differ from the saved setup. Resume its recorded configuration or choose another installation name.");
|
|
8809
|
+
if (existing && recorded && isPlatformSetupDraft(existing) && (args.applicationDomain && normalizeApplicationDomain(args.applicationDomain) !== recorded.application.baseDomain || args.zone && normalizeApplicationDomain(args.zone) !== recorded.application.zoneName || args.workersDev && !!recorded.application.zoneName || args.controlPlaneDomain && normalizeApplicationDomain(args.controlPlaneDomain) !== recorded.controlPlane.apiHostname || args.dedicatedZone && !recorded.application.dedicatedZone)) throw new Error("platform: These options differ from the saved setup. Resume its recorded configuration or choose another installation name.");
|
|
8247
8810
|
let workersDev = !!recorded?.application.workersDev && !recorded.application.zoneName || args.workersDev === true;
|
|
8248
8811
|
if (!recorded && !args.workersDev && !args.applicationDomain && !args.zone && process.stdin.isTTY) {
|
|
8249
8812
|
const mode = await select({
|
|
@@ -8295,7 +8858,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8295
8858
|
progress?.stop("Read the saved installation.");
|
|
8296
8859
|
progress = void 0;
|
|
8297
8860
|
if (authoritative) {
|
|
8298
|
-
const { selectAuthoritativePlatformManifest } = await import("./platform-management-
|
|
8861
|
+
const { selectAuthoritativePlatformManifest } = await import("./platform-management-BwHkz46V.mjs");
|
|
8299
8862
|
const selected = selectAuthoritativePlatformManifest(existing, authoritative);
|
|
8300
8863
|
authoritativeProvisionIntents = true;
|
|
8301
8864
|
if (!args.plan && JSON.stringify(selected) !== JSON.stringify(existing)) writeInstallationManifest(selected);
|
|
@@ -8422,6 +8985,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8422
8985
|
controlPlaneDomain,
|
|
8423
8986
|
...args.dashboardUrl !== void 0 ? { dashboardUrl: args.dashboardUrl } : {},
|
|
8424
8987
|
...args.customDomains ? { customDomains: true } : {},
|
|
8988
|
+
...args.securityAudits ? { securityAudits: true } : {},
|
|
8425
8989
|
dedicatedZone,
|
|
8426
8990
|
displayName,
|
|
8427
8991
|
...externalHyperdrive ? { externalHyperdrive } : {},
|
|
@@ -8442,6 +9006,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8442
9006
|
};
|
|
8443
9007
|
let plan = await withPlatformProgress("Preparing installation plan", () => createPlatformInstallPlan(client, planInput, existing, planOptions));
|
|
8444
9008
|
assertPlatformRuntimeLogsSupported(plan.deployment, runtime.manifest);
|
|
9009
|
+
assertPlatformSecurityAuditsSupported(plan.deployment, runtime.manifest);
|
|
8445
9010
|
assertPlatformStorageSupported(plan.deployment, runtime.manifest);
|
|
8446
9011
|
const commandOptions = {
|
|
8447
9012
|
commandName: cliCommandName(),
|
|
@@ -8453,6 +9018,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8453
9018
|
controlPlaneDomain,
|
|
8454
9019
|
...args.dashboardUrl !== void 0 ? { dashboardUrl: args.dashboardUrl } : {},
|
|
8455
9020
|
...args.customDomains ? { customDomains: true } : {},
|
|
9021
|
+
...args.securityAudits ? { securityAudits: true } : {},
|
|
8456
9022
|
dedicatedZone,
|
|
8457
9023
|
workersDev,
|
|
8458
9024
|
authConfig: args.authConfig,
|
|
@@ -8499,6 +9065,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8499
9065
|
let managementApiToken = operatorCredential.source === "oauth" ? checkpoint?.managementApiToken || "" : "";
|
|
8500
9066
|
if (needsManagementToken || managementApiToken) {
|
|
8501
9067
|
let token = managementApiToken;
|
|
9068
|
+
let tokenSource = token ? "saved" : "entered";
|
|
8502
9069
|
let openedManagementPage = false;
|
|
8503
9070
|
const forgetRejectedManagementToken = () => {
|
|
8504
9071
|
managementApiToken = "";
|
|
@@ -8515,8 +9082,15 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8515
9082
|
openedManagementPage = true;
|
|
8516
9083
|
}
|
|
8517
9084
|
token = (await promptSecret("Paste management API token:", true, (value) => value.trim() ? void 0 : "A value is required.")).trim();
|
|
9085
|
+
tokenSource = "entered";
|
|
8518
9086
|
}
|
|
8519
|
-
const management = new PlatformCloudflareClient(token, {
|
|
9087
|
+
const management = new PlatformCloudflareClient(token, {
|
|
9088
|
+
apiBase: client.apiBaseUrl,
|
|
9089
|
+
credential: {
|
|
9090
|
+
role: "management",
|
|
9091
|
+
source: tokenSource
|
|
9092
|
+
}
|
|
9093
|
+
});
|
|
8520
9094
|
try {
|
|
8521
9095
|
if (!(await management.listAccounts()).some((account) => account.id === accountId)) {
|
|
8522
9096
|
forgetRejectedManagementToken();
|
|
@@ -8532,8 +9106,14 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8532
9106
|
break;
|
|
8533
9107
|
} catch (error) {
|
|
8534
9108
|
if (!isPlatformTokenAuthorizationError(error)) throw error;
|
|
8535
|
-
const details =
|
|
8536
|
-
|
|
9109
|
+
const details = [];
|
|
9110
|
+
const listed = /* @__PURE__ */ new Set();
|
|
9111
|
+
for (let cause = error, depth = 0; depth < 5 && cause instanceof Error; depth++, cause = cause.cause) {
|
|
9112
|
+
if (listed.has(cause)) continue;
|
|
9113
|
+
if (cause instanceof AggregateError) for (const listedError of cause.errors) listed.add(listedError);
|
|
9114
|
+
const message = cause.message.replaceAll(token, "[redacted]");
|
|
9115
|
+
if (!details.some((detail) => detail.includes(message))) details.push(message);
|
|
9116
|
+
}
|
|
8537
9117
|
forgetRejectedManagementToken();
|
|
8538
9118
|
log.warn([...details, "Check the token permissions and account/zone scope, then paste a replacement."].join("\n"));
|
|
8539
9119
|
}
|
|
@@ -8577,17 +9157,22 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8577
9157
|
let rejectedSavedRuntimeToken = false;
|
|
8578
9158
|
const verifyRuntimeToken = async (token) => {
|
|
8579
9159
|
let checkingRuntimePermissions = true;
|
|
9160
|
+
const credential = {
|
|
9161
|
+
role: "runtime",
|
|
9162
|
+
source: token === process.env.VOID_PLATFORM_RUNTIME_CLOUDFLARE_API_TOKEN ? "environment" : token === values.cloudflareApiToken ? "saved" : "entered"
|
|
9163
|
+
};
|
|
8580
9164
|
try {
|
|
8581
|
-
await verifyPlatformRuntimeTokenPermissions(new PlatformCloudflareClient(token), {
|
|
9165
|
+
await verifyPlatformRuntimeTokenPermissions(new PlatformCloudflareClient(token, { credential }), {
|
|
8582
9166
|
accountId,
|
|
8583
9167
|
applicationDomain,
|
|
9168
|
+
credential,
|
|
8584
9169
|
customDomains: plan.deployment.capabilities.customDomains,
|
|
8585
9170
|
...plan.deployment.capabilities.email && plan.deployment.emailSharedZoneId ? { emailZoneId: plan.deployment.emailSharedZoneId } : {},
|
|
8586
9171
|
zoneId: plan.zone?.id ?? null
|
|
8587
9172
|
});
|
|
8588
9173
|
checkingRuntimePermissions = false;
|
|
8589
9174
|
if (plan.actions.some((action) => action.action === "inspect")) {
|
|
8590
|
-
client = client.withAiGatewayToken(token);
|
|
9175
|
+
client = client.withAiGatewayToken(token, credential);
|
|
8591
9176
|
plan = await verifyPlatformAiGatewayPlan(client, planInput, existing, plan, authoritativeProvisionIntents);
|
|
8592
9177
|
}
|
|
8593
9178
|
} catch (error) {
|
|
@@ -8766,7 +9351,7 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8766
9351
|
})).actions.filter((action) => action.kind === "worker"),
|
|
8767
9352
|
revalidateBeforeWorkerDeploy: (manifest, action) => revalidatePlatformInstallAction(client, plan, manifest, action),
|
|
8768
9353
|
verifyExistingOwnership: async (manifest, databaseCheckpointExists) => {
|
|
8769
|
-
const { verifyPlatformInstallationOwnership } = await import("./platform-management-
|
|
9354
|
+
const { verifyPlatformInstallationOwnership } = await import("./platform-management-BwHkz46V.mjs");
|
|
8770
9355
|
const retainedReplacementKeys = new Set(plan.actions.filter((action) => {
|
|
8771
9356
|
const previous = manifest.resources.find((resource) => resource.key === action.key);
|
|
8772
9357
|
return action.action === "create" && previous && previous.name !== action.name;
|
|
@@ -8831,8 +9416,15 @@ async function runPlatformLifecycleCommand(commandArgs) {
|
|
|
8831
9416
|
}
|
|
8832
9417
|
}
|
|
8833
9418
|
function isPlatformTokenAuthorizationError(error, requestPathIncludes) {
|
|
8834
|
-
|
|
8835
|
-
|
|
9419
|
+
return !!findPlatformTokenAuthorizationError(error, requestPathIncludes);
|
|
9420
|
+
}
|
|
9421
|
+
function findPlatformTokenAuthorizationError(error, requestPathIncludes) {
|
|
9422
|
+
for (let depth = 0; depth < 5 && error instanceof Error; depth++, error = error.cause) if (error instanceof PlatformCloudflareApiError && [401, 403].includes(error.status) && (!requestPathIncludes || error.requestPath?.includes(requestPathIncludes))) return error;
|
|
9423
|
+
}
|
|
9424
|
+
/** What the client said about the AI Gateway credential it used, if it knew it. */
|
|
9425
|
+
function platformCredentialHelpInChain(error) {
|
|
9426
|
+
const denied = findPlatformTokenAuthorizationError(error, "/ai-gateway/");
|
|
9427
|
+
return denied?.credential ? platformCredentialHelp(denied.credential, denied.status, denied.requestPath) : void 0;
|
|
8836
9428
|
}
|
|
8837
9429
|
function formatPlatformRuntime(runtime) {
|
|
8838
9430
|
return [
|
|
@@ -8852,7 +9444,10 @@ async function verifyPlatformAiGatewayPlan(client, input, existing, preview, aut
|
|
|
8852
9444
|
deploymentExecution: preview.actions.some((entry) => entry.key === "deployment-queue")
|
|
8853
9445
|
});
|
|
8854
9446
|
} catch (error) {
|
|
8855
|
-
if (isPlatformTokenAuthorizationError(error, "/ai-gateway/"))
|
|
9447
|
+
if (isPlatformTokenAuthorizationError(error, "/ai-gateway/")) {
|
|
9448
|
+
const help = platformCredentialHelpInChain(error);
|
|
9449
|
+
throw new Error(help ? `platform: The runtime token could not verify AI Gateway access. ${help} No platform resources were created.` : "platform: The runtime token could not verify AI Gateway access. Include Account → AI Gateway → Edit for this account, then retry. No platform resources were created.", { cause: error });
|
|
9450
|
+
}
|
|
8856
9451
|
throw error;
|
|
8857
9452
|
}
|
|
8858
9453
|
assertPlatformInstallPlanUnchanged(preview, verified, "AI Gateway access");
|
|
@@ -8933,4 +9528,4 @@ async function promptSecret(message, masked = true, validate, placeholder) {
|
|
|
8933
9528
|
if (isCancel(value) || typeof value === "symbol") throw new Error("platform: Cancelled.");
|
|
8934
9529
|
return value;
|
|
8935
9530
|
}
|
|
8936
|
-
export {
|
|
9531
|
+
export { PlatformCloudflareApiError as $, recordResource as A, r2BucketConfigHash as B, assertProjectZeroTrustAllowsUninstall as C, createPlatformHealthProbeToken as D, loadPlatformRuntime as E, formatPlatformInstallPlan as F, assertPlatformOperatorCredentialCanApplyPlan as G, revalidatePlatformInstallAction as H, hasProvisionIntentStep as I, verifyPlatformCloudflareCredential as J, platformOperatorCredentialLabel as K, legacyResourceConfigHash as L, recordPlatformWorkerTraffic as M, createPlatformInstallPlan as N, createPlatformInstallationSecrets as O, dnsRecordConfigHash as P, preparePlatformAccessSetup as Q, matchesRecordedR2Fingerprint as R, readPlatformProjectZeroTrustState as S, readPlatformDatabase as T, platformDatabaseNameFromOwnerUrl as U, resourceMarkerProblem as V, turnOffInstalledProjectZeroTrust as W, checkpointPlatformAccessResources as X, activatePlatformAccessCredentials as Y, parsePlatformAccessSetupSpec as Z, deletePlatformSecurityScanner as _, createPlatformProgress as a, verifyPlatformRuntimeTokenEmailPermissions as at, platformDatabaseClientUrl as b, formatPlatformWorkerOutsideChanges as c, authenticationSetupRequestHash as d, PlatformCloudflareClient as et, readLoginReplacementFile as f, assertPlatformSecurityAuditsSupported as g, installPlatform as h, verifyPlatformAiGatewayPlan as i, hyperdriveOriginMatches as it, platformTrafficAttachmentWorker as j, resolveBootstrapGitHubId as k, reviewPlatformWorkerOutsideChanges as l, REMOTE_INSTALLATION_MANIFEST_KEY as m, resolvePlatformInstallDatabaseUrl as n, hyperdriveOriginConfigHash as nt, withPlatformProgress as o, verifyPlatformRuntimeTokenPermissions as ot, replacePendingInstallationAuthentication as p, resolvePlatformCloudflareCredential as q, runPlatformLifecycleCommand as r, hyperdriveOriginFromConnectionString as rt, findPlatformWorkerOutsideChanges as s, PLATFORM_WORKERS_PERMISSION as st, assertNoninteractivePlatformMutationAcknowledged as t, PlatformRuntimeTokenEmailPermissionError as tt, uploadPlatformWorkerOutsideChanges as u, acquirePlatformDatabaseLifecycleLock as v, formatZeroTrustApplications as w, readPlatformProjectSlugs as x, acquirePlatformDatabaseLifecycleLockConnection as y, platformAdoptionIntentHash as z };
|