@tinkerlandai/longplay-sdk 0.10.39 → 0.10.40

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 (75) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/README.zh-CN.md +1 -1
  4. package/dist/check-response-DRQCUWDW.js +1 -0
  5. package/dist/{chunk-CBZ5GW4J.js → chunk-2DPNSTCN.js} +1 -1
  6. package/dist/{chunk-CE5MAAIR.js → chunk-33ZVZOSC.js} +1 -1
  7. package/dist/{chunk-N774V4SQ.js → chunk-4TEZZZYK.js} +1 -1
  8. package/dist/{chunk-DPIQ3SV7.js → chunk-57GPGWSK.js} +1 -1
  9. package/dist/{chunk-O2D3A4CS.js → chunk-5DZJCFNQ.js} +1 -1
  10. package/dist/{chunk-PFPMK4IO.js → chunk-67AY54E2.js} +1 -1
  11. package/dist/{chunk-MTIOLSVM.js → chunk-6PG3AS3G.js} +1 -1
  12. package/dist/{chunk-GGYBZWWY.js → chunk-7QDT6DO7.js} +1 -1
  13. package/dist/{chunk-LZBJHWVH.js → chunk-ASDJTOGM.js} +1 -1
  14. package/dist/{chunk-GDD26ZDV.js → chunk-AZFWG352.js} +1 -1
  15. package/dist/{chunk-GNAMACMK.js → chunk-BYP4KVB3.js} +1 -1
  16. package/dist/{chunk-YJS6NNIO.js → chunk-C2KT5ZFU.js} +1 -1
  17. package/dist/{chunk-LJBTEB2Q.js → chunk-C3GYAKIU.js} +1 -1
  18. package/dist/{chunk-525K7BPJ.js → chunk-CZ4TQCUV.js} +1 -1
  19. package/dist/{chunk-CEMHQQAJ.js → chunk-EREQZWGI.js} +1 -1
  20. package/dist/{chunk-TA4W6SXG.js → chunk-ESAHTG3Y.js} +1 -1
  21. package/dist/{chunk-IGANLTKS.js → chunk-FCDWCQYC.js} +1 -1
  22. package/dist/{chunk-CKVAV2W5.js → chunk-GC6JBIRQ.js} +1 -1
  23. package/dist/chunk-IJKAQNK6.js +1 -0
  24. package/dist/{chunk-IYHXEKAD.js → chunk-IOJVF52Q.js} +1 -1
  25. package/dist/{chunk-3JD3U45R.js → chunk-LSPHUA7V.js} +1 -1
  26. package/dist/{chunk-YURGISSB.js → chunk-OOD2VDDP.js} +1 -1
  27. package/dist/{chunk-U7XD4ZR5.js → chunk-ORMQJAQE.js} +1 -1
  28. package/dist/{chunk-W3G4YIM5.js → chunk-P23JOPR5.js} +1 -1
  29. package/dist/{chunk-KIPUBMU3.js → chunk-P6C3PNMQ.js} +1 -1
  30. package/dist/chunk-PJS7M6X3.js +1 -0
  31. package/dist/{chunk-ZORZA4WG.js → chunk-POCDWUD3.js} +1 -1
  32. package/dist/{chunk-HFD4CLCJ.js → chunk-PZOQV6MU.js} +1 -1
  33. package/dist/{chunk-TLRRBUGP.js → chunk-QZTTKH2H.js} +1 -1
  34. package/dist/{chunk-HX36OZPQ.js → chunk-RFNIGJOL.js} +1 -1
  35. package/dist/{chunk-3S25TLC3.js → chunk-RULQQ7WI.js} +1 -1
  36. package/dist/{chunk-JBVZ6A6V.js → chunk-RV6UAUK2.js} +1 -1
  37. package/dist/chunk-U7GH4VME.js +1 -0
  38. package/dist/{chunk-UKVWANDE.js → chunk-VC2HPREX.js} +1 -1
  39. package/dist/{chunk-VYI6QRJW.js → chunk-VOKEZHAH.js} +1 -1
  40. package/dist/{chunk-TPXRO63H.js → chunk-WLGLQJ6M.js} +1 -1
  41. package/dist/{chunk-ONMIBSOC.js → chunk-X6ONZGRY.js} +1 -1
  42. package/dist/{chunk-BIT6YWM7.js → chunk-XDOKFAE6.js} +1 -1
  43. package/dist/{chunk-2Y5SGDC6.js → chunk-Y6HL2IY2.js} +1 -1
  44. package/dist/{chunk-JAZHNQKO.js → chunk-YLPQLD2A.js} +1 -1
  45. package/dist/{chunk-QCMFCK7Z.js → chunk-YY445FBU.js} +1 -1
  46. package/dist/{content-HSMBQFM3.js → content-QUEVNSXD.js} +1 -1
  47. package/dist/{funnel-host-purchase-4KOOLMXV.js → funnel-host-purchase-LMVMJNUO.js} +1 -1
  48. package/dist/funnel-paywall-prerender-LGUSHEP3.js +1 -0
  49. package/dist/funnel-runtime-host-H5FM67UC.js +1 -0
  50. package/dist/index.js +1 -1
  51. package/dist/merchant-bridge-contracts-LZSQYE3O.js +1 -0
  52. package/dist/openrouter.js +1 -1
  53. package/dist/operation-contracts-O7TCDGV4.js +1 -0
  54. package/dist/page.js +1 -1
  55. package/dist/{paywall-ZGG6DXO3.js → paywall-UANWOKKC.js} +1 -1
  56. package/dist/paywall-content-CHPX2P77.js +1 -0
  57. package/dist/paywall-session-3BNUC5ZE.js +1 -0
  58. package/dist/popup.js +1 -1
  59. package/dist/react-native.js +1 -1
  60. package/dist/screen-renderer-FFVZ64MR.js +1 -0
  61. package/dist/server.js +1 -1
  62. package/dist/visual.js +1 -1
  63. package/package.json +9 -10
  64. package/dist/check-response-MNFEOKKE.js +0 -1
  65. package/dist/chunk-73ISTR7P.js +0 -1
  66. package/dist/chunk-NSAEHRIT.js +0 -1
  67. package/dist/chunk-QXOUDODX.js +0 -1
  68. package/dist/funnel-paywall-prerender-NX6ZQ7EU.js +0 -1
  69. package/dist/funnel-runtime-host-6XYYLVCI.js +0 -1
  70. package/dist/merchant-bridge-contracts-ACGAMHU6.js +0 -1
  71. package/dist/operation-contracts-H27WHXQC.js +0 -1
  72. package/dist/paywall-content-ZQBE2EZP.js +0 -1
  73. package/dist/paywall-session-DBTBLLWI.js +0 -1
  74. package/dist/screen-renderer-5SJCTMJH.js +0 -1
  75. /package/dist/{chunk-NOOIJXRN.js → chunk-RGEBK6UF.js} +0 -0
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as gn,c as vn}from"./chunk-QXOUDODX.js";import{a as We,c as En}from"./chunk-UKVWANDE.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as ln,c as hn,d as In}from"./chunk-TLRRBUGP.js";import"./chunk-LZBJHWVH.js";import{a as yn}from"./chunk-NSAEHRIT.js";import"./chunk-PFPMK4IO.js";import{h as dn,i as pn,k as wn}from"./chunk-GDD26ZDV.js";import{F as Ce,e as Xe,g as Ye,h as ge,i as ve,j as Ze,x as un}from"./chunk-N774V4SQ.js";import{a as ze}from"./chunk-ZORZA4WG.js";import"./chunk-U7XD4ZR5.js";import"./chunk-HX36OZPQ.js";import"./chunk-GGYBZWWY.js";import{B as He,D as qe,E as Ue,G as Ve,H as je,I as Ge,J as Je,K as Te,L as $e,x as _e,y as Le,z as Be}from"./chunk-MTIOLSVM.js";import"./chunk-ONMIBSOC.js";import"./chunk-CEMHQQAJ.js";import"./chunk-W3G4YIM5.js";import{aa as Ke,l as an,m as sn,n as cn}from"./chunk-IYHXEKAD.js";import"./chunk-73ISTR7P.js";import{c as fn,e as mn}from"./chunk-3NCMYTNG.js";import"./chunk-CE5MAAIR.js";import"./chunk-VYI6QRJW.js";import{b as Ae}from"./chunk-HFD4CLCJ.js";import"./chunk-IGANLTKS.js";import"./chunk-BIT6YWM7.js";import"./chunk-2Y5SGDC6.js";import"./chunk-3JD3U45R.js";import"./chunk-YURGISSB.js";import{a as G}from"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-SLUA7ABW.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import{c as we,d as Ee}from"./chunk-YJS6NNIO.js";import"./chunk-3VUPVXAV.js";import"./chunk-JBVZ6A6V.js";import{b as U}from"./chunk-NOOIJXRN.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import{a as Q}from"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var I=class extends Error{constructor(f,b=0,w=!1,h="fix_request"){super(f);this.code=f;this.status=b;this.retryable=w;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function bn(n,d){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let f=n.body?.getReader();if(!f)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let b=()=>{f.cancel().catch(()=>{})};d.addEventListener("abort",b,{once:!0});let w=0,h="",t=new TextDecoder("utf-8",{fatal:!0});try{for(d.throwIfAborted();;){let i=await f.read();if(d.throwIfAborted(),i.done)break;if(w+=i.value.byteLength,w>262144)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=t.decode(i.value,{stream:!0})}return h+=t.decode(),JSON.parse(h)}catch(i){throw d.throwIfAborted(),i instanceof I?i:new I("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{d.removeEventListener("abort",b),await f.cancel().catch(()=>{}),f.releaseLock()}}function Sn(n){let d=qe.parse(n.origin),f=Ue.parse(n.manifest),b={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let m of["projectId","environmentId","environment"])if(f[m]!==n.scope[m])throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");let w=n.customerId===void 0?null:U.uuid().parse(n.customerId),h=0,t=null,i=null,u=new AbortController,y=n.fetch??globalThis.fetch;async function R(m,s,E,_,M){if(!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=He[m];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(S.authority))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);let l=h,o=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],..._?[_]:[]]);o.throwIfAborted();let T=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(T.get("authorization")??"")||T.has("X-Indiana-Bridge-Signature")||T.has("X-Indiana-Bridge-Key-Id"))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);T.set(Be,String(_e)),T.set("Accept","application/json");let g=crypto.randomUUID();T.set("X-Request-Id",g),T.set("Content-Type","application/json");let N=await y(d+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:T,signal:o,body:JSON.stringify({bridgeVersion:_e,requestId:g,command:S.command,scope:b,data:M??(E===void 0?{}:{operationId:E})})}),J=await bn(N,o);if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(!N.ok){let O=$e.safeParse(J);throw!O.success||O.data.scope.projectId!==n.scope.projectId||O.data.scope.environment!==n.scope.environment||O.data.scope.environmentId!==n.scope.environmentId||O.data.requestId!==g||O.data.command!==S.command?new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status):new I(O.data.error.code,N.status,O.data.error.retryable,O.data.error.recovery)}let c=Ve(U.unknown()).safeParse(J);if(!c.success||c.data.scope.projectId!==n.scope.projectId||c.data.scope.environment!==n.scope.environment||c.data.scope.environmentId!==n.scope.environmentId||c.data.requestId!==g||c.data.command!==S.command)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status);let $=s.safeParse(c.data.data);if(!$.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status);return $.data}function P(){if(!w)throw new I("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return w}async function B(m,s,E,_){let M=P();if(_!==void 0&&Te.parse({operationId:_,customerId:M}),!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=h,l=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,T=new Promise((g,N)=>{o=()=>N(l.reason),l.addEventListener("abort",o,{once:!0})});try{let N=E(async()=>{let c=await import("./merchant-bridge-contracts-ACGAMHU6.js");if(l.throwIfAborted(),S!==h||w!==M)throw new DOMException("Merchant identity changed","AbortError");return c},l),J=await Promise.race([N,T]);return l.throwIfAborted(),J}finally{l.removeEventListener("abort",o)}}async function z(m,s,E,_){let M=P(),S=Te.parse({operationId:E,customerId:M}),l=await R(m,s,S.operationId,_,S);if(l.customerId!==M||l.operationId!==S.operationId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(m){let s=await R("presentation",Ge,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&w!==null&&s.presentation.customerId!==w)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,t=s.presentation,s},async createSession(m){let s=await R("session",je,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(w!==null&&w!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return w=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(m,s){let E=P(),_=Je.parse(m);if(!t||t.customerId!==E||t.decisionId!==_.decisionId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return R("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,s,_)},async readCustomerCommerce(m){let s=P(),E=await B("customer_commerce",m,async(_,M)=>{let[S,l]=await Promise.all([_(),R("customer_commerce",U.unknown(),void 0,M)]),o=S.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(E.customerId!==s)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E},async executePurchase(m,s){let E=await B("purchases",s,async(_,M)=>z("purchases",(await _()).merchantBridgeOperationSchema,m,M),m);if(E.type!=="purchase")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},readOperation:(m,s)=>B("operation_status",s,async(E,_)=>z("operation_status",(await E()).merchantOperationLookupSchema,m,_),m),async executeSubscriptionChange(m,s){let E=await B("subscription_changes",s,async(_,M)=>z("subscription_changes",(await _()).merchantBridgeOperationSchema,m,M),m);if(E.type!=="subscription_change")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},reset(){h++,u.abort(),u=new AbortController,w=null,t=null,i=null}}}var en=U.strictObject({command:ve,target:Ye,runId:U.uuid().optional(),expiresAt:U.iso.datetime({offset:!0}).optional(),deliveryLimit:U.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Qe=U.strictObject({schemaVersion:U.literal(1),entries:U.array(en).max(4e3)});function nn(n){let d=!1,f=()=>{d||n.unavailable(),d=!0};function b(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function w(t){let i=b()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Qe.parse(JSON.parse(i)).entries}function h(t,i){let u=b();if(!u)return;if(!i.length)return u.removeItem(t);let y=JSON.stringify(Qe.parse({schemaVersion:1,entries:i}));if(y.length>1048576)throw Error("Entry recovery is too large");u.setItem(t,y)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:w(i)}}catch{f();return}},retain(t,i){if(t)try{let u=en.parse(i);h(t,[...w(t).filter(y=>y.command.funnelId!==u.command.funnelId),u])}catch{f()}},forget(t,i){if(t)try{h(t,w(t).filter(u=>u.command.requestId!==i))}catch{f()}}}}var tn=U.strictObject({version:U.literal(1),runs:U.array(U.uuid()).max(100)}),De=new WeakMap,Me=new WeakMap;function Se(n){let d=!1;function f(){d||n.unavailable(),d=!0}function b(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function w(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let u=i.get(t.key);return u||i.set(t.key,u=new Set),u}function h(t){if(!t)return;let i=De.get(t.storage),u=i?.get(t.key);u?.delete(t.requestId),u?.size===0&&i?.delete(t.key)}return{claim(t,i,u,y,R=!1){if(u!==void 0)try{let P=n.binding();if(!P)throw Error("Entry delivery identity is unavailable");let B={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...P,i,t]),requestId:y},z=b(B);if(Me.get(B.storage)?.has(B.key))throw Error("Entry delivery storage is unavailable");B.storage.setItem(B.key,JSON.stringify({version:1,runs:z}));let m=w(B);return!R&&!m.has(y)&&z.length+m.size>=u?!1:(m.add(y),B)}catch{return f(),!1}},accept(t,i){if(t)try{let u=b(t);u.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...u,i].slice(-100)})))}catch{let u=Me.get(t.storage);u||Me.set(t.storage,u=new Set),u.add(t.key),f()}finally{h(t)}},release:h}}function Re(){let n,d,f=()=>{clearTimeout(n),n=void 0;let b=d;d=void 0,b?.cancelled()};return{get active(){return d!==void 0},start(b,w,h,t){if(d)return;if(b===0){w()?h():t();return}let i={valid:w,cancelled:t};d=i,n=setTimeout(()=>{d===i&&(d=void 0,n=void 0,w()?h():t())},b*1e3)},recheck(){d&&!d.valid()&&f()},cancel:f}}var Pe=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function Rn(n){let d=we(n.baseUrl),f=n.scope,b=Ae(n),w=n.fetch??globalThis.fetch.bind(globalThis),h,t=!1,i=!1,u=0,y=0,R="",P=0,B=0,z=0,m=!1,s,E=!0,_,M,S,l,o,T=-1,g,N=e=>{g===e&&(O.release(e.deliveryTicket),g=void 0,k())},J=new Set,c=(e,a)=>Q(n.onStatus,e,a),$=Re(),O=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>c("delivery_unavailable")}),ee=new Set,te=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>c("recovery_unavailable")}),Z=e=>te.forget(e.storageKey,e.command.requestId);function Y(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),te.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),k()}let le=()=>$.active||g!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Y(o.recovery,a);let p=Pe(a);o.slot.hidden=p,p!==o.background&&(o.background=p,p?c("run_background",o.entryId):T=y,k())}function pe(e,a,p){let v=e.client.view;if(!a||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let K=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:a}),j=Ae({...n,session:void 0});j.requestWithCredential("funnels",K,e.runToken,{keepalive:p}).then(()=>Z(e.recovery)).catch(()=>{}).finally(()=>j.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<B&&performance.now()<z;function A(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return c("incompatible",e.id),!1}}function H(e){if(t||e.epoch!==P||e.visit!==y||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(e){if(le()){c("in_progress",e.id);return}let a=P,p=y;$.start(e.delivery?.delaySeconds??0,()=>!t&&a===P&&p===y&&document.visibilityState!=="hidden"&&A(e)&&h?.entries.some(v=>v.id===e.id&&v.funnelId===e.funnelId&&v.versionId===e.versionId&&v.event===e.event&&JSON.stringify(v.target)===JSON.stringify(e.target)&&JSON.stringify(v.delivery)===JSON.stringify(e.delivery))===!0,()=>{V(e)},()=>{J.delete(`${e.funnelId}:${e.id}`)})}async function V(e){if(le()){c("in_progress",e.id);return}if(!n.session.peek()){c("identity_required",e.id);return}let a=te.load(),p=a?.entries.find(C=>C.command.funnelId===e.funnelId&&(!C.expiresAt||Date.parse(C.expiresAt)>Date.now()));if(p){if(!X(p)){c("recovery_pending",e.id);return}let C={...p,storageKey:a.key,epoch:P,visit:y};ee.add(C.command.requestId),g=C,await F(C);return}let v=crypto.randomUUID(),K=O.claim(e.id,e.funnelId,e.delivery?.maxPerSession,v);if(K===!1){c("frequency",e.id),k();return}let j={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:K,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:v,locale:document.documentElement.lang||"en"}),epoch:P,visit:y,target:e.target,storageKey:a?.key};ee.add(j.command.requestId),g=j,await F(j)}async function F(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let p,v=!1,K=!1;async function j(C){if(e.epoch!==P)return;let D=C.view;if(!(e.storageKey&&D&&(Pe(D)||D.paywall||D.pendingRequest))&&D&&["running","waiting"].includes(D.status))try{await C.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:D.nodeId,visit:D.visit,revision:D.revision}),Z(e)}catch(x){if(!(x instanceof G&&x.code==="FORBIDDEN"))throw x}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let q=O.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);q!==!1&&(e.deliveryTicket=q)}Y(e),c("starting",e.command.entryId);let C=await b.request("funnels",e.command),D=Ze.safeParse(C);if(D.success){if(D.data.scope.projectId!==f.projectId||D.data.scope.environment!==f.environment)throw new G("SCOPE_MISMATCH","Entry scope changed");e.epoch===P&&c(D.data.reason,e.command.entryId),Z(e),N(e);return}let x=Xe.parse(C);if(!x.runToken||x.scope.projectId!==f.projectId||x.scope.environment!==f.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new G("INVALID_RESPONSE","Invalid entry Run");if(O.accept(e.deliveryTicket,x.run.id),e.epoch!==P){N(e),c("identity_changed",e.command.entryId);return}Y(e,x.run);let L=Ce({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?C:void 0});p=L,K=!0,await L.get(),K=!1;let ne=L.view;if(!ne||ne.id!==x.run.id||ne.source.type!=="funnel"||ne.source.id!==e.command.funnelId||ne.source.versionId!==e.command.versionId)throw new G("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(ne.status)){Z(e),N(e),c("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-6XYYLVCI.js");if(!H(e)){await j(L),c("left_screen",e.command.entryId),N(e);return}let Fe=!1,ke=!1;if(o&&!o.background){await j(L),c("in_progress",e.command.entryId),N(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Pe(ne),n.container.append(ie);let xe=await fe(ie,{...n.host,client:L,appManifestRelease:n.appManifestRelease,onState(q){me(L,q),Q(n.host?.onState,q)},onDismiss(q){Fe=!0,ie.remove(),q&&!["running","waiting"].includes(q.status)&&Z(e),o?.client===L&&(o=void 0,L.reset(),k(),q&&q.status!=="completed"&&c("run_ended",e.command.entryId)),Q(n.host?.onDismiss,q)},onComplete(q){ke=!0,Z(e),o?.client===L&&re(),Q(n.host?.onComplete,q)},onError(q){Q(n.host?.onError,q),o?.client===L&&q instanceof G&&q.code==="FORBIDDEN"&&(Z(e),re(),c("run_ended",e.command.entryId))}}).catch(q=>{throw ie.remove(),q});if(!H(e)||Fe||ke){xe.destroy(),ie.remove(),H(e)||await j(L),N(e);return}let he=Pe(L.view??ne);ie.hidden=he,o={host:xe,client:L,slot:ie,entryId:e.command.entryId,background:he,runToken:x.runToken,owner:n.session.peek(),recovery:e},he||(T=e.visit),v=!0,N(e),c("started",e.command.entryId),he&&c("run_background",e.command.entryId)}catch(C){C instanceof G&&(!p||K&&C.code==="FORBIDDEN")&&C.status!==void 0&&C.status>=400&&C.status<500&&!C.retryable&&(Z(e),N(e)),e.epoch===P&&!t&&(c("start_failed",e.command.entryId),Q(n.host?.onError,C))}finally{v||p?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=te.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){te.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||ee.has(a.command.requestId)||!X(a))continue;ee.add(a.command.requestId);let p={...a,storageKey:e.key,epoch:P,visit:y};return g=p,F(p),!0}return!1}function ue(){if(m=!1,$.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(T=y),!ye()){if(!r()){E=!0;return}E=!1;for(let a of h?.entries??[]){let p=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||J.has(p)||!A(a))){if(!n.session.peek()){c("identity_required",a.id);continue}if(T===y){J.add(p),e&&c("in_progress",a.id);continue}if(g||$.active){c("in_progress",a.id);return}J.add(p),W(a);break}}}}let k=()=>{!m&&!t&&(m=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===R?!1:(R=e,y++,$.cancel(),E=!0,J.clear(),ee.clear(),!0)}function oe(){se()&&k()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let p=a.closest("button,a,input");if(!(!p||p.matches(":disabled,[aria-disabled='true']")||p.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of h?.entries??[]){let K=v.target.button;if(!(v.event!=="button_click"||!K||!A(v))){try{let j=be(document);if(!p.matches(K.selector)||j(K.selector,p)!==1)continue}catch{c("incompatible",v.id);continue}W(v);break}}}async function Ne(){if(t)return;if(s)return s;let e=++u,a=new AbortController;_=a;let p,v=new Promise((C,D)=>{p=()=>D(new G("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",p,{once:!0})}),K=setTimeout(()=>a.abort(),n.timeoutMs??5e3),j=(async()=>{let C=async()=>{let fe=await w(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},D=await Promise.race([C(),v]),x=Date.parse(D.validatedAt),L=Date.parse(D.validUntil);if(D.scope.projectId!==f.projectId||D.scope.environment!==f.environment||D.scope.environmentId!==n.environmentId||D.release!==n.appManifestRelease||L<=Date.now()||x>Date.now()+5e3||L-x>6e4||L<=x)throw new G("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==u)return;let ne=h===void 0;h=D,B=L,z=performance.now()+Math.min(L-Date.now(),6e4),$.recheck(),(ne||E)&&k()})();s=j;try{await j}finally{clearTimeout(K),a.signal.removeEventListener("abort",p),s===j&&(s=void 0)}}async function on(){if(!(!i||t)){try{await Ne()}catch{t||c("configuration_unavailable")}k()}}let Oe=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,R=location.origin+location.pathname,M=Ee(oe),S=n.session.subscribeIdentity(()=>{P++,$.cancel(),O.release(g?.deliveryTicket),E=!0,g=void 0,J.clear(),T=-1,ee.clear(),o&&pe(o,o.owner,!1),re(),k()}),l=new MutationObserver(k),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",k),addEventListener("pagehide",ae),await Oe.refresh())},refresh:Ne,async retry(){g&&!t&&g.epoch===P&&await F(g)},destroy(){t=!0,u++,$.cancel(),O.release(g?.deliveryTicket),Oe.destroy(),_?.abort(),l?.disconnect(),M?.(),S?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",k),removeEventListener("pagehide",ae),ae(),re(),b.dispose(),h=void 0}}}function Pn(n){let d=we(n.baseUrl),f=n.fetch??globalThis.fetch.bind(globalThis),b,w=0,h=0,t=!1,i=!1,u=!1,y=0,R=0,P=-1,B=!1,z="",m,s,E,_,M=new Set,S,l,o,T=(r,A)=>Q(n.onStatus,r,A),g=Re(),N=()=>{try{return n.deliveryIdentity?.()}catch{return}},J=()=>JSON.stringify(N()),c=Se({storage:n.deliveryStorage,binding:()=>{let r=N();return r?.id?[d,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>T("delivery_unavailable")}),$=()=>Date.now()<w&&performance.now()<h;function O(r){try{return $()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return T("incompatible",r.id),!1}}function ee(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function te(r){if(r.dispatching)return;r.dispatching=!0;let A=y;try{let H=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});c.accept(r.deliveryTicket,H.run.id);let{showFunnelRun:W}=await import("./funnel-runtime-host-6XYYLVCI.js");if(t||A!==y||l!==r)return;let V=document.createElement("div");n.container.append(V),P=R;let F=await W(V,{...n.host,client:H.controller,appManifestRelease:n.appManifestRelease,onDismiss(X){o?.process===r.process&&(o=void 0,V.remove()),Q(n.host?.onDismiss,X)}});if(t||A!==y||l!==r){F.destroy(),V.remove();return}o={entry:r.entry,process:r.process,host:F,slot:V,deliveryTicket:r.deliveryTicket},l=void 0,T("run_presented",r.entry.id)}catch(H){if(t||A!==y||l!==r)return;H instanceof G&&"result"in H?(c.release(r.deliveryTicket),l=void 0,r.process.destroy(),T("suppressed",r.entry.id),Y()):T("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function Z(r){if(t||i||l||o||S||g.active||P===R||!O(r))return;let A=`${R}:${r.id}`;if(M.has(A))return;M.add(A);let H=R,W=y,V=J();g.start(r.delivery?.delaySeconds??0,()=>!t&&y===W&&R===H&&J()===V&&document.visibilityState!=="hidden"&&O(r)&&b?.entries.some(F=>F.id===r.id&&F.funnelId===r.funnelId&&F.versionId===r.versionId&&F.event===r.event&&JSON.stringify(F.target)===JSON.stringify(r.target)&&JSON.stringify(F.delivery)===JSON.stringify(r.delivery))===!0,()=>{let F=c.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(F===!1){T("frequency",r.id),Y();return}try{let X={entry:r,process:n.createProcess(r),visit:R,deliveryTicket:F};l=X,te(X)}catch(X){c.release(F),T("entry_unavailable",r.id),Q(n.host?.onError,X)}},()=>{M.delete(A)})}function Y(){B||t||(B=!0,queueMicrotask(()=>{if(B=!1,g.recheck(),!(t||i||document.visibilityState==="hidden"||!$()||l||o||S||g.active||P===R)){for(let r of b?.entries??[])if(r.event==="screen_enter"&&!M.has(`${R}:${r.id}`)&&O(r)){Z(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||l||o||S||P===R)return;let A=be(document,()=>{});for(let H of b?.entries??[]){let W=H.target.button;if(H.event!=="button_click"||!W||!O(H))continue;let V=r.target.closest(W.selector);if(!(!V||V.tagName.toLowerCase()!==W.tag||A(W.selector)!==1||V.matches(":disabled")||V.closest('[inert],[hidden],[aria-hidden="true"]'))){Z(H);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,R++,g.cancel(),M.clear(),Y())};async function me(){if(t)return;if(s)return s;let r=y,A=new AbortController;m=A;let H,W=new Promise((ye,ue)=>{H=ue}),V=()=>H(new G("TIMEOUT","Funnel entry read cancelled"));A.signal.addEventListener("abort",V,{once:!0});let F=setTimeout(()=>A.abort(),n.timeoutMs??5e3),X=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await f(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:A.signal});if(!ce.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},k=await Promise.race([ue(),W]),se=Date.parse(k.validatedAt),oe=Date.parse(k.validUntil);if(k.scope.projectId!==n.scope.projectId||k.scope.environment!==n.scope.environment||k.scope.environmentId!==n.environmentId||k.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new G("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==y||(b=k,w=oe,h=performance.now()+Math.min(oe-Date.now(),6e4),g.recheck(),Y())})();s=X;try{await X}finally{clearTimeout(F),A.signal.removeEventListener("abort",V),s===X&&(s=void 0)}}async function pe(){if(!(!u||t))try{await me()}catch{t||T("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>u&&!t?15e3:void 0});return{async start(){u||t||(u=!0,z=location.origin+location.pathname,E=Ee(le),_=new MutationObserver(Y),_.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Y),await ae.refresh())},refresh:me,async retry(){l&&!t&&await te(l)},async syncIdentity(){g.cancel();let r=o??l??S;if(!r){i=!1,Y();return}try{let A=await r.process.syncIdentity();return i=!1,S===r&&(l={...r,visit:R},S=void 0,await te(l)),A}catch(A){throw r.process.view||(S={...r,visit:R},l=void 0,ee()),A}},async detach(){i=!0,y++,g.cancel(),m?.abort();let r=o??l??S;r&&(S={...r,visit:R}),l=void 0,ee(),r&&await r.process.detach()},destroy(){t=!0,y++,g.cancel(),ae.destroy(),m?.abort(),_?.disconnect(),E?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Y);let r=o??l??S;c.release(r?.deliveryTicket),l=void 0,S=void 0,ee(),r?.process.destroy(),b=void 0}}}async function _n(n,d){return(await import("./paywall-ZGG6DXO3.js")).showPaywall(n,d)}async function ot(){return await Promise.all([import("./paywall-ZGG6DXO3.js"),import("./screen-renderer-5SJCTMJH.js")]),_n}async function at(...n){return n[1]=ze(n[1]),(await import("./paywall-session-DBTBLLWI.js")).createPaywallSession(...n)}async function st(...n){let d=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-5SJCTMJH.js").catch(()=>{}),import("./paywall-ZGG6DXO3.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-6XYYLVCI.js"),n[1].prepared)).showFunnelRun(...n)}finally{d?.()}}async function rn(n,d){try{return await n()}catch(f){throw d&&d.state!=="adopted"&&await import("./funnel-paywall-prerender-NX6ZQ7EU.js").then(b=>b.preparedInternals(d)?.release(),()=>{}),f}}async function ct(...n){return import("./screen-renderer-5SJCTMJH.js").catch(()=>{}),import("./paywall-ZGG6DXO3.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-4KOOLMXV.js"),n[1].prepared)).showFunnelPurchase(...n)}async function dt(...n){return import("./funnel-host-purchase-4KOOLMXV.js").catch(()=>{}),import("./screen-renderer-5SJCTMJH.js").catch(()=>{}),(await import("./funnel-paywall-prerender-NX6ZQ7EU.js")).prerenderFunnelPurchase(...n)}async function lt(){await Promise.all([import("./funnel-paywall-prerender-NX6ZQ7EU.js"),import("./funnel-host-purchase-4KOOLMXV.js"),import("./paywall-ZGG6DXO3.js"),import("./screen-renderer-5SJCTMJH.js"),import("./paywall-content-ZQBE2EZP.js"),import("./check-response-MNFEOKKE.js"),import("./operation-contracts-H27WHXQC.js")])}async function ut(...n){return(await import("./content-HSMBQFM3.js")).mountContent(...n)}async function ft(...n){return(await import("./content-HSMBQFM3.js")).prepareContent(...n)}export{G as LongplayError,I as MerchantBridgeError,un as createBrowserFunnelCommandStorage,gn as createBrowserFunnelPurchaseStorage,pn as createConfigurationSync,dn as createFeatureClient,hn as createFunnelClient,En as createFunnelPageExperiments,In as createFunnelProcess,vn as createFunnelPurchaseClient,Ce as createFunnelRunController,Rn as createIamFunnelEntries,Pn as createIamFunnelProcessEntries,wn as createLocalFunnelClient,ln as createLongplay,Sn as createMerchantBridge,at as createPaywallSession,yn as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,fn as getPaywallRecovery,ut as mountContent,lt as preloadFunnelPurchase,ot as preloadPaywall,ft as prepareContent,mn as preparePaywallFallback,dt as prerenderFunnelPurchase,ct as showFunnelPurchase,st as showFunnelRun,_n as showPaywall};
1
+ import{a as gn,c as vn}from"./chunk-PJS7M6X3.js";import{a as We,c as En}from"./chunk-VC2HPREX.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as ln,c as hn,d as In}from"./chunk-QZTTKH2H.js";import"./chunk-ASDJTOGM.js";import{a as yn}from"./chunk-IJKAQNK6.js";import"./chunk-67AY54E2.js";import{h as dn,i as pn,k as wn}from"./chunk-AZFWG352.js";import{F as Ce,e as Xe,g as Ye,h as ge,i as ve,j as Ze,x as un}from"./chunk-4TEZZZYK.js";import{a as ze}from"./chunk-POCDWUD3.js";import"./chunk-ORMQJAQE.js";import"./chunk-RFNIGJOL.js";import"./chunk-7QDT6DO7.js";import{B as He,D as qe,E as Ue,G as Ve,H as je,I as Ge,J as Je,K as Te,L as $e,x as _e,y as Le,z as Be}from"./chunk-6PG3AS3G.js";import"./chunk-X6ONZGRY.js";import"./chunk-EREQZWGI.js";import"./chunk-P23JOPR5.js";import{aa as Ke,l as an,m as sn,n as cn}from"./chunk-IOJVF52Q.js";import"./chunk-U7GH4VME.js";import{c as fn,e as mn}from"./chunk-3NCMYTNG.js";import"./chunk-33ZVZOSC.js";import"./chunk-VOKEZHAH.js";import{b as Ae}from"./chunk-PZOQV6MU.js";import"./chunk-FCDWCQYC.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import{a as G}from"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-SLUA7ABW.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import{c as we,d as Ee}from"./chunk-C2KT5ZFU.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import{b as U}from"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import{a as Q}from"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var I=class extends Error{constructor(f,b=0,w=!1,h="fix_request"){super(f);this.code=f;this.status=b;this.retryable=w;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function bn(n,d){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let f=n.body?.getReader();if(!f)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let b=()=>{f.cancel().catch(()=>{})};d.addEventListener("abort",b,{once:!0});let w=0,h="",t=new TextDecoder("utf-8",{fatal:!0});try{for(d.throwIfAborted();;){let i=await f.read();if(d.throwIfAborted(),i.done)break;if(w+=i.value.byteLength,w>262144)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=t.decode(i.value,{stream:!0})}return h+=t.decode(),JSON.parse(h)}catch(i){throw d.throwIfAborted(),i instanceof I?i:new I("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{d.removeEventListener("abort",b),await f.cancel().catch(()=>{}),f.releaseLock()}}function Sn(n){let d=qe.parse(n.origin),f=Ue.parse(n.manifest),b={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let m of["projectId","environmentId","environment"])if(f[m]!==n.scope[m])throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");let w=n.customerId===void 0?null:U.uuid().parse(n.customerId),h=0,t=null,i=null,u=new AbortController,y=n.fetch??globalThis.fetch;async function R(m,s,E,_,M){if(!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=He[m];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(S.authority))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);let l=h,o=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],..._?[_]:[]]);o.throwIfAborted();let T=new Headers(await n.headers?.());if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(T.get("authorization")??"")||T.has("X-Indiana-Bridge-Signature")||T.has("X-Indiana-Bridge-Key-Id"))throw new I("MERCHANT_BRIDGE_FORBIDDEN",403);T.set(Be,String(_e)),T.set("Accept","application/json");let g=crypto.randomUUID();T.set("X-Request-Id",g),T.set("Content-Type","application/json");let N=await y(d+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:T,signal:o,body:JSON.stringify({bridgeVersion:_e,requestId:g,command:S.command,scope:b,data:M??(E===void 0?{}:{operationId:E})})}),J=await bn(N,o);if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(!N.ok){let O=$e.safeParse(J);throw!O.success||O.data.scope.projectId!==n.scope.projectId||O.data.scope.environment!==n.scope.environment||O.data.scope.environmentId!==n.scope.environmentId||O.data.requestId!==g||O.data.command!==S.command?new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status):new I(O.data.error.code,N.status,O.data.error.retryable,O.data.error.recovery)}let c=Ve(U.unknown()).safeParse(J);if(!c.success||c.data.scope.projectId!==n.scope.projectId||c.data.scope.environment!==n.scope.environment||c.data.scope.environmentId!==n.scope.environmentId||c.data.requestId!==g||c.data.command!==S.command)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status);let $=s.safeParse(c.data.data);if(!$.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",N.status);return $.data}function P(){if(!w)throw new I("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return w}async function B(m,s,E,_){let M=P();if(_!==void 0&&Te.parse({operationId:_,customerId:M}),!f.capabilities.includes(m))throw new I("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let S=h,l=AbortSignal.any([u.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...s?[s]:[]]);l.throwIfAborted();let o,T=new Promise((g,N)=>{o=()=>N(l.reason),l.addEventListener("abort",o,{once:!0})});try{let N=E(async()=>{let c=await import("./merchant-bridge-contracts-LZSQYE3O.js");if(l.throwIfAborted(),S!==h||w!==M)throw new DOMException("Merchant identity changed","AbortError");return c},l),J=await Promise.race([N,T]);return l.throwIfAborted(),J}finally{l.removeEventListener("abort",o)}}async function z(m,s,E,_){let M=P(),S=Te.parse({operationId:E,customerId:M}),l=await R(m,s,S.operationId,_,S);if(l.customerId!==M||l.operationId!==S.operationId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(m){let s=await R("presentation",Ge,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&w!==null&&s.presentation.customerId!==w)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,t=s.presentation,s},async createSession(m){let s=await R("session",je,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(w!==null&&w!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return w=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(m,s){let E=P(),_=Je.parse(m);if(!t||t.customerId!==E||t.decisionId!==_.decisionId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return R("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,s,_)},async readCustomerCommerce(m){let s=P(),E=await B("customer_commerce",m,async(_,M)=>{let[S,l]=await Promise.all([_(),R("customer_commerce",U.unknown(),void 0,M)]),o=S.merchantBridgeCommerceSchema.safeParse(l);if(!o.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return o.data});if(E.customerId!==s)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return E},async executePurchase(m,s){let E=await B("purchases",s,async(_,M)=>z("purchases",(await _()).merchantBridgeOperationSchema,m,M),m);if(E.type!=="purchase")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},readOperation:(m,s)=>B("operation_status",s,async(E,_)=>z("operation_status",(await E()).merchantOperationLookupSchema,m,_),m),async executeSubscriptionChange(m,s){let E=await B("subscription_changes",s,async(_,M)=>z("subscription_changes",(await _()).merchantBridgeOperationSchema,m,M),m);if(E.type!=="subscription_change")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},reset(){h++,u.abort(),u=new AbortController,w=null,t=null,i=null}}}var en=U.strictObject({command:ve,target:Ye,runId:U.uuid().optional(),expiresAt:U.iso.datetime({offset:!0}).optional(),deliveryLimit:U.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Qe=U.strictObject({schemaVersion:U.literal(1),entries:U.array(en).max(4e3)});function nn(n){let d=!1,f=()=>{d||n.unavailable(),d=!0};function b(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function w(t){let i=b()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Qe.parse(JSON.parse(i)).entries}function h(t,i){let u=b();if(!u)return;if(!i.length)return u.removeItem(t);let y=JSON.stringify(Qe.parse({schemaVersion:1,entries:i}));if(y.length>1048576)throw Error("Entry recovery is too large");u.setItem(t,y)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:w(i)}}catch{f();return}},retain(t,i){if(t)try{let u=en.parse(i);h(t,[...w(t).filter(y=>y.command.funnelId!==u.command.funnelId),u])}catch{f()}},forget(t,i){if(t)try{h(t,w(t).filter(u=>u.command.requestId!==i))}catch{f()}}}}var tn=U.strictObject({version:U.literal(1),runs:U.array(U.uuid()).max(100)}),De=new WeakMap,Me=new WeakMap;function Se(n){let d=!1;function f(){d||n.unavailable(),d=!0}function b(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function w(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let u=i.get(t.key);return u||i.set(t.key,u=new Set),u}function h(t){if(!t)return;let i=De.get(t.storage),u=i?.get(t.key);u?.delete(t.requestId),u?.size===0&&i?.delete(t.key)}return{claim(t,i,u,y,R=!1){if(u!==void 0)try{let P=n.binding();if(!P)throw Error("Entry delivery identity is unavailable");let B={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...P,i,t]),requestId:y},z=b(B);if(Me.get(B.storage)?.has(B.key))throw Error("Entry delivery storage is unavailable");B.storage.setItem(B.key,JSON.stringify({version:1,runs:z}));let m=w(B);return!R&&!m.has(y)&&z.length+m.size>=u?!1:(m.add(y),B)}catch{return f(),!1}},accept(t,i){if(t)try{let u=b(t);u.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...u,i].slice(-100)})))}catch{let u=Me.get(t.storage);u||Me.set(t.storage,u=new Set),u.add(t.key),f()}finally{h(t)}},release:h}}function Re(){let n,d,f=()=>{clearTimeout(n),n=void 0;let b=d;d=void 0,b?.cancelled()};return{get active(){return d!==void 0},start(b,w,h,t){if(d)return;if(b===0){w()?h():t();return}let i={valid:w,cancelled:t};d=i,n=setTimeout(()=>{d===i&&(d=void 0,n=void 0,w()?h():t())},b*1e3)},recheck(){d&&!d.valid()&&f()},cancel:f}}var Pe=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function Rn(n){let d=we(n.baseUrl),f=n.scope,b=Ae(n),w=n.fetch??globalThis.fetch.bind(globalThis),h,t=!1,i=!1,u=0,y=0,R="",P=0,B=0,z=0,m=!1,s,E=!0,_,M,S,l,o,T=-1,g,N=e=>{g===e&&(O.release(e.deliveryTicket),g=void 0,k())},J=new Set,c=(e,a)=>Q(n.onStatus,e,a),$=Re(),O=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>c("delivery_unavailable")}),ee=new Set,te=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>c("recovery_unavailable")}),Z=e=>te.forget(e.storageKey,e.command.requestId);function Y(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),te.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),k()}let le=()=>$.active||g!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Y(o.recovery,a);let p=Pe(a);o.slot.hidden=p,p!==o.background&&(o.background=p,p?c("run_background",o.entryId):T=y,k())}function pe(e,a,p){let v=e.client.view;if(!a||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let K=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:a}),j=Ae({...n,session:void 0});j.requestWithCredential("funnels",K,e.runToken,{keepalive:p}).then(()=>Z(e.recovery)).catch(()=>{}).finally(()=>j.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<B&&performance.now()<z;function A(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return c("incompatible",e.id),!1}}function H(e){if(t||e.epoch!==P||e.visit!==y||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(e){if(le()){c("in_progress",e.id);return}let a=P,p=y;$.start(e.delivery?.delaySeconds??0,()=>!t&&a===P&&p===y&&document.visibilityState!=="hidden"&&A(e)&&h?.entries.some(v=>v.id===e.id&&v.funnelId===e.funnelId&&v.versionId===e.versionId&&v.event===e.event&&JSON.stringify(v.target)===JSON.stringify(e.target)&&JSON.stringify(v.delivery)===JSON.stringify(e.delivery))===!0,()=>{V(e)},()=>{J.delete(`${e.funnelId}:${e.id}`)})}async function V(e){if(le()){c("in_progress",e.id);return}if(!n.session.peek()){c("identity_required",e.id);return}let a=te.load(),p=a?.entries.find(C=>C.command.funnelId===e.funnelId&&(!C.expiresAt||Date.parse(C.expiresAt)>Date.now()));if(p){if(!X(p)){c("recovery_pending",e.id);return}let C={...p,storageKey:a.key,epoch:P,visit:y};ee.add(C.command.requestId),g=C,await F(C);return}let v=crypto.randomUUID(),K=O.claim(e.id,e.funnelId,e.delivery?.maxPerSession,v);if(K===!1){c("frequency",e.id),k();return}let j={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:K,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:v,locale:document.documentElement.lang||"en"}),epoch:P,visit:y,target:e.target,storageKey:a?.key};ee.add(j.command.requestId),g=j,await F(j)}async function F(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let p,v=!1,K=!1;async function j(C){if(e.epoch!==P)return;let D=C.view;if(!(e.storageKey&&D&&(Pe(D)||D.paywall||D.pendingRequest))&&D&&["running","waiting"].includes(D.status))try{await C.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:D.nodeId,visit:D.visit,revision:D.revision}),Z(e)}catch(x){if(!(x instanceof G&&x.code==="FORBIDDEN"))throw x}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let q=O.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);q!==!1&&(e.deliveryTicket=q)}Y(e),c("starting",e.command.entryId);let C=await b.request("funnels",e.command),D=Ze.safeParse(C);if(D.success){if(D.data.scope.projectId!==f.projectId||D.data.scope.environment!==f.environment)throw new G("SCOPE_MISMATCH","Entry scope changed");e.epoch===P&&c(D.data.reason,e.command.entryId),Z(e),N(e);return}let x=Xe.parse(C);if(!x.runToken||x.scope.projectId!==f.projectId||x.scope.environment!==f.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new G("INVALID_RESPONSE","Invalid entry Run");if(O.accept(e.deliveryTicket,x.run.id),e.epoch!==P){N(e),c("identity_changed",e.command.entryId);return}Y(e,x.run);let L=Ce({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?C:void 0});p=L,K=!0,await L.get(),K=!1;let ne=L.view;if(!ne||ne.id!==x.run.id||ne.source.type!=="funnel"||ne.source.id!==e.command.funnelId||ne.source.versionId!==e.command.versionId)throw new G("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(ne.status)){Z(e),N(e),c("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-H5FM67UC.js");if(!H(e)){await j(L),c("left_screen",e.command.entryId),N(e);return}let Fe=!1,ke=!1;if(o&&!o.background){await j(L),c("in_progress",e.command.entryId),N(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Pe(ne),n.container.append(ie);let xe=await fe(ie,{...n.host,client:L,appManifestRelease:n.appManifestRelease,onState(q){me(L,q),Q(n.host?.onState,q)},onDismiss(q){Fe=!0,ie.remove(),q&&!["running","waiting"].includes(q.status)&&Z(e),o?.client===L&&(o=void 0,L.reset(),k(),q&&q.status!=="completed"&&c("run_ended",e.command.entryId)),Q(n.host?.onDismiss,q)},onComplete(q){ke=!0,Z(e),o?.client===L&&re(),Q(n.host?.onComplete,q)},onError(q){Q(n.host?.onError,q),o?.client===L&&q instanceof G&&q.code==="FORBIDDEN"&&(Z(e),re(),c("run_ended",e.command.entryId))}}).catch(q=>{throw ie.remove(),q});if(!H(e)||Fe||ke){xe.destroy(),ie.remove(),H(e)||await j(L),N(e);return}let he=Pe(L.view??ne);ie.hidden=he,o={host:xe,client:L,slot:ie,entryId:e.command.entryId,background:he,runToken:x.runToken,owner:n.session.peek(),recovery:e},he||(T=e.visit),v=!0,N(e),c("started",e.command.entryId),he&&c("run_background",e.command.entryId)}catch(C){C instanceof G&&(!p||K&&C.code==="FORBIDDEN")&&C.status!==void 0&&C.status>=400&&C.status<500&&!C.retryable&&(Z(e),N(e)),e.epoch===P&&!t&&(c("start_failed",e.command.entryId),Q(n.host?.onError,C))}finally{v||p?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=te.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){te.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||ee.has(a.command.requestId)||!X(a))continue;ee.add(a.command.requestId);let p={...a,storageKey:e.key,epoch:P,visit:y};return g=p,F(p),!0}return!1}function ue(){if(m=!1,$.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(T=y),!ye()){if(!r()){E=!0;return}E=!1;for(let a of h?.entries??[]){let p=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||J.has(p)||!A(a))){if(!n.session.peek()){c("identity_required",a.id);continue}if(T===y){J.add(p),e&&c("in_progress",a.id);continue}if(g||$.active){c("in_progress",a.id);return}J.add(p),W(a);break}}}}let k=()=>{!m&&!t&&(m=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===R?!1:(R=e,y++,$.cancel(),E=!0,J.clear(),ee.clear(),!0)}function oe(){se()&&k()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let p=a.closest("button,a,input");if(!(!p||p.matches(":disabled,[aria-disabled='true']")||p.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of h?.entries??[]){let K=v.target.button;if(!(v.event!=="button_click"||!K||!A(v))){try{let j=be(document);if(!p.matches(K.selector)||j(K.selector,p)!==1)continue}catch{c("incompatible",v.id);continue}W(v);break}}}async function Ne(){if(t)return;if(s)return s;let e=++u,a=new AbortController;_=a;let p,v=new Promise((C,D)=>{p=()=>D(new G("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",p,{once:!0})}),K=setTimeout(()=>a.abort(),n.timeoutMs??5e3),j=(async()=>{let C=async()=>{let fe=await w(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},D=await Promise.race([C(),v]),x=Date.parse(D.validatedAt),L=Date.parse(D.validUntil);if(D.scope.projectId!==f.projectId||D.scope.environment!==f.environment||D.scope.environmentId!==n.environmentId||D.release!==n.appManifestRelease||L<=Date.now()||x>Date.now()+5e3||L-x>6e4||L<=x)throw new G("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==u)return;let ne=h===void 0;h=D,B=L,z=performance.now()+Math.min(L-Date.now(),6e4),$.recheck(),(ne||E)&&k()})();s=j;try{await j}finally{clearTimeout(K),a.signal.removeEventListener("abort",p),s===j&&(s=void 0)}}async function on(){if(!(!i||t)){try{await Ne()}catch{t||c("configuration_unavailable")}k()}}let Oe=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,R=location.origin+location.pathname,M=Ee(oe),S=n.session.subscribeIdentity(()=>{P++,$.cancel(),O.release(g?.deliveryTicket),E=!0,g=void 0,J.clear(),T=-1,ee.clear(),o&&pe(o,o.owner,!1),re(),k()}),l=new MutationObserver(k),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",k),addEventListener("pagehide",ae),await Oe.refresh())},refresh:Ne,async retry(){g&&!t&&g.epoch===P&&await F(g)},destroy(){t=!0,u++,$.cancel(),O.release(g?.deliveryTicket),Oe.destroy(),_?.abort(),l?.disconnect(),M?.(),S?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",k),removeEventListener("pagehide",ae),ae(),re(),b.dispose(),h=void 0}}}function Pn(n){let d=we(n.baseUrl),f=n.fetch??globalThis.fetch.bind(globalThis),b,w=0,h=0,t=!1,i=!1,u=!1,y=0,R=0,P=-1,B=!1,z="",m,s,E,_,M=new Set,S,l,o,T=(r,A)=>Q(n.onStatus,r,A),g=Re(),N=()=>{try{return n.deliveryIdentity?.()}catch{return}},J=()=>JSON.stringify(N()),c=Se({storage:n.deliveryStorage,binding:()=>{let r=N();return r?.id?[d,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>T("delivery_unavailable")}),$=()=>Date.now()<w&&performance.now()<h;function O(r){try{return $()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return T("incompatible",r.id),!1}}function ee(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function te(r){if(r.dispatching)return;r.dispatching=!0;let A=y;try{let H=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});c.accept(r.deliveryTicket,H.run.id);let{showFunnelRun:W}=await import("./funnel-runtime-host-H5FM67UC.js");if(t||A!==y||l!==r)return;let V=document.createElement("div");n.container.append(V),P=R;let F=await W(V,{...n.host,client:H.controller,appManifestRelease:n.appManifestRelease,onDismiss(X){o?.process===r.process&&(o=void 0,V.remove()),Q(n.host?.onDismiss,X)}});if(t||A!==y||l!==r){F.destroy(),V.remove();return}o={entry:r.entry,process:r.process,host:F,slot:V,deliveryTicket:r.deliveryTicket},l=void 0,T("run_presented",r.entry.id)}catch(H){if(t||A!==y||l!==r)return;H instanceof G&&"result"in H?(c.release(r.deliveryTicket),l=void 0,r.process.destroy(),T("suppressed",r.entry.id),Y()):T("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function Z(r){if(t||i||l||o||S||g.active||P===R||!O(r))return;let A=`${R}:${r.id}`;if(M.has(A))return;M.add(A);let H=R,W=y,V=J();g.start(r.delivery?.delaySeconds??0,()=>!t&&y===W&&R===H&&J()===V&&document.visibilityState!=="hidden"&&O(r)&&b?.entries.some(F=>F.id===r.id&&F.funnelId===r.funnelId&&F.versionId===r.versionId&&F.event===r.event&&JSON.stringify(F.target)===JSON.stringify(r.target)&&JSON.stringify(F.delivery)===JSON.stringify(r.delivery))===!0,()=>{let F=c.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(F===!1){T("frequency",r.id),Y();return}try{let X={entry:r,process:n.createProcess(r),visit:R,deliveryTicket:F};l=X,te(X)}catch(X){c.release(F),T("entry_unavailable",r.id),Q(n.host?.onError,X)}},()=>{M.delete(A)})}function Y(){B||t||(B=!0,queueMicrotask(()=>{if(B=!1,g.recheck(),!(t||i||document.visibilityState==="hidden"||!$()||l||o||S||g.active||P===R)){for(let r of b?.entries??[])if(r.event==="screen_enter"&&!M.has(`${R}:${r.id}`)&&O(r)){Z(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||l||o||S||P===R)return;let A=be(document,()=>{});for(let H of b?.entries??[]){let W=H.target.button;if(H.event!=="button_click"||!W||!O(H))continue;let V=r.target.closest(W.selector);if(!(!V||V.tagName.toLowerCase()!==W.tag||A(W.selector)!==1||V.matches(":disabled")||V.closest('[inert],[hidden],[aria-hidden="true"]'))){Z(H);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,R++,g.cancel(),M.clear(),Y())};async function me(){if(t)return;if(s)return s;let r=y,A=new AbortController;m=A;let H,W=new Promise((ye,ue)=>{H=ue}),V=()=>H(new G("TIMEOUT","Funnel entry read cancelled"));A.signal.addEventListener("abort",V,{once:!0});let F=setTimeout(()=>A.abort(),n.timeoutMs??5e3),X=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await f(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:A.signal});if(!ce.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},k=await Promise.race([ue(),W]),se=Date.parse(k.validatedAt),oe=Date.parse(k.validUntil);if(k.scope.projectId!==n.scope.projectId||k.scope.environment!==n.scope.environment||k.scope.environmentId!==n.environmentId||k.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new G("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==y||(b=k,w=oe,h=performance.now()+Math.min(oe-Date.now(),6e4),g.recheck(),Y())})();s=X;try{await X}finally{clearTimeout(F),A.signal.removeEventListener("abort",V),s===X&&(s=void 0)}}async function pe(){if(!(!u||t))try{await me()}catch{t||T("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>u&&!t?15e3:void 0});return{async start(){u||t||(u=!0,z=location.origin+location.pathname,E=Ee(le),_=new MutationObserver(Y),_.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Y),await ae.refresh())},refresh:me,async retry(){l&&!t&&await te(l)},async syncIdentity(){g.cancel();let r=o??l??S;if(!r){i=!1,Y();return}try{let A=await r.process.syncIdentity();return i=!1,S===r&&(l={...r,visit:R},S=void 0,await te(l)),A}catch(A){throw r.process.view||(S={...r,visit:R},l=void 0,ee()),A}},async detach(){i=!0,y++,g.cancel(),m?.abort();let r=o??l??S;r&&(S={...r,visit:R}),l=void 0,ee(),r&&await r.process.detach()},destroy(){t=!0,y++,g.cancel(),ae.destroy(),m?.abort(),_?.disconnect(),E?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Y);let r=o??l??S;c.release(r?.deliveryTicket),l=void 0,S=void 0,ee(),r?.process.destroy(),b=void 0}}}async function _n(n,d){return(await import("./paywall-UANWOKKC.js")).showPaywall(n,d)}async function ot(){return await Promise.all([import("./paywall-UANWOKKC.js"),import("./screen-renderer-FFVZ64MR.js")]),_n}async function at(...n){return n[1]=ze(n[1]),(await import("./paywall-session-3BNUC5ZE.js")).createPaywallSession(...n)}async function st(...n){let d=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-FFVZ64MR.js").catch(()=>{}),import("./paywall-UANWOKKC.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-H5FM67UC.js"),n[1].prepared)).showFunnelRun(...n)}finally{d?.()}}async function rn(n,d){try{return await n()}catch(f){throw d&&d.state!=="adopted"&&await import("./funnel-paywall-prerender-LGUSHEP3.js").then(b=>b.preparedInternals(d)?.release(),()=>{}),f}}async function ct(...n){return import("./screen-renderer-FFVZ64MR.js").catch(()=>{}),import("./paywall-UANWOKKC.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-LMVMJNUO.js"),n[1].prepared)).showFunnelPurchase(...n)}async function dt(...n){return import("./funnel-host-purchase-LMVMJNUO.js").catch(()=>{}),import("./screen-renderer-FFVZ64MR.js").catch(()=>{}),(await import("./funnel-paywall-prerender-LGUSHEP3.js")).prerenderFunnelPurchase(...n)}async function lt(){await Promise.all([import("./funnel-paywall-prerender-LGUSHEP3.js"),import("./funnel-host-purchase-LMVMJNUO.js"),import("./paywall-UANWOKKC.js"),import("./screen-renderer-FFVZ64MR.js"),import("./paywall-content-CHPX2P77.js"),import("./check-response-DRQCUWDW.js"),import("./operation-contracts-O7TCDGV4.js")])}async function ut(...n){return(await import("./content-QUEVNSXD.js")).mountContent(...n)}async function ft(...n){return(await import("./content-QUEVNSXD.js")).prepareContent(...n)}export{G as LongplayError,I as MerchantBridgeError,un as createBrowserFunnelCommandStorage,gn as createBrowserFunnelPurchaseStorage,pn as createConfigurationSync,dn as createFeatureClient,hn as createFunnelClient,En as createFunnelPageExperiments,In as createFunnelProcess,vn as createFunnelPurchaseClient,Ce as createFunnelRunController,Rn as createIamFunnelEntries,Pn as createIamFunnelProcessEntries,wn as createLocalFunnelClient,ln as createLongplay,Sn as createMerchantBridge,at as createPaywallSession,yn as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,fn as getPaywallRecovery,ut as mountContent,lt as preloadFunnelPurchase,ot as preloadPaywall,ft as prepareContent,mn as preparePaywallFallback,dt as prerenderFunnelPurchase,ct as showFunnelPurchase,st as showFunnelRun,_n as showPaywall};
@@ -0,0 +1 @@
1
+ import{N as r,O as m,h as e}from"./chunk-6PG3AS3G.js";import"./chunk-U7GH4VME.js";import"./chunk-FCDWCQYC.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import"./chunk-RULQQ7WI.js";import"./chunk-RGEBK6UF.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{m as merchantBridgeCommerceSchema,r as merchantBridgeOperationSchema,e as merchantOperationLookupSchema};
@@ -1 +1 @@
1
- import"./chunk-QCMFCK7Z.js";import"./chunk-DPIQ3SV7.js";import"./chunk-HFD4CLCJ.js";import"./chunk-IGANLTKS.js";import"./chunk-YURGISSB.js";import{a as i}from"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-JBVZ6A6V.js";import{b as A}from"./chunk-NOOIJXRN.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
1
+ import"./chunk-YY445FBU.js";import"./chunk-57GPGWSK.js";import"./chunk-PZOQV6MU.js";import"./chunk-FCDWCQYC.js";import"./chunk-OOD2VDDP.js";import{a as i}from"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-RV6UAUK2.js";import{b as A}from"./chunk-RGEBK6UF.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
@@ -0,0 +1 @@
1
+ import{e as o}from"./chunk-5DZJCFNQ.js";import"./chunk-YLPQLD2A.js";import"./chunk-ORMQJAQE.js";import"./chunk-RFNIGJOL.js";import"./chunk-6PG3AS3G.js";import"./chunk-EREQZWGI.js";import"./chunk-P23JOPR5.js";import"./chunk-IOJVF52Q.js";import"./chunk-U7GH4VME.js";import"./chunk-33ZVZOSC.js";import"./chunk-57GPGWSK.js";import"./chunk-FCDWCQYC.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import"./chunk-RULQQ7WI.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{o as apiOperations};
package/dist/page.js CHANGED
@@ -1 +1 @@
1
- import{d as o,e as r,f as e,g as f}from"./chunk-CBZ5GW4J.js";import"./chunk-YJS6NNIO.js";import"./chunk-3VUPVXAV.js";import"./chunk-JBVZ6A6V.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
1
+ import{d as o,e as r,f as e,g as f}from"./chunk-2DPNSTCN.js";import"./chunk-C2KT5ZFU.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
@@ -1 +1 @@
1
- import{a as Tt,c as Ot,d as et,f as tt,g as Dt,k as Lt}from"./chunk-525K7BPJ.js";import{b as Xe}from"./chunk-W32FI2A2.js";import{d as Et,e as xt,f as It,h as Ze,i as De,j as At,k as Rt,l as St}from"./chunk-KIPUBMU3.js";import{a as bt,c as Je,d as Ct,e as vt}from"./chunk-3NCMYTNG.js";import{b as ce}from"./chunk-CE5MAAIR.js";import{a as pe,c as Ke,e as Pt,h as kt}from"./chunk-VYI6QRJW.js";import"./chunk-HFD4CLCJ.js";import"./chunk-IGANLTKS.js";import{ca as Ce,ea as ve,i as gt}from"./chunk-BIT6YWM7.js";import{c as fe,j as be}from"./chunk-2Y5SGDC6.js";import{c as Ye}from"./chunk-3JD3U45R.js";import"./chunk-YURGISSB.js";import{a as v}from"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-JBVZ6A6V.js";import"./chunk-NOOIJXRN.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import{a as q}from"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";async function Nt(O,i,R){if(i.status!=="complete")throw new v("INVALID_RESPONSE","A verified completed purchase is required");let P=O?be.parse(O):null;if(await R.onComplete?.(i),!P||!R.check)return;let N=be.parse(await R.check());if(N.internal_feature_id!==P.internal_feature_id||N.quantity!==P.quantity||P.observation!==void 0&&(N.observation===void 0||N.observation.requirementDigest!==P.observation.requirementDigest||N.observation.authority!==P.observation.authority||Ye(N.observation.subject)!==Ye(P.observation.subject)))throw new v("INVALID_RESPONSE","The access requirement changed");N.allowed&&await R.onAccessGranted?.(N)}function nt(O){return Object.entries(O.document.buttons).filter(([,i])=>i.type==="checkout"&&i.product.type==="fixed"&&!ce(i.product,{},O.capabilities)).map(([i])=>i)}function _t(O,i){let R=i.lines[0];if(i.lines.length!==1||!R)return;let P=R.productVersionId,{screen:N,buttons:J}=O.document,x=new Map((R.prepaid??[]).map(m=>[m.internal_feature_id,m.quantity]));function K(m,h){if(m.hidden)return!1;if(m.type==="plan_picker"&&O.capabilities.pickers[m.id]?.options.includes(P))return h[m.id]=P,!0;if(m.type==="quantity_picker"){let Q=x.get(m.internalFeatureId);return Q!==void 0&&(!m.bind?.plan||m.bind.plan===P)&&(h[m.id]=Q),!1}if(m.type==="button"&&m.action){let Q=J[m.action];return Q?.type==="checkout"&&Q.product.type==="fixed"&&Q.product.productVersionId===P}if(m.type!=="stack")return!1;let j=m.interaction,r=m.bind?.plan===P;for(let[Q,p]of m.children.entries()){let te={},S=K(p,te);if(j?.type==="toggle"||j?.type==="tabs"){if(!S)continue;return h[m.id]=j.type==="toggle"?Q===0:p.id,Object.assign(h,te),!0}Object.assign(h,te),S&&(r=!0,j?.type==="select"&&j.purpose==="product"&&j.pickerId&&p.type==="stack"&&p.bind?.plan===P&&(h[m.id]=p.id,h[j.pickerId]=P))}return r}for(let m of N.pages){let h={__page:m.id};if(K(m.root,h))return h}}async function Pn(O,i,R){let P=i.focusAtReveal?()=>{}:Ze(O.ownerDocument),N=()=>{x.finish("dismissed"),P()},J=()=>N(),x=At(O,i,"paywall",()=>{N(),q(i.onDismiss)},Tt);i.signal?.throwIfAborted(),i.signal?.addEventListener("abort",J,{once:!0});let K=null,m,h,j;try{if(x.start(!0,i.loadingDocument?.screen.strings.defaultLocale,i.loadingDocument??null),x.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(K=i.check?be.parse(await x.wait(i.check(),De)):null,K?.allowed)return x.finish("skipped"),i.signal?.removeEventListener("abort",J),P(),await i.onAccessGranted?.(K),{check:K,host:null};let[e,t]=await Promise.allSettled([x.wait(import("./screen-renderer-5SJCTMJH.js")),x.wait(i.start().then(o=>(x.cancelled&&o.destroy(),o)),De)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;j=e.value,m=t.value,i.signal?.throwIfAborted(),m.signal?.throwIfAborted(),m.signal?.addEventListener("abort",J,{once:!0});let n=m.view??await x.wait(m.refresh(),De);if(!n)throw new v("INVALID_RESPONSE","Paywall presentation is missing");m.signal?.throwIfAborted(),h=n}catch(e){throw x.finish("error",e),i.signal?.removeEventListener("abort",J),m?.signal?.removeEventListener("abort",J),m?.destroy(),P(),e}let r=m,{mountScreenPreview:Q}=j,p=O.ownerDocument,te=new AbortController,S=p.createElement("section"),le=p.createElement("div"),G=p.createElement("div"),Le=i.mountControls,V=Le?p.createElement("div"):void 0,u=p.createElement("p"),g=p.createElement("button"),k=p.createElement("button"),I=p.createElement("dialog"),rt=r.locale||h.document.screen.strings.defaultLocale,a=rt.toLowerCase().startsWith("zh"),Ut=a?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",Mt=a?"\u6B63\u5728\u51C6\u5907\u62A5\u4EF7\u2026":"Preparing your price\u2026",D=Ot(h.document.screen.theme);S.dataset.indianaPaywall="",S.setAttribute("aria-label",h.document.name),S.style.cssText=D.root,G.style.cssText=D.controls,u.style.cssText=D.message,u.setAttribute("role","status"),k.style.cssText=D.link,k.textContent=a?"\u5173\u95ED":"Close",g.style.cssText=D.secondary,g.textContent=a?"\u91CD\u8BD5":"Retry",g.hidden=!0,G.append(u,g,k),V&&(V.style.cssText="flex:1 0 100%;min-width:0",V.hidden=!0,G.prepend(V)),S.append(le,G);let Ne=()=>{if(V){let o=!V.childElementCount&&!V.textContent?.trim();V.hidden!==o&&(V.hidden=o)}let e=ne??G,t=[...e.children].every(o=>o===u?!u.textContent:o.hidden),n=[...e.children].some(o=>o===k?!1:o===u?!!u.textContent:!o.hidden);e.style.cssText=t?D.controls.replace(/padding:[^;]+/,"padding:0"):n?`${D.controls};${D.pinned}`:D.controls,Me()},it=typeof MutationObserver>"u"?void 0:new MutationObserver(Ne);it?.observe(S,{attributes:!0,attributeFilter:["hidden"],characterData:!0,childList:!0,subtree:!0});let Pe=h.document.presentation,qt=Object.entries(h.document.buttons).filter(([,e])=>e.type==="close").map(([e])=>e),$,ot,_e=!1,at=JSON.stringify(h.capabilities),st=e=>oe&&!he?Object.entries(e.document.buttons).filter(([,t])=>t.type==="checkout").map(([t])=>t):nt(e);function ke(e){if(y)return;h=e;let t=JSON.stringify(e.capabilities);t!==at&&($?.updateCapabilities(pe(e),st(e)),at=t),Ht(e),ye()}let E,Ue=0;function Me(){let e=p.defaultView;if(!E?.responsive||!e)return;let t=ne??G,n=e.innerHeight-(E.type==="modal"?32:0);t.style.maxHeight=`${Math.max(1,n)}px`,t.style.overflowY="auto",t.style.flexShrink="0",Ue=Math.max(1,n-t.getBoundingClientRect().height),$?.resizeViewport?.(Ue,e.innerWidth)}let y=!1,oe=!1,C=null,qe,Ee=!1,ct=!1,ae=!1,Ve,$e=!1,X,ne;function Vt(){return oe||y||X||$e?{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null}:Je(r)}let A=()=>!y&&!Ee&&!X&&i.canInteract?.()!==!1,H,ue=!1,d=null,Z=null,He="",se=()=>i.checkoutNavigation==="after_confirmation"&&!!(i.terminateCheckout||i.resumeCheckout),me={},he,W=null;function ye(){if(!se()||!$?.updateCheckoutControls)return;let e=r.quote,t=!W&&!!e&&!!r.operation&&B(r.operation).type==="checkout",n=Object.entries(h.document.buttons).flatMap(([o,c])=>c.type==="checkout"?[{actionId:o,policy:c}]:[]);$.updateCheckoutControls({actions:n.map(({actionId:o})=>o),resume:t?n.filter(({actionId:o,policy:c})=>Ae(e,h,o,c.product,me)).map(({actionId:o})=>o):[],resumeLabel:a?"\u7EE7\u7EED\u4ED8\u6B3E":"Continue checkout",busy:he})}function lt(){Z?.remove(),Z=null}async function Be(){if(W)return;if(i.resumeCheckout&&r.operation){await i.resumeCheckout(r.operation.operationId);return}let e=await r.read();if(B(e).type!=="checkout")return _(e,!1);A()&&(xe.delete(e.operationId),await Re(e))}function ut(){u.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u6253\u5F00\u4ED8\u6B3E\u9875\u9762\u3002\u8BF7\u91CD\u8BD5\u3002":"Couldn\u2019t open checkout. Try again.",g.hidden=!0}async function dt(e=!1){let t=W;if(!t)return;g.hidden=!0;let n=Date.now()+2e4;for(;A();){let o=await r.read();if(o.operationId!==t.operationId)throw new v("PURCHASE_PENDING","The original Checkout changed");if(!A())break;let c=B(o);if(c.type==="native"){W=null,lt(),C=t.selection,H=t.coupon,ue=!1,await ge();return}if(c.type==="complete"||c.type==="fulfillment"||c.type==="recording"){W=null,await _(o,!1);return}if(e&&c.type==="checkout"){e=!1;try{await i.terminateCheckout(t.operationId)}catch(w){q(i.onError,w)}}if(Date.now()>=n)break;await Xe(1e3,p,te.signal)}y||ut()}async function $t(e,t,n){W={operationId:e,selection:t,coupon:n};let o=!1;try{await i.terminateCheckout(e)}catch(c){if(c instanceof v&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(c.code)){W=null,u.textContent=a?"\u8BF7\u7EE7\u7EED\u539F\u8BA2\u5355\uFF0C\u6216\u7B49\u5F85\u5B83\u8FC7\u671F\u540E\u518D\u66F4\u6362\u65B9\u6848\u3002":"Continue your original checkout, or wait for it to expire before changing plans.",q(i.onError,c);return}o=c instanceof v&&(c.status??0)>=500,q(i.onError,c)}A()&&await dt(o)}function Fe(e,t,n,o,c){let w=pe(e).checkoutCoupons?.[t],l=w?w.products[n]:i.claimCoupon&&c?gt(e.capabilities,c,o):void 0;return l?.couponId&&l.planVersionId===n?{id:l.couponId,offerId:l.offerId}:void 0}function Ht(e){oe||C||r.quote||r.operation||He&&u.textContent===He||(u.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":a?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let xe=new Map,Ie=!1;function Ae(e,t,n,o,c,w){let l=e.lines.length===1?e.lines[0]:void 0,s=ce(o,c,t.capabilities);if(!l||!s||l.productVersionId!==s)return!1;let L=Fe(t,n,s,c,w);if((L||pe(t).checkoutCoupons?.[n])&&(L?.id??null)!==(e.discount?.couponId??null))return!1;let U;try{U=ve(t.document.screen,s,c,t.capabilities)}catch{return!1}let ie=Object.fromEntries((l.prepaid??[]).map(z=>[z.internal_feature_id,z.quantity]));return[...new Set([...Object.keys(U),...Object.keys(ie)])].every(z=>(U[z]??0)===(ie[z]??0))}let B=e=>bt({quote:r.quote,operation:e,requestId:null,pending:!1,destroyed:y,canReselect:r.canReselect});async function Re(e){let t=e.merchantExecution;if(!(!A()||!e.checkoutUrl||i.checkoutNavigation==="after_confirmation"&&B(e).type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||xe.get(e.operationId)===e.checkoutUrl)){xe.set(e.operationId,e.checkoutUrl);try{i.onCheckoutUrl?await i.onCheckoutUrl(e.checkoutUrl):p.defaultView?.location.assign(e.checkoutUrl)}catch(n){throw xe.delete(e.operationId),n}}}let re=(e,t=!1)=>{if(e instanceof Ke)d=null,u.textContent=e.customerMessage(a);else if(Dt(e))d=null,u.textContent=t?a?"\u5F53\u524D\u65E0\u6CD5\u5728\u6B64\u8D2D\u4E70\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u3002":"Purchases aren\u2019t available here right now. Payment hasn\u2019t started. Contact the merchant for help.":tt(e,a);else if(t){let n=e instanceof v?e.code:void 0;n==="CAPABILITY_UNAVAILABLE"||n==="NOT_CONFIGURED"?(d=null,u.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u4E3A\u6B64\u5957\u9910\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002":"Pricing for this plan is unavailable. Payment hasn\u2019t started."):r.canReselect===!0&&!C?u.textContent=a?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u65B0\u9009\u62E9\u5957\u9910\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Choose a plan again.":n==="COMMAND_PENDING"?u.textContent=a?"\u4ECD\u5728\u51C6\u5907\u62A5\u4EF7\uFF0C\u8BF7\u91CD\u8BD5\u4EE5\u67E5\u770B\u7ED3\u679C\u3002":"Your price is still being prepared. Retry to check the result.":u.textContent=a?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u8BD5\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Try again."}else u.textContent=e instanceof v&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT")?tt(e,a):e instanceof v?e.message:a?"\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5\u3002":"This action couldn\u2019t be completed. Try again.";g.hidden=d===null,He=u.textContent,t&&!E?.responsive&&u.scrollIntoView?.({block:"nearest"}),q(t&&R?.quoteError?R.quoteError:i.onError,e)},Se=new WeakMap;function Te(e){oe=e,g.disabled=e,$?.updateCapabilities?.(pe(h),st(h));for(let t of Z?.querySelectorAll("button")??[])e?(Se.set(t,t.disabled),t.disabled=!0):Se.has(t)&&(t.disabled=Se.get(t),Se.delete(t)),et(t)}function je(){u.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002":"This action is unavailable right now. Try again in a moment."}async function Bt(e){if(i.beforeAction)try{await i.beforeAction()}catch(t){throw t instanceof Ke?(C=null,ue=!1,d=null):d=e,t}}async function M(e,t){if(oe||y)return;if(!A()){je();return}let n=e===ge,o=n?Mt:Ut,c=se()&&t!==void 0;he=c?t:void 0,Te(!0),ye(),g.hidden=!0,u.textContent=c?"":o;try{if((e!==Be||!i.resumeCheckout)&&await Bt(e),y)return;if(!A()){d=e,g.hidden=!1,je();return}await e()}catch(w){y||re(w,n&&!c)}finally{he=void 0,Te(!1),ye(),u.textContent===o&&(u.textContent="")}}async function Ft(e){await Nt(K,e,i)}function ft(e){return Je(r).type==="recording"||B(e).type==="recording"}function pt(e){let t=e.merchantTerms,n=t?.subscriptionTerms?.items??[],o=t?t.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),c=t?n.length===1&&n[0]?.amountMinor===o&&n[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===o&&e.lines[0],w=o===null?fe(t.subtotalMinor-t.discountMinor,e.currency)+(a?" + \u5F85\u786E\u8BA4\u7A0E\u8D39":" + tax confirmed at checkout"):fe(o,e.currency)+(c?Ce(c.interval,a?"zh-CN":"en",c.intervalCount??1):""),l=e.lines.map(s=>s.productName).join(", ");return{label:l?`${l} \xB7 ${w}`:w,recurring:c}}async function _(e,t=i.checkoutNavigation!=="after_confirmation"){if(y)return;if(!A()){d=async()=>_(await r.read()),g.hidden=!1;return}if(u.textContent=Lt(e.status,a),ft(e)){let s=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";u.textContent=s?a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u4F46\u4EA4\u6613\u8BB0\u5F55\u5931\u8D25\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u4FEE\u590D\uFF0C\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u6B63\u5728\u786E\u8BA4\u4EA4\u6613\u8BB0\u5F55\u3002\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",g.textContent=a?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",d=async()=>_(await r.read()),g.hidden=!1;return}if(e.problem){let s=e.problem;d=we,g.textContent=a?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",re(new v(s.code,s.reason==="RESULT_UNKNOWN"?a?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":s.phase==="fulfillment"?a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":s.code==="CAPABILITY_UNAVAILABLE"?a?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":s.code==="NOT_CONFIGURED"?a?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":a?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,s));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(u.textContent=a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){d=null,await Ft(e);return}if(e.status!=="pending"){if(r.canReselect===!1){u.textContent=a?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",g.textContent=a?"\u67E5\u8BE2\u7ED3\u679C":"Check result",d=async()=>_(await r.read()),g.hidden=!1;return}e.status==="cancelled"?u.textContent=a?"\u8FD9\u7B14\u8D2D\u4E70\u5DF2\u53D6\u6D88\uFF0C\u53EF\u4EE5\u91CD\u65B0\u9009\u62E9\u65B9\u6848\u3002":"This purchase was cancelled. Choose a plan to start again.":e.status==="failed"&&(u.textContent=a?"\u8FD9\u7B14\u8D2D\u4E70\u672A\u80FD\u5B8C\u6210\uFF0C\u53EF\u4EE5\u91CD\u65B0\u9009\u62E9\u65B9\u6848\u3002":"This purchase didn\u2019t go through. Choose a plan to try again."),g.textContent=a?"\u91CD\u8BD5":"Retry",d=null,C=null;return}if(!t&&B(e).type==="checkout"){if(W){ut();return}if(se()){u.textContent="",Ie=!1,d=null,ye();return}let s=r.quote,L=s?.operationId===e.operationId?pt(s).label:"";u.textContent=Ie?L?a?`${L} \u5C1A\u672A\u4ED8\u6B3E\u3002\u518D\u6B21\u9009\u62E9\u8BE5\u65B9\u6848\u5373\u53EF\u7EE7\u7EED\u4ED8\u6B3E\u3002`:`${L} is still unpaid. Choose it again to continue paying.`:a?"\u4E4B\u524D\u7684\u8D2D\u4E70\u5C1A\u672A\u4ED8\u6B3E\u3002\u518D\u6B21\u9009\u62E9\u8BE5\u65B9\u6848\u5373\u53EF\u7EE7\u7EED\u4ED8\u6B3E\u3002":"Your earlier purchase is still unpaid. Choose that plan again to continue paying.":"",Ie=!1,d=null;return}await Re(e);let n=Date.now(),o=n+6e5,c=2e3,w=!e.checkoutUrl,l=()=>w&&Date.now()-n<15e3;_e=!0,q(i.onObservationChange,!0);try{for(;!y&&Date.now()<o;){if(await Xe(l()?700:c,p,te.signal),y)return;if(!A()){d=async()=>_(await r.read()),g.hidden=!1;return}let s=await r.read();if(s.checkoutUrl&&(w=!1),!t&&B(s).type==="checkout"){await _(s,!1);return}if(!s.problem&&s.status==="pending"&&await Re(s),s.status!=="pending"||s.problem||ft(s)){await _(s);return}l()||(c=Math.min(c*1.5,3e4))}}finally{_e=!1,q(i.onObservationChange,!1)}d=async()=>_(await r.read()),g.hidden=!1}async function Qe(e=!1){let t=await r.read();if(y)return;if(!A()){d=()=>Qe(e),g.hidden=!1;return}let n=r.quote;if(n&&Pt(t,{operationId:n.operationId,currency:n.currency},"The original purchase operation changed"),n&&t.status==="pending"&&t.quoteFinalized===!1&&!t.confirmedAt&&!t.checkoutUrl&&!t.nativePurchase&&!t.merchantExecution&&!t.problem&&!r.pendingCancellation){mt(n);return}await _(t,e||void 0)}async function we(){lt(),d=we;let e=await r.confirm();if(!A()){d=we,g.hidden=!1;return}if(e.problem){await _(e);return}if(e.status==="pending"){if(e.checkoutUrl)await Re(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!i.onPurchase)throw new v("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await i.onPurchase({operation:e,signal:te.signal})}}d=async()=>_(await r.read()),await _(e,!0)}function mt(e){Z?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());u.textContent=t?a?"\u6B64\u62A5\u4EF7\u5DF2\u8FC7\u671F\u3002\u8BF7\u5148\u53D6\u6D88\uFF0C\u518D\u91CD\u65B0\u9009\u62E9\u3002":"This quote has expired. Cancel it, then choose again.":"";let n=p.createElement("div"),o=p.createElement("button"),c=p.createElement("button"),w=p.createElement("div"),l=p.createElement("p"),s=e.merchantTerms,L=a?"zh-CN":"en",U=s?.subscriptionTerms?.items??[],ie=s?s.subscriptionTerms?.trial?.days:e.lines.find(f=>f.trial)?.trial?.days,ee=ie===void 0?null:s?s.totalMinor:e.charge?e.charge.totalMinor:e.lines.every(f=>f.trial)?0:null,z=(f,b)=>a?`${b} \u5929\u8BD5\u7528\u7ED3\u675F\u540E ${f}`:`Then ${f} after the ${b}-day trial`,{label:ze,recurring:ht}=pt(e),jt=e.lines.map(f=>f.productName).join(", "),yt=ee===null?"":`${a?"\u4ECA\u5929\u5E94\u4ED8":"Due today"} ${fe(ee,e.currency)}`;l.textContent=yt?[jt,yt].filter(Boolean).join(" \xB7 "):ze,o.textContent=a?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",o.disabled=t,c.textContent=a?"\u53D6\u6D88":"Cancel",n.style.cssText=D.panel,l.style.cssText=D.summary,w.style.cssText=D.actions,o.style.cssText=D.primary,c.style.cssText=D.secondary,et(o),o.onclick=()=>{M(we)};let wt=async()=>{let f=await r.cancel();y||(n.remove(),Z=null,await _(f))};c.onclick=()=>{d=wt,M(wt)};let F=p.createElement("div");if(F.style.cssText=D.terms,s){for(let b of U){if(ee===null&&b===ht)continue;let T=p.createElement("p"),Y=fe(b.amountMinor,e.currency)+Ce(b.interval,L,b.intervalCount);T.textContent=ee!==null&&ie!==void 0?z(Y,ie):Y,F.append(T)}let f=s.subscriptionTerms?.trial;if(f){let b=p.createElement("p");b.textContent=a?`\u8BD5\u7528 ${f.days} \u5929\uFF1B${f.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${f.days}; ${f.cardRequired?"a payment method is required":"no payment method is required"}`,F.append(b)}for(let b of[...s.expectedEffects.map(T=>T.description),...s.requiredConsents.map(T=>T.summary)]){let T=p.createElement("p");T.textContent=b,F.append(T)}}else{for(let f of e.lines){if(ee!==null||f!==ht){let b=p.createElement("p"),T=`${fe(f.catalogAmountMinor,e.currency)}${Ce(f.interval,L,f.intervalCount??1)}`;b.textContent=ee!==null&&f.trial?(e.lines.length>1?`${f.productName} \xB7 `:"")+z(T,f.trial.days):`${f.productName} \xB7 ${T}`,F.append(b)}for(let b of f.prepaid??[]){let T=p.createElement("p"),Y=r.view?.capabilities.plans[f.productVersionId]?.prepaid?.find(Qt=>Qt.internalFeatureId===b.internal_feature_id);T.textContent=`${Y?.name??b.internal_feature_id} \xB7 ${b.quantity} ${a?"\u4EFD":"packs"} \xD7 ${b.terms.units}`,Y&&(T.textContent+=Ce(Y.reset==="week"||Y.reset==="month"||Y.reset==="year"?Y.reset:"one_time",L,Y.resetCount)),F.append(T)}if(f.trial){let b=p.createElement("p");b.textContent=a?`\u8BD5\u7528 ${f.trial.days} \u5929\uFF1B${f.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${f.trial.days}; ${f.trial.cardRequired?"a payment method is required":"no payment method is required"}`,F.append(b)}}if(!e.charge){let f=p.createElement("p");f.textContent=a?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",F.append(f)}}for(let f of F.children)f.style.margin="0";w.append(o,c),n.append(l,...F.childElementCount?[F]:[],w),G.prepend(n),E?.responsive||n.scrollIntoView?.({block:"nearest"}),o.focus({preventScroll:!0}),Z=n,d=null}async function ge(){if(!C)return;if(d=ge,!ue){let n=r.view,o=n?.document.buttons[C.actionId],c=n&&o?.type==="checkout"?ce(o.product,C.selection,n.capabilities):null;if(!n||!c)throw new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let w=H?.offerId;if(H&&!w){if(!i.claimCoupon)throw new v("CAPABILITY_UNAVAILABLE","Coupon claiming is unavailable");let{offer:l}=await i.claimCoupon(H.id,C.requestId);if(y)return;if(!l||l.couponId!==H.id||l.status!=="issued"||!(Date.parse(l.expiresAt)>Date.now()))throw C=null,H=void 0,d=async()=>{ke(await r.refresh()),d=null},new v("COUPON_UNAVAILABLE","This Coupon is no longer available for this purchase");w=l.id}if(!H&&!n.document.screen.actions.some(l=>l.id===C?.actionId&&typeof l.properties.couponBinding=="string")&&(w=await i.resolveOfferId?.({actionId:C.actionId,productVersionId:c,featureQuantities:ve(n.document.screen,c,C.selection,n.capabilities)})),y)return;w!==void 0&&(C.offerId=w),ue=!0}if(!A()){g.hidden=!1;return}let e;try{e=await r.preview(C)}catch(n){throw r.canReselect===!0&&(C=null,ue=!1,H=void 0,d=null),n}if(H&&(e.discount?.couponId!==H.id||e.discount.offerId!==C.offerId))throw new v("INVALID_RESPONSE","The quote did not apply the Coupon selected on this Paywall");if(y)return;let t=e.merchantTerms;if(i.confirmOnHostedCheckout&&A()&&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()){let n=he?"":a?"\u6B63\u5728\u6253\u5F00\u6536\u94F6\u53F0\u2026":"Opening checkout\u2026";u.textContent=n;try{await we()}catch(o){y||re(o)}finally{u.textContent===n&&(u.textContent="")}return}mt(e)}function de(e="destroy"){if(y)return;y=!0;let t=qe;qe=void 0,q(t),i.signal?.removeEventListener("abort",J),r.signal?.removeEventListener("abort",J),x.finish("dismissed"),ot?.(),te.abort(),it?.disconnect(),E?.destroy(),$?.destroy(),r.destroy(),I.open&&I.close(),I.remove(),S.remove(),P(),e==="dismiss"&&q(i.onDismiss)}N=de;async function Oe(){if(!ae||y||Ee||X==="closing"||!X&&!A())return;if(!R){de("dismiss");return}let e=p.createElement("p");e.setAttribute("role","status"),e.textContent=a?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",ne||(ne=p.createElement("div"),ne.style.cssText=G.style.cssText,G.replaceWith(ne),le.inert=!0),k.hidden=!1,ne.replaceChildren(e,k),X="closing",k.setAttribute("aria-disabled","true"),k.focus({preventScroll:!0});try{await R.dismiss()}catch(t){y||q(i.onError,t)}y||(X="retry",e.textContent=a?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",k.textContent=a?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",k.removeAttribute("aria-label"),k.removeAttribute("aria-disabled"))}k.onclick=()=>{Oe()},I.addEventListener("cancel",e=>{e.preventDefault(),Oe()}),g.onclick=()=>{d&&M(d)};function Ge(e){x.finish("error",e),de()}function We(){if(!(!ct||ae||y||Ee||E&&!A()))try{let e=t=>{i.focusAtReveal&&(P=Ze(p)),$?.setHidden?.(!1),Ve?.(),E&&(I.showModal(),E.responsive&&I.focus({preventScroll:!0}),!t&&i.loading!=="host"&&xt(I,E.type,E.responsive)),ae=!0};R?R.present(()=>x.present(()=>e(!0))):x.present(e)}catch(e){Ge(e),re(e)}}try{if(Pe.type==="inline"?(Ne(),Ve=St(S,O),O.append(S)):(I.setAttribute("aria-label",h.document.name),k.textContent="\xD7",k.setAttribute("aria-label",a?"\u5173\u95ED":"Close"),It(k,h.document.screen.theme),k.hidden=kt(h.document),I.append(k,S),O.append(I),E=Et(I,{...h.document.screen,presentation:Pe},Me),E.latch(),E.responsive&&(S.style.display="flex",S.style.flexDirection="column",S.style.maxHeight="100%",le.style.overflow="clip",le.style.minHeight="0"),Ve=Rt(I)),Le&&V){let n=Le(V);if(typeof n=="function"&&(y?q(n):qe=n),y)throw new DOMException("Presentation cancelled","AbortError");Ne()}$=Q(le,{mode:"live",rendererUrl:r.webViewUrl,title:h.document.name,closeActions:qt,onAuthoredClose(n){X||y||(k.hidden=n)},hostPresentation:()=>E?.type??Pe.type,reportContentHeight:E?.responsive,onResize:n=>{if(!E?.responsive)return;let o=Math.min(n,Ue);le.style.height=`${o}px`,E.setContentHeight(o+(ne??G).getBoundingClientRect().height)},onSelection(n){me=n,ye()},onAction(n,o={},c,w){if(!ae||y||X)return;let l=r.view,s=l?.document.buttons[n];if(!s)return;if(s.type==="close"&&R&&i.resumeCheckout&&r.operation&&Ct(B(r.operation))){Oe();return}if(oe)return;if(!A()){je();return}if(s.type==="close"){M(async()=>{await i.onAction?.(n),de(i.onAction?"action":"dismiss")});return}if(s.type==="action"){d=async()=>{if(s.action.type==="event"){if(!i.onEvent)throw new v("EVENT_HANDLER_REQUIRED","Provide the event handler");await i.onEvent(s.action.event)}else i.onOpenUrl?await i.onOpenUrl(s.action.url):p.defaultView?.location.assign(s.action.url);await i.onAction?.(n),d=null},M(d);return}if(i.allowNewPurchase===!1){se()&&l&&r.quote&&r.operation&&B(r.operation).type==="checkout"&&Ae(r.quote,l,n,s.product,o,w)?M(Be,n):u.textContent=a?"\u5F53\u524D\u53EA\u80FD\u7EE7\u7EED\u539F\u8BA2\u5355\u3002":"Only your original checkout is available.";return}if(Z&&r.canReselect===!1){u.textContent=a?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",E?.responsive||Z.scrollIntoView?.({block:"nearest"}),Z.querySelector("button")?.focus({preventScroll:!0});return}if(se()&&W){W.selection.actionId===n&&M(()=>dt(!0),n);return}if(se()&&i.terminateCheckout&&l&&r.quote&&r.operation&&r.canReselect===!1&&B(r.operation).type==="checkout"){if(Ae(r.quote,l,n,s.product,o,w)){M(Be,n);return}let U=ce(s.product,o,l.capabilities);try{if(!U)throw new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");ve(l.document.screen,U,o,l.capabilities)}catch(ze){re(ze);return}let ie=r.operation.operationId,ee={actionId:n,requestId:crypto.randomUUID(),selection:structuredClone(o)},z=Fe(l,n,U,o,w);M(()=>$t(ie,ee,z),n);return}if((r.quote||C)&&r.canReselect===!1){let U=!!l&&!!r.quote&&Ae(r.quote,l,n,s.product,o,w);Ie=!!r.quote&&!U,d=r.quote?()=>Qe(U):ge,M(d);return}let L=l&&ce(s.product,o,l.capabilities);if(!l||!L){re(new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(i.onPurchaseIntent){d=null,M(async()=>{let U={actionId:n,productVersionId:L,selection:structuredClone(o),featureQuantities:ve(l.document.screen,L,o,l.capabilities)};$e=!0,await i.onPurchaseIntent(U)});return}if(C&&C.actionId!==n){re(new v("COMMAND_PENDING","Finish the current purchase"));return}C||(H=Fe(l,n,L,o,w),C={requestId:crypto.randomUUID(),actionId:n,selection:structuredClone(o)},ue=!1),M(ge,n)},onEscape:()=>{Oe()},onError:n=>{let o=new Error(n);!ae&&!y&&Ge(o),re(o)},onRendered:n=>{n&&I.setAttribute("aria-label",n),ct=!0,We()}}),$.setHidden?.(!0),Me();let e=se()&&!!r.quote&&!!r.operation&&B(r.operation).type==="checkout";me=e?_t(h,r.quote)??{}:{},$.update(h.document.screen,rt,{capabilities:pe(h),unavailableActions:nt(h),serverInput:{bindings:[],answers:{}},...Object.keys(me).length?{selection:me}:{}}),ot=r.subscribe?.(ke),ke(r.view??h),await x.wait($.ready);let t=r.operation;!e&&(r.quote||t&&(t.confirmedAt||t.checkoutUrl||t.status==="complete"))&&(d=()=>Qe(),M(d))}catch(e){throw Ge(e),e}return{check:K,host:{get observing(){return _e},get recovery(){return Vt()},async prepareFallback(){if(oe||y||X||$e)return{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null};Te(!0);try{let e=await vt(r);return e.type==="native"&&de(),e}finally{Te(!1)}},setSuspended(e){Ee=e,S.hidden=e,e&&I.open?I.close():!e&&!ae?We():!e&&!y&&ae&&Pe.type!=="inline"&&!I.open&&I.showModal()},destroy:de,refresh:async()=>{if(!A()){if(r.view)return r.view;throw new v("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return ke(e),We(),e}}}}export{Pn as showPaywall};
1
+ import{a as Tt,c as Ot,d as et,f as tt,g as Dt,k as Lt}from"./chunk-CZ4TQCUV.js";import{b as Xe}from"./chunk-W32FI2A2.js";import{d as Et,e as xt,f as It,h as Ze,i as De,j as At,k as Rt,l as St}from"./chunk-P6C3PNMQ.js";import{a as bt,c as Je,d as Ct,e as vt}from"./chunk-3NCMYTNG.js";import{b as ce}from"./chunk-33ZVZOSC.js";import{a as pe,c as Ke,e as Pt,h as kt}from"./chunk-VOKEZHAH.js";import"./chunk-PZOQV6MU.js";import"./chunk-FCDWCQYC.js";import{ca as Ce,ea as ve,i as gt}from"./chunk-XDOKFAE6.js";import{c as fe,j as be}from"./chunk-Y6HL2IY2.js";import{c as Ye}from"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import{a as v}from"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-RV6UAUK2.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import{a as q}from"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";async function Nt(O,i,R){if(i.status!=="complete")throw new v("INVALID_RESPONSE","A verified completed purchase is required");let P=O?be.parse(O):null;if(await R.onComplete?.(i),!P||!R.check)return;let N=be.parse(await R.check());if(N.internal_feature_id!==P.internal_feature_id||N.quantity!==P.quantity||P.observation!==void 0&&(N.observation===void 0||N.observation.requirementDigest!==P.observation.requirementDigest||N.observation.authority!==P.observation.authority||Ye(N.observation.subject)!==Ye(P.observation.subject)))throw new v("INVALID_RESPONSE","The access requirement changed");N.allowed&&await R.onAccessGranted?.(N)}function nt(O){return Object.entries(O.document.buttons).filter(([,i])=>i.type==="checkout"&&i.product.type==="fixed"&&!ce(i.product,{},O.capabilities)).map(([i])=>i)}function _t(O,i){let R=i.lines[0];if(i.lines.length!==1||!R)return;let P=R.productVersionId,{screen:N,buttons:J}=O.document,x=new Map((R.prepaid??[]).map(m=>[m.internal_feature_id,m.quantity]));function K(m,h){if(m.hidden)return!1;if(m.type==="plan_picker"&&O.capabilities.pickers[m.id]?.options.includes(P))return h[m.id]=P,!0;if(m.type==="quantity_picker"){let Q=x.get(m.internalFeatureId);return Q!==void 0&&(!m.bind?.plan||m.bind.plan===P)&&(h[m.id]=Q),!1}if(m.type==="button"&&m.action){let Q=J[m.action];return Q?.type==="checkout"&&Q.product.type==="fixed"&&Q.product.productVersionId===P}if(m.type!=="stack")return!1;let j=m.interaction,r=m.bind?.plan===P;for(let[Q,p]of m.children.entries()){let te={},S=K(p,te);if(j?.type==="toggle"||j?.type==="tabs"){if(!S)continue;return h[m.id]=j.type==="toggle"?Q===0:p.id,Object.assign(h,te),!0}Object.assign(h,te),S&&(r=!0,j?.type==="select"&&j.purpose==="product"&&j.pickerId&&p.type==="stack"&&p.bind?.plan===P&&(h[m.id]=p.id,h[j.pickerId]=P))}return r}for(let m of N.pages){let h={__page:m.id};if(K(m.root,h))return h}}async function Pn(O,i,R){let P=i.focusAtReveal?()=>{}:Ze(O.ownerDocument),N=()=>{x.finish("dismissed"),P()},J=()=>N(),x=At(O,i,"paywall",()=>{N(),q(i.onDismiss)},Tt);i.signal?.throwIfAborted(),i.signal?.addEventListener("abort",J,{once:!0});let K=null,m,h,j;try{if(x.start(!0,i.loadingDocument?.screen.strings.defaultLocale,i.loadingDocument??null),x.cancelled)throw new DOMException("Presentation cancelled","AbortError");if(K=i.check?be.parse(await x.wait(i.check(),De)):null,K?.allowed)return x.finish("skipped"),i.signal?.removeEventListener("abort",J),P(),await i.onAccessGranted?.(K),{check:K,host:null};let[e,t]=await Promise.allSettled([x.wait(import("./screen-renderer-FFVZ64MR.js")),x.wait(i.start().then(o=>(x.cancelled&&o.destroy(),o)),De)]);if(e.status==="rejected")throw t.status==="fulfilled"&&t.value.destroy(),e.reason;if(t.status==="rejected")throw t.reason;j=e.value,m=t.value,i.signal?.throwIfAborted(),m.signal?.throwIfAborted(),m.signal?.addEventListener("abort",J,{once:!0});let n=m.view??await x.wait(m.refresh(),De);if(!n)throw new v("INVALID_RESPONSE","Paywall presentation is missing");m.signal?.throwIfAborted(),h=n}catch(e){throw x.finish("error",e),i.signal?.removeEventListener("abort",J),m?.signal?.removeEventListener("abort",J),m?.destroy(),P(),e}let r=m,{mountScreenPreview:Q}=j,p=O.ownerDocument,te=new AbortController,S=p.createElement("section"),le=p.createElement("div"),G=p.createElement("div"),Le=i.mountControls,V=Le?p.createElement("div"):void 0,u=p.createElement("p"),g=p.createElement("button"),k=p.createElement("button"),I=p.createElement("dialog"),rt=r.locale||h.document.screen.strings.defaultLocale,a=rt.toLowerCase().startsWith("zh"),Ut=a?"\u6B63\u5728\u5904\u7406\u2026":"Processing\u2026",Mt=a?"\u6B63\u5728\u51C6\u5907\u62A5\u4EF7\u2026":"Preparing your price\u2026",D=Ot(h.document.screen.theme);S.dataset.indianaPaywall="",S.setAttribute("aria-label",h.document.name),S.style.cssText=D.root,G.style.cssText=D.controls,u.style.cssText=D.message,u.setAttribute("role","status"),k.style.cssText=D.link,k.textContent=a?"\u5173\u95ED":"Close",g.style.cssText=D.secondary,g.textContent=a?"\u91CD\u8BD5":"Retry",g.hidden=!0,G.append(u,g,k),V&&(V.style.cssText="flex:1 0 100%;min-width:0",V.hidden=!0,G.prepend(V)),S.append(le,G);let Ne=()=>{if(V){let o=!V.childElementCount&&!V.textContent?.trim();V.hidden!==o&&(V.hidden=o)}let e=ne??G,t=[...e.children].every(o=>o===u?!u.textContent:o.hidden),n=[...e.children].some(o=>o===k?!1:o===u?!!u.textContent:!o.hidden);e.style.cssText=t?D.controls.replace(/padding:[^;]+/,"padding:0"):n?`${D.controls};${D.pinned}`:D.controls,Me()},it=typeof MutationObserver>"u"?void 0:new MutationObserver(Ne);it?.observe(S,{attributes:!0,attributeFilter:["hidden"],characterData:!0,childList:!0,subtree:!0});let Pe=h.document.presentation,qt=Object.entries(h.document.buttons).filter(([,e])=>e.type==="close").map(([e])=>e),$,ot,_e=!1,at=JSON.stringify(h.capabilities),st=e=>oe&&!he?Object.entries(e.document.buttons).filter(([,t])=>t.type==="checkout").map(([t])=>t):nt(e);function ke(e){if(y)return;h=e;let t=JSON.stringify(e.capabilities);t!==at&&($?.updateCapabilities(pe(e),st(e)),at=t),Ht(e),ye()}let E,Ue=0;function Me(){let e=p.defaultView;if(!E?.responsive||!e)return;let t=ne??G,n=e.innerHeight-(E.type==="modal"?32:0);t.style.maxHeight=`${Math.max(1,n)}px`,t.style.overflowY="auto",t.style.flexShrink="0",Ue=Math.max(1,n-t.getBoundingClientRect().height),$?.resizeViewport?.(Ue,e.innerWidth)}let y=!1,oe=!1,C=null,qe,Ee=!1,ct=!1,ae=!1,Ve,$e=!1,X,ne;function Vt(){return oe||y||X||$e?{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null}:Je(r)}let A=()=>!y&&!Ee&&!X&&i.canInteract?.()!==!1,H,ue=!1,d=null,Z=null,He="",se=()=>i.checkoutNavigation==="after_confirmation"&&!!(i.terminateCheckout||i.resumeCheckout),me={},he,W=null;function ye(){if(!se()||!$?.updateCheckoutControls)return;let e=r.quote,t=!W&&!!e&&!!r.operation&&B(r.operation).type==="checkout",n=Object.entries(h.document.buttons).flatMap(([o,c])=>c.type==="checkout"?[{actionId:o,policy:c}]:[]);$.updateCheckoutControls({actions:n.map(({actionId:o})=>o),resume:t?n.filter(({actionId:o,policy:c})=>Ae(e,h,o,c.product,me)).map(({actionId:o})=>o):[],resumeLabel:a?"\u7EE7\u7EED\u4ED8\u6B3E":"Continue checkout",busy:he})}function lt(){Z?.remove(),Z=null}async function Be(){if(W)return;if(i.resumeCheckout&&r.operation){await i.resumeCheckout(r.operation.operationId);return}let e=await r.read();if(B(e).type!=="checkout")return _(e,!1);A()&&(xe.delete(e.operationId),await Re(e))}function ut(){u.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u6253\u5F00\u4ED8\u6B3E\u9875\u9762\u3002\u8BF7\u91CD\u8BD5\u3002":"Couldn\u2019t open checkout. Try again.",g.hidden=!0}async function dt(e=!1){let t=W;if(!t)return;g.hidden=!0;let n=Date.now()+2e4;for(;A();){let o=await r.read();if(o.operationId!==t.operationId)throw new v("PURCHASE_PENDING","The original Checkout changed");if(!A())break;let c=B(o);if(c.type==="native"){W=null,lt(),C=t.selection,H=t.coupon,ue=!1,await ge();return}if(c.type==="complete"||c.type==="fulfillment"||c.type==="recording"){W=null,await _(o,!1);return}if(e&&c.type==="checkout"){e=!1;try{await i.terminateCheckout(t.operationId)}catch(w){q(i.onError,w)}}if(Date.now()>=n)break;await Xe(1e3,p,te.signal)}y||ut()}async function $t(e,t,n){W={operationId:e,selection:t,coupon:n};let o=!1;try{await i.terminateCheckout(e)}catch(c){if(c instanceof v&&["CAPABILITY_UNAVAILABLE","NOT_CONFIGURED"].includes(c.code)){W=null,u.textContent=a?"\u8BF7\u7EE7\u7EED\u539F\u8BA2\u5355\uFF0C\u6216\u7B49\u5F85\u5B83\u8FC7\u671F\u540E\u518D\u66F4\u6362\u65B9\u6848\u3002":"Continue your original checkout, or wait for it to expire before changing plans.",q(i.onError,c);return}o=c instanceof v&&(c.status??0)>=500,q(i.onError,c)}A()&&await dt(o)}function Fe(e,t,n,o,c){let w=pe(e).checkoutCoupons?.[t],l=w?w.products[n]:i.claimCoupon&&c?gt(e.capabilities,c,o):void 0;return l?.couponId&&l.planVersionId===n?{id:l.couponId,offerId:l.offerId}:void 0}function Ht(e){oe||C||r.quote||r.operation||He&&u.textContent===He||(u.textContent=Object.values(e.capabilities.plans).some(t=>t.available)?"":a?"\u5F53\u524D\u8D26\u53F7\u6682\u65E0\u53EF\u8D2D\u4E70\u7684\u65B9\u6848\u3002":"No plans are currently available for this account.")}let xe=new Map,Ie=!1;function Ae(e,t,n,o,c,w){let l=e.lines.length===1?e.lines[0]:void 0,s=ce(o,c,t.capabilities);if(!l||!s||l.productVersionId!==s)return!1;let L=Fe(t,n,s,c,w);if((L||pe(t).checkoutCoupons?.[n])&&(L?.id??null)!==(e.discount?.couponId??null))return!1;let U;try{U=ve(t.document.screen,s,c,t.capabilities)}catch{return!1}let ie=Object.fromEntries((l.prepaid??[]).map(z=>[z.internal_feature_id,z.quantity]));return[...new Set([...Object.keys(U),...Object.keys(ie)])].every(z=>(U[z]??0)===(ie[z]??0))}let B=e=>bt({quote:r.quote,operation:e,requestId:null,pending:!1,destroyed:y,canReselect:r.canReselect});async function Re(e){let t=e.merchantExecution;if(!(!A()||!e.checkoutUrl||i.checkoutNavigation==="after_confirmation"&&B(e).type!=="checkout"||t?.type==="purchase"&&!["not_started","pending"].includes(t.paymentStatus)||xe.get(e.operationId)===e.checkoutUrl)){xe.set(e.operationId,e.checkoutUrl);try{i.onCheckoutUrl?await i.onCheckoutUrl(e.checkoutUrl):p.defaultView?.location.assign(e.checkoutUrl)}catch(n){throw xe.delete(e.operationId),n}}}let re=(e,t=!1)=>{if(e instanceof Ke)d=null,u.textContent=e.customerMessage(a);else if(Dt(e))d=null,u.textContent=t?a?"\u5F53\u524D\u65E0\u6CD5\u5728\u6B64\u8D2D\u4E70\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u3002":"Purchases aren\u2019t available here right now. Payment hasn\u2019t started. Contact the merchant for help.":tt(e,a);else if(t){let n=e instanceof v?e.code:void 0;n==="CAPABILITY_UNAVAILABLE"||n==="NOT_CONFIGURED"?(d=null,u.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u4E3A\u6B64\u5957\u9910\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002":"Pricing for this plan is unavailable. Payment hasn\u2019t started."):r.canReselect===!0&&!C?u.textContent=a?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u65B0\u9009\u62E9\u5957\u9910\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Choose a plan again.":n==="COMMAND_PENDING"?u.textContent=a?"\u4ECD\u5728\u51C6\u5907\u62A5\u4EF7\uFF0C\u8BF7\u91CD\u8BD5\u4EE5\u67E5\u770B\u7ED3\u679C\u3002":"Your price is still being prepared. Retry to check the result.":u.textContent=a?"\u672A\u80FD\u53D6\u5F97\u62A5\u4EF7\uFF0C\u4ED8\u6B3E\u5C1A\u672A\u5F00\u59CB\u3002\u8BF7\u91CD\u8BD5\u3002":"We couldn\u2019t prepare your price. Payment hasn\u2019t started. Try again."}else u.textContent=e instanceof v&&(e.code==="NETWORK_ERROR"||e.code==="TIMEOUT")?tt(e,a):e instanceof v?e.message:a?"\u64CD\u4F5C\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u8BD5\u3002":"This action couldn\u2019t be completed. Try again.";g.hidden=d===null,He=u.textContent,t&&!E?.responsive&&u.scrollIntoView?.({block:"nearest"}),q(t&&R?.quoteError?R.quoteError:i.onError,e)},Se=new WeakMap;function Te(e){oe=e,g.disabled=e,$?.updateCapabilities?.(pe(h),st(h));for(let t of Z?.querySelectorAll("button")??[])e?(Se.set(t,t.disabled),t.disabled=!0):Se.has(t)&&(t.disabled=Se.get(t),Se.delete(t)),et(t)}function je(){u.textContent=a?"\u6682\u65F6\u65E0\u6CD5\u64CD\u4F5C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002":"This action is unavailable right now. Try again in a moment."}async function Bt(e){if(i.beforeAction)try{await i.beforeAction()}catch(t){throw t instanceof Ke?(C=null,ue=!1,d=null):d=e,t}}async function M(e,t){if(oe||y)return;if(!A()){je();return}let n=e===ge,o=n?Mt:Ut,c=se()&&t!==void 0;he=c?t:void 0,Te(!0),ye(),g.hidden=!0,u.textContent=c?"":o;try{if((e!==Be||!i.resumeCheckout)&&await Bt(e),y)return;if(!A()){d=e,g.hidden=!1,je();return}await e()}catch(w){y||re(w,n&&!c)}finally{he=void 0,Te(!1),ye(),u.textContent===o&&(u.textContent="")}}async function Ft(e){await Nt(K,e,i)}function ft(e){return Je(r).type==="recording"||B(e).type==="recording"}function pt(e){let t=e.merchantTerms,n=t?.subscriptionTerms?.items??[],o=t?t.totalMinor:e.charge?.totalMinor??e.catalogAmountMinor-(e.discount?.amountMinor??0),c=t?n.length===1&&n[0]?.amountMinor===o&&n[0]:e.lines.length===1&&e.lines[0]?.catalogAmountMinor===o&&e.lines[0],w=o===null?fe(t.subtotalMinor-t.discountMinor,e.currency)+(a?" + \u5F85\u786E\u8BA4\u7A0E\u8D39":" + tax confirmed at checkout"):fe(o,e.currency)+(c?Ce(c.interval,a?"zh-CN":"en",c.intervalCount??1):""),l=e.lines.map(s=>s.productName).join(", ");return{label:l?`${l} \xB7 ${w}`:w,recurring:c}}async function _(e,t=i.checkoutNavigation!=="after_confirmation"){if(y)return;if(!A()){d=async()=>_(await r.read()),g.hidden=!1;return}if(u.textContent=Lt(e.status,a),ft(e)){let s=e.merchantExecution?.type==="purchase"&&e.merchantExecution.recordingStatus==="failed";u.textContent=s?a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u4F46\u4EA4\u6613\u8BB0\u5F55\u5931\u8D25\u3002\u8BF7\u8054\u7CFB\u5546\u6237\u4FEE\u590D\uFF0C\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and fulfillment succeeded, but recording failed. Contact the merchant to repair this purchase; do not buy again.":a?"\u4ED8\u6B3E\u548C\u5546\u6237\u5904\u7406\u5DF2\u5B8C\u6210\uFF0C\u6B63\u5728\u786E\u8BA4\u4EA4\u6613\u8BB0\u5F55\u3002\u8BF7\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"Payment and merchant fulfillment are complete. Recording is pending confirmation; do not purchase again.",g.textContent=a?"\u67E5\u8BE2\u8BB0\u5F55":"Check recording",d=async()=>_(await r.read()),g.hidden=!1;return}if(e.problem){let s=e.problem;d=we,g.textContent=a?"\u68C0\u67E5\u5E76\u6062\u590D\u539F\u64CD\u4F5C":"Check and recover original purchase",re(new v(s.code,s.reason==="RESULT_UNKNOWN"?a?"\u4ED8\u6B3E\u7ED3\u679C\u5C1A\u672A\u786E\u5B9A\uFF0C\u8BF7\u6062\u590D\u539F\u64CD\u4F5C\uFF0C\u6682\u52FF\u91CD\u590D\u8D2D\u4E70\u3002":"The payment result is unknown. Recover the original purchase before buying again.":s.phase==="fulfillment"?a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u5546\u6237\u6743\u76CA\u5904\u7406\u9700\u8981\u6838\u5BF9\u3002":"Payment was recorded. Access fulfillment needs attention.":s.code==="CAPABILITY_UNAVAILABLE"?a?"\u5546\u6237\u5C1A\u4E0D\u652F\u6301\u672C\u6B21\u8D2D\u4E70\u6240\u9700\u7684\u5B8C\u6574\u80FD\u529B\uFF0C\u8BF7\u5904\u7406\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The merchant does not currently support all actions required by this purchase. Recover the original purchase after this is resolved.":s.code==="NOT_CONFIGURED"?a?"\u4ED8\u6B3E\u670D\u52A1\u8FDE\u63A5\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u5546\u6237\u540E\u6062\u590D\u539F\u64CD\u4F5C\u3002":"The payment connection needs attention. Contact the merchant, then recover the original purchase.":a?"\u539F\u8D2D\u4E70\u64CD\u4F5C\u9700\u8981\u5904\u7406\uFF0C\u8BF7\u67E5\u8BE2\u6216\u6062\u590D\u6B64\u64CD\u4F5C\u3002":"The original purchase needs attention. Check or recover this operation.",void 0,void 0,s));return}if(e.merchantExecution?.type==="purchase"&&e.merchantExecution.paymentStatus==="succeeded"&&!["applied","not_applicable"].includes(e.merchantExecution.fulfillmentStatus)&&(u.textContent=a?"\u4ED8\u6B3E\u5DF2\u8BB0\u5F55\uFF0C\u6B63\u5728\u7B49\u5F85\u5546\u6237\u5B8C\u6210\u5904\u7406\u3002":"Payment was recorded. Waiting for merchant fulfillment."),e.status==="complete"){d=null,await Ft(e);return}if(e.status!=="pending"){if(r.canReselect===!1){u.textContent=a?"\u6B63\u5728\u6838\u5BF9\u539F\u8D2D\u4E70\u7ED3\u679C":"Checking the original purchase result",g.textContent=a?"\u67E5\u8BE2\u7ED3\u679C":"Check result",d=async()=>_(await r.read()),g.hidden=!1;return}e.status==="cancelled"?u.textContent=a?"\u8FD9\u7B14\u8D2D\u4E70\u5DF2\u53D6\u6D88\uFF0C\u53EF\u4EE5\u91CD\u65B0\u9009\u62E9\u65B9\u6848\u3002":"This purchase was cancelled. Choose a plan to start again.":e.status==="failed"&&(u.textContent=a?"\u8FD9\u7B14\u8D2D\u4E70\u672A\u80FD\u5B8C\u6210\uFF0C\u53EF\u4EE5\u91CD\u65B0\u9009\u62E9\u65B9\u6848\u3002":"This purchase didn\u2019t go through. Choose a plan to try again."),g.textContent=a?"\u91CD\u8BD5":"Retry",d=null,C=null;return}if(!t&&B(e).type==="checkout"){if(W){ut();return}if(se()){u.textContent="",Ie=!1,d=null,ye();return}let s=r.quote,L=s?.operationId===e.operationId?pt(s).label:"";u.textContent=Ie?L?a?`${L} \u5C1A\u672A\u4ED8\u6B3E\u3002\u518D\u6B21\u9009\u62E9\u8BE5\u65B9\u6848\u5373\u53EF\u7EE7\u7EED\u4ED8\u6B3E\u3002`:`${L} is still unpaid. Choose it again to continue paying.`:a?"\u4E4B\u524D\u7684\u8D2D\u4E70\u5C1A\u672A\u4ED8\u6B3E\u3002\u518D\u6B21\u9009\u62E9\u8BE5\u65B9\u6848\u5373\u53EF\u7EE7\u7EED\u4ED8\u6B3E\u3002":"Your earlier purchase is still unpaid. Choose that plan again to continue paying.":"",Ie=!1,d=null;return}await Re(e);let n=Date.now(),o=n+6e5,c=2e3,w=!e.checkoutUrl,l=()=>w&&Date.now()-n<15e3;_e=!0,q(i.onObservationChange,!0);try{for(;!y&&Date.now()<o;){if(await Xe(l()?700:c,p,te.signal),y)return;if(!A()){d=async()=>_(await r.read()),g.hidden=!1;return}let s=await r.read();if(s.checkoutUrl&&(w=!1),!t&&B(s).type==="checkout"){await _(s,!1);return}if(!s.problem&&s.status==="pending"&&await Re(s),s.status!=="pending"||s.problem||ft(s)){await _(s);return}l()||(c=Math.min(c*1.5,3e4))}}finally{_e=!1,q(i.onObservationChange,!1)}d=async()=>_(await r.read()),g.hidden=!1}async function Qe(e=!1){let t=await r.read();if(y)return;if(!A()){d=()=>Qe(e),g.hidden=!1;return}let n=r.quote;if(n&&Pt(t,{operationId:n.operationId,currency:n.currency},"The original purchase operation changed"),n&&t.status==="pending"&&t.quoteFinalized===!1&&!t.confirmedAt&&!t.checkoutUrl&&!t.nativePurchase&&!t.merchantExecution&&!t.problem&&!r.pendingCancellation){mt(n);return}await _(t,e||void 0)}async function we(){lt(),d=we;let e=await r.confirm();if(!A()){d=we,g.hidden=!1;return}if(e.problem){await _(e);return}if(e.status==="pending"){if(e.checkoutUrl)await Re(e);else if(e.execution&&e.execution.provider!=="merchant"||e.nativePurchase){if(!i.onPurchase)throw new v("PURCHASE_HANDLER_REQUIRED","Provide the merchant or native purchase handler");await i.onPurchase({operation:e,signal:te.signal})}}d=async()=>_(await r.read()),await _(e,!0)}function mt(e){Z?.remove();let t=!(Date.parse(e.expiresAt)>Date.now());u.textContent=t?a?"\u6B64\u62A5\u4EF7\u5DF2\u8FC7\u671F\u3002\u8BF7\u5148\u53D6\u6D88\uFF0C\u518D\u91CD\u65B0\u9009\u62E9\u3002":"This quote has expired. Cancel it, then choose again.":"";let n=p.createElement("div"),o=p.createElement("button"),c=p.createElement("button"),w=p.createElement("div"),l=p.createElement("p"),s=e.merchantTerms,L=a?"zh-CN":"en",U=s?.subscriptionTerms?.items??[],ie=s?s.subscriptionTerms?.trial?.days:e.lines.find(f=>f.trial)?.trial?.days,ee=ie===void 0?null:s?s.totalMinor:e.charge?e.charge.totalMinor:e.lines.every(f=>f.trial)?0:null,z=(f,b)=>a?`${b} \u5929\u8BD5\u7528\u7ED3\u675F\u540E ${f}`:`Then ${f} after the ${b}-day trial`,{label:ze,recurring:ht}=pt(e),jt=e.lines.map(f=>f.productName).join(", "),yt=ee===null?"":`${a?"\u4ECA\u5929\u5E94\u4ED8":"Due today"} ${fe(ee,e.currency)}`;l.textContent=yt?[jt,yt].filter(Boolean).join(" \xB7 "):ze,o.textContent=a?"\u786E\u8BA4\u8D2D\u4E70":"Confirm purchase",o.disabled=t,c.textContent=a?"\u53D6\u6D88":"Cancel",n.style.cssText=D.panel,l.style.cssText=D.summary,w.style.cssText=D.actions,o.style.cssText=D.primary,c.style.cssText=D.secondary,et(o),o.onclick=()=>{M(we)};let wt=async()=>{let f=await r.cancel();y||(n.remove(),Z=null,await _(f))};c.onclick=()=>{d=wt,M(wt)};let F=p.createElement("div");if(F.style.cssText=D.terms,s){for(let b of U){if(ee===null&&b===ht)continue;let T=p.createElement("p"),Y=fe(b.amountMinor,e.currency)+Ce(b.interval,L,b.intervalCount);T.textContent=ee!==null&&ie!==void 0?z(Y,ie):Y,F.append(T)}let f=s.subscriptionTerms?.trial;if(f){let b=p.createElement("p");b.textContent=a?`\u8BD5\u7528 ${f.days} \u5929\uFF1B${f.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${f.days}; ${f.cardRequired?"a payment method is required":"no payment method is required"}`,F.append(b)}for(let b of[...s.expectedEffects.map(T=>T.description),...s.requiredConsents.map(T=>T.summary)]){let T=p.createElement("p");T.textContent=b,F.append(T)}}else{for(let f of e.lines){if(ee!==null||f!==ht){let b=p.createElement("p"),T=`${fe(f.catalogAmountMinor,e.currency)}${Ce(f.interval,L,f.intervalCount??1)}`;b.textContent=ee!==null&&f.trial?(e.lines.length>1?`${f.productName} \xB7 `:"")+z(T,f.trial.days):`${f.productName} \xB7 ${T}`,F.append(b)}for(let b of f.prepaid??[]){let T=p.createElement("p"),Y=r.view?.capabilities.plans[f.productVersionId]?.prepaid?.find(Qt=>Qt.internalFeatureId===b.internal_feature_id);T.textContent=`${Y?.name??b.internal_feature_id} \xB7 ${b.quantity} ${a?"\u4EFD":"packs"} \xD7 ${b.terms.units}`,Y&&(T.textContent+=Ce(Y.reset==="week"||Y.reset==="month"||Y.reset==="year"?Y.reset:"one_time",L,Y.resetCount)),F.append(T)}if(f.trial){let b=p.createElement("p");b.textContent=a?`\u8BD5\u7528 ${f.trial.days} \u5929\uFF1B${f.trial.cardRequired?"\u9700\u8981\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F":"\u65E0\u9700\u63D0\u4F9B\u4ED8\u6B3E\u65B9\u5F0F"}`:`Trial days: ${f.trial.days}; ${f.trial.cardRequired?"a payment method is required":"no payment method is required"}`,F.append(b)}}if(!e.charge){let f=p.createElement("p");f.textContent=a?"\u76EE\u5F55\u4EF7\u683C\uFF1B\u6700\u7EC8\u91D1\u989D\u4EE5\u7ED3\u8D26\u65F6\u7A0E\u8D39\u548C\u8BD5\u7528\u89C4\u5219\u4E3A\u51C6\u3002":"Catalog price; the final charge depends on checkout taxes and trial terms.",F.append(f)}}for(let f of F.children)f.style.margin="0";w.append(o,c),n.append(l,...F.childElementCount?[F]:[],w),G.prepend(n),E?.responsive||n.scrollIntoView?.({block:"nearest"}),o.focus({preventScroll:!0}),Z=n,d=null}async function ge(){if(!C)return;if(d=ge,!ue){let n=r.view,o=n?.document.buttons[C.actionId],c=n&&o?.type==="checkout"?ce(o.product,C.selection,n.capabilities):null;if(!n||!c)throw new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");let w=H?.offerId;if(H&&!w){if(!i.claimCoupon)throw new v("CAPABILITY_UNAVAILABLE","Coupon claiming is unavailable");let{offer:l}=await i.claimCoupon(H.id,C.requestId);if(y)return;if(!l||l.couponId!==H.id||l.status!=="issued"||!(Date.parse(l.expiresAt)>Date.now()))throw C=null,H=void 0,d=async()=>{ke(await r.refresh()),d=null},new v("COUPON_UNAVAILABLE","This Coupon is no longer available for this purchase");w=l.id}if(!H&&!n.document.screen.actions.some(l=>l.id===C?.actionId&&typeof l.properties.couponBinding=="string")&&(w=await i.resolveOfferId?.({actionId:C.actionId,productVersionId:c,featureQuantities:ve(n.document.screen,c,C.selection,n.capabilities)})),y)return;w!==void 0&&(C.offerId=w),ue=!0}if(!A()){g.hidden=!1;return}let e;try{e=await r.preview(C)}catch(n){throw r.canReselect===!0&&(C=null,ue=!1,H=void 0,d=null),n}if(H&&(e.discount?.couponId!==H.id||e.discount.offerId!==C.offerId))throw new v("INVALID_RESPONSE","The quote did not apply the Coupon selected on this Paywall");if(y)return;let t=e.merchantTerms;if(i.confirmOnHostedCheckout&&A()&&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()){let n=he?"":a?"\u6B63\u5728\u6253\u5F00\u6536\u94F6\u53F0\u2026":"Opening checkout\u2026";u.textContent=n;try{await we()}catch(o){y||re(o)}finally{u.textContent===n&&(u.textContent="")}return}mt(e)}function de(e="destroy"){if(y)return;y=!0;let t=qe;qe=void 0,q(t),i.signal?.removeEventListener("abort",J),r.signal?.removeEventListener("abort",J),x.finish("dismissed"),ot?.(),te.abort(),it?.disconnect(),E?.destroy(),$?.destroy(),r.destroy(),I.open&&I.close(),I.remove(),S.remove(),P(),e==="dismiss"&&q(i.onDismiss)}N=de;async function Oe(){if(!ae||y||Ee||X==="closing"||!X&&!A())return;if(!R){de("dismiss");return}let e=p.createElement("p");e.setAttribute("role","status"),e.textContent=a?"\u6B63\u5728\u5173\u95ED\u2026":"Closing\u2026",ne||(ne=p.createElement("div"),ne.style.cssText=G.style.cssText,G.replaceWith(ne),le.inert=!0),k.hidden=!1,ne.replaceChildren(e,k),X="closing",k.setAttribute("aria-disabled","true"),k.focus({preventScroll:!0});try{await R.dismiss()}catch(t){y||q(i.onError,t)}y||(X="retry",e.textContent=a?"\u672A\u80FD\u786E\u8BA4\u5173\u95ED\uFF0C\u8BF7\u91CD\u8BD5\u3002":"Could not confirm closure. Try again.",k.textContent=a?"\u91CD\u8BD5\u5173\u95ED":"Retry closing",k.removeAttribute("aria-label"),k.removeAttribute("aria-disabled"))}k.onclick=()=>{Oe()},I.addEventListener("cancel",e=>{e.preventDefault(),Oe()}),g.onclick=()=>{d&&M(d)};function Ge(e){x.finish("error",e),de()}function We(){if(!(!ct||ae||y||Ee||E&&!A()))try{let e=t=>{i.focusAtReveal&&(P=Ze(p)),$?.setHidden?.(!1),Ve?.(),E&&(I.showModal(),E.responsive&&I.focus({preventScroll:!0}),!t&&i.loading!=="host"&&xt(I,E.type,E.responsive)),ae=!0};R?R.present(()=>x.present(()=>e(!0))):x.present(e)}catch(e){Ge(e),re(e)}}try{if(Pe.type==="inline"?(Ne(),Ve=St(S,O),O.append(S)):(I.setAttribute("aria-label",h.document.name),k.textContent="\xD7",k.setAttribute("aria-label",a?"\u5173\u95ED":"Close"),It(k,h.document.screen.theme),k.hidden=kt(h.document),I.append(k,S),O.append(I),E=Et(I,{...h.document.screen,presentation:Pe},Me),E.latch(),E.responsive&&(S.style.display="flex",S.style.flexDirection="column",S.style.maxHeight="100%",le.style.overflow="clip",le.style.minHeight="0"),Ve=Rt(I)),Le&&V){let n=Le(V);if(typeof n=="function"&&(y?q(n):qe=n),y)throw new DOMException("Presentation cancelled","AbortError");Ne()}$=Q(le,{mode:"live",rendererUrl:r.webViewUrl,title:h.document.name,closeActions:qt,onAuthoredClose(n){X||y||(k.hidden=n)},hostPresentation:()=>E?.type??Pe.type,reportContentHeight:E?.responsive,onResize:n=>{if(!E?.responsive)return;let o=Math.min(n,Ue);le.style.height=`${o}px`,E.setContentHeight(o+(ne??G).getBoundingClientRect().height)},onSelection(n){me=n,ye()},onAction(n,o={},c,w){if(!ae||y||X)return;let l=r.view,s=l?.document.buttons[n];if(!s)return;if(s.type==="close"&&R&&i.resumeCheckout&&r.operation&&Ct(B(r.operation))){Oe();return}if(oe)return;if(!A()){je();return}if(s.type==="close"){M(async()=>{await i.onAction?.(n),de(i.onAction?"action":"dismiss")});return}if(s.type==="action"){d=async()=>{if(s.action.type==="event"){if(!i.onEvent)throw new v("EVENT_HANDLER_REQUIRED","Provide the event handler");await i.onEvent(s.action.event)}else i.onOpenUrl?await i.onOpenUrl(s.action.url):p.defaultView?.location.assign(s.action.url);await i.onAction?.(n),d=null},M(d);return}if(i.allowNewPurchase===!1){se()&&l&&r.quote&&r.operation&&B(r.operation).type==="checkout"&&Ae(r.quote,l,n,s.product,o,w)?M(Be,n):u.textContent=a?"\u5F53\u524D\u53EA\u80FD\u7EE7\u7EED\u539F\u8BA2\u5355\u3002":"Only your original checkout is available.";return}if(Z&&r.canReselect===!1){u.textContent=a?"\u8BF7\u5148\u786E\u8BA4\u6216\u53D6\u6D88\u5F53\u524D\u8D2D\u4E70\u3002":"Confirm or cancel the current purchase first.",E?.responsive||Z.scrollIntoView?.({block:"nearest"}),Z.querySelector("button")?.focus({preventScroll:!0});return}if(se()&&W){W.selection.actionId===n&&M(()=>dt(!0),n);return}if(se()&&i.terminateCheckout&&l&&r.quote&&r.operation&&r.canReselect===!1&&B(r.operation).type==="checkout"){if(Ae(r.quote,l,n,s.product,o,w)){M(Be,n);return}let U=ce(s.product,o,l.capabilities);try{if(!U)throw new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area");ve(l.document.screen,U,o,l.capabilities)}catch(ze){re(ze);return}let ie=r.operation.operationId,ee={actionId:n,requestId:crypto.randomUUID(),selection:structuredClone(o)},z=Fe(l,n,U,o,w);M(()=>$t(ie,ee,z),n);return}if((r.quote||C)&&r.canReselect===!1){let U=!!l&&!!r.quote&&Ae(r.quote,l,n,s.product,o,w);Ie=!!r.quote&&!U,d=r.quote?()=>Qe(U):ge,M(d);return}let L=l&&ce(s.product,o,l.capabilities);if(!l||!L){re(new v("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));return}if(i.onPurchaseIntent){d=null,M(async()=>{let U={actionId:n,productVersionId:L,selection:structuredClone(o),featureQuantities:ve(l.document.screen,L,o,l.capabilities)};$e=!0,await i.onPurchaseIntent(U)});return}if(C&&C.actionId!==n){re(new v("COMMAND_PENDING","Finish the current purchase"));return}C||(H=Fe(l,n,L,o,w),C={requestId:crypto.randomUUID(),actionId:n,selection:structuredClone(o)},ue=!1),M(ge,n)},onEscape:()=>{Oe()},onError:n=>{let o=new Error(n);!ae&&!y&&Ge(o),re(o)},onRendered:n=>{n&&I.setAttribute("aria-label",n),ct=!0,We()}}),$.setHidden?.(!0),Me();let e=se()&&!!r.quote&&!!r.operation&&B(r.operation).type==="checkout";me=e?_t(h,r.quote)??{}:{},$.update(h.document.screen,rt,{capabilities:pe(h),unavailableActions:nt(h),serverInput:{bindings:[],answers:{}},...Object.keys(me).length?{selection:me}:{}}),ot=r.subscribe?.(ke),ke(r.view??h),await x.wait($.ready);let t=r.operation;!e&&(r.quote||t&&(t.confirmedAt||t.checkoutUrl||t.status==="complete"))&&(d=()=>Qe(),M(d))}catch(e){throw Ge(e),e}return{check:K,host:{get observing(){return _e},get recovery(){return Vt()},async prepareFallback(){if(oe||y||X||$e)return{type:"recover",operationId:r.operation?.operationId??r.quote?.operationId??null,requestId:null};Te(!0);try{let e=await vt(r);return e.type==="native"&&de(),e}finally{Te(!1)}},setSuspended(e){Ee=e,S.hidden=e,e&&I.open?I.close():!e&&!ae?We():!e&&!y&&ae&&Pe.type!=="inline"&&!I.open&&I.showModal()},destroy:de,refresh:async()=>{if(!A()){if(r.view)return r.view;throw new v("PRECONDITION_FAILED","Paywall presentation is suspended")}let e=await r.refresh();return ke(e),We(),e}}}}export{Pn as showPaywall};
@@ -0,0 +1 @@
1
+ import{b as a}from"./chunk-X6ONZGRY.js";import"./chunk-EREQZWGI.js";import"./chunk-P23JOPR5.js";import"./chunk-IOJVF52Q.js";import"./chunk-U7GH4VME.js";import"./chunk-33ZVZOSC.js";import"./chunk-PZOQV6MU.js";import"./chunk-FCDWCQYC.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-C3GYAKIU.js";import"./chunk-5DZJCFNQ.js";import"./chunk-YLPQLD2A.js";import"./chunk-POCDWUD3.js";import"./chunk-ORMQJAQE.js";import"./chunk-RFNIGJOL.js";import"./chunk-7QDT6DO7.js";import"./chunk-6PG3AS3G.js";import"./chunk-X6ONZGRY.js";import"./chunk-EREQZWGI.js";import"./chunk-P23JOPR5.js";import"./chunk-IOJVF52Q.js";import"./chunk-U7GH4VME.js";import"./chunk-3NCMYTNG.js";import"./chunk-33ZVZOSC.js";import"./chunk-VOKEZHAH.js";import"./chunk-57GPGWSK.js";import"./chunk-PZOQV6MU.js";import"./chunk-FCDWCQYC.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
package/dist/popup.js CHANGED
@@ -1 +1 @@
1
- import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a}from"./chunk-GNAMACMK.js";import"./chunk-KIPUBMU3.js";import"./chunk-BIT6YWM7.js";import"./chunk-2Y5SGDC6.js";import"./chunk-3JD3U45R.js";import"./chunk-YURGISSB.js";import"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-NOOIJXRN.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
1
+ import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a}from"./chunk-BYP4KVB3.js";import"./chunk-P6C3PNMQ.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";export{p as formatCustomerDecimal,r as hostedRendererScript,o as hostedRendererShell,f as inspectCustomHtml,a as mountScreenPreview,x as preparePopup,m as prepareScreen,e as sanitizeCustomHtml,t as showPopup};
@@ -1 +1 @@
1
- import{b as S,c as E,d as T}from"./chunk-TLRRBUGP.js";import"./chunk-LZBJHWVH.js";import{a as A}from"./chunk-LJBTEB2Q.js";import{e as P}from"./chunk-O2D3A4CS.js";import"./chunk-JAZHNQKO.js";import{h as b,i as x,k as L}from"./chunk-GDD26ZDV.js";import{F as C}from"./chunk-N774V4SQ.js";import"./chunk-ZORZA4WG.js";import"./chunk-U7XD4ZR5.js";import"./chunk-HX36OZPQ.js";import"./chunk-GGYBZWWY.js";import"./chunk-MTIOLSVM.js";import"./chunk-ONMIBSOC.js";import"./chunk-CEMHQQAJ.js";import"./chunk-W3G4YIM5.js";import"./chunk-IYHXEKAD.js";import"./chunk-73ISTR7P.js";import"./chunk-3NCMYTNG.js";import"./chunk-CE5MAAIR.js";import"./chunk-VYI6QRJW.js";import"./chunk-DPIQ3SV7.js";import"./chunk-HFD4CLCJ.js";import"./chunk-IGANLTKS.js";import"./chunk-BIT6YWM7.js";import"./chunk-2Y5SGDC6.js";import"./chunk-3JD3U45R.js";import{b as R}from"./chunk-YURGISSB.js";import{a as r}from"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-3VUPVXAV.js";import"./chunk-JBVZ6A6V.js";import"./chunk-NOOIJXRN.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
1
+ import{b as S,c as E,d as T}from"./chunk-QZTTKH2H.js";import"./chunk-ASDJTOGM.js";import{a as A}from"./chunk-C3GYAKIU.js";import{e as P}from"./chunk-5DZJCFNQ.js";import"./chunk-YLPQLD2A.js";import{h as b,i as x,k as L}from"./chunk-AZFWG352.js";import{F as C}from"./chunk-4TEZZZYK.js";import"./chunk-POCDWUD3.js";import"./chunk-ORMQJAQE.js";import"./chunk-RFNIGJOL.js";import"./chunk-7QDT6DO7.js";import"./chunk-6PG3AS3G.js";import"./chunk-X6ONZGRY.js";import"./chunk-EREQZWGI.js";import"./chunk-P23JOPR5.js";import"./chunk-IOJVF52Q.js";import"./chunk-U7GH4VME.js";import"./chunk-3NCMYTNG.js";import"./chunk-33ZVZOSC.js";import"./chunk-VOKEZHAH.js";import"./chunk-57GPGWSK.js";import"./chunk-PZOQV6MU.js";import"./chunk-FCDWCQYC.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import{b as R}from"./chunk-OOD2VDDP.js";import{a as r}from"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i}from"./chunk-BYP4KVB3.js";import"./chunk-P6C3PNMQ.js";import"./chunk-XDOKFAE6.js";import"./chunk-Y6HL2IY2.js";import"./chunk-LSPHUA7V.js";import"./chunk-OOD2VDDP.js";import"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-RGEBK6UF.js";import"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.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};
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as pn}from"./chunk-NSAEHRIT.js";import{a as I}from"./chunk-PFPMK4IO.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-QCMFCK7Z.js";import{a as xt}from"./chunk-LJBTEB2Q.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-O2D3A4CS.js";import"./chunk-JAZHNQKO.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-GDD26ZDV.js";import{A as Tt,C as V,D as N,a as Oe,e as ft,f as ht,l as gt,m as z,n as St,q as Ct,r as Rt,s as bt,t as At,u as Ot,z as pe}from"./chunk-N774V4SQ.js";import{c as h}from"./chunk-ZORZA4WG.js";import"./chunk-U7XD4ZR5.js";import"./chunk-HX36OZPQ.js";import{a as Et,b as _e}from"./chunk-GGYBZWWY.js";import{A as tt,B as Se,C as ie,E as se,F as Ce,K as j,M as ce,N as nt,P as Ee,Q as rt,R as ot,d as Ge,e as je,h as we,p as ze,q as Ke,s as an,t as sn,w as cn,x as X,y as W,z as oe}from"./chunk-MTIOLSVM.js";import"./chunk-ONMIBSOC.js";import"./chunk-CEMHQQAJ.js";import{e as at}from"./chunk-W3G4YIM5.js";import{$ as mt,A as it,B as Re,C as st,D as ct,I as ut,J as dt,K as be,L as Ae,T as pt,U as de,V as Z,W as lt,d as ve,f as Ze,g as et,u as q}from"./chunk-IYHXEKAD.js";import"./chunk-73ISTR7P.js";import"./chunk-3NCMYTNG.js";import"./chunk-CE5MAAIR.js";import"./chunk-VYI6QRJW.js";import"./chunk-DPIQ3SV7.js";import"./chunk-HFD4CLCJ.js";import{a as Ne,b as Le}from"./chunk-IGANLTKS.js";import{$ as ue,J as Xe,M as We}from"./chunk-BIT6YWM7.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-2Y5SGDC6.js";import{c as Ie}from"./chunk-3JD3U45R.js";import{b as Y}from"./chunk-YURGISSB.js";import{a as c}from"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-3VUPVXAV.js";import"./chunk-JBVZ6A6V.js";import{b as u}from"./chunk-NOOIJXRN.js";import{a as Ye}from"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
1
+ import{a as pn}from"./chunk-IJKAQNK6.js";import{a as I}from"./chunk-67AY54E2.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-YY445FBU.js";import{a as xt}from"./chunk-C3GYAKIU.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-5DZJCFNQ.js";import"./chunk-YLPQLD2A.js";import{a as Te,b as ae,c as yt,d as It,e as wt,f as xe,g as vt,h as Me,i as dn,j as ln,k as mn}from"./chunk-AZFWG352.js";import{A as Tt,C as V,D as N,a as Oe,e as ft,f as ht,l as gt,m as z,n as St,q as Ct,r as Rt,s as bt,t as At,u as Ot,z as pe}from"./chunk-4TEZZZYK.js";import{c as h}from"./chunk-POCDWUD3.js";import"./chunk-ORMQJAQE.js";import"./chunk-RFNIGJOL.js";import{a as Et,b as _e}from"./chunk-7QDT6DO7.js";import{A as tt,B as Se,C as ie,E as se,F as Ce,K as j,M as ce,N as nt,P as Ee,Q as rt,R as ot,d as Ge,e as je,h as we,p as ze,q as Ke,s as an,t as sn,w as cn,x as X,y as W,z as oe}from"./chunk-6PG3AS3G.js";import"./chunk-X6ONZGRY.js";import"./chunk-EREQZWGI.js";import{e as at}from"./chunk-P23JOPR5.js";import{$ as mt,A as it,B as Re,C as st,D as ct,I as ut,J as dt,K as be,L as Ae,T as pt,U as de,V as Z,W as lt,d as ve,f as Ze,g as et,u as q}from"./chunk-IOJVF52Q.js";import"./chunk-U7GH4VME.js";import"./chunk-3NCMYTNG.js";import"./chunk-33ZVZOSC.js";import"./chunk-VOKEZHAH.js";import"./chunk-57GPGWSK.js";import"./chunk-PZOQV6MU.js";import{a as Ne,b as Le}from"./chunk-FCDWCQYC.js";import{$ as ue,J as Xe,M as We}from"./chunk-XDOKFAE6.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-Y6HL2IY2.js";import{c as Ie}from"./chunk-LSPHUA7V.js";import{b as Y}from"./chunk-OOD2VDDP.js";import{a as c}from"./chunk-WLGLQJ6M.js";import"./chunk-RULQQ7WI.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import{b as u}from"./chunk-RGEBK6UF.js";import{a as Ye}from"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var _t=4,Mt=[...tt,"requirement_checks","native_offers","preparations","benefit_claims","authorizations","business_results","checkout_termination"],In=u.enum(Mt),ee=(e,n)=>u.array(e).max(n).refine(t=>new Set(t).size===t.length,"Declarations must be unique"),ke=u.strictObject({...se.shape,bridgeVersion:u.literal(_t),capabilities:ee(In,Mt.length),checkKinds:ee(u.enum(["access","metered","credit"]),3),preparationActions:ee(u.enum(["purchase","subscription_change","refund"]),3),authorizationKinds:ee(u.enum(["auto_topup"]),1),nextActionTypes:ee(u.enum(["redirect","authenticate"]),2),resultEvents:ee(u.enum(["benefit.claimed","authorization.updated"]),2)}).superRefine((e,n)=>{e.capabilities.includes("catalog")!==(e.catalog!=="none")&&n.addIssue({code:"custom",path:["catalog"],message:"Catalog declaration differs from its capability"}),(e.capabilities.includes("billing_records")!==e.billingEvents.length>0||new Set(e.billingEvents).size!==e.billingEvents.length)&&n.addIssue({code:"custom",path:["billingEvents"],message:"Declare unique supported billing events"});let t=r=>e.capabilities.includes(r),o=(r,a)=>n.addIssue({code:"custom",path:[r],message:a});t("requirement_checks")!==e.checkKinds.length>0&&o("checkKinds","Declare the supported Check kinds"),t("preparations")!==e.preparationActions.length>0&&o("preparationActions","Declare the supported preparation actions"),t("authorizations")!==e.authorizationKinds.length>0&&o("authorizationKinds","Declare the supported authorization kinds"),t("business_results")!==e.resultEvents.length>0&&o("resultEvents","Declare the supported non-financial results");for(let[r,a,s]of[["purchases","purchase","purchase.completed"],["subscription_changes","subscription_change","subscription.change.completed"],["refunds","refund","refund.updated"]])t(r)&&(!t("operation_status")||!t("billing_records")||!t("preparations")||!e.preparationActions.includes(a)||!e.billingEvents.includes(s))&&o("capabilities",`${r} requires preparation, original lookup and its billing result`);t("purchases")&&!e.billingEvents.includes("purchase.closed")&&o("billingEvents","Purchase execution requires its terminal closure result"),t("checkout_termination")&&(!t("operation_status")||!t("billing_records")||!e.billingEvents.includes("purchase.closed"))&&o("capabilities","Checkout termination requires original lookup and purchase.closed"),t("subscription_changes")&&!e.billingEvents.includes("subscription.change.closed")&&o("billingEvents","Subscription change execution requires its terminal closure result");for(let[r,a]of[["benefit_claims","benefit.claimed"],["authorizations","authorization.updated"]])t(r)&&(!t("operation_status")||!t("business_results")||!e.resultEvents.includes(a))&&o("capabilities",`${r} requires original lookup and its non-financial result`)}),K={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":u.strictObject({}),"requirement.check":$e,"operation.prepare":ze,"benefit.claim":Ue,"operation.read":qe,"purchase.terminate":j},wn={"bridge.ping":u.strictObject({challenge:u.uuid()}),"bridge.describe":ke,"requirement.check":Qe,"operation.prepare":Ke,"benefit.claim":Ve,"operation.read":He,"purchase.terminate":j.extend({outcome:u.enum(["requested","already_paid"])})},Gn=u.enum(["bridge.ping","bridge.describe","requirement.check","operation.prepare","benefit.claim","operation.read","purchase.terminate"]);function $(e,n){return u.strictObject({bridgeVersion:u.literal(_t),requestId:u.uuid(),scope:Ce,command:u.literal(e),data:n})}var kt=u.discriminatedUnion("command",[$("bridge.ping",K["bridge.ping"]),$("bridge.describe",K["bridge.describe"]),$("requirement.check",K["requirement.check"]),$("operation.prepare",K["operation.prepare"]),$("benefit.claim",K["benefit.claim"]),$("operation.read",K["operation.read"]),$("purchase.terminate",K["purchase.terminate"])]),Be=u.strictObject({code:u.string().regex(/^MERCHANT_BRIDGE_[A-Z_]+$/),message:u.string().min(1).max(500),retryable:u.boolean(),recovery:u.string().min(1).max(80),effect:u.enum(["none","unknown"])}).refine(e=>e.effect!=="unknown"||!e.retryable&&e.recovery==="recover_operation","Unknown effects require original-operation recovery");function Bt(e){let n={bridgeVersion:u.literal(4),requestId:u.uuid(),scope:Ce,command:u.literal(e)};return u.union([u.strictObject({...n,data:wn[e]}),u.strictObject({...n,error:Be})])}var Pt="X-Indiana-Bridge-Signature",Q="X-Indiana-Bridge-Key-Id";function vn(e){return new TextEncoder().encode(e)}function Dt(e){return Uint8Array.from(atob(e.replaceAll("-","+").replaceAll("_","/")),n=>n.charCodeAt(0))}function Ft(e,n,t,o){return vn(`indiana-merchant-bridge:${o}
2
2
  ${n}
3
3
  POST
4
4
  ${W}
package/dist/visual.js CHANGED
@@ -1 +1 @@
1
- import{a as pe,c as fe}from"./chunk-OJM6ORHE.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as J,b as F,c as ge,e as me}from"./chunk-CBZ5GW4J.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-YJS6NNIO.js";import"./chunk-3VUPVXAV.js";import"./chunk-JBVZ6A6V.js";import{b as o}from"./chunk-NOOIJXRN.js";import{c as te,e as ie,g as M}from"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var K="indiana-visual-diagnostics-v1",Ae=o.strictObject({environmentId:o.string().uuid(),release:o.string().regex(/^[a-f0-9]{64}$/).nullable(),generation:o.string().regex(/^[a-f0-9]{64}$/).nullable(),publishedGeneration:o.string().regex(/^[a-f0-9]{64}$/).nullable(),checkedAt:o.string().datetime(),origin:o.string().url(),pathname:o.string().max(2048),urlMatches:o.boolean(),stopped:o.boolean(),rows:o.array(o.strictObject({changeId:o.string().regex(/^[a-f0-9]{64}$/),experimentKey:o.string().max(256),variationKey:o.string().max(256),inExperiment:o.boolean(),fingerprint:o.string().regex(/^[a-f0-9]{64}$/),status:o.enum(["inactive","waiting","partial","applied","mismatch","no_changes","unavailable","error"]),total:o.number().int().min(0).max(600),applied:o.number().int().min(0).max(600)})).max(100)});function ye(e){let l=n=>Array.isArray(n)?"["+n.map(l).join(",")+"]":n&&typeof n=="object"?"{"+Object.entries(n).filter(([,c])=>c!==void 0).sort(([c],[y])=>c.localeCompare(y)).map(([c,y])=>JSON.stringify(c)+":"+l(y)).join(",")+"}":JSON.stringify(n);return l({css:e.css,js:e.js,domMutations:e.domMutations,...e.renderGuard?{renderGuard:e.renderGuard}:{}})}function he(e){let l=new URL(e.baseUrl),n=l.origin==="https://api.longplayai.com"||l.origin==="https://api.dev.longplayai.com"?l.hostname.slice(4):void 0,c=e.origins??(n?[`https://console.${n}`]:[]),y=new Set(c.filter(t=>{try{let i=new URL(t);return i.origin===t&&(i.protocol==="https:"||i.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(i.hostname))}catch{return!1}})),v=!1,I=!1,k=0,T=async t=>{if(v||I||!t.source||!y.has(t.origin)||!t.data||typeof t.data!="object")return;let i=t.data;if(!(i.channel!==K||i.type!=="inspect"||i.environmentId!==e.environmentId||typeof i.nonce!="string"||!/^[a-f0-9-]{36}$/i.test(i.nonce)||typeof i.changeId!="string"||!/^[a-f0-9]{64}$/.test(i.changeId)||typeof i.url!="string"||i.url.length>2048||Date.now()-k<250)){try{if(new URL(i.url).origin!==location.origin)return}catch{return}I=!0,k=Date.now();try{let x=await e.inspect(i.changeId,i.url);!v&&x.rows.some(S=>S.changeId===i.changeId)&&t.source.postMessage({channel:K,type:"result",nonce:i.nonce,snapshot:x},t.origin)}finally{I=!1}}},u=t=>{T(t).catch(()=>{})};return window.addEventListener("message",u),()=>{v=!0,window.removeEventListener("message",u)}}var R=e=>!!e&&typeof e=="object"&&!Array.isArray(e),E=(e,l)=>typeof e=="string"&&e.length<=l,Ee=e=>typeof e=="string"&&(["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e));function ke(e){if(!R(e)||!E(e.css??"",1e5)||!E(e.js??"",1e5)||!Array.isArray(e.domMutations??[])||Array.isArray(e.domMutations)&&e.domMutations.length>200)throw new Error("Invalid visual variation");let l=e.domMutations??[];for(let n of l)if(!R(n)||!E(n.selector,2048)||!n.selector||!Ee(n.attribute)||!["set","append","remove"].includes(String(n.action))||n.value!==void 0&&!E(n.value,5e4)||n.parentSelector!==void 0&&!E(n.parentSelector,2048)||n.insertBeforeSelector!==void 0&&!E(n.insertBeforeSelector,2048))throw new Error("Invalid visual mutation");return{css:e.css??"",js:e.js??"",domMutations:l,...e.renderGuard===void 0?{}:{renderGuard:le(e.renderGuard)}}}function q(e){if(!R(e)||typeof e.environmentId!="string"||typeof e.trackExposures!="boolean"||!/^[-a-f0-9]{36}$/i.test(e.environmentId)||typeof e.generation!="string"||!/^[a-f0-9]{64}$/.test(e.generation)||!Array.isArray(e.experiments)||e.experiments.length>100||!R(e.savedGroups))throw new Error("Invalid visual experiment payload");let l=e.experiments.map(n=>{if(!R(n)||!["key","changeId"].every(c=>typeof n[c]=="string"&&n[c])||!/^[a-f0-9]{64}$/.test(String(n.changeId))||["namespace","status","groups","url"].some(c=>Object.hasOwn(n,c))||n.hashVersion!==void 0&&n.hashVersion!==2||!Array.isArray(n.variations)||n.variations.length<2||n.variations.length>20||n.urlPatterns!==void 0&&!Array.isArray(n.urlPatterns))throw new Error("Invalid visual experiment");return{...n,variations:n.variations.map(ke)}});return{...e,experiments:l}}var ve=6e4;function qe(e){let l=se(e.baseUrl);if(e.appManifestRelease!==void 0&&!/^[a-f0-9]{64}$/.test(e.appManifestRelease))throw new Error("Invalid IAM manifest digest");if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("Invalid App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),c=F(n),y=F(n),v=`${l}/api/v1/visual-experiments/${e.environmentId}`,I=e.appManifestRelease?`${v}?iam=${e.appManifestRelease}`:v,k=re(e.deviceIdCookie??"indiana_did"),T=ae(),u=null,t=!1,i=!1,x="",S={...e.attributes??{}},G,B,D=0,H=-1/0,$,m=new Map,O=new Map,C=new Set,z=ge({endpoint:`${v}/events`,fetch:n,log:e.log,label:"Visual exposure"}),P=z.flush,W,b;function j(){clearTimeout(W),b?.remove(),b=void 0}function Y(s,d){let f=M(s,d);C.has(f)||e.trackExposures===!1||u?.trackExposures===!1||t||(C.add(f),z.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:k,...T?{sessionId:T}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:s.key,variationKey:d.key}))}function we(s){if(!u||t)return;let d=new Set,f={onExperimentViewed:(r,p)=>{d.add(M(r,p))},url:location.href,attributes:{...me(k,location),...S,indianaAppManifestRelease:e.appManifestRelease??null},savedGroups:te(u.savedGroups),log:e.log},h=new Set;for(let r of u.experiments){if(de(`${e.environmentId}:${r.key}`))continue;let p=r;try{let a=ie(p,f);if(O.set(r.changeId,a),!a.inExperiment)continue;h.add(r.changeId);let w=JSON.stringify([a.key,a.value]),U=m.get(r.changeId);if(U?.signature===w){d.has(M(p,a))&&s.push(()=>{U.applied()&&Y(p,a)});continue}m.get(r.changeId)?.revert(),m.delete(r.changeId);let A=fe(a.value,{requireUniqueTargets:!!e.appManifestRelease&&Array.isArray(r.condition?.$and)&&r.condition.$and.some(g=>g!==null&&typeof g=="object"&&!Array.isArray(g)&&g.indianaAppManifestRelease===e.appManifestRelease),boundVariations:r.variations,allowJs:e.disableJsInjection===!1,nonce:e.nonce,onApplied:()=>{d.has(M(p,a))&&Y(p,a)},onError:g=>e.log?.("Visual experiment stopped",{experiment:r.key,changeId:r.changeId,variation:a.key,error:String(g)}),onTargetStatus:e.log?g=>e.log?.("Visual target status changed",{experiment:r.key,changeId:r.changeId,variation:a.key,...g}):void 0});m.set(r.changeId,{signature:w,revert:A.revert,applied:()=>A.applied,inspect:()=>A.inspect()})}catch(a){e.log?.("Skipping visual experiment",{experiment:r.key,error:String(a)})}}for(let[r,p]of m)h.has(r)||(p.revert(),m.delete(r));j()}let V=()=>{let s=[];pe(()=>we(s));for(let d of s)d()};async function _(){let s=++D,d;try{d=await c.read(I,J)}catch(h){if(t||s!==D)return!1;throw h}let f=q(d);if(f.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Visual payload scope changed");return t||s!==D?!1:(u=f,H=performance.now(),!0)}async function Q(){!await _()||t||(N(),V())}function L(){clearTimeout($),$=setTimeout(()=>{if(document.visibilityState==="hidden")return L();Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()})},ve)}let X=()=>{t||document.visibilityState==="hidden"||performance.now()-H<ve||(clearTimeout($),Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()}))},Ie=()=>{x!==location.href&&(x=location.href,V())},Z=()=>{P(!0)},N=()=>{G||t||(G=oe(Ie),addEventListener("pagehide",Z),x=location.href)};async function ee(s,d){let f=location.href,h=u,r=[],p=null;if(!t)try{let a=q(await y.read(I,J));a.environmentId===e.environmentId&&(p=a.generation)}catch{}for(let a of h?.experiments??[]){if(s&&a.changeId!==s)continue;let w=O.get(a.changeId);if(!w)continue;let U=new TextEncoder().encode(ye(w.value)),A=[...new Uint8Array(await crypto.subtle.digest("SHA-256",U))].map(be=>be.toString(16).padStart(2,"0")).join(""),g=m.get(a.changeId)?.inspect()??{status:"inactive",total:0,applied:0};r.push({changeId:a.changeId,experimentKey:a.key,variationKey:w.key,inExperiment:w.inExperiment,fingerprint:A,...g})}return{environmentId:e.environmentId,release:e.appManifestRelease??null,generation:h?.generation??null,publishedGeneration:p,checkedAt:new Date().toISOString(),origin:location.origin,pathname:location.pathname,urlMatches:location.href===f&&(!d||d===f)&&h===u,stopped:t,rows:r}}let ne,xe=ue(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=ce(e.appManifestRelease)),e.antiFlicker&&(b=document.createElement("style"),e.nonce&&(b.nonce=e.nonce),b.textContent="body { visibility: hidden !important }",document.head.append(b),W=setTimeout(j,Math.min(3e3,Math.max(0,e.antiFlickerTimeout??1e3))));try{if(!await _()||t)return;N(),V()}finally{j(),t||(L(),document.addEventListener("visibilitychange",X),ne=he({environmentId:e.environmentId,baseUrl:l,origins:e.diagnosticsOrigins,inspect:ee}))}}},async refresh(){t||await _()&&(i&&N(),V())},setAttributes(s){S={...s},V()},flush:()=>P(),getDiagnostics:ee,getResults(){return new Map(O)},get generation(){return u?.generation??null},destroy(){t=!0,clearTimeout($),document.removeEventListener("visibilitychange",X),xe(),ne?.(),D++,c.destroy(),y.destroy(),G?.(),B?.destroy(),removeEventListener("pagehide",Z),j();for(let s of m.values())s.revert();m.clear(),P(!0),u=null,O.clear(),C.clear(),S={}}}}export{qe as createVisualExperiments,Ve as loadAppManifestRelease};
1
+ import{a as pe,c as fe}from"./chunk-OJM6ORHE.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as J,b as F,c as ge,e as me}from"./chunk-2DPNSTCN.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-C2KT5ZFU.js";import"./chunk-3VUPVXAV.js";import"./chunk-RV6UAUK2.js";import{b as o}from"./chunk-RGEBK6UF.js";import{c as te,e as ie,g as M}from"./chunk-O4KXODTJ.js";import"./chunk-CILM5XMH.js";import"./chunk-DSPLGTQI.js";import"./chunk-WOT6VMZA.js";var K="indiana-visual-diagnostics-v1",Ae=o.strictObject({environmentId:o.string().uuid(),release:o.string().regex(/^[a-f0-9]{64}$/).nullable(),generation:o.string().regex(/^[a-f0-9]{64}$/).nullable(),publishedGeneration:o.string().regex(/^[a-f0-9]{64}$/).nullable(),checkedAt:o.string().datetime(),origin:o.string().url(),pathname:o.string().max(2048),urlMatches:o.boolean(),stopped:o.boolean(),rows:o.array(o.strictObject({changeId:o.string().regex(/^[a-f0-9]{64}$/),experimentKey:o.string().max(256),variationKey:o.string().max(256),inExperiment:o.boolean(),fingerprint:o.string().regex(/^[a-f0-9]{64}$/),status:o.enum(["inactive","waiting","partial","applied","mismatch","no_changes","unavailable","error"]),total:o.number().int().min(0).max(600),applied:o.number().int().min(0).max(600)})).max(100)});function ye(e){let l=n=>Array.isArray(n)?"["+n.map(l).join(",")+"]":n&&typeof n=="object"?"{"+Object.entries(n).filter(([,c])=>c!==void 0).sort(([c],[y])=>c.localeCompare(y)).map(([c,y])=>JSON.stringify(c)+":"+l(y)).join(",")+"}":JSON.stringify(n);return l({css:e.css,js:e.js,domMutations:e.domMutations,...e.renderGuard?{renderGuard:e.renderGuard}:{}})}function he(e){let l=new URL(e.baseUrl),n=l.origin==="https://api.longplayai.com"||l.origin==="https://api.dev.longplayai.com"?l.hostname.slice(4):void 0,c=e.origins??(n?[`https://console.${n}`]:[]),y=new Set(c.filter(t=>{try{let i=new URL(t);return i.origin===t&&(i.protocol==="https:"||i.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(i.hostname))}catch{return!1}})),v=!1,I=!1,k=0,T=async t=>{if(v||I||!t.source||!y.has(t.origin)||!t.data||typeof t.data!="object")return;let i=t.data;if(!(i.channel!==K||i.type!=="inspect"||i.environmentId!==e.environmentId||typeof i.nonce!="string"||!/^[a-f0-9-]{36}$/i.test(i.nonce)||typeof i.changeId!="string"||!/^[a-f0-9]{64}$/.test(i.changeId)||typeof i.url!="string"||i.url.length>2048||Date.now()-k<250)){try{if(new URL(i.url).origin!==location.origin)return}catch{return}I=!0,k=Date.now();try{let x=await e.inspect(i.changeId,i.url);!v&&x.rows.some(S=>S.changeId===i.changeId)&&t.source.postMessage({channel:K,type:"result",nonce:i.nonce,snapshot:x},t.origin)}finally{I=!1}}},u=t=>{T(t).catch(()=>{})};return window.addEventListener("message",u),()=>{v=!0,window.removeEventListener("message",u)}}var R=e=>!!e&&typeof e=="object"&&!Array.isArray(e),E=(e,l)=>typeof e=="string"&&e.length<=l,Ee=e=>typeof e=="string"&&(["html","class","style","position","href","src","alt","title","id","role","hidden"].includes(e)||/^(aria|data)-[a-z0-9_-]+$/.test(e));function ke(e){if(!R(e)||!E(e.css??"",1e5)||!E(e.js??"",1e5)||!Array.isArray(e.domMutations??[])||Array.isArray(e.domMutations)&&e.domMutations.length>200)throw new Error("Invalid visual variation");let l=e.domMutations??[];for(let n of l)if(!R(n)||!E(n.selector,2048)||!n.selector||!Ee(n.attribute)||!["set","append","remove"].includes(String(n.action))||n.value!==void 0&&!E(n.value,5e4)||n.parentSelector!==void 0&&!E(n.parentSelector,2048)||n.insertBeforeSelector!==void 0&&!E(n.insertBeforeSelector,2048))throw new Error("Invalid visual mutation");return{css:e.css??"",js:e.js??"",domMutations:l,...e.renderGuard===void 0?{}:{renderGuard:le(e.renderGuard)}}}function q(e){if(!R(e)||typeof e.environmentId!="string"||typeof e.trackExposures!="boolean"||!/^[-a-f0-9]{36}$/i.test(e.environmentId)||typeof e.generation!="string"||!/^[a-f0-9]{64}$/.test(e.generation)||!Array.isArray(e.experiments)||e.experiments.length>100||!R(e.savedGroups))throw new Error("Invalid visual experiment payload");let l=e.experiments.map(n=>{if(!R(n)||!["key","changeId"].every(c=>typeof n[c]=="string"&&n[c])||!/^[a-f0-9]{64}$/.test(String(n.changeId))||["namespace","status","groups","url"].some(c=>Object.hasOwn(n,c))||n.hashVersion!==void 0&&n.hashVersion!==2||!Array.isArray(n.variations)||n.variations.length<2||n.variations.length>20||n.urlPatterns!==void 0&&!Array.isArray(n.urlPatterns))throw new Error("Invalid visual experiment");return{...n,variations:n.variations.map(ke)}});return{...e,experiments:l}}var ve=6e4;function qe(e){let l=se(e.baseUrl);if(e.appManifestRelease!==void 0&&!/^[a-f0-9]{64}$/.test(e.appManifestRelease))throw new Error("Invalid IAM manifest digest");if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("Invalid App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),c=F(n),y=F(n),v=`${l}/api/v1/visual-experiments/${e.environmentId}`,I=e.appManifestRelease?`${v}?iam=${e.appManifestRelease}`:v,k=re(e.deviceIdCookie??"indiana_did"),T=ae(),u=null,t=!1,i=!1,x="",S={...e.attributes??{}},G,B,D=0,H=-1/0,$,m=new Map,O=new Map,C=new Set,z=ge({endpoint:`${v}/events`,fetch:n,log:e.log,label:"Visual exposure"}),P=z.flush,W,b;function j(){clearTimeout(W),b?.remove(),b=void 0}function Y(s,d){let f=M(s,d);C.has(f)||e.trackExposures===!1||u?.trackExposures===!1||t||(C.add(f),z.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:k,...T?{sessionId:T}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:s.key,variationKey:d.key}))}function we(s){if(!u||t)return;let d=new Set,f={onExperimentViewed:(r,p)=>{d.add(M(r,p))},url:location.href,attributes:{...me(k,location),...S,indianaAppManifestRelease:e.appManifestRelease??null},savedGroups:te(u.savedGroups),log:e.log},h=new Set;for(let r of u.experiments){if(de(`${e.environmentId}:${r.key}`))continue;let p=r;try{let a=ie(p,f);if(O.set(r.changeId,a),!a.inExperiment)continue;h.add(r.changeId);let w=JSON.stringify([a.key,a.value]),U=m.get(r.changeId);if(U?.signature===w){d.has(M(p,a))&&s.push(()=>{U.applied()&&Y(p,a)});continue}m.get(r.changeId)?.revert(),m.delete(r.changeId);let A=fe(a.value,{requireUniqueTargets:!!e.appManifestRelease&&Array.isArray(r.condition?.$and)&&r.condition.$and.some(g=>g!==null&&typeof g=="object"&&!Array.isArray(g)&&g.indianaAppManifestRelease===e.appManifestRelease),boundVariations:r.variations,allowJs:e.disableJsInjection===!1,nonce:e.nonce,onApplied:()=>{d.has(M(p,a))&&Y(p,a)},onError:g=>e.log?.("Visual experiment stopped",{experiment:r.key,changeId:r.changeId,variation:a.key,error:String(g)}),onTargetStatus:e.log?g=>e.log?.("Visual target status changed",{experiment:r.key,changeId:r.changeId,variation:a.key,...g}):void 0});m.set(r.changeId,{signature:w,revert:A.revert,applied:()=>A.applied,inspect:()=>A.inspect()})}catch(a){e.log?.("Skipping visual experiment",{experiment:r.key,error:String(a)})}}for(let[r,p]of m)h.has(r)||(p.revert(),m.delete(r));j()}let V=()=>{let s=[];pe(()=>we(s));for(let d of s)d()};async function _(){let s=++D,d;try{d=await c.read(I,J)}catch(h){if(t||s!==D)return!1;throw h}let f=q(d);if(f.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Visual payload scope changed");return t||s!==D?!1:(u=f,H=performance.now(),!0)}async function Q(){!await _()||t||(N(),V())}function L(){clearTimeout($),$=setTimeout(()=>{if(document.visibilityState==="hidden")return L();Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()})},ve)}let X=()=>{t||document.visibilityState==="hidden"||performance.now()-H<ve||(clearTimeout($),Q().catch(s=>e.log?.("Visual payload refresh failed",{error:String(s)})).finally(()=>{t||L()}))},Ie=()=>{x!==location.href&&(x=location.href,V())},Z=()=>{P(!0)},N=()=>{G||t||(G=oe(Ie),addEventListener("pagehide",Z),x=location.href)};async function ee(s,d){let f=location.href,h=u,r=[],p=null;if(!t)try{let a=q(await y.read(I,J));a.environmentId===e.environmentId&&(p=a.generation)}catch{}for(let a of h?.experiments??[]){if(s&&a.changeId!==s)continue;let w=O.get(a.changeId);if(!w)continue;let U=new TextEncoder().encode(ye(w.value)),A=[...new Uint8Array(await crypto.subtle.digest("SHA-256",U))].map(be=>be.toString(16).padStart(2,"0")).join(""),g=m.get(a.changeId)?.inspect()??{status:"inactive",total:0,applied:0};r.push({changeId:a.changeId,experimentKey:a.key,variationKey:w.key,inExperiment:w.inExperiment,fingerprint:A,...g})}return{environmentId:e.environmentId,release:e.appManifestRelease??null,generation:h?.generation??null,publishedGeneration:p,checkedAt:new Date().toISOString(),origin:location.origin,pathname:location.pathname,urlMatches:location.href===f&&(!d||d===f)&&h===u,stopped:t,rows:r}}let ne,xe=ue(()=>{i&&!t&&V()});return{async start(){if(!(i||t)){i=!0,e.appManifestRelease&&(B=ce(e.appManifestRelease)),e.antiFlicker&&(b=document.createElement("style"),e.nonce&&(b.nonce=e.nonce),b.textContent="body { visibility: hidden !important }",document.head.append(b),W=setTimeout(j,Math.min(3e3,Math.max(0,e.antiFlickerTimeout??1e3))));try{if(!await _()||t)return;N(),V()}finally{j(),t||(L(),document.addEventListener("visibilitychange",X),ne=he({environmentId:e.environmentId,baseUrl:l,origins:e.diagnosticsOrigins,inspect:ee}))}}},async refresh(){t||await _()&&(i&&N(),V())},setAttributes(s){S={...s},V()},flush:()=>P(),getDiagnostics:ee,getResults(){return new Map(O)},get generation(){return u?.generation??null},destroy(){t=!0,clearTimeout($),document.removeEventListener("visibilitychange",X),xe(),ne?.(),D++,c.destroy(),y.destroy(),G?.(),B?.destroy(),removeEventListener("pagehide",Z),j();for(let s of m.values())s.revert();m.clear(),P(!0),u=null,O.clear(),C.clear(),S={}}}}export{qe as createVisualExperiments,Ve as loadAppManifestRelease};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkerlandai/longplay-sdk",
3
- "version": "0.10.39",
3
+ "version": "0.10.40",
4
4
  "description": "Framework-independent Longplay SDK for customer identity, entitlements, credits, offers and growth surfaces.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -60,12 +60,6 @@
60
60
  "import": "./dist/visual.js"
61
61
  }
62
62
  },
63
- "scripts": {
64
- "build": "tsup",
65
- "prepack": "pnpm run build",
66
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
67
- "lint": "node ../../scripts/ci/lint.mjs --workspace packages/sdk"
68
- },
69
63
  "dependencies": {
70
64
  "@ai-sdk/provider": "4.0.26",
71
65
  "@types/json-schema": "7.0.15",
@@ -75,13 +69,13 @@
75
69
  "zod": "4.6.6"
76
70
  },
77
71
  "devDependencies": {
78
- "@indiana/contracts": "workspace:*",
79
72
  "@openrouter/sdk": "^1.4.25",
80
73
  "@types/css-tree": "^3.2.0",
81
74
  "ai": "7.0.136",
82
75
  "tsup": "^8.5.1",
83
76
  "typescript": "^5.9.3",
84
- "whatwg-url-minimum": "0.2.0"
77
+ "whatwg-url-minimum": "0.2.0",
78
+ "@indiana/contracts": "0.1.0"
85
79
  },
86
80
  "peerDependencies": {
87
81
  "@openrouter/sdk": "^1.4.25"
@@ -90,5 +84,10 @@
90
84
  "@openrouter/sdk": {
91
85
  "optional": true
92
86
  }
87
+ },
88
+ "scripts": {
89
+ "build": "tsup",
90
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
91
+ "lint": "node ../../scripts/ci/lint.mjs --workspace packages/sdk"
93
92
  }
94
- }
93
+ }
@@ -1 +0,0 @@
1
- import{a,b}from"./chunk-GGYBZWWY.js";import"./chunk-2Y5SGDC6.js";import"./chunk-3JD3U45R.js";import"./chunk-YURGISSB.js";import"./chunk-TPXRO63H.js";import"./chunk-3S25TLC3.js";import"./chunk-NOOIJXRN.js";import"./chunk-CILM5XMH.js";import"./chunk-WOT6VMZA.js";export{a as validateEntitlementCheck,b as validateResourceCheck};
@@ -1 +0,0 @@
1
- import{b as e}from"./chunk-NOOIJXRN.js";var c=e.enum(["replace","stack_native"]);export{c as a};
@@ -1 +0,0 @@
1
- import{p as n,s as t}from"./chunk-N774V4SQ.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};