@spfn/core 0.2.0-beta.9 → 0.3.0-beta.2
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 +1 -1
- package/README.md +467 -305
- package/dist/authz/index.d.ts +34 -0
- package/dist/authz/index.js +810 -0
- package/dist/authz/index.js.map +1 -0
- package/dist/{boss-DI1r4kTS.d.ts → boss-D16fO2oG.d.ts} +41 -1
- package/dist/cache/index.js +42 -30
- package/dist/cache/index.js.map +1 -1
- package/dist/codegen/index.d.ts +121 -13
- package/dist/codegen/index.js +212 -15
- package/dist/codegen/index.js.map +1 -1
- package/dist/config/index.d.ts +615 -6
- package/dist/config/index.js +124 -5
- package/dist/config/index.js.map +1 -1
- package/dist/contract/index.d.ts +220 -0
- package/dist/contract/index.js +558 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/db/index.d.ts +528 -85
- package/dist/db/index.js +831 -122
- package/dist/db/index.js.map +1 -1
- package/dist/define-middleware-DfDP39Nq.d.ts +167 -0
- package/dist/env/index.d.ts +26 -2
- package/dist/env/index.js +15 -5
- package/dist/env/index.js.map +1 -1
- package/dist/env/loader.d.ts +26 -19
- package/dist/env/loader.js +32 -25
- package/dist/env/loader.js.map +1 -1
- package/dist/errors/index.d.ts +10 -0
- package/dist/errors/index.js +418 -5
- package/dist/errors/index.js.map +1 -1
- package/dist/event/index.d.ts +33 -3
- package/dist/event/index.js +24 -3
- package/dist/event/index.js.map +1 -1
- package/dist/event/sse/client.d.ts +42 -3
- package/dist/event/sse/client.js +128 -45
- package/dist/event/sse/client.js.map +1 -1
- package/dist/event/sse/index.d.ts +12 -5
- package/dist/event/sse/index.js +280 -32
- package/dist/event/sse/index.js.map +1 -1
- package/dist/event/ws/client.d.ts +59 -0
- package/dist/event/ws/client.js +273 -0
- package/dist/event/ws/client.js.map +1 -0
- package/dist/event/ws/index.d.ts +94 -0
- package/dist/event/ws/index.js +272 -0
- package/dist/event/ws/index.js.map +1 -0
- package/dist/job/index.d.ts +2 -2
- package/dist/job/index.js +155 -42
- package/dist/job/index.js.map +1 -1
- package/dist/logger/index.d.ts +5 -0
- package/dist/logger/index.js +14 -0
- package/dist/logger/index.js.map +1 -1
- package/dist/middleware/index.d.ts +347 -9
- package/dist/middleware/index.js +1462 -15
- package/dist/middleware/index.js.map +1 -1
- package/dist/nextjs/index.d.ts +2 -2
- package/dist/nextjs/index.js +42 -28
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/server.d.ts +35 -51
- package/dist/nextjs/server.js +126 -60
- package/dist/nextjs/server.js.map +1 -1
- package/dist/ops/index.d.ts +152 -0
- package/dist/ops/index.js +500 -0
- package/dist/ops/index.js.map +1 -0
- package/dist/route/index.d.ts +8 -694
- package/dist/route/index.js +111 -22
- package/dist/route/index.js.map +1 -1
- package/dist/router-Qbssr11H.d.ts +676 -0
- package/dist/security/index.d.ts +83 -0
- package/dist/security/index.js +173 -0
- package/dist/security/index.js.map +1 -0
- package/dist/server/index.d.ts +491 -22
- package/dist/server/index.js +1887 -308
- package/dist/server/index.js.map +1 -1
- package/dist/token-manager-BT5EnUAR.d.ts +278 -0
- package/dist/types-2AbaW4Ie.d.ts +205 -0
- package/dist/{types-BOPTApC2.d.ts → types-9oszaJqp.d.ts} +7 -2
- package/dist/types-D1c57Ko-.d.ts +115 -0
- package/dist/types-ZQODsBft.d.ts +282 -0
- package/package.json +244 -208
- package/dist/router-Di7ENoah.d.ts +0 -151
- package/dist/types-B-e_f2dQ.d.ts +0 -121
- package/docs/cache.md +0 -133
- package/docs/codegen.md +0 -74
- package/docs/database.md +0 -346
- package/docs/entity.md +0 -539
- package/docs/env.md +0 -477
- package/docs/errors.md +0 -319
- package/docs/event.md +0 -116
- package/docs/job.md +0 -131
- package/docs/logger.md +0 -108
- package/docs/middleware.md +0 -337
- package/docs/nextjs.md +0 -241
- package/docs/repository.md +0 -496
- package/docs/route.md +0 -497
- package/docs/server.md +0 -307
package/dist/config/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineEnvSchema,
|
|
1
|
+
import { defineEnvSchema, envBoolean, envNumber, envEnum, envString, envUrl, parseRedisUrl, parsePostgresUrl, createEnvRegistry } from '@spfn/core/env';
|
|
2
2
|
|
|
3
3
|
// src/config/index.ts
|
|
4
4
|
var coreEnvSchema = defineEnvSchema({
|
|
5
5
|
// ========================================================================
|
|
6
6
|
// Core Environment
|
|
7
7
|
// ========================================================================
|
|
8
|
-
NODE_ENV: envEnum(["local", "development", "production", "test"], {
|
|
8
|
+
NODE_ENV: envEnum(["local", "development", "staging", "production", "test"], {
|
|
9
9
|
description: "Node.js runtime environment",
|
|
10
10
|
default: "local",
|
|
11
11
|
nextjs: true
|
|
@@ -42,6 +42,11 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
42
42
|
default: 10,
|
|
43
43
|
examples: [10, 20, 50]
|
|
44
44
|
}),
|
|
45
|
+
DB_POOL_READ_MAX: envNumber({
|
|
46
|
+
description: "Maximum connections for the read-replica pool. Defaults to DB_POOL_MAX. Set lower so write.max + read.max stays under the server max_connections (each process otherwise opens up to 2 \xD7 DB_POOL_MAX when a replica is configured).",
|
|
47
|
+
required: false,
|
|
48
|
+
examples: [5, 10, 20]
|
|
49
|
+
}),
|
|
45
50
|
DB_POOL_IDLE_TIMEOUT: envNumber({
|
|
46
51
|
description: "Database connection idle timeout in seconds",
|
|
47
52
|
default: 30,
|
|
@@ -124,6 +129,19 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
124
129
|
default: 3e4,
|
|
125
130
|
examples: [1e4, 3e4, 6e4]
|
|
126
131
|
}),
|
|
132
|
+
TRANSACTION_IDLE_TIMEOUT: envNumber({
|
|
133
|
+
description: "Max time (ms) a transaction may sit idle (no running query) before Postgres terminates it and reclaims the pooled connection. Guards against external I/O held inside a transaction starving the connection pool. 0 disables.",
|
|
134
|
+
default: 3e4,
|
|
135
|
+
examples: [1e4, 3e4, 0]
|
|
136
|
+
}),
|
|
137
|
+
// ========================================================================
|
|
138
|
+
// Jobs (pg-boss)
|
|
139
|
+
// ========================================================================
|
|
140
|
+
JOB_POLLING_INTERVAL_SECONDS: envNumber({
|
|
141
|
+
description: "How often each pg-boss worker polls the DB for new jobs (seconds). Lower = faster pickup, more idle SELECT load; higher = less DB chatter, slower pickup. Per-job override via job options.",
|
|
142
|
+
default: 2,
|
|
143
|
+
examples: [1, 2, 10]
|
|
144
|
+
}),
|
|
127
145
|
// ========================================================================
|
|
128
146
|
// Database - Development
|
|
129
147
|
// ========================================================================
|
|
@@ -133,6 +151,14 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
133
151
|
examples: [true, false]
|
|
134
152
|
}),
|
|
135
153
|
// ========================================================================
|
|
154
|
+
// Database - Migrations
|
|
155
|
+
// ========================================================================
|
|
156
|
+
SPFN_ALLOW_PENDING_MIGRATIONS: envBoolean({
|
|
157
|
+
description: "Start the server even when a function package or the project has migrations the database has not applied. Off by default: a server booted with pending migrations fails only at request time, as an opaque 500. The flag equivalent is `spfn dev --allow-pending-migrations`.",
|
|
158
|
+
default: false,
|
|
159
|
+
examples: [true, false]
|
|
160
|
+
}),
|
|
161
|
+
// ========================================================================
|
|
136
162
|
// Drizzle ORM
|
|
137
163
|
// ========================================================================
|
|
138
164
|
DRIZZLE_SCHEMA_PATH: envString({
|
|
@@ -204,6 +230,24 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
204
230
|
default: true,
|
|
205
231
|
examples: [true, false]
|
|
206
232
|
}),
|
|
233
|
+
CACHE_MAX_RETRIES_PER_REQUEST: envNumber({
|
|
234
|
+
description: "Max ioredis retries per command before it rejects (fail fast instead of hanging on a cache outage). ioredis default is 20.",
|
|
235
|
+
default: 3,
|
|
236
|
+
examples: [1, 3, 20]
|
|
237
|
+
}),
|
|
238
|
+
CACHE_ENABLE_OFFLINE_QUEUE: envBoolean({
|
|
239
|
+
description: "Queue commands while the cache is disconnected (true) vs reject immediately for strict fail-fast (false). Default true keeps resilience to brief blips.",
|
|
240
|
+
default: true,
|
|
241
|
+
examples: [true, false]
|
|
242
|
+
}),
|
|
243
|
+
// ========================================================================
|
|
244
|
+
// Database - Query limits
|
|
245
|
+
// ========================================================================
|
|
246
|
+
DB_MAX_ROWS: envNumber({
|
|
247
|
+
description: "Safety ceiling for rows returned by repository findMany (0 = unlimited). When >0, an unbounded query is capped and an explicit limit is clamped, guarding against accidentally loading a whole large table.",
|
|
248
|
+
default: 0,
|
|
249
|
+
examples: [0, 1e3, 1e4]
|
|
250
|
+
}),
|
|
207
251
|
// ========================================================================
|
|
208
252
|
// Server - Core
|
|
209
253
|
// ========================================================================
|
|
@@ -237,9 +281,27 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
237
281
|
examples: [3e4, 6e4, 12e4]
|
|
238
282
|
}),
|
|
239
283
|
SHUTDOWN_TIMEOUT: envNumber({
|
|
240
|
-
description: "Graceful shutdown timeout in milliseconds",
|
|
241
|
-
default:
|
|
242
|
-
examples: [
|
|
284
|
+
description: "Graceful shutdown timeout in milliseconds (must be less than k8s terminationGracePeriodSeconds minus preStop sleep, with safety margin)",
|
|
285
|
+
default: 28e4,
|
|
286
|
+
examples: [3e4, 12e4, 28e4]
|
|
287
|
+
}),
|
|
288
|
+
// ========================================================================
|
|
289
|
+
// Fetch (Node.js undici) - outbound HTTP request timeout
|
|
290
|
+
// ========================================================================
|
|
291
|
+
FETCH_CONNECT_TIMEOUT: envNumber({
|
|
292
|
+
description: "Fetch TCP connection timeout in milliseconds (time to establish socket connection to upstream server)",
|
|
293
|
+
default: 1e4,
|
|
294
|
+
examples: [5e3, 1e4, 3e4]
|
|
295
|
+
}),
|
|
296
|
+
FETCH_HEADERS_TIMEOUT: envNumber({
|
|
297
|
+
description: "Fetch headers timeout in milliseconds (time to receive response headers after request sent)",
|
|
298
|
+
default: 3e5,
|
|
299
|
+
examples: [12e4, 3e5, 6e5]
|
|
300
|
+
}),
|
|
301
|
+
FETCH_BODY_TIMEOUT: envNumber({
|
|
302
|
+
description: "Fetch body timeout in milliseconds (time between body data chunks from upstream server)",
|
|
303
|
+
default: 3e5,
|
|
304
|
+
examples: [12e4, 3e5, 6e5]
|
|
243
305
|
}),
|
|
244
306
|
// ========================================================================
|
|
245
307
|
// Next.js Integration
|
|
@@ -261,6 +323,63 @@ var coreEnvSchema = defineEnvSchema({
|
|
|
261
323
|
required: false,
|
|
262
324
|
nextjs: true,
|
|
263
325
|
examples: ["http://localhost:3790", "https://your-app.com"]
|
|
326
|
+
}),
|
|
327
|
+
RPC_PROXY_TIMEOUT: envNumber({
|
|
328
|
+
description: "RPC proxy request timeout in milliseconds (AbortController timeout for proxied requests to backend, should be shorter than FETCH_HEADERS_TIMEOUT)",
|
|
329
|
+
default: 12e4,
|
|
330
|
+
nextjs: true,
|
|
331
|
+
examples: [6e4, 12e4, 28e4]
|
|
332
|
+
}),
|
|
333
|
+
// ========================================================================
|
|
334
|
+
// Proxy → Backend trust (HMAC signing)
|
|
335
|
+
// ========================================================================
|
|
336
|
+
SPFN_PROXY_SECRET: envString({
|
|
337
|
+
description: "Shared secret for signing proxy\u2192backend requests (HMAC-SHA256). Read by BOTH processes \u2014 the Next.js proxy (to sign) and the SPFN backend (to verify) \u2014 so it belongs in .env.local (loaded by both; the backend reads it via loadEnv, Next.js reads it server-side without exposing it to the browser). Set the SAME value on both. Leave unset to disable proxy-guard signing.",
|
|
338
|
+
required: false,
|
|
339
|
+
sensitive: true,
|
|
340
|
+
nextjs: true,
|
|
341
|
+
examples: ["<32+ byte random hex>", "v2:<32+ byte random hex>"]
|
|
342
|
+
}),
|
|
343
|
+
SPFN_PROXY_SECRET_PREVIOUS: envString({
|
|
344
|
+
description: "Previous (grace) proxy keys still accepted for verification during rotation \u2014 comma-separated <keyId>:<secret>. The proxy never signs with these; they only keep requests signed with the prior key verifying until a rollout settles. Backend-only (verification), so it belongs in .env.server, NOT exposed to the Next.js process.",
|
|
345
|
+
required: false,
|
|
346
|
+
sensitive: true,
|
|
347
|
+
nextjs: false,
|
|
348
|
+
examples: ["v1:<old secret>", "v1:<old>,v0:<older>"]
|
|
349
|
+
}),
|
|
350
|
+
TRUSTED_PROXY_HOPS: envNumber({
|
|
351
|
+
description: "Number of trusted reverse proxies in front of the Next.js proxy (e.g. cloud LB + nginx = 2). Read by the proxy to extract the real client IP from the inbound X-Forwarded-For (counting from the right, which your own infra appends and a client cannot spoof) and forward it to the backend for rate limiting. Set it to your actual hop count; too low trusts a client-spoofable entry, too high collapses users behind a shared proxy IP.",
|
|
352
|
+
default: 1,
|
|
353
|
+
nextjs: true,
|
|
354
|
+
examples: [1, 2, 3]
|
|
355
|
+
}),
|
|
356
|
+
// ========================================================================
|
|
357
|
+
// Rate limiting (global default limiter)
|
|
358
|
+
// ========================================================================
|
|
359
|
+
RATE_LIMIT_MODE: envEnum(["off", "on"], {
|
|
360
|
+
description: `Global default rate limiter. "off": only routes tagged with rateLimitPolicy() are limited. "on": every named-middleware route gets the default limit too (opt out per route with .skip(['rateLimit'])). Health/SSE/WebSocket endpoints are always exempt. Overridden by defineServerConfig().rateLimit({ mode }).`,
|
|
361
|
+
default: "off"
|
|
362
|
+
}),
|
|
363
|
+
RATE_LIMIT_DEFAULT_LIMIT: envNumber({
|
|
364
|
+
description: "Max requests per window for the global default limiter (RATE_LIMIT_MODE=on), counted per route and per client IP.",
|
|
365
|
+
default: 100,
|
|
366
|
+
examples: [60, 100, 300]
|
|
367
|
+
}),
|
|
368
|
+
RATE_LIMIT_DEFAULT_WINDOW_MS: envNumber({
|
|
369
|
+
description: "Window length in milliseconds for the global default limiter.",
|
|
370
|
+
default: 6e4,
|
|
371
|
+
examples: [1e3, 6e4]
|
|
372
|
+
}),
|
|
373
|
+
RATE_LIMIT_FAIL_CLOSED: envBoolean({
|
|
374
|
+
description: "When the cache (Redis/Valkey) backing the limiter is unavailable, reject with 429 instead of counting in-process. Default false: the limiter falls back to per-process counters, so limits still apply \u2014 but the effective limit multiplies by the instance count, since each process counts alone. Set true only where a shared count is required and refusing traffic is preferable to a looser one.",
|
|
375
|
+
default: false
|
|
376
|
+
}),
|
|
377
|
+
// ========================================================================
|
|
378
|
+
// Outbound request safety (SSRF)
|
|
379
|
+
// ========================================================================
|
|
380
|
+
SAFE_FETCH_BLOCK_PRIVATE_IPS: envBoolean({
|
|
381
|
+
description: "Default for safeFetch (@spfn/core/security): block outbound requests that resolve to private/reserved IP ranges, including the cloud metadata address. Keep true in production; set false only for trusted internal-network calls in development. Overridden by defineServerConfig().outboundFetch({ blockPrivateIps }).",
|
|
382
|
+
default: true
|
|
264
383
|
})
|
|
265
384
|
});
|
|
266
385
|
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config/schema.ts","../../src/config/index.ts"],"names":[],"mappings":";;;AAsCO,IAAM,gBAAgB,eAAA,CAAgB;AAAA;AAAA;AAAA;AAAA,EAKzC,UAAU,OAAA,CAAQ,CAAC,SAAS,aAAA,EAAe,YAAA,EAAc,MAAM,CAAA,EAAY;AAAA,IACvE,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS,OAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA;AAAA;AAAA;AAAA,EAMD,cAAc,SAAA,CAAU;AAAA,IACpB,WAAA,EAAa,iCAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,SAAA,EAAW,IAAA;AAAA,IACX,SAAA,EAAW,gBAAA;AAAA,IACX,QAAA,EAAU,CAAC,kDAAkD;AAAA,GAChE,CAAA;AAAA,EAED,oBAAoB,SAAA,CAAU;AAAA,IAC1B,WAAA,EAAa,6CAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,SAAA,EAAW,IAAA;AAAA,IACX,SAAA,EAAW,gBAAA;AAAA,IACX,QAAA,EAAU,CAAC,+CAA+C;AAAA,GAC7D,CAAA;AAAA,EAED,mBAAmB,SAAA,CAAU;AAAA,IACzB,WAAA,EAAa,4CAAA;AAAA,IACb,QAAA,E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,GACjE,CAAA;AAAA,EAED,0BAA0B,MAAA,CAAO;AAAA,IAC7B,WAAA,EAAa,gDAAA;AAAA,IACb,QAAA,EAAU,IAAA;AAAA,IACV,MAAA,EAAQ,IAAA;AAAA,IACR,QAAA,EAAU,CAAC,uBAAA,EAAyB,0BAA0B;AAAA,GACjE,CAAA;AAAA,EAED,cAAc,MAAA,CAAO;AAAA,IACjB,WAAA,EAAa,+CAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IACV,MAAA,EAAQ,IAAA;AAAA,IACR,QAAA,EAAU,CAAC,uBAAA,EAAyB,sBAAsB;AAAA,GAC7D;AACL,CAAC;;;AClUM,IAAM,QAAA,GAAW,kBAAkB,aAAa;AAKhD,IAAM,GAAA,GAAM,SAAS,QAAA","file":"index.js","sourcesContent":["/**\n * Core Package Environment Variable Schema\n *\n * Centralized schema definition for all environment variables used in @spfn/core.\n * This provides type safety, validation, and documentation for environment configuration.\n *\n * @module config/schema\n */\n\nimport {\n defineEnvSchema,\n envEnum,\n envNumber,\n envBoolean,\n envUrl,\n envString,\n parsePostgresUrl,\n parseRedisUrl,\n} from '@spfn/core/env';\n\n/**\n * Core package environment variable schema\n *\n * Defines all environment variables with:\n * - Type information\n * - Default values\n * - Validation rules\n * - Documentation\n *\n * @example\n * ```typescript\n * import { coreEnvSchema } from '@spfn/core/config';\n *\n * // Access schema information\n * console.log(coreEnvSchema.DB_POOL_MAX.description);\n * console.log(coreEnvSchema.DB_POOL_MAX.default);\n * ```\n */\nexport const coreEnvSchema = defineEnvSchema({\n // ========================================================================\n // Core Environment\n // ========================================================================\n\n NODE_ENV: envEnum(['local', 'development', 'production', 'test'] as const, {\n description: 'Node.js runtime environment',\n default: 'local',\n nextjs: true,\n }),\n\n // ========================================================================\n // Database - Connection\n // ========================================================================\n\n DATABASE_URL: envString({\n description: 'Primary database connection URL',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@localhost:5432/dbname'],\n }),\n\n DATABASE_WRITE_URL: envString({\n description: 'Write database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@master:5432/dbname'],\n }),\n\n DATABASE_READ_URL: envString({\n description: 'Read database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@replica:5432/dbname'],\n }),\n\n\n // ========================================================================\n // Database - Connection Pool\n // ========================================================================\n\n DB_POOL_MAX: envNumber({\n description: 'Maximum number of database connections in pool',\n default: 10,\n examples: [10, 20, 50],\n }),\n\n DB_POOL_IDLE_TIMEOUT: envNumber({\n description: 'Database connection idle timeout in seconds',\n default: 30,\n examples: [20, 30, 60],\n }),\n\n // ========================================================================\n // Database - Retry Configuration\n // ========================================================================\n\n DB_RETRY_MAX: envNumber({\n description: 'Maximum number of database connection retry attempts',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_RETRY_INITIAL_DELAY: envNumber({\n description: 'Initial delay between database retry attempts (milliseconds)',\n default: 100,\n examples: [50, 100, 200],\n }),\n\n DB_RETRY_MAX_DELAY: envNumber({\n description: 'Maximum delay cap for database retry attempts (milliseconds)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n DB_RETRY_FACTOR: envNumber({\n description: 'Exponential backoff factor for database retry delays',\n default: 2,\n examples: [2, 1.5, 3],\n }),\n\n // ========================================================================\n // Database - Health Check\n // ========================================================================\n\n DB_HEALTH_CHECK_ENABLED: envBoolean({\n description: 'Enable periodic database health checks',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_INTERVAL: envNumber({\n description: 'Database health check interval (milliseconds)',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n DB_HEALTH_CHECK_RECONNECT: envBoolean({\n description: 'Reconnect to database on health check failure',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_MAX_RETRIES: envNumber({\n description: 'Maximum health check retry attempts before marking as failed',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_HEALTH_CHECK_RETRY_INTERVAL: envNumber({\n description: 'Interval between health check retry attempts (milliseconds)',\n default: 5000,\n examples: [5000, 10000, 15000],\n }),\n\n // ========================================================================\n // Database - Monitoring\n // ========================================================================\n\n DB_MONITORING_ENABLED: envBoolean({\n description: 'Enable database query performance monitoring',\n default: false,\n examples: [true, false],\n }),\n\n DB_MONITORING_SLOW_THRESHOLD: envNumber({\n description: 'Slow query threshold for monitoring (milliseconds)',\n default: 1000,\n examples: [500, 1000, 2000],\n }),\n\n DB_MONITORING_LOG_QUERIES: envBoolean({\n description: 'Log all database queries (not just slow queries)',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Transaction\n // ========================================================================\n\n TRANSACTION_TIMEOUT: envNumber({\n description: 'Transaction timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n // ========================================================================\n // Database - Development\n // ========================================================================\n\n DB_DEBUG_TRACE: envBoolean({\n description: 'Enable detailed debug tracing for database operations',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Drizzle ORM\n // ========================================================================\n\n DRIZZLE_SCHEMA_PATH: envString({\n description: 'Path to Drizzle schema configuration',\n required: false,\n default: './src/server/entities/config.ts',\n examples: ['./src/db/schema.ts', './src/server/entities/config.ts'],\n }),\n\n DRIZZLE_OUT_DIR: envString({\n description: 'Output directory for Drizzle migrations',\n required: false,\n default: './drizzle',\n examples: ['./drizzle', './migrations'],\n }),\n\n // ========================================================================\n // Logger - Core\n // ========================================================================\n\n SPFN_LOG_LEVEL: envEnum(['debug', 'info', 'warn', 'error', 'fatal'] as const, {\n description: 'Minimum log level to output',\n default: 'info'\n }),\n\n // ========================================================================\n // Cache (Redis/Valkey)\n // ========================================================================\n\n CACHE_URL: envString({\n description: 'Single Redis/Valkey instance URL',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://localhost:6379', 'rediss://secure.cache.com:6380'],\n }),\n\n CACHE_WRITE_URL: envString({\n description: 'Master Redis/Valkey URL for writes (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://master:6379'],\n }),\n\n CACHE_READ_URL: envString({\n description: 'Replica Redis/Valkey URL for reads (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://replica:6379'],\n }),\n\n CACHE_SENTINEL_HOSTS: envString({\n description: 'Comma-separated Redis Sentinel hosts',\n required: false,\n examples: ['sentinel1:26379,sentinel2:26379'],\n }),\n\n CACHE_CLUSTER_NODES: envString({\n description: 'Comma-separated Redis Cluster nodes',\n required: false,\n examples: ['node1:6379,node2:6379,node3:6379'],\n }),\n\n CACHE_MASTER_NAME: envString({\n description: 'Redis Sentinel master name',\n required: false,\n examples: ['mymaster'],\n }),\n\n CACHE_PASSWORD: envString({\n description: 'Redis/Valkey authentication password',\n required: false,\n sensitive: true,\n examples: ['your-redis-password'],\n }),\n\n CACHE_TLS_REJECT_UNAUTHORIZED: envBoolean({\n description: 'Verify TLS certificates for secure Redis connections',\n default: true,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Server - Core\n // ========================================================================\n\n PORT: envNumber({\n description: 'Server port number',\n default: 4000,\n examples: [3000, 4000, 8080],\n }),\n\n HOST: envString({\n description: 'Server hostname',\n default: 'localhost',\n required: false,\n examples: ['localhost', '0.0.0.0', '127.0.0.1'],\n }),\n\n // ========================================================================\n // Server - Timeout\n // ========================================================================\n\n SERVER_TIMEOUT: envNumber({\n description: 'Request timeout in milliseconds',\n default: 120000,\n examples: [60000, 120000, 300000],\n }),\n\n SERVER_KEEPALIVE_TIMEOUT: envNumber({\n description: 'Keep-alive timeout in milliseconds',\n default: 65000,\n examples: [30000, 65000, 120000],\n }),\n\n SERVER_HEADERS_TIMEOUT: envNumber({\n description: 'Headers timeout in milliseconds',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n SHUTDOWN_TIMEOUT: envNumber({\n description: 'Graceful shutdown timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n // ========================================================================\n // Next.js Integration\n // ========================================================================\n\n SPFN_API_URL: envUrl({\n description: 'SPFN API URL (used by Next.js to call backend)',\n required: true,\n nextjs: true,\n examples: ['http://localhost:8790', 'https://api.your-app.com'],\n }),\n\n NEXT_PUBLIC_SPFN_API_URL: envUrl({\n description: 'SPFN API URL (used by Next.js to call backend)',\n required: true,\n nextjs: true,\n examples: ['http://localhost:8790', 'https://api.your-app.com'],\n }),\n\n SPFN_APP_URL: envUrl({\n description: 'Next.js application URL (used by SPFN server)',\n required: false,\n nextjs: true,\n examples: ['http://localhost:3790', 'https://your-app.com'],\n }),\n});","/**\n * Core Package Configuration\n *\n * @example\n * ```typescript\n * import { registry } from '@spfn/core/config';\n *\n * const env = registry.validate();\n * console.log(env.DB_POOL_MAX);\n * ```\n *\n * @module config\n */\n\nimport { createEnvRegistry } from '@spfn/core/env';\nimport { coreEnvSchema } from './schema';\n\n/**\n * Core environment schema\n */\nexport { coreEnvSchema as envSchema } from './schema';\n\n/**\n * Environment registry\n *\n * @example\n * ```typescript\n * // Reset for testing\n * registry.reset();\n * ```\n */\nexport const registry = createEnvRegistry(coreEnvSchema);\n\n/**\n * Validated environment configuration\n */\nexport const env = registry.validate();"]}
|
|
1
|
+
{"version":3,"sources":["../../src/config/schema.ts","../../src/config/index.ts"],"names":[],"mappings":";;;AAsCO,IAAM,gBAAgB,eAAA,CAAgB;AAAA;AAAA;AAAA;AAAA,EAKzC,QAAA,EAAU,QAAQ,CAAC,OAAA,EAAS,eAAe,SAAA,EAAW,YAAA,EAAc,MAAM,CAAA,EAAY;AAAA,IAClF,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS,OAAA;AAAA,IACT,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA;AAAA;AAAA;AAAA,EAMD,cAAc,SAAA,CAAU;AAAA,IACpB,WAAA,EAAa,iCAAA;AAAA,IACb,QAAA,EAAU,KAAA;AAAA,IAC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AAA,EAAI,GAAA,EAAK,GAAG;AAAA,GAC1B,CAAA;AAAA,EAED,8BAA8B,SAAA,CAAU;AAAA,IACpC,WAAA,EAAa,+DAAA;AAAA,IACb,OAAA,EAAS,GAAA;AAAA,IACT,QAAA,EAAU,CAAC,GAAA,EAAM,GAAK;AAAA,GACzB,CAAA;AAAA,EAED,wBAAwB,UAAA,CAAW;AAAA,IAC/B,WAAA,EAAa,6YAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ,CAAA;AAAA;AAAA;AAAA;AAAA,EAMD,8BAA8B,UAAA,CAAW;AAAA,IACrC,WAAA,EAAa,0TAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACZ;AACL,CAAC;;;ACldM,IAAM,QAAA,GAAW,kBAAkB,aAAa;AAKhD,IAAM,GAAA,GAAM,SAAS,QAAA","file":"index.js","sourcesContent":["/**\n * Core Package Environment Variable Schema\n *\n * Centralized schema definition for all environment variables used in @spfn/core.\n * This provides type safety, validation, and documentation for environment configuration.\n *\n * @module config/schema\n */\n\nimport {\n defineEnvSchema,\n envEnum,\n envNumber,\n envBoolean,\n envUrl,\n envString,\n parsePostgresUrl,\n parseRedisUrl,\n} from '@spfn/core/env';\n\n/**\n * Core package environment variable schema\n *\n * Defines all environment variables with:\n * - Type information\n * - Default values\n * - Validation rules\n * - Documentation\n *\n * @example\n * ```typescript\n * import { coreEnvSchema } from '@spfn/core/config';\n *\n * // Access schema information\n * console.log(coreEnvSchema.DB_POOL_MAX.description);\n * console.log(coreEnvSchema.DB_POOL_MAX.default);\n * ```\n */\nexport const coreEnvSchema = defineEnvSchema({\n // ========================================================================\n // Core Environment\n // ========================================================================\n\n NODE_ENV: envEnum(['local', 'development', 'staging', 'production', 'test'] as const, {\n description: 'Node.js runtime environment',\n default: 'local',\n nextjs: true,\n }),\n\n // ========================================================================\n // Database - Connection\n // ========================================================================\n\n DATABASE_URL: envString({\n description: 'Primary database connection URL',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@localhost:5432/dbname'],\n }),\n\n DATABASE_WRITE_URL: envString({\n description: 'Write database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@master:5432/dbname'],\n }),\n\n DATABASE_READ_URL: envString({\n description: 'Read database URL (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parsePostgresUrl,\n examples: ['postgresql://user:password@replica:5432/dbname'],\n }),\n\n // ========================================================================\n // Database - Connection Pool\n // ========================================================================\n\n DB_POOL_MAX: envNumber({\n description: 'Maximum number of database connections in pool',\n default: 10,\n examples: [10, 20, 50],\n }),\n\n DB_POOL_READ_MAX: envNumber({\n description: 'Maximum connections for the read-replica pool. Defaults to DB_POOL_MAX. Set lower so write.max + read.max stays under the server max_connections (each process otherwise opens up to 2 × DB_POOL_MAX when a replica is configured).',\n required: false,\n examples: [5, 10, 20],\n }),\n\n DB_POOL_IDLE_TIMEOUT: envNumber({\n description: 'Database connection idle timeout in seconds',\n default: 30,\n examples: [20, 30, 60],\n }),\n\n // ========================================================================\n // Database - Retry Configuration\n // ========================================================================\n\n DB_RETRY_MAX: envNumber({\n description: 'Maximum number of database connection retry attempts',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_RETRY_INITIAL_DELAY: envNumber({\n description: 'Initial delay between database retry attempts (milliseconds)',\n default: 100,\n examples: [50, 100, 200],\n }),\n\n DB_RETRY_MAX_DELAY: envNumber({\n description: 'Maximum delay cap for database retry attempts (milliseconds)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n DB_RETRY_FACTOR: envNumber({\n description: 'Exponential backoff factor for database retry delays',\n default: 2,\n examples: [2, 1.5, 3],\n }),\n\n // ========================================================================\n // Database - Health Check\n // ========================================================================\n\n DB_HEALTH_CHECK_ENABLED: envBoolean({\n description: 'Enable periodic database health checks',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_INTERVAL: envNumber({\n description: 'Database health check interval (milliseconds)',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n DB_HEALTH_CHECK_RECONNECT: envBoolean({\n description: 'Reconnect to database on health check failure',\n default: true,\n examples: [true, false],\n }),\n\n DB_HEALTH_CHECK_MAX_RETRIES: envNumber({\n description: 'Maximum health check retry attempts before marking as failed',\n default: 3,\n examples: [3, 5, 10],\n }),\n\n DB_HEALTH_CHECK_RETRY_INTERVAL: envNumber({\n description: 'Interval between health check retry attempts (milliseconds)',\n default: 5000,\n examples: [5000, 10000, 15000],\n }),\n\n // ========================================================================\n // Database - Monitoring\n // ========================================================================\n\n DB_MONITORING_ENABLED: envBoolean({\n description: 'Enable database query performance monitoring',\n default: false,\n examples: [true, false],\n }),\n\n DB_MONITORING_SLOW_THRESHOLD: envNumber({\n description: 'Slow query threshold for monitoring (milliseconds)',\n default: 1000,\n examples: [500, 1000, 2000],\n }),\n\n DB_MONITORING_LOG_QUERIES: envBoolean({\n description: 'Log all database queries (not just slow queries)',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Transaction\n // ========================================================================\n\n TRANSACTION_TIMEOUT: envNumber({\n description: 'Transaction timeout in milliseconds',\n default: 30000,\n examples: [10000, 30000, 60000],\n }),\n\n TRANSACTION_IDLE_TIMEOUT: envNumber({\n description: 'Max time (ms) a transaction may sit idle (no running query) before Postgres terminates it and reclaims the pooled connection. Guards against external I/O held inside a transaction starving the connection pool. 0 disables.',\n default: 30000,\n examples: [10000, 30000, 0],\n }),\n\n // ========================================================================\n // Jobs (pg-boss)\n // ========================================================================\n\n JOB_POLLING_INTERVAL_SECONDS: envNumber({\n description: 'How often each pg-boss worker polls the DB for new jobs (seconds). Lower = faster pickup, more idle SELECT load; higher = less DB chatter, slower pickup. Per-job override via job options.',\n default: 2,\n examples: [1, 2, 10],\n }),\n\n // ========================================================================\n // Database - Development\n // ========================================================================\n\n DB_DEBUG_TRACE: envBoolean({\n description: 'Enable detailed debug tracing for database operations',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Migrations\n // ========================================================================\n\n SPFN_ALLOW_PENDING_MIGRATIONS: envBoolean({\n description: 'Start the server even when a function package or the project has migrations the database has not applied. Off by default: a server booted with pending migrations fails only at request time, as an opaque 500. The flag equivalent is `spfn dev --allow-pending-migrations`.',\n default: false,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Drizzle ORM\n // ========================================================================\n\n DRIZZLE_SCHEMA_PATH: envString({\n description: 'Path to Drizzle schema configuration',\n required: false,\n default: './src/server/entities/config.ts',\n examples: ['./src/db/schema.ts', './src/server/entities/config.ts'],\n }),\n\n DRIZZLE_OUT_DIR: envString({\n description: 'Output directory for Drizzle migrations',\n required: false,\n default: './drizzle',\n examples: ['./drizzle', './migrations'],\n }),\n\n // ========================================================================\n // Logger - Core\n // ========================================================================\n\n SPFN_LOG_LEVEL: envEnum(['debug', 'info', 'warn', 'error', 'fatal'] as const, {\n description: 'Minimum log level to output',\n default: 'info',\n }),\n\n // ========================================================================\n // Cache (Redis/Valkey)\n // ========================================================================\n\n CACHE_URL: envString({\n description: 'Single Redis/Valkey instance URL',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://localhost:6379', 'rediss://secure.cache.com:6380'],\n }),\n\n CACHE_WRITE_URL: envString({\n description: 'Master Redis/Valkey URL for writes (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://master:6379'],\n }),\n\n CACHE_READ_URL: envString({\n description: 'Replica Redis/Valkey URL for reads (master-replica pattern)',\n required: false,\n sensitive: true,\n validator: parseRedisUrl,\n examples: ['redis://replica:6379'],\n }),\n\n CACHE_SENTINEL_HOSTS: envString({\n description: 'Comma-separated Redis Sentinel hosts',\n required: false,\n examples: ['sentinel1:26379,sentinel2:26379'],\n }),\n\n CACHE_CLUSTER_NODES: envString({\n description: 'Comma-separated Redis Cluster nodes',\n required: false,\n examples: ['node1:6379,node2:6379,node3:6379'],\n }),\n\n CACHE_MASTER_NAME: envString({\n description: 'Redis Sentinel master name',\n required: false,\n examples: ['mymaster'],\n }),\n\n CACHE_PASSWORD: envString({\n description: 'Redis/Valkey authentication password',\n required: false,\n sensitive: true,\n examples: ['your-redis-password'],\n }),\n\n CACHE_TLS_REJECT_UNAUTHORIZED: envBoolean({\n description: 'Verify TLS certificates for secure Redis connections',\n default: true,\n examples: [true, false],\n }),\n\n CACHE_MAX_RETRIES_PER_REQUEST: envNumber({\n description: 'Max ioredis retries per command before it rejects (fail fast instead of hanging on a cache outage). ioredis default is 20.',\n default: 3,\n examples: [1, 3, 20],\n }),\n\n CACHE_ENABLE_OFFLINE_QUEUE: envBoolean({\n description: 'Queue commands while the cache is disconnected (true) vs reject immediately for strict fail-fast (false). Default true keeps resilience to brief blips.',\n default: true,\n examples: [true, false],\n }),\n\n // ========================================================================\n // Database - Query limits\n // ========================================================================\n\n DB_MAX_ROWS: envNumber({\n description: 'Safety ceiling for rows returned by repository findMany (0 = unlimited). When >0, an unbounded query is capped and an explicit limit is clamped, guarding against accidentally loading a whole large table.',\n default: 0,\n examples: [0, 1000, 10000],\n }),\n\n // ========================================================================\n // Server - Core\n // ========================================================================\n\n PORT: envNumber({\n description: 'Server port number',\n default: 4000,\n examples: [3000, 4000, 8080],\n }),\n\n HOST: envString({\n description: 'Server hostname',\n default: 'localhost',\n required: false,\n examples: ['localhost', '0.0.0.0', '127.0.0.1'],\n }),\n\n // ========================================================================\n // Server - Timeout\n // ========================================================================\n\n SERVER_TIMEOUT: envNumber({\n description: 'Request timeout in milliseconds',\n default: 120000,\n examples: [60000, 120000, 300000],\n }),\n\n SERVER_KEEPALIVE_TIMEOUT: envNumber({\n description: 'Keep-alive timeout in milliseconds',\n default: 65000,\n examples: [30000, 65000, 120000],\n }),\n\n SERVER_HEADERS_TIMEOUT: envNumber({\n description: 'Headers timeout in milliseconds',\n default: 60000,\n examples: [30000, 60000, 120000],\n }),\n\n SHUTDOWN_TIMEOUT: envNumber({\n description: 'Graceful shutdown timeout in milliseconds (must be less than k8s terminationGracePeriodSeconds minus preStop sleep, with safety margin)',\n default: 280000,\n examples: [30000, 120000, 280000],\n }),\n\n // ========================================================================\n // Fetch (Node.js undici) - outbound HTTP request timeout\n // ========================================================================\n\n FETCH_CONNECT_TIMEOUT: envNumber({\n description: 'Fetch TCP connection timeout in milliseconds (time to establish socket connection to upstream server)',\n default: 10000,\n examples: [5000, 10000, 30000],\n }),\n\n FETCH_HEADERS_TIMEOUT: envNumber({\n description: 'Fetch headers timeout in milliseconds (time to receive response headers after request sent)',\n default: 300000,\n examples: [120000, 300000, 600000],\n }),\n\n FETCH_BODY_TIMEOUT: envNumber({\n description: 'Fetch body timeout in milliseconds (time between body data chunks from upstream server)',\n default: 300000,\n examples: [120000, 300000, 600000],\n }),\n\n // ========================================================================\n // Next.js Integration\n // ========================================================================\n\n SPFN_API_URL: envUrl({\n description: 'SPFN API URL (used by Next.js to call backend)',\n required: true,\n nextjs: true,\n examples: ['http://localhost:8790', 'https://api.your-app.com'],\n }),\n\n NEXT_PUBLIC_SPFN_API_URL: envUrl({\n description: 'SPFN API URL (used by Next.js to call backend)',\n required: true,\n nextjs: true,\n examples: ['http://localhost:8790', 'https://api.your-app.com'],\n }),\n\n SPFN_APP_URL: envUrl({\n description: 'Next.js application URL (used by SPFN server)',\n required: false,\n nextjs: true,\n examples: ['http://localhost:3790', 'https://your-app.com'],\n }),\n\n RPC_PROXY_TIMEOUT: envNumber({\n description: 'RPC proxy request timeout in milliseconds (AbortController timeout for proxied requests to backend, should be shorter than FETCH_HEADERS_TIMEOUT)',\n default: 120000,\n nextjs: true,\n examples: [60000, 120000, 280000],\n }),\n\n // ========================================================================\n // Proxy → Backend trust (HMAC signing)\n // ========================================================================\n\n SPFN_PROXY_SECRET: envString({\n description: 'Shared secret for signing proxy→backend requests (HMAC-SHA256). Read by BOTH processes — the Next.js proxy (to sign) and the SPFN backend (to verify) — so it belongs in .env.local (loaded by both; the backend reads it via loadEnv, Next.js reads it server-side without exposing it to the browser). Set the SAME value on both. Leave unset to disable proxy-guard signing.',\n required: false,\n sensitive: true,\n nextjs: true,\n examples: ['<32+ byte random hex>', 'v2:<32+ byte random hex>'],\n }),\n\n SPFN_PROXY_SECRET_PREVIOUS: envString({\n description: 'Previous (grace) proxy keys still accepted for verification during rotation — comma-separated <keyId>:<secret>. The proxy never signs with these; they only keep requests signed with the prior key verifying until a rollout settles. Backend-only (verification), so it belongs in .env.server, NOT exposed to the Next.js process.',\n required: false,\n sensitive: true,\n nextjs: false,\n examples: ['v1:<old secret>', 'v1:<old>,v0:<older>'],\n }),\n\n TRUSTED_PROXY_HOPS: envNumber({\n description: 'Number of trusted reverse proxies in front of the Next.js proxy (e.g. cloud LB + nginx = 2). Read by the proxy to extract the real client IP from the inbound X-Forwarded-For (counting from the right, which your own infra appends and a client cannot spoof) and forward it to the backend for rate limiting. Set it to your actual hop count; too low trusts a client-spoofable entry, too high collapses users behind a shared proxy IP.',\n default: 1,\n nextjs: true,\n examples: [1, 2, 3],\n }),\n\n // ========================================================================\n // Rate limiting (global default limiter)\n // ========================================================================\n\n RATE_LIMIT_MODE: envEnum(['off', 'on'] as const, {\n description: 'Global default rate limiter. \"off\": only routes tagged with rateLimitPolicy() are limited. \"on\": every named-middleware route gets the default limit too (opt out per route with .skip([\\'rateLimit\\'])). Health/SSE/WebSocket endpoints are always exempt. Overridden by defineServerConfig().rateLimit({ mode }).',\n default: 'off',\n }),\n\n RATE_LIMIT_DEFAULT_LIMIT: envNumber({\n description: 'Max requests per window for the global default limiter (RATE_LIMIT_MODE=on), counted per route and per client IP.',\n default: 100,\n examples: [60, 100, 300],\n }),\n\n RATE_LIMIT_DEFAULT_WINDOW_MS: envNumber({\n description: 'Window length in milliseconds for the global default limiter.',\n default: 60000,\n examples: [1000, 60000],\n }),\n\n RATE_LIMIT_FAIL_CLOSED: envBoolean({\n description: 'When the cache (Redis/Valkey) backing the limiter is unavailable, reject with 429 instead of counting in-process. Default false: the limiter falls back to per-process counters, so limits still apply — but the effective limit multiplies by the instance count, since each process counts alone. Set true only where a shared count is required and refusing traffic is preferable to a looser one.',\n default: false,\n }),\n\n // ========================================================================\n // Outbound request safety (SSRF)\n // ========================================================================\n\n SAFE_FETCH_BLOCK_PRIVATE_IPS: envBoolean({\n description: 'Default for safeFetch (@spfn/core/security): block outbound requests that resolve to private/reserved IP ranges, including the cloud metadata address. Keep true in production; set false only for trusted internal-network calls in development. Overridden by defineServerConfig().outboundFetch({ blockPrivateIps }).',\n default: true,\n }),\n});\n","/**\n * Core Package Configuration\n *\n * @example\n * ```typescript\n * import { registry } from '@spfn/core/config';\n *\n * const env = registry.validate();\n * console.log(env.DB_POOL_MAX);\n * ```\n *\n * @module config\n */\n\nimport { createEnvRegistry } from '@spfn/core/env';\nimport { coreEnvSchema } from './schema';\n\n/**\n * Core environment schema\n */\nexport { coreEnvSchema as envSchema } from './schema';\n\n/**\n * Environment registry\n *\n * @example\n * ```typescript\n * // Reset for testing\n * registry.reset();\n * ```\n */\nexport const registry = createEnvRegistry(coreEnvSchema);\n\n/**\n * Validated environment configuration\n */\nexport const env = registry.validate();\n"]}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { R as Router } from '../router-Qbssr11H.js';
|
|
2
|
+
import { C as ContractDocument, a as ContractViolation, b as ContractOperation, c as ContractSnapshot } from '../types-D1c57Ko-.js';
|
|
3
|
+
export { d as CompatibilityPolicy, e as ContractRequest, f as ContractViolationKind, J as JsonSchema } from '../types-D1c57Ko-.js';
|
|
4
|
+
import '../define-middleware-DfDP39Nq.js';
|
|
5
|
+
import 'hono';
|
|
6
|
+
import '@sinclair/typebox';
|
|
7
|
+
import 'hono/utils/http-status';
|
|
8
|
+
import '../route/types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Contract Collection
|
|
12
|
+
*
|
|
13
|
+
* Walks a loaded router and turns every route carrying `.contract()` into a
|
|
14
|
+
* contract operation.
|
|
15
|
+
*
|
|
16
|
+
* The router is loaded and walked rather than parsed from source. Real routes
|
|
17
|
+
* build their schemas from imported values — `EmailSchema`, `FileSchema()`,
|
|
18
|
+
* `KEY_DEVICE_NAME_MAX_LENGTH` — which a source parser cannot resolve. Loading
|
|
19
|
+
* costs a module import and no infrastructure: route modules have no
|
|
20
|
+
* import-time side effects, so nothing here opens a database connection.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** Thrown when the router cannot produce a contract at all. */
|
|
24
|
+
declare class ContractCollectionError extends Error {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build the contract document from a loaded router.
|
|
29
|
+
*
|
|
30
|
+
* Routes without `.contract()` are skipped — they are not part of the promise.
|
|
31
|
+
*/
|
|
32
|
+
declare function collectContractDocument(router: Router<any>): ContractDocument;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Backward-compatibility comparison
|
|
36
|
+
*
|
|
37
|
+
* Compares the contract a build produces against the newest released snapshot.
|
|
38
|
+
*
|
|
39
|
+
* The rule that shapes everything here: **optional runs in opposite directions
|
|
40
|
+
* on the two sides.** A request is safe when the server grows more tolerant —
|
|
41
|
+
* a new optional field, a dropped field, a requirement relaxed. A response is
|
|
42
|
+
* safe when the server grows more certain — a new field, a value that used to
|
|
43
|
+
* be optional now always present. Collapsing both into one rule would
|
|
44
|
+
* necessarily get one of them backwards.
|
|
45
|
+
*
|
|
46
|
+
* | change | request | response |
|
|
47
|
+
* |-------------------------|---------|----------|
|
|
48
|
+
* | field added (optional) | pass | pass |
|
|
49
|
+
* | field added (required) | refuse | pass |
|
|
50
|
+
* | field removed | pass | refuse |
|
|
51
|
+
* | required → optional | pass | refuse |
|
|
52
|
+
* | optional → required | refuse | pass |
|
|
53
|
+
* | type changed | refuse | refuse |
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
interface DocumentComparison {
|
|
57
|
+
violations: ContractViolation[];
|
|
58
|
+
/**
|
|
59
|
+
* Operations present in the baseline and gone from the current contract.
|
|
60
|
+
*
|
|
61
|
+
* Removal is not decided here: whether an operation may go depends on
|
|
62
|
+
* whether any released app still calls it, which is a separate check.
|
|
63
|
+
*/
|
|
64
|
+
removedOperations: string[];
|
|
65
|
+
}
|
|
66
|
+
/** Compare one operation that exists on both sides. */
|
|
67
|
+
declare function compareOperation(before: ContractOperation, after: ContractOperation): ContractViolation[];
|
|
68
|
+
/**
|
|
69
|
+
* Compare a released contract against the one this build produced.
|
|
70
|
+
*
|
|
71
|
+
* Operations that are new in `after` need no check — nothing has been promised
|
|
72
|
+
* about them yet.
|
|
73
|
+
*/
|
|
74
|
+
declare function compareDocuments(before: ContractDocument, after: ContractDocument): DocumentComparison;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The gate
|
|
78
|
+
*
|
|
79
|
+
* Puts the pieces together: read the newest released snapshot, compare this
|
|
80
|
+
* build's contract against it, and decide removals against what released
|
|
81
|
+
* clients still call.
|
|
82
|
+
*
|
|
83
|
+
* Nothing released yet is a pass — with a warning. "This is the first contract"
|
|
84
|
+
* and "the release that should have written a snapshot didn't" produce the same
|
|
85
|
+
* empty directory, and only a person can tell them apart.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
interface ContractCheckResult {
|
|
89
|
+
/** Version compared against, absent when nothing is released yet. */
|
|
90
|
+
baselineVersion?: string;
|
|
91
|
+
violations: ContractViolation[];
|
|
92
|
+
/** Things a person should look at that do not stop the build. */
|
|
93
|
+
warnings: string[];
|
|
94
|
+
}
|
|
95
|
+
declare function checkContract(contractsDir: string, current: ContractDocument): ContractCheckResult;
|
|
96
|
+
/** Render violations as the message a failing build prints. */
|
|
97
|
+
declare function formatViolations(violations: ContractViolation[]): string;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Deterministic JSON
|
|
101
|
+
*
|
|
102
|
+
* The generated contract is committed and compared against what the generator
|
|
103
|
+
* produces. If key order moved between runs, "the committed file differs from
|
|
104
|
+
* the generated one" would flicker and the check would train people to ignore
|
|
105
|
+
* it. So every emitted document is written with its object keys sorted, and the
|
|
106
|
+
* digest that pins a released snapshot is taken over the same ordering with no
|
|
107
|
+
* whitespace — formatting choices never move a digest.
|
|
108
|
+
*/
|
|
109
|
+
/** Recursively sort object keys and drop `undefined` members. */
|
|
110
|
+
declare function canonicalize(value: unknown): unknown;
|
|
111
|
+
/** Compact canonical encoding — what a digest is taken over. */
|
|
112
|
+
declare function stableStringify(value: unknown): string;
|
|
113
|
+
/** Indented canonical encoding — what gets written to disk and reviewed. */
|
|
114
|
+
declare function stableStringifyPretty(value: unknown): string;
|
|
115
|
+
/** SHA-256 of the compact canonical encoding, lowercase hex. */
|
|
116
|
+
declare function stableDigest(value: unknown): string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Released snapshots
|
|
120
|
+
*
|
|
121
|
+
* `contracts/released/<version>.json` is what a version actually promised. It is
|
|
122
|
+
* written once, at release, and never touched again — the gate compares against
|
|
123
|
+
* the newest one.
|
|
124
|
+
*
|
|
125
|
+
* Comparing against the newest one alone is only sound if no release is missing
|
|
126
|
+
* a snapshot: compatibility is transitive through the chain, and a gap in the
|
|
127
|
+
* chain silently widens what passes. That is why cutting a release writes a
|
|
128
|
+
* snapshot rather than offering to.
|
|
129
|
+
*
|
|
130
|
+
* Each snapshot carries the SHA-256 of its own document, so a hand-edited
|
|
131
|
+
* snapshot fails the gate instead of quietly moving the baseline.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
declare class ContractSnapshotError extends Error {
|
|
135
|
+
constructor(message: string);
|
|
136
|
+
}
|
|
137
|
+
declare const CURRENT_FILENAME = "current.json";
|
|
138
|
+
declare const RELEASED_DIRNAME = "released";
|
|
139
|
+
declare const USAGE_DIRNAME = "usage";
|
|
140
|
+
declare function currentPath(contractsDir: string): string;
|
|
141
|
+
declare function releasedDir(contractsDir: string): string;
|
|
142
|
+
declare function usageDir(contractsDir: string): string;
|
|
143
|
+
/**
|
|
144
|
+
* Order two versions the way a release line runs.
|
|
145
|
+
*
|
|
146
|
+
* Numeric identifiers compare numerically (so 1.10.0 follows 1.9.0), and a
|
|
147
|
+
* pre-release sorts before the release it leads to.
|
|
148
|
+
*/
|
|
149
|
+
declare function compareVersions(a: string, b: string): number;
|
|
150
|
+
interface SnapshotFile {
|
|
151
|
+
version: string;
|
|
152
|
+
file: string;
|
|
153
|
+
}
|
|
154
|
+
/** Every released snapshot, oldest first. */
|
|
155
|
+
declare function listSnapshots(contractsDir: string): SnapshotFile[];
|
|
156
|
+
/** The snapshot the gate compares against, or undefined when nothing is released yet. */
|
|
157
|
+
declare function newestSnapshot(contractsDir: string): SnapshotFile | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Read a snapshot and check its digest.
|
|
160
|
+
*
|
|
161
|
+
* A mismatch means the file was edited after release. The baseline is the whole
|
|
162
|
+
* point of the gate, so an edited baseline is refused rather than trusted.
|
|
163
|
+
*/
|
|
164
|
+
declare function readSnapshot(file: string): ContractSnapshot;
|
|
165
|
+
/**
|
|
166
|
+
* Write the snapshot for a release.
|
|
167
|
+
*
|
|
168
|
+
* The version comes from the document, which took it from `.contractVersion()`
|
|
169
|
+
* on the router. The filename follows the declaration rather than being told
|
|
170
|
+
* separately what to say — a second place to state the version is a second place
|
|
171
|
+
* for it to be wrong.
|
|
172
|
+
*
|
|
173
|
+
* Refuses to overwrite: a published version's promise does not change, a
|
|
174
|
+
* mistake becomes a new version.
|
|
175
|
+
*/
|
|
176
|
+
declare function writeSnapshot(contractsDir: string, document: ContractDocument): string;
|
|
177
|
+
/** Read `contracts/current.json`. */
|
|
178
|
+
declare function readCurrentDocument(contractsDir: string): ContractDocument;
|
|
179
|
+
/** Write `contracts/current.json`. Returns true when the file changed. */
|
|
180
|
+
declare function writeCurrentDocument(contractsDir: string, document: ContractDocument): boolean;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Usage files — who still calls an operation
|
|
184
|
+
*
|
|
185
|
+
* A released app is compiled and shipped; the server cannot ask it what it
|
|
186
|
+
* calls. So each released client writes down the operations it uses, and those
|
|
187
|
+
* files are what a removal is judged against:
|
|
188
|
+
* `contracts/usage/<platform>-<appVersion>.json`.
|
|
189
|
+
*
|
|
190
|
+
* The one rule this file exists to hold: **an unreadable file and "nobody calls
|
|
191
|
+
* it" are not the same answer.** An empty scan result reading as a pass is how
|
|
192
|
+
* a removal check quietly stops checking anything. Every failure to read is a
|
|
193
|
+
* refusal that names the file.
|
|
194
|
+
*/
|
|
195
|
+
/** One released client's declared call list. */
|
|
196
|
+
interface UsageRecord {
|
|
197
|
+
platform: string;
|
|
198
|
+
appVersion: string;
|
|
199
|
+
operations: string[];
|
|
200
|
+
/** File this came from, for messages. */
|
|
201
|
+
file: string;
|
|
202
|
+
}
|
|
203
|
+
type UsageReadResult = {
|
|
204
|
+
decidable: true;
|
|
205
|
+
records: UsageRecord[];
|
|
206
|
+
} | {
|
|
207
|
+
decidable: false;
|
|
208
|
+
reason: string;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Read every usage file under `usageDir`.
|
|
212
|
+
*
|
|
213
|
+
* Returns undecidable — never an empty pass — when the directory is missing,
|
|
214
|
+
* holds no usage file, or holds one that cannot be read.
|
|
215
|
+
*/
|
|
216
|
+
declare function readUsageRecords(usageDir: string): UsageReadResult;
|
|
217
|
+
/** Which released clients still call `operation`. */
|
|
218
|
+
declare function callersOf(operation: string, records: UsageRecord[]): UsageRecord[];
|
|
219
|
+
|
|
220
|
+
export { CURRENT_FILENAME, type ContractCheckResult, ContractCollectionError, ContractDocument, ContractOperation, ContractSnapshot, ContractSnapshotError, ContractViolation, type DocumentComparison, RELEASED_DIRNAME, type SnapshotFile, USAGE_DIRNAME, type UsageReadResult, type UsageRecord, callersOf, canonicalize, checkContract, collectContractDocument, compareDocuments, compareOperation, compareVersions, currentPath, formatViolations, listSnapshots, newestSnapshot, readCurrentDocument, readSnapshot, readUsageRecords, releasedDir, stableDigest, stableStringify, stableStringifyPretty, usageDir, writeCurrentDocument, writeSnapshot };
|