@lensmcp/core 1.18.14 → 1.20.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/lib/event-bus.js CHANGED
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var n=(s,t)=>c(s,"name",{value:t,configurable:!0});var a=Object.defineProperty,o=n((s,t)=>a(s,"name",{value:t,configurable:!0}),"n"),h=Object.defineProperty,u=o((s,t)=>h(s,"name",{value:t,configurable:!0}),"e");export class EventBus{static{n(this,"EventBus")}static{o(this,"EventBus")}static{u(this,"EventBus")}constructor(t={}){this.subs=new Set,this.dropped=0,this.capacity=t.capacity??1e4,this.onDrop=t.onDrop,this.transform=t.transform}publish(t){if(this.subs.size>this.capacity){this.dropped++,this.onDrop?.(1);return}let r=t;if(this.transform)try{r=this.transform(t)??t}catch{r=t}for(const e of this.subs)if(!(e.filter&&!e.filter(r)))try{const i=e.handler(r);i&&typeof i.then=="function"&&i.catch(()=>{})}catch{}}subscribe(t,r){const e={handler:t,filter:r};return this.subs.add(e),()=>{this.subs.delete(e)}}droppedCount(){return this.dropped}subscriberCount(){return this.subs.size}}
1
+ "use strict";var c=Object.defineProperty;var e=(o,s)=>c(o,"name",{value:s,configurable:!0});export class EventBus{static{e(this,"EventBus")}constructor(s={}){this.subs=new Set,this.dropped=0,this.capacity=s.capacity??1e4,this.onDrop=s.onDrop,this.transform=s.transform}publish(s){if(this.subs.size>this.capacity){this.dropped++,this.onDrop?.(1);return}let t=s;if(this.transform)try{t=this.transform(s)??s}catch{t=s}for(const r of this.subs)if(!(r.filter&&!r.filter(t)))try{const i=r.handler(t);i&&typeof i.then=="function"&&i.catch(()=>{})}catch{}}subscribe(s,t){const r={handler:s,filter:t};return this.subs.add(r),()=>{this.subs.delete(r)}}droppedCount(){return this.dropped}subscriberCount(){return this.subs.size}}
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var r=(e,t)=>f(e,"name",{value:t,configurable:!0});var l=Object.defineProperty,n=r((e,t)=>l(e,"name",{value:t,configurable:!0}),"r"),u=Object.defineProperty,o=n((e,t)=>u(e,"name",{value:t,configurable:!0}),"e");const d=2166136261,g=16777619;function a(e){let t=2166136261;for(let i=0;i<e.length;i++)t^=e.charCodeAt(i),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}r(a,"o"),n(a,"i"),o(a,"fnv1a32");export function fingerprint(e){const t=[e.kind,e.identity,e.file??"",e.detail??""];return`${e.kind}:${a(t.join("|"))}`}r(fingerprint,"fingerprint"),n(fingerprint,"fingerprint"),o(fingerprint,"fingerprint");
1
+ "use strict";var o=Object.defineProperty;var e=(t,n)=>o(t,"name",{value:n,configurable:!0});const F=2166136261,S=16777619;function i(t){let n=2166136261;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,16777619);return(n>>>0).toString(16).padStart(8,"0")}e(i,"fnv1a32");export function fingerprint(t){const n=[t.kind,t.identity,t.file??"",t.detail??""];return`${t.kind}:${i(n.join("|"))}`}e(fingerprint,"fingerprint");
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var u=(t,r)=>I(t,"name",{value:r,configurable:!0});var v=Object.defineProperty,l=u((t,r)=>v(t,"name",{value:r,configurable:!0}),"u"),x=Object.defineProperty,m=l((t,r)=>x(t,"name",{value:r,configurable:!0}),"u");function f(t){const r=t.raw??null,i=r?.kind,a=t.context,s={id:t.id,parentTraceNodeId:a.causedByNodeId??a.originNodeId,lifecycle:"completed",context:a,startTime:t.timestamp,attributes:{...r??{}}};if(t.source==="react"&&i==="render"){const n=r;return{parentAxis:"render",node:{...s,type:"render",logicalId:n.render?.componentLogicalId,instanceId:n.render?.componentInstanceId,name:`render ${n.render?.componentName??"?"}`,durationMs:n.render?.actualDurationMs}}}if(t.source==="valtio"&&i==="state-update"){const n=r;return{parentAxis:"state",node:{...s,type:"state-update",logicalId:n.update?.storeId,name:`${n.update?.storeId??"?"}.${n.update?.path??"?"}`}}}if(t.source==="nestjs"&&i==="server-request"){const n=r;return{parentAxis:"backend",node:{...s,type:"server-request",name:`${n.request?.method??"?"} ${n.request?.route??"?"}`,durationMs:n.request?.durationMs}}}if(i==="loop")return{parentAxis:"performance",node:{...s,type:"loop",name:"loop",durationMs:r.loop?.durationMs}};if(t.source==="client-runtime"&&i==="user-action"){const n=r;return{parentAxis:"caused",node:{...s,type:"ui-event",logicalId:n.origin?.nodeId,name:n.origin?.label??t.title}}}}u(f,"m"),l(f,"f"),m(f,"eventToNode");export function buildGraphFromEvents(t,r){const i=[...r].sort((o,e)=>o.timestamp-e.timestamp),a=[];for(const o of i){const e=f(o);e&&(t.addNode(e.node),a.push(e))}let s=0;const n=m((o,e,d,c)=>{const g={id:`${d}:${o}->${e}`,from:o,to:e,axis:d,type:c,timestamp:t.getNode(e)?.startTime??0};t.addEdge(g),s++},"addEdge");for(const o of a){const e=o.node.context.causedByNodeId;e&&t.getNode(e)&&n(e,o.node.id,o.parentAxis??"caused","caused-by")}const p=new Map;for(const o of a){const e=o.node.context.flowId;if(!e)continue;let d=p.get(e);d||(d=[],p.set(e,d)),d.push(o)}for(const o of p.values())for(let e=1;e<o.length;e++){const d=o[e-1].node,c=o[e].node;c.context.causedByNodeId!==d.id&&n(d.id,c.id,"caused","flow-sequence")}return{nodeCount:a.length,edgeCount:s}}u(buildGraphFromEvents,"buildGraphFromEvents"),l(buildGraphFromEvents,"buildGraphFromEvents"),m(buildGraphFromEvents,"buildGraphFromEvents");
1
+ "use strict";var m=Object.defineProperty;var u=(o,d)=>m(o,"name",{value:d,configurable:!0});function f(o){const d=o.raw??null,c=d?.kind,s=o.context,a={id:o.id,parentTraceNodeId:s.causedByNodeId??s.originNodeId,lifecycle:"completed",context:s,startTime:o.timestamp,attributes:{...d??{}}};if(o.source==="react"&&c==="render"){const t=d;return{parentAxis:"render",node:{...a,type:"render",logicalId:t.render?.componentLogicalId,instanceId:t.render?.componentInstanceId,name:`render ${t.render?.componentName??"?"}`,durationMs:t.render?.actualDurationMs}}}if(o.source==="valtio"&&c==="state-update"){const t=d;return{parentAxis:"state",node:{...a,type:"state-update",logicalId:t.update?.storeId,name:`${t.update?.storeId??"?"}.${t.update?.path??"?"}`}}}if(o.source==="nestjs"&&c==="server-request"){const t=d;return{parentAxis:"backend",node:{...a,type:"server-request",name:`${t.request?.method??"?"} ${t.request?.route??"?"}`,durationMs:t.request?.durationMs}}}if(c==="loop")return{parentAxis:"performance",node:{...a,type:"loop",name:"loop",durationMs:d.loop?.durationMs}};if(o.source==="client-runtime"&&c==="user-action"){const t=d;return{parentAxis:"caused",node:{...a,type:"ui-event",logicalId:t.origin?.nodeId,name:t.origin?.label??o.title}}}}u(f,"eventToNode");export function buildGraphFromEvents(o,d){const c=[...d].sort((n,e)=>n.timestamp-e.timestamp),s=[];for(const n of c){const e=f(n);e&&(o.addNode(e.node),s.push(e))}let a=0;const t=u((n,e,r,i)=>{const l={id:`${r}:${n}->${e}`,from:n,to:e,axis:r,type:i,timestamp:o.getNode(e)?.startTime??0};o.addEdge(l),a++},"addEdge");for(const n of s){const e=n.node.context.causedByNodeId;e&&o.getNode(e)&&t(e,n.node.id,n.parentAxis??"caused","caused-by")}const p=new Map;for(const n of s){const e=n.node.context.flowId;if(!e)continue;let r=p.get(e);r||(r=[],p.set(e,r)),r.push(n)}for(const n of p.values())for(let e=1;e<n.length;e++){const r=n[e-1].node,i=n[e].node;i.context.causedByNodeId!==r.id&&t(r.id,i.id,"caused","flow-sequence")}return{nodeCount:s.length,edgeCount:a}}u(buildGraphFromEvents,"buildGraphFromEvents");
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var l=(d,t)=>w(d,"name",{value:t,configurable:!0});var I=Object.defineProperty,y=l((d,t)=>I(d,"name",{value:t,configurable:!0}),"l"),b=Object.defineProperty,m=y((d,t)=>b(d,"name",{value:t,configurable:!0}),"l");const B=4,M=1e3;export class GraphStore{static{l(this,"GraphStore")}static{y(this,"GraphStore")}static{m(this,"GraphStore")}constructor(){this.nodes=new Map,this.edges=new Map,this.byParent=new Map,this.byFlow=new Map,this.byLogical=new Map,this.byInstance=new Map,this.byRequest=new Map,this.outByAxis=new Map,this.inByAxis=new Map}addNode(t){this.nodes.set(t.id,t),t.parentTraceNodeId&&this.addToIndex(this.byParent,t.parentTraceNodeId,t.id),t.context.flowId&&this.addToIndex(this.byFlow,t.context.flowId,t.id),t.logicalId&&this.addToIndex(this.byLogical,t.logicalId,t.id),t.instanceId&&this.addToIndex(this.byInstance,t.instanceId,t.id),t.context.requestId&&this.addToIndex(this.byRequest,t.context.requestId,t.id)}updateNode(t,e){const i=this.nodes.get(t);if(!i)throw new Error(`Unknown node: ${t}`);const s={...i,...e,id:i.id};return this.nodes.set(t,s),s}getNode(t){return this.nodes.get(t)}addEdge(t){this.edges.set(t.id,t);let e=this.outByAxis.get(t.axis);e||(e=new Map,this.outByAxis.set(t.axis,e)),this.addToIndex(e,t.from,t.id);let i=this.inByAxis.get(t.axis);i||(i=new Map,this.inByAxis.set(t.axis,i)),this.addToIndex(i,t.to,t.id)}getEdge(t){return this.edges.get(t)}childrenOf(t){return this.materialiseNodes(this.byParent.get(t))}nodesInFlow(t){return this.materialiseNodes(this.byFlow.get(t))}nodesByLogical(t){return this.materialiseNodes(this.byLogical.get(t))}nodesByInstance(t){return this.materialiseNodes(this.byInstance.get(t))}nodesByRequest(t){return this.materialiseNodes(this.byRequest.get(t))}traverse(t){const e=this.nodes.get(t.from);if(!e)return{nodes:[],edges:[]};const i=Array.isArray(t.lens)?t.lens:[t.lens],s=t.direction??"both",x=t.depth??4,p=t.maxNodes??1e3,o=new Set,g=new Set,c=[{id:e.id,d:0}];for(;c.length&&!(o.size>=p);){const{id:n,d:u}=c.shift();if(!o.has(n)&&(o.add(n),!(u>=x)))for(const f of i){if(s==="out"||s==="both"){const a=this.outByAxis.get(f)?.get(n);if(a)for(const r of a){g.add(r);const h=this.edges.get(r);o.has(h.to)||c.push({id:h.to,d:u+1})}}if(s==="in"||s==="both"){const a=this.inByAxis.get(f)?.get(n);if(a)for(const r of a){g.add(r);const h=this.edges.get(r);o.has(h.from)||c.push({id:h.from,d:u+1})}}}}return{nodes:this.materialiseNodes(o),edges:[...g].map(n=>this.edges.get(n)).filter(n=>!!n)}}nodeCount(){return this.nodes.size}edgeCount(){return this.edges.size}addToIndex(t,e,i){let s=t.get(e);s||(s=new Set,t.set(e,s)),s.add(i)}materialiseNodes(t){if(!t)return[];const e=[];for(const i of t){const s=this.nodes.get(i);s&&e.push(s)}return e}}
1
+ "use strict";var w=Object.defineProperty;var l=(f,t)=>w(f,"name",{value:t,configurable:!0});const b=4,M=1e3;export class GraphStore{static{l(this,"GraphStore")}constructor(){this.nodes=new Map,this.edges=new Map,this.byParent=new Map,this.byFlow=new Map,this.byLogical=new Map,this.byInstance=new Map,this.byRequest=new Map,this.outByAxis=new Map,this.inByAxis=new Map}addNode(t){this.nodes.set(t.id,t),t.parentTraceNodeId&&this.addToIndex(this.byParent,t.parentTraceNodeId,t.id),t.context.flowId&&this.addToIndex(this.byFlow,t.context.flowId,t.id),t.logicalId&&this.addToIndex(this.byLogical,t.logicalId,t.id),t.instanceId&&this.addToIndex(this.byInstance,t.instanceId,t.id),t.context.requestId&&this.addToIndex(this.byRequest,t.context.requestId,t.id)}updateNode(t,e){const i=this.nodes.get(t);if(!i)throw new Error(`Unknown node: ${t}`);const s={...i,...e,id:i.id};return this.nodes.set(t,s),s}getNode(t){return this.nodes.get(t)}addEdge(t){this.edges.set(t.id,t);let e=this.outByAxis.get(t.axis);e||(e=new Map,this.outByAxis.set(t.axis,e)),this.addToIndex(e,t.from,t.id);let i=this.inByAxis.get(t.axis);i||(i=new Map,this.inByAxis.set(t.axis,i)),this.addToIndex(i,t.to,t.id)}getEdge(t){return this.edges.get(t)}childrenOf(t){return this.materialiseNodes(this.byParent.get(t))}nodesInFlow(t){return this.materialiseNodes(this.byFlow.get(t))}nodesByLogical(t){return this.materialiseNodes(this.byLogical.get(t))}nodesByInstance(t){return this.materialiseNodes(this.byInstance.get(t))}nodesByRequest(t){return this.materialiseNodes(this.byRequest.get(t))}traverse(t){const e=this.nodes.get(t.from);if(!e)return{nodes:[],edges:[]};const i=Array.isArray(t.lens)?t.lens:[t.lens],s=t.direction??"both",x=t.depth??4,y=t.maxNodes??1e3,o=new Set,c=new Set,h=[{id:e.id,d:0}];for(;h.length&&!(o.size>=y);){const{id:n,d:u}=h.shift();if(!o.has(n)&&(o.add(n),!(u>=x)))for(const g of i){if(s==="out"||s==="both"){const d=this.outByAxis.get(g)?.get(n);if(d)for(const a of d){c.add(a);const r=this.edges.get(a);o.has(r.to)||h.push({id:r.to,d:u+1})}}if(s==="in"||s==="both"){const d=this.inByAxis.get(g)?.get(n);if(d)for(const a of d){c.add(a);const r=this.edges.get(a);o.has(r.from)||h.push({id:r.from,d:u+1})}}}}return{nodes:this.materialiseNodes(o),edges:[...c].map(n=>this.edges.get(n)).filter(n=>!!n)}}nodeCount(){return this.nodes.size}edgeCount(){return this.edges.size}addToIndex(t,e,i){let s=t.get(e);s||(s=new Set,t.set(e,s)),s.add(i)}materialiseNodes(t){if(!t)return[];const e=[];for(const i of t){const s=this.nodes.get(i);s&&e.push(s)}return e}}
package/lib/patterns.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var p=(a,s)=>M(a,"name",{value:s,configurable:!0});var D=Object.defineProperty,f=p((a,s)=>D(a,"name",{value:s,configurable:!0}),"p"),b=Object.defineProperty,h=f((a,s)=>b(a,"name",{value:s,configurable:!0}),"p");export function detectDbInLoop(a,s={}){const l=s.threshold??5,d=[];for(const i of a){const n=i.raw??null;if(n?.kind!=="loop"||!n.loop)continue;const e=n.loop.dbCallsInsideLoop??0;e>l&&d.push({kind:"db-in-loop",severity:"warning",title:`${e} DB calls inside a loop (${n.loop.iterations??"?"} iterations)`,evidence:[i.id],details:{dbCallsInsideLoop:e,iterations:n.loop.iterations,durationMs:n.loop.durationMs,threshold:l},detectedAt:i.timestamp})}return d}p(detectDbInLoop,"detectDbInLoop"),f(detectDbInLoop,"detectDbInLoop"),h(detectDbInLoop,"detectDbInLoop");export function detectNPlusOne(a,s={}){const l=s.threshold??3,d=new Map;for(const n of a){const e=n.raw??null;if(e?.kind!=="db-query"||!e.query?.signature)continue;const t=e.query.signature;let o=d.get(t);o||(o=[],d.set(t,o)),o.push(n)}const i=[];for(const[n,e]of d)e.length>=l&&i.push({kind:"n+1-query",severity:"warning",title:`Query repeated ${e.length}\xD7 \u2014 likely N+1`,evidence:e.map(t=>t.id),details:{signature:n,count:e.length,threshold:l},detectedAt:e[e.length-1].timestamp});return i}p(detectNPlusOne,"detectNPlusOne"),f(detectNPlusOne,"detectNPlusOne"),h(detectNPlusOne,"detectNPlusOne");export function detectRenderStorm(a,s={}){const l=s.threshold??5,d=s.windowMs??250,i=new Map;for(const e of a){if(e.source!=="react")continue;const t=e.raw??null;if(t?.kind!=="render"||!t.render?.componentInstanceId)continue;const o=t.render.componentInstanceId;let r=i.get(o);r||(r=[],i.set(o,r)),r.push(e)}const n=[];for(const[e,t]of i){t.sort((r,u)=>r.timestamp-u.timestamp);let o=0;for(let r=0;r<t.length;r++){for(;t[r].timestamp-t[o].timestamp>d;)o++;const u=r-o+1;if(u>l){const c=t.slice(o,r+1),m=c[0].raw.render?.componentName??e;n.push({kind:"render-storm",severity:"warning",title:`${m} rendered ${u}\xD7 in ${d}ms`,evidence:c.map(g=>g.id),details:{componentInstanceId:e,count:u,windowMs:d,threshold:l},detectedAt:c[c.length-1].timestamp});break}}}return n}p(detectRenderStorm,"detectRenderStorm"),f(detectRenderStorm,"detectRenderStorm"),h(detectRenderStorm,"detectRenderStorm");export function findSlowPath(a,s,l){const d=new Map,i=new Set;function n(t){const o=d.get(t);if(o)return o;if(i.has(t))return{path:[t],totalDurationMs:l(t)};i.add(t);const r=l(t),u=s.get(t)??[];let c;for(const g of u){const w=n(g);(!c||w.totalDurationMs>c.totalDurationMs)&&(c=w)}i.delete(t);const m=c?{path:[t,...c.path],totalDurationMs:r+c.totalDurationMs}:{path:[t],totalDurationMs:r};return d.set(t,m),m}p(n,"n"),f(n,"o"),h(n,"best");let e={path:[],totalDurationMs:0};for(const t of a){const o=n(t);o.totalDurationMs>e.totalDurationMs&&(e=o)}return e}p(findSlowPath,"findSlowPath"),f(findSlowPath,"findSlowPath"),h(findSlowPath,"findSlowPath");
1
+ "use strict";var w=Object.defineProperty;var p=(u,l)=>w(u,"name",{value:l,configurable:!0});export function detectDbInLoop(u,l={}){const a=l.threshold??5,i=[];for(const r of u){const o=r.raw??null;if(o?.kind!=="loop"||!o.loop)continue;const e=o.loop.dbCallsInsideLoop??0;e>a&&i.push({kind:"db-in-loop",severity:"warning",title:`${e} DB calls inside a loop (${o.loop.iterations??"?"} iterations)`,evidence:[r.id],details:{dbCallsInsideLoop:e,iterations:o.loop.iterations,durationMs:o.loop.durationMs,threshold:a},detectedAt:r.timestamp})}return i}p(detectDbInLoop,"detectDbInLoop");export function detectNPlusOne(u,l={}){const a=l.threshold??3,i=new Map;for(const o of u){const e=o.raw??null;if(e?.kind!=="db-query"||!e.query?.signature)continue;const t=e.query.signature;let n=i.get(t);n||(n=[],i.set(t,n)),n.push(o)}const r=[];for(const[o,e]of i)e.length>=a&&r.push({kind:"n+1-query",severity:"warning",title:`Query repeated ${e.length}\xD7 \u2014 likely N+1`,evidence:e.map(t=>t.id),details:{signature:o,count:e.length,threshold:a},detectedAt:e[e.length-1].timestamp});return r}p(detectNPlusOne,"detectNPlusOne");export function detectRenderStorm(u,l={}){const a=l.threshold??5,i=l.windowMs??250,r=new Map;for(const e of u){if(e.source!=="react")continue;const t=e.raw??null;if(t?.kind!=="render"||!t.render?.componentInstanceId)continue;const n=t.render.componentInstanceId;let s=r.get(n);s||(s=[],r.set(n,s)),s.push(e)}const o=[];for(const[e,t]of r){t.sort((s,d)=>s.timestamp-d.timestamp);let n=0;for(let s=0;s<t.length;s++){for(;t[s].timestamp-t[n].timestamp>i;)n++;const d=s-n+1;if(d>a){const c=t.slice(n,s+1),h=c[0].raw.render?.componentName??e;o.push({kind:"render-storm",severity:"warning",title:`${h} rendered ${d}\xD7 in ${i}ms`,evidence:c.map(f=>f.id),details:{componentInstanceId:e,count:d,windowMs:i,threshold:a},detectedAt:c[c.length-1].timestamp});break}}}return o}p(detectRenderStorm,"detectRenderStorm");export function findSlowPath(u,l,a){const i=new Map,r=new Set;function o(t){const n=i.get(t);if(n)return n;if(r.has(t))return{path:[t],totalDurationMs:a(t)};r.add(t);const s=a(t),d=l.get(t)??[];let c;for(const f of d){const m=o(f);(!c||m.totalDurationMs>c.totalDurationMs)&&(c=m)}r.delete(t);const h=c?{path:[t,...c.path],totalDurationMs:s+c.totalDurationMs}:{path:[t],totalDurationMs:s};return i.set(t,h),h}p(o,"best");let e={path:[],totalDurationMs:0};for(const t of u){const n=o(t);n.totalDurationMs>e.totalDurationMs&&(e=n)}return e}p(findSlowPath,"findSlowPath");
package/lib/redact.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var a=(e,t)=>f(e,"name",{value:t,configurable:!0});var d=Object.defineProperty,o=a((e,t)=>d(e,"name",{value:t,configurable:!0}),"o"),x=Object.defineProperty,c=o((e,t)=>x(e,"name",{value:t,configurable:!0}),"o");export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const A=["token","secret","password","passwd","apikey","credential","assertion","signature"],$=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]);export function isSecretParam(e){const t=e.toLowerCase();if(A.some(r=>t.includes(r)))return!0;for(const r of t.split(/[-_.]+/))if(r&&$.has(r))return!0;return!1}a(isSecretParam,"isSecretParam"),o(isSecretParam,"isSecretParam"),c(isSecretParam,"isSecretParam");const b=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,T=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(e){return e&&e.replace(b,`$1${REDACTED}@`).replace(T,(t,r,i)=>isSecretParam(i)?`${r}${i}=${REDACTED}`:t)}a(redactUrlParams,"redactUrlParams"),o(redactUrlParams,"redactUrlParams"),c(redactUrlParams,"redactUrlParams");export function redactUrl(e){return e&&clip(redactUrlParams(e),1024)}a(redactUrl,"redactUrl"),o(redactUrl,"redactUrl"),c(redactUrl,"redactUrl");const y=/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,g=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,m=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)([^\s"',;]{4,})\3/gi;export function redactText(e){return redactUrlParams(e).replace(m,(t,r,i,n)=>`${r}${i}${n}${REDACTED}${n}`).replace(y,REDACTED).replace(g,(t,r)=>`${r} ${REDACTED}`)}a(redactText,"redactText"),o(redactText,"redactText"),c(redactText,"redactText");export function clip(e,t){return e.length<=t?e:`${e.slice(0,t)}\u2026[lensmcp truncated: ${e.length-t} more chars]`}a(clip,"clip"),o(clip,"clip"),c(clip,"clip");export function safeText(e,t=4096){if(e!==void 0)return clip(redactText(e),t)}a(safeText,"safeText"),o(safeText,"safeText"),c(safeText,"safeText");export function safeTitle(e){return clip(redactText(e),300)}a(safeTitle,"safeTitle"),o(safeTitle,"safeTitle"),c(safeTitle,"safeTitle");const _=6,k=64;export function redactDeep(e,t=0){if(typeof e=="string")return redactText(e);if(e===null||typeof e!="object"||t>=_)return e;if(Array.isArray(e)){let n=!1;const s=e.map((u,l)=>{if(l>=k)return u;const p=redactDeep(u,t+1);return p!==u&&(n=!0),p});return n?s:e}let r=!1;const i={};for(const[n,s]of Object.entries(e)){const u=isSecretParam(n)&&s!==void 0&&s!==null?REDACTED:redactDeep(s,t+1);u!==s&&(r=!0),i[n]=u}return r?i:e}a(redactDeep,"redactDeep"),o(redactDeep,"redactDeep"),c(redactDeep,"redactDeep");
1
+ "use strict";var E=Object.defineProperty;var o=(t,e)=>E(t,"name",{value:e,configurable:!0});export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const _=["token","secret","password","passwd","apikey","credential","assertion","signature"],p=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]);export function isSecretParam(t){const e=t.toLowerCase();if(_.some(r=>e.includes(r)))return!0;for(const r of e.split(/[-_.]+/))if(r&&p.has(r))return!0;return!1}o(isSecretParam,"isSecretParam");const A=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,u=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(t){return t&&t.replace(A,`$1${REDACTED}@`).replace(u,(r,s,n)=>isSecretParam(n)?`${s}${n}=${REDACTED}`:r)}o(redactUrlParams,"redactUrlParams");export function redactUrl(t){return t&&clip(redactUrlParams(t),1024)}o(redactUrl,"redactUrl");const R=/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,S=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,d=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)([^\s"',;]{4,})\3/gi;export function redactText(t){return redactUrlParams(t).replace(d,(e,r,s,n)=>`${r}${s}${n}${REDACTED}${n}`).replace(R,REDACTED).replace(S,(e,r)=>`${r} ${REDACTED}`)}o(redactText,"redactText");export function clip(t,e){return t.length<=e?t:`${t.slice(0,e)}\u2026[lensmcp truncated: ${t.length-e} more chars]`}o(clip,"clip");export function safeText(t,e=4096){if(t!==void 0)return clip(redactText(t),e)}o(safeText,"safeText");export function safeTitle(t){return clip(redactText(t),300)}o(safeTitle,"safeTitle");const T=6,x=64;export function redactDeep(t,e=0){if(typeof t=="string")return redactText(t);if(t===null||typeof t!="object"||e>=T)return t;if(Array.isArray(t)){let n=!1;const i=t.map((c,a)=>{if(a>=x)return c;const f=redactDeep(c,e+1);return f!==c&&(n=!0),f});return n?i:t}let r=!1;const s={};for(const[n,i]of Object.entries(t)){const c=isSecretParam(n)&&i!==void 0&&i!==null?REDACTED:redactDeep(i,e+1);c!==i&&(r=!0),s[n]=c}return r?s:t}o(redactDeep,"redactDeep");
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var c=(r,e)=>a(r,"name",{value:e,configurable:!0});var u=Object.defineProperty,i=c((r,e)=>u(r,"name",{value:e,configurable:!0}),"c"),n=Object.defineProperty,d=i((r,e)=>n(r,"name",{value:e,configurable:!0}),"c");export class ReducerRegistry{static{c(this,"ReducerRegistry")}static{i(this,"ReducerRegistry")}static{d(this,"ReducerRegistry")}constructor(){this.reducers=[]}register(e,s){if(this.reducers.some(t=>t.name===e))throw new Error(`Reducer already registered: ${e}`);this.reducers.push({name:e,reducer:s})}list(){return this.reducers}async dispatch(e){for(const{reducer:s}of this.reducers)try{const t=s(e);t&&typeof t.then=="function"&&await t}catch{}}}
1
+ "use strict";var i=Object.defineProperty;var c=(t,r)=>i(t,"name",{value:r,configurable:!0});export class ReducerRegistry{static{c(this,"ReducerRegistry")}constructor(){this.reducers=[]}register(r,s){if(this.reducers.some(e=>e.name===r))throw new Error(`Reducer already registered: ${r}`);this.reducers.push({name:r,reducer:s})}list(){return this.reducers}async dispatch(r){for(const{reducer:s}of this.reducers)try{const e=s(r);e&&typeof e.then=="function"&&await e}catch{}}}
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var i=(s,e)=>a(s,"name",{value:e,configurable:!0});var h=Object.defineProperty,c=i((s,e)=>h(s,"name",{value:e,configurable:!0}),"i"),d=Object.defineProperty,l=c((s,e)=>d(s,"name",{value:e,configurable:!0}),"o");export class ResourceStore{static{i(this,"ResourceStore")}static{c(this,"ResourceStore")}static{l(this,"ResourceStore")}constructor(){this.entries=new Map,this.subs=new Map}register(e,t){if(this.entries.has(e))throw new Error(`Resource already registered: ${e}`);return this.entries.set(e,{uri:e,produce:t,revision:0}),()=>{this.entries.delete(e),this.subs.delete(e)}}async read(e){const t=this.entries.get(e);if(!t)throw new Error(`Unknown resource: ${e}`);return t.produce()}list(){return[...this.entries.keys()]}async markDirty(e){const t=this.entries.get(e);if(!t)return;const r=await t.produce(),n=JSON.stringify(r);if(n===t.lastJson)return;t.lastJson=n,t.revision+=1;const o=this.subs.get(e);if(o)for(const u of o)try{u(e,t.revision)}catch{}}revision(e){return this.entries.get(e)?.revision}subscribe(e,t){let r=this.subs.get(e);return r||(r=new Set,this.subs.set(e,r)),r.add(t),()=>{r?.delete(t)}}}
1
+ "use strict";var h=Object.defineProperty;var o=(r,e)=>h(r,"name",{value:e,configurable:!0});export class ResourceStore{static{o(this,"ResourceStore")}constructor(){this.entries=new Map,this.subs=new Map}register(e,s){if(this.entries.has(e))throw new Error(`Resource already registered: ${e}`);return this.entries.set(e,{uri:e,produce:s,revision:0}),()=>{this.entries.delete(e),this.subs.delete(e)}}async read(e){const s=this.entries.get(e);if(!s)throw new Error(`Unknown resource: ${e}`);return s.produce()}list(){return[...this.entries.keys()]}async markDirty(e){const s=this.entries.get(e);if(!s)return;const t=await s.produce(),n=JSON.stringify(t);if(n===s.lastJson)return;s.lastJson=n,s.revision+=1;const i=this.subs.get(e);if(i)for(const c of i)try{c(e,s.revision)}catch{}}revision(e){return this.entries.get(e)?.revision}subscribe(e,s){let t=this.subs.get(e);return t||(t=new Set,this.subs.set(e,t)),t.add(s),()=>{t?.delete(s)}}}
package/lib/story.js CHANGED
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var u=(t,n)=>I(t,"name",{value:n,configurable:!0});var k=Object.defineProperty,c=u((t,n)=>k(t,"name",{value:n,configurable:!0}),"u"),b=Object.defineProperty,p=c((t,n)=>b(t,"name",{value:n,configurable:!0}),"c");export function groupByFlow(t){const n=new Map;for(const e of t){const o=e.context.flowId;if(!o)continue;let s=n.get(o);s||(s=[],n.set(o,s)),s.push(e)}return n}u(groupByFlow,"groupByFlow"),c(groupByFlow,"groupByFlow"),p(groupByFlow,"groupByFlow");export function compileStory(t,n={}){let e,o;if(n.flowId)o=n.flowId,e=t.filter(r=>r.context.flowId===o);else{const r=t.find(i=>i.context.flowId);if(!r)return;o=r.context.flowId,e=t.filter(i=>i.context.flowId===o)}if(e.length===0)return;e.sort((r,i)=>r.timestamp-i.timestamp);const s=1e3;e.length>s&&(e=[e[0],...e.slice(e.length-(s-1))]);const m=e[0],d=[];let l,v;for(const r of e){const i=f(r);if(i){if(d.push(i),i.kind==="render"||i.kind==="final-render"){const a=r.raw;a?.render&&(l={id:a.render.id,page:a.render.page,route:a.render.route,componentName:a.render.componentName})}else if(r.source==="visual"&&i.kind==="visual-violation"){const a=r.raw;a?.frame&&(v=a.frame.id)}}}for(let r=d.length-1;r>=0;r--)if(d[r].kind==="render"){d[r]={...d[r],kind:"final-render"};break}const g=e[0].timestamp,w=e[e.length-1].timestamp;return{flowId:o,origin:{type:m.context.originType,nodeId:m.context.originNodeId,at:m.timestamp},phases:d,finalState:l?{page:l.page,route:l.route,componentName:l.componentName,renderId:l.id,visualFrameId:v}:void 0,startedAt:g,endedAt:w,eventCount:e.length}}u(compileStory,"compileStory"),c(compileStory,"compileStory"),p(compileStory,"compileStory");function f(t){const n=(t.raw??null)?.kind;if(n==="flow-origin"||t.source==="client-runtime"&&n==="user-action"){const e=t.raw;return{kind:"user-action",at:t.timestamp,label:e?.origin?.label??t.title,eventIds:[t.id]}}if(t.source==="react"&&n==="render"){const e=t.raw;return{kind:"render",at:t.timestamp,label:`render ${e?.render?.componentName??"?"}`,eventIds:[t.id],details:e?.render?{componentName:e.render.componentName,durationMs:e.render.actualDurationMs}:void 0}}if(t.source==="react"&&n==="slot-content-changed"){const e=t.raw,o=e?.slot?.toComponent??"?";return{kind:/spinner|loader|loading/i.test(o)?"loading-ui":"idle-ui",at:t.timestamp,label:`slot ${e?.slot?.slotLogicalId??""} \u2192 ${o}`,eventIds:[t.id]}}if(t.source==="client-runtime"&&n==="route"){const e=t.raw;return{kind:"route-transition",at:t.timestamp,label:`route ${e?.from??""} \u2192 ${e?.url??""}`,eventIds:[t.id]}}if(t.source==="valtio"&&n==="state-update"){const e=t.raw;return{kind:"state-update",at:t.timestamp,label:`${e?.update?.storeId??"?"}.${e?.update?.path??"?"}`,eventIds:[t.id],details:e?.update}}if(t.source==="nestjs"&&n==="server-request"){const e=t.raw;return{kind:"backend-request",at:t.timestamp,label:`${e?.request?.method??"?"} ${e?.request?.route??"?"} \u2192 ${e?.request?.status??"?"}`,eventIds:[t.id],details:e?.request}}if(t.source==="chrome"&&t.category==="network")return{kind:"backend-request",at:t.timestamp,label:t.title,eventIds:[t.id]};if(t.source==="visual"&&n==="visual-violation"){const e=t.raw;return{kind:"visual-violation",at:t.timestamp,label:`${e?.violation?.ruleType??"rule"} ${e?.violation?.ruleId??""}`,eventIds:[t.id]}}}u(f,"f"),c(f,"g"),p(f,"classifyEvent");
1
+ "use strict";var w=Object.defineProperty;var c=(t,a)=>w(t,"name",{value:a,configurable:!0});export function groupByFlow(t){const a=new Map;for(const r of t){const e=r.context.flowId;if(!e)continue;let o=a.get(e);o||(o=[],a.set(e,o)),o.push(r)}return a}c(groupByFlow,"groupByFlow");export function compileStory(t,a={}){let r,e;if(a.flowId)e=a.flowId,r=t.filter(i=>i.context.flowId===e);else{const i=t.find(n=>n.context.flowId);if(!i)return;e=i.context.flowId,r=t.filter(n=>n.context.flowId===e)}if(r.length===0)return;r.sort((i,n)=>i.timestamp-n.timestamp);const o=1e3;r.length>o&&(r=[r[0],...r.slice(r.length-(o-1))]);const u=r[0],s=[];let l,f;for(const i of r){const n=g(i);if(n){if(s.push(n),n.kind==="render"||n.kind==="final-render"){const d=i.raw;d?.render&&(l={id:d.render.id,page:d.render.page,route:d.render.route,componentName:d.render.componentName})}else if(i.source==="visual"&&n.kind==="visual-violation"){const d=i.raw;d?.frame&&(f=d.frame.id)}}}for(let i=s.length-1;i>=0;i--)if(s[i].kind==="render"){s[i]={...s[i],kind:"final-render"};break}const m=r[0].timestamp,p=r[r.length-1].timestamp;return{flowId:e,origin:{type:u.context.originType,nodeId:u.context.originNodeId,at:u.timestamp},phases:s,finalState:l?{page:l.page,route:l.route,componentName:l.componentName,renderId:l.id,visualFrameId:f}:void 0,startedAt:m,endedAt:p,eventCount:r.length}}c(compileStory,"compileStory");function g(t){const r=(t.raw??null)?.kind;if(r==="flow-origin"||t.source==="client-runtime"&&r==="user-action"){const e=t.raw;return{kind:"user-action",at:t.timestamp,label:e?.origin?.label??t.title,eventIds:[t.id]}}if(t.source==="react"&&r==="render"){const e=t.raw;return{kind:"render",at:t.timestamp,label:`render ${e?.render?.componentName??"?"}`,eventIds:[t.id],details:e?.render?{componentName:e.render.componentName,durationMs:e.render.actualDurationMs}:void 0}}if(t.source==="react"&&r==="slot-content-changed"){const e=t.raw,o=e?.slot?.toComponent??"?";return{kind:/spinner|loader|loading/i.test(o)?"loading-ui":"idle-ui",at:t.timestamp,label:`slot ${e?.slot?.slotLogicalId??""} \u2192 ${o}`,eventIds:[t.id]}}if(t.source==="client-runtime"&&r==="route"){const e=t.raw;return{kind:"route-transition",at:t.timestamp,label:`route ${e?.from??""} \u2192 ${e?.url??""}`,eventIds:[t.id]}}if(t.source==="valtio"&&r==="state-update"){const e=t.raw;return{kind:"state-update",at:t.timestamp,label:`${e?.update?.storeId??"?"}.${e?.update?.path??"?"}`,eventIds:[t.id],details:e?.update}}if(t.source==="nestjs"&&r==="server-request"){const e=t.raw;return{kind:"backend-request",at:t.timestamp,label:`${e?.request?.method??"?"} ${e?.request?.route??"?"} \u2192 ${e?.request?.status??"?"}`,eventIds:[t.id],details:e?.request}}if(t.source==="chrome"&&t.category==="network")return{kind:"backend-request",at:t.timestamp,label:t.title,eventIds:[t.id]};if(t.source==="visual"&&r==="visual-violation"){const e=t.raw;return{kind:"visual-violation",at:t.timestamp,label:`${e?.violation?.ruleType??"rule"} ${e?.violation?.ruleId??""}`,eventIds:[t.id]}}}c(g,"classifyEvent");
package/lib/thresholds.js CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var s=(e,r)=>l(e,"name",{value:r,configurable:!0});var u=Object.defineProperty,t=s((e,r)=>u(e,"name",{value:r,configurable:!0}),"s"),c=Object.defineProperty,i=t((e,r)=>c(e,"name",{value:r,configurable:!0}),"t");export const DEFAULT_THRESHOLDS={dbInLoop:5,nPlusOne:3,renderStorm:5,slowRouteMs:500,slowRenderMs:16,slowQueryMs:100};export function resolveThresholds(e){const r={...DEFAULT_THRESHOLDS};if(e)for(const n of Object.keys(DEFAULT_THRESHOLDS)){const o=e[n];typeof o=="number"&&Number.isFinite(o)&&o>=0&&(r[n]=o)}return r}s(resolveThresholds,"resolveThresholds"),t(resolveThresholds,"resolveThresholds"),i(resolveThresholds,"resolveThresholds");
1
+ "use strict";var r=Object.defineProperty;var t=(o,e)=>r(o,"name",{value:e,configurable:!0});export const DEFAULT_THRESHOLDS={dbInLoop:5,nPlusOne:3,renderStorm:5,slowRouteMs:500,slowRenderMs:16,slowQueryMs:100};export function resolveThresholds(o){const e={...DEFAULT_THRESHOLDS};if(o)for(const n of Object.keys(DEFAULT_THRESHOLDS)){const s=o[n];typeof s=="number"&&Number.isFinite(s)&&s>=0&&(e[n]=s)}return e}t(resolveThresholds,"resolveThresholds");
package/lib/ulid.js CHANGED
@@ -1 +1 @@
1
- "use strict";var s=Object.defineProperty;var o=(e,n)=>s(e,"name",{value:n,configurable:!0});var b=Object.defineProperty,a=o((e,n)=>b(e,"name",{value:n,configurable:!0}),"r"),m=Object.defineProperty,u=a((e,n)=>m(e,"name",{value:n,configurable:!0}),"r");const f="0123456789ABCDEFGHJKMNPQRSTVWXYZ",g=16;function c(e,n){let r="",t=e;for(let l=n-1;l>=0;l--){const d=t%32;r=f[d]+r,t=(t-d)/32}return r}o(c,"l"),a(c,"s"),u(c,"encodeTime");function i(e){const n=new Uint8Array(e);globalThis.crypto.getRandomValues(n);let r="";for(let t=0;t<e;t++)r+=f[(n[t]??0)&31];return r}o(i,"s"),a(i,"a"),u(i,"encodeRandom");export function ulid(e=Date.now()){return c(e,10)+i(16)}o(ulid,"ulid"),a(ulid,"ulid"),u(ulid,"ulid");
1
+ "use strict";var l=Object.defineProperty;var r=(t,o)=>l(t,"name",{value:o,configurable:!0});const i="0123456789ABCDEFGHJKMNPQRSTVWXYZ",A=16;function s(t,o){let e="",n=t;for(let c=o-1;c>=0;c--){const u=n%32;e=i[u]+e,n=(n-u)/32}return e}r(s,"encodeTime");function a(t){const o=new Uint8Array(t);globalThis.crypto.getRandomValues(o);let e="";for(let n=0;n<t;n++)e+=i[(o[n]??0)&31];return e}r(a,"encodeRandom");export function ulid(t=Date.now()){return s(t,10)+a(16)}r(ulid,"ulid");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/core",
3
- "version": "1.18.14",
3
+ "version": "1.20.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -19,7 +19,7 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@lensmcp/protocol-types": "1.18.14",
22
+ "@lensmcp/protocol-types": "1.20.0",
23
23
  "tslib": "^2.3.0"
24
24
  },
25
25
  "license": "Apache-2.0",