@tinkerlandai/longplay-sdk 0.10.56 → 0.10.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/check-response-MJHH5FWT.js +1 -0
- package/dist/{chunk-3B6TBSJL.js → chunk-2NIMTHN7.js} +1 -1
- package/dist/{chunk-C6THF4EZ.js → chunk-2OBAMFGZ.js} +1 -1
- package/dist/{chunk-RUAV3HOQ.js → chunk-36VNAOG6.js} +1 -1
- package/dist/{chunk-GH5OMAX4.js → chunk-3LDOPWRV.js} +1 -1
- package/dist/{chunk-MG4LSTTR.js → chunk-554BTJ3I.js} +1 -1
- package/dist/{chunk-XQQZZYX6.js → chunk-5HYA7TBE.js} +1 -1
- package/dist/{chunk-YTT3OR7C.js → chunk-5UVYLTM7.js} +1 -1
- package/dist/{chunk-QVPSTUJ4.js → chunk-6HKQILBV.js} +1 -1
- package/dist/{chunk-R4CEK37U.js → chunk-6K6N5XLO.js} +1 -1
- package/dist/{chunk-XZTHQPBE.js → chunk-725DCRIN.js} +1 -1
- package/dist/{chunk-KRTURVO3.js → chunk-73UFNVEP.js} +1 -1
- package/dist/{chunk-FA4TDZ5J.js → chunk-ADTZEBQF.js} +1 -1
- package/dist/chunk-AJVVXHP7.js +1 -0
- package/dist/{chunk-W66QWQ2D.js → chunk-ANJPFGFN.js} +1 -1
- package/dist/{chunk-F2PTNSHT.js → chunk-BKBWGPNR.js} +1 -1
- package/dist/{chunk-LI5S3AAP.js → chunk-BX2MSRA4.js} +1 -1
- package/dist/{chunk-ZPGXI7SS.js → chunk-C4NXQMSO.js} +1 -1
- package/dist/{chunk-QV6FPIP5.js → chunk-CAE4KIZN.js} +1 -1
- package/dist/{chunk-3IMU6FJB.js → chunk-CJUODAOF.js} +1 -1
- package/dist/{chunk-JHHSO553.js → chunk-DHFJN4JM.js} +2 -2
- package/dist/{chunk-VROUIFSG.js → chunk-EACC667P.js} +1 -1
- package/dist/{chunk-4VKXDWOF.js → chunk-FQJWNS4U.js} +1 -1
- package/dist/{chunk-EJ5YUUWB.js → chunk-GGZG56GR.js} +1 -1
- package/dist/{chunk-VPT5MFDG.js → chunk-HMJTABQ5.js} +2 -2
- package/dist/{chunk-5GFDXNBE.js → chunk-IN32NWRI.js} +1 -1
- package/dist/{chunk-MR475LAL.js → chunk-J4RM5GQP.js} +1 -1
- package/dist/{chunk-OPUEQMJ2.js → chunk-JJIP6BZL.js} +1 -1
- package/dist/{chunk-DJP3QRW3.js → chunk-JXWZS4UM.js} +1 -1
- package/dist/{chunk-O6URZTR3.js → chunk-L64BS65O.js} +1 -1
- package/dist/{chunk-5NDKI3NX.js → chunk-LENTXDGK.js} +1 -1
- package/dist/{chunk-ZOVQW5BP.js → chunk-LOBZ45T3.js} +1 -1
- package/dist/{chunk-V7KYGDFS.js → chunk-LOKH33KR.js} +1 -1
- package/dist/{chunk-5OPOCHOK.js → chunk-M4P6TGBU.js} +1 -1
- package/dist/{chunk-SIEWM7RJ.js → chunk-NL7AXMUA.js} +1 -1
- package/dist/{chunk-YQW3LPLJ.js → chunk-NMBKBC7X.js} +1 -1
- package/dist/{chunk-LEDJ6HS3.js → chunk-NNJVMJUG.js} +1 -1
- package/dist/{chunk-HBMFTVDT.js → chunk-OQ2E3JLZ.js} +1 -1
- package/dist/{chunk-YNBMNXUI.js → chunk-OV46DXRX.js} +1 -1
- package/dist/{chunk-XRCW5N3J.js → chunk-OZK47BUU.js} +1 -1
- package/dist/{chunk-3DH36REB.js → chunk-PVMGYRGE.js} +1 -1
- package/dist/{chunk-BSYGUZTD.js → chunk-QGKROSRD.js} +1 -1
- package/dist/{chunk-7MS4ZLIM.js → chunk-R4BYUK7S.js} +1 -1
- package/dist/{chunk-TPFGWBVS.js → chunk-RJT764B2.js} +1 -1
- package/dist/{chunk-64KBBZD7.js → chunk-RRZZUIFM.js} +1 -1
- package/dist/chunk-UJVNIA5Q.js +1 -0
- package/dist/{chunk-LWGET37W.js → chunk-UWMXBSYO.js} +1 -1
- package/dist/{chunk-YKGPZJTV.js → chunk-WE55LJEN.js} +1 -1
- package/dist/{chunk-MJ3YZT3G.js → chunk-XHZH3E4G.js} +1 -1
- package/dist/{chunk-TKBXL3WV.js → chunk-YA2XHXUS.js} +1 -1
- package/dist/{chunk-UFOIGB3V.js → chunk-YMRWDMIL.js} +1 -1
- package/dist/{content-JV2I65BF.js → content-3MNGXC7L.js} +1 -1
- package/dist/{funnel-host-purchase-6Y6SU3B6.js → funnel-host-purchase-H6BMFIXK.js} +1 -1
- package/dist/{funnel-host-recovery-paywall-PSGZT6MQ.js → funnel-host-recovery-paywall-UQC5FAL4.js} +1 -1
- package/dist/funnel-paywall-prerender-XBEUY6CG.js +1 -0
- package/dist/funnel-route-prediction-ICGW4DPX.js +1 -0
- package/dist/funnel-route-source-64LTJZXN.js +1 -0
- package/dist/funnel-runtime-host-HEBLLPFC.js +1 -0
- package/dist/index.js +1 -1
- package/dist/merchant-bridge-contracts-DEDEIYNU.js +1 -0
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/operation-contracts-RHJJI5NO.js +1 -0
- package/dist/page.js +1 -1
- package/dist/paywall-HZVO7BDI.js +1 -0
- package/dist/paywall-content-KBHI22JD.js +1 -0
- package/dist/paywall-session-TS7G7OEM.js +1 -0
- package/dist/popup.js +1 -1
- package/dist/react-native.js +1 -1
- package/dist/screen-renderer-XBWES3XN.js +1 -0
- package/dist/server.js +1 -1
- package/dist/{visual-dom-5LUN4AHO.js → visual-dom-MH3JDJHJ.js} +1 -1
- package/dist/visual.js +1 -1
- package/package.json +9 -10
- package/dist/check-response-3OBQIMGN.js +0 -1
- package/dist/chunk-7XX5ZESI.js +0 -1
- package/dist/chunk-OG2WLSCL.js +0 -1
- package/dist/funnel-paywall-prerender-BZ3OBCHW.js +0 -1
- package/dist/funnel-route-prediction-4UCZCVH5.js +0 -1
- package/dist/funnel-route-source-FQEIEUDC.js +0 -1
- package/dist/funnel-runtime-host-DBIJVDWC.js +0 -1
- package/dist/merchant-bridge-contracts-GBBL3HTW.js +0 -1
- package/dist/operation-contracts-RDRBT3QK.js +0 -1
- package/dist/paywall-EL57YBHZ.js +0 -1
- package/dist/paywall-content-YLX2XXIT.js +0 -1
- package/dist/paywall-session-6NKVDVYG.js +0 -1
- package/dist/screen-renderer-XIKOUOI5.js +0 -1
- /package/dist/{chunk-JX6MARAN.js → chunk-5YBTU4KS.js} +0 -0
- /package/dist/{chunk-JHHSO553.js.LEGAL.txt → chunk-DHFJN4JM.js.LEGAL.txt} +0 -0
- /package/dist/{chunk-CILM5XMH.js → chunk-DLRCJF6U.js} +0 -0
- /package/dist/{chunk-VPT5MFDG.js.LEGAL.txt → chunk-HMJTABQ5.js.LEGAL.txt} +0 -0
- /package/dist/{chunk-OJM6ORHE.js → chunk-VJIONC4S.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as xe}from"./chunk-3DH36REB.js";import{a as K}from"./chunk-RUAV3HOQ.js";import{D as J,F as Ge,c as Ne,e as M,j as je,u as De,v as Ve,x as He,z as Le}from"./chunk-R4CEK37U.js";import{a as qe,b as Ae,c as Fe}from"./chunk-QV6FPIP5.js";import{K as G}from"./chunk-LI5S3AAP.js";import{a as ie}from"./chunk-FA4TDZ5J.js";import{i as se}from"./chunk-YNBMNXUI.js";import{A as oe,B as ae,C as Y,E as ke}from"./chunk-EJ5YUUWB.js";import{x as we}from"./chunk-SIEWM7RJ.js";import{b as Ue}from"./chunk-XQQZZYX6.js";import{a as l}from"./chunk-YKGPZJTV.js";import{h as re}from"./chunk-XRCW5N3J.js";import{b as Te}from"./chunk-YQW3LPLJ.js";import{b as r}from"./chunk-JX6MARAN.js";import{a as ye}from"./chunk-DSPLGTQI.js";var P=G.options,nt=r.discriminatedUnion("operation",[P[1].omit({customerToken:!0}),P[2].omit({customerToken:!0}),P[3].omit({customerToken:!0}),P[4].omit({customerToken:!0}),P[5].omit({customerToken:!0}),P[6].omit({customerToken:!0}),P[7].omit({customerToken:!0}),P[8].omit({customerToken:!0}),je.omit({customerToken:!0})]),ge=r.strictObject({receiptId:r.uuid(),operationId:r.uuid()}),pt=r.discriminatedUnion("operation",[r.strictObject({operation:r.literal("find_purchase")}),r.strictObject({operation:r.literal("recover_start"),intent:r.enum(["lookup","resume","start"]),start:r.strictObject({requestId:P[0].shape.requestId,funnelId:P[0].shape.funnelId,locale:P[0].shape.locale,parameters:P[0].shape.parameters})}),r.strictObject({operation:r.literal("recover_run"),runId:r.uuid(),funnelId:r.uuid()}),r.strictObject({operation:r.literal("recover_purchase"),runId:r.uuid(),funnelId:r.uuid(),purchase:ge,includePaywallVersion:r.literal(!0).optional()}),r.strictObject({operation:r.literal("terminate_checkout"),runId:r.uuid(),funnelId:r.uuid(),purchase:ge}),r.strictObject({operation:r.literal("settle_command"),runId:r.uuid(),funnelId:r.uuid(),requestId:r.uuid(),command:r.discriminatedUnion("operation",[P[3].omit({customerToken:!0}),P[4].omit({customerToken:!0}),P[5].omit({customerToken:!0}),P[6].omit({customerToken:!0}),P[7].omit({customerToken:!0})]).optional()}).refine(a=>!a.command||a.requestId===a.command.requestId),r.strictObject({operation:r.literal("run_command"),runId:r.uuid(),funnelId:r.uuid(),command:nt})]),ue=r.strictObject({runId:r.uuid(),funnelId:r.uuid(),versionId:r.uuid(),startRequestId:r.uuid(),runExpiresAt:r.iso.datetime({offset:!0}),status:M.shape.run.shape.status}),V={scope:re,customerId:r.uuid()},Me=r.discriminatedUnion("outcome",[r.strictObject({...V,outcome:r.literal("unknown"),target:r.null(),view:r.null(),access:r.null()}),r.strictObject({...V,outcome:r.literal("resolved"),target:ue,view:M.shape.run.nullable(),access:r.discriminatedUnion("type",[r.strictObject({type:r.literal("customer")}),r.strictObject({type:r.literal("operation_only"),cause:r.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((a,p)=>{a.outcome==="resolved"&&(a.access.type==="customer"!=(a.view!==null)||a.view&&(a.view.id!==a.target.runId||a.view.source.id!==a.target.funnelId||a.view.source.versionId!==a.target.versionId||a.view.status!==a.target.status||a.view.runExpiresAt!==a.target.runExpiresAt||a.view.credentialExpiresAt!==null))&&p.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),ze=r.strictObject({...V,target:ue,view:M.shape.run.nullable(),settlement:r.strictObject({requestId:r.uuid(),state:r.enum(["pending","unknown","settled"]),acceptance:r.enum(["accepted","not_accepted","unknown"]),receiptPhase:r.enum(["accepted","processing","done"]).nullable(),basis:r.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:r.uuid().nullable(),operationId:r.uuid().nullable()}),purchase:M.shape.purchase.unwrap().nullable()}).superRefine((a,p)=>{let f=a.settlement;(f.acceptance==="accepted"!=(f.receiptPhase!==null)||f.acceptance==="accepted"&&f.basis!=="receipt"||f.acceptance==="unknown"&&(f.state!=="unknown"||f.basis!=="none")||f.acceptance!=="accepted"&&(f.operationId!==null||f.receiptId!==null)||f.acceptance==="not_accepted"&&(f.state!=="settled"||!["run_terminal","position_advanced"].includes(f.basis))||a.purchase&&(a.purchase.receiptId!==f.receiptId||a.purchase.operation&&a.purchase.operation.operationId!==f.operationId||a.purchase.quote&&a.purchase.quote.operationId!==f.operationId)||a.view&&(a.view.id!==a.target.runId||a.view.source.id!==a.target.funnelId||a.view.source.versionId!==a.target.versionId||a.view.status!==a.target.status||a.view.runExpiresAt!==a.target.runExpiresAt||a.view.credentialExpiresAt!==null))&&p.addIssue({code:"custom",message:"Original command settlement binding differs"})}),Qe=r.strictObject({...V,target:ue,purchase:M.shape.purchase.unwrap(),paywallVersionId:r.uuid().optional()}).superRefine((a,p)=>{(!a.purchase.operation||typeof a.purchase.canReselect!="boolean"||a.purchase.quote&&a.purchase.quote.operationId!==a.purchase.operation.operationId)&&p.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),Be=r.discriminatedUnion("outcome",[r.strictObject({...V,outcome:r.literal("none")}),r.strictObject({...V,outcome:r.literal("blocked")}),r.strictObject({...V,outcome:r.literal("found"),target:ue,start:r.strictObject({locale:P[0].shape.locale,parameters:P[0].shape.parameters}),purchase:ge})]);var rt=G.options[0].refine(a=>!a.customer&&!a.customerData),ot=r.strictObject({receiptId:r.uuid(),operationId:r.uuid(),terminal:r.enum(["complete","native"]).nullable()}),Ye=r.strictObject({schemaVersion:r.literal(1),baseUrl:r.url(),scope:re,customerId:r.uuid(),sessionId:r.uuid(),start:rt,allowed:r.array(r.enum(["merchant","record_only","indiana","native"])),run:r.strictObject({id:r.uuid(),versionId:r.uuid(),status:Ne.shape.status,revision:r.number().int().nonnegative(),runExpiresAt:r.iso.datetime({offset:!0}).optional()}).optional(),purchases:r.array(ot).max(100),operationCommand:r.strictObject({operationId:r.uuid(),intent:r.literal("confirm")}).optional(),journal:r.strictObject({revision:r.number().int().nonnegative(),entry:De.nullable()})});function Je(a){return He({...a,namespace:"purchases",identity:[a.scope.projectId,a.scope.environment,a.customerId]})}function Ke(a){let p=new URL(a.baseUrl??Te).href,f=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function S(){a.assertCurrent();try{let C=await a.storage.read();if(a.assertCurrent(),!Number.isSafeInteger(C.revision)||C.revision<0)throw f();let u=C.entry===null?null:Ye.parse(C.entry);if(u&&(u.baseUrl!==p||u.customerId!==a.customerId||u.scope.projectId!==a.scope.projectId||u.scope.environment!==a.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(u?.journal.entry&&(u.journal.entry.scope.projectId!==u.scope.projectId||u.journal.entry.scope.environment!==u.scope.environment||u.journal.entry.funnelId!==u.start.funnelId||u.journal.entry.runId!==u.run?.id||u.journal.entry.versionId!==u.run?.versionId)||u?.operationCommand&&!u.purchases.some(_=>_.operationId===u.operationCommand?.operationId))throw f();return{revision:C.revision,entry:u}}catch(C){throw C instanceof l?C:f()}}async function $(C){for(let u=0;u<8;u++){let _=await S(),F=C(structuredClone(_.entry));if(JSON.stringify(F)===JSON.stringify(_.entry))return F;F&&Ye.parse(F),a.assertCurrent();let E;try{E=await a.storage.write(_.revision,F)}catch{throw f()}if(a.assertCurrent(),E!==null){if(!Number.isSafeInteger(E)||E<=_.revision)throw f();return F}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:S,update:$,baseUrl:p}}var at=5*6e4;function it(a,p){let f=a.purchases.find(S=>S.type==="checkout");if(!a.actions.includes("continue_checkout")||f?.type!=="checkout"||p!==void 0&&f.operationId!==p)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return f.checkoutUrl}function Vt(a){let p={...a,scope:{...a.scope},executionPolicy:structuredClone(a.executionPolicy)},f=p.session.snapshot();if(!f)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:S,sessionId:$}=f,C=!1,u=null,_,F=null,E=!1,j,W,X,b={mode:"idle",status:"idle",actions:["start"],purchases:[]},y=new Map,Pe=new Map,T=new Map,ce=new AbortController,Z=new Set,z=Ue(p),ee=xe(z.request);function Q(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 g(){if(C||p.session.snapshot()?.customerId!==S)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let h=Ke({...p,customerId:S,assertCurrent:g,storage:p.storage??Je({baseUrl:p.baseUrl,scope:p.scope,customerId:S})}),$e=p.session.subscribeIdentity(ve);function ve(){C||(C=!0,clearTimeout(X),ce.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),$e(),u?.reset(),u=null,F=null,z.dispose(),Z.clear(),y.clear(),T.clear())}function v(e){g();let t=JSON.stringify(e)!==JSON.stringify(b);b=e,clearTimeout(X),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(X=setTimeout(()=>{L().catch(()=>{})},5e3)),t&&ye(p.onRecovery,structuredClone(e));for(let n of t?Z:[]){if(C)break;ye(n,structuredClone(e))}return structuredClone(e)}function w(e){if(g(),!e||e.start.requestId!==_)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function k(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 U(e){let t=k(e),n=E&&t.length>0&&t.every(o=>o.terminal==="native"&&x(y.get(o.operationId))==="native")&&t.some(o=>{let i=y.get(o.operationId);return!!i&&Y(i)&&T.get(o.operationId)===!0});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 A(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=k(e).map(I=>{let q=y.get(I.operationId);return I.terminal&&!q?{type:I.terminal,operationId:I.operationId}:ie({quote:q?.quote??null,operation:q??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:T.get(I.operationId)===!0})}),i=o.filter(I=>!["complete","native"].includes(I.type)),s=i[0],c=i.length===1&&s?.operationId?y.get(s.operationId):void 0;if(c&&(s?.type==="checkout"||s?.type==="cancel"))try{J({allowed:e.allowed.filter(I=>p.executionPolicy.allowed.includes(I))},c.quote)}catch(I){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:Q(I)}}let m;if(t==="operation"&&!n&&s?.type==="cancel"&&c?.quote&&!c.problem&&!c.confirmedAt)try{J({allowed:e.allowed.filter(I=>p.executionPolicy.allowed.includes(I))},c.quote),Date.parse(c.quote.expiresAt)>Date.now()&&(m={operationId:c.operationId,quote:c.quote})}catch{}let d=o.length>0&&i.length===0,R=U(e)||t==="operation"&&d&&!n&&!e.operationCommand?"complete":s?.type==="checkout"?"checkout":s?.type==="fulfillment"?"fulfillment":s?.type==="recording"?"recording":n||e.operationCommand||s&&s.type!=="cancel"||t==="operation"&&!m?"waiting_result":"ready";return{mode:t,status:R,purchases:o,...m?{confirmation:structuredClone(m)}:{},actions:["refresh",...U(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:m?["confirm"]:[],...i.length===1&&s?.type==="checkout"?["continue_checkout"]:[]]}}function x(e){let t=ie({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&T.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function le(e){if(!e.operation)return;let t=oe.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=se(y.get(t.operationId)??null,t);y.set(t.operationId,n),n===t&&T.set(t.operationId,e.canReselect===!0)}async function We(e){g();for(let n of[e.purchase,e.run.paywall])n&&le(n);let t=await h.update(n=>{if(w(n),n.run&&(n.run.id!==e.run.id||n.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let o=k(n);for(let i of[e.purchase,e.run.paywall]){let s=i?.operation?.operationId??i?.quote?.operationId;if(!i||!s)continue;let c=o.find(d=>d.operationId===s);if(c&&c.receiptId!==i.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let m=x(y.get(s));c?c.terminal??=m:o.push({receiptId:i.receiptId,operationId:s,terminal:m})}return{...n,purchases:o,run:n.run&&(n.run.revision>e.run.revision||!["running","waiting"].includes(n.run.status)&&["running","waiting"].includes(e.run.status))?n.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});w(t),t.run&&!["running","waiting"].includes(t.run.status)&&k(t).some(n=>!n.terminal)&&(t=await H(t,!t.journal.entry?.command&&!t.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(n=>!!n)))),w(t),v(A(t,"run"))}function Xe(){return{async read(){let{entry:e}=await h.read();return w(e),structuredClone(e.journal)},async write(e,t){let n=null;return await h.update(o=>{if(w(o),o.operationCommand&&t?.command&&t.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return n=null,o.journal.revision!==e?o:(n=e+1,{...o,journal:{revision:n,entry:t}})}),n}}}async function H(e,t=!1,n=new Set){w(e);let o=k(e);for(let s of o){if(s.terminal)continue;let c=n.has(s.operationId)?y.get(s.operationId):void 0;if(c??=await D(e,s),g(),c.operationId!==s.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(c.merchantExecution&&c.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&ie({quote:c.quote??null,operation:c,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let m=Y(c)?await ee.update({operationId:s.operationId,intent:"cancel"}):await ee.attach({operationId:s.operationId,intent:"cancel"});if(c=oe.parse(m.operation),g(),c.operationId!==s.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");c=await D(e,s)}y.set(s.operationId,se(y.get(s.operationId)??null,c))}let i=await h.update(s=>{w(s);let c=s.operationCommand&&y.get(s.operationCommand.operationId);return{...s,...c&&(c.confirmedAt||c.merchantExecution||!ke(c))?{operationCommand:void 0}:{},purchases:k(s).map(m=>({...m,terminal:m.terminal??x(y.get(m.operationId))}))}});return w(i),i}async function B(e){g();let t=await z.request("funnels",e);return g(),t}async function Ze(e){try{return await B(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return B({...e,intent:"resume"})}}async function et(){let e=K(Be,await B({operation:"find_purchase"}));if(e.customerId!==S||e.scope.projectId!==p.scope.projectId||e.scope.environment!==p.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 h.update(o=>o&&!U(o)?o:{schemaVersion:1,baseUrl:h.baseUrl,scope:p.scope,customerId:S,sessionId:$,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...p.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 te;function de(e){let t=te;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<at))return t.job;let n={at:Date.now(),job:et().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw te===n&&(te=void 0),o})};return te=n,n.job}async function D(e,t,n="recover_purchase",o=!1){let i=K(Qe,await B({operation:n,runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId},...o?{includePaywallVersion:!0}:{}}));if(pe(e,i),i.purchase.receiptId!==t.receiptId||i.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return le(i.purchase),o&&i.paywallVersionId&&Pe.set(t.operationId,i.paywallVersionId),y.get(t.operationId)}async function Se(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=K(ze,await B({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(pe(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&le(n.purchase);let o=await h.update(i=>{w(i);let s=k(i),{receiptId:c,operationId:m}=n.settlement;if(c&&m){let R=s.find(I=>I.operationId===m);if(R&&R.receiptId!==c)throw new l("INVALID_RESPONSE","Original Receipt changed");R||s.push({receiptId:c,operationId:m,terminal:x(y.get(m))})}let d=n.settlement.state==="settled"?Ve(i.journal.entry,t.requestId):i.journal.entry;return{...i,purchases:s,journal:d===i.journal.entry?i.journal:{revision:i.journal.revision+1,entry:d}}});w(o),e=o}return e}function pe(e,t){if(t.customerId!==S||t.scope.projectId!==p.scope.projectId||t.scope.environment!==p.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 me(e,t){if(w(e),e.run&&(e=await Se(e)),!k(e).length&&U(e))return v(A(e,"operation"));if(!k(e).length)return v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:Q(t)});E=!0;let n=k(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(i=>i.terminal==="native"))for(let i of n)x(y.get(i.operationId))!=="native"&&await D(e,i);let o=await H(e);return v(A(o,"operation"))}async function ne(e,t=!1,n=!0){if(_=e.start.requestId,F=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!u){let o=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 Ze(o)}catch(d){if(!e.run&&d instanceof l&&(d.status===void 0||d.status>=500))return v({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:b.purchases,error:Q(d)});throw d}let s=K(Me,i);if(s.customerId!==S||s.scope.projectId!==p.scope.projectId||s.scope.environment!==p.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(s.outcome==="unknown")return v({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:b.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}});pe(e,s);let c=await h.update(d=>(w(d),{...d,run:{id:s.target.runId,versionId:s.target.versionId,status:s.target.status,revision:s.view?.revision??d.run?.revision??0,runExpiresAt:s.target.runExpiresAt}}));if(w(c),e=c,s.access.type==="operation_only")return me(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await Se(e);let m=s.view;if(m.locale!==e.start.locale||!Le(m.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");u=Ge({...p,customerRun:{runId:s.target.runId,customerId:S,startRequestId:e.start.requestId},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(d=>p.executionPolicy.allowed.includes(d))},funnelCommandStorage:Xe(),onAcceptedResponse:We},{scope:s.scope,run:m})}try{await u.get(),u.view?.pendingRequest?.requestId===e.start.requestId&&!u.pendingCommands?.length&&await u.resume(u.view.pendingRequest.requestId);for(let i of u.pendingCommands??[])i.operation!=="close"&&await u.settle?.(i.requestId);u.pendingCommands?.length&&await u.retry(),g();let o=(await h.read()).entry;return w(o),v(A(o,"run"))}catch(o){if(g(),n&&o instanceof l&&(o.status===401||o.status===409&&o.reason==="STATE_CHANGED")){u.reset(),u=null;let i=(await h.read()).entry;return w(i),ne(i,!1,!1)}throw o}}function N(e,t="read",n){if(g(),j)return t==="read"||t===W?j:j.then(()=>N(e,t,n),()=>N(e,t,n));clearTimeout(X);let o=e().catch(i=>{throw!C&&!n?.(i)&&v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:b.purchases,error:Q(i)}),i});return j=o,W=t,o.then(()=>{j===o&&(j=void 0,W=void 0)},()=>{j===o&&(j=void 0,W=void 0)}),o}function L(){return N(async()=>{let{entry:e}=await h.read();if(!e||U(e)){if(await de(!1)==="blocked")return Ce();({entry:e}=await h.read())}return e?(_&&e.start.requestId!==_&&(u?.reset(),u=null,y.clear(),T.clear(),E=!1),E&&_===e.start.requestId?me(e,b.error):ne(e)):v({mode:"idle",status:"idle",actions:["start"],purchases:[]})})}function Ce(){return v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:Q(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function Re(){let e=await L();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:N(async()=>{let t=(await h.read()).entry;if(w(t),!E){if(!u?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let d=u.view.paywall.operation;if(d?.confirmedAt||d?.merchantExecution||d&&!(Y(d)?["prepared","quoted"].includes(d.status):d.status==="pending"))return v(A(t,"run"));if(u.pendingCommands?.length)await u.retry();else{let I=u.view;await u.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:I.nodeId,visit:I.visit,revision:I.revision,input:{type:"paywall_confirm",operationId:I.paywall.quote.operationId,...I.paywall.quote.merchantTerms?{merchantConfirmation:we(I.paywall.quote.merchantTerms)}:{}}})}let R=(await h.read()).entry;return w(R),v(A(R,"run"))}let n=t.operationCommand?.operationId??b.confirmation?.operationId,o=n&&y.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");J({allowed:t.allowed.filter(d=>p.executionPolicy.allowed.includes(d))},o.quote),await h.update(d=>{if(w(d),d.journal.entry?.command||d.journal.entry?.closeCommand||d.operationCommand&&d.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...d,operationCommand:{operationId:n,intent:"confirm"}}});let i={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:we(o.quote.merchantTerms)}:{}},s=Y(o)?await ee.update(i):await ee.attach(i),c=oe.parse(s.operation);if(g(),s.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");y.set(n,se(o,c));let m=(await h.read()).entry;return w(m),v(A(await H(m,!1,new Set([n])),"operation"))},"confirm")}function tt(e){let t=e?.quote;return t&&ae(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Ee(){if(b.mode!=="operation"||b.status==="blocked")return null;let e=b.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?tt(y.get(t)):null}async function be(){g();let{entry:e}=await h.read();return e?U(e)?"finished":"pending":"none"}return{get controller(){return u},get recovery(){return structuredClone(b)},get attempt(){return g(),structuredClone(F)},get identitySignal(){return ce.signal},get customerId(){return S},retained:be,async findPurchase(){let e=await be();if(e==="pending")return e;let t=await de(!0);return g(),t==="none"?e:t},async readPaywall(e){g();let t=qe(e),[n,{readPaywallContent:o},{validateResourceCheck:i}]=await Promise.all([Ae(z.request,"resolvePaywall"),import("./paywall-content-YLX2XXIT.js"),import("./check-response-3OBQIMGN.js")]);g();let s=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),c=await Fe(z.request,n,s);i(s,c.paywall.check,c.scope);let m=await o(p,c.paywall);if(g(),t.paywallVersionId?m.id!==t.paywallVersionId:m.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return m},get canRestoreUpgradePaywall(){return Ee()!==null},recoverUpgradePaywall(){let e=Ee();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(b.mode!=="operation"||b.status==="blocked")return null;let{entry:n}=await h.read();if(!n?.run)return null;w(n);let o=k(n),i=o.filter(O=>!O.terminal),s=o.filter(O=>O.terminal==="complete"),c=i.length===1?i[0]:i.length?void 0:s.find(O=>e&&e.runId===n.run?.id&&O.receiptId===e.receiptId)??(s.length===1?s[0]:void 0);if(!c||t&&c.operationId!==t)return null;let m=e?.runId===n.run.id&&e.receiptId===c.receiptId?e.view:void 0,d;try{d=await D(n,c,"recover_purchase",!0)}catch(O){if(!(O instanceof l&&O.status===400&&O.code==="INVALID_REQUEST"))throw O;if(!m)return null;d=await D(n,c)}let R=d.quote;if(!R||ae(R)&&(R.timing!=="immediate"||R.execution.provider!=="merchant")||!(d.confirmedAt||d.merchantExecution||d.checkoutUrl||x(d)==="complete"))return null;x(d)!=="complete"&&J({allowed:n.allowed.filter(O=>p.executionPolicy.allowed.includes(O))},R);let I=Pe.get(c.operationId),q=n.start.parameters?.commerce,Oe=n.start.locale??"en",fe=m;if(I){if(typeof q!="object"||!q||!("provider"in q)||typeof q.provider!="string"||!("currency"in q)||typeof q.currency!="string")return null;fe=await this.readPaywall({paywallVersionId:I,locale:Oe,commerce:{provider:q.provider,currency:q.currency,...ae(R)?{intent:"subscription_change"}:{}}})}if(!fe)return null;g();let _e=fe,he=!1,Ie=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:ce.signal,view:_e,quote:R,locale:Oe,get operation(){return d},get canReselect(){return T.get(c.operationId)===!0},async refresh(){return _e},preview:Ie,confirm:Ie,cancel:Ie,async read(){if(he)throw new DOMException("Purchase view closed","AbortError");d=await D(n,c);let O=await H(n,!1,new Set([c.operationId]));return he||v(A(O,"operation")),structuredClone(d)},destroy(){he=!0}}},start(e){let t=G.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 N(async()=>{let n=(await h.read()).entry;if((!n||U(n))&&await de(!0)==="blocked")return Ce();let o=await h.update(i=>{if(i&&!U(i)){if(i.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return i}return{schemaVersion:1,baseUrl:h.baseUrl,scope:p.scope,customerId:S,sessionId:$,start:t,allowed:[...p.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return _!==o.start.requestId&&(u?.reset(),u=null,y.clear(),T.clear(),E=!1),E?me(o,b.error):ne(o,!0)},`start:${t.funnelId}`)},refresh:L,confirm:Re,retry:()=>E?Re():N(async()=>{let{entry:e}=await h.read();return e?ne(e,!0):v({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return u?.view?N(async()=>{if(!u?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(u.pendingCommands?.find(n=>n.operation==="close"))await u.retry();else if(["running","waiting"].includes(u.view.status)){let n=u.view;await u.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await h.read()).entry;return w(t),v(A(t,"run"))},"close"):L()},async continueCheckout(e,t){let n=t?await N(async()=>{let{entry:o}=await h.read();if(w(o),!o.run||!k(o).some(s=>s.operationId===t&&!s.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let i=await H(o);return v(A(i,E?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await L();g(),await e(it(n,t))},async terminateCheckout(e){let t=await L();if(!t.purchases.find(o=>o.type==="checkout"&&o.operationId===e)||!t.actions.includes("continue_checkout"))throw new l("PURCHASE_PENDING","The original Checkout has changed");return N(async()=>{let{entry:o}=await h.read();w(o);let i=k(o).find(c=>c.operationId===e&&!c.terminal);if(!i||!o.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await D(o,i,"terminate_checkout");let s=await H(o,!1,new Set([e]));return v(A(s,E?"operation":"run"))},`terminate:${e}`,o=>o instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(o.code))},subscribe(e){return Z.add(e),()=>{Z.delete(e)}},destroy:ve}}export{Je as a,it as b,Vt as c};
|
|
1
|
+
import{b as xe}from"./chunk-PVMGYRGE.js";import{a as K}from"./chunk-36VNAOG6.js";import{D as J,F as Ge,c as Ne,e as M,j as je,u as De,v as Ve,x as He,z as Le}from"./chunk-6K6N5XLO.js";import{a as qe,b as Ae,c as Fe}from"./chunk-CAE4KIZN.js";import{K as G}from"./chunk-BX2MSRA4.js";import{a as ie}from"./chunk-ADTZEBQF.js";import{i as se}from"./chunk-OV46DXRX.js";import{A as oe,B as ae,C as Y,E as ke}from"./chunk-GGZG56GR.js";import{x as we}from"./chunk-NL7AXMUA.js";import{b as Ue}from"./chunk-5HYA7TBE.js";import{a as l}from"./chunk-WE55LJEN.js";import{h as re}from"./chunk-OZK47BUU.js";import{b as Te}from"./chunk-NMBKBC7X.js";import{b as r}from"./chunk-5YBTU4KS.js";import{a as ye}from"./chunk-DSPLGTQI.js";var P=G.options,nt=r.discriminatedUnion("operation",[P[1].omit({customerToken:!0}),P[2].omit({customerToken:!0}),P[3].omit({customerToken:!0}),P[4].omit({customerToken:!0}),P[5].omit({customerToken:!0}),P[6].omit({customerToken:!0}),P[7].omit({customerToken:!0}),P[8].omit({customerToken:!0}),je.omit({customerToken:!0})]),ge=r.strictObject({receiptId:r.uuid(),operationId:r.uuid()}),pt=r.discriminatedUnion("operation",[r.strictObject({operation:r.literal("find_purchase")}),r.strictObject({operation:r.literal("recover_start"),intent:r.enum(["lookup","resume","start"]),start:r.strictObject({requestId:P[0].shape.requestId,funnelId:P[0].shape.funnelId,locale:P[0].shape.locale,parameters:P[0].shape.parameters})}),r.strictObject({operation:r.literal("recover_run"),runId:r.uuid(),funnelId:r.uuid()}),r.strictObject({operation:r.literal("recover_purchase"),runId:r.uuid(),funnelId:r.uuid(),purchase:ge,includePaywallVersion:r.literal(!0).optional()}),r.strictObject({operation:r.literal("terminate_checkout"),runId:r.uuid(),funnelId:r.uuid(),purchase:ge}),r.strictObject({operation:r.literal("settle_command"),runId:r.uuid(),funnelId:r.uuid(),requestId:r.uuid(),command:r.discriminatedUnion("operation",[P[3].omit({customerToken:!0}),P[4].omit({customerToken:!0}),P[5].omit({customerToken:!0}),P[6].omit({customerToken:!0}),P[7].omit({customerToken:!0})]).optional()}).refine(a=>!a.command||a.requestId===a.command.requestId),r.strictObject({operation:r.literal("run_command"),runId:r.uuid(),funnelId:r.uuid(),command:nt})]),ue=r.strictObject({runId:r.uuid(),funnelId:r.uuid(),versionId:r.uuid(),startRequestId:r.uuid(),runExpiresAt:r.iso.datetime({offset:!0}),status:M.shape.run.shape.status}),V={scope:re,customerId:r.uuid()},Me=r.discriminatedUnion("outcome",[r.strictObject({...V,outcome:r.literal("unknown"),target:r.null(),view:r.null(),access:r.null()}),r.strictObject({...V,outcome:r.literal("resolved"),target:ue,view:M.shape.run.nullable(),access:r.discriminatedUnion("type",[r.strictObject({type:r.literal("customer")}),r.strictObject({type:r.literal("operation_only"),cause:r.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((a,p)=>{a.outcome==="resolved"&&(a.access.type==="customer"!=(a.view!==null)||a.view&&(a.view.id!==a.target.runId||a.view.source.id!==a.target.funnelId||a.view.source.versionId!==a.target.versionId||a.view.status!==a.target.status||a.view.runExpiresAt!==a.target.runExpiresAt||a.view.credentialExpiresAt!==null))&&p.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),ze=r.strictObject({...V,target:ue,view:M.shape.run.nullable(),settlement:r.strictObject({requestId:r.uuid(),state:r.enum(["pending","unknown","settled"]),acceptance:r.enum(["accepted","not_accepted","unknown"]),receiptPhase:r.enum(["accepted","processing","done"]).nullable(),basis:r.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:r.uuid().nullable(),operationId:r.uuid().nullable()}),purchase:M.shape.purchase.unwrap().nullable()}).superRefine((a,p)=>{let f=a.settlement;(f.acceptance==="accepted"!=(f.receiptPhase!==null)||f.acceptance==="accepted"&&f.basis!=="receipt"||f.acceptance==="unknown"&&(f.state!=="unknown"||f.basis!=="none")||f.acceptance!=="accepted"&&(f.operationId!==null||f.receiptId!==null)||f.acceptance==="not_accepted"&&(f.state!=="settled"||!["run_terminal","position_advanced"].includes(f.basis))||a.purchase&&(a.purchase.receiptId!==f.receiptId||a.purchase.operation&&a.purchase.operation.operationId!==f.operationId||a.purchase.quote&&a.purchase.quote.operationId!==f.operationId)||a.view&&(a.view.id!==a.target.runId||a.view.source.id!==a.target.funnelId||a.view.source.versionId!==a.target.versionId||a.view.status!==a.target.status||a.view.runExpiresAt!==a.target.runExpiresAt||a.view.credentialExpiresAt!==null))&&p.addIssue({code:"custom",message:"Original command settlement binding differs"})}),Qe=r.strictObject({...V,target:ue,purchase:M.shape.purchase.unwrap(),paywallVersionId:r.uuid().optional()}).superRefine((a,p)=>{(!a.purchase.operation||typeof a.purchase.canReselect!="boolean"||a.purchase.quote&&a.purchase.quote.operationId!==a.purchase.operation.operationId)&&p.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),Be=r.discriminatedUnion("outcome",[r.strictObject({...V,outcome:r.literal("none")}),r.strictObject({...V,outcome:r.literal("blocked")}),r.strictObject({...V,outcome:r.literal("found"),target:ue,start:r.strictObject({locale:P[0].shape.locale,parameters:P[0].shape.parameters}),purchase:ge})]);var rt=G.options[0].refine(a=>!a.customer&&!a.customerData),ot=r.strictObject({receiptId:r.uuid(),operationId:r.uuid(),terminal:r.enum(["complete","native"]).nullable()}),Ye=r.strictObject({schemaVersion:r.literal(1),baseUrl:r.url(),scope:re,customerId:r.uuid(),sessionId:r.uuid(),start:rt,allowed:r.array(r.enum(["merchant","record_only","indiana","native"])),run:r.strictObject({id:r.uuid(),versionId:r.uuid(),status:Ne.shape.status,revision:r.number().int().nonnegative(),runExpiresAt:r.iso.datetime({offset:!0}).optional()}).optional(),purchases:r.array(ot).max(100),operationCommand:r.strictObject({operationId:r.uuid(),intent:r.literal("confirm")}).optional(),journal:r.strictObject({revision:r.number().int().nonnegative(),entry:De.nullable()})});function Je(a){return He({...a,namespace:"purchases",identity:[a.scope.projectId,a.scope.environment,a.customerId]})}function Ke(a){let p=new URL(a.baseUrl??Te).href,f=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function S(){a.assertCurrent();try{let C=await a.storage.read();if(a.assertCurrent(),!Number.isSafeInteger(C.revision)||C.revision<0)throw f();let u=C.entry===null?null:Ye.parse(C.entry);if(u&&(u.baseUrl!==p||u.customerId!==a.customerId||u.scope.projectId!==a.scope.projectId||u.scope.environment!==a.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(u?.journal.entry&&(u.journal.entry.scope.projectId!==u.scope.projectId||u.journal.entry.scope.environment!==u.scope.environment||u.journal.entry.funnelId!==u.start.funnelId||u.journal.entry.runId!==u.run?.id||u.journal.entry.versionId!==u.run?.versionId)||u?.operationCommand&&!u.purchases.some(_=>_.operationId===u.operationCommand?.operationId))throw f();return{revision:C.revision,entry:u}}catch(C){throw C instanceof l?C:f()}}async function $(C){for(let u=0;u<8;u++){let _=await S(),F=C(structuredClone(_.entry));if(JSON.stringify(F)===JSON.stringify(_.entry))return F;F&&Ye.parse(F),a.assertCurrent();let E;try{E=await a.storage.write(_.revision,F)}catch{throw f()}if(a.assertCurrent(),E!==null){if(!Number.isSafeInteger(E)||E<=_.revision)throw f();return F}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:S,update:$,baseUrl:p}}var at=5*6e4;function it(a,p){let f=a.purchases.find(S=>S.type==="checkout");if(!a.actions.includes("continue_checkout")||f?.type!=="checkout"||p!==void 0&&f.operationId!==p)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return f.checkoutUrl}function Vt(a){let p={...a,scope:{...a.scope},executionPolicy:structuredClone(a.executionPolicy)},f=p.session.snapshot();if(!f)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:S,sessionId:$}=f,C=!1,u=null,_,F=null,E=!1,j,W,X,b={mode:"idle",status:"idle",actions:["start"],purchases:[]},y=new Map,Pe=new Map,T=new Map,ce=new AbortController,Z=new Set,z=Ue(p),ee=xe(z.request);function Q(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 g(){if(C||p.session.snapshot()?.customerId!==S)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let h=Ke({...p,customerId:S,assertCurrent:g,storage:p.storage??Je({baseUrl:p.baseUrl,scope:p.scope,customerId:S})}),$e=p.session.subscribeIdentity(ve);function ve(){C||(C=!0,clearTimeout(X),ce.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),$e(),u?.reset(),u=null,F=null,z.dispose(),Z.clear(),y.clear(),T.clear())}function v(e){g();let t=JSON.stringify(e)!==JSON.stringify(b);b=e,clearTimeout(X),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(X=setTimeout(()=>{L().catch(()=>{})},5e3)),t&&ye(p.onRecovery,structuredClone(e));for(let n of t?Z:[]){if(C)break;ye(n,structuredClone(e))}return structuredClone(e)}function w(e){if(g(),!e||e.start.requestId!==_)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function k(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 U(e){let t=k(e),n=E&&t.length>0&&t.every(o=>o.terminal==="native"&&x(y.get(o.operationId))==="native")&&t.some(o=>{let i=y.get(o.operationId);return!!i&&Y(i)&&T.get(o.operationId)===!0});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 A(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=k(e).map(I=>{let q=y.get(I.operationId);return I.terminal&&!q?{type:I.terminal,operationId:I.operationId}:ie({quote:q?.quote??null,operation:q??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:T.get(I.operationId)===!0})}),i=o.filter(I=>!["complete","native"].includes(I.type)),s=i[0],c=i.length===1&&s?.operationId?y.get(s.operationId):void 0;if(c&&(s?.type==="checkout"||s?.type==="cancel"))try{J({allowed:e.allowed.filter(I=>p.executionPolicy.allowed.includes(I))},c.quote)}catch(I){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:Q(I)}}let m;if(t==="operation"&&!n&&s?.type==="cancel"&&c?.quote&&!c.problem&&!c.confirmedAt)try{J({allowed:e.allowed.filter(I=>p.executionPolicy.allowed.includes(I))},c.quote),Date.parse(c.quote.expiresAt)>Date.now()&&(m={operationId:c.operationId,quote:c.quote})}catch{}let d=o.length>0&&i.length===0,R=U(e)||t==="operation"&&d&&!n&&!e.operationCommand?"complete":s?.type==="checkout"?"checkout":s?.type==="fulfillment"?"fulfillment":s?.type==="recording"?"recording":n||e.operationCommand||s&&s.type!=="cancel"||t==="operation"&&!m?"waiting_result":"ready";return{mode:t,status:R,purchases:o,...m?{confirmation:structuredClone(m)}:{},actions:["refresh",...U(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:m?["confirm"]:[],...i.length===1&&s?.type==="checkout"?["continue_checkout"]:[]]}}function x(e){let t=ie({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&T.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function le(e){if(!e.operation)return;let t=oe.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=se(y.get(t.operationId)??null,t);y.set(t.operationId,n),n===t&&T.set(t.operationId,e.canReselect===!0)}async function We(e){g();for(let n of[e.purchase,e.run.paywall])n&&le(n);let t=await h.update(n=>{if(w(n),n.run&&(n.run.id!==e.run.id||n.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let o=k(n);for(let i of[e.purchase,e.run.paywall]){let s=i?.operation?.operationId??i?.quote?.operationId;if(!i||!s)continue;let c=o.find(d=>d.operationId===s);if(c&&c.receiptId!==i.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let m=x(y.get(s));c?c.terminal??=m:o.push({receiptId:i.receiptId,operationId:s,terminal:m})}return{...n,purchases:o,run:n.run&&(n.run.revision>e.run.revision||!["running","waiting"].includes(n.run.status)&&["running","waiting"].includes(e.run.status))?n.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});w(t),t.run&&!["running","waiting"].includes(t.run.status)&&k(t).some(n=>!n.terminal)&&(t=await H(t,!t.journal.entry?.command&&!t.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(n=>!!n)))),w(t),v(A(t,"run"))}function Xe(){return{async read(){let{entry:e}=await h.read();return w(e),structuredClone(e.journal)},async write(e,t){let n=null;return await h.update(o=>{if(w(o),o.operationCommand&&t?.command&&t.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return n=null,o.journal.revision!==e?o:(n=e+1,{...o,journal:{revision:n,entry:t}})}),n}}}async function H(e,t=!1,n=new Set){w(e);let o=k(e);for(let s of o){if(s.terminal)continue;let c=n.has(s.operationId)?y.get(s.operationId):void 0;if(c??=await D(e,s),g(),c.operationId!==s.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(c.merchantExecution&&c.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&ie({quote:c.quote??null,operation:c,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let m=Y(c)?await ee.update({operationId:s.operationId,intent:"cancel"}):await ee.attach({operationId:s.operationId,intent:"cancel"});if(c=oe.parse(m.operation),g(),c.operationId!==s.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");c=await D(e,s)}y.set(s.operationId,se(y.get(s.operationId)??null,c))}let i=await h.update(s=>{w(s);let c=s.operationCommand&&y.get(s.operationCommand.operationId);return{...s,...c&&(c.confirmedAt||c.merchantExecution||!ke(c))?{operationCommand:void 0}:{},purchases:k(s).map(m=>({...m,terminal:m.terminal??x(y.get(m.operationId))}))}});return w(i),i}async function B(e){g();let t=await z.request("funnels",e);return g(),t}async function Ze(e){try{return await B(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return B({...e,intent:"resume"})}}async function et(){let e=K(Be,await B({operation:"find_purchase"}));if(e.customerId!==S||e.scope.projectId!==p.scope.projectId||e.scope.environment!==p.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 h.update(o=>o&&!U(o)?o:{schemaVersion:1,baseUrl:h.baseUrl,scope:p.scope,customerId:S,sessionId:$,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...p.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 te;function de(e){let t=te;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<at))return t.job;let n={at:Date.now(),job:et().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw te===n&&(te=void 0),o})};return te=n,n.job}async function D(e,t,n="recover_purchase",o=!1){let i=K(Qe,await B({operation:n,runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId},...o?{includePaywallVersion:!0}:{}}));if(pe(e,i),i.purchase.receiptId!==t.receiptId||i.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return le(i.purchase),o&&i.paywallVersionId&&Pe.set(t.operationId,i.paywallVersionId),y.get(t.operationId)}async function Se(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=K(ze,await B({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(pe(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&le(n.purchase);let o=await h.update(i=>{w(i);let s=k(i),{receiptId:c,operationId:m}=n.settlement;if(c&&m){let R=s.find(I=>I.operationId===m);if(R&&R.receiptId!==c)throw new l("INVALID_RESPONSE","Original Receipt changed");R||s.push({receiptId:c,operationId:m,terminal:x(y.get(m))})}let d=n.settlement.state==="settled"?Ve(i.journal.entry,t.requestId):i.journal.entry;return{...i,purchases:s,journal:d===i.journal.entry?i.journal:{revision:i.journal.revision+1,entry:d}}});w(o),e=o}return e}function pe(e,t){if(t.customerId!==S||t.scope.projectId!==p.scope.projectId||t.scope.environment!==p.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 me(e,t){if(w(e),e.run&&(e=await Se(e)),!k(e).length&&U(e))return v(A(e,"operation"));if(!k(e).length)return v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:Q(t)});E=!0;let n=k(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(i=>i.terminal==="native"))for(let i of n)x(y.get(i.operationId))!=="native"&&await D(e,i);let o=await H(e);return v(A(o,"operation"))}async function ne(e,t=!1,n=!0){if(_=e.start.requestId,F=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!u){let o=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 Ze(o)}catch(d){if(!e.run&&d instanceof l&&(d.status===void 0||d.status>=500))return v({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:b.purchases,error:Q(d)});throw d}let s=K(Me,i);if(s.customerId!==S||s.scope.projectId!==p.scope.projectId||s.scope.environment!==p.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(s.outcome==="unknown")return v({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:b.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}});pe(e,s);let c=await h.update(d=>(w(d),{...d,run:{id:s.target.runId,versionId:s.target.versionId,status:s.target.status,revision:s.view?.revision??d.run?.revision??0,runExpiresAt:s.target.runExpiresAt}}));if(w(c),e=c,s.access.type==="operation_only")return me(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await Se(e);let m=s.view;if(m.locale!==e.start.locale||!Le(m.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");u=Ge({...p,customerRun:{runId:s.target.runId,customerId:S,startRequestId:e.start.requestId},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(d=>p.executionPolicy.allowed.includes(d))},funnelCommandStorage:Xe(),onAcceptedResponse:We},{scope:s.scope,run:m})}try{await u.get(),u.view?.pendingRequest?.requestId===e.start.requestId&&!u.pendingCommands?.length&&await u.resume(u.view.pendingRequest.requestId);for(let i of u.pendingCommands??[])i.operation!=="close"&&await u.settle?.(i.requestId);u.pendingCommands?.length&&await u.retry(),g();let o=(await h.read()).entry;return w(o),v(A(o,"run"))}catch(o){if(g(),n&&o instanceof l&&(o.status===401||o.status===409&&o.reason==="STATE_CHANGED")){u.reset(),u=null;let i=(await h.read()).entry;return w(i),ne(i,!1,!1)}throw o}}function N(e,t="read",n){if(g(),j)return t==="read"||t===W?j:j.then(()=>N(e,t,n),()=>N(e,t,n));clearTimeout(X);let o=e().catch(i=>{throw!C&&!n?.(i)&&v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:b.purchases,error:Q(i)}),i});return j=o,W=t,o.then(()=>{j===o&&(j=void 0,W=void 0)},()=>{j===o&&(j=void 0,W=void 0)}),o}function L(){return N(async()=>{let{entry:e}=await h.read();if(!e||U(e)){if(await de(!1)==="blocked")return Ce();({entry:e}=await h.read())}return e?(_&&e.start.requestId!==_&&(u?.reset(),u=null,y.clear(),T.clear(),E=!1),E&&_===e.start.requestId?me(e,b.error):ne(e)):v({mode:"idle",status:"idle",actions:["start"],purchases:[]})})}function Ce(){return v({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:Q(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function Re(){let e=await L();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:N(async()=>{let t=(await h.read()).entry;if(w(t),!E){if(!u?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let d=u.view.paywall.operation;if(d?.confirmedAt||d?.merchantExecution||d&&!(Y(d)?["prepared","quoted"].includes(d.status):d.status==="pending"))return v(A(t,"run"));if(u.pendingCommands?.length)await u.retry();else{let I=u.view;await u.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:I.nodeId,visit:I.visit,revision:I.revision,input:{type:"paywall_confirm",operationId:I.paywall.quote.operationId,...I.paywall.quote.merchantTerms?{merchantConfirmation:we(I.paywall.quote.merchantTerms)}:{}}})}let R=(await h.read()).entry;return w(R),v(A(R,"run"))}let n=t.operationCommand?.operationId??b.confirmation?.operationId,o=n&&y.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");J({allowed:t.allowed.filter(d=>p.executionPolicy.allowed.includes(d))},o.quote),await h.update(d=>{if(w(d),d.journal.entry?.command||d.journal.entry?.closeCommand||d.operationCommand&&d.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...d,operationCommand:{operationId:n,intent:"confirm"}}});let i={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:we(o.quote.merchantTerms)}:{}},s=Y(o)?await ee.update(i):await ee.attach(i),c=oe.parse(s.operation);if(g(),s.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");y.set(n,se(o,c));let m=(await h.read()).entry;return w(m),v(A(await H(m,!1,new Set([n])),"operation"))},"confirm")}function tt(e){let t=e?.quote;return t&&ae(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Ee(){if(b.mode!=="operation"||b.status==="blocked")return null;let e=b.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?tt(y.get(t)):null}async function be(){g();let{entry:e}=await h.read();return e?U(e)?"finished":"pending":"none"}return{get controller(){return u},get recovery(){return structuredClone(b)},get attempt(){return g(),structuredClone(F)},get identitySignal(){return ce.signal},get customerId(){return S},retained:be,async findPurchase(){let e=await be();if(e==="pending")return e;let t=await de(!0);return g(),t==="none"?e:t},async readPaywall(e){g();let t=qe(e),[n,{readPaywallContent:o},{validateResourceCheck:i}]=await Promise.all([Ae(z.request,"resolvePaywall"),import("./paywall-content-KBHI22JD.js"),import("./check-response-MJHH5FWT.js")]);g();let s=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),c=await Fe(z.request,n,s);i(s,c.paywall.check,c.scope);let m=await o(p,c.paywall);if(g(),t.paywallVersionId?m.id!==t.paywallVersionId:m.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return m},get canRestoreUpgradePaywall(){return Ee()!==null},recoverUpgradePaywall(){let e=Ee();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(b.mode!=="operation"||b.status==="blocked")return null;let{entry:n}=await h.read();if(!n?.run)return null;w(n);let o=k(n),i=o.filter(O=>!O.terminal),s=o.filter(O=>O.terminal==="complete"),c=i.length===1?i[0]:i.length?void 0:s.find(O=>e&&e.runId===n.run?.id&&O.receiptId===e.receiptId)??(s.length===1?s[0]:void 0);if(!c||t&&c.operationId!==t)return null;let m=e?.runId===n.run.id&&e.receiptId===c.receiptId?e.view:void 0,d;try{d=await D(n,c,"recover_purchase",!0)}catch(O){if(!(O instanceof l&&O.status===400&&O.code==="INVALID_REQUEST"))throw O;if(!m)return null;d=await D(n,c)}let R=d.quote;if(!R||ae(R)&&(R.timing!=="immediate"||R.execution.provider!=="merchant")||!(d.confirmedAt||d.merchantExecution||d.checkoutUrl||x(d)==="complete"))return null;x(d)!=="complete"&&J({allowed:n.allowed.filter(O=>p.executionPolicy.allowed.includes(O))},R);let I=Pe.get(c.operationId),q=n.start.parameters?.commerce,Oe=n.start.locale??"en",fe=m;if(I){if(typeof q!="object"||!q||!("provider"in q)||typeof q.provider!="string"||!("currency"in q)||typeof q.currency!="string")return null;fe=await this.readPaywall({paywallVersionId:I,locale:Oe,commerce:{provider:q.provider,currency:q.currency,...ae(R)?{intent:"subscription_change"}:{}}})}if(!fe)return null;g();let _e=fe,he=!1,Ie=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:ce.signal,view:_e,quote:R,locale:Oe,get operation(){return d},get canReselect(){return T.get(c.operationId)===!0},async refresh(){return _e},preview:Ie,confirm:Ie,cancel:Ie,async read(){if(he)throw new DOMException("Purchase view closed","AbortError");d=await D(n,c);let O=await H(n,!1,new Set([c.operationId]));return he||v(A(O,"operation")),structuredClone(d)},destroy(){he=!0}}},start(e){let t=G.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 N(async()=>{let n=(await h.read()).entry;if((!n||U(n))&&await de(!0)==="blocked")return Ce();let o=await h.update(i=>{if(i&&!U(i)){if(i.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return i}return{schemaVersion:1,baseUrl:h.baseUrl,scope:p.scope,customerId:S,sessionId:$,start:t,allowed:[...p.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return _!==o.start.requestId&&(u?.reset(),u=null,y.clear(),T.clear(),E=!1),E?me(o,b.error):ne(o,!0)},`start:${t.funnelId}`)},refresh:L,confirm:Re,retry:()=>E?Re():N(async()=>{let{entry:e}=await h.read();return e?ne(e,!0):v({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return u?.view?N(async()=>{if(!u?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(u.pendingCommands?.find(n=>n.operation==="close"))await u.retry();else if(["running","waiting"].includes(u.view.status)){let n=u.view;await u.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await h.read()).entry;return w(t),v(A(t,"run"))},"close"):L()},async continueCheckout(e,t){let n=t?await N(async()=>{let{entry:o}=await h.read();if(w(o),!o.run||!k(o).some(s=>s.operationId===t&&!s.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let i=await H(o);return v(A(i,E?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await L();g(),await e(it(n,t))},async terminateCheckout(e){let t=await L();if(!t.purchases.find(o=>o.type==="checkout"&&o.operationId===e)||!t.actions.includes("continue_checkout"))throw new l("PURCHASE_PENDING","The original Checkout has changed");return N(async()=>{let{entry:o}=await h.read();w(o);let i=k(o).find(c=>c.operationId===e&&!c.terminal);if(!i||!o.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await D(o,i,"terminate_checkout");let s=await H(o,!1,new Set([e]));return v(A(s,E?"operation":"run"))},`terminate:${e}`,o=>o instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(o.code))},subscribe(e){return Z.add(e),()=>{Z.delete(e)}},destroy:ve}}export{Je as a,it as b,Vt as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as o}from"./chunk-
|
|
1
|
+
import{f as o}from"./chunk-OZK47BUU.js";var n=class extends Error{constructor(t,s,y,i,r){super(s);this.code=t;this.status=y;this.requestId=i;this.name="IndianaError",this.reason=r?.reason;let e=o(t,y??0,{...r,retryAfter:r?.retryAfterSeconds===void 0?void 0:String(r.retryAfterSeconds)});this.retryable=e.retryable,this.recovery=e.recovery,this.retryAfterSeconds=e.retryAfterSeconds}code;status;requestId;commandRequestId;retryable;recovery;retryAfterSeconds;reason};export{n as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{m as o}from"./chunk-
|
|
1
|
+
import{m as o}from"./chunk-RJT764B2.js";import{a as i}from"./chunk-WE55LJEN.js";function m(t,e,n,r){if(!o(t,e)||n!==void 0&&e.observation&&e.observation.subject.customerId!==n||r!==void 0&&e.observation!==void 0&&(e.observation.subject.scope.projectId!==r.projectId||e.observation.subject.scope.environment!==r.environment))throw new i("INVALID_RESPONSE","The access requirement or Customer changed");return e}function d(t,e,n){if(t.requirement){if(!e)throw new i("INVALID_RESPONSE","The requested access check is missing");m(t.requirement,e,t.customerId,n)}}export{m as a,d as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as d}from"./chunk-
|
|
1
|
+
import{b as d}from"./chunk-NMBKBC7X.js";import{a as u}from"./chunk-DSPLGTQI.js";function m(e){if(!/^[A-Za-z0-9_-]{1,64}$/.test(e))throw new Error("Invalid device cookie name");let t="";for(let i of document.cookie.split(";"))if(i.trim().startsWith(`${e}=`))try{t=decodeURIComponent(i.trim().slice(e.length+1))}catch{}return/^[A-Za-z0-9_-]{8,128}$/.test(t)||(t=crypto.randomUUID(),document.cookie=`${e}=${encodeURIComponent(t)}; path=/; max-age=${400*24*3600}; SameSite=Lax`),t}function y(){try{let e=sessionStorage.getItem("indiana_sid");return e||(e=crypto.randomUUID(),sessionStorage.setItem("indiana_sid",e)),e}catch{return}}function g(e=d){let t=new URL(e);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(t.hostname))||t.username||t.password||t.search||t.hash)throw new Error("baseUrl must be an https origin without credentials");return t.origin}var o=new Set,s;function S(e){let t=()=>e();if(o.add(t),!s){let i=!0,a=history.pushState,p=history.replaceState,r=()=>{if(i)for(let n of[...o])o.has(n)&&u(n)},c=function(...n){a.apply(this,n),r()},h=function(...n){p.apply(this,n),r()};history.pushState=c,history.replaceState=h,addEventListener("popstate",r),addEventListener("hashchange",r),s=()=>{i=!1,history.pushState===c&&(history.pushState=a),history.replaceState===h&&(history.replaceState=p),removeEventListener("popstate",r),removeEventListener("hashchange",r)}}return()=>{o.delete(t)&&(o.size||(s?.(),s=void 0))}}export{m as a,y as b,g as c,S as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as p,c as d}from"./chunk-
|
|
1
|
+
import{b as p,c as d}from"./chunk-BX2MSRA4.js";import{t as a,w as u,z as m}from"./chunk-RRZZUIFM.js";import{b as e}from"./chunk-5YBTU4KS.js";var s=e.enum(["page","popup","banner"]),y=3e5,f=e.strictObject({type:e.enum(["string","number","boolean","strings","json"]),nullable:e.boolean()}),h=e.strictObject({inputs:e.record(a,f.extend({required:e.boolean()})).refine(t=>Object.keys(t).length<=40,"Too many content inputs"),outputs:e.record(a,f).refine(t=>Object.keys(t).length<=40,"Too many content outputs")}),g=e.strictObject({kind:s,schemaVersion:e.literal(1),name:e.string().trim().min(1).max(80),screen:u,contract:h}),c=g.superRefine((t,r)=>{let n=(o,b)=>r.addIssue({code:"custom",message:o,path:b});t.screen.surface!==t.kind&&n("Content surface must match its domain",["screen","surface"]),t.screen.name!==t.name&&n("Content has one editable name",["screen","name"]),t.kind==="banner"&&t.screen.presentation.type!=="inline"&&n("Banner requires an inline container",["screen","presentation"]),t.kind!=="banner"&&t.screen.presentation.type==="inline"&&n("Inline presentation belongs to Banner",["screen","presentation"]),t.screen.actions.some(o=>o.type!=="event"&&o.type!=="navigate")&&n("Content actions must emit host intents or navigate locally",["screen","actions"]);let i=new Set(t.screen.actions.filter(o=>o.type==="event").map(o=>o.id));(Object.keys(t.contract.outputs).some(o=>!i.has(o))||[...i].some(o=>!Object.hasOwn(t.contract.outputs,o)))&&n("Every event needs exactly one output declaration",["contract","outputs"]),d(t)>y&&n("Content document exceeds its byte budget",[])});function S(t,r){if(t===null)return r.nullable;switch(r.type){case"json":return!0;case"string":return typeof t=="string";case"number":return typeof t=="number"&&Number.isFinite(t);case"boolean":return typeof t=="boolean";case"strings":return Array.isArray(t)&&t.every(n=>typeof n=="string")}}var x=c.superRefine((t,r)=>{for(let n of p(t.screen))Object.keys(t.contract.inputs).some(i=>n===i||n.startsWith(i+"."))||r.addIssue({code:"custom",path:["contract","inputs"],message:"Declare every reusable input read"});for(let n of t.screen.actions){if(n.type!=="event")continue;let i=t.contract.outputs[n.id],o=Object.hasOwn(n.properties,"value")?n.properties.value:n.properties;i&&!S(o,i)&&r.addIssue({code:"custom",path:["contract","outputs",n.id],message:"Action value differs from its declared type"})}m(t.screen).some(n=>!n.complete)&&r.addIssue({code:"custom",path:["screen","strings"],message:"Content needs complete localized copy"})}),l=e.strictObject({id:e.uuid(),kind:s,projectId:e.uuid(),environmentId:e.uuid(),name:e.string(),revision:e.number().int().nonnegative(),status:e.enum(["draft","published","archived"]),publishedVersionId:e.uuid().nullable(),createdAt:e.iso.datetime({offset:!0}),updatedAt:e.iso.datetime({offset:!0})}),D=l.extend({draft:c}),I=e.strictObject({rows:e.array(l).max(200),nextCursor:e.uuid().nullable()}),v=e.strictObject({id:e.uuid(),kind:s,resourceId:e.uuid(),projectId:e.uuid(),environmentId:e.uuid(),version:e.number().int().positive(),sourceRevision:e.number().int().nonnegative(),document:x,createdAt:e.iso.datetime({offset:!0})}),z=v.omit({document:!0}),V=e.discriminatedUnion("action",[e.strictObject({action:e.literal("create"),kind:s,id:e.uuid(),document:c}),e.strictObject({action:e.literal("save"),kind:s,id:e.uuid(),revision:e.number().int().nonnegative(),document:c}),e.strictObject({action:e.enum(["publish","archive"]),kind:s,id:e.uuid(),revision:e.number().int().nonnegative()})]).superRefine((t,r)=>{"document"in t&&t.document.kind!==t.kind&&r.addIssue({code:"custom",path:["document","kind"],message:"Content cannot change domain"})});export{s as a,v as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as ie}from"./chunk-
|
|
1
|
+
import{i as ie}from"./chunk-FQJWNS4U.js";import{a as Z,c as ee,e as te,f as ne,i as N,k as re,l as oe,m as se}from"./chunk-LENTXDGK.js";import{b as X}from"./chunk-YMRWDMIL.js";import{r as V}from"./chunk-EACC667P.js";import"./chunk-BX2MSRA4.js";import"./chunk-J4RM5GQP.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-5HYA7TBE.js";import"./chunk-L64BS65O.js";import{o as Y,p as K}from"./chunk-QGKROSRD.js";import{A as G}from"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import{c as $,d as R}from"./chunk-NNJVMJUG.js";import{a as p}from"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-NMBKBC7X.js";import{b as u}from"./chunk-5YBTU4KS.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(s){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[s.type];return s.nullable?t.nullable():t}function ae(s,t){let f=u.record(u.string(),R).parse(s);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,r]of Object.entries(f))Y.parse({[m]:r});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,r]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(r).parse(f[m]);else if(r.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ae(s,t){return le(s,t,!1)}async function Se(s,t){return le(s,t,!0)}async function le(s,t,f){t.signal?.throwIfAborted();let m=X.parse(t.content),r=m.document;if(t.closeControl==="content"&&!r.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(s))throw new p("CONFLICT","Content is already mounted in this container");let y=ae(t.inputs??{},r.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(r.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(r.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let M=K.parse(t.bindings??[]),d=s.ownerDocument,ue=s.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,x=r.kind==="popup",n=x?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=r.kind,c.setAttribute("aria-label",r.name),c.style.cssText="width:100%;min-width:0",n){n.setAttribute("aria-label",r.name);let e=r.screen.presentation;n.style.cssText="box-sizing:border-box;padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto",e.type==="modal"||e.type==="sheet"?(n.style.width=`${$[e.size]}px`,e.type==="sheet"&&(n.style.margin="auto auto 0")):n.style.width="100vw",a=ee(n,r.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),n.append(c),s.append(n)}else s.append(c);let i=!1,A=!1,E=!1,S=!1,de=n?oe(n):se(c,s),D=re(s,t,r.kind,()=>{k()&&(b(),h(t.onDismiss))}),q,H,L=new Promise((e,o)=>{q=e,H=o});L.catch(()=>{});let g=null,I=structuredClone(r.screen),W=G(I,[t.locale,...d.defaultView?.navigator.languages??[]]),j=t.capabilities;I.actions=I.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function b(){i||(i=!0,t.signal?.removeEventListener("abort",b),D.finish("dismissed"),H(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),n?.close(),n?.remove(),c.remove(),z.delete(s),n&&P?.())}let v=()=>{!E||!k()||(b(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(n&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="×",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"关闭":"Close"),ne(e,r.screen.theme),e.addEventListener("click",v),n.prepend(e)}n&&a?.responsive&&(_=Z(n,v,k,t.locale?.startsWith("zh")?"关闭":"Close"),n.addEventListener("click",e=>{if(e.target!==n)return;let o=n.getBoundingClientRect();(e.clientX<o.left||e.clientX>o.right||e.clientY<o.top||e.clientY>o.bottom)&&v()})),n?.addEventListener("cancel",e=>{e.preventDefault(),v()}),n?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),v())});async function F(){if(i||!E||A||!g)return;let e=g;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),g=null}catch(o){i||h(t.onError,o)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function J(){if(i)throw new p("CONFLICT","Content host has been destroyed");E||!S||(P??=N(d),D.present(e=>{de(),n&&(a?.latch(),n.showModal(),a?.responsive&&n.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(n,a?.type??r.screen.presentation.type,a?.responsive)),E=!0}))}function U(e){D.finish("error",e),H(e instanceof Error?e:new Error(String(e))),b()}let Q={destroy:b,show:J,get pendingAction(){return g?structuredClone(g):null},retryAction:F,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let o=u.record(u.string(),R).parse(e),C=ae({...y,...o},r.contract);for(let l of Object.keys(o))if(!T.has(l)&&(!Object.hasOwn(y,l)||V(y[l])!==V(C[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(y)!==V(C)&&(w?.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:C}}),y=C)},updateCapabilities(e){if(i)return;let o=structuredClone(e);w?.updateCapabilities(o),j=o}};z.set(s,Q),t.signal?.addEventListener("abort",b,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=N(d),D.start(x,t.locale??r.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:r.name,viewportHeight:r.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&&n?.setAttribute("aria-label",e),!S))try{S=!0,f||J(),q()}catch(o){U(o),h(t.onError,o)}},onError:e=>{if(i)return;let o=new Error(e);S||U(o),h(t.onError,o)},onEscape:x?v:void 0,onAction:(e,o,C)=>{if(i||!E||A||g)return;let l=r.screen.actions.find(O=>O.id===e),B=r.contract.outputs[e];if(!(l?.type!=="event"||!B)&&!(l.close&&!k()))try{let O=ce(B).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);g=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:o??{},answers:C??{},requestedClose:l.close}),F()}catch(O){h(t.onError,O)}}}),w.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:y}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return Q}catch(e){throw U(e),e}}export{Ae as mountContent,Se as prepareContent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as ne}from"./chunk-
|
|
1
|
+
import{b as ne}from"./chunk-3LDOPWRV.js";import{b as j}from"./chunk-5UVYLTM7.js";import"./chunk-C4NXQMSO.js";import"./chunk-JJIP6BZL.js";import"./chunk-R4BYUK7S.js";import{a as re}from"./chunk-UJVNIA5Q.js";import{a as z}from"./chunk-OQ2E3JLZ.js";import{b as te}from"./chunk-UWMXBSYO.js";import"./chunk-554BTJ3I.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import{j as O,k as V}from"./chunk-LENTXDGK.js";import"./chunk-PVMGYRGE.js";import"./chunk-36VNAOG6.js";import"./chunk-6K6N5XLO.js";import"./chunk-73UFNVEP.js";import"./chunk-CAE4KIZN.js";import"./chunk-725DCRIN.js";import"./chunk-6HKQILBV.js";import"./chunk-EACC667P.js";import"./chunk-BX2MSRA4.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-5HYA7TBE.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import{a as C}from"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-SLUA7ABW.js";import"./chunk-YA2XHXUS.js";import"./chunk-3VUPVXAV.js";import"./chunk-NMBKBC7X.js";import"./chunk-5YBTU4KS.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";var k=new WeakMap,_=new WeakMap,B=new WeakSet;function he(D,e){let P=e.hostPaywallTarget?void 0:e.prepared,J=()=>{e.prepared&&!B.has(e.prepared)&&j(e.prepared)?.release()},K=k.get(e.client);if(K)return J(),K;let Q=n=>({...n,requestId:n.requestId??crypto.randomUUID()}),R=e.allowNewPurchase!==!1&&e.start instanceof Promise?e.start:void 0,m=e.allowNewPurchase===!1||!e.start||e.start instanceof Promise?void 0:Q(e.start);m&&P?.state==="ready"&&P.matches(m)&&P.open();let f=P&&(m&&(P.state==="preparing"||["shown","closed"].includes(P.state)&&P.matches(m))||R&&["preparing","ready"].includes(P.state))?P:void 0;f?B.add(f):J();let y=f&&j(f);y?.claim();let S=Promise.resolve().then(async()=>{let n=!1,c,p=!1,U,g=0,E,q,X=!1,F=()=>{},Y=()=>{},H,L=!1,M=!1,I,Z=!1,a=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,v=()=>{k.get(e.client)===S&&k.delete(e.client),a.removeEventListener("abort",A),F(),Y(),f&&B.delete(f),y?.release()};function $(){if(I)return I;let t=new Promise(o=>I=o);return _.set(e.client,t),t.then(()=>{_.get(e.client)===t&&_.delete(e.client)}),k.get(e.client)===S&&k.delete(e.client),I}let l=V(D,e,"funnel",()=>b(),z);function A(){b()}function b(t=!1){if(!n){if(n=!0,l.finish("dismissed"),c){c.destroy();return}if(t&&H){let o=$();Z=!0,H.then(async i=>{i.mode==="run"&&i.status!=="blocked"&&e.client.controller&&e.client.attempt?.requestId===m?.requestId&&await e.client.close()}).catch(()=>{}).finally(()=>{o(),h(e.onDismiss,null)}),v();return}v(),h(e.onDismiss,null)}}let N={destroy:()=>b(),refresh:()=>E??(p?G():c?.refresh())??Promise.resolve(),get recovery(){return c?.recovery??{type:"recover",operationId:null,requestId:null}},prepareFallback:()=>c?.prepareFallback()??Promise.resolve({type:"recover",operationId:null,requestId:null}),review:(...t)=>c?.review(...t)??Promise.resolve(),exitReview:(...t)=>c?.exitReview(...t)??Promise.resolve(),get unappliedDrafts(){return c?.unappliedDrafts??new Map}};a.addEventListener("abort",A,{once:!0}),y&&(Y=y.onClose(()=>{L?n||$():b(!0)}));try{a.throwIfAborted();let t=e.client.controller?.view?.paywall?.resolution,o=t&&"document"in t?t.document:e.loadingDocument;l.start(!0,m?.locale??e.client.attempt?.locale??o?.screen.strings.defaultLocale,o??null);let i=R?l.wait(R.then(r=>r?Q(r):null,()=>null),O):Promise.resolve(m??null);i.catch(()=>{}),f?.state==="shown"?(M=!0,l.present(()=>{})):f&&["preparing","ready"].includes(f.state)&&Promise.all([f.ready,i.catch(()=>null)]).then(([r,s])=>{if(r){if(n||!l.active||!s||!f.matches(s)||!y?.revealable)return y?.release();l.present(()=>{f.open()==="shown"?M=!0:y.release()})}});let d=_.get(e.client);if(d&&await l.wait(d),n)return null;if(a.throwIfAborted(),R){let r=await i;if(n)return null;if(a.throwIfAborted(),!r)return l.finish("skipped"),v(),null;m=r}H=m?e.client.start(m):e.client.refresh();let u=await l.wait(H,O);return n?null:(a.throwIfAborted(),await ee(u,l))}catch(t){if(Z||I?.(),n)return null;throw l.finish("error",t),v(),h(e.onError,t),t}function x(t=!1){g++;let o=c;c=void 0,F(),F=()=>{};let i=t?o?.retainPurchaseDialog?.():void 0;return o?.destroy(),a.addEventListener("abort",A,{once:!0}),i}function T(t){p=!0;let o=e.client.attempt?.locale??m?.locale,i=o?.startsWith("zh"),d=t?i?"正在查询原订单…":"Checking your purchase…":i?"暂时无法确认原订单,请重试。":"Could not check your original purchase. Try again.",u=t?void 0:()=>{G()};c?.setPurchaseRecovery?.(d,u)||(c&&x(),l.active||(l=V(D,e,"funnel",()=>b(),z),l.start(!0,o,e.loadingDocument??null)),l.setPurchaseRecovery(d,u))}function G(){if(E)return E;if(n||a.aborted)return Promise.resolve();U??=c?.recoveryPaywall,a.addEventListener("abort",A,{once:!0}),T(!0);let t=Promise.resolve().then(async()=>{try{let i=await l.wait(e.client.refresh(),O);!n&&!a.aborted&&await ee(i,l)}catch(i){!n&&!a.aborted&&(h(e.onError,i),T(!1))}});E=t;let o=()=>{E===t&&(E=void 0)};return t.then(o,o),t}async function ee(t,o){let i=e.client.controller;if(t.mode==="run"&&t.status!=="blocked"&&i)return p&&c&&x(),p=!1,U=void 0,ae(i,o?.active?o:void 0);if(t.mode==="operation"&&t.purchases.length){T(!0);let d=await l.wait(e.client.recoverPurchasePaywall(U).then(u=>((n||a.aborted)&&u?.destroy(),u)),O).catch(u=>(!n&&!a.aborted&&h(e.onError,u),null));if(n||a.aborted)return null;if(d){if(n||a.aborted)return d.destroy(),null;let u=x(!0)??y?.retainPurchaseDialog?.()??l.retainPurchaseDialog();y?.release();let r=await re(D,{signal:a,loading:"host",start:async()=>d,checkoutNavigation:"after_confirmation",allowNewPurchase:!1,resumeCheckout:w=>e.client.continueCheckout(W,w),onError:e.onError,onDismiss:()=>{n||b()}},{retainedDialog:u,present(w){l.active?l.present(w):w(!!u)},async dismiss(){b()}});if(!r.host||n||a.aborted)return r.host?.destroy(),u?.release(),v(),null;let s=r.host;return p=!1,c={destroy(){s.destroy(),v(),h(e.onDismiss,null)},refresh:async()=>{await s.refresh()},get recovery(){return s.recovery},prepareFallback:()=>s.prepareFallback(),review:async()=>{},exitReview:async()=>{},unappliedDrafts:new Map},N}}return t.purchases.length||p?(T(!1),N):(l.finish("skipped"),v(),(M||L)&&(n=!0,h(e.onDismiss,null)),null)}function W(t){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");return e.onCheckoutUrl?e.onCheckoutUrl(t):D.ownerDocument.defaultView?.location.assign(t)}async function ae(t,o){a.removeEventListener("abort",A),L=!0;function i(){!n&&!a.aborted&&!p&&!X&&q&&e.client.recovery.status==="complete"&&(X=!0,h(e.onComplete,structuredClone(q)))}F(),F=e.client.subscribe(i);let d=++g,u=await ne(D,{...e,prepared:f,client:t,signal:a,checkoutNavigation:"after_confirmation",resumeCheckout:r=>e.client.continueCheckout(W,r),terminateCheckout:e.allowNewPurchase===!1?void 0:r=>e.client.terminateCheckout(r),async onCheckoutUrl(r){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let s=e.client.recovery;if((!s.actions.includes("continue_checkout")||!s.purchases.some(w=>w.type==="checkout"&&w.checkoutUrl===r))&&(s=await e.client.refresh(),a.throwIfAborted(),n))throw new DOMException("Presentation dismissed","AbortError");if(te(s)!==r)throw new C("PURCHASE_PENDING","Checkout differs from the original recovery proof");return W(r)},async resolveOfferId(r){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let s=e.client.attempt;if(!s)throw new C("PURCHASE_PENDING","Read the original Start before selecting an offer");let w=await e.resolveOfferId?.(r,s);if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==s.requestId)throw new C("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return w},async resolveSubscriptionChange(r){a.throwIfAborted();let s=e.client.attempt;if(n||!s)throw new C("PURCHASE_PENDING","Read the original Start before selecting a membership");let w=await e.resolveSubscriptionChange?.(r);if(a.throwIfAborted(),n||e.client.attempt?.requestId!==s.requestId)throw new C("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting a membership");return w},onPresentationState(r){d===g&&h(e.onPresentationState,r)},onComplete(r){d===g&&(q=r,i())},onError(r){d===g&&(h(e.onError,r),r instanceof C&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED"&&r.recovery==="recover_operation")&&!a.aborted&&G().catch(s=>h(e.onError,s)))},onDismiss(r){d===g&&(n=!0,v(),I?.(),h(e.onDismiss,r))}},o);return d!==g||n||a.aborted?(u.destroy(),n||a.aborted?null:N):(c=u,N)}});return k.set(e.client,S),S}export{he as showFunnelPurchase};
|
package/dist/{funnel-host-recovery-paywall-PSGZT6MQ.js → funnel-host-recovery-paywall-UQC5FAL4.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as A}from"./chunk-
|
|
1
|
+
import{a as A}from"./chunk-C4NXQMSO.js";import{a as E}from"./chunk-UJVNIA5Q.js";import"./chunk-OQ2E3JLZ.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import{g as S}from"./chunk-LENTXDGK.js";import"./chunk-BX2MSRA4.js";import"./chunk-J4RM5GQP.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import{b as C}from"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-5HYA7TBE.js";import"./chunk-L64BS65O.js";import{t as k}from"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import{a as i}from"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-NMBKBC7X.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";async function V(d,e){if(!d.closest("dialog")?.open)return null;let r=AbortSignal.any([e.signal,e.client.identitySignal]);r.throwIfAborted();let a=e.operationId?await e.client.recoverPurchasePaywall(void 0,e.operationId):await e.client.recoverPurchasePaywall();if(!a)return null;let w=a.view;if(!w||w.document.presentation.type!=="modal"||r.aborted)return a.destroy(),null;let l=e.upgradeReplacement,c=a,f=c,h,R=l?new Proxy(a,{get(o,t){let s=f[t];return typeof s=="function"?s.bind(f):s}}):a;async function U(o,t){if(r.throwIfAborted(),!l||c.operation?.operationId!==o||!c.canReselect)throw new i("PURCHASE_PENDING","The original upgrade has not been closed");if(!h){let n=await l.start();if(!n)throw new i("PRODUCT_UNAVAILABLE","The selected upgrade is unavailable");if(n.funnelId!==e.client.attempt?.funnelId)throw new i("SCOPE_MISMATCH","The new upgrade belongs to another Funnel");h={...n,requestId:n.requestId??crypto.randomUUID()}}r.throwIfAborted();let s=await e.client.start(h),g=e.client.controller;if(s.mode!=="run"||s.status!=="ready"||!g?.view?.paywall)throw new i("PURCHASE_PENDING","The current Paywall could not be opened for the replacement");let p=await A(g);try{r.throwIfAborted();let n=p.view,b=n?.document.buttons[t.actionId],I=n&&b?.type==="checkout"?C(b.product,t.selection,n.capabilities):null;if(!n||I!==t.productVersionId)throw new i("PRODUCT_UNAVAILABLE","The selected upgrade is no longer available");let v=k(n.document.screen,I,t.selection,n.capabilities);if(Object.keys(v).length!==Object.keys(t.featureQuantities).length||Object.entries(v).some(([T,D])=>t.featureQuantities[T]!==D))throw new i("PRODUCT_UNAVAILABLE","The selected upgrade quantities have changed");return f=p,c.destroy(),n}catch(n){throw p.destroy(),n}}let m=S(d);if(!m)return a.destroy(),null;let u,O=new Promise(o=>{u=o}),y=!1,P=()=>u(!1);r.addEventListener("abort",P,{once:!0});try{let{host:o}=await E(d,{signal:r,start:async()=>R,loading:"host",checkoutNavigation:"after_confirmation",allowNewPurchase:!1,...l&&{beforeCheckoutReplacement:l.beforeCheckoutReplacement,resolveOfferId:l.resolveOfferId,resolveSubscriptionChange:l.resolveSubscriptionChange,terminateCheckout:t=>e.client.terminateCheckout(t),prepareUpgradeReplacement:U},resumeCheckout:t=>e.client.continueCheckout(e.onCheckoutUrl,t),onComplete:e.onComplete,onError(t){y?e.onError?.(t):u(!1)}},{retainedDialog:m,present(t){t(!0),y=!0,u(!0)},async dismiss(){e.onDismiss()}});return!o||!await O||r.aborted?(o?.destroy(),null):{document:w.document,destroy:()=>o.destroy()}}finally{r.removeEventListener("abort",P)}}export{V as mountFunnelRecoveryPaywall};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"./chunk-5UVYLTM7.js";import"./chunk-JJIP6BZL.js";import"./chunk-R4BYUK7S.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import"./chunk-OV46DXRX.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-L64BS65O.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{a as PRERENDER_MAX_AGE_MS,b as preparedInternals,c as prerenderFunnelPurchase};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c}from"./chunk-JJIP6BZL.js";import"./chunk-R4BYUK7S.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import"./chunk-VILB5M4X.js";import"./chunk-NNJVMJUG.js";import"./chunk-5YBTU4KS.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{a as predictFunnelStart,c as predictedPaywallLoadingDocument,b as predictionRefusal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,b as o,c as n}from"./chunk-R4BYUK7S.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import"./chunk-VILB5M4X.js";import"./chunk-NNJVMJUG.js";import"./chunk-5YBTU4KS.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{e as FUNNEL_ROUTE_LIMITS,o as funnelRouteSchema,n as projectFunnelRoute};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b}from"./chunk-3LDOPWRV.js";import"./chunk-5UVYLTM7.js";import"./chunk-C4NXQMSO.js";import"./chunk-JJIP6BZL.js";import"./chunk-R4BYUK7S.js";import"./chunk-OQ2E3JLZ.js";import"./chunk-554BTJ3I.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-LENTXDGK.js";import"./chunk-73UFNVEP.js";import"./chunk-BX2MSRA4.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import"./chunk-GGZG56GR.js";import"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import"./chunk-5HYA7TBE.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import"./chunk-SLUA7ABW.js";import"./chunk-YA2XHXUS.js";import"./chunk-NMBKBC7X.js";import"./chunk-5YBTU4KS.js";import"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as En,c as bn}from"./chunk-LWGET37W.js";import{a as Rn}from"./chunk-MG4LSTTR.js";import{a as We}from"./chunk-AEQUKR4O.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as pn,c as wn,d as Sn}from"./chunk-V7KYGDFS.js";import"./chunk-3DH36REB.js";import{a as In}from"./chunk-OG2WLSCL.js";import"./chunk-RUAV3HOQ.js";import{h as mn,i as vn,k as Pn}from"./chunk-C6THF4EZ.js";import{E as Ae,d as Xe,f as Qe,g as ge,h as ve,i as Ye,w as yn}from"./chunk-R4CEK37U.js";import"./chunk-KRTURVO3.js";import{a as ze}from"./chunk-QV6FPIP5.js";import"./chunk-3IMU6FJB.js";import"./chunk-MJ3YZT3G.js";import"./chunk-XZTHQPBE.js";import"./chunk-QVPSTUJ4.js";import"./chunk-VROUIFSG.js";import{K as Ke}from"./chunk-LI5S3AAP.js";import"./chunk-ZOVQW5BP.js";import"./chunk-MR475LAL.js";import{c as hn,e as gn}from"./chunk-FA4TDZ5J.js";import"./chunk-YNBMNXUI.js";import"./chunk-5OPOCHOK.js";import{B as dn,C as ln,D as un,E as fn,c as an,d as sn,e as cn}from"./chunk-EJ5YUUWB.js";import{A as Le,B as Be,D as He,F as qe,G as Ue,I as Ve,J as je,K as Ge,L as Je,M as Te,N as $e,z as _e}from"./chunk-SIEWM7RJ.js";import"./chunk-VILB5M4X.js";import{b as Ce}from"./chunk-XQQZZYX6.js";import"./chunk-O6URZTR3.js";import"./chunk-BSYGUZTD.js";import"./chunk-64KBBZD7.js";import"./chunk-TPFGWBVS.js";import"./chunk-F2PTNSHT.js";import"./chunk-LEDJ6HS3.js";import{a as G}from"./chunk-YKGPZJTV.js";import"./chunk-XRCW5N3J.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as we,d as Ee}from"./chunk-TKBXL3WV.js";import"./chunk-3VUPVXAV.js";import"./chunk-YQW3LPLJ.js";import{b as U}from"./chunk-JX6MARAN.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var I=class extends Error{constructor(f,b=0,w=!1,h="fix_request"){super(f);this.code=f;this.status=b;this.retryable=w;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function _n(n,d){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let f=n.body?.getReader();if(!f)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let b=()=>{f.cancel().catch(()=>{})};d.addEventListener("abort",b,{once:!0});let w=0,h="",t=new TextDecoder("utf-8",{fatal:!0});try{for(d.throwIfAborted();;){let i=await f.read();if(d.throwIfAborted(),i.done)break;if(w+=i.value.byteLength,w>262144)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=t.decode(i.value,{stream:!0})}return h+=t.decode(),JSON.parse(h)}catch(i){throw d.throwIfAborted(),i instanceof I?i:new I("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{d.removeEventListener("abort",b),await f.cancel().catch(()=>{}),f.releaseLock()}}function Tn(n){let d=qe.parse(n.origin),f=Ue.parse(n.manifest),b={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let m of["projectId","environmentId","environment"])if(f[m]!==n.scope[m])throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");let w=n.customerId===void 0?null:U.uuid().parse(n.customerId),h=0,t=null,i=null,u=new AbortController,y=n.fetch??globalThis.fetch;async function P(m,s,E,_,O){if(!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=He[m];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(S.authority))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);let l=h,o=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],..._?[_]:[]]);o.throwIfAborted();let T=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(T.get("authorization")??"")||T.has("X-Indiana-Bridge-Signature")||T.has("X-Indiana-Bridge-Key-Id"))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);T.set(Be,String(_e)),T.set("Accept","application/json");let g=crypto.randomUUID();T.set("X-Request-Id",g),T.set("Content-Type","application/json");let M=await y(d+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:T,signal:o,body:JSON.stringify({bridgeVersion:_e,requestId:g,command:S.command,scope:b,data:O??(E===void 0?{}:{operationId:E})})}),J=await _n(M,o);if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(!M.ok){let F=$e.safeParse(J);throw!F.success||F.data.scope.projectId!==n.scope.projectId||F.data.scope.environment!==n.scope.environment||F.data.scope.environmentId!==n.scope.environmentId||F.data.requestId!==g||F.data.command!==S.command?new I("MERCHANT_BRIDGE_INVALID_RESPONSE",M.status):new I(F.data.error.code,M.status,F.data.error.retryable,F.data.error.recovery)}let c=Ve(U.unknown()).safeParse(J);if(!c.success||c.data.scope.projectId!==n.scope.projectId||c.data.scope.environment!==n.scope.environment||c.data.scope.environmentId!==n.scope.environmentId||c.data.requestId!==g||c.data.command!==S.command)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",M.status);let $=s.safeParse(c.data.data);if(!$.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",M.status);return $.data}function R(){if(!w)throw new I("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return w}async function B(m,s,E,_){let O=R();if(_!==void 0&&Te.parse({operationId:_,customerId:O}),!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=h,l=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,T=new Promise((g,M)=>{o=()=>M(l.reason),l.addEventListener("abort",o,{once:!0})});try{let M=E(async()=>{let c=await import("./merchant-bridge-contracts-GBBL3HTW.js");if(l.throwIfAborted(),S!==h||w!==O)throw new DOMException("Merchant identity changed","AbortError");return c},l),J=await Promise.race([M,T]);return l.throwIfAborted(),J}finally{l.removeEventListener("abort",o)}}async function z(m,s,E,_){let O=R(),S=Te.parse({operationId:E,customerId:O}),l=await P(m,s,S.operationId,_,S);if(l.customerId!==O||l.operationId!==S.operationId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(m){let s=await P("presentation",Ge,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&w!==null&&s.presentation.customerId!==w)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,t=s.presentation,s},async createSession(m){let s=await P("session",je,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(w!==null&&w!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return w=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(m,s){let E=R(),_=Je.parse(m);if(!t||t.customerId!==E||t.decisionId!==_.decisionId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return P("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,s,_)},async readCustomerCommerce(m){let s=R(),E=await B("customer_commerce",m,async(_,O)=>{let[S,l]=await Promise.all([_(),P("customer_commerce",U.unknown(),void 0,O)]),o=S.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(E.customerId!==s)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E},async executePurchase(m,s){let E=await B("purchases",s,async(_,O)=>z("purchases",(await _()).merchantBridgeOperationSchema,m,O),m);if(E.type!=="purchase")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},readOperation:(m,s)=>B("operation_status",s,async(E,_)=>z("operation_status",(await E()).merchantOperationLookupSchema,m,_),m),async executeSubscriptionChange(m,s){let E=await B("subscription_changes",s,async(_,O)=>z("subscription_changes",(await _()).merchantBridgeOperationSchema,m,O),m);if(E.type!=="subscription_change")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},reset(){h++,u.abort(),u=new AbortController,w=null,t=null,i=null}}}var en=U.strictObject({command:ve,target:Qe,runId:U.uuid().optional(),expiresAt:U.iso.datetime({offset:!0}).optional(),deliveryLimit:U.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Ze=U.strictObject({schemaVersion:U.literal(1),entries:U.array(en).max(4e3)});function nn(n){let d=!1,f=()=>{d||n.unavailable(),d=!0};function b(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function w(t){let i=b()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ze.parse(JSON.parse(i)).entries}function h(t,i){let u=b();if(!u)return;if(!i.length)return u.removeItem(t);let y=JSON.stringify(Ze.parse({schemaVersion:1,entries:i}));if(y.length>1048576)throw Error("Entry recovery is too large");u.setItem(t,y)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:w(i)}}catch{f();return}},retain(t,i){if(t)try{let u=en.parse(i);h(t,[...w(t).filter(y=>y.command.funnelId!==u.command.funnelId),u])}catch{f()}},forget(t,i){if(t)try{h(t,w(t).filter(u=>u.command.requestId!==i))}catch{f()}}}}var tn=U.strictObject({version:U.literal(1),runs:U.array(U.uuid()).max(100)}),De=new WeakMap,Oe=new WeakMap;function Se(n){let d=!1;function f(){d||n.unavailable(),d=!0}function b(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function w(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let u=i.get(t.key);return u||i.set(t.key,u=new Set),u}function h(t){if(!t)return;let i=De.get(t.storage),u=i?.get(t.key);u?.delete(t.requestId),u?.size===0&&i?.delete(t.key)}return{claim(t,i,u,y,P=!1){if(u!==void 0)try{let R=n.binding();if(!R)throw Error("Entry delivery identity is unavailable");let B={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...R,i,t]),requestId:y},z=b(B);if(Oe.get(B.storage)?.has(B.key))throw Error("Entry delivery storage is unavailable");B.storage.setItem(B.key,JSON.stringify({version:1,runs:z}));let m=w(B);return!P&&!m.has(y)&&z.length+m.size>=u?!1:(m.add(y),B)}catch{return f(),!1}},accept(t,i){if(t)try{let u=b(t);u.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...u,i].slice(-100)})))}catch{let u=Oe.get(t.storage);u||Oe.set(t.storage,u=new Set),u.add(t.key),f()}finally{h(t)}},release:h}}function Pe(){let n,d,f=()=>{clearTimeout(n),n=void 0;let b=d;d=void 0,b?.cancelled()};return{get active(){return d!==void 0},start(b,w,h,t){if(d)return;if(b===0){w()?h():t();return}let i={valid:w,cancelled:t};d=i,n=setTimeout(()=>{d===i&&(d=void 0,n=void 0,w()?h():t())},b*1e3)},recheck(){d&&!d.valid()&&f()},cancel:f}}var Re=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function Cn(n){let d=we(n.baseUrl),f=n.scope,b=Ce(n),w=n.fetch??globalThis.fetch.bind(globalThis),h,t=!1,i=!1,u=0,y=0,P="",R=0,B=0,z=0,m=!1,s,E=!0,_,O,S,l,o,T=-1,g,M=e=>{g===e&&(F.release(e.deliveryTicket),g=void 0,x())},J=new Set,c=(e,a)=>Z(n.onStatus,e,a),$=Pe(),F=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>c("delivery_unavailable")}),ee=new Set,te=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>c("recovery_unavailable")}),Y=e=>te.forget(e.storageKey,e.command.requestId);function Q(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),te.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),x()}let le=()=>$.active||g!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Q(o.recovery,a);let p=Re(a);o.slot.hidden=p,p!==o.background&&(o.background=p,p?c("run_background",o.entryId):T=y,x())}function pe(e,a,p){let v=e.client.view;if(!a||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let K=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:a}),j=Ce({...n,session:void 0});j.requestWithCredential("funnels",K,e.runToken,{keepalive:p}).then(()=>Y(e.recovery)).catch(()=>{}).finally(()=>j.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<B&&performance.now()<z;function C(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return c("incompatible",e.id),!1}}function H(e){if(t||e.epoch!==R||e.visit!==y||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(e){if(le()){c("in_progress",e.id);return}let a=R,p=y;$.start(e.delivery?.delaySeconds??0,()=>!t&&a===R&&p===y&&document.visibilityState!=="hidden"&&C(e)&&h?.entries.some(v=>v.id===e.id&&v.funnelId===e.funnelId&&v.versionId===e.versionId&&v.event===e.event&&JSON.stringify(v.target)===JSON.stringify(e.target)&&JSON.stringify(v.delivery)===JSON.stringify(e.delivery))===!0,()=>{V(e)},()=>{J.delete(`${e.funnelId}:${e.id}`)})}async function V(e){if(le()){c("in_progress",e.id);return}if(!n.session.peek()){c("identity_required",e.id);return}let a=te.load(),p=a?.entries.find(A=>A.command.funnelId===e.funnelId&&(!A.expiresAt||Date.parse(A.expiresAt)>Date.now()));if(p){if(!X(p)){c("recovery_pending",e.id);return}let A={...p,storageKey:a.key,epoch:R,visit:y};ee.add(A.command.requestId),g=A,await N(A);return}let v=crypto.randomUUID(),K=F.claim(e.id,e.funnelId,e.delivery?.maxPerSession,v);if(K===!1){c("frequency",e.id),x();return}let j={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:K,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:v,locale:document.documentElement.lang||"en"}),epoch:R,visit:y,target:e.target,storageKey:a?.key};ee.add(j.command.requestId),g=j,await N(j)}async function N(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let p,v=!1,K=!1;async function j(A){if(e.epoch!==R)return;let D=A.view;if(!(e.storageKey&&D&&(Re(D)||D.paywall||D.pendingRequest))&&D&&["running","waiting"].includes(D.status))try{await A.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:D.nodeId,visit:D.visit,revision:D.revision}),Y(e)}catch(k){if(!(k instanceof G&&k.code==="FORBIDDEN"))throw k}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let q=F.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);q!==!1&&(e.deliveryTicket=q)}Q(e),c("starting",e.command.entryId);let A=await b.request("funnels",e.command),D=Ye.safeParse(A);if(D.success){if(D.data.scope.projectId!==f.projectId||D.data.scope.environment!==f.environment)throw new G("SCOPE_MISMATCH","Entry scope changed");e.epoch===R&&c(D.data.reason,e.command.entryId),Y(e),M(e);return}let k=Xe.parse(A);if(!k.runToken||k.scope.projectId!==f.projectId||k.scope.environment!==f.environment||k.run.source.type!=="funnel"||k.run.source.id!==e.command.funnelId||k.run.source.versionId!==e.command.versionId||e.runId!==void 0&&k.run.id!==e.runId)throw new G("INVALID_RESPONSE","Invalid entry Run");if(F.accept(e.deliveryTicket,k.run.id),e.epoch!==R){M(e),c("identity_changed",e.command.entryId);return}Q(e,k.run);let L=Ae({...n,runToken:k.runToken,funnelId:e.command.funnelId,initialResponse:a?A:void 0});p=L,K=!0,await L.get(),K=!1;let ne=L.view;if(!ne||ne.id!==k.run.id||ne.source.type!=="funnel"||ne.source.id!==e.command.funnelId||ne.source.versionId!==e.command.versionId)throw new G("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(ne.status)){Y(e),M(e),c("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-DBIJVDWC.js");if(!H(e)){await j(L),c("left_screen",e.command.entryId),M(e);return}let Ne=!1,xe=!1;if(o&&!o.background){await j(L),c("in_progress",e.command.entryId),M(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Re(ne),n.container.append(ie);let ke=await fe(ie,{...n.host,client:L,appManifestRelease:n.appManifestRelease,onState(q){me(L,q),Z(n.host?.onState,q)},onDismiss(q){Ne=!0,ie.remove(),q&&!["running","waiting"].includes(q.status)&&Y(e),o?.client===L&&(o=void 0,L.reset(),x(),q&&q.status!=="completed"&&c("run_ended",e.command.entryId)),Z(n.host?.onDismiss,q)},onComplete(q){xe=!0,Y(e),o?.client===L&&re(),Z(n.host?.onComplete,q)},onError(q){Z(n.host?.onError,q),o?.client===L&&q instanceof G&&q.code==="FORBIDDEN"&&(Y(e),re(),c("run_ended",e.command.entryId))}}).catch(q=>{throw ie.remove(),q});if(!H(e)||Ne||xe){ke.destroy(),ie.remove(),H(e)||await j(L),M(e);return}let he=Re(L.view??ne);ie.hidden=he,o={host:ke,client:L,slot:ie,entryId:e.command.entryId,background:he,runToken:k.runToken,owner:n.session.peek(),recovery:e},he||(T=e.visit),v=!0,M(e),c("started",e.command.entryId),he&&c("run_background",e.command.entryId)}catch(A){A instanceof G&&(!p||K&&A.code==="FORBIDDEN")&&A.status!==void 0&&A.status>=400&&A.status<500&&!A.retryable&&(Y(e),M(e)),e.epoch===R&&!t&&(c("start_failed",e.command.entryId),Z(n.host?.onError,A))}finally{v||p?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=te.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){te.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||ee.has(a.command.requestId)||!X(a))continue;ee.add(a.command.requestId);let p={...a,storageKey:e.key,epoch:R,visit:y};return g=p,N(p),!0}return!1}function ue(){if(m=!1,$.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(T=y),!ye()){if(!r()){E=!0;return}E=!1;for(let a of h?.entries??[]){let p=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||J.has(p)||!C(a))){if(!n.session.peek()){c("identity_required",a.id);continue}if(T===y){J.add(p),e&&c("in_progress",a.id);continue}if(g||$.active){c("in_progress",a.id);return}J.add(p),W(a);break}}}}let x=()=>{!m&&!t&&(m=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===P?!1:(P=e,y++,$.cancel(),E=!0,J.clear(),ee.clear(),!0)}function oe(){se()&&x()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let p=a.closest("button,a,input");if(!(!p||p.matches(":disabled,[aria-disabled='true']")||p.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of h?.entries??[]){let K=v.target.button;if(!(v.event!=="button_click"||!K||!C(v))){try{let j=be(document);if(!p.matches(K.selector)||j(K.selector,p)!==1)continue}catch{c("incompatible",v.id);continue}W(v);break}}}async function Me(){if(t)return;if(s)return s;let e=++u,a=new AbortController;_=a;let p,v=new Promise((A,D)=>{p=()=>D(new G("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",p,{once:!0})}),K=setTimeout(()=>a.abort(),n.timeoutMs??5e3),j=(async()=>{let A=async()=>{let fe=await w(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},D=await Promise.race([A(),v]),k=Date.parse(D.validatedAt),L=Date.parse(D.validUntil);if(D.scope.projectId!==f.projectId||D.scope.environment!==f.environment||D.scope.environmentId!==n.environmentId||D.release!==n.appManifestRelease||L<=Date.now()||k>Date.now()+5e3||L-k>6e4||L<=k)throw new G("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==u)return;let ne=h===void 0;h=D,B=L,z=performance.now()+Math.min(L-Date.now(),6e4),$.recheck(),(ne||E)&&x()})();s=j;try{await j}finally{clearTimeout(K),a.signal.removeEventListener("abort",p),s===j&&(s=void 0)}}async function on(){if(!(!i||t)){try{await Me()}catch{t||c("configuration_unavailable")}x()}}let Fe=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,P=location.origin+location.pathname,O=Ee(oe),S=n.session.subscribeIdentity(()=>{R++,$.cancel(),F.release(g?.deliveryTicket),E=!0,g=void 0,J.clear(),T=-1,ee.clear(),o&&pe(o,o.owner,!1),re(),x()}),l=new MutationObserver(x),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",x),addEventListener("pagehide",ae),await Fe.refresh())},refresh:Me,async retry(){g&&!t&&g.epoch===R&&await N(g)},destroy(){t=!0,u++,$.cancel(),F.release(g?.deliveryTicket),Fe.destroy(),_?.abort(),l?.disconnect(),O?.(),S?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",x),removeEventListener("pagehide",ae),ae(),re(),b.dispose(),h=void 0}}}function An(n){let d=we(n.baseUrl),f=n.fetch??globalThis.fetch.bind(globalThis),b,w=0,h=0,t=!1,i=!1,u=!1,y=0,P=0,R=-1,B=!1,z="",m,s,E,_,O=new Set,S,l,o,T=(r,C)=>Z(n.onStatus,r,C),g=Pe(),M=()=>{try{return n.deliveryIdentity?.()}catch{return}},J=()=>JSON.stringify(M()),c=Se({storage:n.deliveryStorage,binding:()=>{let r=M();return r?.id?[d,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>T("delivery_unavailable")}),$=()=>Date.now()<w&&performance.now()<h;function F(r){try{return $()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return T("incompatible",r.id),!1}}function ee(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function te(r){if(r.dispatching)return;r.dispatching=!0;let C=y;try{let H=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});c.accept(r.deliveryTicket,H.run.id);let{showFunnelRun:W}=await import("./funnel-runtime-host-DBIJVDWC.js");if(t||C!==y||l!==r)return;let V=document.createElement("div");n.container.append(V),R=P;let N=await W(V,{...n.host,client:H.controller,appManifestRelease:n.appManifestRelease,onDismiss(X){o?.process===r.process&&(o=void 0,V.remove()),Z(n.host?.onDismiss,X)}});if(t||C!==y||l!==r){N.destroy(),V.remove();return}o={entry:r.entry,process:r.process,host:N,slot:V,deliveryTicket:r.deliveryTicket},l=void 0,T("run_presented",r.entry.id)}catch(H){if(t||C!==y||l!==r)return;H instanceof G&&"result"in H?(c.release(r.deliveryTicket),l=void 0,r.process.destroy(),T("suppressed",r.entry.id),Q()):T("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function Y(r){if(t||i||l||o||S||g.active||R===P||!F(r))return;let C=`${P}:${r.id}`;if(O.has(C))return;O.add(C);let H=P,W=y,V=J();g.start(r.delivery?.delaySeconds??0,()=>!t&&y===W&&P===H&&J()===V&&document.visibilityState!=="hidden"&&F(r)&&b?.entries.some(N=>N.id===r.id&&N.funnelId===r.funnelId&&N.versionId===r.versionId&&N.event===r.event&&JSON.stringify(N.target)===JSON.stringify(r.target)&&JSON.stringify(N.delivery)===JSON.stringify(r.delivery))===!0,()=>{let N=c.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(N===!1){T("frequency",r.id),Q();return}try{let X={entry:r,process:n.createProcess(r),visit:P,deliveryTicket:N};l=X,te(X)}catch(X){c.release(N),T("entry_unavailable",r.id),Z(n.host?.onError,X)}},()=>{O.delete(C)})}function Q(){B||t||(B=!0,queueMicrotask(()=>{if(B=!1,g.recheck(),!(t||i||document.visibilityState==="hidden"||!$()||l||o||S||g.active||R===P)){for(let r of b?.entries??[])if(r.event==="screen_enter"&&!O.has(`${P}:${r.id}`)&&F(r)){Y(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||l||o||S||R===P)return;let C=be(document,()=>{});for(let H of b?.entries??[]){let W=H.target.button;if(H.event!=="button_click"||!W||!F(H))continue;let V=r.target.closest(W.selector);if(!(!V||V.tagName.toLowerCase()!==W.tag||C(W.selector)!==1||V.matches(":disabled")||V.closest('[inert],[hidden],[aria-hidden="true"]'))){Y(H);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,P++,g.cancel(),O.clear(),Q())};async function me(){if(t)return;if(s)return s;let r=y,C=new AbortController;m=C;let H,W=new Promise((ye,ue)=>{H=ue}),V=()=>H(new G("TIMEOUT","Funnel entry read cancelled"));C.signal.addEventListener("abort",V,{once:!0});let N=setTimeout(()=>C.abort(),n.timeoutMs??5e3),X=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await f(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:C.signal});if(!ce.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},x=await Promise.race([ue(),W]),se=Date.parse(x.validatedAt),oe=Date.parse(x.validUntil);if(x.scope.projectId!==n.scope.projectId||x.scope.environment!==n.scope.environment||x.scope.environmentId!==n.environmentId||x.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new G("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==y||(b=x,w=oe,h=performance.now()+Math.min(oe-Date.now(),6e4),g.recheck(),Q())})();s=X;try{await X}finally{clearTimeout(N),C.signal.removeEventListener("abort",V),s===X&&(s=void 0)}}async function pe(){if(!(!u||t))try{await me()}catch{t||T("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>u&&!t?15e3:void 0});return{async start(){u||t||(u=!0,z=location.origin+location.pathname,E=Ee(le),_=new MutationObserver(Q),_.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Q),await ae.refresh())},refresh:me,async retry(){l&&!t&&await te(l)},async syncIdentity(){g.cancel();let r=o??l??S;if(!r){i=!1,Q();return}try{let C=await r.process.syncIdentity();return i=!1,S===r&&(l={...r,visit:P},S=void 0,await te(l)),C}catch(C){throw r.process.view||(S={...r,visit:P},l=void 0,ee()),C}},async detach(){i=!0,y++,g.cancel(),m?.abort();let r=o??l??S;r&&(S={...r,visit:P}),l=void 0,ee(),r&&await r.process.detach()},destroy(){t=!0,y++,g.cancel(),ae.destroy(),m?.abort(),_?.disconnect(),E?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Q);let r=o??l??S;c.release(r?.deliveryTicket),l=void 0,S=void 0,ee(),r?.process.destroy(),b=void 0}}}async function Dn(n,d){return(await import("./paywall-EL57YBHZ.js")).showPaywall(n,d)}async function dt(){return await Promise.all([import("./paywall-EL57YBHZ.js"),import("./screen-renderer-XIKOUOI5.js")]),Dn}async function lt(...n){return n[1]=ze(n[1]),(await import("./paywall-session-6NKVDVYG.js")).createPaywallSession(...n)}async function ut(...n){let d=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-XIKOUOI5.js").catch(()=>{}),import("./paywall-EL57YBHZ.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-DBIJVDWC.js"),n[1].prepared)).showFunnelRun(...n)}finally{d?.()}}async function rn(n,d){try{return await n()}catch(f){throw d&&d.state!=="adopted"&&await import("./funnel-paywall-prerender-BZ3OBCHW.js").then(b=>b.preparedInternals(d)?.release(),()=>{}),f}}async function ft(...n){return import("./screen-renderer-XIKOUOI5.js").catch(()=>{}),import("./paywall-EL57YBHZ.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-6Y6SU3B6.js"),n[1].prepared)).showFunnelPurchase(...n)}async function mt(...n){return import("./funnel-host-purchase-6Y6SU3B6.js").catch(()=>{}),import("./screen-renderer-XIKOUOI5.js").catch(()=>{}),(await import("./funnel-paywall-prerender-BZ3OBCHW.js")).prerenderFunnelPurchase(...n)}async function pt(){await Promise.all([import("./funnel-paywall-prerender-BZ3OBCHW.js"),import("./funnel-host-purchase-6Y6SU3B6.js"),import("./paywall-EL57YBHZ.js"),import("./screen-renderer-XIKOUOI5.js"),import("./paywall-content-YLX2XXIT.js"),import("./check-response-3OBQIMGN.js"),import("./operation-contracts-RDRBT3QK.js")])}async function yt(...n){return(await import("./funnel-route-prediction-4UCZCVH5.js")).predictFunnelStart(...n)}async function ht(...n){return(await import("./funnel-route-prediction-4UCZCVH5.js")).predictedPaywallLoadingDocument(...n)}async function gt(...n){return(await import("./funnel-host-recovery-paywall-PSGZT6MQ.js")).mountFunnelRecoveryPaywall(...n)}async function vt(...n){return(await import("./content-JV2I65BF.js")).mountContent(...n)}async function It(...n){return(await import("./content-JV2I65BF.js")).prepareContent(...n)}export{G as LongplayError,I as MerchantBridgeError,yn as createBrowserFunnelCommandStorage,En as createBrowserFunnelPurchaseStorage,vn as createConfigurationSync,mn as createFeatureClient,wn as createFunnelClient,Rn as createFunnelPageExperiments,Sn as createFunnelProcess,bn as createFunnelPurchaseClient,Ae as createFunnelRunController,Cn as createIamFunnelEntries,An as createIamFunnelProcessEntries,Pn as createLocalFunnelClient,pn as createLongplay,Tn as createMerchantBridge,lt as createPaywallSession,In as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,hn as getPaywallRecovery,un as isPaywallOperationComplete,fn as isPaywallOperationPending,ln as isPaywallUpdateOperation,dn as isPaywallUpdateQuote,vt as mountContent,gt as mountFunnelRecoveryPaywall,yt as predictFunnelStart,ht as predictedPaywallLoadingDocument,pt as preloadFunnelPurchase,dt as preloadPaywall,It as prepareContent,gn as preparePaywallFallback,mt as prerenderFunnelPurchase,ft as showFunnelPurchase,ut as showFunnelRun,Dn as showPaywall};
|
|
1
|
+
import{a as En,c as bn}from"./chunk-UWMXBSYO.js";import{a as Rn}from"./chunk-554BTJ3I.js";import{a as We}from"./chunk-AEQUKR4O.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as pn,c as wn,d as Sn}from"./chunk-LOKH33KR.js";import"./chunk-PVMGYRGE.js";import{a as In}from"./chunk-AJVVXHP7.js";import"./chunk-36VNAOG6.js";import{h as mn,i as vn,k as Pn}from"./chunk-2OBAMFGZ.js";import{E as Ae,d as Xe,f as Qe,g as ge,h as ve,i as Ye,w as yn}from"./chunk-6K6N5XLO.js";import"./chunk-73UFNVEP.js";import{a as ze}from"./chunk-CAE4KIZN.js";import"./chunk-CJUODAOF.js";import"./chunk-XHZH3E4G.js";import"./chunk-725DCRIN.js";import"./chunk-6HKQILBV.js";import"./chunk-EACC667P.js";import{K as Ke}from"./chunk-BX2MSRA4.js";import"./chunk-LOBZ45T3.js";import"./chunk-J4RM5GQP.js";import{c as hn,e as gn}from"./chunk-ADTZEBQF.js";import"./chunk-OV46DXRX.js";import"./chunk-M4P6TGBU.js";import{B as dn,C as ln,D as un,E as fn,c as an,d as sn,e as cn}from"./chunk-GGZG56GR.js";import{A as Le,B as Be,D as He,F as qe,G as Ue,I as Ve,J as je,K as Ge,L as Je,M as Te,N as $e,z as _e}from"./chunk-NL7AXMUA.js";import"./chunk-VILB5M4X.js";import{b as Ce}from"./chunk-5HYA7TBE.js";import"./chunk-L64BS65O.js";import"./chunk-QGKROSRD.js";import"./chunk-RRZZUIFM.js";import"./chunk-RJT764B2.js";import"./chunk-BKBWGPNR.js";import"./chunk-NNJVMJUG.js";import{a as G}from"./chunk-WE55LJEN.js";import"./chunk-OZK47BUU.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as we,d as Ee}from"./chunk-YA2XHXUS.js";import"./chunk-3VUPVXAV.js";import"./chunk-NMBKBC7X.js";import{b as U}from"./chunk-5YBTU4KS.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-HMJTABQ5.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";var I=class extends Error{constructor(f,b=0,w=!1,h="fix_request"){super(f);this.code=f;this.status=b;this.retryable=w;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function _n(n,d){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let f=n.body?.getReader();if(!f)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let b=()=>{f.cancel().catch(()=>{})};d.addEventListener("abort",b,{once:!0});let w=0,h="",t=new TextDecoder("utf-8",{fatal:!0});try{for(d.throwIfAborted();;){let i=await f.read();if(d.throwIfAborted(),i.done)break;if(w+=i.value.byteLength,w>262144)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=t.decode(i.value,{stream:!0})}return h+=t.decode(),JSON.parse(h)}catch(i){throw d.throwIfAborted(),i instanceof I?i:new I("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{d.removeEventListener("abort",b),await f.cancel().catch(()=>{}),f.releaseLock()}}function Tn(n){let d=qe.parse(n.origin),f=Ue.parse(n.manifest),b={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let m of["projectId","environmentId","environment"])if(f[m]!==n.scope[m])throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");let w=n.customerId===void 0?null:U.uuid().parse(n.customerId),h=0,t=null,i=null,u=new AbortController,y=n.fetch??globalThis.fetch;async function P(m,s,E,_,O){if(!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=He[m];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(S.authority))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);let l=h,o=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],..._?[_]:[]]);o.throwIfAborted();let T=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(T.get("authorization")??"")||T.has("X-Indiana-Bridge-Signature")||T.has("X-Indiana-Bridge-Key-Id"))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);T.set(Be,String(_e)),T.set("Accept","application/json");let g=crypto.randomUUID();T.set("X-Request-Id",g),T.set("Content-Type","application/json");let M=await y(d+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:T,signal:o,body:JSON.stringify({bridgeVersion:_e,requestId:g,command:S.command,scope:b,data:O??(E===void 0?{}:{operationId:E})})}),J=await _n(M,o);if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(!M.ok){let F=$e.safeParse(J);throw!F.success||F.data.scope.projectId!==n.scope.projectId||F.data.scope.environment!==n.scope.environment||F.data.scope.environmentId!==n.scope.environmentId||F.data.requestId!==g||F.data.command!==S.command?new I("MERCHANT_BRIDGE_INVALID_RESPONSE",M.status):new I(F.data.error.code,M.status,F.data.error.retryable,F.data.error.recovery)}let c=Ve(U.unknown()).safeParse(J);if(!c.success||c.data.scope.projectId!==n.scope.projectId||c.data.scope.environment!==n.scope.environment||c.data.scope.environmentId!==n.scope.environmentId||c.data.requestId!==g||c.data.command!==S.command)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",M.status);let $=s.safeParse(c.data.data);if(!$.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",M.status);return $.data}function R(){if(!w)throw new I("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return w}async function B(m,s,E,_){let O=R();if(_!==void 0&&Te.parse({operationId:_,customerId:O}),!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=h,l=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,T=new Promise((g,M)=>{o=()=>M(l.reason),l.addEventListener("abort",o,{once:!0})});try{let M=E(async()=>{let c=await import("./merchant-bridge-contracts-DEDEIYNU.js");if(l.throwIfAborted(),S!==h||w!==O)throw new DOMException("Merchant identity changed","AbortError");return c},l),J=await Promise.race([M,T]);return l.throwIfAborted(),J}finally{l.removeEventListener("abort",o)}}async function z(m,s,E,_){let O=R(),S=Te.parse({operationId:E,customerId:O}),l=await P(m,s,S.operationId,_,S);if(l.customerId!==O||l.operationId!==S.operationId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(m){let s=await P("presentation",Ge,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&w!==null&&s.presentation.customerId!==w)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,t=s.presentation,s},async createSession(m){let s=await P("session",je,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(w!==null&&w!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return w=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(m,s){let E=R(),_=Je.parse(m);if(!t||t.customerId!==E||t.decisionId!==_.decisionId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return P("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,s,_)},async readCustomerCommerce(m){let s=R(),E=await B("customer_commerce",m,async(_,O)=>{let[S,l]=await Promise.all([_(),P("customer_commerce",U.unknown(),void 0,O)]),o=S.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(E.customerId!==s)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E},async executePurchase(m,s){let E=await B("purchases",s,async(_,O)=>z("purchases",(await _()).merchantBridgeOperationSchema,m,O),m);if(E.type!=="purchase")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},readOperation:(m,s)=>B("operation_status",s,async(E,_)=>z("operation_status",(await E()).merchantOperationLookupSchema,m,_),m),async executeSubscriptionChange(m,s){let E=await B("subscription_changes",s,async(_,O)=>z("subscription_changes",(await _()).merchantBridgeOperationSchema,m,O),m);if(E.type!=="subscription_change")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},reset(){h++,u.abort(),u=new AbortController,w=null,t=null,i=null}}}var en=U.strictObject({command:ve,target:Qe,runId:U.uuid().optional(),expiresAt:U.iso.datetime({offset:!0}).optional(),deliveryLimit:U.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Ze=U.strictObject({schemaVersion:U.literal(1),entries:U.array(en).max(4e3)});function nn(n){let d=!1,f=()=>{d||n.unavailable(),d=!0};function b(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function w(t){let i=b()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ze.parse(JSON.parse(i)).entries}function h(t,i){let u=b();if(!u)return;if(!i.length)return u.removeItem(t);let y=JSON.stringify(Ze.parse({schemaVersion:1,entries:i}));if(y.length>1048576)throw Error("Entry recovery is too large");u.setItem(t,y)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:w(i)}}catch{f();return}},retain(t,i){if(t)try{let u=en.parse(i);h(t,[...w(t).filter(y=>y.command.funnelId!==u.command.funnelId),u])}catch{f()}},forget(t,i){if(t)try{h(t,w(t).filter(u=>u.command.requestId!==i))}catch{f()}}}}var tn=U.strictObject({version:U.literal(1),runs:U.array(U.uuid()).max(100)}),De=new WeakMap,Oe=new WeakMap;function Se(n){let d=!1;function f(){d||n.unavailable(),d=!0}function b(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function w(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let u=i.get(t.key);return u||i.set(t.key,u=new Set),u}function h(t){if(!t)return;let i=De.get(t.storage),u=i?.get(t.key);u?.delete(t.requestId),u?.size===0&&i?.delete(t.key)}return{claim(t,i,u,y,P=!1){if(u!==void 0)try{let R=n.binding();if(!R)throw Error("Entry delivery identity is unavailable");let B={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...R,i,t]),requestId:y},z=b(B);if(Oe.get(B.storage)?.has(B.key))throw Error("Entry delivery storage is unavailable");B.storage.setItem(B.key,JSON.stringify({version:1,runs:z}));let m=w(B);return!P&&!m.has(y)&&z.length+m.size>=u?!1:(m.add(y),B)}catch{return f(),!1}},accept(t,i){if(t)try{let u=b(t);u.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...u,i].slice(-100)})))}catch{let u=Oe.get(t.storage);u||Oe.set(t.storage,u=new Set),u.add(t.key),f()}finally{h(t)}},release:h}}function Pe(){let n,d,f=()=>{clearTimeout(n),n=void 0;let b=d;d=void 0,b?.cancelled()};return{get active(){return d!==void 0},start(b,w,h,t){if(d)return;if(b===0){w()?h():t();return}let i={valid:w,cancelled:t};d=i,n=setTimeout(()=>{d===i&&(d=void 0,n=void 0,w()?h():t())},b*1e3)},recheck(){d&&!d.valid()&&f()},cancel:f}}var Re=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function Cn(n){let d=we(n.baseUrl),f=n.scope,b=Ce(n),w=n.fetch??globalThis.fetch.bind(globalThis),h,t=!1,i=!1,u=0,y=0,P="",R=0,B=0,z=0,m=!1,s,E=!0,_,O,S,l,o,T=-1,g,M=e=>{g===e&&(F.release(e.deliveryTicket),g=void 0,x())},J=new Set,c=(e,a)=>Z(n.onStatus,e,a),$=Pe(),F=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>c("delivery_unavailable")}),ee=new Set,te=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>c("recovery_unavailable")}),Y=e=>te.forget(e.storageKey,e.command.requestId);function Q(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),te.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),x()}let le=()=>$.active||g!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Q(o.recovery,a);let p=Re(a);o.slot.hidden=p,p!==o.background&&(o.background=p,p?c("run_background",o.entryId):T=y,x())}function pe(e,a,p){let v=e.client.view;if(!a||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let K=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:a}),j=Ce({...n,session:void 0});j.requestWithCredential("funnels",K,e.runToken,{keepalive:p}).then(()=>Y(e.recovery)).catch(()=>{}).finally(()=>j.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<B&&performance.now()<z;function C(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return c("incompatible",e.id),!1}}function H(e){if(t||e.epoch!==R||e.visit!==y||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(e){if(le()){c("in_progress",e.id);return}let a=R,p=y;$.start(e.delivery?.delaySeconds??0,()=>!t&&a===R&&p===y&&document.visibilityState!=="hidden"&&C(e)&&h?.entries.some(v=>v.id===e.id&&v.funnelId===e.funnelId&&v.versionId===e.versionId&&v.event===e.event&&JSON.stringify(v.target)===JSON.stringify(e.target)&&JSON.stringify(v.delivery)===JSON.stringify(e.delivery))===!0,()=>{V(e)},()=>{J.delete(`${e.funnelId}:${e.id}`)})}async function V(e){if(le()){c("in_progress",e.id);return}if(!n.session.peek()){c("identity_required",e.id);return}let a=te.load(),p=a?.entries.find(A=>A.command.funnelId===e.funnelId&&(!A.expiresAt||Date.parse(A.expiresAt)>Date.now()));if(p){if(!X(p)){c("recovery_pending",e.id);return}let A={...p,storageKey:a.key,epoch:R,visit:y};ee.add(A.command.requestId),g=A,await N(A);return}let v=crypto.randomUUID(),K=F.claim(e.id,e.funnelId,e.delivery?.maxPerSession,v);if(K===!1){c("frequency",e.id),x();return}let j={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:K,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:v,locale:document.documentElement.lang||"en"}),epoch:R,visit:y,target:e.target,storageKey:a?.key};ee.add(j.command.requestId),g=j,await N(j)}async function N(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let p,v=!1,K=!1;async function j(A){if(e.epoch!==R)return;let D=A.view;if(!(e.storageKey&&D&&(Re(D)||D.paywall||D.pendingRequest))&&D&&["running","waiting"].includes(D.status))try{await A.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:D.nodeId,visit:D.visit,revision:D.revision}),Y(e)}catch(k){if(!(k instanceof G&&k.code==="FORBIDDEN"))throw k}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let q=F.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);q!==!1&&(e.deliveryTicket=q)}Q(e),c("starting",e.command.entryId);let A=await b.request("funnels",e.command),D=Ye.safeParse(A);if(D.success){if(D.data.scope.projectId!==f.projectId||D.data.scope.environment!==f.environment)throw new G("SCOPE_MISMATCH","Entry scope changed");e.epoch===R&&c(D.data.reason,e.command.entryId),Y(e),M(e);return}let k=Xe.parse(A);if(!k.runToken||k.scope.projectId!==f.projectId||k.scope.environment!==f.environment||k.run.source.type!=="funnel"||k.run.source.id!==e.command.funnelId||k.run.source.versionId!==e.command.versionId||e.runId!==void 0&&k.run.id!==e.runId)throw new G("INVALID_RESPONSE","Invalid entry Run");if(F.accept(e.deliveryTicket,k.run.id),e.epoch!==R){M(e),c("identity_changed",e.command.entryId);return}Q(e,k.run);let L=Ae({...n,runToken:k.runToken,funnelId:e.command.funnelId,initialResponse:a?A:void 0});p=L,K=!0,await L.get(),K=!1;let ne=L.view;if(!ne||ne.id!==k.run.id||ne.source.type!=="funnel"||ne.source.id!==e.command.funnelId||ne.source.versionId!==e.command.versionId)throw new G("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(ne.status)){Y(e),M(e),c("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-HEBLLPFC.js");if(!H(e)){await j(L),c("left_screen",e.command.entryId),M(e);return}let Ne=!1,xe=!1;if(o&&!o.background){await j(L),c("in_progress",e.command.entryId),M(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Re(ne),n.container.append(ie);let ke=await fe(ie,{...n.host,client:L,appManifestRelease:n.appManifestRelease,onState(q){me(L,q),Z(n.host?.onState,q)},onDismiss(q){Ne=!0,ie.remove(),q&&!["running","waiting"].includes(q.status)&&Y(e),o?.client===L&&(o=void 0,L.reset(),x(),q&&q.status!=="completed"&&c("run_ended",e.command.entryId)),Z(n.host?.onDismiss,q)},onComplete(q){xe=!0,Y(e),o?.client===L&&re(),Z(n.host?.onComplete,q)},onError(q){Z(n.host?.onError,q),o?.client===L&&q instanceof G&&q.code==="FORBIDDEN"&&(Y(e),re(),c("run_ended",e.command.entryId))}}).catch(q=>{throw ie.remove(),q});if(!H(e)||Ne||xe){ke.destroy(),ie.remove(),H(e)||await j(L),M(e);return}let he=Re(L.view??ne);ie.hidden=he,o={host:ke,client:L,slot:ie,entryId:e.command.entryId,background:he,runToken:k.runToken,owner:n.session.peek(),recovery:e},he||(T=e.visit),v=!0,M(e),c("started",e.command.entryId),he&&c("run_background",e.command.entryId)}catch(A){A instanceof G&&(!p||K&&A.code==="FORBIDDEN")&&A.status!==void 0&&A.status>=400&&A.status<500&&!A.retryable&&(Y(e),M(e)),e.epoch===R&&!t&&(c("start_failed",e.command.entryId),Z(n.host?.onError,A))}finally{v||p?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=te.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){te.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||ee.has(a.command.requestId)||!X(a))continue;ee.add(a.command.requestId);let p={...a,storageKey:e.key,epoch:R,visit:y};return g=p,N(p),!0}return!1}function ue(){if(m=!1,$.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(T=y),!ye()){if(!r()){E=!0;return}E=!1;for(let a of h?.entries??[]){let p=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||J.has(p)||!C(a))){if(!n.session.peek()){c("identity_required",a.id);continue}if(T===y){J.add(p),e&&c("in_progress",a.id);continue}if(g||$.active){c("in_progress",a.id);return}J.add(p),W(a);break}}}}let x=()=>{!m&&!t&&(m=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===P?!1:(P=e,y++,$.cancel(),E=!0,J.clear(),ee.clear(),!0)}function oe(){se()&&x()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let p=a.closest("button,a,input");if(!(!p||p.matches(":disabled,[aria-disabled='true']")||p.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of h?.entries??[]){let K=v.target.button;if(!(v.event!=="button_click"||!K||!C(v))){try{let j=be(document);if(!p.matches(K.selector)||j(K.selector,p)!==1)continue}catch{c("incompatible",v.id);continue}W(v);break}}}async function Me(){if(t)return;if(s)return s;let e=++u,a=new AbortController;_=a;let p,v=new Promise((A,D)=>{p=()=>D(new G("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",p,{once:!0})}),K=setTimeout(()=>a.abort(),n.timeoutMs??5e3),j=(async()=>{let A=async()=>{let fe=await w(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},D=await Promise.race([A(),v]),k=Date.parse(D.validatedAt),L=Date.parse(D.validUntil);if(D.scope.projectId!==f.projectId||D.scope.environment!==f.environment||D.scope.environmentId!==n.environmentId||D.release!==n.appManifestRelease||L<=Date.now()||k>Date.now()+5e3||L-k>6e4||L<=k)throw new G("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==u)return;let ne=h===void 0;h=D,B=L,z=performance.now()+Math.min(L-Date.now(),6e4),$.recheck(),(ne||E)&&x()})();s=j;try{await j}finally{clearTimeout(K),a.signal.removeEventListener("abort",p),s===j&&(s=void 0)}}async function on(){if(!(!i||t)){try{await Me()}catch{t||c("configuration_unavailable")}x()}}let Fe=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,P=location.origin+location.pathname,O=Ee(oe),S=n.session.subscribeIdentity(()=>{R++,$.cancel(),F.release(g?.deliveryTicket),E=!0,g=void 0,J.clear(),T=-1,ee.clear(),o&&pe(o,o.owner,!1),re(),x()}),l=new MutationObserver(x),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",x),addEventListener("pagehide",ae),await Fe.refresh())},refresh:Me,async retry(){g&&!t&&g.epoch===R&&await N(g)},destroy(){t=!0,u++,$.cancel(),F.release(g?.deliveryTicket),Fe.destroy(),_?.abort(),l?.disconnect(),O?.(),S?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",x),removeEventListener("pagehide",ae),ae(),re(),b.dispose(),h=void 0}}}function An(n){let d=we(n.baseUrl),f=n.fetch??globalThis.fetch.bind(globalThis),b,w=0,h=0,t=!1,i=!1,u=!1,y=0,P=0,R=-1,B=!1,z="",m,s,E,_,O=new Set,S,l,o,T=(r,C)=>Z(n.onStatus,r,C),g=Pe(),M=()=>{try{return n.deliveryIdentity?.()}catch{return}},J=()=>JSON.stringify(M()),c=Se({storage:n.deliveryStorage,binding:()=>{let r=M();return r?.id?[d,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>T("delivery_unavailable")}),$=()=>Date.now()<w&&performance.now()<h;function F(r){try{return $()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return T("incompatible",r.id),!1}}function ee(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function te(r){if(r.dispatching)return;r.dispatching=!0;let C=y;try{let H=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});c.accept(r.deliveryTicket,H.run.id);let{showFunnelRun:W}=await import("./funnel-runtime-host-HEBLLPFC.js");if(t||C!==y||l!==r)return;let V=document.createElement("div");n.container.append(V),R=P;let N=await W(V,{...n.host,client:H.controller,appManifestRelease:n.appManifestRelease,onDismiss(X){o?.process===r.process&&(o=void 0,V.remove()),Z(n.host?.onDismiss,X)}});if(t||C!==y||l!==r){N.destroy(),V.remove();return}o={entry:r.entry,process:r.process,host:N,slot:V,deliveryTicket:r.deliveryTicket},l=void 0,T("run_presented",r.entry.id)}catch(H){if(t||C!==y||l!==r)return;H instanceof G&&"result"in H?(c.release(r.deliveryTicket),l=void 0,r.process.destroy(),T("suppressed",r.entry.id),Q()):T("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function Y(r){if(t||i||l||o||S||g.active||R===P||!F(r))return;let C=`${P}:${r.id}`;if(O.has(C))return;O.add(C);let H=P,W=y,V=J();g.start(r.delivery?.delaySeconds??0,()=>!t&&y===W&&P===H&&J()===V&&document.visibilityState!=="hidden"&&F(r)&&b?.entries.some(N=>N.id===r.id&&N.funnelId===r.funnelId&&N.versionId===r.versionId&&N.event===r.event&&JSON.stringify(N.target)===JSON.stringify(r.target)&&JSON.stringify(N.delivery)===JSON.stringify(r.delivery))===!0,()=>{let N=c.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(N===!1){T("frequency",r.id),Q();return}try{let X={entry:r,process:n.createProcess(r),visit:P,deliveryTicket:N};l=X,te(X)}catch(X){c.release(N),T("entry_unavailable",r.id),Z(n.host?.onError,X)}},()=>{O.delete(C)})}function Q(){B||t||(B=!0,queueMicrotask(()=>{if(B=!1,g.recheck(),!(t||i||document.visibilityState==="hidden"||!$()||l||o||S||g.active||R===P)){for(let r of b?.entries??[])if(r.event==="screen_enter"&&!O.has(`${P}:${r.id}`)&&F(r)){Y(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||l||o||S||R===P)return;let C=be(document,()=>{});for(let H of b?.entries??[]){let W=H.target.button;if(H.event!=="button_click"||!W||!F(H))continue;let V=r.target.closest(W.selector);if(!(!V||V.tagName.toLowerCase()!==W.tag||C(W.selector)!==1||V.matches(":disabled")||V.closest('[inert],[hidden],[aria-hidden="true"]'))){Y(H);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,P++,g.cancel(),O.clear(),Q())};async function me(){if(t)return;if(s)return s;let r=y,C=new AbortController;m=C;let H,W=new Promise((ye,ue)=>{H=ue}),V=()=>H(new G("TIMEOUT","Funnel entry read cancelled"));C.signal.addEventListener("abort",V,{once:!0});let N=setTimeout(()=>C.abort(),n.timeoutMs??5e3),X=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await f(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:C.signal});if(!ce.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},x=await Promise.race([ue(),W]),se=Date.parse(x.validatedAt),oe=Date.parse(x.validUntil);if(x.scope.projectId!==n.scope.projectId||x.scope.environment!==n.scope.environment||x.scope.environmentId!==n.environmentId||x.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new G("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==y||(b=x,w=oe,h=performance.now()+Math.min(oe-Date.now(),6e4),g.recheck(),Q())})();s=X;try{await X}finally{clearTimeout(N),C.signal.removeEventListener("abort",V),s===X&&(s=void 0)}}async function pe(){if(!(!u||t))try{await me()}catch{t||T("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>u&&!t?15e3:void 0});return{async start(){u||t||(u=!0,z=location.origin+location.pathname,E=Ee(le),_=new MutationObserver(Q),_.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Q),await ae.refresh())},refresh:me,async retry(){l&&!t&&await te(l)},async syncIdentity(){g.cancel();let r=o??l??S;if(!r){i=!1,Q();return}try{let C=await r.process.syncIdentity();return i=!1,S===r&&(l={...r,visit:P},S=void 0,await te(l)),C}catch(C){throw r.process.view||(S={...r,visit:P},l=void 0,ee()),C}},async detach(){i=!0,y++,g.cancel(),m?.abort();let r=o??l??S;r&&(S={...r,visit:P}),l=void 0,ee(),r&&await r.process.detach()},destroy(){t=!0,y++,g.cancel(),ae.destroy(),m?.abort(),_?.disconnect(),E?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Q);let r=o??l??S;c.release(r?.deliveryTicket),l=void 0,S=void 0,ee(),r?.process.destroy(),b=void 0}}}async function Dn(n,d){return(await import("./paywall-HZVO7BDI.js")).showPaywall(n,d)}async function dt(){return await Promise.all([import("./paywall-HZVO7BDI.js"),import("./screen-renderer-XBWES3XN.js")]),Dn}async function lt(...n){return n[1]=ze(n[1]),(await import("./paywall-session-TS7G7OEM.js")).createPaywallSession(...n)}async function ut(...n){let d=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-XBWES3XN.js").catch(()=>{}),import("./paywall-HZVO7BDI.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-HEBLLPFC.js"),n[1].prepared)).showFunnelRun(...n)}finally{d?.()}}async function rn(n,d){try{return await n()}catch(f){throw d&&d.state!=="adopted"&&await import("./funnel-paywall-prerender-XBEUY6CG.js").then(b=>b.preparedInternals(d)?.release(),()=>{}),f}}async function ft(...n){return import("./screen-renderer-XBWES3XN.js").catch(()=>{}),import("./paywall-HZVO7BDI.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-H6BMFIXK.js"),n[1].prepared)).showFunnelPurchase(...n)}async function mt(...n){return import("./funnel-host-purchase-H6BMFIXK.js").catch(()=>{}),import("./screen-renderer-XBWES3XN.js").catch(()=>{}),(await import("./funnel-paywall-prerender-XBEUY6CG.js")).prerenderFunnelPurchase(...n)}async function pt(){await Promise.all([import("./funnel-paywall-prerender-XBEUY6CG.js"),import("./funnel-host-purchase-H6BMFIXK.js"),import("./paywall-HZVO7BDI.js"),import("./screen-renderer-XBWES3XN.js"),import("./paywall-content-KBHI22JD.js"),import("./check-response-MJHH5FWT.js"),import("./operation-contracts-RHJJI5NO.js")])}async function yt(...n){return(await import("./funnel-route-prediction-ICGW4DPX.js")).predictFunnelStart(...n)}async function ht(...n){return(await import("./funnel-route-prediction-ICGW4DPX.js")).predictedPaywallLoadingDocument(...n)}async function gt(...n){return(await import("./funnel-host-recovery-paywall-UQC5FAL4.js")).mountFunnelRecoveryPaywall(...n)}async function vt(...n){return(await import("./content-3MNGXC7L.js")).mountContent(...n)}async function It(...n){return(await import("./content-3MNGXC7L.js")).prepareContent(...n)}export{G as LongplayError,I as MerchantBridgeError,yn as createBrowserFunnelCommandStorage,En as createBrowserFunnelPurchaseStorage,vn as createConfigurationSync,mn as createFeatureClient,wn as createFunnelClient,Rn as createFunnelPageExperiments,Sn as createFunnelProcess,bn as createFunnelPurchaseClient,Ae as createFunnelRunController,Cn as createIamFunnelEntries,An as createIamFunnelProcessEntries,Pn as createLocalFunnelClient,pn as createLongplay,Tn as createMerchantBridge,lt as createPaywallSession,In as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,hn as getPaywallRecovery,un as isPaywallOperationComplete,fn as isPaywallOperationPending,ln as isPaywallUpdateOperation,dn as isPaywallUpdateQuote,vt as mountContent,gt as mountFunnelRecoveryPaywall,yt as predictFunnelStart,ht as predictedPaywallLoadingDocument,pt as preloadFunnelPurchase,dt as preloadPaywall,It as prepareContent,gn as preparePaywallFallback,mt as prerenderFunnelPurchase,ft as showFunnelPurchase,ut as showFunnelRun,Dn as showPaywall};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{P as r,Q as m,j as e}from"./chunk-NL7AXMUA.js";import"./chunk-L64BS65O.js";import"./chunk-BKBWGPNR.js";import"./chunk-OZK47BUU.js";import"./chunk-5YBTU4KS.js";import"./chunk-DLRCJF6U.js";import"./chunk-WOT6VMZA.js";export{m as merchantBridgeCommerceSchema,r as merchantBridgeOperationSchema,e as merchantOperationLookupSchema};
|