@lognroll/lib 1.0.7 → 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 +1 -1
- package/dist/network/index.d.ts +56 -0
- package/dist/network/index.d.ts.map +1 -1
- package/package.json +1 -1
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
|
|
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})()));
|
package/dist/network/index.d.ts
CHANGED
|
@@ -1,9 +1,65 @@
|
|
|
1
1
|
import Core from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Network request object structure for sanitization
|
|
4
|
+
*/
|
|
5
|
+
export interface NetworkRequest {
|
|
6
|
+
id: string;
|
|
7
|
+
url: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
method: string;
|
|
10
|
+
body: any;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
initiatorType?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Network response timing information
|
|
16
|
+
*/
|
|
17
|
+
export interface NetworkResponseTiming {
|
|
18
|
+
startTime: number;
|
|
19
|
+
duration: number;
|
|
20
|
+
fetchStart: number;
|
|
21
|
+
responseEnd: number;
|
|
22
|
+
dnsTime: number;
|
|
23
|
+
connectTime: number;
|
|
24
|
+
ttfb: number;
|
|
25
|
+
downloadTime: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Network response object structure for sanitization
|
|
29
|
+
*/
|
|
30
|
+
export interface NetworkResponse {
|
|
31
|
+
url: string;
|
|
32
|
+
status: number;
|
|
33
|
+
statusText: string;
|
|
34
|
+
headers: Record<string, string>;
|
|
35
|
+
data?: any;
|
|
36
|
+
timestamp: number;
|
|
37
|
+
responseTime: number;
|
|
38
|
+
timing?: NetworkResponseTiming;
|
|
39
|
+
contentType?: string;
|
|
40
|
+
decodedBodySize?: number;
|
|
41
|
+
encodedBodySize?: number;
|
|
42
|
+
transferSize?: number;
|
|
43
|
+
}
|
|
2
44
|
export declare class Network extends Core {
|
|
3
45
|
constructor();
|
|
4
46
|
private responseLogs;
|
|
5
47
|
private processedResources;
|
|
6
48
|
private resourceMonitorInterval;
|
|
49
|
+
/**
|
|
50
|
+
* Check if network logging is enabled
|
|
51
|
+
*/
|
|
52
|
+
private isNetworkEnabled;
|
|
53
|
+
/**
|
|
54
|
+
* Sanitize a network request using the requestSanitizer function if configured
|
|
55
|
+
* Returns null if the request should be ignored, otherwise returns the sanitized request
|
|
56
|
+
*/
|
|
57
|
+
private sanitizeRequest;
|
|
58
|
+
/**
|
|
59
|
+
* Sanitize a network response using the responseSanitizer function if configured
|
|
60
|
+
* Returns null if all response data should be redacted, otherwise returns the sanitized response
|
|
61
|
+
*/
|
|
62
|
+
private sanitizeResponse;
|
|
7
63
|
getResponseLogs(): any[];
|
|
8
64
|
clearResponseLogs(): void;
|
|
9
65
|
private monitorResourceTiming;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,qBAAa,OAAQ,SAAQ,IAAI;;IAO7B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,uBAAuB,CAAuB;IAEtD,eAAe;IAIf,iBAAiB;IAKjB,OAAO,CAAC,qBAAqB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","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