@tinkerlandai/longplay-sdk 0.10.69 → 0.10.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/check-response-3EFQG3PL.js +1 -0
  4. package/dist/{chunk-VMYLTNDS.js → chunk-24Z5QET3.js} +1 -1
  5. package/dist/{chunk-YDPF2ZZW.js → chunk-3KIATB75.js} +1 -1
  6. package/dist/{chunk-3NV6NBQB.js → chunk-44SX4C3G.js} +1 -1
  7. package/dist/{chunk-ZRU7WONE.js → chunk-4C4L3JER.js} +1 -1
  8. package/dist/{chunk-BGCCW5QX.js → chunk-4HMPCJOG.js} +2 -2
  9. package/dist/chunk-4XDMBMDA.js +1 -0
  10. package/dist/{chunk-DXNTXCSI.js → chunk-5M2IIZB6.js} +1 -1
  11. package/dist/{chunk-5MOJUGMA.js → chunk-5XMHY7QX.js} +1 -1
  12. package/dist/{chunk-G3YIPDT6.js → chunk-6A4NV4ET.js} +1 -1
  13. package/dist/{chunk-USH4WN6W.js → chunk-6ZUJCHBI.js} +1 -1
  14. package/dist/{chunk-44ZJPQM6.js → chunk-AFQHUBKJ.js} +1 -1
  15. package/dist/chunk-BZRDECZJ.js +10 -0
  16. package/dist/{chunk-DZYMD4MJ.js → chunk-DGMRFL7K.js} +1 -1
  17. package/dist/{chunk-KJTHMRSH.js → chunk-DJTMSBQN.js} +1 -1
  18. package/dist/{chunk-ULED3B5P.js → chunk-EPQUD3S5.js} +1 -1
  19. package/dist/{chunk-LBYMDTGD.js → chunk-EU4NTVRT.js} +1 -1
  20. package/dist/{chunk-T5SCW4IA.js → chunk-F46VXI3Q.js} +1 -1
  21. package/dist/{chunk-6C3ARFEL.js → chunk-G7JQNJM4.js} +1 -1
  22. package/dist/{chunk-GBUGEL6M.js → chunk-IR6ELT3D.js} +1 -1
  23. package/dist/{chunk-NEW77IDA.js → chunk-IUX4CJZM.js} +1 -1
  24. package/dist/{chunk-UFTKCFNI.js → chunk-IXYVLURA.js} +1 -1
  25. package/dist/{chunk-TFPLIX5E.js → chunk-IYVJOUO7.js} +1 -1
  26. package/dist/chunk-KNZ3WTQ5.js +1 -0
  27. package/dist/{chunk-QTXHF27F.js → chunk-LHUZRVAC.js} +1 -1
  28. package/dist/{chunk-6GY2YT3U.js → chunk-LQ2XY26R.js} +1 -1
  29. package/dist/{chunk-SGOVJD5P.js → chunk-MAKRT62V.js} +1 -1
  30. package/dist/{chunk-Q4GG33R5.js → chunk-MUW3SOTB.js} +1 -1
  31. package/dist/{chunk-NNJ7W4KY.js → chunk-NCMKY7D6.js} +1 -1
  32. package/dist/{chunk-WVTKVQLZ.js → chunk-ONYG4VQI.js} +1 -1
  33. package/dist/{chunk-ECUGL7AO.js → chunk-PYM47Z55.js} +1 -1
  34. package/dist/{chunk-2ZMIM4MO.js → chunk-Q5DB34R4.js} +1 -1
  35. package/dist/chunk-QIV2YOVB.js +1 -0
  36. package/dist/{chunk-CQ5EQNQA.js → chunk-RZ7WFYWY.js} +1 -1
  37. package/dist/{chunk-MT4OQFDI.js → chunk-TDMXEI2U.js} +1 -1
  38. package/dist/chunk-TFGIDUGW.js +1 -0
  39. package/dist/{chunk-LUVTP4VU.js → chunk-TLQUUC3G.js} +1 -1
  40. package/dist/{chunk-JW4MSBYN.js → chunk-TNWZWEEY.js} +1 -1
  41. package/dist/{chunk-5NCQOJR2.js → chunk-TYIAPLQP.js} +1 -1
  42. package/dist/{chunk-ST7XO45I.js → chunk-ULJJTIL5.js} +1 -1
  43. package/dist/chunk-UOJSZMKN.js +1 -0
  44. package/dist/chunk-UR2PWRLG.js +1 -0
  45. package/dist/{chunk-26QYDE7V.js → chunk-UWHTCMMF.js} +1 -1
  46. package/dist/{chunk-TYJWRPJY.js → chunk-VCUJMMEM.js} +1 -1
  47. package/dist/{chunk-EJSTRCBQ.js → chunk-YV4HA2DV.js} +1 -1
  48. package/dist/{chunk-2SSOV3OG.js → chunk-ZFNSXRQY.js} +1 -1
  49. package/dist/{chunk-EQ64JD4L.js → chunk-ZJXQTMBW.js} +1 -1
  50. package/dist/{chunk-RMR64P6V.js → chunk-ZVVDPXHC.js} +1 -1
  51. package/dist/content-F3LHKR2S.js +1 -0
  52. package/dist/funnel-host-purchase-WJ2GKXKT.js +1 -0
  53. package/dist/{funnel-host-recovery-paywall-KHBGMNS5.js → funnel-host-recovery-paywall-OANZILW3.js} +1 -1
  54. package/dist/{funnel-local-client-Cb9jJGpo.d.ts → funnel-local-client-2Yx0Q_lF.d.ts} +27 -0
  55. package/dist/{funnel-paywall-copies-A76T5V7B.js → funnel-paywall-copies-ZI6BLXH7.js} +1 -1
  56. package/dist/funnel-paywall-prerender-36ER2LYV.js +1 -0
  57. package/dist/{funnel-process-client-DE650LzB.d.ts → funnel-process-client-BTusJtqx.d.ts} +10 -1
  58. package/dist/funnel-route-prediction-IO6TEHFN.js +1 -0
  59. package/dist/funnel-route-source-VQQIKYXL.js +1 -0
  60. package/dist/funnel-runtime-host-LXIT2QY7.js +1 -0
  61. package/dist/index.d.ts +22 -6
  62. package/dist/index.js +1 -1
  63. package/dist/merchant-bridge-contracts-CJY7TX6J.js +1 -0
  64. package/dist/native-shell.js +1 -1
  65. package/dist/openrouter.js +1 -1
  66. package/dist/operation-contracts-FAW24KGA.js +1 -0
  67. package/dist/page.js +1 -1
  68. package/dist/paywall-TVYLGNDU.js +1 -0
  69. package/dist/paywall-content-NLEGSOUT.js +1 -0
  70. package/dist/paywall-session-ADXZWQPU.js +1 -0
  71. package/dist/popup.d.ts +56 -3
  72. package/dist/popup.js +1 -1
  73. package/dist/{presentation-loading-B8W6a9WB.d.ts → presentation-loading-CU4c-koG.d.ts} +3 -1
  74. package/dist/react-native.d.ts +4 -4
  75. package/dist/react-native.js +1 -1
  76. package/dist/screen-renderer-EWRXGDWQ.js +1 -0
  77. package/dist/server.d.ts +20 -2
  78. package/dist/server.js +1 -1
  79. package/dist/visual.js +1 -1
  80. package/package.json +1 -1
  81. package/dist/check-response-754GDUOJ.js +0 -1
  82. package/dist/chunk-2BSDXKQS.js +0 -1
  83. package/dist/chunk-57ZXT7AS.js +0 -1
  84. package/dist/chunk-5U7LC2NL.js +0 -1
  85. package/dist/chunk-CWBBW6QS.js +0 -10
  86. package/dist/chunk-F5ABUGHD.js +0 -1
  87. package/dist/chunk-JAH62B6J.js +0 -1
  88. package/dist/chunk-UIR5CBCC.js +0 -1
  89. package/dist/content-66BI72XB.js +0 -1
  90. package/dist/funnel-host-purchase-YPAWZLXP.js +0 -1
  91. package/dist/funnel-paywall-prerender-PNJXR4VC.js +0 -1
  92. package/dist/funnel-route-prediction-KFUCAJLL.js +0 -1
  93. package/dist/funnel-route-source-WEYKNM2C.js +0 -1
  94. package/dist/funnel-runtime-host-RWU52BJ7.js +0 -1
  95. package/dist/merchant-bridge-contracts-RWNJHBTR.js +0 -1
  96. package/dist/operation-contracts-NNWS467N.js +0 -1
  97. package/dist/paywall-BSY67NQL.js +0 -1
  98. package/dist/paywall-content-RAB5S6KB.js +0 -1
  99. package/dist/paywall-session-CRIGHMOQ.js +0 -1
  100. package/dist/screen-renderer-H3FBGJZB.js +0 -1
  101. /package/dist/{chunk-BGCCW5QX.js.LEGAL.txt → chunk-4HMPCJOG.js.LEGAL.txt} +0 -0
  102. /package/dist/{chunk-S7NHVERO.js → chunk-CTCK5BUY.js} +0 -0
@@ -1 +0,0 @@
1
- import{a as kn,c as Rn,d as Lt,f as Ut,g as An,k as Sn}from"./chunk-6GY2YT3U.js";import{a as wn,b as Ye}from"./chunk-W32FI2A2.js";import{d as bn,e as Cn,f as Pn,g as vn,i as _t,j as ot,k as In,l as En,m as xn}from"./chunk-57ZXT7AS.js";import{a as hn,c as Ot,d as mn,e as yn}from"./chunk-LBYMDTGD.js";import{a as at,b as oe,d as Nt,f as Dt,j as gn}from"./chunk-CQ5EQNQA.js";import{b as Ee}from"./chunk-Q4GG33R5.js";import{B as _,C as it,D as Ge,E as _e,y as fn}from"./chunk-WVTKVQLZ.js";import{r as Le,t as Ue}from"./chunk-JW4MSBYN.js";import{i as pn}from"./chunk-EJSTRCBQ.js";import{c as be,j as We}from"./chunk-26QYDE7V.js";import{c as Tt}from"./chunk-DZYMD4MJ.js";import{a as k}from"./chunk-ZRU7WONE.js";import{a as z}from"./chunk-DSPLGTQI.js";async function Tn(H,a,x){if(!Ge(a))throw new k("INVALID_RESPONSE","A verified completed purchase is required");let T=H?We.parse(H):null;if(await x.onComplete?.(a),!T||!x.check)return;let F=We.parse(await x.check());if(F.internal_feature_id!==T.internal_feature_id||F.quantity!==T.quantity||T.observation!==void 0&&(F.observation===void 0||F.observation.requirementDigest!==T.observation.requirementDigest||F.observation.authority!==T.observation.authority||Tt(F.observation.subject)!==Tt(T.observation.subject)))throw new k("INVALID_RESPONSE","The access requirement changed");F.allowed&&await x.onAccessGranted?.(F)}function On(H){return Object.entries(H.document.buttons).filter(([,a])=>a.type==="checkout"&&a.product.type==="fixed"&&!Ee(a.product,{},H.capabilities)).map(([a])=>a)}function Nn(H,a){let x=_(a)?void 0:a.lines[0];if(!_(a)&&(a.lines.length!==1||!x))return;let T=_(a)?a.productVersionId:x.productVersionId,{screen:F,buttons:se}=H.document,M=new Map(_(a)?Object.entries(a.featureQuantities??{}):(x?.prepaid??[]).map(b=>[b.internal_feature_id,b.quantity]));function le(b,u){if(b.hidden)return!1;if(b.type==="plan_picker"&&H.capabilities.pickers[b.id]?.options.includes(T))return u[b.id]=T,!0;if(b.type==="quantity_picker"){let ne=M.get(b.internalFeatureId);return ne!==void 0&&(!b.bind?.plan||b.bind.plan===T)&&(u[b.id]=ne),!1}if(b.type==="button"&&b.action){let ne=se[b.action];return ne?.type==="checkout"&&ne.product.type==="fixed"&&ne.product.productVersionId===T}if(b.type!=="stack")return!1;let te=b.interaction,i=b.bind?.plan===T;for(let[ne,p]of b.children.entries()){let J={},L=le(p,J);if(te?.type==="toggle"||te?.type==="tabs"){if(!L)continue;return u[b.id]=te.type==="toggle"?ne===0:p.id,Object.assign(u,J),!0}Object.assign(u,J),L&&(i=!0,te?.type==="select"&&te.purpose==="product"&&te.pickerId&&p.type==="stack"&&p.bind?.plan===T&&(u[b.id]=p.id,u[te.pickerId]=T))}return i}for(let b of F.pages){let u={__page:b.id};if(le(b.root,u))return u}}var Bn="position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0";async function Pr(H,a,x){let T=a.focusAtReveal?()=>{}:_t(H.ownerDocument),F=()=>{M.finish("dismissed"),T()},se=()=>F(),M=In(H,a,"paywall",()=>{F(),z(a.onDismiss)},kn);a.signal?.throwIfAborted(),a.signal?.addEventListener("abort",se,{once:!0});let le=null,b,u,te;try{if(M.start(!0,a.loadingDocument?.screen.strings.defaultLocale,a.loadingDocument??null),M.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(le=a.check?We.parse(await M.wait(a.check(),ot)):null,le?.allowed)return M.finish("skipped"),a.signal?.removeEventListener("abort",se),T(),await a.onAccessGranted?.(le),{check:le,host:null};let[e,t]=await Promise.allSettled([M.wait(import("./screen-renderer-H3FBGJZB.js")),M.wait(a.start().then(r=>(M.cancelled&&r.destroy(),r)),ot)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;te=e.value,b=t.value,a.signal?.throwIfAborted(),b.signal?.throwIfAborted(),b.signal?.addEventListener("abort",se,{once:!0});let n=b.view??await M.wait(b.refresh(),ot);if(!n)throw new k("INVALID_RESPONSE","Paywall presentation is missing");b.signal?.throwIfAborted(),u=n}catch(e){throw M.finish("error",e),x?.retainedDialog?.release(),a.signal?.removeEventListener("abort",se),b?.signal?.removeEventListener("abort",se),b?.destroy(),T(),e}let i=b,{mountScreenPreview:ne}=te,p=H.ownerDocument,J=new AbortController,L=p.createElement("section"),pe=p.createElement("div"),W=p.createElement("div"),st=a.mountControls,ee=st?p.createElement("div"):void 0,d=p.createElement("p"),y=p.createElement("button"),ce=p.createElement("button"),O=p.createElement("button");(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&x?.hostPaywallTarget&&!x.retainedDialog&&u.document.presentation.type==="modal"&&(x.retainedDialog=vn(x.hostPaywallTarget));let ue=x?.retainedDialog,A=ue?.dialog??p.createElement("dialog"),Me=ue&&u.document.presentation.type==="inline"?{type:"modal",size:"md"}:u.document.presentation,re=Me.type==="inline"?W:p.createElement("div"),lt=i.locale||u.document.screen.strings.defaultLocale,o=lt.toLowerCase().startsWith("zh"),Dn=o?"正在处理…":"Processing…",_n=o?"正在准备报价…":"Preparing your price…",D=Rn(u.document.screen.theme);L.dataset.indianaPaywall="",L.setAttribute("aria-label",u.document.name),L.style.cssText=D.root,W.style.cssText=D.controls,d.style.cssText=D.message,d.setAttribute("role","status"),O.style.cssText=D.link,O.textContent=o?"关闭":"Close",y.style.cssText=D.secondary,y.textContent=o?"重试":"Retry",y.hidden=!0,ce.type="button",ce.style.cssText=D.primary,ce.textContent=o?"继续付款":"Continue payment",ce.hidden=!0,re.append(d,ce,y),W.append(O),ee&&(ee.style.cssText="flex:1 0 100%;min-width:0",ee.hidden=!0,W.prepend(ee)),re!==W&&(re.dataset.indianaPaywallStatus="",re.style.cssText="display:none;padding:0",L.append(re)),L.append(pe,W);let ct=()=>{let e=Mn();d.style.cssText=e?`${D.message};${Bn}`:D.message,zt();let t=c=>!c.hidden&&(c!==d||!!d.textContent&&!e);if(re!==W&&(re.style.cssText=!ie&&[...re.children].some(t)?`${D.controls};padding:12px 64px 12px 20px;flex-shrink:0`:e?"padding:0":"display:none;padding:0"),ee){let c=!ee.childElementCount&&!ee.textContent?.trim();ee.hidden!==c&&(ee.hidden=c)}let n=me??W,r=![...n.children].some(t),s=[...n.children].some(c=>c!==O&&t(c));n.style.cssText=r?D.controls.replace(/padding:[^;]+/,"padding:0"):s?`${D.controls};${D.pinned}`:D.controls,dt()},Mt=typeof MutationObserver>"u"?void 0:new MutationObserver(ct);Mt?.observe(L,{attributes:!0,attributeFilter:["hidden"],characterData:!0,childList:!0,subtree:!0});let Ln=Object.entries(u.document.buttons).filter(([,e])=>e.type==="close").map(([e])=>e),N,Vt,Ve=!1,$t=JSON.stringify(u.capabilities),Q;function Ce(e){let t=On(e);if(Q||fe&&!ae||B&&(C||!Pe()||ge))return Ae(e).map(({actionId:r})=>r);if(bt()||!C&&Pe())return t;let n=C?wt(e):Ct(e);return[...new Set([...t,...Ae(e).map(({actionId:r})=>r).filter(r=>!n.includes(r))])]}function $e(e){if(w)return;let t=u.id!==e.id;u=e;let n=JSON.stringify(e.capabilities);if(t||n!==$t){let r=!v&&!i.quote&&!i.operation?at(e,K,Bt):K;t||JSON.stringify(r)!==JSON.stringify(K)?(K=r,N?.update(e.document.screen,lt,{capabilities:oe(e),unavailableActions:Ce(e),serverInput:{bindings:[],answers:{}},selection:K})):N?.updateCapabilities(oe(e),Ce(e)),$t=n}Vn(e),ve(),Xe()}let U,ut=0;function Ht(){return(me??W).getBoundingClientRect().height+(re===W?0:re.getBoundingClientRect().height)}function dt(){let e=p.defaultView;if(!U?.responsive||!e)return;let t=me??W,n=e.innerHeight-(U.type==="modal"?32:0);t.style.maxHeight=`${Math.max(1,n)}px`,t.style.overflowY="auto",t.style.flexShrink="0",ut=Math.max(1,n-Ht()),N?.resizeViewport?.(ut,e.innerWidth)}let w=!1,fe=!1,v=null,pt,ze=!1,Qt=!1,he=!1,ft,ht=!1,ie,me;function Un(){return fe||w||ie||ht?{type:"recover",operationId:i.operation?.operationId??i.quote?.operationId??null,requestId:null}:Ot(i)}let I=()=>!w&&!ze&&!ie&&a.canInteract?.()!==!1,X,xe=!1,Re=!1,mt,f=null,de=null,Ke="",ye=()=>a.checkoutNavigation==="after_confirmation"&&!!(a.terminateCheckout||a.resumeCheckout),K={},Bt=new Set,ae,C;function yt(e){return!!e&&_(e)&&e.timing==="immediate"&&e.execution.provider==="merchant"}let gt=o?"正在确认付款…":"Confirming payment…",B=null,ge,Je,jt=!1,Pe=()=>a.allowNewPurchase!==!1||jt;function qt(){return JSON.stringify([u.id,u.capabilities])}function Ft(){let e=mt;return e&&e.read===a.prepareSubscriptionChange&&e.basis===qt()?e:void 0}function Xe(){let e=a.prepareSubscriptionChange;if(!e||!he||!I()||!Pe()||a.onPurchaseIntent||p.visibilityState==="hidden"||v||i.quote||i.operation||!Ae(u).length||Ft())return;let t=J.signal,n=new Promise(r=>{let s=()=>r(void 0);t.addEventListener("abort",s,{once:!0}),Promise.resolve().then(()=>(t.throwIfAborted(),e(t))).then(c=>r(t.aborted?void 0:c),s).finally(()=>t.removeEventListener("abort",s))});mt={read:e,basis:qt(),result:n}}let Wt=()=>{p.visibilityState==="hidden"?mt=void 0:Xe()};p.addEventListener("visibilitychange",Wt),J.signal.addEventListener("abort",()=>p.removeEventListener("visibilitychange",Wt),{once:!0});function Ae(e){return Object.entries(e.document.buttons).flatMap(([t,n])=>n.type==="checkout"?[{actionId:t,policy:n}]:[])}function Gt(e){let t=C?.quote;return t?Ae(e).filter(({actionId:n,policy:r})=>Se(t,e,n,r.product,K)).map(({actionId:n})=>n):[]}function wt(e){return C?.phase==="payment"?Gt(e):[]}function bt(){return(C?C.phase==="payment":!Pe())&&(Pe()||!!a.prepareUpgradeReplacement)&&ye()&&!!a.terminateCheckout&&!!i.quote&&i.canReselect===!1&&!!i.operation&&R(i.operation).type==="checkout"}function Ct(e){let t=i.quote;return!ye()||B||!t||!i.operation||R(i.operation).type!=="checkout"?[]:Ae(e).filter(({actionId:n,policy:r})=>Se(t,e,n,r.product,K)).map(({actionId:n})=>n)}function ve(){let e=Q?[]:C?wt(u):Ct(u),t=a.allowNewPurchase===!1&&!!i.operation&&R(i.operation).type==="checkout";ce.hidden=!!Q||(C?C.phase!=="payment":!t)||e.length>0,zt(e)}function Yt(){if(!(ae===void 0||Q))return d.textContent?d.textContent:C?.phase==="checking"?gt:void 0}function Mn(){return!!N?.updateCheckoutControls&&!!d.textContent&&Yt()!==void 0}let Ze;function zt(e=Q?[]:C?wt(u):Ct(u)){if(!N?.updateCheckoutControls)return;let t=Yt(),n=ye()||!!C;if(!t&&!n&&Ze?.on!==N)return;let r={actions:Ae(u).map(({actionId:c})=>c),resume:t?[ae]:n?e:[],resumeLabel:t??(o?"继续付款":C?"Continue payment":"Continue checkout"),busy:ae},s=JSON.stringify(r);Ze?.on===N&&Ze.key===s||(Ze={on:N,key:s},N.updateCheckoutControls(r))}function Kt(){de?.remove(),de=null}async function et(){if(B)return;if(a.resumeCheckout&&i.operation){let t=i.operation.operationId;try{await a.resumeCheckout(t)}catch(n){if(!(n instanceof k&&n.code==="PURCHASE_PENDING"))throw n;let r=await i.read();if(!I())return;if(r.operationId!==t||R(r).type==="checkout")throw n;await V(r,!1)}return}let e=await i.read();if(R(e).type!=="checkout")return V(e,!1);I()&&(He.delete(e.operationId),await Qe(e))}function Pt(){ge?.destroy(),ge=void 0,Je=void 0}function Jt(){let e=B;if(!e||ge)return;let t=o?"仍在核对原订单,暂时无法更换套餐。":"We’re still checking the original purchase before changing plans.",n=Date.now()+6e5,r=wn({document:p,delay:()=>Date.now()<n?5e3:void 0,async run(){if(!I())return;let s=await i.read();if(ge!==r||!I())return;if(s.operationId!==e.operationId)throw new k("PURCHASE_PENDING","The original Checkout changed");let c=R(s);c.type==="native"?(Pt(),d.textContent=o?"原订单已关闭。你可以继续更换套餐。":"The original checkout is closed. You can continue changing plans.",y.textContent=o?"继续更换套餐":"Continue changing plans",f=()=>tt(),y.hidden=!1):(c.type==="complete"||c.type==="fulfillment"||c.type==="recording")&&(Pt(),B=null,y.hidden=!0,await V(s,!1))}});ge=r,Je=async()=>{try{await r.refresh()}finally{ge===r&&(d.textContent=t,y.hidden=!1)}},f=Je,y.textContent=o?"查询结果":"Check result",y.hidden=!1,d.textContent=t,r.schedule()}async function tt(e=!1){let t=B;if(!t)return;f=()=>tt(),C&&(y.textContent=o?"查询状态":"Check status"),y.hidden=!0;let n=Date.now()+2e4;for(;I();){let r=await i.read();if(r.operationId!==t.operationId)throw new k("PURCHASE_PENDING","The original Checkout changed");if(!I())break;let s=R(r);if(s.type==="native"){if(!Pe()&&a.prepareUpgradeReplacement){let c=await a.prepareUpgradeReplacement(t.operationId,t.intent);if(!I())return;jt=!0,$e(c)}B=null,C&&Te(C.quote),Kt(),v=t.selection,X=t.coupon,xe=!1,Re=!1,await qe();return}if(s.type==="complete"||s.type==="fulfillment"||s.type==="recording"){B=null,C?await ke(C.quote,r):await V(r,!1);return}if(e&&s.type==="checkout"){e=!1;try{await a.terminateCheckout(t.operationId)}catch(c){z(a.onError,c)}}if(Date.now()>=n){C&&s.type==="checkout"&&(B=null,await ke(C.quote,r));break}await Ye(1e3,p,J.signal)}!B||w||(C?(d.textContent=o?"仍在核对原升级单,暂时无法更换套餐。":"We’re still checking the original upgrade before changing plans.",y.hidden=!1):Jt())}async function Xt(e,t,n,r){if(f=()=>Xt(e,t,n,r),await a.beforeCheckoutReplacement?.(structuredClone(r)),!I())return;let s=i.operation;if(s?.operationId!==e||R(s).type!=="checkout"){f=null,s&&await V(s,!1);return}B={operationId:e,selection:t,coupon:n,intent:r},C&&(d.textContent=o?"正在切换套餐…":"Changing plan…",y.hidden=!0);let c=!1;try{await a.terminateCheckout(e)}catch(l){if(l instanceof k&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(l.code)){B=null,C&&(f=It,y.textContent=o?"查询状态":"Check status",y.hidden=!1),d.textContent=o?"请继续原订单,或等待它过期后再更换方案。":"Continue your original checkout, or wait for it to expire before changing plans.",z(a.onError,l);return}c=l instanceof k&&(l.status??0)>=500,z(a.onError,l)}I()&&await tt(c)}function vt(e,t,n,r,s){let c=oe(e).checkoutCoupons?.[t],l=c?c.products[n]:a.claimCoupon&&s?pn(e.capabilities,s,r):void 0;return l?.couponId&&l.planVersionId===n?{id:l.couponId,offerId:l.offerId}:void 0}function Vn(e){fe||v||i.quote||i.operation||Ke&&d.textContent===Ke||(d.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":o?"当前账号暂无可购买的方案。":"No plans are currently available for this account.")}let He=new Map,nt=!1;function Se(e,t,n,r,s,c){let l=_(e),m=!l&&e.lines.length===1?e.lines[0]:void 0,h=Ee(r,s,t.capabilities);if(!h||h!==(l?e.productVersionId:m?.productVersionId))return!1;let E=vt(t,n,h,s,c),q;try{q=Ue(t.document.screen,h,s,t.capabilities)}catch{return!1}if(l){let Z=e.merchantTerms?.discount??(e.execution.provider==="merchant"?e.execution.discount:void 0);return Object.keys(q).length===Object.keys(e.featureQuantities??{}).length&&Object.entries(q).every(([De,St])=>e.featureQuantities?.[De]===St)&&(!E||Z?.couponId===E.id&&(!E.offerId||Z.grantId===E.offerId))}if((E||oe(t).checkoutCoupons?.[n])&&(E?.id??null)!==(e.discount?.couponId??null))return!1;let G=Object.fromEntries((m?.prepaid??[]).map(Z=>[Z.internal_feature_id,Z.quantity]));return[...new Set([...Object.keys(q),...Object.keys(G)])].every(Z=>(q[Z]??0)===(G[Z]??0))}let R=e=>hn({quote:i.quote,operation:e,requestId:null,pending:!1,destroyed:w,canReselect:i.canReselect});async function Qe(e){let t=e.merchantExecution,n=R(e),r=n.type==="checkout"?n.checkoutUrl:e.checkoutUrl;if(!(!I()||!r||it(e)&&n.type!=="checkout"||a.checkoutNavigation==="after_confirmation"&&n.type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||He.get(e.operationId)===r)){He.set(e.operationId,r);try{a.onCheckoutUrl?await a.onCheckoutUrl(r):p.defaultView?.location.assign(r)}catch(s){throw He.delete(e.operationId),s}}}let we=(e,t=!1)=>{if(e instanceof Nt)f=null,d.textContent=e.customerMessage(o);else if(An(e))f=null,d.textContent=t?o?"当前无法在此购买,付款尚未开始。请联系商户。":"Purchases aren’t available here right now. Payment hasn’t started. Contact the merchant for help.":Ut(e,o);else if(t){let n=e instanceof k?e.code:void 0;n==="CAPABILITY_UNAVAILABLE"||n==="NOT_CONFIGURED"?(f=null,d.textContent=o?"暂时无法为此套餐报价,付款尚未开始。":"Pricing for this plan is unavailable. Payment hasn’t started."):i.canReselect===!0&&!v?d.textContent=o?"未能取得报价,付款尚未开始。请重新选择套餐。":"We couldn’t prepare your price. Payment hasn’t started. Choose a plan again.":n==="COMMAND_PENDING"?d.textContent=o?"仍在准备报价,请重试以查看结果。":"Your price is still being prepared. Retry to check the result.":d.textContent=o?"未能取得报价,付款尚未开始。请重试。":"We couldn’t prepare your price. Payment hasn’t started. Try again."}else d.textContent=e instanceof k&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT")?Ut(e,o):e instanceof k?e.message:o?"操作未完成,请重试。":"This action couldn’t be completed. Try again.";y.hidden=f===null,Ke=d.textContent,t&&ae===void 0&&!U?.responsive&&d.scrollIntoView?.({block:"nearest"}),z(t&&x?.quoteError?x.quoteError:a.onError,e)},Be=new WeakMap;function je(e){fe=e,y.disabled=e,ce.disabled=e,N?.updateCapabilities?.(oe(u),Ce(u));for(let t of de?.querySelectorAll("button")??[])e?(Be.has(t)||Be.set(t,t.disabled),t.disabled=!0):Be.has(t)&&(t.disabled=Be.get(t),Be.delete(t)),Lt(t)}function Zt(){Q&&(d.textContent=Q.message,y.textContent=o?"重试":"Retry",y.disabled=!1,y.hidden=!Q.retry,ce.disabled=!0)}function kt(){d.textContent=o?"暂时无法操作,请稍后重试。":"This action is unavailable right now. Try again in a moment."}async function $n(e){if(a.beforeAction)try{await a.beforeAction()}catch(t){throw t instanceof Nt?(v=null,xe=!1,Re=!1,f=null):f=e,t}}async function j(e,t){if(fe||w||Q)return;if(!I()){kt();return}let n=e===qe,r=n?_n:Dn;ae=t!==void 0&&N?.updateCheckoutControls?t:void 0,d.textContent=r,je(!0),ve(),y.hidden=!0;try{if(e!==on&&e!==It&&e!==Et&&e!==Je&&(e!==et||!a.resumeCheckout)&&await $n(e),w||Q)return;if(!I()){f=e,y.hidden=!1,kt();return}await e()}catch(s){w||we(s,n)}finally{ae=void 0,je(!1),ve(),Q?Zt():d.textContent===r&&(d.textContent="")}}async function en(e){await Tn(le,e,a)}function Te(e,t){C=t?{quote:e,phase:t}:void 0,t==="checking"?(ae??=v?.actionId??Gt(u)[0],d.textContent=gt,f=It,y.textContent=o?"查询状态":"Check status",y.hidden=!0):ae=void 0,N?.updateCapabilities(oe(u),Ce(u)),ve()}function tn(e){return e instanceof k&&(e.code==="COMMAND_PENDING"||e.reason==="RESULT_UNKNOWN"||e.code==="NETWORK_ERROR"||e.code==="TIMEOUT"||e.status===429||(e.status??0)>=500)}function nn(e,t){Dt(e,{...t,featureQuantities:t.featureQuantities??{}},"Purchase operation changed")}async function It(){C&&await ke(C.quote)}async function ke(e,t){Te(e,"checking"),Ke="";let n=1e3;Ve=!0,z(a.onObservationChange,!0);try{for(let r=t;I();r=void 0){if(!r){try{r=await i.read()}catch(s){if(!tn(s))throw s}if(!I())return}if(r){nn(r,e);let s=R(r);if(s.type==="checkout"){Te(e,"payment"),d.textContent=o?"请先完成原订单的付款。":"Finish paying for this upgrade.",y.hidden=!1;return}if(s.type==="complete"){Te(e,"complete"),f=null;let c=u.capabilities.plans[e.productVersionId]?.name,l=e.merchantTerms?.subscriptionTerms?.items,m=l?.length===1?l[0].interval:void 0,h=m==="year"?o?"年付":"annual billing":m==="month"?o?"月付":"monthly billing":null;d.textContent=c?o?`已升级到 ${c}${h?" "+h:""}。`:`Upgraded to ${c}${h?" ("+h+")":""}.`:o?"已成功升级。":"Plan upgraded.",await en(r);return}if(s.type==="native"&&!_e(r)){Te(e),v=null,f=null,d.textContent=o?"付款没有成功,套餐未变更。请检查付款方式后重新选择套餐。":"Your payment didn’t go through, so your plan is unchanged. Check your payment method, then choose a plan again.",y.textContent=o?"重试":"Retry";return}if(r.problem&&!["RESULT_UNKNOWN","STATE_CHANGED"].includes(r.problem.reason??""))throw new k(r.problem.code,o?"暂时无法完成升级。":"The upgrade needs attention.",void 0,void 0,r.problem)}await Ye(n,p,J.signal),n=Math.min(n*1.5,15e3)}}finally{Ve=!1,z(a.onObservationChange,!1)}}async function Et(){let e=C?.quote;if(!e)return;let t=await i.read();if(nn(t,e),R(t).type!=="checkout")return ke(e,t);if(a.resumeCheckout){await a.resumeCheckout(t.operationId);return}He.delete(t.operationId),await Qe(t)}function rn(e){return Ot(i).type==="recording"||R(e).type==="recording"}function an(e){let t=e.merchantTerms,n=t?.subscriptionTerms?.items??[],r=t?t.totalMinor:_(e)?e.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),s=t?n.length===1&&n[0]?.amountMinor===r&&n[0]:!_(e)&&e.lines.length===1&&e.lines[0]?.catalogAmountMinor===r&&e.lines[0],c=r===null?be(t.subtotalMinor-t.discountMinor,e.currency)+(o?" + 待确认税费":" + tax confirmed at checkout"):be(r,e.currency)+(s?Le(s.interval,o?"zh-CN":"en",s.intervalCount??1):""),l=_(e)?i.view?.capabilities.plans[e.productVersionId]?.name??"":e.lines.map(m=>m.productName).join(", ");return{label:l?`${l} · ${c}`:c,recurring:s}}async function V(e,t=a.checkoutNavigation!=="after_confirmation"){if(w)return;if(!I()){f=async()=>V(await i.read()),y.hidden=!1;return}let n=e.quote??i.quote;if(yt(n)&&(e.confirmedAt||e.merchantExecution))return ke(n,e);if(d.textContent=Sn(e.status,o),rn(e)){let h=e.merchantExecution?.recordingStatus==="failed";d.textContent=h?o?"付款和商户处理已完成,但交易记录失败。请联系商户修复,勿重复购买。":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":o?"付款和商户处理已完成,正在确认交易记录。请勿重复购买。":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",y.textContent=o?"查询记录":"Check recording",f=async()=>V(await i.read()),y.hidden=!1;return}if(e.problem&&R(e).type!=="native"){let h=e.problem;f=Oe,y.textContent=o?"检查并恢复原操作":"Check and recover original purchase",we(new k(h.code,h.reason==="RESULT_UNKNOWN"?o?"付款结果尚未确定,请恢复原操作,暂勿重复购买。":"The payment result is unknown. Recover the original purchase before buying again.":h.phase==="fulfillment"?o?"付款已记录,商户权益处理需要核对。":"Payment was recorded. Access fulfillment needs attention.":h.code==="CAPABILITY_UNAVAILABLE"?o?"商户尚不支持本次购买所需的完整能力,请处理后恢复原操作。":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":h.code==="NOT_CONFIGURED"?o?"付款服务连接需要处理,请联系商户后恢复原操作。":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":o?"原购买操作需要处理,请查询或恢复此操作。":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,h));return}if((e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"||e.merchantExecution?.type==="subscription_change"&&e.merchantExecution.status==="applied")&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(d.textContent=o?"付款已记录,正在等待商户完成处理。":"Payment was recorded. Waiting for merchant fulfillment."),Ge(e)&&R(e).type==="complete"){f=null,await en(e);return}if(!_e(e)&&R(e).type!=="fulfillment"){if(i.canReselect===!1){d.textContent=o?"正在核对原购买结果":"Checking the original purchase result",y.textContent=o?"查询结果":"Check result",f=async()=>V(await i.read()),y.hidden=!1;return}e.status==="cancelled"?d.textContent=o?"这笔购买已取消,可以重新选择方案。":"This purchase was cancelled. Choose a plan to start again.":e.status==="failed"&&(d.textContent=o?"这笔购买未能完成,可以重新选择方案。":"This purchase didn’t go through. Choose a plan to try again."),y.textContent=o?"重试":"Retry",f=null,v=null;return}if(!t&&R(e).type==="checkout"){if(B){Jt();return}if(ye()){d.textContent="",nt=!1,f=null,y.hidden=!0,N?.updateCapabilities?.(oe(u),Ce(u)),ve();return}let h=i.quote,E=h?.operationId===e.operationId?an(h).label:"";d.textContent=nt?E?o?`${E} 尚未付款。再次选择该方案即可继续付款。`:`${E} is still unpaid. Choose it again to continue paying.`:o?"之前的购买尚未付款。再次选择该方案即可继续付款。":"Your earlier purchase is still unpaid. Choose that plan again to continue paying.":"",nt=!1,f=null;return}await Qe(e);let r=Date.now(),s=r+6e5,c=2e3,l=R(e).type!=="checkout",m=()=>l&&Date.now()-r<15e3;Ve=!0,z(a.onObservationChange,!0);try{for(;!w&&Date.now()<s;){if(await Ye(m()?700:c,p,J.signal),w)return;if(!I()){f=async()=>V(await i.read()),y.hidden=!1;return}let h=await i.read();if(R(h).type==="checkout"&&(l=!1),!t&&R(h).type==="checkout"){await V(h,!1);return}if(!h.problem&&_e(h)&&await Qe(h),!_e(h)||h.problem||rn(h)){await V(h);return}m()||(c=Math.min(c*1.5,3e4))}}finally{Ve=!1,z(a.onObservationChange,!1)}f=async()=>V(await i.read()),y.hidden=!1}async function xt(e=!1){let t=await i.read();if(w)return;if(!I()){f=()=>xt(e),y.hidden=!1;return}let n=i.quote;if(n&&Dt(t,{operationId:n.operationId,currency:n.currency},"The original purchase operation changed"),n&&(it(t)?["prepared","quoted"].includes(t.status):t.status==="pending")&&(it(t)||t.quoteFinalized===!1)&&!t.confirmedAt&&!t.checkoutUrl&&!("nativePurchase"in t&&t.nativePurchase)&&!t.merchantExecution&&!t.problem&&!i.pendingCancellation){if(a.purchaseConfirmation!=="paywall"){e?await Oe():f=null;return}setTimeout(sn,0,n);return}await V(t,e||void 0)}async function on(){await xt()}async function Hn(e){d.textContent=gt;let t=Date.now()+12e3;for(;!w&&Date.now()<t&&(await Ye(1500,p,J.signal),!(w||!I()));){let n;try{n=await i.read()}catch{break}if(n.problem?.reason!=="RESULT_UNKNOWN")return n}return e}async function Oe(){if(i.quote&&!(Date.parse(i.quote.expiresAt)>Date.now()))throw new k("INVALID_REQUEST",o?"此报价已过期,请重新选择套餐。":"This quote has expired. Choose a plan again.");Kt();let e=i.quote;if(yt(e)){Te(e,"checking");let n;try{n=await i.confirm()}catch(r){if(!tn(r))throw r;return ke(e)}return ke(e,n)}f=Oe;let t=await i.confirm();if(!I()){f=Oe,y.hidden=!1;return}if(t.problem?.reason==="RESULT_UNKNOWN"&&(t=await Hn(t)),t.problem){await V(t);return}if(_e(t)){if(R(t).type==="checkout")await Qe(t);else if(t.execution&&t.execution.provider!=="merchant"||"nativePurchase"in t&&t.nativePurchase){if(!a.onPurchase)throw new k("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await a.onPurchase({operation:t,signal:J.signal})}}f=async()=>V(await i.read()),await V(t,!0)}function sn(e){if(w)return;de?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());d.textContent=t?o?"此报价已过期。请先取消,再重新选择。":"This quote has expired. Cancel it, then choose again.":"";let n=p.createElement("div"),r=p.createElement("button"),s=p.createElement("button"),c=p.createElement("div"),l=p.createElement("p"),m=e.merchantTerms,h=o?"zh-CN":"en",E=m?.subscriptionTerms?.items??[],q=m?m.subscriptionTerms?.trial?.days:_(e)?void 0:e.lines.find(g=>g.trial)?.trial?.days,G=_(e)?m?m.totalMinor:e.totalMinor:q===void 0?null:m?m.totalMinor:e.charge?e.charge.totalMinor:e.lines.every(g=>g.trial)?0:null,Ne=(g,P)=>o?`${P} 天试用结束后 ${g}`:`Then ${g} after the ${P}-day trial`,{label:Z,recurring:De}=an(e),St=_(e)?i.view?.capabilities.plans[e.productVersionId]?.name??"":e.lines.map(g=>g.productName).join(", "),un=G===null?"":`${o?"今天应付":"Due today"} ${be(G,e.currency)}`;l.textContent=un?[St,un].filter(Boolean).join(" · "):Z,r.textContent=_(e)?o?"确认变更":"Confirm change":o?"确认购买":"Confirm purchase",r.disabled=t,s.textContent=o?"取消":"Cancel",n.style.cssText=D.panel,l.style.cssText=D.summary,c.style.cssText=D.actions,r.style.cssText=D.primary,s.style.cssText=D.secondary,Lt(r),r.onclick=()=>{j(Oe)};let dn=async()=>{let g=await i.cancel();w||(n.remove(),de=null,await V(g))};s.onclick=()=>{f=dn,j(dn)};let Y=p.createElement("div");if(Y.style.cssText=D.terms,_(e)){for(let[P,S]of Object.entries(e.featureQuantities??{})){let $=i.view?.capabilities.plans[e.productVersionId]?.prepaid?.find(Qn=>Qn.internalFeatureId===P),rt=p.createElement("p");rt.textContent=`${$?.name??P} · ${S} ${o?"份":"packs"}${$?` × ${$.terms.units}`:""}`,Y.append(rt)}for(let[P,S]of[[o?"原订阅抵扣":"Unused subscription credit",e.creditMinor],[o?"新套餐费用":"New plan charge",e.debitMinor],[o?"优惠减免":"Offer savings",m?.discountMinor??e.discountMinor],[o?"税费":"Tax",m?m.taxMinor:e.taxMinor]]){let $=p.createElement("p");$.textContent=`${P}: ${S===null?o?"结账时确认":"Confirmed at checkout":be(S,e.currency)}`,Y.append($)}let g=p.createElement("p");g.textContent=`${o?"生效时间":"Effective"}: ${e.effectiveAt}`,Y.append(g)}if(m){for(let P of E){if(G===null&&P===De)continue;let S=p.createElement("p"),$=be(P.amountMinor,e.currency)+Le(P.interval,h,P.intervalCount);S.textContent=G!==null&&q!==void 0?Ne($,q):$,P.amountAfterOfferMinor!==void 0&&(S.textContent+=` · ${o?"优惠结束后":"After the offer"} ${be(P.amountAfterOfferMinor,e.currency)}${Le(P.interval,h,P.intervalCount)}`),Y.append(S)}let g=m.subscriptionTerms?.trial;if(g){let P=p.createElement("p");P.textContent=o?`试用 ${g.days} 天;${g.cardRequired?"需要提供付款方式":"无需提供付款方式"}`:`Trial days: ${g.days}; ${g.cardRequired?"a payment method is required":"no payment method is required"}`,Y.append(P)}for(let P of[...m.expectedEffects.map(S=>S.description),...m.requiredConsents.map(S=>S.summary)]){let S=p.createElement("p");S.textContent=P,Y.append(S)}}else if(!_(e)){for(let g of e.lines){if(G!==null||g!==De){let P=p.createElement("p"),S=`${be(g.catalogAmountMinor,e.currency)}${Le(g.interval,h,g.intervalCount??1)}`;P.textContent=G!==null&&g.trial?(e.lines.length>1?`${g.productName} · `:"")+Ne(S,g.trial.days):`${g.productName} · ${S}`,Y.append(P)}for(let P of g.prepaid??[]){let S=p.createElement("p"),$=i.view?.capabilities.plans[g.productVersionId]?.prepaid?.find(rt=>rt.internalFeatureId===P.internal_feature_id);S.textContent=`${$?.name??P.internal_feature_id} · ${P.quantity} ${o?"份":"packs"} × ${P.terms.units}`,$&&(S.textContent+=Le($.reset==="week"||$.reset==="month"||$.reset==="year"?$.reset:"one_time",h,$.resetCount)),Y.append(S)}if(g.trial){let P=p.createElement("p");P.textContent=o?`试用 ${g.trial.days} 天;${g.trial.cardRequired?"需要提供付款方式":"无需提供付款方式"}`:`Trial days: ${g.trial.days}; ${g.trial.cardRequired?"a payment method is required":"no payment method is required"}`,Y.append(P)}}if(!e.charge){let g=p.createElement("p");g.textContent=o?"目录价格;最终金额以结账时税费和试用规则为准。":"Catalog price; the final charge depends on checkout taxes and trial terms.",Y.append(g)}}for(let g of Y.children)g.style.margin="0";c.append(r,s),n.append(l,...Y.childElementCount?[Y]:[],c),W.prepend(n),U?.responsive||n.scrollIntoView?.({block:"nearest"}),r.focus({preventScroll:!0}),de=n,fe&&je(!0),f=null}async function qe(){if(!v)return;if(f=qe,!xe){let n=i.view,r=n?.document.buttons[v.actionId],s=n&&r?.type==="checkout"?Ee(r.product,v.selection,n.capabilities):null;if(!n||!s)throw new k("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");if(!Re){let l=Ft(),m=l?await l.result:void 0;if(w)return;let h=a.resolveSubscriptionChange;if(h||m){let E={actionId:v.actionId,productVersionId:s,featureQuantities:Ue(n.document.screen,s,v.selection,n.capabilities)},q=m?[async()=>m(E)]:[],G=h?await h(E,...q):await q[0]?.();if(w)return;G!==void 0&&(v.subscriptionChange=fn.parse(G))}Re=!0}let c=X?.offerId;if(X&&!c){if(!a.claimCoupon)throw new k("CAPABILITY_UNAVAILABLE","Coupon claiming is unavailable");let{offer:l}=await a.claimCoupon(X.id,v.requestId);if(w)return;if(!l||l.couponId!==X.id||l.status!=="issued"||!(Date.parse(l.expiresAt)>Date.now()))throw v=null,X=void 0,f=async()=>{$e(await i.refresh()),f=null},new k("COUPON_UNAVAILABLE","This Coupon is no longer available for this purchase");c=l.id}if(!X&&!n.document.screen.actions.some(l=>l.id===v?.actionId&&typeof l.properties.couponBinding=="string")&&(c=await a.resolveOfferId?.({actionId:v.actionId,productVersionId:s,featureQuantities:Ue(n.document.screen,s,v.selection,n.capabilities)})),w)return;c!==void 0&&(v.offerId=c),xe=!0}if(!I()){y.hidden=!1;return}let e;try{e=await i.preview(v)}catch(n){throw i.canReselect===!0&&(v=null,xe=!1,Re=!1,X=void 0,f=null),n}if(X&&(_(e)?(()=>{let n=e.merchantTerms?.discount??(e.execution.provider==="merchant"?e.execution.discount:void 0);return n?.couponId!==X.id||n.grantId!==v.offerId})():e.discount?.couponId!==X.id||e.discount.offerId!==v.offerId))throw new k("INVALID_RESPONSE","The quote did not apply the Coupon selected on this Paywall");if(w)return;let t=e.merchantTerms;if(a.purchaseConfirmation!=="paywall"||a.confirmOnHostedCheckout&&I()&&!_(e)&&e.provider==="merchant"&&e.billingSubscriptionId===null&&t?.request.action==="purchase"&&t.request.mode==="subscription"&&t.subscriptionTerms?.trial===null&&t.requiredConsents.length===0&&Date.parse(e.expiresAt)>Date.now()){if(!I()){y.hidden=!1;return}if(!(Date.parse(e.expiresAt)>Date.now()))throw new k("INVALID_REQUEST",o?"此报价已过期,请重新选择套餐。":"This quote has expired. Choose a plan again.");let n=ae?"":o?"正在打开收银台…":"Opening checkout…";d.textContent=n;try{await Oe()}catch(r){w||we(r)}finally{d.textContent===n&&(d.textContent="")}return}sn(e)}function Ie(e="destroy",t=!1){if(w)return;w=!0;let n=pt;pt=void 0,z(n),a.signal?.removeEventListener("abort",se),i.signal?.removeEventListener("abort",se),M.finish("dismissed"),Vt?.(),Pt(),J.abort(),Mt?.disconnect(),N?.destroy(),i.destroy(),A.removeEventListener("cancel",cn),O.remove(),L.remove(),t||ln(),e==="dismiss"&&z(a.onDismiss)}function ln(){if(U?.destroy(),ue){ue.release();return}A.open&&A.close(),A.remove(),T()}F=Ie;async function Fe(){if(!he||w||ze||ie==="closing"||!ie&&!I())return;if(!x){Ie("dismiss");return}let e=p.createElement("p");e.setAttribute("role","status"),e.textContent=o?"正在关闭…":"Closing…",me||(me=p.createElement("div"),me.style.cssText=W.style.cssText,W.replaceWith(me),pe.inert=!0),O.hidden=!1,me.replaceChildren(e,O),ie="closing",O.setAttribute("aria-disabled","true"),O.focus({preventScroll:!0});try{await x.dismiss()}catch(t){w||z(a.onError,t)}w||(ie="retry",e.textContent=o?"未能确认关闭,请重试。":"Could not confirm closure. Try again.",O.textContent=o?"重试关闭":"Retry closing",O.removeAttribute("aria-label"),O.removeAttribute("aria-disabled"))}O.onclick=()=>{Fe()};function cn(e){e.preventDefault(),Fe()}A.addEventListener("cancel",cn),ce.onclick=()=>{j(C?Et:et)},y.onclick=()=>{if(Q){Q.retry?.();return}f&&j(f)};function Rt(e){M.finish("error",e),Ie()}function At(){if(!(!Qt||he||w||ze||U&&!I()))try{let e=t=>{a.focusAtReveal&&(T=_t(p)),N?.setHidden?.(!1),ft?.(),U&&(A.open||A.showModal(),U.responsive&&A.focus({preventScroll:!0}),!t&&a.loading!=="host"&&Cn(A,U.type,U.responsive)),t&&a.loading!=="host"&&typeof pe.animate=="function"&&!p.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches&&pe.animate([{opacity:.55},{opacity:1}],{duration:160,easing:"ease-out"}),he=!0,Xe()};x?x.present(t=>M.present(n=>e(t??n))):M.present(e)}catch(e){Rt(e),we(e)}}try{if(Me.type==="inline"?(ct(),ft=xn(L,H),H.append(L)):(A.setAttribute("aria-label",u.document.name),O.textContent="×",O.setAttribute("aria-label",o?"关闭":"Close"),Pn(O,u.document.screen.theme),O.hidden=gn(u.document),(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&ue?.content?ue.content.append(O,L):A.replaceChildren(O,L),ue||H.append(A),U=bn(A,{...u.document.screen,presentation:Me},dt),U.latch(),U.responsive&&(L.style.display="flex",L.style.flexDirection="column",L.style.maxHeight="100%",pe.style.overflow="clip",pe.style.minHeight="0"),ue||(ft=En(A))),st&&ee){let n=st(ee);if(typeof n=="function"&&(w?z(n):pt=n),w)throw new DOMException("Presentation cancelled","AbortError");ct()}N=ne(pe,{mode:"live",rendererUrl:"bundled",title:u.document.name,closeActions:Ln,onAuthoredClose(n){ie||w||(O.hidden=n)},hostPresentation:()=>U?.type??Me.type,reportContentHeight:U?.responsive,onResize:n=>{if(!U?.responsive)return;let r=Math.min(n,ut);pe.style.height=`${r}px`,U.setContentHeight(r+Ht())},onSelection(n){for(let[r,s]of Object.entries(n))typeof s=="number"&&typeof K[r]=="number"&&K[r]!==s&&Bt.add(r);K=n,ve(),Xe()},onAction(n,r={},s,c){if(!he||w||ie)return;let l=i.view,m=l?.document.buttons[n];if(!m)return;if(Q){m.type==="close"&&Fe();return}if(m.type==="close"&&x&&a.resumeCheckout&&i.operation&&mn(R(i.operation))){Fe();return}if(fe)return;if(!I()){kt();return}if(m.type==="close"){j(async()=>{x?.closeAction?await x.closeAction(n):await a.onAction?.(n),Ie(a.onAction?"action":"dismiss")});return}if(m.type==="action"){f=async()=>{if(m.action.type==="event"){if(!a.onEvent)throw new k("EVENT_HANDLER_REQUIRED","Provide the event handler");await a.onEvent(m.action.event)}else a.onOpenUrl?await a.onOpenUrl(m.action.url):p.defaultView?.location.assign(m.action.url);await a.onAction?.(n),f=null},j(f);return}if(ye()&&B){!ge&&B.selection.actionId===n&&j(()=>tt(!0),n);return}if(C){if(C.phase==="payment"&&l&&Se(C.quote,l,n,m.product,r,c)){j(Et,n);return}if(!bt())return}if(!Pe()&&!bt()){ye()&&l&&i.quote&&i.operation&&R(i.operation).type==="checkout"&&Se(i.quote,l,n,m.product,r,c)?j(et,n):d.textContent=o?"当前只能继续原订单。":"Only your original checkout is available.";return}if(de&&i.canReselect===!1){d.textContent=o?"请先确认或取消当前购买。":"Confirm or cancel the current purchase first.",U?.responsive||de.scrollIntoView?.({block:"nearest"}),de.querySelector("button")?.focus({preventScroll:!0});return}if(ye()&&a.terminateCheckout&&l&&i.quote&&i.operation&&i.canReselect===!1&&R(i.operation).type==="checkout"){if(Se(i.quote,l,n,m.product,r,c)){j(et,n);return}let E=Ee(m.product,r,l.capabilities),q;try{if(!E)throw new k("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");q=Ue(l.document.screen,E,r,l.capabilities)}catch(De){we(De);return}let G=i.operation.operationId,Ne={actionId:n,requestId:crypto.randomUUID(),selection:structuredClone(r)},Z=vt(l,n,E,r,c);j(()=>Xt(G,Ne,Z,{actionId:n,productVersionId:E,selection:Ne.selection,featureQuantities:q}),n);return}if((i.quote||v)&&i.canReselect===!1){let E=!!l&&!!i.quote&&Se(i.quote,l,n,m.product,r,c);nt=!!i.quote&&!E,f=i.quote?()=>xt(E):qe,j(f,n);return}let h=l&&Ee(m.product,r,l.capabilities);if(!l||!h){we(new k("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(a.onPurchaseIntent){f=null,j(async()=>{let E={actionId:n,productVersionId:h,selection:structuredClone(r),featureQuantities:Ue(l.document.screen,h,r,l.capabilities)};ht=!0,await a.onPurchaseIntent(E)},n);return}if(v&&v.actionId!==n){we(new k("COMMAND_PENDING","Finish the current purchase"));return}v||(X=vt(l,n,h,r,c),v={requestId:crypto.randomUUID(),actionId:n,selection:structuredClone(r)},xe=!1,Re=!1),j(qe,n)},onEscape:()=>{Fe()},onError:n=>{let r=new Error(n);!he&&!w&&Rt(r),we(r)},onRendered:n=>{n&&A.setAttribute("aria-label",n),Qt=!0,At()}}),N.setHidden?.(!0),dt();let e=ye()&&!!i.quote&&!!i.operation&&R(i.operation).type==="checkout";K=i.quote?Nn(u,i.quote)??at(u,{}):at(u,{}),N.update(u.document.screen,lt,{capabilities:oe(u),unavailableActions:Ce(u),serverInput:{bindings:[],answers:{}},...Object.keys(K).length?{selection:K}:{}}),Vt=i.subscribe?.($e),$e(i.view??u),await M.wait(N.ready);let t=i.operation;(!e||yt(i.quote))&&(i.quote||t&&(t.confirmedAt||t.checkoutUrl||Ge(t)))&&(f=on,j(f))}catch(e){throw Rt(e),e}return{check:le,host:{get currentResolution(){return u},setPurchaseRecovery(e,t){Q={message:e,retry:t},N?.updateCapabilities?.(oe(u),Ce(u)),ve(),Zt()},get subscriptionUpgradeActive(){return C!==void 0},get observing(){return Ve},get recovery(){return Un()},async prepareFallback(){if(fe||w||ie||ht)return{type:"recover",operationId:i.operation?.operationId??i.quote?.operationId??null,requestId:null};je(!0);try{let e=await yn(i);return e.type==="native"&&Ie(),e}finally{je(!1)}},setSuspended(e){ze=e,L.hidden=e,e&&A.open?A.close():!e&&!he?At():!e&&!w&&he&&Me.type!=="inline"&&!A.open&&A.showModal()},destroy:Ie,retainPurchaseDialog(){if(!(w||!A.open||!A.isConnected))return Ie("destroy",!0),{dialog:A,content:ue?.content,release:ln}},refresh:async()=>{if(!I()){if(i.view)return i.view;throw new k("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await i.refresh();return $e(e),At(),e}}}}export{Pr as a};
@@ -1 +0,0 @@
1
- import{a as tn}from"./chunk-EQ64JD4L.js";import{b as rn}from"./chunk-LBYMDTGD.js";import{b as nn}from"./chunk-ST7XO45I.js";import{d as We,e as ce}from"./chunk-ULED3B5P.js";import{c as qe,d as je,e as K,l as Ze}from"./chunk-ECUGL7AO.js";import{A as Je,F as He,G as Qe,H as z,I as Ye,J as le,K as G,a as Me,c as Y,g as Z,h as Ge,i as Ue,m as $e}from"./chunk-3NV6NBQB.js";import{A as ie,B as ae,z as oe}from"./chunk-WVTKVQLZ.js";import{a as de,b as Xe}from"./chunk-DXNTXCSI.js";import{a as j,b as _e,c as ke,e as De,h as Ve,i as Le,l as Be}from"./chunk-44ZJPQM6.js";import{b as W}from"./chunk-MT4OQFDI.js";import{a as Q}from"./chunk-KJTHMRSH.js";import{m as Ke,n as ue,o as ze,p as se}from"./chunk-JW4MSBYN.js";import{g as Ee,m as Ce,w as re}from"./chunk-EJSTRCBQ.js";import{b as Pe,d as L,e as Ae,f as Te}from"./chunk-LUVTP4VU.js";import{a as m}from"./chunk-ZRU7WONE.js";import{h as V}from"./chunk-TFPLIX5E.js";import{a as en}from"./chunk-5MRSFLQA.js";import{b as n}from"./chunk-S7NHVERO.js";import{a as on}from"./chunk-DSPLGTQI.js";import{c as Ne,f as Oe}from"./chunk-VPT5MFDG.js";function an(e){return Fn({...e,namespace:"commands",identity:[e.runToken]})}function Fn(e){let t,u,r=()=>new m("COMMAND_STORAGE_INVALID","Durable command storage is unavailable"),o=Promise.resolve().then(async()=>{if(t=e.storage??globalThis.localStorage,u=e.locks??globalThis.navigator?.locks,!t||!u||!globalThis.crypto?.subtle)throw r();let c=new TextEncoder().encode(JSON.stringify([new URL(e.baseUrl??en).href,...e.identity])),a=new Uint8Array(await crypto.subtle.digest("SHA-256",c));return`indiana.funnel.${e.namespace}.v1.`+Array.from(a,i=>i.toString(16).padStart(2,"0")).join("")});o.catch(()=>{});async function p(c){try{let a=await o;return await u.request(a,{mode:"exclusive"},()=>c(a))}catch(a){throw a instanceof m?a:r()}}function d(c){let a=t.getItem(c);if(a===null)return{revision:0,entry:null};if(a.length>1048576)throw r();let i=JSON.parse(a);if(!i||typeof i!="object"||!("revision"in i)||!("entry"in i)||!Number.isSafeInteger(i.revision)||Number(i.revision)<0)throw r();return{revision:Number(i.revision),entry:i.entry}}return{read:()=>p(d),write:(c,a)=>p(i=>{if(d(i).revision!==c)return null;if(!Number.isSafeInteger(c+1))throw r();let y=JSON.stringify({revision:c+1,entry:a});if(y.length>1048576)throw r();return t.setItem(i,y),c+1})}}var un=n.strictObject({type:n.literal("funnel"),id:n.uuid(),versionId:n.uuid()});var M=n.string().regex(/^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/),En=n.enum(["running","waiting","completed","closed","ineligible","failed"]),Cn=n.discriminatedUnion("type",[$e,n.strictObject({type:n.literal("wait"),receiptId:n.uuid(),kind:n.enum(["timer","event","operation"]),deadline:n.iso.datetime({offset:!0}).nullable(),eventName:M.optional()}),n.strictObject({type:n.literal("open_url"),receiptId:n.uuid(),url:He,openIn:Qe}),n.strictObject({type:n.literal("event"),receiptId:n.uuid(),event:M})]),Pn={id:M,presentation:Pe,outputs:n.array(M).max(250),inputs:se,values:n.record(n.string(),L).optional(),offeringKey:j.optional(),capabilities:Ee,customerData:Ce,dataCursors:n.record(M,Ke.nullable())},Nn=n.strictObject({...Pn,content:n.strictObject({type:n.literal("document"),document:re})}),pe=n.strictObject({id:n.uuid(),source:un,revision:n.number().int().nonnegative(),visit:n.number().int().nonnegative(),nodeId:M,nodeType:n.enum(["entry","screen","condition","split","feature","action","external_page","wait","end","offering","coupon","coupons","output"]),status:En,stopped:n.boolean(),canBack:n.boolean(),authenticated:n.boolean(),locale:n.string().min(1).max(35),answers:ue,parameters:ze,variables:n.record(n.string(),L),output:L.nullable(),screen:Nn.nullable(),paywall:n.strictObject({receiptId:n.uuid(),resolution:n.union([We,ce]),quote:oe.nullable(),operation:ie.nullable(),purchaseRequestId:n.uuid().nullable(),selectionGeneration:n.number().int().nonnegative().optional(),canReselect:n.boolean().optional()}).nullable(),instruction:Cn.nullable(),pendingRequest:n.strictObject({requestId:n.uuid(),authenticationRequired:n.boolean()}).nullable(),runExpiresAt:n.iso.datetime({offset:!0}),credentialExpiresAt:n.iso.datetime({offset:!0}).nullable()}),On=n.strictObject({scope:V,run:pe,settlement:n.strictObject({requestId:n.uuid(),state:n.enum(["pending","unknown","settled"]),operationId:n.uuid().nullable(),receiptId:n.uuid().nullable().optional()}).optional(),purchase:n.strictObject({receiptId:n.uuid(),quote:oe.nullable(),operation:ie.nullable(),canReselect:n.boolean().optional()}).optional(),review:n.strictObject({activeOperationId:n.uuid().nullable(),pages:n.array(n.strictObject({receiptId:n.uuid(),nodeId:M,visit:n.number().int().nonnegative()})).max(100),page:n.strictObject({receiptId:n.uuid(),nodeId:M,visit:n.number().int().nonnegative(),document:re,answers:ue,inputs:se,values:n.record(n.string(),L).optional()}).nullable(),coupons:n.array(n.strictObject({grantId:n.uuid(),status:n.enum(["issued","reserved","redeemed","expired","revoked","unknown"]),expiresAt:n.string().nullable()})).max(100),purchases:n.array(n.strictObject({receiptId:n.uuid(),operationId:n.uuid(),status:n.enum(["pending","complete","cancelled","failed","unknown"])})).max(100)}).optional(),runToken:n.string().regex(/^gg_fr_[A-Za-z0-9_-]{43}$/).optional(),customerId:n.uuid().optional()}),sn=On.extend({run:pe.extend({paywall:pe.shape.paywall.unwrap().extend({resolution:ce}).nullable()})});var ln="X-Indiana-Server-Key";var An=n.strictObject({selector:n.string().min(1).max(2048),action:n.enum(["set","append","remove"]),attribute:n.string().min(1).max(128).refine(e=>["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e)),value:n.string().max(5e4).optional(),parentSelector:n.string().max(2048).optional(),insertBeforeSelector:n.string().max(2048).optional()}),Tn=n.strictObject({variation:n.string().min(1).max(128),description:n.string().max(2e3).default(""),css:n.string().max(1e5).default(""),js:n.string().max(1e5).default(""),domMutations:n.array(An).max(200).default([]),iam:Ge.optional(),renderGuard:Z.optional()}),me=Tn.omit({variation:!0,description:!0,iam:!0}),_n=qe.omit({variations:!0,active:!0}).extend({changeId:n.string().regex(/^[a-f0-9]{64}$/),variations:n.tuple([me,me]).rest(me).refine(e=>e.length<=20)}),cn=n.strictObject({trackExposures:n.boolean(),environmentId:n.uuid(),generation:n.string().regex(/^[a-f0-9]{64}$/),experiments:n.array(_n).max(100),savedGroups:je});var $=n.string().regex(/^[a-f0-9]{64}$/),Tt=n.strictObject({iam:$,executionContracts:n.union([n.tuple([n.literal("funnel-run/1")]),n.tuple([n.literal("funnel-process/1")])]).default(["funnel-run/1"])}),kn=n.strictObject({release:$,render:Z,button:n.strictObject({selector:n.string().min(1).max(512),elementKey:n.string().min(1).max(256),tag:n.enum(["button","a","input"])}).nullable()}),_t=n.strictObject({scope:V.extend({environmentId:n.uuid()}),release:$,validatedAt:n.iso.datetime({offset:!0}),validUntil:n.iso.datetime({offset:!0}),entries:n.array(n.strictObject({id:n.uuid(),funnelId:n.uuid(),versionId:n.uuid(),event:n.enum(["screen_enter","button_click"]),delivery:Ue.optional(),target:kn})).max(4e3)}),kt=n.strictObject({operation:n.literal("entry_start"),funnelId:n.uuid(),versionId:n.uuid(),entryId:n.uuid(),release:$,requestId:n.uuid(),locale:n.string().min(1).max(35).default("en")}),Dt=n.strictObject({scope:V,suppressed:n.literal(!0),reason:n.enum(["frequency","in_progress"]),retryAt:n.iso.datetime({offset:!0}).nullable()}),Vt=n.strictObject({experimentId:n.uuid(),splitNodeId:n.string().min(1).max(128)}),Dn=n.strictObject({experimentId:n.uuid(),experimentKey:n.string().min(1).max(128),variationKey:n.string().min(1).max(128),inExperiment:n.boolean(),generation:n.string().min(1).max(256)}),fe=n.strictObject({operation:n.literal("page_experiments"),release:$,usedReceiptIds:n.array(n.uuid()).max(20).default([]),customerToken:n.string().regex(Q).optional()}),dn=n.strictObject({scope:V,runId:n.uuid(),assignments:n.array(Dn.extend({receiptId:n.uuid()})).max(100),payload:cn});var U=n.string().regex(/^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/),mn=n.strictObject({entry:U,nodes:n.array(n.strictObject({id:U,type:n.enum(["entry","screen","condition","split","feature","action","external_page","wait","end","offering","coupon","coupons","output"]),outputs:n.record(n.string(),U),writes:n.record(j,j),resources:n.strictObject({screenId:U.optional(),paywallVersionId:n.uuid().optional(),couponId:n.uuid().optional(),couponIds:n.array(n.uuid()).max(20).optional(),experimentId:n.uuid().optional(),featureKey:n.string().optional(),offeringVersionId:n.uuid().optional()})})).min(1).max(500)}),pn={scope:V,funnelId:n.uuid(),versionId:n.uuid(),evaluationRevision:n.number().int().nonnegative(),expiresAt:n.iso.datetime({offset:!0}).nullable(),topology:mn},X=n.discriminatedUnion("evaluationMode",[n.strictObject({...pn,evaluationMode:n.literal("local"),growth:K,conditions:n.record(U,n.array(n.strictObject({condition:Te,port:n.string()})))}),n.strictObject({...pn,evaluationMode:n.literal("remote")})]),Vn=X.options[0].extend({evaluation:n.strictObject({maxTransitions:n.number().int().min(1).max(1e4),variables:n.record(j,ke),outputSchema:_e,terminals:n.record(U,n.strictObject({outcome:n.enum(["completed","closed","ineligible","failed"]),output:Je.nullable()}))})});function Ln(e){return mn.parse({entry:e.graph.entry,nodes:e.graph.nodes.map(t=>{let u={},r={};switch(t.type){case"entry":case"feature":case"offering":case"coupon":case"coupons":u.next=t.next;break;case"screen":Object.assign(u,t.outputs),r.screenId=t.screenId;{let p=e.screens.find(d=>d.id===t.screenId);p?.type==="paywall"&&(r.paywallVersionId=p.paywallVersionId)}break;case"condition":t.cases.forEach((p,d)=>{u[`case:${d}`]=p.target}),u.default=t.default;break;case"split":Object.assign(u,t.routes),u.notParticipating=t.notParticipating,r.experimentId=t.experimentId;break;case"action":for(let p of["success","cancel","unavailable","failure"])u[p]=t[p];t.action.type==="claim_offer"&&t.action.coupon.source==="literal"&&t.action.coupon.value&&typeof t.action.coupon.value=="object"&&!Array.isArray(t.action.coupon.value)&&(r.couponId=n.uuid().parse(t.action.coupon.value.id));break;case"external_page":u.opened=t.opened,u.failed=t.failed;break;case"wait":t.wait.type==="duration"?u.elapsed=t.wait.elapsed:(u.received=t.wait.received,u.timeout=t.wait.timeout);break;case"end":case"output":break}t.type==="feature"&&(r.featureKey=t.featureKey),t.type==="offering"&&t.configuration.source==="feature"&&(r.featureKey=t.configuration.featureKey);let o=t.type==="output"?t.value:t.type==="end"?t.output:void 0;return o?.type==="feature"&&(r.featureKey=o.featureKey),t.type==="coupon"&&(r.couponId=t.couponId),t.type==="coupons"&&(r.couponIds=t.couponIds),t.type==="offering"&&t.configuration.source==="fixed"&&(r.offeringVersionId=t.configuration.versionId),{id:t.id,type:t.type,outputs:u,resources:r,writes:"writes"in t?t.writes??{}:{}}})})}function ge(e){let t=le.parse(e.document),u=e.evaluationMode==="local"?K.parse(e.payload):null;if(u&&(u.scope.projectId!==e.scope.projectId||u.scope.environment!==e.scope.environment))throw new Error("GB payload belongs to another App or environment");let r={scope:e.scope,funnelId:e.funnelId,versionId:e.versionId,evaluationRevision:e.evaluationRevision,evaluationMode:e.evaluationMode,expiresAt:u?.expiresAt??null,topology:Ln(t)};return X.parse(e.evaluationMode==="remote"?r:{...r,growth:Ze(t,u),conditions:Object.fromEntries(t.graph.nodes.filter(o=>o.type==="condition").map(o=>[o.id,o.cases.map((p,d)=>({condition:p.condition,port:`case:${d}`}))]))})}function $t(e){let t=ge(e);if(t.evaluationMode!=="local")throw new Error("Remote Funnel cannot disclose local rules");let u=le.parse(e.document);return Vn.parse({...t,evaluation:{maxTransitions:u.execution.maxTransitions,variables:u.variables,outputSchema:u.outputSchema,terminals:Object.fromEntries(u.graph.nodes.flatMap(r=>{let o=r.type==="end"?r.output:r.type==="output"?r.value:void 0;return r.type!=="end"&&r.type!=="output"?[]:o&&o.type!=="literal"&&o.type!=="feature"&&o.type!=="variable"?[]:[[r.id,{outcome:r.type==="end"?r.outcome:"completed",output:o??null}]]}))}})}var Ie=32,Mn=522240;function ve(e){if(["entry","condition","feature","split","offering","coupon","coupons"].includes(e.type))return!0;if(e.type!=="end"&&e.type!=="output")return!1;let t=e.type==="end"?e.output:e.value;return t?.type!=="bundle"&&t?.type!=="selection"}var qn=n.strictObject({nodeId:n.string().min(1).max(64),visit:n.number().int().nonnegative(),revision:n.number().int().nonnegative()}),ye=n.record(n.string(),L),jn=n.strictObject({id:n.uuid(),nodeId:n.string().min(1).max(64),visit:n.number().int().nonnegative(),input:n.strictObject({schemaVersion:z.shape.schemaVersion,kind:z.shape.kind,selector:z.shape.selector,contract:z.shape.contract}),context:ye,removed:n.array(n.string()).max(100),attributes:ye,removedAttributes:n.array(n.string()).max(100),result:Ye,offeringVersionId:n.uuid().nullable(),events:n.strictObject({entered:n.string().regex(/^[1-9][0-9]{0,18}$/),decision:n.string().regex(/^[1-9][0-9]{0,18}$/).nullable()})}),Wt=n.strictObject({schemaVersion:n.literal(1),mode:n.enum(["local","remote"]),versionId:n.uuid(),generation:n.number().int().positive(),base:qn,context:ye,steps:n.array(jn).min(1).max(Ie)}).refine(e=>Y(e)<=Mn,"Segment exceeds its byte budget");var Gn=/^(parameters(?:\.|$)|answers(?:\.|$)|results(?:\.|$)|variables(?:\.|$)|funnelParticipantId$)/;function J(e){return Array.isArray(e)?e.some(J):!e||typeof e!="object"?!1:Object.entries(e).some(([t,u])=>t.startsWith("$")?["$and","$or","$nor","$not"].includes(t)&&J(u):!Gn.test(t))}function fn(e,t,u,r){if(e.executionContract!=="funnel-process/1"||r)return null;if(["offering","coupon","coupons"].includes(t.type)||t.type==="action"&&t.action.type!=="event"||t.type==="screen"&&(t.offering||e.screens.some(c=>c.id===t.screenId&&c.type==="paywall")))return"customer_required";let o=t.type==="end"?t.output:t.type==="output"?t.value:void 0;if(o&&["bundle","selection","offering"].includes(o.type)||t.type==="condition"&&t.cases.some(c=>J(c.condition)))return"customer_required";let p=JSON.stringify([t,t.type==="screen"?e.screens.find(c=>c.id===t.screenId):null]);for(let[c,a]of Object.entries(e.variables))if(a.source.type==="attribute"&&a.source.key!=="funnelParticipantId"&&(p.includes(`variables.${c}`)||p.includes(JSON.stringify(c))))return"customer_required";if(t.type==="split"){let c=u.experiments?.[t.experimentId];if((c?.hashAttribute??"id")!=="funnelParticipantId"||J(c?.condition)||c?.parentConditions?.length)return"customer_experiment_required"}let d=t.type==="feature"?t.featureKey:o?.type==="feature"?o.featureKey:void 0;return d&&u.features?.[d]?.rules?.some(c=>(c.hashAttribute??"id")!=="funnelParticipantId"||J(c.condition)||c.parentConditions?.length)?"customer_experiment_required":null}var he=class extends Error{constructor(u,r){super(r);this.code=u;this.name="FunnelLocalCalculationError"}code},ee=(e,t)=>new he(e,t),Un=e=>({experiments:e.experiments,features:e.features});function we(e,t=ee){let u=new Map(e.topology.nodes.map(d=>[d.id,d])),r=Ne(e.growth.savedGroups),o=Un(e.growth);function p(d,c){if(!Object.hasOwn(e.growth.features,d))throw t("INVALID_RESPONSE","Required GB Feature is unavailable");return Oe(d,c).value}return{nodes:u,savedGroups:r,features:o.features,feature:p,evaluate(d,c){let a=u.get(d);if(!a)throw t("NOT_FOUND","Funnel node is unavailable");let i,g;if(a.type==="condition"){let v=e.conditions[a.id];if(!v)throw t("INVALID_RESPONSE","Local condition rules are unavailable");i=de({id:a.id,name:a.id,type:"condition",cases:v.map(h=>({condition:h.condition,target:a.outputs[h.port]})),default:a.outputs.default},c,o.experiments).port}else if(a.type==="feature"){if(!a.resources.featureKey)throw t("INVALID_RESPONSE","Feature reference is unavailable");g=p(a.resources.featureKey,c),i="next"}else if(a.type==="split"){if(!(a.resources.experimentId?e.growth.experiments[a.resources.experimentId]:void 0))throw t("INVALID_RESPONSE","Experiment reference is unavailable");let h=de({id:a.id,name:a.id,type:"split",experimentId:a.resources.experimentId,routes:a.outputs,notParticipating:a.outputs.notParticipating},c,o.experiments);g=h.value,i=h.port}else if(["offering","end","output"].includes(a.type)&&a.resources.featureKey)g=p(a.resources.featureKey,c),i=a.type==="offering"?"next":"value";else throw t("SERVER_REQUIRED","This node is driven by the authoritative Funnel runtime");let y=a.outputs[i]??(i==="value"?a.id:void 0);if(!y)throw t("INVALID_RESPONSE","Evaluated node exit is unavailable");return{nodeId:d,port:i,target:y,...g===void 0?{}:{value:g}}}}}function dr(e,t,u,r=ee){return be(e,r)(t,u)}function be(e,t){let u=X.parse(e);if(u.evaluationMode!=="local")throw t("EVALUATION_MODE","Remote nodes are evaluated by Grow");let r=u.expiresAt?Date.parse(u.expiresAt):null,o=()=>{if(r!==null&&r<=Date.now())throw t("CONFIGURATION_EXPIRED","Refresh local rules at the scheduled transition")};o();let p=we(u,t);return(d,c)=>(o(),Bn(p,d,c))}function Bn(e,t,u){let r=Ae.parse(u.attributes??{}),{saveStickyBucketAssignmentDoc:o,onFeatureUsage:p,onExperimentViewed:d}=u,c={attributes:r,...o?{saveStickyBucketAssignmentDoc:a=>o(structuredClone(a))}:{},...p?{onFeatureUsage:(a,i)=>p(a,structuredClone(i))}:{},...d?{onExperimentViewed:(a,i)=>d(structuredClone(a),structuredClone(i))}:{},features:e.features,savedGroups:e.savedGroups,...u.stickyBucketAssignmentDocs?{stickyBucketAssignmentDocs:structuredClone(u.stickyBucketAssignmentDocs)}:{}};return e.evaluate(t,c)}function pr(e,t,u,r=ee){return gn(be(e,r),t,u)}function gn(e,t,u){let r=[],o=[],p=[],d=e(t,{...u.attributes?{attributes:u.attributes}:{},stickyBucketAssignmentDocs:u.sticky,saveStickyBucketAssignmentDoc(c){let a=r.findIndex(y=>y.next.attributeName===c.attributeName&&y.next.attributeValue===c.attributeValue),i=c.attributeName+"||"+c.attributeValue,g={expected:u.sticky[i]??null,next:c};a<0?r.push(g):r[a]=g},onExperimentViewed(c,a){a.inExperiment&&a.hashUsed&&!a.passthrough&&o.push(L.parse({key:c.key,variationId:a.variationId,keyUsed:a.key,hashAttribute:a.hashAttribute,hashValue:a.hashValue}))},onFeatureUsage(c,a){p.push(L.parse({feature:c,value:a.value,source:a.source,...a.ruleId?{ruleId:a.ruleId}:{}}))}});return{port:d.port,...d.value===void 0?{}:{value:d.value},sticky:r,exposures:o,features:p}}function yn(e,t,u,r=ee){let o=u,p=new Map(t.graph.nodes.map(O=>[O.id,O])),d=structuredClone(u.variables),c=structuredClone(o.sticky),a=[],i=u.nodeId,g=u.visit,y=!1,v,h=O=>fn(t,O,e.evaluationMode==="local"?e.growth:{features:{},experiments:{}},o.attributes.funnelCustomerBound===!0),R=O=>(v??=be(e,r),gn(v,O,{attributes:Be({declarations:t.variables,attributes:o.attributes,parameters:u.parameters,answers:u.answers,results:d,savedGroups:{}}),sticky:c}));for(let O=0;O<Ie;O++){let s=p.get(i);if(!s||!ve(s)||h(s))break;if(g>=t.execution.maxTransitions&&(g>t.execution.maxTransitions||s.type!=="end"&&s.type!=="output")){if(!a.length)throw r("TRANSITION_LIMIT","Local Funnel transition budget exceeded");break}let f,w;if(["condition","feature","split"].includes(s.type)||s.type==="offering"&&s.configuration.source==="feature")f=R(s.id),s.type==="offering"&&(f.value={type:"offering_version",id:String(f.value)}),s.type==="condition"?w=f.port==="default"?s.default:s.cases[Number(f.port.slice(5))]?.target:s.type==="split"?w=f.port==="notParticipating"?s.notParticipating:s.routes[f.port]:(s.type==="feature"||s.type==="offering")&&(w=s.next);else if(f={port:"next",sticky:[],exposures:[],features:[]},(s.type==="entry"||s.type==="coupon"||s.type==="coupons")&&(w=s.next),s.type==="offering"&&s.configuration.source==="fixed"&&(f.value={type:"offering_version",id:s.configuration.versionId},w=s.next),s.type==="end"||s.type==="output"){let x=s.type==="end"?s.output:s.value;if(f=x?.type==="feature"?R(s.id):{...f,port:"value",value:x?.type==="literal"?x.value:x?.type==="variable"?Me({source:"variable",key:x.key,...x.path?{path:x.path}:{}},{declarations:t.variables,answers:u.answers,results:d,parameters:u.parameters,attributes:o.attributes,savedGroups:{}}):null},x&&(f.value===void 0||!De(t.outputSchema,f.value)))throw r("INVALID_RESPONSE","Local terminal violates its declared output")}let N=[...a,{nodeId:i,result:f}];if(Y({steps:N})>6e4){if(!a.length)throw r("INVALID_REQUEST","Local step exceeds its command budget");break}if(a.push({nodeId:i,result:f}),s.type==="feature"||s.type==="offering"||s.type==="coupon"||s.type==="coupons"){let x=s.type==="coupons"?s.couponIds.map(D=>({type:"reward",id:D})):s.type==="coupon"?{type:"reward",id:s.couponId}:f.value;if(x===void 0)throw r("INVALID_RESPONSE","Node output is missing");let _=Ve(s,{value:x});Le(t.variables,s,_),Object.assign(d,_)}for(let x of f.sticky)c[`${x.next.attributeName}||${x.next.attributeValue}`]=structuredClone(x.next);if(s.type==="end"||s.type==="output"){y=!0;break}if(!w)throw r("INVALID_RESPONSE","Local pure exit is unavailable");i=w,g++}let T=p.get(i);return{steps:a,...!y&&T&&(!ve(T)||h(T))?{boundary:{nodeId:i,visit:g}}:{}}}function In(e,t){let u=sn.safeParse(t);if(!u.success)throw new m("INVALID_RESPONSE","Funnel response contract changed");let r=u.data;if(e.scope&&(r.scope.projectId!==e.scope.projectId||r.scope.environment!==e.scope.environment))throw new m("SCOPE_MISMATCH","Funnel scope changed");return r}var xe=(e,t)=>new m(e,t);function hr(e){return we(e,xe)}var Kn=3,zn=2e3;function $n(e){return e instanceof TypeError||e instanceof m&&/^(?:CONFIGURATION_UNAVAILABLE|CONFIGURATION_HTTP_(?:429|5\d\d)|TEMPORARY_UNAVAILABLE)$/i.test(e.code)}async function Jn(e){for(let t=1;;t++)try{return await e.refresh()}catch(u){if(t===Kn||!$n(u))throw u;await new Promise(r=>setTimeout(r,t*zn))}}async function Re(e,t,{predict:u=!0}={}){let r=t.instruction;if(r?.type!=="evaluate_segment")throw new Error("Local segment instruction required");if(!e)throw new m("CONFIGURATION_UNAVAILABLE","Local execution requires public configuration");if(e.scope.environmentId!==r.environmentId)throw new m("SCOPE_MISMATCH","Evaluation environment changed");let o=null,p;if(u)try{let d=await e.funnel(t.source.id,t.source.versionId);p=d.manifest.generation,o=Hn(e,t,d)}catch{o=null}return p??=e.snapshot?.generation??(await Jn(e)).generation,{advance:{policyRevision:r.policyRevision,generation:p},prediction:o}}function Hn(e,t,u){let r=t.instruction;if(r?.type!=="evaluate_segment"||!u.growth||u.control.evaluationMode!=="local"||u.control.evaluationRevision!==r.policyRevision)return null;let{analyticsConfig:o,remoteFeatures:p,...d}=u.growth,c=ge({scope:{projectId:e.scope.projectId,environment:e.scope.environment},funnelId:t.source.id,versionId:t.source.versionId,evaluationMode:"local",evaluationRevision:r.policyRevision,document:u.document,payload:K.parse(d)}),a=Qn(c,u.document,{...t,...r}),i=a.steps.at(-1),g=a.boundary??(i?.result.port==="value"?{nodeId:i.nodeId,visit:t.visit+a.steps.length-1}:null);return g?{runId:t.id,from:{nodeId:t.nodeId,visit:t.visit,revision:t.revision},nodeId:g.nodeId,visit:g.visit,terminal:!a.boundary}:null}function Qn(e,t,u){return yn(e,t,u,xe)}var vn=G.refine(e=>!["start","get","review"].includes(e.operation)&&!("customerToken"in e),"Persist only the original mutation, without credentials").transform(e=>{if(e.operation==="start"||e.operation==="get"||e.operation==="review")throw new m("COMMAND_STORAGE_INVALID","Stored mutation required");return e}),hn=n.strictObject({schemaVersion:n.literal(1),scope:V,runId:n.uuid(),funnelId:n.uuid(),versionId:n.uuid(),processBindingIds:n.record(n.uuid(),n.uuid().nullable()).optional(),command:vn.optional(),closeCommand:vn.refine(e=>e.operation==="close").optional(),purchase:n.strictObject({receiptId:n.uuid(),operationId:n.uuid(),generation:n.number().int().nonnegative()}).optional(),closed:n.literal(!0).optional()}).refine(e=>!e.closeCommand||e.command&&e.command.operation!=="close"&&e.command.requestId!==e.closeCommand.requestId,"Close requires a separate request identity").refine(e=>e.command!==void 0||e.purchase!==void 0,"A recovery record requires an original obligation"),A=()=>new m("COMMAND_STORAGE_CONFLICT","Another host changed this Run's pending command"),ne=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function H(e,t){if(!e||!t)return e;if(e.processBindingIds&&Object.hasOwn(e.processBindingIds,t)){let u={...e.processBindingIds};delete u[t],e={...e,processBindingIds:u}}return e.command?.requestId===t?e.closeCommand?{...e,command:e.closeCommand,closeCommand:void 0}:e.purchase?{...e,command:void 0}:null:e.closeCommand?.requestId===t?{...e,closeCommand:void 0}:e}function wn(e){let t=0,u=null,r=a=>JSON.stringify([a.scope,a.runId,a.funnelId,a.versionId]),o=Promise.resolve();async function p(){let a=await e.read();if(!Number.isSafeInteger(a.revision)||a.revision<0)throw new m("COMMAND_STORAGE_INVALID","Invalid command storage revision");return{revision:a.revision,entry:a.entry===null?null:hn.parse(a.entry)}}function d(a){let i=o.then(a);return o=i.catch(()=>{}),i}async function c(a){for(let i=0;i<4;i++){let g=await p();if(g.entry&&u!==null&&r(g.entry)!==u)throw A();let y=a(g.entry,g.revision);if(ne(g.entry,y)){t=g.revision;return}let v=await e.write(g.revision,y);if(v!==null){if(!Number.isSafeInteger(v)||v<=g.revision)throw A();t=v;return}}throw A()}return{bind(a){let i=JSON.stringify([a.scope,a.runId,a.funnelId,a.versionId]);if(u!==null&&u!==i)throw A();u=i},async load(){let a=await p();return t=a.revision,u=a.entry?r(a.entry):null,a.entry},retain(a){let i=hn.parse(a),g=i.command;return!g||u!==null&&r(i)!==u?Promise.reject(A()):(u??=r(i),d(()=>c((y,v)=>{if(y&&!ne(r(y),r(i)))throw A();if(y&&i.processBindingIds){for(let[h,R]of Object.entries(i.processBindingIds))if(y.processBindingIds&&Object.hasOwn(y.processBindingIds,h)&&y.processBindingIds[h]!==R)throw A();y={...y,processBindingIds:{...y.processBindingIds,...i.processBindingIds}}}if(!y){if(v!==t&&g.operation!=="close")throw A();return i}if(!y.command)return{...y,command:g,...g.operation==="close"?{closed:!0}:{}};if(g.operation==="close"&&y.command.operation!=="close"){if(y.command.requestId===g.requestId||y.closeCommand&&!ne(y.closeCommand,g))throw A();return{...y,closeCommand:g,closed:!0}}if(!ne(y.command,g))throw A();return y})))},observePurchase(a,i,g,y){return d(()=>c((v,h)=>{if(!v&&h!==t||v&&r(v)!==r({...a,schemaVersion:1}))throw A();if(v?.purchase&&v.purchase.generation>i.generation)return H(v,y);if(v?.purchase&&v.purchase.generation===i.generation&&v.purchase.operationId!==i.operationId)throw A();return g?!v?.purchase||v.purchase.operationId!==i.operationId?H(v,y):H(v.command?{...v,purchase:void 0}:null,y):H({schemaVersion:1,...a,...v,purchase:i},y)}))},settle(a){return d(()=>c(i=>H(i,a)))}}}function Tr(e,t){return t.type==="id"?e.customerId===t.value:e.externalUserId===t.value}function te(e,t){if(e===t)return!0;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((o,p)=>te(o,t[p]));if(!e||!t||typeof e!="object"||typeof t!="object")return!1;let u=Object.entries(e),r=Object.entries(t);return u.length===r.length&&u.every(([o,p])=>Object.hasOwn(t,o)&&te(p,Reflect.get(t,o)))}function bn(e,t){let u=t&&{...t},r=null,o=0,p=-1,d=0,c=new AbortController;function a(){d++,c.abort(new m("IDENTITY_CHANGED","Run identity changed")),c=new AbortController}let i=!1,g,y=0,v=new Set;return{get scope(){return u},bindScope(h){if(u&&(u.projectId!==h.projectId||u.environment!==h.environment))throw new m("SCOPE_MISMATCH","Run scope changed");u??={...h}},get view(){return r},get currentView(){return p===d?r:null},get viewAgeMs(){return r&&p===d?performance.now()-o:void 0},get generation(){return d},get signal(){return c.signal},get disposed(){return i},get customerToken(){return g},get readSequence(){return y},nextRead(){return++y},assertCurrent(h,R="Run identity changed during the request"){if(h!==d||i)throw new m("IDENTITY_CHANGED",R)},assertRun(h){if(r&&(h.id!==r.id||h.source.type!==r.source.type||h.source.id!==r.source.id||h.source.versionId!==r.source.versionId||h.locale!==r.locale||!te(h.parameters,r.parameters)))throw new m("INVALID_RESPONSE","Run version changed");if(e&&h.source.id!==e)throw new m("INVALID_RESPONSE","Run belongs to another Funnel")},publish(h,R,T,O,s){if(!(h.operation==="review"&&r&&r!==T&&R.run.revision<=r.revision)&&!(r&&R.run.revision===r.revision&&O!==void 0&&O<y)&&(h.operation==="review"&&!R.run.stopped&&["running","waiting"].includes(R.run.status)&&r&&p===d&&R.run.nodeId===r.nodeId&&R.run.visit===r.visit&&R.run.revision===r.revision&&(R.run.screen=r.screen,(r.paywall?.quote?.operationId===R.review?.activeOperationId||!r.paywall?.quote&&R.review?.activeOperationId===null)&&(R.run.paywall=r.paywall)),!(r?.paywall&&R.run.paywall&&r.paywall.receiptId===R.run.paywall.receiptId&&(R.run.paywall.selectionGeneration??0)<(r.paywall.selectionGeneration??0)))){if(!r||R.run.revision>=r.revision)r=R.run,o=performance.now(),p=d;else if(!s)return;if(r&&p===d)for(let f of v)try{f(structuredClone(r))}catch{}}},identify(h){if(i)throw new m("IDENTITY_CHANGED","Controller was reset");if(!Q.test(h))throw new m("INVALID_TOKEN","Customer credential required");a(),g=h},subscribe(h){return v.add(h),()=>v.delete(h)},reset(){i||(i=!0,a(),g=void 0,r=null,v.clear())}}}var Se=/^gg_sk_[A-Za-z0-9_-]{32,128}$/;function qr(e,t,u="A server API key is required"){if(typeof window<"u")throw new m("SERVER_ONLY",t);if(!Se.test(e))throw new m("INVALID_TOKEN",u)}function jr(e){let t=W(e);return t.identify(e.apiKey),t}function xn(e,t){if(!e)return;let u=t?.execution,r=u?.provider==="merchant"?"merchant":u?.provider==="stripe"?u.executor==="merchant"?"record_only":"indiana":t&&!ae(t)&&["apple","google"].includes(t.provider)?"native":t&&!ae(t)&&t.provider==="stripe"?"indiana":void 0;if(!r||!e.allowed.includes(r))throw new m("EXECUTION_POLICY_REFUSED","The original quote does not permit the declared purchase execution")}function q(e){let{customerToken:t,...u}=e;return u}var Yn=e=>!(e instanceof m&&e.code==="EXECUTION_POLICY_REFUSED")&&(!(e instanceof m)||e.status===void 0||e.status>=500||[401,425].includes(e.status)||e.recovery==="recover_operation");function Rn({journal:e,state:t,call:u,processIdentity:r}){let o=null,p=null,d=!1,c={command:null,close:null},a=new Set,i,g=null,y=e?e.load().then(s=>{if(t.disposed)throw new m("IDENTITY_CHANGED","Controller was reset during command restoration");if(g=s,!s)return;if(r){if([s.command,s.closeCommand].some(w=>w&&!Object.hasOwn(s.processBindingIds??{},w.requestId)))throw new m("COMMAND_STORAGE_INVALID","The original process identity is missing");r.restore(s.processBindingIds??{})}if(t.scope&&(s.scope.projectId!==t.scope.projectId||s.scope.environment!==t.scope.environment))throw new m("SCOPE_MISMATCH","Pending command belongs to another scope");if(i=s.purchase,d=s.closed===!0,!s.command)return;let f=s.command;o=f.operation==="close"?null:f,p=f.operation==="close"?f:s.closeCommand?.operation==="close"?s.closeCommand:null,p&&(d=!0);for(let w of[o,p])w&&a.add(w.requestId)}):Promise.resolve();y.catch(()=>{});async function v(s,f){e&&await y;let w=t.generation;if(e){if(!t.view||!t.scope)throw new m("COMMAND_STORAGE_INVALID","Read the original scoped Run before persisting a mutation");await e.retain({schemaVersion:1,scope:t.scope,runId:t.view.id,funnelId:t.view.source.id,versionId:t.view.source.versionId,command:q(s),...r?{processBindingIds:{[s.requestId]:r.binding(s.requestId)}}:{}})}if(w!==t.generation||o!==s&&p!==s)throw new m("IDENTITY_CHANGED","Run changed before command dispatch");if(e&&on(f),t.assertCurrent(w),o!==s&&p!==s)throw new m("IDENTITY_CHANGED","Run changed before command dispatch");let N=a.has(s.requestId);a.add(s.requestId);try{return await u(s)}catch(x){let _=s.operation==="submit"&&s.input.type==="paywall_quote",D=!N&&!Yn(x),l=!1;if(_&&D&&w===t.generation&&o===s&&x instanceof m&&x.status!==void 0){let I=await T(s.requestId).catch(()=>{});l=I?.settlement?.state==="unknown"&&I.settlement.operationId===null}throw w===t.generation&&(o===s||p===s)&&D&&(!_||!(x instanceof m)||x.status===void 0||l)&&(e&&await e.settle(s.requestId),w===t.generation&&O(s)),x}}function h(s,f){let w=G.parse(s);if(w.operation==="start"||w.operation==="get"||w.operation==="review")throw new m("INVALID_REQUEST","Mutation required");if(d&&w.operation!=="close"){if(o?.requestId===w.requestId)return T(w.requestId);throw new m("COMMAND_PENDING","Close preserves the original recovery record; settle it by identity")}if(w.operation==="close"){if(o?.requestId===w.requestId)throw new m("INVALID_REQUEST","Close requires its own request identity");if(d=!0,p&&JSON.stringify(q(p))!==JSON.stringify(q(w)))throw new m("COMMAND_PENDING","Retry the original Close");return p??=w,c.close?c.close:R(p,"close",f)}if(o){if(JSON.stringify(q(o))!==JSON.stringify(q(w)))throw new m("COMMAND_PENDING","Retry the original command before sending another");if(c.command)return c.command}else o=w;return R(o,"command",f)}function R(s,f,w){let N=v(s,w);c[f]=N;let x=()=>{c[f]===N&&(c[f]=null)};return N.then(x,x),N}function T(s){return u({operation:"get",settlementRequestId:s})}function O(s){return!s||o!==s&&p!==s?!1:(o===s&&(o=null),p===s&&(p=null),a.delete(s.requestId),!o&&!p&&(g=null),!0)}return{ready:y,get pending(){return o},get closing(){return p},get closeRequested(){return d},get inFlight(){return c.command},get closeFlight(){return c.close},get purchase(){return i},assertBinding(s){if(g&&(s.run.id!==g.runId||s.run.source.id!==g.funnelId||s.run.source.versionId!==g.versionId))throw new m("SCOPE_MISMATCH","Stored command belongs to another Run or Version")},async observe(s,f,w,N){let x=s.operation==="get"?s.settlementRequestId:"requestId"in s&&s.operation!=="start"?s.requestId:void 0,_=x&&f.settlement?.state==="settled"&&f.run.pendingRequest?.requestId!==x&&(s.operation==="get"||!d||s.operation==="close"||!["running","waiting"].includes(f.run.status))?x:void 0,D=o?.requestId===_?o:p?.requestId===_?p:void 0;e?.bind({scope:f.scope,runId:f.run.id,funnelId:f.run.source.id,versionId:f.run.source.versionId});let l=f.run.paywall,I=l??f.purchase,C=I?.operation,E=f.settlement&&(!l||l.purchaseRequestId===f.settlement.requestId)&&(!i||i.operationId===f.settlement.operationId)?f.settlement:void 0,S=C?.operationId??I?.quote?.operationId??E?.operationId,F=I?.receiptId??E?.receiptId,b=l?.selectionGeneration??i?.generation??0;if(e&&S&&F&&s.operation!=="review"&&(!t.view||f.run.revision>=t.view.revision)&&(N===void 0||N>=t.readSequence)&&(!i||b>=i.generation)){let P={receiptId:F,operationId:S,generation:b},k=rn(C,I?.canReselect===!0);await e.observePurchase({scope:f.scope,runId:f.run.id,funnelId:f.run.source.id,versionId:f.run.source.versionId},P,k,_),t.assertCurrent(w),(!i||P.generation>=i.generation)&&(N===void 0||N>=t.readSequence)&&(k?i?.operationId===P.operationId&&(i=void 0):i=P)}else e&&_&&await e.settle(_);return t.assertCurrent(w),_?O(D):!1},stop(){d=!0},submit:h,settle:T,reset(){d=!0,o=null,p=null,i=void 0,g=null,c.close=null,a.clear(),c.command=null}}}function Zn(e){e={...e};let t=e.initialResponse;delete e.initialResponse;let u=e.funnelExecutionPolicy&&structuredClone(e.funnelExecutionPolicy);if(!e.customerRun&&(typeof e.runToken!="string"||!/^gg_fr_[A-Za-z0-9_-]{43}$/.test(e.runToken)))throw new m("INVALID_TOKEN","Run credential required");if(e.customerRun&&(!e.session||!e.scope||!e.funnelId||!e.funnelCommandStorage||e.serverKey))throw new m("INVALID_REQUEST","Customer recovery requires its scoped session and durable journal");if(e.serverKey&&(typeof window<"u"||!Se.test(e.serverKey)))throw new m("SERVER_ONLY","Run Server-Key proof belongs to the merchant backend");if(e.serverKey&&e.session)throw new m("INVALID_REQUEST","Choose Customer session or Server-Key proof for this Run");let r=W({...e,session:void 0,timeoutMs:e.timeoutMs??35e3}),o=bn(e.funnelId,e.scope??e.configuration?.scope),p=e.session?.subscribeIdentity(R),d=null,c=e.funnelCommandStorage??(!e.customerRun&&typeof window<"u"&&window.isSecureContext?an(e):void 0),a=c&&wn(c),i=Rn({journal:a,state:o,call:T,processIdentity:e.process}),g=0,y=new Map;function v(){g++,y.clear(),t=void 0}async function h(l){let I=l.operation==="resume"?i.pending?.operation==="resume"?null:i.pending:l;if(u&&l.operation==="resume"&&!I&&l.requestId!==e.customerRun?.startRequestId)throw new m("EXECUTION_POLICY_REFUSED","The original command is required to verify execution permission before resuming");if(I?.operation==="submit"&&I.input.type==="paywall_confirm"){let P=o.view?.paywall;xn(u,P?.quote?.operationId===I.input.operationId?P.quote:void 0)}if(e.process)return e.process.request(l);let C=o.generation;o.assertCurrent(C);let E=performance.now()+(e.timeoutMs??35e3),S=o.customerToken??("customerToken"in l?l.customerToken:void 0);if(e.session){let P=o.signal,k,B=()=>{},Sn=new Promise((Wn,Fe)=>{B=()=>Fe(P.reason),P.addEventListener("abort",B,{once:!0}),k=setTimeout(()=>Fe(new m("TIMEOUT","The request timed out")),Math.max(1,E-performance.now()))});try{S=await Promise.race([Promise.resolve().then(()=>(o.assertCurrent(C),e.session.access())),Sn])}finally{clearTimeout(k),P.removeEventListener("abort",B)}}o.assertCurrent(C);let F={...l,...S?{customerToken:S}:{}},b=l.operation==="page_experiments"?fe.parse(F):G.parse(F);if(e.customerRun){if(e.session?.snapshot()?.customerId!==e.customerRun.customerId||!S)throw new m("IDENTITY_CHANGED","Original recovery Customer changed");let P={...b};return"customerToken"in P&&delete P.customerToken,r.requestWithCredential("funnels",{operation:"run_command",runId:e.customerRun.runId,funnelId:e.funnelId,command:P},S,{timeoutMs:Math.max(1,E-performance.now())})}return r.requestWithCredential("funnels",b,e.runToken,{headers:e.serverKey&&!S?{[ln]:e.serverKey}:void 0,timeoutMs:Math.max(1,E-performance.now())})}function R(){v(),p?.(),o.reset(),i.reset(),d=null,r.dispose()}async function T(l,I){let C=t;t=void 0;let E=o.generation,S=()=>o.assertCurrent(E);a&&await i.ready,S();let F=o.view,b=In(e,C!==void 0&&l.operation==="get"&&!l.data&&!l.purchase&&!l.settlementRequestId?C:await h(l));if(l.operation==="review"&&!b.review)throw new m("INVALID_RESPONSE","Historical projection is missing");if(e.customerRun&&b.run.id!==e.customerRun.runId)throw new m("INVALID_RESPONSE","Original recovery Run changed");if(l.operation==="get"&&l.purchase&&b.purchase&&(b.purchase.receiptId!==l.purchase.receiptId||(b.purchase.operation?.operationId??b.purchase.quote?.operationId)!==l.purchase.operationId))throw new m("INVALID_RESPONSE","The requested original purchase changed");if(S(),b.runToken&&b.runToken!==e.runToken)throw new m("INVALID_RESPONSE","Run credential changed");let P=l.operation==="get"?l.settlementRequestId:"requestId"in l&&l.operation!=="start"?l.requestId:void 0;if(P&&b.settlement?.requestId!==P)throw new m("INVALID_RESPONSE","Exact command settlement is missing or belongs to another command");i.assertBinding(b),o.assertRun(b.run),o.bindScope(b.scope);let k=await i.observe(l,b,E,I);return(!o.view||b.run.revision>=o.view.revision)&&(I===void 0||I>=o.readSequence)&&(await e.onAcceptedResponse?.(b),S()),!b.run.stopped&&["running","waiting"].includes(b.run.status)&&l.operation==="get"&&l.settlementRequestId||(S(),["running","waiting"].includes(b.run.status)||i.stop(),o.publish(l,b,F,I,k)),b}function O(l){let I=o.generation;v();let C=l(),E=()=>{o.generation===I&&v()};return C.then(E,E),C}let s=(l,I)=>O(()=>i.submit(l,I)),f=null,w=new WeakMap;function N(l){let I=w.get(l);if(I)return I;let C=_(l);return w.set(l,C),C}let x=!1;async function _(l){let I=await l;if(I.run.instruction?.type!=="evaluate_segment")return I;if(f)return f;x=!0;let C=o.generation,E=(async()=>{for(let S=0;S<32&&I.run.instruction?.type==="evaluate_segment";S++){if(i.pending||i.closeRequested)return I;let F=I.run;if(I.run.instruction?.type==="evaluate_segment"){let{advance:P}=await Re(e.configuration,F,{predict:!1});if(C!==o.generation)throw new m("IDENTITY_CHANGED","Run identity changed during segment calculation");if(i.pending||i.closeRequested)return I;if(o.view&&(o.view.revision!==F.revision||o.view.visit!==F.visit||o.view.nodeId!==F.nodeId))return T({operation:"get"});let k=!0;Re(e.configuration,F).then(({prediction:B})=>{k&&C===o.generation&&!i.closeRequested&&o.view?.id===F.id&&!o.view.stopped&&o.view.nodeId===F.nodeId&&o.view.visit===F.visit&&o.view.revision===F.revision&&(d=B)}).catch(()=>{});try{I=await s({operation:"commit_segment",requestId:Xe(F.id,F.visit,`segment:${F.revision}`),nodeId:F.nodeId,visit:F.visit,revision:F.revision,...P})}finally{k=!1,d=null}}}return I})();f=E;try{return await E}finally{f===E&&(f=null)}}let D={get configuration(){return x?e.configuration:void 0},get configurationReady(){return!0},get view(){let l=o.currentView;return l?structuredClone(l):null},get viewAgeMs(){return o.viewAgeMs},get pendingCommand(){let l=i.closing??i.pending;return l?structuredClone(q(l)):null},get pendingCommands(){return[i.pending,i.closing].filter(l=>l!==null).map(l=>structuredClone(q(l)))},get pendingPurchase(){return i.purchase?structuredClone(i.purchase):null},get hasDurableJournal(){return a!==void 0},get prediction(){let l=o.view;return d&&l&&!l.stopped&&["running","waiting"].includes(l.status)&&l.id===d.runId&&l.nodeId===d.from.nodeId&&l.visit===d.from.visit&&l.revision===d.from.revision&&!i.closeRequested?structuredClone(d):null},settle:(...l)=>O(()=>i.settle(...l)),get webViewUrl(){return"bundled"},resolvePaywall(l){return nn(e,l)},async pageExperiments(l,I=[]){let C=o.generation;o.assertCurrent(C);let E=o.view?.id;if(!E)throw new m("INVALID_REQUEST","Read the Run before its page experiments");let S=dn.parse(await h(fe.parse({operation:"page_experiments",release:l,usedReceiptIds:I})));if(o.assertCurrent(C),S.runId!==E||S.scope.projectId!==o.scope?.projectId||S.scope.environment!==o.scope?.environment)throw new m("SCOPE_MISMATCH","Page experiment Run changed");return S},review(l){return T({operation:"review",...l?{receiptId:l}:{}},o.nextRead())},async get(l,I){let C=o.generation;l=l&&structuredClone(l),I=I&&{...I},a&&await i.ready,o.assertCurrent(C),I??=i.purchase&&{receiptId:i.purchase.receiptId,operationId:i.purchase.operationId};let E=JSON.stringify([o.generation,g,l??null,I??null]),S=y.get(E);if(S)return S.then(k=>structuredClone(k));let F=o.nextRead(),b=N(T({operation:"get",...l?{data:l}:{},...I?{purchase:I}:{}},F));y.set(E,b);let P=()=>{y.get(E)===b&&y.delete(E)};return b.then(P,P),b.then(k=>structuredClone(k))},resume(l=o.view?.pendingRequest?.requestId){return l?i.closeRequested?D.settle(l):i.pending?.requestId===l?N(s(i.pending)):N(s({operation:"resume",requestId:l})):Promise.reject(new m("INVALID_REQUEST","No interrupted command is available"))},submit(l){return N(s(l))},async retry(){if(i.closeFlight)return i.closeFlight;if(i.closing)return s(i.closing);if(i.closeRequested&&i.pending)return D.settle(i.pending.requestId);if(i.inFlight)return N(i.inFlight);if(!i.pending)throw new m("INVALID_REQUEST","No command is pending");let l=i.pending;if(l.operation==="submit"&&l.input.type==="paywall_quote"){let I=o.generation;if(await D.settle(l.requestId),o.assertCurrent(I),!i.pending)return D.get();if(i.pending!==l||i.closeRequested)throw new m("COMMAND_PENDING","The original quote is being recovered")}return N(s(l))},identify(l){let I=o.customerToken?void 0:t;v(),o.identify(l),t=I,d=null,r.reset()},get identitySignal(){return o.signal},subscribe:o.subscribe,reset:R};return tn(D,(l,I)=>N(s(l,I))),D}function po(e,t){return Zn({...e,runToken:"",initialResponse:t})}export{un as a,Cn as b,pe as c,On as d,sn as e,kn as f,_t as g,kt as h,Dt as i,fe as j,dn as k,X as l,Vn as m,$t as n,dr as o,pr as p,In as q,xe as r,hr as s,Qn as t,hn as u,H as v,an as w,Fn as x,Tr as y,te as z,Se as A,qr as B,jr as C,xn as D,Zn as E,po as F};
@@ -1 +0,0 @@
1
- import{i as ie}from"./chunk-CWBBW6QS.js";import{a as Z,c as ee,e as te,f as ne,i as N,k as re,l as oe,m as se}from"./chunk-57ZXT7AS.js";import{b as X}from"./chunk-NNJ7W4KY.js";import{r as V}from"./chunk-ECUGL7AO.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import{o as Y,p as K}from"./chunk-JW4MSBYN.js";import{A as G}from"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import{c as $,d as R}from"./chunk-LUVTP4VU.js";import{a as p}from"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-S7NHVERO.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var z=new WeakMap;function ce(s){let t={string:u.string(),number:u.number().finite(),boolean:u.boolean(),strings:u.array(u.string()),json:R}[s.type];return s.nullable?t.nullable():t}function ae(s,t){let f=u.record(u.string(),R).parse(s);if(Object.keys(f).length>40)throw new p("INVALID_REQUEST","Too many content inputs");for(let[m,r]of Object.entries(f))Y.parse({[m]:r});if(Object.keys(f).some(m=>!Object.hasOwn(t.inputs,m)))throw new p("INVALID_REQUEST","Undeclared content input");for(let[m,r]of Object.entries(t.inputs))if(Object.hasOwn(f,m))ce(r).parse(f[m]);else if(r.required)throw new p("INVALID_REQUEST",`Missing content input ${m}`);return f}async function Ae(s,t){return le(s,t,!1)}async function Se(s,t){return le(s,t,!0)}async function le(s,t,f){t.signal?.throwIfAborted();let m=X.parse(t.content),r=m.document;if(t.closeControl==="content"&&!r.screen.actions.some(e=>e.type==="event"&&e.close))throw new p("INVALID_REQUEST","An authored Close control requires a declared Close action");if(z.has(s))throw new p("CONFLICT","Content is already mounted in this container");let y=ae(t.inputs??{},r.contract),T=new Set(u.array(u.string()).max(40).parse(t.mutableInputs??[]));if(T.size!==(t.mutableInputs?.length??0)||[...T].some(e=>!Object.hasOwn(r.contract.inputs,e)))throw new p("INVALID_REQUEST","Mutable content inputs must name unique declared inputs");for(let e of Object.keys(r.contract.outputs))if(typeof t.actions[e]!="function")throw new p("INVALID_REQUEST",`Missing host handler for ${e}`);let M=K.parse(t.bindings??[]),d=s.ownerDocument,ue=s.clientHeight||d.defaultView?.innerHeight||800,P,w,a,_,x=r.kind==="popup",n=x?d.createElement("dialog"):null,c=d.createElement("div");if(c.dataset.indianaContent=r.kind,c.setAttribute("aria-label",r.name),c.style.cssText="width:100%;min-width:0",n){n.setAttribute("aria-label",r.name);let e=r.screen.presentation;n.style.cssText="box-sizing:border-box;padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto",e.type==="modal"||e.type==="sheet"?(n.style.width=`${$[e.size]}px`,e.type==="sheet"&&(n.style.margin="auto auto 0")):n.style.width="100vw",a=ee(n,r.screen,()=>{w?.resizeViewport(d.defaultView?.innerHeight||800,d.defaultView?.innerWidth||1024)}),n.append(c),s.append(n)}else s.append(c);let i=!1,A=!1,E=!1,S=!1,de=n?oe(n):se(c,s),D=re(s,t,r.kind,()=>{k()&&(b(),h(t.onDismiss))}),q,H,L=new Promise((e,o)=>{q=e,H=o});L.catch(()=>{});let g=null,I=structuredClone(r.screen),W=G(I,[t.locale,...d.defaultView?.navigator.languages??[]]),j=t.capabilities;I.actions=I.actions.map(e=>e.type==="event"?{...e,close:!1}:e);function b(){i||(i=!0,t.signal?.removeEventListener("abort",b),D.finish("dismissed"),H(new Error("Content preparation cancelled")),a?.destroy(),_?.(),w?.destroy(),n?.close(),n?.remove(),c.remove(),z.delete(s),n&&P?.())}let v=()=>{!E||!k()||(b(),h(t.onDismiss))};function k(){try{return t.canDismiss?.()!==!1}catch(e){return h(t.onError,e),!1}}if(n&&t.closeControl!=="content"){let e=d.createElement("button");e.type="button",e.textContent="×",e.setAttribute("aria-label",t.locale?.startsWith("zh")?"关闭":"Close"),ne(e,r.screen.theme),e.addEventListener("click",v),n.prepend(e)}n&&a?.responsive&&(_=Z(n,v,k,t.locale?.startsWith("zh")?"关闭":"Close"),n.addEventListener("click",e=>{if(e.target!==n)return;let o=n.getBoundingClientRect();(e.clientX<o.left||e.clientX>o.right||e.clientY<o.top||e.clientY>o.bottom)&&v()})),n?.addEventListener("cancel",e=>{e.preventDefault(),v()}),n?.addEventListener("keydown",e=>{e.key==="Escape"&&(e.preventDefault(),v())});async function F(){if(i||!E||A||!g)return;let e=g;A=!0,c.setAttribute("aria-busy","true");try{await t.actions[e.actionId](structuredClone(e)),g=null}catch(o){i||h(t.onError,o)}finally{A=!1,i||c.removeAttribute("aria-busy")}}function J(){if(i)throw new p("CONFLICT","Content host has been destroyed");E||!S||(P??=N(d),D.present(e=>{de(),n&&(a?.latch(),n.showModal(),a?.responsive&&n.focus({preventScroll:!0}),!e&&t.loading!=="host"&&te(n,a?.type??r.screen.presentation.type,a?.responsive)),E=!0}))}function U(e){D.finish("error",e),H(e instanceof Error?e:new Error(String(e))),b()}let Q={destroy:b,show:J,get pendingAction(){return g?structuredClone(g):null},retryAction:F,updateInputs(e){if(i)throw new p("CONFLICT","Content host has been destroyed");let o=u.record(u.string(),R).parse(e),C=ae({...y,...o},r.contract);for(let l of Object.keys(o))if(!T.has(l)&&(!Object.hasOwn(y,l)||V(y[l])!==V(C[l])))throw new p("PRECONDITION_FAILED","This content input is frozen; prepare a new presentation");V(y)!==V(C)&&(w?.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:C}}),y=C)},updateCapabilities(e){if(i)return;let o=structuredClone(e);w?.updateCapabilities(o),j=o}};z.set(s,Q),t.signal?.addEventListener("abort",b,{once:!0});try{if(t.signal?.throwIfAborted(),f||(P=N(d),D.start(x,t.locale??r.screen.strings.defaultLocale),i&&await L),w=ie(c,{mode:"live",rendererUrl:t.rendererUrl,title:r.name,viewportHeight:r.kind==="page"?ue:a?.responsive?d.defaultView?.innerHeight||800:void 0,...a?.responsive?{viewportWidth:d.defaultView?.innerWidth||1024,hostPresentation:()=>a.type}:{},onResize:e=>{i||a?.responsive&&(c.style.height=`${e}px`,c.style.overflow="clip",a.setContentHeight(e))},onRendered:e=>{if(!i&&(e&&n?.setAttribute("aria-label",e),!S))try{S=!0,f||J(),q()}catch(o){U(o),h(t.onError,o)}},onError:e=>{if(i)return;let o=new Error(e);S||U(o),h(t.onError,o)},onEscape:x?v:void 0,onAction:(e,o,C)=>{if(i||!E||A||g)return;let l=r.screen.actions.find(O=>O.id===e),B=r.contract.outputs[e];if(!(l?.type!=="event"||!B)&&!(l.close&&!k()))try{let O=ce(B).parse(Object.hasOwn(l.properties,"value")?l.properties.value:l.properties);g=structuredClone({requestId:crypto.randomUUID(),contentVersionId:m.id,actionId:e,event:l.event,value:O,selection:o??{},answers:C??{},requestedClose:l.close}),F()}catch(O){h(t.onError,O)}}}),w.update(I,W,{capabilities:j,serverInput:{bindings:M,answers:{},values:y}}),await Promise.race([w.ready,L]),f&&await L,i)throw new Error("Content preparation cancelled");return Q}catch(e){throw U(e),e}}export{Ae as mountContent,Se as prepareContent};
@@ -1 +0,0 @@
1
- import{b as ne}from"./chunk-F5ABUGHD.js";import{b as j}from"./chunk-5U7LC2NL.js";import{a as re}from"./chunk-JAH62B6J.js";import"./chunk-VMYLTNDS.js";import{a as V}from"./chunk-6GY2YT3U.js";import"./chunk-2ZMIM4MO.js";import"./chunk-RMR64P6V.js";import{b as te}from"./chunk-5MOJUGMA.js";import"./chunk-45PGU2HW.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import{j as S,k as z}from"./chunk-57ZXT7AS.js";import"./chunk-NEW77IDA.js";import"./chunk-YDPF2ZZW.js";import"./chunk-UIR5CBCC.js";import"./chunk-EQ64JD4L.js";import"./chunk-T5SCW4IA.js";import"./chunk-LBYMDTGD.js";import"./chunk-CQ5EQNQA.js";import"./chunk-ST7XO45I.js";import"./chunk-ULED3B5P.js";import"./chunk-ECUGL7AO.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-DXNTXCSI.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import{a as C}from"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import"./chunk-S7NHVERO.js";import{a as h}from"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";var k=new WeakMap,_=new WeakMap,B=new WeakSet;function me(D,e){let P=e.hostPaywallTarget?void 0:e.prepared,J=()=>{e.prepared&&!B.has(e.prepared)&&j(e.prepared)?.release()},K=k.get(e.client);if(K)return J(),K;let Q=n=>({...n,requestId:n.requestId??crypto.randomUUID()}),A=e.allowNewPurchase!==!1&&e.start instanceof Promise?e.start:void 0,w=e.allowNewPurchase===!1||!e.start||e.start instanceof Promise?void 0:Q(e.start);w&&P?.state==="ready"&&P.matches(w)&&P.open();let f=P&&(w&&(P.state==="preparing"||["shown","closed"].includes(P.state)&&P.matches(w))||A&&["preparing","ready"].includes(P.state))?P:void 0;f?B.add(f):J();let y=f&&j(f);y?.claim();let O=Promise.resolve().then(async()=>{let n=!1,c,g=!1,U,p=0,E,q,X=!1,F=()=>{},Y=()=>{},H,L=!1,M=!1,I,Z=!1,a=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,v=()=>{k.get(e.client)===O&&k.delete(e.client),a.removeEventListener("abort",R),F(),Y(),f&&B.delete(f),y?.release()};function $(){if(I)return I;let t=new Promise(o=>I=o);return _.set(e.client,t),t.then(()=>{_.get(e.client)===t&&_.delete(e.client)}),k.get(e.client)===O&&k.delete(e.client),I}let l=z(D,e,"funnel",()=>b(),V);function R(){b()}function b(t=!1){if(!n){if(n=!0,l.finish("dismissed"),c){c.destroy();return}if(t&&H){let o=$();Z=!0,H.then(async i=>{i.mode==="run"&&i.status!=="blocked"&&e.client.controller&&e.client.attempt?.requestId===w?.requestId&&await e.client.close()}).catch(()=>{}).finally(()=>{o(),h(e.onDismiss,null)}),v();return}v(),h(e.onDismiss,null)}}let N={destroy:()=>b(),refresh:()=>E??(g?G():c?.refresh())??Promise.resolve(),get recovery(){return c?.recovery??{type:"recover",operationId:null,requestId:null}},prepareFallback:()=>c?.prepareFallback()??Promise.resolve({type:"recover",operationId:null,requestId:null}),review:(...t)=>c?.review(...t)??Promise.resolve(),exitReview:(...t)=>c?.exitReview(...t)??Promise.resolve(),get unappliedDrafts(){return c?.unappliedDrafts??new Map}};a.addEventListener("abort",R,{once:!0}),y&&(Y=y.onClose(()=>{L?n||$():b(!0)}));try{a.throwIfAborted();let t=e.client.controller?.view?.paywall?.resolution,o=t&&"document"in t?t.document:e.loadingDocument;l.start(!0,w?.locale??e.client.attempt?.locale??o?.screen.strings.defaultLocale,o??null);let i=A?l.wait(A.then(r=>r?Q(r):null,()=>null),S):Promise.resolve(w??null);i.catch(()=>{}),f?.state==="shown"?(M=!0,l.present(()=>{})):f&&["preparing","ready"].includes(f.state)&&Promise.all([f.ready,i.catch(()=>null)]).then(([r,s])=>{if(r){if(n||!l.active||!s||!f.matches(s)||!y?.revealable)return y?.release();l.present(()=>{f.open()==="shown"?M=!0:y.release()})}});let d=_.get(e.client);if(d&&await l.wait(d),n)return null;if(a.throwIfAborted(),A){let r=await i;if(n)return null;if(a.throwIfAborted(),!r)return l.finish("skipped"),v(),null;w=r}H=w?e.client.start(w):e.client.refresh({reuseRecentRead:!0});let u=await l.wait(H,S);return n?null:(a.throwIfAborted(),await ee(u,l))}catch(t){if(Z||I?.(),n)return null;throw l.finish("error",t),v(),h(e.onError,t),t}function x(t=!1){p++;let o=c;c=void 0,F(),F=()=>{};let i=t?o?.retainPurchaseDialog?.():void 0;return o?.destroy(),a.addEventListener("abort",R,{once:!0}),i}function T(t){g=!0;let o=e.client.attempt?.locale??w?.locale,i=o?.startsWith("zh"),d=t?i?"正在查询原订单…":"Checking your purchase…":i?"暂时无法确认原订单,请重试。":"Could not check your original purchase. Try again.",u=t?void 0:()=>{G()};c?.setPurchaseRecovery?.(d,u)||(c&&x(),l.active||(l=z(D,e,"funnel",()=>b(),V),l.start(!0,o,e.loadingDocument??null)),l.setPurchaseRecovery(d,u))}function G(){if(E)return E;if(n||a.aborted)return Promise.resolve();U??=c?.recoveryPaywall,a.addEventListener("abort",R,{once:!0}),T(!0);let t=Promise.resolve().then(async()=>{try{let i=await l.wait(e.client.refresh(),S);!n&&!a.aborted&&await ee(i,l)}catch(i){!n&&!a.aborted&&(h(e.onError,i),T(!1))}});E=t;let o=()=>{E===t&&(E=void 0)};return t.then(o,o),t}async function ee(t,o){let i=e.client.controller;if(t.mode==="run"&&t.status!=="blocked"&&i)return g&&c&&x(),g=!1,U=void 0,ae(i,o?.active?o:void 0);if(t.mode==="operation"&&t.purchases.length){T(!0);let d=await l.wait(e.client.recoverPurchasePaywall(U).then(u=>((n||a.aborted)&&u?.destroy(),u)),S).catch(u=>(!n&&!a.aborted&&h(e.onError,u),null));if(n||a.aborted)return null;if(d){if(n||a.aborted)return d.destroy(),null;let u=x(!0)??y?.retainPurchaseDialog?.()??l.retainPurchaseDialog();y?.release();let r=await re(D,{signal:a,loading:"host",start:async()=>d,checkoutNavigation:"after_confirmation",allowNewPurchase:!1,resumeCheckout:m=>e.client.continueCheckout(W,m),onError:e.onError,onDismiss:()=>{n||b()}},{retainedDialog:u,present(m){l.active?l.present(m):m(!!u)},async dismiss(){b()}});if(!r.host||n||a.aborted)return r.host?.destroy(),u?.release(),v(),null;let s=r.host;return g=!1,c={destroy(){s.destroy(),v(),h(e.onDismiss,null)},refresh:async()=>{await s.refresh()},get recovery(){return s.recovery},prepareFallback:()=>s.prepareFallback(),review:async()=>{},exitReview:async()=>{},unappliedDrafts:new Map},N}}return t.purchases.length||g?(T(!1),N):(l.finish("skipped"),v(),(M||L)&&(n=!0,h(e.onDismiss,null)),null)}function W(t){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");return e.onCheckoutUrl?e.onCheckoutUrl(t):D.ownerDocument.defaultView?.location.assign(t)}async function ae(t,o){a.removeEventListener("abort",R),L=!0;function i(){!n&&!a.aborted&&!g&&!X&&q&&e.client.recovery.status==="complete"&&(X=!0,h(e.onComplete,structuredClone(q)))}F(),F=e.client.subscribe(i);let d=++p,u=await ne(D,{...e,prepared:f,client:t,signal:a,checkoutNavigation:"after_confirmation",resumeCheckout:r=>e.client.continueCheckout(W,r),terminateCheckout:e.allowNewPurchase===!1?void 0:r=>e.client.terminateCheckout(r),async onCheckoutUrl(r){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let s=e.client.recovery;if((!s.actions.includes("continue_checkout")||!s.purchases.some(m=>m.type==="checkout"&&m.checkoutUrl===r))&&(s=await e.client.refresh(),a.throwIfAborted(),n))throw new DOMException("Presentation dismissed","AbortError");if(te(s)!==r)throw new C("PURCHASE_PENDING","Checkout differs from the original recovery proof");return W(r)},async resolveOfferId(r){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let s=e.client.attempt;if(!s)throw new C("PURCHASE_PENDING","Read the original Start before selecting an offer");let m=await e.resolveOfferId?.(r,s);if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==s.requestId)throw new C("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return m},async resolveSubscriptionChange(r,...s){a.throwIfAborted();let m=e.client.attempt;if(n||!m)throw new C("PURCHASE_PENDING","Read the original Start before selecting a membership");let le=e.resolveSubscriptionChange?await e.resolveSubscriptionChange(r,...s):await s[0]?.();if(a.throwIfAborted(),n||e.client.attempt?.requestId!==m.requestId)throw new C("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting a membership");return le},onPresentationState(r){d===p&&h(e.onPresentationState,r)},onComplete(r){d===p&&(q=r,i())},onError(r){d===p&&(h(e.onError,r),r instanceof C&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED"&&r.recovery==="recover_operation")&&!a.aborted&&G().catch(s=>h(e.onError,s)))},onDismiss(r){d===p&&(n=!0,v(),I?.(),h(e.onDismiss,r))}},o);return d!==p||n||a.aborted?(u.destroy(),n||a.aborted?null:N):(c=u,N)}});return k.set(e.client,O),O}export{me as showFunnelPurchase};
@@ -1 +0,0 @@
1
- import{a,b,c}from"./chunk-5U7LC2NL.js";import"./chunk-2ZMIM4MO.js";import"./chunk-RMR64P6V.js";import"./chunk-CQ5EQNQA.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-DXNTXCSI.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-KJTHMRSH.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-S7NHVERO.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as PRERENDER_MAX_AGE_MS,b as preparedInternals,c as prerenderFunnelPurchase};
@@ -1 +0,0 @@
1
- import{a,b,c}from"./chunk-2ZMIM4MO.js";import"./chunk-RMR64P6V.js";import"./chunk-DXNTXCSI.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-LUVTP4VU.js";import"./chunk-S7NHVERO.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as predictFunnelStart,c as predictedPaywallLoadingDocument,b as predictionRefusal};
@@ -1 +0,0 @@
1
- import{a as e,b as o,c as n}from"./chunk-RMR64P6V.js";import"./chunk-DXNTXCSI.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-LUVTP4VU.js";import"./chunk-S7NHVERO.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{e as FUNNEL_ROUTE_LIMITS,o as funnelRouteSchema,n as projectFunnelRoute};
@@ -1 +0,0 @@
1
- import{a,b}from"./chunk-F5ABUGHD.js";import"./chunk-5U7LC2NL.js";import"./chunk-VMYLTNDS.js";import"./chunk-6GY2YT3U.js";import"./chunk-2ZMIM4MO.js";import"./chunk-RMR64P6V.js";import"./chunk-45PGU2HW.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-57ZXT7AS.js";import"./chunk-EQ64JD4L.js";import"./chunk-LBYMDTGD.js";import"./chunk-CQ5EQNQA.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-DXNTXCSI.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import"./chunk-S7NHVERO.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as showFunnelRun,b as showObservedFunnelRun};
@@ -1 +0,0 @@
1
- import{P as r,Q as m,j as e}from"./chunk-QTXHF27F.js";import"./chunk-KJTHMRSH.js";import"./chunk-DZYMD4MJ.js";import"./chunk-TFPLIX5E.js";import"./chunk-S7NHVERO.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{m as merchantBridgeCommerceSchema,r as merchantBridgeOperationSchema,e as merchantOperationLookupSchema};
@@ -1 +0,0 @@
1
- import{e as o}from"./chunk-USH4WN6W.js";import"./chunk-NNJ7W4KY.js";import"./chunk-2SSOV3OG.js";import"./chunk-ULED3B5P.js";import"./chunk-ECUGL7AO.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-5NCQOJR2.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-TFPLIX5E.js";import"./chunk-S7NHVERO.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{o as apiOperations};
@@ -1 +0,0 @@
1
- import{a}from"./chunk-JAH62B6J.js";import"./chunk-6GY2YT3U.js";import"./chunk-W32FI2A2.js";import"./chunk-57ZXT7AS.js";import"./chunk-LBYMDTGD.js";import"./chunk-CQ5EQNQA.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-VILB5M4X.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import"./chunk-S7NHVERO.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as showPaywall};
@@ -1 +0,0 @@
1
- import{b as a}from"./chunk-ST7XO45I.js";import"./chunk-ULED3B5P.js";import"./chunk-ECUGL7AO.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import"./chunk-S7NHVERO.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
@@ -1 +0,0 @@
1
- import{a}from"./chunk-UFTKCFNI.js";import"./chunk-USH4WN6W.js";import"./chunk-NNJ7W4KY.js";import"./chunk-T5SCW4IA.js";import"./chunk-LBYMDTGD.js";import"./chunk-CQ5EQNQA.js";import"./chunk-2SSOV3OG.js";import"./chunk-SGOVJD5P.js";import"./chunk-ST7XO45I.js";import"./chunk-ULED3B5P.js";import"./chunk-ECUGL7AO.js";import"./chunk-3NV6NBQB.js";import"./chunk-Q4GG33R5.js";import"./chunk-WVTKVQLZ.js";import"./chunk-QTXHF27F.js";import"./chunk-44ZJPQM6.js";import"./chunk-VILB5M4X.js";import"./chunk-5NCQOJR2.js";import"./chunk-MT4OQFDI.js";import"./chunk-KJTHMRSH.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-3VUPVXAV.js";import"./chunk-G3YIPDT6.js";import"./chunk-5MRSFLQA.js";import"./chunk-S7NHVERO.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
@@ -1 +0,0 @@
1
- import{a,b,c,d,e,f,g,h,i}from"./chunk-CWBBW6QS.js";import"./chunk-57ZXT7AS.js";import"./chunk-JW4MSBYN.js";import"./chunk-EJSTRCBQ.js";import"./chunk-26QYDE7V.js";import"./chunk-DZYMD4MJ.js";import"./chunk-LUVTP4VU.js";import"./chunk-ZRU7WONE.js";import"./chunk-TFPLIX5E.js";import"./chunk-S7NHVERO.js";import"./chunk-DSPLGTQI.js";import"./chunk-VPT5MFDG.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{f as formatCustomerDecimal,b as hostedRendererScript,a as hostedRendererShell,d as inspectCustomHtml,i as mountScreenPreview,h as preparePopup,e as prepareScreen,c as sanitizeCustomHtml,g as showPopup};
File without changes