@lensmcp/cluster 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +130 -0
- package/basic-ssl.d.ts +7 -0
- package/basic-ssl.d.ts.map +1 -0
- package/basic-ssl.js +158 -0
- package/build-scope-patterns.d.ts +12 -0
- package/build-scope-patterns.d.ts.map +1 -0
- package/build-scope-patterns.js +40 -0
- package/create-webpack-dev.d.ts +27 -0
- package/create-webpack-dev.d.ts.map +1 -0
- package/create-webpack-dev.js +151 -0
- package/create-webpack-prod.d.ts +28 -0
- package/create-webpack-prod.d.ts.map +1 -0
- package/create-webpack-prod.js +169 -0
- package/executors/build/build.impl.d.ts +19 -0
- package/executors/build/build.impl.d.ts.map +1 -0
- package/executors/build/build.impl.js +98 -0
- package/executors/build/schema.d.ts +35 -0
- package/executors/build/schema.json +135 -0
- package/executors/gateway/gateway.impl.d.ts +23 -0
- package/executors/gateway/gateway.impl.d.ts.map +1 -0
- package/executors/gateway/gateway.impl.js +39 -0
- package/executors/gateway/gateway.lib.d.ts +130 -0
- package/executors/gateway/gateway.lib.d.ts.map +1 -0
- package/executors/gateway/gateway.lib.js +797 -0
- package/executors/gateway/jwks-verify.d.ts +28 -0
- package/executors/gateway/jwks-verify.d.ts.map +1 -0
- package/executors/gateway/jwks-verify.js +121 -0
- package/executors/gateway/main.prod-gateway.d.ts +2 -0
- package/executors/gateway/main.prod-gateway.d.ts.map +1 -0
- package/executors/gateway/main.prod-gateway.js +290 -0
- package/executors/gateway/main.rollout.d.ts +2 -0
- package/executors/gateway/main.rollout.d.ts.map +1 -0
- package/executors/gateway/main.rollout.js +130 -0
- package/executors/gateway/manifest.d.ts +275 -0
- package/executors/gateway/manifest.d.ts.map +1 -0
- package/executors/gateway/manifest.js +344 -0
- package/executors/gateway/prod-gateway.lib.d.ts +58 -0
- package/executors/gateway/prod-gateway.lib.d.ts.map +1 -0
- package/executors/gateway/prod-gateway.lib.js +535 -0
- package/executors/gateway/providers-prod.d.ts +46 -0
- package/executors/gateway/providers-prod.d.ts.map +1 -0
- package/executors/gateway/providers-prod.js +199 -0
- package/executors/gateway/registry-source.d.ts +68 -0
- package/executors/gateway/registry-source.d.ts.map +1 -0
- package/executors/gateway/registry-source.js +131 -0
- package/executors/gateway/rollout-ops.d.ts +54 -0
- package/executors/gateway/rollout-ops.d.ts.map +1 -0
- package/executors/gateway/rollout-ops.js +167 -0
- package/executors/gateway/schema.d.ts +10 -0
- package/executors/gateway/schema.json +30 -0
- package/executors/serve/schema.d.ts +53 -0
- package/executors/serve/schema.json +196 -0
- package/executors/serve/serve.impl.d.ts +25 -0
- package/executors/serve/serve.impl.d.ts.map +1 -0
- package/executors/serve/serve.impl.js +243 -0
- package/executors/trust/schema.d.ts +6 -0
- package/executors/trust/schema.json +20 -0
- package/executors/trust/trust.impl.d.ts +42 -0
- package/executors/trust/trust.impl.d.ts.map +1 -0
- package/executors/trust/trust.impl.js +126 -0
- package/executors.json +24 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +9 -0
- package/main.devserver.d.ts +16 -0
- package/main.devserver.d.ts.map +1 -0
- package/main.devserver.js +812 -0
- package/package.json +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.impl.d.ts","sourceRoot":"","sources":["../../../../../libs/cluster/src/executors/gateway/gateway.impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAElE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAA8B,eAAe,CAC3C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAa/B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = gatewayExecutor;
|
|
4
|
+
const gateway_lib_1 = require("./gateway.lib");
|
|
5
|
+
/**
|
|
6
|
+
* `gateway` executor — ONE https front door for the whole workspace,
|
|
7
|
+
* assembled dynamically from every project's `cluster` declaration:
|
|
8
|
+
*
|
|
9
|
+
* "cluster": { "host": "api.tetros.ai.local", "service": "api", "prependPrefix": "/api" }
|
|
10
|
+
* "cluster": { "host": "tetros.ai.local", "port": 5173, "default": true }
|
|
11
|
+
*
|
|
12
|
+
* Socket-pool services get production-shaped treatment: the gateway is the
|
|
13
|
+
* load balancer, round-robining each request across the service's child
|
|
14
|
+
* sockets (the pods), with serverless lifecycle (eager/minPods/maxPods/
|
|
15
|
+
* idleKillSec) and an auto `internal.<host>` domain for east-west calls
|
|
16
|
+
* that bypass the middleware (JWT) — a full prod demo on localhost. All of
|
|
17
|
+
* it is published to the LensMCP bus (source `gateway`, category `cluster`).
|
|
18
|
+
*
|
|
19
|
+
* The runtime lives in `gateway.lib.ts` (`startGateway`) so it is testable
|
|
20
|
+
* without signals; this wrapper only adds the executor contract.
|
|
21
|
+
*/
|
|
22
|
+
async function gatewayExecutor(options, context) {
|
|
23
|
+
let handle;
|
|
24
|
+
try {
|
|
25
|
+
handle = await (0, gateway_lib_1.startGateway)(options, context);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.error(e.message);
|
|
29
|
+
return { success: false };
|
|
30
|
+
}
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const stop = () => void handle.stop().then(() => resolve({ success: true }));
|
|
33
|
+
process.on('SIGINT', stop);
|
|
34
|
+
process.on('SIGTERM', stop);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
module.exports = gatewayExecutor;
|
|
38
|
+
module.exports.default = gatewayExecutor;
|
|
39
|
+
module.exports.startGateway = gateway_lib_1.startGateway;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway runtime, separated from the Nx executor so it is directly
|
|
3
|
+
* testable: `startGateway()` returns a handle with the actually-bound ports
|
|
4
|
+
* and a `stop()` — no signals needed. The executor is a thin wrapper.
|
|
5
|
+
*/
|
|
6
|
+
import { type ChildProcess } from 'node:child_process';
|
|
7
|
+
import * as http from 'node:http';
|
|
8
|
+
import type { GatewayExecutorSchema } from './schema';
|
|
9
|
+
import { type AuthPolicy } from './manifest';
|
|
10
|
+
export { hostMatches } from './manifest';
|
|
11
|
+
/**
|
|
12
|
+
* Dev edge auth (HS256), mirroring the prod gateway: verify the end-user token, then stamp the
|
|
13
|
+
* trusted identity headers the services read (via GatewayTrustGuard). RS256/JWKS is prod's job;
|
|
14
|
+
* dev shares the `AUTH_JWT_SECRET` the auth host signs with. Returns the claims, or undefined.
|
|
15
|
+
*/
|
|
16
|
+
export declare function verifyDevJwt(req: http.IncomingMessage): Record<string, unknown> | undefined;
|
|
17
|
+
/** Stamp verified identity onto the forwarded request — tenant from the `tid` CLAIM, never a client header. */
|
|
18
|
+
export declare function stampIdentity(req: http.IncomingMessage, claims: Record<string, unknown>): void;
|
|
19
|
+
export interface GatewayContext {
|
|
20
|
+
root: string;
|
|
21
|
+
projectName?: string;
|
|
22
|
+
projectsConfigurations?: {
|
|
23
|
+
projects: Record<string, {
|
|
24
|
+
root: string;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Per-project declaration: top-level `cluster` field in project.json (`davnx` legacy). */
|
|
29
|
+
export interface ClusterProjectDecl {
|
|
30
|
+
/** Public dev hostname (e.g. `api.tetros.ai.local`). */
|
|
31
|
+
host?: string;
|
|
32
|
+
/** Mount PATH under the host — backend services share api.<domain> path-routed (e.g. `/channels`). */
|
|
33
|
+
path?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Socket-pool mode (the "pods" model): the cluster devserver's service
|
|
36
|
+
* name. The gateway round-robins DIRECTLY over its children's unix
|
|
37
|
+
* sockets (`$TMPDIR/<service>-devserver/child-*.sock`) — one load
|
|
38
|
+
* balancer in front of N pods, like production. Also auto-exposes
|
|
39
|
+
* `internal.<host>` for east-west calls that SKIP the middleware (JWT).
|
|
40
|
+
*/
|
|
41
|
+
service?: string;
|
|
42
|
+
/** TCP mode (vite apps etc.): where the dev server listens. */
|
|
43
|
+
upstream?: string;
|
|
44
|
+
/** Shorthand for upstream. */
|
|
45
|
+
port?: number;
|
|
46
|
+
/** Prepend to forwarded URLs (e.g. `/api` for an app mounted under a prefix). */
|
|
47
|
+
prependPrefix?: string;
|
|
48
|
+
/** This project also serves unmatched hostnames (the catch-all). */
|
|
49
|
+
default?: boolean;
|
|
50
|
+
/** Override the auto `internal.<host>` name, or `false` to disable it. */
|
|
51
|
+
internalHost?: string | false;
|
|
52
|
+
/** Edge auth policy (default + per-path overrides) — generated from controller decorators
|
|
53
|
+
* by @tetros-server/gateway-sync; the gateway verifies + injects identity + enforces it.
|
|
54
|
+
* Absent ⇒ the service is unguarded at the edge (current behavior — opt-in enforcement). */
|
|
55
|
+
auth?: AuthPolicy;
|
|
56
|
+
/** Start at gateway boot (true) or on first request — scale from zero (false, default). */
|
|
57
|
+
eager?: boolean;
|
|
58
|
+
/** Pod range: spawn with min, autoscale up to max while requests overlap. */
|
|
59
|
+
minPods?: number;
|
|
60
|
+
maxPods?: number;
|
|
61
|
+
/** Kill a gateway-spawned (non-eager) service after this many idle seconds. */
|
|
62
|
+
idleKillSec?: number;
|
|
63
|
+
/** Nx target that runs the service. Default serve-hmr. */
|
|
64
|
+
serveTarget?: string;
|
|
65
|
+
/** Devserver admin endpoint for scaling (default from port: http(s)://localhost:<port>). */
|
|
66
|
+
adminUrl?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface SockPool {
|
|
69
|
+
dir: string;
|
|
70
|
+
socks: string[];
|
|
71
|
+
idx: number;
|
|
72
|
+
scannedAt: number;
|
|
73
|
+
}
|
|
74
|
+
export interface Route {
|
|
75
|
+
host?: string;
|
|
76
|
+
prefix?: string;
|
|
77
|
+
project: string;
|
|
78
|
+
prependPrefix?: string;
|
|
79
|
+
target?: string;
|
|
80
|
+
pool?: SockPool;
|
|
81
|
+
svc?: ServiceCtl;
|
|
82
|
+
internal?: boolean;
|
|
83
|
+
auth?: AuthPolicy;
|
|
84
|
+
}
|
|
85
|
+
export interface ServiceCtl {
|
|
86
|
+
project: string;
|
|
87
|
+
decl: ClusterProjectDecl;
|
|
88
|
+
pool: SockPool;
|
|
89
|
+
proc?: ChildProcess;
|
|
90
|
+
state: 'down' | 'starting' | 'up';
|
|
91
|
+
lastUsed: number;
|
|
92
|
+
inflight: number;
|
|
93
|
+
lastScaleAt: number;
|
|
94
|
+
spawnAt?: number;
|
|
95
|
+
lastErrors?: string[];
|
|
96
|
+
buildFailed?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** Test-tunable knobs on top of the user-facing schema. */
|
|
99
|
+
export interface GatewayRuntimeOptions extends GatewayExecutorSchema {
|
|
100
|
+
/** Traffic-edge flush period (ms). Default 5000. */
|
|
101
|
+
trafficFlushMs?: number;
|
|
102
|
+
/** Idle sweeper period (ms). Default 10000. */
|
|
103
|
+
sweepMs?: number;
|
|
104
|
+
/** Sock-dir rescan TTL (ms). Default 1500. */
|
|
105
|
+
scanTtlMs?: number;
|
|
106
|
+
/** Cold-start wait budget (ms). Default 120000. */
|
|
107
|
+
startupTimeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
export interface GatewayHandle {
|
|
110
|
+
/** Ports actually bound (resolves `0` to the assigned ephemeral port). */
|
|
111
|
+
ports: number[];
|
|
112
|
+
routes: Route[];
|
|
113
|
+
services: ServiceCtl[];
|
|
114
|
+
stop: () => Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
/** Round-robin over the pool's sockets, rescanning the dir when the cache ages out. */
|
|
117
|
+
export declare function pickSock(pool: SockPool, scanTtlMs?: number): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Read every project's `cluster` (or legacy `davnx`) declaration and build
|
|
120
|
+
* the route table: host routes first (plus auto `internal.<host>` for pod
|
|
121
|
+
* services), the `default` catch-all last.
|
|
122
|
+
*/
|
|
123
|
+
export declare function discoverRoutes(rootDir: string, projects: Record<string, {
|
|
124
|
+
root: string;
|
|
125
|
+
}>, sockBaseDir?: string): {
|
|
126
|
+
routes: Route[];
|
|
127
|
+
services: ServiceCtl[];
|
|
128
|
+
};
|
|
129
|
+
export declare function startGateway(options: GatewayRuntimeOptions, context: GatewayContext): Promise<GatewayHandle>;
|
|
130
|
+
//# sourceMappingURL=gateway.lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.lib.d.ts","sourceRoot":"","sources":["../../../../../libs/cluster/src/executors/gateway/gateway.lib.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG9D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAqE,KAAK,UAAU,EAAc,MAAM,YAAY,CAAC;AAE5H,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKzC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAiB3F;AAED,+GAA+G;AAC/G,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAQ9F;AASD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,M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