snapper-sdk
Version:
An SDK for building applications on top of Snapper.
2 lines • 1.53 kB
JavaScript
;var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var l=(t,e)=>{for(var s in e)a(t,s,{get:e[s],enumerable:!0})},m=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!d.call(t,r)&&r!==s&&a(t,r,{get:()=>e[r],enumerable:!(n=c(e,r))||n.enumerable});return t};var p=t=>m(a({},"__esModule",{value:!0}),t);var h={};l(h,{SESSION_KEY:()=>g,STORAGE_KEY:()=>o,getSessionKey:()=>f,updateReqHistory:()=>u});module.exports=p(h);var g="ray_tab_hash",o="ray_req_hash",f=()=>{if(typeof window===void 0)return"";let t=sessionStorage.getItem(g);return t||(t=`ray-${Date.now()}`,sessionStorage.setItem(g,t)),t},u=async({logCount:t=1e3,removeLastLog:e,...s})=>{if(typeof window===void 0)return new Promise(r=>r());let n=JSON.parse(localStorage.getItem(o)||"[]").slice(0,t-1);e&&n.pop(),new Blob([JSON.stringify(s.data)]).size>1024&&(s.data=JSON.stringify(s.data).substring(0,200)+"..."),n.unshift({...s,time:Date.now(),session:f()});try{localStorage.setItem(o,JSON.stringify(n))}catch{if(e){let r=!1,y=JSON.stringify(s.data).substring(0,100);for(n[0].data=y+(y.length>100?"...":"");!r;){n.pop();let i=JSON.stringify(s.data).substring(0,100);n[0].data=i+(i.length>100?"...":"");try{localStorage.setItem(o,JSON.stringify(n)),r=!0}catch{r=!1}}return new Promise(i=>i())}return u({...s,logCount:t,removeLastLog:!0})}};0&&(module.exports={SESSION_KEY,STORAGE_KEY,getSessionKey,updateReqHistory});
//# sourceMappingURL=utils.js.map