gencow 0.1.278 → 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 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, name, value) {
4765
+ async function execSetConfig(client, text, params) {
4758
4766
  if (typeof client?.unsafe === "function") {
4759
- await client.unsafe(`select set_config($1::text, $2::text, true)`, [name, value]);
4767
+ await client.unsafe(text, params);
4760
4768
  return;
4761
4769
  }
4762
4770
  if (typeof client?.query === "function") {
4763
- await client.query(`select set_config($1::text, $2::text, true)`, [name, value]);
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
- await forEachSetConfig(rls, (name, value) => execSetConfig(client, name, value));
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
- await forEachSetConfig(rls, (name, value) => tx.execute(sql11`SELECT set_config(${name}, ${value}, true)`));
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 = response.status === 401 ? "APP_RELEASE_AUTH_REQUIRED" : LOOKUP_FAILED_CODE;
21
- const retryable = typeof body?.retryable === "boolean" ? body.retryable : response.status >= 500;
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
- lines.push("Next: gencow login, then retry the same command.");
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 {
@@ -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
- export function authCauseNextAction(credentialEnvName = null) {
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). If it repeats, send the Correlation ID.`;
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\`. If it repeats, send the Correlation ID.`;
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.278",
3
+ "version": "0.1.279",
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/core": "0.1.47",
43
44
  "@gencow/client": "0.2.8",
44
45
  "@gencow/react": "0.2.8",
45
- "@gencow/core": "0.1.47",
46
- "@gencow/server": "0.1.3",
47
- "@gencow/shared": "0.0.0"
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",