@3ngram/config 0.2.0
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/LICENSE +202 -0
- package/dist/context.d.ts +29 -0
- package/dist/context.js +23 -0
- package/dist/context.js.map +1 -0
- package/dist/env.d.ts +165 -0
- package/dist/env.js +544 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +24 -0
- package/dist/logger.js +68 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics.d.ts +51 -0
- package/dist/metrics.js +118 -0
- package/dist/metrics.js.map +1 -0
- package/dist/otel.d.ts +58 -0
- package/dist/otel.js +169 -0
- package/dist/otel.js.map +1 -0
- package/dist/redaction.d.ts +27 -0
- package/dist/redaction.js +88 -0
- package/dist/redaction.js.map +1 -0
- package/package.json +66 -0
- package/tsconfig.package.json +10 -0
package/dist/env.js
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export const LOG_LEVELS = ['fatal', 'error', 'warn', 'info', 'debug', 'trace'];
|
|
4
|
+
/** The OAuth MCP resource path appended to BASE_URL (ADR-0009 impl req 1). */
|
|
5
|
+
export const OAUTH_RESOURCE_PATH = '/mcp';
|
|
6
|
+
/**
|
|
7
|
+
* A single private RS256 signing key in JWK form (ADR-0009 impl req 2).
|
|
8
|
+
*
|
|
9
|
+
* OAUTH_JWKS carries an ARRAY of these (as JSON): the FIRST key is the current
|
|
10
|
+
* signing key; the rest are old keys kept until their issued tokens expire
|
|
11
|
+
* (rotation = add new at the front, drop the tail past max token lifetime).
|
|
12
|
+
* Every key MUST carry a `kid` so the resource server can select by header and
|
|
13
|
+
* rotation stays unambiguous. Only RS256 (kty=RSA, alg=RS256) is accepted — the
|
|
14
|
+
* RS validates RS256 exclusively, so any other key is a boot-time config error.
|
|
15
|
+
* The private fields (`d`, `p`, `q`, ...) live here; the JWKS endpoint derives
|
|
16
|
+
* the PUBLIC view and never serves them (impl req: never expose private material).
|
|
17
|
+
*/
|
|
18
|
+
const oauthJwkSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
kty: z.literal('RSA'),
|
|
21
|
+
kid: z.string().min(1),
|
|
22
|
+
alg: z.literal('RS256'),
|
|
23
|
+
n: z.string().min(1),
|
|
24
|
+
e: z.string().min(1),
|
|
25
|
+
d: z.string().min(1),
|
|
26
|
+
})
|
|
27
|
+
.loose();
|
|
28
|
+
const oauthJwksSchema = z.array(oauthJwkSchema).min(1);
|
|
29
|
+
const postgresUrlSchema = z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.transform((value, ctx) => {
|
|
33
|
+
if (value === undefined || value === '')
|
|
34
|
+
return undefined;
|
|
35
|
+
try {
|
|
36
|
+
const parsed = new URL(value);
|
|
37
|
+
if (parsed.protocol !== 'postgres:' && parsed.protocol !== 'postgresql:') {
|
|
38
|
+
ctx.addIssue({
|
|
39
|
+
code: 'custom',
|
|
40
|
+
message: 'must be a postgres:// or postgresql:// URL',
|
|
41
|
+
});
|
|
42
|
+
return z.NEVER;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
ctx.addIssue({ code: 'custom', message: 'must be a valid URL' });
|
|
47
|
+
return z.NEVER;
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
});
|
|
51
|
+
const ownerLikeDatabaseUsers = new Set(['postgres', 'neondb_owner', 'migration_runner']);
|
|
52
|
+
function databaseUsername(url) {
|
|
53
|
+
const username = new URL(url).username;
|
|
54
|
+
try {
|
|
55
|
+
return decodeURIComponent(username);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return username;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function databasePassword(url) {
|
|
62
|
+
const password = new URL(url).password;
|
|
63
|
+
try {
|
|
64
|
+
return decodeURIComponent(password);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return password;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Placeholder/weak-password guard for the runtime DATABASE_URL.
|
|
72
|
+
*
|
|
73
|
+
* `.env.selfhost.example` ships `change-me-*` placeholders; the compose `:?`
|
|
74
|
+
* guards only fail-closed on MISSING vars, not on an unchanged placeholder. A
|
|
75
|
+
* self-host operator who copies the example and sets NODE_ENV=production would
|
|
76
|
+
* otherwise boot with a known credential. Reject the placeholder family, empty,
|
|
77
|
+
* and obviously-too-short passwords so the server refuses to start. Returns a
|
|
78
|
+
* human-readable reason (for the boot error) or undefined when acceptable.
|
|
79
|
+
*
|
|
80
|
+
* Production-gated by the caller so local dev defaults (docker-compose.yml ships
|
|
81
|
+
* `app-user-dev`, NODE_ENV=development) keep working untouched.
|
|
82
|
+
*/
|
|
83
|
+
const PLACEHOLDER_PASSWORD_PREFIX = 'change-me';
|
|
84
|
+
const MIN_DB_PASSWORD_LENGTH = 12;
|
|
85
|
+
// Known PUBLIC credentials shipped in the repo: the docker-compose.yml local-dev
|
|
86
|
+
// defaults (`app-user-dev`, `3ngram-dev`) and the .env.selfhost.example
|
|
87
|
+
// placeholders (`change-me-*`). They are public knowledge, so a production /
|
|
88
|
+
// self-host deploy that reuses one is compromised by default. Rejected
|
|
89
|
+
// explicitly and regardless of length — `app-user-dev` is exactly 12 chars and
|
|
90
|
+
// would otherwise pass MIN_DB_PASSWORD_LENGTH. Compared lowercased; the shell
|
|
91
|
+
// preflight (scripts/check-selfhost-secrets.sh) carries the same denylist.
|
|
92
|
+
const PUBLIC_DEV_PASSWORDS = new Set([
|
|
93
|
+
'app-user-dev',
|
|
94
|
+
'3ngram-dev',
|
|
95
|
+
'change-me-postgres-owner',
|
|
96
|
+
'change-me-app-user',
|
|
97
|
+
]);
|
|
98
|
+
function weakDatabasePasswordReason(password) {
|
|
99
|
+
if (password === '')
|
|
100
|
+
return 'is empty';
|
|
101
|
+
const lower = password.toLowerCase();
|
|
102
|
+
if (PUBLIC_DEV_PASSWORDS.has(lower)) {
|
|
103
|
+
return 'is a known public dev/example default (never use a shipped default in production)';
|
|
104
|
+
}
|
|
105
|
+
if (lower.startsWith(PLACEHOLDER_PASSWORD_PREFIX)) {
|
|
106
|
+
return 'still uses a .env.selfhost.example placeholder (change-me-*)';
|
|
107
|
+
}
|
|
108
|
+
if (password.length < MIN_DB_PASSWORD_LENGTH) {
|
|
109
|
+
return `is too short (minimum ${MIN_DB_PASSWORD_LENGTH} characters)`;
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Observability env contract.
|
|
115
|
+
*
|
|
116
|
+
* Refuse-by-construction gates live here so a misconfigured process fails at
|
|
117
|
+
* boot, not at the first log line:
|
|
118
|
+
* - `LOG_DEBUG_CONTENT=true` outside `NODE_ENV=development` is rejected (§1
|
|
119
|
+
* red line: memory content never enters logs outside local dev).
|
|
120
|
+
* - `LOG_HASH_SALT` is required in production (hashed user_id correlation, §1).
|
|
121
|
+
*/
|
|
122
|
+
export const envSchema = z
|
|
123
|
+
.object({
|
|
124
|
+
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
|
|
125
|
+
PORT: z.coerce.number().int().min(1).max(65535).default(3000),
|
|
126
|
+
// Session token lifetime (ADR-0009). Bounded so a typo cannot
|
|
127
|
+
// mint effectively-immortal sessions; fails the process at boot when out
|
|
128
|
+
// of range. Default 720h = 30 days.
|
|
129
|
+
SESSION_TTL_HOURS: z.coerce.number().int().min(1).max(8760).default(720),
|
|
130
|
+
// Forgotten-password reset-token lifetime. Short by design —
|
|
131
|
+
// a reset link is single-use and time-boxed; bounded so a typo cannot mint a
|
|
132
|
+
// long-lived token. Default 60 minutes.
|
|
133
|
+
RESET_TOKEN_TTL_MINUTES: z.coerce.number().int().min(1).max(1440).default(60),
|
|
134
|
+
// Email-verification token lifetime for self-serve signup. Longer than
|
|
135
|
+
// reset links because signup is not a suspected-compromise flow. Default
|
|
136
|
+
// 1440 minutes = 24 hours.
|
|
137
|
+
EMAIL_VERIFICATION_TOKEN_TTL_MINUTES: z.coerce.number().int().min(1).max(10080).default(1440),
|
|
138
|
+
// --- Budget (GENERIC + Apache-only). These are the license-safe knobs the
|
|
139
|
+
// self-host build keeps; the whole build is provider-agnostic and the license
|
|
140
|
+
// boundary is package-absence-only.
|
|
141
|
+
// Default per-cycle LLM budget cap (USD) used when a user has no override and
|
|
142
|
+
// no plan_tiers row applies — the self-host fallback, so caps still work with
|
|
143
|
+
// no platform (never "no row → no cap").
|
|
144
|
+
BUDGET_DEFAULT_CAP_USD: z.coerce.number().min(0).default(10),
|
|
145
|
+
// Default rolling budget-window length (days) for the no-platform path: with no
|
|
146
|
+
// explicit period, the budget cycle is the last N days. A platform state
|
|
147
|
+
// machine overrides this with the real plan period when present.
|
|
148
|
+
BUDGET_DEFAULT_WINDOW_DAYS: z.coerce.number().int().min(1).max(366).default(30),
|
|
149
|
+
// Runtime database URL. packages/db is the only layer that opens Postgres
|
|
150
|
+
// connections, but the app process still validates the deployment contract at
|
|
151
|
+
// boot so an invalid/missing DB URL fails before the first request.
|
|
152
|
+
DATABASE_URL: postgresUrlSchema,
|
|
153
|
+
// Owner/migration URL. Validated when present, but not required for the
|
|
154
|
+
// served app. Production app processes must not carry this credential; the
|
|
155
|
+
// release migration step injects it separately from operator/CI storage.
|
|
156
|
+
DATABASE_URL_UNPOOLED: postgresUrlSchema,
|
|
157
|
+
// OAuth resource-server config (ADR-0009 impl req 1+2). BASE_URL derives the
|
|
158
|
+
// single issuer + RFC 8707 resource id; OAUTH_JWKS is the JSON array of
|
|
159
|
+
// RS256 signing keys (first = current). Optional outside production so the
|
|
160
|
+
// skeleton boots locally, but REQUIRED + validated in production (a missing
|
|
161
|
+
// or malformed key must fail at boot, not at the first token verify). When
|
|
162
|
+
// present in any env they are validated; loadOAuthConfig() is the consumer.
|
|
163
|
+
// Only an absolute http(s) URL counts as "set". Vite/vitest inject
|
|
164
|
+
// BASE_URL='/' (their app base path) and some shells surface unset keys as
|
|
165
|
+
// '', neither of which is a deployment issuer — coerce those to undefined so
|
|
166
|
+
// they read as "not configured" (and so production's required-check fires
|
|
167
|
+
// with a clear message) rather than crashing every process at import.
|
|
168
|
+
BASE_URL: z
|
|
169
|
+
.string()
|
|
170
|
+
.optional()
|
|
171
|
+
.transform((value) => value === undefined || !/^https?:\/\//.test(value) ? undefined : value)
|
|
172
|
+
.pipe(z.url().optional()),
|
|
173
|
+
// Public origin of the 3ngram dashboard (the separate app that SERVES the
|
|
174
|
+
// /reset-password page). In the documented deploy (docs/operate.mdx)
|
|
175
|
+
// the server runs on Railway and the dashboard on Vercel — DIFFERENT origins —
|
|
176
|
+
// so a reset link built from BASE_URL (the API/OAuth issuer) points at the
|
|
177
|
+
// backend, which has no GET /reset-password (the form never loads). The reset
|
|
178
|
+
// link is built from this origin instead. OPTIONAL: when unset there is no web
|
|
179
|
+
// origin to link to, so the route skips the emailed link (the dev-echo token
|
|
180
|
+
// path stays intact). Only an absolute http(s) URL counts as "set"; '' (CI
|
|
181
|
+
// surfaces unset secrets as empty) and a Vite/vitest base path coerce to
|
|
182
|
+
// undefined, mirroring the BASE_URL contract.
|
|
183
|
+
WEB_APP_URL: z
|
|
184
|
+
.string()
|
|
185
|
+
.optional()
|
|
186
|
+
.transform((value) => value === undefined || !/^https?:\/\//.test(value) ? undefined : value)
|
|
187
|
+
.pipe(z.url().optional()),
|
|
188
|
+
OAUTH_JWKS: z
|
|
189
|
+
.string()
|
|
190
|
+
.optional()
|
|
191
|
+
.transform((value) => (value === undefined || value === '' ? undefined : value)),
|
|
192
|
+
// Embedding gateway (ADR-0007 "bring your own gateway"). Both optional and
|
|
193
|
+
// env-GATED: when LLM_GATEWAY_URL + LLM_GATEWAY_API_KEY are both set the app
|
|
194
|
+
// constructs a real OpenAI-compatible embedding client and injects it into
|
|
195
|
+
// the MCP tools; when either is absent, search surfaces a typed "not
|
|
196
|
+
// configured" error and remember runs with embedding off. Empty-string-is-
|
|
197
|
+
// unset (the eval convention): CI exports these from optional secrets that
|
|
198
|
+
// surface as '' when missing, so '' must read as "not configured", not as a
|
|
199
|
+
// blank URL/key. Names match eval/src/judge.mjs so one secret pair serves
|
|
200
|
+
// both surfaces.
|
|
201
|
+
LLM_GATEWAY_URL: z
|
|
202
|
+
.string()
|
|
203
|
+
.optional()
|
|
204
|
+
.transform((value) => value === undefined || !/^https?:\/\//.test(value) ? undefined : value)
|
|
205
|
+
.pipe(z.url().optional()),
|
|
206
|
+
LLM_GATEWAY_API_KEY: z
|
|
207
|
+
.string()
|
|
208
|
+
.optional()
|
|
209
|
+
.transform((value) => (value === undefined || value === '' ? undefined : value)),
|
|
210
|
+
// Redis connection string for the rate limiter — and
|
|
211
|
+
// the shared store for the BullMQ workers. Optional locally so the
|
|
212
|
+
// skeleton boots with an in-memory limiter (RateLimiterMemory), but REQUIRED
|
|
213
|
+
// in production: rate limiting must be cross-instance there (Railway runs N
|
|
214
|
+
// replicas; an in-memory bucket per instance is no limit at all). Mirrors the
|
|
215
|
+
// OAUTH_JWKS/BASE_URL contract exactly — only a redis(s):// URL counts as
|
|
216
|
+
// "set"; '' (CI surfaces unset secrets as empty) reads as undefined so
|
|
217
|
+
// production's required-check fires with a clear message rather than crashing
|
|
218
|
+
// every process at import. The value is a credential — it MUST NOT enter any
|
|
219
|
+
// log line (hard rule 6).
|
|
220
|
+
REDIS_URL: z
|
|
221
|
+
.string()
|
|
222
|
+
.optional()
|
|
223
|
+
.transform((value) => value === undefined || !/^rediss?:\/\//.test(value) ? undefined : value)
|
|
224
|
+
.pipe(z.url().optional()),
|
|
225
|
+
// Forgotten-password reset: when true, POST /auth/forgot-password
|
|
226
|
+
// surfaces the freshly minted plaintext reset token IN THE 200 RESPONSE BODY
|
|
227
|
+
// so a developer with no email channel can complete the flow. This is a
|
|
228
|
+
// DEV-ONLY convenience — a hard boot guard below refuses it outside
|
|
229
|
+
// NODE_ENV=development (the token is a credential; it must never reach a
|
|
230
|
+
// response body, let alone a log line, in prod — hard rule 6). Default off.
|
|
231
|
+
AUTH_RESET_TOKEN_DEV_ECHO: z.stringbool().default(false),
|
|
232
|
+
// Public account creation. Default off: pre-release/provisioned deployments
|
|
233
|
+
// should not accidentally become open-registration systems. When enabled,
|
|
234
|
+
// SMTP_HOST + SMTP_FROM + WEB_APP_URL are required by the cross-field guard
|
|
235
|
+
// below because signup depends on delivering verification links.
|
|
236
|
+
AUTH_SIGNUP_ENABLED: z.stringbool().default(false),
|
|
237
|
+
// Known-breach password screening (NIST 800-63B, research R3). When true,
|
|
238
|
+
// signup and reset reject passwords found in the HaveIBeenPwned corpus via the
|
|
239
|
+
// k-anonymity range API (only a 5-char SHA-1 prefix leaves the process — never
|
|
240
|
+
// the password). Default off so self-host / restricted-egress deployments are
|
|
241
|
+
// unaffected; the check itself FAILS OPEN on timeout/unreachable (account
|
|
242
|
+
// availability outranks a best-effort screen), so enabling it never blocks
|
|
243
|
+
// account creation when the corpus is down. The toggle and the fail-open
|
|
244
|
+
// behaviour are separate axes (data-model D4).
|
|
245
|
+
PASSWORD_BREACH_CHECK_ENABLED: z.stringbool().default(false),
|
|
246
|
+
// SMTP delivery for password-reset emails (self-host hardening). ALL OPTIONAL and env-GATED: when SMTP_HOST +
|
|
247
|
+
// SMTP_FROM are both set the app constructs a real nodemailer transport and
|
|
248
|
+
// emails the reset link; when either is absent the forgot-password route
|
|
249
|
+
// falls back to the documented owner-level / dev-token path and NEVER throws
|
|
250
|
+
// (self-host must boot with no mail server). Empty-string-is-unset mirrors
|
|
251
|
+
// the LLM_GATEWAY/REDIS contract: CI surfaces unset secrets as '' which must
|
|
252
|
+
// read as "not configured", not as a blank host. SMTP_PASS is a credential —
|
|
253
|
+
// it MUST NOT enter any log line (hard rule 6); the mailer logs host/port/
|
|
254
|
+
// message-id only. SMTP_USER/SMTP_PASS are optional even when SMTP_HOST is
|
|
255
|
+
// set (an open relay or IP-allowlisted MTA needs no auth).
|
|
256
|
+
SMTP_HOST: z
|
|
257
|
+
.string()
|
|
258
|
+
.optional()
|
|
259
|
+
.transform((value) => (value === undefined || value === '' ? undefined : value)),
|
|
260
|
+
// Empty-string-is-unset mirrors SMTP_HOST above: CI/self-host surfaces a
|
|
261
|
+
// missing optional secret as '' (or whitespace), and z.coerce.number()
|
|
262
|
+
// would map '' -> 0 (Number('') === 0), failing .min(1) and THROWING at
|
|
263
|
+
// env load even when SMTP is meant to be disabled. Preprocess '' / blank to
|
|
264
|
+
// undefined BEFORE coercion so the .default(587) applies and the no-SMTP
|
|
265
|
+
// boot path degrades gracefully.
|
|
266
|
+
SMTP_PORT: z.preprocess((value) => (typeof value === 'string' && value.trim() === '' ? undefined : value), z.coerce.number().int().min(1).max(65535).default(587)),
|
|
267
|
+
SMTP_USER: z
|
|
268
|
+
.string()
|
|
269
|
+
.optional()
|
|
270
|
+
.transform((value) => (value === undefined || value === '' ? undefined : value)),
|
|
271
|
+
SMTP_PASS: z
|
|
272
|
+
.string()
|
|
273
|
+
.optional()
|
|
274
|
+
.transform((value) => (value === undefined || value === '' ? undefined : value)),
|
|
275
|
+
SMTP_FROM: z
|
|
276
|
+
.string()
|
|
277
|
+
.optional()
|
|
278
|
+
.transform((value) => (value === undefined || value === '' ? undefined : value)),
|
|
279
|
+
LOG_LEVEL: z.enum(LOG_LEVELS).default('info'),
|
|
280
|
+
LOG_HASH_SALT: z.string().default(''),
|
|
281
|
+
LOG_DEBUG_CONTENT: z.stringbool().default(false),
|
|
282
|
+
SENTRY_DSN: z.string().default(''),
|
|
283
|
+
// Sentry environment tag. Hosted staging and production both run
|
|
284
|
+
// NODE_ENV=production, so the tag must NOT derive from NODE_ENV alone or the
|
|
285
|
+
// two environments are indistinguishable. Set per Railway service
|
|
286
|
+
// (staging|production); resolution + blank-handling live in otel.ts.
|
|
287
|
+
// RAILWAY_ENVIRONMENT_NAME is platform-injected and MUST be declared here —
|
|
288
|
+
// Zod strips undeclared keys, so the fallback tier would never fire.
|
|
289
|
+
SENTRY_ENVIRONMENT: z.string().default(''),
|
|
290
|
+
RAILWAY_ENVIRONMENT_NAME: z.string().default(''),
|
|
291
|
+
GIT_SHA: z.string().default(''),
|
|
292
|
+
RAILWAY_GIT_COMMIT_SHA: z.string().default(''),
|
|
293
|
+
})
|
|
294
|
+
.superRefine((env, ctx) => {
|
|
295
|
+
if (env.LOG_DEBUG_CONTENT && env.NODE_ENV !== 'development') {
|
|
296
|
+
ctx.addIssue({
|
|
297
|
+
code: 'custom',
|
|
298
|
+
path: ['LOG_DEBUG_CONTENT'],
|
|
299
|
+
message: 'LOG_DEBUG_CONTENT=true is refused outside NODE_ENV=development (observability.md §1)',
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
if (env.AUTH_RESET_TOKEN_DEV_ECHO && env.NODE_ENV !== 'development') {
|
|
303
|
+
ctx.addIssue({
|
|
304
|
+
code: 'custom',
|
|
305
|
+
path: ['AUTH_RESET_TOKEN_DEV_ECHO'],
|
|
306
|
+
message: 'AUTH_RESET_TOKEN_DEV_ECHO=true is refused outside NODE_ENV=development (issue #267: a reset token is a credential and must never reach a response body in prod)',
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (env.NODE_ENV === 'production' && env.LOG_HASH_SALT === '') {
|
|
310
|
+
ctx.addIssue({
|
|
311
|
+
code: 'custom',
|
|
312
|
+
path: ['LOG_HASH_SALT'],
|
|
313
|
+
message: 'LOG_HASH_SALT is required in production (observability.md §1 hashed user_id)',
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
if (env.NODE_ENV === 'production' && env.BASE_URL === undefined) {
|
|
317
|
+
ctx.addIssue({
|
|
318
|
+
code: 'custom',
|
|
319
|
+
path: ['BASE_URL'],
|
|
320
|
+
message: 'BASE_URL is required in production (ADR-0009 impl req 1: derives issuer + resource)',
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (env.NODE_ENV === 'production' && env.OAUTH_JWKS === undefined) {
|
|
324
|
+
ctx.addIssue({
|
|
325
|
+
code: 'custom',
|
|
326
|
+
path: ['OAUTH_JWKS'],
|
|
327
|
+
message: 'OAUTH_JWKS is required in production (ADR-0009 impl req 2: RS256 signing keys)',
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (env.NODE_ENV === 'production' && env.REDIS_URL === undefined) {
|
|
331
|
+
ctx.addIssue({
|
|
332
|
+
code: 'custom',
|
|
333
|
+
path: ['REDIS_URL'],
|
|
334
|
+
message: 'REDIS_URL is required in production (MCP D4: cross-instance rate limiting; an in-memory bucket per replica is no limit)',
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
if (env.NODE_ENV === 'production' && env.DATABASE_URL === undefined) {
|
|
338
|
+
ctx.addIssue({
|
|
339
|
+
code: 'custom',
|
|
340
|
+
path: ['DATABASE_URL'],
|
|
341
|
+
message: 'DATABASE_URL is required in production (runtime Postgres app_user URL)',
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
if (env.DATABASE_URL !== undefined) {
|
|
345
|
+
const username = databaseUsername(env.DATABASE_URL);
|
|
346
|
+
if (ownerLikeDatabaseUsers.has(username)) {
|
|
347
|
+
ctx.addIssue({
|
|
348
|
+
code: 'custom',
|
|
349
|
+
path: ['DATABASE_URL'],
|
|
350
|
+
message: 'DATABASE_URL must use the runtime app_user role, not an owner or migration role',
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
if (env.NODE_ENV === 'production' && username !== 'app_user') {
|
|
354
|
+
ctx.addIssue({
|
|
355
|
+
code: 'custom',
|
|
356
|
+
path: ['DATABASE_URL'],
|
|
357
|
+
message: 'DATABASE_URL must use app_user in production',
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
// Fail closed on placeholder/weak DB passwords in production/self-host.
|
|
361
|
+
// Gated to production so local dev defaults (app-user-dev)
|
|
362
|
+
// stay valid; the migrations service has a parallel shell preflight
|
|
363
|
+
// (scripts/check-selfhost-secrets.sh) since it never loads this schema.
|
|
364
|
+
if (env.NODE_ENV === 'production') {
|
|
365
|
+
const reason = weakDatabasePasswordReason(databasePassword(env.DATABASE_URL));
|
|
366
|
+
if (reason) {
|
|
367
|
+
ctx.addIssue({
|
|
368
|
+
code: 'custom',
|
|
369
|
+
path: ['DATABASE_URL'],
|
|
370
|
+
message: `DATABASE_URL password ${reason}; set a strong, URL-safe app_user password (e.g. openssl rand -hex 32) in .env.selfhost (issue #452)`,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (env.NODE_ENV === 'production' && env.DATABASE_URL_UNPOOLED !== undefined) {
|
|
376
|
+
ctx.addIssue({
|
|
377
|
+
code: 'custom',
|
|
378
|
+
path: ['DATABASE_URL_UNPOOLED'],
|
|
379
|
+
message: 'DATABASE_URL_UNPOOLED must not be present in the production app environment; run owner migrations as a separate release step',
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
// SMTP delivery implies a web origin to link to. When SMTP_HOST + SMTP_FROM
|
|
383
|
+
// are both set the forgot-password route SENDS the reset email — but the link
|
|
384
|
+
// is built from WEB_APP_URL (the dashboard origin). With mail enabled and no
|
|
385
|
+
// WEB_APP_URL, buildResetLink() returns undefined: the token is minted, the
|
|
386
|
+
// uniform 200 returns, yet NO email is ever sent — a silent no-delivery path
|
|
387
|
+
// with no boot- or request-time signal. Cross-validate at the boundary so a
|
|
388
|
+
// mail-enabled deploy missing the web origin fails fast at boot instead.
|
|
389
|
+
if (env.SMTP_HOST !== undefined &&
|
|
390
|
+
env.SMTP_FROM !== undefined &&
|
|
391
|
+
env.WEB_APP_URL === undefined) {
|
|
392
|
+
ctx.addIssue({
|
|
393
|
+
code: 'custom',
|
|
394
|
+
path: ['WEB_APP_URL'],
|
|
395
|
+
message: 'WEB_APP_URL is required when SMTP delivery is enabled (SMTP_HOST + SMTP_FROM): the reset link is built from the dashboard origin, so without it reset emails are silently dropped (issue #267)',
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (env.AUTH_SIGNUP_ENABLED) {
|
|
399
|
+
if (env.SMTP_HOST === undefined || env.SMTP_FROM === undefined) {
|
|
400
|
+
ctx.addIssue({
|
|
401
|
+
code: 'custom',
|
|
402
|
+
path: ['AUTH_SIGNUP_ENABLED'],
|
|
403
|
+
message: 'AUTH_SIGNUP_ENABLED=true requires SMTP_HOST + SMTP_FROM so verification emails can be delivered',
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (env.WEB_APP_URL === undefined) {
|
|
407
|
+
ctx.addIssue({
|
|
408
|
+
code: 'custom',
|
|
409
|
+
path: ['WEB_APP_URL'],
|
|
410
|
+
message: 'WEB_APP_URL is required when AUTH_SIGNUP_ENABLED=true: verification links are built from the dashboard origin',
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// Validate the key array WHENEVER it is set, in any environment: a malformed
|
|
415
|
+
// OAUTH_JWKS is a boot-time error, never a deferred token-verify failure.
|
|
416
|
+
if (env.OAUTH_JWKS !== undefined) {
|
|
417
|
+
const parsed = parseOAuthJwks(env.OAUTH_JWKS);
|
|
418
|
+
if (!parsed.ok) {
|
|
419
|
+
ctx.addIssue({ code: 'custom', path: ['OAUTH_JWKS'], message: parsed.message });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
export function parseEnv(source = process.env) {
|
|
424
|
+
return envSchema.parse(source);
|
|
425
|
+
}
|
|
426
|
+
let cached;
|
|
427
|
+
/** Parse-once accessor; all runtime code reads env through this. */
|
|
428
|
+
export function loadEnv() {
|
|
429
|
+
cached ??= parseEnv();
|
|
430
|
+
return cached;
|
|
431
|
+
}
|
|
432
|
+
/** Test seam — drops the memoized env so the next loadEnv() re-parses. */
|
|
433
|
+
export function resetEnvCache() {
|
|
434
|
+
cached = undefined;
|
|
435
|
+
cachedOAuth = undefined;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Parse + validate the OAUTH_JWKS JSON string into the typed key array. Returns
|
|
439
|
+
* a tagged result rather than throwing so the env superRefine can attach a
|
|
440
|
+
* field-scoped issue (boot failure with a clear path) and loadOAuthConfig can
|
|
441
|
+
* surface a precise error.
|
|
442
|
+
*/
|
|
443
|
+
function parseOAuthJwks(raw) {
|
|
444
|
+
let json;
|
|
445
|
+
try {
|
|
446
|
+
json = JSON.parse(raw);
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
return { ok: false, message: 'OAUTH_JWKS must be a JSON array of RS256 JWKs' };
|
|
450
|
+
}
|
|
451
|
+
const result = oauthJwksSchema.safeParse(json);
|
|
452
|
+
if (!result.success) {
|
|
453
|
+
return {
|
|
454
|
+
ok: false,
|
|
455
|
+
message: 'OAUTH_JWKS must be a non-empty array of RS256 private JWKs, each with a kid',
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
return { ok: true, keys: result.data };
|
|
459
|
+
}
|
|
460
|
+
/** Normalize a base URL the same way the S4 SDK does (`new URL().href`). */
|
|
461
|
+
function normalizeIssuer(baseUrl) {
|
|
462
|
+
return new URL(baseUrl).href;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Derive the RFC 8707 resource id from BASE_URL: the MCP endpoint URL. The
|
|
466
|
+
* issuer keeps its trailing slash (normalized), the resource does not — a token
|
|
467
|
+
* `aud` must equal this exact string (ADR-0009 impl req 1).
|
|
468
|
+
*/
|
|
469
|
+
function deriveResource(baseUrl) {
|
|
470
|
+
const issuer = normalizeIssuer(baseUrl);
|
|
471
|
+
return `${issuer.replace(/\/$/, '')}${OAUTH_RESOURCE_PATH}`;
|
|
472
|
+
}
|
|
473
|
+
let cachedOAuth;
|
|
474
|
+
/**
|
|
475
|
+
* Resolve the OAuth resource-server config (issuer, resource, keys) from env.
|
|
476
|
+
* Fails fast — throws when BASE_URL or OAUTH_JWKS is missing or malformed — so
|
|
477
|
+
* the OAuth surface never serves with a half-configured key set. Memoized; the
|
|
478
|
+
* env-level validation already ran at loadEnv(), this re-derives the typed view.
|
|
479
|
+
*/
|
|
480
|
+
export function loadOAuthConfig() {
|
|
481
|
+
if (cachedOAuth)
|
|
482
|
+
return cachedOAuth;
|
|
483
|
+
const env = loadEnv();
|
|
484
|
+
if (env.BASE_URL === undefined) {
|
|
485
|
+
throw new Error('BASE_URL is not set (ADR-0009: required for the OAuth resource server)');
|
|
486
|
+
}
|
|
487
|
+
if (env.OAUTH_JWKS === undefined) {
|
|
488
|
+
throw new Error('OAUTH_JWKS is not set (ADR-0009: required for the OAuth resource server)');
|
|
489
|
+
}
|
|
490
|
+
const parsed = parseOAuthJwks(env.OAUTH_JWKS);
|
|
491
|
+
if (!parsed.ok)
|
|
492
|
+
throw new Error(parsed.message);
|
|
493
|
+
cachedOAuth = {
|
|
494
|
+
issuer: normalizeIssuer(env.BASE_URL),
|
|
495
|
+
resource: deriveResource(env.BASE_URL),
|
|
496
|
+
keys: parsed.keys,
|
|
497
|
+
};
|
|
498
|
+
return cachedOAuth;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Resolve the embedding-gateway config IFF both the URL and the api key are set;
|
|
502
|
+
* otherwise `undefined` ("not configured"). The app uses this to decide whether
|
|
503
|
+
* to construct + inject a real embedding client — embedding is OPTIONAL, so a
|
|
504
|
+
* missing pair is not a boot error (unlike OAuth in production). Re-derived per
|
|
505
|
+
* call from the (memoized) env; no separate cache needed.
|
|
506
|
+
*/
|
|
507
|
+
export function loadLlmGatewayConfig() {
|
|
508
|
+
const env = loadEnv();
|
|
509
|
+
if (env.LLM_GATEWAY_URL === undefined || env.LLM_GATEWAY_API_KEY === undefined) {
|
|
510
|
+
return undefined;
|
|
511
|
+
}
|
|
512
|
+
return { baseUrl: env.LLM_GATEWAY_URL, apiKey: env.LLM_GATEWAY_API_KEY };
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Resolve the SMTP config IFF both SMTP_HOST and SMTP_FROM are set; otherwise
|
|
516
|
+
* `undefined` ("not configured"). SMTP is OPTIONAL by design (self-host must
|
|
517
|
+
* boot with no mail server), so a missing pair is not a boot error — the
|
|
518
|
+
* forgot-password route degrades to the documented owner-level / dev-token path.
|
|
519
|
+
* Re-derived per call from the (memoized) env; no separate cache needed.
|
|
520
|
+
*/
|
|
521
|
+
export function loadSmtpConfig() {
|
|
522
|
+
const env = loadEnv();
|
|
523
|
+
if (env.SMTP_HOST === undefined || env.SMTP_FROM === undefined) {
|
|
524
|
+
return undefined;
|
|
525
|
+
}
|
|
526
|
+
const config = { host: env.SMTP_HOST, port: env.SMTP_PORT, from: env.SMTP_FROM };
|
|
527
|
+
if (env.SMTP_USER !== undefined && env.SMTP_PASS !== undefined) {
|
|
528
|
+
config.auth = { user: env.SMTP_USER, pass: env.SMTP_PASS };
|
|
529
|
+
}
|
|
530
|
+
return config;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Resolve {@link BudgetConfig} from the (memoized) env. Always returns a value
|
|
534
|
+
* (every field has a bounded default) — budget knobs are not optional: self-host
|
|
535
|
+
* must boot with a usable cap and cycle even with nothing configured.
|
|
536
|
+
*/
|
|
537
|
+
export function loadBudgetConfig() {
|
|
538
|
+
const env = loadEnv();
|
|
539
|
+
return {
|
|
540
|
+
defaultCapUsd: env.BUDGET_DEFAULT_CAP_USD,
|
|
541
|
+
defaultWindowDays: env.BUDGET_DEFAULT_WINDOW_DAYS,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OA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AAA;IAClB,CAAC;IACD,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,CAAA;IAC5F,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAC/D,MAAM,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,SAAS,EAAE,CAAA;IAC5D,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAcD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,OAAO,EAAE,CAAA;IACrB,OAAO;QACL,aAAa,EAAE,GAAG,CAAC,sBAAsB;QACzC,iBAAiB,EAAE,GAAG,CAAC,0BAA0B;KAClD,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { bindContext, getContext, type RequestContext, requireContext, runWithContext, type Surface, } from './context.js';
|
|
2
|
+
export { type BudgetConfig, type Env, envSchema, type LlmGatewayConfig, LOG_LEVELS, loadBudgetConfig, loadEnv, loadLlmGatewayConfig, loadOAuthConfig, loadSmtpConfig, OAUTH_RESOURCE_PATH, type OAuthConfig, type OAuthJwk, parseEnv, resetEnvCache, type SmtpConfig, } from './env.js';
|
|
3
|
+
export { contextBindings, createLogger, log, logger, setLogDestination } from './logger.js';
|
|
4
|
+
export { budgetGateLookupFailure, consolidationAccepted, consolidationProposed, consolidationRejected, generationCostObserved, mcpToolCalls, mcpToolErrors, memorySuperseded, memoryWritten, rateLimitStoreFailure, searchLatencyMs, } from './metrics.js';
|
|
5
|
+
export { contentDigest, debugContentEnabled, hashUserId, REDACTED, REDACTED_FIELDS, redactDeep, } from './redaction.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
export { bindContext, getContext, requireContext, runWithContext, } from './context.js';
|
|
3
|
+
export { envSchema, LOG_LEVELS, loadBudgetConfig, loadEnv, loadLlmGatewayConfig, loadOAuthConfig, loadSmtpConfig, OAUTH_RESOURCE_PATH, parseEnv, resetEnvCache, } from './env.js';
|
|
4
|
+
export { contextBindings, createLogger, log, logger, setLogDestination } from './logger.js';
|
|
5
|
+
// otel.ts is intentionally NOT re-exported: importing it has SDK side effects.
|
|
6
|
+
// Apps import '@3ngram/config/otel' first in their entrypoint.
|
|
7
|
+
export { budgetGateLookupFailure, consolidationAccepted, consolidationProposed, consolidationRejected, generationCostObserved, mcpToolCalls, mcpToolErrors, memorySuperseded, memoryWritten, rateLimitStoreFailure, searchLatencyMs, } from './metrics.js';
|
|
8
|
+
export { contentDigest, debugContentEnabled, hashUserId, REDACTED, REDACTED_FIELDS, redactDeep, } from './redaction.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EACL,WAAW,EACX,UAAU,EAEV,cAAc,EACd,cAAc,GAEf,MAAM,cAAc,CAAA;AACrB,OAAO,EAGL,SAAS,EAET,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,mBAAmB,EAGnB,QAAQ,EACR,aAAa,GAEd,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC3F,+EAA+E;AAC/E,+DAA+D;AAC/D,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,eAAe,GAChB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,gBAAgB,CAAA"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type DestinationStream, type Logger } from 'pino';
|
|
2
|
+
import { type RequestContext } from './context.js';
|
|
3
|
+
/** camelCase context → snake_case log keys, mapped once here (observability.md §1). */
|
|
4
|
+
export declare function contextBindings(ctx: RequestContext): Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Production logger config in one place; tests inject a sink to assert on the
|
|
7
|
+
* exact JSON the real config emits.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createLogger(destination?: DestinationStream): Logger;
|
|
10
|
+
/** Root logger. Prefer log() at call sites so request context rides along. */
|
|
11
|
+
export declare const logger: Logger;
|
|
12
|
+
/**
|
|
13
|
+
* Test-only seam: route every subsequent log() through `destination`. Pass
|
|
14
|
+
* undefined to restore the production root logger. Never call this in
|
|
15
|
+
* production code — it exists so a transport test can assert the structured
|
|
16
|
+
* line a handler emits via log() without a DB-backed integration harness.
|
|
17
|
+
*/
|
|
18
|
+
export declare function setLogDestination(destination?: DestinationStream): void;
|
|
19
|
+
/**
|
|
20
|
+
* The call-site API: a child logger carrying the current AsyncLocalStorage
|
|
21
|
+
* request context (request_id, surface, user_id hash, tool_name, ...).
|
|
22
|
+
* Outside a request scope it falls back to the bare root logger.
|
|
23
|
+
*/
|
|
24
|
+
export declare function log(): Logger;
|