@lognroll/lib 1.0.8 → 1.0.9

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/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LognRoll=t():e.LognRoll=t()}(this,(()=>(()=>{"use strict";var e={297:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Core=void 0;class s{constructor(){this.companyId="",this.userId="",this.config={},this.traits={}}initSession(e,t){(window||{}).lnr=this,this.config=t||{},this.companyId=e;const s=document.createElement("script");let o=(new Date).getTime();s.src=((null==t?void 0:t.logFile)||"https://logger.lognroll.com/logger.lnr.1.0.1.js")+"?cc="+o,s.async=!1,document.head.appendChild(s)}initSessionWithoutScript(e,t){console.log("initSessionWithoutScript",e,t),(window||{}).lnr=this,this.config=t||{},this.companyId=e,this.init()}identifyUser(e,t){this.userId=e,this.traits=t}init(){console.log("init",this.companyId,this.config)}}t.Core=s,t.default=s},508:function(e,t,s){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Network=void 0;const n=o(s(297));class r extends n.default{constructor(){super(),this.responseLogs=[],this.processedResources=new Set,this.resourceMonitorInterval=null,"undefined"!=typeof window&&this.wrap()}isNetworkEnabled(){var e;const t=null===(e=this.config)||void 0===e?void 0:e.network;return void 0===t||!1!==t.isEnabled}sanitizeRequest(e){var t;const s=null===(t=this.config)||void 0===t?void 0:t.network,o=null==s?void 0:s.requestSanitizer;if(!o||"function"!=typeof o)return e;try{return o(e)}catch(t){return console.warn("Error in requestSanitizer:",t),e}}sanitizeResponse(e){var t;const s=null===(t=this.config)||void 0===t?void 0:t.network,o=null==s?void 0:s.responseSanitizer;if(!o||"function"!=typeof o)return e;try{return o(e)}catch(t){return console.warn("Error in responseSanitizer:",t),e}}getResponseLogs(){return[...this.responseLogs]}clearResponseLogs(){this.responseLogs=[],this.processedResources.clear()}monitorResourceTiming(){"undefined"!=typeof window&&window.performance&&window.performance.getEntriesByType&&this.isNetworkEnabled()&&(performance.getEntriesByType("resource").forEach((e=>{if(this.processedResources.has(e.name)||e.name.includes("lognroll"))return;this.processedResources.add(e.name);const t={id:`resource-${e.startTime}`,url:e.name,timestamp:Date.now()-e.duration,method:"GET",initiatorType:"STATIC",body:null},s=this.sanitizeRequest(t);if(null===s)return;const o={startTime:e.startTime,duration:e.duration,fetchStart:e.fetchStart,responseEnd:e.responseEnd,dnsTime:e.domainLookupEnd-e.domainLookupStart,connectTime:e.connectEnd-e.connectStart,ttfb:e.responseStart-e.requestStart,downloadTime:e.responseEnd-e.responseStart},n={url:e.name,status:200,statusText:"OK",headers:{},timing:o,contentType:e.initiatorType,decodedBodySize:e.decodedBodySize,encodedBodySize:e.encodedBodySize,transferSize:e.transferSize,timestamp:Date.now(),responseTime:e.duration},r=this.sanitizeResponse(n),i={type:"network",stage:"response",payload:{request:s,response:null===r?{url:n.url,status:n.status,statusText:n.statusText,timing:n.timing,timestamp:n.timestamp,responseTime:n.responseTime}:r}};this.responseLogs.push(i)})),performance.clearResourceTimings())}startResourceMonitoring(e=1e3){null===this.resourceMonitorInterval&&(this.monitorResourceTiming(),"undefined"!=typeof window&&(this.resourceMonitorInterval=window.setInterval((()=>{this.monitorResourceTiming()}),e)))}stopResourceMonitoring(){null!==this.resourceMonitorInterval&&(clearInterval(this.resourceMonitorInterval),this.resourceMonitorInterval=null)}wrap(){if(!this.isNetworkEnabled())return;this.startResourceMonitoring();const e=new Map,t=window.fetch,s=this;window.fetch=async function(o,n){const r=Date.now().toString(),i="string"==typeof o?o:o.url;if(i.includes("lognroll"))return t(o,n);const a=(null==n?void 0:n.method)||"GET",u=(null==n?void 0:n.body)||null,l={id:r,url:i,initiatorType:"fetch",timestamp:Date.now(),method:a,body:u,headers:(()=>{const e={};return(null==n?void 0:n.headers)&&(n.headers instanceof Headers?n.headers.forEach(((t,s)=>{e[s]=t})):Array.isArray(n.headers)?n.headers.forEach((([t,s])=>{e[t]=s})):Object.assign(e,n.headers)),e})()},d=s.sanitizeRequest(l);if(null===d)return t(o,n);e.set(r,{url:i,timestamp:Date.now(),body:d.body||u});const c=Date.now(),p=e.get(r);try{const i=await t(o,n),a=i.clone(),u=await a.text().catch((()=>null)),l={url:i.url,status:i.status,statusText:i.statusText,headers:(()=>{const e={};return i.headers.forEach(((t,s)=>{e[s]=t})),e})(),body:u,timestamp:Date.now(),responseTime:Date.now()-c},p=s.sanitizeResponse(l),h={type:"network",stage:"response",payload:{request:d,response:null===p?{url:l.url,status:l.status,statusText:l.statusText,timestamp:l.timestamp,responseTime:l.responseTime}:p}};return s.responseLogs.push(h),e.delete(r),i}catch(t){const o={type:"network",stage:"error",payload:{request:d||{id:r,url:i,timestamp:(null==p?void 0:p.timestamp)||Date.now()-100,method:a,body:u},error:{message:t instanceof Error?t.message:"Unknown error",timestamp:Date.now()}}};throw s.responseLogs.push(o),e.delete(r),t}};const o=window.XMLHttpRequest;window.XMLHttpRequest=function(){const t=new o,n=Date.now().toString(),r=t.open;t._requestHeaders={};const i=t.setRequestHeader;t.setRequestHeader=function(e,s){t._requestHeaders[e]=s,i.apply(this,arguments)},t.open=function(o,i){if(i.toString().includes("lognroll"))return r.apply(t,arguments);e.set(n,{url:i.toString(),timestamp:Date.now(),body:null});const a=this,u=this.onreadystatechange;return this.onreadystatechange=function(){var r;if(4===a.readyState){const l=e.get(n),d={id:n,url:i.toString(),initiatorType:"xmlhttprequest",timestamp:(null===(r=e.get(n))||void 0===r?void 0:r.timestamp)||Date.now()-100,method:o||"GET",body:(null==l?void 0:l.body)||null,headers:t._requestHeaders||{}},c=s.sanitizeRequest(d);if(null===c)return e.delete(n),void(u&&u.apply(a,arguments));const p=Date.now()-((null==l?void 0:l.timestamp)||Date.now()),h={url:i.toString(),status:a.status,statusText:a.statusText,headers:a.getAllResponseHeaders().split("\r\n").reduce(((e,t)=>{const[s,o]=t.split(": ");return s&&o&&(e[s]=o),e}),{}),body:a.responseText,timestamp:Date.now(),responseTime:p},m=s.sanitizeResponse(h),f={type:"network",stage:"response",payload:{request:c,response:null===m?{url:h.url,status:h.status,statusText:h.statusText,timestamp:h.timestamp,responseTime:h.responseTime}:m}};s.responseLogs.push(f),e.delete(n),u&&u.apply(a,arguments)}else u&&u.apply(a,arguments)},r.apply(t,arguments)};const a=t.send;return t.send=function(o){if(o instanceof FormData){const t={};for(const[e,s]of o.entries())t[e]=s;o=t;const s=e.get(n);null!=s&&(s.body=t)}else{const t=e.get(n);null!=t&&(t.body=o)}return t.addEventListener("load",(function(t){var s;const o=(null===(s=e.get(n))||void 0===s?void 0:s.url)||"";o.includes("lognroll")||o.includes("/api/v1/requests/")})),t.addEventListener("error",(function(){var r;if(t.responseURL.includes("lognroll"))return;const i={id:n,url:t.responseURL,timestamp:(null===(r=e.get(n))||void 0===r?void 0:r.timestamp)||Date.now()-100,method:t._method||"GET",body:o,headers:t._requestHeaders||{}},a=s.sanitizeRequest(i);if(null===a)return void e.delete(n);const u={type:"network",stage:"error",payload:{request:a,error:{message:"XHR request failed",timestamp:Date.now()}}};s.responseLogs.push(u),e.delete(n)})),a.apply(t,arguments)},t}}}t.Network=r,t.default=r},835:function(e,t,s){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Console=void 0;const n=o(s(508));class r extends n.default{constructor(){super(),this.consoleLogs=[],"undefined"!=typeof window&&(this.originalConsole=window.console,this.initializeConsoleOverrides())}initializeConsoleOverrides(){["log","info","warn","error","debug","trace"].forEach((e=>{const t=this.originalConsole[e];window.console[e]=(...s)=>{const o=Date.now();t.apply(this.originalConsole,s);try{const t=()=>{const e=new WeakSet;return(t,s)=>{if("object"==typeof s&&null!==s){if(e.has(s))return"[Circular]";e.add(s)}return s}},n=e+"<|||>"+s.map((e=>{try{return"object"==typeof e&&null!==e?JSON.stringify(e,t()):String(e)}catch(e){return"[Error stringifying argument]"}})).join("<SPLIT>");this.consoleLogs.push({data:n,timestamp:o})}catch(e){t.apply(this.originalConsole,[e,"error sending log"])}}}))}}t.Console=r,t.default=r}},t={};function s(o){var n=t[o];if(void 0!==n)return n.exports;var r=t[o]={exports:{}};return e[o].call(r.exports,r,r.exports,s),r.exports}var o={};return(()=>{var e=o;const t=s(835);class n extends t.Console{constructor(){super()}}e.default=new n})(),o.default})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LognRoll=t():e.LognRoll=t()}(this,(()=>(()=>{"use strict";var e={297:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Core=void 0;class s{constructor(){this.companyId="",this.userId="",this.config={},this.traits={}}initSession(e,t){(window||{}).lnr=this,this.config=t||{},this.companyId=e;const s=document.createElement("script");let o=(new Date).getTime();s.src=((null==t?void 0:t.logFile)||"https://logger.lognroll.com/logger.lnr.1.0.1.js")+"?cc="+o,s.async=!1,document.head.appendChild(s)}initSessionWithoutScript(e,t){console.log("initSessionWithoutScript",e,t),(window||{}).lnr=this,this.config=t||{},this.companyId=e,this.init()}identifyUser(e,t){this.userId=e,this.traits=t}init(){console.log("init",this.companyId,this.config)}}t.Core=s,t.default=s},508:function(e,t,s){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Network=void 0;const n=o(s(297));class r extends n.default{constructor(){super(),this.responseLogs=[],this.processedResources=new Set,this.resourceMonitorInterval=null,"undefined"!=typeof window&&this.wrap()}isNetworkEnabled(){var e;const t=null===(e=this.config)||void 0===e?void 0:e.network;return void 0===t||!1!==t.isEnabled}sanitizeRequest(e){var t;const s=null===(t=this.config)||void 0===t?void 0:t.network,o=null==s?void 0:s.requestSanitizer;if(!o||"function"!=typeof o)return e;try{return o(e)}catch(t){return console.warn("Error in requestSanitizer:",t),e}}sanitizeResponse(e){var t;const s=null===(t=this.config)||void 0===t?void 0:t.network,o=null==s?void 0:s.responseSanitizer;if(!o||"function"!=typeof o)return e;try{return o(e)}catch(t){return console.warn("Error in responseSanitizer:",t),e}}getResponseLogs(){return[...this.responseLogs]}clearResponseLogs(){this.responseLogs=[],this.processedResources.clear()}monitorResourceTiming(){"undefined"!=typeof window&&window.performance&&window.performance.getEntriesByType&&this.isNetworkEnabled()&&(performance.getEntriesByType("resource").forEach((e=>{if(this.processedResources.has(e.name)||e.name.includes("lognroll"))return;this.processedResources.add(e.name);const t={id:`resource-${e.startTime}`,url:e.name,timestamp:Date.now()-e.duration,method:"GET",initiatorType:"STATIC",body:null},s=this.sanitizeRequest(t);if(null===s)return;const o={startTime:e.startTime,duration:e.duration,fetchStart:e.fetchStart,responseEnd:e.responseEnd,dnsTime:e.domainLookupEnd-e.domainLookupStart,connectTime:e.connectEnd-e.connectStart,ttfb:e.responseStart-e.requestStart,downloadTime:e.responseEnd-e.responseStart},n={url:e.name,status:200,statusText:"OK",headers:{},timing:o,contentType:e.initiatorType,decodedBodySize:e.decodedBodySize,encodedBodySize:e.encodedBodySize,transferSize:e.transferSize,timestamp:Date.now(),responseTime:e.duration},r=this.sanitizeResponse(n),i={type:"network",stage:"response",payload:{request:s,response:null===r?{url:n.url,status:n.status,statusText:n.statusText,timing:n.timing,timestamp:n.timestamp,responseTime:n.responseTime}:r}};this.responseLogs.push(i)})),performance.clearResourceTimings())}startResourceMonitoring(e=1e3){null===this.resourceMonitorInterval&&(this.monitorResourceTiming(),"undefined"!=typeof window&&(this.resourceMonitorInterval=window.setInterval((()=>{this.monitorResourceTiming()}),e)))}stopResourceMonitoring(){null!==this.resourceMonitorInterval&&(clearInterval(this.resourceMonitorInterval),this.resourceMonitorInterval=null)}wrap(){if(!this.isNetworkEnabled())return;this.startResourceMonitoring();const e=new Map,t=window.fetch,s=this;window.fetch=async function(o,n){const r=Date.now().toString(),i="string"==typeof o?o:o.url;if(i.includes("lognroll"))return t(o,n);const a=(null==n?void 0:n.method)||"GET",u=(null==n?void 0:n.body)||null,l={id:r,url:i,initiatorType:"fetch",timestamp:Date.now(),method:a,body:u,headers:(()=>{const e={};return(null==n?void 0:n.headers)&&(n.headers instanceof Headers?n.headers.forEach(((t,s)=>{e[s]=t})):Array.isArray(n.headers)?n.headers.forEach((([t,s])=>{e[t]=s})):Object.assign(e,n.headers)),e})()},d=s.sanitizeRequest(l);if(null===d)return t(o,n);e.set(r,{url:i,timestamp:Date.now(),body:d.body||u});const c=Date.now(),p=e.get(r);try{const i=await t(o,n),a=i.clone(),u=await a.text().catch((()=>null)),l={url:i.url,status:i.status,statusText:i.statusText,headers:(()=>{const e={};return i.headers.forEach(((t,s)=>{e[s]=t})),e})(),data:u,timestamp:Date.now(),responseTime:Date.now()-c},p=s.sanitizeResponse(l),h={type:"network",stage:"response",payload:{request:d,response:null===p?{url:l.url,status:l.status,statusText:l.statusText,timestamp:l.timestamp,responseTime:l.responseTime}:p}};return s.responseLogs.push(h),e.delete(r),i}catch(t){const o={type:"network",stage:"error",payload:{request:d||{id:r,url:i,timestamp:(null==p?void 0:p.timestamp)||Date.now()-100,method:a,body:u},error:{message:t instanceof Error?t.message:"Unknown error",timestamp:Date.now()}}};throw s.responseLogs.push(o),e.delete(r),t}};const o=window.XMLHttpRequest;window.XMLHttpRequest=function(){const t=new o,n=Date.now().toString(),r=t.open;t._requestHeaders={};const i=t.setRequestHeader;t.setRequestHeader=function(e,s){t._requestHeaders[e]=s,i.apply(this,arguments)},t.open=function(o,i){if(i.toString().includes("lognroll"))return r.apply(t,arguments);e.set(n,{url:i.toString(),timestamp:Date.now(),body:null});const a=this,u=this.onreadystatechange;return this.onreadystatechange=function(){var r;if(4===a.readyState){const l=e.get(n),d={id:n,url:i.toString(),initiatorType:"xmlhttprequest",timestamp:(null===(r=e.get(n))||void 0===r?void 0:r.timestamp)||Date.now()-100,method:o||"GET",body:(null==l?void 0:l.body)||null,headers:t._requestHeaders||{}},c=s.sanitizeRequest(d);if(null===c)return e.delete(n),void(u&&u.apply(a,arguments));const p=Date.now()-((null==l?void 0:l.timestamp)||Date.now()),h={url:i.toString(),status:a.status,statusText:a.statusText,headers:a.getAllResponseHeaders().split("\r\n").reduce(((e,t)=>{const[s,o]=t.split(": ");return s&&o&&(e[s]=o),e}),{}),data:a.responseText,timestamp:Date.now(),responseTime:p},m=s.sanitizeResponse(h),f={type:"network",stage:"response",payload:{request:c,response:null===m?{url:h.url,status:h.status,statusText:h.statusText,timestamp:h.timestamp,responseTime:h.responseTime}:m}};s.responseLogs.push(f),e.delete(n),u&&u.apply(a,arguments)}else u&&u.apply(a,arguments)},r.apply(t,arguments)};const a=t.send;return t.send=function(o){if(o instanceof FormData){const t={};for(const[e,s]of o.entries())t[e]=s;o=t;const s=e.get(n);null!=s&&(s.body=t)}else{const t=e.get(n);null!=t&&(t.body=o)}return t.addEventListener("load",(function(t){var s;const o=(null===(s=e.get(n))||void 0===s?void 0:s.url)||"";o.includes("lognroll")||o.includes("/api/v1/requests/")})),t.addEventListener("error",(function(){var r;if(t.responseURL.includes("lognroll"))return;const i={id:n,url:t.responseURL,timestamp:(null===(r=e.get(n))||void 0===r?void 0:r.timestamp)||Date.now()-100,method:t._method||"GET",body:o,headers:t._requestHeaders||{}},a=s.sanitizeRequest(i);if(null===a)return void e.delete(n);const u={type:"network",stage:"error",payload:{request:a,error:{message:"XHR request failed",timestamp:Date.now()}}};s.responseLogs.push(u),e.delete(n)})),a.apply(t,arguments)},t}}}t.Network=r,t.default=r},835:function(e,t,s){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Console=void 0;const n=o(s(508));class r extends n.default{constructor(){super(),this.consoleLogs=[],"undefined"!=typeof window&&(this.originalConsole=window.console,this.initializeConsoleOverrides())}initializeConsoleOverrides(){["log","info","warn","error","debug","trace"].forEach((e=>{const t=this.originalConsole[e];window.console[e]=(...s)=>{const o=Date.now();t.apply(this.originalConsole,s);try{const t=()=>{const e=new WeakSet;return(t,s)=>{if("object"==typeof s&&null!==s){if(e.has(s))return"[Circular]";e.add(s)}return s}},n=e+"<|||>"+s.map((e=>{try{return"object"==typeof e&&null!==e?JSON.stringify(e,t()):String(e)}catch(e){return"[Error stringifying argument]"}})).join("<SPLIT>");this.consoleLogs.push({data:n,timestamp:o})}catch(e){t.apply(this.originalConsole,[e,"error sending log"])}}}))}}t.Console=r,t.default=r}},t={};function s(o){var n=t[o];if(void 0!==n)return n.exports;var r=t[o]={exports:{}};return e[o].call(r.exports,r,r.exports,s),r.exports}var o={};return(()=>{var e=o;const t=s(835);class n extends t.Console{constructor(){super()}}e.default=new n})(),o.default})()));
@@ -32,7 +32,7 @@ export interface NetworkResponse {
32
32
  status: number;
33
33
  statusText: string;
34
34
  headers: Record<string, string>;
35
- body?: any;
35
+ data?: any;
36
36
  timestamp: number;
37
37
  responseTime: number;
38
38
  timing?: NetworkResponseTiming;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lognroll/lib",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "The official JavaScript SDK for LogNroll",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",