@rebasepro/cli 0.31.0 → 0.33.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/dist/{agent-setup-DqAcoDcn.js → agent-setup-Cg_zBWoW.js} +3 -3
- package/dist/{agent-setup-DqAcoDcn.js.map → agent-setup-Cg_zBWoW.js.map} +1 -1
- package/dist/api-TbmW33D7.js +275 -0
- package/dist/api-TbmW33D7.js.map +1 -0
- package/dist/{api-keys-eIUjMqWn.js → api-keys-fPQ55DCm.js} +151 -158
- package/dist/api-keys-fPQ55DCm.js.map +1 -0
- package/dist/{apps-DExO4PEl.js → apps-DBTRoOeP.js} +18 -13
- package/dist/apps-DBTRoOeP.js.map +1 -0
- package/dist/{args-CaCcrYE1.js → args-DHyrshtI.js} +3 -132
- package/dist/args-DHyrshtI.js.map +1 -0
- package/dist/{atlas-dev-database-DOCKk6ht.js → atlas-dev-database-D6h65f2x.js} +3 -3
- package/dist/{atlas-dev-database-DOCKk6ht.js.map → atlas-dev-database-D6h65f2x.js.map} +1 -1
- package/dist/{auth-ofQETpM5.js → auth-BpyYLEFY.js} +93 -12
- package/dist/auth-BpyYLEFY.js.map +1 -0
- package/dist/auth-session-B6aT0Dyj.js +371 -0
- package/dist/auth-session-B6aT0Dyj.js.map +1 -0
- package/dist/{backend-guard-C0mVkXBw.js → backend-guard-Cf8eMK_f.js} +2 -2
- package/dist/{backend-guard-C0mVkXBw.js.map → backend-guard-Cf8eMK_f.js.map} +1 -1
- package/dist/{branch-pointer-DMPyvZoK.js → branch-pointer-BJOF2Ubv.js} +1 -1
- package/dist/{build-CA5R07tw.js → build-E5hfEWKj.js} +23 -10
- package/dist/build-E5hfEWKj.js.map +1 -0
- package/dist/{bundle-DgILeA5b.js → bundle-CIiKGrte.js} +78 -12
- package/dist/bundle-CIiKGrte.js.map +1 -0
- package/dist/bundle.d.ts +31 -1
- package/dist/{cloud-CYMk92iG.js → cloud-DNJyUU0T.js} +1715 -1516
- package/dist/cloud-DNJyUU0T.js.map +1 -0
- package/dist/{cms-directories-BK3vcswg.js → cms-directories-BaV-Is9a.js} +2 -2
- package/dist/{cms-directories-BK3vcswg.js.map → cms-directories-BaV-Is9a.js.map} +1 -1
- package/dist/codemod/collections-to-tables/backend.d.ts +0 -2
- package/dist/codemod/collections-to-tables/customization.d.ts +7 -1
- package/dist/codemod/collections-to-tables/modules.d.ts +32 -0
- package/dist/codemod/collections-to-tables/plan-context.d.ts +7 -1
- package/dist/{command-D5lhW_-B.js → command-Bks5xkrQ.js} +89 -44
- package/dist/command-Bks5xkrQ.js.map +1 -0
- package/dist/commands/api-keys.d.ts +89 -52
- package/dist/commands/api.d.ts +114 -0
- package/dist/commands/auth-session.d.ts +94 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/cloud/alerts.d.ts +29 -0
- package/dist/commands/cloud/context.d.ts +8 -0
- package/dist/commands/cloud/debug.d.ts +16 -1
- package/dist/commands/cloud/deploy-hooks.d.ts +19 -0
- package/dist/commands/cloud/deploy.d.ts +25 -0
- package/dist/commands/cloud/env.d.ts +12 -1
- package/dist/commands/cloud/index.d.ts +5 -0
- package/dist/commands/cloud/maintenance.d.ts +26 -1
- package/dist/commands/cloud/not-served.d.ts +27 -0
- package/dist/commands/cloud/orgs.d.ts +5 -0
- package/dist/commands/cloud/resources.d.ts +82 -2
- package/dist/commands/cloud/runtime-logs.d.ts +57 -0
- package/dist/commands/cloud/service-key.d.ts +33 -1
- package/dist/commands/cloud/settings.d.ts +3 -0
- package/dist/commands/cron.d.ts +68 -0
- package/dist/commands/data.d.ts +197 -0
- package/dist/commands/functions.d.ts +38 -0
- package/dist/commands/logs.d.ts +22 -0
- package/dist/commands/rls.d.ts +31 -0
- package/dist/commands/schema-reconcile.d.ts +2 -1
- package/dist/commands/schema-show.d.ts +38 -0
- package/dist/commands/storage-objects.d.ts +88 -0
- package/dist/commands/storage.d.ts +18 -2
- package/dist/commands/users.d.ts +147 -0
- package/dist/{consent-BXLIrMl8.js → consent-UV6ObCME.js} +2 -2
- package/dist/{consent-BXLIrMl8.js.map → consent-UV6ObCME.js.map} +1 -1
- package/dist/{console-DjThnr3f.js → console-BVoYOLAO.js} +6 -6
- package/dist/{console-DjThnr3f.js.map → console-BVoYOLAO.js.map} +1 -1
- package/dist/{context--JwaHaZp.js → context-BOMEoKxn.js} +80 -9
- package/dist/{context--JwaHaZp.js.map → context-BOMEoKxn.js.map} +1 -1
- package/dist/cron-CpUsQ739.js +298 -0
- package/dist/cron-CpUsQ739.js.map +1 -0
- package/dist/cron-ZRXsla0v.js +259 -0
- package/dist/cron-ZRXsla0v.js.map +1 -0
- package/dist/{daemon-w30PsdwV.js → daemon-D5gdG7gx.js} +3 -3
- package/dist/{daemon-w30PsdwV.js.map → daemon-D5gdG7gx.js.map} +1 -1
- package/dist/{daemon-entry-zOC1revO.js → daemon-entry--ummUJnk.js} +2 -2
- package/dist/{daemon-entry-zOC1revO.js.map → daemon-entry--ummUJnk.js.map} +1 -1
- package/dist/data-BJ9AZFUC.js +947 -0
- package/dist/data-BJ9AZFUC.js.map +1 -0
- package/dist/{db-Bz2RFGJj.js → db-D_iF4E-v.js} +38 -34
- package/dist/{db-Bz2RFGJj.js.map → db-D_iF4E-v.js.map} +1 -1
- package/dist/debug-nNbbxAeo.js +1114 -0
- package/dist/debug-nNbbxAeo.js.map +1 -0
- package/dist/{derive-C3ezmY-p.js → derive-Mky_u59_.js} +3 -3
- package/dist/{derive-C3ezmY-p.js.map → derive-Mky_u59_.js.map} +1 -1
- package/dist/{dev-D8TxrE_I.js → dev-bj6dEeSQ.js} +13 -13
- package/dist/{dev-D8TxrE_I.js.map → dev-bj6dEeSQ.js.map} +1 -1
- package/dist/dev-db/pull.d.ts +13 -3
- package/dist/{dev-preflight-DjvcV6SK.js → dev-preflight-BMOf2N6r.js} +2 -2
- package/dist/{dev-preflight-DjvcV6SK.js.map → dev-preflight-BMOf2N6r.js.map} +1 -1
- package/dist/{dev-server-BLxCbQEP.js → dev-server-2XHSHM_q.js} +2 -2
- package/dist/{dev-server-BLxCbQEP.js.map → dev-server-2XHSHM_q.js.map} +1 -1
- package/dist/{doctor-Du-mSxoE.js → doctor-FaBObSlb.js} +29 -10
- package/dist/doctor-FaBObSlb.js.map +1 -0
- package/dist/doctor-environment.d.ts +9 -0
- package/dist/{eject-Bhzd6hgb.js → eject-DK_M9kor.js} +4 -4
- package/dist/{eject-Bhzd6hgb.js.map → eject-DK_M9kor.js.map} +1 -1
- package/dist/{fold-static-CKewnAPX.js → fold-static-2t3UUX4z.js} +10 -6
- package/dist/fold-static-2t3UUX4z.js.map +1 -0
- package/dist/fold-static.d.ts +7 -0
- package/dist/functions-B4JR6EZL.js +120 -0
- package/dist/functions-B4JR6EZL.js.map +1 -0
- package/dist/{generate-view-CTOluXvH.js → generate-view-BMaLQm8H.js} +5 -5
- package/dist/{generate-view-CTOluXvH.js.map → generate-view-BMaLQm8H.js.map} +1 -1
- package/dist/{generate_sdk-De-aLC1L.js → generate_sdk-ByD-gTsK.js} +7 -7
- package/dist/{generate_sdk-De-aLC1L.js.map → generate_sdk-ByD-gTsK.js.map} +1 -1
- package/dist/index.es.js +123 -47
- package/dist/index.es.js.map +1 -1
- package/dist/{init-Dtl-IcXf.js → init-DHCe5mJ5.js} +59 -11
- package/dist/init-DHCe5mJ5.js.map +1 -0
- package/dist/{invoked-command-CG_rIa_o.js → invoked-command-FBeIBS8o.js} +2 -2
- package/dist/{invoked-command-CG_rIa_o.js.map → invoked-command-FBeIBS8o.js.map} +1 -1
- package/dist/last-dev-database-CBVkEUEl.js +2 -0
- package/dist/legacy-layout-DI2VeQSV.js +36 -0
- package/dist/legacy-layout-DI2VeQSV.js.map +1 -0
- package/dist/logs-DpuMukJe.js +192 -0
- package/dist/logs-DpuMukJe.js.map +1 -0
- package/dist/{manifest-C3uLDrrJ.js → manifest-RjqxfCpb.js} +114 -5
- package/dist/manifest-RjqxfCpb.js.map +1 -0
- package/dist/{migrate-VrKoi3nB.js → migrate-CSY9ZDKy.js} +5 -4
- package/dist/{migrate-VrKoi3nB.js.map → migrate-CSY9ZDKy.js.map} +1 -1
- package/dist/{normalize-imports-DwxqEMYq.js → normalize-imports-P86NVfpo.js} +3 -3
- package/dist/{normalize-imports-DwxqEMYq.js.map → normalize-imports-P86NVfpo.js.map} +1 -1
- package/dist/{path-flags-7O5uPBcQ.js → path-flags-ekLdkbra.js} +3 -3
- package/dist/{path-flags-7O5uPBcQ.js.map → path-flags-ekLdkbra.js.map} +1 -1
- package/dist/{prepare-Ccxspoj-.js → prepare-BaJe0Zik.js} +4 -4
- package/dist/{prepare-Ccxspoj-.js.map → prepare-BaJe0Zik.js.map} +1 -1
- package/dist/{project-CLcF5i8c.js → project-DALmhb5R.js} +2 -2
- package/dist/{project-CLcF5i8c.js.map → project-DALmhb5R.js.map} +1 -1
- package/dist/project-command-Cl9EZzjr.js +662 -0
- package/dist/project-command-Cl9EZzjr.js.map +1 -0
- package/dist/{project-schema-CsSOG2gE.js → project-schema-Dm6Jk0Y_.js} +4 -2
- package/dist/{project-schema-CsSOG2gE.js.map → project-schema-Dm6Jk0Y_.js.map} +1 -1
- package/dist/{pull-BMuiUyjb.js → pull-CTIsST6T.js} +66 -5
- package/dist/pull-CTIsST6T.js.map +1 -0
- package/dist/resolve-C36px9tR.js +2 -0
- package/dist/{resources-Dpfs2y8P.js → resources-Db3USuPO.js} +5 -5
- package/dist/{resources-Dpfs2y8P.js.map → resources-Db3USuPO.js.map} +1 -1
- package/dist/rls-BxrQ0P50.js +133 -0
- package/dist/rls-BxrQ0P50.js.map +1 -0
- package/dist/{schema-Dv6nHkb0.js → schema-_FzZEoB8.js} +54 -40
- package/dist/schema-_FzZEoB8.js.map +1 -0
- package/dist/{schema-dir-Cd1kvYbf.js → schema-dir-ChcYfWjP.js} +2 -2
- package/dist/{schema-dir-Cd1kvYbf.js.map → schema-dir-ChcYfWjP.js.map} +1 -1
- package/dist/schema-reconcile-DV14XY4o.js +2 -0
- package/dist/schema-show-h72UJ9zH.js +127 -0
- package/dist/schema-show-h72UJ9zH.js.map +1 -0
- package/dist/{skills-CXjA9TWw.js → skills-DQ2bZGkj.js} +6 -5
- package/dist/{skills-CXjA9TWw.js.map → skills-DQ2bZGkj.js.map} +1 -1
- package/dist/star-nudge.d.ts +28 -0
- package/dist/{start-Bwbtt2W5.js → start-Cjx4W0bJ.js} +7 -7
- package/dist/{start-Bwbtt2W5.js.map → start-Cjx4W0bJ.js.map} +1 -1
- package/dist/{status-BTgTWzlQ.js → status-CDBk25VO.js} +9 -9
- package/dist/{status-BTgTWzlQ.js.map → status-CDBk25VO.js.map} +1 -1
- package/dist/{storage-iTqj5-Av.js → storage-Clc8dLG8.js} +79 -36
- package/dist/storage-Clc8dLG8.js.map +1 -0
- package/dist/storage-objects-CfRKlTDe.js +279 -0
- package/dist/storage-objects-CfRKlTDe.js.map +1 -0
- package/dist/{telemetry-BP_1Cl9r.js → telemetry-DZU2-NCm.js} +5 -4
- package/dist/{telemetry-BP_1Cl9r.js.map → telemetry-DZU2-NCm.js.map} +1 -1
- package/dist/{telemetry-M3HjlyhZ.js → telemetry-EVtASbKb.js} +2 -2
- package/dist/{telemetry-M3HjlyhZ.js.map → telemetry-EVtASbKb.js.map} +1 -1
- package/dist/unknown-command-DnZ2uhGs.js +139 -0
- package/dist/unknown-command-DnZ2uhGs.js.map +1 -0
- package/dist/{upgrade-oZzJ13jM.js → upgrade-ZASvgxWM.js} +41 -9
- package/dist/{upgrade-oZzJ13jM.js.map → upgrade-ZASvgxWM.js.map} +1 -1
- package/dist/users-5PkqBY6R.js +561 -0
- package/dist/users-5PkqBY6R.js.map +1 -0
- package/dist/utils/legacy-layout.d.ts +22 -0
- package/dist/utils/project-command.d.ts +38 -0
- package/dist/utils/project-target.d.ts +193 -0
- package/dist/{verify-BkUVGLqo.js → verify-BdeqNb-V.js} +138 -12
- package/dist/verify-BdeqNb-V.js.map +1 -0
- package/dist/{version-Buyyo1ut.js → version-ONIeo7jl.js} +7 -2
- package/dist/{version-Buyyo1ut.js.map → version-ONIeo7jl.js.map} +1 -1
- package/package.json +10 -10
- package/templates/overlays/baas/backend/package.json +3 -1
- package/templates/template/backend/package.json +3 -1
- package/dist/api-keys-eIUjMqWn.js.map +0 -1
- package/dist/apps-DExO4PEl.js.map +0 -1
- package/dist/args-CaCcrYE1.js.map +0 -1
- package/dist/auth-ofQETpM5.js.map +0 -1
- package/dist/build-CA5R07tw.js.map +0 -1
- package/dist/bundle-DgILeA5b.js.map +0 -1
- package/dist/cloud-CYMk92iG.js.map +0 -1
- package/dist/command-D5lhW_-B.js.map +0 -1
- package/dist/doctor-Du-mSxoE.js.map +0 -1
- package/dist/fold-static-CKewnAPX.js.map +0 -1
- package/dist/init-Dtl-IcXf.js.map +0 -1
- package/dist/last-dev-database-Dc8cP01o.js +0 -2
- package/dist/manifest-C3uLDrrJ.js.map +0 -1
- package/dist/pull-BMuiUyjb.js.map +0 -1
- package/dist/resolve-BY7bSFRT.js +0 -2
- package/dist/schema-Dv6nHkb0.js.map +0 -1
- package/dist/schema-reconcile-CjxLaRHB.js +0 -2
- package/dist/storage-iTqj5-Av.js.map +0 -1
- package/dist/verify-BkUVGLqo.js.map +0 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { i as recordEvent, l as durationBucket } from "./telemetry-
|
|
2
|
-
import {
|
|
3
|
-
import { c as findProjectRoot, p as requireProjectRoot } from "./project-
|
|
4
|
-
import { _ as findBackendApp, b as loadManifest, h as cmsMountOf, w as selectDeployApp, y as formatAppAddress } from "./manifest-
|
|
5
|
-
import { t as cliUserAgent } from "./version-
|
|
6
|
-
import {
|
|
7
|
-
import { $ as
|
|
8
|
-
import { n as foldFrontendIntoBundle, r as foldableApps } from "./fold-static-
|
|
9
|
-
import { n as
|
|
10
|
-
import {
|
|
1
|
+
import { i as recordEvent, l as durationBucket } from "./telemetry-EVtASbKb.js";
|
|
2
|
+
import { i as switchOn } from "./args-DHyrshtI.js";
|
|
3
|
+
import { c as findProjectRoot, p as requireProjectRoot } from "./project-DALmhb5R.js";
|
|
4
|
+
import { C as resolveBackendPaths, _ as findBackendApp, b as loadManifest, h as cmsMountOf, w as selectDeployApp, y as formatAppAddress } from "./manifest-RjqxfCpb.js";
|
|
5
|
+
import { t as cliUserAgent } from "./version-ONIeo7jl.js";
|
|
6
|
+
import { E as toolStdio, c as buildBundle, r as UNVENDORED_COST, w as unvendoredReason } from "./bundle-CIiKGrte.js";
|
|
7
|
+
import { $ as resolveCloudTarget, A as linkedEphemeralGrant, B as projectHost, C as getContextOrg, D as isJsonMode, E as initOutputMode, F as parseCloudArgs, G as reportError, H as readLink, I as printGroupHelp, J as requireInteractive, K as requireClient, L as printJson, M as note, N as noteBlank, O as isKnownControlPlane, P as openUrl, Q as requireSessionClient, R as probeToken, S as freshAccessToken, T as grantProjectOf, U as refuseDirectLink, V as projectLinkPath, W as removeLink, X as requireProject, Y as requireKnownAction, Z as requireProjectRef, _ as ephemeralGrantFor, _t as isTokenCapability, a as billingAccountIdOf, at as setCurrentContext, b as fetchTenantBaseDomain, bt as scopesForOrgCapabilities, c as colorStatus, ct as warn, d as createCloudClient, dt as ORG_CAPABILITIES, et as resolveCloudUrl, f as displayProjectRef, ft as ORG_CAPABILITY_NAMES, g as envToken, gt as isOrgCapability, h as emitHelp, ht as capabilitiesInScopes, i as appKeyExpiryNote, it as setContextOrg, j as lookupProjectId, k as keyValues, l as confirmDestructive, lt as writeLink, m as emit, mt as TOKEN_CAPABILITY_NAMES, n as GLOBAL_HELP_FLAGS, nt as resolveTimeoutMs, o as cloudRow, ot as storedGrantForLink, p as dotenvSets, pt as TOKEN_CAPABILITIES, q as requireCloudRow, r as TOKEN_ENV, rt as saveEphemeralGrant, s as cloudRows, st as success, t as GLOBAL_CLOUD_FLAGS, tt as resolveProjectRef, ut as ALWAYS_SCOPES, v as fail, vt as orgCapabilitiesInScopes, w as grantForLink, x as forgetEphemeralGrant, xt as wantsRawError, y as fetchDeployTargets, yt as scopesForCapabilities, z as projectDotenvSetsAppKey } from "./context-BOMEoKxn.js";
|
|
8
|
+
import { n as foldFrontendIntoBundle, r as foldableApps } from "./fold-static-2t3UUX4z.js";
|
|
9
|
+
import { n as legacyCollectionsDir, r as legacyLayoutRefusal, t as MIGRATE_COMMAND } from "./legacy-layout-DI2VeQSV.js";
|
|
10
|
+
import { n as deriveOptionsFor, r as deriveResourceGraph } from "./derive-Mky_u59_.js";
|
|
11
|
+
import { t as buildAssetApp } from "./build-E5hfEWKj.js";
|
|
12
|
+
import { a as parseLogLine, c as resolveOrigin, i as isErrorLine, l as resolveTail, n as debugCommand, o as parseSince, s as printDebugHelp, t as SERVER_MAX_TAIL_LINES } from "./debug-nNbbxAeo.js";
|
|
13
|
+
import { cronCommand, isMissingRoute } from "./cron-ZRXsla0v.js";
|
|
11
14
|
import chalk from "chalk";
|
|
12
15
|
import arg from "arg";
|
|
13
16
|
import fs from "fs";
|
|
@@ -15,12 +18,59 @@ import os from "os";
|
|
|
15
18
|
import path from "path";
|
|
16
19
|
import { execFileSync, spawn } from "child_process";
|
|
17
20
|
import dotenv from "dotenv";
|
|
18
|
-
import { DEFAULT_STORAGE_SOURCE_KEY } from "@rebasepro/types";
|
|
21
|
+
import { BUNDLE_FORMAT_VERSION, DEFAULT_STORAGE_SOURCE_KEY } from "@rebasepro/types";
|
|
19
22
|
import fs$1 from "node:fs";
|
|
20
23
|
import inquirer from "inquirer";
|
|
21
24
|
import { RebaseApiError, createRebaseClient } from "@rebasepro/client";
|
|
22
25
|
import net from "node:net";
|
|
23
26
|
import { parse } from "acorn";
|
|
27
|
+
//#region src/commands/cloud/not-served.ts
|
|
28
|
+
/**
|
|
29
|
+
* A control plane that does not serve a route a command calls.
|
|
30
|
+
*
|
|
31
|
+
* The CLI is released on its own schedule, and the control plane it talks to
|
|
32
|
+
* may be older than the command: a function the command calls may not be
|
|
33
|
+
* mounted there yet, or a function may be mounted without the route the
|
|
34
|
+
* command needs. Both answer 404, and a generic "Not found" for them reads as
|
|
35
|
+
* "your project is gone" or "you typed the id wrong", which sends the reader
|
|
36
|
+
* looking for a fault that is not theirs.
|
|
37
|
+
*
|
|
38
|
+
* So each command that calls such a route names what is missing and what to do
|
|
39
|
+
* instead, with one code, `not_served`, a caller can branch on.
|
|
40
|
+
* `control-plane-functions.test.ts` holds the list of functions this family
|
|
41
|
+
* calls against the ones the control plane serves.
|
|
42
|
+
*/
|
|
43
|
+
/** The refusal code for a route the control plane does not serve. */
|
|
44
|
+
var NOT_SERVED = "not_served";
|
|
45
|
+
/**
|
|
46
|
+
* Whether an error is the control plane saying it has no such route, rather
|
|
47
|
+
* than a route refusing this request.
|
|
48
|
+
*
|
|
49
|
+
* A Rebase backend answers a function it does not mount, or a route its
|
|
50
|
+
* function does not have, with a 404 coded `FUNCTION_NOT_FOUND`; one from
|
|
51
|
+
* before that envelope answers a bare `Not Found` or `No route for …`. A
|
|
52
|
+
* function that is served and refuses an unknown project answers its own code
|
|
53
|
+
* (`not_found`), so that 404 is not this one.
|
|
54
|
+
*/
|
|
55
|
+
function isRouteNotServed(error) {
|
|
56
|
+
if (typeof error !== "object" || error === null) return false;
|
|
57
|
+
if (!("status" in error) || error.status !== 404) return false;
|
|
58
|
+
if (("code" in error ? error.code : void 0) === "FUNCTION_NOT_FOUND") return true;
|
|
59
|
+
return isMissingRoute("message" in error && typeof error.message === "string" ? error.message : void 0);
|
|
60
|
+
}
|
|
61
|
+
/** Refuse with `not_served` when `error` is a missing route; return otherwise. */
|
|
62
|
+
function refuseIfNotServed(error, unserved) {
|
|
63
|
+
if (isRouteNotServed(error)) fail(`This control plane does not serve ${unserved.what} yet.`, unserved.hint, NOT_SERVED);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Report a failed control-plane call: `not_served` for a missing route, the
|
|
67
|
+
* family's usual report otherwise. Never returns.
|
|
68
|
+
*/
|
|
69
|
+
function reportCallError(error, context, unserved) {
|
|
70
|
+
refuseIfNotServed(error, unserved);
|
|
71
|
+
reportError(error, context);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
24
74
|
//#region src/commands/cloud/maintenance.ts
|
|
25
75
|
/**
|
|
26
76
|
* A project's maintenance window, what its database is waiting on, and its
|
|
@@ -67,17 +117,51 @@ function parseDay(value) {
|
|
|
67
117
|
const i = DAY_NAMES.findIndex((d) => d.startsWith(v));
|
|
68
118
|
return i >= 0 ? i : void 0;
|
|
69
119
|
}
|
|
70
|
-
/**
|
|
120
|
+
/** What a command says on a control plane that has no `maintenance` function yet. */
|
|
121
|
+
var MAINTENANCE_UNSERVED = {
|
|
122
|
+
what: "maintenance windows",
|
|
123
|
+
hint: "Nothing was changed. On this control plane a database change from `rebase cloud compute set` is not held for a window."
|
|
124
|
+
};
|
|
125
|
+
/** What `events` says on a control plane that has no `maintenance` function yet. */
|
|
126
|
+
var EVENTS_UNSERVED = {
|
|
127
|
+
what: "project events",
|
|
128
|
+
hint: "`rebase cloud deployments` lists the project's deploys, and `rebase cloud metrics` what it runs now."
|
|
129
|
+
};
|
|
130
|
+
/** The project's maintenance status, and whether the control plane serves it at all. */
|
|
131
|
+
async function readMaintenance(client, projectId) {
|
|
132
|
+
try {
|
|
133
|
+
return {
|
|
134
|
+
kind: "ok",
|
|
135
|
+
status: await client.functions.invoke("maintenance", void 0, {
|
|
136
|
+
method: "GET",
|
|
137
|
+
path: `projects/${encodeURIComponent(projectId)}`
|
|
138
|
+
})
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
return isRouteNotServed(error) ? { kind: "not_served" } : { kind: "failed" };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** The project's maintenance status, or undefined when it could not be read. */
|
|
71
145
|
async function fetchMaintenance(client, projectId) {
|
|
146
|
+
const read = await readMaintenance(client, projectId);
|
|
147
|
+
return read.kind === "ok" ? read.status : void 0;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The status a command that is about maintenance needs, or a refusal: `not_served`
|
|
151
|
+
* on a control plane without the function, the failure itself otherwise.
|
|
152
|
+
*/
|
|
153
|
+
async function requireMaintenance(client, projectId) {
|
|
72
154
|
try {
|
|
73
155
|
return await client.functions.invoke("maintenance", void 0, {
|
|
74
156
|
method: "GET",
|
|
75
157
|
path: `projects/${encodeURIComponent(projectId)}`
|
|
76
158
|
});
|
|
77
|
-
} catch {
|
|
78
|
-
|
|
159
|
+
} catch (error) {
|
|
160
|
+
reportCallError(error, "Could not read the maintenance window", MAINTENANCE_UNSERVED);
|
|
79
161
|
}
|
|
80
162
|
}
|
|
163
|
+
/** The line a page prints in place of its maintenance section on a control plane without it. */
|
|
164
|
+
var MAINTENANCE_NOT_SERVED_NOTE = "This control plane does not report maintenance windows yet, so none is shown.";
|
|
81
165
|
/** One line for a waiting batch: "Database 0.16 → 0.5 vCPU — applies Sunday 9 November, 03:00 UTC". */
|
|
82
166
|
function describePending(open) {
|
|
83
167
|
if (!open) return void 0;
|
|
@@ -96,9 +180,7 @@ async function computeApplyCommand(rawArgs) {
|
|
|
96
180
|
const { client } = await requireClient(rawArgs);
|
|
97
181
|
const projectId = await requireProject(rawArgs, client);
|
|
98
182
|
const ref = displayProjectRef(rawArgs);
|
|
99
|
-
const
|
|
100
|
-
if (!status) fail("This control plane does not schedule database changes yet.", void 0, "unsupported");
|
|
101
|
-
const open = status.open;
|
|
183
|
+
const open = (await requireMaintenance(client, projectId)).open;
|
|
102
184
|
if (!open || open.state !== "pending" && open.state !== "notified") {
|
|
103
185
|
if (open?.state === "applying") {
|
|
104
186
|
emit(() => note(`${open.summary} is being applied now.`), {
|
|
@@ -120,7 +202,7 @@ async function computeApplyCommand(rawArgs) {
|
|
|
120
202
|
try {
|
|
121
203
|
await client.functions.invoke("maintenance", {}, { path: `projects/${encodeURIComponent(projectId)}/apply` });
|
|
122
204
|
} catch (error) {
|
|
123
|
-
|
|
205
|
+
reportCallError(error, "Could not apply the database change", MAINTENANCE_UNSERVED);
|
|
124
206
|
}
|
|
125
207
|
emit(() => {
|
|
126
208
|
success(`Applying ${open.summary}.`);
|
|
@@ -143,8 +225,7 @@ async function computeWindowCommand(rawArgs) {
|
|
|
143
225
|
const dayFlag = flags["--day"];
|
|
144
226
|
const hourFlag = flags["--hour"];
|
|
145
227
|
if (dayFlag === void 0 && hourFlag === void 0) {
|
|
146
|
-
const status = await
|
|
147
|
-
if (!status) fail("This control plane does not schedule database changes yet.", void 0, "unsupported");
|
|
228
|
+
const status = await requireMaintenance(client, projectId);
|
|
148
229
|
emit(() => {
|
|
149
230
|
console.log("");
|
|
150
231
|
keyValues([
|
|
@@ -177,7 +258,7 @@ async function computeWindowCommand(rawArgs) {
|
|
|
177
258
|
path: `projects/${encodeURIComponent(projectId)}/window`
|
|
178
259
|
});
|
|
179
260
|
} catch (error) {
|
|
180
|
-
|
|
261
|
+
reportCallError(error, "Could not move the maintenance window", MAINTENANCE_UNSERVED);
|
|
181
262
|
}
|
|
182
263
|
emit(() => success(`Maintenance window: ${res?.window?.label ?? `${DAYS[day]} ${hourFlag}:00 UTC`}.`), { window: res?.window ?? {
|
|
183
264
|
day,
|
|
@@ -207,7 +288,7 @@ async function eventsCommand(rawArgs) {
|
|
|
207
288
|
path: `projects/${encodeURIComponent(projectId)}/events?limit=${limit}`
|
|
208
289
|
})).events ?? [];
|
|
209
290
|
} catch (error) {
|
|
210
|
-
|
|
291
|
+
reportCallError(error, "Could not read the project's events", EVENTS_UNSERVED);
|
|
211
292
|
}
|
|
212
293
|
emit(() => {
|
|
213
294
|
console.log("");
|
|
@@ -1526,7 +1607,7 @@ async function statusCommand(rawArgs) {
|
|
|
1526
1607
|
try {
|
|
1527
1608
|
const project = await client.data.table("projects").findById(projectId);
|
|
1528
1609
|
if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`, void 0, "not_found");
|
|
1529
|
-
const [db, storage, deploy, baseDomain,
|
|
1610
|
+
const [db, storage, deploy, baseDomain, maintenanceRead] = await Promise.all([
|
|
1530
1611
|
firstRow(client, "databases", projectId),
|
|
1531
1612
|
client.functions.invoke("storage-provision", void 0, {
|
|
1532
1613
|
method: "GET",
|
|
@@ -1534,8 +1615,10 @@ async function statusCommand(rawArgs) {
|
|
|
1534
1615
|
}).catch(() => void 0),
|
|
1535
1616
|
latestDeployment(client, projectId),
|
|
1536
1617
|
fetchTenantBaseDomain(client, url),
|
|
1537
|
-
|
|
1618
|
+
readMaintenance(client, projectId)
|
|
1538
1619
|
]);
|
|
1620
|
+
const maintenance = maintenanceRead.kind === "ok" ? maintenanceRead.status : void 0;
|
|
1621
|
+
const notServed = maintenanceRead.kind === "not_served" ? ["maintenance"] : [];
|
|
1539
1622
|
const storageLine = describeStorageState(storage);
|
|
1540
1623
|
const databaseLine = describeDatabaseState(db);
|
|
1541
1624
|
const link = readLink();
|
|
@@ -1571,6 +1654,7 @@ async function statusCommand(rawArgs) {
|
|
|
1571
1654
|
console.log(` ${chalk.bold(blocked.nextAction ?? "")}`);
|
|
1572
1655
|
}
|
|
1573
1656
|
console.log("");
|
|
1657
|
+
if (notServed.length > 0) note(chalk.gray(MAINTENANCE_NOT_SERVED_NOTE));
|
|
1574
1658
|
}, {
|
|
1575
1659
|
projectId: String(project.id),
|
|
1576
1660
|
name: project.name ?? null,
|
|
@@ -1602,6 +1686,7 @@ async function statusCommand(rawArgs) {
|
|
|
1602
1686
|
window: maintenance.window,
|
|
1603
1687
|
pending: maintenance.open
|
|
1604
1688
|
} : null,
|
|
1689
|
+
notServed,
|
|
1605
1690
|
unclaimed: grant ? {
|
|
1606
1691
|
claimUrl: grant.claimUrl,
|
|
1607
1692
|
expiresAt: grant.expiresAt,
|
|
@@ -1650,16 +1735,65 @@ function cpuLine(m) {
|
|
|
1650
1735
|
const parts = [request != null ? `${request}m guaranteed` : null, limit != null ? `bursts to ${limit}m` : null].filter(Boolean).join(", ");
|
|
1651
1736
|
return `${m.cpu} ${chalk.gray(`(${parts}, per instance)`)}`;
|
|
1652
1737
|
}
|
|
1738
|
+
/** What `rebase cloud metrics` parses. Its page pairs against this. */
|
|
1739
|
+
var METRICS_FLAGS = {
|
|
1740
|
+
"--runtime": Boolean,
|
|
1741
|
+
"--history": Boolean,
|
|
1742
|
+
"--series": String,
|
|
1743
|
+
"--minutes": String
|
|
1744
|
+
};
|
|
1745
|
+
/**
|
|
1746
|
+
* The series a runtime records, and so the ones `--history` may name.
|
|
1747
|
+
*
|
|
1748
|
+
* The runtime's own list (`METRIC_SERIES` in
|
|
1749
|
+
* `packages/server/src/metrics/history-store.ts`), which is not exported;
|
|
1750
|
+
* `cloud-api-commands.test.ts` holds the two together.
|
|
1751
|
+
*/
|
|
1752
|
+
var HISTORY_SERIES = [
|
|
1753
|
+
"cpu_millicores",
|
|
1754
|
+
"memory_bytes",
|
|
1755
|
+
"event_loop_delay_ms"
|
|
1756
|
+
];
|
|
1757
|
+
/** The longest window the runtime keeps: fourteen days, in minutes. */
|
|
1758
|
+
var HISTORY_MAX_MINUTES = 20160;
|
|
1759
|
+
/** The share of requests that failed, as a percentage with one decimal; undefined with no requests. */
|
|
1760
|
+
function errorRate(requests, errors) {
|
|
1761
|
+
if (!requests) return void 0;
|
|
1762
|
+
return `${((errors ?? 0) / requests * 100).toFixed(1)}%`;
|
|
1763
|
+
}
|
|
1764
|
+
/** `--series` and `--minutes`, checked: the series one the runtime records, the window 1 to 14 days in minutes. */
|
|
1765
|
+
function resolveHistoryArgs(flags) {
|
|
1766
|
+
const series = flags["--series"] ?? "cpu_millicores";
|
|
1767
|
+
if (!HISTORY_SERIES.includes(series)) fail(`--series ${series} is not a series the runtime records.`, `Use one of: ${HISTORY_SERIES.join(", ")}.`, "usage");
|
|
1768
|
+
const raw = flags["--minutes"] ?? "60";
|
|
1769
|
+
const minutes = Number(raw);
|
|
1770
|
+
if (!Number.isInteger(minutes) || minutes < 1 || minutes > 20160) fail(`--minutes takes a whole number from 1 to ${HISTORY_MAX_MINUTES} (got "${raw}").`, "The runtime keeps fourteen days.", "usage");
|
|
1771
|
+
return {
|
|
1772
|
+
series,
|
|
1773
|
+
minutes
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1776
|
+
/** A history value in the series' own unit, for a person. */
|
|
1777
|
+
function historyValue(series, value) {
|
|
1778
|
+
if (series === "memory_bytes") return `${(value / 1024 / 1024).toFixed(0)} MiB`;
|
|
1779
|
+
if (series === "cpu_millicores") return `${Math.round(value)}m`;
|
|
1780
|
+
return `${value.toFixed(1)} ms`;
|
|
1781
|
+
}
|
|
1653
1782
|
async function metricsCommand(rawArgs) {
|
|
1654
|
-
parseCloudArgs({
|
|
1655
|
-
spec:
|
|
1783
|
+
const { flags } = parseCloudArgs({
|
|
1784
|
+
spec: METRICS_FLAGS,
|
|
1656
1785
|
rawArgs,
|
|
1657
1786
|
commandWords: 2,
|
|
1658
1787
|
command: "cloud metrics",
|
|
1659
1788
|
maxPositionals: 0
|
|
1660
1789
|
});
|
|
1790
|
+
if (flags["--runtime"] && flags["--history"]) fail("--runtime and --history are two different reports; pass one.", "Run `rebase cloud metrics --help`.", "usage");
|
|
1791
|
+
if (!flags["--history"] && (flags["--series"] !== void 0 || flags["--minutes"] !== void 0)) fail("--series and --minutes go with --history.", "e.g. `rebase cloud metrics --history --series memory_bytes --minutes 180`.", "usage");
|
|
1792
|
+
const history = flags["--history"] ? resolveHistoryArgs(flags) : void 0;
|
|
1661
1793
|
const { client } = await requireClient(rawArgs);
|
|
1662
1794
|
const projectId = await requireProject(rawArgs, client);
|
|
1795
|
+
if (flags["--runtime"]) return runtimeMetrics(client, projectId, displayProjectRef(rawArgs) || projectId);
|
|
1796
|
+
if (history) return historyMetrics(client, projectId, displayProjectRef(rawArgs) || projectId, history);
|
|
1663
1797
|
try {
|
|
1664
1798
|
const [m, realtime] = await Promise.all([client.functions.invoke("metrics", void 0, {
|
|
1665
1799
|
method: "GET",
|
|
@@ -1724,6 +1858,104 @@ async function metricsCommand(rawArgs) {
|
|
|
1724
1858
|
reportError(e, "Failed to fetch metrics");
|
|
1725
1859
|
}
|
|
1726
1860
|
}
|
|
1861
|
+
/** `rebase cloud metrics --runtime`: what the app itself counted since it started. */
|
|
1862
|
+
async function runtimeMetrics(client, projectId, label) {
|
|
1863
|
+
let res;
|
|
1864
|
+
try {
|
|
1865
|
+
res = await client.functions.invoke("metrics", void 0, {
|
|
1866
|
+
method: "GET",
|
|
1867
|
+
path: `${projectId}/runtime`
|
|
1868
|
+
});
|
|
1869
|
+
} catch (e) {
|
|
1870
|
+
reportError(e, "Failed to fetch runtime metrics");
|
|
1871
|
+
}
|
|
1872
|
+
const r = res.rollup ?? null;
|
|
1873
|
+
const rate = r ? errorRate(r.totalRequests, r.totalErrors) : void 0;
|
|
1874
|
+
emit(() => {
|
|
1875
|
+
console.log("");
|
|
1876
|
+
console.log(chalk.bold(` 📈 Runtime — project ${label}`));
|
|
1877
|
+
console.log("");
|
|
1878
|
+
if (!r) {
|
|
1879
|
+
console.log(chalk.gray(" No data yet: the app is not deployed, is still starting, or does not report metrics."));
|
|
1880
|
+
console.log("");
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
keyValues([
|
|
1884
|
+
["Requests", r.totalRequests !== void 0 ? String(r.totalRequests) : void 0],
|
|
1885
|
+
["Errors (5xx)", r.totalErrors !== void 0 ? `${r.totalErrors}${rate ? ` (${rate})` : ""}` : void 0],
|
|
1886
|
+
["Mean latency", r.meanLatencyMs !== void 0 ? `${r.meanLatencyMs.toFixed(1)} ms` : void 0],
|
|
1887
|
+
["Up for", r.uptimeSeconds !== void 0 ? `${Math.round(r.uptimeSeconds / 60)} min` : void 0],
|
|
1888
|
+
["Memory (RSS)", r.rssBytes !== void 0 ? `${(r.rssBytes / 1024 / 1024).toFixed(0)} MiB` : void 0]
|
|
1889
|
+
]);
|
|
1890
|
+
if (r.surfaces?.length) {
|
|
1891
|
+
console.log("");
|
|
1892
|
+
console.log(chalk.gray(` ${"".padEnd(14)} ${"requests".padStart(9)} ${"errors".padStart(7)} ${"latency".padStart(9)}`));
|
|
1893
|
+
for (const surface of r.surfaces) console.log(` ${(surface.surface ?? "?").padEnd(14)} ${String(surface.requests ?? 0).padStart(9)} ${String(surface.errors ?? 0).padStart(7)} ${`${(surface.meanLatencyMs ?? 0).toFixed(1)} ms`.padStart(9)}`);
|
|
1894
|
+
}
|
|
1895
|
+
console.log("");
|
|
1896
|
+
note(chalk.gray("Counted by the running instance since it started; a restart begins again at zero."));
|
|
1897
|
+
console.log("");
|
|
1898
|
+
}, {
|
|
1899
|
+
projectId,
|
|
1900
|
+
at: res.at ?? null,
|
|
1901
|
+
rollup: r,
|
|
1902
|
+
errorRate: r && r.totalRequests ? (r.totalErrors ?? 0) / r.totalRequests : null
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
/** `rebase cloud metrics --history`: one series the runtime recorded, over a window. */
|
|
1906
|
+
async function historyMetrics(client, projectId, label, args) {
|
|
1907
|
+
let res;
|
|
1908
|
+
try {
|
|
1909
|
+
res = await client.functions.invoke("metrics", void 0, {
|
|
1910
|
+
method: "GET",
|
|
1911
|
+
path: `${projectId}/history?series=${encodeURIComponent(args.series)}&minutes=${args.minutes}`
|
|
1912
|
+
});
|
|
1913
|
+
} catch (e) {
|
|
1914
|
+
reportError(e, "Failed to fetch metric history");
|
|
1915
|
+
}
|
|
1916
|
+
const points = Array.isArray(res.points) ? res.points : null;
|
|
1917
|
+
const values = (points ?? []).map((p) => p.value).filter((v) => typeof v === "number" && Number.isFinite(v));
|
|
1918
|
+
const summary = values.length ? {
|
|
1919
|
+
min: Math.min(...values),
|
|
1920
|
+
max: Math.max(...values),
|
|
1921
|
+
mean: values.reduce((a, b) => a + b, 0) / values.length,
|
|
1922
|
+
latest: values[values.length - 1]
|
|
1923
|
+
} : null;
|
|
1924
|
+
emit(() => {
|
|
1925
|
+
console.log("");
|
|
1926
|
+
console.log(chalk.bold(` 🕘 ${args.series} — project ${label}, last ${args.minutes} min`));
|
|
1927
|
+
console.log("");
|
|
1928
|
+
if (!points) {
|
|
1929
|
+
console.log(chalk.yellow(` ${res.reason ?? "The control plane returned no history."}`));
|
|
1930
|
+
console.log("");
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1933
|
+
if (!summary) {
|
|
1934
|
+
console.log(chalk.gray(" Nothing recorded in this window."));
|
|
1935
|
+
console.log("");
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
keyValues([
|
|
1939
|
+
["Samples", String(values.length)],
|
|
1940
|
+
["Latest", historyValue(args.series, summary.latest)],
|
|
1941
|
+
["Mean", historyValue(args.series, summary.mean)],
|
|
1942
|
+
["Min", historyValue(args.series, summary.min)],
|
|
1943
|
+
["Max", historyValue(args.series, summary.max)]
|
|
1944
|
+
]);
|
|
1945
|
+
console.log("");
|
|
1946
|
+
note(chalk.gray("Every sample is in the JSON (`--json`): its time, value and how many instances it covers."));
|
|
1947
|
+
console.log("");
|
|
1948
|
+
}, {
|
|
1949
|
+
projectId,
|
|
1950
|
+
series: res.series ?? args.series,
|
|
1951
|
+
minutes: res.minutes ?? args.minutes,
|
|
1952
|
+
points,
|
|
1953
|
+
summary,
|
|
1954
|
+
reason: points ? null : res.reason ?? null,
|
|
1955
|
+
retryable: points ? null : res.retryable === true
|
|
1956
|
+
});
|
|
1957
|
+
if (!points) process.exitCode = 1;
|
|
1958
|
+
}
|
|
1727
1959
|
/**
|
|
1728
1960
|
* `rebase cloud webhooks` is retired, and says where to go instead.
|
|
1729
1961
|
*
|
|
@@ -1971,7 +2203,8 @@ var CLUSTERS_ACTIONS = [
|
|
|
1971
2203
|
"list",
|
|
1972
2204
|
"add",
|
|
1973
2205
|
"verify",
|
|
1974
|
-
"registry"
|
|
2206
|
+
"registry",
|
|
2207
|
+
"baseline"
|
|
1975
2208
|
];
|
|
1976
2209
|
/**
|
|
1977
2210
|
* `rebase cloud clusters` — list, register and verify the clusters tenants run on.
|
|
@@ -1985,6 +2218,7 @@ async function clustersCommand(action, rawArgs) {
|
|
|
1985
2218
|
if (action === "verify") return clustersVerifyCommand(rawArgs);
|
|
1986
2219
|
if (action === "add") return clustersAddCommand(rawArgs);
|
|
1987
2220
|
if (action === "registry") return clustersRegistryCommand(rawArgs);
|
|
2221
|
+
if (action === "baseline") return clustersBaselineCommand(rawArgs);
|
|
1988
2222
|
requireKnownAction("clusters", action, CLUSTERS_ACTIONS);
|
|
1989
2223
|
return clustersListCommand(rawArgs);
|
|
1990
2224
|
}
|
|
@@ -2060,6 +2294,104 @@ async function clustersVerifyCommand(rawArgs) {
|
|
|
2060
2294
|
}, report);
|
|
2061
2295
|
if (report.verdict === "unusable") process.exitCode = 1;
|
|
2062
2296
|
}
|
|
2297
|
+
/** What `clusters baseline` parses. */
|
|
2298
|
+
var CLUSTER_BASELINE_FLAGS = { "--install": Boolean };
|
|
2299
|
+
/** Which cluster `clusters baseline` was asked about, and whether to install. */
|
|
2300
|
+
function resolveClusterBaselineArgs(rawArgs) {
|
|
2301
|
+
const { flags, positionals } = parseCloudArgs({
|
|
2302
|
+
spec: CLUSTER_BASELINE_FLAGS,
|
|
2303
|
+
rawArgs,
|
|
2304
|
+
commandWords: 2,
|
|
2305
|
+
command: "cloud clusters baseline",
|
|
2306
|
+
maxPositionals: 2
|
|
2307
|
+
});
|
|
2308
|
+
return {
|
|
2309
|
+
id: positionals[1],
|
|
2310
|
+
install: flags["--install"] === true,
|
|
2311
|
+
yes: flags["--yes"] === true
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* The cluster baseline — ingress-nginx, cert-manager, CloudNativePG — on one
|
|
2316
|
+
* cluster: what is installed and ready, and with `--install`, install what is
|
|
2317
|
+
* missing. Platform-admin only, like the rest of `clusters`: installing
|
|
2318
|
+
* operators is a cluster-wide act.
|
|
2319
|
+
*
|
|
2320
|
+
* The install runs in the background on the control plane; its progress lands
|
|
2321
|
+
* on the cluster's row, which a later `clusters baseline <id>` reads back.
|
|
2322
|
+
*/
|
|
2323
|
+
async function clustersBaselineCommand(rawArgs) {
|
|
2324
|
+
const { id, install, yes } = resolveClusterBaselineArgs(rawArgs);
|
|
2325
|
+
if (!id) fail("Usage: rebase cloud clusters baseline <cluster-id> [--install]", void 0, "bad_request");
|
|
2326
|
+
const { client } = await requireClient(rawArgs);
|
|
2327
|
+
const path = encodeURIComponent(id);
|
|
2328
|
+
if (install) {
|
|
2329
|
+
await confirmDestructive({
|
|
2330
|
+
yes,
|
|
2331
|
+
prompt: `Install the missing baseline components (ingress-nginx, cert-manager, CloudNativePG) on cluster ${id}? They are applied cluster-wide.`
|
|
2332
|
+
});
|
|
2333
|
+
let started;
|
|
2334
|
+
try {
|
|
2335
|
+
started = await client.functions.invoke("cluster-baseline", {}, {
|
|
2336
|
+
method: "POST",
|
|
2337
|
+
path
|
|
2338
|
+
});
|
|
2339
|
+
} catch (error) {
|
|
2340
|
+
reportError(error, "Could not start the baseline install");
|
|
2341
|
+
}
|
|
2342
|
+
emit(() => {
|
|
2343
|
+
success(`Installing the baseline on cluster ${id} in the background.`);
|
|
2344
|
+
note(`Follow it with ${chalk.cyan(`rebase cloud clusters baseline ${id}`)}.`);
|
|
2345
|
+
}, {
|
|
2346
|
+
clusterId: started.clusterId ?? id,
|
|
2347
|
+
started: started.started === true
|
|
2348
|
+
});
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
let report;
|
|
2352
|
+
try {
|
|
2353
|
+
report = await client.functions.invoke("cluster-baseline", void 0, {
|
|
2354
|
+
method: "GET",
|
|
2355
|
+
path
|
|
2356
|
+
});
|
|
2357
|
+
} catch (error) {
|
|
2358
|
+
reportError(error, "Could not read the cluster baseline");
|
|
2359
|
+
}
|
|
2360
|
+
let progress;
|
|
2361
|
+
try {
|
|
2362
|
+
const row = await client.data.table("clusters").findById(id);
|
|
2363
|
+
if (row) progress = {
|
|
2364
|
+
baselineStatus: typeof row.baselineStatus === "string" ? row.baselineStatus : null,
|
|
2365
|
+
baselineMessage: typeof row.baselineMessage === "string" ? row.baselineMessage : null
|
|
2366
|
+
};
|
|
2367
|
+
} catch {
|
|
2368
|
+
progress = void 0;
|
|
2369
|
+
}
|
|
2370
|
+
const components = report.components ?? [];
|
|
2371
|
+
emit(() => {
|
|
2372
|
+
console.log("");
|
|
2373
|
+
console.log(` ${report.ready ? chalk.green(chalk.bold("READY")) : chalk.yellow(chalk.bold("INCOMPLETE"))} ${chalk.gray(id)}`);
|
|
2374
|
+
console.log("");
|
|
2375
|
+
for (const c of components) {
|
|
2376
|
+
const state = c.ready ? chalk.green("ready") : c.installed ? chalk.yellow("installed, not ready") : chalk.red("missing");
|
|
2377
|
+
console.log(` ${(c.name ?? "?").padEnd(16)} ${state}${c.detail ? chalk.gray(` ${c.detail}`) : ""}`);
|
|
2378
|
+
}
|
|
2379
|
+
if (progress?.baselineStatus) {
|
|
2380
|
+
console.log("");
|
|
2381
|
+
keyValues([["Last install", progress.baselineStatus]]);
|
|
2382
|
+
}
|
|
2383
|
+
console.log("");
|
|
2384
|
+
if (!report.ready) {
|
|
2385
|
+
note(`Install what is missing with ${chalk.cyan(`rebase cloud clusters baseline ${id} --install`)}.`);
|
|
2386
|
+
console.log("");
|
|
2387
|
+
}
|
|
2388
|
+
}, {
|
|
2389
|
+
clusterId: id,
|
|
2390
|
+
ready: report.ready === true,
|
|
2391
|
+
components,
|
|
2392
|
+
install: progress ?? null
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2063
2395
|
/**
|
|
2064
2396
|
* What `clusters add` was asked to register.
|
|
2065
2397
|
*
|
|
@@ -2336,29 +2668,62 @@ var BILLING_ACTIONS = [
|
|
|
2336
2668
|
"setup",
|
|
2337
2669
|
"checkout",
|
|
2338
2670
|
"invoices",
|
|
2339
|
-
"upcoming"
|
|
2671
|
+
"upcoming",
|
|
2672
|
+
"email"
|
|
2340
2673
|
];
|
|
2674
|
+
/** What `billing invoices` says on a control plane that has no invoice route yet. */
|
|
2675
|
+
var INVOICES_UNSERVED = {
|
|
2676
|
+
what: "invoices",
|
|
2677
|
+
hint: "`rebase cloud billing` shows the billing account and the card on file; Stripe emails each invoice to the billing email."
|
|
2678
|
+
};
|
|
2679
|
+
/** What `billing upcoming` says on a control plane that has no preview route yet. */
|
|
2680
|
+
var UPCOMING_UNSERVED = {
|
|
2681
|
+
what: "a preview of the next invoice",
|
|
2682
|
+
hint: "`rebase cloud compute` prints what a project is quoted per month."
|
|
2683
|
+
};
|
|
2341
2684
|
async function billingCommand(rawArgs) {
|
|
2342
2685
|
const parsed = parseCloudArgs({
|
|
2343
2686
|
spec: { "--limit": Number },
|
|
2344
2687
|
rawArgs,
|
|
2345
2688
|
commandWords: 2,
|
|
2346
2689
|
command: "cloud billing",
|
|
2347
|
-
maxPositionals:
|
|
2690
|
+
maxPositionals: 2
|
|
2348
2691
|
});
|
|
2349
2692
|
const action = parsed.positionals[0];
|
|
2350
2693
|
requireKnownAction("billing", action, BILLING_ACTIONS);
|
|
2351
2694
|
const limit = parsed.flags["--limit"];
|
|
2352
2695
|
if (limit !== void 0 && action !== "invoices") fail("`--limit` applies to `rebase cloud billing invoices` only.", void 0, "usage");
|
|
2696
|
+
const address = parsed.positionals[1];
|
|
2697
|
+
if (address !== void 0 && action !== "email") fail(`Too many arguments for \`rebase cloud billing${action ? ` ${action}` : ""}\`: ${address}`, "Run `rebase cloud billing --help`.", "usage");
|
|
2698
|
+
if (action === "email" && !address?.trim()) fail("Name the address invoices go to.", "`rebase cloud billing email billing@example.com`.", "usage");
|
|
2353
2699
|
const { client, url } = await requireClient(rawArgs);
|
|
2354
2700
|
const org = getContextOrg(url);
|
|
2701
|
+
if (action === "email") {
|
|
2702
|
+
if (!org) fail("No active organization.", "Run `rebase cloud use` first.", "no_org");
|
|
2703
|
+
let res;
|
|
2704
|
+
try {
|
|
2705
|
+
res = await client.functions.invoke("stripe-billing", {
|
|
2706
|
+
organizationId: org,
|
|
2707
|
+
billingEmail: address.trim()
|
|
2708
|
+
}, { path: "billing-email" });
|
|
2709
|
+
} catch (e) {
|
|
2710
|
+
reportError(e, "Failed to change the billing email");
|
|
2711
|
+
}
|
|
2712
|
+
const billingEmail = res.billingEmail ?? address.trim();
|
|
2713
|
+
emit(() => success(`Invoices for org ${org} now go to ${chalk.bold(billingEmail)}.`), {
|
|
2714
|
+
org,
|
|
2715
|
+
billingEmail
|
|
2716
|
+
});
|
|
2717
|
+
return;
|
|
2718
|
+
}
|
|
2355
2719
|
if (action === "invoices" || action === "upcoming") {
|
|
2356
2720
|
if (!org) fail("No active organization.", "Run `rebase cloud use` first.", "no_org");
|
|
2357
2721
|
try {
|
|
2358
2722
|
if (action === "invoices") await billingInvoices(client, org, limit);
|
|
2359
2723
|
else await billingUpcoming(client, org);
|
|
2360
2724
|
} catch (e) {
|
|
2361
|
-
|
|
2725
|
+
if (action === "invoices") reportCallError(e, "Failed to load invoices", INVOICES_UNSERVED);
|
|
2726
|
+
reportCallError(e, "Failed to load the next invoice", UPCOMING_UNSERVED);
|
|
2362
2727
|
}
|
|
2363
2728
|
return;
|
|
2364
2729
|
}
|
|
@@ -2563,7 +2928,7 @@ async function computeCommand(action, rawArgs) {
|
|
|
2563
2928
|
requireKnownAction("compute", action, COMPUTE_ACTIONS);
|
|
2564
2929
|
if (action === "apply") return computeApplyCommand(rawArgs);
|
|
2565
2930
|
if (action === "window") return computeWindowCommand(rawArgs);
|
|
2566
|
-
parseCloudArgs({
|
|
2931
|
+
const { flags: computeFlags } = parseCloudArgs({
|
|
2567
2932
|
spec: action === "set" ? {
|
|
2568
2933
|
...COMPUTE_SET_FLAGS,
|
|
2569
2934
|
[RETIRED_SCALE_TO_ZERO]: String
|
|
@@ -2579,7 +2944,9 @@ async function computeCommand(action, rawArgs) {
|
|
|
2579
2944
|
if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`, void 0, "not_found");
|
|
2580
2945
|
if (action !== "set") {
|
|
2581
2946
|
let quote;
|
|
2582
|
-
const
|
|
2947
|
+
const maintenanceRead = await readMaintenance(client, projectId);
|
|
2948
|
+
const maintenance = maintenanceRead.kind === "ok" ? maintenanceRead.status : void 0;
|
|
2949
|
+
const notServed = maintenanceRead.kind === "not_served" ? ["maintenance"] : [];
|
|
2583
2950
|
try {
|
|
2584
2951
|
quote = await client.functions.invoke("pricing", project, {
|
|
2585
2952
|
method: "POST",
|
|
@@ -2620,6 +2987,7 @@ async function computeCommand(action, rawArgs) {
|
|
|
2620
2987
|
}
|
|
2621
2988
|
console.log("");
|
|
2622
2989
|
noteBlank();
|
|
2990
|
+
if (notServed.length > 0) note(chalk.gray(MAINTENANCE_NOT_SERVED_NOTE));
|
|
2623
2991
|
note("Empty means the platform default. Change one with:");
|
|
2624
2992
|
note(chalk.cyan(" rebase cloud compute set --cpu 500m --memory 2Gi"));
|
|
2625
2993
|
console.log("");
|
|
@@ -2642,13 +3010,24 @@ async function computeCommand(action, rawArgs) {
|
|
|
2642
3010
|
maintenance: maintenance ? {
|
|
2643
3011
|
window: maintenance.window,
|
|
2644
3012
|
pending: maintenance.open
|
|
2645
|
-
} : null
|
|
3013
|
+
} : null,
|
|
3014
|
+
notServed
|
|
2646
3015
|
});
|
|
2647
3016
|
return;
|
|
2648
3017
|
}
|
|
2649
3018
|
const built = buildDialPatch(rawArgs);
|
|
2650
3019
|
if (built.error) fail(built.error, void 0, "bad_request");
|
|
2651
3020
|
const patch = built.patch;
|
|
3021
|
+
const [quoteNow, quoteAfter] = await Promise.all([quoteDials(client, project), quoteDials(client, {
|
|
3022
|
+
...project,
|
|
3023
|
+
...patch
|
|
3024
|
+
})]);
|
|
3025
|
+
const changes = Object.entries(patch).map(([field, value]) => `${field} → ${String(value)}`).join(", ");
|
|
3026
|
+
const price = quoteAfter ? ` Quoted €${quoteAfter.totalEur.toFixed(2)}/month${quoteNow ? ` (now €${quoteNow.totalEur.toFixed(2)})` : ""}.` : "";
|
|
3027
|
+
await confirmDestructive({
|
|
3028
|
+
yes: Boolean(computeFlags["--yes"]),
|
|
3029
|
+
prompt: `Change ${changes} on ${displayProjectRef(rawArgs) || projectId}?${price} The app rolls its pods now; a database change waits for the maintenance window.`
|
|
3030
|
+
});
|
|
2652
3031
|
try {
|
|
2653
3032
|
await client.data.table("projects").update(projectId, patch);
|
|
2654
3033
|
} catch (error) {
|
|
@@ -2674,6 +3053,21 @@ async function computeCommand(action, rawArgs) {
|
|
|
2674
3053
|
});
|
|
2675
3054
|
}
|
|
2676
3055
|
/**
|
|
3056
|
+
* What the control plane quotes for a project's dials, or undefined when it
|
|
3057
|
+
* cannot say. Never throws: a price is context for a question, not its answer.
|
|
3058
|
+
*/
|
|
3059
|
+
async function quoteDials(client, dials) {
|
|
3060
|
+
try {
|
|
3061
|
+
const quote = await client.functions.invoke("pricing", dials, {
|
|
3062
|
+
method: "POST",
|
|
3063
|
+
path: "quote"
|
|
3064
|
+
});
|
|
3065
|
+
return typeof quote?.totalEur === "number" ? quote : void 0;
|
|
3066
|
+
} catch {
|
|
3067
|
+
return;
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
/**
|
|
2677
3071
|
* A dial's value, or a marker that the platform default decides it.
|
|
2678
3072
|
*
|
|
2679
3073
|
* The two are different states and the distinction is not cosmetic: an unset
|
|
@@ -3002,6 +3396,11 @@ function pipeThroughTunnel(socket, endpoint, token) {
|
|
|
3002
3396
|
* The control plane's `db-access` function does the work; how it keeps this
|
|
3003
3397
|
* read-only and to the named addresses is documented there.
|
|
3004
3398
|
*/
|
|
3399
|
+
/** What `db access` says on a control plane that has no `db-access` function yet. */
|
|
3400
|
+
var DB_ACCESS_UNSERVED = {
|
|
3401
|
+
what: "external database access",
|
|
3402
|
+
hint: "Nothing was changed. `rebase cloud db connect` opens a tunnel to the database from this machine."
|
|
3403
|
+
};
|
|
3005
3404
|
var DB_ACCESS_ACTIONS = [
|
|
3006
3405
|
"status",
|
|
3007
3406
|
"enable",
|
|
@@ -3067,9 +3466,15 @@ async function dbAccessCommand(rawArgs) {
|
|
|
3067
3466
|
const action = positionals[0] || "status";
|
|
3068
3467
|
requireKnownAction("db access", action, DB_ACCESS_ACTIONS);
|
|
3069
3468
|
if (action !== "enable" && (flags["--allow"] || flags["--schemas"] || flags["--tables"])) fail("--allow, --schemas and --tables go with `enable`.", "Run `rebase cloud db access --help`.", "invalid_flags");
|
|
3469
|
+
const allow = action === "enable" ? list(flags["--allow"]) : void 0;
|
|
3470
|
+
if (action === "enable" && !allow) fail("Name the addresses the database may be reached from.", "e.g. --allow 34.89.253.13 (repeat it, or separate with commas).", "missing_allow");
|
|
3070
3471
|
const { client } = await requireClient(rawArgs);
|
|
3071
3472
|
const projectId = await requireProject(rawArgs, client);
|
|
3072
3473
|
const projectRef = displayProjectRef(rawArgs);
|
|
3474
|
+
if (action === "enable") await confirmDestructive({
|
|
3475
|
+
yes: Boolean(flags["--yes"]),
|
|
3476
|
+
prompt: `Open project ${projectRef || projectId}'s database to ${allow.join(", ")}? A load balancer admits those addresses to a read-only role over TLS, and is billed while it exists.`
|
|
3477
|
+
});
|
|
3073
3478
|
try {
|
|
3074
3479
|
if (action === "status") {
|
|
3075
3480
|
const status = await client.functions.invoke("db-access", void 0, {
|
|
@@ -3084,8 +3489,6 @@ async function dbAccessCommand(rawArgs) {
|
|
|
3084
3489
|
return;
|
|
3085
3490
|
}
|
|
3086
3491
|
if (action === "enable") {
|
|
3087
|
-
const allow = list(flags["--allow"]);
|
|
3088
|
-
if (!allow) fail("Name the addresses the database may be reached from.", "e.g. --allow 34.89.253.13 (repeat it, or separate with commas).", "missing_allow");
|
|
3089
3492
|
const status = await client.functions.invoke("db-access", {
|
|
3090
3493
|
allow,
|
|
3091
3494
|
schemas: list(flags["--schemas"]),
|
|
@@ -3142,7 +3545,7 @@ async function dbAccessCommand(rawArgs) {
|
|
|
3142
3545
|
...revealed
|
|
3143
3546
|
});
|
|
3144
3547
|
} catch (e) {
|
|
3145
|
-
|
|
3548
|
+
reportCallError(e, `Failed to ${action === "status" ? "read" : action} external database access`, DB_ACCESS_UNSERVED);
|
|
3146
3549
|
}
|
|
3147
3550
|
}
|
|
3148
3551
|
//#endregion
|
|
@@ -4048,6 +4451,11 @@ async function createProject(rawArgs) {
|
|
|
4048
4451
|
const check = await client.functions.invoke("check-subdomain", { subdomain });
|
|
4049
4452
|
if (!check.available) fail(`Subdomain "${subdomain}" is not available${check.reason ? ` (${check.reason})` : ""}.`, void 0, "subdomain_unavailable");
|
|
4050
4453
|
} catch {}
|
|
4454
|
+
const databaseLabel = dbChoice === "managed" ? "a managed database" : dbChoice === "byodb" ? "your own database" : "no database";
|
|
4455
|
+
await confirmDestructive({
|
|
4456
|
+
yes: Boolean(args["--yes"]),
|
|
4457
|
+
prompt: `Create project ${name} at ${subdomain} in org ${org}, with ${databaseLabel}? Its compute and managed database are billed from its first deploy.`
|
|
4458
|
+
});
|
|
4051
4459
|
try {
|
|
4052
4460
|
const user = await client.auth.getUser();
|
|
4053
4461
|
if (!user) fail("Session is no longer valid.", "Run `rebase cloud login` again.", "session_invalid");
|
|
@@ -4313,1318 +4721,173 @@ function fmtDate(value) {
|
|
|
4313
4721
|
return isNaN(d.getTime()) ? value : d.toLocaleString();
|
|
4314
4722
|
}
|
|
4315
4723
|
//#endregion
|
|
4316
|
-
//#region src/commands/cloud/
|
|
4317
|
-
/**
|
|
4318
|
-
* `rebase cloud
|
|
4319
|
-
* app
|
|
4320
|
-
*
|
|
4321
|
-
*
|
|
4322
|
-
*
|
|
4323
|
-
*
|
|
4324
|
-
*
|
|
4325
|
-
*
|
|
4326
|
-
*
|
|
4327
|
-
*
|
|
4328
|
-
*
|
|
4329
|
-
*
|
|
4330
|
-
*
|
|
4331
|
-
*
|
|
4332
|
-
*
|
|
4333
|
-
*
|
|
4334
|
-
*
|
|
4335
|
-
*
|
|
4336
|
-
*
|
|
4337
|
-
*
|
|
4338
|
-
*
|
|
4339
|
-
*
|
|
4340
|
-
*
|
|
4341
|
-
*
|
|
4342
|
-
*
|
|
4343
|
-
*
|
|
4344
|
-
*
|
|
4345
|
-
*
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
*/
|
|
4352
|
-
/** A response never arrived: DNS, TLS, ingress, or the pod. */
|
|
4353
|
-
var NO_RESPONSE = {
|
|
4354
|
-
verdict: "fail",
|
|
4355
|
-
meaning: "nothing answered — the hostname does not resolve, the ingress has no route, or no pod is running"
|
|
4724
|
+
//#region src/commands/cloud/service-key.ts
|
|
4725
|
+
/**
|
|
4726
|
+
* `rebase cloud service-key [rotate]`: the project's `REBASE_SERVICE_KEY`,
|
|
4727
|
+
* admin on the app's own API, and replacing it.
|
|
4728
|
+
*
|
|
4729
|
+
* The control plane derives the key from the project and a generation, and
|
|
4730
|
+
* injects it into the app. `rotate` issues the next generation and restarts
|
|
4731
|
+
* the app onto it in the background; the old key keeps working until that
|
|
4732
|
+
* restart has come up, and nothing after. Anything that copied the old key —
|
|
4733
|
+
* a script, a CI job, an agent's deployed code that printed it — is refused
|
|
4734
|
+
* from then on. A claim rotates it too.
|
|
4735
|
+
*
|
|
4736
|
+
* Without an action, prints the generation, when it was last rotated and
|
|
4737
|
+
* whether a rotation is still restarting the app. The key itself is
|
|
4738
|
+
* `rebase cloud env reveal REBASE_SERVICE_KEY`. Calls `GET` and `POST
|
|
4739
|
+
* /credentials/:projectId/service-key[/rotate]`, owners and admins, signed in.
|
|
4740
|
+
*
|
|
4741
|
+
* ## `--preview <name>`
|
|
4742
|
+
*
|
|
4743
|
+
* A backend preview (`rebase cloud deploy --preview`) runs with a service key
|
|
4744
|
+
* of its own, minted on its first deploy and kept across redeploys; production's
|
|
4745
|
+
* key answers 401 there. `service-key --preview <name>` prints that key, and
|
|
4746
|
+
* `rotate --preview <name>` writes a new one and restarts only the preview's
|
|
4747
|
+
* pod onto it. Calls `POST /previews/:projectId/:name/service-key/reveal` and
|
|
4748
|
+
* `…/rotate`, which ask what production's reveal asks: the organization's owner
|
|
4749
|
+
* or admin role, `project:env` on an access token, and a claimed project. So an
|
|
4750
|
+
* access token with the `env` capability reaches it, as it reaches `env
|
|
4751
|
+
* reveal`, and a login is not required.
|
|
4752
|
+
*
|
|
4753
|
+
* @module
|
|
4754
|
+
*/
|
|
4755
|
+
/** What `service-key` says on a control plane that has no `credentials` function yet. */
|
|
4756
|
+
var SERVICE_KEY_UNSERVED = {
|
|
4757
|
+
what: "service-key rotation",
|
|
4758
|
+
hint: "Nothing was changed. `rebase cloud env reveal REBASE_SERVICE_KEY` still reads the current key."
|
|
4356
4759
|
};
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4760
|
+
/** What `service-key --preview` says on a control plane without the preview key routes. */
|
|
4761
|
+
var PREVIEW_SERVICE_KEY_UNSERVED = {
|
|
4762
|
+
what: "a preview's own service key",
|
|
4763
|
+
hint: "Nothing was changed. The preview still runs with the key its first deploy gave it."
|
|
4764
|
+
};
|
|
4765
|
+
var SERVICE_KEY_FLAGS = {
|
|
4363
4766
|
/**
|
|
4364
|
-
*
|
|
4365
|
-
*
|
|
4767
|
+
* A backend preview's own key instead of production's, the preview named by
|
|
4768
|
+
* the positional after the action. A switch, as `deploy --preview` and
|
|
4769
|
+
* `logs --preview <name>` have it: the dispatcher's list of flags that take
|
|
4770
|
+
* a value is one list for the family (`value-flags.test.ts`).
|
|
4366
4771
|
*/
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
method: "GET",
|
|
4372
|
-
path: () => "/health",
|
|
4373
|
-
healthy: "200 — the backend is up",
|
|
4374
|
-
interpret: (status) => {
|
|
4375
|
-
if (status === null) return NO_RESPONSE;
|
|
4376
|
-
if (status === 200) return {
|
|
4377
|
-
verdict: "ok",
|
|
4378
|
-
meaning: "the backend is up and serving"
|
|
4379
|
-
};
|
|
4380
|
-
if (status === 404) return {
|
|
4381
|
-
verdict: "fail",
|
|
4382
|
-
meaning: "something answered but it is not a Rebase backend — the ingress is routing this host elsewhere"
|
|
4383
|
-
};
|
|
4384
|
-
if (status >= 500) return serverError("its health endpoint is failing");
|
|
4385
|
-
return {
|
|
4386
|
-
verdict: "unknown",
|
|
4387
|
-
meaning: "unexpected for a health endpoint"
|
|
4388
|
-
};
|
|
4389
|
-
}
|
|
4390
|
-
},
|
|
4391
|
-
{
|
|
4392
|
-
id: "spa",
|
|
4393
|
-
label: "spa",
|
|
4394
|
-
method: "GET",
|
|
4395
|
-
path: () => "/",
|
|
4396
|
-
healthy: "200 — the frontend is being served",
|
|
4397
|
-
interpret: (status) => {
|
|
4398
|
-
if (status === null) return NO_RESPONSE;
|
|
4399
|
-
if (status === 200) return {
|
|
4400
|
-
verdict: "ok",
|
|
4401
|
-
meaning: "the frontend bundle is being served"
|
|
4402
|
-
};
|
|
4403
|
-
if (status === 404) return {
|
|
4404
|
-
verdict: "warn",
|
|
4405
|
-
meaning: "no frontend at the root — expected for a backend-only project, otherwise the SPA assets were not bundled into the image"
|
|
4406
|
-
};
|
|
4407
|
-
if (status >= 500) return serverError("the root route throws");
|
|
4408
|
-
return {
|
|
4409
|
-
verdict: "unknown",
|
|
4410
|
-
meaning: "unexpected at the site root"
|
|
4411
|
-
};
|
|
4412
|
-
}
|
|
4413
|
-
},
|
|
4414
|
-
{
|
|
4415
|
-
id: "auth",
|
|
4416
|
-
label: "auth",
|
|
4417
|
-
method: "POST",
|
|
4418
|
-
path: () => "/api/auth/login",
|
|
4419
|
-
body: {},
|
|
4420
|
-
healthy: "400 — auth is mounted and rejects an empty body",
|
|
4421
|
-
interpret: (status) => {
|
|
4422
|
-
if (status === null) return NO_RESPONSE;
|
|
4423
|
-
if (status === 400 || status === 422) return {
|
|
4424
|
-
verdict: "ok",
|
|
4425
|
-
meaning: "auth is mounted and rejected the empty body, as it should"
|
|
4426
|
-
};
|
|
4427
|
-
if (status === 401 || status === 403) return {
|
|
4428
|
-
verdict: "ok",
|
|
4429
|
-
meaning: "auth is mounted and refused the credentials"
|
|
4430
|
-
};
|
|
4431
|
-
if (status === 404) return {
|
|
4432
|
-
verdict: "fail",
|
|
4433
|
-
meaning: "the auth routes are NOT mounted — this project cannot sign anyone in"
|
|
4434
|
-
};
|
|
4435
|
-
if (status === 200) return {
|
|
4436
|
-
verdict: "fail",
|
|
4437
|
-
meaning: "an EMPTY login body was accepted — a login with no credentials must never succeed"
|
|
4438
|
-
};
|
|
4439
|
-
if (status >= 500) return serverError("the login route throws — often a missing or unmigrated auth table");
|
|
4440
|
-
return {
|
|
4441
|
-
verdict: "unknown",
|
|
4442
|
-
meaning: "unexpected for a login route"
|
|
4443
|
-
};
|
|
4444
|
-
}
|
|
4445
|
-
},
|
|
4446
|
-
{
|
|
4447
|
-
id: "unauthRead",
|
|
4448
|
-
label: "unauth read",
|
|
4449
|
-
method: "GET",
|
|
4450
|
-
path: (t) => `/api/data/${encodeURIComponent(t.collection)}`,
|
|
4451
|
-
healthy: "401 — reads require authentication",
|
|
4452
|
-
interpret: (status) => {
|
|
4453
|
-
if (status === null) return NO_RESPONSE;
|
|
4454
|
-
if (status === 401 || status === 403) return {
|
|
4455
|
-
verdict: "ok",
|
|
4456
|
-
meaning: "unauthenticated reads are refused — row-level security is enforced"
|
|
4457
|
-
};
|
|
4458
|
-
if (status === 200) return {
|
|
4459
|
-
verdict: "warn",
|
|
4460
|
-
meaning: "this table is readable with NO authentication — correct only if it is deliberately public"
|
|
4461
|
-
};
|
|
4462
|
-
if (status === 404) return {
|
|
4463
|
-
verdict: "warn",
|
|
4464
|
-
meaning: "no such table on this deployment — check the name, or pass --collection"
|
|
4465
|
-
};
|
|
4466
|
-
if (status >= 500) return serverError("the read reached the database and failed — most often an RLS policy naming a column or table that is not there");
|
|
4467
|
-
return {
|
|
4468
|
-
verdict: "unknown",
|
|
4469
|
-
meaning: "unexpected for a data read"
|
|
4470
|
-
};
|
|
4471
|
-
}
|
|
4472
|
-
},
|
|
4473
|
-
{
|
|
4474
|
-
id: "functions",
|
|
4475
|
-
label: "functions",
|
|
4772
|
+
"--preview": Boolean };
|
|
4773
|
+
var SERVICE_KEY_ACTIONS = ["rotate"];
|
|
4774
|
+
async function readStatus(client, projectId) {
|
|
4775
|
+
return client.functions.invoke("credentials", void 0, {
|
|
4476
4776
|
method: "GET",
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
* route at its own root (see `createFunctionRoutes`), so a 200 proves
|
|
4490
|
-
* the mount *and* names every function that loaded.
|
|
4491
|
-
*/
|
|
4492
|
-
path: () => "/api/functions",
|
|
4493
|
-
healthy: "200 — the functions router is mounted and lists its functions",
|
|
4494
|
-
interpret: (status) => {
|
|
4495
|
-
if (status === null) return NO_RESPONSE;
|
|
4496
|
-
if (status === 200) return {
|
|
4497
|
-
verdict: "ok",
|
|
4498
|
-
meaning: "the functions router is mounted"
|
|
4499
|
-
};
|
|
4500
|
-
if (status === 401 || status === 403) return {
|
|
4501
|
-
verdict: "ok",
|
|
4502
|
-
meaning: "the functions router is mounted (its listing requires auth)"
|
|
4503
|
-
};
|
|
4504
|
-
if (status === 404) return {
|
|
4505
|
-
verdict: "fail",
|
|
4506
|
-
meaning: "the functions router did not mount — no functions directory was found at build time, or it held no functions, so every function on this project is unreachable"
|
|
4507
|
-
};
|
|
4508
|
-
if (status >= 500) return serverError("the functions router throws");
|
|
4509
|
-
return {
|
|
4510
|
-
verdict: "unknown",
|
|
4511
|
-
meaning: "unexpected for the functions listing"
|
|
4512
|
-
};
|
|
4513
|
-
},
|
|
4514
|
-
needsBody: true,
|
|
4515
|
-
refine: (body, t) => {
|
|
4516
|
-
const names = functionNames(body);
|
|
4517
|
-
if (!names) return null;
|
|
4518
|
-
if (t.fn && !names.includes(t.fn)) return {
|
|
4519
|
-
verdict: "fail",
|
|
4520
|
-
meaning: `the router is mounted but no function is named "${t.fn}" — it loaded ${names.length}: ${names.join(", ")}`
|
|
4521
|
-
};
|
|
4522
|
-
const found = t.fn ? `, including ${t.fn}` : "";
|
|
4523
|
-
return {
|
|
4524
|
-
verdict: "ok",
|
|
4525
|
-
meaning: `the functions router is mounted and loaded ${names.length} function${names.length === 1 ? "" : "s"}${found}`
|
|
4526
|
-
};
|
|
4527
|
-
}
|
|
4777
|
+
path: `${encodeURIComponent(projectId)}/service-key`
|
|
4778
|
+
});
|
|
4779
|
+
}
|
|
4780
|
+
function printStatus(status, label) {
|
|
4781
|
+
console.log("");
|
|
4782
|
+
console.log(chalk.bold(` 🛡 Service key — ${label}`));
|
|
4783
|
+
console.log("");
|
|
4784
|
+
console.log(` Generation ${status.generation}`);
|
|
4785
|
+
console.log(` Rotated ${status.rotatedAt ? new Date(status.rotatedAt).toLocaleString() : chalk.gray("never")}`);
|
|
4786
|
+
if (status.pending) {
|
|
4787
|
+
console.log("");
|
|
4788
|
+
console.log(chalk.yellow(" The app has not restarted onto the newest key yet; the previous one still works until it has."));
|
|
4528
4789
|
}
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
if (!Array.isArray(list)) return null;
|
|
4534
|
-
const names = list.map((f) => f?.name).filter((n) => typeof n === "string");
|
|
4535
|
-
return names.length === list.length ? names : null;
|
|
4790
|
+
console.log("");
|
|
4791
|
+
console.log(chalk.gray(` Read it with ${chalk.bold("rebase cloud env reveal REBASE_SERVICE_KEY")}; replace it with ${chalk.bold("rebase cloud service-key rotate")}.`));
|
|
4792
|
+
console.log(chalk.gray(` A backend preview has a key of its own: ${chalk.bold("rebase cloud service-key --preview <name>")}.`));
|
|
4793
|
+
console.log("");
|
|
4536
4794
|
}
|
|
4537
|
-
/** Milliseconds before a probe is treated as unanswered. */
|
|
4538
|
-
var PROBE_TIMEOUT_MS = 1e4;
|
|
4539
4795
|
/**
|
|
4540
|
-
*
|
|
4541
|
-
*
|
|
4542
|
-
*
|
|
4796
|
+
* The preview `--preview` names, as the control plane spells it.
|
|
4797
|
+
*
|
|
4798
|
+
* Only trimmed and lowercased: the control plane decides which names exist,
|
|
4799
|
+
* and answers `not_found` for the rest. `deploy`'s stricter name check is for
|
|
4800
|
+
* a name about to be created.
|
|
4543
4801
|
*/
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
* need to run.
|
|
4549
|
-
*/
|
|
4550
|
-
async function runProbe(origin, spec, targets) {
|
|
4551
|
-
const url = `${origin}${spec.path(targets)}`;
|
|
4552
|
-
const started = Date.now();
|
|
4553
|
-
let status = null;
|
|
4554
|
-
let body;
|
|
4555
|
-
try {
|
|
4556
|
-
const res = await fetch(url, {
|
|
4557
|
-
method: spec.method,
|
|
4558
|
-
headers: spec.body ? { "Content-Type": "application/json" } : void 0,
|
|
4559
|
-
body: spec.body ? JSON.stringify(spec.body) : void 0,
|
|
4560
|
-
redirect: "manual",
|
|
4561
|
-
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS)
|
|
4562
|
-
});
|
|
4563
|
-
status = res.status;
|
|
4564
|
-
if (spec.needsBody && res.ok) {
|
|
4565
|
-
const text = await res.text();
|
|
4566
|
-
if (text.length <= MAX_PROBE_BODY_BYTES) try {
|
|
4567
|
-
body = JSON.parse(text);
|
|
4568
|
-
} catch {}
|
|
4569
|
-
}
|
|
4570
|
-
} catch {
|
|
4571
|
-
status = null;
|
|
4572
|
-
}
|
|
4573
|
-
const statusReading = spec.interpret(status);
|
|
4574
|
-
const reading = status !== null && spec.refine?.(body, targets) || statusReading;
|
|
4575
|
-
return {
|
|
4576
|
-
statusOk: statusReading.verdict === "ok",
|
|
4577
|
-
id: spec.id,
|
|
4578
|
-
label: spec.label,
|
|
4579
|
-
method: spec.method,
|
|
4580
|
-
url,
|
|
4581
|
-
status,
|
|
4582
|
-
ms: Date.now() - started,
|
|
4583
|
-
verdict: reading.verdict,
|
|
4584
|
-
meaning: reading.meaning,
|
|
4585
|
-
healthy: spec.healthy
|
|
4586
|
-
};
|
|
4587
|
-
}
|
|
4588
|
-
/** The worst verdict across probes — what the command's exit code keys off. */
|
|
4589
|
-
function overallVerdict(results) {
|
|
4590
|
-
if (results.some((r) => r.verdict === "fail")) return "fail";
|
|
4591
|
-
if (results.some((r) => r.verdict === "unknown")) return "unknown";
|
|
4592
|
-
if (results.some((r) => r.verdict === "warn")) return "warn";
|
|
4593
|
-
return "ok";
|
|
4594
|
-
}
|
|
4595
|
-
function verdictMark(v) {
|
|
4596
|
-
switch (v) {
|
|
4597
|
-
case "ok": return chalk.green("✓");
|
|
4598
|
-
case "warn": return chalk.yellow("!");
|
|
4599
|
-
case "fail": return chalk.red("✗");
|
|
4600
|
-
default: return chalk.gray("?");
|
|
4601
|
-
}
|
|
4602
|
-
}
|
|
4603
|
-
var LOG_PREFIX_RE = /^(?:(\d{4}-\d{2}-\d{2}T[\d:.]+Z?)\s+)?(?:\[([^\]]+)\]\s+)?([\s\S]*)$/;
|
|
4604
|
-
function parseLogLine(line) {
|
|
4605
|
-
const m = LOG_PREFIX_RE.exec(line);
|
|
4606
|
-
if (!m) return {
|
|
4607
|
-
ts: null,
|
|
4608
|
-
pod: null,
|
|
4609
|
-
text: line
|
|
4610
|
-
};
|
|
4611
|
-
return {
|
|
4612
|
-
ts: m[1] ?? null,
|
|
4613
|
-
pod: m[2] ?? null,
|
|
4614
|
-
text: m[3] ?? ""
|
|
4615
|
-
};
|
|
4616
|
-
}
|
|
4617
|
-
/**
|
|
4618
|
-
* Lines an operator scanning for a fault wants to see.
|
|
4619
|
-
*
|
|
4620
|
-
* Matches the structured `severity` field first, then the shapes that show up
|
|
4621
|
-
* in unstructured output. `refus`/`denied` are in the list because a permission
|
|
4622
|
-
* failure often logs at info level and is exactly what one is hunting for.
|
|
4623
|
-
*/
|
|
4624
|
-
function isErrorLine(text) {
|
|
4625
|
-
return /"(?:severity|level)":\s*"(?:ERROR|WARN(?:ING)?|error|warn)"|\bError:|\bERR!|refus|denied|EACCES|ECONNREFUSED/i.test(text);
|
|
4626
|
-
}
|
|
4627
|
-
/**
|
|
4628
|
-
* Pull an HTTP request record out of a log line, or null when it is not one.
|
|
4629
|
-
*
|
|
4630
|
-
* Only structured request lines are recognised. Guessing at prose would produce
|
|
4631
|
-
* a table with invented columns, which is worse than a short one.
|
|
4632
|
-
*/
|
|
4633
|
-
function parseRequestLine(text) {
|
|
4634
|
-
const start = text.indexOf("{");
|
|
4635
|
-
if (start === -1) return null;
|
|
4636
|
-
let parsed;
|
|
4637
|
-
try {
|
|
4638
|
-
parsed = JSON.parse(text.slice(start));
|
|
4639
|
-
} catch {
|
|
4640
|
-
return null;
|
|
4641
|
-
}
|
|
4642
|
-
if (parsed.message !== "request" && parsed.msg !== "request") return null;
|
|
4643
|
-
const num = (v) => {
|
|
4644
|
-
const n = typeof v === "string" ? Number(v) : typeof v === "number" ? v : NaN;
|
|
4645
|
-
return Number.isFinite(n) ? n : null;
|
|
4646
|
-
};
|
|
4647
|
-
return {
|
|
4648
|
-
status: num(parsed.status),
|
|
4649
|
-
method: typeof parsed.method === "string" ? parsed.method : "",
|
|
4650
|
-
path: typeof parsed.path === "string" ? parsed.path : "",
|
|
4651
|
-
latencyMs: num(parsed.latencyMs ?? parsed.durationMs)
|
|
4652
|
-
};
|
|
4653
|
-
}
|
|
4654
|
-
/**
|
|
4655
|
-
* Startup lines: what the server *decided* it was going to do. Which storage
|
|
4656
|
-
* backend it bound, which functions it loaded, whether auth tables were found.
|
|
4657
|
-
* This is the fastest way to tell a misconfiguration from a runtime fault.
|
|
4658
|
-
*/
|
|
4659
|
-
function isBootLine(text) {
|
|
4660
|
-
return /storage|Loaded (?:custom )?function|Loaded cron|Cron jobs scheduled|Cron scheduler|Mounted|Auth tables|Server running|listening|Refusing|migrat/i.test(text);
|
|
4661
|
-
}
|
|
4662
|
-
/** Render a number of seconds back as the compact duration a user would type. */
|
|
4663
|
-
function formatDuration$2(seconds) {
|
|
4664
|
-
if (seconds % 86400 === 0 && seconds >= 86400) return `${seconds / 86400}d`;
|
|
4665
|
-
if (seconds % 3600 === 0 && seconds >= 3600) return `${seconds / 3600}h`;
|
|
4666
|
-
if (seconds % 60 === 0 && seconds >= 60) return `${seconds / 60}m`;
|
|
4667
|
-
return `${seconds}s`;
|
|
4668
|
-
}
|
|
4669
|
-
/**
|
|
4670
|
-
* Parse a duration like `15m`, `2h`, `90s`, `1d` (or a bare number of seconds)
|
|
4671
|
-
* into seconds. Returns null when it is not a duration.
|
|
4672
|
-
*/
|
|
4673
|
-
function parseSince(input) {
|
|
4674
|
-
if (!input) return null;
|
|
4675
|
-
const m = /^(\d+(?:\.\d+)?)\s*([smhd])?$/i.exec(input.trim());
|
|
4676
|
-
if (!m) return null;
|
|
4677
|
-
const value = parseFloat(m[1]);
|
|
4678
|
-
const unit = (m[2] || "s").toLowerCase();
|
|
4679
|
-
return Math.round(value * (unit === "s" ? 1 : unit === "m" ? 60 : unit === "h" ? 3600 : 86400));
|
|
4680
|
-
}
|
|
4681
|
-
/**
|
|
4682
|
-
* The most lines `runtime-logs` returns per pod.
|
|
4683
|
-
*
|
|
4684
|
-
* The control plane enforces this (`MAX_TAIL_LINES` in
|
|
4685
|
-
* `saas/backend/functions/runtime-logs.ts`) by clamping a larger `tailLines`
|
|
4686
|
-
* without saying so: its answer names neither the limit nor the value it used.
|
|
4687
|
-
* `--tail 200000` therefore came back as 2000 lines reported as untruncated.
|
|
4688
|
-
* The CLI clamps first, with the same number, so the lowering is something it
|
|
4689
|
-
* can print rather than something that happened out of sight.
|
|
4690
|
-
*/
|
|
4691
|
-
var SERVER_MAX_TAIL_LINES = 2e3;
|
|
4692
|
-
function resolveTail(requested, explicit) {
|
|
4693
|
-
const applied = Math.min(requested, SERVER_MAX_TAIL_LINES);
|
|
4694
|
-
return {
|
|
4695
|
-
requested,
|
|
4696
|
-
applied,
|
|
4697
|
-
explicit,
|
|
4698
|
-
note: applied < requested ? `--tail ${requested} was lowered to ${applied}: the control plane returns at most ${SERVER_MAX_TAIL_LINES} lines per pod.` : null
|
|
4699
|
-
};
|
|
4700
|
-
}
|
|
4701
|
-
/** Read `--tail`, refusing anything that is not a positive whole number. */
|
|
4702
|
-
function tailFromFlag(value, fallback) {
|
|
4703
|
-
if (value === void 0) return resolveTail(fallback, false);
|
|
4704
|
-
if (!Number.isInteger(value) || value <= 0) fail(`--tail must be a positive whole number of lines; received "${value}".`, void 0, "usage");
|
|
4705
|
-
return resolveTail(value, true);
|
|
4706
|
-
}
|
|
4707
|
-
/** A span of milliseconds as `29d 23h`, `2h 5m`, `35m`, `40s`. */
|
|
4708
|
-
function formatSpan(ms) {
|
|
4709
|
-
const s = Math.max(0, Math.round(ms / 1e3));
|
|
4710
|
-
const d = Math.floor(s / 86400);
|
|
4711
|
-
const h = Math.floor(s % 86400 / 3600);
|
|
4712
|
-
const m = Math.floor(s % 3600 / 60);
|
|
4713
|
-
if (d > 0) return h > 0 ? `${d}d ${h}h` : `${d}d`;
|
|
4714
|
-
if (h > 0) return m > 0 ? `${h}h ${m}m` : `${h}h`;
|
|
4715
|
-
if (m > 0) return `${m}m`;
|
|
4716
|
-
return `${s}s`;
|
|
4717
|
-
}
|
|
4718
|
-
function timestampRange(lines) {
|
|
4719
|
-
let first = null;
|
|
4720
|
-
let last = null;
|
|
4721
|
-
for (const l of lines) {
|
|
4722
|
-
if (!l.ts) continue;
|
|
4723
|
-
const ms = Date.parse(l.ts);
|
|
4724
|
-
if (Number.isNaN(ms)) continue;
|
|
4725
|
-
if (!first || ms < first.ms) first = {
|
|
4726
|
-
text: l.ts,
|
|
4727
|
-
ms
|
|
4728
|
-
};
|
|
4729
|
-
if (!last || ms > last.ms) last = {
|
|
4730
|
-
text: l.ts,
|
|
4731
|
-
ms
|
|
4732
|
-
};
|
|
4733
|
-
}
|
|
4734
|
-
return {
|
|
4735
|
-
first: first?.text ?? null,
|
|
4736
|
-
last: last?.text ?? null
|
|
4737
|
-
};
|
|
4738
|
-
}
|
|
4739
|
-
/**
|
|
4740
|
-
* Compare what a read covered with what it asked for.
|
|
4741
|
-
*
|
|
4742
|
-
* The server's `truncated` describes only its byte budgets and pod ceiling, so
|
|
4743
|
-
* a pod that filled the line limit came back marked complete however much of
|
|
4744
|
-
* the window it left unread. The line limit is the cut that matters most, and
|
|
4745
|
-
* it is detected here: a pod that returned as many lines as the limit, whose
|
|
4746
|
-
* earliest line is later than the start of the window, was cut by it.
|
|
4747
|
-
*
|
|
4748
|
-
* Filling the limit is the half that separates a cut from a young pod. A pod
|
|
4749
|
-
* that started an hour ago also has no line older than an hour; it returned
|
|
4750
|
-
* fewer lines than the limit, so what came back is its whole log, and nothing
|
|
4751
|
-
* was cut.
|
|
4752
|
-
*/
|
|
4753
|
-
function assessCoverage(opts) {
|
|
4754
|
-
const { res, lines, sinceSeconds, tail, now } = opts;
|
|
4755
|
-
const windowStartMs = sinceSeconds === null ? null : now - sinceSeconds * 1e3;
|
|
4756
|
-
const requestedFrom = windowStartMs === null ? null : new Date(windowStartMs).toISOString();
|
|
4757
|
-
const limitName = tail.note ? `the control plane's ceiling of ${tail.applied} lines per pod` : tail.explicit ? `the --tail ${tail.applied} limit` : `the default of ${tail.applied} lines per pod`;
|
|
4758
|
-
const raise = tail.applied < 2e3 ? ` Raise --tail (at most ${SERVER_MAX_TAIL_LINES}) to read further back.` : ` The control plane returns only each pod's newest ${SERVER_MAX_TAIL_LINES}, so older lines cannot be read from here.`;
|
|
4759
|
-
const pods = (res.pods ?? []).map((p) => {
|
|
4760
|
-
const range = timestampRange(lines.filter((l) => l.pod === p.pod));
|
|
4761
|
-
const base = {
|
|
4762
|
-
...p,
|
|
4763
|
-
firstTimestamp: range.first,
|
|
4764
|
-
lastTimestamp: range.last
|
|
4765
|
-
};
|
|
4766
|
-
if (p.state !== "ok") return {
|
|
4767
|
-
...base,
|
|
4768
|
-
truncated: false,
|
|
4769
|
-
truncatedBy: null,
|
|
4770
|
-
truncatedReason: null,
|
|
4771
|
-
complete: false
|
|
4772
|
-
};
|
|
4773
|
-
if (p.truncated) return {
|
|
4774
|
-
...base,
|
|
4775
|
-
truncated: true,
|
|
4776
|
-
truncatedBy: "bytes",
|
|
4777
|
-
truncatedReason: `${p.pod}: the control plane's per-pod byte budget cut this pod's output short` + (range.first ? ` — what fit runs ${range.first} to ${range.last}.` : "."),
|
|
4778
|
-
complete: false
|
|
4779
|
-
};
|
|
4780
|
-
const firstMs = range.first ? Date.parse(range.first) : null;
|
|
4781
|
-
const startsLate = windowStartMs === null || firstMs === null || firstMs > windowStartMs;
|
|
4782
|
-
if (p.lines >= tail.applied && startsLate) {
|
|
4783
|
-
let reason;
|
|
4784
|
-
if (firstMs === null) reason = `${p.pod}: returned ${p.lines} lines, ${limitName}; they carry no timestamps, so how far back they reach is unknown.`;
|
|
4785
|
-
else if (sinceSeconds !== null && windowStartMs !== null) reason = `${p.pod}: returned ${p.lines} lines, ${limitName}, and the earliest is ${range.first} — ${formatSpan(firstMs - windowStartMs)} after the ${formatDuration$2(sinceSeconds)} window begins (${requestedFrom}). Lines in between were not read.${raise}`;
|
|
4786
|
-
else reason = `${p.pod}: returned ${p.lines} lines, ${limitName}, so its log before ${range.first} was not read.${raise}`;
|
|
4787
|
-
return {
|
|
4788
|
-
...base,
|
|
4789
|
-
truncated: true,
|
|
4790
|
-
truncatedBy: "tail",
|
|
4791
|
-
truncatedReason: reason,
|
|
4792
|
-
complete: false
|
|
4793
|
-
};
|
|
4794
|
-
}
|
|
4795
|
-
return {
|
|
4796
|
-
...base,
|
|
4797
|
-
truncated: false,
|
|
4798
|
-
truncatedBy: null,
|
|
4799
|
-
truncatedReason: null,
|
|
4800
|
-
complete: true
|
|
4801
|
-
};
|
|
4802
|
-
});
|
|
4803
|
-
const truncatedReasons = pods.flatMap((p) => p.truncatedReason ? [p.truncatedReason] : []);
|
|
4804
|
-
if (res.truncated && !pods.some((p) => p.truncatedBy === "bytes")) truncatedReasons.push("The control plane trimmed the combined result (its total byte budget, or the most pods it reads at once); the oldest lines were dropped.");
|
|
4805
|
-
const overall = timestampRange(lines);
|
|
4806
|
-
return {
|
|
4807
|
-
requestedFrom,
|
|
4808
|
-
firstTimestamp: overall.first,
|
|
4809
|
-
lastTimestamp: overall.last,
|
|
4810
|
-
pods,
|
|
4811
|
-
truncated: Boolean(res.truncated) || pods.some((p) => p.truncated),
|
|
4812
|
-
truncatedReasons
|
|
4813
|
-
};
|
|
4814
|
-
}
|
|
4815
|
-
async function fetchRuntimeLogs(client, projectId, opts) {
|
|
4816
|
-
const params = new URLSearchParams();
|
|
4817
|
-
if (opts.sinceSeconds !== void 0) params.set("sinceSeconds", String(opts.sinceSeconds));
|
|
4818
|
-
if (opts.tailLines !== void 0) params.set("tailLines", String(opts.tailLines));
|
|
4819
|
-
if (opts.previous) params.set("previous", "true");
|
|
4820
|
-
params.set("timestamps", "true");
|
|
4821
|
-
const qs = params.toString();
|
|
4822
|
-
return client.functions.invoke("runtime-logs", void 0, {
|
|
4823
|
-
method: "GET",
|
|
4824
|
-
path: `${projectId}${qs ? `?${qs}` : ""}`
|
|
4825
|
-
});
|
|
4826
|
-
}
|
|
4827
|
-
/** Print the per-pod states runtime-logs reports, including its hints. */
|
|
4828
|
-
function printPodStates(res) {
|
|
4829
|
-
if (res.state === "no_pods") {
|
|
4830
|
-
console.log(chalk.yellow(` ${res.message ?? "No pods are running for this project."}`));
|
|
4831
|
-
console.log("");
|
|
4832
|
-
return;
|
|
4833
|
-
}
|
|
4834
|
-
for (const p of res.pods ?? []) {
|
|
4835
|
-
if (p.state === "ok") continue;
|
|
4836
|
-
console.log(` ${chalk.yellow(p.pod)} ${chalk.gray(`(${p.state})`)}`);
|
|
4837
|
-
if (p.message) console.log(chalk.gray(` ${p.message}`));
|
|
4838
|
-
if (p.hint) console.log(chalk.cyan(` → ${p.hint}`));
|
|
4839
|
-
}
|
|
4840
|
-
}
|
|
4841
|
-
/**
|
|
4842
|
-
* The window asked for, the window delivered, and every cut between them.
|
|
4843
|
-
* Printed after the lines, where a reader's eye is when the output ends.
|
|
4844
|
-
*/
|
|
4845
|
-
function printCoverage(coverage, tail) {
|
|
4846
|
-
const asked = coverage.requestedFrom ? `from ${coverage.requestedFrom}` : "from each pod's start";
|
|
4847
|
-
const got = coverage.firstTimestamp && coverage.lastTimestamp ? `${coverage.firstTimestamp} → ${coverage.lastTimestamp} (${formatSpan(Date.parse(coverage.lastTimestamp) - Date.parse(coverage.firstTimestamp))})` : "no timestamped lines";
|
|
4848
|
-
console.log(chalk.gray(` Asked for: ${asked}`));
|
|
4849
|
-
console.log(chalk.gray(` Returned: ${got}`));
|
|
4850
|
-
if (tail.note) console.log(chalk.yellow(` ! ${tail.note}`));
|
|
4851
|
-
if (coverage.truncated) {
|
|
4852
|
-
console.log(chalk.yellow(" ! Truncated — the lines above do not cover the window asked for:"));
|
|
4853
|
-
for (const reason of coverage.truncatedReasons) console.log(chalk.yellow(` ${reason}`));
|
|
4854
|
-
}
|
|
4855
|
-
console.log("");
|
|
4856
|
-
}
|
|
4857
|
-
/**
|
|
4858
|
-
* Resolve the public origin a project is served at — or `--host`, when given.
|
|
4859
|
-
*
|
|
4860
|
-
* Shared with `rebase cloud cron`, which reads the runtime at the same address
|
|
4861
|
-
* `debug health` probes.
|
|
4862
|
-
*/
|
|
4863
|
-
async function resolveOrigin(rawArgs, client, url, projectId) {
|
|
4864
|
-
const parsed = arg({ "--host": String }, {
|
|
4865
|
-
argv: rawArgs.slice(3),
|
|
4866
|
-
permissive: true
|
|
4867
|
-
});
|
|
4868
|
-
if (parsed["--host"]) {
|
|
4869
|
-
const h = parsed["--host"].trim().replace(/\/+$/, "");
|
|
4870
|
-
return /^https?:\/\//.test(h) ? h : `https://${h}`;
|
|
4871
|
-
}
|
|
4872
|
-
const [project, baseDomain] = await Promise.all([client.data.table("projects").findById(projectId), fetchTenantBaseDomain(client, url)]);
|
|
4873
|
-
if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`);
|
|
4874
|
-
const host = projectHost(project, baseDomain);
|
|
4875
|
-
if (!host) fail("Could not determine the public URL for this project.", "It may never have been deployed. Pass --host <hostname> to probe an address directly.");
|
|
4876
|
-
return `https://${host}`;
|
|
4877
|
-
}
|
|
4878
|
-
async function healthCommand(rawArgs) {
|
|
4879
|
-
const { flags: parsed } = parseCloudArgs({
|
|
4880
|
-
spec: HEALTH_FLAGS,
|
|
4881
|
-
rawArgs,
|
|
4882
|
-
commandWords: 3,
|
|
4883
|
-
command: "cloud debug",
|
|
4884
|
-
maxPositionals: 0
|
|
4885
|
-
});
|
|
4886
|
-
const targets = {
|
|
4887
|
-
collection: parsed["--collection"] || "users",
|
|
4888
|
-
fn: parsed["--function"]
|
|
4889
|
-
};
|
|
4890
|
-
const { client, url } = await requireClient(rawArgs);
|
|
4891
|
-
const origin = await resolveOrigin(rawArgs, client, url, await requireProject(rawArgs, client));
|
|
4892
|
-
const results = [];
|
|
4893
|
-
for (const spec of PROBES) results.push(await runProbe(origin, spec, targets));
|
|
4894
|
-
const overall = overallVerdict(results);
|
|
4895
|
-
emit(() => {
|
|
4896
|
-
console.log("");
|
|
4897
|
-
console.log(chalk.bold(` 🩺 Health — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${origin}`));
|
|
4898
|
-
console.log("");
|
|
4899
|
-
const width = Math.max(...results.map((r) => r.label.length));
|
|
4900
|
-
for (const r of results) {
|
|
4901
|
-
const code = r.status === null ? chalk.red("---") : String(r.status);
|
|
4902
|
-
console.log(` ${verdictMark(r.verdict)} ${chalk.bold(r.label.padEnd(width))} ${code.padStart(3)} ${chalk.gray(`${r.ms}ms`)}`);
|
|
4903
|
-
console.log(` ${chalk.gray(r.meaning)}`);
|
|
4904
|
-
}
|
|
4905
|
-
console.log("");
|
|
4906
|
-
if (overall === "ok") console.log(chalk.green(" Everything reachable and wired as expected."));
|
|
4907
|
-
else {
|
|
4908
|
-
const bad = results.filter((r) => r.verdict === "fail" || r.verdict === "warn");
|
|
4909
|
-
console.log(chalk.gray(` ${bad.length} of ${results.length} check${bad.length === 1 ? "" : "s"} need attention.`));
|
|
4910
|
-
const wrongStatus = bad.filter((r) => !r.statusOk);
|
|
4911
|
-
if (wrongStatus.length > 0) {
|
|
4912
|
-
console.log(chalk.gray(" A healthy deployment answers:"));
|
|
4913
|
-
for (const r of wrongStatus) console.log(chalk.gray(` ${r.label.padEnd(width)} ${r.healthy}`));
|
|
4914
|
-
}
|
|
4915
|
-
}
|
|
4916
|
-
console.log("");
|
|
4917
|
-
}, {
|
|
4918
|
-
origin,
|
|
4919
|
-
overall,
|
|
4920
|
-
probes: results
|
|
4921
|
-
});
|
|
4922
|
-
if (overall === "fail") process.exit(1);
|
|
4923
|
-
}
|
|
4924
|
-
/** What `debug logs`, `errors` and `boot` parse. Their help pairs against this. */
|
|
4925
|
-
var LOG_VIEW_FLAGS = {
|
|
4926
|
-
"--since": String,
|
|
4927
|
-
"--tail": Number,
|
|
4928
|
-
"--previous": Boolean
|
|
4929
|
-
};
|
|
4930
|
-
/** What `debug requests` parses. */
|
|
4931
|
-
var REQUESTS_FLAGS = {
|
|
4932
|
-
"--since": String,
|
|
4933
|
-
"--tail": Number
|
|
4934
|
-
};
|
|
4935
|
-
/** What `debug health` parses. */
|
|
4936
|
-
var HEALTH_FLAGS = {
|
|
4937
|
-
"--collection": String,
|
|
4938
|
-
"--function": String,
|
|
4939
|
-
"--host": String
|
|
4940
|
-
};
|
|
4941
|
-
var LOG_VIEWS = {
|
|
4942
|
-
logs: {
|
|
4943
|
-
defaultSinceSeconds: 900,
|
|
4944
|
-
defaultTail: 500,
|
|
4945
|
-
limit: 200,
|
|
4946
|
-
title: "📄 Logs"
|
|
4947
|
-
},
|
|
4948
|
-
errors: {
|
|
4949
|
-
filter: isErrorLine,
|
|
4950
|
-
defaultSinceSeconds: 3600,
|
|
4951
|
-
defaultTail: 500,
|
|
4952
|
-
limit: 40,
|
|
4953
|
-
title: "🔥 Errors"
|
|
4954
|
-
},
|
|
4955
|
-
boot: {
|
|
4956
|
-
filter: isBootLine,
|
|
4957
|
-
defaultSinceSeconds: null,
|
|
4958
|
-
defaultTail: SERVER_MAX_TAIL_LINES,
|
|
4959
|
-
limit: 25,
|
|
4960
|
-
title: "🚀 Boot",
|
|
4961
|
-
needsStart: true
|
|
4962
|
-
}
|
|
4963
|
-
};
|
|
4964
|
-
var REQUESTS_DEFAULTS = {
|
|
4965
|
-
sinceSeconds: 900,
|
|
4966
|
-
tail: 1e3
|
|
4967
|
-
};
|
|
4968
|
-
/** Read `--since`, refusing anything that is not a duration. Undefined when it was not given. */
|
|
4969
|
-
function sinceFromFlag(sinceArg) {
|
|
4970
|
-
if (sinceArg === void 0) return void 0;
|
|
4971
|
-
const seconds = parseSince(sinceArg);
|
|
4972
|
-
if (seconds === null) fail(`--since must be a duration like 15m, 2h or 90s; received "${sinceArg}".`);
|
|
4973
|
-
return seconds;
|
|
4974
|
-
}
|
|
4975
|
-
function windowLabel(sinceSeconds) {
|
|
4976
|
-
return sinceSeconds === null ? "since each pod started" : `last ${formatDuration$2(sinceSeconds)}`;
|
|
4977
|
-
}
|
|
4978
|
-
/**
|
|
4979
|
-
* Whether a boot read reached each pod's start, which is where its startup
|
|
4980
|
-
* lines are. A pod whose read was cut has not been looked at there, so finding
|
|
4981
|
-
* no startup lines in it means nothing — and a line from later in its life
|
|
4982
|
-
* that happens to mention `storage` is not its startup.
|
|
4983
|
-
*
|
|
4984
|
-
* Under `--since` a pod is never counted as reached: a complete read of the
|
|
4985
|
-
* window starts at the pod's first line only if the pod started inside it, and
|
|
4986
|
-
* nothing in the answer says whether it did.
|
|
4987
|
-
*/
|
|
4988
|
-
function bootReach(pods, sinceSeconds) {
|
|
4989
|
-
const unreached = pods.filter((p) => p.state === "ok" && (!p.complete || sinceSeconds !== null)).map((p) => p.pod);
|
|
4990
|
-
return {
|
|
4991
|
-
reachedStart: unreached.length === 0,
|
|
4992
|
-
unreached
|
|
4993
|
-
};
|
|
4802
|
+
function previewNameArg(raw, usage) {
|
|
4803
|
+
const name = (raw ?? "").trim().toLowerCase();
|
|
4804
|
+
if (name === "") fail(`Name the preview: \`${usage}\`.`, "`rebase cloud previews` lists them.", "usage");
|
|
4805
|
+
return name;
|
|
4994
4806
|
}
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
spec: LOG_VIEW_FLAGS,
|
|
4998
|
-
rawArgs,
|
|
4999
|
-
commandWords: 3,
|
|
5000
|
-
command: "cloud debug",
|
|
5001
|
-
maxPositionals: 0
|
|
5002
|
-
});
|
|
5003
|
-
const sinceSeconds = sinceFromFlag(parsed["--since"]) ?? view.defaultSinceSeconds;
|
|
5004
|
-
const tail = tailFromFlag(parsed["--tail"], view.defaultTail);
|
|
5005
|
-
const { client } = await requireClient(rawArgs);
|
|
5006
|
-
const projectId = await requireProject(rawArgs, client);
|
|
5007
|
-
let res;
|
|
5008
|
-
try {
|
|
5009
|
-
res = await fetchRuntimeLogs(client, projectId, {
|
|
5010
|
-
sinceSeconds: sinceSeconds ?? void 0,
|
|
5011
|
-
tailLines: tail.applied,
|
|
5012
|
-
previous: Boolean(parsed["--previous"])
|
|
5013
|
-
});
|
|
5014
|
-
} catch (e) {
|
|
5015
|
-
reportError(e, "Failed to fetch runtime logs");
|
|
5016
|
-
}
|
|
5017
|
-
const parsedLines = (res.logs ?? "").split("\n").filter((l) => l !== "").map(parseLogLine);
|
|
5018
|
-
const kept = view.filter ? parsedLines.filter((l) => view.filter(l.text)) : parsedLines;
|
|
5019
|
-
const shown = kept.slice(-view.limit);
|
|
5020
|
-
const coverage = assessCoverage({
|
|
5021
|
-
res,
|
|
5022
|
-
lines: parsedLines,
|
|
5023
|
-
sinceSeconds,
|
|
5024
|
-
tail,
|
|
5025
|
-
now: Date.now()
|
|
5026
|
-
});
|
|
5027
|
-
const reach = view.needsStart ? bootReach(coverage.pods, sinceSeconds) : null;
|
|
5028
|
-
emit(() => {
|
|
5029
|
-
console.log("");
|
|
5030
|
-
console.log(chalk.bold(` ${view.title} — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${windowLabel(sinceSeconds)}`));
|
|
5031
|
-
console.log("");
|
|
5032
|
-
printPodStates(res);
|
|
5033
|
-
if (shown.length === 0) {
|
|
5034
|
-
console.log(chalk.gray(" (nothing matched in what was read)"));
|
|
5035
|
-
console.log("");
|
|
5036
|
-
} else {
|
|
5037
|
-
for (const l of shown) console.log(` ${l.pod ? chalk.gray(`[${l.pod}] `) : ""}${l.text}`);
|
|
5038
|
-
console.log("");
|
|
5039
|
-
if (kept.length > shown.length) {
|
|
5040
|
-
console.log(chalk.gray(` (showing the last ${shown.length} of ${kept.length} matching lines)`));
|
|
5041
|
-
console.log("");
|
|
5042
|
-
}
|
|
5043
|
-
}
|
|
5044
|
-
printCoverage(coverage, tail);
|
|
5045
|
-
if (reach && !reach.reachedStart) {
|
|
5046
|
-
const which = reach.unreached.join(", ");
|
|
5047
|
-
console.log(chalk.yellow(sinceSeconds === null ? ` ! The start of ${which} was not read, so its startup lines are not among the lines above.` : ` ! The start of ${which} may not have been read: --since limits the read to a recent window. Drop it to read each pod from its start.`));
|
|
5048
|
-
console.log("");
|
|
5049
|
-
}
|
|
5050
|
-
}, {
|
|
5051
|
-
sinceSeconds,
|
|
5052
|
-
tail: {
|
|
5053
|
-
requested: tail.requested,
|
|
5054
|
-
applied: tail.applied,
|
|
5055
|
-
serverMax: SERVER_MAX_TAIL_LINES,
|
|
5056
|
-
note: tail.note
|
|
5057
|
-
},
|
|
5058
|
-
window: {
|
|
5059
|
-
requestedFrom: coverage.requestedFrom,
|
|
5060
|
-
firstTimestamp: coverage.firstTimestamp,
|
|
5061
|
-
lastTimestamp: coverage.lastTimestamp
|
|
5062
|
-
},
|
|
5063
|
-
state: res.state ?? null,
|
|
5064
|
-
pods: coverage.pods,
|
|
5065
|
-
truncated: coverage.truncated,
|
|
5066
|
-
truncatedReasons: coverage.truncatedReasons,
|
|
5067
|
-
...reach ? {
|
|
5068
|
-
reachedStart: reach.reachedStart,
|
|
5069
|
-
unreachedPods: reach.unreached
|
|
5070
|
-
} : {},
|
|
5071
|
-
matched: kept.length,
|
|
5072
|
-
lines: shown
|
|
5073
|
-
});
|
|
4807
|
+
function previewKeyPath(projectId, name, action) {
|
|
4808
|
+
return `${encodeURIComponent(projectId)}/${encodeURIComponent(name)}/service-key/${action}`;
|
|
5074
4809
|
}
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
spec: REQUESTS_FLAGS,
|
|
5078
|
-
rawArgs,
|
|
5079
|
-
commandWords: 3,
|
|
5080
|
-
command: "cloud debug",
|
|
5081
|
-
maxPositionals: 0
|
|
5082
|
-
});
|
|
5083
|
-
const sinceSeconds = sinceFromFlag(parsed["--since"]) ?? REQUESTS_DEFAULTS.sinceSeconds;
|
|
5084
|
-
const tail = tailFromFlag(parsed["--tail"], REQUESTS_DEFAULTS.tail);
|
|
5085
|
-
const { client } = await requireClient(rawArgs);
|
|
5086
|
-
const projectId = await requireProject(rawArgs, client);
|
|
4810
|
+
/** Read a backend preview's own key. `env reveal REBASE_SERVICE_KEY --preview <name>` lands here too. */
|
|
4811
|
+
async function revealPreviewServiceKey(client, projectId, name) {
|
|
5087
4812
|
let res;
|
|
5088
4813
|
try {
|
|
5089
|
-
res = await
|
|
5090
|
-
sinceSeconds,
|
|
5091
|
-
tailLines: tail.applied
|
|
5092
|
-
});
|
|
4814
|
+
res = await client.functions.invoke("previews", {}, { path: previewKeyPath(projectId, name, "reveal") });
|
|
5093
4815
|
} catch (e) {
|
|
5094
|
-
|
|
4816
|
+
reportCallError(e, "Failed to read the preview's service key", PREVIEW_SERVICE_KEY_UNSERVED);
|
|
5095
4817
|
}
|
|
5096
|
-
const parsedLines = (res.logs ?? "").split("\n").filter((l) => l !== "").map(parseLogLine);
|
|
5097
|
-
const shown = parsedLines.map((l) => parseRequestLine(l.text)).filter((e) => e !== null).slice(-40);
|
|
5098
|
-
const coverage = assessCoverage({
|
|
5099
|
-
res,
|
|
5100
|
-
lines: parsedLines,
|
|
5101
|
-
sinceSeconds,
|
|
5102
|
-
tail,
|
|
5103
|
-
now: Date.now()
|
|
5104
|
-
});
|
|
5105
4818
|
emit(() => {
|
|
5106
4819
|
console.log("");
|
|
5107
|
-
console.log(
|
|
4820
|
+
console.log(` ${chalk.bold(res.key)}=${res.value}`);
|
|
5108
4821
|
console.log("");
|
|
5109
|
-
|
|
5110
|
-
if (shown.length === 0) {
|
|
5111
|
-
console.log(chalk.gray(" No structured request lines in what was read."));
|
|
5112
|
-
console.log(chalk.gray(" (this view needs the server's request logging; try `debug logs`)"));
|
|
5113
|
-
console.log("");
|
|
5114
|
-
printCoverage(coverage, tail);
|
|
5115
|
-
return;
|
|
5116
|
-
}
|
|
5117
|
-
for (const e of shown) {
|
|
5118
|
-
const status = e.status ?? 0;
|
|
5119
|
-
const color = status >= 500 ? chalk.red : status >= 400 ? chalk.yellow : chalk.green;
|
|
5120
|
-
console.log(` ${color(String(e.status ?? "---").padStart(3))} ${e.method.padEnd(6)} ${e.path.slice(0, 70).padEnd(70)} ${chalk.gray(e.latencyMs === null ? "" : `${e.latencyMs}ms`)}`);
|
|
5121
|
-
}
|
|
4822
|
+
console.log(chalk.gray(` Preview ${chalk.bold(res.preview)} (${res.url}) only. Production's key is \`rebase cloud env reveal REBASE_SERVICE_KEY\`.`));
|
|
5122
4823
|
console.log("");
|
|
5123
|
-
|
|
5124
|
-
}, {
|
|
5125
|
-
sinceSeconds,
|
|
5126
|
-
tail: {
|
|
5127
|
-
requested: tail.requested,
|
|
5128
|
-
applied: tail.applied,
|
|
5129
|
-
serverMax: SERVER_MAX_TAIL_LINES,
|
|
5130
|
-
note: tail.note
|
|
5131
|
-
},
|
|
5132
|
-
window: {
|
|
5133
|
-
requestedFrom: coverage.requestedFrom,
|
|
5134
|
-
firstTimestamp: coverage.firstTimestamp,
|
|
5135
|
-
lastTimestamp: coverage.lastTimestamp
|
|
5136
|
-
},
|
|
5137
|
-
pods: coverage.pods,
|
|
5138
|
-
truncated: coverage.truncated,
|
|
5139
|
-
truncatedReasons: coverage.truncatedReasons,
|
|
5140
|
-
requests: shown
|
|
5141
|
-
});
|
|
4824
|
+
}, res);
|
|
5142
4825
|
}
|
|
5143
|
-
async function
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
commandWords: 3,
|
|
5148
|
-
command: "cloud debug",
|
|
5149
|
-
maxPositionals: 0
|
|
4826
|
+
async function rotatePreviewServiceKey(client, projectId, label, name, yes) {
|
|
4827
|
+
await confirmDestructive({
|
|
4828
|
+
yes,
|
|
4829
|
+
prompt: `Rotate the service key of ${label}? Its pod restarts onto a new key, and anything using the old one is refused once it has. Production is not touched.`
|
|
5150
4830
|
});
|
|
5151
|
-
|
|
5152
|
-
const projectId = await requireProject(rawArgs, client);
|
|
5153
|
-
let m;
|
|
4831
|
+
let rotation;
|
|
5154
4832
|
try {
|
|
5155
|
-
|
|
5156
|
-
method: "GET",
|
|
5157
|
-
path: projectId
|
|
5158
|
-
});
|
|
4833
|
+
rotation = await client.functions.invoke("previews", {}, { path: previewKeyPath(projectId, name, "rotate") });
|
|
5159
4834
|
} catch (e) {
|
|
5160
|
-
|
|
4835
|
+
reportCallError(e, "Failed to rotate the preview's service key", PREVIEW_SERVICE_KEY_UNSERVED);
|
|
5161
4836
|
}
|
|
5162
|
-
const p = m.placement ?? {};
|
|
5163
|
-
const replicas = p.replicas ?? {};
|
|
5164
4837
|
emit(() => {
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
["Status", m.status ? colorStatus(m.status === "running" ? "active" : m.status) : void 0],
|
|
5170
|
-
["Replicas", replicas.desired === void 0 ? void 0 : `${replicas.available ?? 0} / ${replicas.desired} available`],
|
|
5171
|
-
["Namespace", p.namespace],
|
|
5172
|
-
["Cluster", p.cluster],
|
|
5173
|
-
["Region", [p.provider, p.region].filter(Boolean).join(" · ") || void 0],
|
|
5174
|
-
["Host", p.host],
|
|
5175
|
-
["Image", p.image],
|
|
5176
|
-
["CPU", m.cpu ?? void 0],
|
|
5177
|
-
["Memory", m.memory ?? void 0]
|
|
5178
|
-
]);
|
|
5179
|
-
console.log("");
|
|
5180
|
-
if ((replicas.available ?? 0) === 0 && (replicas.desired ?? 0) > 0) {
|
|
5181
|
-
console.log(chalk.yellow(" No replica is available — the pod is not passing its readiness check."));
|
|
5182
|
-
console.log(chalk.gray(" See why with: ") + chalk.bold("rebase cloud debug logs --previous"));
|
|
5183
|
-
console.log("");
|
|
5184
|
-
}
|
|
5185
|
-
}, {
|
|
5186
|
-
status: m.status ?? null,
|
|
5187
|
-
placement: p
|
|
5188
|
-
});
|
|
4838
|
+
success(`Issued a new service key for ${label}.`);
|
|
4839
|
+
note(rotation.state === "pending" ? "The preview has no pod running: its next deploy starts on the new key." : "Its pod is restarting onto it; the old key works until the new pod is ready.");
|
|
4840
|
+
note(`Read it with \`rebase cloud service-key --preview ${name}\`.`);
|
|
4841
|
+
}, rotation);
|
|
5189
4842
|
}
|
|
5190
|
-
async function
|
|
5191
|
-
parseCloudArgs({
|
|
5192
|
-
spec:
|
|
4843
|
+
async function serviceKeyCommand(rawArgs) {
|
|
4844
|
+
const parsed = parseCloudArgs({
|
|
4845
|
+
spec: SERVICE_KEY_FLAGS,
|
|
5193
4846
|
rawArgs,
|
|
5194
|
-
commandWords:
|
|
5195
|
-
command: "cloud
|
|
5196
|
-
maxPositionals:
|
|
4847
|
+
commandWords: 2,
|
|
4848
|
+
command: "cloud service-key",
|
|
4849
|
+
maxPositionals: 2
|
|
5197
4850
|
});
|
|
5198
|
-
const
|
|
5199
|
-
const
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
});
|
|
5206
|
-
|
|
5207
|
-
|
|
4851
|
+
const preview = parsed.flags["--preview"] === true;
|
|
4852
|
+
const words = preview && parsed.positionals.length === 2 && parsed.positionals[1] === "rotate" ? [parsed.positionals[1], parsed.positionals[0]] : parsed.positionals;
|
|
4853
|
+
const action = preview ? words.length === 2 || words[0] === "rotate" ? words[0] : void 0 : words[0];
|
|
4854
|
+
if (!preview && words.length > 1) fail(`\`rebase cloud service-key ${words.join(" ")}\`: one action at most.`, "A preview is named after --preview.", "usage");
|
|
4855
|
+
requireKnownAction("service-key", action, SERVICE_KEY_ACTIONS);
|
|
4856
|
+
if (preview) {
|
|
4857
|
+
const name = previewNameArg(words.length === 2 ? words[1] : action === void 0 ? words[0] : void 0, `rebase cloud service-key ${action ? `${action} ` : ""}--preview <name>`);
|
|
4858
|
+
const { client } = await requireClient(rawArgs);
|
|
4859
|
+
const projectId = await requireProject(rawArgs, client);
|
|
4860
|
+
if (action === "rotate") return rotatePreviewServiceKey(client, projectId, `preview "${name}" of project ${displayProjectRef(rawArgs) || projectId}`, name, Boolean(parsed.flags["--yes"]));
|
|
4861
|
+
return revealPreviewServiceKey(client, projectId, name);
|
|
5208
4862
|
}
|
|
5209
|
-
const
|
|
5210
|
-
const
|
|
5211
|
-
const
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
console.log(chalk.yellow(` ${info.unavailableReason}`));
|
|
5219
|
-
console.log("");
|
|
5220
|
-
return;
|
|
5221
|
-
}
|
|
5222
|
-
keyValues([
|
|
5223
|
-
["Type", info.type],
|
|
5224
|
-
["Host", info.host],
|
|
5225
|
-
["Port", info.port],
|
|
5226
|
-
["Database", info.database],
|
|
5227
|
-
["Username", info.username],
|
|
5228
|
-
["Password", info.passwordAvailable ? chalk.gray("stored — not shown here") : chalk.yellow("none stored")]
|
|
5229
|
-
]);
|
|
5230
|
-
console.log("");
|
|
5231
|
-
if (connectCmd) {
|
|
5232
|
-
console.log(chalk.gray(" That host is inside the platform's cluster and does not resolve here."));
|
|
5233
|
-
console.log(chalk.gray(" To reach the database from this machine:"));
|
|
5234
|
-
console.log("");
|
|
5235
|
-
console.log(` ${connectCmd}`);
|
|
5236
|
-
if (psqlCmd) console.log(` ${psqlCmd}`);
|
|
5237
|
-
console.log("");
|
|
5238
|
-
if (kubectlCmd) {
|
|
5239
|
-
console.log(chalk.gray(" Or, on your own cluster:"));
|
|
5240
|
-
console.log(` ${kubectlCmd}`);
|
|
5241
|
-
console.log("");
|
|
5242
|
-
}
|
|
5243
|
-
if (info.passwordAvailable) {
|
|
5244
|
-
console.log(chalk.gray(" Get the password with: ") + chalk.bold("rebase cloud db info --reveal"));
|
|
5245
|
-
console.log("");
|
|
5246
|
-
}
|
|
4863
|
+
const { client } = await requireSessionClient(rawArgs, "rotate a project's service key");
|
|
4864
|
+
const projectId = await requireProject(rawArgs, client);
|
|
4865
|
+
const label = `project ${displayProjectRef(rawArgs) || projectId}`;
|
|
4866
|
+
if (action !== "rotate") {
|
|
4867
|
+
let status;
|
|
4868
|
+
try {
|
|
4869
|
+
status = await readStatus(client, projectId);
|
|
4870
|
+
} catch (e) {
|
|
4871
|
+
reportCallError(e, "Failed to read the service key's state", SERVICE_KEY_UNSERVED);
|
|
5247
4872
|
}
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
host: info.host ?? null,
|
|
5251
|
-
port: info.port ?? null,
|
|
5252
|
-
database: info.database ?? null,
|
|
5253
|
-
username: info.username ?? null,
|
|
5254
|
-
passwordAvailable: Boolean(info.passwordAvailable),
|
|
5255
|
-
connectCommand: connectCmd,
|
|
5256
|
-
kubectlCommand: kubectlCmd,
|
|
5257
|
-
psqlCommand: psqlCmd
|
|
5258
|
-
});
|
|
5259
|
-
}
|
|
5260
|
-
/**
|
|
5261
|
-
* Everything the switch below dispatches, for the did-you-mean. `workload` is
|
|
5262
|
-
* the older spelling of `pod` and stays out of it: suggesting the name we no
|
|
5263
|
-
* longer print in the help would teach the wrong one.
|
|
5264
|
-
*/
|
|
5265
|
-
var DEBUG_SUBCOMMANDS = [
|
|
5266
|
-
"health",
|
|
5267
|
-
"logs",
|
|
5268
|
-
"errors",
|
|
5269
|
-
"boot",
|
|
5270
|
-
"requests",
|
|
5271
|
-
"pod",
|
|
5272
|
-
"db"
|
|
5273
|
-
];
|
|
5274
|
-
async function debugCommand(action, rawArgs) {
|
|
5275
|
-
switch (action) {
|
|
5276
|
-
case void 0:
|
|
5277
|
-
case "health":
|
|
5278
|
-
await healthCommand(rawArgs);
|
|
5279
|
-
break;
|
|
5280
|
-
case "logs":
|
|
5281
|
-
case "errors":
|
|
5282
|
-
case "boot":
|
|
5283
|
-
await logView(rawArgs, LOG_VIEWS[action]);
|
|
5284
|
-
break;
|
|
5285
|
-
case "requests":
|
|
5286
|
-
await requestsCommand(rawArgs);
|
|
5287
|
-
break;
|
|
5288
|
-
case "pod":
|
|
5289
|
-
case "workload":
|
|
5290
|
-
await podCommand(rawArgs);
|
|
5291
|
-
break;
|
|
5292
|
-
case "db":
|
|
5293
|
-
await dbDebugCommand(rawArgs);
|
|
5294
|
-
break;
|
|
5295
|
-
case "help":
|
|
5296
|
-
case "--help":
|
|
5297
|
-
printDebugHelp();
|
|
5298
|
-
break;
|
|
5299
|
-
default: fail(unknownCommandMessage(action, DEBUG_SUBCOMMANDS, "cloud debug"), void 0, "unknown_command");
|
|
4873
|
+
emit(() => printStatus(status, label), status);
|
|
4874
|
+
return;
|
|
5300
4875
|
}
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
* They were one group-wide list saying "Default: 500", which was true of two of
|
|
5305
|
-
* the four actions, and offered `--previous` to `requests`, which rejects it.
|
|
5306
|
-
*/
|
|
5307
|
-
function logFlagHelp(defaults, previous) {
|
|
5308
|
-
const flags = [["--since <dur>", defaults.sinceSeconds === null ? "Only lines this recent: 90s, 15m, 2h, 1d. Default: from each pod's start" : `Lookback window: 90s, 15m, 2h, 1d. Default: ${formatDuration$2(defaults.sinceSeconds)}`], ["--tail <n>", `Newest lines to read per pod, at most ${SERVER_MAX_TAIL_LINES}. Default: ${defaults.tail}`]];
|
|
5309
|
-
if (previous) flags.push(["--previous", "Read the CRASHED container instance, where the reason lives"]);
|
|
5310
|
-
return flags;
|
|
5311
|
-
}
|
|
5312
|
-
function logViewFlagHelp(view) {
|
|
5313
|
-
return logFlagHelp({
|
|
5314
|
-
sinceSeconds: view.defaultSinceSeconds,
|
|
5315
|
-
tail: view.defaultTail
|
|
5316
|
-
}, true);
|
|
5317
|
-
}
|
|
5318
|
-
function printDebugHelp() {
|
|
5319
|
-
printGroupHelp({
|
|
5320
|
-
command: "cloud debug",
|
|
5321
|
-
title: "Find out why a deployed project is misbehaving",
|
|
5322
|
-
actions: [
|
|
5323
|
-
{
|
|
5324
|
-
action: "health",
|
|
5325
|
-
section: "End-to-end",
|
|
5326
|
-
description: "Probe the live URL and explain every status code (the default)",
|
|
5327
|
-
flags: [
|
|
5328
|
-
["--host <hostname>", "Probe this address instead of the project's own"],
|
|
5329
|
-
["--collection <name>", "Table for the unauth-read probe. Default: users"],
|
|
5330
|
-
["--function <name>", "Also assert this function loaded, against the listing"]
|
|
5331
|
-
]
|
|
5332
|
-
},
|
|
5333
|
-
{
|
|
5334
|
-
action: "logs",
|
|
5335
|
-
section: "Runtime",
|
|
5336
|
-
description: "Recent application logs",
|
|
5337
|
-
flags: logViewFlagHelp(LOG_VIEWS.logs)
|
|
5338
|
-
},
|
|
5339
|
-
{
|
|
5340
|
-
action: "errors",
|
|
5341
|
-
section: "Runtime",
|
|
5342
|
-
description: "Error and warning lines only",
|
|
5343
|
-
flags: logViewFlagHelp(LOG_VIEWS.errors)
|
|
5344
|
-
},
|
|
5345
|
-
{
|
|
5346
|
-
action: "requests",
|
|
5347
|
-
section: "Runtime",
|
|
5348
|
-
description: "HTTP requests the server logged: status, path, latency",
|
|
5349
|
-
flags: logFlagHelp(REQUESTS_DEFAULTS, false)
|
|
5350
|
-
},
|
|
5351
|
-
{
|
|
5352
|
-
action: "boot",
|
|
5353
|
-
section: "Runtime",
|
|
5354
|
-
description: "What the server decided at startup: storage, functions, auth",
|
|
5355
|
-
flags: logViewFlagHelp(LOG_VIEWS.boot)
|
|
5356
|
-
},
|
|
5357
|
-
{
|
|
5358
|
-
action: "pod",
|
|
5359
|
-
section: "Runtime",
|
|
5360
|
-
description: "Replicas, image, namespace, cluster placement"
|
|
5361
|
-
},
|
|
5362
|
-
{
|
|
5363
|
-
action: "db",
|
|
5364
|
-
section: "Data",
|
|
5365
|
-
description: "Connection shape and the port-forward recipe. Never the password"
|
|
5366
|
-
}
|
|
5367
|
-
],
|
|
5368
|
-
notes: [
|
|
5369
|
-
"Everything here is read-only. `health` exits non-zero when a check fails, so it works in a",
|
|
5370
|
-
"deploy script. To restart a workload, use `rebase cloud restart`.",
|
|
5371
|
-
"The log views end with the window asked for, the window returned, and anything that cut",
|
|
5372
|
-
`between them. The control plane returns at most ${SERVER_MAX_TAIL_LINES} lines per pod.`
|
|
5373
|
-
]
|
|
4876
|
+
await confirmDestructive({
|
|
4877
|
+
yes: Boolean(parsed.flags["--yes"]),
|
|
4878
|
+
prompt: `Rotate the service key of ${label}? The app restarts onto a new key, and anything using the old one is refused once it has.`
|
|
5374
4879
|
});
|
|
5375
|
-
|
|
5376
|
-
//#endregion
|
|
5377
|
-
//#region src/commands/cloud/cron.ts
|
|
5378
|
-
/**
|
|
5379
|
-
* `rebase cloud cron` — a deployed project's scheduled jobs and their run
|
|
5380
|
-
* history, read with the `rebase cloud` login.
|
|
5381
|
-
*
|
|
5382
|
-
* ## Why this is not just `curl /api/admin/cron`
|
|
5383
|
-
*
|
|
5384
|
-
* The run history lives in the app itself — `rebase.cron_logs`, served by the
|
|
5385
|
-
* runtime's `/api/admin/cron/:id/logs` — behind the app's admin gate. A project
|
|
5386
|
-
* owner is signed in to the *control plane*, which that gate has never heard
|
|
5387
|
-
* of, and holds none of what it accepts: often no admin account in the app yet,
|
|
5388
|
-
* no `rk_` key, and rightly not the service key, which is admin on the whole API.
|
|
5389
|
-
* Pod stdout (`rebase cloud debug logs`) covers the last half hour or so; the
|
|
5390
|
-
* history covers every run.
|
|
5391
|
-
*
|
|
5392
|
-
* ## How it reaches the runtime
|
|
5393
|
-
*
|
|
5394
|
-
* Two legs, each over a channel `rebase cloud debug` already uses:
|
|
5395
|
-
*
|
|
5396
|
-
* 1. The control plane, as the signed-in person (`debug logs`' channel):
|
|
5397
|
-
* `POST /api/functions/runtime-token/<project>` checks the caller may read
|
|
5398
|
-
* this project's logs and answers a token — `rpt_…`, ES256, bound to this
|
|
5399
|
-
* project, `cron:read` only, minutes long.
|
|
5400
|
-
* 2. The runtime at its public address (`debug health`'s channel), with that
|
|
5401
|
-
* token as the bearer. The runtime verifies it against the platform's
|
|
5402
|
-
* public key and grants `cron:read` and nothing else — it cannot trigger,
|
|
5403
|
-
* disable, or read anything but cron.
|
|
5404
|
-
*
|
|
5405
|
-
* A fresh token per command: nothing is cached, so nothing long-lived ends up
|
|
5406
|
-
* on this machine.
|
|
5407
|
-
*/
|
|
5408
|
-
/** The control-plane function that mints runtime tokens. */
|
|
5409
|
-
var RUNTIME_TOKEN_FUNCTION = "runtime-token";
|
|
5410
|
-
/** The one scope these commands ask the platform for. */
|
|
5411
|
-
var CRON_READ_SCOPE = "cron:read";
|
|
5412
|
-
/** Where the runtime serves its cron surface. */
|
|
5413
|
-
var CRON_PATH = "/api/admin/cron";
|
|
5414
|
-
var RUNTIME_TIMEOUT_MS = 15e3;
|
|
5415
|
-
/**
|
|
5416
|
-
* A 404 that is about the route, not the project: the JSON envelope a Rebase
|
|
5417
|
-
* backend answers for an unmatched path, or the bare one a router answers
|
|
5418
|
-
* before that handler exists.
|
|
5419
|
-
*/
|
|
5420
|
-
function isMissingRoute(message) {
|
|
5421
|
-
return /^No route for |^(404 )?Not Found$/i.test((message ?? "").trim());
|
|
5422
|
-
}
|
|
5423
|
-
/**
|
|
5424
|
-
* Ask the control plane for a token the project's runtime will accept.
|
|
5425
|
-
*
|
|
5426
|
-
* A missing route means this control plane has no `runtime-token` function
|
|
5427
|
-
* yet, which is a different fix from "no such project" and is said so.
|
|
5428
|
-
*/
|
|
5429
|
-
async function mintRuntimeToken(client, projectId, scopes) {
|
|
5430
|
-
let res;
|
|
5431
|
-
try {
|
|
5432
|
-
res = await client.functions.invoke(RUNTIME_TOKEN_FUNCTION, { scopes }, {
|
|
5433
|
-
method: "POST",
|
|
5434
|
-
path: projectId
|
|
5435
|
-
});
|
|
5436
|
-
} catch (e) {
|
|
5437
|
-
const err = e;
|
|
5438
|
-
if (err.status === 404 && isMissingRoute(err.message)) fail("This control plane does not issue runtime tokens yet, so the CLI cannot read the app's cron history.", "Until it does, `rebase cloud debug logs` shows what jobs printed in the last half hour.", "runtime_token_unavailable");
|
|
5439
|
-
reportError(e, "Failed to get a runtime token from the control plane");
|
|
5440
|
-
}
|
|
5441
|
-
if (typeof res?.token !== "string" || res.token.length === 0) fail("The control plane answered without a runtime token.", void 0, "runtime_token_unavailable");
|
|
5442
|
-
return res;
|
|
5443
|
-
}
|
|
5444
|
-
/**
|
|
5445
|
-
* GET a path on the runtime with a platform token, and refuse — with what it
|
|
5446
|
-
* means for this command — anything but a 2xx.
|
|
5447
|
-
*
|
|
5448
|
-
* `notFound` words the 404, which means different things per route: no cron
|
|
5449
|
-
* surface at all on the list, no such job on its logs.
|
|
5450
|
-
*/
|
|
5451
|
-
async function runtimeGet(origin, path, token, notFound) {
|
|
5452
|
-
let res;
|
|
4880
|
+
let rotation;
|
|
5453
4881
|
try {
|
|
5454
|
-
|
|
5455
|
-
headers: {
|
|
5456
|
-
Authorization: `Bearer ${token}`,
|
|
5457
|
-
Accept: "application/json"
|
|
5458
|
-
},
|
|
5459
|
-
redirect: "manual",
|
|
5460
|
-
signal: AbortSignal.timeout(RUNTIME_TIMEOUT_MS)
|
|
5461
|
-
});
|
|
4882
|
+
rotation = await client.functions.invoke("credentials", {}, { path: `${encodeURIComponent(projectId)}/service-key/rotate` });
|
|
5462
4883
|
} catch (e) {
|
|
5463
|
-
|
|
5464
|
-
}
|
|
5465
|
-
const text = await res.text();
|
|
5466
|
-
let body;
|
|
5467
|
-
try {
|
|
5468
|
-
body = text ? JSON.parse(text) : void 0;
|
|
5469
|
-
} catch {
|
|
5470
|
-
body = void 0;
|
|
4884
|
+
reportCallError(e, "Failed to rotate the service key", SERVICE_KEY_UNSERVED);
|
|
5471
4885
|
}
|
|
5472
|
-
if (res.ok) return body;
|
|
5473
|
-
const error = body?.error;
|
|
5474
|
-
const said = error?.message ? ` (${error.message})` : "";
|
|
5475
|
-
if (res.status === 401) {
|
|
5476
|
-
if (error?.code === "PLATFORM_TOKENS_OFF" || error?.code === "INVALID_PLATFORM_TOKEN") fail(`The app refused the platform's token${said}.`, "The platform sets the key it verifies with when it deploys; redeploying the project picks it up.", "runtime_token_refused");
|
|
5477
|
-
fail(`This deployment's runtime does not accept platform tokens${said}.`, "Runtimes from before platform tokens accept only an admin of the app, an `rk_` key or the service key. Redeploy to move to a runtime that accepts them.", "runtime_token_refused");
|
|
5478
|
-
}
|
|
5479
|
-
if (res.status === 404) fail(notFound.message, notFound.hint, notFound.code);
|
|
5480
|
-
if (res.status === 501 && error?.code === "ADMIN_SURFACE_UNAVAILABLE") fail(`The app has its admin surfaces switched off${said}.`, void 0, "admin_surface_unavailable");
|
|
5481
|
-
fail(`The app answered ${res.status} for ${path}${said}.`, res.status >= 500 ? "`rebase cloud debug errors` shows what the server logged." : void 0, res.status === 400 ? "usage" : "runtime_error");
|
|
5482
|
-
}
|
|
5483
|
-
/** Everything both actions need before their one request. */
|
|
5484
|
-
async function connect(rawArgs) {
|
|
5485
|
-
const { client, url } = await requireClient(rawArgs);
|
|
5486
|
-
const projectId = await requireProject(rawArgs, client);
|
|
5487
|
-
const origin = await resolveOrigin(rawArgs, client, url, projectId);
|
|
5488
|
-
const { token } = await mintRuntimeToken(client, projectId, [CRON_READ_SCOPE]);
|
|
5489
|
-
return {
|
|
5490
|
-
origin,
|
|
5491
|
-
token
|
|
5492
|
-
};
|
|
5493
|
-
}
|
|
5494
|
-
var NO_CRON_SURFACE = {
|
|
5495
|
-
message: "This deployment serves no cron surface.",
|
|
5496
|
-
hint: "The app was built without a crons directory, or its runtime does not serve the cron admin routes.",
|
|
5497
|
-
code: "cron_not_served"
|
|
5498
|
-
};
|
|
5499
|
-
/** `2026-10-05T10:31:00.000Z` → `2026-10-05 10:31:00Z`, or `—`. */
|
|
5500
|
-
function shortTime(iso) {
|
|
5501
|
-
if (!iso) return "—";
|
|
5502
|
-
const date = new Date(iso);
|
|
5503
|
-
return Number.isNaN(date.getTime()) ? iso : `${date.toISOString().slice(0, 19).replace("T", " ")}Z`;
|
|
5504
|
-
}
|
|
5505
|
-
/** Milliseconds as `850ms`, `2.4s` or `3m 10s`. */
|
|
5506
|
-
function shortDuration(ms) {
|
|
5507
|
-
if (ms === void 0 || !Number.isFinite(ms)) return "";
|
|
5508
|
-
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
5509
|
-
if (ms < 6e4) return `${(ms / 1e3).toFixed(1)}s`;
|
|
5510
|
-
return `${Math.floor(ms / 6e4)}m ${Math.round(ms % 6e4 / 1e3)}s`;
|
|
5511
|
-
}
|
|
5512
|
-
function stateColor(state) {
|
|
5513
|
-
if (state === "error") return chalk.red(state);
|
|
5514
|
-
if (state === "running") return chalk.cyan(state);
|
|
5515
|
-
if (state === "disabled") return chalk.gray(state);
|
|
5516
|
-
if (state === "success") return chalk.green(state);
|
|
5517
|
-
return state;
|
|
5518
|
-
}
|
|
5519
|
-
/** The flags `cron list` parses — the help page lists exactly these. */
|
|
5520
|
-
var CRON_LIST_FLAGS = { "--host": String };
|
|
5521
|
-
async function listCommand$2(rawArgs) {
|
|
5522
|
-
parseCloudArgs({
|
|
5523
|
-
spec: CRON_LIST_FLAGS,
|
|
5524
|
-
rawArgs,
|
|
5525
|
-
commandWords: 3,
|
|
5526
|
-
command: "cloud cron list",
|
|
5527
|
-
maxPositionals: 0
|
|
5528
|
-
});
|
|
5529
|
-
const { origin, token } = await connect(rawArgs);
|
|
5530
|
-
const res = await runtimeGet(origin, CRON_PATH, token, NO_CRON_SURFACE);
|
|
5531
|
-
const jobs = res?.jobs ?? [];
|
|
5532
|
-
emit(() => {
|
|
5533
|
-
console.log("");
|
|
5534
|
-
console.log(chalk.bold(` ⏰ Cron — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${origin}`));
|
|
5535
|
-
console.log("");
|
|
5536
|
-
if (jobs.length === 0) console.log(chalk.gray(" No cron jobs are scheduled on this deployment."));
|
|
5537
|
-
else {
|
|
5538
|
-
const lastRun = (job) => ({
|
|
5539
|
-
at: shortTime(job.lastRunAt),
|
|
5540
|
-
took: job.lastRunAt ? shortDuration(job.lastDurationMs) : ""
|
|
5541
|
-
});
|
|
5542
|
-
const lastText = (job) => [lastRun(job).at, lastRun(job).took].filter(Boolean).join(" ");
|
|
5543
|
-
const idWidth = Math.max(3, ...jobs.map((job) => job.id.length));
|
|
5544
|
-
const scheduleWidth = Math.max(8, ...jobs.map((job) => job.schedule.length));
|
|
5545
|
-
const stateWidth = Math.max(5, ...jobs.map((job) => job.state.length));
|
|
5546
|
-
const lastWidth = Math.max(8, ...jobs.map((job) => lastText(job).length));
|
|
5547
|
-
console.log(chalk.gray(` ${"JOB".padEnd(idWidth)} ${"SCHEDULE".padEnd(scheduleWidth)} ${"STATE".padEnd(stateWidth)} ${"LAST RUN".padEnd(lastWidth)} NEXT RUN`));
|
|
5548
|
-
for (const job of jobs) {
|
|
5549
|
-
const { at, took } = lastRun(job);
|
|
5550
|
-
const pad = (text, width) => " ".repeat(Math.max(0, width - text.length));
|
|
5551
|
-
console.log(` ${chalk.bold(job.id)}${pad(job.id, idWidth)} ${job.schedule.padEnd(scheduleWidth)} ${stateColor(job.state)}${pad(job.state, stateWidth)} ${at}${took ? ` ${chalk.gray(took)}` : ""}${pad(lastText(job), lastWidth)} ${shortTime(job.nextRunAt)}`);
|
|
5552
|
-
if (job.state === "error" && job.lastError) console.log(chalk.red(` ${" ".repeat(idWidth)} ${job.lastError}`));
|
|
5553
|
-
}
|
|
5554
|
-
}
|
|
5555
|
-
if (res?.note) {
|
|
5556
|
-
console.log("");
|
|
5557
|
-
console.log(chalk.yellow(` ⚠ ${res.note}`));
|
|
5558
|
-
for (const rejected of res.rejected ?? []) console.log(chalk.yellow(` ${rejected.id} (${rejected.schedule}): ${rejected.reason}`));
|
|
5559
|
-
}
|
|
5560
|
-
console.log("");
|
|
5561
|
-
if (jobs.length > 0) {
|
|
5562
|
-
console.log(chalk.gray(" A job's run history: ") + chalk.bold("rebase cloud cron logs <job>"));
|
|
5563
|
-
console.log("");
|
|
5564
|
-
}
|
|
5565
|
-
}, {
|
|
5566
|
-
origin,
|
|
5567
|
-
jobs,
|
|
5568
|
-
skipped: res?.skipped ?? 0,
|
|
5569
|
-
rejected: res?.rejected ?? [],
|
|
5570
|
-
note: res?.note ?? null
|
|
5571
|
-
});
|
|
5572
|
-
}
|
|
5573
|
-
/** The flags `cron logs` parses — the help page lists exactly these. */
|
|
5574
|
-
var CRON_LOGS_FLAGS = {
|
|
5575
|
-
"--limit": Number,
|
|
5576
|
-
"--host": String
|
|
5577
|
-
};
|
|
5578
|
-
async function logsCommand$1(rawArgs) {
|
|
5579
|
-
const { flags, positionals } = parseCloudArgs({
|
|
5580
|
-
spec: CRON_LOGS_FLAGS,
|
|
5581
|
-
rawArgs,
|
|
5582
|
-
commandWords: 3,
|
|
5583
|
-
command: "cloud cron logs",
|
|
5584
|
-
maxPositionals: 1
|
|
5585
|
-
});
|
|
5586
|
-
const jobId = positionals[0];
|
|
5587
|
-
if (!jobId) fail("Name the job: `rebase cloud cron logs <job>`.", "`rebase cloud cron list` names them.", "usage");
|
|
5588
|
-
const limit = flags["--limit"];
|
|
5589
|
-
if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1)) fail(`--limit must be a positive whole number; received ${String(limit)}.`, void 0, "usage");
|
|
5590
|
-
const { origin, token } = await connect(rawArgs);
|
|
5591
|
-
const query = limit !== void 0 ? `?limit=${limit}` : "";
|
|
5592
|
-
const logs = (await runtimeGet(origin, `${CRON_PATH}/${encodeURIComponent(jobId)}/logs${query}`, token, {
|
|
5593
|
-
message: `No cron job named "${jobId}" on this deployment (or no cron surface at all).`,
|
|
5594
|
-
hint: "`rebase cloud cron list` names the jobs it runs.",
|
|
5595
|
-
code: "not_found"
|
|
5596
|
-
}))?.logs ?? [];
|
|
5597
4886
|
emit(() => {
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
console.log(chalk.gray(" This job has no recorded runs."));
|
|
5603
|
-
console.log("");
|
|
5604
|
-
return;
|
|
5605
|
-
}
|
|
5606
|
-
for (const run of logs) {
|
|
5607
|
-
const mark = run.success ? chalk.green("✓") : chalk.red("✗");
|
|
5608
|
-
const tags = [shortDuration(run.durationMs), run.manual ? "manual" : void 0].filter(Boolean).join(" ");
|
|
5609
|
-
console.log(` ${mark} ${shortTime(run.startedAt)} ${chalk.gray(tags)}`);
|
|
5610
|
-
if (run.error) console.log(chalk.red(` ${run.error}`));
|
|
5611
|
-
for (const line of run.logs ?? []) console.log(` ${line}`);
|
|
5612
|
-
}
|
|
5613
|
-
console.log("");
|
|
5614
|
-
}, {
|
|
5615
|
-
origin,
|
|
5616
|
-
job: jobId,
|
|
5617
|
-
logs
|
|
5618
|
-
});
|
|
5619
|
-
}
|
|
5620
|
-
var CRON_ACTIONS = ["list", "logs"];
|
|
5621
|
-
async function cronCommand(action, rawArgs) {
|
|
5622
|
-
requireKnownAction("cron", action, CRON_ACTIONS);
|
|
5623
|
-
if (action === "logs") {
|
|
5624
|
-
await logsCommand$1(rawArgs);
|
|
5625
|
-
return;
|
|
5626
|
-
}
|
|
5627
|
-
await listCommand$2(rawArgs);
|
|
4887
|
+
success(`Issued service key generation ${rotation.generation} for ${label}.`);
|
|
4888
|
+
note(rotation.state === "pending" ? "A deploy is running: the next deploy carries the new key. The old one works until then." : "The app is restarting onto it; the old key works until the restart has finished. Follow it with `rebase cloud service-key`.");
|
|
4889
|
+
note("Read the new key with `rebase cloud env reveal REBASE_SERVICE_KEY` once the restart is done.");
|
|
4890
|
+
}, rotation);
|
|
5628
4891
|
}
|
|
5629
4892
|
//#endregion
|
|
5630
4893
|
//#region src/commands/cloud/env.ts
|
|
@@ -5642,7 +4905,8 @@ async function cronCommand(action, rawArgs) {
|
|
|
5642
4905
|
* --preview` hands a variable back to production's value. A backend preview
|
|
5643
4906
|
* starts from a copy of production's environment, live third-party keys
|
|
5644
4907
|
* included; this is how a preview gets a test key instead, or none. Production
|
|
5645
|
-
* is never changed by any of them.
|
|
4908
|
+
* is never changed by any of them. `reveal REBASE_SERVICE_KEY --preview <name>`
|
|
4909
|
+
* prints one backend preview's own service key (`service-key --preview`).
|
|
5646
4910
|
*
|
|
5647
4911
|
* Values are the sharp edge here. The list endpoint returns keys and never
|
|
5648
4912
|
* values by design (a page load is not consent to spray a customer's secrets
|
|
@@ -5945,36 +5209,34 @@ async function setEnv(rawArgs) {
|
|
|
5945
5209
|
}
|
|
5946
5210
|
}
|
|
5947
5211
|
/**
|
|
5948
|
-
*
|
|
5949
|
-
*
|
|
5950
|
-
* `unset` is a delete, and the operand filter aimed it at the wrong variable:
|
|
5951
|
-
* `rebase cloud env unset -p acme` removed a variable called "acme" from the
|
|
5952
|
-
* linked project instead of reporting a missing KEY, and `env unset -p acme
|
|
5953
|
-
* KEY` removed "acme" instead of KEY. Both read `--project`'s value as the
|
|
5954
|
-
* operand — a plain word in the right position that no flag filter can catch.
|
|
5212
|
+
* {@link resolveEnvKeyArg}, and whether `--preview` was given (`unset` and
|
|
5213
|
+
* `reset` take it).
|
|
5955
5214
|
*
|
|
5956
|
-
* `
|
|
5957
|
-
*
|
|
5215
|
+
* `reveal` takes it too, with the preview's name after it, and only for
|
|
5216
|
+
* `REBASE_SERVICE_KEY` — the one value a backend preview holds that is neither
|
|
5217
|
+
* production's nor an override `env list --preview` already shows. The name
|
|
5218
|
+
* is a positional, as in `logs --preview <name>`, so `--preview` stays the
|
|
5219
|
+
* switch it is everywhere else.
|
|
5958
5220
|
*/
|
|
5959
|
-
function resolveEnvKeyArg(rawArgs, action) {
|
|
5960
|
-
return resolveEnvKeyArgs(rawArgs, action).key;
|
|
5961
|
-
}
|
|
5962
|
-
/** {@link resolveEnvKeyArg}, and whether `--preview` was given (`unset` and `reset` take it). */
|
|
5963
5221
|
function resolveEnvKeyArgs(rawArgs, action) {
|
|
5964
5222
|
const { flags, positionals } = parseCloudArgs({
|
|
5965
|
-
spec:
|
|
5223
|
+
spec: ENV_PREVIEW_FLAGS,
|
|
5966
5224
|
rawArgs,
|
|
5967
5225
|
commandWords: 3,
|
|
5968
5226
|
command: `cloud env ${action}`,
|
|
5969
|
-
maxPositionals: 1
|
|
5227
|
+
maxPositionals: action === "reveal" ? 2 : 1
|
|
5970
5228
|
});
|
|
5229
|
+
const preview = flags["--preview"] === true;
|
|
5230
|
+
if (positionals.length > 1 && !preview) fail(`\`rebase cloud env ${action} ${positionals.join(" ")}\`: one KEY at most.`, "A preview is named after --preview.", "usage");
|
|
5971
5231
|
return {
|
|
5972
5232
|
key: positionals[0],
|
|
5973
|
-
preview
|
|
5233
|
+
preview,
|
|
5234
|
+
previewName: positionals[1],
|
|
5235
|
+
yes: flags["--yes"] === true
|
|
5974
5236
|
};
|
|
5975
5237
|
}
|
|
5976
5238
|
async function unsetEnv(rawArgs, action) {
|
|
5977
|
-
const { key, preview } = resolveEnvKeyArgs(rawArgs, action);
|
|
5239
|
+
const { key, preview, yes } = resolveEnvKeyArgs(rawArgs, action);
|
|
5978
5240
|
if (!key) fail("Usage: rebase cloud env unset KEY [--preview]", void 0, "usage");
|
|
5979
5241
|
const { client } = await requireClient(rawArgs);
|
|
5980
5242
|
const projectId = await requireProject(rawArgs, client);
|
|
@@ -6004,6 +5266,10 @@ async function unsetEnv(rawArgs, action) {
|
|
|
6004
5266
|
});
|
|
6005
5267
|
return;
|
|
6006
5268
|
}
|
|
5269
|
+
await confirmDestructive({
|
|
5270
|
+
yes,
|
|
5271
|
+
prompt: `Remove ${key} from project ${displayProjectRef(rawArgs) || projectId}? Its value is deleted, and the next deploy runs without it.`
|
|
5272
|
+
});
|
|
6007
5273
|
try {
|
|
6008
5274
|
emit(() => {
|
|
6009
5275
|
success(`Removed ${chalk.bold(key)}`);
|
|
@@ -6050,8 +5316,14 @@ async function resetPreviewEnv(rawArgs) {
|
|
|
6050
5316
|
});
|
|
6051
5317
|
}
|
|
6052
5318
|
async function revealEnv(rawArgs) {
|
|
6053
|
-
const key =
|
|
6054
|
-
if (!key) fail("Usage: rebase cloud env reveal KEY", void 0, "usage");
|
|
5319
|
+
const { key, preview, previewName } = resolveEnvKeyArgs(rawArgs, "reveal");
|
|
5320
|
+
if (!key) fail("Usage: rebase cloud env reveal KEY [--preview <name>]", void 0, "usage");
|
|
5321
|
+
if (preview) {
|
|
5322
|
+
if (key !== "REBASE_SERVICE_KEY") fail(`Only REBASE_SERVICE_KEY is revealed per preview; ${key} is not one a preview holds of its own.`, "A preview runs with production's variables and the overrides `rebase cloud env list --preview` shows.", "usage");
|
|
5323
|
+
const name = previewNameArg(previewName, "rebase cloud env reveal REBASE_SERVICE_KEY --preview <name>");
|
|
5324
|
+
const { client } = await requireClient(rawArgs);
|
|
5325
|
+
return revealPreviewServiceKey(client, await requireProject(rawArgs, client), name);
|
|
5326
|
+
}
|
|
6055
5327
|
const { client } = await requireClient(rawArgs);
|
|
6056
5328
|
const projectId = await requireProject(rawArgs, client);
|
|
6057
5329
|
const projectRef = displayProjectRef(rawArgs);
|
|
@@ -6197,8 +5469,8 @@ function printEnvHelp() {
|
|
|
6197
5469
|
{
|
|
6198
5470
|
action: "unset",
|
|
6199
5471
|
args: "KEY",
|
|
6200
|
-
description: "Remove a variable",
|
|
6201
|
-
flags: [["--preview", "Only from previews: production keeps it"]]
|
|
5472
|
+
description: "Remove a variable. Asks first; --yes skips the prompt",
|
|
5473
|
+
flags: [["--preview", "Only from previews: production keeps it. Asks nothing: `reset` undoes it"]]
|
|
6202
5474
|
},
|
|
6203
5475
|
{
|
|
6204
5476
|
action: "reset",
|
|
@@ -6209,7 +5481,8 @@ function printEnvHelp() {
|
|
|
6209
5481
|
{
|
|
6210
5482
|
action: "reveal",
|
|
6211
5483
|
args: "KEY",
|
|
6212
|
-
description: "Print one non-secret value"
|
|
5484
|
+
description: "Print one non-secret value",
|
|
5485
|
+
flags: [["--preview <name>", "REBASE_SERVICE_KEY only: that backend preview's own key, as `service-key --preview` prints it"]]
|
|
6213
5486
|
},
|
|
6214
5487
|
{
|
|
6215
5488
|
action: "pull",
|
|
@@ -7983,7 +7256,7 @@ function normalizePreviewName(raw) {
|
|
|
7983
7256
|
function isRecord$1(value) {
|
|
7984
7257
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7985
7258
|
}
|
|
7986
|
-
function text(row, ...keys) {
|
|
7259
|
+
function text$1(row, ...keys) {
|
|
7987
7260
|
for (const key of keys) {
|
|
7988
7261
|
const value = row[key];
|
|
7989
7262
|
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
@@ -7997,21 +7270,21 @@ function text(row, ...keys) {
|
|
|
7997
7270
|
*/
|
|
7998
7271
|
function previewFrom(value) {
|
|
7999
7272
|
if (!isRecord$1(value)) return null;
|
|
8000
|
-
const name = text(value, "name");
|
|
8001
|
-
const url = text(value, "url");
|
|
7273
|
+
const name = text$1(value, "name");
|
|
7274
|
+
const url = text$1(value, "url");
|
|
8002
7275
|
if (!name || !url) return null;
|
|
8003
|
-
const backend = text(value, "backend");
|
|
7276
|
+
const backend = text$1(value, "backend");
|
|
8004
7277
|
return {
|
|
8005
7278
|
name,
|
|
8006
7279
|
url: /^https?:\/\//.test(url) ? url : `https://${url}`,
|
|
8007
|
-
app: text(value, "app"),
|
|
7280
|
+
app: text$1(value, "app"),
|
|
8008
7281
|
backend: backend === "preview" || backend === "production" ? backend : null,
|
|
8009
|
-
status: text(value, "status"),
|
|
8010
|
-
statusMessage: text(value, "statusMessage", "status_message"),
|
|
8011
|
-
deploymentId: text(value, "deploymentId", "deployment_id"),
|
|
8012
|
-
createdAt: text(value, "createdAt", "created_at"),
|
|
8013
|
-
updatedAt: text(value, "updatedAt", "updated_at"),
|
|
8014
|
-
expiresAt: text(value, "expiresAt", "expires_at")
|
|
7282
|
+
status: text$1(value, "status"),
|
|
7283
|
+
statusMessage: text$1(value, "statusMessage", "status_message"),
|
|
7284
|
+
deploymentId: text$1(value, "deploymentId", "deployment_id"),
|
|
7285
|
+
createdAt: text$1(value, "createdAt", "created_at"),
|
|
7286
|
+
updatedAt: text$1(value, "updatedAt", "updated_at"),
|
|
7287
|
+
expiresAt: text$1(value, "expiresAt", "expires_at")
|
|
8015
7288
|
};
|
|
8016
7289
|
}
|
|
8017
7290
|
/**
|
|
@@ -8071,7 +7344,7 @@ async function triggerPreview(client, projectId, body, refusal) {
|
|
|
8071
7344
|
reportError(e, "Preview deploy failed to start");
|
|
8072
7345
|
}
|
|
8073
7346
|
const deployment = isRecord$1(res) && isRecord$1(res.deployment) ? res.deployment : void 0;
|
|
8074
|
-
const deploymentId = deployment ? text(deployment, "id") : null;
|
|
7347
|
+
const deploymentId = deployment ? text$1(deployment, "id") : null;
|
|
8075
7348
|
const preview = isRecord$1(res) ? previewFrom(res.preview) : null;
|
|
8076
7349
|
if (!deploymentId || !preview) fail("The control plane started a preview but did not say where it will be served.", "Run `rebase cloud previews` to find it.", "invalid_response");
|
|
8077
7350
|
return {
|
|
@@ -8475,6 +7748,75 @@ function recordFilter(opts) {
|
|
|
8475
7748
|
return true;
|
|
8476
7749
|
};
|
|
8477
7750
|
}
|
|
7751
|
+
/**
|
|
7752
|
+
* The newest `tail` records of each pod, in their original order. Lines with
|
|
7753
|
+
* no pod prefix count as one pod of their own.
|
|
7754
|
+
*/
|
|
7755
|
+
function tailPerPod(records, tail) {
|
|
7756
|
+
const seen = /* @__PURE__ */ new Map();
|
|
7757
|
+
const keep = new Array(records.length).fill(false);
|
|
7758
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
7759
|
+
const pod = records[i].pod;
|
|
7760
|
+
const n = seen.get(pod) ?? 0;
|
|
7761
|
+
if (n >= tail) continue;
|
|
7762
|
+
seen.set(pod, n + 1);
|
|
7763
|
+
keep[i] = true;
|
|
7764
|
+
}
|
|
7765
|
+
return records.filter((_, i) => keep[i]);
|
|
7766
|
+
}
|
|
7767
|
+
/**
|
|
7768
|
+
* Apply `--grep`/`--level` to everything a page holds, then keep the newest
|
|
7769
|
+
* `tail` matches per pod.
|
|
7770
|
+
*
|
|
7771
|
+
* The control plane cannot filter: it tails each pod's log and answers with
|
|
7772
|
+
* that. So a filtered read asks it for as many lines as it gives
|
|
7773
|
+
* ({@link SERVER_MAX_TAIL_LINES}) and does both steps here. Tailing first and
|
|
7774
|
+
* filtering after — what this used to do — searched only the newest `tail`
|
|
7775
|
+
* lines, so `--since 6h --tail 40 --grep X` found nothing where `--tail 2000`
|
|
7776
|
+
* found X two hours back.
|
|
7777
|
+
*
|
|
7778
|
+
* Whatever the server did not return could not be searched, and that is said
|
|
7779
|
+
* rather than passed off as "no match": a pod that returned the full
|
|
7780
|
+
* `scanLimit` lines has older lines in the window, and a pod (or the page)
|
|
7781
|
+
* the server marked truncated was cut by a byte budget.
|
|
7782
|
+
*/
|
|
7783
|
+
function filterThenTail(page, filter, tail, scanLimit = SERVER_MAX_TAIL_LINES) {
|
|
7784
|
+
const all = parseRecords(page.logs);
|
|
7785
|
+
const matched = all.filter(filter);
|
|
7786
|
+
const records = tailPerPod(matched, tail);
|
|
7787
|
+
const count = (recs, pod) => recs.reduce((n, r) => n + (r.pod === pod ? 1 : 0), 0);
|
|
7788
|
+
const pods = (page.pods ?? []).map((p) => {
|
|
7789
|
+
const scannedLines = typeof p.lines === "number" ? p.lines : count(all, p.pod);
|
|
7790
|
+
const scanCapped = p.state === "ok" && (p.truncated === true || scannedLines >= scanLimit);
|
|
7791
|
+
return {
|
|
7792
|
+
...p,
|
|
7793
|
+
lines: count(records, p.pod),
|
|
7794
|
+
scannedLines,
|
|
7795
|
+
matchedLines: count(matched, p.pod),
|
|
7796
|
+
scanCapped
|
|
7797
|
+
};
|
|
7798
|
+
});
|
|
7799
|
+
const onlyLines = pods.length === 0 && all.length >= scanLimit;
|
|
7800
|
+
const capped = pods.filter((p) => p.scanCapped);
|
|
7801
|
+
const scanCapped = capped.length > 0 || page.truncated === true || onlyLines;
|
|
7802
|
+
let note = null;
|
|
7803
|
+
if (scanCapped) {
|
|
7804
|
+
const reach = capped.map((p) => {
|
|
7805
|
+
const first = all.find((r) => r.pod === p.pod && r.ts !== null)?.ts ?? null;
|
|
7806
|
+
return first ? `${p.pod} from ${first}` : p.pod;
|
|
7807
|
+
}).join(", ");
|
|
7808
|
+
note = `Only the newest lines the control plane returns were searched (at most ${scanLimit} per pod${page.truncated || capped.some((p) => p.truncated) ? ", less where a byte budget cut a pod" : ""})${reach ? `: ${reach}` : ""}. Older lines in the window were not searched, so older matches may exist.`;
|
|
7809
|
+
}
|
|
7810
|
+
return {
|
|
7811
|
+
records,
|
|
7812
|
+
pods,
|
|
7813
|
+
scannedLines: all.length,
|
|
7814
|
+
matchedLines: matched.length,
|
|
7815
|
+
returnedLines: records.length,
|
|
7816
|
+
scanCapped,
|
|
7817
|
+
note
|
|
7818
|
+
};
|
|
7819
|
+
}
|
|
8478
7820
|
function msOf(ts) {
|
|
8479
7821
|
if (ts === null) return null;
|
|
8480
7822
|
const ms = Date.parse(ts);
|
|
@@ -8694,7 +8036,9 @@ async function followRuntimeLogs(deps, opts) {
|
|
|
8694
8036
|
if (!(e instanceof PollTimeout) && !deps.isTransient(e)) throw e;
|
|
8695
8037
|
}
|
|
8696
8038
|
}
|
|
8697
|
-
|
|
8039
|
+
const fresh = cursor.admit(records).filter(opts.filter);
|
|
8040
|
+
const isFirstPage = q === opts.initial;
|
|
8041
|
+
for (const rec of isFirstPage && opts.initialTail !== void 0 ? tailPerPod(fresh, opts.initialTail) : fresh) sink.line(rec);
|
|
8698
8042
|
const tailCut = q !== opts.initial && q.tailLines !== void 0 && pods.some((p) => p.state === "ok" && p.lines >= q.tailLines);
|
|
8699
8043
|
if (page.truncated || pods.some((p) => p.truncated) || tailCut) sink.event({
|
|
8700
8044
|
event: "truncated",
|
|
@@ -9085,6 +8429,8 @@ async function deployBundle(opts) {
|
|
|
9085
8429
|
return;
|
|
9086
8430
|
}
|
|
9087
8431
|
if (target.app.type === "static" && opts.noStatic) fail(`--no-static leaves a backend's frontend out of its bundle, and "${target.name}" is a static app: its bundle is nothing but its frontend.`, "Deploy it without --no-static.", "usage");
|
|
8432
|
+
const standalone = target.app.type === "static" ? standaloneStaticRefusal(target.name, target.app) : void 0;
|
|
8433
|
+
if (standalone) fail(standalone.message, standalone.hint, "usage");
|
|
9088
8434
|
if (target.app.type === "static") {
|
|
9089
8435
|
progress(chalk.gray(` Building static app "${target.name}"...`));
|
|
9090
8436
|
let staticDir;
|
|
@@ -9110,6 +8456,14 @@ async function deployBundle(opts) {
|
|
|
9110
8456
|
});
|
|
9111
8457
|
return;
|
|
9112
8458
|
}
|
|
8459
|
+
if (target.app.type === "backend") {
|
|
8460
|
+
const tablesDir = resolveBackendPaths(target.app, projectRoot).tables;
|
|
8461
|
+
const legacy = legacyCollectionsDir(projectRoot, tablesDir);
|
|
8462
|
+
if (legacy) {
|
|
8463
|
+
const refusal = legacyLayoutRefusal(legacy, tablesDir);
|
|
8464
|
+
fail(refusal.message, refusal.hint, "legacy_layout");
|
|
8465
|
+
}
|
|
8466
|
+
}
|
|
9113
8467
|
progress(chalk.gray(" Building bundle..."));
|
|
9114
8468
|
const backend = {
|
|
9115
8469
|
name: target.name,
|
|
@@ -9179,6 +8533,22 @@ var STATIC_UNDO_HINT = "Something wrong? A static app deployed on its own cannot
|
|
|
9179
8533
|
* by uploading it. `--no-verify` is the way past for a file the check gets
|
|
9180
8534
|
* wrong.
|
|
9181
8535
|
*/
|
|
8536
|
+
/**
|
|
8537
|
+
* Why a static app cannot be deployed on its own, or `undefined` when it can.
|
|
8538
|
+
*
|
|
8539
|
+
* A static app deployed alone is served by a process with no functions, so
|
|
8540
|
+
* routes to custom functions would have nothing to call: the runtime refuses
|
|
8541
|
+
* to boot such a bundle, and an older one would answer every routed path with
|
|
8542
|
+
* the app's index.html. Deploying the backend folds the app in, and that one
|
|
8543
|
+
* process serves the app, its routes and the functions together.
|
|
8544
|
+
*/
|
|
8545
|
+
function standaloneStaticRefusal(name, app) {
|
|
8546
|
+
if (!app.routes?.length) return void 0;
|
|
8547
|
+
return {
|
|
8548
|
+
message: `"${name}" routes ${app.routes.map((route) => route.path).join(", ")} to custom functions, and a static app deployed on its own has no functions to call.`,
|
|
8549
|
+
hint: "Deploy the project's backend instead: its bundle folds this app in, and one process serves both."
|
|
8550
|
+
};
|
|
8551
|
+
}
|
|
9182
8552
|
function verifyStaticOutput(projectRoot, apps) {
|
|
9183
8553
|
const errors = [];
|
|
9184
8554
|
let checked = 0;
|
|
@@ -9220,6 +8590,7 @@ async function uploadAndTrigger(opts) {
|
|
|
9220
8590
|
startedAt: opts.startedAt,
|
|
9221
8591
|
projectRoot
|
|
9222
8592
|
});
|
|
8593
|
+
if (manifest.bundleFormat < BUNDLE_FORMAT_VERSION) fail(`${path.relative(process.cwd(), bundleDir) || "."} is a format-${manifest.bundleFormat} bundle, built from config/collections, and Rebase Cloud takes format ${BUNDLE_FORMAT_VERSION} (backend/schema). Nothing was uploaded.`, `In the project, run \`${MIGRATE_COMMAND}\`, commit, then \`rebase build\` with this CLI and deploy that bundle.`, "bundle_format_too_old");
|
|
9223
8594
|
if (manifest.hooks?.native) {
|
|
9224
8595
|
const names = (manifest.hooks.nativeModules ?? []).map((m) => m.name).join(", ");
|
|
9225
8596
|
fail(`This bundle depends on native modules${names ? ` (${names})` : ""}, which the managed runtime cannot run.`, "Remove the native dependency, or deploy on the custom runtime.");
|
|
@@ -9684,6 +9055,11 @@ function ejectWarning(projectRef) {
|
|
|
9684
9055
|
function ejectRefusal(opts, projectRef) {
|
|
9685
9056
|
if (!opts.managed || opts.eject) return void 0;
|
|
9686
9057
|
const eject = "To eject on purpose, add `--eject`.";
|
|
9058
|
+
if (opts.git) return {
|
|
9059
|
+
message: `${projectRef} runs on the managed runtime, and \`--git\` builds a container image from its repository on the control plane — which ejects it from managed.`,
|
|
9060
|
+
hint: `Ship it to the managed runtime from a checkout with \`rebase cloud deploy\`. ${eject}`,
|
|
9061
|
+
code: "managed_project"
|
|
9062
|
+
};
|
|
9687
9063
|
if (opts.source) return {
|
|
9688
9064
|
message: `${projectRef} runs on the managed runtime, and \`--source\` builds a container image from this directory — which ejects it from managed. Picking a build method is not the same as asking to leave the runtime.`,
|
|
9689
9065
|
hint: `Deploy this directory to the managed runtime with \`rebase cloud deploy --bundle\`. ${eject}`,
|
|
@@ -9865,9 +9241,29 @@ var DEPLOY_FLAGS = {
|
|
|
9865
9241
|
"--allow-downgrade": Boolean,
|
|
9866
9242
|
"--preview": Boolean,
|
|
9867
9243
|
"--preview-name": String,
|
|
9244
|
+
"--git": Boolean,
|
|
9868
9245
|
"-m": "--message"
|
|
9869
9246
|
};
|
|
9870
9247
|
/**
|
|
9248
|
+
* The flags that describe a build made on this machine, which `--git` — a
|
|
9249
|
+
* build the control plane makes from the repository — cannot honour. Refused
|
|
9250
|
+
* rather than ignored: either reading would ship something other than what the
|
|
9251
|
+
* line asked for.
|
|
9252
|
+
*/
|
|
9253
|
+
var LOCAL_BUILD_FLAGS = [
|
|
9254
|
+
"--source",
|
|
9255
|
+
"--bundle",
|
|
9256
|
+
"--bundle-dir",
|
|
9257
|
+
"--skip-type-check",
|
|
9258
|
+
"--skip-schema",
|
|
9259
|
+
"--no-static",
|
|
9260
|
+
"--no-source",
|
|
9261
|
+
"--no-verify",
|
|
9262
|
+
"--allow-downgrade",
|
|
9263
|
+
"--preview",
|
|
9264
|
+
"--preview-name"
|
|
9265
|
+
];
|
|
9266
|
+
/**
|
|
9871
9267
|
* `rebase cloud deploy [app]` — its flags, and which app of this repository the
|
|
9872
9268
|
* line named.
|
|
9873
9269
|
*
|
|
@@ -9931,6 +9327,10 @@ async function deployCommand(rawArgs, projectRef) {
|
|
|
9931
9327
|
if (!isJsonMode() && process.stdout.isTTY !== true) note(chalk.gray("Printing the deploy summary. For the machine-readable result, pass --json."));
|
|
9932
9328
|
if (args["--wait"] && args["--no-follow"]) fail("--wait and --no-follow ask for opposite things.", "`deploy` follows by default — pass neither, or `--no-follow` to return as soon as the build is triggered.", "usage");
|
|
9933
9329
|
if (args["--source"] && args["--no-source"]) fail("--source and --no-source ask for opposite things.", "`--source <path>` builds a container image from a directory; `--no-source` skips uploading the source beside a managed bundle. Pass one.", "usage");
|
|
9330
|
+
if (args["--git"]) {
|
|
9331
|
+
await deployFromGit(rawArgs, projectRef, startedAt);
|
|
9332
|
+
return;
|
|
9333
|
+
}
|
|
9934
9334
|
const preview = resolvePreviewRequest(args);
|
|
9935
9335
|
if (preview && (args["--source"] || args["--eject"])) fail(`--preview cannot be combined with ${args["--source"] ? "--source" : "--eject"}: a preview is built from a managed bundle, and that flag builds a container image for production.`, "Drop it to deploy a preview, or drop --preview to deploy production.", "usage");
|
|
9936
9336
|
if (preview && !args["--bundle"] && !declaresManagedRuntime(appName)) fail("Previews are built from managed bundles, and this app builds a container image.", "Declare `runtime: \"managed\"` on the backend in rebase.json to preview it, with its static apps folded in. A static app cannot be previewed on its own on Rebase Cloud yet.", "preview_unsupported");
|
|
@@ -10085,6 +9485,132 @@ async function deployCommand(rawArgs, projectRef) {
|
|
|
10085
9485
|
}
|
|
10086
9486
|
});
|
|
10087
9487
|
}
|
|
9488
|
+
/**
|
|
9489
|
+
* `rebase cloud deploy --git [<branch>]` — the control plane builds the
|
|
9490
|
+
* project's connected repository, as the hosted connector's `deploy` tool does,
|
|
9491
|
+
* and this follows the deployment the way every other one is followed.
|
|
9492
|
+
*
|
|
9493
|
+
* Nothing on this machine is read, built or uploaded: the repository and its
|
|
9494
|
+
* branch are the build's whole input. Without a branch, the control plane
|
|
9495
|
+
* builds the one configured on the project (`rebase cloud settings`).
|
|
9496
|
+
*/
|
|
9497
|
+
async function deployFromGit(rawArgs, projectRef, startedAt) {
|
|
9498
|
+
const { flags: args, appName: branchArg } = resolveDeployArgs(rawArgs);
|
|
9499
|
+
const local = LOCAL_BUILD_FLAGS.filter((flag) => args[flag] !== void 0 && args[flag] !== false);
|
|
9500
|
+
if (local.length > 0) fail(`--git cannot be combined with ${local.join(", ")}: the control plane builds the repository, and ${local.length === 1 ? "that flag describes" : "those flags describe"} a build made here.`, "Drop --git to build this directory, or drop the other flags to build the repository.", "usage");
|
|
9501
|
+
const branch = branchArg?.trim() || void 0;
|
|
9502
|
+
const { client, url } = await requireClient(rawArgs);
|
|
9503
|
+
const projectId = await resolveProjectRef(projectRef, client);
|
|
9504
|
+
await requirePaymentMethod(client, projectId);
|
|
9505
|
+
const { project, recent, readable } = await readDeployContext(client, projectId);
|
|
9506
|
+
if (!readable && args["--eject"] !== true) fail(`Could not read ${projectRef}, so this cannot tell whether it would eject the project from the managed runtime.`, "Try again in a moment. If leaving the managed runtime is intended, pass `--eject`.", "preflight_unreadable");
|
|
9507
|
+
const projectRow = project;
|
|
9508
|
+
const repo = pick(projectRow, "gitRepoUrl", "git_repo_url");
|
|
9509
|
+
if (readable && !repo) fail(`${projectRef} has no git repository connected, so there is nothing for --git to build.`, "Connect one with `rebase cloud settings set --repo <url>`, or ship this directory with `rebase cloud deploy`.", "no_git_repository");
|
|
9510
|
+
const eject = {
|
|
9511
|
+
managed: isManagedProject(project, recent[0]),
|
|
9512
|
+
source: false,
|
|
9513
|
+
eject: args["--eject"] === true,
|
|
9514
|
+
git: true
|
|
9515
|
+
};
|
|
9516
|
+
const refusal = ejectRefusal(eject, projectRef);
|
|
9517
|
+
if (refusal) fail(refusal.message, refusal.hint, refusal.code);
|
|
9518
|
+
const warnings = deployWarnings(eject, projectRef);
|
|
9519
|
+
for (const w of warnings) warn(w.message, w.hint);
|
|
9520
|
+
const builds = branch ?? pick(projectRow, "gitBranch", "git_branch");
|
|
9521
|
+
if (!isJsonMode()) {
|
|
9522
|
+
console.log("");
|
|
9523
|
+
console.log(chalk.gray(` Building from git: ${repo ?? "the connected repository"}${builds ? ` (${builds})` : ""}.`));
|
|
9524
|
+
console.log(chalk.gray(" This directory is NOT uploaded — the control plane clones the repository."));
|
|
9525
|
+
console.log("");
|
|
9526
|
+
console.log(` 🚀 Triggering deployment for project ${chalk.bold(projectRef)} from git...`);
|
|
9527
|
+
}
|
|
9528
|
+
const body = {
|
|
9529
|
+
projectId,
|
|
9530
|
+
client: "cli"
|
|
9531
|
+
};
|
|
9532
|
+
if (branch) body.branch = branch;
|
|
9533
|
+
if (args["--message"]) body.message = args["--message"];
|
|
9534
|
+
let triggered;
|
|
9535
|
+
try {
|
|
9536
|
+
const res = await client.functions.invoke("deploy", body);
|
|
9537
|
+
if (!res?.deployment?.id) fail("Control plane did not return a deployment id.");
|
|
9538
|
+
triggered = {
|
|
9539
|
+
deploymentId: String(res.deployment.id),
|
|
9540
|
+
deduplicated: res.deduplicated === true,
|
|
9541
|
+
hosts: deployHostsFrom(res)
|
|
9542
|
+
};
|
|
9543
|
+
} catch (e) {
|
|
9544
|
+
resolveTriggerFailure(e);
|
|
9545
|
+
}
|
|
9546
|
+
const { deploymentId, deduplicated, hosts } = triggered;
|
|
9547
|
+
if (!isJsonMode()) console.log(chalk.gray(` Deployment ${deploymentId} created.`));
|
|
9548
|
+
const appsAt = (host) => sourceBuildApps(sourceBuildAppName(), host);
|
|
9549
|
+
const json = {
|
|
9550
|
+
deploymentId,
|
|
9551
|
+
deduplicated,
|
|
9552
|
+
source: "git",
|
|
9553
|
+
branch: builds ?? null,
|
|
9554
|
+
...warningPayload(warnings)
|
|
9555
|
+
};
|
|
9556
|
+
if (args["--no-follow"]) {
|
|
9557
|
+
await reportTriggered({
|
|
9558
|
+
client,
|
|
9559
|
+
url,
|
|
9560
|
+
projectId,
|
|
9561
|
+
deploymentId,
|
|
9562
|
+
appsAt,
|
|
9563
|
+
registeredHosts: hosts,
|
|
9564
|
+
headline: "",
|
|
9565
|
+
json: {
|
|
9566
|
+
...json,
|
|
9567
|
+
following: false
|
|
9568
|
+
}
|
|
9569
|
+
});
|
|
9570
|
+
await recordDeploy({
|
|
9571
|
+
followed: false,
|
|
9572
|
+
status: "not_followed",
|
|
9573
|
+
deduplicated,
|
|
9574
|
+
startedAt
|
|
9575
|
+
});
|
|
9576
|
+
return;
|
|
9577
|
+
}
|
|
9578
|
+
if (!isJsonMode()) {
|
|
9579
|
+
console.log(chalk.gray(" Streaming build logs (Ctrl-C to stop watching — the build keeps running):"));
|
|
9580
|
+
console.log("");
|
|
9581
|
+
}
|
|
9582
|
+
const { status } = await streamBuildLogs(client, deploymentId, {
|
|
9583
|
+
quiet: isJsonMode(),
|
|
9584
|
+
timeoutMs: resolveDeployTimeout(args["--timeout"]),
|
|
9585
|
+
projectId,
|
|
9586
|
+
url,
|
|
9587
|
+
announce: false,
|
|
9588
|
+
failedApps: appsAt(void 0).map((a) => a.name),
|
|
9589
|
+
onTerminal: (ended) => recordDeploy({
|
|
9590
|
+
followed: true,
|
|
9591
|
+
status: ended,
|
|
9592
|
+
deduplicated,
|
|
9593
|
+
startedAt
|
|
9594
|
+
})
|
|
9595
|
+
});
|
|
9596
|
+
await reportDeployed({
|
|
9597
|
+
undo: ROLLBACK_HINT,
|
|
9598
|
+
client,
|
|
9599
|
+
url,
|
|
9600
|
+
projectId,
|
|
9601
|
+
projectRef,
|
|
9602
|
+
deploymentId,
|
|
9603
|
+
startedAt,
|
|
9604
|
+
liveTimeoutMs: resolveLiveTimeout(args["--live-timeout"]),
|
|
9605
|
+
appsAt,
|
|
9606
|
+
registeredHosts: hosts,
|
|
9607
|
+
json: {
|
|
9608
|
+
...json,
|
|
9609
|
+
following: true,
|
|
9610
|
+
status
|
|
9611
|
+
}
|
|
9612
|
+
});
|
|
9613
|
+
}
|
|
10088
9614
|
/** The backend this repository declares, for naming a source build in its summary. */
|
|
10089
9615
|
function sourceBuildAppName() {
|
|
10090
9616
|
try {
|
|
@@ -10423,20 +9949,22 @@ async function logsCommand(rawArgs, projectRef) {
|
|
|
10423
9949
|
const preview = args["--preview"] ? await resolvePreviewRef(client, projectId, previewRef) : void 0;
|
|
10424
9950
|
if (args["--runtime"]) {
|
|
10425
9951
|
if (preview && preview.backend === "production") fail(`Preview "${preview.name}" is a static app: it runs no server of its own and calls the production backend.`, `Its build log is \`rebase cloud logs --preview ${preview.name}\`; production's runtime log is \`rebase cloud logs --runtime\`.`, "preview_static");
|
|
9952
|
+
const matchTail = tail?.requested ?? 500;
|
|
10426
9953
|
const query = {
|
|
10427
9954
|
...since ?? {},
|
|
10428
|
-
...tail ? { tailLines: tail.applied } : {},
|
|
9955
|
+
...filtered ? { tailLines: SERVER_MAX_TAIL_LINES } : tail ? { tailLines: tail.applied } : {},
|
|
10429
9956
|
...args["--previous"] ? { previous: true } : {},
|
|
10430
9957
|
...preview ? { preview: preview.name } : {}
|
|
10431
9958
|
};
|
|
10432
9959
|
const subject = preview ? `preview ${preview.name}` : `project ${projectRef}`;
|
|
10433
|
-
if (tail?.note) note(chalk.yellow(tail.note));
|
|
9960
|
+
if (tail?.note && !filtered) note(chalk.yellow(tail.note));
|
|
10434
9961
|
if (args["--follow"]) {
|
|
10435
9962
|
await followRuntime(client, projectId, {
|
|
10436
9963
|
query,
|
|
10437
9964
|
filter,
|
|
10438
9965
|
subject,
|
|
10439
|
-
preview: preview?.name
|
|
9966
|
+
preview: preview?.name,
|
|
9967
|
+
...filtered ? { initialTail: matchTail } : {}
|
|
10440
9968
|
});
|
|
10441
9969
|
return;
|
|
10442
9970
|
}
|
|
@@ -10446,7 +9974,8 @@ async function logsCommand(rawArgs, projectRef) {
|
|
|
10446
9974
|
} catch (e) {
|
|
10447
9975
|
reportError(e, "Failed to fetch runtime logs");
|
|
10448
9976
|
}
|
|
10449
|
-
const
|
|
9977
|
+
const read = filterThenTail(page, filter, filtered ? matchTail : Number.MAX_SAFE_INTEGER);
|
|
9978
|
+
const records = read.records;
|
|
10450
9979
|
const logs = filtered ? records.map((r) => r.raw).join("\n") : page.logs ?? null;
|
|
10451
9980
|
emit(() => {
|
|
10452
9981
|
console.log("");
|
|
@@ -10456,15 +9985,31 @@ async function logsCommand(rawArgs, projectRef) {
|
|
|
10456
9985
|
if (records.length > 0) for (const r of records) console.log(paintLine(r));
|
|
10457
9986
|
else console.log(chalk.gray(filtered && page.logs ? " (no line matches)" : " (no logs)"));
|
|
10458
9987
|
console.log("");
|
|
9988
|
+
if (filtered && page.logs) {
|
|
9989
|
+
const kept = read.returnedLines < read.matchedLines ? `the newest ${matchTail} per pod of ${read.matchedLines} matching lines` : `${read.matchedLines} matching line${read.matchedLines === 1 ? "" : "s"}`;
|
|
9990
|
+
console.log(chalk.gray(` ${kept}, from ${read.scannedLines} searched.`));
|
|
9991
|
+
if (read.note) console.log(chalk.yellow(` ${read.note}`));
|
|
9992
|
+
console.log("");
|
|
9993
|
+
}
|
|
10459
9994
|
}, {
|
|
10460
9995
|
runtime: true,
|
|
10461
9996
|
preview: preview?.name ?? null,
|
|
10462
9997
|
logs,
|
|
10463
|
-
pods: page.pods ?? [],
|
|
9998
|
+
pods: filtered ? read.pods : page.pods ?? [],
|
|
10464
9999
|
state: page.state ?? null,
|
|
10465
10000
|
message: page.message ?? null,
|
|
10466
10001
|
truncated: page.truncated === true,
|
|
10467
|
-
nextSinceTime: page.nextSinceTime ?? null
|
|
10002
|
+
nextSinceTime: page.nextSinceTime ?? null,
|
|
10003
|
+
...filtered ? { filter: {
|
|
10004
|
+
grep: args["--grep"] ?? null,
|
|
10005
|
+
level: level ?? null,
|
|
10006
|
+
tail: matchTail,
|
|
10007
|
+
scannedLines: read.scannedLines,
|
|
10008
|
+
matchedLines: read.matchedLines,
|
|
10009
|
+
returnedLines: read.returnedLines,
|
|
10010
|
+
scanCapped: read.scanCapped,
|
|
10011
|
+
note: read.note
|
|
10012
|
+
} } : {}
|
|
10468
10013
|
});
|
|
10469
10014
|
return;
|
|
10470
10015
|
}
|
|
@@ -10682,7 +10227,8 @@ async function followRuntime(client, projectId, opts) {
|
|
|
10682
10227
|
isTransient: transientReadFailure
|
|
10683
10228
|
}, {
|
|
10684
10229
|
initial: opts.query,
|
|
10685
|
-
filter: opts.filter
|
|
10230
|
+
filter: opts.filter,
|
|
10231
|
+
...opts.initialTail !== void 0 ? { initialTail: opts.initialTail } : {}
|
|
10686
10232
|
});
|
|
10687
10233
|
} catch (e) {
|
|
10688
10234
|
reportError(e, "Failed to follow runtime logs");
|
|
@@ -10694,7 +10240,7 @@ async function followRuntime(client, projectId, opts) {
|
|
|
10694
10240
|
//#endregion
|
|
10695
10241
|
//#region src/commands/cloud/orgs.ts
|
|
10696
10242
|
/**
|
|
10697
|
-
* `rebase cloud orgs` — list / create / members / invites.
|
|
10243
|
+
* `rebase cloud orgs` — list / create / rename / delete / members / invites.
|
|
10698
10244
|
*
|
|
10699
10245
|
* Members: list, invite by email, remove, change a role. Inviting goes through
|
|
10700
10246
|
* the control plane's `invites` function, which always opens an invitation —
|
|
@@ -10705,6 +10251,11 @@ async function followRuntime(client, projectId, opts) {
|
|
|
10705
10251
|
* the output says whether it did. Inviting takes a `rebase cloud login`
|
|
10706
10252
|
* session — a token cannot hand out access to an organization.
|
|
10707
10253
|
*/
|
|
10254
|
+
/** What the invitation commands say on a control plane that has no `invites` function yet. */
|
|
10255
|
+
var INVITES_UNSERVED = {
|
|
10256
|
+
what: "invitations",
|
|
10257
|
+
hint: "Nothing was sent or changed. `rebase cloud orgs members` still lists, removes and re-roles the members an organization has."
|
|
10258
|
+
};
|
|
10708
10259
|
async function orgsCommand(subcommand, rawArgs) {
|
|
10709
10260
|
switch (subcommand) {
|
|
10710
10261
|
case "list":
|
|
@@ -10714,6 +10265,12 @@ async function orgsCommand(subcommand, rawArgs) {
|
|
|
10714
10265
|
case "create":
|
|
10715
10266
|
await createOrg(rawArgs);
|
|
10716
10267
|
break;
|
|
10268
|
+
case "rename":
|
|
10269
|
+
await renameOrg(rawArgs);
|
|
10270
|
+
break;
|
|
10271
|
+
case "delete":
|
|
10272
|
+
await deleteOrg(rawArgs);
|
|
10273
|
+
break;
|
|
10717
10274
|
case "members":
|
|
10718
10275
|
await membersCommand(rawArgs);
|
|
10719
10276
|
break;
|
|
@@ -10814,6 +10371,97 @@ async function createOrg(rawArgs) {
|
|
|
10814
10371
|
reportError(e, "Failed to create organization");
|
|
10815
10372
|
}
|
|
10816
10373
|
}
|
|
10374
|
+
/** What `rebase cloud orgs rename` parses. Its page is the group's own. */
|
|
10375
|
+
var RENAME_ORG_FLAGS = {
|
|
10376
|
+
"--slug": String,
|
|
10377
|
+
"--org": String
|
|
10378
|
+
};
|
|
10379
|
+
/**
|
|
10380
|
+
* Rename an organization, and with `--slug` change its slug. A plain update of
|
|
10381
|
+
* the `organizations` row: the control plane lets its owners and admins make
|
|
10382
|
+
* it, and refuses a slug another organization holds.
|
|
10383
|
+
*/
|
|
10384
|
+
async function renameOrg(rawArgs) {
|
|
10385
|
+
const { flags, positionals } = parseCloudArgs({
|
|
10386
|
+
spec: RENAME_ORG_FLAGS,
|
|
10387
|
+
rawArgs,
|
|
10388
|
+
commandWords: 3,
|
|
10389
|
+
command: "cloud orgs",
|
|
10390
|
+
maxPositionals: 1
|
|
10391
|
+
});
|
|
10392
|
+
const name = positionals[0]?.trim();
|
|
10393
|
+
const slug = flags["--slug"]?.trim();
|
|
10394
|
+
if (!name) fail("Name the organization's new name.", "`rebase cloud orgs rename \"Acme Inc\" [--slug acme]`.", "usage");
|
|
10395
|
+
if (slug !== void 0 && slugify(slug) !== slug) fail(`--slug ${slug} is not a slug.`, `Lowercase letters, digits and hyphens, e.g. ${slugify(slug) || "acme"}.`, "usage");
|
|
10396
|
+
const { client, url } = await requireClient(rawArgs);
|
|
10397
|
+
const org = orgFor(flags["--org"], url);
|
|
10398
|
+
const patch = { name };
|
|
10399
|
+
if (slug) patch.slug = slug;
|
|
10400
|
+
try {
|
|
10401
|
+
await client.data.table("organizations").update(org, patch);
|
|
10402
|
+
} catch (e) {
|
|
10403
|
+
reportError(e, "Failed to rename the organization");
|
|
10404
|
+
}
|
|
10405
|
+
emit(() => success(`Organization ${org} is now ${chalk.bold(name)}${slug ? ` (${slug})` : ""}`), {
|
|
10406
|
+
success: true,
|
|
10407
|
+
id: org,
|
|
10408
|
+
...patch
|
|
10409
|
+
});
|
|
10410
|
+
}
|
|
10411
|
+
/**
|
|
10412
|
+
* Delete an organization. Asks first, and refuses while it still has projects:
|
|
10413
|
+
* deleting each project is what tears down its namespace and database and
|
|
10414
|
+
* cancels its subscription, and the control plane will not let an
|
|
10415
|
+
* organization's deletion skip that. The check here names them before asking;
|
|
10416
|
+
* the control plane's own refusal is the authority.
|
|
10417
|
+
*/
|
|
10418
|
+
async function deleteOrg(rawArgs) {
|
|
10419
|
+
const { flags } = parseCloudArgs({
|
|
10420
|
+
spec: { "--org": String },
|
|
10421
|
+
rawArgs,
|
|
10422
|
+
commandWords: 3,
|
|
10423
|
+
command: "cloud orgs",
|
|
10424
|
+
maxPositionals: 0
|
|
10425
|
+
});
|
|
10426
|
+
const { client, url } = await requireClient(rawArgs);
|
|
10427
|
+
const org = orgFor(flags["--org"], url);
|
|
10428
|
+
let row;
|
|
10429
|
+
let projects;
|
|
10430
|
+
try {
|
|
10431
|
+
row = cloudRow(await client.data.table("organizations").findById(org));
|
|
10432
|
+
projects = cloudRows((await client.data.table("projects").find({
|
|
10433
|
+
where: { organization: ["==", org] },
|
|
10434
|
+
limit: 20
|
|
10435
|
+
})).data);
|
|
10436
|
+
} catch (e) {
|
|
10437
|
+
reportError(e, "Failed to read the organization");
|
|
10438
|
+
}
|
|
10439
|
+
if (!row) fail(`No organization ${org} that you can see.`, "`rebase cloud orgs` lists yours.", "not_found");
|
|
10440
|
+
const label = row.name ? `${row.name} (${org})` : org;
|
|
10441
|
+
if (projects.length > 0) {
|
|
10442
|
+
const names = projects.map((p) => String(p.subdomain ?? p.name ?? p.id)).sort();
|
|
10443
|
+
fail(`Organization ${label} still has ${projects.length}${projects.length === 20 ? "+" : ""} project(s): ${names.slice(0, 5).join(", ")}${names.length > 5 ? ", …" : ""}.`, "Delete them first with `rebase cloud projects delete <slug>`: that is what tears down each one's database and cancels its subscription.", "org_not_empty");
|
|
10444
|
+
}
|
|
10445
|
+
await confirmDestructive({
|
|
10446
|
+
yes: Boolean(flags["--yes"]),
|
|
10447
|
+
prompt: `Delete organization ${label}? Its members lose it, and this cannot be undone.`
|
|
10448
|
+
});
|
|
10449
|
+
try {
|
|
10450
|
+
await client.data.table("organizations").delete(org);
|
|
10451
|
+
} catch (e) {
|
|
10452
|
+
reportError(e, "Failed to delete the organization");
|
|
10453
|
+
}
|
|
10454
|
+
const wasActive = getContextOrg(url) === org;
|
|
10455
|
+
if (wasActive) setContextOrg(url, void 0);
|
|
10456
|
+
emit(() => {
|
|
10457
|
+
success(`Deleted organization ${label}`);
|
|
10458
|
+
if (wasActive) note(chalk.gray("It was the active organization; pick another with `rebase cloud use`."));
|
|
10459
|
+
}, {
|
|
10460
|
+
success: true,
|
|
10461
|
+
deleted: org,
|
|
10462
|
+
wasActive
|
|
10463
|
+
});
|
|
10464
|
+
}
|
|
10817
10465
|
var MEMBER_ROLES = [
|
|
10818
10466
|
"owner",
|
|
10819
10467
|
"admin",
|
|
@@ -10889,7 +10537,7 @@ async function membersCommand(rawArgs) {
|
|
|
10889
10537
|
case "list": return listMembers(rawArgs, flags["--org"]);
|
|
10890
10538
|
case "invite": return inviteMember(rawArgs, flags["--org"], rest[0], role);
|
|
10891
10539
|
case "remove": return removeMember(rawArgs, flags["--org"], rest[0], Boolean(flags["--yes"]));
|
|
10892
|
-
case "role": return changeRole(rawArgs, flags["--org"], rest[0], rest[1]);
|
|
10540
|
+
case "role": return changeRole(rawArgs, flags["--org"], rest[0], rest[1], Boolean(flags["--yes"]));
|
|
10893
10541
|
}
|
|
10894
10542
|
}
|
|
10895
10543
|
async function listMembers(rawArgs, orgFlag) {
|
|
@@ -10946,7 +10594,7 @@ async function inviteMember(rawArgs, orgFlag, email, role) {
|
|
|
10946
10594
|
role
|
|
10947
10595
|
});
|
|
10948
10596
|
} catch (e) {
|
|
10949
|
-
|
|
10597
|
+
reportCallError(e, `Failed to invite ${email}`, INVITES_UNSERVED);
|
|
10950
10598
|
}
|
|
10951
10599
|
if (result.kind === "added") {
|
|
10952
10600
|
emit(() => success(`${result.email} already had a verified account and is now a member (${result.role}) of org ${org}`), {
|
|
@@ -10998,7 +10646,7 @@ async function removeMember(rawArgs, orgFlag, ref, yes) {
|
|
|
10998
10646
|
}
|
|
10999
10647
|
});
|
|
11000
10648
|
}
|
|
11001
|
-
async function changeRole(rawArgs, orgFlag, ref, role) {
|
|
10649
|
+
async function changeRole(rawArgs, orgFlag, ref, role, yes) {
|
|
11002
10650
|
if (!ref || !role) fail("Name the member and the role.", "`rebase cloud orgs members role <email|uid> <owner|admin|member>`.", "usage");
|
|
11003
10651
|
const { client, url } = await requireClient(rawArgs);
|
|
11004
10652
|
const org = orgFor(orgFlag, url);
|
|
@@ -11020,6 +10668,11 @@ async function changeRole(rawArgs, orgFlag, ref, role) {
|
|
|
11020
10668
|
});
|
|
11021
10669
|
return;
|
|
11022
10670
|
}
|
|
10671
|
+
const ownership = role === "owner" ? " They will be able to delete the organization and change anyone's role." : target.role === "owner" ? " They stop being an owner." : "";
|
|
10672
|
+
await confirmDestructive({
|
|
10673
|
+
yes,
|
|
10674
|
+
prompt: `Make ${who} ${role} in org ${org} (now ${target.role ?? "member"})?${ownership}`
|
|
10675
|
+
});
|
|
11023
10676
|
try {
|
|
11024
10677
|
await client.data.table("organization-members").update(target.id, { role });
|
|
11025
10678
|
} catch (e) {
|
|
@@ -11067,7 +10720,7 @@ async function invitesCommand(rawArgs) {
|
|
|
11067
10720
|
listed = await loadInvites(client, org);
|
|
11068
10721
|
} catch (e) {
|
|
11069
10722
|
if (e?.status === 403) fail(`Only owners and admins of org ${org} can see its pending invitations.`, "Ask one of them; `rebase cloud orgs members` lists who they are.", "forbidden");
|
|
11070
|
-
|
|
10723
|
+
reportCallError(e, "Failed to list invitations", INVITES_UNSERVED);
|
|
11071
10724
|
}
|
|
11072
10725
|
if (action === "list") {
|
|
11073
10726
|
emit(() => {
|
|
@@ -11092,13 +10745,17 @@ async function invitesCommand(rawArgs) {
|
|
|
11092
10745
|
}
|
|
11093
10746
|
const target = pickInvite(listed.invites, ref, action);
|
|
11094
10747
|
if (action === "revoke") {
|
|
10748
|
+
await confirmDestructive({
|
|
10749
|
+
yes: Boolean(flags["--yes"]),
|
|
10750
|
+
prompt: `Revoke the invitation for ${target.email} (${target.role})? Its link stops working.`
|
|
10751
|
+
});
|
|
11095
10752
|
try {
|
|
11096
10753
|
await client.functions.invoke("invites", void 0, {
|
|
11097
10754
|
method: "DELETE",
|
|
11098
10755
|
path: encodeURIComponent(target.id)
|
|
11099
10756
|
});
|
|
11100
10757
|
} catch (e) {
|
|
11101
|
-
|
|
10758
|
+
reportCallError(e, `Failed to revoke the invitation for ${target.email}`, INVITES_UNSERVED);
|
|
11102
10759
|
}
|
|
11103
10760
|
emit(() => success(`Revoked the invitation for ${target.email}; its link no longer works`), {
|
|
11104
10761
|
org,
|
|
@@ -11110,7 +10767,7 @@ async function invitesCommand(rawArgs) {
|
|
|
11110
10767
|
try {
|
|
11111
10768
|
resent = await client.functions.invoke("invites", {}, { path: `${encodeURIComponent(target.id)}/resend` });
|
|
11112
10769
|
} catch (e) {
|
|
11113
|
-
|
|
10770
|
+
reportCallError(e, `Failed to resend the invitation for ${target.email}`, INVITES_UNSERVED);
|
|
11114
10771
|
}
|
|
11115
10772
|
emit(() => {
|
|
11116
10773
|
success(`New link for ${resent.invite.email}, valid until ${resent.invite.expiresAt.slice(0, 10)}; the old one no longer works`);
|
|
@@ -11140,6 +10797,17 @@ function printOrgsHelp() {
|
|
|
11140
10797
|
description: "Create a new organization",
|
|
11141
10798
|
flags: [["--name <name>", "Display name"], ["--slug <slug>", "URL slug. Derived from the name when omitted"]]
|
|
11142
10799
|
},
|
|
10800
|
+
{
|
|
10801
|
+
action: "rename",
|
|
10802
|
+
args: "<name>",
|
|
10803
|
+
description: "Rename the organization. Owners and admins",
|
|
10804
|
+
flags: [["--slug <slug>", "Change its slug too. Kept when omitted"], ["--org <id>", "The organization. Default: the active one"]]
|
|
10805
|
+
},
|
|
10806
|
+
{
|
|
10807
|
+
action: "delete",
|
|
10808
|
+
description: "Delete the organization. Refused while it has projects; asks first, --yes skips the prompt",
|
|
10809
|
+
flags: [["--org <id>", "The organization. Default: the active one"]]
|
|
10810
|
+
},
|
|
11143
10811
|
{
|
|
11144
10812
|
action: "members",
|
|
11145
10813
|
args: "[list]",
|
|
@@ -11164,7 +10832,7 @@ function printOrgsHelp() {
|
|
|
11164
10832
|
action: "members role",
|
|
11165
10833
|
args: "<email|uid> <role>",
|
|
11166
10834
|
section: "Members",
|
|
11167
|
-
description: "Change a member's role: owner, admin or member"
|
|
10835
|
+
description: "Change a member's role: owner, admin or member. Asks first; --yes skips the prompt"
|
|
11168
10836
|
},
|
|
11169
10837
|
{
|
|
11170
10838
|
action: "invites",
|
|
@@ -11176,7 +10844,7 @@ function printOrgsHelp() {
|
|
|
11176
10844
|
action: "invites revoke",
|
|
11177
10845
|
args: "<id|email>",
|
|
11178
10846
|
section: "Invitations",
|
|
11179
|
-
description: "Revoke a pending invitation; its link stops working"
|
|
10847
|
+
description: "Revoke a pending invitation; its link stops working. Asks first; --yes skips the prompt"
|
|
11180
10848
|
},
|
|
11181
10849
|
{
|
|
11182
10850
|
action: "invites resend",
|
|
@@ -11187,6 +10855,7 @@ function printOrgsHelp() {
|
|
|
11187
10855
|
],
|
|
11188
10856
|
notes: [
|
|
11189
10857
|
"The active one is what `rebase cloud use` selects, and what billing is scoped to.",
|
|
10858
|
+
"An organization with projects cannot be deleted: delete each project first, which is what tears down its database and cancels its subscription.",
|
|
11190
10859
|
"Inviting and invitations take a `rebase cloud login` session, not REBASE_TOKEN, and the owner or admin role.",
|
|
11191
10860
|
"The invitation link is printed because the control plane may send no email; the output says whether it did. Only an account that has verified the invited address can accept it."
|
|
11192
10861
|
]
|
|
@@ -11200,6 +10869,8 @@ function printOrgsHelp() {
|
|
|
11200
10869
|
* domains list Every host, its status, and the DNS records it needs
|
|
11201
10870
|
* domains add <domain> Register a host (starts, does not finish, setup)
|
|
11202
10871
|
* domains verify [domain] Check the host's published DNS now; live only if it passes
|
|
10872
|
+
* domains primary <domain> Make a verified host the canonical one
|
|
10873
|
+
* domains redirect <domain> Answer a host with a 308 to the primary (`--off` serves it again)
|
|
11203
10874
|
* domains remove <domain> Stop serving a host
|
|
11204
10875
|
*
|
|
11205
10876
|
* A project's hosts are rows of the control plane's `project_domains` table,
|
|
@@ -11244,6 +10915,7 @@ function rowEntry(row) {
|
|
|
11244
10915
|
id: row.id,
|
|
11245
10916
|
host: row.host,
|
|
11246
10917
|
primary: row.primary === true,
|
|
10918
|
+
...row.redirectToPrimary === true ? { redirectToPrimary: true } : {},
|
|
11247
10919
|
status: row.status === "verified" ? "verified" : "pending",
|
|
11248
10920
|
verifiedAt: row.verifiedAt ?? null,
|
|
11249
10921
|
isApex: row.isApex,
|
|
@@ -11337,6 +11009,12 @@ async function domainsCommand(action, rawArgs) {
|
|
|
11337
11009
|
case "verify":
|
|
11338
11010
|
await verifyDomain(rawArgs);
|
|
11339
11011
|
break;
|
|
11012
|
+
case "primary":
|
|
11013
|
+
await primaryDomain(rawArgs);
|
|
11014
|
+
break;
|
|
11015
|
+
case "redirect":
|
|
11016
|
+
await redirectDomain(rawArgs);
|
|
11017
|
+
break;
|
|
11340
11018
|
case "remove":
|
|
11341
11019
|
case "rm":
|
|
11342
11020
|
case "delete":
|
|
@@ -11376,7 +11054,8 @@ async function listDomains(rawArgs) {
|
|
|
11376
11054
|
}
|
|
11377
11055
|
for (const d of set.domains) {
|
|
11378
11056
|
const status = d.status === "verified" ? chalk.green(d.status) : chalk.yellow(d.status);
|
|
11379
|
-
|
|
11057
|
+
const role = d.primary && set.domains.length > 1 ? chalk.gray(" primary") : d.redirectToPrimary ? chalk.gray(" redirects to the primary") : "";
|
|
11058
|
+
console.log(` ${chalk.bold(d.host)} ${status}${role}`);
|
|
11380
11059
|
if (d.verifiedAt) console.log(chalk.gray(` verified ${d.verifiedAt}`));
|
|
11381
11060
|
if (d.status !== "verified") printRecords(d.instructions);
|
|
11382
11061
|
}
|
|
@@ -11505,6 +11184,105 @@ function verifyOutcome(res, target) {
|
|
|
11505
11184
|
}
|
|
11506
11185
|
};
|
|
11507
11186
|
}
|
|
11187
|
+
/**
|
|
11188
|
+
* Make one verified host the project's canonical one: the address links and
|
|
11189
|
+
* redirects are built from. The control plane keeps one primary per project and
|
|
11190
|
+
* mirrors it into the project's single domain column.
|
|
11191
|
+
*/
|
|
11192
|
+
async function primaryDomain(rawArgs) {
|
|
11193
|
+
const named = resolveDomainArg(rawArgs, "primary");
|
|
11194
|
+
if (!named) fail("Usage: rebase cloud domains primary <domain>", "Name one of the project's verified domains.", "usage");
|
|
11195
|
+
const { client } = await requireClient(rawArgs);
|
|
11196
|
+
const projectId = await requireProject(rawArgs, client);
|
|
11197
|
+
const projectRef = displayProjectRef(rawArgs);
|
|
11198
|
+
let set;
|
|
11199
|
+
try {
|
|
11200
|
+
set = await loadDomains(client, projectId);
|
|
11201
|
+
} catch (e) {
|
|
11202
|
+
reportError(e, "Failed to load custom domains");
|
|
11203
|
+
}
|
|
11204
|
+
if (set.model === "column") fail("This control plane serves one custom domain per project, so there is no primary to choose.", "`rebase cloud domains list` shows the one it serves.", "not_served");
|
|
11205
|
+
const target = pickDomain(set, named, "primary");
|
|
11206
|
+
if (target.id === null) fail(`${target.host} is held outside this project's host list, so it cannot be made primary.`, `Add it to the list first: \`rebase cloud domains add ${target.host}\`, then \`rebase cloud domains verify ${target.host}\`.`, "usage");
|
|
11207
|
+
if (target.status !== "verified") fail(`${target.host} is not verified yet, so it cannot be the primary host.`, `Verify it first: \`rebase cloud domains verify ${target.host}\`.`, "domain_not_verified");
|
|
11208
|
+
let res;
|
|
11209
|
+
try {
|
|
11210
|
+
res = await client.functions.invoke("domains", {}, { path: `${projectId}/${target.id}/primary` });
|
|
11211
|
+
} catch (e) {
|
|
11212
|
+
reportError(e, "Failed to set the primary domain");
|
|
11213
|
+
}
|
|
11214
|
+
const unchanged = res.unchanged === true;
|
|
11215
|
+
emit(() => success(unchanged ? `${target.host} already is the primary host of project ${projectRef}` : `${target.host} is now the primary host of project ${projectRef}`), {
|
|
11216
|
+
success: true,
|
|
11217
|
+
projectId,
|
|
11218
|
+
id: target.id,
|
|
11219
|
+
host: target.host,
|
|
11220
|
+
primary: true,
|
|
11221
|
+
changed: !unchanged
|
|
11222
|
+
});
|
|
11223
|
+
}
|
|
11224
|
+
/**
|
|
11225
|
+
* Answer one host with a permanent redirect (308) to the primary, path and
|
|
11226
|
+
* query kept, instead of serving the project on it — or, with `--off`, serve it
|
|
11227
|
+
* again.
|
|
11228
|
+
*
|
|
11229
|
+
* Per host and off by default, because a project may serve distinct hosts on
|
|
11230
|
+
* purpose (an `api.` host beside the site). What it is for is the other case:
|
|
11231
|
+
* `www.example.com` and `example.com` serving one site are two origins to a
|
|
11232
|
+
* browser, and whatever is keyed on the origin — Google sign-in's authorised
|
|
11233
|
+
* origins first — works on one and fails on the other.
|
|
11234
|
+
*/
|
|
11235
|
+
async function redirectDomain(rawArgs) {
|
|
11236
|
+
const { flags, positionals } = parseCloudArgs({
|
|
11237
|
+
spec: { "--off": Boolean },
|
|
11238
|
+
rawArgs,
|
|
11239
|
+
commandWords: 3,
|
|
11240
|
+
command: "cloud domains redirect",
|
|
11241
|
+
maxPositionals: 1
|
|
11242
|
+
});
|
|
11243
|
+
const named = positionals[0];
|
|
11244
|
+
const on = flags["--off"] !== true;
|
|
11245
|
+
if (!named) fail("Usage: rebase cloud domains redirect <domain> [--off]", "Name the host to send to the primary, e.g. `rebase cloud domains redirect www.example.com`.", "usage");
|
|
11246
|
+
const { client } = await requireClient(rawArgs);
|
|
11247
|
+
const projectId = await requireProject(rawArgs, client);
|
|
11248
|
+
const projectRef = displayProjectRef(rawArgs);
|
|
11249
|
+
let set;
|
|
11250
|
+
try {
|
|
11251
|
+
set = await loadDomains(client, projectId);
|
|
11252
|
+
} catch (e) {
|
|
11253
|
+
reportError(e, "Failed to load custom domains");
|
|
11254
|
+
}
|
|
11255
|
+
if (set.model === "column") fail("This control plane serves one custom domain per project, so there is no other host to redirect.", "`rebase cloud domains list` shows the one it serves.", "not_served");
|
|
11256
|
+
const target = pickDomain(set, named, "redirect");
|
|
11257
|
+
if (target.id === null) fail(`${target.host} is held outside this project's host list, so it cannot redirect.`, `Add it to the list first: \`rebase cloud domains add ${target.host}\`, then \`rebase cloud domains verify ${target.host}\`.`, "usage");
|
|
11258
|
+
if (on && target.primary) {
|
|
11259
|
+
const other = set.domains.find((d) => !d.primary && d.status === "verified");
|
|
11260
|
+
fail(`${target.host} is the primary host: the other hosts redirect to it.`, other ? `Make another host primary first: \`rebase cloud domains primary ${other.host}\`.` : "Add and verify the host it should redirect to, and make that one primary.", "domain_is_primary");
|
|
11261
|
+
}
|
|
11262
|
+
let res;
|
|
11263
|
+
try {
|
|
11264
|
+
res = await client.functions.invoke("domains", { redirect: on }, { path: `${projectId}/${target.id}/redirect` });
|
|
11265
|
+
} catch (e) {
|
|
11266
|
+
reportError(e, on ? "Failed to redirect the domain" : "Failed to stop the redirect");
|
|
11267
|
+
}
|
|
11268
|
+
const redirectsTo = res.redirectsTo ?? null;
|
|
11269
|
+
emit(() => {
|
|
11270
|
+
if (!on) success(`${target.host} is served by project ${projectRef} again`);
|
|
11271
|
+
else if (redirectsTo) success(`${target.host} now redirects to https://${redirectsTo} (308, path and query kept)`);
|
|
11272
|
+
else {
|
|
11273
|
+
success(`${target.host} will redirect to the primary host`);
|
|
11274
|
+
if (res.notInEffect) console.log(chalk.yellow(` Not in effect yet: ${res.notInEffect}`));
|
|
11275
|
+
}
|
|
11276
|
+
}, {
|
|
11277
|
+
success: true,
|
|
11278
|
+
projectId,
|
|
11279
|
+
id: target.id,
|
|
11280
|
+
host: target.host,
|
|
11281
|
+
redirectToPrimary: on,
|
|
11282
|
+
redirectsTo,
|
|
11283
|
+
...res.notInEffect ? { notInEffect: res.notInEffect } : {}
|
|
11284
|
+
});
|
|
11285
|
+
}
|
|
11508
11286
|
async function removeDomain(rawArgs) {
|
|
11509
11287
|
const { flags: args, positionals } = parseCloudArgs({
|
|
11510
11288
|
spec: {},
|
|
@@ -11563,6 +11341,16 @@ function printDomainsHelp() {
|
|
|
11563
11341
|
args: "[domain]",
|
|
11564
11342
|
description: "Check a host's DNS and put it live"
|
|
11565
11343
|
},
|
|
11344
|
+
{
|
|
11345
|
+
action: "primary",
|
|
11346
|
+
args: "<domain>",
|
|
11347
|
+
description: "Make a verified host the canonical one, the address links are built from"
|
|
11348
|
+
},
|
|
11349
|
+
{
|
|
11350
|
+
action: "redirect",
|
|
11351
|
+
args: "<domain> [--off]",
|
|
11352
|
+
description: "Answer a host with a 308 to the primary instead of serving it"
|
|
11353
|
+
},
|
|
11566
11354
|
{
|
|
11567
11355
|
action: "remove",
|
|
11568
11356
|
args: "<domain>",
|
|
@@ -11570,7 +11358,7 @@ function printDomainsHelp() {
|
|
|
11570
11358
|
}
|
|
11571
11359
|
],
|
|
11572
11360
|
notes: [
|
|
11573
|
-
"A project can be served on several hosts; each is verified on its own.",
|
|
11361
|
+
"A project can be served on several hosts; each is verified on its own, and each serves the project unless it redirects.",
|
|
11574
11362
|
"A CNAME is invalid at a zone apex: use an A record there and a CNAME below it.",
|
|
11575
11363
|
"`list` prints the exact records to add — copy them rather than deriving them."
|
|
11576
11364
|
]
|
|
@@ -11779,7 +11567,7 @@ function printExtensionsHelp() {
|
|
|
11779
11567
|
* `rebase cloud settings` — a project's editable configuration.
|
|
11780
11568
|
*
|
|
11781
11569
|
* settings Show the current settings
|
|
11782
|
-
* settings set [flags] Update name / branch / repo / subdomain / platform rebuilds
|
|
11570
|
+
* settings set [flags] Update name / branch / repo / subdomain / platform rebuilds / Studio access
|
|
11783
11571
|
*
|
|
11784
11572
|
* These are plain `projects` updates. A subdomain change is validated against
|
|
11785
11573
|
* `check-subdomain` up front so the CLI fails with the real reason rather than a
|
|
@@ -11827,7 +11615,8 @@ async function showSettings(rawArgs) {
|
|
|
11827
11615
|
["Custom domain", p.customDomain],
|
|
11828
11616
|
["Provider", p.provider],
|
|
11829
11617
|
["Region", p.region],
|
|
11830
|
-
["Platform rebuilds", p.platformRebuilds === false ? "off" : "on"]
|
|
11618
|
+
["Platform rebuilds", p.platformRebuilds === false ? "off" : "on"],
|
|
11619
|
+
["Studio access", p.studioEnabled === false ? "off" : "on"]
|
|
11831
11620
|
]);
|
|
11832
11621
|
console.log("");
|
|
11833
11622
|
}, {
|
|
@@ -11839,7 +11628,8 @@ async function showSettings(rawArgs) {
|
|
|
11839
11628
|
customDomain: p.customDomain ?? null,
|
|
11840
11629
|
provider: p.provider ?? null,
|
|
11841
11630
|
region: p.region ?? null,
|
|
11842
|
-
platformRebuilds: p.platformRebuilds !== false
|
|
11631
|
+
platformRebuilds: p.platformRebuilds !== false,
|
|
11632
|
+
studioEnabled: p.studioEnabled !== false
|
|
11843
11633
|
});
|
|
11844
11634
|
} catch (e) {
|
|
11845
11635
|
reportError(e, "Failed to load settings");
|
|
@@ -11860,6 +11650,7 @@ function buildSettingsPatch(args) {
|
|
|
11860
11650
|
if (args.repo !== void 0) patch.gitRepoUrl = args.repo;
|
|
11861
11651
|
if (args.branch !== void 0) patch.gitBranch = args.branch;
|
|
11862
11652
|
if (args.platformRebuilds !== void 0) patch.platformRebuilds = args.platformRebuilds;
|
|
11653
|
+
if (args.studio !== void 0) patch.studioEnabled = args.studio;
|
|
11863
11654
|
return patch;
|
|
11864
11655
|
}
|
|
11865
11656
|
/** What `rebase cloud settings set` parses. Its page is the group's own. */
|
|
@@ -11868,7 +11659,8 @@ var SET_SETTINGS_FLAGS = {
|
|
|
11868
11659
|
"--subdomain": String,
|
|
11869
11660
|
"--repo": String,
|
|
11870
11661
|
"--branch": String,
|
|
11871
|
-
"--platform-rebuilds": String
|
|
11662
|
+
"--platform-rebuilds": String,
|
|
11663
|
+
"--studio": String
|
|
11872
11664
|
};
|
|
11873
11665
|
async function setSettings(rawArgs) {
|
|
11874
11666
|
const { flags: args } = parseCloudArgs({
|
|
@@ -11887,14 +11679,33 @@ async function setSettings(rawArgs) {
|
|
|
11887
11679
|
if (parsed === null) fail(`--platform-rebuilds takes on or off (got "${args["--platform-rebuilds"]}").`, void 0, "usage");
|
|
11888
11680
|
platformRebuilds = parsed;
|
|
11889
11681
|
}
|
|
11682
|
+
let studio;
|
|
11683
|
+
if (args["--studio"] !== void 0) {
|
|
11684
|
+
const parsed = parseOnOff(args["--studio"]);
|
|
11685
|
+
if (parsed === null) fail(`--studio takes on or off (got "${args["--studio"]}").`, void 0, "usage");
|
|
11686
|
+
studio = parsed;
|
|
11687
|
+
}
|
|
11890
11688
|
const patch = buildSettingsPatch({
|
|
11891
11689
|
name: args["--name"],
|
|
11892
11690
|
subdomain: args["--subdomain"],
|
|
11893
11691
|
repo: args["--repo"],
|
|
11894
11692
|
branch: args["--branch"],
|
|
11895
|
-
platformRebuilds
|
|
11693
|
+
platformRebuilds,
|
|
11694
|
+
studio
|
|
11896
11695
|
});
|
|
11897
|
-
if (Object.keys(patch).length === 0) fail("Nothing to update.", "Pass --name, --subdomain, --repo, --branch,
|
|
11696
|
+
if (Object.keys(patch).length === 0) fail("Nothing to update.", "Pass --name, --subdomain, --repo, --branch, --platform-rebuilds or --studio.", "usage");
|
|
11697
|
+
if (typeof patch.subdomain === "string" && patch.subdomain) {
|
|
11698
|
+
let current;
|
|
11699
|
+
try {
|
|
11700
|
+
current = (await client.data.table("projects").findById(projectId))?.subdomain;
|
|
11701
|
+
} catch (e) {
|
|
11702
|
+
reportError(e, "Failed to load settings");
|
|
11703
|
+
}
|
|
11704
|
+
if (current?.toLowerCase() !== patch.subdomain) await confirmDestructive({
|
|
11705
|
+
yes: Boolean(args["--yes"]),
|
|
11706
|
+
prompt: `Move project ${projectRef} from ${current ?? "its subdomain"} to ${patch.subdomain}? The old address stops answering, and anything that calls it breaks.`
|
|
11707
|
+
});
|
|
11708
|
+
}
|
|
11898
11709
|
try {
|
|
11899
11710
|
if (typeof patch.subdomain === "string" && patch.subdomain) {
|
|
11900
11711
|
const check = await client.functions.invoke("check-subdomain", { subdomain: patch.subdomain }).catch(() => void 0);
|
|
@@ -11916,7 +11727,7 @@ function printSettingsHelp() {
|
|
|
11916
11727
|
title: "Project configuration",
|
|
11917
11728
|
actions: [{
|
|
11918
11729
|
action: "show",
|
|
11919
|
-
description: "Name, subdomain, repository, branch
|
|
11730
|
+
description: "Name, subdomain, repository, branch, platform rebuilds and Studio access as recorded"
|
|
11920
11731
|
}, {
|
|
11921
11732
|
action: "set",
|
|
11922
11733
|
description: "Change one or more of them",
|
|
@@ -11925,9 +11736,11 @@ function printSettingsHelp() {
|
|
|
11925
11736
|
["--subdomain <sub>", "The <slug>.rebase.website host"],
|
|
11926
11737
|
["--repo <git url>", "Repository to build from"],
|
|
11927
11738
|
["--branch <branch>", "Branch to build"],
|
|
11928
|
-
["--platform-rebuilds <on|off>", "Rebuild this app on new framework releases (default on)"]
|
|
11739
|
+
["--platform-rebuilds <on|off>", "Rebuild this app on new framework releases (default on)"],
|
|
11740
|
+
["--studio <on|off>", "Let the console's Studio reach this project's API with admin rights (default on). Owners and admins"]
|
|
11929
11741
|
]
|
|
11930
|
-
}]
|
|
11742
|
+
}],
|
|
11743
|
+
notes: ["A new --subdomain moves the project's address, so it asks first; --yes skips the question, and is required off a terminal.", "--studio and --platform-rebuilds are the organization's consent: only its owners and admins may change them."]
|
|
11931
11744
|
});
|
|
11932
11745
|
}
|
|
11933
11746
|
//#endregion
|
|
@@ -12733,6 +12546,11 @@ async function connectCommand(rawArgs) {
|
|
|
12733
12546
|
* projects undercounting requests, partial days) are printed with the numbers,
|
|
12734
12547
|
* and are in `--json` unchanged. Read-only; any member of the organization.
|
|
12735
12548
|
*/
|
|
12549
|
+
/** What `usage` says on a control plane that has no `usage` function yet. */
|
|
12550
|
+
var USAGE_UNSERVED = {
|
|
12551
|
+
what: "usage reports",
|
|
12552
|
+
hint: "`rebase cloud metrics --runtime` shows the requests and errors the app has counted since it started."
|
|
12553
|
+
};
|
|
12736
12554
|
var USAGE_FLAGS = { "--month": String };
|
|
12737
12555
|
var USAGE_ACTIONS = ["org"];
|
|
12738
12556
|
var MONTH_RE = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
@@ -12837,7 +12655,7 @@ async function usageCommand(rawArgs) {
|
|
|
12837
12655
|
try {
|
|
12838
12656
|
usage = await readOrgUsage(client, org, month);
|
|
12839
12657
|
} catch (e) {
|
|
12840
|
-
|
|
12658
|
+
reportCallError(e, "Failed to load usage", USAGE_UNSERVED);
|
|
12841
12659
|
}
|
|
12842
12660
|
emit(() => printOrg(usage), usage);
|
|
12843
12661
|
return;
|
|
@@ -12847,7 +12665,7 @@ async function usageCommand(rawArgs) {
|
|
|
12847
12665
|
try {
|
|
12848
12666
|
usage = await readProjectUsage(client, projectId, month);
|
|
12849
12667
|
} catch (e) {
|
|
12850
|
-
|
|
12668
|
+
reportCallError(e, "Failed to load usage", USAGE_UNSERVED);
|
|
12851
12669
|
}
|
|
12852
12670
|
emit(() => printProject(usage, `project ${displayProjectRef(rawArgs) || projectId}`), usage);
|
|
12853
12671
|
}
|
|
@@ -12872,6 +12690,11 @@ async function usageCommand(rawArgs) {
|
|
|
12872
12690
|
*
|
|
12873
12691
|
* @module
|
|
12874
12692
|
*/
|
|
12693
|
+
/** What `app-key` says on a control plane that has no `credentials` function yet. */
|
|
12694
|
+
var APP_KEY_UNSERVED = {
|
|
12695
|
+
what: "app keys",
|
|
12696
|
+
hint: "Nothing was changed. The app's own admin panel creates and revokes API keys meanwhile."
|
|
12697
|
+
};
|
|
12875
12698
|
var APP_KEY_FLAGS = {};
|
|
12876
12699
|
var APP_KEY_ACTIONS = ["rotate"];
|
|
12877
12700
|
function isRotated(value) {
|
|
@@ -12922,7 +12745,7 @@ async function appKeyCommand(rawArgs) {
|
|
|
12922
12745
|
try {
|
|
12923
12746
|
listed = await listKeys(client, projectId);
|
|
12924
12747
|
} catch (e) {
|
|
12925
|
-
|
|
12748
|
+
reportCallError(e, "Failed to read the app's keys", APP_KEY_UNSERVED);
|
|
12926
12749
|
}
|
|
12927
12750
|
emit(() => printKeys(listed.keys, label), listed);
|
|
12928
12751
|
return;
|
|
@@ -12935,7 +12758,7 @@ async function appKeyCommand(rawArgs) {
|
|
|
12935
12758
|
try {
|
|
12936
12759
|
answer = await rotateKey(client, projectId);
|
|
12937
12760
|
} catch (e) {
|
|
12938
|
-
|
|
12761
|
+
reportCallError(e, "Failed to rotate the app key", APP_KEY_UNSERVED);
|
|
12939
12762
|
}
|
|
12940
12763
|
if (!isRotated(answer)) reportError(/* @__PURE__ */ new Error("The control plane's answer did not carry a key."), "Failed to rotate the app key");
|
|
12941
12764
|
const rotated = answer;
|
|
@@ -12966,87 +12789,6 @@ async function appKeyCommand(rawArgs) {
|
|
|
12966
12789
|
});
|
|
12967
12790
|
}
|
|
12968
12791
|
//#endregion
|
|
12969
|
-
//#region src/commands/cloud/service-key.ts
|
|
12970
|
-
/**
|
|
12971
|
-
* `rebase cloud service-key [rotate]`: the project's `REBASE_SERVICE_KEY`,
|
|
12972
|
-
* admin on the app's own API, and replacing it.
|
|
12973
|
-
*
|
|
12974
|
-
* The control plane derives the key from the project and a generation, and
|
|
12975
|
-
* injects it into the app. `rotate` issues the next generation and restarts
|
|
12976
|
-
* the app onto it in the background; the old key keeps working until that
|
|
12977
|
-
* restart has come up, and nothing after. Anything that copied the old key —
|
|
12978
|
-
* a script, a CI job, an agent's deployed code that printed it — is refused
|
|
12979
|
-
* from then on. A claim rotates it too.
|
|
12980
|
-
*
|
|
12981
|
-
* Without an action, prints the generation, when it was last rotated and
|
|
12982
|
-
* whether a rotation is still restarting the app. The key itself is
|
|
12983
|
-
* `rebase cloud env reveal REBASE_SERVICE_KEY`. Calls `GET` and `POST
|
|
12984
|
-
* /credentials/:projectId/service-key[/rotate]`, owners and admins, signed in.
|
|
12985
|
-
*
|
|
12986
|
-
* @module
|
|
12987
|
-
*/
|
|
12988
|
-
var SERVICE_KEY_FLAGS = {};
|
|
12989
|
-
var SERVICE_KEY_ACTIONS = ["rotate"];
|
|
12990
|
-
async function readStatus(client, projectId) {
|
|
12991
|
-
return client.functions.invoke("credentials", void 0, {
|
|
12992
|
-
method: "GET",
|
|
12993
|
-
path: `${encodeURIComponent(projectId)}/service-key`
|
|
12994
|
-
});
|
|
12995
|
-
}
|
|
12996
|
-
function printStatus(status, label) {
|
|
12997
|
-
console.log("");
|
|
12998
|
-
console.log(chalk.bold(` 🛡 Service key — ${label}`));
|
|
12999
|
-
console.log("");
|
|
13000
|
-
console.log(` Generation ${status.generation}`);
|
|
13001
|
-
console.log(` Rotated ${status.rotatedAt ? new Date(status.rotatedAt).toLocaleString() : chalk.gray("never")}`);
|
|
13002
|
-
if (status.pending) {
|
|
13003
|
-
console.log("");
|
|
13004
|
-
console.log(chalk.yellow(" The app has not restarted onto the newest key yet; the previous one still works until it has."));
|
|
13005
|
-
}
|
|
13006
|
-
console.log("");
|
|
13007
|
-
console.log(chalk.gray(` Read it with ${chalk.bold("rebase cloud env reveal REBASE_SERVICE_KEY")}; replace it with ${chalk.bold("rebase cloud service-key rotate")}.`));
|
|
13008
|
-
console.log("");
|
|
13009
|
-
}
|
|
13010
|
-
async function serviceKeyCommand(rawArgs) {
|
|
13011
|
-
const parsed = parseCloudArgs({
|
|
13012
|
-
spec: SERVICE_KEY_FLAGS,
|
|
13013
|
-
rawArgs,
|
|
13014
|
-
commandWords: 2,
|
|
13015
|
-
command: "cloud service-key",
|
|
13016
|
-
maxPositionals: 1
|
|
13017
|
-
});
|
|
13018
|
-
const action = parsed.positionals[0];
|
|
13019
|
-
requireKnownAction("service-key", action, SERVICE_KEY_ACTIONS);
|
|
13020
|
-
const { client } = await requireSessionClient(rawArgs, "rotate a project's service key");
|
|
13021
|
-
const projectId = await requireProject(rawArgs, client);
|
|
13022
|
-
const label = `project ${displayProjectRef(rawArgs) || projectId}`;
|
|
13023
|
-
if (action !== "rotate") {
|
|
13024
|
-
let status;
|
|
13025
|
-
try {
|
|
13026
|
-
status = await readStatus(client, projectId);
|
|
13027
|
-
} catch (e) {
|
|
13028
|
-
reportError(e, "Failed to read the service key's state");
|
|
13029
|
-
}
|
|
13030
|
-
emit(() => printStatus(status, label), status);
|
|
13031
|
-
return;
|
|
13032
|
-
}
|
|
13033
|
-
await confirmDestructive({
|
|
13034
|
-
yes: Boolean(parsed.flags["--yes"]),
|
|
13035
|
-
prompt: `Rotate the service key of ${label}? The app restarts onto a new key, and anything using the old one is refused once it has.`
|
|
13036
|
-
});
|
|
13037
|
-
let rotation;
|
|
13038
|
-
try {
|
|
13039
|
-
rotation = await client.functions.invoke("credentials", {}, { path: `${encodeURIComponent(projectId)}/service-key/rotate` });
|
|
13040
|
-
} catch (e) {
|
|
13041
|
-
reportError(e, "Failed to rotate the service key");
|
|
13042
|
-
}
|
|
13043
|
-
emit(() => {
|
|
13044
|
-
success(`Issued service key generation ${rotation.generation} for ${label}.`);
|
|
13045
|
-
note(rotation.state === "pending" ? "A deploy is running: the next deploy carries the new key. The old one works until then." : "The app is restarting onto it; the old key works until the restart has finished. Follow it with `rebase cloud service-key`.");
|
|
13046
|
-
note("Read the new key with `rebase cloud env reveal REBASE_SERVICE_KEY` once the restart is done.");
|
|
13047
|
-
}, rotation);
|
|
13048
|
-
}
|
|
13049
|
-
//#endregion
|
|
13050
12792
|
//#region src/commands/cloud/guests.ts
|
|
13051
12793
|
/**
|
|
13052
12794
|
* `rebase cloud guests [delete <id> | prune --older-than <age>]`: the guest
|
|
@@ -13102,20 +12844,19 @@ function lastSeenBeforeOf(value) {
|
|
|
13102
12844
|
if (ms === void 0) fail(`--older-than takes an age with a unit, e.g. 30d, 12h or 2w (got "${value}").`, void 0, "usage");
|
|
13103
12845
|
return new Date(Date.now() - ms);
|
|
13104
12846
|
}
|
|
13105
|
-
/**
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
}
|
|
12847
|
+
/**
|
|
12848
|
+
* The project's own API, through the console's Studio proxy: the control
|
|
12849
|
+
* plane attaches the app's service key on its own side, so no static secret
|
|
12850
|
+
* reaches this machine. (This used to reveal `REBASE_SERVICE_KEY` into the
|
|
12851
|
+
* CLI's memory, which is the thing `docs/platform-tokens.md` exists to avoid.)
|
|
12852
|
+
* It answers an organization owner or admin, on a project whose Studio switch
|
|
12853
|
+
* is on.
|
|
12854
|
+
*/
|
|
12855
|
+
async function connectToApp(client, url, projectId) {
|
|
12856
|
+
const token = await freshAccessToken(client);
|
|
13116
12857
|
return createRebaseClient({
|
|
13117
|
-
baseUrl:
|
|
13118
|
-
token
|
|
12858
|
+
baseUrl: `${url.replace(/\/+$/, "")}/api/functions/studio/${encodeURIComponent(projectId)}/proxy`,
|
|
12859
|
+
token,
|
|
13119
12860
|
realtime: false,
|
|
13120
12861
|
headers: { "User-Agent": cliUserAgent() },
|
|
13121
12862
|
auth: {
|
|
@@ -13131,6 +12872,7 @@ async function connectToApp(client, origin, projectId) {
|
|
|
13131
12872
|
*/
|
|
13132
12873
|
function reportAppError(error, action, origin) {
|
|
13133
12874
|
if (error instanceof RebaseApiError) {
|
|
12875
|
+
if (error.status === 403 && /Studio access is switched off/i.test(error.message)) fail("Studio access is switched off for this project, and `cloud guests` reaches the app through the console's Studio proxy.", "An organization owner or admin can turn it on: `rebase cloud settings set --studio on`.", "studio_disabled");
|
|
13134
12876
|
if (error.status === 404 && isMissingRoute(error.message)) fail(`The app at ${origin} needs a newer runtime: it has no guest routes yet.`, "`rebase cloud status` shows the runtime it is on.", "runtime_too_old");
|
|
13135
12877
|
if (error.status === 501) fail(`The app at ${origin} cannot manage guests: ${error.message}`, void 0, "not_supported");
|
|
13136
12878
|
if (error.status === 0 || error.code === "NETWORK_ERROR") fail(`Could not reach the app at ${origin}: ${error.message}`, "`rebase cloud debug health` checks whether the deployment is answering at all.", "runtime_unreachable");
|
|
@@ -13227,7 +12969,7 @@ async function guestsCommand(rawArgs) {
|
|
|
13227
12969
|
prompt: `Delete guest ${id} from ${label}? Its sessions end, and whatever the project's own tables cascade from it goes too.`
|
|
13228
12970
|
});
|
|
13229
12971
|
const origin = await resolveOrigin(rawArgs, client, url, projectId);
|
|
13230
|
-
const app = await connectToApp(client,
|
|
12972
|
+
const app = await connectToApp(client, url, projectId);
|
|
13231
12973
|
try {
|
|
13232
12974
|
if (action === "delete") emit(() => success(`Deleted guest ${id} from ${label}.`), await app.admin.deleteGuest(id));
|
|
13233
12975
|
else if (action === "prune" && age && lastSeenBefore) await prune(app, age, lastSeenBefore, Boolean(flags["--yes"]), label);
|
|
@@ -13257,6 +12999,11 @@ async function guestsCommand(rawArgs) {
|
|
|
13257
12999
|
* `--json` is one value: `{ org, events, nextCursor }`, each event exactly as
|
|
13258
13000
|
* the control plane sends it.
|
|
13259
13001
|
*/
|
|
13002
|
+
/** What `activity` says on a control plane that has no `audit` function yet. */
|
|
13003
|
+
var AUDIT_UNSERVED = {
|
|
13004
|
+
what: "the activity log",
|
|
13005
|
+
hint: "`rebase cloud deployments` lists each project's deploys, with who triggered them."
|
|
13006
|
+
};
|
|
13260
13007
|
var ACTIVITY_FLAGS = {
|
|
13261
13008
|
"--org": String,
|
|
13262
13009
|
"--action": String,
|
|
@@ -13348,7 +13095,7 @@ async function activityCommand(rawArgs) {
|
|
|
13348
13095
|
path: `org/${encodeURIComponent(org)}${query ? `?${query}` : ""}`
|
|
13349
13096
|
});
|
|
13350
13097
|
} catch (e) {
|
|
13351
|
-
|
|
13098
|
+
reportCallError(e, "Failed to load the activity log", AUDIT_UNSERVED);
|
|
13352
13099
|
}
|
|
13353
13100
|
const events = res.events ?? [];
|
|
13354
13101
|
const nextCursor = res.nextCursor ?? null;
|
|
@@ -13379,6 +13126,11 @@ async function activityCommand(rawArgs) {
|
|
|
13379
13126
|
* every delivery. Each POST is signed: `X-Webhook-Signature: sha256=<hex HMAC
|
|
13380
13127
|
* of the body>` with the secret `add` prints once.
|
|
13381
13128
|
*/
|
|
13129
|
+
/** What `notifications` says on a control plane that has no `notifications` function yet. */
|
|
13130
|
+
var NOTIFICATIONS_UNSERVED = {
|
|
13131
|
+
what: "notification webhooks",
|
|
13132
|
+
hint: "Nothing was changed. `rebase cloud alerts` lists what the platform has seen go wrong with the project."
|
|
13133
|
+
};
|
|
13382
13134
|
/** The events the control plane notifies about. */
|
|
13383
13135
|
var NOTIFICATION_EVENTS = [
|
|
13384
13136
|
"deploy.failed",
|
|
@@ -13454,7 +13206,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13454
13206
|
...flags["--name"] ? { name: flags["--name"] } : {}
|
|
13455
13207
|
}, { path: "webhooks" });
|
|
13456
13208
|
} catch (e) {
|
|
13457
|
-
|
|
13209
|
+
reportCallError(e, "Failed to add the notification webhook", NOTIFICATIONS_UNSERVED);
|
|
13458
13210
|
}
|
|
13459
13211
|
emit(() => {
|
|
13460
13212
|
success(`Notifications for ${events.join(", ")} now go to ${chalk.bold(created.webhook.url)} [${created.webhook.id}]`);
|
|
@@ -13491,7 +13243,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13491
13243
|
path: `webhooks/${encodeURIComponent(id)}`
|
|
13492
13244
|
});
|
|
13493
13245
|
} catch (e) {
|
|
13494
|
-
|
|
13246
|
+
reportCallError(e, "Failed to remove the notification webhook", NOTIFICATIONS_UNSERVED);
|
|
13495
13247
|
}
|
|
13496
13248
|
success(`Notification webhook ${chalk.bold(id)} removed`);
|
|
13497
13249
|
emit(() => {}, {
|
|
@@ -13504,7 +13256,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13504
13256
|
try {
|
|
13505
13257
|
result = await client.functions.invoke("notifications", {}, { path: `webhooks/${encodeURIComponent(id)}/test` });
|
|
13506
13258
|
} catch (e) {
|
|
13507
|
-
|
|
13259
|
+
reportCallError(e, "Failed to send the test event", NOTIFICATIONS_UNSERVED);
|
|
13508
13260
|
}
|
|
13509
13261
|
if (!result.success) fail(`The test event was not delivered: ${result.statusCode ? `HTTP ${result.statusCode}` : "no response"}.`, result.error || void 0, "delivery_failed");
|
|
13510
13262
|
success(`Test event delivered (HTTP ${result.statusCode})`);
|
|
@@ -13527,7 +13279,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13527
13279
|
try {
|
|
13528
13280
|
webhooks = await listWebhooks(client, projectId);
|
|
13529
13281
|
} catch (e) {
|
|
13530
|
-
|
|
13282
|
+
reportCallError(e, "Failed to list notification webhooks", NOTIFICATIONS_UNSERVED);
|
|
13531
13283
|
}
|
|
13532
13284
|
emit(() => {
|
|
13533
13285
|
console.log("");
|
|
@@ -13552,6 +13304,312 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13552
13304
|
});
|
|
13553
13305
|
}
|
|
13554
13306
|
//#endregion
|
|
13307
|
+
//#region src/commands/cloud/deploy-hooks.ts
|
|
13308
|
+
/**
|
|
13309
|
+
* `rebase cloud deploy-hooks` — URLs that start a build of the project's
|
|
13310
|
+
* connected repository when something POSTs to them: a git host's webhook, a
|
|
13311
|
+
* CMS's publish button, a CI step.
|
|
13312
|
+
*
|
|
13313
|
+
* deploy-hooks [list] The project's hooks: name, branch, last used
|
|
13314
|
+
* deploy-hooks create [--name] [--branch] Mint one, and print its URL once
|
|
13315
|
+
* deploy-hooks revoke <id> Delete one; its URL stops working
|
|
13316
|
+
*
|
|
13317
|
+
* The control plane's `deploy` function serves them (`/hooks`), the same routes
|
|
13318
|
+
* the console's Settings use. The URL carries the hook's token, which is the
|
|
13319
|
+
* whole credential: the control plane keeps only its hash, so the URL is shown
|
|
13320
|
+
* once, at `create`, and never again.
|
|
13321
|
+
*/
|
|
13322
|
+
/** The action words `rebase cloud deploy-hooks` dispatches. No word means `list`. */
|
|
13323
|
+
var DEPLOY_HOOKS_ACTIONS = [
|
|
13324
|
+
"list",
|
|
13325
|
+
"create",
|
|
13326
|
+
"revoke"
|
|
13327
|
+
];
|
|
13328
|
+
/** What `deploy-hooks` parses. `--name` and `--branch` belong to `create`. */
|
|
13329
|
+
var DEPLOY_HOOKS_FLAGS = {
|
|
13330
|
+
"--name": String,
|
|
13331
|
+
"--branch": String
|
|
13332
|
+
};
|
|
13333
|
+
/** The control plane's `deploy` function, where the hooks routes live. */
|
|
13334
|
+
var DEPLOY_FUNCTION = "deploy";
|
|
13335
|
+
function text(value) {
|
|
13336
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
13337
|
+
}
|
|
13338
|
+
/** One hook from the wire, or null for one with no id. */
|
|
13339
|
+
function readHook(value) {
|
|
13340
|
+
if (typeof value !== "object" || value === null) return null;
|
|
13341
|
+
const id = "id" in value ? value.id : void 0;
|
|
13342
|
+
if (typeof id !== "string" && typeof id !== "number") return null;
|
|
13343
|
+
return {
|
|
13344
|
+
id: String(id),
|
|
13345
|
+
name: ("name" in value ? text(value.name) : null) ?? "Deploy hook",
|
|
13346
|
+
branch: ("branch" in value ? text(value.branch) : null) ?? "",
|
|
13347
|
+
createdAt: "createdAt" in value ? text(value.createdAt) : null,
|
|
13348
|
+
lastUsedAt: "lastUsedAt" in value ? text(value.lastUsedAt) : null
|
|
13349
|
+
};
|
|
13350
|
+
}
|
|
13351
|
+
async function listHooks(client, projectId) {
|
|
13352
|
+
return ((await client.functions.invoke(DEPLOY_FUNCTION, void 0, {
|
|
13353
|
+
method: "GET",
|
|
13354
|
+
path: `hooks?projectId=${encodeURIComponent(projectId)}`
|
|
13355
|
+
})).hooks ?? []).map(readHook).filter((h) => h !== null);
|
|
13356
|
+
}
|
|
13357
|
+
async function deployHooksCommand(action, rawArgs) {
|
|
13358
|
+
const { flags, positionals } = parseCloudArgs({
|
|
13359
|
+
spec: DEPLOY_HOOKS_FLAGS,
|
|
13360
|
+
rawArgs,
|
|
13361
|
+
commandWords: 2,
|
|
13362
|
+
command: "cloud deploy-hooks",
|
|
13363
|
+
maxPositionals: 2
|
|
13364
|
+
});
|
|
13365
|
+
const word = positionals[0] ?? action;
|
|
13366
|
+
requireKnownAction("deploy-hooks", word, DEPLOY_HOOKS_ACTIONS);
|
|
13367
|
+
const verb = word ?? "list";
|
|
13368
|
+
const id = positionals[1];
|
|
13369
|
+
if (verb !== "create" && (flags["--name"] !== void 0 || flags["--branch"] !== void 0)) fail("--name and --branch go with `deploy-hooks create`.", "Run `rebase cloud deploy-hooks --help`.", "usage");
|
|
13370
|
+
if (verb !== "revoke" && id !== void 0) fail(`Too many arguments for \`deploy-hooks ${verb}\`: ${id}`, "Run `rebase cloud deploy-hooks --help`.", "usage");
|
|
13371
|
+
if (verb === "revoke" && !id) fail("Name the hook to revoke.", "`rebase cloud deploy-hooks` lists them with their ids.", "usage");
|
|
13372
|
+
const { client, url } = await requireClient(rawArgs);
|
|
13373
|
+
const projectId = await requireProject(rawArgs, client);
|
|
13374
|
+
const label = `project ${displayProjectRef(rawArgs) || projectId}`;
|
|
13375
|
+
if (verb === "create") return createHook(client, url, projectId, label, flags["--name"], flags["--branch"]);
|
|
13376
|
+
if (verb === "revoke") return revokeHook(client, projectId, label, id, flags["--yes"] === true);
|
|
13377
|
+
let hooks;
|
|
13378
|
+
try {
|
|
13379
|
+
hooks = await listHooks(client, projectId);
|
|
13380
|
+
} catch (e) {
|
|
13381
|
+
reportError(e, "Failed to list deploy hooks");
|
|
13382
|
+
}
|
|
13383
|
+
emit(() => {
|
|
13384
|
+
console.log("");
|
|
13385
|
+
console.log(chalk.bold(` 🪝 Deploy hooks — ${label}`));
|
|
13386
|
+
console.log("");
|
|
13387
|
+
if (hooks.length === 0) {
|
|
13388
|
+
console.log(chalk.gray(" None. Mint one with `rebase cloud deploy-hooks create`."));
|
|
13389
|
+
console.log("");
|
|
13390
|
+
return;
|
|
13391
|
+
}
|
|
13392
|
+
for (const h of hooks) {
|
|
13393
|
+
const used = h.lastUsedAt ? `last used ${new Date(h.lastUsedAt).toLocaleString()}` : "never used";
|
|
13394
|
+
console.log(` ${chalk.bold(h.name)} ${chalk.gray(`[${h.id}]`)} ${h.branch || chalk.gray("project branch")} ${chalk.gray(used)}`);
|
|
13395
|
+
}
|
|
13396
|
+
console.log("");
|
|
13397
|
+
note(chalk.gray("A hook's URL is shown only when it is created. Lost one? Revoke it and create another."));
|
|
13398
|
+
console.log("");
|
|
13399
|
+
}, {
|
|
13400
|
+
projectId,
|
|
13401
|
+
hooks
|
|
13402
|
+
});
|
|
13403
|
+
}
|
|
13404
|
+
async function createHook(client, url, projectId, label, name, branch) {
|
|
13405
|
+
const body = { projectId };
|
|
13406
|
+
if (name?.trim()) body.name = name.trim();
|
|
13407
|
+
if (branch?.trim()) body.branch = branch.trim();
|
|
13408
|
+
let res;
|
|
13409
|
+
try {
|
|
13410
|
+
res = await client.functions.invoke(DEPLOY_FUNCTION, body, { path: "hooks" });
|
|
13411
|
+
} catch (e) {
|
|
13412
|
+
reportError(e, "Failed to create the deploy hook");
|
|
13413
|
+
}
|
|
13414
|
+
const hook = readHook(res.hook);
|
|
13415
|
+
if (!hook || typeof res.token !== "string" || typeof res.path !== "string") fail("The control plane created a hook but did not return its URL.", "Revoke it with `rebase cloud deploy-hooks revoke <id>` and try again.");
|
|
13416
|
+
const hookUrl = `${url}${res.path.startsWith("/") ? "" : "/"}${res.path}`;
|
|
13417
|
+
emit(() => {
|
|
13418
|
+
success(`Created deploy hook ${chalk.bold(hook.name)} for ${label}.`);
|
|
13419
|
+
keyValues([["Id", hook.id], ["Builds", hook.branch || "the project's configured branch"]]);
|
|
13420
|
+
console.log("");
|
|
13421
|
+
console.log(` ${chalk.cyan(hookUrl)}`);
|
|
13422
|
+
console.log("");
|
|
13423
|
+
note(chalk.gray("Shown once: the URL is the credential, and the control plane keeps only its hash."));
|
|
13424
|
+
note(chalk.gray("POST to it to build and ship the connected repository. A push to another branch, or a tag, is ignored."));
|
|
13425
|
+
console.log("");
|
|
13426
|
+
}, {
|
|
13427
|
+
projectId,
|
|
13428
|
+
hook,
|
|
13429
|
+
url: hookUrl,
|
|
13430
|
+
token: res.token
|
|
13431
|
+
});
|
|
13432
|
+
}
|
|
13433
|
+
async function revokeHook(client, projectId, label, id, yes) {
|
|
13434
|
+
let hooks;
|
|
13435
|
+
try {
|
|
13436
|
+
hooks = await listHooks(client, projectId);
|
|
13437
|
+
} catch (e) {
|
|
13438
|
+
reportError(e, "Failed to list deploy hooks");
|
|
13439
|
+
}
|
|
13440
|
+
const hook = hooks.find((h) => h.id === id);
|
|
13441
|
+
if (!hook) fail(`${label} has no deploy hook ${id}.`, "`rebase cloud deploy-hooks` lists them with their ids.", "not_found");
|
|
13442
|
+
await confirmDestructive({
|
|
13443
|
+
yes,
|
|
13444
|
+
prompt: `Revoke deploy hook "${hook.name}" (${hook.id}) of ${label}? Anything that POSTs to its URL is refused from then on.`
|
|
13445
|
+
});
|
|
13446
|
+
try {
|
|
13447
|
+
await client.functions.invoke(DEPLOY_FUNCTION, void 0, {
|
|
13448
|
+
method: "DELETE",
|
|
13449
|
+
path: `hooks/${encodeURIComponent(id)}`
|
|
13450
|
+
});
|
|
13451
|
+
} catch (e) {
|
|
13452
|
+
reportError(e, "Failed to revoke the deploy hook");
|
|
13453
|
+
}
|
|
13454
|
+
emit(() => success(`Revoked deploy hook ${hook.name}; its URL no longer works.`), {
|
|
13455
|
+
projectId,
|
|
13456
|
+
revoked: hook
|
|
13457
|
+
});
|
|
13458
|
+
}
|
|
13459
|
+
//#endregion
|
|
13460
|
+
//#region src/commands/cloud/alerts.ts
|
|
13461
|
+
/**
|
|
13462
|
+
* `rebase cloud alerts` — the problems the platform has seen with a project,
|
|
13463
|
+
* and acknowledging or snoozing them.
|
|
13464
|
+
*
|
|
13465
|
+
* alerts [list] [--all] Open alerts, newest first; --all adds the resolved ones
|
|
13466
|
+
* alerts ack <incidentId> Acknowledge: reminders stop for everyone
|
|
13467
|
+
* alerts snooze <incidentId> --hours <n> Nobody is emailed about it for n hours
|
|
13468
|
+
*
|
|
13469
|
+
* Two doors, as in the console. Incidents are read through the data API
|
|
13470
|
+
* (`alert-incidents`), where the control plane's row-level security shows the
|
|
13471
|
+
* caller its own organizations' and nothing else. Acknowledging and snoozing go
|
|
13472
|
+
* through its `alerts` function, which checks the caller's role first: RLS
|
|
13473
|
+
* gates rows, not columns, and a member allowed to update an incident could
|
|
13474
|
+
* rewrite its severity too.
|
|
13475
|
+
*/
|
|
13476
|
+
/** The action words `rebase cloud alerts` dispatches. No word means `list`. */
|
|
13477
|
+
var ALERTS_ACTIONS = [
|
|
13478
|
+
"list",
|
|
13479
|
+
"ack",
|
|
13480
|
+
"snooze"
|
|
13481
|
+
];
|
|
13482
|
+
/** What `alerts` parses: `--all` for `list`, `--hours` for `snooze`. */
|
|
13483
|
+
var ALERTS_FLAGS = {
|
|
13484
|
+
"--all": Boolean,
|
|
13485
|
+
"--hours": String
|
|
13486
|
+
};
|
|
13487
|
+
function field(row, camel, snake) {
|
|
13488
|
+
const value = row[camel] ?? row[snake];
|
|
13489
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
13490
|
+
}
|
|
13491
|
+
/** One incident from the data API, or null for a row that is not one. */
|
|
13492
|
+
function readIncident(row) {
|
|
13493
|
+
const id = row.id;
|
|
13494
|
+
if (typeof id !== "string" && typeof id !== "number" || typeof row.rule !== "string") return null;
|
|
13495
|
+
return {
|
|
13496
|
+
id: String(id),
|
|
13497
|
+
rule: row.rule,
|
|
13498
|
+
title: typeof row.title === "string" && row.title ? row.title : row.rule,
|
|
13499
|
+
summary: typeof row.summary === "string" ? row.summary : "",
|
|
13500
|
+
severity: typeof row.severity === "string" ? row.severity : "info",
|
|
13501
|
+
state: typeof row.state === "string" ? row.state : "firing",
|
|
13502
|
+
category: typeof row.category === "string" ? row.category : null,
|
|
13503
|
+
openedAt: field(row, "openedAt", "opened_at"),
|
|
13504
|
+
lastSeenAt: field(row, "lastSeenAt", "last_seen_at"),
|
|
13505
|
+
resolvedAt: field(row, "resolvedAt", "resolved_at"),
|
|
13506
|
+
acknowledgedAt: field(row, "acknowledgedAt", "acknowledged_at"),
|
|
13507
|
+
snoozedUntil: field(row, "snoozedUntil", "snoozed_until")
|
|
13508
|
+
};
|
|
13509
|
+
}
|
|
13510
|
+
/** `--hours`, checked: a whole number from 1 to a week. */
|
|
13511
|
+
function resolveSnoozeHours(value) {
|
|
13512
|
+
if (value === void 0) fail("Say how long to snooze it for.", `Pass --hours <1-168>, e.g. --hours 24.`, "usage");
|
|
13513
|
+
const hours = Number(value);
|
|
13514
|
+
if (!Number.isInteger(hours) || hours < 1 || hours > 168) fail(`--hours takes a whole number from 1 to 168 (got "${value}").`, "A snooze lasts at most a week.", "usage");
|
|
13515
|
+
return hours;
|
|
13516
|
+
}
|
|
13517
|
+
var SEVERITY_MARK = {
|
|
13518
|
+
critical: chalk.red("●"),
|
|
13519
|
+
warning: chalk.yellow("●"),
|
|
13520
|
+
info: chalk.gray("●")
|
|
13521
|
+
};
|
|
13522
|
+
async function listIncidents(client, projectId, all) {
|
|
13523
|
+
return ((await client.data.table("alert-incidents").find({
|
|
13524
|
+
where: {
|
|
13525
|
+
project: ["==", projectId],
|
|
13526
|
+
state: all ? ["in", ["firing", "resolved"]] : ["==", "firing"]
|
|
13527
|
+
},
|
|
13528
|
+
orderBy: ["openedAt", "desc"],
|
|
13529
|
+
limit: 100
|
|
13530
|
+
})).data ?? []).map(readIncident).filter((i) => i !== null);
|
|
13531
|
+
}
|
|
13532
|
+
async function alertsCommand(action, rawArgs) {
|
|
13533
|
+
const { flags, positionals } = parseCloudArgs({
|
|
13534
|
+
spec: ALERTS_FLAGS,
|
|
13535
|
+
rawArgs,
|
|
13536
|
+
commandWords: 2,
|
|
13537
|
+
command: "cloud alerts",
|
|
13538
|
+
maxPositionals: 2
|
|
13539
|
+
});
|
|
13540
|
+
const word = positionals[0] ?? action;
|
|
13541
|
+
requireKnownAction("alerts", word, ALERTS_ACTIONS);
|
|
13542
|
+
const verb = word ?? "list";
|
|
13543
|
+
const incidentId = positionals[1];
|
|
13544
|
+
if (flags["--all"] && verb !== "list") fail("--all goes with `alerts list`.", "Run `rebase cloud alerts --help`.", "usage");
|
|
13545
|
+
if (flags["--hours"] !== void 0 && verb !== "snooze") fail("--hours goes with `alerts snooze`.", "Run `rebase cloud alerts --help`.", "usage");
|
|
13546
|
+
if (verb === "list" && incidentId !== void 0) fail(`Too many arguments for \`alerts list\`: ${incidentId}`, "Run `rebase cloud alerts --help`.", "usage");
|
|
13547
|
+
if (verb !== "list" && !incidentId) fail(`Name the alert to ${verb === "ack" ? "acknowledge" : "snooze"}.`, "`rebase cloud alerts` lists them with their ids.", "usage");
|
|
13548
|
+
const hours = verb === "snooze" ? resolveSnoozeHours(flags["--hours"]) : void 0;
|
|
13549
|
+
const { client } = await requireClient(rawArgs);
|
|
13550
|
+
if (verb === "ack") {
|
|
13551
|
+
try {
|
|
13552
|
+
await client.functions.invoke("alerts", {}, { path: `incidents/${encodeURIComponent(incidentId)}/acknowledge` });
|
|
13553
|
+
} catch (e) {
|
|
13554
|
+
reportError(e, "Failed to acknowledge the alert");
|
|
13555
|
+
}
|
|
13556
|
+
emit(() => success(`Acknowledged ${incidentId}. Reminders stop for everyone; you will still hear if it gets worse or is resolved.`), {
|
|
13557
|
+
id: incidentId,
|
|
13558
|
+
acknowledged: true
|
|
13559
|
+
});
|
|
13560
|
+
return;
|
|
13561
|
+
}
|
|
13562
|
+
if (verb === "snooze") {
|
|
13563
|
+
let res;
|
|
13564
|
+
try {
|
|
13565
|
+
res = await client.functions.invoke("alerts", { hours }, { path: `incidents/${encodeURIComponent(incidentId)}/snooze` });
|
|
13566
|
+
} catch (e) {
|
|
13567
|
+
reportError(e, "Failed to snooze the alert");
|
|
13568
|
+
}
|
|
13569
|
+
const until = res.snoozedUntil ?? null;
|
|
13570
|
+
emit(() => success(`Snoozed ${incidentId}${until ? ` until ${new Date(until).toLocaleString()}` : ` for ${hours} hours`}. Nobody is emailed about it until then, unless it is resolved.`), {
|
|
13571
|
+
id: incidentId,
|
|
13572
|
+
hours,
|
|
13573
|
+
snoozedUntil: until
|
|
13574
|
+
});
|
|
13575
|
+
return;
|
|
13576
|
+
}
|
|
13577
|
+
const projectId = await requireProject(rawArgs, client);
|
|
13578
|
+
const label = `project ${displayProjectRef(rawArgs) || projectId}`;
|
|
13579
|
+
const all = flags["--all"] === true;
|
|
13580
|
+
let incidents;
|
|
13581
|
+
try {
|
|
13582
|
+
incidents = await listIncidents(client, projectId, all);
|
|
13583
|
+
} catch (e) {
|
|
13584
|
+
reportError(e, "Failed to list alerts");
|
|
13585
|
+
}
|
|
13586
|
+
emit(() => {
|
|
13587
|
+
console.log("");
|
|
13588
|
+
console.log(chalk.bold(` 🚨 Alerts — ${label}`));
|
|
13589
|
+
console.log("");
|
|
13590
|
+
if (incidents.length === 0) {
|
|
13591
|
+
console.log(chalk.gray(all ? " Nothing has gone wrong." : " Nothing is open. `--all` shows the resolved ones too."));
|
|
13592
|
+
console.log("");
|
|
13593
|
+
return;
|
|
13594
|
+
}
|
|
13595
|
+
for (const i of incidents) {
|
|
13596
|
+
const when = i.openedAt ? new Date(i.openedAt).toLocaleString() : "";
|
|
13597
|
+
const state = i.state === "resolved" ? chalk.green("resolved") : chalk.red("open");
|
|
13598
|
+
const quiet = i.acknowledgedAt ? chalk.gray(" · acknowledged") : i.snoozedUntil && Date.parse(i.snoozedUntil) > Date.now() ? chalk.gray(` · snoozed until ${new Date(i.snoozedUntil).toLocaleString()}`) : "";
|
|
13599
|
+
console.log(` ${SEVERITY_MARK[i.severity] ?? SEVERITY_MARK.info} ${chalk.bold(i.title)} ${state}${quiet} ${chalk.gray(when)}`);
|
|
13600
|
+
if (i.summary) console.log(chalk.gray(` ${i.summary}`));
|
|
13601
|
+
console.log(chalk.gray(` ${i.id}`));
|
|
13602
|
+
}
|
|
13603
|
+
console.log("");
|
|
13604
|
+
note(chalk.gray("Acknowledge one with `rebase cloud alerts ack <id>`, or quiet it with `rebase cloud alerts snooze <id> --hours 24`."));
|
|
13605
|
+
console.log("");
|
|
13606
|
+
}, {
|
|
13607
|
+
projectId,
|
|
13608
|
+
all,
|
|
13609
|
+
incidents
|
|
13610
|
+
});
|
|
13611
|
+
}
|
|
13612
|
+
//#endregion
|
|
13555
13613
|
//#region src/commands/cloud/declared-resources.ts
|
|
13556
13614
|
/**
|
|
13557
13615
|
* `rebase cloud resources` — what a project declares against what the platform
|
|
@@ -13732,12 +13790,13 @@ var ACTION_HELP = {
|
|
|
13732
13790
|
},
|
|
13733
13791
|
clusters: {
|
|
13734
13792
|
command: "cloud clusters",
|
|
13735
|
-
usage: "cloud clusters [list|add|verify|registry] [options]",
|
|
13793
|
+
usage: "cloud clusters [list|add|verify|registry|baseline] [options]",
|
|
13736
13794
|
summary: "The compute clusters tenants run on. Platform-admin only.",
|
|
13737
13795
|
flags: [],
|
|
13738
13796
|
examples: [
|
|
13739
13797
|
"rebase cloud clusters",
|
|
13740
13798
|
"rebase cloud clusters verify <cluster-id> --baseline",
|
|
13799
|
+
"rebase cloud clusters baseline <cluster-id> --install",
|
|
13741
13800
|
"rebase cloud clusters add --name gke-eu --provider gcp --region europe-west1 --kubeconfig ./kubeconfig",
|
|
13742
13801
|
"rebase cloud clusters registry <cluster-id> --repository europe-west1-docker.pkg.dev/p/rlc-acme --push-service-account rlc-acme-push@p.iam.gserviceaccount.com --pull-key-file ./rlc-acme-pull.json"
|
|
13743
13802
|
]
|
|
@@ -13769,13 +13828,14 @@ var ACTION_HELP = {
|
|
|
13769
13828
|
],
|
|
13770
13829
|
examples: [
|
|
13771
13830
|
"rebase cloud projects create --name \"Shop\" --subdomain shop --link",
|
|
13772
|
-
"rebase cloud projects create --name Shop --subdomain shop --db none",
|
|
13773
|
-
"rebase cloud projects create --name Shop --subdomain shop --db byodb --connection-string \"$DATABASE_URL\""
|
|
13831
|
+
"rebase cloud projects create --name Shop --subdomain shop --db none --yes",
|
|
13832
|
+
"rebase cloud projects create --name Shop --subdomain shop --db byodb --connection-string \"$DATABASE_URL\" --yes"
|
|
13774
13833
|
],
|
|
13775
13834
|
notes: [
|
|
13776
13835
|
"The subdomain cannot be changed in passing later — a typo here is a new project.",
|
|
13777
13836
|
"A managed database is created at the project's FIRST DEPLOY, not here.",
|
|
13778
|
-
"--provider and --region are not a region picker. They record which of the control plane's registered deploy targets this project belongs to; the private beta has one, so both default to it and neither moves a project anywhere else."
|
|
13837
|
+
"--provider and --region are not a region picker. They record which of the control plane's registered deploy targets this project belongs to; the private beta has one, so both default to it and neither moves a project anywhere else.",
|
|
13838
|
+
"It asks before creating, because a project is billed once it runs. `--yes`, the global flag listed below, skips the question, and a script or agent must pass it: off a terminal the command refuses rather than assume."
|
|
13779
13839
|
]
|
|
13780
13840
|
},
|
|
13781
13841
|
"db create": {
|
|
@@ -13833,11 +13893,14 @@ var ACTION_HELP = {
|
|
|
13833
13893
|
["--allow-downgrade", "Deploy a bundle built on an older framework release than the project runs"],
|
|
13834
13894
|
["--preview", "Serve this build on an address of its own and leave production untouched"],
|
|
13835
13895
|
["--preview-name <name>", "Name the preview, so deploying the same name again updates the same address. Implies --preview"],
|
|
13836
|
-
["--eject", "Leave the managed runtime on purpose (ejects to a container image)"]
|
|
13896
|
+
["--eject", "Leave the managed runtime on purpose (ejects to a container image)"],
|
|
13897
|
+
["--git", "Have the control plane build the project's connected repository instead of this directory. The positional is then the branch"]
|
|
13837
13898
|
],
|
|
13838
13899
|
examples: [
|
|
13839
13900
|
"rebase cloud deploy",
|
|
13840
13901
|
"rebase cloud deploy web --message \"add search\"",
|
|
13902
|
+
"rebase cloud deploy --git",
|
|
13903
|
+
"rebase cloud deploy --git release-2026-11",
|
|
13841
13904
|
"rebase cloud deploy --preview",
|
|
13842
13905
|
"rebase cloud deploy --preview-name new-quiz",
|
|
13843
13906
|
"rebase cloud deploy --timeout 300 --json"
|
|
@@ -13854,7 +13917,8 @@ var ACTION_HELP = {
|
|
|
13854
13917
|
"--preview prints the preview's own address, https://<project>--<name>.rebase.website. A preview of the backend runs its own, on an empty database of its own, with its static apps folded in. It uploads no source and registers no apps or hostnames. `rebase cloud previews` lists and deletes previews.",
|
|
13855
13918
|
"A backend preview is billed while it exists; the deploy prints what it costs per month, as the control plane quotes it (`cost` under --json).",
|
|
13856
13919
|
"A static app previewed on its own (`cloud deploy <app> --preview`) needs a control plane that serves static sites by themselves. Rebase Cloud does not yet, and refuses it with PREVIEW_STATIC_UNSERVED; nothing is published.",
|
|
13857
|
-
"A control plane without previews refuses --preview with previews_unavailable, and nothing is deployed."
|
|
13920
|
+
"A control plane without previews refuses --preview with previews_unavailable, and nothing is deployed.",
|
|
13921
|
+
"--git uploads nothing: the control plane clones the repository connected in `rebase cloud settings`, at the branch named or the project's own, and the deploy is followed like any other. It is refused with no_git_repository when none is connected, beside any flag that describes a local build, and, on a project the managed runtime runs, without --eject (a source build leaves the managed runtime)."
|
|
13858
13922
|
]
|
|
13859
13923
|
},
|
|
13860
13924
|
previews: {
|
|
@@ -13888,7 +13952,7 @@ var ACTION_HELP = {
|
|
|
13888
13952
|
["--follow, -f", "Keep printing new lines until Ctrl-C (exits 0); with no --runtime, tail a build still running"],
|
|
13889
13953
|
["--preview [<name>]", "A preview's log instead of production's: its name, or the deployment id a preview deploy printed; alone, the project's only preview"],
|
|
13890
13954
|
["--since <t>", "With --runtime: start from 30s / 5m / 1h ago, or from an RFC3339 time"],
|
|
13891
|
-
["--tail <n>", "With --runtime: at most this many lines per pod to start with (the control plane caps it at 2000)"],
|
|
13955
|
+
["--tail <n>", "With --runtime: at most this many lines per pod to start with (the control plane caps it at 2000); with --grep or --level, this many matching lines per pod, searched across the whole window"],
|
|
13892
13956
|
["--grep <text>", "With --runtime: only lines containing the text (any case); `/re/flags` for a regular expression"],
|
|
13893
13957
|
["--level <l>", "With --runtime: only lines at this severity or worse — error, warn, info or debug"],
|
|
13894
13958
|
["--previous", "With --runtime: the last instance of a container that restarted, where a crash's reason usually is"]
|
|
@@ -13911,7 +13975,7 @@ var ACTION_HELP = {
|
|
|
13911
13975
|
summary: "One-glance project status: URL, last deploy, runtime, database, storage — and blockedOn/nextAction, which say whether the platform is working or waiting for you.",
|
|
13912
13976
|
flags: [],
|
|
13913
13977
|
examples: ["rebase cloud status", "rebase cloud status --project shop --json"],
|
|
13914
|
-
notes: ["Poll `status` only while blockedOn is null. Any other value names a command, and the state will not change until you run it."]
|
|
13978
|
+
notes: ["Poll `status` only while blockedOn is null. Any other value names a command, and the state will not change until you run it.", "A section the control plane does not serve yet (the maintenance window) is left out and noted; `notServed` in the JSON lists it."]
|
|
13915
13979
|
},
|
|
13916
13980
|
"clusters add": {
|
|
13917
13981
|
command: "cloud clusters add",
|
|
@@ -13954,6 +14018,14 @@ var ACTION_HELP = {
|
|
|
13954
14018
|
examples: ["rebase cloud clusters verify gke-europe-west1 --baseline"],
|
|
13955
14019
|
notes: ["Exits non-zero when the verdict is `unusable`, so it works as a gate."]
|
|
13956
14020
|
},
|
|
14021
|
+
"clusters baseline": {
|
|
14022
|
+
command: "cloud clusters baseline",
|
|
14023
|
+
usage: "cloud clusters baseline <cluster-id> [--install] [--yes]",
|
|
14024
|
+
summary: "The cluster baseline — ingress-nginx, cert-manager and CloudNativePG — on one cluster: which components are installed and ready, and where the last install left off. With --install, install whatever is missing. Platform-admin only.",
|
|
14025
|
+
flags: [["--install", "Install the missing components, in the background. Asks first"]],
|
|
14026
|
+
examples: ["rebase cloud clusters baseline gke-europe-west1", "rebase cloud clusters baseline gke-europe-west1 --install --yes"],
|
|
14027
|
+
notes: ["The install runs on the control plane; run the command again without --install to follow it.", "`clusters verify <id> --baseline` asks the different question of whether a deploy would work there."]
|
|
14028
|
+
},
|
|
13957
14029
|
"resources prune": {
|
|
13958
14030
|
command: "cloud resources prune",
|
|
13959
14031
|
usage: "cloud resources prune database <key> [--yes]",
|
|
@@ -14000,7 +14072,7 @@ var ACTION_HELP = {
|
|
|
14000
14072
|
],
|
|
14001
14073
|
examples: [
|
|
14002
14074
|
"rebase cloud db access enable --allow 34.89.253.13",
|
|
14003
|
-
"rebase cloud db access enable --allow 34.89.253.13 --tables rebase.metric_samples,rebase.cron_logs",
|
|
14075
|
+
"rebase cloud db access enable --allow 34.89.253.13 --tables rebase.metric_samples,rebase.cron_logs --yes",
|
|
14004
14076
|
"rebase cloud db access reveal --ca-out db-ca.pem",
|
|
14005
14077
|
"rebase cloud db access disable --yes"
|
|
14006
14078
|
],
|
|
@@ -14009,7 +14081,7 @@ var ACTION_HELP = {
|
|
|
14009
14081
|
"The `rebase` schema holds users, password hashes and session tokens: it is never granted whole, and its credential tables never at all.",
|
|
14010
14082
|
"Managed databases on GCP capacity only for now. Each project with access on has its own network load balancer, which is billed.",
|
|
14011
14083
|
"The role holds up to 25 connections at once — enough for a dashboard that loads its widgets in parallel, one connection per query — and the app keeps the rest. A tool that opens more is refused the extra ones.",
|
|
14012
|
-
"`disable` closes the address, drops the role and deletes its password. `--yes`, the global flag listed below, skips the
|
|
14084
|
+
"`enable` opens the database to the network and `disable` closes the address, drops the role and deletes its password: both ask first. `--yes`, the global flag listed below, skips the question, and is required off a terminal."
|
|
14013
14085
|
]
|
|
14014
14086
|
},
|
|
14015
14087
|
"db pitr": {
|
|
@@ -14044,6 +14116,30 @@ var ACTION_HELP = {
|
|
|
14044
14116
|
examples: ["rebase cloud domains add app.example.com"],
|
|
14045
14117
|
notes: ["At a zone apex use the A record this prints, not a CNAME: a CNAME is invalid at an apex.", "Verification is a separate command because DNS propagation is not instant."]
|
|
14046
14118
|
},
|
|
14119
|
+
"domains primary": {
|
|
14120
|
+
command: "cloud domains primary",
|
|
14121
|
+
usage: "cloud domains primary <domain>",
|
|
14122
|
+
summary: "Make one of the project's verified domains its canonical host: the address links are built from, and the one `domains redirect` sends the others to. The project keeps serving its other domains as themselves unless each is told to redirect.",
|
|
14123
|
+
flags: [],
|
|
14124
|
+
examples: ["rebase cloud domains primary app.example.com"],
|
|
14125
|
+
notes: ["Only a verified domain can be primary: run `domains verify <domain>` first.", "Refused with not_served by a control plane that keeps a single domain per project."]
|
|
14126
|
+
},
|
|
14127
|
+
"domains redirect": {
|
|
14128
|
+
command: "cloud domains redirect",
|
|
14129
|
+
usage: "cloud domains redirect <domain> [--off]",
|
|
14130
|
+
summary: "Answer one of the project's domains with a permanent redirect (308) to the primary domain, keeping the path and the query, instead of serving the project on it. Use it for `www.` beside an apex: two hosts serving one site are two origins, and Google sign-in, cookies and passkeys each work on one and fail on the other.",
|
|
14131
|
+
flags: [["--off", "Serve the domain again instead of redirecting it"]],
|
|
14132
|
+
examples: [
|
|
14133
|
+
"rebase cloud domains primary example.com",
|
|
14134
|
+
"rebase cloud domains redirect www.example.com",
|
|
14135
|
+
"rebase cloud domains redirect www.example.com --off"
|
|
14136
|
+
],
|
|
14137
|
+
notes: [
|
|
14138
|
+
"Off by default, per domain: a project serving an `api.` host beside its site keeps both.",
|
|
14139
|
+
"In effect while the domain is verified and another domain is primary; until then it is stored and says so.",
|
|
14140
|
+
"Never applies to the primary itself, to the project's <slug>.rebase.website host, or to a domain an app is served on (an app `path` with a hostname in rebase.json)."
|
|
14141
|
+
]
|
|
14142
|
+
},
|
|
14047
14143
|
"domains remove": {
|
|
14048
14144
|
command: "cloud domains remove",
|
|
14049
14145
|
usage: "cloud domains remove <domain>",
|
|
@@ -14175,17 +14271,23 @@ var ACTION_HELP = {
|
|
|
14175
14271
|
},
|
|
14176
14272
|
billing: {
|
|
14177
14273
|
command: "cloud billing",
|
|
14178
|
-
usage: "cloud billing [setup|checkout|invoices|upcoming]",
|
|
14179
|
-
summary: "The selected organization's billing. Bare, it prints the billing account, the card on file and what the linked project costs per month; `setup` attaches a card (one-time, opens a browser); `checkout` opens a Stripe session for one project; `invoices` lists the issued invoices with Stripe's hosted page for each; `upcoming` previews the next invoice of every subscription. Organization-scoped, not project-scoped.",
|
|
14274
|
+
usage: "cloud billing [setup|checkout|invoices|upcoming|email] [<address>]",
|
|
14275
|
+
summary: "The selected organization's billing. Bare, it prints the billing account, the card on file and what the linked project costs per month; `setup` attaches a card (one-time, opens a browser); `checkout` opens a Stripe session for one project; `invoices` lists the issued invoices with Stripe's hosted page for each; `upcoming` previews the next invoice of every subscription; `email <address>` sets where Stripe sends the invoices. Organization-scoped, not project-scoped.",
|
|
14180
14276
|
flags: [["--limit <n>", "`invoices` only: how many to list, newest first. Default 24, at most 100"]],
|
|
14181
14277
|
examples: [
|
|
14182
14278
|
"rebase cloud billing",
|
|
14183
14279
|
"rebase cloud billing setup",
|
|
14184
14280
|
"rebase cloud billing checkout --project shop",
|
|
14185
14281
|
"rebase cloud billing invoices --json",
|
|
14186
|
-
"rebase cloud billing upcoming"
|
|
14282
|
+
"rebase cloud billing upcoming",
|
|
14283
|
+
"rebase cloud billing email billing@example.com"
|
|
14187
14284
|
],
|
|
14188
|
-
notes: [
|
|
14285
|
+
notes: [
|
|
14286
|
+
"`setup` comes before the first deploy: without a card the control plane answers 402, and `deploy` refuses before it builds.",
|
|
14287
|
+
"`email` changes the billing account and the Stripe customer together; owners and admins of the organization.",
|
|
14288
|
+
"A control plane that does not serve invoices, or the preview of the next one, refuses `invoices` or `upcoming` with not_served.",
|
|
14289
|
+
"A token reaches billing with the `billing` capability on the organization (`rebase cloud tokens create --can billing --org <id>`). A token made before that capability existed still works for one release, and each answer warns that it will stop."
|
|
14290
|
+
]
|
|
14189
14291
|
},
|
|
14190
14292
|
"app-key": {
|
|
14191
14293
|
command: "cloud app-key",
|
|
@@ -14205,24 +14307,27 @@ var ACTION_HELP = {
|
|
|
14205
14307
|
},
|
|
14206
14308
|
"service-key": {
|
|
14207
14309
|
command: "cloud service-key",
|
|
14208
|
-
usage: "cloud service-key [rotate]",
|
|
14209
|
-
summary: "The project's REBASE_SERVICE_KEY, admin on the app's own API. Without an action, prints its generation, when it was last rotated and whether the app is still restarting onto the newest one (never the key: that is `rebase cloud env reveal REBASE_SERVICE_KEY`). `rotate` issues a new key and restarts the app onto it; the old key works until the restart has finished and nothing after. Refused while a deploy is running. Owners and admins, signed in.",
|
|
14210
|
-
flags: [],
|
|
14310
|
+
usage: "cloud service-key [rotate] [--preview <name>]",
|
|
14311
|
+
summary: "The project's REBASE_SERVICE_KEY, admin on the app's own API. Without an action, prints its generation, when it was last rotated and whether the app is still restarting onto the newest one (never the key: that is `rebase cloud env reveal REBASE_SERVICE_KEY`). `rotate` issues a new key and restarts the app onto it; the old key works until the restart has finished and nothing after. Refused while a deploy is running. Owners and admins, signed in. With `--preview <name>`, the same for one backend preview's own key: without an action it prints that key, and `rotate` restarts only the preview's pod.",
|
|
14312
|
+
flags: [["--preview <name>", "A backend preview's own key instead of production's: printed, or with `rotate` replaced"]],
|
|
14211
14313
|
examples: [
|
|
14212
14314
|
"rebase cloud service-key",
|
|
14213
14315
|
"rebase cloud service-key rotate",
|
|
14214
|
-
"rebase cloud service-key rotate --yes --json"
|
|
14316
|
+
"rebase cloud service-key rotate --yes --json",
|
|
14317
|
+
"rebase cloud service-key --preview new-quiz",
|
|
14318
|
+
"rebase cloud service-key rotate --preview new-quiz --yes"
|
|
14215
14319
|
],
|
|
14216
14320
|
notes: [
|
|
14217
14321
|
"Anything that copied the old key (a script, a CI job) is refused once the restart has finished.",
|
|
14218
14322
|
"Claiming a project rotates its service key too.",
|
|
14219
|
-
"It runs with your login: no access-token capability grants it, so REBASE_TOKEN is refused."
|
|
14323
|
+
"It runs with your login: no access-token capability grants it, so REBASE_TOKEN is refused.",
|
|
14324
|
+
"A backend preview's key is its own: minted at its first deploy, kept across redeploys, and production's key answers 401 there. `--preview` asks what `env reveal` asks — the owner or admin role, and a token with the env capability on a claimed project — and never touches production's key or pod."
|
|
14220
14325
|
]
|
|
14221
14326
|
},
|
|
14222
14327
|
guests: {
|
|
14223
14328
|
command: "cloud guests",
|
|
14224
14329
|
usage: "cloud guests [delete|prune] [<id>] [--older-than <age>] [--limit <n>]",
|
|
14225
|
-
summary: "The guest users anonymous sign-in left behind on the project. Without an action, counts them and lists the ones last seen longest ago. `delete` removes one. `prune` removes the ones not seen for an age: a dry run that prints how many would go, deleting only with --yes. Only guests can go: an account, or a guest that has become one, is refused by the app itself. Owners and admins.",
|
|
14330
|
+
summary: "The guest users anonymous sign-in left behind on the project. Without an action, counts them and lists the ones last seen longest ago. `delete` removes one. `prune` removes the ones not seen for an age: a dry run that prints how many would go, deleting only with --yes. Only guests can go: an account, or a guest that has become one, is refused by the app itself. Owners and admins, on a project whose Studio access is on: the request goes through the console's Studio proxy, which holds the app's key so this machine never does. `rebase users guests --project <slug>` is the same command in the project family.",
|
|
14226
14331
|
flags: [["--older-than <age>", "With `prune`, or to count the list: not seen for this long, as 30d, 12h, 2w or 45m"], ["--limit <n>", "How many the list shows. Default: 25"]],
|
|
14227
14332
|
examples: [
|
|
14228
14333
|
"rebase cloud guests",
|
|
@@ -14300,7 +14405,11 @@ var ACTION_HELP = {
|
|
|
14300
14405
|
"rebase cloud compute apply",
|
|
14301
14406
|
"rebase cloud compute window --day sun --hour 3"
|
|
14302
14407
|
],
|
|
14303
|
-
notes: [
|
|
14408
|
+
notes: [
|
|
14409
|
+
"The price is the control plane's own quote for these dials, itemised line by line — not a tier, and not a number this CLI computes.",
|
|
14410
|
+
"`Waiting` is a database change a `set` scheduled for the maintenance window and has not applied yet; the project is billed at the size it runs until then.",
|
|
14411
|
+
"A control plane without maintenance windows leaves those lines out and says so; `notServed` in the JSON lists what it left out."
|
|
14412
|
+
]
|
|
14304
14413
|
},
|
|
14305
14414
|
"compute apply": {
|
|
14306
14415
|
command: "cloud compute apply",
|
|
@@ -14353,12 +14462,13 @@ var ACTION_HELP = {
|
|
|
14353
14462
|
],
|
|
14354
14463
|
examples: [
|
|
14355
14464
|
"rebase cloud compute set --cpu 500m --memory 2Gi",
|
|
14356
|
-
"rebase cloud compute set --replicas 2 --autoscale-max 6",
|
|
14465
|
+
"rebase cloud compute set --replicas 2 --autoscale-max 6 --yes",
|
|
14357
14466
|
"rebase cloud compute set --db-instances 2 --db-memory 4Gi",
|
|
14358
14467
|
"rebase cloud compute set --db-autoscale-max-cpu 2 --db-autoscale-max-memory 8Gi"
|
|
14359
14468
|
],
|
|
14360
14469
|
notes: [
|
|
14361
14470
|
"Run `rebase cloud compute` first — it prints the current dials and the €/month this project is quoted.",
|
|
14471
|
+
"It asks before changing anything, with the €/month the control plane quotes for the new dials beside what it quotes now. `--yes`, the global flag listed below, skips the question, and is required off a terminal.",
|
|
14362
14472
|
"Applied immediately: the app rolls its pods and the subscription is prorated from today. A change that restarts the database is scheduled for the project's maintenance window, billed from when it is applied; apply it sooner with `rebase cloud compute apply`.",
|
|
14363
14473
|
"The valid ranges are the target cluster's, not this CLI's — GKE Autopilot bills a 250m/512Mi floor and rewrites a memory:CPU ratio outside 1:1–6.5:1, a Hetzner node has neither constraint. The control plane refuses what it cannot honour and names the field."
|
|
14364
14474
|
]
|
|
@@ -14594,10 +14704,82 @@ var ACTION_HELP = {
|
|
|
14594
14704
|
},
|
|
14595
14705
|
metrics: {
|
|
14596
14706
|
command: "cloud metrics",
|
|
14597
|
-
usage: "cloud metrics",
|
|
14598
|
-
summary: "Live CPU, memory and disk for the project's running units, and each instance's realtime counts, as the control plane reports them.",
|
|
14707
|
+
usage: "cloud metrics [--runtime | --history [--series <name>] [--minutes <n>]]",
|
|
14708
|
+
summary: "Live CPU, memory and disk for the project's running units, and each instance's realtime counts, as the control plane reports them. --runtime is what the app itself counted: requests, the 5xx error rate, mean latency, per surface. --history is one series the runtime recorded over a window.",
|
|
14709
|
+
flags: [
|
|
14710
|
+
["--runtime", "Requests, errors, error rate and mean latency, from the app's own counters"],
|
|
14711
|
+
["--history", "A recorded series over a window instead of the live figures"],
|
|
14712
|
+
["--series <name>", "With --history: cpu_millicores (default), memory_bytes or event_loop_delay_ms"],
|
|
14713
|
+
["--minutes <n>", "With --history: how far back, 1 to 20160 (fourteen days). Default: 60"]
|
|
14714
|
+
],
|
|
14715
|
+
examples: [
|
|
14716
|
+
"rebase cloud metrics",
|
|
14717
|
+
"rebase cloud metrics --runtime",
|
|
14718
|
+
"rebase cloud metrics --history --series memory_bytes --minutes 1440 --json"
|
|
14719
|
+
],
|
|
14720
|
+
notes: ["--runtime counts from when the running instance started, so a restart begins again at zero. \"No data yet\" means the app is not deployed, still starting, or not reporting metrics, never an idle app.", "--history exits 1, with the reason, when the history cannot be read: a runtime that keeps none, one too old to, or one not answering (`retryable`)."]
|
|
14721
|
+
},
|
|
14722
|
+
"deploy-hooks": {
|
|
14723
|
+
command: "cloud deploy-hooks",
|
|
14724
|
+
usage: "cloud deploy-hooks [list|create|revoke] [options]",
|
|
14725
|
+
summary: "URLs that build and ship the project's connected repository when something POSTs to them: a git host's webhook, a CMS's publish button, a CI step. `list` (the default) shows each hook's name, branch and when it was last used, never its URL.",
|
|
14726
|
+
flags: [["--name <name>", "create: what to call it. Default: Deploy hook"], ["--branch <branch>", "create: the branch it builds. Default: the project's configured branch"]],
|
|
14727
|
+
examples: [
|
|
14728
|
+
"rebase cloud deploy-hooks",
|
|
14729
|
+
"rebase cloud deploy-hooks create --name github --branch main",
|
|
14730
|
+
"rebase cloud deploy-hooks revoke 7 --yes"
|
|
14731
|
+
],
|
|
14732
|
+
notes: [
|
|
14733
|
+
"The URL is printed once, at `create`: it is the credential, and the control plane keeps only its hash.",
|
|
14734
|
+
"A GitHub or GitLab push to another branch, a tag, or any other event is acknowledged and ignored.",
|
|
14735
|
+
"Creating and revoking take the owner or admin role; any member may list. A project holds at most 20."
|
|
14736
|
+
]
|
|
14737
|
+
},
|
|
14738
|
+
"deploy-hooks create": {
|
|
14739
|
+
command: "cloud deploy-hooks create",
|
|
14740
|
+
usage: "cloud deploy-hooks create [--name <name>] [--branch <branch>]",
|
|
14741
|
+
summary: "Mint a deploy hook and print its URL, once. POSTing to the URL builds and ships the connected repository.",
|
|
14742
|
+
flags: [["--name <name>", "What to call it. Default: Deploy hook"], ["--branch <branch>", "The branch it builds. Default: the project's configured branch"]],
|
|
14743
|
+
examples: ["rebase cloud deploy-hooks create --name github --branch main --json"],
|
|
14744
|
+
notes: ["`url` and `token` in the JSON are the only copy: store them where the caller of the hook reads secrets."]
|
|
14745
|
+
},
|
|
14746
|
+
"deploy-hooks revoke": {
|
|
14747
|
+
command: "cloud deploy-hooks revoke",
|
|
14748
|
+
usage: "cloud deploy-hooks revoke <id> [--yes]",
|
|
14749
|
+
summary: "Delete a deploy hook: anything POSTing to its URL is refused from then on. Asks first.",
|
|
14750
|
+
flags: [],
|
|
14751
|
+
examples: ["rebase cloud deploy-hooks revoke 7 --yes"]
|
|
14752
|
+
},
|
|
14753
|
+
alerts: {
|
|
14754
|
+
command: "cloud alerts",
|
|
14755
|
+
usage: "cloud alerts [list|ack|snooze] [<incidentId>] [options]",
|
|
14756
|
+
summary: "What the platform has seen go wrong with the project — a disk filling, an app restarting, a deploy failing — newest first. `list` (the default) shows the open ones; `ack` stops the reminders for everyone; `snooze` stops the emails for a while.",
|
|
14757
|
+
flags: [["--all", "list: the resolved ones as well as the open ones"], ["--hours <1-168>", "snooze: how long. Required"]],
|
|
14758
|
+
examples: [
|
|
14759
|
+
"rebase cloud alerts",
|
|
14760
|
+
"rebase cloud alerts list --all --json",
|
|
14761
|
+
"rebase cloud alerts ack 6f1c2a0e-…",
|
|
14762
|
+
"rebase cloud alerts snooze 6f1c2a0e-… --hours 24"
|
|
14763
|
+
],
|
|
14764
|
+
notes: [
|
|
14765
|
+
"Any member of the organization may read, acknowledge and snooze. Only an open alert can be acknowledged or snoozed.",
|
|
14766
|
+
"An organization-wide problem (a failed payment) belongs to no project, and is not listed here; the console shows it.",
|
|
14767
|
+
"You still hear about an acknowledged or snoozed alert if it gets worse or is resolved."
|
|
14768
|
+
]
|
|
14769
|
+
},
|
|
14770
|
+
"alerts ack": {
|
|
14771
|
+
command: "cloud alerts ack",
|
|
14772
|
+
usage: "cloud alerts ack <incidentId>",
|
|
14773
|
+
summary: "Acknowledge an open alert: reminders stop for everyone in the organization.",
|
|
14599
14774
|
flags: [],
|
|
14600
|
-
examples: ["rebase cloud
|
|
14775
|
+
examples: ["rebase cloud alerts ack 6f1c2a0e-…"]
|
|
14776
|
+
},
|
|
14777
|
+
"alerts snooze": {
|
|
14778
|
+
command: "cloud alerts snooze",
|
|
14779
|
+
usage: "cloud alerts snooze <incidentId> --hours <1-168>",
|
|
14780
|
+
summary: "Snooze an open alert: nobody in the organization is emailed about it until the time is up, unless it is resolved.",
|
|
14781
|
+
flags: [["--hours <1-168>", "How long, in hours. Required; at most a week"]],
|
|
14782
|
+
examples: ["rebase cloud alerts snooze 6f1c2a0e-… --hours 24"]
|
|
14601
14783
|
}
|
|
14602
14784
|
};
|
|
14603
14785
|
/** Print one action's page — human, or its JSON description when piped. */
|
|
@@ -14704,6 +14886,7 @@ var CLOUD_VALUE_FLAGS = {
|
|
|
14704
14886
|
"--grep": String,
|
|
14705
14887
|
"--host": String,
|
|
14706
14888
|
"--hour": String,
|
|
14889
|
+
"--hours": String,
|
|
14707
14890
|
"--ingress-address": String,
|
|
14708
14891
|
"--kubeconfig": String,
|
|
14709
14892
|
"--level": String,
|
|
@@ -14711,6 +14894,7 @@ var CLOUD_VALUE_FLAGS = {
|
|
|
14711
14894
|
"--live-timeout": String,
|
|
14712
14895
|
"--memory": String,
|
|
14713
14896
|
"--message": String,
|
|
14897
|
+
"--minutes": String,
|
|
14714
14898
|
"--month": String,
|
|
14715
14899
|
"--name": String,
|
|
14716
14900
|
"--older-than": String,
|
|
@@ -14732,12 +14916,15 @@ var CLOUD_VALUE_FLAGS = {
|
|
|
14732
14916
|
"--scale-to-zero": String,
|
|
14733
14917
|
"--schemas": String,
|
|
14734
14918
|
"--secret-access-key": String,
|
|
14919
|
+
"--series": String,
|
|
14735
14920
|
"--since": String,
|
|
14736
14921
|
"--slug": String,
|
|
14737
14922
|
"--source": String,
|
|
14738
14923
|
"--spot": String,
|
|
14739
14924
|
"--storage": String,
|
|
14925
|
+
"--studio": String,
|
|
14740
14926
|
"--subdomain": String,
|
|
14927
|
+
"--table": String,
|
|
14741
14928
|
"--tail": String,
|
|
14742
14929
|
"--tables": String,
|
|
14743
14930
|
"--target": String,
|
|
@@ -14810,7 +14997,8 @@ var GROUP_ALIASES = {
|
|
|
14810
14997
|
extension: "extensions",
|
|
14811
14998
|
org: "orgs",
|
|
14812
14999
|
preview: "previews",
|
|
14813
|
-
project: "projects"
|
|
15000
|
+
project: "projects",
|
|
15001
|
+
releases: "deployments"
|
|
14814
15002
|
};
|
|
14815
15003
|
var GROUP_HELP = {
|
|
14816
15004
|
env: printEnvHelp,
|
|
@@ -14925,6 +15113,12 @@ async function cloudCommand(subcommand, rawArgs) {
|
|
|
14925
15113
|
case "cron":
|
|
14926
15114
|
await cronCommand(action, rawArgs);
|
|
14927
15115
|
break;
|
|
15116
|
+
case "deploy-hooks":
|
|
15117
|
+
await deployHooksCommand(action, rawArgs);
|
|
15118
|
+
break;
|
|
15119
|
+
case "alerts":
|
|
15120
|
+
await alertsCommand(action, rawArgs);
|
|
15121
|
+
break;
|
|
14928
15122
|
case "env":
|
|
14929
15123
|
await envCommand(action, rawArgs);
|
|
14930
15124
|
break;
|
|
@@ -15162,7 +15356,7 @@ var CLOUD_GROUPS = [
|
|
|
15162
15356
|
{
|
|
15163
15357
|
action: "metrics",
|
|
15164
15358
|
section: "Deploy & observe",
|
|
15165
|
-
description: "Live CPU, memory and disk"
|
|
15359
|
+
description: "Live CPU, memory and disk; requests and errors with --runtime; history with --history"
|
|
15166
15360
|
},
|
|
15167
15361
|
{
|
|
15168
15362
|
action: "debug",
|
|
@@ -15174,6 +15368,16 @@ var CLOUD_GROUPS = [
|
|
|
15174
15368
|
section: "Deploy & observe",
|
|
15175
15369
|
description: "The app's cron jobs and their run history. Read-only"
|
|
15176
15370
|
},
|
|
15371
|
+
{
|
|
15372
|
+
action: "deploy-hooks",
|
|
15373
|
+
section: "Deploy & observe",
|
|
15374
|
+
description: "URLs that build and ship the connected repository when POSTed to"
|
|
15375
|
+
},
|
|
15376
|
+
{
|
|
15377
|
+
action: "alerts",
|
|
15378
|
+
section: "Deploy & observe",
|
|
15379
|
+
description: "What the platform has seen go wrong, and acknowledging or snoozing it"
|
|
15380
|
+
},
|
|
15177
15381
|
{
|
|
15178
15382
|
action: "env",
|
|
15179
15383
|
section: "Config",
|
|
@@ -15192,7 +15396,7 @@ var CLOUD_GROUPS = [
|
|
|
15192
15396
|
{
|
|
15193
15397
|
action: "settings",
|
|
15194
15398
|
section: "Config",
|
|
15195
|
-
description: "Name, subdomain, repository, branch"
|
|
15399
|
+
description: "Name, subdomain, repository, branch, Studio access"
|
|
15196
15400
|
},
|
|
15197
15401
|
{
|
|
15198
15402
|
action: "app-key",
|
|
@@ -15203,8 +15407,8 @@ var CLOUD_GROUPS = [
|
|
|
15203
15407
|
{
|
|
15204
15408
|
action: "service-key",
|
|
15205
15409
|
section: "Config",
|
|
15206
|
-
args: "[rotate]",
|
|
15207
|
-
description: "REBASE_SERVICE_KEY, admin on the app's API: its state, and replacing it. Owners and admins"
|
|
15410
|
+
args: "[rotate] [--preview <name>]",
|
|
15411
|
+
description: "REBASE_SERVICE_KEY, admin on the app's API: its state, and replacing it; a backend preview's own with --preview. Owners and admins"
|
|
15208
15412
|
},
|
|
15209
15413
|
{
|
|
15210
15414
|
action: "orgs",
|
|
@@ -15237,11 +15441,6 @@ var CLOUD_GROUPS = [
|
|
|
15237
15441
|
section: "Deploy & observe",
|
|
15238
15442
|
description: "Send deploy, backup, billing and usage events to Slack, Discord or any URL"
|
|
15239
15443
|
},
|
|
15240
|
-
{
|
|
15241
|
-
action: "webhooks",
|
|
15242
|
-
section: "Other resources",
|
|
15243
|
-
description: "Retired: use `notifications`, or a WebhookDispatcher in your app's code"
|
|
15244
|
-
},
|
|
15245
15444
|
{
|
|
15246
15445
|
action: "resources",
|
|
15247
15446
|
section: "Other resources",
|
|
@@ -15292,4 +15491,4 @@ function printCloudHelp() {
|
|
|
15292
15491
|
//#endregion
|
|
15293
15492
|
export { CLOUD_GROUP_NAMES, GROUP_ALIASES, cloudCommand };
|
|
15294
15493
|
|
|
15295
|
-
//# sourceMappingURL=cloud-
|
|
15494
|
+
//# sourceMappingURL=cloud-DNJyUU0T.js.map
|