@tinkerlandai/longplay-sdk 0.10.96 → 0.10.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +3 -0
- package/README.zh-CN.md +2 -0
- package/dist/{chunk-PWE3ZWLR.js → chunk-33EKLIMB.js} +1 -1
- package/dist/{chunk-7JJGSLXD.js → chunk-55B6CYG6.js} +1 -1
- package/dist/chunk-7DQV2EUW.js +1 -0
- package/dist/{chunk-7NCZ6XU7.js → chunk-AO56DGNZ.js} +1 -1
- package/dist/{chunk-DLORK3P2.js → chunk-BANN2HQH.js} +1 -1
- package/dist/{chunk-MYG5MAKQ.js → chunk-BQFIJCBA.js} +1 -1
- package/dist/chunk-GFH7OK3S.js +1 -0
- package/dist/{chunk-TE2F4PML.js → chunk-HKLAHQKF.js} +1 -1
- package/dist/{chunk-B6TDAH7X.js → chunk-JLKODCRG.js} +2 -2
- package/dist/{chunk-5HWHBCVN.js → chunk-JYTUTIBB.js} +1 -1
- package/dist/{chunk-3XH64DN3.js → chunk-PBHOJKKG.js} +1 -1
- package/dist/{chunk-6CNAIAG2.js → chunk-WLO2GDRF.js} +1 -1
- package/dist/{chunk-XSJGNM2C.js → chunk-XWVK4SJA.js} +1 -1
- package/dist/{content-EV62FGPW.js → content-IDQO7TKS.js} +1 -1
- package/dist/{funnel-host-purchase-6BBAZXCX.js → funnel-host-purchase-7IYZRPYA.js} +1 -1
- package/dist/{funnel-host-purchase-entry-5UDZJJBN.js → funnel-host-purchase-entry-FFZUEX4Q.js} +1 -1
- package/dist/{funnel-host-recovery-paywall-AK4CJGGB.js → funnel-host-recovery-paywall-DGCR4IBQ.js} +1 -1
- package/dist/{funnel-paywall-prerender-YPVUTJTO.js → funnel-paywall-prerender-QHEGZSPT.js} +1 -1
- package/dist/{funnel-runtime-host-D54WIMXD.js → funnel-runtime-host-CFDI4AWM.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/page.js +1 -1
- package/dist/{paywall-DWBIV43F.js → paywall-2Z3FUN2M.js} +1 -1
- package/dist/{paywall-content-S6A2WLIX.js → paywall-content-JXWPOE3Y.js} +1 -1
- package/dist/{paywall-session-R3WV3BSU.js → paywall-session-RNEEPYPG.js} +1 -1
- package/dist/react-native.js +1 -1
- package/dist/server.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-JDXX5XN5.js +0 -1
- package/dist/chunk-XNICYGGP.js +0 -1
- /package/dist/{chunk-B6TDAH7X.js.LEGAL.txt → chunk-JLKODCRG.js.LEGAL.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as Ge}from"./chunk-XLGNBPGF.js";import{a as ee}from"./chunk-EQUVI5QU.js";import{D as Z,F as Ye,c as Ve,e as Y,j as He,u as ze,v as Qe,x as Be,z as Je}from"./chunk-MYG5MAKQ.js";import{a as Ue,b as xe,c as De}from"./chunk-S2S4ROGY.js";import{b as de}from"./chunk-Y55OBV7D.js";import{i as pe}from"./chunk-MOIVJERE.js";import{K as J}from"./chunk-ME6QTD5Y.js";import{A as le,B as X,C as B,E as Te}from"./chunk-3532HSBP.js";import{x as Ce}from"./chunk-67WFVDTV.js";import{b as Me}from"./chunk-7JJGSLXD.js";import{a as l}from"./chunk-UGATOG2T.js";import{h as ce}from"./chunk-LFR2LWYC.js";import{a as Le}from"./chunk-5MRSFLQA.js";import{b as a}from"./chunk-W22ESUYY.js";import{a as Ee}from"./chunk-DSPLGTQI.js";var E=J.options,ft=a.discriminatedUnion("operation",[E[1].omit({customerToken:!0}),E[2].omit({customerToken:!0}),E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0}),E[8].omit({customerToken:!0}),He.omit({customerToken:!0})]),Se=a.strictObject({receiptId:a.uuid(),operationId:a.uuid()}),bt=a.discriminatedUnion("operation",[a.strictObject({operation:a.literal("find_purchase")}),a.strictObject({operation:a.literal("recover_start"),intent:a.enum(["lookup","resume","start"]),start:a.strictObject({requestId:E[0].shape.requestId,funnelId:E[0].shape.funnelId,locale:E[0].shape.locale,parameters:E[0].shape.parameters})}),a.strictObject({operation:a.literal("recover_run"),runId:a.uuid(),funnelId:a.uuid()}),a.strictObject({operation:a.literal("recover_purchase"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,includePaywallVersion:a.literal(!0).optional()}),a.strictObject({operation:a.literal("terminate_checkout"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,intent:a.literal("expire_unconfirmed_quote").optional()}),a.strictObject({operation:a.literal("settle_command"),runId:a.uuid(),funnelId:a.uuid(),requestId:a.uuid(),command:a.discriminatedUnion("operation",[E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0})]).optional()}).refine(u=>!u.command||u.requestId===u.command.requestId),a.strictObject({operation:a.literal("run_command"),runId:a.uuid(),funnelId:a.uuid(),command:ft})]),me=a.strictObject({runId:a.uuid(),funnelId:a.uuid(),versionId:a.uuid(),startRequestId:a.uuid(),runExpiresAt:a.iso.datetime({offset:!0}),status:Y.shape.run.shape.status}),G={scope:ce,customerId:a.uuid()},Ke=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("unknown"),target:a.null(),view:a.null(),access:a.null()}),a.strictObject({...G,outcome:a.literal("resolved"),target:me,view:Y.shape.run.nullable(),access:a.discriminatedUnion("type",[a.strictObject({type:a.literal("customer")}),a.strictObject({type:a.literal("operation_only"),cause:a.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((u,m)=>{u.outcome==="resolved"&&(u.access.type==="customer"!=(u.view!==null)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),$e=a.strictObject({...G,target:me,view:Y.shape.run.nullable(),settlement:a.strictObject({requestId:a.uuid(),state:a.enum(["pending","unknown","settled"]),acceptance:a.enum(["accepted","not_accepted","unknown"]),receiptPhase:a.enum(["accepted","processing","done"]).nullable(),basis:a.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:a.uuid().nullable(),operationId:a.uuid().nullable()}),purchase:Y.shape.purchase.unwrap().nullable()}).superRefine((u,m)=>{let h=u.settlement;(h.acceptance==="accepted"!=(h.receiptPhase!==null)||h.acceptance==="accepted"&&h.basis!=="receipt"||h.acceptance==="unknown"&&(h.state!=="unknown"||h.basis!=="none")||h.acceptance!=="accepted"&&(h.operationId!==null||h.receiptId!==null)||h.acceptance==="not_accepted"&&(h.state!=="settled"||!["run_terminal","position_advanced"].includes(h.basis))||u.purchase&&(u.purchase.receiptId!==h.receiptId||u.purchase.operation&&u.purchase.operation.operationId!==h.operationId||u.purchase.quote&&u.purchase.quote.operationId!==h.operationId)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Original command settlement binding differs"})}),We=a.strictObject({...G,target:me,purchase:Y.shape.purchase.unwrap(),paywallVersionId:a.uuid().optional()}).superRefine((u,m)=>{(!u.purchase.operation||typeof u.purchase.canReselect!="boolean"||u.purchase.quote&&u.purchase.quote.operationId!==u.purchase.operation.operationId)&&m.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),Xe=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("none")}),a.strictObject({...G,outcome:a.literal("blocked")}),a.strictObject({...G,outcome:a.literal("found"),target:me,start:a.strictObject({locale:E[0].shape.locale,parameters:E[0].shape.parameters}),purchase:Se})]);var ht=J.options[0].refine(u=>!u.customer&&!u.customerData),wt=a.strictObject({receiptId:a.uuid(),operationId:a.uuid(),terminal:a.enum(["complete","native"]).nullable()}),Ze=a.strictObject({schemaVersion:a.literal(1),baseUrl:a.url(),scope:ce,customerId:a.uuid(),sessionId:a.uuid(),start:ht,allowed:a.array(a.enum(["merchant","record_only","indiana","native"])),run:a.strictObject({id:a.uuid(),versionId:a.uuid(),status:Ve.shape.status,revision:a.number().int().nonnegative(),runExpiresAt:a.iso.datetime({offset:!0}).optional()}).optional(),purchases:a.array(wt).max(100),operationCommand:a.strictObject({operationId:a.uuid(),intent:a.literal("confirm")}).optional(),journal:a.strictObject({revision:a.number().int().nonnegative(),entry:ze.nullable()})});function et(u){return Be({...u,namespace:"purchases",identity:[u.scope.projectId,u.scope.environment,u.customerId]})}function tt(u){let m=new URL(u.baseUrl??Le).href,h=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function S(){u.assertCurrent();try{let C=await u.storage.read();if(u.assertCurrent(),!Number.isSafeInteger(C.revision)||C.revision<0)throw h();let c=C.entry===null?null:Ze.parse(C.entry);if(c&&(c.baseUrl!==m||c.customerId!==u.customerId||c.scope.projectId!==u.scope.projectId||c.scope.environment!==u.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(c?.journal.entry&&(c.journal.entry.scope.projectId!==c.scope.projectId||c.journal.entry.scope.environment!==c.scope.environment||c.journal.entry.funnelId!==c.start.funnelId||c.journal.entry.runId!==c.run?.id||c.journal.entry.versionId!==c.run?.versionId)||c?.operationCommand&&!c.purchases.some(k=>k.operationId===c.operationCommand?.operationId))throw h();return{revision:C.revision,entry:c}}catch(C){throw C instanceof l?C:h()}}async function te(C){for(let c=0;c<8;c++){let k=await S(),O=C(structuredClone(k.entry));if(JSON.stringify(O)===JSON.stringify(k.entry))return O;O&&Ze.parse(O),u.assertCurrent();let U;try{U=await u.storage.write(k.revision,O)}catch{throw h()}if(u.assertCurrent(),U!==null){if(!Number.isSafeInteger(U)||U<=k.revision)throw h();return O}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:S,update:te,baseUrl:m}}var It=5*6e4,yt=2e3,gt=250;function Pt(u,m){let h=u.purchases.find(S=>S.type==="checkout");if(!u.actions.includes("continue_checkout")||h?.type!=="checkout"||m!==void 0&&h.operationId!==m)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return h.checkoutUrl}function fe(u){return!u||u.operation==="close"||u.operation==="back"||u.operation==="shown"||u.operation==="submit"&&u.input.type==="screen"}var nt=()=>({revision:0,entry:null});function Zt(u){let m={...u,scope:{...u.scope},executionPolicy:structuredClone(u.executionPolicy)},h=m.session.snapshot();if(!h)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:S,sessionId:te}=h,C=!1,c=null,k,O,U=null,A=!1,x,ne,re,q={mode:"idle",status:"idle",actions:["start"],purchases:[]},v=new Map,be=new Map,D=new Map,he=new AbortController,oe=new Set,K=Me(m),ae=Ge(K.request);function $(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function I(){if(C||m.session.snapshot()?.customerId!==S)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=tt({...m,customerId:S,assertCurrent:I,storage:m.storage??et({baseUrl:m.baseUrl,scope:m.scope,customerId:S})}),rt,_e=()=>rt??=import("./funnel-paywall-copies-LPOTYSTS.js").then(({createPaywallCopies:e})=>e({baseUrl:m.baseUrl,scope:m.scope,customerId:S})),ot={read:async e=>(await _e()).read(e),write:async(e,t)=>(await _e()).write(e,t)},at=m.session.subscribeIdentity(qe);function qe(){C||(C=!0,clearTimeout(re),he.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),at(),c?.reset(),c=null,U=null,K.dispose(),oe.clear(),v.clear(),D.clear())}function R(e){I();let t=JSON.stringify(e)!==JSON.stringify(q);q=e,clearTimeout(re),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(re=setTimeout(()=>{Q().catch(()=>{})},5e3)),t&&Ee(m.onRecovery,structuredClone(e));for(let n of t?oe:[]){if(C)break;Ee(n,structuredClone(e))}return structuredClone(e)}function g(e){if(I(),!e||e.start.requestId!==O)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function Oe(e){return!e.run&&!b(e).length&&!e.journal.entry&&!e.operationCommand}function we(e){let t=e.journal.entry;return!b(e).length&&!e.operationCommand&&fe(t?.command)&&fe(t?.closeCommand)}function z(e){return!!e.run&&we(e)}function b(e){let t=[...e.purchases],n=e.journal.entry?.purchase;return n&&!t.some(o=>o.operationId===n.operationId)&&t.push({receiptId:n.receiptId,operationId:n.operationId,terminal:null}),t}function j(e){let t=b(e),n=A&&t.length>0&&t.every(o=>o.terminal==="native"&&H(v.get(o.operationId))==="native")&&t.some(o=>{let r=v.get(o.operationId);return!r||D.get(o.operationId)!==!0?!1:B(r)?!0:r.status==="cancelled"&&r.confirmedAt===null&&!r.quoteFinalized&&!r.merchantExecution&&!r.problem&&!!r.quote&&Date.parse(r.quote.expiresAt)<=Date.now()});return e.run&&(n||!["running","waiting"].includes(e.run.status))&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&t.every(o=>o.terminal!==null)}function N(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=b(e).map(f=>{let _=v.get(f.operationId),P=de({quote:_?.quote??null,operation:_??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:D.get(f.operationId)===!0});return f.terminal&&(P.type==="checkout"||P.type==="recover"||P.type==="cancel")?{type:f.terminal,operationId:f.operationId}:P}),r=o.filter(f=>!["complete","native"].includes(f.type)),i=r[0],s=r.length===1&&i?.operationId?v.get(i.operationId):void 0;if(s&&(i?.type==="checkout"||i?.type==="cancel"))try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote)}catch(f){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:$(f)}}let d;if(t==="operation"&&!n&&i?.type==="cancel"&&s?.quote&&!s.problem&&!s.confirmedAt)try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote),Date.parse(s.quote.expiresAt)>Date.now()&&(d={operationId:s.operationId,quote:s.quote})}catch{}let p=o.length>0&&r.length===0,y=j(e)||t==="operation"&&p&&!n&&!e.operationCommand?"complete":i?.type==="checkout"?"checkout":i?.type==="fulfillment"?"fulfillment":i?.type==="recording"?"recording":n||e.operationCommand||i&&i.type!=="cancel"||t==="operation"&&!d?"waiting_result":"ready";return{mode:t,status:y,purchases:o,...d?{confirmation:structuredClone(d)}:{},actions:["refresh",...j(e)||z(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:d?["confirm"]:[],...r.length===1&&i?.type==="checkout"?["continue_checkout"]:[]]}}function H(e){let t=de({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&D.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function Ie(e){if(!e.operation)return;let t=le.parse({...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}});if(t.merchantExecution&&t.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let n=pe(v.get(t.operationId)??null,t);v.set(t.operationId,n),n===t&&D.set(t.operationId,e.canReselect===!0)}async function it(e,t,n){I();for(let i of[e.purchase,e.run.paywall])i&&Ie(i);let o=!1,r=await w.update(i=>{if(i&&i.start.requestId!==t)return o=!0,i;if(g(i),i.run&&(i.run.id!==e.run.id||i.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let s=b(i);for(let d of[e.purchase,e.run.paywall]){let p=d?.operation?.operationId??d?.quote?.operationId;if(!d||!p)continue;let y=s.find(_=>_.operationId===p);if(y&&y.receiptId!==d.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let f=H(v.get(p));y?y.terminal??=f:s.push({receiptId:d.receiptId,operationId:p,terminal:f})}return{...i,purchases:s,run:i.run&&(i.run.revision>e.run.revision||!["running","waiting"].includes(i.run.status)&&["running","waiting"].includes(e.run.status))?i.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});if(o){n();return}g(r),r.run&&!["running","waiting"].includes(r.run.status)&&b(r).some(i=>!i.terminal)&&(r=await L(r,!r.journal.entry?.command&&!r.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(i=>!!i)))),g(r),R(N(r,"run"))}function st(e){let t;return()=>{t||C||(t=setTimeout(()=>{let n=e(),o=n.view;if(C||!o||!["running","waiting"].includes(o.status)||n.pendingCommands?.some(r=>r.operation==="close")){t=void 0;return}t=n.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:o.nodeId,visit:o.visit,revision:o.revision}).catch(()=>{}).finally(()=>{t=void 0})}))}}function ut(e,t){let n=null,o=r=>!!r&&r.start.requestId!==e;return{async read(){let{entry:r}=await w.read();return I(),o(r)?(t(),structuredClone(n??=nt())):(g(r),structuredClone(r.journal))},async write(r,i){let s=null;return await w.update(d=>{if(o(d)){if(t(),!fe(i?.command)||!fe(i?.closeCommand))throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; its Run can only be dismissed");let p=n??=nt();return s=null,p.revision!==r||(s=r+1,n={revision:s,entry:i}),d}if(g(d),d.operationCommand&&i?.command&&i.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return s=null,d.journal.revision!==r?d:(s=r+1,{...d,journal:{revision:s,entry:i}})}),s}}}async function L(e,t=!1,n=new Set){g(e);let o=b(e);for(let i of o){if(i.terminal)continue;let s=n.has(i.operationId)?v.get(i.operationId):void 0;if(s??=await V(e,i),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(s.merchantExecution&&s.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&de({quote:s.quote??null,operation:s,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let d=B(s)?await ae.update({operationId:i.operationId,intent:"cancel"}):await ae.attach({operationId:i.operationId,intent:"cancel"});if(s=le.parse(d.operation),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");s=await V(e,i)}v.set(i.operationId,pe(v.get(i.operationId)??null,s))}let r=await w.update(i=>{g(i);let s=i.operationCommand&&v.get(i.operationCommand.operationId);return{...i,...s&&(s.confirmedAt||s.merchantExecution||!Te(s))?{operationCommand:void 0}:{},purchases:b(i).map(d=>({...d,terminal:d.terminal??H(v.get(d.operationId))}))}});return g(r),r}async function W(e){I();let t=await K.request("funnels",e);return I(),t}async function ct(e){try{return await W(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return W({...e,intent:"resume"})}}async function lt(){let e=ee(Xe,await W({operation:"find_purchase"}));if(e.customerId!==S||e.scope.projectId!==m.scope.projectId||e.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(e.outcome!=="found")return e.outcome;let{target:t,purchase:n}=e;return await w.update(o=>o&&!j(o)&&!z(o)?o:{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...m.executionPolicy.allowed],run:{id:t.runId,versionId:t.versionId,status:t.status,revision:0,runExpiresAt:t.runExpiresAt},purchases:[{...n,terminal:null}],journal:{revision:0,entry:null}}),"found"}let ie;function ye(e){let t=ie;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<It))return t.job;let n={at:Date.now(),job:lt().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw ie===n&&(ie=void 0),o})};return ie=n,n.job}async function V(e,t,n="recover_purchase",o=!1){let r={runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId}},i=n==="recover_purchase"?{...r,operation:n,...o?{includePaywallVersion:!0}:{}}:{...r,operation:"terminate_checkout",...n==="expire_unconfirmed_quote"?{intent:n}:{}},s=ee(We,await W(i));if(ge(e,s),s.purchase.receiptId!==t.receiptId||s.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return Ie(s.purchase),o&&s.paywallVersionId&&be.set(t.operationId,s.paywallVersionId),v.get(t.operationId)}async function Fe(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=ee($e,await W({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(ge(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&Ie(n.purchase);let o=await w.update(r=>{g(r);let i=b(r),{receiptId:s,operationId:d}=n.settlement;if(s&&d){let y=i.find(f=>f.operationId===d);if(y&&y.receiptId!==s)throw new l("INVALID_RESPONSE","Original Receipt changed");y||i.push({receiptId:s,operationId:d,terminal:H(v.get(d))})}let p=n.settlement.state==="settled"?Qe(r.journal.entry,t.requestId):r.journal.entry;return{...r,purchases:i,journal:p===r.journal.entry?r.journal:{revision:r.journal.revision+1,entry:p}}});g(o),e=o}return e}function ge(e,t){if(t.customerId!==S||t.scope.projectId!==m.scope.projectId||t.scope.environment!==m.scope.environment||t.target.funnelId!==e.start.funnelId||t.target.startRequestId!==e.start.requestId||e.run&&(t.target.runId!==e.run.id||t.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function Pe(e,t){if(g(e),e.run&&(e=await Fe(e)),!b(e).length&&j(e))return R(N(e,"operation"));if(we(e)){let r=e.start.requestId;if(!await w.update(s=>s&&s.start.requestId===r&&we(s)?null:s))return c?.reset(),c=null,A=!1,R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}if(!b(e).length)return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(t)});A=!0;let n=b(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(r=>r.terminal==="native"))for(let r of n)H(v.get(r.operationId))!=="native"&&await V(e,r);let o=await dt(await L(e));return R(N(o,"operation"))}async function dt(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return e;let t=b(e).filter(i=>!i.terminal),n=t[0];if(!n||t.length!==1)return e;let o=v.get(n.operationId),r=o?.quote;if(!o||B(o)||!r||X(r)||r.provider!=="merchant"||o.status!=="pending"||o.confirmedAt!==null||o.quoteFinalized||o.checkoutUrl||o.nativePurchase||o.merchantExecution||o.problem||Date.parse(r.expiresAt)>Date.now())return e;try{await V(e,n,"expire_unconfirmed_quote")}catch{return I(),e}return L(e,!1,new Set([n.operationId]))}async function se(e,t=!1,n=!0,o=!1){if(O=e.start.requestId,U=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!c){let r=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:t?"start":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},i;try{i=await ct(r)}catch(P){if(!e.run&&P instanceof l&&(P.status===void 0||P.status>=500))return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:$(P)});throw P}let s=ee(Ke,i);if(s.customerId!==S||s.scope.projectId!==m.scope.projectId||s.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(s.outcome==="unknown"){if(!t&&Oe(e)){let P=e.start.requestId;if(!await w.update(M=>M&&M.start.requestId===P&&Oe(M)?null:M))return R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}})}ge(e,s);let d=await w.update(P=>(g(P),{...P,run:{id:s.target.runId,versionId:s.target.versionId,status:s.target.status,revision:s.view?.revision??P.run?.revision??0,runExpiresAt:s.target.runExpiresAt}}));if(g(d),e=d,s.access.type==="operation_only")return Pe(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await Fe(e);let p=s.view;if(p.locale!==e.start.locale||!Je(p.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");let y=e.start.requestId,f=st(()=>_),_=Ye({...m,customerRun:{runId:s.target.runId,customerId:S,startRequestId:y},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(P=>m.executionPolicy.allowed.includes(P))},funnelCommandStorage:ut(y,f),onAcceptedResponse:P=>it(P,y,f)},{scope:s.scope,run:p});c=_}try{let r=o&&k?.controller===c?performance.now()-k.at:1/0;(r>=yt||c.pendingCommands?.length||(c.viewAgeMs??0)<r)&&(k=void 0,await c.get(),k={controller:c,at:performance.now()}),c.view?.pendingRequest?.requestId===e.start.requestId&&!c.pendingCommands?.length&&await c.resume(c.view.pendingRequest.requestId);for(let s of c.pendingCommands??[])s.operation!=="close"&&await c.settle?.(s.requestId);c.pendingCommands?.length&&await c.retry(),I();let i=(await w.read()).entry;return g(i),R(N(i,"run"))}catch(r){if(I(),n&&r instanceof l&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED")){c.reset(),c=null;let i=(await w.read()).entry;return g(i),se(i,!1,!1,!1)}throw r}}function T(e,t="read",n){if(I(),x)return t==="read"||t===ne?x:x.then(()=>T(e,t,n),()=>T(e,t,n));clearTimeout(re);let o=e().catch(r=>{throw!C&&!n?.(r)&&R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:q.purchases,error:$(r)}),r});return x=o,ne=t,o.then(()=>{x===o&&(x=void 0,ne=void 0)},()=>{x===o&&(x=void 0,ne=void 0)}),o}function pt(e){return e instanceof l&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT"||e.status===409||e.status===429||e.status!==void 0&&e.status>=500)}function Q(e){let t=e?.reuseRecentRead===!0,n=async o=>{let{entry:r}=await w.read();if(!r||j(r)){if(await ye(!1)==="blocked")return ke();({entry:r}=await w.read())}return r?(O&&r.start.requestId!==O&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A&&O===r.start.requestId?Pe(r,q.error):se(r,!1,!0,o)):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})};return T(async()=>{try{return await n(t)}catch(o){if(C||!pt(o))throw o;return I(),c?.reset(),c=null,k=void 0,o.status===409?A=!1:await new Promise(r=>setTimeout(r,gt)),I(),n(!1)}})}function ke(){return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function Ae(){let e=await Q();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:T(async()=>{let t=(await w.read()).entry;if(g(t),!A){if(!c?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let p=c.view.paywall.operation;if(p?.confirmedAt||p?.merchantExecution||p&&!(B(p)?["prepared","quoted"].includes(p.status):p.status==="pending"))return R(N(t,"run"));if(c.pendingCommands?.length)await c.retry();else{let f=c.view;await c.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:f.nodeId,visit:f.visit,revision:f.revision,input:{type:"paywall_confirm",operationId:f.paywall.quote.operationId,...f.paywall.quote.merchantTerms?{merchantConfirmation:Ce(f.paywall.quote.merchantTerms)}:{}}})}let y=(await w.read()).entry;return g(y),R(N(y,"run"))}let n=t.operationCommand?.operationId??q.confirmation?.operationId,o=n&&v.get(n);if(!n||!o||t.journal.entry?.command||t.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");Z({allowed:t.allowed.filter(p=>m.executionPolicy.allowed.includes(p))},o.quote),await w.update(p=>{if(g(p),p.journal.entry?.command||p.journal.entry?.closeCommand||p.operationCommand&&p.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...p,operationCommand:{operationId:n,intent:"confirm"}}});let r={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:Ce(o.quote.merchantTerms)}:{}},i=B(o)?await ae.update(r):await ae.attach(r),s=le.parse(i.operation);if(I(),i.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");v.set(n,pe(o,s));let d=(await w.read()).entry;return g(d),R(N(await L(d,!1,new Set([n])),"operation"))},"confirm")}function mt(e){let t=e?.quote;return t&&X(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Ne(){if(q.mode!=="operation"||q.status==="blocked")return null;let e=q.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?mt(v.get(t)):null}async function je(){I();let{entry:e}=await w.read();return e?j(e)||z(e)?"finished":"pending":"none"}return{get controller(){return c},get recovery(){return structuredClone(q)},get attempt(){return I(),structuredClone(U)},get identitySignal(){return he.signal},get customerId(){return S},retained:je,async pendingFunnel(){I();let{entry:e}=await w.read();return e&&!j(e)&&!z(e)?e.start.funnelId:null},get paywallCopies(){return ot},async findPurchase(){let e=await je();if(e==="pending")return e;let t=await ye(!0);return I(),t==="none"?e:t},async readPaywall(e){I();let t=Ue(e),[n,{readPaywallContent:o},{validateResourceCheck:r}]=await Promise.all([xe(K.request,"resolvePaywall"),import("./paywall-content-S6A2WLIX.js"),import("./check-response-XGOTG3KL.js")]);I();let i=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),s=await De(K.request,n,i);r(i,s.paywall.check,s.scope);let d=await o(m,s.paywall);if(I(),t.paywallVersionId?d.id!==t.paywallVersionId:d.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return d},get canRestoreUpgradePaywall(){return Ne()!==null},recoverUpgradePaywall(){let e=Ne();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(q.mode!=="operation"||q.status==="blocked")return null;let{entry:n}=await w.read();if(!n?.run)return null;g(n);let o=b(n),r=o.filter(F=>!F.terminal),i=o.filter(F=>F.terminal==="complete"),s=r.length===1?r[0]:r.length?void 0:i.find(F=>e&&e.runId===n.run?.id&&F.receiptId===e.receiptId)??(i.length===1?i[0]:void 0);if(!s||t&&s.operationId!==t)return null;let d=e?.runId===n.run.id&&e.receiptId===s.receiptId?e.view:void 0,p;try{p=await V(n,s,"recover_purchase",!0)}catch(F){if(!(F instanceof l&&F.status===400&&F.code==="INVALID_REQUEST"))throw F;if(!d)return null;p=await V(n,s)}let y=p.quote;if(!y||X(y)&&(y.timing!=="immediate"||y.execution.provider!=="merchant")||!(p.confirmedAt||p.merchantExecution||p.checkoutUrl||H(p)==="complete"))return null;H(p)!=="complete"&&Z({allowed:n.allowed.filter(F=>m.executionPolicy.allowed.includes(F))},y);let f=be.get(s.operationId),_=n.start.parameters?.commerce,P=n.start.locale??"en",ue=d;if(f){if(typeof _!="object"||!_||!("provider"in _)||typeof _.provider!="string"||!("currency"in _)||typeof _.currency!="string")return null;ue=await this.readPaywall({paywallVersionId:f,locale:P,commerce:{provider:_.provider,currency:_.currency,...X(y)?{intent:"subscription_change"}:{}}})}if(!ue)return null;I();let M=ue,ve=!1,Re=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:he.signal,view:M,quote:y,locale:P,get operation(){return p},get canReselect(){return D.get(s.operationId)===!0},async refresh(){return M},preview:Re,confirm:Re,cancel:Re,async read(){if(ve)throw new DOMException("Purchase view closed","AbortError");p=await V(n,s);let F=await L(n,!1,new Set([s.operationId]));return ve||R(N(F,"operation")),structuredClone(p)},destroy(){ve=!0}}},start(e){let t=J.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(t.operation!=="start"||t.customer||t.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return T(async()=>{let n=(await w.read()).entry;if((!n||j(n)||z(n))&&await ye(!0)==="blocked")return ke();let o=await w.update(r=>{if(r&&!j(r)&&!(z(r)&&r.start.requestId!==t.requestId)){if(r.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return r}return{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:t,allowed:[...m.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return O!==o.start.requestId&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A?Pe(o,q.error):se(o,!0,!0,!0)},`start:${t.funnelId}`)},refresh:Q,confirm:Ae,retry:()=>A?Ae():T(async()=>{let{entry:e}=await w.read();return e?se(e,!0):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return c?.view?T(async()=>{if(!c?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(c.pendingCommands?.find(n=>n.operation==="close"))await c.retry();else if(["running","waiting"].includes(c.view.status)){let n=c.view;await c.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await w.read()).entry;return t&&t.start.requestId!==O?R({mode:"idle",status:"idle",actions:["start"],purchases:[]}):(g(t),R(N(t,"run")))},"close"):Q()},async continueCheckout(e,t){let n=t?await T(async()=>{let{entry:o}=await w.read();if(g(o),!o.run||!b(o).some(i=>i.operationId===t&&!i.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let r=await L(o);return R(N(r,A?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await Q();I(),await e(Pt(n,t))},async terminateCheckout(e){let t=n=>n.actions.includes("continue_checkout")&&n.purchases.some(o=>o.type==="checkout"&&o.operationId===e);if(!t(q)&&!t(await Q()))throw new l("PURCHASE_PENDING","The original Checkout has changed");return T(async()=>{let{entry:n}=await w.read();g(n);let o=b(n).find(i=>i.operationId===e&&!i.terminal);if(!o||!n.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await V(n,o,"terminate_checkout");let r=await L(n,!1,new Set([e]));return R(N(r,A?"operation":"run"))},`terminate:${e}`,n=>n instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(n.code))},subscribe(e){return oe.add(e),()=>{oe.delete(e)}},destroy:qe}}export{et as a,Pt as b,Zt as c};
|
|
1
|
+
import{b as Ge}from"./chunk-XLGNBPGF.js";import{a as ee}from"./chunk-EQUVI5QU.js";import{D as Z,F as Ye,c as Ve,e as Y,j as He,u as ze,v as Qe,x as Be,z as Je}from"./chunk-BQFIJCBA.js";import{a as Ue,b as xe,c as De}from"./chunk-S2S4ROGY.js";import{b as de}from"./chunk-Y55OBV7D.js";import{i as pe}from"./chunk-MOIVJERE.js";import{K as J}from"./chunk-ME6QTD5Y.js";import{A as le,B as X,C as B,E as Te}from"./chunk-3532HSBP.js";import{x as Ce}from"./chunk-67WFVDTV.js";import{b as Me}from"./chunk-55B6CYG6.js";import{a as l}from"./chunk-UGATOG2T.js";import{h as ce}from"./chunk-LFR2LWYC.js";import{a as Le}from"./chunk-5MRSFLQA.js";import{b as a}from"./chunk-W22ESUYY.js";import{a as Ee}from"./chunk-DSPLGTQI.js";var E=J.options,ft=a.discriminatedUnion("operation",[E[1].omit({customerToken:!0}),E[2].omit({customerToken:!0}),E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0}),E[8].omit({customerToken:!0}),He.omit({customerToken:!0})]),Se=a.strictObject({receiptId:a.uuid(),operationId:a.uuid()}),bt=a.discriminatedUnion("operation",[a.strictObject({operation:a.literal("find_purchase")}),a.strictObject({operation:a.literal("recover_start"),intent:a.enum(["lookup","resume","start"]),start:a.strictObject({requestId:E[0].shape.requestId,funnelId:E[0].shape.funnelId,locale:E[0].shape.locale,parameters:E[0].shape.parameters})}),a.strictObject({operation:a.literal("recover_run"),runId:a.uuid(),funnelId:a.uuid()}),a.strictObject({operation:a.literal("recover_purchase"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,includePaywallVersion:a.literal(!0).optional()}),a.strictObject({operation:a.literal("terminate_checkout"),runId:a.uuid(),funnelId:a.uuid(),purchase:Se,intent:a.literal("expire_unconfirmed_quote").optional()}),a.strictObject({operation:a.literal("settle_command"),runId:a.uuid(),funnelId:a.uuid(),requestId:a.uuid(),command:a.discriminatedUnion("operation",[E[3].omit({customerToken:!0}),E[4].omit({customerToken:!0}),E[5].omit({customerToken:!0}),E[6].omit({customerToken:!0}),E[7].omit({customerToken:!0})]).optional()}).refine(u=>!u.command||u.requestId===u.command.requestId),a.strictObject({operation:a.literal("run_command"),runId:a.uuid(),funnelId:a.uuid(),command:ft})]),me=a.strictObject({runId:a.uuid(),funnelId:a.uuid(),versionId:a.uuid(),startRequestId:a.uuid(),runExpiresAt:a.iso.datetime({offset:!0}),status:Y.shape.run.shape.status}),G={scope:ce,customerId:a.uuid()},Ke=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("unknown"),target:a.null(),view:a.null(),access:a.null()}),a.strictObject({...G,outcome:a.literal("resolved"),target:me,view:Y.shape.run.nullable(),access:a.discriminatedUnion("type",[a.strictObject({type:a.literal("customer")}),a.strictObject({type:a.literal("operation_only"),cause:a.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((u,m)=>{u.outcome==="resolved"&&(u.access.type==="customer"!=(u.view!==null)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),$e=a.strictObject({...G,target:me,view:Y.shape.run.nullable(),settlement:a.strictObject({requestId:a.uuid(),state:a.enum(["pending","unknown","settled"]),acceptance:a.enum(["accepted","not_accepted","unknown"]),receiptPhase:a.enum(["accepted","processing","done"]).nullable(),basis:a.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:a.uuid().nullable(),operationId:a.uuid().nullable()}),purchase:Y.shape.purchase.unwrap().nullable()}).superRefine((u,m)=>{let h=u.settlement;(h.acceptance==="accepted"!=(h.receiptPhase!==null)||h.acceptance==="accepted"&&h.basis!=="receipt"||h.acceptance==="unknown"&&(h.state!=="unknown"||h.basis!=="none")||h.acceptance!=="accepted"&&(h.operationId!==null||h.receiptId!==null)||h.acceptance==="not_accepted"&&(h.state!=="settled"||!["run_terminal","position_advanced"].includes(h.basis))||u.purchase&&(u.purchase.receiptId!==h.receiptId||u.purchase.operation&&u.purchase.operation.operationId!==h.operationId||u.purchase.quote&&u.purchase.quote.operationId!==h.operationId)||u.view&&(u.view.id!==u.target.runId||u.view.source.id!==u.target.funnelId||u.view.source.versionId!==u.target.versionId||u.view.status!==u.target.status||u.view.runExpiresAt!==u.target.runExpiresAt||u.view.credentialExpiresAt!==null))&&m.addIssue({code:"custom",message:"Original command settlement binding differs"})}),We=a.strictObject({...G,target:me,purchase:Y.shape.purchase.unwrap(),paywallVersionId:a.uuid().optional()}).superRefine((u,m)=>{(!u.purchase.operation||typeof u.purchase.canReselect!="boolean"||u.purchase.quote&&u.purchase.quote.operationId!==u.purchase.operation.operationId)&&m.addIssue({code:"custom",message:"Original purchase proof is incomplete"})}),Xe=a.discriminatedUnion("outcome",[a.strictObject({...G,outcome:a.literal("none")}),a.strictObject({...G,outcome:a.literal("blocked")}),a.strictObject({...G,outcome:a.literal("found"),target:me,start:a.strictObject({locale:E[0].shape.locale,parameters:E[0].shape.parameters}),purchase:Se})]);var ht=J.options[0].refine(u=>!u.customer&&!u.customerData),wt=a.strictObject({receiptId:a.uuid(),operationId:a.uuid(),terminal:a.enum(["complete","native"]).nullable()}),Ze=a.strictObject({schemaVersion:a.literal(1),baseUrl:a.url(),scope:ce,customerId:a.uuid(),sessionId:a.uuid(),start:ht,allowed:a.array(a.enum(["merchant","record_only","indiana","native"])),run:a.strictObject({id:a.uuid(),versionId:a.uuid(),status:Ve.shape.status,revision:a.number().int().nonnegative(),runExpiresAt:a.iso.datetime({offset:!0}).optional()}).optional(),purchases:a.array(wt).max(100),operationCommand:a.strictObject({operationId:a.uuid(),intent:a.literal("confirm")}).optional(),journal:a.strictObject({revision:a.number().int().nonnegative(),entry:ze.nullable()})});function et(u){return Be({...u,namespace:"purchases",identity:[u.scope.projectId,u.scope.environment,u.customerId]})}function tt(u){let m=new URL(u.baseUrl??Le).href,h=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function S(){u.assertCurrent();try{let C=await u.storage.read();if(u.assertCurrent(),!Number.isSafeInteger(C.revision)||C.revision<0)throw h();let c=C.entry===null?null:Ze.parse(C.entry);if(c&&(c.baseUrl!==m||c.customerId!==u.customerId||c.scope.projectId!==u.scope.projectId||c.scope.environment!==u.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(c?.journal.entry&&(c.journal.entry.scope.projectId!==c.scope.projectId||c.journal.entry.scope.environment!==c.scope.environment||c.journal.entry.funnelId!==c.start.funnelId||c.journal.entry.runId!==c.run?.id||c.journal.entry.versionId!==c.run?.versionId)||c?.operationCommand&&!c.purchases.some(k=>k.operationId===c.operationCommand?.operationId))throw h();return{revision:C.revision,entry:c}}catch(C){throw C instanceof l?C:h()}}async function te(C){for(let c=0;c<8;c++){let k=await S(),O=C(structuredClone(k.entry));if(JSON.stringify(O)===JSON.stringify(k.entry))return O;O&&Ze.parse(O),u.assertCurrent();let U;try{U=await u.storage.write(k.revision,O)}catch{throw h()}if(u.assertCurrent(),U!==null){if(!Number.isSafeInteger(U)||U<=k.revision)throw h();return O}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:S,update:te,baseUrl:m}}var It=5*6e4,yt=2e3,gt=250;function Pt(u,m){let h=u.purchases.find(S=>S.type==="checkout");if(!u.actions.includes("continue_checkout")||h?.type!=="checkout"||m!==void 0&&h.operationId!==m)throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return h.checkoutUrl}function fe(u){return!u||u.operation==="close"||u.operation==="back"||u.operation==="shown"||u.operation==="submit"&&u.input.type==="screen"}var nt=()=>({revision:0,entry:null});function Zt(u){let m={...u,scope:{...u.scope},executionPolicy:structuredClone(u.executionPolicy)},h=m.session.snapshot();if(!h)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:S,sessionId:te}=h,C=!1,c=null,k,O,U=null,A=!1,x,ne,re,q={mode:"idle",status:"idle",actions:["start"],purchases:[]},v=new Map,be=new Map,D=new Map,he=new AbortController,oe=new Set,K=Me(m),ae=Ge(K.request);function $(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function I(){if(C||m.session.snapshot()?.customerId!==S)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=tt({...m,customerId:S,assertCurrent:I,storage:m.storage??et({baseUrl:m.baseUrl,scope:m.scope,customerId:S})}),rt,_e=()=>rt??=import("./funnel-paywall-copies-LPOTYSTS.js").then(({createPaywallCopies:e})=>e({baseUrl:m.baseUrl,scope:m.scope,customerId:S})),ot={read:async e=>(await _e()).read(e),write:async(e,t)=>(await _e()).write(e,t)},at=m.session.subscribeIdentity(qe);function qe(){C||(C=!0,clearTimeout(re),he.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),at(),c?.reset(),c=null,U=null,K.dispose(),oe.clear(),v.clear(),D.clear())}function R(e){I();let t=JSON.stringify(e)!==JSON.stringify(q);q=e,clearTimeout(re),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(re=setTimeout(()=>{Q().catch(()=>{})},5e3)),t&&Ee(m.onRecovery,structuredClone(e));for(let n of t?oe:[]){if(C)break;Ee(n,structuredClone(e))}return structuredClone(e)}function g(e){if(I(),!e||e.start.requestId!==O)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function Oe(e){return!e.run&&!b(e).length&&!e.journal.entry&&!e.operationCommand}function we(e){let t=e.journal.entry;return!b(e).length&&!e.operationCommand&&fe(t?.command)&&fe(t?.closeCommand)}function z(e){return!!e.run&&we(e)}function b(e){let t=[...e.purchases],n=e.journal.entry?.purchase;return n&&!t.some(o=>o.operationId===n.operationId)&&t.push({receiptId:n.receiptId,operationId:n.operationId,terminal:null}),t}function j(e){let t=b(e),n=A&&t.length>0&&t.every(o=>o.terminal==="native"&&H(v.get(o.operationId))==="native")&&t.some(o=>{let r=v.get(o.operationId);return!r||D.get(o.operationId)!==!0?!1:B(r)?!0:r.status==="cancelled"&&r.confirmedAt===null&&!r.quoteFinalized&&!r.merchantExecution&&!r.problem&&!!r.quote&&Date.parse(r.quote.expiresAt)<=Date.now()});return e.run&&(n||!["running","waiting"].includes(e.run.status))&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&t.every(o=>o.terminal!==null)}function N(e,t){let n=e.journal.entry?.command??e.journal.entry?.closeCommand,o=b(e).map(f=>{let _=v.get(f.operationId),P=de({quote:_?.quote??null,operation:_??null,requestId:n?.requestId??null,pending:!1,destroyed:!1,canReselect:D.get(f.operationId)===!0});return f.terminal&&(P.type==="checkout"||P.type==="recover"||P.type==="cancel")?{type:f.terminal,operationId:f.operationId}:P}),r=o.filter(f=>!["complete","native"].includes(f.type)),i=r[0],s=r.length===1&&i?.operationId?v.get(i.operationId):void 0;if(s&&(i?.type==="checkout"||i?.type==="cancel"))try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote)}catch(f){return{mode:t,status:"blocked",actions:["refresh",...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:o,error:$(f)}}let d;if(t==="operation"&&!n&&i?.type==="cancel"&&s?.quote&&!s.problem&&!s.confirmedAt)try{Z({allowed:e.allowed.filter(f=>m.executionPolicy.allowed.includes(f))},s.quote),Date.parse(s.quote.expiresAt)>Date.now()&&(d={operationId:s.operationId,quote:s.quote})}catch{}let p=o.length>0&&r.length===0,y=j(e)||t==="operation"&&p&&!n&&!e.operationCommand?"complete":i?.type==="checkout"?"checkout":i?.type==="fulfillment"?"fulfillment":i?.type==="recording"?"recording":n||e.operationCommand||i&&i.type!=="cancel"||t==="operation"&&!d?"waiting_result":"ready";return{mode:t,status:y,purchases:o,...d?{confirmation:structuredClone(d)}:{},actions:["refresh",...j(e)||z(e)?["start"]:[],...t==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:d?["confirm"]:[],...r.length===1&&i?.type==="checkout"?["continue_checkout"]:[]]}}function H(e){let t=de({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&D.get(e.operationId)===!0});return t.type==="complete"||t.type==="native"?t.type:null}function Ie(e){if(!e.operation)return;let t=le.parse({...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}});if(t.merchantExecution&&t.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let n=pe(v.get(t.operationId)??null,t);v.set(t.operationId,n),n===t&&D.set(t.operationId,e.canReselect===!0)}async function it(e,t,n){I();for(let i of[e.purchase,e.run.paywall])i&&Ie(i);let o=!1,r=await w.update(i=>{if(i&&i.start.requestId!==t)return o=!0,i;if(g(i),i.run&&(i.run.id!==e.run.id||i.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let s=b(i);for(let d of[e.purchase,e.run.paywall]){let p=d?.operation?.operationId??d?.quote?.operationId;if(!d||!p)continue;let y=s.find(_=>_.operationId===p);if(y&&y.receiptId!==d.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let f=H(v.get(p));y?y.terminal??=f:s.push({receiptId:d.receiptId,operationId:p,terminal:f})}return{...i,purchases:s,run:i.run&&(i.run.revision>e.run.revision||!["running","waiting"].includes(i.run.status)&&["running","waiting"].includes(e.run.status))?i.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});if(o){n();return}g(r),r.run&&!["running","waiting"].includes(r.run.status)&&b(r).some(i=>!i.terminal)&&(r=await L(r,!r.journal.entry?.command&&!r.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(i=>!!i)))),g(r),R(N(r,"run"))}function st(e){let t;return()=>{t||C||(t=setTimeout(()=>{let n=e(),o=n.view;if(C||!o||!["running","waiting"].includes(o.status)||n.pendingCommands?.some(r=>r.operation==="close")){t=void 0;return}t=n.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:o.nodeId,visit:o.visit,revision:o.revision}).catch(()=>{}).finally(()=>{t=void 0})}))}}function ut(e,t){let n=null,o=r=>!!r&&r.start.requestId!==e;return{async read(){let{entry:r}=await w.read();return I(),o(r)?(t(),structuredClone(n??=nt())):(g(r),structuredClone(r.journal))},async write(r,i){let s=null;return await w.update(d=>{if(o(d)){if(t(),!fe(i?.command)||!fe(i?.closeCommand))throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; its Run can only be dismissed");let p=n??=nt();return s=null,p.revision!==r||(s=r+1,n={revision:s,entry:i}),d}if(g(d),d.operationCommand&&i?.command&&i.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return s=null,d.journal.revision!==r?d:(s=r+1,{...d,journal:{revision:s,entry:i}})}),s}}}async function L(e,t=!1,n=new Set){g(e);let o=b(e);for(let i of o){if(i.terminal)continue;let s=n.has(i.operationId)?v.get(i.operationId):void 0;if(s??=await V(e,i),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(s.merchantExecution&&s.merchantExecution.customerId!==S)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(t&&!e.operationCommand&&de({quote:s.quote??null,operation:s,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){let d=B(s)?await ae.update({operationId:i.operationId,intent:"cancel"}):await ae.attach({operationId:i.operationId,intent:"cancel"});if(s=le.parse(d.operation),I(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");s=await V(e,i)}v.set(i.operationId,pe(v.get(i.operationId)??null,s))}let r=await w.update(i=>{g(i);let s=i.operationCommand&&v.get(i.operationCommand.operationId);return{...i,...s&&(s.confirmedAt||s.merchantExecution||!Te(s))?{operationCommand:void 0}:{},purchases:b(i).map(d=>({...d,terminal:d.terminal??H(v.get(d.operationId))}))}});return g(r),r}async function W(e){I();let t=await K.request("funnels",e);return I(),t}async function ct(e){try{return await W(e)}catch(t){if(e.operation!=="recover_start"||e.intent!=="start"||!(t instanceof l)||t.status!==400||t.code!=="INVALID_REQUEST")throw t;return W({...e,intent:"resume"})}}async function lt(){let e=ee(Xe,await W({operation:"find_purchase"}));if(e.customerId!==S||e.scope.projectId!==m.scope.projectId||e.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(e.outcome!=="found")return e.outcome;let{target:t,purchase:n}=e;return await w.update(o=>o&&!j(o)&&!z(o)?o:{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:{operation:"start",requestId:t.startRequestId,funnelId:t.funnelId,...e.start},allowed:[...m.executionPolicy.allowed],run:{id:t.runId,versionId:t.versionId,status:t.status,revision:0,runExpiresAt:t.runExpiresAt},purchases:[{...n,terminal:null}],journal:{revision:0,entry:null}}),"found"}let ie;function ye(e){let t=ie;if(t&&(!t.outcome||e&&t.outcome==="none"&&Date.now()-t.at<It))return t.job;let n={at:Date.now(),job:lt().then(o=>(n.outcome=o,n.at=Date.now(),o),o=>{throw ie===n&&(ie=void 0),o})};return ie=n,n.job}async function V(e,t,n="recover_purchase",o=!1){let r={runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:t.receiptId,operationId:t.operationId}},i=n==="recover_purchase"?{...r,operation:n,...o?{includePaywallVersion:!0}:{}}:{...r,operation:"terminate_checkout",...n==="expire_unconfirmed_quote"?{intent:n}:{}},s=ee(We,await W(i));if(ge(e,s),s.purchase.receiptId!==t.receiptId||s.purchase.operation?.operationId!==t.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return Ie(s.purchase),o&&s.paywallVersionId&&be.set(t.operationId,s.paywallVersionId),v.get(t.operationId)}async function Fe(e){for(let t of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!t)continue;let n=ee($e,await W({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:t.requestId,...t.operation==="resume"?{}:{command:t}}));if(ge(e,n),n.settlement.requestId!==t.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");n.purchase&&Ie(n.purchase);let o=await w.update(r=>{g(r);let i=b(r),{receiptId:s,operationId:d}=n.settlement;if(s&&d){let y=i.find(f=>f.operationId===d);if(y&&y.receiptId!==s)throw new l("INVALID_RESPONSE","Original Receipt changed");y||i.push({receiptId:s,operationId:d,terminal:H(v.get(d))})}let p=n.settlement.state==="settled"?Qe(r.journal.entry,t.requestId):r.journal.entry;return{...r,purchases:i,journal:p===r.journal.entry?r.journal:{revision:r.journal.revision+1,entry:p}}});g(o),e=o}return e}function ge(e,t){if(t.customerId!==S||t.scope.projectId!==m.scope.projectId||t.scope.environment!==m.scope.environment||t.target.funnelId!==e.start.funnelId||t.target.startRequestId!==e.start.requestId||e.run&&(t.target.runId!==e.run.id||t.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function Pe(e,t){if(g(e),e.run&&(e=await Fe(e)),!b(e).length&&j(e))return R(N(e,"operation"));if(we(e)){let r=e.start.requestId;if(!await w.update(s=>s&&s.start.requestId===r&&we(s)?null:s))return c?.reset(),c=null,A=!1,R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}if(!b(e).length)return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(t)});A=!0;let n=b(e);if(e.run&&["running","waiting"].includes(e.run.status)&&n.every(r=>r.terminal==="native"))for(let r of n)H(v.get(r.operationId))!=="native"&&await V(e,r);let o=await dt(await L(e));return R(N(o,"operation"))}async function dt(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return e;let t=b(e).filter(i=>!i.terminal),n=t[0];if(!n||t.length!==1)return e;let o=v.get(n.operationId),r=o?.quote;if(!o||B(o)||!r||X(r)||r.provider!=="merchant"||o.status!=="pending"||o.confirmedAt!==null||o.quoteFinalized||o.checkoutUrl||o.nativePurchase||o.merchantExecution||o.problem||Date.parse(r.expiresAt)>Date.now())return e;try{await V(e,n,"expire_unconfirmed_quote")}catch{return I(),e}return L(e,!1,new Set([n.operationId]))}async function se(e,t=!1,n=!0,o=!1){if(O=e.start.requestId,U=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!c){let r=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:t?"start":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},i;try{i=await ct(r)}catch(P){if(!e.run&&P instanceof l&&(P.status===void 0||P.status>=500))return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:$(P)});throw P}let s=ee(Ke,i);if(s.customerId!==S||s.scope.projectId!==m.scope.projectId||s.scope.environment!==m.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(s.outcome==="unknown"){if(!t&&Oe(e)){let P=e.start.requestId;if(!await w.update(M=>M&&M.start.requestId===P&&Oe(M)?null:M))return R({mode:"idle",status:"idle",actions:["start"],purchases:[]})}return R({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:q.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}})}ge(e,s);let d=await w.update(P=>(g(P),{...P,run:{id:s.target.runId,versionId:s.target.versionId,status:s.target.status,revision:s.view?.revision??P.run?.revision??0,runExpiresAt:s.target.runExpiresAt}}));if(g(d),e=d,s.access.type==="operation_only")return Pe(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await Fe(e);let p=s.view;if(p.locale!==e.start.locale||!Je(p.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");let y=e.start.requestId,f=st(()=>_),_=Ye({...m,customerRun:{runId:s.target.runId,customerId:S,startRequestId:y},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(P=>m.executionPolicy.allowed.includes(P))},funnelCommandStorage:ut(y,f),onAcceptedResponse:P=>it(P,y,f)},{scope:s.scope,run:p});c=_}try{let r=o&&k?.controller===c?performance.now()-k.at:1/0;(r>=yt||c.pendingCommands?.length||(c.viewAgeMs??0)<r)&&(k=void 0,await c.get(),k={controller:c,at:performance.now()}),c.view?.pendingRequest?.requestId===e.start.requestId&&!c.pendingCommands?.length&&await c.resume(c.view.pendingRequest.requestId);for(let s of c.pendingCommands??[])s.operation!=="close"&&await c.settle?.(s.requestId);c.pendingCommands?.length&&await c.retry(),I();let i=(await w.read()).entry;return g(i),R(N(i,"run"))}catch(r){if(I(),n&&r instanceof l&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED")){c.reset(),c=null;let i=(await w.read()).entry;return g(i),se(i,!1,!1,!1)}throw r}}function T(e,t="read",n){if(I(),x)return t==="read"||t===ne?x:x.then(()=>T(e,t,n),()=>T(e,t,n));clearTimeout(re);let o=e().catch(r=>{throw!C&&!n?.(r)&&R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:q.purchases,error:$(r)}),r});return x=o,ne=t,o.then(()=>{x===o&&(x=void 0,ne=void 0)},()=>{x===o&&(x=void 0,ne=void 0)}),o}function pt(e){return e instanceof l&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT"||e.status===409||e.status===429||e.status!==void 0&&e.status>=500)}function Q(e){let t=e?.reuseRecentRead===!0,n=async o=>{let{entry:r}=await w.read();if(!r||j(r)){if(await ye(!1)==="blocked")return ke();({entry:r}=await w.read())}return r?(O&&r.start.requestId!==O&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A&&O===r.start.requestId?Pe(r,q.error):se(r,!1,!0,o)):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})};return T(async()=>{try{return await n(t)}catch(o){if(C||!pt(o))throw o;return I(),c?.reset(),c=null,k=void 0,o.status===409?A=!1:await new Promise(r=>setTimeout(r,gt)),I(),n(!1)}})}function ke(){return R({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:$(new l("PURCHASE_PENDING","Check the outstanding purchases before starting another"))})}async function Ae(){let e=await Q();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:T(async()=>{let t=(await w.read()).entry;if(g(t),!A){if(!c?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let p=c.view.paywall.operation;if(p?.confirmedAt||p?.merchantExecution||p&&!(B(p)?["prepared","quoted"].includes(p.status):p.status==="pending"))return R(N(t,"run"));if(c.pendingCommands?.length)await c.retry();else{let f=c.view;await c.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:f.nodeId,visit:f.visit,revision:f.revision,input:{type:"paywall_confirm",operationId:f.paywall.quote.operationId,...f.paywall.quote.merchantTerms?{merchantConfirmation:Ce(f.paywall.quote.merchantTerms)}:{}}})}let y=(await w.read()).entry;return g(y),R(N(y,"run"))}let n=t.operationCommand?.operationId??q.confirmation?.operationId,o=n&&v.get(n);if(!n||!o||t.journal.entry?.command||t.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");Z({allowed:t.allowed.filter(p=>m.executionPolicy.allowed.includes(p))},o.quote),await w.update(p=>{if(g(p),p.journal.entry?.command||p.journal.entry?.closeCommand||p.operationCommand&&p.operationCommand.operationId!==n)throw new l("PURCHASE_PENDING","Another original command is pending");return{...p,operationCommand:{operationId:n,intent:"confirm"}}});let r={operationId:n,intent:"confirm",...o.quote?.merchantTerms?{merchantConfirmation:Ce(o.quote.merchantTerms)}:{}},i=B(o)?await ae.update(r):await ae.attach(r),s=le.parse(i.operation);if(I(),i.operation.operationId!==n)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");v.set(n,pe(o,s));let d=(await w.read()).entry;return g(d),R(N(await L(d,!1,new Set([n])),"operation"))},"confirm")}function mt(e){let t=e?.quote;return t&&X(t)&&t.timing==="immediate"&&t.execution.provider==="merchant"&&(e.confirmedAt||e.merchantExecution)?t:null}function Ne(){if(q.mode!=="operation"||q.status==="blocked")return null;let e=q.purchases.filter(({type:n})=>n!=="complete"&&n!=="native"),t=e.length===1&&e[0]?.operationId;return t?mt(v.get(t)):null}async function je(){I();let{entry:e}=await w.read();return e?j(e)||z(e)?"finished":"pending":"none"}return{get controller(){return c},get recovery(){return structuredClone(q)},get attempt(){return I(),structuredClone(U)},get identitySignal(){return he.signal},get customerId(){return S},retained:je,async pendingFunnel(){I();let{entry:e}=await w.read();return e&&!j(e)&&!z(e)?e.start.funnelId:null},get paywallCopies(){return ot},async findPurchase(){let e=await je();if(e==="pending")return e;let t=await ye(!0);return I(),t==="none"?e:t},async readPaywall(e){I();let t=Ue(e),[n,{readPaywallContent:o},{validateResourceCheck:r}]=await Promise.all([xe(K.request,"resolvePaywall"),import("./paywall-content-JXWPOE3Y.js"),import("./check-response-XGOTG3KL.js")]);I();let i=n.request.parse({selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale}),s=await De(K.request,n,i);r(i,s.paywall.check,s.scope);let d=await o(m,s.paywall);if(I(),t.paywallVersionId?d.id!==t.paywallVersionId:d.paywallId!==t.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");return d},get canRestoreUpgradePaywall(){return Ne()!==null},recoverUpgradePaywall(){let e=Ne();return e?this.recoverPurchasePaywall(void 0,e.operationId):Promise.resolve(null)},async recoverPurchasePaywall(e,t){if(q.mode!=="operation"||q.status==="blocked")return null;let{entry:n}=await w.read();if(!n?.run)return null;g(n);let o=b(n),r=o.filter(F=>!F.terminal),i=o.filter(F=>F.terminal==="complete"),s=r.length===1?r[0]:r.length?void 0:i.find(F=>e&&e.runId===n.run?.id&&F.receiptId===e.receiptId)??(i.length===1?i[0]:void 0);if(!s||t&&s.operationId!==t)return null;let d=e?.runId===n.run.id&&e.receiptId===s.receiptId?e.view:void 0,p;try{p=await V(n,s,"recover_purchase",!0)}catch(F){if(!(F instanceof l&&F.status===400&&F.code==="INVALID_REQUEST"))throw F;if(!d)return null;p=await V(n,s)}let y=p.quote;if(!y||X(y)&&(y.timing!=="immediate"||y.execution.provider!=="merchant")||!(p.confirmedAt||p.merchantExecution||p.checkoutUrl||H(p)==="complete"))return null;H(p)!=="complete"&&Z({allowed:n.allowed.filter(F=>m.executionPolicy.allowed.includes(F))},y);let f=be.get(s.operationId),_=n.start.parameters?.commerce,P=n.start.locale??"en",ue=d;if(f){if(typeof _!="object"||!_||!("provider"in _)||typeof _.provider!="string"||!("currency"in _)||typeof _.currency!="string")return null;ue=await this.readPaywall({paywallVersionId:f,locale:P,commerce:{provider:_.provider,currency:_.currency,...X(y)?{intent:"subscription_change"}:{}}})}if(!ue)return null;I();let M=ue,ve=!1,Re=async()=>{throw new l("PURCHASE_PENDING","Only the original purchase can be recovered")};return{signal:he.signal,view:M,quote:y,locale:P,get operation(){return p},get canReselect(){return D.get(s.operationId)===!0},async refresh(){return M},preview:Re,confirm:Re,cancel:Re,async read(){if(ve)throw new DOMException("Purchase view closed","AbortError");p=await V(n,s);let F=await L(n,!1,new Set([s.operationId]));return ve||R(N(F,"operation")),structuredClone(p)},destroy(){ve=!0}}},start(e){let t=J.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(t.operation!=="start"||t.customer||t.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return T(async()=>{let n=(await w.read()).entry;if((!n||j(n)||z(n))&&await ye(!0)==="blocked")return ke();let o=await w.update(r=>{if(r&&!j(r)&&!(z(r)&&r.start.requestId!==t.requestId)){if(r.start.funnelId!==t.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return r}return{schemaVersion:1,baseUrl:w.baseUrl,scope:m.scope,customerId:S,sessionId:te,start:t,allowed:[...m.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!o)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return O!==o.start.requestId&&(c?.reset(),c=null,v.clear(),D.clear(),A=!1),A?Pe(o,q.error):se(o,!0,!0,!0)},`start:${t.funnelId}`)},refresh:Q,confirm:Ae,retry:()=>A?Ae():T(async()=>{let{entry:e}=await w.read();return e?se(e,!0):R({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return c?.view?T(async()=>{if(!c?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(c.pendingCommands?.find(n=>n.operation==="close"))await c.retry();else if(["running","waiting"].includes(c.view.status)){let n=c.view;await c.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:n.nodeId,visit:n.visit,revision:n.revision})}let t=(await w.read()).entry;return t&&t.start.requestId!==O?R({mode:"idle",status:"idle",actions:["start"],purchases:[]}):(g(t),R(N(t,"run")))},"close"):Q()},async continueCheckout(e,t){let n=t?await T(async()=>{let{entry:o}=await w.read();if(g(o),!o.run||!b(o).some(i=>i.operationId===t&&!i.terminal))throw new l("PURCHASE_PENDING","The original Checkout changed");let r=await L(o);return R(N(r,A?"operation":"run"))},`continue:${t}`,o=>o instanceof l&&o.code==="PURCHASE_PENDING"):await Q();I(),await e(Pt(n,t))},async terminateCheckout(e){let t=n=>n.actions.includes("continue_checkout")&&n.purchases.some(o=>o.type==="checkout"&&o.operationId===e);if(!t(q)&&!t(await Q()))throw new l("PURCHASE_PENDING","The original Checkout has changed");return T(async()=>{let{entry:n}=await w.read();g(n);let o=b(n).find(i=>i.operationId===e&&!i.terminal);if(!o||!n.run)throw new l("PURCHASE_PENDING","The original Checkout has changed");await V(n,o,"terminate_checkout");let r=await L(n,!1,new Set([e]));return R(N(r,A?"operation":"run"))},`terminate:${e}`,n=>n instanceof l&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(n.code))},subscribe(e){return oe.add(e),()=>{oe.delete(e)}},destroy:qe}}export{et as a,Pt as b,Zt as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as ie}from"./chunk-LQV7EC5H.js";import{a as N,b as Z,d as ee,f as te,g as ne,j as M,l as re,m as oe,n as se}from"./chunk-CO6HDNOC.js";import{b as K}from"./chunk-FPJ3FE26.js";import{r as V}from"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-
|
|
1
|
+
import{i as ie}from"./chunk-LQV7EC5H.js";import{a as N,b as Z,d as ee,f as te,g as ne,j as M,l as re,m as oe,n as se}from"./chunk-CO6HDNOC.js";import{b as K}from"./chunk-FPJ3FE26.js";import{r as V}from"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import{o as X,p as Y}from"./chunk-Y3W5G4BF.js";import{A as G}from"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import{d as R}from"./chunk-A5WUQLAO.js";import{a as p}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-W22ESUYY.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(o){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[o.type];return o.nullable?t.nullable():t}function ae(o,t){let f=u.record(u.string(),R).parse(o);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,n]of Object.entries(f))X.parse({[m]:n});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,n]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(n).parse(f[m]);else if(n.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ve(o,t){return le(o,t,!1)}async function Ae(o,t){return le(o,t,!0)}async function le(o,t,f){t.signal?.throwIfAborted();let m=K.parse(t.content),n=m.document;if(t.closeControl==="content"&&!n.screen.actions.some(e=>e.type==="event"&&e.close))throw new p("INVALID_REQUEST","An authored Close control requires a declared Close action");if(z.has(o))throw new p("CONFLICT","Content is already mounted in this container");let g=ae(t.inputs??{},n.contract),T=new Set(u.array(u.string()).max(40).parse(t.mutableInputs??[]));if(T.size!==(t.mutableInputs?.length??0)||[...T].some(e=>!Object.hasOwn(n.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(n.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let q=Y.parse(t.bindings??[]),d=o.ownerDocument,ue=o.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,H=n.kind==="popup",r=H?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=n.kind,c.setAttribute("aria-label",n.name),c.style.cssText="width:100%;min-width:0",r){r.setAttribute("aria-label",n.name);let e=n.screen.presentation;r.style.cssText=e.type==="inline"?N("content",{type:"fullscreen"},n.screen.theme):N("content",e,n.screen.theme),a=ee(r,n.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),r.append(c),o.append(r)}else o.append(c);let i=!1,A=!1,C=!1,D=!1,de=r?oe(r):se(c,o),S=re(o,t,n.kind,()=>{k()&&(v(),h(t.onDismiss))}),F,j,L=new Promise((e,s)=>{F=e,j=s});L.catch(()=>{});let y=null,E=structuredClone(n.screen),J=G(E,[t.locale,...d.defaultView?.navigator.languages??[]]),x=t.capabilities;E.actions=E.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function v(){i||(i=!0,t.signal?.removeEventListener("abort",v),S.finish("dismissed"),j(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),r?.close(),r?.remove(),c.remove(),z.delete(o),r&&P?.())}let I=()=>{!C||!k()||(v(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(r&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="×",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"关闭":"Close"),ne(e,n.screen.theme),e.addEventListener("click",I),r.prepend(e)}r&&a?.responsive&&(_=Z(r,I,k,t.locale?.startsWith("zh")?"关闭":"Close")),r?.addEventListener("cancel",e=>{e.preventDefault(),I()}),r?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),I())});async function Q(){if(i||!C||A||!y)return;let e=y;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),y=null}catch(s){i||h(t.onError,s)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function W(){if(i)throw new p("CONFLICT","Content host has been destroyed");C||!D||(P??=M(d),S.present(e=>{de(),r&&(a?.latch(),r.showModal(),a?.responsive&&r.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(r,a?.type??n.screen.presentation.type,a?.responsive)),C=!0}))}function U(e){S.finish("error",e),j(e instanceof Error?e:new Error(String(e))),v()}let B={destroy:v,show:W,get pendingAction(){return y?structuredClone(y):null},retryAction:Q,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let s=u.record(u.string(),R).parse(e),b=ae({...g,...s},n.contract);for(let l of Object.keys(s))if(!T.has(l)&&(!Object.hasOwn(g,l)||V(g[l])!==V(b[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(g)!==V(b)&&(w?.update(E,J,{capabilities:x,serverInput:{bindings:q,answers:{},values:b}}),g=b)},updateCapabilities(e){if(i)return;let s=structuredClone(e);w?.updateCapabilities(s),x=s}};z.set(o,B),t.signal?.addEventListener("abort",v,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=M(d),S.start(H,t.locale??n.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:n.name,viewportHeight:n.kind==="page"?ue:a?.responsive?d.defaultView?.innerHeight||800:void 0,...a?.responsive?{viewportWidth:d.defaultView?.innerWidth||1024,hostPresentation:()=>a.type}:{},onResize:e=>{i||a?.responsive&&(c.style.height=`${e}px`,c.style.overflow="clip",a.setContentHeight(e))},onRendered:e=>{if(!i&&(e&&r?.setAttribute("aria-label",e),!D))try{D=!0,f||W(),F()}catch(s){U(s),h(t.onError,s)}},onError:e=>{if(i)return;let s=new Error(e);D||U(s),h(t.onError,s)},onEscape:H?I:void 0,onAction:(e,s,b)=>{if(i||!C||A||y)return;let l=n.screen.actions.find(O=>O.id===e),$=n.contract.outputs[e];if(!(l?.type!=="event"||!$)&&!(l.close&&!k()))try{let O=ce($).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);y=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:s??{},answers:b??{},requestedClose:l.close}),Q()}catch(O){h(t.onError,O)}}}),w.update(E,J,{capabilities:x,serverInput:{bindings:q,answers:{},values:g}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return B}catch(e){throw U(e),e}}export{Ve as mountContent,Ae as prepareContent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-GFH7OK3S.js";import"./chunk-HKLAHQKF.js";import"./chunk-JYTUTIBB.js";import"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-XWVK4SJA.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-XLGNBPGF.js";import"./chunk-EQUVI5QU.js";import"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelPurchase};
|
package/dist/{funnel-host-purchase-entry-5UDZJJBN.js → funnel-host-purchase-entry-FFZUEX4Q.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as M}from"./chunk-
|
|
1
|
+
import{a as M}from"./chunk-GFH7OK3S.js";import"./chunk-HKLAHQKF.js";import{a as D,c as I}from"./chunk-JYTUTIBB.js";import"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-XWVK4SJA.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-XLGNBPGF.js";import"./chunk-EQUVI5QU.js";import"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import{a as E}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var k=.8;function q(f,r){let y=f.ownerDocument,w=new AbortController,c=AbortSignal.any([w.signal,r.client.identitySignal,...r.signal?[r.signal]:[]]),a,d,m,H=r.maxAgeMs??D,u=e=>E(r.onEvent,{at:performance.now(),...e});function P(e){e?.copy.destroy(),e?.select(void 0)}function b(){clearTimeout(m);let e=[a,d];a=d=void 0,e.forEach(P)}function O(){let e,t=new Promise(i=>{e=i}),l,o={select:e},s=I(f,{...r,start:t,signal:c,onState(i){u({type:"copy",state:i,...s.reason!==void 0&&{reason:s.reason},...l!==void 0&&{local:l}}),o.watch?.(i),E(r.onState,i)}});return o.copy=s,s.local.then(i=>l=i),o}function g(e){a=e,e.copy.ready.then(t=>{t&&a===e&&F()})}function p(){a||c.aborted||!f.isConnected||y.visibilityState==="hidden"||g(O())}function F(){clearTimeout(m),m=setTimeout(()=>{if(!a||d||c.aborted)return;let e=d=O();e.copy.ready.then(t=>{if(d===e){if(d=void 0,!t||!a)return P(e);P(a),a=e,u({type:"renewed"}),F()}})},H*k)}function S(){y.visibilityState==="hidden"?b():p()}function N(){y.removeEventListener("visibilitychange",S),b()}function T(e){let t=e?.parameters?.commerce;return e?.funnelId===r.funnelId&&e.locale===r.locale&&t?.provider===r.commerce.provider&&t.currency===r.commerce.currency&&t.intent===r.commerce.intent}return c.aborted||(c.addEventListener("abort",N,{once:!0}),y.addEventListener("visibilitychange",S),p()),{open(e){if(c.aborted)return Promise.resolve(null);let t=a;a=void 0,clearTimeout(m);let l=d;d=void 0,l&&g(l);let o=t?.copy,s=e.start,i=!e.hostPaywallTarget&&e.allowNewPurchase!==!1&&(s instanceof Promise||T(s)),C=!1,A=!1,h=n=>{A||(A=!0,u({type:"result",revealed:C,adopted:n}))},x=!1,v=n=>{x||(x=!0,h(!1),u({type:"end",outcome:n}))};u({type:"open",copy:o?.state??"none",used:!!o&&i}),t&&i?t.watch=n=>{n==="shown"?C=!0:n==="adopted"?h(!0):n!=="preparing"&&n!=="ready"&&h(!1)}:h(!1),i?o?.state==="ready"&&o.open():o?.destroy(),t?.select(i?s instanceof Promise?s.then(n=>{if(n&&!T(n)){o?.destroy();return}return n}):s:void 0);let R=M(f,{...e,client:r.client,prepared:i?o:void 0,signal:c,onDismiss(n){return v("dismissed"),queueMicrotask(p),e.onDismiss?.(n)}});return R.then(n=>{n||v("nothing"),p()},()=>{v("error"),p()}),R},destroy(){w.abort()}}}export{q as createFunnelPurchaseEntry};
|
package/dist/{funnel-host-recovery-paywall-AK4CJGGB.js → funnel-host-recovery-paywall-DGCR4IBQ.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b}from"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-
|
|
1
|
+
import{a,b}from"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as mountFunnelRecoveryPaywall,b as replaceableOriginalSession};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d}from"./chunk-
|
|
1
|
+
import{a,b,c,d}from"./chunk-JYTUTIBB.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-MOIVJERE.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-KCUE2VFJ.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as PRERENDER_MAX_AGE_MS,b as preparedInternals,c as prerenderFunnelPurchase,d as prerenderRunPaywall};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b}from"./chunk-
|
|
1
|
+
import{a,b}from"./chunk-HKLAHQKF.js";import"./chunk-JYTUTIBB.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-F4AIEI5N.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as En,c as bn}from"./chunk-XSJGNM2C.js";import{a as Rn}from"./chunk-7ZAM4YRK.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-6CNAIAG2.js";import"./chunk-XLGNBPGF.js";import{a as In}from"./chunk-JDXX5XN5.js";import"./chunk-EQUVI5QU.js";import{h as mn,i as vn,k as Pn}from"./chunk-3XH64DN3.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-MYG5MAKQ.js";import"./chunk-F4AIEI5N.js";import{a as ze}from"./chunk-S2S4ROGY.js";import{d as hn,f as gn}from"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-DLORK3P2.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import{K as Ke}from"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.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-3532HSBP.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-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import{b as Ce}from"./chunk-7JJGSLXD.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as $}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.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-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-7NCZ6XU7.js";import"./chunk-5MRSFLQA.js";import{b as q}from"./chunk-W22ESUYY.js";import{a as ne}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var E=class extends Error{constructor(d,P=0,b=!1,I="fix_request"){super(d);this.code=d;this.status=P;this.retryable=b;this.recovery=I;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function _n(n,c){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");let d=n.body?.getReader();if(!d)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");let P=()=>{d.cancel().catch(()=>{})};c.addEventListener("abort",P,{once:!0});let b=0,I="",t=new TextDecoder("utf-8",{fatal:!0});try{for(c.throwIfAborted();;){let i=await d.read();if(c.throwIfAborted(),i.done)break;if(b+=i.value.byteLength,b>262144)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");I+=t.decode(i.value,{stream:!0})}return I+=t.decode(),JSON.parse(I)}catch(i){throw c.throwIfAborted(),i instanceof E?i:new E("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{c.removeEventListener("abort",P),await d.cancel().catch(()=>{}),d.releaseLock()}}var Tn=["customer_commerce","purchases","operation_status","subscription_changes"];function Cn(n){let c=qe.parse(n.origin),d=Ue.parse(n.manifest),P={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let u of["projectId","environmentId","environment"])if(d[u]!==n.scope[u])throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");let b=n.customerId===void 0?null:q.uuid().parse(n.customerId),I=0,t=null,i=null,l=new AbortController,g=n.fetch??globalThis.fetch,A=null,C=()=>A??=import("./merchant-bridge-contracts-OIYML3DE.js").catch(u=>{throw A=null,u});d.capabilities.some(u=>Tn.includes(u))&&C().catch(()=>{});async function O(u,f,S,y,m){if(!d.capabilities.includes(u))throw new E("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let o=He[u];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(o.authority))throw new E("MERCHANT_BRIDGE_FORBIDDEN",403);let v=I,p=AbortSignal.any([l.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...y?[y]:[]]);p.throwIfAborted();let D=new Headers(await n.headers?.());if(p.throwIfAborted(),v!==I)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(D.get("authorization")??"")||D.has("X-Indiana-Bridge-Signature")||D.has("X-Indiana-Bridge-Key-Id"))throw new E("MERCHANT_BRIDGE_FORBIDDEN",403);D.set(Be,String(_e)),D.set("Accept","application/json");let j=crypto.randomUUID();D.set("X-Request-Id",j),D.set("Content-Type","application/json");let s=await g(c+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:D,signal:p,body:JSON.stringify({bridgeVersion:_e,requestId:j,command:o.command,scope:P,data:m??(S===void 0?{}:{operationId:S})})}),G=await _n(s,p);if(p.throwIfAborted(),v!==I)throw new DOMException("Merchant identity changed","AbortError");if(!s.ok){let L=$e.safeParse(G);throw!L.success||L.data.scope.projectId!==n.scope.projectId||L.data.scope.environment!==n.scope.environment||L.data.scope.environmentId!==n.scope.environmentId||L.data.requestId!==j||L.data.command!==o.command?new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status):new E(L.data.error.code,s.status,L.data.error.retryable,L.data.error.recovery)}let F=Ve(q.unknown()).safeParse(G);if(!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!==j||F.data.command!==o.command)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status);let X=f.safeParse(F.data.data);if(!X.success)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status);return X.data}function z(){if(!b)throw new E("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return b}async function V(u,f,S,y){let m=z();if(y!==void 0&&Te.parse({operationId:y,customerId:m}),!d.capabilities.includes(u))throw new E("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let o=I,v=AbortSignal.any([l.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...f?[f]:[]]);v.throwIfAborted();let p,D=new Promise((j,s)=>{p=()=>s(v.reason),v.addEventListener("abort",p,{once:!0})});try{let s=S(async()=>{let F=await C();if(v.throwIfAborted(),o!==I||b!==m)throw new DOMException("Merchant identity changed","AbortError");return F},v),G=await Promise.race([s,D]);return v.throwIfAborted(),G}finally{v.removeEventListener("abort",p)}}async function K(u,f,S,y){let m=z(),o=Te.parse({operationId:S,customerId:m}),v=await O(u,f,o.operationId,y,o);if(v.customerId!==m||v.operationId!==o.operationId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return v}return{async readPresentation(u){let f=await O("presentation",Ge,void 0,u);if(i!==null&&i!==f.nativeUserId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(f.presentation&&b!==null&&f.presentation.customerId!==b)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=f.nativeUserId,t=f.presentation,f},async createSession(u){let f=await O("session",je,void 0,u);if(i!==null&&i!==f.nativeUserId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(b!==null&&b!==f.session.customerId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==f.session.customerId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return b=f.session.customerId,i=f.nativeUserId,f.session},async reportPresentation(u,f){let S=z(),y=Je.parse(u);if(!t||t.customerId!==S||t.decisionId!==y.decisionId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return O("presentation_events",q.strictObject({queued:q.literal(!0)}),void 0,f,y)},async readCustomerCommerce(u){let f=z(),S=await V("customer_commerce",u,async(y,m)=>{let[o,v]=await Promise.all([y(),O("customer_commerce",q.unknown(),void 0,m)]),p=o.merchantBridgeCommerceSchema.safeParse(v);if(!p.success)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return p.data});if(S.customerId!==f)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return S},async executePurchase(u,f){let S=await V("purchases",f,async(y,m)=>K("purchases",(await y()).merchantBridgeOperationSchema,u,m),u);if(S.type!=="purchase")throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return S},readOperation:(u,f)=>V("operation_status",f,async(S,y)=>K("operation_status",(await S()).merchantOperationLookupSchema,u,y),u),async executeSubscriptionChange(u,f){let S=await V("subscription_changes",f,async(y,m)=>K("subscription_changes",(await y()).merchantBridgeOperationSchema,u,m),u);if(S.type!=="subscription_change")throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return S},reset(){I++,l.abort(),l=new AbortController,b=null,t=null,i=null}}}var en=q.strictObject({command:ve,target:Qe,runId:q.uuid().optional(),expiresAt:q.iso.datetime({offset:!0}).optional(),deliveryLimit:q.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Ze=q.strictObject({schemaVersion:q.literal(1),entries:q.array(en).max(4e3)});function nn(n){let c=!1,d=()=>{c||n.unavailable(),c=!0};function P(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function b(t){let i=P()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ze.parse(JSON.parse(i)).entries}function I(t,i){let l=P();if(!l)return;if(!i.length)return l.removeItem(t);let g=JSON.stringify(Ze.parse({schemaVersion:1,entries:i}));if(g.length>1048576)throw Error("Entry recovery is too large");l.setItem(t,g)}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:b(i)}}catch{d();return}},retain(t,i){if(t)try{let l=en.parse(i);I(t,[...b(t).filter(g=>g.command.funnelId!==l.command.funnelId),l])}catch{d()}},forget(t,i){if(t)try{I(t,b(t).filter(l=>l.command.requestId!==i))}catch{d()}}}}var tn=q.strictObject({version:q.literal(1),runs:q.array(q.uuid()).max(100)}),De=new WeakMap,Fe=new WeakMap;function Se(n){let c=!1;function d(){c||n.unavailable(),c=!0}function P(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 b(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let l=i.get(t.key);return l||i.set(t.key,l=new Set),l}function I(t){if(!t)return;let i=De.get(t.storage),l=i?.get(t.key);l?.delete(t.requestId),l?.size===0&&i?.delete(t.key)}return{claim(t,i,l,g,A=!1){if(l!==void 0)try{let C=n.binding();if(!C)throw Error("Entry delivery identity is unavailable");let O={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...C,i,t]),requestId:g},z=P(O);if(Fe.get(O.storage)?.has(O.key))throw Error("Entry delivery storage is unavailable");O.storage.setItem(O.key,JSON.stringify({version:1,runs:z}));let V=b(O);return!A&&!V.has(g)&&z.length+V.size>=l?!1:(V.add(g),O)}catch{return d(),!1}},accept(t,i){if(t)try{let l=P(t);l.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...l,i].slice(-100)})))}catch{let l=Fe.get(t.storage);l||Fe.set(t.storage,l=new Set),l.add(t.key),d()}finally{I(t)}},release:I}}function Pe(){let n,c,d=()=>{clearTimeout(n),n=void 0;let P=c;c=void 0,P?.cancelled()};return{get active(){return c!==void 0},start(P,b,I,t){if(c)return;if(P===0){b()?I():t();return}let i={valid:b,cancelled:t};c=i,n=setTimeout(()=>{c===i&&(c=void 0,n=void 0,b()?I():t())},P*1e3)},recheck(){c&&!c.valid()&&d()},cancel:d}}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 An(n){let c=we(n.baseUrl),d=n.scope,P=Ce(n),b=n.fetch??globalThis.fetch.bind(globalThis),I,t=!1,i=!1,l=0,g=0,A="",C=0,O=0,z=0,V=!1,K,u=!0,f,S,y,m,o,v=-1,p,D=e=>{p===e&&(F.release(e.deliveryTicket),p=void 0,N())},j=new Set,s=(e,a)=>ne(n.onStatus,e,a),G=Pe(),F=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[c,d.projectId,d.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>s("delivery_unavailable")}),X=new Set,L=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[c,d.projectId,d.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>s("recovery_unavailable")}),ee=e=>L.forget(e.storageKey,e.command.requestId);function Z(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),L.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(),N()}let le=()=>G.active||p!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Z(o.recovery,a);let h=Re(a);o.slot.hidden=h,h!==o.background&&(o.background=h,h?s("run_background",o.entryId):v=g,N())}function pe(e,a,h){let w=e.client.view;if(!a||e.background||!w?.screen||w.paywall||w.pendingRequest||w.stopped||w.status!=="waiting")return;let W=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:w.nodeId,visit:w.visit,revision:w.revision,customerToken:a}),J=Ce({...n,session:void 0});J.requestWithCredential("funnels",W,e.runToken,{keepalive:h}).then(()=>ee(e.recovery)).catch(()=>{}).finally(()=>J.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<O&&performance.now()<z;function R(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return s("incompatible",e.id),!1}}function B(e){if(t||e.epoch!==C||e.visit!==g||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function Q(e){if(le()){s("in_progress",e.id);return}let a=C,h=g;G.start(e.delivery?.delaySeconds??0,()=>!t&&a===C&&h===g&&document.visibilityState!=="hidden"&&R(e)&&I?.entries.some(w=>w.id===e.id&&w.funnelId===e.funnelId&&w.versionId===e.versionId&&w.event===e.event&&JSON.stringify(w.target)===JSON.stringify(e.target)&&JSON.stringify(w.delivery)===JSON.stringify(e.delivery))===!0,()=>{U(e)},()=>{j.delete(`${e.funnelId}:${e.id}`)})}async function U(e){if(le()){s("in_progress",e.id);return}if(!n.session.peek()){s("identity_required",e.id);return}let a=L.load(),h=a?.entries.find(_=>_.command.funnelId===e.funnelId&&(!_.expiresAt||Date.parse(_.expiresAt)>Date.now()));if(h){if(!Y(h)){s("recovery_pending",e.id);return}let _={...h,storageKey:a.key,epoch:C,visit:g};X.add(_.command.requestId),p=_,await M(_);return}let w=crypto.randomUUID(),W=F.claim(e.id,e.funnelId,e.delivery?.maxPerSession,w);if(W===!1){s("frequency",e.id),N();return}let J={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:W,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:w,locale:document.documentElement.lang||"en"}),epoch:C,visit:g,target:e.target,storageKey:a?.key};X.add(J.command.requestId),p=J,await M(J)}async function M(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let h,w=!1,W=!1;async function J(_){if(e.epoch!==C)return;let T=_.view;if(!(e.storageKey&&T&&(Re(T)||T.paywall||T.pendingRequest))&&T&&["running","waiting"].includes(T.status))try{await _.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:T.nodeId,visit:T.visit,revision:T.revision}),ee(e)}catch(x){if(!(x instanceof $&&x.code==="FORBIDDEN"))throw x}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let H=F.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);H!==!1&&(e.deliveryTicket=H)}Z(e),s("starting",e.command.entryId);let _=await P.request("funnels",e.command),T=Ye.safeParse(_);if(T.success){if(T.data.scope.projectId!==d.projectId||T.data.scope.environment!==d.environment)throw new $("SCOPE_MISMATCH","Entry scope changed");e.epoch===C&&s(T.data.reason,e.command.entryId),ee(e),D(e);return}let x=Xe.parse(_);if(!x.runToken||x.scope.projectId!==d.projectId||x.scope.environment!==d.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new $("INVALID_RESPONSE","Invalid entry Run");if(F.accept(e.deliveryTicket,x.run.id),e.epoch!==C){D(e),s("identity_changed",e.command.entryId);return}Z(e,x.run);let k=Ae({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?_:void 0});h=k,W=!0,await k.get(),W=!1;let te=k.view;if(!te||te.id!==x.run.id||te.source.type!=="funnel"||te.source.id!==e.command.funnelId||te.source.versionId!==e.command.versionId)throw new $("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(te.status)){ee(e),D(e),s("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-D54WIMXD.js");if(!B(e)){await J(k),s("left_screen",e.command.entryId),D(e);return}let Ne=!1,xe=!1;if(o&&!o.background){await J(k),s("in_progress",e.command.entryId),D(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Re(te),n.container.append(ie);let ke=await fe(ie,{...n.host,client:k,appManifestRelease:n.appManifestRelease,onState(H){me(k,H),ne(n.host?.onState,H)},onDismiss(H){Ne=!0,ie.remove(),H&&!["running","waiting"].includes(H.status)&&ee(e),o?.client===k&&(o=void 0,k.reset(),N(),H&&H.status!=="completed"&&s("run_ended",e.command.entryId)),ne(n.host?.onDismiss,H)},onComplete(H){xe=!0,ee(e),o?.client===k&&re(),ne(n.host?.onComplete,H)},onError(H){ne(n.host?.onError,H),o?.client===k&&H instanceof $&&H.code==="FORBIDDEN"&&(ee(e),re(),s("run_ended",e.command.entryId))}}).catch(H=>{throw ie.remove(),H});if(!B(e)||Ne||xe){ke.destroy(),ie.remove(),B(e)||await J(k),D(e);return}let he=Re(k.view??te);ie.hidden=he,o={host:ke,client:k,slot:ie,entryId:e.command.entryId,background:he,runToken:x.runToken,owner:n.session.peek(),recovery:e},he||(v=e.visit),w=!0,D(e),s("started",e.command.entryId),he&&s("run_background",e.command.entryId)}catch(_){_ instanceof $&&(!h||W&&_.code==="FORBIDDEN")&&_.status!==void 0&&_.status>=400&&_.status<500&&!_.retryable&&(ee(e),D(e)),e.epoch===C&&!t&&(s("start_failed",e.command.entryId),ne(n.host?.onError,_))}finally{w||h?.reset(),e.dispatching=!1}}function Y(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=L.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){L.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||X.has(a.command.requestId)||!Y(a))continue;X.add(a.command.requestId);let h={...a,storageKey:e.key,epoch:C,visit:g};return p=h,M(h),!0}return!1}function ue(){if(V=!1,G.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(v=g),!ye()){if(!r()){u=!0;return}u=!1;for(let a of I?.entries??[]){let h=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||j.has(h)||!R(a))){if(!n.session.peek()){s("identity_required",a.id);continue}if(v===g){j.add(h),e&&s("in_progress",a.id);continue}if(p||G.active){s("in_progress",a.id);return}j.add(h),Q(a);break}}}}let N=()=>{!V&&!t&&(V=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===A?!1:(A=e,g++,G.cancel(),u=!0,j.clear(),X.clear(),!0)}function oe(){se()&&N()}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 h=a.closest("button,a,input");if(!(!h||h.matches(":disabled,[aria-disabled='true']")||h.closest("[hidden],[inert],[aria-hidden='true']")))for(let w of I?.entries??[]){let W=w.target.button;if(!(w.event!=="button_click"||!W||!R(w))){try{let J=be(document);if(!h.matches(W.selector)||J(W.selector,h)!==1)continue}catch{s("incompatible",w.id);continue}Q(w);break}}}async function Oe(){if(t)return;if(K)return K;let e=++l,a=new AbortController;f=a;let h,w=new Promise((_,T)=>{h=()=>T(new $("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",h,{once:!0})}),W=setTimeout(()=>a.abort(),n.timeoutMs??5e3),J=(async()=>{let _=async()=>{let fe=await b(`${c}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new $("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},T=await Promise.race([_(),w]),x=Date.parse(T.validatedAt),k=Date.parse(T.validUntil);if(T.scope.projectId!==d.projectId||T.scope.environment!==d.environment||T.scope.environmentId!==n.environmentId||T.release!==n.appManifestRelease||k<=Date.now()||x>Date.now()+5e3||k-x>6e4||k<=x)throw new $("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==l)return;let te=I===void 0;I=T,O=k,z=performance.now()+Math.min(k-Date.now(),6e4),G.recheck(),(te||u)&&N()})();K=J;try{await J}finally{clearTimeout(W),a.signal.removeEventListener("abort",h),K===J&&(K=void 0)}}async function on(){if(!(!i||t)){try{await Oe()}catch{t||s("configuration_unavailable")}N()}}let Me=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,A=location.origin+location.pathname,S=Ee(oe),y=n.session.subscribeIdentity(()=>{C++,G.cancel(),F.release(p?.deliveryTicket),u=!0,p=void 0,j.clear(),v=-1,X.clear(),o&&pe(o,o.owner,!1),re(),N()}),m=new MutationObserver(N),m.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",N),addEventListener("pagehide",ae),await Me.refresh())},refresh:Oe,async retry(){p&&!t&&p.epoch===C&&await M(p)},destroy(){t=!0,l++,G.cancel(),F.release(p?.deliveryTicket),Me.destroy(),f?.abort(),m?.disconnect(),S?.(),y?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",N),removeEventListener("pagehide",ae),ae(),re(),P.dispose(),I=void 0}}}function Dn(n){let c=we(n.baseUrl),d=n.fetch??globalThis.fetch.bind(globalThis),P,b=0,I=0,t=!1,i=!1,l=!1,g=0,A=0,C=-1,O=!1,z="",V,K,u,f,S=new Set,y,m,o,v=(r,R)=>ne(n.onStatus,r,R),p=Pe(),D=()=>{try{return n.deliveryIdentity?.()}catch{return}},j=()=>JSON.stringify(D()),s=Se({storage:n.deliveryStorage,binding:()=>{let r=D();return r?.id?[c,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>v("delivery_unavailable")}),G=()=>Date.now()<b&&performance.now()<I;function F(r){try{return G()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return v("incompatible",r.id),!1}}function X(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function L(r){if(r.dispatching)return;r.dispatching=!0;let R=g;try{let B=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"});s.accept(r.deliveryTicket,B.run.id);let{showFunnelRun:Q}=await import("./funnel-runtime-host-D54WIMXD.js");if(t||R!==g||m!==r)return;let U=document.createElement("div");n.container.append(U),C=A;let M=await Q(U,{...n.host,client:B.controller,appManifestRelease:n.appManifestRelease,onDismiss(Y){o?.process===r.process&&(o=void 0,U.remove()),ne(n.host?.onDismiss,Y)}});if(t||R!==g||m!==r){M.destroy(),U.remove();return}o={entry:r.entry,process:r.process,host:M,slot:U,deliveryTicket:r.deliveryTicket},m=void 0,v("run_presented",r.entry.id)}catch(B){if(t||R!==g||m!==r)return;B instanceof $&&"result"in B?(s.release(r.deliveryTicket),m=void 0,r.process.destroy(),v("suppressed",r.entry.id),Z()):v("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function ee(r){if(t||i||m||o||y||p.active||C===A||!F(r))return;let R=`${A}:${r.id}`;if(S.has(R))return;S.add(R);let B=A,Q=g,U=j();p.start(r.delivery?.delaySeconds??0,()=>!t&&g===Q&&A===B&&j()===U&&document.visibilityState!=="hidden"&&F(r)&&P?.entries.some(M=>M.id===r.id&&M.funnelId===r.funnelId&&M.versionId===r.versionId&&M.event===r.event&&JSON.stringify(M.target)===JSON.stringify(r.target)&&JSON.stringify(M.delivery)===JSON.stringify(r.delivery))===!0,()=>{let M=s.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(M===!1){v("frequency",r.id),Z();return}try{let Y={entry:r,process:n.createProcess(r),visit:A,deliveryTicket:M};m=Y,L(Y)}catch(Y){s.release(M),v("entry_unavailable",r.id),ne(n.host?.onError,Y)}},()=>{S.delete(R)})}function Z(){O||t||(O=!0,queueMicrotask(()=>{if(O=!1,p.recheck(),!(t||i||document.visibilityState==="hidden"||!G()||m||o||y||p.active||C===A)){for(let r of P?.entries??[])if(r.event==="screen_enter"&&!S.has(`${A}:${r.id}`)&&F(r)){ee(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||m||o||y||C===A)return;let R=be(document,()=>{});for(let B of P?.entries??[]){let Q=B.target.button;if(B.event!=="button_click"||!Q||!F(B))continue;let U=r.target.closest(Q.selector);if(!(!U||U.tagName.toLowerCase()!==Q.tag||R(Q.selector)!==1||U.matches(":disabled")||U.closest('[inert],[hidden],[aria-hidden="true"]'))){ee(B);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,A++,p.cancel(),S.clear(),Z())};async function me(){if(t)return;if(K)return K;let r=g,R=new AbortController;V=R;let B,Q=new Promise((ye,ue)=>{B=ue}),U=()=>B(new $("TIMEOUT","Funnel entry read cancelled"));R.signal.addEventListener("abort",U,{once:!0});let M=setTimeout(()=>R.abort(),n.timeoutMs??5e3),Y=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await d(`${c}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:R.signal});if(!ce.ok)throw new $("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},N=await Promise.race([ue(),Q]),se=Date.parse(N.validatedAt),oe=Date.parse(N.validUntil);if(N.scope.projectId!==n.scope.projectId||N.scope.environment!==n.scope.environment||N.scope.environmentId!==n.environmentId||N.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new $("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==g||(P=N,b=oe,I=performance.now()+Math.min(oe-Date.now(),6e4),p.recheck(),Z())})();K=Y;try{await Y}finally{clearTimeout(M),R.signal.removeEventListener("abort",U),K===Y&&(K=void 0)}}async function pe(){if(!(!l||t))try{await me()}catch{t||v("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>l&&!t?15e3:void 0});return{async start(){l||t||(l=!0,z=location.origin+location.pathname,u=Ee(le),f=new MutationObserver(Z),f.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",Z),await ae.refresh())},refresh:me,async retry(){m&&!t&&await L(m)},async syncIdentity(){p.cancel();let r=o??m??y;if(!r){i=!1,Z();return}try{let R=await r.process.syncIdentity();return i=!1,y===r&&(m={...r,visit:A},y=void 0,await L(m)),R}catch(R){throw r.process.view||(y={...r,visit:A},m=void 0,X()),R}},async detach(){i=!0,g++,p.cancel(),V?.abort();let r=o??m??y;r&&(y={...r,visit:A}),m=void 0,X(),r&&await r.process.detach()},destroy(){t=!0,g++,p.cancel(),ae.destroy(),V?.abort(),f?.disconnect(),u?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Z);let r=o??m??y;s.release(r?.deliveryTicket),m=void 0,y=void 0,X(),r?.process.destroy(),P=void 0}}}async function Fn(n,c){return(await import("./paywall-DWBIV43F.js")).showPaywall(n,c)}async function lt(){return await Promise.all([import("./paywall-DWBIV43F.js"),import("./screen-renderer-HJOKBOZH.js")]),Fn}async function ut(...n){return n[1]=ze(n[1]),(await import("./paywall-session-R3WV3BSU.js")).createPaywallSession(...n)}async function ft(...n){let c=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-DWBIV43F.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-D54WIMXD.js"),n[1].prepared)).showFunnelRun(...n)}finally{c?.()}}async function rn(n,c){try{return await n()}catch(d){throw c&&c.state!=="adopted"&&await import("./funnel-paywall-prerender-YPVUTJTO.js").then(P=>P.preparedInternals(c)?.release(),()=>{}),d}}async function mt(...n){return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-DWBIV43F.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-6BBAZXCX.js"),n[1].prepared)).showFunnelPurchase(...n)}async function pt(...n){return import("./funnel-host-purchase-6BBAZXCX.js").catch(()=>{}),import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),(await import("./funnel-paywall-prerender-YPVUTJTO.js")).prerenderFunnelPurchase(...n)}async function yt(){await Promise.all([import("./funnel-paywall-prerender-YPVUTJTO.js"),import("./funnel-host-purchase-6BBAZXCX.js"),import("./paywall-DWBIV43F.js"),import("./screen-renderer-HJOKBOZH.js"),import("./paywall-content-S6A2WLIX.js"),import("./check-response-XGOTG3KL.js"),import("./operation-contracts-YJM6772C.js"),import("./merchant-bridge-contracts-OIYML3DE.js")])}async function ht(...n){return(await import("./funnel-host-purchase-entry-5UDZJJBN.js")).createFunnelPurchaseEntry(...n)}async function gt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictFunnelStart(...n)}async function vt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictedPaywallLoadingDocument(...n)}async function It(...n){return(await import("./funnel-host-recovery-paywall-AK4CJGGB.js")).mountFunnelRecoveryPaywall(...n)}async function wt(...n){return(await import("./content-EV62FGPW.js")).mountContent(...n)}async function Et(...n){return(await import("./content-EV62FGPW.js")).prepareContent(...n)}export{$ as LongplayError,E 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,ht as createFunnelPurchaseEntry,Ae as createFunnelRunController,An as createIamFunnelEntries,Dn as createIamFunnelProcessEntries,Pn as createLocalFunnelClient,pn as createLongplay,Cn as createMerchantBridge,ut 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,wt as mountContent,It as mountFunnelRecoveryPaywall,gt as predictFunnelStart,vt as predictedPaywallLoadingDocument,yt as preloadFunnelPurchase,lt as preloadPaywall,Et as prepareContent,gn as preparePaywallFallback,pt as prerenderFunnelPurchase,mt as showFunnelPurchase,ft as showFunnelRun,Fn as showPaywall};
|
|
1
|
+
import{a as En,c as bn}from"./chunk-XWVK4SJA.js";import{a as Rn}from"./chunk-7ZAM4YRK.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-WLO2GDRF.js";import"./chunk-XLGNBPGF.js";import{a as In}from"./chunk-7DQV2EUW.js";import"./chunk-EQUVI5QU.js";import{h as mn,i as vn,k as Pn}from"./chunk-PBHOJKKG.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-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import{a as ze}from"./chunk-S2S4ROGY.js";import{d as hn,f as gn}from"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import{K as Ke}from"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.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-3532HSBP.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-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import{b as Ce}from"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as $}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.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-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as q}from"./chunk-W22ESUYY.js";import{a as ne}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var E=class extends Error{constructor(d,P=0,b=!1,I="fix_request"){super(d);this.code=d;this.status=P;this.retryable=b;this.recovery=I;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function _n(n,c){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");let d=n.body?.getReader();if(!d)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");let P=()=>{d.cancel().catch(()=>{})};c.addEventListener("abort",P,{once:!0});let b=0,I="",t=new TextDecoder("utf-8",{fatal:!0});try{for(c.throwIfAborted();;){let i=await d.read();if(c.throwIfAborted(),i.done)break;if(b+=i.value.byteLength,b>262144)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");I+=t.decode(i.value,{stream:!0})}return I+=t.decode(),JSON.parse(I)}catch(i){throw c.throwIfAborted(),i instanceof E?i:new E("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{c.removeEventListener("abort",P),await d.cancel().catch(()=>{}),d.releaseLock()}}var Tn=["customer_commerce","purchases","operation_status","subscription_changes"];function Cn(n){let c=qe.parse(n.origin),d=Ue.parse(n.manifest),P={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let u of["projectId","environmentId","environment"])if(d[u]!==n.scope[u])throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");let b=n.customerId===void 0?null:q.uuid().parse(n.customerId),I=0,t=null,i=null,l=new AbortController,g=n.fetch??globalThis.fetch,A=null,C=()=>A??=import("./merchant-bridge-contracts-OIYML3DE.js").catch(u=>{throw A=null,u});d.capabilities.some(u=>Tn.includes(u))&&C().catch(()=>{});async function O(u,f,S,y,m){if(!d.capabilities.includes(u))throw new E("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let o=He[u];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(o.authority))throw new E("MERCHANT_BRIDGE_FORBIDDEN",403);let v=I,p=AbortSignal.any([l.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...y?[y]:[]]);p.throwIfAborted();let D=new Headers(await n.headers?.());if(p.throwIfAborted(),v!==I)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(D.get("authorization")??"")||D.has("X-Indiana-Bridge-Signature")||D.has("X-Indiana-Bridge-Key-Id"))throw new E("MERCHANT_BRIDGE_FORBIDDEN",403);D.set(Be,String(_e)),D.set("Accept","application/json");let j=crypto.randomUUID();D.set("X-Request-Id",j),D.set("Content-Type","application/json");let s=await g(c+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:D,signal:p,body:JSON.stringify({bridgeVersion:_e,requestId:j,command:o.command,scope:P,data:m??(S===void 0?{}:{operationId:S})})}),G=await _n(s,p);if(p.throwIfAborted(),v!==I)throw new DOMException("Merchant identity changed","AbortError");if(!s.ok){let L=$e.safeParse(G);throw!L.success||L.data.scope.projectId!==n.scope.projectId||L.data.scope.environment!==n.scope.environment||L.data.scope.environmentId!==n.scope.environmentId||L.data.requestId!==j||L.data.command!==o.command?new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status):new E(L.data.error.code,s.status,L.data.error.retryable,L.data.error.recovery)}let F=Ve(q.unknown()).safeParse(G);if(!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!==j||F.data.command!==o.command)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status);let X=f.safeParse(F.data.data);if(!X.success)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status);return X.data}function z(){if(!b)throw new E("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return b}async function V(u,f,S,y){let m=z();if(y!==void 0&&Te.parse({operationId:y,customerId:m}),!d.capabilities.includes(u))throw new E("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let o=I,v=AbortSignal.any([l.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...f?[f]:[]]);v.throwIfAborted();let p,D=new Promise((j,s)=>{p=()=>s(v.reason),v.addEventListener("abort",p,{once:!0})});try{let s=S(async()=>{let F=await C();if(v.throwIfAborted(),o!==I||b!==m)throw new DOMException("Merchant identity changed","AbortError");return F},v),G=await Promise.race([s,D]);return v.throwIfAborted(),G}finally{v.removeEventListener("abort",p)}}async function K(u,f,S,y){let m=z(),o=Te.parse({operationId:S,customerId:m}),v=await O(u,f,o.operationId,y,o);if(v.customerId!==m||v.operationId!==o.operationId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return v}return{async readPresentation(u){let f=await O("presentation",Ge,void 0,u);if(i!==null&&i!==f.nativeUserId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(f.presentation&&b!==null&&f.presentation.customerId!==b)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=f.nativeUserId,t=f.presentation,f},async createSession(u){let f=await O("session",je,void 0,u);if(i!==null&&i!==f.nativeUserId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(b!==null&&b!==f.session.customerId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==f.session.customerId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return b=f.session.customerId,i=f.nativeUserId,f.session},async reportPresentation(u,f){let S=z(),y=Je.parse(u);if(!t||t.customerId!==S||t.decisionId!==y.decisionId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return O("presentation_events",q.strictObject({queued:q.literal(!0)}),void 0,f,y)},async readCustomerCommerce(u){let f=z(),S=await V("customer_commerce",u,async(y,m)=>{let[o,v]=await Promise.all([y(),O("customer_commerce",q.unknown(),void 0,m)]),p=o.merchantBridgeCommerceSchema.safeParse(v);if(!p.success)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return p.data});if(S.customerId!==f)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return S},async executePurchase(u,f){let S=await V("purchases",f,async(y,m)=>K("purchases",(await y()).merchantBridgeOperationSchema,u,m),u);if(S.type!=="purchase")throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return S},readOperation:(u,f)=>V("operation_status",f,async(S,y)=>K("operation_status",(await S()).merchantOperationLookupSchema,u,y),u),async executeSubscriptionChange(u,f){let S=await V("subscription_changes",f,async(y,m)=>K("subscription_changes",(await y()).merchantBridgeOperationSchema,u,m),u);if(S.type!=="subscription_change")throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return S},reset(){I++,l.abort(),l=new AbortController,b=null,t=null,i=null}}}var en=q.strictObject({command:ve,target:Qe,runId:q.uuid().optional(),expiresAt:q.iso.datetime({offset:!0}).optional(),deliveryLimit:q.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Ze=q.strictObject({schemaVersion:q.literal(1),entries:q.array(en).max(4e3)});function nn(n){let c=!1,d=()=>{c||n.unavailable(),c=!0};function P(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function b(t){let i=P()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ze.parse(JSON.parse(i)).entries}function I(t,i){let l=P();if(!l)return;if(!i.length)return l.removeItem(t);let g=JSON.stringify(Ze.parse({schemaVersion:1,entries:i}));if(g.length>1048576)throw Error("Entry recovery is too large");l.setItem(t,g)}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:b(i)}}catch{d();return}},retain(t,i){if(t)try{let l=en.parse(i);I(t,[...b(t).filter(g=>g.command.funnelId!==l.command.funnelId),l])}catch{d()}},forget(t,i){if(t)try{I(t,b(t).filter(l=>l.command.requestId!==i))}catch{d()}}}}var tn=q.strictObject({version:q.literal(1),runs:q.array(q.uuid()).max(100)}),De=new WeakMap,Fe=new WeakMap;function Se(n){let c=!1;function d(){c||n.unavailable(),c=!0}function P(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 b(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let l=i.get(t.key);return l||i.set(t.key,l=new Set),l}function I(t){if(!t)return;let i=De.get(t.storage),l=i?.get(t.key);l?.delete(t.requestId),l?.size===0&&i?.delete(t.key)}return{claim(t,i,l,g,A=!1){if(l!==void 0)try{let C=n.binding();if(!C)throw Error("Entry delivery identity is unavailable");let O={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...C,i,t]),requestId:g},z=P(O);if(Fe.get(O.storage)?.has(O.key))throw Error("Entry delivery storage is unavailable");O.storage.setItem(O.key,JSON.stringify({version:1,runs:z}));let V=b(O);return!A&&!V.has(g)&&z.length+V.size>=l?!1:(V.add(g),O)}catch{return d(),!1}},accept(t,i){if(t)try{let l=P(t);l.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...l,i].slice(-100)})))}catch{let l=Fe.get(t.storage);l||Fe.set(t.storage,l=new Set),l.add(t.key),d()}finally{I(t)}},release:I}}function Pe(){let n,c,d=()=>{clearTimeout(n),n=void 0;let P=c;c=void 0,P?.cancelled()};return{get active(){return c!==void 0},start(P,b,I,t){if(c)return;if(P===0){b()?I():t();return}let i={valid:b,cancelled:t};c=i,n=setTimeout(()=>{c===i&&(c=void 0,n=void 0,b()?I():t())},P*1e3)},recheck(){c&&!c.valid()&&d()},cancel:d}}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 An(n){let c=we(n.baseUrl),d=n.scope,P=Ce(n),b=n.fetch??globalThis.fetch.bind(globalThis),I,t=!1,i=!1,l=0,g=0,A="",C=0,O=0,z=0,V=!1,K,u=!0,f,S,y,m,o,v=-1,p,D=e=>{p===e&&(F.release(e.deliveryTicket),p=void 0,N())},j=new Set,s=(e,a)=>ne(n.onStatus,e,a),G=Pe(),F=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[c,d.projectId,d.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>s("delivery_unavailable")}),X=new Set,L=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[c,d.projectId,d.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>s("recovery_unavailable")}),ee=e=>L.forget(e.storageKey,e.command.requestId);function Z(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),L.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(),N()}let le=()=>G.active||p!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Z(o.recovery,a);let h=Re(a);o.slot.hidden=h,h!==o.background&&(o.background=h,h?s("run_background",o.entryId):v=g,N())}function pe(e,a,h){let w=e.client.view;if(!a||e.background||!w?.screen||w.paywall||w.pendingRequest||w.stopped||w.status!=="waiting")return;let W=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:w.nodeId,visit:w.visit,revision:w.revision,customerToken:a}),J=Ce({...n,session:void 0});J.requestWithCredential("funnels",W,e.runToken,{keepalive:h}).then(()=>ee(e.recovery)).catch(()=>{}).finally(()=>J.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<O&&performance.now()<z;function R(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return s("incompatible",e.id),!1}}function B(e){if(t||e.epoch!==C||e.visit!==g||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function Q(e){if(le()){s("in_progress",e.id);return}let a=C,h=g;G.start(e.delivery?.delaySeconds??0,()=>!t&&a===C&&h===g&&document.visibilityState!=="hidden"&&R(e)&&I?.entries.some(w=>w.id===e.id&&w.funnelId===e.funnelId&&w.versionId===e.versionId&&w.event===e.event&&JSON.stringify(w.target)===JSON.stringify(e.target)&&JSON.stringify(w.delivery)===JSON.stringify(e.delivery))===!0,()=>{U(e)},()=>{j.delete(`${e.funnelId}:${e.id}`)})}async function U(e){if(le()){s("in_progress",e.id);return}if(!n.session.peek()){s("identity_required",e.id);return}let a=L.load(),h=a?.entries.find(_=>_.command.funnelId===e.funnelId&&(!_.expiresAt||Date.parse(_.expiresAt)>Date.now()));if(h){if(!Y(h)){s("recovery_pending",e.id);return}let _={...h,storageKey:a.key,epoch:C,visit:g};X.add(_.command.requestId),p=_,await M(_);return}let w=crypto.randomUUID(),W=F.claim(e.id,e.funnelId,e.delivery?.maxPerSession,w);if(W===!1){s("frequency",e.id),N();return}let J={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:W,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:w,locale:document.documentElement.lang||"en"}),epoch:C,visit:g,target:e.target,storageKey:a?.key};X.add(J.command.requestId),p=J,await M(J)}async function M(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let h,w=!1,W=!1;async function J(_){if(e.epoch!==C)return;let T=_.view;if(!(e.storageKey&&T&&(Re(T)||T.paywall||T.pendingRequest))&&T&&["running","waiting"].includes(T.status))try{await _.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:T.nodeId,visit:T.visit,revision:T.revision}),ee(e)}catch(x){if(!(x instanceof $&&x.code==="FORBIDDEN"))throw x}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let H=F.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);H!==!1&&(e.deliveryTicket=H)}Z(e),s("starting",e.command.entryId);let _=await P.request("funnels",e.command),T=Ye.safeParse(_);if(T.success){if(T.data.scope.projectId!==d.projectId||T.data.scope.environment!==d.environment)throw new $("SCOPE_MISMATCH","Entry scope changed");e.epoch===C&&s(T.data.reason,e.command.entryId),ee(e),D(e);return}let x=Xe.parse(_);if(!x.runToken||x.scope.projectId!==d.projectId||x.scope.environment!==d.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new $("INVALID_RESPONSE","Invalid entry Run");if(F.accept(e.deliveryTicket,x.run.id),e.epoch!==C){D(e),s("identity_changed",e.command.entryId);return}Z(e,x.run);let k=Ae({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?_:void 0});h=k,W=!0,await k.get(),W=!1;let te=k.view;if(!te||te.id!==x.run.id||te.source.type!=="funnel"||te.source.id!==e.command.funnelId||te.source.versionId!==e.command.versionId)throw new $("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(te.status)){ee(e),D(e),s("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-CFDI4AWM.js");if(!B(e)){await J(k),s("left_screen",e.command.entryId),D(e);return}let Ne=!1,xe=!1;if(o&&!o.background){await J(k),s("in_progress",e.command.entryId),D(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Re(te),n.container.append(ie);let ke=await fe(ie,{...n.host,client:k,appManifestRelease:n.appManifestRelease,onState(H){me(k,H),ne(n.host?.onState,H)},onDismiss(H){Ne=!0,ie.remove(),H&&!["running","waiting"].includes(H.status)&&ee(e),o?.client===k&&(o=void 0,k.reset(),N(),H&&H.status!=="completed"&&s("run_ended",e.command.entryId)),ne(n.host?.onDismiss,H)},onComplete(H){xe=!0,ee(e),o?.client===k&&re(),ne(n.host?.onComplete,H)},onError(H){ne(n.host?.onError,H),o?.client===k&&H instanceof $&&H.code==="FORBIDDEN"&&(ee(e),re(),s("run_ended",e.command.entryId))}}).catch(H=>{throw ie.remove(),H});if(!B(e)||Ne||xe){ke.destroy(),ie.remove(),B(e)||await J(k),D(e);return}let he=Re(k.view??te);ie.hidden=he,o={host:ke,client:k,slot:ie,entryId:e.command.entryId,background:he,runToken:x.runToken,owner:n.session.peek(),recovery:e},he||(v=e.visit),w=!0,D(e),s("started",e.command.entryId),he&&s("run_background",e.command.entryId)}catch(_){_ instanceof $&&(!h||W&&_.code==="FORBIDDEN")&&_.status!==void 0&&_.status>=400&&_.status<500&&!_.retryable&&(ee(e),D(e)),e.epoch===C&&!t&&(s("start_failed",e.command.entryId),ne(n.host?.onError,_))}finally{w||h?.reset(),e.dispatching=!1}}function Y(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=L.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){L.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||X.has(a.command.requestId)||!Y(a))continue;X.add(a.command.requestId);let h={...a,storageKey:e.key,epoch:C,visit:g};return p=h,M(h),!0}return!1}function ue(){if(V=!1,G.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(v=g),!ye()){if(!r()){u=!0;return}u=!1;for(let a of I?.entries??[]){let h=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||j.has(h)||!R(a))){if(!n.session.peek()){s("identity_required",a.id);continue}if(v===g){j.add(h),e&&s("in_progress",a.id);continue}if(p||G.active){s("in_progress",a.id);return}j.add(h),Q(a);break}}}}let N=()=>{!V&&!t&&(V=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===A?!1:(A=e,g++,G.cancel(),u=!0,j.clear(),X.clear(),!0)}function oe(){se()&&N()}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 h=a.closest("button,a,input");if(!(!h||h.matches(":disabled,[aria-disabled='true']")||h.closest("[hidden],[inert],[aria-hidden='true']")))for(let w of I?.entries??[]){let W=w.target.button;if(!(w.event!=="button_click"||!W||!R(w))){try{let J=be(document);if(!h.matches(W.selector)||J(W.selector,h)!==1)continue}catch{s("incompatible",w.id);continue}Q(w);break}}}async function Oe(){if(t)return;if(K)return K;let e=++l,a=new AbortController;f=a;let h,w=new Promise((_,T)=>{h=()=>T(new $("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",h,{once:!0})}),W=setTimeout(()=>a.abort(),n.timeoutMs??5e3),J=(async()=>{let _=async()=>{let fe=await b(`${c}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new $("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},T=await Promise.race([_(),w]),x=Date.parse(T.validatedAt),k=Date.parse(T.validUntil);if(T.scope.projectId!==d.projectId||T.scope.environment!==d.environment||T.scope.environmentId!==n.environmentId||T.release!==n.appManifestRelease||k<=Date.now()||x>Date.now()+5e3||k-x>6e4||k<=x)throw new $("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==l)return;let te=I===void 0;I=T,O=k,z=performance.now()+Math.min(k-Date.now(),6e4),G.recheck(),(te||u)&&N()})();K=J;try{await J}finally{clearTimeout(W),a.signal.removeEventListener("abort",h),K===J&&(K=void 0)}}async function on(){if(!(!i||t)){try{await Oe()}catch{t||s("configuration_unavailable")}N()}}let Me=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,A=location.origin+location.pathname,S=Ee(oe),y=n.session.subscribeIdentity(()=>{C++,G.cancel(),F.release(p?.deliveryTicket),u=!0,p=void 0,j.clear(),v=-1,X.clear(),o&&pe(o,o.owner,!1),re(),N()}),m=new MutationObserver(N),m.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",N),addEventListener("pagehide",ae),await Me.refresh())},refresh:Oe,async retry(){p&&!t&&p.epoch===C&&await M(p)},destroy(){t=!0,l++,G.cancel(),F.release(p?.deliveryTicket),Me.destroy(),f?.abort(),m?.disconnect(),S?.(),y?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",N),removeEventListener("pagehide",ae),ae(),re(),P.dispose(),I=void 0}}}function Dn(n){let c=we(n.baseUrl),d=n.fetch??globalThis.fetch.bind(globalThis),P,b=0,I=0,t=!1,i=!1,l=!1,g=0,A=0,C=-1,O=!1,z="",V,K,u,f,S=new Set,y,m,o,v=(r,R)=>ne(n.onStatus,r,R),p=Pe(),D=()=>{try{return n.deliveryIdentity?.()}catch{return}},j=()=>JSON.stringify(D()),s=Se({storage:n.deliveryStorage,binding:()=>{let r=D();return r?.id?[c,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>v("delivery_unavailable")}),G=()=>Date.now()<b&&performance.now()<I;function F(r){try{return G()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return v("incompatible",r.id),!1}}function X(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function L(r){if(r.dispatching)return;r.dispatching=!0;let R=g;try{let B=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"});s.accept(r.deliveryTicket,B.run.id);let{showFunnelRun:Q}=await import("./funnel-runtime-host-CFDI4AWM.js");if(t||R!==g||m!==r)return;let U=document.createElement("div");n.container.append(U),C=A;let M=await Q(U,{...n.host,client:B.controller,appManifestRelease:n.appManifestRelease,onDismiss(Y){o?.process===r.process&&(o=void 0,U.remove()),ne(n.host?.onDismiss,Y)}});if(t||R!==g||m!==r){M.destroy(),U.remove();return}o={entry:r.entry,process:r.process,host:M,slot:U,deliveryTicket:r.deliveryTicket},m=void 0,v("run_presented",r.entry.id)}catch(B){if(t||R!==g||m!==r)return;B instanceof $&&"result"in B?(s.release(r.deliveryTicket),m=void 0,r.process.destroy(),v("suppressed",r.entry.id),Z()):v("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function ee(r){if(t||i||m||o||y||p.active||C===A||!F(r))return;let R=`${A}:${r.id}`;if(S.has(R))return;S.add(R);let B=A,Q=g,U=j();p.start(r.delivery?.delaySeconds??0,()=>!t&&g===Q&&A===B&&j()===U&&document.visibilityState!=="hidden"&&F(r)&&P?.entries.some(M=>M.id===r.id&&M.funnelId===r.funnelId&&M.versionId===r.versionId&&M.event===r.event&&JSON.stringify(M.target)===JSON.stringify(r.target)&&JSON.stringify(M.delivery)===JSON.stringify(r.delivery))===!0,()=>{let M=s.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(M===!1){v("frequency",r.id),Z();return}try{let Y={entry:r,process:n.createProcess(r),visit:A,deliveryTicket:M};m=Y,L(Y)}catch(Y){s.release(M),v("entry_unavailable",r.id),ne(n.host?.onError,Y)}},()=>{S.delete(R)})}function Z(){O||t||(O=!0,queueMicrotask(()=>{if(O=!1,p.recheck(),!(t||i||document.visibilityState==="hidden"||!G()||m||o||y||p.active||C===A)){for(let r of P?.entries??[])if(r.event==="screen_enter"&&!S.has(`${A}:${r.id}`)&&F(r)){ee(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||m||o||y||C===A)return;let R=be(document,()=>{});for(let B of P?.entries??[]){let Q=B.target.button;if(B.event!=="button_click"||!Q||!F(B))continue;let U=r.target.closest(Q.selector);if(!(!U||U.tagName.toLowerCase()!==Q.tag||R(Q.selector)!==1||U.matches(":disabled")||U.closest('[inert],[hidden],[aria-hidden="true"]'))){ee(B);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,A++,p.cancel(),S.clear(),Z())};async function me(){if(t)return;if(K)return K;let r=g,R=new AbortController;V=R;let B,Q=new Promise((ye,ue)=>{B=ue}),U=()=>B(new $("TIMEOUT","Funnel entry read cancelled"));R.signal.addEventListener("abort",U,{once:!0});let M=setTimeout(()=>R.abort(),n.timeoutMs??5e3),Y=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await d(`${c}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:R.signal});if(!ce.ok)throw new $("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},N=await Promise.race([ue(),Q]),se=Date.parse(N.validatedAt),oe=Date.parse(N.validUntil);if(N.scope.projectId!==n.scope.projectId||N.scope.environment!==n.scope.environment||N.scope.environmentId!==n.environmentId||N.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new $("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==g||(P=N,b=oe,I=performance.now()+Math.min(oe-Date.now(),6e4),p.recheck(),Z())})();K=Y;try{await Y}finally{clearTimeout(M),R.signal.removeEventListener("abort",U),K===Y&&(K=void 0)}}async function pe(){if(!(!l||t))try{await me()}catch{t||v("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>l&&!t?15e3:void 0});return{async start(){l||t||(l=!0,z=location.origin+location.pathname,u=Ee(le),f=new MutationObserver(Z),f.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",Z),await ae.refresh())},refresh:me,async retry(){m&&!t&&await L(m)},async syncIdentity(){p.cancel();let r=o??m??y;if(!r){i=!1,Z();return}try{let R=await r.process.syncIdentity();return i=!1,y===r&&(m={...r,visit:A},y=void 0,await L(m)),R}catch(R){throw r.process.view||(y={...r,visit:A},m=void 0,X()),R}},async detach(){i=!0,g++,p.cancel(),V?.abort();let r=o??m??y;r&&(y={...r,visit:A}),m=void 0,X(),r&&await r.process.detach()},destroy(){t=!0,g++,p.cancel(),ae.destroy(),V?.abort(),f?.disconnect(),u?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Z);let r=o??m??y;s.release(r?.deliveryTicket),m=void 0,y=void 0,X(),r?.process.destroy(),P=void 0}}}async function Fn(n,c){return(await import("./paywall-2Z3FUN2M.js")).showPaywall(n,c)}async function lt(){return await Promise.all([import("./paywall-2Z3FUN2M.js"),import("./screen-renderer-HJOKBOZH.js")]),Fn}async function ut(...n){return n[1]=ze(n[1]),(await import("./paywall-session-RNEEPYPG.js")).createPaywallSession(...n)}async function ft(...n){let c=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-2Z3FUN2M.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-CFDI4AWM.js"),n[1].prepared)).showFunnelRun(...n)}finally{c?.()}}async function rn(n,c){try{return await n()}catch(d){throw c&&c.state!=="adopted"&&await import("./funnel-paywall-prerender-QHEGZSPT.js").then(P=>P.preparedInternals(c)?.release(),()=>{}),d}}async function mt(...n){return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-2Z3FUN2M.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-7IYZRPYA.js"),n[1].prepared)).showFunnelPurchase(...n)}async function pt(...n){return import("./funnel-host-purchase-7IYZRPYA.js").catch(()=>{}),import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),(await import("./funnel-paywall-prerender-QHEGZSPT.js")).prerenderFunnelPurchase(...n)}async function yt(){await Promise.all([import("./funnel-paywall-prerender-QHEGZSPT.js"),import("./funnel-host-purchase-7IYZRPYA.js"),import("./paywall-2Z3FUN2M.js"),import("./screen-renderer-HJOKBOZH.js"),import("./paywall-content-JXWPOE3Y.js"),import("./check-response-XGOTG3KL.js"),import("./operation-contracts-YJM6772C.js"),import("./merchant-bridge-contracts-OIYML3DE.js")])}async function ht(...n){return(await import("./funnel-host-purchase-entry-FFZUEX4Q.js")).createFunnelPurchaseEntry(...n)}async function gt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictFunnelStart(...n)}async function vt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictedPaywallLoadingDocument(...n)}async function It(...n){return(await import("./funnel-host-recovery-paywall-DGCR4IBQ.js")).mountFunnelRecoveryPaywall(...n)}async function wt(...n){return(await import("./content-IDQO7TKS.js")).mountContent(...n)}async function Et(...n){return(await import("./content-IDQO7TKS.js")).prepareContent(...n)}export{$ as LongplayError,E 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,ht as createFunnelPurchaseEntry,Ae as createFunnelRunController,An as createIamFunnelEntries,Dn as createIamFunnelProcessEntries,Pn as createLocalFunnelClient,pn as createLongplay,Cn as createMerchantBridge,ut 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,wt as mountContent,It as mountFunnelRecoveryPaywall,gt as predictFunnelStart,vt as predictedPaywallLoadingDocument,yt as preloadFunnelPurchase,lt as preloadPaywall,Et as prepareContent,gn as preparePaywallFallback,pt as prerenderFunnelPurchase,mt as showFunnelPurchase,ft as showFunnelRun,Fn as showPaywall};
|
package/dist/openrouter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-Y6KA56V2.js";import"./chunk-SX7U2ONB.js";import"./chunk-
|
|
1
|
+
import"./chunk-Y6KA56V2.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import{a as i}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as A}from"./chunk-W22ESUYY.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
|
package/dist/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as o,e as r,f as e,g as f}from"./chunk-
|
|
1
|
+
import{d as o,e as r,f as e,g as f}from"./chunk-JLKODCRG.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-XAPMQRVJ.js";import"./chunk-CHRNCOXJ.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-VILB5M4X.js";import"./chunk-
|
|
1
|
+
import{a}from"./chunk-XAPMQRVJ.js";import"./chunk-CHRNCOXJ.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showPaywall};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as a}from"./chunk-
|
|
1
|
+
import{b as a}from"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-33EKLIMB.js";import"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
|
package/dist/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as S,c as E,d as T}from"./chunk-
|
|
1
|
+
import{b as S,c as E,d as T}from"./chunk-WLO2GDRF.js";import"./chunk-XLGNBPGF.js";import{a as A}from"./chunk-33EKLIMB.js";import{e as P}from"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.js";import{h as b,i as x,k as L}from"./chunk-PBHOJKKG.js";import{E as C}from"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as r}from"./chunk-UGATOG2T.js";import{h as R}from"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
|