void 0.22.0 → 0.23.0
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/README.md +5 -1
- package/dist/{account-cmd-CjyxcGkM.mjs → account-cmd-C84Ee8cO.mjs} +4 -4
- package/dist/{scan-ClYmX3sa.mjs → application-analysis-BVsVqc11.mjs} +135 -18
- package/dist/application-routing-B7QEjqSR.mjs +27 -0
- package/dist/{auth-CZuiVsFh.mjs → auth-CCjt0hcq.mjs} +1 -1
- package/dist/{auth-DLNN0D3Z.mjs → auth-CSkdO2Bb.mjs} +4 -47
- package/dist/{auth-link-BLO4ptzo.mjs → auth-link-CioEg6uY.mjs} +4 -4
- package/dist/{auth-router-ZUg9MF_U.mjs → auth-router-BsR981d4.mjs} +4 -4
- package/dist/{better-auth-shared-rsBGBvWJ.mjs → better-auth-shared-hy6RPh9W.mjs} +13 -2
- package/dist/{build-cmd-BxR5FROK.mjs → build-cmd-LzvNJORH.mjs} +17 -5
- package/dist/{cache-D0sWhgKI.mjs → cache-C4MvnrMH.mjs} +2 -2
- package/dist/{cancel-deploy-D4NUqFbi.mjs → cancel-deploy-abUxpP2n.mjs} +2 -2
- package/dist/{cf-build-output-BJ6yGEIS.mjs → cf-build-output-BPqOT964.mjs} +2 -1
- package/dist/cf-build-output-_0HNWysu.mjs +2 -0
- package/dist/cli/cli.mjs +80 -455
- package/dist/cli/{cf-compat.mjs → cloudflare-operation-process.mjs} +442 -421
- package/dist/cli/env-schema-probe.d.mts +2 -1
- package/dist/cli/env-schema-probe.mjs +3 -3
- package/dist/client-Cu7jWiF1.mjs +2 -0
- package/dist/{client-BTZ3XkrB.mjs → client-RV8NVeB8.mjs} +140 -21
- package/dist/{cloudflare-auth-DQkqoMYa.mjs → cloudflare-auth-Qdc7tw8F.mjs} +41 -38
- package/dist/{cloudflare-cmd-BKlfGHAy.mjs → cloudflare-cmd-BcrVyTmJ.mjs} +5 -5
- package/dist/cloudflare-config-Bktvwtpf.mjs +182 -0
- package/dist/{cloudflare-connect-Ctmrw579.mjs → cloudflare-connect-B8uPZ4nx.mjs} +3 -3
- package/dist/{cloudflare-operations-BT6OWFBk.mjs → cloudflare-operations-AiWashgg.mjs} +1 -1
- package/dist/{cloudflare-operations-B9tzgjmf.mjs → cloudflare-operations-fxHb-byx.mjs} +116 -172
- package/dist/{preset-UHj9ARyP.mjs → cloudflare-process-B-wekeR6.mjs} +93 -6
- package/dist/{config-VavjpDnp.d.mts → config-BMHb8RCj.d.mts} +1 -0
- package/dist/config-C_XRIPx2.mjs +89 -0
- package/dist/config-entry.d.mts +1 -1
- package/dist/{connect-Dg-WkW-C.mjs → connect-Bd4kJd9U.mjs} +5 -5
- package/dist/{create-project-DdoqwFLF.mjs → create-project-Boczwj5r.mjs} +1 -1
- package/dist/{create-project-l9J7pbtm.mjs → create-project-bMf6ffLZ.mjs} +2 -2
- package/dist/{db-gp2sCXyN.mjs → db-8uG64XLl.mjs} +21 -21
- package/dist/{delete-TTedbH6B.mjs → delete-NvbiyeJf.mjs} +2 -2
- package/dist/{deploy-CH-o2CaZ.mjs → deploy-DzAIwqNU.mjs} +908 -582
- package/dist/{deploy-B19L2Bra.mjs → deploy-bjXdFCtn.mjs} +1 -1
- package/dist/{domain-JRF59P_r.mjs → domain-y5Tvydvo.mjs} +3 -3
- package/dist/{email-Bo6G9LOZ.mjs → email-B3umsW75.mjs} +13 -28
- package/dist/{env-BYOrWQnv.mjs → env-BS6qYHDb.mjs} +4 -4
- package/dist/{env-public-BxU_0yTL.d.mts → env-public-BX_r8HR6.d.mts} +1 -1
- package/dist/{env-validation-BB4GkLxn.mjs → env-validation-BPn7vk-V.mjs} +18 -71
- package/dist/{env-validation-BXge7uyK.mjs → env-validation-DbTg7-ar.mjs} +1 -1
- package/dist/{fetch-CXDChK7B.mjs → fetch-BIZJh7vR.mjs} +2 -2
- package/dist/{fetch-stream-AOByI7Ki.mjs → fetch-stream-IvCYKyQL.mjs} +24 -4
- package/dist/{gen-sCtlCOdA.mjs → gen-B580--vC.mjs} +2 -2
- package/dist/gen-BVaUUumi.mjs +2 -0
- package/dist/{github-cmd-0-7PexDq.mjs → github-cmd-v45BdfKX.mjs} +2 -2
- package/dist/{handler-HEcZsaij.d.mts → handler-CZ4nAylQ.d.mts} +1 -1
- package/dist/help-DofyZuY7.mjs +2 -0
- package/dist/{help-GKtwl07I.mjs → help-daGKjXGk.mjs} +229 -747
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +288 -1502
- package/dist/info-B97bTX9N.mjs +113 -0
- package/dist/{init-FZx3Elvz.mjs → init-Bvy7zrBo.mjs} +46 -15
- package/dist/limits-Bq5LG8Id.d.mts +27 -0
- package/dist/limits-Cjuk2VPm.mjs +68 -0
- package/dist/{link-BrQfb_CU.mjs → link-CDqqCjFl.mjs} +3 -3
- package/dist/{list-D44jmIAM.mjs → list-CZj0dzKY.mjs} +3 -3
- package/dist/{live-CKJlvlNp.d.mts → live-Chw1eIMv.d.mts} +1 -1
- package/dist/{local-d1-Bg9OzEEO.mjs → local-d1-2CMnpuW_.mjs} +2 -2
- package/dist/login-DYt_An22.mjs +2 -0
- package/dist/{login-CAsAsQ-_.mjs → login-UZKFM_u7.mjs} +3 -3
- package/dist/{logs-BjKvFnVM.mjs → logs-CUZ6t9t3.mjs} +3 -3
- package/dist/migrate-8_2u55MD.mjs +2 -0
- package/dist/{migrate-BPITvDJN.mjs → migrate-DHul7PRV.mjs} +2 -1
- package/dist/{node-Dt7z256D.mjs → node-BkyRWRx8.mjs} +1 -1
- package/dist/operator-args-CLgKGlwU.mjs +690 -0
- package/dist/{operator-cmd-BK5CCiT9.mjs → operator-cmd-DBA6dl0m.mjs} +68 -22
- package/dist/pages/client.d.mts +34 -2
- package/dist/pages/client.mjs +59 -3
- package/dist/pages/index.d.mts +1 -1
- package/dist/pages/index.mjs +1 -1
- package/dist/pages/islands-plugin.mjs +1 -1
- package/dist/pages/protocol.d.mts +2 -2
- package/dist/pages/protocol.mjs +2 -308
- package/dist/{parse-filename-DioPHiR9.mjs → parse-filename-CUbj-1MP.mjs} +35 -1
- package/dist/plan-D1Q5rf-r.mjs +2 -0
- package/dist/plan-NPpwZ_kc.mjs +58 -0
- package/dist/platform-args-BJdRtlLq.mjs +506 -0
- package/dist/platform-args-D3RXyR6h.mjs +2 -0
- package/dist/{platform-auth-config-BlN8xTdD.mjs → platform-auth-config-B56E9YP1.mjs} +3 -3
- package/dist/{platform-auth-protection-7d5aV2Jg.mjs → platform-auth-protection-BDWO_aER.mjs} +2 -2
- package/dist/{platform-auth-recovery-Dxij8ZbR.mjs → platform-auth-recovery-1gg4CSRe.mjs} +3 -3
- package/dist/{platform-cmd-E0FuL212.mjs → platform-cmd-Bt-1w6pY.mjs} +1 -1
- package/dist/{platform-cmd-B3hwKrFK.mjs → platform-cmd-DMcQStSc.mjs} +24 -3
- package/dist/{platform-domain-D6Xcy9ZX.mjs → platform-domain-BNkcz0OB.mjs} +2 -2
- package/dist/{platform-lifecycle-k0E0xoxx.mjs → platform-lifecycle-9OyBALhH.mjs} +327 -215
- package/dist/{platform-lifecycle-DMh_qrry.mjs → platform-lifecycle-BE6C_jxh.mjs} +1 -1
- package/dist/{platform-management-Brz_BDiT.mjs → platform-management-CjwLVQwN.mjs} +6 -3
- package/dist/{platform-management-DOtss0BN.mjs → platform-management-CnyTdcWX.mjs} +1 -1
- package/dist/platform-plans-config-BNGKGr4P.mjs +359 -0
- package/dist/{platform-recovery-BvtcXON5.mjs → platform-recovery-D6KSpuFm.mjs} +2 -2
- package/dist/{plugin-inference-BMfKRSqE.mjs → plugin-inference-CXWnn79A.mjs} +174 -64
- package/dist/{prepare-C-6YZyyg.mjs → prepare-B5Mkic5u.mjs} +1 -1
- package/dist/{prepare-CRhJbVrG.mjs → prepare-DOsL0CC9.mjs} +4 -20
- package/dist/prepare-cgvDMtSb.mjs +2 -0
- package/dist/{project-cmd-BZLCqOqw.mjs → project-cmd-CNzrqvBv.mjs} +16 -16
- package/dist/{project-team-BvgM0WoX.mjs → project-team-DQOWPfQT.mjs} +2 -2
- package/dist/{project-token-l5DqK6Az.mjs → project-token-CTDYU0Cc.mjs} +2 -2
- package/dist/{project-zero-trust-v6Mvpp8y.mjs → project-zero-trust-BNAkW-_0.mjs} +2 -2
- package/dist/{protocol-BBa6cstI.d.mts → protocol-CjF_iI9X.d.mts} +2 -2
- package/dist/protocol-U7bfjHmA.mjs +331 -0
- package/dist/{provision-Fr9pRqce.mjs → provision-C4ORE7G7.mjs} +1 -1
- package/dist/{provision-C4IGqkBf.mjs → provision-CJFgTZY8.mjs} +89 -198
- package/dist/{requests-DN-BbNiM.mjs → requests-MhxYnau8.mjs} +2 -2
- package/dist/resource-name-C7LVpcRm.mjs +11 -0
- package/dist/{rollback-D7rzSaZM.mjs → rollback-CJ6iSDoU.mjs} +3 -3
- package/dist/route-url-CG7U-cRN.mjs +15 -0
- package/dist/{runner-B8wXwWlo.mjs → runner-CXA9Fh8h.mjs} +1 -1
- package/dist/{runner-p-dMs2UN.mjs → runner-Ol0TNjk6.mjs} +2 -2
- package/dist/runtime/ai.d.mts +12 -8
- package/dist/runtime/ai.mjs +84 -17
- package/dist/runtime/better-auth-mysql.mjs +1 -1
- package/dist/runtime/better-auth-pg.mjs +1 -1
- package/dist/runtime/better-auth.mjs +1 -1
- package/dist/runtime/client-react.mjs +2 -2
- package/dist/runtime/client-solid.mjs +2 -2
- package/dist/runtime/client-svelte.mjs +2 -2
- package/dist/runtime/client-vue.mjs +2 -2
- package/dist/runtime/client.mjs +2 -2
- package/dist/runtime/durable.d.mts +3 -1
- package/dist/runtime/durable.mjs +4 -1
- package/dist/runtime/email/testing.mjs +1 -1
- package/dist/runtime/env-public.d.mts +1 -1
- package/dist/runtime/fetch-stream.mjs +1 -1
- package/dist/runtime/fetch.mjs +1 -1
- package/dist/runtime/handler.d.mts +1 -1
- package/dist/runtime/kv.mjs +0 -1
- package/dist/runtime/limits.d.mts +2 -0
- package/dist/runtime/limits.mjs +2 -0
- package/dist/runtime/live-client.d.mts +1 -1
- package/dist/runtime/live-server.mjs +25 -16
- package/dist/runtime/live.d.mts +1 -1
- package/dist/runtime/migration-handler.mjs +62 -42
- package/dist/runtime/route-url.d.mts +4 -0
- package/dist/runtime/route-url.mjs +2 -0
- package/dist/runtime/routing.d.mts +180 -0
- package/dist/runtime/routing.mjs +1082 -0
- package/dist/runtime/sandbox-container.d.mts +1 -1
- package/dist/runtime/sandbox-container.mjs +1 -1
- package/dist/runtime/sandbox.d.mts +3 -3
- package/dist/runtime/sandbox.mjs +75 -45
- package/dist/runtime/sse.mjs +1 -1
- package/dist/runtime/validator.d.mts +1 -1
- package/dist/runtime/ws-server.d.mts +4 -2
- package/dist/runtime/ws-server.mjs +27 -2
- package/dist/runtime/ws.d.mts +2 -2
- package/dist/runtime/ws.mjs +8 -6
- package/dist/{sandbox-qpNBT8a3.d.mts → sandbox-XZAqzFlG.d.mts} +11 -8
- package/dist/{sandbox-container-DdNEBfCc.d.mts → sandbox-container-Bo0eiFKz.d.mts} +2 -1
- package/dist/{sandbox-container-4fdqLnyb.mjs → sandbox-container-C6ItmVuN.mjs} +4 -2
- package/dist/{scan-4tfN-PSn.mjs → scan-C7okrLyM.mjs} +4 -35
- package/dist/{secret-BOtOl_cb.mjs → secret-Dli5fP0B.mjs} +4 -4
- package/dist/{sse-BaC1jXko.mjs → sse-CQNaDFFV.mjs} +6 -3
- package/dist/validate-Dq_L3s0S.mjs +2 -0
- package/dist/{validate-CIUwFpjB.mjs → validate-ctOrgiS3.mjs} +2 -1
- package/dist/{wrangler-DQF1vKyf.mjs → wrangler-7K-bW_DL.mjs} +8 -239
- package/dist/{ws-BoY7vQML.d.mts → ws-CL1w7GXU.d.mts} +13 -2
- package/package.json +15 -8
- package/skills/migrate-vite-cloudflare-to-void/SKILL.md +34 -157
- package/skills/void/SKILL.md +50 -135
- package/skills/void/docs/guide/ai.md +94 -84
- package/skills/void/docs/guide/app-types.md +3 -32
- package/skills/void/docs/guide/auth.md +12 -116
- package/skills/void/docs/guide/database/d1.md +9 -54
- package/skills/void/docs/guide/database/mysql.md +1 -1
- package/skills/void/docs/guide/database/postgresql.md +5 -26
- package/skills/void/docs/guide/database.md +23 -75
- package/skills/void/docs/guide/deployment.md +27 -113
- package/skills/void/docs/guide/durable-state.md +43 -18
- package/skills/void/docs/guide/edge/headers.md +3 -47
- package/skills/void/docs/guide/edge/prerendering.md +5 -20
- package/skills/void/docs/guide/edge/redirects.md +11 -64
- package/skills/void/docs/guide/edge/revalidation.md +5 -18
- package/skills/void/docs/guide/edge/rewrites.md +56 -284
- package/skills/void/docs/guide/edge/static-assets.md +22 -72
- package/skills/void/docs/guide/email/domains.md +112 -0
- package/skills/void/docs/guide/email/receiving.md +139 -0
- package/skills/void/docs/guide/email/sending.md +231 -0
- package/skills/void/docs/guide/email.md +13 -619
- package/skills/void/docs/guide/env-migration.md +11 -11
- package/skills/void/docs/guide/env-vars.md +9 -29
- package/skills/void/docs/guide/index.md +0 -15
- package/skills/void/docs/guide/jobs.md +3 -18
- package/skills/void/docs/guide/kv.md +5 -11
- package/skills/void/docs/guide/live.md +5 -56
- package/skills/void/docs/guide/pages-routing/actions-and-forms.md +78 -125
- package/skills/void/docs/guide/pages-routing/head.md +10 -10
- package/skills/void/docs/guide/pages-routing/islands.md +6 -36
- package/skills/void/docs/guide/pages-routing/layouts.md +6 -128
- package/skills/void/docs/guide/pages-routing/loaders.md +3 -19
- package/skills/void/docs/guide/pages-routing/markdown.md +13 -171
- package/skills/void/docs/guide/pages-routing/overview.md +7 -17
- package/skills/void/docs/guide/pages-routing/view-transitions.md +1 -1
- package/skills/void/docs/guide/platform/administration/access.md +1 -4
- package/skills/void/docs/guide/platform/administration/email.md +35 -8
- package/skills/void/docs/guide/platform/administration/operations.md +26 -4
- package/skills/void/docs/guide/platform/administration/plans.md +126 -0
- package/skills/void/docs/guide/platform/administration/projects.md +5 -2
- package/skills/void/docs/guide/platform/administration/zero-trust.md +23 -152
- package/skills/void/docs/guide/platform/development/runtime.md +3 -13
- package/skills/void/docs/guide/platform/development/schema-ci.md +0 -58
- package/skills/void/docs/guide/platform/installation/credentials.md +6 -4
- package/skills/void/docs/guide/platform/installation/domains.md +30 -2
- package/skills/void/docs/guide/platform/installation/first-deployment.md +2 -0
- package/skills/void/docs/guide/platform/installation/maintenance.md +3 -1
- package/skills/void/docs/guide/platform/installation/prerequisites.md +20 -15
- package/skills/void/docs/guide/platform/installation/setup.md +9 -5
- package/skills/void/docs/guide/platform-administration.md +1 -0
- package/skills/void/docs/guide/queues.md +7 -9
- package/skills/void/docs/guide/quickstart.md +38 -37
- package/skills/void/docs/guide/remote-dev.md +4 -9
- package/skills/void/docs/guide/sandboxes.md +29 -21
- package/skills/void/docs/guide/server-routing.md +9 -72
- package/skills/void/docs/guide/sse.md +4 -18
- package/skills/void/docs/guide/ssg.md +3 -15
- package/skills/void/docs/guide/ssr.md +14 -62
- package/skills/void/docs/guide/storage.md +9 -4
- package/skills/void/docs/guide/type-safety.md +3 -14
- package/skills/void/docs/guide/typed-fetch.md +3 -7
- package/skills/void/docs/guide/websockets.md +68 -40
- package/skills/void/docs/integrations/agents.md +3 -3
- package/skills/void/docs/integrations/cloudflare.md +85 -316
- package/skills/void/docs/integrations/frameworks/analog.md +5 -64
- package/skills/void/docs/integrations/frameworks/astro.md +4 -73
- package/skills/void/docs/integrations/frameworks/nuxt.md +5 -62
- package/skills/void/docs/integrations/frameworks/overview.md +11 -54
- package/skills/void/docs/integrations/frameworks/react-router.md +5 -60
- package/skills/void/docs/integrations/frameworks/sveltekit.md +6 -65
- package/skills/void/docs/integrations/frameworks/tanstack-start.md +4 -62
- package/skills/void/docs/integrations/nodejs-bun-deno.md +5 -69
- package/skills/void/docs/reference/api/auth.md +156 -0
- package/skills/void/docs/reference/api/client.md +87 -0
- package/skills/void/docs/reference/api/database.md +95 -0
- package/skills/void/docs/reference/api/durable.md +46 -0
- package/skills/void/docs/reference/api/env.md +50 -0
- package/skills/void/docs/reference/api/handlers.md +254 -0
- package/skills/void/docs/reference/api/pages.md +241 -0
- package/skills/void/docs/reference/api/plugin.md +39 -0
- package/skills/void/docs/reference/api/resources.md +109 -0
- package/skills/void/docs/reference/api/rewrites.md +76 -0
- package/skills/void/docs/reference/api/types.md +92 -0
- package/skills/void/docs/reference/api.md +56 -1218
- package/skills/void/docs/reference/cli/auth.md +88 -0
- package/skills/void/docs/reference/cli/database.md +128 -0
- package/skills/void/docs/reference/cli/deploy.md +85 -0
- package/skills/void/docs/reference/cli/domains.md +41 -0
- package/skills/void/docs/reference/cli/email.md +129 -0
- package/skills/void/docs/reference/cli/generate.md +116 -0
- package/skills/void/docs/reference/cli/github.md +189 -0
- package/skills/void/docs/reference/cli/platform-config.md +92 -0
- package/skills/void/docs/reference/cli/platform-email.md +81 -0
- package/skills/void/docs/reference/cli/platform-installation.md +127 -0
- package/skills/void/docs/reference/cli/platform-operations.md +90 -0
- package/skills/void/docs/reference/cli/platform-users.md +89 -0
- package/skills/void/docs/reference/cli/platform-zero-trust.md +45 -0
- package/skills/void/docs/reference/cli/platform.md +70 -0
- package/skills/void/docs/reference/cli/project.md +214 -0
- package/skills/void/docs/reference/cli/secrets.md +76 -0
- package/skills/void/docs/reference/cli/setup.md +70 -0
- package/skills/void/docs/reference/cli.md +32 -1682
- package/skills/void/docs/reference/config.md +12 -18
- package/skills/void/docs/reference/resource-inference.md +3 -58
- package/skills/void/docs/reference/structure.md +14 -41
- package/dist/canonical-json-DuDiiUsQ.mjs +0 -13
- package/dist/client-Czz8o5jP.mjs +0 -2
- package/dist/gen-CNJ62MM7.mjs +0 -2
- package/dist/help-CmZzxUba.mjs +0 -2
- package/dist/login-CGcRKEoi.mjs +0 -2
- package/dist/migrate-CYfbKkXh.mjs +0 -2
- package/dist/plan-BEZ8VJW0.mjs +0 -256
- package/dist/plan-DpuOr14e.mjs +0 -2
- package/dist/prepare-Bm3iq-u4.mjs +0 -2
- package/dist/validate-EKmJWxmy.mjs +0 -2
- /package/dist/cli/{cf-compat.d.mts → cloudflare-operation-process.d.mts} +0 -0
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
import { n as __toESM } from "../rolldown-runtime-DXIUcv95.mjs";
|
|
3
3
|
import { a as join, n as dirname, u as resolve } from "../dist-BVqXeR_h.mjs";
|
|
4
4
|
import { t as require_picocolors } from "../picocolors-BTps1_gs.mjs";
|
|
5
|
-
import { t as prepareCfBuildOutput } from "../cf-build-output-BJ6yGEIS.mjs";
|
|
6
5
|
import { copyFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
7
6
|
import { fileURLToPath } from "node:url";
|
|
8
7
|
import { tmpdir } from "node:os";
|
|
9
8
|
import { spawn, spawnSync } from "node:child_process";
|
|
10
9
|
import { parse } from "jsonc-parser";
|
|
11
10
|
import { stripVTControlCharacters } from "node:util";
|
|
12
|
-
import { readBuildOutput } from "@cloudflare/build-output-utils";
|
|
13
11
|
import { EnvHttpProxyAgent, fetch as fetch$1 } from "undici";
|
|
14
12
|
import { getCloudflareAuthUseKeyringFromEnv } from "@cloudflare/workers-auth";
|
|
15
13
|
import { createCfAuth, createCfProfileStore, readUserPreferences, setKeyringPreference } from "@cloudflare/workers-auth/cf";
|
|
@@ -62,18 +60,26 @@ function cloudflareDeviceCode(output) {
|
|
|
62
60
|
const plain = stripVTControlCharacters(output);
|
|
63
61
|
return /and enter the code:\s*([A-Za-z0-9-]+)\s/i.exec(plain)?.[1] ?? /[?&]user_code=([A-Za-z0-9-]+)\s/i.exec(plain)?.[1] ?? null;
|
|
64
62
|
}
|
|
63
|
+
function cloudflareVerificationUrl(output) {
|
|
64
|
+
const plain = stripVTControlCharacters(output);
|
|
65
|
+
return /(?:Opening a link in your default browser:|Visit this link to authenticate:)\s*(https?:\/\/\S+)\s/i.exec(plain)?.[1] ?? /please visit:\s*(https?:\/\/\S+)\s/i.exec(plain)?.[1] ?? null;
|
|
66
|
+
}
|
|
67
|
+
function printCloudflareLoginLink(url) {
|
|
68
|
+
console.log(`Open this link if your browser did not open: ${url}`);
|
|
69
|
+
}
|
|
65
70
|
function printCloudflareLoginPrompt(code) {
|
|
66
71
|
console.log(code ? `Opening Cloudflare login in your browser. Confirm the code ${import_picocolors.default.blue(code)} in your browser. Press Ctrl+C to cancel.` : "Opening Cloudflare login in your browser. Confirm the code shown in your browser. Press Ctrl+C to cancel.");
|
|
67
72
|
}
|
|
68
73
|
//#endregion
|
|
69
|
-
//#region src/cli/
|
|
70
|
-
/**
|
|
71
|
-
* Private transport for the existing Void Cloudflare command seams. The
|
|
72
|
-
* orchestrators still use their established argument/result contracts; this
|
|
73
|
-
* process translates them to the pinned cf CLI. It never invokes Wrangler.
|
|
74
|
-
*/
|
|
74
|
+
//#region src/cli/cloudflare-operation-process.ts
|
|
75
75
|
const cf = join(dirname(fileURLToPath(import.meta.resolve("cf/package.json"))), "bin", "cf");
|
|
76
|
-
const
|
|
76
|
+
const operation = (() => {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(process.argv[2] ?? "null");
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
77
83
|
process.env.CLOUDFLARE_AUTH_USE_KEYRING ??= "true";
|
|
78
84
|
function cfEnvironment() {
|
|
79
85
|
const env = {
|
|
@@ -92,11 +98,20 @@ function cfEnvironment() {
|
|
|
92
98
|
]) if (!env[canonical] && env[alias]) env[canonical] = env[alias];
|
|
93
99
|
return env;
|
|
94
100
|
}
|
|
95
|
-
function result(status, stdout = "", stderr = "") {
|
|
101
|
+
function result(status, stdout = "", stderr = "", data) {
|
|
102
|
+
const code = /\[(?:code:\s*)?(\d{4,})\]/.exec(stderr);
|
|
103
|
+
const errorCode = code ? Number(code[1]) : void 0;
|
|
96
104
|
return {
|
|
97
105
|
status,
|
|
98
106
|
stdout,
|
|
99
|
-
stderr
|
|
107
|
+
stderr,
|
|
108
|
+
...data !== void 0 ? { data } : {},
|
|
109
|
+
...errorCode ? { errorCode } : {},
|
|
110
|
+
...[
|
|
111
|
+
10006,
|
|
112
|
+
10007,
|
|
113
|
+
10090
|
|
114
|
+
].includes(errorCode ?? 0) ? { failure: "not-found" } : {}
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
117
|
function runCf(command, cwd = process.cwd()) {
|
|
@@ -120,7 +135,14 @@ function runCf(command, cwd = process.cwd()) {
|
|
|
120
135
|
child.error?.message || "",
|
|
121
136
|
child.signal ? `Cloudflare CLI terminated by ${child.signal}.` : ""
|
|
122
137
|
].filter(Boolean).join("\n").replace(/\[(\d{4,})\]/g, "[code: $1]");
|
|
123
|
-
|
|
138
|
+
if (child.signal || child.error || child.status === null) return {
|
|
139
|
+
status: 1,
|
|
140
|
+
stdout: "",
|
|
141
|
+
stderr,
|
|
142
|
+
signal: child.signal,
|
|
143
|
+
error: child.error?.message ?? (child.signal ? void 0 : "Cloudflare CLI did not report an exit status.")
|
|
144
|
+
};
|
|
145
|
+
return result(child.status, child.stdout ?? "", stderr);
|
|
124
146
|
}
|
|
125
147
|
function runInteractiveCf(command) {
|
|
126
148
|
return new Promise((resolve) => {
|
|
@@ -144,6 +166,7 @@ function runInteractiveCf(command) {
|
|
|
144
166
|
});
|
|
145
167
|
let output = "";
|
|
146
168
|
let announced = false;
|
|
169
|
+
let announcedLink = false;
|
|
147
170
|
let settled = false;
|
|
148
171
|
const finish = (value) => {
|
|
149
172
|
if (!settled) {
|
|
@@ -160,6 +183,13 @@ function runInteractiveCf(command) {
|
|
|
160
183
|
printCloudflareLoginPrompt(code);
|
|
161
184
|
}
|
|
162
185
|
}
|
|
186
|
+
if (!announcedLink) {
|
|
187
|
+
const url = cloudflareVerificationUrl(output);
|
|
188
|
+
if (url) {
|
|
189
|
+
announcedLink = true;
|
|
190
|
+
printCloudflareLoginLink(url);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
163
193
|
};
|
|
164
194
|
child.stdout.on("data", collect);
|
|
165
195
|
child.stderr.on("data", collect);
|
|
@@ -185,6 +215,7 @@ async function withBuildOutput(raw, sourceMain, action) {
|
|
|
185
215
|
}), { mode: 384 });
|
|
186
216
|
const accountId = process.env.CLOUDFLARE_ACCOUNT_ID ?? raw.account_id;
|
|
187
217
|
if (typeof accountId !== "string" || !accountId) throw new Error("Cloudflare account is not pinned for Worker deployment.");
|
|
218
|
+
const { prepareCfBuildOutput } = await import("../cf-build-output-_0HNWysu.mjs");
|
|
188
219
|
const output = await prepareCfBuildOutput(scratch, accountId);
|
|
189
220
|
if (!output) throw new Error("Could not prepare the Cloudflare Worker build output.");
|
|
190
221
|
try {
|
|
@@ -207,12 +238,8 @@ function object(value) {
|
|
|
207
238
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Cloudflare returned an unexpected response.");
|
|
208
239
|
return value;
|
|
209
240
|
}
|
|
210
|
-
function field(name) {
|
|
211
|
-
const index = args.indexOf(name);
|
|
212
|
-
return index >= 0 ? args[index + 1] : void 0;
|
|
213
|
-
}
|
|
214
241
|
function configPath() {
|
|
215
|
-
return
|
|
242
|
+
return "configPath" in operation ? operation.configPath : void 0;
|
|
216
243
|
}
|
|
217
244
|
function config() {
|
|
218
245
|
const path = configPath();
|
|
@@ -220,7 +247,7 @@ function config() {
|
|
|
220
247
|
return object(parse(readFileSync(path, "utf8")));
|
|
221
248
|
}
|
|
222
249
|
function workerName() {
|
|
223
|
-
const name =
|
|
250
|
+
const name = ("workerName" in operation ? operation.workerName : void 0) ?? config().name;
|
|
224
251
|
if (typeof name !== "string" || !name) throw new Error("Cloudflare Worker name is missing from the generated config.");
|
|
225
252
|
return name;
|
|
226
253
|
}
|
|
@@ -336,6 +363,7 @@ async function clearWorkerCustomDomains(worker) {
|
|
|
336
363
|
}
|
|
337
364
|
}
|
|
338
365
|
async function assertExistingProvisionableResources(directory, account) {
|
|
366
|
+
const { readBuildOutput } = await import("@cloudflare/build-output-utils");
|
|
339
367
|
const bindings = (await readBuildOutput(directory)).workers.default.config.env ?? {};
|
|
340
368
|
const queueNames = /* @__PURE__ */ new Set();
|
|
341
369
|
const accountPath = `/accounts/${encodeURIComponent(account)}`;
|
|
@@ -415,7 +443,7 @@ async function sessionCredential() {
|
|
|
415
443
|
} : null;
|
|
416
444
|
}
|
|
417
445
|
async function auth() {
|
|
418
|
-
if (
|
|
446
|
+
if (operation.type === "auth.login") {
|
|
419
447
|
const loggedIn = await runInteractiveCf([
|
|
420
448
|
"auth",
|
|
421
449
|
"login",
|
|
@@ -424,26 +452,24 @@ async function auth() {
|
|
|
424
452
|
if (loggedIn.status === 0) persistCfKeyringPreference(process.cwd());
|
|
425
453
|
return loggedIn;
|
|
426
454
|
}
|
|
427
|
-
if (
|
|
428
|
-
if (
|
|
455
|
+
if (operation.type === "auth.logout") return runCf(["auth", "logout"]);
|
|
456
|
+
if (operation.type === "auth.whoami") {
|
|
429
457
|
const called = runCf(["auth", "whoami"]);
|
|
430
458
|
if (called.status !== 0) return called;
|
|
431
459
|
const identity = object(parsedJson(called.stdout));
|
|
432
|
-
if (identity.authenticated !== true || identity.tokenValid !== true) return result(1,
|
|
460
|
+
if (identity.authenticated !== true || identity.tokenValid !== true) return result(1, "", "Cloudflare authentication is required.", { loggedIn: false });
|
|
433
461
|
if (String(identity.authSource).startsWith("OAuth token from ")) persistCfKeyringPreference(process.cwd());
|
|
434
|
-
return result(0,
|
|
462
|
+
return result(0, "", called.stderr, {
|
|
435
463
|
loggedIn: true,
|
|
436
464
|
accounts: identity.accounts,
|
|
437
465
|
email: identity.email,
|
|
438
466
|
tokenPermissions: identity.scopes,
|
|
439
467
|
authType: process.env.CLOUDFLARE_API_KEY || process.env.CF_API_KEY ? "Global API Key" : String(identity.authSource).startsWith("OAuth token") ? "OAuth Token" : "API Token"
|
|
440
|
-
})
|
|
441
|
-
}
|
|
442
|
-
if (args[0] === "auth" && args[1] === "token") {
|
|
443
|
-
const credential = await sessionCredential();
|
|
444
|
-
return credential ? result(0, `${JSON.stringify(credential)}\n`) : result(1, "", "Cloudflare session has no OAuth bearer.");
|
|
468
|
+
});
|
|
445
469
|
}
|
|
446
|
-
|
|
470
|
+
if (operation.type !== "auth.token") throw new Error("Unsupported Cloudflare authentication operation.");
|
|
471
|
+
const credential = await sessionCredential();
|
|
472
|
+
return credential ? result(0, "", "", credential) : result(1, "", "Cloudflare session has no OAuth bearer.");
|
|
447
473
|
}
|
|
448
474
|
function listAllResourcePages(command, extraFlags = []) {
|
|
449
475
|
const pageSize = 100;
|
|
@@ -484,152 +510,158 @@ async function readAllQueues() {
|
|
|
484
510
|
throw new Error("Cloudflare Queue list exceeded the supported page limit.");
|
|
485
511
|
}
|
|
486
512
|
async function resources() {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const database = d1Database(third);
|
|
490
|
-
const sql = field("--command");
|
|
491
|
-
if (!sql) throw new Error("D1 SQL command is missing.");
|
|
492
|
-
return runCf([
|
|
513
|
+
switch (operation.type) {
|
|
514
|
+
case "d1.execute": return runCf([
|
|
493
515
|
"d1",
|
|
494
516
|
"query",
|
|
495
|
-
database.id,
|
|
517
|
+
d1Database(operation.database).id,
|
|
496
518
|
"--sql",
|
|
497
|
-
sql
|
|
519
|
+
operation.sql
|
|
498
520
|
]);
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
"list"
|
|
524
|
-
]);
|
|
525
|
-
if (group === "d1" && verb === "list") return listAllResourcePages(["d1", "list"]);
|
|
526
|
-
if (group === "d1" && verb === "info" && third) {
|
|
527
|
-
const listed = listAllResourcePages(["d1", "list"]);
|
|
528
|
-
if (listed.status !== 0) return listed;
|
|
529
|
-
const value = parsedJson(listed.stdout);
|
|
530
|
-
if (!Array.isArray(value)) throw new Error("D1 list was malformed.");
|
|
531
|
-
const selected = value.find((item) => object(item).name === third) ?? null;
|
|
532
|
-
return selected === null ? result(1, "", `D1 database ${JSON.stringify(third)} does not exist.`) : result(0, `${JSON.stringify(selected)}\n`);
|
|
533
|
-
}
|
|
534
|
-
if (group === "d1" && verb === "create" && third) {
|
|
535
|
-
const created = runCf([
|
|
536
|
-
"d1",
|
|
537
|
-
"create",
|
|
538
|
-
"--name",
|
|
539
|
-
third
|
|
521
|
+
case "d1.migrations.list":
|
|
522
|
+
case "d1.migrations.apply": {
|
|
523
|
+
const database = d1Database(operation.database);
|
|
524
|
+
const verb = operation.type === "d1.migrations.list" ? "list" : "apply";
|
|
525
|
+
const called = runCf([
|
|
526
|
+
"d1",
|
|
527
|
+
"migrations",
|
|
528
|
+
verb,
|
|
529
|
+
database.id,
|
|
530
|
+
"--dir",
|
|
531
|
+
database.dir,
|
|
532
|
+
...database.pattern ? ["--pattern", database.pattern] : [],
|
|
533
|
+
"--table",
|
|
534
|
+
database.table
|
|
535
|
+
]);
|
|
536
|
+
if (called.status !== 0 || verb !== "list") return called;
|
|
537
|
+
const pending = parsedJson(called.stdout);
|
|
538
|
+
if (!Array.isArray(pending) || pending.some((item) => typeof object(item).Name !== "string")) throw new Error("D1 migration list was malformed.");
|
|
539
|
+
return result(0, "", called.stderr, { pending: pending.map((item) => object(item).Name) });
|
|
540
|
+
}
|
|
541
|
+
case "containers.list": return runCf([
|
|
542
|
+
"containers",
|
|
543
|
+
"applications",
|
|
544
|
+
"list"
|
|
540
545
|
]);
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
"
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
546
|
+
case "d1.list": return listAllResourcePages(["d1", "list"]);
|
|
547
|
+
case "d1.info": {
|
|
548
|
+
const listed = listAllResourcePages(["d1", "list"]);
|
|
549
|
+
if (listed.status !== 0) return listed;
|
|
550
|
+
const list = parsedJson(listed.stdout);
|
|
551
|
+
if (!Array.isArray(list)) throw new Error("D1 list was malformed.");
|
|
552
|
+
const value = list.find((item) => object(item).name === operation.name);
|
|
553
|
+
return value === void 0 ? {
|
|
554
|
+
...result(1, "", "D1 database does not exist."),
|
|
555
|
+
failure: "not-found"
|
|
556
|
+
} : result(0, "", "", value);
|
|
557
|
+
}
|
|
558
|
+
case "d1.create": {
|
|
559
|
+
const created = runCf([
|
|
560
|
+
"d1",
|
|
561
|
+
"create",
|
|
562
|
+
"--name",
|
|
563
|
+
operation.name
|
|
564
|
+
]);
|
|
565
|
+
if (created.status !== 0) return created;
|
|
566
|
+
const database = object(parsedJson(created.stdout));
|
|
567
|
+
if (typeof database.uuid !== "string") throw new Error("D1 creation returned no database ID.");
|
|
568
|
+
updateBinding("d1_databases", operation.binding, {
|
|
569
|
+
database_name: operation.name,
|
|
570
|
+
database_id: database.uuid
|
|
571
|
+
});
|
|
572
|
+
return created;
|
|
573
|
+
}
|
|
574
|
+
case "kv.namespace.list": return listAllResourcePages([
|
|
562
575
|
"kv",
|
|
563
576
|
"namespaces",
|
|
564
|
-
"
|
|
565
|
-
|
|
566
|
-
|
|
577
|
+
"list"
|
|
578
|
+
], [
|
|
579
|
+
"--order",
|
|
580
|
+
"id",
|
|
581
|
+
"--direction",
|
|
582
|
+
"asc"
|
|
567
583
|
]);
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
584
|
+
case "kv.namespace.create": {
|
|
585
|
+
const created = runCf([
|
|
586
|
+
"kv",
|
|
587
|
+
"namespaces",
|
|
588
|
+
"create",
|
|
589
|
+
"--title",
|
|
590
|
+
operation.name
|
|
591
|
+
]);
|
|
592
|
+
if (created.status !== 0) return created;
|
|
593
|
+
const namespace = object(parsedJson(created.stdout));
|
|
594
|
+
if (typeof namespace.id !== "string") throw new Error("KV creation returned no namespace ID.");
|
|
595
|
+
updateBinding("kv_namespaces", operation.binding, { id: namespace.id });
|
|
596
|
+
return created;
|
|
597
|
+
}
|
|
598
|
+
case "r2.bucket.info": return runCf([
|
|
576
599
|
"r2",
|
|
577
600
|
"buckets",
|
|
578
601
|
"get",
|
|
579
|
-
|
|
602
|
+
operation.name
|
|
580
603
|
]);
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
604
|
+
case "r2.bucket.create": {
|
|
605
|
+
const created = runCf([
|
|
606
|
+
"r2",
|
|
607
|
+
"buckets",
|
|
608
|
+
"create",
|
|
609
|
+
"--name",
|
|
610
|
+
operation.name
|
|
611
|
+
]);
|
|
612
|
+
if (created.status === 0) updateBinding("r2_buckets", operation.binding, { bucket_name: operation.name });
|
|
613
|
+
return created;
|
|
614
|
+
}
|
|
615
|
+
case "hyperdrive.create": {
|
|
616
|
+
const url = new URL(readFileSync(0, "utf8"));
|
|
617
|
+
const name = operation.name;
|
|
618
|
+
const created = await withSecretFile(JSON.stringify({
|
|
619
|
+
name,
|
|
620
|
+
origin: {
|
|
621
|
+
host: url.hostname,
|
|
622
|
+
port: Number(url.port || (url.protocol.startsWith("mysql") ? 3306 : 5432)),
|
|
623
|
+
database: decodeURIComponent(url.pathname.replace(/^\//, "")),
|
|
624
|
+
scheme: url.protocol.replace(":", ""),
|
|
625
|
+
user: decodeURIComponent(url.username),
|
|
626
|
+
password: decodeURIComponent(url.password)
|
|
627
|
+
}
|
|
628
|
+
}), (path) => runCf([
|
|
629
|
+
"hyperdrive",
|
|
630
|
+
"create",
|
|
631
|
+
"--body",
|
|
632
|
+
"@" + path
|
|
633
|
+
]));
|
|
634
|
+
if (created.status !== 0) return {
|
|
635
|
+
...created,
|
|
636
|
+
stdout: "",
|
|
637
|
+
stderr: "Hyperdrive creation failed."
|
|
638
|
+
};
|
|
639
|
+
const hyperdrive = object(parsedJson(created.stdout));
|
|
640
|
+
if (typeof hyperdrive.id !== "string") throw new Error("Hyperdrive creation returned no ID.");
|
|
641
|
+
updateBinding("hyperdrive", operation.binding, { id: hyperdrive.id });
|
|
642
|
+
return result(0, "", "", {
|
|
643
|
+
id: hyperdrive.id,
|
|
644
|
+
name
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
case "queues.create": return runCf([
|
|
625
648
|
"queues",
|
|
626
649
|
"create",
|
|
627
650
|
"--queue-name",
|
|
628
|
-
|
|
651
|
+
operation.name
|
|
629
652
|
]);
|
|
630
|
-
|
|
653
|
+
case "queues.info": {
|
|
654
|
+
const queue = (await readAllQueues()).find((item) => item.queue_name === operation.name);
|
|
655
|
+
return queue ? result(0, "", "", {
|
|
656
|
+
id: queue.queue_id,
|
|
657
|
+
name: queue.queue_name
|
|
658
|
+
}) : {
|
|
659
|
+
...result(1, "", "Cloudflare Queue does not exist."),
|
|
660
|
+
failure: "not-found"
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
default: throw new Error("Unsupported Cloudflare resource operation.");
|
|
631
664
|
}
|
|
632
|
-
return result(1, "", `Unsupported Cloudflare resource operation: ${group} ${verb}.`);
|
|
633
665
|
}
|
|
634
666
|
function emailZone(domain) {
|
|
635
667
|
const labels = domain.split(".");
|
|
@@ -643,103 +675,67 @@ function emailZone(domain) {
|
|
|
643
675
|
candidate
|
|
644
676
|
]);
|
|
645
677
|
if (read.status === 0) return candidate;
|
|
646
|
-
if (!/Zone not found:/.test(read.stderr)) throw new Error("Cloudflare could not resolve the Email zone.");
|
|
678
|
+
if (read.signal || read.error || !/Zone not found:/.test(read.stderr)) throw new Error("Cloudflare could not resolve the Email zone.");
|
|
647
679
|
}
|
|
648
680
|
throw new Error(`Cloudflare Email zone for ${domain} was not found.`);
|
|
649
681
|
}
|
|
650
682
|
function email() {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
683
|
+
if (!("domain" in operation)) throw new Error("Cloudflare Email domain is missing.");
|
|
684
|
+
const domain = operation.domain;
|
|
685
|
+
switch (operation.type) {
|
|
686
|
+
case "email.routing.settings": {
|
|
687
|
+
const read = runCf([
|
|
688
|
+
"email-routing",
|
|
689
|
+
"settings",
|
|
690
|
+
"get",
|
|
691
|
+
"--zone",
|
|
692
|
+
domain
|
|
693
|
+
]);
|
|
694
|
+
return read.status !== 0 && !read.signal && !read.error && /Zone not found:/.test(read.stderr) ? result(0, "", "", null) : read;
|
|
695
|
+
}
|
|
696
|
+
case "email.routing.enable": return runCf([
|
|
655
697
|
"email-routing",
|
|
656
|
-
"
|
|
657
|
-
"get",
|
|
698
|
+
"enable",
|
|
658
699
|
"--zone",
|
|
659
|
-
|
|
700
|
+
domain,
|
|
701
|
+
"--name",
|
|
702
|
+
domain
|
|
660
703
|
]);
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
"email-routing",
|
|
668
|
-
"enable",
|
|
669
|
-
"--zone",
|
|
670
|
-
candidate,
|
|
671
|
-
"--name",
|
|
672
|
-
candidate
|
|
673
|
-
]);
|
|
674
|
-
if (product === "routing" && operation === "rules" && args[3] === "list" && args[4]) {
|
|
675
|
-
const zone = args[4];
|
|
676
|
-
const lines = [];
|
|
677
|
-
for (let page = 1; page <= 100; page++) {
|
|
704
|
+
case "email.routing.rules.list": return listAllResourcePages([
|
|
705
|
+
"email-routing",
|
|
706
|
+
"rules",
|
|
707
|
+
"list-account"
|
|
708
|
+
], ["--zone", domain]);
|
|
709
|
+
case "email.sending.settings": {
|
|
678
710
|
const listed = runCf([
|
|
679
|
-
"email-
|
|
680
|
-
"
|
|
681
|
-
"list
|
|
711
|
+
"email-sending",
|
|
712
|
+
"subdomains",
|
|
713
|
+
"list",
|
|
682
714
|
"--zone",
|
|
683
|
-
|
|
684
|
-
"--page",
|
|
685
|
-
String(page),
|
|
686
|
-
"--per-page",
|
|
687
|
-
"100"
|
|
715
|
+
emailZone(domain)
|
|
688
716
|
]);
|
|
689
717
|
if (listed.status !== 0) return listed;
|
|
690
|
-
const
|
|
691
|
-
if (!Array.isArray(
|
|
692
|
-
|
|
693
|
-
const actions = Array.isArray(entry.actions) ? entry.actions.map((action) => {
|
|
694
|
-
const item = object(action);
|
|
695
|
-
return item.type === "worker" ? `worker:${item.value}` : item.type === "forward" && Array.isArray(item.value) ? `forward:${item.value.join(",")}` : String(item.type);
|
|
696
|
-
}) : [];
|
|
697
|
-
const matchers = Array.isArray(entry.matchers) ? entry.matchers.map(object) : [];
|
|
698
|
-
if (matchers.some((item) => item.type === "all")) lines.push(`Catch-all rule: ${entry.enabled === true ? "enabled" : "disabled"}, action: ${actions.join(", ")}`);
|
|
699
|
-
else {
|
|
700
|
-
if (typeof entry.id !== "string") throw new Error("Email Routing rule ID was missing.");
|
|
701
|
-
const recipients = matchers.filter((item) => item.type === "literal" || item.type === "to").map((item) => `to:${item.value}`);
|
|
702
|
-
lines.push(`Rule: ${entry.id}\n Name: ${entry.name || "(none)"}\n Enabled: ${entry.enabled === true}\n Matchers: ${recipients.join(", ")}\n Actions: ${actions.join(", ")}\n Priority: ${entry.priority ?? 0}`);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
if (items.length < 100) return result(0, lines.length ? `${lines.join("\n")}\n` : "No routing rules found.\n");
|
|
718
|
+
const values = parsedJson(listed.stdout);
|
|
719
|
+
if (!Array.isArray(values)) throw new Error("Email Sending subdomains were malformed.");
|
|
720
|
+
return result(0, "", "", values.map(object).find((item) => item.name === domain) ?? null);
|
|
706
721
|
}
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
if (product === "sending" && operation === "settings") {
|
|
710
|
-
const listed = runCf([
|
|
722
|
+
case "email.sending.enable": return runCf([
|
|
711
723
|
"email-sending",
|
|
712
724
|
"subdomains",
|
|
713
|
-
"
|
|
725
|
+
"create",
|
|
714
726
|
"--zone",
|
|
715
|
-
emailZone(
|
|
727
|
+
emailZone(domain),
|
|
728
|
+
"--name",
|
|
729
|
+
domain
|
|
716
730
|
]);
|
|
717
|
-
|
|
718
|
-
const values = parsedJson(listed.stdout);
|
|
719
|
-
if (!Array.isArray(values)) throw new Error("Email Sending subdomains were malformed.");
|
|
720
|
-
const match = values.map(object).find((item) => item.name === candidate);
|
|
721
|
-
if (!match) return result(1, "", `No sending subdomain found for \`${candidate}\`.`);
|
|
722
|
-
const tag = match.tag ?? match.id;
|
|
723
|
-
if (typeof tag !== "string") throw new Error("Email Sending subdomain ID was missing.");
|
|
724
|
-
return result(0, `Email Sending for ${candidate}:\n Enabled: ${match.enabled === true}\n Tag: ${tag}\n`);
|
|
731
|
+
default: throw new Error("Unsupported Cloudflare Email operation.");
|
|
725
732
|
}
|
|
726
|
-
if (product === "sending" && operation === "enable") return runCf([
|
|
727
|
-
"email-sending",
|
|
728
|
-
"subdomains",
|
|
729
|
-
"create",
|
|
730
|
-
"--zone",
|
|
731
|
-
emailZone(candidate),
|
|
732
|
-
"--name",
|
|
733
|
-
candidate
|
|
734
|
-
]);
|
|
735
|
-
return result(1, "", `Unsupported Cloudflare email operation: ${product} ${operation}.`);
|
|
736
733
|
}
|
|
737
734
|
async function secrets() {
|
|
738
735
|
const worker = workerName();
|
|
739
|
-
const verb = args[1];
|
|
740
736
|
const apply = async (action) => {
|
|
741
737
|
const first = action();
|
|
742
|
-
if (first.status === 0 ||
|
|
738
|
+
if (first.status === 0 || first.errorCode !== 10007) return first;
|
|
743
739
|
const draft = await withBuildOutput({
|
|
744
740
|
name: worker,
|
|
745
741
|
account_id: process.env.CLOUDFLARE_ACCOUNT_ID ?? config().account_id,
|
|
@@ -754,148 +750,142 @@ async function secrets() {
|
|
|
754
750
|
], directory));
|
|
755
751
|
return draft.status === 0 ? action() : draft;
|
|
756
752
|
};
|
|
757
|
-
|
|
758
|
-
|
|
753
|
+
switch (operation.type) {
|
|
754
|
+
case "secret.list": return runCf([
|
|
759
755
|
"workers",
|
|
760
756
|
"secrets",
|
|
761
757
|
"list",
|
|
762
758
|
"--worker",
|
|
763
759
|
worker
|
|
764
760
|
]);
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
761
|
+
case "secret.put": {
|
|
762
|
+
const value = readFileSync(0, "utf8").replace(/\n$/, "");
|
|
763
|
+
const name = operation.name;
|
|
764
|
+
return withSecretFile(JSON.stringify({
|
|
765
|
+
name,
|
|
766
|
+
text: value,
|
|
767
|
+
type: "secret_text"
|
|
768
|
+
}), (path) => apply(() => runCf([
|
|
769
|
+
"workers",
|
|
770
|
+
"secrets",
|
|
771
|
+
"update",
|
|
772
|
+
name,
|
|
773
|
+
"--worker",
|
|
774
|
+
worker,
|
|
775
|
+
"--body",
|
|
776
|
+
"@" + path
|
|
777
|
+
])));
|
|
778
|
+
}
|
|
779
|
+
case "secret.bulk": {
|
|
780
|
+
const values = object(parsedJson(readFileSync(0, "utf8")));
|
|
781
|
+
const patch = Object.fromEntries(Object.entries(values).map(([name, text]) => [name, {
|
|
782
|
+
type: "secret_text",
|
|
783
|
+
text
|
|
784
|
+
}]));
|
|
785
|
+
return withSecretFile(JSON.stringify(patch), (path) => apply(() => runCf([
|
|
786
|
+
"workers",
|
|
787
|
+
"secrets",
|
|
788
|
+
"bulk",
|
|
789
|
+
"--worker",
|
|
790
|
+
worker,
|
|
791
|
+
"--file",
|
|
792
|
+
path
|
|
793
|
+
])));
|
|
794
|
+
}
|
|
795
|
+
case "secret.delete": return runCf([
|
|
792
796
|
"workers",
|
|
793
797
|
"secrets",
|
|
794
|
-
"
|
|
798
|
+
"delete",
|
|
799
|
+
operation.name,
|
|
795
800
|
"--worker",
|
|
796
801
|
worker,
|
|
797
|
-
"--
|
|
798
|
-
|
|
799
|
-
|
|
802
|
+
"--force"
|
|
803
|
+
]);
|
|
804
|
+
default: throw new Error("Unsupported Cloudflare secret operation.");
|
|
800
805
|
}
|
|
801
|
-
if (verb === "delete" && args[2]) return runCf([
|
|
802
|
-
"workers",
|
|
803
|
-
"secrets",
|
|
804
|
-
"delete",
|
|
805
|
-
args[2],
|
|
806
|
-
"--worker",
|
|
807
|
-
worker,
|
|
808
|
-
"--force"
|
|
809
|
-
]);
|
|
810
|
-
return result(1, "", `Unsupported Cloudflare secret operation: ${verb}.`);
|
|
811
806
|
}
|
|
812
807
|
async function workerHistory() {
|
|
813
808
|
const worker = workerName();
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
"workers",
|
|
831
|
-
"versions",
|
|
832
|
-
"list",
|
|
833
|
-
"--worker-id",
|
|
834
|
-
worker
|
|
835
|
-
], (value) => {
|
|
836
|
-
if (!Array.isArray(value)) throw new Error("Worker versions were malformed.");
|
|
837
|
-
return value.map((entry) => {
|
|
838
|
-
const version = object(entry);
|
|
839
|
-
return {
|
|
840
|
-
...version,
|
|
841
|
-
metadata: { created_on: version.created_on }
|
|
842
|
-
};
|
|
843
|
-
});
|
|
844
|
-
});
|
|
845
|
-
if (group === "versions" && verb === "view" && third) {
|
|
846
|
-
const called = runCf([
|
|
809
|
+
switch (operation.type) {
|
|
810
|
+
case "deployments.status":
|
|
811
|
+
case "deployments.list": {
|
|
812
|
+
const called = runCf([
|
|
813
|
+
"workers",
|
|
814
|
+
"deployments",
|
|
815
|
+
"list",
|
|
816
|
+
"--worker",
|
|
817
|
+
worker
|
|
818
|
+
]);
|
|
819
|
+
if (called.status !== 0) return called;
|
|
820
|
+
const deployments = object(parsedJson(called.stdout)).deployments;
|
|
821
|
+
if (!Array.isArray(deployments)) throw new Error("Worker deployments were malformed.");
|
|
822
|
+
return operation.type === "deployments.list" ? result(0, "", called.stderr, deployments) : deployments[0] ? result(0, "", called.stderr, deployments[0]) : result(1, "", "Worker has no active deployment.");
|
|
823
|
+
}
|
|
824
|
+
case "versions.list": return cleanJson([
|
|
847
825
|
"workers",
|
|
848
826
|
"versions",
|
|
849
|
-
"
|
|
850
|
-
third,
|
|
827
|
+
"list",
|
|
851
828
|
"--worker-id",
|
|
852
829
|
worker
|
|
853
|
-
])
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
}
|
|
863
|
-
if (group === "versions" && verb === "deploy") {
|
|
864
|
-
const firstFlag = args.findIndex((part, index) => index >= 2 && part.startsWith("-"));
|
|
865
|
-
const versions = args.slice(2, firstFlag === -1 ? void 0 : firstFlag).map((part) => {
|
|
866
|
-
const [version_id, fraction] = part.split("@");
|
|
867
|
-
const percentage = Number(fraction);
|
|
868
|
-
if (!/^[0-9a-f-]{36}$/i.test(version_id ?? "") || !Number.isFinite(percentage)) throw new Error("Cloudflare deployment version was malformed.");
|
|
869
|
-
return {
|
|
870
|
-
version_id,
|
|
871
|
-
percentage
|
|
872
|
-
};
|
|
830
|
+
], (value) => {
|
|
831
|
+
if (!Array.isArray(value)) throw new Error("Worker versions were malformed.");
|
|
832
|
+
return value.map((entry) => {
|
|
833
|
+
const version = object(entry);
|
|
834
|
+
return {
|
|
835
|
+
...version,
|
|
836
|
+
metadata: { created_on: version.created_on }
|
|
837
|
+
};
|
|
838
|
+
});
|
|
873
839
|
});
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
840
|
+
case "versions.view": {
|
|
841
|
+
const versionId = operation.versionId;
|
|
842
|
+
const called = runCf([
|
|
843
|
+
"workers",
|
|
844
|
+
"versions",
|
|
845
|
+
"get",
|
|
846
|
+
versionId,
|
|
847
|
+
"--worker-id",
|
|
848
|
+
worker
|
|
849
|
+
]);
|
|
850
|
+
if (called.status !== 0) return called;
|
|
851
|
+
const version = object(parsedJson(called.stdout));
|
|
852
|
+
if (version.id !== versionId || !Array.isArray(version.bindings)) throw new Error("Worker version bindings were malformed.");
|
|
853
|
+
const resources = await readVersionResources(worker, versionId);
|
|
854
|
+
return result(0, "", called.stderr, {
|
|
855
|
+
...version,
|
|
856
|
+
resources
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
case "versions.deploy": {
|
|
860
|
+
const versions = operation.versions.map((value) => ({
|
|
861
|
+
version_id: value.versionId,
|
|
862
|
+
percentage: value.percentage
|
|
863
|
+
}));
|
|
864
|
+
if (!versions.length || versions.some((value) => !/^[-a-f\d]{36}$/i.test(value.version_id) || !Number.isFinite(value.percentage) || value.percentage < 0 || value.percentage > 100) || Math.abs(versions.reduce((sum, value) => sum + value.percentage, 0) - 100) > .001) throw new Error("Cloudflare deployment percentages must total 100.");
|
|
865
|
+
return runCf([
|
|
866
|
+
"workers",
|
|
867
|
+
"deployments",
|
|
868
|
+
"create",
|
|
869
|
+
"--worker",
|
|
870
|
+
worker,
|
|
871
|
+
"--body",
|
|
872
|
+
JSON.stringify({
|
|
873
|
+
strategy: "percentage",
|
|
874
|
+
versions,
|
|
875
|
+
...operation.message ? { annotations: { "workers/message": operation.message } } : {}
|
|
876
|
+
})
|
|
877
|
+
]);
|
|
878
|
+
}
|
|
879
|
+
default: throw new Error("Unsupported Cloudflare Worker history operation.");
|
|
889
880
|
}
|
|
890
|
-
return result(1, "", `Unsupported Cloudflare Worker history operation: ${group} ${verb}.`);
|
|
891
881
|
}
|
|
892
882
|
async function workerChanges() {
|
|
893
|
-
if (
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
883
|
+
if (operation.type === "queues.consumer.remove") {
|
|
884
|
+
const queue = (await readAllQueues()).find((item) => item.queue_name === operation.queueName);
|
|
885
|
+
if (!queue || typeof queue.queue_id !== "string") return {
|
|
886
|
+
...result(1, "", "Cloudflare Queue does not exist."),
|
|
887
|
+
failure: "not-found"
|
|
888
|
+
};
|
|
899
889
|
const consumers = runCf([
|
|
900
890
|
"queues",
|
|
901
891
|
"consumers",
|
|
@@ -906,8 +896,17 @@ async function workerChanges() {
|
|
|
906
896
|
if (consumers.status !== 0) return consumers;
|
|
907
897
|
const members = parsedJson(consumers.stdout);
|
|
908
898
|
if (!Array.isArray(members)) throw new Error("Queue consumer list was malformed.");
|
|
909
|
-
|
|
910
|
-
|
|
899
|
+
const matching = members.map(object).filter((entry) => {
|
|
900
|
+
const name = entry.script_name ?? entry.script;
|
|
901
|
+
if (entry.script_name !== void 0 && (typeof entry.script_name !== "string" || !entry.script_name) || entry.script !== void 0 && (typeof entry.script !== "string" || !entry.script) || entry.script_name !== void 0 && entry.script !== void 0 && entry.script_name !== entry.script || entry.type === "worker" && name === void 0) throw new Error("Queue consumer Worker identity is ambiguous.");
|
|
902
|
+
return name === operation.workerName;
|
|
903
|
+
});
|
|
904
|
+
if (matching.length > 1) throw new Error("Queue consumer Worker identity is ambiguous.");
|
|
905
|
+
for (const item of matching) {
|
|
906
|
+
if (typeof item.consumer_id !== "string" || !item.consumer_id || item.consumer_id.startsWith("-") || /\s/.test(item.consumer_id) || [...item.consumer_id].some((character) => {
|
|
907
|
+
const code = character.charCodeAt(0);
|
|
908
|
+
return code < 32 || code === 127;
|
|
909
|
+
}) || item.type !== void 0 && item.type !== "worker") throw new Error("Queue consumer ID or type is invalid.");
|
|
911
910
|
const deleted = runCf([
|
|
912
911
|
"queues",
|
|
913
912
|
"consumers",
|
|
@@ -921,59 +920,62 @@ async function workerChanges() {
|
|
|
921
920
|
}
|
|
922
921
|
return result(0);
|
|
923
922
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
"triggers",
|
|
931
|
-
"deploy",
|
|
932
|
-
"--prebuilt",
|
|
933
|
-
...args.includes("--dry-run") ? ["--dry-run"] : []
|
|
934
|
-
], directory));
|
|
923
|
+
const raw = config();
|
|
924
|
+
const name = workerName();
|
|
925
|
+
if (raw.name !== name) throw new Error("Cloudflare Worker target changed.");
|
|
926
|
+
if (operation.type === "triggers.clear-crons" || operation.type === "triggers.clear-domains") {
|
|
927
|
+
if (raw.account_id !== void 0 && raw.account_id !== accountId()) throw new Error("Cloudflare trigger target changed.");
|
|
928
|
+
return operation.type === "triggers.clear-crons" ? clearWorkerCronSchedules(name) : clearWorkerCustomDomains(name);
|
|
935
929
|
}
|
|
936
|
-
if (
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
if (
|
|
943
|
-
const raw = config();
|
|
944
|
-
const name = workerName();
|
|
945
|
-
if (raw.name !== name || raw.account_id !== void 0 && raw.account_id !== accountId()) throw new Error("Cloudflare trigger target changed.");
|
|
946
|
-
return await clearWorkerCustomDomains(name);
|
|
947
|
-
}
|
|
948
|
-
if (args[0] === "versions" && args[1] === "upload" || args[0] === "deploy") {
|
|
949
|
-
const raw = config();
|
|
930
|
+
if (operation.type === "triggers.deploy") return withBuildOutput(raw, null, (directory) => runCf([
|
|
931
|
+
"workers",
|
|
932
|
+
"triggers",
|
|
933
|
+
"deploy",
|
|
934
|
+
"--prebuilt"
|
|
935
|
+
], directory));
|
|
936
|
+
if (operation.type === "versions.upload" || operation.type === "worker.deploy") {
|
|
950
937
|
const path = configPath();
|
|
951
938
|
if (typeof raw.main !== "string" || !raw.main || raw.no_bundle !== true) throw new Error("Cloudflare Worker upload requires a prebuilt platform Worker.");
|
|
952
939
|
const source = resolve(dirname(path), raw.main);
|
|
953
|
-
const
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
...args[0] === "deploy" ? ["deploy"] : [
|
|
940
|
+
const request = operation;
|
|
941
|
+
const called = await withBuildOutput(raw, source, (directory) => runCf([
|
|
942
|
+
...request.type === "worker.deploy" ? ["deploy"] : [
|
|
957
943
|
"workers",
|
|
958
944
|
"versions",
|
|
959
945
|
"create"
|
|
960
946
|
],
|
|
961
947
|
"--prebuilt",
|
|
962
|
-
...message ? ["--message", message] : [],
|
|
963
|
-
...
|
|
964
|
-
...args.includes("--dry-run") ? ["--dry-run"] : []
|
|
948
|
+
...request.message ? ["--message", request.message] : [],
|
|
949
|
+
...request.secretsFilePath ? ["--secrets-file", request.secretsFilePath] : []
|
|
965
950
|
], directory));
|
|
951
|
+
if (called.status !== 0) return called;
|
|
952
|
+
let uploaded = {};
|
|
953
|
+
try {
|
|
954
|
+
uploaded = object(parsedJson(called.stdout));
|
|
955
|
+
} catch {}
|
|
956
|
+
const output = called.stdout;
|
|
957
|
+
const versionId = uploaded.version_id ?? uploaded.id ?? uploaded.versionId ?? output.match(/(?:Worker|Current) Version ID:\s*([0-9a-f]{8}-[0-9a-f-]{27})/i)?.[1];
|
|
958
|
+
if (typeof versionId !== "string" || !/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(versionId)) throw new Error("Cloudflare did not return the uploaded Worker version ID.");
|
|
959
|
+
const previewUrl = typeof uploaded.preview_url === "string" ? uploaded.preview_url : output.match(/Version Preview(?: Alias)? URL:\s*(https:\/\/\S+)/i)?.[1];
|
|
960
|
+
const workersDevUrl = typeof uploaded.workers_dev_url === "string" ? uploaded.workers_dev_url : output.match(/(https:\/\/[a-z0-9.-]+\.workers\.dev(?:\/[^\s]*)?)/i)?.[1];
|
|
961
|
+
return result(0, "", called.stderr, {
|
|
962
|
+
versionId,
|
|
963
|
+
...previewUrl ? { previewUrl } : {},
|
|
964
|
+
...workersDevUrl ? { workersDevUrl } : {}
|
|
965
|
+
});
|
|
966
966
|
}
|
|
967
|
-
|
|
967
|
+
throw new Error("Unsupported Cloudflare Worker operation.");
|
|
968
968
|
}
|
|
969
969
|
async function tail() {
|
|
970
|
-
|
|
971
|
-
const
|
|
972
|
-
|
|
970
|
+
if (operation.type !== "tail") throw new Error("Cloudflare tail operation is required.");
|
|
971
|
+
const worker = workerName();
|
|
972
|
+
const raw = config();
|
|
973
|
+
const accountId = process.env.CLOUDFLARE_ACCOUNT_ID ?? raw.account_id;
|
|
974
|
+
if (!worker || typeof accountId !== "string" || !accountId || worker !== raw.name) throw new Error("Cloudflare tail target is not pinned.");
|
|
973
975
|
const filters = [];
|
|
974
|
-
if (
|
|
975
|
-
if (
|
|
976
|
-
if (
|
|
976
|
+
if (operation.search) filters.push({ query: operation.search });
|
|
977
|
+
if (operation.versionId) filters.push({ scriptVersion: operation.versionId });
|
|
978
|
+
if (operation.status === "error") filters.push({ outcome: [
|
|
977
979
|
"exception",
|
|
978
980
|
"exceededCpu",
|
|
979
981
|
"exceededMemory",
|
|
@@ -1010,25 +1012,29 @@ async function tail() {
|
|
|
1010
1012
|
if (stopped.signal.aborted) return result(0);
|
|
1011
1013
|
await new Promise((resolve, reject) => {
|
|
1012
1014
|
finish = resolve;
|
|
1015
|
+
let pendingMessages = Promise.resolve();
|
|
1013
1016
|
socket = new WebSocket(tailUrl, "trace-v1");
|
|
1014
1017
|
socket.addEventListener("open", () => {
|
|
1015
1018
|
socket.send(JSON.stringify({ debug: false }));
|
|
1016
1019
|
});
|
|
1017
1020
|
socket.addEventListener("message", (event) => {
|
|
1018
|
-
|
|
1019
|
-
const
|
|
1021
|
+
pendingMessages = pendingMessages.then(async () => {
|
|
1022
|
+
const data = event.data;
|
|
1023
|
+
const text = typeof data === "string" ? data : data instanceof Blob ? await data.text() : data instanceof ArrayBuffer ? new TextDecoder().decode(data) : null;
|
|
1024
|
+
if (text === null) throw new Error("Unsupported Cloudflare tail frame.");
|
|
1025
|
+
const log = object(parsedJson(text));
|
|
1020
1026
|
const detail = object(log.event ?? {});
|
|
1021
1027
|
const request = object(detail.request ?? {});
|
|
1022
1028
|
const prefix = typeof request.url === "string" ? `${request.method ?? "GET"} ${request.url}` : typeof detail.queue === "string" ? `Queue ${detail.queue}` : typeof detail.mailFrom === "string" ? `Email from ${detail.mailFrom}` : "Worker event";
|
|
1023
1029
|
process.stdout.write(`${prefix} - ${log.outcome ?? "unknown"} @ ${new Date(Number(log.eventTimestamp)).toLocaleString()}\n`);
|
|
1024
1030
|
if (Array.isArray(log.logs)) for (const line of log.logs.map(object)) process.stdout.write(` (${line.level ?? "log"}) ${Array.isArray(line.message) ? line.message.join(" ") : ""}\n`);
|
|
1025
1031
|
if (Array.isArray(log.exceptions)) for (const exception of log.exceptions.map(object)) process.stderr.write(` ${exception.name ?? "Error"}: ${exception.message ?? ""}\n`);
|
|
1026
|
-
}
|
|
1032
|
+
}).catch(() => {
|
|
1027
1033
|
process.stderr.write("Cloudflare returned a malformed tail event.\n");
|
|
1028
|
-
}
|
|
1034
|
+
});
|
|
1029
1035
|
});
|
|
1030
1036
|
socket.addEventListener("error", () => reject(/* @__PURE__ */ new Error("Cloudflare Worker tail connection failed.")));
|
|
1031
|
-
socket.addEventListener("close", () => resolve
|
|
1037
|
+
socket.addEventListener("close", () => void pendingMessages.then(resolve));
|
|
1032
1038
|
if (stopped.signal.aborted) resolve();
|
|
1033
1039
|
});
|
|
1034
1040
|
} catch (error) {
|
|
@@ -1048,34 +1054,49 @@ async function tail() {
|
|
|
1048
1054
|
return result(0);
|
|
1049
1055
|
}
|
|
1050
1056
|
async function main() {
|
|
1051
|
-
if (
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
if (
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1060
|
-
if (args[0] === "deployments" || args[0] === "versions" && args[1] !== "upload") return await workerHistory();
|
|
1061
|
-
if (args[0] === "triggers" || args[0] === "deploy" || args[0] === "versions" && args[1] === "upload" || args[0] === "queues" && args[1] === "consumer") return await workerChanges();
|
|
1062
|
-
if ([
|
|
1063
|
-
"d1",
|
|
1064
|
-
"kv",
|
|
1065
|
-
"r2",
|
|
1066
|
-
"hyperdrive",
|
|
1067
|
-
"queues",
|
|
1068
|
-
"containers"
|
|
1069
|
-
].includes(args[0] ?? "")) return await resources();
|
|
1070
|
-
return result(1, "", `Unsupported Cloudflare operation: ${args.slice(0, 2).join(" ")}.`);
|
|
1057
|
+
if (process.argv.length !== 3) throw new Error("Exactly one typed Cloudflare operation is required.");
|
|
1058
|
+
if (!operation || typeof operation !== "object" || typeof operation.type !== "string") throw new Error("Cloudflare operation is required.");
|
|
1059
|
+
if (operation.type.startsWith("auth.")) return auth();
|
|
1060
|
+
if (operation.type.startsWith("secret.")) return secrets();
|
|
1061
|
+
if (operation.type === "tail") return tail();
|
|
1062
|
+
if (operation.type.startsWith("email.")) return email();
|
|
1063
|
+
if (operation.type.startsWith("deployments.") || operation.type.startsWith("versions.") && operation.type !== "versions.upload") return workerHistory();
|
|
1064
|
+
if (operation.type.startsWith("triggers.") || operation.type === "worker.deploy" || operation.type === "versions.upload" || operation.type === "queues.consumer.remove") return workerChanges();
|
|
1065
|
+
return resources();
|
|
1071
1066
|
}
|
|
1072
1067
|
try {
|
|
1073
1068
|
const output = await main();
|
|
1074
|
-
if (
|
|
1069
|
+
if (operation.type !== "auth.login" && operation.type !== "tail") {
|
|
1070
|
+
let data = output.data;
|
|
1071
|
+
let humanOutput = "";
|
|
1072
|
+
if (data === void 0 && output.stdout.trim()) try {
|
|
1073
|
+
data = parsedJson(output.stdout);
|
|
1074
|
+
} catch {
|
|
1075
|
+
humanOutput = output.stdout;
|
|
1076
|
+
}
|
|
1077
|
+
process.stdout.write(JSON.stringify({
|
|
1078
|
+
operationResult: 1,
|
|
1079
|
+
...output.signal ? { signal: output.signal } : {},
|
|
1080
|
+
...output.error ? { error: output.error } : {},
|
|
1081
|
+
...data !== void 0 ? { data } : {},
|
|
1082
|
+
...output.errorCode !== void 0 ? { errorCode: output.errorCode } : {},
|
|
1083
|
+
...output.failure ? { failure: output.failure } : {},
|
|
1084
|
+
...output.stderr ? { errors: [{
|
|
1085
|
+
code: output.errorCode,
|
|
1086
|
+
message: output.stderr
|
|
1087
|
+
}] } : {},
|
|
1088
|
+
...humanOutput ? { output: humanOutput } : {}
|
|
1089
|
+
}) + "\n");
|
|
1090
|
+
}
|
|
1075
1091
|
if (output.stderr) process.stderr.write(output.stderr);
|
|
1076
1092
|
process.exitCode = output.status;
|
|
1077
1093
|
} catch (error) {
|
|
1078
|
-
|
|
1094
|
+
const message = error instanceof Error ? error.message : "Cloudflare operation failed.";
|
|
1095
|
+
if (operation?.type !== "auth.login" && operation?.type !== "tail") process.stdout.write(JSON.stringify({
|
|
1096
|
+
operationResult: 1,
|
|
1097
|
+
errors: [{ message }]
|
|
1098
|
+
}) + "\n");
|
|
1099
|
+
process.stderr.write(message);
|
|
1079
1100
|
process.exitCode = 1;
|
|
1080
1101
|
}
|
|
1081
1102
|
//#endregion
|