gencow 0.1.277 → 0.1.278
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/lib/cli-command-runner.mjs +5 -2
- package/lib/deploy-app-target.mjs +20 -4
- package/lib/release-auth-cause.mjs +26 -0
- package/lib/release-client.mjs +3 -0
- package/package.json +4 -4
- package/runtime/server.mjs +130 -111
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { formatProcedureRpcDiagnostic } from "./procedure-rpc-diagnostic.mjs";
|
|
2
2
|
import { describeMigrationFolderFormatFailure } from "./migration-folder-format.mjs";
|
|
3
|
+
import { authCauseNextAction, safeAuthCauseCode } from "./release-auth-cause.mjs";
|
|
3
4
|
import {
|
|
4
5
|
SCHEMA_LOAD_FAILURE_CLI_ACTION,
|
|
5
6
|
SCHEMA_LOAD_FAILURE_CLI_MESSAGE,
|
|
@@ -378,6 +379,8 @@ function commandErrorMessage(caught) {
|
|
|
378
379
|
}
|
|
379
380
|
if (caught instanceof Error && (caught.message === "APP_RELEASE_AUTH_REQUIRED" || caught.status === 401)) {
|
|
380
381
|
const lines = ["Login expired or invalid for this Platform."];
|
|
382
|
+
const authCauseCode = safeAuthCauseCode(caught.causeCode);
|
|
383
|
+
if (authCauseCode) lines.push("Stage: auth", `Cause: ${authCauseCode}`);
|
|
381
384
|
const platformOrigin = safePlatformOrigin(caught.platformUrl);
|
|
382
385
|
if (platformOrigin) lines.push(`Platform: ${platformOrigin}`);
|
|
383
386
|
const credentialEnvName =
|
|
@@ -390,9 +393,9 @@ function commandErrorMessage(caught) {
|
|
|
390
393
|
lines.push(
|
|
391
394
|
`Action: replace or unset ${credentialEnvName}; environment credentials override interactive login.`,
|
|
392
395
|
);
|
|
393
|
-
} else {
|
|
394
|
-
lines.push("Run: npx gencow@latest login");
|
|
395
396
|
}
|
|
397
|
+
if (authCauseCode) lines.push(`Next: ${authCauseNextAction(credentialEnvName)}`);
|
|
398
|
+
else if (!credentialEnvName) lines.push("Run: npx gencow@latest login");
|
|
396
399
|
if (typeof caught.correlationId === "string" && SAFE_CORRELATION_ID.test(caught.correlationId)) {
|
|
397
400
|
lines.push(`Correlation ID: ${caught.correlationId}`);
|
|
398
401
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { appNotFoundDiagnostic } from "./app-response-contract.mjs";
|
|
2
2
|
import { describeProdTargetFailure, resolveProdAppTarget } from "./cloud-targets.mjs";
|
|
3
3
|
import { readJsonObjectResponse } from "./http-response-json.mjs";
|
|
4
|
+
import { authCauseNextAction, safeAuthCauseCode } from "./release-auth-cause.mjs";
|
|
4
5
|
|
|
5
6
|
const PUBLIC_LOOKUP_ERROR_CODES = new Set([
|
|
6
7
|
"ACCOUNT_DELETED",
|
|
@@ -13,12 +14,20 @@ const PUBLIC_LOOKUP_ERROR_CODES = new Set([
|
|
|
13
14
|
]);
|
|
14
15
|
const SAFE_CORRELATION_ID = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
15
16
|
|
|
16
|
-
function publicLookupFailure(response, body) {
|
|
17
|
+
function publicLookupFailure(response, body, creds) {
|
|
17
18
|
const code = PUBLIC_LOOKUP_ERROR_CODES.has(body?.code)
|
|
18
19
|
? body.code
|
|
19
20
|
: response.status === 401
|
|
20
21
|
? "APP_RELEASE_AUTH_REQUIRED"
|
|
21
22
|
: "APP_DEPLOY_TARGET_LOOKUP_FAILED";
|
|
23
|
+
const causeCode =
|
|
24
|
+
code === "APP_RELEASE_AUTH_REQUIRED" && body?.stage === "auth" ? safeAuthCauseCode(body.causeCode) : null;
|
|
25
|
+
// Only a fixed env name is kept, so the next action can tell the user to replace or unset it.
|
|
26
|
+
const credentialEnvName =
|
|
27
|
+
creds?.credentialSource === "environment" &&
|
|
28
|
+
(creds.credentialEnvName === "GENCOW_TOKEN" || creds.credentialEnvName === "GENCOW_DEPLOY_TOKEN")
|
|
29
|
+
? creds.credentialEnvName
|
|
30
|
+
: null;
|
|
22
31
|
return {
|
|
23
32
|
kind: "error",
|
|
24
33
|
code,
|
|
@@ -27,6 +36,8 @@ function publicLookupFailure(response, body) {
|
|
|
27
36
|
...(typeof body?.correlationId === "string" && SAFE_CORRELATION_ID.test(body.correlationId)
|
|
28
37
|
? { correlationId: body.correlationId }
|
|
29
38
|
: {}),
|
|
39
|
+
...(causeCode ? { causeCode } : {}),
|
|
40
|
+
...(causeCode && credentialEnvName ? { credentialEnvName } : {}),
|
|
30
41
|
};
|
|
31
42
|
}
|
|
32
43
|
|
|
@@ -37,9 +48,14 @@ function formatLookupFailure(failure, target) {
|
|
|
37
48
|
];
|
|
38
49
|
if (failure?.status) lines.push(`HTTP status: ${failure.status}`);
|
|
39
50
|
if (typeof failure?.retryable === "boolean") lines.push(`Retryable: ${failure.retryable ? "yes" : "no"}`);
|
|
51
|
+
if (failure?.causeCode) lines.push("Stage: auth", `Cause: ${failure.causeCode}`);
|
|
40
52
|
if (failure?.correlationId) lines.push(`Correlation ID: ${failure.correlationId}`);
|
|
41
53
|
if (code === "APP_RELEASE_AUTH_REQUIRED") {
|
|
42
|
-
lines.push(
|
|
54
|
+
lines.push(
|
|
55
|
+
failure?.causeCode
|
|
56
|
+
? `Action: ${authCauseNextAction(failure.credentialEnvName ?? null)}`
|
|
57
|
+
: "Action: run gencow login, or replace/unset the environment credential, then retry.",
|
|
58
|
+
);
|
|
43
59
|
} else if (code === "ACCOUNT_SUSPENDED" || code === "ACCOUNT_DELETION_PENDING" || code === "ACCOUNT_DELETED") {
|
|
44
60
|
lines.push("Action: resolve the account status in Platform before retrying.");
|
|
45
61
|
} else if (failure?.retryable) {
|
|
@@ -172,10 +188,10 @@ export async function lookupOwnedApp({ creds, appId, environment, platformFetchI
|
|
|
172
188
|
const body = await readJsonObjectResponse(response);
|
|
173
189
|
if (response.status === 404) {
|
|
174
190
|
if (body?.code === "APP_RELEASE_APP_NOT_FOUND") return "missing";
|
|
175
|
-
return body?.code ? publicLookupFailure(response, body) : "unsupported";
|
|
191
|
+
return body?.code ? publicLookupFailure(response, body, creds) : "unsupported";
|
|
176
192
|
}
|
|
177
193
|
if (response.status === 409 && body?.code === "APP_RELEASE_VERSIONS_DISABLED") return "found";
|
|
178
|
-
if (!response.ok) return publicLookupFailure(response, body);
|
|
194
|
+
if (!response.ok) return publicLookupFailure(response, body, creds);
|
|
179
195
|
return body?.protocol === "app-release-v1" && typeof body.enabled === "boolean" ? "found" : "error";
|
|
180
196
|
} catch {
|
|
181
197
|
return {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Safe cause of a release capability 401 (APP_RELEASE_AUTH_REQUIRED). The Platform sends it as
|
|
2
|
+
// `stage: "auth"` plus `causeCode`; only these fixed values are rendered. Any other value is
|
|
3
|
+
// ignored, so an older Platform response keeps the output it had before this field existed.
|
|
4
|
+
const SAFE_AUTH_CAUSE_CODES = new Set([
|
|
5
|
+
"token_not_found",
|
|
6
|
+
"token_expired",
|
|
7
|
+
"token_scope_invalid",
|
|
8
|
+
"no_identity",
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
export function safeAuthCauseCode(value) {
|
|
12
|
+
return typeof value === "string" && SAFE_AUTH_CAUSE_CODES.has(value) ? value : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Sentence after "Action:" or "Next:" when the Platform stated an auth cause. It does not claim whether the
|
|
16
|
+
// Platform or the credential is at fault; it tells the user the one check that separates the two.
|
|
17
|
+
// There is no automatic retry: the user reruns the command once by hand after the check succeeds.
|
|
18
|
+
// `credentialEnvName` (GENCOW_TOKEN or GENCOW_DEPLOY_TOKEN, already validated by the caller) is passed only
|
|
19
|
+
// when that variable is the credential. It overrides `gencow login`, so the fallback names the env change.
|
|
20
|
+
export function authCauseNextAction(credentialEnvName = null) {
|
|
21
|
+
const check = "run `gencow whoami` first. If it succeeds, rerun the same command once manually (no automatic retry); ";
|
|
22
|
+
if (credentialEnvName) {
|
|
23
|
+
return `${check}if it fails, replace or unset ${credentialEnvName} (gencow login does not override it). If it repeats, send the Correlation ID.`;
|
|
24
|
+
}
|
|
25
|
+
return `${check}if it fails, run \`gencow login\`. If it repeats, send the Correlation ID.`;
|
|
26
|
+
}
|
package/lib/release-client.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { unlink } from "node:fs/promises";
|
|
3
3
|
|
|
4
|
+
import { safeAuthCauseCode } from "./release-auth-cause.mjs";
|
|
4
5
|
import { platformFetch } from "./platform-client.mjs";
|
|
5
6
|
import { createReleaseSourcePackage } from "./release-source-package.mjs";
|
|
6
7
|
|
|
@@ -99,6 +100,8 @@ function throwResponseError(response, fallback, body, creds = {}, context = {})
|
|
|
99
100
|
if (correlationId) error.correlationId = correlationId;
|
|
100
101
|
if (authRequired) {
|
|
101
102
|
error.retryable = false;
|
|
103
|
+
// Set only when the Platform states the auth stage; an older body has neither field.
|
|
104
|
+
if (body?.stage === "auth" && safeAuthCauseCode(body.causeCode)) error.causeCode = body.causeCode;
|
|
102
105
|
} else if (typeof body?.retryable === "boolean") {
|
|
103
106
|
error.retryable = body.retryable;
|
|
104
107
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.278",
|
|
4
4
|
"description": "Gencow — AI Backend Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"ai": "^6.0.314",
|
|
41
41
|
"better-auth": "1.7.11",
|
|
42
42
|
"postgres": "^3.4.9",
|
|
43
|
+
"@gencow/client": "0.2.8",
|
|
44
|
+
"@gencow/react": "0.2.8",
|
|
43
45
|
"@gencow/core": "0.1.47",
|
|
44
|
-
"@gencow/shared": "0.0.0",
|
|
45
46
|
"@gencow/server": "0.1.3",
|
|
46
|
-
"@gencow/
|
|
47
|
-
"@gencow/react": "0.2.8"
|
|
47
|
+
"@gencow/shared": "0.0.0"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
|