@dtect/security-sdk-js 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var z=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var r in t)z(e,r,{get:t[r],enumerable:!0})},ot=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of rt(t))!nt.call(e,i)&&i!==r&&z(e,i,{get:()=>t[i],enumerable:!(n=tt(t,i))||n.enumerable});return e};var st=e=>ot(z({},"__esModule",{value:!0}),e);var Ht={};it(Ht,{SecurityAPIError:()=>Je,default:()=>Zt,getSecurityResult:()=>me,getSecurityToken:()=>Ee,init:()=>ze});module.exports=st(Ht);var S=function(){return S=Object.assign||function(t){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},S.apply(this,arguments)};function Re(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r}function Oe(e,t,r){if(r||arguments.length===2)for(var n=0,i=t.length,s;n<i;n++)(s||!(n in t))&&(s||(s=Array.prototype.slice.call(t,0,n)),s[n]=t[n]);return e.concat(s||Array.prototype.slice.call(t))}function at(e,t){return function(r,n){return Object.prototype.hasOwnProperty.call(r,n)}(e,t)?e[t]:void 0}function ut(e,t,r,n){var i,s=document,u="securitypolicyviolation",o=function(y){var l=new URL(e,location.href),h=y.blockedURI;h!==l.href&&h!==l.protocol.slice(0,-1)&&h!==l.origin||(i=y,a())};s.addEventListener(u,o);var a=function(){return s.removeEventListener(u,o)};return n?.then(a,a),Promise.resolve().then(t).then(function(y){return a(),y},function(y){return new Promise(function(l){var h=new MessageChannel;h.port1.onmessage=function(){return l()},h.port2.postMessage(null)}).then(function(){if(a(),i)return r(i);throw y})})}var ct={default:"endpoint"},lt={default:"tlsEndpoint"},ft="Client timeout",ht="Network connection error",dt="Network request aborted",pt="Response cannot be parsed",Z="Blocked by CSP",H="The endpoint parameter is not a valid URL";function P(e){for(var t="",r=0;r<e.length;++r)if(r>0){var n=e[r].toLowerCase();n!==e[r]?t+=" ".concat(n):t+=e[r]}else t+=e[r].toUpperCase();return t}var yt=P("WrongRegion"),mt=P("SubscriptionNotActive"),Et=P("UnsupportedVersion"),Rt=P("InstallationMethodRestricted"),Ot=P("HostnameRestricted"),Tt=P("IntegrationFailed"),ee="API key required",Te="API key not found",ve="API key expired",vt="Request cannot be parsed",It="Request failed",_t="Request failed to process",gt="Too many requests, rate limit exceeded",bt="Not available for this origin",wt="Not available with restricted header",Pt=ee,At=Te,Dt=ve,Nt="3.11.6",j="Failed to load the JS script of the agent",te="9319";function St(e,t){var r,n,i,s,u,o,a,y=[],l=(r=function(f){var c=Oe([],f,!0);return{current:function(){return c[0]},postpone:function(){var d=c.shift();d!==void 0&&c.push(d)},exclude:function(){c.shift()}}}(e),s=100,u=3e3,o=0,n=function(){return Math.random()*Math.min(u,s*Math.pow(2,o++))},i=new Set,[r.current(),function(f,c){var d,p=c instanceof Error?c.message:"";if(p===Z||p===H)r.exclude(),d=0;else if(p===te)r.exclude();else if(p===j){var O=Date.now()-f.getTime()<50,T=r.current();T&&O&&!i.has(T)&&(i.add(T),d=0),r.postpone()}else r.postpone();var g=r.current();return g===void 0?void 0:[g,d??f.getTime()+n()-Date.now()]}]),h=l[0],I=l[1];if(h===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var _=function(f){var c=new Date,d=function(O){return y.push({url:f,startedAt:c,finishedAt:new Date,error:O})},p=t(f);return p.then(function(){return d()},d),p.catch(function(O){if(a!=null||(a=O),y.length>=5)throw a;var T=I(c,O);if(!T)throw a;var g,J=T[0],He=T[1];return(g=He,new Promise(function(et){return setTimeout(et,g)})).then(function(){return _(J)})})};return _(h).then(function(f){return[f,y]})}var Ie="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",xt=Ie;function Mt(e){var t;e.scriptUrlPattern;var r=e.token,n=e.apiKey,i=n===void 0?r:n,s=Re(e,["scriptUrlPattern","token","apiKey"]),u=(t=at(e,"scriptUrlPattern"))!==null&&t!==void 0?t:Ie,o=function(){var l=[],h=function(){l.push({time:new Date,state:document.visibilityState})},I=function(_,f,c,d){return _.addEventListener(f,c,d),function(){return _.removeEventListener(f,c,d)}}(document,"visibilitychange",h);return h(),[l,I]}(),a=o[0],y=o[1];return Promise.resolve().then(function(){if(!i||typeof i!="string")throw new Error(ee);var l=function(h,I){return(Array.isArray(h)?h:[h]).map(function(_){return function(f,c){var d=encodeURIComponent;return f.replace(/<[^<>]+>/g,function(p){return p==="<version>"?"3":p==="<apiKey>"?d(c):p==="<loaderVersion>"?d(Nt):p})}(String(_),I)})}(u,i);return St(l,Ft)}).catch(function(l){throw y(),function(h){return h instanceof Error&&h.message===te?new Error(j):h}(l)}).then(function(l){var h=l[0],I=l[1];return y(),h.load(S(S({},s),{ldi:{attempts:I,visibilityStates:a}}))})}function Ft(e){return ut(e,function(){return function(t){return new Promise(function(r,n){if(function(o){if(URL.prototype)try{return new URL(o,location.href),!1}catch(a){if(a instanceof Error&&a.name==="TypeError")return!0;throw a}}(t))throw new Error(H);var i=document.createElement("script"),s=function(){var o;return(o=i.parentNode)===null||o===void 0?void 0:o.removeChild(i)},u=document.head||document.getElementsByTagName("head")[0];i.onload=function(){s(),r()},i.onerror=function(){s(),n(new Error(j))},i.async=!0,i.src=t,u.appendChild(i)})}(e)},function(){throw new Error(Z)}).then(Lt)}function Lt(){var e=window,t="__fpjs_p_l_b",r=e[t];if(function(n,i){var s,u=(s=Object.getOwnPropertyDescriptor)===null||s===void 0?void 0:s.call(Object,n,i);u?.configurable?delete n[i]:u&&!u.writable||(n[i]=void 0)}(e,t),typeof r?.load!="function")throw new Error(te);return r}var k={load:Mt,defaultScriptUrlPattern:xt,ERROR_SCRIPT_LOAD_FAIL:j,ERROR_API_KEY_EXPIRED:ve,ERROR_API_KEY_INVALID:Te,ERROR_API_KEY_MISSING:ee,ERROR_BAD_REQUEST_FORMAT:vt,ERROR_BAD_RESPONSE_FORMAT:pt,ERROR_CLIENT_TIMEOUT:ft,ERROR_CSP_BLOCK:Z,ERROR_FORBIDDEN_ENDPOINT:Ot,ERROR_FORBIDDEN_HEADER:wt,ERROR_FORBIDDEN_ORIGIN:bt,ERROR_GENERAL_SERVER_FAILURE:It,ERROR_INSTALLATION_METHOD_RESTRICTED:Rt,ERROR_INTEGRATION_FAILURE:Tt,ERROR_INVALID_ENDPOINT:H,ERROR_NETWORK_ABORT:dt,ERROR_NETWORK_CONNECTION:ht,ERROR_RATE_LIMIT:gt,ERROR_SERVER_TIMEOUT:_t,ERROR_SUBSCRIPTION_NOT_ACTIVE:mt,ERROR_TOKEN_EXPIRED:Dt,ERROR_TOKEN_INVALID:At,ERROR_TOKEN_MISSING:Pt,ERROR_UNSUPPORTED_VERSION:Et,ERROR_WRONG_REGION:yt,defaultEndpoint:ct,defaultTlsEndpoint:lt};var E=[];for(let e=0;e<256;++e)E.push((e+256).toString(16).slice(1));function _e(e,t=0){return(E[e[t+0]]+E[e[t+1]]+E[e[t+2]]+E[e[t+3]]+"-"+E[e[t+4]]+E[e[t+5]]+"-"+E[e[t+6]]+E[e[t+7]]+"-"+E[e[t+8]]+E[e[t+9]]+"-"+E[e[t+10]]+E[e[t+11]]+E[e[t+12]]+E[e[t+13]]+E[e[t+14]]+E[e[t+15]]).toLowerCase()}var re,Ut=new Uint8Array(16);function ne(){if(!re){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");re=crypto.getRandomValues.bind(crypto)}return re(Ut)}var qt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ie={randomUUID:qt};function Kt(e,t,r){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();e=e||{};let n=e.random??e.rng?.()??ne();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){if(r=r||0,r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let i=0;i<16;++i)t[r+i]=n[i];return t}return _e(n)}var Q=Kt;var jt={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},ge={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key"},be={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},we={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},Pe={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},Ae={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},R={...jt,...ge,...be,...we,...Pe,...Ae},De={...ge,...be,...we,...Pe,...Ae};var b=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var w=typeof window>"u"||"Deno"in globalThis;function v(){}function xe(e,t){return typeof e=="function"?e(t):e}function Me(e){return typeof e=="number"&&e>=0&&e!==1/0}function Fe(e,t){return Math.max(e+(t||0)-Date.now(),0)}function se(e,t){return typeof e=="function"?e(t):e}function Le(e,t){return typeof e=="function"?e(t):e}function ae(e,t){let{type:r="all",exact:n,fetchStatus:i,predicate:s,queryKey:u,stale:o}=e;if(u){if(n){if(t.queryHash!==x(u,t.options))return!1}else if(!D(t.queryKey,u))return!1}if(r!=="all"){let a=t.isActive();if(r==="active"&&!a||r==="inactive"&&a)return!1}return!(typeof o=="boolean"&&t.isStale()!==o||i&&i!==t.state.fetchStatus||s&&!s(t))}function ue(e,t){let{exact:r,status:n,predicate:i,mutationKey:s}=e;if(s){if(!t.options.mutationKey)return!1;if(r){if(A(t.options.mutationKey)!==A(s))return!1}else if(!D(t.options.mutationKey,s))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function x(e,t){return(t?.queryKeyHashFn||A)(e)}function A(e){return JSON.stringify(e,(t,r)=>oe(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}function D(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!D(e[r],t[r])):!1}function Ue(e,t){if(e===t)return e;let r=Ne(e)&&Ne(t);if(r||oe(e)&&oe(t)){let n=r?e:Object.keys(e),i=n.length,s=r?t:Object.keys(t),u=s.length,o=r?[]:{},a=0;for(let y=0;y<u;y++){let l=r?y:s[y];(!r&&n.includes(l)||r)&&e[l]===void 0&&t[l]===void 0?(o[l]=void 0,a++):(o[l]=Ue(e[l],t[l]),o[l]===e[l]&&e[l]!==void 0&&a++)}return i===u&&a===i?e:o}return t}function Ne(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function oe(e){if(!Se(e))return!1;let t=e.constructor;if(t===void 0)return!0;let r=t.prototype;return!(!Se(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function Se(e){return Object.prototype.toString.call(e)==="[object Object]"}function qe(e){return new Promise(t=>{setTimeout(t,e)})}function Ke(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?Ue(e,t):t}function je(e,t,r=0){let n=[...e,t];return r&&n.length>r?n.slice(1):n}function ke(e,t,r=0){let n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var M=Symbol();function G(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===M?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var kt=class extends b{#e;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},B=new kt;var Qt=class extends b{#e=!0;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e(!0),r=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(r=>{r(e)}))}isOnline(){return this.#e}},N=new Qt;function Qe(){let e,t,r=new Promise((i,s)=>{e=i,t=s});r.status="pending",r.catch(()=>{});function n(i){Object.assign(r,i),delete r.resolve,delete r.reject}return r.resolve=i=>{n({status:"fulfilled",value:i}),e(i)},r.reject=i=>{n({status:"rejected",reason:i}),t(i)},r}function Gt(e){return Math.min(1e3*2**e,3e4)}function ce(e){return(e??"online")==="online"?N.isOnline():!0}var Ge=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function V(e){return e instanceof Ge}function C(e){let t=!1,r=0,n=!1,i,s=Qe(),u=c=>{n||(I(new Ge(c)),e.abort?.())},o=()=>{t=!0},a=()=>{t=!1},y=()=>B.isFocused()&&(e.networkMode==="always"||N.isOnline())&&e.canRun(),l=()=>ce(e.networkMode)&&e.canRun(),h=c=>{n||(n=!0,e.onSuccess?.(c),i?.(),s.resolve(c))},I=c=>{n||(n=!0,e.onError?.(c),i?.(),s.reject(c))},_=()=>new Promise(c=>{i=d=>{(n||y())&&c(d)},e.onPause?.()}).then(()=>{i=void 0,n||e.onContinue?.()}),f=()=>{if(n)return;let c,d=r===0?e.initialPromise:void 0;try{c=d??e.fn()}catch(p){c=Promise.reject(p)}Promise.resolve(c).then(h).catch(p=>{if(n)return;let O=e.retry??(w?0:3),T=e.retryDelay??Gt,g=typeof T=="function"?T(r,p):T,J=O===!0||typeof O=="number"&&r<O||typeof O=="function"&&O(r,p);if(t||!J){I(p);return}r++,e.onFail?.(r,p),qe(g).then(()=>y()?void 0:_()).then(()=>{t?I(p):f()})})};return{promise:s,cancel:u,continue:()=>(i?.(),s),cancelRetry:o,continueRetry:a,canStart:l,start:()=>(l()?f():_().then(f),s)}}function Bt(){let e=[],t=0,r=o=>{o()},n=o=>{o()},i=o=>setTimeout(o,0),s=o=>{t?e.push(o):i(()=>{r(o)})},u=()=>{let o=e;e=[],o.length&&i(()=>{n(()=>{o.forEach(a=>{r(a)})})})};return{batch:o=>{let a;t++;try{a=o()}finally{t--,t||u()}return a},batchCalls:o=>(...a)=>{s(()=>{o(...a)})},schedule:s,setNotifyFunction:o=>{r=o},setBatchNotifyFunction:o=>{n=o},setScheduler:o=>{i=o}}}var m=Bt();var Y=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Me(this.gcTime)&&(this.#e=setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(w?1/0:5*60*1e3))}clearGcTimeout(){this.#e&&(clearTimeout(this.#e),this.#e=void 0)}};var Be=class extends Y{#e;#t;#r;#n;#s;#o;constructor(e){super(),this.#o=!1,this.#s=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=Ct(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#n?.promise}setOptions(e){this.options={...this.#s,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let r=Ke(this.state.data,e,this.options);return this.#i({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#i({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(v).catch(v):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>Le(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===M||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(e=0){return this.state.isInvalidated||this.state.data===void 0||!Fe(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#n?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#n?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#n&&(this.#o?this.#n.cancel({revert:!0}):this.#n.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#i({type:"invalidate"})}fetch(e,t){if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#n)return this.#n.continueRetry(),this.#n.promise}if(e&&this.setOptions(e),!this.options.queryFn){let o=this.observers.find(a=>a.options.queryFn);o&&this.setOptions(o.options)}let r=new AbortController,n=o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(this.#o=!0,r.signal)})},i=()=>{let o=G(this.options,t),a={queryKey:this.queryKey,meta:this.meta};return n(a),this.#o=!1,this.options.persister?this.options.persister(o,a,this):o(a)},s={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};n(s),this.options.behavior?.onFetch(s,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==s.fetchOptions?.meta)&&this.#i({type:"fetch",meta:s.fetchOptions?.meta});let u=o=>{V(o)&&o.silent||this.#i({type:"error",error:o}),V(o)||(this.#r.config.onError?.(o,this),this.#r.config.onSettled?.(this.state.data,o,this)),this.scheduleGc()};return this.#n=C({initialPromise:t?.initialPromise,fn:s.fetchFn,abort:r.abort.bind(r),onSuccess:o=>{if(o===void 0){u(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(o)}catch(a){u(a);return}this.#r.config.onSuccess?.(o,this),this.#r.config.onSettled?.(o,this.state.error,this),this.scheduleGc()},onError:u,onFail:(o,a)=>{this.#i({type:"failed",failureCount:o,error:a})},onPause:()=>{this.#i({type:"pause"})},onContinue:()=>{this.#i({type:"continue"})},retry:s.options.retry,retryDelay:s.options.retryDelay,networkMode:s.options.networkMode,canRun:()=>!0}),this.#n.start()}#i(e){let t=r=>{switch(e.type){case"failed":return{...r,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...Vt(r.data,this.options),fetchMeta:e.meta??null};case"success":return{...r,data:e.data,dataUpdateCount:r.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":let n=e.error;return V(n)&&n.revert&&this.#t?{...this.#t,fetchStatus:"idle"}:{...r,error:n,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...e.state}}};this.state=t(this.state),m.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Vt(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:ce(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function Ct(e){let t=typeof e.initialData=="function"?e.initialData():e.initialData,r=t!==void 0,n=r?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var F=class extends b{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,r){let n=t.queryKey,i=t.queryHash??x(n,t),s=this.get(i);return s||(s=new Be({cache:this,queryKey:n,queryHash:i,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(n)}),this.add(s)),s}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){m.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(r=>ae(t,r))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(r=>ae(e,r)):t}notify(e){m.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){m.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){m.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var Ve=class extends Y{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||Yt(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#e.includes(e)||(this.#e.push(e),this.clearGcTimeout(),this.#t.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#e=this.#e.filter(t=>t!==e),this.scheduleGc(),this.#t.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#t.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){this.#r=C({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(n,i)=>{this.#n({type:"failed",failureCount:n,error:i})},onPause:()=>{this.#n({type:"pause"})},onContinue:()=>{this.#n({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#t.canRun(this)});let t=this.state.status==="pending",r=!this.#r.canStart();try{if(!t){this.#n({type:"pending",variables:e,isPaused:r}),await this.#t.config.onMutate?.(e,this);let i=await this.options.onMutate?.(e);i!==this.state.context&&this.#n({type:"pending",context:i,variables:e,isPaused:r})}let n=await this.#r.start();return await this.#t.config.onSuccess?.(n,e,this.state.context,this),await this.options.onSuccess?.(n,e,this.state.context),await this.#t.config.onSettled?.(n,null,this.state.variables,this.state.context,this),await this.options.onSettled?.(n,null,e,this.state.context),this.#n({type:"success",data:n}),n}catch(n){try{throw await this.#t.config.onError?.(n,e,this.state.context,this),await this.options.onError?.(n,e,this.state.context),await this.#t.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this),await this.options.onSettled?.(void 0,n,e,this.state.context),n}finally{this.#n({type:"error",error:n})}}finally{this.#t.runNext(this)}}#n(e){let t=r=>{switch(e.type){case"failed":return{...r,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...r,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:e.error,failureCount:r.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),m.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function Yt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var L=class extends b{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#r=0}#e;#t;#r;build(e,t,r){let n=new Ve({mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:r});return this.add(n),n}add(e){this.#e.add(e);let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);r?r.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);if(r)if(r.length>1){let n=r.indexOf(e);n!==-1&&r.splice(n,1)}else r[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){let t=W(e);if(typeof t=="string"){let n=this.#t.get(t)?.find(i=>i.state.status==="pending");return!n||n===e}else return!0}runNext(e){let t=W(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){m.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(r=>ue(t,r))}findAll(e={}){return this.getAll().filter(t=>ue(e,t))}notify(e){m.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return m.batch(()=>Promise.all(e.map(t=>t.continue().catch(v))))}};function W(e){return e.options.scope?.id}function le(e){return{onFetch:(t,r)=>{let n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,s=t.state.data?.pages||[],u=t.state.data?.pageParams||[],o={pages:[],pageParams:[]},a=0,y=async()=>{let l=!1,h=f=>{Object.defineProperty(f,"signal",{enumerable:!0,get:()=>(t.signal.aborted?l=!0:t.signal.addEventListener("abort",()=>{l=!0}),t.signal)})},I=G(t.options,t.fetchOptions),_=async(f,c,d)=>{if(l)return Promise.reject();if(c==null&&f.pages.length)return Promise.resolve(f);let p={queryKey:t.queryKey,pageParam:c,direction:d?"backward":"forward",meta:t.options.meta};h(p);let O=await I(p),{maxPages:T}=t.options,g=d?ke:je;return{pages:g(f.pages,O,T),pageParams:g(f.pageParams,c,T)}};if(i&&s.length){let f=i==="backward",c=f?Wt:Ce,d={pages:s,pageParams:u},p=c(n,d);o=await _(d,p,f)}else{let f=e??s.length;do{let c=a===0?u[0]??n.initialPageParam:Ce(n,o);if(a>0&&c==null)break;o=await _(o,c),a++}while(a<f)}return o};t.options.persister?t.fetchFn=()=>t.options.persister?.(y,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=y}}}function Ce(e,{pages:t,pageParams:r}){let n=t.length-1;return t.length>0?e.getNextPageParam(t[n],t,r[n],r):void 0}function Wt(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var fe=class{#e;#t;#r;#n;#s;#o;#i;#a;constructor(e={}){this.#e=e.queryCache||new F,this.#t=e.mutationCache||new L,this.#r=e.defaultOptions||{},this.#n=new Map,this.#s=new Map,this.#o=0}mount(){this.#o++,this.#o===1&&(this.#i=B.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=N.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#o--,this.#o===0&&(this.#i?.(),this.#i=void 0,this.#a?.(),this.#a=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),r=this.#e.build(this,t),n=r.state.data;return n===void 0?this.fetchQuery(e):(e.revalidateIfStale&&r.isStaleByTime(se(t.staleTime,r))&&this.prefetchQuery(t),Promise.resolve(n))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:r})=>{let n=r.data;return[t,n]})}setQueryData(e,t,r){let n=this.defaultQueryOptions({queryKey:e}),s=this.#e.get(n.queryHash)?.state.data,u=xe(t,s);if(u!==void 0)return this.#e.build(this,n).setData(u,{...r,manual:!0})}setQueriesData(e,t,r){return m.batch(()=>this.#e.findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,r)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;m.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){let r=this.#e,n={type:"active",...e};return m.batch(()=>(r.findAll(e).forEach(i=>{i.reset()}),this.refetchQueries(n,t)))}cancelQueries(e,t={}){let r={revert:!0,...t},n=m.batch(()=>this.#e.findAll(e).map(i=>i.cancel(r)));return Promise.all(n).then(v).catch(v)}invalidateQueries(e,t={}){return m.batch(()=>{if(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none")return Promise.resolve();let r={...e,type:e?.refetchType??e?.type??"active"};return this.refetchQueries(r,t)})}refetchQueries(e,t={}){let r={...t,cancelRefetch:t.cancelRefetch??!0},n=m.batch(()=>this.#e.findAll(e).filter(i=>!i.isDisabled()).map(i=>{let s=i.fetch(void 0,r);return r.throwOnError||(s=s.catch(v)),i.state.fetchStatus==="paused"?Promise.resolve():s}));return Promise.all(n).then(v)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let r=this.#e.build(this,t);return r.isStaleByTime(se(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(v).catch(v)}fetchInfiniteQuery(e){return e.behavior=le(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(v).catch(v)}ensureInfiniteQueryData(e){return e.behavior=le(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return N.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#n.set(A(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#n.values()],r={};return t.forEach(n=>{D(e,n.queryKey)&&Object.assign(r,n.defaultOptions)}),r}setMutationDefaults(e,t){this.#s.set(A(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#s.values()],r={};return t.forEach(n=>{D(e,n.mutationKey)&&(r={...r,...n.defaultOptions})}),r}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=x(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===M&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};var Xt=new fe({defaultOptions:{queries:{staleTime:3e4}},queryCache:new F({onError:(e,t)=>{}}),mutationCache:new L}),Ye=Xt;var $t=(e,t={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...t}),Jt=async(e,t)=>{if(!e.ok){let r=await e.text();throw new Error(r)}return t==="file"?e.blob():t==="json"?e.json():t==="text"?e.text():null},We=async({url:e,auth:t,body:r,method:n="GET",headers:i={},responseType:s="json"})=>{let u={method:n,headers:$t(t,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},o=await fetch(e,u);return Jt(o,s)},Xe=e=>We({...e,method:"GET"}),he=e=>We({...e,method:"POST"});var de,pe="https://api.dtect.io/security",q="",K="",$e="",X,U={isLoading:!1},Je=De;function $(){return!!(document.querySelector("#dtect-h-captcha")&&de)}function ye(){return!!(q&&K)}async function zt({behaviorKey:e}){let t=await k.load({apiKey:e,endpoint:["https://fp.dtect.io",k.defaultEndpoint],scriptUrlPattern:["https://fp.dtect.io/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",k.defaultScriptUrlPattern]});if(t)de=t;else throw new Error(R.SDK_INIT_ERROR)}async function ze(e){if(!e?.clientId||!e?.apiKey)throw new Error(R.MISSING_CREDENTIALS);let{clientId:t,apiKey:r,endpoint:n="https://api.dtect.io/security"}=e;if(pe=n,U.isLoading){if($())return X;throw new Error(R.DUPLICATE_INITIALIZATION)}if(q=t,K=r,U={...U,isLoading:!0},!ye())throw new Error(R.MISSING_CREDENTIALS);if($())return X;let i=document.querySelector("head");document.querySelector("body")?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let u=document.createElement("script");u.setAttribute("src","https://js.hcaptcha.com/1/api.js?onload=onLoad"),u.setAttribute("async","true"),u.setAttribute("defer","true"),i?.append(u);try{let o=await Ye.fetchQuery({queryKey:["getKeys",t,r],queryFn:()=>Xe({url:`${n}/client/get-config`,headers:{"client-id":q,"x-api-key":K}})});if(o?.automationKey&&o?.behaviorKey)return $e=o.automationKey,zt({...o}).then(()=>({getSecurityResult:me,getSecurityToken:Ee,SecurityAPIError:Je})).catch(a=>{throw new Error(a.message)});throw new Error("Empty keys")}catch(o){throw console.warn(`${JSON.stringify(o)}`),o instanceof Error&&o?.message?.includes(R.INVALID_API_KEY)?new Error(R.INVALID_CREDENTIALS):new Error(R.SDK_INIT_ERROR)}finally{U={...U,isLoading:!1}}}async function Ze(){await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:$e,size:"invisible"});let e=await window?.hcaptcha?.execute({async:!0}),t=await de?.get();if(e?.response&&t?.sealedResult&&t?.requestId)return{behaviorRequestId:t.requestId,behaviorToken:t.sealedResult,automationToken:e.response};throw new Error(R.INTERNAL_SERVER_ERROR)}async function me(e){if(!$())throw new Error(R.NOT_INITIALIZED);if(!ye())throw new Error(R.MISSING_CREDENTIALS);try{let t=await Ze();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,visitorId:e.visitorId||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await he({url:`${pe}/client/verify/get-results`,body:{...r},headers:{"client-id":q,"x-api-key":K}});if(n?.results?.dtectScore)return n}throw new Error}catch{throw new Error(R.FAILED_TO_GET_SECURITY_RESULT)}}async function Ee(e){if(!$())throw new Error(R.NOT_INITIALIZED);if(!ye())throw new Error(R.MISSING_CREDENTIALS);try{let t=await Ze();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,visitorId:e.visitorId||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await he({url:`${pe}/client/verify/get-token`,body:{...r},headers:{"client-id":q,"x-api-key":K}});if(n?.token)return n}throw new Error}catch{throw new Error(R.FAILED_TO_GET_SECURITY_TOKEN)}}X={init:ze,getSecurityResult:me,getSecurityToken:Ee};var Zt=X;
|
|
1
|
+
"use strict";var J=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var it=(e,t)=>{for(var r in t)J(e,r,{get:t[r],enumerable:!0})},ot=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of rt(t))!nt.call(e,i)&&i!==r&&J(e,i,{get:()=>t[i],enumerable:!(n=tt(t,i))||n.enumerable});return e};var st=e=>ot(J({},"__esModule",{value:!0}),e);var tr={};it(tr,{SecurityAPIError:()=>ze,default:()=>er,getSecurityResult:()=>Ee,getSecurityToken:()=>me,init:()=>Je});module.exports=st(tr);var S=function(){return S=Object.assign||function(t){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},S.apply(this,arguments)};function Re(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r}function Te(e,t,r){if(r||arguments.length===2)for(var n=0,i=t.length,s;n<i;n++)(s||!(n in t))&&(s||(s=Array.prototype.slice.call(t,0,n)),s[n]=t[n]);return e.concat(s||Array.prototype.slice.call(t))}function at(e,t){return function(r,n){return Object.prototype.hasOwnProperty.call(r,n)}(e,t)?e[t]:void 0}function ut(e,t,r,n){var i,s=document,u="securitypolicyviolation",o=function(y){var l=new URL(e,location.href),h=y.blockedURI;h!==l.href&&h!==l.protocol.slice(0,-1)&&h!==l.origin||(i=y,a())};s.addEventListener(u,o);var a=function(){return s.removeEventListener(u,o)};return n?.then(a,a),Promise.resolve().then(t).then(function(y){return a(),y},function(y){return new Promise(function(l){var h=new MessageChannel;h.port1.onmessage=function(){return l()},h.port2.postMessage(null)}).then(function(){if(a(),i)return r(i);throw y})})}var ct={default:"endpoint"},lt={default:"tlsEndpoint"},ft="Client timeout",ht="Network connection error",dt="Network request aborted",pt="Response cannot be parsed",Z="Blocked by CSP",H="The endpoint parameter is not a valid URL";function A(e){for(var t="",r=0;r<e.length;++r)if(r>0){var n=e[r].toLowerCase();n!==e[r]?t+=" ".concat(n):t+=e[r]}else t+=e[r].toUpperCase();return t}var yt=A("WrongRegion"),Et=A("SubscriptionNotActive"),mt=A("UnsupportedVersion"),Rt=A("InstallationMethodRestricted"),Tt=A("HostnameRestricted"),Ot=A("IntegrationFailed"),ee="API key required",Oe="API key not found",Ie="API key expired",It="Request cannot be parsed",vt="Request failed",_t="Request failed to process",bt="Too many requests, rate limit exceeded",gt="Not available for this origin",wt="Not available with restricted header",At=ee,Pt=Oe,Dt=Ie,Nt="3.11.6",K="Failed to load the JS script of the agent",te="9319";function St(e,t){var r,n,i,s,u,o,a,y=[],l=(r=function(f){var c=Te([],f,!0);return{current:function(){return c[0]},postpone:function(){var d=c.shift();d!==void 0&&c.push(d)},exclude:function(){c.shift()}}}(e),s=100,u=3e3,o=0,n=function(){return Math.random()*Math.min(u,s*Math.pow(2,o++))},i=new Set,[r.current(),function(f,c){var d,p=c instanceof Error?c.message:"";if(p===Z||p===H)r.exclude(),d=0;else if(p===te)r.exclude();else if(p===K){var T=Date.now()-f.getTime()<50,O=r.current();O&&T&&!i.has(O)&&(i.add(O),d=0),r.postpone()}else r.postpone();var b=r.current();return b===void 0?void 0:[b,d??f.getTime()+n()-Date.now()]}]),h=l[0],v=l[1];if(h===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var _=function(f){var c=new Date,d=function(T){return y.push({url:f,startedAt:c,finishedAt:new Date,error:T})},p=t(f);return p.then(function(){return d()},d),p.catch(function(T){if(a!=null||(a=T),y.length>=5)throw a;var O=v(c,T);if(!O)throw a;var b,z=O[0],He=O[1];return(b=He,new Promise(function(et){return setTimeout(et,b)})).then(function(){return _(z)})})};return _(h).then(function(f){return[f,y]})}var ve="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",xt=ve;function Mt(e){var t;e.scriptUrlPattern;var r=e.token,n=e.apiKey,i=n===void 0?r:n,s=Re(e,["scriptUrlPattern","token","apiKey"]),u=(t=at(e,"scriptUrlPattern"))!==null&&t!==void 0?t:ve,o=function(){var l=[],h=function(){l.push({time:new Date,state:document.visibilityState})},v=function(_,f,c,d){return _.addEventListener(f,c,d),function(){return _.removeEventListener(f,c,d)}}(document,"visibilitychange",h);return h(),[l,v]}(),a=o[0],y=o[1];return Promise.resolve().then(function(){if(!i||typeof i!="string")throw new Error(ee);var l=function(h,v){return(Array.isArray(h)?h:[h]).map(function(_){return function(f,c){var d=encodeURIComponent;return f.replace(/<[^<>]+>/g,function(p){return p==="<version>"?"3":p==="<apiKey>"?d(c):p==="<loaderVersion>"?d(Nt):p})}(String(_),v)})}(u,i);return St(l,Ft)}).catch(function(l){throw y(),function(h){return h instanceof Error&&h.message===te?new Error(K):h}(l)}).then(function(l){var h=l[0],v=l[1];return y(),h.load(S(S({},s),{ldi:{attempts:v,visibilityStates:a}}))})}function Ft(e){return ut(e,function(){return function(t){return new Promise(function(r,n){if(function(o){if(URL.prototype)try{return new URL(o,location.href),!1}catch(a){if(a instanceof Error&&a.name==="TypeError")return!0;throw a}}(t))throw new Error(H);var i=document.createElement("script"),s=function(){var o;return(o=i.parentNode)===null||o===void 0?void 0:o.removeChild(i)},u=document.head||document.getElementsByTagName("head")[0];i.onload=function(){s(),r()},i.onerror=function(){s(),n(new Error(K))},i.async=!0,i.src=t,u.appendChild(i)})}(e)},function(){throw new Error(Z)}).then(Lt)}function Lt(){var e=window,t="__fpjs_p_l_b",r=e[t];if(function(n,i){var s,u=(s=Object.getOwnPropertyDescriptor)===null||s===void 0?void 0:s.call(Object,n,i);u?.configurable?delete n[i]:u&&!u.writable||(n[i]=void 0)}(e,t),typeof r?.load!="function")throw new Error(te);return r}var k={load:Mt,defaultScriptUrlPattern:xt,ERROR_SCRIPT_LOAD_FAIL:K,ERROR_API_KEY_EXPIRED:Ie,ERROR_API_KEY_INVALID:Oe,ERROR_API_KEY_MISSING:ee,ERROR_BAD_REQUEST_FORMAT:It,ERROR_BAD_RESPONSE_FORMAT:pt,ERROR_CLIENT_TIMEOUT:ft,ERROR_CSP_BLOCK:Z,ERROR_FORBIDDEN_ENDPOINT:Tt,ERROR_FORBIDDEN_HEADER:wt,ERROR_FORBIDDEN_ORIGIN:gt,ERROR_GENERAL_SERVER_FAILURE:vt,ERROR_INSTALLATION_METHOD_RESTRICTED:Rt,ERROR_INTEGRATION_FAILURE:Ot,ERROR_INVALID_ENDPOINT:H,ERROR_NETWORK_ABORT:dt,ERROR_NETWORK_CONNECTION:ht,ERROR_RATE_LIMIT:bt,ERROR_SERVER_TIMEOUT:_t,ERROR_SUBSCRIPTION_NOT_ACTIVE:Et,ERROR_TOKEN_EXPIRED:Dt,ERROR_TOKEN_INVALID:Pt,ERROR_TOKEN_MISSING:At,ERROR_UNSUPPORTED_VERSION:mt,ERROR_WRONG_REGION:yt,defaultEndpoint:ct,defaultTlsEndpoint:lt};var R=[];for(let e=0;e<256;++e)R.push((e+256).toString(16).slice(1));function _e(e,t=0){return(R[e[t+0]]+R[e[t+1]]+R[e[t+2]]+R[e[t+3]]+"-"+R[e[t+4]]+R[e[t+5]]+"-"+R[e[t+6]]+R[e[t+7]]+"-"+R[e[t+8]]+R[e[t+9]]+"-"+R[e[t+10]]+R[e[t+11]]+R[e[t+12]]+R[e[t+13]]+R[e[t+14]]+R[e[t+15]]).toLowerCase()}var re,Ut=new Uint8Array(16);function ne(){if(!re){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");re=crypto.getRandomValues.bind(crypto)}return re(Ut)}var qt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ie={randomUUID:qt};function jt(e,t,r){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();e=e||{};let n=e.random??e.rng?.()??ne();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){if(r=r||0,r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let i=0;i<16;++i)t[r+i]=n[i];return t}return _e(n)}var Q=jt;var Kt={UNAUTHORIZED:"Unauthorized"},kt={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},be={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key"},ge={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},we={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},Ae={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},Pe={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},m={...Kt,...kt,...be,...ge,...we,...Ae,...Pe},De={...be,...ge,...we,...Ae,...Pe};var g=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var w=typeof window>"u"||"Deno"in globalThis;function I(){}function xe(e,t){return typeof e=="function"?e(t):e}function Me(e){return typeof e=="number"&&e>=0&&e!==1/0}function Fe(e,t){return Math.max(e+(t||0)-Date.now(),0)}function se(e,t){return typeof e=="function"?e(t):e}function Le(e,t){return typeof e=="function"?e(t):e}function ae(e,t){let{type:r="all",exact:n,fetchStatus:i,predicate:s,queryKey:u,stale:o}=e;if(u){if(n){if(t.queryHash!==x(u,t.options))return!1}else if(!D(t.queryKey,u))return!1}if(r!=="all"){let a=t.isActive();if(r==="active"&&!a||r==="inactive"&&a)return!1}return!(typeof o=="boolean"&&t.isStale()!==o||i&&i!==t.state.fetchStatus||s&&!s(t))}function ue(e,t){let{exact:r,status:n,predicate:i,mutationKey:s}=e;if(s){if(!t.options.mutationKey)return!1;if(r){if(P(t.options.mutationKey)!==P(s))return!1}else if(!D(t.options.mutationKey,s))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function x(e,t){return(t?.queryKeyHashFn||P)(e)}function P(e){return JSON.stringify(e,(t,r)=>oe(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}function D(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!D(e[r],t[r])):!1}function Ue(e,t){if(e===t)return e;let r=Ne(e)&&Ne(t);if(r||oe(e)&&oe(t)){let n=r?e:Object.keys(e),i=n.length,s=r?t:Object.keys(t),u=s.length,o=r?[]:{},a=0;for(let y=0;y<u;y++){let l=r?y:s[y];(!r&&n.includes(l)||r)&&e[l]===void 0&&t[l]===void 0?(o[l]=void 0,a++):(o[l]=Ue(e[l],t[l]),o[l]===e[l]&&e[l]!==void 0&&a++)}return i===u&&a===i?e:o}return t}function Ne(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function oe(e){if(!Se(e))return!1;let t=e.constructor;if(t===void 0)return!0;let r=t.prototype;return!(!Se(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function Se(e){return Object.prototype.toString.call(e)==="[object Object]"}function qe(e){return new Promise(t=>{setTimeout(t,e)})}function je(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?Ue(e,t):t}function Ke(e,t,r=0){let n=[...e,t];return r&&n.length>r?n.slice(1):n}function ke(e,t,r=0){let n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var M=Symbol();function G(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===M?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var Qt=class extends g{#e;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},B=new Qt;var Gt=class extends g{#e=!0;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e(!0),r=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(r=>{r(e)}))}isOnline(){return this.#e}},N=new Gt;function Qe(){let e,t,r=new Promise((i,s)=>{e=i,t=s});r.status="pending",r.catch(()=>{});function n(i){Object.assign(r,i),delete r.resolve,delete r.reject}return r.resolve=i=>{n({status:"fulfilled",value:i}),e(i)},r.reject=i=>{n({status:"rejected",reason:i}),t(i)},r}function Bt(e){return Math.min(1e3*2**e,3e4)}function ce(e){return(e??"online")==="online"?N.isOnline():!0}var Ge=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function V(e){return e instanceof Ge}function C(e){let t=!1,r=0,n=!1,i,s=Qe(),u=c=>{n||(v(new Ge(c)),e.abort?.())},o=()=>{t=!0},a=()=>{t=!1},y=()=>B.isFocused()&&(e.networkMode==="always"||N.isOnline())&&e.canRun(),l=()=>ce(e.networkMode)&&e.canRun(),h=c=>{n||(n=!0,e.onSuccess?.(c),i?.(),s.resolve(c))},v=c=>{n||(n=!0,e.onError?.(c),i?.(),s.reject(c))},_=()=>new Promise(c=>{i=d=>{(n||y())&&c(d)},e.onPause?.()}).then(()=>{i=void 0,n||e.onContinue?.()}),f=()=>{if(n)return;let c,d=r===0?e.initialPromise:void 0;try{c=d??e.fn()}catch(p){c=Promise.reject(p)}Promise.resolve(c).then(h).catch(p=>{if(n)return;let T=e.retry??(w?0:3),O=e.retryDelay??Bt,b=typeof O=="function"?O(r,p):O,z=T===!0||typeof T=="number"&&r<T||typeof T=="function"&&T(r,p);if(t||!z){v(p);return}r++,e.onFail?.(r,p),qe(b).then(()=>y()?void 0:_()).then(()=>{t?v(p):f()})})};return{promise:s,cancel:u,continue:()=>(i?.(),s),cancelRetry:o,continueRetry:a,canStart:l,start:()=>(l()?f():_().then(f),s)}}function Vt(){let e=[],t=0,r=o=>{o()},n=o=>{o()},i=o=>setTimeout(o,0),s=o=>{t?e.push(o):i(()=>{r(o)})},u=()=>{let o=e;e=[],o.length&&i(()=>{n(()=>{o.forEach(a=>{r(a)})})})};return{batch:o=>{let a;t++;try{a=o()}finally{t--,t||u()}return a},batchCalls:o=>(...a)=>{s(()=>{o(...a)})},schedule:s,setNotifyFunction:o=>{r=o},setBatchNotifyFunction:o=>{n=o},setScheduler:o=>{i=o}}}var E=Vt();var Y=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Me(this.gcTime)&&(this.#e=setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(w?1/0:5*60*1e3))}clearGcTimeout(){this.#e&&(clearTimeout(this.#e),this.#e=void 0)}};var Be=class extends Y{#e;#t;#r;#n;#s;#o;constructor(e){super(),this.#o=!1,this.#s=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=Yt(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#n?.promise}setOptions(e){this.options={...this.#s,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let r=je(this.state.data,e,this.options);return this.#i({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#i({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(I).catch(I):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>Le(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===M||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(e=0){return this.state.isInvalidated||this.state.data===void 0||!Fe(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#n?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#n?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#n&&(this.#o?this.#n.cancel({revert:!0}):this.#n.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#i({type:"invalidate"})}fetch(e,t){if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#n)return this.#n.continueRetry(),this.#n.promise}if(e&&this.setOptions(e),!this.options.queryFn){let o=this.observers.find(a=>a.options.queryFn);o&&this.setOptions(o.options)}let r=new AbortController,n=o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(this.#o=!0,r.signal)})},i=()=>{let o=G(this.options,t),a={queryKey:this.queryKey,meta:this.meta};return n(a),this.#o=!1,this.options.persister?this.options.persister(o,a,this):o(a)},s={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};n(s),this.options.behavior?.onFetch(s,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==s.fetchOptions?.meta)&&this.#i({type:"fetch",meta:s.fetchOptions?.meta});let u=o=>{V(o)&&o.silent||this.#i({type:"error",error:o}),V(o)||(this.#r.config.onError?.(o,this),this.#r.config.onSettled?.(this.state.data,o,this)),this.scheduleGc()};return this.#n=C({initialPromise:t?.initialPromise,fn:s.fetchFn,abort:r.abort.bind(r),onSuccess:o=>{if(o===void 0){u(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(o)}catch(a){u(a);return}this.#r.config.onSuccess?.(o,this),this.#r.config.onSettled?.(o,this.state.error,this),this.scheduleGc()},onError:u,onFail:(o,a)=>{this.#i({type:"failed",failureCount:o,error:a})},onPause:()=>{this.#i({type:"pause"})},onContinue:()=>{this.#i({type:"continue"})},retry:s.options.retry,retryDelay:s.options.retryDelay,networkMode:s.options.networkMode,canRun:()=>!0}),this.#n.start()}#i(e){let t=r=>{switch(e.type){case"failed":return{...r,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...Ct(r.data,this.options),fetchMeta:e.meta??null};case"success":return{...r,data:e.data,dataUpdateCount:r.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":let n=e.error;return V(n)&&n.revert&&this.#t?{...this.#t,fetchStatus:"idle"}:{...r,error:n,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...e.state}}};this.state=t(this.state),E.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Ct(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:ce(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function Yt(e){let t=typeof e.initialData=="function"?e.initialData():e.initialData,r=t!==void 0,n=r?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var F=class extends g{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,r){let n=t.queryKey,i=t.queryHash??x(n,t),s=this.get(i);return s||(s=new Be({cache:this,queryKey:n,queryHash:i,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(n)}),this.add(s)),s}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){E.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(r=>ae(t,r))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(r=>ae(e,r)):t}notify(e){E.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){E.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){E.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var Ve=class extends Y{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||Wt(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#e.includes(e)||(this.#e.push(e),this.clearGcTimeout(),this.#t.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#e=this.#e.filter(t=>t!==e),this.scheduleGc(),this.#t.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#t.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){this.#r=C({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(n,i)=>{this.#n({type:"failed",failureCount:n,error:i})},onPause:()=>{this.#n({type:"pause"})},onContinue:()=>{this.#n({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#t.canRun(this)});let t=this.state.status==="pending",r=!this.#r.canStart();try{if(!t){this.#n({type:"pending",variables:e,isPaused:r}),await this.#t.config.onMutate?.(e,this);let i=await this.options.onMutate?.(e);i!==this.state.context&&this.#n({type:"pending",context:i,variables:e,isPaused:r})}let n=await this.#r.start();return await this.#t.config.onSuccess?.(n,e,this.state.context,this),await this.options.onSuccess?.(n,e,this.state.context),await this.#t.config.onSettled?.(n,null,this.state.variables,this.state.context,this),await this.options.onSettled?.(n,null,e,this.state.context),this.#n({type:"success",data:n}),n}catch(n){try{throw await this.#t.config.onError?.(n,e,this.state.context,this),await this.options.onError?.(n,e,this.state.context),await this.#t.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this),await this.options.onSettled?.(void 0,n,e,this.state.context),n}finally{this.#n({type:"error",error:n})}}finally{this.#t.runNext(this)}}#n(e){let t=r=>{switch(e.type){case"failed":return{...r,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...r,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:e.error,failureCount:r.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),E.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function Wt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var L=class extends g{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#r=0}#e;#t;#r;build(e,t,r){let n=new Ve({mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:r});return this.add(n),n}add(e){this.#e.add(e);let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);r?r.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);if(r)if(r.length>1){let n=r.indexOf(e);n!==-1&&r.splice(n,1)}else r[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){let t=W(e);if(typeof t=="string"){let n=this.#t.get(t)?.find(i=>i.state.status==="pending");return!n||n===e}else return!0}runNext(e){let t=W(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){E.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(r=>ue(t,r))}findAll(e={}){return this.getAll().filter(t=>ue(e,t))}notify(e){E.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return E.batch(()=>Promise.all(e.map(t=>t.continue().catch(I))))}};function W(e){return e.options.scope?.id}function le(e){return{onFetch:(t,r)=>{let n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,s=t.state.data?.pages||[],u=t.state.data?.pageParams||[],o={pages:[],pageParams:[]},a=0,y=async()=>{let l=!1,h=f=>{Object.defineProperty(f,"signal",{enumerable:!0,get:()=>(t.signal.aborted?l=!0:t.signal.addEventListener("abort",()=>{l=!0}),t.signal)})},v=G(t.options,t.fetchOptions),_=async(f,c,d)=>{if(l)return Promise.reject();if(c==null&&f.pages.length)return Promise.resolve(f);let p={queryKey:t.queryKey,pageParam:c,direction:d?"backward":"forward",meta:t.options.meta};h(p);let T=await v(p),{maxPages:O}=t.options,b=d?ke:Ke;return{pages:b(f.pages,T,O),pageParams:b(f.pageParams,c,O)}};if(i&&s.length){let f=i==="backward",c=f?Xt:Ce,d={pages:s,pageParams:u},p=c(n,d);o=await _(d,p,f)}else{let f=e??s.length;do{let c=a===0?u[0]??n.initialPageParam:Ce(n,o);if(a>0&&c==null)break;o=await _(o,c),a++}while(a<f)}return o};t.options.persister?t.fetchFn=()=>t.options.persister?.(y,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=y}}}function Ce(e,{pages:t,pageParams:r}){let n=t.length-1;return t.length>0?e.getNextPageParam(t[n],t,r[n],r):void 0}function Xt(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var fe=class{#e;#t;#r;#n;#s;#o;#i;#a;constructor(e={}){this.#e=e.queryCache||new F,this.#t=e.mutationCache||new L,this.#r=e.defaultOptions||{},this.#n=new Map,this.#s=new Map,this.#o=0}mount(){this.#o++,this.#o===1&&(this.#i=B.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=N.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#o--,this.#o===0&&(this.#i?.(),this.#i=void 0,this.#a?.(),this.#a=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),r=this.#e.build(this,t),n=r.state.data;return n===void 0?this.fetchQuery(e):(e.revalidateIfStale&&r.isStaleByTime(se(t.staleTime,r))&&this.prefetchQuery(t),Promise.resolve(n))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:r})=>{let n=r.data;return[t,n]})}setQueryData(e,t,r){let n=this.defaultQueryOptions({queryKey:e}),s=this.#e.get(n.queryHash)?.state.data,u=xe(t,s);if(u!==void 0)return this.#e.build(this,n).setData(u,{...r,manual:!0})}setQueriesData(e,t,r){return E.batch(()=>this.#e.findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,r)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;E.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){let r=this.#e,n={type:"active",...e};return E.batch(()=>(r.findAll(e).forEach(i=>{i.reset()}),this.refetchQueries(n,t)))}cancelQueries(e,t={}){let r={revert:!0,...t},n=E.batch(()=>this.#e.findAll(e).map(i=>i.cancel(r)));return Promise.all(n).then(I).catch(I)}invalidateQueries(e,t={}){return E.batch(()=>{if(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none")return Promise.resolve();let r={...e,type:e?.refetchType??e?.type??"active"};return this.refetchQueries(r,t)})}refetchQueries(e,t={}){let r={...t,cancelRefetch:t.cancelRefetch??!0},n=E.batch(()=>this.#e.findAll(e).filter(i=>!i.isDisabled()).map(i=>{let s=i.fetch(void 0,r);return r.throwOnError||(s=s.catch(I)),i.state.fetchStatus==="paused"?Promise.resolve():s}));return Promise.all(n).then(I)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let r=this.#e.build(this,t);return r.isStaleByTime(se(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(I).catch(I)}fetchInfiniteQuery(e){return e.behavior=le(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(I).catch(I)}ensureInfiniteQueryData(e){return e.behavior=le(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return N.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#n.set(P(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#n.values()],r={};return t.forEach(n=>{D(e,n.queryKey)&&Object.assign(r,n.defaultOptions)}),r}setMutationDefaults(e,t){this.#s.set(P(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#s.values()],r={};return t.forEach(n=>{D(e,n.mutationKey)&&(r={...r,...n.defaultOptions})}),r}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=x(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===M&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};var $t=new fe({defaultOptions:{queries:{staleTime:3e4}},queryCache:new F({onError:(e,t)=>{}}),mutationCache:new L}),Ye=$t;var zt=(e,t={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...t}),Jt=async(e,t)=>{if(!e.ok){let r=await e.text();throw new Error(r)}return t==="file"?e.blob():t==="json"?e.json():t==="text"?e.text():null},We=async({url:e,auth:t,body:r,method:n="GET",headers:i={},responseType:s="json"})=>{let u={method:n,headers:zt(t,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},o=await fetch(e,u);return Jt(o,s)},Xe=e=>We({...e,method:"GET"}),he=e=>We({...e,method:"POST"});var de,pe="https://api.dtect.io/security",q="",j="",$e="",Zt="20000000-aaaa-bbbb-cccc-000000000002",X,U={isLoading:!1},ze=De;function $(){return!!(document.querySelector("#dtect-h-captcha")&&de)}function ye(){return!!(q&&j)}async function Ht({behaviorKey:e}){let t=await k.load({apiKey:e,endpoint:["https://fp.dtect.io",k.defaultEndpoint],scriptUrlPattern:["https://fp.dtect.io/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",k.defaultScriptUrlPattern]});if(t)de=t;else throw new Error(m.SDK_INIT_ERROR)}async function Je(e){if(!e?.clientId||!e?.apiKey)throw new Error(m.MISSING_CREDENTIALS);let{clientId:t,apiKey:r,endpoint:n="https://api.dtect.io/security"}=e;if(pe=n,U.isLoading){if($())return X;throw new Error(m.DUPLICATE_INITIALIZATION)}if(q=t,j=r,U={...U,isLoading:!0},!ye())throw new Error(m.MISSING_CREDENTIALS);if($())return X;let i=document.querySelector("head");document.querySelector("body")?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let u=document.createElement("script");u.setAttribute("src","https://js.hcaptcha.com/1/api.js"),u.setAttribute("async","true"),u.setAttribute("defer","true"),i?.append(u);try{let o=await Ye.fetchQuery({queryKey:["getKeys",t,r],queryFn:()=>Xe({url:`${n}/client/config`,headers:{"client-id":q,"x-api-key":j}})});if(o?.automationKey&&o?.behaviorKey)return $e=o.automationKey,Ht({...o}).then(()=>({getSecurityResult:Ee,getSecurityToken:me,SecurityAPIError:ze})).catch(a=>{throw new Error(a.message)});throw new Error}catch(o){throw o instanceof Error&&[m.INVALID_API_KEY,m.UNAUTHORIZED].includes(o?.message)?new Error(m.INVALID_CREDENTIALS):new Error(m.SDK_INIT_ERROR)}finally{U={...U,isLoading:!1}}}async function Ze(){let e=await de?.get();if(window?.location?.href?.includes("localhost")){if(e?.sealedResult&&e?.requestId)return{behaviorRequestId:e.requestId,behaviorToken:e.sealedResult,automationToken:Zt}}else{await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:$e,size:"invisible"});let t=await window?.hcaptcha?.execute({async:!0});if(t?.response&&e?.sealedResult&&e?.requestId)return{behaviorRequestId:e.requestId,behaviorToken:e.sealedResult,automationToken:t.response}}throw new Error(m.INTERNAL_SERVER_ERROR)}async function Ee(e){if(!$())throw new Error(m.NOT_INITIALIZED);if(!ye())throw new Error(m.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(m.FAILED_TO_GET_SECURITY_RESULT);try{let t=await Ze();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,projectId:e?.projectId?.trim(),visitorId:e?.visitorId?.trim()||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await he({url:`${pe}/client/check/results`,body:{...r},headers:{"client-id":q,"x-api-key":j}});if(n?.results?.dtectScore)return n}throw new Error}catch{throw new Error(m.FAILED_TO_GET_SECURITY_RESULT)}}async function me(e){if(!$())throw new Error(m.NOT_INITIALIZED);if(!ye())throw new Error(m.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(m.FAILED_TO_GET_SECURITY_TOKEN);try{let t=await Ze();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,projectId:e.projectId?.trim(),visitorId:e.visitorId?.trim()||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await he({url:`${pe}/client/check/token`,body:{...r},headers:{"client-id":q,"x-api-key":j}});if(n?.token)return n}throw new Error}catch{throw new Error(m.FAILED_TO_GET_SECURITY_TOKEN)}}X={init:Je,getSecurityResult:Ee,getSecurityToken:me};var er=X;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var S=function(){return S=Object.assign||function(t){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},S.apply(this,arguments)};function ye(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r}function me(e,t,r){if(r||arguments.length===2)for(var n=0,i=t.length,s;n<i;n++)(s||!(n in t))&&(s||(s=Array.prototype.slice.call(t,0,n)),s[n]=t[n]);return e.concat(s||Array.prototype.slice.call(t))}function Ze(e,t){return function(r,n){return Object.prototype.hasOwnProperty.call(r,n)}(e,t)?e[t]:void 0}function He(e,t,r,n){var i,s=document,u="securitypolicyviolation",o=function(y){var l=new URL(e,location.href),h=y.blockedURI;h!==l.href&&h!==l.protocol.slice(0,-1)&&h!==l.origin||(i=y,a())};s.addEventListener(u,o);var a=function(){return s.removeEventListener(u,o)};return n?.then(a,a),Promise.resolve().then(t).then(function(y){return a(),y},function(y){return new Promise(function(l){var h=new MessageChannel;h.port1.onmessage=function(){return l()},h.port2.postMessage(null)}).then(function(){if(a(),i)return r(i);throw y})})}var et={default:"endpoint"},tt={default:"tlsEndpoint"},rt="Client timeout",nt="Network connection error",it="Network request aborted",ot="Response cannot be parsed",z="Blocked by CSP",Z="The endpoint parameter is not a valid URL";function P(e){for(var t="",r=0;r<e.length;++r)if(r>0){var n=e[r].toLowerCase();n!==e[r]?t+=" ".concat(n):t+=e[r]}else t+=e[r].toUpperCase();return t}var st=P("WrongRegion"),at=P("SubscriptionNotActive"),ut=P("UnsupportedVersion"),ct=P("InstallationMethodRestricted"),lt=P("HostnameRestricted"),ft=P("IntegrationFailed"),H="API key required",Ee="API key not found",Re="API key expired",ht="Request cannot be parsed",dt="Request failed",pt="Request failed to process",yt="Too many requests, rate limit exceeded",mt="Not available for this origin",Et="Not available with restricted header",Rt=H,Ot=Ee,Tt=Re,vt="3.11.6",j="Failed to load the JS script of the agent",ee="9319";function It(e,t){var r,n,i,s,u,o,a,y=[],l=(r=function(f){var c=me([],f,!0);return{current:function(){return c[0]},postpone:function(){var d=c.shift();d!==void 0&&c.push(d)},exclude:function(){c.shift()}}}(e),s=100,u=3e3,o=0,n=function(){return Math.random()*Math.min(u,s*Math.pow(2,o++))},i=new Set,[r.current(),function(f,c){var d,p=c instanceof Error?c.message:"";if(p===z||p===Z)r.exclude(),d=0;else if(p===ee)r.exclude();else if(p===j){var O=Date.now()-f.getTime()<50,T=r.current();T&&O&&!i.has(T)&&(i.add(T),d=0),r.postpone()}else r.postpone();var g=r.current();return g===void 0?void 0:[g,d??f.getTime()+n()-Date.now()]}]),h=l[0],I=l[1];if(h===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var _=function(f){var c=new Date,d=function(O){return y.push({url:f,startedAt:c,finishedAt:new Date,error:O})},p=t(f);return p.then(function(){return d()},d),p.catch(function(O){if(a!=null||(a=O),y.length>=5)throw a;var T=I(c,O);if(!T)throw a;var g,J=T[0],Je=T[1];return(g=Je,new Promise(function(ze){return setTimeout(ze,g)})).then(function(){return _(J)})})};return _(h).then(function(f){return[f,y]})}var Oe="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",_t=Oe;function gt(e){var t;e.scriptUrlPattern;var r=e.token,n=e.apiKey,i=n===void 0?r:n,s=ye(e,["scriptUrlPattern","token","apiKey"]),u=(t=Ze(e,"scriptUrlPattern"))!==null&&t!==void 0?t:Oe,o=function(){var l=[],h=function(){l.push({time:new Date,state:document.visibilityState})},I=function(_,f,c,d){return _.addEventListener(f,c,d),function(){return _.removeEventListener(f,c,d)}}(document,"visibilitychange",h);return h(),[l,I]}(),a=o[0],y=o[1];return Promise.resolve().then(function(){if(!i||typeof i!="string")throw new Error(H);var l=function(h,I){return(Array.isArray(h)?h:[h]).map(function(_){return function(f,c){var d=encodeURIComponent;return f.replace(/<[^<>]+>/g,function(p){return p==="<version>"?"3":p==="<apiKey>"?d(c):p==="<loaderVersion>"?d(vt):p})}(String(_),I)})}(u,i);return It(l,bt)}).catch(function(l){throw y(),function(h){return h instanceof Error&&h.message===ee?new Error(j):h}(l)}).then(function(l){var h=l[0],I=l[1];return y(),h.load(S(S({},s),{ldi:{attempts:I,visibilityStates:a}}))})}function bt(e){return He(e,function(){return function(t){return new Promise(function(r,n){if(function(o){if(URL.prototype)try{return new URL(o,location.href),!1}catch(a){if(a instanceof Error&&a.name==="TypeError")return!0;throw a}}(t))throw new Error(Z);var i=document.createElement("script"),s=function(){var o;return(o=i.parentNode)===null||o===void 0?void 0:o.removeChild(i)},u=document.head||document.getElementsByTagName("head")[0];i.onload=function(){s(),r()},i.onerror=function(){s(),n(new Error(j))},i.async=!0,i.src=t,u.appendChild(i)})}(e)},function(){throw new Error(z)}).then(wt)}function wt(){var e=window,t="__fpjs_p_l_b",r=e[t];if(function(n,i){var s,u=(s=Object.getOwnPropertyDescriptor)===null||s===void 0?void 0:s.call(Object,n,i);u?.configurable?delete n[i]:u&&!u.writable||(n[i]=void 0)}(e,t),typeof r?.load!="function")throw new Error(ee);return r}var k={load:gt,defaultScriptUrlPattern:_t,ERROR_SCRIPT_LOAD_FAIL:j,ERROR_API_KEY_EXPIRED:Re,ERROR_API_KEY_INVALID:Ee,ERROR_API_KEY_MISSING:H,ERROR_BAD_REQUEST_FORMAT:ht,ERROR_BAD_RESPONSE_FORMAT:ot,ERROR_CLIENT_TIMEOUT:rt,ERROR_CSP_BLOCK:z,ERROR_FORBIDDEN_ENDPOINT:lt,ERROR_FORBIDDEN_HEADER:Et,ERROR_FORBIDDEN_ORIGIN:mt,ERROR_GENERAL_SERVER_FAILURE:dt,ERROR_INSTALLATION_METHOD_RESTRICTED:ct,ERROR_INTEGRATION_FAILURE:ft,ERROR_INVALID_ENDPOINT:Z,ERROR_NETWORK_ABORT:it,ERROR_NETWORK_CONNECTION:nt,ERROR_RATE_LIMIT:yt,ERROR_SERVER_TIMEOUT:pt,ERROR_SUBSCRIPTION_NOT_ACTIVE:at,ERROR_TOKEN_EXPIRED:Tt,ERROR_TOKEN_INVALID:Ot,ERROR_TOKEN_MISSING:Rt,ERROR_UNSUPPORTED_VERSION:ut,ERROR_WRONG_REGION:st,defaultEndpoint:et,defaultTlsEndpoint:tt};var E=[];for(let e=0;e<256;++e)E.push((e+256).toString(16).slice(1));function Te(e,t=0){return(E[e[t+0]]+E[e[t+1]]+E[e[t+2]]+E[e[t+3]]+"-"+E[e[t+4]]+E[e[t+5]]+"-"+E[e[t+6]]+E[e[t+7]]+"-"+E[e[t+8]]+E[e[t+9]]+"-"+E[e[t+10]]+E[e[t+11]]+E[e[t+12]]+E[e[t+13]]+E[e[t+14]]+E[e[t+15]]).toLowerCase()}var te,Pt=new Uint8Array(16);function re(){if(!te){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");te=crypto.getRandomValues.bind(crypto)}return te(Pt)}var At=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ne={randomUUID:At};function Dt(e,t,r){if(ne.randomUUID&&!t&&!e)return ne.randomUUID();e=e||{};let n=e.random??e.rng?.()??re();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){if(r=r||0,r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let i=0;i<16;++i)t[r+i]=n[i];return t}return Te(n)}var Q=Dt;var Nt={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},ve={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key"},Ie={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},_e={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},ge={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},be={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},R={...Nt,...ve,...Ie,..._e,...ge,...be},we={...ve,...Ie,..._e,...ge,...be};var b=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var w=typeof window>"u"||"Deno"in globalThis;function v(){}function De(e,t){return typeof e=="function"?e(t):e}function Ne(e){return typeof e=="number"&&e>=0&&e!==1/0}function Se(e,t){return Math.max(e+(t||0)-Date.now(),0)}function oe(e,t){return typeof e=="function"?e(t):e}function xe(e,t){return typeof e=="function"?e(t):e}function se(e,t){let{type:r="all",exact:n,fetchStatus:i,predicate:s,queryKey:u,stale:o}=e;if(u){if(n){if(t.queryHash!==x(u,t.options))return!1}else if(!D(t.queryKey,u))return!1}if(r!=="all"){let a=t.isActive();if(r==="active"&&!a||r==="inactive"&&a)return!1}return!(typeof o=="boolean"&&t.isStale()!==o||i&&i!==t.state.fetchStatus||s&&!s(t))}function ae(e,t){let{exact:r,status:n,predicate:i,mutationKey:s}=e;if(s){if(!t.options.mutationKey)return!1;if(r){if(A(t.options.mutationKey)!==A(s))return!1}else if(!D(t.options.mutationKey,s))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function x(e,t){return(t?.queryKeyHashFn||A)(e)}function A(e){return JSON.stringify(e,(t,r)=>ie(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}function D(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!D(e[r],t[r])):!1}function Me(e,t){if(e===t)return e;let r=Pe(e)&&Pe(t);if(r||ie(e)&&ie(t)){let n=r?e:Object.keys(e),i=n.length,s=r?t:Object.keys(t),u=s.length,o=r?[]:{},a=0;for(let y=0;y<u;y++){let l=r?y:s[y];(!r&&n.includes(l)||r)&&e[l]===void 0&&t[l]===void 0?(o[l]=void 0,a++):(o[l]=Me(e[l],t[l]),o[l]===e[l]&&e[l]!==void 0&&a++)}return i===u&&a===i?e:o}return t}function Pe(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ie(e){if(!Ae(e))return!1;let t=e.constructor;if(t===void 0)return!0;let r=t.prototype;return!(!Ae(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function Ae(e){return Object.prototype.toString.call(e)==="[object Object]"}function Fe(e){return new Promise(t=>{setTimeout(t,e)})}function Le(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?Me(e,t):t}function Ue(e,t,r=0){let n=[...e,t];return r&&n.length>r?n.slice(1):n}function qe(e,t,r=0){let n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var M=Symbol();function G(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===M?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var St=class extends b{#e;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},B=new St;var xt=class extends b{#e=!0;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e(!0),r=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(r=>{r(e)}))}isOnline(){return this.#e}},N=new xt;function Ke(){let e,t,r=new Promise((i,s)=>{e=i,t=s});r.status="pending",r.catch(()=>{});function n(i){Object.assign(r,i),delete r.resolve,delete r.reject}return r.resolve=i=>{n({status:"fulfilled",value:i}),e(i)},r.reject=i=>{n({status:"rejected",reason:i}),t(i)},r}function Mt(e){return Math.min(1e3*2**e,3e4)}function ue(e){return(e??"online")==="online"?N.isOnline():!0}var je=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function V(e){return e instanceof je}function C(e){let t=!1,r=0,n=!1,i,s=Ke(),u=c=>{n||(I(new je(c)),e.abort?.())},o=()=>{t=!0},a=()=>{t=!1},y=()=>B.isFocused()&&(e.networkMode==="always"||N.isOnline())&&e.canRun(),l=()=>ue(e.networkMode)&&e.canRun(),h=c=>{n||(n=!0,e.onSuccess?.(c),i?.(),s.resolve(c))},I=c=>{n||(n=!0,e.onError?.(c),i?.(),s.reject(c))},_=()=>new Promise(c=>{i=d=>{(n||y())&&c(d)},e.onPause?.()}).then(()=>{i=void 0,n||e.onContinue?.()}),f=()=>{if(n)return;let c,d=r===0?e.initialPromise:void 0;try{c=d??e.fn()}catch(p){c=Promise.reject(p)}Promise.resolve(c).then(h).catch(p=>{if(n)return;let O=e.retry??(w?0:3),T=e.retryDelay??Mt,g=typeof T=="function"?T(r,p):T,J=O===!0||typeof O=="number"&&r<O||typeof O=="function"&&O(r,p);if(t||!J){I(p);return}r++,e.onFail?.(r,p),Fe(g).then(()=>y()?void 0:_()).then(()=>{t?I(p):f()})})};return{promise:s,cancel:u,continue:()=>(i?.(),s),cancelRetry:o,continueRetry:a,canStart:l,start:()=>(l()?f():_().then(f),s)}}function Ft(){let e=[],t=0,r=o=>{o()},n=o=>{o()},i=o=>setTimeout(o,0),s=o=>{t?e.push(o):i(()=>{r(o)})},u=()=>{let o=e;e=[],o.length&&i(()=>{n(()=>{o.forEach(a=>{r(a)})})})};return{batch:o=>{let a;t++;try{a=o()}finally{t--,t||u()}return a},batchCalls:o=>(...a)=>{s(()=>{o(...a)})},schedule:s,setNotifyFunction:o=>{r=o},setBatchNotifyFunction:o=>{n=o},setScheduler:o=>{i=o}}}var m=Ft();var Y=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Ne(this.gcTime)&&(this.#e=setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(w?1/0:5*60*1e3))}clearGcTimeout(){this.#e&&(clearTimeout(this.#e),this.#e=void 0)}};var ke=class extends Y{#e;#t;#r;#n;#s;#o;constructor(e){super(),this.#o=!1,this.#s=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=Ut(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#n?.promise}setOptions(e){this.options={...this.#s,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let r=Le(this.state.data,e,this.options);return this.#i({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#i({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(v).catch(v):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>xe(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===M||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(e=0){return this.state.isInvalidated||this.state.data===void 0||!Se(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#n?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#n?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#n&&(this.#o?this.#n.cancel({revert:!0}):this.#n.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#i({type:"invalidate"})}fetch(e,t){if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#n)return this.#n.continueRetry(),this.#n.promise}if(e&&this.setOptions(e),!this.options.queryFn){let o=this.observers.find(a=>a.options.queryFn);o&&this.setOptions(o.options)}let r=new AbortController,n=o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(this.#o=!0,r.signal)})},i=()=>{let o=G(this.options,t),a={queryKey:this.queryKey,meta:this.meta};return n(a),this.#o=!1,this.options.persister?this.options.persister(o,a,this):o(a)},s={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};n(s),this.options.behavior?.onFetch(s,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==s.fetchOptions?.meta)&&this.#i({type:"fetch",meta:s.fetchOptions?.meta});let u=o=>{V(o)&&o.silent||this.#i({type:"error",error:o}),V(o)||(this.#r.config.onError?.(o,this),this.#r.config.onSettled?.(this.state.data,o,this)),this.scheduleGc()};return this.#n=C({initialPromise:t?.initialPromise,fn:s.fetchFn,abort:r.abort.bind(r),onSuccess:o=>{if(o===void 0){u(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(o)}catch(a){u(a);return}this.#r.config.onSuccess?.(o,this),this.#r.config.onSettled?.(o,this.state.error,this),this.scheduleGc()},onError:u,onFail:(o,a)=>{this.#i({type:"failed",failureCount:o,error:a})},onPause:()=>{this.#i({type:"pause"})},onContinue:()=>{this.#i({type:"continue"})},retry:s.options.retry,retryDelay:s.options.retryDelay,networkMode:s.options.networkMode,canRun:()=>!0}),this.#n.start()}#i(e){let t=r=>{switch(e.type){case"failed":return{...r,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...Lt(r.data,this.options),fetchMeta:e.meta??null};case"success":return{...r,data:e.data,dataUpdateCount:r.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":let n=e.error;return V(n)&&n.revert&&this.#t?{...this.#t,fetchStatus:"idle"}:{...r,error:n,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...e.state}}};this.state=t(this.state),m.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Lt(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:ue(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function Ut(e){let t=typeof e.initialData=="function"?e.initialData():e.initialData,r=t!==void 0,n=r?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var F=class extends b{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,r){let n=t.queryKey,i=t.queryHash??x(n,t),s=this.get(i);return s||(s=new ke({cache:this,queryKey:n,queryHash:i,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(n)}),this.add(s)),s}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){m.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(r=>se(t,r))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(r=>se(e,r)):t}notify(e){m.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){m.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){m.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var Qe=class extends Y{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||qt(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#e.includes(e)||(this.#e.push(e),this.clearGcTimeout(),this.#t.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#e=this.#e.filter(t=>t!==e),this.scheduleGc(),this.#t.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#t.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){this.#r=C({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(n,i)=>{this.#n({type:"failed",failureCount:n,error:i})},onPause:()=>{this.#n({type:"pause"})},onContinue:()=>{this.#n({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#t.canRun(this)});let t=this.state.status==="pending",r=!this.#r.canStart();try{if(!t){this.#n({type:"pending",variables:e,isPaused:r}),await this.#t.config.onMutate?.(e,this);let i=await this.options.onMutate?.(e);i!==this.state.context&&this.#n({type:"pending",context:i,variables:e,isPaused:r})}let n=await this.#r.start();return await this.#t.config.onSuccess?.(n,e,this.state.context,this),await this.options.onSuccess?.(n,e,this.state.context),await this.#t.config.onSettled?.(n,null,this.state.variables,this.state.context,this),await this.options.onSettled?.(n,null,e,this.state.context),this.#n({type:"success",data:n}),n}catch(n){try{throw await this.#t.config.onError?.(n,e,this.state.context,this),await this.options.onError?.(n,e,this.state.context),await this.#t.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this),await this.options.onSettled?.(void 0,n,e,this.state.context),n}finally{this.#n({type:"error",error:n})}}finally{this.#t.runNext(this)}}#n(e){let t=r=>{switch(e.type){case"failed":return{...r,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...r,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:e.error,failureCount:r.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),m.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function qt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var L=class extends b{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#r=0}#e;#t;#r;build(e,t,r){let n=new Qe({mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:r});return this.add(n),n}add(e){this.#e.add(e);let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);r?r.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);if(r)if(r.length>1){let n=r.indexOf(e);n!==-1&&r.splice(n,1)}else r[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){let t=W(e);if(typeof t=="string"){let n=this.#t.get(t)?.find(i=>i.state.status==="pending");return!n||n===e}else return!0}runNext(e){let t=W(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){m.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(r=>ae(t,r))}findAll(e={}){return this.getAll().filter(t=>ae(e,t))}notify(e){m.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return m.batch(()=>Promise.all(e.map(t=>t.continue().catch(v))))}};function W(e){return e.options.scope?.id}function ce(e){return{onFetch:(t,r)=>{let n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,s=t.state.data?.pages||[],u=t.state.data?.pageParams||[],o={pages:[],pageParams:[]},a=0,y=async()=>{let l=!1,h=f=>{Object.defineProperty(f,"signal",{enumerable:!0,get:()=>(t.signal.aborted?l=!0:t.signal.addEventListener("abort",()=>{l=!0}),t.signal)})},I=G(t.options,t.fetchOptions),_=async(f,c,d)=>{if(l)return Promise.reject();if(c==null&&f.pages.length)return Promise.resolve(f);let p={queryKey:t.queryKey,pageParam:c,direction:d?"backward":"forward",meta:t.options.meta};h(p);let O=await I(p),{maxPages:T}=t.options,g=d?qe:Ue;return{pages:g(f.pages,O,T),pageParams:g(f.pageParams,c,T)}};if(i&&s.length){let f=i==="backward",c=f?Kt:Ge,d={pages:s,pageParams:u},p=c(n,d);o=await _(d,p,f)}else{let f=e??s.length;do{let c=a===0?u[0]??n.initialPageParam:Ge(n,o);if(a>0&&c==null)break;o=await _(o,c),a++}while(a<f)}return o};t.options.persister?t.fetchFn=()=>t.options.persister?.(y,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=y}}}function Ge(e,{pages:t,pageParams:r}){let n=t.length-1;return t.length>0?e.getNextPageParam(t[n],t,r[n],r):void 0}function Kt(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var le=class{#e;#t;#r;#n;#s;#o;#i;#a;constructor(e={}){this.#e=e.queryCache||new F,this.#t=e.mutationCache||new L,this.#r=e.defaultOptions||{},this.#n=new Map,this.#s=new Map,this.#o=0}mount(){this.#o++,this.#o===1&&(this.#i=B.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=N.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#o--,this.#o===0&&(this.#i?.(),this.#i=void 0,this.#a?.(),this.#a=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),r=this.#e.build(this,t),n=r.state.data;return n===void 0?this.fetchQuery(e):(e.revalidateIfStale&&r.isStaleByTime(oe(t.staleTime,r))&&this.prefetchQuery(t),Promise.resolve(n))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:r})=>{let n=r.data;return[t,n]})}setQueryData(e,t,r){let n=this.defaultQueryOptions({queryKey:e}),s=this.#e.get(n.queryHash)?.state.data,u=De(t,s);if(u!==void 0)return this.#e.build(this,n).setData(u,{...r,manual:!0})}setQueriesData(e,t,r){return m.batch(()=>this.#e.findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,r)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;m.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){let r=this.#e,n={type:"active",...e};return m.batch(()=>(r.findAll(e).forEach(i=>{i.reset()}),this.refetchQueries(n,t)))}cancelQueries(e,t={}){let r={revert:!0,...t},n=m.batch(()=>this.#e.findAll(e).map(i=>i.cancel(r)));return Promise.all(n).then(v).catch(v)}invalidateQueries(e,t={}){return m.batch(()=>{if(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none")return Promise.resolve();let r={...e,type:e?.refetchType??e?.type??"active"};return this.refetchQueries(r,t)})}refetchQueries(e,t={}){let r={...t,cancelRefetch:t.cancelRefetch??!0},n=m.batch(()=>this.#e.findAll(e).filter(i=>!i.isDisabled()).map(i=>{let s=i.fetch(void 0,r);return r.throwOnError||(s=s.catch(v)),i.state.fetchStatus==="paused"?Promise.resolve():s}));return Promise.all(n).then(v)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let r=this.#e.build(this,t);return r.isStaleByTime(oe(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(v).catch(v)}fetchInfiniteQuery(e){return e.behavior=ce(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(v).catch(v)}ensureInfiniteQueryData(e){return e.behavior=ce(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return N.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#n.set(A(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#n.values()],r={};return t.forEach(n=>{D(e,n.queryKey)&&Object.assign(r,n.defaultOptions)}),r}setMutationDefaults(e,t){this.#s.set(A(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#s.values()],r={};return t.forEach(n=>{D(e,n.mutationKey)&&(r={...r,...n.defaultOptions})}),r}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=x(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===M&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};var jt=new le({defaultOptions:{queries:{staleTime:3e4}},queryCache:new F({onError:(e,t)=>{}}),mutationCache:new L}),Be=jt;var kt=(e,t={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...t}),Qt=async(e,t)=>{if(!e.ok){let r=await e.text();throw new Error(r)}return t==="file"?e.blob():t==="json"?e.json():t==="text"?e.text():null},Ve=async({url:e,auth:t,body:r,method:n="GET",headers:i={},responseType:s="json"})=>{let u={method:n,headers:kt(t,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},o=await fetch(e,u);return Qt(o,s)},Ce=e=>Ve({...e,method:"GET"}),fe=e=>Ve({...e,method:"POST"});var he,de="https://api.dtect.io/security",q="",K="",Ye="",X,U={isLoading:!1},Gt=we;function $(){return!!(document.querySelector("#dtect-h-captcha")&&he)}function pe(){return!!(q&&K)}async function Bt({behaviorKey:e}){let t=await k.load({apiKey:e,endpoint:["https://fp.dtect.io",k.defaultEndpoint],scriptUrlPattern:["https://fp.dtect.io/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",k.defaultScriptUrlPattern]});if(t)he=t;else throw new Error(R.SDK_INIT_ERROR)}async function Vt(e){if(!e?.clientId||!e?.apiKey)throw new Error(R.MISSING_CREDENTIALS);let{clientId:t,apiKey:r,endpoint:n="https://api.dtect.io/security"}=e;if(de=n,U.isLoading){if($())return X;throw new Error(R.DUPLICATE_INITIALIZATION)}if(q=t,K=r,U={...U,isLoading:!0},!pe())throw new Error(R.MISSING_CREDENTIALS);if($())return X;let i=document.querySelector("head");document.querySelector("body")?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let u=document.createElement("script");u.setAttribute("src","https://js.hcaptcha.com/1/api.js?onload=onLoad"),u.setAttribute("async","true"),u.setAttribute("defer","true"),i?.append(u);try{let o=await Be.fetchQuery({queryKey:["getKeys",t,r],queryFn:()=>Ce({url:`${n}/client/get-config`,headers:{"client-id":q,"x-api-key":K}})});if(o?.automationKey&&o?.behaviorKey)return Ye=o.automationKey,Bt({...o}).then(()=>({getSecurityResult:Xe,getSecurityToken:$e,SecurityAPIError:Gt})).catch(a=>{throw new Error(a.message)});throw new Error("Empty keys")}catch(o){throw console.warn(`${JSON.stringify(o)}`),o instanceof Error&&o?.message?.includes(R.INVALID_API_KEY)?new Error(R.INVALID_CREDENTIALS):new Error(R.SDK_INIT_ERROR)}finally{U={...U,isLoading:!1}}}async function We(){await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:Ye,size:"invisible"});let e=await window?.hcaptcha?.execute({async:!0}),t=await he?.get();if(e?.response&&t?.sealedResult&&t?.requestId)return{behaviorRequestId:t.requestId,behaviorToken:t.sealedResult,automationToken:e.response};throw new Error(R.INTERNAL_SERVER_ERROR)}async function Xe(e){if(!$())throw new Error(R.NOT_INITIALIZED);if(!pe())throw new Error(R.MISSING_CREDENTIALS);try{let t=await We();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,visitorId:e.visitorId||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await fe({url:`${de}/client/verify/get-results`,body:{...r},headers:{"client-id":q,"x-api-key":K}});if(n?.results?.dtectScore)return n}throw new Error}catch{throw new Error(R.FAILED_TO_GET_SECURITY_RESULT)}}async function $e(e){if(!$())throw new Error(R.NOT_INITIALIZED);if(!pe())throw new Error(R.MISSING_CREDENTIALS);try{let t=await We();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,visitorId:e.visitorId||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await fe({url:`${de}/client/verify/get-token`,body:{...r},headers:{"client-id":q,"x-api-key":K}});if(n?.token)return n}throw new Error}catch{throw new Error(R.FAILED_TO_GET_SECURITY_TOKEN)}}X={init:Vt,getSecurityResult:Xe,getSecurityToken:$e};var Gn=X;export{Gt as SecurityAPIError,Gn as default,Xe as getSecurityResult,$e as getSecurityToken,Vt as init};
|
|
1
|
+
var S=function(){return S=Object.assign||function(t){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(t[s]=r[s])}return t},S.apply(this,arguments)};function ye(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r}function Ee(e,t,r){if(r||arguments.length===2)for(var n=0,i=t.length,s;n<i;n++)(s||!(n in t))&&(s||(s=Array.prototype.slice.call(t,0,n)),s[n]=t[n]);return e.concat(s||Array.prototype.slice.call(t))}function Ze(e,t){return function(r,n){return Object.prototype.hasOwnProperty.call(r,n)}(e,t)?e[t]:void 0}function He(e,t,r,n){var i,s=document,u="securitypolicyviolation",o=function(y){var l=new URL(e,location.href),h=y.blockedURI;h!==l.href&&h!==l.protocol.slice(0,-1)&&h!==l.origin||(i=y,a())};s.addEventListener(u,o);var a=function(){return s.removeEventListener(u,o)};return n?.then(a,a),Promise.resolve().then(t).then(function(y){return a(),y},function(y){return new Promise(function(l){var h=new MessageChannel;h.port1.onmessage=function(){return l()},h.port2.postMessage(null)}).then(function(){if(a(),i)return r(i);throw y})})}var et={default:"endpoint"},tt={default:"tlsEndpoint"},rt="Client timeout",nt="Network connection error",it="Network request aborted",ot="Response cannot be parsed",J="Blocked by CSP",Z="The endpoint parameter is not a valid URL";function A(e){for(var t="",r=0;r<e.length;++r)if(r>0){var n=e[r].toLowerCase();n!==e[r]?t+=" ".concat(n):t+=e[r]}else t+=e[r].toUpperCase();return t}var st=A("WrongRegion"),at=A("SubscriptionNotActive"),ut=A("UnsupportedVersion"),ct=A("InstallationMethodRestricted"),lt=A("HostnameRestricted"),ft=A("IntegrationFailed"),H="API key required",me="API key not found",Re="API key expired",ht="Request cannot be parsed",dt="Request failed",pt="Request failed to process",yt="Too many requests, rate limit exceeded",Et="Not available for this origin",mt="Not available with restricted header",Rt=H,Tt=me,Ot=Re,It="3.11.6",K="Failed to load the JS script of the agent",ee="9319";function vt(e,t){var r,n,i,s,u,o,a,y=[],l=(r=function(f){var c=Ee([],f,!0);return{current:function(){return c[0]},postpone:function(){var d=c.shift();d!==void 0&&c.push(d)},exclude:function(){c.shift()}}}(e),s=100,u=3e3,o=0,n=function(){return Math.random()*Math.min(u,s*Math.pow(2,o++))},i=new Set,[r.current(),function(f,c){var d,p=c instanceof Error?c.message:"";if(p===J||p===Z)r.exclude(),d=0;else if(p===ee)r.exclude();else if(p===K){var T=Date.now()-f.getTime()<50,O=r.current();O&&T&&!i.has(O)&&(i.add(O),d=0),r.postpone()}else r.postpone();var b=r.current();return b===void 0?void 0:[b,d??f.getTime()+n()-Date.now()]}]),h=l[0],v=l[1];if(h===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var _=function(f){var c=new Date,d=function(T){return y.push({url:f,startedAt:c,finishedAt:new Date,error:T})},p=t(f);return p.then(function(){return d()},d),p.catch(function(T){if(a!=null||(a=T),y.length>=5)throw a;var O=v(c,T);if(!O)throw a;var b,z=O[0],ze=O[1];return(b=ze,new Promise(function(Je){return setTimeout(Je,b)})).then(function(){return _(z)})})};return _(h).then(function(f){return[f,y]})}var Te="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",_t=Te;function bt(e){var t;e.scriptUrlPattern;var r=e.token,n=e.apiKey,i=n===void 0?r:n,s=ye(e,["scriptUrlPattern","token","apiKey"]),u=(t=Ze(e,"scriptUrlPattern"))!==null&&t!==void 0?t:Te,o=function(){var l=[],h=function(){l.push({time:new Date,state:document.visibilityState})},v=function(_,f,c,d){return _.addEventListener(f,c,d),function(){return _.removeEventListener(f,c,d)}}(document,"visibilitychange",h);return h(),[l,v]}(),a=o[0],y=o[1];return Promise.resolve().then(function(){if(!i||typeof i!="string")throw new Error(H);var l=function(h,v){return(Array.isArray(h)?h:[h]).map(function(_){return function(f,c){var d=encodeURIComponent;return f.replace(/<[^<>]+>/g,function(p){return p==="<version>"?"3":p==="<apiKey>"?d(c):p==="<loaderVersion>"?d(It):p})}(String(_),v)})}(u,i);return vt(l,gt)}).catch(function(l){throw y(),function(h){return h instanceof Error&&h.message===ee?new Error(K):h}(l)}).then(function(l){var h=l[0],v=l[1];return y(),h.load(S(S({},s),{ldi:{attempts:v,visibilityStates:a}}))})}function gt(e){return He(e,function(){return function(t){return new Promise(function(r,n){if(function(o){if(URL.prototype)try{return new URL(o,location.href),!1}catch(a){if(a instanceof Error&&a.name==="TypeError")return!0;throw a}}(t))throw new Error(Z);var i=document.createElement("script"),s=function(){var o;return(o=i.parentNode)===null||o===void 0?void 0:o.removeChild(i)},u=document.head||document.getElementsByTagName("head")[0];i.onload=function(){s(),r()},i.onerror=function(){s(),n(new Error(K))},i.async=!0,i.src=t,u.appendChild(i)})}(e)},function(){throw new Error(J)}).then(wt)}function wt(){var e=window,t="__fpjs_p_l_b",r=e[t];if(function(n,i){var s,u=(s=Object.getOwnPropertyDescriptor)===null||s===void 0?void 0:s.call(Object,n,i);u?.configurable?delete n[i]:u&&!u.writable||(n[i]=void 0)}(e,t),typeof r?.load!="function")throw new Error(ee);return r}var k={load:bt,defaultScriptUrlPattern:_t,ERROR_SCRIPT_LOAD_FAIL:K,ERROR_API_KEY_EXPIRED:Re,ERROR_API_KEY_INVALID:me,ERROR_API_KEY_MISSING:H,ERROR_BAD_REQUEST_FORMAT:ht,ERROR_BAD_RESPONSE_FORMAT:ot,ERROR_CLIENT_TIMEOUT:rt,ERROR_CSP_BLOCK:J,ERROR_FORBIDDEN_ENDPOINT:lt,ERROR_FORBIDDEN_HEADER:mt,ERROR_FORBIDDEN_ORIGIN:Et,ERROR_GENERAL_SERVER_FAILURE:dt,ERROR_INSTALLATION_METHOD_RESTRICTED:ct,ERROR_INTEGRATION_FAILURE:ft,ERROR_INVALID_ENDPOINT:Z,ERROR_NETWORK_ABORT:it,ERROR_NETWORK_CONNECTION:nt,ERROR_RATE_LIMIT:yt,ERROR_SERVER_TIMEOUT:pt,ERROR_SUBSCRIPTION_NOT_ACTIVE:at,ERROR_TOKEN_EXPIRED:Ot,ERROR_TOKEN_INVALID:Tt,ERROR_TOKEN_MISSING:Rt,ERROR_UNSUPPORTED_VERSION:ut,ERROR_WRONG_REGION:st,defaultEndpoint:et,defaultTlsEndpoint:tt};var R=[];for(let e=0;e<256;++e)R.push((e+256).toString(16).slice(1));function Oe(e,t=0){return(R[e[t+0]]+R[e[t+1]]+R[e[t+2]]+R[e[t+3]]+"-"+R[e[t+4]]+R[e[t+5]]+"-"+R[e[t+6]]+R[e[t+7]]+"-"+R[e[t+8]]+R[e[t+9]]+"-"+R[e[t+10]]+R[e[t+11]]+R[e[t+12]]+R[e[t+13]]+R[e[t+14]]+R[e[t+15]]).toLowerCase()}var te,At=new Uint8Array(16);function re(){if(!te){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");te=crypto.getRandomValues.bind(crypto)}return te(At)}var Pt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ne={randomUUID:Pt};function Dt(e,t,r){if(ne.randomUUID&&!t&&!e)return ne.randomUUID();e=e||{};let n=e.random??e.rng?.()??re();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){if(r=r||0,r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let i=0;i<16;++i)t[r+i]=n[i];return t}return Oe(n)}var Q=Dt;var Nt={UNAUTHORIZED:"Unauthorized"},St={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},Ie={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key"},ve={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},_e={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},be={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},ge={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},m={...Nt,...St,...Ie,...ve,..._e,...be,...ge},we={...Ie,...ve,..._e,...be,...ge};var g=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var w=typeof window>"u"||"Deno"in globalThis;function I(){}function De(e,t){return typeof e=="function"?e(t):e}function Ne(e){return typeof e=="number"&&e>=0&&e!==1/0}function Se(e,t){return Math.max(e+(t||0)-Date.now(),0)}function oe(e,t){return typeof e=="function"?e(t):e}function xe(e,t){return typeof e=="function"?e(t):e}function se(e,t){let{type:r="all",exact:n,fetchStatus:i,predicate:s,queryKey:u,stale:o}=e;if(u){if(n){if(t.queryHash!==x(u,t.options))return!1}else if(!D(t.queryKey,u))return!1}if(r!=="all"){let a=t.isActive();if(r==="active"&&!a||r==="inactive"&&a)return!1}return!(typeof o=="boolean"&&t.isStale()!==o||i&&i!==t.state.fetchStatus||s&&!s(t))}function ae(e,t){let{exact:r,status:n,predicate:i,mutationKey:s}=e;if(s){if(!t.options.mutationKey)return!1;if(r){if(P(t.options.mutationKey)!==P(s))return!1}else if(!D(t.options.mutationKey,s))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function x(e,t){return(t?.queryKeyHashFn||P)(e)}function P(e){return JSON.stringify(e,(t,r)=>ie(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}function D(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!D(e[r],t[r])):!1}function Me(e,t){if(e===t)return e;let r=Ae(e)&&Ae(t);if(r||ie(e)&&ie(t)){let n=r?e:Object.keys(e),i=n.length,s=r?t:Object.keys(t),u=s.length,o=r?[]:{},a=0;for(let y=0;y<u;y++){let l=r?y:s[y];(!r&&n.includes(l)||r)&&e[l]===void 0&&t[l]===void 0?(o[l]=void 0,a++):(o[l]=Me(e[l],t[l]),o[l]===e[l]&&e[l]!==void 0&&a++)}return i===u&&a===i?e:o}return t}function Ae(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function ie(e){if(!Pe(e))return!1;let t=e.constructor;if(t===void 0)return!0;let r=t.prototype;return!(!Pe(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function Pe(e){return Object.prototype.toString.call(e)==="[object Object]"}function Fe(e){return new Promise(t=>{setTimeout(t,e)})}function Le(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?Me(e,t):t}function Ue(e,t,r=0){let n=[...e,t];return r&&n.length>r?n.slice(1):n}function qe(e,t,r=0){let n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var M=Symbol();function G(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===M?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var xt=class extends g{#e;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e=="boolean"?this.#e:globalThis.document?.visibilityState!=="hidden"}},B=new xt;var Mt=class extends g{#e=!0;#t;#r;constructor(){super(),this.#r=e=>{if(!w&&window.addEventListener){let t=()=>e(!0),r=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#t||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#r=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(r=>{r(e)}))}isOnline(){return this.#e}},N=new Mt;function je(){let e,t,r=new Promise((i,s)=>{e=i,t=s});r.status="pending",r.catch(()=>{});function n(i){Object.assign(r,i),delete r.resolve,delete r.reject}return r.resolve=i=>{n({status:"fulfilled",value:i}),e(i)},r.reject=i=>{n({status:"rejected",reason:i}),t(i)},r}function Ft(e){return Math.min(1e3*2**e,3e4)}function ue(e){return(e??"online")==="online"?N.isOnline():!0}var Ke=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function V(e){return e instanceof Ke}function C(e){let t=!1,r=0,n=!1,i,s=je(),u=c=>{n||(v(new Ke(c)),e.abort?.())},o=()=>{t=!0},a=()=>{t=!1},y=()=>B.isFocused()&&(e.networkMode==="always"||N.isOnline())&&e.canRun(),l=()=>ue(e.networkMode)&&e.canRun(),h=c=>{n||(n=!0,e.onSuccess?.(c),i?.(),s.resolve(c))},v=c=>{n||(n=!0,e.onError?.(c),i?.(),s.reject(c))},_=()=>new Promise(c=>{i=d=>{(n||y())&&c(d)},e.onPause?.()}).then(()=>{i=void 0,n||e.onContinue?.()}),f=()=>{if(n)return;let c,d=r===0?e.initialPromise:void 0;try{c=d??e.fn()}catch(p){c=Promise.reject(p)}Promise.resolve(c).then(h).catch(p=>{if(n)return;let T=e.retry??(w?0:3),O=e.retryDelay??Ft,b=typeof O=="function"?O(r,p):O,z=T===!0||typeof T=="number"&&r<T||typeof T=="function"&&T(r,p);if(t||!z){v(p);return}r++,e.onFail?.(r,p),Fe(b).then(()=>y()?void 0:_()).then(()=>{t?v(p):f()})})};return{promise:s,cancel:u,continue:()=>(i?.(),s),cancelRetry:o,continueRetry:a,canStart:l,start:()=>(l()?f():_().then(f),s)}}function Lt(){let e=[],t=0,r=o=>{o()},n=o=>{o()},i=o=>setTimeout(o,0),s=o=>{t?e.push(o):i(()=>{r(o)})},u=()=>{let o=e;e=[],o.length&&i(()=>{n(()=>{o.forEach(a=>{r(a)})})})};return{batch:o=>{let a;t++;try{a=o()}finally{t--,t||u()}return a},batchCalls:o=>(...a)=>{s(()=>{o(...a)})},schedule:s,setNotifyFunction:o=>{r=o},setBatchNotifyFunction:o=>{n=o},setScheduler:o=>{i=o}}}var E=Lt();var Y=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Ne(this.gcTime)&&(this.#e=setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(w?1/0:5*60*1e3))}clearGcTimeout(){this.#e&&(clearTimeout(this.#e),this.#e=void 0)}};var ke=class extends Y{#e;#t;#r;#n;#s;#o;constructor(e){super(),this.#o=!1,this.#s=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=qt(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#n?.promise}setOptions(e){this.options={...this.#s,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let r=Le(this.state.data,e,this.options);return this.#i({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#i({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(I).catch(I):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>xe(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===M||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(e=0){return this.state.isInvalidated||this.state.data===void 0||!Se(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#n?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#n?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#n&&(this.#o?this.#n.cancel({revert:!0}):this.#n.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#i({type:"invalidate"})}fetch(e,t){if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#n)return this.#n.continueRetry(),this.#n.promise}if(e&&this.setOptions(e),!this.options.queryFn){let o=this.observers.find(a=>a.options.queryFn);o&&this.setOptions(o.options)}let r=new AbortController,n=o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(this.#o=!0,r.signal)})},i=()=>{let o=G(this.options,t),a={queryKey:this.queryKey,meta:this.meta};return n(a),this.#o=!1,this.options.persister?this.options.persister(o,a,this):o(a)},s={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};n(s),this.options.behavior?.onFetch(s,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==s.fetchOptions?.meta)&&this.#i({type:"fetch",meta:s.fetchOptions?.meta});let u=o=>{V(o)&&o.silent||this.#i({type:"error",error:o}),V(o)||(this.#r.config.onError?.(o,this),this.#r.config.onSettled?.(this.state.data,o,this)),this.scheduleGc()};return this.#n=C({initialPromise:t?.initialPromise,fn:s.fetchFn,abort:r.abort.bind(r),onSuccess:o=>{if(o===void 0){u(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(o)}catch(a){u(a);return}this.#r.config.onSuccess?.(o,this),this.#r.config.onSettled?.(o,this.state.error,this),this.scheduleGc()},onError:u,onFail:(o,a)=>{this.#i({type:"failed",failureCount:o,error:a})},onPause:()=>{this.#i({type:"pause"})},onContinue:()=>{this.#i({type:"continue"})},retry:s.options.retry,retryDelay:s.options.retryDelay,networkMode:s.options.networkMode,canRun:()=>!0}),this.#n.start()}#i(e){let t=r=>{switch(e.type){case"failed":return{...r,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...Ut(r.data,this.options),fetchMeta:e.meta??null};case"success":return{...r,data:e.data,dataUpdateCount:r.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":let n=e.error;return V(n)&&n.revert&&this.#t?{...this.#t,fetchStatus:"idle"}:{...r,error:n,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...e.state}}};this.state=t(this.state),E.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Ut(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:ue(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function qt(e){let t=typeof e.initialData=="function"?e.initialData():e.initialData,r=t!==void 0,n=r?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var F=class extends g{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,r){let n=t.queryKey,i=t.queryHash??x(n,t),s=this.get(i);return s||(s=new ke({cache:this,queryKey:n,queryHash:i,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(n)}),this.add(s)),s}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){E.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(r=>se(t,r))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(r=>se(e,r)):t}notify(e){E.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){E.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){E.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var Qe=class extends Y{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||jt(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#e.includes(e)||(this.#e.push(e),this.clearGcTimeout(),this.#t.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#e=this.#e.filter(t=>t!==e),this.scheduleGc(),this.#t.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#t.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){this.#r=C({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(n,i)=>{this.#n({type:"failed",failureCount:n,error:i})},onPause:()=>{this.#n({type:"pause"})},onContinue:()=>{this.#n({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#t.canRun(this)});let t=this.state.status==="pending",r=!this.#r.canStart();try{if(!t){this.#n({type:"pending",variables:e,isPaused:r}),await this.#t.config.onMutate?.(e,this);let i=await this.options.onMutate?.(e);i!==this.state.context&&this.#n({type:"pending",context:i,variables:e,isPaused:r})}let n=await this.#r.start();return await this.#t.config.onSuccess?.(n,e,this.state.context,this),await this.options.onSuccess?.(n,e,this.state.context),await this.#t.config.onSettled?.(n,null,this.state.variables,this.state.context,this),await this.options.onSettled?.(n,null,e,this.state.context),this.#n({type:"success",data:n}),n}catch(n){try{throw await this.#t.config.onError?.(n,e,this.state.context,this),await this.options.onError?.(n,e,this.state.context),await this.#t.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this),await this.options.onSettled?.(void 0,n,e,this.state.context),n}finally{this.#n({type:"error",error:n})}}finally{this.#t.runNext(this)}}#n(e){let t=r=>{switch(e.type){case"failed":return{...r,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...r,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:e.error,failureCount:r.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),E.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function jt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var L=class extends g{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#r=0}#e;#t;#r;build(e,t,r){let n=new Qe({mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:r});return this.add(n),n}add(e){this.#e.add(e);let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);r?r.push(e):this.#t.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#e.delete(e)){let t=W(e);if(typeof t=="string"){let r=this.#t.get(t);if(r)if(r.length>1){let n=r.indexOf(e);n!==-1&&r.splice(n,1)}else r[0]===e&&this.#t.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){let t=W(e);if(typeof t=="string"){let n=this.#t.get(t)?.find(i=>i.state.status==="pending");return!n||n===e}else return!0}runNext(e){let t=W(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){E.batch(()=>{this.#e.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(r=>ae(t,r))}findAll(e={}){return this.getAll().filter(t=>ae(e,t))}notify(e){E.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return E.batch(()=>Promise.all(e.map(t=>t.continue().catch(I))))}};function W(e){return e.options.scope?.id}function ce(e){return{onFetch:(t,r)=>{let n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,s=t.state.data?.pages||[],u=t.state.data?.pageParams||[],o={pages:[],pageParams:[]},a=0,y=async()=>{let l=!1,h=f=>{Object.defineProperty(f,"signal",{enumerable:!0,get:()=>(t.signal.aborted?l=!0:t.signal.addEventListener("abort",()=>{l=!0}),t.signal)})},v=G(t.options,t.fetchOptions),_=async(f,c,d)=>{if(l)return Promise.reject();if(c==null&&f.pages.length)return Promise.resolve(f);let p={queryKey:t.queryKey,pageParam:c,direction:d?"backward":"forward",meta:t.options.meta};h(p);let T=await v(p),{maxPages:O}=t.options,b=d?qe:Ue;return{pages:b(f.pages,T,O),pageParams:b(f.pageParams,c,O)}};if(i&&s.length){let f=i==="backward",c=f?Kt:Ge,d={pages:s,pageParams:u},p=c(n,d);o=await _(d,p,f)}else{let f=e??s.length;do{let c=a===0?u[0]??n.initialPageParam:Ge(n,o);if(a>0&&c==null)break;o=await _(o,c),a++}while(a<f)}return o};t.options.persister?t.fetchFn=()=>t.options.persister?.(y,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=y}}}function Ge(e,{pages:t,pageParams:r}){let n=t.length-1;return t.length>0?e.getNextPageParam(t[n],t,r[n],r):void 0}function Kt(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var le=class{#e;#t;#r;#n;#s;#o;#i;#a;constructor(e={}){this.#e=e.queryCache||new F,this.#t=e.mutationCache||new L,this.#r=e.defaultOptions||{},this.#n=new Map,this.#s=new Map,this.#o=0}mount(){this.#o++,this.#o===1&&(this.#i=B.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=N.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#o--,this.#o===0&&(this.#i?.(),this.#i=void 0,this.#a?.(),this.#a=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#t.findAll({...e,status:"pending"}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),r=this.#e.build(this,t),n=r.state.data;return n===void 0?this.fetchQuery(e):(e.revalidateIfStale&&r.isStaleByTime(oe(t.staleTime,r))&&this.prefetchQuery(t),Promise.resolve(n))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:t,state:r})=>{let n=r.data;return[t,n]})}setQueryData(e,t,r){let n=this.defaultQueryOptions({queryKey:e}),s=this.#e.get(n.queryHash)?.state.data,u=De(t,s);if(u!==void 0)return this.#e.build(this,n).setData(u,{...r,manual:!0})}setQueriesData(e,t,r){return E.batch(()=>this.#e.findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,r)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;E.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){let r=this.#e,n={type:"active",...e};return E.batch(()=>(r.findAll(e).forEach(i=>{i.reset()}),this.refetchQueries(n,t)))}cancelQueries(e,t={}){let r={revert:!0,...t},n=E.batch(()=>this.#e.findAll(e).map(i=>i.cancel(r)));return Promise.all(n).then(I).catch(I)}invalidateQueries(e,t={}){return E.batch(()=>{if(this.#e.findAll(e).forEach(n=>{n.invalidate()}),e?.refetchType==="none")return Promise.resolve();let r={...e,type:e?.refetchType??e?.type??"active"};return this.refetchQueries(r,t)})}refetchQueries(e,t={}){let r={...t,cancelRefetch:t.cancelRefetch??!0},n=E.batch(()=>this.#e.findAll(e).filter(i=>!i.isDisabled()).map(i=>{let s=i.fetch(void 0,r);return r.throwOnError||(s=s.catch(I)),i.state.fetchStatus==="paused"?Promise.resolve():s}));return Promise.all(n).then(I)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let r=this.#e.build(this,t);return r.isStaleByTime(oe(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(I).catch(I)}fetchInfiniteQuery(e){return e.behavior=ce(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(I).catch(I)}ensureInfiniteQueryData(e){return e.behavior=ce(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return N.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#r}setDefaultOptions(e){this.#r=e}setQueryDefaults(e,t){this.#n.set(P(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#n.values()],r={};return t.forEach(n=>{D(e,n.queryKey)&&Object.assign(r,n.defaultOptions)}),r}setMutationDefaults(e,t){this.#s.set(P(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#s.values()],r={};return t.forEach(n=>{D(e,n.mutationKey)&&(r={...r,...n.defaultOptions})}),r}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#r.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=x(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===M&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#r.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};var kt=new le({defaultOptions:{queries:{staleTime:3e4}},queryCache:new F({onError:(e,t)=>{}}),mutationCache:new L}),Be=kt;var Qt=(e,t={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...t}),Gt=async(e,t)=>{if(!e.ok){let r=await e.text();throw new Error(r)}return t==="file"?e.blob():t==="json"?e.json():t==="text"?e.text():null},Ve=async({url:e,auth:t,body:r,method:n="GET",headers:i={},responseType:s="json"})=>{let u={method:n,headers:Qt(t,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},o=await fetch(e,u);return Gt(o,s)},Ce=e=>Ve({...e,method:"GET"}),fe=e=>Ve({...e,method:"POST"});var he,de="https://api.dtect.io/security",q="",j="",Ye="",Bt="20000000-aaaa-bbbb-cccc-000000000002",X,U={isLoading:!1},Vt=we;function $(){return!!(document.querySelector("#dtect-h-captcha")&&he)}function pe(){return!!(q&&j)}async function Ct({behaviorKey:e}){let t=await k.load({apiKey:e,endpoint:["https://fp.dtect.io",k.defaultEndpoint],scriptUrlPattern:["https://fp.dtect.io/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",k.defaultScriptUrlPattern]});if(t)he=t;else throw new Error(m.SDK_INIT_ERROR)}async function Yt(e){if(!e?.clientId||!e?.apiKey)throw new Error(m.MISSING_CREDENTIALS);let{clientId:t,apiKey:r,endpoint:n="https://api.dtect.io/security"}=e;if(de=n,U.isLoading){if($())return X;throw new Error(m.DUPLICATE_INITIALIZATION)}if(q=t,j=r,U={...U,isLoading:!0},!pe())throw new Error(m.MISSING_CREDENTIALS);if($())return X;let i=document.querySelector("head");document.querySelector("body")?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let u=document.createElement("script");u.setAttribute("src","https://js.hcaptcha.com/1/api.js"),u.setAttribute("async","true"),u.setAttribute("defer","true"),i?.append(u);try{let o=await Be.fetchQuery({queryKey:["getKeys",t,r],queryFn:()=>Ce({url:`${n}/client/config`,headers:{"client-id":q,"x-api-key":j}})});if(o?.automationKey&&o?.behaviorKey)return Ye=o.automationKey,Ct({...o}).then(()=>({getSecurityResult:Xe,getSecurityToken:$e,SecurityAPIError:Vt})).catch(a=>{throw new Error(a.message)});throw new Error}catch(o){throw o instanceof Error&&[m.INVALID_API_KEY,m.UNAUTHORIZED].includes(o?.message)?new Error(m.INVALID_CREDENTIALS):new Error(m.SDK_INIT_ERROR)}finally{U={...U,isLoading:!1}}}async function We(){let e=await he?.get();if(window?.location?.href?.includes("localhost")){if(e?.sealedResult&&e?.requestId)return{behaviorRequestId:e.requestId,behaviorToken:e.sealedResult,automationToken:Bt}}else{await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:Ye,size:"invisible"});let t=await window?.hcaptcha?.execute({async:!0});if(t?.response&&e?.sealedResult&&e?.requestId)return{behaviorRequestId:e.requestId,behaviorToken:e.sealedResult,automationToken:t.response}}throw new Error(m.INTERNAL_SERVER_ERROR)}async function Xe(e){if(!$())throw new Error(m.NOT_INITIALIZED);if(!pe())throw new Error(m.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(m.FAILED_TO_GET_SECURITY_RESULT);try{let t=await We();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,projectId:e?.projectId?.trim(),visitorId:e?.visitorId?.trim()||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await fe({url:`${de}/client/check/results`,body:{...r},headers:{"client-id":q,"x-api-key":j}});if(n?.results?.dtectScore)return n}throw new Error}catch{throw new Error(m.FAILED_TO_GET_SECURITY_RESULT)}}async function $e(e){if(!$())throw new Error(m.NOT_INITIALIZED);if(!pe())throw new Error(m.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(m.FAILED_TO_GET_SECURITY_TOKEN);try{let t=await We();if(t?.behaviorToken&&t?.behaviorRequestId&&t?.behaviorToken){let r={...e,projectId:e.projectId?.trim(),visitorId:e.visitorId?.trim()||Q(),visitorData:{behaviorToken:t.behaviorToken,automationToken:t.automationToken,behaviorRequestId:t.behaviorRequestId,entryLink:window?.location?.href}},n=await fe({url:`${de}/client/check/token`,body:{...r},headers:{"client-id":q,"x-api-key":j}});if(n?.token)return n}throw new Error}catch{throw new Error(m.FAILED_TO_GET_SECURITY_TOKEN)}}X={init:Yt,getSecurityResult:Xe,getSecurityToken:$e};var Vn=X;export{Vt as SecurityAPIError,Vn as default,Xe as getSecurityResult,$e as getSecurityToken,Yt as init};
|