@lensmcp/core 1.25.77 → 1.25.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/redact.js +1 -1
  2. package/package.json +2 -2
package/lib/redact.js CHANGED
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var f=(t,e)=>_(t,"name",{value:e,configurable:!0});var I=Object.defineProperty,l=f((t,e)=>I(t,"name",{value:e,configurable:!0}),"a");export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const v=["token","secret","password","passwd","apikey","credential","assertion","signature"],Z=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]),R=/^(?:(?:prompt|completion|total|input|output|cache|cached|cacheread|cachewrite|reasoning|thinking|max|min|remaining|used|billed)tokens|tokens?(?:count|used|limit|remaining))$/;export function isSecretParam(t){const e=d.get(t);if(e!==void 0)return e;const r=m(t);return t.length<=64&&d.size<C&&d.set(t,r),r}f(isSecretParam,"isSecretParam"),l(isSecretParam,"isSecretParam");const P=new Set(["sess","csrf","xsrf","refresh","nonce","reset","magic","mfa","2fa","verify","verification","invite","login"]);export function isSecretCacheKey(t){for(const e of t.split(/[:/{}#]+/))if(!(!e||e.length>64)){if(isSecretParam(e))return!0;for(const r of e.toLowerCase().split(/[-_.]+/))if(P.has(r))return!0}return!1}f(isSecretCacheKey,"isSecretCacheKey"),l(isSecretCacheKey,"isSecretCacheKey");const C=4096,d=new Map;function m(t){const e=t.toLowerCase();if(R.test(e.replace(/[-_.]+/g,"")))return!1;if(v.some(r=>e.includes(r)))return!0;for(const r of e.split(/[-_.]+/))if(r&&Z.has(r))return!0;return!1}f(m,"N"),l(m,"judgeParam");const O=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,N=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(t){return t&&t.replace(O,`$1${REDACTED}@`).replace(N,(e,r,n)=>isSecretParam(n)?`${r}${n}=${REDACTED}`:e)}f(redactUrlParams,"redactUrlParams"),l(redactUrlParams,"redactUrlParams");export function redactUrl(t){return t&&clip(redactUrlParams(t),1024)}f(redactUrl,"redactUrl"),l(redactUrl,"redactUrl");const D=/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,M=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,K=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)((?:(?:bearer|basic)\s+)?[^\s"',;]{4,})\3/gi,j=/[@=:]|eyJ|bearer|basic/i;export function redactText(t){return j.test(t)?redactUrlParams(t).replace(K,(e,r,n,a)=>`${r}${n}${a}${REDACTED}${a}`).replace(D,REDACTED).replace(M,(e,r)=>`${r} ${REDACTED}`):t}f(redactText,"redactText"),l(redactText,"redactText");const L=[/\bsk-(?:ant-|proj-|live-|test-)?[A-Za-z0-9_-]{20,}/g,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,/\bgh[pousr]_[A-Za-z0-9]{30,}/g,/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,/\bAIza[0-9A-Za-z_-]{35}\b/g],h="-----BEGIN ",U=4096;function S(t){if(!t.includes("PRIVATE KEY-----"))return t;let e="",r=0,n=!1;for(;;){const a=t.indexOf(h,r);if(a===-1)break;const o=t.indexOf("-----",a+h.length);if(o===-1)break;const s=t.slice(a+h.length,o);if(!/^[A-Z ]{0,30}PRIVATE KEY$/.test(s)){e+=t.slice(r,o+5),r=o+5;continue}e+=t.slice(r,a);const i=n?-1:t.indexOf("-----END ",o+5);let c;if(i===-1)n=!0,c=Math.min(t.length,o+5+U);else{const u=t.indexOf("-----",i+9);c=u===-1?t.length:u+5}e+=REDACTED,r=c}return e+t.slice(r)}f(S,"y"),l(S,"redactPrivateKeys");const H=/"([A-Za-z0-9_.-]{1,64})"\s*:\s*"((?:[^"\\]|\\.){1,8192})"/g,V=/\b([A-Za-z][A-Za-z0-9_-]{1,40})(\s*[:=]\s*)([^\s"'`,;&)}\]]{8,200})/g,X=/(token|secret|pass(?:word|wd)?|pwd|api[-_]?key|apikey|credential|authorization|bearer)/i;function w(t){return t.replace(H,(e,r)=>isSecretParam(r)?`"${r}": "${REDACTED}"`:e).replace(V,(e,r,n)=>X.test(r)&&isSecretParam(r)?`${r}${n}${REDACTED}`:e)}f(w,"U"),l(w,"redactStructured");export function redactSecretText(t){let e=w(redactText(S(t)));for(const r of L)e=e.replace(r,REDACTED);return e}f(redactSecretText,"redactSecretText"),l(redactSecretText,"redactSecretText");export function clip(t,e){return t.length<=e?t:`${t.slice(0,e)}\u2026[lensmcp truncated: ${t.length-e} more chars]`}f(clip,"clip"),l(clip,"clip");export function safeText(t,e=4096){if(t!==void 0)return clip(redactText(t),e)}f(safeText,"safeText"),l(safeText,"safeText");export function safeTitle(t){return clip(redactText(t),300)}f(safeTitle,"safeTitle"),l(safeTitle,"safeTitle");const q=6,G=64,J=/^TS\d{1,5}$/,Y=l((t,e)=>t==="code"&&typeof e=="string"&&J.test(e),"isDiagnosticCode");export function redactDeep(t,e=0,r=q){if(typeof t=="string")return redactText(t);if(t===null||typeof t!="object"||e>=r)return t;if(Array.isArray(t)){let s;for(let i=0;i<t.length;i++){if(i>=G){s&&s.push(t[i]);continue}const c=t[i],u=redactDeep(c,e+1,r);s?s.push(u):u!==c&&(s=t.slice(0,i),s.push(u))}return s??t}const n=t,a=Object.keys(n);let o;for(let s=0;s<a.length;s++){const i=a[s],c=n[i],u=isSecretParam(i)&&c!==void 0&&c!==null&&!Y(i,c)?REDACTED:redactDeep(c,e+1,r);if(o)o[i]=u;else if(u!==c){o={};for(let p=0;p<s;p++)o[a[p]]=n[a[p]];o[i]=u}}return o??t}f(redactDeep,"redactDeep"),l(redactDeep,"redactDeep");const A=String.raw`(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`,x=String.raw`${A}(?:\s*\.\s*${A})*`,B=String.raw`(?:=|<>|!=|<=|>=|<|>|(?:NOT\s+)?I?LIKE|IS\s+(?:NOT\s+)?DISTINCT\s+FROM)`,F=new RegExp(String.raw`(${x})\s*${B}\s*(?:[A-Za-z_]\w*\s*\(\s*)?\$(\d+)`,"gi"),W=new RegExp(String.raw`(${x})\s+(?:NOT\s+)?IN\s*\(([^()]*)\)`,"gi"),Q=new RegExp(String.raw`\bINSERT\s+INTO\s+${x}\s*\(([^()]*)\)\s*VALUES\s*`,"gi"),tt=new RegExp(A,"g"),z=/\$(\d+)/g,T=16384,et=256,rt=4096,g=new Map,b=l(t=>{const e=t.match(tt)??[],r=e[e.length-1]??"";return r.startsWith('"')?r.slice(1,-1).replace(/""/g,'"'):r},"lastIdent");function k(t,e){const r=[];let n=e;for(;;){for(;n<t.length&&/\s/.test(t[n]);)n++;if(t[n]!=="(")return r;const a=[];let o=n+1,s=0,i=!1;for(n+=1;n<t.length;n++){const c=t[n];if(i){c==="'"&&(i=!1);continue}if(c==="'")i=!0;else if(c==="(")s++;else if(c===")"){if(s===0)break;s--}else c===","&&s===0&&(a.push(t.slice(o,n)),o=n+1)}if(n>=t.length)return r;for(a.push(t.slice(o,n)),r.push(a),n+=1;n<t.length&&/\s/.test(t[n]);)n++;if(t[n]!==",")return r;n+=1}}f(k,"q"),l(k,"valuesTuples");function y(t){const e=t.length<=rt,r=e?g.get(t):void 0;if(r)return r;const n=t.length>T?t.slice(0,T):t,a=new Set,o=l((s,i)=>{i&&isSecretParam(i)&&a.add(Number(s))},"bind");for(const s of n.matchAll(F))o(s[2],b(s[1]));for(const s of n.matchAll(W)){const i=b(s[1]);for(const c of s[2].matchAll(z))o(c[1],i)}for(const s of n.matchAll(Q)){const i=s[1].split(",").map(c=>b(c.trim()));for(const c of k(n,(s.index??0)+s[0].length))c.forEach((u,p)=>{const $=i[p];if($)for(const E of u.matchAll(z))o(E[1],$)})}if(e){if(g.size>=et){const s=g.keys().next().value;s!==void 0&&g.delete(s)}g.set(t,a)}return a}f(y,"ee"),l(y,"secretPlaceholders");export function redactSqlParams(t,e){if(e.length===0||!t.includes("$"))return e;const r=y(t);if(r.size===0)return e;let n=!1;const a=e.map((o,s)=>o==null||!r.has(s+1)?o:(n=!0,REDACTED));return n?a:e}f(redactSqlParams,"redactSqlParams"),l(redactSqlParams,"redactSqlParams");
1
+ "use strict";var v=Object.defineProperty;var f=(e,t)=>v(e,"name",{value:t,configurable:!0});var R=Object.defineProperty,l=f((e,t)=>R(e,"name",{value:t,configurable:!0}),"a");export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const O=["token","secret","password","passwd","apikey","credential","assertion","signature"],Z=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]),C=/^(?:(?:prompt|completion|total|input|output|cache|cached|cacheread|cachewrite|reasoning|thinking|max|min|remaining|used|billed)tokens|tokens?(?:count|used|limit|remaining))$/;export function isSecretParam(e){const t=d.get(e);if(t!==void 0)return t;const r=m(e);return e.length<=64&&d.size<N&&d.set(e,r),r}f(isSecretParam,"isSecretParam"),l(isSecretParam,"isSecretParam");const P=new Set(["sess","csrf","xsrf","refresh","nonce","reset","magic","mfa","2fa","verify","verification","invite","login"]);export function isSecretCacheKey(e){for(const t of e.split(/[:/{}#]+/))if(!(!t||t.length>64)){if(isSecretParam(t))return!0;for(const r of t.toLowerCase().split(/[-_.]+/))if(P.has(r))return!0}return!1}f(isSecretCacheKey,"isSecretCacheKey"),l(isSecretCacheKey,"isSecretCacheKey");const N=4096,d=new Map;function m(e){const t=e.toLowerCase();if(C.test(t.replace(/[-_.]+/g,"")))return!1;if(O.some(r=>t.includes(r)))return!0;for(const r of t.split(/[-_.]+/))if(r&&Z.has(r))return!0;return!1}f(m,"$"),l(m,"judgeParam");const D=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,M=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(e){return e&&e.replace(D,`$1${REDACTED}@`).replace(M,(t,r,n)=>isSecretParam(n)?`${r}${n}=${REDACTED}`:t)}f(redactUrlParams,"redactUrlParams"),l(redactUrlParams,"redactUrlParams");export function redactUrl(e){return e&&clip(redactUrlParams(e),1024)}f(redactUrl,"redactUrl"),l(redactUrl,"redactUrl");const j=/[A-Za-z0-9_.-]{15,}/g;function S(e){for(let t=0;;){const r=e.indexOf("eyJ",t);if(r===-1||e.length-r-3<6)return-1;if(r===0||e.charCodeAt(r-1)===45)return r;t=r+1}}f(S,"D"),l(S,"jwtStart");function w(e){if(e.indexOf("eyJ")===-1||e.indexOf(".")===-1)return e;const t=e.split(".");let r="";for(let n=0;n<t.length;n++){const o=t[n];if(n+2<t.length&&t[n+1].length>=4){const i=S(o);if(i!==-1){r+=o.slice(0,i)+REDACTED,n+=2,n<t.length-1&&(r+=".");continue}}r+=o,n<t.length-1&&(r+=".")}return r}f(w,"x"),l(w,"redactJwtRun");const K=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,L=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)((?:(?:bearer|basic)\s+)?[^\s"',;]{4,})\3/gi,U=/[@=:]|eyJ|bearer|basic/i;export function redactText(e){return U.test(e)?redactUrlParams(e).replace(L,(t,r,n,o)=>`${r}${n}${o}${REDACTED}${o}`).replace(j,w).replace(K,(t,r)=>`${r} ${REDACTED}`):e}f(redactText,"redactText"),l(redactText,"redactText");const J=[/\bsk-(?:ant-|proj-|live-|test-)?[A-Za-z0-9_-]{20,}/g,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,/\bgh[pousr]_[A-Za-z0-9]{30,}/g,/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,/\bAIza[0-9A-Za-z_-]{35}\b/g],h="-----BEGIN ",H=4096;function T(e){if(!e.includes("PRIVATE KEY-----"))return e;let t="",r=0,n=!1;for(;;){const o=e.indexOf(h,r);if(o===-1)break;const i=e.indexOf("-----",o+h.length);if(i===-1)break;const s=e.slice(o+h.length,i);if(!/^[A-Z ]{0,30}PRIVATE KEY$/.test(s)){t+=e.slice(r,i+5),r=i+5;continue}t+=e.slice(r,o);const c=n?-1:e.indexOf("-----END ",i+5);let a;if(c===-1)n=!0,a=Math.min(e.length,i+5+H);else{const u=e.indexOf("-----",c+9);a=u===-1?e.length:u+5}t+=REDACTED,r=a}return t+e.slice(r)}f(T,"U"),l(T,"redactPrivateKeys");const V=/"([A-Za-z0-9_.-]{1,64})"\s*:\s*"((?:[^"\\]|\\.){1,8192})"/g,X=/\b([A-Za-z][A-Za-z0-9_-]{1,40})(\s*[:=]\s*)([^\s"'`,;&)}\]]{8,200})/g,q=/(token|secret|pass(?:word|wd)?|pwd|api[-_]?key|apikey|credential|authorization|bearer)/i;function y(e){return e.replace(V,(t,r)=>isSecretParam(r)?`"${r}": "${REDACTED}"`:t).replace(X,(t,r,n)=>q.test(r)&&isSecretParam(r)?`${r}${n}${REDACTED}`:t)}f(y,"j"),l(y,"redactStructured");export function redactSecretText(e){let t=y(redactText(T(e)));for(const r of J)t=t.replace(r,REDACTED);return t}f(redactSecretText,"redactSecretText"),l(redactSecretText,"redactSecretText");export function clip(e,t){return e.length<=t?e:`${e.slice(0,t)}\u2026[lensmcp truncated: ${e.length-t} more chars]`}f(clip,"clip"),l(clip,"clip");export function safeText(e,t=4096){if(e!==void 0)return clip(redactText(e),t)}f(safeText,"safeText"),l(safeText,"safeText");export function safeTitle(e){return clip(redactText(e),300)}f(safeTitle,"safeTitle"),l(safeTitle,"safeTitle");const G=6,Y=64,B=/^TS\d{1,5}$/,F=l((e,t)=>e==="code"&&typeof t=="string"&&B.test(t),"isDiagnosticCode");export function redactDeep(e,t=0,r=G){if(typeof e=="string")return redactText(e);if(e===null||typeof e!="object"||t>=r)return e;if(Array.isArray(e)){let s;for(let c=0;c<e.length;c++){if(c>=Y){s&&s.push(e[c]);continue}const a=e[c],u=redactDeep(a,t+1,r);s?s.push(u):u!==a&&(s=e.slice(0,c),s.push(u))}return s??e}const n=e,o=Object.keys(n);let i;for(let s=0;s<o.length;s++){const c=o[s],a=n[c],u=isSecretParam(c)&&a!==void 0&&a!==null&&!F(c,a)?REDACTED:redactDeep(a,t+1,r);if(i)i[c]=u;else if(u!==a){i={};for(let p=0;p<s;p++)i[o[p]]=n[o[p]];i[c]=u}}return i??e}f(redactDeep,"redactDeep"),l(redactDeep,"redactDeep");const A=String.raw`(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`,x=String.raw`${A}(?:\s*\.\s*${A})*`,W=String.raw`(?:=|<>|!=|<=|>=|<|>|(?:NOT\s+)?I?LIKE|IS\s+(?:NOT\s+)?DISTINCT\s+FROM)`,Q=new RegExp(String.raw`(${x})\s*${W}\s*(?:[A-Za-z_]\w*\s*\(\s*)?\$(\d+)`,"gi"),ee=new RegExp(String.raw`(${x})\s+(?:NOT\s+)?IN\s*\(([^()]*)\)`,"gi"),te=new RegExp(String.raw`\bINSERT\s+INTO\s+${x}\s*\(([^()]*)\)\s*VALUES\s*`,"gi"),re=new RegExp(A,"g"),k=/\$(\d+)/g,z=16384,ne=256,se=4096,g=new Map,$=l(e=>{const t=e.match(re)??[],r=t[t.length-1]??"";return r.startsWith('"')?r.slice(1,-1).replace(/""/g,'"'):r},"lastIdent");function E(e,t){const r=[];let n=t;for(;;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!=="(")return r;const o=[];let i=n+1,s=0,c=!1;for(n+=1;n<e.length;n++){const a=e[n];if(c){a==="'"&&(c=!1);continue}if(a==="'")c=!0;else if(a==="(")s++;else if(a===")"){if(s===0)break;s--}else a===","&&s===0&&(o.push(e.slice(i,n)),i=n+1)}if(n>=e.length)return r;for(o.push(e.slice(i,n)),r.push(o),n+=1;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!==",")return r;n+=1}}f(E,"et"),l(E,"valuesTuples");function _(e){const t=e.length<=se,r=t?g.get(e):void 0;if(r)return r;const n=e.length>z?e.slice(0,z):e,o=new Set,i=l((s,c)=>{c&&isSecretParam(c)&&o.add(Number(s))},"bind");for(const s of n.matchAll(Q))i(s[2],$(s[1]));for(const s of n.matchAll(ee)){const c=$(s[1]);for(const a of s[2].matchAll(k))i(a[1],c)}for(const s of n.matchAll(te)){const c=s[1].split(",").map(a=>$(a.trim()));for(const a of E(n,(s.index??0)+s[0].length))a.forEach((u,p)=>{const b=c[p];if(b)for(const I of u.matchAll(k))i(I[1],b)})}if(t){if(g.size>=ne){const s=g.keys().next().value;s!==void 0&&g.delete(s)}g.set(e,o)}return o}f(_,"nt"),l(_,"secretPlaceholders");export function redactSqlParams(e,t){if(t.length===0||!e.includes("$"))return t;const r=_(e);if(r.size===0)return t;let n=!1;const o=t.map((i,s)=>i==null||!r.has(s+1)?i:(n=!0,REDACTED));return n?o:t}f(redactSqlParams,"redactSqlParams"),l(redactSqlParams,"redactSqlParams");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/core",
3
- "version": "1.25.77",
3
+ "version": "1.25.79",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -94,7 +94,7 @@
94
94
  }
95
95
  },
96
96
  "dependencies": {
97
- "@lensmcp/protocol-types": "1.25.77",
97
+ "@lensmcp/protocol-types": "1.25.79",
98
98
  "tslib": "^2.3.0"
99
99
  },
100
100
  "license": "Apache-2.0",