@supersdk/supercli 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/analyticsClient.js +48 -0
- package/dist/api/analyticsClient.js.map +1 -0
- package/dist/api/consoleClient.js +58 -42
- package/dist/api/consoleClient.js.map +1 -1
- package/dist/api/dbClient.js +90 -0
- package/dist/api/dbClient.js.map +1 -0
- package/dist/api/settingsClient.js +43 -0
- package/dist/api/settingsClient.js.map +1 -0
- package/dist/cli.js +24 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.js +67 -226
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/analytics.js +265 -0
- package/dist/commands/analytics.js.map +1 -0
- package/dist/commands/db.js +590 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/deploy.js +883 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/env.js +53 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/image.js +471 -0
- package/dist/commands/image.js.map +1 -0
- package/dist/commands/logs.js +131 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/publishSite.js +28 -10
- package/dist/commands/publishSite.js.map +1 -1
- package/dist/commands/register.js +363 -0
- package/dist/commands/register.js.map +1 -0
- package/dist/commands/settings.js +307 -0
- package/dist/commands/settings.js.map +1 -0
- package/dist/commands/sqlInput.js +48 -0
- package/dist/commands/sqlInput.js.map +1 -0
- package/dist/docker/dockerCli.js +301 -0
- package/dist/docker/dockerCli.js.map +1 -0
- package/dist/docker/registry.js +128 -0
- package/dist/docker/registry.js.map +1 -0
- package/dist/generated/log_contract.js +33 -0
- package/dist/generated/log_contract.js.map +1 -0
- package/dist/output/envelope.js +20 -5
- package/dist/output/envelope.js.map +1 -1
- package/dist/output/resultPrinter.js +35 -6
- package/dist/output/resultPrinter.js.map +1 -1
- package/dist/publish/registryClient.js +128 -0
- package/dist/publish/registryClient.js.map +1 -0
- package/dist/publish/runClient.js +495 -0
- package/dist/publish/runClient.js.map +1 -0
- package/dist/template/scripts/build_android.sh +107 -8
- package/dist/template/scripts/web_package.py +15 -3
- package/dist/template/web/src/js/app.js +3 -2
- package/dist/template/web/src/js/supersdk.js +1 -2024
- package/dist/template/web/src/js/supersdk.provenance.json +5 -4
- package/dist/util/prompt.js +7 -2
- package/dist/util/prompt.js.map +1 -1
- package/dist/workspace/config.js +1 -0
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/inspect.js +274 -0
- package/dist/workspace/inspect.js.map +1 -0
- package/dist/workspace/projectIdentity.js +255 -0
- package/dist/workspace/projectIdentity.js.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resultPrinter.js","sourceRoot":"","sources":["../../src/output/resultPrinter.ts"],"names":[],"mappings":";;;AAAA,kEAAkE;AAClE,+EAA+E;AAC/E,2EAA2E;AAC3E,yEAAyE;AACzE,4DAA4D;AAC5D,gFAAgF;AAChF,
|
|
1
|
+
{"version":3,"file":"resultPrinter.js","sourceRoot":"","sources":["../../src/output/resultPrinter.ts"],"names":[],"mappings":";;;AAAA,kEAAkE;AAClE,+EAA+E;AAC/E,2EAA2E;AAC3E,yEAAyE;AACzE,4DAA4D;AAC5D,gFAAgF;AAChF,yCAOoB;AACpB,iDAAsE;AACtE,qCAAkC;AAelC,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C,SAAS,eAAe,CAAC,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,MAAa,aAAa;IAIb;IAHF,SAAS,CAAS;IAE3B,YACW,IAAgB,EACzB,SAAkB;QADT,SAAI,GAAJ,IAAI,CAAY;QAGzB,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAA,4BAAiB,GAAE,CAAC;IACpD,CAAC;IAED,4CAA4C;IAC5C,OAAO,CAAC,MAAe,EAAE,OAA6E,EAAE;QACtG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UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;CACF;AAvFD,sCAuFC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Project-scoped Image Registry Console API client.
|
|
4
|
+
*
|
|
5
|
+
* The registry surface deliberately uses the same cli_ bearer and X-Org-Id
|
|
6
|
+
* context as deploy. It never talks to Zot directly and never accepts a
|
|
7
|
+
* registry credential: listing and conditional deletion are coordinated by CA.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.RegistryClient = void 0;
|
|
11
|
+
const PUBLIC_CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
12
|
+
function stringValue(value) {
|
|
13
|
+
return typeof value === 'string' ? value : undefined;
|
|
14
|
+
}
|
|
15
|
+
async function responseEnvelope(response) {
|
|
16
|
+
let text;
|
|
17
|
+
try {
|
|
18
|
+
text = await response.text();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (text.length === 0)
|
|
24
|
+
return {};
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(text);
|
|
27
|
+
return parsed !== null && typeof parsed === 'object' ? parsed : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function projectPath(spid) {
|
|
34
|
+
return `/api/console/projects/${encodeURIComponent(spid)}`;
|
|
35
|
+
}
|
|
36
|
+
class RegistryClient {
|
|
37
|
+
apiOrigin;
|
|
38
|
+
fetchImpl;
|
|
39
|
+
constructor(apiOrigin, fetchImpl) {
|
|
40
|
+
this.apiOrigin = apiOrigin;
|
|
41
|
+
this.fetchImpl = fetchImpl ?? globalThis.fetch;
|
|
42
|
+
}
|
|
43
|
+
async send(ctx, method, path, body) {
|
|
44
|
+
if (!this.fetchImpl) {
|
|
45
|
+
return { kind: 'infra_error', message: 'no fetch implementation available (requires Node >=18)' };
|
|
46
|
+
}
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
const timer = setTimeout(() => controller.abort(), 30_000);
|
|
49
|
+
let response;
|
|
50
|
+
try {
|
|
51
|
+
response = await this.fetchImpl(`${this.apiOrigin}${path}`, {
|
|
52
|
+
method,
|
|
53
|
+
headers: {
|
|
54
|
+
accept: 'application/json',
|
|
55
|
+
authorization: `Bearer ${ctx.token}`,
|
|
56
|
+
'x-org-id': ctx.orgId,
|
|
57
|
+
...(ctx.requestId ? { 'x-request-id': ctx.requestId } : {}),
|
|
58
|
+
...(body === undefined ? {} : { 'content-type': 'application/json' }),
|
|
59
|
+
},
|
|
60
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
61
|
+
redirect: 'manual',
|
|
62
|
+
signal: controller.signal,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (controller.signal.aborted || err.name === 'AbortError') {
|
|
67
|
+
return { kind: 'infra_error', message: 'registry request timed out' };
|
|
68
|
+
}
|
|
69
|
+
return { kind: 'infra_error', message: 'registry network request failed' };
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
}
|
|
74
|
+
if (response.type === 'opaqueredirect' || (response.status >= 300 && response.status < 400)) {
|
|
75
|
+
return { kind: 'infra_error', status: response.status, message: `unexpected redirect (${response.status}); not followed` };
|
|
76
|
+
}
|
|
77
|
+
if (response.status === 401)
|
|
78
|
+
return { kind: 'auth_invalid' };
|
|
79
|
+
if (response.status === 403) {
|
|
80
|
+
return { kind: 'forbidden', message: 'registry access is forbidden for this project' };
|
|
81
|
+
}
|
|
82
|
+
if (response.status === 429) {
|
|
83
|
+
return { kind: 'rate_limited', message: 'registry request was rate limited; retry later' };
|
|
84
|
+
}
|
|
85
|
+
const envelope = await responseEnvelope(response);
|
|
86
|
+
if (!envelope) {
|
|
87
|
+
return { kind: 'infra_error', status: response.status, message: 'registry response was not valid JSON' };
|
|
88
|
+
}
|
|
89
|
+
const code = stringValue(envelope.code);
|
|
90
|
+
if (response.status >= 200 && response.status < 300 && code === 'SUCCESS') {
|
|
91
|
+
return { kind: 'success', data: envelope.data };
|
|
92
|
+
}
|
|
93
|
+
if (code && code !== 'SUCCESS' && PUBLIC_CODE.test(code)) {
|
|
94
|
+
return {
|
|
95
|
+
kind: 'business_error',
|
|
96
|
+
code,
|
|
97
|
+
message: stringValue(envelope.message) ?? code,
|
|
98
|
+
details: envelope.data ?? envelope.extra,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (response.status >= 500) {
|
|
102
|
+
return { kind: 'infra_error', status: response.status, message: `registry server error (${response.status})` };
|
|
103
|
+
}
|
|
104
|
+
return { kind: 'infra_error', status: response.status, message: `unexpected registry response (${response.status})` };
|
|
105
|
+
}
|
|
106
|
+
list(ctx, spid, query = {}) {
|
|
107
|
+
const params = new URLSearchParams();
|
|
108
|
+
if (query.cursor)
|
|
109
|
+
params.set('cursor', query.cursor);
|
|
110
|
+
if (query.page_size !== undefined)
|
|
111
|
+
params.set('page_size', String(query.page_size));
|
|
112
|
+
if (query.repository)
|
|
113
|
+
params.set('repository', query.repository);
|
|
114
|
+
const suffix = params.size > 0 ? `?${params.toString()}` : '';
|
|
115
|
+
return this.send(ctx, 'GET', `${projectPath(spid)}/images${suffix}`);
|
|
116
|
+
}
|
|
117
|
+
preflight(ctx, spid, body) {
|
|
118
|
+
return this.send(ctx, 'POST', `${projectPath(spid)}/image-delete-preflights`, body);
|
|
119
|
+
}
|
|
120
|
+
createDeletion(ctx, spid, body) {
|
|
121
|
+
return this.send(ctx, 'POST', `${projectPath(spid)}/image-deletions`, body);
|
|
122
|
+
}
|
|
123
|
+
getDeletion(ctx, spid, operationId) {
|
|
124
|
+
return this.send(ctx, 'GET', `${projectPath(spid)}/image-deletions/${encodeURIComponent(String(operationId))}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.RegistryClient = RegistryClient;
|
|
128
|
+
//# sourceMappingURL=registryClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registryClient.js","sourceRoot":"","sources":["../../src/publish/registryClient.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA0GH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAI,QAAkB;IACnD,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;QAC3C,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAE,MAA8B,CAAC,CAAC,CAAC,IAAI,CAAC;IAChG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,yBAAyB,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7D,CAAC;AAyBD,MAAa,cAAc;IAIN;IAHF,SAAS,CAAoB;IAE9C,YACmB,SAAiB,EAClC,SAA6B;QADZ,cAAS,GAAT,SAAS,CAAQ;QAGlC,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC;IACjD,CAAC;IAEO,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AY,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,SAAS,CACP,GAA2B,EAC3B,IAAY,EACZ,IAAyC;QAEzC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,0BAA0B,EAAE,IAAI,CAAC,CAAC;IACtF,CAAC;IAED,cAAc,CACZ,GAA2B,EAC3B,IAAY,EACZ,IAA8D;QAE9D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IAED,WAAW,CACT,GAA2B,EAC3B,IAAY,EACZ,WAAmB;QAEnB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,oBAAoB,kBAAkB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IAClH,CAAC;CACF;AAlHD,wCAkHC"}
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunClient = exports.IDEMPOTENCY_PENDING = void 0;
|
|
4
|
+
exports.classifyRunResponse = classifyRunResponse;
|
|
5
|
+
exports.runServiceDeployPath = runServiceDeployPath;
|
|
6
|
+
exports.describeRunError = describeRunError;
|
|
7
|
+
// SuperRun (container service) Console API client — the `deploy` counterpart of
|
|
8
|
+
// siteClient.ts. Same transport discipline:
|
|
9
|
+
// - `Authorization: Bearer <cli_ token>` + `x-org-id` on every call;
|
|
10
|
+
// - `x-idempotency-key` on the create call (AC-16 — replaying the same key
|
|
11
|
+
// returns the first service instead of creating a second);
|
|
12
|
+
// - `redirect: 'manual'` — a Bearer request is never forwarded to another
|
|
13
|
+
// origin;
|
|
14
|
+
// - the envelope classification is shared with the site path
|
|
15
|
+
// (`responseClassifier.ts`), because CA answers both families with the same
|
|
16
|
+
// `{code, message, data, extra}` envelope.
|
|
17
|
+
//
|
|
18
|
+
// The one divergence is the 503 family: `classifySiteResponse` treats "503 with
|
|
19
|
+
// an envelope code" as a hard business error (that is right for SITE_DISABLED),
|
|
20
|
+
// but the container path has three 503 codes that are genuinely INFRASTRUCTURE
|
|
21
|
+
// and retryable — see RUN_INFRA_CODES.
|
|
22
|
+
const responseClassifier_1 = require("./responseClassifier");
|
|
23
|
+
const log_contract_1 = require("../generated/log_contract");
|
|
24
|
+
const MAX_LOG_FOLLOW_FRAME_CHARS = 8 * 1024 * 1024;
|
|
25
|
+
const LOG_FOLLOW_FRAME_TYPES = new Set(['state', 'record', 'watermark', 'heartbeat', 'error', 'end']);
|
|
26
|
+
const LOG_FOLLOW_STATES = new Set(['catching_up', 'live', 'no_instances', 'retrying']);
|
|
27
|
+
const LOG_FOLLOW_ERROR_CODES = new Set([
|
|
28
|
+
'NOT_FOUND', 'FORBIDDEN', 'UNAUTHORIZED', 'INVALID_QUERY', 'QUERY_TOO_EXPENSIVE',
|
|
29
|
+
'FOLLOW_LIMIT_REACHED', 'LIVE_REPAIR_INCOMPLETE', 'FOLLOW_BACKPRESSURE',
|
|
30
|
+
'FOLLOW_CANCELLED', 'INTERNAL_ERROR',
|
|
31
|
+
]);
|
|
32
|
+
const LOG_SEVERITIES = new Set(['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'UNKNOWN']);
|
|
33
|
+
const QUERY_LOG_RECORD_KEYS = [
|
|
34
|
+
'schema_version', 'source_id', 'event_id', 'archive_seq', 'event_time',
|
|
35
|
+
'event_time_unix_nano', 'pod_uid', 'pod_name', 'container', 'restart_count',
|
|
36
|
+
'stream', 'occurrence', 'revision', 'severity', 'message', 'truncated', 'original_bytes',
|
|
37
|
+
];
|
|
38
|
+
function hasExactKeys(value, expected) {
|
|
39
|
+
const actual = Object.keys(value).sort();
|
|
40
|
+
const wanted = [...expected].sort();
|
|
41
|
+
return actual.length === wanted.length && actual.every((key, index) => key === wanted[index]);
|
|
42
|
+
}
|
|
43
|
+
function isOpaqueWatermark(value) {
|
|
44
|
+
return typeof value === 'string' && value.length >= 16 && value.length <= 4096
|
|
45
|
+
&& /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value);
|
|
46
|
+
}
|
|
47
|
+
function isCanonicalArchiveSeq(value) {
|
|
48
|
+
if (typeof value !== 'string' || !/^[1-9][0-9]{0,19}$/.test(value))
|
|
49
|
+
return false;
|
|
50
|
+
try {
|
|
51
|
+
return BigInt(value) <= 18446744073709551615n;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function isContractDateTime(value) {
|
|
58
|
+
if (typeof value !== 'string')
|
|
59
|
+
return false;
|
|
60
|
+
const matched = value.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?(Z|[+-]\d{2}:\d{2})$/);
|
|
61
|
+
if (!matched)
|
|
62
|
+
return false;
|
|
63
|
+
const [, year, month, day, hour, minute, second, fraction, offset] = matched;
|
|
64
|
+
const yearNumber = Number(year);
|
|
65
|
+
const monthNumber = Number(month);
|
|
66
|
+
const dayNumber = Number(day);
|
|
67
|
+
const daysInMonth = monthNumber >= 1 && monthNumber <= 12
|
|
68
|
+
? new Date(Date.UTC(yearNumber, monthNumber, 0)).getUTCDate()
|
|
69
|
+
: 0;
|
|
70
|
+
if (dayNumber < 1 || dayNumber > daysInMonth || Number(hour) > 23 || Number(minute) > 59 || Number(second) > 59)
|
|
71
|
+
return false;
|
|
72
|
+
const milliseconds = fraction ? `.${fraction.slice(0, 3).padEnd(3, '0')}` : '';
|
|
73
|
+
return !Number.isNaN(Date.parse(`${year}-${month}-${day}T${hour}:${minute}:${second}${milliseconds}${offset}`));
|
|
74
|
+
}
|
|
75
|
+
function utf8LengthAtMost(value, maximum) {
|
|
76
|
+
return typeof value === 'string' && new TextEncoder().encode(value).byteLength <= maximum;
|
|
77
|
+
}
|
|
78
|
+
function isQueryLogRecord(value) {
|
|
79
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
80
|
+
return false;
|
|
81
|
+
const record = value;
|
|
82
|
+
return hasExactKeys(record, QUERY_LOG_RECORD_KEYS)
|
|
83
|
+
&& record.schema_version === '1'
|
|
84
|
+
&& typeof record.source_id === 'string' && /^lsrc_[0-9a-f]{32}$/.test(record.source_id)
|
|
85
|
+
&& typeof record.event_id === 'string' && /^[0-9a-f]{64}$/.test(record.event_id)
|
|
86
|
+
&& isCanonicalArchiveSeq(record.archive_seq)
|
|
87
|
+
&& isContractDateTime(record.event_time)
|
|
88
|
+
&& typeof record.event_time_unix_nano === 'string' && /^(0|[1-9][0-9]{0,19})$/.test(record.event_time_unix_nano)
|
|
89
|
+
&& typeof record.pod_uid === 'string' && record.pod_uid.length > 0
|
|
90
|
+
&& typeof record.pod_name === 'string' && record.pod_name.length > 0
|
|
91
|
+
&& record.container === 'user-container'
|
|
92
|
+
&& Number.isInteger(record.restart_count) && record.restart_count >= 0 && record.restart_count <= 4_294_967_295
|
|
93
|
+
&& (record.stream === 'stdout' || record.stream === 'stderr')
|
|
94
|
+
&& Number.isInteger(record.occurrence) && record.occurrence >= 0 && record.occurrence <= 4_294_967_295
|
|
95
|
+
&& (record.revision === null || typeof record.revision === 'string')
|
|
96
|
+
&& typeof record.severity === 'string' && LOG_SEVERITIES.has(record.severity)
|
|
97
|
+
&& utf8LengthAtMost(record.message, log_contract_1.QUERY_MESSAGE_MAX_BYTES)
|
|
98
|
+
&& typeof record.truncated === 'boolean'
|
|
99
|
+
&& Number.isInteger(record.original_bytes) && record.original_bytes >= 0 && record.original_bytes <= log_contract_1.LOG_MESSAGE_MAX_BYTES;
|
|
100
|
+
}
|
|
101
|
+
function isQueryBudget(value) {
|
|
102
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
103
|
+
return false;
|
|
104
|
+
const budget = value;
|
|
105
|
+
return hasExactKeys(budget, ['listed_objects', 'compressed_bytes', 'decompressed_bytes', 'elapsed_ms'])
|
|
106
|
+
&& ['listed_objects', 'compressed_bytes', 'decompressed_bytes', 'elapsed_ms']
|
|
107
|
+
.every((key) => Number.isInteger(budget[key]) && budget[key] >= 0);
|
|
108
|
+
}
|
|
109
|
+
function isRunLogQueryResponse(value) {
|
|
110
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
111
|
+
return false;
|
|
112
|
+
const response = value;
|
|
113
|
+
return hasExactKeys(response, ['records', 'exclusive_watermark', 'resume_key', 'truncated', 'budget'])
|
|
114
|
+
&& Array.isArray(response.records) && response.records.every(isQueryLogRecord)
|
|
115
|
+
&& (response.exclusive_watermark === null || isOpaqueWatermark(response.exclusive_watermark))
|
|
116
|
+
&& (response.resume_key === null || isOpaqueWatermark(response.resume_key))
|
|
117
|
+
&& typeof response.truncated === 'boolean'
|
|
118
|
+
&& isQueryBudget(response.budget);
|
|
119
|
+
}
|
|
120
|
+
function parseFollowWireFrame(line) {
|
|
121
|
+
let parsed;
|
|
122
|
+
try {
|
|
123
|
+
parsed = JSON.parse(line);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw new Error('follow returned malformed NDJSON');
|
|
127
|
+
}
|
|
128
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
129
|
+
throw new Error('follow frame was not an object');
|
|
130
|
+
const frame = parsed;
|
|
131
|
+
if (typeof frame.type !== 'string' || !LOG_FOLLOW_FRAME_TYPES.has(frame.type))
|
|
132
|
+
throw new Error('follow returned an unknown frame type');
|
|
133
|
+
if (typeof frame.request_id !== 'string' || frame.request_id.length < 1 || frame.request_id.length > 128)
|
|
134
|
+
throw new Error('follow frame had an invalid request_id');
|
|
135
|
+
switch (frame.type) {
|
|
136
|
+
case 'state':
|
|
137
|
+
if (!hasExactKeys(frame, ['type', 'request_id', 'state']) || typeof frame.state !== 'string' || !LOG_FOLLOW_STATES.has(frame.state))
|
|
138
|
+
throw new Error('follow returned an invalid state frame');
|
|
139
|
+
break;
|
|
140
|
+
case 'record':
|
|
141
|
+
if (!hasExactKeys(frame, ['type', 'request_id', 'record']) || !isQueryLogRecord(frame.record))
|
|
142
|
+
throw new Error('follow returned an invalid record frame');
|
|
143
|
+
break;
|
|
144
|
+
case 'watermark':
|
|
145
|
+
if (!hasExactKeys(frame, ['type', 'request_id', 'watermark']) || !isOpaqueWatermark(frame.watermark))
|
|
146
|
+
throw new Error('follow returned an invalid watermark frame');
|
|
147
|
+
break;
|
|
148
|
+
case 'heartbeat':
|
|
149
|
+
if (!hasExactKeys(frame, ['type', 'request_id', 'server_time']) || typeof frame.server_time !== 'string' || Number.isNaN(Date.parse(frame.server_time)))
|
|
150
|
+
throw new Error('follow returned an invalid heartbeat frame');
|
|
151
|
+
break;
|
|
152
|
+
case 'error':
|
|
153
|
+
if (!hasExactKeys(frame, ['type', 'request_id', 'watermark', 'error_code', 'retryable', 'message'])
|
|
154
|
+
|| (frame.watermark !== null && !isOpaqueWatermark(frame.watermark))
|
|
155
|
+
|| typeof frame.error_code !== 'string' || !LOG_FOLLOW_ERROR_CODES.has(frame.error_code)
|
|
156
|
+
|| typeof frame.retryable !== 'boolean' || typeof frame.message !== 'string' || frame.message.length > 512) {
|
|
157
|
+
throw new Error('follow returned an invalid error frame');
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 'end':
|
|
161
|
+
if (!hasExactKeys(frame, ['type', 'request_id', 'watermark', 'retryable'])
|
|
162
|
+
|| (frame.watermark !== null && !isOpaqueWatermark(frame.watermark)) || typeof frame.retryable !== 'boolean') {
|
|
163
|
+
throw new Error('follow returned an invalid end frame');
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
return frame;
|
|
168
|
+
}
|
|
169
|
+
function isNdjson(contentType) {
|
|
170
|
+
return contentType.split(';', 1)[0].trim().toLowerCase() === 'application/x-ndjson';
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 🔴 503 codes that mean "our side is unavailable, retry later", NOT "your
|
|
174
|
+
* request is wrong". They must reach the agent as INFRA_ERROR (exit 5), which is
|
|
175
|
+
* the retryable bucket — collapsing them into a business error (exit 2) tells a
|
|
176
|
+
* caller a transient outage is permanent.
|
|
177
|
+
*/
|
|
178
|
+
const RUN_INFRA_CODES = new Set([
|
|
179
|
+
'RUN_SRUN_UNAVAILABLE',
|
|
180
|
+
'RUN_DISABLED',
|
|
181
|
+
'RUN_SECRETS_UNAVAILABLE',
|
|
182
|
+
'DB_MODULE_DISABLED',
|
|
183
|
+
'RUN_DB_CREDENTIAL_UNAVAILABLE',
|
|
184
|
+
'RUN_DB_DELIVERY_FAILED',
|
|
185
|
+
'RUN_DB_DELIVERY_PENDING',
|
|
186
|
+
]);
|
|
187
|
+
/** In-flight duplicate of the same idempotency key — transient, back off and retry. */
|
|
188
|
+
exports.IDEMPOTENCY_PENDING = 'IDEMPOTENCY_PENDING';
|
|
189
|
+
function classifyRunResponse(snapshot) {
|
|
190
|
+
const outcome = (0, responseClassifier_1.classifySiteResponse)(snapshot);
|
|
191
|
+
if (outcome.kind === 'business_error' && RUN_INFRA_CODES.has(outcome.code)) {
|
|
192
|
+
return { kind: 'infra_error', status: snapshot.status, message: `${outcome.code}: ${outcome.message}` };
|
|
193
|
+
}
|
|
194
|
+
return outcome;
|
|
195
|
+
}
|
|
196
|
+
async function toSnapshot(res) {
|
|
197
|
+
const redirected = res.type === 'opaqueredirect' || (res.status >= 300 && res.status < 400);
|
|
198
|
+
if (redirected)
|
|
199
|
+
return { status: res.status, redirected: true };
|
|
200
|
+
let text;
|
|
201
|
+
try {
|
|
202
|
+
text = await res.text();
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
return { status: res.status, bodyError: `failed to read response body: ${err.message}` };
|
|
206
|
+
}
|
|
207
|
+
let body = null;
|
|
208
|
+
if (text.length > 0) {
|
|
209
|
+
try {
|
|
210
|
+
body = JSON.parse(text);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return { status: res.status, bodyError: 'response was not valid JSON' };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { status: res.status, body };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* 🔴 The redeploy route, pinned by the CA-side contract for IND-1 and kept in ONE
|
|
220
|
+
* place so a path change is a one-line diff plus one test string.
|
|
221
|
+
*
|
|
222
|
+
* 🔴 This path is a CROSS-SERVICE CONTRACT, and it already drifted once: the redeploy
|
|
223
|
+
* route was handed over with an extra `/run/` segment that no CA route actually has.
|
|
224
|
+
* CA implemented it under the family's real prefix (`/projects/{spid}/services/...`),
|
|
225
|
+
* the CLI wrote the handed-over string verbatim, and BOTH sides' tests were green
|
|
226
|
+
* while the CLI would have 404'd in production.
|
|
227
|
+
*
|
|
228
|
+
* So it is no longer pinned by a second literal: `builds a path that CA actually serves`
|
|
229
|
+
* in `test/unit/commands/deploy.test.ts` reads CA's own route table and asserts the
|
|
230
|
+
* template this function produces is really served. Do not "fix" a failure there by
|
|
231
|
+
* copying the new literal over — fix whichever side moved.
|
|
232
|
+
*/
|
|
233
|
+
function runServiceDeployPath(spid, slug, env) {
|
|
234
|
+
return (`/api/console/projects/${encodeURIComponent(spid)}/services/${encodeURIComponent(slug)}` +
|
|
235
|
+
`/envs/${encodeURIComponent(env)}/deploy`);
|
|
236
|
+
}
|
|
237
|
+
class RunClient {
|
|
238
|
+
apiOrigin;
|
|
239
|
+
fetchImpl;
|
|
240
|
+
constructor(apiOrigin, fetchImpl) {
|
|
241
|
+
this.apiOrigin = apiOrigin;
|
|
242
|
+
this.fetchImpl = fetchImpl ?? globalThis.fetch;
|
|
243
|
+
}
|
|
244
|
+
async send(ctx, method, path, opts = {}) {
|
|
245
|
+
if (!this.fetchImpl) {
|
|
246
|
+
return { kind: 'infra_error', message: 'no fetch implementation available (requires Node >=18)' };
|
|
247
|
+
}
|
|
248
|
+
const controller = new AbortController();
|
|
249
|
+
// Creating a service polls the cluster for readiness in the foreground, so
|
|
250
|
+
// the budget here is generous relative to the site path's 60s.
|
|
251
|
+
const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 180_000);
|
|
252
|
+
let res;
|
|
253
|
+
try {
|
|
254
|
+
res = await this.fetchImpl(`${this.apiOrigin}${path}`, {
|
|
255
|
+
method,
|
|
256
|
+
headers: {
|
|
257
|
+
accept: 'application/json',
|
|
258
|
+
authorization: `Bearer ${ctx.accessToken}`,
|
|
259
|
+
'x-org-id': ctx.orgId,
|
|
260
|
+
...(opts.jsonBody !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
261
|
+
...(opts.extraHeaders ?? {}),
|
|
262
|
+
},
|
|
263
|
+
body: opts.jsonBody !== undefined ? JSON.stringify(opts.jsonBody) : undefined,
|
|
264
|
+
redirect: 'manual',
|
|
265
|
+
signal: controller.signal,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
return { kind: 'infra_error', message: `network error: ${err.message}` };
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
clearTimeout(timer);
|
|
273
|
+
}
|
|
274
|
+
return classifyRunResponse(await toSnapshot(res));
|
|
275
|
+
}
|
|
276
|
+
createService(ctx, spid, input, idempotencyKey) {
|
|
277
|
+
return this.send(ctx, 'POST', `/api/console/projects/${encodeURIComponent(spid)}/services`, {
|
|
278
|
+
jsonBody: input,
|
|
279
|
+
...(idempotencyKey ? { extraHeaders: { 'x-idempotency-key': idempotencyKey } } : {}),
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
deployService(ctx, spid, slug, env, input, idempotencyKey) {
|
|
283
|
+
return this.send(ctx, 'POST', runServiceDeployPath(spid, slug, env), {
|
|
284
|
+
jsonBody: input,
|
|
285
|
+
...(idempotencyKey ? { extraHeaders: { 'x-idempotency-key': idempotencyKey } } : {}),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
getService(ctx, spid, slug, env) {
|
|
289
|
+
return this.send(ctx, 'GET', `/api/console/projects/${encodeURIComponent(spid)}/services/${encodeURIComponent(slug)}?env=${encodeURIComponent(env)}`, { timeoutMs: 30_000 });
|
|
290
|
+
}
|
|
291
|
+
logs(ctx, spid, slug, env, tail) {
|
|
292
|
+
return this.send(ctx, 'GET', `/api/console/projects/${encodeURIComponent(spid)}/services/${encodeURIComponent(slug)}` +
|
|
293
|
+
`/envs/${encodeURIComponent(env)}/logs?tail=${encodeURIComponent(String(tail))}`, { timeoutMs: 30_000 });
|
|
294
|
+
}
|
|
295
|
+
async queryLogs(ctx, spid, slug, env, input) {
|
|
296
|
+
const outcome = await this.send(ctx, 'POST', `/api/console/projects/${encodeURIComponent(spid)}/services/${encodeURIComponent(slug)}/envs/${encodeURIComponent(env)}/logs/query`, {
|
|
297
|
+
jsonBody: input, timeoutMs: 35_000,
|
|
298
|
+
});
|
|
299
|
+
if (outcome.kind !== 'success')
|
|
300
|
+
return outcome;
|
|
301
|
+
if (!isRunLogQueryResponse(outcome.data)) {
|
|
302
|
+
return { kind: 'infra_error', code: 'LOG_QUERY_INVALID_RESPONSE', message: 'logs query returned a response outside the canonical contract' };
|
|
303
|
+
}
|
|
304
|
+
return { kind: 'success', data: outcome.data };
|
|
305
|
+
}
|
|
306
|
+
async followLogs(ctx, spid, slug, env, input, onLine) {
|
|
307
|
+
if (!this.fetchImpl)
|
|
308
|
+
return { kind: 'infra_error', message: 'no fetch implementation available (requires Node >=18)' };
|
|
309
|
+
const controller = new AbortController();
|
|
310
|
+
// Distinct clocks: connect ≤5s, each received chunk resets the 45s idle timer,
|
|
311
|
+
// and a 30m session ends normally at the consumer layer with a new watermark.
|
|
312
|
+
let idleTimer;
|
|
313
|
+
const connectTimer = setTimeout(() => controller.abort(), 5_000);
|
|
314
|
+
// SRUN owns the canonical 30m end frame. This is only a transport safety margin so a timer
|
|
315
|
+
// race cannot turn that normal end into a local AbortError.
|
|
316
|
+
const sessionTimer = setTimeout(() => controller.abort(), 30 * 60_000 + 5_000);
|
|
317
|
+
const resetIdle = () => { if (idleTimer)
|
|
318
|
+
clearTimeout(idleTimer); idleTimer = setTimeout(() => controller.abort(), 45_000); };
|
|
319
|
+
const cancel = () => controller.abort();
|
|
320
|
+
process.once('SIGINT', cancel);
|
|
321
|
+
let response;
|
|
322
|
+
try {
|
|
323
|
+
response = await this.fetchImpl(`${this.apiOrigin}/api/console/projects/${encodeURIComponent(spid)}/services/${encodeURIComponent(slug)}/envs/${encodeURIComponent(env)}/logs/follow`, {
|
|
324
|
+
method: 'POST', headers: { accept: 'application/x-ndjson', 'content-type': 'application/json', authorization: `Bearer ${ctx.accessToken}`, 'x-org-id': ctx.orgId }, body: JSON.stringify(input), redirect: 'manual', signal: controller.signal,
|
|
325
|
+
});
|
|
326
|
+
clearTimeout(connectTimer);
|
|
327
|
+
if (!response.ok || !isNdjson(response.headers.get('content-type') ?? ''))
|
|
328
|
+
return classifyRunResponse(await toSnapshot(response));
|
|
329
|
+
if (!response.body)
|
|
330
|
+
return { kind: 'infra_error', message: 'follow response had no readable body' };
|
|
331
|
+
const reader = response.body.getReader();
|
|
332
|
+
const decoder = new TextDecoder();
|
|
333
|
+
let pending = '';
|
|
334
|
+
let sawEnd = false;
|
|
335
|
+
let sawError = false;
|
|
336
|
+
let frameCount = 0;
|
|
337
|
+
let requestId;
|
|
338
|
+
let streamError;
|
|
339
|
+
const emitLine = (line) => {
|
|
340
|
+
let frame;
|
|
341
|
+
try {
|
|
342
|
+
frame = parseFollowWireFrame(line);
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
streamError = { code: 'LOG_FOLLOW_INVALID_FRAME', message: error.message, retryable: true };
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (sawEnd) {
|
|
349
|
+
streamError = { code: 'LOG_FOLLOW_AFTER_END', message: 'follow returned data after its terminal frame', retryable: true };
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
if (frameCount === 0 && frame.type !== 'state') {
|
|
353
|
+
streamError = { code: 'LOG_FOLLOW_FIRST_FRAME_NOT_STATE', message: 'follow stream did not begin with a state frame', retryable: true };
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
if (requestId !== undefined && frame.request_id !== requestId) {
|
|
357
|
+
streamError = { code: 'LOG_FOLLOW_REQUEST_ID_CHANGED', message: 'follow stream changed request_id mid-stream', retryable: true };
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
if (sawError && frame.type !== 'end') {
|
|
361
|
+
streamError = { code: 'LOG_FOLLOW_AFTER_ERROR', message: 'follow returned data after an error before its terminal frame', retryable: true };
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
requestId ??= frame.request_id;
|
|
365
|
+
frameCount += 1;
|
|
366
|
+
if (frame.type === 'end')
|
|
367
|
+
sawEnd = true;
|
|
368
|
+
if (frame.type === 'error') {
|
|
369
|
+
sawError = true;
|
|
370
|
+
const code = frame.error_code;
|
|
371
|
+
streamError = {
|
|
372
|
+
code,
|
|
373
|
+
message: frame.message,
|
|
374
|
+
retryable: frame.retryable === true,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
onLine(line);
|
|
378
|
+
return true;
|
|
379
|
+
};
|
|
380
|
+
resetIdle();
|
|
381
|
+
for (;;) {
|
|
382
|
+
const { done, value } = await reader.read();
|
|
383
|
+
if (value)
|
|
384
|
+
resetIdle();
|
|
385
|
+
pending += decoder.decode(value, { stream: !done });
|
|
386
|
+
if (pending.length > MAX_LOG_FOLLOW_FRAME_CHARS && !pending.includes('\n'))
|
|
387
|
+
return { kind: 'infra_error', code: 'LOG_FOLLOW_FRAME_TOO_LARGE', message: 'follow frame exceeded the client safety bound' };
|
|
388
|
+
const lines = pending.split('\n');
|
|
389
|
+
pending = lines.pop() ?? '';
|
|
390
|
+
for (const line of lines)
|
|
391
|
+
if (line.trim() && !emitLine(line))
|
|
392
|
+
return { kind: 'infra_error', code: streamError?.code, message: streamError?.message ?? 'follow returned malformed NDJSON' };
|
|
393
|
+
if (done)
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
if (pending.trim() && !emitLine(pending))
|
|
397
|
+
return { kind: 'infra_error', code: streamError?.code, message: streamError?.message ?? 'follow returned malformed NDJSON' };
|
|
398
|
+
if (streamError) {
|
|
399
|
+
if (streamError.retryable)
|
|
400
|
+
return { kind: 'infra_error', code: streamError.code, message: streamError.message };
|
|
401
|
+
return { kind: 'business_error', code: streamError.code, message: streamError.message, retryable: false };
|
|
402
|
+
}
|
|
403
|
+
if (!sawEnd)
|
|
404
|
+
return { kind: 'infra_error', code: 'LOG_FOLLOW_EOF_BEFORE_END', message: 'log follow ended without a terminal frame' };
|
|
405
|
+
return { kind: 'success', data: { completed: true } };
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
return { kind: 'infra_error', message: `network error: ${error.message}` };
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
process.removeListener('SIGINT', cancel);
|
|
412
|
+
clearTimeout(connectTimer);
|
|
413
|
+
clearTimeout(sessionTimer);
|
|
414
|
+
if (idleTimer)
|
|
415
|
+
clearTimeout(idleTimer);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
exports.RunClient = RunClient;
|
|
420
|
+
/**
|
|
421
|
+
* Container-specific rendering of a business error code. Kept next to the client
|
|
422
|
+
* (not in the command) so it is unit-testable against the exact backend codes
|
|
423
|
+
* from `services/super-console-main/src/shared/error_codes.rs`.
|
|
424
|
+
*/
|
|
425
|
+
function describeRunError(code, message) {
|
|
426
|
+
switch (code) {
|
|
427
|
+
case 'SITE_SLUG_INVALID':
|
|
428
|
+
return `${message} — slug must be 1-32 lowercase letters or digits; fix --slug`;
|
|
429
|
+
case 'SITE_SLUG_RESERVED':
|
|
430
|
+
return `${message} — that slug is reserved; pick another --slug`;
|
|
431
|
+
// 🔴 IND-1: this is NOT "you already deployed once". A second `deploy` of the same
|
|
432
|
+
// (slug, env) is a redeploy and takes the redeploy route — so by the time this
|
|
433
|
+
// message is rendered, `runDeploy` has already confirmed no service of that name
|
|
434
|
+
// exists in THIS environment. What is left is a genuine name collision: the pool
|
|
435
|
+
// is per project and shared across kinds AND environments.
|
|
436
|
+
case 'SITE_SLUG_DUPLICATE':
|
|
437
|
+
return (`${message} — that name is already taken in this project by another deploy unit (a static site, or a ` +
|
|
438
|
+
'container service in a different --env): the name pool is per project, shared across both. Pick another ' +
|
|
439
|
+
'--slug, or delete the existing unit in the Console');
|
|
440
|
+
case 'RUN_LIFECYCLE_STATE_INVALID':
|
|
441
|
+
return `${message} — the service is not in a state that accepts this change (disable needs it \`active\`, enable needs it \`disabled\`)`;
|
|
442
|
+
// 🔴 Deliberately distinct from RUN_ROLLBACK_STATE_INVALID on the CA side: being told a
|
|
443
|
+
// *rollback* state is wrong when you ran `deploy` sends you looking for a rollback you
|
|
444
|
+
// never started. The two refusals below are also distinct from each other on purpose —
|
|
445
|
+
// one says wait, the other says the service is switched off.
|
|
446
|
+
case 'RUN_DEPLOY_STATE_INVALID':
|
|
447
|
+
return (`${message} — a redeploy is refused while a previous one is still \`provisioning\` (wait for it to ` +
|
|
448
|
+
'settle and retry), and a disabled service must be enabled first — deploying to it would leave you ' +
|
|
449
|
+
'with a rollout that still answers 410');
|
|
450
|
+
case 'RUN_CONCURRENT_DEPLOY_LIMIT':
|
|
451
|
+
return `${message} — too many services in this project are converging at once; this is transient, retry shortly`;
|
|
452
|
+
case 'RUN_QUOTA_EXCEEDED':
|
|
453
|
+
return `${message} — the container service quota for this project is used up; delete an unused service or raise it in the Console`;
|
|
454
|
+
case 'RUN_IMAGE_INVALID':
|
|
455
|
+
return `${message} — pass a digest-pinned image (\`--image repo/name@sha256:…\`), or let \`deploy\` build one`;
|
|
456
|
+
case 'RUN_SPEC_INVALID':
|
|
457
|
+
return `${message} — check --port / --cpu / --memory / --max-scale against the platform limits`;
|
|
458
|
+
case 'RUN_ENV_VAR_INVALID':
|
|
459
|
+
return `${message} — env var names must match ^[A-Z_][A-Z0-9_]{0,127}$`;
|
|
460
|
+
case 'RUN_ENV_VAR_SECRET_DOWNGRADE':
|
|
461
|
+
return `${message} — a key that was deployed with --secret cannot come back as a plaintext --env-var`;
|
|
462
|
+
// The server keeps an untouched secret when it receives the mask back (or the value omitted).
|
|
463
|
+
// That only works for a key that already exists AND is already a secret — otherwise it would be
|
|
464
|
+
// storing the literal `********` as somebody's real value.
|
|
465
|
+
case 'RUN_ENV_VAR_VALUE_INVALID':
|
|
466
|
+
return `${message} — a masked value only means "keep what is already stored", so it needs an existing secret of that name; pass the real value with --secret KEY=VALUE`;
|
|
467
|
+
case 'RUN_DB_CONNECTION_NOT_FOUND':
|
|
468
|
+
return `${message} — check --database-connection or --conn: that named database connection does not exist in this project environment`;
|
|
469
|
+
case 'RUN_DB_ENV_CONFLICT':
|
|
470
|
+
return `${message} — the target service already defines environment keys reserved for injected database credentials; remove or rename those conflicting vars first`;
|
|
471
|
+
case 'DB_CONNECTION_IN_USE':
|
|
472
|
+
return `${message} — this database connection is still referenced by one or more services; unbind or refresh those services before deleting or changing it`;
|
|
473
|
+
case 'RUN_DB_REFRESH_NOT_ALLOWED':
|
|
474
|
+
return `${message} — the current binding state does not require a refresh; re-check the service status before retrying`;
|
|
475
|
+
case 'DB_MODULE_DISABLED':
|
|
476
|
+
return `${message} — database binding is disabled for this Console deployment`;
|
|
477
|
+
case 'RUN_DB_CREDENTIAL_UNAVAILABLE':
|
|
478
|
+
return `${message} — database credentials are temporarily unavailable; retry later`;
|
|
479
|
+
case 'RUN_DB_DELIVERY_FAILED':
|
|
480
|
+
return `${message} — the database credential delivery step failed inside the runtime; retry later`;
|
|
481
|
+
case 'RUN_DB_DELIVERY_PENDING':
|
|
482
|
+
return `${message} — the runtime is still applying the database credential update; retry later`;
|
|
483
|
+
case 'RUN_REVISION_NOT_ROLLBACKABLE':
|
|
484
|
+
return `${message} — that revision never came up, so rolling back to it would redeploy a version already known to fail; pick one that reached active`;
|
|
485
|
+
case exports.IDEMPOTENCY_PENDING:
|
|
486
|
+
return `${message} — the first request with this --idempotency-key is still running; retry the SAME command shortly (it will return that deploy, not a second one)`;
|
|
487
|
+
case 'STALE_RUN_GENERATION':
|
|
488
|
+
return `${message} — the service was deleted and recreated; re-query it before deploying again`;
|
|
489
|
+
case 'NOT_FOUND':
|
|
490
|
+
return `${message} — check --spid and --env (an unknown project, environment or service all fold into this one answer)`;
|
|
491
|
+
default:
|
|
492
|
+
return message;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
//# sourceMappingURL=runClient.js.map
|