@cross-deck/web 1.9.1 → 1.10.3
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/CHANGELOG.md +66 -0
- package/README.md +5 -3
- package/dist/crossdeck.umd.min.js +2 -2
- package/dist/crossdeck.umd.min.js.map +1 -1
- package/dist/error-codes.json +1 -1
- package/dist/index.cjs +91 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.mjs +91 -30
- package/dist/index.mjs.map +1 -1
- package/dist/react.cjs +91 -30
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +91 -30
- package/dist/react.mjs.map +1 -1
- package/dist/vue.cjs +91 -30
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.mjs +91 -30
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var Crossdeck=(()=>{var me=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var yt=Object.prototype.hasOwnProperty;var bt=(r,e)=>{for(var t in e)me(r,t,{get:e[t],enumerable:!0})},kt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of gt(e))!yt.call(r,n)&&n!==t&&me(r,n,{get:()=>e[n],enumerable:!(s=mt(e,n))||s.enumerable});return r};var vt=r=>kt(me({},"__esModule",{value:!0}),r);var Ur={};bt(Ur,{CROSSDECK_ERROR_CODES:()=>xe,Crossdeck:()=>dt,CrossdeckClient:()=>G,CrossdeckContracts:()=>ft,CrossdeckError:()=>_,DEFAULT_BASE_URL:()=>Y,MemoryStorage:()=>O,SDK_NAME:()=>A,SDK_VERSION:()=>R,getErrorCode:()=>fe});var _=class r extends Error{constructor(e){super(e.message),this.name="CrossdeckError",this.type=e.type,this.code=e.code,this.requestId=e.requestId,this.status=e.status,this.retryAfterMs=e.retryAfterMs,this.minVersion=e.minVersion,this.surface=e.surface,Object.setPrototypeOf(this,r.prototype)}};async function Oe(r){let e=r.headers.get("x-request-id")??void 0,t=wt(r.headers.get("retry-after")),s;try{s=await r.json()}catch{s=null}let n=s?.error;return n&&typeof n.type=="string"&&typeof n.code=="string"?new _({type:n.type,code:n.code,message:n.message??`HTTP ${r.status}`,requestId:n.request_id??e,status:r.status,retryAfterMs:t,minVersion:typeof n.minVersion=="string"?n.minVersion:void 0,surface:typeof n.surface=="string"?n.surface:void 0}):new _({type:_t(r.status),code:`http_${r.status}`,message:`HTTP ${r.status} ${r.statusText||""}`.trim(),requestId:e,status:r.status,retryAfterMs:t})}function wt(r){if(!r)return;let e=r.trim();if(!e)return;if(/^\d+(\.\d+)?$/.test(e)){let n=Number(e);return!Number.isFinite(n)||n<0?void 0:Math.round(n*1e3)}if(!/[a-zA-Z,/:]/.test(e))return;let t=Date.parse(e);if(!Number.isFinite(t))return;let s=t-Date.now();return s>0?s:0}function _t(r){return r===401?"authentication_error":r===403?"permission_error":r===429?"rate_limit_error":r>=400&&r<500?"invalid_request_error":"internal_error"}var R="1.9.1",A="@cross-deck/web";var Y="https://api.cross-deck.com/v1",St=15e3,X=class{constructor(e){this.config=e}async request(e,t,s={}){if(this.config.localDevMode)return Et(t);let n=this.buildUrl(t,s.query),i={Authorization:`Bearer ${this.config.publicKey}`,"Crossdeck-Sdk-Version":`${A}@${this.config.sdkVersion}`,Accept:"application/json"};s.idempotencyKey&&(i["Idempotency-Key"]=s.idempotencyKey);let a;s.body!==void 0&&(i["Content-Type"]="application/json",a=JSON.stringify(s.body));let o=s.timeoutMs??this.config.timeoutMs??St,c=typeof AbortController<"u"&&o>0?new AbortController:null,l=null;c&&o>0&&(l=setTimeout(()=>c.abort(),o));let d;try{d=await fetch(n,{method:e,headers:i,body:a,keepalive:s.keepalive===!0,signal:c?.signal})}catch(u){let m=c?.signal?.aborted===!0;throw new _({type:"network_error",code:m?"request_timeout":"fetch_failed",message:m?`Request to ${t} aborted after ${o}ms`:u instanceof Error?u.message:"fetch failed"})}finally{l!==null&&clearTimeout(l)}if(!d.ok){let u=await Oe(d);if(this.config.onErrorParsed)try{this.config.onErrorParsed(u)}catch{}throw u}if(d.status!==204)try{return await d.json()}catch{throw new _({type:"internal_error",code:"invalid_json_response",message:"Server returned a 2xx with an unparseable body.",requestId:d.headers.get("x-request-id")??void 0,status:d.status})}}get isLocalDevMode(){return this.config.localDevMode===!0}buildUrl(e,t){let s=this.config.baseUrl.replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`,i=s+n;if(t){let a=new URLSearchParams;for(let[c,l]of Object.entries(t))typeof l=="string"&&l.length>0&&a.append(c,l);let o=a.toString();o&&(i+=(i.includes("?")?"&":"?")+o)}return i}},J=null;function Et(r){return r.startsWith("/sdk/heartbeat")?{object:"heartbeat",ok:!0,projectId:"proj_local_dev",appId:"app_local_dev",platform:"web",env:"sandbox",serverTime:Date.now()}:r.startsWith("/identity/alias")?(J||(J=`cdcust_local_${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID().replace(/-/g,"").slice(0,16):Math.random().toString(36).slice(2,18)}`),{object:"alias_result",crossdeckCustomerId:J,linked:[],mergePending:!1,env:"sandbox"}):r.startsWith("/entitlements")?{object:"list",data:[],crossdeckCustomerId:J??"",env:"sandbox"}:r.startsWith("/events")?{object:"list",received:0,env:"sandbox"}:{}}var K="anon_id",B="cdcust_id",Q=class{constructor(e,t,s){this.primary=e;this.prefix=t;this.secondary=s??null;let n=e.getItem(t+K),i=e.getItem(t+B),a=this.secondary?.getItem(t+K)??null,o=this.secondary?.getItem(t+B)??null,c=n??a,l=i??o;this.state={anonymousId:c??this.mintAnonymousId(),crossdeckCustomerId:l},(!n||!a)&&this.writeBoth(t+K,this.state.anonymousId),l&&(!i||!o)&&this.writeBoth(t+B,l)}get anonymousId(){return this.state.anonymousId}get crossdeckCustomerId(){return this.state.crossdeckCustomerId}setCrossdeckCustomerId(e){this.state.crossdeckCustomerId=e,this.writeBoth(this.prefix+B,e)}reset(){this.deleteBoth(this.prefix+K),this.deleteBoth(this.prefix+B),this.state={anonymousId:this.mintAnonymousId(),crossdeckCustomerId:null},this.writeBoth(this.prefix+K,this.state.anonymousId)}mintAnonymousId(){let e=Date.now().toString(36),t=V(10);return`anon_${e}${t}`}writeBoth(e,t){try{this.primary.setItem(e,t)}catch{}if(this.secondary)try{this.secondary.setItem(e,t)}catch{}}deleteBoth(e){try{this.primary.removeItem(e)}catch{}if(this.secondary)try{this.secondary.removeItem(e)}catch{}}};function V(r){let e="0123456789abcdefghijklmnopqrstuvwxyz",t=[],s=globalThis.crypto;if(s?.getRandomValues){let n=new Uint8Array(r);s.getRandomValues(n);for(let i=0;i<r;i++)t.push(e[n[i]%e.length]??"0")}else for(let n=0;n<r;n++)t.push(e[Math.floor(Math.random()*e.length)]??"0");return t.join("")}var xt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Ct(r){if(typeof TextEncoder<"u")return new TextEncoder().encode(r);let e=[];for(let t=0;t<r.length;t++){let s=r.charCodeAt(t);if(s>=55296&&s<=56319&&t+1<r.length){let n=r.charCodeAt(t+1);n>=56320&&n<=57343&&(s=65536+(s-55296<<10)+(n-56320),t++)}s<128?e.push(s):s<2048?(e.push(192|s>>6),e.push(128|s&63)):s<65536?(e.push(224|s>>12),e.push(128|s>>6&63),e.push(128|s&63)):(e.push(240|s>>18),e.push(128|s>>12&63),e.push(128|s>>6&63),e.push(128|s&63))}return new Uint8Array(e)}function q(r){let e=Ct(r),t=e.length*8,s=Math.floor((e.length+9+63)/64),n=new Uint8Array(s*64);n.set(e),n[e.length]=128;let i=Math.floor(t/4294967296),a=t>>>0,o=n.length-8;n[o+0]=i>>>24&255,n[o+1]=i>>>16&255,n[o+2]=i>>>8&255,n[o+3]=i&255,n[o+4]=a>>>24&255,n[o+5]=a>>>16&255,n[o+6]=a>>>8&255,n[o+7]=a&255;let c=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),l=new Uint32Array(64);for(let u=0;u<s;u++){let m=u*64;for(let f=0;f<16;f++)l[f]=(n[m+f*4]<<24|n[m+f*4+1]<<16|n[m+f*4+2]<<8|n[m+f*4+3])>>>0;for(let f=16;f<64;f++){let w=l[f-15],E=l[f-2],I=(w>>>7|w<<25)^(w>>>18|w<<14)^w>>>3,D=(E>>>17|E<<15)^(E>>>19|E<<13)^E>>>10;l[f]=l[f-16]+I+l[f-7]+D>>>0}let p=c[0],y=c[1],k=c[2],g=c[3],v=c[4],S=c[5],T=c[6],C=c[7];for(let f=0;f<64;f++){let w=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7),E=v&S^~v&T,I=C+w+E+xt[f]+l[f]>>>0,D=(p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10),pt=p&y^p&k^y&k,ht=D+pt>>>0;C=T,T=S,S=v,v=g+I>>>0,g=k,k=y,y=p,p=I+ht>>>0}c[0]=c[0]+p>>>0,c[1]=c[1]+y>>>0,c[2]=c[2]+k>>>0,c[3]=c[3]+g>>>0,c[4]=c[4]+v>>>0,c[5]=c[5]+S>>>0,c[6]=c[6]+T>>>0,c[7]=c[7]+C>>>0}let d="";for(let u=0;u<8;u++)d+=c[u].toString(16).padStart(8,"0");return d}var Tt=1440*60*1e3,Z="_anon",It="_index",P=class r{constructor(e,t="crossdeck:entitlements",s=Tt){this.all=[];this.lastUpdated=0;this.lastRefreshFailedAt=0;this.listeners=new Set;this.listenerErrorCount=0;this.currentSuffix=Z;this.storage=e,this.storageKeyPrefix=t,this.staleAfterMs=s,this.hydrate()}get storageKey(){return`${this.storageKeyPrefix}:${this.currentSuffix}`}get indexKey(){return`${this.storageKeyPrefix}:${It}`}static suffixForUserId(e){return e==null||e===""?Z:q(e)}setUserKey(e){let t=r.suffixForUserId(e);if(t===this.currentSuffix){this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.notify(),this.hydrate();return}this.currentSuffix=t,this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.hydrate(),this.notify()}isEntitled(e){let t=Date.now()/1e3;return this.all.some(s=>s.key===e&&s.isActive&&(s.validUntil==null||s.validUntil>t))}list(){return this.all.slice()}get freshness(){return this.lastUpdated}get isStale(){return this.lastRefreshFailedAt>this.lastUpdated?!0:this.lastUpdated>0&&Date.now()-this.lastUpdated>this.staleAfterMs}get refreshFailedAt(){return this.lastRefreshFailedAt}get listenerErrors(){return this.listenerErrorCount}markRefreshFailed(){this.lastRefreshFailedAt=Date.now()}setFromList(e){this.all=e.slice(),this.lastUpdated=Date.now(),this.lastRefreshFailedAt=0,this.persist(),this.recordSuffixInIndex(this.currentSuffix),this.notify()}clear(){if(this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.storage)try{this.storage.removeItem(this.storageKey)}catch{}this.removeSuffixFromIndex(this.currentSuffix),this.notify()}clearAll(){if(this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.currentSuffix=Z,this.storage){let e=this.readIndex();for(let t of e)try{this.storage.removeItem(`${this.storageKeyPrefix}:${t}`)}catch{}try{this.storage.removeItem(`${this.storageKeyPrefix}:${Z}`)}catch{}try{this.storage.removeItem(this.indexKey)}catch{}}this.notify()}subscribe(e){this.listeners.add(e);let t=!1;return()=>{t||(t=!0,this.listeners.delete(e))}}hydrate(){if(this.storage)try{let e=this.storage.getItem(this.storageKey);if(!e)return;let t=JSON.parse(e);t&&t.v===1&&Array.isArray(t.entitlements)&&(this.all=t.entitlements,this.lastUpdated=typeof t.lastUpdated=="number"?t.lastUpdated:0)}catch{}}persist(){if(this.storage)try{let e={v:1,entitlements:this.all,lastUpdated:this.lastUpdated};this.storage.setItem(this.storageKey,JSON.stringify(e))}catch{}}readIndex(){if(!this.storage)return[];try{let e=this.storage.getItem(this.indexKey);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}recordSuffixInIndex(e){if(!this.storage)return;let t=this.readIndex();if(!t.includes(e)){t.push(e);try{this.storage.setItem(this.indexKey,JSON.stringify(t))}catch{}}}removeSuffixFromIndex(e){if(!this.storage)return;let t=this.readIndex(),s=t.filter(n=>n!==e);if(s.length!==t.length)try{s.length===0?this.storage.removeItem(this.indexKey):this.storage.setItem(this.indexKey,JSON.stringify(s))}catch{}}notify(){if(this.listeners.size===0)return;let e=this.all.slice(),t=[...this.listeners];for(let s of t)try{s(e)}catch{this.listenerErrorCount+=1}}};function Rt(r){return[r.slice(0,8),r.slice(8,12),r.slice(12,16),r.slice(16,20),r.slice(20,32)].join("-")}function L(r){let e;if(r.rail==="apple"?e=r.signedTransactionInfo??"":r.rail==="google"?e=r.purchaseToken??"":e="",!e)throw new Error(`deriveIdempotencyKeyForPurchase: no stable identifier in body (rail=${r.rail}). Apple needs signedTransactionInfo; Google needs purchaseToken.`);let t=`crossdeck:purchases/sync:${r.rail}:${e}`;return Rt(q(t))}function At(r,e,t={},s=Math.random){let n=t.baseMs??1e3,i=t.maxMs??6e4,a=t.factor??2,o=Math.min(r,30),l=Math.min(i,n*Math.pow(a,o))*s();if(e!==void 0){let u=Math.min(864e5,e);if(u>l)return u}return Math.max(0,Math.round(l))}var ee=class{constructor(e={}){this.options=e;this.attempts=0}get consecutiveFailures(){return this.attempts}get isWarning(){return this.attempts>=(this.options.failuresBeforeWarn??8)}nextDelay(e,t=Math.random){let s=At(this.attempts,e,this.options,t);return this.attempts+=1,s}recordSuccess(){this.attempts=0}};var N=1e3,te=class{constructor(e){this.cfg=e;this.buffer=[];this.pendingBatch=null;this.pendingBatchId=null;this.dropped=0;this.inFlight=0;this.lastFlushAt=0;this.lastError=null;this.cancelTimer=null;this.firstFlushFired=!1;this.nextRetryAt=null;this.parked=!1;this.parkWarned=!1;if(this.retry=new ee(e.retry??{}),this.persistent=e.persistentStore??null,this.persistent){let t=this.persistent.load();t.length>0&&(t.length>N?(this.dropped+=t.length-N,this.buffer=t.slice(t.length-N)):this.buffer=t,this.cfg.onBufferChange?.(this.buffer.length),this.scheduleIdleFlush())}}enqueue(e){if(this.buffer.push(e),this.buffer.length>N){let t=this.buffer.length-N;this.buffer.splice(0,t),this.dropped+=t,this.cfg.onDrop?.(t)}this.cfg.onBufferChange?.(this.buffer.length),this.persistAll(),this.buffer.length>=this.cfg.batchSize?this.flush():this.scheduleIdleFlush()}async flush(e={}){if(this.parked)return null;let t,s;if(this.pendingBatch!==null&&this.pendingBatchId!==null)t=this.pendingBatch,s=this.pendingBatchId;else{if(this.buffer.length===0)return null;t=this.buffer.splice(0),s=this.mintBatchId(),this.pendingBatch=t,this.pendingBatchId=s,this.inFlight+=t.length,this.cfg.onBufferChange?.(this.buffer.length),this.persistAll()}this.cancelTimerIfSet(),this.nextRetryAt=null;try{let n=this.cfg.envelope(),i=await this.cfg.http.request("POST","/events",{body:{envelopeVersion:1,appId:n.appId,environment:n.environment,sdk:n.sdk,events:t},keepalive:e.keepalive===!0,idempotencyKey:s});return this.lastFlushAt=Date.now(),this.lastError=null,this.inFlight-=t.length,this.pendingBatch=null,this.pendingBatchId=null,this.retry.recordSuccess(),this.persistAll(),this.firstFlushFired||(this.firstFlushFired=!0,this.cfg.onFirstFlushSuccess?.()),i}catch(n){let i=n instanceof Error?n.message:String(n);if(this.lastError=i,Vt(n)){if(this.parked=!0,this.buffer=[...t,...this.buffer],this.buffer.length>N){let l=this.buffer.length-N;this.buffer.splice(0,l),this.dropped+=l}this.pendingBatch=null,this.pendingBatchId=null,this.inFlight-=t.length,this.persistAll(),this.cfg.onBufferChange?.(this.buffer.length);let c=Ot(n);return this.parkWarned||(this.parkWarned=!0,console.warn(`[Crossdeck] SDK outdated \u2014 the server is no longer accepting this version's event format. Your events are PARKED on-device (held, not lost) and will deliver automatically once you update @cross-deck/web${c?` to >= ${c}`:""} and redeploy.`)),this.cfg.onParked?.({minVersion:c,surface:Ft(n)}),null}if(Dt(n)){let c=t.length;return this.pendingBatch=null,this.pendingBatchId=null,this.inFlight-=c,this.dropped+=c,this.persistAll(),this.cfg.onDrop?.(c),this.cfg.onPermanentFailure?.({status:n.status??0,droppedCount:c,lastError:i}),null}let a=Pt(n),o=this.retry.nextDelay(a);return this.scheduleRetry(o),this.cfg.onRetryScheduled?.({delayMs:o,consecutiveFailures:this.retry.consecutiveFailures,retryAfterMs:a,lastError:i}),null}}reset(){this.cancelTimerIfSet(),this.nextRetryAt=null,this.buffer=[],this.pendingBatch=null,this.pendingBatchId=null,this.dropped=0,this.inFlight=0,this.lastError=null,this.retry.recordSuccess(),this.persistent?.clear(),this.cfg.onBufferChange?.(0)}getStats(){return{buffered:this.buffer.length,dropped:this.dropped,inFlight:this.inFlight,lastFlushAt:this.lastFlushAt,lastError:this.lastError,consecutiveFailures:this.retry.consecutiveFailures,nextRetryAt:this.nextRetryAt}}get pendingIdempotencyKey(){return this.pendingBatchId}persistAll(){if(this.persistent){if(this.pendingBatch===null){this.persistent.save(this.buffer);return}this.persistent.save([...this.pendingBatch,...this.buffer])}}scheduleIdleFlush(){this.cancelTimerIfSet();let e=this.cfg.scheduler??Fe;this.cancelTimer=e(()=>{this.flush()},this.cfg.intervalMs)}scheduleRetry(e){this.cancelTimerIfSet(),this.nextRetryAt=Date.now()+e;let t=this.cfg.scheduler??Fe;this.cancelTimer=t(()=>{this.flush()},e)}cancelTimerIfSet(){this.cancelTimer&&(this.cancelTimer(),this.cancelTimer=null)}mintBatchId(){return`batch_${Date.now().toString(36)}${V(10)}`}};function Pt(r){if(r&&typeof r=="object"&&"retryAfterMs"in r){let e=r.retryAfterMs;return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}}function Dt(r){if(!r||typeof r!="object")return!1;let e=r.status;return!(typeof e!="number"||!Number.isFinite(e)||e<400||e>=500||e===408||e===429||e===426)}function Vt(r){return!r||typeof r!="object"?!1:r.status===426?!0:r.code==="sdk_version_unsupported"}function Ot(r){let e=r?.minVersion;return typeof e=="string"&&e.length>0?e:void 0}function Ft(r){let e=r?.surface;return typeof e=="string"&&e.length>0?e:void 0}function Fe(r,e){let t=setTimeout(r,e);if(typeof t.unref=="function")try{t.unref()}catch{}return()=>clearTimeout(t)}var re=class{constructor(e){this.options=e;this.writeScheduled=!1;this.pendingSnapshot=null;this.key=`${e.prefix}queue.v1`}load(){let e;try{e=this.options.storage.getItem(this.key)}catch{return[]}if(!e)return[];try{let t=JSON.parse(e);return!t||t.version!==1||!Array.isArray(t.events)?[]:t.events}catch{return[]}}save(e){this.pendingSnapshot=e.slice(),!this.writeScheduled&&(this.writeScheduled=!0,queueMicrotask(()=>this.flushWrite()))}saveSync(e){this.pendingSnapshot=e.slice(),this.flushWrite()}clear(){this.pendingSnapshot=null,this.writeScheduled=!1;try{this.options.storage.removeItem(this.key)}catch{}}flushWrite(){this.writeScheduled=!1;let e=this.pendingSnapshot;if(this.pendingSnapshot=null,e===null)return;if(e.length===0){try{this.options.storage.removeItem(this.key)}catch{}return}let t={version:1,events:e};try{this.options.storage.setItem(this.key,JSON.stringify(t))}catch{}}};var O=class{constructor(){this.store=new Map}getItem(e){return this.store.get(e)??null}setItem(e,t){this.store.set(e,t)}removeItem(e){this.store.delete(e)}},se=class{constructor(e){this.maxAgeSec=e?.maxAgeSec??63072e3,this.secure=e?.secure??Lt(),this.sameSite=e?.sameSite??"Lax"}getItem(e){if(!ge())return null;let t=globalThis.document,s=t.cookie?t.cookie.split(/;\s*/):[],n=encodeURIComponent(e)+"=";for(let i of s)if(i.startsWith(n))try{return decodeURIComponent(i.slice(n.length))}catch{return null}return null}setItem(e,t){if(!ge())return;let s=globalThis.document,n=[`${encodeURIComponent(e)}=${encodeURIComponent(t)}`,"Path=/",`Max-Age=${this.maxAgeSec}`,`SameSite=${this.sameSite}`];this.secure&&n.push("Secure");try{s.cookie=n.join("; ")}catch{}}removeItem(e){if(!ge())return;let t=globalThis.document,s=[`${encodeURIComponent(e)}=`,"Path=/","Max-Age=0",`SameSite=${this.sameSite}`];this.secure&&s.push("Secure");try{t.cookie=s.join("; ")}catch{}}};function Le(){try{let r=globalThis.localStorage;if(r){let e="__crossdeck_probe__";return r.setItem(e,"1"),r.removeItem(e),r}}catch{}return new O}function Lt(){try{return globalThis.location?.protocol==="https:"}catch{return!1}}function ge(){return typeof globalThis.document<"u"}var Nt="__crossdeckBucketsBridge__";function ye(r){try{let e=globalThis[Nt];typeof e=="function"&&e(r)}catch{}}function Ut(){return typeof globalThis.window<"u"&&typeof globalThis.document<"u"&&typeof globalThis.navigator<"u"}function Ne(r){let e={};if(r?.appVersion&&(e.appVersion=r.appVersion),!Ut())return e;let t=globalThis.window,s=globalThis.navigator,n=globalThis.document;try{typeof s.language=="string"&&(e.locale=s.language)}catch{}try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}try{t.screen&&(e.screenWidth=t.screen.width,e.screenHeight=t.screen.height),e.viewportWidth=t.innerWidth,e.viewportHeight=t.innerHeight,e.devicePixelRatio=t.devicePixelRatio}catch{}try{let i=s.userAgent??"",a=qt(i);Object.assign(e,a)}catch{}try{let i=s.userAgentData;if(i?.platform&&!e.os&&(e.os=i.platform),i?.brands&&!e.browser){let a=i.brands.find(o=>!/Not[ .;A]*Brand/i.test(o.brand)&&!/Chromium/i.test(o.brand));a&&(e.browser=a.brand,e.browserVersion=a.version)}}catch{}return e}function qt(r){let e={};if(/iPad|iPhone|iPod/.test(r)){e.os="iOS";let t=r.match(/OS (\d+[._]\d+(?:[._]\d+)?)/);t?.[1]&&(e.osVersion=t[1].replace(/_/g,"."))}else if(/Android/.test(r)){e.os="Android";let t=r.match(/Android (\d+(?:\.\d+)*)/);t?.[1]&&(e.osVersion=t[1])}else if(/Windows/.test(r)){e.os="Windows";let t=r.match(/Windows NT (\d+\.\d+)/);t?.[1]&&(e.osVersion=t[1])}else if(/Mac OS X|Macintosh/.test(r)){e.os="macOS";let t=r.match(/Mac OS X (\d+[._]\d+(?:[._]\d+)?)/);t?.[1]&&(e.osVersion=t[1].replace(/_/g,"."))}else/Linux/.test(r)&&(e.os="Linux");return/Edg\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Edge",e.browserVersion=r.match(/Edg\/(\d+(?:\.\d+)*)/)?.[1]):/Firefox\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Firefox",e.browserVersion=r.match(/Firefox\/(\d+(?:\.\d+)*)/)?.[1]):/OPR\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Opera",e.browserVersion=r.match(/OPR\/(\d+(?:\.\d+)*)/)?.[1]):/Chrome\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Chrome",e.browserVersion=r.match(/Chrome\/(\d+(?:\.\d+)*)/)?.[1]):/Version\/(\d+(?:\.\d+)*).*Safari/.test(r)&&(e.browser="Safari",e.browserVersion=r.match(/Version\/(\d+(?:\.\d+)*)/)?.[1]),e}var F={sessions:!0,pageViews:!0,deviceInfo:!0,clicks:!0,webVitals:!0,errors:!0},be=1800*1e3,Mt="crossdeck:session",$t=5e3,ne={utm_source:"",utm_medium:"",utm_campaign:"",utm_content:"",utm_term:"",referrer:"",gclid:"",fbclid:"",msclkid:"",ttclid:"",li_fat_id:"",twclid:""},j=class{constructor(e,t,s){this.cfg=e;this.track=t;this.session=null;this.cleanups=[];this.lastPersistAt=0;this._sessionSeq=0;this.pageviewId=null;this.storage=s?.storage??null,this.sessionKey=s?.storageKey??Mt}install(){qe()&&(this.cfg.sessions&&this.installSessionTracking(),this.cfg.pageViews&&this.installPageViewTracking(),this.cfg.clicks&&this.installClickTracking())}uninstall(){for(;this.cleanups.length;){let e=this.cleanups.pop();try{e?.()}catch{}}this.session&&!this.session.endedSent&&this.emitSessionEnd(),this.clearStoredSession(),this.session=null}resetSession(){this.session&&!this.session.endedSent&&this.emitSessionEnd(),this.pageviewId=null,this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart()}markActivity(){if(!this.session)return;let e=Date.now();if(e-this.session.lastActivityAt>=be){this.pageviewId=null,this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart();return}this.session.lastActivityAt=e,e-this.lastPersistAt>=$t&&this.persistSession()}get currentSessionId(){return this.session?.sessionId??null}get currentPageviewId(){return this.pageviewId}get currentAcquisition(){return this.session?.acquisition??ne}nextSeq(){let e=this._sessionSeq;return this._sessionSeq+=1,e}installSessionTracking(){let e=Date.now(),t=this.readStoredSession();t&&e-t.lastActivityAt<be?(this.session={sessionId:t.id,startedAt:t.startedAt,lastActivityAt:e,hiddenAt:null,endedSent:!1,acquisition:t.acquisition},this.persistSession()):(this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart());let s=()=>{if(!this.session)return;let o=globalThis.document;o.visibilityState==="hidden"?(this.session.hiddenAt=Date.now(),this.persistSession()):o.visibilityState==="visible"&&(Date.now()-this.session.lastActivityAt>=be?(this.pageviewId=null,this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart()):this.session.hiddenAt=null)},n=()=>this.persistSession(),i=globalThis.window,a=globalThis.document;a.addEventListener("visibilitychange",s),i.addEventListener("pagehide",n),i.addEventListener("beforeunload",n),this.cleanups.push(()=>{a.removeEventListener("visibilitychange",s),i.removeEventListener("pagehide",n),i.removeEventListener("beforeunload",n)})}startNewSession(){let e=Date.now();return this._sessionSeq=0,{sessionId:rr(),startedAt:e,lastActivityAt:e,hiddenAt:null,endedSent:!1,acquisition:sr()}}readStoredSession(){if(!this.storage)return null;try{let e=this.storage.getItem(this.sessionKey);if(!e)return null;let t=JSON.parse(e);return!t||typeof t.id!="string"||typeof t.startedAt!="number"||typeof t.lastActivityAt!="number"?null:{id:t.id,startedAt:t.startedAt,lastActivityAt:t.lastActivityAt,acquisition:t.acquisition&&typeof t.acquisition=="object"?t.acquisition:ne}}catch{return null}}persistSession(){if(!(!this.storage||!this.session)){this.lastPersistAt=Date.now();try{let e={id:this.session.sessionId,startedAt:this.session.startedAt,lastActivityAt:this.session.lastActivityAt,acquisition:this.session.acquisition};this.storage.setItem(this.sessionKey,JSON.stringify(e))}catch{}}}clearStoredSession(){if(this.storage)try{this.storage.removeItem(this.sessionKey)}catch{}}emitSessionStart(){this.session&&this.track("session.started",{sessionId:this.session.sessionId})}emitSessionEnd(){if(!this.session||this.session.endedSent)return;let e=Date.now()-this.session.startedAt;this.track("session.ended",{sessionId:this.session.sessionId,durationMs:e}),this.session.endedSent=!0}installPageViewTracking(){let e=globalThis.window,t=globalThis.document,s=0,n="",i=250,a=(m=!1)=>{let p=e.location,y=p.href,k=Date.now();!m&&y===n&&k-s<i||(s=k,n=y,this.pageviewId=`pv_${Date.now().toString(36)}${V(10)}`,this.track("page.viewed",{pageviewId:this.pageviewId,path:p.pathname,url:y,search:p.search||void 0,hash:p.hash||void 0,title:t.title,referrer:t.referrer||void 0}))};a();let o=e.history.pushState,c=e.history.replaceState;function l(m,p,y){o.apply(this,[m,p,y]),queueMicrotask(a)}function d(m,p,y){c.apply(this,[m,p,y]),queueMicrotask(a)}e.history.pushState=l,e.history.replaceState=d;let u=()=>a(!0);e.addEventListener("popstate",u),this.cleanups.push(()=>{e.history.pushState===l&&(e.history.pushState=o),e.history.replaceState===d&&(e.history.replaceState=c),e.removeEventListener("popstate",u)})}installClickTracking(){let e=globalThis.window,t=globalThis.document,s=0,n=null,i=100,a=64,o=c=>{let l=c.target;if(!l||!(l instanceof Element))return;let d=Date.now();if(l===n&&d-s<i)return;s=d,n=l;let m=Kt(l)||l;if(Bt(m)||jt(m)||Wt(m))return;let p=m.tagName.toLowerCase(),y=Zt(Qt(m),a),k=m.href||void 0,g=m.target||void 0,v=m.id||void 0,S=m.getAttribute("role")||void 0,T=m.getAttribute("aria-label")||void 0,C=er(m),f=tr(m),w=p==="a"&&!!k,E=m.getAttribute("data-cd-event"),I={selector:C,tag:p,text:y,elementId:v,role:S,ariaLabel:T,href:k,isLink:w,linkTarget:g,viewportX:c.clientX,viewportY:c.clientY,pageX:c.pageX,pageY:c.pageY,...f};for(let D of Object.keys(I))(I[D]===void 0||I[D]===null||I[D]==="")&&delete I[D];this.track(E||"element.clicked",I)};t.addEventListener("click",o,{capture:!0,passive:!0}),this.cleanups.push(()=>{t.removeEventListener("click",o,{capture:!0})})}};function Kt(r){return r.closest("[data-cd-event]")||r.closest("[data-cd-noTrack]")||r.closest("button, a, [role='button'], [role='link'], input[type='button'], input[type='submit']")||null}function Bt(r){if(!(r instanceof HTMLElement))return!1;let e=r.tagName.toLowerCase();if(e==="textarea"||e==="select")return!0;if(e==="input"){let t=(r.type||"").toLowerCase();return t!=="button"&&t!=="submit"&&t!=="image"&&t!=="reset"}return!1}function jt(r){return!!r.closest("[data-cd-noTrack], [data-cd-no-track], .cd-noTrack, .cd-no-track")}function Wt(r){return!!r.closest('input[type="password"]')}var Ht=new Set(["span","b","strong","em","i","small","mark","u","label","abbr","time","bdi","cite","code","kbd","q","sub","sup"]),zt=new Set(["svg","style","script","noscript"]),Gt="a[href], button, input, select, textarea, [role='button'], [role='link'], h1, h2, h3, h4, h5, h6",Jt="h1, h2, h3, h4, h5, h6";function Ue(r){return r.replace(/\s+/g," ").trim()}function ke(r){let e="",t=s=>{let n=s.childNodes;for(let i=0;i<n.length;i++){let a=n[i];if(a){if(a.nodeType===3)e+=a.textContent||"";else if(a.nodeType===1){if(zt.has(a.tagName.toLowerCase()))continue;e+=" ",t(a),e+=" "}}}};return t(r),Ue(e)}function Xt(r){let e="",t=r.childNodes;for(let s=0;s<t.length;s++){let n=t[s];n&&(n.nodeType===3?e+=" "+(n.textContent||""):n.nodeType===1&&Ht.has(n.tagName.toLowerCase())&&(e+=" "+ke(n)))}return Ue(e)}function Yt(r){if(!(r.querySelector(Gt)!==null))return ke(r);let t=Xt(r);if(t)return t;let s=r.querySelector(Jt);if(s){let n=ke(s);if(n)return n}return""}function Qt(r){let e=l=>l.replace(/\s+/g," ").trim(),t=r.getAttribute("data-cd-track")||r.getAttribute("data-track")||r.getAttribute("data-testid");if(t){let l=e(t);if(l)return l}let s=r.getAttribute("aria-label");if(s){let l=e(s);if(l)return l}let n=r.getAttribute("aria-labelledby");if(n&&typeof r.ownerDocument?.getElementById=="function"){let l=[];for(let d of n.split(/\s+/)){let u=r.ownerDocument.getElementById(d),m=u?.textContent?e(u.textContent):"";m&&l.push(m)}if(l.length>0)return l.join(" ")}if(r instanceof HTMLInputElement&&r.value){let l=e(r.value);if(l)return l}let i=Yt(r);if(i)return i;let a=r.getAttribute("title");if(a){let l=e(a);if(l)return l}let o=r.querySelector("img[alt]");if(o){let l=o.getAttribute("alt")??"",d=e(l);if(d)return d}let c=r.querySelector("svg title");if(c?.textContent){let l=e(c.textContent);if(l)return l}return""}function Zt(r,e){return r.length<=e?r:r.slice(0,e-1)+"\u2026"}function er(r){let e=[],t=r,s=0;for(;t&&t.nodeName.toLowerCase()!=="body"&&s<5;){let n=t.nodeName.toLowerCase();if(t.id){e.unshift(`${n}#${t.id}`);break}if(t.classList.length>0){let i=Array.from(t.classList).filter(a=>!a.startsWith("cd-")).slice(0,2).join(".");i&&(n+=`.${i}`)}e.unshift(n),t=t.parentElement,s++}return e.join(" > ")}function tr(r){let e={};if(!(r instanceof HTMLElement))return e;for(let t of r.getAttributeNames()){if(!t.startsWith("data-")||t==="data-cd-noTrack"||t==="data-cd-no-track"||t==="data-cd-event")continue;let s=r.getAttribute(t)||"",n=t.replace(/^data-cd-prop-/,"").replace(/^data-/,"");e[n]=s}return e}function qe(){return typeof globalThis.window<"u"&&typeof globalThis.document<"u"}function rr(){return`sess_${Date.now().toString(36)}${V(10)}`}function sr(){if(!qe())return{...ne};let r={...ne};try{let e=globalThis.window,t=new URLSearchParams(e.location.search??"");r.utm_source=t.get("utm_source")??"",r.utm_medium=t.get("utm_medium")??"",r.utm_campaign=t.get("utm_campaign")??"",r.utm_content=t.get("utm_content")??"",r.utm_term=t.get("utm_term")??"",r.gclid=t.get("gclid")??"",r.fbclid=t.get("fbclid")??"",r.msclkid=t.get("msclkid")??"",r.ttclid=t.get("ttclid")??"",r.li_fat_id=t.get("li_fat_id")??"",r.twclid=t.get("twclid")??""}catch{}try{let e=globalThis.document;typeof e.referrer=="string"&&(r.referrer=e.referrer)}catch{}return r}var nr=[/^email$/i,/^password$/i,/^token$/i,/^secret$/i,/^card$/i,/^phone$/i,/password/i,/credit_?card/i];function Me(r){if(!r)return[];let e=[];for(let t of Object.keys(r))nr.some(s=>s.test(t))&&e.push(t);return e}var ie=class{constructor(){this.enabled=!1;this.seen=new Set}emit(e,t,s){if(!this.enabled)return;if(ir.has(e)){if(this.seen.has(e))return;this.seen.add(e)}let n=s?` ${or(s)}`:"";console.info(`[crossdeck:${e}] ${t}${n}`)}},ir=new Set(["sdk.configured","sdk.first_event_sent","sdk.environment_mismatch"]);function or(r){try{return JSON.stringify(r)}catch{return"[unserialisable context]"}}function W(r,e={}){let t=[];if(!r)return{properties:{},warnings:t};let s=e.maxStringLength??1024,n=e.maxBatchPropertyBytes??8192,i=e.maxDepth??5,a=new Set,o=(d,u,m)=>{if(m>i)return t.push({kind:"depth_exceeded",key:u}),{keep:!0,value:"[depth-exceeded]"};if(d===null)return{keep:!0,value:null};let p=typeof d;if(p==="string"){let y=d;return y.length>s?(t.push({kind:"truncated_string",key:u}),{keep:!0,value:y.slice(0,s-1)+"\u2026"}):{keep:!0,value:y}}if(p==="number")return Number.isFinite(d)?{keep:!0,value:d}:(t.push({kind:"non_serialisable",key:u}),{keep:!0,value:null});if(p==="boolean")return{keep:!0,value:d};if(p==="bigint")return t.push({kind:"coerced_bigint",key:u}),{keep:!0,value:d.toString()};if(p==="function")return t.push({kind:"dropped_function",key:u}),{keep:!1,value:void 0};if(p==="symbol")return t.push({kind:"dropped_symbol",key:u}),{keep:!1,value:void 0};if(p==="undefined")return t.push({kind:"dropped_undefined",key:u}),{keep:!1,value:void 0};if(d instanceof Date)return t.push({kind:"coerced_date",key:u}),{keep:!0,value:Number.isFinite(d.getTime())?d.toISOString():null};if(d instanceof Error)return t.push({kind:"coerced_error",key:u}),{keep:!0,value:{name:d.name,message:d.message,stack:typeof d.stack=="string"?d.stack.slice(0,s):void 0}};if(d instanceof Map){t.push({kind:"coerced_map",key:u});let y={};for(let[k,g]of d.entries()){let v=typeof k=="string"?k:String(k),S=o(g,`${u}.${v}`,m+1);S.keep&&(y[v]=S.value)}return{keep:!0,value:y}}if(d instanceof Set){t.push({kind:"coerced_set",key:u});let y=[],k=0;for(let g of d.values()){let v=o(g,`${u}[${k}]`,m+1);v.keep&&y.push(v.value),k++}return{keep:!0,value:y}}if(Array.isArray(d)){if(a.has(d))return t.push({kind:"circular_reference",key:u}),{keep:!0,value:"[circular]"};a.add(d);let y=[];for(let k=0;k<d.length;k++){let g=o(d[k],`${u}[${k}]`,m+1);g.keep&&y.push(g.value)}return a.delete(d),{keep:!0,value:y}}if(p==="object"){let y=d;if(a.has(y))return t.push({kind:"circular_reference",key:u}),{keep:!0,value:"[circular]"};a.add(y);let k={};for(let g of Object.keys(y)){let v=o(y[g],`${u}.${g}`,m+1);v.keep&&(k[g]=v.value)}return a.delete(y),{keep:!0,value:k}}t.push({kind:"non_serialisable",key:u});try{return{keep:!0,value:String(d)}}catch{return{keep:!1,value:void 0}}},c={};for(let d of Object.keys(r)){let u=o(r[d],d,0);u.keep&&(c[d]=u.value)}let l=$e(c);if(l&&ve(l)>n){t.push({kind:"size_cap_exceeded",key:"*"});let d=Object.keys(c).map(m=>({k:m,size:ve($e(c[m])??"")})).sort((m,p)=>p.size-m.size),u=ve(l);for(let{k:m}of d){if(u<=n)break;u-=d.find(p=>p.k===m).size,delete c[m]}c.__truncated=!0}return{properties:c,warnings:t}}function $e(r){try{return JSON.stringify(r)??null}catch{return null}}function ve(r){return typeof TextEncoder<"u"?new TextEncoder().encode(r).length:r.length*4}var oe="super_props",we="groups",ae=class{constructor(e,t){this.storage=e;this.prefix=t;this.superProps={};this.groups={};this.superProps=Ke(e,t+oe)??{},this.groups=Ke(e,t+we)??{}}register(e){for(let[t,s]of Object.entries(e))s===null?delete this.superProps[t]:s!==void 0&&(this.superProps[t]=s);return _e(this.storage,this.prefix+oe,this.superProps),{...this.superProps}}unregister(e){e in this.superProps&&(delete this.superProps[e],_e(this.storage,this.prefix+oe,this.superProps))}getSuperProperties(){return{...this.superProps}}setGroup(e,t,s){t===null?delete this.groups[e]:this.groups[e]=s!==void 0?{id:t,traits:s}:{id:t},_e(this.storage,this.prefix+we,this.groups)}getGroups(){return JSON.parse(JSON.stringify(this.groups))}getGroupIds(){let e={};for(let[t,s]of Object.entries(this.groups))e[t]=s.id;return e}clear(){this.superProps={},this.groups={};try{this.storage.removeItem(this.prefix+oe)}catch{}try{this.storage.removeItem(this.prefix+we)}catch{}}};function Ke(r,e){let t;try{t=r.getItem(e)}catch{return null}if(!t)return null;try{return JSON.parse(t)}catch{return null}}function _e(r,e,t){try{r.setItem(e,JSON.stringify(t))}catch{}}var Be="$crossdeck_internal",Se="crossdeck.internalOptOut";function je(){try{return typeof localStorage<"u"?localStorage:null}catch{return null}}function We(){try{let r=typeof location<"u"?location.search:"",e=new URLSearchParams(r||"");if(!e.has("crossdeck_internal"))return;let t=je();if(!t)return;let s=e.get("crossdeck_internal");s==="1"||s==="true"?t.setItem(Se,"1"):(s==="0"||s==="false")&&t.removeItem(Se)}catch{}}function He(){try{return je()?.getItem(Se)==="1"}catch{return!1}}var ce=class{constructor(e,t){this.cfg=e;this.report=t;this.observers=[];this.flushed=new Set;this.cls=0;this.clsEntries=[];this.inp=0;this.cleanups=[]}install(){if(!this.cfg.enabled||typeof PerformanceObserver>"u"||typeof globalThis>"u"||!("document"in globalThis))return;let e=globalThis.document;try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries()){let c=o;c.responseStart>0&&!this.flushed.has("ttfb")&&(this.flushed.add("ttfb"),this.report("webvitals.ttfb",{valueMs:Math.round(c.responseStart-c.startTime)}))}});i.observe({type:"navigation",buffered:!0}),this.observers.push(i)}catch{}try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries())o.name==="first-contentful-paint"&&!this.flushed.has("fcp")&&(this.flushed.add("fcp"),this.report("webvitals.fcp",{valueMs:Math.round(o.startTime)}))});i.observe({type:"paint",buffered:!0}),this.observers.push(i)}catch{}let t=0;try{let i=new PerformanceObserver(a=>{let o=a.getEntries(),c=o[o.length-1];c&&(t=c.startTime)});i.observe({type:"largest-contentful-paint",buffered:!0}),this.observers.push(i)}catch{}try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries()){let c=o;typeof c.value=="number"&&!c.hadRecentInput&&(this.cls+=c.value,this.clsEntries.push(o))}});i.observe({type:"layout-shift",buffered:!0}),this.observers.push(i)}catch{}try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries()){let c=o;c.interactionId&&c.duration>this.inp&&(this.inp=c.duration)}});try{i.observe({type:"event",buffered:!0,durationThreshold:16})}catch{i.observe({type:"first-input",buffered:!0})}this.observers.push(i)}catch{}let s=()=>{t>0&&!this.flushed.has("lcp")&&(this.flushed.add("lcp"),this.report("webvitals.lcp",{valueMs:Math.round(t)})),this.cls>0&&!this.flushed.has("cls")&&(this.flushed.add("cls"),this.report("webvitals.cls",{value:Math.round(this.cls*1e3)/1e3})),this.inp>0&&!this.flushed.has("inp")&&(this.flushed.add("inp"),this.report("webvitals.inp",{valueMs:Math.round(this.inp)}))},n=()=>{e.visibilityState==="hidden"&&s()};e.addEventListener("visibilitychange",n),globalThis.window.addEventListener("pagehide",s),this.cleanups.push(()=>{e.removeEventListener("visibilitychange",n),globalThis.window.removeEventListener("pagehide",s)})}uninstall(){for(let e of this.observers)try{e.disconnect()}catch{}this.observers=[];for(let e of this.cleanups.splice(0))try{e()}catch{}}};var ar={analytics:!0,marketing:!0,errors:!0},de=class{constructor(e){this.state={...ar};this.dntDenied=!1;e?.respectDnt&&this.detectDnt()&&(this.dntDenied=!0,this.state={analytics:!1,marketing:!1,errors:!1})}set(e){if(this.dntDenied)return{...this.state};for(let t of Object.keys(e)){let s=e[t];typeof s=="boolean"&&(this.state[t]=s)}return{...this.state}}get(){return{...this.state}}get analytics(){return this.state.analytics}get marketing(){return this.state.marketing}get errors(){return this.state.errors}get isDntDenied(){return this.dntDenied}detectDnt(){try{let e=globalThis.navigator;return e?[e.doNotTrack,e.msDoNotTrack,globalThis.doNotTrack].some(s=>s==="1"||s==="yes"):!1}catch{return!1}}},cr=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,dr=/\b\d(?:[ -]?\d){12,18}\b/g,lr="<email>",ur="<card>";function fr(r){return r&&r.replace(cr,lr).replace(dr,ur)}function Ee(r){let e={};for(let t of Object.keys(r))e[t]=ze(r[t]);return e}function ze(r){return typeof r=="string"?fr(r):Array.isArray(r)?r.map(ze):r&&typeof r=="object"&&r.constructor===Object?Ee(r):r}var le=class{constructor(e=50){this.maxSize=e;this.items=[]}add(e){this.items.push(e),this.items.length>this.maxSize&&this.items.shift()}snapshot(){return this.items.slice()}clear(){this.items=[]}get size(){return this.items.length}};var pr="https://api.cross-deck.com/v1/events",Ge="cd_pub_live_9490e7aa029c432abf";function hr(){return!Ge.startsWith("cd_pub_RELIABILITY_PLACEHOLDER")}var mr=new Set(["contract_id","sdk_version","sdk_platform","failure_reason","run_context","run_id","test_file","test_name","device_class","verification_phase"]);function gr(r){let e={};for(let[t,s]of Object.entries(r))mr.has(t)&&typeof s=="string"&&(e[t]=s);return e}function ue(r){if(!hr())return;let e=gr(r);if(Object.keys(e).length===0)return;let t=JSON.stringify({events:[{name:"crossdeck.contract_failed",timestamp:Date.now(),properties:e}]}),s=globalThis.fetch;if(typeof s=="function")try{s(pr,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Ge}`,"Crossdeck-Sdk-Version":`${A}@${R}`},body:t,keepalive:!0,credentials:"omit",cache:"no-store",referrerPolicy:"no-referrer"}).catch(()=>{})}catch{}}var xe=Object.freeze([{code:"invalid_public_key",type:"configuration_error",description:"The publishable key passed to Crossdeck.init() doesn't start with cd_pub_.",resolution:"Copy the key from your Crossdeck dashboard \u2192 API keys page.",retryable:!1},{code:"missing_app_id",type:"configuration_error",description:"Crossdeck.init() was called without an appId.",resolution:"Add appId to your init options \u2014 find it in the dashboard's Apps page.",retryable:!1},{code:"invalid_environment",type:"configuration_error",description:"Crossdeck.init() requires environment: 'production' | 'sandbox'.",resolution:'Pass the literal string "production" or "sandbox" \u2014 no other values are accepted.',retryable:!1},{code:"environment_mismatch",type:"configuration_error",description:"The publishable key's env prefix doesn't match the declared environment option.",resolution:"Either change `environment` to match the key prefix (cd_pub_test_ \u2194 sandbox, cd_pub_live_ \u2194 production), or swap the key for one minted in the right env.",retryable:!1},{code:"not_initialized",type:"configuration_error",description:"An SDK method was called before Crossdeck.init().",resolution:"Call Crossdeck.init({ appId, publicKey, environment }) once at app startup before any other method.",retryable:!1},{code:"missing_user_id",type:"invalid_request_error",description:"identify() was called with an empty userId.",resolution:"Pass a stable, non-empty user identifier from your auth layer \u2014 never a hardcoded placeholder.",retryable:!1},{code:"missing_event_name",type:"invalid_request_error",description:"track() was called without an event name.",resolution:"Pass a non-empty string as the first argument.",retryable:!1},{code:"missing_group_type",type:"invalid_request_error",description:"group() was called without a group type.",resolution:'Pass a non-empty type (e.g. "org", "team") as the first argument.',retryable:!1},{code:"missing_signed_transaction_info",type:"invalid_request_error",description:"syncPurchases() was called without StoreKit 2 signed transaction info.",resolution:"Pass the JWS string from Transaction.currentEntitlements / Transaction.updates.",retryable:!1},{code:"fetch_failed",type:"network_error",description:"The underlying fetch() call failed (typically a network outage or DNS issue).",resolution:"Check the user's network. The SDK will retry automatically with exponential backoff.",retryable:!0},{code:"request_timeout",type:"network_error",description:"A request was aborted after the configured timeoutMs (default 15s).",resolution:"Check the user's connection. Increase timeoutMs in init options if the user is on a known-slow network.",retryable:!0},{code:"invalid_json_response",type:"internal_error",description:"The server returned a 2xx with an unparseable body.",resolution:"Likely a transient backend bug. Retry; if it persists, contact support with the requestId.",retryable:!0},{code:"missing_api_key",type:"authentication_error",description:"No Authorization header (or Crossdeck-Api-Key header) on the request.",resolution:"Make sure Crossdeck.init({ publicKey }) was called with a cd_pub_\u2026 key before the request fired. Re-check your env-vars in CI / Docker if the key is empty at runtime.",retryable:!1},{code:"invalid_api_key",type:"authentication_error",description:"The API key is malformed, unknown, or doesn't resolve to a project.",resolution:"Copy the key from your Crossdeck dashboard \u2192 API keys. Confirm prefix is cd_pub_test_ / cd_pub_live_ for client SDKs and cd_sk_test_ / cd_sk_live_ for the Node server SDK.",retryable:!1},{code:"key_revoked",type:"authentication_error",description:"The API key was revoked in the Crossdeck dashboard.",resolution:"Mint a fresh key in the dashboard \u2192 API keys \u2192 Create new, swap it in, and redeploy. The revoked key cannot be reactivated.",retryable:!1},{code:"identity_token_invalid",type:"authentication_error",description:"The Firebase / Apple / Google ID token supplied with the request didn't verify against the dashboard's configured signers.",resolution:"Refresh the token client-side (Firebase auth.currentUser.getIdToken(true)) and retry. If the failure persists, confirm the signer is registered under dashboard \u2192 Authentication \u2192 Identity sources.",retryable:!0},{code:"origin_not_allowed",type:"permission_error",description:"The Origin header isn't in the project's Allowed origins list.",resolution:"Add the origin (e.g. https://app.example.com) under dashboard \u2192 Settings \u2192 Allowed origins. Wildcards like https://*.example.com are supported.",retryable:!1},{code:"bundle_id_not_allowed",type:"permission_error",description:"The iOS bundle ID sent via X-Crossdeck-Bundle-Id isn't registered under this app's Apple identity lock.",resolution:"Add the bundle ID under dashboard \u2192 Apps \u2192 <your app> \u2192 iOS bundle IDs.",retryable:!1},{code:"package_name_not_allowed",type:"permission_error",description:"The Android package name sent via X-Crossdeck-Package-Name isn't registered under this app's Android identity lock.",resolution:"Add the package name under dashboard \u2192 Apps \u2192 <your app> \u2192 Android package names.",retryable:!1},{code:"env_mismatch",type:"permission_error",description:"The request env (inferred from key prefix) doesn't match the resolved app's configured env.",resolution:"Use a cd_pub_live_ / cd_sk_live_ key with a production app, cd_pub_test_ / cd_sk_test_ with a sandbox app. The two cannot cross.",retryable:!1},{code:"idempotency_key_in_use",type:"invalid_request_error",description:"An Idempotency-Key was reused for a request with a different body (Stripe-grade contract).",resolution:"Generate a fresh key for a different transaction, or reuse the key only with the EXACT same body. The v1.4.0 SDKs derive keys deterministically from the body so this should never fire on SDK-managed calls.",retryable:!1},{code:"rate_limited",type:"rate_limit_error",description:"Request rate exceeded the project's per-second cap.",resolution:"Honour the Retry-After header \u2014 the SDK does this automatically on managed retries. If you're hitting it from a custom code path, throttle to <100 req/s/key.",retryable:!0},{code:"internal_error",type:"internal_error",description:"Server-side issue. Safe to retry with backoff.",resolution:"The SDK retries automatically. If your code paths through to this error, contact support with the requestId from the response envelope.",retryable:!0},{code:"google_not_supported",type:"invalid_request_error",description:"POST /purchases/sync with rail=google is gated until the Play Developer API reconciliation worker ships.",resolution:"Until v1.5+, Google Play purchases verify via Real-time Developer Notifications. The SDK auto-track path handles this transparently for Android consumers.",retryable:!1},{code:"stripe_not_supported",type:"invalid_request_error",description:"POST /purchases/sync with rail=stripe is unsupported \u2014 Stripe Checkout's redirect flow uses platform webhooks instead.",resolution:"Wire Stripe via the standard Checkout / Customer Portal flow; Crossdeck reconciles via the platform webhook automatically. No SDK call needed.",retryable:!1},{code:"missing_required_param",type:"invalid_request_error",description:"A required field is absent from the request body.",resolution:"Inspect the error.message \u2014 the missing field name is included verbatim. Refer to the SDK's TypeScript types for the canonical request shape.",retryable:!1},{code:"invalid_param_value",type:"invalid_request_error",description:"A field is present but the value failed validation (wrong shape, wrong length, wrong enum value).",resolution:"Read error.message for the specific field + reason. SDK-managed call sites should never emit this \u2014 file a bug if you do.",retryable:!1},{code:"sdk_version_unsupported",type:"version_error",description:"HTTP 426 \u2014 your installed SDK sends an event format the server no longer accepts. The data is good; only the wire dialect is too old. The SDK PARKS automatically: events are held on-device (paused, not lost) and deliver on the next launch after you upgrade.",resolution:"Update @cross-deck/web to at least the version in error.minVersion and redeploy \u2014 the parked queue backfills automatically. See https://cross-deck.com/docs/sdk-event-durability/.",retryable:!1}]);function fe(r){return xe.find(e=>e.code===r)}function Ze(r){return{sdkVersion:`${A}@${R}`,runId:`cd_verify_${Tr(8)}`,runContext:r.runContext??"customer-app",logVerifierResults:r.logVerifierResults,disableContractAssertions:r.disableContractAssertions,console,emitTelemetry:ue}}var z=class{constructor(e){this.ctx=e;this.reentrancyDepth=0}report(e,t,s){this.ctx.disableContractAssertions||(e.ok?this.reportPass(e,t,s):this.reportFail(e,t,s))}reportPass(e,t,s){if(!this.ctx.logVerifierResults)return;let n=yr(e,s);t==="boot"?this.ctx.console.info(n):this.ctx.console.debug(n)}reportFail(e,t,s){if(this.ctx.console.warn(br(e,s)),!(this.reentrancyDepth>0)){this.reentrancyDepth+=1;try{this.ctx.emitTelemetry({contract_id:e.contractId,sdk_version:this.ctx.sdkVersion,sdk_platform:"web",failure_reason:Cr(e.failureReason,128),run_context:this.ctx.runContext,run_id:this.ctx.runId,verification_phase:t})}finally{this.reentrancyDepth-=1}}}};function yr(r,e){return`${e?`[crossdeck.${e}]`:"[crossdeck]"} \u2713 ${r.contractId} \u2014 ${r.evidence} (${r.durationMs}ms)`}function br(r,e){return`${e?`[crossdeck.${e}]`:"[crossdeck]"} \u2717 ${r.contractId} \u2014 ${r.failureReason} (${r.durationMs}ms)`}var kr={contractId:"per-user-cache-isolation",bootTest(){let r=h();try{let e=new pe,t=new P(e,"_verifier");if(t.setUserKey("user_A"),t.setFromList([{object:"entitlement",key:"pro",isActive:!0,validUntil:null,source:{rail:"stripe",productId:"p_verifier",subscriptionId:"s_verifier"},updatedAt:Date.now()}]),t.setUserKey("user_B"),t.list().length!==0)return b("per-user-cache-isolation","in-memory snapshot still carried user_A's entitlements after rotation",h()-r);let n=P.suffixForUserId("user_A"),i=P.suffixForUserId("user_B");if(n===i)return b("per-user-cache-isolation","suffixes for user_A and user_B collided",h()-r);let a=e.getItem(`_verifier:${n}`),o=e.getItem(`_verifier:${i}`);return a?o?b("per-user-cache-isolation","user_B's storage slot already contained data before any write",h()-r):x("per-user-cache-isolation",`slot rotated A:${H(n)} \u2192 B:${H(i)} (isolated, physically separate)`,h()-r):b("per-user-cache-isolation","user_A's storage slot was wiped on rotation (expected isolation, not erasure)",h()-r)}catch(e){return b("per-user-cache-isolation",`boot test threw: ${e.message?.slice(0,80)??"unknown error"}`,h()-r)}},hooks:{onIdentify(r){let e=h(),t=P.suffixForUserId(r.priorUserId),s=P.suffixForUserId(r.nextUserId);return t!==s?r.cache.list().length!==0?b("per-user-cache-isolation","in-memory snapshot still held entitlements after slot rotation",h()-e):x("per-user-cache-isolation",`slot rotated ${H(t)} \u2192 ${H(s)}`,h()-e):x("per-user-cache-isolation",`same-id re-identify (suffix ${H(s)}); cleared + rehydrated per contract`,h()-e)}}},Ce="eyJ.jws.sig",Je="a66b1640-efaf-bb4d-1261-6650033bf111",vr={contractId:"idempotency-key-deterministic",bootTest(){let r=h();try{let e=L({rail:"apple",signedTransactionInfo:Ce});if(e!==Je)return b("idempotency-key-deterministic",`canonical apple JWS derived ${e} (expected ${Je})`,h()-r);if(L({rail:"apple",signedTransactionInfo:Ce})!==e)return b("idempotency-key-deterministic","same JWS produced different keys on two derivations",h()-r);let s=e,n=L({rail:"google",purchaseToken:Ce});return s===n?b("idempotency-key-deterministic","rail namespacing failed \u2014 apple/google identical key",h()-r):x("idempotency-key-deterministic",`apple JWS \u2192 ${e} (canonical vector + determinism + rail isolation)`,h()-r)}catch(e){return b("idempotency-key-deterministic",`boot test threw: ${e.message?.slice(0,80)??"unknown error"}`,h()-r)}},hooks:{onSyncPurchases(r){let e=h();try{return L(r.rail==="apple"?{rail:"apple",signedTransactionInfo:r.stableIdentifier}:{rail:r.rail,purchaseToken:r.stableIdentifier})!==r.derivedKey?b("idempotency-key-deterministic","derived key drifted from canonical algorithm",h()-e):x("idempotency-key-deterministic",`${r.rail} \u2192 ${r.derivedKey}`,h()-e)}catch(t){return b("idempotency-key-deterministic",`hot-path derivation threw: ${t.message?.slice(0,80)??"unknown error"}`,h()-e)}}}},wr={contractId:"error-envelope-shape",bootTest(){let r=h(),e={error:{type:"invalid_request_error",code:"missing_customer",message:"Customer identifier is required.",request_id:"req_test1234"}},t=new Set(["authentication_error","permission_error","invalid_request_error","rate_limit_error","internal_error"]),s=e.error,n=["type","code","message","request_id"].filter(i=>!(i in s)||typeof s[i]!="string");return n.length>0?b("error-envelope-shape",`envelope missing required fields: ${n.join(", ")}`,h()-r):t.has(s.type)?x("error-envelope-shape","{ type, code, message, request_id } parsed and type \u2208 ApiErrorType",h()-r):b("error-envelope-shape",`error.type "${s.type}" not in canonical ApiErrorType set`,h()-r)},hooks:{onErrorParse(r){let e=h();return new Set(["authentication_error","permission_error","invalid_request_error","rate_limit_error","internal_error"]).has(r.errorType)?!r.errorCode||r.errorCode.length===0?b("error-envelope-shape","wire error.code was empty",h()-e):x("error-envelope-shape",`${r.errorType}/${r.errorCode} on ${r.httpStatus}${r.requestId?` (${r.requestId.slice(0,12)}\u2026)`:""}`,h()-e):b("error-envelope-shape",`wire error.type "${r.errorType}" outside canonical ApiErrorType`,h()-e)}}},_r={contractId:"flush-interval-parity",bootTest(){let r=h();return 2e3!==2e3?b("flush-interval-parity","canonical default drifted from 2000ms",h()-r):x("flush-interval-parity","eventFlushIntervalMs default = 2000ms (Web/Node/RN/Swift/Android parity)",h()-r)}};function et(r){return{contractId:"flush-interval-parity",bootTest(){let e=h(),t=2e3;return r<100||r>6e4?b("flush-interval-parity",`configured eventFlushIntervalMs=${r} outside reasonable bounds [100, 60000]`,h()-e):r!==t?x("flush-interval-parity",`eventFlushIntervalMs = ${r}ms (override; canonical default is 2000ms)`,h()-e):x("flush-interval-parity","eventFlushIntervalMs = 2000ms (canonical default)",h()-e)}}}var Sr={contractId:"super-property-merge-precedence",bootTest(){let r=h(),n={...{plan:"device_plan",os:"macos"},...{plan:"super_plan",appVersion:"1.0.0"},...{plan:"caller_plan",eventSpecific:!0}};return n.plan!=="caller_plan"?b("super-property-merge-precedence",`merged.plan = "${n.plan}" (expected "caller_plan"; caller must override super and device)`,h()-r):n.appVersion!=="1.0.0"?b("super-property-merge-precedence","super-property appVersion was clobbered by device or caller",h()-r):n.os!=="macos"?b("super-property-merge-precedence","device property os was dropped from merged result",h()-r):x("super-property-merge-precedence","caller > super > device verified (synthetic merge)",h()-r)},hooks:{onTrack(r){let e=h();for(let[t,s]of Object.entries(r.callerProperties))if(r.mergedProperties[t]!==s)return b("super-property-merge-precedence",`caller key "${t}" did not win in merged output`,h()-e);for(let[t,s]of Object.entries(r.superProperties))if(!(t in r.callerProperties)&&r.mergedProperties[t]!==s)return b("super-property-merge-precedence",`super key "${t}" did not win over device in merged output`,h()-e);return x("super-property-merge-precedence",`caller(${Object.keys(r.callerProperties).length}) > super(${Object.keys(r.superProperties).length}) > device verified`,h()-e)}}},Te=["contract_id","sdk_version","sdk_platform","failure_reason","run_context","run_id"],Xe=["test_file","test_name","device_class","verification_phase"],Ye=["anonymousId","developerUserId","crossdeckCustomerId","email","userId","ip","ipAddress","userAgent","stack","stackTrace","url","referrer","deviceId"],Er={contractId:"contract-failed-payload-schema-lock",bootTest(){let r=h(),t=Object.keys({contract_id:"synthetic",sdk_version:R,sdk_platform:"web",failure_reason:"synthetic",run_context:"customer-app",run_id:"synthetic-run-id",verification_phase:"boot"}),s=new Set([...Te,...Xe]),n=new Set(Ye);for(let i of Te)if(!t.includes(i))return b("contract-failed-payload-schema-lock",`missing required field: ${i}`,h()-r);for(let i of t)if(n.has(i))return b("contract-failed-payload-schema-lock",`forbidden field on wire: ${i}`,h()-r);for(let i of t)if(!s.has(i))return b("contract-failed-payload-schema-lock",`unrecognised field on wire: ${i} (not in required \u222A optional)`,h()-r);return x("contract-failed-payload-schema-lock",`${t.length} fields \u2286 required(${Te.length}) \u222A optional(${Xe.length}); ${Ye.length} forbidden absent`,h()-r)}},Qe=Object.freeze(["missing_api_key","invalid_api_key","key_revoked","identity_token_invalid","origin_not_allowed","bundle_id_not_allowed","package_name_not_allowed","env_mismatch","idempotency_key_in_use","rate_limited","internal_error","google_not_supported","stripe_not_supported","missing_required_param","invalid_param_value","sdk_version_unsupported"]),xr={contractId:"sdk-error-codes-catalogue",bootTest(){let r=h();try{let e=[];for(let t of Qe){let s=fe(t);(!s||!s.description||s.description.trim().length===0||!s.resolution||s.resolution.trim().length===0)&&e.push(t)}return e.length>0?b("sdk-error-codes-catalogue",`catalogue missing description+resolution for backend code(s): ${e.join(", ")}`,h()-r):x("sdk-error-codes-catalogue",`all ${Qe.length} backend wire codes carry description + resolution`,h()-r)}catch(e){return b("sdk-error-codes-catalogue",`boot test threw: ${e.message?.slice(0,80)??"unknown error"}`,h()-r)}}},tt=Object.freeze([kr,vr,wr,_r,Sr,Er,xr]);async function Ie(r,e,t){if(t.disableContractAssertions)return{passed:0,failed:0,totalMs:0};let s=h(),n=0,i=0;if(t.logVerifierResults){let o=r.filter(d=>d.bootTest).length,c=r.filter(d=>d.hooks).length,l=r.map(d=>d.contractId).join(", ");t.console.info(`[crossdeck] Contract self-verification \u2014 ${r.length} verifiers (${o} boot-tests, ${c} hot-path hooks): ${l}`)}for(let o of r){if(!o.bootTest)continue;let c;try{c=await o.bootTest()}catch(l){c=b(o.contractId,`bootTest threw: ${l.message?.slice(0,80)??"unknown"}`,0)}e.report(c,"boot"),c.ok?n+=1:i+=1}let a=h()-s;if(t.logVerifierResults){let o=i===0?"passed":"complete";t.console.info(`[crossdeck] Self-verification ${o} \u2014 ${n} passed, ${i} failed (${a}ms)`)}return{passed:n,failed:i,totalMs:a}}function rt(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onIdentify;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","identify")}}function st(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onTrack;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","track")}}function nt(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onSyncPurchases;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","syncPurchases")}}function it(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onErrorParse;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","errorParse")}}function ot(){try{if(typeof process<"u"&&process.env){let e=process.env.NODE_ENV;if(typeof e=="string")return e!=="production"}}catch{}let r=globalThis.__DEV__;return typeof r=="boolean"?r:!1}function x(r,e,t){return{ok:!0,contractId:r,evidence:e,durationMs:t}}function b(r,e,t){return{ok:!1,contractId:r,failureReason:e,durationMs:t}}function h(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Cr(r,e){return r.length>e?r.slice(0,e-1)+"\u2026":r}function H(r){let e=r.startsWith("_")?r.slice(1):r;return e.length<=12?e:`${e.slice(0,4)}\u2026${e.slice(-4)}`}function Tr(r){let e=new Uint8Array(Math.ceil(r/2));if(typeof globalThis<"u"&&globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(e);else for(let s=0;s<e.length;s+=1)e[s]=Math.floor(Math.random()*256);let t="";for(let s=0;s<e.length;s+=1)t+=e[s].toString(16).padStart(2,"0");return t.slice(0,r)}var pe=class{constructor(){this.map=new Map}getItem(e){return this.map.get(e)??null}setItem(e,t){this.map.set(e,t)}removeItem(e){this.map.delete(e)}keys(){return Array.from(this.map.keys())}};pe._=q;function Ae(r){if(!r||typeof r!="string")return[];let e=r.split(`
|
|
2
|
-
`),t=[];for(let s of e){let n=s.trim();if(!n)continue;let i=Ir(n);i&&t.push(i)}return t}function Ir(r){let e=/^at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)$/.exec(r);return e?Re({function:e[1],filename:e[2],lineno:parseInt(e[3],10),colno:parseInt(e[4],10),raw:r}):(e=/^at\s+(.+?):(\d+):(\d+)$/.exec(r),e?Re({function:"?",filename:e[1],lineno:parseInt(e[2],10),colno:parseInt(e[3],10),raw:r}):(e=/^(.*?)@(.+?):(\d+):(\d+)$/.exec(r),e?Re({function:e[1]||"?",filename:e[2],lineno:parseInt(e[3],10),colno:parseInt(e[4],10),raw:r}):/^\w*Error/.test(r)||!r.includes(":")?null:{function:"?",filename:"",lineno:0,colno:0,in_app:!0,raw:r}))}function Re(r){return{function:r.function||"?",filename:r.filename,lineno:Number.isFinite(r.lineno)?r.lineno:0,colno:Number.isFinite(r.colno)?r.colno:0,in_app:Rr(r.filename),raw:r.raw}}function Rr(r){return r?!(/^(?:chrome|moz|safari|webkit)-extension:\/\//.test(r)||/\bcdn\.jsdelivr\.net\b/.test(r)||/\bunpkg\.com\b/.test(r)||/\bgoogletagmanager\.com\b/.test(r)||/\bgoogle-analytics\.com\b/.test(r)||/\b@cross-deck\/web\b/.test(r)||/\/crossdeck\.umd\.min\.js$/.test(r)):!0}function M(r,e,t){let s=e.filter(i=>i.in_app).slice(0,3),n=[(r||"").slice(0,200),...s.map(i=>`${i.function}@${i.filename}:${i.lineno}`)];if(s.length===0&&t){let i=[t.errorType??"",t.filename??"",t.lineno??"",t.colno??""].join(":");i!==":::"&&n.push(i)}return Ar(n.join("|"))}function Ar(r){let e=5381;for(let t=0;t<r.length;t++)e=(e<<5)+e+r.charCodeAt(t)|0;return(e>>>0).toString(16).padStart(8,"0")}var at={enabled:!0,onError:!0,onUnhandledRejection:!0,wrapFetch:!0,wrapXhr:!0,captureConsole:!1,ignoreErrors:["ResizeObserver loop limit exceeded","ResizeObserver loop completed with undelivered notifications","Non-Error promise rejection captured"],allowUrls:[],denyUrls:[/^chrome-extension:\/\//,/^moz-extension:\/\//,/^safari-extension:\/\//,/^webkit-extension:\/\//,/^safari-web-extension:\/\//],sampleRate:1,maxPerFingerprintPerMinute:5,maxPerSession:100},he=class{constructor(e){this.opts=e;this.installed=!1;this.cleanups=[];this._reporting=!1;this.sessionCount=0;this.fingerprintWindow=new Map}install(){if(this.installed||!this.opts.config.enabled||typeof globalThis>"u"||!("window"in globalThis))return;let e=globalThis.window;this.opts.config.onError&&this.installOnErrorListener(e),this.opts.config.onUnhandledRejection&&this.installRejectionListener(e),this.opts.config.wrapFetch&&this.installFetchWrap(e),this.opts.config.wrapXhr&&this.installXhrWrap(e),this.opts.config.captureConsole&&this.installConsoleWrap(),this.installed=!0}uninstall(){for(let e of this.cleanups.splice(0))try{e()}catch{}this.installed=!1}captureError(e,t){if(this.opts.isConsented())try{let s=this.buildFromUnknown(e,"error.handled",t?.level??"error");t?.context&&(s.context={...s.context,...t.context}),t?.tags&&(s.tags={...s.tags,...t.tags}),this.maybeReport(s)}catch{}}captureMessage(e,t="info"){if(this.opts.isConsented())try{let s={timestamp:Date.now(),kind:"error.message",level:t,message:e,errorType:null,frames:[],rawStack:null,filename:null,lineno:null,colno:null,fingerprint:M(e,[]),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:this.opts.getContext(),tags:this.opts.getTags()};this.maybeReport(s)}catch{}}installOnErrorListener(e){let t=s=>{if(!this._reporting&&this.opts.isConsented())try{this._reporting=!0;let n=this.buildFromErrorEvent(s);this.maybeReport(n)}catch{}finally{this._reporting=!1}};e.addEventListener("error",t,!0),this.cleanups.push(()=>e.removeEventListener("error",t,!0))}installRejectionListener(e){let t=s=>{if(!this._reporting&&this.opts.isConsented())try{this._reporting=!0;let n=this.buildFromUnknown(s.reason,"error.unhandledrejection","error");this.maybeReport(n)}catch{}finally{this._reporting=!1}};e.addEventListener("unhandledrejection",t),this.cleanups.push(()=>e.removeEventListener("unhandledrejection",t))}installFetchWrap(e){let t=e.fetch?.bind(e);if(!t)return;let s=async(...n)=>{let i=n[0],a=n[1]??{},o=typeof i=="string"?i:i?.url??"",c=(a.method||"GET").toUpperCase(),l=Date.now();De(o,this.opts.selfHostname)||this.opts.breadcrumbs.add({timestamp:l,category:"http",message:`${c} ${o}`,data:{url:o,method:c}});try{let d=await t(...n);return d.status>=500&&this.opts.isConsented()&&(De(o,this.opts.selfHostname)||this.captureHttp({url:o,method:c,status:d.status,statusText:d.statusText})),d}catch(d){throw this.opts.isConsented()&&!o.includes("api.cross-deck.com")&&!Vr(o,d,e)&&this.captureHttp({url:o,method:c,status:0,statusText:d instanceof Error?d.message:"network error"}),d}};e.fetch=s,this.cleanups.push(()=>{e.fetch===s&&(e.fetch=t)})}installXhrWrap(e){let s=e.XMLHttpRequest?.prototype;if(!s)return;let n=s.open,i=s.send,a=this;s.open=function(o,c,...l){return this._cdMethod=o,this._cdUrl=c,n.apply(this,[o,c,...l])},s.send=function(o){let c=this,l=()=>{try{if(c.status>=500&&a.opts.isConsented()){let d=c._cdUrl??"";De(d,a.opts.selfHostname)||a.captureHttp({url:d,method:(c._cdMethod??"GET").toUpperCase(),status:c.status,statusText:c.statusText})}}catch{}};return c.addEventListener("loadend",l),i.apply(this,[o??null])},this.cleanups.push(()=>{s.open=n,s.send=i})}installConsoleWrap(){let e=globalThis.console;if(!e)return;let t=e.error.bind(e);e.error=(...s)=>{try{this.opts.isConsented()&&this.captureMessage(s.map(n=>Dr(n)).join(" "),"error")}catch{}return t(...s)},this.cleanups.push(()=>{e.error=t})}buildFromErrorEvent(e){let t=e.error,s=e.filename||null,n=typeof e.lineno=="number"&&e.lineno>0?e.lineno:null,i=typeof e.colno=="number"&&e.colno>0?e.colno:null;if(t==null&&!s&&n==null&&(e.message==="Script error."||e.message==="Script error"||!e.message)){let p="Cross-origin script error (browser hid details \u2014 script needs crossorigin attribute + CORS headers)";return{timestamp:Date.now(),kind:"error.unhandled",level:"error",message:p,errorType:"ScriptError",frames:[],rawStack:null,filename:null,lineno:null,colno:null,fingerprint:M(p,[]),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:this.opts.getContext(),tags:{...this.opts.getTags(),cross_origin:"true"}}}let o=Ve(t),c=(o.message||e.message||"Unknown error").slice(0,1024),l=t instanceof Error?t.stack??null:null,d=Ae(l),u=o.errorType??null,m=o.extras?{...this.opts.getContext(),__error_extras:o.extras}:this.opts.getContext();return{timestamp:Date.now(),kind:"error.unhandled",level:"error",message:c,errorType:u,frames:d,rawStack:l,filename:s,lineno:n,colno:i,fingerprint:M(c,d,{filename:s,lineno:n,colno:i,errorType:u}),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:m,tags:this.opts.getTags()}}buildFromUnknown(e,t,s){let n=Ve(e),i=(n.message||"Unknown error").slice(0,1024),a=e instanceof Error?e.stack??null:null,o=Ae(a),c=n.errorType??null,l=n.extras?{...this.opts.getContext(),__error_extras:n.extras}:this.opts.getContext();return{timestamp:Date.now(),kind:t,level:s,message:i,errorType:c,frames:o,rawStack:a,filename:null,lineno:null,colno:null,fingerprint:M(i,o,{errorType:c}),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:l,tags:this.opts.getTags()}}captureHttp(e){try{let t=`HTTP ${e.status} ${e.method} ${e.url}`,s={timestamp:Date.now(),kind:"error.http",level:"error",message:t,errorType:"HTTPError",frames:[],rawStack:null,filename:e.url,lineno:null,colno:null,fingerprint:M(`HTTP ${e.status} ${e.method}`,[],{filename:e.url,errorType:"HTTPError"}),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:this.opts.getContext(),tags:this.opts.getTags(),http:e};this.maybeReport(s)}catch{}}maybeReport(e){if(this.sessionCount>=this.opts.config.maxPerSession||this.shouldIgnore(e)||!this.passesUrlGate(e)||!this.passesSample(e)||!this.passesRateLimit(e))return;let t=e,s=this.opts.beforeSend?.();if(s){try{t=s(e)}catch{t=e}if(!t)return}this.sessionCount+=1;try{this.opts.report(t)}catch{}}shouldIgnore(e){for(let t of this.opts.config.ignoreErrors)if(typeof t=="string"&&e.message.includes(t)||t instanceof RegExp&&t.test(e.message))return!0;return!1}passesUrlGate(e){let s=(e.frames.find(n=>n.filename)??null)?.filename??e.filename??"";if(!s)return!0;for(let n of this.opts.config.denyUrls)if(typeof n=="string"&&s.includes(n)||n instanceof RegExp&&n.test(s))return!1;if(this.opts.config.allowUrls.length>0){for(let n of this.opts.config.allowUrls)if(typeof n=="string"&&s.includes(n)||n instanceof RegExp&&n.test(s))return!0;return!1}return!0}passesSample(e){return this.opts.config.sampleRate>=1?!0:this.opts.config.sampleRate<=0?!1:parseInt(e.fingerprint.slice(0,2),16)/255<this.opts.config.sampleRate}passesRateLimit(e){let s=Date.now(),n=this.opts.config.maxPerFingerprintPerMinute,a=(this.fingerprintWindow.get(e.fingerprint)??[]).filter(o=>s-o<6e4);return a.length>=n?(this.fingerprintWindow.set(e.fingerprint,a),!1):(a.push(s),this.fingerprintWindow.set(e.fingerprint,a),!0)}};function Ve(r){if(r===null)return{message:"(thrown: null)",errorType:null,extras:null};if(r===void 0)return{message:"(thrown: undefined)",errorType:null,extras:null};if(typeof r=="string")return{message:r,errorType:null,extras:null};if(typeof r=="number"||typeof r=="boolean"||typeof r=="bigint")return{message:String(r),errorType:typeof r,extras:null};if(typeof r=="symbol")return{message:r.toString(),errorType:"symbol",extras:null};if(typeof r=="function")return{message:`(thrown function: ${r.name||"anonymous"})`,errorType:"function",extras:null};if(r instanceof Error){let e=r.name||r.constructor?.name||"Error",t=typeof r.message=="string"&&r.message.length>0?r.message:$(r)||e,s={},n=Pr(r);n.length>0&&(s.cause=n);for(let i of["code","status","statusCode","errno","response","data","detail","details"]){let a=r[i];a!==void 0&&typeof a!="function"&&(s[i]=Pe(a))}for(let i of Object.keys(r)){if(i==="message"||i==="stack"||i==="name"||i==="cause"||i in s)continue;let a=r[i];typeof a!="function"&&(s[i]=Pe(a))}return{message:t,errorType:e,extras:Object.keys(s).length>0?s:null}}if(typeof Response<"u"&&r instanceof Response)return{message:`HTTP ${r.status} ${r.statusText||""}${r.url?` ${r.url}`:""}`.trim(),errorType:"Response",extras:{status:r.status,statusText:r.statusText,url:r.url,type:r.type}};if(typeof r=="object"){let e=r,t=e.constructor&&typeof e.constructor=="function"&&e.constructor.name||null,s=typeof e.message=="string"&&e.message?e.message:null,n=typeof e.name=="string"&&e.name?e.name:null,i=null;try{let u=JSON.stringify(e);i=u==="{}"?null:u}catch{i=null}let a=$(e),o=s??i??(a&&a!=="[object Object]"?a:null)??(t?`(thrown ${t} with no message)`:"(thrown object with no message)"),c=n??t??null,l={},d=0;for(let u of Object.keys(e)){if(d>=20)break;if(u==="message"||u==="name")continue;let m=e[u];typeof m!="function"&&(l[u]=Pe(m),d++)}return{message:o,errorType:c,extras:Object.keys(l).length>0?l:null}}return{message:$(r)||"(unstringifiable thrown value)",errorType:null,extras:null}}function Pr(r){let e=[],t=r.cause,s=0;for(;t!=null&&s<5;)t instanceof Error?(e.push({name:t.name||"Error",message:t.message||""}),t=t.cause):(e.push({name:"non-Error",message:$(t)}),t=null),s++;return e}function $(r){try{let e=Object.prototype.toString.call(r);if(e!=="[object Object]")return e;let t=r?.toString;if(typeof t=="function"&&t!==Object.prototype.toString){let s=t.call(r);if(typeof s=="string")return s}return e}catch{return"(throwing toString)"}}function Pe(r){if(r==null)return r;let e=typeof r;if(e==="string"||e==="number"||e==="boolean")return r;if(e==="bigint")return String(r);try{let t=JSON.stringify(r);return t===void 0?$(r):JSON.parse(t)}catch{return $(r)}}function Dr(r){return Ve(r).message}function ct(r){if(!r||typeof r!="string")return null;try{return new URL(r).hostname.toLowerCase()}catch{return null}}function De(r,e){if(!e||!r)return!1;try{return new URL(r).hostname.toLowerCase()===e}catch{return!1}}function Vr(r,e,t){if(e instanceof Error&&e.name==="AbortError")return!0;let s=t.navigator;if(s&&s.onLine===!1)return!0;let n=t.location?.href,i=t.location?.origin;if(!i)return!1;try{return new URL(r,n??i).origin===i}catch{return!1}}var G=class{constructor(){this.state=null;this.verifiers=null;this.verifierReporter=null;this.verifierCtx=null}init(e){if(this.state){try{this.state.uninstallUnloadFlush?.()}catch{}try{this.state.autoTracker?.uninstall()}catch{}try{this.state.webVitals?.uninstall()}catch{}try{this.state.errors?.uninstall()}catch{}try{this.state.events.flush({keepalive:!0})}catch{}}if(!e.publicKey||!e.publicKey.startsWith("cd_pub_"))throw new _({type:"configuration_error",code:"invalid_public_key",message:"Crossdeck.init requires a publishable key starting with cd_pub_."});if(!e.appId)throw new _({type:"configuration_error",code:"missing_app_id",message:"Crossdeck.init requires an appId. Find yours in the Crossdeck dashboard."});if(e.environment!=="production"&&e.environment!=="sandbox")throw new _({type:"configuration_error",code:"invalid_environment",message:'Crossdeck.init requires environment: "production" | "sandbox".'});let t=Or(e.publicKey);if(t&&t!==e.environment)throw new _({type:"configuration_error",code:"environment_mismatch",message:`Crossdeck.init: environment "${e.environment}" disagrees with key prefix (${t}). Reconcile the publishable key with the environment declaration.`});let s=Fr(),n=e.storage??Le(),i=e.persistIdentity??!0,a=Lr(e.autoTrack),o={appId:e.appId,publicKey:e.publicKey,environment:e.environment,baseUrl:e.baseUrl??Y,persistIdentity:i,storagePrefix:e.storagePrefix??"crossdeck:",autoHeartbeat:e.autoHeartbeat??!0,eventFlushBatchSize:e.eventFlushBatchSize??20,eventFlushIntervalMs:e.eventFlushIntervalMs??2e3,sdkVersion:e.sdkVersion??R,autoTrack:a,appVersion:e.appVersion??null},c=new ie;c.enabled=e.debug===!0;let l=new X({publicKey:o.publicKey,baseUrl:o.baseUrl,sdkVersion:o.sdkVersion,localDevMode:s,onErrorParsed:f=>{this.verifiers&&this.verifierReporter&&this.verifierCtx&&it(this.verifiers,this.verifierReporter,this.verifierCtx,{errorType:f.type,errorCode:f.code,requestId:f.requestId??null,httpStatus:typeof f.status=="number"?f.status:0})}});s&&console.log("[crossdeck] Localhost detected \u2014 running in dev mode (no network calls). Set publicKey: 'cd_pub_test_\u2026' and deploy to a real domain to test against the Crossdeck Sandbox.");let d=i?n:new O,m=i&&!e.storage&&typeof globalThis.document<"u"?new se:void 0,p=new Q(d,o.storagePrefix,m),y=new P(d,o.storagePrefix+"entitlements"),k=i?new re({storage:d,prefix:o.storagePrefix}):null;k&&c.emit("sdk.queue_restored","Restored persisted event queue from a prior session.");let g=new te({http:l,batchSize:o.eventFlushBatchSize,intervalMs:o.eventFlushIntervalMs,envelope:()=>({appId:o.appId,environment:o.environment,sdk:{name:A,version:o.sdkVersion}}),persistentStore:k??void 0,onFirstFlushSuccess:()=>{c.emit("sdk.first_event_sent","First telemetry event received. View it in Live Events.",{appId:o.appId,environment:o.environment})},onRetryScheduled:f=>{c.emit("sdk.flush_retry_scheduled",`Event flush failed (${f.lastError}). Retrying in ${f.delayMs}ms (attempt ${f.consecutiveFailures}).`,{...f})},onPermanentFailure:f=>{let w=`[crossdeck] Event batch DROPPED (status ${f.status}): ${f.lastError}. ${f.droppedCount} event(s) lost \u2014 check your publishable key + app config.`;console.error(w),c.emit("sdk.flush_permanent_failure",w,{...f})},onParked:f=>{c.emit("sdk.parked",`[crossdeck] SDK parked \u2014 server no longer accepts this version's event format. Events held on-device (paused, not lost); update @cross-deck/web${f.minVersion?` to >= ${f.minVersion}`:""} to resume.`,{...f})}}),v=a.deviceInfo?Ne({appVersion:o.appVersion??void 0}):o.appVersion?{appVersion:o.appVersion}:{},S=new ae(i?d:new O,o.storagePrefix);We();let T=new de({respectDnt:e.respectDnt===!0});T.isDntDenied&&c.emit("sdk.consent_dnt_applied","Do Not Track detected \u2014 all tracking dimensions denied at init.");let C=new le(50);if(this.state={http:l,identity:p,entitlements:y,events:g,autoTracker:null,webVitals:null,errors:null,breadcrumbs:C,errorContext:{},errorTags:{},errorBeforeSend:null,superProps:S,consent:T,scrubPii:e.scrubPii!==!1,deviceInfo:v,options:o,debug:c,developerUserId:null,uninstallUnloadFlush:null,lastServerTime:null,lastClientTime:null},c.emit("sdk.configured",`Crossdeck connected to ${o.appId} in ${o.environment} mode.`,{appId:o.appId,environment:o.environment,sdkVersion:o.sdkVersion}),a.sessions||a.pageViews){let f=new j(a,(w,E)=>this.track(w,E),{storage:d,storageKey:o.storagePrefix+"session"});this.state.autoTracker=f,f.install()}if(a.webVitals){let f=new ce({enabled:!0},(w,E)=>this.track(w,E));this.state.webVitals=f,f.install()}if(a.errors){let f=new he({config:{...at,enabled:!0},breadcrumbs:C,report:w=>this.reportError(w),getContext:()=>({...this.state.errorContext}),getTags:()=>({...this.state.errorTags}),beforeSend:()=>this.state.errorBeforeSend,isConsented:()=>this.state.consent.errors,selfHostname:ct(o.baseUrl)});this.state.errors=f,f.install()}if(this.state.uninstallUnloadFlush=Nr(()=>{this.flush({keepalive:!0}).catch(()=>{})}),o.autoHeartbeat&&!s&&this.heartbeat().catch(()=>{}),e.disableContractAssertions!==!0){let f=ot();this.verifierCtx=Ze({logVerifierResults:e.logVerifierResults??f,disableContractAssertions:!1,runContext:typeof process<"u"&&process.env&&process.env.CI?"ci":"customer-app"}),this.verifierReporter=new z(this.verifierCtx);let w=et(o.eventFlushIntervalMs);this.verifiers=Object.freeze([...tt,w]),s?(e.verifyContractsAtBoot??f)&&this.verifierReporter&&Ie(this.verifiers,this.verifierReporter,this.verifierCtx).catch(()=>{}):this.bootstrapVerifierLayerRemote(e,f).catch(()=>{})}}async bootstrapVerifierLayerRemote(e,t){if(!this.state||!this.verifiers||!this.verifierCtx)return;let s={logVerifierResults:null,verifyContractsAtBoot:null};try{let a=await this.state.http.request("GET","/config");if(a&&a.verifierConfig){let o=a.verifierConfig;s={logVerifierResults:typeof o.logVerifierResults=="boolean"?o.logVerifierResults:null,verifyContractsAtBoot:typeof o.verifyContractsAtBoot=="boolean"?o.verifyContractsAtBoot:null}}}catch{}let n=e.logVerifierResults??s.logVerifierResults??t,i=e.verifyContractsAtBoot??s.verifyContractsAtBoot??t;n!==this.verifierCtx.logVerifierResults&&(this.verifierCtx={...this.verifierCtx,logVerifierResults:n},this.verifierReporter=new z(this.verifierCtx)),i&&this.verifierReporter&&await Ie(this.verifiers,this.verifierReporter,this.verifierCtx)}start(e){typeof console<"u"&&console.warn("[crossdeck] Crossdeck.start() is deprecated \u2014 use Crossdeck.init() instead. The signature is the same."),this.init(e)}async identify(e,t){let s=this.requireStarted();if(!e)throw new _({type:"invalid_request_error",code:"missing_user_id",message:"identify(userId) requires a non-empty userId."});if(ye({actor:e}),!s.consent.analytics)return s.debug.emit("sdk.consent_denied","identify() skipped \u2014 consent denied for analytics."),{object:"alias_result",crossdeckCustomerId:s.identity.crossdeckCustomerId??"",linked:[],mergePending:!1,env:s.options.environment};let n=t?.traits!==void 0?W(t.traits):null,i=n&&Object.keys(n.properties).length>0?n.properties:void 0;if(s.debug.enabled&&n&&n.warnings.length>0)for(let l of n.warnings)s.debug.emit("sdk.property_coerced",`identify() traits key ${JSON.stringify(l.key)} was ${l.kind.replace(/_/g," ")} during validation.`,{key:l.key,kind:l.kind});let a={userId:e,anonymousId:s.identity.anonymousId};t?.email&&(a.email=t.email),i&&(a.traits=i);let o=s.developerUserId;s.entitlements.setUserKey(e),this.verifiers&&this.verifierReporter&&this.verifierCtx&&rt(this.verifiers,this.verifierReporter,this.verifierCtx,{priorUserId:o,nextUserId:e,cache:s.entitlements});let c=await s.http.request("POST","/identity/alias",{body:a});return s.identity.setCrossdeckCustomerId(c.crossdeckCustomerId),s.developerUserId=e,c}register(e){let t=this.requireStarted(),s=W(e);return t.superProps.register(s.properties)}unregister(e){this.requireStarted().superProps.unregister(e)}getSuperProperties(){return this.state?this.state.superProps.getSuperProperties():{}}group(e,t,s){let n=this.requireStarted();if(!e)throw new _({type:"invalid_request_error",code:"missing_group_type",message:"group(type, id) requires a non-empty type."});let i=s?W(s).properties:void 0;n.superProps.setGroup(e,t,i)}getGroups(){return this.state?this.state.superProps.getGroups():{}}consent(e){let t=this.requireStarted(),s=t.consent.set(e);return t.debug.emit("sdk.consent_changed","Consent state updated.",{...s}),s}consentStatus(){return this.state?this.state.consent.get():{analytics:!0,marketing:!0,errors:!0}}captureError(e,t){this.state?.errors&&this.state.errors.captureError(e,t)}captureMessage(e,t="info"){this.state?.errors&&this.state.errors.captureMessage(e,t)}setTag(e,t){this.state&&(this.state.errorTags[e]=t)}setTags(e){this.state&&Object.assign(this.state.errorTags,e)}setContext(e,t){this.state&&(this.state.errorContext[e]=t)}addBreadcrumb(e){this.state&&this.state.breadcrumbs.add(e)}setErrorBeforeSend(e){this.state&&(this.state.errorBeforeSend=e)}reportError(e){let t={fingerprint:e.fingerprint,level:e.level,errorType:e.errorType,message:e.message,stack:e.rawStack??void 0,frames:e.frames,filename:e.filename??void 0,lineno:e.lineno??void 0,colno:e.colno??void 0,tags:e.tags,context:e.context,breadcrumbs:e.breadcrumbs,http:e.http};for(let s of Object.keys(t))t[s]===void 0&&delete t[s];this.track(e.kind,t)}async forget(){let e=this.requireStarted(),t=this.identityQueryParams();try{await e.http.request("POST","/identity/forget",{body:{...t}})}catch(s){e.debug.emit("sdk.consent_denied",`forget() server call failed (${s instanceof Error?s.message:String(s)}). Local state wiped anyway.`)}this.reset()}async getEntitlements(){let e=this.requireStarted(),t=this.identityQueryParams(),s;try{s=await e.http.request("GET","/entitlements",{query:t})}catch(n){throw e.entitlements.markRefreshFailed(),n}return s.crossdeckCustomerId&&e.identity.setCrossdeckCustomerId(s.crossdeckCustomerId),e.entitlements.setFromList(s.data),s.data}isEntitled(e){return this.requireStarted().entitlements.isEntitled(e)}listEntitlements(){return this.requireStarted().entitlements.list()}onEntitlementsChange(e){return this.requireStarted().entitlements.subscribe(e)}reportContractFailure(e){let t={contract_id:e.contractId,sdk_version:R,sdk_platform:"web",failure_reason:e.failureReason,run_context:e.runContext,run_id:e.runId};e.testRef&&(t.test_file=e.testRef.file,t.test_name=e.testRef.name),e.deviceClass&&(t.device_class=e.deviceClass),ue(t)}track(e,t){let s=this.requireStarted();if(!e)throw new _({type:"invalid_request_error",code:"missing_event_name",message:"track(name) requires a non-empty name."});let n=e.startsWith("error."),i=e.startsWith("webvitals.");if(!(n||i?s.consent.errors:s.consent.analytics)){s.debug.enabled&&s.debug.emit("sdk.consent_denied",`Dropped event "${e}" \u2014 consent denied for ${i?"errors":"analytics"}.`);return}if(s.debug.enabled&&t){let f=Me(t);f.length>0&&s.debug.emit("sdk.sensitive_property_warning",`Event "${e}" has potentially sensitive property names: ${f.join(", ")}. Crossdeck is privacy-first \u2014 avoid sending PII unless intentional.`,{eventName:e,flagged:f})}s.debug.enabled&&!s.developerUserId&&!s.identity.crossdeckCustomerId&&s.debug.emit("sdk.no_identity","Using anonymous user until identify(userId) is called.");let o=W(t);if(s.debug.enabled&&o.warnings.length>0)for(let f of o.warnings)s.debug.emit("sdk.property_coerced",`Event "${e}" property ${JSON.stringify(f.key)} was ${f.kind.replace(/_/g," ")} during validation.`,{eventName:e,key:f.key,kind:f.kind});let c=s.autoTracker?.nextSeq()??0,l=Date.now();s.autoTracker?.markActivity();let d={},u=s.deviceInfo;u.os&&(d.os=u.os),u.osVersion&&(d.osVersion=u.osVersion);let m=s.options.appVersion;m&&(d.appVersion=m),d.sdkName=A,d.sdkVersion=s.options.sdkVersion,u.locale&&(d.locale=u.locale),u.timezone&&(d.timezone=u.timezone),u.browser&&(d.browser=u.browser),u.browserVersion&&(d.browserVersion=u.browserVersion);let p={};u.screenWidth!==void 0&&(p.screenWidth=u.screenWidth),u.screenHeight!==void 0&&(p.screenHeight=u.screenHeight),u.viewportWidth!==void 0&&(p.viewportWidth=u.viewportWidth),u.viewportHeight!==void 0&&(p.viewportHeight=u.viewportHeight),u.devicePixelRatio!==void 0&&(p.devicePixelRatio=u.devicePixelRatio);let y=s.autoTracker?.currentSessionId;y&&(p.sessionId=y);let k=s.autoTracker?.currentPageviewId;k&&(p.pageviewId=k);let g=s.autoTracker?.currentAcquisition;g&&(g.utm_source&&(p.utm_source=g.utm_source),g.utm_medium&&(p.utm_medium=g.utm_medium),g.utm_campaign&&(p.utm_campaign=g.utm_campaign),g.utm_content&&(p.utm_content=g.utm_content),g.utm_term&&(p.utm_term=g.utm_term),g.referrer&&s.consent.marketing&&(p.referrer=g.referrer),s.consent.marketing&&(g.gclid&&(p.gclid=g.gclid),g.fbclid&&(p.fbclid=g.fbclid),g.msclkid&&(p.msclkid=g.msclkid),g.ttclid&&(p.ttclid=g.ttclid),g.li_fat_id&&(p.li_fat_id=g.li_fat_id),g.twclid&&(p.twclid=g.twclid)));let v=s.superProps.getSuperProperties();for(let f of Object.keys(v))f in p||(p[f]=v[f]);let S=s.superProps.getGroupIds();Object.keys(S).length>0&&(p.$groups=S),Object.assign(p,o.properties),He()&&(p[Be]=!0);let T=s.scrubPii?Ee(p):p,C={eventId:this.mintEventId(),name:e,timestamp:l,seq:c,context:d,properties:T};if(Object.assign(C,this.identityHintForEvent()),s.events.enqueue(C),this.verifiers&&this.verifierReporter&&this.verifierCtx&&st(this.verifiers,this.verifierReporter,this.verifierCtx,{callerProperties:o.properties,superProperties:v,deviceProperties:s.deviceInfo,mergedProperties:p}),!n&&!i){let f=e.startsWith("page.")?"navigation":e.startsWith("element.")||e==="session.started"?"ui.click":"custom";s.breadcrumbs.add({timestamp:C.timestamp,category:f,message:e,data:t?{...t}:void 0})}}async flush(e={}){await this.requireStarted().events.flush(e)}async flushEvents(){return this.flush()}async syncPurchases(e){let t=this.requireStarted();if(!e.signedTransactionInfo)throw new _({type:"invalid_request_error",code:"missing_signed_transaction_info",message:"syncPurchases requires a signedTransactionInfo string from StoreKit 2."});let s=e.rail??"apple",n={...e,rail:s},i=L(n);if(this.verifiers&&this.verifierReporter&&this.verifierCtx){let o=s==="apple"?n.signedTransactionInfo??"":n.purchaseToken??"";nt(this.verifiers,this.verifierReporter,this.verifierCtx,{rail:s,stableIdentifier:o,derivedKey:i})}let a=await t.http.request("POST","/purchases/sync",{body:n,idempotencyKey:i});t.identity.setCrossdeckCustomerId(a.crossdeckCustomerId),t.entitlements.setFromList(a.entitlements);try{let o=a.entitlements[0]?.source.productId,c=a.entitlements[0]?.source.subscriptionId,l={rail:s};o&&(l.productId=o),c&&(l.subscriptionId=c),a.idempotent_replay&&(l.idempotent_replay=!0),this.track("purchase.completed",l)}catch{}return t.debug.emit("sdk.purchase_evidence_sent","StoreKit transaction forwarded. Waiting for backend verification.",{rail:e.rail??"apple"}),a}async purchaseApple(e){return this.syncPurchases({rail:"apple",...e})}setDebugMode(e){let t=this.requireStarted();t.debug.enabled=e,e&&t.debug.emit("sdk.configured",`Debug mode enabled for ${t.options.appId} in ${t.options.environment} mode.`,{appId:t.options.appId,environment:t.options.environment})}async heartbeat(){let e=this.requireStarted(),t=await e.http.request("GET","/sdk/heartbeat");return typeof t?.serverTime=="number"&&Number.isFinite(t.serverTime)&&(e.lastServerTime=t.serverTime,e.lastClientTime=Date.now()),t}reset(){if(this.state){if(this.state.developerUserId)try{this.track("user.signed_out",{auto:!0})}catch{}if(this.state.autoTracker?.uninstall(),this.state.identity.reset(),ye({actor:void 0}),this.state.entitlements.clearAll(),this.state.events.reset(),this.state.superProps.clear(),this.state.breadcrumbs.clear(),this.state.errorContext={},this.state.errorTags={},this.state.developerUserId=null,this.state.lastServerTime=null,this.state.lastClientTime=null,this.state.autoTracker){let e=new j(this.state.options.autoTrack,(t,s)=>this.track(t,s));this.state.autoTracker=e,e.install()}}}diagnostics(){if(!this.state)return{started:!1,anonymousId:null,crossdeckCustomerId:null,developerUserId:null,sdkVersion:null,baseUrl:null,clock:{lastServerTime:null,lastClientTime:null,skewMs:null},entitlements:{count:0,lastUpdated:0,stale:!1,listenerErrors:0},events:{buffered:0,dropped:0,inFlight:0,lastFlushAt:0,lastError:null,consecutiveFailures:0,nextRetryAt:null}};let e=this.state,t=e.lastServerTime!==null&&e.lastClientTime!==null?e.lastClientTime-e.lastServerTime:null;return{started:!0,anonymousId:e.identity.anonymousId,crossdeckCustomerId:e.identity.crossdeckCustomerId,developerUserId:e.developerUserId,sdkVersion:e.options.sdkVersion,baseUrl:e.options.baseUrl,clock:{lastServerTime:e.lastServerTime,lastClientTime:e.lastClientTime,skewMs:t},entitlements:{count:e.entitlements.list().length,lastUpdated:e.entitlements.freshness,stale:e.entitlements.isStale,listenerErrors:e.entitlements.listenerErrors},events:e.events.getStats()}}getCheckoutReference(){let e=this.requireStarted();return e.identity.crossdeckCustomerId??e.developerUserId??e.identity.anonymousId}getAnonymousId(){return this.state?this.state.identity.anonymousId:null}requireStarted(){if(!this.state)throw new _({type:"configuration_error",code:"not_initialized",message:"Call Crossdeck.init({ appId, publicKey, environment }) before any other method."});return this.state}identityQueryParams(){let e=this.requireStarted();return e.identity.crossdeckCustomerId?{customerId:e.identity.crossdeckCustomerId}:e.developerUserId?{userId:e.developerUserId}:{anonymousId:e.identity.anonymousId}}identityHintForEvent(){let e=this.requireStarted(),t={anonymousId:e.identity.anonymousId};return e.developerUserId&&(t.developerUserId=e.developerUserId),e.identity.crossdeckCustomerId&&(t.crossdeckCustomerId=e.identity.crossdeckCustomerId),t}mintEventId(){return`evt_${Date.now().toString(36)}${V(8)}`}},dt=new G;function Or(r){return r.startsWith("cd_pub_test_")?"sandbox":r.startsWith("cd_pub_live_")?"production":null}function Fr(){let r=globalThis.window;if(r?.__CROSSDECK_FORCE_LIVE__===!0)return!1;let e=r?.location?.hostname;return e?!!(e==="localhost"||e==="127.0.0.1"||e==="0.0.0.0"||e==="::1"||e==="[::1]"||/^\[?fe80::/i.test(e)||e.endsWith(".local")||/^10\./.test(e)||/^192\.168\./.test(e)||/^172\.(1[6-9]|2\d|3[0-1])\./.test(e)):!1}function Lr(r){return r===!1?{sessions:!1,pageViews:!1,deviceInfo:!1,clicks:!1,webVitals:!1,errors:!1}:r===void 0||r===!0?{...F}:{sessions:r.sessions??F.sessions,pageViews:r.pageViews??F.pageViews,deviceInfo:r.deviceInfo??F.deviceInfo,clicks:r.clicks??F.clicks,webVitals:r.webVitals??F.webVitals,errors:r.errors??F.errors}}function Nr(r){let e=globalThis.window,t=globalThis.document;if(!e||!t)return()=>{};let s=()=>{t.visibilityState==="hidden"&&r()},n=()=>r();return t.addEventListener("visibilitychange",s),e.addEventListener("pagehide",n),e.addEventListener("beforeunload",n),()=>{t.removeEventListener("visibilitychange",s),e.removeEventListener("pagehide",n),e.removeEventListener("beforeunload",n)}}var lt="@cross-deck/web@1.8.0",ut="1.8.0",U=Object.freeze([{id:"contract-failed-payload-schema-lock",pillar:"diagnostics",status:"enforced",claim:"The `crossdeck.contract_failed` event payload contains ONLY the named diagnostic fields and never any end-user personal data. The wire shape is fixed \u2014 adding a new field requires (1) a pull request that updates this contract's `allowedFields` set, (2) a Privacy Policy \xA76 amendment, and (3) the Customer Disclosure Template / SDK Data Collection Reference \xA7B updates. Per-SDK assertion tests enforce the field set on every release. The `verification_phase` field is a categorical bucket \u2014 values are restricted to `boot` (the SDK self-test ran on Crossdeck.start) or `hot_path` (a verifier observed a real customer-triggered operation). The categorical nature is what preserves the diagnostic-only-not-personal classification. This is the structural guarantee that backs the independent-controller lawful basis in the Privacy Policy: the payload remains diagnostic-only, not personal, so the legitimate-interest analysis stays valid as the SDK evolves.",appliesTo:["web","node","swift","android","react-native"],allowedFields:{required:["contract_id","sdk_version","sdk_platform","failure_reason","run_context","run_id"],optional:["test_file","test_name","device_class","verification_phase"],forbidden:["anonymousId","developerUserId","crossdeckCustomerId","email","ip","user_agent","message","stack","stack_trace","frames","exception_message","url","path","screen","title","label","text","ariaLabel","accessibilityLabel","contentDescription","session_id","sessionId"]},transport:"Telemetry is single-fire to the Crossdeck reliability endpoint only \u2014 NOT the customer's appId. The customer's track() pipeline never carries `crossdeck.*` events; the customer's dashboard never shows individual contract failures. Operational telemetry flows one-way to the Crossdeck operations team for SDK reliability purposes (legitimate interest, independent-controller flow per Privacy Policy \xA76). The reliability endpoint is hardcoded at SDK build time; the publishable key for the reliability project is embedded as a constant and rejects writes that don't match the schema.",codeRef:["sdks/web/src/crossdeck.ts","sdks/node/src/crossdeck-server.ts","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/swift/Sources/Crossdeck/_DiagnosticTelemetry.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/_DiagnosticTelemetry.kt","sdks/react-native/src/crossdeck.ts","backend/src/api/v1-sdk-diagnostic.ts","sdks/web/src/_diagnostic-telemetry.ts","sdks/node/src/_diagnostic-telemetry.ts","sdks/react-native/src/_diagnostic-telemetry.ts"],testRef:[{file:"sdks/web/tests/contract-failed-schema-lock.test.ts",name:"reportContractFailure payload conforms to schema-lock"},{file:"sdks/node/tests/contract-failed-schema-lock.test.ts",name:"reportContractFailure payload conforms to schema-lock"},{file:"sdks/swift/Tests/CrossdeckTests/ContractFailedSchemaLockTests.swift",name:"test_reportContractFailure_payloadFieldsAreInAllowList"},{file:"sdks/swift/Tests/CrossdeckTests/ContractFailedSchemaLockTests.swift",name:"test_reportContractFailure_doesNotEnterCustomerTrackPipeline"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ContractFailedSchemaLockTest.kt",name:"reportContractFailure payload conforms to schema-lock"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ContractFailedSchemaLockTest.kt",name:"reportContractFailure does not enter customer track pipeline"},{file:"sdks/react-native/tests/contract-failed-schema-lock.test.ts",name:"reportContractFailure payload conforms to schema-lock"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"forbidden fields are enumerated in the schema-lock contract"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"required fields are enumerated in the schema-lock contract"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"regression guard: never returns a raw IP"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"verification_phase is in the optional field set"}],registeredAt:"2026-05-27",firstRegisteredIn:"Diagnostic telemetry single-fire + schema-lock \u2014 independent-controller flow",privacyReferences:["legal/privacy/index.html#sdk-diagnostic","legal/customer-disclosure/index.html#flow-b","legal/security/index.html#diagnostic","legal/sdk-data/index.html#b-diagnostic"],bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"error-envelope-shape",pillar:"errors",status:"enforced",claim:"Every v1 REST endpoint returns errors in a Stripe-shape envelope: `{ error: { type, code, message, request_id } }` where `type` is one of authentication_error / permission_error / invalid_request_error / rate_limit_error / internal_error (the wire vocabulary in backend/src/api/v1-errors.ts ApiErrorType). HTTP status parity: invalid_request_error \u2192 400, authentication_error \u2192 401, permission_error \u2192 403, rate_limit_error \u2192 429, internal_error \u2192 500. SDK-side clients parse this shape via `crossdeckErrorFromResponse` (Web/Node/RN) / `crossdeckErrorFrom(response:)` (Swift) / `crossdeckErrorFromResponse` (Android) and surface the request_id verbatim so support traces are end-to-end joinable. Firebase callable endpoints (managed-keys / dashboard auth) use the Firebase HttpsError envelope instead \u2014 this contract applies to REST /v1/* only.",appliesTo:["web","node","react-native","swift","android","backend"],codeRef:["backend/src/api/v1-errors.ts","sdks/web/src/errors.ts","sdks/node/src/errors.ts","sdks/react-native/src/errors.ts","sdks/swift/Sources/Crossdeck/Errors.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Errors.kt"],testRef:[{file:"sdks/swift/Tests/CrossdeckTests/ErrorsTests.swift",name:"test_errorEnvelope_fallsBackOnGarbageBody"},{file:"sdks/swift/Tests/CrossdeckTests/ErrorsTests.swift",name:"test_errorEnvelope_reads_XRequestId_fallback"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ErrorTypeWireVocabTest.kt",name:"backend 500 response parses to INTERNAL_ERROR"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 8 (codifies existing contract)",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"flush-interval-parity",pillar:"analytics",status:"enforced",claim:"Every Crossdeck SDK defaults its event-queue flush interval to 2000ms \u2014 the Stripe-adjacent industry norm. Pre-v1.4.0 the defaults disagreed (Web/Node 1500ms; RN/Swift/Android 5000ms), so cross-platform funnels saw events landing at different cadences. Per-instance override stays \u2014 call sites can still tune it freely.",appliesTo:["web","node","react-native","swift","android"],codeRef:["sdks/web/src/crossdeck.ts","sdks/node/src/crossdeck-server.ts","sdks/react-native/src/crossdeck.ts","sdks/swift/Sources/Crossdeck/EventQueue.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EventQueue.kt"],testRef:[{file:"sdks/swift/Sources/Crossdeck/EventQueue.swift",name:"flushIntervalMs: Int = 2_000"},{file:"sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EventQueue.kt",name:"flushIntervalMs: Long = 2_000L"},{file:"sdks/web/src/crossdeck.ts",name:"options.eventFlushIntervalMs ?? 2000"},{file:"sdks/node/src/crossdeck-server.ts",name:"options.eventFlushIntervalMs ?? 2000"},{file:"sdks/react-native/src/crossdeck.ts",name:"options.eventFlushIntervalMs ?? 2000"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 3.3",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"idempotency-key-deterministic",pillar:"revenue",status:"enforced",claim:"syncPurchases() on every SDK derives a deterministic Idempotency-Key from the request body (UUID-shaped SHA-256 of `crossdeck:purchases/sync:<rail>:<jws|token>`). Same input -> same key. Backend short-circuits same-key-same-body retries by returning the cached response (status + body) with `idempotent_replay: true` flag in the body AND `Idempotent-Replayed: true` response header. Same-key-different-body returns 400 `idempotency_key_in_use`. 24-hour TTL matches Stripe. Cache only stores 2xx responses \u2014 4xx/5xx pass through so callers can fix bugs and retry. Helper returns nil/throws on missing identifier (no silent random fallback). Cross-SDK parity is CI-pinned: deriveForPurchase('apple', 'eyJ.jws.sig') MUST equal 'a66b1640-efaf-bb4d-1261-6650033bf111' on every SDK.",appliesTo:["web","node","react-native","swift","android","backend"],codeRef:["sdks/web/src/idempotency-key.ts","sdks/web/src/crossdeck.ts","sdks/react-native/src/idempotency-key.ts","sdks/react-native/src/crossdeck.ts","sdks/node/src/idempotency-key.ts","sdks/node/src/crossdeck-server.ts","sdks/swift/Sources/Crossdeck/IdempotencyKey.swift","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/IdempotencyKey.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt","backend/src/lib/idempotency-response-cache.ts","backend/src/api/v1-purchases.ts"],testRef:[{file:"sdks/web/tests/idempotency-key.test.ts",name:"cross-SDK oracle \u2014 apple JWS pins canonical vector"},{file:"sdks/web/tests/idempotency-key.test.ts",name:"is deterministic: same body twice -> identical key"},{file:"sdks/web/tests/idempotency-key.test.ts",name:"same identifier under different rails -> different keys"},{file:"sdks/web/tests/idempotency-key.test.ts",name:"never silently falls back to a random key on missing identifier"},{file:"sdks/react-native/tests/idempotency-key.test.ts",name:"is deterministic"},{file:"sdks/react-native/tests/idempotency-key.test.ts",name:"cross-SDK oracle \u2014 apple JWS pins canonical vector"},{file:"sdks/node/tests/idempotency-key.test.ts",name:"is deterministic"},{file:"sdks/node/tests/idempotency-key.test.ts",name:"rail namespacing prevents cross-rail collisions"},{file:"sdks/node/tests/idempotency-key.test.ts",name:"apple JWS produces the canonical pinned UUID across all 5 SDKs"},{file:"backend/tests/unit/idempotency-response-cache.test.ts",name:"is deterministic for the same input"},{file:"backend/tests/unit/idempotency-response-cache.test.ts",name:"injects idempotent_replay: true into a JSON object body"},{file:"backend/tests/unit/idempotency-response-cache.test.ts",name:"matches Stripe's 24-hour idempotency window"},{file:"sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",name:"test_crossSdkOracle_appleJWS"},{file:"sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",name:"test_railNamespacing_preventsCrossRailCollisions"},{file:"sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",name:"test_missingIdentifier_returnsNil"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",name:"cross-SDK oracle for apple JWS"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",name:"rail namespacing prevents cross-rail collisions"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",name:"missing identifier returns null - never silent random fallback"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 2.2.a + 2.2.b + 2.2.c",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"init-reentry-drains-prior-queue",pillar:"lifecycle",status:"enforced",claim:"Web + RN init() re-entry drains the prior EventQueue's pending setTimeout BEFORE replacing this.state. Pre-v1.4.0 the teardown handled autoTracker/webVitals/errors/unloadFlush but NOT events, so the prior queue's timer would fire AFTER the state swap \u2014 sending old-init events against new-init http + identity references (cross-identity leak during HMR / config swap / multi-tenant SDK shells). The teardown CANNOT call persistent.clear() \u2014 the durable queue belongs to the SDK lifetime, not the init() lifetime, and a survived crash mid-flush re-hydrates on the next init.",appliesTo:["web","react-native"],codeRef:["sdks/web/src/crossdeck.ts","sdks/react-native/src/crossdeck.ts"],testRef:[{file:"sdks/web/tests/init-reentry.test.ts",name:"re-init drains the prior queue's pending timer before swapping state"},{file:"sdks/web/tests/init-reentry.test.ts",name:"re-init does NOT wipe the durable event store"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 5.5",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!1},{id:"per-user-cache-isolation",pillar:"entitlements",status:"enforced",claim:"Every identify(userId) switches the entitlement cache to a physically separate per-user storage slot \u2014 `crossdeck:entitlements:<sha256(userId)>` \u2014 and unconditionally wipes the in-memory snapshot. A user-switch on a shared device CANNOT cross-read a prior user's cached entitlements, even if the in-memory clear is somehow skipped, because the storage keys are physically separate. reset() wipes every per-user slot via the persisted index.",appliesTo:["web","react-native","swift","android"],codeRef:["sdks/web/src/entitlement-cache.ts","sdks/web/src/hash.ts","sdks/web/src/crossdeck.ts","sdks/react-native/src/entitlement-cache.ts","sdks/react-native/src/hash.ts","sdks/react-native/src/crossdeck.ts","sdks/swift/Sources/Crossdeck/EntitlementCache.swift","sdks/swift/Sources/Crossdeck/IdempotencyKey.swift","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EntitlementCache.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/IdempotencyKey.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt"],testRef:[{file:"sdks/web/tests/entitlement-cache-isolation.test.ts",name:"identify(B) makes A's entitlements unreachable from in-memory"},{file:"sdks/web/tests/entitlement-cache-isolation.test.ts",name:"clearAll() removes every per-user storage key plus the index"},{file:"sdks/web/tests/entitlement-cache-isolation.test.ts",name:"a second cache instance reading A's storage suffix CANNOT see B's data"},{file:"sdks/react-native/tests/entitlement-cache-isolation.test.ts",name:"identify(B) makes A's entitlements unreachable from in-memory"},{file:"sdks/react-native/tests/entitlement-cache-isolation.test.ts",name:"removes every per-user storage key plus the index"},{file:"sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",name:"test_identifyB_makesAEntitlementsUnreachable"},{file:"sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",name:"test_identifiedWritesLandUnderPerUserSha256Key"},{file:"sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",name:"test_clearAll_removesEveryPerUserStorageKeyPlusIndex"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"identified writes land under per-user sha256 key"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"identify B makes A entitlements unreachable from in-memory"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"clearAll removes every per-user storage key plus the index"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"a fresh cache bound to A's key CANNOT read B's blob"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 1.3 (web/RN) + dogfood-gap fix (swift + android)",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"sdk-error-codes-catalogue",pillar:"errors",status:"enforced",claim:"Web + Node SDK error-codes catalogues include EVERY backend-emitted ApiErrorCode with a description + resolution. Pre-v1.4.0 the catalogues documented codes the SDK threw ITSELF but ZERO backend codes \u2014 a developer hitting `invalid_api_key` / `origin_not_allowed` / `bundle_id_not_allowed` / `env_mismatch` / `idempotency_key_in_use` etc. got `undefined` from getErrorCode() and had to hunt for guidance. v1.4.0 backfills the catalogue from backend/src/api/v1-errors.ts so every wire code has a canonical 'what does this mean / what should I do' answer Stripe-style.",appliesTo:["web","node"],codeRef:["sdks/web/src/error-codes.ts","sdks/node/src/error-codes.ts","sdks/web/src/_contract-verifiers.ts","backend/src/api/v1-errors.ts"],testRef:[{file:"sdks/web/tests/contract-verifiers.test.ts",name:"sdk-error-codes-catalogue covers every backend wire code with remediation"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"includes backend code"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"invalid_api_key resolution points at the dashboard"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"idempotency_key_in_use resolution mentions Stripe-grade contract"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"identity-lock codes carry permission_error type"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"no entry has an empty description or resolution"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 6.2",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"super-property-merge-precedence",pillar:"analytics",status:"enforced",claim:"Every Crossdeck SDK merges event properties with the precedence device < super < caller (caller-supplied values win over registered super-properties, which win over auto-attached device info). Pre-v1.4.0 Swift had it INVERTED (super < device < caller \u2014 device clobbered super), so a `register('plan', 'pro')` super-property was silently overridden by auto-attached device fields whenever keys collided. Cross-SDK funnel queries on super-property keys returned different answers per platform.",appliesTo:["web","swift"],codeRef:["sdks/web/src/super-properties.ts","sdks/web/src/_contract-verifiers.ts","sdks/swift/Sources/Crossdeck/EventPropertyMerge.swift","sdks/swift/Sources/Crossdeck/Crossdeck.swift"],testRef:[{file:"sdks/web/tests/contract-verifiers.test.ts",name:"super-property-merge-precedence verifies caller > super > device"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_super_overrides_device"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_caller_overrides_super"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_full_precedence_chain"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_matchesWebNodeRNPrecedence"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 3.2",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"sync-purchases-funnel-parity",pillar:"analytics",status:"enforced",claim:"Manual syncPurchases() emits a `purchase.completed` analytics event on success across ALL SDKs (Web / Node / RN / Swift / Android). Pre-v1.4.0 only Swift/Android auto-track emitted it \u2014 Web/Node/RN manual calls + Swift/Android manual calls fired ZERO analytics. Schema mirrors the auto-track event name + rail/productId/subscriptionId so cross-platform funnels reconcile on every payment path. When the backend short-circuits via the v1.4.0 idempotency cache, the event also carries `idempotent_replay: true`.",appliesTo:["web","node","react-native","swift","android"],codeRef:["sdks/web/src/crossdeck.ts","sdks/node/src/crossdeck-server.ts","sdks/react-native/src/crossdeck.ts","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt"],testRef:[{file:"sdks/web/tests/sync-purchases-funnel.test.ts",name:"emits purchase.completed after a successful sync"},{file:"sdks/web/tests/sync-purchases-funnel.test.ts",name:"carries idempotent_replay=true when backend replied from cache"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 3.5",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!1}]);var ft={all(){return U.filter(r=>r.status==="enforced")},allIncludingHistorical(){return U},byId(r){return U.find(e=>e.id===r)},byPillar(r){return U.filter(e=>e.pillar===r&&e.status==="enforced")},withStatus(r){return U.filter(e=>e.status===r)},sdkVersion:ut,bundledIn:lt,findByTestName(r){return U.find(e=>e.testRef.some(t=>t.name===r))}};return vt(Ur);})();
|
|
1
|
+
"use strict";var Crossdeck=(()=>{var me=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var wt=(r,e)=>{for(var t in e)me(r,t,{get:e[t],enumerable:!0})},_t=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of kt(e))!vt.call(r,n)&&n!==t&&me(r,n,{get:()=>e[n],enumerable:!(s=bt(e,n))||s.enumerable});return r};var St=r=>_t(me({},"__esModule",{value:!0}),r);var Mr={};wt(Mr,{CROSSDECK_ERROR_CODES:()=>xe,Crossdeck:()=>ft,CrossdeckClient:()=>G,CrossdeckContracts:()=>mt,CrossdeckError:()=>_,DEFAULT_BASE_URL:()=>Y,MemoryStorage:()=>O,SDK_NAME:()=>A,SDK_VERSION:()=>R,getErrorCode:()=>fe});var _=class r extends Error{constructor(e){super(e.message),this.name="CrossdeckError",this.type=e.type,this.code=e.code,this.requestId=e.requestId,this.status=e.status,this.retryAfterMs=e.retryAfterMs,this.minVersion=e.minVersion,this.surface=e.surface,Object.setPrototypeOf(this,r.prototype)}};async function Fe(r){let e=r.headers.get("x-request-id")??void 0,t=Et(r.headers.get("retry-after")),s;try{s=await r.json()}catch{s=null}let n=s?.error;return n&&typeof n.type=="string"&&typeof n.code=="string"?new _({type:n.type,code:n.code,message:n.message??`HTTP ${r.status}`,requestId:n.request_id??e,status:r.status,retryAfterMs:t,minVersion:typeof n.minVersion=="string"?n.minVersion:void 0,surface:typeof n.surface=="string"?n.surface:void 0}):new _({type:xt(r.status),code:`http_${r.status}`,message:`HTTP ${r.status} ${r.statusText||""}`.trim(),requestId:e,status:r.status,retryAfterMs:t})}function Et(r){if(!r)return;let e=r.trim();if(!e)return;if(/^\d+(\.\d+)?$/.test(e)){let n=Number(e);return!Number.isFinite(n)||n<0?void 0:Math.round(n*1e3)}if(!/[a-zA-Z,/:]/.test(e))return;let t=Date.parse(e);if(!Number.isFinite(t))return;let s=t-Date.now();return s>0?s:0}function xt(r){return r===401?"authentication_error":r===403?"permission_error":r===429?"rate_limit_error":r>=400&&r<500?"invalid_request_error":"internal_error"}var R="1.10.3",A="@cross-deck/web";var Y="https://api.cross-deck.com/v1",Ct=15e3,X=class{constructor(e){this.config=e}async request(e,t,s={}){if(this.config.localDevMode)return Tt(t);let n=this.buildUrl(t,s.query),i={Authorization:`Bearer ${this.config.publicKey}`,"Crossdeck-Sdk-Version":`${A}@${this.config.sdkVersion}`,Accept:"application/json"};s.idempotencyKey&&(i["Idempotency-Key"]=s.idempotencyKey);let a;s.body!==void 0&&(i["Content-Type"]="application/json",a=JSON.stringify(s.body));let o=s.timeoutMs??this.config.timeoutMs??Ct,c=typeof AbortController<"u"&&o>0?new AbortController:null,l=null;c&&o>0&&(l=setTimeout(()=>c.abort(),o));let d;try{d=await fetch(n,{method:e,headers:i,body:a,keepalive:s.keepalive===!0,signal:c?.signal})}catch(u){let m=c?.signal?.aborted===!0;throw new _({type:"network_error",code:m?"request_timeout":"fetch_failed",message:m?`Request to ${t} aborted after ${o}ms`:u instanceof Error?u.message:"fetch failed"})}finally{l!==null&&clearTimeout(l)}if(!d.ok){let u=await Fe(d);if(this.config.onErrorParsed)try{this.config.onErrorParsed(u)}catch{}throw u}if(d.status!==204)try{return await d.json()}catch{throw new _({type:"internal_error",code:"invalid_json_response",message:"Server returned a 2xx with an unparseable body.",requestId:d.headers.get("x-request-id")??void 0,status:d.status})}}get isLocalDevMode(){return this.config.localDevMode===!0}buildUrl(e,t){let s=this.config.baseUrl.replace(/\/+$/,""),n=e.startsWith("/")?e:`/${e}`,i=s+n;if(t){let a=new URLSearchParams;for(let[c,l]of Object.entries(t))typeof l=="string"&&l.length>0&&a.append(c,l);let o=a.toString();o&&(i+=(i.includes("?")?"&":"?")+o)}return i}},J=null;function Tt(r){return r.startsWith("/sdk/heartbeat")?{object:"heartbeat",ok:!0,projectId:"proj_local_dev",appId:"app_local_dev",platform:"web",env:"sandbox",serverTime:Date.now()}:r.startsWith("/identity/alias")?(J||(J=`cdcust_local_${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID().replace(/-/g,"").slice(0,16):Math.random().toString(36).slice(2,18)}`),{object:"alias_result",crossdeckCustomerId:J,linked:[],mergePending:!1,env:"sandbox"}):r.startsWith("/entitlements")?{object:"list",data:[],crossdeckCustomerId:J??"",env:"sandbox"}:r.startsWith("/events")?{object:"list",received:0,env:"sandbox"}:{}}var K="anon_id",B="cdcust_id",Q=class{constructor(e,t,s){this.primary=e;this.prefix=t;this.secondary=s??null;let n=e.getItem(t+K),i=e.getItem(t+B),a=this.secondary?.getItem(t+K)??null,o=this.secondary?.getItem(t+B)??null,c=n??a,l=i??o;this.state={anonymousId:c??this.mintAnonymousId(),crossdeckCustomerId:l},(!n||!a)&&this.writeBoth(t+K,this.state.anonymousId),l&&(!i||!o)&&this.writeBoth(t+B,l)}get anonymousId(){return this.state.anonymousId}get crossdeckCustomerId(){return this.state.crossdeckCustomerId}setCrossdeckCustomerId(e){this.state.crossdeckCustomerId=e,this.writeBoth(this.prefix+B,e)}reset(){this.deleteBoth(this.prefix+K),this.deleteBoth(this.prefix+B),this.state={anonymousId:this.mintAnonymousId(),crossdeckCustomerId:null},this.writeBoth(this.prefix+K,this.state.anonymousId)}mintAnonymousId(){let e=Date.now().toString(36),t=V(10);return`anon_${e}${t}`}writeBoth(e,t){try{this.primary.setItem(e,t)}catch{}if(this.secondary)try{this.secondary.setItem(e,t)}catch{}}deleteBoth(e){try{this.primary.removeItem(e)}catch{}if(this.secondary)try{this.secondary.removeItem(e)}catch{}}};function V(r){let e="0123456789abcdefghijklmnopqrstuvwxyz",t=[],s=globalThis.crypto;if(s?.getRandomValues){let n=new Uint8Array(r);s.getRandomValues(n);for(let i=0;i<r;i++)t.push(e[n[i]%e.length]??"0")}else for(let n=0;n<r;n++)t.push(e[Math.floor(Math.random()*e.length)]??"0");return t.join("")}var It=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Rt(r){if(typeof TextEncoder<"u")return new TextEncoder().encode(r);let e=[];for(let t=0;t<r.length;t++){let s=r.charCodeAt(t);if(s>=55296&&s<=56319&&t+1<r.length){let n=r.charCodeAt(t+1);n>=56320&&n<=57343&&(s=65536+(s-55296<<10)+(n-56320),t++)}s<128?e.push(s):s<2048?(e.push(192|s>>6),e.push(128|s&63)):s<65536?(e.push(224|s>>12),e.push(128|s>>6&63),e.push(128|s&63)):(e.push(240|s>>18),e.push(128|s>>12&63),e.push(128|s>>6&63),e.push(128|s&63))}return new Uint8Array(e)}function q(r){let e=Rt(r),t=e.length*8,s=Math.floor((e.length+9+63)/64),n=new Uint8Array(s*64);n.set(e),n[e.length]=128;let i=Math.floor(t/4294967296),a=t>>>0,o=n.length-8;n[o+0]=i>>>24&255,n[o+1]=i>>>16&255,n[o+2]=i>>>8&255,n[o+3]=i&255,n[o+4]=a>>>24&255,n[o+5]=a>>>16&255,n[o+6]=a>>>8&255,n[o+7]=a&255;let c=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),l=new Uint32Array(64);for(let u=0;u<s;u++){let m=u*64;for(let f=0;f<16;f++)l[f]=(n[m+f*4]<<24|n[m+f*4+1]<<16|n[m+f*4+2]<<8|n[m+f*4+3])>>>0;for(let f=16;f<64;f++){let w=l[f-15],E=l[f-2],I=(w>>>7|w<<25)^(w>>>18|w<<14)^w>>>3,D=(E>>>17|E<<15)^(E>>>19|E<<13)^E>>>10;l[f]=l[f-16]+I+l[f-7]+D>>>0}let p=c[0],y=c[1],k=c[2],g=c[3],v=c[4],S=c[5],T=c[6],C=c[7];for(let f=0;f<64;f++){let w=(v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7),E=v&S^~v&T,I=C+w+E+It[f]+l[f]>>>0,D=(p>>>2|p<<30)^(p>>>13|p<<19)^(p>>>22|p<<10),gt=p&y^p&k^y&k,yt=D+gt>>>0;C=T,T=S,S=v,v=g+I>>>0,g=k,k=y,y=p,p=I+yt>>>0}c[0]=c[0]+p>>>0,c[1]=c[1]+y>>>0,c[2]=c[2]+k>>>0,c[3]=c[3]+g>>>0,c[4]=c[4]+v>>>0,c[5]=c[5]+S>>>0,c[6]=c[6]+T>>>0,c[7]=c[7]+C>>>0}let d="";for(let u=0;u<8;u++)d+=c[u].toString(16).padStart(8,"0");return d}var At=1440*60*1e3,Z="_anon",Pt="_index",P=class r{constructor(e,t="crossdeck:entitlements",s=At){this.all=[];this.lastUpdated=0;this.lastRefreshFailedAt=0;this.listeners=new Set;this.listenerErrorCount=0;this.currentSuffix=Z;this.storage=e,this.storageKeyPrefix=t,this.staleAfterMs=s,this.hydrate()}get storageKey(){return`${this.storageKeyPrefix}:${this.currentSuffix}`}get indexKey(){return`${this.storageKeyPrefix}:${Pt}`}static suffixForUserId(e){return e==null||e===""?Z:q(e)}setUserKey(e){let t=r.suffixForUserId(e);if(t===this.currentSuffix){this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.notify(),this.hydrate();return}this.currentSuffix=t,this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.hydrate(),this.notify()}isEntitled(e){let t=Date.now()/1e3;return this.all.some(s=>s.key===e&&s.isActive&&(s.validUntil==null||s.validUntil>t))}list(){return this.all.slice()}get freshness(){return this.lastUpdated}get isStale(){return this.lastRefreshFailedAt>this.lastUpdated?!0:this.lastUpdated>0&&Date.now()-this.lastUpdated>this.staleAfterMs}get refreshFailedAt(){return this.lastRefreshFailedAt}get listenerErrors(){return this.listenerErrorCount}markRefreshFailed(){this.lastRefreshFailedAt=Date.now()}setFromList(e){this.all=e.slice(),this.lastUpdated=Date.now(),this.lastRefreshFailedAt=0,this.persist(),this.recordSuffixInIndex(this.currentSuffix),this.notify()}clear(){if(this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.storage)try{this.storage.removeItem(this.storageKey)}catch{}this.removeSuffixFromIndex(this.currentSuffix),this.notify()}clearAll(){if(this.all=[],this.lastUpdated=0,this.lastRefreshFailedAt=0,this.currentSuffix=Z,this.storage){let e=this.readIndex();for(let t of e)try{this.storage.removeItem(`${this.storageKeyPrefix}:${t}`)}catch{}try{this.storage.removeItem(`${this.storageKeyPrefix}:${Z}`)}catch{}try{this.storage.removeItem(this.indexKey)}catch{}}this.notify()}subscribe(e){this.listeners.add(e);let t=!1;return()=>{t||(t=!0,this.listeners.delete(e))}}hydrate(){if(this.storage)try{let e=this.storage.getItem(this.storageKey);if(!e)return;let t=JSON.parse(e);t&&t.v===1&&Array.isArray(t.entitlements)&&(this.all=t.entitlements,this.lastUpdated=typeof t.lastUpdated=="number"?t.lastUpdated:0)}catch{}}persist(){if(this.storage)try{let e={v:1,entitlements:this.all,lastUpdated:this.lastUpdated};this.storage.setItem(this.storageKey,JSON.stringify(e))}catch{}}readIndex(){if(!this.storage)return[];try{let e=this.storage.getItem(this.indexKey);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}catch{return[]}}recordSuffixInIndex(e){if(!this.storage)return;let t=this.readIndex();if(!t.includes(e)){t.push(e);try{this.storage.setItem(this.indexKey,JSON.stringify(t))}catch{}}}removeSuffixFromIndex(e){if(!this.storage)return;let t=this.readIndex(),s=t.filter(n=>n!==e);if(s.length!==t.length)try{s.length===0?this.storage.removeItem(this.indexKey):this.storage.setItem(this.indexKey,JSON.stringify(s))}catch{}}notify(){if(this.listeners.size===0)return;let e=this.all.slice(),t=[...this.listeners];for(let s of t)try{s(e)}catch{this.listenerErrorCount+=1}}};function Dt(r){return[r.slice(0,8),r.slice(8,12),r.slice(12,16),r.slice(16,20),r.slice(20,32)].join("-")}function L(r){let e;if(r.rail==="apple"?e=r.signedTransactionInfo??"":r.rail==="google"?e=r.purchaseToken??"":e="",!e)throw new Error(`deriveIdempotencyKeyForPurchase: no stable identifier in body (rail=${r.rail}). Apple needs signedTransactionInfo; Google needs purchaseToken.`);let t=`crossdeck:purchases/sync:${r.rail}:${e}`;return Dt(q(t))}function Vt(r,e,t={},s=Math.random){let n=t.baseMs??1e3,i=t.maxMs??6e4,a=t.factor??2,o=Math.min(r,30),l=Math.min(i,n*Math.pow(a,o))*s();if(e!==void 0){let u=Math.min(864e5,e);if(u>l)return u}return Math.max(0,Math.round(l))}var ee=class{constructor(e={}){this.options=e;this.attempts=0}get consecutiveFailures(){return this.attempts}get isWarning(){return this.attempts>=(this.options.failuresBeforeWarn??8)}nextDelay(e,t=Math.random){let s=Vt(this.attempts,e,this.options,t);return this.attempts+=1,s}recordSuccess(){this.attempts=0}};var N=1e3,te=class{constructor(e){this.cfg=e;this.buffer=[];this.pendingBatch=null;this.pendingBatchId=null;this.dropped=0;this.inFlight=0;this.lastFlushAt=0;this.lastError=null;this.cancelTimer=null;this.firstFlushFired=!1;this.nextRetryAt=null;this.parked=!1;this.parkWarned=!1;if(this.retry=new ee(e.retry??{}),this.persistent=e.persistentStore??null,this.persistent){let t=this.persistent.load();t.length>0&&(t.length>N?(this.dropped+=t.length-N,this.buffer=t.slice(t.length-N)):this.buffer=t,this.cfg.onBufferChange?.(this.buffer.length),this.scheduleIdleFlush())}}enqueue(e){if(this.buffer.push(e),this.buffer.length>N){let t=this.buffer.length-N;this.buffer.splice(0,t),this.dropped+=t,this.cfg.onDrop?.(t)}this.cfg.onBufferChange?.(this.buffer.length),this.persistAll(),this.buffer.length>=this.cfg.batchSize?this.flush():this.scheduleIdleFlush()}async flush(e={}){if(this.parked)return null;let t,s;if(this.pendingBatch!==null&&this.pendingBatchId!==null)t=this.pendingBatch,s=this.pendingBatchId;else{if(this.buffer.length===0)return null;t=this.buffer.splice(0),s=this.mintBatchId(),this.pendingBatch=t,this.pendingBatchId=s,this.inFlight+=t.length,this.cfg.onBufferChange?.(this.buffer.length),this.persistAll()}this.cancelTimerIfSet(),this.nextRetryAt=null;try{let n=this.cfg.envelope(),i=await this.cfg.http.request("POST","/events",{body:{envelopeVersion:1,appId:n.appId,environment:n.environment,sdk:n.sdk,events:t},keepalive:e.keepalive===!0,idempotencyKey:s});return this.lastFlushAt=Date.now(),this.lastError=null,this.inFlight-=t.length,this.pendingBatch=null,this.pendingBatchId=null,this.retry.recordSuccess(),this.persistAll(),this.firstFlushFired||(this.firstFlushFired=!0,this.cfg.onFirstFlushSuccess?.()),i}catch(n){let i=n instanceof Error?n.message:String(n);if(this.lastError=i,Lt(n)){if(this.parked=!0,this.buffer=[...t,...this.buffer],this.buffer.length>N){let l=this.buffer.length-N;this.buffer.splice(0,l),this.dropped+=l}this.pendingBatch=null,this.pendingBatchId=null,this.inFlight-=t.length,this.persistAll(),this.cfg.onBufferChange?.(this.buffer.length);let c=Nt(n);return this.parkWarned||(this.parkWarned=!0,console.warn(`[Crossdeck] SDK outdated \u2014 the server is no longer accepting this version's event format. Your events are PARKED on-device (held, not lost) and will deliver automatically once you update @cross-deck/web${c?` to >= ${c}`:""} and redeploy.`)),this.cfg.onParked?.({minVersion:c,surface:Ut(n)}),null}if(Ft(n)){let c=t.length;return this.pendingBatch=null,this.pendingBatchId=null,this.inFlight-=c,this.dropped+=c,this.persistAll(),this.cfg.onDrop?.(c),this.cfg.onPermanentFailure?.({status:n.status??0,droppedCount:c,lastError:i}),null}let a=Ot(n),o=this.retry.nextDelay(a);return this.scheduleRetry(o),this.cfg.onRetryScheduled?.({delayMs:o,consecutiveFailures:this.retry.consecutiveFailures,retryAfterMs:a,lastError:i}),null}}reset(){this.cancelTimerIfSet(),this.nextRetryAt=null,this.buffer=[],this.pendingBatch=null,this.pendingBatchId=null,this.dropped=0,this.inFlight=0,this.lastError=null,this.retry.recordSuccess(),this.persistent?.clear(),this.cfg.onBufferChange?.(0)}getStats(){return{buffered:this.buffer.length,dropped:this.dropped,inFlight:this.inFlight,lastFlushAt:this.lastFlushAt,lastError:this.lastError,consecutiveFailures:this.retry.consecutiveFailures,nextRetryAt:this.nextRetryAt}}get pendingIdempotencyKey(){return this.pendingBatchId}persistAll(){if(this.persistent){if(this.pendingBatch===null){this.persistent.save(this.buffer);return}this.persistent.save([...this.pendingBatch,...this.buffer])}}scheduleIdleFlush(){this.cancelTimerIfSet();let e=this.cfg.scheduler??Le;this.cancelTimer=e(()=>{this.flush()},this.cfg.intervalMs)}scheduleRetry(e){this.cancelTimerIfSet(),this.nextRetryAt=Date.now()+e;let t=this.cfg.scheduler??Le;this.cancelTimer=t(()=>{this.flush()},e)}cancelTimerIfSet(){this.cancelTimer&&(this.cancelTimer(),this.cancelTimer=null)}mintBatchId(){return`batch_${Date.now().toString(36)}${V(10)}`}};function Ot(r){if(r&&typeof r=="object"&&"retryAfterMs"in r){let e=r.retryAfterMs;return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}}function Ft(r){if(!r||typeof r!="object")return!1;let e=r.status;return!(typeof e!="number"||!Number.isFinite(e)||e<400||e>=500||e===408||e===429||e===426)}function Lt(r){return!r||typeof r!="object"?!1:r.status===426?!0:r.code==="sdk_version_unsupported"}function Nt(r){let e=r?.minVersion;return typeof e=="string"&&e.length>0?e:void 0}function Ut(r){let e=r?.surface;return typeof e=="string"&&e.length>0?e:void 0}function Le(r,e){let t=setTimeout(r,e);if(typeof t.unref=="function")try{t.unref()}catch{}return()=>clearTimeout(t)}var re=class{constructor(e){this.options=e;this.writeScheduled=!1;this.pendingSnapshot=null;this.key=`${e.prefix}queue.v1`}load(){let e;try{e=this.options.storage.getItem(this.key)}catch{return[]}if(!e)return[];try{let t=JSON.parse(e);return!t||t.version!==1||!Array.isArray(t.events)?[]:t.events}catch{return[]}}save(e){this.pendingSnapshot=e.slice(),!this.writeScheduled&&(this.writeScheduled=!0,queueMicrotask(()=>this.flushWrite()))}saveSync(e){this.pendingSnapshot=e.slice(),this.flushWrite()}clear(){this.pendingSnapshot=null,this.writeScheduled=!1;try{this.options.storage.removeItem(this.key)}catch{}}flushWrite(){this.writeScheduled=!1;let e=this.pendingSnapshot;if(this.pendingSnapshot=null,e===null)return;if(e.length===0){try{this.options.storage.removeItem(this.key)}catch{}return}let t={version:1,events:e};try{this.options.storage.setItem(this.key,JSON.stringify(t))}catch{}}};var O=class{constructor(){this.store=new Map}getItem(e){return this.store.get(e)??null}setItem(e,t){this.store.set(e,t)}removeItem(e){this.store.delete(e)}},se=class{constructor(e){this.maxAgeSec=e?.maxAgeSec??63072e3,this.secure=e?.secure??qt(),this.sameSite=e?.sameSite??"Lax"}getItem(e){if(!ge())return null;let t=globalThis.document,s=t.cookie?t.cookie.split(/;\s*/):[],n=encodeURIComponent(e)+"=";for(let i of s)if(i.startsWith(n))try{return decodeURIComponent(i.slice(n.length))}catch{return null}return null}setItem(e,t){if(!ge())return;let s=globalThis.document,n=[`${encodeURIComponent(e)}=${encodeURIComponent(t)}`,"Path=/",`Max-Age=${this.maxAgeSec}`,`SameSite=${this.sameSite}`];this.secure&&n.push("Secure");try{s.cookie=n.join("; ")}catch{}}removeItem(e){if(!ge())return;let t=globalThis.document,s=[`${encodeURIComponent(e)}=`,"Path=/","Max-Age=0",`SameSite=${this.sameSite}`];this.secure&&s.push("Secure");try{t.cookie=s.join("; ")}catch{}}};function Ne(){try{let r=globalThis.localStorage;if(r){let e="__crossdeck_probe__";return r.setItem(e,"1"),r.removeItem(e),r}}catch{}return new O}function qt(){try{return globalThis.location?.protocol==="https:"}catch{return!1}}function ge(){return typeof globalThis.document<"u"}var $t="__crossdeckBucketsBridge__";function ye(r){try{let e=globalThis[$t];typeof e=="function"&&e(r)}catch{}}function Mt(){return typeof globalThis.window<"u"&&typeof globalThis.document<"u"&&typeof globalThis.navigator<"u"}function Ue(r){let e={};if(r?.appVersion&&(e.appVersion=r.appVersion),!Mt())return e;let t=globalThis.window,s=globalThis.navigator,n=globalThis.document;try{typeof s.language=="string"&&(e.locale=s.language)}catch{}try{e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}try{t.screen&&(e.screenWidth=t.screen.width,e.screenHeight=t.screen.height),e.viewportWidth=t.innerWidth,e.viewportHeight=t.innerHeight,e.devicePixelRatio=t.devicePixelRatio}catch{}try{let i=s.userAgent??"",a=Kt(i);Object.assign(e,a)}catch{}try{let i=s.userAgentData;if(i?.platform&&!e.os&&(e.os=i.platform),i?.brands&&!e.browser){let a=i.brands.find(o=>!/Not[ .;A]*Brand/i.test(o.brand)&&!/Chromium/i.test(o.brand));a&&(e.browser=a.brand,e.browserVersion=a.version)}}catch{}return e}function Kt(r){let e={};if(/iPad|iPhone|iPod/.test(r)){e.os="iOS";let t=r.match(/OS (\d+[._]\d+(?:[._]\d+)?)/);t?.[1]&&(e.osVersion=t[1].replace(/_/g,"."))}else if(/Android/.test(r)){e.os="Android";let t=r.match(/Android (\d+(?:\.\d+)*)/);t?.[1]&&(e.osVersion=t[1])}else if(/Windows/.test(r)){e.os="Windows";let t=r.match(/Windows NT (\d+\.\d+)/);t?.[1]&&(e.osVersion=t[1])}else if(/Mac OS X|Macintosh/.test(r)){e.os="macOS";let t=r.match(/Mac OS X (\d+[._]\d+(?:[._]\d+)?)/);t?.[1]&&(e.osVersion=t[1].replace(/_/g,"."))}else/Linux/.test(r)&&(e.os="Linux");return/Edg\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Edge",e.browserVersion=r.match(/Edg\/(\d+(?:\.\d+)*)/)?.[1]):/Firefox\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Firefox",e.browserVersion=r.match(/Firefox\/(\d+(?:\.\d+)*)/)?.[1]):/OPR\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Opera",e.browserVersion=r.match(/OPR\/(\d+(?:\.\d+)*)/)?.[1]):/Chrome\/(\d+(?:\.\d+)*)/.test(r)?(e.browser="Chrome",e.browserVersion=r.match(/Chrome\/(\d+(?:\.\d+)*)/)?.[1]):/Version\/(\d+(?:\.\d+)*).*Safari/.test(r)&&(e.browser="Safari",e.browserVersion=r.match(/Version\/(\d+(?:\.\d+)*)/)?.[1]),e}var F={sessions:!0,pageViews:!0,deviceInfo:!0,clicks:!0,webVitals:!0,errors:!0},be=1800*1e3,Bt="crossdeck:session",jt=5e3,ne={utm_source:"",utm_medium:"",utm_campaign:"",utm_content:"",utm_term:"",referrer:"",gclid:"",fbclid:"",msclkid:"",ttclid:"",li_fat_id:"",twclid:""},j=class{constructor(e,t,s){this.cfg=e;this.track=t;this.session=null;this.cleanups=[];this.lastPersistAt=0;this._sessionSeq=0;this.pageviewId=null;this.storage=s?.storage??null,this.sessionKey=s?.storageKey??Bt}install(){$e()&&(this.cfg.sessions&&this.installSessionTracking(),this.cfg.pageViews&&this.installPageViewTracking(),this.cfg.clicks&&this.installClickTracking())}uninstall(){for(;this.cleanups.length;){let e=this.cleanups.pop();try{e?.()}catch{}}this.session&&!this.session.endedSent&&this.emitSessionEnd(),this.clearStoredSession(),this.session=null}resetSession(){this.session&&!this.session.endedSent&&this.emitSessionEnd(),this.pageviewId=null,this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart()}markActivity(){if(!this.session)return;let e=Date.now();if(e-this.session.lastActivityAt>=be){this.pageviewId=null,this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart();return}this.session.lastActivityAt=e,e-this.lastPersistAt>=jt&&this.persistSession()}get currentSessionId(){return this.session?.sessionId??null}get currentPageviewId(){return this.pageviewId}get currentAcquisition(){return this.session?.acquisition??ne}nextSeq(){let e=this._sessionSeq;return this._sessionSeq+=1,e}installSessionTracking(){let e=Date.now(),t=this.readStoredSession();t&&e-t.lastActivityAt<be?(this.session={sessionId:t.id,startedAt:t.startedAt,lastActivityAt:e,hiddenAt:null,endedSent:!1,acquisition:t.acquisition},this.persistSession()):(this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart());let s=()=>{try{if(!this.session)return;let o=globalThis.document;o.visibilityState==="hidden"?(this.session.hiddenAt=Date.now(),this.persistSession()):o.visibilityState==="visible"&&(Date.now()-this.session.lastActivityAt>=be?(this.pageviewId=null,this.session=this.startNewSession(),this.persistSession(),this.emitSessionStart()):this.session.hiddenAt=null)}catch{}},n=()=>{try{this.persistSession()}catch{}},i=globalThis.window,a=globalThis.document;a.addEventListener("visibilitychange",s),i.addEventListener("pagehide",n),i.addEventListener("beforeunload",n),this.cleanups.push(()=>{a.removeEventListener("visibilitychange",s),i.removeEventListener("pagehide",n),i.removeEventListener("beforeunload",n)})}startNewSession(){let e=Date.now();return this._sessionSeq=0,{sessionId:ir(),startedAt:e,lastActivityAt:e,hiddenAt:null,endedSent:!1,acquisition:or()}}readStoredSession(){if(!this.storage)return null;try{let e=this.storage.getItem(this.sessionKey);if(!e)return null;let t=JSON.parse(e);return!t||typeof t.id!="string"||typeof t.startedAt!="number"||typeof t.lastActivityAt!="number"?null:{id:t.id,startedAt:t.startedAt,lastActivityAt:t.lastActivityAt,acquisition:t.acquisition&&typeof t.acquisition=="object"?t.acquisition:ne}}catch{return null}}persistSession(){if(!(!this.storage||!this.session)){this.lastPersistAt=Date.now();try{let e={id:this.session.sessionId,startedAt:this.session.startedAt,lastActivityAt:this.session.lastActivityAt,acquisition:this.session.acquisition};this.storage.setItem(this.sessionKey,JSON.stringify(e))}catch{}}}clearStoredSession(){if(this.storage)try{this.storage.removeItem(this.sessionKey)}catch{}}emitSessionStart(){this.session&&this.track("session.started",{sessionId:this.session.sessionId})}emitSessionEnd(){if(!this.session||this.session.endedSent)return;let e=Date.now()-this.session.startedAt;this.track("session.ended",{sessionId:this.session.sessionId,durationMs:e}),this.session.endedSent=!0}installPageViewTracking(){let e=globalThis.window,t=globalThis.document,s=0,n="",i=250,a=(m=!1)=>{let p=e.location,y=p.href,k=Date.now();!m&&y===n&&k-s<i||(s=k,n=y,this.pageviewId=`pv_${Date.now().toString(36)}${V(10)}`,this.track("page.viewed",{pageviewId:this.pageviewId,path:p.pathname,url:y,search:p.search||void 0,hash:p.hash||void 0,title:t.title,referrer:t.referrer||void 0}))};a();let o=e.history.pushState,c=e.history.replaceState;function l(m,p,y){o.apply(this,[m,p,y]),queueMicrotask(a)}function d(m,p,y){c.apply(this,[m,p,y]),queueMicrotask(a)}e.history.pushState=l,e.history.replaceState=d;let u=()=>a(!0);e.addEventListener("popstate",u),this.cleanups.push(()=>{e.history.pushState===l&&(e.history.pushState=o),e.history.replaceState===d&&(e.history.replaceState=c),e.removeEventListener("popstate",u)})}installClickTracking(){let e=globalThis.window,t=globalThis.document,s=0,n=null,i=100,a=64,o=c=>{let l=c.target;if(!l||!(l instanceof Element))return;let d=Date.now();if(l===n&&d-s<i)return;s=d,n=l;let m=Wt(l)||l;if(Ht(m)||zt(m)||Gt(m))return;let p=m.tagName.toLowerCase(),y=rr(tr(m),a),k=m.href||void 0,g=m.target||void 0,v=m.id||void 0,S=m.getAttribute("role")||void 0,T=m.getAttribute("aria-label")||void 0,C=sr(m),f=nr(m),w=p==="a"&&!!k,E=m.getAttribute("data-cd-event"),I={selector:C,tag:p,text:y,elementId:v,role:S,ariaLabel:T,href:k,isLink:w,linkTarget:g,viewportX:c.clientX,viewportY:c.clientY,pageX:c.pageX,pageY:c.pageY,...f};for(let D of Object.keys(I))(I[D]===void 0||I[D]===null||I[D]==="")&&delete I[D];this.track(E||"element.clicked",I)};t.addEventListener("click",o,{capture:!0,passive:!0}),this.cleanups.push(()=>{t.removeEventListener("click",o,{capture:!0})})}};function Wt(r){return r.closest("[data-cd-event]")||r.closest("[data-cd-noTrack]")||r.closest("button, a, [role='button'], [role='link'], input[type='button'], input[type='submit']")||null}function Ht(r){if(!(r instanceof HTMLElement))return!1;let e=r.tagName.toLowerCase();if(e==="textarea"||e==="select")return!0;if(e==="input"){let t=(r.type||"").toLowerCase();return t!=="button"&&t!=="submit"&&t!=="image"&&t!=="reset"}return!1}function zt(r){return!!r.closest("[data-cd-noTrack], [data-cd-no-track], .cd-noTrack, .cd-no-track")}function Gt(r){return!!r.closest('input[type="password"]')}var Jt=new Set(["span","b","strong","em","i","small","mark","u","label","abbr","time","bdi","cite","code","kbd","q","sub","sup"]),Xt=new Set(["svg","style","script","noscript"]),Yt="a[href], button, input, select, textarea, [role='button'], [role='link'], h1, h2, h3, h4, h5, h6",Qt="h1, h2, h3, h4, h5, h6";function qe(r){return r.replace(/\s+/g," ").trim()}function ke(r){let e="",t=s=>{let n=s.childNodes;for(let i=0;i<n.length;i++){let a=n[i];if(a){if(a.nodeType===3)e+=a.textContent||"";else if(a.nodeType===1){if(Xt.has(a.tagName.toLowerCase()))continue;e+=" ",t(a),e+=" "}}}};return t(r),qe(e)}function Zt(r){let e="",t=r.childNodes;for(let s=0;s<t.length;s++){let n=t[s];n&&(n.nodeType===3?e+=" "+(n.textContent||""):n.nodeType===1&&Jt.has(n.tagName.toLowerCase())&&(e+=" "+ke(n)))}return qe(e)}function er(r){if(!(r.querySelector(Yt)!==null))return ke(r);let t=Zt(r);if(t)return t;let s=r.querySelector(Qt);if(s){let n=ke(s);if(n)return n}return""}function tr(r){let e=l=>l.replace(/\s+/g," ").trim(),t=r.getAttribute("data-cd-track")||r.getAttribute("data-track")||r.getAttribute("data-testid");if(t){let l=e(t);if(l)return l}let s=r.getAttribute("aria-label");if(s){let l=e(s);if(l)return l}let n=r.getAttribute("aria-labelledby");if(n&&typeof r.ownerDocument?.getElementById=="function"){let l=[];for(let d of n.split(/\s+/)){let u=r.ownerDocument.getElementById(d),m=u?.textContent?e(u.textContent):"";m&&l.push(m)}if(l.length>0)return l.join(" ")}if(r instanceof HTMLInputElement&&r.value){let l=e(r.value);if(l)return l}let i=er(r);if(i)return i;let a=r.getAttribute("title");if(a){let l=e(a);if(l)return l}let o=r.querySelector("img[alt]");if(o){let l=o.getAttribute("alt")??"",d=e(l);if(d)return d}let c=r.querySelector("svg title");if(c?.textContent){let l=e(c.textContent);if(l)return l}return""}function rr(r,e){return r.length<=e?r:r.slice(0,e-1)+"\u2026"}function sr(r){let e=[],t=r,s=0;for(;t&&t.nodeName.toLowerCase()!=="body"&&s<5;){let n=t.nodeName.toLowerCase();if(t.id){e.unshift(`${n}#${t.id}`);break}if(t.classList.length>0){let i=Array.from(t.classList).filter(a=>!a.startsWith("cd-")).slice(0,2).join(".");i&&(n+=`.${i}`)}e.unshift(n),t=t.parentElement,s++}return e.join(" > ")}function nr(r){let e={};if(!(r instanceof HTMLElement))return e;for(let t of r.getAttributeNames()){if(!t.startsWith("data-")||t==="data-cd-noTrack"||t==="data-cd-no-track"||t==="data-cd-event")continue;let s=r.getAttribute(t)||"",n=t.replace(/^data-cd-prop-/,"").replace(/^data-/,"");e[n]=s}return e}function $e(){return typeof globalThis.window<"u"&&typeof globalThis.document<"u"}function ir(){return`sess_${Date.now().toString(36)}${V(10)}`}function or(){if(!$e())return{...ne};let r={...ne};try{let e=globalThis.window,t=new URLSearchParams(e.location.search??"");r.utm_source=t.get("utm_source")??"",r.utm_medium=t.get("utm_medium")??"",r.utm_campaign=t.get("utm_campaign")??"",r.utm_content=t.get("utm_content")??"",r.utm_term=t.get("utm_term")??"",r.gclid=t.get("gclid")??"",r.fbclid=t.get("fbclid")??"",r.msclkid=t.get("msclkid")??"",r.ttclid=t.get("ttclid")??"",r.li_fat_id=t.get("li_fat_id")??"",r.twclid=t.get("twclid")??""}catch{}try{let e=globalThis.document;typeof e.referrer=="string"&&(r.referrer=e.referrer)}catch{}return r}var ar=[/^email$/i,/^password$/i,/^token$/i,/^secret$/i,/^card$/i,/^phone$/i,/password/i,/credit_?card/i];function Me(r){if(!r)return[];let e=[];for(let t of Object.keys(r))ar.some(s=>s.test(t))&&e.push(t);return e}var ie=class{constructor(){this.enabled=!1;this.seen=new Set}emit(e,t,s){if(!this.enabled)return;if(cr.has(e)){if(this.seen.has(e))return;this.seen.add(e)}let n=s?` ${dr(s)}`:"";console.info(`[crossdeck:${e}] ${t}${n}`)}},cr=new Set(["sdk.configured","sdk.first_event_sent","sdk.environment_mismatch"]);function dr(r){try{return JSON.stringify(r)}catch{return"[unserialisable context]"}}function W(r,e={}){let t=[];if(!r)return{properties:{},warnings:t};let s=e.maxStringLength??1024,n=e.maxBatchPropertyBytes??8192,i=e.maxDepth??5,a=new Set,o=(d,u,m)=>{if(m>i)return t.push({kind:"depth_exceeded",key:u}),{keep:!0,value:"[depth-exceeded]"};if(d===null)return{keep:!0,value:null};let p=typeof d;if(p==="string"){let y=d;return y.length>s?(t.push({kind:"truncated_string",key:u}),{keep:!0,value:y.slice(0,s-1)+"\u2026"}):{keep:!0,value:y}}if(p==="number")return Number.isFinite(d)?{keep:!0,value:d}:(t.push({kind:"non_serialisable",key:u}),{keep:!0,value:null});if(p==="boolean")return{keep:!0,value:d};if(p==="bigint")return t.push({kind:"coerced_bigint",key:u}),{keep:!0,value:d.toString()};if(p==="function")return t.push({kind:"dropped_function",key:u}),{keep:!1,value:void 0};if(p==="symbol")return t.push({kind:"dropped_symbol",key:u}),{keep:!1,value:void 0};if(p==="undefined")return t.push({kind:"dropped_undefined",key:u}),{keep:!1,value:void 0};if(d instanceof Date)return t.push({kind:"coerced_date",key:u}),{keep:!0,value:Number.isFinite(d.getTime())?d.toISOString():null};if(d instanceof Error)return t.push({kind:"coerced_error",key:u}),{keep:!0,value:{name:d.name,message:d.message,stack:typeof d.stack=="string"?d.stack.slice(0,s):void 0}};if(d instanceof Map){t.push({kind:"coerced_map",key:u});let y={};for(let[k,g]of d.entries()){let v=typeof k=="string"?k:String(k),S=o(g,`${u}.${v}`,m+1);S.keep&&(y[v]=S.value)}return{keep:!0,value:y}}if(d instanceof Set){t.push({kind:"coerced_set",key:u});let y=[],k=0;for(let g of d.values()){let v=o(g,`${u}[${k}]`,m+1);v.keep&&y.push(v.value),k++}return{keep:!0,value:y}}if(Array.isArray(d)){if(a.has(d))return t.push({kind:"circular_reference",key:u}),{keep:!0,value:"[circular]"};a.add(d);let y=[];for(let k=0;k<d.length;k++){let g=o(d[k],`${u}[${k}]`,m+1);g.keep&&y.push(g.value)}return a.delete(d),{keep:!0,value:y}}if(p==="object"){let y=d;if(a.has(y))return t.push({kind:"circular_reference",key:u}),{keep:!0,value:"[circular]"};a.add(y);let k={};for(let g of Object.keys(y)){let v=o(y[g],`${u}.${g}`,m+1);v.keep&&(k[g]=v.value)}return a.delete(y),{keep:!0,value:k}}t.push({kind:"non_serialisable",key:u});try{return{keep:!0,value:String(d)}}catch{return{keep:!1,value:void 0}}},c={};for(let d of Object.keys(r)){let u=o(r[d],d,0);u.keep&&(c[d]=u.value)}let l=Ke(c);if(l&&ve(l)>n){t.push({kind:"size_cap_exceeded",key:"*"});let d=Object.keys(c).map(m=>({k:m,size:ve(Ke(c[m])??"")})).sort((m,p)=>p.size-m.size),u=ve(l);for(let{k:m}of d){if(u<=n)break;u-=d.find(p=>p.k===m).size,delete c[m]}c.__truncated=!0}return{properties:c,warnings:t}}function Ke(r){try{return JSON.stringify(r)??null}catch{return null}}function ve(r){return typeof TextEncoder<"u"?new TextEncoder().encode(r).length:r.length*4}var oe="super_props",we="groups",ae=class{constructor(e,t){this.storage=e;this.prefix=t;this.superProps={};this.groups={};this.superProps=Be(e,t+oe)??{},this.groups=Be(e,t+we)??{}}register(e){for(let[t,s]of Object.entries(e))s===null?delete this.superProps[t]:s!==void 0&&(this.superProps[t]=s);return _e(this.storage,this.prefix+oe,this.superProps),{...this.superProps}}unregister(e){e in this.superProps&&(delete this.superProps[e],_e(this.storage,this.prefix+oe,this.superProps))}getSuperProperties(){return{...this.superProps}}setGroup(e,t,s){t===null?delete this.groups[e]:this.groups[e]=s!==void 0?{id:t,traits:s}:{id:t},_e(this.storage,this.prefix+we,this.groups)}getGroups(){return JSON.parse(JSON.stringify(this.groups))}getGroupIds(){let e={};for(let[t,s]of Object.entries(this.groups))e[t]=s.id;return e}clear(){this.superProps={},this.groups={};try{this.storage.removeItem(this.prefix+oe)}catch{}try{this.storage.removeItem(this.prefix+we)}catch{}}};function Be(r,e){let t;try{t=r.getItem(e)}catch{return null}if(!t)return null;try{return JSON.parse(t)}catch{return null}}function _e(r,e,t){try{r.setItem(e,JSON.stringify(t))}catch{}}var je="$crossdeck_internal",Se="crossdeck.internalOptOut";function We(){try{return typeof localStorage<"u"?localStorage:null}catch{return null}}function He(){try{let r=typeof location<"u"?location.search:"",e=new URLSearchParams(r||"");if(!e.has("crossdeck_internal"))return;let t=We();if(!t)return;let s=e.get("crossdeck_internal");s==="1"||s==="true"?t.setItem(Se,"1"):(s==="0"||s==="false")&&t.removeItem(Se)}catch{}}function ze(){try{return We()?.getItem(Se)==="1"}catch{return!1}}var ce=class{constructor(e,t){this.cfg=e;this.report=t;this.observers=[];this.flushed=new Set;this.cls=0;this.clsEntries=[];this.inp=0;this.cleanups=[]}install(){if(!this.cfg.enabled||typeof PerformanceObserver>"u"||typeof globalThis>"u"||!("document"in globalThis))return;let e=globalThis.document;try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries()){let c=o;c.responseStart>0&&!this.flushed.has("ttfb")&&(this.flushed.add("ttfb"),this.report("webvitals.ttfb",{valueMs:Math.round(c.responseStart-c.startTime)}))}});i.observe({type:"navigation",buffered:!0}),this.observers.push(i)}catch{}try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries())o.name==="first-contentful-paint"&&!this.flushed.has("fcp")&&(this.flushed.add("fcp"),this.report("webvitals.fcp",{valueMs:Math.round(o.startTime)}))});i.observe({type:"paint",buffered:!0}),this.observers.push(i)}catch{}let t=0;try{let i=new PerformanceObserver(a=>{let o=a.getEntries(),c=o[o.length-1];c&&(t=c.startTime)});i.observe({type:"largest-contentful-paint",buffered:!0}),this.observers.push(i)}catch{}try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries()){let c=o;typeof c.value=="number"&&!c.hadRecentInput&&(this.cls+=c.value,this.clsEntries.push(o))}});i.observe({type:"layout-shift",buffered:!0}),this.observers.push(i)}catch{}try{let i=new PerformanceObserver(a=>{for(let o of a.getEntries()){let c=o;c.interactionId&&c.duration>this.inp&&(this.inp=c.duration)}});try{i.observe({type:"event",buffered:!0,durationThreshold:16})}catch{i.observe({type:"first-input",buffered:!0})}this.observers.push(i)}catch{}let s=()=>{try{t>0&&!this.flushed.has("lcp")&&(this.flushed.add("lcp"),this.report("webvitals.lcp",{valueMs:Math.round(t)})),this.cls>0&&!this.flushed.has("cls")&&(this.flushed.add("cls"),this.report("webvitals.cls",{value:Math.round(this.cls*1e3)/1e3})),this.inp>0&&!this.flushed.has("inp")&&(this.flushed.add("inp"),this.report("webvitals.inp",{valueMs:Math.round(this.inp)}))}catch{}},n=()=>{e.visibilityState==="hidden"&&s()};e.addEventListener("visibilitychange",n),globalThis.window.addEventListener("pagehide",s),this.cleanups.push(()=>{e.removeEventListener("visibilitychange",n),globalThis.window.removeEventListener("pagehide",s)})}uninstall(){for(let e of this.observers)try{e.disconnect()}catch{}this.observers=[];for(let e of this.cleanups.splice(0))try{e()}catch{}}};var lr={analytics:!0,marketing:!0,errors:!0},de=class{constructor(e){this.state={...lr};this.dntDenied=!1;e?.respectDnt&&this.detectDnt()&&(this.dntDenied=!0,this.state={analytics:!1,marketing:!1,errors:!1})}set(e){if(this.dntDenied)return{...this.state};for(let t of Object.keys(e)){let s=e[t];typeof s=="boolean"&&(this.state[t]=s)}return{...this.state}}get(){return{...this.state}}get analytics(){return this.state.analytics}get marketing(){return this.state.marketing}get errors(){return this.state.errors}get isDntDenied(){return this.dntDenied}detectDnt(){try{let e=globalThis.navigator;return e?[e.doNotTrack,e.msDoNotTrack,globalThis.doNotTrack].some(s=>s==="1"||s==="yes"):!1}catch{return!1}}},ur=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,fr=/\b\d(?:[ -]?\d){12,18}\b/g,pr="<email>",hr="<card>";function mr(r){return r&&r.replace(ur,pr).replace(fr,hr)}function Ee(r){let e={};for(let t of Object.keys(r))e[t]=Ge(r[t]);return e}function Ge(r){return typeof r=="string"?mr(r):Array.isArray(r)?r.map(Ge):r&&typeof r=="object"&&r.constructor===Object?Ee(r):r}var le=class{constructor(e=50){this.maxSize=e;this.items=[]}add(e){this.items.push(e),this.items.length>this.maxSize&&this.items.shift()}snapshot(){return this.items.slice()}clear(){this.items=[]}get size(){return this.items.length}};var gr="https://api.cross-deck.com/v1/events",Je="cd_pub_live_9490e7aa029c432abf";function yr(){return!Je.startsWith("cd_pub_RELIABILITY_PLACEHOLDER")}var br=new Set(["contract_id","sdk_version","sdk_platform","failure_reason","run_context","run_id","test_file","test_name","device_class","verification_phase"]);function kr(r){let e={};for(let[t,s]of Object.entries(r))br.has(t)&&typeof s=="string"&&(e[t]=s);return e}function ue(r){if(!yr())return;let e=kr(r);if(Object.keys(e).length===0)return;let t=JSON.stringify({events:[{name:"crossdeck.contract_failed",timestamp:Date.now(),properties:e}]}),s=globalThis.fetch;if(typeof s=="function")try{s(gr,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${Je}`,"Crossdeck-Sdk-Version":`${A}@${R}`},body:t,keepalive:!0,credentials:"omit",cache:"no-store",referrerPolicy:"no-referrer"}).catch(()=>{})}catch{}}var xe=Object.freeze([{code:"invalid_public_key",type:"configuration_error",description:"The publishable key passed to Crossdeck.init() doesn't start with cd_pub_.",resolution:"Copy the key from your Crossdeck dashboard \u2192 API keys page.",retryable:!1},{code:"missing_app_id",type:"configuration_error",description:"Crossdeck.init() was called without an appId.",resolution:"Add appId to your init options \u2014 find it in the dashboard's Apps page.",retryable:!1},{code:"invalid_environment",type:"configuration_error",description:"Crossdeck.init() requires environment: 'production' | 'sandbox'.",resolution:'Pass the literal string "production" or "sandbox" \u2014 no other values are accepted.',retryable:!1},{code:"environment_mismatch",type:"configuration_error",description:"The publishable key's env prefix doesn't match the declared environment option.",resolution:"Either change `environment` to match the key prefix (cd_pub_test_ \u2194 sandbox, cd_pub_live_ \u2194 production), or swap the key for one minted in the right env.",retryable:!1},{code:"not_initialized",type:"configuration_error",description:"An SDK method was called before Crossdeck.init().",resolution:"Call Crossdeck.init({ appId, publicKey, environment }) once at app startup before any other method.",retryable:!1},{code:"missing_user_id",type:"invalid_request_error",description:"identify() was called with an empty userId.",resolution:"Pass a stable, non-empty user identifier from your auth layer \u2014 never a hardcoded placeholder.",retryable:!1},{code:"missing_event_name",type:"invalid_request_error",description:"track() was called without an event name.",resolution:"Pass a non-empty string as the first argument.",retryable:!1},{code:"missing_group_type",type:"invalid_request_error",description:"group() was called without a group type.",resolution:'Pass a non-empty type (e.g. "org", "team") as the first argument.',retryable:!1},{code:"missing_signed_transaction_info",type:"invalid_request_error",description:"syncPurchases() was called without StoreKit 2 signed transaction info.",resolution:"Pass the JWS string from Transaction.currentEntitlements / Transaction.updates.",retryable:!1},{code:"fetch_failed",type:"network_error",description:"The underlying fetch() call failed (typically a network outage or DNS issue).",resolution:"Check the user's network. The SDK will retry automatically with exponential backoff.",retryable:!0},{code:"request_timeout",type:"network_error",description:"A request was aborted after the configured timeoutMs (default 15s).",resolution:"Check the user's connection. Increase timeoutMs in init options if the user is on a known-slow network.",retryable:!0},{code:"invalid_json_response",type:"internal_error",description:"The server returned a 2xx with an unparseable body.",resolution:"Likely a transient backend bug. Retry; if it persists, contact support with the requestId.",retryable:!0},{code:"missing_api_key",type:"authentication_error",description:"No Authorization header (or Crossdeck-Api-Key header) on the request.",resolution:"Make sure Crossdeck.init({ publicKey }) was called with a cd_pub_\u2026 key before the request fired. Re-check your env-vars in CI / Docker if the key is empty at runtime.",retryable:!1},{code:"invalid_api_key",type:"authentication_error",description:"The API key is malformed, unknown, or doesn't resolve to a project.",resolution:"Copy the key from your Crossdeck dashboard \u2192 API keys. Confirm prefix is cd_pub_test_ / cd_pub_live_ for client SDKs and cd_sk_test_ / cd_sk_live_ for the Node server SDK.",retryable:!1},{code:"key_revoked",type:"authentication_error",description:"The API key was revoked in the Crossdeck dashboard.",resolution:"Mint a fresh key in the dashboard \u2192 API keys \u2192 Create new, swap it in, and redeploy. The revoked key cannot be reactivated.",retryable:!1},{code:"identity_token_invalid",type:"authentication_error",description:"The Firebase / Apple / Google ID token supplied with the request didn't verify against the dashboard's configured signers.",resolution:"Refresh the token client-side (Firebase auth.currentUser.getIdToken(true)) and retry. If the failure persists, confirm the signer is registered under dashboard \u2192 Authentication \u2192 Identity sources.",retryable:!0},{code:"origin_not_allowed",type:"permission_error",description:"The Origin header isn't in the project's Allowed origins list.",resolution:"Add the origin (e.g. https://app.example.com) under dashboard \u2192 Settings \u2192 Allowed origins. Wildcards like https://*.example.com are supported.",retryable:!1},{code:"bundle_id_not_allowed",type:"permission_error",description:"The iOS bundle ID sent via X-Crossdeck-Bundle-Id isn't registered under this app's Apple identity lock.",resolution:"Add the bundle ID under dashboard \u2192 Apps \u2192 <your app> \u2192 iOS bundle IDs.",retryable:!1},{code:"package_name_not_allowed",type:"permission_error",description:"The Android package name sent via X-Crossdeck-Package-Name isn't registered under this app's Android identity lock.",resolution:"Add the package name under dashboard \u2192 Apps \u2192 <your app> \u2192 Android package names.",retryable:!1},{code:"env_mismatch",type:"permission_error",description:"The request env (inferred from key prefix) doesn't match the resolved app's configured env.",resolution:"Use a cd_pub_live_ / cd_sk_live_ key with a production app, cd_pub_test_ / cd_sk_test_ with a sandbox app. The two cannot cross.",retryable:!1},{code:"idempotency_key_in_use",type:"invalid_request_error",description:"An Idempotency-Key was reused for a request with a different body (Stripe-grade contract).",resolution:"Generate a fresh key for a different transaction, or reuse the key only with the EXACT same body. The v1.4.0 SDKs derive keys deterministically from the body so this should never fire on SDK-managed calls.",retryable:!1},{code:"rate_limited",type:"rate_limit_error",description:"Request rate exceeded the project's per-second cap.",resolution:"Honour the Retry-After header \u2014 the SDK does this automatically on managed retries. If you're hitting it from a custom code path, throttle to <100 req/s/key.",retryable:!0},{code:"internal_error",type:"internal_error",description:"Server-side issue. Safe to retry with backoff.",resolution:"The SDK retries automatically. If your code paths through to this error, contact support with the requestId from the response envelope.",retryable:!0},{code:"google_not_supported",type:"invalid_request_error",description:"POST /purchases/sync with rail=google is gated until the Play Developer API reconciliation worker ships.",resolution:"Until v1.5+, Google Play purchases verify via Real-time Developer Notifications. The SDK auto-track path handles this transparently for Android consumers.",retryable:!1},{code:"stripe_not_supported",type:"invalid_request_error",description:"POST /purchases/sync with rail=stripe is unsupported \u2014 Stripe Checkout's redirect flow uses platform webhooks instead.",resolution:"Wire Stripe via the standard Checkout / Customer Portal flow; Crossdeck reconciles via the platform webhook automatically. No SDK call needed.",retryable:!1},{code:"missing_required_param",type:"invalid_request_error",description:"A required field is absent from the request body.",resolution:"Inspect the error.message \u2014 the missing field name is included verbatim. Refer to the SDK's TypeScript types for the canonical request shape.",retryable:!1},{code:"invalid_param_value",type:"invalid_request_error",description:"A field is present but the value failed validation (wrong shape, wrong length, wrong enum value).",resolution:"Read error.message for the specific field + reason. SDK-managed call sites should never emit this \u2014 file a bug if you do.",retryable:!1},{code:"sdk_version_unsupported",type:"version_error",description:"HTTP 426 \u2014 your installed SDK sends an event format the server no longer accepts. The data is good; only the wire dialect is too old. The SDK PARKS automatically: events are held on-device (paused, not lost) and deliver on the next launch after you upgrade.",resolution:"Update @cross-deck/web to at least the version in error.minVersion and redeploy \u2014 the parked queue backfills automatically. See https://cross-deck.com/docs/sdk-event-durability/.",retryable:!1}]);function fe(r){return xe.find(e=>e.code===r)}function et(r){return{sdkVersion:`${A}@${R}`,runId:`cd_verify_${Ar(8)}`,runContext:r.runContext??"customer-app",logVerifierResults:r.logVerifierResults,disableContractAssertions:r.disableContractAssertions,console,emitTelemetry:ue}}var z=class{constructor(e){this.ctx=e;this.reentrancyDepth=0}report(e,t,s){this.ctx.disableContractAssertions||(e.ok?this.reportPass(e,t,s):this.reportFail(e,t,s))}reportPass(e,t,s){if(!this.ctx.logVerifierResults)return;let n=vr(e,s);t==="boot"?this.ctx.console.info(n):this.ctx.console.debug(n)}reportFail(e,t,s){if(this.ctx.console.warn(wr(e,s)),!(this.reentrancyDepth>0)){this.reentrancyDepth+=1;try{this.ctx.emitTelemetry({contract_id:e.contractId,sdk_version:this.ctx.sdkVersion,sdk_platform:"web",failure_reason:Rr(e.failureReason,128),run_context:this.ctx.runContext,run_id:this.ctx.runId,verification_phase:t})}finally{this.reentrancyDepth-=1}}}};function vr(r,e){return`${e?`[crossdeck.${e}]`:"[crossdeck]"} \u2713 ${r.contractId} \u2014 ${r.evidence} (${r.durationMs}ms)`}function wr(r,e){return`${e?`[crossdeck.${e}]`:"[crossdeck]"} \u2717 ${r.contractId} \u2014 ${r.failureReason} (${r.durationMs}ms)`}var _r={contractId:"per-user-cache-isolation",bootTest(){let r=h();try{let e=new pe,t=new P(e,"_verifier");if(t.setUserKey("user_A"),t.setFromList([{object:"entitlement",key:"pro",isActive:!0,validUntil:null,source:{rail:"stripe",productId:"p_verifier",subscriptionId:"s_verifier"},updatedAt:Date.now()}]),t.setUserKey("user_B"),t.list().length!==0)return b("per-user-cache-isolation","in-memory snapshot still carried user_A's entitlements after rotation",h()-r);let n=P.suffixForUserId("user_A"),i=P.suffixForUserId("user_B");if(n===i)return b("per-user-cache-isolation","suffixes for user_A and user_B collided",h()-r);let a=e.getItem(`_verifier:${n}`),o=e.getItem(`_verifier:${i}`);return a?o?b("per-user-cache-isolation","user_B's storage slot already contained data before any write",h()-r):x("per-user-cache-isolation",`slot rotated A:${H(n)} \u2192 B:${H(i)} (isolated, physically separate)`,h()-r):b("per-user-cache-isolation","user_A's storage slot was wiped on rotation (expected isolation, not erasure)",h()-r)}catch(e){return b("per-user-cache-isolation",`boot test threw: ${e.message?.slice(0,80)??"unknown error"}`,h()-r)}},hooks:{onIdentify(r){let e=h(),t=P.suffixForUserId(r.priorUserId),s=P.suffixForUserId(r.nextUserId);return t!==s?r.cache.list().length!==0?b("per-user-cache-isolation","in-memory snapshot still held entitlements after slot rotation",h()-e):x("per-user-cache-isolation",`slot rotated ${H(t)} \u2192 ${H(s)}`,h()-e):x("per-user-cache-isolation",`same-id re-identify (suffix ${H(s)}); cleared + rehydrated per contract`,h()-e)}}},Ce="eyJ.jws.sig",Xe="a66b1640-efaf-bb4d-1261-6650033bf111",Sr={contractId:"idempotency-key-deterministic",bootTest(){let r=h();try{let e=L({rail:"apple",signedTransactionInfo:Ce});if(e!==Xe)return b("idempotency-key-deterministic",`canonical apple JWS derived ${e} (expected ${Xe})`,h()-r);if(L({rail:"apple",signedTransactionInfo:Ce})!==e)return b("idempotency-key-deterministic","same JWS produced different keys on two derivations",h()-r);let s=e,n=L({rail:"google",purchaseToken:Ce});return s===n?b("idempotency-key-deterministic","rail namespacing failed \u2014 apple/google identical key",h()-r):x("idempotency-key-deterministic",`apple JWS \u2192 ${e} (canonical vector + determinism + rail isolation)`,h()-r)}catch(e){return b("idempotency-key-deterministic",`boot test threw: ${e.message?.slice(0,80)??"unknown error"}`,h()-r)}},hooks:{onSyncPurchases(r){let e=h();try{return L(r.rail==="apple"?{rail:"apple",signedTransactionInfo:r.stableIdentifier}:{rail:r.rail,purchaseToken:r.stableIdentifier})!==r.derivedKey?b("idempotency-key-deterministic","derived key drifted from canonical algorithm",h()-e):x("idempotency-key-deterministic",`${r.rail} \u2192 ${r.derivedKey}`,h()-e)}catch(t){return b("idempotency-key-deterministic",`hot-path derivation threw: ${t.message?.slice(0,80)??"unknown error"}`,h()-e)}}}},Er={contractId:"error-envelope-shape",bootTest(){let r=h(),e={error:{type:"invalid_request_error",code:"missing_customer",message:"Customer identifier is required.",request_id:"req_test1234"}},t=new Set(["authentication_error","permission_error","invalid_request_error","rate_limit_error","internal_error"]),s=e.error,n=["type","code","message","request_id"].filter(i=>!(i in s)||typeof s[i]!="string");return n.length>0?b("error-envelope-shape",`envelope missing required fields: ${n.join(", ")}`,h()-r):t.has(s.type)?x("error-envelope-shape","{ type, code, message, request_id } parsed and type \u2208 ApiErrorType",h()-r):b("error-envelope-shape",`error.type "${s.type}" not in canonical ApiErrorType set`,h()-r)},hooks:{onErrorParse(r){let e=h();return new Set(["authentication_error","permission_error","invalid_request_error","rate_limit_error","internal_error"]).has(r.errorType)?!r.errorCode||r.errorCode.length===0?b("error-envelope-shape","wire error.code was empty",h()-e):x("error-envelope-shape",`${r.errorType}/${r.errorCode} on ${r.httpStatus}${r.requestId?` (${r.requestId.slice(0,12)}\u2026)`:""}`,h()-e):b("error-envelope-shape",`wire error.type "${r.errorType}" outside canonical ApiErrorType`,h()-e)}}},xr={contractId:"flush-interval-parity",bootTest(){let r=h();return 2e3!==2e3?b("flush-interval-parity","canonical default drifted from 2000ms",h()-r):x("flush-interval-parity","eventFlushIntervalMs default = 2000ms (Web/Node/RN/Swift/Android parity)",h()-r)}};function tt(r){return{contractId:"flush-interval-parity",bootTest(){let e=h(),t=2e3;return r<100||r>6e4?b("flush-interval-parity",`configured eventFlushIntervalMs=${r} outside reasonable bounds [100, 60000]`,h()-e):r!==t?x("flush-interval-parity",`eventFlushIntervalMs = ${r}ms (override; canonical default is 2000ms)`,h()-e):x("flush-interval-parity","eventFlushIntervalMs = 2000ms (canonical default)",h()-e)}}}var Cr={contractId:"super-property-merge-precedence",bootTest(){let r=h(),n={...{plan:"device_plan",os:"macos"},...{plan:"super_plan",appVersion:"1.0.0"},...{plan:"caller_plan",eventSpecific:!0}};return n.plan!=="caller_plan"?b("super-property-merge-precedence",`merged.plan = "${n.plan}" (expected "caller_plan"; caller must override super and device)`,h()-r):n.appVersion!=="1.0.0"?b("super-property-merge-precedence","super-property appVersion was clobbered by device or caller",h()-r):n.os!=="macos"?b("super-property-merge-precedence","device property os was dropped from merged result",h()-r):x("super-property-merge-precedence","caller > super > device verified (synthetic merge)",h()-r)},hooks:{onTrack(r){let e=h();for(let[t,s]of Object.entries(r.callerProperties))if(r.mergedProperties[t]!==s)return b("super-property-merge-precedence",`caller key "${t}" did not win in merged output`,h()-e);for(let[t,s]of Object.entries(r.superProperties))if(!(t in r.callerProperties)&&r.mergedProperties[t]!==s)return b("super-property-merge-precedence",`super key "${t}" did not win over device in merged output`,h()-e);return x("super-property-merge-precedence",`caller(${Object.keys(r.callerProperties).length}) > super(${Object.keys(r.superProperties).length}) > device verified`,h()-e)}}},Te=["contract_id","sdk_version","sdk_platform","failure_reason","run_context","run_id"],Ye=["test_file","test_name","device_class","verification_phase"],Qe=["anonymousId","developerUserId","crossdeckCustomerId","email","userId","ip","ipAddress","userAgent","stack","stackTrace","url","referrer","deviceId"],Tr={contractId:"contract-failed-payload-schema-lock",bootTest(){let r=h(),t=Object.keys({contract_id:"synthetic",sdk_version:R,sdk_platform:"web",failure_reason:"synthetic",run_context:"customer-app",run_id:"synthetic-run-id",verification_phase:"boot"}),s=new Set([...Te,...Ye]),n=new Set(Qe);for(let i of Te)if(!t.includes(i))return b("contract-failed-payload-schema-lock",`missing required field: ${i}`,h()-r);for(let i of t)if(n.has(i))return b("contract-failed-payload-schema-lock",`forbidden field on wire: ${i}`,h()-r);for(let i of t)if(!s.has(i))return b("contract-failed-payload-schema-lock",`unrecognised field on wire: ${i} (not in required \u222A optional)`,h()-r);return x("contract-failed-payload-schema-lock",`${t.length} fields \u2286 required(${Te.length}) \u222A optional(${Ye.length}); ${Qe.length} forbidden absent`,h()-r)}},Ze=Object.freeze(["missing_api_key","invalid_api_key","key_revoked","identity_token_invalid","origin_not_allowed","bundle_id_not_allowed","package_name_not_allowed","env_mismatch","idempotency_key_in_use","rate_limited","internal_error","google_not_supported","stripe_not_supported","missing_required_param","invalid_param_value","sdk_version_unsupported"]),Ir={contractId:"sdk-error-codes-catalogue",bootTest(){let r=h();try{let e=[];for(let t of Ze){let s=fe(t);(!s||!s.description||s.description.trim().length===0||!s.resolution||s.resolution.trim().length===0)&&e.push(t)}return e.length>0?b("sdk-error-codes-catalogue",`catalogue missing description+resolution for backend code(s): ${e.join(", ")}`,h()-r):x("sdk-error-codes-catalogue",`all ${Ze.length} backend wire codes carry description + resolution`,h()-r)}catch(e){return b("sdk-error-codes-catalogue",`boot test threw: ${e.message?.slice(0,80)??"unknown error"}`,h()-r)}}},rt=Object.freeze([_r,Sr,Er,xr,Cr,Tr,Ir]);async function Ie(r,e,t){if(t.disableContractAssertions)return{passed:0,failed:0,totalMs:0};let s=h(),n=0,i=0;if(t.logVerifierResults){let o=r.filter(d=>d.bootTest).length,c=r.filter(d=>d.hooks).length,l=r.map(d=>d.contractId).join(", ");t.console.info(`[crossdeck] Contract self-verification \u2014 ${r.length} verifiers (${o} boot-tests, ${c} hot-path hooks): ${l}`)}for(let o of r){if(!o.bootTest)continue;let c;try{c=await o.bootTest()}catch(l){c=b(o.contractId,`bootTest threw: ${l.message?.slice(0,80)??"unknown"}`,0)}e.report(c,"boot"),c.ok?n+=1:i+=1}let a=h()-s;if(t.logVerifierResults){let o=i===0?"passed":"complete";t.console.info(`[crossdeck] Self-verification ${o} \u2014 ${n} passed, ${i} failed (${a}ms)`)}return{passed:n,failed:i,totalMs:a}}function st(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onIdentify;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","identify")}}function nt(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onTrack;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","track")}}function it(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onSyncPurchases;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","syncPurchases")}}function ot(r,e,t,s){if(!t.disableContractAssertions)for(let n of r){let i=n.hooks?.onErrorParse;if(!i)continue;let a;try{a=i(s)}catch(o){a=b(n.contractId,`hook threw: ${o.message?.slice(0,80)??"unknown"}`,0)}e.report(a,"hot_path","errorParse")}}function at(){try{if(typeof process<"u"&&process.env){let e=process.env.NODE_ENV;if(typeof e=="string")return e!=="production"}}catch{}let r=globalThis.__DEV__;return typeof r=="boolean"?r:!1}function x(r,e,t){return{ok:!0,contractId:r,evidence:e,durationMs:t}}function b(r,e,t){return{ok:!1,contractId:r,failureReason:e,durationMs:t}}function h(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Rr(r,e){return r.length>e?r.slice(0,e-1)+"\u2026":r}function H(r){let e=r.startsWith("_")?r.slice(1):r;return e.length<=12?e:`${e.slice(0,4)}\u2026${e.slice(-4)}`}function Ar(r){let e=new Uint8Array(Math.ceil(r/2));if(typeof globalThis<"u"&&globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(e);else for(let s=0;s<e.length;s+=1)e[s]=Math.floor(Math.random()*256);let t="";for(let s=0;s<e.length;s+=1)t+=e[s].toString(16).padStart(2,"0");return t.slice(0,r)}var pe=class{constructor(){this.map=new Map}getItem(e){return this.map.get(e)??null}setItem(e,t){this.map.set(e,t)}removeItem(e){this.map.delete(e)}keys(){return Array.from(this.map.keys())}};pe._=q;function Ae(r){if(!r||typeof r!="string")return[];let e=r.split(`
|
|
2
|
+
`),t=[];for(let s of e){let n=s.trim();if(!n)continue;let i=Pr(n);i&&t.push(i)}return t}function Pr(r){let e=/^at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)$/.exec(r);return e?Re({function:e[1],filename:e[2],lineno:parseInt(e[3],10),colno:parseInt(e[4],10),raw:r}):(e=/^at\s+(.+?):(\d+):(\d+)$/.exec(r),e?Re({function:"?",filename:e[1],lineno:parseInt(e[2],10),colno:parseInt(e[3],10),raw:r}):(e=/^(.*?)@(.+?):(\d+):(\d+)$/.exec(r),e?Re({function:e[1]||"?",filename:e[2],lineno:parseInt(e[3],10),colno:parseInt(e[4],10),raw:r}):/^\w*Error/.test(r)||!r.includes(":")?null:{function:"?",filename:"",lineno:0,colno:0,in_app:!0,raw:r}))}function Re(r){return{function:r.function||"?",filename:r.filename,lineno:Number.isFinite(r.lineno)?r.lineno:0,colno:Number.isFinite(r.colno)?r.colno:0,in_app:Dr(r.filename),raw:r.raw}}function Dr(r){return r?!(/^(?:chrome|moz|safari|webkit)-extension:\/\//.test(r)||/^iabjs:\/\//.test(r)||/^(?:webview|inappbrowser):\/\//i.test(r)||/\bcdn\.jsdelivr\.net\b/.test(r)||/\bunpkg\.com\b/.test(r)||/\bgoogletagmanager\.com\b/.test(r)||/\bgoogle-analytics\.com\b/.test(r)||/\b@cross-deck\/web\b/.test(r)||/\/crossdeck\.umd\.min\.js$/.test(r)):!0}var Vr=/(__firefox__|__gCrWeb|zaloJSV2)/;function dt(r){let e=Vr.exec(r??"");return e?e[1]:null}function Pe(r,e){return dt(e)?r.map(t=>t.in_app?{...t,in_app:!1}:t):r}function $(r,e,t){let s=dt(r);if(s)return ct(`injected-global:${s}`);let n=e.filter(a=>a.in_app).slice(0,3),i=[(r||"").slice(0,200),...n.map(a=>`${a.function}@${a.filename}:${a.lineno}`)];if(n.length===0&&t){let a=[t.errorType??"",t.filename??"",t.lineno??"",t.colno??""].join(":");a!==":::"&&i.push(a)}return ct(i.join("|"))}function ct(r){let e=5381;for(let t=0;t<r.length;t++)e=(e<<5)+e+r.charCodeAt(t)|0;return(e>>>0).toString(16).padStart(8,"0")}var lt={enabled:!0,onError:!0,onUnhandledRejection:!0,wrapFetch:!0,wrapXhr:!0,captureConsole:!1,ignoreErrors:["ResizeObserver loop limit exceeded","ResizeObserver loop completed with undelivered notifications","Non-Error promise rejection captured"],allowUrls:[],denyUrls:[/^chrome-extension:\/\//,/^moz-extension:\/\//,/^safari-extension:\/\//,/^webkit-extension:\/\//,/^safari-web-extension:\/\//],sampleRate:1,maxPerFingerprintPerMinute:5,maxPerSession:100},he=class{constructor(e){this.opts=e;this.installed=!1;this.cleanups=[];this._reporting=!1;this.sessionCount=0;this.fingerprintWindow=new Map}install(){if(this.installed||!this.opts.config.enabled||typeof globalThis>"u"||!("window"in globalThis))return;let e=globalThis.window;this.opts.config.onError&&this.installOnErrorListener(e),this.opts.config.onUnhandledRejection&&this.installRejectionListener(e),this.opts.config.wrapFetch&&this.installFetchWrap(e),this.opts.config.wrapXhr&&this.installXhrWrap(e),this.opts.config.captureConsole&&this.installConsoleWrap(),this.installed=!0}uninstall(){for(let e of this.cleanups.splice(0))try{e()}catch{}this.installed=!1}captureError(e,t){if(this.opts.isConsented())try{let s=this.buildFromUnknown(e,"error.handled",t?.level??"error");t?.context&&(s.context={...s.context,...t.context}),t?.tags&&(s.tags={...s.tags,...t.tags}),this.maybeReport(s)}catch{}}captureMessage(e,t="info"){if(this.opts.isConsented())try{let s={timestamp:Date.now(),kind:"error.message",level:t,message:e,errorType:null,frames:[],rawStack:null,filename:null,lineno:null,colno:null,fingerprint:$(e,[]),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:this.opts.getContext(),tags:this.opts.getTags()};this.maybeReport(s)}catch{}}installOnErrorListener(e){let t=s=>{if(!this._reporting&&this.opts.isConsented())try{this._reporting=!0;let n=this.buildFromErrorEvent(s);this.maybeReport(n)}catch{}finally{this._reporting=!1}};e.addEventListener("error",t,!0),this.cleanups.push(()=>e.removeEventListener("error",t,!0))}installRejectionListener(e){let t=s=>{if(!this._reporting&&this.opts.isConsented())try{this._reporting=!0;let n=this.buildFromUnknown(s.reason,"error.unhandledrejection","error");this.maybeReport(n)}catch{}finally{this._reporting=!1}};e.addEventListener("unhandledrejection",t),this.cleanups.push(()=>e.removeEventListener("unhandledrejection",t))}installFetchWrap(e){let t=e.fetch?.bind(e);if(!t)return;let s=async(...n)=>{let i=n[0],a=n[1]??{},o=typeof i=="string"?i:i?.url??"",c=(a.method||"GET").toUpperCase(),l=Date.now();Ve(o,this.opts.selfHostname)||this.opts.breadcrumbs.add({timestamp:l,category:"http",message:`${c} ${o}`,data:{url:o,method:c}});try{let d=await t(...n);return d.status>=500&&this.opts.isConsented()&&(Ve(o,this.opts.selfHostname)||this.captureHttp({url:o,method:c,status:d.status,statusText:d.statusText})),d}catch(d){throw this.opts.isConsented()&&!o.includes("api.cross-deck.com")&&!Lr(o,d,e)&&this.captureHttp({url:o,method:c,status:0,statusText:d instanceof Error?d.message:"network error"}),d}};e.fetch=s,this.cleanups.push(()=>{e.fetch===s&&(e.fetch=t)})}installXhrWrap(e){let s=e.XMLHttpRequest?.prototype;if(!s)return;let n=s.open,i=s.send,a=this;s.open=function(o,c,...l){return this._cdMethod=o,this._cdUrl=c,n.apply(this,[o,c,...l])},s.send=function(o){let c=this,l=()=>{try{if(c.status>=500&&a.opts.isConsented()){let d=c._cdUrl??"";Ve(d,a.opts.selfHostname)||a.captureHttp({url:d,method:(c._cdMethod??"GET").toUpperCase(),status:c.status,statusText:c.statusText})}}catch{}};return c.addEventListener("loadend",l),i.apply(this,[o??null])},this.cleanups.push(()=>{s.open=n,s.send=i})}installConsoleWrap(){let e=globalThis.console;if(!e)return;let t=e.error.bind(e);e.error=(...s)=>{try{this.opts.isConsented()&&this.captureMessage(s.map(n=>Fr(n)).join(" "),"error")}catch{}return t(...s)},this.cleanups.push(()=>{e.error=t})}buildFromErrorEvent(e){let t=e.error,s=e.filename||null,n=typeof e.lineno=="number"&&e.lineno>0?e.lineno:null,i=typeof e.colno=="number"&&e.colno>0?e.colno:null;if(t==null&&!s&&n==null&&(e.message==="Script error."||e.message==="Script error"||!e.message)){let p="Cross-origin script error (browser hid details \u2014 script needs crossorigin attribute + CORS headers)";return{timestamp:Date.now(),kind:"error.unhandled",level:"error",message:p,errorType:"ScriptError",frames:[],rawStack:null,filename:null,lineno:null,colno:null,fingerprint:$(p,[]),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:this.opts.getContext(),tags:{...this.opts.getTags(),cross_origin:"true"}}}let o=Oe(t),c=(o.message||e.message||"Unknown error").slice(0,1024),l=t instanceof Error?t.stack??null:null,d=Pe(Ae(l),c),u=o.errorType??null,m=o.extras?{...this.opts.getContext(),__error_extras:o.extras}:this.opts.getContext();return{timestamp:Date.now(),kind:"error.unhandled",level:"error",message:c,errorType:u,frames:d,rawStack:l,filename:s,lineno:n,colno:i,fingerprint:$(c,d,{filename:s,lineno:n,colno:i,errorType:u}),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:m,tags:this.opts.getTags()}}buildFromUnknown(e,t,s){let n=Oe(e),i=(n.message||"Unknown error").slice(0,1024),a=e instanceof Error?e.stack??null:null,o=Pe(Ae(a),i),c=n.errorType??null,l=n.extras?{...this.opts.getContext(),__error_extras:n.extras}:this.opts.getContext();return{timestamp:Date.now(),kind:t,level:s,message:i,errorType:c,frames:o,rawStack:a,filename:null,lineno:null,colno:null,fingerprint:$(i,o,{errorType:c}),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:l,tags:this.opts.getTags()}}captureHttp(e){try{let t=`HTTP ${e.status} ${e.method} ${e.url}`,s={timestamp:Date.now(),kind:"error.http",level:"error",message:t,errorType:"HTTPError",frames:[],rawStack:null,filename:e.url,lineno:null,colno:null,fingerprint:$(`HTTP ${e.status} ${e.method}`,[],{filename:e.url,errorType:"HTTPError"}),breadcrumbs:this.opts.breadcrumbs.snapshot(),context:this.opts.getContext(),tags:this.opts.getTags(),http:e};this.maybeReport(s)}catch{}}maybeReport(e){if(this.sessionCount>=this.opts.config.maxPerSession||this.shouldIgnore(e)||!this.passesUrlGate(e)||!this.passesSample(e)||!this.passesRateLimit(e))return;let t=e,s=this.opts.beforeSend?.();if(s){try{t=s(e)}catch{t=e}if(!t)return}this.sessionCount+=1;try{this.opts.report(t)}catch{}}shouldIgnore(e){for(let t of this.opts.config.ignoreErrors)if(typeof t=="string"&&e.message.includes(t)||t instanceof RegExp&&t.test(e.message))return!0;return!1}passesUrlGate(e){let s=(e.frames.find(n=>n.filename)??null)?.filename??e.filename??"";if(!s)return!0;for(let n of this.opts.config.denyUrls)if(typeof n=="string"&&s.includes(n)||n instanceof RegExp&&n.test(s))return!1;if(this.opts.config.allowUrls.length>0){for(let n of this.opts.config.allowUrls)if(typeof n=="string"&&s.includes(n)||n instanceof RegExp&&n.test(s))return!0;return!1}return!0}passesSample(e){return this.opts.config.sampleRate>=1?!0:this.opts.config.sampleRate<=0?!1:parseInt(e.fingerprint.slice(0,2),16)/255<this.opts.config.sampleRate}passesRateLimit(e){let s=Date.now(),n=this.opts.config.maxPerFingerprintPerMinute,a=(this.fingerprintWindow.get(e.fingerprint)??[]).filter(o=>s-o<6e4);return a.length>=n?(this.fingerprintWindow.set(e.fingerprint,a),!1):(a.push(s),this.fingerprintWindow.set(e.fingerprint,a),!0)}};function Oe(r){if(r===null)return{message:"(thrown: null)",errorType:null,extras:null};if(r===void 0)return{message:"(thrown: undefined)",errorType:null,extras:null};if(typeof r=="string")return{message:r,errorType:null,extras:null};if(typeof r=="number"||typeof r=="boolean"||typeof r=="bigint")return{message:String(r),errorType:typeof r,extras:null};if(typeof r=="symbol")return{message:r.toString(),errorType:"symbol",extras:null};if(typeof r=="function")return{message:`(thrown function: ${r.name||"anonymous"})`,errorType:"function",extras:null};if(r instanceof Error){let e=r.name||r.constructor?.name||"Error",t=typeof r.message=="string"&&r.message.length>0?r.message:M(r)||e,s={},n=Or(r);n.length>0&&(s.cause=n);for(let i of["code","status","statusCode","errno","response","data","detail","details"]){let a=r[i];a!==void 0&&typeof a!="function"&&(s[i]=De(a))}for(let i of Object.keys(r)){if(i==="message"||i==="stack"||i==="name"||i==="cause"||i in s)continue;let a=r[i];typeof a!="function"&&(s[i]=De(a))}return{message:t,errorType:e,extras:Object.keys(s).length>0?s:null}}if(typeof Response<"u"&&r instanceof Response)return{message:`HTTP ${r.status} ${r.statusText||""}${r.url?` ${r.url}`:""}`.trim(),errorType:"Response",extras:{status:r.status,statusText:r.statusText,url:r.url,type:r.type}};if(typeof r=="object"){let e=r,t=e.constructor&&typeof e.constructor=="function"&&e.constructor.name||null,s=typeof e.message=="string"&&e.message?e.message:null,n=typeof e.name=="string"&&e.name?e.name:null,i=null;try{let u=JSON.stringify(e);i=u==="{}"?null:u}catch{i=null}let a=M(e),o=s??i??(a&&a!=="[object Object]"?a:null)??(t?`(thrown ${t} with no message)`:"(thrown object with no message)"),c=n??t??null,l={},d=0;for(let u of Object.keys(e)){if(d>=20)break;if(u==="message"||u==="name")continue;let m=e[u];typeof m!="function"&&(l[u]=De(m),d++)}return{message:o,errorType:c,extras:Object.keys(l).length>0?l:null}}return{message:M(r)||"(unstringifiable thrown value)",errorType:null,extras:null}}function Or(r){let e=[],t=r.cause,s=0;for(;t!=null&&s<5;)t instanceof Error?(e.push({name:t.name||"Error",message:t.message||""}),t=t.cause):(e.push({name:"non-Error",message:M(t)}),t=null),s++;return e}function M(r){try{let e=Object.prototype.toString.call(r);if(e!=="[object Object]")return e;let t=r?.toString;if(typeof t=="function"&&t!==Object.prototype.toString){let s=t.call(r);if(typeof s=="string")return s}return e}catch{return"(throwing toString)"}}function De(r){if(r==null)return r;let e=typeof r;if(e==="string"||e==="number"||e==="boolean")return r;if(e==="bigint")return String(r);try{let t=JSON.stringify(r);return t===void 0?M(r):JSON.parse(t)}catch{return M(r)}}function Fr(r){return Oe(r).message}function ut(r){if(!r||typeof r!="string")return null;try{return new URL(r).hostname.toLowerCase()}catch{return null}}function Ve(r,e){if(!e||!r)return!1;try{return new URL(r).hostname.toLowerCase()===e}catch{return!1}}function Lr(r,e,t){if(e instanceof Error&&e.name==="AbortError")return!0;let s=t.navigator;if(s&&s.onLine===!1)return!0;let n=t.location?.href,i=t.location?.origin;if(!i)return!1;try{return new URL(r,n??i).origin===i}catch{return!1}}var G=class{constructor(){this.state=null;this.verifiers=null;this.verifierReporter=null;this.verifierCtx=null}init(e){if(this.state){try{this.state.uninstallUnloadFlush?.()}catch{}try{this.state.autoTracker?.uninstall()}catch{}try{this.state.webVitals?.uninstall()}catch{}try{this.state.errors?.uninstall()}catch{}try{this.state.events.flush({keepalive:!0})}catch{}}if(!e.publicKey||!e.publicKey.startsWith("cd_pub_"))throw new _({type:"configuration_error",code:"invalid_public_key",message:"Crossdeck.init requires a publishable key starting with cd_pub_."});if(!e.appId)throw new _({type:"configuration_error",code:"missing_app_id",message:"Crossdeck.init requires an appId. Find yours in the Crossdeck dashboard."});if(e.environment!=="production"&&e.environment!=="sandbox")throw new _({type:"configuration_error",code:"invalid_environment",message:'Crossdeck.init requires environment: "production" | "sandbox".'});let t=Nr(e.publicKey);if(t&&t!==e.environment)throw new _({type:"configuration_error",code:"environment_mismatch",message:`Crossdeck.init: environment "${e.environment}" disagrees with key prefix (${t}). Reconcile the publishable key with the environment declaration.`});let s=Ur(),n=e.storage??Ne(),i=e.persistIdentity??!0,a=qr(e.autoTrack),o={appId:e.appId,publicKey:e.publicKey,environment:e.environment,baseUrl:e.baseUrl??Y,persistIdentity:i,storagePrefix:e.storagePrefix??"crossdeck:",autoHeartbeat:e.autoHeartbeat??!0,eventFlushBatchSize:e.eventFlushBatchSize??20,eventFlushIntervalMs:e.eventFlushIntervalMs??2e3,sdkVersion:e.sdkVersion??R,autoTrack:a,appVersion:e.appVersion??null},c=new ie;c.enabled=e.debug===!0;let l=new X({publicKey:o.publicKey,baseUrl:o.baseUrl,sdkVersion:o.sdkVersion,localDevMode:s,onErrorParsed:f=>{this.verifiers&&this.verifierReporter&&this.verifierCtx&&ot(this.verifiers,this.verifierReporter,this.verifierCtx,{errorType:f.type,errorCode:f.code,requestId:f.requestId??null,httpStatus:typeof f.status=="number"?f.status:0})}});s&&console.log("[crossdeck] Localhost detected \u2014 running in dev mode (no network calls). Set publicKey: 'cd_pub_test_\u2026' and deploy to a real domain to test against the Crossdeck Sandbox.");let d=i?n:new O,m=i&&!e.storage&&typeof globalThis.document<"u"?new se:void 0,p=new Q(d,o.storagePrefix,m),y=new P(d,o.storagePrefix+"entitlements"),k=i?new re({storage:d,prefix:o.storagePrefix}):null;k&&c.emit("sdk.queue_restored","Restored persisted event queue from a prior session.");let g=new te({http:l,batchSize:o.eventFlushBatchSize,intervalMs:o.eventFlushIntervalMs,envelope:()=>({appId:o.appId,environment:o.environment,sdk:{name:A,version:o.sdkVersion}}),persistentStore:k??void 0,onFirstFlushSuccess:()=>{c.emit("sdk.first_event_sent","First telemetry event received. View it in Live Events.",{appId:o.appId,environment:o.environment})},onRetryScheduled:f=>{c.emit("sdk.flush_retry_scheduled",`Event flush failed (${f.lastError}). Retrying in ${f.delayMs}ms (attempt ${f.consecutiveFailures}).`,{...f})},onPermanentFailure:f=>{let w=`[crossdeck] Event batch DROPPED (status ${f.status}): ${f.lastError}. ${f.droppedCount} event(s) lost \u2014 check your publishable key + app config.`;console.error(w),c.emit("sdk.flush_permanent_failure",w,{...f})},onParked:f=>{c.emit("sdk.parked",`[crossdeck] SDK parked \u2014 server no longer accepts this version's event format. Events held on-device (paused, not lost); update @cross-deck/web${f.minVersion?` to >= ${f.minVersion}`:""} to resume.`,{...f})}}),v=a.deviceInfo?Ue({appVersion:o.appVersion??void 0}):o.appVersion?{appVersion:o.appVersion}:{},S=new ae(i?d:new O,o.storagePrefix);He();let T=new de({respectDnt:e.respectDnt===!0});T.isDntDenied&&c.emit("sdk.consent_dnt_applied","Do Not Track detected \u2014 all tracking dimensions denied at init.");let C=new le(50);if(this.state={http:l,identity:p,entitlements:y,events:g,autoTracker:null,webVitals:null,errors:null,breadcrumbs:C,errorContext:{},errorTags:{},errorBeforeSend:null,superProps:S,consent:T,scrubPii:e.scrubPii!==!1,deviceInfo:v,options:o,debug:c,developerUserId:null,uninstallUnloadFlush:null,lastServerTime:null,lastClientTime:null},c.emit("sdk.configured",`Crossdeck connected to ${o.appId} in ${o.environment} mode.`,{appId:o.appId,environment:o.environment,sdkVersion:o.sdkVersion}),a.sessions||a.pageViews){let f=new j(a,(w,E)=>this.track(w,E),{storage:d,storageKey:o.storagePrefix+"session"});this.state.autoTracker=f,f.install()}if(a.webVitals){let f=new ce({enabled:!0},(w,E)=>this.track(w,E));this.state.webVitals=f,f.install()}if(a.errors){let f=new he({config:{...lt,enabled:!0},breadcrumbs:C,report:w=>this.reportError(w),getContext:()=>({...this.state.errorContext}),getTags:()=>({...this.state.errorTags}),beforeSend:()=>this.state.errorBeforeSend,isConsented:()=>this.state.consent.errors,selfHostname:ut(o.baseUrl)});this.state.errors=f,f.install()}if(this.state.uninstallUnloadFlush=$r(()=>{this.flush({keepalive:!0}).catch(()=>{})}),o.autoHeartbeat&&!s&&this.heartbeat().catch(()=>{}),s||this.captureCampaignArrival().catch(()=>{}),e.disableContractAssertions!==!0){let f=at();this.verifierCtx=et({logVerifierResults:e.logVerifierResults??f,disableContractAssertions:!1,runContext:typeof process<"u"&&process.env&&process.env.CI?"ci":"customer-app"}),this.verifierReporter=new z(this.verifierCtx);let w=tt(o.eventFlushIntervalMs);this.verifiers=Object.freeze([...rt,w]),s?(e.verifyContractsAtBoot??f)&&this.verifierReporter&&Ie(this.verifiers,this.verifierReporter,this.verifierCtx).catch(()=>{}):this.bootstrapVerifierLayerRemote(e,f).catch(()=>{})}}async bootstrapVerifierLayerRemote(e,t){if(!this.state||!this.verifiers||!this.verifierCtx)return;let s={logVerifierResults:null,verifyContractsAtBoot:null};try{let a=await this.state.http.request("GET","/config");if(a&&a.verifierConfig){let o=a.verifierConfig;s={logVerifierResults:typeof o.logVerifierResults=="boolean"?o.logVerifierResults:null,verifyContractsAtBoot:typeof o.verifyContractsAtBoot=="boolean"?o.verifyContractsAtBoot:null}}}catch{}let n=e.logVerifierResults??s.logVerifierResults??t,i=e.verifyContractsAtBoot??s.verifyContractsAtBoot??t;n!==this.verifierCtx.logVerifierResults&&(this.verifierCtx={...this.verifierCtx,logVerifierResults:n},this.verifierReporter=new z(this.verifierCtx)),i&&this.verifierReporter&&await Ie(this.verifiers,this.verifierReporter,this.verifierCtx)}start(e){typeof console<"u"&&console.warn("[crossdeck] Crossdeck.start() is deprecated \u2014 use Crossdeck.init() instead. The signature is the same."),this.init(e)}async captureCampaignArrival(){let e=this.state;if(!e)return;let t=globalThis.location;if(!t||typeof t.search!="string"||t.search.length===0)return;let s=null;try{s=new URLSearchParams(t.search).get("cd_ref")}catch{return}if(s)try{await e.http.request("POST","/integrations/hubspot/arrival",{body:{anonymousId:e.identity.anonymousId,ref:s}})}catch{}}async identify(e,t){let s=this.requireStarted();if(!e)throw new _({type:"invalid_request_error",code:"missing_user_id",message:"identify(userId) requires a non-empty userId."});if(ye({actor:e}),!s.consent.analytics)return s.debug.emit("sdk.consent_denied","identify() skipped \u2014 consent denied for analytics."),{object:"alias_result",crossdeckCustomerId:s.identity.crossdeckCustomerId??"",linked:[],mergePending:!1,env:s.options.environment};let n=t?.traits!==void 0?W(t.traits):null,i=n&&Object.keys(n.properties).length>0?n.properties:void 0;if(s.debug.enabled&&n&&n.warnings.length>0)for(let l of n.warnings)s.debug.emit("sdk.property_coerced",`identify() traits key ${JSON.stringify(l.key)} was ${l.kind.replace(/_/g," ")} during validation.`,{key:l.key,kind:l.kind});let a={userId:e,anonymousId:s.identity.anonymousId};t?.email&&(a.email=t.email),i&&(a.traits=i);let o=s.developerUserId;s.entitlements.setUserKey(e),this.verifiers&&this.verifierReporter&&this.verifierCtx&&st(this.verifiers,this.verifierReporter,this.verifierCtx,{priorUserId:o,nextUserId:e,cache:s.entitlements});let c=await s.http.request("POST","/identity/alias",{body:a});return s.identity.setCrossdeckCustomerId(c.crossdeckCustomerId),s.developerUserId=e,c}register(e){let t=this.requireStarted(),s=W(e);return t.superProps.register(s.properties)}unregister(e){this.requireStarted().superProps.unregister(e)}getSuperProperties(){return this.state?this.state.superProps.getSuperProperties():{}}group(e,t,s){let n=this.requireStarted();if(!e)throw new _({type:"invalid_request_error",code:"missing_group_type",message:"group(type, id) requires a non-empty type."});let i=s?W(s).properties:void 0;n.superProps.setGroup(e,t,i)}getGroups(){return this.state?this.state.superProps.getGroups():{}}consent(e){let t=this.requireStarted(),s=t.consent.set(e);return t.debug.emit("sdk.consent_changed","Consent state updated.",{...s}),s}consentStatus(){return this.state?this.state.consent.get():{analytics:!0,marketing:!0,errors:!0}}captureError(e,t){this.state?.errors&&this.state.errors.captureError(e,t)}captureMessage(e,t="info"){this.state?.errors&&this.state.errors.captureMessage(e,t)}setTag(e,t){this.state&&(this.state.errorTags[e]=t)}setTags(e){this.state&&Object.assign(this.state.errorTags,e)}setContext(e,t){this.state&&(this.state.errorContext[e]=t)}addBreadcrumb(e){this.state&&this.state.breadcrumbs.add(e)}setErrorBeforeSend(e){this.state&&(this.state.errorBeforeSend=e)}reportError(e){let t={fingerprint:e.fingerprint,level:e.level,errorType:e.errorType,message:e.message,stack:e.rawStack??void 0,frames:e.frames,filename:e.filename??void 0,lineno:e.lineno??void 0,colno:e.colno??void 0,tags:e.tags,context:e.context,breadcrumbs:e.breadcrumbs,http:e.http};for(let s of Object.keys(t))t[s]===void 0&&delete t[s];this.track(e.kind,t)}async forget(){let e=this.requireStarted(),t=this.identityQueryParams();try{await e.http.request("POST","/identity/forget",{body:{...t}})}catch(s){e.debug.emit("sdk.consent_denied",`forget() server call failed (${s instanceof Error?s.message:String(s)}). Local state wiped anyway.`)}this.reset()}async getEntitlements(){let e=this.requireStarted(),t=this.identityQueryParams(),s;try{s=await e.http.request("GET","/entitlements",{query:t})}catch(n){throw e.entitlements.markRefreshFailed(),n}return s.crossdeckCustomerId&&e.identity.setCrossdeckCustomerId(s.crossdeckCustomerId),e.entitlements.setFromList(s.data),s.data}isEntitled(e){return this.requireStarted().entitlements.isEntitled(e)}listEntitlements(){return this.requireStarted().entitlements.list()}onEntitlementsChange(e){return this.requireStarted().entitlements.subscribe(e)}reportContractFailure(e){let t={contract_id:e.contractId,sdk_version:R,sdk_platform:"web",failure_reason:e.failureReason,run_context:e.runContext,run_id:e.runId};e.testRef&&(t.test_file=e.testRef.file,t.test_name=e.testRef.name),e.deviceClass&&(t.device_class=e.deviceClass),ue(t)}track(e,t){let s=this.requireStarted();if(!e)throw new _({type:"invalid_request_error",code:"missing_event_name",message:"track(name) requires a non-empty name."});let n=e.startsWith("error."),i=e.startsWith("webvitals.");if(!(n||i?s.consent.errors:s.consent.analytics)){s.debug.enabled&&s.debug.emit("sdk.consent_denied",`Dropped event "${e}" \u2014 consent denied for ${i?"errors":"analytics"}.`);return}if(s.debug.enabled&&t){let f=Me(t);f.length>0&&s.debug.emit("sdk.sensitive_property_warning",`Event "${e}" has potentially sensitive property names: ${f.join(", ")}. Crossdeck is privacy-first \u2014 avoid sending PII unless intentional.`,{eventName:e,flagged:f})}s.debug.enabled&&!s.developerUserId&&!s.identity.crossdeckCustomerId&&s.debug.emit("sdk.no_identity","Using anonymous user until identify(userId) is called.");let o=W(t);if(s.debug.enabled&&o.warnings.length>0)for(let f of o.warnings)s.debug.emit("sdk.property_coerced",`Event "${e}" property ${JSON.stringify(f.key)} was ${f.kind.replace(/_/g," ")} during validation.`,{eventName:e,key:f.key,kind:f.kind});let c=s.autoTracker?.nextSeq()??0,l=Date.now();s.autoTracker?.markActivity();let d={},u=s.deviceInfo;u.os&&(d.os=u.os),u.osVersion&&(d.osVersion=u.osVersion);let m=s.options.appVersion;m&&(d.appVersion=m),d.sdkName=A,d.sdkVersion=s.options.sdkVersion,u.locale&&(d.locale=u.locale),u.timezone&&(d.timezone=u.timezone),u.browser&&(d.browser=u.browser),u.browserVersion&&(d.browserVersion=u.browserVersion);let p={};u.screenWidth!==void 0&&(p.screenWidth=u.screenWidth),u.screenHeight!==void 0&&(p.screenHeight=u.screenHeight),u.viewportWidth!==void 0&&(p.viewportWidth=u.viewportWidth),u.viewportHeight!==void 0&&(p.viewportHeight=u.viewportHeight),u.devicePixelRatio!==void 0&&(p.devicePixelRatio=u.devicePixelRatio);let y=s.autoTracker?.currentSessionId;y&&(p.sessionId=y);let k=s.autoTracker?.currentPageviewId;k&&(p.pageviewId=k);let g=s.autoTracker?.currentAcquisition;g&&(g.utm_source&&(p.utm_source=g.utm_source),g.utm_medium&&(p.utm_medium=g.utm_medium),g.utm_campaign&&(p.utm_campaign=g.utm_campaign),g.utm_content&&(p.utm_content=g.utm_content),g.utm_term&&(p.utm_term=g.utm_term),g.referrer&&s.consent.marketing&&(p.referrer=g.referrer),s.consent.marketing&&(g.gclid&&(p.gclid=g.gclid),g.fbclid&&(p.fbclid=g.fbclid),g.msclkid&&(p.msclkid=g.msclkid),g.ttclid&&(p.ttclid=g.ttclid),g.li_fat_id&&(p.li_fat_id=g.li_fat_id),g.twclid&&(p.twclid=g.twclid)));let v=s.superProps.getSuperProperties();for(let f of Object.keys(v))f in p||(p[f]=v[f]);let S=s.superProps.getGroupIds();Object.keys(S).length>0&&(p.$groups=S),Object.assign(p,o.properties),ze()&&(p[je]=!0);let T=s.scrubPii?Ee(p):p,C={eventId:this.mintEventId(),name:e,timestamp:l,seq:c,context:d,properties:T};if(Object.assign(C,this.identityHintForEvent()),s.events.enqueue(C),this.verifiers&&this.verifierReporter&&this.verifierCtx&&nt(this.verifiers,this.verifierReporter,this.verifierCtx,{callerProperties:o.properties,superProperties:v,deviceProperties:s.deviceInfo,mergedProperties:p}),!n&&!i){let f=e.startsWith("page.")?"navigation":e.startsWith("element.")||e==="session.started"?"ui.click":"custom";s.breadcrumbs.add({timestamp:C.timestamp,category:f,message:e,data:t?{...t}:void 0})}}async flush(e={}){await this.requireStarted().events.flush(e)}async flushEvents(){return this.flush()}async syncPurchases(e){let t=this.requireStarted();if(!e.signedTransactionInfo)throw new _({type:"invalid_request_error",code:"missing_signed_transaction_info",message:"syncPurchases requires a signedTransactionInfo string from StoreKit 2."});let s=e.rail??"apple",n={...e,rail:s},i=L(n);if(this.verifiers&&this.verifierReporter&&this.verifierCtx){let o=s==="apple"?n.signedTransactionInfo??"":n.purchaseToken??"";it(this.verifiers,this.verifierReporter,this.verifierCtx,{rail:s,stableIdentifier:o,derivedKey:i})}let a=await t.http.request("POST","/purchases/sync",{body:n,idempotencyKey:i});t.identity.setCrossdeckCustomerId(a.crossdeckCustomerId),t.entitlements.setFromList(a.entitlements);try{let o=a.entitlements[0]?.source.productId,c=a.entitlements[0]?.source.subscriptionId,l={rail:s};o&&(l.productId=o),c&&(l.subscriptionId=c),a.idempotent_replay&&(l.idempotent_replay=!0),this.track("purchase.completed",l)}catch{}return t.debug.emit("sdk.purchase_evidence_sent","StoreKit transaction forwarded. Waiting for backend verification.",{rail:e.rail??"apple"}),a}async purchaseApple(e){return this.syncPurchases({rail:"apple",...e})}setDebugMode(e){let t=this.requireStarted();t.debug.enabled=e,e&&t.debug.emit("sdk.configured",`Debug mode enabled for ${t.options.appId} in ${t.options.environment} mode.`,{appId:t.options.appId,environment:t.options.environment})}async heartbeat(){let e=this.requireStarted(),t=await e.http.request("GET","/sdk/heartbeat");return typeof t?.serverTime=="number"&&Number.isFinite(t.serverTime)&&(e.lastServerTime=t.serverTime,e.lastClientTime=Date.now()),t}reset(){if(this.state){if(this.state.developerUserId)try{this.track("user.signed_out",{auto:!0})}catch{}if(this.state.autoTracker?.uninstall(),this.state.identity.reset(),ye({actor:void 0}),this.state.entitlements.clearAll(),this.state.events.reset(),this.state.superProps.clear(),this.state.breadcrumbs.clear(),this.state.errorContext={},this.state.errorTags={},this.state.developerUserId=null,this.state.lastServerTime=null,this.state.lastClientTime=null,this.state.autoTracker){let e=new j(this.state.options.autoTrack,(t,s)=>this.track(t,s));this.state.autoTracker=e,e.install()}}}diagnostics(){if(!this.state)return{started:!1,anonymousId:null,crossdeckCustomerId:null,developerUserId:null,sdkVersion:null,baseUrl:null,clock:{lastServerTime:null,lastClientTime:null,skewMs:null},entitlements:{count:0,lastUpdated:0,stale:!1,listenerErrors:0},events:{buffered:0,dropped:0,inFlight:0,lastFlushAt:0,lastError:null,consecutiveFailures:0,nextRetryAt:null}};let e=this.state,t=e.lastServerTime!==null&&e.lastClientTime!==null?e.lastClientTime-e.lastServerTime:null;return{started:!0,anonymousId:e.identity.anonymousId,crossdeckCustomerId:e.identity.crossdeckCustomerId,developerUserId:e.developerUserId,sdkVersion:e.options.sdkVersion,baseUrl:e.options.baseUrl,clock:{lastServerTime:e.lastServerTime,lastClientTime:e.lastClientTime,skewMs:t},entitlements:{count:e.entitlements.list().length,lastUpdated:e.entitlements.freshness,stale:e.entitlements.isStale,listenerErrors:e.entitlements.listenerErrors},events:e.events.getStats()}}getCheckoutReference(){let e=this.requireStarted();return e.identity.crossdeckCustomerId??e.developerUserId??e.identity.anonymousId}getAnonymousId(){return this.state?this.state.identity.anonymousId:null}requireStarted(){if(!this.state)throw new _({type:"configuration_error",code:"not_initialized",message:"Call Crossdeck.init({ appId, publicKey, environment }) before any other method."});return this.state}identityQueryParams(){let e=this.requireStarted();return e.identity.crossdeckCustomerId?{customerId:e.identity.crossdeckCustomerId}:e.developerUserId?{userId:e.developerUserId}:{anonymousId:e.identity.anonymousId}}identityHintForEvent(){let e=this.requireStarted(),t={anonymousId:e.identity.anonymousId};return e.developerUserId&&(t.developerUserId=e.developerUserId),e.identity.crossdeckCustomerId&&(t.crossdeckCustomerId=e.identity.crossdeckCustomerId),t}mintEventId(){return`evt_${Date.now().toString(36)}${V(8)}`}},ft=new G;function Nr(r){return r.startsWith("cd_pub_test_")?"sandbox":r.startsWith("cd_pub_live_")?"production":null}function Ur(){let r=globalThis.window;if(r?.__CROSSDECK_FORCE_LIVE__===!0)return!1;let e=r?.location?.hostname;return e?!!(e==="localhost"||e==="127.0.0.1"||e==="0.0.0.0"||e==="::1"||e==="[::1]"||/^\[?fe80::/i.test(e)||e.endsWith(".local")||/^10\./.test(e)||/^192\.168\./.test(e)||/^172\.(1[6-9]|2\d|3[0-1])\./.test(e)):!1}function qr(r){return r===!1?{sessions:!1,pageViews:!1,deviceInfo:!1,clicks:!1,webVitals:!1,errors:!1}:r===void 0||r===!0?{...F}:{sessions:r.sessions??F.sessions,pageViews:r.pageViews??F.pageViews,deviceInfo:r.deviceInfo??F.deviceInfo,clicks:r.clicks??F.clicks,webVitals:r.webVitals??F.webVitals,errors:r.errors??F.errors}}function $r(r){let e=globalThis.window,t=globalThis.document;if(!e||!t)return()=>{};let s=()=>{try{t.visibilityState==="hidden"&&r()}catch{}},n=()=>{try{r()}catch{}};return t.addEventListener("visibilitychange",s),e.addEventListener("pagehide",n),e.addEventListener("beforeunload",n),()=>{t.removeEventListener("visibilitychange",s),e.removeEventListener("pagehide",n),e.removeEventListener("beforeunload",n)}}var pt="@cross-deck/web@1.8.0",ht="1.8.0",U=Object.freeze([{id:"contract-failed-payload-schema-lock",pillar:"diagnostics",status:"enforced",claim:"The `crossdeck.contract_failed` event payload contains ONLY the named diagnostic fields and never any end-user personal data. The wire shape is fixed \u2014 adding a new field requires (1) a pull request that updates this contract's `allowedFields` set, (2) a Privacy Policy \xA76 amendment, and (3) the Customer Disclosure Template / SDK Data Collection Reference \xA7B updates. Per-SDK assertion tests enforce the field set on every release. The `verification_phase` field is a categorical bucket \u2014 values are restricted to `boot` (the SDK self-test ran on Crossdeck.start) or `hot_path` (a verifier observed a real customer-triggered operation). The categorical nature is what preserves the diagnostic-only-not-personal classification. This is the structural guarantee that backs the independent-controller lawful basis in the Privacy Policy: the payload remains diagnostic-only, not personal, so the legitimate-interest analysis stays valid as the SDK evolves.",appliesTo:["web","node","swift","android","react-native"],allowedFields:{required:["contract_id","sdk_version","sdk_platform","failure_reason","run_context","run_id"],optional:["test_file","test_name","device_class","verification_phase"],forbidden:["anonymousId","developerUserId","crossdeckCustomerId","email","ip","user_agent","message","stack","stack_trace","frames","exception_message","url","path","screen","title","label","text","ariaLabel","accessibilityLabel","contentDescription","session_id","sessionId"]},transport:"Telemetry is single-fire to the Crossdeck reliability endpoint only \u2014 NOT the customer's appId. The customer's track() pipeline never carries `crossdeck.*` events; the customer's dashboard never shows individual contract failures. Operational telemetry flows one-way to the Crossdeck operations team for SDK reliability purposes (legitimate interest, independent-controller flow per Privacy Policy \xA76). The reliability endpoint is hardcoded at SDK build time; the publishable key for the reliability project is embedded as a constant and rejects writes that don't match the schema.",codeRef:["sdks/web/src/crossdeck.ts","sdks/node/src/crossdeck-server.ts","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/swift/Sources/Crossdeck/_DiagnosticTelemetry.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/_DiagnosticTelemetry.kt","sdks/react-native/src/crossdeck.ts","backend/src/api/v1-sdk-diagnostic.ts","sdks/web/src/_diagnostic-telemetry.ts","sdks/node/src/_diagnostic-telemetry.ts","sdks/react-native/src/_diagnostic-telemetry.ts"],testRef:[{file:"sdks/web/tests/contract-failed-schema-lock.test.ts",name:"reportContractFailure payload conforms to schema-lock"},{file:"sdks/node/tests/contract-failed-schema-lock.test.ts",name:"reportContractFailure payload conforms to schema-lock"},{file:"sdks/swift/Tests/CrossdeckTests/ContractFailedSchemaLockTests.swift",name:"test_reportContractFailure_payloadFieldsAreInAllowList"},{file:"sdks/swift/Tests/CrossdeckTests/ContractFailedSchemaLockTests.swift",name:"test_reportContractFailure_doesNotEnterCustomerTrackPipeline"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ContractFailedSchemaLockTest.kt",name:"reportContractFailure payload conforms to schema-lock"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ContractFailedSchemaLockTest.kt",name:"reportContractFailure does not enter customer track pipeline"},{file:"sdks/react-native/tests/contract-failed-schema-lock.test.ts",name:"reportContractFailure payload conforms to schema-lock"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"forbidden fields are enumerated in the schema-lock contract"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"required fields are enumerated in the schema-lock contract"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"regression guard: never returns a raw IP"},{file:"backend/tests/unit/v1-sdk-diagnostic.test.ts",name:"verification_phase is in the optional field set"}],registeredAt:"2026-05-27",firstRegisteredIn:"Diagnostic telemetry single-fire + schema-lock \u2014 independent-controller flow",privacyReferences:["legal/privacy/index.html#sdk-diagnostic","legal/customer-disclosure/index.html#flow-b","legal/security/index.html#diagnostic","legal/sdk-data/index.html#b-diagnostic"],bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"error-envelope-shape",pillar:"errors",status:"enforced",claim:"Every v1 REST endpoint returns errors in a Stripe-shape envelope: `{ error: { type, code, message, request_id } }` where `type` is one of authentication_error / permission_error / invalid_request_error / rate_limit_error / internal_error (the wire vocabulary in backend/src/api/v1-errors.ts ApiErrorType). HTTP status parity: invalid_request_error \u2192 400, authentication_error \u2192 401, permission_error \u2192 403, rate_limit_error \u2192 429, internal_error \u2192 500. SDK-side clients parse this shape via `crossdeckErrorFromResponse` (Web/Node/RN) / `crossdeckErrorFrom(response:)` (Swift) / `crossdeckErrorFromResponse` (Android) and surface the request_id verbatim so support traces are end-to-end joinable. Firebase callable endpoints (managed-keys / dashboard auth) use the Firebase HttpsError envelope instead \u2014 this contract applies to REST /v1/* only.",appliesTo:["web","node","react-native","swift","android","backend"],codeRef:["backend/src/api/v1-errors.ts","sdks/web/src/errors.ts","sdks/node/src/errors.ts","sdks/react-native/src/errors.ts","sdks/swift/Sources/Crossdeck/Errors.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Errors.kt"],testRef:[{file:"sdks/swift/Tests/CrossdeckTests/ErrorsTests.swift",name:"test_errorEnvelope_fallsBackOnGarbageBody"},{file:"sdks/swift/Tests/CrossdeckTests/ErrorsTests.swift",name:"test_errorEnvelope_reads_XRequestId_fallback"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ErrorTypeWireVocabTest.kt",name:"backend 500 response parses to INTERNAL_ERROR"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 8 (codifies existing contract)",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"flush-interval-parity",pillar:"analytics",status:"enforced",claim:"Every Crossdeck SDK defaults its event-queue flush interval to 2000ms \u2014 the Stripe-adjacent industry norm. Pre-v1.4.0 the defaults disagreed (Web/Node 1500ms; RN/Swift/Android 5000ms), so cross-platform funnels saw events landing at different cadences. Per-instance override stays \u2014 call sites can still tune it freely.",appliesTo:["web","node","react-native","swift","android"],codeRef:["sdks/web/src/crossdeck.ts","sdks/node/src/crossdeck-server.ts","sdks/react-native/src/crossdeck.ts","sdks/swift/Sources/Crossdeck/EventQueue.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EventQueue.kt"],testRef:[{file:"sdks/swift/Sources/Crossdeck/EventQueue.swift",name:"flushIntervalMs: Int = 2_000"},{file:"sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EventQueue.kt",name:"flushIntervalMs: Long = 2_000L"},{file:"sdks/web/src/crossdeck.ts",name:"options.eventFlushIntervalMs ?? 2000"},{file:"sdks/node/src/crossdeck-server.ts",name:"options.eventFlushIntervalMs ?? 2000"},{file:"sdks/react-native/src/crossdeck.ts",name:"options.eventFlushIntervalMs ?? 2000"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 3.3",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"idempotency-key-deterministic",pillar:"revenue",status:"enforced",claim:"syncPurchases() on every SDK derives a deterministic Idempotency-Key from the request body (UUID-shaped SHA-256 of `crossdeck:purchases/sync:<rail>:<jws|token>`). Same input -> same key. Backend short-circuits same-key-same-body retries by returning the cached response (status + body) with `idempotent_replay: true` flag in the body AND `Idempotent-Replayed: true` response header. Same-key-different-body returns 400 `idempotency_key_in_use`. 24-hour TTL matches Stripe. Cache only stores 2xx responses \u2014 4xx/5xx pass through so callers can fix bugs and retry. Helper returns nil/throws on missing identifier (no silent random fallback). Cross-SDK parity is CI-pinned: deriveForPurchase('apple', 'eyJ.jws.sig') MUST equal 'a66b1640-efaf-bb4d-1261-6650033bf111' on every SDK.",appliesTo:["web","node","react-native","swift","android","backend"],codeRef:["sdks/web/src/idempotency-key.ts","sdks/web/src/crossdeck.ts","sdks/react-native/src/idempotency-key.ts","sdks/react-native/src/crossdeck.ts","sdks/node/src/idempotency-key.ts","sdks/node/src/crossdeck-server.ts","sdks/swift/Sources/Crossdeck/IdempotencyKey.swift","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/IdempotencyKey.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt","backend/src/lib/idempotency-response-cache.ts","backend/src/api/v1-purchases.ts"],testRef:[{file:"sdks/web/tests/idempotency-key.test.ts",name:"cross-SDK oracle \u2014 apple JWS pins canonical vector"},{file:"sdks/web/tests/idempotency-key.test.ts",name:"is deterministic: same body twice -> identical key"},{file:"sdks/web/tests/idempotency-key.test.ts",name:"same identifier under different rails -> different keys"},{file:"sdks/web/tests/idempotency-key.test.ts",name:"never silently falls back to a random key on missing identifier"},{file:"sdks/react-native/tests/idempotency-key.test.ts",name:"is deterministic"},{file:"sdks/react-native/tests/idempotency-key.test.ts",name:"cross-SDK oracle \u2014 apple JWS pins canonical vector"},{file:"sdks/node/tests/idempotency-key.test.ts",name:"is deterministic"},{file:"sdks/node/tests/idempotency-key.test.ts",name:"rail namespacing prevents cross-rail collisions"},{file:"sdks/node/tests/idempotency-key.test.ts",name:"apple JWS produces the canonical pinned UUID across all 5 SDKs"},{file:"backend/tests/unit/idempotency-response-cache.test.ts",name:"is deterministic for the same input"},{file:"backend/tests/unit/idempotency-response-cache.test.ts",name:"injects idempotent_replay: true into a JSON object body"},{file:"backend/tests/unit/idempotency-response-cache.test.ts",name:"matches Stripe's 24-hour idempotency window"},{file:"sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",name:"test_crossSdkOracle_appleJWS"},{file:"sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",name:"test_railNamespacing_preventsCrossRailCollisions"},{file:"sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",name:"test_missingIdentifier_returnsNil"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",name:"cross-SDK oracle for apple JWS"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",name:"rail namespacing prevents cross-rail collisions"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",name:"missing identifier returns null - never silent random fallback"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 2.2.a + 2.2.b + 2.2.c",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"init-reentry-drains-prior-queue",pillar:"lifecycle",status:"enforced",claim:"Web + RN init() re-entry drains the prior EventQueue's pending setTimeout BEFORE replacing this.state. Pre-v1.4.0 the teardown handled autoTracker/webVitals/errors/unloadFlush but NOT events, so the prior queue's timer would fire AFTER the state swap \u2014 sending old-init events against new-init http + identity references (cross-identity leak during HMR / config swap / multi-tenant SDK shells). The teardown CANNOT call persistent.clear() \u2014 the durable queue belongs to the SDK lifetime, not the init() lifetime, and a survived crash mid-flush re-hydrates on the next init.",appliesTo:["web","react-native"],codeRef:["sdks/web/src/crossdeck.ts","sdks/react-native/src/crossdeck.ts"],testRef:[{file:"sdks/web/tests/init-reentry.test.ts",name:"re-init drains the prior queue's pending timer before swapping state"},{file:"sdks/web/tests/init-reentry.test.ts",name:"re-init does NOT wipe the durable event store"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 5.5",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!1},{id:"per-user-cache-isolation",pillar:"entitlements",status:"enforced",claim:"Every identify(userId) switches the entitlement cache to a physically separate per-user storage slot \u2014 `crossdeck:entitlements:<sha256(userId)>` \u2014 and unconditionally wipes the in-memory snapshot. A user-switch on a shared device CANNOT cross-read a prior user's cached entitlements, even if the in-memory clear is somehow skipped, because the storage keys are physically separate. reset() wipes every per-user slot via the persisted index.",appliesTo:["web","react-native","swift","android"],codeRef:["sdks/web/src/entitlement-cache.ts","sdks/web/src/hash.ts","sdks/web/src/crossdeck.ts","sdks/react-native/src/entitlement-cache.ts","sdks/react-native/src/hash.ts","sdks/react-native/src/crossdeck.ts","sdks/swift/Sources/Crossdeck/EntitlementCache.swift","sdks/swift/Sources/Crossdeck/IdempotencyKey.swift","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EntitlementCache.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/IdempotencyKey.kt","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt"],testRef:[{file:"sdks/web/tests/entitlement-cache-isolation.test.ts",name:"identify(B) makes A's entitlements unreachable from in-memory"},{file:"sdks/web/tests/entitlement-cache-isolation.test.ts",name:"clearAll() removes every per-user storage key plus the index"},{file:"sdks/web/tests/entitlement-cache-isolation.test.ts",name:"a second cache instance reading A's storage suffix CANNOT see B's data"},{file:"sdks/react-native/tests/entitlement-cache-isolation.test.ts",name:"identify(B) makes A's entitlements unreachable from in-memory"},{file:"sdks/react-native/tests/entitlement-cache-isolation.test.ts",name:"removes every per-user storage key plus the index"},{file:"sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",name:"test_identifyB_makesAEntitlementsUnreachable"},{file:"sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",name:"test_identifiedWritesLandUnderPerUserSha256Key"},{file:"sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",name:"test_clearAll_removesEveryPerUserStorageKeyPlusIndex"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"identified writes land under per-user sha256 key"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"identify B makes A entitlements unreachable from in-memory"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"clearAll removes every per-user storage key plus the index"},{file:"sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",name:"a fresh cache bound to A's key CANNOT read B's blob"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 1.3 (web/RN) + dogfood-gap fix (swift + android)",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"sdk-error-codes-catalogue",pillar:"errors",status:"enforced",claim:"Web + Node SDK error-codes catalogues include EVERY backend-emitted ApiErrorCode with a description + resolution. Pre-v1.4.0 the catalogues documented codes the SDK threw ITSELF but ZERO backend codes \u2014 a developer hitting `invalid_api_key` / `origin_not_allowed` / `bundle_id_not_allowed` / `env_mismatch` / `idempotency_key_in_use` etc. got `undefined` from getErrorCode() and had to hunt for guidance. v1.4.0 backfills the catalogue from backend/src/api/v1-errors.ts so every wire code has a canonical 'what does this mean / what should I do' answer Stripe-style.",appliesTo:["web","node"],codeRef:["sdks/web/src/error-codes.ts","sdks/node/src/error-codes.ts","sdks/web/src/_contract-verifiers.ts","backend/src/api/v1-errors.ts"],testRef:[{file:"sdks/web/tests/contract-verifiers.test.ts",name:"sdk-error-codes-catalogue covers every backend wire code with remediation"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"includes backend code"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"invalid_api_key resolution points at the dashboard"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"idempotency_key_in_use resolution mentions Stripe-grade contract"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"identity-lock codes carry permission_error type"},{file:"sdks/web/tests/error-codes-backfill.test.ts",name:"no entry has an empty description or resolution"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 6.2",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"super-property-merge-precedence",pillar:"analytics",status:"enforced",claim:"Every Crossdeck SDK merges event properties with the precedence device < super < caller (caller-supplied values win over registered super-properties, which win over auto-attached device info). Pre-v1.4.0 Swift had it INVERTED (super < device < caller \u2014 device clobbered super), so a `register('plan', 'pro')` super-property was silently overridden by auto-attached device fields whenever keys collided. Cross-SDK funnel queries on super-property keys returned different answers per platform.",appliesTo:["web","swift"],codeRef:["sdks/web/src/super-properties.ts","sdks/web/src/_contract-verifiers.ts","sdks/swift/Sources/Crossdeck/EventPropertyMerge.swift","sdks/swift/Sources/Crossdeck/Crossdeck.swift"],testRef:[{file:"sdks/web/tests/contract-verifiers.test.ts",name:"super-property-merge-precedence verifies caller > super > device"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_super_overrides_device"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_caller_overrides_super"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_full_precedence_chain"},{file:"sdks/swift/Tests/CrossdeckTests/EventPropertyMergeTests.swift",name:"test_matchesWebNodeRNPrecedence"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 3.2",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!0},{id:"sync-purchases-funnel-parity",pillar:"analytics",status:"enforced",claim:"Manual syncPurchases() emits a `purchase.completed` analytics event on success across ALL SDKs (Web / Node / RN / Swift / Android). Pre-v1.4.0 only Swift/Android auto-track emitted it \u2014 Web/Node/RN manual calls + Swift/Android manual calls fired ZERO analytics. Schema mirrors the auto-track event name + rail/productId/subscriptionId so cross-platform funnels reconcile on every payment path. When the backend short-circuits via the v1.4.0 idempotency cache, the event also carries `idempotent_replay: true`.",appliesTo:["web","node","react-native","swift","android"],codeRef:["sdks/web/src/crossdeck.ts","sdks/node/src/crossdeck-server.ts","sdks/react-native/src/crossdeck.ts","sdks/swift/Sources/Crossdeck/Crossdeck.swift","sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt"],testRef:[{file:"sdks/web/tests/sync-purchases-funnel.test.ts",name:"emits purchase.completed after a successful sync"},{file:"sdks/web/tests/sync-purchases-funnel.test.ts",name:"carries idempotent_replay=true when backend replied from cache"}],registeredAt:"2026-05-26",firstRegisteredIn:"bank-grade reconciliation v1.4.0 \u2014 phase 3.5",bundledIn:"@cross-deck/web@1.8.0",runtimeVerified:!1}]);var mt={all(){return U.filter(r=>r.status==="enforced")},allIncludingHistorical(){return U},byId(r){return U.find(e=>e.id===r)},byPillar(r){return U.filter(e=>e.pillar===r&&e.status==="enforced")},withStatus(r){return U.filter(e=>e.status===r)},sdkVersion:ht,bundledIn:pt,findByTestName(r){return U.find(e=>e.testRef.some(t=>t.name===r))}};return St(Mr);})();
|
|
3
3
|
//# sourceMappingURL=crossdeck.umd.min.js.map
|