@webority/web-core 0.77.2 → 0.78.1
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/dist/logger/logger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getConfigValue as e}from"../config/index.js";import{redact as t,redactString as
|
|
2
|
-
`)[1]?.trim();return t?`${e.message}::${t}`:e.message},x=()=>{for(;v.size>y;){let e=v.keys().next().value;if(e===void 0)return;v.delete(e)}},S=e=>{if(m.dedupeWindowMs<=0)return{forward:!0};let t=Date.now(),n=v.get(e);if(!n||t-n.windowStart>=m.dedupeWindowMs){let r=n?.suppressedCount??0;return v.set(e,{windowStart:t,count:1,suppressedCount:0}),x(),r>0?{forward:!0,suppressedCount:r}:{forward:!0}}return n.count+=1,n.count>m.dedupeMaxPerWindow?(n.suppressedCount+=1,{forward:!1}):{forward:!0}},C=(e,t)=>{let n={...u};return h!==null&&(n.screen=h),t&&(n.suppressedCount=t),{...n,...e}},w=(e,t)=>{let{forward:n,suppressedCount:r}=S(b(e));n&&
|
|
1
|
+
import{getConfigValue as e}from"../config/index.js";import{redact as t,redactError as n,redactString as r}from"./redact.js";var i=[`debug`,`info`,`warn`,`error`],a=t=>{let n=e(`logLevel`,`info`);return i.indexOf(t)>=i.indexOf(n)},o=()=>e(`loggingEnabled`,!0),s=null,c=e=>{s=e},l=e=>{if(e)try{e()}catch{}},u=null,d=e=>e==null?null:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e),f=e=>{if(u=e,e)for(let[t,n]of Object.entries(e))l(()=>s?.setAttribute?.(t,d(n)))},p=()=>u,m={dedupeWindowMs:5e3,dedupeMaxPerWindow:1,screenHistoryLimit:20},h=null,g=[],_=e=>{m={...m,...e},g.length>m.screenHistoryLimit&&(g=g.slice(g.length-m.screenHistoryLimit))},v=new Map,y=200,b=e=>{let t=e.stack?.split(`
|
|
2
|
+
`)[1]?.trim();return t?`${e.message}::${t}`:e.message},x=()=>{for(;v.size>y;){let e=v.keys().next().value;if(e===void 0)return;v.delete(e)}},S=e=>{if(m.dedupeWindowMs<=0)return{forward:!0};let t=Date.now(),n=v.get(e);if(!n||t-n.windowStart>=m.dedupeWindowMs){let r=n?.suppressedCount??0;return v.set(e,{windowStart:t,count:1,suppressedCount:0}),x(),r>0?{forward:!0,suppressedCount:r}:{forward:!0}}return n.count+=1,n.count>m.dedupeMaxPerWindow?(n.suppressedCount+=1,{forward:!1}):{forward:!0}},C=(e,t)=>{let n={...u};return h!==null&&(n.screen=h),t&&(n.suppressedCount=t),{...n,...e}},w=(e,t)=>{let{forward:n,suppressedCount:r}=S(b(e));n&&l(()=>s?.recordError?.(e,C(t,r)))},T=(e,...n)=>{!o()||!a(`debug`)||console.debug(`[DEBUG]: ${r(e)}`,...t(n))},E=(e,...n)=>{let i=r(e),c=t(n);!o()||!a(`info`)||(console.info(`[INFO]: ${i}`,...c),l(()=>s?.log?.(`info`,i,c)))},D=(e,...n)=>{let i=r(e),c=t(n);!o()||!a(`warn`)||(console.warn(`[WARNING]: ${i}`,...c),l(()=>s?.log?.(`warn`,i,c)))},O=(e,...i)=>{let c=r(e),u=t(i);o()&&a(`error`)&&console.error(`[ERROR]: ${c}`,...u),l(()=>s?.log?.(`error`,c,u));let d=i[0];d!==void 0&&w(n(d),{source:`Logger.error`,message:c})},k=(e,n)=>{let i=r(e),c=t(n);o()&&a(`info`)&&console.info(`[BREADCRUMB]: ${i}`,c??``),l(()=>s?.breadcrumb?.(i,c))},A=(e,r)=>{let i=n(e),s=t(r);o()&&a(`error`)&&console.error(`[RECORDED]: ${i.message}`,s??``),w(i,s)},j=e=>typeof e==`object`&&e?e:null,M=(e,t)=>{let n=j(e);if(!n)return null;let r=typeof n.get==`function`?n.get.call(e,t):n[t]??n[t.toLowerCase()];return typeof r==`string`&&r!==``?r:null},N={debug:T,info:E,warn:D,error:O,breadcrumb:k,recordError:A,requestFailed:(n,i={})=>{let{label:c,expectedStatuses:u=[],...d}=i,f=j(n),p=j(f?.config),m=j(f?.response),h=j(m?.data),g=typeof m?.status==`number`?m.status:null,_=typeof p?.method==`string`?p.method.toUpperCase():null,v=typeof p?.url==`string`?p.url.split(`?`)[0]??null:null,y=c??([_,v].filter(Boolean).join(` `)||`Request`);if(f?.name===`CanceledError`||f?.code===`ERR_CANCELED`||f?.__CANCEL__===!0){E(`${y} canceled`);return}if(g!==null&&u.includes(g)){E(`${y} refused (${g})`);return}let b=typeof f?.message==`string`?f.message:n instanceof Error?n.message:null,x=r(g===null?`${y} failed`:`${y} failed (${g})`);o()&&a(`error`)&&console.error(`[ERROR]: ${x}`,r(b??``)),l(()=>s?.log?.(`error`,x,[]));let S=e(`correlationIdHeader`,null),C=t({source:`Logger.requestFailed`,label:y,status:g,method:_,path:v,code:typeof h?.code==`string`?h.code:null,traceId:typeof h?.traceId==`string`?h.traceId:null,correlationId:S?M(p?.headers,S):null,detail:b,...d});w(Error(x),C)},setUser:(e,t)=>{l(()=>s?.setUser?.(e,t))},setAttribute:(e,t)=>{l(()=>s?.setAttribute?.(e,t))},trackScreen:(e,t)=>{e!==h&&(h=e,g.push(e),g.length>m.screenHistoryLimit&&(g=g.slice(g.length-m.screenHistoryLimit)),k(`Screen: ${e}`,t))},getCurrentScreen:()=>h,getScreenHistory:()=>[...g]};export{N as Logger,_ as configureLogger,p as getDeviceContext,f as setDeviceContext,c as setRemoteLogger};
|
package/dist/logger/redact.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=`[REDACTED]`,t
|
|
1
|
+
var e=`[REDACTED]`,t=/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi,n=/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g,r=[`token`,`accesstoken`,`refreshtoken`,`password`,`authorization`,`cookie`,`setcookie`,`xapikey`,`apikey`,`secret`,`clientsecret`,`otp`,`pin`,`aadhaar`,`aadhaarnumber`,`pan`,`pannumber`,`accountnumber`,`cvv`,`cardnumber`],i=new Set(r),a=new Set([`config`,`request`,`data`]),o=e=>e.toLowerCase().replace(/[-_]/g,``),s=RegExp(`(?<![a-z])(["']?(?:${r.map(e=>[...e].join(`[-_]?`)).join(`|`)})["']?\\s*[:=]\\s*)(?:"(?:[^"\\\\]|\\\\.)*"|'[^']*'|[^\\s,;&}]+)`,`gi`),c=r=>r.replace(t,`Bearer ${e}`).replace(n,e).replace(s,(t,n)=>`${n}"${e}"`),l=e=>typeof e==`object`&&e?e:null,u=e=>e instanceof Error||e.isAxiosError===!0,d=e=>{let t=e,n=l(t.config),r=l(t.response);return{name:typeof t.name==`string`?t.name:`Error`,message:c(typeof t.message==`string`?t.message:``),stack:typeof t.stack==`string`?c(t.stack):null,code:typeof t.code==`string`?t.code:null,status:typeof r?.status==`number`?r.status:null,method:typeof n?.method==`string`?n.method.toUpperCase():null,url:typeof n?.url==`string`?n.url.split(/[?#]/)[0]??null:null}},f=(t,n,r)=>{if(typeof t==`string`)return c(t);if(typeof t!=`object`||!t)return t;if(u(t))return d(t);if(t instanceof Date)return t;if(r.has(t))return`[Circular]`;if(n>=6)return`[Truncated]`;r.add(t);try{if(Array.isArray(t))return t.map(e=>f(e,n+1,r));let s={};for(let[c,l]of Object.entries(t)){let t=o(c);a.has(t)?s[c]=`[OMITTED]`:i.has(t)?s[c]=e:s[c]=f(l,n+1,r)}return s}finally{r.delete(t)}},p=e=>f(e,0,new Set),m=e=>{if(typeof e==`object`&&e&&u(e)){let t=d(e),n=Error(t.message);return n.name=t.name,t.stack!==null&&(n.stack=t.stack),n}let t=p(e);if(typeof t==`string`)return Error(t);try{return Error(JSON.stringify(t))}catch{return Error(String(t))}};export{p as redact,m as redactError,c as redactString};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const redactString: (input: string) => string;
|
|
2
|
-
/** Returns a copy with secrets masked
|
|
2
|
+
/** Returns a copy with secrets masked. An Error comes back as its summary, never as the Error itself. */
|
|
3
3
|
export declare const redact: <T>(value: T) => T;
|
|
4
|
+
/** An Error safe to hand to a sink: the original name and stack, a redacted message, and no request data. */
|
|
5
|
+
export declare const redactError: (input: unknown) => Error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.1",
|
|
4
4
|
"description": "Platform layer for Webority React web portals: HTTP clients with single-flight token refresh, auth store, API error extraction, RTK Query base query, logger, formatters, storage, version check and route guards. No UI.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|