@tinkerlandai/longplay-sdk 0.10.30 → 0.10.31

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.
@@ -1 +1 @@
1
- import{a as kn,b as rn,c as on,d as _e,e as Fn,f as We,h as Dn}from"./chunk-UWYL2QCF.js";import{c as Cn,d as Pn,e as Rn,f as Ae,g as Be,h as En,i as je,k as qn}from"./chunk-RBMOWJGE.js";import{$ as Qe}from"./chunk-ITVSLSRM.js";import{a as ze,e as gn,f as vn,g as hn,h as In,i as bn}from"./chunk-B3KFE57L.js";import{b as wn}from"./chunk-ACFQLHJR.js";import{R as fn,qa as yn}from"./chunk-WRUW2UIJ.js";import{a as P}from"./chunk-HJLGRW4A.js";import{b as Sn,e as On}from"./chunk-SLUA7ABW.js";import{d as Tn}from"./chunk-XRR5X74T.js";import{a as le}from"./chunk-DSPLGTQI.js";import{b as mn}from"./chunk-6BTJNSQQ.js";var Te=new WeakMap;function Bn(n){let g=n.view,w=g?.paywall?.resolution;if(!g||!["running","waiting"].includes(g.status)||g.stopped||!w||"document"in w||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(w);if(Te.get(n)?.key===e)return;let p=JSON.parse(e),D=n.identitySignal,a=Promise.resolve().then(async()=>{D?.throwIfAborted();let s=await n.resolvePaywall(p);return D?.throwIfAborted(),s}),S={key:e,content:a};return Te.set(n,S),a.catch(()=>{}),()=>{Te.get(n)===S&&Te.delete(n)}}function Nn(n,g){let w=Te.get(n);return Te.delete(n),w?.key===JSON.stringify(g)?w.content:n.resolvePaywall(g)}async function An(n){let{session:g,load:w}=Qn(n);try{return await w(),g}catch(e){throw g.destroy(),e}}function Qn(n){let g=n.view;if(!g?.paywall)throw new P("INVALID_REQUEST","The current node is not a Paywall");let w=g.paywall.receiptId,e=g.nodeId,p=g.visit,D=g.paywall.resolution,a=g.paywall,S="document"in D?{document:D.document,offering:D.offering,capabilities:D.capabilities}:null;function s(){let i=a.resolution;return"document"in i?i:S&&{...i,document:S.document,offering:S.offering,capabilities:gn(i.capabilities,S.capabilities)}}function v(i){if(!vn(i,D))throw new P("INVALID_RESPONSE","The pinned Paywall binding changed")}let u=!1,q=new Set,A=null;function V(){let i=s();if(i&&!u)for(let l of q)le(l,structuredClone(i))}async function k(){J();let i=s();if(i)return structuredClone(i);if(!A){let l=(async()=>{if("document"in a.resolution||!n.resolvePaywall)throw new P("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await Nn(n,a.resolution);return J(),v(c),S={document:c.document,offering:c.offering,capabilities:c.capabilities},V(),s()})();A=l;let o=()=>{A===l&&(A=null)};l.then(o,o)}return A.then(l=>structuredClone(l))}let d=new AbortController,F=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_quote")?.requestId??g.paywall.purchaseRequestId,R=0,M=null,C=new Set,H=null,h=new Map;function _(i){if(i.purchase&&i.purchase.receiptId!==w)throw new P("INVALID_RESPONSE","Purchase receipt changed");let l=i.run.paywall;return i.purchase??(l?.receiptId===w?l:null)}function J(){if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed")}function z(i,l,o){if(J(),l!==R||o!==void 0&&a.quote?.operationId!==o)return!1;let c=a.selectionGeneration??0,y=i.run.paywall;if(y?.receiptId===w){if((y.selectionGeneration??0)<(a.selectionGeneration??0))return!1;v(y.resolution)}let I=_(i),B=y?.receiptId===w&&(y.selectionGeneration??0)>c,G=B?I?.quote??null:I?.quote??a.quote,b=I?.operation??(G?.operationId===a.quote?.operationId?a.operation:null);return G&&b&&hn(b,{operationId:G.operationId},"Purchase operation changed"),(B||G?.operationId!==a.quote?.operationId)&&(R++,y?.receiptId===w&&(F=y.purchaseRequestId)),y?.canReselect===!0&&y.purchaseRequestId===H&&!(n.pendingCommands??[n.pendingCommand]).some($=>$?.requestId===H)&&(H=null),a={...a,...y?.receiptId===w?y:{},quote:G,operation:bn(a.operation,b,!0)},V(),!0}function L(i,l,o){return new Promise((c,y)=>{let I=!1,B=()=>{clearTimeout(Re),d.signal.removeEventListener("abort",$)},G=Ee=>{I||(I=!0,B(),c(Ee))},b=Ee=>{I||(I=!0,B(),y(Ee))},$=()=>b(new P("IDENTITY_CHANGED","Paywall presentation has closed")),Re=setTimeout(()=>b(new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o)),Math.max(0,l-Date.now()));d.signal.addEventListener("abort",$,{once:!0}),d.signal.aborted&&$(),i.then(G,b)})}function de(i){return new Promise(l=>{let o=()=>{clearTimeout(c),d.signal.removeEventListener("abort",o),l()},c=setTimeout(o,i);d.signal.addEventListener("abort",o,{once:!0}),d.signal.aborted&&o()})}function Y(i,l){J();let o=h.get(i)??n.pendingCommands?.find(I=>I.requestId===i)??n.pendingCommand;if(o?.operation==="submit"&&o.requestId===i&&o.nodeId===e&&o.visit===p){l.type==="paywall_quote"&&o.input.type==="paywall_quote"&&o.input.predecessor&&!l.predecessor&&(l={...l,predecessor:o.input.predecessor});let I=Qe.parse(o),B=Qe.parse({...o,input:l});if(I.operation!=="submit"||B.operation!=="submit"||JSON.stringify(I.input)!==JSON.stringify(B.input))throw new P("CONFLICT","A purchase request cannot change its input");return h.set(i,I),I}let c=n.view;if(!c||c.nodeId!==e||c.visit!==p||c.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","The Paywall visit has changed");let y=Qe.parse({operation:"submit",requestId:i,nodeId:e,visit:p,revision:c.revision,input:structuredClone(l)});if(y.operation!=="submit")throw new P("INVALID_REQUEST","A purchase submission is required");return h.set(i,y),y}async function ce(i,l){J();let{requestId:o,input:c}=i,y=Date.now()+3e4;C.add(o);try{let I=await L(n.submit(i),y,o);for(;I.run.pendingRequest?.requestId===o&&Date.now()<y&&!u&&(await de(Math.min(1e3,y-Date.now())),!(u||Date.now()>=y));)I=await L(n.resume(o),y,o);if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed");if(I.run.pendingRequest?.requestId===o)throw new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o);if(!z(I,l,c.type==="paywall_confirm"||c.type==="paywall_cancel"?c.operationId:void 0))throw new P("PRECONDITION_FAILED","The purchase selection has changed");H===o&&(H=null)}catch(I){if(H=o,c.type==="paywall_quote"&&n.settle&&!u&&I instanceof P&&I.status!==void 0&&![401,425].includes(I.status)&&!I.retryable&&I.recovery!=="recover_operation")try{if((await L(n.settle(o),y,o)).settlement?.state==="settled"){let G=await L(n.get(),y,o);z(G,l)&&G.run.paywall?.purchaseRequestId===o&&a.canReselect===!0&&h.delete(o)}}catch{}throw I instanceof P&&I.code==="COMMAND_PENDING"&&I.status===void 0&&h.delete(o),I}finally{C.delete(o)}}async function re(i){if(!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let l=i==="confirm"?"paywall_confirm":"paywall_cancel",o=[...h.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(y=>y.operation==="submit"&&y.input.type===l&&"operationId"in y.input&&y.input.operationId===a.quote.operationId),c=o?.operation==="submit"&&o.input.type===l&&"operationId"in o.input&&o.input.operationId===a.quote.operationId?o.requestId:crypto.randomUUID();if(await ce(Y(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.quote.operationId}),R),!a.operation)throw new P("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(a.operation)}let T={get view(){return structuredClone(s())},get quote(){return a.quote?structuredClone(a.quote):null},get operation(){return a.operation?structuredClone(a.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return a.canReselect===!0&&H===null},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),l=n.pendingPurchase;if(l&&(l.receiptId!==w||l.operationId!==a.quote?.operationId))return{type:"recover",operationId:l.operationId,requestId:i[0]?.requestId??null};let o=ze({quote:a.quote,operation:a.operation,requestId:i[0]?.requestId??H??F,pending:C.size>0||i.length>0||H!==null,destroyed:u,canReselect:a.canReselect});return o.type==="recover"&&o.requestId===null&&!u&&n.hasDurableJournal===!0&&!a.quote&&!a.operation&&(a.selectionGeneration??0)===0&&!l&&!i.length&&!C.size&&!F?{type:"native",operationId:null}:o},get pendingCancellation(){return!u&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_cancel"&&i.input.operationId===a.quote?.operationId)},subscribe(i){return u?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){J();let i=R,l=await n.get();if(z(l,i),l.run.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","Paywall presentation has changed");return k()},preview(i){let l=s();if(!l)return Promise.reject(new P("PRECONDITION_FAILED","Load the Paywall presentation first"));if(F&&F!==i.requestId&&(M||a.canReselect!==!0))return Promise.reject(new P("COMMAND_PENDING","Retry the original purchase before starting another"));let o=l.document.buttons[i.actionId],c=o?.type==="checkout"?wn(o.product,i.selection,l.capabilities):null;if(!c)return Promise.reject(new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let y=yn(l.document.screen,c,i.selection,l.capabilities),I=F!==i.requestId&&(a.selectionGeneration??0)>0?{operationId:a.quote?.operationId??null,generation:a.selectionGeneration??0}:void 0;if(I&&a.canReselect!==!0)return Promise.reject(new P("COMMAND_PENDING","Original purchase requires authoritative termination"));let B;try{B=Y(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...Object.keys(y).length?{featureQuantities:y}:{},...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch($){return Promise.reject($)}if(F===i.requestId&&M)return M;F!==i.requestId&&R++;let G=R;F=i.requestId;let b=(async()=>{if(await ce(B,G),!a.quote)throw new P("INVALID_RESPONSE","The accepted quote is missing");return In(a.quote,{productVersionId:c,featureQuantities:y},"The selected purchase changed"),structuredClone(a.quote)})();return M=b,b.then(()=>{M===b&&(M=null)},$=>{M===b&&(M=null),F===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&$ instanceof P&&$.status!==void 0&&$.status<500&&![401,425].includes($.status)&&(F=null)}),b},confirm:()=>re("confirm"),cancel:()=>re("cancel"),async read(){if(J(),!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let i=a.quote.operationId,l=R,o=n.pendingCommands?.find(G=>G.operation==="submit"&&(G.input.type==="paywall_confirm"||G.input.type==="paywall_cancel")&&G.input.operationId===i)??n.pendingCommand;o?.operation==="submit"&&(o.input.type==="paywall_confirm"||o.input.type==="paywall_cancel")&&o.input.operationId===i&&await n.settle?.(o.requestId);let c=await n.get(void 0,{receiptId:w,operationId:i});J();let y=_(c);if(y?.quote&&y.quote.operationId!==i||y?.operation&&y.operation.operationId!==i)throw new P("INVALID_RESPONSE","Purchase operation changed");let I=z(c,l,i),B=I?a.operation:y?.operation;if(!B)throw new P("INVALID_RESPONSE","The current purchase result is missing");return I&&C.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(H=null),structuredClone(B)},destroy(){u=!0,E(),q.clear(),d.abort(),h.clear()}},E=n.subscribe(i=>{u||i.nodeId!==e||i.visit!==p||i.paywall?.receiptId!==w||(i.paywall.selectionGeneration??0)<(a.selectionGeneration??0)||(v(i.paywall.resolution),a={...a,resolution:i.paywall.resolution},V())});return{session:T,load:k}}function _n(n){let g=new Set,w=new Set,e=null;async function p(s,v){let u=!1;for(;!n.stopped&&n.key===s&&n.client.pendingCommand?.requestId===v;){if(!n.client.settle)throw new P("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(v),u=!0,n.client.pendingCommand?.requestId===v&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==s||(u&&await n.client.get(),!(n.stopped||n.key!==s)&&g.add(s))}function D(s,v){e=v;let u=()=>{e===v&&(e=null),w.delete(s)};return v.then(u,q=>{u(),n.busy||n.fail(q)}),v}function a(s){if(n.reviewing||g.has(s)||w.has(s)||n.stopped)return;w.add(s);let v=async()=>{if(n.reviewing||n.stopped||n.key!==s||g.has(s)){w.delete(s);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{v()},250);return}let u=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==s)return;if(n.client.pendingCommand){setTimeout(()=>{v()},250);return}}let q=n.client.view,A=n.expected(),V=A.requestId;try{await n.client.submit({operation:"shown",...A})}catch(k){if(!(k instanceof P)||k.code!=="CONFLICT"||k.status!==409||n.client.pendingCommand)throw k;await n.client.get();let d=n.client.view;if(n.stopped||n.reviewing||n.key!==s||!d||!q||d.id!==q.id||d.source.versionId!==q.source.versionId||d.nodeId!==A.nodeId||d.visit!==A.visit||d.revision<=A.revision||d.stopped||!d.screen&&(!d.paywall||d.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(d.status)||n.client.pendingCommand)throw k;let O=n.expected();V=O.requestId,await n.client.submit({operation:"shown",...O})}await p(s,V)})();D(s,u)};v()}function S(){if(e)return e;let s=n.client.pendingCommand;if(s?.operation!=="shown")return null;let v=n.key;return w.add(v),D(v,(async()=>{await n.client.retry(),await p(v,s.requestId)})())}return{report:a,settled:S,get inFlight(){return e}}}function Ln(n){let g={},w=new Map;async function e(p){let D=n.client.view,a=D?.screen,S=a?.customerData.nodes[p.nodeId];if(n.stopped||n.busy||!D||!a||!S)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(p.action)){let k=n.document,d=k?fn(k,p.nodeId):null,O=d?.type==="customer_data"?d.data.outputs?.[p.action]:void 0;O&&a.outputs.includes(O)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:O,answers:n.answers,selection:p.value?{[p.nodeId]:p.value}:{}}})):await n.onIntent?.(p,D);return}let v=p.action.startsWith("sources_")?S.resources.find(k=>k.key===p.value):null;if(p.action.startsWith("sources_")&&!v)throw new P("INVALID_REQUEST","Choose a current resource");let u=`${D.visit}:${p.nodeId}:${v?.key??""}`,q=w.get(u)??[null],V=g[p.nodeId]??{page:1,after:null,filter:"all",...v?{resourceKey:v.key}:{}};if(p.action==="filter"){let k=p.value;if(!k||!(S.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new P("INVALID_REQUEST","Unknown data filter");V={page:1,after:null,filter:k},q.splice(0,q.length,null)}else if(p.action==="next"||p.action==="sources_next"){let k=v?.sources.at(-1),d=v?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:a.dataCursors[p.nodeId];if(!d||!v&&!S.hasNext)return;q[V.page]=d,V={...V,page:V.page+1,after:d}}else if(p.action==="previous"||p.action==="sources_previous"){if(V.page<=1)return;V={...V,page:V.page-1,after:q[V.page-2]??null}}w.set(u,q),g={...g,[p.nodeId]:V},await n.perform(()=>n.client.get({nodeId:D.nodeId,visit:D.visit,revision:D.revision,components:g}))}return{get queries(){return g},intent:e,reset(){g={},w.clear()}}}function Vn(n){let{doc:g,holder:w,reviewHolder:e,mountScreenPreview:p}=n,D=!1,a,S=0,s=null,v="",u,q=new Map,A=d=>d?`${d.id}:${d.nodeId}:${d.visit}:${d.revision}:${d.paywall?.quote?.operationId??""}`:"";async function V(d){if(n.stopped||!n.client.review||D&&d===a&&u?.active)return;let O=!D||d!==a;D||(v=A(n.client.view),q.set(v,structuredClone(n.answers))),D=!0,a=d,w.hidden=!0,n.suspend(!0),e.hidden=!1;let F=++S;O&&(u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),u=Be(e,n.loadingOptions,"funnel",()=>{k()}));let R=O?u:void 0;try{if(R?.start(!1,n.client.view?.locale),F!==S||n.stopped)return;let M=n.client.review(d),C=await(R?.wait(M,Ae)??M);if(n.stopped||F!==S||!D)return;if(!C.review)throw new P("INVALID_RESPONSE","Historical projection is missing");s?.destroy(),s=null,R||e.replaceChildren();let H=g.createElement("div"),h=R?je(H,e):()=>{};e.append(H);let _=C.run.locale.startsWith("zh"),J=n.chrome;H.style.cssText=J.history;let z=g.createElement("p");z.textContent=_?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",z.style.cssText=J.historyTitle,H.append(z);let L=g.createElement("p");L.style.cssText=J.historyNote,L.textContent=C.review.pages.length?_?"\u9009\u62E9\u4E00\u9875\u67E5\u770B\u5F53\u65F6\u7684\u5185\u5BB9\uFF0C\u56DE\u770B\u4E0D\u4F1A\u6539\u52A8\u4EFB\u4F55\u4FE1\u606F\u3002":"Choose a page to see it as it was. Nothing here can be changed.":_?"\u8FD8\u6CA1\u6709\u53EF\u56DE\u770B\u7684\u9875\u9762\u3002":"There are no earlier pages yet.",H.append(L);let de=C.review.page?.receiptId,Y=g.createElement("div");Y.style.cssText=J.historyPages;for(let[T,E]of C.review.pages.entries()){let i=g.createElement("button");i.type="button",i.textContent=_?`\u7B2C ${T+1} \u9875`:`Page ${T+1}`;let l=de!==void 0&&E.receiptId===de;i.style.cssText=l?J.primary:J.secondary,l&&i.setAttribute("aria-current","page"),_e(i,()=>n.chrome.focus),i.onclick=()=>{V(E.receiptId)},Y.append(i)}if(Y.childElementCount&&H.append(Y),C.review.page){let T=C.review.page,E=g.createElement("div");E.inert=!0,E.style.cssText=J.historyPage,H.append(E),s=p(E,{mode:"live",rendererUrl:n.client.webViewUrl,title:T.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{F===S&&!n.stopped&&R?.present(h)},onError:l=>{if(F!==S||n.stopped)return;let o=new Error(l);R?.finish("error",o),s?.destroy(),s=null,H.remove(),n.fail(o)},onEscape:()=>{k()}});let i=s;if(i.update(T.document,C.run.locale,{serverInput:{bindings:T.inputs,answers:T.answers,values:T.values}}),await i.ready,n.stopped||F!==S||!D)return}let ce=_?{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"},re=g.createElement("div");re.style.cssText=J.historyRecords;for(let T of[...C.review.coupons.map((E,i)=>`${_?"\u4F18\u60E0\u5238":"Coupon"} ${i+1}: ${ce[E.status]}`),...C.review.purchases.map((E,i)=>`${_?"\u8D2D\u4E70":"Purchase"} ${i+1}: ${Dn(E.status,_)}`)]){let E=g.createElement("p");E.textContent=T,E.style.margin="0",re.append(E)}re.childElementCount&&H.append(re),C.review.page||R?.present(h),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(F!==S||n.stopped)return;R?.finish("error",M),s?.destroy(),s=null,e.replaceChildren(),n.fail(M)}}async function k(){if(!D||n.stopped||!n.client.review)return;let d=++S;u?.finish("dismissed");try{if(await n.client.review(),n.stopped||d!==S)return;D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1;let O=n.client.view;A(O)!==v?(q.set(v,structuredClone(n.answers)),n.resetScreen()):(q.delete(v),n.suspend(!1)),O&&await n.enqueue(O)}catch(O){if(d!==S||n.stopped)return;s?.destroy(),s=null,e.replaceChildren(),n.fail(O)}}return{get active(){return D},get receipt(){return a},open:V,exit:k,get drafts(){return new Map([...q].map(([d,O])=>[d,structuredClone(O)]))},stop(){D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1}}}function Mn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let g=n.client.pageExperiments.bind(n.client),w=!1,e=!1,p=0,D=!1,a=!1,S="",s=()=>{let h=n.client.view;return JSON.stringify([h?.id,h?.source.versionId,h?.visit,h?.revision,h?.status,h?.stopped])},v=new Map,u=new Set,q={},A=new Map,V=Sn(n.appManifestRelease),k=()=>{for(let h of v.values())h.effect.revert();v.clear()},d=()=>{k();for(let h of A.values())h();A.clear()};function O(h){if(w||u.has(h))return;u.add(h);let _=p;g(n.appManifestRelease,[h]).catch(J=>{u.delete(h),!w&&_===p&&le(n.onError,J)})}async function F(){if(w)return;S=s();let h=n.client.view;if(!h||h.stopped||!["running","waiting"].includes(h.status)){p++,d();return}if(document.visibilityState==="hidden")return;if(D){a=!0;return}D=!0;let _=++p,J=`${h.id}:${h.visit}:${h.revision}`,z=location.href;try{let[L,{applyVisualVariation:de}]=await Promise.all([g(n.appManifestRelease),import("./visual-dom-32PB6MMP.js")]),Y=n.client.view;if(w||_!==p||!Y||Y.stopped||!["running","waiting"].includes(Y.status)||`${Y.id}:${Y.visit}:${Y.revision}`!==J||location.href!==z)return;let ce=new Set,re=new Set;for(let T of L.assignments){let E=`${L.payload.environmentId}:${T.experimentKey}`;if(re.add(E),A.has(E)||A.set(E,On(E,q)),!!T.inExperiment)for(let i of L.payload.experiments){if(i.key!==T.experimentKey||!mn(location.href,i.urlPatterns??[]))continue;let l=i.meta?.findIndex(G=>G.key===T.variationKey)??-1,o=i.variations[l];if(!o?.renderGuard)continue;let c=T.receiptId+":"+i.changeId,y=JSON.stringify([T.variationKey,o]);ce.add(c);let I=v.get(c);if(I?.signature===y){I.effect.applied&&O(T.receiptId);continue}v.get(c)?.effect.revert(),v.delete(c);let B=de(o,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>O(T.receiptId),onError:G=>le(n.onError,G)});v.set(c,{signature:y,effect:B}),B.applied&&O(T.receiptId)}}for(let[T,E]of v)ce.has(T)||(E.effect.revert(),v.delete(T));for(let[T,E]of A)re.has(T)||(E(),A.delete(T))}catch(L){_===p&&d(),!w&&_===p&&le(n.onError,L)}finally{D=!1,a&&!w&&(a=!1,F())}}let R=n.client.subscribe(()=>{if(s()===S)return;S=s(),p++;let h=n.client.view;(!h||h.stopped||!["running","waiting"].includes(h.status))&&d(),e&&F()}),M=Tn(()=>{p++,d(),e&&F()}),C=()=>{p++,k()};document.addEventListener("visibilitychange",C);let H=We({document,run:async()=>{e&&await F()},delay:()=>e&&!w?15e3:void 0});return{async start(){e||w||(e=!0,await H.refresh())},refresh:F,destroy(){w=!0,p++,H.destroy(),document.removeEventListener("visibilitychange",C),R(),M(),d(),V.destroy()}}}var sn=5e3;async function zn(n,g,w){let e=g,[{mountScreenPreview:p},{showPaywall:D}]=await Promise.all([import("./screen-renderer-W5MP4KVG.js"),import("./paywall-L7M4VA3Z.js")]),a=e.client.identitySignal;e.signal?.throwIfAborted(),a?.throwIfAborted();let S=e.appManifestRelease?Mn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;S?.start();let s=n.ownerDocument,v=qn(s),u=s.createElement("section"),q=s.createElement("div"),A=s.createElement("div"),V=s.createElement("div"),k=s.createElement("button");V.hidden=!0,k.type="button";let d=s.createElement("p"),O=s.createElement("p"),F=s.createElement("button"),R=s.createElement("button"),M=s.createElement("button"),C=s.createElement("dialog"),H;u.dataset.indianaFunnel="",u.setAttribute("aria-busy","false"),d.setAttribute("role","status"),O.setAttribute("role","alert"),O.hidden=!0,F.type=R.type=M.type="button",A.append(F,k,d,O,M,R),u.append(q,V,A),n.append(u);let h=kn,_=rn(h),J="",z=(s.documentElement.lang||"").startsWith("zh"),L,de="",Y;for(let t of[F,k,M,R])_e(t,()=>_.focus);function ce(){let t=z?"\u5173\u95ED":"Close";R.parentElement===C?(R.textContent="\xD7",R.setAttribute("aria-label",t),Rn(R,h)):(R.textContent=t,R.removeAttribute("aria-label"),R.style.cssText=_.link+";margin-inline-start:auto")}function re(t){let r=t?.screen?.content.document.theme??h,f=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,R.parentElement===C]);f!==J&&(J=f,h=r,_=rn(h,R.parentElement===C),u.style.cssText=_.root+";min-width:0",A.style.cssText=_.bar,F.style.cssText=k.style.cssText=_.secondary,M.style.cssText=_.primary,d.style.cssText=_.status,O.style.cssText=_.alert,ce(),on(F))}function T(){A.hidden=F.hidden&&k.hidden&&M.hidden&&O.hidden&&!d.textContent&&(R.hidden||R.parentElement!==A),L?.responsive&&Y!==void 0&&L.setContentHeight(Y+A.getBoundingClientRect().height)}re();let E=null,i=null,l=null,o="",c="",y=!1,I="",B="",G="",b=!1,$=0,Re=!1,Ee="",Ke=null,Ye=Promise.resolve(),an=!e.client.view,W=w,qe,Oe,Le="",Ve,pe=!1,Ie=null,ye=!1,Me=()=>e.client.pendingCommand?.operation==="close",se=null,K=null,ln=We({document:s,run:async()=>{(!i?.observing||e.client.pendingCommand)&&await Ze()},delay:()=>{if(!(b||!l||!["running","waiting"].includes(l.status)&&!e.client.pendingCommand)&&!(i?.observing&&!e.client.pendingCommand))return l.pendingRequest||e.client.pendingCommand?1500:sn},hiddenDelay:()=>!b&&e.client.pendingCommand?15e3:void 0}),X=null;function Xe(){return K&&e.client.hasDurableJournal===!0&&X?.acknowledged===!0&&X.operationId===K.operationId&&e.client.view?.id===X.runId&&e.client.view?.status==="closed"&&e.client.view.revision===X.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?K:null}function un(t){let r=t.run.paywall;if(X&&t.settlement?.requestId===X.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===X.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===X.revision+1&&t.run.nodeId===X.nodeId&&t.run.visit===X.visit&&r?.receiptId===X.receiptId&&r.selectionGeneration===X.selectionGeneration&&(r.quote?.operationId??null)===X.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===X.operationId){let f=X.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,ne=ze({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(f||r.canReselect===!0&&ne.type==="native")&&(X.acknowledged=!0)}}let ke=null,He=new Set,fe={},Fe=!1,ue=(t,r=null)=>{b||(ke=r,Fe=!1,O.textContent=Fn(t,z),O.hidden=!1,M.hidden=e.client.pendingCommand===null,T(),le(e.onError,t))};function be(){let t=e.client.view;if(!t)throw new P("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let U=Vn({client:e.client,doc:s,holder:q,reviewHolder:V,mountScreenPreview:p,loadingOptions:e,get chrome(){return _},get stopped(){return b},get answers(){return fe},suspend(t){i?.setSuspended(t)},resetScreen(){o="",c="",I=""},enqueue:me,fail:ue}),$e=_n({client:e.client,expected:be,fail:ue,get stopped(){return b},get reviewing(){return U.active},get key(){return o},get busy(){return $},get staleRead(){return Ke}}),Ue=Ln({client:e.client,expected:be,perform:Se,onIntent:e.onCustomerDataIntent,get stopped(){return b},get busy(){return $},get document(){return E?.document},get answers(){return fe}}),xe=t=>`${t.id}:${t.nodeId}:${t.visit}`,De=t=>t&&(t.screen||t.paywall)?xe(t):"";function Ce(){let t=e.client.view;F.disabled=!U.active&&($>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!De(t)||c!==De(t)),F.hidden=!U.active&&!t?.canBack,on(F);let r=!!i&&!U.active;R.hidden=r&&!W?.active,k.hidden=!e.client.review||r&&!t?.canBack,r&&(d.textContent=""),T()}async function dn(t){if(!t)return;let r=e.client.view;await t;let f=e.client.view;if(!r||!f||f.id!==r.id||f.nodeId!==r.nodeId||f.visit!==r.visit||f.stopped||!["running","waiting"].includes(f.status))throw new P("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Se(t,r=!1){if(!(($||ye||se||K)&&!r||b||U.active&&!r)){$++,u.setAttribute("aria-busy","true"),O.hidden=!0,ke=null,Fe=!1,Ce();try{if(r||await dn($e.inFlight),b)return;let f=await t();b||await me(e.client.view??f.run)}catch(f){ue(f,e.client.pendingCommand?.requestId??null)}finally{$=Math.max(0,$-1),u.setAttribute("aria-busy",String($>0)),b||(M.hidden=e.client.pendingCommand===null,Ce())}}}function Ne(){ln.schedule()}async function Ze(){if(!(b||Re||$)){if(U.active){await U.open(U.receipt);return}Re=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let r=e.client.view,f=Ue.queries,ne=await e.client.get(r?.screen&&Object.keys(f).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:f}:void 0);Fe&&!b&&(Fe=!1,O.hidden=!0,T()),!b&&f===Ue.queries&&await me(e.client.view??ne.run)}catch(t){ue(t),Fe=!b}finally{Re=!1}}}function Ge(t,r){if(W?.active){let ne=W;return ne.setDismissHandler(()=>cn(ne)),ne}let f=Be(n,e,"funnel",()=>cn(f));return W=f,f.start(t,r),f}function cn(t){b||pe||(pe=!0,t.finish("dismissed"),ve(),u.hidden=!0,e.client.view?Pe().finally(ae):ae())}function en(){clearTimeout(Ve?.timeout),Ve=void 0}function ve(){en(),qe?.abort(),qe=void 0,E?.destroy(),E=null,i?.destroy(),i=null,Oe?.(),Oe=void 0,C.open&&C.close(),q.replaceChildren(),q.style.cssText="",Y=void 0,o="",c="",y=!1,I="",G=""}function pn(){let t=s.defaultView;L?.responsive&&t&&E?.resizeViewport?.(t.innerHeight,t.innerWidth)}function nn(){L?.destroy(),L=void 0,de=""}function tn(t){let r=t.screen?.presentation;if(!r||r.type==="inline"){C.open&&C.close(),nn(),R.parentElement!==A&&A.append(R),u.parentElement!==n&&n.append(u),re(t),T();return}u.parentElement!==C&&(C.append(R,u),n.append(C)),re(t);let f=t.screen.content.document,ne=JSON.stringify([r,J]);if(ne!==de){nn(),de=ne;let ge={sm:420,md:640,lg:900},we="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";C.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${h.background};color:${h.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ge[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${we};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),L=Cn(C,{presentation:r,theme:f.theme,pages:f.pages},pn),L.latch()}T(),C.setAttribute("aria-label",(H?.screen===t.screen?.content.document.name?H?.label:void 0)??E?.document?.name??t.screen?.content.document.name??"Funnel")}async function Hn(t){if(b||pe||ye&&(Me()||["running","waiting"].includes(t.status))||(l=t,ke&&e.client.pendingCommand?.requestId!==ke&&(O.hidden=!0,ke=null),z=t.locale.startsWith("zh"),k.textContent=z?"\u56DE\u770B":"History",F.textContent=U.active?z?"\u8FD4\u56DE\u5F53\u524D":"Return to current":z?"\u8FD4\u56DE":"Back",ce(),M.textContent=z?"\u91CD\u8BD5":"Retry",M.hidden=e.client.pendingCommand===null,d.textContent=t.pendingRequest?z?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?z?"\u7B49\u5F85\u4E2D":"Waiting":"",Ce(),Ee!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(Ee=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,le(e.onState,structuredClone(t))),b||pe))return;if((!t.pendingRequest||ye&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ae();return}if(t.stopped||e.client.configurationReady===!1){U.stop(),ve(),W?.finish("skipped"),u.hidden=!0,Ne();return}if(u.hidden=!1,U.active){Ne();return}let r=De(t),f=e.client.view;if(f&&f.revision>t.revision&&De(f)!==r)return;let ne=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);r!==o&&(o&&W?.finish("dismissed"),ve(),o=r,fe={...t.answers},Ue.reset());let ge=xe(t);if(Le===ge){u.hidden=!0;return}if(ne&&!r){u.hidden=!0;let Q=Ge(!0,t.locale);!b&&!pe&&Ve?.key!==ge&&(en(),Ve={key:ge,timeout:setTimeout(()=>{let m=e.client.view;if(!Q.active||!m||xe(m)!==ge)return;Le=ge;let j=new Error("Funnel screen preparation timed out");Q.finish("error",j),ve(),ue(j)},Ae)}),Ne();return}en();let Z=Q=>{let m=e.client.view;return!b&&!pe&&!Ie&&!Q.aborted&&e.client.configurationReady!==!1&&!!m&&!m.stopped&&!["closed","ineligible","failed"].includes(m.status)&&De(m)===r},we=(Q,m)=>{Z(m)&&(Le=r,W?.finish("error",Q),ve(),u.hidden=!0,ue(Q))};if(r||(tn(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&W?.finish("skipped")),t.screen){let Q=t.screen.content;if(!E){let te=t.screen.presentation.type!=="inline",oe=Ge(te,t.locale);if(b||pe)return;let ie=(qe=new AbortController).signal;tn(t),Oe=te?En(C):je(u,n),E=p(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:Q.document.name,...te?{hostPresentation:()=>L?.type??t.screen.presentation.type}:{},onResize:ee=>{Y=ee,L?.responsive&&L.setContentHeight(ee+A.getBoundingClientRect().height)},onAction(ee,he={},Gn={}){if(U.active||!Z(ie)||c!==r)return;fe={...fe,...Gn};let Jn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Je})=>Object.hasOwn(fe,Je)).map(({variable:Je})=>[Je,fe[Je]]));Se(()=>e.client.submit({operation:"submit",...be(),input:{type:"screen",output:ee,answers:Jn,selection:he}}))},onAnswers:ee=>{U.active||!Z(ie)||c!==r||(fe={...fe,...ee})},onCustomerDataIntent:ee=>{U.active||!Z(ie)||c!==r||Ue.intent(ee).catch(ue)},onEscape:()=>{!Z(ie)||c!==r||U.active||se||K||Pe()},onError:ee=>{let he=new Error(ee);c===r?ue(he):we(he,ie)},onRendered:ee=>{if(!(!Z(ie)||c===r))try{oe.present(he=>{Oe?.(),Oe=void 0,ee&&(H={screen:Q.document.name,label:ee},C.setAttribute("aria-label",ee)),te&&(C.showModal(),L?.responsive&&C.focus({preventScroll:!0}),!he&&e.loading!=="host"&&Pn(C,L?.type??t.screen.presentation.type,L?.responsive)),c=r,y=te,Ce()}),Z(ie)&&$e.report(r)}catch(he){we(he,ie)}}}),pn()}let m={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:fe,values:t.screen.values}},j=JSON.stringify([Q,t.locale,m.parameters,t.screen.inputs,t.screen.values]);if(j!==I)E.update(Q.document,t.locale,m),I=j,B=JSON.stringify(m.capabilities),G=JSON.stringify(m.customerData);else{let te=JSON.stringify(m.capabilities);te!==B&&(E.updateCapabilities(m.capabilities),B=te),JSON.stringify(m.customerData)!==G&&(E.updateCustomerData(m.customerData),G=JSON.stringify(m.customerData))}let x=E;if(x)try{await(W?.wait(x.ready)??x.ready)}catch(te){qe&&we(te,qe.signal)}}else if(t.paywall&&!i){let Q=Ge(!0,t.locale);if(b||pe)return;let m=(qe=new AbortController).signal;tn(t);let j=await D(q,{loading:"host",signal:m,canInteract:()=>Z(m)&&!U.active&&!se&&!K,beforeAction:async()=>{$++;try{await dn($e.settled()),O.hidden=!0,ke=null,Fe=!1,T()}finally{$=Math.max(0,$-1)}},start:()=>An(e.client),onObservationChange:Ne,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,confirmOnHostedCheckout:e.confirmOnHostedCheckout,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:x=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:x,openIn:"same_window"}):s.defaultView?.location.assign(x),onAction:async x=>{if(U.active)return;let te=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:x,answers:{}}});await me(e.client.view??te.run)},onError:x=>{c===r?ue(x):we(x,m)}},{quoteError:x=>le(e.onError,x),present(x){Z(m)&&(Q.present(()=>{x(),c=r,y=!!q.querySelector("dialog[open]"),Ce()}),Z(m)&&$e.report(r))},async dismiss(){b||m.aborted||U.active||se||K||!ye&&!Z(m)||(ye=!0,await Pe())}}).catch(x=>(we(x,m),null));!Z(m)&&!(ye&&!b&&!m.aborted)?j?.host?.destroy():j&&(i=j.host,i?.setSuspended(U.active))}if(b||pe)return;Ce();let N=t.instruction;if(N&&(N.type==="open_url"||N.type==="event")&&!He.has(N.receiptId)){let Q=s.createElement("button");Q.type="button",Q.style.cssText=_.primary,_e(Q,()=>_.focus),q.style.cssText=_.stage,Q.textContent=N.type==="open_url"?`${z?"\u524D\u5F80":"Continue to"} ${new URL(N.url).host}`:z?"\u7EE7\u7EED":"Continue",Q.onclick=()=>{let m=be(),j=N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="new_window"?$n(N.url):null;Se(async()=>{let x="success";if(N.type==="open_url")if(e.onOpenUrl)try{x=await e.onOpenUrl({receiptId:N.receiptId,url:N.url,openIn:N.openIn})===!1?"failed":"opened"}catch(oe){le(e.onError,oe),x="failed"}else x=N.openIn==="new_window"&&!j?"failed":"opened";if(N.type==="event"){if(!e.onEvent)throw new P("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent(N.event)}if(b||e.client.view?.nodeId!==m.nodeId||e.client.view.visit!==m.visit)throw new P("PRECONDITION_FAILED","The client action visit changed");let te=await e.client.submit({operation:"submit",...m,input:{type:"client_action",receiptId:N.receiptId,outcome:x}});return He.add(N.receiptId),N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="same_window"&&s.defaultView?.location.assign(N.url),te})},W?.active?W.present(()=>q.replaceChildren(Q)):q.replaceChildren(Q)}!t.pendingRequest&&t.status==="completed"&&!He.has(`complete:${t.id}`)&&(He.add(`complete:${t.id}`),le(e.onComplete,structuredClone(t))),Ne()}function $n(t){let r=s.defaultView?.open(t,"_blank")??null;return r&&(r.opener=null),r}function me(t){return Ce(),Ye=Ye.catch(()=>{}).then(async()=>{try{await Hn(t)}catch(r){throw W?.active&&(Le=xe(t),W.finish("error",r),ve(),u.hidden=!0),r}}),Ye}let Un=e.client.subscribe(t=>{if(!an){if(t.stopped&&y&&!ye){l=t,ae();return}!ye&&(t.stopped||e.client.configurationReady===!1||o&&c!==o&&(De(t)!==o||["closed","ineligible","failed"].includes(t.status)))&&(ve(),W?.finish("dismissed"),u.hidden=!0),me(t).catch(ue)}}),xn=e.client.subscribeError?.(ue);function Pe(t){if(Ie)return Ie;if(b||!t&&(se||K))return Promise.resolve();let r=!t&&Me();return!r&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(l=e.client.view,ae(),Promise.resolve()):(Ie=Se(async()=>{let f=r?await e.client.retry():await e.client.submit({operation:"close",...t??be()});return t&&un(f),f},!0).then(()=>{let f=e.client.view;f?.status==="closed"&&!Me()&&(l=f,ae())}).finally(()=>{Ie=null}),Ie)}function ae(){S?.destroy(),!b&&(b=!0,e.signal?.removeEventListener("abort",ae),a?.removeEventListener("abort",ae),W?.finish("dismissed"),ln.destroy(),Un(),xn?.(),ve(),nn(),U.stop(),C.remove(),u.remove(),v(),le(e.onDismiss,l?structuredClone(l):null))}F.onclick=()=>{if(!F.disabled){if(U.active){U.exit();return}Se(()=>e.client.submit({operation:"back",...be()}))}},k.onclick=()=>{U.open()},R.onclick=()=>{W?.active?W.dismiss():se||Pe()},M.onclick=()=>{Me()?Pe():Se(()=>e.client.retry())},C.addEventListener("cancel",t=>{t.preventDefault(),W?.active?W.dismiss():se||Pe()}),e.signal?.addEventListener("abort",ae,{once:!0}),a?.addEventListener("abort",ae,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??sn)>=sn||t.instruction?.type==="evaluate_segment")&&(Ke=Ze().finally(()=>{Ke=null})),await me(t);else{u.hidden=!0;let r=Ge(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(b||pe)throw new DOMException("Presentation cancelled","AbortError");let f=await r.wait(e.client.get(),Ae);an=!1,await me(e.client.view??f.run)}}catch(t){throw W?.finish("error",t),ae(),t}return{destroy:ae,refresh:Ze,get recovery(){let t=Xe();if(t)return t;if(!b&&!$&&!ye&&!se&&i){let r=i.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let t=Xe();if(t)return Promise.resolve(t);let r=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,f=()=>({type:"recover",operationId:r,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let N=i?.recovery;return Promise.resolve(N&&N.type!=="native"&&N.type!=="cancel"?N:f())}let ne=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(N=>N.operation==="close");if(b&&!(ne||K&&e.client.view?.status==="closed")||$||Re||Ie||U.active||!i&&!K&&!ne)return Promise.resolve(f());let ge=i,Z=(async()=>{try{if(!K&&ne){let m=await e.client.retry();return await me(e.client.view??m.run),f()}if(!K){let m=await ge.prepareFallback();if(m.type!=="native")return m;if(e.client.hasDurableJournal!==!0)return f();K=m}let N=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(N.length){let m=N.find(x=>x.operation==="close");if(!m||!X||m.requestId!==X.requestId)return f();let j=await e.client.retry();un(j),await me(e.client.view??j.run)}else{let m=e.client.view,j=m?.paywall;if(!m||!j||j.selectionGeneration===void 0||(j.quote?.operationId??null)!==K.operationId||K.operationId!==null&&j.canReselect!==!0)return f();let x=j.selectionGeneration,te=await e.client.get();await me(e.client.view??te.run);let oe=e.client.view,ie=oe?.paywall;if(!oe||!ie||!["running","waiting"].includes(oe.status)||oe.stopped||oe.id!==m.id||oe.nodeId!==m.nodeId||oe.visit!==m.visit||ie.receiptId!==j.receiptId||ie.selectionGeneration!==x||(ie.quote?.operationId??null)!==K.operationId||K.operationId!==null&&ie.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return f();let ee=be();X={runId:oe.id,operationId:K.operationId,revision:ee.revision,requestId:ee.requestId,nodeId:oe.nodeId,visit:oe.visit,receiptId:ie.receiptId,selectionGeneration:x,acknowledged:!1},await Pe(ee)}let Q=Xe();return Q?(ae(),Q):f()}catch(N){return ue(N),f()}})();se=Z;let we=()=>{se===Z&&(se=null)};return Z.then(we,we),Z},review:U.open,exitReview:U.exit,get unappliedDrafts(){return U.drafts}}}function Vt(n,g,w){return zn(n,g,w)}export{Bn as a,Mn as b,zn as c,Vt as d};
1
+ import{a as kn,b as rn,c as on,d as _e,e as Fn,f as We,h as Dn}from"./chunk-UWYL2QCF.js";import{c as Cn,d as Pn,e as Rn,f as Ae,g as Be,h as En,i as je,k as qn}from"./chunk-RBMOWJGE.js";import{$ as Qe}from"./chunk-ITVSLSRM.js";import{a as ze,e as gn,f as vn,g as hn,h as In,i as bn}from"./chunk-B3KFE57L.js";import{b as wn}from"./chunk-ACFQLHJR.js";import{R as fn,qa as yn}from"./chunk-WRUW2UIJ.js";import{a as P}from"./chunk-HJLGRW4A.js";import{b as Sn,e as On}from"./chunk-SLUA7ABW.js";import{d as Tn}from"./chunk-ZYTT7ZAB.js";import{a as le}from"./chunk-DSPLGTQI.js";import{b as mn}from"./chunk-6BTJNSQQ.js";var Te=new WeakMap;function Bn(n){let g=n.view,w=g?.paywall?.resolution;if(!g||!["running","waiting"].includes(g.status)||g.stopped||!w||"document"in w||!n.resolvePaywall||n.identitySignal?.aborted)return;let e=JSON.stringify(w);if(Te.get(n)?.key===e)return;let p=JSON.parse(e),D=n.identitySignal,a=Promise.resolve().then(async()=>{D?.throwIfAborted();let s=await n.resolvePaywall(p);return D?.throwIfAborted(),s}),S={key:e,content:a};return Te.set(n,S),a.catch(()=>{}),()=>{Te.get(n)===S&&Te.delete(n)}}function Nn(n,g){let w=Te.get(n);return Te.delete(n),w?.key===JSON.stringify(g)?w.content:n.resolvePaywall(g)}async function An(n){let{session:g,load:w}=Qn(n);try{return await w(),g}catch(e){throw g.destroy(),e}}function Qn(n){let g=n.view;if(!g?.paywall)throw new P("INVALID_REQUEST","The current node is not a Paywall");let w=g.paywall.receiptId,e=g.nodeId,p=g.visit,D=g.paywall.resolution,a=g.paywall,S="document"in D?{document:D.document,offering:D.offering,capabilities:D.capabilities}:null;function s(){let i=a.resolution;return"document"in i?i:S&&{...i,document:S.document,offering:S.offering,capabilities:gn(i.capabilities,S.capabilities)}}function v(i){if(!vn(i,D))throw new P("INVALID_RESPONSE","The pinned Paywall binding changed")}let u=!1,q=new Set,A=null;function V(){let i=s();if(i&&!u)for(let l of q)le(l,structuredClone(i))}async function k(){J();let i=s();if(i)return structuredClone(i);if(!A){let l=(async()=>{if("document"in a.resolution||!n.resolvePaywall)throw new P("INVALID_RESPONSE","Public Paywall reader is unavailable");let c=await Nn(n,a.resolution);return J(),v(c),S={document:c.document,offering:c.offering,capabilities:c.capabilities},V(),s()})();A=l;let o=()=>{A===l&&(A=null)};l.then(o,o)}return A.then(l=>structuredClone(l))}let d=new AbortController,F=(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).find(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_quote")?.requestId??g.paywall.purchaseRequestId,R=0,M=null,C=new Set,H=null,h=new Map;function _(i){if(i.purchase&&i.purchase.receiptId!==w)throw new P("INVALID_RESPONSE","Purchase receipt changed");let l=i.run.paywall;return i.purchase??(l?.receiptId===w?l:null)}function J(){if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed")}function z(i,l,o){if(J(),l!==R||o!==void 0&&a.quote?.operationId!==o)return!1;let c=a.selectionGeneration??0,y=i.run.paywall;if(y?.receiptId===w){if((y.selectionGeneration??0)<(a.selectionGeneration??0))return!1;v(y.resolution)}let I=_(i),B=y?.receiptId===w&&(y.selectionGeneration??0)>c,G=B?I?.quote??null:I?.quote??a.quote,b=I?.operation??(G?.operationId===a.quote?.operationId?a.operation:null);return G&&b&&hn(b,{operationId:G.operationId},"Purchase operation changed"),(B||G?.operationId!==a.quote?.operationId)&&(R++,y?.receiptId===w&&(F=y.purchaseRequestId)),y?.canReselect===!0&&y.purchaseRequestId===H&&!(n.pendingCommands??[n.pendingCommand]).some($=>$?.requestId===H)&&(H=null),a={...a,...y?.receiptId===w?y:{},quote:G,operation:bn(a.operation,b,!0)},V(),!0}function L(i,l,o){return new Promise((c,y)=>{let I=!1,B=()=>{clearTimeout(Re),d.signal.removeEventListener("abort",$)},G=Ee=>{I||(I=!0,B(),c(Ee))},b=Ee=>{I||(I=!0,B(),y(Ee))},$=()=>b(new P("IDENTITY_CHANGED","Paywall presentation has closed")),Re=setTimeout(()=>b(new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o)),Math.max(0,l-Date.now()));d.signal.addEventListener("abort",$,{once:!0}),d.signal.aborted&&$(),i.then(G,b)})}function de(i){return new Promise(l=>{let o=()=>{clearTimeout(c),d.signal.removeEventListener("abort",o),l()},c=setTimeout(o,i);d.signal.addEventListener("abort",o,{once:!0}),d.signal.aborted&&o()})}function Y(i,l){J();let o=h.get(i)??n.pendingCommands?.find(I=>I.requestId===i)??n.pendingCommand;if(o?.operation==="submit"&&o.requestId===i&&o.nodeId===e&&o.visit===p){l.type==="paywall_quote"&&o.input.type==="paywall_quote"&&o.input.predecessor&&!l.predecessor&&(l={...l,predecessor:o.input.predecessor});let I=Qe.parse(o),B=Qe.parse({...o,input:l});if(I.operation!=="submit"||B.operation!=="submit"||JSON.stringify(I.input)!==JSON.stringify(B.input))throw new P("CONFLICT","A purchase request cannot change its input");return h.set(i,I),I}let c=n.view;if(!c||c.nodeId!==e||c.visit!==p||c.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","The Paywall visit has changed");let y=Qe.parse({operation:"submit",requestId:i,nodeId:e,visit:p,revision:c.revision,input:structuredClone(l)});if(y.operation!=="submit")throw new P("INVALID_REQUEST","A purchase submission is required");return h.set(i,y),y}async function ce(i,l){J();let{requestId:o,input:c}=i,y=Date.now()+3e4;C.add(o);try{let I=await L(n.submit(i),y,o);for(;I.run.pendingRequest?.requestId===o&&Date.now()<y&&!u&&(await de(Math.min(1e3,y-Date.now())),!(u||Date.now()>=y));)I=await L(n.resume(o),y,o);if(u)throw new P("IDENTITY_CHANGED","Paywall presentation has closed");if(I.run.pendingRequest?.requestId===o)throw new P("COMMAND_PENDING","The purchase command is still pending; retry the original request",202,o);if(!z(I,l,c.type==="paywall_confirm"||c.type==="paywall_cancel"?c.operationId:void 0))throw new P("PRECONDITION_FAILED","The purchase selection has changed");H===o&&(H=null)}catch(I){if(H=o,c.type==="paywall_quote"&&n.settle&&!u&&I instanceof P&&I.status!==void 0&&![401,425].includes(I.status)&&!I.retryable&&I.recovery!=="recover_operation")try{if((await L(n.settle(o),y,o)).settlement?.state==="settled"){let G=await L(n.get(),y,o);z(G,l)&&G.run.paywall?.purchaseRequestId===o&&a.canReselect===!0&&h.delete(o)}}catch{}throw I instanceof P&&I.code==="COMMAND_PENDING"&&I.status===void 0&&h.delete(o),I}finally{C.delete(o)}}async function re(i){if(!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let l=i==="confirm"?"paywall_confirm":"paywall_cancel",o=[...h.values(),...n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])].find(y=>y.operation==="submit"&&y.input.type===l&&"operationId"in y.input&&y.input.operationId===a.quote.operationId),c=o?.operation==="submit"&&o.input.type===l&&"operationId"in o.input&&o.input.operationId===a.quote.operationId?o.requestId:crypto.randomUUID();if(await ce(Y(c,{type:i==="confirm"?"paywall_confirm":"paywall_cancel",operationId:a.quote.operationId}),R),!a.operation)throw new P("INVALID_RESPONSE","The accepted purchase result is missing");return structuredClone(a.operation)}let T={get view(){return structuredClone(s())},get quote(){return a.quote?structuredClone(a.quote):null},get operation(){return a.operation?structuredClone(a.operation):null},get webViewUrl(){return n.webViewUrl},get canReselect(){return a.canReselect===!0&&H===null},get recovery(){let i=n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[]),l=n.pendingPurchase;if(l&&(l.receiptId!==w||l.operationId!==a.quote?.operationId))return{type:"recover",operationId:l.operationId,requestId:i[0]?.requestId??null};let o=ze({quote:a.quote,operation:a.operation,requestId:i[0]?.requestId??H??F,pending:C.size>0||i.length>0||H!==null,destroyed:u,canReselect:a.canReselect});return o.type==="recover"&&o.requestId===null&&!u&&n.hasDurableJournal===!0&&!a.quote&&!a.operation&&(a.selectionGeneration??0)===0&&!l&&!i.length&&!C.size&&!F?{type:"native",operationId:null}:o},get pendingCancellation(){return!u&&(n.pendingCommands??(n.pendingCommand?[n.pendingCommand]:[])).some(i=>i.operation==="submit"&&i.nodeId===e&&i.visit===p&&i.input.type==="paywall_cancel"&&i.input.operationId===a.quote?.operationId)},subscribe(i){return u?()=>{}:(q.add(i),()=>q.delete(i))},async refresh(){J();let i=R,l=await n.get();if(z(l,i),l.run.paywall?.receiptId!==w)throw new P("PRECONDITION_FAILED","Paywall presentation has changed");return k()},preview(i){let l=s();if(!l)return Promise.reject(new P("PRECONDITION_FAILED","Load the Paywall presentation first"));if(F&&F!==i.requestId&&(M||a.canReselect!==!0))return Promise.reject(new P("COMMAND_PENDING","Retry the original purchase before starting another"));let o=l.document.buttons[i.actionId],c=o?.type==="checkout"?wn(o.product,i.selection,l.capabilities):null;if(!c)return Promise.reject(new P("PRODUCT_UNAVAILABLE","Choose an available Product in this purchase area"));let y=yn(l.document.screen,c,i.selection,l.capabilities),I=F!==i.requestId&&(a.selectionGeneration??0)>0?{operationId:a.quote?.operationId??null,generation:a.selectionGeneration??0}:void 0;if(I&&a.canReselect!==!0)return Promise.reject(new P("COMMAND_PENDING","Original purchase requires authoritative termination"));let B;try{B=Y(i.requestId,{type:"paywall_quote",actionId:i.actionId,productVersionId:c,...Object.keys(y).length?{featureQuantities:y}:{},...I?{predecessor:I}:{},...i.offerId?{offerId:i.offerId}:{},...i.nativeOffer?{nativeOffer:i.nativeOffer}:{}})}catch($){return Promise.reject($)}if(F===i.requestId&&M)return M;F!==i.requestId&&R++;let G=R;F=i.requestId;let b=(async()=>{if(await ce(B,G),!a.quote)throw new P("INVALID_RESPONSE","The accepted quote is missing");return In(a.quote,{productVersionId:c,featureQuantities:y},"The selected purchase changed"),structuredClone(a.quote)})();return M=b,b.then(()=>{M===b&&(M=null)},$=>{M===b&&(M=null),F===i.requestId&&n.pendingCommand?.requestId!==i.requestId&&$ instanceof P&&$.status!==void 0&&$.status<500&&![401,425].includes($.status)&&(F=null)}),b},confirm:()=>re("confirm"),cancel:()=>re("cancel"),async read(){if(J(),!a.quote)throw new P("INVALID_REQUEST","A quoted purchase is required");let i=a.quote.operationId,l=R,o=n.pendingCommands?.find(G=>G.operation==="submit"&&(G.input.type==="paywall_confirm"||G.input.type==="paywall_cancel")&&G.input.operationId===i)??n.pendingCommand;o?.operation==="submit"&&(o.input.type==="paywall_confirm"||o.input.type==="paywall_cancel")&&o.input.operationId===i&&await n.settle?.(o.requestId);let c=await n.get(void 0,{receiptId:w,operationId:i});J();let y=_(c);if(y?.quote&&y.quote.operationId!==i||y?.operation&&y.operation.operationId!==i)throw new P("INVALID_RESPONSE","Purchase operation changed");let I=z(c,l,i),B=I?a.operation:y?.operation;if(!B)throw new P("INVALID_RESPONSE","The current purchase result is missing");return I&&C.size===0&&!(n.pendingCommands?.length??(n.pendingCommand?1:0))&&(H=null),structuredClone(B)},destroy(){u=!0,E(),q.clear(),d.abort(),h.clear()}},E=n.subscribe(i=>{u||i.nodeId!==e||i.visit!==p||i.paywall?.receiptId!==w||(i.paywall.selectionGeneration??0)<(a.selectionGeneration??0)||(v(i.paywall.resolution),a={...a,resolution:i.paywall.resolution},V())});return{session:T,load:k}}function _n(n){let g=new Set,w=new Set,e=null;async function p(s,v){let u=!1;for(;!n.stopped&&n.key===s&&n.client.pendingCommand?.requestId===v;){if(!n.client.settle)throw new P("COMMAND_PENDING","The original display acknowledgement is still pending");await n.client.settle(v),u=!0,n.client.pendingCommand?.requestId===v&&await new Promise(q=>setTimeout(q,1500))}n.stopped||n.key!==s||(u&&await n.client.get(),!(n.stopped||n.key!==s)&&g.add(s))}function D(s,v){e=v;let u=()=>{e===v&&(e=null),w.delete(s)};return v.then(u,q=>{u(),n.busy||n.fail(q)}),v}function a(s){if(n.reviewing||g.has(s)||w.has(s)||n.stopped)return;w.add(s);let v=async()=>{if(n.reviewing||n.stopped||n.key!==s||g.has(s)){w.delete(s);return}if(n.busy||n.client.pendingCommand){setTimeout(()=>{v()},250);return}let u=(async()=>{if(n.staleRead){if(await n.staleRead,n.stopped||n.key!==s)return;if(n.client.pendingCommand){setTimeout(()=>{v()},250);return}}let q=n.client.view,A=n.expected(),V=A.requestId;try{await n.client.submit({operation:"shown",...A})}catch(k){if(!(k instanceof P)||k.code!=="CONFLICT"||k.status!==409||n.client.pendingCommand)throw k;await n.client.get();let d=n.client.view;if(n.stopped||n.reviewing||n.key!==s||!d||!q||d.id!==q.id||d.source.versionId!==q.source.versionId||d.nodeId!==A.nodeId||d.visit!==A.visit||d.revision<=A.revision||d.stopped||!d.screen&&(!d.paywall||d.paywall.receiptId!==q.paywall?.receiptId)||!["running","waiting"].includes(d.status)||n.client.pendingCommand)throw k;let O=n.expected();V=O.requestId,await n.client.submit({operation:"shown",...O})}await p(s,V)})();D(s,u)};v()}function S(){if(e)return e;let s=n.client.pendingCommand;if(s?.operation!=="shown")return null;let v=n.key;return w.add(v),D(v,(async()=>{await n.client.retry(),await p(v,s.requestId)})())}return{report:a,settled:S,get inFlight(){return e}}}function Ln(n){let g={},w=new Map;async function e(p){let D=n.client.view,a=D?.screen,S=a?.customerData.nodes[p.nodeId];if(n.stopped||n.busy||!D||!a||!S)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(p.action)){let k=n.document,d=k?fn(k,p.nodeId):null,O=d?.type==="customer_data"?d.data.outputs?.[p.action]:void 0;O&&a.outputs.includes(O)?await n.perform(()=>n.client.submit({operation:"submit",...n.expected(),input:{type:"screen",output:O,answers:n.answers,selection:p.value?{[p.nodeId]:p.value}:{}}})):await n.onIntent?.(p,D);return}let v=p.action.startsWith("sources_")?S.resources.find(k=>k.key===p.value):null;if(p.action.startsWith("sources_")&&!v)throw new P("INVALID_REQUEST","Choose a current resource");let u=`${D.visit}:${p.nodeId}:${v?.key??""}`,q=w.get(u)??[null],V=g[p.nodeId]??{page:1,after:null,filter:"all",...v?{resourceKey:v.key}:{}};if(p.action==="filter"){let k=p.value;if(!k||!(S.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new P("INVALID_REQUEST","Unknown data filter");V={page:1,after:null,filter:k},q.splice(0,q.length,null)}else if(p.action==="next"||p.action==="sources_next"){let k=v?.sources.at(-1),d=v?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:a.dataCursors[p.nodeId];if(!d||!v&&!S.hasNext)return;q[V.page]=d,V={...V,page:V.page+1,after:d}}else if(p.action==="previous"||p.action==="sources_previous"){if(V.page<=1)return;V={...V,page:V.page-1,after:q[V.page-2]??null}}w.set(u,q),g={...g,[p.nodeId]:V},await n.perform(()=>n.client.get({nodeId:D.nodeId,visit:D.visit,revision:D.revision,components:g}))}return{get queries(){return g},intent:e,reset(){g={},w.clear()}}}function Vn(n){let{doc:g,holder:w,reviewHolder:e,mountScreenPreview:p}=n,D=!1,a,S=0,s=null,v="",u,q=new Map,A=d=>d?`${d.id}:${d.nodeId}:${d.visit}:${d.revision}:${d.paywall?.quote?.operationId??""}`:"";async function V(d){if(n.stopped||!n.client.review||D&&d===a&&u?.active)return;let O=!D||d!==a;D||(v=A(n.client.view),q.set(v,structuredClone(n.answers))),D=!0,a=d,w.hidden=!0,n.suspend(!0),e.hidden=!1;let F=++S;O&&(u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),u=Be(e,n.loadingOptions,"funnel",()=>{k()}));let R=O?u:void 0;try{if(R?.start(!1,n.client.view?.locale),F!==S||n.stopped)return;let M=n.client.review(d),C=await(R?.wait(M,Ae)??M);if(n.stopped||F!==S||!D)return;if(!C.review)throw new P("INVALID_RESPONSE","Historical projection is missing");s?.destroy(),s=null,R||e.replaceChildren();let H=g.createElement("div"),h=R?je(H,e):()=>{};e.append(H);let _=C.run.locale.startsWith("zh"),J=n.chrome;H.style.cssText=J.history;let z=g.createElement("p");z.textContent=_?"\u53EA\u8BFB\u56DE\u770B":"Read-only history",z.style.cssText=J.historyTitle,H.append(z);let L=g.createElement("p");L.style.cssText=J.historyNote,L.textContent=C.review.pages.length?_?"\u9009\u62E9\u4E00\u9875\u67E5\u770B\u5F53\u65F6\u7684\u5185\u5BB9\uFF0C\u56DE\u770B\u4E0D\u4F1A\u6539\u52A8\u4EFB\u4F55\u4FE1\u606F\u3002":"Choose a page to see it as it was. Nothing here can be changed.":_?"\u8FD8\u6CA1\u6709\u53EF\u56DE\u770B\u7684\u9875\u9762\u3002":"There are no earlier pages yet.",H.append(L);let de=C.review.page?.receiptId,Y=g.createElement("div");Y.style.cssText=J.historyPages;for(let[T,E]of C.review.pages.entries()){let i=g.createElement("button");i.type="button",i.textContent=_?`\u7B2C ${T+1} \u9875`:`Page ${T+1}`;let l=de!==void 0&&E.receiptId===de;i.style.cssText=l?J.primary:J.secondary,l&&i.setAttribute("aria-current","page"),_e(i,()=>n.chrome.focus),i.onclick=()=>{V(E.receiptId)},Y.append(i)}if(Y.childElementCount&&H.append(Y),C.review.page){let T=C.review.page,E=g.createElement("div");E.inert=!0,E.style.cssText=J.historyPage,H.append(E),s=p(E,{mode:"live",rendererUrl:n.client.webViewUrl,title:T.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{F===S&&!n.stopped&&R?.present(h)},onError:l=>{if(F!==S||n.stopped)return;let o=new Error(l);R?.finish("error",o),s?.destroy(),s=null,H.remove(),n.fail(o)},onEscape:()=>{k()}});let i=s;if(i.update(T.document,C.run.locale,{serverInput:{bindings:T.inputs,answers:T.answers,values:T.values}}),await i.ready,n.stopped||F!==S||!D)return}let ce=_?{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"},re=g.createElement("div");re.style.cssText=J.historyRecords;for(let T of[...C.review.coupons.map((E,i)=>`${_?"\u4F18\u60E0\u5238":"Coupon"} ${i+1}: ${ce[E.status]}`),...C.review.purchases.map((E,i)=>`${_?"\u8D2D\u4E70":"Purchase"} ${i+1}: ${Dn(E.status,_)}`)]){let E=g.createElement("p");E.textContent=T,E.style.margin="0",re.append(E)}re.childElementCount&&H.append(re),C.review.page||R?.present(h),n.client.view&&await n.enqueue(n.client.view)}catch(M){if(F!==S||n.stopped)return;R?.finish("error",M),s?.destroy(),s=null,e.replaceChildren(),n.fail(M)}}async function k(){if(!D||n.stopped||!n.client.review)return;let d=++S;u?.finish("dismissed");try{if(await n.client.review(),n.stopped||d!==S)return;D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1;let O=n.client.view;A(O)!==v?(q.set(v,structuredClone(n.answers)),n.resetScreen()):(q.delete(v),n.suspend(!1)),O&&await n.enqueue(O)}catch(O){if(d!==S||n.stopped)return;s?.destroy(),s=null,e.replaceChildren(),n.fail(O)}}return{get active(){return D},get receipt(){return a},open:V,exit:k,get drafts(){return new Map([...q].map(([d,O])=>[d,structuredClone(O)]))},stop(){D=!1,S++,u?.finish("dismissed"),s?.destroy(),s=null,e.replaceChildren(),e.hidden=!0,w.hidden=!1}}}function Mn(n){if(!n.client.pageExperiments)throw new Error("The Run controller does not support page experiments");let g=n.client.pageExperiments.bind(n.client),w=!1,e=!1,p=0,D=!1,a=!1,S="",s=()=>{let h=n.client.view;return JSON.stringify([h?.id,h?.source.versionId,h?.visit,h?.revision,h?.status,h?.stopped])},v=new Map,u=new Set,q={},A=new Map,V=Sn(n.appManifestRelease),k=()=>{for(let h of v.values())h.effect.revert();v.clear()},d=()=>{k();for(let h of A.values())h();A.clear()};function O(h){if(w||u.has(h))return;u.add(h);let _=p;g(n.appManifestRelease,[h]).catch(J=>{u.delete(h),!w&&_===p&&le(n.onError,J)})}async function F(){if(w)return;S=s();let h=n.client.view;if(!h||h.stopped||!["running","waiting"].includes(h.status)){p++,d();return}if(document.visibilityState==="hidden")return;if(D){a=!0;return}D=!0;let _=++p,J=`${h.id}:${h.visit}:${h.revision}`,z=location.href;try{let[L,{applyVisualVariation:de}]=await Promise.all([g(n.appManifestRelease),import("./visual-dom-32PB6MMP.js")]),Y=n.client.view;if(w||_!==p||!Y||Y.stopped||!["running","waiting"].includes(Y.status)||`${Y.id}:${Y.visit}:${Y.revision}`!==J||location.href!==z)return;let ce=new Set,re=new Set;for(let T of L.assignments){let E=`${L.payload.environmentId}:${T.experimentKey}`;if(re.add(E),A.has(E)||A.set(E,On(E,q)),!!T.inExperiment)for(let i of L.payload.experiments){if(i.key!==T.experimentKey||!mn(location.href,i.urlPatterns??[]))continue;let l=i.meta?.findIndex(G=>G.key===T.variationKey)??-1,o=i.variations[l];if(!o?.renderGuard)continue;let c=T.receiptId+":"+i.changeId,y=JSON.stringify([T.variationKey,o]);ce.add(c);let I=v.get(c);if(I?.signature===y){I.effect.applied&&O(T.receiptId);continue}v.get(c)?.effect.revert(),v.delete(c);let B=de(o,{requireUniqueTargets:!0,boundVariations:i.variations,allowJs:!1,onApplied:()=>O(T.receiptId),onError:G=>le(n.onError,G)});v.set(c,{signature:y,effect:B}),B.applied&&O(T.receiptId)}}for(let[T,E]of v)ce.has(T)||(E.effect.revert(),v.delete(T));for(let[T,E]of A)re.has(T)||(E(),A.delete(T))}catch(L){_===p&&d(),!w&&_===p&&le(n.onError,L)}finally{D=!1,a&&!w&&(a=!1,F())}}let R=n.client.subscribe(()=>{if(s()===S)return;S=s(),p++;let h=n.client.view;(!h||h.stopped||!["running","waiting"].includes(h.status))&&d(),e&&F()}),M=Tn(()=>{p++,d(),e&&F()}),C=()=>{p++,k()};document.addEventListener("visibilitychange",C);let H=We({document,run:async()=>{e&&await F()},delay:()=>e&&!w?15e3:void 0});return{async start(){e||w||(e=!0,await H.refresh())},refresh:F,destroy(){w=!0,p++,H.destroy(),document.removeEventListener("visibilitychange",C),R(),M(),d(),V.destroy()}}}var sn=5e3;async function zn(n,g,w){let e=g,[{mountScreenPreview:p},{showPaywall:D}]=await Promise.all([import("./screen-renderer-W5MP4KVG.js"),import("./paywall-DI62MX5L.js")]),a=e.client.identitySignal;e.signal?.throwIfAborted(),a?.throwIfAborted();let S=e.appManifestRelease?Mn({client:e.client,appManifestRelease:e.appManifestRelease,onError:e.onError}):void 0;S?.start();let s=n.ownerDocument,v=qn(s),u=s.createElement("section"),q=s.createElement("div"),A=s.createElement("div"),V=s.createElement("div"),k=s.createElement("button");V.hidden=!0,k.type="button";let d=s.createElement("p"),O=s.createElement("p"),F=s.createElement("button"),R=s.createElement("button"),M=s.createElement("button"),C=s.createElement("dialog"),H;u.dataset.indianaFunnel="",u.setAttribute("aria-busy","false"),d.setAttribute("role","status"),O.setAttribute("role","alert"),O.hidden=!0,F.type=R.type=M.type="button",A.append(F,k,d,O,M,R),u.append(q,V,A),n.append(u);let h=kn,_=rn(h),J="",z=(s.documentElement.lang||"").startsWith("zh"),L,de="",Y;for(let t of[F,k,M,R])_e(t,()=>_.focus);function ce(){let t=z?"\u5173\u95ED":"Close";R.parentElement===C?(R.textContent="\xD7",R.setAttribute("aria-label",t),Rn(R,h)):(R.textContent=t,R.removeAttribute("aria-label"),R.style.cssText=_.link+";margin-inline-start:auto")}function re(t){let r=t?.screen?.content.document.theme??h,f=JSON.stringify([r.primary,r.background,r.text,r.radius,r.font,R.parentElement===C]);f!==J&&(J=f,h=r,_=rn(h,R.parentElement===C),u.style.cssText=_.root+";min-width:0",A.style.cssText=_.bar,F.style.cssText=k.style.cssText=_.secondary,M.style.cssText=_.primary,d.style.cssText=_.status,O.style.cssText=_.alert,ce(),on(F))}function T(){A.hidden=F.hidden&&k.hidden&&M.hidden&&O.hidden&&!d.textContent&&(R.hidden||R.parentElement!==A),L?.responsive&&Y!==void 0&&L.setContentHeight(Y+A.getBoundingClientRect().height)}re();let E=null,i=null,l=null,o="",c="",y=!1,I="",B="",G="",b=!1,$=0,Re=!1,Ee="",Ke=null,Ye=Promise.resolve(),an=!e.client.view,W=w,qe,Oe,Le="",Ve,pe=!1,Ie=null,ye=!1,Me=()=>e.client.pendingCommand?.operation==="close",se=null,K=null,ln=We({document:s,run:async()=>{(!i?.observing||e.client.pendingCommand)&&await Ze()},delay:()=>{if(!(b||!l||!["running","waiting"].includes(l.status)&&!e.client.pendingCommand)&&!(i?.observing&&!e.client.pendingCommand))return l.pendingRequest||e.client.pendingCommand?1500:sn},hiddenDelay:()=>!b&&e.client.pendingCommand?15e3:void 0}),X=null;function Xe(){return K&&e.client.hasDurableJournal===!0&&X?.acknowledged===!0&&X.operationId===K.operationId&&e.client.view?.id===X.runId&&e.client.view?.status==="closed"&&e.client.view.revision===X.revision+1&&!(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0))&&!e.client.pendingPurchase?K:null}function un(t){let r=t.run.paywall;if(X&&t.settlement?.requestId===X.requestId&&t.settlement.state==="settled"&&t.settlement.operationId===null&&t.run.id===X.runId&&t.run.status==="closed"&&!t.run.pendingRequest&&t.run.revision===X.revision+1&&t.run.nodeId===X.nodeId&&t.run.visit===X.visit&&r?.receiptId===X.receiptId&&r.selectionGeneration===X.selectionGeneration&&(r.quote?.operationId??null)===X.operationId&&(r.operation?.operationId??r.quote?.operationId??null)===X.operationId){let f=X.operationId===null&&r.selectionGeneration===0&&!r.quote&&!r.operation&&!r.purchaseRequestId,ne=ze({quote:r.quote,operation:r.operation,requestId:r.purchaseRequestId,pending:!1,destroyed:!1,canReselect:r.canReselect});(f||r.canReselect===!0&&ne.type==="native")&&(X.acknowledged=!0)}}let ke=null,He=new Set,fe={},Fe=!1,ue=(t,r=null)=>{b||(ke=r,Fe=!1,O.textContent=Fn(t,z),O.hidden=!1,M.hidden=e.client.pendingCommand===null,T(),le(e.onError,t))};function be(){let t=e.client.view;if(!t)throw new P("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision}}let U=Vn({client:e.client,doc:s,holder:q,reviewHolder:V,mountScreenPreview:p,loadingOptions:e,get chrome(){return _},get stopped(){return b},get answers(){return fe},suspend(t){i?.setSuspended(t)},resetScreen(){o="",c="",I=""},enqueue:me,fail:ue}),$e=_n({client:e.client,expected:be,fail:ue,get stopped(){return b},get reviewing(){return U.active},get key(){return o},get busy(){return $},get staleRead(){return Ke}}),Ue=Ln({client:e.client,expected:be,perform:Se,onIntent:e.onCustomerDataIntent,get stopped(){return b},get busy(){return $},get document(){return E?.document},get answers(){return fe}}),xe=t=>`${t.id}:${t.nodeId}:${t.visit}`,De=t=>t&&(t.screen||t.paywall)?xe(t):"";function Ce(){let t=e.client.view;F.disabled=!U.active&&($>0||!!e.client.pendingCommand||!t?.canBack||t.stopped||!["running","waiting"].includes(t.status)||!De(t)||c!==De(t)),F.hidden=!U.active&&!t?.canBack,on(F);let r=!!i&&!U.active;R.hidden=r&&!W?.active,k.hidden=!e.client.review||r&&!t?.canBack,r&&(d.textContent=""),T()}async function dn(t){if(!t)return;let r=e.client.view;await t;let f=e.client.view;if(!r||!f||f.id!==r.id||f.nodeId!==r.nodeId||f.visit!==r.visit||f.stopped||!["running","waiting"].includes(f.status))throw new P("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function Se(t,r=!1){if(!(($||ye||se||K)&&!r||b||U.active&&!r)){$++,u.setAttribute("aria-busy","true"),O.hidden=!0,ke=null,Fe=!1,Ce();try{if(r||await dn($e.inFlight),b)return;let f=await t();b||await me(e.client.view??f.run)}catch(f){ue(f,e.client.pendingCommand?.requestId??null)}finally{$=Math.max(0,$-1),u.setAttribute("aria-busy",String($>0)),b||(M.hidden=e.client.pendingCommand===null,Ce())}}}function Ne(){ln.schedule()}async function Ze(){if(!(b||Re||$)){if(U.active){await U.open(U.receipt);return}Re=!0;try{let t=e.client.pendingCommand;t&&e.client.settle&&await e.client.settle(t.requestId);let r=e.client.view,f=Ue.queries,ne=await e.client.get(r?.screen&&Object.keys(f).length?{nodeId:r.nodeId,visit:r.visit,revision:r.revision,components:f}:void 0);Fe&&!b&&(Fe=!1,O.hidden=!0,T()),!b&&f===Ue.queries&&await me(e.client.view??ne.run)}catch(t){ue(t),Fe=!b}finally{Re=!1}}}function Ge(t,r){if(W?.active){let ne=W;return ne.setDismissHandler(()=>cn(ne)),ne}let f=Be(n,e,"funnel",()=>cn(f));return W=f,f.start(t,r),f}function cn(t){b||pe||(pe=!0,t.finish("dismissed"),ve(),u.hidden=!0,e.client.view?Pe().finally(ae):ae())}function en(){clearTimeout(Ve?.timeout),Ve=void 0}function ve(){en(),qe?.abort(),qe=void 0,E?.destroy(),E=null,i?.destroy(),i=null,Oe?.(),Oe=void 0,C.open&&C.close(),q.replaceChildren(),q.style.cssText="",Y=void 0,o="",c="",y=!1,I="",G=""}function pn(){let t=s.defaultView;L?.responsive&&t&&E?.resizeViewport?.(t.innerHeight,t.innerWidth)}function nn(){L?.destroy(),L=void 0,de=""}function tn(t){let r=t.screen?.presentation;if(!r||r.type==="inline"){C.open&&C.close(),nn(),R.parentElement!==A&&A.append(R),u.parentElement!==n&&n.append(u),re(t),T();return}u.parentElement!==C&&(C.append(R,u),n.append(C)),re(t);let f=t.screen.content.document,ne=JSON.stringify([r,J]);if(ne!==de){nn(),de=ne;let ge={sm:420,md:640,lg:900},we="size"in r&&!r.backdrop?",0 0 0 100vmax #16142566":"";C.style.cssText=`box-sizing:border-box;padding:0;border:0;overflow:auto;background:${h.background};color:${h.text};`+(r.type==="fullscreen"?"width:100vw;height:100dvh;max-width:100vw;max-height:100dvh;margin:0;border-radius:0":`width:${ge[r.size]}px;max-width:calc(100vw - 32px);max-height:calc(100dvh - 32px);box-shadow:0 24px 80px #0003${we};`+(r.type==="sheet"?"margin:auto auto 0;border-radius:14px 14px 0 0":"border-radius:14px")),L=Cn(C,{presentation:r,theme:f.theme,pages:f.pages},pn),L.latch()}T(),C.setAttribute("aria-label",(H?.screen===t.screen?.content.document.name?H?.label:void 0)??E?.document?.name??t.screen?.content.document.name??"Funnel")}async function Hn(t){if(b||pe||ye&&(Me()||["running","waiting"].includes(t.status))||(l=t,ke&&e.client.pendingCommand?.requestId!==ke&&(O.hidden=!0,ke=null),z=t.locale.startsWith("zh"),k.textContent=z?"\u56DE\u770B":"History",F.textContent=U.active?z?"\u8FD4\u56DE\u5F53\u524D":"Return to current":z?"\u8FD4\u56DE":"Back",ce(),M.textContent=z?"\u91CD\u8BD5":"Retry",M.hidden=e.client.pendingCommand===null,d.textContent=t.pendingRequest?z?"\u6B63\u5728\u5904\u7406":"Processing":t.instruction?.type==="wait"?z?"\u7B49\u5F85\u4E2D":"Waiting":"",Ce(),Ee!==`${t.revision}:${t.visit}:${t.status}:${t.stopped}`&&(Ee=`${t.revision}:${t.visit}:${t.status}:${t.stopped}`,le(e.onState,structuredClone(t))),b||pe))return;if((!t.pendingRequest||ye&&t.status==="closed")&&["closed","ineligible","failed"].includes(t.status)){ae();return}if(t.stopped||e.client.configurationReady===!1){U.stop(),ve(),W?.finish("skipped"),u.hidden=!0,Ne();return}if(u.hidden=!1,U.active){Ne();return}let r=De(t),f=e.client.view;if(f&&f.revision>t.revision&&De(f)!==r)return;let ne=!t.instruction&&!t.pendingRequest&&t.nodeType==="screen"&&["running","waiting"].includes(t.status);r!==o&&(o&&W?.finish("dismissed"),ve(),o=r,fe={...t.answers},Ue.reset());let ge=xe(t);if(Le===ge){u.hidden=!0;return}if(ne&&!r){u.hidden=!0;let Q=Ge(!0,t.locale);!b&&!pe&&Ve?.key!==ge&&(en(),Ve={key:ge,timeout:setTimeout(()=>{let m=e.client.view;if(!Q.active||!m||xe(m)!==ge)return;Le=ge;let j=new Error("Funnel screen preparation timed out");Q.finish("error",j),ve(),ue(j)},Ae)}),Ne();return}en();let Z=Q=>{let m=e.client.view;return!b&&!pe&&!Ie&&!Q.aborted&&e.client.configurationReady!==!1&&!!m&&!m.stopped&&!["closed","ineligible","failed"].includes(m.status)&&De(m)===r},we=(Q,m)=>{Z(m)&&(Le=r,W?.finish("error",Q),ve(),u.hidden=!0,ue(Q))};if(r||(tn(t),t.instruction?.type!=="event"&&t.instruction?.type!=="open_url"&&W?.finish("skipped")),t.screen){let Q=t.screen.content;if(!E){let te=t.screen.presentation.type!=="inline",oe=Ge(te,t.locale);if(b||pe)return;let ie=(qe=new AbortController).signal;tn(t),Oe=te?En(C):je(u,n),E=p(q,{mode:"live",rendererUrl:e.client.webViewUrl,title:Q.document.name,...te?{hostPresentation:()=>L?.type??t.screen.presentation.type}:{},onResize:ee=>{Y=ee,L?.responsive&&L.setContentHeight(ee+A.getBoundingClientRect().height)},onAction(ee,he={},Gn={}){if(U.active||!Z(ie)||c!==r)return;fe={...fe,...Gn};let Jn=Object.fromEntries((t.screen?.inputs??[]).filter(({variable:Je})=>Object.hasOwn(fe,Je)).map(({variable:Je})=>[Je,fe[Je]]));Se(()=>e.client.submit({operation:"submit",...be(),input:{type:"screen",output:ee,answers:Jn,selection:he}}))},onAnswers:ee=>{U.active||!Z(ie)||c!==r||(fe={...fe,...ee})},onCustomerDataIntent:ee=>{U.active||!Z(ie)||c!==r||Ue.intent(ee).catch(ue)},onEscape:()=>{!Z(ie)||c!==r||U.active||se||K||Pe()},onError:ee=>{let he=new Error(ee);c===r?ue(he):we(he,ie)},onRendered:ee=>{if(!(!Z(ie)||c===r))try{oe.present(he=>{Oe?.(),Oe=void 0,ee&&(H={screen:Q.document.name,label:ee},C.setAttribute("aria-label",ee)),te&&(C.showModal(),L?.responsive&&C.focus({preventScroll:!0}),!he&&e.loading!=="host"&&Pn(C,L?.type??t.screen.presentation.type,L?.responsive)),c=r,y=te,Ce()}),Z(ie)&&$e.report(r)}catch(he){we(he,ie)}}}),pn()}let m={capabilities:t.screen.capabilities,customerData:t.screen.customerData,parameters:t.parameters,serverInput:{bindings:t.screen.inputs,answers:fe,values:t.screen.values}},j=JSON.stringify([Q,t.locale,m.parameters,t.screen.inputs,t.screen.values]);if(j!==I)E.update(Q.document,t.locale,m),I=j,B=JSON.stringify(m.capabilities),G=JSON.stringify(m.customerData);else{let te=JSON.stringify(m.capabilities);te!==B&&(E.updateCapabilities(m.capabilities),B=te),JSON.stringify(m.customerData)!==G&&(E.updateCustomerData(m.customerData),G=JSON.stringify(m.customerData))}let x=E;if(x)try{await(W?.wait(x.ready)??x.ready)}catch(te){qe&&we(te,qe.signal)}}else if(t.paywall&&!i){let Q=Ge(!0,t.locale);if(b||pe)return;let m=(qe=new AbortController).signal;tn(t);let j=await D(q,{loading:"host",signal:m,canInteract:()=>Z(m)&&!U.active&&!se&&!K,beforeAction:async()=>{$++;try{await dn($e.settled()),O.hidden=!0,ke=null,Fe=!1,T()}finally{$=Math.max(0,$-1)}},start:()=>An(e.client),onObservationChange:Ne,onPurchase:e.onPurchase,onCheckoutUrl:e.onCheckoutUrl,checkoutNavigation:e.checkoutNavigation,confirmOnHostedCheckout:e.confirmOnHostedCheckout,resolveOfferId:e.resolveOfferId,onEvent:e.onEvent,onOpenUrl:x=>e.onOpenUrl?e.onOpenUrl({receiptId:t.paywall.receiptId,url:x,openIn:"same_window"}):s.defaultView?.location.assign(x),onAction:async x=>{if(U.active)return;let te=await e.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:e.client.view?.revision??t.revision,input:{type:"screen",output:x,answers:{}}});await me(e.client.view??te.run)},onError:x=>{c===r?ue(x):we(x,m)}},{quoteError:x=>le(e.onError,x),present(x){Z(m)&&(Q.present(()=>{x(),c=r,y=!!q.querySelector("dialog[open]"),Ce()}),Z(m)&&$e.report(r))},async dismiss(){b||m.aborted||U.active||se||K||!ye&&!Z(m)||(ye=!0,await Pe())}}).catch(x=>(we(x,m),null));!Z(m)&&!(ye&&!b&&!m.aborted)?j?.host?.destroy():j&&(i=j.host,i?.setSuspended(U.active))}if(b||pe)return;Ce();let N=t.instruction;if(N&&(N.type==="open_url"||N.type==="event")&&!He.has(N.receiptId)){let Q=s.createElement("button");Q.type="button",Q.style.cssText=_.primary,_e(Q,()=>_.focus),q.style.cssText=_.stage,Q.textContent=N.type==="open_url"?`${z?"\u524D\u5F80":"Continue to"} ${new URL(N.url).host}`:z?"\u7EE7\u7EED":"Continue",Q.onclick=()=>{let m=be(),j=N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="new_window"?$n(N.url):null;Se(async()=>{let x="success";if(N.type==="open_url")if(e.onOpenUrl)try{x=await e.onOpenUrl({receiptId:N.receiptId,url:N.url,openIn:N.openIn})===!1?"failed":"opened"}catch(oe){le(e.onError,oe),x="failed"}else x=N.openIn==="new_window"&&!j?"failed":"opened";if(N.type==="event"){if(!e.onEvent)throw new P("EVENT_HANDLER_REQUIRED","Provide the event handler");await e.onEvent(N.event)}if(b||e.client.view?.nodeId!==m.nodeId||e.client.view.visit!==m.visit)throw new P("PRECONDITION_FAILED","The client action visit changed");let te=await e.client.submit({operation:"submit",...m,input:{type:"client_action",receiptId:N.receiptId,outcome:x}});return He.add(N.receiptId),N.type==="open_url"&&!e.onOpenUrl&&N.openIn==="same_window"&&s.defaultView?.location.assign(N.url),te})},W?.active?W.present(()=>q.replaceChildren(Q)):q.replaceChildren(Q)}!t.pendingRequest&&t.status==="completed"&&!He.has(`complete:${t.id}`)&&(He.add(`complete:${t.id}`),le(e.onComplete,structuredClone(t))),Ne()}function $n(t){let r=s.defaultView?.open(t,"_blank")??null;return r&&(r.opener=null),r}function me(t){return Ce(),Ye=Ye.catch(()=>{}).then(async()=>{try{await Hn(t)}catch(r){throw W?.active&&(Le=xe(t),W.finish("error",r),ve(),u.hidden=!0),r}}),Ye}let Un=e.client.subscribe(t=>{if(!an){if(t.stopped&&y&&!ye){l=t,ae();return}!ye&&(t.stopped||e.client.configurationReady===!1||o&&c!==o&&(De(t)!==o||["closed","ineligible","failed"].includes(t.status)))&&(ve(),W?.finish("dismissed"),u.hidden=!0),me(t).catch(ue)}}),xn=e.client.subscribeError?.(ue);function Pe(t){if(Ie)return Ie;if(b||!t&&(se||K))return Promise.resolve();let r=!t&&Me();return!r&&e.client.view&&!["running","waiting"].includes(e.client.view.status)?(l=e.client.view,ae(),Promise.resolve()):(Ie=Se(async()=>{let f=r?await e.client.retry():await e.client.submit({operation:"close",...t??be()});return t&&un(f),f},!0).then(()=>{let f=e.client.view;f?.status==="closed"&&!Me()&&(l=f,ae())}).finally(()=>{Ie=null}),Ie)}function ae(){S?.destroy(),!b&&(b=!0,e.signal?.removeEventListener("abort",ae),a?.removeEventListener("abort",ae),W?.finish("dismissed"),ln.destroy(),Un(),xn?.(),ve(),nn(),U.stop(),C.remove(),u.remove(),v(),le(e.onDismiss,l?structuredClone(l):null))}F.onclick=()=>{if(!F.disabled){if(U.active){U.exit();return}Se(()=>e.client.submit({operation:"back",...be()}))}},k.onclick=()=>{U.open()},R.onclick=()=>{W?.active?W.dismiss():se||Pe()},M.onclick=()=>{Me()?Pe():Se(()=>e.client.retry())},C.addEventListener("cancel",t=>{t.preventDefault(),W?.active?W.dismiss():se||Pe()}),e.signal?.addEventListener("abort",ae,{once:!0}),a?.addEventListener("abort",ae,{once:!0});try{let t=e.client.view;if(t)((e.client.viewAgeMs??sn)>=sn||t.instruction?.type==="evaluate_segment")&&(Ke=Ze().finally(()=>{Ke=null})),await me(t);else{u.hidden=!0;let r=Ge(e.client.view?.screen?.presentation.type!=="inline",e.client.view?.locale);if(b||pe)throw new DOMException("Presentation cancelled","AbortError");let f=await r.wait(e.client.get(),Ae);an=!1,await me(e.client.view??f.run)}}catch(t){throw W?.finish("error",t),ae(),t}return{destroy:ae,refresh:Ze,get recovery(){let t=Xe();if(t)return t;if(!b&&!$&&!ye&&!se&&i){let r=i.recovery;if(r.type!=="native")return r}return{type:"recover",operationId:e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,requestId:e.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let t=Xe();if(t)return Promise.resolve(t);let r=e.client.pendingPurchase?.operationId??e.client.view?.paywall?.quote?.operationId??K?.operationId??null,f=()=>({type:"recover",operationId:r,requestId:e.client.pendingCommand?.requestId??null});if(e.client.hasDurableJournal!==!0){let N=i?.recovery;return Promise.resolve(N&&N.type!=="native"&&N.type!=="cancel"?N:f())}let ne=(e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[])).some(N=>N.operation==="close");if(b&&!(ne||K&&e.client.view?.status==="closed")||$||Re||Ie||U.active||!i&&!K&&!ne)return Promise.resolve(f());let ge=i,Z=(async()=>{try{if(!K&&ne){let m=await e.client.retry();return await me(e.client.view??m.run),f()}if(!K){let m=await ge.prepareFallback();if(m.type!=="native")return m;if(e.client.hasDurableJournal!==!0)return f();K=m}let N=e.client.pendingCommands??(e.client.pendingCommand?[e.client.pendingCommand]:[]);if(N.length){let m=N.find(x=>x.operation==="close");if(!m||!X||m.requestId!==X.requestId)return f();let j=await e.client.retry();un(j),await me(e.client.view??j.run)}else{let m=e.client.view,j=m?.paywall;if(!m||!j||j.selectionGeneration===void 0||(j.quote?.operationId??null)!==K.operationId||K.operationId!==null&&j.canReselect!==!0)return f();let x=j.selectionGeneration,te=await e.client.get();await me(e.client.view??te.run);let oe=e.client.view,ie=oe?.paywall;if(!oe||!ie||!["running","waiting"].includes(oe.status)||oe.stopped||oe.id!==m.id||oe.nodeId!==m.nodeId||oe.visit!==m.visit||ie.receiptId!==j.receiptId||ie.selectionGeneration!==x||(ie.quote?.operationId??null)!==K.operationId||K.operationId!==null&&ie.canReselect!==!0||e.client.pendingPurchase||(e.client.pendingCommands?.length??(e.client.pendingCommand?1:0)))return f();let ee=be();X={runId:oe.id,operationId:K.operationId,revision:ee.revision,requestId:ee.requestId,nodeId:oe.nodeId,visit:oe.visit,receiptId:ie.receiptId,selectionGeneration:x,acknowledged:!1},await Pe(ee)}let Q=Xe();return Q?(ae(),Q):f()}catch(N){return ue(N),f()}})();se=Z;let we=()=>{se===Z&&(se=null)};return Z.then(we,we),Z},review:U.open,exitReview:U.exit,get unappliedDrafts(){return U.drafts}}}function Vt(n,g,w){return zn(n,g,w)}export{Bn as a,Mn as b,zn as c,Vt as d};
@@ -1 +1 @@
1
- import{e as h}from"./chunk-EZ5RCVVY.js";import{b as J}from"./chunk-23WNEOK4.js";import{c as N,e as x}from"./chunk-STPMMA64.js";import{v as Q}from"./chunk-LZV4QJ5E.js";import{a as j,f as H,g as K,h as B,i as F}from"./chunk-B3KFE57L.js";import{b as L}from"./chunk-ACFQLHJR.js";import{b as U}from"./chunk-CLAZ7NVN.js";import{a as M}from"./chunk-J4VTKRH7.js";import{qa as G}from"./chunk-WRUW2UIJ.js";import{a as l}from"./chunk-HJLGRW4A.js";import{a as W}from"./chunk-DSPLGTQI.js";async function ce(I,o){if(!M.test(o.customerToken))throw new l("INVALID_TOKEN","A verified Customer credential is required");if(I.session&&I.session.peek()!==o.customerToken)throw new l("SCOPE_MISMATCH","Paywall credential does not match the shared session");let u=h.resolvePaywall.request.parse({funnelId:o.funnelId,funnelVersionId:o.funnelVersionId,selector:o.paywallVersionId?{type:"version",versionId:o.paywallVersionId}:{type:"paywall",paywallId:o.paywallId},commerce:o.commerce,locale:o.locale,...o.requirement?{requirement:o.requirement}:{}}),S=U(I);I.session||S.identify(o.customerToken);let r=null,P=!1,D=new AbortController,s=null,c=null,v=null,w=null,R=null,d=null,f=null,A=0,O=null,_="",V=0,b=new Map,q=new Set;function g(){if(P)throw new l("IDENTITY_CHANGED","Paywall is closed")}function k(){let e=JSON.stringify([A,f!==null]);if(!O||e!==_){_=e;let t=Y(++V);O=t;let a=()=>{O===t&&(O=null)};t.then(a,a)}return O.then(t=>structuredClone(t))}async function Y(e){g();let t=h.resolvePaywall,a=await N(S.request,t,{...u,selector:r?{type:"version",versionId:r.id}:u.selector});J(u,a.paywall.check,a.scope);let i=await x(I,a.paywall);if(g(),o.paywallVersionId?i.id!==o.paywallVersionId:i.paywallId!==o.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");if(r&&(!H(i,r)||i.paywallId!==r.paywallId))throw new l("INVALID_RESPONSE","The pinned Paywall or Offering Version changed");if(e!==V)return structuredClone(r??i);r=i;for(let m of q)W(m,structuredClone(r));return structuredClone(r)}async function E(e){if(g(),w&&e!=="read")throw new l("COMMAND_PENDING","Wait for the original quote");if(!s)throw new l("INVALID_REQUEST","A quoted purchase is required");let t=s;if(e!=="read"){if(f){if(d===e)return f;throw new l("COMMAND_PENDING","Wait for the original purchase command")}if(d&&d!==e)throw new l("COMMAND_PENDING","Read the original purchase before changing an uncertain command");d=e,A++,V++}let a=d,i=A,m=e==="read"&&f===null,p=JSON.stringify([t.operationId,i,f!==null]);if(e==="read"&&b.has(p))return b.get(p).then(n=>structuredClone(n));let C=e==="read"?h.readSubscriptionOperation:h.attach,y=(async()=>{let n=await N(S.request,C,{operationId:t.operationId,...e==="read"?{}:{intent:e},...e==="confirm"&&t.merchantTerms?{merchantConfirmation:Q(t.merchantTerms)}:{}});return K(n.operation,{operationId:t.operationId,currency:u.commerce.currency},"The purchase operation changed"),g(),s?.operationId!==t.operationId?structuredClone(n.operation):(c=F(c,n.operation),(e!=="read"||m&&f===null)&&A===i&&d===a&&(d=null),structuredClone(c))})();if(e!=="read"){f=y;let n=()=>{f===y&&(f=null)};y.then(n,n)}else{b.set(p,y);let n=()=>{b.get(p)===y&&b.delete(p)};y.then(n,n)}return y.then(n=>structuredClone(n))}let T={signal:D.signal,get view(){return r?structuredClone(r):null},get quote(){return s?structuredClone(s):null},get operation(){return c?structuredClone(c):null},get webViewUrl(){return"bundled"},get recovery(){return j({quote:s,operation:c,requestId:R,pending:w!==null||d!==null,destroyed:P})},get pendingCancellation(){return!P&&d==="cancel"},refresh:k,subscribe(e){return P?()=>{}:(q.add(e),()=>q.delete(e))},async preview(e){if(g(),!r)throw new l("INVALID_REQUEST","Load the Paywall first");let t=r.document.buttons[e.actionId];if(t?.type!=="checkout")throw new l("INVALID_REQUEST","Choose an authored purchase action");let a=L(t.product,e.selection,r.capabilities);if(!a)throw new l("PRODUCT_UNAVAILABLE","Choose an available Product");let i=G(r.document.screen,a,e.selection,r.capabilities),m=h.previewAttach.request.parse({funnelId:u.funnelId,funnelVersionId:u.funnelVersionId,requestId:e.requestId,plans:[{productVersionId:a,...Object.keys(i).length?{featureQuantities:i}:{}}],provider:u.commerce.provider,currency:u.commerce.currency,...e.offerId?{offerId:e.offerId}:{},...e.nativeOffer?{nativeOffer:e.nativeOffer}:{}}),p=JSON.stringify(m);if(v&&v!==p&&(w||d||!c||c.status==="pending"))throw new l("COMMAND_PENDING","Finish or cancel the original purchase before changing it");if(v===p){if(w)return w;if(s)return structuredClone(s)}v!==p&&(s=null,c=null),v=p,R=m.requestId;let C=(async()=>{let y=h.previewAttach,n=await N(S.request,y,m);return g(),B(n.quote,{productVersionId:a,featureQuantities:i,currency:u.commerce.currency,provider:u.commerce.provider},"The purchase quote changed its selected Product or presentment"),s=n.quote,c=null,structuredClone(s)})();w=C;try{return await C}finally{w===C&&(w=null)}},confirm:()=>E("confirm"),cancel:()=>E("cancel"),read:()=>E("read"),destroy(){P||(P=!0,D.abort(),q.clear(),b.clear(),z?.(),S.dispose(),r=null,s=null,c=null,v=null,R=null)}},z=I.session?.subscribeIdentity(T.destroy);try{return await k(),T}catch(e){throw T.destroy(),e}}export{ce as a};
1
+ import{e as h}from"./chunk-EZ5RCVVY.js";import{b as J}from"./chunk-23WNEOK4.js";import{c as N,e as x}from"./chunk-WK4WQZHK.js";import{v as Q}from"./chunk-LZV4QJ5E.js";import{a as j,f as H,g as K,h as B,i as F}from"./chunk-B3KFE57L.js";import{b as L}from"./chunk-ACFQLHJR.js";import{b as U}from"./chunk-XZEGVBAI.js";import{a as M}from"./chunk-J4VTKRH7.js";import{qa as G}from"./chunk-WRUW2UIJ.js";import{a as l}from"./chunk-HJLGRW4A.js";import{a as W}from"./chunk-DSPLGTQI.js";async function ce(I,o){if(!M.test(o.customerToken))throw new l("INVALID_TOKEN","A verified Customer credential is required");if(I.session&&I.session.peek()!==o.customerToken)throw new l("SCOPE_MISMATCH","Paywall credential does not match the shared session");let u=h.resolvePaywall.request.parse({funnelId:o.funnelId,funnelVersionId:o.funnelVersionId,selector:o.paywallVersionId?{type:"version",versionId:o.paywallVersionId}:{type:"paywall",paywallId:o.paywallId},commerce:o.commerce,locale:o.locale,...o.requirement?{requirement:o.requirement}:{}}),S=U(I);I.session||S.identify(o.customerToken);let r=null,P=!1,D=new AbortController,s=null,c=null,v=null,w=null,R=null,d=null,f=null,A=0,O=null,_="",V=0,b=new Map,q=new Set;function g(){if(P)throw new l("IDENTITY_CHANGED","Paywall is closed")}function k(){let e=JSON.stringify([A,f!==null]);if(!O||e!==_){_=e;let t=Y(++V);O=t;let a=()=>{O===t&&(O=null)};t.then(a,a)}return O.then(t=>structuredClone(t))}async function Y(e){g();let t=h.resolvePaywall,a=await N(S.request,t,{...u,selector:r?{type:"version",versionId:r.id}:u.selector});J(u,a.paywall.check,a.scope);let i=await x(I,a.paywall);if(g(),o.paywallVersionId?i.id!==o.paywallVersionId:i.paywallId!==o.paywallId)throw new l("INVALID_RESPONSE","The requested Paywall changed");if(r&&(!H(i,r)||i.paywallId!==r.paywallId))throw new l("INVALID_RESPONSE","The pinned Paywall or Offering Version changed");if(e!==V)return structuredClone(r??i);r=i;for(let m of q)W(m,structuredClone(r));return structuredClone(r)}async function E(e){if(g(),w&&e!=="read")throw new l("COMMAND_PENDING","Wait for the original quote");if(!s)throw new l("INVALID_REQUEST","A quoted purchase is required");let t=s;if(e!=="read"){if(f){if(d===e)return f;throw new l("COMMAND_PENDING","Wait for the original purchase command")}if(d&&d!==e)throw new l("COMMAND_PENDING","Read the original purchase before changing an uncertain command");d=e,A++,V++}let a=d,i=A,m=e==="read"&&f===null,p=JSON.stringify([t.operationId,i,f!==null]);if(e==="read"&&b.has(p))return b.get(p).then(n=>structuredClone(n));let C=e==="read"?h.readSubscriptionOperation:h.attach,y=(async()=>{let n=await N(S.request,C,{operationId:t.operationId,...e==="read"?{}:{intent:e},...e==="confirm"&&t.merchantTerms?{merchantConfirmation:Q(t.merchantTerms)}:{}});return K(n.operation,{operationId:t.operationId,currency:u.commerce.currency},"The purchase operation changed"),g(),s?.operationId!==t.operationId?structuredClone(n.operation):(c=F(c,n.operation),(e!=="read"||m&&f===null)&&A===i&&d===a&&(d=null),structuredClone(c))})();if(e!=="read"){f=y;let n=()=>{f===y&&(f=null)};y.then(n,n)}else{b.set(p,y);let n=()=>{b.get(p)===y&&b.delete(p)};y.then(n,n)}return y.then(n=>structuredClone(n))}let T={signal:D.signal,get view(){return r?structuredClone(r):null},get quote(){return s?structuredClone(s):null},get operation(){return c?structuredClone(c):null},get webViewUrl(){return"bundled"},get recovery(){return j({quote:s,operation:c,requestId:R,pending:w!==null||d!==null,destroyed:P})},get pendingCancellation(){return!P&&d==="cancel"},refresh:k,subscribe(e){return P?()=>{}:(q.add(e),()=>q.delete(e))},async preview(e){if(g(),!r)throw new l("INVALID_REQUEST","Load the Paywall first");let t=r.document.buttons[e.actionId];if(t?.type!=="checkout")throw new l("INVALID_REQUEST","Choose an authored purchase action");let a=L(t.product,e.selection,r.capabilities);if(!a)throw new l("PRODUCT_UNAVAILABLE","Choose an available Product");let i=G(r.document.screen,a,e.selection,r.capabilities),m=h.previewAttach.request.parse({funnelId:u.funnelId,funnelVersionId:u.funnelVersionId,requestId:e.requestId,plans:[{productVersionId:a,...Object.keys(i).length?{featureQuantities:i}:{}}],provider:u.commerce.provider,currency:u.commerce.currency,...e.offerId?{offerId:e.offerId}:{},...e.nativeOffer?{nativeOffer:e.nativeOffer}:{}}),p=JSON.stringify(m);if(v&&v!==p&&(w||d||!c||c.status==="pending"))throw new l("COMMAND_PENDING","Finish or cancel the original purchase before changing it");if(v===p){if(w)return w;if(s)return structuredClone(s)}v!==p&&(s=null,c=null),v=p,R=m.requestId;let C=(async()=>{let y=h.previewAttach,n=await N(S.request,y,m);return g(),B(n.quote,{productVersionId:a,featureQuantities:i,currency:u.commerce.currency,provider:u.commerce.provider},"The purchase quote changed its selected Product or presentment"),s=n.quote,c=null,structuredClone(s)})();w=C;try{return await C}finally{w===C&&(w=null)}},confirm:()=>E("confirm"),cancel:()=>E("cancel"),read:()=>E("read"),destroy(){P||(P=!0,D.abort(),q.clear(),b.clear(),z?.(),S.dispose(),r=null,s=null,c=null,v=null,R=null)}},z=I.session?.subscribeIdentity(T.destroy);try{return await k(),T}catch(e){throw T.destroy(),e}}export{ce as a};
@@ -1,4 +1,4 @@
1
- import{a as $,b as N,c as J,d as q}from"./chunk-XRR5X74T.js";import{a as P}from"./chunk-3VUPVXAV.js";import{a as D}from"./chunk-OHOROFWN.js";import{a as _}from"./chunk-DSPLGTQI.js";import{b as C,c as O,e as j}from"./chunk-6BTJNSQQ.js";async function B(e,t,o,n={}){let r=n.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(r);let u;try{u=await P(e,t,{signal:o,error:()=>Error(r)})}catch(p){throw o.aborted?Error(r):p}return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(u))}async function G(e,t){if(!e?.body)return;let o=new AbortController,n=()=>o.abort(t?.reason);t?.addEventListener("abort",n,{once:!0}),t?.aborted&&n();let r=setTimeout(()=>o.abort(Error("Exposure response timeout")),2e3);try{return await P(e,16384,{signal:o.signal,error:()=>Error("Exposure response budget")})}finally{clearTimeout(r),t?.removeEventListener("abort",n)}}var be=2*1024*1024,V=256*1024;async function Y(e,t,o,n){let r=()=>{},s=new Promise((u,p)=>{r=()=>p(n.reason),n.addEventListener("abort",r,{once:!0}),n.aborted&&r()});try{let u=e(t,{...o,signal:n});return u.then(p=>{n.aborted&&p.body?.cancel().catch(()=>{})},()=>{}),await Promise.race([u,s])}finally{n.removeEventListener("abort",r)}}async function M(e,t,o,n=!1){if(new TextEncoder().encode(o).byteLength>65536)throw Error("Exposure request budget");let r=new URL(t);r.searchParams.set("sdkVersion",D.version);let s=new AbortController,u=setTimeout(()=>s.abort(Error("Exposure request timeout")),5e3);try{let p=await Y(e,r.href,{method:"POST",headers:{"Content-Type":"text/plain"},body:o,credentials:"omit",keepalive:n,redirect:"error"},s.signal),a=await G(p,s.signal),c;try{c=a&&JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(a))}catch{}return{response:p,receipt:c}}finally{clearTimeout(u)}}function H(e){let t,o=!1;return{async read(n,r){if(o)throw Error("Experiment client stopped");t?.abort(Error("Experiment request superseded"));let s=new AbortController;t=s;let{signal:u}=s,p=setTimeout(()=>s.abort(Error("Experiment request timeout")),5e3);try{let a=await Y(e,n,{cache:"no-cache",credentials:"omit",redirect:"error"},u),c=await B(a,r,u);return u.throwIfAborted(),c}finally{clearTimeout(p),t===s&&(t=void 0)}},destroy(){o=!0,t?.abort(Error("Experiment client stopped")),t=void 0}}}var Q=20,ie=65536,se=5e3,ae=5,K=e=>new TextEncoder().encode(JSON.stringify(e)).length;function ce(e,t){let o=e,n=r=>Number.isSafeInteger(r)&&r>=0;return!!o&&typeof o=="object"&&n(o.inserted)&&n(o.duplicates)&&n(o.skipped)&&Array.isArray(o.rejected)&&o.inserted+o.duplicates+o.skipped+o.rejected.length===t&&o.rejected.every(r=>!!r&&typeof r=="object"&&n(r.index)&&r.index<t&&typeof r.reason=="string")&&new Set(o.rejected.map(r=>r.index)).size===o.rejected.length}function F(e){let t=[],o,n,r=(a,c)=>{try{e.log?.(`${e.label} ${a}`,c)}catch{}};function s(a){o===void 0&&!n&&t.length&&(o=setTimeout(()=>{p()},a))}async function u(a,c){let g,f;try{({response:g,receipt:f}=await M(e.fetch,e.endpoint,JSON.stringify({events:a}),c))}catch(h){return r("not sent",{error:h}),!1}return g.status===408||g.status===429||g.status>=500?(r("not sent",{status:g.status}),!1):g.ok?ce(f,a.length)?(f.rejected.length&&r("rejected",{rejected:f.rejected}),!0):(r("not acknowledged",{status:g.status}),!1):(r("rejected",{status:g.status,events:a.length}),!0)}function p(a=!0){if(n)return n;clearTimeout(o),o=void 0;let c=[],g=K({events:[]});for(;t.length&&c.length<Q;){let m=K(t[0].event)+(c.length?1:0);if(c.length&&g+m>ie)break;c.push(t.shift()),g+=m}if(!c.length)return Promise.resolve();let f=1e3,h=u(c.map(m=>m.event),a).then(m=>{if(m)return;f=se;let y=c.filter(b=>++b.attempts<ae);y.length<c.length&&r("dropped after retries",{events:c.length-y.length}),t.unshift(...y)}).finally(()=>{n===h&&(n=void 0),s(f)});return n=h,h}return{push(a){t.push({event:structuredClone(a),attempts:0}),t.length>=Q?p():s(1e3)},flush:p}}/*!
1
+ import{a as $,b as N,c as J,d as q}from"./chunk-ZYTT7ZAB.js";import{a as P}from"./chunk-3VUPVXAV.js";import{a as D}from"./chunk-FVGUBIVT.js";import{a as _}from"./chunk-DSPLGTQI.js";import{b as C,c as O,e as j}from"./chunk-6BTJNSQQ.js";async function B(e,t,o,n={}){let r=n.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(r);let u;try{u=await P(e,t,{signal:o,error:()=>Error(r)})}catch(p){throw o.aborted?Error(r):p}return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(u))}async function G(e,t){if(!e?.body)return;let o=new AbortController,n=()=>o.abort(t?.reason);t?.addEventListener("abort",n,{once:!0}),t?.aborted&&n();let r=setTimeout(()=>o.abort(Error("Exposure response timeout")),2e3);try{return await P(e,16384,{signal:o.signal,error:()=>Error("Exposure response budget")})}finally{clearTimeout(r),t?.removeEventListener("abort",n)}}var be=2*1024*1024,V=256*1024;async function Y(e,t,o,n){let r=()=>{},s=new Promise((u,p)=>{r=()=>p(n.reason),n.addEventListener("abort",r,{once:!0}),n.aborted&&r()});try{let u=e(t,{...o,signal:n});return u.then(p=>{n.aborted&&p.body?.cancel().catch(()=>{})},()=>{}),await Promise.race([u,s])}finally{n.removeEventListener("abort",r)}}async function M(e,t,o,n=!1){if(new TextEncoder().encode(o).byteLength>65536)throw Error("Exposure request budget");let r=new URL(t);r.searchParams.set("sdkVersion",D.version);let s=new AbortController,u=setTimeout(()=>s.abort(Error("Exposure request timeout")),5e3);try{let p=await Y(e,r.href,{method:"POST",headers:{"Content-Type":"text/plain"},body:o,credentials:"omit",keepalive:n,redirect:"error"},s.signal),a=await G(p,s.signal),c;try{c=a&&JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(a))}catch{}return{response:p,receipt:c}}finally{clearTimeout(u)}}function H(e){let t,o=!1;return{async read(n,r){if(o)throw Error("Experiment client stopped");t?.abort(Error("Experiment request superseded"));let s=new AbortController;t=s;let{signal:u}=s,p=setTimeout(()=>s.abort(Error("Experiment request timeout")),5e3);try{let a=await Y(e,n,{cache:"no-cache",credentials:"omit",redirect:"error"},u),c=await B(a,r,u);return u.throwIfAborted(),c}finally{clearTimeout(p),t===s&&(t=void 0)}},destroy(){o=!0,t?.abort(Error("Experiment client stopped")),t=void 0}}}var Q=20,ie=65536,se=5e3,ae=5,K=e=>new TextEncoder().encode(JSON.stringify(e)).length;function ce(e,t){let o=e,n=r=>Number.isSafeInteger(r)&&r>=0;return!!o&&typeof o=="object"&&n(o.inserted)&&n(o.duplicates)&&n(o.skipped)&&Array.isArray(o.rejected)&&o.inserted+o.duplicates+o.skipped+o.rejected.length===t&&o.rejected.every(r=>!!r&&typeof r=="object"&&n(r.index)&&r.index<t&&typeof r.reason=="string")&&new Set(o.rejected.map(r=>r.index)).size===o.rejected.length}function F(e){let t=[],o,n,r=(a,c)=>{try{e.log?.(`${e.label} ${a}`,c)}catch{}};function s(a){o===void 0&&!n&&t.length&&(o=setTimeout(()=>{p()},a))}async function u(a,c){let g,f;try{({response:g,receipt:f}=await M(e.fetch,e.endpoint,JSON.stringify({events:a}),c))}catch(h){return r("not sent",{error:h}),!1}return g.status===408||g.status===429||g.status>=500?(r("not sent",{status:g.status}),!1):g.ok?ce(f,a.length)?(f.rejected.length&&r("rejected",{rejected:f.rejected}),!0):(r("not acknowledged",{status:g.status}),!1):(r("rejected",{status:g.status,events:a.length}),!0)}function p(a=!0){if(n)return n;clearTimeout(o),o=void 0;let c=[],g=K({events:[]});for(;t.length&&c.length<Q;){let m=K(t[0].event)+(c.length?1:0);if(c.length&&g+m>ie)break;c.push(t.shift()),g+=m}if(!c.length)return Promise.resolve();let f=1e3,h=u(c.map(m=>m.event),a).then(m=>{if(m)return;f=se;let y=c.filter(b=>++b.attempts<ae);y.length<c.length&&r("dropped after retries",{events:c.length-y.length}),t.unshift(...y)}).finally(()=>{n===h&&(n=void 0),s(f)});return n=h,h}return{push(a){t.push({event:structuredClone(a),attempts:0}),t.length>=Q?p():s(1e3)},flush:p}}/*!
2
2
  Portions ported from GrowthBook sdk-js @ ed29827 (GrowthBook.ts auto experiments, util.ts mergeQueryStrings,
3
3
  plugins/auto-attributes.ts). Copyright (c) GrowthBook, Inc. MIT License.
4
4
  */function ue(e,t){let o,n;try{o=new URL(e),n=new URL(t)}catch{return t}return o.searchParams.forEach((r,s)=>{n.searchParams.has(s)||n.searchParams.set(s,r)}),n.toString()}function de(e,t){let o=navigator.userAgent,n=new URLSearchParams(t.search),r={};for(let s of["source","medium","campaign","term","content"]){let u=n.get(`utm_${s}`);u!==null&&(r[`utm${s[0].toUpperCase()}${s.slice(1)}`]=u)}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(o)?"edge":/Chrome/.test(o)?"chrome":/Firefox/.test(o)?"firefox":/Safari/.test(o)?"safari":"unknown",deviceType:/Mobi/.test(o)?"mobile":"desktop",...r}}function le(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(n=>!!n&&!["namespace","status","url","groups"].some(r=>Object.hasOwn(n,r))&&(n.hashVersion===void 0||n.hashVersion===2)&&typeof n.key=="string"&&Array.isArray(n.variations)&&n.variations.length>=2&&n.variations.every(r=>!!r&&typeof r.urlRedirect=="string")&&(n.urlPatterns===void 0||Array.isArray(n.urlPatterns)))&&!!t.savedGroups&&typeof t.savedGroups=="object"&&!Array.isArray(t.savedGroups)))throw new Error("Invalid page experiment payload");return t}function Te(e){if(e.configuration&&e.configuration.scope.environmentId!==e.environmentId)throw new Error("Page configuration belongs to another App environment");let t=J(e.baseUrl);if(!/^[0-9a-f-]{36}$/i.test(e.environmentId))throw new Error("environmentId must be the App environment ID");let o=e.fetch??globalThis.fetch.bind(globalThis),n=H(async(i,d)=>{let l=await o(i,d);if(!l.ok)throw l.body?.cancel().catch(()=>{}),new Error(`Page experiments unavailable (${l.status})`);return l}),r=e.log?(i,d)=>_(e.log,i,d):void 0,s=`${t}/api/v1/page-experiments/${e.environmentId}`,u=$(e.deviceIdCookie??"indiana_did"),p=N(),a=null,c={...e.attributes??{}},g="",f=!1,h=!1,m=0,y=0,b=new Map,S=F({endpoint:`${s}/events`,fetch:o,log:r,label:"Exposure"}),k=S.flush,E={trackedExperiments:new Set,log:r,onExperimentViewed:(i,d)=>{e.trackExposures===!1||a?.trackExposures===!1||S.push({eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString(),deviceId:u,...p?{sessionId:p}:{},url:location.href,pageTitle:document.title.slice(0,512),experimentKey:i.key,variationKey:d.key})}},z=()=>{E.url=location.href,E.attributes={...de(u,location),...c}};function W(i){if(!e.disableCrossOriginUrlRedirects)return!1;try{let d=new URL(location.href);return i.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 X(i,d){let l=e.configuration?.snapshot?.generation,v=y,te=location.href;g=i;let re=e.navigate??(w=>location.replace(w)),ne=e.navigateDelay??(e.navigate?0:100),oe=e.maxNavigateDelay??1e3;Promise.all([Promise.race([d,new Promise(w=>setTimeout(w,oe))]),new Promise(w=>setTimeout(w,ne))]).then(()=>{!f&&v===y&&location.href===te&&(!e.configuration||e.configuration.fresh&&e.configuration.snapshot?.generation===l)&&re(i)})}function x(){if(!(!a||f||e.configuration&&!e.configuration.fresh)){z();for(let i of a.experiments){if(W(i)){r?.("Auto experiment blocked",{id:i.key});continue}let d;try{d=j(i,E)}catch(l){r?.("Skipping page experiment",{id:i.key,error:String(l)});continue}if(b.set(i.key,d),!!d.inExperiment){if(d.value.urlRedirect){let l=i.persistQueryString?ue(location.href,d.value.urlRedirect):d.value.urlRedirect;C(l,i.urlPatterns??[])?r?.("Skipping redirect because original URL matches redirect URL",{id:i.key}):l!==g&&X(l,k())}break}}}}let R="",Z=()=>{location.href!==R&&(y++,R=location.href,g="",x())},T,L;function ee(){T??=q(Z),addEventListener("pagehide",I)}let I=()=>{k()};async function A(){if(f)return!1;let i=++m,d;try{d=e.configuration?await e.configuration.pageExperiments():await n.read(s,V)}catch(v){if(f||i!==m)return!1;throw v}if(f||i!==m)return!1;let l=le(d);if(l.environmentId.toLowerCase()!==e.environmentId.toLowerCase())throw new Error("Page experiment payload scope changed");return a?.trackExposures===!1&&l.trackExposures&&E.trackedExperiments?.clear(),a=l,E.savedGroups=O(l.savedGroups),!0}function U(){f||(L??=e.configuration?.subscribe(()=>{!f&&e.configuration?.fresh&&A().then(i=>{i&&x()}).catch(i=>r?.("Page configuration unavailable",{error:String(i)}))}),ee(),R=location.href)}return{async start(){h||f||(h=!0,await A()&&(U(),x()))},async refresh(){await A()&&(y++,h&&U(),g="",x())},setAttributes(i){y++,g="",c={...i},x()},getResults(){return new Map(b)},get generation(){return a?.generation??null},destroy(){f||(f=!0,m++,n.destroy(),L?.(),T?.(),removeEventListener("pagehide",I),a=null,b.clear(),k())}}}export{be as a,H as b,F as c,ue as d,de as e,le as f,Te as g};
@@ -1 +1 @@
1
- import{s as g,t as w}from"./chunk-QPHT6QHE.js";import{n as I,s as h}from"./chunk-4ZVVG5LM.js";import{a as y}from"./chunk-CLAZ7NVN.js";import{a}from"./chunk-HJLGRW4A.js";import{a as T}from"./chunk-3VUPVXAV.js";import{b as P}from"./chunk-OHOROFWN.js";import{a as f}from"./chunk-ZY4XAKNQ.js";function b(r,n,o){if(!["subscriptions/operations/read","subscriptions/updates/read","subscriptions/refunds/read"].includes(r))return;let e=n,c=o,s=c.operation;if(s.operationId!==e.operationId||[s.authority,s.merchantExecution].some(t=>t&&(t.operationId!==e.operationId||e.customerId!==void 0&&t.customerId!==e.customerId))||s.authority&&(s.authority.scope.projectId!==c.scope.projectId||s.authority.scope.environment!==c.scope.environment))throw new a("INVALID_RESPONSE","Original commerce operation changed")}function D(r){try{return structuredClone(r)}catch{return r}}async function q(r,n){let o=r.captureIdentity?.(),{apiOperations:e}=await import("./operation-contracts-SP2RZUT3.js");return o?.(),e[n]}function E(r,n,o,e){try{return r.parse(n)}catch(c){throw e&&c instanceof f?new a(o,e):c}}async function x(r,n,o,e={},c){let s=typeof e=="function"?{}:e,t=E(n.request,o,"INVALID_REQUEST",s.request);try{let i=await r(n.path,t,n.method,c),u=typeof e=="function"?e:e.parseResponse,d=u?u(n.response,i):E(n.response,i,"INVALID_RESPONSE",s.response);return b(n.path,t,d),d}catch(i){throw i instanceof a&&t!==null&&typeof t=="object"&&"requestId"in t&&typeof t.requestId=="string"&&(i.commandRequestId??=t.requestId),i}}function O(r,n){let o=typeof r=="string"?new TextEncoder().encode(r):r;return o.byteLength===n.byteLength&&h(o)===n.sha256}async function F(r,n){let o=g.parse(n),{artifact:e,environmentId:c}=o.content,s=new y(r.baseUrl??P).origin,t=new y(e.url,s);if(t.origin!==s||t.username||t.password||t.search||t.hash||t.pathname!==`/api/v1/configuration/${c}/artifacts/${e.sha256}`)throw new a("INVALID_RESPONSE","Public Paywall locator is not trusted");let i=new AbortController,u,d=new Promise((p,l)=>{u=setTimeout(()=>{let m=new a("TIMEOUT","Public Paywall read timed out");i.abort(m),l(m)},I.initializationMs)}),R=(async()=>{let p=await(r.fetch??globalThis.fetch)(t,{method:"GET",credentials:"omit",redirect:"error",cache:"default",signal:i.signal});if(i.signal.aborted&&(p.body?.cancel().catch(()=>{}),i.signal.throwIfAborted()),!p.ok||!p.headers.get("content-type")?.toLowerCase().startsWith("application/json")||Number(p.headers.get("content-length"))>e.byteLength)throw p.body?.cancel().catch(()=>{}),new a("INVALID_RESPONSE","Public Paywall is unavailable");let l=await T(p,e.byteLength,{signal:i.signal,error:m=>new a("INVALID_RESPONSE",m==="missing"?"Public Paywall body is missing":"Public Paywall exceeds its byte limit")});if(!O(l,e))throw new a("INVALID_RESPONSE","Public Paywall digest or size changed");return w(o,JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(l)))})();try{return await Promise.race([R,d])}finally{clearTimeout(u)}}export{D as a,q as b,x as c,O as d,F as e};
1
+ import{s as g,t as w}from"./chunk-QPHT6QHE.js";import{n as I,s as h}from"./chunk-4ZVVG5LM.js";import{a as y}from"./chunk-XZEGVBAI.js";import{a}from"./chunk-HJLGRW4A.js";import{a as T}from"./chunk-3VUPVXAV.js";import{b as P}from"./chunk-FVGUBIVT.js";import{a as f}from"./chunk-ZY4XAKNQ.js";function b(r,n,o){if(!["subscriptions/operations/read","subscriptions/updates/read","subscriptions/refunds/read"].includes(r))return;let e=n,c=o,s=c.operation;if(s.operationId!==e.operationId||[s.authority,s.merchantExecution].some(t=>t&&(t.operationId!==e.operationId||e.customerId!==void 0&&t.customerId!==e.customerId))||s.authority&&(s.authority.scope.projectId!==c.scope.projectId||s.authority.scope.environment!==c.scope.environment))throw new a("INVALID_RESPONSE","Original commerce operation changed")}function D(r){try{return structuredClone(r)}catch{return r}}async function q(r,n){let o=r.captureIdentity?.(),{apiOperations:e}=await import("./operation-contracts-SP2RZUT3.js");return o?.(),e[n]}function E(r,n,o,e){try{return r.parse(n)}catch(c){throw e&&c instanceof f?new a(o,e):c}}async function x(r,n,o,e={},c){let s=typeof e=="function"?{}:e,t=E(n.request,o,"INVALID_REQUEST",s.request);try{let i=await r(n.path,t,n.method,c),u=typeof e=="function"?e:e.parseResponse,d=u?u(n.response,i):E(n.response,i,"INVALID_RESPONSE",s.response);return b(n.path,t,d),d}catch(i){throw i instanceof a&&t!==null&&typeof t=="object"&&"requestId"in t&&typeof t.requestId=="string"&&(i.commandRequestId??=t.requestId),i}}function O(r,n){let o=typeof r=="string"?new TextEncoder().encode(r):r;return o.byteLength===n.byteLength&&h(o)===n.sha256}async function F(r,n){let o=g.parse(n),{artifact:e,environmentId:c}=o.content,s=new y(r.baseUrl??P).origin,t=new y(e.url,s);if(t.origin!==s||t.username||t.password||t.search||t.hash||t.pathname!==`/api/v1/configuration/${c}/artifacts/${e.sha256}`)throw new a("INVALID_RESPONSE","Public Paywall locator is not trusted");let i=new AbortController,u,d=new Promise((p,l)=>{u=setTimeout(()=>{let m=new a("TIMEOUT","Public Paywall read timed out");i.abort(m),l(m)},I.initializationMs)}),R=(async()=>{let p=await(r.fetch??globalThis.fetch)(t,{method:"GET",credentials:"omit",redirect:"error",cache:"default",signal:i.signal});if(i.signal.aborted&&(p.body?.cancel().catch(()=>{}),i.signal.throwIfAborted()),!p.ok||!p.headers.get("content-type")?.toLowerCase().startsWith("application/json")||Number(p.headers.get("content-length"))>e.byteLength)throw p.body?.cancel().catch(()=>{}),new a("INVALID_RESPONSE","Public Paywall is unavailable");let l=await T(p,e.byteLength,{signal:i.signal,error:m=>new a("INVALID_RESPONSE",m==="missing"?"Public Paywall body is missing":"Public Paywall exceeds its byte limit")});if(!O(l,e))throw new a("INVALID_RESPONSE","Public Paywall digest or size changed");return w(o,JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(l)))})();try{return await Promise.race([R,d])}finally{clearTimeout(u)}}export{D as a,q as b,x as c,O as d,F as e};
@@ -1 +1 @@
1
- import{b as UA}from"./chunk-J4VTKRH7.js";import{a as P}from"./chunk-HJLGRW4A.js";import{a as _A,d as jA,e as xA,f as MA,h as sA}from"./chunk-XIP32WI7.js";import{a as $A,b as zA}from"./chunk-OHOROFWN.js";var pA="X-Indiana-Protocol",FA="X-Indiana-SDK-Version";var gA={current:"0.10"};function b(A){return typeof A=="string"?A:String(A)}var De=/[\ud800-\udbff](?![\udc00-\udfff])|(^|[^\ud800-\udbff])[\udc00-\udfff]/g;function Se(A){return A.replace(De,"$1\uFFFD")}function PA(A,e){if(typeof A!="object"||A==null){let t="";throw t+="The provided value is not an object",new TypeError(t)}return A}function ZA(A){if(A!=null&&(typeof A=="object"||typeof A=="function")){let e=A[Symbol.iterator];if(e==null)return;if(typeof e!="function")throw new TypeError("The provided value is not iterable");let t=e.call(A);if(!t||typeof t!="object")throw new TypeError("Result of the Symbol.iterator method is not an object");return t}}function QA(A){let e;if(Array.isArray(A)){let t=A.map(b);if(t.length===2)return t}else if((e=ZA(A))!=null){let t=PA(e.next()),n=PA(e.next());if(!t.done&&!n.done)return[b(t.value),b(n.value)]}throw new TypeError("Each query pair must be an iterable [name, value] tuple")}var GA="0123456789ABCDEF",be=/(?:%[0-9A-Fa-f]{2})+/g;function M(A){return`%${GA[A>>4&15]}${GA[15&A]}`}function Ae(A,e,t=!1){return A>=55296&&A<=57343&&(A=65533),A<=127?t&&A===32?"+":e(A)?M(A):String.fromCharCode(A):A<=2047?M(192|A>>6)+M(128|63&A):A<=65535?M(224|A>>12)+M(128|A>>6&63)+M(128|63&A):M(240|A>>18)+M(128|A>>12&63)+M(128|A>>6&63)+M(128|63&A)}function DA(A){return A>=48&&A<=57?A-48:A>=65&&A<=70?A-65+10:A>=97&&A<=102?A-97+10:-1}function SA(A,e=!1){let t=0;for(;t<A.length;t++){let n=A.charCodeAt(t);if(n===37||e&&n===43)break}return t===A.length?A:(e?A.replace(/\+/g," "):A).replace(be,n=>{try{return decodeURIComponent(n)}catch{return"\uFFFD".repeat(n.length/3)}})}function AA(A){return A<=31||A>126}function Ie(A){switch(A){case 32:case 34:case 60:case 62:case 96:return!0;default:return AA(A)}}function OA(A){switch(A){case 32:case 34:case 35:case 60:case 62:return!0;default:return AA(A)}}function Ce(A){return OA(A)||A===39}function bA(A){switch(A){case 63:case 94:case 96:case 123:case 125:return!0;default:return OA(A)}}function cA(A){switch(A){case 47:case 58:case 59:case 61:case 64:case 91:case 92:case 93:case 124:return!0;default:return bA(A)}}function KA(A){switch(A){case 33:case 39:case 40:case 41:case 126:return!0;default:return(function(t){switch(t){case 36:case 37:case 38:case 43:case 44:return!0;default:return cA(t)}})(A)}}function ee(A,e){return Ae(A=A||0,e)}function U(A,e,t=!1){let n=0;for(;n<A.length;n++){let u=A.charCodeAt(n);if(u>=128||t&&u===32||e(u))break}if(n===A.length)return A;let r=A.slice(0,n);for(;n<A.length;n++){let u=A.charCodeAt(n),l=u;if(u>=55296&&u<=56319&&n+1<A.length){let a=A.charCodeAt(n+1);a>=56320&&a<=57343&&(l=(u-55296<<10)+a-56320+65536,n++)}r+=Ae(l,e,t)}return r}function qA(A){let e=[],t=0,n=0;for(;n<=A.length;){if(n=A.indexOf("&",t),n<0&&(n=A.length),n!==t){let r=A.slice(t,n),u=r.indexOf("=");u<0&&(u=r.length),e.push([SA(r.slice(0,u),!0),SA(r.slice(u+1),!0)])}if(t=n+1,n===A.length)break}return e}function IA(A){let e="";for(let t=0;t<A.length;t++){let n=U(A[t][0],KA,!0),r=U(A[t][1],KA,!0);e+=t!==0?`&${n}=${r}`:`${n}=${r}`}return e}var Ee=[2191,2191,3164,3164,3292,3292,6863,6877,6880,6891,8385,8385,11158,11158,42958,42959,42962,42962,42964,42964,42993,42993,64451,64466,64912,64913,64968,64974,67904,67929,69317,69319,69328,69336,69370,69371,72544,72551,73136,73179,73184,73193,93856,93880,93883,93907,94194,94198,100344,100351,101641,101662,101760,101874,118010,118012,118458,118480,118496,118512,124608,124638,124640,124661,124670,124671,128728,128728,128887,128890,129232,129240,129620,129623,129674,129674,129678,129678,129736,129736,129741,129741,129770,129770,129775,129775,130042,130042,177978,177983,183970,183981,205744,210041],Te=[7296,7297,7298,7299,7300,7301,7302,7303,7304,42958,42962,42964,42993],ve=["\u0432","\u0434","\u043E","\u0441","\u0442","\u0442","\u044A","\u0463","\uA64B","\uA7CF","\uA7D3","\uA7D5","s"],Oe=[2381,2381,2509,2509,2637,2637,2765,2765,2893,2893,3021,3021,3149,3149,3277,3277,3387,3388,3405,3405,3530,3530,3642,3642,3770,3770,3972,3972,4153,4154,5908,5909,5940,5940,6098,6098,6752,6752,6980,6980,7082,7083,7154,7155,11647,11647,43014,43014,43052,43052,43204,43204,43347,43347,43456,43456,43766,43766,44013,44013,68159,68159,69702,69702,69744,69744,69759,69759,69817,69817,69939,69940,70080,70080,70197,70197,70378,70378,70477,70477,70606,70608,70722,70722,70850,70850,71103,71103,71231,71231,71350,71350,71467,71467,71737,71737,71997,71998,72160,72160,72244,72244,72263,72263,72345,72345,72767,72767,73028,73029,73111,73111,73537,73538,90415,90415];function qe(A){for(let e=0;e<A.length;e++){let t=A.codePointAt(e);if(t>65535&&e++,t<=32||t===37||t===127||t>=55296&&t<=57343||t>=128&&t<=159||t>=64976&&t<=65007||!(65534&~t)||t===65533)return!0}return!1}var[Re,Ne,ke,YA]=[[[],"0,6,7,8,m,w,10,1b,1d,1f,72,73,7k,8k,dt,2rk","AAAAAAAAAAAAAAAAAAAAAP////8AAAAAAAAAAAAAAAA/AAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAADAAABwfwAAAAAAAMADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhAAAAQAAAAAAAAQCAAABAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgACAAAAAAAAAAAAAAAAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAP///////////////wAAAAAAAAAAAAAAAAAAAAA="],[[],"6,7,8,o,4o,7e,7f,7h,7i,7j,dl","AAAAAEF9+P/+BwAAAMAA//8AAPz/////BlADAAAAAJwAAPz///8AAADA//H/5+X8AAAAAAAAAAAA/P///wcAAAAAAAAAAAAAPv0vAD0BAABA/gAA/5/5/f8BAAAAAAAAgAAAAP//////////////AYD/////BQAAAAAAAAAAAAAAAAAAAAAAAP///////wcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8g+N8B+AAAAAAAAAAAAAAAAAAAAAAAAP//AwAAYAAAAAAAAAAAAAD/////CwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANgAAAAAAAAAAAAAAAAA//8fAB4AAAD//wMAAAAAAH3/HgwAAAAAAAD//////////w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="],[[],"6,7,8,o,4o,7e,7f,7h,7i,7j,dl","AAAAAP3////+BwAAAMDu//////////////8vAADAAJwAAP3///8AAADg////////AAAAAAAAAAAA/P///wcAAAAAAAAAAAAA////Ab0H//9H/gAA/9////8BAAAAAAAAgAAAAP//////////////AYD/////BQAAAAAAAAAAAAAAAAAAAAAAAP///////wcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL/G//8T+AAAAAAAAAAAAAAAAAAAAAAAAP//AwAAfgAAAAAAAAAAAAD+////DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANwAAAAAAAAAAAAAAAAA//8fAB4AAAD//wMAAAAAAH3/Hg4AAAAAAAD//////////w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="],[[],"0,3,4,5,6,7,8,9,a,b,c,d,e,f,g,j,n,o,p,q,r,s,t,w,18,19,1c,4m,4o,4p,4q,4r,6z,72,73,75,76,77,7e,7h,7i,7j,7k,7l,7m,7n,7o,7p,7q,7r,7s,7t,7u,7v,7w,7x,7y,7z,8k,9t,a2,a3,a7,cc,cv,cx,cy,d6,dc,dd,de,dg,dh,di,dk,dl,2rk,2rl","AAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAD//////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4AwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/v////+/tgAAAAAAAAAAAP8XAAAAAAD4//8AAAEAAAAAAAAAAAAAAMCfnz0AAACAAgAAAP///wcAAAAAAAAAAAAAwP8BAAAAAAAA+A8gAADA++8+AAAAAAAOAAAAAAAAgP8AAAAAAPz///v///8HAAAAAAAAFP4h/gAMAAAAAgAAAAAAABAeIAAADAAAQAYAAAAAAAAQhjkCAAAAIwAGAAAAAAAAEL4hAAAMAAD8AgAAAAAAAJAeIGAADAAAAAQAAAAAAAAAASAAAAAAAAARAAAAAAAA0ME9YAAMAAAAAgAAAAAAAJBAMAAADAAAAAMAAAAAAAAYHiAAAAwAAAACAAAAAAAAAAAEXAAAAAAAAAAAAAAA8geAfwAAAAAAAAAAAAAAAPIfAH8AAAAAAAAAAAADAACgAgAAAAAAAP5/3+D//v///x9AAAAAAAAAAAAAAAAA4P1mAAAAwwEAHgBkIAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAMAAAADAAAAAwAAAAAAAAAsD9A/g8gAAAAAAC4AAAAAAAAAAAAAAAAAABgAAAAAAIAAAAAAAAAAAAAAAAAAIcBBA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAJAAAAAAAAQH/lH/ifAAAAAAAA//////8//w8AAA8AAAAAANAXBAAAAAD4DwADAAAAPDsAAAAAAABAowMAAAAAAADwzwAAAAAAAAAAAAAAAAAAAAAAAAD3//0hEAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////wDIAAAAfAAAAAAAAB/8AAAAAAAAAAAAAAAA/////wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAwAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAA/////wAAAAAAPAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAID3PwAAAMAAAAAAAAAAAAAAAwBECAAAYBAAAAAAAAAAAAAAAAAAAAAAAAAwAAAA//8DgAAAAADAPwAAgP8DAAAAAAAHAAAAAADIMwAAAAAgAAAAAAAAAAB+ZgAIEAAAAAAAEAAAAAAAAJ3BAgAAAAAwQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAICEAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAP//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAMAHAAAAAAAAAAAAAAAAAAAAAG7wAAAAAACHAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAPAAAAAAAAAAAD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAA/AAAAAAAAAAAwP8BAAAAAAA8AAAAAAAAAAAAAAAAAAAAAgAAAAAAAP9/AAAAAAAZgAMAAAAAAHgGBAAAAAAAAAAHAAAAgO8fAAAAAAAAAAgAAwAAAAAAwH8AngAAAAAAAAAAAAAAgNNAAgAAAAAAAAAAAAAAAAAAAAAAAID4BwAAAwAAAAAAABgBAAAAwB8fAAAAAAAAAAD4AUAFAAYAAAAAAAAAAAAA/1wAAEAAAAAAAAAAAAAA+IUNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8sAEAADAAAAAAAAAAAAAA+KcBAAAAAAAAAAAAAAAAKL8AAAAAAAAAAAAAAACgvA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgP8GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFgIAAAAAAAAAAAAAAAAAAAAAADwDAEAAAD+BwAAAAD4eYAAfg4AAAAAAPx/AwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf78AAAAAAAAAAAAA/P///G0AAAAAAAAAAAAAAAAAAAB+tL8AAAAAAAAAAACjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAwAAAAAAwAcFAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//4H/PwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMD/4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHwAAAAAAAAB/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAcAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAPAAAAAAAAAAAAAAD//////z///38AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAD+P/nDwAAADwAAAAAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////9/+P//////HyAAEAAA+P7/AAAAAAAAAAAAAH////nbBwAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASMAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAAAAAAAAADwDwAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAA////////////////AAAAAAAAAAAAAAAAAAAAAP///////////////////////////////////////wAA"]].map(function([e,t,n]){return[e,t.split(",").map(r=>parseInt(r,36)),Uint8Array.from(atob(n),r=>r.charCodeAt(0))]});function Le(A,e){return e===931||e===1010||e===120531||e===120589||e===120647||e===120705||e===120763?"\u03C3":e>=5112&&e<=5117?String.fromCodePoint(e-8):e>=43888&&e<=43967?String.fromCodePoint(e-38864):e>=93856&&e<=93880?String.fromCodePoint(e+27):e===837||e===890||e>=8064&&e<=8111||e>=8114&&e<=8188?A.normalize("NFD").replace(/\u0345/g,"\u03B9").normalize("NFC").toLowerCase():""}function te(A,e){for(let t=0;t<A.length;t+=2)if(e>=A[t]&&e<=A[t+1])return!0;return!1}function W(A,e){let[t,n,r]=A,u=e>>8;for(let h=0;h<t.length;h+=2)if(u>=t[h]&&u<=t[h+1])return!0;let l=n.indexOf(u);if(l<0)return!1;let a=255&e;return!!(r[32*l+(a>>3)]&1<<(7&a))}function He(A){let e=Array.from(A,t=>t.codePointAt(0));for(let t=0;t<e.length;t++){let n=e[t];if(n!==8204&&n!==8205||t>0&&te(Oe,e[t-1]))continue;if(n===8205)return!1;let r=t-1;for(;r>=0&&W(YA,e[r]);)r--;let u=t+1;for(;u<e.length&&W(YA,e[u]);)u++;if(!(r>=0&&u<e.length&&W(Ne,e[r])&&W(ke,e[u])))return!1}return!0}var Be=/(?![\p{Mark}\p{Decimal_Number}])[\p{Script=Arabic}\p{Script=Hebrew}]/u,_e=/\p{Script=Latin}/u;function je(A){return!Be.test(A)||!_e.test(A)}var F=36,iA=1,CA=26,xe=38,Me=700,Ue=72,$e=128,ze=2147483647;function VA(A){return String.fromCharCode(A+22+75*+(A<26))}function Fe(A,e,t){let n=0;for(A=t?Math.floor(A/Me):A>>1,A+=Math.floor(A/e);A>(F-iA)*CA>>1;n+=F)A=Math.floor(A/(F-iA));return Math.floor(n+(F-iA+1)*A/(A+xe))}function Qe(A){let e=Array.from(A,h=>h.codePointAt(0)),t="",n=0;for(let h=0;h<e.length;h++){let f=e[h];f<128&&(t+=String.fromCharCode(f),n++)}let r=n;r&&(t+="-");let u=$e,l=0,a=Ue;for(;n<e.length;){let h=ze;for(let f=0;f<e.length;f++){let g=e[f];g>=u&&g<h&&(h=g)}l+=(h-u)*(n+1),u=h;for(let f=0;f<e.length;f++){let g=e[f];if(g<u&&l++,g===u){let p=l;for(let w=F;;w+=F){let y=w<=a?iA:w>=a+CA?CA:w-a;if(p<y)break;t+=VA(y+(p-y)%(F-y)),p=Math.floor((p-y)/(F-y))}t+=VA(p),a=Fe(l,n+1,n===r),l=0,n++}}l++,u++}return t}function mA(A){let e=10;if(A.length>=2&&A[0]==="0"&&(A[1]==="x"||A[1]==="X"))A=A.slice(2),e=16;else if(A.length>=2&&A[0]==="0")A=A.slice(1),e=8;else if(A==="")return-1;let t=0;for(let n=0;n<A.length;n++){let r=DA(A.charCodeAt(n));if(r>=e||r<0)return-1;t=t*e+r}return t}function XA(A){switch(A){case".":case"%2e":case"%2E":return!0;default:return!1}}function ne(A,e){return(A>=65&&A<=90||A>=97&&A<=122)&&(e===58||e===124)}function re(A){return A.length===2&&ne(A.codePointAt(0),A.codePointAt(1))}function JA(A){return A.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u)!==-1}function C(A){switch(A){case"ftp":case"http":case"https":case"ws":case"wss":case"file":return!0;default:return!1}}function se(A){switch(A){case"ftp":return 21;case"http":case"ws":return 80;case"https":case"wss":return 443;default:return null}}function EA(A,e){if(A[0]==="[")return A[A.length-1]==="]"?(function(n){let r=[0,0,0,0,0,0,0,0],u=null,l=0,a=0,h=Array.from(n,f=>f.codePointAt(0));if(h[a]===58){if(h[a+1]!==58)return null;a+=2,l++,u=l}for(;a<h.length;){if(l===8)return null;if(h[a]===58){if(u!==null)return null;a++,l++,u=l;continue}let f=0,g=0,p=0;for(;p<4&&(f=DA(h[a]))>=0;)g=(g<<4)+f,a++,p++;if(h[a]===46){if(p===0||l>6)return null;a-=p;let w=0;for(;h[a]!==void 0;){let y=0;if(w>0)if(h[a]===46&&w<4)a++;else return null;if(h[a]==null||h[a]<48||h[a]>57)return null;for(;h[a]>=48&&h[a]<=57;){if(y=10*y+DA(h[a]),y>255)return null;a++}r[l]=256*r[l]+y,w++,w%2==0&&l++}if(w!==4)return null;break}else if(h[a]===58){if(h[++a]===void 0)return null}else if(h[a]!==void 0)return null;r[l]=g,l++}if(u!==null){let f=l-u;for(l=7;l!==0&&f>0;){let g=r[u+f-1];r[u+f-1]=r[l],r[l]=g,l--,f--}}else if(u===null&&l!==8)return null;return r})(A.substring(1,A.length-1)):null;if(e)return(function(n){return JA(n)?null:U(n,AA)})(A);{let t=(function(r){let u=!1,l=!1;for(let h=0;h<r.length;h++){let f=r.charCodeAt(h);if(f<=32||f===37||f===127)return null;if(f>=128){u=!0;break}f>=65&&f<=90&&(l=!0)}if(!u)return r!==""?l?r.toLowerCase():r:null;if((function(f){for(let g of f){let p=g.codePointAt(0);if(/[\p{Cn}\p{Co}\p{Cs}\p{Noncharacter_Code_Point}]/u.test(g)&&!te(Ee,p)||W(Re,p))return!0}return!1})(r))return null;let a=(r=(function(f){let g="";for(let p of f){let w=p.codePointAt(0);if(w!==8204&&w!==8205&&/\p{Default_Ignorable_Code_Point}/u.test(p))continue;let y=Le(p,w);if(y){g+=y;continue}let R=Te.indexOf(w);g+=R<0?p:ve[R]}return g})(r).normalize("NFKC").replace(/[\u3002\uff0e\uff61]/g,".").toLowerCase()).split(".");for(let h=0;h<a.length;h++){let f=a[h];if(f==="")continue;let g=/[^\0-\x7f]/.test(f);if(qe(f)||g&&(/^\p{Mark}/u.test(f)||!He(f)||!je(f)||f.startsWith("xn--")))return null;g&&(a[h]=`xn--${Qe(f)}`)}return(r=a.join("."))!==""?r:null})(A.indexOf("%")===-1?A:SA(A));return t===null||JA(t)?null:(function(r){let u=r.length,l=r.lastIndexOf(".",u-2)+1;if(r.charCodeAt(u-1)===46&&u--,u<=l)return!1;if(mA(r.slice(l,u))>=0)return!0;for(;l<u;l++){let a=r.charCodeAt(l);if(a<48||a>57)return!1}return!0})(t)?(function(r){let u=r.split("."),l=u.length;if(u[l-1]||l--,l>4)return null;let a=0;for(let f=0;f<l-1;f++){let g=mA(u[f]);if(g<0||g>255)return null;a+=g*(1<<8*(3-f))}let h=mA(u[l-1]);return h<0||h>=256**(5-l)?null:(a+=h,a)})(t):t}}function TA(A){return typeof A=="number"?(function(t){let r="";return r+=`${(t>>>24&255).toString(10)}.`,r+=`${(t>>>16&255).toString(10)}.`,r+=`${(t>>>8&255).toString(10)}.`,r+=(t&255).toString(10),r})(A):Array.isArray(A)?`[${(function(t){let n=(function(a){let h=-1,f=-1,g=1,p=0;for(let w=0;w<a.length;++w)a[w]!==0?(p>g&&(h=f,g=p),f=-1,p=0):(f===-1&&(f=w),++p);return p>g?f:h})(t),r="",u=!1;for(let l=0;l<=7;++l)if(!(u&&t[l]===0)){if(u&&(u=!1),n===l){r+=l===0?"::":":",u=!0;continue}r+=t[l].toString(16),l!==7&&(r+=":")}return r})(A)}]`:A}function oe(A){A.path.length>0&&(A.path.length!==1||A.scheme!=="file"||!(function(t){return/^[A-Za-z]:$/u.test(t)})(A.path[0]))&&A.path.pop()}function ie(A){return A.username!==""||A.password!==""}function wA(A){return A.host===null||A.host===""||A.scheme==="file"}var s=0,o="",m="",D=null,i,lA=!1,uA=!1,G=!1,E;function H(A,e,t,n){e||(A=(function(l){let a=0,h=l.length;for(;a<h&&!(l.charCodeAt(a)>32);++a);for(;h>a&&!(l.charCodeAt(h-1)>32);--h);return l.substring(a,h)})(A)),A=(function(l){let a=0;for(;a<l.length;a++){let f=l.charCodeAt(a);if(f===9||f===10||f===13)break}if(a===l.length)return l;let h=l.slice(0,a);for(;a<l.length;a++){let f=l.charCodeAt(a);f!==9&&f!==10&&f!==13&&(h+=l[a])}return h})(A),s=0,o=A,m="",D=t||null,i=e||{scheme:"",username:"",password:"",host:null,port:null,path:[],query:null,fragment:null,opaquePath:!1},lA=!1,uA=!1,G=!1,E=n||0;let r=Ge;switch(n){case 3:case 4:r=aA;break;case 5:r=NA;break;case 6:r=K;break;case 7:r=Q;break;case 8:r=$}return r(c(A,s))!==1?i:null}function d(A,e){return s+=s===A?j(e):1,s<=o.length}function c(A,e){return e<A.length?A.codePointAt(e):void 0}function j(A){return A!=null&&A>65535?2:1}function le(A){return A==null?"":A<=65535?String.fromCharCode(A):String.fromCodePoint(A)}var Ge=A=>{let e=s;if(A!=null&&(A>=65&&A<=90||A>=97&&A<=122)){let t=s+1;for(A=o.charCodeAt(t);A===43||A===45||A===46||A>=65&&A<=90||A>=97&&A<=122||A>=48&&A<=57;)t++,A=o.charCodeAt(t);return m=o.slice(s,t).toLowerCase(),s=t,Ke(t<o.length?A:void 0)}else return E?1:(--s,d(e,A)?ue(c(o,s)):0)},Ke=A=>{let e=s;if(A===58){if(E){if(C(i.scheme)!==C(m))return 0;if((ie(i)||i.port!==null)&&m==="file")return 0;if(i.scheme==="file"&&i.host==="")return 0}return i.scheme=m,E?(i.port===se(i.scheme)&&(i.port=null),0):(m="",i.scheme==="file"?d(e,A)?kA(c(o,s)):0:C(i.scheme)&&D!==null&&D.scheme===i.scheme?d(e,A)?Ye(c(o,s)):0:C(i.scheme)?d(e,A)?Xe(c(o,s)):0:c(o,s+1)===47?(s++,d(e,A)?Ve(c(o,s)):0):(i.path=[""],i.opaquePath=!0,d(e,A)?ae(c(o,s)):0))}else return E?1:(m="",s=-1,d(e,A)?ue(c(o,s)):0)},ue=A=>{let e=s;return D===null||D.opaquePath&&A!==35?1:D.opaquePath&&A===35?(i.scheme=D.scheme,i.path=D.path.slice(),i.opaquePath=D.opaquePath,i.query=D.query,i.fragment="",d(e,A)?$(c(o,s)):0):D.scheme==="file"?(s--,d(e,A)?kA(c(o,s)):0):(s--,d(e,A)?RA(c(o,s)):0)},Ye=A=>{let e=s;return A===47&&c(o,s+1)===47?(++s,d(e,A)?hA(c(o,s)):0):(s--,d(e,A)?RA(c(o,s)):0)},Ve=A=>{let e=s;return A===47?d(e,A)?J(c(o,s)):0:(s--,d(e,A)?x(c(o,s)):0)},RA=A=>{let e=s;return i.scheme=D.scheme,A===47||C(i.scheme)&&A===92?d(e,A)?WA(c(o,s)):0:(i.username=D.username,i.password=D.password,i.host=D.host,i.port=D.port,i.path=D.path.slice(),i.query=D.query,A===63?(i.query="",d(e,A)?Q(c(o,s)):0):A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):A!=null?(i.query=null,i.path.pop(),s--,d(e,A)?x(c(o,s)):0):d(e,A)?RA(c(o,s)):0)},WA=A=>{let e=s;return C(i.scheme)&&(A===47||A===92)?d(e,A)?hA(c(o,s)):0:A===47?d(e,A)?J(c(o,s)):0:(i.username=D.username,i.password=D.password,i.host=D.host,i.port=D.port,s--,d(e,A)?x(c(o,s)):0)},Xe=A=>{let e=s;return A===47&&c(o,s+1)===47?s++:s--,d(e,A)?hA(c(o,s)):0},hA=A=>{let e=s;return A!==47&&A!==92?(s--,d(e,A)?J(c(o,s)):0):d(e,A)?hA(c(o,s)):0},J=A=>{let e=s;if(A!=null&&A!==64&&A!==35&&A!==47&&A!==63&&(A!==92||!C(i.scheme))){let t=s+j(A);for(;t<o.length;){let n=c(o,t);if(n==null||n===64||n===35||n===47||n===63||n===92&&C(i.scheme))break;t+=j(n)}return m+=o.slice(s,t),s=t-1,d(e,A)?J(c(o,s)):0}if(A===64){lA&&(m=`%40${m}`),lA=!0;for(let t=0;t<m.length;t++){let n=m.codePointAt(t);if(n===58&&!uA){uA=!0;continue}let r=ee(n,cA);uA?i.password+=r:i.username+=r,n!=null&&n>65535&&t++}return m="",d(e,A)?J(c(o,s)):0}else return A==null||A===35||A===47||A===63||A===92&&C(i.scheme)?lA&&m===""?1:(s-=m.length+1,m="",d(e,A)?aA(c(o,s)):0):(m+=le(A),d(e,A)?J(c(o,s)):0)},aA=A=>{let e=s;if(E&&i.scheme==="file")return s--,d(e,A)?LA(c(o,s)):0;if(A!=null&&A!==58&&A!==35&&A!==47&&A!==63&&(A!==92||!C(i.scheme))){let t=s+j(A);for(A===91?G=!0:A===93&&(G=!1);t<o.length;){let n=c(o,t);if(n==null||!G&&n===58||n===35||n===47||n===63||n===92&&C(i.scheme))break;n===91?G=!0:n===93&&(G=!1),t+=j(n)}return m+=o.slice(s,t),s=t-1,d(e,A)?aA(c(o,s)):0}else if(A===58&&!G){if(m===""||E===4)return 1;let t=EA(m,!C(i.scheme));return t===null?1:(i.host=TA(t),m="",d(e,A)?NA(c(o,s)):0)}else if(A==null||A===35||A===47||A===63||A===92&&C(i.scheme)){if(s--,C(i.scheme)&&m==="")return 1;if(E&&m===""&&(ie(i)||i.port!==null))return 1;let t=EA(m,!C(i.scheme));return t===null?1:(i.host=TA(t),m="",E?0:d(e,A)?K(c(o,s)):0)}else return m+=le(A),d(e,A)?aA(c(o,s)):0},NA=A=>{let e=s;if(A!=null&&A>=48&&A<=57){let t=s+1;for(;t<o.length;){let n=o.charCodeAt(t);if(n<48||n>57)break;t++}return m+=o.slice(s,t),s=t-1,d(e,A)?NA(c(o,s)):0}else if(E||A==null||A===35||A===47||A===63||A===92&&C(i.scheme)){if(m!==""){let t=parseInt(m,10);if(t>65535)return 1;if(i.port=t===se(i.scheme)?null:t,m="",E)return 0}return E?1:(s--,d(e,A)?K(c(o,s)):0)}else return 1};function ce(A,e){let t=A.length-e;if(t<2)return!1;if(ne(c(A,e),c(A,e+1))){if(t===2)return!0;{let n=c(A,e+2);return n===47||n===92||n===63||n===35}}else return!1}var kA=A=>{let e=s;return i.scheme="file",i.host="",A===47||A===92?d(e,A)?Je(c(o,s)):0:D?.scheme==="file"?(i.host=D.host,i.path=D.path.slice(),i.opaquePath=D.opaquePath,i.query=D.query,A===63?(i.query="",d(e,A)?Q(c(o,s)):0):A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):A!=null?(i.query=null,ce(o,s)?i.path=[]:oe(i),s--,d(e,A)?x(c(o,s)):0):d(e,A)?kA(c(o,s)):0):(s--,d(e,A)?x(c(o,s)):0)},Je=A=>{let e=s;return A===47||A===92?d(e,A)?LA(c(o,s)):0:(D!==null&&D.scheme==="file"&&(!ce(o,s)&&(function(n){if(n.length===2){let r=n.codePointAt(0),u=n.codePointAt(1);return(r>=65&&r<=90||r>=97&&r<=122)&&u===58}else return!1})(D.path[0])&&i.path.push(D.path[0]),i.host=D.host),s--,d(e,A)?x(c(o,s)):0)},LA=A=>{let e=s;if(A!=null&&A!==47&&A!==92&&A!==63&&A!==35){let t=s+j(A);for(;t<o.length;){let n=c(o,t);if(n==null||n===47||n===92||n===63||n===35)break;t+=j(n)}return m+=o.slice(s,t),s=t-1,d(e,A)?LA(c(o,s)):0}else if(A==null||A===47||A===92||A===63||A===35){if(s--,!E&&re(m))return d(e,A)?x(c(o,s)):0;if(m==="")return i.host="",E?0:d(e,A)?K(c(o,s)):0;{let t=EA(m,!C(i.scheme));return t===null?1:(t==="localhost"&&(t=""),i.host=TA(t),m="",E?0:d(e,A)?K(c(o,s)):0)}}return 1},K=A=>{let e=s;return C(i.scheme)?(A!==92&&A!==47&&s--,d(e,A)?x(c(o,s)):0):!E&&A===63?(i.query="",d(e,A)?Q(c(o,s)):0):!E&&A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):A!=null?(A!==47&&s--,d(e,A)?x(c(o,s)):0):(E&&i.host===null&&i.path.push(""),d(e,A)?K(c(o,s)):0)},x=A=>{let e=s;if(A!=null&&A!==47&&(!C(i.scheme)||A!==92)&&(E||A!==63&&A!==35)){let t=s+j(A);for(;t<o.length;){let n=c(o,t);if(n==null||n===47||C(i.scheme)&&n===92||!E&&(n===63||n===35))break;t+=j(n)}m+=U(o.slice(s,t),bA),s=t,A=c(o,t)}if(A==null||A===47||C(i.scheme)&&A===92||!E&&(A===63||A===35)){let t=C(i.scheme)&&A===92;return(function(r){switch(r){case"..":case"%2e.":case"%2E.":case".%2e":case".%2E":case"%2e%2e":case"%2E%2e":case"%2e%2E":case"%2E%2E":return!0;default:return!1}})(m)?(oe(i),A!==47&&!t&&i.path.push("")):XA(m)&&A!==47&&!t?i.path.push(""):XA(m)||(i.scheme==="file"&&i.path.length===0&&re(m)&&(m=`${m[0]}:`),i.path.push(m)),m="",A===63?(i.query="",d(e,A)?Q(c(o,s)):0):A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):d(e,A)?x(c(o,s)):0}else return m+=ee(A,bA),d(e,A)?x(c(o,s)):0},ae=A=>{let e=s;if(A===63)return i.query="",d(e,A)?Q(c(o,s)):0;if(A===35)return i.fragment="",d(e,A)?$(c(o,s)):0;if(A!=null){let t=s+j(A);for(;t<o.length;){let r=c(o,t);if(r===63||r===35)break;t+=j(r)}let n=o.slice(s,t);if(t<o.length&&n.charCodeAt(n.length-1)===32?i.path[0]+=U(n.slice(0,-1),AA)+"%20":i.path[0]+=U(n,AA),s=t,(A=c(o,t))===63)return i.query="",d(e,A)?Q(c(o,s)):0;if(A===35)return i.fragment="",d(e,A)?$(c(o,s)):0}return d(e,A)?ae(c(o,s)):0},Q=A=>{let e=s,t=s;if(A!=null){if(E)t=o.length;else{let r=o.indexOf("#",s);t=r===-1?o.length:r}let n=C(i.scheme)?Ce:OA;i.query+=U(o.slice(s,t),n)}return s=t,c(o,t)===35&&!E?(i.fragment="",d(e,A)?$(c(o,s)):0):d(e,A)?Q(c(o,s)):0},$=A=>{let e=s;return A!=null&&(i.fragment+=U(o.slice(s),Ie),s=o.length),d(e,A)?$(c(o,s)):0};function vA(A){if(A.opaquePath)return A.path[0];{let e="";for(let t of A.path)e+=`/${t}`;return e}}function fe(A){switch(A.scheme){case"blob":{let e=H(vA(A),null,null,0);return e===null||e.scheme!=="http"&&e.scheme!=="https"?"null":fe(e)}case"ftp":case"http":case"https":case"ws":case"wss":return(function(t){let n=`${t.scheme}://`;return n+=t.host,t.port!==null&&(n+=`:${t.port}`),n})(A);default:return"null"}}var S=Symbol("URLImpl"),eA=class A{constructor(e,t){if(e===void 0&&t===void 0)throw new TypeError('The "url" argument must be specified.');e=b(e),t!=null&&(t=b(t));let n=null;if(t!=null&&(n=H(t,null,null,0),n==null))throw new TypeError(`Invalid base URL: ${t}`);let r=H(e,null,n,0);if(r==null)throw new TypeError(`Invalid URL: ${e}`);this[S]={url:r,query:null}}static createObjectURL(e){throw new TypeError("URL.createObjetURL is unsupported")}static revokeObjectURL(e){}static parse(e,t){e=b(e),t!==void 0&&(t=b(t));try{return new A(e,t)}catch{return null}}static canParse(e,t){e=b(e),t!==void 0&&(t=b(t));let n=null;return t!=null&&(n=H(t,null,null,0),n==null)?!1:H(e,null,n,0)!=null}get href(){return(function(t){let n=`${t.scheme}:`;return t.host!==null&&(n+="//",(t.username!==""||t.password!=="")&&(n+=t.username,t.password!==""&&(n+=`:${t.password}`),n+="@"),n+=t.host,t.port!==null&&(n+=`:${t.port}`)),t.host===null&&!t.opaquePath&&t.path.length>1&&t.path[0]===""&&(n+="/."),n+=vA(t),t.query!==null&&(n+=`?${t.query}`),t.fragment!==null&&(n+=`#${t.fragment}`),n})(this[S].url)}set href(e){let t=H(e=b(e),null,null,0);if(t==null)throw new TypeError(`Invalid URL: ${e}`);this[S].url=t,this[S].query&&yA(this[S].query,t.query)}get origin(){return fe(this[S].url)}get protocol(){return`${this[S].url.scheme}:`}set protocol(e){H(`${e=b(e)}:`,this[S].url,null,2)}get username(){return this[S].url.username}set username(e){e=b(e),wA(this[S].url)||(function(n,r){n.username=U(r,cA)})(this[S].url,e)}get password(){return this[S].url.password}set password(e){e=b(e),wA(this[S].url)||(function(n,r){n.password=U(r,cA)})(this[S].url,e)}get host(){let{url:e}=this[S];return e.host==null?"":e.port==null?e.host:`${e.host}:${e.port}`}set host(e){e=b(e),this[S].url.opaquePath||H(e,this[S].url,null,3)}get hostname(){let{url:e}=this[S];return e.host!=null?e.host:""}set hostname(e){e=b(e),this[S].url.opaquePath||H(e,this[S].url,null,4)}get port(){let{url:e}=this[S];return e.port!=null?`${e.port}`:""}set port(e){e=b(e);let{url:t}=this[S];wA(t)||(e?H(e,t,null,5):t.port=null)}get pathname(){return vA(this[S].url)}set pathname(e){e=b(e);let{url:t}=this[S];t.opaquePath||(t.path=[],H(e,t,null,6))}get search(){let{url:e}=this[S];return e.query?`?${e.query}`:""}set search(e){e=b(e);let{url:t,query:n}=this[S];if(!e)t.query=null,n&&yA(n,null);else{let r=e[0]==="?"?e.substring(1):e;t.query="",H(r,t,null,7),n&&yA(n,t.query)}}get searchParams(){let e=this[S],t=e.query;return t==null&&(t=e.query=(function(r,u){let l=new fA;return l[I].url=r,l[I].serialized=u==null,u&&(l[I].list=qA(u)),l})(this,e.url.query)),t}get hash(){let{url:e}=this[S];return e.fragment?`#${e.fragment}`:""}set hash(e){e=b(e);let{url:t}=this[S];if(!e)t.fragment=null;else{let n=e[0]==="#"?e.substring(1):e;t.fragment="",H(n,t,null,8)}}toJSON(){return this.href}toString(){return this.href}};Object.defineProperty(eA.prototype,Symbol.toStringTag,{value:"URL",configurable:!0});var I=Symbol("URLSearchParamsImpl"),We=Symbol.dispose||Symbol.for("dispose");function yA(A,e){e?A[I].list=qA(e):A[I].list.length=0,A[I].serialized=e==null}function oA(A){if(A.url){let e=IA(A.list);(function(n,r){n[S].url.query=r})(A.url,e||null),A.serialized=!0}}var Ze=typeof Iterator<"u"?Iterator:Object,Z=class extends Ze{constructor(e,t){super(),this[I]={ptr:e,map:t,index:0}}next(){let e=this[I];return e.index<e.ptr.list.length?{value:e.map(e.ptr.list[e.index++]),done:!1}:{value:void 0,done:!0}}[Symbol.iterator](){return this}[We](){}},fA=class{constructor(e){let t=this[I]={list:[],url:null,serialized:!0},n;if(Array.isArray(e))for(let r=0;r<e.length;r++)t.list.push(QA(e[r]));else if((n=ZA(e))!=null){let r;for(;!(r=PA(n.next())).done;)t.list.push(QA(r.value))}else if((typeof e=="object"||typeof e=="function")&&e!=null){let r=Object.keys(e);for(let u=0;u<r.length;u++){let l=r[u],a=Se(l),h=b(e[l]),f=t.list.find(g=>g[0]===a);f?f[1]=h:t.list.push([a,h])}}else if(e!==void 0){let r=b(e);r=r[0]==="?"?r.substring(1):r,t.list=qA(r)}}get size(){return this[I].list.length}append(e,t){e=b(e),t=b(t),this[I].list.push([e,t]);let n=this[I];n.url&&n.serialized?(function(u,l){let a=u[S].url;a.query=a.query?`${a.query}&${l}`:l})(n.url,IA([[e,t]])):oA(n)}delete(e,t){e=b(e),t=t!=null?b(t):void 0;let{list:n}=this[I],r=0;for(;r<n.length;)n[r][0]===e&&(t==null||n[r][1]===t)?n.splice(r,1):r++;oA(this[I])}get(e){e=b(e);let{list:t}=this[I];for(let n=0;n<t.length;n++)if(t[n][0]===e)return t[n][1];return null}getAll(e){e=b(e);let t=[],{list:n}=this[I];for(let r=0;r<n.length;r++)n[r][0]===e&&t.push(n[r][1]);return t}has(e,t){e=b(e),t=t!=null?b(t):void 0;let{list:n}=this[I];for(let r=0;r<n.length;r++)if(n[r][0]===e&&(t==null||n[r][1]===t))return!0;return!1}set(e,t){e=b(e),t=b(t);let{list:n}=this[I],r=!1,u=!1,l=0;for(;l<n.length;)n[l][0]===e?r?(n.splice(l,1),u=!0):(r=!0,n[l][1]!==t&&(n[l][1]=t,u=!0),l++):l++;r||(n.push([e,t]),u=!0),u&&oA(this[I])}sort(){this[I].list.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),oA(this[I])}forEach(e,t){if(typeof e!="function")throw new TypeError('The "callback" argument must be of type function');let{list:n}=this[I];for(let r=0;r<n.length;r++)e.call(t,n[r][1],n[r][0],this)}entries(){return new Z(this[I],e=>e)}keys(){return new Z(this[I],e=>e[0])}values(){return new Z(this[I],e=>e[1])}toString(){return IA(this[I].list)}[Symbol.iterator](){return this.entries()}};Object.defineProperty(fA.prototype,Symbol.toStringTag,{value:"URLSearchParams",configurable:!0});function he(A){let e,t=()=>typeof e=="string"?e:e?.accessToken,n=0,r,u=new Map,l=()=>{for(let p of[...u.keys()])try{p()}catch{}};function a(p){let w=++n;r=void 0,e=void 0;for(let y of[...u.values()])try{y?.()}catch{}w===n&&(e=p,l())}let h=()=>a();function f(p,w=!1){let y=UA.safeParse(p);if(!y.success||w&&Date.parse(y.data.expiresAt)<=Date.now()||Date.parse(y.data.refreshExpiresAt)<=Date.now()||Date.parse(y.data.refreshExpiresAt)<Date.parse(y.data.expiresAt))throw new P("INVALID_RESPONSE","Invalid customer session credentials");return y.data}async function g(){if(r)return r;let p=typeof e=="object"?e:void 0,w=n;if(!p||Date.parse(p.refreshExpiresAt)<=Date.now())throw p&&h(),new P("UNAUTHENTICATED","Customer authentication is required",401);let y=(async()=>{try{let R=await A(p.refreshToken);if(w!==n)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");let Y=f(R,!0);if(Y.customerId!==p.customerId||Y.sessionId!==p.sessionId)throw new P("SCOPE_MISMATCH","Refresh changed the customer session");return e=Y,{...Y}}catch(R){throw w!==n?new P("IDENTITY_CHANGED","Customer identity changed during refresh"):(R instanceof P&&R.status===401&&h(),R)}})();r=y;try{return await y}finally{r===y&&(r=void 0)}}return{identify(p){let w=typeof p=="string"?p:f(p),y=typeof w=="string"?w:w.accessToken;if(!y.trim()||/\s/.test(y)||y.length>4096)throw new P("INVALID_TOKEN","A server-issued token is required");a(w)},reset:h,subscribeIdentity(p,w){return u.set(p,w),()=>{u.delete(p)}},access(){let p=typeof e=="object"?e:void 0;if(p&&Date.parse(p.expiresAt)<=Date.now()+3e4){let y=n;return g().then(()=>{let R=t();if(y!==n||!R)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");return R})}let w=t();if(!w)throw new P("NOT_IDENTIFIED","Identify a customer session before making a request");return w},peek:t,snapshot:()=>typeof e=="object"?{...e}:void 0,refresh:g}}var de=Symbol("IndianaNoContent");function dt(A,e,t=eA){let n=A.configuration?.scope,r=A.scope??(n&&{projectId:n.projectId,environment:n.environment}),u=r?sA.parse(r):void 0;if(u&&n&&(u.projectId!==n.projectId||u.environment!==n.environment))throw new P("SCOPE_MISMATCH","Configuration belongs to another App/environment");let l=new t(A.baseUrl??zA);if(l.username||l.password||l.search||l.hash)throw new P("INVALID_URL","baseUrl must not contain credentials, query, or fragment");if(l.protocol!=="https:"&&!(l.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(l.hostname)))throw new P("INVALID_URL","Use HTTPS, or HTTP on localhost during development");let a=A.fetch??globalThis.fetch.bind(globalThis),h=A.timeoutMs??1e4;if(!Number.isFinite(h)||h<1||h>12e4)throw new P("INVALID_TIMEOUT","timeoutMs must be between 1 and 120000");let f=!1,g=0,p=null,w=new Set,y=A.session??he(async v=>{let T=await tA("customer-sessions/refresh",{},"POST",{},v);if(!T||typeof T!="object")throw new P("INVALID_RESPONSE","Invalid refresh response");let{requestId:B,scope:_,...V}=T;return V});function R(){g+=1,p=null;for(let v of w)v.abort();w.clear()}let Y=y.subscribeIdentity(R);function pe(){f||y.reset()}async function tA(v,T={},B="POST",_={},V){let k=_.installationDetach===!0;if(k&&(v!=="push/installations/detach"||B!=="POST"))throw new P("INVALID_REQUEST","Installation authority only detaches this installation");if(!V&&!k)throw new P("NOT_IDENTIFIED","Call identify with a server-issued customer token first");let X=g,L=new AbortController;k||w.add(L);let nA=()=>!k&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):new P("TIMEOUT","The request timed out"),dA,we=new Promise((q,N)=>{dA=()=>N(nA()),L.signal.addEventListener("abort",dA,{once:!0})}),ye=setTimeout(()=>L.abort(),_.timeoutMs??h),Pe=async()=>{let q=await a(`${l.href.replace(/\/$/,"")}/api/v1/${v}`,{method:B,headers:{..._.headers,"Content-Type":"application/json",...k?{}:{Authorization:`Bearer ${V}`},[pA]:gA.current,[FA]:$A.version,...u?{"X-Indiana-Project":u.projectId,"X-Indiana-Environment":u.environment}:{}},body:B==="POST"?JSON.stringify(T):void 0,signal:L.signal,credentials:"omit",cache:B==="POST"&&typeof document<"u"&&v==="funnels"&&T!==null&&typeof T=="object"&&"operation"in T&&(T.operation==="start"||T.operation==="shown")?"default":"no-store",redirect:"error",..._.keepalive?{keepalive:!0}:{}});if(L.signal.aborted)throw nA();let N;try{N=q.status===204?de:await q.json()}catch{throw L.signal.aborted?nA():new P(q.ok?"INVALID_RESPONSE":"HTTP_ERROR","The gateway returned an unreadable response",q.status,q.headers.get("X-Request-Id")??void 0)}if(L.signal.aborted)throw nA();if(!k&&X!==g)throw new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight");if(!q.ok){let O=xA.safeParse(N),z=O.success&&(!_A.safeParse(O.data.error.code).success||jA(O.data.error.code,q.status)),HA=z?O.data.error.code:"HTTP_ERROR",BA=MA(HA,q.status,{retryAfter:q.headers.get("Retry-After"),recovery:z?O.data.error.recovery:void 0,reason:z?O.data.error.reason:void 0});throw new P(HA,z?O.data.error.message:"The request failed",q.status,q.headers.get("X-Request-Id")??(O.success?O.data.requestId:void 0),{...BA,...O.success&&O.data.error.retryable===!1?{retryable:!1}:{},...BA.retryAfterSeconds===void 0&&O.success&&O.data.error.retryAfterSeconds!==void 0?{retryAfterSeconds:O.data.error.retryAfterSeconds}:{}})}if(q.headers.get(pA)!==gA.current)throw new P("PROTOCOL_MISMATCH","Response protocol does not match this SDK");if(u&&N!==de){let O=N&&typeof N=="object"&&"scope"in N?N:N&&typeof N=="object"&&"configuration"in N?N.configuration:null;if(!O||typeof O!="object"||!("scope"in O))throw new P("INVALID_RESPONSE","Response is missing its App/environment scope");let z=sA.safeParse(O.scope);if(!z.success||z.data.projectId!==u.projectId||z.data.environment!==u.environment)throw new P("SCOPE_MISMATCH","Response scope does not match this SDK instance")}let rA=q.headers.get("X-Indiana-Telemetry-Subject");if(rA){if(!/^[a-f0-9]{64}$/.test(rA))throw new P("INVALID_RESPONSE","Invalid telemetry identity");p!==rA&&(p=rA,e?.(p))}return N};try{return await Promise.race([Pe(),we])}catch(q){throw!k&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):q instanceof P?q:new P(L.signal.aborted?"TIMEOUT":"NETWORK_ERROR",L.signal.aborted?"The request timed out":"Unable to read the response")}finally{clearTimeout(ye),L.signal.removeEventListener("abort",dA),w.delete(L)}}function ge(v,T={},B="POST",_={}){if(f)return Promise.reject(new P("CLOSED","SDK client was destroyed"));if(_.installationDetach)return tA(v,T,B,_);let V=g;try{let k=y.access(),X=L=>{if(V!==g)throw new P("IDENTITY_CHANGED","Customer identity changed before dispatch");return tA(v,T,B,_,L)};return typeof k=="string"?X(k):k.then(X)}catch(k){return Promise.reject(k)}}let me=Object.assign(ge,{captureIdentity(){let v=g,T=f,B=!!y.peek();return()=>{if(T)throw new P("CLOSED","SDK client was destroyed");if(!B)throw new P("NOT_IDENTIFIED","Call identify with a server-issued customer token first");if(v!==g)throw new P("IDENTITY_CHANGED","Customer identity changed before dispatch")}}});return{session:y,requestWithCredential(v,T,B,_={}){return f?Promise.reject(new P("CLOSED","SDK client was destroyed")):tA(v,T,"POST",_,B)},subjectKey:()=>p,identify(v){if(f)throw new P("CLOSED","SDK client was destroyed");if(u&&typeof v=="object"&&"scope"in v){let T=sA.safeParse(v.scope);if(!T.success||T.data.projectId!==u.projectId||T.data.environment!==u.environment)throw new P("SCOPE_MISMATCH","Customer session belongs to another App/environment")}y.identify(v)},reset:pe,dispose(){f||(f=!0,Y(),R())},request:me}}export{eA as a,dt as b};
1
+ import{b as UA}from"./chunk-J4VTKRH7.js";import{a as P}from"./chunk-HJLGRW4A.js";import{a as _A,d as jA,e as xA,f as MA,h as sA}from"./chunk-XIP32WI7.js";import{a as $A,b as zA}from"./chunk-FVGUBIVT.js";var pA="X-Indiana-Protocol",FA="X-Indiana-SDK-Version";var gA={current:"0.10"};function b(A){return typeof A=="string"?A:String(A)}var De=/[\ud800-\udbff](?![\udc00-\udfff])|(^|[^\ud800-\udbff])[\udc00-\udfff]/g;function Se(A){return A.replace(De,"$1\uFFFD")}function PA(A,e){if(typeof A!="object"||A==null){let t="";throw t+="The provided value is not an object",new TypeError(t)}return A}function ZA(A){if(A!=null&&(typeof A=="object"||typeof A=="function")){let e=A[Symbol.iterator];if(e==null)return;if(typeof e!="function")throw new TypeError("The provided value is not iterable");let t=e.call(A);if(!t||typeof t!="object")throw new TypeError("Result of the Symbol.iterator method is not an object");return t}}function QA(A){let e;if(Array.isArray(A)){let t=A.map(b);if(t.length===2)return t}else if((e=ZA(A))!=null){let t=PA(e.next()),n=PA(e.next());if(!t.done&&!n.done)return[b(t.value),b(n.value)]}throw new TypeError("Each query pair must be an iterable [name, value] tuple")}var GA="0123456789ABCDEF",be=/(?:%[0-9A-Fa-f]{2})+/g;function M(A){return`%${GA[A>>4&15]}${GA[15&A]}`}function Ae(A,e,t=!1){return A>=55296&&A<=57343&&(A=65533),A<=127?t&&A===32?"+":e(A)?M(A):String.fromCharCode(A):A<=2047?M(192|A>>6)+M(128|63&A):A<=65535?M(224|A>>12)+M(128|A>>6&63)+M(128|63&A):M(240|A>>18)+M(128|A>>12&63)+M(128|A>>6&63)+M(128|63&A)}function DA(A){return A>=48&&A<=57?A-48:A>=65&&A<=70?A-65+10:A>=97&&A<=102?A-97+10:-1}function SA(A,e=!1){let t=0;for(;t<A.length;t++){let n=A.charCodeAt(t);if(n===37||e&&n===43)break}return t===A.length?A:(e?A.replace(/\+/g," "):A).replace(be,n=>{try{return decodeURIComponent(n)}catch{return"\uFFFD".repeat(n.length/3)}})}function AA(A){return A<=31||A>126}function Ie(A){switch(A){case 32:case 34:case 60:case 62:case 96:return!0;default:return AA(A)}}function OA(A){switch(A){case 32:case 34:case 35:case 60:case 62:return!0;default:return AA(A)}}function Ce(A){return OA(A)||A===39}function bA(A){switch(A){case 63:case 94:case 96:case 123:case 125:return!0;default:return OA(A)}}function cA(A){switch(A){case 47:case 58:case 59:case 61:case 64:case 91:case 92:case 93:case 124:return!0;default:return bA(A)}}function KA(A){switch(A){case 33:case 39:case 40:case 41:case 126:return!0;default:return(function(t){switch(t){case 36:case 37:case 38:case 43:case 44:return!0;default:return cA(t)}})(A)}}function ee(A,e){return Ae(A=A||0,e)}function U(A,e,t=!1){let n=0;for(;n<A.length;n++){let u=A.charCodeAt(n);if(u>=128||t&&u===32||e(u))break}if(n===A.length)return A;let r=A.slice(0,n);for(;n<A.length;n++){let u=A.charCodeAt(n),l=u;if(u>=55296&&u<=56319&&n+1<A.length){let a=A.charCodeAt(n+1);a>=56320&&a<=57343&&(l=(u-55296<<10)+a-56320+65536,n++)}r+=Ae(l,e,t)}return r}function qA(A){let e=[],t=0,n=0;for(;n<=A.length;){if(n=A.indexOf("&",t),n<0&&(n=A.length),n!==t){let r=A.slice(t,n),u=r.indexOf("=");u<0&&(u=r.length),e.push([SA(r.slice(0,u),!0),SA(r.slice(u+1),!0)])}if(t=n+1,n===A.length)break}return e}function IA(A){let e="";for(let t=0;t<A.length;t++){let n=U(A[t][0],KA,!0),r=U(A[t][1],KA,!0);e+=t!==0?`&${n}=${r}`:`${n}=${r}`}return e}var Ee=[2191,2191,3164,3164,3292,3292,6863,6877,6880,6891,8385,8385,11158,11158,42958,42959,42962,42962,42964,42964,42993,42993,64451,64466,64912,64913,64968,64974,67904,67929,69317,69319,69328,69336,69370,69371,72544,72551,73136,73179,73184,73193,93856,93880,93883,93907,94194,94198,100344,100351,101641,101662,101760,101874,118010,118012,118458,118480,118496,118512,124608,124638,124640,124661,124670,124671,128728,128728,128887,128890,129232,129240,129620,129623,129674,129674,129678,129678,129736,129736,129741,129741,129770,129770,129775,129775,130042,130042,177978,177983,183970,183981,205744,210041],Te=[7296,7297,7298,7299,7300,7301,7302,7303,7304,42958,42962,42964,42993],ve=["\u0432","\u0434","\u043E","\u0441","\u0442","\u0442","\u044A","\u0463","\uA64B","\uA7CF","\uA7D3","\uA7D5","s"],Oe=[2381,2381,2509,2509,2637,2637,2765,2765,2893,2893,3021,3021,3149,3149,3277,3277,3387,3388,3405,3405,3530,3530,3642,3642,3770,3770,3972,3972,4153,4154,5908,5909,5940,5940,6098,6098,6752,6752,6980,6980,7082,7083,7154,7155,11647,11647,43014,43014,43052,43052,43204,43204,43347,43347,43456,43456,43766,43766,44013,44013,68159,68159,69702,69702,69744,69744,69759,69759,69817,69817,69939,69940,70080,70080,70197,70197,70378,70378,70477,70477,70606,70608,70722,70722,70850,70850,71103,71103,71231,71231,71350,71350,71467,71467,71737,71737,71997,71998,72160,72160,72244,72244,72263,72263,72345,72345,72767,72767,73028,73029,73111,73111,73537,73538,90415,90415];function qe(A){for(let e=0;e<A.length;e++){let t=A.codePointAt(e);if(t>65535&&e++,t<=32||t===37||t===127||t>=55296&&t<=57343||t>=128&&t<=159||t>=64976&&t<=65007||!(65534&~t)||t===65533)return!0}return!1}var[Re,Ne,ke,YA]=[[[],"0,6,7,8,m,w,10,1b,1d,1f,72,73,7k,8k,dt,2rk","AAAAAAAAAAAAAAAAAAAAAP////8AAAAAAAAAAAAAAAA/AAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAADAAABwfwAAAAAAAMADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhAAAAQAAAAAAAAQCAAABAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgACAAAAAAAAAAAAAAAAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAP///////////////wAAAAAAAAAAAAAAAAAAAAA="],[[],"6,7,8,o,4o,7e,7f,7h,7i,7j,dl","AAAAAEF9+P/+BwAAAMAA//8AAPz/////BlADAAAAAJwAAPz///8AAADA//H/5+X8AAAAAAAAAAAA/P///wcAAAAAAAAAAAAAPv0vAD0BAABA/gAA/5/5/f8BAAAAAAAAgAAAAP//////////////AYD/////BQAAAAAAAAAAAAAAAAAAAAAAAP///////wcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD8g+N8B+AAAAAAAAAAAAAAAAAAAAAAAAP//AwAAYAAAAAAAAAAAAAD/////CwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANgAAAAAAAAAAAAAAAAA//8fAB4AAAD//wMAAAAAAH3/HgwAAAAAAAD//////////w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="],[[],"6,7,8,o,4o,7e,7f,7h,7i,7j,dl","AAAAAP3////+BwAAAMDu//////////////8vAADAAJwAAP3///8AAADg////////AAAAAAAAAAAA/P///wcAAAAAAAAAAAAA////Ab0H//9H/gAA/9////8BAAAAAAAAgAAAAP//////////////AYD/////BQAAAAAAAAAAAAAAAAAAAAAAAP///////wcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL/G//8T+AAAAAAAAAAAAAAAAAAAAAAAAP//AwAAfgAAAAAAAAAAAAD+////DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANwAAAAAAAAAAAAAAAAA//8fAB4AAAD//wMAAAAAAH3/Hg4AAAAAAAD//////////w8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="],[[],"0,3,4,5,6,7,8,9,a,b,c,d,e,f,g,j,n,o,p,q,r,s,t,w,18,19,1c,4m,4o,4p,4q,4r,6z,72,73,75,76,77,7e,7h,7i,7j,7k,7l,7m,7n,7o,7p,7q,7r,7s,7t,7u,7v,7w,7x,7y,7z,8k,9t,a2,a3,a7,cc,cv,cx,cy,d6,dc,dd,de,dg,dh,di,dk,dl,2rk,2rl","AAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAD//////////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4AwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/v////+/tgAAAAAAAAAAAP8XAAAAAAD4//8AAAEAAAAAAAAAAAAAAMCfnz0AAACAAgAAAP///wcAAAAAAAAAAAAAwP8BAAAAAAAA+A8gAADA++8+AAAAAAAOAAAAAAAAgP8AAAAAAPz///v///8HAAAAAAAAFP4h/gAMAAAAAgAAAAAAABAeIAAADAAAQAYAAAAAAAAQhjkCAAAAIwAGAAAAAAAAEL4hAAAMAAD8AgAAAAAAAJAeIGAADAAAAAQAAAAAAAAAASAAAAAAAAARAAAAAAAA0ME9YAAMAAAAAgAAAAAAAJBAMAAADAAAAAMAAAAAAAAYHiAAAAwAAAACAAAAAAAAAAAEXAAAAAAAAAAAAAAA8geAfwAAAAAAAAAAAAAAAPIfAH8AAAAAAAAAAAADAACgAgAAAAAAAP5/3+D//v///x9AAAAAAAAAAAAAAAAA4P1mAAAAwwEAHgBkIAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwAAAAMAAAADAAAAAwAAAAAAAAAsD9A/g8gAAAAAAC4AAAAAAAAAAAAAAAAAABgAAAAAAIAAAAAAAAAAAAAAAAAAIcBBA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAJAAAAAAAAQH/lH/ifAAAAAAAA//////8//w8AAA8AAAAAANAXBAAAAAD4DwADAAAAPDsAAAAAAABAowMAAAAAAADwzwAAAAAAAAAAAAAAAAAAAAAAAAD3//0hEAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//////////wDIAAAAfAAAAAAAAB/8AAAAAAAAAAAAAAAA/////wEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAwAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAA/////wAAAAAAPAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAID3PwAAAMAAAAAAAAAAAAAAAwBECAAAYBAAAAAAAAAAAAAAAAAAAAAAAAAwAAAA//8DgAAAAADAPwAAgP8DAAAAAAAHAAAAAADIMwAAAAAgAAAAAAAAAAB+ZgAIEAAAAAAAEAAAAAAAAJ3BAgAAAAAwQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAICEAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAP//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAMAHAAAAAAAAAAAAAAAAAAAAAG7wAAAAAACHAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAPAAAAAAAAAAAD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYAAAAAAAAAAAA/AAAAAAAAAAAwP8BAAAAAAA8AAAAAAAAAAAAAAAAAAAAAgAAAAAAAP9/AAAAAAAZgAMAAAAAAHgGBAAAAAAAAAAHAAAAgO8fAAAAAAAAAAgAAwAAAAAAwH8AngAAAAAAAAAAAAAAgNNAAgAAAAAAAAAAAAAAAAAAAAAAAID4BwAAAwAAAAAAABgBAAAAwB8fAAAAAAAAAAD4AUAFAAYAAAAAAAAAAAAA/1wAAEAAAAAAAAAAAAAA+IUNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8sAEAADAAAAAAAAAAAAAA+KcBAAAAAAAAAAAAAAAAKL8AAAAAAAAAAAAAAACgvA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgP8GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFgIAAAAAAAAAAAAAAAAAAAAAADwDAEAAAD+BwAAAAD4eYAAfg4AAAAAAPx/AwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf78AAAAAAAAAAAAA/P///G0AAAAAAAAAAAAAAAAAAAB+tL8AAAAAAAAAAACjAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAwAAAAAAwAcFAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//4H/PwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMD/4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHwAAAAAAAAB/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAgAcAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAPAAAAAAAAAAAAAAD//////z///38AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAD+P/nDwAAADwAAAAAAAAAAAAAAAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///////9/+P//////HyAAEAAA+P7/AAAAAAAAAAAAAH////nbBwAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASMAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAfwAAAAAAAAAAAAAAAADwDwAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAA////////////////AAAAAAAAAAAAAAAAAAAAAP///////////////////////////////////////wAA"]].map(function([e,t,n]){return[e,t.split(",").map(r=>parseInt(r,36)),Uint8Array.from(atob(n),r=>r.charCodeAt(0))]});function Le(A,e){return e===931||e===1010||e===120531||e===120589||e===120647||e===120705||e===120763?"\u03C3":e>=5112&&e<=5117?String.fromCodePoint(e-8):e>=43888&&e<=43967?String.fromCodePoint(e-38864):e>=93856&&e<=93880?String.fromCodePoint(e+27):e===837||e===890||e>=8064&&e<=8111||e>=8114&&e<=8188?A.normalize("NFD").replace(/\u0345/g,"\u03B9").normalize("NFC").toLowerCase():""}function te(A,e){for(let t=0;t<A.length;t+=2)if(e>=A[t]&&e<=A[t+1])return!0;return!1}function W(A,e){let[t,n,r]=A,u=e>>8;for(let h=0;h<t.length;h+=2)if(u>=t[h]&&u<=t[h+1])return!0;let l=n.indexOf(u);if(l<0)return!1;let a=255&e;return!!(r[32*l+(a>>3)]&1<<(7&a))}function He(A){let e=Array.from(A,t=>t.codePointAt(0));for(let t=0;t<e.length;t++){let n=e[t];if(n!==8204&&n!==8205||t>0&&te(Oe,e[t-1]))continue;if(n===8205)return!1;let r=t-1;for(;r>=0&&W(YA,e[r]);)r--;let u=t+1;for(;u<e.length&&W(YA,e[u]);)u++;if(!(r>=0&&u<e.length&&W(Ne,e[r])&&W(ke,e[u])))return!1}return!0}var Be=/(?![\p{Mark}\p{Decimal_Number}])[\p{Script=Arabic}\p{Script=Hebrew}]/u,_e=/\p{Script=Latin}/u;function je(A){return!Be.test(A)||!_e.test(A)}var F=36,iA=1,CA=26,xe=38,Me=700,Ue=72,$e=128,ze=2147483647;function VA(A){return String.fromCharCode(A+22+75*+(A<26))}function Fe(A,e,t){let n=0;for(A=t?Math.floor(A/Me):A>>1,A+=Math.floor(A/e);A>(F-iA)*CA>>1;n+=F)A=Math.floor(A/(F-iA));return Math.floor(n+(F-iA+1)*A/(A+xe))}function Qe(A){let e=Array.from(A,h=>h.codePointAt(0)),t="",n=0;for(let h=0;h<e.length;h++){let f=e[h];f<128&&(t+=String.fromCharCode(f),n++)}let r=n;r&&(t+="-");let u=$e,l=0,a=Ue;for(;n<e.length;){let h=ze;for(let f=0;f<e.length;f++){let g=e[f];g>=u&&g<h&&(h=g)}l+=(h-u)*(n+1),u=h;for(let f=0;f<e.length;f++){let g=e[f];if(g<u&&l++,g===u){let p=l;for(let w=F;;w+=F){let y=w<=a?iA:w>=a+CA?CA:w-a;if(p<y)break;t+=VA(y+(p-y)%(F-y)),p=Math.floor((p-y)/(F-y))}t+=VA(p),a=Fe(l,n+1,n===r),l=0,n++}}l++,u++}return t}function mA(A){let e=10;if(A.length>=2&&A[0]==="0"&&(A[1]==="x"||A[1]==="X"))A=A.slice(2),e=16;else if(A.length>=2&&A[0]==="0")A=A.slice(1),e=8;else if(A==="")return-1;let t=0;for(let n=0;n<A.length;n++){let r=DA(A.charCodeAt(n));if(r>=e||r<0)return-1;t=t*e+r}return t}function XA(A){switch(A){case".":case"%2e":case"%2E":return!0;default:return!1}}function ne(A,e){return(A>=65&&A<=90||A>=97&&A<=122)&&(e===58||e===124)}function re(A){return A.length===2&&ne(A.codePointAt(0),A.codePointAt(1))}function JA(A){return A.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u)!==-1}function C(A){switch(A){case"ftp":case"http":case"https":case"ws":case"wss":case"file":return!0;default:return!1}}function se(A){switch(A){case"ftp":return 21;case"http":case"ws":return 80;case"https":case"wss":return 443;default:return null}}function EA(A,e){if(A[0]==="[")return A[A.length-1]==="]"?(function(n){let r=[0,0,0,0,0,0,0,0],u=null,l=0,a=0,h=Array.from(n,f=>f.codePointAt(0));if(h[a]===58){if(h[a+1]!==58)return null;a+=2,l++,u=l}for(;a<h.length;){if(l===8)return null;if(h[a]===58){if(u!==null)return null;a++,l++,u=l;continue}let f=0,g=0,p=0;for(;p<4&&(f=DA(h[a]))>=0;)g=(g<<4)+f,a++,p++;if(h[a]===46){if(p===0||l>6)return null;a-=p;let w=0;for(;h[a]!==void 0;){let y=0;if(w>0)if(h[a]===46&&w<4)a++;else return null;if(h[a]==null||h[a]<48||h[a]>57)return null;for(;h[a]>=48&&h[a]<=57;){if(y=10*y+DA(h[a]),y>255)return null;a++}r[l]=256*r[l]+y,w++,w%2==0&&l++}if(w!==4)return null;break}else if(h[a]===58){if(h[++a]===void 0)return null}else if(h[a]!==void 0)return null;r[l]=g,l++}if(u!==null){let f=l-u;for(l=7;l!==0&&f>0;){let g=r[u+f-1];r[u+f-1]=r[l],r[l]=g,l--,f--}}else if(u===null&&l!==8)return null;return r})(A.substring(1,A.length-1)):null;if(e)return(function(n){return JA(n)?null:U(n,AA)})(A);{let t=(function(r){let u=!1,l=!1;for(let h=0;h<r.length;h++){let f=r.charCodeAt(h);if(f<=32||f===37||f===127)return null;if(f>=128){u=!0;break}f>=65&&f<=90&&(l=!0)}if(!u)return r!==""?l?r.toLowerCase():r:null;if((function(f){for(let g of f){let p=g.codePointAt(0);if(/[\p{Cn}\p{Co}\p{Cs}\p{Noncharacter_Code_Point}]/u.test(g)&&!te(Ee,p)||W(Re,p))return!0}return!1})(r))return null;let a=(r=(function(f){let g="";for(let p of f){let w=p.codePointAt(0);if(w!==8204&&w!==8205&&/\p{Default_Ignorable_Code_Point}/u.test(p))continue;let y=Le(p,w);if(y){g+=y;continue}let R=Te.indexOf(w);g+=R<0?p:ve[R]}return g})(r).normalize("NFKC").replace(/[\u3002\uff0e\uff61]/g,".").toLowerCase()).split(".");for(let h=0;h<a.length;h++){let f=a[h];if(f==="")continue;let g=/[^\0-\x7f]/.test(f);if(qe(f)||g&&(/^\p{Mark}/u.test(f)||!He(f)||!je(f)||f.startsWith("xn--")))return null;g&&(a[h]=`xn--${Qe(f)}`)}return(r=a.join("."))!==""?r:null})(A.indexOf("%")===-1?A:SA(A));return t===null||JA(t)?null:(function(r){let u=r.length,l=r.lastIndexOf(".",u-2)+1;if(r.charCodeAt(u-1)===46&&u--,u<=l)return!1;if(mA(r.slice(l,u))>=0)return!0;for(;l<u;l++){let a=r.charCodeAt(l);if(a<48||a>57)return!1}return!0})(t)?(function(r){let u=r.split("."),l=u.length;if(u[l-1]||l--,l>4)return null;let a=0;for(let f=0;f<l-1;f++){let g=mA(u[f]);if(g<0||g>255)return null;a+=g*(1<<8*(3-f))}let h=mA(u[l-1]);return h<0||h>=256**(5-l)?null:(a+=h,a)})(t):t}}function TA(A){return typeof A=="number"?(function(t){let r="";return r+=`${(t>>>24&255).toString(10)}.`,r+=`${(t>>>16&255).toString(10)}.`,r+=`${(t>>>8&255).toString(10)}.`,r+=(t&255).toString(10),r})(A):Array.isArray(A)?`[${(function(t){let n=(function(a){let h=-1,f=-1,g=1,p=0;for(let w=0;w<a.length;++w)a[w]!==0?(p>g&&(h=f,g=p),f=-1,p=0):(f===-1&&(f=w),++p);return p>g?f:h})(t),r="",u=!1;for(let l=0;l<=7;++l)if(!(u&&t[l]===0)){if(u&&(u=!1),n===l){r+=l===0?"::":":",u=!0;continue}r+=t[l].toString(16),l!==7&&(r+=":")}return r})(A)}]`:A}function oe(A){A.path.length>0&&(A.path.length!==1||A.scheme!=="file"||!(function(t){return/^[A-Za-z]:$/u.test(t)})(A.path[0]))&&A.path.pop()}function ie(A){return A.username!==""||A.password!==""}function wA(A){return A.host===null||A.host===""||A.scheme==="file"}var s=0,o="",m="",D=null,i,lA=!1,uA=!1,G=!1,E;function H(A,e,t,n){e||(A=(function(l){let a=0,h=l.length;for(;a<h&&!(l.charCodeAt(a)>32);++a);for(;h>a&&!(l.charCodeAt(h-1)>32);--h);return l.substring(a,h)})(A)),A=(function(l){let a=0;for(;a<l.length;a++){let f=l.charCodeAt(a);if(f===9||f===10||f===13)break}if(a===l.length)return l;let h=l.slice(0,a);for(;a<l.length;a++){let f=l.charCodeAt(a);f!==9&&f!==10&&f!==13&&(h+=l[a])}return h})(A),s=0,o=A,m="",D=t||null,i=e||{scheme:"",username:"",password:"",host:null,port:null,path:[],query:null,fragment:null,opaquePath:!1},lA=!1,uA=!1,G=!1,E=n||0;let r=Ge;switch(n){case 3:case 4:r=aA;break;case 5:r=NA;break;case 6:r=K;break;case 7:r=Q;break;case 8:r=$}return r(c(A,s))!==1?i:null}function d(A,e){return s+=s===A?j(e):1,s<=o.length}function c(A,e){return e<A.length?A.codePointAt(e):void 0}function j(A){return A!=null&&A>65535?2:1}function le(A){return A==null?"":A<=65535?String.fromCharCode(A):String.fromCodePoint(A)}var Ge=A=>{let e=s;if(A!=null&&(A>=65&&A<=90||A>=97&&A<=122)){let t=s+1;for(A=o.charCodeAt(t);A===43||A===45||A===46||A>=65&&A<=90||A>=97&&A<=122||A>=48&&A<=57;)t++,A=o.charCodeAt(t);return m=o.slice(s,t).toLowerCase(),s=t,Ke(t<o.length?A:void 0)}else return E?1:(--s,d(e,A)?ue(c(o,s)):0)},Ke=A=>{let e=s;if(A===58){if(E){if(C(i.scheme)!==C(m))return 0;if((ie(i)||i.port!==null)&&m==="file")return 0;if(i.scheme==="file"&&i.host==="")return 0}return i.scheme=m,E?(i.port===se(i.scheme)&&(i.port=null),0):(m="",i.scheme==="file"?d(e,A)?kA(c(o,s)):0:C(i.scheme)&&D!==null&&D.scheme===i.scheme?d(e,A)?Ye(c(o,s)):0:C(i.scheme)?d(e,A)?Xe(c(o,s)):0:c(o,s+1)===47?(s++,d(e,A)?Ve(c(o,s)):0):(i.path=[""],i.opaquePath=!0,d(e,A)?ae(c(o,s)):0))}else return E?1:(m="",s=-1,d(e,A)?ue(c(o,s)):0)},ue=A=>{let e=s;return D===null||D.opaquePath&&A!==35?1:D.opaquePath&&A===35?(i.scheme=D.scheme,i.path=D.path.slice(),i.opaquePath=D.opaquePath,i.query=D.query,i.fragment="",d(e,A)?$(c(o,s)):0):D.scheme==="file"?(s--,d(e,A)?kA(c(o,s)):0):(s--,d(e,A)?RA(c(o,s)):0)},Ye=A=>{let e=s;return A===47&&c(o,s+1)===47?(++s,d(e,A)?hA(c(o,s)):0):(s--,d(e,A)?RA(c(o,s)):0)},Ve=A=>{let e=s;return A===47?d(e,A)?J(c(o,s)):0:(s--,d(e,A)?x(c(o,s)):0)},RA=A=>{let e=s;return i.scheme=D.scheme,A===47||C(i.scheme)&&A===92?d(e,A)?WA(c(o,s)):0:(i.username=D.username,i.password=D.password,i.host=D.host,i.port=D.port,i.path=D.path.slice(),i.query=D.query,A===63?(i.query="",d(e,A)?Q(c(o,s)):0):A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):A!=null?(i.query=null,i.path.pop(),s--,d(e,A)?x(c(o,s)):0):d(e,A)?RA(c(o,s)):0)},WA=A=>{let e=s;return C(i.scheme)&&(A===47||A===92)?d(e,A)?hA(c(o,s)):0:A===47?d(e,A)?J(c(o,s)):0:(i.username=D.username,i.password=D.password,i.host=D.host,i.port=D.port,s--,d(e,A)?x(c(o,s)):0)},Xe=A=>{let e=s;return A===47&&c(o,s+1)===47?s++:s--,d(e,A)?hA(c(o,s)):0},hA=A=>{let e=s;return A!==47&&A!==92?(s--,d(e,A)?J(c(o,s)):0):d(e,A)?hA(c(o,s)):0},J=A=>{let e=s;if(A!=null&&A!==64&&A!==35&&A!==47&&A!==63&&(A!==92||!C(i.scheme))){let t=s+j(A);for(;t<o.length;){let n=c(o,t);if(n==null||n===64||n===35||n===47||n===63||n===92&&C(i.scheme))break;t+=j(n)}return m+=o.slice(s,t),s=t-1,d(e,A)?J(c(o,s)):0}if(A===64){lA&&(m=`%40${m}`),lA=!0;for(let t=0;t<m.length;t++){let n=m.codePointAt(t);if(n===58&&!uA){uA=!0;continue}let r=ee(n,cA);uA?i.password+=r:i.username+=r,n!=null&&n>65535&&t++}return m="",d(e,A)?J(c(o,s)):0}else return A==null||A===35||A===47||A===63||A===92&&C(i.scheme)?lA&&m===""?1:(s-=m.length+1,m="",d(e,A)?aA(c(o,s)):0):(m+=le(A),d(e,A)?J(c(o,s)):0)},aA=A=>{let e=s;if(E&&i.scheme==="file")return s--,d(e,A)?LA(c(o,s)):0;if(A!=null&&A!==58&&A!==35&&A!==47&&A!==63&&(A!==92||!C(i.scheme))){let t=s+j(A);for(A===91?G=!0:A===93&&(G=!1);t<o.length;){let n=c(o,t);if(n==null||!G&&n===58||n===35||n===47||n===63||n===92&&C(i.scheme))break;n===91?G=!0:n===93&&(G=!1),t+=j(n)}return m+=o.slice(s,t),s=t-1,d(e,A)?aA(c(o,s)):0}else if(A===58&&!G){if(m===""||E===4)return 1;let t=EA(m,!C(i.scheme));return t===null?1:(i.host=TA(t),m="",d(e,A)?NA(c(o,s)):0)}else if(A==null||A===35||A===47||A===63||A===92&&C(i.scheme)){if(s--,C(i.scheme)&&m==="")return 1;if(E&&m===""&&(ie(i)||i.port!==null))return 1;let t=EA(m,!C(i.scheme));return t===null?1:(i.host=TA(t),m="",E?0:d(e,A)?K(c(o,s)):0)}else return m+=le(A),d(e,A)?aA(c(o,s)):0},NA=A=>{let e=s;if(A!=null&&A>=48&&A<=57){let t=s+1;for(;t<o.length;){let n=o.charCodeAt(t);if(n<48||n>57)break;t++}return m+=o.slice(s,t),s=t-1,d(e,A)?NA(c(o,s)):0}else if(E||A==null||A===35||A===47||A===63||A===92&&C(i.scheme)){if(m!==""){let t=parseInt(m,10);if(t>65535)return 1;if(i.port=t===se(i.scheme)?null:t,m="",E)return 0}return E?1:(s--,d(e,A)?K(c(o,s)):0)}else return 1};function ce(A,e){let t=A.length-e;if(t<2)return!1;if(ne(c(A,e),c(A,e+1))){if(t===2)return!0;{let n=c(A,e+2);return n===47||n===92||n===63||n===35}}else return!1}var kA=A=>{let e=s;return i.scheme="file",i.host="",A===47||A===92?d(e,A)?Je(c(o,s)):0:D?.scheme==="file"?(i.host=D.host,i.path=D.path.slice(),i.opaquePath=D.opaquePath,i.query=D.query,A===63?(i.query="",d(e,A)?Q(c(o,s)):0):A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):A!=null?(i.query=null,ce(o,s)?i.path=[]:oe(i),s--,d(e,A)?x(c(o,s)):0):d(e,A)?kA(c(o,s)):0):(s--,d(e,A)?x(c(o,s)):0)},Je=A=>{let e=s;return A===47||A===92?d(e,A)?LA(c(o,s)):0:(D!==null&&D.scheme==="file"&&(!ce(o,s)&&(function(n){if(n.length===2){let r=n.codePointAt(0),u=n.codePointAt(1);return(r>=65&&r<=90||r>=97&&r<=122)&&u===58}else return!1})(D.path[0])&&i.path.push(D.path[0]),i.host=D.host),s--,d(e,A)?x(c(o,s)):0)},LA=A=>{let e=s;if(A!=null&&A!==47&&A!==92&&A!==63&&A!==35){let t=s+j(A);for(;t<o.length;){let n=c(o,t);if(n==null||n===47||n===92||n===63||n===35)break;t+=j(n)}return m+=o.slice(s,t),s=t-1,d(e,A)?LA(c(o,s)):0}else if(A==null||A===47||A===92||A===63||A===35){if(s--,!E&&re(m))return d(e,A)?x(c(o,s)):0;if(m==="")return i.host="",E?0:d(e,A)?K(c(o,s)):0;{let t=EA(m,!C(i.scheme));return t===null?1:(t==="localhost"&&(t=""),i.host=TA(t),m="",E?0:d(e,A)?K(c(o,s)):0)}}return 1},K=A=>{let e=s;return C(i.scheme)?(A!==92&&A!==47&&s--,d(e,A)?x(c(o,s)):0):!E&&A===63?(i.query="",d(e,A)?Q(c(o,s)):0):!E&&A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):A!=null?(A!==47&&s--,d(e,A)?x(c(o,s)):0):(E&&i.host===null&&i.path.push(""),d(e,A)?K(c(o,s)):0)},x=A=>{let e=s;if(A!=null&&A!==47&&(!C(i.scheme)||A!==92)&&(E||A!==63&&A!==35)){let t=s+j(A);for(;t<o.length;){let n=c(o,t);if(n==null||n===47||C(i.scheme)&&n===92||!E&&(n===63||n===35))break;t+=j(n)}m+=U(o.slice(s,t),bA),s=t,A=c(o,t)}if(A==null||A===47||C(i.scheme)&&A===92||!E&&(A===63||A===35)){let t=C(i.scheme)&&A===92;return(function(r){switch(r){case"..":case"%2e.":case"%2E.":case".%2e":case".%2E":case"%2e%2e":case"%2E%2e":case"%2e%2E":case"%2E%2E":return!0;default:return!1}})(m)?(oe(i),A!==47&&!t&&i.path.push("")):XA(m)&&A!==47&&!t?i.path.push(""):XA(m)||(i.scheme==="file"&&i.path.length===0&&re(m)&&(m=`${m[0]}:`),i.path.push(m)),m="",A===63?(i.query="",d(e,A)?Q(c(o,s)):0):A===35?(i.fragment="",d(e,A)?$(c(o,s)):0):d(e,A)?x(c(o,s)):0}else return m+=ee(A,bA),d(e,A)?x(c(o,s)):0},ae=A=>{let e=s;if(A===63)return i.query="",d(e,A)?Q(c(o,s)):0;if(A===35)return i.fragment="",d(e,A)?$(c(o,s)):0;if(A!=null){let t=s+j(A);for(;t<o.length;){let r=c(o,t);if(r===63||r===35)break;t+=j(r)}let n=o.slice(s,t);if(t<o.length&&n.charCodeAt(n.length-1)===32?i.path[0]+=U(n.slice(0,-1),AA)+"%20":i.path[0]+=U(n,AA),s=t,(A=c(o,t))===63)return i.query="",d(e,A)?Q(c(o,s)):0;if(A===35)return i.fragment="",d(e,A)?$(c(o,s)):0}return d(e,A)?ae(c(o,s)):0},Q=A=>{let e=s,t=s;if(A!=null){if(E)t=o.length;else{let r=o.indexOf("#",s);t=r===-1?o.length:r}let n=C(i.scheme)?Ce:OA;i.query+=U(o.slice(s,t),n)}return s=t,c(o,t)===35&&!E?(i.fragment="",d(e,A)?$(c(o,s)):0):d(e,A)?Q(c(o,s)):0},$=A=>{let e=s;return A!=null&&(i.fragment+=U(o.slice(s),Ie),s=o.length),d(e,A)?$(c(o,s)):0};function vA(A){if(A.opaquePath)return A.path[0];{let e="";for(let t of A.path)e+=`/${t}`;return e}}function fe(A){switch(A.scheme){case"blob":{let e=H(vA(A),null,null,0);return e===null||e.scheme!=="http"&&e.scheme!=="https"?"null":fe(e)}case"ftp":case"http":case"https":case"ws":case"wss":return(function(t){let n=`${t.scheme}://`;return n+=t.host,t.port!==null&&(n+=`:${t.port}`),n})(A);default:return"null"}}var S=Symbol("URLImpl"),eA=class A{constructor(e,t){if(e===void 0&&t===void 0)throw new TypeError('The "url" argument must be specified.');e=b(e),t!=null&&(t=b(t));let n=null;if(t!=null&&(n=H(t,null,null,0),n==null))throw new TypeError(`Invalid base URL: ${t}`);let r=H(e,null,n,0);if(r==null)throw new TypeError(`Invalid URL: ${e}`);this[S]={url:r,query:null}}static createObjectURL(e){throw new TypeError("URL.createObjetURL is unsupported")}static revokeObjectURL(e){}static parse(e,t){e=b(e),t!==void 0&&(t=b(t));try{return new A(e,t)}catch{return null}}static canParse(e,t){e=b(e),t!==void 0&&(t=b(t));let n=null;return t!=null&&(n=H(t,null,null,0),n==null)?!1:H(e,null,n,0)!=null}get href(){return(function(t){let n=`${t.scheme}:`;return t.host!==null&&(n+="//",(t.username!==""||t.password!=="")&&(n+=t.username,t.password!==""&&(n+=`:${t.password}`),n+="@"),n+=t.host,t.port!==null&&(n+=`:${t.port}`)),t.host===null&&!t.opaquePath&&t.path.length>1&&t.path[0]===""&&(n+="/."),n+=vA(t),t.query!==null&&(n+=`?${t.query}`),t.fragment!==null&&(n+=`#${t.fragment}`),n})(this[S].url)}set href(e){let t=H(e=b(e),null,null,0);if(t==null)throw new TypeError(`Invalid URL: ${e}`);this[S].url=t,this[S].query&&yA(this[S].query,t.query)}get origin(){return fe(this[S].url)}get protocol(){return`${this[S].url.scheme}:`}set protocol(e){H(`${e=b(e)}:`,this[S].url,null,2)}get username(){return this[S].url.username}set username(e){e=b(e),wA(this[S].url)||(function(n,r){n.username=U(r,cA)})(this[S].url,e)}get password(){return this[S].url.password}set password(e){e=b(e),wA(this[S].url)||(function(n,r){n.password=U(r,cA)})(this[S].url,e)}get host(){let{url:e}=this[S];return e.host==null?"":e.port==null?e.host:`${e.host}:${e.port}`}set host(e){e=b(e),this[S].url.opaquePath||H(e,this[S].url,null,3)}get hostname(){let{url:e}=this[S];return e.host!=null?e.host:""}set hostname(e){e=b(e),this[S].url.opaquePath||H(e,this[S].url,null,4)}get port(){let{url:e}=this[S];return e.port!=null?`${e.port}`:""}set port(e){e=b(e);let{url:t}=this[S];wA(t)||(e?H(e,t,null,5):t.port=null)}get pathname(){return vA(this[S].url)}set pathname(e){e=b(e);let{url:t}=this[S];t.opaquePath||(t.path=[],H(e,t,null,6))}get search(){let{url:e}=this[S];return e.query?`?${e.query}`:""}set search(e){e=b(e);let{url:t,query:n}=this[S];if(!e)t.query=null,n&&yA(n,null);else{let r=e[0]==="?"?e.substring(1):e;t.query="",H(r,t,null,7),n&&yA(n,t.query)}}get searchParams(){let e=this[S],t=e.query;return t==null&&(t=e.query=(function(r,u){let l=new fA;return l[I].url=r,l[I].serialized=u==null,u&&(l[I].list=qA(u)),l})(this,e.url.query)),t}get hash(){let{url:e}=this[S];return e.fragment?`#${e.fragment}`:""}set hash(e){e=b(e);let{url:t}=this[S];if(!e)t.fragment=null;else{let n=e[0]==="#"?e.substring(1):e;t.fragment="",H(n,t,null,8)}}toJSON(){return this.href}toString(){return this.href}};Object.defineProperty(eA.prototype,Symbol.toStringTag,{value:"URL",configurable:!0});var I=Symbol("URLSearchParamsImpl"),We=Symbol.dispose||Symbol.for("dispose");function yA(A,e){e?A[I].list=qA(e):A[I].list.length=0,A[I].serialized=e==null}function oA(A){if(A.url){let e=IA(A.list);(function(n,r){n[S].url.query=r})(A.url,e||null),A.serialized=!0}}var Ze=typeof Iterator<"u"?Iterator:Object,Z=class extends Ze{constructor(e,t){super(),this[I]={ptr:e,map:t,index:0}}next(){let e=this[I];return e.index<e.ptr.list.length?{value:e.map(e.ptr.list[e.index++]),done:!1}:{value:void 0,done:!0}}[Symbol.iterator](){return this}[We](){}},fA=class{constructor(e){let t=this[I]={list:[],url:null,serialized:!0},n;if(Array.isArray(e))for(let r=0;r<e.length;r++)t.list.push(QA(e[r]));else if((n=ZA(e))!=null){let r;for(;!(r=PA(n.next())).done;)t.list.push(QA(r.value))}else if((typeof e=="object"||typeof e=="function")&&e!=null){let r=Object.keys(e);for(let u=0;u<r.length;u++){let l=r[u],a=Se(l),h=b(e[l]),f=t.list.find(g=>g[0]===a);f?f[1]=h:t.list.push([a,h])}}else if(e!==void 0){let r=b(e);r=r[0]==="?"?r.substring(1):r,t.list=qA(r)}}get size(){return this[I].list.length}append(e,t){e=b(e),t=b(t),this[I].list.push([e,t]);let n=this[I];n.url&&n.serialized?(function(u,l){let a=u[S].url;a.query=a.query?`${a.query}&${l}`:l})(n.url,IA([[e,t]])):oA(n)}delete(e,t){e=b(e),t=t!=null?b(t):void 0;let{list:n}=this[I],r=0;for(;r<n.length;)n[r][0]===e&&(t==null||n[r][1]===t)?n.splice(r,1):r++;oA(this[I])}get(e){e=b(e);let{list:t}=this[I];for(let n=0;n<t.length;n++)if(t[n][0]===e)return t[n][1];return null}getAll(e){e=b(e);let t=[],{list:n}=this[I];for(let r=0;r<n.length;r++)n[r][0]===e&&t.push(n[r][1]);return t}has(e,t){e=b(e),t=t!=null?b(t):void 0;let{list:n}=this[I];for(let r=0;r<n.length;r++)if(n[r][0]===e&&(t==null||n[r][1]===t))return!0;return!1}set(e,t){e=b(e),t=b(t);let{list:n}=this[I],r=!1,u=!1,l=0;for(;l<n.length;)n[l][0]===e?r?(n.splice(l,1),u=!0):(r=!0,n[l][1]!==t&&(n[l][1]=t,u=!0),l++):l++;r||(n.push([e,t]),u=!0),u&&oA(this[I])}sort(){this[I].list.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),oA(this[I])}forEach(e,t){if(typeof e!="function")throw new TypeError('The "callback" argument must be of type function');let{list:n}=this[I];for(let r=0;r<n.length;r++)e.call(t,n[r][1],n[r][0],this)}entries(){return new Z(this[I],e=>e)}keys(){return new Z(this[I],e=>e[0])}values(){return new Z(this[I],e=>e[1])}toString(){return IA(this[I].list)}[Symbol.iterator](){return this.entries()}};Object.defineProperty(fA.prototype,Symbol.toStringTag,{value:"URLSearchParams",configurable:!0});function he(A){let e,t=()=>typeof e=="string"?e:e?.accessToken,n=0,r,u=new Map,l=()=>{for(let p of[...u.keys()])try{p()}catch{}};function a(p){let w=++n;r=void 0,e=void 0;for(let y of[...u.values()])try{y?.()}catch{}w===n&&(e=p,l())}let h=()=>a();function f(p,w=!1){let y=UA.safeParse(p);if(!y.success||w&&Date.parse(y.data.expiresAt)<=Date.now()||Date.parse(y.data.refreshExpiresAt)<=Date.now()||Date.parse(y.data.refreshExpiresAt)<Date.parse(y.data.expiresAt))throw new P("INVALID_RESPONSE","Invalid customer session credentials");return y.data}async function g(){if(r)return r;let p=typeof e=="object"?e:void 0,w=n;if(!p||Date.parse(p.refreshExpiresAt)<=Date.now())throw p&&h(),new P("UNAUTHENTICATED","Customer authentication is required",401);let y=(async()=>{try{let R=await A(p.refreshToken);if(w!==n)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");let Y=f(R,!0);if(Y.customerId!==p.customerId||Y.sessionId!==p.sessionId)throw new P("SCOPE_MISMATCH","Refresh changed the customer session");return e=Y,{...Y}}catch(R){throw w!==n?new P("IDENTITY_CHANGED","Customer identity changed during refresh"):(R instanceof P&&R.status===401&&h(),R)}})();r=y;try{return await y}finally{r===y&&(r=void 0)}}return{identify(p){let w=typeof p=="string"?p:f(p),y=typeof w=="string"?w:w.accessToken;if(!y.trim()||/\s/.test(y)||y.length>4096)throw new P("INVALID_TOKEN","A server-issued token is required");a(w)},reset:h,subscribeIdentity(p,w){return u.set(p,w),()=>{u.delete(p)}},access(){let p=typeof e=="object"?e:void 0;if(p&&Date.parse(p.expiresAt)<=Date.now()+3e4){let y=n;return g().then(()=>{let R=t();if(y!==n||!R)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");return R})}let w=t();if(!w)throw new P("NOT_IDENTIFIED","Identify a customer session before making a request");return w},peek:t,snapshot:()=>typeof e=="object"?{...e}:void 0,refresh:g}}var de=Symbol("IndianaNoContent");function dt(A,e,t=eA){let n=A.configuration?.scope,r=A.scope??(n&&{projectId:n.projectId,environment:n.environment}),u=r?sA.parse(r):void 0;if(u&&n&&(u.projectId!==n.projectId||u.environment!==n.environment))throw new P("SCOPE_MISMATCH","Configuration belongs to another App/environment");let l=new t(A.baseUrl??zA);if(l.username||l.password||l.search||l.hash)throw new P("INVALID_URL","baseUrl must not contain credentials, query, or fragment");if(l.protocol!=="https:"&&!(l.protocol==="http:"&&["localhost","127.0.0.1","[::1]"].includes(l.hostname)))throw new P("INVALID_URL","Use HTTPS, or HTTP on localhost during development");let a=A.fetch??globalThis.fetch.bind(globalThis),h=A.timeoutMs??1e4;if(!Number.isFinite(h)||h<1||h>12e4)throw new P("INVALID_TIMEOUT","timeoutMs must be between 1 and 120000");let f=!1,g=0,p=null,w=new Set,y=A.session??he(async v=>{let T=await tA("customer-sessions/refresh",{},"POST",{},v);if(!T||typeof T!="object")throw new P("INVALID_RESPONSE","Invalid refresh response");let{requestId:B,scope:_,...V}=T;return V});function R(){g+=1,p=null;for(let v of w)v.abort();w.clear()}let Y=y.subscribeIdentity(R);function pe(){f||y.reset()}async function tA(v,T={},B="POST",_={},V){let k=_.installationDetach===!0;if(k&&(v!=="push/installations/detach"||B!=="POST"))throw new P("INVALID_REQUEST","Installation authority only detaches this installation");if(!V&&!k)throw new P("NOT_IDENTIFIED","Call identify with a server-issued customer token first");let X=g,L=new AbortController;k||w.add(L);let nA=()=>!k&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):new P("TIMEOUT","The request timed out"),dA,we=new Promise((q,N)=>{dA=()=>N(nA()),L.signal.addEventListener("abort",dA,{once:!0})}),ye=setTimeout(()=>L.abort(),_.timeoutMs??h),Pe=async()=>{let q=await a(`${l.href.replace(/\/$/,"")}/api/v1/${v}`,{method:B,headers:{..._.headers,"Content-Type":"application/json",...k?{}:{Authorization:`Bearer ${V}`},[pA]:gA.current,[FA]:$A.version,...u?{"X-Indiana-Project":u.projectId,"X-Indiana-Environment":u.environment}:{}},body:B==="POST"?JSON.stringify(T):void 0,signal:L.signal,credentials:"omit",cache:B==="POST"&&typeof document<"u"&&v==="funnels"&&T!==null&&typeof T=="object"&&"operation"in T&&(T.operation==="start"||T.operation==="shown")?"default":"no-store",redirect:"error",..._.keepalive?{keepalive:!0}:{}});if(L.signal.aborted)throw nA();let N;try{N=q.status===204?de:await q.json()}catch{throw L.signal.aborted?nA():new P(q.ok?"INVALID_RESPONSE":"HTTP_ERROR","The gateway returned an unreadable response",q.status,q.headers.get("X-Request-Id")??void 0)}if(L.signal.aborted)throw nA();if(!k&&X!==g)throw new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight");if(!q.ok){let O=xA.safeParse(N),z=O.success&&(!_A.safeParse(O.data.error.code).success||jA(O.data.error.code,q.status)),HA=z?O.data.error.code:"HTTP_ERROR",BA=MA(HA,q.status,{retryAfter:q.headers.get("Retry-After"),recovery:z?O.data.error.recovery:void 0,reason:z?O.data.error.reason:void 0});throw new P(HA,z?O.data.error.message:"The request failed",q.status,q.headers.get("X-Request-Id")??(O.success?O.data.requestId:void 0),{...BA,...O.success&&O.data.error.retryable===!1?{retryable:!1}:{},...BA.retryAfterSeconds===void 0&&O.success&&O.data.error.retryAfterSeconds!==void 0?{retryAfterSeconds:O.data.error.retryAfterSeconds}:{}})}if(q.headers.get(pA)!==gA.current)throw new P("PROTOCOL_MISMATCH","Response protocol does not match this SDK");if(u&&N!==de){let O=N&&typeof N=="object"&&"scope"in N?N:N&&typeof N=="object"&&"configuration"in N?N.configuration:null;if(!O||typeof O!="object"||!("scope"in O))throw new P("INVALID_RESPONSE","Response is missing its App/environment scope");let z=sA.safeParse(O.scope);if(!z.success||z.data.projectId!==u.projectId||z.data.environment!==u.environment)throw new P("SCOPE_MISMATCH","Response scope does not match this SDK instance")}let rA=q.headers.get("X-Indiana-Telemetry-Subject");if(rA){if(!/^[a-f0-9]{64}$/.test(rA))throw new P("INVALID_RESPONSE","Invalid telemetry identity");p!==rA&&(p=rA,e?.(p))}return N};try{return await Promise.race([Pe(),we])}catch(q){throw!k&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):q instanceof P?q:new P(L.signal.aborted?"TIMEOUT":"NETWORK_ERROR",L.signal.aborted?"The request timed out":"Unable to read the response")}finally{clearTimeout(ye),L.signal.removeEventListener("abort",dA),w.delete(L)}}function ge(v,T={},B="POST",_={}){if(f)return Promise.reject(new P("CLOSED","SDK client was destroyed"));if(_.installationDetach)return tA(v,T,B,_);let V=g;try{let k=y.access(),X=L=>{if(V!==g)throw new P("IDENTITY_CHANGED","Customer identity changed before dispatch");return tA(v,T,B,_,L)};return typeof k=="string"?X(k):k.then(X)}catch(k){return Promise.reject(k)}}let me=Object.assign(ge,{captureIdentity(){let v=g,T=f,B=!!y.peek();return()=>{if(T)throw new P("CLOSED","SDK client was destroyed");if(!B)throw new P("NOT_IDENTIFIED","Call identify with a server-issued customer token first");if(v!==g)throw new P("IDENTITY_CHANGED","Customer identity changed before dispatch")}}});return{session:y,requestWithCredential(v,T,B,_={}){return f?Promise.reject(new P("CLOSED","SDK client was destroyed")):tA(v,T,"POST",_,B)},subjectKey:()=>p,identify(v){if(f)throw new P("CLOSED","SDK client was destroyed");if(u&&typeof v=="object"&&"scope"in v){let T=sA.safeParse(v.scope);if(!T.success||T.data.projectId!==u.projectId||T.data.environment!==u.environment)throw new P("SCOPE_MISMATCH","Customer session belongs to another App/environment")}y.identify(v)},reset:pe,dispose(){f||(f=!0,Y(),R())},request:me}}export{eA as a,dt as b};
@@ -0,0 +1 @@
1
+ import{b as we}from"./chunk-2TPPGW7V.js";import{a as Q}from"./chunk-TMZGZAWM.js";import{A as Pe,E as B,G as Re,d as me,f as N,k as fe,v as ge,w as ye,y as Se}from"./chunk-7Z7JT4HE.js";import{$ as k}from"./chunk-ITVSLSRM.js";import{a as U,i as J}from"./chunk-B3KFE57L.js";import{b as Ie}from"./chunk-XZEGVBAI.js";import{a as l}from"./chunk-HJLGRW4A.js";import{h as z}from"./chunk-XIP32WI7.js";import{b as he}from"./chunk-FVGUBIVT.js";import{b as r}from"./chunk-ZY4XAKNQ.js";import{a as ae}from"./chunk-DSPLGTQI.js";var g=k.options,ke=r.discriminatedUnion("operation",[g[1].omit({customerToken:!0}),g[2].omit({customerToken:!0}),g[3].omit({customerToken:!0}),g[4].omit({customerToken:!0}),g[5].omit({customerToken:!0}),g[6].omit({customerToken:!0}),g[7].omit({customerToken:!0}),g[8].omit({customerToken:!0}),fe.omit({customerToken:!0})]),Ne=r.strictObject({receiptId:r.uuid(),operationId:r.uuid()}),Ge=r.discriminatedUnion("operation",[r.strictObject({operation:r.literal("recover_start"),intent:r.enum(["lookup","resume"]),start:r.strictObject({requestId:g[0].shape.requestId,funnelId:g[0].shape.funnelId,locale:g[0].shape.locale,parameters:g[0].shape.parameters})}),r.strictObject({operation:r.literal("recover_run"),runId:r.uuid(),funnelId:r.uuid()}),r.strictObject({operation:r.literal("recover_purchase"),runId:r.uuid(),funnelId:r.uuid(),purchase:Ne}),r.strictObject({operation:r.literal("settle_command"),runId:r.uuid(),funnelId:r.uuid(),requestId:r.uuid(),command:r.discriminatedUnion("operation",[g[3].omit({customerToken:!0}),g[4].omit({customerToken:!0}),g[5].omit({customerToken:!0}),g[6].omit({customerToken:!0}),g[7].omit({customerToken:!0})]).optional()}).refine(o=>!o.command||o.requestId===o.command.requestId),r.strictObject({operation:r.literal("run_command"),runId:r.uuid(),funnelId:r.uuid(),command:ke})]),ie=r.strictObject({runId:r.uuid(),funnelId:r.uuid(),versionId:r.uuid(),startRequestId:r.uuid(),runExpiresAt:r.iso.datetime({offset:!0}),status:N.shape.run.shape.status}),K={scope:z,customerId:r.uuid()},Ce=r.discriminatedUnion("outcome",[r.strictObject({...K,outcome:r.literal("unknown"),target:r.null(),view:r.null(),access:r.null()}),r.strictObject({...K,outcome:r.literal("resolved"),target:ie,view:N.shape.run.nullable(),access:r.discriminatedUnion("type",[r.strictObject({type:r.literal("customer")}),r.strictObject({type:r.literal("operation_only"),cause:r.enum(["run_terminal","run_expired","run_revoked","issuer_unavailable"])})])})]).superRefine((o,d)=>{o.outcome==="resolved"&&(o.access.type==="customer"!=(o.view!==null)||o.view&&(o.view.id!==o.target.runId||o.view.source.id!==o.target.funnelId||o.view.source.versionId!==o.target.versionId||o.view.status!==o.target.status||o.view.runExpiresAt!==o.target.runExpiresAt||o.view.credentialExpiresAt!==null))&&d.addIssue({code:"custom",message:"Recovery view and original Run binding differ"})}),ve=r.strictObject({...K,target:ie,view:N.shape.run.nullable(),settlement:r.strictObject({requestId:r.uuid(),state:r.enum(["pending","unknown","settled"]),acceptance:r.enum(["accepted","not_accepted","unknown"]),receiptPhase:r.enum(["accepted","processing","done"]).nullable(),basis:r.enum(["receipt","run_terminal","position_advanced","none"]),receiptId:r.uuid().nullable(),operationId:r.uuid().nullable()}),purchase:N.shape.purchase.unwrap().nullable()}).superRefine((o,d)=>{let p=o.settlement;(p.acceptance==="accepted"!=(p.receiptPhase!==null)||p.acceptance==="accepted"&&p.basis!=="receipt"||p.acceptance==="unknown"&&(p.state!=="unknown"||p.basis!=="none")||p.acceptance!=="accepted"&&(p.operationId!==null||p.receiptId!==null)||p.acceptance==="not_accepted"&&(p.state!=="settled"||!["run_terminal","position_advanced"].includes(p.basis))||o.purchase&&(o.purchase.receiptId!==p.receiptId||o.purchase.operation&&o.purchase.operation.operationId!==p.operationId||o.purchase.quote&&o.purchase.quote.operationId!==p.operationId)||o.view&&(o.view.id!==o.target.runId||o.view.source.id!==o.target.funnelId||o.view.source.versionId!==o.target.versionId||o.view.status!==o.target.status||o.view.runExpiresAt!==o.target.runExpiresAt||o.view.credentialExpiresAt!==null))&&d.addIssue({code:"custom",message:"Original command settlement binding differs"})}),Ee=r.strictObject({...K,target:ie,purchase:N.shape.purchase.unwrap()}).superRefine((o,d)=>{(!o.purchase.operation||typeof o.purchase.canReselect!="boolean"||o.purchase.quote&&o.purchase.quote.operationId!==o.purchase.operation.operationId)&&d.addIssue({code:"custom",message:"Original purchase proof is incomplete"})});var Te=k.options[0].refine(o=>!o.customer&&!o.customerData),xe=r.strictObject({receiptId:r.uuid(),operationId:r.uuid(),terminal:r.enum(["complete","native"]).nullable()}),be=r.strictObject({schemaVersion:r.literal(1),baseUrl:r.url(),scope:z,customerId:r.uuid(),sessionId:r.uuid(),start:Te,allowed:r.array(r.enum(["merchant","record_only","indiana","native"])),run:r.strictObject({id:r.uuid(),versionId:r.uuid(),status:me.shape.status,revision:r.number().int().nonnegative(),runExpiresAt:r.iso.datetime({offset:!0}).optional()}).optional(),purchases:r.array(xe).max(100),operationCommand:r.strictObject({operationId:r.uuid(),intent:r.literal("confirm")}).optional(),journal:r.strictObject({revision:r.number().int().nonnegative(),entry:ge.nullable()})});function Fe(o){return Se({...o,namespace:"purchases",identity:[o.scope.projectId,o.scope.environment,o.customerId]})}function Oe(o){let d=new URL(o.baseUrl??he).href,p=()=>new l("PURCHASE_STORAGE_INVALID","Purchase recovery storage is unavailable or invalid; native fallback is not authorized");async function v(){o.assertCurrent();try{let y=await o.storage.read();if(o.assertCurrent(),!Number.isSafeInteger(y.revision)||y.revision<0)throw p();let a=y.entry===null?null:be.parse(y.entry);if(a&&(a.baseUrl!==d||a.customerId!==o.customerId||a.scope.projectId!==o.scope.projectId||a.scope.environment!==o.scope.environment))throw new l("SCOPE_MISMATCH","Purchase recovery belongs to another Customer or environment");if(a?.journal.entry&&(a.journal.entry.scope.projectId!==a.scope.projectId||a.journal.entry.scope.environment!==a.scope.environment||a.journal.entry.funnelId!==a.start.funnelId||a.journal.entry.runId!==a.run?.id||a.journal.entry.versionId!==a.run?.versionId)||a?.operationCommand&&!a.purchases.some(P=>P.operationId===a.operationCommand?.operationId))throw p();return{revision:y.revision,entry:a}}catch(y){throw y instanceof l?y:p()}}async function Y(y){for(let a=0;a<8;a++){let P=await v(),b=y(structuredClone(P.entry));if(JSON.stringify(b)===JSON.stringify(P.entry))return b;b&&be.parse(b),o.assertCurrent();let E;try{E=await o.storage.write(P.revision,b)}catch{throw p()}if(o.assertCurrent(),E!==null){if(!Number.isSafeInteger(E)||E<=P.revision)throw p();return b}}throw new l("PURCHASE_STORAGE_CONFLICT","Another consumer changed this purchase; recover the original attempt")}return{read:v,update:Y,baseUrl:d}}function Ue(o){let d=o.purchases.find(p=>p.type==="checkout");if(!o.actions.includes("continue_checkout")||d?.type!=="checkout")throw new l("PURCHASE_PENDING","No single resumable Checkout is confirmed");return d.checkoutUrl}function fn(o){let d={...o,scope:{...o.scope},executionPolicy:structuredClone(o.executionPolicy)},p=d.session.snapshot();if(!p)throw new l("CUSTOMER_SESSION_REQUIRED","Purchase recovery requires a verified Customer session");let{customerId:v,sessionId:Y}=p,y=!1,a=null,P,b=null,E=!1,q,D,H,O={mode:"idle",status:"idle",actions:["start"],purchases:[]},I=new Map,j=new Map,se=new AbortController,L=new Set,W=Ie(d),ue=we(W.request);function M(e){return{code:e instanceof l?e.code:"PURCHASE_RECOVERY_BLOCKED",message:e instanceof Error?e.message:"The original purchase requires server confirmation",...e instanceof l&&e.status!==void 0?{status:e.status}:{}}}function R(){if(y||d.session.snapshot()?.customerId!==v)throw new l("IDENTITY_CHANGED","The original purchase Customer changed")}let w=Oe({...d,customerId:v,assertCurrent:R,storage:d.storage??Fe({baseUrl:d.baseUrl,scope:d.scope,customerId:v})}),qe=d.session.subscribeIdentity(ce);function ce(){y||(y=!0,clearTimeout(H),se.abort(new l("IDENTITY_CHANGED","Purchase consumer was destroyed")),qe(),a?.reset(),a=null,b=null,W.dispose(),L.clear(),I.clear(),j.clear())}function C(e){R();let n=JSON.stringify(e)!==JSON.stringify(O);O=e,clearTimeout(H),(e.mode==="operation"||e.mode==="run"&&!e.actions.includes("close"))&&["waiting_result","fulfillment","recording"].includes(e.status)&&(H=setTimeout(()=>{T().catch(()=>{})},5e3)),n&&ae(d.onRecovery,structuredClone(e));for(let t of n?L:[]){if(y)break;ae(t,structuredClone(e))}return structuredClone(e)}function h(e){if(R(),!e||e.start.requestId!==P)throw new l("PURCHASE_STORAGE_CONFLICT","This purchase was superseded; the old consumer cannot dispatch")}function F(e){let n=[...e.purchases],t=e.journal.entry?.purchase;return t&&!n.some(u=>u.operationId===t.operationId)&&n.push({receiptId:t.receiptId,operationId:t.operationId,terminal:null}),n}function V(e){return e.run&&!["running","waiting"].includes(e.run.status)&&!e.journal.entry?.command&&!e.journal.entry?.closeCommand&&!e.operationCommand&&F(e).every(n=>n.terminal!==null)}function $(e){if(e.journal.entry?.command||e.journal.entry?.closeCommand||e.operationCommand)return!1;let n=F(e).filter(t=>t.terminal===null);return n.length>0&&n.every(t=>{let u=I.get(t.operationId);return u?.executor==="merchant"&&U({quote:u.quote??null,operation:u,requestId:null,pending:!1,destroyed:!1,canReselect:!1}).type==="checkout"})}function _(e,n){let t=e.journal.entry?.command??e.journal.entry?.closeCommand,u=F(e).map(S=>{let oe=I.get(S.operationId);return S.terminal&&!oe?{type:S.terminal,operationId:S.operationId}:U({quote:oe?.quote??null,operation:oe??null,requestId:t?.requestId??null,pending:!1,destroyed:!1,canReselect:j.get(S.operationId)===!0})}),c=u.filter(S=>!["complete","native"].includes(S.type)),i=c[0],s=c.length===1&&i?.operationId?I.get(i.operationId):void 0;if(s&&(i?.type==="checkout"||i?.type==="cancel"))try{B({allowed:e.allowed.filter(S=>d.executionPolicy.allowed.includes(S))},s.quote)}catch(S){return{mode:n,status:"blocked",actions:["refresh",...n==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[]],purchases:u,error:M(S)}}let m;if(n==="operation"&&!t&&i?.type==="cancel"&&s?.quote&&!s.problem&&!s.confirmedAt)try{B({allowed:e.allowed.filter(S=>d.executionPolicy.allowed.includes(S))},s.quote),Date.parse(s.quote.expiresAt)>Date.now()&&(m={operationId:s.operationId,quote:s.quote})}catch{}let f=u.length>0&&c.length===0,x=V(e)||n==="operation"&&f&&!t&&!e.operationCommand?"complete":i?.type==="checkout"?"checkout":i?.type==="fulfillment"?"fulfillment":i?.type==="recording"?"recording":t||e.operationCommand||i&&i.type!=="cancel"||n==="operation"&&!m?"waiting_result":"ready";return{mode:n,status:x,purchases:u,...m?{confirmation:structuredClone(m)}:{},actions:["refresh",...V(e)||$(e)?["start"]:[],...n==="run"&&e.run&&["running","waiting"].includes(e.run.status)?["close"]:[],...e.operationCommand?["retry"]:m?["confirm"]:[],...c.length===1&&i?.type==="checkout"?["continue_checkout"]:[]]}}function X(e){let n=U({quote:e?.quote??null,operation:e??null,requestId:null,pending:!1,destroyed:!1,canReselect:e&&j.get(e.operationId)===!0});return n.type==="complete"||n.type==="native"?n.type:null}function Z(e){if(!e.operation)return;let n={...e.operation,...e.operation.quote?{}:e.quote?{quote:e.quote}:{}};if(n.merchantExecution&&n.merchantExecution.customerId!==v)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");let t=J(I.get(n.operationId)??null,n);I.set(n.operationId,t),t===n&&j.set(n.operationId,e.canReselect===!0)}async function _e(e){R();for(let t of[e.purchase,e.run.paywall])t&&Z(t);let n=await w.update(t=>{if(h(t),t.run&&(t.run.id!==e.run.id||t.run.versionId!==e.run.source.versionId))throw new l("SCOPE_MISMATCH","The original purchase Run changed");let u=F(t);for(let c of[e.purchase,e.run.paywall]){let i=c?.operation?.operationId??c?.quote?.operationId;if(!c||!i)continue;let s=u.find(f=>f.operationId===i);if(s&&s.receiptId!==c.receiptId)throw new l("INVALID_RESPONSE","The original purchase Receipt changed");let m=X(I.get(i));s?s.terminal??=m:u.push({receiptId:c.receiptId,operationId:i,terminal:m})}return{...t,purchases:u,run:t.run&&(t.run.revision>e.run.revision||!["running","waiting"].includes(t.run.status)&&["running","waiting"].includes(e.run.status))?t.run:{id:e.run.id,versionId:e.run.source.versionId,status:e.run.status,revision:e.run.revision,runExpiresAt:e.run.runExpiresAt}}});h(n),n.run&&!["running","waiting"].includes(n.run.status)&&F(n).some(t=>!t.terminal)&&(n=await ee(n,!n.journal.entry?.command&&!n.journal.entry?.closeCommand,new Set([e.purchase?.operation?.operationId,e.run.paywall?.operation?.operationId].filter(t=>!!t)))),h(n),C(_(n,"run"))}function Ae(){return{async read(){let{entry:e}=await w.read();return h(e),structuredClone(e.journal)},async write(e,n){let t=null;return await w.update(u=>{if(h(u),u.operationCommand&&n?.command&&n.command.operation!=="close")throw new l("PURCHASE_PENDING","Recover the original Operation command before dispatching a Run mutation");return t=null,u.journal.revision!==e?u:(t=e+1,{...u,journal:{revision:t,entry:n}})}),t}}}async function ee(e,n=!1,t=new Set){h(e);let u=F(e);for(let i of u){if(i.terminal)continue;let s=t.has(i.operationId)?I.get(i.operationId):void 0;if(s??=await le(e,i),R(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original Operation changed");if(s.merchantExecution&&s.merchantExecution.customerId!==v)throw new l("SCOPE_MISMATCH","Purchase execution belongs to another Customer");if(n&&!e.operationCommand&&U({quote:s.quote??null,operation:s,requestId:null,pending:!1,destroyed:!1}).type==="cancel"){if({operation:s}=await ue.attach({operationId:i.operationId,intent:"cancel"}),R(),s.operationId!==i.operationId)throw new l("INVALID_RESPONSE","Original cancellation Operation changed");s=await le(e,i)}I.set(i.operationId,J(I.get(i.operationId)??null,s))}let c=await w.update(i=>{h(i);let s=i.operationCommand&&I.get(i.operationCommand.operationId);return{...i,...s&&(s.confirmedAt||s.merchantExecution||s.status!=="pending")?{operationCommand:void 0}:{},purchases:F(i).map(m=>({...m,terminal:m.terminal??X(I.get(m.operationId))}))}});return h(c),c}async function ne(e){R();let n=await W.request("funnels",e);return R(),n}async function le(e,n){let t=Q(Ee,await ne({operation:"recover_purchase",runId:e.run.id,funnelId:e.start.funnelId,purchase:{receiptId:n.receiptId,operationId:n.operationId}}));if(te(e,t),t.purchase.receiptId!==n.receiptId||t.purchase.operation?.operationId!==n.operationId)throw new l("INVALID_RESPONSE","Original purchase reference changed");return Z(t.purchase),I.get(n.operationId)}async function de(e){for(let n of[e.journal.entry?.command,e.journal.entry?.closeCommand]){if(!n)continue;let t=Q(ve,await ne({operation:"settle_command",runId:e.run.id,funnelId:e.start.funnelId,requestId:n.requestId,...n.operation==="resume"?{}:{command:n}}));if(te(e,t),t.settlement.requestId!==n.requestId)throw new l("INVALID_RESPONSE","Original command settlement changed");t.purchase&&Z(t.purchase);let u=await w.update(c=>{h(c);let i=F(c),{receiptId:s,operationId:m}=t.settlement;if(s&&m){let x=i.find(S=>S.operationId===m);if(x&&x.receiptId!==s)throw new l("INVALID_RESPONSE","Original Receipt changed");x||i.push({receiptId:s,operationId:m,terminal:X(I.get(m))})}let f=t.settlement.state==="settled"?ye(c.journal.entry,n.requestId):c.journal.entry;return{...c,purchases:i,journal:f===c.journal.entry?c.journal:{revision:c.journal.revision+1,entry:f}}});h(u),e=u}return e}function te(e,n){if(n.customerId!==v||n.scope.projectId!==d.scope.projectId||n.scope.environment!==d.scope.environment||n.target.funnelId!==e.start.funnelId||n.target.startRequestId!==e.start.requestId||e.run&&(n.target.runId!==e.run.id||n.target.versionId!==e.run.versionId))throw new l("SCOPE_MISMATCH","The original recovery binding changed")}async function re(e,n){if(h(e),e.run&&(e=await de(e)),!F(e).length&&V(e))return C(_(e,"operation"));if(!F(e).length)return C({mode:"blocked",status:"blocked",actions:["refresh"],purchases:[],error:M(n)});E=!0;let t=await ee(e);return C(_(t,"operation"))}async function G(e,n=!1,t=!0){if(P=e.start.requestId,b=structuredClone({requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}),!a){let u=e.run?{operation:"recover_run",runId:e.run.id,funnelId:e.start.funnelId}:{operation:"recover_start",intent:n?"resume":"lookup",start:{requestId:e.start.requestId,funnelId:e.start.funnelId,locale:e.start.locale,parameters:e.start.parameters}},c;try{c=await ne(u)}catch(f){if(!e.run&&f instanceof l&&(f.status===void 0||f.status>=500))return C({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:O.purchases,error:M(f)});throw f}let i=Q(Ce,c);if(i.customerId!==v||i.scope.projectId!==d.scope.projectId||i.scope.environment!==d.scope.environment)throw new l("SCOPE_MISMATCH","Recovery Customer or environment changed");if(i.outcome==="unknown")return C({mode:"blocked",status:"blocked",actions:["refresh","retry"],purchases:O.purchases,error:{code:"RESULT_UNKNOWN",message:"The original Start outcome remains unknown; retry only its original input"}});te(e,i);let s=await w.update(f=>(h(f),{...f,run:{id:i.target.runId,versionId:i.target.versionId,status:i.target.status,revision:i.view?.revision??f.run?.revision??0,runExpiresAt:i.target.runExpiresAt}}));if(h(s),e=s,i.access.type==="operation_only")return re(e,new l("RUN_RECONCILIATION_REQUIRED","Only the original command and Operation can be recovered"));e=await de(e);let m=i.view;if(m.locale!==e.start.locale||!Pe(m.parameters,e.start.parameters))throw new l("INVALID_RESPONSE","The original Start input changed");a=Re({...d,customerRun:{runId:i.target.runId,customerId:v,startRequestId:e.start.requestId},funnelId:e.start.funnelId,funnelExecutionPolicy:{allowed:e.allowed.filter(f=>d.executionPolicy.allowed.includes(f))},funnelCommandStorage:Ae(),onAcceptedResponse:_e},{scope:i.scope,run:m})}try{await a.get(),a.view?.pendingRequest?.requestId===e.start.requestId&&!a.pendingCommands?.length&&await a.resume(a.view.pendingRequest.requestId);for(let c of a.pendingCommands??[])c.operation!=="close"&&await a.settle?.(c.requestId);a.pendingCommands?.length&&await a.retry(),R();let u=(await w.read()).entry;return h(u),C(_(u,"run"))}catch(u){if(R(),t&&u instanceof l&&(u.status===401||u.status===409&&u.reason==="STATE_CHANGED")){a.reset(),a=null;let c=(await w.read()).entry;return h(c),G(c,!1,!1)}throw u}}function A(e,n="read"){if(R(),q)return n==="read"||n===D?q:q.then(()=>A(e,n),()=>A(e,n));clearTimeout(H);let t=e().catch(u=>{throw y||C({mode:"blocked",status:"blocked",actions:["refresh"],purchases:O.purchases,error:M(u)}),u});return q=t,D=n,t.then(()=>{q===t&&(q=void 0,D=void 0)},()=>{q===t&&(q=void 0,D=void 0)}),t}function T(){return A(async()=>{let{entry:e}=await w.read();return e?(P&&e.start.requestId!==P&&(a?.reset(),a=null,I.clear(),j.clear()),E&&P===e.start.requestId?re(e,O.error):G(e)):C({mode:"idle",status:"idle",actions:["start"],purchases:[]})})}async function pe(){let e=await T();return e.mode==="operation"&&!e.actions.includes("confirm")&&!e.actions.includes("retry")?e:A(async()=>{let n=(await w.read()).entry;if(h(n),!E){if(!a?.view?.paywall?.quote)throw new l("PURCHASE_PENDING","Read the original quote before confirming");let s=a.view.paywall.operation;if(s?.confirmedAt||s?.merchantExecution||s&&s.status!=="pending")return C(_(n,"run"));if(a.pendingCommands?.length)await a.retry();else{let f=a.view;await a.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:f.nodeId,visit:f.visit,revision:f.revision,input:{type:"paywall_confirm",operationId:f.paywall.quote.operationId}})}let m=(await w.read()).entry;return h(m),C(_(m,"run"))}let t=n.operationCommand?.operationId??O.confirmation?.operationId,u=t&&I.get(t);if(!t||!u||n.journal.entry?.command||n.journal.entry?.closeCommand)throw new l("PURCHASE_PENDING","The original Run command must be settled before Operation confirmation");B({allowed:n.allowed.filter(s=>d.executionPolicy.allowed.includes(s))},u.quote),await w.update(s=>{if(h(s),s.journal.entry?.command||s.journal.entry?.closeCommand||s.operationCommand&&s.operationCommand.operationId!==t)throw new l("PURCHASE_PENDING","Another original command is pending");return{...s,operationCommand:{operationId:t,intent:"confirm"}}});let c=await ue.attach({operationId:t,intent:"confirm"});if(R(),c.operation.operationId!==t)throw new l("INVALID_RESPONSE","Original confirmation Operation changed");I.set(t,J(u,c.operation));let i=(await w.read()).entry;return h(i),C(_(await ee(i,!1,new Set([t])),"operation"))},"confirm")}async function je(){let e=a?.view;if(!(!a||!e||!["running","waiting"].includes(e.status)))try{await a.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision})}catch{}}return{get controller(){return a},get recovery(){return structuredClone(O)},get attempt(){return R(),structuredClone(b)},get identitySignal(){return se.signal},start(e){let n=k.parse({...structuredClone(e),operation:"start",requestId:e.requestId??crypto.randomUUID()});if(n.operation!=="start"||n.customer||n.customerData)throw new l("INVALID_REQUEST","A Customer-owned Funnel start is required");return A(async()=>{let t=(await w.read()).entry;t&&t.start.requestId===P&&$(t)&&await je();let u=await w.update(c=>{if(c&&!V(c)&&!$(c)){if(c.start.funnelId!==n.funnelId)throw new l("PURCHASE_PENDING","Recover the original Funnel before starting another purchase");return c}return{schemaVersion:1,baseUrl:w.baseUrl,scope:d.scope,customerId:v,sessionId:Y,start:n,allowed:[...d.executionPolicy.allowed],purchases:[],journal:{revision:0,entry:null}}});if(!u)throw new l("PURCHASE_STORAGE_INVALID","Original start was not retained");return P!==u.start.requestId&&(a?.reset(),a=null,I.clear(),j.clear(),E=!1),E?re(u,O.error):G(u,!0)},`start:${n.funnelId}`)},refresh:T,confirm:pe,retry:()=>E?pe():A(async()=>{let{entry:e}=await w.read();return e?G(e,!0):C({mode:"idle",status:"idle",actions:["start"],purchases:[]})},"retry"),async close(){return a?.view?A(async()=>{if(!a?.view)throw new l("PURCHASE_PENDING","Recover the original Run before closing");if(a.pendingCommands?.find(t=>t.operation==="close"))await a.retry();else if(["running","waiting"].includes(a.view.status)){let t=a.view;await a.submit({operation:"close",requestId:crypto.randomUUID(),nodeId:t.nodeId,visit:t.visit,revision:t.revision})}let n=(await w.read()).entry;return h(n),C(_(n,"run"))},"close"):T()},async continueCheckout(e){let n=await T();R(),await e(Ue(n))},subscribe(e){return L.add(e),()=>{L.delete(e)}},destroy:ce}}export{Fe as a,Ue as b,fn as c};