@lognroll/lib 1.0.6 → 1.0.8

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.
@@ -0,0 +1,9 @@
1
+ import Network from "../network";
2
+ export declare class Console extends Network {
3
+ private originalConsole;
4
+ consoleLogs: any[];
5
+ constructor();
6
+ initializeConsoleOverrides(): void;
7
+ }
8
+ export default Console;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/console/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,qBAAa,OAAQ,SAAQ,OAAO;IAEhC,OAAO,CAAC,eAAe,CAAM;IACtB,WAAW,EAAE,GAAG,EAAE,CAAM;;IAU/B,0BAA0B;CA4C7B;AAED,eAAe,OAAO,CAAC"}
@@ -0,0 +1,19 @@
1
+ export declare class Core {
2
+ constructor();
3
+ companyId: string;
4
+ userId: string;
5
+ config: any;
6
+ traits: {
7
+ name?: string;
8
+ email?: string;
9
+ };
10
+ initSession(companyId: string, data: any): void;
11
+ initSessionWithoutScript(companyId: string, data: any): void;
12
+ identifyUser(userId: string, traits: {
13
+ name?: string;
14
+ email?: string;
15
+ }): void;
16
+ init(): void;
17
+ }
18
+ export default Core;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAEA,qBAAa,IAAI;;IAGR,SAAS,EAAE,MAAM,CAAM;IACvB,MAAM,EAAE,MAAM,CAAM;IACpB,MAAM,EAAE,GAAG,CAAM;IACjB,MAAM,EAAE;QAAC,IAAI,CAAC,EAAC,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAC,CAAM;IAEnD,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAWxC,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IASrD,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;QAAC,IAAI,CAAC,EAAC,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAC;IAM5D,IAAI;CAGZ;AAED,eAAe,IAAI,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Console } from './console';
2
+ declare class LognRoll extends Console {
3
+ constructor();
4
+ }
5
+ declare const _default: LognRoll;
6
+ export default _default;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,cAAM,QAAS,SAAQ,OAAO;;CAK7B;;AAED,wBAA8B"}
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- /*! For license information please see index.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.LognRoll=e():t.LognRoll=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}function o(t,e,r){return(e=i(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],s=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);s=!0);}catch(t){c=!0,o=t}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return u}}(t,e)||l(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(){s=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function l(t,e,r,n){return Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function f(e,r,n,o){var i=r&&r.prototype instanceof d?r:d,a=Object.create(i.prototype);return l(a,"_invoke",function(e,r,n){var o=1;return function(i,a){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var s=j(u,n);if(s){if(s===y)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===o)throw o=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=3;var c=p(e,r,n);if("normal"===c.type){if(o=n.done?4:2,c.arg===y)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=4,n.method="throw",n.arg=c.arg)}}}(e,n,new P(o||[])),!0),a}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var y={};function d(){}function h(){}function v(){}var m={};l(m,i,(function(){return this}));var b=Object.getPrototypeOf,w=b&&b(b(x([])));w&&w!==r&&n.call(w,i)&&(m=w);var g=v.prototype=d.prototype=Object.create(m);function S(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,u,s){var c=p(t[o],t,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==a(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,u,s)}),(function(t){r("throw",t,u,s)})):e.resolve(f).then((function(t){l.value=t,u(l)}),(function(t){return r("throw",t,u,s)}))}s(c.arg)}var o;l(this,"_invoke",(function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}),!0)}function j(e,r){var n=r.method,o=e.i[n];if(o===t)return r.delegate=null,"throw"===n&&e.i.return&&(r.method="return",r.arg=t,j(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=p(o,e.i,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,y;var a=i.arg;return a?a.done?(r[e.r]=a.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function E(t){this.tryEntries.push(t)}function T(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function P(t){this.tryEntries=[[-1]],t.forEach(E,this),this.reset(!0)}function x(e){if(null!=e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,u=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return u.next=u}}throw new TypeError(a(e)+" is not iterable")}return h.prototype=v,l(g,"constructor",v),l(v,"constructor",h),h.displayName=l(v,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,l(t,c,"GeneratorFunction")),t.prototype=Object.create(g),t},e.awrap=function(t){return{__await:t}},S(O.prototype),l(O.prototype,u,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},S(g),l(g,c,"Generator"),l(g,i,(function(){return this})),l(g,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},e.values=x,P.prototype={constructor:P,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t){a.type="throw",a.arg=e,r.next=t}for(var o=r.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i[4],u=this.prev,s=i[1],c=i[2];if(-1===i[0])return n("end"),!1;if(!s&&!c)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=u){if(u<s)return this.method="next",this.arg=t,n(s),!0;if(u<c)return n(c),!1}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var o=n;break}}o&&("break"===t||"continue"===t)&&o[0]<=e&&e<=o[2]&&(o=null);var i=o?o[4]:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o[2],y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[2]===t)return this.complete(r[4],r[3]),T(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[0]===t){var n=r[4];if("throw"===n.type){var o=n.arg;T(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:x(e),r,n},"next"===this.method&&(this.arg=t),y}},e}function c(t,e,r,n,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}function l(t,e){if(t){if("string"==typeof t)return f(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(t,e):void 0}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function p(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,m(n.key),n)}}function y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(y=function(){return!!t})()}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function h(t,e){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},h(t,e)}function v(t,e,r){return(e=m(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function m(t){var e=function(t){if("object"!=a(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=a(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==a(e)?e:e+""}function b(t){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},b(t)}function w(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,j(n.key),n)}}function g(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(g=function(){return!!t})()}function S(t){return S=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},S(t)}function O(t,e){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},O(t,e)}function j(t){var e=function(t){if("object"!=b(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=b(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==b(e)?e:e+""}function E(t){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(t)}function T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(T=function(){return!!t})()}function P(t){return P=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},P(t)}function x(t,e){return x=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},x(t,e)}t.d(e,{default:()=>_});const _=new(function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e,r){return e=P(e),function(t,e){if(e&&("object"==E(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,T()?Reflect.construct(e,r||[],P(t).constructor):e.apply(t,r))}(this,e)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&x(t,e)}(e,t),r=e,Object.defineProperty(r,"prototype",{writable:!1}),r;var r}(function(t){function e(){var t,r,n,o;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),t=function(t,e,r){return e=S(e),function(t,e){if(e&&("object"==b(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,g()?Reflect.construct(e,r||[],S(t).constructor):e.apply(t,r))}(this,e),r=t,o=[],(n=j(n="consoleLogs"))in r?Object.defineProperty(r,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):r[n]=o,"undefined"!=typeof window&&(t.originalConsole=window.console,t.initializeConsoleOverrides()),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&O(t,e)}(e,t),r=e,n=[{key:"initializeConsoleOverrides",value:function(){var t=this;["log","info","warn","error","debug","trace"].forEach((function(e){var r=t.originalConsole[e];window.console[e]=function(){for(var n=Date.now(),o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];r.apply(t.originalConsole,i);try{var u=e+"<|||>"+i.map((function(t){try{return"object"===b(t)&&null!==t?JSON.stringify(t,(e=new WeakSet,function(t,r){if("object"===b(r)&&null!==r){if(e.has(r))return"[Circular]";e.add(r)}return r})):String(t)}catch(t){return"[Error stringifying argument]"}var e})).join("<SPLIT>");t.consoleLogs.push({data:u,timestamp:n})}catch(e){r.apply(t.originalConsole,[e,"error sending log"])}}}))}}],n&&w(r.prototype,n),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n}(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),v(t=function(t,e,r){return e=d(e),function(t,e){if(e&&("object"==a(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,y()?Reflect.construct(e,r||[],d(t).constructor):e.apply(t,r))}(this,e),"responseLogs",[]),v(t,"processedResources",new Set),v(t,"resourceMonitorInterval",null),"undefined"!=typeof window&&t.wrap(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&h(t,e)}(e,t),r=e,n=[{key:"getResponseLogs",value:function(){return function(t){return function(t){if(Array.isArray(t))return f(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||l(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(this.responseLogs)}},{key:"clearResponseLogs",value:function(){this.responseLogs=[],this.processedResources.clear()}},{key:"monitorResourceTiming",value:function(){var t=this;"undefined"!=typeof window&&window.performance&&window.performance.getEntriesByType&&(performance.getEntriesByType("resource").forEach((function(e){if(!t.processedResources.has(e.name)&&!e.name.includes("lognroll")){t.processedResources.add(e.name);var r={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={type:"network",stage:"response",payload:{request:{id:"resource-".concat(e.startTime),url:e.name,timestamp:Date.now()-e.duration,method:"GET",initiatorType:"STATIC",body:null},response:{url:e.name,status:200,statusText:"OK",headers:{},timing:r,contentType:e.initiatorType,decodedBodySize:e.decodedBodySize,encodedBodySize:e.encodedBodySize,transferSize:e.transferSize,timestamp:Date.now(),responseTime:e.duration}}};t.responseLogs.push(n)}})),performance.clearResourceTimings())}},{key:"startResourceMonitoring",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e3;null===this.resourceMonitorInterval&&(this.monitorResourceTiming(),"undefined"!=typeof window&&(this.resourceMonitorInterval=window.setInterval((function(){t.monitorResourceTiming()}),e)))}},{key:"stopResourceMonitoring",value:function(){null!==this.resourceMonitorInterval&&(clearInterval(this.resourceMonitorInterval),this.resourceMonitorInterval=null)}},{key:"wrap",value:function(){this.startResourceMonitoring();var t=new Map,e=window.fetch,r=this;window.fetch=function(){var n,o=(n=s().mark((function n(o,i){var a,u,c,l,f,p,y,d,h,v,m,b;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(a=Date.now().toString(),!(u="string"==typeof o?o:o.url).includes("lognroll")){n.next=4;break}return n.abrupt("return",e(o,i));case 4:return c=(null==i?void 0:i.method)||"GET",l=(null==i?void 0:i.body)||null,t.set(a,{url:u,timestamp:Date.now(),body:null}),f=Date.now(),p=t.get(a),n.prev=9,n.next=12,e(o,i);case 12:return y=n.sent,d=y.clone(),n.next=16,d.text().catch((function(){return null}));case 16:return h=n.sent,v=Date.now()-f,m={type:"network",stage:"response",payload:{request:{id:a,url:y.url,initiatorType:"fetch",timestamp:(null==p?void 0:p.timestamp)||Date.now()-100,method:c,body:l},response:{url:y.url,status:y.status,statusText:y.statusText,headers:function(){var t={};return y.headers.forEach((function(e,r){t[r]=e})),t}(),data:h,timestamp:Date.now(),responseTime:v}}},r.responseLogs.push(m),t.delete(a),n.abrupt("return",y);case 24:throw n.prev=24,n.t0=n.catch(9),b={type:"network",stage:"error",payload:{request:{id:a,url:u,timestamp:(null==p?void 0:p.timestamp)||Date.now()-100,method:c,body:l},error:{message:n.t0 instanceof Error?n.t0.message:"Unknown error",timestamp:Date.now()}}},r.responseLogs.push(b),t.delete(a),n.t0;case 30:case"end":return n.stop()}}),n,null,[[9,24]])})),function(){var t=this,e=arguments;return new Promise((function(r,o){var i=n.apply(t,e);function a(t){c(i,r,o,a,u,"next",t)}function u(t){c(i,r,o,a,u,"throw",t)}a(void 0)}))});return function(t,e){return o.apply(this,arguments)}}();var n=window.XMLHttpRequest;window.XMLHttpRequest=function(){var e=new n,o=Date.now().toString(),i=e.open;e._requestHeaders={};var a=e.setRequestHeader;e.setRequestHeader=function(t,r){e._requestHeaders[t]=r,a.apply(this,arguments)},e.open=function(n,a){if(a.toString().includes("lognroll"))return i.apply(e,arguments);t.set(o,{url:a.toString(),timestamp:Date.now(),body:null});var s=this,c=this.onreadystatechange;return this.onreadystatechange=function(){if(4===s.readyState){var i,l=t.get(o),f=Date.now()-((null==l?void 0:l.timestamp)||Date.now()),p={type:"network",stage:"response",payload:{request:{id:o,url:a,initiatorType:"xmlhttprequest",timestamp:(null===(i=t.get(o))||void 0===i?void 0:i.timestamp)||Date.now()-100,method:n||"GET",body:(null==l?void 0:l.body)||null,headers:e._requestHeaders||{}},response:{status:s.status,statusText:s.statusText,headers:s.getAllResponseHeaders().split("\r\n").reduce((function(t,e){var r=u(e.split(": "),2),n=r[0],o=r[1];return n&&o&&(t[n]=o),t}),{}),data:s.responseText,timestamp:Date.now(),responseTime:f}}};r.responseLogs.push(p),t.delete(o),c&&c.apply(s,arguments)}else c&&c.apply(s,arguments)},i.apply(e,arguments)};var s=e.send;return e.send=function(n){if(n instanceof FormData){var i,a={},c=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=l(t))){e&&(t=e);var r=0,n=function(){};return{s:n,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return i=t.done,t},e:function(t){a=!0,o=t},f:function(){try{i||null==e.return||e.return()}finally{if(a)throw o}}}}(n.entries());try{for(c.s();!(i=c.n()).done;){var f=u(i.value,2),p=f[0],y=f[1];a[p]=y}}catch(t){c.e(t)}finally{c.f()}n=a;var d=t.get(o);null!=d&&(d.body=a)}else{var h=t.get(o);null!=h&&(h.body=n)}return e.addEventListener("load",(function(e){var r,n=(null===(r=t.get(o))||void 0===r?void 0:r.url)||"";n.includes("lognroll")||n.includes("/api/v1/requests/")})),e.addEventListener("error",(function(){var i;if(!e.responseURL.includes("lognroll")){var a={type:"network",stage:"error",payload:{request:{id:o,url:e.responseURL,timestamp:(null===(i=t.get(o))||void 0===i?void 0:i.timestamp)||Date.now()-100,method:e._method||"GET",body:n},error:{message:"XHR request failed",timestamp:Date.now()}}};r.responseLogs.push(a),t.delete(o)}})),s.apply(e,arguments)},e}}}],n&&p(r.prototype,n),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n}(function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),o(this,"companyId",""),o(this,"userId",""),o(this,"config",{}),o(this,"traits",{})},(e=[{key:"initSession",value:function(t,e){(window||{}).lnr=this,this.config=e||{},this.companyId=t;var r=document.createElement("script"),n=(new Date).getTime();r.src=((null==e?void 0:e.logFile)||"https://logger.lognroll.com/logger.lnr.1.0.1.js")+"?cc="+n,r.async=!1,document.head.appendChild(r)}},{key:"initSessionWithoutScript",value:function(t,e){console.log("initSessionWithoutScript",t,e),(window||{}).lnr=this,this.config=e||{},this.companyId=t,this.init()}},{key:"identifyUser",value:function(t,e){this.userId=t,this.traits=e}},{key:"init",value:function(){console.log("init",this.companyId,this.config)}}])&&n(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}()))));return e.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})(),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})()));
@@ -0,0 +1,71 @@
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
+ body?: any;
36
+ timestamp: number;
37
+ responseTime: number;
38
+ timing?: NetworkResponseTiming;
39
+ contentType?: string;
40
+ decodedBodySize?: number;
41
+ encodedBodySize?: number;
42
+ transferSize?: number;
43
+ }
44
+ export declare class Network extends Core {
45
+ constructor();
46
+ private responseLogs;
47
+ private processedResources;
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;
63
+ getResponseLogs(): any[];
64
+ clearResponseLogs(): void;
65
+ private monitorResourceTiming;
66
+ startResourceMonitoring(interval?: number): void;
67
+ stopResourceMonitoring(): void;
68
+ wrap(): void;
69
+ }
70
+ export default Network;
71
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,OAAQ,SAAQ,IAAI;;IAO7B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,uBAAuB,CAAuB;IAEtD;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgBxB,eAAe;IAIf,iBAAiB;IAKjB,OAAO,CAAC,qBAAqB;IAqG7B,uBAAuB,CAAC,QAAQ,GAAE,MAAa;IAgB/C,sBAAsB;IAOtB,IAAI;CA8VP;AAED,eAAe,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lognroll/lib",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "The official JavaScript SDK for LogNroll",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,6 +27,7 @@
27
27
  "esbuild": "^0.25.4",
28
28
  "rollup": "^4.39.0",
29
29
  "rollup-plugin-typescript2": "^0.36.0",
30
+ "ts-loader": "^9.5.1",
30
31
  "typescript": "^5.8.3",
31
32
  "webpack": "^5.99.8",
32
33
  "webpack-cli": "^6.0.1"
@@ -1 +0,0 @@
1
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */