@tinkerlandai/indiana-sdk 0.9.5 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +30 -41
  3. package/README.zh-CN.md +24 -22
  4. package/dist/{ai-usage-CUTIHAU0.d.ts → ai-usage-Cn7dhvFw.d.ts} +3 -3
  5. package/dist/{api-BXu6TAoB.d.ts → api-DC44FaTV.d.ts} +6354 -904
  6. package/dist/chunk-ACF2FBUB.js +1 -0
  7. package/dist/{chunk-XSOEA4A5.js → chunk-CWHJKWOD.js} +1 -1
  8. package/dist/chunk-EARSGITJ.js +1 -0
  9. package/dist/chunk-FYGXGMRB.js +1 -0
  10. package/dist/chunk-GHJ65ILJ.js +1 -0
  11. package/dist/chunk-JPV7F5XI.js +1 -0
  12. package/dist/{chunk-AOGPGUWE.js → chunk-LCLCG2I2.js} +1 -1
  13. package/dist/chunk-Q64VNSPV.js +6 -0
  14. package/dist/chunk-SBPTOOYB.js +1 -0
  15. package/dist/{chunk-MKV726FV.js → chunk-V3RAOCVQ.js} +1 -1
  16. package/dist/chunk-VZVUZWP2.js +1 -0
  17. package/dist/{chunk-M7JWCLYX.js → chunk-X6BCUINI.js} +1 -1
  18. package/dist/{chunk-4C3HUZ3B.js → chunk-XO42OH3M.js} +1 -1
  19. package/dist/{configuration-sync-DuJl4SbM.d.ts → configuration-sync-CywDxRkX.d.ts} +12 -12
  20. package/dist/{content-PQJYLAGQ.js → content-QM75T7JO.js} +1 -1
  21. package/dist/{funnel-local-client-BhHdi5_V.d.ts → funnel-local-client-DXamAj1-.d.ts} +18475 -2597
  22. package/dist/funnel-node-evaluation-P5B4fPfJ.d.ts +2054 -0
  23. package/dist/{funnel-resource-client-BoIhL_my.d.ts → funnel-resource-client-md62M8Rv.d.ts} +5977 -1126
  24. package/dist/funnel-runtime-host-BJZUVJAI.js +1 -0
  25. package/dist/index.d.ts +9924 -1958
  26. package/dist/index.js +1 -1
  27. package/dist/native-shell.js +1 -1
  28. package/dist/openrouter.d.ts +3 -3
  29. package/dist/openrouter.js +1 -1
  30. package/dist/page.d.ts +4 -4
  31. package/dist/page.js +1 -1
  32. package/dist/paywall-527RPFAX.js +1 -0
  33. package/dist/popup.d.ts +1 -1
  34. package/dist/popup.js +1 -1
  35. package/dist/react-native.d.ts +19930 -7179
  36. package/dist/react-native.js +1 -1
  37. package/dist/{screen-renderer-VAMWY7ID.js → screen-renderer-ZSAR7LPS.js} +1 -1
  38. package/dist/server.d.ts +2737 -573
  39. package/dist/server.js +1 -1
  40. package/dist/visual.d.ts +1 -1
  41. package/dist/visual.js +1 -1
  42. package/package.json +2 -2
  43. package/dist/chunk-5ZWSFE2C.js +0 -1
  44. package/dist/chunk-6ZZUNGNE.js +0 -1
  45. package/dist/chunk-HEGNIATD.js +0 -1
  46. package/dist/chunk-LMO3FXRT.js +0 -1
  47. package/dist/chunk-QYECMZJJ.js +0 -1
  48. package/dist/chunk-UBMPFTGE.js +0 -1
  49. package/dist/chunk-UWFYBRM2.js +0 -6
  50. package/dist/chunk-XRXI3DMZ.js +0 -1
  51. package/dist/funnel-node-evaluation-DuPmqIo1.d.ts +0 -998
  52. package/dist/funnel-runtime-host-3YUGXD3Y.js +0 -1
  53. package/dist/paywall-CSAGKPCP.js +0 -1
  54. package/dist/{screen-CvfI_L41.d.ts → screen-D81zCpfi.d.ts} +2 -2
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as Le,b as be}from"./chunk-AOGPGUWE.js";import{a as Pe,c as Fe}from"./chunk-QYECMZJJ.js";import{a as Be}from"./chunk-XRXI3DMZ.js";import{b as Te,g as De,l as $,m as Oe,n as xe,p as He}from"./chunk-UBMPFTGE.js";import"./chunk-5ZWSFE2C.js";import{B as Ae,C as Me,D as Ne,Ga as ye,Ha as ge,Ia as we,Ma as Ee,h as V,i as re,j as oe,k as ae,l as ie,m as se,ma as Ie,n as ce,o as de,p as ue,q as le,r as me,s as fe,t as pe,u as he}from"./chunk-UWFYBRM2.js";import{oa as D}from"./chunk-HEGNIATD.js";import{c as Re}from"./chunk-CLXORAOK.js";import"./chunk-6ZZUNGNE.js";import{c as ve,d as Se}from"./chunk-4C3HUZ3B.js";import{a as G}from"./chunk-DSPLGTQI.js";import"./chunk-G56XGVMS.js";import"./chunk-LMO3FXRT.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";import{z as U}from"zod";var r=class extends Error{constructor(d,O=0,p=!1,l="fix_request"){super(d);this.code=d;this.status=O;this.retryable=p;this.recovery=l;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function ke(n,b){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let d=n.body?.getReader();if(!d)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let O=()=>{d.cancel().catch(()=>{})};b.addEventListener("abort",O,{once:!0});let p=0,l="",a=new TextDecoder("utf-8",{fatal:!0});try{for(b.throwIfAborted();;){let c=await d.read();if(b.throwIfAborted(),c.done)break;if(p+=c.value.byteLength,p>262144)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");l+=a.decode(c.value,{stream:!0})}return l+=a.decode(),JSON.parse(l)}catch(c){throw b.throwIfAborted(),c instanceof r?c:new r("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{b.removeEventListener("abort",O),await d.cancel().catch(()=>{}),d.releaseLock()}}function Ge(n){let b=ie.parse(n.origin),d=se.parse(n.manifest),O={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment,accountId:n.scope.accountId};for(let o of["projectId","environmentId","environment","accountId"])if(d[o]!==n.scope[o])throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");let p=n.customerId===void 0?null:U.uuid().parse(n.customerId),l=0,a=null,c=null,x=new AbortController,F=n.fetch??globalThis.fetch;async function M(o,t,y,g,N){if(!n.scope.accountId)throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501,!1,"check_availability");if(!d.capabilities.includes(o))throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let v=ae[o];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(v.authority))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);let H=l,P=AbortSignal.any([x.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...g?[g]:[]]);P.throwIfAborted();let S=new Headers(await n.headers?.());if(P.throwIfAborted(),H!==l)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(S.get("authorization")??"")||S.has("X-Indiana-Bridge-Signature")||S.has("X-Indiana-Bridge-Key-Id"))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);S.set(oe,String(V)),S.set("Accept","application/json");let R=crypto.randomUUID();S.set("X-Request-Id",R),S.set("Content-Type","application/json");let m=await F(b+re,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:S,signal:P,body:JSON.stringify({bridgeVersion:V,requestId:R,command:v.command,scope:O,data:N??(y===void 0?{}:{operationId:y})})}),T=await ke(m,P);if(P.throwIfAborted(),H!==l)throw new DOMException("Merchant identity changed","AbortError");if(!m.ok){let I=he.safeParse(T);throw!I.success||I.data.scope.projectId!==n.scope.projectId||I.data.scope.environment!==n.scope.environment||I.data.scope.environmentId!==n.scope.environmentId||I.data.scope.accountId!==n.scope.accountId||I.data.requestId!==R||I.data.command!==v.command?new r("MERCHANT_BRIDGE_INVALID_RESPONSE",m.status):new r(I.data.error.code,m.status,I.data.error.retryable,I.data.error.recovery)}let w=ce(U.unknown()).safeParse(T);if(!w.success||w.data.scope.projectId!==n.scope.projectId||w.data.scope.environment!==n.scope.environment||w.data.scope.environmentId!==n.scope.environmentId||w.data.scope.accountId!==n.scope.accountId||w.data.requestId!==R||w.data.command!==v.command)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",m.status);let h=t.safeParse(w.data.data);if(!h.success)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",m.status);return h.data}function E(){if(!p)throw new r("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return p}async function B(o,t,y){let g=E(),N=me.parse({operationId:t}).operationId,v=await M(o,fe,N,y);if(v.customerId!==g||v.operationId!==N)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return v}return{async readPresentation(o){let t=await M("presentation",ue,void 0,o);if(c!==null&&c!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t.presentation&&p!==null&&t.presentation.customerId!==p)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return c=t.nativeUserId,a=t.presentation,t},async createSession(o){let t=await M("session",de,void 0,o);if(c!==null&&c!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(p!==null&&p!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(a&&a.customerId!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return p=t.session.customerId,c=t.nativeUserId,t.session},async reportPresentation(o,t){let y=E(),g=le.parse(o);if(!a||a.customerId!==y||a.decisionId!==g.decisionId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return M("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,t,g)},async readCustomerCommerce(o){let t=E(),y=await M("customer_commerce",pe,void 0,o);if(y.customerId!==t)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return y},executePurchase:(o,t)=>B("purchases",o,t),readOperation:(o,t)=>B("operation_status",o,t),executeSubscriptionChange:(o,t)=>B("subscription_changes",o,t),reset(){l++,x.abort(),x=new AbortController,p=null,a=null,c=null}}}function Ue(n){let b=ve(n.baseUrl),d=n.scope,O=Ee(n),p=n.fetch??globalThis.fetch.bind(globalThis),l,a=!1,c=!1,x=0,F=0,M="",E=0,B=0,o=0,t,y=!1,g,N=!0,v,H,P,S,R,m,T=e=>{m===e&&(m=void 0)},w=new Set,h=(e,u)=>G(n.onStatus,e,u);function I(){let e=R;R=void 0,e?.host.destroy(),e?.client.reset()}let z=()=>Date.now()<B&&performance.now()<o;function K(e){if(e.target.release!==n.appManifestRelease||!z())return!1;try{return Re(e.target.render,document,location.pathname,()=>{})}catch{return h("incompatible",e.id),!1}}function j(e){return!a&&e.epoch===E&&e.visit===F&&document.visibilityState!=="hidden"}async function J(e){if(m||R){h("in_progress",e.id);return}if(!n.session.peek()){h("identity_required",e.id);return}let u={command:ge.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:E,visit:F};m=u,await X(u)}async function X(e){if(e.dispatching)return;e.dispatching=!0;let u,C=!1;async function f(i){if(e.epoch!==E)return;let s=i.view;s&&["running","waiting"].includes(s.status)&&await i.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:s.nodeId,visit:s.visit,revision:s.revision})}try{h("starting",e.command.entryId);let i=await O.request("funnels",e.command),s=we.safeParse(i);if(s.success){if(s.data.scope.projectId!==d.projectId||s.data.scope.environment!==d.environment)throw new D("SCOPE_MISMATCH","Entry scope changed");e.epoch===E&&h(s.data.reason,e.command.entryId),T(e);return}let _=Ie.parse(i);if(!_.runToken||_.scope.projectId!==d.projectId||_.scope.environment!==d.environment||_.run.source.type!=="funnel"||_.run.source.id!==e.command.funnelId||_.run.source.versionId!==e.command.versionId)throw new D("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==E){T(e),h("identity_changed",e.command.entryId);return}let A=$({...n,runToken:_.runToken,funnelId:e.command.funnelId});u=A,await A.get();let k=A.view;if(!k||k.id!==_.run.id||k.source.type!=="funnel"||k.source.id!==e.command.funnelId||k.source.versionId!==e.command.versionId)throw new D("INVALID_RESPONSE","Entry Run version changed");if(!j(e)){await f(A),h("left_screen",e.command.entryId),T(e);return}let ee=!1,ne=!1,te=await be(n.container,{...n.host,client:A,appManifestRelease:n.appManifestRelease,onDismiss(q){ee=!0,R?.client===A&&(R=void 0,A.reset()),G(n.host?.onDismiss,q)},onComplete(q){ne=!0,R?.client===A&&I(),G(n.host?.onComplete,q)}});if(!j(e)||ee||ne){te.destroy(),j(e)||await f(A),T(e);return}R={host:te,client:A},C=!0,T(e),h("started",e.command.entryId)}catch(i){!u&&i instanceof D&&i.status!==void 0&&i.status>=400&&i.status<500&&!i.retryable&&T(e),e.epoch===E&&!a&&(h("start_failed",e.command.entryId),G(n.host?.onError,i))}finally{C||u?.reset(),e.dispatching=!1}}function Ce(){if(y=!1,!(a||!c||!z()||document.visibilityState==="hidden")){N=!1;for(let e of l?.entries??[])if(!(e.event!=="screen_enter"||w.has(`${e.funnelId}:${e.id}`)||!K(e))){if(!n.session.peek()){h("identity_required",e.id);continue}w.add(`${e.funnelId}:${e.id}`),J(e);break}}}let L=()=>{!y&&!a&&(y=!0,queueMicrotask(Ce))};function _e(){let e=location.origin+location.pathname;e!==M&&(M=e,F++,N=!0,w.clear(),L())}function Y(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let u=e.target;if(!(u instanceof Element)||u.closest("[data-indiana-funnel]"))return;let C=u.closest("button,a,input");if(!(!C||C.matches(":disabled,[aria-disabled='true']")||C.closest("[hidden],[inert],[aria-hidden='true']")))for(let f of l?.entries??[]){let i=f.target.button;if(f.event!=="button_click"||!i||!K(f))continue;let s=document.querySelectorAll(i.selector);if(!(s.length!==1||s[0]!==C)){J(f);break}}}async function Z(){if(a)return;if(g)return g;let e=++x;v=new AbortController;let u=(async()=>{let C=await p(`${b}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",signal:v.signal});if(!C.ok)throw new D("SERVICE_UNAVAILABLE","Funnel entries unavailable",C.status);let f=ye.parse(await C.json()),i=Date.parse(f.validatedAt),s=Date.parse(f.validUntil);if(f.scope.projectId!==d.projectId||f.scope.environment!==d.environment||f.scope.environmentId!==n.environmentId||f.release!==n.appManifestRelease||s<=Date.now()||i>Date.now()+5e3||s-i>6e4||s<=i)throw new D("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(a||e!==x)return;let _=l===void 0;l=f,B=s,o=performance.now()+Math.min(s-Date.now(),6e4),(_||N)&&L()})();g=u;try{await u}finally{g===u&&(g=void 0)}}async function Q(){try{await Z()}catch{h("configuration_unavailable")}a||(t=setTimeout(()=>{Q()},15e3))}let W=()=>L();return{async start(){c||a||(c=!0,M=location.origin+location.pathname,H=Se(_e),P=n.session.subscribeIdentity(()=>{E++,N=!0,m=void 0,w.clear(),I(),L()}),S=new MutationObserver(L),S.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id"]}),document.addEventListener("click",Y,!0),document.addEventListener("visibilitychange",W),await Q())},refresh:Z,async retry(){m&&!a&&m.epoch===E&&await X(m)},destroy(){a=!0,x++,clearTimeout(t),v?.abort(),S?.disconnect(),H?.(),P?.(),document.removeEventListener("click",Y,!0),document.removeEventListener("visibilitychange",W),I(),l=void 0}}}async function en(...n){return(await import("./paywall-CSAGKPCP.js")).showPaywall(...n)}async function nn(...n){return(await import("./funnel-runtime-host-3YUGXD3Y.js")).showFunnelRun(...n)}async function tn(...n){return(await import("./content-PQJYLAGQ.js")).mountContent(...n)}async function rn(...n){return(await import("./content-PQJYLAGQ.js")).prepareContent(...n)}export{D as IndianaError,r as MerchantBridgeError,De as createBrowserFunnelCommandStorage,xe as createConfigurationSync,Te as createFeatureClient,Fe as createFunnelClient,Le as createFunnelPageExperiments,$ as createFunnelRunController,Ue as createIamFunnelEntries,Pe as createIndiana,He as createLocalFunnelClient,Ge as createMerchantBridge,Oe as createPaywallSession,Be as evaluateFunnelNode,Me as formatCouponDiscount,Ae as formatCouponMoney,Ne as formatCouponTerms,tn as mountContent,rn as prepareContent,nn as showFunnelRun,en as showPaywall};
1
+ import{a as ke,b as be}from"./chunk-LCLCG2I2.js";import{a as Oe,c as He}from"./chunk-VZVUZWP2.js";import{a as Fe}from"./chunk-JPV7F5XI.js";import{b as De,g as Pe,l as z,m as xe,n as Be,p as Le}from"./chunk-FYGXGMRB.js";import"./chunk-SBPTOOYB.js";import{F as Me,G as Ne,H as Te,Ka as Ee,La as ge,Ma as we,Qa as ve,i as oe,k as q,l as ae,m as ie,n as se,o as ce,p as de,q as ue,qa as ye,r as le,s as me,t as fe,u as pe,w as $,x as he,y as Ie}from"./chunk-Q64VNSPV.js";import{qa as P}from"./chunk-ACF2FBUB.js";import{c as _e}from"./chunk-CLXORAOK.js";import"./chunk-EARSGITJ.js";import{c as Se,d as Re}from"./chunk-XO42OH3M.js";import{a as L}from"./chunk-DSPLGTQI.js";import"./chunk-G56XGVMS.js";import"./chunk-GHJ65ILJ.js";import"./chunk-7DXL3LHT.js";import"./chunk-3PZ4Y6UD.js";import{z as j}from"zod";var r=class extends Error{constructor(u,B=0,I=!1,f="fix_request"){super(u);this.code=u;this.status=B;this.retryable=I;this.recovery=f;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function Ge(n,_){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let u=n.body?.getReader();if(!u)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let B=()=>{u.cancel().catch(()=>{})};_.addEventListener("abort",B,{once:!0});let I=0,f="",a=new TextDecoder("utf-8",{fatal:!0});try{for(_.throwIfAborted();;){let d=await u.read();if(_.throwIfAborted(),d.done)break;if(I+=d.value.byteLength,I>262144)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");f+=a.decode(d.value,{stream:!0})}return f+=a.decode(),JSON.parse(f)}catch(d){throw _.throwIfAborted(),d instanceof r?d:new r("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{_.removeEventListener("abort",B),await u.cancel().catch(()=>{}),u.releaseLock()}}function Ue(n){let _=ce.parse(n.origin),u=de.parse(n.manifest),B={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let o of["projectId","environmentId","environment"])if(u[o]!==n.scope[o])throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");let I=n.customerId===void 0?null:j.uuid().parse(n.customerId),f=0,a=null,d=null,F=new AbortController,k=n.fetch??globalThis.fetch;async function M(o,t,i,E,N){if(!u.capabilities.includes(o))throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let v=se[o];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(v.authority))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);let T=f,x=AbortSignal.any([F.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...E?[E]:[]]);x.throwIfAborted();let S=new Headers(await n.headers?.());if(x.throwIfAborted(),T!==f)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(S.get("authorization")??"")||S.has("X-Indiana-Bridge-Signature")||S.has("X-Indiana-Bridge-Key-Id"))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);S.set(ie,String(q)),S.set("Accept","application/json");let g=crypto.randomUUID();S.set("X-Request-Id",g),S.set("Content-Type","application/json");let p=await k(_+ae,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:S,signal:x,body:JSON.stringify({bridgeVersion:q,requestId:g,command:v.command,scope:B,data:N??(i===void 0?{}:{operationId:i})})}),D=await Ge(p,x);if(x.throwIfAborted(),T!==f)throw new DOMException("Merchant identity changed","AbortError");if(!p.ok){let y=Ie.safeParse(D);throw!y.success||y.data.scope.projectId!==n.scope.projectId||y.data.scope.environment!==n.scope.environment||y.data.scope.environmentId!==n.scope.environmentId||y.data.requestId!==g||y.data.command!==v.command?new r("MERCHANT_BRIDGE_INVALID_RESPONSE",p.status):new r(y.data.error.code,p.status,y.data.error.retryable,y.data.error.recovery)}let R=ue(j.unknown()).safeParse(D);if(!R.success||R.data.scope.projectId!==n.scope.projectId||R.data.scope.environment!==n.scope.environment||R.data.scope.environmentId!==n.scope.environmentId||R.data.requestId!==g||R.data.command!==v.command)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",p.status);let l=t.safeParse(R.data.data);if(!l.success)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",p.status);return l.data}function w(){if(!I)throw new r("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return I}async function H(o,t,i,E){let N=w(),v=pe.parse({operationId:i,customerId:N}),T=await M(o,t,v.operationId,E,v);if(T.customerId!==N||T.operationId!==v.operationId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return T}return{async readPresentation(o){let t=await M("presentation",me,void 0,o);if(d!==null&&d!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t.presentation&&I!==null&&t.presentation.customerId!==I)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return d=t.nativeUserId,a=t.presentation,t},async createSession(o){let t=await M("session",le,void 0,o);if(d!==null&&d!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(I!==null&&I!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(a&&a.customerId!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return I=t.session.customerId,d=t.nativeUserId,t.session},async reportPresentation(o,t){let i=w(),E=fe.parse(o);if(!a||a.customerId!==i||a.decisionId!==E.decisionId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return M("presentation_events",j.strictObject({queued:j.literal(!0)}),void 0,t,E)},async readCustomerCommerce(o){let t=w(),i=await M("customer_commerce",he,void 0,o);if(i.customerId!==t)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i},async executePurchase(o,t){let i=await H("purchases",$,o,t);if(i.type!=="purchase")throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");return i},readOperation:(o,t)=>H("operation_status",oe,o,t),async executeSubscriptionChange(o,t){let i=await H("subscription_changes",$,o,t);if(i.type!=="subscription_change")throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");return i},reset(){f++,F.abort(),F=new AbortController,I=null,a=null,d=null}}}function je(n){let _=Se(n.baseUrl),u=n.scope,B=ve(n),I=n.fetch??globalThis.fetch.bind(globalThis),f,a=!1,d=!1,F=0,k=0,M="",w=0,H=0,o=0,t,i=!1,E,N=!0,v,T,x,S,g,p,D=e=>{p===e&&(p=void 0)},R=new Set,l=(e,m)=>L(n.onStatus,e,m);function y(){let e=g;g=void 0,e?.host.destroy(),e?.client.reset()}let K=()=>Date.now()<H&&performance.now()<o;function J(e){if(e.target.release!==n.appManifestRelease||!K())return!1;try{return _e(e.target.render,document,location.pathname,()=>{})}catch{return l("incompatible",e.id),!1}}function V(e){return!a&&e.epoch===w&&e.visit===k&&document.visibilityState!=="hidden"}async function X(e){if(p||g){l("in_progress",e.id);return}if(!n.session.peek()){l("identity_required",e.id);return}let m={command:ge.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:w,visit:k};p=m,await Z(m)}async function Z(e){if(e.dispatching)return;e.dispatching=!0;let m,b=!1;async function h(s){if(e.epoch!==w)return;let c=s.view;c&&["running","waiting"].includes(c.status)&&await s.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:c.nodeId,visit:c.visit,revision:c.revision})}try{l("starting",e.command.entryId);let s=await B.request("funnels",e.command),c=we.safeParse(s);if(c.success){if(c.data.scope.projectId!==u.projectId||c.data.scope.environment!==u.environment)throw new P("SCOPE_MISMATCH","Entry scope changed");e.epoch===w&&l(c.data.reason,e.command.entryId),D(e);return}let A=ye.parse(s);if(!A.runToken||A.scope.projectId!==u.projectId||A.scope.environment!==u.environment||A.run.source.type!=="funnel"||A.run.source.id!==e.command.funnelId||A.run.source.versionId!==e.command.versionId)throw new P("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==w){D(e),l("identity_changed",e.command.entryId);return}let C=z({...n,runToken:A.runToken,funnelId:e.command.funnelId});m=C,await C.get();let U=C.view;if(!U||U.id!==A.run.id||U.source.type!=="funnel"||U.source.id!==e.command.funnelId||U.source.versionId!==e.command.versionId)throw new P("INVALID_RESPONSE","Entry Run version changed");if(!V(e)){await h(C),l("left_screen",e.command.entryId),D(e);return}let ne=!1,te=!1,re=await be(n.container,{...n.host,client:C,appManifestRelease:n.appManifestRelease,onDismiss(O){ne=!0,g?.client===C&&(g=void 0,C.reset(),O&&O.status!=="completed"&&l("run_ended",e.command.entryId)),L(n.host?.onDismiss,O)},onComplete(O){te=!0,g?.client===C&&y(),L(n.host?.onComplete,O)},onError(O){L(n.host?.onError,O),g?.client===C&&O instanceof P&&O.code==="FORBIDDEN"&&(y(),l("run_ended",e.command.entryId))}});if(!V(e)||ne||te){re.destroy(),V(e)||await h(C),D(e);return}g={host:re,client:C},b=!0,D(e),l("started",e.command.entryId)}catch(s){!m&&s instanceof P&&s.status!==void 0&&s.status>=400&&s.status<500&&!s.retryable&&D(e),e.epoch===w&&!a&&(l("start_failed",e.command.entryId),L(n.host?.onError,s))}finally{b||m?.reset(),e.dispatching=!1}}function Ce(){if(i=!1,!(a||!d||!K()||document.visibilityState==="hidden")){N=!1;for(let e of f?.entries??[])if(!(e.event!=="screen_enter"||R.has(`${e.funnelId}:${e.id}`)||!J(e))){if(!n.session.peek()){l("identity_required",e.id);continue}R.add(`${e.funnelId}:${e.id}`),X(e);break}}}let G=()=>{!i&&!a&&(i=!0,queueMicrotask(Ce))};function Ae(){let e=location.origin+location.pathname;e!==M&&(M=e,k++,N=!0,R.clear(),G())}function Y(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let m=e.target;if(!(m instanceof Element)||m.closest("[data-indiana-funnel]"))return;let b=m.closest("button,a,input");if(!(!b||b.matches(":disabled,[aria-disabled='true']")||b.closest("[hidden],[inert],[aria-hidden='true']")))for(let h of f?.entries??[]){let s=h.target.button;if(h.event!=="button_click"||!s||!J(h))continue;let c=document.querySelectorAll(s.selector);if(!(c.length!==1||c[0]!==b)){X(h);break}}}async function Q(){if(a)return;if(E)return E;let e=++F;v=new AbortController;let m=(async()=>{let b=await I(`${_}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",signal:v.signal});if(!b.ok)throw new P("SERVICE_UNAVAILABLE","Funnel entries unavailable",b.status);let h=Ee.parse(await b.json()),s=Date.parse(h.validatedAt),c=Date.parse(h.validUntil);if(h.scope.projectId!==u.projectId||h.scope.environment!==u.environment||h.scope.environmentId!==n.environmentId||h.release!==n.appManifestRelease||c<=Date.now()||s>Date.now()+5e3||c-s>6e4||c<=s)throw new P("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(a||e!==F)return;let A=f===void 0;f=h,H=c,o=performance.now()+Math.min(c-Date.now(),6e4),(A||N)&&G()})();E=m;try{await m}finally{E===m&&(E=void 0)}}async function W(){try{await Q()}catch{l("configuration_unavailable")}a||(t=setTimeout(()=>{W()},15e3))}let ee=()=>G();return{async start(){d||a||(d=!0,M=location.origin+location.pathname,T=Re(Ae),x=n.session.subscribeIdentity(()=>{w++,N=!0,p=void 0,R.clear(),y(),G()}),S=new MutationObserver(G),S.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id"]}),document.addEventListener("click",Y,!0),document.addEventListener("visibilitychange",ee),await W())},refresh:Q,async retry(){p&&!a&&p.epoch===w&&await Z(p)},destroy(){a=!0,F++,clearTimeout(t),v?.abort(),S?.disconnect(),T?.(),x?.(),document.removeEventListener("click",Y,!0),document.removeEventListener("visibilitychange",ee),y(),f=void 0}}}async function nn(...n){return(await import("./paywall-527RPFAX.js")).showPaywall(...n)}async function tn(...n){return(await import("./funnel-runtime-host-BJZUVJAI.js")).showFunnelRun(...n)}async function rn(...n){return(await import("./content-QM75T7JO.js")).mountContent(...n)}async function on(...n){return(await import("./content-QM75T7JO.js")).prepareContent(...n)}export{P as IndianaError,r as MerchantBridgeError,Pe as createBrowserFunnelCommandStorage,Be as createConfigurationSync,De as createFeatureClient,He as createFunnelClient,ke as createFunnelPageExperiments,z as createFunnelRunController,je as createIamFunnelEntries,Oe as createIndiana,Le as createLocalFunnelClient,Ue as createMerchantBridge,xe as createPaywallSession,Fe as evaluateFunnelNode,Ne as formatCouponDiscount,Me as formatCouponMoney,Te as formatCouponTerms,rn as mountContent,on as prepareContent,tn as showFunnelRun,nn as showPaywall};