@rebasepro/cli 0.31.0-canary.g902a0ce → 0.32.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-CyADghFQ.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-BfdT-AUR.js} +12 -10
- package/dist/{build-CA5R07tw.js.map → build-BfdT-AUR.js.map} +1 -1
- 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-MqnyPnmX.js} +1540 -1531
- package/dist/cloud-MqnyPnmX.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 +2 -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-D9g46gg9.js} +68 -42
- package/dist/command-D9g46gg9.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 +1 -0
- 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/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-CMjhgMUE.js → console-BVoYOLAO.js} +6 -6
- package/dist/{console-CMjhgMUE.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-A7XDCIIO.js → db-D_iF4E-v.js} +60 -36
- package/dist/db-D_iF4E-v.js.map +1 -0
- 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-tWwPyWkQ.js → dev-bj6dEeSQ.js} +13 -13
- package/dist/{dev-tWwPyWkQ.js.map → dev-bj6dEeSQ.js.map} +1 -1
- package/dist/dev-db/__fixtures__/unanswering-postgres.d.ts +11 -0
- package/dist/dev-db/attver.d.ts +38 -6
- package/dist/dev-db/local-timeouts.d.ts +25 -0
- package/dist/dev-db/pull.d.ts +49 -9
- 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-BBM0dWvZ.js → doctor-2Jlau0Rm.js} +9 -8
- package/dist/{doctor-BBM0dWvZ.js.map → doctor-2Jlau0Rm.js.map} +1 -1
- 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/local-timeouts-B1Kwligw.js +30 -0
- package/dist/local-timeouts-B1Kwligw.js.map +1 -0
- package/dist/logs-CIgfLBsu.js +192 -0
- package/dist/logs-CIgfLBsu.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-Cx8-Y4TG.js} +5 -4
- package/dist/{migrate-VrKoi3nB.js.map → migrate-Cx8-Y4TG.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-D9WvpDYY.js → pull-CTIsST6T.js} +336 -55
- 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-DwFDI1iU.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-DQ_PPz4C.js → status-CDBk25VO.js} +9 -9
- package/dist/{status-DQ_PPz4C.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-DhpUFb6p.js} +5 -5
- package/dist/{upgrade-oZzJ13jM.js.map → upgrade-DhpUFb6p.js.map} +1 -1
- package/dist/users-5PkqBY6R.js +561 -0
- package/dist/users-5PkqBY6R.js.map +1 -0
- package/dist/utils/project-command.d.ts +38 -0
- package/dist/utils/project-target.d.ts +193 -0
- package/dist/{verify-DkJqhYPI.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/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-CyADghFQ.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/db-A7XDCIIO.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-D9WvpDYY.js.map +0 -1
- package/dist/resolve-BY7bSFRT.js +0 -2
- package/dist/schema-DwFDI1iU.js.map +0 -1
- package/dist/schema-reconcile-Tto54Qbv.js +0 -2
- package/dist/storage-iTqj5-Av.js.map +0 -1
- package/dist/verify-DkJqhYPI.js.map +0 -1
|
@@ -1,13 +1,15 @@
|
|
|
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 deriveOptionsFor, r as deriveResourceGraph } from "./derive-
|
|
10
|
-
import { t as buildAssetApp } from "./build-
|
|
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 { _ 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 deriveOptionsFor, r as deriveResourceGraph } from "./derive-Mky_u59_.js";
|
|
10
|
+
import { t as buildAssetApp } from "./build-BfdT-AUR.js";
|
|
11
|
+
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";
|
|
12
|
+
import { cronCommand, isMissingRoute } from "./cron-ZRXsla0v.js";
|
|
11
13
|
import chalk from "chalk";
|
|
12
14
|
import arg from "arg";
|
|
13
15
|
import fs from "fs";
|
|
@@ -21,6 +23,53 @@ import inquirer from "inquirer";
|
|
|
21
23
|
import { RebaseApiError, createRebaseClient } from "@rebasepro/client";
|
|
22
24
|
import net from "node:net";
|
|
23
25
|
import { parse } from "acorn";
|
|
26
|
+
//#region src/commands/cloud/not-served.ts
|
|
27
|
+
/**
|
|
28
|
+
* A control plane that does not serve a route a command calls.
|
|
29
|
+
*
|
|
30
|
+
* The CLI is released on its own schedule, and the control plane it talks to
|
|
31
|
+
* may be older than the command: a function the command calls may not be
|
|
32
|
+
* mounted there yet, or a function may be mounted without the route the
|
|
33
|
+
* command needs. Both answer 404, and a generic "Not found" for them reads as
|
|
34
|
+
* "your project is gone" or "you typed the id wrong", which sends the reader
|
|
35
|
+
* looking for a fault that is not theirs.
|
|
36
|
+
*
|
|
37
|
+
* So each command that calls such a route names what is missing and what to do
|
|
38
|
+
* instead, with one code, `not_served`, a caller can branch on.
|
|
39
|
+
* `control-plane-functions.test.ts` holds the list of functions this family
|
|
40
|
+
* calls against the ones the control plane serves.
|
|
41
|
+
*/
|
|
42
|
+
/** The refusal code for a route the control plane does not serve. */
|
|
43
|
+
var NOT_SERVED = "not_served";
|
|
44
|
+
/**
|
|
45
|
+
* Whether an error is the control plane saying it has no such route, rather
|
|
46
|
+
* than a route refusing this request.
|
|
47
|
+
*
|
|
48
|
+
* A Rebase backend answers a function it does not mount, or a route its
|
|
49
|
+
* function does not have, with a 404 coded `FUNCTION_NOT_FOUND`; one from
|
|
50
|
+
* before that envelope answers a bare `Not Found` or `No route for …`. A
|
|
51
|
+
* function that is served and refuses an unknown project answers its own code
|
|
52
|
+
* (`not_found`), so that 404 is not this one.
|
|
53
|
+
*/
|
|
54
|
+
function isRouteNotServed(error) {
|
|
55
|
+
if (typeof error !== "object" || error === null) return false;
|
|
56
|
+
if (!("status" in error) || error.status !== 404) return false;
|
|
57
|
+
if (("code" in error ? error.code : void 0) === "FUNCTION_NOT_FOUND") return true;
|
|
58
|
+
return isMissingRoute("message" in error && typeof error.message === "string" ? error.message : void 0);
|
|
59
|
+
}
|
|
60
|
+
/** Refuse with `not_served` when `error` is a missing route; return otherwise. */
|
|
61
|
+
function refuseIfNotServed(error, unserved) {
|
|
62
|
+
if (isRouteNotServed(error)) fail(`This control plane does not serve ${unserved.what} yet.`, unserved.hint, NOT_SERVED);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Report a failed control-plane call: `not_served` for a missing route, the
|
|
66
|
+
* family's usual report otherwise. Never returns.
|
|
67
|
+
*/
|
|
68
|
+
function reportCallError(error, context, unserved) {
|
|
69
|
+
refuseIfNotServed(error, unserved);
|
|
70
|
+
reportError(error, context);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
24
73
|
//#region src/commands/cloud/maintenance.ts
|
|
25
74
|
/**
|
|
26
75
|
* A project's maintenance window, what its database is waiting on, and its
|
|
@@ -67,17 +116,51 @@ function parseDay(value) {
|
|
|
67
116
|
const i = DAY_NAMES.findIndex((d) => d.startsWith(v));
|
|
68
117
|
return i >= 0 ? i : void 0;
|
|
69
118
|
}
|
|
70
|
-
/**
|
|
119
|
+
/** What a command says on a control plane that has no `maintenance` function yet. */
|
|
120
|
+
var MAINTENANCE_UNSERVED = {
|
|
121
|
+
what: "maintenance windows",
|
|
122
|
+
hint: "Nothing was changed. On this control plane a database change from `rebase cloud compute set` is not held for a window."
|
|
123
|
+
};
|
|
124
|
+
/** What `events` says on a control plane that has no `maintenance` function yet. */
|
|
125
|
+
var EVENTS_UNSERVED = {
|
|
126
|
+
what: "project events",
|
|
127
|
+
hint: "`rebase cloud deployments` lists the project's deploys, and `rebase cloud metrics` what it runs now."
|
|
128
|
+
};
|
|
129
|
+
/** The project's maintenance status, and whether the control plane serves it at all. */
|
|
130
|
+
async function readMaintenance(client, projectId) {
|
|
131
|
+
try {
|
|
132
|
+
return {
|
|
133
|
+
kind: "ok",
|
|
134
|
+
status: await client.functions.invoke("maintenance", void 0, {
|
|
135
|
+
method: "GET",
|
|
136
|
+
path: `projects/${encodeURIComponent(projectId)}`
|
|
137
|
+
})
|
|
138
|
+
};
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return isRouteNotServed(error) ? { kind: "not_served" } : { kind: "failed" };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** The project's maintenance status, or undefined when it could not be read. */
|
|
71
144
|
async function fetchMaintenance(client, projectId) {
|
|
145
|
+
const read = await readMaintenance(client, projectId);
|
|
146
|
+
return read.kind === "ok" ? read.status : void 0;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The status a command that is about maintenance needs, or a refusal: `not_served`
|
|
150
|
+
* on a control plane without the function, the failure itself otherwise.
|
|
151
|
+
*/
|
|
152
|
+
async function requireMaintenance(client, projectId) {
|
|
72
153
|
try {
|
|
73
154
|
return await client.functions.invoke("maintenance", void 0, {
|
|
74
155
|
method: "GET",
|
|
75
156
|
path: `projects/${encodeURIComponent(projectId)}`
|
|
76
157
|
});
|
|
77
|
-
} catch {
|
|
78
|
-
|
|
158
|
+
} catch (error) {
|
|
159
|
+
reportCallError(error, "Could not read the maintenance window", MAINTENANCE_UNSERVED);
|
|
79
160
|
}
|
|
80
161
|
}
|
|
162
|
+
/** The line a page prints in place of its maintenance section on a control plane without it. */
|
|
163
|
+
var MAINTENANCE_NOT_SERVED_NOTE = "This control plane does not report maintenance windows yet, so none is shown.";
|
|
81
164
|
/** One line for a waiting batch: "Database 0.16 → 0.5 vCPU — applies Sunday 9 November, 03:00 UTC". */
|
|
82
165
|
function describePending(open) {
|
|
83
166
|
if (!open) return void 0;
|
|
@@ -96,9 +179,7 @@ async function computeApplyCommand(rawArgs) {
|
|
|
96
179
|
const { client } = await requireClient(rawArgs);
|
|
97
180
|
const projectId = await requireProject(rawArgs, client);
|
|
98
181
|
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;
|
|
182
|
+
const open = (await requireMaintenance(client, projectId)).open;
|
|
102
183
|
if (!open || open.state !== "pending" && open.state !== "notified") {
|
|
103
184
|
if (open?.state === "applying") {
|
|
104
185
|
emit(() => note(`${open.summary} is being applied now.`), {
|
|
@@ -120,7 +201,7 @@ async function computeApplyCommand(rawArgs) {
|
|
|
120
201
|
try {
|
|
121
202
|
await client.functions.invoke("maintenance", {}, { path: `projects/${encodeURIComponent(projectId)}/apply` });
|
|
122
203
|
} catch (error) {
|
|
123
|
-
|
|
204
|
+
reportCallError(error, "Could not apply the database change", MAINTENANCE_UNSERVED);
|
|
124
205
|
}
|
|
125
206
|
emit(() => {
|
|
126
207
|
success(`Applying ${open.summary}.`);
|
|
@@ -143,8 +224,7 @@ async function computeWindowCommand(rawArgs) {
|
|
|
143
224
|
const dayFlag = flags["--day"];
|
|
144
225
|
const hourFlag = flags["--hour"];
|
|
145
226
|
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");
|
|
227
|
+
const status = await requireMaintenance(client, projectId);
|
|
148
228
|
emit(() => {
|
|
149
229
|
console.log("");
|
|
150
230
|
keyValues([
|
|
@@ -177,7 +257,7 @@ async function computeWindowCommand(rawArgs) {
|
|
|
177
257
|
path: `projects/${encodeURIComponent(projectId)}/window`
|
|
178
258
|
});
|
|
179
259
|
} catch (error) {
|
|
180
|
-
|
|
260
|
+
reportCallError(error, "Could not move the maintenance window", MAINTENANCE_UNSERVED);
|
|
181
261
|
}
|
|
182
262
|
emit(() => success(`Maintenance window: ${res?.window?.label ?? `${DAYS[day]} ${hourFlag}:00 UTC`}.`), { window: res?.window ?? {
|
|
183
263
|
day,
|
|
@@ -207,7 +287,7 @@ async function eventsCommand(rawArgs) {
|
|
|
207
287
|
path: `projects/${encodeURIComponent(projectId)}/events?limit=${limit}`
|
|
208
288
|
})).events ?? [];
|
|
209
289
|
} catch (error) {
|
|
210
|
-
|
|
290
|
+
reportCallError(error, "Could not read the project's events", EVENTS_UNSERVED);
|
|
211
291
|
}
|
|
212
292
|
emit(() => {
|
|
213
293
|
console.log("");
|
|
@@ -1526,7 +1606,7 @@ async function statusCommand(rawArgs) {
|
|
|
1526
1606
|
try {
|
|
1527
1607
|
const project = await client.data.table("projects").findById(projectId);
|
|
1528
1608
|
if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`, void 0, "not_found");
|
|
1529
|
-
const [db, storage, deploy, baseDomain,
|
|
1609
|
+
const [db, storage, deploy, baseDomain, maintenanceRead] = await Promise.all([
|
|
1530
1610
|
firstRow(client, "databases", projectId),
|
|
1531
1611
|
client.functions.invoke("storage-provision", void 0, {
|
|
1532
1612
|
method: "GET",
|
|
@@ -1534,8 +1614,10 @@ async function statusCommand(rawArgs) {
|
|
|
1534
1614
|
}).catch(() => void 0),
|
|
1535
1615
|
latestDeployment(client, projectId),
|
|
1536
1616
|
fetchTenantBaseDomain(client, url),
|
|
1537
|
-
|
|
1617
|
+
readMaintenance(client, projectId)
|
|
1538
1618
|
]);
|
|
1619
|
+
const maintenance = maintenanceRead.kind === "ok" ? maintenanceRead.status : void 0;
|
|
1620
|
+
const notServed = maintenanceRead.kind === "not_served" ? ["maintenance"] : [];
|
|
1539
1621
|
const storageLine = describeStorageState(storage);
|
|
1540
1622
|
const databaseLine = describeDatabaseState(db);
|
|
1541
1623
|
const link = readLink();
|
|
@@ -1571,6 +1653,7 @@ async function statusCommand(rawArgs) {
|
|
|
1571
1653
|
console.log(` ${chalk.bold(blocked.nextAction ?? "")}`);
|
|
1572
1654
|
}
|
|
1573
1655
|
console.log("");
|
|
1656
|
+
if (notServed.length > 0) note(chalk.gray(MAINTENANCE_NOT_SERVED_NOTE));
|
|
1574
1657
|
}, {
|
|
1575
1658
|
projectId: String(project.id),
|
|
1576
1659
|
name: project.name ?? null,
|
|
@@ -1602,6 +1685,7 @@ async function statusCommand(rawArgs) {
|
|
|
1602
1685
|
window: maintenance.window,
|
|
1603
1686
|
pending: maintenance.open
|
|
1604
1687
|
} : null,
|
|
1688
|
+
notServed,
|
|
1605
1689
|
unclaimed: grant ? {
|
|
1606
1690
|
claimUrl: grant.claimUrl,
|
|
1607
1691
|
expiresAt: grant.expiresAt,
|
|
@@ -1650,16 +1734,65 @@ function cpuLine(m) {
|
|
|
1650
1734
|
const parts = [request != null ? `${request}m guaranteed` : null, limit != null ? `bursts to ${limit}m` : null].filter(Boolean).join(", ");
|
|
1651
1735
|
return `${m.cpu} ${chalk.gray(`(${parts}, per instance)`)}`;
|
|
1652
1736
|
}
|
|
1737
|
+
/** What `rebase cloud metrics` parses. Its page pairs against this. */
|
|
1738
|
+
var METRICS_FLAGS = {
|
|
1739
|
+
"--runtime": Boolean,
|
|
1740
|
+
"--history": Boolean,
|
|
1741
|
+
"--series": String,
|
|
1742
|
+
"--minutes": String
|
|
1743
|
+
};
|
|
1744
|
+
/**
|
|
1745
|
+
* The series a runtime records, and so the ones `--history` may name.
|
|
1746
|
+
*
|
|
1747
|
+
* The runtime's own list (`METRIC_SERIES` in
|
|
1748
|
+
* `packages/server/src/metrics/history-store.ts`), which is not exported;
|
|
1749
|
+
* `cloud-api-commands.test.ts` holds the two together.
|
|
1750
|
+
*/
|
|
1751
|
+
var HISTORY_SERIES = [
|
|
1752
|
+
"cpu_millicores",
|
|
1753
|
+
"memory_bytes",
|
|
1754
|
+
"event_loop_delay_ms"
|
|
1755
|
+
];
|
|
1756
|
+
/** The longest window the runtime keeps: fourteen days, in minutes. */
|
|
1757
|
+
var HISTORY_MAX_MINUTES = 20160;
|
|
1758
|
+
/** The share of requests that failed, as a percentage with one decimal; undefined with no requests. */
|
|
1759
|
+
function errorRate(requests, errors) {
|
|
1760
|
+
if (!requests) return void 0;
|
|
1761
|
+
return `${((errors ?? 0) / requests * 100).toFixed(1)}%`;
|
|
1762
|
+
}
|
|
1763
|
+
/** `--series` and `--minutes`, checked: the series one the runtime records, the window 1 to 14 days in minutes. */
|
|
1764
|
+
function resolveHistoryArgs(flags) {
|
|
1765
|
+
const series = flags["--series"] ?? "cpu_millicores";
|
|
1766
|
+
if (!HISTORY_SERIES.includes(series)) fail(`--series ${series} is not a series the runtime records.`, `Use one of: ${HISTORY_SERIES.join(", ")}.`, "usage");
|
|
1767
|
+
const raw = flags["--minutes"] ?? "60";
|
|
1768
|
+
const minutes = Number(raw);
|
|
1769
|
+
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");
|
|
1770
|
+
return {
|
|
1771
|
+
series,
|
|
1772
|
+
minutes
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
/** A history value in the series' own unit, for a person. */
|
|
1776
|
+
function historyValue(series, value) {
|
|
1777
|
+
if (series === "memory_bytes") return `${(value / 1024 / 1024).toFixed(0)} MiB`;
|
|
1778
|
+
if (series === "cpu_millicores") return `${Math.round(value)}m`;
|
|
1779
|
+
return `${value.toFixed(1)} ms`;
|
|
1780
|
+
}
|
|
1653
1781
|
async function metricsCommand(rawArgs) {
|
|
1654
|
-
parseCloudArgs({
|
|
1655
|
-
spec:
|
|
1782
|
+
const { flags } = parseCloudArgs({
|
|
1783
|
+
spec: METRICS_FLAGS,
|
|
1656
1784
|
rawArgs,
|
|
1657
1785
|
commandWords: 2,
|
|
1658
1786
|
command: "cloud metrics",
|
|
1659
1787
|
maxPositionals: 0
|
|
1660
1788
|
});
|
|
1789
|
+
if (flags["--runtime"] && flags["--history"]) fail("--runtime and --history are two different reports; pass one.", "Run `rebase cloud metrics --help`.", "usage");
|
|
1790
|
+
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");
|
|
1791
|
+
const history = flags["--history"] ? resolveHistoryArgs(flags) : void 0;
|
|
1661
1792
|
const { client } = await requireClient(rawArgs);
|
|
1662
1793
|
const projectId = await requireProject(rawArgs, client);
|
|
1794
|
+
if (flags["--runtime"]) return runtimeMetrics(client, projectId, displayProjectRef(rawArgs) || projectId);
|
|
1795
|
+
if (history) return historyMetrics(client, projectId, displayProjectRef(rawArgs) || projectId, history);
|
|
1663
1796
|
try {
|
|
1664
1797
|
const [m, realtime] = await Promise.all([client.functions.invoke("metrics", void 0, {
|
|
1665
1798
|
method: "GET",
|
|
@@ -1724,6 +1857,104 @@ async function metricsCommand(rawArgs) {
|
|
|
1724
1857
|
reportError(e, "Failed to fetch metrics");
|
|
1725
1858
|
}
|
|
1726
1859
|
}
|
|
1860
|
+
/** `rebase cloud metrics --runtime`: what the app itself counted since it started. */
|
|
1861
|
+
async function runtimeMetrics(client, projectId, label) {
|
|
1862
|
+
let res;
|
|
1863
|
+
try {
|
|
1864
|
+
res = await client.functions.invoke("metrics", void 0, {
|
|
1865
|
+
method: "GET",
|
|
1866
|
+
path: `${projectId}/runtime`
|
|
1867
|
+
});
|
|
1868
|
+
} catch (e) {
|
|
1869
|
+
reportError(e, "Failed to fetch runtime metrics");
|
|
1870
|
+
}
|
|
1871
|
+
const r = res.rollup ?? null;
|
|
1872
|
+
const rate = r ? errorRate(r.totalRequests, r.totalErrors) : void 0;
|
|
1873
|
+
emit(() => {
|
|
1874
|
+
console.log("");
|
|
1875
|
+
console.log(chalk.bold(` 📈 Runtime — project ${label}`));
|
|
1876
|
+
console.log("");
|
|
1877
|
+
if (!r) {
|
|
1878
|
+
console.log(chalk.gray(" No data yet: the app is not deployed, is still starting, or does not report metrics."));
|
|
1879
|
+
console.log("");
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
keyValues([
|
|
1883
|
+
["Requests", r.totalRequests !== void 0 ? String(r.totalRequests) : void 0],
|
|
1884
|
+
["Errors (5xx)", r.totalErrors !== void 0 ? `${r.totalErrors}${rate ? ` (${rate})` : ""}` : void 0],
|
|
1885
|
+
["Mean latency", r.meanLatencyMs !== void 0 ? `${r.meanLatencyMs.toFixed(1)} ms` : void 0],
|
|
1886
|
+
["Up for", r.uptimeSeconds !== void 0 ? `${Math.round(r.uptimeSeconds / 60)} min` : void 0],
|
|
1887
|
+
["Memory (RSS)", r.rssBytes !== void 0 ? `${(r.rssBytes / 1024 / 1024).toFixed(0)} MiB` : void 0]
|
|
1888
|
+
]);
|
|
1889
|
+
if (r.surfaces?.length) {
|
|
1890
|
+
console.log("");
|
|
1891
|
+
console.log(chalk.gray(` ${"".padEnd(14)} ${"requests".padStart(9)} ${"errors".padStart(7)} ${"latency".padStart(9)}`));
|
|
1892
|
+
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)}`);
|
|
1893
|
+
}
|
|
1894
|
+
console.log("");
|
|
1895
|
+
note(chalk.gray("Counted by the running instance since it started; a restart begins again at zero."));
|
|
1896
|
+
console.log("");
|
|
1897
|
+
}, {
|
|
1898
|
+
projectId,
|
|
1899
|
+
at: res.at ?? null,
|
|
1900
|
+
rollup: r,
|
|
1901
|
+
errorRate: r && r.totalRequests ? (r.totalErrors ?? 0) / r.totalRequests : null
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
/** `rebase cloud metrics --history`: one series the runtime recorded, over a window. */
|
|
1905
|
+
async function historyMetrics(client, projectId, label, args) {
|
|
1906
|
+
let res;
|
|
1907
|
+
try {
|
|
1908
|
+
res = await client.functions.invoke("metrics", void 0, {
|
|
1909
|
+
method: "GET",
|
|
1910
|
+
path: `${projectId}/history?series=${encodeURIComponent(args.series)}&minutes=${args.minutes}`
|
|
1911
|
+
});
|
|
1912
|
+
} catch (e) {
|
|
1913
|
+
reportError(e, "Failed to fetch metric history");
|
|
1914
|
+
}
|
|
1915
|
+
const points = Array.isArray(res.points) ? res.points : null;
|
|
1916
|
+
const values = (points ?? []).map((p) => p.value).filter((v) => typeof v === "number" && Number.isFinite(v));
|
|
1917
|
+
const summary = values.length ? {
|
|
1918
|
+
min: Math.min(...values),
|
|
1919
|
+
max: Math.max(...values),
|
|
1920
|
+
mean: values.reduce((a, b) => a + b, 0) / values.length,
|
|
1921
|
+
latest: values[values.length - 1]
|
|
1922
|
+
} : null;
|
|
1923
|
+
emit(() => {
|
|
1924
|
+
console.log("");
|
|
1925
|
+
console.log(chalk.bold(` 🕘 ${args.series} — project ${label}, last ${args.minutes} min`));
|
|
1926
|
+
console.log("");
|
|
1927
|
+
if (!points) {
|
|
1928
|
+
console.log(chalk.yellow(` ${res.reason ?? "The control plane returned no history."}`));
|
|
1929
|
+
console.log("");
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
if (!summary) {
|
|
1933
|
+
console.log(chalk.gray(" Nothing recorded in this window."));
|
|
1934
|
+
console.log("");
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
keyValues([
|
|
1938
|
+
["Samples", String(values.length)],
|
|
1939
|
+
["Latest", historyValue(args.series, summary.latest)],
|
|
1940
|
+
["Mean", historyValue(args.series, summary.mean)],
|
|
1941
|
+
["Min", historyValue(args.series, summary.min)],
|
|
1942
|
+
["Max", historyValue(args.series, summary.max)]
|
|
1943
|
+
]);
|
|
1944
|
+
console.log("");
|
|
1945
|
+
note(chalk.gray("Every sample is in the JSON (`--json`): its time, value and how many instances it covers."));
|
|
1946
|
+
console.log("");
|
|
1947
|
+
}, {
|
|
1948
|
+
projectId,
|
|
1949
|
+
series: res.series ?? args.series,
|
|
1950
|
+
minutes: res.minutes ?? args.minutes,
|
|
1951
|
+
points,
|
|
1952
|
+
summary,
|
|
1953
|
+
reason: points ? null : res.reason ?? null,
|
|
1954
|
+
retryable: points ? null : res.retryable === true
|
|
1955
|
+
});
|
|
1956
|
+
if (!points) process.exitCode = 1;
|
|
1957
|
+
}
|
|
1727
1958
|
/**
|
|
1728
1959
|
* `rebase cloud webhooks` is retired, and says where to go instead.
|
|
1729
1960
|
*
|
|
@@ -1971,7 +2202,8 @@ var CLUSTERS_ACTIONS = [
|
|
|
1971
2202
|
"list",
|
|
1972
2203
|
"add",
|
|
1973
2204
|
"verify",
|
|
1974
|
-
"registry"
|
|
2205
|
+
"registry",
|
|
2206
|
+
"baseline"
|
|
1975
2207
|
];
|
|
1976
2208
|
/**
|
|
1977
2209
|
* `rebase cloud clusters` — list, register and verify the clusters tenants run on.
|
|
@@ -1985,6 +2217,7 @@ async function clustersCommand(action, rawArgs) {
|
|
|
1985
2217
|
if (action === "verify") return clustersVerifyCommand(rawArgs);
|
|
1986
2218
|
if (action === "add") return clustersAddCommand(rawArgs);
|
|
1987
2219
|
if (action === "registry") return clustersRegistryCommand(rawArgs);
|
|
2220
|
+
if (action === "baseline") return clustersBaselineCommand(rawArgs);
|
|
1988
2221
|
requireKnownAction("clusters", action, CLUSTERS_ACTIONS);
|
|
1989
2222
|
return clustersListCommand(rawArgs);
|
|
1990
2223
|
}
|
|
@@ -2060,6 +2293,104 @@ async function clustersVerifyCommand(rawArgs) {
|
|
|
2060
2293
|
}, report);
|
|
2061
2294
|
if (report.verdict === "unusable") process.exitCode = 1;
|
|
2062
2295
|
}
|
|
2296
|
+
/** What `clusters baseline` parses. */
|
|
2297
|
+
var CLUSTER_BASELINE_FLAGS = { "--install": Boolean };
|
|
2298
|
+
/** Which cluster `clusters baseline` was asked about, and whether to install. */
|
|
2299
|
+
function resolveClusterBaselineArgs(rawArgs) {
|
|
2300
|
+
const { flags, positionals } = parseCloudArgs({
|
|
2301
|
+
spec: CLUSTER_BASELINE_FLAGS,
|
|
2302
|
+
rawArgs,
|
|
2303
|
+
commandWords: 2,
|
|
2304
|
+
command: "cloud clusters baseline",
|
|
2305
|
+
maxPositionals: 2
|
|
2306
|
+
});
|
|
2307
|
+
return {
|
|
2308
|
+
id: positionals[1],
|
|
2309
|
+
install: flags["--install"] === true,
|
|
2310
|
+
yes: flags["--yes"] === true
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
/**
|
|
2314
|
+
* The cluster baseline — ingress-nginx, cert-manager, CloudNativePG — on one
|
|
2315
|
+
* cluster: what is installed and ready, and with `--install`, install what is
|
|
2316
|
+
* missing. Platform-admin only, like the rest of `clusters`: installing
|
|
2317
|
+
* operators is a cluster-wide act.
|
|
2318
|
+
*
|
|
2319
|
+
* The install runs in the background on the control plane; its progress lands
|
|
2320
|
+
* on the cluster's row, which a later `clusters baseline <id>` reads back.
|
|
2321
|
+
*/
|
|
2322
|
+
async function clustersBaselineCommand(rawArgs) {
|
|
2323
|
+
const { id, install, yes } = resolveClusterBaselineArgs(rawArgs);
|
|
2324
|
+
if (!id) fail("Usage: rebase cloud clusters baseline <cluster-id> [--install]", void 0, "bad_request");
|
|
2325
|
+
const { client } = await requireClient(rawArgs);
|
|
2326
|
+
const path = encodeURIComponent(id);
|
|
2327
|
+
if (install) {
|
|
2328
|
+
await confirmDestructive({
|
|
2329
|
+
yes,
|
|
2330
|
+
prompt: `Install the missing baseline components (ingress-nginx, cert-manager, CloudNativePG) on cluster ${id}? They are applied cluster-wide.`
|
|
2331
|
+
});
|
|
2332
|
+
let started;
|
|
2333
|
+
try {
|
|
2334
|
+
started = await client.functions.invoke("cluster-baseline", {}, {
|
|
2335
|
+
method: "POST",
|
|
2336
|
+
path
|
|
2337
|
+
});
|
|
2338
|
+
} catch (error) {
|
|
2339
|
+
reportError(error, "Could not start the baseline install");
|
|
2340
|
+
}
|
|
2341
|
+
emit(() => {
|
|
2342
|
+
success(`Installing the baseline on cluster ${id} in the background.`);
|
|
2343
|
+
note(`Follow it with ${chalk.cyan(`rebase cloud clusters baseline ${id}`)}.`);
|
|
2344
|
+
}, {
|
|
2345
|
+
clusterId: started.clusterId ?? id,
|
|
2346
|
+
started: started.started === true
|
|
2347
|
+
});
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
let report;
|
|
2351
|
+
try {
|
|
2352
|
+
report = await client.functions.invoke("cluster-baseline", void 0, {
|
|
2353
|
+
method: "GET",
|
|
2354
|
+
path
|
|
2355
|
+
});
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
reportError(error, "Could not read the cluster baseline");
|
|
2358
|
+
}
|
|
2359
|
+
let progress;
|
|
2360
|
+
try {
|
|
2361
|
+
const row = await client.data.table("clusters").findById(id);
|
|
2362
|
+
if (row) progress = {
|
|
2363
|
+
baselineStatus: typeof row.baselineStatus === "string" ? row.baselineStatus : null,
|
|
2364
|
+
baselineMessage: typeof row.baselineMessage === "string" ? row.baselineMessage : null
|
|
2365
|
+
};
|
|
2366
|
+
} catch {
|
|
2367
|
+
progress = void 0;
|
|
2368
|
+
}
|
|
2369
|
+
const components = report.components ?? [];
|
|
2370
|
+
emit(() => {
|
|
2371
|
+
console.log("");
|
|
2372
|
+
console.log(` ${report.ready ? chalk.green(chalk.bold("READY")) : chalk.yellow(chalk.bold("INCOMPLETE"))} ${chalk.gray(id)}`);
|
|
2373
|
+
console.log("");
|
|
2374
|
+
for (const c of components) {
|
|
2375
|
+
const state = c.ready ? chalk.green("ready") : c.installed ? chalk.yellow("installed, not ready") : chalk.red("missing");
|
|
2376
|
+
console.log(` ${(c.name ?? "?").padEnd(16)} ${state}${c.detail ? chalk.gray(` ${c.detail}`) : ""}`);
|
|
2377
|
+
}
|
|
2378
|
+
if (progress?.baselineStatus) {
|
|
2379
|
+
console.log("");
|
|
2380
|
+
keyValues([["Last install", progress.baselineStatus]]);
|
|
2381
|
+
}
|
|
2382
|
+
console.log("");
|
|
2383
|
+
if (!report.ready) {
|
|
2384
|
+
note(`Install what is missing with ${chalk.cyan(`rebase cloud clusters baseline ${id} --install`)}.`);
|
|
2385
|
+
console.log("");
|
|
2386
|
+
}
|
|
2387
|
+
}, {
|
|
2388
|
+
clusterId: id,
|
|
2389
|
+
ready: report.ready === true,
|
|
2390
|
+
components,
|
|
2391
|
+
install: progress ?? null
|
|
2392
|
+
});
|
|
2393
|
+
}
|
|
2063
2394
|
/**
|
|
2064
2395
|
* What `clusters add` was asked to register.
|
|
2065
2396
|
*
|
|
@@ -2336,29 +2667,62 @@ var BILLING_ACTIONS = [
|
|
|
2336
2667
|
"setup",
|
|
2337
2668
|
"checkout",
|
|
2338
2669
|
"invoices",
|
|
2339
|
-
"upcoming"
|
|
2670
|
+
"upcoming",
|
|
2671
|
+
"email"
|
|
2340
2672
|
];
|
|
2673
|
+
/** What `billing invoices` says on a control plane that has no invoice route yet. */
|
|
2674
|
+
var INVOICES_UNSERVED = {
|
|
2675
|
+
what: "invoices",
|
|
2676
|
+
hint: "`rebase cloud billing` shows the billing account and the card on file; Stripe emails each invoice to the billing email."
|
|
2677
|
+
};
|
|
2678
|
+
/** What `billing upcoming` says on a control plane that has no preview route yet. */
|
|
2679
|
+
var UPCOMING_UNSERVED = {
|
|
2680
|
+
what: "a preview of the next invoice",
|
|
2681
|
+
hint: "`rebase cloud compute` prints what a project is quoted per month."
|
|
2682
|
+
};
|
|
2341
2683
|
async function billingCommand(rawArgs) {
|
|
2342
2684
|
const parsed = parseCloudArgs({
|
|
2343
2685
|
spec: { "--limit": Number },
|
|
2344
2686
|
rawArgs,
|
|
2345
2687
|
commandWords: 2,
|
|
2346
2688
|
command: "cloud billing",
|
|
2347
|
-
maxPositionals:
|
|
2689
|
+
maxPositionals: 2
|
|
2348
2690
|
});
|
|
2349
2691
|
const action = parsed.positionals[0];
|
|
2350
2692
|
requireKnownAction("billing", action, BILLING_ACTIONS);
|
|
2351
2693
|
const limit = parsed.flags["--limit"];
|
|
2352
2694
|
if (limit !== void 0 && action !== "invoices") fail("`--limit` applies to `rebase cloud billing invoices` only.", void 0, "usage");
|
|
2695
|
+
const address = parsed.positionals[1];
|
|
2696
|
+
if (address !== void 0 && action !== "email") fail(`Too many arguments for \`rebase cloud billing${action ? ` ${action}` : ""}\`: ${address}`, "Run `rebase cloud billing --help`.", "usage");
|
|
2697
|
+
if (action === "email" && !address?.trim()) fail("Name the address invoices go to.", "`rebase cloud billing email billing@example.com`.", "usage");
|
|
2353
2698
|
const { client, url } = await requireClient(rawArgs);
|
|
2354
2699
|
const org = getContextOrg(url);
|
|
2700
|
+
if (action === "email") {
|
|
2701
|
+
if (!org) fail("No active organization.", "Run `rebase cloud use` first.", "no_org");
|
|
2702
|
+
let res;
|
|
2703
|
+
try {
|
|
2704
|
+
res = await client.functions.invoke("stripe-billing", {
|
|
2705
|
+
organizationId: org,
|
|
2706
|
+
billingEmail: address.trim()
|
|
2707
|
+
}, { path: "billing-email" });
|
|
2708
|
+
} catch (e) {
|
|
2709
|
+
reportError(e, "Failed to change the billing email");
|
|
2710
|
+
}
|
|
2711
|
+
const billingEmail = res.billingEmail ?? address.trim();
|
|
2712
|
+
emit(() => success(`Invoices for org ${org} now go to ${chalk.bold(billingEmail)}.`), {
|
|
2713
|
+
org,
|
|
2714
|
+
billingEmail
|
|
2715
|
+
});
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2355
2718
|
if (action === "invoices" || action === "upcoming") {
|
|
2356
2719
|
if (!org) fail("No active organization.", "Run `rebase cloud use` first.", "no_org");
|
|
2357
2720
|
try {
|
|
2358
2721
|
if (action === "invoices") await billingInvoices(client, org, limit);
|
|
2359
2722
|
else await billingUpcoming(client, org);
|
|
2360
2723
|
} catch (e) {
|
|
2361
|
-
|
|
2724
|
+
if (action === "invoices") reportCallError(e, "Failed to load invoices", INVOICES_UNSERVED);
|
|
2725
|
+
reportCallError(e, "Failed to load the next invoice", UPCOMING_UNSERVED);
|
|
2362
2726
|
}
|
|
2363
2727
|
return;
|
|
2364
2728
|
}
|
|
@@ -2563,7 +2927,7 @@ async function computeCommand(action, rawArgs) {
|
|
|
2563
2927
|
requireKnownAction("compute", action, COMPUTE_ACTIONS);
|
|
2564
2928
|
if (action === "apply") return computeApplyCommand(rawArgs);
|
|
2565
2929
|
if (action === "window") return computeWindowCommand(rawArgs);
|
|
2566
|
-
parseCloudArgs({
|
|
2930
|
+
const { flags: computeFlags } = parseCloudArgs({
|
|
2567
2931
|
spec: action === "set" ? {
|
|
2568
2932
|
...COMPUTE_SET_FLAGS,
|
|
2569
2933
|
[RETIRED_SCALE_TO_ZERO]: String
|
|
@@ -2579,7 +2943,9 @@ async function computeCommand(action, rawArgs) {
|
|
|
2579
2943
|
if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`, void 0, "not_found");
|
|
2580
2944
|
if (action !== "set") {
|
|
2581
2945
|
let quote;
|
|
2582
|
-
const
|
|
2946
|
+
const maintenanceRead = await readMaintenance(client, projectId);
|
|
2947
|
+
const maintenance = maintenanceRead.kind === "ok" ? maintenanceRead.status : void 0;
|
|
2948
|
+
const notServed = maintenanceRead.kind === "not_served" ? ["maintenance"] : [];
|
|
2583
2949
|
try {
|
|
2584
2950
|
quote = await client.functions.invoke("pricing", project, {
|
|
2585
2951
|
method: "POST",
|
|
@@ -2620,6 +2986,7 @@ async function computeCommand(action, rawArgs) {
|
|
|
2620
2986
|
}
|
|
2621
2987
|
console.log("");
|
|
2622
2988
|
noteBlank();
|
|
2989
|
+
if (notServed.length > 0) note(chalk.gray(MAINTENANCE_NOT_SERVED_NOTE));
|
|
2623
2990
|
note("Empty means the platform default. Change one with:");
|
|
2624
2991
|
note(chalk.cyan(" rebase cloud compute set --cpu 500m --memory 2Gi"));
|
|
2625
2992
|
console.log("");
|
|
@@ -2642,13 +3009,24 @@ async function computeCommand(action, rawArgs) {
|
|
|
2642
3009
|
maintenance: maintenance ? {
|
|
2643
3010
|
window: maintenance.window,
|
|
2644
3011
|
pending: maintenance.open
|
|
2645
|
-
} : null
|
|
3012
|
+
} : null,
|
|
3013
|
+
notServed
|
|
2646
3014
|
});
|
|
2647
3015
|
return;
|
|
2648
3016
|
}
|
|
2649
3017
|
const built = buildDialPatch(rawArgs);
|
|
2650
3018
|
if (built.error) fail(built.error, void 0, "bad_request");
|
|
2651
3019
|
const patch = built.patch;
|
|
3020
|
+
const [quoteNow, quoteAfter] = await Promise.all([quoteDials(client, project), quoteDials(client, {
|
|
3021
|
+
...project,
|
|
3022
|
+
...patch
|
|
3023
|
+
})]);
|
|
3024
|
+
const changes = Object.entries(patch).map(([field, value]) => `${field} → ${String(value)}`).join(", ");
|
|
3025
|
+
const price = quoteAfter ? ` Quoted €${quoteAfter.totalEur.toFixed(2)}/month${quoteNow ? ` (now €${quoteNow.totalEur.toFixed(2)})` : ""}.` : "";
|
|
3026
|
+
await confirmDestructive({
|
|
3027
|
+
yes: Boolean(computeFlags["--yes"]),
|
|
3028
|
+
prompt: `Change ${changes} on ${displayProjectRef(rawArgs) || projectId}?${price} The app rolls its pods now; a database change waits for the maintenance window.`
|
|
3029
|
+
});
|
|
2652
3030
|
try {
|
|
2653
3031
|
await client.data.table("projects").update(projectId, patch);
|
|
2654
3032
|
} catch (error) {
|
|
@@ -2674,6 +3052,21 @@ async function computeCommand(action, rawArgs) {
|
|
|
2674
3052
|
});
|
|
2675
3053
|
}
|
|
2676
3054
|
/**
|
|
3055
|
+
* What the control plane quotes for a project's dials, or undefined when it
|
|
3056
|
+
* cannot say. Never throws: a price is context for a question, not its answer.
|
|
3057
|
+
*/
|
|
3058
|
+
async function quoteDials(client, dials) {
|
|
3059
|
+
try {
|
|
3060
|
+
const quote = await client.functions.invoke("pricing", dials, {
|
|
3061
|
+
method: "POST",
|
|
3062
|
+
path: "quote"
|
|
3063
|
+
});
|
|
3064
|
+
return typeof quote?.totalEur === "number" ? quote : void 0;
|
|
3065
|
+
} catch {
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
/**
|
|
2677
3070
|
* A dial's value, or a marker that the platform default decides it.
|
|
2678
3071
|
*
|
|
2679
3072
|
* The two are different states and the distinction is not cosmetic: an unset
|
|
@@ -3002,6 +3395,11 @@ function pipeThroughTunnel(socket, endpoint, token) {
|
|
|
3002
3395
|
* The control plane's `db-access` function does the work; how it keeps this
|
|
3003
3396
|
* read-only and to the named addresses is documented there.
|
|
3004
3397
|
*/
|
|
3398
|
+
/** What `db access` says on a control plane that has no `db-access` function yet. */
|
|
3399
|
+
var DB_ACCESS_UNSERVED = {
|
|
3400
|
+
what: "external database access",
|
|
3401
|
+
hint: "Nothing was changed. `rebase cloud db connect` opens a tunnel to the database from this machine."
|
|
3402
|
+
};
|
|
3005
3403
|
var DB_ACCESS_ACTIONS = [
|
|
3006
3404
|
"status",
|
|
3007
3405
|
"enable",
|
|
@@ -3067,9 +3465,15 @@ async function dbAccessCommand(rawArgs) {
|
|
|
3067
3465
|
const action = positionals[0] || "status";
|
|
3068
3466
|
requireKnownAction("db access", action, DB_ACCESS_ACTIONS);
|
|
3069
3467
|
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");
|
|
3468
|
+
const allow = action === "enable" ? list(flags["--allow"]) : void 0;
|
|
3469
|
+
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
3470
|
const { client } = await requireClient(rawArgs);
|
|
3071
3471
|
const projectId = await requireProject(rawArgs, client);
|
|
3072
3472
|
const projectRef = displayProjectRef(rawArgs);
|
|
3473
|
+
if (action === "enable") await confirmDestructive({
|
|
3474
|
+
yes: Boolean(flags["--yes"]),
|
|
3475
|
+
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.`
|
|
3476
|
+
});
|
|
3073
3477
|
try {
|
|
3074
3478
|
if (action === "status") {
|
|
3075
3479
|
const status = await client.functions.invoke("db-access", void 0, {
|
|
@@ -3084,8 +3488,6 @@ async function dbAccessCommand(rawArgs) {
|
|
|
3084
3488
|
return;
|
|
3085
3489
|
}
|
|
3086
3490
|
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
3491
|
const status = await client.functions.invoke("db-access", {
|
|
3090
3492
|
allow,
|
|
3091
3493
|
schemas: list(flags["--schemas"]),
|
|
@@ -3142,7 +3544,7 @@ async function dbAccessCommand(rawArgs) {
|
|
|
3142
3544
|
...revealed
|
|
3143
3545
|
});
|
|
3144
3546
|
} catch (e) {
|
|
3145
|
-
|
|
3547
|
+
reportCallError(e, `Failed to ${action === "status" ? "read" : action} external database access`, DB_ACCESS_UNSERVED);
|
|
3146
3548
|
}
|
|
3147
3549
|
}
|
|
3148
3550
|
//#endregion
|
|
@@ -4048,6 +4450,11 @@ async function createProject(rawArgs) {
|
|
|
4048
4450
|
const check = await client.functions.invoke("check-subdomain", { subdomain });
|
|
4049
4451
|
if (!check.available) fail(`Subdomain "${subdomain}" is not available${check.reason ? ` (${check.reason})` : ""}.`, void 0, "subdomain_unavailable");
|
|
4050
4452
|
} catch {}
|
|
4453
|
+
const databaseLabel = dbChoice === "managed" ? "a managed database" : dbChoice === "byodb" ? "your own database" : "no database";
|
|
4454
|
+
await confirmDestructive({
|
|
4455
|
+
yes: Boolean(args["--yes"]),
|
|
4456
|
+
prompt: `Create project ${name} at ${subdomain} in org ${org}, with ${databaseLabel}? Its compute and managed database are billed from its first deploy.`
|
|
4457
|
+
});
|
|
4051
4458
|
try {
|
|
4052
4459
|
const user = await client.auth.getUser();
|
|
4053
4460
|
if (!user) fail("Session is no longer valid.", "Run `rebase cloud login` again.", "session_invalid");
|
|
@@ -4245,1386 +4652,72 @@ async function projectInfo(rawArgs, projectRef) {
|
|
|
4245
4652
|
host: projectHost(p, baseDomain) ?? null,
|
|
4246
4653
|
customDomain: p.customDomain ?? null,
|
|
4247
4654
|
repository: p.gitRepoUrl ?? null,
|
|
4248
|
-
branch: p.gitBranch ?? null,
|
|
4249
|
-
provider: p.provider ?? null,
|
|
4250
|
-
region: p.region ?? null,
|
|
4251
|
-
status: p.status ?? null,
|
|
4252
|
-
org: p.organization !== void 0 ? String(p.organization) : null,
|
|
4253
|
-
database: db ? {
|
|
4254
|
-
type: db.type ?? null,
|
|
4255
|
-
connectionStatus: db.connectionStatus ?? null,
|
|
4256
|
-
capacity: capacity ?? null
|
|
4257
|
-
} : null,
|
|
4258
|
-
lastDeploy: lastDeploy ? {
|
|
4259
|
-
id: String(lastDeploy.id),
|
|
4260
|
-
status: lastDeploy.status ?? null,
|
|
4261
|
-
createdAt: lastDeploy.createdAt ?? null
|
|
4262
|
-
} : null
|
|
4263
|
-
});
|
|
4264
|
-
} catch (e) {
|
|
4265
|
-
reportError(e, "Failed to load project");
|
|
4266
|
-
}
|
|
4267
|
-
}
|
|
4268
|
-
async function deleteProject(rawArgs, projectRef) {
|
|
4269
|
-
const { flags: args } = parseCloudArgs({
|
|
4270
|
-
spec: {},
|
|
4271
|
-
rawArgs,
|
|
4272
|
-
commandWords: 3,
|
|
4273
|
-
command: "cloud projects delete",
|
|
4274
|
-
maxPositionals: 1
|
|
4275
|
-
});
|
|
4276
|
-
const { client } = await requireClient(rawArgs);
|
|
4277
|
-
const projectId = await resolveProjectRef(projectRef, client);
|
|
4278
|
-
const p = await client.data.table("projects").findById(projectId).catch(() => void 0);
|
|
4279
|
-
if (!p) fail(`Project ${projectRef} not found.`, void 0, "project_not_found");
|
|
4280
|
-
await confirmDestructive({
|
|
4281
|
-
yes: Boolean(args["--yes"]),
|
|
4282
|
-
prompt: `Permanently delete project "${p.name ?? projectRef}" (${p.subdomain ?? projectRef})? This tears down its deployment.`
|
|
4283
|
-
});
|
|
4284
|
-
try {
|
|
4285
|
-
await client.data.table("projects").delete(projectId);
|
|
4286
|
-
success(`Deleted project ${chalk.bold(p.name ?? projectId)}`);
|
|
4287
|
-
emit(() => {}, {
|
|
4288
|
-
success: true,
|
|
4289
|
-
id: projectId,
|
|
4290
|
-
name: p.name ?? null,
|
|
4291
|
-
slug: p.subdomain ?? null
|
|
4292
|
-
});
|
|
4293
|
-
} catch (e) {
|
|
4294
|
-
reportError(e, "Failed to delete project");
|
|
4295
|
-
}
|
|
4296
|
-
}
|
|
4297
|
-
async function firstRow(client, collection, projectId) {
|
|
4298
|
-
return (await client.data.table(collection).find({
|
|
4299
|
-
where: { project: ["==", projectId] },
|
|
4300
|
-
limit: 1
|
|
4301
|
-
})).data[0];
|
|
4302
|
-
}
|
|
4303
|
-
async function latestDeployment(client, projectId) {
|
|
4304
|
-
return (await client.data.table("deployments").find({
|
|
4305
|
-
where: { project: ["==", projectId] },
|
|
4306
|
-
orderBy: ["createdAt", "desc"],
|
|
4307
|
-
limit: 1
|
|
4308
|
-
})).data[0];
|
|
4309
|
-
}
|
|
4310
|
-
function fmtDate(value) {
|
|
4311
|
-
if (!value) return "—";
|
|
4312
|
-
const d = new Date(value);
|
|
4313
|
-
return isNaN(d.getTime()) ? value : d.toLocaleString();
|
|
4314
|
-
}
|
|
4315
|
-
//#endregion
|
|
4316
|
-
//#region src/commands/cloud/debug.ts
|
|
4317
|
-
/**
|
|
4318
|
-
* `rebase cloud debug <subcommand>` — one entry point for "why is my deployed
|
|
4319
|
-
* app not behaving".
|
|
4320
|
-
*
|
|
4321
|
-
* ## Why this exists
|
|
4322
|
-
*
|
|
4323
|
-
* The useful signals for a deployed project live in four different places — the
|
|
4324
|
-
* control plane, the workload's pods, the tenant database, and the public URL —
|
|
4325
|
-
* and each is normally reached with a different tool and a different set of
|
|
4326
|
-
* flags. Getting to a log should not be a research task. This started life as a
|
|
4327
|
-
* hand-rolled `prod-debug.sh` for a single project, with the namespace and the
|
|
4328
|
-
* URL hardcoded at the top; it earned its place twice in one week, so it is
|
|
4329
|
-
* generalised here to any project the CLI can already resolve.
|
|
4330
|
-
*
|
|
4331
|
-
* ## Read-only by default
|
|
4332
|
-
*
|
|
4333
|
-
* Every subcommand here only reads. The two things the original script could do
|
|
4334
|
-
* that mutate are deliberately NOT reproduced as-is:
|
|
4335
|
-
*
|
|
4336
|
-
* - restarting the workload lives at `rebase cloud restart`, which already
|
|
4337
|
-
* gates downtime behind `--yes`; duplicating it here would give the same
|
|
4338
|
-
* destructive act a second, ungated spelling.
|
|
4339
|
-
* - `debug db` prints the port-forward recipe and the connection's *shape*.
|
|
4340
|
-
* It opens no session and prints no password — `rebase cloud db info
|
|
4341
|
-
* --reveal` is the explicit, auditable way to get one.
|
|
4342
|
-
*
|
|
4343
|
-
* ## The probes are the point
|
|
4344
|
-
*
|
|
4345
|
-
* `debug health` is the highest-value piece and the reason the script existed.
|
|
4346
|
-
* A bare status code is not a diagnosis: a 404 from a functions route means
|
|
4347
|
-
* something completely different from a 404 at the root, and a 200 on an
|
|
4348
|
-
* unauthenticated read is a finding rather than a success. So every probe ships
|
|
4349
|
-
* with the interpretation of what it got, not just the number — see
|
|
4350
|
-
* {@link PROBES}.
|
|
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"
|
|
4356
|
-
};
|
|
4357
|
-
function serverError(what) {
|
|
4358
|
-
return {
|
|
4359
|
-
verdict: "fail",
|
|
4360
|
-
meaning: `the server is running but ${what}`
|
|
4361
|
-
};
|
|
4362
|
-
}
|
|
4363
|
-
/**
|
|
4364
|
-
* The probe set, in the order a failure cascades: if `health` is down, nothing
|
|
4365
|
-
* below it is meaningful, so it is checked first and reported first.
|
|
4366
|
-
*/
|
|
4367
|
-
var PROBES = [
|
|
4368
|
-
{
|
|
4369
|
-
id: "health",
|
|
4370
|
-
label: "health",
|
|
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",
|
|
4476
|
-
method: "GET",
|
|
4477
|
-
/**
|
|
4478
|
-
* The router's own listing endpoint, NOT a function's path.
|
|
4479
|
-
*
|
|
4480
|
-
* This matters, and it is the one place the original script got a wrong
|
|
4481
|
-
* answer. A function is a Hono sub-app mounted at `/<name>`, and it
|
|
4482
|
-
* usually defines only sub-routes (`/get`, `/list`) — so
|
|
4483
|
-
* `/api/functions/<name>` 404s **even when everything is mounted and
|
|
4484
|
-
* healthy**. Probing there cannot separate "the router is missing" from
|
|
4485
|
-
* "that function defines no root route", and reporting the first is how
|
|
4486
|
-
* you send someone to debug a deployment that was fine.
|
|
4487
|
-
*
|
|
4488
|
-
* `GET /api/functions` is unambiguous: the router registers a listing
|
|
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
|
-
}
|
|
4528
|
-
}
|
|
4529
|
-
];
|
|
4530
|
-
/** The function names out of a listing body, or null when it is not one. */
|
|
4531
|
-
function functionNames(body) {
|
|
4532
|
-
const list = body?.functions;
|
|
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;
|
|
4536
|
-
}
|
|
4537
|
-
/** Milliseconds before a probe is treated as unanswered. */
|
|
4538
|
-
var PROBE_TIMEOUT_MS = 1e4;
|
|
4539
|
-
/**
|
|
4540
|
-
* Ceiling on a probe body we will parse. The only body read is the function
|
|
4541
|
-
* listing; anything larger is a page we have no use for, and a debug command
|
|
4542
|
-
* must not be the thing that runs a machine out of memory.
|
|
4543
|
-
*/
|
|
4544
|
-
var MAX_PROBE_BODY_BYTES = 256 * 1024;
|
|
4545
|
-
/**
|
|
4546
|
-
* Run one probe. A transport failure is a `null` status, never a thrown error:
|
|
4547
|
-
* "nothing answered" is a diagnosis in its own right and the other probes still
|
|
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
|
-
};
|
|
4994
|
-
}
|
|
4995
|
-
async function logView(rawArgs, view) {
|
|
4996
|
-
const { flags: parsed } = parseCloudArgs({
|
|
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
|
-
});
|
|
5074
|
-
}
|
|
5075
|
-
async function requestsCommand(rawArgs) {
|
|
5076
|
-
const { flags: parsed } = parseCloudArgs({
|
|
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);
|
|
5087
|
-
let res;
|
|
5088
|
-
try {
|
|
5089
|
-
res = await fetchRuntimeLogs(client, projectId, {
|
|
5090
|
-
sinceSeconds,
|
|
5091
|
-
tailLines: tail.applied
|
|
5092
|
-
});
|
|
5093
|
-
} catch (e) {
|
|
5094
|
-
reportError(e, "Failed to fetch runtime logs");
|
|
5095
|
-
}
|
|
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
|
-
emit(() => {
|
|
5106
|
-
console.log("");
|
|
5107
|
-
console.log(chalk.bold(` 🌐 Requests — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${windowLabel(sinceSeconds)}`));
|
|
5108
|
-
console.log("");
|
|
5109
|
-
printPodStates(res);
|
|
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
|
-
}
|
|
5122
|
-
console.log("");
|
|
5123
|
-
printCoverage(coverage, tail);
|
|
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
|
-
});
|
|
5142
|
-
}
|
|
5143
|
-
async function podCommand(rawArgs) {
|
|
5144
|
-
parseCloudArgs({
|
|
5145
|
-
spec: {},
|
|
5146
|
-
rawArgs,
|
|
5147
|
-
commandWords: 3,
|
|
5148
|
-
command: "cloud debug",
|
|
5149
|
-
maxPositionals: 0
|
|
5150
|
-
});
|
|
5151
|
-
const { client } = await requireClient(rawArgs);
|
|
5152
|
-
const projectId = await requireProject(rawArgs, client);
|
|
5153
|
-
let m;
|
|
5154
|
-
try {
|
|
5155
|
-
m = await client.functions.invoke("metrics", void 0, {
|
|
5156
|
-
method: "GET",
|
|
5157
|
-
path: projectId
|
|
5158
|
-
});
|
|
5159
|
-
} catch (e) {
|
|
5160
|
-
reportError(e, "Failed to read workload placement");
|
|
5161
|
-
}
|
|
5162
|
-
const p = m.placement ?? {};
|
|
5163
|
-
const replicas = p.replicas ?? {};
|
|
5164
|
-
emit(() => {
|
|
5165
|
-
console.log("");
|
|
5166
|
-
console.log(chalk.bold(` ☸ Workload — ${displayProjectRef(rawArgs)}`));
|
|
5167
|
-
console.log("");
|
|
5168
|
-
keyValues([
|
|
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
|
-
});
|
|
5189
|
-
}
|
|
5190
|
-
async function dbDebugCommand(rawArgs) {
|
|
5191
|
-
parseCloudArgs({
|
|
5192
|
-
spec: {},
|
|
5193
|
-
rawArgs,
|
|
5194
|
-
commandWords: 3,
|
|
5195
|
-
command: "cloud debug",
|
|
5196
|
-
maxPositionals: 0
|
|
5197
|
-
});
|
|
5198
|
-
const { client } = await requireClient(rawArgs);
|
|
5199
|
-
const projectId = await requireProject(rawArgs, client);
|
|
5200
|
-
let info;
|
|
5201
|
-
try {
|
|
5202
|
-
info = await client.functions.invoke("db-info", void 0, {
|
|
5203
|
-
method: "GET",
|
|
5204
|
-
path: projectId
|
|
5205
|
-
});
|
|
5206
|
-
} catch (e) {
|
|
5207
|
-
reportError(e, "Failed to read database connection info");
|
|
5208
|
-
}
|
|
5209
|
-
const access = info.directAccess;
|
|
5210
|
-
const connectCmd = access ? "rebase cloud db connect" : null;
|
|
5211
|
-
const psqlCmd = access && info.username && info.database ? `psql -h 127.0.0.1 -p 5432 -U ${info.username} -d ${info.database}` : null;
|
|
5212
|
-
const kubectlCmd = access?.kubectl ? `kubectl port-forward -n ${access.kubectl.namespace} svc/${access.kubectl.service} ${access.kubectl.localPort}:${access.kubectl.remotePort}` : null;
|
|
5213
|
-
emit(() => {
|
|
5214
|
-
console.log("");
|
|
5215
|
-
console.log(chalk.bold(` 🐘 Database — ${displayProjectRef(rawArgs)}`));
|
|
5216
|
-
console.log("");
|
|
5217
|
-
if (info.unavailableReason) {
|
|
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
|
-
}
|
|
5247
|
-
}
|
|
5248
|
-
}, {
|
|
5249
|
-
type: info.type ?? null,
|
|
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");
|
|
5300
|
-
}
|
|
5301
|
-
}
|
|
5302
|
-
/**
|
|
5303
|
-
* The log flags as one action's help lists them, with THAT action's defaults.
|
|
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
|
-
]
|
|
5374
|
-
});
|
|
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;
|
|
5453
|
-
try {
|
|
5454
|
-
res = await fetch(`${origin}${path}`, {
|
|
5455
|
-
headers: {
|
|
5456
|
-
Authorization: `Bearer ${token}`,
|
|
5457
|
-
Accept: "application/json"
|
|
5458
|
-
},
|
|
5459
|
-
redirect: "manual",
|
|
5460
|
-
signal: AbortSignal.timeout(RUNTIME_TIMEOUT_MS)
|
|
5461
|
-
});
|
|
5462
|
-
} catch (e) {
|
|
5463
|
-
fail(`Could not reach the app at ${origin}: ${e instanceof Error ? e.message : String(e)}`, "`rebase cloud debug health` checks whether the deployment is answering at all.", "runtime_unreachable");
|
|
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;
|
|
5471
|
-
}
|
|
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
|
-
});
|
|
4655
|
+
branch: p.gitBranch ?? null,
|
|
4656
|
+
provider: p.provider ?? null,
|
|
4657
|
+
region: p.region ?? null,
|
|
4658
|
+
status: p.status ?? null,
|
|
4659
|
+
org: p.organization !== void 0 ? String(p.organization) : null,
|
|
4660
|
+
database: db ? {
|
|
4661
|
+
type: db.type ?? null,
|
|
4662
|
+
connectionStatus: db.connectionStatus ?? null,
|
|
4663
|
+
capacity: capacity ?? null
|
|
4664
|
+
} : null,
|
|
4665
|
+
lastDeploy: lastDeploy ? {
|
|
4666
|
+
id: String(lastDeploy.id),
|
|
4667
|
+
status: lastDeploy.status ?? null,
|
|
4668
|
+
createdAt: lastDeploy.createdAt ?? null
|
|
4669
|
+
} : null
|
|
4670
|
+
});
|
|
4671
|
+
} catch (e) {
|
|
4672
|
+
reportError(e, "Failed to load project");
|
|
4673
|
+
}
|
|
5572
4674
|
}
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
"--host": String
|
|
5577
|
-
};
|
|
5578
|
-
async function logsCommand$1(rawArgs) {
|
|
5579
|
-
const { flags, positionals } = parseCloudArgs({
|
|
5580
|
-
spec: CRON_LOGS_FLAGS,
|
|
4675
|
+
async function deleteProject(rawArgs, projectRef) {
|
|
4676
|
+
const { flags: args } = parseCloudArgs({
|
|
4677
|
+
spec: {},
|
|
5581
4678
|
rawArgs,
|
|
5582
4679
|
commandWords: 3,
|
|
5583
|
-
command: "cloud
|
|
4680
|
+
command: "cloud projects delete",
|
|
5584
4681
|
maxPositionals: 1
|
|
5585
4682
|
});
|
|
5586
|
-
const
|
|
5587
|
-
|
|
5588
|
-
const
|
|
5589
|
-
if (
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
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
|
-
emit(() => {
|
|
5598
|
-
console.log("");
|
|
5599
|
-
console.log(chalk.bold(` 📜 Cron runs — ${jobId} on ${displayProjectRef(rawArgs)}`) + chalk.gray(` newest first, ${logs.length} run${logs.length === 1 ? "" : "s"}`));
|
|
5600
|
-
console.log("");
|
|
5601
|
-
if (logs.length === 0) {
|
|
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
|
|
4683
|
+
const { client } = await requireClient(rawArgs);
|
|
4684
|
+
const projectId = await resolveProjectRef(projectRef, client);
|
|
4685
|
+
const p = await client.data.table("projects").findById(projectId).catch(() => void 0);
|
|
4686
|
+
if (!p) fail(`Project ${projectRef} not found.`, void 0, "project_not_found");
|
|
4687
|
+
await confirmDestructive({
|
|
4688
|
+
yes: Boolean(args["--yes"]),
|
|
4689
|
+
prompt: `Permanently delete project "${p.name ?? projectRef}" (${p.subdomain ?? projectRef})? This tears down its deployment.`
|
|
5618
4690
|
});
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
4691
|
+
try {
|
|
4692
|
+
await client.data.table("projects").delete(projectId);
|
|
4693
|
+
success(`Deleted project ${chalk.bold(p.name ?? projectId)}`);
|
|
4694
|
+
emit(() => {}, {
|
|
4695
|
+
success: true,
|
|
4696
|
+
id: projectId,
|
|
4697
|
+
name: p.name ?? null,
|
|
4698
|
+
slug: p.subdomain ?? null
|
|
4699
|
+
});
|
|
4700
|
+
} catch (e) {
|
|
4701
|
+
reportError(e, "Failed to delete project");
|
|
5626
4702
|
}
|
|
5627
|
-
|
|
4703
|
+
}
|
|
4704
|
+
async function firstRow(client, collection, projectId) {
|
|
4705
|
+
return (await client.data.table(collection).find({
|
|
4706
|
+
where: { project: ["==", projectId] },
|
|
4707
|
+
limit: 1
|
|
4708
|
+
})).data[0];
|
|
4709
|
+
}
|
|
4710
|
+
async function latestDeployment(client, projectId) {
|
|
4711
|
+
return (await client.data.table("deployments").find({
|
|
4712
|
+
where: { project: ["==", projectId] },
|
|
4713
|
+
orderBy: ["createdAt", "desc"],
|
|
4714
|
+
limit: 1
|
|
4715
|
+
})).data[0];
|
|
4716
|
+
}
|
|
4717
|
+
function fmtDate(value) {
|
|
4718
|
+
if (!value) return "—";
|
|
4719
|
+
const d = new Date(value);
|
|
4720
|
+
return isNaN(d.getTime()) ? value : d.toLocaleString();
|
|
5628
4721
|
}
|
|
5629
4722
|
//#endregion
|
|
5630
4723
|
//#region src/commands/cloud/env.ts
|
|
@@ -5970,11 +5063,12 @@ function resolveEnvKeyArgs(rawArgs, action) {
|
|
|
5970
5063
|
});
|
|
5971
5064
|
return {
|
|
5972
5065
|
key: positionals[0],
|
|
5973
|
-
preview: flags["--preview"] === true
|
|
5066
|
+
preview: flags["--preview"] === true,
|
|
5067
|
+
yes: flags["--yes"] === true
|
|
5974
5068
|
};
|
|
5975
5069
|
}
|
|
5976
5070
|
async function unsetEnv(rawArgs, action) {
|
|
5977
|
-
const { key, preview } = resolveEnvKeyArgs(rawArgs, action);
|
|
5071
|
+
const { key, preview, yes } = resolveEnvKeyArgs(rawArgs, action);
|
|
5978
5072
|
if (!key) fail("Usage: rebase cloud env unset KEY [--preview]", void 0, "usage");
|
|
5979
5073
|
const { client } = await requireClient(rawArgs);
|
|
5980
5074
|
const projectId = await requireProject(rawArgs, client);
|
|
@@ -6004,6 +5098,10 @@ async function unsetEnv(rawArgs, action) {
|
|
|
6004
5098
|
});
|
|
6005
5099
|
return;
|
|
6006
5100
|
}
|
|
5101
|
+
await confirmDestructive({
|
|
5102
|
+
yes,
|
|
5103
|
+
prompt: `Remove ${key} from project ${displayProjectRef(rawArgs) || projectId}? Its value is deleted, and the next deploy runs without it.`
|
|
5104
|
+
});
|
|
6007
5105
|
try {
|
|
6008
5106
|
emit(() => {
|
|
6009
5107
|
success(`Removed ${chalk.bold(key)}`);
|
|
@@ -6197,8 +5295,8 @@ function printEnvHelp() {
|
|
|
6197
5295
|
{
|
|
6198
5296
|
action: "unset",
|
|
6199
5297
|
args: "KEY",
|
|
6200
|
-
description: "Remove a variable",
|
|
6201
|
-
flags: [["--preview", "Only from previews: production keeps it"]]
|
|
5298
|
+
description: "Remove a variable. Asks first; --yes skips the prompt",
|
|
5299
|
+
flags: [["--preview", "Only from previews: production keeps it. Asks nothing: `reset` undoes it"]]
|
|
6202
5300
|
},
|
|
6203
5301
|
{
|
|
6204
5302
|
action: "reset",
|
|
@@ -7983,7 +7081,7 @@ function normalizePreviewName(raw) {
|
|
|
7983
7081
|
function isRecord$1(value) {
|
|
7984
7082
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7985
7083
|
}
|
|
7986
|
-
function text(row, ...keys) {
|
|
7084
|
+
function text$1(row, ...keys) {
|
|
7987
7085
|
for (const key of keys) {
|
|
7988
7086
|
const value = row[key];
|
|
7989
7087
|
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
@@ -7997,21 +7095,21 @@ function text(row, ...keys) {
|
|
|
7997
7095
|
*/
|
|
7998
7096
|
function previewFrom(value) {
|
|
7999
7097
|
if (!isRecord$1(value)) return null;
|
|
8000
|
-
const name = text(value, "name");
|
|
8001
|
-
const url = text(value, "url");
|
|
7098
|
+
const name = text$1(value, "name");
|
|
7099
|
+
const url = text$1(value, "url");
|
|
8002
7100
|
if (!name || !url) return null;
|
|
8003
|
-
const backend = text(value, "backend");
|
|
7101
|
+
const backend = text$1(value, "backend");
|
|
8004
7102
|
return {
|
|
8005
7103
|
name,
|
|
8006
7104
|
url: /^https?:\/\//.test(url) ? url : `https://${url}`,
|
|
8007
|
-
app: text(value, "app"),
|
|
7105
|
+
app: text$1(value, "app"),
|
|
8008
7106
|
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")
|
|
7107
|
+
status: text$1(value, "status"),
|
|
7108
|
+
statusMessage: text$1(value, "statusMessage", "status_message"),
|
|
7109
|
+
deploymentId: text$1(value, "deploymentId", "deployment_id"),
|
|
7110
|
+
createdAt: text$1(value, "createdAt", "created_at"),
|
|
7111
|
+
updatedAt: text$1(value, "updatedAt", "updated_at"),
|
|
7112
|
+
expiresAt: text$1(value, "expiresAt", "expires_at")
|
|
8015
7113
|
};
|
|
8016
7114
|
}
|
|
8017
7115
|
/**
|
|
@@ -8071,7 +7169,7 @@ async function triggerPreview(client, projectId, body, refusal) {
|
|
|
8071
7169
|
reportError(e, "Preview deploy failed to start");
|
|
8072
7170
|
}
|
|
8073
7171
|
const deployment = isRecord$1(res) && isRecord$1(res.deployment) ? res.deployment : void 0;
|
|
8074
|
-
const deploymentId = deployment ? text(deployment, "id") : null;
|
|
7172
|
+
const deploymentId = deployment ? text$1(deployment, "id") : null;
|
|
8075
7173
|
const preview = isRecord$1(res) ? previewFrom(res.preview) : null;
|
|
8076
7174
|
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
7175
|
return {
|
|
@@ -8475,6 +7573,75 @@ function recordFilter(opts) {
|
|
|
8475
7573
|
return true;
|
|
8476
7574
|
};
|
|
8477
7575
|
}
|
|
7576
|
+
/**
|
|
7577
|
+
* The newest `tail` records of each pod, in their original order. Lines with
|
|
7578
|
+
* no pod prefix count as one pod of their own.
|
|
7579
|
+
*/
|
|
7580
|
+
function tailPerPod(records, tail) {
|
|
7581
|
+
const seen = /* @__PURE__ */ new Map();
|
|
7582
|
+
const keep = new Array(records.length).fill(false);
|
|
7583
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
7584
|
+
const pod = records[i].pod;
|
|
7585
|
+
const n = seen.get(pod) ?? 0;
|
|
7586
|
+
if (n >= tail) continue;
|
|
7587
|
+
seen.set(pod, n + 1);
|
|
7588
|
+
keep[i] = true;
|
|
7589
|
+
}
|
|
7590
|
+
return records.filter((_, i) => keep[i]);
|
|
7591
|
+
}
|
|
7592
|
+
/**
|
|
7593
|
+
* Apply `--grep`/`--level` to everything a page holds, then keep the newest
|
|
7594
|
+
* `tail` matches per pod.
|
|
7595
|
+
*
|
|
7596
|
+
* The control plane cannot filter: it tails each pod's log and answers with
|
|
7597
|
+
* that. So a filtered read asks it for as many lines as it gives
|
|
7598
|
+
* ({@link SERVER_MAX_TAIL_LINES}) and does both steps here. Tailing first and
|
|
7599
|
+
* filtering after — what this used to do — searched only the newest `tail`
|
|
7600
|
+
* lines, so `--since 6h --tail 40 --grep X` found nothing where `--tail 2000`
|
|
7601
|
+
* found X two hours back.
|
|
7602
|
+
*
|
|
7603
|
+
* Whatever the server did not return could not be searched, and that is said
|
|
7604
|
+
* rather than passed off as "no match": a pod that returned the full
|
|
7605
|
+
* `scanLimit` lines has older lines in the window, and a pod (or the page)
|
|
7606
|
+
* the server marked truncated was cut by a byte budget.
|
|
7607
|
+
*/
|
|
7608
|
+
function filterThenTail(page, filter, tail, scanLimit = SERVER_MAX_TAIL_LINES) {
|
|
7609
|
+
const all = parseRecords(page.logs);
|
|
7610
|
+
const matched = all.filter(filter);
|
|
7611
|
+
const records = tailPerPod(matched, tail);
|
|
7612
|
+
const count = (recs, pod) => recs.reduce((n, r) => n + (r.pod === pod ? 1 : 0), 0);
|
|
7613
|
+
const pods = (page.pods ?? []).map((p) => {
|
|
7614
|
+
const scannedLines = typeof p.lines === "number" ? p.lines : count(all, p.pod);
|
|
7615
|
+
const scanCapped = p.state === "ok" && (p.truncated === true || scannedLines >= scanLimit);
|
|
7616
|
+
return {
|
|
7617
|
+
...p,
|
|
7618
|
+
lines: count(records, p.pod),
|
|
7619
|
+
scannedLines,
|
|
7620
|
+
matchedLines: count(matched, p.pod),
|
|
7621
|
+
scanCapped
|
|
7622
|
+
};
|
|
7623
|
+
});
|
|
7624
|
+
const onlyLines = pods.length === 0 && all.length >= scanLimit;
|
|
7625
|
+
const capped = pods.filter((p) => p.scanCapped);
|
|
7626
|
+
const scanCapped = capped.length > 0 || page.truncated === true || onlyLines;
|
|
7627
|
+
let note = null;
|
|
7628
|
+
if (scanCapped) {
|
|
7629
|
+
const reach = capped.map((p) => {
|
|
7630
|
+
const first = all.find((r) => r.pod === p.pod && r.ts !== null)?.ts ?? null;
|
|
7631
|
+
return first ? `${p.pod} from ${first}` : p.pod;
|
|
7632
|
+
}).join(", ");
|
|
7633
|
+
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.`;
|
|
7634
|
+
}
|
|
7635
|
+
return {
|
|
7636
|
+
records,
|
|
7637
|
+
pods,
|
|
7638
|
+
scannedLines: all.length,
|
|
7639
|
+
matchedLines: matched.length,
|
|
7640
|
+
returnedLines: records.length,
|
|
7641
|
+
scanCapped,
|
|
7642
|
+
note
|
|
7643
|
+
};
|
|
7644
|
+
}
|
|
8478
7645
|
function msOf(ts) {
|
|
8479
7646
|
if (ts === null) return null;
|
|
8480
7647
|
const ms = Date.parse(ts);
|
|
@@ -8694,7 +7861,9 @@ async function followRuntimeLogs(deps, opts) {
|
|
|
8694
7861
|
if (!(e instanceof PollTimeout) && !deps.isTransient(e)) throw e;
|
|
8695
7862
|
}
|
|
8696
7863
|
}
|
|
8697
|
-
|
|
7864
|
+
const fresh = cursor.admit(records).filter(opts.filter);
|
|
7865
|
+
const isFirstPage = q === opts.initial;
|
|
7866
|
+
for (const rec of isFirstPage && opts.initialTail !== void 0 ? tailPerPod(fresh, opts.initialTail) : fresh) sink.line(rec);
|
|
8698
7867
|
const tailCut = q !== opts.initial && q.tailLines !== void 0 && pods.some((p) => p.state === "ok" && p.lines >= q.tailLines);
|
|
8699
7868
|
if (page.truncated || pods.some((p) => p.truncated) || tailCut) sink.event({
|
|
8700
7869
|
event: "truncated",
|
|
@@ -9085,6 +8254,8 @@ async function deployBundle(opts) {
|
|
|
9085
8254
|
return;
|
|
9086
8255
|
}
|
|
9087
8256
|
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");
|
|
8257
|
+
const standalone = target.app.type === "static" ? standaloneStaticRefusal(target.name, target.app) : void 0;
|
|
8258
|
+
if (standalone) fail(standalone.message, standalone.hint, "usage");
|
|
9088
8259
|
if (target.app.type === "static") {
|
|
9089
8260
|
progress(chalk.gray(` Building static app "${target.name}"...`));
|
|
9090
8261
|
let staticDir;
|
|
@@ -9179,6 +8350,22 @@ var STATIC_UNDO_HINT = "Something wrong? A static app deployed on its own cannot
|
|
|
9179
8350
|
* by uploading it. `--no-verify` is the way past for a file the check gets
|
|
9180
8351
|
* wrong.
|
|
9181
8352
|
*/
|
|
8353
|
+
/**
|
|
8354
|
+
* Why a static app cannot be deployed on its own, or `undefined` when it can.
|
|
8355
|
+
*
|
|
8356
|
+
* A static app deployed alone is served by a process with no functions, so
|
|
8357
|
+
* routes to custom functions would have nothing to call: the runtime refuses
|
|
8358
|
+
* to boot such a bundle, and an older one would answer every routed path with
|
|
8359
|
+
* the app's index.html. Deploying the backend folds the app in, and that one
|
|
8360
|
+
* process serves the app, its routes and the functions together.
|
|
8361
|
+
*/
|
|
8362
|
+
function standaloneStaticRefusal(name, app) {
|
|
8363
|
+
if (!app.routes?.length) return void 0;
|
|
8364
|
+
return {
|
|
8365
|
+
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.`,
|
|
8366
|
+
hint: "Deploy the project's backend instead: its bundle folds this app in, and one process serves both."
|
|
8367
|
+
};
|
|
8368
|
+
}
|
|
9182
8369
|
function verifyStaticOutput(projectRoot, apps) {
|
|
9183
8370
|
const errors = [];
|
|
9184
8371
|
let checked = 0;
|
|
@@ -9684,6 +8871,11 @@ function ejectWarning(projectRef) {
|
|
|
9684
8871
|
function ejectRefusal(opts, projectRef) {
|
|
9685
8872
|
if (!opts.managed || opts.eject) return void 0;
|
|
9686
8873
|
const eject = "To eject on purpose, add `--eject`.";
|
|
8874
|
+
if (opts.git) return {
|
|
8875
|
+
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.`,
|
|
8876
|
+
hint: `Ship it to the managed runtime from a checkout with \`rebase cloud deploy\`. ${eject}`,
|
|
8877
|
+
code: "managed_project"
|
|
8878
|
+
};
|
|
9687
8879
|
if (opts.source) return {
|
|
9688
8880
|
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
8881
|
hint: `Deploy this directory to the managed runtime with \`rebase cloud deploy --bundle\`. ${eject}`,
|
|
@@ -9865,9 +9057,29 @@ var DEPLOY_FLAGS = {
|
|
|
9865
9057
|
"--allow-downgrade": Boolean,
|
|
9866
9058
|
"--preview": Boolean,
|
|
9867
9059
|
"--preview-name": String,
|
|
9060
|
+
"--git": Boolean,
|
|
9868
9061
|
"-m": "--message"
|
|
9869
9062
|
};
|
|
9870
9063
|
/**
|
|
9064
|
+
* The flags that describe a build made on this machine, which `--git` — a
|
|
9065
|
+
* build the control plane makes from the repository — cannot honour. Refused
|
|
9066
|
+
* rather than ignored: either reading would ship something other than what the
|
|
9067
|
+
* line asked for.
|
|
9068
|
+
*/
|
|
9069
|
+
var LOCAL_BUILD_FLAGS = [
|
|
9070
|
+
"--source",
|
|
9071
|
+
"--bundle",
|
|
9072
|
+
"--bundle-dir",
|
|
9073
|
+
"--skip-type-check",
|
|
9074
|
+
"--skip-schema",
|
|
9075
|
+
"--no-static",
|
|
9076
|
+
"--no-source",
|
|
9077
|
+
"--no-verify",
|
|
9078
|
+
"--allow-downgrade",
|
|
9079
|
+
"--preview",
|
|
9080
|
+
"--preview-name"
|
|
9081
|
+
];
|
|
9082
|
+
/**
|
|
9871
9083
|
* `rebase cloud deploy [app]` — its flags, and which app of this repository the
|
|
9872
9084
|
* line named.
|
|
9873
9085
|
*
|
|
@@ -9931,6 +9143,10 @@ async function deployCommand(rawArgs, projectRef) {
|
|
|
9931
9143
|
if (!isJsonMode() && process.stdout.isTTY !== true) note(chalk.gray("Printing the deploy summary. For the machine-readable result, pass --json."));
|
|
9932
9144
|
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
9145
|
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");
|
|
9146
|
+
if (args["--git"]) {
|
|
9147
|
+
await deployFromGit(rawArgs, projectRef, startedAt);
|
|
9148
|
+
return;
|
|
9149
|
+
}
|
|
9934
9150
|
const preview = resolvePreviewRequest(args);
|
|
9935
9151
|
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
9152
|
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 +9301,132 @@ async function deployCommand(rawArgs, projectRef) {
|
|
|
10085
9301
|
}
|
|
10086
9302
|
});
|
|
10087
9303
|
}
|
|
9304
|
+
/**
|
|
9305
|
+
* `rebase cloud deploy --git [<branch>]` — the control plane builds the
|
|
9306
|
+
* project's connected repository, as the hosted connector's `deploy` tool does,
|
|
9307
|
+
* and this follows the deployment the way every other one is followed.
|
|
9308
|
+
*
|
|
9309
|
+
* Nothing on this machine is read, built or uploaded: the repository and its
|
|
9310
|
+
* branch are the build's whole input. Without a branch, the control plane
|
|
9311
|
+
* builds the one configured on the project (`rebase cloud settings`).
|
|
9312
|
+
*/
|
|
9313
|
+
async function deployFromGit(rawArgs, projectRef, startedAt) {
|
|
9314
|
+
const { flags: args, appName: branchArg } = resolveDeployArgs(rawArgs);
|
|
9315
|
+
const local = LOCAL_BUILD_FLAGS.filter((flag) => args[flag] !== void 0 && args[flag] !== false);
|
|
9316
|
+
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");
|
|
9317
|
+
const branch = branchArg?.trim() || void 0;
|
|
9318
|
+
const { client, url } = await requireClient(rawArgs);
|
|
9319
|
+
const projectId = await resolveProjectRef(projectRef, client);
|
|
9320
|
+
await requirePaymentMethod(client, projectId);
|
|
9321
|
+
const { project, recent, readable } = await readDeployContext(client, projectId);
|
|
9322
|
+
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");
|
|
9323
|
+
const projectRow = project;
|
|
9324
|
+
const repo = pick(projectRow, "gitRepoUrl", "git_repo_url");
|
|
9325
|
+
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");
|
|
9326
|
+
const eject = {
|
|
9327
|
+
managed: isManagedProject(project, recent[0]),
|
|
9328
|
+
source: false,
|
|
9329
|
+
eject: args["--eject"] === true,
|
|
9330
|
+
git: true
|
|
9331
|
+
};
|
|
9332
|
+
const refusal = ejectRefusal(eject, projectRef);
|
|
9333
|
+
if (refusal) fail(refusal.message, refusal.hint, refusal.code);
|
|
9334
|
+
const warnings = deployWarnings(eject, projectRef);
|
|
9335
|
+
for (const w of warnings) warn(w.message, w.hint);
|
|
9336
|
+
const builds = branch ?? pick(projectRow, "gitBranch", "git_branch");
|
|
9337
|
+
if (!isJsonMode()) {
|
|
9338
|
+
console.log("");
|
|
9339
|
+
console.log(chalk.gray(` Building from git: ${repo ?? "the connected repository"}${builds ? ` (${builds})` : ""}.`));
|
|
9340
|
+
console.log(chalk.gray(" This directory is NOT uploaded — the control plane clones the repository."));
|
|
9341
|
+
console.log("");
|
|
9342
|
+
console.log(` 🚀 Triggering deployment for project ${chalk.bold(projectRef)} from git...`);
|
|
9343
|
+
}
|
|
9344
|
+
const body = {
|
|
9345
|
+
projectId,
|
|
9346
|
+
client: "cli"
|
|
9347
|
+
};
|
|
9348
|
+
if (branch) body.branch = branch;
|
|
9349
|
+
if (args["--message"]) body.message = args["--message"];
|
|
9350
|
+
let triggered;
|
|
9351
|
+
try {
|
|
9352
|
+
const res = await client.functions.invoke("deploy", body);
|
|
9353
|
+
if (!res?.deployment?.id) fail("Control plane did not return a deployment id.");
|
|
9354
|
+
triggered = {
|
|
9355
|
+
deploymentId: String(res.deployment.id),
|
|
9356
|
+
deduplicated: res.deduplicated === true,
|
|
9357
|
+
hosts: deployHostsFrom(res)
|
|
9358
|
+
};
|
|
9359
|
+
} catch (e) {
|
|
9360
|
+
resolveTriggerFailure(e);
|
|
9361
|
+
}
|
|
9362
|
+
const { deploymentId, deduplicated, hosts } = triggered;
|
|
9363
|
+
if (!isJsonMode()) console.log(chalk.gray(` Deployment ${deploymentId} created.`));
|
|
9364
|
+
const appsAt = (host) => sourceBuildApps(sourceBuildAppName(), host);
|
|
9365
|
+
const json = {
|
|
9366
|
+
deploymentId,
|
|
9367
|
+
deduplicated,
|
|
9368
|
+
source: "git",
|
|
9369
|
+
branch: builds ?? null,
|
|
9370
|
+
...warningPayload(warnings)
|
|
9371
|
+
};
|
|
9372
|
+
if (args["--no-follow"]) {
|
|
9373
|
+
await reportTriggered({
|
|
9374
|
+
client,
|
|
9375
|
+
url,
|
|
9376
|
+
projectId,
|
|
9377
|
+
deploymentId,
|
|
9378
|
+
appsAt,
|
|
9379
|
+
registeredHosts: hosts,
|
|
9380
|
+
headline: "",
|
|
9381
|
+
json: {
|
|
9382
|
+
...json,
|
|
9383
|
+
following: false
|
|
9384
|
+
}
|
|
9385
|
+
});
|
|
9386
|
+
await recordDeploy({
|
|
9387
|
+
followed: false,
|
|
9388
|
+
status: "not_followed",
|
|
9389
|
+
deduplicated,
|
|
9390
|
+
startedAt
|
|
9391
|
+
});
|
|
9392
|
+
return;
|
|
9393
|
+
}
|
|
9394
|
+
if (!isJsonMode()) {
|
|
9395
|
+
console.log(chalk.gray(" Streaming build logs (Ctrl-C to stop watching — the build keeps running):"));
|
|
9396
|
+
console.log("");
|
|
9397
|
+
}
|
|
9398
|
+
const { status } = await streamBuildLogs(client, deploymentId, {
|
|
9399
|
+
quiet: isJsonMode(),
|
|
9400
|
+
timeoutMs: resolveDeployTimeout(args["--timeout"]),
|
|
9401
|
+
projectId,
|
|
9402
|
+
url,
|
|
9403
|
+
announce: false,
|
|
9404
|
+
failedApps: appsAt(void 0).map((a) => a.name),
|
|
9405
|
+
onTerminal: (ended) => recordDeploy({
|
|
9406
|
+
followed: true,
|
|
9407
|
+
status: ended,
|
|
9408
|
+
deduplicated,
|
|
9409
|
+
startedAt
|
|
9410
|
+
})
|
|
9411
|
+
});
|
|
9412
|
+
await reportDeployed({
|
|
9413
|
+
undo: ROLLBACK_HINT,
|
|
9414
|
+
client,
|
|
9415
|
+
url,
|
|
9416
|
+
projectId,
|
|
9417
|
+
projectRef,
|
|
9418
|
+
deploymentId,
|
|
9419
|
+
startedAt,
|
|
9420
|
+
liveTimeoutMs: resolveLiveTimeout(args["--live-timeout"]),
|
|
9421
|
+
appsAt,
|
|
9422
|
+
registeredHosts: hosts,
|
|
9423
|
+
json: {
|
|
9424
|
+
...json,
|
|
9425
|
+
following: true,
|
|
9426
|
+
status
|
|
9427
|
+
}
|
|
9428
|
+
});
|
|
9429
|
+
}
|
|
10088
9430
|
/** The backend this repository declares, for naming a source build in its summary. */
|
|
10089
9431
|
function sourceBuildAppName() {
|
|
10090
9432
|
try {
|
|
@@ -10423,20 +9765,22 @@ async function logsCommand(rawArgs, projectRef) {
|
|
|
10423
9765
|
const preview = args["--preview"] ? await resolvePreviewRef(client, projectId, previewRef) : void 0;
|
|
10424
9766
|
if (args["--runtime"]) {
|
|
10425
9767
|
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");
|
|
9768
|
+
const matchTail = tail?.requested ?? 500;
|
|
10426
9769
|
const query = {
|
|
10427
9770
|
...since ?? {},
|
|
10428
|
-
...tail ? { tailLines: tail.applied } : {},
|
|
9771
|
+
...filtered ? { tailLines: SERVER_MAX_TAIL_LINES } : tail ? { tailLines: tail.applied } : {},
|
|
10429
9772
|
...args["--previous"] ? { previous: true } : {},
|
|
10430
9773
|
...preview ? { preview: preview.name } : {}
|
|
10431
9774
|
};
|
|
10432
9775
|
const subject = preview ? `preview ${preview.name}` : `project ${projectRef}`;
|
|
10433
|
-
if (tail?.note) note(chalk.yellow(tail.note));
|
|
9776
|
+
if (tail?.note && !filtered) note(chalk.yellow(tail.note));
|
|
10434
9777
|
if (args["--follow"]) {
|
|
10435
9778
|
await followRuntime(client, projectId, {
|
|
10436
9779
|
query,
|
|
10437
9780
|
filter,
|
|
10438
9781
|
subject,
|
|
10439
|
-
preview: preview?.name
|
|
9782
|
+
preview: preview?.name,
|
|
9783
|
+
...filtered ? { initialTail: matchTail } : {}
|
|
10440
9784
|
});
|
|
10441
9785
|
return;
|
|
10442
9786
|
}
|
|
@@ -10446,7 +9790,8 @@ async function logsCommand(rawArgs, projectRef) {
|
|
|
10446
9790
|
} catch (e) {
|
|
10447
9791
|
reportError(e, "Failed to fetch runtime logs");
|
|
10448
9792
|
}
|
|
10449
|
-
const
|
|
9793
|
+
const read = filterThenTail(page, filter, filtered ? matchTail : Number.MAX_SAFE_INTEGER);
|
|
9794
|
+
const records = read.records;
|
|
10450
9795
|
const logs = filtered ? records.map((r) => r.raw).join("\n") : page.logs ?? null;
|
|
10451
9796
|
emit(() => {
|
|
10452
9797
|
console.log("");
|
|
@@ -10456,15 +9801,31 @@ async function logsCommand(rawArgs, projectRef) {
|
|
|
10456
9801
|
if (records.length > 0) for (const r of records) console.log(paintLine(r));
|
|
10457
9802
|
else console.log(chalk.gray(filtered && page.logs ? " (no line matches)" : " (no logs)"));
|
|
10458
9803
|
console.log("");
|
|
9804
|
+
if (filtered && page.logs) {
|
|
9805
|
+
const kept = read.returnedLines < read.matchedLines ? `the newest ${matchTail} per pod of ${read.matchedLines} matching lines` : `${read.matchedLines} matching line${read.matchedLines === 1 ? "" : "s"}`;
|
|
9806
|
+
console.log(chalk.gray(` ${kept}, from ${read.scannedLines} searched.`));
|
|
9807
|
+
if (read.note) console.log(chalk.yellow(` ${read.note}`));
|
|
9808
|
+
console.log("");
|
|
9809
|
+
}
|
|
10459
9810
|
}, {
|
|
10460
9811
|
runtime: true,
|
|
10461
9812
|
preview: preview?.name ?? null,
|
|
10462
9813
|
logs,
|
|
10463
|
-
pods: page.pods ?? [],
|
|
9814
|
+
pods: filtered ? read.pods : page.pods ?? [],
|
|
10464
9815
|
state: page.state ?? null,
|
|
10465
9816
|
message: page.message ?? null,
|
|
10466
9817
|
truncated: page.truncated === true,
|
|
10467
|
-
nextSinceTime: page.nextSinceTime ?? null
|
|
9818
|
+
nextSinceTime: page.nextSinceTime ?? null,
|
|
9819
|
+
...filtered ? { filter: {
|
|
9820
|
+
grep: args["--grep"] ?? null,
|
|
9821
|
+
level: level ?? null,
|
|
9822
|
+
tail: matchTail,
|
|
9823
|
+
scannedLines: read.scannedLines,
|
|
9824
|
+
matchedLines: read.matchedLines,
|
|
9825
|
+
returnedLines: read.returnedLines,
|
|
9826
|
+
scanCapped: read.scanCapped,
|
|
9827
|
+
note: read.note
|
|
9828
|
+
} } : {}
|
|
10468
9829
|
});
|
|
10469
9830
|
return;
|
|
10470
9831
|
}
|
|
@@ -10682,7 +10043,8 @@ async function followRuntime(client, projectId, opts) {
|
|
|
10682
10043
|
isTransient: transientReadFailure
|
|
10683
10044
|
}, {
|
|
10684
10045
|
initial: opts.query,
|
|
10685
|
-
filter: opts.filter
|
|
10046
|
+
filter: opts.filter,
|
|
10047
|
+
...opts.initialTail !== void 0 ? { initialTail: opts.initialTail } : {}
|
|
10686
10048
|
});
|
|
10687
10049
|
} catch (e) {
|
|
10688
10050
|
reportError(e, "Failed to follow runtime logs");
|
|
@@ -10694,7 +10056,7 @@ async function followRuntime(client, projectId, opts) {
|
|
|
10694
10056
|
//#endregion
|
|
10695
10057
|
//#region src/commands/cloud/orgs.ts
|
|
10696
10058
|
/**
|
|
10697
|
-
* `rebase cloud orgs` — list / create / members / invites.
|
|
10059
|
+
* `rebase cloud orgs` — list / create / rename / delete / members / invites.
|
|
10698
10060
|
*
|
|
10699
10061
|
* Members: list, invite by email, remove, change a role. Inviting goes through
|
|
10700
10062
|
* the control plane's `invites` function, which always opens an invitation —
|
|
@@ -10705,6 +10067,11 @@ async function followRuntime(client, projectId, opts) {
|
|
|
10705
10067
|
* the output says whether it did. Inviting takes a `rebase cloud login`
|
|
10706
10068
|
* session — a token cannot hand out access to an organization.
|
|
10707
10069
|
*/
|
|
10070
|
+
/** What the invitation commands say on a control plane that has no `invites` function yet. */
|
|
10071
|
+
var INVITES_UNSERVED = {
|
|
10072
|
+
what: "invitations",
|
|
10073
|
+
hint: "Nothing was sent or changed. `rebase cloud orgs members` still lists, removes and re-roles the members an organization has."
|
|
10074
|
+
};
|
|
10708
10075
|
async function orgsCommand(subcommand, rawArgs) {
|
|
10709
10076
|
switch (subcommand) {
|
|
10710
10077
|
case "list":
|
|
@@ -10714,6 +10081,12 @@ async function orgsCommand(subcommand, rawArgs) {
|
|
|
10714
10081
|
case "create":
|
|
10715
10082
|
await createOrg(rawArgs);
|
|
10716
10083
|
break;
|
|
10084
|
+
case "rename":
|
|
10085
|
+
await renameOrg(rawArgs);
|
|
10086
|
+
break;
|
|
10087
|
+
case "delete":
|
|
10088
|
+
await deleteOrg(rawArgs);
|
|
10089
|
+
break;
|
|
10717
10090
|
case "members":
|
|
10718
10091
|
await membersCommand(rawArgs);
|
|
10719
10092
|
break;
|
|
@@ -10782,37 +10155,128 @@ async function createOrg(rawArgs) {
|
|
|
10782
10155
|
maxPositionals: 0
|
|
10783
10156
|
});
|
|
10784
10157
|
const { client, url } = await requireClient(rawArgs);
|
|
10785
|
-
const prompts = [];
|
|
10786
|
-
if (!args["--name"]) {
|
|
10787
|
-
requireInteractive("an organization name", "--name <name>");
|
|
10788
|
-
prompts.push({
|
|
10789
|
-
type: "input",
|
|
10790
|
-
name: "name",
|
|
10791
|
-
message: "Organization name:"
|
|
10792
|
-
});
|
|
10158
|
+
const prompts = [];
|
|
10159
|
+
if (!args["--name"]) {
|
|
10160
|
+
requireInteractive("an organization name", "--name <name>");
|
|
10161
|
+
prompts.push({
|
|
10162
|
+
type: "input",
|
|
10163
|
+
name: "name",
|
|
10164
|
+
message: "Organization name:"
|
|
10165
|
+
});
|
|
10166
|
+
}
|
|
10167
|
+
const answers = prompts.length ? await inquirer.prompt(prompts) : {};
|
|
10168
|
+
const name = (args["--name"] || answers.name || "").trim();
|
|
10169
|
+
if (!name) fail("Organization name is required.", "Pass `--name <name>`.", "input_required");
|
|
10170
|
+
const slug = (args["--slug"] || slugify(name)).trim();
|
|
10171
|
+
try {
|
|
10172
|
+
const created = requireCloudRow(await client.data.table("organizations").create({
|
|
10173
|
+
name,
|
|
10174
|
+
slug,
|
|
10175
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
10176
|
+
}), "organization");
|
|
10177
|
+
setContextOrg(url, String(created.id));
|
|
10178
|
+
success(`Created organization ${chalk.bold(name)} and set it active`);
|
|
10179
|
+
emit(() => {}, {
|
|
10180
|
+
success: true,
|
|
10181
|
+
id: String(created.id),
|
|
10182
|
+
name,
|
|
10183
|
+
slug,
|
|
10184
|
+
setActive: true
|
|
10185
|
+
});
|
|
10186
|
+
} catch (e) {
|
|
10187
|
+
reportError(e, "Failed to create organization");
|
|
10188
|
+
}
|
|
10189
|
+
}
|
|
10190
|
+
/** What `rebase cloud orgs rename` parses. Its page is the group's own. */
|
|
10191
|
+
var RENAME_ORG_FLAGS = {
|
|
10192
|
+
"--slug": String,
|
|
10193
|
+
"--org": String
|
|
10194
|
+
};
|
|
10195
|
+
/**
|
|
10196
|
+
* Rename an organization, and with `--slug` change its slug. A plain update of
|
|
10197
|
+
* the `organizations` row: the control plane lets its owners and admins make
|
|
10198
|
+
* it, and refuses a slug another organization holds.
|
|
10199
|
+
*/
|
|
10200
|
+
async function renameOrg(rawArgs) {
|
|
10201
|
+
const { flags, positionals } = parseCloudArgs({
|
|
10202
|
+
spec: RENAME_ORG_FLAGS,
|
|
10203
|
+
rawArgs,
|
|
10204
|
+
commandWords: 3,
|
|
10205
|
+
command: "cloud orgs",
|
|
10206
|
+
maxPositionals: 1
|
|
10207
|
+
});
|
|
10208
|
+
const name = positionals[0]?.trim();
|
|
10209
|
+
const slug = flags["--slug"]?.trim();
|
|
10210
|
+
if (!name) fail("Name the organization's new name.", "`rebase cloud orgs rename \"Acme Inc\" [--slug acme]`.", "usage");
|
|
10211
|
+
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");
|
|
10212
|
+
const { client, url } = await requireClient(rawArgs);
|
|
10213
|
+
const org = orgFor(flags["--org"], url);
|
|
10214
|
+
const patch = { name };
|
|
10215
|
+
if (slug) patch.slug = slug;
|
|
10216
|
+
try {
|
|
10217
|
+
await client.data.table("organizations").update(org, patch);
|
|
10218
|
+
} catch (e) {
|
|
10219
|
+
reportError(e, "Failed to rename the organization");
|
|
10220
|
+
}
|
|
10221
|
+
emit(() => success(`Organization ${org} is now ${chalk.bold(name)}${slug ? ` (${slug})` : ""}`), {
|
|
10222
|
+
success: true,
|
|
10223
|
+
id: org,
|
|
10224
|
+
...patch
|
|
10225
|
+
});
|
|
10226
|
+
}
|
|
10227
|
+
/**
|
|
10228
|
+
* Delete an organization. Asks first, and refuses while it still has projects:
|
|
10229
|
+
* deleting each project is what tears down its namespace and database and
|
|
10230
|
+
* cancels its subscription, and the control plane will not let an
|
|
10231
|
+
* organization's deletion skip that. The check here names them before asking;
|
|
10232
|
+
* the control plane's own refusal is the authority.
|
|
10233
|
+
*/
|
|
10234
|
+
async function deleteOrg(rawArgs) {
|
|
10235
|
+
const { flags } = parseCloudArgs({
|
|
10236
|
+
spec: { "--org": String },
|
|
10237
|
+
rawArgs,
|
|
10238
|
+
commandWords: 3,
|
|
10239
|
+
command: "cloud orgs",
|
|
10240
|
+
maxPositionals: 0
|
|
10241
|
+
});
|
|
10242
|
+
const { client, url } = await requireClient(rawArgs);
|
|
10243
|
+
const org = orgFor(flags["--org"], url);
|
|
10244
|
+
let row;
|
|
10245
|
+
let projects;
|
|
10246
|
+
try {
|
|
10247
|
+
row = cloudRow(await client.data.table("organizations").findById(org));
|
|
10248
|
+
projects = cloudRows((await client.data.table("projects").find({
|
|
10249
|
+
where: { organization: ["==", org] },
|
|
10250
|
+
limit: 20
|
|
10251
|
+
})).data);
|
|
10252
|
+
} catch (e) {
|
|
10253
|
+
reportError(e, "Failed to read the organization");
|
|
10793
10254
|
}
|
|
10794
|
-
|
|
10795
|
-
const
|
|
10796
|
-
if (
|
|
10797
|
-
|
|
10255
|
+
if (!row) fail(`No organization ${org} that you can see.`, "`rebase cloud orgs` lists yours.", "not_found");
|
|
10256
|
+
const label = row.name ? `${row.name} (${org})` : org;
|
|
10257
|
+
if (projects.length > 0) {
|
|
10258
|
+
const names = projects.map((p) => String(p.subdomain ?? p.name ?? p.id)).sort();
|
|
10259
|
+
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");
|
|
10260
|
+
}
|
|
10261
|
+
await confirmDestructive({
|
|
10262
|
+
yes: Boolean(flags["--yes"]),
|
|
10263
|
+
prompt: `Delete organization ${label}? Its members lose it, and this cannot be undone.`
|
|
10264
|
+
});
|
|
10798
10265
|
try {
|
|
10799
|
-
|
|
10800
|
-
name,
|
|
10801
|
-
slug,
|
|
10802
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
10803
|
-
}), "organization");
|
|
10804
|
-
setContextOrg(url, String(created.id));
|
|
10805
|
-
success(`Created organization ${chalk.bold(name)} and set it active`);
|
|
10806
|
-
emit(() => {}, {
|
|
10807
|
-
success: true,
|
|
10808
|
-
id: String(created.id),
|
|
10809
|
-
name,
|
|
10810
|
-
slug,
|
|
10811
|
-
setActive: true
|
|
10812
|
-
});
|
|
10266
|
+
await client.data.table("organizations").delete(org);
|
|
10813
10267
|
} catch (e) {
|
|
10814
|
-
reportError(e, "Failed to
|
|
10268
|
+
reportError(e, "Failed to delete the organization");
|
|
10815
10269
|
}
|
|
10270
|
+
const wasActive = getContextOrg(url) === org;
|
|
10271
|
+
if (wasActive) setContextOrg(url, void 0);
|
|
10272
|
+
emit(() => {
|
|
10273
|
+
success(`Deleted organization ${label}`);
|
|
10274
|
+
if (wasActive) note(chalk.gray("It was the active organization; pick another with `rebase cloud use`."));
|
|
10275
|
+
}, {
|
|
10276
|
+
success: true,
|
|
10277
|
+
deleted: org,
|
|
10278
|
+
wasActive
|
|
10279
|
+
});
|
|
10816
10280
|
}
|
|
10817
10281
|
var MEMBER_ROLES = [
|
|
10818
10282
|
"owner",
|
|
@@ -10889,7 +10353,7 @@ async function membersCommand(rawArgs) {
|
|
|
10889
10353
|
case "list": return listMembers(rawArgs, flags["--org"]);
|
|
10890
10354
|
case "invite": return inviteMember(rawArgs, flags["--org"], rest[0], role);
|
|
10891
10355
|
case "remove": return removeMember(rawArgs, flags["--org"], rest[0], Boolean(flags["--yes"]));
|
|
10892
|
-
case "role": return changeRole(rawArgs, flags["--org"], rest[0], rest[1]);
|
|
10356
|
+
case "role": return changeRole(rawArgs, flags["--org"], rest[0], rest[1], Boolean(flags["--yes"]));
|
|
10893
10357
|
}
|
|
10894
10358
|
}
|
|
10895
10359
|
async function listMembers(rawArgs, orgFlag) {
|
|
@@ -10946,7 +10410,7 @@ async function inviteMember(rawArgs, orgFlag, email, role) {
|
|
|
10946
10410
|
role
|
|
10947
10411
|
});
|
|
10948
10412
|
} catch (e) {
|
|
10949
|
-
|
|
10413
|
+
reportCallError(e, `Failed to invite ${email}`, INVITES_UNSERVED);
|
|
10950
10414
|
}
|
|
10951
10415
|
if (result.kind === "added") {
|
|
10952
10416
|
emit(() => success(`${result.email} already had a verified account and is now a member (${result.role}) of org ${org}`), {
|
|
@@ -10998,7 +10462,7 @@ async function removeMember(rawArgs, orgFlag, ref, yes) {
|
|
|
10998
10462
|
}
|
|
10999
10463
|
});
|
|
11000
10464
|
}
|
|
11001
|
-
async function changeRole(rawArgs, orgFlag, ref, role) {
|
|
10465
|
+
async function changeRole(rawArgs, orgFlag, ref, role, yes) {
|
|
11002
10466
|
if (!ref || !role) fail("Name the member and the role.", "`rebase cloud orgs members role <email|uid> <owner|admin|member>`.", "usage");
|
|
11003
10467
|
const { client, url } = await requireClient(rawArgs);
|
|
11004
10468
|
const org = orgFor(orgFlag, url);
|
|
@@ -11020,6 +10484,11 @@ async function changeRole(rawArgs, orgFlag, ref, role) {
|
|
|
11020
10484
|
});
|
|
11021
10485
|
return;
|
|
11022
10486
|
}
|
|
10487
|
+
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." : "";
|
|
10488
|
+
await confirmDestructive({
|
|
10489
|
+
yes,
|
|
10490
|
+
prompt: `Make ${who} ${role} in org ${org} (now ${target.role ?? "member"})?${ownership}`
|
|
10491
|
+
});
|
|
11023
10492
|
try {
|
|
11024
10493
|
await client.data.table("organization-members").update(target.id, { role });
|
|
11025
10494
|
} catch (e) {
|
|
@@ -11067,7 +10536,7 @@ async function invitesCommand(rawArgs) {
|
|
|
11067
10536
|
listed = await loadInvites(client, org);
|
|
11068
10537
|
} catch (e) {
|
|
11069
10538
|
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
|
-
|
|
10539
|
+
reportCallError(e, "Failed to list invitations", INVITES_UNSERVED);
|
|
11071
10540
|
}
|
|
11072
10541
|
if (action === "list") {
|
|
11073
10542
|
emit(() => {
|
|
@@ -11092,13 +10561,17 @@ async function invitesCommand(rawArgs) {
|
|
|
11092
10561
|
}
|
|
11093
10562
|
const target = pickInvite(listed.invites, ref, action);
|
|
11094
10563
|
if (action === "revoke") {
|
|
10564
|
+
await confirmDestructive({
|
|
10565
|
+
yes: Boolean(flags["--yes"]),
|
|
10566
|
+
prompt: `Revoke the invitation for ${target.email} (${target.role})? Its link stops working.`
|
|
10567
|
+
});
|
|
11095
10568
|
try {
|
|
11096
10569
|
await client.functions.invoke("invites", void 0, {
|
|
11097
10570
|
method: "DELETE",
|
|
11098
10571
|
path: encodeURIComponent(target.id)
|
|
11099
10572
|
});
|
|
11100
10573
|
} catch (e) {
|
|
11101
|
-
|
|
10574
|
+
reportCallError(e, `Failed to revoke the invitation for ${target.email}`, INVITES_UNSERVED);
|
|
11102
10575
|
}
|
|
11103
10576
|
emit(() => success(`Revoked the invitation for ${target.email}; its link no longer works`), {
|
|
11104
10577
|
org,
|
|
@@ -11110,7 +10583,7 @@ async function invitesCommand(rawArgs) {
|
|
|
11110
10583
|
try {
|
|
11111
10584
|
resent = await client.functions.invoke("invites", {}, { path: `${encodeURIComponent(target.id)}/resend` });
|
|
11112
10585
|
} catch (e) {
|
|
11113
|
-
|
|
10586
|
+
reportCallError(e, `Failed to resend the invitation for ${target.email}`, INVITES_UNSERVED);
|
|
11114
10587
|
}
|
|
11115
10588
|
emit(() => {
|
|
11116
10589
|
success(`New link for ${resent.invite.email}, valid until ${resent.invite.expiresAt.slice(0, 10)}; the old one no longer works`);
|
|
@@ -11140,6 +10613,17 @@ function printOrgsHelp() {
|
|
|
11140
10613
|
description: "Create a new organization",
|
|
11141
10614
|
flags: [["--name <name>", "Display name"], ["--slug <slug>", "URL slug. Derived from the name when omitted"]]
|
|
11142
10615
|
},
|
|
10616
|
+
{
|
|
10617
|
+
action: "rename",
|
|
10618
|
+
args: "<name>",
|
|
10619
|
+
description: "Rename the organization. Owners and admins",
|
|
10620
|
+
flags: [["--slug <slug>", "Change its slug too. Kept when omitted"], ["--org <id>", "The organization. Default: the active one"]]
|
|
10621
|
+
},
|
|
10622
|
+
{
|
|
10623
|
+
action: "delete",
|
|
10624
|
+
description: "Delete the organization. Refused while it has projects; asks first, --yes skips the prompt",
|
|
10625
|
+
flags: [["--org <id>", "The organization. Default: the active one"]]
|
|
10626
|
+
},
|
|
11143
10627
|
{
|
|
11144
10628
|
action: "members",
|
|
11145
10629
|
args: "[list]",
|
|
@@ -11164,7 +10648,7 @@ function printOrgsHelp() {
|
|
|
11164
10648
|
action: "members role",
|
|
11165
10649
|
args: "<email|uid> <role>",
|
|
11166
10650
|
section: "Members",
|
|
11167
|
-
description: "Change a member's role: owner, admin or member"
|
|
10651
|
+
description: "Change a member's role: owner, admin or member. Asks first; --yes skips the prompt"
|
|
11168
10652
|
},
|
|
11169
10653
|
{
|
|
11170
10654
|
action: "invites",
|
|
@@ -11176,7 +10660,7 @@ function printOrgsHelp() {
|
|
|
11176
10660
|
action: "invites revoke",
|
|
11177
10661
|
args: "<id|email>",
|
|
11178
10662
|
section: "Invitations",
|
|
11179
|
-
description: "Revoke a pending invitation; its link stops working"
|
|
10663
|
+
description: "Revoke a pending invitation; its link stops working. Asks first; --yes skips the prompt"
|
|
11180
10664
|
},
|
|
11181
10665
|
{
|
|
11182
10666
|
action: "invites resend",
|
|
@@ -11187,6 +10671,7 @@ function printOrgsHelp() {
|
|
|
11187
10671
|
],
|
|
11188
10672
|
notes: [
|
|
11189
10673
|
"The active one is what `rebase cloud use` selects, and what billing is scoped to.",
|
|
10674
|
+
"An organization with projects cannot be deleted: delete each project first, which is what tears down its database and cancels its subscription.",
|
|
11190
10675
|
"Inviting and invitations take a `rebase cloud login` session, not REBASE_TOKEN, and the owner or admin role.",
|
|
11191
10676
|
"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
10677
|
]
|
|
@@ -11200,6 +10685,7 @@ function printOrgsHelp() {
|
|
|
11200
10685
|
* domains list Every host, its status, and the DNS records it needs
|
|
11201
10686
|
* domains add <domain> Register a host (starts, does not finish, setup)
|
|
11202
10687
|
* domains verify [domain] Check the host's published DNS now; live only if it passes
|
|
10688
|
+
* domains primary <domain> Make a verified host the canonical one
|
|
11203
10689
|
* domains remove <domain> Stop serving a host
|
|
11204
10690
|
*
|
|
11205
10691
|
* A project's hosts are rows of the control plane's `project_domains` table,
|
|
@@ -11337,6 +10823,9 @@ async function domainsCommand(action, rawArgs) {
|
|
|
11337
10823
|
case "verify":
|
|
11338
10824
|
await verifyDomain(rawArgs);
|
|
11339
10825
|
break;
|
|
10826
|
+
case "primary":
|
|
10827
|
+
await primaryDomain(rawArgs);
|
|
10828
|
+
break;
|
|
11340
10829
|
case "remove":
|
|
11341
10830
|
case "rm":
|
|
11342
10831
|
case "delete":
|
|
@@ -11505,6 +10994,43 @@ function verifyOutcome(res, target) {
|
|
|
11505
10994
|
}
|
|
11506
10995
|
};
|
|
11507
10996
|
}
|
|
10997
|
+
/**
|
|
10998
|
+
* Make one verified host the project's canonical one: the address links and
|
|
10999
|
+
* redirects are built from. The control plane keeps one primary per project and
|
|
11000
|
+
* mirrors it into the project's single domain column.
|
|
11001
|
+
*/
|
|
11002
|
+
async function primaryDomain(rawArgs) {
|
|
11003
|
+
const named = resolveDomainArg(rawArgs, "primary");
|
|
11004
|
+
if (!named) fail("Usage: rebase cloud domains primary <domain>", "Name one of the project's verified domains.", "usage");
|
|
11005
|
+
const { client } = await requireClient(rawArgs);
|
|
11006
|
+
const projectId = await requireProject(rawArgs, client);
|
|
11007
|
+
const projectRef = displayProjectRef(rawArgs);
|
|
11008
|
+
let set;
|
|
11009
|
+
try {
|
|
11010
|
+
set = await loadDomains(client, projectId);
|
|
11011
|
+
} catch (e) {
|
|
11012
|
+
reportError(e, "Failed to load custom domains");
|
|
11013
|
+
}
|
|
11014
|
+
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");
|
|
11015
|
+
const target = pickDomain(set, named, "primary");
|
|
11016
|
+
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");
|
|
11017
|
+
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");
|
|
11018
|
+
let res;
|
|
11019
|
+
try {
|
|
11020
|
+
res = await client.functions.invoke("domains", {}, { path: `${projectId}/${target.id}/primary` });
|
|
11021
|
+
} catch (e) {
|
|
11022
|
+
reportError(e, "Failed to set the primary domain");
|
|
11023
|
+
}
|
|
11024
|
+
const unchanged = res.unchanged === true;
|
|
11025
|
+
emit(() => success(unchanged ? `${target.host} already is the primary host of project ${projectRef}` : `${target.host} is now the primary host of project ${projectRef}`), {
|
|
11026
|
+
success: true,
|
|
11027
|
+
projectId,
|
|
11028
|
+
id: target.id,
|
|
11029
|
+
host: target.host,
|
|
11030
|
+
primary: true,
|
|
11031
|
+
changed: !unchanged
|
|
11032
|
+
});
|
|
11033
|
+
}
|
|
11508
11034
|
async function removeDomain(rawArgs) {
|
|
11509
11035
|
const { flags: args, positionals } = parseCloudArgs({
|
|
11510
11036
|
spec: {},
|
|
@@ -11563,6 +11089,11 @@ function printDomainsHelp() {
|
|
|
11563
11089
|
args: "[domain]",
|
|
11564
11090
|
description: "Check a host's DNS and put it live"
|
|
11565
11091
|
},
|
|
11092
|
+
{
|
|
11093
|
+
action: "primary",
|
|
11094
|
+
args: "<domain>",
|
|
11095
|
+
description: "Make a verified host the canonical one, the address links are built from"
|
|
11096
|
+
},
|
|
11566
11097
|
{
|
|
11567
11098
|
action: "remove",
|
|
11568
11099
|
args: "<domain>",
|
|
@@ -11779,7 +11310,7 @@ function printExtensionsHelp() {
|
|
|
11779
11310
|
* `rebase cloud settings` — a project's editable configuration.
|
|
11780
11311
|
*
|
|
11781
11312
|
* settings Show the current settings
|
|
11782
|
-
* settings set [flags] Update name / branch / repo / subdomain / platform rebuilds
|
|
11313
|
+
* settings set [flags] Update name / branch / repo / subdomain / platform rebuilds / Studio access
|
|
11783
11314
|
*
|
|
11784
11315
|
* These are plain `projects` updates. A subdomain change is validated against
|
|
11785
11316
|
* `check-subdomain` up front so the CLI fails with the real reason rather than a
|
|
@@ -11827,7 +11358,8 @@ async function showSettings(rawArgs) {
|
|
|
11827
11358
|
["Custom domain", p.customDomain],
|
|
11828
11359
|
["Provider", p.provider],
|
|
11829
11360
|
["Region", p.region],
|
|
11830
|
-
["Platform rebuilds", p.platformRebuilds === false ? "off" : "on"]
|
|
11361
|
+
["Platform rebuilds", p.platformRebuilds === false ? "off" : "on"],
|
|
11362
|
+
["Studio access", p.studioEnabled === false ? "off" : "on"]
|
|
11831
11363
|
]);
|
|
11832
11364
|
console.log("");
|
|
11833
11365
|
}, {
|
|
@@ -11839,7 +11371,8 @@ async function showSettings(rawArgs) {
|
|
|
11839
11371
|
customDomain: p.customDomain ?? null,
|
|
11840
11372
|
provider: p.provider ?? null,
|
|
11841
11373
|
region: p.region ?? null,
|
|
11842
|
-
platformRebuilds: p.platformRebuilds !== false
|
|
11374
|
+
platformRebuilds: p.platformRebuilds !== false,
|
|
11375
|
+
studioEnabled: p.studioEnabled !== false
|
|
11843
11376
|
});
|
|
11844
11377
|
} catch (e) {
|
|
11845
11378
|
reportError(e, "Failed to load settings");
|
|
@@ -11860,6 +11393,7 @@ function buildSettingsPatch(args) {
|
|
|
11860
11393
|
if (args.repo !== void 0) patch.gitRepoUrl = args.repo;
|
|
11861
11394
|
if (args.branch !== void 0) patch.gitBranch = args.branch;
|
|
11862
11395
|
if (args.platformRebuilds !== void 0) patch.platformRebuilds = args.platformRebuilds;
|
|
11396
|
+
if (args.studio !== void 0) patch.studioEnabled = args.studio;
|
|
11863
11397
|
return patch;
|
|
11864
11398
|
}
|
|
11865
11399
|
/** What `rebase cloud settings set` parses. Its page is the group's own. */
|
|
@@ -11868,7 +11402,8 @@ var SET_SETTINGS_FLAGS = {
|
|
|
11868
11402
|
"--subdomain": String,
|
|
11869
11403
|
"--repo": String,
|
|
11870
11404
|
"--branch": String,
|
|
11871
|
-
"--platform-rebuilds": String
|
|
11405
|
+
"--platform-rebuilds": String,
|
|
11406
|
+
"--studio": String
|
|
11872
11407
|
};
|
|
11873
11408
|
async function setSettings(rawArgs) {
|
|
11874
11409
|
const { flags: args } = parseCloudArgs({
|
|
@@ -11887,14 +11422,33 @@ async function setSettings(rawArgs) {
|
|
|
11887
11422
|
if (parsed === null) fail(`--platform-rebuilds takes on or off (got "${args["--platform-rebuilds"]}").`, void 0, "usage");
|
|
11888
11423
|
platformRebuilds = parsed;
|
|
11889
11424
|
}
|
|
11425
|
+
let studio;
|
|
11426
|
+
if (args["--studio"] !== void 0) {
|
|
11427
|
+
const parsed = parseOnOff(args["--studio"]);
|
|
11428
|
+
if (parsed === null) fail(`--studio takes on or off (got "${args["--studio"]}").`, void 0, "usage");
|
|
11429
|
+
studio = parsed;
|
|
11430
|
+
}
|
|
11890
11431
|
const patch = buildSettingsPatch({
|
|
11891
11432
|
name: args["--name"],
|
|
11892
11433
|
subdomain: args["--subdomain"],
|
|
11893
11434
|
repo: args["--repo"],
|
|
11894
11435
|
branch: args["--branch"],
|
|
11895
|
-
platformRebuilds
|
|
11436
|
+
platformRebuilds,
|
|
11437
|
+
studio
|
|
11896
11438
|
});
|
|
11897
|
-
if (Object.keys(patch).length === 0) fail("Nothing to update.", "Pass --name, --subdomain, --repo, --branch,
|
|
11439
|
+
if (Object.keys(patch).length === 0) fail("Nothing to update.", "Pass --name, --subdomain, --repo, --branch, --platform-rebuilds or --studio.", "usage");
|
|
11440
|
+
if (typeof patch.subdomain === "string" && patch.subdomain) {
|
|
11441
|
+
let current;
|
|
11442
|
+
try {
|
|
11443
|
+
current = (await client.data.table("projects").findById(projectId))?.subdomain;
|
|
11444
|
+
} catch (e) {
|
|
11445
|
+
reportError(e, "Failed to load settings");
|
|
11446
|
+
}
|
|
11447
|
+
if (current?.toLowerCase() !== patch.subdomain) await confirmDestructive({
|
|
11448
|
+
yes: Boolean(args["--yes"]),
|
|
11449
|
+
prompt: `Move project ${projectRef} from ${current ?? "its subdomain"} to ${patch.subdomain}? The old address stops answering, and anything that calls it breaks.`
|
|
11450
|
+
});
|
|
11451
|
+
}
|
|
11898
11452
|
try {
|
|
11899
11453
|
if (typeof patch.subdomain === "string" && patch.subdomain) {
|
|
11900
11454
|
const check = await client.functions.invoke("check-subdomain", { subdomain: patch.subdomain }).catch(() => void 0);
|
|
@@ -11916,7 +11470,7 @@ function printSettingsHelp() {
|
|
|
11916
11470
|
title: "Project configuration",
|
|
11917
11471
|
actions: [{
|
|
11918
11472
|
action: "show",
|
|
11919
|
-
description: "Name, subdomain, repository, branch
|
|
11473
|
+
description: "Name, subdomain, repository, branch, platform rebuilds and Studio access as recorded"
|
|
11920
11474
|
}, {
|
|
11921
11475
|
action: "set",
|
|
11922
11476
|
description: "Change one or more of them",
|
|
@@ -11925,9 +11479,11 @@ function printSettingsHelp() {
|
|
|
11925
11479
|
["--subdomain <sub>", "The <slug>.rebase.website host"],
|
|
11926
11480
|
["--repo <git url>", "Repository to build from"],
|
|
11927
11481
|
["--branch <branch>", "Branch to build"],
|
|
11928
|
-
["--platform-rebuilds <on|off>", "Rebuild this app on new framework releases (default on)"]
|
|
11482
|
+
["--platform-rebuilds <on|off>", "Rebuild this app on new framework releases (default on)"],
|
|
11483
|
+
["--studio <on|off>", "Let the console's Studio reach this project's API with admin rights (default on). Owners and admins"]
|
|
11929
11484
|
]
|
|
11930
|
-
}]
|
|
11485
|
+
}],
|
|
11486
|
+
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
11487
|
});
|
|
11932
11488
|
}
|
|
11933
11489
|
//#endregion
|
|
@@ -12733,6 +12289,11 @@ async function connectCommand(rawArgs) {
|
|
|
12733
12289
|
* projects undercounting requests, partial days) are printed with the numbers,
|
|
12734
12290
|
* and are in `--json` unchanged. Read-only; any member of the organization.
|
|
12735
12291
|
*/
|
|
12292
|
+
/** What `usage` says on a control plane that has no `usage` function yet. */
|
|
12293
|
+
var USAGE_UNSERVED = {
|
|
12294
|
+
what: "usage reports",
|
|
12295
|
+
hint: "`rebase cloud metrics --runtime` shows the requests and errors the app has counted since it started."
|
|
12296
|
+
};
|
|
12736
12297
|
var USAGE_FLAGS = { "--month": String };
|
|
12737
12298
|
var USAGE_ACTIONS = ["org"];
|
|
12738
12299
|
var MONTH_RE = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
@@ -12837,7 +12398,7 @@ async function usageCommand(rawArgs) {
|
|
|
12837
12398
|
try {
|
|
12838
12399
|
usage = await readOrgUsage(client, org, month);
|
|
12839
12400
|
} catch (e) {
|
|
12840
|
-
|
|
12401
|
+
reportCallError(e, "Failed to load usage", USAGE_UNSERVED);
|
|
12841
12402
|
}
|
|
12842
12403
|
emit(() => printOrg(usage), usage);
|
|
12843
12404
|
return;
|
|
@@ -12847,7 +12408,7 @@ async function usageCommand(rawArgs) {
|
|
|
12847
12408
|
try {
|
|
12848
12409
|
usage = await readProjectUsage(client, projectId, month);
|
|
12849
12410
|
} catch (e) {
|
|
12850
|
-
|
|
12411
|
+
reportCallError(e, "Failed to load usage", USAGE_UNSERVED);
|
|
12851
12412
|
}
|
|
12852
12413
|
emit(() => printProject(usage, `project ${displayProjectRef(rawArgs) || projectId}`), usage);
|
|
12853
12414
|
}
|
|
@@ -12872,6 +12433,11 @@ async function usageCommand(rawArgs) {
|
|
|
12872
12433
|
*
|
|
12873
12434
|
* @module
|
|
12874
12435
|
*/
|
|
12436
|
+
/** What `app-key` says on a control plane that has no `credentials` function yet. */
|
|
12437
|
+
var APP_KEY_UNSERVED = {
|
|
12438
|
+
what: "app keys",
|
|
12439
|
+
hint: "Nothing was changed. The app's own admin panel creates and revokes API keys meanwhile."
|
|
12440
|
+
};
|
|
12875
12441
|
var APP_KEY_FLAGS = {};
|
|
12876
12442
|
var APP_KEY_ACTIONS = ["rotate"];
|
|
12877
12443
|
function isRotated(value) {
|
|
@@ -12922,7 +12488,7 @@ async function appKeyCommand(rawArgs) {
|
|
|
12922
12488
|
try {
|
|
12923
12489
|
listed = await listKeys(client, projectId);
|
|
12924
12490
|
} catch (e) {
|
|
12925
|
-
|
|
12491
|
+
reportCallError(e, "Failed to read the app's keys", APP_KEY_UNSERVED);
|
|
12926
12492
|
}
|
|
12927
12493
|
emit(() => printKeys(listed.keys, label), listed);
|
|
12928
12494
|
return;
|
|
@@ -12935,7 +12501,7 @@ async function appKeyCommand(rawArgs) {
|
|
|
12935
12501
|
try {
|
|
12936
12502
|
answer = await rotateKey(client, projectId);
|
|
12937
12503
|
} catch (e) {
|
|
12938
|
-
|
|
12504
|
+
reportCallError(e, "Failed to rotate the app key", APP_KEY_UNSERVED);
|
|
12939
12505
|
}
|
|
12940
12506
|
if (!isRotated(answer)) reportError(/* @__PURE__ */ new Error("The control plane's answer did not carry a key."), "Failed to rotate the app key");
|
|
12941
12507
|
const rotated = answer;
|
|
@@ -12985,6 +12551,11 @@ async function appKeyCommand(rawArgs) {
|
|
|
12985
12551
|
*
|
|
12986
12552
|
* @module
|
|
12987
12553
|
*/
|
|
12554
|
+
/** What `service-key` says on a control plane that has no `credentials` function yet. */
|
|
12555
|
+
var SERVICE_KEY_UNSERVED = {
|
|
12556
|
+
what: "service-key rotation",
|
|
12557
|
+
hint: "Nothing was changed. `rebase cloud env reveal REBASE_SERVICE_KEY` still reads the current key."
|
|
12558
|
+
};
|
|
12988
12559
|
var SERVICE_KEY_FLAGS = {};
|
|
12989
12560
|
var SERVICE_KEY_ACTIONS = ["rotate"];
|
|
12990
12561
|
async function readStatus(client, projectId) {
|
|
@@ -13025,7 +12596,7 @@ async function serviceKeyCommand(rawArgs) {
|
|
|
13025
12596
|
try {
|
|
13026
12597
|
status = await readStatus(client, projectId);
|
|
13027
12598
|
} catch (e) {
|
|
13028
|
-
|
|
12599
|
+
reportCallError(e, "Failed to read the service key's state", SERVICE_KEY_UNSERVED);
|
|
13029
12600
|
}
|
|
13030
12601
|
emit(() => printStatus(status, label), status);
|
|
13031
12602
|
return;
|
|
@@ -13038,7 +12609,7 @@ async function serviceKeyCommand(rawArgs) {
|
|
|
13038
12609
|
try {
|
|
13039
12610
|
rotation = await client.functions.invoke("credentials", {}, { path: `${encodeURIComponent(projectId)}/service-key/rotate` });
|
|
13040
12611
|
} catch (e) {
|
|
13041
|
-
|
|
12612
|
+
reportCallError(e, "Failed to rotate the service key", SERVICE_KEY_UNSERVED);
|
|
13042
12613
|
}
|
|
13043
12614
|
emit(() => {
|
|
13044
12615
|
success(`Issued service key generation ${rotation.generation} for ${label}.`);
|
|
@@ -13102,20 +12673,19 @@ function lastSeenBeforeOf(value) {
|
|
|
13102
12673
|
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
12674
|
return new Date(Date.now() - ms);
|
|
13104
12675
|
}
|
|
13105
|
-
/**
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
}
|
|
12676
|
+
/**
|
|
12677
|
+
* The project's own API, through the console's Studio proxy: the control
|
|
12678
|
+
* plane attaches the app's service key on its own side, so no static secret
|
|
12679
|
+
* reaches this machine. (This used to reveal `REBASE_SERVICE_KEY` into the
|
|
12680
|
+
* CLI's memory, which is the thing `docs/platform-tokens.md` exists to avoid.)
|
|
12681
|
+
* It answers an organization owner or admin, on a project whose Studio switch
|
|
12682
|
+
* is on.
|
|
12683
|
+
*/
|
|
12684
|
+
async function connectToApp(client, url, projectId) {
|
|
12685
|
+
const token = await freshAccessToken(client);
|
|
13116
12686
|
return createRebaseClient({
|
|
13117
|
-
baseUrl:
|
|
13118
|
-
token
|
|
12687
|
+
baseUrl: `${url.replace(/\/+$/, "")}/api/functions/studio/${encodeURIComponent(projectId)}/proxy`,
|
|
12688
|
+
token,
|
|
13119
12689
|
realtime: false,
|
|
13120
12690
|
headers: { "User-Agent": cliUserAgent() },
|
|
13121
12691
|
auth: {
|
|
@@ -13131,6 +12701,7 @@ async function connectToApp(client, origin, projectId) {
|
|
|
13131
12701
|
*/
|
|
13132
12702
|
function reportAppError(error, action, origin) {
|
|
13133
12703
|
if (error instanceof RebaseApiError) {
|
|
12704
|
+
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
12705
|
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
12706
|
if (error.status === 501) fail(`The app at ${origin} cannot manage guests: ${error.message}`, void 0, "not_supported");
|
|
13136
12707
|
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 +12798,7 @@ async function guestsCommand(rawArgs) {
|
|
|
13227
12798
|
prompt: `Delete guest ${id} from ${label}? Its sessions end, and whatever the project's own tables cascade from it goes too.`
|
|
13228
12799
|
});
|
|
13229
12800
|
const origin = await resolveOrigin(rawArgs, client, url, projectId);
|
|
13230
|
-
const app = await connectToApp(client,
|
|
12801
|
+
const app = await connectToApp(client, url, projectId);
|
|
13231
12802
|
try {
|
|
13232
12803
|
if (action === "delete") emit(() => success(`Deleted guest ${id} from ${label}.`), await app.admin.deleteGuest(id));
|
|
13233
12804
|
else if (action === "prune" && age && lastSeenBefore) await prune(app, age, lastSeenBefore, Boolean(flags["--yes"]), label);
|
|
@@ -13257,6 +12828,11 @@ async function guestsCommand(rawArgs) {
|
|
|
13257
12828
|
* `--json` is one value: `{ org, events, nextCursor }`, each event exactly as
|
|
13258
12829
|
* the control plane sends it.
|
|
13259
12830
|
*/
|
|
12831
|
+
/** What `activity` says on a control plane that has no `audit` function yet. */
|
|
12832
|
+
var AUDIT_UNSERVED = {
|
|
12833
|
+
what: "the activity log",
|
|
12834
|
+
hint: "`rebase cloud deployments` lists each project's deploys, with who triggered them."
|
|
12835
|
+
};
|
|
13260
12836
|
var ACTIVITY_FLAGS = {
|
|
13261
12837
|
"--org": String,
|
|
13262
12838
|
"--action": String,
|
|
@@ -13348,7 +12924,7 @@ async function activityCommand(rawArgs) {
|
|
|
13348
12924
|
path: `org/${encodeURIComponent(org)}${query ? `?${query}` : ""}`
|
|
13349
12925
|
});
|
|
13350
12926
|
} catch (e) {
|
|
13351
|
-
|
|
12927
|
+
reportCallError(e, "Failed to load the activity log", AUDIT_UNSERVED);
|
|
13352
12928
|
}
|
|
13353
12929
|
const events = res.events ?? [];
|
|
13354
12930
|
const nextCursor = res.nextCursor ?? null;
|
|
@@ -13379,6 +12955,11 @@ async function activityCommand(rawArgs) {
|
|
|
13379
12955
|
* every delivery. Each POST is signed: `X-Webhook-Signature: sha256=<hex HMAC
|
|
13380
12956
|
* of the body>` with the secret `add` prints once.
|
|
13381
12957
|
*/
|
|
12958
|
+
/** What `notifications` says on a control plane that has no `notifications` function yet. */
|
|
12959
|
+
var NOTIFICATIONS_UNSERVED = {
|
|
12960
|
+
what: "notification webhooks",
|
|
12961
|
+
hint: "Nothing was changed. `rebase cloud alerts` lists what the platform has seen go wrong with the project."
|
|
12962
|
+
};
|
|
13382
12963
|
/** The events the control plane notifies about. */
|
|
13383
12964
|
var NOTIFICATION_EVENTS = [
|
|
13384
12965
|
"deploy.failed",
|
|
@@ -13454,7 +13035,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13454
13035
|
...flags["--name"] ? { name: flags["--name"] } : {}
|
|
13455
13036
|
}, { path: "webhooks" });
|
|
13456
13037
|
} catch (e) {
|
|
13457
|
-
|
|
13038
|
+
reportCallError(e, "Failed to add the notification webhook", NOTIFICATIONS_UNSERVED);
|
|
13458
13039
|
}
|
|
13459
13040
|
emit(() => {
|
|
13460
13041
|
success(`Notifications for ${events.join(", ")} now go to ${chalk.bold(created.webhook.url)} [${created.webhook.id}]`);
|
|
@@ -13491,7 +13072,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13491
13072
|
path: `webhooks/${encodeURIComponent(id)}`
|
|
13492
13073
|
});
|
|
13493
13074
|
} catch (e) {
|
|
13494
|
-
|
|
13075
|
+
reportCallError(e, "Failed to remove the notification webhook", NOTIFICATIONS_UNSERVED);
|
|
13495
13076
|
}
|
|
13496
13077
|
success(`Notification webhook ${chalk.bold(id)} removed`);
|
|
13497
13078
|
emit(() => {}, {
|
|
@@ -13504,7 +13085,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13504
13085
|
try {
|
|
13505
13086
|
result = await client.functions.invoke("notifications", {}, { path: `webhooks/${encodeURIComponent(id)}/test` });
|
|
13506
13087
|
} catch (e) {
|
|
13507
|
-
|
|
13088
|
+
reportCallError(e, "Failed to send the test event", NOTIFICATIONS_UNSERVED);
|
|
13508
13089
|
}
|
|
13509
13090
|
if (!result.success) fail(`The test event was not delivered: ${result.statusCode ? `HTTP ${result.statusCode}` : "no response"}.`, result.error || void 0, "delivery_failed");
|
|
13510
13091
|
success(`Test event delivered (HTTP ${result.statusCode})`);
|
|
@@ -13527,7 +13108,7 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13527
13108
|
try {
|
|
13528
13109
|
webhooks = await listWebhooks(client, projectId);
|
|
13529
13110
|
} catch (e) {
|
|
13530
|
-
|
|
13111
|
+
reportCallError(e, "Failed to list notification webhooks", NOTIFICATIONS_UNSERVED);
|
|
13531
13112
|
}
|
|
13532
13113
|
emit(() => {
|
|
13533
13114
|
console.log("");
|
|
@@ -13552,6 +13133,312 @@ async function notificationsCommand(action, rawArgs) {
|
|
|
13552
13133
|
});
|
|
13553
13134
|
}
|
|
13554
13135
|
//#endregion
|
|
13136
|
+
//#region src/commands/cloud/deploy-hooks.ts
|
|
13137
|
+
/**
|
|
13138
|
+
* `rebase cloud deploy-hooks` — URLs that start a build of the project's
|
|
13139
|
+
* connected repository when something POSTs to them: a git host's webhook, a
|
|
13140
|
+
* CMS's publish button, a CI step.
|
|
13141
|
+
*
|
|
13142
|
+
* deploy-hooks [list] The project's hooks: name, branch, last used
|
|
13143
|
+
* deploy-hooks create [--name] [--branch] Mint one, and print its URL once
|
|
13144
|
+
* deploy-hooks revoke <id> Delete one; its URL stops working
|
|
13145
|
+
*
|
|
13146
|
+
* The control plane's `deploy` function serves them (`/hooks`), the same routes
|
|
13147
|
+
* the console's Settings use. The URL carries the hook's token, which is the
|
|
13148
|
+
* whole credential: the control plane keeps only its hash, so the URL is shown
|
|
13149
|
+
* once, at `create`, and never again.
|
|
13150
|
+
*/
|
|
13151
|
+
/** The action words `rebase cloud deploy-hooks` dispatches. No word means `list`. */
|
|
13152
|
+
var DEPLOY_HOOKS_ACTIONS = [
|
|
13153
|
+
"list",
|
|
13154
|
+
"create",
|
|
13155
|
+
"revoke"
|
|
13156
|
+
];
|
|
13157
|
+
/** What `deploy-hooks` parses. `--name` and `--branch` belong to `create`. */
|
|
13158
|
+
var DEPLOY_HOOKS_FLAGS = {
|
|
13159
|
+
"--name": String,
|
|
13160
|
+
"--branch": String
|
|
13161
|
+
};
|
|
13162
|
+
/** The control plane's `deploy` function, where the hooks routes live. */
|
|
13163
|
+
var DEPLOY_FUNCTION = "deploy";
|
|
13164
|
+
function text(value) {
|
|
13165
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
13166
|
+
}
|
|
13167
|
+
/** One hook from the wire, or null for one with no id. */
|
|
13168
|
+
function readHook(value) {
|
|
13169
|
+
if (typeof value !== "object" || value === null) return null;
|
|
13170
|
+
const id = "id" in value ? value.id : void 0;
|
|
13171
|
+
if (typeof id !== "string" && typeof id !== "number") return null;
|
|
13172
|
+
return {
|
|
13173
|
+
id: String(id),
|
|
13174
|
+
name: ("name" in value ? text(value.name) : null) ?? "Deploy hook",
|
|
13175
|
+
branch: ("branch" in value ? text(value.branch) : null) ?? "",
|
|
13176
|
+
createdAt: "createdAt" in value ? text(value.createdAt) : null,
|
|
13177
|
+
lastUsedAt: "lastUsedAt" in value ? text(value.lastUsedAt) : null
|
|
13178
|
+
};
|
|
13179
|
+
}
|
|
13180
|
+
async function listHooks(client, projectId) {
|
|
13181
|
+
return ((await client.functions.invoke(DEPLOY_FUNCTION, void 0, {
|
|
13182
|
+
method: "GET",
|
|
13183
|
+
path: `hooks?projectId=${encodeURIComponent(projectId)}`
|
|
13184
|
+
})).hooks ?? []).map(readHook).filter((h) => h !== null);
|
|
13185
|
+
}
|
|
13186
|
+
async function deployHooksCommand(action, rawArgs) {
|
|
13187
|
+
const { flags, positionals } = parseCloudArgs({
|
|
13188
|
+
spec: DEPLOY_HOOKS_FLAGS,
|
|
13189
|
+
rawArgs,
|
|
13190
|
+
commandWords: 2,
|
|
13191
|
+
command: "cloud deploy-hooks",
|
|
13192
|
+
maxPositionals: 2
|
|
13193
|
+
});
|
|
13194
|
+
const word = positionals[0] ?? action;
|
|
13195
|
+
requireKnownAction("deploy-hooks", word, DEPLOY_HOOKS_ACTIONS);
|
|
13196
|
+
const verb = word ?? "list";
|
|
13197
|
+
const id = positionals[1];
|
|
13198
|
+
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");
|
|
13199
|
+
if (verb !== "revoke" && id !== void 0) fail(`Too many arguments for \`deploy-hooks ${verb}\`: ${id}`, "Run `rebase cloud deploy-hooks --help`.", "usage");
|
|
13200
|
+
if (verb === "revoke" && !id) fail("Name the hook to revoke.", "`rebase cloud deploy-hooks` lists them with their ids.", "usage");
|
|
13201
|
+
const { client, url } = await requireClient(rawArgs);
|
|
13202
|
+
const projectId = await requireProject(rawArgs, client);
|
|
13203
|
+
const label = `project ${displayProjectRef(rawArgs) || projectId}`;
|
|
13204
|
+
if (verb === "create") return createHook(client, url, projectId, label, flags["--name"], flags["--branch"]);
|
|
13205
|
+
if (verb === "revoke") return revokeHook(client, projectId, label, id, flags["--yes"] === true);
|
|
13206
|
+
let hooks;
|
|
13207
|
+
try {
|
|
13208
|
+
hooks = await listHooks(client, projectId);
|
|
13209
|
+
} catch (e) {
|
|
13210
|
+
reportError(e, "Failed to list deploy hooks");
|
|
13211
|
+
}
|
|
13212
|
+
emit(() => {
|
|
13213
|
+
console.log("");
|
|
13214
|
+
console.log(chalk.bold(` 🪝 Deploy hooks — ${label}`));
|
|
13215
|
+
console.log("");
|
|
13216
|
+
if (hooks.length === 0) {
|
|
13217
|
+
console.log(chalk.gray(" None. Mint one with `rebase cloud deploy-hooks create`."));
|
|
13218
|
+
console.log("");
|
|
13219
|
+
return;
|
|
13220
|
+
}
|
|
13221
|
+
for (const h of hooks) {
|
|
13222
|
+
const used = h.lastUsedAt ? `last used ${new Date(h.lastUsedAt).toLocaleString()}` : "never used";
|
|
13223
|
+
console.log(` ${chalk.bold(h.name)} ${chalk.gray(`[${h.id}]`)} ${h.branch || chalk.gray("project branch")} ${chalk.gray(used)}`);
|
|
13224
|
+
}
|
|
13225
|
+
console.log("");
|
|
13226
|
+
note(chalk.gray("A hook's URL is shown only when it is created. Lost one? Revoke it and create another."));
|
|
13227
|
+
console.log("");
|
|
13228
|
+
}, {
|
|
13229
|
+
projectId,
|
|
13230
|
+
hooks
|
|
13231
|
+
});
|
|
13232
|
+
}
|
|
13233
|
+
async function createHook(client, url, projectId, label, name, branch) {
|
|
13234
|
+
const body = { projectId };
|
|
13235
|
+
if (name?.trim()) body.name = name.trim();
|
|
13236
|
+
if (branch?.trim()) body.branch = branch.trim();
|
|
13237
|
+
let res;
|
|
13238
|
+
try {
|
|
13239
|
+
res = await client.functions.invoke(DEPLOY_FUNCTION, body, { path: "hooks" });
|
|
13240
|
+
} catch (e) {
|
|
13241
|
+
reportError(e, "Failed to create the deploy hook");
|
|
13242
|
+
}
|
|
13243
|
+
const hook = readHook(res.hook);
|
|
13244
|
+
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.");
|
|
13245
|
+
const hookUrl = `${url}${res.path.startsWith("/") ? "" : "/"}${res.path}`;
|
|
13246
|
+
emit(() => {
|
|
13247
|
+
success(`Created deploy hook ${chalk.bold(hook.name)} for ${label}.`);
|
|
13248
|
+
keyValues([["Id", hook.id], ["Builds", hook.branch || "the project's configured branch"]]);
|
|
13249
|
+
console.log("");
|
|
13250
|
+
console.log(` ${chalk.cyan(hookUrl)}`);
|
|
13251
|
+
console.log("");
|
|
13252
|
+
note(chalk.gray("Shown once: the URL is the credential, and the control plane keeps only its hash."));
|
|
13253
|
+
note(chalk.gray("POST to it to build and ship the connected repository. A push to another branch, or a tag, is ignored."));
|
|
13254
|
+
console.log("");
|
|
13255
|
+
}, {
|
|
13256
|
+
projectId,
|
|
13257
|
+
hook,
|
|
13258
|
+
url: hookUrl,
|
|
13259
|
+
token: res.token
|
|
13260
|
+
});
|
|
13261
|
+
}
|
|
13262
|
+
async function revokeHook(client, projectId, label, id, yes) {
|
|
13263
|
+
let hooks;
|
|
13264
|
+
try {
|
|
13265
|
+
hooks = await listHooks(client, projectId);
|
|
13266
|
+
} catch (e) {
|
|
13267
|
+
reportError(e, "Failed to list deploy hooks");
|
|
13268
|
+
}
|
|
13269
|
+
const hook = hooks.find((h) => h.id === id);
|
|
13270
|
+
if (!hook) fail(`${label} has no deploy hook ${id}.`, "`rebase cloud deploy-hooks` lists them with their ids.", "not_found");
|
|
13271
|
+
await confirmDestructive({
|
|
13272
|
+
yes,
|
|
13273
|
+
prompt: `Revoke deploy hook "${hook.name}" (${hook.id}) of ${label}? Anything that POSTs to its URL is refused from then on.`
|
|
13274
|
+
});
|
|
13275
|
+
try {
|
|
13276
|
+
await client.functions.invoke(DEPLOY_FUNCTION, void 0, {
|
|
13277
|
+
method: "DELETE",
|
|
13278
|
+
path: `hooks/${encodeURIComponent(id)}`
|
|
13279
|
+
});
|
|
13280
|
+
} catch (e) {
|
|
13281
|
+
reportError(e, "Failed to revoke the deploy hook");
|
|
13282
|
+
}
|
|
13283
|
+
emit(() => success(`Revoked deploy hook ${hook.name}; its URL no longer works.`), {
|
|
13284
|
+
projectId,
|
|
13285
|
+
revoked: hook
|
|
13286
|
+
});
|
|
13287
|
+
}
|
|
13288
|
+
//#endregion
|
|
13289
|
+
//#region src/commands/cloud/alerts.ts
|
|
13290
|
+
/**
|
|
13291
|
+
* `rebase cloud alerts` — the problems the platform has seen with a project,
|
|
13292
|
+
* and acknowledging or snoozing them.
|
|
13293
|
+
*
|
|
13294
|
+
* alerts [list] [--all] Open alerts, newest first; --all adds the resolved ones
|
|
13295
|
+
* alerts ack <incidentId> Acknowledge: reminders stop for everyone
|
|
13296
|
+
* alerts snooze <incidentId> --hours <n> Nobody is emailed about it for n hours
|
|
13297
|
+
*
|
|
13298
|
+
* Two doors, as in the console. Incidents are read through the data API
|
|
13299
|
+
* (`alert-incidents`), where the control plane's row-level security shows the
|
|
13300
|
+
* caller its own organizations' and nothing else. Acknowledging and snoozing go
|
|
13301
|
+
* through its `alerts` function, which checks the caller's role first: RLS
|
|
13302
|
+
* gates rows, not columns, and a member allowed to update an incident could
|
|
13303
|
+
* rewrite its severity too.
|
|
13304
|
+
*/
|
|
13305
|
+
/** The action words `rebase cloud alerts` dispatches. No word means `list`. */
|
|
13306
|
+
var ALERTS_ACTIONS = [
|
|
13307
|
+
"list",
|
|
13308
|
+
"ack",
|
|
13309
|
+
"snooze"
|
|
13310
|
+
];
|
|
13311
|
+
/** What `alerts` parses: `--all` for `list`, `--hours` for `snooze`. */
|
|
13312
|
+
var ALERTS_FLAGS = {
|
|
13313
|
+
"--all": Boolean,
|
|
13314
|
+
"--hours": String
|
|
13315
|
+
};
|
|
13316
|
+
function field(row, camel, snake) {
|
|
13317
|
+
const value = row[camel] ?? row[snake];
|
|
13318
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
13319
|
+
}
|
|
13320
|
+
/** One incident from the data API, or null for a row that is not one. */
|
|
13321
|
+
function readIncident(row) {
|
|
13322
|
+
const id = row.id;
|
|
13323
|
+
if (typeof id !== "string" && typeof id !== "number" || typeof row.rule !== "string") return null;
|
|
13324
|
+
return {
|
|
13325
|
+
id: String(id),
|
|
13326
|
+
rule: row.rule,
|
|
13327
|
+
title: typeof row.title === "string" && row.title ? row.title : row.rule,
|
|
13328
|
+
summary: typeof row.summary === "string" ? row.summary : "",
|
|
13329
|
+
severity: typeof row.severity === "string" ? row.severity : "info",
|
|
13330
|
+
state: typeof row.state === "string" ? row.state : "firing",
|
|
13331
|
+
category: typeof row.category === "string" ? row.category : null,
|
|
13332
|
+
openedAt: field(row, "openedAt", "opened_at"),
|
|
13333
|
+
lastSeenAt: field(row, "lastSeenAt", "last_seen_at"),
|
|
13334
|
+
resolvedAt: field(row, "resolvedAt", "resolved_at"),
|
|
13335
|
+
acknowledgedAt: field(row, "acknowledgedAt", "acknowledged_at"),
|
|
13336
|
+
snoozedUntil: field(row, "snoozedUntil", "snoozed_until")
|
|
13337
|
+
};
|
|
13338
|
+
}
|
|
13339
|
+
/** `--hours`, checked: a whole number from 1 to a week. */
|
|
13340
|
+
function resolveSnoozeHours(value) {
|
|
13341
|
+
if (value === void 0) fail("Say how long to snooze it for.", `Pass --hours <1-168>, e.g. --hours 24.`, "usage");
|
|
13342
|
+
const hours = Number(value);
|
|
13343
|
+
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");
|
|
13344
|
+
return hours;
|
|
13345
|
+
}
|
|
13346
|
+
var SEVERITY_MARK = {
|
|
13347
|
+
critical: chalk.red("●"),
|
|
13348
|
+
warning: chalk.yellow("●"),
|
|
13349
|
+
info: chalk.gray("●")
|
|
13350
|
+
};
|
|
13351
|
+
async function listIncidents(client, projectId, all) {
|
|
13352
|
+
return ((await client.data.table("alert-incidents").find({
|
|
13353
|
+
where: {
|
|
13354
|
+
project: ["==", projectId],
|
|
13355
|
+
state: all ? ["in", ["firing", "resolved"]] : ["==", "firing"]
|
|
13356
|
+
},
|
|
13357
|
+
orderBy: ["openedAt", "desc"],
|
|
13358
|
+
limit: 100
|
|
13359
|
+
})).data ?? []).map(readIncident).filter((i) => i !== null);
|
|
13360
|
+
}
|
|
13361
|
+
async function alertsCommand(action, rawArgs) {
|
|
13362
|
+
const { flags, positionals } = parseCloudArgs({
|
|
13363
|
+
spec: ALERTS_FLAGS,
|
|
13364
|
+
rawArgs,
|
|
13365
|
+
commandWords: 2,
|
|
13366
|
+
command: "cloud alerts",
|
|
13367
|
+
maxPositionals: 2
|
|
13368
|
+
});
|
|
13369
|
+
const word = positionals[0] ?? action;
|
|
13370
|
+
requireKnownAction("alerts", word, ALERTS_ACTIONS);
|
|
13371
|
+
const verb = word ?? "list";
|
|
13372
|
+
const incidentId = positionals[1];
|
|
13373
|
+
if (flags["--all"] && verb !== "list") fail("--all goes with `alerts list`.", "Run `rebase cloud alerts --help`.", "usage");
|
|
13374
|
+
if (flags["--hours"] !== void 0 && verb !== "snooze") fail("--hours goes with `alerts snooze`.", "Run `rebase cloud alerts --help`.", "usage");
|
|
13375
|
+
if (verb === "list" && incidentId !== void 0) fail(`Too many arguments for \`alerts list\`: ${incidentId}`, "Run `rebase cloud alerts --help`.", "usage");
|
|
13376
|
+
if (verb !== "list" && !incidentId) fail(`Name the alert to ${verb === "ack" ? "acknowledge" : "snooze"}.`, "`rebase cloud alerts` lists them with their ids.", "usage");
|
|
13377
|
+
const hours = verb === "snooze" ? resolveSnoozeHours(flags["--hours"]) : void 0;
|
|
13378
|
+
const { client } = await requireClient(rawArgs);
|
|
13379
|
+
if (verb === "ack") {
|
|
13380
|
+
try {
|
|
13381
|
+
await client.functions.invoke("alerts", {}, { path: `incidents/${encodeURIComponent(incidentId)}/acknowledge` });
|
|
13382
|
+
} catch (e) {
|
|
13383
|
+
reportError(e, "Failed to acknowledge the alert");
|
|
13384
|
+
}
|
|
13385
|
+
emit(() => success(`Acknowledged ${incidentId}. Reminders stop for everyone; you will still hear if it gets worse or is resolved.`), {
|
|
13386
|
+
id: incidentId,
|
|
13387
|
+
acknowledged: true
|
|
13388
|
+
});
|
|
13389
|
+
return;
|
|
13390
|
+
}
|
|
13391
|
+
if (verb === "snooze") {
|
|
13392
|
+
let res;
|
|
13393
|
+
try {
|
|
13394
|
+
res = await client.functions.invoke("alerts", { hours }, { path: `incidents/${encodeURIComponent(incidentId)}/snooze` });
|
|
13395
|
+
} catch (e) {
|
|
13396
|
+
reportError(e, "Failed to snooze the alert");
|
|
13397
|
+
}
|
|
13398
|
+
const until = res.snoozedUntil ?? null;
|
|
13399
|
+
emit(() => success(`Snoozed ${incidentId}${until ? ` until ${new Date(until).toLocaleString()}` : ` for ${hours} hours`}. Nobody is emailed about it until then, unless it is resolved.`), {
|
|
13400
|
+
id: incidentId,
|
|
13401
|
+
hours,
|
|
13402
|
+
snoozedUntil: until
|
|
13403
|
+
});
|
|
13404
|
+
return;
|
|
13405
|
+
}
|
|
13406
|
+
const projectId = await requireProject(rawArgs, client);
|
|
13407
|
+
const label = `project ${displayProjectRef(rawArgs) || projectId}`;
|
|
13408
|
+
const all = flags["--all"] === true;
|
|
13409
|
+
let incidents;
|
|
13410
|
+
try {
|
|
13411
|
+
incidents = await listIncidents(client, projectId, all);
|
|
13412
|
+
} catch (e) {
|
|
13413
|
+
reportError(e, "Failed to list alerts");
|
|
13414
|
+
}
|
|
13415
|
+
emit(() => {
|
|
13416
|
+
console.log("");
|
|
13417
|
+
console.log(chalk.bold(` 🚨 Alerts — ${label}`));
|
|
13418
|
+
console.log("");
|
|
13419
|
+
if (incidents.length === 0) {
|
|
13420
|
+
console.log(chalk.gray(all ? " Nothing has gone wrong." : " Nothing is open. `--all` shows the resolved ones too."));
|
|
13421
|
+
console.log("");
|
|
13422
|
+
return;
|
|
13423
|
+
}
|
|
13424
|
+
for (const i of incidents) {
|
|
13425
|
+
const when = i.openedAt ? new Date(i.openedAt).toLocaleString() : "";
|
|
13426
|
+
const state = i.state === "resolved" ? chalk.green("resolved") : chalk.red("open");
|
|
13427
|
+
const quiet = i.acknowledgedAt ? chalk.gray(" · acknowledged") : i.snoozedUntil && Date.parse(i.snoozedUntil) > Date.now() ? chalk.gray(` · snoozed until ${new Date(i.snoozedUntil).toLocaleString()}`) : "";
|
|
13428
|
+
console.log(` ${SEVERITY_MARK[i.severity] ?? SEVERITY_MARK.info} ${chalk.bold(i.title)} ${state}${quiet} ${chalk.gray(when)}`);
|
|
13429
|
+
if (i.summary) console.log(chalk.gray(` ${i.summary}`));
|
|
13430
|
+
console.log(chalk.gray(` ${i.id}`));
|
|
13431
|
+
}
|
|
13432
|
+
console.log("");
|
|
13433
|
+
note(chalk.gray("Acknowledge one with `rebase cloud alerts ack <id>`, or quiet it with `rebase cloud alerts snooze <id> --hours 24`."));
|
|
13434
|
+
console.log("");
|
|
13435
|
+
}, {
|
|
13436
|
+
projectId,
|
|
13437
|
+
all,
|
|
13438
|
+
incidents
|
|
13439
|
+
});
|
|
13440
|
+
}
|
|
13441
|
+
//#endregion
|
|
13555
13442
|
//#region src/commands/cloud/declared-resources.ts
|
|
13556
13443
|
/**
|
|
13557
13444
|
* `rebase cloud resources` — what a project declares against what the platform
|
|
@@ -13732,12 +13619,13 @@ var ACTION_HELP = {
|
|
|
13732
13619
|
},
|
|
13733
13620
|
clusters: {
|
|
13734
13621
|
command: "cloud clusters",
|
|
13735
|
-
usage: "cloud clusters [list|add|verify|registry] [options]",
|
|
13622
|
+
usage: "cloud clusters [list|add|verify|registry|baseline] [options]",
|
|
13736
13623
|
summary: "The compute clusters tenants run on. Platform-admin only.",
|
|
13737
13624
|
flags: [],
|
|
13738
13625
|
examples: [
|
|
13739
13626
|
"rebase cloud clusters",
|
|
13740
13627
|
"rebase cloud clusters verify <cluster-id> --baseline",
|
|
13628
|
+
"rebase cloud clusters baseline <cluster-id> --install",
|
|
13741
13629
|
"rebase cloud clusters add --name gke-eu --provider gcp --region europe-west1 --kubeconfig ./kubeconfig",
|
|
13742
13630
|
"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
13631
|
]
|
|
@@ -13769,13 +13657,14 @@ var ACTION_HELP = {
|
|
|
13769
13657
|
],
|
|
13770
13658
|
examples: [
|
|
13771
13659
|
"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\""
|
|
13660
|
+
"rebase cloud projects create --name Shop --subdomain shop --db none --yes",
|
|
13661
|
+
"rebase cloud projects create --name Shop --subdomain shop --db byodb --connection-string \"$DATABASE_URL\" --yes"
|
|
13774
13662
|
],
|
|
13775
13663
|
notes: [
|
|
13776
13664
|
"The subdomain cannot be changed in passing later — a typo here is a new project.",
|
|
13777
13665
|
"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."
|
|
13666
|
+
"--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.",
|
|
13667
|
+
"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
13668
|
]
|
|
13780
13669
|
},
|
|
13781
13670
|
"db create": {
|
|
@@ -13833,11 +13722,14 @@ var ACTION_HELP = {
|
|
|
13833
13722
|
["--allow-downgrade", "Deploy a bundle built on an older framework release than the project runs"],
|
|
13834
13723
|
["--preview", "Serve this build on an address of its own and leave production untouched"],
|
|
13835
13724
|
["--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)"]
|
|
13725
|
+
["--eject", "Leave the managed runtime on purpose (ejects to a container image)"],
|
|
13726
|
+
["--git", "Have the control plane build the project's connected repository instead of this directory. The positional is then the branch"]
|
|
13837
13727
|
],
|
|
13838
13728
|
examples: [
|
|
13839
13729
|
"rebase cloud deploy",
|
|
13840
13730
|
"rebase cloud deploy web --message \"add search\"",
|
|
13731
|
+
"rebase cloud deploy --git",
|
|
13732
|
+
"rebase cloud deploy --git release-2026-11",
|
|
13841
13733
|
"rebase cloud deploy --preview",
|
|
13842
13734
|
"rebase cloud deploy --preview-name new-quiz",
|
|
13843
13735
|
"rebase cloud deploy --timeout 300 --json"
|
|
@@ -13854,7 +13746,8 @@ var ACTION_HELP = {
|
|
|
13854
13746
|
"--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
13747
|
"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
13748
|
"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."
|
|
13749
|
+
"A control plane without previews refuses --preview with previews_unavailable, and nothing is deployed.",
|
|
13750
|
+
"--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
13751
|
]
|
|
13859
13752
|
},
|
|
13860
13753
|
previews: {
|
|
@@ -13888,7 +13781,7 @@ var ACTION_HELP = {
|
|
|
13888
13781
|
["--follow, -f", "Keep printing new lines until Ctrl-C (exits 0); with no --runtime, tail a build still running"],
|
|
13889
13782
|
["--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
13783
|
["--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)"],
|
|
13784
|
+
["--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
13785
|
["--grep <text>", "With --runtime: only lines containing the text (any case); `/re/flags` for a regular expression"],
|
|
13893
13786
|
["--level <l>", "With --runtime: only lines at this severity or worse — error, warn, info or debug"],
|
|
13894
13787
|
["--previous", "With --runtime: the last instance of a container that restarted, where a crash's reason usually is"]
|
|
@@ -13911,7 +13804,7 @@ var ACTION_HELP = {
|
|
|
13911
13804
|
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
13805
|
flags: [],
|
|
13913
13806
|
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."]
|
|
13807
|
+
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
13808
|
},
|
|
13916
13809
|
"clusters add": {
|
|
13917
13810
|
command: "cloud clusters add",
|
|
@@ -13954,6 +13847,14 @@ var ACTION_HELP = {
|
|
|
13954
13847
|
examples: ["rebase cloud clusters verify gke-europe-west1 --baseline"],
|
|
13955
13848
|
notes: ["Exits non-zero when the verdict is `unusable`, so it works as a gate."]
|
|
13956
13849
|
},
|
|
13850
|
+
"clusters baseline": {
|
|
13851
|
+
command: "cloud clusters baseline",
|
|
13852
|
+
usage: "cloud clusters baseline <cluster-id> [--install] [--yes]",
|
|
13853
|
+
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.",
|
|
13854
|
+
flags: [["--install", "Install the missing components, in the background. Asks first"]],
|
|
13855
|
+
examples: ["rebase cloud clusters baseline gke-europe-west1", "rebase cloud clusters baseline gke-europe-west1 --install --yes"],
|
|
13856
|
+
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."]
|
|
13857
|
+
},
|
|
13957
13858
|
"resources prune": {
|
|
13958
13859
|
command: "cloud resources prune",
|
|
13959
13860
|
usage: "cloud resources prune database <key> [--yes]",
|
|
@@ -14000,7 +13901,7 @@ var ACTION_HELP = {
|
|
|
14000
13901
|
],
|
|
14001
13902
|
examples: [
|
|
14002
13903
|
"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",
|
|
13904
|
+
"rebase cloud db access enable --allow 34.89.253.13 --tables rebase.metric_samples,rebase.cron_logs --yes",
|
|
14004
13905
|
"rebase cloud db access reveal --ca-out db-ca.pem",
|
|
14005
13906
|
"rebase cloud db access disable --yes"
|
|
14006
13907
|
],
|
|
@@ -14009,7 +13910,7 @@ var ACTION_HELP = {
|
|
|
14009
13910
|
"The `rebase` schema holds users, password hashes and session tokens: it is never granted whole, and its credential tables never at all.",
|
|
14010
13911
|
"Managed databases on GCP capacity only for now. Each project with access on has its own network load balancer, which is billed.",
|
|
14011
13912
|
"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
|
|
13913
|
+
"`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
13914
|
]
|
|
14014
13915
|
},
|
|
14015
13916
|
"db pitr": {
|
|
@@ -14044,6 +13945,14 @@ var ACTION_HELP = {
|
|
|
14044
13945
|
examples: ["rebase cloud domains add app.example.com"],
|
|
14045
13946
|
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
13947
|
},
|
|
13948
|
+
"domains primary": {
|
|
13949
|
+
command: "cloud domains primary",
|
|
13950
|
+
usage: "cloud domains primary <domain>",
|
|
13951
|
+
summary: "Make one of the project's verified domains its canonical host: the address links and redirects are built from. The project keeps serving its other domains.",
|
|
13952
|
+
flags: [],
|
|
13953
|
+
examples: ["rebase cloud domains primary app.example.com"],
|
|
13954
|
+
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."]
|
|
13955
|
+
},
|
|
14047
13956
|
"domains remove": {
|
|
14048
13957
|
command: "cloud domains remove",
|
|
14049
13958
|
usage: "cloud domains remove <domain>",
|
|
@@ -14175,17 +14084,23 @@ var ACTION_HELP = {
|
|
|
14175
14084
|
},
|
|
14176
14085
|
billing: {
|
|
14177
14086
|
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.",
|
|
14087
|
+
usage: "cloud billing [setup|checkout|invoices|upcoming|email] [<address>]",
|
|
14088
|
+
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
14089
|
flags: [["--limit <n>", "`invoices` only: how many to list, newest first. Default 24, at most 100"]],
|
|
14181
14090
|
examples: [
|
|
14182
14091
|
"rebase cloud billing",
|
|
14183
14092
|
"rebase cloud billing setup",
|
|
14184
14093
|
"rebase cloud billing checkout --project shop",
|
|
14185
14094
|
"rebase cloud billing invoices --json",
|
|
14186
|
-
"rebase cloud billing upcoming"
|
|
14095
|
+
"rebase cloud billing upcoming",
|
|
14096
|
+
"rebase cloud billing email billing@example.com"
|
|
14187
14097
|
],
|
|
14188
|
-
notes: [
|
|
14098
|
+
notes: [
|
|
14099
|
+
"`setup` comes before the first deploy: without a card the control plane answers 402, and `deploy` refuses before it builds.",
|
|
14100
|
+
"`email` changes the billing account and the Stripe customer together; owners and admins of the organization.",
|
|
14101
|
+
"A control plane that does not serve invoices, or the preview of the next one, refuses `invoices` or `upcoming` with not_served.",
|
|
14102
|
+
"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."
|
|
14103
|
+
]
|
|
14189
14104
|
},
|
|
14190
14105
|
"app-key": {
|
|
14191
14106
|
command: "cloud app-key",
|
|
@@ -14222,7 +14137,7 @@ var ACTION_HELP = {
|
|
|
14222
14137
|
guests: {
|
|
14223
14138
|
command: "cloud guests",
|
|
14224
14139
|
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.",
|
|
14140
|
+
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
14141
|
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
14142
|
examples: [
|
|
14228
14143
|
"rebase cloud guests",
|
|
@@ -14300,7 +14215,11 @@ var ACTION_HELP = {
|
|
|
14300
14215
|
"rebase cloud compute apply",
|
|
14301
14216
|
"rebase cloud compute window --day sun --hour 3"
|
|
14302
14217
|
],
|
|
14303
|
-
notes: [
|
|
14218
|
+
notes: [
|
|
14219
|
+
"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.",
|
|
14220
|
+
"`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.",
|
|
14221
|
+
"A control plane without maintenance windows leaves those lines out and says so; `notServed` in the JSON lists what it left out."
|
|
14222
|
+
]
|
|
14304
14223
|
},
|
|
14305
14224
|
"compute apply": {
|
|
14306
14225
|
command: "cloud compute apply",
|
|
@@ -14353,12 +14272,13 @@ var ACTION_HELP = {
|
|
|
14353
14272
|
],
|
|
14354
14273
|
examples: [
|
|
14355
14274
|
"rebase cloud compute set --cpu 500m --memory 2Gi",
|
|
14356
|
-
"rebase cloud compute set --replicas 2 --autoscale-max 6",
|
|
14275
|
+
"rebase cloud compute set --replicas 2 --autoscale-max 6 --yes",
|
|
14357
14276
|
"rebase cloud compute set --db-instances 2 --db-memory 4Gi",
|
|
14358
14277
|
"rebase cloud compute set --db-autoscale-max-cpu 2 --db-autoscale-max-memory 8Gi"
|
|
14359
14278
|
],
|
|
14360
14279
|
notes: [
|
|
14361
14280
|
"Run `rebase cloud compute` first — it prints the current dials and the €/month this project is quoted.",
|
|
14281
|
+
"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
14282
|
"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
14283
|
"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
14284
|
]
|
|
@@ -14594,10 +14514,82 @@ var ACTION_HELP = {
|
|
|
14594
14514
|
},
|
|
14595
14515
|
metrics: {
|
|
14596
14516
|
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.",
|
|
14517
|
+
usage: "cloud metrics [--runtime | --history [--series <name>] [--minutes <n>]]",
|
|
14518
|
+
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.",
|
|
14519
|
+
flags: [
|
|
14520
|
+
["--runtime", "Requests, errors, error rate and mean latency, from the app's own counters"],
|
|
14521
|
+
["--history", "A recorded series over a window instead of the live figures"],
|
|
14522
|
+
["--series <name>", "With --history: cpu_millicores (default), memory_bytes or event_loop_delay_ms"],
|
|
14523
|
+
["--minutes <n>", "With --history: how far back, 1 to 20160 (fourteen days). Default: 60"]
|
|
14524
|
+
],
|
|
14525
|
+
examples: [
|
|
14526
|
+
"rebase cloud metrics",
|
|
14527
|
+
"rebase cloud metrics --runtime",
|
|
14528
|
+
"rebase cloud metrics --history --series memory_bytes --minutes 1440 --json"
|
|
14529
|
+
],
|
|
14530
|
+
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`)."]
|
|
14531
|
+
},
|
|
14532
|
+
"deploy-hooks": {
|
|
14533
|
+
command: "cloud deploy-hooks",
|
|
14534
|
+
usage: "cloud deploy-hooks [list|create|revoke] [options]",
|
|
14535
|
+
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.",
|
|
14536
|
+
flags: [["--name <name>", "create: what to call it. Default: Deploy hook"], ["--branch <branch>", "create: the branch it builds. Default: the project's configured branch"]],
|
|
14537
|
+
examples: [
|
|
14538
|
+
"rebase cloud deploy-hooks",
|
|
14539
|
+
"rebase cloud deploy-hooks create --name github --branch main",
|
|
14540
|
+
"rebase cloud deploy-hooks revoke 7 --yes"
|
|
14541
|
+
],
|
|
14542
|
+
notes: [
|
|
14543
|
+
"The URL is printed once, at `create`: it is the credential, and the control plane keeps only its hash.",
|
|
14544
|
+
"A GitHub or GitLab push to another branch, a tag, or any other event is acknowledged and ignored.",
|
|
14545
|
+
"Creating and revoking take the owner or admin role; any member may list. A project holds at most 20."
|
|
14546
|
+
]
|
|
14547
|
+
},
|
|
14548
|
+
"deploy-hooks create": {
|
|
14549
|
+
command: "cloud deploy-hooks create",
|
|
14550
|
+
usage: "cloud deploy-hooks create [--name <name>] [--branch <branch>]",
|
|
14551
|
+
summary: "Mint a deploy hook and print its URL, once. POSTing to the URL builds and ships the connected repository.",
|
|
14552
|
+
flags: [["--name <name>", "What to call it. Default: Deploy hook"], ["--branch <branch>", "The branch it builds. Default: the project's configured branch"]],
|
|
14553
|
+
examples: ["rebase cloud deploy-hooks create --name github --branch main --json"],
|
|
14554
|
+
notes: ["`url` and `token` in the JSON are the only copy: store them where the caller of the hook reads secrets."]
|
|
14555
|
+
},
|
|
14556
|
+
"deploy-hooks revoke": {
|
|
14557
|
+
command: "cloud deploy-hooks revoke",
|
|
14558
|
+
usage: "cloud deploy-hooks revoke <id> [--yes]",
|
|
14559
|
+
summary: "Delete a deploy hook: anything POSTing to its URL is refused from then on. Asks first.",
|
|
14560
|
+
flags: [],
|
|
14561
|
+
examples: ["rebase cloud deploy-hooks revoke 7 --yes"]
|
|
14562
|
+
},
|
|
14563
|
+
alerts: {
|
|
14564
|
+
command: "cloud alerts",
|
|
14565
|
+
usage: "cloud alerts [list|ack|snooze] [<incidentId>] [options]",
|
|
14566
|
+
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.",
|
|
14567
|
+
flags: [["--all", "list: the resolved ones as well as the open ones"], ["--hours <1-168>", "snooze: how long. Required"]],
|
|
14568
|
+
examples: [
|
|
14569
|
+
"rebase cloud alerts",
|
|
14570
|
+
"rebase cloud alerts list --all --json",
|
|
14571
|
+
"rebase cloud alerts ack 6f1c2a0e-…",
|
|
14572
|
+
"rebase cloud alerts snooze 6f1c2a0e-… --hours 24"
|
|
14573
|
+
],
|
|
14574
|
+
notes: [
|
|
14575
|
+
"Any member of the organization may read, acknowledge and snooze. Only an open alert can be acknowledged or snoozed.",
|
|
14576
|
+
"An organization-wide problem (a failed payment) belongs to no project, and is not listed here; the console shows it.",
|
|
14577
|
+
"You still hear about an acknowledged or snoozed alert if it gets worse or is resolved."
|
|
14578
|
+
]
|
|
14579
|
+
},
|
|
14580
|
+
"alerts ack": {
|
|
14581
|
+
command: "cloud alerts ack",
|
|
14582
|
+
usage: "cloud alerts ack <incidentId>",
|
|
14583
|
+
summary: "Acknowledge an open alert: reminders stop for everyone in the organization.",
|
|
14599
14584
|
flags: [],
|
|
14600
|
-
examples: ["rebase cloud
|
|
14585
|
+
examples: ["rebase cloud alerts ack 6f1c2a0e-…"]
|
|
14586
|
+
},
|
|
14587
|
+
"alerts snooze": {
|
|
14588
|
+
command: "cloud alerts snooze",
|
|
14589
|
+
usage: "cloud alerts snooze <incidentId> --hours <1-168>",
|
|
14590
|
+
summary: "Snooze an open alert: nobody in the organization is emailed about it until the time is up, unless it is resolved.",
|
|
14591
|
+
flags: [["--hours <1-168>", "How long, in hours. Required; at most a week"]],
|
|
14592
|
+
examples: ["rebase cloud alerts snooze 6f1c2a0e-… --hours 24"]
|
|
14601
14593
|
}
|
|
14602
14594
|
};
|
|
14603
14595
|
/** Print one action's page — human, or its JSON description when piped. */
|
|
@@ -14704,6 +14696,7 @@ var CLOUD_VALUE_FLAGS = {
|
|
|
14704
14696
|
"--grep": String,
|
|
14705
14697
|
"--host": String,
|
|
14706
14698
|
"--hour": String,
|
|
14699
|
+
"--hours": String,
|
|
14707
14700
|
"--ingress-address": String,
|
|
14708
14701
|
"--kubeconfig": String,
|
|
14709
14702
|
"--level": String,
|
|
@@ -14711,6 +14704,7 @@ var CLOUD_VALUE_FLAGS = {
|
|
|
14711
14704
|
"--live-timeout": String,
|
|
14712
14705
|
"--memory": String,
|
|
14713
14706
|
"--message": String,
|
|
14707
|
+
"--minutes": String,
|
|
14714
14708
|
"--month": String,
|
|
14715
14709
|
"--name": String,
|
|
14716
14710
|
"--older-than": String,
|
|
@@ -14732,12 +14726,15 @@ var CLOUD_VALUE_FLAGS = {
|
|
|
14732
14726
|
"--scale-to-zero": String,
|
|
14733
14727
|
"--schemas": String,
|
|
14734
14728
|
"--secret-access-key": String,
|
|
14729
|
+
"--series": String,
|
|
14735
14730
|
"--since": String,
|
|
14736
14731
|
"--slug": String,
|
|
14737
14732
|
"--source": String,
|
|
14738
14733
|
"--spot": String,
|
|
14739
14734
|
"--storage": String,
|
|
14735
|
+
"--studio": String,
|
|
14740
14736
|
"--subdomain": String,
|
|
14737
|
+
"--table": String,
|
|
14741
14738
|
"--tail": String,
|
|
14742
14739
|
"--tables": String,
|
|
14743
14740
|
"--target": String,
|
|
@@ -14810,7 +14807,8 @@ var GROUP_ALIASES = {
|
|
|
14810
14807
|
extension: "extensions",
|
|
14811
14808
|
org: "orgs",
|
|
14812
14809
|
preview: "previews",
|
|
14813
|
-
project: "projects"
|
|
14810
|
+
project: "projects",
|
|
14811
|
+
releases: "deployments"
|
|
14814
14812
|
};
|
|
14815
14813
|
var GROUP_HELP = {
|
|
14816
14814
|
env: printEnvHelp,
|
|
@@ -14925,6 +14923,12 @@ async function cloudCommand(subcommand, rawArgs) {
|
|
|
14925
14923
|
case "cron":
|
|
14926
14924
|
await cronCommand(action, rawArgs);
|
|
14927
14925
|
break;
|
|
14926
|
+
case "deploy-hooks":
|
|
14927
|
+
await deployHooksCommand(action, rawArgs);
|
|
14928
|
+
break;
|
|
14929
|
+
case "alerts":
|
|
14930
|
+
await alertsCommand(action, rawArgs);
|
|
14931
|
+
break;
|
|
14928
14932
|
case "env":
|
|
14929
14933
|
await envCommand(action, rawArgs);
|
|
14930
14934
|
break;
|
|
@@ -15162,7 +15166,7 @@ var CLOUD_GROUPS = [
|
|
|
15162
15166
|
{
|
|
15163
15167
|
action: "metrics",
|
|
15164
15168
|
section: "Deploy & observe",
|
|
15165
|
-
description: "Live CPU, memory and disk"
|
|
15169
|
+
description: "Live CPU, memory and disk; requests and errors with --runtime; history with --history"
|
|
15166
15170
|
},
|
|
15167
15171
|
{
|
|
15168
15172
|
action: "debug",
|
|
@@ -15174,6 +15178,16 @@ var CLOUD_GROUPS = [
|
|
|
15174
15178
|
section: "Deploy & observe",
|
|
15175
15179
|
description: "The app's cron jobs and their run history. Read-only"
|
|
15176
15180
|
},
|
|
15181
|
+
{
|
|
15182
|
+
action: "deploy-hooks",
|
|
15183
|
+
section: "Deploy & observe",
|
|
15184
|
+
description: "URLs that build and ship the connected repository when POSTed to"
|
|
15185
|
+
},
|
|
15186
|
+
{
|
|
15187
|
+
action: "alerts",
|
|
15188
|
+
section: "Deploy & observe",
|
|
15189
|
+
description: "What the platform has seen go wrong, and acknowledging or snoozing it"
|
|
15190
|
+
},
|
|
15177
15191
|
{
|
|
15178
15192
|
action: "env",
|
|
15179
15193
|
section: "Config",
|
|
@@ -15192,7 +15206,7 @@ var CLOUD_GROUPS = [
|
|
|
15192
15206
|
{
|
|
15193
15207
|
action: "settings",
|
|
15194
15208
|
section: "Config",
|
|
15195
|
-
description: "Name, subdomain, repository, branch"
|
|
15209
|
+
description: "Name, subdomain, repository, branch, Studio access"
|
|
15196
15210
|
},
|
|
15197
15211
|
{
|
|
15198
15212
|
action: "app-key",
|
|
@@ -15237,11 +15251,6 @@ var CLOUD_GROUPS = [
|
|
|
15237
15251
|
section: "Deploy & observe",
|
|
15238
15252
|
description: "Send deploy, backup, billing and usage events to Slack, Discord or any URL"
|
|
15239
15253
|
},
|
|
15240
|
-
{
|
|
15241
|
-
action: "webhooks",
|
|
15242
|
-
section: "Other resources",
|
|
15243
|
-
description: "Retired: use `notifications`, or a WebhookDispatcher in your app's code"
|
|
15244
|
-
},
|
|
15245
15254
|
{
|
|
15246
15255
|
action: "resources",
|
|
15247
15256
|
section: "Other resources",
|
|
@@ -15292,4 +15301,4 @@ function printCloudHelp() {
|
|
|
15292
15301
|
//#endregion
|
|
15293
15302
|
export { CLOUD_GROUP_NAMES, GROUP_ALIASES, cloudCommand };
|
|
15294
15303
|
|
|
15295
|
-
//# sourceMappingURL=cloud-
|
|
15304
|
+
//# sourceMappingURL=cloud-MqnyPnmX.js.map
|