@tinkerlandai/indiana-sdk 0.8.4 → 0.8.5
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 +9 -1
- package/README.md +32 -3
- package/README.zh-CN.md +32 -3
- package/dist/chunk-3KQHKRZJ.js +1 -0
- package/dist/chunk-6A5WWFNS.js +10 -0
- package/dist/{chunk-F2GOIBDQ.js → chunk-A3XRIG53.js} +1 -1
- package/dist/{chunk-663UOBHL.js → chunk-FGIGKO7A.js} +1 -1
- package/dist/chunk-HEBQUICQ.js +4 -0
- package/dist/{chunk-3F2NQOR2.js → chunk-SUXAWRR6.js} +1 -1
- package/dist/chunk-WWUUVURR.js +1 -0
- package/dist/{content-2FCUY6XX.js → content-DDMDNRCV.js} +1 -1
- package/dist/funnel-runtime-host-QK6WDRPS.js +1 -0
- 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-734GWAS4.js → paywall-4QT3JYD4.js} +1 -1
- package/dist/react-native.js +1 -1
- package/dist/server.js +1 -1
- package/dist/{src-CLEFCTAU.js → src-EG7RWDDY.js} +1 -1
- package/dist/visual.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-EJTBSGLV.js +0 -10
- package/dist/chunk-EXCPE2XH.js +0 -1
- package/dist/chunk-RZBZ6LCT.js +0 -4
- package/dist/chunk-SSHUBTT3.js +0 -1
- package/dist/funnel-runtime-host-ENRTSXPJ.js +0 -1
package/dist/chunk-EXCPE2XH.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t="https://api.tinker.cash";export{t as a};
|
package/dist/chunk-RZBZ6LCT.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{a as P}from"./chunk-DSPLGTQI.js";import{a as $}from"./chunk-EXCPE2XH.js";import{e as C,h as O,k as D}from"./chunk-KQCTDXVD.js";function N(e){if(!/^[A-Za-z0-9_-]{1,64}$/.test(e))throw new Error("Invalid device cookie name");let t="";for(let n of document.cookie.split(";"))if(n.trim().startsWith(`${e}=`))try{t=decodeURIComponent(n.trim().slice(e.length+1))}catch{}return/^[A-Za-z0-9_-]{8,128}$/.test(t)||(t=crypto.randomUUID(),document.cookie=`${e}=${encodeURIComponent(t)}; path=/; max-age=${400*24*3600}; SameSite=Lax`),t}function j(){try{let e=sessionStorage.getItem("indiana_sid");return e||(e=crypto.randomUUID(),sessionStorage.setItem("indiana_sid",e)),e}catch{return}}function H(e=$){let t=new URL(e);if(t.protocol!=="https:"&&!(t.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(t.hostname))||t.username||t.password||t.search||t.hash)throw new Error("baseUrl must be an https origin without credentials");return t.origin}var w=new Set,R;function Y(e){let t=()=>e();if(w.add(t),!R){let n=!0,r=history.pushState,o=history.replaceState,s=()=>{if(n)for(let i of[...w])w.has(i)&&P(i)},c=function(...i){r.apply(this,i),s()},a=function(...i){o.apply(this,i),s()};history.pushState=c,history.replaceState=a,addEventListener("popstate",s),addEventListener("hashchange",s),R=()=>{n=!1,history.pushState===c&&(history.pushState=r),history.replaceState===a&&(history.replaceState=o),removeEventListener("popstate",s),removeEventListener("hashchange",s)}}return()=>{w.delete(t)&&(w.size||(R?.(),R=void 0))}}var ee=e=>new TextEncoder().encode(JSON.stringify({events:e})).length;function te(e,t){let n=e,r=o=>Number.isInteger(o)&&o>=0;return!!n&&typeof n=="object"&&r(n.inserted)&&r(n.duplicates)&&r(n.skipped)&&Array.isArray(n.rejected)&&n.inserted+n.duplicates+n.skipped+n.rejected.length===t}function B(e){let t=[],n,r=(a,i)=>e.log?.(`${e.label} ${a}`,i);function o(a){n===void 0&&t.length&&(n=setTimeout(()=>{c()},a))}async function s(a){let i;try{i=await e.fetch(e.endpoint,{method:"POST",body:JSON.stringify({events:a}),headers:{"Content-Type":"text/plain"},keepalive:!0,credentials:"omit"})}catch(f){return r("not sent",{error:f}),!1}if(i.status===408||i.status===429||i.status>=500)return r("not sent",{status:i.status}),!1;if(!i.ok)return r("rejected",{status:i.status,events:a.length}),!0;let p;try{p=await i.json()}catch{p=void 0}return te(p,a.length)?(p.rejected.length&&r("rejected",{rejected:p.rejected}),!0):(r("not acknowledged",{status:i.status}),!1)}function c(){clearTimeout(n),n=void 0;let a=[];for(;t.length&&a.length<20&&(!a.length||ee([...a,t[0]].map(i=>i.event))<=65536);)a.push(t.shift());return a.length?s(a.map(i=>i.event)).then(i=>{if(i)return o(1e3);let p=a.filter(f=>++f.attempts<5);p.length<a.length&&r("dropped after retries",{events:a.length-p.length}),t.unshift(...p),o(5e3)}):Promise.resolve()}return{push(a){t.push({event:a,attempts:0}),t.length>=20?c():o(1e3)},flush:c}}async function q(e,t,n,r={}){let o=r.message??"Invalid SDK JSON response",s=e.headers.get("content-length");if(!e.ok||!/^application\/json(?:;|$)/i.test(e.headers.get("content-type")??"")||s!==null&&(!/^\d+$/.test(s)||Number(s)>t)||!e.body)throw e.body?.cancel().catch(()=>{}),Error(o);let c=e.body.getReader(),a=[],i=0,p=!1,f=()=>{},g=new Promise((y,h)=>{f=()=>h(Error(o)),n.addEventListener("abort",f,{once:!0}),n.aborted&&f()});try{for(;;){let m=await Promise.race([c.read(),g]);if(m.done){p=!0;break}if(i+=m.value.byteLength,i>t)throw Error(o);a.push(m.value)}let y=new Uint8Array(i),h=0;for(let m of a)y.set(m,h),h+=m.length;return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(y))}finally{n.removeEventListener("abort",f),p||c.cancel().catch(()=>{}),c.releaseLock()}}async function V(e,t){let n=e?.body;if(!n)return;let r=n.getReader(),o=0,s=!1,c,a=new Promise((f,g)=>{c=setTimeout(()=>g(Error("Exposure response timeout")),2e3)}),i=()=>{},p=new Promise((f,g)=>{i=()=>g(t?.reason),t?.addEventListener("abort",i,{once:!0}),t?.aborted&&i()});try{for(;;){let f=await Promise.race([r.read(),a,p]);if(f.done){s=!0;return}if(o+=f.value.byteLength,o>16384)throw Error("Exposure response budget")}}finally{clearTimeout(c),t?.removeEventListener("abort",i),s||r.cancel().catch(()=>{}),r.releaseLock()}}var fe=2*1024*1024,G=256*1024;async function J(e,t,n,r){let o=()=>{},s=new Promise((c,a)=>{o=()=>a(r.reason),r.addEventListener("abort",o,{once:!0}),r.aborted&&o()});try{let c=e(t,{...n,signal:r});return c.then(a=>{r.aborted&&a.body?.cancel().catch(()=>{})},()=>{}),await Promise.race([c,s])}finally{r.removeEventListener("abort",o)}}async function ge(e,t,n,r=!1){if(new TextEncoder().encode(n).byteLength>65536)throw Error("Exposure request budget");let o=new AbortController,s=setTimeout(()=>o.abort(Error("Exposure request timeout")),5e3);try{let c=await J(e,t,{method:"POST",headers:{"Content-Type":"text/plain"},body:n,credentials:"omit",keepalive:r,redirect:"error"},o.signal);await V(c,o.signal)}finally{clearTimeout(s)}}function M(e){let t,n=!1;return{async read(r,o){if(n)throw Error("Experiment client stopped");t?.abort(Error("Experiment request superseded"));let s=new AbortController;t=s;let{signal:c}=s,a=setTimeout(()=>s.abort(Error("Experiment request timeout")),5e3);try{let i=await J(e,r,{cache:"no-cache",credentials:"omit",redirect:"error"},c),p=await q(i,o,c);return c.throwIfAborted(),p}finally{clearTimeout(a),t===s&&(t=void 0)}},destroy(){n=!0,t?.abort(Error("Experiment client stopped")),t=void 0}}}/*!
|
|
2
|
-
Portions ported from GrowthBook sdk-js @ ed29827 (GrowthBook.ts auto experiments, util.ts mergeQueryStrings,
|
|
3
|
-
plugins/auto-attributes.ts). Copyright (c) GrowthBook, Inc. MIT License.
|
|
4
|
-
*/function re(e,t){let n,r;try{n=new URL(e),r=new URL(t)}catch{return t}return n.searchParams.forEach((o,s)=>{r.searchParams.has(s)||r.searchParams.set(s,o)}),r.toString()}function ne(e,t){let n=navigator.userAgent,r=new URLSearchParams(t.search),o={};for(let s of["source","medium","campaign","term","content"]){let c=r.get(`utm_${s}`);c!==null&&(o[`utm${s[0].toUpperCase()}${s.slice(1)}`]=c)}return{id:e,deviceId:e,url:t.href,path:t.pathname,host:t.host,query:t.search,pageTitle:typeof document>"u"?"":document.title,browser:/Edg/.test(n)?"edge":/Chrome/.test(n)?"chrome":/Firefox/.test(n)?"firefox":/Safari/.test(n)?"safari":"unknown",deviceType:/Mobi/.test(n)?"mobile":"desktop",...o}}function oe(e){let t=e;if(!(!!t&&typeof t=="object"&&typeof t.environmentId=="string"&&typeof t.trackExposures=="boolean"&&/^[a-f0-9]{64}$/.test(t.generation??"")&&Array.isArray(t.experiments)&&t.experiments.length<=100&&t.experiments.every(r=>!!r&&!["namespace","status","url","groups"].some(o=>Object.hasOwn(r,o))&&(r.hashVersion===void 0||r.hashVersion===2)&&typeof r.key=="string"&&Array.isArray(r.variations)&&r.variations.length>=2&&r.variations.every(o=>!!o&&typeof o.urlRedirect=="string")&&(r.urlPatterns===void 0||Array.isArray(r.urlPatterns)))&&!!t.savedGroups&&typeof t.savedGroups=="object"&&!Array.isArray(t.savedGroups)))throw new Error("Invalid page experiment payload");return t}function xe(e){if(e.configuration&&e.configuration.scope.environmentId!==e.environmentId)throw new Error("Page configuration belongs to another App environment");let t=H(e.baseUrl);if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("environmentId must be the App environment ID");let n=e.fetch??globalThis.fetch.bind(globalThis),r=M(async(u,d)=>{let l=await n(u,d);if(!l.ok)throw l.body?.cancel().catch(()=>{}),new Error(`Page experiments unavailable (${l.status})`);return l}),o=e.log?(u,d)=>P(e.log,u,d):void 0,s=`${t}/api/v1/page-experiments/${e.environmentId}`,c=N(e.deviceIdCookie??"indiana_did"),a=j(),i=null,p={...e.attributes??{}},f="",g=!1,y=!1,h=0,m=new Map,T=B({endpoint:`${s}/events`,fetch:n,log:o,label:"Exposure"}),S=T.flush,E={trackedExperiments:new Set,log:o,onExperimentViewed:(u,d)=>{e.trackExposures===!1||i?.trackExposures===!1||T.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:c,...a?{sessionId:a}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:u.key,variationKey:d.key})}},z=()=>{E.url=location.href,E.attributes={...ne(c,location),...p}};function Q(u){if(!e.disableCrossOriginUrlRedirects)return!1;try{let d=new URL(location.href);return u.variations.some(l=>{if(!l.urlRedirect)return!1;let v=new URL(l.urlRedirect);return v.protocol!==d.protocol||v.host!==d.host})}catch{return!0}}function W(u,d){let l=e.configuration?.snapshot?.generation;f=u;let v=e.navigate??(x=>location.replace(x)),X=e.navigateDelay??(e.navigate?0:100),Z=e.maxNavigateDelay??1e3;Promise.all([Promise.race([d,new Promise(x=>setTimeout(x,Z))]),new Promise(x=>setTimeout(x,X))]).then(()=>{!g&&(!e.configuration||e.configuration.fresh&&e.configuration.snapshot?.generation===l)&&v(u)})}function b(){if(!(!i||g||e.configuration&&!e.configuration.fresh)){z();for(let u of i.experiments){if(Q(u)){o?.("Auto experiment blocked",{id:u.key});continue}let d;try{d=D(u,E)}catch(l){o?.("Skipping page experiment",{id:u.key,error:String(l)});continue}if(m.set(u.key,d),!!d.inExperiment){if(d.value.urlRedirect){let l=u.persistQueryString?re(location.href,d.value.urlRedirect):d.value.urlRedirect;C(l,u.urlPatterns??[])?o?.("Skipping redirect because original URL matches redirect URL",{id:u.key}):l!==f&&W(l,S())}break}}}}let k="",F=()=>{location.href!==k&&(k=location.href,f="",b())},L,I;function K(){L??=Y(F),addEventListener("pagehide",U)}let U=()=>{S()};async function A(){if(g)return!1;let u=++h,d;try{d=e.configuration?await e.configuration.pageExperiments():await r.read(s,G)}catch(v){if(g||u!==h)return!1;throw v}if(g||u!==h)return!1;let l=oe(d);if(l.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Page experiment payload scope changed");return i?.trackExposures===!1&&l.trackExposures&&E.trackedExperiments?.clear(),i=l,E.savedGroups=O(l.savedGroups),!0}function _(){g||(I??=e.configuration?.subscribe(()=>{!g&&e.configuration?.fresh&&A().then(u=>{u&&b()}).catch(u=>o?.("Page configuration unavailable",{error:String(u)}))}),K(),k=location.href)}return{async start(){y||g||(y=!0,await A()&&(_(),b()))},async refresh(){await A()&&(y&&_(),f="",b())},setAttributes(u){p={...u},b()},getResults(){return new Map(m)},get generation(){return i?.generation??null},destroy(){g||(g=!0,h++,r.destroy(),I?.(),L?.(),removeEventListener("pagehide",U),i=null,m.clear(),S())}}}export{N as a,j as b,H as c,Y as d,fe as e,ge as f,M as g,re as h,ne as i,oe as j,xe as k};
|
package/dist/chunk-SSHUBTT3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as v,p as k,s as S}from"./chunk-EJTBSGLV.js";import{a as e}from"./chunk-SOQO2RDZ.js";import{a as C,j,m as _,p as P}from"./chunk-LMR2TM3X.js";import{b}from"./chunk-OBYJWIRB.js";import{a as L}from"./chunk-EXCPE2XH.js";var M={name:"@tinkerlandai/indiana-sdk",version:"0.8.4",description:"Framework-independent Indiana SDK for customer identity, entitlements, credits, offers and growth surfaces.",license:"UNLICENSED",repository:{type:"git",url:"git+https://github.com/tinkerlandai/Indiana.git",directory:"packages/sdk"},engines:{node:">=22"},publishConfig:{access:"public",tag:"beta"},type:"module",sideEffects:!1,files:["dist","README.md","README.zh-CN.md","CHANGELOG.md","THIRD_PARTY_NOTICES.md"],exports:{"./react-native":{types:"./dist/react-native.d.ts","react-native":"./dist/react-native.js",import:"./dist/react-native.js",default:"./dist/react-native.js"},".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./popup":{types:"./dist/popup.d.ts",import:"./dist/popup.js"},"./server":{types:"./dist/server.d.ts",import:"./dist/server.js"},"./openrouter":{types:"./dist/openrouter.d.ts",import:"./dist/openrouter.js"},"./native-shell":{types:"./dist/native-shell.d.ts",import:"./dist/native-shell.js"},"./page":{types:"./dist/page.d.ts",import:"./dist/page.js"},"./visual":{types:"./dist/visual.d.ts",import:"./dist/visual.js"}},scripts:{build:"tsup",prepack:"pnpm run build",typecheck:"tsc --noEmit",lint:"node ../../scripts/ci/lint.mjs --workspace packages/sdk"},dependencies:{"@ai-sdk/provider":"4.0.26","@types/json-schema":"7.0.15","css-tree":"^3.2.1","dom-mutator":"0.7.0",dompurify:"^3.4.15",zod:"4.6.6"},devDependencies:{"@indiana/contracts":"workspace:*","@openrouter/sdk":"^1.4.25","@types/css-tree":"^3.2.0",ai:"7.0.136",tsup:"^8.5.1",typescript:"^5.9.3","whatwg-url-minimum":"0.2.0"},peerDependencies:{"@openrouter/sdk":"^1.4.25"},peerDependenciesMeta:{"@openrouter/sdk":{optional:!0}}};var U=Symbol("IndianaNoContent");function Z(p,H,q=URL){let l=p.configuration?.scope,R=p.scope??(l&&{projectId:l.projectId,environment:l.environment}),s=R?b.parse(R):void 0;if(s&&l&&(s.projectId!==l.projectId||s.environment!==l.environment))throw new e("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=new q(p.baseUrl??L);if(a.username||a.password||a.search||a.hash)throw new e("INVALID_URL","baseUrl must not contain credentials, query, or fragment");if(a.protocol!=="https:"&&!(a.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(a.hostname)))throw new e("INVALID_URL","Use HTTPS, or HTTP on localhost during development");let V=p.fetch??globalThis.fetch.bind(globalThis),f=p.timeoutMs??1e4;if(!Number.isFinite(f)||f<1||f>12e4)throw new e("INVALID_TIMEOUT","timeoutMs must be between 1 and 120000");let h=null,u=0,m=null,g=new Set;function A(){u+=1,h=null,m=null;for(let i of g)i.abort();g.clear()}async function x(i,K={},I="POST",D={}){let d=D.installationDetach===!0;if(d&&(i!=="push/installations/detach"||I!=="POST"))throw new e("INVALID_REQUEST","Installation authority only detaches this installation");if(!h&&!d)throw new e("NOT_IDENTIFIED","Call identify with a server-issued customer token first");let E=u,o=new AbortController;d||g.add(o);let w=()=>!d&&E!==u?new e("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):new e("TIMEOUT","Indiana request timed out"),T,F=new Promise((n,r)=>{T=()=>r(w()),o.signal.addEventListener("abort",T,{once:!0})}),G=setTimeout(()=>o.abort(),f),X=async()=>{let n=await V(`${a.href.replace(/\/$/,"")}/api/v1/${i}`,{method:I,headers:{"Content-Type":"application/json",...d?{}:{Authorization:`Bearer ${h}`},[v]:S.current,[k]:M.version,...s?{"X-Indiana-Project":s.projectId,"X-Indiana-Environment":s.environment}:{}},body:I==="POST"?JSON.stringify(K):void 0,signal:o.signal,credentials:"omit",cache:"no-store",redirect:"error",...D.keepalive?{keepalive:!0}:{}});if(o.signal.aborted)throw w();let r;try{r=n.status===204?U:await n.json()}catch{throw o.signal.aborted?w():new e(n.ok?"INVALID_RESPONSE":"HTTP_ERROR","The gateway returned an unreadable response",n.status,n.headers.get("X-Request-Id")??void 0)}if(o.signal.aborted)throw w();if(!d&&E!==u)throw new e("IDENTITY_CHANGED","Customer identity changed while the request was in flight");if(!n.ok){let t=_.safeParse(r),c=t.success&&(!C.safeParse(t.data.error.code).success||j(t.data.error.code,n.status)),N=c?t.data.error.code:"HTTP_ERROR",O=P(N,n.status,{retryAfter:n.headers.get("Retry-After"),recovery:c?t.data.error.recovery:void 0,reason:c?t.data.error.reason:void 0});throw new e(N,c?t.data.error.message:"Indiana request failed",n.status,n.headers.get("X-Request-Id")??(t.success?t.data.requestId:void 0),{...O,...t.success&&t.data.error.retryable===!1?{retryable:!1}:{},...O.retryAfterSeconds===void 0&&t.success&&t.data.error.retryAfterSeconds!==void 0?{retryAfterSeconds:t.data.error.retryAfterSeconds}:{}})}if(n.headers.get(v)!==S.current)throw new e("PROTOCOL_MISMATCH","Response protocol does not match this SDK");if(s&&r!==U){let t=r&&typeof r=="object"&&"scope"in r?r:r&&typeof r=="object"&&"configuration"in r?r.configuration:null;if(!t||typeof t!="object"||!("scope"in t))throw new e("INVALID_RESPONSE","Response is missing its App/environment scope");let c=b.safeParse(t.scope);if(!c.success||c.data.projectId!==s.projectId||c.data.environment!==s.environment)throw new e("SCOPE_MISMATCH","Response scope does not match this SDK instance")}let y=n.headers.get("X-Indiana-Telemetry-Subject");if(y){if(!/^[a-f0-9]{64}$/.test(y))throw new e("INVALID_RESPONSE","Invalid telemetry identity");m!==y&&(m=y,H?.(m))}return r};try{return await Promise.race([X(),F])}catch(n){throw!d&&E!==u?new e("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):n instanceof e?n:new e(o.signal.aborted?"TIMEOUT":"NETWORK_ERROR",o.signal.aborted?"Indiana request timed out":"Unable to read the Indiana response")}finally{clearTimeout(G),o.signal.removeEventListener("abort",T),g.delete(o)}}return{subjectKey:()=>m,identify(i){if(!i.trim()||/\s/.test(i)||i.length>4096)throw new e("INVALID_TOKEN","A nonempty server-issued token is required");A(),h=i},reset:A,request:x}}export{Z as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as le,b as ue,d as de}from"./chunk-GRLMT5PR.js";import"./chunk-SSHUBTT3.js";import{Je as ae,Vg as re}from"./chunk-EJTBSGLV.js";import{a as u}from"./chunk-SOQO2RDZ.js";import{Hb as se}from"./chunk-LMR2TM3X.js";import{a as X}from"./chunk-DSPLGTQI.js";import"./chunk-OBYJWIRB.js";import"./chunk-EXCPE2XH.js";import"./chunk-RRII2DMC.js";import"./chunk-KQCTDXVD.js";function ce(e){let C=e.view;if(!C?.paywall)throw new u("INVALID_REQUEST","The current node is not a Paywall");let n=C.paywall.receiptId,P=C.nodeId,h=C.visit,o=C.paywall.resolution,k=o,s="document"in o?o:null;function v(i){if(!le(i,o))throw new u("INVALID_RESPONSE","The pinned Paywall binding changed")}let a=C.paywall.quote,R=C.paywall.operation,S=!1,T=new AbortController,l=C.paywall.purchaseRequestId,r=0,f=C.paywall.selectionGeneration??0,E=C.paywall.canReselect===!0,y=null,O=new Map,U=new Map;function G(i){if(i.purchase&&i.purchase.receiptId!==n)throw new u("INVALID_RESPONSE","Purchase receipt changed");let w=i.run.paywall;return i.purchase??(w?.receiptId===n?w:null)}function F(){if(S)throw new u("IDENTITY_CHANGED","Paywall presentation has closed")}function _(i,w,c){if(F(),w!==r||c!==void 0&&a?.operationId!==c)return!1;let I=f,d=i.run.paywall;if(d?.receiptId===n){if((d.selectionGeneration??0)<f)return!1;f=d.selectionGeneration??0,E=d.canReselect===!0,v(d.resolution)}let m=G(i),p=f>I,N=p?m?.quote??null:m?.quote??a,q=m?.operation??(N?.operationId===a?.operationId?R:null);return N&&q&&ue(q,{operationId:N.operationId},"Purchase operation changed"),d?.receiptId===n&&(k=d.resolution,s="document"in k?k:s?{...k,document:s.document,offering:s.offering}:null),(p||N?.operationId!==a?.operationId)&&(r++,d?.receiptId===n&&(l=d.purchaseRequestId)),a=N,R=de(R,q,!0),!0}function $(i,w,c){return new Promise((I,d)=>{let m=!1,p=()=>{clearTimeout(D),T.signal.removeEventListener("abort",J)},N=z=>{m||(m=!0,p(),I(z))},q=z=>{m||(m=!0,p(),d(z))},J=()=>q(new u("IDENTITY_CHANGED","Paywall presentation has closed")),D=setTimeout(()=>q(new u("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,c)),Math.max(0,w-Date.now()));T.signal.addEventListener("abort",J,{once:!0}),T.signal.aborted&&J(),i.then(N,q)})}function j(i){return new Promise(w=>{let c=()=>{clearTimeout(I),T.signal.removeEventListener("abort",c),w()},I=setTimeout(c,i);T.signal.addEventListener("abort",c,{once:!0}),T.signal.aborted&&c()})}async function A(i,w,c){F();let I=O.get(i);if(!I){let p=e.pendingCommands?.find(N=>N.requestId===i)??e.pendingCommand;if(p?.operation==="submit"&&p.requestId===i&&p.nodeId===P&&p.visit===h){w.type==="paywall_quote"&&p.input.type==="paywall_quote"&&p.input.predecessor&&!w.predecessor&&(w={...w,predecessor:p.input.predecessor});let N=re.parse(p),q=re.parse({...p,input:w});if(q.operation!=="submit"||N.operation!=="submit"||JSON.stringify(q.input)!==JSON.stringify(N.input))throw new u("CONFLICT","A restored purchase request cannot change its input");w=q.input,I=N,O.set(i,I)}}if(I){if(JSON.stringify(I.input)!==JSON.stringify(w))throw new u("CONFLICT","A purchase request cannot change its input")}else{let p=e.view;if(!p||p.nodeId!==P||p.visit!==h||p.paywall?.receiptId!==n)throw new u("PRECONDITION_FAILED","The Paywall visit has changed");I={operation:"submit",requestId:i,nodeId:P,visit:h,revision:p.revision,input:w},O.set(i,I)}let d=Date.now()+3e4,m=await $(e.submit(I),d,i);for(;m.run.pendingRequest?.requestId===i&&Date.now()<d&&!S&&(await j(Math.min(1e3,d-Date.now())),!(S||Date.now()>=d));)m=await $(e.resume(i),d,i);if(S)throw new u("IDENTITY_CHANGED","Paywall presentation has closed");if(m.run.pendingRequest?.requestId===i)throw new u("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,i);if(!_(m,c,w.type==="paywall_confirm"||w.type==="paywall_cancel"?w.operationId:void 0))throw new u("PRECONDITION_FAILED","The purchase selection has changed")}async function Q(i){if(!a)throw new u("INVALID_REQUEST","A quoted purchase is required");let w=`${i}:${a.operationId}`,c=U.get(w);if(!c){let I=i==="confirm"?"paywall_confirm":"paywall_cancel",d=e.pendingCommands?.find(m=>m.operation==="submit"&&m.input.type===I&&"operationId"in m.input&&m.input.operationId===a.operationId)??e.pendingCommand;c=d?.operation==="submit"&&d.input.type===I&&"operationId"in d.input&&d.input.operationId===a.operationId?d.requestId:crypto.randomUUID(),U.set(w,c)}if(await A(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.operationId},r),!R)throw new u("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(R)}return{get view(){return structuredClone(s)},get quote(){return a?structuredClone(a):null},get operation(){return R?structuredClone(R):null},get webViewUrl(){return e.webViewUrl},get canReselect(){return E},async refresh(){F();let i=r,w=await e.get();if(_(w,i),w.run.paywall?.receiptId!==n)throw new u("PRECONDITION_FAILED","Paywall presentation has changed");if(!s){if("document"in k||!e.resolvePaywall)throw new u("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await e.resolvePaywall(k);F(),v(c),s={...k,document:c.document,offering:c.offering}}return structuredClone(s)},preview(i){if(!s)return Promise.reject(new u("PRECONDITION_FAILED","Load the Paywall presentation first"));if(l&&l!==i.requestId&&(y||!E))return Promise.reject(new u("COMMAND_PENDING","Retry the original purchase before starting another"));if(l===i.requestId&&y)return y;let w=s.document.buttons[i.actionId],c=w?.type==="checkout"?ae(w.product,i.selection,s.capabilities):null;if(!c)return Promise.reject(new u("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let I=l!==i.requestId&&f>0?{operationId:a?.operationId??null,generation:f}:void 0;if(I&&(!E||f<=0))return Promise.reject(new u("COMMAND_PENDING","Original purchase requires authoritative termination"));l!==i.requestId&&r++;let d=r;l=i.requestId;let m=(async()=>{if(await A(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}},d),!a)throw new u("INVALID_RESPONSE","The accepted quote is missing");return structuredClone(a)})();return y=m,m.then(()=>{y===m&&(y=null)},p=>{y===m&&(y=null),l===i.requestId&&e.pendingCommand?.requestId!==i.requestId&&p instanceof u&&p.status!==void 0&&p.status<500&&![401,425].includes(p.status)&&(l=null)}),m},confirm:()=>Q("confirm"),cancel:()=>Q("cancel"),async read(){if(F(),!a)throw new u("INVALID_REQUEST","A quoted purchase is required");let i=a.operationId,w=r,c=e.pendingCommands?.find(p=>p.operation==="submit"&&(p.input.type==="paywall_confirm"||p.input.type==="paywall_cancel")&&p.input.operationId===i)??e.pendingCommand;c?.operation==="submit"&&(c.input.type==="paywall_confirm"||c.input.type==="paywall_cancel")&&c.input.operationId===i&&await e.settle?.(c.requestId);let I=await e.get(void 0,{receiptId:n,operationId:i});F();let d=G(I);if(d?.quote&&d.quote.operationId!==i||d?.operation&&d.operation.operationId!==i)throw new u("INVALID_RESPONSE","Purchase operation changed");let m=_(I,w,i)?R:d?.operation;if(!m)throw new u("INVALID_RESPONSE","The current purchase result is missing");return structuredClone(m)},destroy(){S=!0,T.abort(),O.clear(),U.clear()}}}function pe(e){let C=new Set,n=new Set,P=null;function h(o){if(e.reviewing||C.has(o)||n.has(o)||e.stopped)return;n.add(o);let k=async()=>{if(e.reviewing||e.stopped||e.key!==o){n.delete(o);return}if(e.busy||e.client.pendingCommand){setTimeout(()=>{k()},250);return}let s=(async()=>{let a=e.client.view,R=e.expected(),S=R.requestId,T=!1;try{await e.client.submit({operation:"shown",...R})}catch(l){if(!(l instanceof u)||l.code!=="CONFLICT"||l.status!==409||e.client.pendingCommand)throw l;await e.client.get();let r=e.client.view;if(e.stopped||e.reviewing||e.key!==o||!r||!a||r.id!==a.id||r.source.versionId!==a.source.versionId||r.nodeId!==R.nodeId||r.visit!==R.visit||r.revision<=R.revision||r.stopped||!r.screen||!["running","waiting"].includes(r.status)||e.client.pendingCommand)throw l;let f=e.expected();S=f.requestId,await e.client.submit({operation:"shown",...f})}for(;!e.stopped&&e.key===o&&e.client.pendingCommand?.requestId===S;){if(!e.client.settle)throw new u("COMMAND_PENDING","The original display acknowledgement is still pending");await e.client.settle(S),T=!0,e.client.pendingCommand?.requestId===S&&await new Promise(l=>setTimeout(l,1500))}e.stopped||e.key!==o||(T&&await e.client.get(),!(e.stopped||e.key!==o)&&C.add(o))})();P=s;let v=()=>{P===s&&(P=null),n.delete(o)};s.then(v,a=>{v(),e.busy||e.fail(a)})};k()}return{report:h,get inFlight(){return P}}}function fe(e){let C={},n=new Map;async function P(h){let o=e.client.view,k=o?.screen,s=k?.customerData.nodes[h.nodeId];if(e.stopped||e.busy||!o||!k||!s)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(h.action)){let r=e.document,f=r?se(r,h.nodeId):null,E=f?.type==="customer_data"?f.data.outputs?.[h.action]:void 0;E&&k.outputs.includes(E)?await e.perform(()=>e.client.submit({operation:"submit",...e.expected(),input:{type:"screen",output:E,answers:e.answers,selection:h.value?{[h.nodeId]:h.value}:{}}})):await e.onIntent?.(h,o);return}let a=h.action.startsWith("sources_")?s.resources.find(r=>r.key===h.value):null;if(h.action.startsWith("sources_")&&!a)throw new u("INVALID_REQUEST","Choose a current resource");let R=`${o.visit}:${h.nodeId}:${a?.key??""}`,S=n.get(R)??[null],l=C[h.nodeId]??{page:1,after:null,filter:"all",...a?{resourceKey:a.key}:{}};if(h.action==="filter"){let r=h.value;if(!r||!(s.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(r))throw new u("INVALID_REQUEST","Unknown data filter");l={page:1,after:null,filter:r},S.splice(0,S.length,null)}else if(h.action==="next"||h.action==="sources_next"){let r=a?.sources.at(-1),f=a?r?{kind:"ledger",cursor:{at:r.detail[0],id:r.id,type:"source"}}:null:k.dataCursors[h.nodeId];if(!f||!a&&!s.hasNext)return;S[l.page]=f,l={...l,page:l.page+1,after:f}}else if(h.action==="previous"||h.action==="sources_previous"){if(l.page<=1)return;l={...l,page:l.page-1,after:S[l.page-2]??null}}n.set(R,S),C={...C,[h.nodeId]:l},await e.perform(()=>e.client.get({nodeId:o.nodeId,visit:o.visit,revision:o.revision,components:C}))}return{get queries(){return C},intent:P,reset(){C={},n.clear()}}}function we(e){let{doc:C,holder:n,reviewHolder:P,mountScreenPreview:h}=e,o=!1,k,s=0,v=null,a="",R=new Map,S=r=>r?`${r.id}:${r.nodeId}:${r.visit}:${r.revision}:${r.paywall?.quote?.operationId??""}`:"";async function T(r){if(e.stopped||!e.client.review)return;o||(a=S(e.client.view),R.set(a,structuredClone(e.answers))),o=!0,k=r,n.hidden=!0,e.suspend(!0),P.hidden=!1;let f=++s;try{let E=await e.client.review(r);if(e.stopped||f!==s||!o)return;if(!E.review)throw new u("INVALID_RESPONSE","Historical projection is missing");v?.destroy(),v=null,P.replaceChildren();let y=E.run.locale.startsWith("zh"),O=C.createElement("p");O.textContent=y?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",P.append(O);for(let[F,_]of E.review.pages.entries()){let $=C.createElement("button");$.type="button",$.textContent=y?`\u7B2C ${F+1} \u9875`:`Page ${F+1}`,$.onclick=()=>{T(_.receiptId)},P.append($)}if(E.review.page){let F=E.review.page,_=C.createElement("div");if(_.inert=!0,P.append(_),v=h(_,{mode:"live",rendererUrl:e.client.webViewUrl,title:F.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{},onEscape:()=>{l()}}),v.update(F.document,E.run.locale,{serverInput:{bindings:F.inputs,answers:F.answers,values:F.values}}),await v.ready,e.stopped||f!==s||!o)return}let U=y?{issued:"\u5DF2\u9886\u53D6",reserved:"\u5DF2\u9884\u7559",redeemed:"\u5DF2\u4F7F\u7528",expired:"\u5DF2\u8FC7\u671F",revoked:"\u5DF2\u64A4\u9500",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},G=y?{pending:"\u5904\u7406\u4E2D",complete:"\u5DF2\u5B8C\u6210",cancelled:"\u5DF2\u53D6\u6D88",failed:"\u5931\u8D25",unknown:"\u72B6\u6001\u5F85\u786E\u8BA4"}:{pending:"Processing",complete:"Completed",cancelled:"Cancelled",failed:"Failed",unknown:"Status unconfirmed"};for(let F of[...E.review.coupons.map((_,$)=>`${y?"\u4F18\u60E0\u5238":"Coupon"} ${$+1}: ${U[_.status]}`),...E.review.purchases.map((_,$)=>`${y?"\u8D2D\u4E70":"Purchase"} ${$+1}: ${G[_.status]}`)]){let _=C.createElement("p");_.textContent=F,P.append(_)}e.client.view&&await e.enqueue(e.client.view)}catch(E){if(f!==s||e.stopped)return;v?.destroy(),v=null,P.replaceChildren(),e.fail(E)}}async function l(){if(!o||e.stopped||!e.client.review)return;let r=++s;try{if(await e.client.review(),e.stopped||r!==s)return;o=!1,s++,v?.destroy(),v=null,P.replaceChildren(),P.hidden=!0,n.hidden=!1;let f=e.client.view;S(f)!==a?(R.set(a,structuredClone(e.answers)),e.resetScreen()):(R.delete(a),e.suspend(!1)),f&&await e.enqueue(f)}catch(f){if(r!==s||e.stopped)return;v?.destroy(),v=null,P.replaceChildren(),e.fail(f)}}return{get active(){return o},get receipt(){return k},open:T,exit:l,get drafts(){return new Map([...R].map(([r,f])=>[r,structuredClone(f)]))},stop(){o=!1,s++,v?.destroy(),v=null,P.replaceChildren(),P.hidden=!0,n.hidden=!1}}}async function Ue(e,C){let n=C,{mountScreenPreview:P}=await import("./screen-renderer-DLXDQQKK.js"),{showPaywall:h}=await import("./paywall-734GWAS4.js"),o=e.ownerDocument,k=o.activeElement,s=o.createElement("section"),v=o.createElement("div"),a=o.createElement("div"),R=o.createElement("div"),S=o.createElement("button");R.hidden=!0,S.type="button";let T=o.createElement("p"),l=o.createElement("p"),r=o.createElement("button"),f=o.createElement("button"),E=o.createElement("button"),y=o.createElement("dialog");s.dataset.indianaFunnel="",s.setAttribute("aria-busy","false"),s.style.cssText="box-sizing:border-box;width:100%;min-width:0;font:14px/1.5 system-ui,sans-serif;color:#172033;background:#fff",a.style.cssText="display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:12px 20px",T.setAttribute("role","status"),l.setAttribute("role","alert"),l.hidden=!0,r.type=f.type=E.type="button",a.append(r,T,l,E,S,f),s.append(v,R,a),e.append(s);let O=null,U=null,G=null,F="",_="",$="",j="",A=!1,Q=0,i=!1,w="",c=null,I=Promise.resolve(),d=null,m=null,p=new Set,N={},q=(t,g=null)=>{A||(m=g,l.textContent=t instanceof Error?t.message:"Request failed",l.hidden=!1,E.hidden=n.client.pendingCommand===null,X(n.onError,t))};function J(){let t=n.client.view;if(!t)throw new u("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let D=we({client:n.client,doc:o,holder:v,reviewHolder:R,mountScreenPreview:P,get stopped(){return A},get answers(){return N},suspend(t){U?.setSuspended(t)},resetScreen(){F="",_=""},enqueue:W,fail:q}),z=pe({client:n.client,expected:J,fail:q,get stopped(){return A},get reviewing(){return D.active},get key(){return F},get busy(){return Q}}),Z=fe({client:n.client,expected:J,perform:B,onIntent:n.onCustomerDataIntent,get stopped(){return A},get busy(){return Q},get document(){return O?.document},get answers(){return N}});async function B(t,g=!1){if(!(Q&&!g||A||D.active&&!g)){Q++,s.setAttribute("aria-busy","true"),l.hidden=!0,m=null;try{if(!g&&z.inFlight){let b=n.client.view;await z.inFlight;let L=n.client.view;if(!b||!L||L.id!==b.id||L.nodeId!==b.nodeId||L.visit!==b.visit||L.stopped||!["running","waiting"].includes(L.status))throw new u("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}if(A)return;let M=await t();A||await W(n.client.view??M.run)}catch(M){q(M,n.client.pendingCommand?.requestId??null)}finally{Q=Math.max(0,Q-1),s.setAttribute("aria-busy",String(Q>0)),A||(E.hidden=n.client.pendingCommand===null,r.disabled=Q>0||!!n.client.pendingCommand||!n.client.view?.canBack)}}}function x(){c&&clearTimeout(c),!(A||!G||!["running","waiting"].includes(G.status)&&!n.client.pendingCommand)&&(c=setTimeout(()=>{c=null,oe().finally(x)},G.pendingRequest||n.client.pendingCommand?1500:5e3))}async function oe(){if(!(A||i||Q)){if(D.active){await D.open(D.receipt);return}i=!0;try{let t=n.client.pendingCommand;t&&n.client.settle&&await n.client.settle(t.requestId);let g=n.client.view,M=Z.queries,b=await n.client.get(g?.screen&&Object.keys(M).length?{nodeId:g.nodeId,visit:g.visit,revision:g.revision,components:M}:void 0);!A&&M===Z.queries&&await W(n.client.view??b.run)}catch(t){q(t)}finally{i=!1}}}function me(t){let g=t.screen?.presentation;if(!g||g.type==="inline"){y.open&&y.close(),s.parentElement!==e&&e.append(s);return}s.parentElement!==y&&(y.append(s),e.append(y));let M={sm:420,md:640,lg:900};y.style.cssText=`padding:0;border:0;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);overflow:auto;width:${"size"in g?M[g.size]+"px":"100vw"}`,y.setAttribute("aria-label",O?.document?.name??t.screen?.content.document.name??"Funnel"),y.open||y.showModal()}async function ye(t){if(A)return;G=t,m&&n.client.pendingCommand?.requestId!==m&&(l.hidden=!0,m=null);let g=t.locale.startsWith("zh");if(S.textContent=g?"\u56DE\u770B":"History",S.hidden=!n.client.review,r.textContent=D.active?g?"\u8FD4\u56DE\u5F53\u524D":"Return to current":g?"\u8FD4\u56DE":"Back",f.textContent=g?"\u5173\u95ED":"Close",E.textContent=g?"\u91CD\u8BD5":"Retry",r.disabled=!D.active&&(Q>0||!!n.client.pendingCommand||!t.canBack),E.hidden=n.client.pendingCommand===null,T.textContent=t.pendingRequest?g?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?g?"\u7B49\u5F85\u4E2D":"Waiting":"",w!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(w=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,X(n.onState,structuredClone(t))),t.stopped||n.client.configurationReady===!1){D.stop(),O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F="",_="",j="",y.open&&y.close(),s.hidden=!0,x();return}if(s.hidden=!1,D.active){x();return}let M=t.screen||t.paywall?`${t.id}:${t.nodeId}:${t.visit}`:"";if(M!==F&&(O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F=M,_="",j="",N={...t.answers},Z.reset()),me(t),t.screen){let L=t.screen.content;O||(O=P(v,{mode:"live",rendererUrl:n.client.webViewUrl,title:L.document.name,onAction(H,te={},ie={}){if(D.active)return;N={...N,...ie};let Ie=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:ne})=>Object.hasOwn(N,ne)).map(({variable:ne})=>[ne,N[ne]]));B(()=>n.client.submit({operation:"submit",...J(),input:{type:"screen",output:H,answers:Ie,selection:te}}))},onAnswers:H=>{D.active||(N={...N,...H})},onCustomerDataIntent:H=>{D.active||Z.intent(H).catch(q)},onEscape:()=>{D.active||K()},onError:H=>q(new Error(H)),onRendered:()=>z.report(M)}));let V={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:N,values:t.screen.values}},Y=JSON.stringify([L,t.locale,V.parameters,t.screen.inputs,t.screen.values]);if(Y!==_)O.update(L.document,t.locale,V),_=Y,$=JSON.stringify(V.capabilities),j=JSON.stringify(V.customerData);else{let H=JSON.stringify(V.capabilities);H!==$&&(O.updateCapabilities(V.capabilities),$=H),JSON.stringify(V.customerData)!==j&&(O.updateCustomerData(V.customerData),j=JSON.stringify(V.customerData))}await O.ready}else if(t.paywall&&!U){let L=await h(v,{canInteract:()=>!D.active&&!A,start:async()=>ce(n.client),onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resolveOfferId:n.resolveOfferId,onEvent:n.onEvent,onOpenUrl:V=>n.onOpenUrl?n.onOpenUrl({receiptId:t.paywall.receiptId,url:V,openIn:"same_window"}):o.defaultView?.location.assign(V),onAction:async V=>{if(D.active)return;let Y=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision,input:{type:"screen",output:V,answers:{}}});await W(n.client.view??Y.run)},onError:q,onDismiss:()=>{!D.active&&!A&&n.client.view?.visit===t.visit&&K()}});A?L.host?.destroy():(U=L.host,U?.setSuspended(D.active)),z.report(M)}let b=t.instruction;if(b&&(b.type==="open_url"||b.type==="event")&&!p.has(b.receiptId)){let L=o.createElement("button");L.type="button",L.textContent=b.type==="open_url"?`${g?"\u524D\u5F80":"Continue to"} ${new URL(b.url).host}`:g?"\u7EE7\u7EED":"Continue",L.onclick=()=>{let V=J(),Y=b.type==="open_url"&&!n.onOpenUrl&&b.openIn==="new_window"?he(b.url):null;B(async()=>{let H="success";if(b.type==="open_url")if(n.onOpenUrl)try{H=await n.onOpenUrl({receiptId:b.receiptId,url:b.url,openIn:b.openIn})===!1?"failed":"opened"}catch(ie){X(n.onError,ie),H="failed"}else H=b.openIn==="new_window"&&!Y?"failed":"opened";if(b.type==="event"){if(!n.onEvent)throw new u("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(b.event)}if(A||n.client.view?.nodeId!==V.nodeId||n.client.view.visit!==V.visit)throw new u("PRECONDITION_FAILED","The client action visit changed");let te=await n.client.submit({operation:"submit",...V,input:{type:"client_action",receiptId:b.receiptId,outcome:H}});return p.add(b.receiptId),b.type==="open_url"&&!n.onOpenUrl&&b.openIn==="same_window"&&o.defaultView?.location.assign(b.url),te})},v.replaceChildren(L)}!t.pendingRequest&&t.status==="completed"&&!p.has(`complete:${t.id}`)&&(p.add(`complete:${t.id}`),X(n.onComplete,structuredClone(t))),x()}function he(t){let g=o.defaultView?.open(t,"_blank")??null;return g&&(g.opener=null),g}function W(t){return I=I.catch(()=>{}).then(()=>ye(t)),I}let ve=n.client.subscribe(t=>{n.client.configurationReady===!1&&(s.hidden=!0,O?.destroy(),O=null,U?.destroy(),U=null,v.replaceChildren(),F="",_="",j="",y.open&&y.close()),W(t).catch(q)}),ge=n.client.subscribeError?.(q);function K(){return d||(A?Promise.resolve():n.client.view&&!["running","waiting"].includes(n.client.view.status)?(ee(),Promise.resolve()):(d=B(()=>n.client.submit({operation:"close",...J()}),!0).then(()=>{n.client.view?.status==="closed"&&ee()}).finally(()=>{d=null}),d))}function ee(){A||(A=!0,c&&clearTimeout(c),ve(),ge?.(),O?.destroy(),D.stop(),U?.destroy(),y.close(),y.remove(),s.remove(),k instanceof HTMLElement&&k.isConnected&&k.focus(),X(n.onDismiss,G?structuredClone(G):null))}r.onclick=()=>{if(D.active){D.exit();return}B(()=>n.client.submit({operation:"back",...J()}))},S.onclick=()=>{D.open()},f.onclick=()=>{K()},E.onclick=()=>{B(()=>n.client.retry())},y.addEventListener("cancel",t=>{t.preventDefault(),K()});try{let t=await n.client.get();await W(n.client.view??t.run)}catch(t){throw ee(),t}return{destroy:ee,refresh:oe,review:D.open,exitReview:D.exit,get unappliedDrafts(){return D.drafts}}}export{Ue as showFunnelRun};
|