@wildo-ai/saas-workers-node-lib 1.1.10 → 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.
Files changed (21) hide show
  1. package/dist/esm/index.d.ts.map +1 -1
  2. package/dist/esm/inject/models/container.d.ts.map +1 -1
  3. package/dist/esm/inject/models/service-types.d.ts.map +1 -1
  4. package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.d.ts.map +1 -1
  5. package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js +10 -4
  6. package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js.map +1 -1
  7. package/dist/esm/runtime/middlewares/worker-request-context.middleware.d.ts.map +1 -1
  8. package/dist/esm/runtime/services/define-worker-init.d.ts +4 -2
  9. package/dist/esm/runtime/services/define-worker-init.d.ts.map +1 -1
  10. package/dist/esm/runtime/services/define-worker-init.js.map +1 -1
  11. package/dist/esm/runtime/services/read-worker-bootstrap-env.d.ts.map +1 -1
  12. package/dist/esm/runtime/services/read-worker-bootstrap-env.js +3 -0
  13. package/dist/esm/runtime/services/read-worker-bootstrap-env.js.map +1 -1
  14. package/dist/esm/runtime/services/read-worker-http-surface-env.d.ts.map +1 -1
  15. package/dist/esm/runtime/services/start-worker-application.backend.service.d.ts.map +1 -1
  16. package/dist/esm/runtime/services/worker-http-server.backend.service.d.ts.map +1 -1
  17. package/package.json +5 -5
  18. package/src/runtime/middlewares/__tests__/worker-jwt-verifier.rotation-cutoff.middleware.test.ts +15 -1
  19. package/src/runtime/middlewares/worker-jwt-verifier.middleware.ts +10 -3
  20. package/src/runtime/services/define-worker-init.ts +4 -2
  21. package/src/runtime/services/read-worker-bootstrap-env.ts +3 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,iDAAiD,CAAC;AAChE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,uDAAuD,CAAC;AACtE,cAAc,sDAAsD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,iDAAiD,CAAC;AAChE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,uDAAuD,CAAC;AACtE,cAAc,sDAAsD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../../src/inject/models/container.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,4BAA4B,CAAC;AAKpC,KAAK,SAAS,GAAG,kBAAkB,CAAC;AA4CpC,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAYxE;AAED,wBAAgB,yBAAyB,IAAI,SAAS,CAErD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD"}
1
+ {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../../../src/inject/models/container.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,4BAA4B,CAAC;AAKpC,KAAK,SAAS,GAAG,kBAAkB,CAAC;AA4CpC,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAYxE;AAED,wBAAgB,yBAAyB,IAAI,SAAS,CAErD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD"}
@@ -1 +1 @@
1
- {"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["../../../../src/inject/models/service-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAC;IAC/C,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;CAC1C;AAED,eAAO,MAAM,+BAA+B,EAAE,2BAG7C,CAAC"}
1
+ {"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["../../../../../src/inject/models/service-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAC;IAC/C,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;CAC1C;AAED,eAAO,MAAM,+BAA+B,EAAE,2BAG7C,CAAC"}
@@ -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;AAG/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,CAmChB"}
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 { JwtPrivateKeys, JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
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
- const verifyOptions = JwtVerifyOptions[JwtPrivateKeys.APPLICATION_WORKER_REQUEST];
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-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,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 { JwtPrivateKeys, JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';\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 const verifyOptions = JwtVerifyOptions[JwtPrivateKeys.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);\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): 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 (!decoded || typeof decoded === 'string') {\n reject(new Error('jwt_payload_not_object'));\n return;\n }\n resolve(decoded as WorkerVerifiedJwtPayload);\n });\n });\n}\n"]}
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,gBAAgB,EAAE,MAAM,4BAA4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AE,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"worker-request-context.middleware.d.ts","sourceRoot":"","sources":["../../../../src/runtime/middlewares/worker-request-context.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,cAAc,EAAY,MAAM,SAAS,CAAC;AAI/E,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf;;;;;;eAMG;YACH,aAAa,CAAC,EAAE,MAAM,CAAC;SACxB;KACF;CACF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oCAAoC,IAAI,cAAc,CAQrE"}
1
+ {"version":3,"file":"worker-request-context.middleware.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/middlewares/worker-request-context.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,cAAc,EAAY,MAAM,SAAS,CAAC;AAI/E,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf;;;;;;eAMG;YACH,aAAa,CAAC,EAAE,MAAM,CAAC;SACxB;KACF;CACF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oCAAoC,IAAI,cAAc,CAQrE"}
@@ -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
- * per Q3 LOCKED.
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;;;;OAIG;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
+ {"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,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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":"AA0FA,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 * per Q3 LOCKED.\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
+ {"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,CAmCpB"}
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;IAEpF,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\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"]}
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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"read-worker-http-surface-env.d.ts","sourceRoot":"","sources":["../../../../src/runtime/services/read-worker-http-surface-env.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,4GAA4G;IAC5G,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAcD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,oBAAoB,CA0BtB"}
1
+ {"version":3,"file":"read-worker-http-surface-env.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/read-worker-http-surface-env.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,4GAA4G;IAC5G,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAcD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,oBAAoB,CA0BtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"start-worker-application.backend.service.d.ts","sourceRoot":"","sources":["../../../../src/runtime/services/start-worker-application.backend.service.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,uBAAuB,EAE5B,iCAAiC,EAClC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBACa,oCAAoC;IAS7C,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAEtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAVnC,OAAO,CAAC,iBAAiB,CAAC,CAA6B;IACvD,OAAO,CAAC,eAAe,CAAC,CAA0B;IAClD,OAAO,CAAC,YAAY,CAAC,CAAiB;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,wBAAwB,CAAS;gBAItB,qBAAqB,EAAE,iCAAiC,EAExD,gBAAgB,EAAE,8BAA8B;IAGtD,UAAU,CAAC,KAAK,EAAE;QAC7B,MAAM,EAAE,0BAA0B,CAAC;QACnC,aAAa,EAAE,MAAM,CAAC;QACtB;;;;;;WAMG;QACH,gCAAgC,EAAE,MAAM,CAAC;KAC1C,GAAG,OAAO,CAAC,IAAI,CAAC;IAkEjB;;;;;;OAMG;IACI,oBAAoB,IAAI,0BAA0B;IAIzD;;;;OAIG;IACI,kBAAkB,IAAI,uBAAuB,GAAG,SAAS;IAInD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5D;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;YASlB,gBAAgB;IAyB9B,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,eAAe;IAuBvB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,wBAAwB;IAoBhC,OAAO,CAAC,gCAAgC;CAuEzC"}
1
+ {"version":3,"file":"start-worker-application.backend.service.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/start-worker-application.backend.service.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,uBAAuB,EAE5B,iCAAiC,EAClC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBACa,oCAAoC;IAS7C,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAEtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAVnC,OAAO,CAAC,iBAAiB,CAAC,CAA6B;IACvD,OAAO,CAAC,eAAe,CAAC,CAA0B;IAClD,OAAO,CAAC,YAAY,CAAC,CAAiB;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,wBAAwB,CAAS;gBAItB,qBAAqB,EAAE,iCAAiC,EAExD,gBAAgB,EAAE,8BAA8B;IAGtD,UAAU,CAAC,KAAK,EAAE;QAC7B,MAAM,EAAE,0BAA0B,CAAC;QACnC,aAAa,EAAE,MAAM,CAAC;QACtB;;;;;;WAMG;QACH,gCAAgC,EAAE,MAAM,CAAC;KAC1C,GAAG,OAAO,CAAC,IAAI,CAAC;IAkEjB;;;;;;OAMG;IACI,oBAAoB,IAAI,0BAA0B;IAIzD;;;;OAIG;IACI,kBAAkB,IAAI,uBAAuB,GAAG,SAAS;IAInD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5D;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;YASlB,gBAAgB;IAyB9B,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,eAAe;IAuBvB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,wBAAwB;IAoBhC,OAAO,CAAC,gCAAgC;CAuEzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"worker-http-server.backend.service.d.ts","sourceRoot":"","sources":["../../../../src/runtime/services/worker-http-server.backend.service.ts"],"names":[],"mappings":"AACA,OAAgB,EAAgB,KAAK,cAAc,EAAU,MAAM,SAAS,CAAC;AAG7E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAIvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBACa,8BAA8B;IACzC,OAAO,CAAC,GAAG,CAAC,CAAU;IACtB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAEjB,UAAU,CAAC,KAAK,EAAE;QACvB,MAAM,EAAE,0BAA0B,CAAC;QACnC,eAAe,CAAC,EAAE,uBAAuB,CAAC;QAC1C,mBAAmB,EAAE,MAAM,MAAM,CAAC;QAClC,oBAAoB,CAAC,EAAE,MAAM,KAAK,CAAC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QACjG,cAAc,CAAC,EAAE,cAAc,CAAC;KACjC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgEV,SAAS,IAAI,IAAI;IAIjB,YAAY,IAAI,IAAI;IAId,QAAQ,CAAC,aAAa,GAAE,MAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBrE"}
1
+ {"version":3,"file":"worker-http-server.backend.service.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/services/worker-http-server.backend.service.ts"],"names":[],"mappings":"AACA,OAAgB,EAAgB,KAAK,cAAc,EAAU,MAAM,SAAS,CAAC;AAG7E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAIvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBACa,8BAA8B;IACzC,OAAO,CAAC,GAAG,CAAC,CAAU;IACtB,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;IAEjB,UAAU,CAAC,KAAK,EAAE;QACvB,MAAM,EAAE,0BAA0B,CAAC;QACnC,eAAe,CAAC,EAAE,uBAAuB,CAAC;QAC1C,mBAAmB,EAAE,MAAM,MAAM,CAAC;QAClC,oBAAoB,CAAC,EAAE,MAAM,KAAK,CAAC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;SAAE,CAAC,CAAC;QACjG,cAAc,CAAC,EAAE,cAAc,CAAC;KACjC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgEV,SAAS,IAAI,IAAI;IAIjB,YAAY,IAAI,IAAI;IAId,QAAQ,CAAC,aAAa,GAAE,MAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildo-ai/saas-workers-node-lib",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "Node worker runtime host boundary for Wildo SaaS applications",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Wildo AI",
@@ -30,10 +30,10 @@
30
30
  "test:watch": "vitest"
31
31
  },
32
32
  "dependencies": {
33
- "@wildo-ai/platform-config-lib": "1.1.10",
34
- "@wildo-ai/platform-core-shared": "1.1.10",
35
- "@wildo-ai/saas-backend-lib": "1.1.10",
36
- "@wildo-ai/saas-models": "1.1.10",
33
+ "@wildo-ai/platform-config-lib": "1.1.11",
34
+ "@wildo-ai/platform-core-shared": "1.1.11",
35
+ "@wildo-ai/saas-backend-lib": "1.1.11",
36
+ "@wildo-ai/saas-models": "1.1.11",
37
37
  "express": "^5.1.0",
38
38
  "helmet": "^8.1.0",
39
39
  "jsonwebtoken": "^9.0.2",
@@ -3,6 +3,7 @@ import { generateKeyPairSync } from 'node:crypto';
3
3
  import jwt from 'jsonwebtoken';
4
4
  import { afterEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
+ import { CryptoKey_Purpose, singleJwsTypeOf } from '@wildo-ai/saas-models';
6
7
  import { createWorkerJwtVerifierMiddleware } from '../worker-jwt-verifier.middleware';
7
8
 
8
9
  function generateSigningPair(): { readonly privateKey: string; readonly publicKey: string } {
@@ -13,9 +14,10 @@ function generateSigningPair(): { readonly privateKey: string; readonly publicKe
13
14
  });
14
15
  }
15
16
 
16
- function signWorkerToken(privateKey: string): string {
17
+ function signWorkerToken(privateKey: string, typ: string = singleJwsTypeOf(CryptoKey_Purpose.APPLICATION_WORKER_REQUEST)): string {
17
18
  return jwt.sign({ sub: 'worker-caller' }, privateKey, {
18
19
  algorithm: 'ES256',
20
+ header: { alg: 'ES256', typ },
19
21
  issuer: 'wildo-application',
20
22
  audience: 'APPLICATION_WORKER',
21
23
  expiresIn: '5m',
@@ -59,4 +61,16 @@ describe('worker JWT rotated-key retirement', () => {
59
61
  expect(refused.response.status).toHaveBeenCalledWith(401);
60
62
  expect(refused.response.json).toHaveBeenCalledWith({ error: 'invalid_jwt' });
61
63
  });
64
+
65
+ // #2892 — mutation: drop the typ check → a token another of the application's keys signed for another use (same
66
+ // issuer, same audience forged) is admitted by a worker holding only the worker-request public key.
67
+ it('refuses a token whose type is not the worker-request type, even under the trusted key', async () => {
68
+ const { privateKey, publicKey } = generateSigningPair();
69
+ const middleware = createWorkerJwtVerifierMiddleware({ getCurrentPublicKey: () => publicKey });
70
+ const { response } = responseDouble();
71
+ const next = vi.fn();
72
+ await middleware({ headers: { authorization: `Bearer ${signWorkerToken(privateKey, 'wildo-access+jwt')}` } } as never, response as never, next);
73
+ expect(next).not.toHaveBeenCalled();
74
+ expect(response.status).toHaveBeenCalledWith(401);
75
+ });
62
76
  });
@@ -1,6 +1,7 @@
1
1
  import type { Request, RequestHandler, Response, NextFunction } from 'express';
2
2
  import jwt from 'jsonwebtoken';
3
- import { JwtPrivateKeys, JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
3
+ import { JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
4
+ import { CryptoKey_Purpose } from '@wildo-ai/saas-models';
4
5
 
5
6
  /**
6
7
  * Per-request claims attached to the express `Request` object after the
@@ -55,7 +56,8 @@ export interface WorkerJwtVerifierFactoryInput {
55
56
  export function createWorkerJwtVerifierMiddleware(
56
57
  input: WorkerJwtVerifierFactoryInput,
57
58
  ): RequestHandler {
58
- const verifyOptions = JwtVerifyOptions[JwtPrivateKeys.APPLICATION_WORKER_REQUEST];
59
+ // The worker-request key signs nothing else, and its tokens carry their purpose's own type (#2892).
60
+ const { expectedTyp, ...verifyOptions } = JwtVerifyOptions[CryptoKey_Purpose.APPLICATION_WORKER_REQUEST];
59
61
 
60
62
  return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
61
63
  const authHeader = req.headers.authorization ?? req.headers.Authorization;
@@ -79,7 +81,7 @@ export function createWorkerJwtVerifierMiddleware(
79
81
 
80
82
  for (const candidate of candidates) {
81
83
  try {
82
- const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions);
84
+ const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions, expectedTyp);
83
85
  req.workerJwt = decoded;
84
86
  next();
85
87
  return;
@@ -95,6 +97,7 @@ function verifyOnce(
95
97
  token: string,
96
98
  publicKey: string,
97
99
  verifyOptions: jwt.VerifyOptions,
100
+ expectedTyp: string | undefined,
98
101
  ): Promise<WorkerVerifiedJwtPayload> {
99
102
  return new Promise((resolve, reject) => {
100
103
  jwt.verify(token, publicKey, verifyOptions, (err, decoded) => {
@@ -102,6 +105,10 @@ function verifyOnce(
102
105
  reject(err);
103
106
  return;
104
107
  }
108
+ if (expectedTyp !== undefined && jwt.decode(token, { complete: true })?.header?.typ !== expectedTyp) {
109
+ reject(new Error('jwt_typ_invalid'));
110
+ return;
111
+ }
105
112
  if (!decoded || typeof decoded === 'string') {
106
113
  reject(new Error('jwt_payload_not_object'));
107
114
  return;
@@ -69,8 +69,10 @@ export interface WorkerInitializationConfig {
69
69
  providerRuntime?: ProviderRuntimeArtifact | WorkerProviderRuntimeArtifact;
70
70
  /**
71
71
  * Cadence (ms) at which the worker re-polls apps-manager for the
72
- * trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh
73
- * per Q3 LOCKED.
72
+ * trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh:
73
+ * the request verifier reads the key fetched by the latest poll, so a
74
+ * rotated signing key is accepted without a worker restart. A failed
75
+ * poll keeps the previous key; omitted or `<= 0` disables re-polling.
74
76
  */
75
77
  publicKeyRefreshIntervalMs?: number;
76
78
  /**
@@ -67,6 +67,9 @@ export function readWorkerBootstrapEnv(
67
67
  ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_URL,
68
68
  );
69
69
  const applicationEnv = requireKey(ApplicationWorkerBootstrapEnvKey.APPLICATION_ENV);
70
+ // #2921 — required: the worker verifies every bootstrap answer against these keys. Read again (and parsed) by the
71
+ // bootstrap client; required here so a missing value is named with the other missing variables.
72
+ requireKey(ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_RESPONSE_VERIFICATION_KEYS);
70
73
 
71
74
  if (missingKeys.length > 0) {
72
75
  throw new Error(