@dtect/security-sdk-js 0.0.6 → 0.0.8
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/README.md +41 -20
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -6,17 +6,13 @@ Security API Javascript SDK by dtect.
|
|
|
6
6
|
<details>
|
|
7
7
|
<summary>Table of Contents</summary>
|
|
8
8
|
<ol>
|
|
9
|
-
<li>
|
|
10
|
-
<a href="#about-the-project">About The Project</a>
|
|
11
|
-
</li>
|
|
12
9
|
<li>
|
|
13
10
|
<a href="#getting-started">Getting Started</a>
|
|
14
11
|
<ul>
|
|
15
|
-
<li><a href="#prerequisites">Prerequisites</a></li>
|
|
16
12
|
<li><a href="#installation">Installation</a></li>
|
|
17
13
|
</ul>
|
|
18
14
|
</li>
|
|
19
|
-
|
|
15
|
+
<li>
|
|
20
16
|
<a href="#implementation">Implementation</a>
|
|
21
17
|
</li>
|
|
22
18
|
<li>
|
|
@@ -24,17 +20,10 @@ Security API Javascript SDK by dtect.
|
|
|
24
20
|
</li>
|
|
25
21
|
<li><a href="#license">License</a></li>
|
|
26
22
|
<li><a href="#contact">Contact</a></li>
|
|
23
|
+
|
|
27
24
|
</ol>
|
|
28
25
|
</details>
|
|
29
26
|
|
|
30
|
-
<!-- ABOUT THE PROJECT -->
|
|
31
|
-
|
|
32
|
-
## About The Project
|
|
33
|
-
|
|
34
|
-
Security API SDK
|
|
35
|
-
|
|
36
|
-
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
37
|
-
|
|
38
27
|
<!-- GETTING STARTED -->
|
|
39
28
|
|
|
40
29
|
## Getting Started
|
|
@@ -42,9 +31,9 @@ Security API SDK
|
|
|
42
31
|
The dtect Security API helps you gather valuable insights about your visitors, enhancing the quality of your survey data.
|
|
43
32
|
This library is responsible for collecting data about the visitor's browser and behavior, send everything to our API and return a Security Result or a Security Token.
|
|
44
33
|
|
|
45
|
-
|
|
34
|
+
_Please refer to [our official documentation](https://docs.dtect.io) to learn more about the dtect Security API_
|
|
46
35
|
|
|
47
|
-
|
|
36
|
+
_**If you want to use our API, please [contact us](https://dtect.io/contact)**_
|
|
48
37
|
|
|
49
38
|
### Installation
|
|
50
39
|
|
|
@@ -68,10 +57,12 @@ or CDN
|
|
|
68
57
|
|
|
69
58
|
## NPM Implementation
|
|
70
59
|
|
|
60
|
+
_Read full documentation about implementation on [our official docs](https://docs.dtect.io/frontend/introduction)_
|
|
61
|
+
|
|
71
62
|
### 1. Start initialize security sdk by calling init function.
|
|
72
63
|
|
|
73
|
-
- Set
|
|
74
|
-
- Set
|
|
64
|
+
- Set your public client id as `clientId`
|
|
65
|
+
- Set your public api key as `apiKey`
|
|
75
66
|
|
|
76
67
|
```jsx
|
|
77
68
|
import dtect from "@dtect/security-sdk-js";
|
|
@@ -123,7 +114,9 @@ dtect
|
|
|
123
114
|
|
|
124
115
|
```html
|
|
125
116
|
<script>
|
|
126
|
-
const dtectPromise = import(
|
|
117
|
+
const dtectPromise = import(
|
|
118
|
+
"https://unpkg.com/@dtect/security-sdk-js@latest/dist/index.mjs"
|
|
119
|
+
).then((dtect) =>
|
|
127
120
|
dtect.init({
|
|
128
121
|
clientId: "your-public-client-id-from-dashboard", // required
|
|
129
122
|
apiKey: "your-public-api-key-from-dashboard", // required
|
|
@@ -152,6 +145,8 @@ dtect
|
|
|
152
145
|
|
|
153
146
|
## Errors
|
|
154
147
|
|
|
148
|
+
_Read full documentation about errors on [our official docs](https://docs.dtect.io/errors)_
|
|
149
|
+
|
|
155
150
|
Access the list of error enums from `SecurityAPIError`
|
|
156
151
|
|
|
157
152
|
### init()
|
|
@@ -164,6 +159,7 @@ You will see these errors on console
|
|
|
164
159
|
| `INVALID_CREDENTIALS` | Invalid Public Client ID or Public API Key | Ensure you are using valid Public Client ID and Public API Key. |
|
|
165
160
|
| `SDK_INIT_ERROR` | Internal Server Error during SDK Initialization | An unexpected error occurred on our servers during SDK initialization. |
|
|
166
161
|
| `DUPLICATE_INITIALIZATION` | Multiple SDK Initializations Detected | You should initialize our package only once. |
|
|
162
|
+
| `MAINTENANCE_MODE` | API Under Maintenance | The API is currently undergoing maintenance and will be available again shortly. |
|
|
167
163
|
|
|
168
164
|
### getSecurityToken()/getSecurityResult()
|
|
169
165
|
|
|
@@ -173,6 +169,11 @@ You will see these errors on console
|
|
|
173
169
|
| `INTERNAL_SERVER_ERROR` | Internal Server Error during API Request | An unexpected error occurred on our servers during the API request. Check server logs for details. |
|
|
174
170
|
| `FAILED_TO_GET_SECURITY_TOKEN` | Failed to Generate Security Token | An error occurred while generating the Security Token. |
|
|
175
171
|
| `FAILED_TO_GET_SECURITY_RESULT` | Failed to Retrieve Security Result | An error occurred while retrieving the Security Result. |
|
|
172
|
+
| `MAINTENANCE_MODE` | API Under Maintenance | The API is currently undergoing maintenance and will be available again shortly. |
|
|
173
|
+
|
|
174
|
+
|
|
|
175
|
+
|
|
176
|
+
#### NPM implementation with errors
|
|
176
177
|
|
|
177
178
|
```jsx
|
|
178
179
|
import dtect, { SecurityAPIError } from "@dtect/security-sdk-js";
|
|
@@ -191,11 +192,31 @@ dtect
|
|
|
191
192
|
});
|
|
192
193
|
```
|
|
193
194
|
|
|
195
|
+
#### CDN implementation with errors
|
|
196
|
+
|
|
197
|
+
```jsx
|
|
198
|
+
<script>
|
|
199
|
+
dtectPromise.then((dtect) =>
|
|
200
|
+
dtect
|
|
201
|
+
.getSecurityResult({
|
|
202
|
+
projectId: "your-project-id-for-deduplication", // required
|
|
203
|
+
})
|
|
204
|
+
.then((securityResult) => console.log(securityResult))
|
|
205
|
+
.catch((error) => {
|
|
206
|
+
switch(error.message) {
|
|
207
|
+
case dtect.SecurityAPIError.FAILED_TO_GET_SECURITY_RESULT:
|
|
208
|
+
// log internally
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
);
|
|
212
|
+
</script>
|
|
213
|
+
```
|
|
214
|
+
|
|
194
215
|
<!-- LICENSE -->
|
|
195
216
|
|
|
196
|
-
## License
|
|
217
|
+
<!-- ## License
|
|
197
218
|
|
|
198
|
-
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
219
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p> -->
|
|
199
220
|
|
|
200
221
|
<!-- CONTACT -->
|
|
201
222
|
|
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,9 @@ interface ISecurityResultResponse {
|
|
|
15
15
|
isDuplicateId: boolean;
|
|
16
16
|
isLocationBlocked: boolean;
|
|
17
17
|
isLocationInvalid: boolean;
|
|
18
|
+
isAutomationDetected: boolean;
|
|
19
|
+
isUntrustedBrowserOrOS: boolean;
|
|
20
|
+
isBlockedIP: boolean;
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
interface ISecurityTokenResponse {
|
|
@@ -44,6 +47,7 @@ declare const SecurityAPIError: {
|
|
|
44
47
|
NOT_INITIALIZED: string;
|
|
45
48
|
INTERNAL_SERVER_ERROR: "Internal Server Error during API Request";
|
|
46
49
|
MISSING_CREDENTIALS: "Missing Public Client ID or Public API Key";
|
|
50
|
+
MAINTENANCE_MODE: "API Under Maintenance";
|
|
47
51
|
};
|
|
48
52
|
declare function init(props: ISecurityAPIInitProps): Promise<IdtectModule>;
|
|
49
53
|
declare function getSecurityResult(props: ISecurityCheckInput): Promise<ISecurityResultResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ interface ISecurityResultResponse {
|
|
|
15
15
|
isDuplicateId: boolean;
|
|
16
16
|
isLocationBlocked: boolean;
|
|
17
17
|
isLocationInvalid: boolean;
|
|
18
|
+
isAutomationDetected: boolean;
|
|
19
|
+
isUntrustedBrowserOrOS: boolean;
|
|
20
|
+
isBlockedIP: boolean;
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
interface ISecurityTokenResponse {
|
|
@@ -44,6 +47,7 @@ declare const SecurityAPIError: {
|
|
|
44
47
|
NOT_INITIALIZED: string;
|
|
45
48
|
INTERNAL_SERVER_ERROR: "Internal Server Error during API Request";
|
|
46
49
|
MISSING_CREDENTIALS: "Missing Public Client ID or Public API Key";
|
|
50
|
+
MAINTENANCE_MODE: "API Under Maintenance";
|
|
47
51
|
};
|
|
48
52
|
declare function init(props: ISecurityAPIInitProps): Promise<IdtectModule>;
|
|
49
53
|
declare function getSecurityResult(props: ISecurityCheckInput): Promise<ISecurityResultResponse>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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",_t="Request failed",vt="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,Nt=Ie,Dt="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],_=l[1];if(h===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var v=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=_(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 v(z)})})};return v(h).then(function(f){return[f,y]})}var _e="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Mt=_e;function xt(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:_e,o=function(){var l=[],h=function(){l.push({time:new Date,state:document.visibilityState})},_=function(v,f,c,d){return v.addEventListener(f,c,d),function(){return v.removeEventListener(f,c,d)}}(document,"visibilitychange",h);return h(),[l,_]}(),a=o[0],y=o[1];return Promise.resolve().then(function(){if(!i||typeof i!="string")throw new Error(ee);var l=function(h,_){return(Array.isArray(h)?h:[h]).map(function(v){return function(f,c){var d=encodeURIComponent;return f.replace(/<[^<>]+>/g,function(p){return p==="<version>"?"3":p==="<apiKey>"?d(c):p==="<loaderVersion>"?d(Dt):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],_=l[1];return y(),h.load(S(S({},s),{ldi:{attempts:_,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:xt,defaultScriptUrlPattern:Mt,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:_t,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:vt,ERROR_SUBSCRIPTION_NOT_ACTIVE:Et,ERROR_TOKEN_EXPIRED:Nt,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 ve(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 ve(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",MAINTENANCE_MODE:"API Under Maintenance"},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"},E={...Kt,...kt,...be,...ge,...we,...Ae,...Pe},Ne={...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 Me(e,t){return typeof e=="function"?e(t):e}function xe(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!==M(u,t.options))return!1}else if(!N(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(!N(t.options.mutationKey,s))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function M(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 N(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!N(e[r],t[r])):!1}function Ue(e,t){if(e===t)return e;let r=De(e)&&De(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 De(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 x=Symbol();function G(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===x?()=>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}},D=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"?D.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||(_(new Ge(c)),e.abort?.())},o=()=>{t=!0},a=()=>{t=!1},y=()=>B.isFocused()&&(e.networkMode==="always"||D.isOnline())&&e.canRun(),l=()=>ce(e.networkMode)&&e.canRun(),h=c=>{n||(n=!0,e.onSuccess?.(c),i?.(),s.resolve(c))},_=c=>{n||(n=!0,e.onError?.(c),i?.(),s.reject(c))},v=()=>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){_(p);return}r++,e.onFail?.(r,p),qe(b).then(()=>y()?void 0:v()).then(()=>{t?_(p):f()})})};return{promise:s,cancel:u,continue:()=>(i?.(),s),cancelRetry:o,continueRetry:a,canStart:l,start:()=>(l()?f():v().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 m=Vt();var Y=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),xe(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===x||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),m.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??M(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||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),m.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(){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(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)})},_=G(t.options,t.fetchOptions),v=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 _(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 v(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 v(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=D.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=Me(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(I).catch(I)}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(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 D.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=>{N(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=>{N(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=M(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===x&&(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=Ne;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(E.SDK_INIT_ERROR)}async function Je(e){if(!e?.clientId||!e?.apiKey)throw new Error(E.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(E.DUPLICATE_INITIALIZATION)}if(q=t,j=r,U={...U,isLoading:!0},!ye())throw new Error(E.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){if(o instanceof Error){if(o?.message?.includes("maintenance_mode"))throw new Error(E.MAINTENANCE_MODE);if([E.INVALID_API_KEY,E.UNAUTHORIZED].includes(o?.message))throw new Error(E.INVALID_CREDENTIALS)}throw new Error(E.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(E.INTERNAL_SERVER_ERROR)}async function Ee(e){if(!$())throw new Error(E.NOT_INITIALIZED);if(!ye())throw new Error(E.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(E.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(t){throw t instanceof Error&&t?.message?.includes("maintenance_mode")?new Error(E.MAINTENANCE_MODE):new Error(E.FAILED_TO_GET_SECURITY_RESULT)}}async function me(e){if(!$())throw new Error(E.NOT_INITIALIZED);if(!ye())throw new Error(E.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(E.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(t){throw t instanceof Error&&t?.message?.includes("maintenance_mode")?new Error(E.MAINTENANCE_MODE):new Error(E.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 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};
|
|
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 _t(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],_=l[1];if(h===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var v=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=_(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 v(z)})})};return v(h).then(function(f){return[f,y]})}var Te="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",vt=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})},_=function(v,f,c,d){return v.addEventListener(f,c,d),function(){return v.removeEventListener(f,c,d)}}(document,"visibilitychange",h);return h(),[l,_]}(),a=o[0],y=o[1];return Promise.resolve().then(function(){if(!i||typeof i!="string")throw new Error(H);var l=function(h,_){return(Array.isArray(h)?h:[h]).map(function(v){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 _t(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],_=l[1];return y(),h.load(S(S({},s),{ldi:{attempts:_,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:vt,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 Nt(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=Nt;var Dt={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",MAINTENANCE_MODE:"API Under Maintenance"},_e={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},ve={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"},E={...Dt,...St,...Ie,..._e,...ve,...be,...ge},we={...Ie,..._e,...ve,...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 Ne(e,t){return typeof e=="function"?e(t):e}function De(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 Me(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!==M(u,t.options))return!1}else if(!N(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(!N(t.options.mutationKey,s))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function M(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 N(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!N(e[r],t[r])):!1}function xe(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]=xe(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?xe(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 x=Symbol();function G(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===x?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var Mt=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 Mt;var xt=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}},D=new xt;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"?D.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||(_(new Ke(c)),e.abort?.())},o=()=>{t=!0},a=()=>{t=!1},y=()=>B.isFocused()&&(e.networkMode==="always"||D.isOnline())&&e.canRun(),l=()=>ue(e.networkMode)&&e.canRun(),h=c=>{n||(n=!0,e.onSuccess?.(c),i?.(),s.resolve(c))},_=c=>{n||(n=!0,e.onError?.(c),i?.(),s.reject(c))},v=()=>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){_(p);return}r++,e.onFail?.(r,p),Fe(b).then(()=>y()?void 0:v()).then(()=>{t?_(p):f()})})};return{promise:s,cancel:u,continue:()=>(i?.(),s),cancelRetry:o,continueRetry:a,canStart:l,start:()=>(l()?f():v().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 m=Lt();var Y=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),De(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=>Me(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===x||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),m.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??M(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||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),m.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(){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(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)})},_=G(t.options,t.fetchOptions),v=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 _(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 v(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 v(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=D.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=Ne(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(I).catch(I)}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(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 D.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=>{N(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=>{N(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=M(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===x&&(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(E.SDK_INIT_ERROR)}async function Yt(e){if(!e?.clientId||!e?.apiKey)throw new Error(E.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(E.DUPLICATE_INITIALIZATION)}if(q=t,j=r,U={...U,isLoading:!0},!pe())throw new Error(E.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){if(o instanceof Error){if(o?.message?.includes("maintenance_mode"))throw new Error(E.MAINTENANCE_MODE);if([E.INVALID_API_KEY,E.UNAUTHORIZED].includes(o?.message))throw new Error(E.INVALID_CREDENTIALS)}throw new Error(E.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(E.INTERNAL_SERVER_ERROR)}async function Xe(e){if(!$())throw new Error(E.NOT_INITIALIZED);if(!pe())throw new Error(E.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(E.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(t){throw t instanceof Error&&t?.message?.includes("maintenance_mode")?new Error(E.MAINTENANCE_MODE):new Error(E.FAILED_TO_GET_SECURITY_RESULT)}}async function $e(e){if(!$())throw new Error(E.NOT_INITIALIZED);if(!pe())throw new Error(E.MISSING_CREDENTIALS);if(!e||!e?.projectId?.trim())throw new Error(E.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(t){throw t instanceof Error&&t?.message?.includes("maintenance_mode")?new Error(E.MAINTENANCE_MODE):new Error(E.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};
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtect/security-sdk-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
8
9
|
"build": "tsup --dts",
|
|
9
|
-
"ts:check": "tsc --noEmit"
|
|
10
|
+
"ts:check": "tsc --noEmit",
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"test:watch": "vitest",
|
|
13
|
+
"test:ui": "vitest --ui"
|
|
10
14
|
},
|
|
11
15
|
"dependencies": {
|
|
12
16
|
"@fingerprintjs/fingerprintjs-pro": "^3.11.6",
|
|
@@ -17,10 +21,15 @@
|
|
|
17
21
|
"@eslint/js": "^9.17.0",
|
|
18
22
|
"@hcaptcha/types": "^1.0.4",
|
|
19
23
|
"@types/uuid": "^10.0.0",
|
|
24
|
+
"@vitest/expect": "^3.1.3",
|
|
25
|
+
"@vitest/ui": "^3.1.3",
|
|
20
26
|
"eslint": "^9.17.0",
|
|
27
|
+
"jsdom": "^26.1.0",
|
|
21
28
|
"tsup": "^8.3.5",
|
|
29
|
+
"tsx": "^4.19.4",
|
|
22
30
|
"typescript": "^5.7.2",
|
|
23
|
-
"typescript-eslint": "^8.19.0"
|
|
31
|
+
"typescript-eslint": "^8.19.0",
|
|
32
|
+
"vitest": "^3.1.3"
|
|
24
33
|
},
|
|
25
34
|
"author": "dtect",
|
|
26
35
|
"license": "MIT",
|