@wildo-ai/saas-workers-node-lib 1.1.9 → 1.1.11
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/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.d.ts.map +1 -1
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js +10 -4
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js.map +1 -1
- package/dist/esm/runtime/services/define-worker-init.d.ts +4 -2
- package/dist/esm/runtime/services/define-worker-init.d.ts.map +1 -1
- package/dist/esm/runtime/services/define-worker-init.js.map +1 -1
- package/dist/esm/runtime/services/read-worker-bootstrap-env.d.ts.map +1 -1
- package/dist/esm/runtime/services/read-worker-bootstrap-env.js +3 -0
- package/dist/esm/runtime/services/read-worker-bootstrap-env.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/runtime/middlewares/__tests__/worker-jwt-verifier.rotation-cutoff.middleware.test.ts +15 -1
- package/src/runtime/middlewares/worker-jwt-verifier.middleware.ts +10 -3
- package/src/runtime/services/define-worker-init.ts +4 -2
- package/src/runtime/services/read-worker-bootstrap-env.ts +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-jwt-verifier.middleware.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/middlewares/worker-jwt-verifier.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,cAAc,EAA0B,MAAM,SAAS,CAAC;AAC/E,OAAO,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-jwt-verifier.middleware.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/middlewares/worker-jwt-verifier.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,cAAc,EAA0B,MAAM,SAAS,CAAC;AAC/E,OAAO,GAAG,MAAM,cAAc,CAAC;AAI/B;;;;;;;;;GASG;AACH,MAAM,WAAW,wBAAyB,SAAQ,GAAG,CAAC,UAAU;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,SAAS,CAAC,EAAE,wBAAwB,CAAC;SACtC;KACF;CACF;AAED,MAAM,WAAW,6BAA6B;IAC5C;;;;;OAKG;IACH,mBAAmB,EAAE,MAAM,MAAM,CAAC;IAClC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;CAClG;AAED;;;;;;;;GAQG;AACH,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,6BAA6B,GACnC,cAAc,CAoChB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
-
import {
|
|
2
|
+
import { JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
|
|
3
|
+
import { CryptoKey_Purpose } from '@wildo-ai/saas-models';
|
|
3
4
|
/**
|
|
4
5
|
* Factory for the worker JWT verifier middleware. Verifies inbound
|
|
5
6
|
* `Authorization: Bearer <jwt>` headers against the trusted
|
|
@@ -10,7 +11,8 @@ import { JwtPrivateKeys, JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
|
|
|
10
11
|
* bootstrap response managed by `StartWorkerApplicationBackendService`.
|
|
11
12
|
*/
|
|
12
13
|
export function createWorkerJwtVerifierMiddleware(input) {
|
|
13
|
-
|
|
14
|
+
// The worker-request key signs nothing else, and its tokens carry their purpose's own type (#2892).
|
|
15
|
+
const { expectedTyp, ...verifyOptions } = JwtVerifyOptions[CryptoKey_Purpose.APPLICATION_WORKER_REQUEST];
|
|
14
16
|
return async (req, res, next) => {
|
|
15
17
|
const authHeader = req.headers.authorization ?? req.headers.Authorization;
|
|
16
18
|
const headerValue = Array.isArray(authHeader) ? authHeader[0] : authHeader;
|
|
@@ -31,7 +33,7 @@ export function createWorkerJwtVerifierMiddleware(input) {
|
|
|
31
33
|
];
|
|
32
34
|
for (const candidate of candidates) {
|
|
33
35
|
try {
|
|
34
|
-
const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions);
|
|
36
|
+
const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions, expectedTyp);
|
|
35
37
|
req.workerJwt = decoded;
|
|
36
38
|
next();
|
|
37
39
|
return;
|
|
@@ -43,13 +45,17 @@ export function createWorkerJwtVerifierMiddleware(input) {
|
|
|
43
45
|
res.status(401).json({ error: 'invalid_jwt' });
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
|
-
function verifyOnce(token, publicKey, verifyOptions) {
|
|
48
|
+
function verifyOnce(token, publicKey, verifyOptions, expectedTyp) {
|
|
47
49
|
return new Promise((resolve, reject) => {
|
|
48
50
|
jwt.verify(token, publicKey, verifyOptions, (err, decoded) => {
|
|
49
51
|
if (err) {
|
|
50
52
|
reject(err);
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
55
|
+
if (expectedTyp !== undefined && jwt.decode(token, { complete: true })?.header?.typ !== expectedTyp) {
|
|
56
|
+
reject(new Error('jwt_typ_invalid'));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
53
59
|
if (!decoded || typeof decoded === 'string') {
|
|
54
60
|
reject(new Error('jwt_payload_not_object'));
|
|
55
61
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-jwt-verifier.middleware.js","sourceRoot":"","sources":["../../../../../src/runtime/middlewares/worker-jwt-verifier.middleware.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"worker-jwt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,OAAO;YACT,CAAC;YACD,IAAI,WAAW,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,WAAW,EAAE,CAAC;gBACpG,MAAM,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;gBACrC,OAAO;YACT,CAAC;YACD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC5C,MAAM,CAAC,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC;gBAC5C,OAAO;YACT,CAAC;YACD,OAAO,CAAC,OAAmC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Request, RequestHandler, Response, NextFunction } from 'express';\nimport jwt from 'jsonwebtoken';\nimport { JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';\nimport { CryptoKey_Purpose } from '@wildo-ai/saas-models';\n\n/**\n * Per-request claims attached to the express `Request` object after the\n * `APPLICATION_WORKER_REQUEST` JWT has been verified. The shape mirrors\n * what `jsonwebtoken.verify` decodes: framework `iat`/`exp`/`iss`/`aud`\n * fields plus whatever the backend-api stamped onto the payload.\n *\n * Worker route handlers read this via `req.workerJwt` to authorize a\n * specific call, e.g. confirming the source applicationId or correlation\n * id that the backend-api signed.\n */\nexport interface WorkerVerifiedJwtPayload extends jwt.JwtPayload {\n applicationId?: string;\n correlationId?: string;\n workerName?: string;\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Express {\n interface Request {\n workerJwt?: WorkerVerifiedJwtPayload;\n }\n }\n}\n\nexport interface WorkerJwtVerifierFactoryInput {\n /**\n * Returns the trusted `APPLICATION_WORKER_REQUEST` public key. Called\n * on every request so the JWKS-style refresh loop (managed by\n * `StartWorkerApplicationBackendService`) takes effect without\n * restarting the server.\n */\n getCurrentPublicKey: () => string;\n /**\n * Optional set of rotation public keys that are still trusted during\n * a rotation window. Each entry is tried after the current key fails.\n * Provided by the bootstrap response payload.\n */\n getRotatedPublicKeys?: () => Array<{ kid: string; publicKey: string; notAfter?: Date | string }>;\n}\n\n/**\n * Factory for the worker JWT verifier middleware. Verifies inbound\n * `Authorization: Bearer <jwt>` headers against the trusted\n * `APPLICATION_WORKER_REQUEST` public key (Q3 LOCKED — dynamic resolver).\n *\n * Independent of any DI container: takes plain functions returning the\n * current trusted key(s). The host wires those functions to the\n * bootstrap response managed by `StartWorkerApplicationBackendService`.\n */\nexport function createWorkerJwtVerifierMiddleware(\n input: WorkerJwtVerifierFactoryInput,\n): RequestHandler {\n // The worker-request key signs nothing else, and its tokens carry their purpose's own type (#2892).\n const { expectedTyp, ...verifyOptions } = JwtVerifyOptions[CryptoKey_Purpose.APPLICATION_WORKER_REQUEST];\n\n return async (req: Request, res: Response, next: NextFunction): Promise<void> => {\n const authHeader = req.headers.authorization ?? req.headers.Authorization;\n const headerValue = Array.isArray(authHeader) ? authHeader[0] : authHeader;\n if (!headerValue || typeof headerValue !== 'string' || !headerValue.startsWith('Bearer ')) {\n res.status(401).json({ error: 'missing_authorization' });\n return;\n }\n const token = headerValue.slice('Bearer '.length).trim();\n if (!token) {\n res.status(401).json({ error: 'empty_authorization_token' });\n return;\n }\n\n const candidates: Array<{ kid: string; publicKey: string }> = [\n { kid: 'current', publicKey: input.getCurrentPublicKey() },\n ...(input.getRotatedPublicKeys?.() ?? [])\n .filter((candidate) => !candidate.notAfter || new Date(candidate.notAfter).getTime() > Date.now())\n .map(({ kid, publicKey }) => ({ kid, publicKey })),\n ];\n\n for (const candidate of candidates) {\n try {\n const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions, expectedTyp);\n req.workerJwt = decoded;\n next();\n return;\n } catch {\n // try the next candidate; only emit 401 once all keys have failed\n }\n }\n res.status(401).json({ error: 'invalid_jwt' });\n };\n}\n\nfunction verifyOnce(\n token: string,\n publicKey: string,\n verifyOptions: jwt.VerifyOptions,\n expectedTyp: string | undefined,\n): Promise<WorkerVerifiedJwtPayload> {\n return new Promise((resolve, reject) => {\n jwt.verify(token, publicKey, verifyOptions, (err, decoded) => {\n if (err) {\n reject(err);\n return;\n }\n if (expectedTyp !== undefined && jwt.decode(token, { complete: true })?.header?.typ !== expectedTyp) {\n reject(new Error('jwt_typ_invalid'));\n return;\n }\n if (!decoded || typeof decoded === 'string') {\n reject(new Error('jwt_payload_not_object'));\n return;\n }\n resolve(decoded as WorkerVerifiedJwtPayload);\n });\n });\n}\n"]}
|
|
@@ -66,8 +66,10 @@ export interface WorkerInitializationConfig {
|
|
|
66
66
|
providerRuntime?: ProviderRuntimeArtifact | WorkerProviderRuntimeArtifact;
|
|
67
67
|
/**
|
|
68
68
|
* Cadence (ms) at which the worker re-polls apps-manager for the
|
|
69
|
-
* trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh
|
|
70
|
-
*
|
|
69
|
+
* trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh:
|
|
70
|
+
* the request verifier reads the key fetched by the latest poll, so a
|
|
71
|
+
* rotated signing key is accepted without a worker restart. A failed
|
|
72
|
+
* poll keeps the previous key; omitted or `<= 0` disables re-polling.
|
|
71
73
|
*/
|
|
72
74
|
publicKeyRefreshIntervalMs?: number;
|
|
73
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-worker-init.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/define-worker-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAE1E,KAAK,oBAAoB,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC7D,KAAK,sBAAsB,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAEjE,MAAM,WAAW,6BAA6B;IAC5C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,uBAAuB,CAAC,aAAa,CAAC,CAAC;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,uBAAuB,CAAC,cAAc,CAAC,CAAC;IACvD;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,uBAAuB,CAAC,wBAAwB,CAAC,CAAC;IAC3E,oFAAoF;IACpF,4BAA4B,CAAC,EAAE,uBAAuB,CAAC,8BAA8B,CAAC,CAAC;IACvF,mBAAmB,CAAC,EAAE,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;IACrE,qBAAqB,CAAC,EAAE,uBAAuB,CAAC,uBAAuB,CAAC,CAAC;IACzE,YAAY,EAAE,aAAa,CAAC;IAC5B,OAAO,EAAE,sBAAsB,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,sIAAsI;AACtI,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,qBAAqB,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,uBAAuB,EAAE,MAAM,CAAC;IAChC;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,uBAAuB,GAAG,6BAA6B,CAAC;IAC1E
|
|
1
|
+
{"version":3,"file":"define-worker-init.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/define-worker-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,c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AAM,CAAC;IAChC;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,uBAAuB,GAAG,6BAA6B,CAAC;IAC1E;;;;;;OAMG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,KAAK,IAAI,CAAC;CAC1E;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,cAAc,CAAC;IAC1B,eAAe,CAAC,EAAE,uBAAuB,CAAC;CAC3C;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,0BAA0B,GACjC,0BAA0B,CAE5B;;AACD,+DAA+D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-worker-init.js","sourceRoot":"","sources":["../../../../../src/runtime/services/define-worker-init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"define-worker-init.js","sourceRoot":"","sources":["../../../../../src/runtime/services/define-worker-init.ts"],"names":[],"mappings":"AA4FA,MAAM,UAAU,gBAAgB,CAC9B,MAAkC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC;AACD,+DAA+D","sourcesContent":["import type { Router, RequestHandler } from 'express';\nimport type { BackgroundRuntimeType } from '@wildo-ai/saas-models';\nimport type { ProviderRuntimeArtifact } from '@wildo-ai/saas-backend-lib';\n\ntype ProviderRuntimeScope = ProviderRuntimeArtifact['scope'];\ntype ProviderRuntimeModules = ProviderRuntimeArtifact['modules'];\n\nexport interface WorkerProviderRuntimeArtifact {\n __AUTOGENERATED__: string;\n generatedBy: ProviderRuntimeArtifact['generatedBy'];\n generatedAt: string;\n sourceDigest: string;\n providerRefs?: ProviderRuntimeArtifact['providerRefs'];\n /**\n * Mirrored from the engine artifact so the per-host projection can FORWARD it (#330).\n *\n * This interface is a hand-written mirror of the CLI's multi-scope artifact, so a field the\n * CLI emits and this shape omits is a field the projection can only reach through a cast —\n * which would assert, across a package boundary, the very thing nobody checked.\n */\n providerRuntimeImports?: ProviderRuntimeArtifact['providerRuntimeImports'];\n /** Mirrored for the same reason: the projection narrows and forwards it (#1672). */\n providerRuntimeAugmentations?: ProviderRuntimeArtifact['providerRuntimeAugmentations'];\n providerGraphDigest?: ProviderRuntimeArtifact['providerGraphDigest'];\n lockfileSectionDigest?: ProviderRuntimeArtifact['lockfileSectionDigest'];\n artifactKind: 'nodeWorkers';\n modules: ProviderRuntimeModules;\n scopes: Record<string, ProviderRuntimeScope>;\n}\n\n/**\n * Inputs the worker host needs to bootstrap. Intentionally minimal per KD-3\n * of `.claude/plans/minions-and-workers-implementation.md`: the worker has\n * no backing-service access (no Mongo / Redis / RabbitMQ), only:\n * - the four-env bootstrap-env-contract\n * (`APPLICATION_ID`, `PLATFORM_APPLICATION_PRIMARY_SECRET`,\n * `PLATFORM_APPS_MANAGER_URL`, `APPLICATION_ENV`), read via\n * `readWorkerBootstrapEnv()`,\n * - the worker's HTTP surface descriptor (port + paths),\n * - the apps-manager `worker-bootstrap` URL it polls for the trusted\n * `APPLICATION_WORKER_REQUEST` public key (Q3 LOCKED — dynamic resolver),\n * - the worker's identity (`workerName`, paired with\n * `APP_OWNED_SERVICE_KIND === BackgroundRuntimeType.WORKER`).\n *\n * The wider DI graph used by backend-api and minions is deliberately NOT\n * imported here — pulling it in would drag Mongo / Redis / RabbitMQ\n * services into the worker boundary and defeat the language-pluggable\n * isolation the worker kind exists to provide.\n */\n/** @wildo_source:part:start workers.node.worker-init-contract facet:layer:backend facet:family:worker facet:audience:app-developer */\nexport interface WorkerInitializationConfig {\n workerName: string;\n serviceKind: BackgroundRuntimeType.WORKER;\n http: {\n port: number;\n healthPath: string;\n readyPath: string;\n metricsPath?: string;\n };\n appsManagerBootstrapUrl: string;\n /**\n * Generated provider topology imported from the worker package's local\n * `src/generated/wildo-provider-runtime.generated.ts` module.\n *\n * Node workers receive only their own pre-scoped provider graph. Non-Node\n * workers stay on the deferred env/bootstrap delivery path and therefore do\n * not use this seam.\n */\n providerRuntime?: ProviderRuntimeArtifact | WorkerProviderRuntimeArtifact;\n /**\n * Cadence (ms) at which the worker re-polls apps-manager for the\n * trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh:\n * the request verifier reads the key fetched by the latest poll, so a\n * rotated signing key is accepted without a worker restart. A failed\n * poll keeps the previous key; omitted or `<= 0` disables re-polling.\n */\n publicKeyRefreshIntervalMs?: number;\n /**\n * Worker route registration. Called once during HTTP server install\n * with an authenticated `Router` (the JWT verifier middleware is\n * already mounted by the host) plus the verifier handle as `verifyJwt`\n * for routes that need to opt out of the default authenticated\n * pipeline.\n */\n registerRoutes?: (router: Router, deps: WorkerRouteDependencies) => void;\n}\n\nexport interface WorkerRouteDependencies {\n verifyJwt: RequestHandler;\n providerRuntime?: ProviderRuntimeArtifact;\n}\n\nexport function defineWorkerInit(\n config: WorkerInitializationConfig,\n): WorkerInitializationConfig {\n return config;\n}\n/** @wildo_source:part:end workers.node.worker-init-contract */\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-worker-bootstrap-env.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/read-worker-bootstrap-env.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,gCAAgC,EAAE,MAAM,CAAC;IACzC;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,kBAAkB,
|
|
1
|
+
{"version":3,"file":"read-worker-bootstrap-env.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/read-worker-bootstrap-env.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,gCAAgC,EAAE,MAAM,CAAC;IACzC;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,kBAAkB,CAsCpB"}
|
|
@@ -27,6 +27,9 @@ export function readWorkerBootstrapEnv(env = process.env) {
|
|
|
27
27
|
const platformApplicationPrimarySecret = requireKey(ApplicationWorkerBootstrapEnvKey.PLATFORM_APPLICATION_PRIMARY_SECRET);
|
|
28
28
|
const appsManagerUrl = requireKey(ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_URL);
|
|
29
29
|
const applicationEnv = requireKey(ApplicationWorkerBootstrapEnvKey.APPLICATION_ENV);
|
|
30
|
+
// #2921 — required: the worker verifies every bootstrap answer against these keys. Read again (and parsed) by the
|
|
31
|
+
// bootstrap client; required here so a missing value is named with the other missing variables.
|
|
32
|
+
requireKey(ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_RESPONSE_VERIFICATION_KEYS);
|
|
30
33
|
if (missingKeys.length > 0) {
|
|
31
34
|
throw new Error('[saas-workers-node-lib] Worker booted without required bootstrap env '
|
|
32
35
|
+ `var(s): ${missingKeys.join(', ')}. These are projected into the worker's `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-worker-bootstrap-env.js","sourceRoot":"","sources":["../../../../../src/runtime/services/read-worker-bootstrap-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAkClF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAyB,OAAO,CAAC,GAAG;IAEpC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,UAAU,GAAG,CAAC,GAAqC,EAAU,EAAE;QACnE,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,UAAU,CAAC,gCAAgC,CAAC,cAAc,CAAC,CAAC;IAClF,MAAM,gCAAgC,GAAG,UAAU,CACjD,gCAAgC,CAAC,mCAAmC,CACrE,CAAC;IACF,MAAM,cAAc,GAAG,UAAU,CAC/B,gCAAgC,CAAC,yBAAyB,CAC3D,CAAC;IACF,MAAM,cAAc,GAAG,UAAU,CAAC,gCAAgC,CAAC,eAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"read-worker-bootstrap-env.js","sourceRoot":"","sources":["../../../../../src/runtime/services/read-worker-bootstrap-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAkClF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAyB,OAAO,CAAC,GAAG;IAEpC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,UAAU,GAAG,CAAC,GAAqC,EAAU,EAAE;QACnE,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtB,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,UAAU,CAAC,gCAAgC,CAAC,cAAc,CAAC,CAAC;IAClF,MAAM,gCAAgC,GAAG,UAAU,CACjD,gCAAgC,CAAC,mCAAmC,CACrE,CAAC;IACF,MAAM,cAAc,GAAG,UAAU,CAC/B,gCAAgC,CAAC,yBAAyB,CAC3D,CAAC;IACF,MAAM,cAAc,GAAG,UAAU,CAAC,gCAAgC,CAAC,eAAe,CAAC,CAAC;IACpF,kHAAkH;IAClH,gGAAgG;IAChG,UAAU,CAAC,gCAAgC,CAAC,gDAAgD,CAAC,CAAC;IAE9F,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,uEAAuE;cACrE,WAAW,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,0CAA0C;cAC3E,4EAA4E;cAC5E,4EAA4E,CAC/E,CAAC;IACJ,CAAC;IAED,OAAO;QACL,aAAa;QACb,gCAAgC;QAChC,cAAc;QACd,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["import { ApplicationWorkerBootstrapEnvKey } from '@wildo-ai/platform-core-shared';\n\n/**\n * The four-env bootstrap-env-contract a Node worker needs at boot, read from\n * the process environment and validated fail-closed.\n *\n * These keys are always projected into the worker's `.env` by\n * `wildo config sync` (from `wildo.saas.config.ts`), keyed off the canonical\n * {@link ApplicationWorkerBootstrapEnvKey} enum. Reading them back through the\n * SAME enum closes the loop the backend lane already has — its\n * `ApplicationEnvConfigurationSchema` is keyed off the sibling\n * `ApplicationBackendBootstrapEnvKey`, so an emit-side rename fails to compile\n * against the read side. Workers previously re-derived these names as string\n * literals in each `index.ts`, which is exactly how a worker drifted from the\n * emitter (`APPS_MANAGER_URL` vs the emitted `PLATFORM_APPS_MANAGER_URL`).\n */\nexport interface WorkerBootstrapEnv {\n /** `APPLICATION_ID` — the caller identity forwarded to apps-manager. */\n applicationId: string;\n /**\n * `PLATFORM_APPLICATION_PRIMARY_SECRET` — paired with the application id as\n * the `x-platform-secret` header so the worker-bootstrap fetch authenticates\n * as `APP_TO_PLATFORM`.\n */\n platformApplicationPrimarySecret: string;\n /**\n * `PLATFORM_APPS_MANAGER_URL` — base URL of the apps-manager the worker polls\n * for the trusted `APPLICATION_WORKER_REQUEST` public key.\n */\n appsManagerUrl: string;\n /** `APPLICATION_ENV` — the deployment environment (`development`, `staging`, …). */\n applicationEnv: string;\n}\n\n/**\n * Read and validate the worker bootstrap-env-contract, failing closed with\n * EVERY missing key named at once (not just the first) so a misconfigured\n * `.env` surfaces in a single boot attempt.\n *\n * The worker entrypoint calls this once and threads the values into\n * {@link StartWorkerApplicationBackendService.initialize}. Keeping the read\n * here — rather than re-deriving `process.env['…']` literals in each worker's\n * `index.ts` — is what prevents the name drift this helper exists to close.\n *\n * @param env Environment source; defaults to `process.env`. Overridable so\n * tests can exercise the fail-closed path without mutating global state.\n * @throws If any of the four contract keys is missing or empty.\n */\nexport function readWorkerBootstrapEnv(\n env: NodeJS.ProcessEnv = process.env,\n): WorkerBootstrapEnv {\n const missingKeys: string[] = [];\n const requireKey = (key: ApplicationWorkerBootstrapEnvKey): string => {\n const value = env[key];\n if (!value) {\n missingKeys.push(key);\n return '';\n }\n return value;\n };\n\n const applicationId = requireKey(ApplicationWorkerBootstrapEnvKey.APPLICATION_ID);\n const platformApplicationPrimarySecret = requireKey(\n ApplicationWorkerBootstrapEnvKey.PLATFORM_APPLICATION_PRIMARY_SECRET,\n );\n const appsManagerUrl = requireKey(\n ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_URL,\n );\n const applicationEnv = requireKey(ApplicationWorkerBootstrapEnvKey.APPLICATION_ENV);\n // #2921 — required: the worker verifies every bootstrap answer against these keys. Read again (and parsed) by the\n // bootstrap client; required here so a missing value is named with the other missing variables.\n requireKey(ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_RESPONSE_VERIFICATION_KEYS);\n\n if (missingKeys.length > 0) {\n throw new Error(\n '[saas-workers-node-lib] Worker booted without required bootstrap env '\n + `var(s): ${missingKeys.join(', ')}. These are projected into the worker's `\n + '`.env` by `wildo config sync` from `wildo.saas.config.ts`; re-run it (and '\n + 'verify the `.env` is loaded into this process) before starting the worker.',\n );\n }\n\n return {\n applicationId,\n platformApplicationPrimarySecret,\n appsManagerUrl,\n applicationEnv,\n };\n}\n"]}
|