@dtect/security-sdk-js 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var he=(e,n)=>{for(var r in n)G(e,r,{get:n[r],enumerable:!0})},De=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Ne(n))!fe.call(e,i)&&i!==r&&G(e,i,{get:()=>n[i],enumerable:!(o=Ae(n,i))||o.enumerable});return e};var we=e=>De(G({},"__esModule",{value:!0}),e);var fn={};he(fn,{LanguageCodes:()=>v,QualityQuestionsRespondentTypes:()=>g,SecurityAPIError:()=>ue,checkQualityQuestions:()=>z,default:()=>Nn,getQualityQuestions:()=>Z,getSecurityResult:()=>$,getSecurityToken:()=>W,init:()=>me,isAIUsageDetected:()=>J});module.exports=we(fn);function ye(e,n){return function(r,o){return Object.prototype.hasOwnProperty.call(r,o)}(e,n)?e[n]:void 0}function pe(e,n,r,o){let i=document,E="securitypolicyviolation",a,l=u=>{let c=new URL(e,location.href),{blockedURI:t}=u;t!==c.href&&t!==c.protocol.slice(0,-1)&&t!==c.origin||(a=u,R())};i.addEventListener(E,l);let R=()=>i.removeEventListener(E,l);return o?.then(R,R),Promise.resolve().then(n).then(u=>(R(),u),u=>new Promise(c=>{let t=new MessageChannel;t.port1.onmessage=()=>c(),t.port2.postMessage(null)}).then(()=>{if(R(),a)return r(a);throw u}))}function f(e){let n="";for(let r=0;r<e.length;++r)if(r>0){let o=e[r].toLowerCase();o!==e[r]?n+=` ${o}`:n+=e[r]}else n+=e[r].toUpperCase();return n}var Pe={default:"endpoint"},ve={default:"tlsEndpoint"},ge="Client timeout",ke="Network connection error",Le="Network request aborted",be="Response cannot be parsed",B="Blocked by CSP",K="The endpoint parameter is not a valid URL",Ue="Handle on demand agent data error",Me=f("WrongRegion"),Se=f("SubscriptionNotActive"),xe=f("UnsupportedVersion"),Ge=f("InstallationMethodRestricted"),Be=f("HostnameRestricted"),Ke=f("IntegrationFailed"),Fe=f("NetworkRestricted"),Ve=f("InvalidProxyIntegrationSecret"),qe=f("InvalidProxyIntegrationHeaders"),je=f("ProxyIntegrationSecretEnvironmentMismatch"),F="API key required",Q="API key not found",C="API key expired",Ye="Request cannot be parsed",Xe="Request failed",$e="Request failed to process",We="Too many requests, rate limit exceeded",Ze="Not available for this origin",ze="Not available with restricted header",Je=F,Qe=Q,Ce=C,He="3.12.0",L="Failed to load the JS script of the agent",V="9319";function en(e,n){let r=[],[o,i]=function(l){let R=function(t){let d=[...t];return{current:()=>d[0],postpone(){let O=d.shift();O!==void 0&&d.push(O)},exclude(){d.shift()}}}(l),u=function(t,d){let O=0;return()=>Math.random()*Math.min(d,t*Math.pow(2,O++))}(100,3e3),c=new Set;return[R.current(),(t,d)=>{let O,A=d instanceof Error?d.message:"";if(A===B||A===K)R.exclude(),O=0;else if(A===V)R.exclude();else if(A===L){let h=Date.now()-t.getTime()<50,I=R.current();I&&h&&!c.has(I)&&(c.add(I),O=0),R.postpone()}else R.postpone();let N=R.current();return N===void 0?void 0:[N,O??t.getTime()+u()-Date.now()]}]}(e),E;if(o===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));let a=l=>{let R=new Date,u=t=>r.push({url:l,startedAt:R,finishedAt:new Date,error:t}),c=n(l);return c.then(()=>u(),u),c.catch(t=>{if(E!=null||(E=t),r.length>=5)throw E;let d=i(R,t);if(!d)throw E;let[O,A]=d;return(N=A,new Promise(h=>setTimeout(h,N))).then(()=>a(O));var N})};return a(o).then(l=>[l,r])}var H="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",nn=H;function rn(e){var n,r;let{picked:o,rest:i}=function(c,t){let d={},O={};for(let[A,N]of Object.entries(c))t.includes(A)?d[A]=N:O[A]=N;return{picked:d,rest:O}}(e,["scriptUrlPattern","token","apiKey"]),E=o.token,a=(n=o.apiKey)!==null&&n!==void 0?n:E,l=(r=ye(e,"scriptUrlPattern"))!==null&&r!==void 0?r:H,[R,u]=function(){let c=[],t=()=>{c.push({time:new Date,state:document.visibilityState})},d=function(O,A,N,h){return O.addEventListener(A,N,h),()=>O.removeEventListener(A,N,h)}(document,"visibilitychange",t);return t(),[c,d]}();return Promise.resolve().then(()=>{if(!a||typeof a!="string")throw new Error(F);let c=function(t,d){return(Array.isArray(t)?t:[t]).map(O=>function(A,N){let h=encodeURIComponent;return A.replace(/<[^<>]+>/g,I=>I==="<version>"?"3":I==="<apiKey>"?h(N):I==="<loaderVersion>"?h(He):I)}(String(O),d))}(l,a);return en(c,on)}).catch(c=>{throw u(),function(t){return t instanceof Error&&t.message===V?new Error(L):t}(c)}).then(([c,t])=>(u(),c.load({...i,ldi:{attempts:t,visibilityStates:R}})))}function on(e){return pe(e,()=>function(n){return new Promise((r,o)=>{if(function(l){if(URL.prototype)try{return new URL(l,location.href),!1}catch(R){if(R instanceof Error&&R.name==="TypeError")return!0;throw R}}(n))throw new Error(K);let i=document.createElement("script"),E=()=>{var l;return(l=i.parentNode)===null||l===void 0?void 0:l.removeChild(i)},a=document.head||document.getElementsByTagName("head")[0];i.onload=()=>{E(),r()},i.onerror=()=>{E(),o(new Error(L))},i.async=!0,i.src=n,a.appendChild(i)})}(e),()=>{throw new Error(B)}).then(tn)}function tn(){let e=window,n="__fpjs_p_l_b",r=e[n];if(function(o,i){var E;let a=(E=Object.getOwnPropertyDescriptor)===null||E===void 0?void 0:E.call(Object,o,i);a?.configurable?delete o[i]:a&&!a.writable||(o[i]=void 0)}(e,n),typeof r?.load!="function")throw new Error(V);return r}var y={load:rn,defaultScriptUrlPattern:nn,ERROR_SCRIPT_LOAD_FAIL:L,ERROR_API_KEY_EXPIRED:C,ERROR_API_KEY_INVALID:Q,ERROR_API_KEY_MISSING:F,ERROR_BAD_REQUEST_FORMAT:Ye,ERROR_BAD_RESPONSE_FORMAT:be,ERROR_CLIENT_TIMEOUT:ge,ERROR_CSP_BLOCK:B,ERROR_FORBIDDEN_ENDPOINT:Be,ERROR_FORBIDDEN_HEADER:ze,ERROR_FORBIDDEN_ORIGIN:Ze,ERROR_GENERAL_SERVER_FAILURE:Xe,ERROR_HANDLE_AGENT_DATA:Ue,ERROR_INSTALLATION_METHOD_RESTRICTED:Ge,ERROR_INTEGRATION_FAILURE:Ke,ERROR_INVALID_ENDPOINT:K,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:qe,ERROR_INVALID_PROXY_INTEGRATION_SECRET:Ve,ERROR_NETWORK_ABORT:Le,ERROR_NETWORK_CONNECTION:ke,ERROR_NETWORK_RESTRICTED:Fe,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:je,ERROR_RATE_LIMIT:We,ERROR_SERVER_TIMEOUT:$e,ERROR_SUBSCRIPTION_NOT_ACTIVE:Se,ERROR_TOKEN_EXPIRED:Ce,ERROR_TOKEN_INVALID:Qe,ERROR_TOKEN_MISSING:Je,ERROR_UNSUPPORTED_VERSION:xe,ERROR_WRONG_REGION:Me,defaultEndpoint:Pe,defaultTlsEndpoint:ve};var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function ee(e,n=0){return(m[e[n+0]]+m[e[n+1]]+m[e[n+2]]+m[e[n+3]]+"-"+m[e[n+4]]+m[e[n+5]]+"-"+m[e[n+6]]+m[e[n+7]]+"-"+m[e[n+8]]+m[e[n+9]]+"-"+m[e[n+10]]+m[e[n+11]]+m[e[n+12]]+m[e[n+13]]+m[e[n+14]]+m[e[n+15]]).toLowerCase()}var q,an=new Uint8Array(16);function j(){if(!q){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");q=crypto.getRandomValues.bind(crypto)}return q(an)}var cn=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Y={randomUUID:cn};function sn(e,n,r){if(Y.randomUUID&&!n&&!e)return Y.randomUUID();e=e||{};let o=e.random??e.rng?.()??j();if(o.length<16)throw new Error("Random bytes length must be >= 16");if(o[6]=o[6]&15|64,o[8]=o[8]&63|128,n){if(r=r||0,r<0||r+16>n.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let i=0;i<16;++i)n[r+i]=o[i];return n}return ee(o)}var b=sn;var En={UNAUTHORIZED:"Unauthorized"},Rn={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},ne={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key",MAINTENANCE_MODE:"API Under Maintenance",RATE_LIMIT_REACHED:"Too many requests. Rate limit exceeded"},re={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},ie={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},oe={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},te={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},s={...En,...Rn,...ne,...re,...ie,...oe,...te},ae={...ne,...re,...ie,...oe,...te};var v=(I=>(I.AR="ar",I.BN="bn",I.DE="de",I.EN="en",I.ES="es",I.FR="fr",I.HI="hi",I.ID="id",I.IT="it",I.JA="ja",I.KO="ko",I.MS="ms",I.NL="nl",I.PT="pt",I.RU="ru",I.YU="yu",I.ZH="zh",I))(v||{}),g=(_=>(_.GeneralConsumer="general-consumer",_.HRManagerDirector="hr-manager-director",_.WebDeveloper="web-developer",_.SoftwareEngineer="software-engineer",_.ITDirector="it-director",_.BusinessAdministrator="business-administrator",_.AccountsPayableManager="accounts-payable-manager",_.Accountant="accountant",_.FinanceDirector="finance-director",_.SmallBusinessOwner="small-business-owner",_.GeneralContractor="general-contractor",_.MarketingManagerDirector="marketing-manager-director",_.ConsumerShopper="consumer-shopper",_.Travel="travel",_.Entertainment="entertainment",_.FinanceAndBanking="finance-and-banking",_.General="general",_.B2BWhiteCollar="b2b-white-collar",_.B2BBlueCollar="b2b-blue-collar",_.Lawyer="lawyer",_))(g||{});var In=(e,n={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...n}),ln=async(e,n)=>{if(!e.ok){let r=await e.text();throw new Error(r)}return n==="file"?e.blob():n==="json"?e.json():n==="text"?e.text():null},ce=async({url:e,auth:n,body:r,method:o="GET",headers:i={},responseType:E="json"})=>{let a={method:o,headers:In(n,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},l=await fetch(e,a);return ln(l,E)},se=e=>ce({...e,method:"GET"}),U=e=>ce({...e,method:"POST"});function Ee(){let e=!1,n=!1,r=!1,o=null,i=0,E=()=>{e=!1,n=!1,r=!1,o=void 0,i=0},a=()=>{let c=window?.getSelection()?.toString();c&&c.length>0&&(i=Date.now(),e=!0)},l=u=>{let c=u.clipboardData?.getData("text"),t=u.target instanceof HTMLInputElement||u.target instanceof HTMLTextAreaElement;c&&t&&(r=!0)},R=()=>{n=!0;let u=Date.now();if(i){let c=(u-i)/1e3;(o===void 0||c<o)&&(o=c)}};return document?.addEventListener("copy",a),document?.addEventListener("paste",l),window?.addEventListener("blur",R),{get qbc(){return e},get mas(){return n},get apd(){return r},get scb(){return o},reset:E,destroy(){document?.removeEventListener("copy",a),document?.removeEventListener("paste",l),window?.removeEventListener("blur",R)}}}var M,D="https://api.dtect.io/security",S=`${D}/client/check`,w="",P="",Ie="0.0.15",le="7166bf18-b91e-407a-84fc-d57ac104de98",Te,Re,Tn="20000000-aaaa-bbbb-cccc-000000000002",x,T={isLoading:!1,token:"",visitorId:"",projectId:"",questionData:null,clientData:null,aiCheckData:null,tokens:null};var ue=ae,k;function X(e){if(e instanceof Error){if(e?.message?.includes("maintenance_mode"))throw new Error(s.MAINTENANCE_MODE);if(e?.message?.includes("rate-limited"))throw new Error(s.RATE_LIMIT_REACHED);switch(e?.message){case y.ERROR_RATE_LIMIT:throw new Error(s.RATE_LIMIT_REACHED);default:throw new Error(s.INTERNAL_SERVER_ERROR)}}throw new Error(s.FAILED_TO_GET_SECURITY_TOKEN)}function p(){let e=window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"),n=document.querySelector("#dtect-h-captcha");return!!(M&&(n||e))}function _e(){return!!(w&&P)}function un(){return new Promise(e=>{let n=()=>{window?.hcaptcha?e():requestAnimationFrame(n)};n()})}var de=()=>window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///");async function _n({behaviorKey:e}){if(M=await y.load({apiKey:e,endpoint:["https://fp.dtect.io",y.defaultEndpoint],scriptUrlPattern:["https://fp.dtect.io/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",y.defaultScriptUrlPattern]}),de()||(await un(),await window.hcaptcha.render("dtect-h-captcha",{sitekey:le,size:"invisible"})),!M)throw new Error(s.SDK_INIT_ERROR)}async function dn(){if(T.tokens)return T.tokens;let e=new Promise(i=>{let E=M?.get();i(E)}),n=new Promise(async i=>{de()&&i({response:Tn}),await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:le,size:"invisible"});let a=await window?.hcaptcha?.execute({async:!0});i(a)}),[r,o]=await Promise.all([n,e]);return T.tokens={behaviorRequestId:o?.requestId,behaviorToken:o?.sealedResult,automationToken:r?.response},T.tokens}async function Oe(e,n){if(!p())throw new Error(s.NOT_INITIALIZED);if(!_e())throw new Error(s.MISSING_CREDENTIALS);let{projectId:r,visitorId:o}=On(e);if(!e||!r?.trim())throw new Error(s.FAILED_TO_GET_SECURITY_RESULT);try{let i=await dn();if(i?.behaviorToken&&i?.behaviorRequestId&&i?.automationToken){let E={behaviorToken:i.behaviorToken,automationToken:i.automationToken,behaviorRequestId:i.behaviorRequestId,entryLink:window?.location?.href,securitySettings:e.securitySettings,metaData:e.metaData};T.clientData=E;let a={...e,projectId:r?.trim(),visitorId:o?.trim()||b(),clientData:E,version:"0.0.15",token:T.token,questionData:T.questionData,aiCheckData:T.aiCheckData};Re=performance.now();let l=(Re-Te).toFixed(),R=await U({url:`${n}?clientId=${w}&diff=${l}`,body:{...a},headers:{"client-id":w,"x-api-key":P}});if("token"in R||"results"in R)return R}throw new Error(s.INTERNAL_SERVER_ERROR)}catch(i){if(i instanceof Error){if(i?.message?.includes("maintenance_mode"))throw new Error(s.MAINTENANCE_MODE);if(i?.message?.includes("rate-limited")||i?.message?.includes("429"))throw new Error(s.RATE_LIMIT_REACHED);switch(i?.message){case y.ERROR_RATE_LIMIT:throw new Error(s.RATE_LIMIT_REACHED);default:throw new Error(s.INTERNAL_SERVER_ERROR)}}throw new Error(s.FAILED_TO_GET_SECURITY_RESULT)}}async function $(e){return await Oe(e,`${D}/client/check/result`)}async function W(e){return await Oe(e,`${D}/client/check`)}function On(e){let n=e?.projectId,r=e?.visitorId;return(typeof e?.projectId=="number"||typeof e?.visitorId=="number")&&(n=`${e?.projectId}`,r=`${e?.visitorId}`),{visitorId:r,projectId:n}}async function Z(e){if(!p())throw new Error(s.NOT_INITIALIZED);let{respondentType:n,language:r}=e;try{let o=await se({url:`${D}/client/quality-questions/${n}/${r}`,headers:{"client-id":w,"x-api-key":P}});if(o)return o;throw new Error(s.INTERNAL_SERVER_ERROR)}catch(o){X(o)}}async function z(e){if(!p())throw new Error(s.NOT_INITIALIZED);T.questionData={questions:e.questions};try{let n=await U({url:S,headers:{"client-id":w,"x-api-key":P},body:{token:T.token,visitorId:e.visitorId,projectId:e.projectId,version:Ie,questionData:T.questionData,aiCheckData:T.aiCheckData,clientData:T.clientData}});if(n)return n;throw new Error(s.INTERNAL_SERVER_ERROR)}catch(n){X(n)}}async function J(e){if(!p())throw new Error(s.NOT_INITIALIZED);T.aiCheckData={timeTakenSeconds:e.timeTakenSeconds,qbc:e.qbc||k.qbc,mas:e.mas||k.mas,scb:e.scb||k.scb,apd:e.apd||k.apd};try{let n=await U({url:S,headers:{"client-id":w,"x-api-key":P},body:{token:T.token,visitorId:e.visitorId,projectId:e.projectId,version:Ie,clientData:T.clientData,questionData:T.questionData,aiCheckData:T.aiCheckData}});if(n)return n;throw new Error(s.INTERNAL_SERVER_ERROR)}catch(n){X(n)}}async function mn(){return b()}function An(){let e=document.querySelector("head"),n=document.querySelector("body");if(!(window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"))){n?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let o=document.createElement("script");o.setAttribute("src","https://js.hcaptcha.com/1/api.js"),o.setAttribute("async","true"),o.setAttribute("defer","true"),e?.append(o)}}async function me(e){if(!e?.clientId||!e?.apiKey)throw new Error(s.MISSING_CREDENTIALS);Te=performance.now();let{clientId:n,apiKey:r,endpoint:o="https://api.dtect.io/security",includeResults:i}=e;D=o,S=`${D}/client/check`;let E=await mn();if(T.isLoading){if(p())return x;throw new Error(s.DUPLICATE_INITIALIZATION)}if(k=Ee(),w=n,P=r,i&&(S=`${D}/client/check/result`),T={...T,isLoading:!0,token:E||""},!_e())throw new Error(s.MISSING_CREDENTIALS);if(p())return x;An();try{return _n({behaviorKey:"bwDZ0V3Zrb4SB6g4lZwW"}).then(()=>({getSecurityResult:$,getSecurityToken:W,SecurityAPIError:ue,isAIUsageDetected:J,checkQualityQuestions:z,getQualityQuestions:Z,LanguageCodes:v,QualityQuestionsRespondentTypes:g})).catch(a=>{throw new Error(a.message)})}catch(a){if(a instanceof Error){if(a?.message?.includes("maintenance_mode"))throw new Error(s.MAINTENANCE_MODE);if([s.INVALID_API_KEY,s.UNAUTHORIZED].includes(a?.message))throw new Error(s.INVALID_CREDENTIALS)}throw new Error(s.SDK_INIT_ERROR)}finally{T={...T,isLoading:!1,token:E}}}x={init:me,getSecurityResult:$,getSecurityToken:W,isAIUsageDetected:J,checkQualityQuestions:z,getQualityQuestions:Z,QualityQuestionsRespondentTypes:g,LanguageCodes:v};var Nn=x;
|
|
1
|
+
"use strict";var ne=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ht=Object.prototype.hasOwnProperty;var ft=(e,t)=>{for(var r in t)ne(e,r,{get:t[r],enumerable:!0})},dt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of lt(t))!ht.call(e,i)&&i!==r&&ne(e,i,{get:()=>t[i],enumerable:!(n=ut(t,i))||n.enumerable});return e};var Et=e=>dt(ne({},"__esModule",{value:!0}),e);var _r={};ft(_r,{LanguageCodes:()=>x,QualityQuestionsRespondentTypes:()=>q,SecurityAPIError:()=>nt,checkQualityQuestions:()=>ve,default:()=>Or,getQualityQuestions:()=>_e,getSecurityResult:()=>Te,getSecurityToken:()=>Oe,init:()=>at,isAIUsageDetected:()=>ge});module.exports=Et(_r);function Rt(e,t){return function(r,n){return Object.prototype.hasOwnProperty.call(r,n)}(e,t)?e[t]:void 0}function mt(e,t,r,n){let i=document,o="securitypolicyviolation",c,s=d=>{let u=new URL(e,location.href),{blockedURI:l}=d;l!==u.href&&l!==u.protocol.slice(0,-1)&&l!==u.origin||(c=d,a())};i.addEventListener(o,s);let a=()=>i.removeEventListener(o,s);return n?.then(a,a),Promise.resolve().then(t).then(d=>(a(),d),d=>new Promise(u=>{let l=new MessageChannel;l.port1.onmessage=()=>u(),l.port2.postMessage(null)}).then(()=>{if(a(),c)return r(c);throw d}))}function g(e){let t="";for(let r=0;r<e.length;++r)if(r>0){let n=e[r].toLowerCase();n!==e[r]?t+=` ${n}`:t+=e[r]}else t+=e[r].toUpperCase();return t}var pt={default:"endpoint"},yt={default:"tlsEndpoint"},It="Client timeout",Tt="Network connection error",Ot="Network request aborted",_t="Response cannot be parsed",ie="Blocked by CSP",se="The endpoint parameter is not a valid URL",vt="Handle on demand agent data error",gt=g("WrongRegion"),At=g("SubscriptionNotActive"),wt=g("UnsupportedVersion"),Dt=g("InstallationMethodRestricted"),Nt=g("HostnameRestricted"),bt=g("IntegrationFailed"),Pt=g("NetworkRestricted"),St=g("InvalidProxyIntegrationSecret"),kt=g("InvalidProxyIntegrationHeaders"),Mt=g("ProxyIntegrationSecretEnvironmentMismatch"),oe="API key required",Ae="API key not found",we="API key expired",Lt="Request cannot be parsed",Ut="Request failed",Ft="Request failed to process",xt="Too many requests, rate limit exceeded",qt="Not available for this origin",Kt="Not available with restricted header",Gt=oe,Bt=Ae,jt=we,Ct="3.12.0",V="Failed to load the JS script of the agent",ae="9319";function Vt(e,t){let r=[],[n,i]=function(s){let a=function(l){let m=[...l];return{current:()=>m[0],postpone(){let p=m.shift();p!==void 0&&m.push(p)},exclude(){m.shift()}}}(s),d=function(l,m){let p=0;return()=>Math.random()*Math.min(m,l*Math.pow(2,p++))}(100,3e3),u=new Set;return[a.current(),(l,m)=>{let p,E=m instanceof Error?m.message:"";if(E===ie||E===se)a.exclude(),p=0;else if(E===ae)a.exclude();else if(E===V){let O=Date.now()-l.getTime()<50,h=a.current();h&&O&&!u.has(h)&&(u.add(h),p=0),a.postpone()}else a.postpone();let f=a.current();return f===void 0?void 0:[f,p??l.getTime()+d()-Date.now()]}]}(e),o;if(n===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));let c=s=>{let a=new Date,d=l=>r.push({url:s,startedAt:a,finishedAt:new Date,error:l}),u=t(s);return u.then(()=>d(),d),u.catch(l=>{if(o!=null||(o=l),r.length>=5)throw o;let m=i(a,l);if(!m)throw o;let[p,E]=m;return(f=E,new Promise(O=>setTimeout(O,f))).then(()=>c(p));var f})};return c(n).then(s=>[s,r])}var De="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Qt=De;function Yt(e){var t,r;let{picked:n,rest:i}=function(u,l){let m={},p={};for(let[E,f]of Object.entries(u))l.includes(E)?m[E]=f:p[E]=f;return{picked:m,rest:p}}(e,["scriptUrlPattern","token","apiKey"]),o=n.token,c=(t=n.apiKey)!==null&&t!==void 0?t:o,s=(r=Rt(e,"scriptUrlPattern"))!==null&&r!==void 0?r:De,[a,d]=function(){let u=[],l=()=>{u.push({time:new Date,state:document.visibilityState})},m=function(p,E,f,O){return p.addEventListener(E,f,O),()=>p.removeEventListener(E,f,O)}(document,"visibilitychange",l);return l(),[u,m]}();return Promise.resolve().then(()=>{if(!c||typeof c!="string")throw new Error(oe);let u=function(l,m){return(Array.isArray(l)?l:[l]).map(p=>function(E,f){let O=encodeURIComponent;return E.replace(/<[^<>]+>/g,h=>h==="<version>"?"3":h==="<apiKey>"?O(f):h==="<loaderVersion>"?O(Ct):h)}(String(p),m))}(s,c);return Vt(u,$t)}).catch(u=>{throw d(),function(l){return l instanceof Error&&l.message===ae?new Error(V):l}(u)}).then(([u,l])=>(d(),u.load({...i,ldi:{attempts:l,visibilityStates:a}})))}function $t(e){return mt(e,()=>function(t){return new Promise((r,n)=>{if(function(s){if(URL.prototype)try{return new URL(s,location.href),!1}catch(a){if(a instanceof Error&&a.name==="TypeError")return!0;throw a}}(t))throw new Error(se);let i=document.createElement("script"),o=()=>{var s;return(s=i.parentNode)===null||s===void 0?void 0:s.removeChild(i)},c=document.head||document.getElementsByTagName("head")[0];i.onload=()=>{o(),r()},i.onerror=()=>{o(),n(new Error(V))},i.async=!0,i.src=t,c.appendChild(i)})}(e),()=>{throw new Error(ie)}).then(Xt)}function Xt(){let e=window,t="__fpjs_p_l_b",r=e[t];if(function(n,i){var o;let c=(o=Object.getOwnPropertyDescriptor)===null||o===void 0?void 0:o.call(Object,n,i);c?.configurable?delete n[i]:c&&!c.writable||(n[i]=void 0)}(e,t),typeof r?.load!="function")throw new Error(ae);return r}var k={load:Yt,defaultScriptUrlPattern:Qt,ERROR_SCRIPT_LOAD_FAIL:V,ERROR_API_KEY_EXPIRED:we,ERROR_API_KEY_INVALID:Ae,ERROR_API_KEY_MISSING:oe,ERROR_BAD_REQUEST_FORMAT:Lt,ERROR_BAD_RESPONSE_FORMAT:_t,ERROR_CLIENT_TIMEOUT:It,ERROR_CSP_BLOCK:ie,ERROR_FORBIDDEN_ENDPOINT:Nt,ERROR_FORBIDDEN_HEADER:Kt,ERROR_FORBIDDEN_ORIGIN:qt,ERROR_GENERAL_SERVER_FAILURE:Ut,ERROR_HANDLE_AGENT_DATA:vt,ERROR_INSTALLATION_METHOD_RESTRICTED:Dt,ERROR_INTEGRATION_FAILURE:bt,ERROR_INVALID_ENDPOINT:se,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:kt,ERROR_INVALID_PROXY_INTEGRATION_SECRET:St,ERROR_NETWORK_ABORT:Ot,ERROR_NETWORK_CONNECTION:Tt,ERROR_NETWORK_RESTRICTED:Pt,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:Mt,ERROR_RATE_LIMIT:xt,ERROR_SERVER_TIMEOUT:Ft,ERROR_SUBSCRIPTION_NOT_ACTIVE:At,ERROR_TOKEN_EXPIRED:jt,ERROR_TOKEN_INVALID:Bt,ERROR_TOKEN_MISSING:Gt,ERROR_UNSUPPORTED_VERSION:wt,ERROR_WRONG_REGION:gt,defaultEndpoint:pt,defaultTlsEndpoint:yt};var _=[];for(let e=0;e<256;++e)_.push((e+256).toString(16).slice(1));function Ne(e,t=0){return(_[e[t+0]]+_[e[t+1]]+_[e[t+2]]+_[e[t+3]]+"-"+_[e[t+4]]+_[e[t+5]]+"-"+_[e[t+6]]+_[e[t+7]]+"-"+_[e[t+8]]+_[e[t+9]]+"-"+_[e[t+10]]+_[e[t+11]]+_[e[t+12]]+_[e[t+13]]+_[e[t+14]]+_[e[t+15]]).toLowerCase()}var ce,Wt=new Uint8Array(16);function ue(){if(!ce){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ce=crypto.getRandomValues.bind(crypto)}return ce(Wt)}var zt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),le={randomUUID:zt};function Jt(e,t,r){if(le.randomUUID&&!t&&!e)return le.randomUUID();e=e||{};let n=e.random??e.rng?.()??ue();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 Ne(n)}var Q=Jt;var Zt={UNAUTHORIZED:"Unauthorized"},Ht={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",RATE_LIMIT_REACHED:"Too many requests. Rate limit exceeded"},Pe={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},Se={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},ke={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},Me={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},R={...Zt,...Ht,...be,...Pe,...Se,...ke,...Me},Le={...be,...Pe,...Se,...ke,...Me};var x=(h=>(h.AR="ar",h.BN="bn",h.DE="de",h.EN="en",h.ES="es",h.FR="fr",h.HI="hi",h.ID="id",h.IT="it",h.JA="ja",h.KO="ko",h.MS="ms",h.NL="nl",h.PT="pt",h.RU="ru",h.YU="yu",h.ZH="zh",h))(x||{}),q=(y=>(y.GeneralConsumer="general-consumer",y.HRManagerDirector="hr-manager-director",y.WebDeveloper="web-developer",y.SoftwareEngineer="software-engineer",y.ITDirector="it-director",y.BusinessAdministrator="business-administrator",y.AccountsPayableManager="accounts-payable-manager",y.Accountant="accountant",y.FinanceDirector="finance-director",y.SmallBusinessOwner="small-business-owner",y.GeneralContractor="general-contractor",y.MarketingManagerDirector="marketing-manager-director",y.ConsumerShopper="consumer-shopper",y.Travel="travel",y.Entertainment="entertainment",y.FinanceAndBanking="finance-and-banking",y.General="general",y.B2BWhiteCollar="b2b-white-collar",y.B2BBlueCollar="b2b-blue-collar",y.Lawyer="lawyer",y))(q||{});var er=(e,t={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...t}),tr=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},Ue=async({url:e,auth:t,body:r,method:n="GET",headers:i={},responseType:o="json"})=>{let c={method:n,headers:er(t,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},s=await fetch(e,c);return tr(s,o)},he=e=>Ue({...e,method:"GET"}),Y=e=>Ue({...e,method:"POST"});function Fe(){let e=!1,t=!1,r=!1,n=null,i=0,o=()=>{e=!1,t=!1,r=!1,n=void 0,i=0},c=()=>{let u=window?.getSelection()?.toString();u&&u.length>0&&(i=Date.now(),e=!0)},s=d=>{let u=d.clipboardData?.getData("text"),l=d.target instanceof HTMLInputElement||d.target instanceof HTMLTextAreaElement;u&&l&&(r=!0)},a=()=>{t=!0;let d=Date.now();if(i){let u=(d-i)/1e3;(n===void 0||u<n)&&(n=u)}};return document?.addEventListener("copy",c),document?.addEventListener("paste",s),window?.addEventListener("blur",a),{get qbc(){return e},get mas(){return t},get apd(){return r},get scb(){return n},reset:o,destroy(){document?.removeEventListener("copy",c),document?.removeEventListener("paste",s),window?.removeEventListener("blur",a)}}}var A=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var w=typeof window>"u"||"Deno"in globalThis;function v(){}function Ke(e,t){return typeof e=="function"?e(t):e}function Ge(e){return typeof e=="number"&&e>=0&&e!==1/0}function Be(e,t){return Math.max(e+(t||0)-Date.now(),0)}function de(e,t){return typeof e=="function"?e(t):e}function je(e,t){return typeof e=="function"?e(t):e}function Ee(e,t){let{type:r="all",exact:n,fetchStatus:i,predicate:o,queryKey:c,stale:s}=e;if(c){if(n){if(t.queryHash!==K(c,t.options))return!1}else if(!L(t.queryKey,c))return!1}if(r!=="all"){let a=t.isActive();if(r==="active"&&!a||r==="inactive"&&a)return!1}return!(typeof s=="boolean"&&t.isStale()!==s||i&&i!==t.state.fetchStatus||o&&!o(t))}function Re(e,t){let{exact:r,status:n,predicate:i,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(r){if(M(t.options.mutationKey)!==M(o))return!1}else if(!L(t.options.mutationKey,o))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function K(e,t){return(t?.queryKeyHashFn||M)(e)}function M(e){return JSON.stringify(e,(t,r)=>fe(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}function L(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!L(e[r],t[r])):!1}function Ce(e,t){if(e===t)return e;let r=xe(e)&&xe(t);if(r||fe(e)&&fe(t)){let n=r?e:Object.keys(e),i=n.length,o=r?t:Object.keys(t),c=o.length,s=r?[]:{},a=0;for(let d=0;d<c;d++){let u=r?d:o[d];(!r&&n.includes(u)||r)&&e[u]===void 0&&t[u]===void 0?(s[u]=void 0,a++):(s[u]=Ce(e[u],t[u]),s[u]===e[u]&&e[u]!==void 0&&a++)}return i===c&&a===i?e:s}return t}function xe(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function fe(e){if(!qe(e))return!1;let t=e.constructor;if(t===void 0)return!0;let r=t.prototype;return!(!qe(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function qe(e){return Object.prototype.toString.call(e)==="[object Object]"}function Ve(e){return new Promise(t=>{setTimeout(t,e)})}function Qe(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?Ce(e,t):t}function Ye(e,t,r=0){let n=[...e,t];return r&&n.length>r?n.slice(1):n}function $e(e,t,r=0){let n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var G=Symbol();function $(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===G?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var rr=class extends A{#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"}},X=new rr;var nr=class extends A{#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}},U=new nr;function Xe(){let e,t,r=new Promise((i,o)=>{e=i,t=o});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 ir(e){return Math.min(1e3*2**e,3e4)}function me(e){return(e??"online")==="online"?U.isOnline():!0}var We=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function W(e){return e instanceof We}function z(e){let t=!1,r=0,n=!1,i,o=Xe(),c=f=>{n||(m(new We(f)),e.abort?.())},s=()=>{t=!0},a=()=>{t=!1},d=()=>X.isFocused()&&(e.networkMode==="always"||U.isOnline())&&e.canRun(),u=()=>me(e.networkMode)&&e.canRun(),l=f=>{n||(n=!0,e.onSuccess?.(f),i?.(),o.resolve(f))},m=f=>{n||(n=!0,e.onError?.(f),i?.(),o.reject(f))},p=()=>new Promise(f=>{i=O=>{(n||d())&&f(O)},e.onPause?.()}).then(()=>{i=void 0,n||e.onContinue?.()}),E=()=>{if(n)return;let f,O=r===0?e.initialPromise:void 0;try{f=O??e.fn()}catch(h){f=Promise.reject(h)}Promise.resolve(f).then(l).catch(h=>{if(n)return;let N=e.retry??(w?0:3),S=e.retryDelay??ir,y=typeof S=="function"?S(r,h):S,ct=N===!0||typeof N=="number"&&r<N||typeof N=="function"&&N(r,h);if(t||!ct){m(h);return}r++,e.onFail?.(r,h),Ve(y).then(()=>d()?void 0:p()).then(()=>{t?m(h):E()})})};return{promise:o,cancel:c,continue:()=>(i?.(),o),cancelRetry:s,continueRetry:a,canStart:u,start:()=>(u()?E():p().then(E),o)}}function sr(){let e=[],t=0,r=s=>{s()},n=s=>{s()},i=s=>setTimeout(s,0),o=s=>{t?e.push(s):i(()=>{r(s)})},c=()=>{let s=e;e=[],s.length&&i(()=>{n(()=>{s.forEach(a=>{r(a)})})})};return{batch:s=>{let a;t++;try{a=s()}finally{t--,t||c()}return a},batchCalls:s=>(...a)=>{o(()=>{s(...a)})},schedule:o,setNotifyFunction:s=>{r=s},setBatchNotifyFunction:s=>{n=s},setScheduler:s=>{i=s}}}var T=sr();var J=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Ge(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 ze=class extends J{#e;#t;#r;#n;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=ar(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.#o,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let r=Qe(this.state.data,e,this.options);return this.#i({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#i({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(v).catch(v):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>je(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===G||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||!Be(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.#s?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 s=this.observers.find(a=>a.options.queryFn);s&&this.setOptions(s.options)}let r=new AbortController,n=s=>{Object.defineProperty(s,"signal",{enumerable:!0,get:()=>(this.#s=!0,r.signal)})},i=()=>{let s=$(this.options,t),a={queryKey:this.queryKey,meta:this.meta};return n(a),this.#s=!1,this.options.persister?this.options.persister(s,a,this):s(a)},o={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};n(o),this.options.behavior?.onFetch(o,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==o.fetchOptions?.meta)&&this.#i({type:"fetch",meta:o.fetchOptions?.meta});let c=s=>{W(s)&&s.silent||this.#i({type:"error",error:s}),W(s)||(this.#r.config.onError?.(s,this),this.#r.config.onSettled?.(this.state.data,s,this)),this.scheduleGc()};return this.#n=z({initialPromise:t?.initialPromise,fn:o.fetchFn,abort:r.abort.bind(r),onSuccess:s=>{if(s===void 0){c(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(s)}catch(a){c(a);return}this.#r.config.onSuccess?.(s,this),this.#r.config.onSettled?.(s,this.state.error,this),this.scheduleGc()},onError:c,onFail:(s,a)=>{this.#i({type:"failed",failureCount:s,error:a})},onPause:()=>{this.#i({type:"pause"})},onContinue:()=>{this.#i({type:"continue"})},retry:o.options.retry,retryDelay:o.options.retryDelay,networkMode:o.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,...or(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 W(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),T.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function or(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:me(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function ar(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 B=class extends A{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,r){let n=t.queryKey,i=t.queryHash??K(n,t),o=this.get(i);return o||(o=new ze({cache:this,queryKey:n,queryHash:i,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(n)}),this.add(o)),o}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(){T.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=>Ee(t,r))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(r=>Ee(e,r)):t}notify(e){T.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){T.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){T.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var Je=class extends J{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||cr(),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=z({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),T.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function cr(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var j=class extends A{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 Je({mutationCache:this,mutationId:++this.#r,options:e.defaultMutationOptions(t),state:r});return this.add(n),n}add(e){this.#e.add(e);let t=Z(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=Z(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=Z(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=Z(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){T.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=>Re(t,r))}findAll(e={}){return this.getAll().filter(t=>Re(e,t))}notify(e){T.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return T.batch(()=>Promise.all(e.map(t=>t.continue().catch(v))))}};function Z(e){return e.options.scope?.id}function pe(e){return{onFetch:(t,r)=>{let n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,o=t.state.data?.pages||[],c=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},a=0,d=async()=>{let u=!1,l=E=>{Object.defineProperty(E,"signal",{enumerable:!0,get:()=>(t.signal.aborted?u=!0:t.signal.addEventListener("abort",()=>{u=!0}),t.signal)})},m=$(t.options,t.fetchOptions),p=async(E,f,O)=>{if(u)return Promise.reject();if(f==null&&E.pages.length)return Promise.resolve(E);let h={queryKey:t.queryKey,pageParam:f,direction:O?"backward":"forward",meta:t.options.meta};l(h);let N=await m(h),{maxPages:S}=t.options,y=O?$e:Ye;return{pages:y(E.pages,N,S),pageParams:y(E.pageParams,f,S)}};if(i&&o.length){let E=i==="backward",f=E?ur:Ze,O={pages:o,pageParams:c},h=f(n,O);s=await p(O,h,E)}else{let E=e??o.length;do{let f=a===0?c[0]??n.initialPageParam:Ze(n,s);if(a>0&&f==null)break;s=await p(s,f),a++}while(a<E)}return s};t.options.persister?t.fetchFn=()=>t.options.persister?.(d,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=d}}}function Ze(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 ur(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var ye=class{#e;#t;#r;#n;#o;#s;#i;#a;constructor(e={}){this.#e=e.queryCache||new B,this.#t=e.mutationCache||new j,this.#r=e.defaultOptions||{},this.#n=new Map,this.#o=new Map,this.#s=0}mount(){this.#s++,this.#s===1&&(this.#i=X.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=U.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#s--,this.#s===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(de(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}),o=this.#e.get(n.queryHash)?.state.data,c=Ke(t,o);if(c!==void 0)return this.#e.build(this,n).setData(c,{...r,manual:!0})}setQueriesData(e,t,r){return T.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;T.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){let r=this.#e,n={type:"active",...e};return T.batch(()=>(r.findAll(e).forEach(i=>{i.reset()}),this.refetchQueries(n,t)))}cancelQueries(e,t={}){let r={revert:!0,...t},n=T.batch(()=>this.#e.findAll(e).map(i=>i.cancel(r)));return Promise.all(n).then(v).catch(v)}invalidateQueries(e,t={}){return T.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=T.batch(()=>this.#e.findAll(e).filter(i=>!i.isDisabled()).map(i=>{let o=i.fetch(void 0,r);return r.throwOnError||(o=o.catch(v)),i.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(n).then(v)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let r=this.#e.build(this,t);return r.isStaleByTime(de(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(v).catch(v)}fetchInfiniteQuery(e){return e.behavior=pe(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(v).catch(v)}ensureInfiniteQueryData(e){return e.behavior=pe(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return U.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(M(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#n.values()],r={};return t.forEach(n=>{L(e,n.queryKey)&&Object.assign(r,n.defaultOptions)}),r}setMutationDefaults(e,t){this.#o.set(M(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#o.values()],r={};return t.forEach(n=>{L(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=K(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===G&&(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 lr=new ye({defaultOptions:{queries:{staleTime:3e4}},queryCache:new B({onError:(e,t)=>{}}),mutationCache:new j}),He=lr;var H,b="https://api.dtect.io/security",ee=`${b}/client/check`,D="",P="",tt="0.0.16",re,rt,et,hr="20000000-aaaa-bbbb-cccc-000000000002",te,I={isLoading:!1,token:"",visitorId:"",projectId:"",questionData:null,clientData:null,aiCheckData:null,tokens:null};var nt=Le,C;async function fr({clientId:e,apiKey:t,endpoint:r}){return await He.fetchQuery({queryKey:["getClientConfig",e,t],queryFn:()=>he({url:`${r}/client/config`,headers:{"client-id":D,"x-api-key":P}})})}function Ie(e){if(e instanceof Error){if(e?.message?.includes("maintenance_mode"))throw new Error(R.MAINTENANCE_MODE);if(e?.message?.includes("rate-limited"))throw new Error(R.RATE_LIMIT_REACHED);switch(e?.message){case k.ERROR_RATE_LIMIT:throw new Error(R.RATE_LIMIT_REACHED);default:throw new Error(R.INTERNAL_SERVER_ERROR)}}throw new Error(R.FAILED_TO_GET_SECURITY_TOKEN)}function F(){let e=window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"),t=document.querySelector("#dtect-h-captcha");return!!(H&&(t||e))}function it(){return!!(D&&P)}function dr(){return new Promise(e=>{let t=()=>{window?.hcaptcha?e():requestAnimationFrame(t)};t()})}var st=()=>window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///");async function Er({behaviorKey:e}){if(H=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]}),st()||(await dr(),await window.hcaptcha.render("dtect-h-captcha",{sitekey:re,size:"invisible"})),!H)throw new Error(R.SDK_INIT_ERROR)}async function Rr(){if(I.tokens)return I.tokens;let e=new Promise(i=>{let o=H?.get();i(o)}),t=new Promise(async i=>{st()&&i({response:hr}),await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:re,size:"invisible"});let c=await window?.hcaptcha?.execute({async:!0});i(c)}),[r,n]=await Promise.all([t,e]);return I.tokens={behaviorRequestId:n?.requestId,behaviorToken:n?.sealedResult,automationToken:r?.response},I.tokens}async function ot(e,t){if(!F())throw new Error(R.NOT_INITIALIZED);if(!it())throw new Error(R.MISSING_CREDENTIALS);let{projectId:r,visitorId:n}=mr(e);if(!e||!r?.trim())throw new Error(R.FAILED_TO_GET_SECURITY_RESULT);try{let i=await Rr();if(i?.behaviorToken&&i?.behaviorRequestId&&i?.automationToken){let o={behaviorToken:i.behaviorToken,automationToken:i.automationToken,behaviorRequestId:i.behaviorRequestId,entryLink:window?.location?.href,securitySettings:e.securitySettings,metaData:e.metaData};I.clientData=o;let c={...e,projectId:r?.trim(),visitorId:n?.trim()||Q(),clientData:o,version:"0.0.16",token:I.token,questionData:I.questionData,aiCheckData:I.aiCheckData};et=performance.now();let s=(et-rt).toFixed(),a=await Y({url:`${t}?clientId=${D}&diff=${s}`,body:{...c},headers:{"client-id":D,"x-api-key":P}});if("token"in a||"results"in a)return a}throw new Error(R.INTERNAL_SERVER_ERROR)}catch(i){if(i instanceof Error){if(i?.message?.includes("maintenance_mode"))throw new Error(R.MAINTENANCE_MODE);if(i?.message?.includes("rate-limited")||i?.message?.includes("429"))throw new Error(R.RATE_LIMIT_REACHED);switch(i?.message){case k.ERROR_RATE_LIMIT:throw new Error(R.RATE_LIMIT_REACHED);default:throw new Error(R.INTERNAL_SERVER_ERROR)}}throw new Error(R.FAILED_TO_GET_SECURITY_RESULT)}}async function Te(e){return await ot(e,`${b}/client/check/result`)}async function Oe(e){return await ot(e,`${b}/client/check`)}function mr(e){let t=e?.projectId,r=e?.visitorId;return(typeof e?.projectId=="number"||typeof e?.visitorId=="number")&&(t=`${e?.projectId}`,r=`${e?.visitorId}`),{visitorId:r,projectId:t}}async function _e(e){if(!F())throw new Error(R.NOT_INITIALIZED);let{respondentType:t,language:r}=e;try{let n=await he({url:`${b}/client/quality-questions/${t}/${r}`,headers:{"client-id":D,"x-api-key":P}});if(n)return n;throw new Error(R.INTERNAL_SERVER_ERROR)}catch(n){Ie(n)}}async function ve(e){if(!F())throw new Error(R.NOT_INITIALIZED);I.questionData={questions:e.questions};try{let t=await Y({url:ee,headers:{"client-id":D,"x-api-key":P},body:{token:I.token,visitorId:e.visitorId,projectId:e.projectId,version:tt,questionData:I.questionData,aiCheckData:I.aiCheckData,clientData:I.clientData}});if(t)return t;throw new Error(R.INTERNAL_SERVER_ERROR)}catch(t){Ie(t)}}async function ge(e){if(!F())throw new Error(R.NOT_INITIALIZED);I.aiCheckData={timeTakenSeconds:e.timeTakenSeconds,qbc:e.qbc||C.qbc,mas:e.mas||C.mas,scb:e.scb||C.scb,apd:e.apd||C.apd};try{let t=await Y({url:ee,headers:{"client-id":D,"x-api-key":P},body:{token:I.token,visitorId:e.visitorId,projectId:e.projectId,version:tt,clientData:I.clientData,questionData:I.questionData,aiCheckData:I.aiCheckData}});if(t)return t;throw new Error(R.INTERNAL_SERVER_ERROR)}catch(t){Ie(t)}}async function pr(){return Q()}function yr(){let e=document.querySelector("head"),t=document.querySelector("body");if(!(window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"))){t?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let n=document.createElement("script");n.setAttribute("src","https://js.hcaptcha.com/1/api.js"),n.setAttribute("async","true"),n.setAttribute("defer","true"),e?.append(n)}}function Ir(){return!!re}function Tr(e){return e?.automationKey&&e?.behaviorKey}async function at(e){if(!e?.clientId||!e?.apiKey)throw new Error(R.MISSING_CREDENTIALS);rt=performance.now();let{clientId:t,apiKey:r,endpoint:n="https://api.dtect.io/security",includeResults:i}=e;b=n,ee=`${b}/client/check`;let o=await pr();if(I.isLoading){if(F())return te;throw new Error(R.DUPLICATE_INITIALIZATION)}if(C=Fe(),D=t,P=r,i&&(ee=`${b}/client/check/result`),I={...I,isLoading:!0,token:o||""},!it())throw new Error(R.MISSING_CREDENTIALS);if(F())return te;yr();try{let c=await fr({clientId:t,apiKey:r,endpoint:n});if(!Tr(c)||Ir())throw new Error;return re=c.automationKey,Er({behaviorKey:c.behaviorKey}).then(()=>({getSecurityResult:Te,getSecurityToken:Oe,SecurityAPIError:nt,isAIUsageDetected:ge,checkQualityQuestions:ve,getQualityQuestions:_e,LanguageCodes:x,QualityQuestionsRespondentTypes:q})).catch(s=>{throw new Error(s.message)})}catch(c){if(c instanceof Error){if(c?.message?.includes("maintenance_mode"))throw new Error(R.MAINTENANCE_MODE);if([R.INVALID_API_KEY,R.UNAUTHORIZED].includes(c?.message))throw new Error(R.INVALID_CREDENTIALS)}throw new Error(R.SDK_INIT_ERROR)}finally{I={...I,isLoading:!1,token:o}}}te={init:at,getSecurityResult:Te,getSecurityToken:Oe,isAIUsageDetected:ge,checkQualityQuestions:ve,getQualityQuestions:_e,QualityQuestionsRespondentTypes:q,LanguageCodes:x};var Or=te;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function de(e,n){return function(r,i){return Object.prototype.hasOwnProperty.call(r,i)}(e,n)?e[n]:void 0}function Oe(e,n,r,i){let o=document,E="securitypolicyviolation",a,l=u=>{let c=new URL(e,location.href),{blockedURI:t}=u;t!==c.href&&t!==c.protocol.slice(0,-1)&&t!==c.origin||(a=u,R())};o.addEventListener(E,l);let R=()=>o.removeEventListener(E,l);return i?.then(R,R),Promise.resolve().then(n).then(u=>(R(),u),u=>new Promise(c=>{let t=new MessageChannel;t.port1.onmessage=()=>c(),t.port2.postMessage(null)}).then(()=>{if(R(),a)return r(a);throw u}))}function f(e){let n="";for(let r=0;r<e.length;++r)if(r>0){let i=e[r].toLowerCase();i!==e[r]?n+=` ${i}`:n+=e[r]}else n+=e[r].toUpperCase();return n}var me={default:"endpoint"},Ae={default:"tlsEndpoint"},Ne="Client timeout",fe="Network connection error",he="Network request aborted",De="Response cannot be parsed",G="Blocked by CSP",B="The endpoint parameter is not a valid URL",we="Handle on demand agent data error",ye=f("WrongRegion"),pe=f("SubscriptionNotActive"),Pe=f("UnsupportedVersion"),ve=f("InstallationMethodRestricted"),ge=f("HostnameRestricted"),ke=f("IntegrationFailed"),Le=f("NetworkRestricted"),be=f("InvalidProxyIntegrationSecret"),Ue=f("InvalidProxyIntegrationHeaders"),Me=f("ProxyIntegrationSecretEnvironmentMismatch"),K="API key required",X="API key not found",$="API key expired",Se="Request cannot be parsed",xe="Request failed",Ge="Request failed to process",Be="Too many requests, rate limit exceeded",Ke="Not available for this origin",Fe="Not available with restricted header",Ve=K,qe=X,je=$,Ye="3.12.0",g="Failed to load the JS script of the agent",F="9319";function Xe(e,n){let r=[],[i,o]=function(l){let R=function(t){let d=[...t];return{current:()=>d[0],postpone(){let O=d.shift();O!==void 0&&d.push(O)},exclude(){d.shift()}}}(l),u=function(t,d){let O=0;return()=>Math.random()*Math.min(d,t*Math.pow(2,O++))}(100,3e3),c=new Set;return[R.current(),(t,d)=>{let O,A=d instanceof Error?d.message:"";if(A===G||A===B)R.exclude(),O=0;else if(A===F)R.exclude();else if(A===g){let h=Date.now()-t.getTime()<50,I=R.current();I&&h&&!c.has(I)&&(c.add(I),O=0),R.postpone()}else R.postpone();let N=R.current();return N===void 0?void 0:[N,O??t.getTime()+u()-Date.now()]}]}(e),E;if(i===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));let a=l=>{let R=new Date,u=t=>r.push({url:l,startedAt:R,finishedAt:new Date,error:t}),c=n(l);return c.then(()=>u(),u),c.catch(t=>{if(E!=null||(E=t),r.length>=5)throw E;let d=o(R,t);if(!d)throw E;let[O,A]=d;return(N=A,new Promise(h=>setTimeout(h,N))).then(()=>a(O));var N})};return a(i).then(l=>[l,r])}var W="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",$e=W;function We(e){var n,r;let{picked:i,rest:o}=function(c,t){let d={},O={};for(let[A,N]of Object.entries(c))t.includes(A)?d[A]=N:O[A]=N;return{picked:d,rest:O}}(e,["scriptUrlPattern","token","apiKey"]),E=i.token,a=(n=i.apiKey)!==null&&n!==void 0?n:E,l=(r=de(e,"scriptUrlPattern"))!==null&&r!==void 0?r:W,[R,u]=function(){let c=[],t=()=>{c.push({time:new Date,state:document.visibilityState})},d=function(O,A,N,h){return O.addEventListener(A,N,h),()=>O.removeEventListener(A,N,h)}(document,"visibilitychange",t);return t(),[c,d]}();return Promise.resolve().then(()=>{if(!a||typeof a!="string")throw new Error(K);let c=function(t,d){return(Array.isArray(t)?t:[t]).map(O=>function(A,N){let h=encodeURIComponent;return A.replace(/<[^<>]+>/g,I=>I==="<version>"?"3":I==="<apiKey>"?h(N):I==="<loaderVersion>"?h(Ye):I)}(String(O),d))}(l,a);return Xe(c,Ze)}).catch(c=>{throw u(),function(t){return t instanceof Error&&t.message===F?new Error(g):t}(c)}).then(([c,t])=>(u(),c.load({...o,ldi:{attempts:t,visibilityStates:R}})))}function Ze(e){return Oe(e,()=>function(n){return new Promise((r,i)=>{if(function(l){if(URL.prototype)try{return new URL(l,location.href),!1}catch(R){if(R instanceof Error&&R.name==="TypeError")return!0;throw R}}(n))throw new Error(B);let o=document.createElement("script"),E=()=>{var l;return(l=o.parentNode)===null||l===void 0?void 0:l.removeChild(o)},a=document.head||document.getElementsByTagName("head")[0];o.onload=()=>{E(),r()},o.onerror=()=>{E(),i(new Error(g))},o.async=!0,o.src=n,a.appendChild(o)})}(e),()=>{throw new Error(G)}).then(ze)}function ze(){let e=window,n="__fpjs_p_l_b",r=e[n];if(function(i,o){var E;let a=(E=Object.getOwnPropertyDescriptor)===null||E===void 0?void 0:E.call(Object,i,o);a?.configurable?delete i[o]:a&&!a.writable||(i[o]=void 0)}(e,n),typeof r?.load!="function")throw new Error(F);return r}var y={load:We,defaultScriptUrlPattern:$e,ERROR_SCRIPT_LOAD_FAIL:g,ERROR_API_KEY_EXPIRED:$,ERROR_API_KEY_INVALID:X,ERROR_API_KEY_MISSING:K,ERROR_BAD_REQUEST_FORMAT:Se,ERROR_BAD_RESPONSE_FORMAT:De,ERROR_CLIENT_TIMEOUT:Ne,ERROR_CSP_BLOCK:G,ERROR_FORBIDDEN_ENDPOINT:ge,ERROR_FORBIDDEN_HEADER:Fe,ERROR_FORBIDDEN_ORIGIN:Ke,ERROR_GENERAL_SERVER_FAILURE:xe,ERROR_HANDLE_AGENT_DATA:we,ERROR_INSTALLATION_METHOD_RESTRICTED:ve,ERROR_INTEGRATION_FAILURE:ke,ERROR_INVALID_ENDPOINT:B,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:Ue,ERROR_INVALID_PROXY_INTEGRATION_SECRET:be,ERROR_NETWORK_ABORT:he,ERROR_NETWORK_CONNECTION:fe,ERROR_NETWORK_RESTRICTED:Le,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:Me,ERROR_RATE_LIMIT:Be,ERROR_SERVER_TIMEOUT:Ge,ERROR_SUBSCRIPTION_NOT_ACTIVE:pe,ERROR_TOKEN_EXPIRED:je,ERROR_TOKEN_INVALID:qe,ERROR_TOKEN_MISSING:Ve,ERROR_UNSUPPORTED_VERSION:Pe,ERROR_WRONG_REGION:ye,defaultEndpoint:me,defaultTlsEndpoint:Ae};var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function Z(e,n=0){return(m[e[n+0]]+m[e[n+1]]+m[e[n+2]]+m[e[n+3]]+"-"+m[e[n+4]]+m[e[n+5]]+"-"+m[e[n+6]]+m[e[n+7]]+"-"+m[e[n+8]]+m[e[n+9]]+"-"+m[e[n+10]]+m[e[n+11]]+m[e[n+12]]+m[e[n+13]]+m[e[n+14]]+m[e[n+15]]).toLowerCase()}var V,Je=new Uint8Array(16);function q(){if(!V){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");V=crypto.getRandomValues.bind(crypto)}return V(Je)}var Qe=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),j={randomUUID:Qe};function Ce(e,n,r){if(j.randomUUID&&!n&&!e)return j.randomUUID();e=e||{};let i=e.random??e.rng?.()??q();if(i.length<16)throw new Error("Random bytes length must be >= 16");if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,n){if(r=r||0,r<0||r+16>n.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let o=0;o<16;++o)n[r+o]=i[o];return n}return Z(i)}var k=Ce;var He={UNAUTHORIZED:"Unauthorized"},en={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},z={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key",MAINTENANCE_MODE:"API Under Maintenance",RATE_LIMIT_REACHED:"Too many requests. Rate limit exceeded"},J={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},Q={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},C={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},H={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},s={...He,...en,...z,...J,...Q,...C,...H},ee={...z,...J,...Q,...C,...H};var L=(I=>(I.AR="ar",I.BN="bn",I.DE="de",I.EN="en",I.ES="es",I.FR="fr",I.HI="hi",I.ID="id",I.IT="it",I.JA="ja",I.KO="ko",I.MS="ms",I.NL="nl",I.PT="pt",I.RU="ru",I.YU="yu",I.ZH="zh",I))(L||{}),b=(_=>(_.GeneralConsumer="general-consumer",_.HRManagerDirector="hr-manager-director",_.WebDeveloper="web-developer",_.SoftwareEngineer="software-engineer",_.ITDirector="it-director",_.BusinessAdministrator="business-administrator",_.AccountsPayableManager="accounts-payable-manager",_.Accountant="accountant",_.FinanceDirector="finance-director",_.SmallBusinessOwner="small-business-owner",_.GeneralContractor="general-contractor",_.MarketingManagerDirector="marketing-manager-director",_.ConsumerShopper="consumer-shopper",_.Travel="travel",_.Entertainment="entertainment",_.FinanceAndBanking="finance-and-banking",_.General="general",_.B2BWhiteCollar="b2b-white-collar",_.B2BBlueCollar="b2b-blue-collar",_.Lawyer="lawyer",_))(b||{});var nn=(e,n={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...n}),rn=async(e,n)=>{if(!e.ok){let r=await e.text();throw new Error(r)}return n==="file"?e.blob():n==="json"?e.json():n==="text"?e.text():null},ne=async({url:e,auth:n,body:r,method:i="GET",headers:o={},responseType:E="json"})=>{let a={method:i,headers:nn(n,o),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},l=await fetch(e,a);return rn(l,E)},re=e=>ne({...e,method:"GET"}),U=e=>ne({...e,method:"POST"});function ie(){let e=!1,n=!1,r=!1,i=null,o=0,E=()=>{e=!1,n=!1,r=!1,i=void 0,o=0},a=()=>{let c=window?.getSelection()?.toString();c&&c.length>0&&(o=Date.now(),e=!0)},l=u=>{let c=u.clipboardData?.getData("text"),t=u.target instanceof HTMLInputElement||u.target instanceof HTMLTextAreaElement;c&&t&&(r=!0)},R=()=>{n=!0;let u=Date.now();if(o){let c=(u-o)/1e3;(i===void 0||c<i)&&(i=c)}};return document?.addEventListener("copy",a),document?.addEventListener("paste",l),window?.addEventListener("blur",R),{get qbc(){return e},get mas(){return n},get apd(){return r},get scb(){return i},reset:E,destroy(){document?.removeEventListener("copy",a),document?.removeEventListener("paste",l),window?.removeEventListener("blur",R)}}}var M,D="https://api.dtect.io/security",S=`${D}/client/check`,w="",P="",te="0.0.15",ae="7166bf18-b91e-407a-84fc-d57ac104de98",ce,oe,on="20000000-aaaa-bbbb-cccc-000000000002",x,T={isLoading:!1,token:"",visitorId:"",projectId:"",questionData:null,clientData:null,aiCheckData:null,tokens:null};var tn=ee,v;function Y(e){if(e instanceof Error){if(e?.message?.includes("maintenance_mode"))throw new Error(s.MAINTENANCE_MODE);if(e?.message?.includes("rate-limited"))throw new Error(s.RATE_LIMIT_REACHED);switch(e?.message){case y.ERROR_RATE_LIMIT:throw new Error(s.RATE_LIMIT_REACHED);default:throw new Error(s.INTERNAL_SERVER_ERROR)}}throw new Error(s.FAILED_TO_GET_SECURITY_TOKEN)}function p(){let e=window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"),n=document.querySelector("#dtect-h-captcha");return!!(M&&(n||e))}function se(){return!!(w&&P)}function an(){return new Promise(e=>{let n=()=>{window?.hcaptcha?e():requestAnimationFrame(n)};n()})}var Ee=()=>window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///");async function cn({behaviorKey:e}){if(M=await y.load({apiKey:e,endpoint:["https://fp.dtect.io",y.defaultEndpoint],scriptUrlPattern:["https://fp.dtect.io/web/v<version>/<apiKey>/loader_v<loaderVersion>.js",y.defaultScriptUrlPattern]}),Ee()||(await an(),await window.hcaptcha.render("dtect-h-captcha",{sitekey:ae,size:"invisible"})),!M)throw new Error(s.SDK_INIT_ERROR)}async function sn(){if(T.tokens)return T.tokens;let e=new Promise(o=>{let E=M?.get();o(E)}),n=new Promise(async o=>{Ee()&&o({response:on}),await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:ae,size:"invisible"});let a=await window?.hcaptcha?.execute({async:!0});o(a)}),[r,i]=await Promise.all([n,e]);return T.tokens={behaviorRequestId:i?.requestId,behaviorToken:i?.sealedResult,automationToken:r?.response},T.tokens}async function Re(e,n){if(!p())throw new Error(s.NOT_INITIALIZED);if(!se())throw new Error(s.MISSING_CREDENTIALS);let{projectId:r,visitorId:i}=En(e);if(!e||!r?.trim())throw new Error(s.FAILED_TO_GET_SECURITY_RESULT);try{let o=await sn();if(o?.behaviorToken&&o?.behaviorRequestId&&o?.automationToken){let E={behaviorToken:o.behaviorToken,automationToken:o.automationToken,behaviorRequestId:o.behaviorRequestId,entryLink:window?.location?.href,securitySettings:e.securitySettings,metaData:e.metaData};T.clientData=E;let a={...e,projectId:r?.trim(),visitorId:i?.trim()||k(),clientData:E,version:"0.0.15",token:T.token,questionData:T.questionData,aiCheckData:T.aiCheckData};oe=performance.now();let l=(oe-ce).toFixed(),R=await U({url:`${n}?clientId=${w}&diff=${l}`,body:{...a},headers:{"client-id":w,"x-api-key":P}});if("token"in R||"results"in R)return R}throw new Error(s.INTERNAL_SERVER_ERROR)}catch(o){if(o instanceof Error){if(o?.message?.includes("maintenance_mode"))throw new Error(s.MAINTENANCE_MODE);if(o?.message?.includes("rate-limited")||o?.message?.includes("429"))throw new Error(s.RATE_LIMIT_REACHED);switch(o?.message){case y.ERROR_RATE_LIMIT:throw new Error(s.RATE_LIMIT_REACHED);default:throw new Error(s.INTERNAL_SERVER_ERROR)}}throw new Error(s.FAILED_TO_GET_SECURITY_RESULT)}}async function Ie(e){return await Re(e,`${D}/client/check/result`)}async function le(e){return await Re(e,`${D}/client/check`)}function En(e){let n=e?.projectId,r=e?.visitorId;return(typeof e?.projectId=="number"||typeof e?.visitorId=="number")&&(n=`${e?.projectId}`,r=`${e?.visitorId}`),{visitorId:r,projectId:n}}async function Te(e){if(!p())throw new Error(s.NOT_INITIALIZED);let{respondentType:n,language:r}=e;try{let i=await re({url:`${D}/client/quality-questions/${n}/${r}`,headers:{"client-id":w,"x-api-key":P}});if(i)return i;throw new Error(s.INTERNAL_SERVER_ERROR)}catch(i){Y(i)}}async function ue(e){if(!p())throw new Error(s.NOT_INITIALIZED);T.questionData={questions:e.questions};try{let n=await U({url:S,headers:{"client-id":w,"x-api-key":P},body:{token:T.token,visitorId:e.visitorId,projectId:e.projectId,version:te,questionData:T.questionData,aiCheckData:T.aiCheckData,clientData:T.clientData}});if(n)return n;throw new Error(s.INTERNAL_SERVER_ERROR)}catch(n){Y(n)}}async function _e(e){if(!p())throw new Error(s.NOT_INITIALIZED);T.aiCheckData={timeTakenSeconds:e.timeTakenSeconds,qbc:e.qbc||v.qbc,mas:e.mas||v.mas,scb:e.scb||v.scb,apd:e.apd||v.apd};try{let n=await U({url:S,headers:{"client-id":w,"x-api-key":P},body:{token:T.token,visitorId:e.visitorId,projectId:e.projectId,version:te,clientData:T.clientData,questionData:T.questionData,aiCheckData:T.aiCheckData}});if(n)return n;throw new Error(s.INTERNAL_SERVER_ERROR)}catch(n){Y(n)}}async function Rn(){return k()}function In(){let e=document.querySelector("head"),n=document.querySelector("body");if(!(window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"))){n?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let i=document.createElement("script");i.setAttribute("src","https://js.hcaptcha.com/1/api.js"),i.setAttribute("async","true"),i.setAttribute("defer","true"),e?.append(i)}}async function ln(e){if(!e?.clientId||!e?.apiKey)throw new Error(s.MISSING_CREDENTIALS);ce=performance.now();let{clientId:n,apiKey:r,endpoint:i="https://api.dtect.io/security",includeResults:o}=e;D=i,S=`${D}/client/check`;let E=await Rn();if(T.isLoading){if(p())return x;throw new Error(s.DUPLICATE_INITIALIZATION)}if(v=ie(),w=n,P=r,o&&(S=`${D}/client/check/result`),T={...T,isLoading:!0,token:E||""},!se())throw new Error(s.MISSING_CREDENTIALS);if(p())return x;In();try{return cn({behaviorKey:"bwDZ0V3Zrb4SB6g4lZwW"}).then(()=>({getSecurityResult:Ie,getSecurityToken:le,SecurityAPIError:tn,isAIUsageDetected:_e,checkQualityQuestions:ue,getQualityQuestions:Te,LanguageCodes:L,QualityQuestionsRespondentTypes:b})).catch(a=>{throw new Error(a.message)})}catch(a){if(a instanceof Error){if(a?.message?.includes("maintenance_mode"))throw new Error(s.MAINTENANCE_MODE);if([s.INVALID_API_KEY,s.UNAUTHORIZED].includes(a?.message))throw new Error(s.INVALID_CREDENTIALS)}throw new Error(s.SDK_INIT_ERROR)}finally{T={...T,isLoading:!1,token:E}}}x={init:ln,getSecurityResult:Ie,getSecurityToken:le,isAIUsageDetected:_e,checkQualityQuestions:ue,getQualityQuestions:Te,QualityQuestionsRespondentTypes:b,LanguageCodes:L};var tr=x;export{L as LanguageCodes,b as QualityQuestionsRespondentTypes,tn as SecurityAPIError,ue as checkQualityQuestions,tr as default,Te as getQualityQuestions,Ie as getSecurityResult,le as getSecurityToken,ln as init,_e as isAIUsageDetected};
|
|
1
|
+
function ot(e,t){return function(r,n){return Object.prototype.hasOwnProperty.call(r,n)}(e,t)?e[t]:void 0}function at(e,t,r,n){let i=document,o="securitypolicyviolation",c,s=d=>{let u=new URL(e,location.href),{blockedURI:l}=d;l!==u.href&&l!==u.protocol.slice(0,-1)&&l!==u.origin||(c=d,a())};i.addEventListener(o,s);let a=()=>i.removeEventListener(o,s);return n?.then(a,a),Promise.resolve().then(t).then(d=>(a(),d),d=>new Promise(u=>{let l=new MessageChannel;l.port1.onmessage=()=>u(),l.port2.postMessage(null)}).then(()=>{if(a(),c)return r(c);throw d}))}function g(e){let t="";for(let r=0;r<e.length;++r)if(r>0){let n=e[r].toLowerCase();n!==e[r]?t+=` ${n}`:t+=e[r]}else t+=e[r].toUpperCase();return t}var ct={default:"endpoint"},ut={default:"tlsEndpoint"},lt="Client timeout",ht="Network connection error",ft="Network request aborted",dt="Response cannot be parsed",ne="Blocked by CSP",ie="The endpoint parameter is not a valid URL",Et="Handle on demand agent data error",Rt=g("WrongRegion"),mt=g("SubscriptionNotActive"),pt=g("UnsupportedVersion"),yt=g("InstallationMethodRestricted"),It=g("HostnameRestricted"),Tt=g("IntegrationFailed"),Ot=g("NetworkRestricted"),_t=g("InvalidProxyIntegrationSecret"),vt=g("InvalidProxyIntegrationHeaders"),gt=g("ProxyIntegrationSecretEnvironmentMismatch"),se="API key required",Ie="API key not found",Te="API key expired",At="Request cannot be parsed",wt="Request failed",Dt="Request failed to process",Nt="Too many requests, rate limit exceeded",bt="Not available for this origin",Pt="Not available with restricted header",St=se,kt=Ie,Mt=Te,Lt="3.12.0",j="Failed to load the JS script of the agent",oe="9319";function Ut(e,t){let r=[],[n,i]=function(s){let a=function(l){let m=[...l];return{current:()=>m[0],postpone(){let p=m.shift();p!==void 0&&m.push(p)},exclude(){m.shift()}}}(s),d=function(l,m){let p=0;return()=>Math.random()*Math.min(m,l*Math.pow(2,p++))}(100,3e3),u=new Set;return[a.current(),(l,m)=>{let p,E=m instanceof Error?m.message:"";if(E===ne||E===ie)a.exclude(),p=0;else if(E===oe)a.exclude();else if(E===j){let O=Date.now()-l.getTime()<50,h=a.current();h&&O&&!u.has(h)&&(u.add(h),p=0),a.postpone()}else a.postpone();let f=a.current();return f===void 0?void 0:[f,p??l.getTime()+d()-Date.now()]}]}(e),o;if(n===void 0)return Promise.reject(new TypeError("The list of script URL patterns is empty"));let c=s=>{let a=new Date,d=l=>r.push({url:s,startedAt:a,finishedAt:new Date,error:l}),u=t(s);return u.then(()=>d(),d),u.catch(l=>{if(o!=null||(o=l),r.length>=5)throw o;let m=i(a,l);if(!m)throw o;let[p,E]=m;return(f=E,new Promise(O=>setTimeout(O,f))).then(()=>c(p));var f})};return c(n).then(s=>[s,r])}var Oe="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Ft=Oe;function xt(e){var t,r;let{picked:n,rest:i}=function(u,l){let m={},p={};for(let[E,f]of Object.entries(u))l.includes(E)?m[E]=f:p[E]=f;return{picked:m,rest:p}}(e,["scriptUrlPattern","token","apiKey"]),o=n.token,c=(t=n.apiKey)!==null&&t!==void 0?t:o,s=(r=ot(e,"scriptUrlPattern"))!==null&&r!==void 0?r:Oe,[a,d]=function(){let u=[],l=()=>{u.push({time:new Date,state:document.visibilityState})},m=function(p,E,f,O){return p.addEventListener(E,f,O),()=>p.removeEventListener(E,f,O)}(document,"visibilitychange",l);return l(),[u,m]}();return Promise.resolve().then(()=>{if(!c||typeof c!="string")throw new Error(se);let u=function(l,m){return(Array.isArray(l)?l:[l]).map(p=>function(E,f){let O=encodeURIComponent;return E.replace(/<[^<>]+>/g,h=>h==="<version>"?"3":h==="<apiKey>"?O(f):h==="<loaderVersion>"?O(Lt):h)}(String(p),m))}(s,c);return Ut(u,qt)}).catch(u=>{throw d(),function(l){return l instanceof Error&&l.message===oe?new Error(j):l}(u)}).then(([u,l])=>(d(),u.load({...i,ldi:{attempts:l,visibilityStates:a}})))}function qt(e){return at(e,()=>function(t){return new Promise((r,n)=>{if(function(s){if(URL.prototype)try{return new URL(s,location.href),!1}catch(a){if(a instanceof Error&&a.name==="TypeError")return!0;throw a}}(t))throw new Error(ie);let i=document.createElement("script"),o=()=>{var s;return(s=i.parentNode)===null||s===void 0?void 0:s.removeChild(i)},c=document.head||document.getElementsByTagName("head")[0];i.onload=()=>{o(),r()},i.onerror=()=>{o(),n(new Error(j))},i.async=!0,i.src=t,c.appendChild(i)})}(e),()=>{throw new Error(ne)}).then(Kt)}function Kt(){let e=window,t="__fpjs_p_l_b",r=e[t];if(function(n,i){var o;let c=(o=Object.getOwnPropertyDescriptor)===null||o===void 0?void 0:o.call(Object,n,i);c?.configurable?delete n[i]:c&&!c.writable||(n[i]=void 0)}(e,t),typeof r?.load!="function")throw new Error(oe);return r}var k={load:xt,defaultScriptUrlPattern:Ft,ERROR_SCRIPT_LOAD_FAIL:j,ERROR_API_KEY_EXPIRED:Te,ERROR_API_KEY_INVALID:Ie,ERROR_API_KEY_MISSING:se,ERROR_BAD_REQUEST_FORMAT:At,ERROR_BAD_RESPONSE_FORMAT:dt,ERROR_CLIENT_TIMEOUT:lt,ERROR_CSP_BLOCK:ne,ERROR_FORBIDDEN_ENDPOINT:It,ERROR_FORBIDDEN_HEADER:Pt,ERROR_FORBIDDEN_ORIGIN:bt,ERROR_GENERAL_SERVER_FAILURE:wt,ERROR_HANDLE_AGENT_DATA:Et,ERROR_INSTALLATION_METHOD_RESTRICTED:yt,ERROR_INTEGRATION_FAILURE:Tt,ERROR_INVALID_ENDPOINT:ie,ERROR_INVALID_PROXY_INTEGRATION_HEADERS:vt,ERROR_INVALID_PROXY_INTEGRATION_SECRET:_t,ERROR_NETWORK_ABORT:ft,ERROR_NETWORK_CONNECTION:ht,ERROR_NETWORK_RESTRICTED:Ot,ERROR_PROXY_INTEGRATION_SECRET_ENVIRONMENT_MISMATCH:gt,ERROR_RATE_LIMIT:Nt,ERROR_SERVER_TIMEOUT:Dt,ERROR_SUBSCRIPTION_NOT_ACTIVE:mt,ERROR_TOKEN_EXPIRED:Mt,ERROR_TOKEN_INVALID:kt,ERROR_TOKEN_MISSING:St,ERROR_UNSUPPORTED_VERSION:pt,ERROR_WRONG_REGION:Rt,defaultEndpoint:ct,defaultTlsEndpoint:ut};var _=[];for(let e=0;e<256;++e)_.push((e+256).toString(16).slice(1));function _e(e,t=0){return(_[e[t+0]]+_[e[t+1]]+_[e[t+2]]+_[e[t+3]]+"-"+_[e[t+4]]+_[e[t+5]]+"-"+_[e[t+6]]+_[e[t+7]]+"-"+_[e[t+8]]+_[e[t+9]]+"-"+_[e[t+10]]+_[e[t+11]]+_[e[t+12]]+_[e[t+13]]+_[e[t+14]]+_[e[t+15]]).toLowerCase()}var ae,Gt=new Uint8Array(16);function ce(){if(!ae){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ae=crypto.getRandomValues.bind(crypto)}return ae(Gt)}var Bt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ue={randomUUID:Bt};function jt(e,t,r){if(ue.randomUUID&&!t&&!e)return ue.randomUUID();e=e||{};let n=e.random??e.rng?.()??ce();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 C=jt;var Ct={UNAUTHORIZED:"Unauthorized"},Vt={EXPIRED:"EXPIRED_TOKEN",INVALID_API_KEY:"INVALID_API_KEY",MISSING_AUTHENTICATION_TOKEN:"MISSING_AUTHENTICATION_TOKEN"},ve={INTERNAL_SERVER_ERROR:"Internal Server Error during API Request",MISSING_CREDENTIALS:"Missing Public Client ID or Public API Key",MAINTENANCE_MODE:"API Under Maintenance",RATE_LIMIT_REACHED:"Too many requests. Rate limit exceeded"},ge={SDK_INIT_ERROR:"Internal Server Error during SDK Initialization",DUPLICATE_INITIALIZATION:"Multiple SDK Initializations Detected",NOT_INITIALIZED:"SDK Not Initialized"},Ae={INVALID_CREDENTIALS:"Invalid Public Client ID or Public API Key"},we={FAILED_TO_GET_SECURITY_RESULT:"Failed to Retrieve Security Result"},De={FAILED_TO_GET_SECURITY_TOKEN:" Failed to Generate Security Token"},R={...Ct,...Vt,...ve,...ge,...Ae,...we,...De},Ne={...ve,...ge,...Ae,...we,...De};var V=(h=>(h.AR="ar",h.BN="bn",h.DE="de",h.EN="en",h.ES="es",h.FR="fr",h.HI="hi",h.ID="id",h.IT="it",h.JA="ja",h.KO="ko",h.MS="ms",h.NL="nl",h.PT="pt",h.RU="ru",h.YU="yu",h.ZH="zh",h))(V||{}),Q=(y=>(y.GeneralConsumer="general-consumer",y.HRManagerDirector="hr-manager-director",y.WebDeveloper="web-developer",y.SoftwareEngineer="software-engineer",y.ITDirector="it-director",y.BusinessAdministrator="business-administrator",y.AccountsPayableManager="accounts-payable-manager",y.Accountant="accountant",y.FinanceDirector="finance-director",y.SmallBusinessOwner="small-business-owner",y.GeneralContractor="general-contractor",y.MarketingManagerDirector="marketing-manager-director",y.ConsumerShopper="consumer-shopper",y.Travel="travel",y.Entertainment="entertainment",y.FinanceAndBanking="finance-and-banking",y.General="general",y.B2BWhiteCollar="b2b-white-collar",y.B2BBlueCollar="b2b-blue-collar",y.Lawyer="lawyer",y))(Q||{});var Qt=(e,t={})=>({"Content-Type":"application/json",...e?.accessToken&&{Authorization:`Bearer ${e?.accessToken}`},...t}),Yt=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},be=async({url:e,auth:t,body:r,method:n="GET",headers:i={},responseType:o="json"})=>{let c={method:n,headers:Qt(t,i),...r?{body:r instanceof FormData?r:JSON.stringify(r)}:{}},s=await fetch(e,c);return Yt(s,o)},le=e=>be({...e,method:"GET"}),Y=e=>be({...e,method:"POST"});function Pe(){let e=!1,t=!1,r=!1,n=null,i=0,o=()=>{e=!1,t=!1,r=!1,n=void 0,i=0},c=()=>{let u=window?.getSelection()?.toString();u&&u.length>0&&(i=Date.now(),e=!0)},s=d=>{let u=d.clipboardData?.getData("text"),l=d.target instanceof HTMLInputElement||d.target instanceof HTMLTextAreaElement;u&&l&&(r=!0)},a=()=>{t=!0;let d=Date.now();if(i){let u=(d-i)/1e3;(n===void 0||u<n)&&(n=u)}};return document?.addEventListener("copy",c),document?.addEventListener("paste",s),window?.addEventListener("blur",a),{get qbc(){return e},get mas(){return t},get apd(){return r},get scb(){return n},reset:o,destroy(){document?.removeEventListener("copy",c),document?.removeEventListener("paste",s),window?.removeEventListener("blur",a)}}}var A=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var w=typeof window>"u"||"Deno"in globalThis;function v(){}function Me(e,t){return typeof e=="function"?e(t):e}function Le(e){return typeof e=="number"&&e>=0&&e!==1/0}function Ue(e,t){return Math.max(e+(t||0)-Date.now(),0)}function fe(e,t){return typeof e=="function"?e(t):e}function Fe(e,t){return typeof e=="function"?e(t):e}function de(e,t){let{type:r="all",exact:n,fetchStatus:i,predicate:o,queryKey:c,stale:s}=e;if(c){if(n){if(t.queryHash!==x(c,t.options))return!1}else if(!L(t.queryKey,c))return!1}if(r!=="all"){let a=t.isActive();if(r==="active"&&!a||r==="inactive"&&a)return!1}return!(typeof s=="boolean"&&t.isStale()!==s||i&&i!==t.state.fetchStatus||o&&!o(t))}function Ee(e,t){let{exact:r,status:n,predicate:i,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(r){if(M(t.options.mutationKey)!==M(o))return!1}else if(!L(t.options.mutationKey,o))return!1}return!(n&&t.state.status!==n||i&&!i(t))}function x(e,t){return(t?.queryKeyHashFn||M)(e)}function M(e){return JSON.stringify(e,(t,r)=>he(r)?Object.keys(r).sort().reduce((n,i)=>(n[i]=r[i],n),{}):r)}function L(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!L(e[r],t[r])):!1}function xe(e,t){if(e===t)return e;let r=Se(e)&&Se(t);if(r||he(e)&&he(t)){let n=r?e:Object.keys(e),i=n.length,o=r?t:Object.keys(t),c=o.length,s=r?[]:{},a=0;for(let d=0;d<c;d++){let u=r?d:o[d];(!r&&n.includes(u)||r)&&e[u]===void 0&&t[u]===void 0?(s[u]=void 0,a++):(s[u]=xe(e[u],t[u]),s[u]===e[u]&&e[u]!==void 0&&a++)}return i===c&&a===i?e:s}return t}function Se(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function he(e){if(!ke(e))return!1;let t=e.constructor;if(t===void 0)return!0;let r=t.prototype;return!(!ke(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function ke(e){return Object.prototype.toString.call(e)==="[object Object]"}function qe(e){return new Promise(t=>{setTimeout(t,e)})}function Ke(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?xe(e,t):t}function Ge(e,t,r=0){let n=[...e,t];return r&&n.length>r?n.slice(1):n}function Be(e,t,r=0){let n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var q=Symbol();function $(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===q?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}var $t=class extends A{#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"}},X=new $t;var Xt=class extends A{#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}},U=new Xt;function je(){let e,t,r=new Promise((i,o)=>{e=i,t=o});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 Wt(e){return Math.min(1e3*2**e,3e4)}function Re(e){return(e??"online")==="online"?U.isOnline():!0}var Ce=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function W(e){return e instanceof Ce}function z(e){let t=!1,r=0,n=!1,i,o=je(),c=f=>{n||(m(new Ce(f)),e.abort?.())},s=()=>{t=!0},a=()=>{t=!1},d=()=>X.isFocused()&&(e.networkMode==="always"||U.isOnline())&&e.canRun(),u=()=>Re(e.networkMode)&&e.canRun(),l=f=>{n||(n=!0,e.onSuccess?.(f),i?.(),o.resolve(f))},m=f=>{n||(n=!0,e.onError?.(f),i?.(),o.reject(f))},p=()=>new Promise(f=>{i=O=>{(n||d())&&f(O)},e.onPause?.()}).then(()=>{i=void 0,n||e.onContinue?.()}),E=()=>{if(n)return;let f,O=r===0?e.initialPromise:void 0;try{f=O??e.fn()}catch(h){f=Promise.reject(h)}Promise.resolve(f).then(l).catch(h=>{if(n)return;let N=e.retry??(w?0:3),S=e.retryDelay??Wt,y=typeof S=="function"?S(r,h):S,st=N===!0||typeof N=="number"&&r<N||typeof N=="function"&&N(r,h);if(t||!st){m(h);return}r++,e.onFail?.(r,h),qe(y).then(()=>d()?void 0:p()).then(()=>{t?m(h):E()})})};return{promise:o,cancel:c,continue:()=>(i?.(),o),cancelRetry:s,continueRetry:a,canStart:u,start:()=>(u()?E():p().then(E),o)}}function zt(){let e=[],t=0,r=s=>{s()},n=s=>{s()},i=s=>setTimeout(s,0),o=s=>{t?e.push(s):i(()=>{r(s)})},c=()=>{let s=e;e=[],s.length&&i(()=>{n(()=>{s.forEach(a=>{r(a)})})})};return{batch:s=>{let a;t++;try{a=s()}finally{t--,t||c()}return a},batchCalls:s=>(...a)=>{o(()=>{s(...a)})},schedule:o,setNotifyFunction:s=>{r=s},setBatchNotifyFunction:s=>{n=s},setScheduler:s=>{i=s}}}var T=zt();var J=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Le(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 Ve=class extends J{#e;#t;#r;#n;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#r=e.cache,this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=Zt(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.#o,...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let r=Ke(this.state.data,e,this.options);return this.#i({data:r,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),r}setState(e,t){this.#i({type:"setState",state:e,setStateOptions:t})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(v).catch(v):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#e)}isActive(){return this.observers.some(e=>Fe(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===q||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||!Ue(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.#s?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 s=this.observers.find(a=>a.options.queryFn);s&&this.setOptions(s.options)}let r=new AbortController,n=s=>{Object.defineProperty(s,"signal",{enumerable:!0,get:()=>(this.#s=!0,r.signal)})},i=()=>{let s=$(this.options,t),a={queryKey:this.queryKey,meta:this.meta};return n(a),this.#s=!1,this.options.persister?this.options.persister(s,a,this):s(a)},o={fetchOptions:t,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};n(o),this.options.behavior?.onFetch(o,this),this.#t=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==o.fetchOptions?.meta)&&this.#i({type:"fetch",meta:o.fetchOptions?.meta});let c=s=>{W(s)&&s.silent||this.#i({type:"error",error:s}),W(s)||(this.#r.config.onError?.(s,this),this.#r.config.onSettled?.(this.state.data,s,this)),this.scheduleGc()};return this.#n=z({initialPromise:t?.initialPromise,fn:o.fetchFn,abort:r.abort.bind(r),onSuccess:s=>{if(s===void 0){c(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(s)}catch(a){c(a);return}this.#r.config.onSuccess?.(s,this),this.#r.config.onSettled?.(s,this.state.error,this),this.scheduleGc()},onError:c,onFail:(s,a)=>{this.#i({type:"failed",failureCount:s,error:a})},onPause:()=>{this.#i({type:"pause"})},onContinue:()=>{this.#i({type:"continue"})},retry:o.options.retry,retryDelay:o.options.retryDelay,networkMode:o.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,...Jt(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 W(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),T.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Jt(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Re(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function Zt(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 K=class extends A{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),o=this.get(i);return o||(o=new Ve({cache:this,queryKey:n,queryHash:i,options:e.defaultQueryOptions(t),state:r,defaultOptions:e.getQueryDefaults(n)}),this.add(o)),o}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(){T.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=>de(t,r))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(r=>de(e,r)):t}notify(e){T.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){T.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){T.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var Qe=class extends J{#e;#t;#r;constructor(e){super(),this.mutationId=e.mutationId,this.#t=e.mutationCache,this.#e=[],this.state=e.state||Ht(),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=z({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),T.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(e)}),this.#t.notify({mutation:this,type:"updated",action:e})})}};function Ht(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var G=class extends A{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=Z(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=Z(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=Z(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=Z(e);return typeof t=="string"?this.#t.get(t)?.find(n=>n!==e&&n.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){T.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=>Ee(t,r))}findAll(e={}){return this.getAll().filter(t=>Ee(e,t))}notify(e){T.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return T.batch(()=>Promise.all(e.map(t=>t.continue().catch(v))))}};function Z(e){return e.options.scope?.id}function me(e){return{onFetch:(t,r)=>{let n=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,o=t.state.data?.pages||[],c=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},a=0,d=async()=>{let u=!1,l=E=>{Object.defineProperty(E,"signal",{enumerable:!0,get:()=>(t.signal.aborted?u=!0:t.signal.addEventListener("abort",()=>{u=!0}),t.signal)})},m=$(t.options,t.fetchOptions),p=async(E,f,O)=>{if(u)return Promise.reject();if(f==null&&E.pages.length)return Promise.resolve(E);let h={queryKey:t.queryKey,pageParam:f,direction:O?"backward":"forward",meta:t.options.meta};l(h);let N=await m(h),{maxPages:S}=t.options,y=O?Be:Ge;return{pages:y(E.pages,N,S),pageParams:y(E.pageParams,f,S)}};if(i&&o.length){let E=i==="backward",f=E?er:Ye,O={pages:o,pageParams:c},h=f(n,O);s=await p(O,h,E)}else{let E=e??o.length;do{let f=a===0?c[0]??n.initialPageParam:Ye(n,s);if(a>0&&f==null)break;s=await p(s,f),a++}while(a<E)}return s};t.options.persister?t.fetchFn=()=>t.options.persister?.(d,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r):t.fetchFn=d}}}function Ye(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 er(e,{pages:t,pageParams:r}){return t.length>0?e.getPreviousPageParam?.(t[0],t,r[0],r):void 0}var pe=class{#e;#t;#r;#n;#o;#s;#i;#a;constructor(e={}){this.#e=e.queryCache||new K,this.#t=e.mutationCache||new G,this.#r=e.defaultOptions||{},this.#n=new Map,this.#o=new Map,this.#s=0}mount(){this.#s++,this.#s===1&&(this.#i=X.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#a=U.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#s--,this.#s===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(fe(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}),o=this.#e.get(n.queryHash)?.state.data,c=Me(t,o);if(c!==void 0)return this.#e.build(this,n).setData(c,{...r,manual:!0})}setQueriesData(e,t,r){return T.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;T.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){let r=this.#e,n={type:"active",...e};return T.batch(()=>(r.findAll(e).forEach(i=>{i.reset()}),this.refetchQueries(n,t)))}cancelQueries(e,t={}){let r={revert:!0,...t},n=T.batch(()=>this.#e.findAll(e).map(i=>i.cancel(r)));return Promise.all(n).then(v).catch(v)}invalidateQueries(e,t={}){return T.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=T.batch(()=>this.#e.findAll(e).filter(i=>!i.isDisabled()).map(i=>{let o=i.fetch(void 0,r);return r.throwOnError||(o=o.catch(v)),i.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(n).then(v)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let r=this.#e.build(this,t);return r.isStaleByTime(fe(t.staleTime,r))?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(v).catch(v)}fetchInfiniteQuery(e){return e.behavior=me(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(v).catch(v)}ensureInfiniteQueryData(e){return e.behavior=me(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return U.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(M(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#n.values()],r={};return t.forEach(n=>{L(e,n.queryKey)&&Object.assign(r,n.defaultOptions)}),r}setMutationDefaults(e,t){this.#o.set(M(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#o.values()],r={};return t.forEach(n=>{L(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===q&&(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 tr=new pe({defaultOptions:{queries:{staleTime:3e4}},queryCache:new K({onError:(e,t)=>{}}),mutationCache:new G}),$e=tr;var H,b="https://api.dtect.io/security",ee=`${b}/client/check`,D="",P="",We="0.0.16",re,ze,Xe,rr="20000000-aaaa-bbbb-cccc-000000000002",te,I={isLoading:!1,token:"",visitorId:"",projectId:"",questionData:null,clientData:null,aiCheckData:null,tokens:null};var nr=Ne,B;async function ir({clientId:e,apiKey:t,endpoint:r}){return await $e.fetchQuery({queryKey:["getClientConfig",e,t],queryFn:()=>le({url:`${r}/client/config`,headers:{"client-id":D,"x-api-key":P}})})}function ye(e){if(e instanceof Error){if(e?.message?.includes("maintenance_mode"))throw new Error(R.MAINTENANCE_MODE);if(e?.message?.includes("rate-limited"))throw new Error(R.RATE_LIMIT_REACHED);switch(e?.message){case k.ERROR_RATE_LIMIT:throw new Error(R.RATE_LIMIT_REACHED);default:throw new Error(R.INTERNAL_SERVER_ERROR)}}throw new Error(R.FAILED_TO_GET_SECURITY_TOKEN)}function F(){let e=window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"),t=document.querySelector("#dtect-h-captcha");return!!(H&&(t||e))}function Je(){return!!(D&&P)}function sr(){return new Promise(e=>{let t=()=>{window?.hcaptcha?e():requestAnimationFrame(t)};t()})}var Ze=()=>window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///");async function or({behaviorKey:e}){if(H=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]}),Ze()||(await sr(),await window.hcaptcha.render("dtect-h-captcha",{sitekey:re,size:"invisible"})),!H)throw new Error(R.SDK_INIT_ERROR)}async function ar(){if(I.tokens)return I.tokens;let e=new Promise(i=>{let o=H?.get();i(o)}),t=new Promise(async i=>{Ze()&&i({response:rr}),await window?.hcaptcha?.render("dtect-h-captcha",{sitekey:re,size:"invisible"});let c=await window?.hcaptcha?.execute({async:!0});i(c)}),[r,n]=await Promise.all([t,e]);return I.tokens={behaviorRequestId:n?.requestId,behaviorToken:n?.sealedResult,automationToken:r?.response},I.tokens}async function He(e,t){if(!F())throw new Error(R.NOT_INITIALIZED);if(!Je())throw new Error(R.MISSING_CREDENTIALS);let{projectId:r,visitorId:n}=cr(e);if(!e||!r?.trim())throw new Error(R.FAILED_TO_GET_SECURITY_RESULT);try{let i=await ar();if(i?.behaviorToken&&i?.behaviorRequestId&&i?.automationToken){let o={behaviorToken:i.behaviorToken,automationToken:i.automationToken,behaviorRequestId:i.behaviorRequestId,entryLink:window?.location?.href,securitySettings:e.securitySettings,metaData:e.metaData};I.clientData=o;let c={...e,projectId:r?.trim(),visitorId:n?.trim()||C(),clientData:o,version:"0.0.16",token:I.token,questionData:I.questionData,aiCheckData:I.aiCheckData};Xe=performance.now();let s=(Xe-ze).toFixed(),a=await Y({url:`${t}?clientId=${D}&diff=${s}`,body:{...c},headers:{"client-id":D,"x-api-key":P}});if("token"in a||"results"in a)return a}throw new Error(R.INTERNAL_SERVER_ERROR)}catch(i){if(i instanceof Error){if(i?.message?.includes("maintenance_mode"))throw new Error(R.MAINTENANCE_MODE);if(i?.message?.includes("rate-limited")||i?.message?.includes("429"))throw new Error(R.RATE_LIMIT_REACHED);switch(i?.message){case k.ERROR_RATE_LIMIT:throw new Error(R.RATE_LIMIT_REACHED);default:throw new Error(R.INTERNAL_SERVER_ERROR)}}throw new Error(R.FAILED_TO_GET_SECURITY_RESULT)}}async function et(e){return await He(e,`${b}/client/check/result`)}async function tt(e){return await He(e,`${b}/client/check`)}function cr(e){let t=e?.projectId,r=e?.visitorId;return(typeof e?.projectId=="number"||typeof e?.visitorId=="number")&&(t=`${e?.projectId}`,r=`${e?.visitorId}`),{visitorId:r,projectId:t}}async function rt(e){if(!F())throw new Error(R.NOT_INITIALIZED);let{respondentType:t,language:r}=e;try{let n=await le({url:`${b}/client/quality-questions/${t}/${r}`,headers:{"client-id":D,"x-api-key":P}});if(n)return n;throw new Error(R.INTERNAL_SERVER_ERROR)}catch(n){ye(n)}}async function nt(e){if(!F())throw new Error(R.NOT_INITIALIZED);I.questionData={questions:e.questions};try{let t=await Y({url:ee,headers:{"client-id":D,"x-api-key":P},body:{token:I.token,visitorId:e.visitorId,projectId:e.projectId,version:We,questionData:I.questionData,aiCheckData:I.aiCheckData,clientData:I.clientData}});if(t)return t;throw new Error(R.INTERNAL_SERVER_ERROR)}catch(t){ye(t)}}async function it(e){if(!F())throw new Error(R.NOT_INITIALIZED);I.aiCheckData={timeTakenSeconds:e.timeTakenSeconds,qbc:e.qbc||B.qbc,mas:e.mas||B.mas,scb:e.scb||B.scb,apd:e.apd||B.apd};try{let t=await Y({url:ee,headers:{"client-id":D,"x-api-key":P},body:{token:I.token,visitorId:e.visitorId,projectId:e.projectId,version:We,clientData:I.clientData,questionData:I.questionData,aiCheckData:I.aiCheckData}});if(t)return t;throw new Error(R.INTERNAL_SERVER_ERROR)}catch(t){ye(t)}}async function ur(){return C()}function lr(){let e=document.querySelector("head"),t=document.querySelector("body");if(!(window?.location?.href?.includes("localhost")||window?.location?.href?.includes("file:///"))){t?.insertAdjacentHTML("beforeend",'<div id="dtect-h-captcha" ></div>');let n=document.createElement("script");n.setAttribute("src","https://js.hcaptcha.com/1/api.js"),n.setAttribute("async","true"),n.setAttribute("defer","true"),e?.append(n)}}function hr(){return!!re}function fr(e){return e?.automationKey&&e?.behaviorKey}async function dr(e){if(!e?.clientId||!e?.apiKey)throw new Error(R.MISSING_CREDENTIALS);ze=performance.now();let{clientId:t,apiKey:r,endpoint:n="https://api.dtect.io/security",includeResults:i}=e;b=n,ee=`${b}/client/check`;let o=await ur();if(I.isLoading){if(F())return te;throw new Error(R.DUPLICATE_INITIALIZATION)}if(B=Pe(),D=t,P=r,i&&(ee=`${b}/client/check/result`),I={...I,isLoading:!0,token:o||""},!Je())throw new Error(R.MISSING_CREDENTIALS);if(F())return te;lr();try{let c=await ir({clientId:t,apiKey:r,endpoint:n});if(!fr(c)||hr())throw new Error;return re=c.automationKey,or({behaviorKey:c.behaviorKey}).then(()=>({getSecurityResult:et,getSecurityToken:tt,SecurityAPIError:nr,isAIUsageDetected:it,checkQualityQuestions:nt,getQualityQuestions:rt,LanguageCodes:V,QualityQuestionsRespondentTypes:Q})).catch(s=>{throw new Error(s.message)})}catch(c){if(c instanceof Error){if(c?.message?.includes("maintenance_mode"))throw new Error(R.MAINTENANCE_MODE);if([R.INVALID_API_KEY,R.UNAUTHORIZED].includes(c?.message))throw new Error(R.INVALID_CREDENTIALS)}throw new Error(R.SDK_INIT_ERROR)}finally{I={...I,isLoading:!1,token:o}}}te={init:dr,getSecurityResult:et,getSecurityToken:tt,isAIUsageDetected:it,checkQualityQuestions:nt,getQualityQuestions:rt,QualityQuestionsRespondentTypes:Q,LanguageCodes:V};var pi=te;export{V as LanguageCodes,Q as QualityQuestionsRespondentTypes,nr as SecurityAPIError,nt as checkQualityQuestions,pi as default,rt as getQualityQuestions,et as getSecurityResult,tt as getSecurityToken,dr as init,it as isAIUsageDetected};
|