gencow 0.1.277 → 0.1.279
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/core/index.js +23 -10
- package/lib/cli-command-runner.mjs +5 -2
- package/lib/cloud-target-environment.mjs +23 -4
- package/lib/deploy-app-target.mjs +20 -4
- package/lib/release-auth-cause.mjs +31 -0
- package/lib/release-client.mjs +3 -0
- package/package.json +4 -4
- package/runtime/server.mjs +314 -295
package/core/index.js
CHANGED
|
@@ -4556,6 +4556,19 @@ var pgBaseTable = pgTable;
|
|
|
4556
4556
|
// ../core/src/rls-db.ts
|
|
4557
4557
|
import { sql as sql11 } from "drizzle-orm";
|
|
4558
4558
|
|
|
4559
|
+
// ../core/src/rls-set-config-statement.ts
|
|
4560
|
+
function buildRlsSetConfigStatement(pairs) {
|
|
4561
|
+
if (pairs.length === 0) return null;
|
|
4562
|
+
const calls = [];
|
|
4563
|
+
const params = [];
|
|
4564
|
+
for (const [name, value] of pairs) {
|
|
4565
|
+
const n = params.length;
|
|
4566
|
+
calls.push(`set_config($${n + 1}::text, $${n + 2}::text, true)`);
|
|
4567
|
+
params.push(name, value);
|
|
4568
|
+
}
|
|
4569
|
+
return { text: `select ${calls.join(", ")}`, params };
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4559
4572
|
// ../core/src/rls-db-scoped-query.ts
|
|
4560
4573
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4561
4574
|
import { NoopCache } from "drizzle-orm/cache/core";
|
|
@@ -4741,11 +4754,6 @@ function rlsSetConfigPairs(rls) {
|
|
|
4741
4754
|
}
|
|
4742
4755
|
return pairs;
|
|
4743
4756
|
}
|
|
4744
|
-
async function forEachSetConfig(rls, setOne) {
|
|
4745
|
-
for (const [name, value] of rlsSetConfigPairs(rls)) {
|
|
4746
|
-
await setOne(name, value);
|
|
4747
|
-
}
|
|
4748
|
-
}
|
|
4749
4757
|
function isDrizzleTransactionDb(db) {
|
|
4750
4758
|
const d = db;
|
|
4751
4759
|
if (typeof d?.rollback === "function") {
|
|
@@ -4754,23 +4762,28 @@ function isDrizzleTransactionDb(db) {
|
|
|
4754
4762
|
const name = d?.constructor?.name;
|
|
4755
4763
|
return typeof name === "string" && name.includes("Transaction");
|
|
4756
4764
|
}
|
|
4757
|
-
async function execSetConfig(client,
|
|
4765
|
+
async function execSetConfig(client, text, params) {
|
|
4758
4766
|
if (typeof client?.unsafe === "function") {
|
|
4759
|
-
await client.unsafe(
|
|
4767
|
+
await client.unsafe(text, params);
|
|
4760
4768
|
return;
|
|
4761
4769
|
}
|
|
4762
4770
|
if (typeof client?.query === "function") {
|
|
4763
|
-
await client.query(
|
|
4771
|
+
await client.query(text, params);
|
|
4764
4772
|
return;
|
|
4765
4773
|
}
|
|
4766
4774
|
throw new Error("createRlsDb: unsupported SQL driver (expected Bun SQL, node-pg client/pool, or PGlite)");
|
|
4767
4775
|
}
|
|
4768
4776
|
async function applyRlsSessionVars(client, rls) {
|
|
4769
|
-
|
|
4777
|
+
const statement = buildRlsSetConfigStatement(rlsSetConfigPairs(rls));
|
|
4778
|
+
if (statement) await execSetConfig(client, statement.text, statement.params);
|
|
4770
4779
|
}
|
|
4771
4780
|
async function injectRlsVarsOnTx(tx, rls, onTransactionContextFailure) {
|
|
4772
4781
|
try {
|
|
4773
|
-
|
|
4782
|
+
const pairs = rlsSetConfigPairs(rls);
|
|
4783
|
+
if (pairs.length > 0) {
|
|
4784
|
+
const calls = pairs.map(([name, value]) => sql11`set_config(${name}::text, ${value}::text, true)`);
|
|
4785
|
+
await tx.execute(sql11`select ${sql11.join(calls, sql11`, `)}`);
|
|
4786
|
+
}
|
|
4774
4787
|
} catch (error) {
|
|
4775
4788
|
try {
|
|
4776
4789
|
onTransactionContextFailure?.(error);
|
|
@@ -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,8 +1,11 @@
|
|
|
1
1
|
import { readProjectAppTargets, resolveCloudAppTarget } from "./cloud-targets.mjs";
|
|
2
2
|
import { readJsonValueResponse } from "./http-response-json.mjs";
|
|
3
|
+
import { loginCheckNextAction } from "./release-auth-cause.mjs";
|
|
3
4
|
|
|
4
5
|
const SAFE_CORRELATION_ID = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
5
6
|
const LOOKUP_FAILED_CODE = "APP_DEPLOY_TARGET_LOOKUP_FAILED";
|
|
7
|
+
// Public code the Platform sends when its auth lookup failed on the database side (HTTP 503, retryable).
|
|
8
|
+
const AUTH_LOOKUP_UNAVAILABLE_CODE = "AUTH_LOOKUP_UNAVAILABLE";
|
|
6
9
|
|
|
7
10
|
// Reads the environment fact the server stores for an app (apps.get: environment "production" |
|
|
8
11
|
// "development", prodApp = the dev app's prod sibling). Used only when the project cannot tell us the
|
|
@@ -17,8 +20,15 @@ export async function lookupAppEnvironment({ creds, appId, rpcQueryImpl }) {
|
|
|
17
20
|
const decoded = await readJsonValueResponse(response);
|
|
18
21
|
const body = decoded.parsed ? decoded.value : undefined;
|
|
19
22
|
if (!response.ok) {
|
|
20
|
-
const code =
|
|
21
|
-
|
|
23
|
+
const code =
|
|
24
|
+
response.status === 401
|
|
25
|
+
? "APP_RELEASE_AUTH_REQUIRED"
|
|
26
|
+
: response.status === 503 && body?.code === AUTH_LOOKUP_UNAVAILABLE_CODE
|
|
27
|
+
? AUTH_LOOKUP_UNAVAILABLE_CODE
|
|
28
|
+
: LOOKUP_FAILED_CODE;
|
|
29
|
+
// A 401 without a stated retryable is not "no": it is decided by the login check in the next action.
|
|
30
|
+
const retryable =
|
|
31
|
+
typeof body?.retryable === "boolean" ? body.retryable : response.status === 401 ? undefined : response.status >= 500;
|
|
22
32
|
return {
|
|
23
33
|
kind: "error",
|
|
24
34
|
code,
|
|
@@ -65,12 +75,21 @@ function renderLookupFailure(failure, { stage, appId }) {
|
|
|
65
75
|
`Stage: ${stage}`,
|
|
66
76
|
`App ID: ${appId}`,
|
|
67
77
|
"Changed: nothing. No app, env value, or serving state was changed.",
|
|
68
|
-
`Retryable: ${failure.retryable ? "yes" : "no"}`,
|
|
69
78
|
];
|
|
79
|
+
if (failure.code === "APP_RELEASE_AUTH_REQUIRED" && failure.retryable === undefined) {
|
|
80
|
+
lines.push("Retryable: only after `gencow whoami` succeeds");
|
|
81
|
+
} else {
|
|
82
|
+
lines.push(`Retryable: ${failure.retryable ? "yes" : "no"}`);
|
|
83
|
+
}
|
|
70
84
|
if (failure.status) lines.push(`HTTP status: ${failure.status}`);
|
|
71
85
|
if (failure.correlationId) lines.push(`Correlation ID: ${failure.correlationId}`);
|
|
72
86
|
if (failure.code === "APP_RELEASE_AUTH_REQUIRED") {
|
|
73
|
-
|
|
87
|
+
// No correlation ID is sent for a 401 without a stated cause, so the next action does not mention one.
|
|
88
|
+
lines.push(`Next: ${loginCheckNextAction(null)}`);
|
|
89
|
+
} else if (failure.code === AUTH_LOOKUP_UNAVAILABLE_CODE) {
|
|
90
|
+
lines.push(
|
|
91
|
+
"Next: this is a temporary Platform lookup failure, not a login problem. Wait a few seconds, then run the same command again. If it repeats, send the Correlation ID.",
|
|
92
|
+
);
|
|
74
93
|
} else if (failure.retryable) {
|
|
75
94
|
lines.push("Next: retry the same command after a short wait.");
|
|
76
95
|
} else {
|
|
@@ -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,31 @@
|
|
|
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
|
+
// The login-check sentence alone, for a failure whose correlation ID is not available.
|
|
21
|
+
export function loginCheckNextAction(credentialEnvName = null) {
|
|
22
|
+
const check = "run `gencow whoami` first. If it succeeds, rerun the same command once manually (no automatic retry); ";
|
|
23
|
+
if (credentialEnvName) {
|
|
24
|
+
return `${check}if it fails, replace or unset ${credentialEnvName} (gencow login does not override it).`;
|
|
25
|
+
}
|
|
26
|
+
return `${check}if it fails, run \`gencow login\`.`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function authCauseNextAction(credentialEnvName = null) {
|
|
30
|
+
return `${loginCheckNextAction(credentialEnvName)} If it repeats, send the Correlation ID.`;
|
|
31
|
+
}
|
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.279",
|
|
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",
|
|
45
|
-
"@gencow/server": "0.1.3",
|
|
46
44
|
"@gencow/client": "0.2.8",
|
|
47
|
-
"@gencow/react": "0.2.8"
|
|
45
|
+
"@gencow/react": "0.2.8",
|
|
46
|
+
"@gencow/shared": "0.0.0",
|
|
47
|
+
"@gencow/server": "0.1.3"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
|