@prodantix/sdk 0.6.0 → 0.7.0-beta.438

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.
Files changed (39) hide show
  1. package/README.md +19 -0
  2. package/dist/chat.cjs +23 -18
  3. package/dist/chat.d.cts +125 -7
  4. package/dist/chat.d.ts +125 -7
  5. package/dist/chat.js +25 -20
  6. package/dist/chunk-D6PMLUYA.js +2 -0
  7. package/dist/{client-BO7f6q5k.d.cts → client-CL6Xvhay.d.cts} +2 -1
  8. package/dist/{client-BQlU_3Dc.d.ts → client-QyKW0LFW.d.ts} +2 -1
  9. package/dist/{config-DqC0lcr7.d.ts → config-C9Njc6-j.d.ts} +34 -1
  10. package/dist/{config-CMF9zz1a.d.cts → config-CpfUyEw8.d.cts} +34 -1
  11. package/dist/csp.cjs +2 -2
  12. package/dist/csp.d.cts +9 -10
  13. package/dist/csp.d.ts +9 -10
  14. package/dist/csp.js +2 -2
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +5 -5
  17. package/dist/index.d.ts +5 -5
  18. package/dist/index.js +1 -1
  19. package/dist/messenger-files.iife.js +2 -0
  20. package/dist/messenger-help.iife.js +3 -0
  21. package/dist/messenger.cjs +1 -1
  22. package/dist/messenger.d.cts +1 -1
  23. package/dist/messenger.d.ts +1 -1
  24. package/dist/messenger.iife.js +11 -6
  25. package/dist/messenger.js +1 -1
  26. package/dist/node.cjs +1 -1
  27. package/dist/node.d.cts +2 -2
  28. package/dist/node.d.ts +2 -2
  29. package/dist/node.js +1 -1
  30. package/dist/{transport-CqAmRbpQ.d.ts → transport-DKFvkfX4.d.ts} +1 -1
  31. package/dist/{transport-Cy42FY5A.d.cts → transport-DN9pXyrX.d.cts} +1 -1
  32. package/dist/{types-DjMXp6Wg.d.cts → types-Q2VNlJbG.d.cts} +1 -0
  33. package/dist/{types-DjMXp6Wg.d.ts → types-Q2VNlJbG.d.ts} +1 -0
  34. package/dist/web.cjs +1 -1
  35. package/dist/web.d.cts +9 -4
  36. package/dist/web.d.ts +9 -4
  37. package/dist/web.js +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-4RLPQZ5L.js +0 -2
package/dist/web.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var ut=Object.defineProperty;var pt=(t,e,n)=>e in t?ut(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var a=(t,e,n)=>pt(t,typeof e!="symbol"?e+"":e,n);var u=class extends Error{constructor(n,r,i){super(r,i);a(this,"code");this.code=n,this.name="ProdantixError";}},x=class extends u{constructor(e){super("config",e),this.name="ConfigError";}},k=class extends u{constructor(n,r){super("validation",r);a(this,"field");this.field=n,this.name="ValidationError";}},d=class extends u{constructor(n,r,i){super("transport",n,i);a(this,"status");this.status=r,this.name="TransportError";}};function f(t){if(t)return t;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function m(){let t=globalThis.AbortController;return t?new t:void 0}var ye=t=>new Promise(e=>{setTimeout(e,t);});function p(t){return t.replace(/\/+$/,"")}var b=class{constructor(){a(this,"store",new Map);}getItem(e){return this.store.get(e)??null}removeItem(e){this.store.delete(e);}setItem(e,n){this.store.set(e,n);}};function ve(){try{let t=globalThis.localStorage;if(t){let e="__pdx_probe__";return t.setItem(e,"1"),t.removeItem(e),t}}catch{return new b}return new b}var C={now:()=>new Date};function A(t){return t.toISOString()}function ht(){return globalThis.crypto}function ft(t){t[6]=t[6]&15|64,t[8]=t[8]&63|128;let e=[];for(let n=0;n<16;n+=1)e.push(t[n].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function Q(){let t=ht();if(t?.randomUUID)return t.randomUUID();let e=new Uint8Array(16);if(t?.getRandomValues)t.getRandomValues(e);else for(let n=0;n<16;n+=1)e[n]=Math.floor(Math.random()*256);return ft(e)}var ke={uuid:Q};var mt=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var gt=/^(?:\$|[a-z])[a-z0-9_.]*$/;function _(t){let e=0;for(let n of t)e+=1;return e}function be(t){return mt.test(t)}function yt(t){return gt.test(t)}function Ee(t){let e=_(t);if(e<1||e>200)throw new k("distinct_id","distinct_id must be between 1 and 200 characters")}function xe(t){let e=_(t);if(e<1||e>200)throw new k("event_name","event_name must be between 1 and 200 characters");if(!yt(t))throw new k("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var Se="prodantix-js",we="0.0.1";var vt=t=>{};function Ie(t){if(!t.apiKey||!be(t.apiKey))throw new x("apiKey must be a public project key of the form pdx_pub_<32 lowercase alphanumerics>");if(!t.host)throw new x("host is required (the ingest base URL)");let e=p(t.host),n=t.defaultProperties,r=t.storage??new b;return {apiKey:t.apiKey,autocapture:t.autocapture??false,clock:t.clock??C,consent:t.consent,defaultProperties:typeof n=="function"?n:()=>n??{},flagsHost:t.flagsHost?p(t.flagsHost):e,flushAt:t.flushAt??20,flushIntervalMs:t.flushIntervalMs??1e4,host:e,ids:t.ids??ke,locale:t.locale,maxQueueSize:t.maxQueueSize??1e3,maxRetries:t.maxRetries??3,namespace:F(t.apiKey),onError:t.onError??vt,os:t.os,requestTimeoutMs:t.requestTimeoutMs??1e4,sdkName:t.sdkName??Se,sdkVersion:t.sdkVersion??we,sessionTracking:t.sessionTracking??false,sharedStorage:t.sharedStorage??r,socketFactory:t.socketFactory,storage:r,streamFlags:t.streamFlags??false,transport:t.transport}}function F(t){return t.slice(0,16)}function Te(t,e,n){xe(t.eventName),Ee(t.distinctId);let r={distinct_id:t.distinctId,event_id:t.eventId??n.uuid(),event_name:t.eventName,properties:t.properties??{},schema_version:1,timestamp:A(t.timestamp??e.now())};return t.context&&(r.context=t.context),t.sessionId&&(r.session_id=t.sessionId),r}var v=Symbol("absent");function kt(t,e){if(t==="distinct_id")return e.distinctId;let n=e.properties??{};if(Object.prototype.hasOwnProperty.call(n,t))return n[t];let r=e.attributes??{};return Object.prototype.hasOwnProperty.call(r,t)?r[t]:v}function y(t){return t===v?"undefined":String(t)}function Ce(t){return t===v?Number.NaN:Number(t)}function Ae(t){return t!==v&&t!==null&&t!==""}function _e(t,e){if(!Array.isArray(e))return false;let n=y(t);return e.map(r=>String(r)).includes(n)}function Fe(t,e){let n=kt(t.attribute,e),r=t.value;switch(t.op){case "is_set":return Ae(n);case "is_not_set":return !Ae(n);case "eq":return y(n)===y(r===void 0?v:r);case "neq":return y(n)!==y(r===void 0?v:r);case "contains":return y(n).includes(y(r===void 0?v:r));case "in":return _e(n,r);case "not_in":return Array.isArray(r)?!_e(n,r):false;case "gt":return L(n,r,(i,s)=>i>s);case "gte":return L(n,r,(i,s)=>i>=s);case "lt":return L(n,r,(i,s)=>i<s);case "lte":return L(n,r,(i,s)=>i<=s);case "in_cohort":return typeof r=="string"&&r!==""&&(e.cohorts??[]).includes(r);case "not_in_cohort":return typeof r=="string"&&r!==""&&!(e.cohorts??[]).includes(r);default:return false}}function L(t,e,n){let r=Ce(t),i=e===void 0?Number.NaN:Ce(e);return Number.isNaN(r)||Number.isNaN(i)?false:n(r,i)}function Le(t,e){let n=`${t}:${e}`,r=2166136261;for(let i=0;i<n.length;i++)r^=n.charCodeAt(i),r=Math.imul(r,16777619);return (r>>>0)%100}function Y(t,e){return t.targeting.length===0||t.targeting.every(n=>Fe(n,e))}function Ne(t,e){let n=Le(t.key,e.distinctId),r=t.variations??[];if(r.length===0)return t.rolloutPercentage>=100||n<t.rolloutPercentage?"true":"false";let i=0;for(let s=r.length-1;s>=0;s--)if(i+=r[s].weight,n<i)return r[s].key;return r[0].key}function X(t,e,n,r){for(let i of t.prerequisites??[]){if(r.includes(i.flagKey))return false;let s=e.find(c=>c.key===i.flagKey);if(!s||!s.enabled)return false;r.push(s.key);let o=X(s,e,n,r)&&Y(s,n)&&Ne(s,n)===i.variationKey;if(r.pop(),!o)return false}return true}function N(t,e,n){return t.enabled?X(t,e,n,[t.key])?Y(t,n)?t.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:Le(t.key,n.distinctId)<t.rolloutPercentage?{enabled:true,reason:"rollout"}:{enabled:false,reason:"rollout_excluded"}:{enabled:false,reason:"targeting"}:{enabled:false,reason:"prerequisite"}:{enabled:false,reason:"disabled"}}function Pe(t,e){let n={};for(let r of t)n[r.key]=N(r,t,e).enabled;return n}function Z(t,e,n){let r=t.variations??[],i=r[0];if(!i)return null;if(!t.enabled||!X(t,e,n,[t.key])||!Y(t,n))return i;let s=Ne(t,n);return r.find(o=>o.key===s)??i}function Re(t){return t.some(e=>e.targeting.some(n=>n.op==="in_cohort"||n.op==="not_in_cohort"))}function Oe(t){return `40${JSON.stringify(t)}`}function $e(){return "3"}function Me(t){let e=t.charAt(0),n=t.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let o=ee(n);return {kind:"open",pingInterval:typeof o?.pingInterval=="number"?o.pingInterval:25e3,pingTimeout:typeof o?.pingTimeout=="number"?o.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=n.charAt(0),i=n.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=ee(i);return {kind:"connectError",message:typeof o?.message=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let s=ee(i);return !Array.isArray(s)||typeof s[0]!="string"?{kind:"other"}:{kind:"event",name:s[0],payload:s[1]}}function ee(t){try{return JSON.parse(t)}catch{return null}}var bt="/socket.io/?EIO=4&transport=websocket",Et=250,P=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"pending",null);a(this,"lastKey","");a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??xt,this.setTimer=e.setTimer??((n,r)=>setTimeout(n,r)),this.clearTimer=e.clearTimer??(n=>clearTimeout(n));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${bt}`,n;try{n=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=n,n.onmessage=r=>this.receive(String(r.data)),n.onerror=()=>n.close(),n.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat(),this.pending!==null&&this.clearTimer(this.pending),this.pending=null;let e=this.socket;this.socket=null,e?.close();}receive(e){let n=Me(e);if(n.kind==="open"){this.armHeartbeat(n.pingInterval+n.pingTimeout),this.socket?.send(Oe({projectKey:this.options.projectKey}));return}if(n.kind==="ping"){this.armHeartbeat(),this.socket?.send($e());return}if(n.kind==="connectError"||n.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(n.kind==="event"){if(n.name==="ready"){this.ready=true;return}if(n.name==="flagChange"){let r=n.payload?.key;this.lastKey=typeof r=="string"?r:"",this.pending===null&&(this.pending=this.setTimer(()=>{this.pending=null,this.options.onChange(this.lastKey);},Et));}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function xt(t){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(t)}var R=class{constructor(e){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=f(e.fetch),this.host=p(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async fetchAll(e){return (await this.fetchDecisions(e)).flags}async fetchDecisions(e){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let r=`${this.host}/v1/flags?distinct_id=${encodeURIComponent(e)}`,i=m(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let o=await n(r,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!o.ok)throw new d(`flags request failed with status ${o.status}`,o.status);let c=JSON.parse(await o.text());return {flags:c.flags??{},variants:c.variants??{}}}finally{s!==void 0&&clearTimeout(s);}}async snapshot(){let e=this.fetch;if(!e)throw new d("no fetch implementation available in this runtime");let n=`${this.host}/v1/flags/snapshot`,r=m(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{let s=await e(n,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:r?.signal});if(!s.ok)throw new d(`flag snapshot request failed with status ${s.status}`,s.status);let o=JSON.parse(await s.text()),c={flags:o.flags??[],generatedAt:o.generatedAt};return typeof o.socketUrl=="string"&&o.socketUrl!==""&&(c.socketUrl=o.socketUrl),c}finally{i!==void 0&&clearTimeout(i);}}async memberships(e){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let r=`${this.host}/v1/flags/memberships?distinct_id=${encodeURIComponent(e)}`,i=m(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let o=await n(r,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!o.ok)throw new d(`memberships request failed with status ${o.status}`,o.status);return JSON.parse(await o.text()).cohorts??[]}finally{s!==void 0&&clearTimeout(s);}}};function S(t){if(typeof t!="string")return;let e=Array.from(t).length;return e>=1&&e<=200?t:void 0}function $(t,e){return `pdx.${t}.${e}`}var De="consent";function St(t){if(typeof t!="string")return null;try{let e=JSON.parse(t);if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=e.identityLink;return typeof n=="boolean"?{identityLink:n}:null}catch{return null}}function wt(t,e){return St(t.getItem($(e,De)))}function It(t,e,n){let r=$(e,De);if(typeof n.identityLink!="boolean"){t.removeItem(r);return}t.setItem(r,JSON.stringify({identityLink:n.identityLink}));}function Ke(t,e,n,r){let i=$(n,"anonymous_id"),s=S(e.getItem(i))??S(t.getItem(i));return e.setItem(i,r),t.setItem(i,r),s!==void 0&&s!==r?s:void 0}var O=class{constructor(e,n,r,i){this.storage=e;this.shared=n;this.ids=r;this.namespace=i;a(this,"anonymousId");a(this,"distinctId");a(this,"identified");this.refresh();}refresh(){let e=S(this.shared.getItem(this.key("anonymous_id"))),n=S(this.storage.getItem(this.key("anonymous_id")));e?(this.anonymousId=e,n!==e&&this.storage.setItem(this.key("anonymous_id"),e)):n?(this.anonymousId=n,this.shared.setItem(this.key("anonymous_id"),n)):(this.anonymousId=this.ids.uuid(),this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId));let r=S(this.storage.getItem(this.key("distinct_id")));r?(this.distinctId=r,this.identified=true):(this.distinctId=this.anonymousId,this.identified=false);}getAnonymousId(){return this.anonymousId}getDistinctId(){return this.distinctId}isIdentified(){return this.identified}snapshot(){return {anonymousId:this.anonymousId,distinctId:this.distinctId,identified:this.identified}}consent(){return wt(this.shared,this.namespace)}setConsent(e){It(this.shared,this.namespace,e);}identify(e){let n=!this.identified||this.distinctId!==e,r=this.storage.getItem(this.key("linked_anonymous_id")),i=n||r!==this.anonymousId;return this.distinctId=e,this.identified=true,n&&this.storage.setItem(this.key("distinct_id"),e),!i||this.consent()?.identityLink===false?{changed:n}:(this.storage.setItem(this.key("linked_anonymous_id"),this.anonymousId),{anonymousToLink:this.anonymousId,changed:n})}reset(){this.anonymousId=this.ids.uuid(),this.distinctId=this.anonymousId,this.identified=false,this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.removeItem(this.key("distinct_id")),this.storage.removeItem(this.key("linked_anonymous_id"));}key(e){return $(this.namespace,e)}};var M=class{constructor(e){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=f(e.fetch),this.host=p(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async inbox(e){let n=this.requireFetch(),r=`${this.host}/v1/messages?distinct_id=${encodeURIComponent(e)}`,i=await this.request(n,r,{headers:this.authHeaders(),method:"GET"});if(!i.ok)throw new d(`inbox request failed with status ${i.status}`,i.status);return JSON.parse(await i.text()).messages??[]}async markRead(e,n){let r=this.requireFetch(),i=`${this.host}/v1/messages/read`,s=await this.request(r,i,{body:JSON.stringify({distinct_id:n,message_id:e}),headers:{...this.authHeaders(),"content-type":"application/json"},method:"POST"});if(!s.ok)throw new d(`mark-read request failed with status ${s.status}`,s.status)}requireFetch(){if(!this.fetch)throw new d("no fetch implementation available in this runtime");return this.fetch}authHeaders(){return {authorization:`Bearer ${this.projectKey}`}}async request(e,n,r){let i=m(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(n,{...r,signal:i?.signal})}finally{s!==void 0&&clearTimeout(s);}}};var D=class{constructor(e,n){this.maxSize=e;this.onOverflow=n;a(this,"events",[]);}get size(){return this.events.length}enqueue(e){this.events.push(e),this.enforceCap();}restore(e){this.events.push(...e),this.enforceCap();}requeue(e){this.events.unshift(...e),this.enforceCap();}drain(e){let n=e===void 0?this.events.length:Math.min(e,this.events.length);return this.events.splice(0,n)}snapshot(){return [...this.events]}enforceCap(){if(this.events.length<=this.maxSize)return;let e=this.events.splice(0,this.events.length-this.maxSize);this.onOverflow?.({dropped:e});}};var Tt={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function qe(t){return `pdx.${t}.session`}function Ve(t,e,n,r){let i={id:n.id,lastActivityAt:r,startedAt:n.startedAt};t.setItem(qe(e),JSON.stringify(i));}var K=class{constructor(e,n,r,i,s=Tt){this.storage=e;this.ids=n;this.clock=r;this.namespace=i;this.options=s;}current(){return this.touch().id}startedAt(){return this.touch().startedAt}reset(){this.storage.removeItem(this.key());}touch(){let e=this.clock.now().getTime(),n=this.live(this.read(),e);if(n===void 0)return this.write({id:this.ids.uuid(),lastActivityAt:e,startedAt:e});if(e-n.lastActivityAt<=this.options.throttleMs)return n;let r=this.live(this.read(),e),i=r!==void 0&&r.id!==n.id?r:n;return this.write({...i,lastActivityAt:e})}live(e,n){if(e!==void 0&&!(n-e.lastActivityAt>this.options.idleMs||n-e.startedAt>this.options.maxMs))return e}write(e){return this.storage.setItem(this.key(),JSON.stringify(e)),e}read(){let e=this.storage.getItem(this.key());if(e)try{let n=JSON.parse(e);return typeof n.id=="string"&&typeof n.startedAt=="number"&&typeof n.lastActivityAt=="number"?{id:n.id,lastActivityAt:n.lastActivityAt,startedAt:n.startedAt}:void 0}catch{return}}key(){return qe(this.namespace)}};var l={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageview:"$pageview",set:"$set"};function je(t){return t>=400&&t<500&&t!==429}var E=class{constructor(e={}){a(this,"fetch");a(this,"maxRetries");a(this,"requestTimeoutMs");a(this,"baseDelayMs");a(this,"maxDelayMs");a(this,"sleep");a(this,"random");this.fetch=f(e.fetch),this.maxRetries=e.maxRetries??3,this.requestTimeoutMs=e.requestTimeoutMs??1e4,this.baseDelayMs=e.baseDelayMs??500,this.maxDelayMs=e.maxDelayMs??3e4,this.sleep=e.sleep??ye,this.random=e.random??Math.random;}async send(e){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let r=JSON.stringify(e.body),i;for(let s=0;s<=this.maxRetries;s+=1){try{let o=await this.attempt(n,e,r);if(o.ok)return;if(je(o.status))throw new d(`ingest rejected batch with status ${o.status}`,o.status);i=new d(`ingest transient status ${o.status}`,o.status);}catch(o){if(o instanceof d&&o.status!==void 0&&je(o.status))throw o;i=o;}s<this.maxRetries&&await this.sleep(this.backoff(s));}throw new d("ingest delivery failed after retries",void 0,{cause:i})}async attempt(e,n,r){let i=m(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(n.url,{body:r,headers:{authorization:`Bearer ${n.projectKey}`,"content-type":"application/json"},method:"POST",signal:i?.signal})}finally{s!==void 0&&clearTimeout(s);}}backoff(e){return Math.min(this.maxDelayMs,this.baseDelayMs*2**e)+this.random()*this.baseDelayMs}};var Ct="queue",At=1e3,He=3e4,te=t=>{let e={};return t.avatar!==void 0&&(e.$avatar=t.avatar),t.email!==void 0&&(e.$email=t.email),t.name!==void 0&&(e.$name=t.name),t.phone!==void 0&&(e.$phone=t.phone),e},q=class{constructor(e){a(this,"config");a(this,"identity");a(this,"session");a(this,"queue");a(this,"transport");a(this,"flagsClient");a(this,"messagesClient");a(this,"context");a(this,"flushTimer");a(this,"flushing",false);a(this,"cachedFlags");a(this,"cachedSnapshot");a(this,"membershipCache");a(this,"stream");a(this,"shutDown",false);a(this,"exposures",new Set);this.config=Ie(e),this.identity=new O(this.config.storage,this.config.sharedStorage,this.config.ids,this.config.namespace),this.config.consent!==void 0&&this.identity.setConsent(this.config.consent),this.session=this.config.sessionTracking?new K(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new D(this.config.maxQueueSize,({dropped:n})=>{this.config.onError(new u("queue_overflow",`event queue overflow: dropped ${n.length} oldest event(s)`));}),this.transport=this.config.transport??new E({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new R({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new M({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.context={sdk:this.config.sdkName,sdk_version:this.config.sdkVersion},this.config.os&&(this.context.os=this.config.os),this.config.locale&&(this.context.locale=this.config.locale),this.restoreQueue(),this.startTimer();}get distinctId(){return this.identity.getDistinctId()}get anonymousId(){return this.identity.getAnonymousId()}get isIdentified(){return this.identity.isIdentified()}get sessionId(){return this.session?.current()}get sessionStartedAt(){return this.session?.startedAt()}capture(e,n={}){try{this.identity.refresh();let r={...this.config.defaultProperties(),...n.properties??{}},i=Te({context:this.context,distinctId:n.distinctId??this.identity.getDistinctId(),eventName:e,properties:r,sessionId:n.sessionId??this.session?.current(),timestamp:n.timestamp},this.config.clock,this.config.ids);this.enqueue(i);}catch(r){this.config.onError(r);}}identify(e,n={}){this.identity.refresh();let r=this.identity.identify(e),i={};r.anonymousToLink!==void 0&&(i.$anon_distinct_id=r.anonymousToLink);let s={...te(n.traits??{}),...n.set??{}};Object.keys(s).length>0&&(i.$set=s),this.capture(l.identify,{properties:i});}link(e,n,r){let i={$anon_distinct_id:n},s=te(r??{});Object.keys(s).length>0&&(i.$set=s),this.capture(l.identify,{distinctId:e,properties:i});}setConsent(e){this.identity.setConsent(e);}consent(){return this.identity.consent()}alias(e){this.capture(l.createAlias,{properties:{alias:e}});}group(e,n,r){let i={$group_key:n,$group_type:e};r&&(i.$set=r),this.capture(l.group,{properties:i});}setPersonProperties(e,n){let r={};e&&(r.$set=e),n&&(r.$set_once=n),this.capture(l.set,{properties:r});}setPersonTraits(e){let n=te(e);Object.keys(n).length!==0&&this.capture(l.set,{properties:{$set:n}});}async getAllFlags(){let e=this.identity.getDistinctId(),n=await this.flagsClient.fetchDecisions(e);return this.cachedFlags={distinctId:e,flags:n.flags,variants:n.variants??{}},n.flags}async isFeatureEnabled(e){let r=(await this.getAllFlags())[e]??false;return this.recordExposure(e,this.cachedFlags?.variants[e]?.key??String(r)),r}async getVariant(e){let n=await this.getAllFlags(),r=this.cachedFlags?.variants[e]??null;return this.recordExposure(e,r?.key??String(n[e]??false)),r}async getVariantLocal(e,n={}){let r=await this.flagSnapshot(),i=r.flags.find(h=>h.key===e),s=await this.localContext(n,r.flags),o=i?Z(i,r.flags,s):null,c=i?N(i,r.flags,s).enabled:false;return this.recordExposure(e,o?.key??String(c)),o?{key:o.key,value:o.value}:null}recordExposure(e,n){let r=`${this.identity.getDistinctId()} ${e} ${n}`;this.exposures.has(r)||(this.exposures.add(r),this.capture(l.featureFlagCalled,{properties:{$feature_flag:e,$feature_flag_response:n}}));}getCachedFlag(e){if(!(!this.cachedFlags||this.cachedFlags.distinctId!==this.distinctId))return this.cachedFlags.flags[e]}async getLocalFlags(e={}){let n=await this.flagSnapshot();return Pe(n.flags,await this.localContext(e,n.flags))}async isFeatureEnabledLocal(e,n={}){let r=await this.flagSnapshot(),i=r.flags.find(c=>c.key===e),s=await this.localContext(n,r.flags),o=i?N(i,r.flags,s).enabled:false;return this.recordExposure(e,(i?Z(i,r.flags,s)?.key:void 0)??String(o)),o}async localContext(e,n){let r=this.identity.getDistinctId(),i=e.cohorts;if(i===void 0&&Re(n)){let s=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===r&&s-this.membershipCache.fetchedAt<He?i=this.membershipCache.cohorts:(i=await this.flagsClient.memberships(r),this.membershipCache={cohorts:i,distinctId:r,fetchedAt:s});}return {attributes:e.attributes,cohorts:i,distinctId:r,properties:e.properties}}async flagSnapshot(){let e=this.config.clock.now().getTime();if(this.cachedSnapshot&&e-this.cachedSnapshot.fetchedAt<He)return this.cachedSnapshot.snapshot;let n=await this.flagsClient.snapshot();return this.cachedSnapshot={fetchedAt:e,snapshot:n},this.maybeStream(n),n}maybeStream(e){if(!this.config.streamFlags||this.shutDown||this.stream||!e.socketUrl)return;let n=new P({host:e.socketUrl,onChange:()=>{this.cachedSnapshot=void 0,this.flagSnapshot().catch(r=>this.config.onError(r));},onClosed:r=>{this.stream=void 0,r&&this.maybeStream(e);},projectKey:this.config.apiKey,socketFactory:this.config.socketFactory});this.stream=n,n.open();}async getInbox(){return this.messagesClient.inbox(this.identity.getDistinctId())}async markMessageRead(e){await this.messagesClient.markRead(e,this.identity.getDistinctId());}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(At);try{await this.transport.send({body:{events:e,sent_at:A(this.config.clock.now())},projectKey:this.config.apiKey,url:`${this.config.host}/v1/events`}),this.persistQueue();}catch(n){this.queue.requeue(e),this.persistQueue(),this.config.onError(n);}finally{this.flushing=false;}}reset(){this.session?.reset(),this.identity.reset(),this.cachedFlags=void 0,this.cachedSnapshot=void 0,this.membershipCache=void 0;}async shutdown(){this.shutDown=true,this.stopTimer(),this.stream?.close(),this.stream=void 0,await this.flush();}enqueue(e){this.queue.enqueue(e),this.persistQueue(),this.queue.size>=this.config.flushAt&&this.flush();}persistQueue(){try{this.config.storage.setItem(this.persistKey(),JSON.stringify(this.queue.snapshot()));}catch(e){this.config.onError(e);}}restoreQueue(){try{let e=this.config.storage.getItem(this.persistKey());if(!e)return;let n=JSON.parse(e);Array.isArray(n)&&this.queue.restore(n);}catch(e){this.config.onError(e);}}startTimer(){if(this.config.flushIntervalMs<=0)return;let e=setInterval(()=>{this.flush();},this.config.flushIntervalMs),n=e;typeof n.unref=="function"&&n.unref(),this.flushTimer=e;}stopTimer(){this.flushTimer!==void 0&&(clearInterval(this.flushTimer),this.flushTimer=void 0);}persistKey(){return `pdx.${this.config.namespace}.${Ct}`}};var _t="data-pdx-no-capture",Ft="pdx-no-capture",Lt=new Set(["input","select","textarea"]),Nt=new Set(["email","password","tel"]);function re(){return globalThis.location}function Ue(){return globalThis.document}function Pt(){return globalThis.window??globalThis}function Rt(t){return typeof t=="object"&&t!==null&&typeof t.tagName=="string"}function ne(t,e){let n;try{n=new URL(t,e);}catch{return}return n.protocol==="http:"||n.protocol==="https:"?`${n.origin}${n.pathname}`:n.protocol}function Je(){let t=re(),e=Ue(),n={};if(t){let r=ne(t.href);r&&(n.$current_url=r),n.$pathname=t.pathname,n.$host=t.host;}if(e){e.title&&(n.$title=e.title);let r=e.referrer?ne(e.referrer):void 0;r&&(n.$referrer=r);}return n}function Be(t){return typeof t.className=="string"?t.className:""}function Ot(t){return Lt.has(t.tagName.toLowerCase())||Nt.has((t.getAttribute("type")??"").toLowerCase())}function $t(t,e,n){let r={$el_tag:t.tagName.toLowerCase(),$event_type:"click"};if(e)return r;let i=n?t.textContent?.trim():void 0;i&&(r.$el_text=i.slice(0,255)),t.id&&(r.$el_id=t.id);let s=Be(t);s&&(r.$el_classes=s);let o=t.getAttribute("href"),c=o?ne(o,re()?.href):void 0;return c&&(r.$el_href=c),r}function Mt(t,e){let n=new Set,r=(s,o)=>{if(n.has(o)||!s.matches)return false;try{return s.matches(o)}catch(c){return n.add(o),e(new u("config",`autocapture maskSelectors entry "${o}" is not a valid selector`,{cause:c})),false}},i=s=>s.getAttribute(_t)!==null||Be(s).split(/\s+/).includes(Ft)||Ot(s)||t.some(o=>r(s,o));return s=>{for(let o=s;o;o=o.parentElement)if(i(o))return true;return false}}function Dt(t){let e=globalThis.history,n=Pt(),r="",i=()=>{let c=re(),h=c?`${c.pathname}${c.search}`:"";h!==r&&(r=h,t.capture(l.pageview,{properties:Je()}));};if(i(),!e||!n)return ()=>{};let s=e.pushState.bind(e),o=e.replaceState.bind(e);return e.pushState=(...c)=>{s(...c),i();},e.replaceState=(...c)=>{o(...c),i();},n.addEventListener("popstate",i),()=>{e.pushState=s,e.replaceState=o,n.removeEventListener("popstate",i);}}function Kt(t,e){let n=Ue();if(!n)return ()=>{};let r=Mt(e.maskSelectors??[],e.onError??(()=>{})),i=e.captureElementText??false,s=o=>{let c=o.target;Rt(c)&&t.capture(l.autocapture,{properties:{...Je(),...$t(c,r(c),i)}});};return n.addEventListener("click",s,true),()=>n.removeEventListener("click",s,true)}function ze(t,e={}){let n=[];return (e.pageviews??true)&&n.push(Dt(t)),(e.clicks??true)&&n.push(Kt(t,e)),()=>{for(let r of n)r();}}function qt(){return globalThis.document?.visibilityState==="hidden"}function Vt(t){let e=globalThis.navigator,n=globalThis.Blob;if(!e?.sendBeacon||!n)return false;let r=JSON.stringify({...t.body,api_key:t.projectKey});try{let i=new n([r],{type:"application/json"});return e.sendBeacon(t.url,i)}catch{return false}}var V=class{constructor(e={}){a(this,"fetchTransport");this.fetchTransport=new E(e);}async send(e){qt()&&Vt(e)||await this.fetchTransport.send(e);}};var jt=/^\d{1,3}(\.\d{1,3}){3}$/,Ht=/^[a-z0-9.-]+$/i;function Ge(){return Math.random().toString(36).slice(2,12)}function j(t,e){let n=`${e}=`,r=[];for(let i of t.cookie.split(";")){let s=i.trim();s.startsWith(n)&&r.push(s.slice(n.length));}return r}function w(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function We(t,e,n,r){try{let i=`pdx_probe_${r()}`,s=r();t.cookie=`${i}=${s}; ${w(e,60,n)}`;let o=j(t,i).includes(s);t.cookie=`${i}=; ${w(e,0,n)}`;let c=j(t,i).includes(s);return o&&!c}catch{return false}}function se(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||jt.test(e)||!e.includes("."))return [];let n=e.split("."),r=[];for(let i=n.length-2;i>=0;i-=1)r.push(n.slice(i).join("."));return r}function Qe(t,e,n,r=Ge){for(let i of se(t))if(We(e,i,n,r))return i}function Ut(t){let e=new Map,n=JSON.parse(decodeURIComponent(t));if(n===null||typeof n!="object"||Array.isArray(n))return e;for(let[r,i]of Object.entries(n))typeof i=="string"&&e.set(r,i);return e}var ie=class{constructor(e,n,r,i){this.jar=e;this.name=n;this.domain=r;this.secure=i;}getItem(e){return this.read().get(e)??null}setItem(e,n){let r=this.read();r.set(e,n),this.write(r);}removeItem(e){let n=this.read();n.delete(e)&&this.write(n);}read(){try{let e=j(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${w(void 0,0,this.secure)}`,e=j(this.jar,this.name));let n=e[0];return n?Ut(n):new Map}catch{return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${w(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${w(this.domain,31536e3,this.secure)}`;}catch{return}}};function Jt(){return globalThis.document}function Bt(){return globalThis.location?.hostname??""}function zt(){return globalThis.location?.protocol==="https:"}function Gt(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Ht.test(e)?e.toLowerCase():void 0}function oe(t){let e="jar"in t?t.jar:Jt();if(!e||globalThis.navigator?.cookieEnabled===false)return null;let r=t.random??Ge,i=t.secure??zt(),s=t.hostname??Bt();try{let o=Gt(t.domain)??Qe(s,e,i,r);return We(e,o,i,r)?new ie(e,t.name,o,i):null}catch{return null}}var Ze="_pdx",et="~",Wt=200,Qt=/^\d+$/;function tt(t,e,n,r){let i=Xt(t.href);if(i===void 0||ce(i.search).some(de))return;let s=Ye(i.hostname,n);s===void 0||s===Ye(r,n)||(i.search=`${i.search}${i.search?"&":"?"}${Ze}=${Yt(e)}`,t.href=i.href);}function Yt(t){return [t.anonymousId,t.sessionId,String(t.sessionStartedAt)].map(en).join(et)}function nt(t){let e=ce(t).find(de);if(e===void 0)return;let n=Zt(e).split(et);if(n.length!==3)return;let r=H(n[0]),i=H(n[1]),s=H(n[2]);if(!(!Xe(r)||!Xe(i)||!tn(s)))return {anonymousId:r,sessionId:i,sessionStartedAt:Number(s)}}function rt(t,e){let n=ce(e.search),r=n.filter(s=>!de(s));if(r.length===n.length)return;let i=r.length>0?`?${r.join("&")}`:"";t.replaceState(t.state,"",`${e.pathname}${i}${e.hash}`);}function it(t){if(t.location===void 0||typeof t.location.search!="string")return;let e=nt(t.location.search);if(e===void 0)return;let n=Ke(t.storage,t.shared,t.namespace,e.anonymousId);return Ve(t.shared,t.namespace,{id:e.sessionId,startedAt:e.sessionStartedAt},t.now),t.history!==void 0&&rt(t.history,t.location),n}function ae(t,e,n){if(n.length===0)return ()=>{};let r=i=>{let s=sn(i.target);if(s===void 0)return;let o=nn(e);o!==void 0&&tt(s,o,n,t.location?.hostname??"");};return t.addEventListener("click",r,true),t.addEventListener("auxclick",r,true),()=>{t.removeEventListener("click",r,true),t.removeEventListener("auxclick",r,true);}}function Xt(t){try{let e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"?e:void 0}catch{return}}function Ye(t,e){let n=e.map(r=>r.replace(/^\./,"").toLowerCase());return se(t).find(r=>n.includes(r))}function ce(t){return t.replace(/^\?/,"").split("&").filter(e=>e!=="")}function de(t){let e=t.indexOf("=");return H(e===-1?t:t.slice(0,e))===Ze}function Zt(t){let e=t.indexOf("=");return e===-1?"":t.slice(e+1)}function en(t){return encodeURIComponent(t).replace(/~/g,"%7E")}function H(t){try{return decodeURIComponent(t)}catch{return}}function Xe(t){if(t===void 0)return false;let e=_(t);return e>=1&&e<=Wt}function tn(t){return t!==void 0&&Qt.test(t)&&Number.isSafeInteger(Number(t))}function nn(t){if(t.consent?.()?.identityLink===false)return;let e=t.sessionId,n=t.sessionStartedAt;if(!(e===void 0||n===void 0))return {anonymousId:t.anonymousId,sessionId:e,sessionStartedAt:n}}function rn(t){return typeof t.tagName=="string"&&t.tagName.toUpperCase()==="A"&&typeof t.href=="string"}function sn(t){let e=typeof t=="object"?t:null;for(;e;){if(rn(e))return e;e=e.parentElement??null;}}var st={maskAllInputs:true,maskAllText:false},on=new Set(["email","password","tel"]);function ot(t){return t.replace(/\S/g,"*")}function U(t,e,n){return an(e)||n.maskAllInputs?ot(t):t}function J(t,e){return e.maskAllText?ot(t):t}function an(t){return on.has((t??"").toLowerCase())}var cn=5e3,B=class{constructor(e){this.options=e;a(this,"buffer",[]);a(this,"seq",0);a(this,"maxEvents");this.maxEvents=Math.min(Math.max(1,e.maxEvents),cn);}add(e){return this.buffer.push(e),this.buffer.length>=this.maxEvents?this.flush():null}flush(){if(this.buffer.length===0)return null;let e=this.buffer;this.buffer=[];let n={distinct_id:this.options.distinctId(),events:e,masked:this.options.masked,schema_version:1,seq:this.seq,session_id:this.options.sessionId,timestamp:new Date(this.options.now()).toISOString()};return this.seq+=1,n}};var le=1,ue=3,dn=9,z=class{constructor(){a(this,"next",1);}allocate(){let e=this.next;return this.next+=1,e}},ln=new Set(["NOSCRIPT","SCRIPT"]);function G(t,e,n,r){if(t.nodeType===ue){let i=e.allocate();return r?.(t,i),{id:i,textContent:J(t.textValue??"",n),type:"text"}}if(t.nodeType===dn){let i=e.allocate();return r?.(t,i),{childNodes:at(t,e,n,r),id:i,type:"document"}}if(t.nodeType===le){let i=t.tagName??"";if(ln.has(i))return null;let s=e.allocate();return r?.(t,s),{attributes:un(t,n),childNodes:at(t,e,n,r),id:s,tagName:i,type:"element"}}return null}function at(t,e,n,r){let i=[];for(let s of t.childNodes??[]){let o=G(s,e,n,r);o&&i.push(o);}return i}function un(t,e){let n={};for(let r of t.attributes??[])n[r.name]=r.value;return t.inputValue!==void 0&&(n.value=U(t.inputValue,t.inputType,e)),n}async function ct(t,e){let n=`${p(e.replayHost)}/v1/replay`;return (await e.fetch(n,{body:JSON.stringify(t),headers:{authorization:`Bearer ${e.apiKey}`,"content-type":"application/json"},method:"POST"})).ok}var dt=new Set(["INPUT","SELECT","TEXTAREA"]),W=class{constructor(e){this.options=e;a(this,"allocator",new z);a(this,"mirror",new Map);a(this,"chunker");a(this,"fetchImpl");a(this,"observer");a(this,"timer");a(this,"started",false);this.chunker=new B({distinctId:e.distinctId,masked:e.mask.maskAllInputs,maxEvents:e.maxEvents,now:e.now,sessionId:e.sessionId}),this.fetchImpl=f(e.fetch);}start(){if(this.started)return;let e=pn(),n=e?.documentElement;!e||!n||!this.fetchImpl||(this.started=true,this.captureFullSnapshot(n),this.observeMutations(n),this.observeInteractions(e),this.timer=setInterval(()=>this.upload(this.chunker.flush()),this.options.flushIntervalMs));}stop(){this.started&&(this.started=false,this.observer?.disconnect(),this.timer&&clearInterval(this.timer),this.upload(this.chunker.flush()));}captureFullSnapshot(e){let n=G(this.adapt(e),this.allocator,this.options.mask,(r,i)=>{let s=r.ref;s&&this.mirror.set(s,i);});n&&this.push(2,{node:n});}observeMutations(e){let n=globalThis.MutationObserver;n&&(this.observer=new n(r=>{for(let i of r)this.handleMutation(i);}),this.observer.observe(e,{attributes:true,characterData:true,childList:true,subtree:true}));}handleMutation(e){if(e.type==="characterData"){let n=this.mirror.get(e.target);n!==void 0&&this.push(3,{texts:[{id:n,value:J(e.target.textContent??"",this.options.mask)}]});return}if(e.type==="attributes"&&e.attributeName){let n=this.mirror.get(e.target),r=e.target;n!==void 0&&this.push(3,{attributes:[{attributes:{[e.attributeName]:r.getAttribute(e.attributeName)??""},id:n}]});return}if(e.type==="childList"){let n=this.mirror.get(e.target);if(n===void 0)return;for(let r of Array.from(e.addedNodes)){let i=G(this.adapt(r),this.allocator,this.options.mask,(s,o)=>{let c=s.ref;c&&this.mirror.set(c,o);});i&&this.push(3,{adds:[{node:i,parentId:n}]});}for(let r of Array.from(e.removedNodes)){let i=this.mirror.get(r);i!==void 0&&(this.push(3,{removes:[{id:i,parentId:n}]}),this.mirror.delete(r));}}}observeInteractions(e){e.addEventListener("input",n=>{let r=n.target;if(!r||!dt.has(r.tagName))return;let i=this.mirror.get(r);i!==void 0&&this.push(3,{input:{id:i,value:U(r.value??"",r.type,this.options.mask)}});},true),e.addEventListener("scroll",n=>{let r=n.target,i=r?this.mirror.get(r):void 0;this.push(3,{scroll:{id:i??0,x:r?.scrollLeft??0,y:r?.scrollTop??0}});},true);}adapt(e){let n={childNodes:[],nodeType:e.nodeType,ref:e};if(e.nodeType===ue)return n.textValue=e.textContent??"",n;if(e.nodeType===le){let r=e;if(n.tagName=r.tagName,n.attributes=Array.from(r.attributes).map(i=>({name:i.name,value:i.value})),dt.has(r.tagName)){let i=r;n.inputType=i.type,n.inputValue=i.value??"";}}return n.childNodes=Array.from(e.childNodes).map(r=>this.adapt(r)),n}push(e,n){let r=this.chunker.add({data:n,timestamp:this.options.now(),type:e});r&&this.upload(r);}upload(e){!e||!this.fetchImpl||ct(e,{apiKey:this.options.apiKey,fetch:this.fetchImpl,replayHost:this.options.replayHost}).catch(n=>this.options.onError?.(n));}};function pn(){return globalThis.document}function lt(t){let e=new W({apiKey:t.apiKey,distinctId:t.distinctId,flushIntervalMs:t.flushIntervalMs??5e3,mask:{...st,...t.mask},maxEvents:t.maxEvents??200,now:t.now??(()=>Date.now()),onError:t.onError,replayHost:t.replayHost,sessionId:t.sessionId??Q()});return e.start(),e}function hn(){return globalThis.navigator}function fn(){return globalThis.document}function mn(){return globalThis.history}function gn(){return globalThis.location}function yn(t){let e=t?.userAgentData?.platform??t?.platform;return e?e.slice(0,50):void 0}function vn(t){let e=()=>{t.flush();};globalThis.document?.addEventListener?.("visibilitychange",e),globalThis.addEventListener?.("pagehide",e);}function kn(t,e,n){try{return oe({domain:e,name:`pdx_${F(t)}`})??n}catch{return n}}function vi(t){let{autocaptureOptions:e,cookieDomain:n,linkedDomains:r,replayHost:i,sessionReplay:s,sessionReplayOptions:o,...c}=t,h=hn(),pe=ve(),he=c.storage??pe,fe=c.sharedStorage??kn(c.apiKey,n,pe),me=it({history:mn(),location:gn(),namespace:F(c.apiKey),now:(c.clock??C).now().getTime(),shared:fe,storage:he}),T={...c,locale:c.locale??(h?.language?h.language.slice(0,20):void 0),os:c.os??yn(h),sessionTracking:c.sessionTracking??true,sharedStorage:fe,storage:he,transport:c.transport??new V({maxRetries:c.maxRetries,requestTimeoutMs:c.requestTimeoutMs})},g=new q(T);me!==void 0&&g.alias(me),vn(g),(t.autocapture??true)&&ze(g,{onError:T.onError,...e});let ge=fn();return ge&&r&&ae(ge,g,r),s&&i&&lt({apiKey:T.apiKey,distinctId:()=>g.distinctId,onError:T.onError,replayHost:i,...o,sessionId:o?.sessionId??g.sessionId}),g}exports.WebTransport=V;exports.createCookieStorage=oe;exports.createWebClient=vi;exports.decorateLink=tt;exports.installAutocapture=ze;exports.installLinkCarry=ae;exports.installSessionReplay=lt;exports.readCarry=nt;exports.resolveCookieDomain=Qe;exports.stripCarry=rt;//# sourceMappingURL=web.cjs.map
1
+ 'use strict';var Ct=Object.defineProperty;var At=(t,e,n)=>e in t?Ct(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var a=(t,e,n)=>At(t,typeof e!="symbol"?e+"":e,n);var m=class extends Error{constructor(n,r,i){super(r,i);a(this,"code");this.code=n,this.name="ProdantixError";}},C=class extends m{constructor(e){super("config",e),this.name="ConfigError";}},S=class extends m{constructor(n,r){super("validation",r);a(this,"field");this.field=n,this.name="ValidationError";}},d=class extends m{constructor(n,r,i){super("transport",n,i);a(this,"status");this.status=r,this.name="TransportError";}};function y(t){if(t)return t;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function v(){let t=globalThis.AbortController;return t?new t:void 0}var Ae=t=>new Promise(e=>{setTimeout(e,t);});function g(t){return t.replace(/\/+$/,"")}var T=class{constructor(){a(this,"store",new Map);}getItem(e){return this.store.get(e)??null}removeItem(e){this.store.delete(e);}setItem(e,n){this.store.set(e,n);}};function _e(){try{let t=globalThis.localStorage;if(t){let e="__pdx_probe__";return t.setItem(e,"1"),t.removeItem(e),t}}catch{return new T}return new T}var F={now:()=>new Date};function P(t){return t.toISOString()}function _t(){return globalThis.crypto}function Nt(t){t[6]=t[6]&15|64,t[8]=t[8]&63|128;let e=[];for(let n=0;n<16;n+=1)e.push(t[n].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function oe(){let t=_t();if(t?.randomUUID)return t.randomUUID();let e=new Uint8Array(16);if(t?.getRandomValues)t.getRandomValues(e);else for(let n=0;n<16;n+=1)e[n]=Math.floor(Math.random()*256);return Nt(e)}var Ne={uuid:oe};var Lt=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var Ot=/^(?:\$|[a-z])[a-z0-9_.]*$/;function R(t){let e=0;for(let n of t)e+=1;return e}function Le(t){return Lt.test(t)}function Ft(t){return Ot.test(t)}function Oe(t){let e=R(t);if(e<1||e>200)throw new S("distinct_id","distinct_id must be between 1 and 200 characters")}function Fe(t){let e=R(t);if(e<1||e>200)throw new S("event_name","event_name must be between 1 and 200 characters");if(!Ft(t))throw new S("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var Pe="prodantix-js",Re="0.7.0";var Pt=t=>{};function $e(t){if(!t.apiKey||!Le(t.apiKey))throw new C("apiKey must be a public project key of the form pdx_pub_<32 lowercase alphanumerics>");if(!t.host)throw new C("host is required (the ingest base URL)");let e=g(t.host),n=t.defaultProperties,r=t.storage??new T;return {apiKey:t.apiKey,autocapture:t.autocapture??false,clock:t.clock??F,consent:t.consent,defaultProperties:typeof n=="function"?n:()=>n??{},describeElement:t.describeElement,flagsHost:t.flagsHost?g(t.flagsHost):e,flushAt:t.flushAt??20,flushIntervalMs:t.flushIntervalMs??1e4,host:e,ids:t.ids??Ne,locale:t.locale,maxQueueSize:t.maxQueueSize??1e3,maxRetries:t.maxRetries??3,namespace:$(t.apiKey),onError:t.onError??Pt,os:t.os,requestTimeoutMs:t.requestTimeoutMs??1e4,sdkName:t.sdkName??Pe,sdkVersion:t.sdkVersion??Re,sessionTracking:t.sessionTracking??false,sharedStorage:t.sharedStorage??r,socketFactory:t.socketFactory,storage:r,streamFlags:t.streamFlags??false,transport:t.transport}}function $(t){return t.slice(0,16)}function Me(t,e,n){Fe(t.eventName),Oe(t.distinctId);let r={distinct_id:t.distinctId,event_id:t.eventId??n.uuid(),event_name:t.eventName,properties:t.properties??{},schema_version:1,timestamp:P(t.timestamp??e.now())};return t.context&&(r.context=t.context),t.sessionId&&(r.session_id=t.sessionId),r}var x=Symbol("absent");function Rt(t,e){if(t==="distinct_id")return e.distinctId;let n=e.properties??{};if(Object.prototype.hasOwnProperty.call(n,t))return n[t];let r=e.attributes??{};return Object.prototype.hasOwnProperty.call(r,t)?r[t]:x}function E(t){return t===x?"undefined":String(t)}function De(t){return t===x?Number.NaN:Number(t)}function qe(t){return t!==x&&t!==null&&t!==""}function Ke(t,e){if(!Array.isArray(e))return false;let n=E(t);return e.map(r=>String(r)).includes(n)}function Ve(t,e){let n=Rt(t.attribute,e),r=t.value;switch(t.op){case "is_set":return qe(n);case "is_not_set":return !qe(n);case "eq":return E(n)===E(r===void 0?x:r);case "neq":return E(n)!==E(r===void 0?x:r);case "contains":return E(n).includes(E(r===void 0?x:r));case "in":return Ke(n,r);case "not_in":return Array.isArray(r)?!Ke(n,r):false;case "gt":return M(n,r,(i,s)=>i>s);case "gte":return M(n,r,(i,s)=>i>=s);case "lt":return M(n,r,(i,s)=>i<s);case "lte":return M(n,r,(i,s)=>i<=s);case "in_cohort":return typeof r=="string"&&r!==""&&(e.cohorts??[]).includes(r);case "not_in_cohort":return typeof r=="string"&&r!==""&&!(e.cohorts??[]).includes(r);default:return false}}function M(t,e,n){let r=De(t),i=e===void 0?Number.NaN:De(e);return Number.isNaN(r)||Number.isNaN(i)?false:n(r,i)}function je(t,e){let n=`${t}:${e}`,r=2166136261;for(let i=0;i<n.length;i++)r^=n.charCodeAt(i),r=Math.imul(r,16777619);return (r>>>0)%100}function ae(t,e){return t.targeting.length===0||t.targeting.every(n=>Ve(n,e))}function He(t,e){let n=je(t.key,e.distinctId),r=t.variations??[];if(r.length===0)return t.rolloutPercentage>=100||n<t.rolloutPercentage?"true":"false";let i=0;for(let s=r.length-1;s>=0;s--)if(i+=r[s].weight,n<i)return r[s].key;return r[0].key}function ce(t,e,n,r){for(let i of t.prerequisites??[]){if(r.includes(i.flagKey))return false;let s=e.find(c=>c.key===i.flagKey);if(!s||!s.enabled)return false;r.push(s.key);let o=ce(s,e,n,r)&&ae(s,n)&&He(s,n)===i.variationKey;if(r.pop(),!o)return false}return true}function D(t,e,n){return t.enabled?ce(t,e,n,[t.key])?ae(t,n)?t.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:je(t.key,n.distinctId)<t.rolloutPercentage?{enabled:true,reason:"rollout"}:{enabled:false,reason:"rollout_excluded"}:{enabled:false,reason:"targeting"}:{enabled:false,reason:"prerequisite"}:{enabled:false,reason:"disabled"}}function Ue(t,e){let n={};for(let r of t)n[r.key]=D(r,t,e).enabled;return n}function le(t,e,n){let r=t.variations??[],i=r[0];if(!i)return null;if(!t.enabled||!ce(t,e,n,[t.key])||!ae(t,n))return i;let s=He(t,n);return r.find(o=>o.key===s)??i}function Be(t){return t.some(e=>e.targeting.some(n=>n.op==="in_cohort"||n.op==="not_in_cohort"))}function Ge(t){return `40${JSON.stringify(t)}`}function Je(){return "3"}function ze(t){let e=t.charAt(0),n=t.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let o=ue(n);return {kind:"open",pingInterval:typeof o?.pingInterval=="number"?o.pingInterval:25e3,pingTimeout:typeof o?.pingTimeout=="number"?o.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=n.charAt(0),i=n.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=ue(i);return {kind:"connectError",message:typeof o?.message=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let s=ue(i);return !Array.isArray(s)||typeof s[0]!="string"?{kind:"other"}:{kind:"event",name:s[0],payload:s[1]}}function ue(t){try{return JSON.parse(t)}catch{return null}}var $t="/socket.io/?EIO=4&transport=websocket",Mt=250,q=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"pending",null);a(this,"lastKey","");a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??Dt,this.setTimer=e.setTimer??((n,r)=>setTimeout(n,r)),this.clearTimer=e.clearTimer??(n=>clearTimeout(n));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${$t}`,n;try{n=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=n,n.onmessage=r=>this.receive(String(r.data)),n.onerror=()=>n.close(),n.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat(),this.pending!==null&&this.clearTimer(this.pending),this.pending=null;let e=this.socket;this.socket=null,e?.close();}receive(e){let n=ze(e);if(n.kind==="open"){this.armHeartbeat(n.pingInterval+n.pingTimeout),this.socket?.send(Ge({projectKey:this.options.projectKey}));return}if(n.kind==="ping"){this.armHeartbeat(),this.socket?.send(Je());return}if(n.kind==="connectError"||n.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(n.kind==="event"){if(n.name==="ready"){this.ready=true;return}if(n.name==="flagChange"){let r=n.payload?.key;this.lastKey=typeof r=="string"?r:"",this.pending===null&&(this.pending=this.setTimer(()=>{this.pending=null,this.options.onChange(this.lastKey);},Mt));}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Dt(t){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(t)}var K=class{constructor(e){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=y(e.fetch),this.host=g(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async fetchAll(e){return (await this.fetchDecisions(e)).flags}async fetchDecisions(e){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let r=`${this.host}/v1/flags?distinct_id=${encodeURIComponent(e)}`,i=v(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let o=await n(r,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!o.ok)throw new d(`flags request failed with status ${o.status}`,o.status);let c=JSON.parse(await o.text());return {flags:c.flags??{},variants:c.variants??{}}}finally{s!==void 0&&clearTimeout(s);}}async snapshot(){let e=this.fetch;if(!e)throw new d("no fetch implementation available in this runtime");let n=`${this.host}/v1/flags/snapshot`,r=v(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{let s=await e(n,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:r?.signal});if(!s.ok)throw new d(`flag snapshot request failed with status ${s.status}`,s.status);let o=JSON.parse(await s.text()),c={flags:o.flags??[],generatedAt:o.generatedAt};return typeof o.socketUrl=="string"&&o.socketUrl!==""&&(c.socketUrl=o.socketUrl),c}finally{i!==void 0&&clearTimeout(i);}}async memberships(e){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let r=`${this.host}/v1/flags/memberships?distinct_id=${encodeURIComponent(e)}`,i=v(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let o=await n(r,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!o.ok)throw new d(`memberships request failed with status ${o.status}`,o.status);return JSON.parse(await o.text()).cohorts??[]}finally{s!==void 0&&clearTimeout(s);}}};function A(t){if(typeof t!="string")return;let e=Array.from(t).length;return e>=1&&e<=200?t:void 0}function j(t,e){return `pdx.${t}.${e}`}var We="consent";function qt(t){if(typeof t!="string")return null;try{let e=JSON.parse(t);if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=e.identityLink;return typeof n=="boolean"?{identityLink:n}:null}catch{return null}}function Kt(t,e){return qt(t.getItem(j(e,We)))}function Vt(t,e,n){let r=j(e,We);if(typeof n.identityLink!="boolean"){t.removeItem(r);return}t.setItem(r,JSON.stringify({identityLink:n.identityLink}));}function Qe(t,e,n,r){let i=j(n,"anonymous_id"),s=A(e.getItem(i))??A(t.getItem(i));return e.setItem(i,r),t.setItem(i,r),s!==void 0&&s!==r?s:void 0}var V=class{constructor(e,n,r,i){this.storage=e;this.shared=n;this.ids=r;this.namespace=i;a(this,"anonymousId");a(this,"distinctId");a(this,"identified");this.refresh();}refresh(){let e=A(this.shared.getItem(this.key("anonymous_id"))),n=A(this.storage.getItem(this.key("anonymous_id")));e?(this.anonymousId=e,n!==e&&this.storage.setItem(this.key("anonymous_id"),e)):n?(this.anonymousId=n,this.shared.setItem(this.key("anonymous_id"),n)):(this.anonymousId=this.ids.uuid(),this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId));let r=A(this.storage.getItem(this.key("distinct_id")));r?(this.distinctId=r,this.identified=true):(this.distinctId=this.anonymousId,this.identified=false);}getAnonymousId(){return this.anonymousId}getDistinctId(){return this.distinctId}isIdentified(){return this.identified}snapshot(){return {anonymousId:this.anonymousId,distinctId:this.distinctId,identified:this.identified}}consent(){return Kt(this.shared,this.namespace)}setConsent(e){Vt(this.shared,this.namespace,e);}identify(e){let n=!this.identified||this.distinctId!==e,r=this.storage.getItem(this.key("linked_anonymous_id")),i=n||r!==this.anonymousId;return this.distinctId=e,this.identified=true,n&&this.storage.setItem(this.key("distinct_id"),e),!i||this.consent()?.identityLink===false?{changed:n}:(this.storage.setItem(this.key("linked_anonymous_id"),this.anonymousId),{anonymousToLink:this.anonymousId,changed:n})}reset(){this.anonymousId=this.ids.uuid(),this.distinctId=this.anonymousId,this.identified=false,this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.removeItem(this.key("distinct_id")),this.storage.removeItem(this.key("linked_anonymous_id"));}key(e){return j(this.namespace,e)}};var H=class{constructor(e){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=y(e.fetch),this.host=g(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async inbox(e){let n=this.requireFetch(),r=`${this.host}/v1/messages?distinct_id=${encodeURIComponent(e)}`,i=await this.request(n,r,{headers:this.authHeaders(),method:"GET"});if(!i.ok)throw new d(`inbox request failed with status ${i.status}`,i.status);return JSON.parse(await i.text()).messages??[]}async markRead(e,n){let r=this.requireFetch(),i=`${this.host}/v1/messages/read`,s=await this.request(r,i,{body:JSON.stringify({distinct_id:n,message_id:e}),headers:{...this.authHeaders(),"content-type":"application/json"},method:"POST"});if(!s.ok)throw new d(`mark-read request failed with status ${s.status}`,s.status)}requireFetch(){if(!this.fetch)throw new d("no fetch implementation available in this runtime");return this.fetch}authHeaders(){return {authorization:`Bearer ${this.projectKey}`}}async request(e,n,r){let i=v(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(n,{...r,signal:i?.signal})}finally{s!==void 0&&clearTimeout(s);}}};var U=class{constructor(e,n){this.maxSize=e;this.onOverflow=n;a(this,"events",[]);}get size(){return this.events.length}enqueue(e){this.events.push(e),this.enforceCap();}restore(e){this.events.push(...e),this.enforceCap();}requeue(e){this.events.unshift(...e),this.enforceCap();}drain(e){let n=e===void 0?this.events.length:Math.min(e,this.events.length);return this.events.splice(0,n)}snapshot(){return [...this.events]}enforceCap(){if(this.events.length<=this.maxSize)return;let e=this.events.splice(0,this.events.length-this.maxSize);this.onOverflow?.({dropped:e});}};var jt={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function Xe(t){return `pdx.${t}.session`}function Ye(t,e,n,r){let i={id:n.id,lastActivityAt:r,startedAt:n.startedAt};t.setItem(Xe(e),JSON.stringify(i));}var B=class{constructor(e,n,r,i,s=jt){this.storage=e;this.ids=n;this.clock=r;this.namespace=i;this.options=s;}current(){return this.touch().id}startedAt(){return this.touch().startedAt}reset(){this.storage.removeItem(this.key());}touch(){let e=this.clock.now().getTime(),n=this.live(this.read(),e);if(n===void 0)return this.write({id:this.ids.uuid(),lastActivityAt:e,startedAt:e});if(e-n.lastActivityAt<=this.options.throttleMs)return n;let r=this.live(this.read(),e),i=r!==void 0&&r.id!==n.id?r:n;return this.write({...i,lastActivityAt:e})}live(e,n){if(e!==void 0&&!(n-e.lastActivityAt>this.options.idleMs||n-e.startedAt>this.options.maxMs))return e}write(e){return this.storage.setItem(this.key(),JSON.stringify(e)),e}read(){let e=this.storage.getItem(this.key());if(e)try{let n=JSON.parse(e);return typeof n.id=="string"&&typeof n.startedAt=="number"&&typeof n.lastActivityAt=="number"?{id:n.id,lastActivityAt:n.lastActivityAt,startedAt:n.startedAt}:void 0}catch{return}}key(){return Xe(this.namespace)}};var p={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageview:"$pageview",set:"$set"};function Ze(t){return t>=400&&t<500&&t!==429}var I=class{constructor(e={}){a(this,"fetch");a(this,"maxRetries");a(this,"requestTimeoutMs");a(this,"baseDelayMs");a(this,"maxDelayMs");a(this,"sleep");a(this,"random");this.fetch=y(e.fetch),this.maxRetries=e.maxRetries??3,this.requestTimeoutMs=e.requestTimeoutMs??1e4,this.baseDelayMs=e.baseDelayMs??500,this.maxDelayMs=e.maxDelayMs??3e4,this.sleep=e.sleep??Ae,this.random=e.random??Math.random;}async send(e){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let r=JSON.stringify(e.body),i;for(let s=0;s<=this.maxRetries;s+=1){try{let o=await this.attempt(n,e,r);if(o.ok)return;if(Ze(o.status))throw new d(`ingest rejected batch with status ${o.status}`,o.status);i=new d(`ingest transient status ${o.status}`,o.status);}catch(o){if(o instanceof d&&o.status!==void 0&&Ze(o.status))throw o;i=o;}s<this.maxRetries&&await this.sleep(this.backoff(s));}throw new d("ingest delivery failed after retries",void 0,{cause:i})}async attempt(e,n,r){let i=v(),s=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(n.url,{body:r,headers:{authorization:`Bearer ${n.projectKey}`,"content-type":"application/json"},method:"POST",signal:i?.signal})}finally{s!==void 0&&clearTimeout(s);}}backoff(e){return Math.min(this.maxDelayMs,this.baseDelayMs*2**e)+this.random()*this.baseDelayMs}};var Ht="queue",Ut=1e3,et=3e4,de=t=>{let e={};return t.avatar!==void 0&&(e.$avatar=t.avatar),t.email!==void 0&&(e.$email=t.email),t.name!==void 0&&(e.$name=t.name),t.phone!==void 0&&(e.$phone=t.phone),e},G=class{constructor(e){a(this,"config");a(this,"identity");a(this,"session");a(this,"queue");a(this,"transport");a(this,"flagsClient");a(this,"messagesClient");a(this,"context");a(this,"flushTimer");a(this,"flushing",false);a(this,"cachedFlags");a(this,"cachedSnapshot");a(this,"membershipCache");a(this,"stream");a(this,"shutDown",false);a(this,"exposures",new Set);this.config=$e(e),this.identity=new V(this.config.storage,this.config.sharedStorage,this.config.ids,this.config.namespace),this.config.consent!==void 0&&this.identity.setConsent(this.config.consent),this.session=this.config.sessionTracking?new B(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new U(this.config.maxQueueSize,({dropped:n})=>{this.config.onError(new m("queue_overflow",`event queue overflow: dropped ${n.length} oldest event(s)`));}),this.transport=this.config.transport??new I({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new K({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new H({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.context={sdk:this.config.sdkName,sdk_version:this.config.sdkVersion},this.config.os&&(this.context.os=this.config.os),this.config.locale&&(this.context.locale=this.config.locale),this.restoreQueue(),this.startTimer();}get distinctId(){return this.identity.getDistinctId()}get anonymousId(){return this.identity.getAnonymousId()}get isIdentified(){return this.identity.isIdentified()}get sessionId(){return this.session?.current()}get sessionStartedAt(){return this.session?.startedAt()}capture(e,n={}){try{this.identity.refresh();let r={...this.config.defaultProperties(),...n.element===void 0?{}:this.config.describeElement?.(n.element)??{},...n.properties??{}},i=Me({context:this.context,distinctId:n.distinctId??this.identity.getDistinctId(),eventName:e,properties:r,sessionId:n.sessionId??this.session?.current(),timestamp:n.timestamp},this.config.clock,this.config.ids);this.enqueue(i);}catch(r){this.config.onError(r);}}identify(e,n={}){this.identity.refresh();let r=this.identity.identify(e),i={};r.anonymousToLink!==void 0&&(i.$anon_distinct_id=r.anonymousToLink);let s={...de(n.traits??{}),...n.set??{}};Object.keys(s).length>0&&(i.$set=s),this.capture(p.identify,{properties:i});}link(e,n,r){let i={$anon_distinct_id:n},s=de(r??{});Object.keys(s).length>0&&(i.$set=s),this.capture(p.identify,{distinctId:e,properties:i});}setConsent(e){this.identity.setConsent(e);}consent(){return this.identity.consent()}alias(e){this.capture(p.createAlias,{properties:{alias:e}});}group(e,n,r){let i={$group_key:n,$group_type:e};r&&(i.$set=r),this.capture(p.group,{properties:i});}setPersonProperties(e,n){let r={};e&&(r.$set=e),n&&(r.$set_once=n),this.capture(p.set,{properties:r});}setPersonTraits(e){let n=de(e);Object.keys(n).length!==0&&this.capture(p.set,{properties:{$set:n}});}async getAllFlags(){let e=this.identity.getDistinctId(),n=await this.flagsClient.fetchDecisions(e);return this.cachedFlags={distinctId:e,flags:n.flags,variants:n.variants??{}},n.flags}async isFeatureEnabled(e){let r=(await this.getAllFlags())[e]??false;return this.recordExposure(e,this.cachedFlags?.variants[e]?.key??String(r)),r}async getVariant(e){let n=await this.getAllFlags(),r=this.cachedFlags?.variants[e]??null;return this.recordExposure(e,r?.key??String(n[e]??false)),r}async getVariantLocal(e,n={}){let r=await this.flagSnapshot(),i=r.flags.find(f=>f.key===e),s=await this.localContext(n,r.flags),o=i?le(i,r.flags,s):null,c=i?D(i,r.flags,s).enabled:false;return this.recordExposure(e,o?.key??String(c)),o?{key:o.key,value:o.value}:null}recordExposure(e,n){let r=`${this.identity.getDistinctId()} ${e} ${n}`;this.exposures.has(r)||(this.exposures.add(r),this.capture(p.featureFlagCalled,{properties:{$feature_flag:e,$feature_flag_response:n}}));}getCachedFlag(e){if(!(!this.cachedFlags||this.cachedFlags.distinctId!==this.distinctId))return this.cachedFlags.flags[e]}async getLocalFlags(e={}){let n=await this.flagSnapshot();return Ue(n.flags,await this.localContext(e,n.flags))}async isFeatureEnabledLocal(e,n={}){let r=await this.flagSnapshot(),i=r.flags.find(c=>c.key===e),s=await this.localContext(n,r.flags),o=i?D(i,r.flags,s).enabled:false;return this.recordExposure(e,(i?le(i,r.flags,s)?.key:void 0)??String(o)),o}async localContext(e,n){let r=this.identity.getDistinctId(),i=e.cohorts;if(i===void 0&&Be(n)){let s=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===r&&s-this.membershipCache.fetchedAt<et?i=this.membershipCache.cohorts:(i=await this.flagsClient.memberships(r),this.membershipCache={cohorts:i,distinctId:r,fetchedAt:s});}return {attributes:e.attributes,cohorts:i,distinctId:r,properties:e.properties}}async flagSnapshot(){let e=this.config.clock.now().getTime();if(this.cachedSnapshot&&e-this.cachedSnapshot.fetchedAt<et)return this.cachedSnapshot.snapshot;let n=await this.flagsClient.snapshot();return this.cachedSnapshot={fetchedAt:e,snapshot:n},this.maybeStream(n),n}maybeStream(e){if(!this.config.streamFlags||this.shutDown||this.stream||!e.socketUrl)return;let n=new q({host:e.socketUrl,onChange:()=>{this.cachedSnapshot=void 0,this.flagSnapshot().catch(r=>this.config.onError(r));},onClosed:r=>{this.stream=void 0,r&&this.maybeStream(e);},projectKey:this.config.apiKey,socketFactory:this.config.socketFactory});this.stream=n,n.open();}async getInbox(){return this.messagesClient.inbox(this.identity.getDistinctId())}async markMessageRead(e){await this.messagesClient.markRead(e,this.identity.getDistinctId());}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(Ut);try{await this.transport.send({body:{events:e,sent_at:P(this.config.clock.now())},projectKey:this.config.apiKey,url:`${this.config.host}/v1/events`}),this.persistQueue();}catch(n){this.queue.requeue(e),this.persistQueue(),this.config.onError(n);}finally{this.flushing=false;}}reset(){this.session?.reset(),this.identity.reset(),this.cachedFlags=void 0,this.cachedSnapshot=void 0,this.membershipCache=void 0;}async shutdown(){this.shutDown=true,this.stopTimer(),this.stream?.close(),this.stream=void 0,await this.flush();}enqueue(e){this.queue.enqueue(e),this.persistQueue(),this.queue.size>=this.config.flushAt&&this.flush();}persistQueue(){try{this.config.storage.setItem(this.persistKey(),JSON.stringify(this.queue.snapshot()));}catch(e){this.config.onError(e);}}restoreQueue(){try{let e=this.config.storage.getItem(this.persistKey());if(!e)return;let n=JSON.parse(e);Array.isArray(n)&&this.queue.restore(n);}catch(e){this.config.onError(e);}}startTimer(){if(this.config.flushIntervalMs<=0)return;let e=setInterval(()=>{this.flush();},this.config.flushIntervalMs),n=e;typeof n.unref=="function"&&n.unref(),this.flushTimer=e;}stopTimer(){this.flushTimer!==void 0&&(clearInterval(this.flushTimer),this.flushTimer=void 0);}persistKey(){return `pdx.${this.config.namespace}.${Ht}`}};var nt="data-prodantix",rt="data-prodantix-action",it="data-prodantix-ignore",w=300,pe="data-pdx-no-capture",fe="pdx-no-capture",Bt=new Set(["a","button","input","label","option","select","summary","textarea"]),Gt=new Set(["button","checkbox","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","switch","tab","treeitem"]);function Jt(t){return Bt.has(t.tagName.toLowerCase())||Gt.has((t.getAttribute("role")??"").trim().toLowerCase())}function he(t){for(let e=t;e!==null;e=e.parentElement)if(Jt(e))return e;return t}function me(t){for(let e=t;e!==null;e=e.parentElement)if(e.getAttribute(it)!==null)return true;return false}function ge(t){for(let e=t;e!==null;e=e.parentElement)if(e.getAttribute(pe)!==null||typeof e.className=="string"&&e.className.split(/\s+/).includes(fe))return true;return false}function J(t){let e=new Set;return n=>{e.has(n.message)||(e.add(n.message),t(n));}}function tt(t,e,n){let r=t.getAttribute(e);if(r===null)return;let i=r.trim();if(i!==""){if(i.length>w){n(new m("validation",`${e} on a <${t.tagName.toLowerCase()}> is ${i.length} characters, over the ${w}-character limit, so it was ignored: "${i.slice(0,40)}\u2026"`));return}return i}}function ye(t,e){let n={},r=tt(t,nt,e);r!==void 0&&(n.$el_description=r,n.$el_description_source="annotation");let i=tt(t,rt,e);return i!==void 0&&(n.$el_action=i),n}function st(t,e){return !zt(t)||me(t)||ge(t)?{}:ye(he(t),e)}function zt(t){return typeof t=="object"&&t!==null&&typeof t.tagName=="string"&&typeof t.getAttribute=="function"}var Wt=new Set(["input","select","textarea"]),Qt=new Set(["email","password","tel"]);function W(){return globalThis.location}function ot(){return globalThis.document}function Xt(){return globalThis.window??globalThis}function Yt(t){return typeof t=="object"&&t!==null&&typeof t.tagName=="string"}function z(t,e){let n;try{n=new URL(t,e);}catch{return}return n.protocol==="http:"||n.protocol==="https:"?`${n.origin}${n.pathname}`:n.protocol}function at(){let t=W(),e=ot(),n={};if(t){let r=z(t.href);r&&(n.$current_url=r),n.$pathname=t.pathname,n.$host=t.host;}if(e){e.title&&(n.$title=e.title);let r=e.referrer?z(e.referrer):void 0;r&&(n.$referrer=r);}return n}function Zt(t){return typeof t.className=="string"?t.className:""}function en(t){return Wt.has(t.tagName.toLowerCase())||Qt.has((t.getAttribute("type")??"").toLowerCase())}function tn(t,e,n){let r={$el_tag:t.tagName.toLowerCase(),$event_type:"click"};if(e)return r;let i=n?t.textContent?.trim():void 0;i&&(r.$el_text=i.slice(0,255)),t.id&&(r.$el_id=t.id);let s=Zt(t);s&&(r.$el_classes=s);let o=t.getAttribute("href"),c=o?z(o,W()?.href):void 0;return c&&(r.$el_href=c),r}function ve(t){return (t??"").replace(/\s+/g," ").trim()}function _(t,e){return {$el_description:t,$el_description_source:e}}function nn(t,e,n){if(!e&&n){let o=ve(t.getAttribute("aria-label"));if(o!==""&&o.length<=w)return _(o,"aria_label");let c=ve(t.textContent);if(c!==""&&c.length<=w)return _(c,"text")}let r=e?null:t.getAttribute("href"),i=r?z(r,W()?.href):void 0;if(i)return _(i,"href");let s=ve(t.getAttribute("role")).toLowerCase();return s===""?_(t.tagName.toLowerCase(),"tag"):_(s,"role")}function rn(t,e){let n=new Set,r=(l,u)=>{if(n.has(l))return false;try{return u()}catch(h){return n.add(l),e(new m("config",`autocapture maskSelectors entry "${l}" is not a valid selector`,{cause:h})),false}},i=(l,u)=>l.matches?r(u,()=>l.matches?.(u)===!0):false,s=l=>{let u=l.querySelector?.bind(l);return u?u(`[${pe}], .${fe}`)!==null||t.some(h=>r(h,()=>u(h)!==null)):false},o=l=>{for(let u=l;u;u=u.parentElement){let h=u;if(t.some(k=>i(h,k)))return true}return false},c=l=>{for(let u=l;u;u=u.parentElement)if(en(u))return true;return false},f=l=>ge(l)||o(l);return {holdsMasked:s,isMasked:l=>f(l)||c(l),isOptedOut:f}}function sn(t){let e=globalThis.history,n=Xt(),r="",i=()=>{let c=W(),f=c?`${c.pathname}${c.search}`:"";f!==r&&(r=f,t.capture(p.pageview,{properties:at()}));};if(i(),!e||!n)return ()=>{};let s=e.pushState.bind(e),o=e.replaceState.bind(e);return e.pushState=(...c)=>{s(...c),i();},e.replaceState=(...c)=>{o(...c),i();},n.addEventListener("popstate",i),()=>{e.pushState=s,e.replaceState=o,n.removeEventListener("popstate",i);}}function on(t,e){let n=ot();if(!n)return ()=>{};let r=e.onError??(()=>{}),i=rn(e.maskSelectors??[],r),s=J(r),o=e.captureElementText??false,c=f=>{let l=f.target;if(!Yt(l)||me(l))return;let u=he(l),h=i.isMasked(l)||i.holdsMasked(u),k=i.isOptedOut(l)?{}:ye(u,s),se=k.$el_description===void 0?nn(u,h,o):{};t.capture(p.autocapture,{properties:{...at(),...tn(u,h,o),...se,...k}});};return n.addEventListener("click",c,true),()=>n.removeEventListener("click",c,true)}function ct(t,e={}){let n=[];return (e.pageviews??true)&&n.push(sn(t)),(e.clicks??true)&&n.push(on(t,e)),()=>{for(let r of n)r();}}function an(){return globalThis.document?.visibilityState==="hidden"}function cn(t){let e=globalThis.navigator,n=globalThis.Blob;if(!e?.sendBeacon||!n)return false;let r=JSON.stringify({...t.body,api_key:t.projectKey});try{let i=new n([r],{type:"application/json"});return e.sendBeacon(t.url,i)}catch{return false}}var Q=class{constructor(e={}){a(this,"fetchTransport");this.fetchTransport=new I(e);}async send(e){an()&&cn(e)||await this.fetchTransport.send(e);}};var ln=/^\d{1,3}(\.\d{1,3}){3}$/,un=/^[a-z0-9.-]+$/i;function lt(){return Math.random().toString(36).slice(2,12)}function X(t,e){let n=`${e}=`,r=[];for(let i of t.cookie.split(";")){let s=i.trim();s.startsWith(n)&&r.push(s.slice(n.length));}return r}function N(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function ut(t,e,n,r){try{let i=`pdx_probe_${r()}`,s=r();t.cookie=`${i}=${s}; ${N(e,60,n)}`;let o=X(t,i).includes(s);t.cookie=`${i}=; ${N(e,0,n)}`;let c=X(t,i).includes(s);return o&&!c}catch{return false}}function be(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||ln.test(e)||!e.includes("."))return [];let n=e.split("."),r=[];for(let i=n.length-2;i>=0;i-=1)r.push(n.slice(i).join("."));return r}function dt(t,e,n,r=lt){for(let i of be(t))if(ut(e,i,n,r))return i}function dn(t){let e=new Map,n=JSON.parse(decodeURIComponent(t));if(n===null||typeof n!="object"||Array.isArray(n))return e;for(let[r,i]of Object.entries(n))typeof i=="string"&&e.set(r,i);return e}var ke=class{constructor(e,n,r,i){this.jar=e;this.name=n;this.domain=r;this.secure=i;}getItem(e){return this.read().get(e)??null}setItem(e,n){let r=this.read();r.set(e,n),this.write(r);}removeItem(e){let n=this.read();n.delete(e)&&this.write(n);}read(){try{let e=X(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${N(void 0,0,this.secure)}`,e=X(this.jar,this.name));let n=e[0];return n?dn(n):new Map}catch{return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${N(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${N(this.domain,31536e3,this.secure)}`;}catch{return}}};function pn(){return globalThis.document}function fn(){return globalThis.location?.hostname??""}function hn(){return globalThis.location?.protocol==="https:"}function mn(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return un.test(e)?e.toLowerCase():void 0}function Ee(t){let e="jar"in t?t.jar:pn();if(!e||globalThis.navigator?.cookieEnabled===false)return null;let r=t.random??lt,i=t.secure??hn(),s=t.hostname??fn();try{let o=mn(t.domain)??dt(s,e,i,r);return ut(e,o,i,r)?new ke(e,t.name,o,i):null}catch{return null}}var ht="_pdx",mt="~",gn=200,yn=/^\d+$/;function gt(t,e,n,r){let i=kn(t.href);if(i===void 0||Se(i.search).some(Te))return;let s=pt(i.hostname,n);s===void 0||s===pt(r,n)||(i.search=`${i.search}${i.search?"&":"?"}${ht}=${vn(e)}`,t.href=i.href);}function vn(t){return [t.anonymousId,t.sessionId,String(t.sessionStartedAt)].map(En).join(mt)}function yt(t){let e=Se(t).find(Te);if(e===void 0)return;let n=bn(e).split(mt);if(n.length!==3)return;let r=Y(n[0]),i=Y(n[1]),s=Y(n[2]);if(!(!ft(r)||!ft(i)||!xn(s)))return {anonymousId:r,sessionId:i,sessionStartedAt:Number(s)}}function vt(t,e){let n=Se(e.search),r=n.filter(s=>!Te(s));if(r.length===n.length)return;let i=r.length>0?`?${r.join("&")}`:"";t.replaceState(t.state,"",`${e.pathname}${i}${e.hash}`);}function kt(t){if(t.location===void 0||typeof t.location.search!="string")return;let e=yt(t.location.search);if(e===void 0)return;let n=Qe(t.storage,t.shared,t.namespace,e.anonymousId);return Ye(t.shared,t.namespace,{id:e.sessionId,startedAt:e.sessionStartedAt},t.now),t.history!==void 0&&vt(t.history,t.location),n}function xe(t,e,n){if(n.length===0)return ()=>{};let r=i=>{let s=In(i.target);if(s===void 0)return;let o=Sn(e);o!==void 0&&gt(s,o,n,t.location?.hostname??"");};return t.addEventListener("click",r,true),t.addEventListener("auxclick",r,true),()=>{t.removeEventListener("click",r,true),t.removeEventListener("auxclick",r,true);}}function kn(t){try{let e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"?e:void 0}catch{return}}function pt(t,e){let n=e.map(r=>r.replace(/^\./,"").toLowerCase());return be(t).find(r=>n.includes(r))}function Se(t){return t.replace(/^\?/,"").split("&").filter(e=>e!=="")}function Te(t){let e=t.indexOf("=");return Y(e===-1?t:t.slice(0,e))===ht}function bn(t){let e=t.indexOf("=");return e===-1?"":t.slice(e+1)}function En(t){return encodeURIComponent(t).replace(/~/g,"%7E")}function Y(t){try{return decodeURIComponent(t)}catch{return}}function ft(t){if(t===void 0)return false;let e=R(t);return e>=1&&e<=gn}function xn(t){return t!==void 0&&yn.test(t)&&Number.isSafeInteger(Number(t))}function Sn(t){if(t.consent?.()?.identityLink===false)return;let e=t.sessionId,n=t.sessionStartedAt;if(!(e===void 0||n===void 0))return {anonymousId:t.anonymousId,sessionId:e,sessionStartedAt:n}}function Tn(t){return typeof t.tagName=="string"&&t.tagName.toUpperCase()==="A"&&typeof t.href=="string"}function In(t){let e=typeof t=="object"?t:null;for(;e;){if(Tn(e))return e;e=e.parentElement??null;}}var bt={maskAllInputs:true,maskAllText:false},wn=new Set(["email","password","tel"]);function Et(t){return t.replace(/\S/g,"*")}function Z(t,e,n){return Cn(e)||n.maskAllInputs?Et(t):t}function ee(t,e){return e.maskAllText?Et(t):t}function Cn(t){return wn.has((t??"").toLowerCase())}var An=5e3,te=class{constructor(e){this.options=e;a(this,"buffer",[]);a(this,"seq",0);a(this,"maxEvents");this.maxEvents=Math.min(Math.max(1,e.maxEvents),An);}add(e){return this.buffer.push(e),this.buffer.length>=this.maxEvents?this.flush():null}flush(){if(this.buffer.length===0)return null;let e=this.buffer;this.buffer=[];let n={distinct_id:this.options.distinctId(),events:e,masked:this.options.masked,schema_version:1,seq:this.seq,session_id:this.options.sessionId,timestamp:new Date(this.options.now()).toISOString()};return this.seq+=1,n}};var Ie=1,we=3,_n=9,ne=class{constructor(){a(this,"next",1);}allocate(){let e=this.next;return this.next+=1,e}},Nn=new Set(["NOSCRIPT","SCRIPT"]);function re(t,e,n,r){if(t.nodeType===we){let i=e.allocate();return r?.(t,i),{id:i,textContent:ee(t.textValue??"",n),type:"text"}}if(t.nodeType===_n){let i=e.allocate();return r?.(t,i),{childNodes:xt(t,e,n,r),id:i,type:"document"}}if(t.nodeType===Ie){let i=t.tagName??"";if(Nn.has(i))return null;let s=e.allocate();return r?.(t,s),{attributes:Ln(t,n),childNodes:xt(t,e,n,r),id:s,tagName:i,type:"element"}}return null}function xt(t,e,n,r){let i=[];for(let s of t.childNodes??[]){let o=re(s,e,n,r);o&&i.push(o);}return i}function Ln(t,e){let n={};for(let r of t.attributes??[])n[r.name]=r.value;return t.inputValue!==void 0&&(n.value=Z(t.inputValue,t.inputType,e)),n}async function St(t,e){let n=`${g(e.replayHost)}/v1/replay`;return (await e.fetch(n,{body:JSON.stringify(t),headers:{authorization:`Bearer ${e.apiKey}`,"content-type":"application/json"},method:"POST"})).ok}var Tt=new Set(["INPUT","SELECT","TEXTAREA"]),ie=class{constructor(e){this.options=e;a(this,"allocator",new ne);a(this,"mirror",new Map);a(this,"chunker");a(this,"fetchImpl");a(this,"observer");a(this,"timer");a(this,"started",false);this.chunker=new te({distinctId:e.distinctId,masked:e.mask.maskAllInputs,maxEvents:e.maxEvents,now:e.now,sessionId:e.sessionId}),this.fetchImpl=y(e.fetch);}start(){if(this.started)return;let e=On(),n=e?.documentElement;!e||!n||!this.fetchImpl||(this.started=true,this.captureFullSnapshot(n),this.observeMutations(n),this.observeInteractions(e),this.timer=setInterval(()=>this.upload(this.chunker.flush()),this.options.flushIntervalMs));}stop(){this.started&&(this.started=false,this.observer?.disconnect(),this.timer&&clearInterval(this.timer),this.upload(this.chunker.flush()));}captureFullSnapshot(e){let n=re(this.adapt(e),this.allocator,this.options.mask,(r,i)=>{let s=r.ref;s&&this.mirror.set(s,i);});n&&this.push(2,{node:n});}observeMutations(e){let n=globalThis.MutationObserver;n&&(this.observer=new n(r=>{for(let i of r)this.handleMutation(i);}),this.observer.observe(e,{attributes:true,characterData:true,childList:true,subtree:true}));}handleMutation(e){if(e.type==="characterData"){let n=this.mirror.get(e.target);n!==void 0&&this.push(3,{texts:[{id:n,value:ee(e.target.textContent??"",this.options.mask)}]});return}if(e.type==="attributes"&&e.attributeName){let n=this.mirror.get(e.target),r=e.target;n!==void 0&&this.push(3,{attributes:[{attributes:{[e.attributeName]:r.getAttribute(e.attributeName)??""},id:n}]});return}if(e.type==="childList"){let n=this.mirror.get(e.target);if(n===void 0)return;for(let r of Array.from(e.addedNodes)){let i=re(this.adapt(r),this.allocator,this.options.mask,(s,o)=>{let c=s.ref;c&&this.mirror.set(c,o);});i&&this.push(3,{adds:[{node:i,parentId:n}]});}for(let r of Array.from(e.removedNodes)){let i=this.mirror.get(r);i!==void 0&&(this.push(3,{removes:[{id:i,parentId:n}]}),this.mirror.delete(r));}}}observeInteractions(e){e.addEventListener("input",n=>{let r=n.target;if(!r||!Tt.has(r.tagName))return;let i=this.mirror.get(r);i!==void 0&&this.push(3,{input:{id:i,value:Z(r.value??"",r.type,this.options.mask)}});},true),e.addEventListener("scroll",n=>{let r=n.target,i=r?this.mirror.get(r):void 0;this.push(3,{scroll:{id:i??0,x:r?.scrollLeft??0,y:r?.scrollTop??0}});},true);}adapt(e){let n={childNodes:[],nodeType:e.nodeType,ref:e};if(e.nodeType===we)return n.textValue=e.textContent??"",n;if(e.nodeType===Ie){let r=e;if(n.tagName=r.tagName,n.attributes=Array.from(r.attributes).map(i=>({name:i.name,value:i.value})),Tt.has(r.tagName)){let i=r;n.inputType=i.type,n.inputValue=i.value??"";}}return n.childNodes=Array.from(e.childNodes).map(r=>this.adapt(r)),n}push(e,n){let r=this.chunker.add({data:n,timestamp:this.options.now(),type:e});r&&this.upload(r);}upload(e){!e||!this.fetchImpl||St(e,{apiKey:this.options.apiKey,fetch:this.fetchImpl,replayHost:this.options.replayHost}).catch(n=>this.options.onError?.(n));}};function On(){return globalThis.document}function It(t){let e=new ie({apiKey:t.apiKey,distinctId:t.distinctId,flushIntervalMs:t.flushIntervalMs??5e3,mask:{...bt,...t.mask},maxEvents:t.maxEvents??200,now:t.now??(()=>Date.now()),onError:t.onError,replayHost:t.replayHost,sessionId:t.sessionId??oe()});return e.start(),e}function Fn(){return globalThis.navigator}function Pn(){return globalThis.document}function Rn(){return globalThis.history}function $n(){return globalThis.location}function Mn(t){let e=t?.userAgentData?.platform??t?.platform;return e?e.slice(0,50):void 0}function Dn(t){let e=()=>{t.flush();};globalThis.document?.addEventListener?.("visibilitychange",e),globalThis.addEventListener?.("pagehide",e);}function qn(t,e,n){try{return Ee({domain:e,name:`pdx_${$(t)}`})??n}catch{return n}}function ji(t){let{autocaptureOptions:e,cookieDomain:n,linkedDomains:r,replayHost:i,sessionReplay:s,sessionReplayOptions:o,...c}=t,f=Fn(),l=_e(),u=c.storage??l,h=c.sharedStorage??qn(c.apiKey,n,l),k=kt({history:Rn(),location:$n(),namespace:$(c.apiKey),now:(c.clock??F).now().getTime(),shared:h,storage:u}),se=J(c.onError??(()=>{})),O={...c,describeElement:c.describeElement??(wt=>st(wt,se)),locale:c.locale??(f?.language?f.language.slice(0,20):void 0),os:c.os??Mn(f),sessionTracking:c.sessionTracking??true,sharedStorage:h,storage:u,transport:c.transport??new Q({maxRetries:c.maxRetries,requestTimeoutMs:c.requestTimeoutMs})},b=new G(O);k!==void 0&&b.alias(k),Dn(b),(t.autocapture??true)&&ct(b,{onError:O.onError,...e});let Ce=Pn();return Ce&&r&&xe(Ce,b,r),s&&i&&It({apiKey:O.apiKey,distinctId:()=>b.distinctId,onError:O.onError,replayHost:i,...o,sessionId:o?.sessionId??b.sessionId}),b}exports.ACTION_ATTRIBUTE=rt;exports.ANNOTATION_ATTRIBUTE=nt;exports.ANNOTATION_MAX_LENGTH=w;exports.IGNORE_ATTRIBUTE=it;exports.WebTransport=Q;exports.createCookieStorage=Ee;exports.createWebClient=ji;exports.decorateLink=gt;exports.installAutocapture=ct;exports.installLinkCarry=xe;exports.installSessionReplay=It;exports.readCarry=yt;exports.resolveCookieDomain=dt;exports.stripCarry=vt;//# sourceMappingURL=web.cjs.map
2
2
  //# sourceMappingURL=web.cjs.map
package/dist/web.d.cts CHANGED
@@ -1,8 +1,13 @@
1
- import { P as ProdantixClient } from './client-BO7f6q5k.cjs';
2
- import { T as Transport, i as TransportRequest, a as StorageAdapter, b as Consent, P as ProdantixConfig } from './types-DjMXp6Wg.cjs';
3
- import { a as FetchTransportOptions } from './transport-Cy42FY5A.cjs';
1
+ import { P as ProdantixClient } from './client-CL6Xvhay.cjs';
2
+ import { T as Transport, i as TransportRequest, a as StorageAdapter, b as Consent, P as ProdantixConfig } from './types-Q2VNlJbG.cjs';
3
+ import { a as FetchTransportOptions } from './transport-DN9pXyrX.cjs';
4
4
  import { F as FetchLike } from './http-BCh716Vs.cjs';
5
5
 
6
+ declare const ANNOTATION_ATTRIBUTE = "data-prodantix";
7
+ declare const ACTION_ATTRIBUTE = "data-prodantix-action";
8
+ declare const IGNORE_ATTRIBUTE = "data-prodantix-ignore";
9
+ declare const ANNOTATION_MAX_LENGTH = 300;
10
+
6
11
  interface AutocaptureOptions {
7
12
  captureElementText?: boolean;
8
13
  clicks?: boolean;
@@ -156,4 +161,4 @@ interface WebClientOptions extends ProdantixConfig {
156
161
  }
157
162
  declare function createWebClient(options: WebClientOptions): ProdantixClient;
158
163
 
159
- export { type AutocaptureOptions, type Carry, Consent, type CookieJar, type CookieStorageOptions, type MaskOptions, type SessionReplayOptions, type WebClientOptions, type WebSessionReplayOptions, WebTransport, createCookieStorage, createWebClient, decorateLink, installAutocapture, installLinkCarry, installSessionReplay, readCarry, resolveCookieDomain, stripCarry };
164
+ export { ACTION_ATTRIBUTE, ANNOTATION_ATTRIBUTE, ANNOTATION_MAX_LENGTH, type AutocaptureOptions, type Carry, Consent, type CookieJar, type CookieStorageOptions, IGNORE_ATTRIBUTE, type MaskOptions, type SessionReplayOptions, type WebClientOptions, type WebSessionReplayOptions, WebTransport, createCookieStorage, createWebClient, decorateLink, installAutocapture, installLinkCarry, installSessionReplay, readCarry, resolveCookieDomain, stripCarry };
package/dist/web.d.ts CHANGED
@@ -1,8 +1,13 @@
1
- import { P as ProdantixClient } from './client-BQlU_3Dc.js';
2
- import { T as Transport, i as TransportRequest, a as StorageAdapter, b as Consent, P as ProdantixConfig } from './types-DjMXp6Wg.js';
3
- import { a as FetchTransportOptions } from './transport-CqAmRbpQ.js';
1
+ import { P as ProdantixClient } from './client-QyKW0LFW.js';
2
+ import { T as Transport, i as TransportRequest, a as StorageAdapter, b as Consent, P as ProdantixConfig } from './types-Q2VNlJbG.js';
3
+ import { a as FetchTransportOptions } from './transport-DKFvkfX4.js';
4
4
  import { F as FetchLike } from './http-BCh716Vs.js';
5
5
 
6
+ declare const ANNOTATION_ATTRIBUTE = "data-prodantix";
7
+ declare const ACTION_ATTRIBUTE = "data-prodantix-action";
8
+ declare const IGNORE_ATTRIBUTE = "data-prodantix-ignore";
9
+ declare const ANNOTATION_MAX_LENGTH = 300;
10
+
6
11
  interface AutocaptureOptions {
7
12
  captureElementText?: boolean;
8
13
  clicks?: boolean;
@@ -156,4 +161,4 @@ interface WebClientOptions extends ProdantixConfig {
156
161
  }
157
162
  declare function createWebClient(options: WebClientOptions): ProdantixClient;
158
163
 
159
- export { type AutocaptureOptions, type Carry, Consent, type CookieJar, type CookieStorageOptions, type MaskOptions, type SessionReplayOptions, type WebClientOptions, type WebSessionReplayOptions, WebTransport, createCookieStorage, createWebClient, decorateLink, installAutocapture, installLinkCarry, installSessionReplay, readCarry, resolveCookieDomain, stripCarry };
164
+ export { ACTION_ATTRIBUTE, ANNOTATION_ATTRIBUTE, ANNOTATION_MAX_LENGTH, type AutocaptureOptions, type Carry, Consent, type CookieJar, type CookieStorageOptions, IGNORE_ATTRIBUTE, type MaskOptions, type SessionReplayOptions, type WebClientOptions, type WebSessionReplayOptions, WebTransport, createCookieStorage, createWebClient, decorateLink, installAutocapture, installLinkCarry, installSessionReplay, readCarry, resolveCookieDomain, stripCarry };
package/dist/web.js CHANGED
@@ -1,2 +1,2 @@
1
- import {x,e,d,b as b$1,c,h as h$1,y as y$1,q,s,t}from'./chunk-4RLPQZ5L.js';import'./chunk-V77KYPOF.js';import {e as e$1,h as h$2,a as a$1}from'./chunk-ODN4ZELX.js';import {a}from'./chunk-5XGN7UAV.js';var ke="data-pdx-no-capture",ve="pdx-no-capture",be=new Set(["input","select","textarea"]),Ee=new Set(["email","password","tel"]);function T(){return globalThis.location}function G(){return globalThis.document}function Le(){return globalThis.window??globalThis}function xe(t){return typeof t=="object"&&t!==null&&typeof t.tagName=="string"}function w(t,e){let n;try{n=new URL(t,e);}catch{return}return n.protocol==="http:"||n.protocol==="https:"?`${n.origin}${n.pathname}`:n.protocol}function Q(){let t=T(),e=G(),n={};if(t){let r=w(t.href);r&&(n.$current_url=r),n.$pathname=t.pathname,n.$host=t.host;}if(e){e.title&&(n.$title=e.title);let r=e.referrer?w(e.referrer):void 0;r&&(n.$referrer=r);}return n}function Z(t){return typeof t.className=="string"?t.className:""}function Se(t){return be.has(t.tagName.toLowerCase())||Ee.has((t.getAttribute("type")??"").toLowerCase())}function we(t,e,n){let r={$el_tag:t.tagName.toLowerCase(),$event_type:"click"};if(e)return r;let i=n?t.textContent?.trim():void 0;i&&(r.$el_text=i.slice(0,255)),t.id&&(r.$el_id=t.id);let o=Z(t);o&&(r.$el_classes=o);let s=t.getAttribute("href"),a=s?w(s,T()?.href):void 0;return a&&(r.$el_href=a),r}function Te(t,e){let n=new Set,r=(o,s)=>{if(n.has(s)||!o.matches)return false;try{return o.matches(s)}catch(a){return n.add(s),e(new a$1("config",`autocapture maskSelectors entry "${s}" is not a valid selector`,{cause:a})),false}},i=o=>o.getAttribute(ke)!==null||Z(o).split(/\s+/).includes(ve)||Se(o)||t.some(s=>r(o,s));return o=>{for(let s=o;s;s=s.parentElement)if(i(s))return true;return false}}function Ce(t$1){let e=globalThis.history,n=Le(),r="",i=()=>{let a=T(),d=a?`${a.pathname}${a.search}`:"";d!==r&&(r=d,t$1.capture(t.pageview,{properties:Q()}));};if(i(),!e||!n)return ()=>{};let o=e.pushState.bind(e),s=e.replaceState.bind(e);return e.pushState=(...a)=>{o(...a),i();},e.replaceState=(...a)=>{s(...a),i();},n.addEventListener("popstate",i),()=>{e.pushState=o,e.replaceState=s,n.removeEventListener("popstate",i);}}function Ae(t$1,e){let n=G();if(!n)return ()=>{};let r=Te(e.maskSelectors??[],e.onError??(()=>{})),i=e.captureElementText??false,o=s=>{let a=s.target;xe(a)&&t$1.capture(t.autocapture,{properties:{...Q(),...we(a,r(a),i)}});};return n.addEventListener("click",o,true),()=>n.removeEventListener("click",o,true)}function ee(t,e={}){let n=[];return (e.pageviews??true)&&n.push(Ce(t)),(e.clicks??true)&&n.push(Ae(t,e)),()=>{for(let r of n)r();}}function Ne(){return globalThis.document?.visibilityState==="hidden"}function Ie(t){let e=globalThis.navigator,n=globalThis.Blob;if(!e?.sendBeacon||!n)return false;let r=JSON.stringify({...t.body,api_key:t.projectKey});try{let i=new n([r],{type:"application/json"});return e.sendBeacon(t.url,i)}catch{return false}}var m=class{constructor(e={}){a(this,"fetchTransport");this.fetchTransport=new x(e);}async send(e){Ne()&&Ie(e)||await this.fetchTransport.send(e);}};var Oe=/^\d{1,3}(\.\d{1,3}){3}$/,Re=/^[a-z0-9.-]+$/i;function te(){return Math.random().toString(36).slice(2,12)}function h(t,e){let n=`${e}=`,r=[];for(let i of t.cookie.split(";")){let o=i.trim();o.startsWith(n)&&r.push(o.slice(n.length));}return r}function l(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function ne(t,e,n,r){try{let i=`pdx_probe_${r()}`,o=r();t.cookie=`${i}=${o}; ${l(e,60,n)}`;let s=h(t,i).includes(o);t.cookie=`${i}=; ${l(e,0,n)}`;let a=h(t,i).includes(o);return s&&!a}catch{return false}}function A(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||Oe.test(e)||!e.includes("."))return [];let n=e.split("."),r=[];for(let i=n.length-2;i>=0;i-=1)r.push(n.slice(i).join("."));return r}function re(t,e,n,r=te){for(let i of A(t))if(ne(e,i,n,r))return i}function Me(t){let e=new Map,n=JSON.parse(decodeURIComponent(t));if(n===null||typeof n!="object"||Array.isArray(n))return e;for(let[r,i]of Object.entries(n))typeof i=="string"&&e.set(r,i);return e}var C=class{constructor(e,n,r,i){this.jar=e;this.name=n;this.domain=r;this.secure=i;}getItem(e){return this.read().get(e)??null}setItem(e,n){let r=this.read();r.set(e,n),this.write(r);}removeItem(e){let n=this.read();n.delete(e)&&this.write(n);}read(){try{let e=h(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${l(void 0,0,this.secure)}`,e=h(this.jar,this.name));let n=e[0];return n?Me(n):new Map}catch{return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${l(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${l(this.domain,31536e3,this.secure)}`;}catch{return}}};function Pe(){return globalThis.document}function _e(){return globalThis.location?.hostname??""}function $e(){return globalThis.location?.protocol==="https:"}function De(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Re.test(e)?e.toLowerCase():void 0}function N(t){let e="jar"in t?t.jar:Pe();if(!e||globalThis.navigator?.cookieEnabled===false)return null;let r=t.random??te,i=t.secure??$e(),o=t.hostname??_e();try{let s=De(t.domain)??re(o,e,i,r);return ne(e,s,i,r)?new C(e,t.name,s,i):null}catch{return null}}var se="_pdx",ae="~",He=200,Fe=/^\d+$/;function ue(t,e,n,r){let i=Ve(t.href);if(i===void 0||O(i.search).some(R))return;let o=ie(i.hostname,n);o===void 0||o===ie(r,n)||(i.search=`${i.search}${i.search?"&":"?"}${se}=${Ue(e)}`,t.href=i.href);}function Ue(t){return [t.anonymousId,t.sessionId,String(t.sessionStartedAt)].map(Ke).join(ae)}function ce(t){let e=O(t).find(R);if(e===void 0)return;let n=je(e).split(ae);if(n.length!==3)return;let r=g(n[0]),i=g(n[1]),o=g(n[2]);if(!(!oe(r)||!oe(i)||!Je(o)))return {anonymousId:r,sessionId:i,sessionStartedAt:Number(o)}}function de(t,e){let n=O(e.search),r=n.filter(o=>!R(o));if(r.length===n.length)return;let i=r.length>0?`?${r.join("&")}`:"";t.replaceState(t.state,"",`${e.pathname}${i}${e.hash}`);}function le(t){if(t.location===void 0||typeof t.location.search!="string")return;let e=ce(t.location.search);if(e===void 0)return;let n=q(t.storage,t.shared,t.namespace,e.anonymousId);return s(t.shared,t.namespace,{id:e.sessionId,startedAt:e.sessionStartedAt},t.now),t.history!==void 0&&de(t.history,t.location),n}function I(t,e,n){if(n.length===0)return ()=>{};let r=i=>{let o=ze(i.target);if(o===void 0)return;let s=Be(e);s!==void 0&&ue(o,s,n,t.location?.hostname??"");};return t.addEventListener("click",r,true),t.addEventListener("auxclick",r,true),()=>{t.removeEventListener("click",r,true),t.removeEventListener("auxclick",r,true);}}function Ve(t){try{let e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"?e:void 0}catch{return}}function ie(t,e){let n=e.map(r=>r.replace(/^\./,"").toLowerCase());return A(t).find(r=>n.includes(r))}function O(t){return t.replace(/^\?/,"").split("&").filter(e=>e!=="")}function R(t){let e=t.indexOf("=");return g(e===-1?t:t.slice(0,e))===se}function je(t){let e=t.indexOf("=");return e===-1?"":t.slice(e+1)}function Ke(t){return encodeURIComponent(t).replace(/~/g,"%7E")}function g(t){try{return decodeURIComponent(t)}catch{return}}function oe(t){if(t===void 0)return false;let e$1=e(t);return e$1>=1&&e$1<=He}function Je(t){return t!==void 0&&Fe.test(t)&&Number.isSafeInteger(Number(t))}function Be(t){if(t.consent?.()?.identityLink===false)return;let e=t.sessionId,n=t.sessionStartedAt;if(!(e===void 0||n===void 0))return {anonymousId:t.anonymousId,sessionId:e,sessionStartedAt:n}}function We(t){return typeof t.tagName=="string"&&t.tagName.toUpperCase()==="A"&&typeof t.href=="string"}function ze(t){let e=typeof t=="object"?t:null;for(;e;){if(We(e))return e;e=e.parentElement??null;}}var pe={maskAllInputs:true,maskAllText:false},qe=new Set(["email","password","tel"]);function fe(t){return t.replace(/\S/g,"*")}function y(t,e,n){return Xe(e)||n.maskAllInputs?fe(t):t}function k(t,e){return e.maskAllText?fe(t):t}function Xe(t){return qe.has((t??"").toLowerCase())}var Ye=5e3,v=class{constructor(e){this.options=e;a(this,"buffer",[]);a(this,"seq",0);a(this,"maxEvents");this.maxEvents=Math.min(Math.max(1,e.maxEvents),Ye);}add(e){return this.buffer.push(e),this.buffer.length>=this.maxEvents?this.flush():null}flush(){if(this.buffer.length===0)return null;let e=this.buffer;this.buffer=[];let n={distinct_id:this.options.distinctId(),events:e,masked:this.options.masked,schema_version:1,seq:this.seq,session_id:this.options.sessionId,timestamp:new Date(this.options.now()).toISOString()};return this.seq+=1,n}};var M=1,P=3,Ge=9,b=class{constructor(){a(this,"next",1);}allocate(){let e=this.next;return this.next+=1,e}},Qe=new Set(["NOSCRIPT","SCRIPT"]);function E(t,e,n,r){if(t.nodeType===P){let i=e.allocate();return r?.(t,i),{id:i,textContent:k(t.textValue??"",n),type:"text"}}if(t.nodeType===Ge){let i=e.allocate();return r?.(t,i),{childNodes:me(t,e,n,r),id:i,type:"document"}}if(t.nodeType===M){let i=t.tagName??"";if(Qe.has(i))return null;let o=e.allocate();return r?.(t,o),{attributes:Ze(t,n),childNodes:me(t,e,n,r),id:o,tagName:i,type:"element"}}return null}function me(t,e,n,r){let i=[];for(let o of t.childNodes??[]){let s=E(o,e,n,r);s&&i.push(s);}return i}function Ze(t,e){let n={};for(let r of t.attributes??[])n[r.name]=r.value;return t.inputValue!==void 0&&(n.value=y(t.inputValue,t.inputType,e)),n}async function he(t,e){let n=`${h$2(e.replayHost)}/v1/replay`;return (await e.fetch(n,{body:JSON.stringify(t),headers:{authorization:`Bearer ${e.apiKey}`,"content-type":"application/json"},method:"POST"})).ok}var ge=new Set(["INPUT","SELECT","TEXTAREA"]),L=class{constructor(e){this.options=e;a(this,"allocator",new b);a(this,"mirror",new Map);a(this,"chunker");a(this,"fetchImpl");a(this,"observer");a(this,"timer");a(this,"started",false);this.chunker=new v({distinctId:e.distinctId,masked:e.mask.maskAllInputs,maxEvents:e.maxEvents,now:e.now,sessionId:e.sessionId}),this.fetchImpl=e$1(e.fetch);}start(){if(this.started)return;let e=et(),n=e?.documentElement;!e||!n||!this.fetchImpl||(this.started=true,this.captureFullSnapshot(n),this.observeMutations(n),this.observeInteractions(e),this.timer=setInterval(()=>this.upload(this.chunker.flush()),this.options.flushIntervalMs));}stop(){this.started&&(this.started=false,this.observer?.disconnect(),this.timer&&clearInterval(this.timer),this.upload(this.chunker.flush()));}captureFullSnapshot(e){let n=E(this.adapt(e),this.allocator,this.options.mask,(r,i)=>{let o=r.ref;o&&this.mirror.set(o,i);});n&&this.push(2,{node:n});}observeMutations(e){let n=globalThis.MutationObserver;n&&(this.observer=new n(r=>{for(let i of r)this.handleMutation(i);}),this.observer.observe(e,{attributes:true,characterData:true,childList:true,subtree:true}));}handleMutation(e){if(e.type==="characterData"){let n=this.mirror.get(e.target);n!==void 0&&this.push(3,{texts:[{id:n,value:k(e.target.textContent??"",this.options.mask)}]});return}if(e.type==="attributes"&&e.attributeName){let n=this.mirror.get(e.target),r=e.target;n!==void 0&&this.push(3,{attributes:[{attributes:{[e.attributeName]:r.getAttribute(e.attributeName)??""},id:n}]});return}if(e.type==="childList"){let n=this.mirror.get(e.target);if(n===void 0)return;for(let r of Array.from(e.addedNodes)){let i=E(this.adapt(r),this.allocator,this.options.mask,(o,s)=>{let a=o.ref;a&&this.mirror.set(a,s);});i&&this.push(3,{adds:[{node:i,parentId:n}]});}for(let r of Array.from(e.removedNodes)){let i=this.mirror.get(r);i!==void 0&&(this.push(3,{removes:[{id:i,parentId:n}]}),this.mirror.delete(r));}}}observeInteractions(e){e.addEventListener("input",n=>{let r=n.target;if(!r||!ge.has(r.tagName))return;let i=this.mirror.get(r);i!==void 0&&this.push(3,{input:{id:i,value:y(r.value??"",r.type,this.options.mask)}});},true),e.addEventListener("scroll",n=>{let r=n.target,i=r?this.mirror.get(r):void 0;this.push(3,{scroll:{id:i??0,x:r?.scrollLeft??0,y:r?.scrollTop??0}});},true);}adapt(e){let n={childNodes:[],nodeType:e.nodeType,ref:e};if(e.nodeType===P)return n.textValue=e.textContent??"",n;if(e.nodeType===M){let r=e;if(n.tagName=r.tagName,n.attributes=Array.from(r.attributes).map(i=>({name:i.name,value:i.value})),ge.has(r.tagName)){let i=r;n.inputType=i.type,n.inputValue=i.value??"";}}return n.childNodes=Array.from(e.childNodes).map(r=>this.adapt(r)),n}push(e,n){let r=this.chunker.add({data:n,timestamp:this.options.now(),type:e});r&&this.upload(r);}upload(e){!e||!this.fetchImpl||he(e,{apiKey:this.options.apiKey,fetch:this.fetchImpl,replayHost:this.options.replayHost}).catch(n=>this.options.onError?.(n));}};function et(){return globalThis.document}function ye(t){let e=new L({apiKey:t.apiKey,distinctId:t.distinctId,flushIntervalMs:t.flushIntervalMs??5e3,mask:{...pe,...t.mask},maxEvents:t.maxEvents??200,now:t.now??(()=>Date.now()),onError:t.onError,replayHost:t.replayHost,sessionId:t.sessionId??d()});return e.start(),e}function tt(){return globalThis.navigator}function nt(){return globalThis.document}function rt(){return globalThis.history}function it(){return globalThis.location}function ot(t){let e=t?.userAgentData?.platform??t?.platform;return e?e.slice(0,50):void 0}function st(t){let e=()=>{t.flush();};globalThis.document?.addEventListener?.("visibilitychange",e),globalThis.addEventListener?.("pagehide",e);}function at(t,e,n){try{return N({domain:e,name:`pdx_${h$1(t)}`})??n}catch{return n}}function Yt(t){let{autocaptureOptions:e,cookieDomain:n,linkedDomains:r,replayHost:i,sessionReplay:o,sessionReplayOptions:s,...a}=t,d=tt(),_=b$1(),$=a.storage??_,D=a.sharedStorage??at(a.apiKey,n,_),H=le({history:rt(),location:it(),namespace:h$1(a.apiKey),now:(a.clock??c).now().getTime(),shared:D,storage:$}),f={...a,locale:a.locale??(d?.language?d.language.slice(0,20):void 0),os:a.os??ot(d),sessionTracking:a.sessionTracking??true,sharedStorage:D,storage:$,transport:a.transport??new m({maxRetries:a.maxRetries,requestTimeoutMs:a.requestTimeoutMs})},c$1=new y$1(f);H!==void 0&&c$1.alias(H),st(c$1),(t.autocapture??true)&&ee(c$1,{onError:f.onError,...e});let F=nt();return F&&r&&I(F,c$1,r),o&&i&&ye({apiKey:f.apiKey,distinctId:()=>c$1.distinctId,onError:f.onError,replayHost:i,...s,sessionId:s?.sessionId??c$1.sessionId}),c$1}export{m as WebTransport,N as createCookieStorage,Yt as createWebClient,ue as decorateLink,ee as installAutocapture,I as installLinkCarry,ye as installSessionReplay,ce as readCarry,re as resolveCookieDomain,de as stripCarry};//# sourceMappingURL=web.js.map
1
+ import {x as x$1,e,d,b as b$1,c,h as h$1,y,q as q$1,s,t}from'./chunk-D6PMLUYA.js';import'./chunk-V77KYPOF.js';import {e as e$1,h as h$2,a as a$1}from'./chunk-ODN4ZELX.js';import {a}from'./chunk-5XGN7UAV.js';var ce="data-prodantix",le="data-prodantix-action",de="data-prodantix-ignore",h=300,$="data-pdx-no-capture",D="pdx-no-capture",Re=new Set(["a","button","input","label","option","select","summary","textarea"]),Me=new Set(["button","checkbox","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","switch","tab","treeitem"]);function $e(t){return Re.has(t.tagName.toLowerCase())||Me.has((t.getAttribute("role")??"").trim().toLowerCase())}function H(t){for(let e=t;e!==null;e=e.parentElement)if($e(e))return e;return t}function U(t){for(let e=t;e!==null;e=e.parentElement)if(e.getAttribute(de)!==null)return true;return false}function F(t){for(let e=t;e!==null;e=e.parentElement)if(e.getAttribute($)!==null||typeof e.className=="string"&&e.className.split(/\s+/).includes(D))return true;return false}function b(t){let e=new Set;return n=>{e.has(n.message)||(e.add(n.message),t(n));}}function ue(t,e,n){let r=t.getAttribute(e);if(r===null)return;let o=r.trim();if(o!==""){if(o.length>h){n(new a$1("validation",`${e} on a <${t.tagName.toLowerCase()}> is ${o.length} characters, over the ${h}-character limit, so it was ignored: "${o.slice(0,40)}\u2026"`));return}return o}}function V(t,e){let n={},r=ue(t,ce,e);r!==void 0&&(n.$el_description=r,n.$el_description_source="annotation");let o=ue(t,le,e);return o!==void 0&&(n.$el_action=o),n}function pe(t,e){return !De(t)||U(t)||F(t)?{}:V(H(t),e)}function De(t){return typeof t=="object"&&t!==null&&typeof t.tagName=="string"&&typeof t.getAttribute=="function"}var He=new Set(["input","select","textarea"]),Ue=new Set(["email","password","tel"]);function x(){return globalThis.location}function fe(){return globalThis.document}function Fe(){return globalThis.window??globalThis}function Ve(t){return typeof t=="object"&&t!==null&&typeof t.tagName=="string"}function T(t,e){let n;try{n=new URL(t,e);}catch{return}return n.protocol==="http:"||n.protocol==="https:"?`${n.origin}${n.pathname}`:n.protocol}function me(){let t=x(),e=fe(),n={};if(t){let r=T(t.href);r&&(n.$current_url=r),n.$pathname=t.pathname,n.$host=t.host;}if(e){e.title&&(n.$title=e.title);let r=e.referrer?T(e.referrer):void 0;r&&(n.$referrer=r);}return n}function je(t){return typeof t.className=="string"?t.className:""}function Be(t){return He.has(t.tagName.toLowerCase())||Ue.has((t.getAttribute("type")??"").toLowerCase())}function Ke(t,e,n){let r={$el_tag:t.tagName.toLowerCase(),$event_type:"click"};if(e)return r;let o=n?t.textContent?.trim():void 0;o&&(r.$el_text=o.slice(0,255)),t.id&&(r.$el_id=t.id);let i=je(t);i&&(r.$el_classes=i);let a=t.getAttribute("href"),s=a?T(a,x()?.href):void 0;return s&&(r.$el_href=s),r}function j(t){return (t??"").replace(/\s+/g," ").trim()}function g(t,e){return {$el_description:t,$el_description_source:e}}function Je(t,e,n){if(!e&&n){let a=j(t.getAttribute("aria-label"));if(a!==""&&a.length<=h)return g(a,"aria_label");let s=j(t.textContent);if(s!==""&&s.length<=h)return g(s,"text")}let r=e?null:t.getAttribute("href"),o=r?T(r,x()?.href):void 0;if(o)return g(o,"href");let i=j(t.getAttribute("role")).toLowerCase();return i===""?g(t.tagName.toLowerCase(),"tag"):g(i,"role")}function We(t,e){let n=new Set,r=(u,c)=>{if(n.has(u))return false;try{return c()}catch(d){return n.add(u),e(new a$1("config",`autocapture maskSelectors entry "${u}" is not a valid selector`,{cause:d})),false}},o=(u,c)=>u.matches?r(c,()=>u.matches?.(c)===!0):false,i=u=>{let c=u.querySelector?.bind(u);return c?c(`[${$}], .${D}`)!==null||t.some(d=>r(d,()=>c(d)!==null)):false},a=u=>{for(let c=u;c;c=c.parentElement){let d=c;if(t.some(f=>o(d,f)))return true}return false},s=u=>{for(let c=u;c;c=c.parentElement)if(Be(c))return true;return false},p=u=>F(u)||a(u);return {holdsMasked:i,isMasked:u=>p(u)||s(u),isOptedOut:p}}function qe(t$1){let e=globalThis.history,n=Fe(),r="",o=()=>{let s=x(),p=s?`${s.pathname}${s.search}`:"";p!==r&&(r=p,t$1.capture(t.pageview,{properties:me()}));};if(o(),!e||!n)return ()=>{};let i=e.pushState.bind(e),a=e.replaceState.bind(e);return e.pushState=(...s)=>{i(...s),o();},e.replaceState=(...s)=>{a(...s),o();},n.addEventListener("popstate",o),()=>{e.pushState=i,e.replaceState=a,n.removeEventListener("popstate",o);}}function ze(t$1,e){let n=fe();if(!n)return ()=>{};let r=e.onError??(()=>{}),o=We(e.maskSelectors??[],r),i=b(r),a=e.captureElementText??false,s=p=>{let u=p.target;if(!Ve(u)||U(u))return;let c=H(u),d=o.isMasked(u)||o.holdsMasked(c),f=o.isOptedOut(u)?{}:V(c,i),P=f.$el_description===void 0?Je(c,d,a):{};t$1.capture(t.autocapture,{properties:{...me(),...Ke(c,d,a),...P,...f}});};return n.addEventListener("click",s,true),()=>n.removeEventListener("click",s,true)}function he(t,e={}){let n=[];return (e.pageviews??true)&&n.push(qe(t)),(e.clicks??true)&&n.push(ze(t,e)),()=>{for(let r of n)r();}}function Ge(){return globalThis.document?.visibilityState==="hidden"}function Xe(t){let e=globalThis.navigator,n=globalThis.Blob;if(!e?.sendBeacon||!n)return false;let r=JSON.stringify({...t.body,api_key:t.projectKey});try{let o=new n([r],{type:"application/json"});return e.sendBeacon(t.url,o)}catch{return false}}var L=class{constructor(e={}){a(this,"fetchTransport");this.fetchTransport=new x$1(e);}async send(e){Ge()&&Xe(e)||await this.fetchTransport.send(e);}};var Ye=/^\d{1,3}(\.\d{1,3}){3}$/,Qe=/^[a-z0-9.-]+$/i;function ge(){return Math.random().toString(36).slice(2,12)}function S(t,e){let n=`${e}=`,r=[];for(let o of t.cookie.split(";")){let i=o.trim();i.startsWith(n)&&r.push(i.slice(n.length));}return r}function k(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function ke(t,e,n,r){try{let o=`pdx_probe_${r()}`,i=r();t.cookie=`${o}=${i}; ${k(e,60,n)}`;let a=S(t,o).includes(i);t.cookie=`${o}=; ${k(e,0,n)}`;let s=S(t,o).includes(i);return a&&!s}catch{return false}}function K(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||Ye.test(e)||!e.includes("."))return [];let n=e.split("."),r=[];for(let o=n.length-2;o>=0;o-=1)r.push(n.slice(o).join("."));return r}function ye(t,e,n,r=ge){for(let o of K(t))if(ke(e,o,n,r))return o}function Ze(t){let e=new Map,n=JSON.parse(decodeURIComponent(t));if(n===null||typeof n!="object"||Array.isArray(n))return e;for(let[r,o]of Object.entries(n))typeof o=="string"&&e.set(r,o);return e}var B=class{constructor(e,n,r,o){this.jar=e;this.name=n;this.domain=r;this.secure=o;}getItem(e){return this.read().get(e)??null}setItem(e,n){let r=this.read();r.set(e,n),this.write(r);}removeItem(e){let n=this.read();n.delete(e)&&this.write(n);}read(){try{let e=S(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${k(void 0,0,this.secure)}`,e=S(this.jar,this.name));let n=e[0];return n?Ze(n):new Map}catch{return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${k(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${k(this.domain,31536e3,this.secure)}`;}catch{return}}};function et(){return globalThis.document}function tt(){return globalThis.location?.hostname??""}function nt(){return globalThis.location?.protocol==="https:"}function rt(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Qe.test(e)?e.toLowerCase():void 0}function J(t){let e="jar"in t?t.jar:et();if(!e||globalThis.navigator?.cookieEnabled===false)return null;let r=t.random??ge,o=t.secure??nt(),i=t.hostname??tt();try{let a=rt(t.domain)??ye(i,e,o,r);return ke(e,a,o,r)?new B(e,t.name,a,o):null}catch{return null}}var be="_pdx",Te="~",ot=200,it=/^\d+$/;function xe(t,e,n,r){let o=at(t.href);if(o===void 0||q(o.search).some(z))return;let i=ve(o.hostname,n);i===void 0||i===ve(r,n)||(o.search=`${o.search}${o.search?"&":"?"}${be}=${st(e)}`,t.href=o.href);}function st(t){return [t.anonymousId,t.sessionId,String(t.sessionStartedAt)].map(ct).join(Te)}function Le(t){let e=q(t).find(z);if(e===void 0)return;let n=ut(e).split(Te);if(n.length!==3)return;let r=A(n[0]),o=A(n[1]),i=A(n[2]);if(!(!Ee(r)||!Ee(o)||!lt(i)))return {anonymousId:r,sessionId:o,sessionStartedAt:Number(i)}}function Se(t,e){let n=q(e.search),r=n.filter(i=>!z(i));if(r.length===n.length)return;let o=r.length>0?`?${r.join("&")}`:"";t.replaceState(t.state,"",`${e.pathname}${o}${e.hash}`);}function Ae(t){if(t.location===void 0||typeof t.location.search!="string")return;let e=Le(t.location.search);if(e===void 0)return;let n=q$1(t.storage,t.shared,t.namespace,e.anonymousId);return s(t.shared,t.namespace,{id:e.sessionId,startedAt:e.sessionStartedAt},t.now),t.history!==void 0&&Se(t.history,t.location),n}function W(t,e,n){if(n.length===0)return ()=>{};let r=o=>{let i=ft(o.target);if(i===void 0)return;let a=dt(e);a!==void 0&&xe(i,a,n,t.location?.hostname??"");};return t.addEventListener("click",r,true),t.addEventListener("auxclick",r,true),()=>{t.removeEventListener("click",r,true),t.removeEventListener("auxclick",r,true);}}function at(t){try{let e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"?e:void 0}catch{return}}function ve(t,e){let n=e.map(r=>r.replace(/^\./,"").toLowerCase());return K(t).find(r=>n.includes(r))}function q(t){return t.replace(/^\?/,"").split("&").filter(e=>e!=="")}function z(t){let e=t.indexOf("=");return A(e===-1?t:t.slice(0,e))===be}function ut(t){let e=t.indexOf("=");return e===-1?"":t.slice(e+1)}function ct(t){return encodeURIComponent(t).replace(/~/g,"%7E")}function A(t){try{return decodeURIComponent(t)}catch{return}}function Ee(t){if(t===void 0)return false;let e$1=e(t);return e$1>=1&&e$1<=ot}function lt(t){return t!==void 0&&it.test(t)&&Number.isSafeInteger(Number(t))}function dt(t){if(t.consent?.()?.identityLink===false)return;let e=t.sessionId,n=t.sessionStartedAt;if(!(e===void 0||n===void 0))return {anonymousId:t.anonymousId,sessionId:e,sessionStartedAt:n}}function pt(t){return typeof t.tagName=="string"&&t.tagName.toUpperCase()==="A"&&typeof t.href=="string"}function ft(t){let e=typeof t=="object"?t:null;for(;e;){if(pt(e))return e;e=e.parentElement??null;}}var we={maskAllInputs:true,maskAllText:false},mt=new Set(["email","password","tel"]);function Ne(t){return t.replace(/\S/g,"*")}function w(t,e,n){return ht(e)||n.maskAllInputs?Ne(t):t}function N(t,e){return e.maskAllText?Ne(t):t}function ht(t){return mt.has((t??"").toLowerCase())}var gt=5e3,O=class{constructor(e){this.options=e;a(this,"buffer",[]);a(this,"seq",0);a(this,"maxEvents");this.maxEvents=Math.min(Math.max(1,e.maxEvents),gt);}add(e){return this.buffer.push(e),this.buffer.length>=this.maxEvents?this.flush():null}flush(){if(this.buffer.length===0)return null;let e=this.buffer;this.buffer=[];let n={distinct_id:this.options.distinctId(),events:e,masked:this.options.masked,schema_version:1,seq:this.seq,session_id:this.options.sessionId,timestamp:new Date(this.options.now()).toISOString()};return this.seq+=1,n}};var G=1,X=3,kt=9,C=class{constructor(){a(this,"next",1);}allocate(){let e=this.next;return this.next+=1,e}},yt=new Set(["NOSCRIPT","SCRIPT"]);function I(t,e,n,r){if(t.nodeType===X){let o=e.allocate();return r?.(t,o),{id:o,textContent:N(t.textValue??"",n),type:"text"}}if(t.nodeType===kt){let o=e.allocate();return r?.(t,o),{childNodes:Oe(t,e,n,r),id:o,type:"document"}}if(t.nodeType===G){let o=t.tagName??"";if(yt.has(o))return null;let i=e.allocate();return r?.(t,i),{attributes:vt(t,n),childNodes:Oe(t,e,n,r),id:i,tagName:o,type:"element"}}return null}function Oe(t,e,n,r){let o=[];for(let i of t.childNodes??[]){let a=I(i,e,n,r);a&&o.push(a);}return o}function vt(t,e){let n={};for(let r of t.attributes??[])n[r.name]=r.value;return t.inputValue!==void 0&&(n.value=w(t.inputValue,t.inputType,e)),n}async function Ce(t,e){let n=`${h$2(e.replayHost)}/v1/replay`;return (await e.fetch(n,{body:JSON.stringify(t),headers:{authorization:`Bearer ${e.apiKey}`,"content-type":"application/json"},method:"POST"})).ok}var Ie=new Set(["INPUT","SELECT","TEXTAREA"]),_=class{constructor(e){this.options=e;a(this,"allocator",new C);a(this,"mirror",new Map);a(this,"chunker");a(this,"fetchImpl");a(this,"observer");a(this,"timer");a(this,"started",false);this.chunker=new O({distinctId:e.distinctId,masked:e.mask.maskAllInputs,maxEvents:e.maxEvents,now:e.now,sessionId:e.sessionId}),this.fetchImpl=e$1(e.fetch);}start(){if(this.started)return;let e=Et(),n=e?.documentElement;!e||!n||!this.fetchImpl||(this.started=true,this.captureFullSnapshot(n),this.observeMutations(n),this.observeInteractions(e),this.timer=setInterval(()=>this.upload(this.chunker.flush()),this.options.flushIntervalMs));}stop(){this.started&&(this.started=false,this.observer?.disconnect(),this.timer&&clearInterval(this.timer),this.upload(this.chunker.flush()));}captureFullSnapshot(e){let n=I(this.adapt(e),this.allocator,this.options.mask,(r,o)=>{let i=r.ref;i&&this.mirror.set(i,o);});n&&this.push(2,{node:n});}observeMutations(e){let n=globalThis.MutationObserver;n&&(this.observer=new n(r=>{for(let o of r)this.handleMutation(o);}),this.observer.observe(e,{attributes:true,characterData:true,childList:true,subtree:true}));}handleMutation(e){if(e.type==="characterData"){let n=this.mirror.get(e.target);n!==void 0&&this.push(3,{texts:[{id:n,value:N(e.target.textContent??"",this.options.mask)}]});return}if(e.type==="attributes"&&e.attributeName){let n=this.mirror.get(e.target),r=e.target;n!==void 0&&this.push(3,{attributes:[{attributes:{[e.attributeName]:r.getAttribute(e.attributeName)??""},id:n}]});return}if(e.type==="childList"){let n=this.mirror.get(e.target);if(n===void 0)return;for(let r of Array.from(e.addedNodes)){let o=I(this.adapt(r),this.allocator,this.options.mask,(i,a)=>{let s=i.ref;s&&this.mirror.set(s,a);});o&&this.push(3,{adds:[{node:o,parentId:n}]});}for(let r of Array.from(e.removedNodes)){let o=this.mirror.get(r);o!==void 0&&(this.push(3,{removes:[{id:o,parentId:n}]}),this.mirror.delete(r));}}}observeInteractions(e){e.addEventListener("input",n=>{let r=n.target;if(!r||!Ie.has(r.tagName))return;let o=this.mirror.get(r);o!==void 0&&this.push(3,{input:{id:o,value:w(r.value??"",r.type,this.options.mask)}});},true),e.addEventListener("scroll",n=>{let r=n.target,o=r?this.mirror.get(r):void 0;this.push(3,{scroll:{id:o??0,x:r?.scrollLeft??0,y:r?.scrollTop??0}});},true);}adapt(e){let n={childNodes:[],nodeType:e.nodeType,ref:e};if(e.nodeType===X)return n.textValue=e.textContent??"",n;if(e.nodeType===G){let r=e;if(n.tagName=r.tagName,n.attributes=Array.from(r.attributes).map(o=>({name:o.name,value:o.value})),Ie.has(r.tagName)){let o=r;n.inputType=o.type,n.inputValue=o.value??"";}}return n.childNodes=Array.from(e.childNodes).map(r=>this.adapt(r)),n}push(e,n){let r=this.chunker.add({data:n,timestamp:this.options.now(),type:e});r&&this.upload(r);}upload(e){!e||!this.fetchImpl||Ce(e,{apiKey:this.options.apiKey,fetch:this.fetchImpl,replayHost:this.options.replayHost}).catch(n=>this.options.onError?.(n));}};function Et(){return globalThis.document}function _e(t){let e=new _({apiKey:t.apiKey,distinctId:t.distinctId,flushIntervalMs:t.flushIntervalMs??5e3,mask:{...we,...t.mask},maxEvents:t.maxEvents??200,now:t.now??(()=>Date.now()),onError:t.onError,replayHost:t.replayHost,sessionId:t.sessionId??d()});return e.start(),e}function bt(){return globalThis.navigator}function Tt(){return globalThis.document}function xt(){return globalThis.history}function Lt(){return globalThis.location}function St(t){let e=t?.userAgentData?.platform??t?.platform;return e?e.slice(0,50):void 0}function At(t){let e=()=>{t.flush();};globalThis.document?.addEventListener?.("visibilitychange",e),globalThis.addEventListener?.("pagehide",e);}function wt(t,e,n){try{return J({domain:e,name:`pdx_${h$1(t)}`})??n}catch{return n}}function bn(t){let{autocaptureOptions:e,cookieDomain:n,linkedDomains:r,replayHost:o,sessionReplay:i,sessionReplayOptions:a,...s}=t,p=bt(),u=b$1(),c$1=s.storage??u,d=s.sharedStorage??wt(s.apiKey,n,u),f=Ae({history:xt(),location:Lt(),namespace:h$1(s.apiKey),now:(s.clock??c).now().getTime(),shared:d,storage:c$1}),P=b(s.onError??(()=>{})),v={...s,describeElement:s.describeElement??(Pe=>pe(Pe,P)),locale:s.locale??(p?.language?p.language.slice(0,20):void 0),os:s.os??St(p),sessionTracking:s.sessionTracking??true,sharedStorage:d,storage:c$1,transport:s.transport??new L({maxRetries:s.maxRetries,requestTimeoutMs:s.requestTimeoutMs})},m=new y(v);f!==void 0&&m.alias(f),At(m),(t.autocapture??true)&&he(m,{onError:v.onError,...e});let Y=Tt();return Y&&r&&W(Y,m,r),i&&o&&_e({apiKey:v.apiKey,distinctId:()=>m.distinctId,onError:v.onError,replayHost:o,...a,sessionId:a?.sessionId??m.sessionId}),m}export{le as ACTION_ATTRIBUTE,ce as ANNOTATION_ATTRIBUTE,h as ANNOTATION_MAX_LENGTH,de as IGNORE_ATTRIBUTE,L as WebTransport,J as createCookieStorage,bn as createWebClient,xe as decorateLink,he as installAutocapture,W as installLinkCarry,_e as installSessionReplay,Le as readCarry,ye as resolveCookieDomain,Se as stripCarry};//# sourceMappingURL=web.js.map
2
2
  //# sourceMappingURL=web.js.map
package/package.json CHANGED
@@ -63,5 +63,5 @@
63
63
  "sideEffects": false,
64
64
  "type": "module",
65
65
  "types": "./dist/index.d.ts",
66
- "version": "0.6.0"
66
+ "version": "0.7.0-beta.438"
67
67
  }
@@ -1,2 +0,0 @@
1
- import {c as c$1,a as a$2,b as b$2}from'./chunk-V77KYPOF.js';import {e,h,d,f as f$1,g,a as a$1,b as b$1,c as c$2}from'./chunk-ODN4ZELX.js';import {a}from'./chunk-5XGN7UAV.js';var m=class{constructor(){a(this,"store",new Map);}getItem(e){return this.store.get(e)??null}removeItem(e){this.store.delete(e);}setItem(e,t){this.store.set(e,t);}};function Ce(){try{let s=globalThis.localStorage;if(s){let e="__pdx_probe__";return s.setItem(e,"1"),s.removeItem(e),s}}catch{return new m}return new m}var V={now:()=>new Date};function S(s){return s.toISOString()}var de=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var ue=/^(?:\$|[a-z])[a-z0-9_.]*$/;function j(s){let e=0;for(let t of s)e+=1;return e}function H(s){return de.test(s)}function he(s){return ue.test(s)}function U(s){let e=j(s);if(e<1||e>200)throw new c$2("distinct_id","distinct_id must be between 1 and 200 characters")}function B(s){let e=j(s);if(e<1||e>200)throw new c$2("event_name","event_name must be between 1 and 200 characters");if(!he(s))throw new c$2("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var J="prodantix-js",z="0.0.1";function pe(){return globalThis.crypto}function fe(s){s[6]=s[6]&15|64,s[8]=s[8]&63|128;let e=[];for(let t=0;t<16;t+=1)e.push(s[t].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function ge(){let s=pe();if(s?.randomUUID)return s.randomUUID();let e=new Uint8Array(16);if(s?.getRandomValues)s.getRandomValues(e);else for(let t=0;t<16;t+=1)e[t]=Math.floor(Math.random()*256);return fe(e)}var Q={uuid:ge};var me=s=>{};function G(s){if(!s.apiKey||!H(s.apiKey))throw new b$1("apiKey must be a public project key of the form pdx_pub_<32 lowercase alphanumerics>");if(!s.host)throw new b$1("host is required (the ingest base URL)");let e=h(s.host),t=s.defaultProperties,n=s.storage??new m;return {apiKey:s.apiKey,autocapture:s.autocapture??false,clock:s.clock??V,consent:s.consent,defaultProperties:typeof t=="function"?t:()=>t??{},flagsHost:s.flagsHost?h(s.flagsHost):e,flushAt:s.flushAt??20,flushIntervalMs:s.flushIntervalMs??1e4,host:e,ids:s.ids??Q,locale:s.locale,maxQueueSize:s.maxQueueSize??1e3,maxRetries:s.maxRetries??3,namespace:ye(s.apiKey),onError:s.onError??me,os:s.os,requestTimeoutMs:s.requestTimeoutMs??1e4,sdkName:s.sdkName??J,sdkVersion:s.sdkVersion??z,sessionTracking:s.sessionTracking??false,sharedStorage:s.sharedStorage??n,socketFactory:s.socketFactory,storage:n,streamFlags:s.streamFlags??false,transport:s.transport}}function ye(s){return s.slice(0,16)}var f=Symbol("absent");function ve(s,e){if(s==="distinct_id")return e.distinctId;let t=e.properties??{};if(Object.prototype.hasOwnProperty.call(t,s))return t[s];let n=e.attributes??{};return Object.prototype.hasOwnProperty.call(n,s)?n[s]:f}function p(s){return s===f?"undefined":String(s)}function W(s){return s===f?Number.NaN:Number(s)}function Y(s){return s!==f&&s!==null&&s!==""}function X(s,e){if(!Array.isArray(e))return false;let t=p(s);return e.map(n=>String(n)).includes(t)}function Z(s,e){let t=ve(s.attribute,e),n=s.value;switch(s.op){case "is_set":return Y(t);case "is_not_set":return !Y(t);case "eq":return p(t)===p(n===void 0?f:n);case "neq":return p(t)!==p(n===void 0?f:n);case "contains":return p(t).includes(p(n===void 0?f:n));case "in":return X(t,n);case "not_in":return Array.isArray(n)?!X(t,n):false;case "gt":return x(t,n,(i,r)=>i>r);case "gte":return x(t,n,(i,r)=>i>=r);case "lt":return x(t,n,(i,r)=>i<r);case "lte":return x(t,n,(i,r)=>i<=r);case "in_cohort":return typeof n=="string"&&n!==""&&(e.cohorts??[]).includes(n);case "not_in_cohort":return typeof n=="string"&&n!==""&&!(e.cohorts??[]).includes(n);default:return false}}function x(s,e,t){let n=W(s),i=e===void 0?Number.NaN:W(e);return Number.isNaN(n)||Number.isNaN(i)?false:t(n,i)}function ee(s,e){let t=`${s}:${e}`,n=2166136261;for(let i=0;i<t.length;i++)n^=t.charCodeAt(i),n=Math.imul(n,16777619);return (n>>>0)%100}function P(s,e){return s.targeting.length===0||s.targeting.every(t=>Z(t,e))}function te(s,e){let t=ee(s.key,e.distinctId),n=s.variations??[];if(n.length===0)return s.rolloutPercentage>=100||t<s.rolloutPercentage?"true":"false";let i=0;for(let r=n.length-1;r>=0;r--)if(i+=n[r].weight,t<i)return n[r].key;return n[0].key}function R(s,e,t,n){for(let i of s.prerequisites??[]){if(n.includes(i.flagKey))return false;let r=e.find(d=>d.key===i.flagKey);if(!r||!r.enabled)return false;n.push(r.key);let a=R(r,e,t,n)&&P(r,t)&&te(r,t)===i.variationKey;if(n.pop(),!a)return false}return true}function y(s,e,t){return s.enabled?R(s,e,t,[s.key])?P(s,t)?s.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:ee(s.key,t.distinctId)<s.rolloutPercentage?{enabled:true,reason:"rollout"}:{enabled:false,reason:"rollout_excluded"}:{enabled:false,reason:"targeting"}:{enabled:false,reason:"prerequisite"}:{enabled:false,reason:"disabled"}}function ze(s,e){return y(s,[],e)}function se(s,e){let t={};for(let n of s)t[n.key]=y(n,s,e).enabled;return t}function v(s,e,t){let n=s.variations??[],i=n[0];if(!i)return null;if(!s.enabled||!R(s,e,t,[s.key])||!P(s,t))return i;let r=te(s,t);return n.find(a=>a.key===r)??i}function Qe(s,e){return v(s,[],e)}function Ge(s,e,t){let n=s.find(i=>i.key===e);return n?v(n,s,t)?.value??null:null}function ne(s){return s.some(e=>e.targeting.some(t=>t.op==="in_cohort"||t.op==="not_in_cohort"))}var I=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async fetchAll(e){return (await this.fetchDecisions(e)).flags}async fetchDecisions(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=`${this.host}/v1/flags?distinct_id=${encodeURIComponent(e)}`,i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await t(n,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!a.ok)throw new d(`flags request failed with status ${a.status}`,a.status);let d$1=JSON.parse(await a.text());return {flags:d$1.flags??{},variants:d$1.variants??{}}}finally{r!==void 0&&clearTimeout(r);}}async snapshot(){let e=this.fetch;if(!e)throw new d("no fetch implementation available in this runtime");let t=`${this.host}/v1/flags/snapshot`,n=f$1(),i=n?setTimeout(()=>n.abort(),this.requestTimeoutMs):void 0;try{let r=await e(t,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:n?.signal});if(!r.ok)throw new d(`flag snapshot request failed with status ${r.status}`,r.status);let a=JSON.parse(await r.text()),d$1={flags:a.flags??[],generatedAt:a.generatedAt};return typeof a.socketUrl=="string"&&a.socketUrl!==""&&(d$1.socketUrl=a.socketUrl),d$1}finally{i!==void 0&&clearTimeout(i);}}async memberships(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=`${this.host}/v1/flags/memberships?distinct_id=${encodeURIComponent(e)}`,i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await t(n,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!a.ok)throw new d(`memberships request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).cohorts??[]}finally{r!==void 0&&clearTimeout(r);}}};function b(s){if(typeof s!="string")return;let e=Array.from(s).length;return e>=1&&e<=200?s:void 0}function F(s,e){return `pdx.${s}.${e}`}var ie="consent";function be(s){if(typeof s!="string")return null;try{let e=JSON.parse(s);if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=e.identityLink;return typeof t=="boolean"?{identityLink:t}:null}catch{return null}}function ke(s,e){return be(s.getItem(F(e,ie)))}function Se(s,e,t){let n=F(e,ie);if(typeof t.identityLink!="boolean"){s.removeItem(n);return}s.setItem(n,JSON.stringify({identityLink:t.identityLink}));}function tt(s,e,t,n){let i=F(t,"anonymous_id"),r=b(e.getItem(i))??b(s.getItem(i));return e.setItem(i,n),s.setItem(i,n),r!==void 0&&r!==n?r:void 0}var w=class{constructor(e,t,n,i){this.storage=e;this.shared=t;this.ids=n;this.namespace=i;a(this,"anonymousId");a(this,"distinctId");a(this,"identified");this.refresh();}refresh(){let e=b(this.shared.getItem(this.key("anonymous_id"))),t=b(this.storage.getItem(this.key("anonymous_id")));e?(this.anonymousId=e,t!==e&&this.storage.setItem(this.key("anonymous_id"),e)):t?(this.anonymousId=t,this.shared.setItem(this.key("anonymous_id"),t)):(this.anonymousId=this.ids.uuid(),this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId));let n=b(this.storage.getItem(this.key("distinct_id")));n?(this.distinctId=n,this.identified=true):(this.distinctId=this.anonymousId,this.identified=false);}getAnonymousId(){return this.anonymousId}getDistinctId(){return this.distinctId}isIdentified(){return this.identified}snapshot(){return {anonymousId:this.anonymousId,distinctId:this.distinctId,identified:this.identified}}consent(){return ke(this.shared,this.namespace)}setConsent(e){Se(this.shared,this.namespace,e);}identify(e){let t=!this.identified||this.distinctId!==e,n=this.storage.getItem(this.key("linked_anonymous_id")),i=t||n!==this.anonymousId;return this.distinctId=e,this.identified=true,t&&this.storage.setItem(this.key("distinct_id"),e),!i||this.consent()?.identityLink===false?{changed:t}:(this.storage.setItem(this.key("linked_anonymous_id"),this.anonymousId),{anonymousToLink:this.anonymousId,changed:t})}reset(){this.anonymousId=this.ids.uuid(),this.distinctId=this.anonymousId,this.identified=false,this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.removeItem(this.key("distinct_id")),this.storage.removeItem(this.key("linked_anonymous_id"));}key(e){return F(this.namespace,e)}};var E=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async inbox(e){let t=this.requireFetch(),n=`${this.host}/v1/messages?distinct_id=${encodeURIComponent(e)}`,i=await this.request(t,n,{headers:this.authHeaders(),method:"GET"});if(!i.ok)throw new d(`inbox request failed with status ${i.status}`,i.status);return JSON.parse(await i.text()).messages??[]}async markRead(e,t){let n=this.requireFetch(),i=`${this.host}/v1/messages/read`,r=await this.request(n,i,{body:JSON.stringify({distinct_id:t,message_id:e}),headers:{...this.authHeaders(),"content-type":"application/json"},method:"POST"});if(!r.ok)throw new d(`mark-read request failed with status ${r.status}`,r.status)}requireFetch(){if(!this.fetch)throw new d("no fetch implementation available in this runtime");return this.fetch}authHeaders(){return {authorization:`Bearer ${this.projectKey}`}}async request(e,t,n){let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(t,{...n,signal:i?.signal})}finally{r!==void 0&&clearTimeout(r);}}};var c={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageview:"$pageview",screen:"$screen",set:"$set"},xe=[{emittedBy:"web",meaning:"A click anywhere on the page, with the element that was clicked. The web SDK sends it by default; autocapture: false or autocaptureOptions.clicks: false turns it off.",name:c.autocapture,properties:["$event_type","$el_tag","$el_text","$el_id","$el_classes","$el_href","$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"web",meaning:"A page shown, including every client-side navigation the History API makes: one per distinct path and query.",name:c.pageview,properties:["$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"flutter",meaning:"A named route pushed or replaced in a Flutter app, the mobile counterpart of $pageview.",name:c.screen,properties:["screen"]},{emittedBy:"every",meaning:"A person becomes known by a distinct id. The anonymous trail before it is joined to them, and any traits ride along under $set.",name:c.identify,properties:["$anon_distinct_id","$set"]},{emittedBy:"every",meaning:"A second id for the same person, so events sent under either resolve to one profile.",name:c.createAlias,properties:["alias"]},{emittedBy:"every",meaning:"The person is placed in a group such as a company or a team; group properties ride along under $set.",name:c.group,properties:["$group_type","$group_key","$set"]},{emittedBy:"every",meaning:"Person properties written without an identify: $set overwrites, $set_once fills only what is still empty.",name:c.set,properties:["$set","$set_once"]},{emittedBy:"every",meaning:"A flag was evaluated for this person, sent once per distinct answer. Experiments attribute exposure from it.",name:c.featureFlagCalled,properties:["$feature_flag","$feature_flag_response"]}],lt=s=>s.startsWith("$"),ct=s=>xe.find(e=>e.name===s);function re(s){return s>=400&&s<500&&s!==429}var T=class{constructor(e$1={}){a(this,"fetch");a(this,"maxRetries");a(this,"requestTimeoutMs");a(this,"baseDelayMs");a(this,"maxDelayMs");a(this,"sleep");a(this,"random");this.fetch=e(e$1.fetch),this.maxRetries=e$1.maxRetries??3,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4,this.baseDelayMs=e$1.baseDelayMs??500,this.maxDelayMs=e$1.maxDelayMs??3e4,this.sleep=e$1.sleep??g,this.random=e$1.random??Math.random;}async send(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=JSON.stringify(e.body),i;for(let r=0;r<=this.maxRetries;r+=1){try{let a=await this.attempt(t,e,n);if(a.ok)return;if(re(a.status))throw new d(`ingest rejected batch with status ${a.status}`,a.status);i=new d(`ingest transient status ${a.status}`,a.status);}catch(a){if(a instanceof d&&a.status!==void 0&&re(a.status))throw a;i=a;}r<this.maxRetries&&await this.sleep(this.backoff(r));}throw new d("ingest delivery failed after retries",void 0,{cause:i})}async attempt(e,t,n){let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(t.url,{body:n,headers:{authorization:`Bearer ${t.projectKey}`,"content-type":"application/json"},method:"POST",signal:i?.signal})}finally{r!==void 0&&clearTimeout(r);}}backoff(e){return Math.min(this.maxDelayMs,this.baseDelayMs*2**e)+this.random()*this.baseDelayMs}};function oe(s,e,t){B(s.eventName),U(s.distinctId);let n={distinct_id:s.distinctId,event_id:s.eventId??t.uuid(),event_name:s.eventName,properties:s.properties??{},schema_version:1,timestamp:S(s.timestamp??e.now())};return s.context&&(n.context=s.context),s.sessionId&&(n.session_id=s.sessionId),n}var Ie="/socket.io/?EIO=4&transport=websocket",we=250,_=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"pending",null);a(this,"lastKey","");a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??Fe,this.setTimer=e.setTimer??((t,n)=>setTimeout(t,n)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Ie}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=n=>this.receive(String(n.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat(),this.pending!==null&&this.clearTimer(this.pending),this.pending=null;let e=this.socket;this.socket=null,e?.close();}receive(e){let t=c$1(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(a$2({projectKey:this.options.projectKey}));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(b$2());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true;return}if(t.name==="flagChange"){let n=t.payload?.key;this.lastKey=typeof n=="string"?n:"",this.pending===null&&(this.pending=this.setTimer(()=>{this.pending=null,this.options.onChange(this.lastKey);},we));}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Fe(s){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(s)}var C=class{constructor(e,t){this.maxSize=e;this.onOverflow=t;a(this,"events",[]);}get size(){return this.events.length}enqueue(e){this.events.push(e),this.enforceCap();}restore(e){this.events.push(...e),this.enforceCap();}requeue(e){this.events.unshift(...e),this.enforceCap();}drain(e){let t=e===void 0?this.events.length:Math.min(e,this.events.length);return this.events.splice(0,t)}snapshot(){return [...this.events]}enforceCap(){if(this.events.length<=this.maxSize)return;let e=this.events.splice(0,this.events.length-this.maxSize);this.onOverflow?.({dropped:e});}};var Ee={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function ae(s){return `pdx.${s}.session`}function wt(s,e,t,n){let i={id:t.id,lastActivityAt:n,startedAt:t.startedAt};s.setItem(ae(e),JSON.stringify(i));}var A=class{constructor(e,t,n,i,r=Ee){this.storage=e;this.ids=t;this.clock=n;this.namespace=i;this.options=r;}current(){return this.touch().id}startedAt(){return this.touch().startedAt}reset(){this.storage.removeItem(this.key());}touch(){let e=this.clock.now().getTime(),t=this.live(this.read(),e);if(t===void 0)return this.write({id:this.ids.uuid(),lastActivityAt:e,startedAt:e});if(e-t.lastActivityAt<=this.options.throttleMs)return t;let n=this.live(this.read(),e),i=n!==void 0&&n.id!==t.id?n:t;return this.write({...i,lastActivityAt:e})}live(e,t){if(e!==void 0&&!(t-e.lastActivityAt>this.options.idleMs||t-e.startedAt>this.options.maxMs))return e}write(e){return this.storage.setItem(this.key(),JSON.stringify(e)),e}read(){let e=this.storage.getItem(this.key());if(e)try{let t=JSON.parse(e);return typeof t.id=="string"&&typeof t.startedAt=="number"&&typeof t.lastActivityAt=="number"?{id:t.id,lastActivityAt:t.lastActivityAt,startedAt:t.startedAt}:void 0}catch{return}}key(){return ae(this.namespace)}};var Te="queue",_e=1e3,le=3e4,M=s=>{let e={};return s.avatar!==void 0&&(e.$avatar=s.avatar),s.email!==void 0&&(e.$email=s.email),s.name!==void 0&&(e.$name=s.name),s.phone!==void 0&&(e.$phone=s.phone),e},q=class{constructor(e){a(this,"config");a(this,"identity");a(this,"session");a(this,"queue");a(this,"transport");a(this,"flagsClient");a(this,"messagesClient");a(this,"context");a(this,"flushTimer");a(this,"flushing",false);a(this,"cachedFlags");a(this,"cachedSnapshot");a(this,"membershipCache");a(this,"stream");a(this,"shutDown",false);a(this,"exposures",new Set);this.config=G(e),this.identity=new w(this.config.storage,this.config.sharedStorage,this.config.ids,this.config.namespace),this.config.consent!==void 0&&this.identity.setConsent(this.config.consent),this.session=this.config.sessionTracking?new A(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new C(this.config.maxQueueSize,({dropped:t})=>{this.config.onError(new a$1("queue_overflow",`event queue overflow: dropped ${t.length} oldest event(s)`));}),this.transport=this.config.transport??new T({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new I({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new E({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.context={sdk:this.config.sdkName,sdk_version:this.config.sdkVersion},this.config.os&&(this.context.os=this.config.os),this.config.locale&&(this.context.locale=this.config.locale),this.restoreQueue(),this.startTimer();}get distinctId(){return this.identity.getDistinctId()}get anonymousId(){return this.identity.getAnonymousId()}get isIdentified(){return this.identity.isIdentified()}get sessionId(){return this.session?.current()}get sessionStartedAt(){return this.session?.startedAt()}capture(e,t={}){try{this.identity.refresh();let n={...this.config.defaultProperties(),...t.properties??{}},i=oe({context:this.context,distinctId:t.distinctId??this.identity.getDistinctId(),eventName:e,properties:n,sessionId:t.sessionId??this.session?.current(),timestamp:t.timestamp},this.config.clock,this.config.ids);this.enqueue(i);}catch(n){this.config.onError(n);}}identify(e,t={}){this.identity.refresh();let n=this.identity.identify(e),i={};n.anonymousToLink!==void 0&&(i.$anon_distinct_id=n.anonymousToLink);let r={...M(t.traits??{}),...t.set??{}};Object.keys(r).length>0&&(i.$set=r),this.capture(c.identify,{properties:i});}link(e,t,n){let i={$anon_distinct_id:t},r=M(n??{});Object.keys(r).length>0&&(i.$set=r),this.capture(c.identify,{distinctId:e,properties:i});}setConsent(e){this.identity.setConsent(e);}consent(){return this.identity.consent()}alias(e){this.capture(c.createAlias,{properties:{alias:e}});}group(e,t,n){let i={$group_key:t,$group_type:e};n&&(i.$set=n),this.capture(c.group,{properties:i});}setPersonProperties(e,t){let n={};e&&(n.$set=e),t&&(n.$set_once=t),this.capture(c.set,{properties:n});}setPersonTraits(e){let t=M(e);Object.keys(t).length!==0&&this.capture(c.set,{properties:{$set:t}});}async getAllFlags(){let e=this.identity.getDistinctId(),t=await this.flagsClient.fetchDecisions(e);return this.cachedFlags={distinctId:e,flags:t.flags,variants:t.variants??{}},t.flags}async isFeatureEnabled(e){let n=(await this.getAllFlags())[e]??false;return this.recordExposure(e,this.cachedFlags?.variants[e]?.key??String(n)),n}async getVariant(e){let t=await this.getAllFlags(),n=this.cachedFlags?.variants[e]??null;return this.recordExposure(e,n?.key??String(t[e]??false)),n}async getVariantLocal(e,t={}){let n=await this.flagSnapshot(),i=n.flags.find(ce=>ce.key===e),r=await this.localContext(t,n.flags),a=i?v(i,n.flags,r):null,d=i?y(i,n.flags,r).enabled:false;return this.recordExposure(e,a?.key??String(d)),a?{key:a.key,value:a.value}:null}recordExposure(e,t){let n=`${this.identity.getDistinctId()} ${e} ${t}`;this.exposures.has(n)||(this.exposures.add(n),this.capture(c.featureFlagCalled,{properties:{$feature_flag:e,$feature_flag_response:t}}));}getCachedFlag(e){if(!(!this.cachedFlags||this.cachedFlags.distinctId!==this.distinctId))return this.cachedFlags.flags[e]}async getLocalFlags(e={}){let t=await this.flagSnapshot();return se(t.flags,await this.localContext(e,t.flags))}async isFeatureEnabledLocal(e,t={}){let n=await this.flagSnapshot(),i=n.flags.find(d=>d.key===e),r=await this.localContext(t,n.flags),a=i?y(i,n.flags,r).enabled:false;return this.recordExposure(e,(i?v(i,n.flags,r)?.key:void 0)??String(a)),a}async localContext(e,t){let n=this.identity.getDistinctId(),i=e.cohorts;if(i===void 0&&ne(t)){let r=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===n&&r-this.membershipCache.fetchedAt<le?i=this.membershipCache.cohorts:(i=await this.flagsClient.memberships(n),this.membershipCache={cohorts:i,distinctId:n,fetchedAt:r});}return {attributes:e.attributes,cohorts:i,distinctId:n,properties:e.properties}}async flagSnapshot(){let e=this.config.clock.now().getTime();if(this.cachedSnapshot&&e-this.cachedSnapshot.fetchedAt<le)return this.cachedSnapshot.snapshot;let t=await this.flagsClient.snapshot();return this.cachedSnapshot={fetchedAt:e,snapshot:t},this.maybeStream(t),t}maybeStream(e){if(!this.config.streamFlags||this.shutDown||this.stream||!e.socketUrl)return;let t=new _({host:e.socketUrl,onChange:()=>{this.cachedSnapshot=void 0,this.flagSnapshot().catch(n=>this.config.onError(n));},onClosed:n=>{this.stream=void 0,n&&this.maybeStream(e);},projectKey:this.config.apiKey,socketFactory:this.config.socketFactory});this.stream=t,t.open();}async getInbox(){return this.messagesClient.inbox(this.identity.getDistinctId())}async markMessageRead(e){await this.messagesClient.markRead(e,this.identity.getDistinctId());}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(_e);try{await this.transport.send({body:{events:e,sent_at:S(this.config.clock.now())},projectKey:this.config.apiKey,url:`${this.config.host}/v1/events`}),this.persistQueue();}catch(t){this.queue.requeue(e),this.persistQueue(),this.config.onError(t);}finally{this.flushing=false;}}reset(){this.session?.reset(),this.identity.reset(),this.cachedFlags=void 0,this.cachedSnapshot=void 0,this.membershipCache=void 0;}async shutdown(){this.shutDown=true,this.stopTimer(),this.stream?.close(),this.stream=void 0,await this.flush();}enqueue(e){this.queue.enqueue(e),this.persistQueue(),this.queue.size>=this.config.flushAt&&this.flush();}persistQueue(){try{this.config.storage.setItem(this.persistKey(),JSON.stringify(this.queue.snapshot()));}catch(e){this.config.onError(e);}}restoreQueue(){try{let e=this.config.storage.getItem(this.persistKey());if(!e)return;let t=JSON.parse(e);Array.isArray(t)&&this.queue.restore(t);}catch(e){this.config.onError(e);}}startTimer(){if(this.config.flushIntervalMs<=0)return;let e=setInterval(()=>{this.flush();},this.config.flushIntervalMs),t=e;typeof t.unref=="function"&&t.unref(),this.flushTimer=e;}stopTimer(){this.flushTimer!==void 0&&(clearInterval(this.flushTimer),this.flushTimer=void 0);}persistKey(){return `pdx.${this.config.namespace}.${Te}`}};function Lt(s){return new q(s)}export{m as a,Ce as b,V as c,ge as d,j as e,J as f,z as g,ye as h,Z as i,ee as j,ze as k,se as l,Qe as m,Ge as n,I as o,be as p,tt as q,E as r,wt as s,c as t,xe as u,lt as v,ct as w,T as x,q as y,Lt as z};//# sourceMappingURL=chunk-4RLPQZ5L.js.map
2
- //# sourceMappingURL=chunk-4RLPQZ5L.js.map