@tinkerlandai/longplay-sdk 0.10.5 → 0.10.7
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 +11 -0
- package/README.md +6 -4
- package/README.zh-CN.md +9 -7
- package/dist/{chunk-MSOVR5KN.js → chunk-22Z7JR4B.js} +1 -1
- package/dist/{chunk-5FAUO337.js → chunk-3OFRQUUI.js} +1 -1
- package/dist/chunk-5JJZSH23.js +179 -0
- package/dist/chunk-6LILLFH3.js +1 -0
- package/dist/{chunk-5BWSWP6H.js → chunk-ACF2FBUB.js} +1 -1
- package/dist/{chunk-KMCA4Y2Q.js → chunk-AK3IJ6FZ.js} +1 -1
- package/dist/{chunk-O3FHA25D.js → chunk-G56XGVMS.js} +1 -1
- package/dist/{chunk-ZEEDAM4H.js → chunk-I4BZSRT4.js} +1 -1
- package/dist/{chunk-EK6IPAY5.js → chunk-IAOOTBJV.js} +1 -1
- package/dist/chunk-J6KIN4RH.js +1 -0
- package/dist/chunk-MOWYD2TV.js +1 -0
- package/dist/{chunk-OHYC6K3A.js → chunk-O52OWKP7.js} +1 -1
- package/dist/{chunk-BEBSMWPR.js → chunk-SBPTOOYB.js} +1 -1
- package/dist/chunk-SLUA7ABW.js +1 -0
- package/dist/chunk-SV6W2E2A.js +1 -0
- package/dist/{chunk-ZIUBXO6M.js → chunk-Y3AGPHWF.js} +1 -1
- package/dist/{chunk-ABL2UMTI.js → chunk-ZKSKBL4N.js} +1 -1
- package/dist/content-F7IVCK3I.js +1 -0
- package/dist/{funnel-local-client-CVokI0rx.d.ts → funnel-local-client-B4Z3dvNf.d.ts} +1 -1
- package/dist/{funnel-resource-client-Cv5OjfAn.d.ts → funnel-resource-client-BhbXsB2q.d.ts} +1 -1
- package/dist/funnel-runtime-host-W25OXLGE.js +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.js +1 -1
- package/dist/page.js +1 -1
- package/dist/paywall-XGDRMPLP.js +1 -0
- package/dist/popup.d.ts +2 -1
- package/dist/popup.js +1 -1
- package/dist/react-native.d.ts +5 -5
- package/dist/react-native.js +1 -1
- package/dist/screen-renderer-NLB3FAQJ.js +1 -0
- package/dist/server.d.ts +3 -3
- package/dist/server.js +1 -1
- package/dist/visual-dom-OIXANRP3.js +1 -0
- package/dist/visual.js +1 -1
- package/package.json +9 -10
- package/dist/chunk-EARSGITJ.js +0 -1
- package/dist/chunk-FSTRGSM5.js +0 -1
- package/dist/chunk-MPE7OZTE.js +0 -1
- package/dist/chunk-QOUOTUVB.js +0 -1
- package/dist/chunk-ZDT32X4G.js +0 -173
- package/dist/content-QPJOW6OT.js +0 -1
- package/dist/funnel-runtime-host-EHYY7OIZ.js +0 -1
- package/dist/paywall-EYRLWKC5.js +0 -1
- package/dist/screen-renderer-KOKMHO6R.js +0 -1
- package/dist/visual-dom-YGLIHSKU.js +0 -1
- /package/dist/{chunk-XVT5BKJW.js → chunk-7DXL3LHT.js} +0 -0
- /package/dist/{chunk-BI4R5Q7Z.js → chunk-XSVQHPQT.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Ge,b as Ae}from"./chunk-QOUOTUVB.js";import{a as Se,c as Le}from"./chunk-5FAUO337.js";import{a as He}from"./chunk-FSTRGSM5.js";import{b as Pe,g as xe,l as X,m as Be,n as Fe,p as ke}from"./chunk-ZIUBXO6M.js";import"./chunk-BEBSMWPR.js";import{F as Te,G as Oe,H as De,Ka as Ee,La as we,Ma as ve,Qa as Re,i as ae,k as K,l as ie,m as se,n as ce,o as de,p as ue,q as le,qa as ge,r as me,s as fe,t as pe,u as he,w as J,x as Ie,y as ye}from"./chunk-EK6IPAY5.js";import{qa as A}from"./chunk-5BWSWP6H.js";import{a as Ce,c as Z}from"./chunk-MPE7OZTE.js";import"./chunk-EARSGITJ.js";import{c as _e,d as be}from"./chunk-ABL2UMTI.js";import{a as j}from"./chunk-DSPLGTQI.js";import"./chunk-O3FHA25D.js";import"./chunk-MSOVR5KN.js";import"./chunk-XVT5BKJW.js";import"./chunk-BI4R5Q7Z.js";import{z as $}from"zod";var r=class extends Error{constructor(m,L=0,I=!1,h="fix_request"){super(m);this.code=m;this.status=L;this.retryable=I;this.recovery=h;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function Ue(n,S){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let m=n.body?.getReader();if(!m)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let L=()=>{m.cancel().catch(()=>{})};S.addEventListener("abort",L,{once:!0});let I=0,h="",a=new TextDecoder("utf-8",{fatal:!0});try{for(S.throwIfAborted();;){let c=await m.read();if(S.throwIfAborted(),c.done)break;if(I+=c.value.byteLength,I>262144)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");h+=a.decode(c.value,{stream:!0})}return h+=a.decode(),JSON.parse(h)}catch(c){throw S.throwIfAborted(),c instanceof r?c:new r("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{S.removeEventListener("abort",L),await m.cancel().catch(()=>{}),m.releaseLock()}}function je(n){let S=de.parse(n.origin),m=ue.parse(n.manifest),L={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let o of["projectId","environmentId","environment"])if(m[o]!==n.scope[o])throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");let I=n.customerId===void 0?null:$.uuid().parse(n.customerId),h=0,a=null,c=null,k=new AbortController,V=n.fetch??globalThis.fetch;async function T(o,t,s,E,M){if(!m.capabilities.includes(o))throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let _=ce[o];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(_.authority))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);let O=h,B=AbortSignal.any([k.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...E?[E]:[]]);B.throwIfAborted();let v=new Headers(await n.headers?.());if(B.throwIfAborted(),O!==h)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(v.get("authorization")??"")||v.has("X-Indiana-Bridge-Signature")||v.has("X-Indiana-Bridge-Key-Id"))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);v.set(se,String(K)),v.set("Accept","application/json");let y=crypto.randomUUID();v.set("X-Request-Id",y),v.set("Content-Type","application/json");let f=await V(S+ie,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:v,signal:B,body:JSON.stringify({bridgeVersion:K,requestId:y,command:_.command,scope:L,data:M??(s===void 0?{}:{operationId:s})})}),D=await Ue(f,B);if(B.throwIfAborted(),O!==h)throw new DOMException("Merchant identity changed","AbortError");if(!f.ok){let g=ye.safeParse(D);throw!g.success||g.data.scope.projectId!==n.scope.projectId||g.data.scope.environment!==n.scope.environment||g.data.scope.environmentId!==n.scope.environmentId||g.data.requestId!==y||g.data.command!==_.command?new r("MERCHANT_BRIDGE_INVALID_RESPONSE",f.status):new r(g.data.error.code,f.status,g.data.error.retryable,g.data.error.recovery)}let R=le($.unknown()).safeParse(D);if(!R.success||R.data.scope.projectId!==n.scope.projectId||R.data.scope.environment!==n.scope.environment||R.data.scope.environmentId!==n.scope.environmentId||R.data.requestId!==y||R.data.command!==_.command)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",f.status);let d=t.safeParse(R.data.data);if(!d.success)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",f.status);return d.data}function w(){if(!I)throw new r("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return I}async function G(o,t,s,E){let M=w(),_=he.parse({operationId:s,customerId:M}),O=await T(o,t,_.operationId,E,_);if(O.customerId!==M||O.operationId!==_.operationId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return O}return{async readPresentation(o){let t=await T("presentation",fe,void 0,o);if(c!==null&&c!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t.presentation&&I!==null&&t.presentation.customerId!==I)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return c=t.nativeUserId,a=t.presentation,t},async createSession(o){let t=await T("session",me,void 0,o);if(c!==null&&c!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(I!==null&&I!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(a&&a.customerId!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return I=t.session.customerId,c=t.nativeUserId,t.session},async reportPresentation(o,t){let s=w(),E=pe.parse(o);if(!a||a.customerId!==s||a.decisionId!==E.decisionId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return T("presentation_events",$.strictObject({queued:$.literal(!0)}),void 0,t,E)},async readCustomerCommerce(o){let t=w(),s=await T("customer_commerce",Ie,void 0,o);if(s.customerId!==t)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return s},async executePurchase(o,t){let s=await G("purchases",J,o,t);if(s.type!=="purchase")throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");return s},readOperation:(o,t)=>G("operation_status",ae,o,t),async executeSubscriptionChange(o,t){let s=await G("subscription_changes",J,o,t);if(s.type!=="subscription_change")throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");return s},reset(){h++,k.abort(),k=new AbortController,I=null,a=null,c=null}}}function Ve(n){let S=_e(n.baseUrl),m=n.scope,L=Re(n),I=n.fetch??globalThis.fetch.bind(globalThis),h,a=!1,c=!1,k=0,V=0,T="",w=0,G=0,o=0,t,s=!1,E,M=!0,_,O,B,v,y,f,D=e=>{f===e&&(f=void 0,F())},R=new Set,d=(e,u)=>j(n.onStatus,e,u);function g(){let e=y;y=void 0,e?.host.destroy(),e?.client.reset(),F()}let Y=()=>Date.now()<G&&performance.now()<o;function Q(e){if(e.target.release!==n.appManifestRelease||!Y())return!1;try{return Z(e.target.render,document,location.pathname,()=>{})}catch{return d("incompatible",e.id),!1}}function z(e){if(a||e.epoch!==w||e.visit!==V||document.visibilityState==="hidden")return!1;try{return Z(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function W(e){if(f||y){d("in_progress",e.id);return}if(!n.session.peek()){d("identity_required",e.id);return}let u={command:we.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:w,visit:V,target:e.target};f=u,await ee(u)}async function ee(e){if(e.dispatching)return;e.dispatching=!0;let u,b=!1;async function N(l){if(e.epoch!==w)return;let p=l.view;p&&["running","waiting"].includes(p.status)&&await l.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:p.nodeId,visit:p.visit,revision:p.revision})}try{d("starting",e.command.entryId);let l=await L.request("funnels",e.command),p=ve.safeParse(l);if(p.success){if(p.data.scope.projectId!==m.projectId||p.data.scope.environment!==m.environment)throw new A("SCOPE_MISMATCH","Entry scope changed");e.epoch===w&&d(p.data.reason,e.command.entryId),D(e);return}let C=ge.parse(l);if(!C.runToken||C.scope.projectId!==m.projectId||C.scope.environment!==m.environment||C.run.source.type!=="funnel"||C.run.source.id!==e.command.funnelId||C.run.source.versionId!==e.command.versionId)throw new A("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==w){D(e),d("identity_changed",e.command.entryId);return}let i=X({...n,runToken:C.runToken,funnelId:e.command.funnelId});u=i,await i.get();let P=i.view;if(!P||P.id!==C.run.id||P.source.type!=="funnel"||P.source.id!==e.command.funnelId||P.source.versionId!==e.command.versionId)throw new A("INVALID_RESPONSE","Entry Run version changed");if(!z(e)){await N(i),d("left_screen",e.command.entryId),D(e);return}let H=!1,q=!1,U=await Ae(n.container,{...n.host,client:i,appManifestRelease:n.appManifestRelease,onDismiss(x){H=!0,y?.client===i&&(y=void 0,i.reset(),F(),x&&x.status!=="completed"&&d("run_ended",e.command.entryId)),j(n.host?.onDismiss,x)},onComplete(x){q=!0,y?.client===i&&g(),j(n.host?.onComplete,x)},onError(x){j(n.host?.onError,x),y?.client===i&&x instanceof A&&x.code==="FORBIDDEN"&&(g(),d("run_ended",e.command.entryId))}});if(!z(e)||H||q){U.destroy(),z(e)||await N(i),D(e);return}y={host:U,client:i},b=!0,D(e),d("started",e.command.entryId)}catch(l){!u&&l instanceof A&&l.status!==void 0&&l.status>=400&&l.status<500&&!l.retryable&&D(e),e.epoch===w&&!a&&(d("start_failed",e.command.entryId),j(n.host?.onError,l))}finally{b||u?.reset(),e.dispatching=!1}}function Me(){if(s=!1,!(a||!c||document.visibilityState==="hidden")){if(!Y()){M=!0;return}M=!1;for(let e of h?.entries??[])if(!(e.event!=="screen_enter"||R.has(`${e.funnelId}:${e.id}`)||!Q(e))){if(!n.session.peek()){d("identity_required",e.id);continue}if(f||y){d("in_progress",e.id);return}R.add(`${e.funnelId}:${e.id}`),W(e);break}}}let F=()=>{!s&&!a&&(s=!0,queueMicrotask(Me))};function Ne(){let e=location.origin+location.pathname;e!==T&&(T=e,V++,M=!0,R.clear(),F())}function ne(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let u=e.target;if(!(u instanceof Element)||u.closest("[data-indiana-funnel]"))return;let b=u.closest("button,a,input");if(!(!b||b.matches(":disabled,[aria-disabled='true']")||b.closest("[hidden],[inert],[aria-hidden='true']")))for(let N of h?.entries??[]){let l=N.target.button;if(!(N.event!=="button_click"||!l||!Q(N))){try{let p=Ce(document);if(!b.matches(l.selector)||p(l.selector)!==1)continue}catch{d("incompatible",N.id);continue}W(N);break}}}async function te(){if(a)return;if(E)return E;let e=++k,u=new AbortController;_=u;let b,N=new Promise((C,i)=>{b=()=>i(new A("TIMEOUT","Funnel entry configuration read cancelled or timed out")),u.signal.addEventListener("abort",b,{once:!0})}),l=setTimeout(()=>u.abort(),n.timeoutMs??5e3),p=(async()=>{let C=async()=>{let U=await I(`${S}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:u.signal});if(!U.ok)throw new A("SERVICE_UNAVAILABLE","Funnel entries unavailable",U.status);return Ee.parse(await U.json())},i=await Promise.race([C(),N]),P=Date.parse(i.validatedAt),H=Date.parse(i.validUntil);if(i.scope.projectId!==m.projectId||i.scope.environment!==m.environment||i.scope.environmentId!==n.environmentId||i.release!==n.appManifestRelease||H<=Date.now()||P>Date.now()+5e3||H-P>6e4||H<=P)throw new A("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(a||e!==k)return;let q=h===void 0;h=i,G=H,o=performance.now()+Math.min(H-Date.now(),6e4),(q||M)&&F()})();E=p;try{await p}finally{clearTimeout(l),u.signal.removeEventListener("abort",b),E===p&&(E=void 0)}}async function re(){try{await te()}catch{a||d("configuration_unavailable")}a||(t=setTimeout(()=>{re()},15e3))}let oe=()=>F();return{async start(){c||a||(c=!0,T=location.origin+location.pathname,O=be(Ne),B=n.session.subscribeIdentity(()=>{w++,M=!0,f=void 0,R.clear(),g(),F()}),v=new MutationObserver(F),v.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",ne,!0),document.addEventListener("visibilitychange",oe),await re())},refresh:te,async retry(){f&&!a&&f.epoch===w&&await ee(f)},destroy(){a=!0,k++,clearTimeout(t),_?.abort(),v?.disconnect(),O?.(),B?.(),document.removeEventListener("click",ne,!0),document.removeEventListener("visibilitychange",oe),g(),h=void 0}}}async function rn(...n){return(await import("./paywall-EYRLWKC5.js")).showPaywall(...n)}async function on(...n){return(await import("./funnel-runtime-host-EHYY7OIZ.js")).showFunnelRun(...n)}async function an(...n){return(await import("./content-QPJOW6OT.js")).mountContent(...n)}async function sn(...n){return(await import("./content-QPJOW6OT.js")).prepareContent(...n)}export{A as IndianaError,A as LongplayError,r as MerchantBridgeError,xe as createBrowserFunnelCommandStorage,Fe as createConfigurationSync,Pe as createFeatureClient,Le as createFunnelClient,Ge as createFunnelPageExperiments,X as createFunnelRunController,Ve as createIamFunnelEntries,Se as createIndiana,ke as createLocalFunnelClient,Se as createLongplay,je as createMerchantBridge,Be as createPaywallSession,He as evaluateFunnelNode,Oe as formatCouponDiscount,Te as formatCouponMoney,De as formatCouponTerms,an as mountContent,sn as prepareContent,on as showFunnelRun,rn as showPaywall};
|
|
1
|
+
import{a as Ue,b as Ae}from"./chunk-SV6W2E2A.js";import"./chunk-MOWYD2TV.js";import{a as xe,c as ke}from"./chunk-3OFRQUUI.js";import{a as Le}from"./chunk-6LILLFH3.js";import{b as Pe,g as Be,l as X,m as Fe,n as He,p as Ge}from"./chunk-Y3AGPHWF.js";import"./chunk-SBPTOOYB.js";import{F as Te,G as De,H as Oe,Ka as we,La as ve,Ma as Re,Qa as Se,i as ie,k as K,l as se,m as ce,n as de,o as ue,p as le,q as me,qa as Ee,r as fe,s as pe,t as he,u as Ie,w as J,x as ye,y as ge}from"./chunk-IAOOTBJV.js";import{qa as N}from"./chunk-ACF2FBUB.js";import{a as Ce,c as Z}from"./chunk-J6KIN4RH.js";import"./chunk-SLUA7ABW.js";import{c as _e,d as be}from"./chunk-ZKSKBL4N.js";import{a as j}from"./chunk-DSPLGTQI.js";import"./chunk-G56XGVMS.js";import"./chunk-22Z7JR4B.js";import"./chunk-7DXL3LHT.js";import"./chunk-XSVQHPQT.js";import{z as $}from"zod";var r=class extends Error{constructor(m,L=0,I=!1,p="fix_request"){super(m);this.code=m;this.status=L;this.retryable=I;this.recovery=p;this.name="MerchantBridgeError"}code;status;retryable;recovery};async function je(n,b){if(!n.headers.get("content-type")?.split(";",1)[0].trim().match(/^application\/(?:json|[a-z0-9.+-]+\+json)$/i))throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let m=n.body?.getReader();if(!m)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");let L=()=>{m.cancel().catch(()=>{})};b.addEventListener("abort",L,{once:!0});let I=0,p="",a=new TextDecoder("utf-8",{fatal:!0});try{for(b.throwIfAborted();;){let d=await m.read();if(b.throwIfAborted(),d.done)break;if(I+=d.value.byteLength,I>262144)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");p+=a.decode(d.value,{stream:!0})}return p+=a.decode(),JSON.parse(p)}catch(d){throw b.throwIfAborted(),d instanceof r?d:new r("MERCHANT_BRIDGE_INVALID_RESPONSE")}finally{b.removeEventListener("abort",L),await m.cancel().catch(()=>{}),m.releaseLock()}}function Ve(n){let b=ue.parse(n.origin),m=le.parse(n.manifest),L={projectId:n.scope.projectId,environmentId:n.scope.environmentId,environment:n.scope.environment};for(let o of["projectId","environmentId","environment"])if(m[o]!==n.scope[o])throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");let I=n.customerId===void 0?null:$.uuid().parse(n.customerId),p=0,a=null,d=null,k=new AbortController,V=n.fetch??globalThis.fetch;async function D(o,t,s,E,T){if(!m.capabilities.includes(o))throw new r("MERCHANT_BRIDGE_CAPABILITY_UNSUPPORTED",501);let C=de[o];if(["merchant_catalog_reader","merchant_refund_authority","indiana_server_key"].includes(C.authority))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);let O=p,B=AbortSignal.any([k.signal,AbortSignal.timeout(Math.min(3e4,Math.max(1e3,n.timeoutMs??1e4))),...n.signal?[n.signal]:[],...E?[E]:[]]);B.throwIfAborted();let R=new Headers(await n.headers?.());if(B.throwIfAborted(),O!==p)throw new DOMException("Merchant identity changed","AbortError");if(/\bgg_(?:sk|ct|rt)_/.test(R.get("authorization")??"")||R.has("X-Indiana-Bridge-Signature")||R.has("X-Indiana-Bridge-Key-Id"))throw new r("MERCHANT_BRIDGE_FORBIDDEN",403);R.set(ce,String(K)),R.set("Accept","application/json");let y=crypto.randomUUID();R.set("X-Request-Id",y),R.set("Content-Type","application/json");let f=await V(b+se,{method:"POST",credentials:"include",redirect:"error",cache:"no-store",headers:R,signal:B,body:JSON.stringify({bridgeVersion:K,requestId:y,command:C.command,scope:L,data:T??(s===void 0?{}:{operationId:s})})}),P=await je(f,B);if(B.throwIfAborted(),O!==p)throw new DOMException("Merchant identity changed","AbortError");if(!f.ok){let g=ge.safeParse(P);throw!g.success||g.data.scope.projectId!==n.scope.projectId||g.data.scope.environment!==n.scope.environment||g.data.scope.environmentId!==n.scope.environmentId||g.data.requestId!==y||g.data.command!==C.command?new r("MERCHANT_BRIDGE_INVALID_RESPONSE",f.status):new r(g.data.error.code,f.status,g.data.error.retryable,g.data.error.recovery)}let S=me($.unknown()).safeParse(P);if(!S.success||S.data.scope.projectId!==n.scope.projectId||S.data.scope.environment!==n.scope.environment||S.data.scope.environmentId!==n.scope.environmentId||S.data.requestId!==y||S.data.command!==C.command)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",f.status);let u=t.safeParse(S.data.data);if(!u.success)throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE",f.status);return u.data}function v(){if(!I)throw new r("MERCHANT_BRIDGE_UNAUTHENTICATED",401);return I}async function G(o,t,s,E){let T=v(),C=Ie.parse({operationId:s,customerId:T}),O=await D(o,t,C.operationId,E,C);if(O.customerId!==T||O.operationId!==C.operationId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return O}return{async readPresentation(o){let t=await D("presentation",pe,void 0,o);if(d!==null&&d!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(t.presentation&&I!==null&&t.presentation.customerId!==I)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return d=t.nativeUserId,a=t.presentation,t},async createSession(o){let t=await D("session",fe,void 0,o);if(d!==null&&d!==t.nativeUserId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(I!==null&&I!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");if(a&&a.customerId!==t.session.customerId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return I=t.session.customerId,d=t.nativeUserId,t.session},async reportPresentation(o,t){let s=v(),E=he.parse(o);if(!a||a.customerId!==s||a.decisionId!==E.decisionId)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return D("presentation_events",$.strictObject({queued:$.literal(!0)}),void 0,t,E)},async readCustomerCommerce(o){let t=v(),s=await D("customer_commerce",ye,void 0,o);if(s.customerId!==t)throw new r("MERCHANT_BRIDGE_SCOPE_MISMATCH");return s},async executePurchase(o,t){let s=await G("purchases",J,o,t);if(s.type!=="purchase")throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");return s},readOperation:(o,t)=>G("operation_status",ie,o,t),async executeSubscriptionChange(o,t){let s=await G("subscription_changes",J,o,t);if(s.type!=="subscription_change")throw new r("MERCHANT_BRIDGE_INVALID_RESPONSE");return s},reset(){p++,k.abort(),k=new AbortController,I=null,a=null,d=null}}}function qe(n){let b=_e(n.baseUrl),m=n.scope,L=Se(n),I=n.fetch??globalThis.fetch.bind(globalThis),p,a=!1,d=!1,k=0,V=0,D="",v=0,G=0,o=0,t,s=!1,E,T=!0,C,O,B,R,y,f,P=e=>{f===e&&(f=void 0,F())},S=new Set,u=(e,l)=>j(n.onStatus,e,l);function g(){let e=y;y=void 0,e?.host.destroy(),e?.client.reset(),F()}let Y=()=>Date.now()<G&&performance.now()<o;function Q(e){if(e.target.release!==n.appManifestRelease||!Y())return!1;try{return Z(e.target.render,document,location.pathname,()=>{})}catch{return u("incompatible",e.id),!1}}function z(e){if(a||e.epoch!==v||e.visit!==V||document.visibilityState==="hidden")return!1;try{return Z(e.target.render,document,location.pathname,()=>{})}catch{return!1}}async function W(e){if(f||y){u("in_progress",e.id);return}if(!n.session.peek()){u("identity_required",e.id);return}let l={command:ve.parse({operation:"entry_start",entryId:e.id,funnelId:e.funnelId,versionId:e.versionId,release:n.appManifestRelease,requestId:crypto.randomUUID(),locale:document.documentElement.lang||"en"}),epoch:v,visit:V,target:e.target};f=l,await ee(l)}async function ee(e){if(e.dispatching)return;e.dispatching=!0;let l,_=!1,A=!1;async function H(c){if(e.epoch!==v)return;let w=c.view;if(w&&["running","waiting"].includes(w.status))try{await c.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:w.nodeId,visit:w.visit,revision:w.revision})}catch(i){if(!(i instanceof N&&i.code==="FORBIDDEN"))throw i}}try{u("starting",e.command.entryId);let c=await L.request("funnels",e.command),w=Re.safeParse(c);if(w.success){if(w.data.scope.projectId!==m.projectId||w.data.scope.environment!==m.environment)throw new N("SCOPE_MISMATCH","Entry scope changed");e.epoch===v&&u(w.data.reason,e.command.entryId),P(e);return}let i=Ee.parse(c);if(!i.runToken||i.scope.projectId!==m.projectId||i.scope.environment!==m.environment||i.run.source.type!=="funnel"||i.run.source.id!==e.command.funnelId||i.run.source.versionId!==e.command.versionId)throw new N("INVALID_RESPONSE","Invalid entry Run");if(e.epoch!==v){P(e),u("identity_changed",e.command.entryId);return}let h=X({...n,runToken:i.runToken,funnelId:e.command.funnelId});l=h,A=!0,await h.get(),A=!1;let M=h.view;if(!M||M.id!==i.run.id||M.source.type!=="funnel"||M.source.id!==e.command.funnelId||M.source.versionId!==e.command.versionId)throw new N("INVALID_RESPONSE","Entry Run version changed");if(!z(e)){await H(h),u("left_screen",e.command.entryId),P(e);return}let q=!1,U=!1,ae=await Ae(n.container,{...n.host,client:h,appManifestRelease:n.appManifestRelease,onDismiss(x){q=!0,y?.client===h&&(y=void 0,h.reset(),F(),x&&x.status!=="completed"&&u("run_ended",e.command.entryId)),j(n.host?.onDismiss,x)},onComplete(x){U=!0,y?.client===h&&g(),j(n.host?.onComplete,x)},onError(x){j(n.host?.onError,x),y?.client===h&&x instanceof N&&x.code==="FORBIDDEN"&&(g(),u("run_ended",e.command.entryId))}});if(!z(e)||q||U){ae.destroy(),z(e)||await H(h),P(e);return}y={host:ae,client:h},_=!0,P(e),u("started",e.command.entryId)}catch(c){c instanceof N&&(!l||A&&c.code==="FORBIDDEN")&&c.status!==void 0&&c.status>=400&&c.status<500&&!c.retryable&&P(e),e.epoch===v&&!a&&(u("start_failed",e.command.entryId),j(n.host?.onError,c))}finally{_||l?.reset(),e.dispatching=!1}}function Me(){if(s=!1,!(a||!d||document.visibilityState==="hidden")){if(!Y()){T=!0;return}T=!1;for(let e of p?.entries??[])if(!(e.event!=="screen_enter"||S.has(`${e.funnelId}:${e.id}`)||!Q(e))){if(!n.session.peek()){u("identity_required",e.id);continue}if(f||y){u("in_progress",e.id);return}S.add(`${e.funnelId}:${e.id}`),W(e);break}}}let F=()=>{!s&&!a&&(s=!0,queueMicrotask(Me))};function Ne(){let e=location.origin+location.pathname;e!==D&&(D=e,V++,T=!0,S.clear(),F())}function ne(e){if(!e.isTrusted||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey||document.visibilityState==="hidden")return;let l=e.target;if(!(l instanceof Element)||l.closest("[data-indiana-funnel]"))return;let _=l.closest("button,a,input");if(!(!_||_.matches(":disabled,[aria-disabled='true']")||_.closest("[hidden],[inert],[aria-hidden='true']")))for(let A of p?.entries??[]){let H=A.target.button;if(!(A.event!=="button_click"||!H||!Q(A))){try{let c=Ce(document);if(!_.matches(H.selector)||c(H.selector,_)!==1)continue}catch{u("incompatible",A.id);continue}W(A);break}}}async function te(){if(a)return;if(E)return E;let e=++k,l=new AbortController;C=l;let _,A=new Promise((w,i)=>{_=()=>i(new N("TIMEOUT","Funnel entry configuration read cancelled or timed out")),l.signal.addEventListener("abort",_,{once:!0})}),H=setTimeout(()=>l.abort(),n.timeoutMs??5e3),c=(async()=>{let w=async()=>{let U=await I(`${b}/api/v1/funnel-entries/${n.environmentId}?iam=${n.appManifestRelease}`,{credentials:"omit",cache:"no-store",redirect:"error",signal:l.signal});if(!U.ok)throw new N("SERVICE_UNAVAILABLE","Funnel entries unavailable",U.status);return we.parse(await U.json())},i=await Promise.race([w(),A]),h=Date.parse(i.validatedAt),M=Date.parse(i.validUntil);if(i.scope.projectId!==m.projectId||i.scope.environment!==m.environment||i.scope.environmentId!==n.environmentId||i.release!==n.appManifestRelease||M<=Date.now()||h>Date.now()+5e3||M-h>6e4||M<=h)throw new N("INVALID_RESPONSE","Entry configuration scope or deadline changed");if(a||e!==k)return;let q=p===void 0;p=i,G=M,o=performance.now()+Math.min(M-Date.now(),6e4),(q||T)&&F()})();E=c;try{await c}finally{clearTimeout(H),l.signal.removeEventListener("abort",_),E===c&&(E=void 0)}}async function re(){try{await te()}catch{a||u("configuration_unavailable")}a||(t=setTimeout(()=>{re()},15e3))}let oe=()=>F();return{async start(){d||a||(d=!0,D=location.origin+location.pathname,O=be(Ne),B=n.session.subscribeIdentity(()=>{v++,T=!0,f=void 0,S.clear(),g(),F()}),R=new MutationObserver(F),R.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",ne,!0),document.addEventListener("visibilitychange",oe),await re())},refresh:te,async retry(){f&&!a&&f.epoch===v&&await ee(f)},destroy(){a=!0,k++,clearTimeout(t),C?.abort(),R?.disconnect(),O?.(),B?.(),document.removeEventListener("click",ne,!0),document.removeEventListener("visibilitychange",oe),g(),p=void 0}}}async function on(...n){return(await import("./paywall-XGDRMPLP.js")).showPaywall(...n)}async function an(...n){return(await import("./funnel-runtime-host-W25OXLGE.js")).showFunnelRun(...n)}async function sn(...n){return(await import("./content-F7IVCK3I.js")).mountContent(...n)}async function cn(...n){return(await import("./content-F7IVCK3I.js")).prepareContent(...n)}export{N as LongplayError,r as MerchantBridgeError,Be as createBrowserFunnelCommandStorage,He as createConfigurationSync,Pe as createFeatureClient,ke as createFunnelClient,Ue as createFunnelPageExperiments,X as createFunnelRunController,qe as createIamFunnelEntries,Ge as createLocalFunnelClient,xe as createLongplay,Ve as createMerchantBridge,Fe as createPaywallSession,Le as evaluateFunnelNode,De as formatCouponDiscount,Te as formatCouponMoney,Oe as formatCouponTerms,sn as mountContent,cn as prepareContent,an as showFunnelRun,on as showPaywall};
|