@tinkerlandai/longplay-sdk 0.10.19 → 0.10.20

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 (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +6 -2
  3. package/README.zh-CN.md +4 -2
  4. package/dist/{ai-usage-DPGx5otD.d.ts → ai-usage-wsrO7M2I.d.ts} +1 -1
  5. package/dist/{api-G8EA_ueL.d.ts → api-BDUQ1udV.d.ts} +54 -5
  6. package/dist/{chunk-A7U4Z6EH.js → chunk-327BKZ6Q.js} +1 -1
  7. package/dist/chunk-5QS6C4AI.js +6 -0
  8. package/dist/chunk-6WFCEV3R.js +1 -0
  9. package/dist/{chunk-CCRBXW4M.js → chunk-BO5DJEMS.js} +1 -1
  10. package/dist/{chunk-YNMSSQQY.js → chunk-CRIFRDSD.js} +1 -1
  11. package/dist/{chunk-W2Z3UVW3.js → chunk-E6GGMHIY.js} +1 -1
  12. package/dist/{chunk-XXBN76NP.js → chunk-LE4UIZGR.js} +1 -1
  13. package/dist/chunk-P3EOONST.js +1 -0
  14. package/dist/chunk-S4LVODTE.js +1 -0
  15. package/dist/{chunk-LNSFRQ6G.js → chunk-SHEGSRUV.js} +1 -1
  16. package/dist/{content-E2OWWKDG.js → content-42ORME22.js} +1 -1
  17. package/dist/{funnel-local-client-DjvVzCfH.d.ts → funnel-local-client-DInl0SJb.d.ts} +5 -3
  18. package/dist/{funnel-process-client-bO9Wfumi.d.ts → funnel-process-client-DRztj2Cb.d.ts} +4 -2
  19. package/dist/funnel-runtime-host-FG4BOC3T.js +1 -0
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.js +1 -1
  22. package/dist/native-shell.js +1 -1
  23. package/dist/openrouter.d.ts +2 -2
  24. package/dist/openrouter.js +1 -1
  25. package/dist/page.js +1 -1
  26. package/dist/{paywall-OUIB7SVI.js → paywall-GVZTDHXI.js} +1 -1
  27. package/dist/react-native.d.ts +5 -5
  28. package/dist/react-native.js +1 -1
  29. package/dist/server.d.ts +4 -4
  30. package/dist/server.js +1 -1
  31. package/dist/visual.js +1 -1
  32. package/package.json +1 -1
  33. package/dist/chunk-2JBNOE2D.js +0 -1
  34. package/dist/chunk-5OD42XQS.js +0 -1
  35. package/dist/chunk-DVKZLOS7.js +0 -1
  36. package/dist/chunk-GSFNAB3W.js +0 -6
  37. package/dist/funnel-runtime-host-FOM4Z7ZK.js +0 -1
@@ -0,0 +1 @@
1
+ import{a as p,b as ne,c as j,d as re,n as B,q as ie}from"./chunk-6WFCEV3R.js";import{b as te}from"./chunk-CRIFRDSD.js";import{a as o}from"./chunk-KHIQQNTR.js";import{a as J}from"./chunk-DSPLGTQI.js";import{Da as c,Fa as G,Qa as ee,_ as $,a as K,b as Q,c as W,d as M,e as H,f as X,ia as Z,q as L}from"./chunk-5QS6C4AI.js";import{a as Y}from"./chunk-4SWGHICJ.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new o("INVALID_STATE","Installation sequence exhausted");return t+1},ve=async t=>[...new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(t,e=>e.charCodeAt(0))))].map(e=>e.toString(16).padStart(2,"0")).join("");function F(t,e){return t.transaction(n=>{if(!Number.isSafeInteger(n.identitySeq)||n.identitySeq<0||!Number.isSafeInteger(n.addressSeq)||n.addressSeq<0||n.detachSeq!==null&&(!Number.isSafeInteger(n.detachSeq)||n.detachSeq<1||n.detachSeq>n.identitySeq))throw new o("INVALID_STATE","Installation journal is invalid");return e({...n})})}function se(t,e,n){let r=null,s=0,a=0,l=0,y=Promise.resolve(),h=!1;if(t&&(!n||Y.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new o("SCOPE_MISMATCH","Push installation belongs to another scope");let f=()=>{if(h)throw new o("CLOSED","SDK client was destroyed");if(!t)throw new o("NOT_CONFIGURED","Configure this client's native Push host first");return t},S=i=>{if(i!==s)throw new o("IDENTITY_CHANGED","Identity changed during Push operation")};async function D(i){let d=f();if(!d.sha256&&!globalThis.crypto?.subtle)throw new o("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=d.sha256?await d.sha256(Uint8Array.from(i,O=>O.charCodeAt(0))):await ve(i);if(!/^[a-f0-9]{64}$/.test(u))throw new o("INVALID_STATE","Push credential digest is invalid");return u}function m(i){let d=H.parse(i);if(d.installationId.toLowerCase()!==f().installationId.toLowerCase())throw new o("INVALID_RESPONSE","Push response belongs to another installation");return d}async function C(i,d){let u=f(),O={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...d},T=await u.sign(X(i,u.scope,O));return{...O,signature:T}}let I=(i,d,u)=>e.requestWithCredential?e.requestWithCredential(i,d,u):e.request(i,d);async function E(){let i=f(),d=s,u=r?await(e.session?.access()??r):null,O=F(i,w=>w),T;if(O.detachSeq!==null){let w=O.detachSeq,x=K.parse(await C("detach",{sequence:w,platform:i.platform}));try{let N=await e.request("push/installations/detach",{...i.scope,...x},"POST",{installationDetach:!0});if(!N||typeof N!="object"||!("installation"in N))throw new o("INVALID_RESPONSE","Push detach acknowledgement is invalid");let _=m(N.installation);if(_.bound||_.identitySeq!==w)throw new o("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(N){if(N instanceof o&&N.status===404)T=N;else if(!(N instanceof o)||N.status!==412)throw N}T||F(i,N=>({...N,detachSeq:N.detachSeq===w?null:N.detachSeq}))}if(S(d),!u){if(T)throw T;return null}let A=c.bindPushInstallation,k=A.request.parse(await C("bind",{sequence:l,platform:i.platform,credentialDigest:await D(u)}));S(d);let q=A.response.parse(await I(A.path,k,u));S(d);let R=m(q.installation);if(!R.bound||R.identitySeq!==l)throw new o("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return T&&O.detachSeq!==null&&l>O.detachSeq&&F(i,w=>({...w,detachSeq:w.detachSeq===O.detachSeq?null:w.detachSeq})),R}async function v(){f();let i=s,d=r?await(e.session?.access()??r):null;if(!d)throw new o("NOT_IDENTIFIED","Identify before reading this installation");let u=c.readPushInstallation,O=u.request.parse(await C("read",{credentialDigest:await D(d)}));S(i);let T=u.response.parse(await I(u.path,O,d));return S(i),m(T.installation)}function g(i=E){let d=y.catch(()=>{}).then(i);return y=d,d.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),d}async function P(i,d,u){let O=f(),T=d.identity,A=d.observation,k=r?await(e.session?.access()??r):null;if(S(T),A!==a)throw new o("INVALID_STATE","Push observation changed during recovery");if(!k)throw new o("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new o("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await g(async()=>{if(S(T),await E(),S(T),A!==a)throw new o("INVALID_STATE","Push observation changed during recovery");let q=F(O,_=>u?_:{..._,addressSeq:U(_.addressSeq)}),w=await C(u?"recovery_confirm":"recovery_request",{...i,sequence:q.addressSeq,credentialDigest:await D(k),...u?{challenge:u}:{}}),x=u?W.parse(w):Q.parse(w);if(S(T),A!==a)throw new o("INVALID_STATE","Push observation changed during recovery");let N=await I(`push/installations/recovery/${u?"confirm":"request"}`,x,k);if(S(T),A!==a||F(O,_=>_).addressSeq!==q.addressSeq)throw new o("INVALID_STATE","Push observation changed during recovery");if(u){let _=c.updatePushAddress.response.parse(N),V=m(_.installation);if(!V.bound||V.identitySeq!==l||V.addressSeq!==q.addressSeq||V.connectionId!==i.connectionId||V.addressStatus!=="active")throw new o("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return V}if(!N||typeof N!="object"||!("recovery"in N))throw new o("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return M.parse(N.recovery)})}return{recoveryObserver(){f();let i={identity:s,observation:++a};return{async request(d){return M.parse(await P(d,i))},async confirm(d,u){return H.parse(await P(u,i,d))}}},identify(i){if(!t)return;l=F(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,s++,a++},reset(){if(t)try{F(t,i=>{let d=U(i.identitySeq);return{...i,identitySeq:d,detachSeq:d}})}finally{r=null,s++,a++}},start(){t&&!h&&g()},destroy(){h=!0,r=null,s++,a++},async sync(){return await g()},read:v,async recover(){let i=f(),d=s,u=l;return a++,await g(async()=>{S(d);let O=await v();return S(d),l=F(i,A=>{if(A.identitySeq!==u)throw new o("IDENTITY_CHANGED","A newer installation intent exists");return{...A,identitySeq:U(Math.max(A.identitySeq,O.identitySeq)),addressSeq:Math.max(A.addressSeq,O.addressSeq)}}).identitySeq,await E()})},tokenObserver(){f();let i=++a,d=s;return async u=>{if(i!==a||d!==s)return null;let O=f(),T=r?await(e.session?.access()??r):null;if(!T)throw new o("NOT_IDENTIFIED","Identify before registering a Push token");if(await g(),S(d),i!==a)return null;let A=F(O,w=>({...w,addressSeq:U(w.addressSeq)})),k=c.updatePushAddress,q=k.request.parse(await C("address",{...u,sequence:A.addressSeq,credentialDigest:await D(T)}));if(S(d),i!==a)return null;let R=await I(k.path,q,T);return S(d),i!==a||F(O,w=>w).addressSeq!==A.addressSeq?null:m(k.response.parse(R).installation)}}}}function oe(t,e){let n={async preference(r){let s=c.readMessagingPreference;return(await p(t,s,{channel:r})).preference},async setPreference(r){let s=c.setMessagingPreference;return(await p(t,s,r)).preference}};return{messaging:n,push:{sync:e.sync,read:e.read,recover:e.recover,tokenObserver:e.tokenObserver,recoveryObserver:e.recoveryObserver,async preference(){return n.preference("push")},async setPreference(r){return n.setPreference({...r,channel:"push"})}}}}function ae(t,e,n={}){let r=!1;function s(){if(r)throw new o("CLOSED","SDK client was destroyed")}let a=new Set,l=h=>{for(let f of a)try{f(h)}catch{}},y=t.session.subscribeIdentity(()=>{l(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:s,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(h){return s(),a.add(h),()=>{a.delete(h)}},identify(h){s();let f=typeof h=="string"?h:h.accessToken;if(!L.test(f))throw new o("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(f),t.identify(h)},reset(){if(!r)try{n.beforeReset?.()}finally{t.reset()}},destroy(){if(!r){r=!0,y(),a.clear();try{n.beforeDestroy?.(),e()}finally{t.dispose()}}}}}}function b(t){if(t!==null&&typeof t=="object"&&"customerId"in t)throw new o("INVALID_REQUEST","Customer requests use the verified session identity")}var Ae={...c.readHoldings,request:c.readHoldings.request.omit({customerId:!0})};function ce(t){return{async checkEntitlement(e){b(e);let n=c.checkEntitlement,r=n.request.parse(e),s=await p(t,n,r);return ne(r.requirement,s.check,void 0,s.scope),s},async readHoldings(e={}){return p(t,Ae,e)}}}function ue(t){return{async readLedger(e){let n=c.readLedger;return p(t,n,{query:e})},async readCreditStatement(e){b(e);let n=c.readCreditStatement;return p(t,n,e)},async quoteBalance(e){b(e);let n=c.quoteBalance;return p(t,n,{command:e})}}}function de(t){return{async setupPayment(e){b(e);let n=c.setupPayment;return p(t,n,e)},async readPaymentSetup(e){b(e);let n=c.readPaymentSetup;return p(t,n,e)},async readBillingInvoice(e){b(e);let n=c.readBillingInvoice;return p(t,n,e)},async readBillingControls(e={}){b(e);let n=c.readBillingControls;return p(t,n,e)},async prepareBillingAuthorization(e){b(e);let n=c.prepareBillingAuthorization;return p(t,n,e)},async confirmBillingAuthorization(e){b(e);let n=c.confirmBillingAuthorization;return p(t,n,e)},async setBillingCoupons(e){b(e);let n=c.setBillingCoupons;return p(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){b(e);let n=c.revokeBillingAuthorization;return p(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){b(e);let n=c.listBillingInvoices;return p(t,n,e)},async confirmBillingAdjustment(e){b(e);let n=c.confirmBillingAdjustment;return p(t,n,e)}}}function pe(t){return{async previewUpdate(e){b(e);let n=c.previewUpdate;return p(t,n,e)},async update(e){b(e);let n=c.update;return p(t,n,e)},async readSubscriptionUpdate(e){b(e);let n=c.readSubscriptionUpdate;return p(t,n,e)},async restoreNativePurchase(e){b(e);let n=c.restoreNativePurchase;return p(t,n,e)},async previewAttach(e){b(e);let n=c.previewAttach;return p(t,n,e)},async attach(e){b(e);let n=c.attach;return p(t,n,e)},async readSubscriptionOperation(e){b(e);let n=c.readSubscriptionOperation;return p(t,n,e)}}}function le(t){return{async redeemReward(e){return b(e),(await p(t,c.redeemReward,{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return b(e),(await p(t,c.claimRewardProduct,e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return b(e),(await p(t,c.createReferralCode,{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){let r=await p(t,c.redeemCoupon,{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async claimCoupon(e,n=crypto.randomUUID()){let r=await p(t,c.grantOffer,{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await p(t,c.listOffers,{},{response:"Invalid offers response"})).offers}}}function fe(t){return{...ce(t),...ue(t),...de(t),...pe(t),...le(t)}}function me(t){return{async resolveContent(e){b(e);let n=c.resolveContent;return p(t,n,e)},async resolvePaywall(e){b(e);let n=c.resolvePaywall,r=n.request.parse(e),s=await p(t,n,r);return j(r,s.paywall.check,s.scope),s},async resolveOffering(e){b(e);let n=c.resolveOffering,r=n.request.parse(e),s=await p(t,n,r);return j(r,s.check,s.scope),s}}}var z=t=>new TextEncoder().encode(JSON.stringify(t)).length,ye=16384,be=5e3,Ee=6e4,Oe=5;function Se(t){return t instanceof o&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function Ie(t,e){let n=0,r,s=v=>{r={config:structuredClone(v),until:Date.now()+3e4}},a=[],l=null,y,h=0;function f(){if(!e())throw new o("NOT_IDENTIFIED","Call identify before using Features or events")}function S(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,C().catch(()=>{}).finally(S)},Math.min(be*2**h,Ee)),typeof y=="object"&&"unref"in y&&y.unref())}function D(v){if(f(),r&&Date.now()<r.until&&!$(r.config,v.kind))return;E();let g=c.trackEvents.request.parse({events:[{...v,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(z({events:[g]})>ye)throw new o("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new o("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(g)),S()}function m(v,g={},P={}){D({kind:"custom",name:v,properties:g,...P})}async function C(v=!1){if(f(),l)return l;let g=n,P=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},d=a.length;for(;d&&g===n;){let u=[],O=z({events:[]});for(let k of a.slice(0,Math.min(d,100))){let q=z(k)+(u.length?1:0);if(u.length&&O+q>ye)break;u.push(k),O+=q}let T=c.trackEvents,A;try{if(A=await p(t,T,{events:u},void 0,{keepalive:v}),g!==n)throw new o("IDENTITY_CHANGED","Event identity changed during delivery");if(A.inserted+A.duplicates+A.rejected+A.skipped!==u.length||A.rejections.length!==A.rejected)throw new o("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(k){throw g===n&&(h++,(Se(k)||h>=Oe)&&(a.splice(0,u.length),h=0)),k}h=0,s(A.analyticsConfig),a.splice(0,u.length),d-=u.length,i.inserted+=A.inserted,i.duplicates+=A.duplicates,i.rejected+=A.rejected,i.skipped+=A.skipped,i.rejections.push(...A.rejections)}return i})();l=P;try{return await P}finally{l===P&&(l=null)}}let I;function E(){if(I||typeof document>"u")return;let v=()=>{document.visibilityState==="hidden"&&e()&&a.length&&C(!0).catch(()=>{})};document.addEventListener("visibilitychange",v),I=()=>document.removeEventListener("visibilitychange",v)}return{rememberConfiguration:s,track:m,observe:D,flush:C,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],h=0,l=null},detachVisibility(){I?.(),I=void 0}}}function he(t){let e=t.merchandise;if(typeof t.merchandiseId=="string")return{internalId:t.merchandiseId};if(!(!e||typeof e!="object"||Array.isArray(e))){if(typeof e.internalId=="string")return{internalId:e.internalId};if(typeof e.externalId=="string")return{id:e.externalId};if(typeof e.id=="string")return{id:e.id}}}var Pe=new Set([...Z,"merchandiseId","merchandise"]);function Ce(t){let e=he(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!Pe.has(r))),...e?{merchandise:e}:{}}}function ge(t,e,n,r,s){if(s&&r&&(s.scope.projectId!==r.projectId||s.scope.environment!==r.environment))throw new o("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,l=new Set;function y(){if(!e())throw new o("NOT_IDENTIFIED","Call identify before using Features or events")}async function h(f={}){s||y();let S=a,D=!1,m=async()=>{if(D||S!==a)throw new o("IDENTITY_CHANGED","Feature identity changed");let q=c.getFeatures,R=s?{scope:{projectId:s.scope.projectId,environment:s.scope.environment},payload:await s.features()}:await p(t,q,{});if(S!==a)throw new o("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new o("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},C=await m(),I=!0,E,v=q=>{try{f.onError?.(q)}catch{}},g=(q,R)=>{try{let w=he(R);n.observe({...q,...w?{merchandise:w}:{}})}catch(w){v(w)}},P=re({assertUsable:s?.assertFeatures,scope:C.scope,attributes:f.attributes,onError:f.onError,load:async()=>I?(I=!1,C.payload):(await m()).payload,evaluateRemote:async q=>{if(S!==a)throw new o("IDENTITY_CHANGED","Feature identity changed");let R=c.evaluateFeatures,w=await p(t,R,{...q,attributes:Ce(q.attributes)});if(w.scope.projectId!==C.scope.projectId||w.scope.environment!==C.scope.environment)throw new o("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:w.generation,evaluatedAt:w.evaluatedAt,expiresAt:w.expiresAt,features:w.features,...w.merchandiseContext?{merchandiseContext:w.merchandiseContext}:{}}},onExperimentViewed:(q,R,w,x)=>g({kind:"experiment_exposure",generation:x,experimentId:q.key,variationId:R.key},w),onFeatureUsage:(q,R,w,x)=>g({kind:"feature_usage",generation:x,feature:q,value:R.value??null,source:R.source,ruleId:R.ruleId,...R.experimentResult?{variationId:R.experimentResult.key}:{}},w)}),i=P.refresh;function d(){clearTimeout(E),!s&&(D||S!==a||!P.expiresAt||(E=setTimeout(()=>{u().catch(v)},Math.min(2147483647,Math.max(1e3,Date.parse(P.expiresAt)-Date.now()))),typeof E=="object"&&"unref"in E&&E.unref()))}async function u(){try{return await i()}finally{d()}}let O=()=>{D||u().catch(v)},T=P.subscribe(d),A=s?.subscribe(()=>{!D&&s.fresh&&u().catch(v)});function k(){D||(D=!0,clearTimeout(E),typeof window<"u"&&window.removeEventListener("focus",O),T(),A?.(),P.reset(),l.delete(k))}l.add(k);try{await P.init(),(f.attributes?.merchandise||f.attributes?.merchandiseId)&&await P.refreshRemote()}catch(q){throw k(),q}return d(),!s&&typeof window<"u"&&window.addEventListener("focus",O),Object.assign(P,{refresh:u,destroy:k})}return{features:h,reset(f){a++,f();for(let S of l)S()}}}import{z as Te}from"zod";function we(t,e){let n="source"in e?{funnelId:e.source.id,funnelVersionId:e.source.versionId}:"versionId"in e?{funnelId:e.funnelId,funnelVersionId:e.versionId}:e,r=Te.object({funnelId:G.shape.id,funnelVersionId:G.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new o("INVALID_REQUEST","A valid Funnel source is required");let s=Object.freeze(r.data);function a(l){if("customerId"in l)throw new o("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in l&&l.funnelId!==void 0&&l.funnelId!==s.funnelId||"funnelVersionId"in l&&l.funnelVersionId!==void 0&&l.funnelVersionId!==s.funnelVersionId)throw new o("SCOPE_MISMATCH","The original Funnel source cannot change");return{...l,...s}}return{async claimCoupon(l,y=crypto.randomUUID()){let h=c.grantOffer,f=await p(t,h,a({couponId:l,requestId:y}));return{offer:f.offer,reason:f.reason}},async resolveOffering(l){let y=c.resolveOffering,h=y.request.parse(a(l)),f=await p(t,y,h);return j(h,f.check,f.scope),f},async resolvePaywall(l){let y=c.resolvePaywall,h=y.request.parse(a(l)),f=await p(t,y,h);return j(h,f.paywall.check,f.scope),f},async previewAttach(l){let y=c.previewAttach;return p(t,y,a(l))}}}function Ht(t){return qe(t)}function qe(t){let e=te(t),n=e.request,r;try{r=se(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let s=ae(e,()=>{l.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=Ie(n,s.isIdentified),l=ge(n,s.isIdentified,a,t.scope,t.configuration);return{session:e.session,...oe(n,r),...fe(n),...me(n),forFunnel(y){return s.assertActive(),we(n,y)},async features(y={}){return s.assertActive(),l.features(y)},track(y,h,f={}){return a.track(y,h,f)},flush(){return a.flush()},...s.methods}}function Qt(t){if(!L.test(t.customerToken))throw new o("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new o("INVALID_REQUEST","An explicit App and environment scope is required");let e=ie({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),s=B({...t,runToken:r.runToken});s.identify(t.customerToken);let a=r.run.instruction?.type==="evaluate_segment"?await s.get():r;return{...r,...a,controller:s}}}}function tn(t){if(!t.scope)throw new o("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new o("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,s=new Set,a=new Map,l=new Map;async function y(m){let C,I=new Promise((E,v)=>{C=setTimeout(()=>v(new o("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(m),I])}finally{clearTimeout(C)}}function h(m){throw m instanceof o&&(m.status===401||m.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),l.clear()),m}function f(m,C){if(C!==r)throw new o("IDENTITY_CHANGED","Process was detached during a request");let I=ee.parse(m);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new o("SCOPE_MISMATCH","Process response belongs to another App/environment");if(e&&(e.run.id!==I.run.id||e.run.source.versionId!==I.run.source.versionId||e.run.source.id!==I.run.source.id||e.run.runExpiresAt!==I.run.runExpiresAt||e.run.identity.startedAs!==I.run.identity.startedAs||e.run.identity.participantId!==I.run.identity.participantId||e.run.identity.binding&&I.run.identity.binding&&e.run.identity.binding.id!==I.run.identity.binding.id))throw new o("INVALID_RESPONSE","The process changed its Run or Customer binding");if(!e||I.run.revision>=e.run.revision){if(e?.run.identity.binding&&!I.run.identity.binding)throw new o("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let O of s)J(O,I.run);I.run.instruction?.type==="authentication_required"&&J(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&l.set(I.settlement.requestId,I.settlement.accepted);let{identity:E,instruction:v,...g}=I.run,{contract:P,settlement:i,...d}=I,u=i&&(({accepted:O,...T})=>T)(i);return{...d,run:{...g,authenticated:E.binding!==null,instruction:v?.type==="authentication_required"?null:v},...u?{settlement:u}:{}}}let S=m=>(a.has(m)||a.set(m,e?.run.identity.binding?.id??null),a.get(m));async function D(m){let C=r,I=e?.run.identity.binding?.id??null,E=g=>{if(I!==(e?.run.identity.binding?.id??null))throw g;return h(g)};if(m.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new o("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(m.release,m.usedReceiptIds)).catch(E)}let v;if(m.operation==="get"){let{operation:g,customerToken:P,...i}=m;v=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:S(i.settlementRequestId)}:{}})).catch(E)}else if(m.operation==="review")v=await y(()=>t.adapter.review(m.receiptId)).catch(E);else{if(m.operation==="start")throw new o("INVALID_REQUEST","Use process.open for entry");{let{customerToken:g,...P}=m;v=await y(()=>t.adapter.command(P,S(P.requestId))).catch(E)}}return f(v,C)}return{get view(){return e?.run??null},get controller(){return n},async open(m){let C=r,I=await y(()=>t.adapter.open(m)).catch(h);if(f(I,C),!n){n=B({...t,runToken:I.runToken,process:{request:D,binding:S,restore(g){for(let[P,i]of Object.entries(g))a.set(P,i)}}});let E=n,v=E.submit;E.submit=async g=>{try{return await v(g)}catch(P){if(!(P instanceof o)||P.reason!=="IDENTITY_CONTEXT_CHANGED"||g.operation!=="submit"||g.input.type!=="screen"||a.get(g.requestId)!==null)throw P;await E.settle?.(g.requestId),await E.get();let i=E.view;if(l.get(g.requestId)!==!1||!i||i.id!==e?.run.id||i.nodeId!==g.nodeId||i.visit!==g.visit||!e?.run.identity.binding)throw P;return v({...g,requestId:crypto.randomUUID(),revision:i.revision})}}}await n.get();for(let E of n.pendingCommands??[])a.has(E.requestId)&&a.get(E.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(E.requestId);return{run:e.run,controller:n}},async syncIdentity(){let m=r;f(await y(()=>t.adapter.syncIdentity()).catch(h),m),await n?.get();for(let C of n?.pendingCommands??[])a.has(C.requestId)&&a.get(C.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(C.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),l.clear(),await y(()=>t.adapter.detach())},forProcess(m){if(!e?.run.identity.binding)throw new o("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:m}},subscribe(m){return s.add(m),()=>{s.delete(m)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),l.clear(),s.clear()}}}export{Ht as a,qe as b,Qt as c,tn as d};
@@ -1 +1 @@
1
- import{a as u}from"./chunk-DSPLGTQI.js";import{kb as d}from"./chunk-GSFNAB3W.js";function m(e){if(!/^[A-Za-z0-9_-]{1,64}$/.test(e))throw new Error("Invalid device cookie name");let t="";for(let i of document.cookie.split(";"))if(i.trim().startsWith(`${e}=`))try{t=decodeURIComponent(i.trim().slice(e.length+1))}catch{}return/^[A-Za-z0-9_-]{8,128}$/.test(t)||(t=crypto.randomUUID(),document.cookie=`${e}=${encodeURIComponent(t)}; path=/; max-age=${400*24*3600}; SameSite=Lax`),t}function y(){try{let e=sessionStorage.getItem("indiana_sid");return e||(e=crypto.randomUUID(),sessionStorage.setItem("indiana_sid",e)),e}catch{return}}function g(e=d){let t=new URL(e);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(t.hostname))||t.username||t.password||t.search||t.hash)throw new Error("baseUrl must be an https origin without credentials");return t.origin}var o=new Set,s;function S(e){let t=()=>e();if(o.add(t),!s){let i=!0,a=history.pushState,p=history.replaceState,r=()=>{if(i)for(let n of[...o])o.has(n)&&u(n)},c=function(...n){a.apply(this,n),r()},h=function(...n){p.apply(this,n),r()};history.pushState=c,history.replaceState=h,addEventListener("popstate",r),addEventListener("hashchange",r),s=()=>{i=!1,history.pushState===c&&(history.pushState=a),history.replaceState===h&&(history.replaceState=p),removeEventListener("popstate",r),removeEventListener("hashchange",r)}}return()=>{o.delete(t)&&(o.size||(s?.(),s=void 0))}}export{m as a,y as b,g as c,S as d};
1
+ import{a as u}from"./chunk-DSPLGTQI.js";import{lb as d}from"./chunk-5QS6C4AI.js";function m(e){if(!/^[A-Za-z0-9_-]{1,64}$/.test(e))throw new Error("Invalid device cookie name");let t="";for(let i of document.cookie.split(";"))if(i.trim().startsWith(`${e}=`))try{t=decodeURIComponent(i.trim().slice(e.length+1))}catch{}return/^[A-Za-z0-9_-]{8,128}$/.test(t)||(t=crypto.randomUUID(),document.cookie=`${e}=${encodeURIComponent(t)}; path=/; max-age=${400*24*3600}; SameSite=Lax`),t}function y(){try{let e=sessionStorage.getItem("indiana_sid");return e||(e=crypto.randomUUID(),sessionStorage.setItem("indiana_sid",e)),e}catch{return}}function g(e=d){let t=new URL(e);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(t.hostname))||t.username||t.password||t.search||t.hash)throw new Error("baseUrl must be an https origin without credentials");return t.origin}var o=new Set,s;function S(e){let t=()=>e();if(o.add(t),!s){let i=!0,a=history.pushState,p=history.replaceState,r=()=>{if(i)for(let n of[...o])o.has(n)&&u(n)},c=function(...n){a.apply(this,n),r()},h=function(...n){p.apply(this,n),r()};history.pushState=c,history.replaceState=h,addEventListener("popstate",r),addEventListener("hashchange",r),s=()=>{i=!1,history.pushState===c&&(history.pushState=a),history.replaceState===h&&(history.replaceState=p),removeEventListener("popstate",r),removeEventListener("hashchange",r)}}return()=>{o.delete(t)&&(o.size||(s?.(),s=void 0))}}export{m as a,y as b,g as c,S as d};
@@ -1 +1 @@
1
- import{f as F,j as Q}from"./chunk-EDVR7FPD.js";import{b as B}from"./chunk-SSLZKIIU.js";import{c as z,d as _}from"./chunk-XIYNQHN7.js";import"./chunk-YNMSSQQY.js";import{a as d}from"./chunk-KHIQQNTR.js";import{a as v}from"./chunk-DSPLGTQI.js";import{Y as M}from"./chunk-GSFNAB3W.js";import{Ba as U,Ia as N,Ja as q,O as V,sa as P}from"./chunk-4SWGHICJ.js";import{z as p}from"zod";var x=new WeakMap;function W(r){let t={string:p.string(),number:p.number().finite(),boolean:p.boolean(),strings:p.array(p.string()),json:V}[r.type];return r.nullable?t.nullable():t}async function ie(r,t){return $(r,t,!1)}async function se(r,t){return $(r,t,!0)}async function $(r,t,w){t.signal?.throwIfAborted();let L=M.parse(t.content),o=L.document;if(x.has(r))throw new d("CONFLICT","Content is already mounted in this container");let f=p.record(p.string(),V).parse(t.inputs??{});if(Object.keys(f).length>40)throw new d("INVALID_REQUEST","Too many content inputs");for(let[e,s]of Object.entries(f))N.parse({[e]:s});if(Object.keys(f).some(e=>!Object.hasOwn(o.contract.inputs,e)))throw new d("INVALID_REQUEST","Undeclared content input");for(let[e,s]of Object.entries(o.contract.inputs))if(Object.hasOwn(f,e))W(s).parse(f[e]);else if(s.required)throw new d("INVALID_REQUEST",`Missing content input ${e}`);for(let e of Object.keys(o.contract.outputs))if(typeof t.actions[e]!="function")throw new d("INVALID_REQUEST",`Missing host handler for ${e}`);let J=q.parse(t.bindings??[]),c=r.ownerDocument,T,k=o.kind==="popup",n=k?c.createElement("dialog"):null,i=c.createElement("div");if(i.dataset.indianaContent=o.kind,i.setAttribute("aria-label",o.name),i.style.cssText="width:100%;min-width:0",n){n.setAttribute("aria-label",o.name);let e=o.screen.presentation;n.style.cssText="box-sizing:border-box;padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto",e.type==="modal"||e.type==="sheet"?(n.style.width=`${P[e.size]}px`,e.type==="sheet"&&(n.style.margin="auto auto 0")):n.style.width="100vw",n.append(i),r.append(n)}else r.append(i);let l=!1,C=!1,g=!1;w&&!n&&(i.style.width=`${r.getBoundingClientRect().width||c.defaultView?.innerWidth||800}px`);let G=w?F(n??i):()=>{},D,A,S=new Promise((e,s)=>{D=e,A=s});S.catch(()=>{});let u=null,E=structuredClone(o.screen);E.actions=E.actions.map(e=>e.type==="event"?{...e,close:!1}:e);let y;function m(){l||(l=!0,t.signal?.removeEventListener("abort",m),A(new Error("Content preparation cancelled")),y?.destroy(),n?.close(),n?.remove(),i.remove(),x.delete(r),n&&T?.())}let O=()=>{g&&(m(),v(t.onDismiss))};if(n){let e=c.createElement("button");e.type="button",e.textContent="\xD7",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"\u5173\u95ED":"Close"),_(e,o.screen.theme),e.addEventListener("click",O),n.prepend(e)}n?.addEventListener("cancel",e=>{e.preventDefault(),O()});async function H(){if(l||!g||C||!u)return;let e=u;C=!0,i.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),u=null}catch(s){v(t.onError,s)}finally{C=!1,l||i.removeAttribute("aria-busy")}}function R(){if(l)throw new d("CONFLICT","Content host has been destroyed");g||(T=B(c),G(),w&&!n&&(i.style.width="100%"),n&&(n.showModal(),z(n,o.screen.presentation.type)),g=!0)}try{w||R(),y=Q(i,{mode:"live",rendererUrl:t.rendererUrl,title:o.name,viewportHeight:o.kind==="page"?r.clientHeight||c.defaultView?.innerHeight||800:void 0,onRendered:a=>{a&&n?.setAttribute("aria-label",a),D()},onError:a=>{let I=new Error(a);A(I),v(t.onError,I)},onEscape:k?O:void 0,onAction:(a,I,K)=>{if(l||!g||C||u)return;let h=o.screen.actions.find(b=>b.id===a),j=o.contract.outputs[a];if(!(h?.type!=="event"||!j))try{let b=W(j).parse(Object.hasOwn(h.properties,"value")?h.properties.value:h.properties);u={requestId:crypto.randomUUID(),contentVersionId:L.id,actionId:a,event:h.event,value:b,selection:I??{},answers:K??{},requestedClose:h.close},H()}catch(b){v(t.onError,b)}}});let e={destroy:m,show:R,get pendingAction(){return u?structuredClone(u):null},retryAction:H,updateCapabilities:a=>y?.updateCapabilities(a)};x.set(r,e),t.signal?.addEventListener("abort",m,{once:!0}),t.signal?.aborted&&(m(),t.signal.throwIfAborted());let s=U(E,[t.locale,...c.defaultView?.navigator.languages??[]]);if(y.update(E,s,{capabilities:t.capabilities,serverInput:{bindings:J,answers:{},values:f}}),await Promise.race([y.ready,S]),w&&await S,l)throw new Error("Content preparation cancelled");return e}catch(e){throw m(),e}}export{ie as mountContent,se as prepareContent};
1
+ import{f as F,j as Q}from"./chunk-EDVR7FPD.js";import{b as B}from"./chunk-SSLZKIIU.js";import{c as z,d as _}from"./chunk-XIYNQHN7.js";import"./chunk-CRIFRDSD.js";import{a as d}from"./chunk-KHIQQNTR.js";import{a as v}from"./chunk-DSPLGTQI.js";import{Y as M}from"./chunk-5QS6C4AI.js";import{Ba as U,Ia as N,Ja as q,O as V,sa as P}from"./chunk-4SWGHICJ.js";import{z as p}from"zod";var x=new WeakMap;function W(r){let t={string:p.string(),number:p.number().finite(),boolean:p.boolean(),strings:p.array(p.string()),json:V}[r.type];return r.nullable?t.nullable():t}async function ie(r,t){return $(r,t,!1)}async function se(r,t){return $(r,t,!0)}async function $(r,t,w){t.signal?.throwIfAborted();let L=M.parse(t.content),o=L.document;if(x.has(r))throw new d("CONFLICT","Content is already mounted in this container");let f=p.record(p.string(),V).parse(t.inputs??{});if(Object.keys(f).length>40)throw new d("INVALID_REQUEST","Too many content inputs");for(let[e,s]of Object.entries(f))N.parse({[e]:s});if(Object.keys(f).some(e=>!Object.hasOwn(o.contract.inputs,e)))throw new d("INVALID_REQUEST","Undeclared content input");for(let[e,s]of Object.entries(o.contract.inputs))if(Object.hasOwn(f,e))W(s).parse(f[e]);else if(s.required)throw new d("INVALID_REQUEST",`Missing content input ${e}`);for(let e of Object.keys(o.contract.outputs))if(typeof t.actions[e]!="function")throw new d("INVALID_REQUEST",`Missing host handler for ${e}`);let J=q.parse(t.bindings??[]),c=r.ownerDocument,T,k=o.kind==="popup",n=k?c.createElement("dialog"):null,i=c.createElement("div");if(i.dataset.indianaContent=o.kind,i.setAttribute("aria-label",o.name),i.style.cssText="width:100%;min-width:0",n){n.setAttribute("aria-label",o.name);let e=o.screen.presentation;n.style.cssText="box-sizing:border-box;padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto",e.type==="modal"||e.type==="sheet"?(n.style.width=`${P[e.size]}px`,e.type==="sheet"&&(n.style.margin="auto auto 0")):n.style.width="100vw",n.append(i),r.append(n)}else r.append(i);let l=!1,C=!1,g=!1;w&&!n&&(i.style.width=`${r.getBoundingClientRect().width||c.defaultView?.innerWidth||800}px`);let G=w?F(n??i):()=>{},D,A,S=new Promise((e,s)=>{D=e,A=s});S.catch(()=>{});let u=null,E=structuredClone(o.screen);E.actions=E.actions.map(e=>e.type==="event"?{...e,close:!1}:e);let y;function m(){l||(l=!0,t.signal?.removeEventListener("abort",m),A(new Error("Content preparation cancelled")),y?.destroy(),n?.close(),n?.remove(),i.remove(),x.delete(r),n&&T?.())}let O=()=>{g&&(m(),v(t.onDismiss))};if(n){let e=c.createElement("button");e.type="button",e.textContent="\xD7",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"\u5173\u95ED":"Close"),_(e,o.screen.theme),e.addEventListener("click",O),n.prepend(e)}n?.addEventListener("cancel",e=>{e.preventDefault(),O()});async function H(){if(l||!g||C||!u)return;let e=u;C=!0,i.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),u=null}catch(s){v(t.onError,s)}finally{C=!1,l||i.removeAttribute("aria-busy")}}function R(){if(l)throw new d("CONFLICT","Content host has been destroyed");g||(T=B(c),G(),w&&!n&&(i.style.width="100%"),n&&(n.showModal(),z(n,o.screen.presentation.type)),g=!0)}try{w||R(),y=Q(i,{mode:"live",rendererUrl:t.rendererUrl,title:o.name,viewportHeight:o.kind==="page"?r.clientHeight||c.defaultView?.innerHeight||800:void 0,onRendered:a=>{a&&n?.setAttribute("aria-label",a),D()},onError:a=>{let I=new Error(a);A(I),v(t.onError,I)},onEscape:k?O:void 0,onAction:(a,I,K)=>{if(l||!g||C||u)return;let h=o.screen.actions.find(b=>b.id===a),j=o.contract.outputs[a];if(!(h?.type!=="event"||!j))try{let b=W(j).parse(Object.hasOwn(h.properties,"value")?h.properties.value:h.properties);u={requestId:crypto.randomUUID(),contentVersionId:L.id,actionId:a,event:h.event,value:b,selection:I??{},answers:K??{},requestedClose:h.close},H()}catch(b){v(t.onError,b)}}});let e={destroy:m,show:R,get pendingAction(){return u?structuredClone(u):null},retryAction:H,updateCapabilities:a=>y?.updateCapabilities(a)};x.set(r,e),t.signal?.addEventListener("abort",m,{once:!0}),t.signal?.aborted&&(m(),t.signal.throwIfAborted());let s=U(E,[t.locale,...c.defaultView?.navigator.languages??[]]);if(y.update(E,s,{capabilities:t.capabilities,serverInput:{bindings:J,answers:{},values:f}}),await Promise.race([y.ready,S]),w&&await S,l)throw new Error("Content preparation cancelled");return e}catch(e){throw m(),e}}export{ie as mountContent,se as prepareContent};
@@ -1,6 +1,6 @@
1
1
  import * as zod from 'zod';
2
2
  import { z } from 'zod';
3
- import { I as InvoiceModeParams, a as InvoiceModeParamsInput, A as ApiInput } from './api-G8EA_ueL.js';
3
+ import { I as InvoiceModeParams, b as InvoiceModeParamsInput, A as ApiInput } from './api-BDUQ1udV.js';
4
4
  import { S as StackNode, a as ScreenSelection } from './screen-DRP7nsrQ.js';
5
5
  import { J as JsonValue, E as EvaluationContext, F as FeatureResult } from './growth-rules-B4YYy64R.js';
6
6
  import { a as ConfigurationSync } from './configuration-sync-C2jtm37f.js';
@@ -26456,11 +26456,13 @@ type FeatureClientOptions = {
26456
26456
  onError?: (error: unknown) => void;
26457
26457
  onFeatureUsage?: (...args: [
26458
26458
  ...Parameters<NonNullable<EvaluationContext["onFeatureUsage"]>>,
26459
- Record<string, JsonValue>
26459
+ Record<string, JsonValue>,
26460
+ string
26460
26461
  ]) => void;
26461
26462
  onExperimentViewed?: (...args: [
26462
26463
  ...Parameters<NonNullable<EvaluationContext["onExperimentViewed"]>>,
26463
- Record<string, JsonValue>
26464
+ Record<string, JsonValue>,
26465
+ string
26464
26466
  ]) => void;
26465
26467
  stickyBucketAssignmentDocs?: EvaluationContext["stickyBucketAssignmentDocs"];
26466
26468
  saveStickyBucketAssignmentDoc?: EvaluationContext["saveStickyBucketAssignmentDoc"];
@@ -1,7 +1,7 @@
1
1
  import * as zod from 'zod';
2
2
  import { z } from 'zod';
3
- import { h as FunnelRuntimeResponse, F as FunnelRunView, w as FunnelMutation, g as FunnelPurchaseRecovery, i as FunnelSegmentPrediction, x as PaywallDelivery, y as PaywallResolution, z as FunnelDataQueries, I as IndianaOptions, A as FunnelCommand, e as FeatureClientOptions, C as CustomerSession, R as RemoteFeatureResult, B as PushAddressObservation, D as FunnelStartInput, E as FunnelProcessOpenInput, G as FunnelProcessResponse, H as FunnelProcessMutation, c as FunnelProcessRunView } from './funnel-local-client-DjvVzCfH.js';
4
- import { I as InvoiceModeParams, A as ApiInput, O as OfferingItem } from './api-G8EA_ueL.js';
3
+ import { h as FunnelRuntimeResponse, F as FunnelRunView, w as FunnelMutation, g as FunnelPurchaseRecovery, i as FunnelSegmentPrediction, x as PaywallDelivery, y as PaywallResolution, z as FunnelDataQueries, I as IndianaOptions, A as FunnelCommand, e as FeatureClientOptions, C as CustomerSession, R as RemoteFeatureResult, B as PushAddressObservation, D as FunnelStartInput, E as FunnelProcessOpenInput, G as FunnelProcessResponse, H as FunnelProcessMutation, c as FunnelProcessRunView } from './funnel-local-client-DInl0SJb.js';
4
+ import { I as InvoiceModeParams, A as ApiInput, O as OfferingItem, a as ApiOutput } from './api-BDUQ1udV.js';
5
5
  import { O as Offer } from './coupon-Btz_KFKp.js';
6
6
  import { S as StackNode } from './screen-DRP7nsrQ.js';
7
7
  import { J as JsonValue, F as FeatureResult } from './growth-rules-B4YYy64R.js';
@@ -20441,6 +20441,7 @@ declare function createIndiana(options: IndianaOptions): {
20441
20441
  duplicates: number;
20442
20442
  rejected: number;
20443
20443
  skipped: number;
20444
+ rejections: ApiOutput<"trackEvents">["rejections"];
20444
20445
  }>;
20445
20446
  resolveContent(input: Omit<ApiInput<"resolveContent">, "customerId">): Promise<{
20446
20447
  requestId: string;
@@ -27344,6 +27345,7 @@ declare function createCustomerClient(options: IndianaOptions): {
27344
27345
  duplicates: number;
27345
27346
  rejected: number;
27346
27347
  skipped: number;
27348
+ rejections: ApiOutput<"trackEvents">["rejections"];
27347
27349
  }>;
27348
27350
  resolveContent(input: Omit<ApiInput<"resolveContent">, "customerId">): Promise<{
27349
27351
  requestId: string;
@@ -0,0 +1 @@
1
+ import{b as a}from"./chunk-E6GGMHIY.js";import"./chunk-XIYNQHN7.js";import"./chunk-FISFN5IY.js";import"./chunk-CRIFRDSD.js";import"./chunk-KHIQQNTR.js";import"./chunk-SLUA7ABW.js";import"./chunk-SHEGSRUV.js";import"./chunk-DSPLGTQI.js";import"./chunk-5QS6C4AI.js";import"./chunk-4SWGHICJ.js";export{a as showFunnelRun};
package/dist/index.d.ts CHANGED
@@ -2,16 +2,16 @@ import { z } from 'zod';
2
2
  import { S as ScreenAnswers, s as screenInputBindingsSchema, a as SurfaceData, C as CustomerDataIntent } from './customer-page-BV5EvCUY.js';
3
3
  import { J as JsonValue } from './growth-rules-B4YYy64R.js';
4
4
  import { S as StackNode, a as ScreenSelection } from './screen-DRP7nsrQ.js';
5
- import { P as PaywallSession, S as SubscriptionOperation, a as PaywallRecovery, F as FunnelRunView, b as FunnelCommandStorage, I as IndianaOptions, c as FunnelProcessRunView } from './funnel-local-client-DjvVzCfH.js';
6
- export { C as CustomerSession, d as FeatureClient, e as FeatureClientOptions, f as FunnelPendingEntry, g as FunnelPurchaseRecovery, h as FunnelRuntimeResponse, i as FunnelSegmentPrediction, L as LocalFunnelClient, j as LocalFunnelClientOptions, k as LongplayError, l as PaywallPurchaseInput, m as PaywallStartInput, n as PushHost, o as PushJournal, p as SessionCredentials, q as createFeatureClient, r as createLocalFunnelClient, s as createPaywallSession, t as getPaywallRecovery, u as preparePaywallFallback } from './funnel-local-client-DjvVzCfH.js';
7
- import { F as FunnelRunController, I as IamFunnelEntryDelivery, c as createFunnelProcess } from './funnel-process-client-bO9Wfumi.js';
8
- export { a as FunnelControllerResponse, b as FunnelProcessAdapter, d as FunnelProcessOptions, e as FunnelResourceSource, f as LongplayFeatureOptions, g as createFunnelClient, h as createFunnelRunController, i as createLongplay } from './funnel-process-client-bO9Wfumi.js';
5
+ import { P as PaywallSession, S as SubscriptionOperation, a as PaywallRecovery, F as FunnelRunView, b as FunnelCommandStorage, I as IndianaOptions, c as FunnelProcessRunView } from './funnel-local-client-DInl0SJb.js';
6
+ export { C as CustomerSession, d as FeatureClient, e as FeatureClientOptions, f as FunnelPendingEntry, g as FunnelPurchaseRecovery, h as FunnelRuntimeResponse, i as FunnelSegmentPrediction, L as LocalFunnelClient, j as LocalFunnelClientOptions, k as LongplayError, l as PaywallPurchaseInput, m as PaywallStartInput, n as PushHost, o as PushJournal, p as SessionCredentials, q as createFeatureClient, r as createLocalFunnelClient, s as createPaywallSession, t as getPaywallRecovery, u as preparePaywallFallback } from './funnel-local-client-DInl0SJb.js';
7
+ import { F as FunnelRunController, I as IamFunnelEntryDelivery, c as createFunnelProcess } from './funnel-process-client-DRztj2Cb.js';
8
+ export { a as FunnelControllerResponse, b as FunnelProcessAdapter, d as FunnelProcessOptions, e as FunnelResourceSource, f as LongplayFeatureOptions, g as createFunnelClient, h as createFunnelRunController, i as createLongplay } from './funnel-process-client-DRztj2Cb.js';
9
9
  import { E as EntitlementCheckResult, M as MerchantBridgeManifest } from './funnel-node-evaluation-D9FwkMa3.js';
10
10
  export { F as FunnelNodeEvaluationContext, e as evaluateFunnelNode } from './funnel-node-evaluation-D9FwkMa3.js';
11
11
  import { C as CouponInput } from './coupon-Btz_KFKp.js';
12
12
  export { O as Offer, a as OfferUnavailableReason } from './coupon-Btz_KFKp.js';
13
13
  export { C as ConfigurationStorage, a as ConfigurationSync, b as ConfigurationSyncOptions, c as createConfigurationSync } from './configuration-sync-C2jtm37f.js';
14
- import './api-G8EA_ueL.js';
14
+ import './api-BDUQ1udV.js';
15
15
  import 'zod/v4';
16
16
 
17
17
  /** Currency always comes from business data; locale only controls notation. No currency conversion. */
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as fn,b as Ie}from"./chunk-W2Z3UVW3.js";import"./chunk-XIYNQHN7.js";import{a as nn,c as dn,d as un}from"./chunk-5OD42XQS.js";import{a as cn}from"./chunk-DVKZLOS7.js";import{d as en,i as tn,n as be,o as an,p as sn,r as ln}from"./chunk-2JBNOE2D.js";import{g as rn,h as on}from"./chunk-FISFN5IY.js";import{b as $e}from"./chunk-YNMSSQQY.js";import{a as B}from"./chunk-KHIQQNTR.js";import{a as he,c as ie}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as pe,d as ye}from"./chunk-LNSFRQ6G.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-CCRBXW4M.js";import{A as ke,B as Be,C as He,D as Le,F as Ee,Fa as je,G as qe,H as Ue,Ia as Ge,Ja as fe,Ka as me,La as Ke,S as We,T as Ye,U as Qe,l as Ne,la as Ve,s as we,t as Pe,u as Te,v as Oe,x as De,y as Fe,z as xe}from"./chunk-GSFNAB3W.js";import"./chunk-4SWGHICJ.js";import{z as ge}from"zod";var f=class extends Error{constructor(p,D=0,E=!1,b="fix_request"){super(p);this.code=p;this.status=D;this.retryable=E;this.recovery=b;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function mn(n,T){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");let p=n.body?.getReader();if(!p)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");let D=()=>{p.cancel().catch(()=>{})};T.addEventListener("abort",D,{once:!0});let E=0,b="",r=new TextDecoder("utf-8",{fatal:!0});try{for(T.throwIfAborted();;){let i=await p.read();if(T.throwIfAborted(),i.done)break;if(E+=i.value.byteLength,E>262144)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");b+=r.decode(i.value,{stream:!0})}return b+=r.decode(),JSON.parse(b)}catch(i){throw T.throwIfAborted(),i instanceof f?i:new f("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{T.removeEventListener("abort",D),await p.cancel().catch(()=>{}),p.releaseLock()}}function pn(n){let T=De.parse(n.origin),p=Fe.parse(n.manifest),D={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let l of["projectId","environmentId","environment"])if(p[l]!==n.scope[l])throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");let E=n.customerId===void 0?null:ge.uuid().parse(n.customerId),b=0,r=null,i=null,y=new AbortController,m=n.fetch??globalThis.fetch;async function q(l,c,h,F,U){if(!p.capabilities.includes(l))throw new f("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let H=Oe[l];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(H.authority))throw new f("MERCHANT_BRIDGE_FORBIDDEN",403);let R=b,u=AbortSignal.any([y.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...F?[F]:[]]);u.throwIfAborted();let g=new Headers(await n.headers?.());if(u.throwIfAborted(),R!==b)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(g.get("authorization")??"")||g.has("X-Indiana-Bridge-Signature")||g.has("X-Indiana-Bridge-Key-Id"))throw new f("MERCHANT_BRIDGE_FORBIDDEN",403);g.set(Te,String(we)),g.set("Accept","application/json");let a=crypto.randomUUID();g.set("X-Request-Id",a),g.set("Content-Type","application/json");let L=await m(T+Pe,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:g,signal:u,body:JSON.stringify({bridgeVersion:we,requestId:a,command:H.command,scope:D,data:U??(h===void 0?{}:{operationId:h})})}),M=await mn(L,u);if(u.throwIfAborted(),R!==b)throw new DOMException("Merchant identity changed","AbortError");if(!L.ok){let s=Ue.safeParse(M);throw!s.success||s.data.scope.projectId!==n.scope.projectId||s.data.scope.environment!==n.scope.environment||s.data.scope.environmentId!==n.scope.environmentId||s.data.requestId!==a||s.data.command!==H.command?new f("MERCHANT_BRIDGE_INVALID_RESPONSE",L.status):new f(s.data.error.code,L.status,s.data.error.retryable,s.data.error.recovery)}let S=xe(ge.unknown()).safeParse(M);if(!S.success||S.data.scope.projectId!==n.scope.projectId||S.data.scope.environment!==n.scope.environment||S.data.scope.environmentId!==n.scope.environmentId||S.data.requestId!==a||S.data.command!==H.command)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE",L.status);let $=c.safeParse(S.data.data);if(!$.success)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE",L.status);return $.data}function A(){if(!E)throw new f("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return E}async function z(l,c,h,F){let U=A(),H=Le.parse({operationId:h,customerId:U}),R=await q(l,c,H.operationId,F,H);if(R.customerId!==U||R.operationId!==H.operationId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return R}return{async readPresentation(l){let c=await q("presentation",Be,void 0,l);if(i!==null&&i!==c.nativeUserId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(c.presentation&&E!==null&&c.presentation.customerId!==E)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=c.nativeUserId,r=c.presentation,c},async createSession(l){let c=await q("session",ke,void 0,l);if(i!==null&&i!==c.nativeUserId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(E!==null&&E!==c.session.customerId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(r&&r.customerId!==c.session.customerId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E=c.session.customerId,i=c.nativeUserId,c.session},async reportPresentation(l,c){let h=A(),F=He.parse(l);if(!r||r.customerId!==h||r.decisionId!==F.decisionId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return q("presentation_events",ge.strictObject({queued:ge.literal(!0)}),void 0,c,F)},async readCustomerCommerce(l){let c=A(),h=await q("customer_commerce",qe,void 0,l);if(h.customerId!==c)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return h},async executePurchase(l,c){let h=await z("purchases",Ee,l,c);if(h.type!=="purchase")throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");return h},readOperation:(l,c)=>z("operation_status",Ne,l,c),async executeSubscriptionChange(l,c){let h=await z("subscription_changes",Ee,l,c);if(h.type!=="subscription_change")throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");return h},reset(){b++,y.abort(),y=new AbortController,E=null,r=null,i=null}}}import{z as se}from"zod";var Je=se.strictObject({command:me,target:Ge,runId:se.uuid().optional(),expiresAt:se.iso.datetime({offset:!0}).optional()}).refine(n=>n.command.release===n.target.release),ze=se.strictObject({schemaVersion:se.literal(1),entries:se.array(Je).max(4e3)});function Xe(n){let T=!1,p=()=>{T||n.unavailable(),T=!0};function D(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function E(r){let i=D()?.getItem(r);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return ze.parse(JSON.parse(i)).entries}function b(r,i){let y=D();if(!y)return;if(!i.length)return y.removeItem(r);let m=JSON.stringify(ze.parse({schemaVersion:1,entries:i}));if(m.length>1048576)throw Error("Entry recovery is too large");y.setItem(r,m)}return{load(){try{let r=n.binding();if(!r||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(r);return{key:i,entries:E(i)}}catch{p();return}},retain(r,i){if(r)try{let y=Je.parse(i);b(r,[...E(r).filter(m=>m.command.funnelId!==y.command.funnelId),y])}catch{p()}},forget(r,i){if(r)try{b(r,E(r).filter(y=>y.command.requestId!==i))}catch{p()}}}}var ve=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function yn(n){let T=pe(n.baseUrl),p=n.scope,D=$e(n),E=n.fetch??globalThis.fetch.bind(globalThis),b,r=!1,i=!1,y=0,m=0,q="",A=0,z=0,l=0,c,h=!1,F,U=!0,H,R,u,g,a,L=-1,M,S=e=>{M===e&&(M=void 0,K())},$=new Set,s=(e,o)=>Z(n.onStatus,e,o),j=new Set,W=Xe({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[T,p.projectId,p.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>s("recovery_unavailable")}),J=e=>W.forget(e.storageKey,e.command.requestId);function re(e,o){o&&(e.runId=o.id,e.expiresAt=o.runExpiresAt),W.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt}})}function Y(){let e=a;a=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),K()}let t=()=>M!==void 0||a!==void 0&&!a.background;function w(e,o){if(a?.client!==e)return;re(a.recovery,o);let d=ve(o);a.slot.hidden=d,d!==a.background&&(a.background=d,d?s("run_background",a.entryId):L=m,K())}function N(e,o,d){let v=e.client.view;if(!o||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let _=Ve.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:o});D.requestWithCredential("funnels",_,e.runToken,{keepalive:d}).then(()=>J(e.recovery)).catch(()=>{})}let x=()=>{a&&N(a,n.session.peek(),!0)},G=()=>Date.now()<z&&performance.now()<l;function oe(e){if(e.target.release!==n.appManifestRelease||!G())return!1;try{return ie(e.target.render,document,location.pathname,()=>{})}catch{return s("incompatible",e.id),!1}}function ne(e){if(r||e.epoch!==A||e.visit!==m||document.visibilityState==="hidden")return!1;try{return ie(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function ce(e){if(t()){s("in_progress",e.id);return}if(!n.session.peek()){s("identity_required",e.id);return}let o=W.load(),d=o?.entries.find(_=>_.command.funnelId===e.funnelId&&(!_.expiresAt||Date.parse(_.expiresAt)>Date.now()));if(d){if(!X(d)){s("recovery_pending",e.id);return}let _={...d,storageKey:o.key,epoch:A,visit:m};j.add(_.command.requestId),M=_,await Q(_);return}let v={command:me.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:A,visit:m,target:e.target,storageKey:o?.key};j.add(v.command.requestId),M=v,await Q(v)}async function Q(e){if(e.dispatching)return;e.dispatching=!0;let o,d=!1,v=!1;async function _(C){if(e.epoch!==A)return;let O=C.view;if(!(e.storageKey&&O&&(ve(O)||O.paywall||O.pendingRequest))&&O&&["running","waiting"].includes(O.status))try{await C.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:O.nodeId,visit:O.visit,revision:O.revision}),J(e)}catch(I){if(!(I instanceof B&&I.code==="FORBIDDEN"))throw I}}try{re(e),s("starting",e.command.entryId);let C=await D.request("funnels",e.command),O=Ke.safeParse(C);if(O.success){if(O.data.scope.projectId!==p.projectId||O.data.scope.environment!==p.environment)throw new B("SCOPE_MISMATCH","Entry scope changed");e.epoch===A&&s(O.data.reason,e.command.entryId),J(e),S(e);return}let I=je.parse(C);if(!I.runToken||I.scope.projectId!==p.projectId||I.scope.environment!==p.environment||I.run.source.type!=="funnel"||I.run.source.id!==e.command.funnelId||I.run.source.versionId!==e.command.versionId||e.runId!==void 0&&I.run.id!==e.runId)throw new B("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==A){S(e),s("identity_changed",e.command.entryId);return}re(e,I.run);let P=be({...n,runToken:I.runToken,funnelId:e.command.funnelId});o=P,v=!0,await P.get(),v=!1;let V=P.view;if(!V||V.id!==I.run.id||V.source.type!=="funnel"||V.source.id!==e.command.funnelId||V.source.versionId!==e.command.versionId)throw new B("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(V.status)){J(e),S(e),s("run_ended",e.command.entryId);return}if(!ne(e)){await _(P),s("left_screen",e.command.entryId),S(e);return}let ue=!1,ae=!1;if(a&&!a.background){await _(P),s("in_progress",e.command.entryId),S(e);return}a&&Y();let ee=document.createElement("div");ee.hidden=ve(V),n.container.append(ee);let Me=await Ie(ee,{...n.host,client:P,appManifestRelease:n.appManifestRelease,onState(k){w(P,k),Z(n.host?.onState,k)},onDismiss(k){ue=!0,ee.remove(),k&&!["running","waiting"].includes(k.status)&&J(e),a?.client===P&&(a=void 0,P.reset(),K(),k&&k.status!=="completed"&&s("run_ended",e.command.entryId)),Z(n.host?.onDismiss,k)},onComplete(k){ae=!0,J(e),a?.client===P&&Y(),Z(n.host?.onComplete,k)},onError(k){Z(n.host?.onError,k),a?.client===P&&k instanceof B&&k.code==="FORBIDDEN"&&(J(e),Y(),s("run_ended",e.command.entryId))}}).catch(k=>{throw ee.remove(),k});if(!ne(e)||ue||ae){Me.destroy(),ee.remove(),ne(e)||await _(P),S(e);return}let le=ve(P.view??V);ee.hidden=le,a={host:Me,client:P,slot:ee,entryId:e.command.entryId,background:le,runToken:I.runToken,owner:n.session.peek(),recovery:e},le||(L=e.visit),d=!0,S(e),s("started",e.command.entryId),le&&s("run_background",e.command.entryId)}catch(C){C instanceof B&&(!o||v&&C.code==="FORBIDDEN")&&C.status!==void 0&&C.status>=400&&C.status<500&&!C.retryable&&(J(e),S(e)),e.epoch===A&&!r&&(s("start_failed",e.command.entryId),Z(n.host?.onError,C))}finally{d||o?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return ie(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function de(){if(t())return!1;let e=W.load();for(let o of e?.entries??[]){if(o.expiresAt&&Date.parse(o.expiresAt)<=Date.now()){W.forget(e.key,o.command.requestId);continue}if(o.command.requestId===a?.recovery.command.requestId||j.has(o.command.requestId)||!X(o))continue;j.add(o.command.requestId);let d={...o,storageKey:e.key,epoch:A,visit:m};return M=d,Q(d),!0}return!1}function te(){if(h=!1,r||!i||document.visibilityState==="hidden")return;Re();let e=a!==void 0&&!a.background;if(e&&(L=m),!de()){if(!G()){U=!0;return}U=!1;for(let o of b?.entries??[]){let d=`${o.funnelId}:${o.id}`;if(!(o.event!=="screen_enter"||$.has(d)||!oe(o))){if(!n.session.peek()){s("identity_required",o.id);continue}if(L===m){$.add(d),e&&s("in_progress",o.id);continue}if(M){s("in_progress",o.id);return}$.add(d),ce(o);break}}}}let K=()=>{!h&&!r&&(h=!0,queueMicrotask(te))};function Re(){let e=location.origin+location.pathname;return e===q?!1:(q=e,m++,U=!0,$.clear(),j.clear(),!0)}function Ze(){Re()&&K()}function Se(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let o=e.target;if(!(o instanceof Element)||o.closest("[data-indiana-funnel]"))return;let d=o.closest("button,a,input");if(!(!d||d.matches(":disabled,[aria-disabled='true']")||d.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of b?.entries??[]){let _=v.target.button;if(!(v.event!=="button_click"||!_||!oe(v))){try{let C=he(document);if(!d.matches(_.selector)||C(_.selector,d)!==1)continue}catch{s("incompatible",v.id);continue}ce(v);break}}}async function _e(){if(r)return;if(F)return F;let e=++y,o=new AbortController;H=o;let d,v=new Promise((O,I)=>{d=()=>I(new B("TIMEOUT","Funnel entry configuration read cancelled or timed out")),o.signal.addEventListener("abort",d,{once:!0})}),_=setTimeout(()=>o.abort(),n.timeoutMs??5e3),C=(async()=>{let O=async()=>{let ae=await E(`${T}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:o.signal});if(!ae.ok)throw new B("SERVICE_UNAVAILABLE","Funnel entries unavailable",ae.status);return fe.parse(await ae.json())},I=await Promise.race([O(),v]),P=Date.parse(I.validatedAt),V=Date.parse(I.validUntil);if(I.scope.projectId!==p.projectId||I.scope.environment!==p.environment||I.scope.environmentId!==n.environmentId||I.release!==n.appManifestRelease||V<=Date.now()||P>Date.now()+5e3||V-P>6e4||V<=P)throw new B("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(r||e!==y)return;let ue=b===void 0;b=I,z=V,l=performance.now()+Math.min(V-Date.now(),6e4),(ue||U)&&K()})();F=C;try{await C}finally{clearTimeout(_),o.signal.removeEventListener("abort",d),F===C&&(F=void 0)}}async function Ce(){try{await _e()}catch{r||s("configuration_unavailable")}r||(c=setTimeout(()=>{Ce()},15e3))}let Ae=()=>K();return{async start(){i||r||(i=!0,q=location.origin+location.pathname,R=ye(Ze),u=n.session.subscribeIdentity(()=>{A++,U=!0,M=void 0,$.clear(),L=-1,j.clear(),a&&N(a,a.owner,!1),Y(),K()}),g=new MutationObserver(K),g.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",Se,!0),document.addEventListener("visibilitychange",Ae),addEventListener("pagehide",x),await Ce())},refresh:_e,async retry(){M&&!r&&M.epoch===A&&await Q(M)},destroy(){r=!0,y++,clearTimeout(c),H?.abort(),g?.disconnect(),R?.(),u?.(),document.removeEventListener("click",Se,!0),document.removeEventListener("visibilitychange",Ae),removeEventListener("pagehide",x),x(),Y(),b=void 0}}}function hn(n){let T=pe(n.baseUrl),p=n.fetch??globalThis.fetch.bind(globalThis),D,E=0,b=0,r=!1,i=!1,y=0,m=0,q=-1,A=!1,z="",l,c,h,F,U,H=new Set,R,u,g,a=(t,w)=>Z(n.onStatus,t,w),L=()=>Date.now()<E&&performance.now()<b;function M(t){try{return L()&&t.target.release===n.appManifestRelease&&ie(t.target.render,document,location.pathname,()=>{})}catch{return a("incompatible",t.id),!1}}function S(){let t=g;g=void 0,t?.host.destroy(),t?.slot.remove()}async function $(t){if(t.dispatching)return;t.dispatching=!0;let w=y;try{let N=await t.process.open({operation:"entry_start",funnelId:t.entry.funnelId,versionId:t.entry.versionId,entryId:t.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});if(r||w!==y||u!==t)return;let x=document.createElement("div");n.container.append(x),q=m;let G=await Ie(x,{...n.host,client:N.controller,appManifestRelease:n.appManifestRelease,onDismiss(oe){g?.process===t.process&&(g=void 0,x.remove()),Z(n.host?.onDismiss,oe)}});if(r||w!==y||u!==t){G.destroy(),x.remove();return}g={entry:t.entry,process:t.process,host:G,slot:x},u=void 0,a("run_presented",t.entry.id)}catch(N){if(r||w!==y||u!==t)return;N instanceof B&&"result"in N?(u=void 0,t.process.destroy(),a("suppressed",t.entry.id),j()):a("entry_unavailable",t.entry.id)}finally{t.dispatching=!1}}function s(t){if(r||u||g||R||q===m||!M(t))return;let w=`${m}:${t.id}`;if(H.has(w))return;H.add(w);let N={entry:t,process:n.createProcess(t),visit:m};u=N,$(N)}function j(){A||r||(A=!0,queueMicrotask(()=>{if(A=!1,!(r||document.visibilityState==="hidden"||!L()||u||g||R||q===m)){for(let t of D?.entries??[])if(t.event==="screen_enter"&&M(t)){s(t);break}}}))}function W(t){if(!t.isTrusted||t.defaultPrevented||!(t.target instanceof Element)||u||g||R||q===m)return;let w=he(document,()=>{});for(let N of D?.entries??[]){let x=N.target.button;if(N.event!=="button_click"||!x||!M(N))continue;let G=t.target.closest(x.selector);if(!(!G||G.tagName.toLowerCase()!==x.tag||w(x.selector)!==1||G.matches(":disabled")||G.closest('[inert],[hidden],[aria-hidden="true"]'))){s(N);break}}}let J=()=>{let t=location.origin+location.pathname;t!==z&&(z=t,m++,H.clear(),j())};async function re(){if(r)return;if(h)return h;let t=y,w=new AbortController;c=w;let N,x=new Promise((ce,Q)=>{N=Q}),G=()=>N(new B("TIMEOUT","Funnel entry read cancelled"));w.signal.addEventListener("abort",G,{once:!0});let oe=setTimeout(()=>w.abort(),n.timeoutMs??5e3),ne=(async()=>{let ce=encodeURIComponent(JSON.stringify(["funnel-process/1"])),Q=async()=>{let K=await p(`${T}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ce}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:w.signal});if(!K.ok)throw new B("SERVICE_UNAVAILABLE","Funnel entries unavailable",K.status);return fe.parse(await K.json())},X=await Promise.race([Q(),x]),de=Date.parse(X.validatedAt),te=Date.parse(X.validUntil);if(X.scope.projectId!==n.scope.projectId||X.scope.environment!==n.scope.environment||X.scope.environmentId!==n.environmentId||X.release!==n.appManifestRelease||te<=Date.now()||de>Date.now()+5e3||te<=de||te-de>6e4)throw new B("INVALID_RESPONSE","Entry scope or deadline changed");r||t!==y||(D=X,E=te,b=performance.now()+Math.min(te-Date.now(),6e4),j())})();h=ne;try{await ne}finally{clearTimeout(oe),w.signal.removeEventListener("abort",G),h===ne&&(h=void 0)}}async function Y(){try{await re()}catch{r||a("configuration_unavailable")}r||(l=setTimeout(()=>{Y()},15e3))}return{async start(){i||r||(i=!0,z=location.origin+location.pathname,F=ye(J),U=new MutationObserver(j),U.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",W,!0),document.addEventListener("visibilitychange",j),await Y())},refresh:re,async retry(){u&&!r&&await $(u)},async syncIdentity(){let t=g??u??R;if(t)try{let w=await t.process.syncIdentity();return R===t&&(u={entry:t.entry,process:t.process,visit:m},R=void 0,await $(u)),w}catch(w){throw t.process.view||(R={entry:t.entry,process:t.process,visit:m},u=void 0,S()),w}},async detach(){y++,c?.abort();let t=g??u??R;t&&(R={entry:t.entry,process:t.process,visit:m}),u=void 0,S(),t&&await t.process.detach()},destroy(){r=!0,y++,clearTimeout(l),c?.abort(),U?.disconnect(),F?.(),document.removeEventListener("click",W,!0),document.removeEventListener("visibilitychange",j);let t=g??u??R;u=void 0,R=void 0,S(),t?.process.destroy(),D=void 0}}}async function Vn(...n){return(await import("./paywall-OUIB7SVI.js")).showPaywall(...n)}async function jn(...n){return(await import("./funnel-runtime-host-FOM4Z7ZK.js")).showFunnelRun(...n)}async function Gn(...n){return(await import("./content-E2OWWKDG.js")).mountContent(...n)}async function Kn(...n){return(await import("./content-E2OWWKDG.js")).prepareContent(...n)}export{B as LongplayError,f as MerchantBridgeError,tn as createBrowserFunnelCommandStorage,sn as createConfigurationSync,en as createFeatureClient,dn as createFunnelClient,fn as createFunnelPageExperiments,un as createFunnelProcess,be as createFunnelRunController,yn as createIamFunnelEntries,hn as createIamFunnelProcessEntries,ln as createLocalFunnelClient,nn as createLongplay,pn as createMerchantBridge,an as createPaywallSession,cn as evaluateFunnelNode,Ye as formatCouponDiscount,We as formatCouponMoney,Qe as formatCouponTerms,rn as getPaywallRecovery,Gn as mountContent,Kn as prepareContent,on as preparePaywallFallback,jn as showFunnelRun,Vn as showPaywall};
1
+ import{a as fn,b as Ie}from"./chunk-E6GGMHIY.js";import"./chunk-XIYNQHN7.js";import{a as nn,c as dn,d as un}from"./chunk-S4LVODTE.js";import{a as cn}from"./chunk-P3EOONST.js";import{d as en,i as tn,n as be,o as an,p as sn,r as ln}from"./chunk-6WFCEV3R.js";import{g as rn,h as on}from"./chunk-FISFN5IY.js";import{b as $e}from"./chunk-CRIFRDSD.js";import{a as B}from"./chunk-KHIQQNTR.js";import{a as he,c as ie}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as pe,d as ye}from"./chunk-SHEGSRUV.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-BO5DJEMS.js";import{A as ke,B as Be,C as He,D as Le,F as Ee,G as qe,Ga as je,H as Ue,Ja as Ge,Ka as fe,La as me,Ma as Ke,S as We,T as Ye,U as Qe,l as Ne,ma as Ve,s as we,t as Pe,u as Te,v as Oe,x as De,y as Fe,z as xe}from"./chunk-5QS6C4AI.js";import"./chunk-4SWGHICJ.js";import{z as ge}from"zod";var f=class extends Error{constructor(p,D=0,E=!1,b="fix_request"){super(p);this.code=p;this.status=D;this.retryable=E;this.recovery=b;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function mn(n,T){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");let p=n.body?.getReader();if(!p)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");let D=()=>{p.cancel().catch(()=>{})};T.addEventListener("abort",D,{once:!0});let E=0,b="",r=new TextDecoder("utf-8",{fatal:!0});try{for(T.throwIfAborted();;){let i=await p.read();if(T.throwIfAborted(),i.done)break;if(E+=i.value.byteLength,E>262144)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");b+=r.decode(i.value,{stream:!0})}return b+=r.decode(),JSON.parse(b)}catch(i){throw T.throwIfAborted(),i instanceof f?i:new f("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{T.removeEventListener("abort",D),await p.cancel().catch(()=>{}),p.releaseLock()}}function pn(n){let T=De.parse(n.origin),p=Fe.parse(n.manifest),D={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let l of["projectId","environmentId","environment"])if(p[l]!==n.scope[l])throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");let E=n.customerId===void 0?null:ge.uuid().parse(n.customerId),b=0,r=null,i=null,y=new AbortController,m=n.fetch??globalThis.fetch;async function q(l,c,h,F,U){if(!p.capabilities.includes(l))throw new f("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let H=Oe[l];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(H.authority))throw new f("MERCHANT_BRIDGE_FORBIDDEN",403);let R=b,u=AbortSignal.any([y.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...F?[F]:[]]);u.throwIfAborted();let g=new Headers(await n.headers?.());if(u.throwIfAborted(),R!==b)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(g.get("authorization")??"")||g.has("X-Indiana-Bridge-Signature")||g.has("X-Indiana-Bridge-Key-Id"))throw new f("MERCHANT_BRIDGE_FORBIDDEN",403);g.set(Te,String(we)),g.set("Accept","application/json");let a=crypto.randomUUID();g.set("X-Request-Id",a),g.set("Content-Type","application/json");let L=await m(T+Pe,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:g,signal:u,body:JSON.stringify({bridgeVersion:we,requestId:a,command:H.command,scope:D,data:U??(h===void 0?{}:{operationId:h})})}),M=await mn(L,u);if(u.throwIfAborted(),R!==b)throw new DOMException("Merchant identity changed","AbortError");if(!L.ok){let s=Ue.safeParse(M);throw!s.success||s.data.scope.projectId!==n.scope.projectId||s.data.scope.environment!==n.scope.environment||s.data.scope.environmentId!==n.scope.environmentId||s.data.requestId!==a||s.data.command!==H.command?new f("MERCHANT_BRIDGE_INVALID_RESPONSE",L.status):new f(s.data.error.code,L.status,s.data.error.retryable,s.data.error.recovery)}let S=xe(ge.unknown()).safeParse(M);if(!S.success||S.data.scope.projectId!==n.scope.projectId||S.data.scope.environment!==n.scope.environment||S.data.scope.environmentId!==n.scope.environmentId||S.data.requestId!==a||S.data.command!==H.command)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE",L.status);let $=c.safeParse(S.data.data);if(!$.success)throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE",L.status);return $.data}function A(){if(!E)throw new f("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return E}async function z(l,c,h,F){let U=A(),H=Le.parse({operationId:h,customerId:U}),R=await q(l,c,H.operationId,F,H);if(R.customerId!==U||R.operationId!==H.operationId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return R}return{async readPresentation(l){let c=await q("presentation",Be,void 0,l);if(i!==null&&i!==c.nativeUserId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(c.presentation&&E!==null&&c.presentation.customerId!==E)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=c.nativeUserId,r=c.presentation,c},async createSession(l){let c=await q("session",ke,void 0,l);if(i!==null&&i!==c.nativeUserId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(E!==null&&E!==c.session.customerId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(r&&r.customerId!==c.session.customerId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E=c.session.customerId,i=c.nativeUserId,c.session},async reportPresentation(l,c){let h=A(),F=He.parse(l);if(!r||r.customerId!==h||r.decisionId!==F.decisionId)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return q("presentation_events",ge.strictObject({queued:ge.literal(!0)}),void 0,c,F)},async readCustomerCommerce(l){let c=A(),h=await q("customer_commerce",qe,void 0,l);if(h.customerId!==c)throw new f("MERCHANT_BRIDGE_SCOPE_MISMATCH");return h},async executePurchase(l,c){let h=await z("purchases",Ee,l,c);if(h.type!=="purchase")throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");return h},readOperation:(l,c)=>z("operation_status",Ne,l,c),async executeSubscriptionChange(l,c){let h=await z("subscription_changes",Ee,l,c);if(h.type!=="subscription_change")throw new f("MERCHANT_BRIDGE_INVALID_RESPONSE");return h},reset(){b++,y.abort(),y=new AbortController,E=null,r=null,i=null}}}import{z as se}from"zod";var Je=se.strictObject({command:me,target:Ge,runId:se.uuid().optional(),expiresAt:se.iso.datetime({offset:!0}).optional()}).refine(n=>n.command.release===n.target.release),ze=se.strictObject({schemaVersion:se.literal(1),entries:se.array(Je).max(4e3)});function Xe(n){let T=!1,p=()=>{T||n.unavailable(),T=!0};function D(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function E(r){let i=D()?.getItem(r);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return ze.parse(JSON.parse(i)).entries}function b(r,i){let y=D();if(!y)return;if(!i.length)return y.removeItem(r);let m=JSON.stringify(ze.parse({schemaVersion:1,entries:i}));if(m.length>1048576)throw Error("Entry recovery is too large");y.setItem(r,m)}return{load(){try{let r=n.binding();if(!r||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(r);return{key:i,entries:E(i)}}catch{p();return}},retain(r,i){if(r)try{let y=Je.parse(i);b(r,[...E(r).filter(m=>m.command.funnelId!==y.command.funnelId),y])}catch{p()}},forget(r,i){if(r)try{b(r,E(r).filter(y=>y.command.requestId!==i))}catch{p()}}}}var ve=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function yn(n){let T=pe(n.baseUrl),p=n.scope,D=$e(n),E=n.fetch??globalThis.fetch.bind(globalThis),b,r=!1,i=!1,y=0,m=0,q="",A=0,z=0,l=0,c,h=!1,F,U=!0,H,R,u,g,a,L=-1,M,S=e=>{M===e&&(M=void 0,K())},$=new Set,s=(e,o)=>Z(n.onStatus,e,o),j=new Set,W=Xe({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[T,p.projectId,p.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>s("recovery_unavailable")}),J=e=>W.forget(e.storageKey,e.command.requestId);function re(e,o){o&&(e.runId=o.id,e.expiresAt=o.runExpiresAt),W.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt}})}function Y(){let e=a;a=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),K()}let t=()=>M!==void 0||a!==void 0&&!a.background;function w(e,o){if(a?.client!==e)return;re(a.recovery,o);let d=ve(o);a.slot.hidden=d,d!==a.background&&(a.background=d,d?s("run_background",a.entryId):L=m,K())}function N(e,o,d){let v=e.client.view;if(!o||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let _=Ve.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:o});D.requestWithCredential("funnels",_,e.runToken,{keepalive:d}).then(()=>J(e.recovery)).catch(()=>{})}let x=()=>{a&&N(a,n.session.peek(),!0)},G=()=>Date.now()<z&&performance.now()<l;function oe(e){if(e.target.release!==n.appManifestRelease||!G())return!1;try{return ie(e.target.render,document,location.pathname,()=>{})}catch{return s("incompatible",e.id),!1}}function ne(e){if(r||e.epoch!==A||e.visit!==m||document.visibilityState==="hidden")return!1;try{return ie(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function ce(e){if(t()){s("in_progress",e.id);return}if(!n.session.peek()){s("identity_required",e.id);return}let o=W.load(),d=o?.entries.find(_=>_.command.funnelId===e.funnelId&&(!_.expiresAt||Date.parse(_.expiresAt)>Date.now()));if(d){if(!X(d)){s("recovery_pending",e.id);return}let _={...d,storageKey:o.key,epoch:A,visit:m};j.add(_.command.requestId),M=_,await Q(_);return}let v={command:me.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:A,visit:m,target:e.target,storageKey:o?.key};j.add(v.command.requestId),M=v,await Q(v)}async function Q(e){if(e.dispatching)return;e.dispatching=!0;let o,d=!1,v=!1;async function _(C){if(e.epoch!==A)return;let O=C.view;if(!(e.storageKey&&O&&(ve(O)||O.paywall||O.pendingRequest))&&O&&["running","waiting"].includes(O.status))try{await C.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:O.nodeId,visit:O.visit,revision:O.revision}),J(e)}catch(I){if(!(I instanceof B&&I.code==="FORBIDDEN"))throw I}}try{re(e),s("starting",e.command.entryId);let C=await D.request("funnels",e.command),O=Ke.safeParse(C);if(O.success){if(O.data.scope.projectId!==p.projectId||O.data.scope.environment!==p.environment)throw new B("SCOPE_MISMATCH","Entry scope changed");e.epoch===A&&s(O.data.reason,e.command.entryId),J(e),S(e);return}let I=je.parse(C);if(!I.runToken||I.scope.projectId!==p.projectId||I.scope.environment!==p.environment||I.run.source.type!=="funnel"||I.run.source.id!==e.command.funnelId||I.run.source.versionId!==e.command.versionId||e.runId!==void 0&&I.run.id!==e.runId)throw new B("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==A){S(e),s("identity_changed",e.command.entryId);return}re(e,I.run);let P=be({...n,runToken:I.runToken,funnelId:e.command.funnelId});o=P,v=!0,await P.get(),v=!1;let V=P.view;if(!V||V.id!==I.run.id||V.source.type!=="funnel"||V.source.id!==e.command.funnelId||V.source.versionId!==e.command.versionId)throw new B("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(V.status)){J(e),S(e),s("run_ended",e.command.entryId);return}if(!ne(e)){await _(P),s("left_screen",e.command.entryId),S(e);return}let ue=!1,ae=!1;if(a&&!a.background){await _(P),s("in_progress",e.command.entryId),S(e);return}a&&Y();let ee=document.createElement("div");ee.hidden=ve(V),n.container.append(ee);let Me=await Ie(ee,{...n.host,client:P,appManifestRelease:n.appManifestRelease,onState(k){w(P,k),Z(n.host?.onState,k)},onDismiss(k){ue=!0,ee.remove(),k&&!["running","waiting"].includes(k.status)&&J(e),a?.client===P&&(a=void 0,P.reset(),K(),k&&k.status!=="completed"&&s("run_ended",e.command.entryId)),Z(n.host?.onDismiss,k)},onComplete(k){ae=!0,J(e),a?.client===P&&Y(),Z(n.host?.onComplete,k)},onError(k){Z(n.host?.onError,k),a?.client===P&&k instanceof B&&k.code==="FORBIDDEN"&&(J(e),Y(),s("run_ended",e.command.entryId))}}).catch(k=>{throw ee.remove(),k});if(!ne(e)||ue||ae){Me.destroy(),ee.remove(),ne(e)||await _(P),S(e);return}let le=ve(P.view??V);ee.hidden=le,a={host:Me,client:P,slot:ee,entryId:e.command.entryId,background:le,runToken:I.runToken,owner:n.session.peek(),recovery:e},le||(L=e.visit),d=!0,S(e),s("started",e.command.entryId),le&&s("run_background",e.command.entryId)}catch(C){C instanceof B&&(!o||v&&C.code==="FORBIDDEN")&&C.status!==void 0&&C.status>=400&&C.status<500&&!C.retryable&&(J(e),S(e)),e.epoch===A&&!r&&(s("start_failed",e.command.entryId),Z(n.host?.onError,C))}finally{d||o?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return ie(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function de(){if(t())return!1;let e=W.load();for(let o of e?.entries??[]){if(o.expiresAt&&Date.parse(o.expiresAt)<=Date.now()){W.forget(e.key,o.command.requestId);continue}if(o.command.requestId===a?.recovery.command.requestId||j.has(o.command.requestId)||!X(o))continue;j.add(o.command.requestId);let d={...o,storageKey:e.key,epoch:A,visit:m};return M=d,Q(d),!0}return!1}function te(){if(h=!1,r||!i||document.visibilityState==="hidden")return;Re();let e=a!==void 0&&!a.background;if(e&&(L=m),!de()){if(!G()){U=!0;return}U=!1;for(let o of b?.entries??[]){let d=`${o.funnelId}:${o.id}`;if(!(o.event!=="screen_enter"||$.has(d)||!oe(o))){if(!n.session.peek()){s("identity_required",o.id);continue}if(L===m){$.add(d),e&&s("in_progress",o.id);continue}if(M){s("in_progress",o.id);return}$.add(d),ce(o);break}}}}let K=()=>{!h&&!r&&(h=!0,queueMicrotask(te))};function Re(){let e=location.origin+location.pathname;return e===q?!1:(q=e,m++,U=!0,$.clear(),j.clear(),!0)}function Ze(){Re()&&K()}function Se(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let o=e.target;if(!(o instanceof Element)||o.closest("[data-indiana-funnel]"))return;let d=o.closest("button,a,input");if(!(!d||d.matches(":disabled,[aria-disabled='true']")||d.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of b?.entries??[]){let _=v.target.button;if(!(v.event!=="button_click"||!_||!oe(v))){try{let C=he(document);if(!d.matches(_.selector)||C(_.selector,d)!==1)continue}catch{s("incompatible",v.id);continue}ce(v);break}}}async function _e(){if(r)return;if(F)return F;let e=++y,o=new AbortController;H=o;let d,v=new Promise((O,I)=>{d=()=>I(new B("TIMEOUT","Funnel entry configuration read cancelled or timed out")),o.signal.addEventListener("abort",d,{once:!0})}),_=setTimeout(()=>o.abort(),n.timeoutMs??5e3),C=(async()=>{let O=async()=>{let ae=await E(`${T}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:o.signal});if(!ae.ok)throw new B("SERVICE_UNAVAILABLE","Funnel entries unavailable",ae.status);return fe.parse(await ae.json())},I=await Promise.race([O(),v]),P=Date.parse(I.validatedAt),V=Date.parse(I.validUntil);if(I.scope.projectId!==p.projectId||I.scope.environment!==p.environment||I.scope.environmentId!==n.environmentId||I.release!==n.appManifestRelease||V<=Date.now()||P>Date.now()+5e3||V-P>6e4||V<=P)throw new B("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(r||e!==y)return;let ue=b===void 0;b=I,z=V,l=performance.now()+Math.min(V-Date.now(),6e4),(ue||U)&&K()})();F=C;try{await C}finally{clearTimeout(_),o.signal.removeEventListener("abort",d),F===C&&(F=void 0)}}async function Ce(){try{await _e()}catch{r||s("configuration_unavailable")}r||(c=setTimeout(()=>{Ce()},15e3))}let Ae=()=>K();return{async start(){i||r||(i=!0,q=location.origin+location.pathname,R=ye(Ze),u=n.session.subscribeIdentity(()=>{A++,U=!0,M=void 0,$.clear(),L=-1,j.clear(),a&&N(a,a.owner,!1),Y(),K()}),g=new MutationObserver(K),g.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",Se,!0),document.addEventListener("visibilitychange",Ae),addEventListener("pagehide",x),await Ce())},refresh:_e,async retry(){M&&!r&&M.epoch===A&&await Q(M)},destroy(){r=!0,y++,clearTimeout(c),H?.abort(),g?.disconnect(),R?.(),u?.(),document.removeEventListener("click",Se,!0),document.removeEventListener("visibilitychange",Ae),removeEventListener("pagehide",x),x(),Y(),b=void 0}}}function hn(n){let T=pe(n.baseUrl),p=n.fetch??globalThis.fetch.bind(globalThis),D,E=0,b=0,r=!1,i=!1,y=0,m=0,q=-1,A=!1,z="",l,c,h,F,U,H=new Set,R,u,g,a=(t,w)=>Z(n.onStatus,t,w),L=()=>Date.now()<E&&performance.now()<b;function M(t){try{return L()&&t.target.release===n.appManifestRelease&&ie(t.target.render,document,location.pathname,()=>{})}catch{return a("incompatible",t.id),!1}}function S(){let t=g;g=void 0,t?.host.destroy(),t?.slot.remove()}async function $(t){if(t.dispatching)return;t.dispatching=!0;let w=y;try{let N=await t.process.open({operation:"entry_start",funnelId:t.entry.funnelId,versionId:t.entry.versionId,entryId:t.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});if(r||w!==y||u!==t)return;let x=document.createElement("div");n.container.append(x),q=m;let G=await Ie(x,{...n.host,client:N.controller,appManifestRelease:n.appManifestRelease,onDismiss(oe){g?.process===t.process&&(g=void 0,x.remove()),Z(n.host?.onDismiss,oe)}});if(r||w!==y||u!==t){G.destroy(),x.remove();return}g={entry:t.entry,process:t.process,host:G,slot:x},u=void 0,a("run_presented",t.entry.id)}catch(N){if(r||w!==y||u!==t)return;N instanceof B&&"result"in N?(u=void 0,t.process.destroy(),a("suppressed",t.entry.id),j()):a("entry_unavailable",t.entry.id)}finally{t.dispatching=!1}}function s(t){if(r||u||g||R||q===m||!M(t))return;let w=`${m}:${t.id}`;if(H.has(w))return;H.add(w);let N={entry:t,process:n.createProcess(t),visit:m};u=N,$(N)}function j(){A||r||(A=!0,queueMicrotask(()=>{if(A=!1,!(r||document.visibilityState==="hidden"||!L()||u||g||R||q===m)){for(let t of D?.entries??[])if(t.event==="screen_enter"&&M(t)){s(t);break}}}))}function W(t){if(!t.isTrusted||t.defaultPrevented||!(t.target instanceof Element)||u||g||R||q===m)return;let w=he(document,()=>{});for(let N of D?.entries??[]){let x=N.target.button;if(N.event!=="button_click"||!x||!M(N))continue;let G=t.target.closest(x.selector);if(!(!G||G.tagName.toLowerCase()!==x.tag||w(x.selector)!==1||G.matches(":disabled")||G.closest('[inert],[hidden],[aria-hidden="true"]'))){s(N);break}}}let J=()=>{let t=location.origin+location.pathname;t!==z&&(z=t,m++,H.clear(),j())};async function re(){if(r)return;if(h)return h;let t=y,w=new AbortController;c=w;let N,x=new Promise((ce,Q)=>{N=Q}),G=()=>N(new B("TIMEOUT","Funnel entry read cancelled"));w.signal.addEventListener("abort",G,{once:!0});let oe=setTimeout(()=>w.abort(),n.timeoutMs??5e3),ne=(async()=>{let ce=encodeURIComponent(JSON.stringify(["funnel-process/1"])),Q=async()=>{let K=await p(`${T}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ce}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:w.signal});if(!K.ok)throw new B("SERVICE_UNAVAILABLE","Funnel entries unavailable",K.status);return fe.parse(await K.json())},X=await Promise.race([Q(),x]),de=Date.parse(X.validatedAt),te=Date.parse(X.validUntil);if(X.scope.projectId!==n.scope.projectId||X.scope.environment!==n.scope.environment||X.scope.environmentId!==n.environmentId||X.release!==n.appManifestRelease||te<=Date.now()||de>Date.now()+5e3||te<=de||te-de>6e4)throw new B("INVALID_RESPONSE","Entry scope or deadline changed");r||t!==y||(D=X,E=te,b=performance.now()+Math.min(te-Date.now(),6e4),j())})();h=ne;try{await ne}finally{clearTimeout(oe),w.signal.removeEventListener("abort",G),h===ne&&(h=void 0)}}async function Y(){try{await re()}catch{r||a("configuration_unavailable")}r||(l=setTimeout(()=>{Y()},15e3))}return{async start(){i||r||(i=!0,z=location.origin+location.pathname,F=ye(J),U=new MutationObserver(j),U.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",W,!0),document.addEventListener("visibilitychange",j),await Y())},refresh:re,async retry(){u&&!r&&await $(u)},async syncIdentity(){let t=g??u??R;if(t)try{let w=await t.process.syncIdentity();return R===t&&(u={entry:t.entry,process:t.process,visit:m},R=void 0,await $(u)),w}catch(w){throw t.process.view||(R={entry:t.entry,process:t.process,visit:m},u=void 0,S()),w}},async detach(){y++,c?.abort();let t=g??u??R;t&&(R={entry:t.entry,process:t.process,visit:m}),u=void 0,S(),t&&await t.process.detach()},destroy(){r=!0,y++,clearTimeout(l),c?.abort(),U?.disconnect(),F?.(),document.removeEventListener("click",W,!0),document.removeEventListener("visibilitychange",j);let t=g??u??R;u=void 0,R=void 0,S(),t?.process.destroy(),D=void 0}}}async function Vn(...n){return(await import("./paywall-GVZTDHXI.js")).showPaywall(...n)}async function jn(...n){return(await import("./funnel-runtime-host-FG4BOC3T.js")).showFunnelRun(...n)}async function Gn(...n){return(await import("./content-42ORME22.js")).mountContent(...n)}async function Kn(...n){return(await import("./content-42ORME22.js")).prepareContent(...n)}export{B as LongplayError,f as MerchantBridgeError,tn as createBrowserFunnelCommandStorage,sn as createConfigurationSync,en as createFeatureClient,dn as createFunnelClient,fn as createFunnelPageExperiments,un as createFunnelProcess,be as createFunnelRunController,yn as createIamFunnelEntries,hn as createIamFunnelProcessEntries,ln as createLocalFunnelClient,nn as createLongplay,pn as createMerchantBridge,an as createPaywallSession,cn as evaluateFunnelNode,Ye as formatCouponDiscount,We as formatCouponMoney,Qe as formatCouponTerms,rn as getPaywallRecovery,Gn as mountContent,Kn as prepareContent,on as preparePaywallFallback,jn as showFunnelRun,Vn as showPaywall};