@selvajs/selva 4.20.1-beta.1 → 4.20.1-beta.3

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.
Files changed (73) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/chunks/{D-SwRD80.js → D-uUm_OB.js} +43 -43
  3. package/build/client/_app/immutable/chunks/D-uUm_OB.js.br +0 -0
  4. package/build/client/_app/immutable/chunks/{D-SwRD80.js.gz → D-uUm_OB.js.gz} +0 -0
  5. package/build/client/_app/immutable/chunks/D84F7w9g.js +1 -0
  6. package/build/client/_app/immutable/chunks/D84F7w9g.js.br +1 -0
  7. package/build/client/_app/immutable/chunks/D84F7w9g.js.gz +0 -0
  8. package/build/client/_app/immutable/entry/{app.hg2qyLJU.js → app.BpT6WkO1.js} +2 -2
  9. package/build/client/_app/immutable/entry/app.BpT6WkO1.js.br +0 -0
  10. package/build/client/_app/immutable/entry/app.BpT6WkO1.js.gz +0 -0
  11. package/build/client/_app/immutable/nodes/21.BkNlRItr.js +1 -0
  12. package/build/client/_app/immutable/nodes/21.BkNlRItr.js.br +0 -0
  13. package/build/client/_app/immutable/nodes/21.BkNlRItr.js.gz +0 -0
  14. package/build/client/_app/version.json +1 -1
  15. package/build/client/_app/version.json.br +0 -0
  16. package/build/client/_app/version.json.gz +0 -0
  17. package/build/server/.vite/manifest.json +9 -2
  18. package/build/server/chunks/access.js +0 -3
  19. package/build/server/chunks/access.js.map +1 -1
  20. package/build/server/chunks/definitions.js +178 -1
  21. package/build/server/chunks/definitions.js.map +1 -1
  22. package/build/server/chunks/handlers.js +4 -5
  23. package/build/server/chunks/handlers.js.map +1 -1
  24. package/build/server/chunks/instance.js +3 -3
  25. package/build/server/chunks/internal.js +1 -1
  26. package/build/server/chunks/package.js +1 -1
  27. package/build/server/chunks/package.js.map +1 -1
  28. package/build/server/chunks/providers.server.js +112 -189
  29. package/build/server/chunks/providers.server.js.map +1 -1
  30. package/build/server/chunks/registry.js +3 -3
  31. package/build/server/chunks/registry.js.map +1 -1
  32. package/build/server/chunks/resolve.server.js +1 -1
  33. package/build/server/chunks/server-config-write.js +13 -1
  34. package/build/server/chunks/server-config-write.js.map +1 -1
  35. package/build/server/chunks/solve.server.js +8 -3
  36. package/build/server/chunks/solve.server.js.map +1 -1
  37. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js +30 -48
  38. package/build/server/entries/endpoints/api/admin/compute/_server.ts.js.map +1 -1
  39. package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js +3 -2
  40. package/build/server/entries/endpoints/api/admin/compute/actions/_server.ts.js.map +1 -1
  41. package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +3 -2
  42. package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js.map +1 -1
  43. package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +3 -2
  44. package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js.map +1 -1
  45. package/build/server/entries/endpoints/api/admin/users/_server.ts.js +6 -2
  46. package/build/server/entries/endpoints/api/admin/users/_server.ts.js.map +1 -1
  47. package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js +8 -8
  48. package/build/server/entries/endpoints/api/files/_...path_/_server.ts.js.map +1 -1
  49. package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
  50. package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +1 -1
  51. package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
  52. package/build/server/entries/hooks.server.js +13 -1
  53. package/build/server/entries/hooks.server.js.map +1 -1
  54. package/build/server/entries/pages/accept-invite/_page.server.ts.js +19 -1
  55. package/build/server/entries/pages/accept-invite/_page.server.ts.js.map +1 -1
  56. package/build/server/entries/pages/library/_guid_/_page.server.ts.js +16 -3
  57. package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
  58. package/build/server/entries/pages/library/_guid_/_page.svelte.js +132 -89
  59. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  60. package/build/server/manifest-full.js +1 -1
  61. package/build/server/manifest.js +1 -1
  62. package/build/server/nodes/21.js +1 -1
  63. package/build/server/server.js +1 -1
  64. package/package.json +10 -10
  65. package/build/client/_app/immutable/chunks/D-SwRD80.js.br +0 -0
  66. package/build/client/_app/immutable/chunks/Dvq2vJj6.js +0 -1
  67. package/build/client/_app/immutable/chunks/Dvq2vJj6.js.br +0 -1
  68. package/build/client/_app/immutable/chunks/Dvq2vJj6.js.gz +0 -0
  69. package/build/client/_app/immutable/entry/app.hg2qyLJU.js.br +0 -0
  70. package/build/client/_app/immutable/entry/app.hg2qyLJU.js.gz +0 -0
  71. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js +0 -1
  72. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.br +0 -1
  73. package/build/client/_app/immutable/nodes/21.gGT7QEb1.js.gz +0 -0
@@ -1,4 +1,181 @@
1
1
  import "./visibility.js";
2
+ // ../server/src/logging/PinoLogger.ts
3
+ /**
4
+ * Field names scrubbed before a record is written, by both backends. A backstop
5
+ * for accidents, NOT a licence to log objects: call sites are required not to
6
+ * log secrets in the first place (see `LogFields`). This catches the case where
7
+ * a whole object is spread into fields and happens to carry a credential.
8
+ *
9
+ * It matches by FIELD NAME, and only at the top level or one level deep. It will
10
+ * not catch personal data: an email nested in a payload sails straight through,
11
+ * and a log line reaches a collector that erasure can never reach.
12
+ */
13
+ var REDACTED_KEYS = [
14
+ "token",
15
+ "sessionToken",
16
+ "refreshToken",
17
+ "apiKey",
18
+ "api_key",
19
+ "password",
20
+ "authorization",
21
+ "Authorization",
22
+ "cookie",
23
+ "secret"
24
+ ];
25
+ var CENSOR = "[redacted]";
26
+ var REDACTED = new Set(REDACTED_KEYS);
27
+ var REDACTED_PATHS = [...REDACTED_KEYS, ...REDACTED_KEYS.map((k) => `*.${k}`)];
28
+ /** {@link REDACTED_KEYS} applied the way pino applies its paths, on a copy. */
29
+ function redact(fields) {
30
+ const out = {};
31
+ for (const [key, value] of Object.entries(fields)) out[key] = REDACTED.has(key) ? CENSOR : redactOneLevel(value);
32
+ return out;
33
+ }
34
+ function redactOneLevel(value) {
35
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return value;
36
+ if (!Object.keys(value).some((k) => REDACTED.has(k))) return value;
37
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, REDACTED.has(k) ? CENSOR : v]));
38
+ }
39
+ /**
40
+ * Minimal `ILogger` over `console.*`, used when pino isn't installed. Renders
41
+ * as `LEVEL message {fields}` — greppable, and honest about not being
42
+ * machine-parseable. `child` fields merge eagerly so correlation still works.
43
+ */
44
+ var ConsoleLogger = class ConsoleLogger {
45
+ bound;
46
+ minLevel;
47
+ constructor(bound = {}, minLevel = "info") {
48
+ this.bound = bound;
49
+ this.minLevel = minLevel;
50
+ }
51
+ static ORDER = {
52
+ debug: 10,
53
+ info: 20,
54
+ warn: 30,
55
+ error: 40
56
+ };
57
+ write(level, message, fields) {
58
+ if (ConsoleLogger.ORDER[level] < ConsoleLogger.ORDER[this.minLevel]) return;
59
+ const merged = {
60
+ ...this.bound,
61
+ ...fields
62
+ };
63
+ const suffix = Object.keys(merged).length > 0 ? ` ${renderFields(merged)}` : "";
64
+ const line = `${level.toUpperCase()} ${message}${suffix}`;
65
+ if (level === "error") console.error(line);
66
+ else if (level === "warn") console.warn(line);
67
+ else console.info(line);
68
+ }
69
+ debug(message, fields) {
70
+ this.write("debug", message, fields);
71
+ }
72
+ info(message, fields) {
73
+ this.write("info", message, fields);
74
+ }
75
+ warn(message, fields) {
76
+ this.write("warn", message, fields);
77
+ }
78
+ error(message, fields) {
79
+ this.write("error", message, fields);
80
+ }
81
+ child(fields) {
82
+ return new ConsoleLogger({
83
+ ...this.bound,
84
+ ...fields
85
+ }, this.minLevel);
86
+ }
87
+ };
88
+ /** Fields can hold anything, including cycles. Never let rendering throw. */
89
+ function renderFields(fields) {
90
+ try {
91
+ return JSON.stringify(redact(fields)) ?? String(fields);
92
+ } catch {
93
+ return "[unserializable]";
94
+ }
95
+ }
96
+ var PinoLogger = class PinoLogger {
97
+ pino;
98
+ constructor(pino) {
99
+ this.pino = pino;
100
+ }
101
+ debug(message, fields) {
102
+ try {
103
+ this.pino.debug(fields ?? {}, message);
104
+ } catch {}
105
+ }
106
+ info(message, fields) {
107
+ try {
108
+ this.pino.info(fields ?? {}, message);
109
+ } catch {}
110
+ }
111
+ warn(message, fields) {
112
+ try {
113
+ this.pino.warn(fields ?? {}, message);
114
+ } catch {}
115
+ }
116
+ error(message, fields) {
117
+ try {
118
+ this.pino.error(fields ?? {}, message);
119
+ } catch {}
120
+ }
121
+ child(fields) {
122
+ try {
123
+ return new PinoLogger(this.pino.child(fields));
124
+ } catch {
125
+ return this;
126
+ }
127
+ }
128
+ };
129
+ /** Build the app's root logger. Never throws, never returns `null`. */
130
+ async function createLogger(opts = {}) {
131
+ const level = opts.level ?? "info";
132
+ try {
133
+ const factory = await loadPinoFactory();
134
+ if (!factory) return new ConsoleLogger(opts.base ?? {}, level);
135
+ return new PinoLogger(factory({
136
+ level,
137
+ base: opts.base,
138
+ redact: {
139
+ paths: REDACTED_PATHS,
140
+ censor: CENSOR
141
+ },
142
+ transport: opts.pretty ? {
143
+ target: "pino-pretty",
144
+ options: {
145
+ colorize: true,
146
+ ignore: "pid,hostname"
147
+ }
148
+ } : void 0
149
+ }));
150
+ } catch (err) {
151
+ console.warn(`[Logger] pino was found but could not be initialized; falling back to console logging. ${String(err)}`);
152
+ return new ConsoleLogger(opts.base ?? {}, level);
153
+ }
154
+ }
155
+ /**
156
+ * Load pino's factory, or `null` when it isn't installed.
157
+ *
158
+ * Don't inline the specifier. A literal `import('pino')` is statically
159
+ * analyzable, so Vite applied browser-field mapping to this server build and
160
+ * resolved it to pino's `server_false` browser shim — a stub whose factory
161
+ * throws, turning "use pino" into a silent fall back to the console. Computing
162
+ * the specifier defeats that and leaves the import to Node at runtime.
163
+ * `@vite-ignore` alone was NOT enough: it silenced the warning and the rewrite
164
+ * still happened.
165
+ */
166
+ async function loadPinoFactory() {
167
+ const specifier = "pino";
168
+ try {
169
+ const mod = await import(
170
+ /* @vite-ignore */
171
+ specifier
172
+ );
173
+ const factory = mod.default ?? mod;
174
+ return typeof factory === "function" ? factory : null;
175
+ } catch {
176
+ return null;
177
+ }
178
+ }
2
179
  // ../server/src/logging/requestId.ts
3
180
  /**
4
181
  * Request-id resolution for log correlation. Every record on a request path
@@ -81,6 +258,6 @@ function randomId() {
81
258
  if (c && typeof c.randomUUID === "function") return c.randomUUID();
82
259
  return `req-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
83
260
  }
84
- export { renderThrown as n, resolveRequestId as r, REQUEST_ID_HEADER as t };
261
+ export { createLogger as a, ConsoleLogger as i, renderThrown as n, resolveRequestId as r, REQUEST_ID_HEADER as t };
85
262
 
86
263
  //# sourceMappingURL=definitions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","names":[],"sources":["../../../../server/src/logging/requestId.ts"],"sourcesContent":["/**\n * Request-id resolution for log correlation. Every record on a request path\n * carries the same `requestId`, so an operator handed one id can reconstruct\n * that request's whole story.\n *\n * Inbound ids are TRUSTED when present. Selva runs behind a reverse proxy\n * (Caddy/nginx) that mints a request id for its own access logs; minting a\n * second one here would split one request across two ids and kill cross-tier\n * correlation. The trade — a direct caller picks their own id — is fine, because\n * the id is only ever a log field and an echoed response header, never an\n * authorization or uniqueness input.\n *\n * That trust is why {@link sanitizeRequestId} exists: an attacker-chosen id is\n * untrusted content. Unbounded or newline-carrying values would let a caller\n * forge log lines (log injection) or bloat every record on the request.\n */\n\n/** Header carrying a caller/proxy-supplied id. The de-facto standard spelling. */\nexport const REQUEST_ID_HEADER = 'x-request-id';\n\n/** Long enough for a UUID or a W3C trace-id, short enough to bound a record. */\nconst MAX_REQUEST_ID_LENGTH = 128;\n\n/**\n * Characters allowed through verbatim. Strict on purpose: UUIDs, ULIDs, hex\n * trace-ids and nginx's `$request_id` all fit. Everything else — whitespace,\n * control chars, quotes, CR/LF — is dropped rather than escaped, since no\n * legitimate id needs them and dropping can't be un-escaped downstream.\n */\nconst UNSAFE_REQUEST_ID_CHARS = /[^A-Za-z0-9._:-]/g;\n\n/** Returns `null` when nothing usable survives, so the caller generates instead. */\nexport function sanitizeRequestId(raw: string | null | undefined): string | null {\n\tif (!raw) return null;\n\tconst cleaned = raw.replace(UNSAFE_REQUEST_ID_CHARS, '').slice(0, MAX_REQUEST_ID_LENGTH);\n\treturn cleaned.length > 0 ? cleaned : null;\n}\n\n/**\n * Reuse the proxy's id when it survives sanitization, otherwise mint a UUID.\n *\n * @param generate injectable so tests get deterministic ids\n */\nexport function resolveRequestId(headers: Headers, generate: () => string = randomId): string {\n\treturn sanitizeRequestId(headers.get(REQUEST_ID_HEADER)) ?? generate();\n}\n\n/**\n * Render a thrown value into a log field.\n *\n * Not every rejection is an `Error` — provider adapters sometimes reject with a\n * plain `{ message, status }`, which would stringify to a useless\n * `[object Object]` and destroy the only record of the failure. Errors keep\n * their stack; anything else is JSON-serialized, with `String()` as the last\n * resort for cycles and exotic values.\n *\n * A `code` / `statusCode` carried on the error (ComputeError, ProviderError,\n * Node's ECONNREFUSED-style errors) is appended as a `[code=… status=…]` tag —\n * it classifies the failure and stacks alone don't show it.\n */\nexport function renderThrown(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst base = error.stack ?? error.message;\n\t\tconst code = (error as { code?: unknown }).code;\n\t\tconst statusCode = (error as { statusCode?: unknown }).statusCode;\n\t\tconst tags: string[] = [];\n\t\tif (typeof code === 'string' || typeof code === 'number') tags.push(`code=${code}`);\n\t\tif (typeof statusCode === 'number') tags.push(`status=${statusCode}`);\n\t\treturn tags.length > 0 ? `${base} [${tags.join(' ')}]` : base;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error) ?? String(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n\n/**\n * `crypto.randomUUID` exists in every runtime Selva targets (Node 22+, workers,\n * modern browsers); the `Math.random` branch only covers non-secure contexts\n * where it is missing. Not a weakness: these ids need to be collision-free\n * enough to correlate logs, never unguessable.\n */\nfunction randomId(): string {\n\tconst c: Crypto | undefined = globalThis.crypto;\n\tif (c && typeof c.randomUUID === 'function') return c.randomUUID();\n\treturn `req-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,oBAAoB;;AAGjC,IAAM,wBAAwB;;;;;;;AAQ9B,IAAM,0BAA0B;;AAGhC,SAAgB,kBAAkB,KAA+C;CAChF,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,UAAU,IAAI,QAAQ,yBAAyB,EAAE,CAAC,CAAC,MAAM,GAAG,qBAAqB;CACvF,OAAO,QAAQ,SAAS,IAAI,UAAU;AACvC;;;;;;AAOA,SAAgB,iBAAiB,SAAkB,WAAyB,UAAkB;CAC7F,OAAO,kBAAkB,QAAQ,IAAA,cAAqB,CAAC,KAAK,SAAS;AACtE;;;;;;;;;;;;;;AAeA,SAAgB,aAAa,OAAwB;CACpD,IAAI,iBAAiB,OAAO;EAC3B,MAAM,OAAO,MAAM,SAAS,MAAM;EAClC,MAAM,OAAQ,MAA6B;EAC3C,MAAM,aAAc,MAAmC;EACvD,MAAM,OAAiB,CAAC;EACxB,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAM;EAClF,IAAI,OAAO,eAAe,UAAU,KAAK,KAAK,UAAU,YAAY;EACpE,OAAO,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,KAAK,KAAK,GAAG,EAAE,KAAK;CAC1D;CACA,IAAI;EACH,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC7C,QAAQ;EACP,OAAO,OAAO,KAAK;CACpB;AACD;;;;;;;AAQA,SAAS,WAAmB;CAC3B,MAAM,IAAwB,WAAW;CACzC,IAAI,KAAK,OAAO,EAAE,eAAe,YAAY,OAAO,EAAE,WAAW;CACjE,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE;AAChF"}
1
+ {"version":3,"file":"definitions.js","names":[],"sources":["../../../../server/src/logging/PinoLogger.ts","../../../../server/src/logging/requestId.ts"],"sourcesContent":["import type { ILogger, LogFields, LogLevel } from '@selvajs/platform';\n\n/**\n * `ILogger` backed by pino, with a console-backed fallback.\n *\n * pino is an OPTIONAL peer dependency, imported dynamically so the base install\n * ships without it. Unlike `@sentry/node` next door, absence must NOT degrade to\n * silence — an operator who never configured a logging backend still needs\n * warnings and errors on stdout, so {@link createLogger} falls back to\n * {@link ConsoleLogger} rather than returning `null`.\n *\n * pino earns its place by writing newline-delimited JSON with a stable schema:\n * what every log collector expects, and what console template literals can't\n * produce.\n */\n\n/** The slice of pino's surface used here — a hard import would make it mandatory. */\ninterface PinoLike {\n\tdebug(obj: object, msg?: string): void;\n\tinfo(obj: object, msg?: string): void;\n\twarn(obj: object, msg?: string): void;\n\terror(obj: object, msg?: string): void;\n\tchild(bindings: object): PinoLike;\n}\n\ntype PinoFactory = (options: {\n\tlevel: string;\n\tbase: object | undefined;\n\tredact?: { paths: string[]; censor: string };\n\ttransport?: { target: string; options: object };\n}) => PinoLike;\n\n/**\n * Field names scrubbed before a record is written, by both backends. A backstop\n * for accidents, NOT a licence to log objects: call sites are required not to\n * log secrets in the first place (see `LogFields`). This catches the case where\n * a whole object is spread into fields and happens to carry a credential.\n *\n * It matches by FIELD NAME, and only at the top level or one level deep. It will\n * not catch personal data: an email nested in a payload sails straight through,\n * and a log line reaches a collector that erasure can never reach.\n */\nconst REDACTED_KEYS = [\n\t'token',\n\t'sessionToken',\n\t'refreshToken',\n\t'apiKey',\n\t'api_key',\n\t'password',\n\t'authorization',\n\t'Authorization',\n\t'cookie',\n\t// A freshly minted API token is returned as `secret`.\n\t'secret'\n];\n\nconst CENSOR = '[redacted]';\nconst REDACTED = new Set(REDACTED_KEYS);\nconst REDACTED_PATHS = [...REDACTED_KEYS, ...REDACTED_KEYS.map((k) => `*.${k}`)];\n\n/** {@link REDACTED_KEYS} applied the way pino applies its paths, on a copy. */\nfunction redact(fields: LogFields): LogFields {\n\tconst out: LogFields = {};\n\tfor (const [key, value] of Object.entries(fields)) {\n\t\tout[key] = REDACTED.has(key) ? CENSOR : redactOneLevel(value);\n\t}\n\treturn out;\n}\n\nfunction redactOneLevel(value: unknown): unknown {\n\tif (value === null || typeof value !== 'object' || Array.isArray(value)) return value;\n\tif (!Object.keys(value).some((k) => REDACTED.has(k))) return value;\n\treturn Object.fromEntries(\n\t\tObject.entries(value).map(([k, v]) => [k, REDACTED.has(k) ? CENSOR : v])\n\t);\n}\n\n/**\n * Minimal `ILogger` over `console.*`, used when pino isn't installed. Renders\n * as `LEVEL message {fields}` — greppable, and honest about not being\n * machine-parseable. `child` fields merge eagerly so correlation still works.\n */\nexport class ConsoleLogger implements ILogger {\n\tconstructor(\n\t\tprivate readonly bound: LogFields = {},\n\t\tprivate readonly minLevel: LogLevel = 'info'\n\t) {}\n\n\tprivate static readonly ORDER: Record<LogLevel, number> = {\n\t\tdebug: 10,\n\t\tinfo: 20,\n\t\twarn: 30,\n\t\terror: 40\n\t};\n\n\tprivate write(level: LogLevel, message: string, fields?: LogFields): void {\n\t\tif (ConsoleLogger.ORDER[level] < ConsoleLogger.ORDER[this.minLevel]) return;\n\t\tconst merged = { ...this.bound, ...fields };\n\t\tconst suffix = Object.keys(merged).length > 0 ? ` ${renderFields(merged)}` : '';\n\t\tconst line = `${level.toUpperCase()} ${message}${suffix}`;\n\t\t// Split stderr/stdout the way an operator expects. `info` carries debug\n\t\t// too — both land on stdout, and the line already spells out its level.\n\t\tif (level === 'error') console.error(line);\n\t\telse if (level === 'warn') console.warn(line);\n\t\telse console.info(line);\n\t}\n\n\tdebug(message: string, fields?: LogFields): void {\n\t\tthis.write('debug', message, fields);\n\t}\n\tinfo(message: string, fields?: LogFields): void {\n\t\tthis.write('info', message, fields);\n\t}\n\twarn(message: string, fields?: LogFields): void {\n\t\tthis.write('warn', message, fields);\n\t}\n\terror(message: string, fields?: LogFields): void {\n\t\tthis.write('error', message, fields);\n\t}\n\tchild(fields: LogFields): ILogger {\n\t\treturn new ConsoleLogger({ ...this.bound, ...fields }, this.minLevel);\n\t}\n}\n\n/** Fields can hold anything, including cycles. Never let rendering throw. */\nfunction renderFields(fields: LogFields): string {\n\ttry {\n\t\treturn JSON.stringify(redact(fields)) ?? String(fields);\n\t} catch {\n\t\treturn '[unserializable]';\n\t}\n}\n\nclass PinoLogger implements ILogger {\n\tconstructor(private readonly pino: PinoLike) {}\n\n\t// pino takes (fields, message); ILogger takes (message, fields). The flip is\n\t// deliberate — the message is what a human scans for first.\n\tdebug(message: string, fields?: LogFields): void {\n\t\ttry {\n\t\t\tthis.pino.debug(fields ?? {}, message);\n\t\t} catch {\n\t\t\t/* logging must never throw */\n\t\t}\n\t}\n\tinfo(message: string, fields?: LogFields): void {\n\t\ttry {\n\t\t\tthis.pino.info(fields ?? {}, message);\n\t\t} catch {\n\t\t\t/* logging must never throw */\n\t\t}\n\t}\n\twarn(message: string, fields?: LogFields): void {\n\t\ttry {\n\t\t\tthis.pino.warn(fields ?? {}, message);\n\t\t} catch {\n\t\t\t/* logging must never throw */\n\t\t}\n\t}\n\terror(message: string, fields?: LogFields): void {\n\t\ttry {\n\t\t\tthis.pino.error(fields ?? {}, message);\n\t\t} catch {\n\t\t\t/* logging must never throw */\n\t\t}\n\t}\n\tchild(fields: LogFields): ILogger {\n\t\ttry {\n\t\t\treturn new PinoLogger(this.pino.child(fields));\n\t\t} catch {\n\t\t\treturn this;\n\t\t}\n\t}\n}\n\nexport interface CreateLoggerOptions {\n\t/** Minimum level written; records below it are dropped. Defaults to `info`. */\n\tlevel?: LogLevel;\n\t/**\n\t * Pretty-print via `pino-pretty` instead of JSON — for local development;\n\t * production wants JSON for the collector. Asking for this without\n\t * `pino-pretty` installed drops the whole logger to {@link ConsoleLogger}.\n\t */\n\tpretty?: boolean;\n\t/** Fields stamped on every record (e.g. service name, release). */\n\tbase?: LogFields;\n}\n\n/** Build the app's root logger. Never throws, never returns `null`. */\nexport async function createLogger(opts: CreateLoggerOptions = {}): Promise<ILogger> {\n\tconst level = opts.level ?? 'info';\n\ttry {\n\t\tconst factory = await loadPinoFactory();\n\t\tif (!factory) return new ConsoleLogger(opts.base ?? {}, level);\n\t\tconst pino = factory({\n\t\t\tlevel,\n\t\t\tbase: opts.base,\n\t\t\tredact: { paths: REDACTED_PATHS, censor: CENSOR },\n\t\t\ttransport: opts.pretty\n\t\t\t\t? { target: 'pino-pretty', options: { colorize: true, ignore: 'pid,hostname' } }\n\t\t\t\t: undefined\n\t\t});\n\t\treturn new PinoLogger(pino);\n\t} catch (err) {\n\t\t// pino resolved but wouldn't construct — a real misconfiguration (e.g.\n\t\t// `pretty: true` with pino-pretty absent). Worth complaining about, unlike\n\t\t// a merely absent package: the operator asked for something they didn't get.\n\t\tconsole.warn(\n\t\t\t`[Logger] pino was found but could not be initialized; falling back to console logging. ${String(err)}`\n\t\t);\n\t\treturn new ConsoleLogger(opts.base ?? {}, level);\n\t}\n}\n\n/**\n * Load pino's factory, or `null` when it isn't installed.\n *\n * Don't inline the specifier. A literal `import('pino')` is statically\n * analyzable, so Vite applied browser-field mapping to this server build and\n * resolved it to pino's `server_false` browser shim — a stub whose factory\n * throws, turning \"use pino\" into a silent fall back to the console. Computing\n * the specifier defeats that and leaves the import to Node at runtime.\n * `@vite-ignore` alone was NOT enough: it silenced the warning and the rewrite\n * still happened.\n */\nasync function loadPinoFactory(): Promise<PinoFactory | null> {\n\tconst specifier = 'pino';\n\ttry {\n\t\tconst mod = await import(/* @vite-ignore */ specifier);\n\t\tconst factory = ((mod as { default?: unknown }).default ?? mod) as PinoFactory;\n\t\treturn typeof factory === 'function' ? factory : null;\n\t} catch {\n\t\t// Not installed — the expected path on a base install, where the console\n\t\t// fallback is intended. Quiet on purpose: complaining at boot about an\n\t\t// optional package nobody asked for is noise.\n\t\treturn null;\n\t}\n}\n","/**\n * Request-id resolution for log correlation. Every record on a request path\n * carries the same `requestId`, so an operator handed one id can reconstruct\n * that request's whole story.\n *\n * Inbound ids are TRUSTED when present. Selva runs behind a reverse proxy\n * (Caddy/nginx) that mints a request id for its own access logs; minting a\n * second one here would split one request across two ids and kill cross-tier\n * correlation. The trade — a direct caller picks their own id — is fine, because\n * the id is only ever a log field and an echoed response header, never an\n * authorization or uniqueness input.\n *\n * That trust is why {@link sanitizeRequestId} exists: an attacker-chosen id is\n * untrusted content. Unbounded or newline-carrying values would let a caller\n * forge log lines (log injection) or bloat every record on the request.\n */\n\n/** Header carrying a caller/proxy-supplied id. The de-facto standard spelling. */\nexport const REQUEST_ID_HEADER = 'x-request-id';\n\n/** Long enough for a UUID or a W3C trace-id, short enough to bound a record. */\nconst MAX_REQUEST_ID_LENGTH = 128;\n\n/**\n * Characters allowed through verbatim. Strict on purpose: UUIDs, ULIDs, hex\n * trace-ids and nginx's `$request_id` all fit. Everything else — whitespace,\n * control chars, quotes, CR/LF — is dropped rather than escaped, since no\n * legitimate id needs them and dropping can't be un-escaped downstream.\n */\nconst UNSAFE_REQUEST_ID_CHARS = /[^A-Za-z0-9._:-]/g;\n\n/** Returns `null` when nothing usable survives, so the caller generates instead. */\nexport function sanitizeRequestId(raw: string | null | undefined): string | null {\n\tif (!raw) return null;\n\tconst cleaned = raw.replace(UNSAFE_REQUEST_ID_CHARS, '').slice(0, MAX_REQUEST_ID_LENGTH);\n\treturn cleaned.length > 0 ? cleaned : null;\n}\n\n/**\n * Reuse the proxy's id when it survives sanitization, otherwise mint a UUID.\n *\n * @param generate injectable so tests get deterministic ids\n */\nexport function resolveRequestId(headers: Headers, generate: () => string = randomId): string {\n\treturn sanitizeRequestId(headers.get(REQUEST_ID_HEADER)) ?? generate();\n}\n\n/**\n * Render a thrown value into a log field.\n *\n * Not every rejection is an `Error` — provider adapters sometimes reject with a\n * plain `{ message, status }`, which would stringify to a useless\n * `[object Object]` and destroy the only record of the failure. Errors keep\n * their stack; anything else is JSON-serialized, with `String()` as the last\n * resort for cycles and exotic values.\n *\n * A `code` / `statusCode` carried on the error (ComputeError, ProviderError,\n * Node's ECONNREFUSED-style errors) is appended as a `[code=… status=…]` tag —\n * it classifies the failure and stacks alone don't show it.\n */\nexport function renderThrown(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst base = error.stack ?? error.message;\n\t\tconst code = (error as { code?: unknown }).code;\n\t\tconst statusCode = (error as { statusCode?: unknown }).statusCode;\n\t\tconst tags: string[] = [];\n\t\tif (typeof code === 'string' || typeof code === 'number') tags.push(`code=${code}`);\n\t\tif (typeof statusCode === 'number') tags.push(`status=${statusCode}`);\n\t\treturn tags.length > 0 ? `${base} [${tags.join(' ')}]` : base;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error) ?? String(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n\n/**\n * `crypto.randomUUID` exists in every runtime Selva targets (Node 22+, workers,\n * modern browsers); the `Math.random` branch only covers non-secure contexts\n * where it is missing. Not a weakness: these ids need to be collision-free\n * enough to correlate logs, never unguessable.\n */\nfunction randomId(): string {\n\tconst c: Crypto | undefined = globalThis.crypto;\n\tif (c && typeof c.randomUUID === 'function') return c.randomUUID();\n\treturn `req-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,IAAM,gBAAgB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;AACD;AAEA,IAAM,SAAS;AACf,IAAM,WAAW,IAAI,IAAI,aAAa;AACtC,IAAM,iBAAiB,CAAC,GAAG,eAAe,GAAG,cAAc,KAAK,MAAM,KAAK,GAAG,CAAC;;AAG/E,SAAS,OAAO,QAA8B;CAC7C,MAAM,MAAiB,CAAC;CACxB,KAAK,MAAM,CAAC,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AK,IAAI,KAAK,KAAK,GAAG,EAAE,KAAK;CAC1D;CACA,IAAI;EACH,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC7C,QAAQ;EACP,OAAO,OAAO,KAAK;CACpB;AACD;;;;;;;AAQA,SAAS,WAAmB;CAC3B,MAAM,IAAwB,WAAW;CACzC,IAAI,KAAK,OAAO,EAAE,eAAe,YAAY,OAAO,EAAE,WAAW;CACjE,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,EAAE;AAChF"}
@@ -12,7 +12,7 @@ import { t as DEFAULT_SHARE_LINK_MAX_SOLVES } from "./types4.js";
12
12
  import { a as loadVisibleDefinition, c as resolveAccessibleProjects, i as listVisibleDefinitions, l as clampPageLimit, n as getVisibleDefinition, o as loadVisibleVersion, p as walkPages, r as listEditableDefinitionsByDocument, s as mayUploadToDefinition } from "./visibility.js";
13
13
  import { r as fetchSchemaFromCompute } from "./schema-extraction.js";
14
14
  import { n as resolveServerForOrg } from "./resolve-server.js";
15
- import { a as validateIncomingServers, i as storedKeysById, n as assertStoredKeysReadable, o as evictChangedServers, r as resolveApiKey, t as assertKeyNotRetargeted } from "./server-config-write.js";
15
+ import { n as validateIncomingServers, r as evictChangedServers, t as mergeApiKeys } from "./server-config-write.js";
16
16
  import "./compute.js";
17
17
  import { t as canHoldApiTokens } from "./tokens.js";
18
18
  import { c as buildRequestContext, s as signInIsStale } from "./http.js";
@@ -1470,16 +1470,14 @@ var updateOrgCompute = async (req) => {
1470
1470
  const provider = req.deps.computeServer;
1471
1471
  const existing = await provider.getConfig(ctx, { includeApiKeys: true });
1472
1472
  const orgServers = existing.servers.filter((s) => isOrgServer(s) && s.ownerOrgId === orgId);
1473
- assertStoredKeysReadable(incoming.servers, orgServers);
1474
- assertKeyNotRetargeted(incoming.servers, orgServers);
1475
- const storedKeys = storedKeysById(orgServers);
1473
+ const apiKeys = mergeApiKeys(incoming.servers, orgServers);
1476
1474
  const next = incoming.servers.map((s) => ({
1477
1475
  id: s.id,
1478
1476
  scope: "org",
1479
1477
  ownerOrgId: orgId,
1480
1478
  label: s.label,
1481
1479
  serverUrl: s.serverUrl,
1482
- apiKey: resolveApiKey(s.apiKey, storedKeys.get(s.id))
1480
+ apiKey: apiKeys.get(s.id)
1483
1481
  }));
1484
1482
  if (typeof incoming.defaultServerId === "string") {
1485
1483
  const projected = {
@@ -1549,6 +1547,7 @@ async function mailInvite(req, invite, acceptUrl) {
1549
1547
  }
1550
1548
  /** Pending and recently accepted invites for the acting org. */
1551
1549
  var listInvites = async (req) => {
1550
+ requireSession(req, "Invites are managed from the web app, not with an API key.");
1552
1551
  requireManageOrgMembers(req);
1553
1552
  const { ctx, orgId } = requireActingOrg(req, req.params.orgId);
1554
1553
  return shapedCollection(InviteResponseSchema, await req.deps.invites.listByOrg(ctx, orgId, parseListOptions(req.url)));