@tinkerlandai/longplay-sdk 0.10.80 → 0.10.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/{chunk-HMOKLBID.js → chunk-3P7M3WT7.js} +1 -1
  3. package/dist/{chunk-FV7BUKOJ.js → chunk-3ZOUIESZ.js} +1 -1
  4. package/dist/{chunk-4UD5K5UD.js → chunk-A6GBOXP2.js} +2 -2
  5. package/dist/{chunk-Z4OHCMV7.js → chunk-BSC3VAYP.js} +1 -1
  6. package/dist/chunk-HHBDNW52.js +1 -0
  7. package/dist/{chunk-MXI4ANML.js → chunk-OJZWFIG3.js} +1 -1
  8. package/dist/{chunk-PPG76HUS.js → chunk-PP3FCEXY.js} +1 -1
  9. package/dist/{chunk-EMOKR3UA.js → chunk-TGCVYHPW.js} +1 -1
  10. package/dist/chunk-TYDSAHJO.js +1 -0
  11. package/dist/{chunk-E5B2TEKP.js → chunk-UBRDRCJZ.js} +1 -1
  12. package/dist/{chunk-J6ATQION.js → chunk-V7QPMA2C.js} +1 -1
  13. package/dist/{chunk-523S4AFJ.js → chunk-ZTKPJTE4.js} +1 -1
  14. package/dist/{content-MWQH43G6.js → content-VD374F7V.js} +1 -1
  15. package/dist/{funnel-host-purchase-CZHW32EF.js → funnel-host-purchase-KVU6FBVO.js} +1 -1
  16. package/dist/{funnel-host-recovery-paywall-SWOGVUIF.js → funnel-host-recovery-paywall-X7HESLZM.js} +1 -1
  17. package/dist/{funnel-paywall-prerender-7VOZ3RG3.js → funnel-paywall-prerender-22AH6WEM.js} +1 -1
  18. package/dist/{funnel-runtime-host-SYN546TS.js → funnel-runtime-host-RHIDG6EF.js} +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/openrouter.js +1 -1
  21. package/dist/page.js +1 -1
  22. package/dist/{paywall-TID3CHRR.js → paywall-CMDMDGJ4.js} +1 -1
  23. package/dist/{paywall-content-OIQDGYFI.js → paywall-content-Z4LKDIO2.js} +1 -1
  24. package/dist/{paywall-session-CIJK4MRJ.js → paywall-session-JDJ4E4BO.js} +1 -1
  25. package/dist/react-native.js +1 -1
  26. package/dist/server.js +1 -1
  27. package/dist/visual.js +1 -1
  28. package/package.json +1 -1
  29. package/dist/chunk-5VWKCHAB.js +0 -1
  30. package/dist/chunk-AXFFDCHY.js +0 -1
  31. /package/dist/{chunk-4UD5K5UD.js.LEGAL.txt → chunk-A6GBOXP2.js.LEGAL.txt} +0 -0
@@ -1 +1 @@
1
- import{b as $A}from"./chunk-KCUE2VFJ.js";import{a as P}from"./chunk-UGATOG2T.js";import{a as BA,c as jA,d as xA,e as MA,f as UA,h as sA}from"./chunk-LFR2LWYC.js";import{a as zA}from"./chunk-HMOKLBID.js";import{a as FA}from"./chunk-5MRSFLQA.js";function I(A){return typeof A=="string"?A:String(A)}var Se=/[\ud800-\udbff](?![\udc00-\udfff])|(^|[^\ud800-\udbff])[\udc00-\udfff]/g;function Ie(A){return A.replace(Se,"$1�")}function mA(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(I);if(t.length===2)return t}else if((e=ZA(A))!=null){let t=mA(e.next()),n=mA(e.next());if(!t.done&&!n.done)return[I(t.value),I(n.value)]}throw new TypeError("Each query pair must be an iterable [name, value] tuple")}var GA="0123456789ABCDEF",Ce=/(?:%[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 yA(A){return A>=48&&A<=57?A-48:A>=65&&A<=70?A-65+10:A>=97&&A<=102?A-97+10:-1}function PA(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(Ce,n=>{try{return decodeURIComponent(n)}catch{return"�".repeat(n.length/3)}})}function AA(A){return A<=31||A>126}function be(A){switch(A){case 32:case 34:case 60:case 62:case 96:return!0;default:return AA(A)}}function TA(A){switch(A){case 32:case 34:case 35:case 60:case 62:return!0;default:return AA(A)}}function Ee(A){return TA(A)||A===39}function DA(A){switch(A){case 63:case 94:case 96:case 123:case 125:return!0;default:return TA(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 DA(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 vA(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([PA(r.slice(0,u),!0),PA(r.slice(u+1),!0)])}if(t=n+1,n===A.length)break}return e}function SA(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 Te=[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],ve=[7296,7297,7298,7299,7300,7301,7302,7303,7304,42958,42962,42964,42993],Oe=["в","д","о","с","т","т","ъ","ѣ","ꙋ","꟏","ꟓ","ꟕ","s"],Re=[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 ke(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[qe,Ne,Le,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 He(A,e){return e===931||e===1010||e===120531||e===120589||e===120647||e===120705||e===120763?"σ":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,"ι").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 _e(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(Re,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(Le,e[u])))return!1}return!0}var Be=/(?![\p{Mark}\p{Decimal_Number}])[\p{Script=Arabic}\p{Script=Hebrew}]/u,je=/\p{Script=Latin}/u;function xe(A){return!Be.test(A)||!je.test(A)}var F=36,iA=1,IA=26,Me=38,Ue=700,$e=72,ze=128,Fe=2147483647;function VA(A){return String.fromCharCode(A+22+75*+(A<26))}function Qe(A,e,t){let n=0;for(A=t?Math.floor(A/Ue):A>>1,A+=Math.floor(A/e);A>(F-iA)*IA>>1;n+=F)A=Math.floor(A/(F-iA));return Math.floor(n+(F-iA+1)*A/(A+Me))}function Ge(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=ze,l=0,a=$e;for(;n<e.length;){let h=Fe;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 m=F;;m+=F){let y=m<=a?iA:m>=a+IA?IA:m-a;if(p<y)break;t+=VA(y+(p-y)%(F-y)),p=Math.floor((p-y)/(F-y))}t+=VA(p),a=Qe(l,n+1,n===r),l=0,n++}}l++,u++}return t}function pA(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=yA(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 b(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 CA(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=yA(h[a]))>=0;)g=(g<<4)+f,a++,p++;if(h[a]===46){if(p===0||l>6)return null;a-=p;let m=0;for(;h[a]!==void 0;){let y=0;if(m>0)if(h[a]===46&&m<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+yA(h[a]),y>255)return null;a++}r[l]=256*r[l]+y,m++,m%2==0&&l++}if(m!==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(Te,p)||W(qe,p))return!0}return!1})(r))return null;let a=(r=(function(f){let g="";for(let p of f){let m=p.codePointAt(0);if(m!==8204&&m!==8205&&/\p{Default_Ignorable_Code_Point}/u.test(p))continue;let y=He(p,m);if(y){g+=y;continue}let k=ve.indexOf(m);g+=k<0?p:Oe[k]}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(ke(f)||g&&(/^\p{Mark}/u.test(f)||!_e(f)||!xe(f)||f.startsWith("xn--")))return null;g&&(a[h]=`xn--${Ge(f)}`)}return(r=a.join("."))!==""?r:null})(A.indexOf("%")===-1?A:PA(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(pA(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=pA(u[f]);if(g<0||g>255)return null;a+=g*(1<<8*(3-f))}let h=pA(u[l-1]);return h<0||h>=256**(5-l)?null:(a+=h,a)})(t):t}}function bA(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 m=0;m<a.length;++m)a[m]!==0?(p>g&&(h=f,g=p),f=-1,p=0):(f===-1&&(f=m),++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 gA(A){return A.host===null||A.host===""||A.scheme==="file"}var s=0,o="",w="",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,w="",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=Ke;switch(n){case 3:case 4:r=aA;break;case 5:r=RA;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 Ke=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 w=o.slice(s,t).toLowerCase(),s=t,Ye(t<o.length?A:void 0)}else return E?1:(--s,d(e,A)?ue(c(o,s)):0)},Ye=A=>{let e=s;if(A===58){if(E){if(b(i.scheme)!==b(w))return 0;if((ie(i)||i.port!==null)&&w==="file")return 0;if(i.scheme==="file"&&i.host==="")return 0}return i.scheme=w,E?(i.port===se(i.scheme)&&(i.port=null),0):(w="",i.scheme==="file"?d(e,A)?kA(c(o,s)):0:b(i.scheme)&&D!==null&&D.scheme===i.scheme?d(e,A)?Ve(c(o,s)):0:b(i.scheme)?d(e,A)?Je(c(o,s)):0:c(o,s+1)===47?(s++,d(e,A)?Xe(c(o,s)):0):(i.path=[""],i.opaquePath=!0,d(e,A)?ae(c(o,s)):0))}else return E?1:(w="",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)?OA(c(o,s)):0)},Ve=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)?OA(c(o,s)):0)},Xe=A=>{let e=s;return A===47?d(e,A)?J(c(o,s)):0:(s--,d(e,A)?x(c(o,s)):0)},OA=A=>{let e=s;return i.scheme=D.scheme,A===47||b(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)?OA(c(o,s)):0)},WA=A=>{let e=s;return b(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)},Je=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||!b(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&&b(i.scheme))break;t+=j(n)}return w+=o.slice(s,t),s=t-1,d(e,A)?J(c(o,s)):0}if(A===64){lA&&(w=`%40${w}`),lA=!0;for(let t=0;t<w.length;t++){let n=w.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 w="",d(e,A)?J(c(o,s)):0}else return A==null||A===35||A===47||A===63||A===92&&b(i.scheme)?lA&&w===""?1:(s-=w.length+1,w="",d(e,A)?aA(c(o,s)):0):(w+=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)?qA(c(o,s)):0;if(A!=null&&A!==58&&A!==35&&A!==47&&A!==63&&(A!==92||!b(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&&b(i.scheme))break;n===91?G=!0:n===93&&(G=!1),t+=j(n)}return w+=o.slice(s,t),s=t-1,d(e,A)?aA(c(o,s)):0}else if(A===58&&!G){if(w===""||E===4)return 1;let t=CA(w,!b(i.scheme));return t===null?1:(i.host=bA(t),w="",d(e,A)?RA(c(o,s)):0)}else if(A==null||A===35||A===47||A===63||A===92&&b(i.scheme)){if(s--,b(i.scheme)&&w==="")return 1;if(E&&w===""&&(ie(i)||i.port!==null))return 1;let t=CA(w,!b(i.scheme));return t===null?1:(i.host=bA(t),w="",E?0:d(e,A)?K(c(o,s)):0)}else return w+=le(A),d(e,A)?aA(c(o,s)):0},RA=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 w+=o.slice(s,t),s=t-1,d(e,A)?RA(c(o,s)):0}else if(E||A==null||A===35||A===47||A===63||A===92&&b(i.scheme)){if(w!==""){let t=parseInt(w,10);if(t>65535)return 1;if(i.port=t===se(i.scheme)?null:t,w="",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)?We(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)},We=A=>{let e=s;return A===47||A===92?d(e,A)?qA(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)},qA=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 w+=o.slice(s,t),s=t-1,d(e,A)?qA(c(o,s)):0}else if(A==null||A===47||A===92||A===63||A===35){if(s--,!E&&re(w))return d(e,A)?x(c(o,s)):0;if(w==="")return i.host="",E?0:d(e,A)?K(c(o,s)):0;{let t=CA(w,!b(i.scheme));return t===null?1:(t==="localhost"&&(t=""),i.host=bA(t),w="",E?0:d(e,A)?K(c(o,s)):0)}}return 1},K=A=>{let e=s;return b(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&&(!b(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||b(i.scheme)&&n===92||!E&&(n===63||n===35))break;t+=j(n)}w+=U(o.slice(s,t),DA),s=t,A=c(o,t)}if(A==null||A===47||b(i.scheme)&&A===92||!E&&(A===63||A===35)){let t=b(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}})(w)?(oe(i),A!==47&&!t&&i.path.push("")):XA(w)&&A!==47&&!t?i.path.push(""):XA(w)||(i.scheme==="file"&&i.path.length===0&&re(w)&&(w=`${w[0]}:`),i.path.push(w)),w="",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 w+=ee(A,DA),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=b(i.scheme)?Ee:TA;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),be),s=o.length),d(e,A)?$(c(o,s)):0};function EA(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(EA(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=I(e),t!=null&&(t=I(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=I(e),t!==void 0&&(t=I(t));try{return new A(e,t)}catch{return null}}static canParse(e,t){e=I(e),t!==void 0&&(t=I(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+=EA(t),t.query!==null&&(n+=`?${t.query}`),t.fragment!==null&&(n+=`#${t.fragment}`),n})(this[S].url)}set href(e){let t=H(e=I(e),null,null,0);if(t==null)throw new TypeError(`Invalid URL: ${e}`);this[S].url=t,this[S].query&&wA(this[S].query,t.query)}get origin(){return fe(this[S].url)}get protocol(){return`${this[S].url.scheme}:`}set protocol(e){H(`${e=I(e)}:`,this[S].url,null,2)}get username(){return this[S].url.username}set username(e){e=I(e),gA(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=I(e),gA(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=I(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=I(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=I(e);let{url:t}=this[S];gA(t)||(e?H(e,t,null,5):t.port=null)}get pathname(){return EA(this[S].url)}set pathname(e){e=I(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=I(e);let{url:t,query:n}=this[S];if(!e)t.query=null,n&&wA(n,null);else{let r=e[0]==="?"?e.substring(1):e;t.query="",H(r,t,null,7),n&&wA(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[C].url=r,l[C].serialized=u==null,u&&(l[C].list=vA(u)),l})(this,e.url.query)),t}get hash(){let{url:e}=this[S];return e.fragment?`#${e.fragment}`:""}set hash(e){e=I(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 C=Symbol("URLSearchParamsImpl"),Ze=Symbol.dispose||Symbol.for("dispose");function wA(A,e){e?A[C].list=vA(e):A[C].list.length=0,A[C].serialized=e==null}function oA(A){if(A.url){let e=SA(A.list);(function(n,r){n[S].url.query=r})(A.url,e||null),A.serialized=!0}}var At=typeof Iterator<"u"?Iterator:Object,Z=class extends At{constructor(e,t){super(),this[C]={ptr:e,map:t,index:0}}next(){let e=this[C];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}[Ze](){}},fA=class{constructor(e){let t=this[C]={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=mA(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=Ie(l),h=I(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=I(e);r=r[0]==="?"?r.substring(1):r,t.list=vA(r)}}get size(){return this[C].list.length}append(e,t){e=I(e),t=I(t),this[C].list.push([e,t]);let n=this[C];n.url&&n.serialized?(function(u,l){let a=u[S].url;a.query=a.query?`${a.query}&${l}`:l})(n.url,SA([[e,t]])):oA(n)}delete(e,t){e=I(e),t=t!=null?I(t):void 0;let{list:n}=this[C],r=0;for(;r<n.length;)n[r][0]===e&&(t==null||n[r][1]===t)?n.splice(r,1):r++;oA(this[C])}get(e){e=I(e);let{list:t}=this[C];for(let n=0;n<t.length;n++)if(t[n][0]===e)return t[n][1];return null}getAll(e){e=I(e);let t=[],{list:n}=this[C];for(let r=0;r<n.length;r++)n[r][0]===e&&t.push(n[r][1]);return t}has(e,t){e=I(e),t=t!=null?I(t):void 0;let{list:n}=this[C];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=I(e),t=I(t);let{list:n}=this[C],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[C])}sort(){this[C].list.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),oA(this[C])}forEach(e,t){if(typeof e!="function")throw new TypeError('The "callback" argument must be of type function');let{list:n}=this[C];for(let r=0;r<n.length;r++)e.call(t,n[r][1],n[r][0],this)}entries(){return new Z(this[C],e=>e)}keys(){return new Z(this[C],e=>e[0])}values(){return new Z(this[C],e=>e[1])}toString(){return SA(this[C].list)}[Symbol.iterator](){return this.entries()}};Object.defineProperty(fA.prototype,Symbol.toStringTag,{value:"URLSearchParams",configurable:!0});var NA="X-Indiana-Protocol",he="X-Indiana-SDK-Version";var LA={current:"0.10"};function de(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 m=++n;r=void 0,e=void 0;for(let y of[...u.values()])try{y?.()}catch{}m===n&&(e=p,l())}let h=()=>a();function f(p,m=!1){let y=$A.safeParse(p);if(!y.success||m&&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,m=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 k=await A(p.refreshToken);if(m!==n)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");let Y=f(k,!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(k){throw m!==n?new P("IDENTITY_CHANGED","Customer identity changed during refresh"):(k instanceof P&&k.status===401&&h(),k)}})();r=y;try{return await y}finally{r===y&&(r=void 0)}}return{identify(p){let m=typeof p=="string"?p:f(p),y=typeof m=="string"?m:m.accessToken;if(!y.trim()||/\s/.test(y)||y.length>4096)throw new P("INVALID_TOKEN","A server-issued token is required");a(m)},reset:h,subscribeIdentity(p,m){return u.set(p,m),()=>{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 k=t();if(y!==n||!k)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");return k})}let m=t();if(!m)throw new P("NOT_IDENTIFIED","Identify a customer session before making a request");return m},peek:t,snapshot:()=>typeof e=="object"?{...e}:void 0,refresh:g}}var pe=Symbol("IndianaNoContent");function gt(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??FA);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,m=new Set,y=A.session??de(async v=>{let R=await tA("customer-sessions/refresh",{},"POST",{},v);if(!R||typeof R!="object")throw new P("INVALID_RESPONSE","Invalid refresh response");let{requestId:_,scope:B,...V}=R;return V});function k(){g+=1,p=null;for(let v of m)v.abort();m.clear()}let Y=y.subscribeIdentity(k);function ge(){f||y.reset()}async function tA(v,R={},_="POST",B={},V){let N=B.installationDetach===!0;if(N&&(v!=="push/installations/detach"||_!=="POST"))throw new P("INVALID_REQUEST","Installation authority only detaches this installation");if(!V&&!N)throw new P("NOT_IDENTIFIED","Call identify with a server-issued customer token first");let X=g,L=new AbortController;N||m.add(L);let nA=()=>!N&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):new P("TIMEOUT","The request timed out"),dA,ye=new Promise((O,q)=>{dA=()=>q(nA()),L.signal.addEventListener("abort",dA,{once:!0})}),Pe=setTimeout(()=>L.abort(),B.timeoutMs??h),De=async()=>{let O=await a(`${l.href.replace(/\/$/,"")}/api/v1/${v}`,{method:_,headers:{...B.headers,"Content-Type":"application/json",...N?{}:{Authorization:`Bearer ${V}`},[NA]:LA.current,[he]:zA.version,...u?{"X-Indiana-Project":u.projectId,"X-Indiana-Environment":u.environment}:{}},body:_==="POST"?JSON.stringify(R):void 0,signal:L.signal,credentials:"omit",cache:_==="POST"&&typeof document<"u"?"default":"no-store",redirect:"error",...B.keepalive?{keepalive:!0}:{}});if(L.signal.aborted)throw nA();let q;try{q=O.status===204?pe:await O.json()}catch{throw L.signal.aborted?nA():new P(O.ok?"INVALID_RESPONSE":"HTTP_ERROR","The gateway returned an unreadable response",O.status,O.headers.get("X-Request-Id")??void 0)}if(L.signal.aborted)throw nA();if(!N&&X!==g)throw new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight");if(!O.ok){let T=MA.safeParse(et(q)),z=T.success&&(!BA.safeParse(T.data.error.code).success||xA(T.data.error.code,O.status)),HA=z?T.data.error.code:"HTTP_ERROR",_A=UA(HA,O.status,{retryAfter:O.headers.get("Retry-After"),recovery:z?T.data.error.recovery:void 0,reason:z?T.data.error.reason:void 0});throw new P(HA,z?T.data.error.message:"The request failed",O.status,O.headers.get("X-Request-Id")??(T.success?T.data.requestId:void 0),{..._A,...T.success&&T.data.error.retryable===!1?{retryable:!1}:{},..._A.retryAfterSeconds===void 0&&T.success&&T.data.error.retryAfterSeconds!==void 0?{retryAfterSeconds:T.data.error.retryAfterSeconds}:{}})}if(O.headers.get(NA)!==LA.current)throw new P("PROTOCOL_MISMATCH","Response protocol does not match this SDK");if(u&&q!==pe){let T=q&&typeof q=="object"&&"scope"in q?q:q&&typeof q=="object"&&"configuration"in q?q.configuration:null;if(!T||typeof T!="object"||!("scope"in T))throw new P("INVALID_RESPONSE","Response is missing its App/environment scope");let z=sA.safeParse(T.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=O.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 q};try{return await Promise.race([De(),ye])}catch(O){throw!N&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):O instanceof P?O:new P(L.signal.aborted?"TIMEOUT":"NETWORK_ERROR",L.signal.aborted?"The request timed out":"Unable to read the response")}finally{clearTimeout(Pe),L.signal.removeEventListener("abort",dA),m.delete(L)}}function we(v,R={},_="POST",B={}){if(f)return Promise.reject(new P("CLOSED","SDK client was destroyed"));if(B.installationDetach)return tA(v,R,_,B);let V=g;try{let N=y.access(),X=L=>{if(V!==g)throw new P("IDENTITY_CHANGED","Customer identity changed before dispatch");return tA(v,R,_,B,L)};return typeof N=="string"?X(N):N.then(X)}catch(N){return Promise.reject(N)}}let me=Object.assign(we,{captureIdentity(){let v=g,R=f,_=!!y.peek();return()=>{if(R)throw new P("CLOSED","SDK client was destroyed");if(!_)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,R,_,B={}){return f?Promise.reject(new P("CLOSED","SDK client was destroyed")):tA(v,R,"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 R=sA.safeParse(v.scope);if(!R.success||R.data.projectId!==u.projectId||R.data.environment!==u.environment)throw new P("SCOPE_MISMATCH","Customer session belongs to another App/environment")}y.identify(v)},reset:ge,dispose(){f||(f=!0,Y(),k())},request:me}}function et(A){if(!A||typeof A!="object"||!("error"in A))return A;let e=A.error;if(!e||typeof e!="object"||!("reason"in e)||jA.safeParse(e.reason).success)return A;let{reason:t,...n}=e;return{...A,error:n}}export{eA as a,gt as b};
1
+ import{b as $A}from"./chunk-KCUE2VFJ.js";import{a as P}from"./chunk-UGATOG2T.js";import{a as BA,c as jA,d as xA,e as MA,f as UA,h as sA}from"./chunk-LFR2LWYC.js";import{a as zA}from"./chunk-3P7M3WT7.js";import{a as FA}from"./chunk-5MRSFLQA.js";function I(A){return typeof A=="string"?A:String(A)}var Se=/[\ud800-\udbff](?![\udc00-\udfff])|(^|[^\ud800-\udbff])[\udc00-\udfff]/g;function Ie(A){return A.replace(Se,"$1�")}function mA(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(I);if(t.length===2)return t}else if((e=ZA(A))!=null){let t=mA(e.next()),n=mA(e.next());if(!t.done&&!n.done)return[I(t.value),I(n.value)]}throw new TypeError("Each query pair must be an iterable [name, value] tuple")}var GA="0123456789ABCDEF",Ce=/(?:%[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 yA(A){return A>=48&&A<=57?A-48:A>=65&&A<=70?A-65+10:A>=97&&A<=102?A-97+10:-1}function PA(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(Ce,n=>{try{return decodeURIComponent(n)}catch{return"�".repeat(n.length/3)}})}function AA(A){return A<=31||A>126}function be(A){switch(A){case 32:case 34:case 60:case 62:case 96:return!0;default:return AA(A)}}function TA(A){switch(A){case 32:case 34:case 35:case 60:case 62:return!0;default:return AA(A)}}function Ee(A){return TA(A)||A===39}function DA(A){switch(A){case 63:case 94:case 96:case 123:case 125:return!0;default:return TA(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 DA(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 vA(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([PA(r.slice(0,u),!0),PA(r.slice(u+1),!0)])}if(t=n+1,n===A.length)break}return e}function SA(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 Te=[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],ve=[7296,7297,7298,7299,7300,7301,7302,7303,7304,42958,42962,42964,42993],Oe=["в","д","о","с","т","т","ъ","ѣ","ꙋ","꟏","ꟓ","ꟕ","s"],Re=[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 ke(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[qe,Ne,Le,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 He(A,e){return e===931||e===1010||e===120531||e===120589||e===120647||e===120705||e===120763?"σ":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,"ι").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 _e(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(Re,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(Le,e[u])))return!1}return!0}var Be=/(?![\p{Mark}\p{Decimal_Number}])[\p{Script=Arabic}\p{Script=Hebrew}]/u,je=/\p{Script=Latin}/u;function xe(A){return!Be.test(A)||!je.test(A)}var F=36,iA=1,IA=26,Me=38,Ue=700,$e=72,ze=128,Fe=2147483647;function VA(A){return String.fromCharCode(A+22+75*+(A<26))}function Qe(A,e,t){let n=0;for(A=t?Math.floor(A/Ue):A>>1,A+=Math.floor(A/e);A>(F-iA)*IA>>1;n+=F)A=Math.floor(A/(F-iA));return Math.floor(n+(F-iA+1)*A/(A+Me))}function Ge(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=ze,l=0,a=$e;for(;n<e.length;){let h=Fe;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 m=F;;m+=F){let y=m<=a?iA:m>=a+IA?IA:m-a;if(p<y)break;t+=VA(y+(p-y)%(F-y)),p=Math.floor((p-y)/(F-y))}t+=VA(p),a=Qe(l,n+1,n===r),l=0,n++}}l++,u++}return t}function pA(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=yA(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 b(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 CA(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=yA(h[a]))>=0;)g=(g<<4)+f,a++,p++;if(h[a]===46){if(p===0||l>6)return null;a-=p;let m=0;for(;h[a]!==void 0;){let y=0;if(m>0)if(h[a]===46&&m<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+yA(h[a]),y>255)return null;a++}r[l]=256*r[l]+y,m++,m%2==0&&l++}if(m!==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(Te,p)||W(qe,p))return!0}return!1})(r))return null;let a=(r=(function(f){let g="";for(let p of f){let m=p.codePointAt(0);if(m!==8204&&m!==8205&&/\p{Default_Ignorable_Code_Point}/u.test(p))continue;let y=He(p,m);if(y){g+=y;continue}let k=ve.indexOf(m);g+=k<0?p:Oe[k]}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(ke(f)||g&&(/^\p{Mark}/u.test(f)||!_e(f)||!xe(f)||f.startsWith("xn--")))return null;g&&(a[h]=`xn--${Ge(f)}`)}return(r=a.join("."))!==""?r:null})(A.indexOf("%")===-1?A:PA(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(pA(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=pA(u[f]);if(g<0||g>255)return null;a+=g*(1<<8*(3-f))}let h=pA(u[l-1]);return h<0||h>=256**(5-l)?null:(a+=h,a)})(t):t}}function bA(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 m=0;m<a.length;++m)a[m]!==0?(p>g&&(h=f,g=p),f=-1,p=0):(f===-1&&(f=m),++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 gA(A){return A.host===null||A.host===""||A.scheme==="file"}var s=0,o="",w="",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,w="",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=Ke;switch(n){case 3:case 4:r=aA;break;case 5:r=RA;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 Ke=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 w=o.slice(s,t).toLowerCase(),s=t,Ye(t<o.length?A:void 0)}else return E?1:(--s,d(e,A)?ue(c(o,s)):0)},Ye=A=>{let e=s;if(A===58){if(E){if(b(i.scheme)!==b(w))return 0;if((ie(i)||i.port!==null)&&w==="file")return 0;if(i.scheme==="file"&&i.host==="")return 0}return i.scheme=w,E?(i.port===se(i.scheme)&&(i.port=null),0):(w="",i.scheme==="file"?d(e,A)?kA(c(o,s)):0:b(i.scheme)&&D!==null&&D.scheme===i.scheme?d(e,A)?Ve(c(o,s)):0:b(i.scheme)?d(e,A)?Je(c(o,s)):0:c(o,s+1)===47?(s++,d(e,A)?Xe(c(o,s)):0):(i.path=[""],i.opaquePath=!0,d(e,A)?ae(c(o,s)):0))}else return E?1:(w="",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)?OA(c(o,s)):0)},Ve=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)?OA(c(o,s)):0)},Xe=A=>{let e=s;return A===47?d(e,A)?J(c(o,s)):0:(s--,d(e,A)?x(c(o,s)):0)},OA=A=>{let e=s;return i.scheme=D.scheme,A===47||b(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)?OA(c(o,s)):0)},WA=A=>{let e=s;return b(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)},Je=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||!b(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&&b(i.scheme))break;t+=j(n)}return w+=o.slice(s,t),s=t-1,d(e,A)?J(c(o,s)):0}if(A===64){lA&&(w=`%40${w}`),lA=!0;for(let t=0;t<w.length;t++){let n=w.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 w="",d(e,A)?J(c(o,s)):0}else return A==null||A===35||A===47||A===63||A===92&&b(i.scheme)?lA&&w===""?1:(s-=w.length+1,w="",d(e,A)?aA(c(o,s)):0):(w+=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)?qA(c(o,s)):0;if(A!=null&&A!==58&&A!==35&&A!==47&&A!==63&&(A!==92||!b(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&&b(i.scheme))break;n===91?G=!0:n===93&&(G=!1),t+=j(n)}return w+=o.slice(s,t),s=t-1,d(e,A)?aA(c(o,s)):0}else if(A===58&&!G){if(w===""||E===4)return 1;let t=CA(w,!b(i.scheme));return t===null?1:(i.host=bA(t),w="",d(e,A)?RA(c(o,s)):0)}else if(A==null||A===35||A===47||A===63||A===92&&b(i.scheme)){if(s--,b(i.scheme)&&w==="")return 1;if(E&&w===""&&(ie(i)||i.port!==null))return 1;let t=CA(w,!b(i.scheme));return t===null?1:(i.host=bA(t),w="",E?0:d(e,A)?K(c(o,s)):0)}else return w+=le(A),d(e,A)?aA(c(o,s)):0},RA=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 w+=o.slice(s,t),s=t-1,d(e,A)?RA(c(o,s)):0}else if(E||A==null||A===35||A===47||A===63||A===92&&b(i.scheme)){if(w!==""){let t=parseInt(w,10);if(t>65535)return 1;if(i.port=t===se(i.scheme)?null:t,w="",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)?We(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)},We=A=>{let e=s;return A===47||A===92?d(e,A)?qA(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)},qA=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 w+=o.slice(s,t),s=t-1,d(e,A)?qA(c(o,s)):0}else if(A==null||A===47||A===92||A===63||A===35){if(s--,!E&&re(w))return d(e,A)?x(c(o,s)):0;if(w==="")return i.host="",E?0:d(e,A)?K(c(o,s)):0;{let t=CA(w,!b(i.scheme));return t===null?1:(t==="localhost"&&(t=""),i.host=bA(t),w="",E?0:d(e,A)?K(c(o,s)):0)}}return 1},K=A=>{let e=s;return b(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&&(!b(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||b(i.scheme)&&n===92||!E&&(n===63||n===35))break;t+=j(n)}w+=U(o.slice(s,t),DA),s=t,A=c(o,t)}if(A==null||A===47||b(i.scheme)&&A===92||!E&&(A===63||A===35)){let t=b(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}})(w)?(oe(i),A!==47&&!t&&i.path.push("")):XA(w)&&A!==47&&!t?i.path.push(""):XA(w)||(i.scheme==="file"&&i.path.length===0&&re(w)&&(w=`${w[0]}:`),i.path.push(w)),w="",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 w+=ee(A,DA),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=b(i.scheme)?Ee:TA;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),be),s=o.length),d(e,A)?$(c(o,s)):0};function EA(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(EA(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=I(e),t!=null&&(t=I(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=I(e),t!==void 0&&(t=I(t));try{return new A(e,t)}catch{return null}}static canParse(e,t){e=I(e),t!==void 0&&(t=I(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+=EA(t),t.query!==null&&(n+=`?${t.query}`),t.fragment!==null&&(n+=`#${t.fragment}`),n})(this[S].url)}set href(e){let t=H(e=I(e),null,null,0);if(t==null)throw new TypeError(`Invalid URL: ${e}`);this[S].url=t,this[S].query&&wA(this[S].query,t.query)}get origin(){return fe(this[S].url)}get protocol(){return`${this[S].url.scheme}:`}set protocol(e){H(`${e=I(e)}:`,this[S].url,null,2)}get username(){return this[S].url.username}set username(e){e=I(e),gA(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=I(e),gA(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=I(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=I(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=I(e);let{url:t}=this[S];gA(t)||(e?H(e,t,null,5):t.port=null)}get pathname(){return EA(this[S].url)}set pathname(e){e=I(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=I(e);let{url:t,query:n}=this[S];if(!e)t.query=null,n&&wA(n,null);else{let r=e[0]==="?"?e.substring(1):e;t.query="",H(r,t,null,7),n&&wA(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[C].url=r,l[C].serialized=u==null,u&&(l[C].list=vA(u)),l})(this,e.url.query)),t}get hash(){let{url:e}=this[S];return e.fragment?`#${e.fragment}`:""}set hash(e){e=I(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 C=Symbol("URLSearchParamsImpl"),Ze=Symbol.dispose||Symbol.for("dispose");function wA(A,e){e?A[C].list=vA(e):A[C].list.length=0,A[C].serialized=e==null}function oA(A){if(A.url){let e=SA(A.list);(function(n,r){n[S].url.query=r})(A.url,e||null),A.serialized=!0}}var At=typeof Iterator<"u"?Iterator:Object,Z=class extends At{constructor(e,t){super(),this[C]={ptr:e,map:t,index:0}}next(){let e=this[C];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}[Ze](){}},fA=class{constructor(e){let t=this[C]={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=mA(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=Ie(l),h=I(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=I(e);r=r[0]==="?"?r.substring(1):r,t.list=vA(r)}}get size(){return this[C].list.length}append(e,t){e=I(e),t=I(t),this[C].list.push([e,t]);let n=this[C];n.url&&n.serialized?(function(u,l){let a=u[S].url;a.query=a.query?`${a.query}&${l}`:l})(n.url,SA([[e,t]])):oA(n)}delete(e,t){e=I(e),t=t!=null?I(t):void 0;let{list:n}=this[C],r=0;for(;r<n.length;)n[r][0]===e&&(t==null||n[r][1]===t)?n.splice(r,1):r++;oA(this[C])}get(e){e=I(e);let{list:t}=this[C];for(let n=0;n<t.length;n++)if(t[n][0]===e)return t[n][1];return null}getAll(e){e=I(e);let t=[],{list:n}=this[C];for(let r=0;r<n.length;r++)n[r][0]===e&&t.push(n[r][1]);return t}has(e,t){e=I(e),t=t!=null?I(t):void 0;let{list:n}=this[C];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=I(e),t=I(t);let{list:n}=this[C],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[C])}sort(){this[C].list.sort((e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0),oA(this[C])}forEach(e,t){if(typeof e!="function")throw new TypeError('The "callback" argument must be of type function');let{list:n}=this[C];for(let r=0;r<n.length;r++)e.call(t,n[r][1],n[r][0],this)}entries(){return new Z(this[C],e=>e)}keys(){return new Z(this[C],e=>e[0])}values(){return new Z(this[C],e=>e[1])}toString(){return SA(this[C].list)}[Symbol.iterator](){return this.entries()}};Object.defineProperty(fA.prototype,Symbol.toStringTag,{value:"URLSearchParams",configurable:!0});var NA="X-Indiana-Protocol",he="X-Indiana-SDK-Version";var LA={current:"0.10"};function de(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 m=++n;r=void 0,e=void 0;for(let y of[...u.values()])try{y?.()}catch{}m===n&&(e=p,l())}let h=()=>a();function f(p,m=!1){let y=$A.safeParse(p);if(!y.success||m&&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,m=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 k=await A(p.refreshToken);if(m!==n)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");let Y=f(k,!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(k){throw m!==n?new P("IDENTITY_CHANGED","Customer identity changed during refresh"):(k instanceof P&&k.status===401&&h(),k)}})();r=y;try{return await y}finally{r===y&&(r=void 0)}}return{identify(p){let m=typeof p=="string"?p:f(p),y=typeof m=="string"?m:m.accessToken;if(!y.trim()||/\s/.test(y)||y.length>4096)throw new P("INVALID_TOKEN","A server-issued token is required");a(m)},reset:h,subscribeIdentity(p,m){return u.set(p,m),()=>{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 k=t();if(y!==n||!k)throw new P("IDENTITY_CHANGED","Customer identity changed during refresh");return k})}let m=t();if(!m)throw new P("NOT_IDENTIFIED","Identify a customer session before making a request");return m},peek:t,snapshot:()=>typeof e=="object"?{...e}:void 0,refresh:g}}var pe=Symbol("IndianaNoContent");function gt(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??FA);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,m=new Set,y=A.session??de(async v=>{let R=await tA("customer-sessions/refresh",{},"POST",{},v);if(!R||typeof R!="object")throw new P("INVALID_RESPONSE","Invalid refresh response");let{requestId:_,scope:B,...V}=R;return V});function k(){g+=1,p=null;for(let v of m)v.abort();m.clear()}let Y=y.subscribeIdentity(k);function ge(){f||y.reset()}async function tA(v,R={},_="POST",B={},V){let N=B.installationDetach===!0;if(N&&(v!=="push/installations/detach"||_!=="POST"))throw new P("INVALID_REQUEST","Installation authority only detaches this installation");if(!V&&!N)throw new P("NOT_IDENTIFIED","Call identify with a server-issued customer token first");let X=g,L=new AbortController;N||m.add(L);let nA=()=>!N&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):new P("TIMEOUT","The request timed out"),dA,ye=new Promise((O,q)=>{dA=()=>q(nA()),L.signal.addEventListener("abort",dA,{once:!0})}),Pe=setTimeout(()=>L.abort(),B.timeoutMs??h),De=async()=>{let O=await a(`${l.href.replace(/\/$/,"")}/api/v1/${v}`,{method:_,headers:{...B.headers,"Content-Type":"application/json",...N?{}:{Authorization:`Bearer ${V}`},[NA]:LA.current,[he]:zA.version,...u?{"X-Indiana-Project":u.projectId,"X-Indiana-Environment":u.environment}:{}},body:_==="POST"?JSON.stringify(R):void 0,signal:L.signal,credentials:"omit",cache:_==="POST"&&typeof document<"u"?"default":"no-store",redirect:"error",...B.keepalive?{keepalive:!0}:{}});if(L.signal.aborted)throw nA();let q;try{q=O.status===204?pe:await O.json()}catch{throw L.signal.aborted?nA():new P(O.ok?"INVALID_RESPONSE":"HTTP_ERROR","The gateway returned an unreadable response",O.status,O.headers.get("X-Request-Id")??void 0)}if(L.signal.aborted)throw nA();if(!N&&X!==g)throw new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight");if(!O.ok){let T=MA.safeParse(et(q)),z=T.success&&(!BA.safeParse(T.data.error.code).success||xA(T.data.error.code,O.status)),HA=z?T.data.error.code:"HTTP_ERROR",_A=UA(HA,O.status,{retryAfter:O.headers.get("Retry-After"),recovery:z?T.data.error.recovery:void 0,reason:z?T.data.error.reason:void 0});throw new P(HA,z?T.data.error.message:"The request failed",O.status,O.headers.get("X-Request-Id")??(T.success?T.data.requestId:void 0),{..._A,...T.success&&T.data.error.retryable===!1?{retryable:!1}:{},..._A.retryAfterSeconds===void 0&&T.success&&T.data.error.retryAfterSeconds!==void 0?{retryAfterSeconds:T.data.error.retryAfterSeconds}:{}})}if(O.headers.get(NA)!==LA.current)throw new P("PROTOCOL_MISMATCH","Response protocol does not match this SDK");if(u&&q!==pe){let T=q&&typeof q=="object"&&"scope"in q?q:q&&typeof q=="object"&&"configuration"in q?q.configuration:null;if(!T||typeof T!="object"||!("scope"in T))throw new P("INVALID_RESPONSE","Response is missing its App/environment scope");let z=sA.safeParse(T.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=O.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 q};try{return await Promise.race([De(),ye])}catch(O){throw!N&&X!==g?new P("IDENTITY_CHANGED","Customer identity changed while the request was in flight"):O instanceof P?O:new P(L.signal.aborted?"TIMEOUT":"NETWORK_ERROR",L.signal.aborted?"The request timed out":"Unable to read the response")}finally{clearTimeout(Pe),L.signal.removeEventListener("abort",dA),m.delete(L)}}function we(v,R={},_="POST",B={}){if(f)return Promise.reject(new P("CLOSED","SDK client was destroyed"));if(B.installationDetach)return tA(v,R,_,B);let V=g;try{let N=y.access(),X=L=>{if(V!==g)throw new P("IDENTITY_CHANGED","Customer identity changed before dispatch");return tA(v,R,_,B,L)};return typeof N=="string"?X(N):N.then(X)}catch(N){return Promise.reject(N)}}let me=Object.assign(we,{captureIdentity(){let v=g,R=f,_=!!y.peek();return()=>{if(R)throw new P("CLOSED","SDK client was destroyed");if(!_)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,R,_,B={}){return f?Promise.reject(new P("CLOSED","SDK client was destroyed")):tA(v,R,"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 R=sA.safeParse(v.scope);if(!R.success||R.data.projectId!==u.projectId||R.data.environment!==u.environment)throw new P("SCOPE_MISMATCH","Customer session belongs to another App/environment")}y.identify(v)},reset:ge,dispose(){f||(f=!0,Y(),k())},request:me}}function et(A){if(!A||typeof A!="object"||!("error"in A))return A;let e=A.error;if(!e||typeof e!="object"||!("reason"in e)||jA.safeParse(e.reason).success)return A;let{reason:t,...n}=e;return{...A,error:n}}export{eA as a,gt as b};
@@ -1 +1 @@
1
- import{a as T,b as se}from"./chunk-XLGNBPGF.js";import{b as re,h as ae,j as ce}from"./chunk-523S4AFJ.js";import{E as M,a as J}from"./chunk-Z4OHCMV7.js";import{a as b,b as f,c as m}from"./chunk-S2S4ROGY.js";import{c as Z,e as ee,f as te,g as H,h as G,j as ne}from"./chunk-2OBXRQMW.js";import{a as oe,b as j}from"./chunk-PUDTOCQF.js";import{b as W,j as X}from"./chunk-BT7IC765.js";import{n as $}from"./chunk-ME6QTD5Y.js";import{b as ie}from"./chunk-MXI4ANML.js";import{a as B}from"./chunk-KCUE2VFJ.js";import{a as s}from"./chunk-UGATOG2T.js";import{h as Q}from"./chunk-LFR2LWYC.js";import{b as K}from"./chunk-W22ESUYY.js";import{a as z}from"./chunk-DSPLGTQI.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new s("INVALID_STATE","Installation sequence exhausted");return t+1},Se=async t=>[...new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(t,e=>e.charCodeAt(0))))].map(e=>e.toString(16).padStart(2,"0")).join("");function _(t,e){return t.transaction(n=>{if(!Number.isSafeInteger(n.identitySeq)||n.identitySeq<0||!Number.isSafeInteger(n.addressSeq)||n.addressSeq<0||n.detachSeq!==null&&(!Number.isSafeInteger(n.detachSeq)||n.detachSeq<1||n.detachSeq>n.identitySeq))throw new s("INVALID_STATE","Installation journal is invalid");return e({...n})})}function ue(t,e,n){let r=null,o=0,a=0,d=0,y=Promise.resolve(),g=!1;if(t&&(!n||Q.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new s("SCOPE_MISMATCH","Push installation belongs to another scope");let l=()=>{if(g)throw new s("CLOSED","SDK client was destroyed");if(!t)throw new s("NOT_CONFIGURED","Configure this client's native Push host first");return t},O=i=>{if(i!==o)throw new s("IDENTITY_CHANGED","Identity changed during Push operation")};async function F(i){let c=l();if(!c.sha256&&!globalThis.crypto?.subtle)throw new s("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=c.sha256?await c.sha256(Uint8Array.from(i,A=>A.charCodeAt(0))):await Se(i);if(!/^[a-f0-9]{64}$/.test(u))throw new s("INVALID_STATE","Push credential digest is invalid");return u}function p(i){let c=G.parse(i);if(c.installationId.toLowerCase()!==l().installationId.toLowerCase())throw new s("INVALID_RESPONSE","Push response belongs to another installation");return c}async function S(i,c){let u=l(),A={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...c},w=await u.sign(ne(i,u.scope,A));return{...A,signature:w}}let I=(i,c,u)=>e.requestWithCredential?e.requestWithCredential(i,c,u):e.request(i,c);async function q(){let i=l(),c=o,u=r?await(e.session?.access()??r):null,A=_(i,v=>v),w;if(A.detachSeq!==null){let v=A.detachSeq,V=Z.parse(await S("detach",{sequence:v,platform:i.platform}));try{let k=await e.request("push/installations/detach",{...i.scope,...V},"POST",{installationDetach:!0});if(!k||typeof k!="object"||!("installation"in k))throw new s("INVALID_RESPONSE","Push detach acknowledgement is invalid");let x=p(k.installation);if(x.bound||x.identitySeq!==v)throw new s("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(k){if(k instanceof s&&k.status===404)w=k;else if(!(k instanceof s)||k.status!==412)throw k}w||_(i,k=>({...k,detachSeq:k.detachSeq===v?null:k.detachSeq}))}if(O(c),!u){if(w)throw w;return null}let C=(await import("./operation-contracts-YJM6772C.js")).apiOperations.bindPushInstallation,D=C.request.parse(await S("bind",{sequence:d,platform:i.platform,credentialDigest:await F(u)}));O(c);let R=C.response.parse(await I(C.path,D,u));O(c);let N=p(R.installation);if(!N.bound||N.identitySeq!==d)throw new s("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return w&&A.detachSeq!==null&&d>A.detachSeq&&_(i,v=>({...v,detachSeq:v.detachSeq===A.detachSeq?null:v.detachSeq})),N}async function h(){l();let i=o,c=r?await(e.session?.access()??r):null;if(!c)throw new s("NOT_IDENTIFIED","Identify before reading this installation");let u=(await import("./operation-contracts-YJM6772C.js")).apiOperations.readPushInstallation,A=u.request.parse(await S("read",{credentialDigest:await F(c)}));O(i);let w=u.response.parse(await I(u.path,A,c));return O(i),p(w.installation)}function P(i=q){let c=y.catch(()=>{}).then(i);return y=c,c.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),c}async function E(i,c,u){let A=l(),w=c.identity,C=c.observation,D=r?await(e.session?.access()??r):null;if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");if(!D)throw new s("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new s("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await P(async()=>{if(O(w),await q(),O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let R=_(A,x=>u?x:{...x,addressSeq:U(x.addressSeq)}),v=await S(u?"recovery_confirm":"recovery_request",{...i,sequence:R.addressSeq,credentialDigest:await F(D),...u?{challenge:u}:{}}),V=u?te.parse(v):ee.parse(v);if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let k=await I(`push/installations/recovery/${u?"confirm":"request"}`,V,D);if(O(w),C!==a||_(A,x=>x).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");if(u){let{apiOperations:x}=await import("./operation-contracts-YJM6772C.js");if(O(w),C!==a||_(A,Oe=>Oe).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");let Ae=x.updatePushAddress.response.parse(k),L=p(Ae.installation);if(!L.bound||L.identitySeq!==d||L.addressSeq!==R.addressSeq||L.connectionId!==i.connectionId||L.addressStatus!=="active")throw new s("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return L}if(!k||typeof k!="object"||!("recovery"in k))throw new s("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return H.parse(k.recovery)})}return{recoveryObserver(){l();let i={identity:o,observation:++a};return{async request(c){return H.parse(await E(c,i))},async confirm(c,u){return G.parse(await E(u,i,c))}}},identify(i){if(!t)return;d=_(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,o++,a++},reset(){if(t)try{_(t,i=>{let c=U(i.identitySeq);return{...i,identitySeq:c,detachSeq:c}})}finally{r=null,o++,a++}},start(){t&&!g&&P()},destroy(){g=!0,r=null,o++,a++},async sync(){return await P()},read:h,async recover(){let i=l(),c=o,u=d;return a++,await P(async()=>{O(c);let A=await h();return O(c),d=_(i,C=>{if(C.identitySeq!==u)throw new s("IDENTITY_CHANGED","A newer installation intent exists");return{...C,identitySeq:U(Math.max(C.identitySeq,A.identitySeq)),addressSeq:Math.max(C.addressSeq,A.addressSeq)}}).identitySeq,await q()})},tokenObserver(){l();let i=++a,c=o;return async u=>{if(i!==a||c!==o)return null;let A=l(),w=r?await(e.session?.access()??r):null;if(!w)throw new s("NOT_IDENTIFIED","Identify before registering a Push token");if(await P(),O(c),i!==a)return null;let C=_(A,v=>({...v,addressSeq:U(v.addressSeq)})),D=(await import("./operation-contracts-YJM6772C.js")).apiOperations.updatePushAddress,R=D.request.parse(await S("address",{...u,sequence:C.addressSeq,credentialDigest:await F(w)}));if(O(c),i!==a)return null;let N=await I(D.path,R,w);return O(c),i!==a||_(A,v=>v).addressSeq!==C.addressSeq?null:p(D.response.parse(N).installation)}}}}function de(t,e){let n={async preference(r){let o=await f(t,"readMessagingPreference");return(await m(t,o,{channel:r})).preference},async setPreference(r){r=b(r);let o=await f(t,"setMessagingPreference");return(await m(t,o,r)).preference}};return{messaging:n,push:{sync:e.sync,read:e.read,recover:e.recover,tokenObserver:e.tokenObserver,recoveryObserver:e.recoveryObserver,async preference(){return n.preference("push")},async setPreference(r){return r=b(r),n.setPreference({...r,channel:"push"})}}}}function le(t,e,n={}){let r=!1;function o(){if(r)throw new s("CLOSED","SDK client was destroyed")}let a=new Set,d=g=>{for(let l of a)try{l(g)}catch{}},y=t.session.subscribeIdentity(()=>{d(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:o,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(g){return o(),a.add(g),()=>{a.delete(g)}},identify(g){o();let l=typeof g=="string"?g:g.accessToken;if(!B.test(l))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(l),t.identify(g)},reset(){if(!r)try{n.beforeReset?.()}finally{t.reset()}},destroy(){if(!r){r=!0,y(),a.clear();try{n.beforeDestroy?.(),e()}finally{t.dispose()}}}}}}function pe(t){return{async checkEntitlement(e){e=b(e),T(e);let n=await f(t,"checkEntitlement"),r=n.request.parse(e),o=await m(t,n,r);return oe(r.requirement,o.check,void 0,o.scope),o},async readHoldings(e={}){e=b(e);let n=await f(t,"readHoldings"),r={...n,request:n.request.omit({customerId:!0})};return m(t,r,e)}}}function fe(t){return{async readLedger(e){e=b(e);let n=await f(t,"readLedger");return m(t,n,{query:e})},async readCreditStatement(e){e=b(e),T(e);let n=await f(t,"readCreditStatement");return m(t,n,e)},async quoteBalance(e){e=b(e),T(e);let n=await f(t,"quoteBalance");return m(t,n,{command:e})}}}function me(t){return{async setupPayment(e){e=b(e),T(e);let n=await f(t,"setupPayment");return m(t,n,e)},async readPaymentSetup(e){e=b(e),T(e);let n=await f(t,"readPaymentSetup");return m(t,n,e)},async readBillingInvoice(e){e=b(e),T(e);let n=await f(t,"readBillingInvoice");return m(t,n,e)},async readBillingControls(e={}){e=b(e),T(e);let n=await f(t,"readBillingControls");return m(t,n,e)},async prepareBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"prepareBillingAuthorization");return m(t,n,e)},async confirmBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"confirmBillingAuthorization");return m(t,n,e)},async setBillingCoupons(e){e=b(e),T(e);let n=await f(t,"setBillingCoupons");return m(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"revokeBillingAuthorization");return m(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){e=b(e),T(e);let n=await f(t,"listBillingInvoices");return m(t,n,e)},async confirmBillingAdjustment(e){e=b(e),T(e);let n=await f(t,"confirmBillingAdjustment");return m(t,n,e)}}}function ye(t){return{async redeemReward(e){return e=b(e),T(e),(await m(t,await f(t,"redeemReward"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return e=b(e),T(e),(await m(t,await f(t,"claimRewardProduct"),e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return e=b(e),T(e),(await m(t,await f(t,"createReferralCode"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){typeof e=="string"&&(e=e.trim().toUpperCase());let r=await m(t,await f(t,"redeemCoupon"),{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async claimCoupon(e,n=crypto.randomUUID()){let r=await m(t,await f(t,"grantOffer"),{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await m(t,await f(t,"listOffers"),{},{response:"Invalid offers response"})).offers}}}function Ie(t){return{...pe(t),...fe(t),...me(t),...se(t),...ye(t)}}function he(t){return{async resolveContent(e){e=b(e),T(e);let n=await f(t,"resolveContent");return m(t,n,e)},async resolvePaywall(e){e=b(e),T(e);let n=await f(t,"resolvePaywall"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.paywall.check,o.scope),o},async resolveOffering(e){e=b(e),T(e);let n=await f(t,"resolveOffering"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.check,o.scope),o}}}var Y=t=>new TextEncoder().encode(JSON.stringify(t)).length,we=16384,Pe=5e3,Ce=6e4,Re=5;function Te(t){return t instanceof s&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function ge(t,e){let n=0,r,o=h=>{r={config:structuredClone(h),until:Date.now()+3e4}},a=[],d=null,y,g=0;function l(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function O(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,S().catch(()=>{}).finally(O)},Math.min(Pe*2**g,Ce)),typeof y=="object"&&"unref"in y&&y.unref())}function F(h){if(l(),r&&Date.now()<r.until&&!W(r.config,h.kind))return;q();let P=X.parse({events:[{...h,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(Y({events:[P]})>we)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(P)),O()}function p(h,P={},E={}){F({kind:"custom",name:h,properties:P,...E})}async function S(h=!1){if(l(),d)return d;let P=n,E=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},c=a.length;for(;c&&P===n;){let u=[],A=Y({events:[]});for(let C of a.slice(0,Math.min(c,100))){let D=Y(C)+(u.length?1:0);if(u.length&&A+D>we)break;u.push(C),A+=D}let w;try{let C=await f(t,"trackEvents");if(w=await m(t,C,{events:u},void 0,{keepalive:h}),P!==n)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==u.length||w.rejections.length!==w.rejected)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(C){throw P===n&&(g++,(Te(C)||g>=Re)&&(a.splice(0,u.length),g=0)),C}g=0,o(w.analyticsConfig),a.splice(0,u.length),c-=u.length,i.inserted+=w.inserted,i.duplicates+=w.duplicates,i.rejected+=w.rejected,i.skipped+=w.skipped,i.rejections.push(...w.rejections)}return i})();d=E;try{return await E}finally{d===E&&(d=null)}}let I;function q(){if(I||typeof document>"u")return;let h=()=>{document.visibilityState==="hidden"&&e()&&a.length&&S(!0).catch(()=>{})};document.addEventListener("visibilitychange",h),I=()=>document.removeEventListener("visibilitychange",h)}return{rememberConfiguration:o,track:p,observe:F,flush:S,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],g=0,d=null},detachVisibility(){I?.(),I=void 0}}}function ve(t){let e=t.merchandise;if(typeof t.merchandiseId=="string")return{internalId:t.merchandiseId};if(!(!e||typeof e!="object"||Array.isArray(e))){if(typeof e.internalId=="string")return{internalId:e.internalId};if(typeof e.externalId=="string")return{id:e.externalId};if(typeof e.id=="string")return{id:e.id}}}var qe=new Set([...$,"merchandiseId","merchandise"]);function ke(t){let e=ve(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!qe.has(r))),...e?{merchandise:e}:{}}}function Ee(t,e,n,r,o){if(o&&r&&(o.scope.projectId!==r.projectId||o.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,d=new Set;function y(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}async function g(l={}){o||y();let O=a,F=!1,p=async()=>{if(F||O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let R=o?{scope:{projectId:o.scope.projectId,environment:o.scope.environment},payload:await o.features()}:await m(t,await f(t,"getFeatures"),{});if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},S=await p(),I=!0,q,h=R=>{try{l.onError?.(R)}catch{}},P=(R,N)=>{try{let v=ve(N);n.observe({...R,...v?{merchandise:v}:{}})}catch(v){h(v)}},E=ae({assertUsable:o?.assertFeatures,scope:S.scope,attributes:l.attributes,onError:l.onError,load:async()=>I?(I=!1,S.payload):(await p()).payload,evaluateRemote:async R=>{if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let N=await f(t,"evaluateFeatures"),v=await m(t,N,{...R,attributes:ke(R.attributes)});if(v.scope.projectId!==S.scope.projectId||v.scope.environment!==S.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:v.generation,evaluatedAt:v.evaluatedAt,expiresAt:v.expiresAt,features:v.features,...v.merchandiseContext?{merchandiseContext:v.merchandiseContext}:{}}},onExperimentViewed:(R,N,v,V)=>P({kind:"experiment_exposure",generation:V,experimentId:R.key,variationId:N.key},v),onFeatureUsage:(R,N,v,V)=>P({kind:"feature_usage",generation:V,feature:R,value:N.value??null,source:N.source,ruleId:N.ruleId,...N.experimentResult?{variationId:N.experimentResult.key}:{}},v)}),i=E.refresh;function c(){clearTimeout(q),!o&&(F||O!==a||!E.expiresAt||(q=setTimeout(()=>{u().catch(h)},Math.min(2147483647,Math.max(1e3,Date.parse(E.expiresAt)-Date.now()))),typeof q=="object"&&"unref"in q&&q.unref()))}async function u(){try{return await i()}finally{c()}}let A=()=>{F||u().catch(h)},w=E.subscribe(c),C=o?.subscribe(()=>{!F&&o.fresh&&u().catch(h)});function D(){F||(F=!0,clearTimeout(q),typeof window<"u"&&window.removeEventListener("focus",A),w(),C?.(),E.reset(),d.delete(D))}d.add(D);try{await E.init(),(l.attributes?.merchandise||l.attributes?.merchandiseId)&&await E.refreshRemote()}catch(R){throw D(),R}return c(),!o&&typeof window<"u"&&window.addEventListener("focus",A),Object.assign(E,{refresh:u,destroy:D})}return{features:g,reset(l){a++,l();for(let O of d)O()}}}function be(t,e){let n="source"in e?{funnelId:e.source.id,funnelVersionId:e.source.versionId}:"versionId"in e?{funnelId:e.funnelId,funnelVersionId:e.versionId}:e,r=K.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let o=Object.freeze(r.data);function a(d){if("customerId"in d)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in d&&d.funnelId!==void 0&&d.funnelId!==o.funnelId||"funnelVersionId"in d&&d.funnelVersionId!==void 0&&d.funnelVersionId!==o.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...d,...o}}return{async claimCoupon(d,y=crypto.randomUUID()){let g=await f(t,"grantOffer"),l=await m(t,g,a({couponId:d,requestId:y}));return{offer:l.offer,reason:l.reason}},async resolveOffering(d){d=b(d);let y=await f(t,"resolveOffering"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.check,l.scope),l},async resolvePaywall(d){d=b(d);let y=await f(t,"resolvePaywall"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.paywall.check,l.scope),l},async previewAttach(d){d=b(d);let y=await f(t,"previewAttach");return m(t,y,a(d))}}}function xt(t){return Ne(t)}function Ne(t){let e=ie(t),n=e.request,r;try{r=ue(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let o=le(e,()=>{d.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=ge(n,o.isIdentified),d=Ee(n,o.isIdentified,a,t.scope,t.configuration);return{session:e.session,...de(n,r),...Ie(n),...he(n),forFunnel(y){return o.assertActive(),be(n,y)},async features(y={}){return o.assertActive(),d.features(y)},track(y,g,l={}){return a.track(y,g,l)},flush(){return a.flush()},...o.methods}}function Mt(t){if(!B.test(t.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let e=ce({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),o=M({...t,runToken:r.runToken,initialResponse:r});o.identify(t.customerToken);let a=await o.get();return{...r,...a,controller:o}}}}function Kt(t){if(!t.scope)throw new s("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new s("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,o=new Set,a=new Map,d=new Map;async function y(p){let S,I=new Promise((q,h)=>{S=setTimeout(()=>h(new s("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(p),I])}finally{clearTimeout(S)}}function g(p){throw p instanceof s&&(p.status===401||p.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear()),p}function l(p,S){if(S!==r)throw new s("IDENTITY_CHANGED","Process was detached during a request");let I=re.parse(p);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new s("SCOPE_MISMATCH","Process response belongs to another App/environment");if(e&&(e.run.id!==I.run.id||e.run.source.versionId!==I.run.source.versionId||e.run.source.id!==I.run.source.id||e.run.runExpiresAt!==I.run.runExpiresAt||e.run.identity.startedAs!==I.run.identity.startedAs||e.run.identity.participantId!==I.run.identity.participantId||e.run.identity.binding&&I.run.identity.binding&&e.run.identity.binding.id!==I.run.identity.binding.id))throw new s("INVALID_RESPONSE","The process changed its Run or Customer binding");if(!e||I.run.revision>=e.run.revision){if(e?.run.identity.binding&&!I.run.identity.binding)throw new s("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let A of o)z(A,I.run);I.run.instruction?.type==="authentication_required"&&z(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&d.set(I.settlement.requestId,I.settlement.accepted);let{identity:q,instruction:h,...P}=I.run,{contract:E,settlement:i,...c}=I,u=i&&(({accepted:A,...w})=>w)(i);return{...c,run:{...P,authenticated:q.binding!==null,instruction:h?.type==="authentication_required"?null:h},...u?{settlement:u}:{}}}let O=p=>(a.has(p)||a.set(p,e?.run.identity.binding?.id??null),a.get(p));async function F(p){let S=r,I=e?.run.identity.binding?.id??null,q=P=>{if(I!==(e?.run.identity.binding?.id??null))throw P;return g(P)};if(p.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new s("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(p.release,p.usedReceiptIds)).catch(q)}let h;if(p.operation==="get"){let{operation:P,customerToken:E,...i}=p;h=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:O(i.settlementRequestId)}:{}})).catch(q)}else if(p.operation==="review")h=await y(()=>t.adapter.review(p.receiptId)).catch(q);else{if(p.operation==="start")throw new s("INVALID_REQUEST","Use process.open for entry");{let{customerToken:P,...E}=p;h=await y(()=>t.adapter.command(E,O(E.requestId))).catch(q)}}return l(h,S)}return{get view(){return e?.run??null},get controller(){return n},async open(p){let S=r,I=await y(()=>t.adapter.open(p)).catch(g),q=l(I,S);if(!n){n=M({...t,runToken:I.runToken,initialResponse:q,process:{request:F,binding:O,restore(E){for(let[i,c]of Object.entries(E))a.set(i,c)}}});let h=n,P=h.submit;h.submit=async E=>{try{return await P(E)}catch(i){if(!(i instanceof s)||i.reason!=="IDENTITY_CONTEXT_CHANGED"||E.operation!=="submit"||E.input.type!=="screen"||a.get(E.requestId)!==null)throw i;await h.settle?.(E.requestId),await h.get();let c=h.view;if(d.get(E.requestId)!==!1||!c||c.id!==e?.run.id||c.nodeId!==E.nodeId||c.visit!==E.visit||!e?.run.identity.binding)throw i;return P({...E,requestId:crypto.randomUUID(),revision:c.revision})}}}await n.get();for(let h of n.pendingCommands??[])a.has(h.requestId)&&a.get(h.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(h.requestId);return{run:e.run,controller:n}},async syncIdentity(){let p=r;l(await y(()=>t.adapter.syncIdentity()).catch(g),p),await n?.get();for(let S of n?.pendingCommands??[])a.has(S.requestId)&&a.get(S.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(S.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),await y(()=>t.adapter.detach())},forProcess(p){if(!e?.run.identity.binding)throw new s("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:p}},subscribe(p){return o.add(p),()=>{o.delete(p)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),o.clear()}}}export{xt as a,Ne as b,Mt as c,Kt as d};
1
+ import{a as T,b as se}from"./chunk-XLGNBPGF.js";import{b as re,h as ae,j as ce}from"./chunk-ZTKPJTE4.js";import{E as M,a as J}from"./chunk-BSC3VAYP.js";import{a as b,b as f,c as m}from"./chunk-S2S4ROGY.js";import{c as Z,e as ee,f as te,g as H,h as G,j as ne}from"./chunk-2OBXRQMW.js";import{a as oe,b as j}from"./chunk-PUDTOCQF.js";import{b as W,j as X}from"./chunk-BT7IC765.js";import{n as $}from"./chunk-ME6QTD5Y.js";import{b as ie}from"./chunk-OJZWFIG3.js";import{a as B}from"./chunk-KCUE2VFJ.js";import{a as s}from"./chunk-UGATOG2T.js";import{h as Q}from"./chunk-LFR2LWYC.js";import{b as K}from"./chunk-W22ESUYY.js";import{a as z}from"./chunk-DSPLGTQI.js";var U=t=>{if(!Number.isSafeInteger(t)||t<0||t>=Number.MAX_SAFE_INTEGER)throw new s("INVALID_STATE","Installation sequence exhausted");return t+1},Se=async t=>[...new Uint8Array(await crypto.subtle.digest("SHA-256",Uint8Array.from(t,e=>e.charCodeAt(0))))].map(e=>e.toString(16).padStart(2,"0")).join("");function _(t,e){return t.transaction(n=>{if(!Number.isSafeInteger(n.identitySeq)||n.identitySeq<0||!Number.isSafeInteger(n.addressSeq)||n.addressSeq<0||n.detachSeq!==null&&(!Number.isSafeInteger(n.detachSeq)||n.detachSeq<1||n.detachSeq>n.identitySeq))throw new s("INVALID_STATE","Installation journal is invalid");return e({...n})})}function ue(t,e,n){let r=null,o=0,a=0,d=0,y=Promise.resolve(),g=!1;if(t&&(!n||Q.parse(t.scope).projectId!==n.projectId||t.scope.environment!==n.environment))throw new s("SCOPE_MISMATCH","Push installation belongs to another scope");let l=()=>{if(g)throw new s("CLOSED","SDK client was destroyed");if(!t)throw new s("NOT_CONFIGURED","Configure this client's native Push host first");return t},O=i=>{if(i!==o)throw new s("IDENTITY_CHANGED","Identity changed during Push operation")};async function F(i){let c=l();if(!c.sha256&&!globalThis.crypto?.subtle)throw new s("NOT_CONFIGURED","Configure native SHA-256 for this Push host");let u=c.sha256?await c.sha256(Uint8Array.from(i,A=>A.charCodeAt(0))):await Se(i);if(!/^[a-f0-9]{64}$/.test(u))throw new s("INVALID_STATE","Push credential digest is invalid");return u}function p(i){let c=G.parse(i);if(c.installationId.toLowerCase()!==l().installationId.toLowerCase())throw new s("INVALID_RESPONSE","Push response belongs to another installation");return c}async function S(i,c){let u=l(),A={installationId:u.installationId,publicKey:u.publicKey,issuedAt:new Date().toISOString(),...c},w=await u.sign(ne(i,u.scope,A));return{...A,signature:w}}let I=(i,c,u)=>e.requestWithCredential?e.requestWithCredential(i,c,u):e.request(i,c);async function q(){let i=l(),c=o,u=r?await(e.session?.access()??r):null,A=_(i,v=>v),w;if(A.detachSeq!==null){let v=A.detachSeq,V=Z.parse(await S("detach",{sequence:v,platform:i.platform}));try{let k=await e.request("push/installations/detach",{...i.scope,...V},"POST",{installationDetach:!0});if(!k||typeof k!="object"||!("installation"in k))throw new s("INVALID_RESPONSE","Push detach acknowledgement is invalid");let x=p(k.installation);if(x.bound||x.identitySeq!==v)throw new s("INVALID_RESPONSE","Push detach acknowledgement does not match its intent")}catch(k){if(k instanceof s&&k.status===404)w=k;else if(!(k instanceof s)||k.status!==412)throw k}w||_(i,k=>({...k,detachSeq:k.detachSeq===v?null:k.detachSeq}))}if(O(c),!u){if(w)throw w;return null}let C=(await import("./operation-contracts-YJM6772C.js")).apiOperations.bindPushInstallation,D=C.request.parse(await S("bind",{sequence:d,platform:i.platform,credentialDigest:await F(u)}));O(c);let R=C.response.parse(await I(C.path,D,u));O(c);let N=p(R.installation);if(!N.bound||N.identitySeq!==d)throw new s("INVALID_RESPONSE","Push binding acknowledgement does not match its intent");return w&&A.detachSeq!==null&&d>A.detachSeq&&_(i,v=>({...v,detachSeq:v.detachSeq===A.detachSeq?null:v.detachSeq})),N}async function h(){l();let i=o,c=r?await(e.session?.access()??r):null;if(!c)throw new s("NOT_IDENTIFIED","Identify before reading this installation");let u=(await import("./operation-contracts-YJM6772C.js")).apiOperations.readPushInstallation,A=u.request.parse(await S("read",{credentialDigest:await F(c)}));O(i);let w=u.response.parse(await I(u.path,A,c));return O(i),p(w.installation)}function P(i=q){let c=y.catch(()=>{}).then(i);return y=c,c.catch(u=>{try{t?.onError?.(u instanceof Error?u:new Error("Push synchronization failed"))}catch{}}),c}async function E(i,c,u){let A=l(),w=c.identity,C=c.observation,D=r?await(e.session?.access()??r):null;if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");if(!D)throw new s("NOT_IDENTIFIED","Identify before recovering a Push address");if(!i.connectionId||!i.kind||!i.token||!["granted","provisional"].includes(i.permission))throw new s("INVALID_REQUEST","Recovery needs a provider token and notification permission");return await P(async()=>{if(O(w),await q(),O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let R=_(A,x=>u?x:{...x,addressSeq:U(x.addressSeq)}),v=await S(u?"recovery_confirm":"recovery_request",{...i,sequence:R.addressSeq,credentialDigest:await F(D),...u?{challenge:u}:{}}),V=u?te.parse(v):ee.parse(v);if(O(w),C!==a)throw new s("INVALID_STATE","Push observation changed during recovery");let k=await I(`push/installations/recovery/${u?"confirm":"request"}`,V,D);if(O(w),C!==a||_(A,x=>x).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");if(u){let{apiOperations:x}=await import("./operation-contracts-YJM6772C.js");if(O(w),C!==a||_(A,Oe=>Oe).addressSeq!==R.addressSeq)throw new s("INVALID_STATE","Push observation changed during recovery");let Ae=x.updatePushAddress.response.parse(k),L=p(Ae.installation);if(!L.bound||L.identitySeq!==d||L.addressSeq!==R.addressSeq||L.connectionId!==i.connectionId||L.addressStatus!=="active")throw new s("INVALID_RESPONSE","Push recovery acknowledgement does not match its intent");return L}if(!k||typeof k!="object"||!("recovery"in k))throw new s("INVALID_RESPONSE","Push recovery acknowledgement is invalid");return H.parse(k.recovery)})}return{recoveryObserver(){l();let i={identity:o,observation:++a};return{async request(c){return H.parse(await E(c,i))},async confirm(c,u){return G.parse(await E(u,i,c))}}},identify(i){if(!t)return;d=_(t,u=>({...u,identitySeq:U(u.identitySeq)})).identitySeq,r=i,o++,a++},reset(){if(t)try{_(t,i=>{let c=U(i.identitySeq);return{...i,identitySeq:c,detachSeq:c}})}finally{r=null,o++,a++}},start(){t&&!g&&P()},destroy(){g=!0,r=null,o++,a++},async sync(){return await P()},read:h,async recover(){let i=l(),c=o,u=d;return a++,await P(async()=>{O(c);let A=await h();return O(c),d=_(i,C=>{if(C.identitySeq!==u)throw new s("IDENTITY_CHANGED","A newer installation intent exists");return{...C,identitySeq:U(Math.max(C.identitySeq,A.identitySeq)),addressSeq:Math.max(C.addressSeq,A.addressSeq)}}).identitySeq,await q()})},tokenObserver(){l();let i=++a,c=o;return async u=>{if(i!==a||c!==o)return null;let A=l(),w=r?await(e.session?.access()??r):null;if(!w)throw new s("NOT_IDENTIFIED","Identify before registering a Push token");if(await P(),O(c),i!==a)return null;let C=_(A,v=>({...v,addressSeq:U(v.addressSeq)})),D=(await import("./operation-contracts-YJM6772C.js")).apiOperations.updatePushAddress,R=D.request.parse(await S("address",{...u,sequence:C.addressSeq,credentialDigest:await F(w)}));if(O(c),i!==a)return null;let N=await I(D.path,R,w);return O(c),i!==a||_(A,v=>v).addressSeq!==C.addressSeq?null:p(D.response.parse(N).installation)}}}}function de(t,e){let n={async preference(r){let o=await f(t,"readMessagingPreference");return(await m(t,o,{channel:r})).preference},async setPreference(r){r=b(r);let o=await f(t,"setMessagingPreference");return(await m(t,o,r)).preference}};return{messaging:n,push:{sync:e.sync,read:e.read,recover:e.recover,tokenObserver:e.tokenObserver,recoveryObserver:e.recoveryObserver,async preference(){return n.preference("push")},async setPreference(r){return r=b(r),n.setPreference({...r,channel:"push"})}}}}function le(t,e,n={}){let r=!1;function o(){if(r)throw new s("CLOSED","SDK client was destroyed")}let a=new Set,d=g=>{for(let l of a)try{l(g)}catch{}},y=t.session.subscribeIdentity(()=>{d(!!t.session.peek()),n.afterChange?.()},()=>{e()});return{assertActive:o,isIdentified:()=>!r&&!!t.session.peek(),methods:{subscribeIdentity(g){return o(),a.add(g),()=>{a.delete(g)}},identify(g){o();let l=typeof g=="string"?g:g.accessToken;if(!B.test(l))throw new s("INVALID_TOKEN","Browser SDK requires a customer session");n.beforeIdentify?.(l),t.identify(g)},reset(){if(!r)try{n.beforeReset?.()}finally{t.reset()}},destroy(){if(!r){r=!0,y(),a.clear();try{n.beforeDestroy?.(),e()}finally{t.dispose()}}}}}}function pe(t){return{async checkEntitlement(e){e=b(e),T(e);let n=await f(t,"checkEntitlement"),r=n.request.parse(e),o=await m(t,n,r);return oe(r.requirement,o.check,void 0,o.scope),o},async readHoldings(e={}){e=b(e);let n=await f(t,"readHoldings"),r={...n,request:n.request.omit({customerId:!0})};return m(t,r,e)}}}function fe(t){return{async readLedger(e){e=b(e);let n=await f(t,"readLedger");return m(t,n,{query:e})},async readCreditStatement(e){e=b(e),T(e);let n=await f(t,"readCreditStatement");return m(t,n,e)},async quoteBalance(e){e=b(e),T(e);let n=await f(t,"quoteBalance");return m(t,n,{command:e})}}}function me(t){return{async setupPayment(e){e=b(e),T(e);let n=await f(t,"setupPayment");return m(t,n,e)},async readPaymentSetup(e){e=b(e),T(e);let n=await f(t,"readPaymentSetup");return m(t,n,e)},async readBillingInvoice(e){e=b(e),T(e);let n=await f(t,"readBillingInvoice");return m(t,n,e)},async readBillingControls(e={}){e=b(e),T(e);let n=await f(t,"readBillingControls");return m(t,n,e)},async prepareBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"prepareBillingAuthorization");return m(t,n,e)},async confirmBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"confirmBillingAuthorization");return m(t,n,e)},async setBillingCoupons(e){e=b(e),T(e);let n=await f(t,"setBillingCoupons");return m(t,n,e,{request:"Invalid billing coupon list",response:"Invalid billing coupon receipt"})},async revokeBillingAuthorization(e){e=b(e),T(e);let n=await f(t,"revokeBillingAuthorization");return m(t,n,e)},async listBillingInvoices(e={after:null,limit:25}){e=b(e),T(e);let n=await f(t,"listBillingInvoices");return m(t,n,e)},async confirmBillingAdjustment(e){e=b(e),T(e);let n=await f(t,"confirmBillingAdjustment");return m(t,n,e)}}}function ye(t){return{async redeemReward(e){return e=b(e),T(e),(await m(t,await f(t,"redeemReward"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid reward redemption",response:"Invalid reward receipt"})).redemption},async claimRewardProduct(e){return e=b(e),T(e),(await m(t,await f(t,"claimRewardProduct"),e,{request:"Invalid reward product claim",response:"Invalid reward product checkout"})).checkout},async createReferralCode(e){return e=b(e),T(e),(await m(t,await f(t,"createReferralCode"),{...e,requestId:e.requestId??crypto.randomUUID()},{request:"Invalid referral program",response:"Invalid referral code"})).referralCode},async redeemCoupon(e,n=crypto.randomUUID()){typeof e=="string"&&(e=e.trim().toUpperCase());let r=await m(t,await f(t,"redeemCoupon"),{code:e,requestId:n},{request:"Invalid coupon code",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async claimCoupon(e,n=crypto.randomUUID()){let r=await m(t,await f(t,"grantOffer"),{couponId:e,requestId:n},{request:"Invalid Coupon claim",response:"Invalid Coupon receipt"});return{offer:r.offer,reason:r.reason}},async listOffers(){return(await m(t,await f(t,"listOffers"),{},{response:"Invalid offers response"})).offers}}}function Ie(t){return{...pe(t),...fe(t),...me(t),...se(t),...ye(t)}}function he(t){return{async resolveContent(e){e=b(e),T(e);let n=await f(t,"resolveContent");return m(t,n,e)},async resolvePaywall(e){e=b(e),T(e);let n=await f(t,"resolvePaywall"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.paywall.check,o.scope),o},async resolveOffering(e){e=b(e),T(e);let n=await f(t,"resolveOffering"),r=n.request.parse(e),o=await m(t,n,r);return j(r,o.check,o.scope),o}}}var Y=t=>new TextEncoder().encode(JSON.stringify(t)).length,we=16384,Pe=5e3,Ce=6e4,Re=5;function Te(t){return t instanceof s&&t.status!==void 0&&t.status>=400&&t.status<500&&!t.retryable}function ge(t,e){let n=0,r,o=h=>{r={config:structuredClone(h),until:Date.now()+3e4}},a=[],d=null,y,g=0;function l(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}function O(){y||!a.length||!e()||(y=setTimeout(()=>{y=void 0,S().catch(()=>{}).finally(O)},Math.min(Pe*2**g,Ce)),typeof y=="object"&&"unref"in y&&y.unref())}function F(h){if(l(),r&&Date.now()<r.until&&!W(r.config,h.kind))return;q();let P=X.parse({events:[{...h,eventUuid:crypto.randomUUID(),timestamp:new Date().toISOString()}]}).events[0];if(Y({events:[P]})>we)throw new s("INVALID_REQUEST","Event exceeds the delivery size limit");if(a.length>=500)throw new s("EVENT_QUEUE_FULL","Flush pending events before tracking more");a.push(structuredClone(P)),O()}function p(h,P={},E={}){F({kind:"custom",name:h,properties:P,...E})}async function S(h=!1){if(l(),d)return d;let P=n,E=(async()=>{let i={inserted:0,duplicates:0,rejected:0,skipped:0,rejections:[]},c=a.length;for(;c&&P===n;){let u=[],A=Y({events:[]});for(let C of a.slice(0,Math.min(c,100))){let D=Y(C)+(u.length?1:0);if(u.length&&A+D>we)break;u.push(C),A+=D}let w;try{let C=await f(t,"trackEvents");if(w=await m(t,C,{events:u},void 0,{keepalive:h}),P!==n)throw new s("IDENTITY_CHANGED","Event identity changed during delivery");if(w.inserted+w.duplicates+w.rejected+w.skipped!==u.length||w.rejections.length!==w.rejected)throw new s("INVALID_RESPONSE","Incomplete event acknowledgement")}catch(C){throw P===n&&(g++,(Te(C)||g>=Re)&&(a.splice(0,u.length),g=0)),C}g=0,o(w.analyticsConfig),a.splice(0,u.length),c-=u.length,i.inserted+=w.inserted,i.duplicates+=w.duplicates,i.rejected+=w.rejected,i.skipped+=w.skipped,i.rejections.push(...w.rejections)}return i})();d=E;try{return await E}finally{d===E&&(d=null)}}let I;function q(){if(I||typeof document>"u")return;let h=()=>{document.visibilityState==="hidden"&&e()&&a.length&&S(!0).catch(()=>{})};document.addEventListener("visibilitychange",h),I=()=>document.removeEventListener("visibilitychange",h)}return{rememberConfiguration:o,track:p,observe:F,flush:S,reset(){n++,r=void 0,clearTimeout(y),y=void 0,a=[],g=0,d=null},detachVisibility(){I?.(),I=void 0}}}function ve(t){let e=t.merchandise;if(typeof t.merchandiseId=="string")return{internalId:t.merchandiseId};if(!(!e||typeof e!="object"||Array.isArray(e))){if(typeof e.internalId=="string")return{internalId:e.internalId};if(typeof e.externalId=="string")return{id:e.externalId};if(typeof e.id=="string")return{id:e.id}}}var qe=new Set([...$,"merchandiseId","merchandise"]);function ke(t){let e=ve(t);return{...Object.fromEntries(Object.entries(t).filter(([r])=>!qe.has(r))),...e?{merchandise:e}:{}}}function Ee(t,e,n,r,o){if(o&&r&&(o.scope.projectId!==r.projectId||o.scope.environment!==r.environment))throw new s("SCOPE_MISMATCH","Configuration belongs to another App/environment");let a=0,d=new Set;function y(){if(!e())throw new s("NOT_IDENTIFIED","Call identify before using Features or events")}async function g(l={}){o||y();let O=a,F=!1,p=async()=>{if(F||O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let R=o?{scope:{projectId:o.scope.projectId,environment:o.scope.environment},payload:await o.features()}:await m(t,await f(t,"getFeatures"),{});if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");if(r&&(R.scope.projectId!==r.projectId||R.scope.environment!==r.environment))throw new s("INVALID_RESPONSE","Feature response scope changed");return n.rememberConfiguration(R.payload.analyticsConfig),R},S=await p(),I=!0,q,h=R=>{try{l.onError?.(R)}catch{}},P=(R,N)=>{try{let v=ve(N);n.observe({...R,...v?{merchandise:v}:{}})}catch(v){h(v)}},E=ae({assertUsable:o?.assertFeatures,scope:S.scope,attributes:l.attributes,onError:l.onError,load:async()=>I?(I=!1,S.payload):(await p()).payload,evaluateRemote:async R=>{if(O!==a)throw new s("IDENTITY_CHANGED","Feature identity changed");let N=await f(t,"evaluateFeatures"),v=await m(t,N,{...R,attributes:ke(R.attributes)});if(v.scope.projectId!==S.scope.projectId||v.scope.environment!==S.scope.environment)throw new s("INVALID_RESPONSE","Remote Feature response scope changed");return{generation:v.generation,evaluatedAt:v.evaluatedAt,expiresAt:v.expiresAt,features:v.features,...v.merchandiseContext?{merchandiseContext:v.merchandiseContext}:{}}},onExperimentViewed:(R,N,v,V)=>P({kind:"experiment_exposure",generation:V,experimentId:R.key,variationId:N.key},v),onFeatureUsage:(R,N,v,V)=>P({kind:"feature_usage",generation:V,feature:R,value:N.value??null,source:N.source,ruleId:N.ruleId,...N.experimentResult?{variationId:N.experimentResult.key}:{}},v)}),i=E.refresh;function c(){clearTimeout(q),!o&&(F||O!==a||!E.expiresAt||(q=setTimeout(()=>{u().catch(h)},Math.min(2147483647,Math.max(1e3,Date.parse(E.expiresAt)-Date.now()))),typeof q=="object"&&"unref"in q&&q.unref()))}async function u(){try{return await i()}finally{c()}}let A=()=>{F||u().catch(h)},w=E.subscribe(c),C=o?.subscribe(()=>{!F&&o.fresh&&u().catch(h)});function D(){F||(F=!0,clearTimeout(q),typeof window<"u"&&window.removeEventListener("focus",A),w(),C?.(),E.reset(),d.delete(D))}d.add(D);try{await E.init(),(l.attributes?.merchandise||l.attributes?.merchandiseId)&&await E.refreshRemote()}catch(R){throw D(),R}return c(),!o&&typeof window<"u"&&window.addEventListener("focus",A),Object.assign(E,{refresh:u,destroy:D})}return{features:g,reset(l){a++,l();for(let O of d)O()}}}function be(t,e){let n="source"in e?{funnelId:e.source.id,funnelVersionId:e.source.versionId}:"versionId"in e?{funnelId:e.funnelId,funnelVersionId:e.versionId}:e,r=K.object({funnelId:J.shape.id,funnelVersionId:J.shape.versionId.optional()}).safeParse(n);if(!r.success)throw new s("INVALID_REQUEST","A valid Funnel source is required");let o=Object.freeze(r.data);function a(d){if("customerId"in d)throw new s("INVALID_REQUEST","Customer identity cannot be overridden");if("funnelId"in d&&d.funnelId!==void 0&&d.funnelId!==o.funnelId||"funnelVersionId"in d&&d.funnelVersionId!==void 0&&d.funnelVersionId!==o.funnelVersionId)throw new s("SCOPE_MISMATCH","The original Funnel source cannot change");return{...d,...o}}return{async claimCoupon(d,y=crypto.randomUUID()){let g=await f(t,"grantOffer"),l=await m(t,g,a({couponId:d,requestId:y}));return{offer:l.offer,reason:l.reason}},async resolveOffering(d){d=b(d);let y=await f(t,"resolveOffering"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.check,l.scope),l},async resolvePaywall(d){d=b(d);let y=await f(t,"resolvePaywall"),g=y.request.parse(a(d)),l=await m(t,y,g);return j(g,l.paywall.check,l.scope),l},async previewAttach(d){d=b(d);let y=await f(t,"previewAttach");return m(t,y,a(d))}}}function xt(t){return Ne(t)}function Ne(t){let e=ie(t),n=e.request,r;try{r=ue(t.push,e,t.scope??t.configuration?.scope)}catch(y){throw e.dispose(),y}let o=le(e,()=>{d.reset(a.reset),a.detachVisibility()},{beforeIdentify:r.identify,beforeReset:r.reset,afterChange:r.start,beforeDestroy:r.destroy}),a=ge(n,o.isIdentified),d=Ee(n,o.isIdentified,a,t.scope,t.configuration);return{session:e.session,...de(n,r),...Ie(n),...he(n),forFunnel(y){return o.assertActive(),be(n,y)},async features(y={}){return o.assertActive(),d.features(y)},track(y,g,l={}){return a.track(y,g,l)},flush(){return a.flush()},...o.methods}}function Mt(t){if(!B.test(t.customerToken))throw new s("INVALID_TOKEN","A customer credential is required");if(!t.scope)throw new s("INVALID_REQUEST","An explicit App and environment scope is required");let e=ce({...t,scope:t.scope,apiKey:t.customerToken});return{async start(n){let r=await e.start(n),o=M({...t,runToken:r.runToken,initialResponse:r});o.identify(t.customerToken);let a=await o.get();return{...r,...a,controller:o}}}}function Kt(t){if(!t.scope)throw new s("INVALID_CONFIGURATION","An explicit process App/environment scope is required");if(t.session!==void 0)throw new s("INVALID_CONFIGURATION","The merchant process adapter owns the session");let e=null,n,r=0,o=new Set,a=new Map,d=new Map;async function y(p){let S,I=new Promise((q,h)=>{S=setTimeout(()=>h(new s("TIMEOUT","Process bridge request timed out")),t.timeoutMs??35e3)});try{return await Promise.race([Promise.resolve().then(p),I])}finally{clearTimeout(S)}}function g(p){throw p instanceof s&&(p.status===401||p.reason==="CUSTOMER_BINDING_CONFLICT")&&(r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear()),p}function l(p,S){if(S!==r)throw new s("IDENTITY_CHANGED","Process was detached during a request");let I=re.parse(p);if(I.scope.projectId!==t.scope.projectId||I.scope.environment!==t.scope.environment)throw new s("SCOPE_MISMATCH","Process response belongs to another App/environment");if(e&&(e.run.id!==I.run.id||e.run.source.versionId!==I.run.source.versionId||e.run.source.id!==I.run.source.id||e.run.runExpiresAt!==I.run.runExpiresAt||e.run.identity.startedAs!==I.run.identity.startedAs||e.run.identity.participantId!==I.run.identity.participantId||e.run.identity.binding&&I.run.identity.binding&&e.run.identity.binding.id!==I.run.identity.binding.id))throw new s("INVALID_RESPONSE","The process changed its Run or Customer binding");if(!e||I.run.revision>=e.run.revision){if(e?.run.identity.binding&&!I.run.identity.binding)throw new s("INVALID_RESPONSE","The process lost its Customer binding");e=I;for(let A of o)z(A,I.run);I.run.instruction?.type==="authentication_required"&&z(t.onAuthenticationRequired,I.run)}I.settlement?.accepted!==void 0&&d.set(I.settlement.requestId,I.settlement.accepted);let{identity:q,instruction:h,...P}=I.run,{contract:E,settlement:i,...c}=I,u=i&&(({accepted:A,...w})=>w)(i);return{...c,run:{...P,authenticated:q.binding!==null,instruction:h?.type==="authentication_required"?null:h},...u?{settlement:u}:{}}}let O=p=>(a.has(p)||a.set(p,e?.run.identity.binding?.id??null),a.get(p));async function F(p){let S=r,I=e?.run.identity.binding?.id??null,q=P=>{if(I!==(e?.run.identity.binding?.id??null))throw P;return g(P)};if(p.operation==="page_experiments"){if(!t.adapter.pageExperiments)throw new s("CAPABILITY_UNAVAILABLE","Process page experiments are unavailable",501);return y(()=>t.adapter.pageExperiments(p.release,p.usedReceiptIds)).catch(q)}let h;if(p.operation==="get"){let{operation:P,customerToken:E,...i}=p;h=await y(()=>t.adapter.get({...i,...i.settlementRequestId?{settlementBindingId:O(i.settlementRequestId)}:{}})).catch(q)}else if(p.operation==="review")h=await y(()=>t.adapter.review(p.receiptId)).catch(q);else{if(p.operation==="start")throw new s("INVALID_REQUEST","Use process.open for entry");{let{customerToken:P,...E}=p;h=await y(()=>t.adapter.command(E,O(E.requestId))).catch(q)}}return l(h,S)}return{get view(){return e?.run??null},get controller(){return n},async open(p){let S=r,I=await y(()=>t.adapter.open(p)).catch(g),q=l(I,S);if(!n){n=M({...t,runToken:I.runToken,initialResponse:q,process:{request:F,binding:O,restore(E){for(let[i,c]of Object.entries(E))a.set(i,c)}}});let h=n,P=h.submit;h.submit=async E=>{try{return await P(E)}catch(i){if(!(i instanceof s)||i.reason!=="IDENTITY_CONTEXT_CHANGED"||E.operation!=="submit"||E.input.type!=="screen"||a.get(E.requestId)!==null)throw i;await h.settle?.(E.requestId),await h.get();let c=h.view;if(d.get(E.requestId)!==!1||!c||c.id!==e?.run.id||c.nodeId!==E.nodeId||c.visit!==E.visit||!e?.run.identity.binding)throw i;return P({...E,requestId:crypto.randomUUID(),revision:c.revision})}}}await n.get();for(let h of n.pendingCommands??[])a.has(h.requestId)&&a.get(h.requestId)!==(e?.run.identity.binding?.id??null)&&await n.settle?.(h.requestId);return{run:e.run,controller:n}},async syncIdentity(){let p=r;l(await y(()=>t.adapter.syncIdentity()).catch(g),p),await n?.get();for(let S of n?.pendingCommands??[])a.has(S.requestId)&&a.get(S.requestId)!==(e?.run.identity.binding?.id??null)&&await n?.settle?.(S.requestId);return e.run},async detach(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),await y(()=>t.adapter.detach())},forProcess(p){if(!e?.run.identity.binding)throw new s("UNAUTHENTICATED","Sign in before a commercial operation",401);return{runId:e.run.id,bindingId:e.run.identity.binding.id,receiptId:p}},subscribe(p){return o.add(p),()=>{o.delete(p)}},destroy(){r++,n?.reset(),n=void 0,e=null,a.clear(),d.clear(),o.clear()}}}export{xt as a,Ne as b,Mt as c,Kt as d};
@@ -1 +1 @@
1
- import{e as y}from"./chunk-CKMSSBJM.js";import{c as g}from"./chunk-S2S4ROGY.js";import{a as $}from"./chunk-EQBJNU6R.js";import{e as Y,f as X,g as Z,h as ee,i as re}from"./chunk-MOIVJERE.js";import{b as B}from"./chunk-PUDTOCQF.js";import{b as F}from"./chunk-FV7BUKOJ.js";import{b as j}from"./chunk-6XRQR43F.js";import{A as J,B as R,E as H,z as x}from"./chunk-3532HSBP.js";import{x as G}from"./chunk-67WFVDTV.js";import{b as W}from"./chunk-MXI4ANML.js";import{a as L}from"./chunk-KCUE2VFJ.js";import{t as K}from"./chunk-Y3W5G4BF.js";import{a}from"./chunk-UGATOG2T.js";import{a as z}from"./chunk-DSPLGTQI.js";function ae(I){let t=[...new Set(I.map(({path:s})=>{let c=s.map(String).join(".");return c.startsWith("selector")?"paywallId or paywallVersionId":c||"input"}))],O=t.includes("locale")?` Pass locale, the Customer's language such as "en" or "zh-CN".`:"";return new a("INVALID_REQUEST",`createPaywallSession input is invalid: ${t.join(", ")}.${O}`)}async function Ie(I,t){if(!L.test(t.customerToken))throw new a("INVALID_TOKEN","A verified Customer credential is required");if(I.session&&I.session.peek()!==t.customerToken)throw new a("SCOPE_MISMATCH","Paywall credential does not match the shared session");let O=y.resolvePaywall.request.safeParse({funnelId:t.funnelId,funnelVersionId:t.funnelVersionId,selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale,...t.requirement?{requirement:t.requirement}:{}});if(!O.success)throw ae(O.error.issues);let s=O.data,c=W(I);I.session||c.identify(t.customerToken);let n=null,b=!1,k=new AbortController,u=null,d=null,v=null,P=null,T=null,w=null,m=null,A=0,q=null,U="",D=0,C=new Map,E=new Set;function S(){if(b)throw new a("IDENTITY_CHANGED","Paywall is closed")}function M(){let e=JSON.stringify([A,m!==null]);if(!q||e!==U){U=e;let r=te(++D);q=r;let i=()=>{q===r&&(q=null)};r.then(i,i)}return q.then(r=>structuredClone(r))}async function te(e){S();let r=y.resolvePaywall,i=await g(c.request,r,{...s,selector:n?{type:"version",versionId:n.id}:s.selector});B(s,i.paywall.check,i.scope);let l=await F(I,i.paywall);if(S(),t.paywallVersionId?l.id!==t.paywallVersionId:l.paywallId!==t.paywallId)throw new a("INVALID_RESPONSE","The requested Paywall changed");if(n&&(!Y(l,n)||l.paywallId!==n.paywallId))throw new a("INVALID_RESPONSE","The pinned Paywall or Offering Version changed");if(e!==D)return structuredClone(n??l);n=l;for(let h of E)z(h,structuredClone(n));return structuredClone(n)}async function Q(e){if(S(),P&&e!=="read")throw new a("COMMAND_PENDING","Wait for the original quote");if(!u)throw new a("INVALID_REQUEST","A quoted purchase is required");let r=u;if(e!=="read"){if(m){if(w===e)return m;throw new a("COMMAND_PENDING","Wait for the original purchase command")}if(w&&w!==e)throw new a("COMMAND_PENDING","Read the original purchase before changing an uncertain command");w=e,A++,D++}let i=w,l=A,h=e==="read"&&m===null,f=JSON.stringify([r.operationId,l,m!==null]);if(e==="read"&&C.has(f))return C.get(f).then(o=>structuredClone(o));let p=(async()=>{let o={operationId:r.operationId,...e==="read"?{}:{intent:e},...e==="confirm"&&r.merchantTerms?{merchantConfirmation:G(r.merchantTerms)}:{}},V=R(r)?e==="read"?await g(c.request,y.readSubscriptionUpdate,o):await g(c.request,y.update,o):e==="read"?await g(c.request,y.readSubscriptionOperation,o):await g(c.request,y.attach,o),N=J.parse(V.operation);return N.quote&&ee(r,N.quote),X(N,{operationId:r.operationId,currency:s.commerce.currency,membershipId:R(r)?r.membershipId:null,...R(r)?{featureQuantities:r.featureQuantities??{}}:{}},"The purchase operation changed"),S(),u?.operationId!==r.operationId?structuredClone(N):(d=re(d,N),(e!=="read"||h&&m===null)&&A===l&&w===i&&(w=null),structuredClone(d))})();if(e!=="read"){m=p;let o=()=>{m===p&&(m=null)};p.then(o,o)}else{C.set(f,p);let o=()=>{C.get(f)===p&&C.delete(f)};p.then(o,o)}return p.then(o=>structuredClone(o))}let _={signal:k.signal,get view(){return n?structuredClone(n):null},get quote(){return u?structuredClone(u):null},get operation(){return d?structuredClone(d):null},get webViewUrl(){return"bundled"},get locale(){return s.locale},get recovery(){return $({quote:u,operation:d,requestId:T,pending:P!==null||w!==null,destroyed:b})},get pendingCancellation(){return!b&&w==="cancel"},refresh:M,subscribe(e){return b?()=>{}:(E.add(e),()=>E.delete(e))},async preview(e){if(S(),!n)throw new a("INVALID_REQUEST","Load the Paywall first");let r=n.document.buttons[e.actionId];if(r?.type!=="checkout")throw new a("INVALID_REQUEST","Choose an authored purchase action");let i=j(r.product,e.selection,n.capabilities);if(!i)throw new a("PRODUCT_UNAVAILABLE","Choose an available Product");let l=K(n.document.screen,i,e.selection,n.capabilities);if(s.commerce.intent==="subscription_change"&&!e.subscriptionChange)throw new a("INVALID_REQUEST","Choose the existing membership for this subscription change");if(e.subscriptionChange&&e.nativeOffer)throw new a("INVALID_REQUEST","A web membership change cannot include a store offer");let h=e.subscriptionChange?y.previewUpdate.request.parse({requestId:e.requestId,...e.subscriptionChange,change:{type:"plan",productVersionId:i,...Object.keys(l).length?{featureQuantities:l}:{}},...e.offerId?{offerId:e.offerId}:{}}):y.previewAttach.request.parse({funnelId:s.funnelId,funnelVersionId:s.funnelVersionId,requestId:e.requestId,plans:[{productVersionId:i,...Object.keys(l).length?{featureQuantities:l}:{}}],provider:s.commerce.provider,currency:s.commerce.currency,...e.offerId?{offerId:e.offerId}:{},...e.nativeOffer?{nativeOffer:e.nativeOffer}:{}}),f=JSON.stringify(h);if(v&&v!==f&&(P||w||!d||H(d)))throw new a("COMMAND_PENDING","Finish or cancel the original purchase before changing it");if(v===f){if(P)return P;if(u)return structuredClone(u)}v!==f&&(u=null,d=null),v=f,T=h.requestId;let p=(async()=>{let o="membershipId"in h?await g(c.request,y.previewUpdate,h):await g(c.request,y.previewAttach,h),V=x.parse(o.quote);return S(),Z(V,{productVersionId:i,featureQuantities:l,currency:s.commerce.currency,provider:s.commerce.provider,subscriptionChange:e.subscriptionChange},"The purchase quote changed its selected Product or presentment"),u=V,d=null,structuredClone(u)})();P=p;try{return await p}finally{P===p&&(P=null)}},confirm:()=>Q("confirm"),cancel:()=>Q("cancel"),read:()=>Q("read"),destroy(){b||(b=!0,k.abort(),E.clear(),C.clear(),ne?.(),c.dispose(),n=null,u=null,d=null,v=null,T=null)}},ne=I.session?.subscribeIdentity(_.destroy);try{return await M(),_}catch(e){throw _.destroy(),e}}export{Ie as a};
1
+ import{e as y}from"./chunk-CKMSSBJM.js";import{c as g}from"./chunk-S2S4ROGY.js";import{a as $}from"./chunk-EQBJNU6R.js";import{e as Y,f as X,g as Z,h as ee,i as re}from"./chunk-MOIVJERE.js";import{b as B}from"./chunk-PUDTOCQF.js";import{b as F}from"./chunk-3ZOUIESZ.js";import{b as j}from"./chunk-6XRQR43F.js";import{A as J,B as R,E as H,z as x}from"./chunk-3532HSBP.js";import{x as G}from"./chunk-67WFVDTV.js";import{b as W}from"./chunk-OJZWFIG3.js";import{a as L}from"./chunk-KCUE2VFJ.js";import{t as K}from"./chunk-Y3W5G4BF.js";import{a}from"./chunk-UGATOG2T.js";import{a as z}from"./chunk-DSPLGTQI.js";function ae(I){let t=[...new Set(I.map(({path:s})=>{let c=s.map(String).join(".");return c.startsWith("selector")?"paywallId or paywallVersionId":c||"input"}))],O=t.includes("locale")?` Pass locale, the Customer's language such as "en" or "zh-CN".`:"";return new a("INVALID_REQUEST",`createPaywallSession input is invalid: ${t.join(", ")}.${O}`)}async function Ie(I,t){if(!L.test(t.customerToken))throw new a("INVALID_TOKEN","A verified Customer credential is required");if(I.session&&I.session.peek()!==t.customerToken)throw new a("SCOPE_MISMATCH","Paywall credential does not match the shared session");let O=y.resolvePaywall.request.safeParse({funnelId:t.funnelId,funnelVersionId:t.funnelVersionId,selector:t.paywallVersionId?{type:"version",versionId:t.paywallVersionId}:{type:"paywall",paywallId:t.paywallId},commerce:t.commerce,locale:t.locale,...t.requirement?{requirement:t.requirement}:{}});if(!O.success)throw ae(O.error.issues);let s=O.data,c=W(I);I.session||c.identify(t.customerToken);let n=null,b=!1,k=new AbortController,u=null,d=null,v=null,P=null,T=null,w=null,m=null,A=0,q=null,U="",D=0,C=new Map,E=new Set;function S(){if(b)throw new a("IDENTITY_CHANGED","Paywall is closed")}function M(){let e=JSON.stringify([A,m!==null]);if(!q||e!==U){U=e;let r=te(++D);q=r;let i=()=>{q===r&&(q=null)};r.then(i,i)}return q.then(r=>structuredClone(r))}async function te(e){S();let r=y.resolvePaywall,i=await g(c.request,r,{...s,selector:n?{type:"version",versionId:n.id}:s.selector});B(s,i.paywall.check,i.scope);let l=await F(I,i.paywall);if(S(),t.paywallVersionId?l.id!==t.paywallVersionId:l.paywallId!==t.paywallId)throw new a("INVALID_RESPONSE","The requested Paywall changed");if(n&&(!Y(l,n)||l.paywallId!==n.paywallId))throw new a("INVALID_RESPONSE","The pinned Paywall or Offering Version changed");if(e!==D)return structuredClone(n??l);n=l;for(let h of E)z(h,structuredClone(n));return structuredClone(n)}async function Q(e){if(S(),P&&e!=="read")throw new a("COMMAND_PENDING","Wait for the original quote");if(!u)throw new a("INVALID_REQUEST","A quoted purchase is required");let r=u;if(e!=="read"){if(m){if(w===e)return m;throw new a("COMMAND_PENDING","Wait for the original purchase command")}if(w&&w!==e)throw new a("COMMAND_PENDING","Read the original purchase before changing an uncertain command");w=e,A++,D++}let i=w,l=A,h=e==="read"&&m===null,f=JSON.stringify([r.operationId,l,m!==null]);if(e==="read"&&C.has(f))return C.get(f).then(o=>structuredClone(o));let p=(async()=>{let o={operationId:r.operationId,...e==="read"?{}:{intent:e},...e==="confirm"&&r.merchantTerms?{merchantConfirmation:G(r.merchantTerms)}:{}},V=R(r)?e==="read"?await g(c.request,y.readSubscriptionUpdate,o):await g(c.request,y.update,o):e==="read"?await g(c.request,y.readSubscriptionOperation,o):await g(c.request,y.attach,o),N=J.parse(V.operation);return N.quote&&ee(r,N.quote),X(N,{operationId:r.operationId,currency:s.commerce.currency,membershipId:R(r)?r.membershipId:null,...R(r)?{featureQuantities:r.featureQuantities??{}}:{}},"The purchase operation changed"),S(),u?.operationId!==r.operationId?structuredClone(N):(d=re(d,N),(e!=="read"||h&&m===null)&&A===l&&w===i&&(w=null),structuredClone(d))})();if(e!=="read"){m=p;let o=()=>{m===p&&(m=null)};p.then(o,o)}else{C.set(f,p);let o=()=>{C.get(f)===p&&C.delete(f)};p.then(o,o)}return p.then(o=>structuredClone(o))}let _={signal:k.signal,get view(){return n?structuredClone(n):null},get quote(){return u?structuredClone(u):null},get operation(){return d?structuredClone(d):null},get webViewUrl(){return"bundled"},get locale(){return s.locale},get recovery(){return $({quote:u,operation:d,requestId:T,pending:P!==null||w!==null,destroyed:b})},get pendingCancellation(){return!b&&w==="cancel"},refresh:M,subscribe(e){return b?()=>{}:(E.add(e),()=>E.delete(e))},async preview(e){if(S(),!n)throw new a("INVALID_REQUEST","Load the Paywall first");let r=n.document.buttons[e.actionId];if(r?.type!=="checkout")throw new a("INVALID_REQUEST","Choose an authored purchase action");let i=j(r.product,e.selection,n.capabilities);if(!i)throw new a("PRODUCT_UNAVAILABLE","Choose an available Product");let l=K(n.document.screen,i,e.selection,n.capabilities);if(s.commerce.intent==="subscription_change"&&!e.subscriptionChange)throw new a("INVALID_REQUEST","Choose the existing membership for this subscription change");if(e.subscriptionChange&&e.nativeOffer)throw new a("INVALID_REQUEST","A web membership change cannot include a store offer");let h=e.subscriptionChange?y.previewUpdate.request.parse({requestId:e.requestId,...e.subscriptionChange,change:{type:"plan",productVersionId:i,...Object.keys(l).length?{featureQuantities:l}:{}},...e.offerId?{offerId:e.offerId}:{}}):y.previewAttach.request.parse({funnelId:s.funnelId,funnelVersionId:s.funnelVersionId,requestId:e.requestId,plans:[{productVersionId:i,...Object.keys(l).length?{featureQuantities:l}:{}}],provider:s.commerce.provider,currency:s.commerce.currency,...e.offerId?{offerId:e.offerId}:{},...e.nativeOffer?{nativeOffer:e.nativeOffer}:{}}),f=JSON.stringify(h);if(v&&v!==f&&(P||w||!d||H(d)))throw new a("COMMAND_PENDING","Finish or cancel the original purchase before changing it");if(v===f){if(P)return P;if(u)return structuredClone(u)}v!==f&&(u=null,d=null),v=f,T=h.requestId;let p=(async()=>{let o="membershipId"in h?await g(c.request,y.previewUpdate,h):await g(c.request,y.previewAttach,h),V=x.parse(o.quote);return S(),Z(V,{productVersionId:i,featureQuantities:l,currency:s.commerce.currency,provider:s.commerce.provider,subscriptionChange:e.subscriptionChange},"The purchase quote changed its selected Product or presentment"),u=V,d=null,structuredClone(u)})();P=p;try{return await p}finally{P===p&&(P=null)}},confirm:()=>Q("confirm"),cancel:()=>Q("cancel"),read:()=>Q("read"),destroy(){b||(b=!0,k.abort(),E.clear(),C.clear(),ne?.(),c.dispose(),n=null,u=null,d=null,v=null,T=null)}},ne=I.session?.subscribeIdentity(_.destroy);try{return await M(),_}catch(e){throw _.destroy(),e}}export{Ie as a};
@@ -0,0 +1 @@
1
+ import{o as n,r as t}from"./chunk-BSC3VAYP.js";function u(o,e,a){return n(o,e,a,t)}export{u as a};
@@ -1 +1 @@
1
- import{b as Rn}from"./chunk-J6ATQION.js";import{a as Pn}from"./chunk-M5TCDVMJ.js";import{a as jn,b as Zn,c as Cn,d as bn,e as Be,f as Kn,h as et,i as nt,j as tt,k as it}from"./chunk-CHRNCOXJ.js";import{a as rt}from"./chunk-7ZAM4YRK.js";import{a as Jn}from"./chunk-W32FI2A2.js";import{a as zn,d as Gn,f as Qn,g as Wn,j as Yn,k as _e,l as sn,m as Xn,n as an}from"./chunk-CO6HDNOC.js";import{b as xn}from"./chunk-F4AIEI5N.js";import{a as In,d as Bn}from"./chunk-EQBJNU6R.js";import{C as $n}from"./chunk-FYUMVOCV.js";import{a as ne}from"./chunk-UGATOG2T.js";import{a as ke}from"./chunk-DSPLGTQI.js";function ot(i){let E=new Set,q=new Set,n=null;async function u(o,p){let A=!1;for(;!i.stopped&&i.key===o&&i.client.pendingCommand?.requestId===p;){if(!i.client.settle)throw new ne("COMMAND_PENDING","The original display acknowledgement is still pending");await i.client.settle(p),A=!0,i.client.pendingCommand?.requestId===p&&await new Promise(v=>setTimeout(v,1500))}i.stopped||i.key!==o||(A&&await i.client.get(),!(i.stopped||i.key!==o)&&E.add(o))}function y(o,p){n=p;let A=()=>{n===p&&(n=null),q.delete(o)};return p.then(A,v=>{A(),i.busy||i.fail(v)}),p}function W(o){if(i.reviewing||E.has(o)||q.has(o)||i.stopped)return;q.add(o);let p=async()=>{if(i.reviewing||i.stopped||i.key!==o||E.has(o)){q.delete(o);return}if(i.busy||i.client.pendingCommand){setTimeout(()=>{p()},250);return}let A=(async()=>{if(i.staleRead){if(await i.staleRead,i.stopped||i.key!==o)return;if(i.client.pendingCommand){setTimeout(()=>{p()},250);return}}let v=i.client.view,de=i.expected(),O=de.requestId;try{await i.client.submit({operation:"shown",...de})}catch(k){if(!(k instanceof ne)||k.code!=="CONFLICT"||k.status!==409||i.client.pendingCommand)throw k;await i.client.get();let c=i.client.view;if(i.stopped||i.reviewing||i.key!==o||!c||!v||c.id!==v.id||c.source.versionId!==v.source.versionId||c.nodeId!==de.nodeId||c.visit!==de.visit||c.revision<=de.revision||c.stopped||!c.screen&&(!c.paywall||c.paywall.receiptId!==v.paywall?.receiptId)||!["running","waiting"].includes(c.status)||i.client.pendingCommand)throw k;let _=i.expected();O=_.requestId,await i.client.submit({operation:"shown",..._})}await u(o,O)})();y(o,A)};p()}function R(){if(n)return n;let o=i.client.pendingCommand;if(o?.operation!=="shown")return null;let p=i.key;return q.add(p),y(p,(async()=>{await i.client.retry(),await u(p,o.requestId)})())}return{report:W,settled:R,get inFlight(){return n}}}function st(i){let E={},q=new Map;async function n(u){let y=i.client.view,W=y?.screen,R=W?.customerData.nodes[u.nodeId];if(i.stopped||i.busy||!y||!W||!R)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(u.action)){let k=i.document,c=k?$n(k,u.nodeId):null,_=c?.type==="customer_data"?c.data.outputs?.[u.action]:void 0;_&&W.outputs.includes(_)?await i.perform(()=>i.client.submit({operation:"submit",...i.expected(),input:{type:"screen",output:_,answers:i.answers,selection:u.value?{[u.nodeId]:u.value}:{}}})):await i.onIntent?.(u,y);return}let p=u.action.startsWith("sources_")?R.resources.find(k=>k.key===u.value):null;if(u.action.startsWith("sources_")&&!p)throw new ne("INVALID_REQUEST","Choose a current resource");let A=`${y.visit}:${u.nodeId}:${p?.key??""}`,v=q.get(A)??[null],O=E[u.nodeId]??{page:1,after:null,filter:"all",...p?{resourceKey:p.key}:{}};if(u.action==="filter"){let k=u.value;if(!k||!(R.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new ne("INVALID_REQUEST","Unknown data filter");O={page:1,after:null,filter:k},v.splice(0,v.length,null)}else if(u.action==="next"||u.action==="sources_next"){let k=p?.sources.at(-1),c=p?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:W.dataCursors[u.nodeId];if(!c||!p&&!R.hasNext)return;v[O.page]=c,O={...O,page:O.page+1,after:c}}else if(u.action==="previous"||u.action==="sources_previous"){if(O.page<=1)return;O={...O,page:O.page-1,after:v[O.page-2]??null}}q.set(A,v),E={...E,[u.nodeId]:O},await i.perform(()=>i.client.get({nodeId:y.nodeId,visit:y.visit,revision:y.revision,components:E}))}return{get queries(){return E},intent:n,reset(){E={},q.clear()}}}function at(i){let{doc:E,holder:q,reviewHolder:n,mountScreenPreview:u}=i,y=!1,W,R=0,o=null,p="",A,v=new Map,de=c=>c?`${c.id}:${c.nodeId}:${c.visit}:${c.revision}:${c.paywall?.quote?.operationId??""}`:"";async function O(c){if(i.stopped||!i.client.review||y&&c===W&&A?.active)return;let _=!y||c!==W;y||(p=de(i.client.view),v.set(p,structuredClone(i.answers))),y=!0,W=c,q.hidden=!0,i.suspend(!0),n.hidden=!1;let ve=++R;_&&(A?.finish("dismissed"),o?.destroy(),o=null,n.replaceChildren(),A=sn(n,i.loadingOptions,"funnel",()=>{k()}));let g=_?A:void 0;try{if(g?.start(!1,i.client.view?.locale),ve!==R||i.stopped)return;let Ie=i.client.review(c),V=await(g?.wait(Ie,_e)??Ie);if(i.stopped||ve!==R||!y)return;if(!V.review)throw new ne("INVALID_RESPONSE","Historical projection is missing");o?.destroy(),o=null,g||n.replaceChildren();let d=E.createElement("div"),x=g?an(d,n):()=>{};n.append(d);let F=V.run.locale.startsWith("zh"),te=i.chrome;d.style.cssText=te.history;let ie=E.createElement("p");ie.textContent=F?"只读回看":"Read-only history",ie.style.cssText=te.historyTitle,d.append(ie);let me=E.createElement("p");me.style.cssText=te.historyNote,me.textContent=V.review.pages.length?F?"选择一页查看当时的内容,回看不会改动任何信息。":"Choose a page to see it as it was. Nothing here can be changed.":F?"还没有可回看的页面。":"There are no earlier pages yet.",d.append(me);let j=V.review.page?.receiptId,B=E.createElement("div");B.style.cssText=te.historyPages;for(let[m,U]of V.review.pages.entries()){let J=E.createElement("button");J.type="button",J.textContent=F?`第 ${m+1} 页`:`Page ${m+1}`;let ue=j!==void 0&&U.receiptId===j;J.style.cssText=ue?te.primary:te.secondary,ue&&J.setAttribute("aria-current","page"),Be(J,()=>i.chrome.focus),J.onclick=()=>{O(U.receiptId)},B.append(J)}if(B.childElementCount&&d.append(B),V.review.page){let m=V.review.page,U=E.createElement("div");U.inert=!0,U.style.cssText=te.historyPage,d.append(U),o=u(U,{mode:"live",rendererUrl:i.client.webViewUrl,title:m.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{ve===R&&!i.stopped&&g?.present(x)},onError:ue=>{if(ve!==R||i.stopped)return;let X=new Error(ue);g?.finish("error",X),o?.destroy(),o=null,d.remove(),i.fail(X)},onEscape:()=>{k()}});let J=o;if(J.update(m.document,V.run.locale,{serverInput:{bindings:m.inputs,answers:m.answers,values:m.values}}),await J.ready,i.stopped||ve!==R||!y)return}let D=F?{issued:"已领取",reserved:"已预留",redeemed:"已使用",expired:"已过期",revoked:"已撤销",unknown:"状态待确认"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},Y=E.createElement("div");Y.style.cssText=te.historyRecords;for(let m of[...V.review.coupons.map((U,J)=>`${F?"优惠券":"Coupon"} ${J+1}: ${D[U.status]}`),...V.review.purchases.map((U,J)=>`${F?"购买":"Purchase"} ${J+1}: ${it(U.status,F)}`)]){let U=E.createElement("p");U.textContent=m,U.style.margin="0",Y.append(U)}Y.childElementCount&&d.append(Y),V.review.page||g?.present(x),i.client.view&&await i.enqueue(i.client.view)}catch(Ie){if(ve!==R||i.stopped)return;g?.finish("error",Ie),o?.destroy(),o=null,n.replaceChildren(),i.fail(Ie)}}async function k(){if(!y||i.stopped||!i.client.review)return;let c=++R;A?.finish("dismissed");try{if(await i.client.review(),i.stopped||c!==R)return;y=!1,R++,A?.finish("dismissed"),o?.destroy(),o=null,n.replaceChildren(),n.hidden=!0,q.hidden=!1;let _=i.client.view;de(_)!==p?(v.set(p,structuredClone(i.answers)),i.resetScreen()):(v.delete(p),i.suspend(!1)),_&&await i.enqueue(_)}catch(_){if(c!==R||i.stopped)return;o?.destroy(),o=null,n.replaceChildren(),i.fail(_)}}return{get active(){return y},get receipt(){return W},open:O,exit:k,get drafts(){return new Map([...v].map(([c,_])=>[c,structuredClone(_)]))},stop(){y=!1,R++,A?.finish("dismissed"),o?.destroy(),o=null,n.replaceChildren(),n.hidden=!0,q.hidden=!1}}}var En=5e3,ft="position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap";async function mt(i,E,q){let n=E,u=n.prepared,y=u&&Rn(u),W=()=>{},R,o;function p(e){for(let t of R?.copies.values()??[])t!==e&&t.destroy();R=void 0}let A;function v(){u&&u.state!=="adopted"&&y?.release()}let de=()=>u?.state==="shown"&&!!y?.modal,O=n.client.identitySignal,k;try{k=await Promise.all([import("./screen-renderer-HJOKBOZH.js"),import("./paywall-TID3CHRR.js")]),n.signal?.throwIfAborted(),O?.throwIfAborted()}catch(e){throw v(),e}let[{mountScreenPreview:c},{showPaywall:_}]=k,ve=(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&n.appManifestRelease?rt({client:n.client,appManifestRelease:n.appManifestRelease,onError:n.onError}):void 0;ve?.start();let g=i.ownerDocument,Ie=Yn(g),V=!1,d=g.createElement("section"),x=g.createElement("div"),F=g.createElement("div"),te=g.createElement("div"),ie=g.createElement("button");te.hidden=!0,ie.type="button";let me=g.createElement("p"),j=g.createElement("p"),B=g.createElement("button"),D=g.createElement("button"),Y=g.createElement("button"),m=g.createElement("dialog"),U,J=!1;d.dataset.indianaFunnel="",d.dataset.longplayCloseOwner="sdk",d.setAttribute("aria-busy","false"),me.setAttribute("role","status"),j.setAttribute("role","alert"),j.hidden=!0,B.type=D.type=Y.type="button",F.append(B,ie,me,j,Y,D),d.append(x,te,F),i.append(d);let ue=Zn,X=Cn(ue),ln="",we=(g.documentElement.lang||"").startsWith("zh"),K,dn="",Je,kn=!1,un=!1;for(let e of[B,ie,Y,D])Be(e,()=>X.focus);function Fn(){let e=we?"关闭":"Close";D.parentElement===m?(D.textContent="×",D.setAttribute("aria-label",e),Wn(D,ue)):(D.textContent=e,D.removeAttribute("aria-label"),D.style.cssText=X.link+";margin-inline-start:auto")}function ze(e){let t=e?.screen?.content.document.theme??ue,r=JSON.stringify([t.primary,t.background,t.text,t.radius,t.font,D.parentElement===m]);if(r===ln)return;ln=r,ue=t;let b=D.parentElement===m;X=Cn(ue,b),d.style.cssText=X.root+";min-width:0"+(b?";display:flex;flex-direction:column;min-height:100%":""),F.style.cssText=Dn(),F.hidden&&(F.style.display="none"),B.style.cssText=ie.style.cssText=X.secondary,Y.style.cssText=X.primary,me.style.cssText=X.status,j.style.cssText=X.alert,Fn(),bn(B)}function Dn(){let e=D.parentElement===m,t=e&&K?.responsive===!0;return X.bar+(e?";margin-top:auto":"")+(t?`;position:sticky;bottom:0;z-index:1;background:${ue.background}`:"")+(un?`;${ft}`:"")}function Tn(){return F.hidden||un?0:F.getBoundingClientRect().height}function Fe(){let e=D.parentElement===m,t=B.hidden&&ie.hidden&&Y.hidden&&j.hidden&&(D.hidden||D.parentElement!==F);un=e&&kn&&!!t,F.hidden=t&&!me.textContent,F.style.cssText=Dn(),F.style.display=F.hidden?"none":"flex",K?.responsive&&Je!==void 0&&K.setContentHeight(Je+Tn())}ze();let pe=null,C=null,re=null,Ce="",ee="",De=!1,Ge="",cn="",Qe="",s=!1,G=0,We=!1,An="",pn=null,fn=Promise.resolve(),Sn=!n.client.view,Ve,mn=!1,T=q,je=n.hostPaywallTarget,Ne,Ue,Ye="",Xe,oe=!1,Te=null,ye=!1,Ze=()=>n.client.pendingCommand?.operation==="close",se=null,H=null,wn=Jn({document:g,run:async()=>{(!C?.observing||n.client.pendingCommand)&&await gn()},delay:()=>{if(!ae.pending&&!(s||!re||!["running","waiting"].includes(re.status)&&!n.client.pendingCommand)&&!(C?.observing&&!n.client.pendingCommand))return re.pendingRequest||n.client.pendingCommand?1500:En},hiddenDelay:()=>!s&&!ae.pending&&n.client.pendingCommand?15e3:void 0}),M=null;function yn(){return H&&n.client.hasDurableJournal===!0&&M?.acknowledged===!0&&M.operationId===H.operationId&&n.client.view?.id===M.runId&&n.client.view?.status==="closed"&&n.client.view.revision===M.revision+1&&!(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0))&&!n.client.pendingPurchase?H:null}function On(e){let t=e.run.paywall;if(M&&e.settlement?.requestId===M.requestId&&e.settlement.state==="settled"&&e.settlement.operationId===null&&e.run.id===M.runId&&e.run.status==="closed"&&!e.run.pendingRequest&&e.run.revision===M.revision+1&&e.run.nodeId===M.nodeId&&e.run.visit===M.visit&&t?.receiptId===M.receiptId&&t.selectionGeneration===M.selectionGeneration&&(t.quote?.operationId??null)===M.operationId&&(t.operation?.operationId??t.quote?.operationId??null)===M.operationId){let r=M.operationId===null&&t.selectionGeneration===0&&!t.quote&&!t.operation&&!t.purchaseRequestId,b=In({quote:t.quote,operation:t.operation,requestId:t.purchaseRequestId,pending:!1,destroyed:!1,canReselect:t.canReselect});(r||t.canReselect===!0&&b.type==="native")&&(M.acknowledged=!0)}}let Ae=null,Me=new Set,ge={},qe=!1,Z=(e,t=null)=>{s||(e instanceof ne&&e.status===409&&e.reason==="STATE_CHANGED"&&e.recovery==="recover_operation"&&wn.destroy(),Ae=t,qe=!1,j.textContent=Kn(e,we),j.hidden=!1,Y.hidden=n.client.pendingCommand===null,Fe(),ke(n.onError,e))},ae=xn({client:n.client,document:g,conceal(){s||(he(),T?.finish("dismissed"),d.hidden=!0,V||(V=!0,Ie()))},async receive(e){s||await ce(n.client.view??e.run)},failed(e){if(!s){if(!ae.pending){ye=!1;let t=n.client.view;t&&ce(t).then(()=>Z(e),Z);return}tn(),d.parentElement!==i&&i.append(d),d.hidden=!1,B.hidden=ie.hidden=D.hidden=!0,me.textContent="",ze(),Z(e,n.client.pendingCommand?.requestId??null)}}}),Nn=()=>{s||(Ae=null,j.textContent=nt(we),j.hidden=!1,Y.hidden=!0,Fe())};function Se(){let e=n.client.view;if(!e)throw new ne("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}let h=at({client:n.client,doc:g,holder:x,reviewHolder:te,mountScreenPreview:c,loadingOptions:n,get chrome(){return X},get stopped(){return s},get answers(){return ge},suspend(e){C?.setSuspended(e)},resetScreen(){Ce="",ee="",Ge=""},enqueue:ce,fail:Z}),$e=ot({client:n.client,expected:Se,fail:Z,get stopped(){return s},get reviewing(){return h.active},get key(){return Ce},get busy(){return G},get staleRead(){return pn}}),Ke=st({client:n.client,expected:Se,perform:He,onIntent:n.onCustomerDataIntent,get stopped(){return s},get busy(){return G},get document(){return pe?.document},get answers(){return ge}}),en=e=>`${e.id}:${e.nodeId}:${e.visit}`,Oe=e=>e&&(e.screen||e.paywall)?en(e):"";function be(){let e=n.client.view;B.disabled=!h.active&&(G>0||!!n.client.pendingCommand||!e?.canBack||e.stopped||!["running","waiting"].includes(e.status)||!Oe(e)||ee!==Oe(e)),B.hidden=!h.active&&!e?.canBack,bn(B);let t=!!C&&!h.active;D.hidden=t&&!T?.active||J&&!h.active,ie.hidden=!n.client.review||!h.active&&!e?.canBack;let r=e?.locale.startsWith("zh");kn=!t&&(G>0||!!e?.pendingRequest),me.textContent=t?"":G>0||e?.pendingRequest?r?"正在处理":"Processing":e?.instruction?.type==="wait"?r?"等待中":"Waiting":"",Fe()}async function qn(e){if(!e)return;let t=n.client.view;await e;let r=n.client.view;if(!t||!r||r.id!==t.id||r.nodeId!==t.nodeId||r.visit!==t.visit||r.stopped||!["running","waiting"].includes(r.status))throw new ne("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function He(e,t=!1,r){if(!((G||ye||se||H)&&!t||s||h.active&&!t)){G++,d.setAttribute("aria-busy","true"),j.hidden=!0,Ae=null,qe=!1,be();try{if(t||await qn($e.inFlight),s)return;let b=await e();s||await ce(n.client.view??b.run)}catch(b){r?.(b)&&n.client.pendingCommand===null?Nn():ae.pending||Z(b,n.client.pendingCommand?.requestId??null)}finally{G=Math.max(0,G-1),d.setAttribute("aria-busy",String(G>0)),s||(Y.hidden=n.client.pendingCommand===null,be())}}}function Le(){wn.schedule()}async function gn(){if(!(s||We||G)&&!ae.pending){if(h.active){await h.open(h.receipt);return}We=!0;try{let e=n.client.pendingCommand;e&&n.client.settle&&await n.client.settle(e.requestId);let t=n.client.view,r=Ke.queries,b=await n.client.get(t?.screen&&Object.keys(r).length?{nodeId:t.nodeId,visit:t.visit,revision:t.revision,components:r}:void 0);qe&&!s&&(qe=!1,j.hidden=!0,Fe()),!s&&r===Ke.queries&&await ce(n.client.view??b.run)}catch(e){Z(e),qe=!s}finally{We=!1}}}function nn(e,t,r){if(T?.active){let le=T;return le.setDismissHandler(()=>Hn(le)),le}let b=sn(i,n,"funnel",()=>Hn(b),jn);return T=b,b.start(e,t,r),b}function Hn(e){s||oe||(oe=!0,e.finish("dismissed"),he(),d.hidden=!0,n.client.view?Pe().finally(z):z())}function hn(){clearTimeout(Xe?.timeout),Xe=void 0}function he(e){J=!1,hn(),Ne?.abort(),Ne=void 0,pe?.destroy(),pe=null,C?.destroy(),C=null,Ve=void 0,Ue?.(),Ue=void 0,m.open&&m.close();for(let t of Array.from(x.children))(!e||!t.contains(e))&&t.remove();x.style.cssText="",Je=void 0,Ce="",ee="",De=!1,Ge="",Qe=""}function Ln(){let e=g.defaultView;K?.responsive&&e&&pe?.resizeViewport?.(e.innerHeight,e.innerWidth)}function tn(){K?.destroy(),K=void 0,dn=""}function rn(e){let t=e.screen?.presentation;if(!t||t.type==="inline"){m.open&&m.close(),tn(),D.parentElement!==F&&F.append(D),d.parentElement!==i&&i.append(d);for(let le of["flex","display","flex-direction","justify-content"])x.style.removeProperty(le);ze(e),Fe();return}d.parentElement!==m&&(m.append(D,d),i.append(m)),x.style.flex="1 0 auto",x.style.display="flex",x.style.flexDirection="column",x.style.justifyContent="center",ze(e);let r=e.screen.content.document,b=JSON.stringify([t,ln]);b!==dn&&(tn(),dn=b,m.style.cssText=zn("funnel",t,ue),K=Gn(m,{presentation:t,theme:r.theme,pages:r.pages},Ln),K.latch()),Fe(),m.setAttribute("aria-label",(U?.screen===e.screen?.content.document.name?U?.label:void 0)??pe?.document?.name??e.screen?.content.document.name??"Funnel")}async function lt(e){if(s||oe)return;if(ae.observe(),ae.pending){re=e;return}if(ye&&(Ze()||["running","waiting"].includes(e.status))||(re=e,Ae&&n.client.pendingCommand?.requestId!==Ae&&(j.hidden=!0,Ae=null),we=e.locale.startsWith("zh"),ie.textContent=we?"回看":"History",B.textContent=h.active?we?"返回当前":"Return to current":we?"返回":"Back",Fn(),Y.textContent=we?"重试":"Retry",Y.hidden=n.client.pendingCommand===null,be(),An!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(An=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,ke(n.onState,structuredClone(e))),s||oe))return;if((!e.pendingRequest||ye&&e.status==="closed")&&["closed","ineligible","failed"].includes(e.status)){z();return}if(e.stopped&&de()){z();return}if(e.stopped||n.client.configurationReady===!1){h.stop(),v(),he(),T?.finish("skipped"),d.hidden=!0,Le();return}if(d.hidden=!1,h.active){Le();return}if(e.status==="completed"&&C?.subscriptionUpgradeActive){Le();return}let t=Oe(e),r=n.client.view;if(r&&r.revision>e.revision&&Oe(r)!==t)return;let b=!e.instruction&&!e.pendingRequest&&e.nodeType==="screen"&&["running","waiting"].includes(e.status);t!==Ce&&(Ce&&T?.finish("dismissed"),he(),Ce=t,ge={...e.answers},Ke.reset());let le=en(e);if(Ye===le){d.hidden=!0;return}if(b&&!t){d.hidden=!0;let P=u?.state==="shown"?null:nn(!0,e.locale);!s&&!oe&&Xe?.key!==le&&(hn(),Xe={key:le,timeout:setTimeout(()=>{let l=n.client.view;if(s||!P?.active&&u?.state!=="shown"||!l||en(l)!==le)return;Ye=le;let S=new Error("Funnel screen preparation timed out");P?.finish("error",S),v(),he(),Z(S)},_e)}),Le();return}hn();let $=P=>{let l=n.client.view;return!s&&!oe&&!Te&&!P.aborted&&n.client.configurationReady!==!1&&!!l&&!l.stopped&&!["closed","ineligible","failed"].includes(l.status)&&(Oe(l)===t||l.status==="completed"&&C?.subscriptionUpgradeActive===!0)},Ee=(P,l)=>{$(l)&&(Ye=t,T?.finish("error",P),he(),d.hidden=!0,Z(P))};if(t||((e.instruction&&e.instruction.type!=="evaluate_segment"||!["running","waiting"].includes(e.status))&&v(),rn(e),e.instruction?.type!=="event"&&e.instruction?.type!=="open_url"&&T?.finish("skipped")),e.screen){if(mn=!0,je=void 0,v(),n.prepareNextPaywall&&R?.key!==t){p();let L=new Map;for(let[I,N]of Object.entries(e.screen.nextPaywalls??{})){if(!e.screen.outputs.includes(I))continue;let f=n.prepareNextPaywall({run:e,paywallVersionId:N.paywallVersionId});f&&L.set(I,f)}R={key:t,copies:L}}let P=e.screen.content;if(!pe){let L=e.screen.presentation.type!=="inline",I=nn(L,e.locale);if(s||oe)return;let N=(Ne=new AbortController).signal;rn(e),Ue=L?Xn(m):an(d,i),pe=c(x,{mode:"live",closeActions:Array.from(new Set([...n.closeActions??[],...P.document.actions.filter(f=>f.type==="event"&&f.close).map(f=>f.id)])),onAuthoredClose(f){$(N)&&(J=f,be())},rendererUrl:n.client.webViewUrl,title:P.document.name,...L?{hostPresentation:()=>K?.type??e.screen.presentation.type}:{},onResize:f=>{Je=f,K?.responsive&&K.setContentHeight(f+Tn())},onAction(f,a={},fe={}){if(h.active||!$(N)||ee!==t)return;ge={...ge,...fe};let vn=e.screen?.inputs??[],Mn=Object.fromEntries(vn.filter(({variable:Re})=>Object.hasOwn(ge,Re)).map(({variable:Re})=>[Re,ge[Re]]));if(tt(vn,Mn).length){Nn();return}let xe=!G&&R?.key===t?R.copies.get(f):void 0;xe?.state==="ready"&&xe.open()==="shown"&&(p(xe),v(),W(),u=xe,y=Rn(xe),W=y?.onClose(Vn)??(()=>{}),o=t),He(()=>n.client.submit({operation:"submit",...Se(),input:{type:"screen",output:f,answers:Mn,selection:a}}),!1,Re=>et(Re,vn)).finally(()=>{let Re=n.client.view;o===t&&(!Re||Oe(Re)===t)&&(o=void 0,v())})},onAnswers:f=>{h.active||!$(N)||ee!==t||(ge={...ge,...f})},onCustomerDataIntent:f=>{h.active||!$(N)||ee!==t||Ke.intent(f).catch(Z)},onEscape:()=>{!$(N)||ee!==t||h.active||se||H||Pe()},onError:f=>{let a=new Error(f);ee===t?Z(a):Ee(a,N)},onRendered:f=>{if(!(!$(N)||ee===t))try{I.present(a=>{Ue?.(),Ue=void 0,f&&(U={screen:P.document.name,label:f},m.setAttribute("aria-label",f)),L&&(m.showModal(),V=!1,K?.responsive&&m.focus({preventScroll:!0}),!a&&n.loading!=="host"&&Qn(m,K?.type??e.screen.presentation.type,K?.responsive)),ee=t,De=L,be()}),$(N)&&$e.report(t)}catch(a){Ee(a,N)}}}),Ln()}let l={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:ge,values:e.screen.values}},S=JSON.stringify([P,e.locale,l.parameters,e.screen.inputs,e.screen.values]);if(S!==Ge)pe.update(P.document,e.locale,l),Ge=S,cn=JSON.stringify(l.capabilities),Qe=JSON.stringify(l.customerData);else{let L=JSON.stringify(l.capabilities);L!==cn&&(pe.updateCapabilities(l.capabilities),cn=L),JSON.stringify(l.customerData)!==Qe&&(pe.updateCustomerData(l.customerData),Qe=JSON.stringify(l.customerData))}let Q=pe;if(Q)try{await(T?.wait(Q.ready)??Q.ready)}catch(L){Ne&&Ee(L,Ne.signal)}}else if(e.paywall&&!C){mn=!0,p();let P=e.paywall.resolution,l="document"in P?P.document:null,S=y,Q=n.mountPaywallControls,L=null,I=(Ne=new AbortController).signal,N={loading:"host",signal:I,...Q&&{mountControls:a=>Q(a,e)},canInteract:()=>$(I)&&!h.active&&!se&&!H,beforeAction:async()=>{G++;try{await qn($e.settled()),j.hidden=!0,Ae=null,qe=!1,Fe()}finally{G=Math.max(0,G-1)}},start:async()=>{let a=await Pn(n.client),fe=A;return A=void 0,a.view&&fe?.(a.view),a},onObservationChange:Le,...n.onPurchaseIntent&&{onPurchaseIntent:a=>n.onPurchaseIntent(a,structuredClone(e))},onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resumeCheckout:n.resumeCheckout,allowNewPurchase:n.allowNewPurchase,checkoutNavigation:n.checkoutNavigation,terminateCheckout:n.terminateCheckout,beforeCheckoutReplacement:n.beforeCheckoutReplacement,purchaseConfirmation:n.purchaseConfirmation,confirmOnHostedCheckout:n.confirmOnHostedCheckout,resolveOfferId:n.resolveOfferId,prepareSubscriptionChange:n.prepareSubscriptionChange,resolveSubscriptionChange:n.resolveSubscriptionChange,claimCoupon:n.claimCoupon,onEvent:n.onEvent,onOpenUrl:a=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:a,openIn:"same_window"}):g.defaultView?.location.assign(a),onAction:async a=>{if(h.active)return;let fe=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:a,answers:{}}});await ce(n.client.view??fe.run)},onError:a=>{ee===t?Z(a):Ee(a,I)}},f={quoteError:a=>ke(n.onError,a),present(a){$(I)&&(L?.present(fe=>{a(fe),ee=t,De=f.retainedDialog?.dialog.open??!!x.querySelector("dialog[open]"),De&&(V=!1),be()}),$(I)&&$e.report(t))},async closeAction(a){s||h.active||await ae.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:a,answers:{}}})},async dismiss(){if(s||I.aborted||h.active||se||H||!ye&&!$(I))return;ye=!0;let a=n.client.view;if(a?.status==="completed"&&C?.subscriptionUpgradeActive){Me.add(`complete:${a.id}`),ke(n.onComplete,structuredClone(a)),z();return}if((n.resumeCheckout||n.terminateCheckout)&&pt()){re=n.client.view,z();return}await Pe()}};if(S&&Q)v();else if(S){let a=await S.adopt(e,{options:N,handoff:f,start:()=>Pn(n.client)});o=void 0,a&&$(I)&&!s?(rn(e),C=a,Ve={runId:e.id,receiptId:e.paywall.receiptId},T?.active&&T.present(()=>{}),ee=t,De=S.modal,De&&(V=!1),be(),$e.report(t),h.active&&C.setSuspended(!0)):(a?.destroy(),v(),A=fe=>y?.remember(fe))}if(s||oe)return;if(!C){if(L=nn(!0,e.locale,l),s||oe)return;(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&n.loading==="host"&&je?.ownerDocument===g&&(f.hostPaywallTarget=je),je=void 0,rn(e);let a=await _(x,N,f).catch(fe=>(Ee(fe,I),null));!$(I)&&!(ye&&!s&&!I.aborted)?a?.host?.destroy():a&&(C=a.host,C&&(Ve={runId:e.id,receiptId:e.paywall.receiptId}),C?.setSuspended(h.active))}}if(s||oe)return;be();let w=e.instruction;if(w&&(w.type==="open_url"||w.type==="event")&&!Me.has(w.receiptId)){let P=g.createElement("button");P.type="button",P.style.cssText=X.primary,Be(P,()=>X.focus),x.style.cssText=X.stage,P.textContent=w.type==="open_url"?`${we?"前往":"Continue to"} ${new URL(w.url).host}`:we?"继续":"Continue",P.onclick=()=>{let l=Se(),S=w.type==="open_url"&&!n.onOpenUrl&&w.openIn==="new_window"?dt(w.url):null;He(async()=>{let Q="success";if(w.type==="open_url")if(n.onOpenUrl)try{Q=await n.onOpenUrl({receiptId:w.receiptId,url:w.url,openIn:w.openIn})===!1?"failed":"opened"}catch(I){ke(n.onError,I),Q="failed"}else Q=w.openIn==="new_window"&&!S?"failed":"opened";if(w.type==="event"){if(!n.onEvent)throw new ne("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(w.event)}if(s||n.client.view?.nodeId!==l.nodeId||n.client.view.visit!==l.visit)throw new ne("PRECONDITION_FAILED","The client action visit changed");let L=await n.client.submit({operation:"submit",...l,input:{type:"client_action",receiptId:w.receiptId,outcome:Q}});return Me.add(w.receiptId),w.type==="open_url"&&!n.onOpenUrl&&w.openIn==="same_window"&&g.defaultView?.location.assign(w.url),L})},T?.active?T.present(()=>x.replaceChildren(P)):x.replaceChildren(P)}!e.pendingRequest&&e.status==="completed"&&!Me.has(`complete:${e.id}`)&&(Me.add(`complete:${e.id}`),ke(n.onComplete,structuredClone(e))),Le()}function dt(e){let t=g.defaultView?.open(e,"_blank")??null;return t&&(t.opener=null),t}function ce(e){return be(),fn=fn.catch(()=>{}).then(async()=>{try{await lt(e)}catch(t){throw T?.active&&(Ye=en(e),T.finish("error",t),he(),d.hidden=!0),t}}),fn}let ut=n.client.subscribe(e=>{if(!Sn){if(e.stopped&&(De||de())&&!ye){re=e,z();return}!ye&&(e.stopped||n.client.configurationReady===!1||Ce&&ee!==Ce&&(Oe(e)!==Ce||["closed","ineligible","failed"].includes(e.status)))&&(he(),T?.finish("dismissed"),d.hidden=!0),ce(e).catch(Z)}}),ct=n.client.subscribeError?.(e=>{ae.pending||Z(e)});function pt(){let e=n.client.view,t=e?.paywall;return!!t?.operation&&!!e&&["running","waiting"].includes(e.status)&&Bn(In({quote:t.quote,operation:t.operation,requestId:t.purchaseRequestId,pending:!1,destroyed:!1,canReselect:t.canReselect}))}function Pe(e){if(Te)return Te;if(s||!e&&(se||H))return Promise.resolve();let t=!e&&Ze();return!t&&n.client.view&&!["running","waiting"].includes(n.client.view.status)?(re=n.client.view,z(),Promise.resolve()):(Te=He(async()=>{let r=t?await n.client.retry():await(e?n.client.submit.bind(n.client):ae.submit)({operation:"close",...e??Se()});return e&&On(r),r},!0).then(()=>{let r=n.client.view;r?.status==="closed"&&!Ze()&&(re=r,z())}).finally(()=>{Te=null}),Te)}function z(){_n()}function _n(e){ve?.destroy(),!s&&(s=!0,ae.destroy(),W(),p(),!mn&&(re?.status==="ineligible"||re?.status==="completed")&&y?.withhold(),v(),n.signal?.removeEventListener("abort",z),O?.removeEventListener("abort",z),T?.finish("dismissed"),wn.destroy(),ut(),ct?.(),he(e),tn(),h.stop(),m.remove(),!e||!d.contains(e)?d.remove():(F.remove(),te.remove()),!e&&!V&&Ie(),ke(n.onDismiss,re?structuredClone(re):null))}B.onclick=()=>{if(!B.disabled){if(h.active){h.exit();return}He(()=>n.client.submit({operation:"back",...Se()}))}},ie.onclick=()=>{h.open()},D.onclick=()=>{T?.active?T.dismiss():se||Pe()},Y.onclick=()=>{ae.pending?ae.retry().catch(()=>{}):Ze()?Pe():He(()=>n.client.retry())},m.addEventListener("cancel",e=>{e.preventDefault(),T?.active?T.dismiss():se||Pe()}),n.signal?.addEventListener("abort",z,{once:!0}),O?.addEventListener("abort",z,{once:!0});let on=!1;function Vn(){s||oe||(oe=!0,T?.finish("dismissed"),he(),d.hidden=!0,n.client.view?Pe().finally(z):on=!0)}y&&(W=y.onClose(Vn));let Un={destroy:z,refresh:gn,get recoveryPaywall(){if(C&&Ve)return{...Ve,view:C.currentResolution}},setPurchaseRecovery(e,t){return C?.setPurchaseRecovery(e,t),C!==null},retainPurchaseDialog(){let e=C?.retainPurchaseDialog();if(e)return C=null,_n(e.dialog),{dialog:e.dialog,release(){e.release(),d.remove(),V||Ie()}}},get recovery(){let e=yn();if(e)return e;if(!s&&!G&&!ye&&!se&&C){let t=C.recovery;if(t.type!=="native")return t}return{type:"recover",operationId:n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??H?.operationId??null,requestId:n.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let e=yn();if(e)return Promise.resolve(e);let t=n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??H?.operationId??null,r=()=>({type:"recover",operationId:t,requestId:n.client.pendingCommand?.requestId??null});if(n.client.hasDurableJournal!==!0){let w=C?.recovery;return Promise.resolve(w&&w.type!=="native"&&w.type!=="cancel"?w:r())}let b=(n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[])).some(w=>w.operation==="close");if(s&&!(b||H&&n.client.view?.status==="closed")||G||We||Te||h.active||!C&&!H&&!b)return Promise.resolve(r());let le=C,$=(async()=>{try{if(!H&&b){let l=await n.client.retry();return await ce(n.client.view??l.run),r()}if(!H){let l=await le.prepareFallback();if(l.type!=="native")return l;if(n.client.hasDurableJournal!==!0)return r();H=l}let w=n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[]);if(w.length){let l=w.find(Q=>Q.operation==="close");if(!l||!M||l.requestId!==M.requestId)return r();let S=await n.client.retry();On(S),await ce(n.client.view??S.run)}else{let l=n.client.view,S=l?.paywall;if(!l||!S||S.selectionGeneration===void 0||(S.quote?.operationId??null)!==H.operationId||H.operationId!==null&&S.canReselect!==!0)return r();let Q=S.selectionGeneration,L=await n.client.get();await ce(n.client.view??L.run);let I=n.client.view,N=I?.paywall;if(!I||!N||!["running","waiting"].includes(I.status)||I.stopped||I.id!==l.id||I.nodeId!==l.nodeId||I.visit!==l.visit||N.receiptId!==S.receiptId||N.selectionGeneration!==Q||(N.quote?.operationId??null)!==H.operationId||H.operationId!==null&&N.canReselect!==!0||n.client.pendingPurchase||(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0)))return r();let f=Se();M={runId:I.id,operationId:H.operationId,revision:f.revision,requestId:f.requestId,nodeId:I.nodeId,visit:I.visit,receiptId:N.receiptId,selectionGeneration:Q,acknowledged:!1},await Pe(f)}let P=yn();return P?(z(),P):r()}catch(w){return Z(w),r()}})();se=$;let Ee=()=>{se===$&&(se=null)};return $.then(Ee,Ee),$},review:h.open,exitReview:h.exit,get unappliedDrafts(){return h.drafts}};try{let e=n.client.view;if(e)((n.client.viewAgeMs??En)>=En||e.instruction?.type==="evaluate_segment")&&(pn=gn().finally(()=>{pn=null})),await ce(e);else{if(d.hidden=!0,s)throw new DOMException("Presentation cancelled","AbortError");let t=on||u?.state==="shown"?null:nn(n.client.view?.screen?.presentation.type!=="inline",n.client.view?.locale);if(s||oe&&!on)throw new DOMException("Presentation cancelled","AbortError");let r=n.client.get(),b=await(t?t.wait(r,_e):wt(r,_e));if(Sn=!1,on)return s||await Pe().finally(z),Un;await ce(n.client.view??b.run)}}catch(e){throw T?.finish("error",e),z(),e}return Un}function wt(i,E){let q;return Promise.race([i,new Promise((n,u)=>{q=setTimeout(()=>u(new Error("Presentation data timed out")),E)})]).finally(()=>clearTimeout(q))}function zt(i,E,q){return mt(i,E,q)}export{mt as a,zt as b};
1
+ import{b as Rn}from"./chunk-V7QPMA2C.js";import{a as Pn}from"./chunk-M5TCDVMJ.js";import{a as jn,b as Zn,c as Cn,d as bn,e as Be,f as Kn,h as et,i as nt,j as tt,k as it}from"./chunk-CHRNCOXJ.js";import{a as rt}from"./chunk-7ZAM4YRK.js";import{a as Jn}from"./chunk-W32FI2A2.js";import{a as zn,d as Gn,f as Qn,g as Wn,j as Yn,k as _e,l as sn,m as Xn,n as an}from"./chunk-CO6HDNOC.js";import{b as xn}from"./chunk-F4AIEI5N.js";import{a as In,d as Bn}from"./chunk-EQBJNU6R.js";import{C as $n}from"./chunk-FYUMVOCV.js";import{a as ne}from"./chunk-UGATOG2T.js";import{a as ke}from"./chunk-DSPLGTQI.js";function ot(i){let E=new Set,q=new Set,n=null;async function u(o,p){let A=!1;for(;!i.stopped&&i.key===o&&i.client.pendingCommand?.requestId===p;){if(!i.client.settle)throw new ne("COMMAND_PENDING","The original display acknowledgement is still pending");await i.client.settle(p),A=!0,i.client.pendingCommand?.requestId===p&&await new Promise(v=>setTimeout(v,1500))}i.stopped||i.key!==o||(A&&await i.client.get(),!(i.stopped||i.key!==o)&&E.add(o))}function y(o,p){n=p;let A=()=>{n===p&&(n=null),q.delete(o)};return p.then(A,v=>{A(),i.busy||i.fail(v)}),p}function W(o){if(i.reviewing||E.has(o)||q.has(o)||i.stopped)return;q.add(o);let p=async()=>{if(i.reviewing||i.stopped||i.key!==o||E.has(o)){q.delete(o);return}if(i.busy||i.client.pendingCommand){setTimeout(()=>{p()},250);return}let A=(async()=>{if(i.staleRead){if(await i.staleRead,i.stopped||i.key!==o)return;if(i.client.pendingCommand){setTimeout(()=>{p()},250);return}}let v=i.client.view,de=i.expected(),O=de.requestId;try{await i.client.submit({operation:"shown",...de})}catch(k){if(!(k instanceof ne)||k.code!=="CONFLICT"||k.status!==409||i.client.pendingCommand)throw k;await i.client.get();let c=i.client.view;if(i.stopped||i.reviewing||i.key!==o||!c||!v||c.id!==v.id||c.source.versionId!==v.source.versionId||c.nodeId!==de.nodeId||c.visit!==de.visit||c.revision<=de.revision||c.stopped||!c.screen&&(!c.paywall||c.paywall.receiptId!==v.paywall?.receiptId)||!["running","waiting"].includes(c.status)||i.client.pendingCommand)throw k;let _=i.expected();O=_.requestId,await i.client.submit({operation:"shown",..._})}await u(o,O)})();y(o,A)};p()}function R(){if(n)return n;let o=i.client.pendingCommand;if(o?.operation!=="shown")return null;let p=i.key;return q.add(p),y(p,(async()=>{await i.client.retry(),await u(p,o.requestId)})())}return{report:W,settled:R,get inFlight(){return n}}}function st(i){let E={},q=new Map;async function n(u){let y=i.client.view,W=y?.screen,R=W?.customerData.nodes[u.nodeId];if(i.stopped||i.busy||!y||!W||!R)return;if(!["refresh","next","previous","filter","sources_next","sources_previous"].includes(u.action)){let k=i.document,c=k?$n(k,u.nodeId):null,_=c?.type==="customer_data"?c.data.outputs?.[u.action]:void 0;_&&W.outputs.includes(_)?await i.perform(()=>i.client.submit({operation:"submit",...i.expected(),input:{type:"screen",output:_,answers:i.answers,selection:u.value?{[u.nodeId]:u.value}:{}}})):await i.onIntent?.(u,y);return}let p=u.action.startsWith("sources_")?R.resources.find(k=>k.key===u.value):null;if(u.action.startsWith("sources_")&&!p)throw new ne("INVALID_REQUEST","Choose a current resource");let A=`${y.visit}:${u.nodeId}:${p?.key??""}`,v=q.get(A)??[null],O=E[u.nodeId]??{page:1,after:null,filter:"all",...p?{resourceKey:p.key}:{}};if(u.action==="filter"){let k=u.value;if(!k||!(R.source==="offer_history"?["all","issued","reserved","redeemed","expired","revoked"]:["all","purchase","refund","source","usage","debt","settlement"]).includes(k))throw new ne("INVALID_REQUEST","Unknown data filter");O={page:1,after:null,filter:k},v.splice(0,v.length,null)}else if(u.action==="next"||u.action==="sources_next"){let k=p?.sources.at(-1),c=p?k?{kind:"ledger",cursor:{at:k.detail[0],id:k.id,type:"source"}}:null:W.dataCursors[u.nodeId];if(!c||!p&&!R.hasNext)return;v[O.page]=c,O={...O,page:O.page+1,after:c}}else if(u.action==="previous"||u.action==="sources_previous"){if(O.page<=1)return;O={...O,page:O.page-1,after:v[O.page-2]??null}}q.set(A,v),E={...E,[u.nodeId]:O},await i.perform(()=>i.client.get({nodeId:y.nodeId,visit:y.visit,revision:y.revision,components:E}))}return{get queries(){return E},intent:n,reset(){E={},q.clear()}}}function at(i){let{doc:E,holder:q,reviewHolder:n,mountScreenPreview:u}=i,y=!1,W,R=0,o=null,p="",A,v=new Map,de=c=>c?`${c.id}:${c.nodeId}:${c.visit}:${c.revision}:${c.paywall?.quote?.operationId??""}`:"";async function O(c){if(i.stopped||!i.client.review||y&&c===W&&A?.active)return;let _=!y||c!==W;y||(p=de(i.client.view),v.set(p,structuredClone(i.answers))),y=!0,W=c,q.hidden=!0,i.suspend(!0),n.hidden=!1;let ve=++R;_&&(A?.finish("dismissed"),o?.destroy(),o=null,n.replaceChildren(),A=sn(n,i.loadingOptions,"funnel",()=>{k()}));let g=_?A:void 0;try{if(g?.start(!1,i.client.view?.locale),ve!==R||i.stopped)return;let Ie=i.client.review(c),V=await(g?.wait(Ie,_e)??Ie);if(i.stopped||ve!==R||!y)return;if(!V.review)throw new ne("INVALID_RESPONSE","Historical projection is missing");o?.destroy(),o=null,g||n.replaceChildren();let d=E.createElement("div"),x=g?an(d,n):()=>{};n.append(d);let F=V.run.locale.startsWith("zh"),te=i.chrome;d.style.cssText=te.history;let ie=E.createElement("p");ie.textContent=F?"只读回看":"Read-only history",ie.style.cssText=te.historyTitle,d.append(ie);let me=E.createElement("p");me.style.cssText=te.historyNote,me.textContent=V.review.pages.length?F?"选择一页查看当时的内容,回看不会改动任何信息。":"Choose a page to see it as it was. Nothing here can be changed.":F?"还没有可回看的页面。":"There are no earlier pages yet.",d.append(me);let j=V.review.page?.receiptId,B=E.createElement("div");B.style.cssText=te.historyPages;for(let[m,U]of V.review.pages.entries()){let J=E.createElement("button");J.type="button",J.textContent=F?`第 ${m+1} 页`:`Page ${m+1}`;let ue=j!==void 0&&U.receiptId===j;J.style.cssText=ue?te.primary:te.secondary,ue&&J.setAttribute("aria-current","page"),Be(J,()=>i.chrome.focus),J.onclick=()=>{O(U.receiptId)},B.append(J)}if(B.childElementCount&&d.append(B),V.review.page){let m=V.review.page,U=E.createElement("div");U.inert=!0,U.style.cssText=te.historyPage,d.append(U),o=u(U,{mode:"live",rendererUrl:i.client.webViewUrl,title:m.document.name,onAction:()=>{},onAnswers:()=>{},onCustomerDataIntent:()=>{},onRendered:()=>{ve===R&&!i.stopped&&g?.present(x)},onError:ue=>{if(ve!==R||i.stopped)return;let X=new Error(ue);g?.finish("error",X),o?.destroy(),o=null,d.remove(),i.fail(X)},onEscape:()=>{k()}});let J=o;if(J.update(m.document,V.run.locale,{serverInput:{bindings:m.inputs,answers:m.answers,values:m.values}}),await J.ready,i.stopped||ve!==R||!y)return}let D=F?{issued:"已领取",reserved:"已预留",redeemed:"已使用",expired:"已过期",revoked:"已撤销",unknown:"状态待确认"}:{issued:"Issued",reserved:"Reserved",redeemed:"Used",expired:"Expired",revoked:"Revoked",unknown:"Status unconfirmed"},Y=E.createElement("div");Y.style.cssText=te.historyRecords;for(let m of[...V.review.coupons.map((U,J)=>`${F?"优惠券":"Coupon"} ${J+1}: ${D[U.status]}`),...V.review.purchases.map((U,J)=>`${F?"购买":"Purchase"} ${J+1}: ${it(U.status,F)}`)]){let U=E.createElement("p");U.textContent=m,U.style.margin="0",Y.append(U)}Y.childElementCount&&d.append(Y),V.review.page||g?.present(x),i.client.view&&await i.enqueue(i.client.view)}catch(Ie){if(ve!==R||i.stopped)return;g?.finish("error",Ie),o?.destroy(),o=null,n.replaceChildren(),i.fail(Ie)}}async function k(){if(!y||i.stopped||!i.client.review)return;let c=++R;A?.finish("dismissed");try{if(await i.client.review(),i.stopped||c!==R)return;y=!1,R++,A?.finish("dismissed"),o?.destroy(),o=null,n.replaceChildren(),n.hidden=!0,q.hidden=!1;let _=i.client.view;de(_)!==p?(v.set(p,structuredClone(i.answers)),i.resetScreen()):(v.delete(p),i.suspend(!1)),_&&await i.enqueue(_)}catch(_){if(c!==R||i.stopped)return;o?.destroy(),o=null,n.replaceChildren(),i.fail(_)}}return{get active(){return y},get receipt(){return W},open:O,exit:k,get drafts(){return new Map([...v].map(([c,_])=>[c,structuredClone(_)]))},stop(){y=!1,R++,A?.finish("dismissed"),o?.destroy(),o=null,n.replaceChildren(),n.hidden=!0,q.hidden=!1}}}var En=5e3,ft="position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap";async function mt(i,E,q){let n=E,u=n.prepared,y=u&&Rn(u),W=()=>{},R,o;function p(e){for(let t of R?.copies.values()??[])t!==e&&t.destroy();R=void 0}let A;function v(){u&&u.state!=="adopted"&&y?.release()}let de=()=>u?.state==="shown"&&!!y?.modal,O=n.client.identitySignal,k;try{k=await Promise.all([import("./screen-renderer-HJOKBOZH.js"),import("./paywall-CMDMDGJ4.js")]),n.signal?.throwIfAborted(),O?.throwIfAborted()}catch(e){throw v(),e}let[{mountScreenPreview:c},{showPaywall:_}]=k,ve=(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&n.appManifestRelease?rt({client:n.client,appManifestRelease:n.appManifestRelease,onError:n.onError}):void 0;ve?.start();let g=i.ownerDocument,Ie=Yn(g),V=!1,d=g.createElement("section"),x=g.createElement("div"),F=g.createElement("div"),te=g.createElement("div"),ie=g.createElement("button");te.hidden=!0,ie.type="button";let me=g.createElement("p"),j=g.createElement("p"),B=g.createElement("button"),D=g.createElement("button"),Y=g.createElement("button"),m=g.createElement("dialog"),U,J=!1;d.dataset.indianaFunnel="",d.dataset.longplayCloseOwner="sdk",d.setAttribute("aria-busy","false"),me.setAttribute("role","status"),j.setAttribute("role","alert"),j.hidden=!0,B.type=D.type=Y.type="button",F.append(B,ie,me,j,Y,D),d.append(x,te,F),i.append(d);let ue=Zn,X=Cn(ue),ln="",we=(g.documentElement.lang||"").startsWith("zh"),K,dn="",Je,kn=!1,un=!1;for(let e of[B,ie,Y,D])Be(e,()=>X.focus);function Fn(){let e=we?"关闭":"Close";D.parentElement===m?(D.textContent="×",D.setAttribute("aria-label",e),Wn(D,ue)):(D.textContent=e,D.removeAttribute("aria-label"),D.style.cssText=X.link+";margin-inline-start:auto")}function ze(e){let t=e?.screen?.content.document.theme??ue,r=JSON.stringify([t.primary,t.background,t.text,t.radius,t.font,D.parentElement===m]);if(r===ln)return;ln=r,ue=t;let b=D.parentElement===m;X=Cn(ue,b),d.style.cssText=X.root+";min-width:0"+(b?";display:flex;flex-direction:column;min-height:100%":""),F.style.cssText=Dn(),F.hidden&&(F.style.display="none"),B.style.cssText=ie.style.cssText=X.secondary,Y.style.cssText=X.primary,me.style.cssText=X.status,j.style.cssText=X.alert,Fn(),bn(B)}function Dn(){let e=D.parentElement===m,t=e&&K?.responsive===!0;return X.bar+(e?";margin-top:auto":"")+(t?`;position:sticky;bottom:0;z-index:1;background:${ue.background}`:"")+(un?`;${ft}`:"")}function Tn(){return F.hidden||un?0:F.getBoundingClientRect().height}function Fe(){let e=D.parentElement===m,t=B.hidden&&ie.hidden&&Y.hidden&&j.hidden&&(D.hidden||D.parentElement!==F);un=e&&kn&&!!t,F.hidden=t&&!me.textContent,F.style.cssText=Dn(),F.style.display=F.hidden?"none":"flex",K?.responsive&&Je!==void 0&&K.setContentHeight(Je+Tn())}ze();let pe=null,C=null,re=null,Ce="",ee="",De=!1,Ge="",cn="",Qe="",s=!1,G=0,We=!1,An="",pn=null,fn=Promise.resolve(),Sn=!n.client.view,Ve,mn=!1,T=q,je=n.hostPaywallTarget,Ne,Ue,Ye="",Xe,oe=!1,Te=null,ye=!1,Ze=()=>n.client.pendingCommand?.operation==="close",se=null,H=null,wn=Jn({document:g,run:async()=>{(!C?.observing||n.client.pendingCommand)&&await gn()},delay:()=>{if(!ae.pending&&!(s||!re||!["running","waiting"].includes(re.status)&&!n.client.pendingCommand)&&!(C?.observing&&!n.client.pendingCommand))return re.pendingRequest||n.client.pendingCommand?1500:En},hiddenDelay:()=>!s&&!ae.pending&&n.client.pendingCommand?15e3:void 0}),M=null;function yn(){return H&&n.client.hasDurableJournal===!0&&M?.acknowledged===!0&&M.operationId===H.operationId&&n.client.view?.id===M.runId&&n.client.view?.status==="closed"&&n.client.view.revision===M.revision+1&&!(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0))&&!n.client.pendingPurchase?H:null}function On(e){let t=e.run.paywall;if(M&&e.settlement?.requestId===M.requestId&&e.settlement.state==="settled"&&e.settlement.operationId===null&&e.run.id===M.runId&&e.run.status==="closed"&&!e.run.pendingRequest&&e.run.revision===M.revision+1&&e.run.nodeId===M.nodeId&&e.run.visit===M.visit&&t?.receiptId===M.receiptId&&t.selectionGeneration===M.selectionGeneration&&(t.quote?.operationId??null)===M.operationId&&(t.operation?.operationId??t.quote?.operationId??null)===M.operationId){let r=M.operationId===null&&t.selectionGeneration===0&&!t.quote&&!t.operation&&!t.purchaseRequestId,b=In({quote:t.quote,operation:t.operation,requestId:t.purchaseRequestId,pending:!1,destroyed:!1,canReselect:t.canReselect});(r||t.canReselect===!0&&b.type==="native")&&(M.acknowledged=!0)}}let Ae=null,Me=new Set,ge={},qe=!1,Z=(e,t=null)=>{s||(e instanceof ne&&e.status===409&&e.reason==="STATE_CHANGED"&&e.recovery==="recover_operation"&&wn.destroy(),Ae=t,qe=!1,j.textContent=Kn(e,we),j.hidden=!1,Y.hidden=n.client.pendingCommand===null,Fe(),ke(n.onError,e))},ae=xn({client:n.client,document:g,conceal(){s||(he(),T?.finish("dismissed"),d.hidden=!0,V||(V=!0,Ie()))},async receive(e){s||await ce(n.client.view??e.run)},failed(e){if(!s){if(!ae.pending){ye=!1;let t=n.client.view;t&&ce(t).then(()=>Z(e),Z);return}tn(),d.parentElement!==i&&i.append(d),d.hidden=!1,B.hidden=ie.hidden=D.hidden=!0,me.textContent="",ze(),Z(e,n.client.pendingCommand?.requestId??null)}}}),Nn=()=>{s||(Ae=null,j.textContent=nt(we),j.hidden=!1,Y.hidden=!0,Fe())};function Se(){let e=n.client.view;if(!e)throw new ne("INVALID_REQUEST","No current Run is available");return{requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:e.revision}}let h=at({client:n.client,doc:g,holder:x,reviewHolder:te,mountScreenPreview:c,loadingOptions:n,get chrome(){return X},get stopped(){return s},get answers(){return ge},suspend(e){C?.setSuspended(e)},resetScreen(){Ce="",ee="",Ge=""},enqueue:ce,fail:Z}),$e=ot({client:n.client,expected:Se,fail:Z,get stopped(){return s},get reviewing(){return h.active},get key(){return Ce},get busy(){return G},get staleRead(){return pn}}),Ke=st({client:n.client,expected:Se,perform:He,onIntent:n.onCustomerDataIntent,get stopped(){return s},get busy(){return G},get document(){return pe?.document},get answers(){return ge}}),en=e=>`${e.id}:${e.nodeId}:${e.visit}`,Oe=e=>e&&(e.screen||e.paywall)?en(e):"";function be(){let e=n.client.view;B.disabled=!h.active&&(G>0||!!n.client.pendingCommand||!e?.canBack||e.stopped||!["running","waiting"].includes(e.status)||!Oe(e)||ee!==Oe(e)),B.hidden=!h.active&&!e?.canBack,bn(B);let t=!!C&&!h.active;D.hidden=t&&!T?.active||J&&!h.active,ie.hidden=!n.client.review||!h.active&&!e?.canBack;let r=e?.locale.startsWith("zh");kn=!t&&(G>0||!!e?.pendingRequest),me.textContent=t?"":G>0||e?.pendingRequest?r?"正在处理":"Processing":e?.instruction?.type==="wait"?r?"等待中":"Waiting":"",Fe()}async function qn(e){if(!e)return;let t=n.client.view;await e;let r=n.client.view;if(!t||!r||r.id!==t.id||r.nodeId!==t.nodeId||r.visit!==t.visit||r.stopped||!["running","waiting"].includes(r.status))throw new ne("PRECONDITION_FAILED","The screen changed while its display was acknowledged")}async function He(e,t=!1,r){if(!((G||ye||se||H)&&!t||s||h.active&&!t)){G++,d.setAttribute("aria-busy","true"),j.hidden=!0,Ae=null,qe=!1,be();try{if(t||await qn($e.inFlight),s)return;let b=await e();s||await ce(n.client.view??b.run)}catch(b){r?.(b)&&n.client.pendingCommand===null?Nn():ae.pending||Z(b,n.client.pendingCommand?.requestId??null)}finally{G=Math.max(0,G-1),d.setAttribute("aria-busy",String(G>0)),s||(Y.hidden=n.client.pendingCommand===null,be())}}}function Le(){wn.schedule()}async function gn(){if(!(s||We||G)&&!ae.pending){if(h.active){await h.open(h.receipt);return}We=!0;try{let e=n.client.pendingCommand;e&&n.client.settle&&await n.client.settle(e.requestId);let t=n.client.view,r=Ke.queries,b=await n.client.get(t?.screen&&Object.keys(r).length?{nodeId:t.nodeId,visit:t.visit,revision:t.revision,components:r}:void 0);qe&&!s&&(qe=!1,j.hidden=!0,Fe()),!s&&r===Ke.queries&&await ce(n.client.view??b.run)}catch(e){Z(e),qe=!s}finally{We=!1}}}function nn(e,t,r){if(T?.active){let le=T;return le.setDismissHandler(()=>Hn(le)),le}let b=sn(i,n,"funnel",()=>Hn(b),jn);return T=b,b.start(e,t,r),b}function Hn(e){s||oe||(oe=!0,e.finish("dismissed"),he(),d.hidden=!0,n.client.view?Pe().finally(z):z())}function hn(){clearTimeout(Xe?.timeout),Xe=void 0}function he(e){J=!1,hn(),Ne?.abort(),Ne=void 0,pe?.destroy(),pe=null,C?.destroy(),C=null,Ve=void 0,Ue?.(),Ue=void 0,m.open&&m.close();for(let t of Array.from(x.children))(!e||!t.contains(e))&&t.remove();x.style.cssText="",Je=void 0,Ce="",ee="",De=!1,Ge="",Qe=""}function Ln(){let e=g.defaultView;K?.responsive&&e&&pe?.resizeViewport?.(e.innerHeight,e.innerWidth)}function tn(){K?.destroy(),K=void 0,dn=""}function rn(e){let t=e.screen?.presentation;if(!t||t.type==="inline"){m.open&&m.close(),tn(),D.parentElement!==F&&F.append(D),d.parentElement!==i&&i.append(d);for(let le of["flex","display","flex-direction","justify-content"])x.style.removeProperty(le);ze(e),Fe();return}d.parentElement!==m&&(m.append(D,d),i.append(m)),x.style.flex="1 0 auto",x.style.display="flex",x.style.flexDirection="column",x.style.justifyContent="center",ze(e);let r=e.screen.content.document,b=JSON.stringify([t,ln]);b!==dn&&(tn(),dn=b,m.style.cssText=zn("funnel",t,ue),K=Gn(m,{presentation:t,theme:r.theme,pages:r.pages},Ln),K.latch()),Fe(),m.setAttribute("aria-label",(U?.screen===e.screen?.content.document.name?U?.label:void 0)??pe?.document?.name??e.screen?.content.document.name??"Funnel")}async function lt(e){if(s||oe)return;if(ae.observe(),ae.pending){re=e;return}if(ye&&(Ze()||["running","waiting"].includes(e.status))||(re=e,Ae&&n.client.pendingCommand?.requestId!==Ae&&(j.hidden=!0,Ae=null),we=e.locale.startsWith("zh"),ie.textContent=we?"回看":"History",B.textContent=h.active?we?"返回当前":"Return to current":we?"返回":"Back",Fn(),Y.textContent=we?"重试":"Retry",Y.hidden=n.client.pendingCommand===null,be(),An!==`${e.revision}:${e.visit}:${e.status}:${e.stopped}`&&(An=`${e.revision}:${e.visit}:${e.status}:${e.stopped}`,ke(n.onState,structuredClone(e))),s||oe))return;if((!e.pendingRequest||ye&&e.status==="closed")&&["closed","ineligible","failed"].includes(e.status)){z();return}if(e.stopped&&de()){z();return}if(e.stopped||n.client.configurationReady===!1){h.stop(),v(),he(),T?.finish("skipped"),d.hidden=!0,Le();return}if(d.hidden=!1,h.active){Le();return}if(e.status==="completed"&&C?.subscriptionUpgradeActive){Le();return}let t=Oe(e),r=n.client.view;if(r&&r.revision>e.revision&&Oe(r)!==t)return;let b=!e.instruction&&!e.pendingRequest&&e.nodeType==="screen"&&["running","waiting"].includes(e.status);t!==Ce&&(Ce&&T?.finish("dismissed"),he(),Ce=t,ge={...e.answers},Ke.reset());let le=en(e);if(Ye===le){d.hidden=!0;return}if(b&&!t){d.hidden=!0;let P=u?.state==="shown"?null:nn(!0,e.locale);!s&&!oe&&Xe?.key!==le&&(hn(),Xe={key:le,timeout:setTimeout(()=>{let l=n.client.view;if(s||!P?.active&&u?.state!=="shown"||!l||en(l)!==le)return;Ye=le;let S=new Error("Funnel screen preparation timed out");P?.finish("error",S),v(),he(),Z(S)},_e)}),Le();return}hn();let $=P=>{let l=n.client.view;return!s&&!oe&&!Te&&!P.aborted&&n.client.configurationReady!==!1&&!!l&&!l.stopped&&!["closed","ineligible","failed"].includes(l.status)&&(Oe(l)===t||l.status==="completed"&&C?.subscriptionUpgradeActive===!0)},Ee=(P,l)=>{$(l)&&(Ye=t,T?.finish("error",P),he(),d.hidden=!0,Z(P))};if(t||((e.instruction&&e.instruction.type!=="evaluate_segment"||!["running","waiting"].includes(e.status))&&v(),rn(e),e.instruction?.type!=="event"&&e.instruction?.type!=="open_url"&&T?.finish("skipped")),e.screen){if(mn=!0,je=void 0,v(),n.prepareNextPaywall&&R?.key!==t){p();let L=new Map;for(let[I,N]of Object.entries(e.screen.nextPaywalls??{})){if(!e.screen.outputs.includes(I))continue;let f=n.prepareNextPaywall({run:e,paywallVersionId:N.paywallVersionId});f&&L.set(I,f)}R={key:t,copies:L}}let P=e.screen.content;if(!pe){let L=e.screen.presentation.type!=="inline",I=nn(L,e.locale);if(s||oe)return;let N=(Ne=new AbortController).signal;rn(e),Ue=L?Xn(m):an(d,i),pe=c(x,{mode:"live",closeActions:Array.from(new Set([...n.closeActions??[],...P.document.actions.filter(f=>f.type==="event"&&f.close).map(f=>f.id)])),onAuthoredClose(f){$(N)&&(J=f,be())},rendererUrl:n.client.webViewUrl,title:P.document.name,...L?{hostPresentation:()=>K?.type??e.screen.presentation.type}:{},onResize:f=>{Je=f,K?.responsive&&K.setContentHeight(f+Tn())},onAction(f,a={},fe={}){if(h.active||!$(N)||ee!==t)return;ge={...ge,...fe};let vn=e.screen?.inputs??[],Mn=Object.fromEntries(vn.filter(({variable:Re})=>Object.hasOwn(ge,Re)).map(({variable:Re})=>[Re,ge[Re]]));if(tt(vn,Mn).length){Nn();return}let xe=!G&&R?.key===t?R.copies.get(f):void 0;xe?.state==="ready"&&xe.open()==="shown"&&(p(xe),v(),W(),u=xe,y=Rn(xe),W=y?.onClose(Vn)??(()=>{}),o=t),He(()=>n.client.submit({operation:"submit",...Se(),input:{type:"screen",output:f,answers:Mn,selection:a}}),!1,Re=>et(Re,vn)).finally(()=>{let Re=n.client.view;o===t&&(!Re||Oe(Re)===t)&&(o=void 0,v())})},onAnswers:f=>{h.active||!$(N)||ee!==t||(ge={...ge,...f})},onCustomerDataIntent:f=>{h.active||!$(N)||ee!==t||Ke.intent(f).catch(Z)},onEscape:()=>{!$(N)||ee!==t||h.active||se||H||Pe()},onError:f=>{let a=new Error(f);ee===t?Z(a):Ee(a,N)},onRendered:f=>{if(!(!$(N)||ee===t))try{I.present(a=>{Ue?.(),Ue=void 0,f&&(U={screen:P.document.name,label:f},m.setAttribute("aria-label",f)),L&&(m.showModal(),V=!1,K?.responsive&&m.focus({preventScroll:!0}),!a&&n.loading!=="host"&&Qn(m,K?.type??e.screen.presentation.type,K?.responsive)),ee=t,De=L,be()}),$(N)&&$e.report(t)}catch(a){Ee(a,N)}}}),Ln()}let l={capabilities:e.screen.capabilities,customerData:e.screen.customerData,parameters:e.parameters,serverInput:{bindings:e.screen.inputs,answers:ge,values:e.screen.values}},S=JSON.stringify([P,e.locale,l.parameters,e.screen.inputs,e.screen.values]);if(S!==Ge)pe.update(P.document,e.locale,l),Ge=S,cn=JSON.stringify(l.capabilities),Qe=JSON.stringify(l.customerData);else{let L=JSON.stringify(l.capabilities);L!==cn&&(pe.updateCapabilities(l.capabilities),cn=L),JSON.stringify(l.customerData)!==Qe&&(pe.updateCustomerData(l.customerData),Qe=JSON.stringify(l.customerData))}let Q=pe;if(Q)try{await(T?.wait(Q.ready)??Q.ready)}catch(L){Ne&&Ee(L,Ne.signal)}}else if(e.paywall&&!C){mn=!0,p();let P=e.paywall.resolution,l="document"in P?P.document:null,S=y,Q=n.mountPaywallControls,L=null,I=(Ne=new AbortController).signal,N={loading:"host",signal:I,...Q&&{mountControls:a=>Q(a,e)},canInteract:()=>$(I)&&!h.active&&!se&&!H,beforeAction:async()=>{G++;try{await qn($e.settled()),j.hidden=!0,Ae=null,qe=!1,Fe()}finally{G=Math.max(0,G-1)}},start:async()=>{let a=await Pn(n.client),fe=A;return A=void 0,a.view&&fe?.(a.view),a},onObservationChange:Le,...n.onPurchaseIntent&&{onPurchaseIntent:a=>n.onPurchaseIntent(a,structuredClone(e))},onPurchase:n.onPurchase,onCheckoutUrl:n.onCheckoutUrl,resumeCheckout:n.resumeCheckout,allowNewPurchase:n.allowNewPurchase,checkoutNavigation:n.checkoutNavigation,terminateCheckout:n.terminateCheckout,beforeCheckoutReplacement:n.beforeCheckoutReplacement,purchaseConfirmation:n.purchaseConfirmation,confirmOnHostedCheckout:n.confirmOnHostedCheckout,resolveOfferId:n.resolveOfferId,prepareSubscriptionChange:n.prepareSubscriptionChange,resolveSubscriptionChange:n.resolveSubscriptionChange,claimCoupon:n.claimCoupon,onEvent:n.onEvent,onOpenUrl:a=>n.onOpenUrl?n.onOpenUrl({receiptId:e.paywall.receiptId,url:a,openIn:"same_window"}):g.defaultView?.location.assign(a),onAction:async a=>{if(h.active)return;let fe=await n.client.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:a,answers:{}}});await ce(n.client.view??fe.run)},onError:a=>{ee===t?Z(a):Ee(a,I)}},f={quoteError:a=>ke(n.onError,a),present(a){$(I)&&(L?.present(fe=>{a(fe),ee=t,De=f.retainedDialog?.dialog.open??!!x.querySelector("dialog[open]"),De&&(V=!1),be()}),$(I)&&$e.report(t))},async closeAction(a){s||h.active||await ae.submit({operation:"submit",requestId:crypto.randomUUID(),nodeId:e.nodeId,visit:e.visit,revision:n.client.view?.revision??e.revision,input:{type:"screen",output:a,answers:{}}})},async dismiss(){if(s||I.aborted||h.active||se||H||!ye&&!$(I))return;ye=!0;let a=n.client.view;if(a?.status==="completed"&&C?.subscriptionUpgradeActive){Me.add(`complete:${a.id}`),ke(n.onComplete,structuredClone(a)),z();return}if((n.resumeCheckout||n.terminateCheckout)&&pt()){re=n.client.view,z();return}await Pe()}};if(S&&Q)v();else if(S){let a=await S.adopt(e,{options:N,handoff:f,start:()=>Pn(n.client)});o=void 0,a&&$(I)&&!s?(rn(e),C=a,Ve={runId:e.id,receiptId:e.paywall.receiptId},T?.active&&T.present(()=>{}),ee=t,De=S.modal,De&&(V=!1),be(),$e.report(t),h.active&&C.setSuspended(!0)):(a?.destroy(),v(),A=fe=>y?.remember(fe))}if(s||oe)return;if(!C){if(L=nn(!0,e.locale,l),s||oe)return;(typeof INDIANA_NATIVE_SHELL_BUILD>"u"||!INDIANA_NATIVE_SHELL_BUILD)&&n.loading==="host"&&je?.ownerDocument===g&&(f.hostPaywallTarget=je),je=void 0,rn(e);let a=await _(x,N,f).catch(fe=>(Ee(fe,I),null));!$(I)&&!(ye&&!s&&!I.aborted)?a?.host?.destroy():a&&(C=a.host,C&&(Ve={runId:e.id,receiptId:e.paywall.receiptId}),C?.setSuspended(h.active))}}if(s||oe)return;be();let w=e.instruction;if(w&&(w.type==="open_url"||w.type==="event")&&!Me.has(w.receiptId)){let P=g.createElement("button");P.type="button",P.style.cssText=X.primary,Be(P,()=>X.focus),x.style.cssText=X.stage,P.textContent=w.type==="open_url"?`${we?"前往":"Continue to"} ${new URL(w.url).host}`:we?"继续":"Continue",P.onclick=()=>{let l=Se(),S=w.type==="open_url"&&!n.onOpenUrl&&w.openIn==="new_window"?dt(w.url):null;He(async()=>{let Q="success";if(w.type==="open_url")if(n.onOpenUrl)try{Q=await n.onOpenUrl({receiptId:w.receiptId,url:w.url,openIn:w.openIn})===!1?"failed":"opened"}catch(I){ke(n.onError,I),Q="failed"}else Q=w.openIn==="new_window"&&!S?"failed":"opened";if(w.type==="event"){if(!n.onEvent)throw new ne("EVENT_HANDLER_REQUIRED","Provide the event handler");await n.onEvent(w.event)}if(s||n.client.view?.nodeId!==l.nodeId||n.client.view.visit!==l.visit)throw new ne("PRECONDITION_FAILED","The client action visit changed");let L=await n.client.submit({operation:"submit",...l,input:{type:"client_action",receiptId:w.receiptId,outcome:Q}});return Me.add(w.receiptId),w.type==="open_url"&&!n.onOpenUrl&&w.openIn==="same_window"&&g.defaultView?.location.assign(w.url),L})},T?.active?T.present(()=>x.replaceChildren(P)):x.replaceChildren(P)}!e.pendingRequest&&e.status==="completed"&&!Me.has(`complete:${e.id}`)&&(Me.add(`complete:${e.id}`),ke(n.onComplete,structuredClone(e))),Le()}function dt(e){let t=g.defaultView?.open(e,"_blank")??null;return t&&(t.opener=null),t}function ce(e){return be(),fn=fn.catch(()=>{}).then(async()=>{try{await lt(e)}catch(t){throw T?.active&&(Ye=en(e),T.finish("error",t),he(),d.hidden=!0),t}}),fn}let ut=n.client.subscribe(e=>{if(!Sn){if(e.stopped&&(De||de())&&!ye){re=e,z();return}!ye&&(e.stopped||n.client.configurationReady===!1||Ce&&ee!==Ce&&(Oe(e)!==Ce||["closed","ineligible","failed"].includes(e.status)))&&(he(),T?.finish("dismissed"),d.hidden=!0),ce(e).catch(Z)}}),ct=n.client.subscribeError?.(e=>{ae.pending||Z(e)});function pt(){let e=n.client.view,t=e?.paywall;return!!t?.operation&&!!e&&["running","waiting"].includes(e.status)&&Bn(In({quote:t.quote,operation:t.operation,requestId:t.purchaseRequestId,pending:!1,destroyed:!1,canReselect:t.canReselect}))}function Pe(e){if(Te)return Te;if(s||!e&&(se||H))return Promise.resolve();let t=!e&&Ze();return!t&&n.client.view&&!["running","waiting"].includes(n.client.view.status)?(re=n.client.view,z(),Promise.resolve()):(Te=He(async()=>{let r=t?await n.client.retry():await(e?n.client.submit.bind(n.client):ae.submit)({operation:"close",...e??Se()});return e&&On(r),r},!0).then(()=>{let r=n.client.view;r?.status==="closed"&&!Ze()&&(re=r,z())}).finally(()=>{Te=null}),Te)}function z(){_n()}function _n(e){ve?.destroy(),!s&&(s=!0,ae.destroy(),W(),p(),!mn&&(re?.status==="ineligible"||re?.status==="completed")&&y?.withhold(),v(),n.signal?.removeEventListener("abort",z),O?.removeEventListener("abort",z),T?.finish("dismissed"),wn.destroy(),ut(),ct?.(),he(e),tn(),h.stop(),m.remove(),!e||!d.contains(e)?d.remove():(F.remove(),te.remove()),!e&&!V&&Ie(),ke(n.onDismiss,re?structuredClone(re):null))}B.onclick=()=>{if(!B.disabled){if(h.active){h.exit();return}He(()=>n.client.submit({operation:"back",...Se()}))}},ie.onclick=()=>{h.open()},D.onclick=()=>{T?.active?T.dismiss():se||Pe()},Y.onclick=()=>{ae.pending?ae.retry().catch(()=>{}):Ze()?Pe():He(()=>n.client.retry())},m.addEventListener("cancel",e=>{e.preventDefault(),T?.active?T.dismiss():se||Pe()}),n.signal?.addEventListener("abort",z,{once:!0}),O?.addEventListener("abort",z,{once:!0});let on=!1;function Vn(){s||oe||(oe=!0,T?.finish("dismissed"),he(),d.hidden=!0,n.client.view?Pe().finally(z):on=!0)}y&&(W=y.onClose(Vn));let Un={destroy:z,refresh:gn,get recoveryPaywall(){if(C&&Ve)return{...Ve,view:C.currentResolution}},setPurchaseRecovery(e,t){return C?.setPurchaseRecovery(e,t),C!==null},retainPurchaseDialog(){let e=C?.retainPurchaseDialog();if(e)return C=null,_n(e.dialog),{dialog:e.dialog,release(){e.release(),d.remove(),V||Ie()}}},get recovery(){let e=yn();if(e)return e;if(!s&&!G&&!ye&&!se&&C){let t=C.recovery;if(t.type!=="native")return t}return{type:"recover",operationId:n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??H?.operationId??null,requestId:n.client.pendingCommand?.requestId??null}},prepareFallback(){if(se)return se;let e=yn();if(e)return Promise.resolve(e);let t=n.client.pendingPurchase?.operationId??n.client.view?.paywall?.quote?.operationId??H?.operationId??null,r=()=>({type:"recover",operationId:t,requestId:n.client.pendingCommand?.requestId??null});if(n.client.hasDurableJournal!==!0){let w=C?.recovery;return Promise.resolve(w&&w.type!=="native"&&w.type!=="cancel"?w:r())}let b=(n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[])).some(w=>w.operation==="close");if(s&&!(b||H&&n.client.view?.status==="closed")||G||We||Te||h.active||!C&&!H&&!b)return Promise.resolve(r());let le=C,$=(async()=>{try{if(!H&&b){let l=await n.client.retry();return await ce(n.client.view??l.run),r()}if(!H){let l=await le.prepareFallback();if(l.type!=="native")return l;if(n.client.hasDurableJournal!==!0)return r();H=l}let w=n.client.pendingCommands??(n.client.pendingCommand?[n.client.pendingCommand]:[]);if(w.length){let l=w.find(Q=>Q.operation==="close");if(!l||!M||l.requestId!==M.requestId)return r();let S=await n.client.retry();On(S),await ce(n.client.view??S.run)}else{let l=n.client.view,S=l?.paywall;if(!l||!S||S.selectionGeneration===void 0||(S.quote?.operationId??null)!==H.operationId||H.operationId!==null&&S.canReselect!==!0)return r();let Q=S.selectionGeneration,L=await n.client.get();await ce(n.client.view??L.run);let I=n.client.view,N=I?.paywall;if(!I||!N||!["running","waiting"].includes(I.status)||I.stopped||I.id!==l.id||I.nodeId!==l.nodeId||I.visit!==l.visit||N.receiptId!==S.receiptId||N.selectionGeneration!==Q||(N.quote?.operationId??null)!==H.operationId||H.operationId!==null&&N.canReselect!==!0||n.client.pendingPurchase||(n.client.pendingCommands?.length??(n.client.pendingCommand?1:0)))return r();let f=Se();M={runId:I.id,operationId:H.operationId,revision:f.revision,requestId:f.requestId,nodeId:I.nodeId,visit:I.visit,receiptId:N.receiptId,selectionGeneration:Q,acknowledged:!1},await Pe(f)}let P=yn();return P?(z(),P):r()}catch(w){return Z(w),r()}})();se=$;let Ee=()=>{se===$&&(se=null)};return $.then(Ee,Ee),$},review:h.open,exitReview:h.exit,get unappliedDrafts(){return h.drafts}};try{let e=n.client.view;if(e)((n.client.viewAgeMs??En)>=En||e.instruction?.type==="evaluate_segment")&&(pn=gn().finally(()=>{pn=null})),await ce(e);else{if(d.hidden=!0,s)throw new DOMException("Presentation cancelled","AbortError");let t=on||u?.state==="shown"?null:nn(n.client.view?.screen?.presentation.type!=="inline",n.client.view?.locale);if(s||oe&&!on)throw new DOMException("Presentation cancelled","AbortError");let r=n.client.get(),b=await(t?t.wait(r,_e):wt(r,_e));if(Sn=!1,on)return s||await Pe().finally(z),Un;await ce(n.client.view??b.run)}}catch(e){throw T?.finish("error",e),z(),e}return Un}function wt(i,E){let q;return Promise.race([i,new Promise((n,u)=>{q=setTimeout(()=>u(new Error("Presentation data timed out")),E)})]).finally(()=>clearTimeout(q))}function zt(i,E,q){return mt(i,E,q)}export{mt as a,zt as b};