@tinkerlandai/longplay-sdk 0.10.94 → 0.10.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +7 -0
- package/README.zh-CN.md +4 -0
- package/dist/{chunk-Q5IYCTRL.js → chunk-33EKLIMB.js} +1 -1
- package/dist/{chunk-6QBSJRAD.js → chunk-55B6CYG6.js} +1 -1
- package/dist/chunk-7DQV2EUW.js +1 -0
- package/dist/{chunk-FEU6XRHV.js → chunk-AO56DGNZ.js} +1 -1
- package/dist/{chunk-C4HLVYSU.js → chunk-BANN2HQH.js} +1 -1
- package/dist/{chunk-FDXBCQBO.js → chunk-BQFIJCBA.js} +1 -1
- package/dist/chunk-GFH7OK3S.js +1 -0
- package/dist/{chunk-H3LJWAAE.js → chunk-HKLAHQKF.js} +1 -1
- package/dist/{chunk-ANEFV7YJ.js → chunk-JLKODCRG.js} +2 -2
- package/dist/{chunk-NKYNGR3L.js → chunk-JYTUTIBB.js} +1 -1
- package/dist/{chunk-IL5OTR6J.js → chunk-PBHOJKKG.js} +1 -1
- package/dist/{chunk-5SB3RRGA.js → chunk-WLO2GDRF.js} +1 -1
- package/dist/{chunk-VVBXVJI6.js → chunk-XWVK4SJA.js} +1 -1
- package/dist/{content-K2T4V3ZD.js → content-IDQO7TKS.js} +1 -1
- package/dist/{funnel-host-purchase-M2JNOOCE.js → funnel-host-purchase-7IYZRPYA.js} +1 -1
- package/dist/funnel-host-purchase-entry-FFZUEX4Q.js +1 -0
- package/dist/{funnel-host-recovery-paywall-XFL6JS74.js → funnel-host-recovery-paywall-DGCR4IBQ.js} +1 -1
- package/dist/{funnel-paywall-prerender-YUBH7ZC7.js → funnel-paywall-prerender-QHEGZSPT.js} +1 -1
- package/dist/{funnel-runtime-host-3P62SXBA.js → funnel-runtime-host-CFDI4AWM.js} +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/page.js +1 -1
- package/dist/{paywall-JTKB4MMC.js → paywall-2Z3FUN2M.js} +1 -1
- package/dist/{paywall-content-GJX3FQ6D.js → paywall-content-JXWPOE3Y.js} +1 -1
- package/dist/{paywall-session-PCWN2M24.js → paywall-session-RNEEPYPG.js} +1 -1
- package/dist/react-native.js +1 -1
- package/dist/server.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-MMHL2KFB.js +0 -1
- package/dist/chunk-XKYVXIUI.js +0 -1
- package/dist/funnel-host-purchase-entry-OKHAEHOG.js +0 -1
- /package/dist/{chunk-ANEFV7YJ.js.LEGAL.txt → chunk-JLKODCRG.js.LEGAL.txt} +0 -0
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as En,c as bn}from"./chunk-VVBXVJI6.js";import{a as Rn}from"./chunk-7ZAM4YRK.js";import{a as We}from"./chunk-AEQUKR4O.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as pn,c as wn,d as Sn}from"./chunk-5SB3RRGA.js";import"./chunk-XLGNBPGF.js";import{a as In}from"./chunk-XKYVXIUI.js";import"./chunk-EQUVI5QU.js";import{h as mn,i as vn,k as Pn}from"./chunk-IL5OTR6J.js";import{E as Ae,d as Xe,f as Qe,g as ge,h as ve,i as Ye,w as yn}from"./chunk-FDXBCQBO.js";import"./chunk-F4AIEI5N.js";import{a as ze}from"./chunk-S2S4ROGY.js";import{d as hn,f as gn}from"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-C4HLVYSU.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import{K as Ke}from"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import{B as dn,C as ln,D as un,E as fn,c as an,d as sn,e as cn}from"./chunk-3532HSBP.js";import{A as Le,B as Be,D as He,F as qe,G as Ue,I as Ve,J as je,K as Ge,L as Je,M as Te,N as $e,z as _e}from"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import{b as Ce}from"./chunk-6QBSJRAD.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as G}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as we,d as Ee}from"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-FEU6XRHV.js";import"./chunk-5MRSFLQA.js";import{b as U}from"./chunk-W22ESUYY.js";import{a as Z}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var I=class extends Error{constructor(f,b=0,w=!1,h="fix_request"){super(f);this.code=f;this.status=b;this.retryable=w;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function _n(n,d){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let f=n.body?.getReader();if(!f)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");let b=()=>{f.cancel().catch(()=>{})};d.addEventListener("abort",b,{once:!0});let w=0,h="",t=new TextDecoder("utf-8",{fatal:!0});try{for(d.throwIfAborted();;){let i=await f.read();if(d.throwIfAborted(),i.done)break;if(w+=i.value.byteLength,w>262144)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=t.decode(i.value,{stream:!0})}return h+=t.decode(),JSON.parse(h)}catch(i){throw d.throwIfAborted(),i instanceof I?i:new I("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{d.removeEventListener("abort",b),await f.cancel().catch(()=>{}),f.releaseLock()}}function Tn(n){let d=qe.parse(n.origin),f=Ue.parse(n.manifest),b={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let m of["projectId","environmentId","environment"])if(f[m]!==n.scope[m])throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");let w=n.customerId===void 0?null:U.uuid().parse(n.customerId),h=0,t=null,i=null,u=new AbortController,y=n.fetch??globalThis.fetch;async function P(m,s,E,_,F){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 O=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:F??(E===void 0?{}:{operationId:E})})}),J=await _n(O,o);if(o.throwIfAborted(),l!==h)throw new DOMException("Merchant identity changed","AbortError");if(!O.ok){let M=$e.safeParse(J);throw!M.success||M.data.scope.projectId!==n.scope.projectId||M.data.scope.environment!==n.scope.environment||M.data.scope.environmentId!==n.scope.environmentId||M.data.requestId!==g||M.data.command!==S.command?new I("MERCHANT_BRIDGE_INVALID_RESPONSE",O.status):new I(M.data.error.code,O.status,M.data.error.retryable,M.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",O.status);let $=s.safeParse(c.data.data);if(!$.success)throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE",O.status);return $.data}function R(){if(!w)throw new I("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return w}async function B(m,s,E,_){let F=R();if(_!==void 0&&Te.parse({operationId:_,customerId:F}),!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,O)=>{o=()=>O(l.reason),l.addEventListener("abort",o,{once:!0})});try{let O=E(async()=>{let c=await import("./merchant-bridge-contracts-OIYML3DE.js");if(l.throwIfAborted(),S!==h||w!==F)throw new DOMException("Merchant identity changed","AbortError");return c},l),J=await Promise.race([O,T]);return l.throwIfAborted(),J}finally{l.removeEventListener("abort",o)}}async function z(m,s,E,_){let F=R(),S=Te.parse({operationId:E,customerId:F}),l=await P(m,s,S.operationId,_,S);if(l.customerId!==F||l.operationId!==S.operationId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return l}return{async readPresentation(m){let s=await P("presentation",Ge,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(s.presentation&&w!==null&&s.presentation.customerId!==w)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=s.nativeUserId,t=s.presentation,s},async createSession(m){let s=await P("session",je,void 0,m);if(i!==null&&i!==s.nativeUserId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(w!==null&&w!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==s.session.customerId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return w=s.session.customerId,i=s.nativeUserId,s.session},async reportPresentation(m,s){let E=R(),_=Je.parse(m);if(!t||t.customerId!==E||t.decisionId!==_.decisionId)throw new I("MERCHANT_BRIDGE_SCOPE_MISMATCH");return P("presentation_events",U.strictObject({queued:U.literal(!0)}),void 0,s,_)},async readCustomerCommerce(m){let s=R(),E=await B("customer_commerce",m,async(_,F)=>{let[S,l]=await Promise.all([_(),P("customer_commerce",U.unknown(),void 0,F)]),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(_,F)=>z("purchases",(await _()).merchantBridgeOperationSchema,m,F),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(_,F)=>z("subscription_changes",(await _()).merchantBridgeOperationSchema,m,F),m);if(E.type!=="subscription_change")throw new I("MERCHANT_BRIDGE_INVALID_RESPONSE");return E},reset(){h++,u.abort(),u=new AbortController,w=null,t=null,i=null}}}var en=U.strictObject({command:ve,target:Qe,runId:U.uuid().optional(),expiresAt:U.iso.datetime({offset:!0}).optional(),deliveryLimit:U.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Ze=U.strictObject({schemaVersion:U.literal(1),entries:U.array(en).max(4e3)});function nn(n){let d=!1,f=()=>{d||n.unavailable(),d=!0};function b(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function w(t){let i=b()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ze.parse(JSON.parse(i)).entries}function h(t,i){let u=b();if(!u)return;if(!i.length)return u.removeItem(t);let y=JSON.stringify(Ze.parse({schemaVersion:1,entries:i}));if(y.length>1048576)throw Error("Entry recovery is too large");u.setItem(t,y)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:w(i)}}catch{f();return}},retain(t,i){if(t)try{let u=en.parse(i);h(t,[...w(t).filter(y=>y.command.funnelId!==u.command.funnelId),u])}catch{f()}},forget(t,i){if(t)try{h(t,w(t).filter(u=>u.command.requestId!==i))}catch{f()}}}}var tn=U.strictObject({version:U.literal(1),runs:U.array(U.uuid()).max(100)}),De=new WeakMap,Fe=new WeakMap;function Se(n){let d=!1;function f(){d||n.unavailable(),d=!0}function b(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function w(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let u=i.get(t.key);return u||i.set(t.key,u=new Set),u}function h(t){if(!t)return;let i=De.get(t.storage),u=i?.get(t.key);u?.delete(t.requestId),u?.size===0&&i?.delete(t.key)}return{claim(t,i,u,y,P=!1){if(u!==void 0)try{let R=n.binding();if(!R)throw Error("Entry delivery identity is unavailable");let B={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...R,i,t]),requestId:y},z=b(B);if(Fe.get(B.storage)?.has(B.key))throw Error("Entry delivery storage is unavailable");B.storage.setItem(B.key,JSON.stringify({version:1,runs:z}));let m=w(B);return!P&&!m.has(y)&&z.length+m.size>=u?!1:(m.add(y),B)}catch{return f(),!1}},accept(t,i){if(t)try{let u=b(t);u.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...u,i].slice(-100)})))}catch{let u=Fe.get(t.storage);u||Fe.set(t.storage,u=new Set),u.add(t.key),f()}finally{h(t)}},release:h}}function Pe(){let n,d,f=()=>{clearTimeout(n),n=void 0;let b=d;d=void 0,b?.cancelled()};return{get active(){return d!==void 0},start(b,w,h,t){if(d)return;if(b===0){w()?h():t();return}let i={valid:w,cancelled:t};d=i,n=setTimeout(()=>{d===i&&(d=void 0,n=void 0,w()?h():t())},b*1e3)},recheck(){d&&!d.valid()&&f()},cancel:f}}var Re=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function Cn(n){let d=we(n.baseUrl),f=n.scope,b=Ce(n),w=n.fetch??globalThis.fetch.bind(globalThis),h,t=!1,i=!1,u=0,y=0,P="",R=0,B=0,z=0,m=!1,s,E=!0,_,F,S,l,o,T=-1,g,O=e=>{g===e&&(M.release(e.deliveryTicket),g=void 0,x())},J=new Set,c=(e,a)=>Z(n.onStatus,e,a),$=Pe(),M=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>c("delivery_unavailable")}),ee=new Set,te=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[d,f.projectId,f.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>c("recovery_unavailable")}),Y=e=>te.forget(e.storageKey,e.command.requestId);function Q(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),te.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),x()}let le=()=>$.active||g!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Q(o.recovery,a);let p=Re(a);o.slot.hidden=p,p!==o.background&&(o.background=p,p?c("run_background",o.entryId):T=y,x())}function pe(e,a,p){let v=e.client.view;if(!a||e.background||!v?.screen||v.paywall||v.pendingRequest||v.stopped||v.status!=="waiting")return;let K=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:v.nodeId,visit:v.visit,revision:v.revision,customerToken:a}),j=Ce({...n,session:void 0});j.requestWithCredential("funnels",K,e.runToken,{keepalive:p}).then(()=>Y(e.recovery)).catch(()=>{}).finally(()=>j.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<B&&performance.now()<z;function C(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return c("incompatible",e.id),!1}}function H(e){if(t||e.epoch!==R||e.visit!==y||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function W(e){if(le()){c("in_progress",e.id);return}let a=R,p=y;$.start(e.delivery?.delaySeconds??0,()=>!t&&a===R&&p===y&&document.visibilityState!=="hidden"&&C(e)&&h?.entries.some(v=>v.id===e.id&&v.funnelId===e.funnelId&&v.versionId===e.versionId&&v.event===e.event&&JSON.stringify(v.target)===JSON.stringify(e.target)&&JSON.stringify(v.delivery)===JSON.stringify(e.delivery))===!0,()=>{V(e)},()=>{J.delete(`${e.funnelId}:${e.id}`)})}async function V(e){if(le()){c("in_progress",e.id);return}if(!n.session.peek()){c("identity_required",e.id);return}let a=te.load(),p=a?.entries.find(A=>A.command.funnelId===e.funnelId&&(!A.expiresAt||Date.parse(A.expiresAt)>Date.now()));if(p){if(!X(p)){c("recovery_pending",e.id);return}let A={...p,storageKey:a.key,epoch:R,visit:y};ee.add(A.command.requestId),g=A,await N(A);return}let v=crypto.randomUUID(),K=M.claim(e.id,e.funnelId,e.delivery?.maxPerSession,v);if(K===!1){c("frequency",e.id),x();return}let j={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:K,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:v,locale:document.documentElement.lang||"en"}),epoch:R,visit:y,target:e.target,storageKey:a?.key};ee.add(j.command.requestId),g=j,await N(j)}async function N(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let p,v=!1,K=!1;async function j(A){if(e.epoch!==R)return;let D=A.view;if(!(e.storageKey&&D&&(Re(D)||D.paywall||D.pendingRequest))&&D&&["running","waiting"].includes(D.status))try{await A.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:D.nodeId,visit:D.visit,revision:D.revision}),Y(e)}catch(k){if(!(k instanceof G&&k.code==="FORBIDDEN"))throw k}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let q=M.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);q!==!1&&(e.deliveryTicket=q)}Q(e),c("starting",e.command.entryId);let A=await b.request("funnels",e.command),D=Ye.safeParse(A);if(D.success){if(D.data.scope.projectId!==f.projectId||D.data.scope.environment!==f.environment)throw new G("SCOPE_MISMATCH","Entry scope changed");e.epoch===R&&c(D.data.reason,e.command.entryId),Y(e),O(e);return}let k=Xe.parse(A);if(!k.runToken||k.scope.projectId!==f.projectId||k.scope.environment!==f.environment||k.run.source.type!=="funnel"||k.run.source.id!==e.command.funnelId||k.run.source.versionId!==e.command.versionId||e.runId!==void 0&&k.run.id!==e.runId)throw new G("INVALID_RESPONSE","Invalid entry Run");if(M.accept(e.deliveryTicket,k.run.id),e.epoch!==R){O(e),c("identity_changed",e.command.entryId);return}Q(e,k.run);let L=Ae({...n,runToken:k.runToken,funnelId:e.command.funnelId,initialResponse:a?A:void 0});p=L,K=!0,await L.get(),K=!1;let ne=L.view;if(!ne||ne.id!==k.run.id||ne.source.type!=="funnel"||ne.source.id!==e.command.funnelId||ne.source.versionId!==e.command.versionId)throw new G("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(ne.status)){Y(e),O(e),c("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-3P62SXBA.js");if(!H(e)){await j(L),c("left_screen",e.command.entryId),O(e);return}let Ne=!1,xe=!1;if(o&&!o.background){await j(L),c("in_progress",e.command.entryId),O(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Re(ne),n.container.append(ie);let ke=await fe(ie,{...n.host,client:L,appManifestRelease:n.appManifestRelease,onState(q){me(L,q),Z(n.host?.onState,q)},onDismiss(q){Ne=!0,ie.remove(),q&&!["running","waiting"].includes(q.status)&&Y(e),o?.client===L&&(o=void 0,L.reset(),x(),q&&q.status!=="completed"&&c("run_ended",e.command.entryId)),Z(n.host?.onDismiss,q)},onComplete(q){xe=!0,Y(e),o?.client===L&&re(),Z(n.host?.onComplete,q)},onError(q){Z(n.host?.onError,q),o?.client===L&&q instanceof G&&q.code==="FORBIDDEN"&&(Y(e),re(),c("run_ended",e.command.entryId))}}).catch(q=>{throw ie.remove(),q});if(!H(e)||Ne||xe){ke.destroy(),ie.remove(),H(e)||await j(L),O(e);return}let he=Re(L.view??ne);ie.hidden=he,o={host:ke,client:L,slot:ie,entryId:e.command.entryId,background:he,runToken:k.runToken,owner:n.session.peek(),recovery:e},he||(T=e.visit),v=!0,O(e),c("started",e.command.entryId),he&&c("run_background",e.command.entryId)}catch(A){A instanceof G&&(!p||K&&A.code==="FORBIDDEN")&&A.status!==void 0&&A.status>=400&&A.status<500&&!A.retryable&&(Y(e),O(e)),e.epoch===R&&!t&&(c("start_failed",e.command.entryId),Z(n.host?.onError,A))}finally{v||p?.reset(),e.dispatching=!1}}function X(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=te.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){te.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||ee.has(a.command.requestId)||!X(a))continue;ee.add(a.command.requestId);let p={...a,storageKey:e.key,epoch:R,visit:y};return g=p,N(p),!0}return!1}function ue(){if(m=!1,$.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(T=y),!ye()){if(!r()){E=!0;return}E=!1;for(let a of h?.entries??[]){let p=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||J.has(p)||!C(a))){if(!n.session.peek()){c("identity_required",a.id);continue}if(T===y){J.add(p),e&&c("in_progress",a.id);continue}if(g||$.active){c("in_progress",a.id);return}J.add(p),W(a);break}}}}let x=()=>{!m&&!t&&(m=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===P?!1:(P=e,y++,$.cancel(),E=!0,J.clear(),ee.clear(),!0)}function oe(){se()&&x()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let p=a.closest("button,a,input");if(!(!p||p.matches(":disabled,[aria-disabled='true']")||p.closest("[hidden],[inert],[aria-hidden='true']")))for(let v of h?.entries??[]){let K=v.target.button;if(!(v.event!=="button_click"||!K||!C(v))){try{let j=be(document);if(!p.matches(K.selector)||j(K.selector,p)!==1)continue}catch{c("incompatible",v.id);continue}W(v);break}}}async function Oe(){if(t)return;if(s)return s;let e=++u,a=new AbortController;_=a;let p,v=new Promise((A,D)=>{p=()=>D(new G("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",p,{once:!0})}),K=setTimeout(()=>a.abort(),n.timeoutMs??5e3),j=(async()=>{let A=async()=>{let fe=await w(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},D=await Promise.race([A(),v]),k=Date.parse(D.validatedAt),L=Date.parse(D.validUntil);if(D.scope.projectId!==f.projectId||D.scope.environment!==f.environment||D.scope.environmentId!==n.environmentId||D.release!==n.appManifestRelease||L<=Date.now()||k>Date.now()+5e3||L-k>6e4||L<=k)throw new G("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==u)return;let ne=h===void 0;h=D,B=L,z=performance.now()+Math.min(L-Date.now(),6e4),$.recheck(),(ne||E)&&x()})();s=j;try{await j}finally{clearTimeout(K),a.signal.removeEventListener("abort",p),s===j&&(s=void 0)}}async function on(){if(!(!i||t)){try{await Oe()}catch{t||c("configuration_unavailable")}x()}}let Me=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,P=location.origin+location.pathname,F=Ee(oe),S=n.session.subscribeIdentity(()=>{R++,$.cancel(),M.release(g?.deliveryTicket),E=!0,g=void 0,J.clear(),T=-1,ee.clear(),o&&pe(o,o.owner,!1),re(),x()}),l=new MutationObserver(x),l.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",x),addEventListener("pagehide",ae),await Me.refresh())},refresh:Oe,async retry(){g&&!t&&g.epoch===R&&await N(g)},destroy(){t=!0,u++,$.cancel(),M.release(g?.deliveryTicket),Me.destroy(),_?.abort(),l?.disconnect(),F?.(),S?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",x),removeEventListener("pagehide",ae),ae(),re(),b.dispose(),h=void 0}}}function An(n){let d=we(n.baseUrl),f=n.fetch??globalThis.fetch.bind(globalThis),b,w=0,h=0,t=!1,i=!1,u=!1,y=0,P=0,R=-1,B=!1,z="",m,s,E,_,F=new Set,S,l,o,T=(r,C)=>Z(n.onStatus,r,C),g=Pe(),O=()=>{try{return n.deliveryIdentity?.()}catch{return}},J=()=>JSON.stringify(O()),c=Se({storage:n.deliveryStorage,binding:()=>{let r=O();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 M(r){try{return $()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return T("incompatible",r.id),!1}}function ee(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function te(r){if(r.dispatching)return;r.dispatching=!0;let C=y;try{let H=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});c.accept(r.deliveryTicket,H.run.id);let{showFunnelRun:W}=await import("./funnel-runtime-host-3P62SXBA.js");if(t||C!==y||l!==r)return;let V=document.createElement("div");n.container.append(V),R=P;let N=await W(V,{...n.host,client:H.controller,appManifestRelease:n.appManifestRelease,onDismiss(X){o?.process===r.process&&(o=void 0,V.remove()),Z(n.host?.onDismiss,X)}});if(t||C!==y||l!==r){N.destroy(),V.remove();return}o={entry:r.entry,process:r.process,host:N,slot:V,deliveryTicket:r.deliveryTicket},l=void 0,T("run_presented",r.entry.id)}catch(H){if(t||C!==y||l!==r)return;H instanceof G&&"result"in H?(c.release(r.deliveryTicket),l=void 0,r.process.destroy(),T("suppressed",r.entry.id),Q()):T("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function Y(r){if(t||i||l||o||S||g.active||R===P||!M(r))return;let C=`${P}:${r.id}`;if(F.has(C))return;F.add(C);let H=P,W=y,V=J();g.start(r.delivery?.delaySeconds??0,()=>!t&&y===W&&P===H&&J()===V&&document.visibilityState!=="hidden"&&M(r)&&b?.entries.some(N=>N.id===r.id&&N.funnelId===r.funnelId&&N.versionId===r.versionId&&N.event===r.event&&JSON.stringify(N.target)===JSON.stringify(r.target)&&JSON.stringify(N.delivery)===JSON.stringify(r.delivery))===!0,()=>{let N=c.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(N===!1){T("frequency",r.id),Q();return}try{let X={entry:r,process:n.createProcess(r),visit:P,deliveryTicket:N};l=X,te(X)}catch(X){c.release(N),T("entry_unavailable",r.id),Z(n.host?.onError,X)}},()=>{F.delete(C)})}function Q(){B||t||(B=!0,queueMicrotask(()=>{if(B=!1,g.recheck(),!(t||i||document.visibilityState==="hidden"||!$()||l||o||S||g.active||R===P)){for(let r of b?.entries??[])if(r.event==="screen_enter"&&!F.has(`${P}:${r.id}`)&&M(r)){Y(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||l||o||S||R===P)return;let C=be(document,()=>{});for(let H of b?.entries??[]){let W=H.target.button;if(H.event!=="button_click"||!W||!M(H))continue;let V=r.target.closest(W.selector);if(!(!V||V.tagName.toLowerCase()!==W.tag||C(W.selector)!==1||V.matches(":disabled")||V.closest('[inert],[hidden],[aria-hidden="true"]'))){Y(H);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,P++,g.cancel(),F.clear(),Q())};async function me(){if(t)return;if(s)return s;let r=y,C=new AbortController;m=C;let H,W=new Promise((ye,ue)=>{H=ue}),V=()=>H(new G("TIMEOUT","Funnel entry read cancelled"));C.signal.addEventListener("abort",V,{once:!0});let N=setTimeout(()=>C.abort(),n.timeoutMs??5e3),X=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await f(`${d}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:C.signal});if(!ce.ok)throw new G("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},x=await Promise.race([ue(),W]),se=Date.parse(x.validatedAt),oe=Date.parse(x.validUntil);if(x.scope.projectId!==n.scope.projectId||x.scope.environment!==n.scope.environment||x.scope.environmentId!==n.environmentId||x.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new G("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==y||(b=x,w=oe,h=performance.now()+Math.min(oe-Date.now(),6e4),g.recheck(),Q())})();s=X;try{await X}finally{clearTimeout(N),C.signal.removeEventListener("abort",V),s===X&&(s=void 0)}}async function pe(){if(!(!u||t))try{await me()}catch{t||T("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>u&&!t?15e3:void 0});return{async start(){u||t||(u=!0,z=location.origin+location.pathname,E=Ee(le),_=new MutationObserver(Q),_.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Q),await ae.refresh())},refresh:me,async retry(){l&&!t&&await te(l)},async syncIdentity(){g.cancel();let r=o??l??S;if(!r){i=!1,Q();return}try{let C=await r.process.syncIdentity();return i=!1,S===r&&(l={...r,visit:P},S=void 0,await te(l)),C}catch(C){throw r.process.view||(S={...r,visit:P},l=void 0,ee()),C}},async detach(){i=!0,y++,g.cancel(),m?.abort();let r=o??l??S;r&&(S={...r,visit:P}),l=void 0,ee(),r&&await r.process.detach()},destroy(){t=!0,y++,g.cancel(),ae.destroy(),m?.abort(),_?.disconnect(),E?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Q);let r=o??l??S;c.release(r?.deliveryTicket),l=void 0,S=void 0,ee(),r?.process.destroy(),b=void 0}}}async function Dn(n,d){return(await import("./paywall-JTKB4MMC.js")).showPaywall(n,d)}async function dt(){return await Promise.all([import("./paywall-JTKB4MMC.js"),import("./screen-renderer-HJOKBOZH.js")]),Dn}async function lt(...n){return n[1]=ze(n[1]),(await import("./paywall-session-PCWN2M24.js")).createPaywallSession(...n)}async function ut(...n){let d=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-JTKB4MMC.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-3P62SXBA.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-YUBH7ZC7.js").then(b=>b.preparedInternals(d)?.release(),()=>{}),f}}async function ft(...n){return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-JTKB4MMC.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-M2JNOOCE.js"),n[1].prepared)).showFunnelPurchase(...n)}async function mt(...n){return import("./funnel-host-purchase-M2JNOOCE.js").catch(()=>{}),import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),(await import("./funnel-paywall-prerender-YUBH7ZC7.js")).prerenderFunnelPurchase(...n)}async function pt(){await Promise.all([import("./funnel-paywall-prerender-YUBH7ZC7.js"),import("./funnel-host-purchase-M2JNOOCE.js"),import("./paywall-JTKB4MMC.js"),import("./screen-renderer-HJOKBOZH.js"),import("./paywall-content-GJX3FQ6D.js"),import("./check-response-XGOTG3KL.js"),import("./operation-contracts-YJM6772C.js")])}async function yt(...n){return(await import("./funnel-host-purchase-entry-OKHAEHOG.js")).createFunnelPurchaseEntry(...n)}async function ht(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictFunnelStart(...n)}async function gt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictedPaywallLoadingDocument(...n)}async function vt(...n){return(await import("./funnel-host-recovery-paywall-XFL6JS74.js")).mountFunnelRecoveryPaywall(...n)}async function It(...n){return(await import("./content-K2T4V3ZD.js")).mountContent(...n)}async function wt(...n){return(await import("./content-K2T4V3ZD.js")).prepareContent(...n)}export{G as LongplayError,I as MerchantBridgeError,yn as createBrowserFunnelCommandStorage,En as createBrowserFunnelPurchaseStorage,vn as createConfigurationSync,mn as createFeatureClient,wn as createFunnelClient,Rn as createFunnelPageExperiments,Sn as createFunnelProcess,bn as createFunnelPurchaseClient,yt as createFunnelPurchaseEntry,Ae as createFunnelRunController,Cn as createIamFunnelEntries,An as createIamFunnelProcessEntries,Pn as createLocalFunnelClient,pn as createLongplay,Tn as createMerchantBridge,lt as createPaywallSession,In as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,hn as getPaywallRecovery,un as isPaywallOperationComplete,fn as isPaywallOperationPending,ln as isPaywallUpdateOperation,dn as isPaywallUpdateQuote,It as mountContent,vt as mountFunnelRecoveryPaywall,ht as predictFunnelStart,gt as predictedPaywallLoadingDocument,pt as preloadFunnelPurchase,dt as preloadPaywall,wt as prepareContent,gn as preparePaywallFallback,mt as prerenderFunnelPurchase,ft as showFunnelPurchase,ut as showFunnelRun,Dn as showPaywall};
|
|
1
|
+
import{a as En,c as bn}from"./chunk-XWVK4SJA.js";import{a as Rn}from"./chunk-7ZAM4YRK.js";import{a as We}from"./chunk-AEQUKR4O.js";import{a as Ie}from"./chunk-W32FI2A2.js";import{a as pn,c as wn,d as Sn}from"./chunk-WLO2GDRF.js";import"./chunk-XLGNBPGF.js";import{a as In}from"./chunk-7DQV2EUW.js";import"./chunk-EQUVI5QU.js";import{h as mn,i as vn,k as Pn}from"./chunk-PBHOJKKG.js";import{E as Ae,d as Xe,f as Qe,g as ge,h as ve,i as Ye,w as yn}from"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import{a as ze}from"./chunk-S2S4ROGY.js";import{d as hn,f as gn}from"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import{K as Ke}from"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import{B as dn,C as ln,D as un,E as fn,c as an,d as sn,e as cn}from"./chunk-3532HSBP.js";import{A as Le,B as Be,D as He,F as qe,G as Ue,I as Ve,J as je,K as Ge,L as Je,M as Te,N as $e,z as _e}from"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import{b as Ce}from"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as $}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import{a as be,c as de}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as we,d as Ee}from"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as q}from"./chunk-W22ESUYY.js";import{a as ne}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var E=class extends Error{constructor(d,P=0,b=!1,I="fix_request"){super(d);this.code=d;this.status=P;this.retryable=b;this.recovery=I;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function _n(n,c){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");let d=n.body?.getReader();if(!d)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");let P=()=>{d.cancel().catch(()=>{})};c.addEventListener("abort",P,{once:!0});let b=0,I="",t=new TextDecoder("utf-8",{fatal:!0});try{for(c.throwIfAborted();;){let i=await d.read();if(c.throwIfAborted(),i.done)break;if(b+=i.value.byteLength,b>262144)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");I+=t.decode(i.value,{stream:!0})}return I+=t.decode(),JSON.parse(I)}catch(i){throw c.throwIfAborted(),i instanceof E?i:new E("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{c.removeEventListener("abort",P),await d.cancel().catch(()=>{}),d.releaseLock()}}var Tn=["customer_commerce","purchases","operation_status","subscription_changes"];function Cn(n){let c=qe.parse(n.origin),d=Ue.parse(n.manifest),P={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let u of["projectId","environmentId","environment"])if(d[u]!==n.scope[u])throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");let b=n.customerId===void 0?null:q.uuid().parse(n.customerId),I=0,t=null,i=null,l=new AbortController,g=n.fetch??globalThis.fetch,A=null,C=()=>A??=import("./merchant-bridge-contracts-OIYML3DE.js").catch(u=>{throw A=null,u});d.capabilities.some(u=>Tn.includes(u))&&C().catch(()=>{});async function O(u,f,S,y,m){if(!d.capabilities.includes(u))throw new E("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let o=He[u];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(o.authority))throw new E("MERCHANT_BRIDGE_FORBIDDEN",403);let v=I,p=AbortSignal.any([l.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...y?[y]:[]]);p.throwIfAborted();let D=new Headers(await n.headers?.());if(p.throwIfAborted(),v!==I)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(D.get("authorization")??"")||D.has("X-Indiana-Bridge-Signature")||D.has("X-Indiana-Bridge-Key-Id"))throw new E("MERCHANT_BRIDGE_FORBIDDEN",403);D.set(Be,String(_e)),D.set("Accept","application/json");let j=crypto.randomUUID();D.set("X-Request-Id",j),D.set("Content-Type","application/json");let s=await g(c+Le,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:D,signal:p,body:JSON.stringify({bridgeVersion:_e,requestId:j,command:o.command,scope:P,data:m??(S===void 0?{}:{operationId:S})})}),G=await _n(s,p);if(p.throwIfAborted(),v!==I)throw new DOMException("Merchant identity changed","AbortError");if(!s.ok){let L=$e.safeParse(G);throw!L.success||L.data.scope.projectId!==n.scope.projectId||L.data.scope.environment!==n.scope.environment||L.data.scope.environmentId!==n.scope.environmentId||L.data.requestId!==j||L.data.command!==o.command?new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status):new E(L.data.error.code,s.status,L.data.error.retryable,L.data.error.recovery)}let F=Ve(q.unknown()).safeParse(G);if(!F.success||F.data.scope.projectId!==n.scope.projectId||F.data.scope.environment!==n.scope.environment||F.data.scope.environmentId!==n.scope.environmentId||F.data.requestId!==j||F.data.command!==o.command)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status);let X=f.safeParse(F.data.data);if(!X.success)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE",s.status);return X.data}function z(){if(!b)throw new E("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return b}async function V(u,f,S,y){let m=z();if(y!==void 0&&Te.parse({operationId:y,customerId:m}),!d.capabilities.includes(u))throw new E("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let o=I,v=AbortSignal.any([l.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...f?[f]:[]]);v.throwIfAborted();let p,D=new Promise((j,s)=>{p=()=>s(v.reason),v.addEventListener("abort",p,{once:!0})});try{let s=S(async()=>{let F=await C();if(v.throwIfAborted(),o!==I||b!==m)throw new DOMException("Merchant identity changed","AbortError");return F},v),G=await Promise.race([s,D]);return v.throwIfAborted(),G}finally{v.removeEventListener("abort",p)}}async function K(u,f,S,y){let m=z(),o=Te.parse({operationId:S,customerId:m}),v=await O(u,f,o.operationId,y,o);if(v.customerId!==m||v.operationId!==o.operationId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return v}return{async readPresentation(u){let f=await O("presentation",Ge,void 0,u);if(i!==null&&i!==f.nativeUserId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(f.presentation&&b!==null&&f.presentation.customerId!==b)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return i=f.nativeUserId,t=f.presentation,f},async createSession(u){let f=await O("session",je,void 0,u);if(i!==null&&i!==f.nativeUserId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(b!==null&&b!==f.session.customerId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t&&t.customerId!==f.session.customerId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return b=f.session.customerId,i=f.nativeUserId,f.session},async reportPresentation(u,f){let S=z(),y=Je.parse(u);if(!t||t.customerId!==S||t.decisionId!==y.decisionId)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return O("presentation_events",q.strictObject({queued:q.literal(!0)}),void 0,f,y)},async readCustomerCommerce(u){let f=z(),S=await V("customer_commerce",u,async(y,m)=>{let[o,v]=await Promise.all([y(),O("customer_commerce",q.unknown(),void 0,m)]),p=o.merchantBridgeCommerceSchema.safeParse(v);if(!p.success)throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return p.data});if(S.customerId!==f)throw new E("MERCHANT_BRIDGE_SCOPE_MISMATCH");return S},async executePurchase(u,f){let S=await V("purchases",f,async(y,m)=>K("purchases",(await y()).merchantBridgeOperationSchema,u,m),u);if(S.type!=="purchase")throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return S},readOperation:(u,f)=>V("operation_status",f,async(S,y)=>K("operation_status",(await S()).merchantOperationLookupSchema,u,y),u),async executeSubscriptionChange(u,f){let S=await V("subscription_changes",f,async(y,m)=>K("subscription_changes",(await y()).merchantBridgeOperationSchema,u,m),u);if(S.type!=="subscription_change")throw new E("MERCHANT_BRIDGE_INVALID_RESPONSE");return S},reset(){I++,l.abort(),l=new AbortController,b=null,t=null,i=null}}}var en=q.strictObject({command:ve,target:Qe,runId:q.uuid().optional(),expiresAt:q.iso.datetime({offset:!0}).optional(),deliveryLimit:q.number().int().min(1).max(100).optional()}).refine(n=>n.command.release===n.target.release),Ze=q.strictObject({schemaVersion:q.literal(1),entries:q.array(en).max(4e3)});function nn(n){let c=!1,d=()=>{c||n.unavailable(),c=!0};function P(){return n.storage===!1?void 0:n.storage??globalThis.sessionStorage}function b(t){let i=P()?.getItem(t);if(!i)return[];if(i.length>1048576)throw Error("Entry recovery is too large");return Ze.parse(JSON.parse(i)).entries}function I(t,i){let l=P();if(!l)return;if(!i.length)return l.removeItem(t);let g=JSON.stringify(Ze.parse({schemaVersion:1,entries:i}));if(g.length>1048576)throw Error("Entry recovery is too large");l.setItem(t,g)}return{load(){try{let t=n.binding();if(!t||n.storage===!1)return;let i="indiana.funnel.entries.v1."+JSON.stringify(t);return{key:i,entries:b(i)}}catch{d();return}},retain(t,i){if(t)try{let l=en.parse(i);I(t,[...b(t).filter(g=>g.command.funnelId!==l.command.funnelId),l])}catch{d()}},forget(t,i){if(t)try{I(t,b(t).filter(l=>l.command.requestId!==i))}catch{d()}}}}var tn=q.strictObject({version:q.literal(1),runs:q.array(q.uuid()).max(100)}),De=new WeakMap,Fe=new WeakMap;function Se(n){let c=!1;function d(){c||n.unavailable(),c=!0}function P(t){let i=t.storage.getItem(t.key);if(!i)return[];if(i.length>8192)throw Error("Invalid entry delivery record");return tn.parse(JSON.parse(i)).runs}function b(t){let i=De.get(t.storage);i||De.set(t.storage,i=new Map);let l=i.get(t.key);return l||i.set(t.key,l=new Set),l}function I(t){if(!t)return;let i=De.get(t.storage),l=i?.get(t.key);l?.delete(t.requestId),l?.size===0&&i?.delete(t.key)}return{claim(t,i,l,g,A=!1){if(l!==void 0)try{let C=n.binding();if(!C)throw Error("Entry delivery identity is unavailable");let O={storage:n.storage??globalThis.sessionStorage,key:"indiana.funnel.delivery.v1."+JSON.stringify([...C,i,t]),requestId:g},z=P(O);if(Fe.get(O.storage)?.has(O.key))throw Error("Entry delivery storage is unavailable");O.storage.setItem(O.key,JSON.stringify({version:1,runs:z}));let V=b(O);return!A&&!V.has(g)&&z.length+V.size>=l?!1:(V.add(g),O)}catch{return d(),!1}},accept(t,i){if(t)try{let l=P(t);l.includes(i)||t.storage.setItem(t.key,JSON.stringify(tn.parse({version:1,runs:[...l,i].slice(-100)})))}catch{let l=Fe.get(t.storage);l||Fe.set(t.storage,l=new Set),l.add(t.key),d()}finally{I(t)}},release:I}}function Pe(){let n,c,d=()=>{clearTimeout(n),n=void 0;let P=c;c=void 0,P?.cancelled()};return{get active(){return c!==void 0},start(P,b,I,t){if(c)return;if(P===0){b()?I():t();return}let i={valid:b,cancelled:t};c=i,n=setTimeout(()=>{c===i&&(c=void 0,n=void 0,b()?I():t())},P*1e3)},recheck(){c&&!c.valid()&&d()},cancel:d}}var Re=n=>["running","waiting"].includes(n.status)&&!n.pendingRequest&&(n.stopped||!n.screen&&!n.paywall&&n.instruction?.type==="wait"&&n.instruction.kind!=="operation");function An(n){let c=we(n.baseUrl),d=n.scope,P=Ce(n),b=n.fetch??globalThis.fetch.bind(globalThis),I,t=!1,i=!1,l=0,g=0,A="",C=0,O=0,z=0,V=!1,K,u=!0,f,S,y,m,o,v=-1,p,D=e=>{p===e&&(F.release(e.deliveryTicket),p=void 0,N())},j=new Set,s=(e,a)=>ne(n.onStatus,e,a),G=Pe(),F=Se({storage:n.deliveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[c,d.projectId,d.environment,n.environmentId,"customer",e]:void 0},unavailable:()=>s("delivery_unavailable")}),X=new Set,L=nn({storage:n.recoveryStorage,binding:()=>{let e=n.session.snapshot()?.customerId;return e?[c,d.projectId,d.environment,n.environmentId,n.appManifestRelease,e]:void 0},unavailable:()=>s("recovery_unavailable")}),ee=e=>L.forget(e.storageKey,e.command.requestId);function Z(e,a){a&&(e.runId=a.id,e.expiresAt=a.runExpiresAt),L.retain(e.storageKey,{command:e.command,target:e.target,...e.runId&&{runId:e.runId},...e.expiresAt&&{expiresAt:e.expiresAt},...e.deliveryLimit!==void 0&&{deliveryLimit:e.deliveryLimit}})}function re(){let e=o;o=void 0,e?.host.destroy(),e?.slot.remove(),e?.client.reset(),N()}let le=()=>G.active||p!==void 0||o!==void 0&&!o.background;function me(e,a){if(o?.client!==e)return;Z(o.recovery,a);let h=Re(a);o.slot.hidden=h,h!==o.background&&(o.background=h,h?s("run_background",o.entryId):v=g,N())}function pe(e,a,h){let w=e.client.view;if(!a||e.background||!w?.screen||w.paywall||w.pendingRequest||w.stopped||w.status!=="waiting")return;let W=Ke.parse({operation:"close",requestId:crypto.randomUUID(),nodeId:w.nodeId,visit:w.visit,revision:w.revision,customerToken:a}),J=Ce({...n,session:void 0});J.requestWithCredential("funnels",W,e.runToken,{keepalive:h}).then(()=>ee(e.recovery)).catch(()=>{}).finally(()=>J.dispose())}let ae=()=>{o&&pe(o,n.session.peek(),!0)},r=()=>Date.now()<O&&performance.now()<z;function R(e){if(e.target.release!==n.appManifestRelease||!r())return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return s("incompatible",e.id),!1}}function B(e){if(t||e.epoch!==C||e.visit!==g||document.visibilityState==="hidden")return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function Q(e){if(le()){s("in_progress",e.id);return}let a=C,h=g;G.start(e.delivery?.delaySeconds??0,()=>!t&&a===C&&h===g&&document.visibilityState!=="hidden"&&R(e)&&I?.entries.some(w=>w.id===e.id&&w.funnelId===e.funnelId&&w.versionId===e.versionId&&w.event===e.event&&JSON.stringify(w.target)===JSON.stringify(e.target)&&JSON.stringify(w.delivery)===JSON.stringify(e.delivery))===!0,()=>{U(e)},()=>{j.delete(`${e.funnelId}:${e.id}`)})}async function U(e){if(le()){s("in_progress",e.id);return}if(!n.session.peek()){s("identity_required",e.id);return}let a=L.load(),h=a?.entries.find(_=>_.command.funnelId===e.funnelId&&(!_.expiresAt||Date.parse(_.expiresAt)>Date.now()));if(h){if(!Y(h)){s("recovery_pending",e.id);return}let _={...h,storageKey:a.key,epoch:C,visit:g};X.add(_.command.requestId),p=_,await M(_);return}let w=crypto.randomUUID(),W=F.claim(e.id,e.funnelId,e.delivery?.maxPerSession,w);if(W===!1){s("frequency",e.id),N();return}let J={freshStart:!0,deliveryLimit:e.delivery?.maxPerSession,deliveryTicket:W,command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:w,locale:document.documentElement.lang||"en"}),epoch:C,visit:g,target:e.target,storageKey:a?.key};X.add(J.command.requestId),p=J,await M(J)}async function M(e){if(e.dispatching)return;e.dispatching=!0;let a=e.freshStart===!0;e.freshStart=!1;let h,w=!1,W=!1;async function J(_){if(e.epoch!==C)return;let T=_.view;if(!(e.storageKey&&T&&(Re(T)||T.paywall||T.pendingRequest))&&T&&["running","waiting"].includes(T.status))try{await _.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:T.nodeId,visit:T.visit,revision:T.revision}),ee(e)}catch(x){if(!(x instanceof $&&x.code==="FORBIDDEN"))throw x}}try{if(!e.deliveryTicket&&e.deliveryLimit!==void 0){let H=F.claim(e.command.entryId,e.command.funnelId,e.deliveryLimit,e.command.requestId,!0);H!==!1&&(e.deliveryTicket=H)}Z(e),s("starting",e.command.entryId);let _=await P.request("funnels",e.command),T=Ye.safeParse(_);if(T.success){if(T.data.scope.projectId!==d.projectId||T.data.scope.environment!==d.environment)throw new $("SCOPE_MISMATCH","Entry scope changed");e.epoch===C&&s(T.data.reason,e.command.entryId),ee(e),D(e);return}let x=Xe.parse(_);if(!x.runToken||x.scope.projectId!==d.projectId||x.scope.environment!==d.environment||x.run.source.type!=="funnel"||x.run.source.id!==e.command.funnelId||x.run.source.versionId!==e.command.versionId||e.runId!==void 0&&x.run.id!==e.runId)throw new $("INVALID_RESPONSE","Invalid entry Run");if(F.accept(e.deliveryTicket,x.run.id),e.epoch!==C){D(e),s("identity_changed",e.command.entryId);return}Z(e,x.run);let k=Ae({...n,runToken:x.runToken,funnelId:e.command.funnelId,initialResponse:a?_:void 0});h=k,W=!0,await k.get(),W=!1;let te=k.view;if(!te||te.id!==x.run.id||te.source.type!=="funnel"||te.source.id!==e.command.funnelId||te.source.versionId!==e.command.versionId)throw new $("INVALID_RESPONSE","Entry Run version changed");if(!["running","waiting"].includes(te.status)){ee(e),D(e),s("run_ended",e.command.entryId);return}let{showFunnelRun:fe}=await import("./funnel-runtime-host-CFDI4AWM.js");if(!B(e)){await J(k),s("left_screen",e.command.entryId),D(e);return}let Ne=!1,xe=!1;if(o&&!o.background){await J(k),s("in_progress",e.command.entryId),D(e);return}o&&re();let ie=document.createElement("div");ie.hidden=Re(te),n.container.append(ie);let ke=await fe(ie,{...n.host,client:k,appManifestRelease:n.appManifestRelease,onState(H){me(k,H),ne(n.host?.onState,H)},onDismiss(H){Ne=!0,ie.remove(),H&&!["running","waiting"].includes(H.status)&&ee(e),o?.client===k&&(o=void 0,k.reset(),N(),H&&H.status!=="completed"&&s("run_ended",e.command.entryId)),ne(n.host?.onDismiss,H)},onComplete(H){xe=!0,ee(e),o?.client===k&&re(),ne(n.host?.onComplete,H)},onError(H){ne(n.host?.onError,H),o?.client===k&&H instanceof $&&H.code==="FORBIDDEN"&&(ee(e),re(),s("run_ended",e.command.entryId))}}).catch(H=>{throw ie.remove(),H});if(!B(e)||Ne||xe){ke.destroy(),ie.remove(),B(e)||await J(k),D(e);return}let he=Re(k.view??te);ie.hidden=he,o={host:ke,client:k,slot:ie,entryId:e.command.entryId,background:he,runToken:x.runToken,owner:n.session.peek(),recovery:e},he||(v=e.visit),w=!0,D(e),s("started",e.command.entryId),he&&s("run_background",e.command.entryId)}catch(_){_ instanceof $&&(!h||W&&_.code==="FORBIDDEN")&&_.status!==void 0&&_.status>=400&&_.status<500&&!_.retryable&&(ee(e),D(e)),e.epoch===C&&!t&&(s("start_failed",e.command.entryId),ne(n.host?.onError,_))}finally{w||h?.reset(),e.dispatching=!1}}function Y(e){if(e.command.release!==n.appManifestRelease||e.target.release!==n.appManifestRelease)return!1;try{return de(e.target.render,document,location.pathname,()=>{})}catch{return!1}}function ye(){if(le())return!1;let e=L.load();for(let a of e?.entries??[]){if(a.expiresAt&&Date.parse(a.expiresAt)<=Date.now()){L.forget(e.key,a.command.requestId);continue}if(a.command.requestId===o?.recovery.command.requestId||X.has(a.command.requestId)||!Y(a))continue;X.add(a.command.requestId);let h={...a,storageKey:e.key,epoch:C,visit:g};return p=h,M(h),!0}return!1}function ue(){if(V=!1,G.recheck(),t||!i||document.visibilityState==="hidden")return;se();let e=o!==void 0&&!o.background;if(e&&(v=g),!ye()){if(!r()){u=!0;return}u=!1;for(let a of I?.entries??[]){let h=`${a.funnelId}:${a.id}`;if(!(a.event!=="screen_enter"||j.has(h)||!R(a))){if(!n.session.peek()){s("identity_required",a.id);continue}if(v===g){j.add(h),e&&s("in_progress",a.id);continue}if(p||G.active){s("in_progress",a.id);return}j.add(h),Q(a);break}}}}let N=()=>{!V&&!t&&(V=!0,queueMicrotask(ue))};function se(){let e=location.origin+location.pathname;return e===A?!1:(A=e,g++,G.cancel(),u=!0,j.clear(),X.clear(),!0)}function oe(){se()&&N()}function ce(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let a=e.target;if(!(a instanceof Element)||a.closest("[data-indiana-funnel]"))return;let h=a.closest("button,a,input");if(!(!h||h.matches(":disabled,[aria-disabled='true']")||h.closest("[hidden],[inert],[aria-hidden='true']")))for(let w of I?.entries??[]){let W=w.target.button;if(!(w.event!=="button_click"||!W||!R(w))){try{let J=be(document);if(!h.matches(W.selector)||J(W.selector,h)!==1)continue}catch{s("incompatible",w.id);continue}Q(w);break}}}async function Oe(){if(t)return;if(K)return K;let e=++l,a=new AbortController;f=a;let h,w=new Promise((_,T)=>{h=()=>T(new $("TIMEOUT","Funnel entry configuration read cancelled or timed out")),a.signal.addEventListener("abort",h,{once:!0})}),W=setTimeout(()=>a.abort(),n.timeoutMs??5e3),J=(async()=>{let _=async()=>{let fe=await b(`${c}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:a.signal});if(!fe.ok)throw new $("SERVICE_UNAVAILABLE","Funnel entries unavailable",fe.status);return ge.parse(await fe.json())},T=await Promise.race([_(),w]),x=Date.parse(T.validatedAt),k=Date.parse(T.validUntil);if(T.scope.projectId!==d.projectId||T.scope.environment!==d.environment||T.scope.environmentId!==n.environmentId||T.release!==n.appManifestRelease||k<=Date.now()||x>Date.now()+5e3||k-x>6e4||k<=x)throw new $("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(t||e!==l)return;let te=I===void 0;I=T,O=k,z=performance.now()+Math.min(k-Date.now(),6e4),G.recheck(),(te||u)&&N()})();K=J;try{await J}finally{clearTimeout(W),a.signal.removeEventListener("abort",h),K===J&&(K=void 0)}}async function on(){if(!(!i||t)){try{await Oe()}catch{t||s("configuration_unavailable")}N()}}let Me=Ie({document,run:on,delay:()=>i&&!t?15e3:void 0});return{async start(){i||t||(i=!0,A=location.origin+location.pathname,S=Ee(oe),y=n.session.subscribeIdentity(()=>{C++,G.cancel(),F.release(p?.deliveryTicket),u=!0,p=void 0,j.clear(),v=-1,X.clear(),o&&pe(o,o.owner,!1),re(),N()}),m=new MutationObserver(N),m.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",ce,!0),document.addEventListener("visibilitychange",N),addEventListener("pagehide",ae),await Me.refresh())},refresh:Oe,async retry(){p&&!t&&p.epoch===C&&await M(p)},destroy(){t=!0,l++,G.cancel(),F.release(p?.deliveryTicket),Me.destroy(),f?.abort(),m?.disconnect(),S?.(),y?.(),document.removeEventListener("click",ce,!0),document.removeEventListener("visibilitychange",N),removeEventListener("pagehide",ae),ae(),re(),P.dispose(),I=void 0}}}function Dn(n){let c=we(n.baseUrl),d=n.fetch??globalThis.fetch.bind(globalThis),P,b=0,I=0,t=!1,i=!1,l=!1,g=0,A=0,C=-1,O=!1,z="",V,K,u,f,S=new Set,y,m,o,v=(r,R)=>ne(n.onStatus,r,R),p=Pe(),D=()=>{try{return n.deliveryIdentity?.()}catch{return}},j=()=>JSON.stringify(D()),s=Se({storage:n.deliveryStorage,binding:()=>{let r=D();return r?.id?[c,n.scope.projectId,n.scope.environment,n.environmentId,r.type,r.id]:void 0},unavailable:()=>v("delivery_unavailable")}),G=()=>Date.now()<b&&performance.now()<I;function F(r){try{return G()&&r.target.release===n.appManifestRelease&&de(r.target.render,document,location.pathname,()=>{})}catch{return v("incompatible",r.id),!1}}function X(){let r=o;o=void 0,r?.host.destroy(),r?.slot.remove()}async function L(r){if(r.dispatching)return;r.dispatching=!0;let R=g;try{let B=await r.process.open({operation:"entry_start",funnelId:r.entry.funnelId,versionId:r.entry.versionId,entryId:r.entry.id,release:n.appManifestRelease,locale:n.locale??"en"});s.accept(r.deliveryTicket,B.run.id);let{showFunnelRun:Q}=await import("./funnel-runtime-host-CFDI4AWM.js");if(t||R!==g||m!==r)return;let U=document.createElement("div");n.container.append(U),C=A;let M=await Q(U,{...n.host,client:B.controller,appManifestRelease:n.appManifestRelease,onDismiss(Y){o?.process===r.process&&(o=void 0,U.remove()),ne(n.host?.onDismiss,Y)}});if(t||R!==g||m!==r){M.destroy(),U.remove();return}o={entry:r.entry,process:r.process,host:M,slot:U,deliveryTicket:r.deliveryTicket},m=void 0,v("run_presented",r.entry.id)}catch(B){if(t||R!==g||m!==r)return;B instanceof $&&"result"in B?(s.release(r.deliveryTicket),m=void 0,r.process.destroy(),v("suppressed",r.entry.id),Z()):v("entry_unavailable",r.entry.id)}finally{r.dispatching=!1}}function ee(r){if(t||i||m||o||y||p.active||C===A||!F(r))return;let R=`${A}:${r.id}`;if(S.has(R))return;S.add(R);let B=A,Q=g,U=j();p.start(r.delivery?.delaySeconds??0,()=>!t&&g===Q&&A===B&&j()===U&&document.visibilityState!=="hidden"&&F(r)&&P?.entries.some(M=>M.id===r.id&&M.funnelId===r.funnelId&&M.versionId===r.versionId&&M.event===r.event&&JSON.stringify(M.target)===JSON.stringify(r.target)&&JSON.stringify(M.delivery)===JSON.stringify(r.delivery))===!0,()=>{let M=s.claim(r.id,r.funnelId,r.delivery?.maxPerSession,crypto.randomUUID());if(M===!1){v("frequency",r.id),Z();return}try{let Y={entry:r,process:n.createProcess(r),visit:A,deliveryTicket:M};m=Y,L(Y)}catch(Y){s.release(M),v("entry_unavailable",r.id),ne(n.host?.onError,Y)}},()=>{S.delete(R)})}function Z(){O||t||(O=!0,queueMicrotask(()=>{if(O=!1,p.recheck(),!(t||i||document.visibilityState==="hidden"||!G()||m||o||y||p.active||C===A)){for(let r of P?.entries??[])if(r.event==="screen_enter"&&!S.has(`${A}:${r.id}`)&&F(r)){ee(r);break}}}))}function re(r){if(!r.isTrusted||r.defaultPrevented||!(r.target instanceof Element)||m||o||y||C===A)return;let R=be(document,()=>{});for(let B of P?.entries??[]){let Q=B.target.button;if(B.event!=="button_click"||!Q||!F(B))continue;let U=r.target.closest(Q.selector);if(!(!U||U.tagName.toLowerCase()!==Q.tag||R(Q.selector)!==1||U.matches(":disabled")||U.closest('[inert],[hidden],[aria-hidden="true"]'))){ee(B);break}}}let le=()=>{let r=location.origin+location.pathname;r!==z&&(z=r,A++,p.cancel(),S.clear(),Z())};async function me(){if(t)return;if(K)return K;let r=g,R=new AbortController;V=R;let B,Q=new Promise((ye,ue)=>{B=ue}),U=()=>B(new $("TIMEOUT","Funnel entry read cancelled"));R.signal.addEventListener("abort",U,{once:!0});let M=setTimeout(()=>R.abort(),n.timeoutMs??5e3),Y=(async()=>{let ye=encodeURIComponent(JSON.stringify(["funnel-process/1"])),ue=async()=>{let ce=await d(`${c}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}&executionContracts=${ye}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:R.signal});if(!ce.ok)throw new $("SERVICE_UNAVAILABLE","Funnel entries unavailable",ce.status);return ge.parse(await ce.json())},N=await Promise.race([ue(),Q]),se=Date.parse(N.validatedAt),oe=Date.parse(N.validUntil);if(N.scope.projectId!==n.scope.projectId||N.scope.environment!==n.scope.environment||N.scope.environmentId!==n.environmentId||N.release!==n.appManifestRelease||oe<=Date.now()||se>Date.now()+5e3||oe<=se||oe-se>6e4)throw new $("INVALID_RESPONSE","Entry scope or deadline changed");t||r!==g||(P=N,b=oe,I=performance.now()+Math.min(oe-Date.now(),6e4),p.recheck(),Z())})();K=Y;try{await Y}finally{clearTimeout(M),R.signal.removeEventListener("abort",U),K===Y&&(K=void 0)}}async function pe(){if(!(!l||t))try{await me()}catch{t||v("configuration_unavailable")}}let ae=Ie({document,run:pe,delay:()=>l&&!t?15e3:void 0});return{async start(){l||t||(l=!0,z=location.origin+location.pathname,u=Ee(le),f=new MutationObserver(Z),f.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["hidden","inert","aria-hidden","data-indiana-id","id","style","data-testid","data-test","data-qa"]}),document.addEventListener("click",re,!0),document.addEventListener("visibilitychange",Z),await ae.refresh())},refresh:me,async retry(){m&&!t&&await L(m)},async syncIdentity(){p.cancel();let r=o??m??y;if(!r){i=!1,Z();return}try{let R=await r.process.syncIdentity();return i=!1,y===r&&(m={...r,visit:A},y=void 0,await L(m)),R}catch(R){throw r.process.view||(y={...r,visit:A},m=void 0,X()),R}},async detach(){i=!0,g++,p.cancel(),V?.abort();let r=o??m??y;r&&(y={...r,visit:A}),m=void 0,X(),r&&await r.process.detach()},destroy(){t=!0,g++,p.cancel(),ae.destroy(),V?.abort(),f?.disconnect(),u?.(),document.removeEventListener("click",re,!0),document.removeEventListener("visibilitychange",Z);let r=o??m??y;s.release(r?.deliveryTicket),m=void 0,y=void 0,X(),r?.process.destroy(),P=void 0}}}async function Fn(n,c){return(await import("./paywall-2Z3FUN2M.js")).showPaywall(n,c)}async function lt(){return await Promise.all([import("./paywall-2Z3FUN2M.js"),import("./screen-renderer-HJOKBOZH.js")]),Fn}async function ut(...n){return n[1]=ze(n[1]),(await import("./paywall-session-RNEEPYPG.js")).createPaywallSession(...n)}async function ft(...n){let c=n[1].signal?.aborted?void 0:We(n[1].client);try{return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-2Z3FUN2M.js").catch(()=>{}),await(await rn(()=>import("./funnel-runtime-host-CFDI4AWM.js"),n[1].prepared)).showFunnelRun(...n)}finally{c?.()}}async function rn(n,c){try{return await n()}catch(d){throw c&&c.state!=="adopted"&&await import("./funnel-paywall-prerender-QHEGZSPT.js").then(P=>P.preparedInternals(c)?.release(),()=>{}),d}}async function mt(...n){return import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),import("./paywall-2Z3FUN2M.js").catch(()=>{}),(await rn(()=>import("./funnel-host-purchase-7IYZRPYA.js"),n[1].prepared)).showFunnelPurchase(...n)}async function pt(...n){return import("./funnel-host-purchase-7IYZRPYA.js").catch(()=>{}),import("./screen-renderer-HJOKBOZH.js").catch(()=>{}),(await import("./funnel-paywall-prerender-QHEGZSPT.js")).prerenderFunnelPurchase(...n)}async function yt(){await Promise.all([import("./funnel-paywall-prerender-QHEGZSPT.js"),import("./funnel-host-purchase-7IYZRPYA.js"),import("./paywall-2Z3FUN2M.js"),import("./screen-renderer-HJOKBOZH.js"),import("./paywall-content-JXWPOE3Y.js"),import("./check-response-XGOTG3KL.js"),import("./operation-contracts-YJM6772C.js"),import("./merchant-bridge-contracts-OIYML3DE.js")])}async function ht(...n){return(await import("./funnel-host-purchase-entry-FFZUEX4Q.js")).createFunnelPurchaseEntry(...n)}async function gt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictFunnelStart(...n)}async function vt(...n){return(await import("./funnel-route-prediction-Q4HMRAVQ.js")).predictedPaywallLoadingDocument(...n)}async function It(...n){return(await import("./funnel-host-recovery-paywall-DGCR4IBQ.js")).mountFunnelRecoveryPaywall(...n)}async function wt(...n){return(await import("./content-IDQO7TKS.js")).mountContent(...n)}async function Et(...n){return(await import("./content-IDQO7TKS.js")).prepareContent(...n)}export{$ as LongplayError,E as MerchantBridgeError,yn as createBrowserFunnelCommandStorage,En as createBrowserFunnelPurchaseStorage,vn as createConfigurationSync,mn as createFeatureClient,wn as createFunnelClient,Rn as createFunnelPageExperiments,Sn as createFunnelProcess,bn as createFunnelPurchaseClient,ht as createFunnelPurchaseEntry,Ae as createFunnelRunController,An as createIamFunnelEntries,Dn as createIamFunnelProcessEntries,Pn as createLocalFunnelClient,pn as createLongplay,Cn as createMerchantBridge,ut as createPaywallSession,In as evaluateFunnelNode,sn as formatCouponDiscount,an as formatCouponMoney,cn as formatCouponTerms,hn as getPaywallRecovery,un as isPaywallOperationComplete,fn as isPaywallOperationPending,ln as isPaywallUpdateOperation,dn as isPaywallUpdateQuote,wt as mountContent,It as mountFunnelRecoveryPaywall,gt as predictFunnelStart,vt as predictedPaywallLoadingDocument,yt as preloadFunnelPurchase,lt as preloadPaywall,Et as prepareContent,gn as preparePaywallFallback,pt as prerenderFunnelPurchase,mt as showFunnelPurchase,ft as showFunnelRun,Fn as showPaywall};
|
package/dist/openrouter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-Y6KA56V2.js";import"./chunk-SX7U2ONB.js";import"./chunk-
|
|
1
|
+
import"./chunk-Y6KA56V2.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import{a as i}from"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as A}from"./chunk-W22ESUYY.js";import"./chunk-WOT6VMZA.js";var c=A.number().int().min(0).max(1e9);function R(e,o){let a=c.parse(e.promptTokens),p=c.parse(e.completionTokens),s=c.parse(e.promptTokensDetails?.cachedTokens??0),t=c.parse(e.promptTokensDetails?.cacheWriteTokens??0),r=c.parse(e.promptTokensDetails?.audioTokens??0),l=c.parse(e.completionTokensDetails?.audioTokens??0),n=c.parse(e.completionTokensDetails?.reasoningTokens??0);if(c.parse(e.totalTokens)!==a+p||s+t+r>a||n+l>p||(e.promptTokensDetails?.videoTokens??0)>0)throw new i("AI_USAGE_UNAVAILABLE","Token pools must conserve usage; video needs an explicit token mapper");return{input:a-s-t-r,output:p-l-(o==="separate"?n:0),cache_read:s,cache_write:t,input_audio:r,output_audio:l,reasoning:o==="separate"?n:0}}function I(e){if(!Number.isFinite(e)||e<0)throw new i("AI_USAGE_UNAVAILABLE","Provider cost must be a nonnegative USD amount");let o=String(e),a=o.includes("e")?e.toFixed(18).replace(/0+$/,"").replace(/\.$/,""):o;if(!/^(0|[1-9]\d{0,11})(\.\d{1,18})?$/.test(a)||Number(a)!==e)throw new i("AI_USAGE_UNAVAILABLE","Provider cost exceeds the supported precision");return a}async function f(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning)||!e.modelId||!e.generationId)throw new i("INVALID_REQUEST","Actual model, generation ID and reasoning pricing are required");let o={context:e.context,generationId:e.generationId,modelId:`openrouter/${e.modelId}`,usage:e.usage,tokens:null,quote:null,receipt:null,phase:"captured"};await e.persist(o);let a=e.mapTokens?e.mapTokens(e.usage):R(e.usage,e.reasoning),p=e.usage.cost==null?void 0:I(e.usage.cost),s=e.quote??await e.pricing.quoteTokens({modelId:o.modelId,tokens:a});if(s.pricing.modelId!==o.modelId||Object.keys(a).some(l=>a[l]!==s.tokens[l]))throw new i("INVALID_REQUEST","Saved quote must match the provider model and token pools");await e.persist({...o,tokens:a,quote:s,phase:"quoted"});let t=await e.pricing.trackTokens(e.client,{...e.context,quote:s,providerCostUsd:p,generationId:e.generationId});if(!t.receipt.accepted)throw new i("AI_BALANCE_REJECTED","OpenRouter usage was saved but the balance request was rejected");let r={...o,tokens:a,quote:s,receipt:t,phase:"settled"};return await e.persist(r),r}function T(e){if(typeof window<"u")throw new i("SERVER_ONLY","OpenRouter accounting requires your backend");if(!["output","separate"].includes(e.reasoning))throw new i("INVALID_REQUEST","Reasoning pricing is required");let o=e.openRouter.chat;async function a(t){if(!t.usage||!t.modelId||!t.generationId)throw new i("AI_USAGE_UNAVAILABLE","OpenRouter did not return final usage and the actual model");await f({...e,context:t.context,generationId:t.generationId,modelId:t.modelId.slice(11),usage:t.usage})}let p=async(t,r)=>{let n={context:await e.context(),generationId:null,modelId:null,usage:null,tokens:null,quote:null,receipt:null,phase:"incomplete"},d;try{d=await o.send(t,r)}catch(g){throw await e.persist(n),g}if(!(d instanceof ReadableStream)){if(n={...n,generationId:d.id,modelId:d.model?`openrouter/${d.model}`:null,usage:d.usage??null},!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter omitted final accounting");return await a(n),d}let w=d.getReader(),m=!1;return new ReadableStream({async pull(g){try{let{value:u,done:k}=await w.read();if(k){if(m=!0,!n.usage||!n.modelId)throw await e.persist(n),new i("AI_USAGE_UNAVAILABLE","OpenRouter stream ended without final accounting");await a(n),g.close();return}if(u.error)throw new i("AI_PROVIDER_ERROR",u.error.message);u.usage&&(n={...n,generationId:u.id,modelId:u.model?`openrouter/${u.model}`:null,usage:u.usage}),g.enqueue(u)}catch(u){m||(m=!0,await e.persist(n)),await w.cancel(u),g.error(u)}},async cancel(g){m||(m=!0,await e.persist(n)),await w.cancel(g)}})},s=new Proxy(o,{get(t,r){return r==="send"?p:Reflect.get(t,r,t)}});return new Proxy(e.openRouter,{get(t,r){return r==="chat"?s:Reflect.get(t,r,t)}})}export{T as createOpenRouterUsageClient,f as trackOpenRouterUsage};
|
package/dist/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as o,e as r,f as e,g as f}from"./chunk-
|
|
1
|
+
import{d as o,e as r,f as e,g as f}from"./chunk-JLKODCRG.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{f as createPageExperiments,o as mergeQueryStrings,r as pageAttributes,e as readPayload};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-XAPMQRVJ.js";import"./chunk-CHRNCOXJ.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-VILB5M4X.js";import"./chunk-
|
|
1
|
+
import{a}from"./chunk-XAPMQRVJ.js";import"./chunk-CHRNCOXJ.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as showPaywall};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as a}from"./chunk-
|
|
1
|
+
import{b as a}from"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as readPaywallContent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-33EKLIMB.js";import"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";export{a as createPaywallSession};
|
package/dist/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as S,c as E,d as T}from"./chunk-
|
|
1
|
+
import{b as S,c as E,d as T}from"./chunk-WLO2GDRF.js";import"./chunk-XLGNBPGF.js";import{a as A}from"./chunk-33EKLIMB.js";import{e as P}from"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.js";import{h as b,i as x,k as L}from"./chunk-PBHOJKKG.js";import{E as C}from"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import{a as r}from"./chunk-UGATOG2T.js";import{h as R}from"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";function k(t,d){let n,a=0,m=-1,l,i=!1,y=()=>{if(i)throw new r("CLOSED","Native host was destroyed");if(!t.nativeModule)throw new r("CAPABILITY_UNAVAILABLE","Link IndianaBridge and supply nativeModule");return t.nativeModule},o=()=>new r("IDENTITY_CHANGED","Customer identity changed during the native operation"),h=d.subscribeIdentity(()=>{a++,m=-1;let e=a;n&&t.nativeModule&&n.then(c=>t.nativeModule.reset(c,e)).catch(()=>{})}),I=t.nativeEvents?.(e=>{!n||!t.nativeModule||typeof e?.requestId!="string"||(async()=>{let c=await n;if(e.instanceId!==c)return;if(e.kind==="credential"){let w=a,f=null;try{if(!i&&e.revision===w){let N=await d.access();!i&&a===w&&(f=N)}}finally{await t.nativeModule.provideCredential(c,e.requestId,f)}return}let s=!1,u=a;try{if(i||e.revision!==u||!t.onNativeAction)throw o();await t.onNativeAction(e.action),s=!i&&a===u}finally{await t.nativeModule.acknowledge(c,e.requestId,s)}})().catch(()=>{})});async function p(e,c={}){let s=y();if(d.snapshot()&&!t.nativeEvents)throw new r("CAPABILITY_UNAVAILABLE","Supply nativeEvents to share credential refresh with the native host");let u=a,w=await d.access();if(i||a!==u)throw o();if(!n){let v=s.create(JSON.stringify({baseUrl:t.baseUrl??"https://api.longplayai.com",scope:t.scope,timeout:(t.timeoutMs??15e3)/1e3,credentialEvents:!!t.nativeEvents}));n=v,v.catch(()=>{n===v&&(n=void 0)})}let f=await n;if(i||a!==u)throw o();if(m!==u){if(!l||l.epoch!==u){let O=(async()=>{if(await s.identify(f,JSON.stringify({revision:u,credentials:w})),i||a!==u)throw await s.reset(f,u),o();m=u})();l={epoch:u,task:O}}let v=l;try{await v.task}finally{l===v&&(l=void 0)}}let N=await s.invoke(f,e,JSON.stringify(c));if(i||a!==u)throw o();try{return JSON.parse(N)}catch{throw new r("INVALID_RESPONSE","Native host returned invalid JSON")}}async function g(e,c){let s=await p(e,c);if(!s||typeof s!="object"||Array.isArray(s)||s.status!=="complete"&&s.status!=="dismissed")throw new r("INVALID_RESPONSE","Native presentation returned an invalid result");return s}return{showFunnel(e){return g("showFunnel",{runToken:e})},showPaywall(e){return g("showPaywall",e)},showContent(e){return g("showContent",e)},purchaseSubscription(e,c){return p("purchaseSubscription",{operationId:e,accepted:c})},switchSubscription(e,c){return p("switchSubscription",{operationId:e,accepted:c})},restorePurchases(){return p("restorePurchases")},manageSubscriptions(e){return p("manageSubscriptions",e?{productId:e}:{})},async dismiss(){a++,m=-1,n&&await y().reset(await n,a)},async destroy(){i||(i=!0,a++,h(),I?.(),n&&t.nativeModule&&await t.nativeModule.destroy(await n))}}}var M=P.trackUsage.request.shape.command,U=P.trackUsage.response;function F(t){let d=R.parse(t.scope),n=S({...t,scope:d}),a={...t,scope:d,session:n.session},m=k(t,n.session),l=0,i=!1;n.subscribeIdentity(()=>{l++});let y=()=>{if(i)throw new r("CLOSED","SDK client was destroyed");let o=n.session.peek();if(!o)throw new r("UNAUTHENTICATED","Identify the Customer first");return o};return{...n,native:m,async destroy(){i||(i=!0,l++,n.destroy(),await m.destroy())},funnel(){return E({...a,customerToken:y()})},resumeFunnel(o){return y(),C({...a,runToken:o})},paywall(o){return A(a,{...o,customerToken:y()})},async trackUsage(o){if(y(),!t.usageReporter)throw new r("INVALID_REQUEST","Configure your authenticated backend usageReporter");let h=M.parse(o),I=l,p;try{p=await t.usageReporter(h)}catch(e){throw I!==l?new r("IDENTITY_CHANGED","Customer identity changed during usage reporting"):e}if(I!==l)throw new r("IDENTITY_CHANGED","Customer identity changed during usage reporting");let g=U.parse(p);if(g.scope.projectId!==d.projectId||g.scope.environment!==d.environment)throw new r("INVALID_RESPONSE","Usage response scope differs");return g}}}export{r as LongplayError,x as createConfigurationSync,b as createFeatureClient,T as createFunnelProcess,L as createLocalFunnelClient,F as createLongplayReactNative};
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as pn}from"./chunk-
|
|
1
|
+
import{a as pn}from"./chunk-7DQV2EUW.js";import{a as I}from"./chunk-EQUVI5QU.js";import{a as fn,b as hn,c as gn,d as yn}from"./chunk-Y6KA56V2.js";import{a as xt}from"./chunk-33EKLIMB.js";import{a as Ue,b as Ve,c as qe,d as He,e as m}from"./chunk-CKMSSBJM.js";import"./chunk-FPJ3FE26.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-PBHOJKKG.js";import{B as V,C as N,d as ft,e as ht,k as gt,l as z,m as St,p as Ct,q as Rt,r as bt,s as At,t as Ot,y as pe,z as Tt}from"./chunk-BQFIJCBA.js";import"./chunk-F4AIEI5N.js";import{c as h}from"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-2OBXRQMW.js";import{a as Et,b as _e}from"./chunk-PUDTOCQF.js";import"./chunk-BANN2HQH.js";import"./chunk-7QPCNDIY.js";import{e as at}from"./chunk-BT7IC765.js";import{B as pt,C as de,D as Z,E as lt,J as mt,a as et,e as q,j as Re,k as st,l as ct,q as ut,r as dt,s as be,t as Ae}from"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import{A as W,B as oe,C as tt,D as Se,E as ie,G as se,H as Ce,M as j,O as ce,P as nt,R as Ee,S as rt,T as ot,f as Ge,g as je,j as we,r as ze,s as Ke,u as an,v as sn,y as cn,z as X}from"./chunk-67WFVDTV.js";import{b as Oe}from"./chunk-KX67ZM7H.js";import{e as ve,i as Ze,l as it}from"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-SX7U2ONB.js";import"./chunk-55B6CYG6.js";import{a as Ne,b as Le}from"./chunk-KCUE2VFJ.js";import{o as ue}from"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import{i as un,k as $e,l as Qe,m as Je}from"./chunk-DUS5V65Z.js";import{c as Ie}from"./chunk-BOT6ZDLK.js";import{e as Xe,h as We}from"./chunk-A5WUQLAO.js";import{a as c}from"./chunk-UGATOG2T.js";import{h as Y}from"./chunk-LFR2LWYC.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as u}from"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import{a as Ye}from"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.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-KV5MZ4NI.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-
|
|
1
|
+
import{a as pe,c as fe}from"./chunk-KV5MZ4NI.js";import{b as le}from"./chunk-J6KIN4RH.js";import{a as Ve,b as ce,c as de,d as ue}from"./chunk-SLUA7ABW.js";import{a as J,b as F,c as ge,e as me}from"./chunk-JLKODCRG.js";import{a as re,b as ae,c as se,d as oe}from"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-AO56DGNZ.js";import"./chunk-5MRSFLQA.js";import{b as o}from"./chunk-W22ESUYY.js";import"./chunk-DSPLGTQI.js";import{c as te,e as ie,g as M}from"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.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
package/dist/chunk-MMHL2KFB.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as ce}from"./chunk-H3LJWAAE.js";import{b as W,d as oe}from"./chunk-NKYNGR3L.js";import{b as ue}from"./chunk-KCG7GZXO.js";import{a as se}from"./chunk-XAPMQRVJ.js";import{a as X}from"./chunk-CHRNCOXJ.js";import{b as ie}from"./chunk-VVBXVJI6.js";import{k as H,l as Y}from"./chunk-CO6HDNOC.js";import{a as g}from"./chunk-UGATOG2T.js";import{a as h}from"./chunk-DSPLGTQI.js";var D=new WeakMap,V=new WeakMap,Z=new WeakSet;function be(R,e){let w=e.hostPaywallTarget?void 0:e.prepared,$=()=>{e.prepared&&!Z.has(e.prepared)&&W(e.prepared)?.release()},ee=D.get(e.client);if(ee)return $(),ee;let te=n=>({...n,requestId:n.requestId??crypto.randomUUID()}),N=e.allowNewPurchase!==!1&&e.start instanceof Promise?e.start:void 0,m=e.allowNewPurchase===!1||!e.start||e.start instanceof Promise?void 0:te(e.start);m&&w?.state==="ready"&&w.matches(m)&&w.open();let f=w&&(m&&(w.state==="preparing"||["shown","closed"].includes(w.state)&&w.matches(m))||N&&["preparing","ready"].includes(w.state)||w.state==="shown"&&W(w)?.recovering)?w:void 0;f?Z.add(f):$();let P=f&&W(f);P?.claim();let z=()=>!!P?.recovering&&f?.state==="shown",T=Promise.resolve().then(async()=>{let n=!1,c,b=!1,j,C=0,S,I,U=!1,E=()=>{},re=()=>{},_,B=!1,J=!1,O,ne=!1,a=e.signal?AbortSignal.any([e.signal,e.client.identitySignal]):e.client.identitySignal,v=()=>{D.get(e.client)===T&&D.delete(e.client),a.removeEventListener("abort",F),E(),re(),f&&Z.delete(f),P?.release()};function ae(){if(O)return O;let t=new Promise(o=>O=o);return V.set(e.client,t),t.then(()=>{V.get(e.client)===t&&V.delete(e.client)}),D.get(e.client)===T&&D.delete(e.client),O}let l=Y(R,e,"funnel",()=>k(),X);function F(){k()}function k(t=!1){if(!n){if(n=!0,l.finish("dismissed"),c){c.destroy();return}if(t&&_){let o=ae();ne=!0,_.then(async s=>{s.mode==="run"&&s.status!=="blocked"&&e.client.controller&&e.client.attempt?.requestId===m?.requestId&&await e.client.close()}).catch(()=>{}).finally(()=>{o(),h(e.onDismiss,null)}),v();return}v(),h(e.onDismiss,null)}}let q={destroy:()=>k(),refresh:()=>S??(b?Q():c?.refresh())??Promise.resolve(),get recovery(){return c?.recovery??{type:"recover",operationId:null,requestId:null}},prepareFallback:()=>c?.prepareFallback()??Promise.resolve({type:"recover",operationId:null,requestId:null}),review:(...t)=>c?.review(...t)??Promise.resolve(),exitReview:(...t)=>c?.exitReview(...t)??Promise.resolve(),get unappliedDrafts(){return c?.unappliedDrafts??new Map}};a.addEventListener("abort",F,{once:!0}),P&&(re=P.onClose(()=>{B?n||ae():k(!0)}));try{a.throwIfAborted();let t=e.client.controller?.view?.paywall?.resolution,o=t&&"document"in t?t.document:e.loadingDocument;l.start(!0,m?.locale??e.client.attempt?.locale??o?.screen.strings.defaultLocale,o??null);let s=N?l.wait(N.then(r=>r?te(r):null,()=>null),H):Promise.resolve(m??null);s.catch(()=>{}),f?.state==="shown"?(J=!0,l.present(()=>{})):f&&["preparing","ready"].includes(f.state)&&Promise.all([f.ready,s.catch(()=>null)]).then(([r,i])=>{if(r){if(n||!l.active||!i||!f.matches(i)||!P?.revealable)return P?.release();l.present(()=>{f.open()==="shown"?J=!0:P.release()})}});let d=V.get(e.client);if(d&&await l.wait(d),n)return null;if(a.throwIfAborted(),N){let r=await s;if(n)return null;if(a.throwIfAborted(),!r&&!z())return l.finish("skipped"),v(),null;m=r??void 0}_=m?e.client.start(m):e.client.refresh({reuseRecentRead:!0});let u=await l.wait(_,H);return n?null:(a.throwIfAborted(),await le(u,l))}catch(t){if(ne||O?.(),n)return null;throw l.finish("error",t),v(),h(e.onError,t),t}function K(t=!1){C++;let o=c;c=void 0,E(),E=()=>{};let s=t?o?.retainPurchaseDialog?.():void 0;return o?.destroy(),a.addEventListener("abort",F,{once:!0}),s}function x(t){b=!0;let o=e.client.attempt?.locale??m?.locale,s=o?.startsWith("zh"),d=t?s?"正在查询原订单…":"Checking your purchase…":s?"暂时无法确认原订单,请重试。":"Could not check your original purchase. Try again.",u=t?void 0:()=>{Q()};c?.setPurchaseRecovery?.(d,u)||(c&&K(),l.active||(l=Y(R,e,"funnel",()=>k(),X),l.start(!0,o,e.loadingDocument??null)),l.setPurchaseRecovery(d,u))}function Q(){if(S)return S;if(n||a.aborted)return Promise.resolve();j??=c?.recoveryPaywall,a.addEventListener("abort",F,{once:!0}),x(!0);let t=Promise.resolve().then(async()=>{try{let s=await l.wait(e.client.refresh(),H);!n&&!a.aborted&&await le(s,l)}catch(s){!n&&!a.aborted&&(h(e.onError,s),x(!1))}});S=t;let o=()=>{S===t&&(S=void 0)};return t.then(o,o),t}async function le(t,o){let s=e.client.controller;if(t.mode==="run"&&t.status!=="blocked"&&s)return b&&c&&K(),b=!1,j=void 0,de(s,o?.active?o:void 0);if(t.mode==="operation"&&t.purchases.length){z()||x(!0);let d=await l.wait(e.client.recoverPurchasePaywall(j).then(u=>((n||a.aborted)&&u?.destroy(),u)),H).catch(u=>(!n&&!a.aborted&&h(e.onError,u),null));if(n||a.aborted)return null;if(d){if(n||a.aborted)return d.destroy(),null;let u=K(!0)??P?.retainPurchaseDialog?.()??l.retainPurchaseDialog();P?.release();let r=m,i=ue({client:e.client,session:d,start:e.allowNewPurchase===!1||!r?void 0:async()=>{let{requestId:p,...G}=r;return G},signal:a}),y=()=>{!n&&!a.aborted&&!U&&I&&e.client.recovery.status==="complete"&&(U=!0,h(e.onComplete,structuredClone(I)))},A=await se(R,{signal:a,loading:"host",start:async()=>i.session,checkoutNavigation:"after_confirmation",allowNewPurchase:!1,resumeCheckout:p=>e.client.continueCheckout(L,p),...i.prepare&&{prepareUpgradeReplacement:i.prepare,terminateCheckout:p=>e.client.terminateCheckout(p),beforeCheckoutReplacement:e.beforeCheckoutReplacement,purchaseConfirmation:e.purchaseConfirmation,confirmOnHostedCheckout:e.confirmOnHostedCheckout,claimCoupon:e.claimCoupon,prepareSubscriptionChange:e.prepareSubscriptionChange,resolveSubscriptionChange:e.resolveSubscriptionChange,onPurchase:e.onPurchase,onCheckoutUrl:L,async resolveOfferId(p){let G=e.client.attempt;if(!G)throw new g("PURCHASE_PENDING","Read the new Start before selecting an offer");return e.resolveOfferId?.(p,G)},onComplete(){I=structuredClone(e.client.controller?.view)??I,E(),E=e.client.subscribe(y),y()}},onError:e.onError,onDismiss:()=>{n||k()}},{retainedDialog:u,present(p){l.active?l.present(p):p(!!u)},async dismiss(){k()}});if(!A.host||n||a.aborted)return A.host?.destroy(),u?.release(),v(),null;let M=A.host;return b=!1,c={destroy(){M.destroy(),v(),h(e.onDismiss,null)},refresh:async()=>{await M.refresh()},get recovery(){return M.recovery},prepareFallback:()=>M.prepareFallback(),review:async()=>{},exitReview:async()=>{},unappliedDrafts:new Map},q}}return t.purchases.length||b?(z()&&P?.release(),x(!1),q):(l.finish("skipped"),v(),(J||B)&&(n=!0,h(e.onDismiss,null)),null)}function L(t){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");return e.onCheckoutUrl?e.onCheckoutUrl(t):R.ownerDocument.defaultView?.location.assign(t)}async function de(t,o){a.removeEventListener("abort",F),B=!0;function s(){!n&&!a.aborted&&!b&&!U&&I&&e.client.recovery.status==="complete"&&(U=!0,h(e.onComplete,structuredClone(I)))}E(),E=e.client.subscribe(s);let d=++C,u=await ce(R,{...e,prepared:f,client:t,signal:a,prepareNextPaywall:({run:r,paywallVersionId:i})=>oe(R,{client:e.client,run:r,paywallVersionId:i,signal:a}),checkoutNavigation:"after_confirmation",resumeCheckout:r=>e.client.continueCheckout(L,r),terminateCheckout:e.allowNewPurchase===!1?void 0:r=>e.client.terminateCheckout(r),async onCheckoutUrl(r){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let i=e.client.recovery;if((!i.actions.includes("continue_checkout")||!i.purchases.some(y=>y.type==="checkout"&&y.checkoutUrl===r))&&(i=await e.client.refresh(),a.throwIfAborted(),n))throw new DOMException("Presentation dismissed","AbortError");if(ie(i)!==r)throw new g("PURCHASE_PENDING","Checkout differs from the original recovery proof");return L(r)},async resolveOfferId(r){if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");let i=e.client.attempt;if(!i)throw new g("PURCHASE_PENDING","Read the original Start before selecting an offer");let y=await e.resolveOfferId?.(r,i);if(a.throwIfAborted(),n)throw new DOMException("Presentation dismissed","AbortError");if(e.client.attempt?.requestId!==i.requestId)throw new g("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting an offer");return y},async resolveSubscriptionChange(r,...i){a.throwIfAborted();let y=e.client.attempt;if(n||!y)throw new g("PURCHASE_PENDING","Read the original Start before selecting a membership");let A=e.resolveSubscriptionChange?await e.resolveSubscriptionChange(r,...i):await i[0]?.();if(a.throwIfAborted(),n||e.client.attempt?.requestId!==y.requestId)throw new g("PURCHASE_STORAGE_CONFLICT","The original purchase changed while selecting a membership");return A},onPresentationState(r){d===C&&h(e.onPresentationState,r)},onComplete(r){d===C&&(I=r,s())},onError(r){d===C&&(h(e.onError,r),r instanceof g&&(r.status===401||r.status===409&&r.reason==="STATE_CHANGED"&&r.recovery==="recover_operation")&&!a.aborted&&Q().catch(i=>h(e.onError,i)))},onDismiss(r){d===C&&(n=!0,v(),O?.(),h(e.onDismiss,r))}},o);return d!==C||n||a.aborted?(u.destroy(),n||a.aborted?null:q):(c=u,q)}});return D.set(e.client,T),T}export{be as a};
|
package/dist/chunk-XKYVXIUI.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as n,r as t}from"./chunk-FDXBCQBO.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as x}from"./chunk-MMHL2KFB.js";import"./chunk-H3LJWAAE.js";import{a as T,c as A}from"./chunk-NKYNGR3L.js";import"./chunk-KCG7GZXO.js";import"./chunk-XAPMQRVJ.js";import"./chunk-C4KLIT5L.js";import"./chunk-CHRNCOXJ.js";import"./chunk-7CZEXBQY.js";import"./chunk-VXNN3RV3.js";import"./chunk-VVBXVJI6.js";import"./chunk-7ZAM4YRK.js";import"./chunk-AEQUKR4O.js";import"./chunk-W32FI2A2.js";import"./chunk-CO6HDNOC.js";import"./chunk-XLGNBPGF.js";import"./chunk-EQUVI5QU.js";import"./chunk-FDXBCQBO.js";import"./chunk-F4AIEI5N.js";import"./chunk-S2S4ROGY.js";import"./chunk-Y55OBV7D.js";import"./chunk-MOIVJERE.js";import"./chunk-C4HLVYSU.js";import"./chunk-7QPCNDIY.js";import"./chunk-BT7IC765.js";import"./chunk-ME6QTD5Y.js";import"./chunk-6XRQR43F.js";import"./chunk-3532HSBP.js";import"./chunk-67WFVDTV.js";import"./chunk-KX67ZM7H.js";import"./chunk-6VVQWTHV.js";import"./chunk-VILB5M4X.js";import"./chunk-6QBSJRAD.js";import"./chunk-KCUE2VFJ.js";import"./chunk-Y3W5G4BF.js";import"./chunk-FYUMVOCV.js";import"./chunk-DUS5V65Z.js";import"./chunk-BOT6ZDLK.js";import"./chunk-A5WUQLAO.js";import"./chunk-UGATOG2T.js";import"./chunk-LFR2LWYC.js";import"./chunk-SLUA7ABW.js";import"./chunk-MB2U2GWJ.js";import"./chunk-3VUPVXAV.js";import"./chunk-FEU6XRHV.js";import"./chunk-5MRSFLQA.js";import"./chunk-W22ESUYY.js";import{a as P}from"./chunk-DSPLGTQI.js";import"./chunk-FYMVNLQN.js";import"./chunk-FRK6322O.js";import"./chunk-WOT6VMZA.js";var D=.8;function N(l,n){let p=l.ownerDocument,v=new AbortController,c=AbortSignal.any([v.signal,n.client.identitySignal,...n.signal?[n.signal]:[]]),r,d,y,C=n.maxAgeMs??T,m=e=>P(n.onEvent,{at:performance.now(),...e});function f(e){e?.copy.destroy(),e?.select(void 0)}function E(){clearTimeout(y);let e=[r,d];r=d=void 0,e.forEach(f)}function O(){let e,t=new Promise(i=>{e=i}),o,a=A(l,{...n,start:t,signal:c,onState(i){m({type:"copy",state:i,...a.reason!==void 0&&{reason:a.reason},...o!==void 0&&{local:o}}),P(n.onState,i)}});return a.local.then(i=>o=i),{copy:a,select:e}}function u(){if(r||c.aborted||!l.isConnected||p.visibilityState==="hidden")return;let e=r=O();e.copy.ready.then(t=>{t&&r===e&&w()})}function w(){clearTimeout(y),y=setTimeout(()=>{if(!r||d||c.aborted)return;let e=d=O();e.copy.ready.then(t=>{if(d===e){if(d=void 0,!t||!r)return f(e);f(r),r=e,m({type:"renewed"}),w()}})},C*D)}function b(){p.visibilityState==="hidden"?E():u()}function R(){p.removeEventListener("visibilitychange",b),E()}function g(e){let t=e?.parameters?.commerce;return e?.funnelId===n.funnelId&&e.locale===n.locale&&t?.provider===n.commerce.provider&&t.currency===n.commerce.currency&&t.intent===n.commerce.intent}return c.aborted||(c.addEventListener("abort",R,{once:!0}),p.addEventListener("visibilitychange",b),u()),{open(e){if(c.aborted)return Promise.resolve(null);let t=r;r=void 0,clearTimeout(y),f(d),d=void 0;let o=t?.copy,a=e.start,i=!e.hostPaywallTarget&&e.allowNewPurchase!==!1&&(a instanceof Promise||g(a)),F=!1,h=s=>{F||(F=!0,m({type:"end",outcome:s}))};m({type:"open",copy:o?.state??"none",used:!!o&&i}),i||o?.destroy(),t?.select(i?a instanceof Promise?a.then(s=>{if(s&&!g(s)){o?.destroy();return}return s}):a:void 0);let S=x(l,{...e,client:n.client,prepared:i?o:void 0,signal:c,onDismiss(s){return h("dismissed"),queueMicrotask(u),e.onDismiss?.(s)}});return S.then(s=>{s||(h("nothing"),u())},()=>{h("error"),u()}),S},destroy(){v.abort()}}}export{N as createFunnelPurchaseEntry};
|
|
File without changes
|