@prodantix/sdk 0.7.0 → 0.8.0-beta.651

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import {c,a as a$2,b as b$2}from'./chunk-V77KYPOF.js';import {e,h,d,f as f$1,g as g$1,a as a$1,b as b$1,c as c$1}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);}},y=class{constructor(e,t=()=>false){this.real=e;this.passes=t;a(this,"held",new m);a(this,"opened",false);}get isOpen(){return this.opened}open(){this.opened=true;}close(){this.opened=false;}target(e){return this.opened||this.passes(e)?this.real:this.held}getItem(e){return this.target(e).getItem(e)}removeItem(e){this.target(e).removeItem(e);}setItem(e,t){this.target(e).setItem(e,t);}};function Ye(){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 X={now:()=>new Date};function x(s){return s.toISOString()}function Z(){if(typeof window>"u"||typeof Intl>"u")return null;let s=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof s=="string"&&s!==""?s:null}var Te=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var Ee=/^(?:\$|[a-z])[a-z0-9_.]*$/;function ee(s){let e=0;for(let t of s)e+=1;return e}function te(s){return Te.test(s)}function $e(s){return Ee.test(s)}function se(s){let e=ee(s);if(e<1||e>200)throw new c$1("distinct_id","distinct_id must be between 1 and 200 characters")}function ne(s){let e=ee(s);if(e<1||e>200)throw new c$1("event_name","event_name must be between 1 and 200 characters");if(!$e(s))throw new c$1("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var ie="prodantix-js",re="0.8.0";function Ae(){return globalThis.crypto}function Pe(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 Re(){let s=Ae();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 Pe(e)}var oe={uuid:Re};var Me=s=>{};function ae(s){if(!s.apiKey||!te(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??X,consent:s.consent,consentMode:s.consentMode,defaultProperties:typeof t=="function"?t:()=>t??{},describeElement:s.describeElement,flagsHost:s.flagsHost?h(s.flagsHost):e,flushAt:s.flushAt??20,flushIntervalMs:s.flushIntervalMs??1e4,host:e,ids:s.ids??oe,locale:s.locale,maxQueueSize:s.maxQueueSize??1e3,maxRetries:s.maxRetries??3,namespace:qe(s.apiKey),onError:s.onError??Me,os:s.os,requestTimeoutMs:s.requestTimeoutMs??1e4,sdkName:s.sdkName??ie,sdkVersion:s.sdkVersion??re,sessionTracking:s.sessionTracking??false,sharedStorage:s.sharedStorage??n,socketFactory:s.socketFactory,storage:n,streamFlags:s.streamFlags??false,transport:s.transport}}function qe(s){return s.slice(0,16)}var f=Symbol("absent");function Ke(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 g(s){return s===f?"undefined":String(s)}function le(s){return s===f?Number.NaN:Number(s)}function ce(s){return s!==f&&s!==null&&s!==""}function ue(s,e){if(!Array.isArray(e))return false;let t=g(s);return e.map(n=>String(n)).includes(t)}function de(s,e){let t=Ke(s.attribute,e),n=s.value;switch(s.op){case "is_set":return ce(t);case "is_not_set":return !ce(t);case "eq":return g(t)===g(n===void 0?f:n);case "neq":return g(t)!==g(n===void 0?f:n);case "contains":return g(t).includes(g(n===void 0?f:n));case "in":return ue(t,n);case "not_in":return Array.isArray(n)?!ue(t,n):false;case "gt":return w(t,n,(i,r)=>i>r);case "gte":return w(t,n,(i,r)=>i>=r);case "lt":return w(t,n,(i,r)=>i<r);case "lte":return w(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 w(s,e,t){let n=le(s),i=e===void 0?Number.NaN:le(e);return Number.isNaN(n)||Number.isNaN(i)?false:t(n,i)}function pe(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 N(s,e){return s.targeting.length===0||s.targeting.every(t=>de(t,e))}function he(s,e){let t=pe(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 L(s,e,t,n){for(let i of s.prerequisites??[]){if(n.includes(i.flagKey))return false;let r=e.find(c=>c.key===i.flagKey);if(!r||!r.enabled)return false;n.push(r.key);let a=L(r,e,t,n)&&N(r,t)&&he(r,t)===i.variationKey;if(n.pop(),!a)return false}return true}function v(s,e,t){return s.enabled?L(s,e,t,[s.key])?N(s,t)?s.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:pe(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 gt(s,e){return v(s,[],e)}function me(s,e){let t={};for(let n of s)t[n.key]=v(n,s,e).enabled;return t}function b(s,e,t){let n=s.variations??[],i=n[0];if(!i)return null;if(!s.enabled||!L(s,e,t,[s.key])||!N(s,t))return i;let r=he(s,t);return n.find(a=>a.key===r)??i}function ft(s,e){return b(s,[],e)}function yt(s,e,t){let n=s.find(i=>i.key===e);return n?b(n,s,t)?.value??null:null}function ge(s){return s.some(e=>e.targeting.some(t=>t.op==="in_cohort"||t.op==="not_in_cohort"))}var _=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 c=JSON.parse(await a.text());return {flags:c.flags??{},variants:c.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()),c={flags:a.flags??[],generatedAt:a.generatedAt};return typeof a.socketUrl=="string"&&a.socketUrl!==""&&(c.socketUrl=a.socketUrl),c}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);}}};var fe="$survey_shown",ye="$survey_dismissed",ve="$survey_sent",F=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 surveys(e,t){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await n(`${this.host}/v1/surveys?distinct_id=${encodeURIComponent(e)}${t?`&lang=${encodeURIComponent(t)}`:""}`,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!a.ok)throw new d(`surveys request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).surveys??[]}finally{r!==void 0&&clearTimeout(r);}}},Oe=864e5,De=s=>`${s.id}:${s.iteration}`;function j(s,e){return s.length===0?true:s.some(t=>{switch(t.matches){case "exact":return e===t.value;case "starts_with":return e.startsWith(t.value);default:return e.includes(t.value)}})}function Ft(s,e,t,n,i){return s.kind!=="popover"||e.settled.includes(De(s))||s.showOnce&&e.settled.some(r=>r.startsWith(`${s.id}:`))||s.waitDays>0&&e.lastShownAt!==void 0&&n-e.lastShownAt<s.waitDays*Oe||s.event&&s.event!==i?false:j(s.urls,t)}function Ne(s,e,t){return s>=(e.minScore??0)&&s<=(e.maxScore??t)}function Ct(s,e,t){let n=e.kind==="nps"?10:e.scale??5,i=e.branches.find(a=>a.choice!=null?t===a.choice:typeof t=="number"&&Ne(t,a,n));if(i)return i.next??null;let r=s.questions.findIndex(a=>a.id===e.id);return s.questions[r+1]?.id??null}function C(s,e){let t={$survey_id:s.id,$survey_iteration:s.iteration,$survey_name:s.name};for(let[n,i]of Object.entries(e))t[`$survey_response_${n}`]=i;return t}var Pt="$guide_shown",Rt="$guide_step_viewed",Mt="$guide_step_missed",qt="$guide_completed",Kt="$guide_dismissed",Ot="$checklist_task_done",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 guides(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=f$1(),i=n?setTimeout(()=>n.abort(),this.requestTimeoutMs):void 0;try{let r=await t(`${this.host}/v1/guides?distinct_id=${encodeURIComponent(e)}`,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:n?.signal});if(!r.ok)throw new d(`guides request failed with status ${r.status}`,r.status);return JSON.parse(await r.text()).guides??[]}finally{i!==void 0&&clearTimeout(i);}}},Le=864e5,be=s=>`${s.id}:${s.iteration}`,je=(s,e)=>`${be(s)}:${e}`;function Dt(s,e,t,n,i){return e.settled.includes(be(s))||s.showOnce&&e.settled.some(r=>r.startsWith(`${s.id}:`))||s.kind!=="checklist"&&s.waitDays>0&&e.lastShownAt!==void 0&&n-e.lastShownAt<s.waitDays*Le||s.event&&s.event!==i?false:j(s.urls,t)}var Nt=(s,e)=>s.steps.filter(t=>e.done.includes(je(s,t.id))).map(t=>t.id),Lt=(s,e)=>s.kind==="checklist"?s.steps.find(t=>t.event===e):void 0;function Se(s,e){let t={$guide_id:s.id,$guide_iteration:s.iteration,$guide_name:s.name};return e!==void 0&&(t.$guide_step_id=e),t}function S(s){if(typeof s!="string")return;let e=Array.from(s).length;return e>=1&&e<=200?s:void 0}function E(s,e){return `pdx.${s}.${e}`}var G="consent",Ve=["identityLink","analytics","marketing","functional"];function V(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,n={};for(let i of Ve){let r=t[i];typeof r=="boolean"&&(n[i]=r);}return typeof t.version=="number"&&Number.isInteger(t.version)&&(n.version=t.version),Array.isArray(t.categories)&&t.categories.every(i=>typeof i=="string")&&(n.categories=t.categories),Object.keys(n).length===0?null:n}catch{return null}}var ke=s=>s.endsWith(`.${G}`);function $(s,e){return V(s.getItem(E(e,G)))}function Ge(s,e,t){let n=E(e,G),i=V(JSON.stringify(t)),r=i===null?null:V(JSON.stringify({...$(s,e)??{},...i}));if(r===null){s.removeItem(n);return}s.setItem(n,JSON.stringify(r));}function Gt(s,e,t,n){let i=E(t,"anonymous_id"),r=S(e.getItem(i))??S(s.getItem(i));return e.setItem(i,n),s.setItem(i,n),r!==void 0&&r!==n?r:void 0}var T=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=S(this.shared.getItem(this.key("anonymous_id"))),t=S(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=S(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 $(this.shared,this.namespace)}setConsent(e){Ge(this.shared,this.namespace,e);}assumeAnonymousId(e){this.anonymousId=e,this.shared.setItem(this.key("anonymous_id"),e),this.storage.setItem(this.key("anonymous_id"),e),this.identified||(this.distinctId=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 E(this.namespace,e)}};var A=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 u={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageleave:"$pageleave",pageview:"$pageview",screen:"$screen",set:"$set",webVitals:"$web_vitals"},Ue=[{emittedBy:"web_and_flutter",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. A Flutter app sends each tap as this event too, under TelemetryTapCapture.",name:u.autocapture,properties:["$event_type","$el_description","$el_description_source","$el_action","$el_tag","$el_text","$el_id","$el_classes","$el_href","$current_url","$pathname","$host","$title","$referrer","$screen_name"]},{emittedBy:"web",meaning:"A page shown, including every client-side navigation the History API makes: one per distinct path and query.",name:u.pageview,properties:["$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"web",meaning:"A landing page left the visitor's sight, by a tab switch, a closed tab or a navigation away, with the seconds it was in front of them so far. A page returned to and left again sends it again with the larger total.",name:u.pageleave,properties:["$engaged_seconds","$page_id","$page_view_id","$page_variant"]},{emittedBy:"web",meaning:"A page's Core Web Vitals, sent once per page load the first time the page leaves the visitor's sight: largest contentful paint, first contentful paint, cumulative layout shift, interaction to next paint and time to first byte, each only when the browser measured it. autocaptureOptions.webVitals: false turns it off.",name:u.webVitals,properties:["$lcp_ms","$fcp_ms","$cls","$inp_ms","$ttfb_ms","$pathname"]},{emittedBy:"flutter",meaning:"A named route pushed or replaced in a Flutter app, the mobile counterpart of $pageview.",name:u.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:u.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:u.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:u.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:u.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:u.featureFlagCalled,properties:["$feature_flag","$feature_flag_response"]}],Wt=s=>s.startsWith("$"),Yt=s=>Ue.find(e=>e.name===s);function xe(s){return s>=400&&s<500&&s!==429}var P=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$1,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(xe(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&&xe(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}};var rs="$cta_viewed",os="$cta_clicked",as="$cta_dismissed",we=(s,e)=>{let t={$cta_id:s.id,$cta_kind:s.kind,$cta_variant:s.variant.key,$cta_version:s.version},n=e===void 0?void 0:s.variant.content.buttons[e];return n&&e!==void 0&&(t.$cta_button=e,t.$cta_button_label=n.label,n.action.kind==="form"&&(t.$cta_form_id=n.action.value)),t},R=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 ctas(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=new URLSearchParams({anonymous:String(e.anonymous),device:e.device,distinct_id:e.distinctId,language:e.language,url:e.url}),i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await t(`${this.host}/v1/ctas?${n.toString()}`,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(a.status<200||a.status>=300)throw new d(`ctas request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).ctas}finally{r!==void 0&&clearTimeout(r);}}};function _e(s,e,t){ne(s.eventName),se(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:x(s.timestamp??e.now())};return s.context&&(n.context=s.context),s.sessionId&&(n.session_id=s.sessionId),n}var Be="/socket.io/?EIO=4&transport=websocket",He=250,M=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??Je,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(/\/+$/,"")}${Be}`,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(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);},He));}}}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 Je(s){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(s)}var bs="$form_viewed",Ss="$form_started",U=class extends Error{constructor(t,n,i){super(i);a(this,"fields");a(this,"status");this.name="FormRefusedError",this.status=t,this.fields=n;}},q=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 request(e,t){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a={authorization:`Bearer ${this.projectKey}`};t.body!==void 0&&(a["content-type"]="application/json");let c=await n(`${this.host}${e}`,{body:t.body,headers:a,method:t.method,signal:i?.signal});return {status:c.status,text:await c.text()}}finally{r!==void 0&&clearTimeout(r);}}async form(e,t){let{status:n,text:i}=await this.request(`/v1/forms/${encodeURIComponent(e)}?distinct_id=${encodeURIComponent(t)}`,{method:"GET"});if(n<200||n>=300)throw new d(`form request failed with status ${n}`,n);return JSON.parse(i)}async submit(e,t){let{status:n,text:i}=await this.request(`/v1/forms/${encodeURIComponent(e)}/submissions`,{body:JSON.stringify(t),method:"POST"});if(n>=200&&n<300)return JSON.parse(i).afterSubmit;let r=[],a=`form submission failed with status ${n}`;try{let c=JSON.parse(i);r=c.error?.fields??[],a=c.error?.message??a;}catch{r=[];}throw new U(n,r,a)}};var K=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 ze={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function Fe(s){return `pdx.${s}.session`}function Fs(s,e,t,n){let i={id:t.id,lastActivityAt:n,startedAt:t.startedAt};s.setItem(Fe(e),JSON.stringify(i));}var O=class{constructor(e,t,n,i,r=ze){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 Fe(this.namespace)}};var Qe="queue",We=1e3,Ce=3e4,B=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},H=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,"surveysClient");a(this,"guidesClient");a(this,"captureListeners",new Set);a(this,"formsClient");a(this,"ctasClient");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);a(this,"gates");a(this,"cookielessId");a(this,"storageListeners",new Set);let t=ae(e),n=$(t.sharedStorage,t.namespace)??t.consent??null;if(this.gates=[new y(t.storage),new y(t.sharedStorage,ke)],t.consentMode!=="banner"||n?.analytics===true)for(let a of this.gates)a.open();let[i,r]=this.gates;this.config={...t,sharedStorage:r,storage:i},this.identity=new T(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 O(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new K(this.config.maxQueueSize,({dropped:a})=>{this.config.onError(new a$1("queue_overflow",`event queue overflow: dropped ${a.length} oldest event(s)`));}),this.transport=this.config.transport??new P({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new _({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new A({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.surveysClient=new F({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.guidesClient=new I({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.formsClient=new q({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.ctasClient=new R({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.element===void 0?{}:this.config.describeElement?.(t.element)??{},...t.properties??{}},i=_e({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);}for(let n of this.captureListeners)try{n(e);}catch(i){this.config.onError(i);}}onCapture(e){return this.captureListeners.add(e),()=>{this.captureListeners.delete(e);}}identify(e,t={}){if(this.isCookieless())return;this.identity.refresh();let n=this.identity.identify(e),i={};n.anonymousToLink!==void 0&&(i.$anon_distinct_id=n.anonymousToLink);let r=Z(),a={...r===null?{}:{$timezone:r},...B(t.traits??{}),...t.set??{}};Object.keys(a).length>0&&(i.$set=a),this.capture(u.identify,{properties:i});}link(e,t,n){if(this.isCookieless())return;let i={$anon_distinct_id:t},r=B(n??{});Object.keys(r).length>0&&(i.$set=r),this.capture(u.identify,{distinctId:e,properties:i});}setConsent(e){this.identity.setConsent(e),e.analytics===true&&this.allowStorage(),e.analytics===false&&this.config.consentMode==="banner"&&this.forbidStorage();}isCookieless(){return !this.gates[0].isOpen}takeCookielessId(e){this.cookielessId=e,this.isCookieless()&&this.identity.assumeAnonymousId(e);}allowStorage(){if(this.isCookieless()){for(let e of this.gates)e.open();this.identity.refresh();for(let e of [...this.storageListeners])e();}}onStorageAllowed(e){return this.storageListeners.add(e),()=>{this.storageListeners.delete(e);}}forbidStorage(){if(!this.isCookieless()){for(let e of ["anonymous_id","distinct_id","linked_anonymous_id","session"])this.config.storage.removeItem(`pdx.${this.config.namespace}.${e}`),this.config.sharedStorage.removeItem(`pdx.${this.config.namespace}.${e}`);for(let e of this.gates)e.close();this.identity.refresh(),this.cookielessId!==void 0&&this.identity.assumeAnonymousId(this.cookielessId);}}consent(){return this.identity.consent()}alias(e){this.capture(u.createAlias,{properties:{alias:e}});}group(e,t,n){let i={$group_key:t,$group_type:e};n&&(i.$set=n),this.capture(u.group,{properties:i});}setPersonProperties(e,t){if(this.isCookieless())return;let n={};e&&(n.$set=e),t&&(n.$set_once=t),this.capture(u.set,{properties:n});}setPersonTraits(e){if(this.isCookieless())return;let t=B(e);Object.keys(t).length!==0&&this.capture(u.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(Ie=>Ie.key===e),r=await this.localContext(t,n.flags),a=i?b(i,n.flags,r):null,c=i?v(i,n.flags,r).enabled:false;return this.recordExposure(e,a?.key??String(c)),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(u.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 me(t.flags,await this.localContext(e,t.flags))}async isFeatureEnabledLocal(e,t={}){let n=await this.flagSnapshot(),i=n.flags.find(c=>c.key===e),r=await this.localContext(t,n.flags),a=i?v(i,n.flags,r).enabled:false;return this.recordExposure(e,(i?b(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&&ge(t)){let r=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===n&&r-this.membershipCache.fetchedAt<Ce?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<Ce)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 M({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 getSurveys(e){return this.surveysClient.surveys(this.identity.getDistinctId(),e??this.config.locale)}captureSurveyShown(e){this.capture(fe,{properties:C(e,{})});}captureSurveyDismissed(e){this.capture(ye,{properties:C(e,{})});}captureSurveySent(e,t){this.capture(ve,{properties:C(e,t)});}async getGuides(){return this.guidesClient.guides(this.identity.getDistinctId())}captureGuide(e,t,n){this.capture(e,{properties:Se(t,n)});}async getForm(e){return this.formsClient.form(e,this.identity.getDistinctId())}async submitForm(e,t,n,i){let{$page_id:r,$page_variant:a}=this.config.defaultProperties();return this.formsClient.submit(e,{answers:t,challenge:n,distinctId:this.identity.getDistinctId(),isAnonymous:!this.identity.isIdentified(),pageUrl:typeof window>"u"?"":window.location.href,solution:i,...typeof r=="string"&&typeof a=="string"?{pageId:r,pageVariant:a}:{}})}async getCtas(e){return this.ctasClient.ctas({...e,anonymous:!this.identity.isIdentified(),distinctId:this.identity.getDistinctId()})}captureCta(e,t,n){this.capture(e,{properties:we(t,n)});}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(We);try{await this.transport.send({body:{events:e,sent_at:x(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}.${Qe}`}};function Bs(s){return new H(s)}export{Bs as $,j as A,Ft as B,Ct as C,C as D,Pt as E,Rt as F,Mt as G,qt as H,Kt as I,Ot as J,I as K,be as L,je as M,Dt as N,Nt as O,Lt as P,Se as Q,V as R,Gt as S,A as T,Fs as U,u as V,Ue as W,Wt as X,Yt as Y,P as Z,H as _,m as a,Ye as b,X as c,Re as d,ee as e,ie as f,re as g,qe as h,rs as i,os as j,as as k,de as l,pe as m,gt as n,me as o,ft as p,yt as q,_ as r,bs as s,Ss as t,U as u,fe as v,ye as w,ve as x,F as y,De as z};//# sourceMappingURL=chunk-YHIIKYUP.js.map
2
+ //# sourceMappingURL=chunk-YHIIKYUP.js.map
@@ -16,6 +16,10 @@ interface ChatUpload {
16
16
  contentType: string;
17
17
  bytes: number;
18
18
  }
19
+ type UploadRefusalCode = 'ATTACHMENT_REFUSED' | 'ATTACHMENT_UNCHECKED';
20
+ interface ChatUploadRefusal {
21
+ refusal: UploadRefusalCode;
22
+ }
19
23
  interface ChatAttachment extends ChatUpload {
20
24
  url: string;
21
25
  }
@@ -98,7 +102,7 @@ declare class ChatClient {
98
102
  ensureThread(subject?: string): Promise<boolean>;
99
103
  cameFrom(article: ArticleRef): void;
100
104
  send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
101
- upload(file: File): Promise<ChatUpload | null>;
105
+ upload(file: File, refusalOf?: (text: string) => ChatUploadRefusal | null): Promise<ChatUpload | ChatUploadRefusal | null>;
102
106
  file(path: string): Promise<Blob | null>;
103
107
  helpCentre<T>(suffix: string, params: Record<string, string>, body?: Record<string, string>): Promise<T | null>;
104
108
  get visitor(): (ChatIdentity & {
@@ -225,6 +229,12 @@ interface MessengerAttachments {
225
229
  enabled: boolean;
226
230
  maxBytes: number;
227
231
  accept: string[];
232
+ words?: AttachmentWords;
233
+ }
234
+ interface AttachmentWords {
235
+ refused: string;
236
+ unchecked: string;
237
+ tryAgain: string;
228
238
  }
229
239
  interface MessengerConfigOptions {
230
240
  apiKey: string;
@@ -240,4 +250,4 @@ declare const cacheKeyFor: (apiKey: string, locale: string | undefined) => strin
240
250
  declare function cachedMessengerConfig(storage: ChatStorage | undefined, apiKey: string, locale?: string): MessengerConfig | null;
241
251
  declare function fetchMessengerConfig(options: MessengerConfigOptions): Promise<MessengerConfig | null>;
242
252
 
243
- export { type ArticleRef as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, cacheKeyFor as E, type FileFetchLike as F, cachedMessengerConfig as G, type HelpWords as H, fetchMessengerConfig as I, localeCandidates as J, type LauncherContent as L, type MessengerAttachments as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type TicketWords as T, type ArticleReaction as a, type ArticleHit as b, type ArticleCollection as c, type AppearanceSettings as d, type ChatTurn as e, type ChatUpload as f, type ChatIdentity as g, type MessengerConfig as h, type ChatClientOptions as i, type BubbleShape as j, type ChatAttachment as k, ChatClient as l, type ChatStorage as m, type ComposerShape as n, type FileResponseLike as o, type LauncherFill as p, type LauncherShape as q, type LauncherSize as r, type MessengerSkin as s, type StampPlacement as t, resolveAppearance as u, MESSENGER_CACHE_KEY as v, type MessengerConfigOptions as w, type MessengerHelp as x, type MessengerTickets as y, type StarterPrompt as z };
253
+ export { type ArticleRef as A, type BubbleFill as B, type ChatUploadRefusal as C, DEFAULT_APPEARANCE_SETTINGS as D, type MessengerTickets as E, type FileFetchLike as F, type StarterPrompt as G, type HelpWords as H, cacheKeyFor as I, cachedMessengerConfig as J, fetchMessengerConfig as K, type LauncherContent as L, type MessengerAttachments as M, type NamePlacement as N, localeCandidates as O, type PageContext as P, type StampContent as S, type TicketWords as T, type UploadRefusalCode as U, type ArticleReaction as a, type ArticleHit as b, type ArticleCollection as c, type AppearanceSettings as d, type ChatThread as e, type ChatTurn as f, type ChatUpload as g, type ChatIdentity as h, type MessengerConfig as i, type ChatClientOptions as j, type BubbleShape as k, type ChatAttachment as l, ChatClient as m, type ChatStorage as n, type ComposerShape as o, type FileResponseLike as p, type LauncherFill as q, type LauncherShape as r, type LauncherSize as s, type MessengerSkin as t, type StampPlacement as u, resolveAppearance as v, type AttachmentWords as w, MESSENGER_CACHE_KEY as x, type MessengerConfigOptions as y, type MessengerHelp as z };
@@ -16,6 +16,10 @@ interface ChatUpload {
16
16
  contentType: string;
17
17
  bytes: number;
18
18
  }
19
+ type UploadRefusalCode = 'ATTACHMENT_REFUSED' | 'ATTACHMENT_UNCHECKED';
20
+ interface ChatUploadRefusal {
21
+ refusal: UploadRefusalCode;
22
+ }
19
23
  interface ChatAttachment extends ChatUpload {
20
24
  url: string;
21
25
  }
@@ -98,7 +102,7 @@ declare class ChatClient {
98
102
  ensureThread(subject?: string): Promise<boolean>;
99
103
  cameFrom(article: ArticleRef): void;
100
104
  send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
101
- upload(file: File): Promise<ChatUpload | null>;
105
+ upload(file: File, refusalOf?: (text: string) => ChatUploadRefusal | null): Promise<ChatUpload | ChatUploadRefusal | null>;
102
106
  file(path: string): Promise<Blob | null>;
103
107
  helpCentre<T>(suffix: string, params: Record<string, string>, body?: Record<string, string>): Promise<T | null>;
104
108
  get visitor(): (ChatIdentity & {
@@ -225,6 +229,12 @@ interface MessengerAttachments {
225
229
  enabled: boolean;
226
230
  maxBytes: number;
227
231
  accept: string[];
232
+ words?: AttachmentWords;
233
+ }
234
+ interface AttachmentWords {
235
+ refused: string;
236
+ unchecked: string;
237
+ tryAgain: string;
228
238
  }
229
239
  interface MessengerConfigOptions {
230
240
  apiKey: string;
@@ -240,4 +250,4 @@ declare const cacheKeyFor: (apiKey: string, locale: string | undefined) => strin
240
250
  declare function cachedMessengerConfig(storage: ChatStorage | undefined, apiKey: string, locale?: string): MessengerConfig | null;
241
251
  declare function fetchMessengerConfig(options: MessengerConfigOptions): Promise<MessengerConfig | null>;
242
252
 
243
- export { type ArticleRef as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, cacheKeyFor as E, type FileFetchLike as F, cachedMessengerConfig as G, type HelpWords as H, fetchMessengerConfig as I, localeCandidates as J, type LauncherContent as L, type MessengerAttachments as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type TicketWords as T, type ArticleReaction as a, type ArticleHit as b, type ArticleCollection as c, type AppearanceSettings as d, type ChatTurn as e, type ChatUpload as f, type ChatIdentity as g, type MessengerConfig as h, type ChatClientOptions as i, type BubbleShape as j, type ChatAttachment as k, ChatClient as l, type ChatStorage as m, type ComposerShape as n, type FileResponseLike as o, type LauncherFill as p, type LauncherShape as q, type LauncherSize as r, type MessengerSkin as s, type StampPlacement as t, resolveAppearance as u, MESSENGER_CACHE_KEY as v, type MessengerConfigOptions as w, type MessengerHelp as x, type MessengerTickets as y, type StarterPrompt as z };
253
+ export { type ArticleRef as A, type BubbleFill as B, type ChatUploadRefusal as C, DEFAULT_APPEARANCE_SETTINGS as D, type MessengerTickets as E, type FileFetchLike as F, type StarterPrompt as G, type HelpWords as H, cacheKeyFor as I, cachedMessengerConfig as J, fetchMessengerConfig as K, type LauncherContent as L, type MessengerAttachments as M, type NamePlacement as N, localeCandidates as O, type PageContext as P, type StampContent as S, type TicketWords as T, type UploadRefusalCode as U, type ArticleReaction as a, type ArticleHit as b, type ArticleCollection as c, type AppearanceSettings as d, type ChatThread as e, type ChatTurn as f, type ChatUpload as g, type ChatIdentity as h, type MessengerConfig as i, type ChatClientOptions as j, type BubbleShape as k, type ChatAttachment as l, ChatClient as m, type ChatStorage as n, type ComposerShape as o, type FileResponseLike as p, type LauncherFill as q, type LauncherShape as r, type LauncherSize as s, type MessengerSkin as t, type StampPlacement as u, resolveAppearance as v, type AttachmentWords as w, MESSENGER_CACHE_KEY as x, type MessengerConfigOptions as y, type MessengerHelp as z };
@@ -1,20 +1,51 @@
1
- (function(){'use strict';var gt=Object.defineProperty;var mt=(t,e,n)=>e in t?gt(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var b=(t,e,n)=>mt(t,typeof e!="symbol"?e+"":e,n);var L=class extends Error{constructor(n,r,o){super(r,o);b(this,"code");this.code=n,this.name="ProdantixError";}};var C=class extends L{constructor(n,r,o){super("transport",n,o);b(this,"status");this.status=r,this.name="TransportError";}};function U(t){let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}var E=class{constructor(){b(this,"store",new Map);}getItem(e){var n;return (n=this.store.get(e))!=null?n:null}removeItem(e){this.store.delete(e);}setItem(e,n){this.store.set(e,n);}};function M(){try{let t=globalThis.localStorage;if(t){let e="__pdx_probe__";return t.setItem(e,"1"),t.removeItem(e),t}}catch(t){return new E}return new E}function yt(){return globalThis.crypto}function ht(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 ft(){let t=yt();if(t!=null&&t.randomUUID)return t.randomUUID();let e=new Uint8Array(16);if(t!=null&&t.getRandomValues)t.getRandomValues(e);else for(let n=0;n<16;n+=1)e[n]=Math.floor(Math.random()*256);return ht(e)}var J={uuid:ft};function V(t){return t.slice(0,16)}function F(t,e){return `pdx.${t}.${e}`}var z="consent",xt=["identityLink","analytics","marketing","functional"];function N(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,r={};for(let o of xt){let i=n[o];typeof i=="boolean"&&(r[o]=i);}return typeof n.version=="number"&&Number.isInteger(n.version)&&(r.version=n.version),Array.isArray(n.categories)&&n.categories.every(o=>typeof o=="string")&&(r.categories=n.categories),Object.keys(r).length===0?null:r}catch(e){return null}}var P=t=>F(t,"anonymous_id");function R(t,e){return N(t.getItem(F(e,z)))}function W(t,e,n){var s;let r=F(e,z),o=N(JSON.stringify(n)),i=o===null?null:N(JSON.stringify({...(s=R(t,e))!=null?s:{},...o}));if(i===null){t.removeItem(r);return}t.setItem(r,JSON.stringify(i));}var k=["analytics","marketing","functional"],G="prodantix:consent-ready",q="prodantix:consent",Y="__prodantixConsent",X=(t,e)=>{var r;if(t===null||t.version===void 0)return true;let n=(r=t.categories)!=null?r:[];return e.categories.some(o=>!n.includes(o))},Q=(t,e)=>({analytics:t.categories.includes("analytics")&&e.has("analytics"),categories:[...t.categories],functional:t.categories.includes("functional")&&e.has("functional"),marketing:t.categories.includes("marketing")&&e.has("marketing"),version:t.version}),B=t=>new Set(k.filter(e=>(t==null?void 0:t[e])===true));var Z="prodantix-consent-style",bt=`
2
- .pdx-consent{position:fixed;z-index:2147483000;left:0;right:0;box-sizing:border-box;padding:16px;font:14px/1.5 system-ui,sans-serif;color:var(--pdx-consent-text);background:var(--pdx-consent-background);box-shadow:0 -2px 12px rgba(0,0,0,.15)}
1
+ (function(){'use strict';var ft=Object.defineProperty;var yt=(t,e,n)=>e in t?ft(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var A=(t,e,n)=>yt(t,typeof e!="symbol"?e+"":e,n);var O=class extends Error{constructor(n,r,o){super(r,o);A(this,"code");this.code=n,this.name="ProdantixError";}};var M=class extends O{constructor(n,r,o){super("transport",n,o);A(this,"status");this.status=r,this.name="TransportError";}};function G(t){let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}var B=class{constructor(){A(this,"store",new Map);}getItem(e){var n;return (n=this.store.get(e))!=null?n:null}removeItem(e){this.store.delete(e);}setItem(e,n){this.store.set(e,n);}};function H(){try{let t=globalThis.localStorage;if(t){let e="__pdx_probe__";return t.setItem(e,"1"),t.removeItem(e),t}}catch(t){return new B}return new B}function bt(){return globalThis.crypto}function vt(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 kt(){let t=bt();if(t!=null&&t.randomUUID)return t.randomUUID();let e=new Uint8Array(16);if(t!=null&&t.getRandomValues)t.getRandomValues(e);else for(let n=0;n<16;n+=1)e[n]=Math.floor(Math.random()*256);return vt(e)}var q={uuid:kt};function Y(t){return t.slice(0,16)}function j(t,e){return `pdx.${t}.${e}`}var X="consent",St=["identityLink","analytics","marketing","functional"];function K(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,r={};for(let o of St){let i=n[o];typeof i=="boolean"&&(r[o]=i);}return typeof n.version=="number"&&Number.isInteger(n.version)&&(r.version=n.version),Array.isArray(n.categories)&&n.categories.every(o=>typeof o=="string")&&(r.categories=n.categories),Object.keys(r).length===0?null:r}catch(e){return null}}var U=t=>j(t,"anonymous_id");function z(t,e){return K(t.getItem(j(e,X)))}function Q(t,e,n){var s;let r=j(e,X),o=K(JSON.stringify(n)),i=o===null?null:K(JSON.stringify({...(s=z(t,e))!=null?s:{},...o}));if(i===null){t.removeItem(r);return}t.setItem(r,JSON.stringify(i));}var E=["analytics","marketing","functional"],Z="prodantix:consent-ready",tt="prodantix:consent",et="__prodantixConsent",nt=(t,e)=>{var r;if(t===null||t.version===void 0)return true;let n=(r=t.categories)!=null?r:[];return e.categories.some(o=>!n.includes(o))},ot=(t,e)=>({analytics:t.categories.includes("analytics")&&e.has("analytics"),categories:[...t.categories],functional:t.categories.includes("functional")&&e.has("functional"),marketing:t.categories.includes("marketing")&&e.has("marketing"),version:t.version}),J=t=>new Set(E.filter(e=>(t==null?void 0:t[e])===true));var rt="prodantix-consent-style",wt=`
2
+ .pdx-consent,.pdx-consent-dialog{color-scheme:light dark;--pdx-text:light-dark(oklch(0% 0 0/.93),oklch(100% 0 0));--pdx-text-2:light-dark(color-mix(in oklab,var(--pdx-text) 85%,transparent),color-mix(in oklab,var(--pdx-text) 70%,transparent));--pdx-surface:light-dark(oklch(97% .0029 264.54),oklch(26.5% .0157 256.82));--pdx-divider:light-dark(color-mix(in oklab,var(--pdx-text) 17.2%,transparent),color-mix(in oklab,var(--pdx-text) 12%,transparent));--pdx-hover:light-dark(color-mix(in oklab,var(--pdx-text) 4.6%,transparent),color-mix(in oklab,var(--pdx-text) 8%,transparent));--pdx-success:light-dark(oklch(52.4% .1274 163.23),oklch(69.51% .1809 145.62));box-sizing:border-box;font:14px/1.5 Geist,-apple-system,BlinkMacSystemFont,'Segoe UI',Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',sans-serif;color:var(--pdx-text)}
3
+ .pdx-consent *,.pdx-consent-dialog *{box-sizing:border-box}
4
+ .pdx-consent{position:fixed;z-index:2147483000;background:var(--pdx-surface);border:1px solid var(--pdx-divider)}
5
+ .pdx-consent[data-layout="box"]{bottom:24px;left:24px;width:min(420px,calc(100vw - 32px));padding:20px;border-radius:12px;box-shadow:0 16px 40px rgba(0,0,0,.2)}
6
+ .pdx-consent[data-layout^="bar"]{left:0;right:0;display:flex;flex-wrap:wrap;gap:12px 24px;align-items:center;justify-content:space-between;padding:20px 24px;border-width:1px 0;box-shadow:0 8px 24px rgba(0,0,0,.16)}
3
7
  .pdx-consent[data-layout="bar_bottom"]{bottom:0}
4
8
  .pdx-consent[data-layout="bar_top"]{top:0}
5
- .pdx-consent[data-layout="box"]{left:16px;right:auto;bottom:16px;max-width:360px;border-radius:var(--pdx-consent-radius)}
6
- .pdx-consent h2{margin:0 0 4px;font-size:16px}
7
- .pdx-consent p{margin:0 0 12px}
9
+ .pdx-consent-title{margin:0 0 4px;font-size:16px;font-weight:600}
10
+ .pdx-consent-body,.pdx-consent-intro{margin:0;max-width:62ch;color:var(--pdx-text-2)}
11
+ .pdx-consent[data-layout="box"] .pdx-consent-body{margin-bottom:16px}
12
+ .pdx-consent a{color:var(--pdx-text);text-decoration:underline;text-underline-offset:2px}
8
13
  .pdx-consent-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
9
- .pdx-consent-choice{min-width:120px;min-height:44px;padding:0 16px;font:inherit;font-weight:600;color:var(--pdx-consent-button-text);background:var(--pdx-consent-button);border:0;border-radius:var(--pdx-consent-radius);cursor:pointer}
10
- .pdx-consent-link{min-height:44px;padding:0 8px;font:inherit;color:inherit;text-decoration:underline;background:none;border:0;cursor:pointer}
11
- .pdx-consent-choice:focus-visible,.pdx-consent-link:focus-visible,.pdx-consent input:focus-visible{outline:2px solid currentColor;outline-offset:2px}
14
+ .pdx-consent-button{min-height:44px;padding:0 16px;font:inherit;font-weight:600;border:1px solid transparent;border-radius:8px;cursor:pointer}
15
+ .pdx-consent-button[data-variant="contained"]{color:#fff;background:var(--pdx-accent);border-color:var(--pdx-accent)}
16
+ .pdx-consent-button[data-variant="outlined"]{color:var(--pdx-text);background:transparent;border-color:var(--pdx-divider)}
17
+ .pdx-consent-button[data-variant="outlined"]:hover{background:var(--pdx-hover)}
18
+ .pdx-consent :focus-visible,.pdx-consent-dialog :focus-visible{outline:2px solid var(--pdx-text);outline-offset:2px}
19
+ .pdx-consent-meta{width:100%;margin:12px 0 0;font-size:12px;color:var(--pdx-text-2)}
12
20
  .pdx-consent-dialog{position:fixed;inset:0;z-index:2147483001;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(0,0,0,.4)}
13
- .pdx-consent-panel{box-sizing:border-box;width:100%;max-width:480px;max-height:100%;overflow:auto;padding:20px;font:14px/1.5 system-ui,sans-serif;color:var(--pdx-consent-text);background:var(--pdx-consent-background);border-radius:var(--pdx-consent-radius)}
14
- .pdx-consent-panel h2{margin:0 0 12px;font-size:16px}
15
- .pdx-consent-category{display:flex;gap:12px;align-items:flex-start;padding:8px 0;border-top:1px solid currentColor}
16
- .pdx-consent-category input{width:20px;height:20px;margin:2px 0 0}
17
- .pdx-consent-meta{margin:12px 0 0;font-size:12px;opacity:.8}
18
- `,kt=t=>{if(t.getElementById(Z))return;let e=t.createElement("style");e.id=Z,e.textContent=bt,t.head.append(e);},tt=(t,e)=>{t.style.setProperty("--pdx-consent-background",e.style.background),t.style.setProperty("--pdx-consent-text",e.style.text),t.style.setProperty("--pdx-consent-button",e.style.button),t.style.setProperty("--pdx-consent-button-text",e.style.buttonText),t.style.setProperty("--pdx-consent-radius",`${e.style.radius}px`);},v=(t,e,n,r,o)=>{let i=t.createElement("button");return i.type="button",i.className=n==="choice"?"pdx-consent-choice":"pdx-consent-link",i.textContent=e,i.dataset.testid=r,i.addEventListener("click",o),i},et=(t,e,n,r)=>{kt(t);let o=e.texts,i=k.filter(d=>e.categories.includes(d)),s=null,g=null,y=null,h=()=>{g==null||g.remove(),g=null,y==null||y.focus();},p=d=>{h(),s==null||s.remove(),s=null,n.onAnswer(d);},l=d=>{var j;if(g)return;y=t.activeElement instanceof HTMLElement?t.activeElement:null;let u=t.createElement("div");u.className="pdx-consent-dialog";let a=t.createElement("div");a.className="pdx-consent-panel",a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true"),a.setAttribute("aria-labelledby","pdx-consent-settings-title"),a.dataset.testid="prodantix-consent-settings",tt(a,e);let c=t.createElement("h2");c.id="pdx-consent-settings-title",c.textContent=o.settings,a.append(c);let S=new Map,H=(m,w,pt,ut)=>{let $=t.createElement("label");$.className="pdx-consent-category";let x=t.createElement("input");x.type="checkbox",x.checked=pt,x.disabled=ut,x.dataset.testid=`prodantix-consent-category-${m}`;let K=t.createElement("span");return K.textContent=w,$.append(x,K),a.append($),x};H("necessary",o.necessary,true,true);for(let m of i)S.set(m,H(m,o[m],d.has(m),false));let T=t.createElement("div");T.className="pdx-consent-actions",T.append(v(t,o.save,"choice","prodantix-consent-save",()=>p(new Set(i.filter(m=>{var w;return ((w=S.get(m))==null?void 0:w.checked)===true})))),v(t,o.acceptAll,"choice","prodantix-consent-settings-accept",()=>p(new Set(i))),v(t,o.rejectAll,"choice","prodantix-consent-settings-reject",()=>p(new Set))),a.append(T),u.append(a),u.addEventListener("keydown",m=>{m.key==="Escape"&&h();}),t.body.append(u),g=u,(j=a.querySelector("input:not([disabled])"))==null||j.focus();};if(r){s=t.createElement("section"),s.className="pdx-consent",s.dataset.layout=e.layout,s.dataset.testid="prodantix-consent-banner",s.setAttribute("aria-label",o.title),tt(s,e);let d=t.createElement("h2");d.textContent=o.title;let u=t.createElement("p");u.textContent=o.body,s.append(d,u);let a=t.createElement("div");if(a.className="pdx-consent-actions",a.append(v(t,o.acceptAll,"choice","prodantix-consent-accept",()=>p(new Set(i))),v(t,o.rejectAll,"choice","prodantix-consent-reject",()=>p(new Set)),v(t,o.settings,"link","prodantix-consent-open-settings",()=>l(new Set))),e.policyUrl.startsWith("https://")){let c=t.createElement("a");c.className="pdx-consent-link",c.href=e.policyUrl,c.rel="noopener",c.target="_blank",c.textContent=o.policyLabel||e.policyUrl,a.append(c);}if(s.append(a),e.poweredBy){let c=t.createElement("p");c.className="pdx-consent-meta",c.textContent=e.poweredByText,s.append(c);}t.body.append(s);}return {openSettings:l,remove:()=>{h(),s==null||s.remove(),s=null;}}};var vt='script[type="text/plain"][data-prodantix-consent]',A=(t,e)=>{let n=0;for(let r of Array.from(t.querySelectorAll(vt))){let o=r.dataset.prodantixConsent;if(o===void 0||!e.has(o))continue;let i=t.createElement("script");for(let s of Array.from(r.attributes))s.name!=="type"&&s.name!=="data-prodantix-consent"&&i.setAttribute(s.name,s.value);i.text=r.text,r.replaceWith(i),n+=1;}return n};var nt=(t,e,n)=>{t.win.dispatchEvent(new CustomEvent(e,{detail:n}));},ot=async t=>{let e=await t.fetch(`${t.edge}/v1/consent?language=${encodeURIComponent(t.language)}`,{headers:{authorization:`Bearer ${t.apiKey}`},method:"GET"});if(!e.ok)throw new C("the consent banner could not be read",e.status);let n=JSON.parse(await e.text()),r=R(t.shared,t.namespace),o=n.banner,i=o!==null&&r!==null&&!X(r,o)?r:null,s={anonymousId:n.anonymousId,consent:i,rule:n.rule};if(t.win[Y]=s,nt(t,G,s),o===null)return A(t.doc,new Set(k)),{openSettings:()=>{}};A(t.doc,i!==null?B(i):n.rule==="notice"?new Set(k):new Set);let g=p=>{var u,a,c;let l=Q(o,p),d=n.anonymousId;l.analytics===true&&(d=(u=t.shared.getItem(P(t.namespace)))!=null?u:t.ids.uuid(),t.shared.setItem(P(t.namespace),d)),W(t.shared,t.namespace,l),s.consent=l,nt(t,q,l),A(t.doc,p),t.fetch(`${t.edge}/v1/consent`,{body:JSON.stringify({analytics:l.analytics===true,distinctId:d,functional:l.functional===true,marketing:l.marketing===true,pageUrl:(c=(a=t.doc.location)==null?void 0:a.href)!=null?c:"",version:o.version}),headers:{authorization:`Bearer ${t.apiKey}`,"content-type":"application/json"},method:"POST"}).then(S=>{S.ok||t.onError(new C("the consent answer could not be kept",S.status));}).catch(t.onError);},y=et(t.doc,o,{onAnswer:g},i===null),h=()=>y.openSettings(B(s.consent));return t.doc.addEventListener("click",p=>{var d,u;(u=(d=p.target)==null?void 0:d.closest)!=null&&u.call(d,"[data-prodantix-consent-settings]")&&(p.preventDefault(),h());}),{openSettings:h}};var St=/^\d{1,3}(\.\d{1,3}){3}$/,Ct=/^[a-z0-9.-]+$/i;function rt(){return Math.random().toString(36).slice(2,12)}function _(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 I(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function st(t,e,n,r){try{let o=`pdx_probe_${r()}`,i=r();t.cookie=`${o}=${i}; ${I(e,60,n)}`;let s=_(t,o).includes(i);t.cookie=`${o}=; ${I(e,0,n)}`;let g=_(t,o).includes(i);return s&&!g}catch(o){return false}}function It(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||St.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 wt(t,e,n,r=rt){for(let o of It(t))if(st(e,o,n,r))return o}function Et(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 D=class{constructor(e,n,r,o){this.jar=e;this.name=n;this.domain=r;this.secure=o;}getItem(e){var n;return (n=this.read().get(e))!=null?n: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=_(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${I(void 0,0,this.secure)}`,e=_(this.jar,this.name));let n=e[0];return n?Et(n):new Map}catch(e){return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${I(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${I(this.domain,31536e3,this.secure)}`;}catch(n){return}}};function At(){return globalThis.document}function _t(){var t,e;return (e=(t=globalThis.location)==null?void 0:t.hostname)!=null?e:""}function Tt(){var t;return ((t=globalThis.location)==null?void 0:t.protocol)==="https:"}function $t(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Ct.test(e)?e.toLowerCase():void 0}function it(t){var s,g,y,h,p;let e="jar"in t?t.jar:At();if(!e||((s=globalThis.navigator)==null?void 0:s.cookieEnabled)===false)return null;let r=(g=t.random)!=null?g:rt,o=(y=t.secure)!=null?y:Tt(),i=(h=t.hostname)!=null?h:_t();try{let l=(p=$t(t.domain))!=null?p:wt(i,e,o,r);return st(e,l,o,r)?new D(e,t.name,l,o):null}catch(l){return null}}var f=document.currentScript,O=f==null?void 0:f.dataset.key,at=U(),dt,ct,lt;if(f&&O&&at){let t=V(O),e=M();try{e=(dt=it({name:`pdx_${t}`}))!=null?dt:e;}catch(n){e=M();}ot({apiKey:O,doc:document,edge:(ct=f.dataset.edge)!=null?ct:new URL(f.src,window.location.href).origin,fetch:at,ids:J,language:(lt=f.dataset.language)!=null?lt:document.documentElement.lang,namespace:t,onError:n=>console.error("[prodantix] the consent answer could not be kept",n),shared:e,win:window}).then(n=>{window.prodantixConsent=n;}).catch(n=>console.error("[prodantix] the consent banner could not be read",n));}
21
+ .pdx-consent-panel{display:flex;flex-direction:column;width:100%;max-width:640px;max-height:min(720px,100%);background:var(--pdx-surface);border:1px solid var(--pdx-divider);border-radius:12px;box-shadow:0 16px 40px rgba(0,0,0,.2)}
22
+ .pdx-consent-panel h2{margin:0;padding:20px 24px 12px;font-size:16px;font-weight:600}
23
+ .pdx-consent-content{overflow:auto;padding:0 24px}
24
+ .pdx-consent-intro{margin-bottom:16px}
25
+ .pdx-consent-cats{display:flex;flex-direction:column;gap:8px}
26
+ .pdx-consent-cat{position:relative;border:1px solid var(--pdx-divider);border-radius:8px}
27
+ .pdx-consent-head{display:flex;gap:8px;align-items:center;width:100%;min-height:52px;padding:0 140px 0 16px;font:inherit;font-weight:600;color:inherit;text-align:start;background:none;border:0;cursor:pointer}
28
+ .pdx-consent-head::before{content:"";width:6px;height:6px;border:solid currentColor;border-width:0 2px 2px 0;transform:rotate(-45deg)}
29
+ .pdx-consent-head[aria-expanded="true"]::before{transform:rotate(45deg)}
30
+ .pdx-consent-count{font-weight:400;font-size:12px;color:var(--pdx-text-2)}
31
+ .pdx-consent-control{position:absolute;top:0;right:16px;display:flex;align-items:center;height:52px}
32
+ .pdx-consent-chip{padding:2px 8px;font-size:12px;font-weight:600;color:var(--pdx-success);background:color-mix(in oklab,var(--pdx-success) 12%,transparent);border-radius:9999px}
33
+ .pdx-consent-switch{appearance:none;position:relative;width:40px;height:24px;margin:0;background:var(--pdx-divider);border-radius:9999px;cursor:pointer}
34
+ .pdx-consent-switch::after{content:"";position:absolute;top:3px;left:3px;width:18px;height:18px;background:#fff;border-radius:50%;box-shadow:0 1px 2px rgba(16,24,40,.2)}
35
+ .pdx-consent-switch:checked{background:var(--pdx-accent)}
36
+ .pdx-consent-switch:checked::after{transform:translateX(16px)}
37
+ .pdx-consent-detail{padding:0 16px 16px}
38
+ .pdx-consent-detail p{margin:0 0 12px;font-size:12px;color:var(--pdx-text-2)}
39
+ .pdx-consent-table{width:100%;font-size:12px;border-collapse:collapse}
40
+ .pdx-consent-table th{padding:8px 12px;font-size:11px;color:var(--pdx-text-2);text-align:start}
41
+ .pdx-consent-table th,.pdx-consent-table td{border-bottom:1px solid var(--pdx-divider)}
42
+ .pdx-consent-table td{padding:8px 12px;vertical-align:top}
43
+ .pdx-consent-table tr:last-child td{border-bottom:0}
44
+ .pdx-consent-name{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px}
45
+ .pdx-consent-foot{justify-content:flex-end;padding:16px 24px 20px}
46
+ @media (max-width:639px){.pdx-consent-dialog{align-items:flex-end;padding:0}.pdx-consent-panel{max-height:85vh;border-radius:12px 12px 0 0}.pdx-consent-foot .pdx-consent-button{flex:1 1 auto}}
47
+ @media (prefers-reduced-motion:no-preference){.pdx-consent,.pdx-consent-panel{animation:pdx-consent-in .2s ease-out}.pdx-consent-switch::after{transition:transform .15s ease-out}}
48
+ @keyframes pdx-consent-in{from{opacity:0;transform:translateY(8px)}}
49
+ `,Ct={alwaysActive:"Always active",analyticsName:"Analytics",cookieColumn:"Cookie",durationColumn:"Duration",functionalName:"Functional",marketingName:"Marketing",necessaryName:"Necessary",preferencesTitle:"Privacy preferences",providerColumn:"Provider",purposeColumn:"Purpose",visitDuration:"Session"},It={days:"day",hours:"hour",minutes:"minute",months:"month",years:"year"},At=t=>{if(t.getElementById(rt))return;let e=t.createElement("style");e.id=rt,e.textContent=wt,t.head.append(e);},Et=(t,e,n)=>{var r;return t.unit==="visit"?n:new Intl.NumberFormat(e,{style:"unit",unit:It[t.unit],unitDisplay:"long"}).format((r=t.amount)!=null?r:0)},a=(t,e,n="",r="")=>{let o=t.createElement(e);return n&&(o.className=n),r&&(o.textContent=r),o},T=(t,e,n,r,o)=>{let i=a(t,"button","pdx-consent-button",e);return i.type="button",i.dataset.variant=n,i.dataset.testid=r,i.addEventListener("click",o),i},st=(t,e,n,r,o)=>{let i=a(t,"p",e,n);if(r.policyUrl.startsWith("https://")){let s=a(t,"a","",o||r.policyUrl);s.href=r.policyUrl,s.rel="noopener",s.target="_blank",s.dataset.testid="prodantix-consent-policy",i.append(" ",s);}return i},it="button,a[href],input:not([disabled])",at=(t,e,n,r)=>{At(t);let o={...e.texts};for(let[l,p]of Object.entries(Ct))o[l]||(o[l]=p);let i=E.filter(l=>e.categories.includes(l)),s=null,m=null,v=null,S=l=>{l.style.setProperty("--pdx-accent",e.style.accent);},x=()=>{m&&(m.remove(),m=null,v==null||v.focus());},u=l=>{x(),s==null||s.remove(),s=null,n.onAnswer(l);},f=(l,p,g,D)=>{var L,$;let C=a(t,"div","pdx-consent-cat");C.dataset.testid=`prodantix-consent-category-${p}`;let h=a(t,"button","pdx-consent-head",o[`${p}Name`]);h.type="button",h.setAttribute("aria-expanded","false"),h.dataset.testid=`prodantix-consent-category-${p}-head`,h.append(" ",a(t,"span","pdx-consent-count",String(g.length)));let k=a(t,"div","pdx-consent-detail");if(k.hidden=true,k.dataset.testid=`prodantix-consent-category-${p}-detail`,o[p]&&k.append(a(t,"p","",o[p])),g.length>0){let y=a(t,"table","pdx-consent-table"),c=a(t,"tr");for(let d of [o.cookieColumn,o.providerColumn,o.purposeColumn,o.durationColumn]){let b=a(t,"th","",d);b.scope="col",c.append(b);}y.append(a(t,"thead"),a(t,"tbody")),(L=y.tHead)==null||L.append(c);for(let d of g){let b=a(t,"tr");b.append(a(t,"td","pdx-consent-name",d.name),a(t,"td","",d.provider),a(t,"td","",d.purpose),a(t,"td","",Et(d.duration,e.language,o.visitDuration))),($=y.tBodies[0])==null||$.append(b);}k.append(y);}h.addEventListener("click",()=>{let y=h.getAttribute("aria-expanded")!=="true";h.setAttribute("aria-expanded",String(y)),k.hidden=!y;});let _=a(t,"span","pdx-consent-control");_.append(D),C.append(h,_,k),l.append(C);},w=l=>{var y;if(m)return;v=t.activeElement instanceof HTMLElement?t.activeElement:null;let p=a(t,"div","pdx-consent-dialog");S(p);let g=a(t,"div","pdx-consent-panel");g.setAttribute("role","dialog"),g.setAttribute("aria-modal","true"),g.setAttribute("aria-labelledby","pdx-consent-preferences-title"),g.dataset.testid="prodantix-consent-settings";let D=a(t,"h2","",o.preferencesTitle);D.id="pdx-consent-preferences-title";let C=a(t,"div","pdx-consent-content");o.preferencesIntro&&C.append(st(t,"pdx-consent-intro",o.preferencesIntro,e,o.policyLabel));let h=a(t,"div","pdx-consent-cats"),k=c=>e.items.filter(d=>d.category===c),_=a(t,"span","pdx-consent-chip",o.alwaysActive);_.dataset.testid="prodantix-consent-always-active",f(h,"necessary",k("necessary"),_);let L=new Map;for(let c of i){let d=a(t,"input","pdx-consent-switch");d.type="checkbox",d.setAttribute("role","switch"),d.checked=l.has(c),d.setAttribute("aria-checked",String(d.checked)),d.setAttribute("aria-label",o[`${c}Name`]),d.dataset.testid=`prodantix-consent-switch-${c}`,d.addEventListener("change",()=>d.setAttribute("aria-checked",String(d.checked))),L.set(c,d),f(h,c,k(c),d);}C.append(h);let $=a(t,"div","pdx-consent-actions pdx-consent-foot");$.append(T(t,o.rejectAll,"outlined","prodantix-consent-settings-reject",()=>u(new Set)),T(t,o.acceptAll,"outlined","prodantix-consent-settings-accept",()=>u(new Set(i))),T(t,o.save,"contained","prodantix-consent-save",()=>u(new Set(i.filter(c=>{var d;return ((d=L.get(c))==null?void 0:d.checked)===true}))))),g.append(D,C,$),p.append(g),p.addEventListener("keydown",c=>{if(c.key==="Escape"){c.preventDefault(),x();return}if(c.key!=="Tab")return;let d=[...g.querySelectorAll(it)],b=d[0],F=d[d.length-1];c.shiftKey&&t.activeElement===b?(c.preventDefault(),F==null||F.focus()):!c.shiftKey&&t.activeElement===F&&(c.preventDefault(),b==null||b.focus());}),t.body.append(p),m=p,(y=g.querySelector(it))==null||y.focus();};if(r){s=a(t,"section","pdx-consent"),s.dataset.layout=e.layout,s.dataset.testid="prodantix-consent-banner",s.setAttribute("aria-label",o.title),S(s);let l=a(t,"div");l.append(a(t,"p","pdx-consent-title",o.title),st(t,"pdx-consent-body",o.body,e,o.policyLabel));let p=a(t,"div","pdx-consent-actions");p.append(T(t,o.acceptAll,"contained","prodantix-consent-accept",()=>u(new Set(i))),T(t,o.rejectAll,"contained","prodantix-consent-reject",()=>u(new Set)),T(t,o.preferences,"outlined","prodantix-consent-open-settings",()=>w(new Set))),s.append(l,p),e.poweredBy&&s.append(a(t,"p","pdx-consent-meta",e.poweredByText)),t.body.append(s);}return {openSettings:w,remove:()=>{x(),s==null||s.remove(),s=null;}}};var Tt='script[type="text/plain"][data-prodantix-consent]',P=(t,e)=>{let n=0;for(let r of Array.from(t.querySelectorAll(Tt))){let o=r.dataset.prodantixConsent;if(o===void 0||!e.has(o))continue;let i=t.createElement("script");for(let s of Array.from(r.attributes))s.name!=="type"&&s.name!=="data-prodantix-consent"&&i.setAttribute(s.name,s.value);i.text=r.text,r.replaceWith(i),n+=1;}return n};var dt=(t,e,n)=>{t.win.dispatchEvent(new CustomEvent(e,{detail:n}));},ct=async t=>{let e=await t.fetch(`${t.edge}/v1/consent?language=${encodeURIComponent(t.language)}`,{headers:{authorization:`Bearer ${t.apiKey}`},method:"GET"});if(!e.ok)throw new M("the consent banner could not be read",e.status);let n=JSON.parse(await e.text()),r=z(t.shared,t.namespace),o=n.banner,i=o!==null&&r!==null&&!nt(r,o)?r:null,s={anonymousId:n.anonymousId,consent:i,rule:n.rule};if(t.win[et]=s,dt(t,Z,s),o===null)return P(t.doc,new Set(E)),{openSettings:()=>{}};P(t.doc,i!==null?J(i):n.rule==="notice"?new Set(E):new Set);let m=x=>{var w,l,p;let u=ot(o,x),f=n.anonymousId;u.analytics===true&&(f=(w=t.shared.getItem(U(t.namespace)))!=null?w:t.ids.uuid(),t.shared.setItem(U(t.namespace),f)),Q(t.shared,t.namespace,u),s.consent=u,dt(t,tt,u),P(t.doc,x),t.fetch(`${t.edge}/v1/consent`,{body:JSON.stringify({analytics:u.analytics===true,distinctId:f,functional:u.functional===true,marketing:u.marketing===true,pageUrl:(p=(l=t.doc.location)==null?void 0:l.href)!=null?p:"",version:o.version}),headers:{authorization:`Bearer ${t.apiKey}`,"content-type":"application/json"},method:"POST"}).then(g=>{g.ok||t.onError(new M("the consent answer could not be kept",g.status));}).catch(t.onError);},v=at(t.doc,o,{onAnswer:m},i===null),S=()=>v.openSettings(J(s.consent));return t.doc.addEventListener("click",x=>{var f,w;(w=(f=x.target)==null?void 0:f.closest)!=null&&w.call(f,"[data-prodantix-consent-settings]")&&(x.preventDefault(),S());}),{openSettings:S}};var _t=/^\d{1,3}(\.\d{1,3}){3}$/,Lt=/^[a-z0-9.-]+$/i;function pt(){return Math.random().toString(36).slice(2,12)}function R(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 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 lt(t,e,n,r){try{let o=`pdx_probe_${r()}`,i=r();t.cookie=`${o}=${i}; ${N(e,60,n)}`;let s=R(t,o).includes(i);t.cookie=`${o}=; ${N(e,0,n)}`;let m=R(t,o).includes(i);return s&&!m}catch(o){return false}}function $t(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||_t.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 Mt(t,e,n,r=pt){for(let o of $t(t))if(lt(e,o,n,r))return o}function Nt(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 V=class{constructor(e,n,r,o){this.jar=e;this.name=n;this.domain=r;this.secure=o;}getItem(e){var n;return (n=this.read().get(e))!=null?n: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=R(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${N(void 0,0,this.secure)}`,e=R(this.jar,this.name));let n=e[0];return n?Nt(n):new Map}catch(e){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(n){return}}};function Dt(){return globalThis.document}function Ft(){var t,e;return (e=(t=globalThis.location)==null?void 0:t.hostname)!=null?e:""}function Bt(){var t;return ((t=globalThis.location)==null?void 0:t.protocol)==="https:"}function Pt(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Lt.test(e)?e.toLowerCase():void 0}function ut(t){var s,m,v,S,x;let e="jar"in t?t.jar:Dt();if(!e||((s=globalThis.navigator)==null?void 0:s.cookieEnabled)===false)return null;let r=(m=t.random)!=null?m:pt,o=(v=t.secure)!=null?v:Bt(),i=(S=t.hostname)!=null?S:Ft();try{let u=(x=Pt(t.domain))!=null?x:Mt(i,e,o,r);return lt(e,u,o,r)?new V(e,t.name,u,o):null}catch(u){return null}}var I=document.currentScript,W=I==null?void 0:I.dataset.key,gt=G(),mt,xt,ht;if(I&&W&&gt){let t=Y(W),e=H();try{e=(mt=ut({name:`pdx_${t}`}))!=null?mt:e;}catch(n){e=H();}ct({apiKey:W,doc:document,edge:(xt=I.dataset.edge)!=null?xt:new URL(I.src,window.location.href).origin,fetch:gt,ids:q,language:(ht=I.dataset.language)!=null?ht:document.documentElement.lang,namespace:t,onError:n=>console.error("[prodantix] the consent answer could not be kept",n),shared:e,win:window}).then(n=>{window.prodantixConsent=n;}).catch(n=>console.error("[prodantix] the consent banner could not be read",n));}
19
50
  })();//# sourceMappingURL=consent.iife.js.map
20
51
  //# sourceMappingURL=consent.iife.js.map