gencow 0.1.278 → 0.1.280
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/cloud-target-environment.mjs +23 -4
- package/lib/deploy-command.mjs +60 -21
- package/lib/deployment-operation-poll.mjs +2 -2
- package/lib/release-auth-cause.mjs +8 -3
- package/package.json +4 -4
- package/runtime/server.mjs +265 -265
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,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 {
|
package/lib/deploy-command.mjs
CHANGED
|
@@ -29,7 +29,7 @@ export function renderDeployHelp() {
|
|
|
29
29
|
log(` ${BOLD}Examples:${RESET}`);
|
|
30
30
|
log(` gencow deploy`);
|
|
31
31
|
log(` gencow deploy status`);
|
|
32
|
-
log(` gencow deploy status --deployment <operation-id
|
|
32
|
+
log(` gencow deploy status --deployment <operation-id> [--prod] [--app <name>]`);
|
|
33
33
|
log(` gencow deploy status --release-attempt <attempt-id> [--prod]`);
|
|
34
34
|
log(` gencow deploy logs [-n 100] [--history]`);
|
|
35
35
|
log(` gencow deploy --static dist/`);
|
|
@@ -49,6 +49,8 @@ export function parseDeployLogScope(deployArgs) {
|
|
|
49
49
|
return deployArgs.includes("--history") ? "history" : "current";
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const APP_NAME_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
53
|
+
|
|
52
54
|
function readReleaseAttemptStatusId(deployArgs) {
|
|
53
55
|
const indices = deployArgs.flatMap((arg, index) => (arg === "--release-attempt" ? [index] : []));
|
|
54
56
|
if (indices.length === 0) return null;
|
|
@@ -72,7 +74,7 @@ function readReleaseAttemptStatusId(deployArgs) {
|
|
|
72
74
|
}
|
|
73
75
|
if ((targetArgs[cursor] === "--app" || targetArgs[cursor] === "-a") && !appSelected) {
|
|
74
76
|
const appName = targetArgs[cursor + 1];
|
|
75
|
-
if (typeof appName !== "string" ||
|
|
77
|
+
if (typeof appName !== "string" || !APP_NAME_PATTERN.test(appName)) return undefined;
|
|
76
78
|
appSelected = true;
|
|
77
79
|
cursor += 1;
|
|
78
80
|
continue;
|
|
@@ -82,24 +84,55 @@ function readReleaseAttemptStatusId(deployArgs) {
|
|
|
82
84
|
return value;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
)
|
|
100
|
-
|
|
87
|
+
function isDeploymentOperationIdText(value) {
|
|
88
|
+
return typeof value === "string" && /^[1-9][0-9]*$/u.test(value) && Number.isSafeInteger(Number(value));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const INLINE_OPTION_PATTERN = /^(-{1,2}[a-z][a-z0-9-]*)=(.*)$/u;
|
|
92
|
+
const MAX_ECHOED_OPTION_LENGTH = 40;
|
|
93
|
+
|
|
94
|
+
// --deployment is the operation-scoped form: the endpoint is addressed by the id alone. --prod and
|
|
95
|
+
// --app/-a are accepted in any order as selectors; --app is format-checked but does not change the lookup.
|
|
96
|
+
// `--name=value` is split into `--name value` first, so both spellings share one validation path.
|
|
97
|
+
function readDeploymentStatusArgs(rawDeployArgs) {
|
|
98
|
+
const deployArgs = rawDeployArgs.flatMap((arg) => {
|
|
99
|
+
const inline = INLINE_OPTION_PATTERN.exec(arg);
|
|
100
|
+
return inline ? [inline[1], inline[2]] : [arg];
|
|
101
|
+
});
|
|
102
|
+
if (!deployArgs.includes("--deployment")) return null;
|
|
103
|
+
const rawOperationId = deployArgs[deployArgs.indexOf("--deployment") + 1];
|
|
104
|
+
const operationText = isDeploymentOperationIdText(rawOperationId) ? rawOperationId : "<operation-id>";
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
let operationId = null;
|
|
107
|
+
for (let cursor = 1; cursor < deployArgs.length; cursor += 1) {
|
|
108
|
+
const arg = deployArgs[cursor];
|
|
109
|
+
if (arg === "--deployment" || arg === "--prod" || arg === "--app" || arg === "-a") {
|
|
110
|
+
const option = arg === "-a" ? "--app" : arg;
|
|
111
|
+
if (seen.has(option))
|
|
112
|
+
return { error: "args", reason: `option ${option} was given more than once`, operationText };
|
|
113
|
+
seen.add(option);
|
|
114
|
+
if (option === "--prod") continue;
|
|
115
|
+
const value = deployArgs[cursor + 1];
|
|
116
|
+
cursor += 1;
|
|
117
|
+
if (option === "--deployment") {
|
|
118
|
+
if (!isDeploymentOperationIdText(value)) return { error: "operation-id" };
|
|
119
|
+
operationId = Number(value);
|
|
120
|
+
} else if (typeof value !== "string" || !APP_NAME_PATTERN.test(value)) {
|
|
121
|
+
return { error: "args", reason: "option --app needs a valid app name", operationText };
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Only [a-z0-9-] option names are echoed, and the echo is length-capped; anything else is not repeated.
|
|
126
|
+
const reason = /^-{1,2}[a-z][a-z0-9-]*$/u.test(arg)
|
|
127
|
+
? `unknown option ${arg.slice(0, MAX_ECHOED_OPTION_LENGTH)}${arg.length > MAX_ECHOED_OPTION_LENGTH ? "..." : ""}`
|
|
128
|
+
: "unexpected argument";
|
|
129
|
+
return { error: "args", reason, operationText };
|
|
101
130
|
}
|
|
102
|
-
return
|
|
131
|
+
return { operationId };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function renderDeploymentStatusArgsInvalid({ reason, operationText }) {
|
|
135
|
+
return `DEPLOYMENT_OPERATION_ARGS_INVALID: ${reason}. Stage: status argument parsing. Changed: nothing; status is read-only. Retry: run again with only the allowed options: gencow deploy status --deployment ${operationText} [--prod] [--app <name>]`;
|
|
103
136
|
}
|
|
104
137
|
|
|
105
138
|
function logDeploymentOperationStatus(logImpl, infoImpl, body) {
|
|
@@ -207,12 +240,18 @@ export async function handleDeployReadonlySubcommand(params) {
|
|
|
207
240
|
logImpl("");
|
|
208
241
|
return true;
|
|
209
242
|
}
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
243
|
+
const deploymentStatus = subcmd === "status" ? readDeploymentStatusArgs(deployArgs) : null;
|
|
244
|
+
if (deploymentStatus?.error === "operation-id") {
|
|
212
245
|
errorImpl("DEPLOYMENT_OPERATION_ID_INVALID: use a positive numeric --deployment value.");
|
|
213
246
|
exitImpl(1);
|
|
214
247
|
return true;
|
|
215
248
|
}
|
|
249
|
+
if (deploymentStatus?.error) {
|
|
250
|
+
errorImpl(renderDeploymentStatusArgsInvalid(deploymentStatus));
|
|
251
|
+
exitImpl(1);
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
const deploymentId = deploymentStatus?.operationId ?? null;
|
|
216
255
|
if (deploymentId !== null) {
|
|
217
256
|
if (typeof platformFetchImpl !== "function") {
|
|
218
257
|
errorImpl("DEPLOYMENT_STATUS_UNAVAILABLE: operation status transport is unavailable.");
|
|
@@ -33,8 +33,8 @@ export function readDeploymentOperationPhase(body) {
|
|
|
33
33
|
/**
|
|
34
34
|
* One-line acceptance notice for `gencow deploy`. The identity was validated by
|
|
35
35
|
* pollAcceptedDeploymentOperation (positive integer operation ID, safe correlation ID).
|
|
36
|
-
* The status command uses the operation-scoped `--deployment` form
|
|
37
|
-
*
|
|
36
|
+
* The status command uses the operation-scoped `--deployment` form. The endpoint is addressed by the
|
|
37
|
+
* operation ID alone; `--prod` and `--app` are optional selectors, so no `--app` is appended.
|
|
38
38
|
*/
|
|
39
39
|
export function formatDeploymentAcceptedLine({ operationId, correlationId, envTarget }) {
|
|
40
40
|
const prodSelector = envTarget === "prod" ? " --prod" : "";
|
|
@@ -17,10 +17,15 @@ export function safeAuthCauseCode(value) {
|
|
|
17
17
|
// There is no automatic retry: the user reruns the command once by hand after the check succeeds.
|
|
18
18
|
// `credentialEnvName` (GENCOW_TOKEN or GENCOW_DEPLOY_TOKEN, already validated by the caller) is passed only
|
|
19
19
|
// when that variable is the credential. It overrides `gencow login`, so the fallback names the env change.
|
|
20
|
-
|
|
20
|
+
// The login-check sentence alone, for a failure whose correlation ID is not available.
|
|
21
|
+
export function loginCheckNextAction(credentialEnvName = null) {
|
|
21
22
|
const check = "run `gencow whoami` first. If it succeeds, rerun the same command once manually (no automatic retry); ";
|
|
22
23
|
if (credentialEnvName) {
|
|
23
|
-
return `${check}if it fails, replace or unset ${credentialEnvName} (gencow login does not override it)
|
|
24
|
+
return `${check}if it fails, replace or unset ${credentialEnvName} (gencow login does not override it).`;
|
|
24
25
|
}
|
|
25
|
-
return `${check}if it fails, run \`gencow login
|
|
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.`;
|
|
26
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.280",
|
|
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",
|
|
45
43
|
"@gencow/core": "0.1.47",
|
|
44
|
+
"@gencow/shared": "0.0.0",
|
|
46
45
|
"@gencow/server": "0.1.3",
|
|
47
|
-
"@gencow/
|
|
46
|
+
"@gencow/client": "0.2.8",
|
|
47
|
+
"@gencow/react": "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",
|