@aftership/web-pixels
Version:
AfterShip Web Pixels for data anaylsis
2 lines (1 loc) • 40.9 kB
JavaScript
;const Dr=require("./avo.js");(function(){if(typeof window>"u")return;var n={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};function t(r){return r&&DataView.prototype.isPrototypeOf(r)}if(n.arrayBuffer)var i=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(r){return r&&i.indexOf(Object.prototype.toString.call(r))>-1};function d(r){if(typeof r!="string"&&(r=String(r)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(r))throw new TypeError("Invalid character in header field name");return r.toLowerCase()}function b(r){return typeof r!="string"&&(r=String(r)),r}function g(r){var u={next:function(){var w=r.shift();return{done:w===void 0,value:w}}};return n.iterable&&(u[Symbol.iterator]=function(){return u}),u}function h(r){this.map={},r instanceof h?r.forEach(function(u,w){this.append(w,u)},this):Array.isArray(r)?r.forEach(function(u){this.append(u[0],u[1])},this):r&&Object.getOwnPropertyNames(r).forEach(function(u){this.append(u,r[u])},this)}h.prototype.append=function(r,u){r=d(r),u=b(u);var w=this.map[r];this.map[r]=w?w+", "+u:u},h.prototype.delete=function(r){delete this.map[d(r)]},h.prototype.get=function(r){return r=d(r),this.has(r)?this.map[r]:null},h.prototype.has=function(r){return this.map.hasOwnProperty(d(r))},h.prototype.set=function(r,u){this.map[d(r)]=b(u)},h.prototype.forEach=function(r,u){for(var w in this.map)this.map.hasOwnProperty(w)&&r.call(u,this.map[w],w,this)},h.prototype.keys=function(){var r=[];return this.forEach(function(u,w){r.push(w)}),g(r)},h.prototype.values=function(){var r=[];return this.forEach(function(u){r.push(u)}),g(r)},h.prototype.entries=function(){var r=[];return this.forEach(function(u,w){r.push([w,u])}),g(r)},n.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);function I(r){return r.bodyUsed?!0:(r.bodyUsed=!0,!1)}function F(r){return new Promise(function(u,w){r.onload=function(){u(r.result)},r.onerror=function(){w(r.error)}})}function se(r){var u=new FileReader,w=F(u);return u.readAsArrayBuffer(r),w}function Y(r){var u=new FileReader,w=F(u);return u.readAsText(r),w}function xe(r){for(var u=new Uint8Array(r),w=new Array(u.length),U=0;U<u.length;U++)w[U]=String.fromCharCode(u[U]);return w.join("")}function ee(r){if(r.slice)return r.slice(0);var u=new Uint8Array(r.byteLength);return u.set(new Uint8Array(r)),u.buffer}function te(){return this.bodyUsed=!1,this._initBody=function(r){this._bodyInit=r,r?typeof r=="string"?this._bodyText=r:n.blob&&Blob.prototype.isPrototypeOf(r)?this._bodyBlob=r:n.formData&&FormData.prototype.isPrototypeOf(r)?this._bodyFormData=r:n.searchParams&&URLSearchParams.prototype.isPrototypeOf(r)?this._bodyText=r.toString():n.arrayBuffer&&n.blob&&t(r)?(this._bodyArrayBuffer=ee(r.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):n.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(r)||o(r))?this._bodyArrayBuffer=ee(r):this._bodyText=r=Object.prototype.toString.call(r):this._bodyText="",this.headers.get("content-type")||(typeof r=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):n.searchParams&&URLSearchParams.prototype.isPrototypeOf(r)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},n.blob&&(this.blob=function(){var r=I(this);if(r)return Promise.reject(new TypeError("Already read"));if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?I(this)?Promise.reject(new TypeError("Already read")):Promise.resolve(this._bodyArrayBuffer):this.blob().then(se)}),this.text=function(){var r=I(this);if(r)return Promise.reject(new TypeError("Already read"));if(this._bodyBlob)return Y(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(xe(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},n.formData&&(this.formData=function(){return this.text().then(ne)}),this.json=function(){return this.text().then(JSON.parse)},this}var fe=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function K(r){var u=r.toUpperCase();return fe.indexOf(u)>-1?u:r}function re(r,u){u=u||{};var w=u.body;if(r instanceof re){if(r.bodyUsed)throw new TypeError("Already read");this.url=r.url,this.credentials=r.credentials,u.headers||(this.headers=new h(r.headers)),this.method=r.method,this.mode=r.mode,this.signal=r.signal,!w&&r._bodyInit!=null&&(w=r._bodyInit,r.bodyUsed=!0)}else this.url=String(r);if(this.credentials=u.credentials||this.credentials||"same-origin",(u.headers||!this.headers)&&(this.headers=new h(u.headers)),this.method=K(u.method||this.method||"GET"),this.mode=u.mode||this.mode||null,this.signal=u.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&w)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(w)}re.prototype.clone=function(){return new re(this,{body:this._bodyInit})};function ne(r){var u=new FormData;return r.trim().split("&").forEach(function(w){if(w){var U=w.split("="),Q=U.shift().replace(/\+/g," "),D=U.join("=").replace(/\+/g," ");u.append(decodeURIComponent(Q),decodeURIComponent(D))}}),u}function me(r){var u=new h,w=r.replace(/\r?\n[\t ]+/g," ");return w.split(/\r?\n/).forEach(function(U){var Q=U.split(":"),D=Q.shift().trim();if(D){var le=Q.join(":").trim();u.append(D,le)}}),u}te.call(re.prototype);function m(r,u){u||(u={}),this.type="default",this.status=u.status===void 0?200:u.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in u?u.statusText:"OK",this.headers=new h(u.headers),this.url=u.url||"",this._initBody(r)}te.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},m.error=function(){var r=new m(null,{status:0,statusText:""});return r.type="error",r};var B=[301,302,303,307,308];m.redirect=function(r,u){if(B.indexOf(u)===-1)throw new RangeError("Invalid status code");return new m(null,{status:u,headers:{location:r}})},self.DOMException=self.DOMException;try{new self.DOMException}catch{self.DOMException=function(u,w){this.message=u,this.name=w;var U=Error(u);this.stack=U.stack},self.DOMException.prototype=Object.create(Error.prototype),self.DOMException.prototype.constructor=self.DOMException}function E(r,u){return new Promise(function(w,U){var Q=new re(r,u);if(Q.signal&&Q.signal.aborted)return U(new self.DOMException("Aborted","AbortError"));var D=new XMLHttpRequest;function le(){D.abort()}D.onload=function(){var De={status:D.status,statusText:D.statusText,headers:me(D.getAllResponseHeaders()||"")};De.url="responseURL"in D?D.responseURL:De.headers.get("X-Request-URL");var Be="response"in D?D.response:D.responseText;w(new m(Be,De))},D.onerror=function(){U(new TypeError("Network request failed"))},D.ontimeout=function(){U(new TypeError("Network request failed"))},D.onabort=function(){U(new self.DOMException("Aborted","AbortError"))},D.open(Q.method,Q.url,!0),Q.credentials==="include"?D.withCredentials=!0:Q.credentials==="omit"&&(D.withCredentials=!1),"responseType"in D&&n.blob&&(D.responseType="blob"),Q.headers.forEach(function(De,Be){D.setRequestHeader(Be,De)}),Q.signal&&(Q.signal.addEventListener("abort",le),D.onreadystatechange=function(){D.readyState===4&&Q.signal.removeEventListener("abort",le)}),D.send(typeof Q._bodyInit>"u"?null:Q._bodyInit)})}E.polyfill=!0,self.fetch||(self.fetch=E,self.Headers=h,self.Request=re,self.Response=m)})();var At=(n=>(n.Prod="prod",n.Dev="dev",n))(At||{});typeof Object.assign!="function"&&Object.defineProperty(Object,"assign",{value:function(t,i){if(t==null)throw new TypeError("Cannot convert undefined or null to object");let o=Object(t);for(let d=1;d<arguments.length;d++){let b=arguments[d];if(b!=null)for(let g in b)Object.prototype.hasOwnProperty.call(b,g)&&(o[g]=b[g])}return o},writable:!0,configurable:!0});let Kt=[];typeof window<"u"&&window.addEventListener("message",function(n){if(n.origin!=="https://www.avo.app")return;let t=document.getElementById("avo-debugger");if(t&&n&&n.data&&n.data.type_==="avo-debugger-update-style")t.style=n.data.style;else if(t&&n&&n.data&&n.data.type_==="avo-debugger-ready"){let i={type_:"avo-debugger-boot-events",schemaId:"tLvqZe7vIUgYITePLioH",href:window.location.href,events:Kt};Kt=[],t.contentWindow.postMessage(i,"https://www.avo.app/_debugger")}});const Ar=(n,t)=>Object.fromEntries(Object.entries(t).filter(([i])=>!n.includes(i))),Br=(n,t)=>({make:function(i){t.init({env:i,pixelId:n.pixelId,libVersion:n.libVersion,libName:n.libName,debug:n.debug,customerId:n.customerId})},logEvent:(i,o,d,b)=>{t.logEventForNode(i,o,d,b)}}),Pr=(n,t)=>{const i=Ar(["initAvo","setSystemProperties","avoInspectorApiKey","AvoEnv","identify","resetIdentity"],n);return{init:o=>{const d=o,b=["production","prod","staging"].includes("development")?At.Prod:At.Dev,g=d.env||b;n.initAvo({env:b,webDebugger:!1,avoLogger:{logDebug:()=>!0,logWarn:()=>!0,logError:()=>!0},inspector:void 0},{pixelId:o.pixelId,env:g},{},Br({pixelId:o.pixelId,debug:o.debug,env:g,libVersion:"0.0.1-alpha.7",libName:"@aftership/business-pixels/nodejs",customerId:o.customerId},t))},debug:()=>{},events:{...i}}},Tt=(n,t,i="#ff6b2b")=>["%c%s%c%s",`background: ${i}; color: white; border-radius: 5px; padding: 2px 5px; margin-right: 5px; margin-bottom: 5px;`,n,"color: unset!important;"," "+t],Ot=(n,t)=>{t?(console.groupCollapsed(...n),console.log(JSON.stringify(t,null,2)),console.groupEnd()):console.log(...n)},Tr=({title:n="AfterShip Pixel",description:t="",details:i})=>{const o=Tt(n,t,"#ff6b2b");Ot(o,i)},Or=({title:n="Error",description:t="",details:i})=>{const o=Tt(n,t,"#ff0000");Ot(o,i)},Lr=({title:n="Warn",description:t="",details:i})=>{const o=Tt(n,t,"#ffff00");Ot(o,i)},dt={success:Tr,error:Or,warn:Lr};class Je{constructor(){if(this.debug=!1,Je.instance)return Je.instance;Je.instance=this}setDebug(t){this.debug=t}warn(t){if(!this.debug)return;const i=new Date().toISOString();dt.warn({title:`AfterShip Pixel ${i} ⚠️ `,description:"warn",...t})}setStatus(t){this.debug=t??!this.debug,this.debug&&dt.success({title:"AfterShip Pixel",description:"current is debug mode"})}success(t){this.debug&&dt.success({title:"AfterShip Pixel",description:"success",...t})}error(t){this.debug&&dt.error({title:"AfterShip Pixel",description:"error",...t})}}const ye=new Je;function Cr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var tr={exports:{}},pt={exports:{}};(function(){var n=[],t=3988292384;function i(){var g,h,I;for(h=0;h<256;h+=1){for(g=h,I=0;I<8;I+=1)g&1?g=t^g>>>1:g=g>>>1;n[h]=g>>>0}}function o(g){return Array.prototype.map.call(g,function(h){return h.charCodeAt(0)})}function d(g){var h=-1,I,F,se,Y;for(I=0,se=g.length;I<se;I+=1){for(Y=(h^g[I])&255,F=0;F<8;F+=1)(Y&1)===1?Y=Y>>>1^t:Y=Y>>>1;h=h>>>8^Y}return h^-1}function b(g,h){var I,F,se;if(!((typeof b.crc>"u"||!h||!g)&&(b.crc=-1,!g))){for(I=b.crc,F=0,se=g.length;F<se;F+=1)I=I>>>8^n[(I^g[F])&255];return b.crc=I,I^-1}}i(),pt.exports=function(I,h){var I=typeof I=="string"?o(I):I,F=h?d(I):b(I);return(F>>>0).toString(16)},pt.exports.direct=d,pt.exports.table=b})();var qr=pt.exports,rr={exports:{}},nr={exports:{}};(function(){var n=32768,t=0,i=1,o=2,d=9,b=6,g,h,I=null,F,se,Y,xe,ee,te,fe,K,re,ne,me,m,B,E,r,u=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],w=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],U=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,99,99],Q=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],D=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],le=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function De(){this.next=null,this.list=null}function Be(){this.e=0,this.b=0,this.n=0,this.t=null}function Te(O,L,A,a,p,S){this.BMAX=16,this.N_MAX=288,this.status=0,this.root=null,this.m=0;var we,J=[],M,X,_,C,v,y,ge,_e=[],Z,ce,be,j=new Be,pe=[],Ee=[],W,$=[],de,ae,ue,ie,N;for(N=this.root=null,v=0;v<this.BMAX+1;v++)J[v]=0;for(v=0;v<this.BMAX+1;v++)_e[v]=0;for(v=0;v<this.BMAX;v++)pe[v]=null;for(v=0;v<this.N_MAX;v++)Ee[v]=0;for(v=0;v<this.BMAX+1;v++)$[v]=0;M=L>256?O[256]:this.BMAX,Z=O,ce=0,v=L;do J[Z[ce]]++,ce++;while(--v>0);if(J[0]===L){this.root=null,this.m=0,this.status=0;return}for(y=1;y<=this.BMAX&&J[y]===0;y++);for(ge=y,S<y&&(S=y),v=this.BMAX;v!==0&&J[v]===0;v--);for(_=v,S>v&&(S=v),ae=1<<y;y<v;y++,ae<<=1)if((ae-=J[y])<0){this.status=2,this.m=S;return}if((ae-=J[v])<0){this.status=2,this.m=S;return}for(J[v]+=ae,$[1]=y=0,Z=J,ce=1,de=2;--v>0;)$[de++]=y+=Z[ce++];Z=O,ce=0,v=0;do(y=Z[ce++])!==0&&(Ee[$[y]++]=v);while(++v<L);for(L=$[_],$[0]=v=0,Z=Ee,ce=0,C=-1,W=_e[0]=0,be=null,ue=0,null;ge<=_;ge++)for(we=J[ge];we-- >0;){for(;ge>W+_e[1+C];){if(W+=_e[1+C],C++,ue=(ue=_-W)>S?S:ue,(X=1<<(y=ge-W))>we+1)for(X-=we+1,de=ge;++y<ue&&!((X<<=1)<=J[++de]);)X-=J[de];for(W+y>M&&W<M&&(y=M-W),ue=1<<y,_e[1+C]=y,be=[],ie=0;ie<ue;ie++)be[ie]=new Be;N?N=N.next=new De:N=this.root=new De,N.next=null,N.list=be,pe[C]=be,C>0&&($[C]=v,j.b=_e[C],j.e=16+y,j.t=be,y=(v&(1<<W)-1)>>W-_e[C],pe[C-1][y].e=j.e,pe[C-1][y].b=j.b,pe[C-1][y].n=j.n,pe[C-1][y].t=j.t)}for(j.b=ge-W,ce>=L?j.e=99:Z[ce]<A?(j.e=Z[ce]<256?16:15,j.n=Z[ce++]):(j.e=p[Z[ce]-A],j.n=a[Z[ce++]-A]),X=1<<ge-W,y=v>>W;y<ue;y+=X)be[y].e=j.e,be[y].b=j.b,be[y].n=j.n,be[y].t=j.t;for(y=1<<ge-1;v&y;y>>=1)v^=y;for(v^=y;(v&(1<<W)-1)!==$[C];)W-=_e[C],C--}this.m=_e[1],this.status=ae!==0&&_!==1?1:0}function Oe(){return E.length===r?-1:E[r++]&255}function T(O){for(;ee<O;)xe|=Oe()<<ee,ee+=8}function V(O){return xe&u[O]}function z(O){xe>>=O,ee-=O}function Ie(O,L,A){var a,p,S;if(A===0)return 0;for(S=0;;){for(T(m),p=ne.list[V(m)],a=p.e;a>16;){if(a===99)return-1;z(p.b),a-=16,T(a),p=p.t[V(a)],a=p.e}if(z(p.b),a===16){if(h&=n-1,O[L+S++]=g[h++]=p.n,S===A)return A;continue}if(a===15)break;for(T(a),K=p.n+V(a),z(a),T(B),p=me.list[V(B)],a=p.e;a>16;){if(a===99)return-1;z(p.b),a-=16,T(a),p=p.t[V(a)],a=p.e}for(z(p.b),T(a),re=h-p.n-V(a),z(a);K>0&&S<A;)K--,re&=n-1,h&=n-1,O[L+S++]=g[h++]=g[re++];if(S===A)return A}return te=-1,S}function he(O,L,A){var a;if(a=ee&7,z(a),T(16),a=V(16),z(16),T(16),a!==(~xe&65535))return-1;for(z(16),K=a,a=0;K>0&&a<A;)K--,h&=n-1,T(8),O[L+a++]=g[h++]=V(8),z(8);return K===0&&(te=-1),a}function oe(O,L,A){if(!I){var a,p=[],S;for(a=0;a<144;a++)p[a]=8;for(null;a<256;a++)p[a]=9;for(null;a<280;a++)p[a]=7;for(null;a<288;a++)p[a]=8;if(se=7,S=new Te(p,288,257,w,U,se),S.status!==0)return console.error("HufBuild error: "+S.status),-1;for(I=S.root,se=S.m,a=0;a<30;a++)p[a]=5;if(Y=5,S=new Te(p,30,0,Q,D,Y),S.status>1)return I=null,console.error("HufBuild error: "+S.status),-1;F=S.root,Y=S.m}return ne=I,me=F,m=se,B=Y,Ie(O,L,A)}function Re(O,L,A){var a,p,S,we,J,M,X,_,C=[],v;for(a=0;a<286+30;a++)C[a]=0;if(T(5),X=257+V(5),z(5),T(5),_=1+V(5),z(5),T(4),M=4+V(4),z(4),X>286||_>30)return-1;for(p=0;p<M;p++)T(3),C[le[p]]=V(3),z(3);for(null;p<19;p++)C[le[p]]=0;if(m=7,v=new Te(C,19,19,null,null,m),v.status!==0)return-1;for(ne=v.root,m=v.m,we=X+_,a=S=0;a<we;)if(T(m),J=ne.list[V(m)],p=J.b,z(p),p=J.n,p<16)C[a++]=S=p;else if(p===16){if(T(2),p=3+V(2),z(2),a+p>we)return-1;for(;p-- >0;)C[a++]=S}else if(p===17){if(T(3),p=3+V(3),z(3),a+p>we)return-1;for(;p-- >0;)C[a++]=0;S=0}else{if(T(7),p=11+V(7),z(7),a+p>we)return-1;for(;p-- >0;)C[a++]=0;S=0}if(m=d,v=new Te(C,X,257,w,U,m),m===0&&(v.status=1),v.status!==0&&v.status!==1)return-1;for(ne=v.root,m=v.m,a=0;a<_;a++)C[a]=C[a+X];return B=b,v=new Te(C,_,0,Q,D,B),me=v.root,B=v.m,B===0&&X>257||v.status!==0?-1:Ie(O,L,A)}function H(){g||(g=[]),h=0,xe=0,ee=0,te=-1,fe=!1,K=re=0,ne=null}function je(O,L,A){var a,p;for(a=0;a<A;){if(fe&&te===-1)return a;if(K>0){if(te!==t)for(;K>0&&a<A;)K--,re&=n-1,h&=n-1,O[L+a++]=g[h++]=g[re++];else{for(;K>0&&a<A;)K--,h&=n-1,T(8),O[L+a++]=g[h++]=V(8),z(8);K===0&&(te=-1)}if(a===A)return a}if(te===-1){if(fe)break;T(1),V(1)!==0&&(fe=!0),z(1),T(2),te=V(2),z(2),ne=null,K=0}switch(te){case t:p=he(O,L+a,A-a);break;case i:ne?p=Ie(O,L+a,A-a):p=oe(O,L+a,A-a);break;case o:ne?p=Ie(O,L+a,A-a):p=Re(O,L+a,A-a);break;default:p=-1;break}if(p===-1)return fe?0:-1;a+=p}return a}function He(O){var L=[],A;H(),E=O,r=0;do A=je(L,L.length,1024);while(A>0);return E=null,L}nr.exports=He})();var Fr=nr.exports,Bt={exports:{}};(function(){var n=32768,t=0,i=1,o=2,d=6,b=1024*8,g=2*n,h=3,I=258,F=8192,se=15,Y=F,xe=1<<se,ee=xe-1,te=n-1,fe=0,K=4096,re=I+h+1,ne=n-re,me=1,m=15,B=7,E=29,r=256,u=256,w=r+1+E,U=30,Q=19,D=16,le=17,De=18,Be=2*w+1,Te=parseInt((se+h-1)/h,10),Oe,T,V,z,Ie=null,he,oe,Re,H,je,He,O,L,A,a,p,S,we,J,M,X,_,C,v,y,ge,_e,Z,ce,be,j,pe,Ee,W,$,de,ae,ue,ie,N,Le,Ue,Ae,ke,ze,yt,et,tt,Ce,rt,xt,Xe,nt,Me,it,st,wt;function $e(){this.fc=0,this.dl=0}function gt(){this.dyn_tree=null,this.static_tree=null,this.extra_bits=null,this.extra_base=0,this.elems=0,this.max_length=0,this.max_code=0}function Pe(e,s,c,f){this.good_length=e,this.max_lazy=s,this.nice_length=c,this.max_chain=f}function lr(){this.next=null,this.len=0,this.ptr=[],this.off=0}var _t=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Ve=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],cr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Ft=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],ot=[new Pe(0,0,0,0),new Pe(4,4,8,4),new Pe(4,5,16,8),new Pe(4,6,32,32),new Pe(4,4,16,16),new Pe(8,16,32,32),new Pe(8,16,128,128),new Pe(8,32,128,256),new Pe(32,128,258,1024),new Pe(32,258,258,4096)];function dr(e){var s;if(e?e<1?e=1:e>9&&(e=9):e=d,Z=e,z=!1,v=!1,Ie===null){for(Oe=T=V=null,Ie=[],H=[],je=[],He=[],O=[],j=[],s=0;s<Be;s++)j[s]=new $e;for(pe=[],s=0;s<2*U+1;s++)pe[s]=new $e;for(Ee=[],s=0;s<w+2;s++)Ee[s]=new $e;for(W=[],s=0;s<U;s++)W[s]=new $e;for($=[],s=0;s<2*Q+1;s++)$[s]=new $e;de=new gt,ae=new gt,ue=new gt,ie=[],N=[],Ae=[],ke=[],ze=[],yt=[],et=[],tt=[]}}function hr(e){e.next=Oe,Oe=e}function pr(){var e;return Oe!==null?(e=Oe,Oe=Oe.next):e=new lr,e.next=null,e.len=e.off=0,e}function Rt(e){return O[n+e]}function Ut(e,s){return O[n+e]=s}function at(e){Ie[oe+he++]=e,oe+he===b&&Sr()}function ut(e){e&=65535,oe+he<b-2?(Ie[oe+he++]=e&255,Ie[oe+he++]=e>>>8):(at(e&255),at(e>>>8))}function ft(){p=(p<<Te^H[_+h-1]&255)&ee,S=Rt(p),O[_&te]=S,Ut(p,_)}function qe(e,s){Se(s[e].fc,s[e].dl)}function Mt(e){return(e<256?ze[e]:ze[256+(e>>7)])&255}function Nt(e,s,c){return e[s].fc<e[c].fc||e[s].fc===e[c].fc&&Ae[s]<=Ae[c]}function Qt(e,s,c){var f;for(f=0;f<c&&wt<st.length;f++)e[s+f]=st[wt++]&255;return f}function vr(){var e;for(e=0;e<xe;e++)O[n+e]=0;if(_e=ot[Z].max_lazy,ce=ot[Z].good_length,be=ot[Z].nice_length,ge=ot[Z].max_chain,_=0,a=0,y=Qt(H,0,2*n),y<=0){v=!0,y=0;return}for(v=!1;y<re&&!v;)bt();for(p=0,e=0;e<h-1;e++)p=(p<<Te^H[e]&255)&ee}function jt(e){var s=ge,c=_,f,l,x=X,q=_>ne?_-ne:fe,R=_+I,P=H[c+x-1],ve=H[c+x],k,Fe;X>=ce&&(s>>=2);do if(f=e,!(H[f+x]!==ve||H[f+x-1]!==P||H[f]!==H[c]||H[++f]!==H[c+1])){for(c+=2,f++;c<R;){for(Fe=!1,k=0;k<8;k+=1)if(c+=1,f+=1,H[c]!==H[f]){Fe=!0;break}if(Fe)break}if(l=I-(R-c),c=R-I,l>x){if(C=e,x=l,l>=be)break;P=H[c+x-1],ve=H[c+x]}}while((e=O[e&te])>q&&--s!==0);return x}function bt(){var e,s,c=g-y-_;if(c===-1)c--;else if(_>=n+ne){for(e=0;e<n;e++)H[e]=H[e+n];for(C-=n,_-=n,a-=n,e=0;e<xe;e++)s=Rt(e),Ut(e,s>=n?s-n:fe);for(e=0;e<n;e++)s=O[e],O[e]=s>=n?s-n:fe;c+=n}v||(e=Qt(H,_+y,c),e<=0?v=!0:y+=e)}function mr(){for(;y!==0&&T===null;){var e;if(ft(),S!==fe&&_-S<=ne&&(M=jt(S),M>y&&(M=y)),M>=h)if(e=We(_-C,M-h),y-=M,M<=_e){M--;do _++,ft();while(--M!==0);_++}else _+=M,M=0,p=H[_]&255,p=(p<<Te^H[_+1]&255)ⅇelse e=We(0,H[_]&255),y--,_++;for(e&&(lt(0),a=_);y<re&&!v;)bt()}}function yr(){for(;y!==0&&T===null;){if(ft(),X=M,we=C,M=h-1,S!==fe&&X<_e&&_-S<=ne&&(M=jt(S),M>y&&(M=y),M===h&&_-C>K&&M--),X>=h&&M<=X){var e;e=We(_-1-we,X-h),y-=X-1,X-=2;do _++,ft();while(--X!==0);J=!1,M=h-1,_++,e&&(lt(0),a=_)}else J?(We(0,H[_-1]&255)&&(lt(0),a=_),_++,y--):(J=!0,_++,y--);for(;y<re&&!v;)bt()}}function xr(){v||(L=0,A=0,gr(),vr(),T=null,he=0,oe=0,Z<=3?(X=h-1,M=0):(M=h-1,J=!1),Re=!1)}function wr(e,s,c){var f;return!z&&(xr(),z=!0,y===0)?(Re=!0,0):(f=Ht(e,s,c),f===c?c:Re?f:(Z<=3?mr():yr(),y===0&&(J&&We(0,H[_-1]&255),lt(1),Re=!0),f+Ht(e,f+s,c-f)))}function Ht(e,s,c){var f,l,x;for(f=0;T!==null&&f<c;){for(l=c-f,l>T.len&&(l=T.len),x=0;x<l;x++)e[s+f+x]=T.ptr[T.off+x];if(T.off+=l,T.len-=l,f+=l,T.len===0){var q;q=T,T=T.next,hr(q)}}if(f===c)return f;if(oe<he){for(l=c-f,l>he-oe&&(l=he-oe),x=0;x<l;x++)e[s+f+x]=Ie[oe+x];oe+=l,f+=l,he===oe&&(he=oe=0)}return f}function gr(){var e,s,c,f,l;if(W[0].dl===0){for(de.dyn_tree=j,de.static_tree=Ee,de.extra_bits=_t,de.extra_base=r+1,de.elems=w,de.max_length=m,de.max_code=0,ae.dyn_tree=pe,ae.static_tree=W,ae.extra_bits=Ve,ae.extra_base=0,ae.elems=U,ae.max_length=m,ae.max_code=0,ue.dyn_tree=$,ue.static_tree=null,ue.extra_bits=cr,ue.extra_base=0,ue.elems=Q,ue.max_length=B,ue.max_code=0,c=0,f=0;f<E-1;f++)for(yt[f]=c,e=0;e<1<<_t[f];e++)ke[c++]=f;for(ke[c-1]=f,l=0,f=0;f<16;f++)for(et[f]=l,e=0;e<1<<Ve[f];e++)ze[l++]=f;for(l>>=7;f<U;f++)for(et[f]=l<<7,e=0;e<1<<Ve[f]-7;e++)ze[256+l++]=f;for(s=0;s<=m;s++)ie[s]=0;for(e=0;e<=143;)Ee[e++].dl=8,ie[8]++;for(;e<=255;)Ee[e++].dl=9,ie[9]++;for(;e<=279;)Ee[e++].dl=7,ie[7]++;for(;e<=287;)Ee[e++].dl=8,ie[8]++;for(zt(Ee,w+1),e=0;e<U;e++)W[e].dl=5,W[e].fc=Wt(e,5);kt()}}function kt(){var e;for(e=0;e<w;e++)j[e].fc=0;for(e=0;e<U;e++)pe[e].fc=0;for(e=0;e<Q;e++)$[e].fc=0;j[u].fc=1,Me=it=0,Ce=rt=xt=0,Xe=0,nt=1}function Et(e,s){for(var c=N[s],f=s<<1;f<=Le&&(f<Le&&Nt(e,N[f+1],N[f])&&f++,!Nt(e,c,N[f]));)N[s]=N[f],s=f,f<<=1;N[s]=c}function _r(e){var s=e.dyn_tree,c=e.extra_bits,f=e.extra_base,l=e.max_code,x=e.max_length,q=e.static_tree,R,P,ve,k,Fe,Dt,ct=0;for(k=0;k<=m;k++)ie[k]=0;for(s[N[Ue]].dl=0,R=Ue+1;R<Be;R++)P=N[R],k=s[s[P].dl].dl+1,k>x&&(k=x,ct++),s[P].dl=k,!(P>l)&&(ie[k]++,Fe=0,P>=f&&(Fe=c[P-f]),Dt=s[P].fc,Me+=Dt*(k+Fe),q!==null&&(it+=Dt*(q[P].dl+Fe)));if(ct!==0){do{for(k=x-1;ie[k]===0;)k--;ie[k]--,ie[k+1]+=2,ie[x]--,ct-=2}while(ct>0);for(k=x;k!==0;k--)for(P=ie[k];P!==0;)ve=N[--R],!(ve>l)&&(s[ve].dl!==k&&(Me+=(k-s[ve].dl)*s[ve].fc,s[ve].fc=k),P--)}}function zt(e,s){var c=[],f=0,l,x;for(l=1;l<=m;l++)f=f+ie[l-1]<<1,c[l]=f;for(x=0;x<=s;x++){var q=e[x].dl;q!==0&&(e[x].fc=Wt(c[q]++,q))}}function St(e){var s=e.dyn_tree,c=e.static_tree,f=e.elems,l,x,q=-1,R=f;for(Le=0,Ue=Be,l=0;l<f;l++)s[l].fc!==0?(N[++Le]=q=l,Ae[l]=0):s[l].dl=0;for(;Le<2;){var P=N[++Le]=q<2?++q:0;s[P].fc=1,Ae[P]=0,Me--,c!==null&&(it-=c[P].dl)}for(e.max_code=q,l=Le>>1;l>=1;l--)Et(s,l);do l=N[me],N[me]=N[Le--],Et(s,me),x=N[me],N[--Ue]=l,N[--Ue]=x,s[R].fc=s[l].fc+s[x].fc,Ae[l]>Ae[x]+1?Ae[R]=Ae[l]:Ae[R]=Ae[x]+1,s[l].dl=s[x].dl=R,N[me]=R++,Et(s,me);while(Le>=2);N[--Ue]=N[me],_r(e),zt(s,q)}function Xt(e,s){var c,f=-1,l,x=e[0].dl,q=0,R=7,P=4;for(x===0&&(R=138,P=3),e[s+1].dl=65535,c=0;c<=s;c++)l=x,x=e[c+1].dl,!(++q<R&&l===x)&&(q<P?$[l].fc+=q:l!==0?(l!==f&&$[l].fc++,$[D].fc++):q<=10?$[le].fc++:$[De].fc++,q=0,f=l,x===0?(R=138,P=3):l===x?(R=6,P=3):(R=7,P=4))}function $t(e,s){var c,f=-1,l,x=e[0].dl,q=0,R=7,P=4;for(x===0&&(R=138,P=3),c=0;c<=s;c++)if(l=x,x=e[c+1].dl,!(++q<R&&l===x)){if(q<P)do qe(l,$);while(--q!==0);else l!==0?(l!==f&&(qe(l,$),q--),qe(D,$),Se(q-3,2)):q<=10?(qe(le,$),Se(q-3,3)):(qe(De,$),Se(q-11,7));q=0,f=l,x===0?(R=138,P=3):l===x?(R=6,P=3):(R=7,P=4)}}function br(){var e;for(Xt(j,de.max_code),Xt(pe,ae.max_code),St(ue),e=Q-1;e>=3&&$[Ft[e]].dl===0;e--);return Me+=3*(e+1)+5+5+4,e}function Er(e,s,c){var f;for(Se(e-257,5),Se(s-1,5),Se(c-4,4),f=0;f<c;f++)Se($[Ft[f]].dl,3);$t(j,e-1),$t(pe,s-1)}function lt(e){var s,c,f,l,x;if(l=_-a,tt[xt]=Xe,St(de),St(ae),f=br(),s=Me+3+7>>3,c=it+3+7>>3,c<=s&&(s=c),l+4<=s&&a>=0)for(Se((t<<1)+e,3),Gt(),ut(l),ut(~l),x=0;x<l;x++)at(H[a+x]);else c===s?(Se((i<<1)+e,3),Vt(Ee,W)):(Se((o<<1)+e,3),Er(de.max_code+1,ae.max_code+1,f+1),Vt(j,pe));kt(),e!==0&&Gt()}function We(e,s){if(He[Ce++]=s,e===0?j[s].fc++:(e--,j[ke[s]+r+1].fc++,pe[Mt(e)].fc++,je[rt++]=e,Xe|=nt),nt<<=1,Ce&7||(tt[xt++]=Xe,Xe=0,nt=1),Z>2&&!(Ce&4095)){var c=Ce*8,f=_-a,l;for(l=0;l<U;l++)c+=pe[l].fc*(5+Ve[l]);if(c>>=3,rt<parseInt(Ce/2,10)&&c<parseInt(f/2,10))return!0}return Ce===F-1||rt===Y}function Vt(e,s){var c,f,l=0,x=0,q=0,R=0,P,ve;if(Ce!==0)do l&7||(R=tt[q++]),f=He[l++]&255,R&1?(P=ke[f],qe(P+r+1,e),ve=_t[P],ve!==0&&(f-=yt[P],Se(f,ve)),c=je[x++],P=Mt(c),qe(P,s),ve=Ve[P],ve!==0&&(c-=et[P],Se(c,ve))):qe(f,e),R>>=1;while(l<Ce);qe(u,e)}var It=16;function Se(e,s){A>It-s?(L|=e<<A,ut(L),L=e>>It-A,A+=s-It):(L|=e<<A,A+=s)}function Wt(e,s){var c=0;do c|=e&1,e>>=1,c<<=1;while(--s>0);return c>>1}function Gt(){A>8?ut(L):A>0&&at(L),L=0,A=0}function Sr(){var e,s;if(he!==0){for(e=pr(),T===null?T=V=e:V=V.next=e,e.len=he-oe,s=0;s<e.len;s++)e.ptr[s]=Ie[oe+s];he=oe=0}}function Ir(e,s){var c,f;st=e,wt=0,typeof s>"u"&&(s=d),dr(s),f=[];do c=wr(f,f.length,1024);while(c>0);return st=null,f}Bt.exports=Ir,Bt.exports.DEFAULT_LEVEL=d})();var Rr=Bt.exports;(function(){rr.exports={inflate:Fr,deflate:Rr}})();var Ur=rr.exports;(function(){var n=qr,t=Ur,i=31,o=139,d={deflate:8},b={FTEXT:1,FHCRC:2,FEXTRA:4,FNAME:8,FCOMMENT:16},g={fat:0,amiga:1,vmz:2,unix:3,"vm/cms":4,atari:5,hpfs:6,macintosh:7,"z-system":8,cplm:9,"tops-20":10,ntfs:11,qdos:12,acorn:13,vfat:14,vms:15,beos:16,tandem:17,theos:18},h="unix",I=6;function F(m,B){B.push(m&255)}function se(m,B){B.push(m&255),B.push(m>>>8)}function Y(m,B){se(m&65535,B),se(m>>>16,B)}function xe(m,B){var E,r=m.length;for(E=0;E<r;E+=1)F(m.charCodeAt(E),B)}function ee(m){return m.shift()}function te(m){return m.shift()|m.shift()<<8}function fe(m){var B=te(m),E=te(m);return E>32768?(E-=32768,(E<<16|B)+32768*Math.pow(2,16)):E<<16|B}function K(m){for(var B=[];m[0]!==0;)B.push(String.fromCharCode(m.shift()));return m.shift(),B.join("")}function re(m,B){var E,r=[];for(E=0;E<B;E+=1)r.push(m.shift());return r}function ne(m,B){var E=0,r,u=[];return B||(B={}),r=B.level||I,typeof m=="string"&&(m=Array.prototype.map.call(m,function(w){return w.charCodeAt(0)})),F(i,u),F(o,u),F(d.deflate,u),B.name&&(E|=b.FNAME),F(E,u),Y(B.timestamp||parseInt(Date.now()/1e3,10),u),F(r===1?4:r===9?2:0,u),F(g[h],u),B.name&&(xe(B.name.substring(B.name.lastIndexOf("/")+1),u),F(0,u)),t.deflate(m,r).forEach(function(w){F(w,u)}),Y(parseInt(n(m),16),u),Y(m.length,u),u}function me(m,B){var E=Array.prototype.slice.call(m,0),r,u,w,U,Q,D;if(ee(E)!==i||ee(E)!==o)throw"Not a GZIP file";if(r=ee(E),r=Object.keys(d).some(function(le){return u=le,d[le]===r}),!r)throw"Unsupported compression method";if(w=ee(E),fe(E),ee(E),r=ee(E),Object.keys(g).some(function(le){if(g[le]===r)return!0}),w&b.FEXTRA&&(r=te(E),re(E,r)),w&b.FNAME&&K(E),w&b.FCOMMENT&&K(E),w&b.FHCRC&&te(E),u==="deflate"&&(D=t.inflate(E.splice(0,E.length-8))),w&b.FTEXT&&(D=Array.prototype.map.call(D,function(le){return String.fromCharCode(le)}).join("")),U=fe(E),U!==parseInt(n(D),16))throw"Checksum does not match";if(Q=fe(E),Q!==D.length)throw"Size of decompressed file not correct";return D}tr.exports={zip:ne,unzip:me,get DEFAULT_LEVEL(){return I}}})();var Mr=tr.exports;const Nr=Cr(Mr);class Ze{constructor(){if(this.state={pixelId:"",libName:"",libVersion:"",env:"dev"},Ze.instance)return Ze.instance;Ze.instance=this}getState(){return this.state}setState(t){const i=Object.fromEntries(Object.entries(t).filter(([,o])=>o!==void 0));this.state={...this.state,...i}}getPixelId(){return this.state.pixelId}getLibVersion(){return this.state.libVersion}getLibName(){return this.state.libName}}const Ne=new Ze,Qr="ASPixel",jr=1,Qe="ASPixelStore",Jt="AS_USER_PSEUDO_ID",Lt="AS_CUSTOMER_ID",Zt="AS_USER_SESSION_ID",ir="AS_AM_ID",ht="_sc_p",Yt="AS_SC_P";function Hr(n,t){const i={};if(typeof window>"u")return i;const o=new URLSearchParams(n);return t.forEach(d=>{const b=o.get(d);b&&(i[d]=b)}),i}function kr(n){return n.split("*").reduce((i,o)=>{const d=o.split(":");return i={...i,[d[0]]:d[1]},i},{})}function Pt(n,t){try{const i=JSON.stringify(t);sessionStorage.setItem(n,i)}catch{}}function Ct(n){try{const t=sessionStorage.getItem(n);return t?JSON.parse(t):null}catch{return null}}function sr(){return new Promise((n,t)=>{if(!window.indexedDB){t(new Error("IndexedDB is not supported"));return}try{const i=indexedDB.open(Qr,jr);i.onupgradeneeded=o=>{const d=o.target?.result;d.objectStoreNames.contains(Qe)||d.createObjectStore(Qe)},i.onsuccess=o=>{n(o.target.result)},i.onerror=o=>{t(new Error("IndexedDB error: "+o.target?.error))}}catch(i){t(new Error("Failed to access IndexedDB: "+i))}})}async function zr(n,t){if(typeof indexedDB>"u")return new Promise((o,d)=>{d(new Error("IndexedDB is not supported"))});const i=await sr();return new Promise((o,d)=>{const h=i.transaction([Qe],"readwrite").objectStore(Qe).put(t,n);h.onsuccess=()=>o(),h.onerror=I=>d(new Error("IndexedDB error: "+I.target?.error))})}async function Xr(n){if(typeof indexedDB>"u")return new Promise((i,o)=>{o(new Error("IndexedDB is not supported"))});const t=await sr();return new Promise((i,o)=>{const g=t.transaction([Qe],"readonly").objectStore(Qe).get(n);g.onsuccess=h=>i(h.target.result),g.onerror=h=>o(new Error("IndexedDB error: "+h.target?.error))})}async function qt(n,t){const i=JSON.stringify(t);try{localStorage.setItem(n,i)}catch(o){console.warn("localStorage storage failed:",o)}try{await zr(n,t)}catch(o){console.warn("IndexedDB storage failed:",o);try{localStorage.setItem(n,i)}catch(d){console.error("Both storage methods failed:",d)}}}async function or(n){try{const t=localStorage.getItem(n);if(t!==null)return JSON.parse(t);try{const i=await Xr(n);if(i!==void 0)return i}catch(i){console.warn("IndexedDB read failed:",i)}return null}catch(t){return console.error("Data retrieval failed:",t),null}}function $r(){let n=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(i){let o=Math.random()*16;return n>0?(o=(n+o)%16|0,n=Math.floor(n/16)):(o=(t+o)%16|0,t=Math.floor(t/16)),(i==="x"?o:o&3|8).toString(16)})}function mt(){return $r().replace(/-/g,"")}async function Vr(){const n=await Jr(),t=Zr(),i=Ct(ir)||"",o=await Wr();return{$user_pseudo_id:n,$session_id:t,$am_id:i,$customer_id:o}}async function Wr(){return await or(Lt)||""}async function Gr(n){await qt(Lt,n)}async function Kr(){await qt(Lt,"")}async function Jr(){let n=await or(Jt);return n||(n=mt(),await qt(Jt,n)),n}function Zr(){let n=Ct(Zt);return n||(n=mt(),Pt(Zt,n)),n}class Yr{addEventListener(t,i){window.addEventListener(t,i)}removeEventListener(t,i){window.removeEventListener(t,i)}isOnline(){return navigator.onLine}setInterval(t,i){return window.setInterval(t,i)}clearInterval(t){window.clearInterval(t)}now(){return Date.now()}}class en{constructor(){this.eventHandlers=new Map,this.online=!0}addEventListener(t,i){this.eventHandlers.has(t)||this.eventHandlers.set(t,[]),this.eventHandlers.get(t)?.push(i)}removeEventListener(t,i){const o=this.eventHandlers.get(t);if(o){const d=o.indexOf(i);d>-1&&o.splice(d,1)}}isOnline(){return this.online}setInterval(t,i){return setInterval(t,i)}clearInterval(t){clearInterval(t)}now(){return Date.now()}setOnline(t){this.online=t,this.eventHandlers.get(t?"online":"offline")?.forEach(o=>o())}}const ar=class Ge{constructor(){this.platform=typeof window<"u"?new Yr:new en,this.isWeb=typeof window<"u"}static getInstance(){return Ge.instance||(Ge.instance=new Ge),Ge.instance}getPlatform(){return this.platform}isWindow(){return this.isWeb}};ar.instance=null;let tn=ar;const G=tn.getInstance();class Ye{constructor(){if(this.data={},Ye.instance)return Ye.instance;Ye.instance=this,this.init()}async init(){if(G.isWindow()){this.setSCPFromUrl(window.location.href);const t=await Vr();this.data={...this.data,...t}}}identify(t){t===this.data.$customer_id||!t||(this.data={...this.data,$customer_id:t},G.isWindow()&&Gr(t))}resetIdentity(){this.data.$customer_id="",G.isWindow()&&Kr()}getIdentify(){return this.data}reset(){this.data={}}setSCPFromUrl(t){if(!G.isWindow()||!t)return;const i=new URL(t),o=Hr(i.search,[ht]);if(o[ht]){Pt(Yt,o[ht]);const d=kr(o[ht]);d.lid&&Pt(ir,d.lid)}}getSCPFromSession(){return G.isWindow()?Ct(Yt):""}}const vt=new Ye;class rn{constructor(){this.formatEventData=(t,i)=>{const o=i?.$pixel_id,d=i?.$env,b=i?.$sc_p;return o&&delete i.$pixel_id,d&&delete i.$env,b&&delete i.$sc_p,{$event_name:t,$event_timestamp:G.getPlatform().now(),$user_properties:vt.getIdentify(),$lib_version:Ne.getLibVersion(),$lib:Ne.getLibName(),$params:{...i,page_object:G.isWindow()?{page_location:window.location.href,page_title:document.title,page_referrer:document.referrer}:{page_location:"",page_title:"",page_referrer:""}},$env:d||Ne.getState().env,$pixel_id:o||Ne.getPixelId(),$log_id:mt(),$sc_p:b||vt.getSCPFromSession()||""}}}formatEventPayload(t){return{events:t}}}const ur=new rn;class nn{constructor(t){this.options=t}get ReqUrl(){const t=new URL(this.options.endpoint),i=this.options.commonQueryParams?.();return i&&Object.entries(i).forEach(([o,d])=>{t.searchParams.set(o,d)}),t.toString()}async report(t){let i;G.isWindow()?typeof window.navigator?.sendBeacon=="function"?i=this.reportBySendBeacon:i=this.reportByXHR:i=this.reportByNode;const o=ur.formatEventPayload(t),d=await i.call(this,o);return d?ye.success({description:`Event reported successfully, ${t?.length} events`,details:{payload:o,result:d}}):ye.error({description:`Event reported failed, ${t?.length} events`,details:{payload:o,result:d}}),d}async reportBySendBeacon(t){const i=this.ReqUrl,o=this.compressData(t);let d=!1;try{d=navigator.sendBeacon(i,o)}catch{return await this.reportByXHR(t)}return d?Promise.resolve(!0):Promise.reject(new Error("sendBeacon failed"))}async reportByXHR(t){try{const i=new window.XMLHttpRequest,o=this.compressData(t);return i.withCredentials=!1,i.open("POST",this.ReqUrl),i.send(o),new Promise((d,b)=>{i.onload=()=>d(!0),i.onerror=g=>b(g)})}catch{return!1}}async reportByNode(t){const i=this.compressData(t);try{const{default:o}=await Promise.resolve().then(()=>require("./index-65654678.js"));return await o.post(this.ReqUrl,i,{headers:{"Content-Type":"text/plain"},timeout:5e3,validateStatus:d=>d>=200&&d<300}),!0}catch(o){return o&&typeof o=="object"&&"isAxiosError"in o?ye.error({description:"Network request failed",details:{status:o.response?.status,statusText:o.response?.statusText,data:o.response?.data,url:this.ReqUrl}}):ye.error({description:"Unknown error during report",details:{error:o}}),!1}}compressData(t){const i=JSON.stringify(t),d=new TextEncoder().encode(i),b=Nr.zip(d,{level:9});return new Blob([new Uint8Array(b)],{type:"text/plain"})}}const sn=new nn({endpoint:"http://event-collector.as-in.io/analytics/v1/collect",commonQueryParams:()=>({pixel_id:Ne.getPixelId()})}),fr=class Ke{constructor(t){if(this.isDestroyed=!1,this.queues=[[]],this.currentQueueIndex=0,this.queueSizes=[0],this.state={maxQueueCount:10,maxQueueSize:16e3,processInterval:3e3},this.processTimer=null,this.isFlushingLock=!1,this.MAX_QUEUES=100,this.handleNetworkChange=()=>{G.getPlatform().isOnline()&&(this.ensureQueueConsistency(),this.currentQueueIndex>0&&this.flush())},this.handleVisibilityChange=()=>{typeof document<"u"&&document.visibilityState==="hidden"&&this.flush()},this.startProcessTimer=()=>{this.processTimer||(this.processTimer=G.getPlatform().setInterval(()=>{this.ensureQueueConsistency(),G.getPlatform().isOnline()&&this.queues?.some(i=>i.length>0)&&this.flushAll()},this.state.processInterval))},this.stopProcessTimer=()=>{this.processTimer&&(G.getPlatform().clearInterval(this.processTimer),this.processTimer=null)},this.judgeCurrentQueueFull=(i=0)=>{if(this.queues?.length>=this.MAX_QUEUES)return ye.warn({description:"Max queues reached, forcing flush"}),this.flush(),!0;const o=this.queues[this.currentQueueIndex],d=this.queueSizes[this.currentQueueIndex];return o.length>=this.state.maxQueueCount||d+i>this.state.maxQueueSize},this.enqueue=async(i,o)=>{if(this.isDestroyed){ye.warn({description:"EventQueue has been destroyed"});return}const d={id:mt(),name:i,properties:o,size:JSON.stringify(o).length,timestamp:G.getPlatform().now()};this.judgeCurrentQueueFull(d.size)&&(this.currentQueueIndex++,this.queues?.push([]),this.queueSizes.push(0)),this.queues[this.currentQueueIndex].push(d),this.queueSizes[this.currentQueueIndex]+=d.size,this.currentQueueIndex>0&&this.flush()},this.destroy=async()=>{if(!this.isDestroyed){for(this.isDestroyed=!0;this.queues?.length>0&&this.queues?.[0]?.length>0;)await this.flush();typeof window<"u"&&(G.getPlatform().removeEventListener("pagehide",this.flush),G.getPlatform().removeEventListener("visibilitychange",this.handleVisibilityChange),G.getPlatform().removeEventListener("beforeunload",this.flush)),typeof process<"u"&&(process.removeListener("beforeExit",this.destroy),process.removeListener("SIGINT",this.destroy)),G.getPlatform().removeEventListener("online",this.handleNetworkChange),G.getPlatform().removeEventListener("offline",this.handleNetworkChange),this.stopProcessTimer(),Ke.instance=null}},Ke.instance)return Ke.instance;Ke.instance=this,t&&(this.state=t),typeof process<"u"&&(process.on("beforeExit",this.destroy),process.on("SIGINT",()=>{this.destroy(),process.exit(0)})),this.initializeEventListeners(),this.startProcessTimer(),this.queues=[[]],this.queueSizes=[0],this.currentQueueIndex=0,t&&this.validateState(t)}initializeEventListeners(){typeof window<"u"&&(G.getPlatform().addEventListener("pagehide",this.flush),G.getPlatform().addEventListener("visibilitychange",this.handleVisibilityChange),G.getPlatform().addEventListener("beforeunload",this.flush)),G.getPlatform().addEventListener("online",this.handleNetworkChange),G.getPlatform().addEventListener("offline",this.handleNetworkChange)}async processQueues(t){await Promise.all(t.map(async i=>{try{if(i.length>0){const o=i.map(d=>ur.formatEventData(d.name,d.properties));o.length>0&&await sn.report(o)}}catch(o){ye.error({description:"Failed to process queue",details:{error:o}}),this.reEnqueueFailedEvents(i)}}))}async flush(){if(!this.isFlushingLock){if(typeof this.queues>"u"||typeof this.queueSizes>"u"||this.queues.length===0||this.queues[0]?.length===0||this.queueSizes.length===0||!this.queueSizes[0]){ye.warn({description:"Flush: queue is empty"});return}this.isFlushingLock=!0,ye.success({description:"Flush full queue events"});try{const t=this.queues?.slice(0,this.currentQueueIndex),i=this.queues?.slice(this.currentQueueIndex),o=this.queueSizes.slice(this.currentQueueIndex);await this.processQueues(t),this.queues=i,this.queueSizes=o,this.currentQueueIndex=0,this.queues?.length===0&&(this.queues=[[]],this.queueSizes=[0]),this.ensureQueueConsistency()}catch(t){ye.error({description:"Failed to flush",details:{error:t}})}finally{this.isFlushingLock=!1}}}reEnqueueFailedEvents(t){const i=[];let o=0;for(const d of t)i.push(d),o+=d.size;this.queues?.push(i),this.queueSizes.push(o),this.ensureQueueConsistency()}ensureQueueConsistency(){this.queues?.length!==this.queueSizes.length&&(ye.error({description:"Queue inconsistency detected"}),this.queueSizes=this.queues?.map(t=>t.reduce((i,o)=>i+o.size,0))),this.currentQueueIndex>=this.queues?.length&&(this.currentQueueIndex=this.queues?.length-1)}validateState(t){if(t.maxQueueCount<=0)throw new Error("maxQueueCount must be positive");if(t.maxQueueSize<=0)throw new Error("maxQueueSize must be positive");if(t.processInterval<1e3)throw new Error("processInterval must be at least 1000ms")}async flushAll(){if(!this.isFlushingLock){ye.success({description:"Flush all events"}),this.isFlushingLock=!0;try{if(this.queues?.length===0)return;const t=this.queues?.filter(i=>i.length>0);await this.processQueues(t),this.queues=[[]],this.queueSizes=[0],this.currentQueueIndex=0,this.ensureQueueConsistency()}catch(t){ye.error({description:"Failed to flush all events",details:{error:t}})}finally{this.isFlushingLock=!1}}}};fr.instance=null;let on=fr;const er=new on({maxQueueCount:10,maxQueueSize:16e3,processInterval:3e3});class an{constructor(){this.isInitialized=!1}async init({pixelId:t,libVersion:i,libName:o,env:d,debug:b=!1,customerId:g}){this.isInitialized=!0,Ne.setState({pixelId:t,libVersion:i,libName:o,env:d}),g&&this.identify(g),ye.setStatus(b)}async logEvent(t,i){er.enqueue(t,i)}async logEventForNode(t,i,o,d){er.enqueue(o,{...d,$sc_p:t})}async identify(t){vt.identify(t)}async resetIdentity(){vt.resetIdentity()}hasInit(){return this.isInitialized}}const un=new an,fn=Pr(Dr.default,un);module.exports=fn;