@wildo-ai/saas-workers-node-lib 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +34 -0
- package/dist/esm/index.d.ts +37 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/inject/models/container.d.ts +7 -0
- package/dist/esm/inject/models/container.d.ts.map +1 -0
- package/dist/esm/inject/models/container.js +63 -0
- package/dist/esm/inject/models/container.js.map +1 -0
- package/dist/esm/inject/models/service-types.d.ts +6 -0
- package/dist/esm/inject/models/service-types.d.ts.map +1 -0
- package/dist/esm/inject/models/service-types.js +5 -0
- package/dist/esm/inject/models/service-types.js.map +1 -0
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.d.ts +54 -0
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.d.ts.map +1 -0
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js +61 -0
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js.map +1 -0
- package/dist/esm/runtime/middlewares/worker-request-context.middleware.d.ts +35 -0
- package/dist/esm/runtime/middlewares/worker-request-context.middleware.d.ts.map +1 -0
- package/dist/esm/runtime/middlewares/worker-request-context.middleware.js +30 -0
- package/dist/esm/runtime/middlewares/worker-request-context.middleware.js.map +1 -0
- package/dist/esm/runtime/services/define-worker-init.d.ts +85 -0
- package/dist/esm/runtime/services/define-worker-init.d.ts.map +1 -0
- package/dist/esm/runtime/services/define-worker-init.js +4 -0
- package/dist/esm/runtime/services/define-worker-init.js.map +1 -0
- package/dist/esm/runtime/services/read-worker-bootstrap-env.d.ts +47 -0
- package/dist/esm/runtime/services/read-worker-bootstrap-env.d.ts.map +1 -0
- package/dist/esm/runtime/services/read-worker-bootstrap-env.js +43 -0
- package/dist/esm/runtime/services/read-worker-bootstrap-env.js.map +1 -0
- package/dist/esm/runtime/services/read-worker-http-surface-env.d.ts +42 -0
- package/dist/esm/runtime/services/read-worker-http-surface-env.d.ts.map +1 -0
- package/dist/esm/runtime/services/read-worker-http-surface-env.js +49 -0
- package/dist/esm/runtime/services/read-worker-http-surface-env.js.map +1 -0
- package/dist/esm/runtime/services/start-worker-application.backend.service.d.ts +100 -0
- package/dist/esm/runtime/services/start-worker-application.backend.service.d.ts.map +1 -0
- package/dist/esm/runtime/services/start-worker-application.backend.service.js +297 -0
- package/dist/esm/runtime/services/start-worker-application.backend.service.js.map +1 -0
- package/dist/esm/runtime/services/worker-http-server.backend.service.d.ts +56 -0
- package/dist/esm/runtime/services/worker-http-server.backend.service.d.ts.map +1 -0
- package/dist/esm/runtime/services/worker-http-server.backend.service.js +128 -0
- package/dist/esm/runtime/services/worker-http-server.backend.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +61 -0
- package/src/index.ts +36 -0
- package/src/inject/models/container.ts +76 -0
- package/src/inject/models/service-types.ts +9 -0
- package/src/runtime/middlewares/__tests__/worker-jwt-verifier.rotation-cutoff.middleware.test.ts +62 -0
- package/src/runtime/middlewares/__tests__/worker-request-context.middleware.test.ts +85 -0
- package/src/runtime/middlewares/worker-jwt-verifier.middleware.ts +112 -0
- package/src/runtime/middlewares/worker-request-context.middleware.ts +47 -0
- package/src/runtime/services/__tests__/read-worker-http-surface-env.test.ts +66 -0
- package/src/runtime/services/__tests__/start-worker-application.backend.service.test.ts +315 -0
- package/src/runtime/services/__tests__/worker-http-server.backend.service.test.ts +69 -0
- package/src/runtime/services/define-worker-init.ts +92 -0
- package/src/runtime/services/read-worker-bootstrap-env.ts +86 -0
- package/src/runtime/services/read-worker-http-surface-env.ts +84 -0
- package/src/runtime/services/start-worker-application.backend.service.ts +346 -0
- package/src/runtime/services/worker-http-server.backend.service.ts +144 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Copyright (c) 2026 P2C Consulting, s.à r.l.-S
|
|
2
|
+
RCS Luxembourg B307591
|
|
3
|
+
6C, Porte de France, L-4360 Esch-sur-Alzette, Luxembourg
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
This software and its accompanying materials (the "Software") are the
|
|
8
|
+
confidential and proprietary property of P2C Consulting, s.à r.l.-S (the
|
|
9
|
+
"Licensor"). The Software is made available for viewing only. No licence,
|
|
10
|
+
right, or permission of any kind is granted by its publication or by its
|
|
11
|
+
availability on any package registry or source repository.
|
|
12
|
+
|
|
13
|
+
Without the Licensor's prior written permission, you may not use, copy,
|
|
14
|
+
reproduce, modify, adapt, translate, merge, publish, distribute, sublicense,
|
|
15
|
+
sell, host, or create derivative works of the Software, in whole or in part,
|
|
16
|
+
nor use it to provide a service to any third party.
|
|
17
|
+
|
|
18
|
+
Publication of the Software in any public registry is for distribution to
|
|
19
|
+
authorised recipients and for technical evaluation of its packaging only. It
|
|
20
|
+
does not place the Software in the public domain, does not constitute an open
|
|
21
|
+
source release, and does not waive any right of the Licensor.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
27
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
28
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
29
|
+
|
|
30
|
+
Third-party components distributed with the Software remain governed by their
|
|
31
|
+
own licences.
|
|
32
|
+
|
|
33
|
+
Contact: P2C Consulting, s.à r.l.-S, 6C, Porte de France, L-4360
|
|
34
|
+
Esch-sur-Alzette, Luxembourg.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node worker runtime-host boundary.
|
|
3
|
+
*
|
|
4
|
+
* Owns the worker-side surface that intentionally lives OUTSIDE
|
|
5
|
+
* `saas-backend-lib` per KD-3 of
|
|
6
|
+
* `.claude/plans/minions-and-workers-implementation.md`: the worker is a
|
|
7
|
+
* stateless HTTP-only runtime with no backing-service access (Mongo /
|
|
8
|
+
* Redis / RabbitMQ MUST NOT bleed in).
|
|
9
|
+
*
|
|
10
|
+
* Current shipped surface:
|
|
11
|
+
* - `defineWorkerInit` — typed config helper for the worker entrypoint
|
|
12
|
+
* including the generated provider-runtime seam for Node workers
|
|
13
|
+
* - `setupSaasWorkerInjection` — composes the worker DI graph on top of
|
|
14
|
+
* the saas-backend bindings (JWT signer family, logger, error builder,
|
|
15
|
+
* `WildoWorkerBootstrapClientService`) without auto-connecting backing
|
|
16
|
+
* services
|
|
17
|
+
* - `StartWorkerApplicationBackendService` — wires the dynamic public-key
|
|
18
|
+
* resolver (Q3 LOCKED), prefetches the trusted public key, and
|
|
19
|
+
* schedules the JWKS-style refresh loop while selecting the current
|
|
20
|
+
* worker's generated provider scope
|
|
21
|
+
* - `WorkerHttpServerBackendService` — installs the authenticated route
|
|
22
|
+
* surface and threads the selected provider runtime into
|
|
23
|
+
* `registerRoutes(...)`
|
|
24
|
+
*
|
|
25
|
+
* Non-Node workers remain on the deferred env/bootstrap delivery track;
|
|
26
|
+
* this package only owns executable provider delivery for Node/JS/TS
|
|
27
|
+
* worker runtimes.
|
|
28
|
+
*/
|
|
29
|
+
export * from './inject/models/service-types';
|
|
30
|
+
export * from './inject/models/container';
|
|
31
|
+
export * from './runtime/services/define-worker-init';
|
|
32
|
+
export * from './runtime/services/read-worker-bootstrap-env';
|
|
33
|
+
export * from './runtime/services/read-worker-http-surface-env';
|
|
34
|
+
export * from './runtime/services/start-worker-application.backend.service';
|
|
35
|
+
export * from './runtime/services/worker-http-server.backend.service';
|
|
36
|
+
export * from './runtime/middlewares/worker-jwt-verifier.middleware';
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node worker runtime-host boundary.
|
|
3
|
+
*
|
|
4
|
+
* Owns the worker-side surface that intentionally lives OUTSIDE
|
|
5
|
+
* `saas-backend-lib` per KD-3 of
|
|
6
|
+
* `.claude/plans/minions-and-workers-implementation.md`: the worker is a
|
|
7
|
+
* stateless HTTP-only runtime with no backing-service access (Mongo /
|
|
8
|
+
* Redis / RabbitMQ MUST NOT bleed in).
|
|
9
|
+
*
|
|
10
|
+
* Current shipped surface:
|
|
11
|
+
* - `defineWorkerInit` — typed config helper for the worker entrypoint
|
|
12
|
+
* including the generated provider-runtime seam for Node workers
|
|
13
|
+
* - `setupSaasWorkerInjection` — composes the worker DI graph on top of
|
|
14
|
+
* the saas-backend bindings (JWT signer family, logger, error builder,
|
|
15
|
+
* `WildoWorkerBootstrapClientService`) without auto-connecting backing
|
|
16
|
+
* services
|
|
17
|
+
* - `StartWorkerApplicationBackendService` — wires the dynamic public-key
|
|
18
|
+
* resolver (Q3 LOCKED), prefetches the trusted public key, and
|
|
19
|
+
* schedules the JWKS-style refresh loop while selecting the current
|
|
20
|
+
* worker's generated provider scope
|
|
21
|
+
* - `WorkerHttpServerBackendService` — installs the authenticated route
|
|
22
|
+
* surface and threads the selected provider runtime into
|
|
23
|
+
* `registerRoutes(...)`
|
|
24
|
+
*
|
|
25
|
+
* Non-Node workers remain on the deferred env/bootstrap delivery track;
|
|
26
|
+
* this package only owns executable provider delivery for Node/JS/TS
|
|
27
|
+
* worker runtimes.
|
|
28
|
+
*/
|
|
29
|
+
export * from './inject/models/service-types.js';
|
|
30
|
+
export * from './inject/models/container.js';
|
|
31
|
+
export * from './runtime/services/define-worker-init.js';
|
|
32
|
+
export * from './runtime/services/read-worker-bootstrap-env.js';
|
|
33
|
+
export * from './runtime/services/read-worker-http-surface-env.js';
|
|
34
|
+
export * from './runtime/services/start-worker-application.backend.service.js';
|
|
35
|
+
export * from './runtime/services/worker-http-server.backend.service.js';
|
|
36
|
+
export * from './runtime/middlewares/worker-jwt-verifier.middleware.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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","sourcesContent":["/**\n * Node worker runtime-host boundary.\n *\n * Owns the worker-side surface that intentionally lives OUTSIDE\n * `saas-backend-lib` per KD-3 of\n * `.claude/plans/minions-and-workers-implementation.md`: the worker is a\n * stateless HTTP-only runtime with no backing-service access (Mongo /\n * Redis / RabbitMQ MUST NOT bleed in).\n *\n * Current shipped surface:\n * - `defineWorkerInit` — typed config helper for the worker entrypoint\n * including the generated provider-runtime seam for Node workers\n * - `setupSaasWorkerInjection` — composes the worker DI graph on top of\n * the saas-backend bindings (JWT signer family, logger, error builder,\n * `WildoWorkerBootstrapClientService`) without auto-connecting backing\n * services\n * - `StartWorkerApplicationBackendService` — wires the dynamic public-key\n * resolver (Q3 LOCKED), prefetches the trusted public key, and\n * schedules the JWKS-style refresh loop while selecting the current\n * worker's generated provider scope\n * - `WorkerHttpServerBackendService` — installs the authenticated route\n * surface and threads the selected provider runtime into\n * `registerRoutes(...)`\n *\n * Non-Node workers remain on the deferred env/bootstrap delivery track;\n * this package only owns executable provider delivery for Node/JS/TS\n * worker runtimes.\n */\nexport * from './inject/models/service-types';\nexport * from './inject/models/container';\nexport * from './runtime/services/define-worker-init';\nexport * from './runtime/services/read-worker-bootstrap-env';\nexport * from './runtime/services/read-worker-http-surface-env';\nexport * from './runtime/services/start-worker-application.backend.service';\nexport * from './runtime/services/worker-http-server.backend.service';\nexport * from './runtime/middlewares/worker-jwt-verifier.middleware';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type InversifyContainer } from '@wildo-ai/saas-backend-lib';
|
|
2
|
+
type Container = InversifyContainer;
|
|
3
|
+
export declare function setupSaasWorkerInjection(existing?: Container): Container;
|
|
4
|
+
export declare function getGlobalWorkersContainer(): Container;
|
|
5
|
+
export declare function resetGlobalWorkersContainer(): void;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { resetGlobalContainer, SAAS_SERVICE_TYPES, setupSaasBackendInjection, } from '@wildo-ai/saas-backend-lib';
|
|
2
|
+
import { StartWorkerApplicationBackendService } from '../../runtime/services/start-worker-application.backend.service.js';
|
|
3
|
+
import { WorkerHttpServerBackendService } from '../../runtime/services/worker-http-server.backend.service.js';
|
|
4
|
+
import { SAAS_WORKERS_NODE_SERVICE_TYPES } from './service-types.js';
|
|
5
|
+
let globalWorkersContainer;
|
|
6
|
+
/**
|
|
7
|
+
* Composes the worker DI graph on top of `setupSaasBackendInjection()`.
|
|
8
|
+
*
|
|
9
|
+
* Per KD-3 of `.claude/plans/minions-and-workers-implementation.md`, the
|
|
10
|
+
* worker boundary deliberately does NOT consume backing-service bindings
|
|
11
|
+
* (Mongo / Redis / RabbitMQ) at runtime. The shared backend container is
|
|
12
|
+
* still composed underneath because it carries the JWT signer family,
|
|
13
|
+
* the logger, the error builder, and `WildoWorkerBootstrapClientService`
|
|
14
|
+
* — all stateless services the worker host needs. Subsequent slices may
|
|
15
|
+
* shrink this composition further (e.g. by introducing a smaller
|
|
16
|
+
* "stateless-services-only" base) once the contract stabilises; today
|
|
17
|
+
* the saas-backend bindings do not auto-connect to backing services
|
|
18
|
+
* unless their `initialize()` is called, so wiring them in the container
|
|
19
|
+
* is safe at the worker boundary.
|
|
20
|
+
*/
|
|
21
|
+
class SaasWorkersNodeContainer {
|
|
22
|
+
container;
|
|
23
|
+
constructor(container) {
|
|
24
|
+
this.container = container;
|
|
25
|
+
this.bindRuntimeServices();
|
|
26
|
+
}
|
|
27
|
+
getContainer() {
|
|
28
|
+
return this.container;
|
|
29
|
+
}
|
|
30
|
+
bindRuntimeServices() {
|
|
31
|
+
if (!this.container.isBound(SAAS_WORKERS_NODE_SERVICE_TYPES.StartWorkerApplicationService)) {
|
|
32
|
+
this.container
|
|
33
|
+
.bind(SAAS_WORKERS_NODE_SERVICE_TYPES.StartWorkerApplicationService)
|
|
34
|
+
.to(StartWorkerApplicationBackendService)
|
|
35
|
+
.inSingletonScope();
|
|
36
|
+
}
|
|
37
|
+
if (!this.container.isBound(SAAS_WORKERS_NODE_SERVICE_TYPES.WorkerHttpServerService)) {
|
|
38
|
+
this.container
|
|
39
|
+
.bind(SAAS_WORKERS_NODE_SERVICE_TYPES.WorkerHttpServerService)
|
|
40
|
+
.to(WorkerHttpServerBackendService)
|
|
41
|
+
.inSingletonScope();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function setupSaasWorkerInjection(existing) {
|
|
46
|
+
const container = existing ?? globalWorkersContainer ?? setupSaasBackendInjection();
|
|
47
|
+
if (existing && !container.isBound(SAAS_SERVICE_TYPES.WildoWorkerBootstrapClientService)) {
|
|
48
|
+
throw new Error('setupSaasWorkerInjection(existing) requires a container that already includes saas-backend-lib bindings.');
|
|
49
|
+
}
|
|
50
|
+
const workersContainer = new SaasWorkersNodeContainer(container);
|
|
51
|
+
if (!existing) {
|
|
52
|
+
globalWorkersContainer = workersContainer.getContainer();
|
|
53
|
+
}
|
|
54
|
+
return workersContainer.getContainer();
|
|
55
|
+
}
|
|
56
|
+
export function getGlobalWorkersContainer() {
|
|
57
|
+
return globalWorkersContainer ?? setupSaasWorkerInjection();
|
|
58
|
+
}
|
|
59
|
+
export function resetGlobalWorkersContainer() {
|
|
60
|
+
globalWorkersContainer = undefined;
|
|
61
|
+
resetGlobalContainer();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../../src/inject/models/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oCAAoC,EAAE,MAAM,iEAAiE,CAAC;AACvH,OAAO,EAAE,8BAA8B,EAAE,MAAM,2DAA2D,CAAC;AAC3G,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAIlE,IAAI,sBAA6C,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,MAAM,wBAAwB;IACC;IAA7B,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QAC/C,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAEM,YAAY;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEO,mBAAmB;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,+BAA+B,CAAC,6BAA6B,CAAC,EAAE,CAAC;YAC3F,IAAI,CAAC,SAAS;iBACX,IAAI,CAAC,+BAA+B,CAAC,6BAA6B,CAAC;iBACnE,EAAE,CAAC,oCAAoC,CAAC;iBACxC,gBAAgB,EAAE,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,+BAA+B,CAAC,uBAAuB,CAAC,EAAE,CAAC;YACrF,IAAI,CAAC,SAAS;iBACX,IAAI,CAAC,+BAA+B,CAAC,uBAAuB,CAAC;iBAC7D,EAAE,CAAC,8BAA8B,CAAC;iBAClC,gBAAgB,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CAAC,QAAoB;IAC3D,MAAM,SAAS,GAAG,QAAQ,IAAI,sBAAsB,IAAI,yBAAyB,EAAE,CAAC;IACpF,IAAI,QAAQ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,kBAAkB,CAAC,iCAAiC,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,KAAK,CACb,0GAA0G,CAC3G,CAAC;IACJ,CAAC;IACD,MAAM,gBAAgB,GAAG,IAAI,wBAAwB,CAAC,SAAS,CAAC,CAAC;IACjE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,sBAAsB,GAAG,gBAAgB,CAAC,YAAY,EAAE,CAAC;IAC3D,CAAC;IACD,OAAO,gBAAgB,CAAC,YAAY,EAAE,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,sBAAsB,IAAI,wBAAwB,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,sBAAsB,GAAG,SAAS,CAAC;IACnC,oBAAoB,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n type InversifyContainer,\n resetGlobalContainer,\n SAAS_SERVICE_TYPES,\n setupSaasBackendInjection,\n} from '@wildo-ai/saas-backend-lib';\nimport { StartWorkerApplicationBackendService } from '../../runtime/services/start-worker-application.backend.service';\nimport { WorkerHttpServerBackendService } from '../../runtime/services/worker-http-server.backend.service';\nimport { SAAS_WORKERS_NODE_SERVICE_TYPES } from './service-types';\n\ntype Container = InversifyContainer;\n\nlet globalWorkersContainer: Container | undefined;\n\n/**\n * Composes the worker DI graph on top of `setupSaasBackendInjection()`.\n *\n * Per KD-3 of `.claude/plans/minions-and-workers-implementation.md`, the\n * worker boundary deliberately does NOT consume backing-service bindings\n * (Mongo / Redis / RabbitMQ) at runtime. The shared backend container is\n * still composed underneath because it carries the JWT signer family,\n * the logger, the error builder, and `WildoWorkerBootstrapClientService`\n * — all stateless services the worker host needs. Subsequent slices may\n * shrink this composition further (e.g. by introducing a smaller\n * \"stateless-services-only\" base) once the contract stabilises; today\n * the saas-backend bindings do not auto-connect to backing services\n * unless their `initialize()` is called, so wiring them in the container\n * is safe at the worker boundary.\n */\nclass SaasWorkersNodeContainer {\n constructor(private readonly container: Container) {\n this.bindRuntimeServices();\n }\n\n public getContainer(): Container {\n return this.container;\n }\n\n private bindRuntimeServices(): void {\n if (!this.container.isBound(SAAS_WORKERS_NODE_SERVICE_TYPES.StartWorkerApplicationService)) {\n this.container\n .bind(SAAS_WORKERS_NODE_SERVICE_TYPES.StartWorkerApplicationService)\n .to(StartWorkerApplicationBackendService)\n .inSingletonScope();\n }\n if (!this.container.isBound(SAAS_WORKERS_NODE_SERVICE_TYPES.WorkerHttpServerService)) {\n this.container\n .bind(SAAS_WORKERS_NODE_SERVICE_TYPES.WorkerHttpServerService)\n .to(WorkerHttpServerBackendService)\n .inSingletonScope();\n }\n }\n}\n\nexport function setupSaasWorkerInjection(existing?: Container): Container {\n const container = existing ?? globalWorkersContainer ?? setupSaasBackendInjection();\n if (existing && !container.isBound(SAAS_SERVICE_TYPES.WildoWorkerBootstrapClientService)) {\n throw new Error(\n 'setupSaasWorkerInjection(existing) requires a container that already includes saas-backend-lib bindings.',\n );\n }\n const workersContainer = new SaasWorkersNodeContainer(container);\n if (!existing) {\n globalWorkersContainer = workersContainer.getContainer();\n }\n return workersContainer.getContainer();\n}\n\nexport function getGlobalWorkersContainer(): Container {\n return globalWorkersContainer ?? setupSaasWorkerInjection();\n}\n\nexport function resetGlobalWorkersContainer(): void {\n globalWorkersContainer = undefined;\n resetGlobalContainer();\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface SaasWorkersNodeServiceTypes {
|
|
2
|
+
readonly StartWorkerApplicationService: symbol;
|
|
3
|
+
readonly WorkerHttpServerService: symbol;
|
|
4
|
+
}
|
|
5
|
+
export declare const SAAS_WORKERS_NODE_SERVICE_TYPES: SaasWorkersNodeServiceTypes;
|
|
6
|
+
//# sourceMappingURL=service-types.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const SAAS_WORKERS_NODE_SERVICE_TYPES = {
|
|
2
|
+
StartWorkerApplicationService: Symbol.for('SaaS.WorkersNode.StartWorkerApplicationService'),
|
|
3
|
+
WorkerHttpServerService: Symbol.for('SaaS.WorkersNode.WorkerHttpServerService'),
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=service-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-types.js","sourceRoot":"","sources":["../../../../../src/inject/models/service-types.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,+BAA+B,GAAgC;IAC1E,6BAA6B,EAAE,MAAM,CAAC,GAAG,CAAC,gDAAgD,CAAC;IAC3F,uBAAuB,EAAE,MAAM,CAAC,GAAG,CAAC,0CAA0C,CAAC;CAChF,CAAC","sourcesContent":["export interface SaasWorkersNodeServiceTypes {\n readonly StartWorkerApplicationService: symbol;\n readonly WorkerHttpServerService: symbol;\n}\n\nexport const SAAS_WORKERS_NODE_SERVICE_TYPES: SaasWorkersNodeServiceTypes = {\n StartWorkerApplicationService: Symbol.for('SaaS.WorkersNode.StartWorkerApplicationService'),\n WorkerHttpServerService: Symbol.for('SaaS.WorkersNode.WorkerHttpServerService'),\n};\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
3
|
+
/**
|
|
4
|
+
* Per-request claims attached to the express `Request` object after the
|
|
5
|
+
* `APPLICATION_WORKER_REQUEST` JWT has been verified. The shape mirrors
|
|
6
|
+
* what `jsonwebtoken.verify` decodes: framework `iat`/`exp`/`iss`/`aud`
|
|
7
|
+
* fields plus whatever the backend-api stamped onto the payload.
|
|
8
|
+
*
|
|
9
|
+
* Worker route handlers read this via `req.workerJwt` to authorize a
|
|
10
|
+
* specific call, e.g. confirming the source applicationId or correlation
|
|
11
|
+
* id that the backend-api signed.
|
|
12
|
+
*/
|
|
13
|
+
export interface WorkerVerifiedJwtPayload extends jwt.JwtPayload {
|
|
14
|
+
applicationId?: string;
|
|
15
|
+
correlationId?: string;
|
|
16
|
+
workerName?: string;
|
|
17
|
+
}
|
|
18
|
+
declare global {
|
|
19
|
+
namespace Express {
|
|
20
|
+
interface Request {
|
|
21
|
+
workerJwt?: WorkerVerifiedJwtPayload;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export interface WorkerJwtVerifierFactoryInput {
|
|
26
|
+
/**
|
|
27
|
+
* Returns the trusted `APPLICATION_WORKER_REQUEST` public key. Called
|
|
28
|
+
* on every request so the JWKS-style refresh loop (managed by
|
|
29
|
+
* `StartWorkerApplicationBackendService`) takes effect without
|
|
30
|
+
* restarting the server.
|
|
31
|
+
*/
|
|
32
|
+
getCurrentPublicKey: () => string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional set of rotation public keys that are still trusted during
|
|
35
|
+
* a rotation window. Each entry is tried after the current key fails.
|
|
36
|
+
* Provided by the bootstrap response payload.
|
|
37
|
+
*/
|
|
38
|
+
getRotatedPublicKeys?: () => Array<{
|
|
39
|
+
kid: string;
|
|
40
|
+
publicKey: string;
|
|
41
|
+
notAfter?: Date | string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Factory for the worker JWT verifier middleware. Verifies inbound
|
|
46
|
+
* `Authorization: Bearer <jwt>` headers against the trusted
|
|
47
|
+
* `APPLICATION_WORKER_REQUEST` public key (Q3 LOCKED — dynamic resolver).
|
|
48
|
+
*
|
|
49
|
+
* Independent of any DI container: takes plain functions returning the
|
|
50
|
+
* current trusted key(s). The host wires those functions to the
|
|
51
|
+
* bootstrap response managed by `StartWorkerApplicationBackendService`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createWorkerJwtVerifierMiddleware(input: WorkerJwtVerifierFactoryInput): RequestHandler;
|
|
54
|
+
//# sourceMappingURL=worker-jwt-verifier.middleware.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import { JwtPrivateKeys, JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
|
|
3
|
+
/**
|
|
4
|
+
* Factory for the worker JWT verifier middleware. Verifies inbound
|
|
5
|
+
* `Authorization: Bearer <jwt>` headers against the trusted
|
|
6
|
+
* `APPLICATION_WORKER_REQUEST` public key (Q3 LOCKED — dynamic resolver).
|
|
7
|
+
*
|
|
8
|
+
* Independent of any DI container: takes plain functions returning the
|
|
9
|
+
* current trusted key(s). The host wires those functions to the
|
|
10
|
+
* bootstrap response managed by `StartWorkerApplicationBackendService`.
|
|
11
|
+
*/
|
|
12
|
+
export function createWorkerJwtVerifierMiddleware(input) {
|
|
13
|
+
const verifyOptions = JwtVerifyOptions[JwtPrivateKeys.APPLICATION_WORKER_REQUEST];
|
|
14
|
+
return async (req, res, next) => {
|
|
15
|
+
const authHeader = req.headers.authorization ?? req.headers.Authorization;
|
|
16
|
+
const headerValue = Array.isArray(authHeader) ? authHeader[0] : authHeader;
|
|
17
|
+
if (!headerValue || typeof headerValue !== 'string' || !headerValue.startsWith('Bearer ')) {
|
|
18
|
+
res.status(401).json({ error: 'missing_authorization' });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const token = headerValue.slice('Bearer '.length).trim();
|
|
22
|
+
if (!token) {
|
|
23
|
+
res.status(401).json({ error: 'empty_authorization_token' });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const candidates = [
|
|
27
|
+
{ kid: 'current', publicKey: input.getCurrentPublicKey() },
|
|
28
|
+
...(input.getRotatedPublicKeys?.() ?? [])
|
|
29
|
+
.filter((candidate) => !candidate.notAfter || new Date(candidate.notAfter).getTime() > Date.now())
|
|
30
|
+
.map(({ kid, publicKey }) => ({ kid, publicKey })),
|
|
31
|
+
];
|
|
32
|
+
for (const candidate of candidates) {
|
|
33
|
+
try {
|
|
34
|
+
const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions);
|
|
35
|
+
req.workerJwt = decoded;
|
|
36
|
+
next();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// try the next candidate; only emit 401 once all keys have failed
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
res.status(401).json({ error: 'invalid_jwt' });
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function verifyOnce(token, publicKey, verifyOptions) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
jwt.verify(token, publicKey, verifyOptions, (err, decoded) => {
|
|
49
|
+
if (err) {
|
|
50
|
+
reject(err);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!decoded || typeof decoded === 'string') {
|
|
54
|
+
reject(new Error('jwt_payload_not_object'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
resolve(decoded);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=worker-jwt-verifier.middleware.js.map
|
|
@@ -0,0 +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,cAAc,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AA2C9E;;;;;;;;GAQG;AACH,MAAM,UAAU,iCAAiC,CAC/C,KAAoC;IAEpC,MAAM,aAAa,GAAG,gBAAgB,CAAC,cAAc,CAAC,0BAA0B,CAAC,CAAC;IAElF,OAAO,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAiB,EAAE;QAC9E,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;QAC1E,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;QAC3E,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1F,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAAC;YACzD,OAAO;QACT,CAAC;QACD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QACzD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,2BAA2B,EAAE,CAAC,CAAC;YAC7D,OAAO;QACT,CAAC;QAED,MAAM,UAAU,GAA8C;YAC5D,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,mBAAmB,EAAE,EAAE;YAC1D,GAAG,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,IAAI,EAAE,CAAC;iBACtC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;iBACjG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;SACrD,CAAC;QAEF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;gBAC5E,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC;gBACxB,IAAI,EAAE,CAAC;gBACP,OAAO;YACT,CAAC;YAAC,MAAM,CAAC;gBACP,kEAAkE;YACpE,CAAC;QACH,CAAC;QACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,KAAa,EACb,SAAiB,EACjB,aAAgC;IAEhC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;YAC3D,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,GAAG,CAAC,CAAC;gBACZ,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 { 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"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Express {
|
|
4
|
+
interface Request {
|
|
5
|
+
/**
|
|
6
|
+
* The correlation id for THIS worker dispatch, read from the `x-correlation-id` header (SD7 — the
|
|
7
|
+
* header the backend interceptor stamps, NEVER the `APPLICATION_WORKER_REQUEST` JWT `correlationId`
|
|
8
|
+
* claim). Set by {@link createWorkerRequestContextMiddleware}. The same value is carried in the
|
|
9
|
+
* ambient request-context ALS frame, so backend-lib code invoked during the dispatch logs it via
|
|
10
|
+
* the pino mixin; worker route handlers that log directly can read `req.correlationId`.
|
|
11
|
+
*/
|
|
12
|
+
correlationId?: string;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Establish the request-scoped correlation frame for an inbound worker dispatch.
|
|
18
|
+
*
|
|
19
|
+
* The backend's `RemoteClientBaseBackendService` interceptor stamps the canonical `x-correlation-id`
|
|
20
|
+
* header on every backend → worker call (Phase 6). This middleware ingests it into the request-context
|
|
21
|
+
* ALS frame — the SAME `@wildo-ai/saas-backend-lib` primitive the backend HTTP server uses in
|
|
22
|
+
* `setupRequestContext()` — so the worker's dispatch shares the DISPATCHING request's correlationId:
|
|
23
|
+
* every log line emitted by backend-lib code invoked within the dispatch (via the pino ALS mixin)
|
|
24
|
+
* carries it, and the value is mirrored onto `req.correlationId` for handlers that log directly. A fresh
|
|
25
|
+
* id is minted when the header is absent or unsafe, so an un-correlated call stays independently traceable.
|
|
26
|
+
*
|
|
27
|
+
* Per SD7 the id comes from the HEADER, not the JWT: correlation is a uniform transport concern (the same
|
|
28
|
+
* `x-correlation-id` channel used service → service), deliberately decoupled from worker authentication.
|
|
29
|
+
* The pattern — wrapping the whole downstream continuation in `runWithRequestContext(frame, () => next())`
|
|
30
|
+
* so route handlers AND the error path share one ambient frame — is pinned by the backend HTTP-seam
|
|
31
|
+
* integration test (`request-context.als.http-seam.integration.test.ts`); this worker seam is structurally
|
|
32
|
+
* identical (minus `x-frontend-service-name`, which a backend-originated dispatch never carries).
|
|
33
|
+
*/
|
|
34
|
+
export declare function createWorkerRequestContextMiddleware(): RequestHandler;
|
|
35
|
+
//# sourceMappingURL=worker-request-context.middleware.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { WildoHeaderKeys } from '@wildo-ai/saas-models';
|
|
2
|
+
import { buildRequestContextFrame, runWithRequestContext } from '@wildo-ai/saas-backend-lib';
|
|
3
|
+
/**
|
|
4
|
+
* Establish the request-scoped correlation frame for an inbound worker dispatch.
|
|
5
|
+
*
|
|
6
|
+
* The backend's `RemoteClientBaseBackendService` interceptor stamps the canonical `x-correlation-id`
|
|
7
|
+
* header on every backend → worker call (Phase 6). This middleware ingests it into the request-context
|
|
8
|
+
* ALS frame — the SAME `@wildo-ai/saas-backend-lib` primitive the backend HTTP server uses in
|
|
9
|
+
* `setupRequestContext()` — so the worker's dispatch shares the DISPATCHING request's correlationId:
|
|
10
|
+
* every log line emitted by backend-lib code invoked within the dispatch (via the pino ALS mixin)
|
|
11
|
+
* carries it, and the value is mirrored onto `req.correlationId` for handlers that log directly. A fresh
|
|
12
|
+
* id is minted when the header is absent or unsafe, so an un-correlated call stays independently traceable.
|
|
13
|
+
*
|
|
14
|
+
* Per SD7 the id comes from the HEADER, not the JWT: correlation is a uniform transport concern (the same
|
|
15
|
+
* `x-correlation-id` channel used service → service), deliberately decoupled from worker authentication.
|
|
16
|
+
* The pattern — wrapping the whole downstream continuation in `runWithRequestContext(frame, () => next())`
|
|
17
|
+
* so route handlers AND the error path share one ambient frame — is pinned by the backend HTTP-seam
|
|
18
|
+
* integration test (`request-context.als.http-seam.integration.test.ts`); this worker seam is structurally
|
|
19
|
+
* identical (minus `x-frontend-service-name`, which a backend-originated dispatch never carries).
|
|
20
|
+
*/
|
|
21
|
+
export function createWorkerRequestContextMiddleware() {
|
|
22
|
+
return (req, _res, next) => {
|
|
23
|
+
const frame = buildRequestContextFrame({
|
|
24
|
+
inboundCorrelationId: req.get(WildoHeaderKeys.CORRELATION_ID),
|
|
25
|
+
});
|
|
26
|
+
req.correlationId = frame.correlationId;
|
|
27
|
+
runWithRequestContext(frame, () => next());
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=worker-request-context.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-request-context.middleware.js","sourceRoot":"","sources":["../../../../../src/runtime/middlewares/worker-request-context.middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAkB7F;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,oCAAoC;IAClD,OAAO,CAAC,GAAY,EAAE,IAAc,EAAE,IAAkB,EAAQ,EAAE;QAChE,MAAM,KAAK,GAAG,wBAAwB,CAAC;YACrC,oBAAoB,EAAE,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,cAAc,CAAC;SAC9D,CAAC,CAAC;QACH,GAAG,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;QACxC,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { NextFunction, Request, RequestHandler, Response } from 'express';\nimport { WildoHeaderKeys } from '@wildo-ai/saas-models';\nimport { buildRequestContextFrame, runWithRequestContext } from '@wildo-ai/saas-backend-lib';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace Express {\n interface Request {\n /**\n * The correlation id for THIS worker dispatch, read from the `x-correlation-id` header (SD7 — the\n * header the backend interceptor stamps, NEVER the `APPLICATION_WORKER_REQUEST` JWT `correlationId`\n * claim). Set by {@link createWorkerRequestContextMiddleware}. The same value is carried in the\n * ambient request-context ALS frame, so backend-lib code invoked during the dispatch logs it via\n * the pino mixin; worker route handlers that log directly can read `req.correlationId`.\n */\n correlationId?: string;\n }\n }\n}\n\n/**\n * Establish the request-scoped correlation frame for an inbound worker dispatch.\n *\n * The backend's `RemoteClientBaseBackendService` interceptor stamps the canonical `x-correlation-id`\n * header on every backend → worker call (Phase 6). This middleware ingests it into the request-context\n * ALS frame — the SAME `@wildo-ai/saas-backend-lib` primitive the backend HTTP server uses in\n * `setupRequestContext()` — so the worker's dispatch shares the DISPATCHING request's correlationId:\n * every log line emitted by backend-lib code invoked within the dispatch (via the pino ALS mixin)\n * carries it, and the value is mirrored onto `req.correlationId` for handlers that log directly. A fresh\n * id is minted when the header is absent or unsafe, so an un-correlated call stays independently traceable.\n *\n * Per SD7 the id comes from the HEADER, not the JWT: correlation is a uniform transport concern (the same\n * `x-correlation-id` channel used service → service), deliberately decoupled from worker authentication.\n * The pattern — wrapping the whole downstream continuation in `runWithRequestContext(frame, () => next())`\n * so route handlers AND the error path share one ambient frame — is pinned by the backend HTTP-seam\n * integration test (`request-context.als.http-seam.integration.test.ts`); this worker seam is structurally\n * identical (minus `x-frontend-service-name`, which a backend-originated dispatch never carries).\n */\nexport function createWorkerRequestContextMiddleware(): RequestHandler {\n return (req: Request, _res: Response, next: NextFunction): void => {\n const frame = buildRequestContextFrame({\n inboundCorrelationId: req.get(WildoHeaderKeys.CORRELATION_ID),\n });\n req.correlationId = frame.correlationId;\n runWithRequestContext(frame, () => next());\n };\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Router, RequestHandler } from 'express';
|
|
2
|
+
import type { BackgroundRuntimeType } from '@wildo-ai/saas-models';
|
|
3
|
+
import type { ProviderRuntimeArtifact } from '@wildo-ai/saas-backend-lib';
|
|
4
|
+
type ProviderRuntimeScope = ProviderRuntimeArtifact['scope'];
|
|
5
|
+
type ProviderRuntimeModules = ProviderRuntimeArtifact['modules'];
|
|
6
|
+
export interface WorkerProviderRuntimeArtifact {
|
|
7
|
+
__AUTOGENERATED__: string;
|
|
8
|
+
generatedBy: ProviderRuntimeArtifact['generatedBy'];
|
|
9
|
+
generatedAt: string;
|
|
10
|
+
sourceDigest: string;
|
|
11
|
+
providerRefs?: ProviderRuntimeArtifact['providerRefs'];
|
|
12
|
+
/**
|
|
13
|
+
* Mirrored from the engine artifact so the per-host projection can FORWARD it (#330).
|
|
14
|
+
*
|
|
15
|
+
* This interface is a hand-written mirror of the CLI's multi-scope artifact, so a field the
|
|
16
|
+
* CLI emits and this shape omits is a field the projection can only reach through a cast —
|
|
17
|
+
* which would assert, across a package boundary, the very thing nobody checked.
|
|
18
|
+
*/
|
|
19
|
+
providerRuntimeImports?: ProviderRuntimeArtifact['providerRuntimeImports'];
|
|
20
|
+
providerGraphDigest?: ProviderRuntimeArtifact['providerGraphDigest'];
|
|
21
|
+
lockfileSectionDigest?: ProviderRuntimeArtifact['lockfileSectionDigest'];
|
|
22
|
+
artifactKind: 'nodeWorkers';
|
|
23
|
+
modules: ProviderRuntimeModules;
|
|
24
|
+
scopes: Record<string, ProviderRuntimeScope>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Inputs the worker host needs to bootstrap. Intentionally minimal per KD-3
|
|
28
|
+
* of `.claude/plans/minions-and-workers-implementation.md`: the worker has
|
|
29
|
+
* no backing-service access (no Mongo / Redis / RabbitMQ), only:
|
|
30
|
+
* - the four-env bootstrap-env-contract
|
|
31
|
+
* (`APPLICATION_ID`, `PLATFORM_APPLICATION_PRIMARY_SECRET`,
|
|
32
|
+
* `PLATFORM_APPS_MANAGER_URL`, `APPLICATION_ENV`), read via
|
|
33
|
+
* `readWorkerBootstrapEnv()`,
|
|
34
|
+
* - the worker's HTTP surface descriptor (port + paths),
|
|
35
|
+
* - the apps-manager `worker-bootstrap` URL it polls for the trusted
|
|
36
|
+
* `APPLICATION_WORKER_REQUEST` public key (Q3 LOCKED — dynamic resolver),
|
|
37
|
+
* - the worker's identity (`workerName`, paired with
|
|
38
|
+
* `APP_OWNED_SERVICE_KIND === BackgroundRuntimeType.WORKER`).
|
|
39
|
+
*
|
|
40
|
+
* The wider DI graph used by backend-api and minions is deliberately NOT
|
|
41
|
+
* imported here — pulling it in would drag Mongo / Redis / RabbitMQ
|
|
42
|
+
* services into the worker boundary and defeat the language-pluggable
|
|
43
|
+
* isolation the worker kind exists to provide.
|
|
44
|
+
*/
|
|
45
|
+
export interface WorkerInitializationConfig {
|
|
46
|
+
workerName: string;
|
|
47
|
+
serviceKind: BackgroundRuntimeType.WORKER;
|
|
48
|
+
http: {
|
|
49
|
+
port: number;
|
|
50
|
+
healthPath: string;
|
|
51
|
+
readyPath: string;
|
|
52
|
+
metricsPath?: string;
|
|
53
|
+
};
|
|
54
|
+
appsManagerBootstrapUrl: string;
|
|
55
|
+
/**
|
|
56
|
+
* Generated provider topology imported from the worker package's local
|
|
57
|
+
* `src/generated/wildo-provider-runtime.generated.ts` module.
|
|
58
|
+
*
|
|
59
|
+
* Node workers receive only their own pre-scoped provider graph. Non-Node
|
|
60
|
+
* workers stay on the deferred env/bootstrap delivery path and therefore do
|
|
61
|
+
* not use this seam.
|
|
62
|
+
*/
|
|
63
|
+
providerRuntime?: ProviderRuntimeArtifact | WorkerProviderRuntimeArtifact;
|
|
64
|
+
/**
|
|
65
|
+
* Cadence (ms) at which the worker re-polls apps-manager for the
|
|
66
|
+
* trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh
|
|
67
|
+
* per Q3 LOCKED.
|
|
68
|
+
*/
|
|
69
|
+
publicKeyRefreshIntervalMs?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Worker route registration. Called once during HTTP server install
|
|
72
|
+
* with an authenticated `Router` (the JWT verifier middleware is
|
|
73
|
+
* already mounted by the host) plus the verifier handle as `verifyJwt`
|
|
74
|
+
* for routes that need to opt out of the default authenticated
|
|
75
|
+
* pipeline.
|
|
76
|
+
*/
|
|
77
|
+
registerRoutes?: (router: Router, deps: WorkerRouteDependencies) => void;
|
|
78
|
+
}
|
|
79
|
+
export interface WorkerRouteDependencies {
|
|
80
|
+
verifyJwt: RequestHandler;
|
|
81
|
+
providerRuntime?: ProviderRuntimeArtifact;
|
|
82
|
+
}
|
|
83
|
+
export declare function defineWorkerInit(config: WorkerInitializationConfig): WorkerInitializationConfig;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=define-worker-init.d.ts.map
|
|
@@ -0,0 +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,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,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-worker-init.js","sourceRoot":"","sources":["../../../../../src/runtime/services/define-worker-init.ts"],"names":[],"mappings":"AAuFA,MAAM,UAAU,gBAAgB,CAC9B,MAAkC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC","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 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 */\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"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four-env bootstrap-env-contract a Node worker needs at boot, read from
|
|
3
|
+
* the process environment and validated fail-closed.
|
|
4
|
+
*
|
|
5
|
+
* These keys are always projected into the worker's `.env` by
|
|
6
|
+
* `wildo config sync` (from `wildo.saas.config.ts`), keyed off the canonical
|
|
7
|
+
* {@link ApplicationWorkerBootstrapEnvKey} enum. Reading them back through the
|
|
8
|
+
* SAME enum closes the loop the backend lane already has — its
|
|
9
|
+
* `ApplicationEnvConfigurationSchema` is keyed off the sibling
|
|
10
|
+
* `ApplicationBackendBootstrapEnvKey`, so an emit-side rename fails to compile
|
|
11
|
+
* against the read side. Workers previously re-derived these names as string
|
|
12
|
+
* literals in each `index.ts`, which is exactly how a worker drifted from the
|
|
13
|
+
* emitter (`APPS_MANAGER_URL` vs the emitted `PLATFORM_APPS_MANAGER_URL`).
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkerBootstrapEnv {
|
|
16
|
+
/** `APPLICATION_ID` — the caller identity forwarded to apps-manager. */
|
|
17
|
+
applicationId: string;
|
|
18
|
+
/**
|
|
19
|
+
* `PLATFORM_APPLICATION_PRIMARY_SECRET` — paired with the application id as
|
|
20
|
+
* the `x-platform-secret` header so the worker-bootstrap fetch authenticates
|
|
21
|
+
* as `APP_TO_PLATFORM`.
|
|
22
|
+
*/
|
|
23
|
+
platformApplicationPrimarySecret: string;
|
|
24
|
+
/**
|
|
25
|
+
* `PLATFORM_APPS_MANAGER_URL` — base URL of the apps-manager the worker polls
|
|
26
|
+
* for the trusted `APPLICATION_WORKER_REQUEST` public key.
|
|
27
|
+
*/
|
|
28
|
+
appsManagerUrl: string;
|
|
29
|
+
/** `APPLICATION_ENV` — the deployment environment (`development`, `staging`, …). */
|
|
30
|
+
applicationEnv: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Read and validate the worker bootstrap-env-contract, failing closed with
|
|
34
|
+
* EVERY missing key named at once (not just the first) so a misconfigured
|
|
35
|
+
* `.env` surfaces in a single boot attempt.
|
|
36
|
+
*
|
|
37
|
+
* The worker entrypoint calls this once and threads the values into
|
|
38
|
+
* {@link StartWorkerApplicationBackendService.initialize}. Keeping the read
|
|
39
|
+
* here — rather than re-deriving `process.env['…']` literals in each worker's
|
|
40
|
+
* `index.ts` — is what prevents the name drift this helper exists to close.
|
|
41
|
+
*
|
|
42
|
+
* @param env Environment source; defaults to `process.env`. Overridable so
|
|
43
|
+
* tests can exercise the fail-closed path without mutating global state.
|
|
44
|
+
* @throws If any of the four contract keys is missing or empty.
|
|
45
|
+
*/
|
|
46
|
+
export declare function readWorkerBootstrapEnv(env?: NodeJS.ProcessEnv): WorkerBootstrapEnv;
|
|
47
|
+
//# sourceMappingURL=read-worker-bootstrap-env.d.ts.map
|
|
@@ -0,0 +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"}
|