gencow 0.1.282 → 0.1.284
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/bin/gencow.mjs +1 -2
- package/core/index.js +3 -0
- package/lib/deploy-prod-target.mjs +7 -1
- package/lib/env-command.mjs +50 -4
- package/lib/prod-create-auth-diagnostic.mjs +87 -0
- package/lib/prod-create-failure.mjs +3 -0
- package/lib/static-command.mjs +7 -1
- package/package.json +3 -3
- package/runtime/server.mjs +117 -102
- package/runtime/tooling.mjs +3 -0
package/bin/gencow.mjs
CHANGED
|
@@ -466,8 +466,7 @@ ${BOLD}App management:${RESET}
|
|
|
466
466
|
${GREEN}app list${RESET} List your apps
|
|
467
467
|
${GREEN}app create${RESET} Create a new app
|
|
468
468
|
${GREEN}app delete${RESET} Delete an app ${DIM}(confirmation required)${RESET}
|
|
469
|
-
${GREEN}app status${RESET}
|
|
470
|
-
${GREEN}app stop|resume|wake${RESET} Control the app runtime ${DIM}(stop asks to confirm on prod)${RESET}
|
|
469
|
+
${GREEN}app status|stop|resume|wake${RESET} Show status / control runtime ${DIM}(stop asks to confirm on prod)${RESET}
|
|
471
470
|
|
|
472
471
|
${BOLD}Ops (Observability):${RESET}
|
|
473
472
|
${GREEN}logs${RESET} Show local dev server logs ${DIM}(--lines N, --follow)${RESET}
|
package/core/index.js
CHANGED
|
@@ -4126,6 +4126,9 @@ var RESERVED_TENANT_RUNTIME_ENV_KEYS = [
|
|
|
4126
4126
|
"GENCOW_MEMORY_MB",
|
|
4127
4127
|
"BUN_JSC_forceRAMSize",
|
|
4128
4128
|
"MIMALLOC_PURGE_DELAY",
|
|
4129
|
+
"BUN_JSC_numberOfGCMarkers",
|
|
4130
|
+
"BUN_JSC_numberOfDFGCompilerThreads",
|
|
4131
|
+
"BUN_JSC_numberOfFTLCompilerThreads",
|
|
4129
4132
|
"NODE_PATH"
|
|
4130
4133
|
];
|
|
4131
4134
|
var RESERVED_TENANT_RUNTIME_ENV_KEY_SET = new Set(RESERVED_TENANT_RUNTIME_ENV_KEYS);
|
|
@@ -6,6 +6,7 @@ import { prodRetryCommandLine, reconcileProductionAppTarget } from "./deploy-app
|
|
|
6
6
|
import { readJsonObjectResponse } from "./http-response-json.mjs";
|
|
7
7
|
import { BOLD, DIM, GREEN, RED, RESET, error, info, log, success } from "./output.mjs";
|
|
8
8
|
import { prodCreateFailureMessage } from "./prod-create-failure.mjs";
|
|
9
|
+
import { credentialEnvNameOf } from "./prod-create-auth-diagnostic.mjs";
|
|
9
10
|
|
|
10
11
|
export async function ensureProductionDeployTarget({
|
|
11
12
|
appId,
|
|
@@ -110,7 +111,12 @@ export async function ensureProductionDeployTarget({
|
|
|
110
111
|
logImpl(` ${GREEN}gencow upgrade${RESET} ${DIM}← Upgrade to Startup${RESET}`);
|
|
111
112
|
logImpl("");
|
|
112
113
|
} else {
|
|
113
|
-
errorImpl(
|
|
114
|
+
errorImpl(
|
|
115
|
+
prodCreateFailureMessage(errData, createProdRes, {
|
|
116
|
+
requestedRegion: region,
|
|
117
|
+
credentialEnvName: credentialEnvNameOf(creds),
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
114
120
|
}
|
|
115
121
|
exitImpl(1);
|
|
116
122
|
return null;
|
package/lib/env-command.mjs
CHANGED
|
@@ -9,9 +9,12 @@ import {
|
|
|
9
9
|
import { resolveCloudAppTargetWithServerEnvironment } from "./cloud-target-environment.mjs";
|
|
10
10
|
import { cloudTargetRejectionMessage, prodRetryCommandLine, redactConfigSetValue, redactEnvPairs } from "./deploy-app-target.mjs";
|
|
11
11
|
import { BOLD, CYAN, DIM, GREEN, RESET, error, info, log, success, warn } from "./output.mjs";
|
|
12
|
+
import { renderLifecycleFailure } from "./app-lifecycle-format.mjs";
|
|
12
13
|
import { platformFetch, requireCreds, rpcQuery } from "./platform-client.mjs";
|
|
13
14
|
|
|
14
15
|
const ENV_RESPONSE_UNREADABLE_CODE = "ENV_RESPONSE_UNREADABLE";
|
|
16
|
+
const ENV_APP_NOT_FOUND_REASON = "App not found";
|
|
17
|
+
const ENV_APP_NOT_FOUND_CODE = "APP_NOT_FOUND";
|
|
15
18
|
|
|
16
19
|
// Reads a failed platform response. A JSON `null`, an empty body, or a non-object body
|
|
17
20
|
// normalizes to `message: null`, so callers never dereference the parsed value.
|
|
@@ -19,7 +22,24 @@ async function readEnvErrorResponse(response) {
|
|
|
19
22
|
const parsed = await response.json().catch(() => null);
|
|
20
23
|
const body = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
21
24
|
const message = typeof body?.error === "string" && body.error.trim() ? body.error.trim() : null;
|
|
22
|
-
|
|
25
|
+
const code = typeof body?.code === "string" ? body.code : null;
|
|
26
|
+
return { ...envResponseFacts(response), message, code };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The Platform's typed missing-app answer is code APP_NOT_FOUND. Servers that predate the code answer
|
|
30
|
+
// 404 with the text "App not found", so that text is used only when no code is present.
|
|
31
|
+
function isEnvAppNotFound(failure) {
|
|
32
|
+
if (failure.status !== 404) return false;
|
|
33
|
+
if (typeof failure.code === "string") return failure.code === ENV_APP_NOT_FOUND_CODE;
|
|
34
|
+
return failure.message === ENV_APP_NOT_FOUND_REASON;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Shared typed rendering (same catalog as app status); the stage and correlation are the only per-call facts.
|
|
38
|
+
function envAppNotFoundOutput(failure, appId, stage) {
|
|
39
|
+
return renderLifecycleFailure("APP_NOT_FOUND", {
|
|
40
|
+
name: appId,
|
|
41
|
+
extra: [`Stage: ${stage}`, `Correlation: ${failure.correlationId ?? "none returned"}`],
|
|
42
|
+
});
|
|
23
43
|
}
|
|
24
44
|
|
|
25
45
|
function envResponseFacts(response) {
|
|
@@ -331,6 +351,15 @@ export function createEnvCommand(deps = {}) {
|
|
|
331
351
|
// A `null` or non-object error body must not turn into a TypeError that hides the HTTP status.
|
|
332
352
|
const body = await res.json().catch(() => null);
|
|
333
353
|
const reason = typeof body?.error === "string" && body.error ? body.error : null;
|
|
354
|
+
const failure = {
|
|
355
|
+
...envResponseFacts(res),
|
|
356
|
+
message: reason,
|
|
357
|
+
code: typeof body?.code === "string" ? body.code : null,
|
|
358
|
+
};
|
|
359
|
+
if (isEnvAppNotFound(failure)) {
|
|
360
|
+
error(envAppNotFoundOutput(failure, appId, "env_list"));
|
|
361
|
+
return 1;
|
|
362
|
+
}
|
|
334
363
|
throw new Error(reason ?? `HTTP ${res.status}`);
|
|
335
364
|
}
|
|
336
365
|
const vars = await res.json().catch(() => null);
|
|
@@ -421,8 +450,14 @@ export function createEnvCommand(deps = {}) {
|
|
|
421
450
|
body: JSON.stringify({ key: name, value, env: envTarget }),
|
|
422
451
|
});
|
|
423
452
|
if (!res.ok) {
|
|
453
|
+
const failure = await readEnvErrorResponse(res);
|
|
454
|
+
if (isEnvAppNotFound(failure)) {
|
|
455
|
+
error(envAppNotFoundOutput(failure, appId, "env_set"));
|
|
456
|
+
commandFailed = true;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
424
459
|
throw new Error(
|
|
425
|
-
formatEnvErrorMessage(
|
|
460
|
+
formatEnvErrorMessage(failure, {
|
|
426
461
|
stage: "env_set",
|
|
427
462
|
checkCommand: envListCommand(appId, envTarget),
|
|
428
463
|
}),
|
|
@@ -476,8 +511,14 @@ export function createEnvCommand(deps = {}) {
|
|
|
476
511
|
},
|
|
477
512
|
);
|
|
478
513
|
if (!res.ok) {
|
|
514
|
+
const failure = await readEnvErrorResponse(res);
|
|
515
|
+
if (isEnvAppNotFound(failure)) {
|
|
516
|
+
error(envAppNotFoundOutput(failure, appId, "env_unset"));
|
|
517
|
+
commandFailed = true;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
479
520
|
throw new Error(
|
|
480
|
-
formatEnvErrorMessage(
|
|
521
|
+
formatEnvErrorMessage(failure, {
|
|
481
522
|
stage: "env_unset",
|
|
482
523
|
checkCommand: envListCommand(appId, envTarget),
|
|
483
524
|
}),
|
|
@@ -572,8 +613,13 @@ export function createEnvCommand(deps = {}) {
|
|
|
572
613
|
body: JSON.stringify({ vars, env: envTarget }),
|
|
573
614
|
});
|
|
574
615
|
if (!res.ok) {
|
|
616
|
+
const failure = await readEnvErrorResponse(res);
|
|
617
|
+
if (isEnvAppNotFound(failure)) {
|
|
618
|
+
error(envAppNotFoundOutput(failure, appId, "env_push"));
|
|
619
|
+
return 1;
|
|
620
|
+
}
|
|
575
621
|
throw new Error(
|
|
576
|
-
formatEnvErrorMessage(
|
|
622
|
+
formatEnvErrorMessage(failure, {
|
|
577
623
|
stage: "env_push",
|
|
578
624
|
checkCommand: envListCommand(appId, envTarget),
|
|
579
625
|
}),
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { authCauseNextAction, safeAuthCauseCode } from "./release-auth-cause.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Renders the typed auth rejection from a create-prod response: 503 AUTH_LOOKUP_UNAVAILABLE
|
|
5
|
+
* (temporary lookup failure) or 401 with a credential code or an account lifecycle code.
|
|
6
|
+
* Every field is allow-listed. The message text comes from this file, never from the server body.
|
|
7
|
+
*/
|
|
8
|
+
const CREDENTIAL_REJECTED_CODE = "APP_CREATE_AUTH_REQUIRED";
|
|
9
|
+
const LOOKUP_UNAVAILABLE_CODE = "AUTH_LOOKUP_UNAVAILABLE";
|
|
10
|
+
const ACCOUNT_MESSAGES = new Map([
|
|
11
|
+
["ACCOUNT_DELETED", "This account has been deleted."],
|
|
12
|
+
["ACCOUNT_DELETION_PENDING", "This account is pending deletion."],
|
|
13
|
+
["ACCOUNT_SUSPENDED", "This account is suspended."],
|
|
14
|
+
]);
|
|
15
|
+
const CORRELATION_ID_PATTERN = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
16
|
+
const ACCOUNT_NEXT_ACTION =
|
|
17
|
+
"running `gencow login` or `gencow whoami` does not change the account state. Check the account status in the Gencow dashboard, then run the command again.";
|
|
18
|
+
|
|
19
|
+
export function readCreateProdAuthDiagnostic(body, response) {
|
|
20
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return null;
|
|
21
|
+
if (body.stage !== "auth") return null;
|
|
22
|
+
const correlationId =
|
|
23
|
+
typeof body.correlationId === "string" && CORRELATION_ID_PATTERN.test(body.correlationId)
|
|
24
|
+
? body.correlationId
|
|
25
|
+
: null;
|
|
26
|
+
|
|
27
|
+
if (response?.status === 503 && body.code === LOOKUP_UNAVAILABLE_CODE) {
|
|
28
|
+
return { kind: "unavailable", code: LOOKUP_UNAVAILABLE_CODE, correlationId };
|
|
29
|
+
}
|
|
30
|
+
if (response?.status !== 401) return null;
|
|
31
|
+
if (body.code === CREDENTIAL_REJECTED_CODE) {
|
|
32
|
+
return {
|
|
33
|
+
kind: "credential",
|
|
34
|
+
code: CREDENTIAL_REJECTED_CODE,
|
|
35
|
+
causeCode: safeAuthCauseCode(body.causeCode),
|
|
36
|
+
correlationId,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (ACCOUNT_MESSAGES.has(body.code)) {
|
|
40
|
+
return { kind: "account", code: body.code, correlationId };
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The env credential that overrides `gencow login`, or null. Same rule as the deploy target helpers.
|
|
46
|
+
export function credentialEnvNameOf(creds) {
|
|
47
|
+
return creds?.credentialSource === "environment" &&
|
|
48
|
+
(creds.credentialEnvName === "GENCOW_TOKEN" || creds.credentialEnvName === "GENCOW_DEPLOY_TOKEN")
|
|
49
|
+
? creds.credentialEnvName
|
|
50
|
+
: null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function formatCreateProdAuthMessage(diagnostic, credentialEnvName = null) {
|
|
54
|
+
const correlation = diagnostic.correlationId ?? "none returned";
|
|
55
|
+
if (diagnostic.kind === "unavailable") {
|
|
56
|
+
return [
|
|
57
|
+
"Prod app creation failed: Authentication lookup temporarily unavailable",
|
|
58
|
+
`Code: ${diagnostic.code}`,
|
|
59
|
+
"Stage: auth",
|
|
60
|
+
"Changed: nothing (no prod app was created)",
|
|
61
|
+
"Retryable: yes",
|
|
62
|
+
"Next: wait a short while, then run the same command again. If it keeps failing, send the Correlation ID.",
|
|
63
|
+
`Correlation ID: ${correlation}`,
|
|
64
|
+
].join("\n");
|
|
65
|
+
}
|
|
66
|
+
if (diagnostic.kind === "account") {
|
|
67
|
+
return [
|
|
68
|
+
`Prod app creation failed: ${ACCOUNT_MESSAGES.get(diagnostic.code)}`,
|
|
69
|
+
`Code: ${diagnostic.code}`,
|
|
70
|
+
"Stage: auth",
|
|
71
|
+
"Changed: nothing (no prod app was created)",
|
|
72
|
+
"Retryable: no",
|
|
73
|
+
`Next: ${ACCOUNT_NEXT_ACTION}`,
|
|
74
|
+
`Correlation ID: ${correlation}`,
|
|
75
|
+
].join("\n");
|
|
76
|
+
}
|
|
77
|
+
const lines = [
|
|
78
|
+
"Prod app creation failed: CLI authentication is required",
|
|
79
|
+
`Code: ${diagnostic.code}`,
|
|
80
|
+
"Stage: auth",
|
|
81
|
+
];
|
|
82
|
+
if (diagnostic.causeCode) lines.push(`Cause: ${diagnostic.causeCode}`);
|
|
83
|
+
lines.push("Changed: nothing (no prod app was created)", "Retryable: no");
|
|
84
|
+
lines.push(`Next: ${authCauseNextAction(credentialEnvName)}`);
|
|
85
|
+
lines.push(`Correlation ID: ${correlation}`);
|
|
86
|
+
return lines.join("\n");
|
|
87
|
+
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
formatRegionUnavailableMessage,
|
|
4
4
|
readRegionUnavailableDiagnostic,
|
|
5
5
|
} from "./prod-create-region-diagnostic.mjs";
|
|
6
|
+
import { formatCreateProdAuthMessage, readCreateProdAuthDiagnostic } from "./prod-create-auth-diagnostic.mjs";
|
|
6
7
|
|
|
7
8
|
/** One rendering of a failed `create-prod` response for every CLI deploy path. */
|
|
8
9
|
export function prodCreateFailureMessage(errData, response, options = {}) {
|
|
@@ -10,6 +11,8 @@ export function prodCreateFailureMessage(errData, response, options = {}) {
|
|
|
10
11
|
response.status === 503
|
|
11
12
|
? "Prod app creation is temporarily unavailable."
|
|
12
13
|
: errData?.error || response.statusText || `HTTP ${response.status}`;
|
|
14
|
+
const authDiagnostic = readCreateProdAuthDiagnostic(errData, response);
|
|
15
|
+
if (authDiagnostic) return formatCreateProdAuthMessage(authDiagnostic, options.credentialEnvName ?? null);
|
|
13
16
|
const regionDiagnostic = readRegionUnavailableDiagnostic(errData, response);
|
|
14
17
|
if (regionDiagnostic) {
|
|
15
18
|
return formatRegionUnavailableMessage(regionDiagnostic, fallback, options.requestedRegion ?? null);
|
package/lib/static-command.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import { BOLD, CYAN, DIM, RESET, error, info, log, success } from "./output.mjs";
|
|
19
19
|
import { platformFetch } from "./platform-client.mjs";
|
|
20
20
|
import { prodCreateFailureMessage } from "./prod-create-failure.mjs";
|
|
21
|
+
import { credentialEnvNameOf } from "./prod-create-auth-diagnostic.mjs";
|
|
21
22
|
import { readJsonObjectResponse } from "./http-response-json.mjs";
|
|
22
23
|
import { detectStaticDeployBackend, preflightStaticDeployArtifact } from "./static-deploy-command.mjs";
|
|
23
24
|
|
|
@@ -138,7 +139,12 @@ async function ensureStaticProductionTarget({
|
|
|
138
139
|
|
|
139
140
|
if (!createProdRes.ok) {
|
|
140
141
|
const errData = await readJsonObjectResponse(createProdRes);
|
|
141
|
-
errorImpl(
|
|
142
|
+
errorImpl(
|
|
143
|
+
prodCreateFailureMessage(errData, createProdRes, {
|
|
144
|
+
requestedRegion: region,
|
|
145
|
+
credentialEnvName: credentialEnvNameOf(creds),
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
142
148
|
exitImpl(1);
|
|
143
149
|
return null;
|
|
144
150
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.284",
|
|
4
4
|
"description": "Gencow — AI Backend Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"better-auth": "1.7.11",
|
|
42
42
|
"postgres": "^3.4.9",
|
|
43
43
|
"@gencow/core": "0.1.47",
|
|
44
|
+
"@gencow/shared": "0.0.0",
|
|
44
45
|
"@gencow/react": "0.2.8",
|
|
45
46
|
"@gencow/server": "0.1.3",
|
|
46
|
-
"@gencow/client": "0.2.8"
|
|
47
|
-
"@gencow/shared": "0.0.0"
|
|
47
|
+
"@gencow/client": "0.2.8"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
|