@tinkerlandai/longplay-sdk 0.10.94 → 0.10.97

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 +13 -0
  2. package/README.md +7 -0
  3. package/README.zh-CN.md +4 -0
  4. package/dist/{chunk-Q5IYCTRL.js → chunk-33EKLIMB.js} +1 -1
  5. package/dist/{chunk-6QBSJRAD.js → chunk-55B6CYG6.js} +1 -1
  6. package/dist/chunk-7DQV2EUW.js +1 -0
  7. package/dist/{chunk-FEU6XRHV.js → chunk-AO56DGNZ.js} +1 -1
  8. package/dist/{chunk-C4HLVYSU.js → chunk-BANN2HQH.js} +1 -1
  9. package/dist/{chunk-FDXBCQBO.js → chunk-BQFIJCBA.js} +1 -1
  10. package/dist/chunk-GFH7OK3S.js +1 -0
  11. package/dist/{chunk-H3LJWAAE.js → chunk-HKLAHQKF.js} +1 -1
  12. package/dist/{chunk-ANEFV7YJ.js → chunk-JLKODCRG.js} +2 -2
  13. package/dist/{chunk-NKYNGR3L.js → chunk-JYTUTIBB.js} +1 -1
  14. package/dist/{chunk-IL5OTR6J.js → chunk-PBHOJKKG.js} +1 -1
  15. package/dist/{chunk-5SB3RRGA.js → chunk-WLO2GDRF.js} +1 -1
  16. package/dist/{chunk-VVBXVJI6.js → chunk-XWVK4SJA.js} +1 -1
  17. package/dist/{content-K2T4V3ZD.js → content-IDQO7TKS.js} +1 -1
  18. package/dist/{funnel-host-purchase-M2JNOOCE.js → funnel-host-purchase-7IYZRPYA.js} +1 -1
  19. package/dist/funnel-host-purchase-entry-FFZUEX4Q.js +1 -0
  20. package/dist/{funnel-host-recovery-paywall-XFL6JS74.js → funnel-host-recovery-paywall-DGCR4IBQ.js} +1 -1
  21. package/dist/{funnel-paywall-prerender-YUBH7ZC7.js → funnel-paywall-prerender-QHEGZSPT.js} +1 -1
  22. package/dist/{funnel-runtime-host-3P62SXBA.js → funnel-runtime-host-CFDI4AWM.js} +1 -1
  23. package/dist/index.d.ts +11 -1
  24. package/dist/index.js +1 -1
  25. package/dist/openrouter.js +1 -1
  26. package/dist/page.js +1 -1
  27. package/dist/{paywall-JTKB4MMC.js → paywall-2Z3FUN2M.js} +1 -1
  28. package/dist/{paywall-content-GJX3FQ6D.js → paywall-content-JXWPOE3Y.js} +1 -1
  29. package/dist/{paywall-session-PCWN2M24.js → paywall-session-RNEEPYPG.js} +1 -1
  30. package/dist/react-native.js +1 -1
  31. package/dist/server.js +1 -1
  32. package/dist/visual.js +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-MMHL2KFB.js +0 -1
  35. package/dist/chunk-XKYVXIUI.js +0 -1
  36. package/dist/funnel-host-purchase-entry-OKHAEHOG.js +0 -1
  37. /package/dist/{chunk-ANEFV7YJ.js.LEGAL.txt → chunk-JLKODCRG.js.LEGAL.txt} +0 -0
@@ -1 +1 @@
1
- import{a as T,b as se}from"./chunk-XLGNBPGF.js";import{b as re,h as ae,j as ce}from"./chunk-IL5OTR6J.js";import{E as M,a as J}from"./chunk-FDXBCQBO.js";import{a as b,b as f,c as m}from"./chunk-S2S4ROGY.js";import{c as Z,e as ee,f as te,g as H,h as G,j as ne}from"./chunk-2OBXRQMW.js";import{a as oe,b as j}from"./chunk-PUDTOCQF.js";import{b as W,j as X}from"./chunk-BT7IC765.js";import{n as $}from"./chunk-ME6QTD5Y.js";import{b as ie}from"./chunk-6QBSJRAD.js";import{a as B}from"./chunk-KCUE2VFJ.js";import{a as s}from"./chunk-UGATOG2T.js";import{h as Q}from"./chunk-LFR2LWYC.js";import{b as K}from"./chunk-W22ESUYY.js";import{a as z}from"./chunk-DSPLGTQI.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new s("INVALID_STATE","Installation sequence exhausted");return t+1},Se=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 _(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 s("INVALID_STATE","Installation journal is invalid");return e({...n})})}function ue(t,e,n){let r=null,o=0,a=0,d=0,y=Promise.resolve(),g=!1;if(t&&(!n||Q.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new s("SCOPE_MISMATCH","Push installation belongs to another scope");let l=()=>{if(g)throw new s("CLOSED","SDK client was destroyed");if(!t)throw new s("NOT_CONFIGURED","Configure this client's native Push host first");return t},O=i=>{if(i!==o)throw new s("IDENTITY_CHANGED","Identity changed during Push operation")};async function F(i){let c=l();if(!c.sha256&&!globalThis.crypto?.subtle)throw new s("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=c.sha256?await c.sha256(Uint8Array.from(i,A=>A.charCodeAt(0))):await Se(i);if(!/^[a-f0-9]{64}$/.test(u))throw new s("INVALID_STATE","Push credential digest is invalid");return u}function p(i){let c=G.parse(i);if(c.installationId.toLowerCase()!==l().installationId.toLowerCase())throw new s("INVALID_RESPONSE","Push response belongs to another installation");return c}async function S(i,c){let u=l(),A={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...c},w=await u.sign(ne(i,u.scope,A));return{...A,signature:w}}let I=(i,c,u)=>e.requestWithCredential?e.requestWithCredential(i,c,u):e.request(i,c);async function q(){let i=l(),c=o,u=r?await(e.session?.access()??r):null,A=_(i,v=>v),w;if(A.detachSeq!==null){let v=A.detachSeq,V=Z.parse(await S("detach",{sequence:v,platform:i.platform}));try{let k=await e.request("push/installations/detach",{...i.scope,...V},"POST",{installationDetach:!0});if(!k||typeof k!="object"||!("installation"in k))throw new s("INVALID_RESPONSE","Push detach acknowledgement is invalid");let x=p(k.installation);if(x.bound||x.identitySeq!==v)throw new s("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(k){if(k instanceof s&&k.status===404)w=k;else if(!(k instanceof s)||k.status!==412)throw k}w||_(i,k=>({...k,detachSeq:k.detachSeq===v?null:k.detachSeq}))}if(O(c),!u){if(w)throw w;return null}let C=(await import("./operation-contracts-YJM6772C.js")).apiOperations.bindPushInstallation,D=C.request.parse(await S("bind",{sequence:d,platform:i.platform,credentialDigest:await F(u)}));O(c);let R=C.response.parse(await I(C.path,D,u));O(c);let N=p(R.installation);if(!N.bound||N.identitySeq!==d)throw new s("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return w&&A.detachSeq!==null&&d>A.detachSeq&&_(i,v=>({...v,detachSeq:v.detachSeq===A.detachSeq?null:v.detachSeq})),N}async function h(){l();let i=o,c=r?await(e.session?.access()??r):null;if(!c)throw new s("NOT_IDENTIFIED","Identify before reading this installation");let u=(await import("./operation-contracts-YJM6772C.js")).apiOperations.readPushInstallation,A=u.request.parse(await S("read",{credentialDigest:await F(c)}));O(i);let w=u.response.parse(await I(u.path,A,c));return O(i),p(w.installation)}function P(i=q){let c=y.catch(()=>{}).then(i);return y=c,c.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),c}async function E(i,c,u){let A=l(),w=c.identity,C=c.observation,D=r?await(e.session?.access()??r):null;if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");if(!D)throw new s("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new s("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await P(async()=>{if(O(w),await q(),O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let R=_(A,x=>u?x:{...x,addressSeq:U(x.addressSeq)}),v=await S(u?"recovery_confirm":"recovery_request",{...i,sequence:R.addressSeq,credentialDigest:await F(D),...u?{challenge:u}:{}}),V=u?te.parse(v):ee.parse(v);if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let k=await I(`push/installations/recovery/${u?"confirm":"request"}`,V,D);if(O(w),C!==a||_(A,x=>x).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");if(u){let{apiOperations:x}=await import("./operation-contracts-YJM6772C.js");if(O(w),C!==a||_(A,Oe=>Oe).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");let Ae=x.updatePushAddress.response.parse(k),L=p(Ae.installation);if(!L.bound||L.identitySeq!==d||L.addressSeq!==R.addressSeq||L.connectionId!==i.connectionId||L.addressStatus!=="active")throw new s("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return L}if(!k||typeof k!="object"||!("recovery"in k))throw new s("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return H.parse(k.recovery)})}return{recoveryObserver(){l();let i={identity:o,observation:++a};return{async request(c){return H.parse(await E(c,i))},async confirm(c,u){return G.parse(await E(u,i,c))}}},identify(i){if(!t)return;d=_(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,o++,a++},reset(){if(t)try{_(t,i=>{let c=U(i.identitySeq);return{...i,identitySeq:c,detachSeq:c}})}finally{r=null,o++,a++}},start(){t&&!g&&P()},destroy(){g=!0,r=null,o++,a++},async sync(){return await P()},read:h,async recover(){let i=l(),c=o,u=d;return a++,await P(async()=>{O(c);let A=await h();return O(c),d=_(i,C=>{if(C.identitySeq!==u)throw new s("IDENTITY_CHANGED","A newer installation intent exists");return{...C,identitySeq:U(Math.max(C.identitySeq,A.identitySeq)),addressSeq:Math.max(C.addressSeq,A.addressSeq)}}).identitySeq,await q()})},tokenObserver(){l();let i=++a,c=o;return async u=>{if(i!==a||c!==o)return null;let A=l(),w=r?await(e.session?.access()??r):null;if(!w)throw new s("NOT_IDENTIFIED","Identify before registering a Push token");if(await P(),O(c),i!==a)return null;let C=_(A,v=>({...v,addressSeq:U(v.addressSeq)})),D=(await import("./operation-contracts-YJM6772C.js")).apiOperations.updatePushAddress,R=D.request.parse(await S("address",{...u,sequence:C.addressSeq,credentialDigest:await F(w)}));if(O(c),i!==a)return null;let N=await I(D.path,R,w);return O(c),i!==a||_(A,v=>v).addressSeq!==C.addressSeq?null:p(D.response.parse(N).installation)}}}}function de(t,e){let n={async preference(r){let o=await f(t,"readMessagingPreference");return(await m(t,o,{channel:r})).preference},async setPreference(r){r=b(r);let o=await f(t,"setMessagingPreference");return(await m(t,o,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 r=b(r),n.setPreference({...r,channel:"push"})}}}}function le(t,e,n={}){let r=!1;function o(){if(r)throw new s("CLOSED","SDK client was destroyed")}let a=new Set,d=g=>{for(let l of a)try{l(g)}catch{}},y=t.session.subscribeIdentity(()=>{d(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:o,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(g){return o(),a.add(g),()=>{a.delete(g)}},identify(g){o();let l=typeof g=="string"?g:g.accessToken;if(!B.test(l))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(l),t.identify(g)},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 pe(t){return{async checkEntitlement(e){e=b(e),T(e);let n=await f(t,"checkEntitlement"),r=n.request.parse(e),o=await m(t,n,r);return oe(r.requirement,o.check,void 0,o.scope),o},async readHoldings(e={}){e=b(e);let n=await f(t,"readHoldings"),r={...n,request:n.request.omit({customerId:!0})};return m(t,r,e)}}}function fe(t){return{async readLedger(e){e=b(e);let n=await f(t,"readLedger");return m(t,n,{query:e})},async readCreditStatement(e){e=b(e),T(e);let n=await f(t,"readCreditStatement");return m(t,n,e)},async quoteBalance(e){e=b(e),T(e);let n=await f(t,"quoteBalance");return m(t,n,{command:e})}}}function me(t){return{async setupPayment(e){e=b(e),T(e);let n=await f(t,"setupPayment");return m(t,n,e)},async readPaymentSetup(e){e=b(e),T(e);let n=await f(t,"readPaymentSetup");return m(t,n,e)},async readBillingInvoice(e){e=b(e),T(e);let n=await f(t,"readBillingInvoice");return m(t,n,e)},async readBillingControls(e={}){e=b(e),T(e);let n=await f(t,"readBillingControls");return m(t,n,e)},async prepareBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"prepareBillingAuthorization");return m(t,n,e)},async confirmBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"confirmBillingAuthorization");return m(t,n,e)},async setBillingCoupons(e){e=b(e),T(e);let n=await f(t,"setBillingCoupons");return m(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"revokeBillingAuthorization");return m(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){e=b(e),T(e);let n=await f(t,"listBillingInvoices");return m(t,n,e)},async confirmBillingAdjustment(e){e=b(e),T(e);let n=await f(t,"confirmBillingAdjustment");return m(t,n,e)}}}function ye(t){return{async redeemReward(e){return e=b(e),T(e),(await m(t,await f(t,"redeemReward"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return e=b(e),T(e),(await m(t,await f(t,"claimRewardProduct"),e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return e=b(e),T(e),(await m(t,await f(t,"createReferralCode"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){typeof e=="string"&&(e=e.trim().toUpperCase());let r=await m(t,await f(t,"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 m(t,await f(t,"grantOffer"),{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await m(t,await f(t,"listOffers"),{},{response:"Invalid offers response"})).offers}}}function Ie(t){return{...pe(t),...fe(t),...me(t),...se(t),...ye(t)}}function he(t){return{async resolveContent(e){e=b(e),T(e);let n=await f(t,"resolveContent");return m(t,n,e)},async resolvePaywall(e){e=b(e),T(e);let n=await f(t,"resolvePaywall"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.paywall.check,o.scope),o},async resolveOffering(e){e=b(e),T(e);let n=await f(t,"resolveOffering"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.check,o.scope),o}}}var Y=t=>new TextEncoder().encode(JSON.stringify(t)).length,we=16384,Pe=5e3,Ce=6e4,Re=5;function Te(t){return t instanceof s&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function ge(t,e){let n=0,r,o=h=>{r={config:structuredClone(h),until:Date.now()+3e4}},a=[],d=null,y,g=0;function l(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function O(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,S().catch(()=>{}).finally(O)},Math.min(Pe*2**g,Ce)),typeof y=="object"&&"unref"in y&&y.unref())}function F(h){if(l(),r&&Date.now()<r.until&&!W(r.config,h.kind))return;q();let P=X.parse({events:[{...h,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(Y({events:[P]})>we)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(P)),O()}function p(h,P={},E={}){F({kind:"custom",name:h,properties:P,...E})}async function S(h=!1){if(l(),d)return d;let P=n,E=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},c=a.length;for(;c&&P===n;){let u=[],A=Y({events:[]});for(let C of a.slice(0,Math.min(c,100))){let D=Y(C)+(u.length?1:0);if(u.length&&A+D>we)break;u.push(C),A+=D}let w;try{let C=await f(t,"trackEvents");if(w=await m(t,C,{events:u},void 0,{keepalive:h}),P!==n)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==u.length||w.rejections.length!==w.rejected)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(C){throw P===n&&(g++,(Te(C)||g>=Re)&&(a.splice(0,u.length),g=0)),C}g=0,o(w.analyticsConfig),a.splice(0,u.length),c-=u.length,i.inserted+=w.inserted,i.duplicates+=w.duplicates,i.rejected+=w.rejected,i.skipped+=w.skipped,i.rejections.push(...w.rejections)}return i})();d=E;try{return await E}finally{d===E&&(d=null)}}let I;function q(){if(I||typeof document>"u")return;let h=()=>{document.visibilityState==="hidden"&&e()&&a.length&&S(!0).catch(()=>{})};document.addEventListener("visibilitychange",h),I=()=>document.removeEventListener("visibilitychange",h)}return{rememberConfiguration:o,track:p,observe:F,flush:S,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],g=0,d=null},detachVisibility(){I?.(),I=void 0}}}function ve(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 qe=new Set([...$,"merchandiseId","merchandise"]);function ke(t){let e=ve(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!qe.has(r))),...e?{merchandise:e}:{}}}function Ee(t,e,n,r,o){if(o&&r&&(o.scope.projectId!==r.projectId||o.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,d=new Set;function y(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}async function g(l={}){o||y();let O=a,F=!1,p=async()=>{if(F||O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let R=o?{scope:{projectId:o.scope.projectId,environment:o.scope.environment},payload:await o.features()}:await m(t,await f(t,"getFeatures"),{});if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},S=await p(),I=!0,q,h=R=>{try{l.onError?.(R)}catch{}},P=(R,N)=>{try{let v=ve(N);n.observe({...R,...v?{merchandise:v}:{}})}catch(v){h(v)}},E=ae({assertUsable:o?.assertFeatures,scope:S.scope,attributes:l.attributes,onError:l.onError,load:async()=>I?(I=!1,S.payload):(await p()).payload,evaluateRemote:async R=>{if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let N=await f(t,"evaluateFeatures"),v=await m(t,N,{...R,attributes:ke(R.attributes)});if(v.scope.projectId!==S.scope.projectId||v.scope.environment!==S.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:v.generation,evaluatedAt:v.evaluatedAt,expiresAt:v.expiresAt,features:v.features,...v.merchandiseContext?{merchandiseContext:v.merchandiseContext}:{}}},onExperimentViewed:(R,N,v,V)=>P({kind:"experiment_exposure",generation:V,experimentId:R.key,variationId:N.key},v),onFeatureUsage:(R,N,v,V)=>P({kind:"feature_usage",generation:V,feature:R,value:N.value??null,source:N.source,ruleId:N.ruleId,...N.experimentResult?{variationId:N.experimentResult.key}:{}},v)}),i=E.refresh;function c(){clearTimeout(q),!o&&(F||O!==a||!E.expiresAt||(q=setTimeout(()=>{u().catch(h)},Math.min(2147483647,Math.max(1e3,Date.parse(E.expiresAt)-Date.now()))),typeof q=="object"&&"unref"in q&&q.unref()))}async function u(){try{return await i()}finally{c()}}let A=()=>{F||u().catch(h)},w=E.subscribe(c),C=o?.subscribe(()=>{!F&&o.fresh&&u().catch(h)});function D(){F||(F=!0,clearTimeout(q),typeof window<"u"&&window.removeEventListener("focus",A),w(),C?.(),E.reset(),d.delete(D))}d.add(D);try{await E.init(),(l.attributes?.merchandise||l.attributes?.merchandiseId)&&await E.refreshRemote()}catch(R){throw D(),R}return c(),!o&&typeof window<"u"&&window.addEventListener("focus",A),Object.assign(E,{refresh:u,destroy:D})}return{features:g,reset(l){a++,l();for(let O of d)O()}}}function be(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=K.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let o=Object.freeze(r.data);function a(d){if("customerId"in d)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in d&&d.funnelId!==void 0&&d.funnelId!==o.funnelId||"funnelVersionId"in d&&d.funnelVersionId!==void 0&&d.funnelVersionId!==o.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...d,...o}}return{async claimCoupon(d,y=crypto.randomUUID()){let g=await f(t,"grantOffer"),l=await m(t,g,a({couponId:d,requestId:y}));return{offer:l.offer,reason:l.reason}},async resolveOffering(d){d=b(d);let y=await f(t,"resolveOffering"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.check,l.scope),l},async resolvePaywall(d){d=b(d);let y=await f(t,"resolvePaywall"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.paywall.check,l.scope),l},async previewAttach(d){d=b(d);let y=await f(t,"previewAttach");return m(t,y,a(d))}}}function xt(t){return Ne(t)}function Ne(t){let e=ie(t),n=e.request,r;try{r=ue(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let o=le(e,()=>{d.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=ge(n,o.isIdentified),d=Ee(n,o.isIdentified,a,t.scope,t.configuration);return{session:e.session,...de(n,r),...Ie(n),...he(n),forFunnel(y){return o.assertActive(),be(n,y)},async features(y={}){return o.assertActive(),d.features(y)},track(y,g,l={}){return a.track(y,g,l)},flush(){return a.flush()},...o.methods}}function Mt(t){if(!B.test(t.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let e=ce({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),o=M({...t,runToken:r.runToken,initialResponse:r});o.identify(t.customerToken);let a=await o.get();return{...r,...a,controller:o}}}}function Kt(t){if(!t.scope)throw new s("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new s("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,o=new Set,a=new Map,d=new Map;async function y(p){let S,I=new Promise((q,h)=>{S=setTimeout(()=>h(new s("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(p),I])}finally{clearTimeout(S)}}function g(p){throw p instanceof s&&(p.status===401||p.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear()),p}function l(p,S){if(S!==r)throw new s("IDENTITY_CHANGED","Process was detached during a request");let I=re.parse(p);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new s("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 s("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 s("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let A of o)z(A,I.run);I.run.instruction?.type==="authentication_required"&&z(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&d.set(I.settlement.requestId,I.settlement.accepted);let{identity:q,instruction:h,...P}=I.run,{contract:E,settlement:i,...c}=I,u=i&&(({accepted:A,...w})=>w)(i);return{...c,run:{...P,authenticated:q.binding!==null,instruction:h?.type==="authentication_required"?null:h},...u?{settlement:u}:{}}}let O=p=>(a.has(p)||a.set(p,e?.run.identity.binding?.id??null),a.get(p));async function F(p){let S=r,I=e?.run.identity.binding?.id??null,q=P=>{if(I!==(e?.run.identity.binding?.id??null))throw P;return g(P)};if(p.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new s("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(p.release,p.usedReceiptIds)).catch(q)}let h;if(p.operation==="get"){let{operation:P,customerToken:E,...i}=p;h=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:O(i.settlementRequestId)}:{}})).catch(q)}else if(p.operation==="review")h=await y(()=>t.adapter.review(p.receiptId)).catch(q);else{if(p.operation==="start")throw new s("INVALID_REQUEST","Use process.open for entry");{let{customerToken:P,...E}=p;h=await y(()=>t.adapter.command(E,O(E.requestId))).catch(q)}}return l(h,S)}return{get view(){return e?.run??null},get controller(){return n},async open(p){let S=r,I=await y(()=>t.adapter.open(p)).catch(g),q=l(I,S);if(!n){n=M({...t,runToken:I.runToken,initialResponse:q,process:{request:F,binding:O,restore(E){for(let[i,c]of Object.entries(E))a.set(i,c)}}});let h=n,P=h.submit;h.submit=async E=>{try{return await P(E)}catch(i){if(!(i instanceof s)||i.reason!=="IDENTITY_CONTEXT_CHANGED"||E.operation!=="submit"||E.input.type!=="screen"||a.get(E.requestId)!==null)throw i;await h.settle?.(E.requestId),await h.get();let c=h.view;if(d.get(E.requestId)!==!1||!c||c.id!==e?.run.id||c.nodeId!==E.nodeId||c.visit!==E.visit||!e?.run.identity.binding)throw i;return P({...E,requestId:crypto.randomUUID(),revision:c.revision})}}}await n.get();for(let h of n.pendingCommands??[])a.has(h.requestId)&&a.get(h.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(h.requestId);return{run:e.run,controller:n}},async syncIdentity(){let p=r;l(await y(()=>t.adapter.syncIdentity()).catch(g),p),await n?.get();for(let S of n?.pendingCommands??[])a.has(S.requestId)&&a.get(S.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(S.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),await y(()=>t.adapter.detach())},forProcess(p){if(!e?.run.identity.binding)throw new s("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:p}},subscribe(p){return o.add(p),()=>{o.delete(p)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),o.clear()}}}export{xt as a,Ne as b,Mt as c,Kt as d};
1
+ import{a as T,b as se}from"./chunk-XLGNBPGF.js";import{b as re,h as ae,j as ce}from"./chunk-PBHOJKKG.js";import{E as M,a as J}from"./chunk-BQFIJCBA.js";import{a as b,b as f,c as m}from"./chunk-S2S4ROGY.js";import{c as Z,e as ee,f as te,g as H,h as G,j as ne}from"./chunk-2OBXRQMW.js";import{a as oe,b as j}from"./chunk-PUDTOCQF.js";import{b as W,j as X}from"./chunk-BT7IC765.js";import{n as $}from"./chunk-ME6QTD5Y.js";import{b as ie}from"./chunk-55B6CYG6.js";import{a as B}from"./chunk-KCUE2VFJ.js";import{a as s}from"./chunk-UGATOG2T.js";import{h as Q}from"./chunk-LFR2LWYC.js";import{b as K}from"./chunk-W22ESUYY.js";import{a as z}from"./chunk-DSPLGTQI.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new s("INVALID_STATE","Installation sequence exhausted");return t+1},Se=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 _(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 s("INVALID_STATE","Installation journal is invalid");return e({...n})})}function ue(t,e,n){let r=null,o=0,a=0,d=0,y=Promise.resolve(),g=!1;if(t&&(!n||Q.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new s("SCOPE_MISMATCH","Push installation belongs to another scope");let l=()=>{if(g)throw new s("CLOSED","SDK client was destroyed");if(!t)throw new s("NOT_CONFIGURED","Configure this client's native Push host first");return t},O=i=>{if(i!==o)throw new s("IDENTITY_CHANGED","Identity changed during Push operation")};async function F(i){let c=l();if(!c.sha256&&!globalThis.crypto?.subtle)throw new s("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=c.sha256?await c.sha256(Uint8Array.from(i,A=>A.charCodeAt(0))):await Se(i);if(!/^[a-f0-9]{64}$/.test(u))throw new s("INVALID_STATE","Push credential digest is invalid");return u}function p(i){let c=G.parse(i);if(c.installationId.toLowerCase()!==l().installationId.toLowerCase())throw new s("INVALID_RESPONSE","Push response belongs to another installation");return c}async function S(i,c){let u=l(),A={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...c},w=await u.sign(ne(i,u.scope,A));return{...A,signature:w}}let I=(i,c,u)=>e.requestWithCredential?e.requestWithCredential(i,c,u):e.request(i,c);async function q(){let i=l(),c=o,u=r?await(e.session?.access()??r):null,A=_(i,v=>v),w;if(A.detachSeq!==null){let v=A.detachSeq,V=Z.parse(await S("detach",{sequence:v,platform:i.platform}));try{let k=await e.request("push/installations/detach",{...i.scope,...V},"POST",{installationDetach:!0});if(!k||typeof k!="object"||!("installation"in k))throw new s("INVALID_RESPONSE","Push detach acknowledgement is invalid");let x=p(k.installation);if(x.bound||x.identitySeq!==v)throw new s("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(k){if(k instanceof s&&k.status===404)w=k;else if(!(k instanceof s)||k.status!==412)throw k}w||_(i,k=>({...k,detachSeq:k.detachSeq===v?null:k.detachSeq}))}if(O(c),!u){if(w)throw w;return null}let C=(await import("./operation-contracts-YJM6772C.js")).apiOperations.bindPushInstallation,D=C.request.parse(await S("bind",{sequence:d,platform:i.platform,credentialDigest:await F(u)}));O(c);let R=C.response.parse(await I(C.path,D,u));O(c);let N=p(R.installation);if(!N.bound||N.identitySeq!==d)throw new s("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return w&&A.detachSeq!==null&&d>A.detachSeq&&_(i,v=>({...v,detachSeq:v.detachSeq===A.detachSeq?null:v.detachSeq})),N}async function h(){l();let i=o,c=r?await(e.session?.access()??r):null;if(!c)throw new s("NOT_IDENTIFIED","Identify before reading this installation");let u=(await import("./operation-contracts-YJM6772C.js")).apiOperations.readPushInstallation,A=u.request.parse(await S("read",{credentialDigest:await F(c)}));O(i);let w=u.response.parse(await I(u.path,A,c));return O(i),p(w.installation)}function P(i=q){let c=y.catch(()=>{}).then(i);return y=c,c.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),c}async function E(i,c,u){let A=l(),w=c.identity,C=c.observation,D=r?await(e.session?.access()??r):null;if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");if(!D)throw new s("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new s("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await P(async()=>{if(O(w),await q(),O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let R=_(A,x=>u?x:{...x,addressSeq:U(x.addressSeq)}),v=await S(u?"recovery_confirm":"recovery_request",{...i,sequence:R.addressSeq,credentialDigest:await F(D),...u?{challenge:u}:{}}),V=u?te.parse(v):ee.parse(v);if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let k=await I(`push/installations/recovery/${u?"confirm":"request"}`,V,D);if(O(w),C!==a||_(A,x=>x).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");if(u){let{apiOperations:x}=await import("./operation-contracts-YJM6772C.js");if(O(w),C!==a||_(A,Oe=>Oe).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");let Ae=x.updatePushAddress.response.parse(k),L=p(Ae.installation);if(!L.bound||L.identitySeq!==d||L.addressSeq!==R.addressSeq||L.connectionId!==i.connectionId||L.addressStatus!=="active")throw new s("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return L}if(!k||typeof k!="object"||!("recovery"in k))throw new s("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return H.parse(k.recovery)})}return{recoveryObserver(){l();let i={identity:o,observation:++a};return{async request(c){return H.parse(await E(c,i))},async confirm(c,u){return G.parse(await E(u,i,c))}}},identify(i){if(!t)return;d=_(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,o++,a++},reset(){if(t)try{_(t,i=>{let c=U(i.identitySeq);return{...i,identitySeq:c,detachSeq:c}})}finally{r=null,o++,a++}},start(){t&&!g&&P()},destroy(){g=!0,r=null,o++,a++},async sync(){return await P()},read:h,async recover(){let i=l(),c=o,u=d;return a++,await P(async()=>{O(c);let A=await h();return O(c),d=_(i,C=>{if(C.identitySeq!==u)throw new s("IDENTITY_CHANGED","A newer installation intent exists");return{...C,identitySeq:U(Math.max(C.identitySeq,A.identitySeq)),addressSeq:Math.max(C.addressSeq,A.addressSeq)}}).identitySeq,await q()})},tokenObserver(){l();let i=++a,c=o;return async u=>{if(i!==a||c!==o)return null;let A=l(),w=r?await(e.session?.access()??r):null;if(!w)throw new s("NOT_IDENTIFIED","Identify before registering a Push token");if(await P(),O(c),i!==a)return null;let C=_(A,v=>({...v,addressSeq:U(v.addressSeq)})),D=(await import("./operation-contracts-YJM6772C.js")).apiOperations.updatePushAddress,R=D.request.parse(await S("address",{...u,sequence:C.addressSeq,credentialDigest:await F(w)}));if(O(c),i!==a)return null;let N=await I(D.path,R,w);return O(c),i!==a||_(A,v=>v).addressSeq!==C.addressSeq?null:p(D.response.parse(N).installation)}}}}function de(t,e){let n={async preference(r){let o=await f(t,"readMessagingPreference");return(await m(t,o,{channel:r})).preference},async setPreference(r){r=b(r);let o=await f(t,"setMessagingPreference");return(await m(t,o,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 r=b(r),n.setPreference({...r,channel:"push"})}}}}function le(t,e,n={}){let r=!1;function o(){if(r)throw new s("CLOSED","SDK client was destroyed")}let a=new Set,d=g=>{for(let l of a)try{l(g)}catch{}},y=t.session.subscribeIdentity(()=>{d(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:o,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(g){return o(),a.add(g),()=>{a.delete(g)}},identify(g){o();let l=typeof g=="string"?g:g.accessToken;if(!B.test(l))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(l),t.identify(g)},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 pe(t){return{async checkEntitlement(e){e=b(e),T(e);let n=await f(t,"checkEntitlement"),r=n.request.parse(e),o=await m(t,n,r);return oe(r.requirement,o.check,void 0,o.scope),o},async readHoldings(e={}){e=b(e);let n=await f(t,"readHoldings"),r={...n,request:n.request.omit({customerId:!0})};return m(t,r,e)}}}function fe(t){return{async readLedger(e){e=b(e);let n=await f(t,"readLedger");return m(t,n,{query:e})},async readCreditStatement(e){e=b(e),T(e);let n=await f(t,"readCreditStatement");return m(t,n,e)},async quoteBalance(e){e=b(e),T(e);let n=await f(t,"quoteBalance");return m(t,n,{command:e})}}}function me(t){return{async setupPayment(e){e=b(e),T(e);let n=await f(t,"setupPayment");return m(t,n,e)},async readPaymentSetup(e){e=b(e),T(e);let n=await f(t,"readPaymentSetup");return m(t,n,e)},async readBillingInvoice(e){e=b(e),T(e);let n=await f(t,"readBillingInvoice");return m(t,n,e)},async readBillingControls(e={}){e=b(e),T(e);let n=await f(t,"readBillingControls");return m(t,n,e)},async prepareBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"prepareBillingAuthorization");return m(t,n,e)},async confirmBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"confirmBillingAuthorization");return m(t,n,e)},async setBillingCoupons(e){e=b(e),T(e);let n=await f(t,"setBillingCoupons");return m(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"revokeBillingAuthorization");return m(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){e=b(e),T(e);let n=await f(t,"listBillingInvoices");return m(t,n,e)},async confirmBillingAdjustment(e){e=b(e),T(e);let n=await f(t,"confirmBillingAdjustment");return m(t,n,e)}}}function ye(t){return{async redeemReward(e){return e=b(e),T(e),(await m(t,await f(t,"redeemReward"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return e=b(e),T(e),(await m(t,await f(t,"claimRewardProduct"),e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return e=b(e),T(e),(await m(t,await f(t,"createReferralCode"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){typeof e=="string"&&(e=e.trim().toUpperCase());let r=await m(t,await f(t,"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 m(t,await f(t,"grantOffer"),{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await m(t,await f(t,"listOffers"),{},{response:"Invalid offers response"})).offers}}}function Ie(t){return{...pe(t),...fe(t),...me(t),...se(t),...ye(t)}}function he(t){return{async resolveContent(e){e=b(e),T(e);let n=await f(t,"resolveContent");return m(t,n,e)},async resolvePaywall(e){e=b(e),T(e);let n=await f(t,"resolvePaywall"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.paywall.check,o.scope),o},async resolveOffering(e){e=b(e),T(e);let n=await f(t,"resolveOffering"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.check,o.scope),o}}}var Y=t=>new TextEncoder().encode(JSON.stringify(t)).length,we=16384,Pe=5e3,Ce=6e4,Re=5;function Te(t){return t instanceof s&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function ge(t,e){let n=0,r,o=h=>{r={config:structuredClone(h),until:Date.now()+3e4}},a=[],d=null,y,g=0;function l(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function O(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,S().catch(()=>{}).finally(O)},Math.min(Pe*2**g,Ce)),typeof y=="object"&&"unref"in y&&y.unref())}function F(h){if(l(),r&&Date.now()<r.until&&!W(r.config,h.kind))return;q();let P=X.parse({events:[{...h,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(Y({events:[P]})>we)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(P)),O()}function p(h,P={},E={}){F({kind:"custom",name:h,properties:P,...E})}async function S(h=!1){if(l(),d)return d;let P=n,E=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},c=a.length;for(;c&&P===n;){let u=[],A=Y({events:[]});for(let C of a.slice(0,Math.min(c,100))){let D=Y(C)+(u.length?1:0);if(u.length&&A+D>we)break;u.push(C),A+=D}let w;try{let C=await f(t,"trackEvents");if(w=await m(t,C,{events:u},void 0,{keepalive:h}),P!==n)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==u.length||w.rejections.length!==w.rejected)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(C){throw P===n&&(g++,(Te(C)||g>=Re)&&(a.splice(0,u.length),g=0)),C}g=0,o(w.analyticsConfig),a.splice(0,u.length),c-=u.length,i.inserted+=w.inserted,i.duplicates+=w.duplicates,i.rejected+=w.rejected,i.skipped+=w.skipped,i.rejections.push(...w.rejections)}return i})();d=E;try{return await E}finally{d===E&&(d=null)}}let I;function q(){if(I||typeof document>"u")return;let h=()=>{document.visibilityState==="hidden"&&e()&&a.length&&S(!0).catch(()=>{})};document.addEventListener("visibilitychange",h),I=()=>document.removeEventListener("visibilitychange",h)}return{rememberConfiguration:o,track:p,observe:F,flush:S,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],g=0,d=null},detachVisibility(){I?.(),I=void 0}}}function ve(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 qe=new Set([...$,"merchandiseId","merchandise"]);function ke(t){let e=ve(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!qe.has(r))),...e?{merchandise:e}:{}}}function Ee(t,e,n,r,o){if(o&&r&&(o.scope.projectId!==r.projectId||o.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,d=new Set;function y(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}async function g(l={}){o||y();let O=a,F=!1,p=async()=>{if(F||O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let R=o?{scope:{projectId:o.scope.projectId,environment:o.scope.environment},payload:await o.features()}:await m(t,await f(t,"getFeatures"),{});if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},S=await p(),I=!0,q,h=R=>{try{l.onError?.(R)}catch{}},P=(R,N)=>{try{let v=ve(N);n.observe({...R,...v?{merchandise:v}:{}})}catch(v){h(v)}},E=ae({assertUsable:o?.assertFeatures,scope:S.scope,attributes:l.attributes,onError:l.onError,load:async()=>I?(I=!1,S.payload):(await p()).payload,evaluateRemote:async R=>{if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let N=await f(t,"evaluateFeatures"),v=await m(t,N,{...R,attributes:ke(R.attributes)});if(v.scope.projectId!==S.scope.projectId||v.scope.environment!==S.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:v.generation,evaluatedAt:v.evaluatedAt,expiresAt:v.expiresAt,features:v.features,...v.merchandiseContext?{merchandiseContext:v.merchandiseContext}:{}}},onExperimentViewed:(R,N,v,V)=>P({kind:"experiment_exposure",generation:V,experimentId:R.key,variationId:N.key},v),onFeatureUsage:(R,N,v,V)=>P({kind:"feature_usage",generation:V,feature:R,value:N.value??null,source:N.source,ruleId:N.ruleId,...N.experimentResult?{variationId:N.experimentResult.key}:{}},v)}),i=E.refresh;function c(){clearTimeout(q),!o&&(F||O!==a||!E.expiresAt||(q=setTimeout(()=>{u().catch(h)},Math.min(2147483647,Math.max(1e3,Date.parse(E.expiresAt)-Date.now()))),typeof q=="object"&&"unref"in q&&q.unref()))}async function u(){try{return await i()}finally{c()}}let A=()=>{F||u().catch(h)},w=E.subscribe(c),C=o?.subscribe(()=>{!F&&o.fresh&&u().catch(h)});function D(){F||(F=!0,clearTimeout(q),typeof window<"u"&&window.removeEventListener("focus",A),w(),C?.(),E.reset(),d.delete(D))}d.add(D);try{await E.init(),(l.attributes?.merchandise||l.attributes?.merchandiseId)&&await E.refreshRemote()}catch(R){throw D(),R}return c(),!o&&typeof window<"u"&&window.addEventListener("focus",A),Object.assign(E,{refresh:u,destroy:D})}return{features:g,reset(l){a++,l();for(let O of d)O()}}}function be(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=K.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let o=Object.freeze(r.data);function a(d){if("customerId"in d)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in d&&d.funnelId!==void 0&&d.funnelId!==o.funnelId||"funnelVersionId"in d&&d.funnelVersionId!==void 0&&d.funnelVersionId!==o.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...d,...o}}return{async claimCoupon(d,y=crypto.randomUUID()){let g=await f(t,"grantOffer"),l=await m(t,g,a({couponId:d,requestId:y}));return{offer:l.offer,reason:l.reason}},async resolveOffering(d){d=b(d);let y=await f(t,"resolveOffering"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.check,l.scope),l},async resolvePaywall(d){d=b(d);let y=await f(t,"resolvePaywall"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.paywall.check,l.scope),l},async previewAttach(d){d=b(d);let y=await f(t,"previewAttach");return m(t,y,a(d))}}}function xt(t){return Ne(t)}function Ne(t){let e=ie(t),n=e.request,r;try{r=ue(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let o=le(e,()=>{d.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=ge(n,o.isIdentified),d=Ee(n,o.isIdentified,a,t.scope,t.configuration);return{session:e.session,...de(n,r),...Ie(n),...he(n),forFunnel(y){return o.assertActive(),be(n,y)},async features(y={}){return o.assertActive(),d.features(y)},track(y,g,l={}){return a.track(y,g,l)},flush(){return a.flush()},...o.methods}}function Mt(t){if(!B.test(t.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let e=ce({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),o=M({...t,runToken:r.runToken,initialResponse:r});o.identify(t.customerToken);let a=await o.get();return{...r,...a,controller:o}}}}function Kt(t){if(!t.scope)throw new s("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new s("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,o=new Set,a=new Map,d=new Map;async function y(p){let S,I=new Promise((q,h)=>{S=setTimeout(()=>h(new s("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(p),I])}finally{clearTimeout(S)}}function g(p){throw p instanceof s&&(p.status===401||p.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear()),p}function l(p,S){if(S!==r)throw new s("IDENTITY_CHANGED","Process was detached during a request");let I=re.parse(p);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new s("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 s("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 s("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let A of o)z(A,I.run);I.run.instruction?.type==="authentication_required"&&z(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&d.set(I.settlement.requestId,I.settlement.accepted);let{identity:q,instruction:h,...P}=I.run,{contract:E,settlement:i,...c}=I,u=i&&(({accepted:A,...w})=>w)(i);return{...c,run:{...P,authenticated:q.binding!==null,instruction:h?.type==="authentication_required"?null:h},...u?{settlement:u}:{}}}let O=p=>(a.has(p)||a.set(p,e?.run.identity.binding?.id??null),a.get(p));async function F(p){let S=r,I=e?.run.identity.binding?.id??null,q=P=>{if(I!==(e?.run.identity.binding?.id??null))throw P;return g(P)};if(p.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new s("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(p.release,p.usedReceiptIds)).catch(q)}let h;if(p.operation==="get"){let{operation:P,customerToken:E,...i}=p;h=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:O(i.settlementRequestId)}:{}})).catch(q)}else if(p.operation==="review")h=await y(()=>t.adapter.review(p.receiptId)).catch(q);else{if(p.operation==="start")throw new s("INVALID_REQUEST","Use process.open for entry");{let{customerToken:P,...E}=p;h=await y(()=>t.adapter.command(E,O(E.requestId))).catch(q)}}return l(h,S)}return{get view(){return e?.run??null},get controller(){return n},async open(p){let S=r,I=await y(()=>t.adapter.open(p)).catch(g),q=l(I,S);if(!n){n=M({...t,runToken:I.runToken,initialResponse:q,process:{request:F,binding:O,restore(E){for(let[i,c]of Object.entries(E))a.set(i,c)}}});let h=n,P=h.submit;h.submit=async E=>{try{return await P(E)}catch(i){if(!(i instanceof s)||i.reason!=="IDENTITY_CONTEXT_CHANGED"||E.operation!=="submit"||E.input.type!=="screen"||a.get(E.requestId)!==null)throw i;await h.settle?.(E.requestId),await h.get();let c=h.view;if(d.get(E.requestId)!==!1||!c||c.id!==e?.run.id||c.nodeId!==E.nodeId||c.visit!==E.visit||!e?.run.identity.binding)throw i;return P({...E,requestId:crypto.randomUUID(),revision:c.revision})}}}await n.get();for(let h of n.pendingCommands??[])a.has(h.requestId)&&a.get(h.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(h.requestId);return{run:e.run,controller:n}},async syncIdentity(){let p=r;l(await y(()=>t.adapter.syncIdentity()).catch(g),p),await n?.get();for(let S of n?.pendingCommands??[])a.has(S.requestId)&&a.get(S.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(S.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),await y(()=>t.adapter.detach())},forProcess(p){if(!e?.run.identity.binding)throw new s("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:p}},subscribe(p){return o.add(p),()=>{o.delete(p)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),o.clear()}}}export{xt as a,Ne as b,Mt as c,Kt as d};
@@ -1 +1 @@
1
- import{b as Ge}from"./chunk-XLGNBPGF.js";import{a as ee}from"./chunk-EQUVI5QU.js";import{D as Z,F as Ye,c as Ve,e as Y,j as He,u as ze,v as Qe,x as Be,z as Je}from"./chunk-FDXBCQBO.js";import{a as Ue,b as xe,c as De}from"./chunk-S2S4ROGY.js";import{b as de}from"./chunk-Y55OBV7D.js";import{i as pe}from"./chunk-MOIVJERE.js";import{K as J}from"./chunk-ME6QTD5Y.js";import{A as le,B as X,C as B,E as Te}from"./chunk-3532HSBP.js";import{x as Ce}from"./chunk-67WFVDTV.js";import{b as Me}from"./chunk-6QBSJRAD.js";import{a as l}from"./chunk-UGATOG2T.js";import{h as ce}from"./chunk-LFR2LWYC.js";import{a as Le}from"./chunk-5MRSFLQA.js";import{b as a}from"./chunk-W22ESUYY.js";import{a as Ee}from"./chunk-DSPLGTQI.js";var E=J.options,ft=a.discriminatedUnion("operation",[E[1].omit({customerToken:!0}),E[2].omit({customerToken:!0}),E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0}),E[8].omit({customerToken:!0}),He.omit({customerToken:!0})]),Se=a.strictObject({receiptId:a.uuid(),operationId:a.uuid()}),bt=a.discriminatedUnion("operation",[a.strictObject({operation:a.literal("find_purchase")}),a.strictObject({operation:a.literal("recover_start"),intent:a.enum(["lookup","resume","start"]),start:a.strictObject({requestId:E[0].shape.requestId,funnelId:E[0].shape.funnelId,locale:E[0].shape.locale,parameters:E[0].shape.parameters})}),a.strictObject({operation:a.literal("recover_run"),runId:a.uuid(),funnelId:a.uuid()}),a.strictObject({operation:a.literal("recover_purchase"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,includePaywallVersion:a.literal(!0).optional()}),a.strictObject({operation:a.literal("terminate_checkout"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,intent:a.literal("expire_unconfirmed_quote").optional()}),a.strictObject({operation:a.literal("settle_command"),runId:a.uuid(),funnelId:a.uuid(),requestId:a.uuid(),command:a.discriminatedUnion("operation",[E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0})]).optional()}).refine(u=>!u.command||u.requestId===u.command.requestId),a.strictObject({operation:a.literal("run_command"),runId:a.uuid(),funnelId:a.uuid(),command:ft})]),me=a.strictObject({runId:a.uuid(),funnelId:a.uuid(),versionId:a.uuid(),startRequestId:a.uuid(),runExpiresAt:a.iso.datetime({offset:!0}),status:Y.shape.run.shape.status}),G={scope:ce,customerId:a.uuid()},Ke=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("unknown"),target:a.null(),view:a.null(),access:a.null()}),a.strictObject({...G,outcome:a.literal("resolved"),target:me,view:Y.shape.run.nullable(),access:a.discriminatedUnion("type",[a.strictObject({type:a.literal("customer")}),a.strictObject({type:a.literal("operation_only"),cause:a.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((u,m)=>{u.outcome==="resolved"&&(u.access.type==="customer"!=(u.view!==null)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),$e=a.strictObject({...G,target:me,view:Y.shape.run.nullable(),settlement:a.strictObject({requestId:a.uuid(),state:a.enum(["pending","unknown","settled"]),acceptance:a.enum(["accepted","not_accepted","unknown"]),receiptPhase:a.enum(["accepted","processing","done"]).nullable(),basis:a.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:a.uuid().nullable(),operationId:a.uuid().nullable()}),purchase:Y.shape.purchase.unwrap().nullable()}).superRefine((u,m)=>{let h=u.settlement;(h.acceptance==="accepted"!=(h.receiptPhase!==null)||h.acceptance==="accepted"&&h.basis!=="receipt"||h.acceptance==="unknown"&&(h.state!=="unknown"||h.basis!=="none")||h.acceptance!=="accepted"&&(h.operationId!==null||h.receiptId!==null)||h.acceptance==="not_accepted"&&(h.state!=="settled"||!["run_terminal","position_advanced"].includes(h.basis))||u.purchase&&(u.purchase.receiptId!==h.receiptId||u.purchase.operation&&u.purchase.operation.operationId!==h.operationId||u.purchase.quote&&u.purchase.quote.operationId!==h.operationId)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Original command settlement binding differs"})}),We=a.strictObject({...G,target:me,purchase:Y.shape.purchase.unwrap(),paywallVersionId:a.uuid().optional()}).superRefine((u,m)=>{(!u.purchase.operation||typeof u.purchase.canReselect!="boolean"||u.purchase.quote&&u.purchase.quote.operationId!==u.purchase.operation.operationId)&&m.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),Xe=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("none")}),a.strictObject({...G,outcome:a.literal("blocked")}),a.strictObject({...G,outcome:a.literal("found"),target:me,start:a.strictObject({locale:E[0].shape.locale,parameters:E[0].shape.parameters}),purchase:Se})]);var ht=J.options[0].refine(u=>!u.customer&&!u.customerData),wt=a.strictObject({receiptId:a.uuid(),operationId:a.uuid(),terminal:a.enum(["complete","native"]).nullable()}),Ze=a.strictObject({schemaVersion:a.literal(1),baseUrl:a.url(),scope:ce,customerId:a.uuid(),sessionId:a.uuid(),start:ht,allowed:a.array(a.enum(["merchant","record_only","indiana","native"])),run:a.strictObject({id:a.uuid(),versionId:a.uuid(),status:Ve.shape.status,revision:a.number().int().nonnegative(),runExpiresAt:a.iso.datetime({offset:!0}).optional()}).optional(),purchases:a.array(wt).max(100),operationCommand:a.strictObject({operationId:a.uuid(),intent:a.literal("confirm")}).optional(),journal:a.strictObject({revision:a.number().int().nonnegative(),entry:ze.nullable()})});function et(u){return Be({...u,namespace:"purchases",identity:[u.scope.projectId,u.scope.environment,u.customerId]})}function tt(u){let m=new URL(u.baseUrl??Le).href,h=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function S(){u.assertCurrent();try{let C=await u.storage.read();if(u.assertCurrent(),!Number.isSafeInteger(C.revision)||C.revision<0)throw h();let c=C.entry===null?null:Ze.parse(C.entry);if(c&&(c.baseUrl!==m||c.customerId!==u.customerId||c.scope.projectId!==u.scope.projectId||c.scope.environment!==u.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(c?.journal.entry&&(c.journal.entry.scope.projectId!==c.scope.projectId||c.journal.entry.scope.environment!==c.scope.environment||c.journal.entry.funnelId!==c.start.funnelId||c.journal.entry.runId!==c.run?.id||c.journal.entry.versionId!==c.run?.versionId)||c?.operationCommand&&!c.purchases.some(k=>k.operationId===c.operationCommand?.operationId))throw h();return{revision:C.revision,entry:c}}catch(C){throw C instanceof l?C:h()}}async function te(C){for(let c=0;c<8;c++){let k=await S(),O=C(structuredClone(k.entry));if(JSON.stringify(O)===JSON.stringify(k.entry))return O;O&&Ze.parse(O),u.assertCurrent();let U;try{U=await u.storage.write(k.revision,O)}catch{throw h()}if(u.assertCurrent(),U!==null){if(!Number.isSafeInteger(U)||U<=k.revision)throw h();return O}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:S,update:te,baseUrl:m}}var It=5*6e4,yt=2e3,gt=250;function Pt(u,m){let h=u.purchases.find(S=>S.type==="checkout");if(!u.actions.includes("continue_checkout")||h?.type!=="checkout"||m!==void 0&&h.operationId!==m)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return h.checkoutUrl}function fe(u){return!u||u.operation==="close"||u.operation==="back"||u.operation==="shown"||u.operation==="submit"&&u.input.type==="screen"}var nt=()=>({revision:0,entry:null});function Zt(u){let m={...u,scope:{...u.scope},executionPolicy:structuredClone(u.executionPolicy)},h=m.session.snapshot();if(!h)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:S,sessionId:te}=h,C=!1,c=null,k,O,U=null,A=!1,x,ne,re,q={mode:"idle",status:"idle",actions:["start"],purchases:[]},v=new Map,be=new Map,D=new Map,he=new AbortController,oe=new Set,K=Me(m),ae=Ge(K.request);function $(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function I(){if(C||m.session.snapshot()?.customerId!==S)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=tt({...m,customerId:S,assertCurrent:I,storage:m.storage??et({baseUrl:m.baseUrl,scope:m.scope,customerId:S})}),rt,_e=()=>rt??=import("./funnel-paywall-copies-LPOTYSTS.js").then(({createPaywallCopies:e})=>e({baseUrl:m.baseUrl,scope:m.scope,customerId:S})),ot={read:async e=>(await _e()).read(e),write:async(e,t)=>(await _e()).write(e,t)},at=m.session.subscribeIdentity(qe);function qe(){C||(C=!0,clearTimeout(re),he.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),at(),c?.reset(),c=null,U=null,K.dispose(),oe.clear(),v.clear(),D.clear())}function R(e){I();let t=JSON.stringify(e)!==JSON.stringify(q);q=e,clearTimeout(re),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(re=setTimeout(()=>{Q().catch(()=>{})},5e3)),t&&Ee(m.onRecovery,structuredClone(e));for(let n of t?oe:[]){if(C)break;Ee(n,structuredClone(e))}return structuredClone(e)}function g(e){if(I(),!e||e.start.requestId!==O)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function Oe(e){return!e.run&&!b(e).length&&!e.journal.entry&&!e.operationCommand}function we(e){let t=e.journal.entry;return!b(e).length&&!e.operationCommand&&fe(t?.command)&&fe(t?.closeCommand)}function z(e){return!!e.run&&we(e)}function b(e){let t=[...e.purchases],n=e.journal.entry?.purchase;return n&&!t.some(o=>o.operationId===n.operationId)&&t.push({receiptId:n.receiptId,operationId:n.operationId,terminal:null}),t}function j(e){let t=b(e),n=A&&t.length>0&&t.every(o=>o.terminal==="native"&&H(v.get(o.operationId))==="native")&&t.some(o=>{let r=v.get(o.operationId);return!r||D.get(o.operationId)!==!0?!1:B(r)?!0:r.status==="cancelled"&&r.confirmedAt===null&&!r.quoteFinalized&&!r.merchantExecution&&!r.problem&&!!r.quote&&Date.parse(r.quote.expiresAt)<=Date.now()});return e.run&&(n||!["running","waiting"].includes(e.run.status))&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&t.every(o=>o.terminal!==null)}function N(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=b(e).map(f=>{let _=v.get(f.operationId),P=de({quote:_?.quote??null,operation:_??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:D.get(f.operationId)===!0});return f.terminal&&(P.type==="checkout"||P.type==="recover"||P.type==="cancel")?{type:f.terminal,operationId:f.operationId}:P}),r=o.filter(f=>!["complete","native"].includes(f.type)),i=r[0],s=r.length===1&&i?.operationId?v.get(i.operationId):void 0;if(s&&(i?.type==="checkout"||i?.type==="cancel"))try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote)}catch(f){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:$(f)}}let d;if(t==="operation"&&!n&&i?.type==="cancel"&&s?.quote&&!s.problem&&!s.confirmedAt)try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote),Date.parse(s.quote.expiresAt)>Date.now()&&(d={operationId:s.operationId,quote:s.quote})}catch{}let p=o.length>0&&r.length===0,y=j(e)||t==="operation"&&p&&!n&&!e.operationCommand?"complete":i?.type==="checkout"?"checkout":i?.type==="fulfillment"?"fulfillment":i?.type==="recording"?"recording":n||e.operationCommand||i&&i.type!=="cancel"||t==="operation"&&!d?"waiting_result":"ready";return{mode:t,status:y,purchases:o,...d?{confirmation:structuredClone(d)}:{},actions:["refresh",...j(e)||z(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:d?["confirm"]:[],...r.length===1&&i?.type==="checkout"?["continue_checkout"]:[]]}}function H(e){let t=de({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&D.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function Ie(e){if(!e.operation)return;let t=le.parse({...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}});if(t.merchantExecution&&t.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let n=pe(v.get(t.operationId)??null,t);v.set(t.operationId,n),n===t&&D.set(t.operationId,e.canReselect===!0)}async function it(e,t,n){I();for(let i of[e.purchase,e.run.paywall])i&&Ie(i);let o=!1,r=await w.update(i=>{if(i&&i.start.requestId!==t)return o=!0,i;if(g(i),i.run&&(i.run.id!==e.run.id||i.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let s=b(i);for(let d of[e.purchase,e.run.paywall]){let p=d?.operation?.operationId??d?.quote?.operationId;if(!d||!p)continue;let y=s.find(_=>_.operationId===p);if(y&&y.receiptId!==d.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let f=H(v.get(p));y?y.terminal??=f:s.push({receiptId:d.receiptId,operationId:p,terminal:f})}return{...i,purchases:s,run:i.run&&(i.run.revision>e.run.revision||!["running","waiting"].includes(i.run.status)&&["running","waiting"].includes(e.run.status))?i.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});if(o){n();return}g(r),r.run&&!["running","waiting"].includes(r.run.status)&&b(r).some(i=>!i.terminal)&&(r=await L(r,!r.journal.entry?.command&&!r.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(i=>!!i)))),g(r),R(N(r,"run"))}function st(e){let t;return()=>{t||C||(t=setTimeout(()=>{let n=e(),o=n.view;if(C||!o||!["running","waiting"].includes(o.status)||n.pendingCommands?.some(r=>r.operation==="close")){t=void 0;return}t=n.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:o.nodeId,visit:o.visit,revision:o.revision}).catch(()=>{}).finally(()=>{t=void 0})}))}}function ut(e,t){let n=null,o=r=>!!r&&r.start.requestId!==e;return{async read(){let{entry:r}=await w.read();return I(),o(r)?(t(),structuredClone(n??=nt())):(g(r),structuredClone(r.journal))},async write(r,i){let s=null;return await w.update(d=>{if(o(d)){if(t(),!fe(i?.command)||!fe(i?.closeCommand))throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; its Run can only be dismissed");let p=n??=nt();return s=null,p.revision!==r||(s=r+1,n={revision:s,entry:i}),d}if(g(d),d.operationCommand&&i?.command&&i.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return s=null,d.journal.revision!==r?d:(s=r+1,{...d,journal:{revision:s,entry:i}})}),s}}}async function L(e,t=!1,n=new Set){g(e);let o=b(e);for(let i of o){if(i.terminal)continue;let s=n.has(i.operationId)?v.get(i.operationId):void 0;if(s??=await V(e,i),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(s.merchantExecution&&s.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&de({quote:s.quote??null,operation:s,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let d=B(s)?await ae.update({operationId:i.operationId,intent:"cancel"}):await ae.attach({operationId:i.operationId,intent:"cancel"});if(s=le.parse(d.operation),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");s=await V(e,i)}v.set(i.operationId,pe(v.get(i.operationId)??null,s))}let r=await w.update(i=>{g(i);let s=i.operationCommand&&v.get(i.operationCommand.operationId);return{...i,...s&&(s.confirmedAt||s.merchantExecution||!Te(s))?{operationCommand:void 0}:{},purchases:b(i).map(d=>({...d,terminal:d.terminal??H(v.get(d.operationId))}))}});return g(r),r}async function W(e){I();let t=await K.request("funnels",e);return I(),t}async function ct(e){try{return await W(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return W({...e,intent:"resume"})}}async function lt(){let e=ee(Xe,await W({operation:"find_purchase"}));if(e.customerId!==S||e.scope.projectId!==m.scope.projectId||e.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(e.outcome!=="found")return e.outcome;let{target:t,purchase:n}=e;return await w.update(o=>o&&!j(o)&&!z(o)?o:{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...m.executionPolicy.allowed],run:{id:t.runId,versionId:t.versionId,status:t.status,revision:0,runExpiresAt:t.runExpiresAt},purchases:[{...n,terminal:null}],journal:{revision:0,entry:null}}),"found"}let ie;function ye(e){let t=ie;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<It))return t.job;let n={at:Date.now(),job:lt().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw ie===n&&(ie=void 0),o})};return ie=n,n.job}async function V(e,t,n="recover_purchase",o=!1){let r={runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId}},i=n==="recover_purchase"?{...r,operation:n,...o?{includePaywallVersion:!0}:{}}:{...r,operation:"terminate_checkout",...n==="expire_unconfirmed_quote"?{intent:n}:{}},s=ee(We,await W(i));if(ge(e,s),s.purchase.receiptId!==t.receiptId||s.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return Ie(s.purchase),o&&s.paywallVersionId&&be.set(t.operationId,s.paywallVersionId),v.get(t.operationId)}async function Fe(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=ee($e,await W({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(ge(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&Ie(n.purchase);let o=await w.update(r=>{g(r);let i=b(r),{receiptId:s,operationId:d}=n.settlement;if(s&&d){let y=i.find(f=>f.operationId===d);if(y&&y.receiptId!==s)throw new l("INVALID_RESPONSE","Original Receipt changed");y||i.push({receiptId:s,operationId:d,terminal:H(v.get(d))})}let p=n.settlement.state==="settled"?Qe(r.journal.entry,t.requestId):r.journal.entry;return{...r,purchases:i,journal:p===r.journal.entry?r.journal:{revision:r.journal.revision+1,entry:p}}});g(o),e=o}return e}function ge(e,t){if(t.customerId!==S||t.scope.projectId!==m.scope.projectId||t.scope.environment!==m.scope.environment||t.target.funnelId!==e.start.funnelId||t.target.startRequestId!==e.start.requestId||e.run&&(t.target.runId!==e.run.id||t.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function Pe(e,t){if(g(e),e.run&&(e=await Fe(e)),!b(e).length&&j(e))return R(N(e,"operation"));if(we(e)){let r=e.start.requestId;if(!await w.update(s=>s&&s.start.requestId===r&&we(s)?null:s))return c?.reset(),c=null,A=!1,R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}if(!b(e).length)return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(t)});A=!0;let n=b(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(r=>r.terminal==="native"))for(let r of n)H(v.get(r.operationId))!=="native"&&await V(e,r);let o=await dt(await L(e));return R(N(o,"operation"))}async function dt(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return e;let t=b(e).filter(i=>!i.terminal),n=t[0];if(!n||t.length!==1)return e;let o=v.get(n.operationId),r=o?.quote;if(!o||B(o)||!r||X(r)||r.provider!=="merchant"||o.status!=="pending"||o.confirmedAt!==null||o.quoteFinalized||o.checkoutUrl||o.nativePurchase||o.merchantExecution||o.problem||Date.parse(r.expiresAt)>Date.now())return e;try{await V(e,n,"expire_unconfirmed_quote")}catch{return I(),e}return L(e,!1,new Set([n.operationId]))}async function se(e,t=!1,n=!0,o=!1){if(O=e.start.requestId,U=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!c){let r=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:t?"start":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},i;try{i=await ct(r)}catch(P){if(!e.run&&P instanceof l&&(P.status===void 0||P.status>=500))return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:$(P)});throw P}let s=ee(Ke,i);if(s.customerId!==S||s.scope.projectId!==m.scope.projectId||s.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(s.outcome==="unknown"){if(!t&&Oe(e)){let P=e.start.requestId;if(!await w.update(M=>M&&M.start.requestId===P&&Oe(M)?null:M))return R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}})}ge(e,s);let d=await w.update(P=>(g(P),{...P,run:{id:s.target.runId,versionId:s.target.versionId,status:s.target.status,revision:s.view?.revision??P.run?.revision??0,runExpiresAt:s.target.runExpiresAt}}));if(g(d),e=d,s.access.type==="operation_only")return Pe(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await Fe(e);let p=s.view;if(p.locale!==e.start.locale||!Je(p.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");let y=e.start.requestId,f=st(()=>_),_=Ye({...m,customerRun:{runId:s.target.runId,customerId:S,startRequestId:y},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(P=>m.executionPolicy.allowed.includes(P))},funnelCommandStorage:ut(y,f),onAcceptedResponse:P=>it(P,y,f)},{scope:s.scope,run:p});c=_}try{let r=o&&k?.controller===c?performance.now()-k.at:1/0;(r>=yt||c.pendingCommands?.length||(c.viewAgeMs??0)<r)&&(k=void 0,await c.get(),k={controller:c,at:performance.now()}),c.view?.pendingRequest?.requestId===e.start.requestId&&!c.pendingCommands?.length&&await c.resume(c.view.pendingRequest.requestId);for(let s of c.pendingCommands??[])s.operation!=="close"&&await c.settle?.(s.requestId);c.pendingCommands?.length&&await c.retry(),I();let i=(await w.read()).entry;return g(i),R(N(i,"run"))}catch(r){if(I(),n&&r instanceof l&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED")){c.reset(),c=null;let i=(await w.read()).entry;return g(i),se(i,!1,!1,!1)}throw r}}function T(e,t="read",n){if(I(),x)return t==="read"||t===ne?x:x.then(()=>T(e,t,n),()=>T(e,t,n));clearTimeout(re);let o=e().catch(r=>{throw!C&&!n?.(r)&&R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:q.purchases,error:$(r)}),r});return x=o,ne=t,o.then(()=>{x===o&&(x=void 0,ne=void 0)},()=>{x===o&&(x=void 0,ne=void 0)}),o}function pt(e){return e instanceof l&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT"||e.status===409||e.status===429||e.status!==void 0&&e.status>=500)}function Q(e){let t=e?.reuseRecentRead===!0,n=async o=>{let{entry:r}=await w.read();if(!r||j(r)){if(await ye(!1)==="blocked")return ke();({entry:r}=await w.read())}return r?(O&&r.start.requestId!==O&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A&&O===r.start.requestId?Pe(r,q.error):se(r,!1,!0,o)):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})};return T(async()=>{try{return await n(t)}catch(o){if(C||!pt(o))throw o;return I(),c?.reset(),c=null,k=void 0,o.status===409?A=!1:await new Promise(r=>setTimeout(r,gt)),I(),n(!1)}})}function ke(){return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function Ae(){let e=await Q();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:T(async()=>{let t=(await w.read()).entry;if(g(t),!A){if(!c?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let p=c.view.paywall.operation;if(p?.confirmedAt||p?.merchantExecution||p&&!(B(p)?["prepared","quoted"].includes(p.status):p.status==="pending"))return R(N(t,"run"));if(c.pendingCommands?.length)await c.retry();else{let f=c.view;await c.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:f.nodeId,visit:f.visit,revision:f.revision,input:{type:"paywall_confirm",operationId:f.paywall.quote.operationId,...f.paywall.quote.merchantTerms?{merchantConfirmation:Ce(f.paywall.quote.merchantTerms)}:{}}})}let y=(await w.read()).entry;return g(y),R(N(y,"run"))}let n=t.operationCommand?.operationId??q.confirmation?.operationId,o=n&&v.get(n);if(!n||!o||t.journal.entry?.command||t.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");Z({allowed:t.allowed.filter(p=>m.executionPolicy.allowed.includes(p))},o.quote),await w.update(p=>{if(g(p),p.journal.entry?.command||p.journal.entry?.closeCommand||p.operationCommand&&p.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...p,operationCommand:{operationId:n,intent:"confirm"}}});let r={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:Ce(o.quote.merchantTerms)}:{}},i=B(o)?await ae.update(r):await ae.attach(r),s=le.parse(i.operation);if(I(),i.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");v.set(n,pe(o,s));let d=(await w.read()).entry;return g(d),R(N(await L(d,!1,new Set([n])),"operation"))},"confirm")}function mt(e){let t=e?.quote;return t&&X(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Ne(){if(q.mode!=="operation"||q.status==="blocked")return null;let e=q.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?mt(v.get(t)):null}async function je(){I();let{entry:e}=await w.read();return e?j(e)||z(e)?"finished":"pending":"none"}return{get controller(){return c},get recovery(){return structuredClone(q)},get attempt(){return I(),structuredClone(U)},get identitySignal(){return he.signal},get customerId(){return S},retained:je,async pendingFunnel(){I();let{entry:e}=await w.read();return e&&!j(e)&&!z(e)?e.start.funnelId:null},get paywallCopies(){return ot},async findPurchase(){let e=await je();if(e==="pending")return e;let t=await ye(!0);return I(),t==="none"?e:t},async readPaywall(e){I();let t=Ue(e),[n,{readPaywallContent:o},{validateResourceCheck:r}]=await Promise.all([xe(K.request,"resolvePaywall"),import("./paywall-content-GJX3FQ6D.js"),import("./check-response-XGOTG3KL.js")]);I();let i=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),s=await De(K.request,n,i);r(i,s.paywall.check,s.scope);let d=await o(m,s.paywall);if(I(),t.paywallVersionId?d.id!==t.paywallVersionId:d.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return d},get canRestoreUpgradePaywall(){return Ne()!==null},recoverUpgradePaywall(){let e=Ne();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(q.mode!=="operation"||q.status==="blocked")return null;let{entry:n}=await w.read();if(!n?.run)return null;g(n);let o=b(n),r=o.filter(F=>!F.terminal),i=o.filter(F=>F.terminal==="complete"),s=r.length===1?r[0]:r.length?void 0:i.find(F=>e&&e.runId===n.run?.id&&F.receiptId===e.receiptId)??(i.length===1?i[0]:void 0);if(!s||t&&s.operationId!==t)return null;let d=e?.runId===n.run.id&&e.receiptId===s.receiptId?e.view:void 0,p;try{p=await V(n,s,"recover_purchase",!0)}catch(F){if(!(F instanceof l&&F.status===400&&F.code==="INVALID_REQUEST"))throw F;if(!d)return null;p=await V(n,s)}let y=p.quote;if(!y||X(y)&&(y.timing!=="immediate"||y.execution.provider!=="merchant")||!(p.confirmedAt||p.merchantExecution||p.checkoutUrl||H(p)==="complete"))return null;H(p)!=="complete"&&Z({allowed:n.allowed.filter(F=>m.executionPolicy.allowed.includes(F))},y);let f=be.get(s.operationId),_=n.start.parameters?.commerce,P=n.start.locale??"en",ue=d;if(f){if(typeof _!="object"||!_||!("provider"in _)||typeof _.provider!="string"||!("currency"in _)||typeof _.currency!="string")return null;ue=await this.readPaywall({paywallVersionId:f,locale:P,commerce:{provider:_.provider,currency:_.currency,...X(y)?{intent:"subscription_change"}:{}}})}if(!ue)return null;I();let M=ue,ve=!1,Re=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:he.signal,view:M,quote:y,locale:P,get operation(){return p},get canReselect(){return D.get(s.operationId)===!0},async refresh(){return M},preview:Re,confirm:Re,cancel:Re,async read(){if(ve)throw new DOMException("Purchase view closed","AbortError");p=await V(n,s);let F=await L(n,!1,new Set([s.operationId]));return ve||R(N(F,"operation")),structuredClone(p)},destroy(){ve=!0}}},start(e){let t=J.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(t.operation!=="start"||t.customer||t.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return T(async()=>{let n=(await w.read()).entry;if((!n||j(n)||z(n))&&await ye(!0)==="blocked")return ke();let o=await w.update(r=>{if(r&&!j(r)&&!(z(r)&&r.start.requestId!==t.requestId)){if(r.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return r}return{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:t,allowed:[...m.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return O!==o.start.requestId&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A?Pe(o,q.error):se(o,!0,!0,!0)},`start:${t.funnelId}`)},refresh:Q,confirm:Ae,retry:()=>A?Ae():T(async()=>{let{entry:e}=await w.read();return e?se(e,!0):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return c?.view?T(async()=>{if(!c?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(c.pendingCommands?.find(n=>n.operation==="close"))await c.retry();else if(["running","waiting"].includes(c.view.status)){let n=c.view;await c.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await w.read()).entry;return t&&t.start.requestId!==O?R({mode:"idle",status:"idle",actions:["start"],purchases:[]}):(g(t),R(N(t,"run")))},"close"):Q()},async continueCheckout(e,t){let n=t?await T(async()=>{let{entry:o}=await w.read();if(g(o),!o.run||!b(o).some(i=>i.operationId===t&&!i.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let r=await L(o);return R(N(r,A?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await Q();I(),await e(Pt(n,t))},async terminateCheckout(e){let t=n=>n.actions.includes("continue_checkout")&&n.purchases.some(o=>o.type==="checkout"&&o.operationId===e);if(!t(q)&&!t(await Q()))throw new l("PURCHASE_PENDING","The original Checkout has changed");return T(async()=>{let{entry:n}=await w.read();g(n);let o=b(n).find(i=>i.operationId===e&&!i.terminal);if(!o||!n.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await V(n,o,"terminate_checkout");let r=await L(n,!1,new Set([e]));return R(N(r,A?"operation":"run"))},`terminate:${e}`,n=>n instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(n.code))},subscribe(e){return oe.add(e),()=>{oe.delete(e)}},destroy:qe}}export{et as a,Pt as b,Zt as c};
1
+ import{b as Ge}from"./chunk-XLGNBPGF.js";import{a as ee}from"./chunk-EQUVI5QU.js";import{D as Z,F as Ye,c as Ve,e as Y,j as He,u as ze,v as Qe,x as Be,z as Je}from"./chunk-BQFIJCBA.js";import{a as Ue,b as xe,c as De}from"./chunk-S2S4ROGY.js";import{b as de}from"./chunk-Y55OBV7D.js";import{i as pe}from"./chunk-MOIVJERE.js";import{K as J}from"./chunk-ME6QTD5Y.js";import{A as le,B as X,C as B,E as Te}from"./chunk-3532HSBP.js";import{x as Ce}from"./chunk-67WFVDTV.js";import{b as Me}from"./chunk-55B6CYG6.js";import{a as l}from"./chunk-UGATOG2T.js";import{h as ce}from"./chunk-LFR2LWYC.js";import{a as Le}from"./chunk-5MRSFLQA.js";import{b as a}from"./chunk-W22ESUYY.js";import{a as Ee}from"./chunk-DSPLGTQI.js";var E=J.options,ft=a.discriminatedUnion("operation",[E[1].omit({customerToken:!0}),E[2].omit({customerToken:!0}),E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0}),E[8].omit({customerToken:!0}),He.omit({customerToken:!0})]),Se=a.strictObject({receiptId:a.uuid(),operationId:a.uuid()}),bt=a.discriminatedUnion("operation",[a.strictObject({operation:a.literal("find_purchase")}),a.strictObject({operation:a.literal("recover_start"),intent:a.enum(["lookup","resume","start"]),start:a.strictObject({requestId:E[0].shape.requestId,funnelId:E[0].shape.funnelId,locale:E[0].shape.locale,parameters:E[0].shape.parameters})}),a.strictObject({operation:a.literal("recover_run"),runId:a.uuid(),funnelId:a.uuid()}),a.strictObject({operation:a.literal("recover_purchase"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,includePaywallVersion:a.literal(!0).optional()}),a.strictObject({operation:a.literal("terminate_checkout"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,intent:a.literal("expire_unconfirmed_quote").optional()}),a.strictObject({operation:a.literal("settle_command"),runId:a.uuid(),funnelId:a.uuid(),requestId:a.uuid(),command:a.discriminatedUnion("operation",[E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0})]).optional()}).refine(u=>!u.command||u.requestId===u.command.requestId),a.strictObject({operation:a.literal("run_command"),runId:a.uuid(),funnelId:a.uuid(),command:ft})]),me=a.strictObject({runId:a.uuid(),funnelId:a.uuid(),versionId:a.uuid(),startRequestId:a.uuid(),runExpiresAt:a.iso.datetime({offset:!0}),status:Y.shape.run.shape.status}),G={scope:ce,customerId:a.uuid()},Ke=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("unknown"),target:a.null(),view:a.null(),access:a.null()}),a.strictObject({...G,outcome:a.literal("resolved"),target:me,view:Y.shape.run.nullable(),access:a.discriminatedUnion("type",[a.strictObject({type:a.literal("customer")}),a.strictObject({type:a.literal("operation_only"),cause:a.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((u,m)=>{u.outcome==="resolved"&&(u.access.type==="customer"!=(u.view!==null)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),$e=a.strictObject({...G,target:me,view:Y.shape.run.nullable(),settlement:a.strictObject({requestId:a.uuid(),state:a.enum(["pending","unknown","settled"]),acceptance:a.enum(["accepted","not_accepted","unknown"]),receiptPhase:a.enum(["accepted","processing","done"]).nullable(),basis:a.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:a.uuid().nullable(),operationId:a.uuid().nullable()}),purchase:Y.shape.purchase.unwrap().nullable()}).superRefine((u,m)=>{let h=u.settlement;(h.acceptance==="accepted"!=(h.receiptPhase!==null)||h.acceptance==="accepted"&&h.basis!=="receipt"||h.acceptance==="unknown"&&(h.state!=="unknown"||h.basis!=="none")||h.acceptance!=="accepted"&&(h.operationId!==null||h.receiptId!==null)||h.acceptance==="not_accepted"&&(h.state!=="settled"||!["run_terminal","position_advanced"].includes(h.basis))||u.purchase&&(u.purchase.receiptId!==h.receiptId||u.purchase.operation&&u.purchase.operation.operationId!==h.operationId||u.purchase.quote&&u.purchase.quote.operationId!==h.operationId)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Original command settlement binding differs"})}),We=a.strictObject({...G,target:me,purchase:Y.shape.purchase.unwrap(),paywallVersionId:a.uuid().optional()}).superRefine((u,m)=>{(!u.purchase.operation||typeof u.purchase.canReselect!="boolean"||u.purchase.quote&&u.purchase.quote.operationId!==u.purchase.operation.operationId)&&m.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),Xe=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("none")}),a.strictObject({...G,outcome:a.literal("blocked")}),a.strictObject({...G,outcome:a.literal("found"),target:me,start:a.strictObject({locale:E[0].shape.locale,parameters:E[0].shape.parameters}),purchase:Se})]);var ht=J.options[0].refine(u=>!u.customer&&!u.customerData),wt=a.strictObject({receiptId:a.uuid(),operationId:a.uuid(),terminal:a.enum(["complete","native"]).nullable()}),Ze=a.strictObject({schemaVersion:a.literal(1),baseUrl:a.url(),scope:ce,customerId:a.uuid(),sessionId:a.uuid(),start:ht,allowed:a.array(a.enum(["merchant","record_only","indiana","native"])),run:a.strictObject({id:a.uuid(),versionId:a.uuid(),status:Ve.shape.status,revision:a.number().int().nonnegative(),runExpiresAt:a.iso.datetime({offset:!0}).optional()}).optional(),purchases:a.array(wt).max(100),operationCommand:a.strictObject({operationId:a.uuid(),intent:a.literal("confirm")}).optional(),journal:a.strictObject({revision:a.number().int().nonnegative(),entry:ze.nullable()})});function et(u){return Be({...u,namespace:"purchases",identity:[u.scope.projectId,u.scope.environment,u.customerId]})}function tt(u){let m=new URL(u.baseUrl??Le).href,h=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function S(){u.assertCurrent();try{let C=await u.storage.read();if(u.assertCurrent(),!Number.isSafeInteger(C.revision)||C.revision<0)throw h();let c=C.entry===null?null:Ze.parse(C.entry);if(c&&(c.baseUrl!==m||c.customerId!==u.customerId||c.scope.projectId!==u.scope.projectId||c.scope.environment!==u.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(c?.journal.entry&&(c.journal.entry.scope.projectId!==c.scope.projectId||c.journal.entry.scope.environment!==c.scope.environment||c.journal.entry.funnelId!==c.start.funnelId||c.journal.entry.runId!==c.run?.id||c.journal.entry.versionId!==c.run?.versionId)||c?.operationCommand&&!c.purchases.some(k=>k.operationId===c.operationCommand?.operationId))throw h();return{revision:C.revision,entry:c}}catch(C){throw C instanceof l?C:h()}}async function te(C){for(let c=0;c<8;c++){let k=await S(),O=C(structuredClone(k.entry));if(JSON.stringify(O)===JSON.stringify(k.entry))return O;O&&Ze.parse(O),u.assertCurrent();let U;try{U=await u.storage.write(k.revision,O)}catch{throw h()}if(u.assertCurrent(),U!==null){if(!Number.isSafeInteger(U)||U<=k.revision)throw h();return O}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:S,update:te,baseUrl:m}}var It=5*6e4,yt=2e3,gt=250;function Pt(u,m){let h=u.purchases.find(S=>S.type==="checkout");if(!u.actions.includes("continue_checkout")||h?.type!=="checkout"||m!==void 0&&h.operationId!==m)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return h.checkoutUrl}function fe(u){return!u||u.operation==="close"||u.operation==="back"||u.operation==="shown"||u.operation==="submit"&&u.input.type==="screen"}var nt=()=>({revision:0,entry:null});function Zt(u){let m={...u,scope:{...u.scope},executionPolicy:structuredClone(u.executionPolicy)},h=m.session.snapshot();if(!h)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:S,sessionId:te}=h,C=!1,c=null,k,O,U=null,A=!1,x,ne,re,q={mode:"idle",status:"idle",actions:["start"],purchases:[]},v=new Map,be=new Map,D=new Map,he=new AbortController,oe=new Set,K=Me(m),ae=Ge(K.request);function $(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function I(){if(C||m.session.snapshot()?.customerId!==S)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=tt({...m,customerId:S,assertCurrent:I,storage:m.storage??et({baseUrl:m.baseUrl,scope:m.scope,customerId:S})}),rt,_e=()=>rt??=import("./funnel-paywall-copies-LPOTYSTS.js").then(({createPaywallCopies:e})=>e({baseUrl:m.baseUrl,scope:m.scope,customerId:S})),ot={read:async e=>(await _e()).read(e),write:async(e,t)=>(await _e()).write(e,t)},at=m.session.subscribeIdentity(qe);function qe(){C||(C=!0,clearTimeout(re),he.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),at(),c?.reset(),c=null,U=null,K.dispose(),oe.clear(),v.clear(),D.clear())}function R(e){I();let t=JSON.stringify(e)!==JSON.stringify(q);q=e,clearTimeout(re),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(re=setTimeout(()=>{Q().catch(()=>{})},5e3)),t&&Ee(m.onRecovery,structuredClone(e));for(let n of t?oe:[]){if(C)break;Ee(n,structuredClone(e))}return structuredClone(e)}function g(e){if(I(),!e||e.start.requestId!==O)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function Oe(e){return!e.run&&!b(e).length&&!e.journal.entry&&!e.operationCommand}function we(e){let t=e.journal.entry;return!b(e).length&&!e.operationCommand&&fe(t?.command)&&fe(t?.closeCommand)}function z(e){return!!e.run&&we(e)}function b(e){let t=[...e.purchases],n=e.journal.entry?.purchase;return n&&!t.some(o=>o.operationId===n.operationId)&&t.push({receiptId:n.receiptId,operationId:n.operationId,terminal:null}),t}function j(e){let t=b(e),n=A&&t.length>0&&t.every(o=>o.terminal==="native"&&H(v.get(o.operationId))==="native")&&t.some(o=>{let r=v.get(o.operationId);return!r||D.get(o.operationId)!==!0?!1:B(r)?!0:r.status==="cancelled"&&r.confirmedAt===null&&!r.quoteFinalized&&!r.merchantExecution&&!r.problem&&!!r.quote&&Date.parse(r.quote.expiresAt)<=Date.now()});return e.run&&(n||!["running","waiting"].includes(e.run.status))&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&t.every(o=>o.terminal!==null)}function N(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=b(e).map(f=>{let _=v.get(f.operationId),P=de({quote:_?.quote??null,operation:_??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:D.get(f.operationId)===!0});return f.terminal&&(P.type==="checkout"||P.type==="recover"||P.type==="cancel")?{type:f.terminal,operationId:f.operationId}:P}),r=o.filter(f=>!["complete","native"].includes(f.type)),i=r[0],s=r.length===1&&i?.operationId?v.get(i.operationId):void 0;if(s&&(i?.type==="checkout"||i?.type==="cancel"))try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote)}catch(f){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:$(f)}}let d;if(t==="operation"&&!n&&i?.type==="cancel"&&s?.quote&&!s.problem&&!s.confirmedAt)try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote),Date.parse(s.quote.expiresAt)>Date.now()&&(d={operationId:s.operationId,quote:s.quote})}catch{}let p=o.length>0&&r.length===0,y=j(e)||t==="operation"&&p&&!n&&!e.operationCommand?"complete":i?.type==="checkout"?"checkout":i?.type==="fulfillment"?"fulfillment":i?.type==="recording"?"recording":n||e.operationCommand||i&&i.type!=="cancel"||t==="operation"&&!d?"waiting_result":"ready";return{mode:t,status:y,purchases:o,...d?{confirmation:structuredClone(d)}:{},actions:["refresh",...j(e)||z(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:d?["confirm"]:[],...r.length===1&&i?.type==="checkout"?["continue_checkout"]:[]]}}function H(e){let t=de({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&D.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function Ie(e){if(!e.operation)return;let t=le.parse({...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}});if(t.merchantExecution&&t.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let n=pe(v.get(t.operationId)??null,t);v.set(t.operationId,n),n===t&&D.set(t.operationId,e.canReselect===!0)}async function it(e,t,n){I();for(let i of[e.purchase,e.run.paywall])i&&Ie(i);let o=!1,r=await w.update(i=>{if(i&&i.start.requestId!==t)return o=!0,i;if(g(i),i.run&&(i.run.id!==e.run.id||i.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let s=b(i);for(let d of[e.purchase,e.run.paywall]){let p=d?.operation?.operationId??d?.quote?.operationId;if(!d||!p)continue;let y=s.find(_=>_.operationId===p);if(y&&y.receiptId!==d.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let f=H(v.get(p));y?y.terminal??=f:s.push({receiptId:d.receiptId,operationId:p,terminal:f})}return{...i,purchases:s,run:i.run&&(i.run.revision>e.run.revision||!["running","waiting"].includes(i.run.status)&&["running","waiting"].includes(e.run.status))?i.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});if(o){n();return}g(r),r.run&&!["running","waiting"].includes(r.run.status)&&b(r).some(i=>!i.terminal)&&(r=await L(r,!r.journal.entry?.command&&!r.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(i=>!!i)))),g(r),R(N(r,"run"))}function st(e){let t;return()=>{t||C||(t=setTimeout(()=>{let n=e(),o=n.view;if(C||!o||!["running","waiting"].includes(o.status)||n.pendingCommands?.some(r=>r.operation==="close")){t=void 0;return}t=n.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:o.nodeId,visit:o.visit,revision:o.revision}).catch(()=>{}).finally(()=>{t=void 0})}))}}function ut(e,t){let n=null,o=r=>!!r&&r.start.requestId!==e;return{async read(){let{entry:r}=await w.read();return I(),o(r)?(t(),structuredClone(n??=nt())):(g(r),structuredClone(r.journal))},async write(r,i){let s=null;return await w.update(d=>{if(o(d)){if(t(),!fe(i?.command)||!fe(i?.closeCommand))throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; its Run can only be dismissed");let p=n??=nt();return s=null,p.revision!==r||(s=r+1,n={revision:s,entry:i}),d}if(g(d),d.operationCommand&&i?.command&&i.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return s=null,d.journal.revision!==r?d:(s=r+1,{...d,journal:{revision:s,entry:i}})}),s}}}async function L(e,t=!1,n=new Set){g(e);let o=b(e);for(let i of o){if(i.terminal)continue;let s=n.has(i.operationId)?v.get(i.operationId):void 0;if(s??=await V(e,i),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(s.merchantExecution&&s.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&de({quote:s.quote??null,operation:s,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let d=B(s)?await ae.update({operationId:i.operationId,intent:"cancel"}):await ae.attach({operationId:i.operationId,intent:"cancel"});if(s=le.parse(d.operation),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");s=await V(e,i)}v.set(i.operationId,pe(v.get(i.operationId)??null,s))}let r=await w.update(i=>{g(i);let s=i.operationCommand&&v.get(i.operationCommand.operationId);return{...i,...s&&(s.confirmedAt||s.merchantExecution||!Te(s))?{operationCommand:void 0}:{},purchases:b(i).map(d=>({...d,terminal:d.terminal??H(v.get(d.operationId))}))}});return g(r),r}async function W(e){I();let t=await K.request("funnels",e);return I(),t}async function ct(e){try{return await W(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return W({...e,intent:"resume"})}}async function lt(){let e=ee(Xe,await W({operation:"find_purchase"}));if(e.customerId!==S||e.scope.projectId!==m.scope.projectId||e.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(e.outcome!=="found")return e.outcome;let{target:t,purchase:n}=e;return await w.update(o=>o&&!j(o)&&!z(o)?o:{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...m.executionPolicy.allowed],run:{id:t.runId,versionId:t.versionId,status:t.status,revision:0,runExpiresAt:t.runExpiresAt},purchases:[{...n,terminal:null}],journal:{revision:0,entry:null}}),"found"}let ie;function ye(e){let t=ie;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<It))return t.job;let n={at:Date.now(),job:lt().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw ie===n&&(ie=void 0),o})};return ie=n,n.job}async function V(e,t,n="recover_purchase",o=!1){let r={runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId}},i=n==="recover_purchase"?{...r,operation:n,...o?{includePaywallVersion:!0}:{}}:{...r,operation:"terminate_checkout",...n==="expire_unconfirmed_quote"?{intent:n}:{}},s=ee(We,await W(i));if(ge(e,s),s.purchase.receiptId!==t.receiptId||s.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return Ie(s.purchase),o&&s.paywallVersionId&&be.set(t.operationId,s.paywallVersionId),v.get(t.operationId)}async function Fe(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=ee($e,await W({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(ge(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&Ie(n.purchase);let o=await w.update(r=>{g(r);let i=b(r),{receiptId:s,operationId:d}=n.settlement;if(s&&d){let y=i.find(f=>f.operationId===d);if(y&&y.receiptId!==s)throw new l("INVALID_RESPONSE","Original Receipt changed");y||i.push({receiptId:s,operationId:d,terminal:H(v.get(d))})}let p=n.settlement.state==="settled"?Qe(r.journal.entry,t.requestId):r.journal.entry;return{...r,purchases:i,journal:p===r.journal.entry?r.journal:{revision:r.journal.revision+1,entry:p}}});g(o),e=o}return e}function ge(e,t){if(t.customerId!==S||t.scope.projectId!==m.scope.projectId||t.scope.environment!==m.scope.environment||t.target.funnelId!==e.start.funnelId||t.target.startRequestId!==e.start.requestId||e.run&&(t.target.runId!==e.run.id||t.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function Pe(e,t){if(g(e),e.run&&(e=await Fe(e)),!b(e).length&&j(e))return R(N(e,"operation"));if(we(e)){let r=e.start.requestId;if(!await w.update(s=>s&&s.start.requestId===r&&we(s)?null:s))return c?.reset(),c=null,A=!1,R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}if(!b(e).length)return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(t)});A=!0;let n=b(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(r=>r.terminal==="native"))for(let r of n)H(v.get(r.operationId))!=="native"&&await V(e,r);let o=await dt(await L(e));return R(N(o,"operation"))}async function dt(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return e;let t=b(e).filter(i=>!i.terminal),n=t[0];if(!n||t.length!==1)return e;let o=v.get(n.operationId),r=o?.quote;if(!o||B(o)||!r||X(r)||r.provider!=="merchant"||o.status!=="pending"||o.confirmedAt!==null||o.quoteFinalized||o.checkoutUrl||o.nativePurchase||o.merchantExecution||o.problem||Date.parse(r.expiresAt)>Date.now())return e;try{await V(e,n,"expire_unconfirmed_quote")}catch{return I(),e}return L(e,!1,new Set([n.operationId]))}async function se(e,t=!1,n=!0,o=!1){if(O=e.start.requestId,U=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!c){let r=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:t?"start":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},i;try{i=await ct(r)}catch(P){if(!e.run&&P instanceof l&&(P.status===void 0||P.status>=500))return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:$(P)});throw P}let s=ee(Ke,i);if(s.customerId!==S||s.scope.projectId!==m.scope.projectId||s.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(s.outcome==="unknown"){if(!t&&Oe(e)){let P=e.start.requestId;if(!await w.update(M=>M&&M.start.requestId===P&&Oe(M)?null:M))return R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}})}ge(e,s);let d=await w.update(P=>(g(P),{...P,run:{id:s.target.runId,versionId:s.target.versionId,status:s.target.status,revision:s.view?.revision??P.run?.revision??0,runExpiresAt:s.target.runExpiresAt}}));if(g(d),e=d,s.access.type==="operation_only")return Pe(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await Fe(e);let p=s.view;if(p.locale!==e.start.locale||!Je(p.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");let y=e.start.requestId,f=st(()=>_),_=Ye({...m,customerRun:{runId:s.target.runId,customerId:S,startRequestId:y},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(P=>m.executionPolicy.allowed.includes(P))},funnelCommandStorage:ut(y,f),onAcceptedResponse:P=>it(P,y,f)},{scope:s.scope,run:p});c=_}try{let r=o&&k?.controller===c?performance.now()-k.at:1/0;(r>=yt||c.pendingCommands?.length||(c.viewAgeMs??0)<r)&&(k=void 0,await c.get(),k={controller:c,at:performance.now()}),c.view?.pendingRequest?.requestId===e.start.requestId&&!c.pendingCommands?.length&&await c.resume(c.view.pendingRequest.requestId);for(let s of c.pendingCommands??[])s.operation!=="close"&&await c.settle?.(s.requestId);c.pendingCommands?.length&&await c.retry(),I();let i=(await w.read()).entry;return g(i),R(N(i,"run"))}catch(r){if(I(),n&&r instanceof l&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED")){c.reset(),c=null;let i=(await w.read()).entry;return g(i),se(i,!1,!1,!1)}throw r}}function T(e,t="read",n){if(I(),x)return t==="read"||t===ne?x:x.then(()=>T(e,t,n),()=>T(e,t,n));clearTimeout(re);let o=e().catch(r=>{throw!C&&!n?.(r)&&R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:q.purchases,error:$(r)}),r});return x=o,ne=t,o.then(()=>{x===o&&(x=void 0,ne=void 0)},()=>{x===o&&(x=void 0,ne=void 0)}),o}function pt(e){return e instanceof l&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT"||e.status===409||e.status===429||e.status!==void 0&&e.status>=500)}function Q(e){let t=e?.reuseRecentRead===!0,n=async o=>{let{entry:r}=await w.read();if(!r||j(r)){if(await ye(!1)==="blocked")return ke();({entry:r}=await w.read())}return r?(O&&r.start.requestId!==O&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A&&O===r.start.requestId?Pe(r,q.error):se(r,!1,!0,o)):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})};return T(async()=>{try{return await n(t)}catch(o){if(C||!pt(o))throw o;return I(),c?.reset(),c=null,k=void 0,o.status===409?A=!1:await new Promise(r=>setTimeout(r,gt)),I(),n(!1)}})}function ke(){return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function Ae(){let e=await Q();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:T(async()=>{let t=(await w.read()).entry;if(g(t),!A){if(!c?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let p=c.view.paywall.operation;if(p?.confirmedAt||p?.merchantExecution||p&&!(B(p)?["prepared","quoted"].includes(p.status):p.status==="pending"))return R(N(t,"run"));if(c.pendingCommands?.length)await c.retry();else{let f=c.view;await c.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:f.nodeId,visit:f.visit,revision:f.revision,input:{type:"paywall_confirm",operationId:f.paywall.quote.operationId,...f.paywall.quote.merchantTerms?{merchantConfirmation:Ce(f.paywall.quote.merchantTerms)}:{}}})}let y=(await w.read()).entry;return g(y),R(N(y,"run"))}let n=t.operationCommand?.operationId??q.confirmation?.operationId,o=n&&v.get(n);if(!n||!o||t.journal.entry?.command||t.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");Z({allowed:t.allowed.filter(p=>m.executionPolicy.allowed.includes(p))},o.quote),await w.update(p=>{if(g(p),p.journal.entry?.command||p.journal.entry?.closeCommand||p.operationCommand&&p.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...p,operationCommand:{operationId:n,intent:"confirm"}}});let r={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:Ce(o.quote.merchantTerms)}:{}},i=B(o)?await ae.update(r):await ae.attach(r),s=le.parse(i.operation);if(I(),i.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");v.set(n,pe(o,s));let d=(await w.read()).entry;return g(d),R(N(await L(d,!1,new Set([n])),"operation"))},"confirm")}function mt(e){let t=e?.quote;return t&&X(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Ne(){if(q.mode!=="operation"||q.status==="blocked")return null;let e=q.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?mt(v.get(t)):null}async function je(){I();let{entry:e}=await w.read();return e?j(e)||z(e)?"finished":"pending":"none"}return{get controller(){return c},get recovery(){return structuredClone(q)},get attempt(){return I(),structuredClone(U)},get identitySignal(){return he.signal},get customerId(){return S},retained:je,async pendingFunnel(){I();let{entry:e}=await w.read();return e&&!j(e)&&!z(e)?e.start.funnelId:null},get paywallCopies(){return ot},async findPurchase(){let e=await je();if(e==="pending")return e;let t=await ye(!0);return I(),t==="none"?e:t},async readPaywall(e){I();let t=Ue(e),[n,{readPaywallContent:o},{validateResourceCheck:r}]=await Promise.all([xe(K.request,"resolvePaywall"),import("./paywall-content-JXWPOE3Y.js"),import("./check-response-XGOTG3KL.js")]);I();let i=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),s=await De(K.request,n,i);r(i,s.paywall.check,s.scope);let d=await o(m,s.paywall);if(I(),t.paywallVersionId?d.id!==t.paywallVersionId:d.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return d},get canRestoreUpgradePaywall(){return Ne()!==null},recoverUpgradePaywall(){let e=Ne();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(q.mode!=="operation"||q.status==="blocked")return null;let{entry:n}=await w.read();if(!n?.run)return null;g(n);let o=b(n),r=o.filter(F=>!F.terminal),i=o.filter(F=>F.terminal==="complete"),s=r.length===1?r[0]:r.length?void 0:i.find(F=>e&&e.runId===n.run?.id&&F.receiptId===e.receiptId)??(i.length===1?i[0]:void 0);if(!s||t&&s.operationId!==t)return null;let d=e?.runId===n.run.id&&e.receiptId===s.receiptId?e.view:void 0,p;try{p=await V(n,s,"recover_purchase",!0)}catch(F){if(!(F instanceof l&&F.status===400&&F.code==="INVALID_REQUEST"))throw F;if(!d)return null;p=await V(n,s)}let y=p.quote;if(!y||X(y)&&(y.timing!=="immediate"||y.execution.provider!=="merchant")||!(p.confirmedAt||p.merchantExecution||p.checkoutUrl||H(p)==="complete"))return null;H(p)!=="complete"&&Z({allowed:n.allowed.filter(F=>m.executionPolicy.allowed.includes(F))},y);let f=be.get(s.operationId),_=n.start.parameters?.commerce,P=n.start.locale??"en",ue=d;if(f){if(typeof _!="object"||!_||!("provider"in _)||typeof _.provider!="string"||!("currency"in _)||typeof _.currency!="string")return null;ue=await this.readPaywall({paywallVersionId:f,locale:P,commerce:{provider:_.provider,currency:_.currency,...X(y)?{intent:"subscription_change"}:{}}})}if(!ue)return null;I();let M=ue,ve=!1,Re=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:he.signal,view:M,quote:y,locale:P,get operation(){return p},get canReselect(){return D.get(s.operationId)===!0},async refresh(){return M},preview:Re,confirm:Re,cancel:Re,async read(){if(ve)throw new DOMException("Purchase view closed","AbortError");p=await V(n,s);let F=await L(n,!1,new Set([s.operationId]));return ve||R(N(F,"operation")),structuredClone(p)},destroy(){ve=!0}}},start(e){let t=J.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(t.operation!=="start"||t.customer||t.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return T(async()=>{let n=(await w.read()).entry;if((!n||j(n)||z(n))&&await ye(!0)==="blocked")return ke();let o=await w.update(r=>{if(r&&!j(r)&&!(z(r)&&r.start.requestId!==t.requestId)){if(r.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return r}return{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:t,allowed:[...m.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return O!==o.start.requestId&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A?Pe(o,q.error):se(o,!0,!0,!0)},`start:${t.funnelId}`)},refresh:Q,confirm:Ae,retry:()=>A?Ae():T(async()=>{let{entry:e}=await w.read();return e?se(e,!0):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return c?.view?T(async()=>{if(!c?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(c.pendingCommands?.find(n=>n.operation==="close"))await c.retry();else if(["running","waiting"].includes(c.view.status)){let n=c.view;await c.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await w.read()).entry;return t&&t.start.requestId!==O?R({mode:"idle",status:"idle",actions:["start"],purchases:[]}):(g(t),R(N(t,"run")))},"close"):Q()},async continueCheckout(e,t){let n=t?await T(async()=>{let{entry:o}=await w.read();if(g(o),!o.run||!b(o).some(i=>i.operationId===t&&!i.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let r=await L(o);return R(N(r,A?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await Q();I(),await e(Pt(n,t))},async terminateCheckout(e){let t=n=>n.actions.includes("continue_checkout")&&n.purchases.some(o=>o.type==="checkout"&&o.operationId===e);if(!t(q)&&!t(await Q()))throw new l("PURCHASE_PENDING","The original Checkout has changed");return T(async()=>{let{entry:n}=await w.read();g(n);let o=b(n).find(i=>i.operationId===e&&!i.terminal);if(!o||!n.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await V(n,o,"terminate_checkout");let r=await L(n,!1,new Set([e]));return R(N(r,A?"operation":"run"))},`terminate:${e}`,n=>n instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(n.code))},subscribe(e){return oe.add(e),()=>{oe.delete(e)}},destroy:qe}}export{et as a,Pt as b,Zt as c};
@@ -1 +1 @@
1
- import{i as ie}from"./chunk-LQV7EC5H.js";import{a as N,b as Z,d as ee,f as te,g as ne,j as M,l as re,m as oe,n as se}from"./chunk-CO6HDNOC.js";import{b as K}from"./chunk-FPJ3FE26.js";import{r as V}from"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-6QBSJRAD.js";import"./chunk-KCUE2VFJ.js";import{o as X,p as Y}from"./chunk-Y3W5G4BF.js";import{A as G}from"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import{d as R}from"./chunk-A5WUQLAO.js";import{a as p}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-FEU6XRHV.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-W22ESUYY.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(o){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[o.type];return o.nullable?t.nullable():t}function ae(o,t){let f=u.record(u.string(),R).parse(o);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,n]of Object.entries(f))X.parse({[m]:n});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,n]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(n).parse(f[m]);else if(n.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ve(o,t){return le(o,t,!1)}async function Ae(o,t){return le(o,t,!0)}async function le(o,t,f){t.signal?.throwIfAborted();let m=K.parse(t.content),n=m.document;if(t.closeControl==="content"&&!n.screen.actions.some(e=>e.type==="event"&&e.close))throw new p("INVALID_REQUEST","An authored Close control requires a declared Close action");if(z.has(o))throw new p("CONFLICT","Content is already mounted in this container");let g=ae(t.inputs??{},n.contract),T=new Set(u.array(u.string()).max(40).parse(t.mutableInputs??[]));if(T.size!==(t.mutableInputs?.length??0)||[...T].some(e=>!Object.hasOwn(n.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(n.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let q=Y.parse(t.bindings??[]),d=o.ownerDocument,ue=o.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,H=n.kind==="popup",r=H?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=n.kind,c.setAttribute("aria-label",n.name),c.style.cssText="width:100%;min-width:0",r){r.setAttribute("aria-label",n.name);let e=n.screen.presentation;r.style.cssText=e.type==="inline"?N("content",{type:"fullscreen"},n.screen.theme):N("content",e,n.screen.theme),a=ee(r,n.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),r.append(c),o.append(r)}else o.append(c);let i=!1,A=!1,C=!1,D=!1,de=r?oe(r):se(c,o),S=re(o,t,n.kind,()=>{k()&&(v(),h(t.onDismiss))}),F,j,L=new Promise((e,s)=>{F=e,j=s});L.catch(()=>{});let y=null,E=structuredClone(n.screen),J=G(E,[t.locale,...d.defaultView?.navigator.languages??[]]),x=t.capabilities;E.actions=E.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function v(){i||(i=!0,t.signal?.removeEventListener("abort",v),S.finish("dismissed"),j(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),r?.close(),r?.remove(),c.remove(),z.delete(o),r&&P?.())}let I=()=>{!C||!k()||(v(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(r&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="×",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"关闭":"Close"),ne(e,n.screen.theme),e.addEventListener("click",I),r.prepend(e)}r&&a?.responsive&&(_=Z(r,I,k,t.locale?.startsWith("zh")?"关闭":"Close")),r?.addEventListener("cancel",e=>{e.preventDefault(),I()}),r?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),I())});async function Q(){if(i||!C||A||!y)return;let e=y;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),y=null}catch(s){i||h(t.onError,s)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function W(){if(i)throw new p("CONFLICT","Content host has been destroyed");C||!D||(P??=M(d),S.present(e=>{de(),r&&(a?.latch(),r.showModal(),a?.responsive&&r.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(r,a?.type??n.screen.presentation.type,a?.responsive)),C=!0}))}function U(e){S.finish("error",e),j(e instanceof Error?e:new Error(String(e))),v()}let B={destroy:v,show:W,get pendingAction(){return y?structuredClone(y):null},retryAction:Q,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let s=u.record(u.string(),R).parse(e),b=ae({...g,...s},n.contract);for(let l of Object.keys(s))if(!T.has(l)&&(!Object.hasOwn(g,l)||V(g[l])!==V(b[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(g)!==V(b)&&(w?.update(E,J,{capabilities:x,serverInput:{bindings:q,answers:{},values:b}}),g=b)},updateCapabilities(e){if(i)return;let s=structuredClone(e);w?.updateCapabilities(s),x=s}};z.set(o,B),t.signal?.addEventListener("abort",v,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=M(d),S.start(H,t.locale??n.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:n.name,viewportHeight:n.kind==="page"?ue:a?.responsive?d.defaultView?.innerHeight||800:void 0,...a?.responsive?{viewportWidth:d.defaultView?.innerWidth||1024,hostPresentation:()=>a.type}:{},onResize:e=>{i||a?.responsive&&(c.style.height=`${e}px`,c.style.overflow="clip",a.setContentHeight(e))},onRendered:e=>{if(!i&&(e&&r?.setAttribute("aria-label",e),!D))try{D=!0,f||W(),F()}catch(s){U(s),h(t.onError,s)}},onError:e=>{if(i)return;let s=new Error(e);D||U(s),h(t.onError,s)},onEscape:H?I:void 0,onAction:(e,s,b)=>{if(i||!C||A||y)return;let l=n.screen.actions.find(O=>O.id===e),$=n.contract.outputs[e];if(!(l?.type!=="event"||!$)&&!(l.close&&!k()))try{let O=ce($).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);y=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:s??{},answers:b??{},requestedClose:l.close}),Q()}catch(O){h(t.onError,O)}}}),w.update(E,J,{capabilities:x,serverInput:{bindings:q,answers:{},values:g}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return B}catch(e){throw U(e),e}}export{Ve as mountContent,Ae as prepareContent};
1
+ import{i as ie}from"./chunk-LQV7EC5H.js";import{a as N,b as Z,d as ee,f as te,g as ne,j as M,l as re,m as oe,n as se}from"./chunk-CO6HDNOC.js";import{b as K}from"./chunk-FPJ3FE26.js";import{r as V}from"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import{o as X,p as Y}from"./chunk-Y3W5G4BF.js";import{A as G}from"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import{d as R}from"./chunk-A5WUQLAO.js";import{a as p}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-W22ESUYY.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(o){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[o.type];return o.nullable?t.nullable():t}function ae(o,t){let f=u.record(u.string(),R).parse(o);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,n]of Object.entries(f))X.parse({[m]:n});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,n]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(n).parse(f[m]);else if(n.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ve(o,t){return le(o,t,!1)}async function Ae(o,t){return le(o,t,!0)}async function le(o,t,f){t.signal?.throwIfAborted();let m=K.parse(t.content),n=m.document;if(t.closeControl==="content"&&!n.screen.actions.some(e=>e.type==="event"&&e.close))throw new p("INVALID_REQUEST","An authored Close control requires a declared Close action");if(z.has(o))throw new p("CONFLICT","Content is already mounted in this container");let g=ae(t.inputs??{},n.contract),T=new Set(u.array(u.string()).max(40).parse(t.mutableInputs??[]));if(T.size!==(t.mutableInputs?.length??0)||[...T].some(e=>!Object.hasOwn(n.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(n.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let q=Y.parse(t.bindings??[]),d=o.ownerDocument,ue=o.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,H=n.kind==="popup",r=H?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=n.kind,c.setAttribute("aria-label",n.name),c.style.cssText="width:100%;min-width:0",r){r.setAttribute("aria-label",n.name);let e=n.screen.presentation;r.style.cssText=e.type==="inline"?N("content",{type:"fullscreen"},n.screen.theme):N("content",e,n.screen.theme),a=ee(r,n.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),r.append(c),o.append(r)}else o.append(c);let i=!1,A=!1,C=!1,D=!1,de=r?oe(r):se(c,o),S=re(o,t,n.kind,()=>{k()&&(v(),h(t.onDismiss))}),F,j,L=new Promise((e,s)=>{F=e,j=s});L.catch(()=>{});let y=null,E=structuredClone(n.screen),J=G(E,[t.locale,...d.defaultView?.navigator.languages??[]]),x=t.capabilities;E.actions=E.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function v(){i||(i=!0,t.signal?.removeEventListener("abort",v),S.finish("dismissed"),j(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),r?.close(),r?.remove(),c.remove(),z.delete(o),r&&P?.())}let I=()=>{!C||!k()||(v(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(r&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="×",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"关闭":"Close"),ne(e,n.screen.theme),e.addEventListener("click",I),r.prepend(e)}r&&a?.responsive&&(_=Z(r,I,k,t.locale?.startsWith("zh")?"关闭":"Close")),r?.addEventListener("cancel",e=>{e.preventDefault(),I()}),r?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),I())});async function Q(){if(i||!C||A||!y)return;let e=y;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),y=null}catch(s){i||h(t.onError,s)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function W(){if(i)throw new p("CONFLICT","Content host has been destroyed");C||!D||(P??=M(d),S.present(e=>{de(),r&&(a?.latch(),r.showModal(),a?.responsive&&r.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(r,a?.type??n.screen.presentation.type,a?.responsive)),C=!0}))}function U(e){S.finish("error",e),j(e instanceof Error?e:new Error(String(e))),v()}let B={destroy:v,show:W,get pendingAction(){return y?structuredClone(y):null},retryAction:Q,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let s=u.record(u.string(),R).parse(e),b=ae({...g,...s},n.contract);for(let l of Object.keys(s))if(!T.has(l)&&(!Object.hasOwn(g,l)||V(g[l])!==V(b[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(g)!==V(b)&&(w?.update(E,J,{capabilities:x,serverInput:{bindings:q,answers:{},values:b}}),g=b)},updateCapabilities(e){if(i)return;let s=structuredClone(e);w?.updateCapabilities(s),x=s}};z.set(o,B),t.signal?.addEventListener("abort",v,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=M(d),S.start(H,t.locale??n.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:n.name,viewportHeight:n.kind==="page"?ue:a?.responsive?d.defaultView?.innerHeight||800:void 0,...a?.responsive?{viewportWidth:d.defaultView?.innerWidth||1024,hostPresentation:()=>a.type}:{},onResize:e=>{i||a?.responsive&&(c.style.height=`${e}px`,c.style.overflow="clip",a.setContentHeight(e))},onRendered:e=>{if(!i&&(e&&r?.setAttribute("aria-label",e),!D))try{D=!0,f||W(),F()}catch(s){U(s),h(t.onError,s)}},onError:e=>{if(i)return;let s=new Error(e);D||U(s),h(t.onError,s)},onEscape:H?I:void 0,onAction:(e,s,b)=>{if(i||!C||A||y)return;let l=n.screen.actions.find(O=>O.id===e),$=n.contract.outputs[e];if(!(l?.type!=="event"||!$)&&!(l.close&&!k()))try{let O=ce($).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);y=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:s??{},answers:b??{},requestedClose:l.close}),Q()}catch(O){h(t.onError,O)}}}),w.update(E,J,{capabilities:x,serverInput:{bindings:q,answers:{},values:g}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return B}catch(e){throw U(e),e}}export{Ve as mountContent,Ae as prepareContent};
@@ -1 +1 @@
1
- import{a}from"./chunk-MMHL2KFB.js";import"./chunk-H3LJWAAE.js";import"./chunk-NKYNGR3L.js";import"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-VVBXVJI6.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-XLGNBPGF.js";import"./chunk-EQUVI5QU.js";import"./chunk-FDXBCQBO.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-C4HLVYSU.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-6QBSJRAD.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-FEU6XRHV.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelPurchase};
1
+ import{a}from"./chunk-GFH7OK3S.js";import"./chunk-HKLAHQKF.js";import"./chunk-JYTUTIBB.js";import"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-XWVK4SJA.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-XLGNBPGF.js";import"./chunk-EQUVI5QU.js";import"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelPurchase};
@@ -0,0 +1 @@
1
+ import{a as M}from"./chunk-GFH7OK3S.js";import"./chunk-HKLAHQKF.js";import{a as D,c as I}from"./chunk-JYTUTIBB.js";import"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-XWVK4SJA.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-XLGNBPGF.js";import"./chunk-EQUVI5QU.js";import"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import{a as E}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var k=.8;function q(f,r){let y=f.ownerDocument,w=new AbortController,c=AbortSignal.any([w.signal,r.client.identitySignal,...r.signal?[r.signal]:[]]),a,d,m,H=r.maxAgeMs??D,u=e=>E(r.onEvent,{at:performance.now(),...e});function P(e){e?.copy.destroy(),e?.select(void 0)}function b(){clearTimeout(m);let e=[a,d];a=d=void 0,e.forEach(P)}function O(){let e,t=new Promise(i=>{e=i}),l,o={select:e},s=I(f,{...r,start:t,signal:c,onState(i){u({type:"copy",state:i,...s.reason!==void 0&&{reason:s.reason},...l!==void 0&&{local:l}}),o.watch?.(i),E(r.onState,i)}});return o.copy=s,s.local.then(i=>l=i),o}function g(e){a=e,e.copy.ready.then(t=>{t&&a===e&&F()})}function p(){a||c.aborted||!f.isConnected||y.visibilityState==="hidden"||g(O())}function F(){clearTimeout(m),m=setTimeout(()=>{if(!a||d||c.aborted)return;let e=d=O();e.copy.ready.then(t=>{if(d===e){if(d=void 0,!t||!a)return P(e);P(a),a=e,u({type:"renewed"}),F()}})},H*k)}function S(){y.visibilityState==="hidden"?b():p()}function N(){y.removeEventListener("visibilitychange",S),b()}function T(e){let t=e?.parameters?.commerce;return e?.funnelId===r.funnelId&&e.locale===r.locale&&t?.provider===r.commerce.provider&&t.currency===r.commerce.currency&&t.intent===r.commerce.intent}return c.aborted||(c.addEventListener("abort",N,{once:!0}),y.addEventListener("visibilitychange",S),p()),{open(e){if(c.aborted)return Promise.resolve(null);let t=a;a=void 0,clearTimeout(m);let l=d;d=void 0,l&&g(l);let o=t?.copy,s=e.start,i=!e.hostPaywallTarget&&e.allowNewPurchase!==!1&&(s instanceof Promise||T(s)),C=!1,A=!1,h=n=>{A||(A=!0,u({type:"result",revealed:C,adopted:n}))},x=!1,v=n=>{x||(x=!0,h(!1),u({type:"end",outcome:n}))};u({type:"open",copy:o?.state??"none",used:!!o&&i}),t&&i?t.watch=n=>{n==="shown"?C=!0:n==="adopted"?h(!0):n!=="preparing"&&n!=="ready"&&h(!1)}:h(!1),i?o?.state==="ready"&&o.open():o?.destroy(),t?.select(i?s instanceof Promise?s.then(n=>{if(n&&!T(n)){o?.destroy();return}return n}):s:void 0);let R=M(f,{...e,client:r.client,prepared:i?o:void 0,signal:c,onDismiss(n){return v("dismissed"),queueMicrotask(p),e.onDismiss?.(n)}});return R.then(n=>{n||v("nothing"),p()},()=>{v("error"),p()}),R},destroy(){w.abort()}}}export{q as createFunnelPurchaseEntry};
@@ -1 +1 @@
1
- import{a,b}from"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-6QBSJRAD.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-FEU6XRHV.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as mountFunnelRecoveryPaywall,b as replaceableOriginalSession};
1
+ import{a,b}from"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as mountFunnelRecoveryPaywall,b as replaceableOriginalSession};
@@ -1 +1 @@
1
- import{a,b,c,d}from"./chunk-NKYNGR3L.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-MOIVJERE.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-KCUE2VFJ.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as PRERENDER_MAX_AGE_MS,b as preparedInternals,c as prerenderFunnelPurchase,d as prerenderRunPaywall};
1
+ import{a,b,c,d}from"./chunk-JYTUTIBB.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-MOIVJERE.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-KCUE2VFJ.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as PRERENDER_MAX_AGE_MS,b as preparedInternals,c as prerenderFunnelPurchase,d as prerenderRunPaywall};
@@ -1 +1 @@
1
- import{a,b}from"./chunk-H3LJWAAE.js";import"./chunk-NKYNGR3L.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-F4AIEI5N.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-6QBSJRAD.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-FEU6XRHV.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
1
+ import{a,b}from"./chunk-HKLAHQKF.js";import"./chunk-JYTUTIBB.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-F4AIEI5N.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
package/dist/index.d.ts CHANGED
@@ -3875,6 +3875,17 @@ type FunnelPurchaseEntryEvent = {
3875
3875
  type: "open";
3876
3876
  copy: PreparedState | "none";
3877
3877
  used: boolean;
3878
+ } | {
3879
+ /**
3880
+ * What became of the copy an opening took, once per `open()`. `revealed`: the Customer saw
3881
+ * it. `adopted`: the Run took it over, so the Paywall the Customer saw at the click is the
3882
+ * one they buy from. An opening that had no copy, could not use it, or whose Run presented
3883
+ * its own Paywall instead reports `adopted: false`; count hits by this event, not by
3884
+ * `open.used`.
3885
+ */
3886
+ type: "result";
3887
+ revealed: boolean;
3888
+ adopted: boolean;
3878
3889
  } | {
3879
3890
  /** The opening ended: presented and later dismissed, presented nothing, or failed. */
3880
3891
  type: "end";
@@ -3917,7 +3928,6 @@ type MerchantBridgeOptions = {
3917
3928
  signal?: AbortSignal;
3918
3929
  timeoutMs?: number;
3919
3930
  };
3920
- /** User-facing standard bridge. No catalog secret, refund authority, automatic charge retry or automatic redirect. */
3921
3931
  declare function createMerchantBridge(options: MerchantBridgeOptions): {
3922
3932
  readPresentation(signal?: AbortSignal): Promise<{
3923
3933
  nativeUserId: string;