@sentientui/core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2K7NAMTI.mjs +1 -0
- package/dist/index-graph.js +1 -1
- package/dist/index-graph.mjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +37 -39
- package/dist/chunk-HRRGYUE4.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var V=Object.defineProperty,X=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var z=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,J=(e,t)=>{for(var n in t||(t={}))Z.call(t,n)&&z(e,n,t[n]);if(F)for(var n of F(t))ee.call(t,n)&&z(e,n,t[n]);return e},j=(e,t)=>X(e,H(t));var te="_snt_uid";var b="_snt_uid";function ne(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function re(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function se(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(o){}}function ie(e){try{return localStorage.getItem(e)}catch(t){return null}}function oe(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function ae(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function ce(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function ue(e){try{sessionStorage.removeItem(e)}catch(t){}}function de(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function le(e){try{localStorage.removeItem(e)}catch(t){}}function ge(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var me={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function W(e){var m,d,p,I,y;if(typeof window=="undefined")return me;let t=(m=e==null?void 0:e.cookieName)!=null?m:te,o=((d=e==null?void 0:e.cookieTTLDays)!=null?d:365)*24*60*60,r=(y=(I=(p=re(t))!=null?p:ie(b))!=null?I:ae(b))!=null?y:ne();se(t,r,o);let a=oe(b,r),s=de(t),i=a?!1:ce(b,r),u=!a&&!s&&!i;return{getSessionId:()=>r,isEphemeral:()=>u,destroy:()=>{r=null,ge(t),le(b),ue(b)}}}var U="_snt_retry";var fe={push:()=>{},flush:()=>{},destroy:()=>{}};function pe(e){try{let t=localStorage.getItem(U);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?(localStorage.removeItem(U),n.slice(-e)):[]}catch(t){return[]}}function N(e,t){try{let o=[...(()=>{try{let r=localStorage.getItem(U);if(!r)return[];let a=JSON.parse(r);return Array.isArray(a)?a:[]}catch(r){return[]}})(),...e].slice(-t);localStorage.setItem(U,JSON.stringify(o))}catch(n){}}function Y(e){var A,x,G;if(typeof window=="undefined")return fe;let t=(A=e.flushIntervalMs)!=null?A:5e3,n=(x=e.maxBatchSize)!=null?x:20,o=(G=e.maxRetrySize)!=null?G:100,r=e.ingestUrl,a=e.apiKey,s=[],i=new Set,u=[],m=c=>{for(let l of c)i.has(l)||(i.add(l),u.push(l));for(;u.length>500;){let l=u.shift();l&&i.delete(l)}},d=new Set,p=c=>{i.has(c.id)||d.has(c.id)||(d.add(c.id),s.push(c))},I=pe(o);for(let c of I)p(c);let y=0,S=0,D=c=>{if(c.length===0)return;let l=JSON.stringify(c),_=c.map(w=>w.id),E;try{E=fetch(r,{method:"POST",keepalive:!0,body:l,headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}})}catch(w){N(c,o),S++,y=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6));return}let C=w=>{if(w.ok||w.status>=400&&w.status<500&&w.status!==429){m(_),S=0,y=0;return}N(c,o),S++,y=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))};E instanceof Promise?E.then(C).catch(()=>{N(c,o),S++,y=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))}):C(E)},T=c=>{let l=[],_=2;for(let E of c){let C=JSON.stringify(E).length+1;if(l.length>0&&_+C>57344||l.length>=n)break;l.push(E),_+=C}return l},h=()=>{try{if(Date.now()<y)return;for(;s.length>0;){let c=s.filter(_=>!i.has(_.id));if(s.length=0,c.length===0)break;let l=T(c);if(l.length===0)break;l.length<c.length&&s.push(...c.slice(l.length)),D(l)}}catch(c){}},g=!0,f=null;f=setInterval(()=>{g&&h()},t);let v=()=>{document.visibilityState==="hidden"&&h()},k=()=>{h()};return document.addEventListener("visibilitychange",v),window.addEventListener("beforeunload",k),{push(c){p(c),s.length>=n&&h()},flush:h,destroy(){g=!1,f!==null&&(clearInterval(f),f=null),document.removeEventListener("visibilitychange",v),window.removeEventListener("beforeunload",k),h()}}}var R="_snt_asgn_";function O(e,t){return`${e}:${t}`}function ye(e,t){return`${R}${e}_${t}`}function B(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(R)&&e.push(n)}return e}catch(e){return[]}}function q(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of B())try{let a=localStorage.getItem(r);if(!a)continue;let s=JSON.parse(a);if(n(s)){localStorage.removeItem(r);continue}let i=r.slice(R.length),u=i.lastIndexOf("_");if(u<0)continue;let m=i.slice(0,u),d=i.slice(u+1);t.set(O(m,d),s)}catch(a){}})(),{get(r,a){let s=t.get(O(r,a));return s?n(s)?(t.delete(O(r,a)),null):s:null},set(r,a,s){let i=O(r,a);t.set(i,s);try{localStorage.setItem(ye(r,a),JSON.stringify(s))}catch(u){}},invalidate(r){let a=`${r}:`;for(let s of[...t.keys()])s.startsWith(a)&&t.delete(s);for(let s of B()){let i=s.slice(R.length),u=i.lastIndexOf("_");if(u<0)continue;if(i.slice(0,u)===r)try{localStorage.removeItem(s)}catch(d){}}},clear(){t.clear();for(let r of B())try{localStorage.removeItem(r)}catch(a){}}}}function P(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function $(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(r){}let o=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(o)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(o)?"social":"referral"}catch(n){return"direct"}}function L(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function M(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function Se(e){let t=Q("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function Q(e,t){var a,s,i,u,m,d,p;let n=(s=(a=t==null?void 0:t.userAgent)==null?void 0:a.trim())!=null?s:"",o=(u=(i=t==null?void 0:t.referer)==null?void 0:i.trim())!=null?u:"",r=(m=t==null?void 0:t.now)!=null?m:new Date;return{sessionId:e,ephemeral:!1,utmParams:(d=t==null?void 0:t.utmParams)!=null?d:{},deviceClass:n?P(n):"desktop",trafficSource:o?$(o,t==null?void 0:t.appOrigin):"direct",referrerDomain:L(o),timeOfDay:M(r),dayOfWeek:(p=["sun","mon","tue","wed","thu","fri","sat"][r.getDay()])!=null?p:"sun"}}async function he(e,t,n){let o={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};n.origin&&(o.Origin=n.origin);let r=Q(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,appOrigin:n.origin});try{await fetch(`${n.baseUrl}/sessions`,{method:"POST",headers:o,body:JSON.stringify(r)})}catch(i){}let a=await Promise.allSettled(e.map(async({id:i,variantIds:u})=>{let m=await fetch(`${n.baseUrl}/assign`,{method:"POST",headers:o,body:JSON.stringify({sessionId:t,componentId:i,variantIds:u})});if(!m.ok)return null;let d=await m.json();return{id:i,variantId:d.variantId}})),s={};for(let i of a)i.status==="fulfilled"&&i.value&&(s[i.value.id]=i.value.variantId);return s}function ve(e){var t,n;return(n=(t=e.get("_snt_uid"))==null?void 0:t.value)!=null?n:null}function Ie(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return`evt-${Date.now()}-${Math.random().toString(16).slice(2)}`}var K={track:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),getGraph:()=>({pageNodes:[],userEdges:[],capturedAt:0}),destroy:()=>{}};function Ee(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,o]of t)n.startsWith("utm_")&&(e[n]=o);return e}catch(e){return{}}}function we(e){return e.replace(/\/events\/?$/,"")}function Pe(e){var S,D,T,h;if(typeof window=="undefined"||e.consent===!1)return K;if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),K;if(!e.ingestUrl)return console.warn("[sentient] init() called without ingestUrl. SDK disabled."),K;let t=Date.now(),n=W(),o=q(),r=Y({ingestUrl:e.ingestUrl,apiKey:e.apiKey}),a=we(e.ingestUrl),s={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},i=P((S=navigator.userAgent)!=null?S:""),u=typeof window!="undefined"?window.location.origin:void 0,m=$((D=document.referrer)!=null?D:"",u),d=(T=e.sessionSegment)!=null?T:`${i}:${m}`;if(e.initialAssignments)for(let[g,f]of Object.entries(e.initialAssignments))o.set(g,d,{variantId:f,assignedAt:Date.now(),segment:d,confidence:1});let p=Promise.resolve(),I=n.getSessionId();if(I){let g=L((h=document.referrer)!=null?h:""),f={sessionId:I,deviceClass:i,trafficSource:m,referrerDomain:g,utmParams:Ee(),timeOfDay:M(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral()};try{p=fetch(`${a}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(f),headers:s}).then(()=>{}).catch(()=>{})}catch(v){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let y={track(g){let f=n.getSessionId();if(!f)return;let v=j(J({},g),{id:Ie(),sessionId:f,timestamp:Date.now(),timeInSession:Date.now()-t});r.push(v),e.debug&&console.log("[sentient] track",v)},getAssignment(g,f){return o.get(g,f)},async assign(g,f){let v=n.getSessionId();if(!v)return null;let k=o.get(g,d);if(k)return{variantId:k.variantId,assignmentTtlMs:0};await p;try{let A=await fetch(`${a}/assign`,{method:"POST",body:JSON.stringify({sessionId:v,componentId:g,variantIds:f}),headers:s});if(!A.ok)return null;let x=await A.json();return o.set(g,d,{variantId:x.variantId,assignedAt:Date.now(),segment:d,confidence:1}),x}catch(A){return null}},getGraph(){return{pageNodes:[],userEdges:[],capturedAt:0}},destroy(){r.destroy(),n.destroy(),e.debug&&console.log("[sentient] destroyed")}};if(e.debug){let g=window;g.__sentient&&(g.__sentient.client=y)}return y}export{J as a,j as b,P as c,$ as d,L as e,M as f,Se as g,he as h,ve as i,Pe as j};
|
package/dist/index-graph.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty,ie=Object.defineProperties,ae=Object.getOwnPropertyDescriptor,ce=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertyNames,q=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var H=(e,t,n)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,I=(e,t)=>{for(var n in t||(t={}))Y.call(t,n)&&H(e,n,t[n]);if(q)for(var n of q(t))ue.call(t,n)&&H(e,n,t[n]);return e},U=(e,t)=>ie(e,ce(t));var ge=(e,t)=>{for(var n in t)k(e,n,{get:t[n],enumerable:!0})},le=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of de(t))!Y.call(e,s)&&s!==n&&k(e,s,{get:()=>t[s],enumerable:!(c=ae(t,s))||c.enumerable});return e};var pe=e=>le(k({},"__esModule",{value:!0}),e);var Ye={};ge(Ye,{deriveSessionSegment:()=>K,detectDeviceClass:()=>C,detectTimeOfDay:()=>_,detectTrafficSource:()=>x,init:()=>He,preloadAssignments:()=>F,readSessionCookie:()=>j,referrerDomainFromReferer:()=>T});module.exports=pe(Ye);var me="_snt_uid";var A="_snt_uid";function fe(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function he(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ye(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(c){}}function Se(e){try{return localStorage.getItem(e)}catch(t){return null}}function ve(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function be(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function we(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Ee(e){try{sessionStorage.removeItem(e)}catch(t){}}function Ie(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function Ae(e){try{localStorage.removeItem(e)}catch(t){}}function Ce(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var xe={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function V(e){var d,u,l,h,y;if(typeof window=="undefined")return xe;let t=(d=e==null?void 0:e.cookieName)!=null?d:me,c=((u=e==null?void 0:e.cookieTTLDays)!=null?u:365)*24*60*60,s=(y=(h=(l=he(t))!=null?l:Se(A))!=null?h:be(A))!=null?y:fe();ye(t,s,c);let r=ve(A,s),o=Ie(t),i=r?!1:we(A,s),a=!r&&!o&&!i;return{getSessionId:()=>s,isEphemeral:()=>a,destroy:()=>{s=null,Ce(t),Ae(A),Ee(A)}}}var R="_snt_retry";var Te={push:()=>{},flush:()=>{},destroy:()=>{}};function _e(e){try{let t=localStorage.getItem(R);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?(localStorage.removeItem(R),n.slice(-e)):[]}catch(t){return[]}}function Ne(e,t){try{let c=[...(()=>{try{let s=localStorage.getItem(R);if(!s)return[];let r=JSON.parse(s);return Array.isArray(r)?r:[]}catch(s){return[]}})(),...e].slice(-t);localStorage.setItem(R,JSON.stringify(c))}catch(n){}}function X(e){var b,D,E;if(typeof window=="undefined")return Te;let t=(b=e.flushIntervalMs)!=null?b:5e3,n=(D=e.maxBatchSize)!=null?D:20,c=(E=e.maxRetrySize)!=null?E:100,s=e.ingestUrl,r=e.apiKey,o=[],i=new Set,a=[],d=g=>{for(let m of g)i.has(m)||(i.add(m),a.push(m));for(;a.length>500;){let m=a.shift();m&&i.delete(m)}},u=new Set,l=g=>{i.has(g.id)||u.has(g.id)||(u.add(g.id),o.push(g))},h=_e(c);for(let g of h)l(g);let y=g=>{if(g.length===0)return!0;let m=JSON.stringify(g);try{return fetch(s,{method:"POST",keepalive:!0,body:m,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}}),d(g.map(O=>O.id)),!0}catch(O){return Ne(g,c),!1}},S=()=>{try{for(;o.length>0;){let m=o.splice(0,n).filter(oe=>!i.has(oe.id));if(m.length===0)continue;if(!y(m)){o.unshift(...m);break}}}catch(g){}},w=!0,v=null,N=()=>{if(!w)return;let g=Date.now()+t,m=()=>{if(w){if(Date.now()>=g){S(),N();return}try{v=new MessageChannel,v.port1.onmessage=m,v.port2.postMessage(null)}catch(O){}}};m()},p=()=>{document.visibilityState==="hidden"&&S()},f=()=>{S()};return document.addEventListener("visibilitychange",p),window.addEventListener("beforeunload",f),N(),{push(g){l(g),o.length>=n&&S()},flush:S,destroy(){w=!1,document.removeEventListener("visibilitychange",p),window.removeEventListener("beforeunload",f),v&&(v.port1.onmessage=null,v=null),S()}}}var M="_snt_asgn_";function P(e,t){return`${e}:${t}`}function De(e,t){return`${M}${e}_${t}`}function $(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(M)&&e.push(n)}return e}catch(e){return[]}}function Z(e=18e5){let t=new Map,n=s=>s.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let s of $())try{let r=localStorage.getItem(s);if(!r)continue;let o=JSON.parse(r);if(n(o)){localStorage.removeItem(s);continue}let i=s.slice(M.length),a=i.lastIndexOf("_");if(a<0)continue;let d=i.slice(0,a),u=i.slice(a+1);t.set(P(d,u),o)}catch(r){}})(),{get(s,r){let o=t.get(P(s,r));return o?n(o)?(t.delete(P(s,r)),null):o:null},set(s,r,o){let i=P(s,r);t.set(i,o);try{localStorage.setItem(De(s,r),JSON.stringify(o))}catch(a){}},invalidate(s){let r=`${s}:`;for(let o of[...t.keys()])o.startsWith(r)&&t.delete(o);for(let o of $()){let i=o.slice(M.length),a=i.lastIndexOf("_");if(a<0)continue;if(i.slice(0,a)===s)try{localStorage.removeItem(o)}catch(u){}}},clear(){t.clear();for(let s of $())try{localStorage.removeItem(s)}catch(r){}}}}function C(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function x(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(s){}let c=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(c)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(c)?"social":"referral"}catch(n){return"direct"}}function T(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function _(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function K(e){let t=G("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function G(e,t){var r,o,i,a,d,u,l;let n=(o=(r=t==null?void 0:t.userAgent)==null?void 0:r.trim())!=null?o:"",c=(a=(i=t==null?void 0:t.referer)==null?void 0:i.trim())!=null?a:"",s=(d=t==null?void 0:t.now)!=null?d:new Date;return{sessionId:e,ephemeral:!1,utmParams:(u=t==null?void 0:t.utmParams)!=null?u:{},deviceClass:n?C(n):"desktop",trafficSource:c?x(c,t==null?void 0:t.appOrigin):"direct",referrerDomain:T(c),timeOfDay:_(s),dayOfWeek:(l=["sun","mon","tue","wed","thu","fri","sat"][s.getDay()])!=null?l:"sun"}}async function F(e,t,n){let c={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};n.origin&&(c.Origin=n.origin);let s=G(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,appOrigin:n.origin});try{await fetch(`${n.baseUrl}/sessions`,{method:"POST",headers:c,body:JSON.stringify(s)})}catch(i){}let r=await Promise.allSettled(e.map(async({id:i,variantIds:a})=>{let d=await fetch(`${n.baseUrl}/assign`,{method:"POST",headers:c,body:JSON.stringify({sessionId:t,componentId:i,variantIds:a})});if(!d.ok)return null;let u=await d.json();return{id:i,variantId:u.variantId}})),o={};for(let i of r)i.status==="fulfilled"&&i.value&&(o[i.value.id]=i.value.variantId);return o}function j(e){var t,n;return(n=(t=e.get("_snt_uid"))==null?void 0:t.value)!=null?n:null}function Oe(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return`evt-${Date.now()}-${Math.random().toString(16).slice(2)}`}var L={track:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),getGraph:()=>({pageNodes:[],userEdges:[],capturedAt:0}),destroy:()=>{}};function ke(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,c]of t)n.startsWith("utm_")&&(e[n]=c);return e}catch(e){return{}}}function Ue(e){return e.replace(/\/events\/?$/,"")}function ee(e){var S,w,v,N;if(typeof window=="undefined"||e.consent===!1)return L;if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),L;if(!e.ingestUrl)return console.warn("[sentient] init() called without ingestUrl. SDK disabled."),L;let t=Date.now(),n=V(),c=Z(),s=X({ingestUrl:e.ingestUrl,apiKey:e.apiKey}),r=Ue(e.ingestUrl),o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},i=C((S=navigator.userAgent)!=null?S:""),a=typeof window!="undefined"?window.location.origin:void 0,d=x((w=document.referrer)!=null?w:"",a),u=(v=e.sessionSegment)!=null?v:`${i}:${d}`;if(e.initialAssignments)for(let[p,f]of Object.entries(e.initialAssignments))c.set(p,u,{variantId:f,assignedAt:Date.now(),segment:u,confidence:1});let l=Promise.resolve(),h=n.getSessionId();if(h){let p=T((N=document.referrer)!=null?N:""),f={sessionId:h,deviceClass:i,trafficSource:d,referrerDomain:p,utmParams:ke(),timeOfDay:_(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral()};try{l=fetch(`${r}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(f),headers:o}).then(()=>{}).catch(()=>{})}catch(b){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:s});let y={track(p){let f=n.getSessionId();if(!f)return;let b=U(I({},p),{id:Oe(),sessionId:f,timestamp:Date.now(),timeInSession:Date.now()-t});s.push(b),e.debug&&console.log("[sentient] track",b)},getAssignment(p,f){return c.get(p,f)},async assign(p,f){let b=n.getSessionId();if(!b)return null;let D=c.get(p,u);if(D)return{variantId:D.variantId,assignmentTtlMs:0};await l;try{let E=await fetch(`${r}/assign`,{method:"POST",body:JSON.stringify({sessionId:b,componentId:p,variantIds:f}),headers:o});if(!E.ok)return null;let g=await E.json();return c.set(p,u,{variantId:g.variantId,assignedAt:Date.now(),segment:u,confidence:1}),g}catch(E){return null}},getGraph(){return{pageNodes:[],userEdges:[],capturedAt:0}},destroy(){s.destroy(),n.destroy(),e.debug&&console.log("[sentient] destroyed")}};if(e.debug){let p=window;p.__sentient&&(p.__sentient.client=y)}return y}var Re=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Pe="h1, h2, h3",Me={scan:async()=>({nodes:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function z(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Le(e){var t,n,c;try{let s=e;for(let r of Object.keys(s)){if(!r.startsWith("__reactFiber")&&!r.startsWith("__reactInternalInstance"))continue;let o=s[r],i=(c=(t=o==null?void 0:o.type)==null?void 0:t.displayName)!=null?c:(n=o==null?void 0:o.type)==null?void 0:n.name;if(i&&i.length>1)return i}}catch(s){}}function $e(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}function Ke(e){let t=e.getAttribute("data-sentient-type");if(t)return t;let n=e.getAttribute("role");return n||"generic"}function Ge(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function Fe(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function J(e,t){var c,s,r;let n=e.querySelector(Pe);return{componentId:Ge(e),semanticType:Ke(e),ariaLabel:(c=e.getAttribute("aria-label"))!=null?c:void 0,headingText:(r=(s=n==null?void 0:n.textContent)==null?void 0:s.trim())!=null?r:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:Fe(e),reactComponentName:Le(e),dataAttributes:$e(e)}}function je(e){let t=[],n=new Set;return document.querySelectorAll("[data-sentient-id]").forEach(r=>{r instanceof Element&&!n.has(r)&&(n.add(r),t.push(J(r,e)))}),document.querySelectorAll("section, article, main, aside").forEach(r=>{if(!(r instanceof Element)||n.has(r))return;let o=r.hasAttribute("aria-label"),i=r.hasAttribute("data-sentient-id");!o&&!i||(n.add(r),t.push(J(r,e)))}),t}function te(){if(typeof window=="undefined")return Me;let e=null,t=0,n=null,c=i=>{try{let a=window.getComputedStyle(i),d=parseFloat(a.fontSize)||12,u=parseFloat(a.zIndex)||0,l=i.getBoundingClientRect(),h=Math.max(l.top,0),y=window.innerHeight||1,S=1/(h/y+1),w=z(d,12,48)*.4+z(S,0,1)*.4+z(u,0,100)*.2;return Math.max(0,Math.min(1,w))}catch(a){return .5}};return{scan:()=>new Promise(i=>{let a=()=>{i({nodes:je(c),scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(a,{timeout:100}):a()}catch(d){a()}}),observe:i=>{n=i;try{e=new MutationObserver(a=>{let d=[];for(let u of a)u.type==="childList"&&u.addedNodes.forEach(l=>{if(!(l instanceof Element)||!Re.has(l.tagName))return;let h=l.hasAttribute("data-sentient-id"),y=l.hasAttribute("aria-label");!h&&!y||d.push(J(l,c))});d.length>0&&n&&n({nodes:d,addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(a){}},getProminenceScore:c,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(i){}t=0,n=null}}}var Q="_snt_graph_nodes",W="_snt_graph_edges",ze={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function B(e){return Math.max(0,Math.min(1,e))}function Je(e){var t;return(t=ze[e])!=null?t:[]}function ne(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function re(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var Qe=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function We(e){return Qe.has(e)?e:"generic"}function Be(e,t,n){let c=`${e}:${t}:${n.join(",")}`,s=5381;for(let r=0;r<c.length;r++)s=(s<<5)+s+c.charCodeAt(r)&4294967295;return(s>>>0).toString(16).padStart(8,"0")}function se(e){let t=new Map,n=new Map,c=()=>{typeof window!="undefined"&&(re(Q,[...t.values()]),re(W,[...n.values()]))},s=o=>{var i,a;try{let d=JSON.parse(o);t.clear(),n.clear();for(let u of(i=d.pageNodes)!=null?i:[])t.set(u.componentId,u);for(let u of(a=d.userEdges)!=null?a:[])n.set(u.componentId,u)}catch(d){}};if(typeof window!="undefined"){let o=ne(Q,[]),i=ne(W,[]);for(let a of o)t.set(a.componentId,a);for(let a of i)n.set(a.componentId,a)}let r=(o,i)=>{let a=n.get(o);a?(a.attentionWeight=B(a.attentionWeight+i),a.lastUpdated=Date.now()):n.set(o,{componentId:o,attentionWeight:B(i),interactionCount:0,dwellTime:0,lastUpdated:Date.now()})};return{addPageNode(o){t.set(o.componentId,o),c()},syncOnce(){if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let o=[...t.values()];if(o.length!==0)try{let i={pageUrl:window.location.href,nodes:o.map(a=>{let d=We(a.semanticType);return{componentId:a.componentId,semanticType:d,answers:a.answers,contentHash:Be(a.componentId,d,a.answers),prominenceScore:a.prominenceScore,depthInPage:a.depth}}),edges:[]};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:I({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(i)}).catch(()=>{})}catch(i){}},updateUserEdge(o,i){var d;let a=(d=n.get(o))!=null?d:{componentId:o,attentionWeight:0,interactionCount:0,dwellTime:0,lastUpdated:Date.now()};a.attentionWeight=B(a.attentionWeight+i),a.interactionCount+=1,a.lastUpdated=Date.now(),n.set(o,a),c()},propagate(o,i){let a=t.get(o);if(!a){r(o,i),c();return}r(o,i);for(let d of Je(a.semanticType))for(let u of t.values())u.semanticType===d&&u.componentId!==o&&r(u.componentId,i*.4);for(let d of t.values())d.depth===a.depth+1&&r(d.componentId,i*.6);for(let d of t.values())d.semanticType===a.semanticType&&d.componentId!==o&&r(d.componentId,i*-.2);c()},snapshot(){return{pageNodes:[...t.values()],userEdges:[...n.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()],userEdges:[...n.values()]})},restore:s,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(Q),localStorage.removeItem(W)}catch(o){}}}}function qe(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function He(e){let t=ee(e);if(!e.graph||typeof window=="undefined")return t;let n=te(),c=se({syncUrl:e.ingestUrl.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:qe()});try{let s=localStorage.getItem("_snt_graph_nodes"),r=localStorage.getItem("_snt_graph_edges");(s||r)&&c.restore(JSON.stringify({pageNodes:s?JSON.parse(s):[],userEdges:r?JSON.parse(r):[]}))}catch(s){}return n.scan().then(s=>{for(let r of s.nodes)c.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth});c.syncOnce()}),n.observe(s=>{for(let r of s.nodes)c.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth})}),U(I({},t),{getGraph:()=>c.snapshot(),destroy:()=>{n.destroy(),c.destroy(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,preloadAssignments,readSessionCookie,referrerDomainFromReferer});
|
|
1
|
+
"use strict";var M=Object.defineProperty,ge=Object.defineProperties,le=Object.getOwnPropertyDescriptor,pe=Object.getOwnPropertyDescriptors,me=Object.getOwnPropertyNames,ee=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var te=(e,t,n)=>t in e?M(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_=(e,t)=>{for(var n in t||(t={}))ne.call(t,n)&&te(e,n,t[n]);if(ee)for(var n of ee(t))fe.call(t,n)&&te(e,n,t[n]);return e},L=(e,t)=>ge(e,pe(t));var he=(e,t)=>{for(var n in t)M(e,n,{get:t[n],enumerable:!0})},ye=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of me(t))!ne.call(e,s)&&s!==n&&M(e,s,{get:()=>t[s],enumerable:!(c=le(t,s))||c.enumerable});return e};var Se=e=>ye(M({},"__esModule",{value:!0}),e);var et={};he(et,{deriveSessionSegment:()=>J,detectDeviceClass:()=>T,detectTimeOfDay:()=>k,detectTrafficSource:()=>N,init:()=>Ze,preloadAssignments:()=>Q,readSessionCookie:()=>W,referrerDomainFromReferer:()=>D});module.exports=Se(et);var ve="_snt_uid";var x="_snt_uid";function Ee(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function be(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function we(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(c){}}function Ie(e){try{return localStorage.getItem(e)}catch(t){return null}}function Ae(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function Ce(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function _e(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function xe(e){try{sessionStorage.removeItem(e)}catch(t){}}function Te(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function Ne(e){try{localStorage.removeItem(e)}catch(t){}}function De(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var ke={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function re(e){var d,u,l,S,f;if(typeof window=="undefined")return ke;let t=(d=e==null?void 0:e.cookieName)!=null?d:ve,c=((u=e==null?void 0:e.cookieTTLDays)!=null?u:365)*24*60*60,s=(f=(S=(l=be(t))!=null?l:Ie(x))!=null?S:Ce(x))!=null?f:Ee();we(t,s,c);let r=Ae(x,s),o=Te(t),i=r?!1:_e(x,s),a=!r&&!o&&!i;return{getSessionId:()=>s,isEphemeral:()=>a,destroy:()=>{s=null,De(t),Ne(x),xe(x)}}}var $="_snt_retry";var Oe={push:()=>{},flush:()=>{},destroy:()=>{}};function Ue(e){try{let t=localStorage.getItem($);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?(localStorage.removeItem($),n.slice(-e)):[]}catch(t){return[]}}function F(e,t){try{let c=[...(()=>{try{let s=localStorage.getItem($);if(!s)return[];let r=JSON.parse(s);return Array.isArray(r)?r:[]}catch(s){return[]}})(),...e].slice(-t);localStorage.setItem($,JSON.stringify(c))}catch(n){}}function se(e){var A,U,Z;if(typeof window=="undefined")return Oe;let t=(A=e.flushIntervalMs)!=null?A:5e3,n=(U=e.maxBatchSize)!=null?U:20,c=(Z=e.maxRetrySize)!=null?Z:100,s=e.ingestUrl,r=e.apiKey,o=[],i=new Set,a=[],d=g=>{for(let p of g)i.has(p)||(i.add(p),a.push(p));for(;a.length>500;){let p=a.shift();p&&i.delete(p)}},u=new Set,l=g=>{i.has(g.id)||u.has(g.id)||(u.add(g.id),o.push(g))},S=Ue(c);for(let g of S)l(g);let f=0,y=0,I=g=>{if(g.length===0)return;let p=JSON.stringify(g),C=g.map(w=>w.id),b;try{b=fetch(s,{method:"POST",keepalive:!0,body:p,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}})}catch(w){F(g,c),y++,f=Date.now()+Math.min(6e4,1e3*2**Math.min(y,6));return}let R=w=>{if(w.ok||w.status>=400&&w.status<500&&w.status!==429){d(C),y=0,f=0;return}F(g,c),y++,f=Date.now()+Math.min(6e4,1e3*2**Math.min(y,6))};b instanceof Promise?b.then(R).catch(()=>{F(g,c),y++,f=Date.now()+Math.min(6e4,1e3*2**Math.min(y,6))}):R(b)},P=g=>{let p=[],C=2;for(let b of g){let R=JSON.stringify(b).length+1;if(p.length>0&&C+R>57344||p.length>=n)break;p.push(b),C+=R}return p},v=()=>{try{if(Date.now()<f)return;for(;o.length>0;){let g=o.filter(C=>!i.has(C.id));if(o.length=0,g.length===0)break;let p=P(g);if(p.length===0)break;p.length<g.length&&o.push(...g.slice(p.length)),I(p)}}catch(g){}},m=!0,h=null;h=setInterval(()=>{m&&v()},t);let E=()=>{document.visibilityState==="hidden"&&v()},O=()=>{v()};return document.addEventListener("visibilitychange",E),window.addEventListener("beforeunload",O),{push(g){l(g),o.length>=n&&v()},flush:v,destroy(){m=!1,h!==null&&(clearInterval(h),h=null),document.removeEventListener("visibilitychange",E),window.removeEventListener("beforeunload",O),v()}}}var G="_snt_asgn_";function K(e,t){return`${e}:${t}`}function Re(e,t){return`${G}${e}_${t}`}function z(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(G)&&e.push(n)}return e}catch(e){return[]}}function oe(e=18e5){let t=new Map,n=s=>s.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let s of z())try{let r=localStorage.getItem(s);if(!r)continue;let o=JSON.parse(r);if(n(o)){localStorage.removeItem(s);continue}let i=s.slice(G.length),a=i.lastIndexOf("_");if(a<0)continue;let d=i.slice(0,a),u=i.slice(a+1);t.set(K(d,u),o)}catch(r){}})(),{get(s,r){let o=t.get(K(s,r));return o?n(o)?(t.delete(K(s,r)),null):o:null},set(s,r,o){let i=K(s,r);t.set(i,o);try{localStorage.setItem(Re(s,r),JSON.stringify(o))}catch(a){}},invalidate(s){let r=`${s}:`;for(let o of[...t.keys()])o.startsWith(r)&&t.delete(o);for(let o of z()){let i=o.slice(G.length),a=i.lastIndexOf("_");if(a<0)continue;if(i.slice(0,a)===s)try{localStorage.removeItem(o)}catch(u){}}},clear(){t.clear();for(let s of z())try{localStorage.removeItem(s)}catch(r){}}}}function T(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function N(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(s){}let c=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(c)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(c)?"social":"referral"}catch(n){return"direct"}}function D(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function k(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function J(e){let t=j("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function j(e,t){var r,o,i,a,d,u,l;let n=(o=(r=t==null?void 0:t.userAgent)==null?void 0:r.trim())!=null?o:"",c=(a=(i=t==null?void 0:t.referer)==null?void 0:i.trim())!=null?a:"",s=(d=t==null?void 0:t.now)!=null?d:new Date;return{sessionId:e,ephemeral:!1,utmParams:(u=t==null?void 0:t.utmParams)!=null?u:{},deviceClass:n?T(n):"desktop",trafficSource:c?N(c,t==null?void 0:t.appOrigin):"direct",referrerDomain:D(c),timeOfDay:k(s),dayOfWeek:(l=["sun","mon","tue","wed","thu","fri","sat"][s.getDay()])!=null?l:"sun"}}async function Q(e,t,n){let c={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};n.origin&&(c.Origin=n.origin);let s=j(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,appOrigin:n.origin});try{await fetch(`${n.baseUrl}/sessions`,{method:"POST",headers:c,body:JSON.stringify(s)})}catch(i){}let r=await Promise.allSettled(e.map(async({id:i,variantIds:a})=>{let d=await fetch(`${n.baseUrl}/assign`,{method:"POST",headers:c,body:JSON.stringify({sessionId:t,componentId:i,variantIds:a})});if(!d.ok)return null;let u=await d.json();return{id:i,variantId:u.variantId}})),o={};for(let i of r)i.status==="fulfilled"&&i.value&&(o[i.value.id]=i.value.variantId);return o}function W(e){var t,n;return(n=(t=e.get("_snt_uid"))==null?void 0:t.value)!=null?n:null}function Pe(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return`evt-${Date.now()}-${Math.random().toString(16).slice(2)}`}var B={track:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),getGraph:()=>({pageNodes:[],userEdges:[],capturedAt:0}),destroy:()=>{}};function Me(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,c]of t)n.startsWith("utm_")&&(e[n]=c);return e}catch(e){return{}}}function Le(e){return e.replace(/\/events\/?$/,"")}function ie(e){var y,I,P,v;if(typeof window=="undefined"||e.consent===!1)return B;if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),B;if(!e.ingestUrl)return console.warn("[sentient] init() called without ingestUrl. SDK disabled."),B;let t=Date.now(),n=re(),c=oe(),s=se({ingestUrl:e.ingestUrl,apiKey:e.apiKey}),r=Le(e.ingestUrl),o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},i=T((y=navigator.userAgent)!=null?y:""),a=typeof window!="undefined"?window.location.origin:void 0,d=N((I=document.referrer)!=null?I:"",a),u=(P=e.sessionSegment)!=null?P:`${i}:${d}`;if(e.initialAssignments)for(let[m,h]of Object.entries(e.initialAssignments))c.set(m,u,{variantId:h,assignedAt:Date.now(),segment:u,confidence:1});let l=Promise.resolve(),S=n.getSessionId();if(S){let m=D((v=document.referrer)!=null?v:""),h={sessionId:S,deviceClass:i,trafficSource:d,referrerDomain:m,utmParams:Me(),timeOfDay:k(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral()};try{l=fetch(`${r}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(h),headers:o}).then(()=>{}).catch(()=>{})}catch(E){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:s});let f={track(m){let h=n.getSessionId();if(!h)return;let E=L(_({},m),{id:Pe(),sessionId:h,timestamp:Date.now(),timeInSession:Date.now()-t});s.push(E),e.debug&&console.log("[sentient] track",E)},getAssignment(m,h){return c.get(m,h)},async assign(m,h){let E=n.getSessionId();if(!E)return null;let O=c.get(m,u);if(O)return{variantId:O.variantId,assignmentTtlMs:0};await l;try{let A=await fetch(`${r}/assign`,{method:"POST",body:JSON.stringify({sessionId:E,componentId:m,variantIds:h}),headers:o});if(!A.ok)return null;let U=await A.json();return c.set(m,u,{variantId:U.variantId,assignedAt:Date.now(),segment:u,confidence:1}),U}catch(A){return null}},getGraph(){return{pageNodes:[],userEdges:[],capturedAt:0}},destroy(){s.destroy(),n.destroy(),e.debug&&console.log("[sentient] destroyed")}};if(e.debug){let m=window;m.__sentient&&(m.__sentient.client=f)}return f}var $e=new Set(["SECTION","ARTICLE","MAIN","DIV"]),Ke="h1, h2, h3",Ge={scan:async()=>({nodes:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function q(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function Be(e){var t,n,c;try{let s=e;for(let r of Object.keys(s)){if(!r.startsWith("__reactFiber")&&!r.startsWith("__reactInternalInstance"))continue;let o=s[r],i=(c=(t=o==null?void 0:o.type)==null?void 0:t.displayName)!=null?c:(n=o==null?void 0:o.type)==null?void 0:n.name;if(i&&i.length>1)return i}}catch(s){}}function Fe(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}function ze(e){let t=e.getAttribute("data-sentient-type");if(t)return t;let n=e.getAttribute("role");return n||"generic"}function Je(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function je(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function Y(e,t){var c,s,r;let n=e.querySelector(Ke);return{componentId:Je(e),semanticType:ze(e),ariaLabel:(c=e.getAttribute("aria-label"))!=null?c:void 0,headingText:(r=(s=n==null?void 0:n.textContent)==null?void 0:s.trim())!=null?r:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:je(e),reactComponentName:Be(e),dataAttributes:Fe(e)}}function Qe(e){let t=[],n=new Set;return document.querySelectorAll("[data-sentient-id]").forEach(r=>{r instanceof Element&&!n.has(r)&&(n.add(r),t.push(Y(r,e)))}),document.querySelectorAll("section, article, main, aside").forEach(r=>{if(!(r instanceof Element)||n.has(r))return;let o=r.hasAttribute("aria-label"),i=r.hasAttribute("data-sentient-id");!o&&!i||(n.add(r),t.push(Y(r,e)))}),t}function ae(){if(typeof window=="undefined")return Ge;let e=null,t=0,n=null,c=i=>{try{let a=window.getComputedStyle(i),d=parseFloat(a.fontSize)||12,u=parseFloat(a.zIndex)||0,l=i.getBoundingClientRect(),S=Math.max(l.top,0),f=window.innerHeight||1,y=1/(S/f+1),I=q(d,12,48)*.4+q(y,0,1)*.4+q(u,0,100)*.2;return Math.max(0,Math.min(1,I))}catch(a){return .5}};return{scan:()=>new Promise(i=>{let a=()=>{i({nodes:Qe(c),scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(a,{timeout:100}):a()}catch(d){a()}}),observe:i=>{n=i;try{e=new MutationObserver(a=>{let d=[];for(let u of a)u.type==="childList"&&u.addedNodes.forEach(l=>{if(!(l instanceof Element)||!$e.has(l.tagName))return;let S=l.hasAttribute("data-sentient-id"),f=l.hasAttribute("aria-label");!S&&!f||d.push(Y(l,c))});d.length>0&&n&&n({nodes:d,addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(a){}},getProminenceScore:c,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(i){}t=0,n=null}}}var H="_snt_graph_nodes",V="_snt_graph_edges",We={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function X(e){return Math.max(0,Math.min(1,e))}function qe(e){var t;return(t=We[e])!=null?t:[]}function ce(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function de(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var Ye=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function He(e){return Ye.has(e)?e:"generic"}function Ve(e,t,n){let c=`${e}:${t}:${n.join(",")}`,s=5381;for(let r=0;r<c.length;r++)s=(s<<5)+s+c.charCodeAt(r)&4294967295;return(s>>>0).toString(16).padStart(8,"0")}function ue(e){let t=new Map,n=new Map,c=()=>{typeof window!="undefined"&&(de(H,[...t.values()]),de(V,[...n.values()]))},s=o=>{var i,a;try{let d=JSON.parse(o);t.clear(),n.clear();for(let u of(i=d.pageNodes)!=null?i:[])t.set(u.componentId,u);for(let u of(a=d.userEdges)!=null?a:[])n.set(u.componentId,u)}catch(d){}};if(typeof window!="undefined"){let o=ce(H,[]),i=ce(V,[]);for(let a of o)t.set(a.componentId,a);for(let a of i)n.set(a.componentId,a)}let r=(o,i)=>{let a=n.get(o);a?(a.attentionWeight=X(a.attentionWeight+i),a.lastUpdated=Date.now()):n.set(o,{componentId:o,attentionWeight:X(i),interactionCount:0,dwellTime:0,lastUpdated:Date.now()})};return{addPageNode(o){t.set(o.componentId,o),c()},syncOnce(){if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let o=[...t.values()];if(o.length!==0)try{let i={pageUrl:window.location.href,nodes:o.map(a=>{let d=He(a.semanticType);return{componentId:a.componentId,semanticType:d,answers:a.answers,contentHash:Ve(a.componentId,d,a.answers),prominenceScore:a.prominenceScore,depthInPage:a.depth}}),edges:[]};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:_({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(i)}).catch(()=>{})}catch(i){}},updateUserEdge(o,i){var d;let a=(d=n.get(o))!=null?d:{componentId:o,attentionWeight:0,interactionCount:0,dwellTime:0,lastUpdated:Date.now()};a.attentionWeight=X(a.attentionWeight+i),a.interactionCount+=1,a.lastUpdated=Date.now(),n.set(o,a),c()},propagate(o,i){let a=t.get(o);if(!a){r(o,i),c();return}r(o,i);for(let d of qe(a.semanticType))for(let u of t.values())u.semanticType===d&&u.componentId!==o&&r(u.componentId,i*.4);for(let d of t.values())d.depth===a.depth+1&&r(d.componentId,i*.6);for(let d of t.values())d.semanticType===a.semanticType&&d.componentId!==o&&r(d.componentId,i*-.2);c()},snapshot(){return{pageNodes:[...t.values()],userEdges:[...n.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()],userEdges:[...n.values()]})},restore:s,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(H),localStorage.removeItem(V)}catch(o){}}}}function Xe(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function Ze(e){let t=ie(e);if(!e.graph||typeof window=="undefined")return t;let n=ae(),c=ue({syncUrl:e.ingestUrl.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:Xe()});try{let s=localStorage.getItem("_snt_graph_nodes"),r=localStorage.getItem("_snt_graph_edges");(s||r)&&c.restore(JSON.stringify({pageNodes:s?JSON.parse(s):[],userEdges:r?JSON.parse(r):[]}))}catch(s){}return n.scan().then(s=>{for(let r of s.nodes)c.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth});c.syncOnce()}),n.observe(s=>{for(let r of s.nodes)c.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth})}),L(_({},t),{getGraph:()=>c.snapshot(),destroy:()=>{n.destroy(),c.destroy(),t.destroy()}})}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,preloadAssignments,readSessionCookie,referrerDomainFromReferer});
|
package/dist/index-graph.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as g,b,c as x,d as O,e as _,f as U,g as D,h as R,i as P,j as E}from"./chunk-
|
|
1
|
+
import{a as g,b,c as x,d as O,e as _,f as U,g as D,h as R,i as P,j as E}from"./chunk-2K7NAMTI.mjs";var M=new Set(["SECTION","ARTICLE","MAIN","DIV"]),G="h1, h2, h3",k={scan:async()=>({nodes:[],scannedAt:0}),observe:()=>{},getProminenceScore:()=>0,destroy:()=>{}};function f(e,t,n){return n<=t?0:Math.max(0,Math.min(1,(e-t)/(n-t)))}function j(e){var t,n,i;try{let c=e;for(let r of Object.keys(c)){if(!r.startsWith("__reactFiber")&&!r.startsWith("__reactInternalInstance"))continue;let s=c[r],a=(i=(t=s==null?void 0:s.type)==null?void 0:t.displayName)!=null?i:(n=s==null?void 0:s.type)==null?void 0:n.name;if(a&&a.length>1)return a}}catch(c){}}function W(e){let t={};for(let n of Array.from(e.attributes))n.name.startsWith("data-")&&(t[n.name]=n.value);return t}function F(e){let t=e.getAttribute("data-sentient-type");if(t)return t;let n=e.getAttribute("role");return n||"generic"}function L(e){var t,n;return(n=(t=e.getAttribute("data-sentient-id"))!=null?t:e.getAttribute("id"))!=null?n:e.tagName.toLowerCase()}function q(e){let t=0,n=e.parentElement;for(;n;)t++,n=n.parentElement;return t}function h(e,t){var i,c,r;let n=e.querySelector(G);return{componentId:L(e),semanticType:F(e),ariaLabel:(i=e.getAttribute("aria-label"))!=null?i:void 0,headingText:(r=(c=n==null?void 0:n.textContent)==null?void 0:c.trim())!=null?r:void 0,isAboveFold:e.getBoundingClientRect().top<window.innerHeight,prominenceScore:t(e),depth:q(e),reactComponentName:j(e),dataAttributes:W(e)}}function z(e){let t=[],n=new Set;return document.querySelectorAll("[data-sentient-id]").forEach(r=>{r instanceof Element&&!n.has(r)&&(n.add(r),t.push(h(r,e)))}),document.querySelectorAll("section, article, main, aside").forEach(r=>{if(!(r instanceof Element)||n.has(r))return;let s=r.hasAttribute("aria-label"),a=r.hasAttribute("data-sentient-id");!s&&!a||(n.add(r),t.push(h(r,e)))}),t}function C(){if(typeof window=="undefined")return k;let e=null,t=0,n=null,i=a=>{try{let o=window.getComputedStyle(a),d=parseFloat(o.fontSize)||12,p=parseFloat(o.zIndex)||0,u=a.getBoundingClientRect(),l=Math.max(u.top,0),m=window.innerHeight||1,A=1/(l/m+1),T=f(d,12,48)*.4+f(A,0,1)*.4+f(p,0,100)*.2;return Math.max(0,Math.min(1,T))}catch(o){return .5}};return{scan:()=>new Promise(a=>{let o=()=>{a({nodes:z(i),scannedAt:Date.now()})};try{typeof requestIdleCallback=="function"?t=requestIdleCallback(o,{timeout:100}):o()}catch(d){o()}}),observe:a=>{n=a;try{e=new MutationObserver(o=>{let d=[];for(let p of o)p.type==="childList"&&p.addedNodes.forEach(u=>{if(!(u instanceof Element)||!M.has(u.tagName))return;let l=u.hasAttribute("data-sentient-id"),m=u.hasAttribute("aria-label");!l&&!m||d.push(h(u,i))});d.length>0&&n&&n({nodes:d,addedAt:Date.now()})}),e.observe(document.body,{childList:!0,subtree:!0})}catch(o){}},getProminenceScore:i,destroy:()=>{if(e&&(e.disconnect(),e=null),t&&typeof cancelIdleCallback=="function")try{cancelIdleCallback(t)}catch(a){}t=0,n=null}}}var y="_snt_graph_nodes",S="_snt_graph_edges",J={pricing:["features","faq"],features:["pricing"],faq:["pricing"],social_proof:["cta"],cta:["social_proof","hero","trust"],hero:["cta"],comparison:["pricing"],trust:["cta"]};function v(e){return Math.max(0,Math.min(1,e))}function K(e){var t;return(t=J[e])!=null?t:[]}function N(e,t){try{let n=localStorage.getItem(e);return n?JSON.parse(n):t}catch(n){return t}}function w(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){}}var H=new Set(["pricing","hero","social_proof","cta","features","faq","comparison","trust","navigation","generic"]);function B(e){return H.has(e)?e:"generic"}function $(e,t,n){let i=`${e}:${t}:${n.join(",")}`,c=5381;for(let r=0;r<i.length;r++)c=(c<<5)+c+i.charCodeAt(r)&4294967295;return(c>>>0).toString(16).padStart(8,"0")}function I(e){let t=new Map,n=new Map,i=()=>{typeof window!="undefined"&&(w(y,[...t.values()]),w(S,[...n.values()]))},c=s=>{var a,o;try{let d=JSON.parse(s);t.clear(),n.clear();for(let p of(a=d.pageNodes)!=null?a:[])t.set(p.componentId,p);for(let p of(o=d.userEdges)!=null?o:[])n.set(p.componentId,p)}catch(d){}};if(typeof window!="undefined"){let s=N(y,[]),a=N(S,[]);for(let o of s)t.set(o.componentId,o);for(let o of a)n.set(o.componentId,o)}let r=(s,a)=>{let o=n.get(s);o?(o.attentionWeight=v(o.attentionWeight+a),o.lastUpdated=Date.now()):n.set(s,{componentId:s,attentionWeight:v(a),interactionCount:0,dwellTime:0,lastUpdated:Date.now()})};return{addPageNode(s){t.set(s.componentId,s),i()},syncOnce(){if(!(e!=null&&e.syncUrl)||typeof window=="undefined")return;let s=[...t.values()];if(s.length!==0)try{let a={pageUrl:window.location.href,nodes:s.map(o=>{let d=B(o.semanticType);return{componentId:o.componentId,semanticType:d,answers:o.answers,contentHash:$(o.componentId,d,o.answers),prominenceScore:o.prominenceScore,depthInPage:o.depth}}),edges:[]};fetch(e.syncUrl,{method:"POST",keepalive:!0,headers:g({"Content-Type":"application/json"},e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{}),body:JSON.stringify(a)}).catch(()=>{})}catch(a){}},updateUserEdge(s,a){var d;let o=(d=n.get(s))!=null?d:{componentId:s,attentionWeight:0,interactionCount:0,dwellTime:0,lastUpdated:Date.now()};o.attentionWeight=v(o.attentionWeight+a),o.interactionCount+=1,o.lastUpdated=Date.now(),n.set(s,o),i()},propagate(s,a){let o=t.get(s);if(!o){r(s,a),i();return}r(s,a);for(let d of K(o.semanticType))for(let p of t.values())p.semanticType===d&&p.componentId!==s&&r(p.componentId,a*.4);for(let d of t.values())d.depth===o.depth+1&&r(d.componentId,a*.6);for(let d of t.values())d.semanticType===o.semanticType&&d.componentId!==s&&r(d.componentId,a*-.2);i()},snapshot(){return{pageNodes:[...t.values()],userEdges:[...n.values()],capturedAt:Date.now()}},serialize(){return JSON.stringify({pageNodes:[...t.values()],userEdges:[...n.values()]})},restore:c,destroy(){if(typeof window!="undefined")try{localStorage.removeItem(y),localStorage.removeItem(S)}catch(s){}}}}function V(){try{let e=document.cookie.match(/(?:^|; )_snt_uid=([^;]*)/);return e?decodeURIComponent(e[1]):void 0}catch(e){return}}function ne(e){let t=E(e);if(!e.graph||typeof window=="undefined")return t;let n=C(),i=I({syncUrl:e.ingestUrl.replace(/\/events\/?$/,"/graph/sync"),apiKey:e.apiKey,projectId:e.apiKey,sessionId:V()});try{let c=localStorage.getItem("_snt_graph_nodes"),r=localStorage.getItem("_snt_graph_edges");(c||r)&&i.restore(JSON.stringify({pageNodes:c?JSON.parse(c):[],userEdges:r?JSON.parse(r):[]}))}catch(c){}return n.scan().then(c=>{for(let r of c.nodes)i.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth});i.syncOnce()}),n.observe(c=>{for(let r of c.nodes)i.addPageNode({id:r.componentId,componentId:r.componentId,semanticType:r.semanticType,answers:r.headingText?[r.headingText]:[],prominenceScore:r.prominenceScore,depth:r.depth})}),b(g({},t),{getGraph:()=>i.snapshot(),destroy:()=>{n.destroy(),i.destroy(),t.destroy()}})}export{D as deriveSessionSegment,x as detectDeviceClass,U as detectTimeOfDay,O as detectTrafficSource,ne as init,R as preloadAssignments,P as readSessionCookie,_ as referrerDomainFromReferer};
|
package/dist/index.d.cts
CHANGED
|
@@ -10,7 +10,7 @@ type SessionManager = {
|
|
|
10
10
|
destroy(): void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
/** Batched event queue with reliable transport (
|
|
13
|
+
/** Batched event queue with reliable transport (fetch + keepalive, localStorage retry). */
|
|
14
14
|
type EventType = 'variant_assigned' | 'goal_achieved' | 'scroll_depth' | 'dwell' | 'cursor_signal' | 'component_visible' | 'component_exited';
|
|
15
15
|
type SentientEvent = {
|
|
16
16
|
id: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ type SessionManager = {
|
|
|
10
10
|
destroy(): void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
/** Batched event queue with reliable transport (
|
|
13
|
+
/** Batched event queue with reliable transport (fetch + keepalive, localStorage retry). */
|
|
14
14
|
type EventType = 'variant_assigned' | 'goal_achieved' | 'scroll_depth' | 'dwell' | 'cursor_signal' | 'component_visible' | 'component_exited';
|
|
15
15
|
type SentientEvent = {
|
|
16
16
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var O=Object.defineProperty,X=Object.defineProperties,H=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertyNames,K=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var N=(e,t,n)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,F=(e,t)=>{for(var n in t||(t={}))Q.call(t,n)&&N(e,n,t[n]);if(K)for(var n of K(t))ee.call(t,n)&&N(e,n,t[n]);return e},G=(e,t)=>X(e,V(t));var te=(e,t)=>{for(var n in t)O(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Z(t))!Q.call(e,r)&&r!==n&&O(e,r,{get:()=>t[r],enumerable:!(o=H(t,r))||o.enumerable});return e};var re=e=>ne(O({},"__esModule",{value:!0}),e);var _e={};te(_e,{deriveSessionSegment:()=>j,detectDeviceClass:()=>k,detectTimeOfDay:()=>D,detectTrafficSource:()=>C,init:()=>Ee,preloadAssignments:()=>W,readSessionCookie:()=>Y,referrerDomainFromReferer:()=>x});module.exports=re(_e);var se="_snt_uid";var b="_snt_uid";function ie(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function oe(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ae(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(o){}}function ce(e){try{return localStorage.getItem(e)}catch(t){return null}}function ue(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function de(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function le(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function ge(e){try{sessionStorage.removeItem(e)}catch(t){}}function me(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function fe(e){try{localStorage.removeItem(e)}catch(t){}}function pe(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var ye={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function B(e){var g,d,p,v,w;if(typeof window=="undefined")return ye;let t=(g=e==null?void 0:e.cookieName)!=null?g:se,o=((d=e==null?void 0:e.cookieTTLDays)!=null?d:365)*24*60*60,r=(w=(v=(p=oe(t))!=null?p:ce(b))!=null?v:de(b))!=null?w:ie();ae(t,r,o);let a=ue(b,r),s=me(t),i=a?!1:le(b,r),u=!a&&!s&&!i;return{getSessionId:()=>r,isEphemeral:()=>u,destroy:()=>{r=null,pe(t),fe(b),ge(b)}}}var U="_snt_retry";var Se={push:()=>{},flush:()=>{},destroy:()=>{}};function he(e){try{let t=localStorage.getItem(U);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?(localStorage.removeItem(U),n.slice(-e)):[]}catch(t){return[]}}function ve(e,t){try{let o=[...(()=>{try{let r=localStorage.getItem(U);if(!r)return[];let a=JSON.parse(r);return Array.isArray(a)?a:[]}catch(r){return[]}})(),...e].slice(-t);localStorage.setItem(U,JSON.stringify(o))}catch(n){}}function z(e){var h,_,I;if(typeof window=="undefined")return Se;let t=(h=e.flushIntervalMs)!=null?h:5e3,n=(_=e.maxBatchSize)!=null?_:20,o=(I=e.maxRetrySize)!=null?I:100,r=e.ingestUrl,a=e.apiKey,s=[],i=new Set,u=[],g=c=>{for(let m of c)i.has(m)||(i.add(m),u.push(m));for(;u.length>500;){let m=u.shift();m&&i.delete(m)}},d=new Set,p=c=>{i.has(c.id)||d.has(c.id)||(d.add(c.id),s.push(c))},v=he(o);for(let c of v)p(c);let w=c=>{if(c.length===0)return!0;let m=JSON.stringify(c);try{return fetch(r,{method:"POST",keepalive:!0,body:m,headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}}),g(c.map(T=>T.id)),!0}catch(T){return ve(c,o),!1}},y=()=>{try{for(;s.length>0;){let m=s.splice(0,n).filter(q=>!i.has(q.id));if(m.length===0)continue;if(!w(m)){s.unshift(...m);break}}}catch(c){}},A=!0,S=null,E=()=>{if(!A)return;let c=Date.now()+t,m=()=>{if(A){if(Date.now()>=c){y(),E();return}try{S=new MessageChannel,S.port1.onmessage=m,S.port2.postMessage(null)}catch(T){}}};m()},l=()=>{document.visibilityState==="hidden"&&y()},f=()=>{y()};return document.addEventListener("visibilitychange",l),window.addEventListener("beforeunload",f),E(),{push(c){p(c),s.length>=n&&y()},flush:y,destroy(){A=!1,document.removeEventListener("visibilitychange",l),window.removeEventListener("beforeunload",f),S&&(S.port1.onmessage=null,S=null),y()}}}var $="_snt_asgn_";function R(e,t){return`${e}:${t}`}function we(e,t){return`${$}${e}_${t}`}function L(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith($)&&e.push(n)}return e}catch(e){return[]}}function J(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of L())try{let a=localStorage.getItem(r);if(!a)continue;let s=JSON.parse(a);if(n(s)){localStorage.removeItem(r);continue}let i=r.slice($.length),u=i.lastIndexOf("_");if(u<0)continue;let g=i.slice(0,u),d=i.slice(u+1);t.set(R(g,d),s)}catch(a){}})(),{get(r,a){let s=t.get(R(r,a));return s?n(s)?(t.delete(R(r,a)),null):s:null},set(r,a,s){let i=R(r,a);t.set(i,s);try{localStorage.setItem(we(r,a),JSON.stringify(s))}catch(u){}},invalidate(r){let a=`${r}:`;for(let s of[...t.keys()])s.startsWith(a)&&t.delete(s);for(let s of L()){let i=s.slice($.length),u=i.lastIndexOf("_");if(u<0)continue;if(i.slice(0,u)===r)try{localStorage.removeItem(s)}catch(d){}}},clear(){t.clear();for(let r of L())try{localStorage.removeItem(r)}catch(a){}}}}function k(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function C(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(r){}let o=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(o)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(o)?"social":"referral"}catch(n){return"direct"}}function x(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function D(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function j(e){let t=M("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function M(e,t){var a,s,i,u,g,d,p;let n=(s=(a=t==null?void 0:t.userAgent)==null?void 0:a.trim())!=null?s:"",o=(u=(i=t==null?void 0:t.referer)==null?void 0:i.trim())!=null?u:"",r=(g=t==null?void 0:t.now)!=null?g:new Date;return{sessionId:e,ephemeral:!1,utmParams:(d=t==null?void 0:t.utmParams)!=null?d:{},deviceClass:n?k(n):"desktop",trafficSource:o?C(o,t==null?void 0:t.appOrigin):"direct",referrerDomain:x(o),timeOfDay:D(r),dayOfWeek:(p=["sun","mon","tue","wed","thu","fri","sat"][r.getDay()])!=null?p:"sun"}}async function W(e,t,n){let o={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};n.origin&&(o.Origin=n.origin);let r=M(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,appOrigin:n.origin});try{await fetch(`${n.baseUrl}/sessions`,{method:"POST",headers:o,body:JSON.stringify(r)})}catch(i){}let a=await Promise.allSettled(e.map(async({id:i,variantIds:u})=>{let g=await fetch(`${n.baseUrl}/assign`,{method:"POST",headers:o,body:JSON.stringify({sessionId:t,componentId:i,variantIds:u})});if(!g.ok)return null;let d=await g.json();return{id:i,variantId:d.variantId}})),s={};for(let i of a)i.status==="fulfilled"&&i.value&&(s[i.value.id]=i.value.variantId);return s}function Y(e){var t,n;return(n=(t=e.get("_snt_uid"))==null?void 0:t.value)!=null?n:null}function Ae(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return`evt-${Date.now()}-${Math.random().toString(16).slice(2)}`}var P={track:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),getGraph:()=>({pageNodes:[],userEdges:[],capturedAt:0}),destroy:()=>{}};function Ie(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,o]of t)n.startsWith("utm_")&&(e[n]=o);return e}catch(e){return{}}}function be(e){return e.replace(/\/events\/?$/,"")}function Ee(e){var y,A,S,E;if(typeof window=="undefined"||e.consent===!1)return P;if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),P;if(!e.ingestUrl)return console.warn("[sentient] init() called without ingestUrl. SDK disabled."),P;let t=Date.now(),n=B(),o=J(),r=z({ingestUrl:e.ingestUrl,apiKey:e.apiKey}),a=be(e.ingestUrl),s={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},i=k((y=navigator.userAgent)!=null?y:""),u=typeof window!="undefined"?window.location.origin:void 0,g=C((A=document.referrer)!=null?A:"",u),d=(S=e.sessionSegment)!=null?S:`${i}:${g}`;if(e.initialAssignments)for(let[l,f]of Object.entries(e.initialAssignments))o.set(l,d,{variantId:f,assignedAt:Date.now(),segment:d,confidence:1});let p=Promise.resolve(),v=n.getSessionId();if(v){let l=x((E=document.referrer)!=null?E:""),f={sessionId:v,deviceClass:i,trafficSource:g,referrerDomain:l,utmParams:Ie(),timeOfDay:D(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral()};try{p=fetch(`${a}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(f),headers:s}).then(()=>{}).catch(()=>{})}catch(h){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let w={track(l){let f=n.getSessionId();if(!f)return;let h=G(F({},l),{id:Ae(),sessionId:f,timestamp:Date.now(),timeInSession:Date.now()-t});r.push(h),e.debug&&console.log("[sentient] track",h)},getAssignment(l,f){return o.get(l,f)},async assign(l,f){let h=n.getSessionId();if(!h)return null;let _=o.get(l,d);if(_)return{variantId:_.variantId,assignmentTtlMs:0};await p;try{let I=await fetch(`${a}/assign`,{method:"POST",body:JSON.stringify({sessionId:h,componentId:l,variantIds:f}),headers:s});if(!I.ok)return null;let c=await I.json();return o.set(l,d,{variantId:c.variantId,assignedAt:Date.now(),segment:d,confidence:1}),c}catch(I){return null}},getGraph(){return{pageNodes:[],userEdges:[],capturedAt:0}},destroy(){r.destroy(),n.destroy(),e.debug&&console.log("[sentient] destroyed")}};if(e.debug){let l=window;l.__sentient&&(l.__sentient.client=w)}return w}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,preloadAssignments,readSessionCookie,referrerDomainFromReferer});
|
|
1
|
+
"use strict";var $=Object.defineProperty,te=Object.defineProperties,ne=Object.getOwnPropertyDescriptor,re=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var J=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,W=(e,t)=>{for(var n in t||(t={}))j.call(t,n)&&J(e,n,t[n]);if(z)for(var n of z(t))ie.call(t,n)&&J(e,n,t[n]);return e},Y=(e,t)=>te(e,re(t));var oe=(e,t)=>{for(var n in t)$(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of se(t))!j.call(e,r)&&r!==n&&$(e,r,{get:()=>t[r],enumerable:!(i=ne(t,r))||i.enumerable});return e};var ce=e=>ae($({},"__esModule",{value:!0}),e);var De={};oe(De,{deriveSessionSegment:()=>H,detectDeviceClass:()=>D,detectTimeOfDay:()=>O,detectTrafficSource:()=>T,init:()=>Ce,preloadAssignments:()=>Z,readSessionCookie:()=>ee,referrerDomainFromReferer:()=>U});module.exports=ce(De);var ue="_snt_uid";var b="_snt_uid";function de(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function le(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function ge(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(i){}}function me(e){try{return localStorage.getItem(e)}catch(t){return null}}function fe(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function pe(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function ye(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function Se(e){try{sessionStorage.removeItem(e)}catch(t){}}function he(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function ve(e){try{localStorage.removeItem(e)}catch(t){}}function Ie(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var Ee={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function q(e){var m,d,p,I,y;if(typeof window=="undefined")return Ee;let t=(m=e==null?void 0:e.cookieName)!=null?m:ue,i=((d=e==null?void 0:e.cookieTTLDays)!=null?d:365)*24*60*60,r=(y=(I=(p=le(t))!=null?p:me(b))!=null?I:pe(b))!=null?y:de();ge(t,r,i);let a=fe(b,r),s=he(t),o=a?!1:ye(b,r),u=!a&&!s&&!o;return{getSessionId:()=>r,isEphemeral:()=>u,destroy:()=>{r=null,Ie(t),ve(b),Se(b)}}}var L="_snt_retry";var we={push:()=>{},flush:()=>{},destroy:()=>{}};function Ae(e){try{let t=localStorage.getItem(L);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?(localStorage.removeItem(L),n.slice(-e)):[]}catch(t){return[]}}function B(e,t){try{let i=[...(()=>{try{let r=localStorage.getItem(L);if(!r)return[];let a=JSON.parse(r);return Array.isArray(a)?a:[]}catch(r){return[]}})(),...e].slice(-t);localStorage.setItem(L,JSON.stringify(i))}catch(n){}}function V(e){var A,x,F;if(typeof window=="undefined")return we;let t=(A=e.flushIntervalMs)!=null?A:5e3,n=(x=e.maxBatchSize)!=null?x:20,i=(F=e.maxRetrySize)!=null?F:100,r=e.ingestUrl,a=e.apiKey,s=[],o=new Set,u=[],m=c=>{for(let l of c)o.has(l)||(o.add(l),u.push(l));for(;u.length>500;){let l=u.shift();l&&o.delete(l)}},d=new Set,p=c=>{o.has(c.id)||d.has(c.id)||(d.add(c.id),s.push(c))},I=Ae(i);for(let c of I)p(c);let y=0,S=0,R=c=>{if(c.length===0)return;let l=JSON.stringify(c),_=c.map(w=>w.id),E;try{E=fetch(r,{method:"POST",keepalive:!0,body:l,headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}})}catch(w){B(c,i),S++,y=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6));return}let C=w=>{if(w.ok||w.status>=400&&w.status<500&&w.status!==429){m(_),S=0,y=0;return}B(c,i),S++,y=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))};E instanceof Promise?E.then(C).catch(()=>{B(c,i),S++,y=Date.now()+Math.min(6e4,1e3*2**Math.min(S,6))}):C(E)},P=c=>{let l=[],_=2;for(let E of c){let C=JSON.stringify(E).length+1;if(l.length>0&&_+C>57344||l.length>=n)break;l.push(E),_+=C}return l},h=()=>{try{if(Date.now()<y)return;for(;s.length>0;){let c=s.filter(_=>!o.has(_.id));if(s.length=0,c.length===0)break;let l=P(c);if(l.length===0)break;l.length<c.length&&s.push(...c.slice(l.length)),R(l)}}catch(c){}},g=!0,f=null;f=setInterval(()=>{g&&h()},t);let v=()=>{document.visibilityState==="hidden"&&h()},k=()=>{h()};return document.addEventListener("visibilitychange",v),window.addEventListener("beforeunload",k),{push(c){p(c),s.length>=n&&h()},flush:h,destroy(){g=!1,f!==null&&(clearInterval(f),f=null),document.removeEventListener("visibilitychange",v),window.removeEventListener("beforeunload",k),h()}}}var K="_snt_asgn_";function M(e,t){return`${e}:${t}`}function _e(e,t){return`${K}${e}_${t}`}function Q(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(K)&&e.push(n)}return e}catch(e){return[]}}function X(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of Q())try{let a=localStorage.getItem(r);if(!a)continue;let s=JSON.parse(a);if(n(s)){localStorage.removeItem(r);continue}let o=r.slice(K.length),u=o.lastIndexOf("_");if(u<0)continue;let m=o.slice(0,u),d=o.slice(u+1);t.set(M(m,d),s)}catch(a){}})(),{get(r,a){let s=t.get(M(r,a));return s?n(s)?(t.delete(M(r,a)),null):s:null},set(r,a,s){let o=M(r,a);t.set(o,s);try{localStorage.setItem(_e(r,a),JSON.stringify(s))}catch(u){}},invalidate(r){let a=`${r}:`;for(let s of[...t.keys()])s.startsWith(a)&&t.delete(s);for(let s of Q()){let o=s.slice(K.length),u=o.lastIndexOf("_");if(u<0)continue;if(o.slice(0,u)===r)try{localStorage.removeItem(s)}catch(d){}}},clear(){t.clear();for(let r of Q())try{localStorage.removeItem(r)}catch(a){}}}}function D(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function T(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(r){}let i=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(i)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(i)?"social":"referral"}catch(n){return"direct"}}function U(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function O(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function H(e){let t=G("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function G(e,t){var a,s,o,u,m,d,p;let n=(s=(a=t==null?void 0:t.userAgent)==null?void 0:a.trim())!=null?s:"",i=(u=(o=t==null?void 0:t.referer)==null?void 0:o.trim())!=null?u:"",r=(m=t==null?void 0:t.now)!=null?m:new Date;return{sessionId:e,ephemeral:!1,utmParams:(d=t==null?void 0:t.utmParams)!=null?d:{},deviceClass:n?D(n):"desktop",trafficSource:i?T(i,t==null?void 0:t.appOrigin):"direct",referrerDomain:U(i),timeOfDay:O(r),dayOfWeek:(p=["sun","mon","tue","wed","thu","fri","sat"][r.getDay()])!=null?p:"sun"}}async function Z(e,t,n){let i={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};n.origin&&(i.Origin=n.origin);let r=G(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,appOrigin:n.origin});try{await fetch(`${n.baseUrl}/sessions`,{method:"POST",headers:i,body:JSON.stringify(r)})}catch(o){}let a=await Promise.allSettled(e.map(async({id:o,variantIds:u})=>{let m=await fetch(`${n.baseUrl}/assign`,{method:"POST",headers:i,body:JSON.stringify({sessionId:t,componentId:o,variantIds:u})});if(!m.ok)return null;let d=await m.json();return{id:o,variantId:d.variantId}})),s={};for(let o of a)o.status==="fulfilled"&&o.value&&(s[o.value.id]=o.value.variantId);return s}function ee(e){var t,n;return(n=(t=e.get("_snt_uid"))==null?void 0:t.value)!=null?n:null}function be(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return`evt-${Date.now()}-${Math.random().toString(16).slice(2)}`}var N={track:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),getGraph:()=>({pageNodes:[],userEdges:[],capturedAt:0}),destroy:()=>{}};function ke(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,i]of t)n.startsWith("utm_")&&(e[n]=i);return e}catch(e){return{}}}function xe(e){return e.replace(/\/events\/?$/,"")}function Ce(e){var S,R,P,h;if(typeof window=="undefined"||e.consent===!1)return N;if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),N;if(!e.ingestUrl)return console.warn("[sentient] init() called without ingestUrl. SDK disabled."),N;let t=Date.now(),n=q(),i=X(),r=V({ingestUrl:e.ingestUrl,apiKey:e.apiKey}),a=xe(e.ingestUrl),s={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},o=D((S=navigator.userAgent)!=null?S:""),u=typeof window!="undefined"?window.location.origin:void 0,m=T((R=document.referrer)!=null?R:"",u),d=(P=e.sessionSegment)!=null?P:`${o}:${m}`;if(e.initialAssignments)for(let[g,f]of Object.entries(e.initialAssignments))i.set(g,d,{variantId:f,assignedAt:Date.now(),segment:d,confidence:1});let p=Promise.resolve(),I=n.getSessionId();if(I){let g=U((h=document.referrer)!=null?h:""),f={sessionId:I,deviceClass:o,trafficSource:m,referrerDomain:g,utmParams:ke(),timeOfDay:O(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral()};try{p=fetch(`${a}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(f),headers:s}).then(()=>{}).catch(()=>{})}catch(v){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let y={track(g){let f=n.getSessionId();if(!f)return;let v=Y(W({},g),{id:be(),sessionId:f,timestamp:Date.now(),timeInSession:Date.now()-t});r.push(v),e.debug&&console.log("[sentient] track",v)},getAssignment(g,f){return i.get(g,f)},async assign(g,f){let v=n.getSessionId();if(!v)return null;let k=i.get(g,d);if(k)return{variantId:k.variantId,assignmentTtlMs:0};await p;try{let A=await fetch(`${a}/assign`,{method:"POST",body:JSON.stringify({sessionId:v,componentId:g,variantIds:f}),headers:s});if(!A.ok)return null;let x=await A.json();return i.set(g,d,{variantId:x.variantId,assignedAt:Date.now(),segment:d,confidence:1}),x}catch(A){return null}},getGraph(){return{pageNodes:[],userEdges:[],capturedAt:0}},destroy(){r.destroy(),n.destroy(),e.debug&&console.log("[sentient] destroyed")}};if(e.debug){let g=window;g.__sentient&&(g.__sentient.client=y)}return y}0&&(module.exports={deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,init,preloadAssignments,readSessionCookie,referrerDomainFromReferer});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h}from"./chunk-
|
|
1
|
+
import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h}from"./chunk-2K7NAMTI.mjs";export{e as deriveSessionSegment,a as detectDeviceClass,d as detectTimeOfDay,b as detectTrafficSource,h as init,f as preloadAssignments,g as readSessionCookie,c as referrerDomainFromReferer};
|
package/package.json
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@sentientui/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"private": false,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.js"
|
|
14
|
-
},
|
|
15
|
-
"./graph": {
|
|
16
|
-
"types": "./dist/index-graph.d.ts",
|
|
17
|
-
"import": "./dist/index-graph.mjs",
|
|
18
|
-
"require": "./dist/index-graph.js"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@sentientui/core",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./graph": {
|
|
16
|
+
"types": "./dist/index-graph.d.ts",
|
|
17
|
+
"import": "./dist/index-graph.mjs",
|
|
18
|
+
"require": "./dist/index-graph.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": ["dist"],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"size-check": "tsx scripts/size-check.ts",
|
|
27
|
+
"lint": "eslint src"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.10.2",
|
|
31
|
+
"jsdom": "^25.0.1",
|
|
32
|
+
"tsup": "^8.3.5",
|
|
33
|
+
"tsx": "^4.19.2",
|
|
34
|
+
"typescript": "^5.7.2",
|
|
35
|
+
"vitest": "^2.1.8"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/chunk-HRRGYUE4.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var J=Object.defineProperty,j=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var K=(e,t,n)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,N=(e,t)=>{for(var n in t||(t={}))Y.call(t,n)&&K(e,n,t[n]);if(M)for(var n of M(t))q.call(t,n)&&K(e,n,t[n]);return e},Q=(e,t)=>j(e,W(t));var X="_snt_uid";var b="_snt_uid";function H(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(t){}let e=()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0");return`${e()}-${e()}-${e()}-${e()}`}function V(e){try{let t=document.cookie.match(new RegExp(`(?:^|; )${e}=([^;]*)`));return t?decodeURIComponent(t[1]):null}catch(t){return null}}function Z(e,t,n){try{document.cookie=`${e}=${encodeURIComponent(t)}; max-age=${n}; SameSite=strict; path=/`}catch(a){}}function ee(e){try{return localStorage.getItem(e)}catch(t){return null}}function te(e,t){try{return localStorage.setItem(e,t),!0}catch(n){return!1}}function ne(e){try{return sessionStorage.getItem(e)}catch(t){return null}}function re(e,t){try{return sessionStorage.setItem(e,t),!0}catch(n){return!1}}function se(e){try{sessionStorage.removeItem(e)}catch(t){}}function ie(e){try{return document.cookie=`${e}_probe=1; max-age=1; SameSite=strict; path=/`,/(?:^|; )_snt_uid_probe=1/.test(document.cookie)||document.cookie.indexOf(`${e}_probe=1`)!==-1}catch(t){return!1}}function oe(e){try{localStorage.removeItem(e)}catch(t){}}function ae(e){try{document.cookie=`${e}=; max-age=0; SameSite=strict; path=/`}catch(t){}}var ce={getSessionId:()=>null,isEphemeral:()=>!1,destroy:()=>{}};function F(e){var g,d,p,v,w;if(typeof window=="undefined")return ce;let t=(g=e==null?void 0:e.cookieName)!=null?g:X,a=((d=e==null?void 0:e.cookieTTLDays)!=null?d:365)*24*60*60,r=(w=(v=(p=V(t))!=null?p:ee(b))!=null?v:ne(b))!=null?w:H();Z(t,r,a);let o=te(b,r),s=ie(t),i=o?!1:re(b,r),u=!o&&!s&&!i;return{getSessionId:()=>r,isEphemeral:()=>u,destroy:()=>{r=null,ae(t),oe(b),se(b)}}}var C="_snt_retry";var ue={push:()=>{},flush:()=>{},destroy:()=>{}};function de(e){try{let t=localStorage.getItem(C);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?(localStorage.removeItem(C),n.slice(-e)):[]}catch(t){return[]}}function le(e,t){try{let a=[...(()=>{try{let r=localStorage.getItem(C);if(!r)return[];let o=JSON.parse(r);return Array.isArray(o)?o:[]}catch(r){return[]}})(),...e].slice(-t);localStorage.setItem(C,JSON.stringify(a))}catch(n){}}function G(e){var h,_,I;if(typeof window=="undefined")return ue;let t=(h=e.flushIntervalMs)!=null?h:5e3,n=(_=e.maxBatchSize)!=null?_:20,a=(I=e.maxRetrySize)!=null?I:100,r=e.ingestUrl,o=e.apiKey,s=[],i=new Set,u=[],g=c=>{for(let m of c)i.has(m)||(i.add(m),u.push(m));for(;u.length>500;){let m=u.shift();m&&i.delete(m)}},d=new Set,p=c=>{i.has(c.id)||d.has(c.id)||(d.add(c.id),s.push(c))},v=de(a);for(let c of v)p(c);let w=c=>{if(c.length===0)return!0;let m=JSON.stringify(c);try{return fetch(r,{method:"POST",keepalive:!0,body:m,headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`}}),g(c.map(k=>k.id)),!0}catch(k){return le(c,a),!1}},y=()=>{try{for(;s.length>0;){let m=s.splice(0,n).filter(z=>!i.has(z.id));if(m.length===0)continue;if(!w(m)){s.unshift(...m);break}}}catch(c){}},A=!0,S=null,E=()=>{if(!A)return;let c=Date.now()+t,m=()=>{if(A){if(Date.now()>=c){y(),E();return}try{S=new MessageChannel,S.port1.onmessage=m,S.port2.postMessage(null)}catch(k){}}};m()},l=()=>{document.visibilityState==="hidden"&&y()},f=()=>{y()};return document.addEventListener("visibilitychange",l),window.addEventListener("beforeunload",f),E(),{push(c){p(c),s.length>=n&&y()},flush:y,destroy(){A=!1,document.removeEventListener("visibilitychange",l),window.removeEventListener("beforeunload",f),S&&(S.port1.onmessage=null,S=null),y()}}}var D="_snt_asgn_";function x(e,t){return`${e}:${t}`}function ge(e,t){return`${D}${e}_${t}`}function P(){try{let e=[];for(let t=0;t<localStorage.length;t++){let n=localStorage.key(t);n!=null&&n.startsWith(D)&&e.push(n)}return e}catch(e){return[]}}function B(e=18e5){let t=new Map,n=r=>r.assignedAt+e<Date.now();return typeof window!="undefined"&&(()=>{for(let r of P())try{let o=localStorage.getItem(r);if(!o)continue;let s=JSON.parse(o);if(n(s)){localStorage.removeItem(r);continue}let i=r.slice(D.length),u=i.lastIndexOf("_");if(u<0)continue;let g=i.slice(0,u),d=i.slice(u+1);t.set(x(g,d),s)}catch(o){}})(),{get(r,o){let s=t.get(x(r,o));return s?n(s)?(t.delete(x(r,o)),null):s:null},set(r,o,s){let i=x(r,o);t.set(i,s);try{localStorage.setItem(ge(r,o),JSON.stringify(s))}catch(u){}},invalidate(r){let o=`${r}:`;for(let s of[...t.keys()])s.startsWith(o)&&t.delete(s);for(let s of P()){let i=s.slice(D.length),u=i.lastIndexOf("_");if(u<0)continue;if(i.slice(0,u)===r)try{localStorage.removeItem(s)}catch(d){}}},clear(){t.clear();for(let r of P())try{localStorage.removeItem(r)}catch(o){}}}}function T(e){let t=e.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(t)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(t)?"mobile":"desktop"}function O(e,t){if(!e)return"direct";try{let n=new URL(e);if(t)try{if(new URL(t).host===n.host)return"direct"}catch(r){}let a=n.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(a)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(a)?"social":"referral"}catch(n){return"direct"}}function U(e){if(!e)return null;try{return new URL(e).hostname}catch(t){return null}}function R(e){let t=e.getHours();return t<6?"night":t<12?"morning":t<18?"afternoon":"evening"}function me(e){let t=L("__segment__",e);return`${t.deviceClass}:${t.trafficSource}`}function L(e,t){var o,s,i,u,g,d,p;let n=(s=(o=t==null?void 0:t.userAgent)==null?void 0:o.trim())!=null?s:"",a=(u=(i=t==null?void 0:t.referer)==null?void 0:i.trim())!=null?u:"",r=(g=t==null?void 0:t.now)!=null?g:new Date;return{sessionId:e,ephemeral:!1,utmParams:(d=t==null?void 0:t.utmParams)!=null?d:{},deviceClass:n?T(n):"desktop",trafficSource:a?O(a,t==null?void 0:t.appOrigin):"direct",referrerDomain:U(a),timeOfDay:R(r),dayOfWeek:(p=["sun","mon","tue","wed","thu","fri","sat"][r.getDay()])!=null?p:"sun"}}async function fe(e,t,n){let a={"Content-Type":"application/json",Authorization:`Bearer ${n.apiKey}`};n.origin&&(a.Origin=n.origin);let r=L(t,{userAgent:n.userAgent,referer:n.referer,utmParams:n.utmParams,appOrigin:n.origin});try{await fetch(`${n.baseUrl}/sessions`,{method:"POST",headers:a,body:JSON.stringify(r)})}catch(i){}let o=await Promise.allSettled(e.map(async({id:i,variantIds:u})=>{let g=await fetch(`${n.baseUrl}/assign`,{method:"POST",headers:a,body:JSON.stringify({sessionId:t,componentId:i,variantIds:u})});if(!g.ok)return null;let d=await g.json();return{id:i,variantId:d.variantId}})),s={};for(let i of o)i.status==="fulfilled"&&i.value&&(s[i.value.id]=i.value.variantId);return s}function pe(e){var t,n;return(n=(t=e.get("_snt_uid"))==null?void 0:t.value)!=null?n:null}function ye(){try{if(typeof crypto!="undefined"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch(e){}return`evt-${Date.now()}-${Math.random().toString(16).slice(2)}`}var $={track:()=>{},getAssignment:()=>null,assign:()=>Promise.resolve(null),getGraph:()=>({pageNodes:[],userEdges:[],capturedAt:0}),destroy:()=>{}};function Se(){try{let e={},t=new URLSearchParams(window.location.search);for(let[n,a]of t)n.startsWith("utm_")&&(e[n]=a);return e}catch(e){return{}}}function he(e){return e.replace(/\/events\/?$/,"")}function Te(e){var y,A,S,E;if(typeof window=="undefined"||e.consent===!1)return $;if(!e.apiKey||!e.apiKey.startsWith("pk_"))return console.warn("[sentient] init() called with an invalid apiKey \u2014 expected a pk_ public key. SDK disabled."),$;if(!e.ingestUrl)return console.warn("[sentient] init() called without ingestUrl. SDK disabled."),$;let t=Date.now(),n=F(),a=B(),r=G({ingestUrl:e.ingestUrl,apiKey:e.apiKey}),o=he(e.ingestUrl),s={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`},i=T((y=navigator.userAgent)!=null?y:""),u=typeof window!="undefined"?window.location.origin:void 0,g=O((A=document.referrer)!=null?A:"",u),d=(S=e.sessionSegment)!=null?S:`${i}:${g}`;if(e.initialAssignments)for(let[l,f]of Object.entries(e.initialAssignments))a.set(l,d,{variantId:f,assignedAt:Date.now(),segment:d,confidence:1});let p=Promise.resolve(),v=n.getSessionId();if(v){let l=U((E=document.referrer)!=null?E:""),f={sessionId:v,deviceClass:i,trafficSource:g,referrerDomain:l,utmParams:Se(),timeOfDay:R(new Date),dayOfWeek:["sun","mon","tue","wed","thu","fri","sat"][new Date().getDay()],ephemeral:n.isEphemeral()};try{p=fetch(`${o}/sessions`,{method:"POST",keepalive:!0,body:JSON.stringify(f),headers:s}).then(()=>{}).catch(()=>{})}catch(h){}}e.debug&&(console.log("[sentient] initialized",{context:e.context}),window.__sentient={client:null,queue:r});let w={track(l){let f=n.getSessionId();if(!f)return;let h=Q(N({},l),{id:ye(),sessionId:f,timestamp:Date.now(),timeInSession:Date.now()-t});r.push(h),e.debug&&console.log("[sentient] track",h)},getAssignment(l,f){return a.get(l,f)},async assign(l,f){let h=n.getSessionId();if(!h)return null;let _=a.get(l,d);if(_)return{variantId:_.variantId,assignmentTtlMs:0};await p;try{let I=await fetch(`${o}/assign`,{method:"POST",body:JSON.stringify({sessionId:h,componentId:l,variantIds:f}),headers:s});if(!I.ok)return null;let c=await I.json();return a.set(l,d,{variantId:c.variantId,assignedAt:Date.now(),segment:d,confidence:1}),c}catch(I){return null}},getGraph(){return{pageNodes:[],userEdges:[],capturedAt:0}},destroy(){r.destroy(),n.destroy(),e.debug&&console.log("[sentient] destroyed")}};if(e.debug){let l=window;l.__sentient&&(l.__sentient.client=w)}return w}export{N as a,Q as b,T as c,O as d,U as e,R as f,me as g,fe as h,pe as i,Te as j};
|