@lensmcp/cluster 1.26.3 → 1.26.5

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.
@@ -28,6 +28,12 @@ interface ProjectFile {
28
28
  export declare function readProjectFiles(root: string, maxDepth?: number): ProjectFile[];
29
29
  /** Why the workspace's `lensmcp.json` cannot be read, when it is there and is not a JSON object. */
30
30
  export declare function lensmcpJsonProblem(root: string): string | undefined;
31
+ export interface LensmcpJsonGateway {
32
+ project?: string;
33
+ options: Record<string, unknown>;
34
+ }
35
+ /** The gateway `lensmcp.json` → `config.gateway` declares: where detach-project moved a project's gateway target (foodguard-300). */
36
+ export declare function lensmcpJsonGateway(root: string): LensmcpJsonGateway | undefined;
31
37
  export type DaemonPlan = {
32
38
  ok: true;
33
39
  options: GatewayExecutorSchema;
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var c=(r,t)=>l(r,"name",{value:t,configurable:!0});var f=Object.defineProperty,a=c((r,t)=>f(r,"name",{value:t,configurable:!0}),"a");Object.defineProperty(exports,"__esModule",{value:!0}),exports.GATEWAY_EXECUTOR=void 0,exports.parseDaemonArgs=parseDaemonArgs,exports.readProjectFiles=readProjectFiles,exports.lensmcpJsonProblem=lensmcpJsonProblem,exports.planDaemon=planDaemon,exports.main=main;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path"));exports.GATEWAY_EXECUTOR="@lensmcp/cluster:gateway";function parseDaemonArgs(r){const t=a(p=>{const i=r.indexOf(p);return i>=0?r[i+1]:void 0},"value"),n=t("--root");if(!n)return{error:"usage: daemon.js --root <workspace> [--project <p>] [--target <t>]"};const s=t("--project"),o=t("--target");return{root:path.resolve(n),...s?{project:s}:{},...o?{target:o}:{}}}c(parseDaemonArgs,"parseDaemonArgs"),a(parseDaemonArgs,"parseDaemonArgs");const SKIP=new Set(["node_modules","dist","tmp","coverage",".git",".nx",".lensmcp",".yarn",".angular",".cache"]);function readProjectFiles(r,t=8){const n=[],s=a((o,p)=>{let i;try{i=fs.readdirSync(o,{withFileTypes:!0})}catch{return}if(i.some(e=>e.isFile()&&e.name==="project.json"))try{const e=JSON.parse(fs.readFileSync(path.join(o,"project.json"),"utf8"));n.push({name:e.name??path.basename(o),root:path.relative(r,o)||".",targets:e.targets??{}})}catch{}else if(i.some(e=>e.isFile()&&e.name==="package.json"))try{const e=JSON.parse(fs.readFileSync(path.join(o,"package.json"),"utf8"));typeof e.name=="string"&&e.name&&e.nx&&typeof e.nx=="object"&&!Array.isArray(e.nx)&&n.push({name:e.name,root:path.relative(r,o)||".",targets:e.nx.targets??{}})}catch{}if(!(p>=t))for(const e of i)e.isDirectory()&&!SKIP.has(e.name)&&!e.name.startsWith(".")&&s(path.join(o,e.name),p+1)},"walk");return s(r,0),n}c(readProjectFiles,"readProjectFiles"),a(readProjectFiles,"readProjectFiles");function lensmcpJsonProblem(r){const t=path.join(r,"lensmcp.json");let n;try{n=fs.readFileSync(t,"utf8")}catch{return}try{const s=JSON.parse(n);return s&&typeof s=="object"&&!Array.isArray(s)?void 0:`${t} is not a JSON object \u2014 fix it, or remove it`}catch(s){return`${t} is not valid JSON (${s instanceof Error?s.message:String(s)}) \u2014 fix it, or remove it`}}c(lensmcpJsonProblem,"lensmcpJsonProblem"),a(lensmcpJsonProblem,"lensmcpJsonProblem");function planDaemon(r){const t=lensmcpJsonProblem(r.root);if(t)return{ok:!1,error:t};const n=readProjectFiles(r.root),s=r.project?n.find(i=>i.name===r.project):void 0;if(r.project&&!s)return{ok:!1,error:`no project '${r.project}' in ${r.root}`};let o;for(const i of s?[s]:n){for(const[e,m]of Object.entries(i.targets))if(!(r.target?e!==r.target:m.executor!==exports.GATEWAY_EXECUTOR)){if(r.target&&m.executor&&m.executor!==exports.GATEWAY_EXECUTOR)return{ok:!1,error:`${i.name}:${e} runs ${m.executor}, not ${exports.GATEWAY_EXECUTOR}`};o={project:i.name,target:e,options:m.options??{}};break}if(o)break}if(!o&&(r.project||r.target))return{ok:!1,error:`no ${exports.GATEWAY_EXECUTOR} target ${[r.project,r.target].filter(Boolean).join(":")} in ${r.root}`};if(!o&&!fs.existsSync(path.join(r.root,"lensmcp.json")))return{ok:!1,error:`no project in ${r.root} declares ${exports.GATEWAY_EXECUTOR}, and it has no lensmcp.json`};const p={root:r.root,...o?{projectName:o.project}:{},projectsConfigurations:{projects:Object.fromEntries(n.map(i=>[i.name,{root:i.root}]))}};return{ok:!0,options:o?.options??{},context:p,from:o?`${o.project}:${o.target}`:"lensmcp.json"}}c(planDaemon,"planDaemon"),a(planDaemon,"planDaemon");async function main(r){const t=parseDaemonArgs(r);if("error"in t)return console.error(t.error),2;const n=planDaemon(t);if("error"in n)return console.error(`[gateway] ${n.error}`),1;console.log(`[gateway] ${new Date().toISOString()} starting without nx (pid ${process.pid}) \u2014 ${n.from} in ${t.root}, from ${__filename}`);const{default:s}=require("./gateway.impl");return(await s(n.options,n.context)).success?0:1}c(main,"main"),a(main,"main"),require.main===module&&main(process.argv.slice(2)).then(r=>process.exit(r),r=>{console.error(r instanceof Error?r.stack??r.message:String(r)),process.exit(1)});
1
+ "use strict";var y=Object.defineProperty;var m=(r,e)=>y(r,"name",{value:e,configurable:!0});var j=Object.defineProperty,p=m((r,e)=>j(r,"name",{value:e,configurable:!0}),"p");Object.defineProperty(exports,"__esModule",{value:!0}),exports.GATEWAY_EXECUTOR=void 0,exports.parseDaemonArgs=parseDaemonArgs,exports.readProjectFiles=readProjectFiles,exports.lensmcpJsonProblem=lensmcpJsonProblem,exports.lensmcpJsonGateway=lensmcpJsonGateway,exports.planDaemon=planDaemon,exports.main=main;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path"));exports.GATEWAY_EXECUTOR="@lensmcp/cluster:gateway";function parseDaemonArgs(r){const e=p(a=>{const i=r.indexOf(a);return i>=0?r[i+1]:void 0},"value"),o=e("--root");if(!o)return{error:"usage: daemon.js --root <workspace> [--project <p>] [--target <t>]"};const s=e("--project"),n=e("--target");return{root:path.resolve(o),...s?{project:s}:{},...n?{target:n}:{}}}m(parseDaemonArgs,"parseDaemonArgs"),p(parseDaemonArgs,"parseDaemonArgs");const SKIP=new Set(["node_modules","dist","tmp","coverage",".git",".nx",".lensmcp",".yarn",".angular",".cache"]);function readProjectFiles(r,e=8){const o=[],s=p((n,a)=>{let i;try{i=fs.readdirSync(n,{withFileTypes:!0})}catch{return}if(i.some(t=>t.isFile()&&t.name==="project.json"))try{const t=JSON.parse(fs.readFileSync(path.join(n,"project.json"),"utf8"));o.push({name:t.name??path.basename(n),root:path.relative(r,n)||".",targets:t.targets??{}})}catch{}else if(i.some(t=>t.isFile()&&t.name==="package.json"))try{const t=JSON.parse(fs.readFileSync(path.join(n,"package.json"),"utf8"));typeof t.name=="string"&&t.name&&t.nx&&typeof t.nx=="object"&&!Array.isArray(t.nx)&&o.push({name:t.name,root:path.relative(r,n)||".",targets:t.nx.targets??{}})}catch{}if(!(a>=e))for(const t of i)t.isDirectory()&&!SKIP.has(t.name)&&!t.name.startsWith(".")&&s(path.join(n,t.name),a+1)},"walk");return s(r,0),o}m(readProjectFiles,"readProjectFiles"),p(readProjectFiles,"readProjectFiles");function lensmcpJsonProblem(r){const e=path.join(r,"lensmcp.json");let o;try{o=fs.readFileSync(e,"utf8")}catch{return}try{const s=JSON.parse(o);return s&&typeof s=="object"&&!Array.isArray(s)?void 0:`${e} is not a JSON object \u2014 fix it, or remove it`}catch(s){return`${e} is not valid JSON (${s instanceof Error?s.message:String(s)}) \u2014 fix it, or remove it`}}m(lensmcpJsonProblem,"lensmcpJsonProblem"),p(lensmcpJsonProblem,"lensmcpJsonProblem");const isPlainObject=p(r=>!!r&&typeof r=="object"&&!Array.isArray(r),"isPlainObject");function lensmcpJsonGateway(r){let e;try{e=JSON.parse(fs.readFileSync(path.join(r,"lensmcp.json"),"utf8"))}catch{return}const o=isPlainObject(e)&&isPlainObject(e.config)?e.config.gateway:void 0;if(!(!isPlainObject(o)||o.executor!==void 0&&o.executor!==exports.GATEWAY_EXECUTOR))return{...typeof o.project=="string"?{project:o.project}:{},options:isPlainObject(o.options)?o.options:{}}}m(lensmcpJsonGateway,"lensmcpJsonGateway"),p(lensmcpJsonGateway,"lensmcpJsonGateway");function planDaemon(r){const e=lensmcpJsonProblem(r.root);if(e)return{ok:!1,error:e};const o=readProjectFiles(r.root),s=r.project?o.find(c=>c.name===r.project):void 0;if(r.project&&!s)return{ok:!1,error:`no project '${r.project}' in ${r.root}`};let n;for(const c of s?[s]:o){for(const[u,l]of Object.entries(c.targets))if(!(r.target?u!==r.target:l.executor!==exports.GATEWAY_EXECUTOR)){if(r.target&&l.executor&&l.executor!==exports.GATEWAY_EXECUTOR)return{ok:!1,error:`${c.name}:${u} runs ${l.executor}, not ${exports.GATEWAY_EXECUTOR}`};n={project:c.name,target:u,options:l.options??{}};break}if(n)break}if(!n&&(r.project||r.target))return{ok:!1,error:`no ${exports.GATEWAY_EXECUTOR} target ${[r.project,r.target].filter(Boolean).join(":")} in ${r.root}`};if(!n&&!fs.existsSync(path.join(r.root,"lensmcp.json")))return{ok:!1,error:`no project in ${r.root} declares ${exports.GATEWAY_EXECUTOR}, and it has no lensmcp.json`};const a=n?void 0:lensmcpJsonGateway(r.root),i=n?.project??(a?.project&&o.some(c=>c.name===a.project)?a.project:void 0),t={root:r.root,...i?{projectName:i}:{},projectsConfigurations:{projects:Object.fromEntries(o.map(c=>[c.name,{root:c.root}]))}},f=n?.options??a?.options??{},g=n?`${n.project}:${n.target}`:a?"lensmcp.json config.gateway":"lensmcp.json";return{ok:!0,options:f,context:t,from:g}}m(planDaemon,"planDaemon"),p(planDaemon,"planDaemon");async function main(r){const e=parseDaemonArgs(r);if("error"in e)return console.error(e.error),2;const o=planDaemon(e);if("error"in o)return console.error(`[gateway] ${o.error}`),1;console.log(`[gateway] ${new Date().toISOString()} starting without nx (pid ${process.pid}) \u2014 ${o.from} in ${e.root}, from ${__filename}`);const{default:s}=require("./gateway.impl");return(await s(o.options,o.context)).success?0:1}m(main,"main"),p(main,"main"),require.main===module&&main(process.argv.slice(2)).then(r=>process.exit(r),r=>{console.error(r instanceof Error?r.stack??r.message:String(r)),process.exit(1)});
@@ -6,12 +6,14 @@ export interface ServiceDecls {
6
6
  from: Record<string, DeclSource>;
7
7
  problems: string[];
8
8
  }
9
+ export declare function readJson(file: string): unknown;
9
10
  /** Why `<root>/lensmcp.json` cannot be read, when it is there and is not a JSON object (as the no-nx daemon refuses it). */
10
11
  export declare function lensmcpJsonProblem(root: string): string | undefined;
11
12
  export declare function lensmcpServices(rootDir: string): {
12
13
  services: Record<string, ClusterProjectDecl | false>;
13
14
  problems: string[];
14
15
  };
16
+ /** A project's declaration: its `project.json` `cluster` (else `davnx`), with its lensmcp.json `services` entry over it key by key; `false` turns it off, and one naming nothing to serve (only targets or settings) is none. */
15
17
  export declare function declFor<D>(services: Readonly<Record<string, unknown>>, name: string, projectJson: {
16
18
  cluster?: D;
17
19
  davnx?: D;
@@ -1 +1 @@
1
- "use strict";var v=Object.defineProperty;var l=(r,o)=>v(r,"name",{value:o,configurable:!0});var d=Object.defineProperty,i=l((r,o)=>d(r,"name",{value:o,configurable:!0}),"i");Object.defineProperty(exports,"__esModule",{value:!0}),exports.lensmcpJsonProblem=lensmcpJsonProblem,exports.lensmcpServices=lensmcpServices,exports.declFor=declFor,exports.readServiceDecls=readServiceDecls;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path"));function readJson(r){try{return JSON.parse(fs.readFileSync(r,"utf8"))}catch{return}}l(readJson,"readJson"),i(readJson,"readJson");function lensmcpJsonProblem(r){const o=path.join(r,"lensmcp.json");let s;try{s=fs.readFileSync(o,"utf8")}catch{return}try{const e=JSON.parse(s);return e&&typeof e=="object"&&!Array.isArray(e)?void 0:`${o} is not a JSON object \u2014 fix it, or remove it`}catch(e){return`${o} is not valid JSON (${e instanceof Error?e.message:String(e)}) \u2014 fix it, or remove it`}}l(lensmcpJsonProblem,"lensmcpJsonProblem"),i(lensmcpJsonProblem,"lensmcpJsonProblem");function lensmcpServices(r){const o=lensmcpJsonProblem(r);if(o)return{services:{},problems:[o]};const s=readJson(path.join(r,"lensmcp.json"))?.services;if(s===void 0)return{services:{},problems:[]};if(!s||typeof s!="object"||Array.isArray(s))return{services:{},problems:["lensmcp.json services is not an object of projects \u2014 ignored"]};const e={},t=[];for(const[p,n]of Object.entries(s))n===!1?e[p]=!1:n&&typeof n=="object"&&!Array.isArray(n)?e[p]=n:t.push(`lensmcp.json services.${p} is neither a declaration nor false \u2014 ignored`);return{services:e,problems:t}}l(lensmcpServices,"lensmcpServices"),i(lensmcpServices,"lensmcpServices");function declFor(r,o,s){const e=r[o];if(e===!1)return{};if(e&&typeof e=="object"&&!Array.isArray(e))return{decl:e,from:"lensmcp.json"};const t=s?.cluster??s?.davnx;return t?{decl:t,from:"project.json"}:{}}l(declFor,"declFor"),i(declFor,"declFor");function readServiceDecls(r,o){const{services:s,problems:e}=lensmcpServices(r),t=[],p=new Map,n={};for(const c of Object.keys(s))o[c]||e.push(`lensmcp.json services.${c} names no project of this workspace \u2014 ignored`);for(const[c,a]of Object.entries(o)){const m=s[c]===void 0?readJson(path.join(r,a.root,"project.json")):void 0,{decl:f,from:u}=declFor(s,c,m);!f||!u||(t.push([c,f]),p.set(c,a.root),n[c]=u)}return{decls:t,rootOf:p,from:n,problems:e}}l(readServiceDecls,"readServiceDecls"),i(readServiceDecls,"readServiceDecls");
1
+ "use strict";var v=Object.defineProperty;var i=(o,r)=>v(o,"name",{value:r,configurable:!0});var d=Object.defineProperty,f=i((o,r)=>d(o,"name",{value:r,configurable:!0}),"f");Object.defineProperty(exports,"__esModule",{value:!0}),exports.readJson=readJson,exports.lensmcpJsonProblem=lensmcpJsonProblem,exports.lensmcpServices=lensmcpServices,exports.declFor=declFor,exports.readServiceDecls=readServiceDecls;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path"));function readJson(o){try{return JSON.parse(fs.readFileSync(o,"utf8"))}catch{return}}i(readJson,"readJson"),f(readJson,"readJson");function lensmcpJsonProblem(o){const r=path.join(o,"lensmcp.json");let s;try{s=fs.readFileSync(r,"utf8")}catch{return}try{const e=JSON.parse(s);return e&&typeof e=="object"&&!Array.isArray(e)?void 0:`${r} is not a JSON object \u2014 fix it, or remove it`}catch(e){return`${r} is not valid JSON (${e instanceof Error?e.message:String(e)}) \u2014 fix it, or remove it`}}i(lensmcpJsonProblem,"lensmcpJsonProblem"),f(lensmcpJsonProblem,"lensmcpJsonProblem");function lensmcpServices(o){const r=lensmcpJsonProblem(o);if(r)return{services:{},problems:[r]};const s=readJson(path.join(o,"lensmcp.json"))?.services;if(s===void 0)return{services:{},problems:[]};if(!s||typeof s!="object"||Array.isArray(s))return{services:{},problems:["lensmcp.json services is not an object of projects \u2014 ignored"]};const e={},c=[];for(const[n,t]of Object.entries(s))t===!1?e[n]=!1:t&&typeof t=="object"&&!Array.isArray(t)?e[n]=t:c.push(`lensmcp.json services.${n} is neither a declaration nor false \u2014 ignored`);return{services:e,problems:c}}i(lensmcpServices,"lensmcpServices"),f(lensmcpServices,"lensmcpServices");const SERVING_KEYS=["host","service","upstream","port","kind","lens","sources"];function namesWhatToServe(o){const r=o;return SERVING_KEYS.some(s=>r[s]!==void 0&&r[s]!==!1)}i(namesWhatToServe,"namesWhatToServe"),f(namesWhatToServe,"namesWhatToServe");function declFor(o,r,s){const e=o[r];if(e===!1)return{};const c=s?.cluster??s?.davnx,n=!!e&&typeof e=="object"&&!Array.isArray(e),t=n?{...c,...e}:c;return!t||!namesWhatToServe(t)?{}:{decl:t,from:n?"lensmcp.json":"project.json"}}i(declFor,"declFor"),f(declFor,"declFor");function readServiceDecls(o,r){const{services:s,problems:e}=lensmcpServices(o),c=[],n=new Map,t={};for(const a of Object.keys(s))r[a]||e.push(`lensmcp.json services.${a} names no project of this workspace \u2014 ignored`);for(const[a,p]of Object.entries(r)){const m=readJson(path.join(o,p.root,"project.json")),{decl:l,from:u}=declFor(s,a,m);!l||!u||(c.push([a,l]),n.set(a,p.root),t[a]=u)}return{decls:c,rootOf:n,from:t,problems:e}}i(readServiceDecls,"readServiceDecls"),f(readServiceDecls,"readServiceDecls");
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var d=(t,r)=>M(t,"name",{value:r,configurable:!0});var g=Object.defineProperty,s=d((t,r)=>g(t,"name",{value:r,configurable:!0}),"s");Object.defineProperty(exports,"__esModule",{value:!0}),exports.unavailableMiddleware=void 0,exports.guestMiddlewarePolicy=guestMiddlewarePolicy,exports.findGatewayMiddleware=findGatewayMiddleware,exports.loadMiddleware=loadMiddleware,exports.createWorkspaceMiddleware=createWorkspaceMiddleware;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path")),workspace_auth_1=require("ringwall/workspace-auth");function guestMiddlewarePolicy(t=process.env){const r=t.LENSMCP_GUEST_MIDDLEWARE;return r==="owner"||r==="none"?r:"own"}d(guestMiddlewarePolicy,"guestMiddlewarePolicy"),s(guestMiddlewarePolicy,"guestMiddlewarePolicy");function findGatewayMiddleware(t,r){for(const i of Object.values(r)){let a;try{a=JSON.parse(fs.readFileSync(path.join(t,i.root,"project.json"),"utf8"))}catch{continue}for(const o of Object.values(a.targets??{}))if(o?.executor==="@lensmcp/cluster:gateway"&&typeof o.options?.middleware=="string"&&o.options.middleware)return o.options.middleware}}d(findGatewayMiddleware,"findGatewayMiddleware"),s(findGatewayMiddleware,"findGatewayMiddleware");function loadMiddleware(t){const r=require.resolve(t);delete require.cache[r];const i=require(r);return(0,workspace_auth_1.validateMiddleware)(i.default??i)}d(loadMiddleware,"loadMiddleware"),s(loadMiddleware,"loadMiddleware");const unavailableMiddleware=s(()=>{throw new Error("Gateway middleware unavailable")},"unavailableMiddleware");exports.unavailableMiddleware=unavailableMiddleware;const loadFailure=s(t=>{const r=t;return typeof r?.code=="string"?r.code:typeof r?.name=="string"?r.name:"error"},"loadFailure");function release(t,r,i,a){const o=i?.dispose;if(typeof o=="function")try{const e=o.call(i);e&&typeof e.catch=="function"&&e.catch(n=>console.warn(`[gateway] a middleware's dispose failed (${loadFailure(n)})`))}catch(e){console.warn(`[gateway] a middleware's dispose failed (${loadFailure(e)})`)}let l=t;try{l=fs.realpathSync(t)}catch{}const c=[t,l].map(e=>e.endsWith(path.sep)?e:e+path.sep);for(const e of Object.keys(a))(r.includes(e)||c.some(n=>e.startsWith(n)))&&delete a[e]}d(release,"release"),s(release,"release");function createWorkspaceMiddleware(t){const r=t.policy??"own",i=t.load??loadMiddleware,a=new Map,o=new Map,l=t.cache??require.cache,c=s(e=>{const n=o.get(e);n&&release(n.root,n.loaded,a.get(e),l),o.delete(e)},"letGo");return{set(e,n,p){if(e===t.ownerKey)return;if(c(e),!p){a.set(e,void 0);return}const u=path.resolve(n,p),f=new Set(Object.keys(l));try{const w=i(u);o.set(e,{root:n,loaded:Object.keys(l).filter(y=>!f.has(y))}),a.set(e,w),r==="own"&&console.log(`[gateway] '${e}' routes run its own middleware: ${u}`)}catch(w){a.set(e,exports.unavailableMiddleware),console.warn(`[gateway] could not load '${e}''s middleware ${u} (${loadFailure(w)}) \u2014 its routes refuse every request until it registers again`)}},drop(e){c(e),a.delete(e)},for(e){if(e===void 0||e===t.ownerKey||r==="owner")return t.owner;if(r!=="none")return a.get(e)}}}d(createWorkspaceMiddleware,"createWorkspaceMiddleware"),s(createWorkspaceMiddleware,"createWorkspaceMiddleware");
1
+ "use strict";var M=Object.defineProperty;var c=(r,t)=>M(r,"name",{value:t,configurable:!0});var g=Object.defineProperty,s=c((r,t)=>g(r,"name",{value:t,configurable:!0}),"s");Object.defineProperty(exports,"__esModule",{value:!0}),exports.unavailableMiddleware=void 0,exports.guestMiddlewarePolicy=guestMiddlewarePolicy,exports.findGatewayMiddleware=findGatewayMiddleware,exports.loadMiddleware=loadMiddleware,exports.createWorkspaceMiddleware=createWorkspaceMiddleware;const tslib_1=require("tslib"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path")),workspace_auth_1=require("ringwall/workspace-auth"),daemon_1=require("../daemon");function guestMiddlewarePolicy(r=process.env){const t=r.LENSMCP_GUEST_MIDDLEWARE;return t==="owner"||t==="none"?t:"own"}c(guestMiddlewarePolicy,"guestMiddlewarePolicy"),s(guestMiddlewarePolicy,"guestMiddlewarePolicy");function findGatewayMiddleware(r,t){let a=!1;for(const l of Object.values(t)){let i;try{i=JSON.parse(fs.readFileSync(path.join(r,l.root,"project.json"),"utf8"))}catch{continue}for(const d of Object.values(i.targets??{}))if(d?.executor==="@lensmcp/cluster:gateway"&&(a=!0,typeof d.options?.middleware=="string"&&d.options.middleware))return d.options.middleware}if(a)return;const o=(0,daemon_1.lensmcpJsonGateway)(r)?.options.middleware;return typeof o=="string"&&o?o:void 0}c(findGatewayMiddleware,"findGatewayMiddleware"),s(findGatewayMiddleware,"findGatewayMiddleware");function loadMiddleware(r){const t=require.resolve(r);delete require.cache[t];const a=require(t);return(0,workspace_auth_1.validateMiddleware)(a.default??a)}c(loadMiddleware,"loadMiddleware"),s(loadMiddleware,"loadMiddleware");const unavailableMiddleware=s(()=>{throw new Error("Gateway middleware unavailable")},"unavailableMiddleware");exports.unavailableMiddleware=unavailableMiddleware;const loadFailure=s(r=>{const t=r;return typeof t?.code=="string"?t.code:typeof t?.name=="string"?t.name:"error"},"loadFailure");function release(r,t,a,o){const l=a?.dispose;if(typeof l=="function")try{const e=l.call(a);e&&typeof e.catch=="function"&&e.catch(n=>console.warn(`[gateway] a middleware's dispose failed (${loadFailure(n)})`))}catch(e){console.warn(`[gateway] a middleware's dispose failed (${loadFailure(e)})`)}let i=r;try{i=fs.realpathSync(r)}catch{}const d=[r,i].map(e=>e.endsWith(path.sep)?e:e+path.sep);for(const e of Object.keys(o))(t.includes(e)||d.some(n=>e.startsWith(n)))&&delete o[e]}c(release,"release"),s(release,"release");function createWorkspaceMiddleware(r){const t=r.policy??"own",a=r.load??loadMiddleware,o=new Map,l=new Map,i=r.cache??require.cache,d=s(e=>{const n=l.get(e);n&&release(n.root,n.loaded,o.get(e),i),l.delete(e)},"letGo");return{set(e,n,p){if(e===r.ownerKey)return;if(d(e),!p){o.set(e,void 0);return}const u=path.resolve(n,p),f=new Set(Object.keys(i));try{const w=a(u);l.set(e,{root:n,loaded:Object.keys(i).filter(y=>!f.has(y))}),o.set(e,w),t==="own"&&console.log(`[gateway] '${e}' routes run its own middleware: ${u}`)}catch(w){o.set(e,exports.unavailableMiddleware),console.warn(`[gateway] could not load '${e}''s middleware ${u} (${loadFailure(w)}) \u2014 its routes refuse every request until it registers again`)}},drop(e){d(e),o.delete(e)},for(e){if(e===void 0||e===r.ownerKey||t==="owner")return r.owner;if(t!=="none")return o.get(e)}}}c(createWorkspaceMiddleware,"createWorkspaceMiddleware"),s(createWorkspaceMiddleware,"createWorkspaceMiddleware");
@@ -1,6 +1,6 @@
1
- "use strict";var y=Object.defineProperty;var f=(r,e)=>y(r,"name",{value:e,configurable:!0});var h=Object.defineProperty,u=f((r,e)=>h(r,"name",{value:e,configurable:!0}),"u");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=trustExecutor,exports.missingHostLines=missingHostLines,exports.collectHosts=collectHosts;const tslib_1=require("tslib"),node_child_process_1=require("node:child_process"),services_decl_1=require("../gateway/runtime/services-decl"),node_dns_1=require("node:dns"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path")),basic_ssl_1=require("../../basic-ssl"),checkout_cache_1=require("../../checkout-cache"),hostname_1=require("./hostname");async function trustExecutor(r,e){const t=(0,checkout_cache_1.checkoutCacheDir)(e.root,"davnx-webpack"),n=(0,basic_ssl_1.ensureCaSync)(t),i=process.env.LENSMCP_TRUST_HOSTS_ONLY==="1",s=collectHosts(r,e);if(s.length===0&&console.log("[trust] no concrete hostnames found (only wildcards?) \u2014 keychain step only."),process.platform!=="darwin"){console.log("[trust] non-macOS platform \u2014 do these manually:"),console.log(` \u2022 trust ${n} in your OS/browser store (Linux: update-ca-certificates / certutil)`);for(const c of s)console.log(` \u2022 /etc/hosts: "127.0.0.1 ${c}" and "::1 ${c}"`);return{success:!0}}const a=caSha256Fingerprint(n),o=i||a!==void 0&&(0,node_child_process_1.spawnSync)("security",["find-certificate","-a","-c","lensmcp local dev CA","-Z","/Library/Keychains/System.keychain"],{encoding:"utf8"}).stdout?.includes(a)===!0;if(i)console.log("[trust] hosts-only: a shared daemon serves TLS with its own CA \u2014 skipping the keychain step.");else if(o)console.log("[trust] CA already in the System keychain \u2014 skipping.");else{if(console.log(`[trust] adding CA to the System keychain (sudo will prompt): ${n}`),(0,node_child_process_1.spawnSync)("sudo",["security","add-trusted-cert","-d","-r","trustRoot","-k","/Library/Keychains/System.keychain",n],{stdio:"inherit"}).status!==0)return console.error("[trust] add-trusted-cert failed \u2014 rerun in a terminal so sudo can prompt."),{success:!1};console.log("[trust] CA trusted. Restart your browser once (it caches certificate verdicts).")}const d=fs.readFileSync("/etc/hosts","utf8"),l=missingHostLines(s,d,await resolveAll(s));if(l.length===0)console.log("[trust] /etc/hosts already complete (both families for every hostname, by a line or by the OS resolver).");else{if(console.log(`[trust] appending to /etc/hosts (sudo):
1
+ "use strict";var y=Object.defineProperty;var h=(r,e)=>y(r,"name",{value:e,configurable:!0});var f=Object.defineProperty,u=h((r,e)=>f(r,"name",{value:e,configurable:!0}),"u");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=trustExecutor,exports.missingHostLines=missingHostLines,exports.collectHosts=collectHosts;const tslib_1=require("tslib"),node_child_process_1=require("node:child_process"),services_decl_1=require("../gateway/runtime/services-decl"),node_dns_1=require("node:dns"),fs=tslib_1.__importStar(require("node:fs")),path=tslib_1.__importStar(require("node:path")),basic_ssl_1=require("../../basic-ssl"),checkout_cache_1=require("../../checkout-cache"),hostname_1=require("./hostname");async function trustExecutor(r,e){const t=(0,checkout_cache_1.checkoutCacheDir)(e.root,"davnx-webpack"),n=(0,basic_ssl_1.ensureCaSync)(t),i=process.env.LENSMCP_TRUST_HOSTS_ONLY==="1",s=collectHosts(r,e);if(s.length===0&&console.log("[trust] no concrete hostnames found (only wildcards?) \u2014 keychain step only."),process.platform!=="darwin"){console.log("[trust] non-macOS platform \u2014 do these manually:"),console.log(` \u2022 trust ${n} in your OS/browser store (Linux: update-ca-certificates / certutil)`);for(const c of s)console.log(` \u2022 /etc/hosts: "127.0.0.1 ${c}" and "::1 ${c}"`);return{success:!0}}const a=caSha256Fingerprint(n),o=i||a!==void 0&&(0,node_child_process_1.spawnSync)("security",["find-certificate","-a","-c","lensmcp local dev CA","-Z","/Library/Keychains/System.keychain"],{encoding:"utf8"}).stdout?.includes(a)===!0;if(i)console.log("[trust] hosts-only: a shared daemon serves TLS with its own CA \u2014 skipping the keychain step.");else if(o)console.log("[trust] CA already in the System keychain \u2014 skipping.");else{if(console.log(`[trust] adding CA to the System keychain (sudo will prompt): ${n}`),(0,node_child_process_1.spawnSync)("sudo",["security","add-trusted-cert","-d","-r","trustRoot","-k","/Library/Keychains/System.keychain",n],{stdio:"inherit"}).status!==0)return console.error("[trust] add-trusted-cert failed \u2014 rerun in a terminal so sudo can prompt."),{success:!1};console.log("[trust] CA trusted. Restart your browser once (it caches certificate verdicts).")}const d=fs.readFileSync("/etc/hosts","utf8"),l=missingHostLines(s,d,await resolveAll(s));if(l.length===0)console.log("[trust] /etc/hosts already complete (both families for every hostname, by a line or by the OS resolver).");else{if(console.log(`[trust] appending to /etc/hosts (sudo):
2
2
  ${l.join(`
3
3
  `)}`),(0,node_child_process_1.spawnSync)("sudo",["tee","-a","/etc/hosts"],{input:l.join(`
4
4
  `)+`
5
- `,stdio:["pipe","ignore","inherit"]}).status!==0)return console.error("[trust] /etc/hosts update failed."),{success:!1};(0,node_child_process_1.spawnSync)("sudo",["dscacheutil","-flushcache"],{stdio:"inherit"}),(0,node_child_process_1.spawnSync)("sudo",["killall","-HUP","mDNSResponder"],{stdio:"inherit"})}if(!i){const c=(0,node_child_process_1.spawnSync)("security",["verify-cert","-c",n,"-p","basic"],{stdio:"ignore"});console.log(`[trust] CA trust check: ${c.status===0?"OK":"NOT TRUSTED YET (browser restart may be needed)"}`)}for(const c of s)console.log(`[trust] ${c} \u2192 https ready (hosts + cert SAN ride the gateway config)`);return{success:!0}}f(trustExecutor,"trustExecutor"),u(trustExecutor,"trustExecutor");function caSha256Fingerprint(r){const e=(0,node_child_process_1.spawnSync)("openssl",["x509","-in",r,"-noout","-fingerprint","-sha256"],{encoding:"utf8"});if(e.status!==0||!e.stdout)return;const t=e.stdout.split("=")[1]?.replaceAll(":","").trim().toUpperCase();return t&&/^[0-9A-F]{64}$/.test(t)?t:void 0}f(caSha256Fingerprint,"caSha256Fingerprint"),u(caSha256Fingerprint,"caSha256Fingerprint");function missingHostLines(r,e,t){const n=u((s,a)=>e.split(`
6
- `).some(o=>{const d=o.trim();if(d.startsWith("#"))return!1;const l=d.split(/\s+/);return l[0]===s&&l.slice(1).includes(a)}),"hasEntry"),i=[];for(const s of r)!n("127.0.0.1",s)&&!t.get(s)?.v4&&i.push(`127.0.0.1 ${s}`),!n("::1",s)&&!t.get(s)?.v6&&i.push(`::1 ${s}`);return i}f(missingHostLines,"missingHostLines"),u(missingHostLines,"missingHostLines");async function resolveAll(r){const e=u(t=>new Promise(n=>{const i=setTimeout(()=>n({v4:!1,v6:!1}),2e3);(0,node_dns_1.lookup)(t,{all:!0},(s,a)=>{if(clearTimeout(i),s||!Array.isArray(a))return n({v4:!1,v6:!1});n({v4:a.some(o=>o.family===4&&o.address.startsWith("127.")),v6:a.some(o=>o.family===6&&o.address==="::1")})})}),"one");return new Map(await Promise.all(r.map(async t=>[t,await e(t)])))}f(resolveAll,"resolveAll"),u(resolveAll,"resolveAll");function collectHosts(r,e){const t=[],n=e.projectName?e.projectsConfigurations?.projects[e.projectName]:void 0,i=r.serveTarget??"serve-hmr",s=n?.targets?.[i]?.options?.gateway?.routes??[];for(const o of s)o.host&&(0,hostname_1.isValidHostname)(o.host)?t.push(o.host):o.host&&console.warn(`[trust] ignoring invalid hostname in ${i} routes: ${JSON.stringify(o.host)}`);const{services:a}=(0,services_decl_1.lensmcpServices)(e.root);for(const[o,d]of Object.entries(e.projectsConfigurations?.projects??{}))try{const l=a[o]===void 0?JSON.parse(fs.readFileSync(path.join(e.root,d.root,"project.json"),"utf8")):void 0,{decl:c}=(0,services_decl_1.declFor)(a,o,l),p=c?.host;p&&!(0,hostname_1.isValidHostname)(p)&&console.warn(`[trust] ignoring invalid hostname in ${d.root}/project.json: ${JSON.stringify(p)}`),p&&(0,hostname_1.isValidHostname)(p)&&(t.push(p),c?.service&&c.internalHost!==!1&&t.push(typeof c.internalHost=="string"?c.internalHost:`internal.${p}`))}catch{}return[...new Set([...t,"lensmcp.local",...r.hosts??[]])]}f(collectHosts,"collectHosts"),u(collectHosts,"collectHosts");
5
+ `,stdio:["pipe","ignore","inherit"]}).status!==0)return console.error("[trust] /etc/hosts update failed."),{success:!1};(0,node_child_process_1.spawnSync)("sudo",["dscacheutil","-flushcache"],{stdio:"inherit"}),(0,node_child_process_1.spawnSync)("sudo",["killall","-HUP","mDNSResponder"],{stdio:"inherit"})}if(!i){const c=(0,node_child_process_1.spawnSync)("security",["verify-cert","-c",n,"-p","basic"],{stdio:"ignore"});console.log(`[trust] CA trust check: ${c.status===0?"OK":"NOT TRUSTED YET (browser restart may be needed)"}`)}for(const c of s)console.log(`[trust] ${c} \u2192 https ready (hosts + cert SAN ride the gateway config)`);return{success:!0}}h(trustExecutor,"trustExecutor"),u(trustExecutor,"trustExecutor");function caSha256Fingerprint(r){const e=(0,node_child_process_1.spawnSync)("openssl",["x509","-in",r,"-noout","-fingerprint","-sha256"],{encoding:"utf8"});if(e.status!==0||!e.stdout)return;const t=e.stdout.split("=")[1]?.replaceAll(":","").trim().toUpperCase();return t&&/^[0-9A-F]{64}$/.test(t)?t:void 0}h(caSha256Fingerprint,"caSha256Fingerprint"),u(caSha256Fingerprint,"caSha256Fingerprint");function missingHostLines(r,e,t){const n=u((s,a)=>e.split(`
6
+ `).some(o=>{const d=o.trim();if(d.startsWith("#"))return!1;const l=d.split(/\s+/);return l[0]===s&&l.slice(1).includes(a)}),"hasEntry"),i=[];for(const s of r)!n("127.0.0.1",s)&&!t.get(s)?.v4&&i.push(`127.0.0.1 ${s}`),!n("::1",s)&&!t.get(s)?.v6&&i.push(`::1 ${s}`);return i}h(missingHostLines,"missingHostLines"),u(missingHostLines,"missingHostLines");async function resolveAll(r){const e=u(t=>new Promise(n=>{const i=setTimeout(()=>n({v4:!1,v6:!1}),2e3);(0,node_dns_1.lookup)(t,{all:!0},(s,a)=>{if(clearTimeout(i),s||!Array.isArray(a))return n({v4:!1,v6:!1});n({v4:a.some(o=>o.family===4&&o.address.startsWith("127.")),v6:a.some(o=>o.family===6&&o.address==="::1")})})}),"one");return new Map(await Promise.all(r.map(async t=>[t,await e(t)])))}h(resolveAll,"resolveAll"),u(resolveAll,"resolveAll");function collectHosts(r,e){const t=[],n=e.projectName?e.projectsConfigurations?.projects[e.projectName]:void 0,i=r.serveTarget??"serve-hmr",s=n?.targets?.[i]?.options?.gateway?.routes??[];for(const o of s)o.host&&(0,hostname_1.isValidHostname)(o.host)?t.push(o.host):o.host&&console.warn(`[trust] ignoring invalid hostname in ${i} routes: ${JSON.stringify(o.host)}`);const{services:a}=(0,services_decl_1.lensmcpServices)(e.root);for(const[o,d]of Object.entries(e.projectsConfigurations?.projects??{}))try{const l=(0,services_decl_1.readJson)(path.join(e.root,d.root,"project.json")),{decl:c}=(0,services_decl_1.declFor)(a,o,l),p=c?.host;p&&!(0,hostname_1.isValidHostname)(p)&&console.warn(`[trust] ignoring invalid hostname in ${d.root}/project.json: ${JSON.stringify(p)}`),p&&(0,hostname_1.isValidHostname)(p)&&(t.push(p),c?.service&&c.internalHost!==!1&&t.push(typeof c.internalHost=="string"?c.internalHost:`internal.${p}`))}catch{}return[...new Set([...t,"lensmcp.local",...r.hosts??[]])]}h(collectHosts,"collectHosts"),u(collectHosts,"collectHosts");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/cluster",
3
- "version": "1.26.3",
3
+ "version": "1.26.5",
4
4
  "description": "Run your Nx workspace as a local production cluster: pods on unix sockets with true HMR, one https gateway with per-project domains, scale-from-zero, autoscale, idle-kill, local-CA TLS — observed by the LensMCP lens.",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -32,9 +32,9 @@
32
32
  "typescript": ">=5.0.0"
33
33
  },
34
34
  "dependencies": {
35
- "@lensmcp/core": "1.26.3",
36
- "@lensmcp/node-instrumentation": "1.26.3",
37
- "@lensmcp/nx-plugin": "1.26.3",
35
+ "@lensmcp/core": "1.26.5",
36
+ "@lensmcp/node-instrumentation": "1.26.5",
37
+ "@lensmcp/nx-plugin": "1.26.5",
38
38
  "ringwall": "1.0.1",
39
39
  "@typescript/native-preview": "^7.0.0-dev.20260707.2",
40
40
  "fork-ts-checker-webpack-plugin": "^9.0.0",