@fingerprint/agent 4.0.0-beta.3 → 4.0.0-beta.5
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/fp.cjs.min.js +2 -2
- package/dist/fp.d.ts +1 -1
- package/dist/fp.esm.min.js +2 -2
- package/package.json +1 -1
package/dist/fp.cjs.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fingerprint v4.0.0-beta.
|
|
2
|
+
* Fingerprint v4.0.0-beta.5 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
"use strict";function t(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function e(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}function n(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>127)return(new TextEncoder).encode(t);e[n]=r}return e}function r(e){if("function"==typeof TextDecoder){const t=(new TextDecoder).decode(e);if(t)return t}const n=t(e);return decodeURIComponent(escape(String.fromCharCode.apply(null,n)))}function o(t,e){return(t-e+256)%256}function i(t){if(t instanceof Array)return t.map(i);if(t&&"object"==typeof t){const e={};for(const n of Object.keys(t))e[n]=i(t[n]);return e}return t}function c(t){return a(t)?t:[t]}Object.defineProperty(exports,"__esModule",{value:!0});const a=Array.isArray;function s(t,e){return new Promise((n=>function(t,e,...n){const r=Date.now()+e;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...n)}),r-Date.now())};return i(),()=>clearTimeout(o)}(n,t,e)))}function u(t,e){return new Promise(((n,r)=>{let o=!1;null==e||e.then((()=>o=!0),(()=>o=!0));("function"==typeof t?u(Promise.resolve(),e).then(t):t).then((t=>{o||n(t)}),(t=>{o||r(t)}))}))}function f(t,e,n,r){const o=document,i="securitypolicyviolation";let c;const a=e=>{const n=new URL(t,location.href),{blockedURI:r}=e;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(c=e,s())};o.addEventListener(i,a);const s=()=>o.removeEventListener(i,a);return null==r||r.then(s,s),Promise.resolve().then(e).then((t=>(s(),t)),(t=>new Promise((t=>{const e=new MessageChannel;e.port1.onmessage=()=>t(),e.port2.postMessage(null)})).then((()=>{if(s(),c)return n(c);throw t}))))}function l(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(d(t))return!0;throw t}}function d(t){return t instanceof Error&&"TypeError"===t.name}function p(t){if(l(t))return t;const e=new URL(t);return e.search="",e.toString()}function h(t){return t.endsWith("/")?t:`${t}/`}const w="csp_block",y="invalid_endpoint",m="script_load_fail",g="endpoints_misconfigured",v="bundle_not_defined",b={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[w]:"Blocked by CSP",[y]:'The provided endpoint in "endpoints" parameter is not a valid URL',handle_agent_data:"Handle on demand agent data error",[m]:"Failed to load the JS script of the agent",[v]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",api_key_missing:"The `apiKey` option is not provided",api_key_invalid:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[g]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class _ extends Error{constructor(t,e){super(t),this.name="FingerprintError",this.event_id=null,this.code=e}}function A(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}var k="4.0.0-beta.3";function U(t,e,n,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:s}=o,u={failedAttempts:[]},[f,l]=function(t,e,n,r){const o=function(t){const e=[...t];return{current:()=>e[0],postpone(){const t=e.shift();void 0!==t&&e.push(t)},exclude(){e.shift()}}}(t),i=function(t,e){let n=0;return()=>Math.random()*Math.min(e,t*Math.pow(2,n++))}(n,r),c=new Set;return[o.current(),(t,n,r)=>{const a=e(t,n,r);"exclude"===a.action?o.exclude():o.postpone();const s=()=>Math.max(0,t.getTime()+i()-Date.now());let u;u="number"==typeof a.delay?a.delay:s();const f=o.current();if(0===u&&f){Date.now()-t.getTime()<50&&(c.has(f)?u=s():c.add(f))}return void 0===f?void 0:[f,u]}]}(t,r,c,a),d=(p=[null==s?void 0:s.then((t=>u.aborted={resolve:!0,value:t}),(t=>u.aborted={resolve:!1,error:t})),x(f,i,e,n,l,u,s)],Promise.race(p.filter((t=>!!t)))).then((()=>u));var p;return{then:d.then.bind(d),current:u}}async function x(t,e,n,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<e;++t){const e=new Date;let f,l;try{f=await u((()=>n(a,t,c)),c)}catch(t){l=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(f){const t=r(f);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const d=o(e,f,l);if(!d)break;await u(s(d[1]),c),a=d[0]}}function $(t,e,n){const r=n instanceof _?n.code:null;if(r===w||r===y)return{action:"exclude",delay:0};if(r===v)return{action:"exclude",delay:"backoff"};if(r===m){return{action:"postpone",delay:Date.now()-t.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}function C(t,e){D(t,t.len+1),t.arr[t.len++]=e}function E(t,e){D(t,t.len+e.length),t.arr.set(e,t.len),t.len+=e.length}function D(t,e){if(t.arr.length<e){const n=new Uint8Array(Math.max(2*t.arr.length,e));n.set(t.arr),t.arr=n}}function T(e){const o={len:0,arr:new Uint8Array(128)},i=t(e);let c=0;const a=()=>(d(),i[c]===L?s():P(i[c])?u():p(X)?(c+=X.length,null):p(Y)?(c+=Y.length,!0):p(Z)?(c+=Z.length,!1):i[c]===H?f():i[c]===Q?l():h()),s=()=>{for(o.len=0;c++,i[c]!==L;){if(i[c]===W){if(c++,i[c]===N){const t=parseInt(r(i.subarray(c+1,c+5)),16);E(o,n(String.fromCharCode(t))),c+=4;continue}const t=et[i[c]];if(t){C(o,t);continue}return h()}if(void 0===i[c])return h();C(o,i[c])}return c++,r(function(t){return t.arr.subarray(0,t.len)}(o))},u=()=>{const t=c;for(;i[c]===q||i[c]===F||i[c]===K||i[c]===z||P(i[c]);)c++;return Number(r(i.subarray(t,c)))},f=()=>{const t=[];for(c++;;){if(d(),i[c]===G){c++;break}if(t.length){if(i[c]!==R)return h();c++}t.push(a())}return t},l=()=>{const t={};let e=!0;for(c++;;){if(d(),i[c]===V){c++;break}if(!e){if(i[c]!==R)return h();c++,d()}if(i[c]!==L)return h();const n=s();if(d(),i[c]!==j)return h();c++,Object.defineProperty(t,n,{value:a(),configurable:!0,enumerable:!0,writable:!0}),e=!1}return t},d=()=>{for(;i[c]===S||i[c]===I||i[c]===O||i[c]===M;)c++},p=t=>{for(let e=0;e<t.length;e++)if(i[c+e]!==t[e])return!1;return!0},h=()=>{throw new SyntaxError("Unexpected "+(c<i.length?`byte ${c}`:"end"))},w=a();return d(),void 0!==i[c]&&h(),w}function P(t){return t>=B&&t<B+10||t===J}const L=34,R=44,j=58,S=32,M=9,O=13,I=10,W=92,B=48,F=101,N=117,K=69,z=43,J=45,q=46,H=91,G=93,Q=123,V=125,X=new Uint8Array([110,N,108,108]),Y=new Uint8Array([116,114,N,F]),Z=new Uint8Array([102,97,108,115,F]),tt={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},et=(()=>{const t=new Uint8Array(128);for(const[e,n]of Object.entries(tt))t[n.charCodeAt(0)]=e.charCodeAt(0);return t})();const nt="withoutDefault";function rt(t){return{__type__:nt,value:t}}function ot(t){return!!t&&t.__type__===nt}const it="https://fpnpmcdn.net/",ct=Symbol("default");function at(t,e,n=!1,r){const o=function(t){const{region:e,protocol:n}=t;let r=t.host;"us"!==e&&(r=`${e}.${r}`);return`${n}://${r}/`}(e);return n?function(t,e){const n="web",r=[],o=t===it?`${t}`:`${t}${n}`;if(st(e))ut(e.script,o,r,"script");else for(const t of ft(e))dt(t,[{defaultUrl:o,output:r,path:n}],!0);return{script:r}}(o,t):function(t,e,n){const r=[],o=[];if(st(e))ut(e.helper,t,r,"helper"),ut(e.ingress,t,o,"ingress");else for(const i of ft(e))n?ht(wt(i,t),r,n):dt(i,[{defaultUrl:t,output:r}]),dt(i,[{defaultUrl:t,output:o}]);return{helper:r,get:o}}(o,t,r)}function st(t){return!!t&&"object"==typeof t&&!Array.isArray(t)&&!ot(t)}function ut(t,e,n,r){var o;for(const i of ft(t)){lt(n,i===ct?e:null===(o=pt(i,`\`${r}\` endpoint`))||void 0===o?void 0:o.href)}}function ft(t){return ot(t)?c(t.value):void 0===t?[ct]:[...c(t),ct]}function lt(t,e){void 0!==e&&t.push(e)}function dt(t,e,n=!1){var r;if(t===ct){for(const t of e)t.output.push(t.defaultUrl);return}n&&(t=yt((()=>p(t))));const o=pt(t,"`endpoints` value");if(!o)return;const i=h(o.pathname);for(const t of e){const e=null!==(r=t.path)&&void 0!==r?r:"";o.pathname=`${i}${e}`,t.output.push(o.href)}}function pt(t,e){const{location:n,URL:r}=window;try{return new r(t,n.href)}catch(n){if(d(n))return console.warn(`Ignoring an invalid ${e} ${JSON.stringify(t)}`),null;throw n}}function ht(t,e,n){const r=yt((()=>p(t)));e.push(n(h(r)))}function wt(t,e){return t===ct?e:t}function yt(t){try{return t()}catch(t){if(d(t))throw new _(b[y],y);throw t}}var mt=function(e,n){let r;return c=>(r||(r=function(e,n){return T(function(e,n,r){const i=()=>{throw new Error("Invalid data")},c=t(e);c.length<n.length+2&&i();for(let t=0;t<n.length;++t)o(c[1+t],c[0])!==n[t]&&i();const a=1+n.length,s=o(c[a],c[0]);c.length<a+1+s+r&&i();const u=a+1+s,f=u+r,l=new ArrayBuffer(c.length-f),d=new Uint8Array(l);for(let t=0;t<d.length;++t)d[t]=c[f+t]^c[u+t%r];return l}(new Uint32Array(e),[],n))}(e,n)),i(r[c]))}([3501680230,3964354670,1059981298,553689810,78837799,4072876069,3341640258,674045630,775995091,1123205934,2764252002,3932762910],5);const gt=mt(0);function vt(t){let n,r;const{picked:o,rest:i}=function(t,e){const n={},r={};for(const[o,i]of Object.entries(t))e.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(t,["apiKey","region"]),{apiKey:c,region:a}=o,s=e(t,"endpoints");if(!function(t,e){return!(void 0!==t&&"string"!=typeof t&&!ot(t))||(Array.isArray(t)?t.every((t=>"string"==typeof t)):!(!st(t)||!t.type||t.type!==e))}(s,gt))throw new _(b[g],g);const[u,f]=function(){const t=[],e=()=>{t.push({time:new Date,state:document.visibilityState})},n=function(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}(document,"visibilitychange",e);return e(),[t,n]}();const l=async function(){try{if(!c||"string"!=typeof c)throw new Error("API key not provided");const t=function(t,e,n){const{script:r}=function(t,e,n=mt(1)){return r=at,o=t,i={region:e,host:n,protocol:mt(2)},r(o,i,!0);var r,o,i}(t,n||"us"),o=null==r?void 0:r.map((t=>function(t,e){const n=new URL(t,window.location.href),r=n.pathname,o="4";return n.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(e)}`,n.search=`?ci=jsl/${encodeURIComponent(k)}`,n.href}(t,e)));return o||[]}(s,c,a),[e,r]=await function(t,e){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const n=[],r=U(t,(async t=>{const r=new Date;try{const o=await e(t);return n.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(e){throw n.push({url:t,startedAt:r,finishedAt:new Date,error:e}),e}}),(t=>({result:t})),$,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,e)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,n]);else{const t=r.failedAttempts[0];e(t?t.error:new Error("No attempts were made"))}})).catch(e)}))}(t,bt),o=await e.start({...i,ldi:{attempts:r,visibilityStates:u}});return n=o,o}catch(t){throw r=function(t){if(t instanceof _&&t.code===v)return new _(b[m],m);return t}(t),r}finally{f()}}();return{async get(t){if(n)return n.get(t);if(r)throw r;return(await l).get(t)},async collect(t){if(n)return n.collect(t);if(r)throw r;return(await l).collect(t)}}}function bt(t){return f(t,(async()=>{if(l(t))throw new _(b[y],y);try{return await import(t)}catch(t){throw new _(b[m],m)}}),(()=>{throw new _(b[w],w)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new _(b[v],v);return t}))}var _t={start:vt,isFingerprintError:A,withoutDefault:rt};exports.default=_t,exports.isFingerprintError=A,exports.start=vt,exports.withoutDefault=rt;
|
|
5
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t="csp_block",e="invalid_endpoint",n="script_load_fail",r="endpoints_misconfigured",o="bundle_not_defined",i={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[t]:"Blocked by CSP",[e]:'The provided endpoint in "endpoints" parameter is not a valid URL',handle_agent_data:"Handle on demand agent data error",[n]:"Failed to load the JS script of the agent",[o]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",api_key_missing:"The `apiKey` option is not provided",api_key_invalid:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[r]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class c extends Error{constructor(t,e){super(t),this.name="FingerprintError",this.event_id=null,this.code=e}}function a(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}const s="withoutDefault";function u(t){return{__type__:s,value:t}}function f(t){return!!t&&t.__type__===s}function l(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function d(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}function p(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>127)return(new TextEncoder).encode(t);e[n]=r}return e}function h(t){if("function"==typeof TextDecoder){const e=(new TextDecoder).decode(t);if(e)return e}const e=l(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,e)))}function w(t,e){return(t-e+256)%256}function y(t){if(t instanceof Array)return t.map(y);if(t&&"object"==typeof t){const e={};for(const n of Object.keys(t))e[n]=y(t[n]);return e}return t}function m(t){return g(t)?t:[t]}const g=Array.isArray;function v(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(b(t))return!0;throw t}}function b(t){return t instanceof Error&&"TypeError"===t.name}function _(t){if(v(t))return t;const e=new URL(t);return e.search="",e.toString()}function A(t){return t.endsWith("/")?t:`${t}/`}const k="https://fpnpmcdn.net/",U=Symbol("default");function x(t,e,n=!1,r){const o=n?function(t){const{protocol:e}=t;return`${e}://${new URL(k).host}/`}(e):function(t){const{region:e,protocol:n}=t;let r=t.host;"us"!==e&&(r=`${e}.${r}`);return`${n}://${r}/`}(e);return n?function(t,e){const n="web",r=[],o=t===k?`${t}`:`${t}${n}`;if($(e))C(e.script,o,r,"script");else for(const t of E(e))T(t,[{defaultUrl:o,output:r,path:n}],!0);return{script:r}}(o,t):function(t,e,n){const r=[],o=[];if($(e))C(e.helper,t,r,"helper"),C(e.ingress,t,o,"ingress");else for(const i of E(e))n?P(R(i,t),r,n):T(i,[{defaultUrl:t,output:r}]),T(i,[{defaultUrl:t,output:o}]);return{helper:r,get:o}}(o,t,r)}function $(t){return!!t&&"object"==typeof t&&!Array.isArray(t)&&!f(t)}function C(t,e,n,r){var o;for(const i of E(t)){D(n,i===U?e:null===(o=L(i,`\`${r}\` endpoint`))||void 0===o?void 0:o.href)}}function E(t){return f(t)?m(t.value):void 0===t?[U]:[...m(t),U]}function D(t,e){void 0!==e&&t.push(e)}function T(t,e,n=!1){var r;if(t===U){for(const t of e)t.output.push(t.defaultUrl);return}n&&(t=j((()=>_(t))));const o=L(t,"`endpoints` value");if(!o)return;const i=A(o.pathname);for(const t of e){const e=null!==(r=t.path)&&void 0!==r?r:"";o.pathname=`${i}${e}`,t.output.push(o.href)}}function L(t,e){const{location:n,URL:r}=window;try{return new r(t,n.href)}catch(n){if(b(n))return console.warn(`Ignoring an invalid ${e} ${JSON.stringify(t)}`),null;throw n}}function P(t,e,n){const r=j((()=>_(t)));e.push(n(A(r)))}function R(t,e){return t===U?e:t}function j(t){try{return t()}catch(t){if(b(t))throw new c(i[e],e);throw t}}function S(t,e){return new Promise((n=>function(t,e,...n){const r=Date.now()+e;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...n)}),r-Date.now())};return i(),()=>clearTimeout(o)}(n,t,e)))}function M(t,e){return new Promise(((n,r)=>{let o=!1;null==e||e.then((()=>o=!0),(()=>o=!0));("function"==typeof t?M(Promise.resolve(),e).then(t):t).then((t=>{o||n(t)}),(t=>{o||r(t)}))}))}function O(t,e,n,r){const o=document,i="securitypolicyviolation";let c;const a=e=>{const n=new URL(t,location.href),{blockedURI:r}=e;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(c=e,s())};o.addEventListener(i,a);const s=()=>o.removeEventListener(i,a);return null==r||r.then(s,s),Promise.resolve().then(e).then((t=>(s(),t)),(t=>new Promise((t=>{const e=new MessageChannel;e.port1.onmessage=()=>t(),e.port2.postMessage(null)})).then((()=>{if(s(),c)return n(c);throw t}))))}var I="4.0.0-beta.5";function W(t,e){F(t,t.len+1),t.arr[t.len++]=e}function B(t,e){F(t,t.len+e.length),t.arr.set(e,t.len),t.len+=e.length}function F(t,e){if(t.arr.length<e){const n=new Uint8Array(Math.max(2*t.arr.length,e));n.set(t.arr),t.arr=n}}function N(t){const e={len:0,arr:new Uint8Array(128)},n=l(t);let r=0;const o=()=>(u(),n[r]===z?i():K(n[r])?c():f(ut)?(r+=ut.length,null):f(ft)?(r+=ft.length,!0):f(lt)?(r+=lt.length,!1):n[r]===it?a():n[r]===at?s():d()),i=()=>{for(e.len=0;r++,n[r]!==z;){if(n[r]===X){if(r++,n[r]===tt){const t=parseInt(h(n.subarray(r+1,r+5)),16);B(e,p(String.fromCharCode(t))),r+=4;continue}const t=pt[n[r]];if(t){W(e,t);continue}return d()}if(void 0===n[r])return d();W(e,n[r])}return r++,h(function(t){return t.arr.subarray(0,t.len)}(e))},c=()=>{const t=r;for(;n[r]===ot||n[r]===Z||n[r]===et||n[r]===nt||K(n[r]);)r++;return Number(h(n.subarray(t,r)))},a=()=>{const t=[];for(r++;;){if(u(),n[r]===ct){r++;break}if(t.length){if(n[r]!==J)return d();r++}t.push(o())}return t},s=()=>{const t={};let e=!0;for(r++;;){if(u(),n[r]===st){r++;break}if(!e){if(n[r]!==J)return d();r++,u()}if(n[r]!==z)return d();const c=i();if(u(),n[r]!==q)return d();r++,Object.defineProperty(t,c,{value:o(),configurable:!0,enumerable:!0,writable:!0}),e=!1}return t},u=()=>{for(;n[r]===H||n[r]===V||n[r]===Q||n[r]===G;)r++},f=t=>{for(let e=0;e<t.length;e++)if(n[r+e]!==t[e])return!1;return!0},d=()=>{throw new SyntaxError("Unexpected "+(r<n.length?`byte ${r}`:"end"))},w=o();return u(),void 0!==n[r]&&d(),w}function K(t){return t>=Y&&t<Y+10||t===rt}const z=34,J=44,q=58,H=32,G=9,Q=13,V=10,X=92,Y=48,Z=101,tt=117,et=69,nt=43,rt=45,ot=46,it=91,ct=93,at=123,st=125,ut=new Uint8Array([110,tt,108,108]),ft=new Uint8Array([116,114,tt,Z]),lt=new Uint8Array([102,97,108,115,Z]),dt={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},pt=(()=>{const t=new Uint8Array(128);for(const[e,n]of Object.entries(dt))t[n.charCodeAt(0)]=e.charCodeAt(0);return t})();var ht=function(t,e){let n;return r=>(n||(n=function(t,e){return N(function(t,e,n){const r=()=>{throw new Error("Invalid data")},o=l(t);o.length<e.length+2&&r();for(let t=0;t<e.length;++t)w(o[1+t],o[0])!==e[t]&&r();const i=1+e.length,c=w(o[i],o[0]);o.length<i+1+c+n&&r();const a=i+1+c,s=a+n,u=new ArrayBuffer(o.length-s),f=new Uint8Array(u);for(let t=0;t<f.length;++t)f[t]=o[s+t]^o[a+t%n];return u}(new Uint32Array(t),[],e))}(t,e)),y(n[r]))}([3501680230,3964354670,1059981298,553689810,78837799,4072876069,3341640258,674045630,775995091,1123205934,2764252002,3932762910],5);const wt=ht(0);function yt(t,e,n,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:s}=o,u={failedAttempts:[]},[f,l]=function(t,e,n,r){const o=function(t){const e=[...t];return{current:()=>e[0],postpone(){const t=e.shift();void 0!==t&&e.push(t)},exclude(){e.shift()}}}(t),i=function(t,e){let n=0;return()=>Math.random()*Math.min(e,t*Math.pow(2,n++))}(n,r),c=new Set;return[o.current(),(t,n,r)=>{const a=e(t,n,r);"exclude"===a.action?o.exclude():o.postpone();const s=()=>Math.max(0,t.getTime()+i()-Date.now());let u;u="number"==typeof a.delay?a.delay:s();const f=o.current();if(0===u&&f){Date.now()-t.getTime()<50&&(c.has(f)?u=s():c.add(f))}return void 0===f?void 0:[f,u]}]}(t,r,c,a),d=(p=[null==s?void 0:s.then((t=>u.aborted={resolve:!0,value:t}),(t=>u.aborted={resolve:!1,error:t})),mt(f,i,e,n,l,u,s)],Promise.race(p.filter((t=>!!t)))).then((()=>u));var p;return{then:d.then.bind(d),current:u}}async function mt(t,e,n,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<e;++t){const e=new Date;let s,u;try{s=await M((()=>n(a,t,c)),c)}catch(t){u=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(s){const t=r(s);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const f=o(e,s,u);if(!f)break;await M(S(f[1]),c),a=f[0]}}function gt(r,i,a){const s=a instanceof c?a.code:null;if(s===t||s===e)return{action:"exclude",delay:0};if(s===o)return{action:"exclude",delay:"backoff"};if(s===n){return{action:"postpone",delay:Date.now()-r.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}function vt(t){let e,a;const{picked:s,rest:u}=function(t,e){const n={},r={};for(const[o,i]of Object.entries(t))e.includes(o)?n[o]=i:r[o]=i;return{picked:n,rest:r}}(t,["apiKey","region"]),{apiKey:l,region:p}=s,h=d(t,"endpoints");if(!function(t,e){return!(void 0!==t&&"string"!=typeof t&&!f(t))||(Array.isArray(t)?t.every((t=>"string"==typeof t)):!(!$(t)||!t.type||t.type!==e))}(h,wt))throw new c(i[r],r);const[w,y]=function(){const t=[],e=()=>{t.push({time:new Date,state:document.visibilityState})},n=function(t,e,n,r){return t.addEventListener(e,n,r),()=>t.removeEventListener(e,n,r)}(document,"visibilitychange",e);return e(),[t,n]}();const m=async function(){try{if(!l||"string"!=typeof l)throw new Error("API key not provided");const t=function(t,e,n){const{script:r}=function(t,e,n=ht(1)){return r=x,o=t,i={region:e,host:n,protocol:ht(2)},r(o,i,!0);var r,o,i}(t,n||"us"),o=null==r?void 0:r.map((t=>function(t,e){const n=new URL(t,window.location.href),r=n.pathname,o="4";return n.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(e)}`,n.search=`?ci=jsl/${encodeURIComponent(I)}`,n.href}(t,e)));return o||[]}(h,l,p),[n,r]=await function(t,e){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const n=[],r=yt(t,(async t=>{const r=new Date;try{const o=await e(t);return n.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(e){throw n.push({url:t,startedAt:r,finishedAt:new Date,error:e}),e}}),(t=>({result:t})),gt,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,e)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,n]);else{const t=r.failedAttempts[0];e(t?t.error:new Error("No attempts were made"))}})).catch(e)}))}(t,bt),o=await n.start({...u,ldi:{attempts:r,visibilityStates:w}});return e=o,o}catch(t){throw a=function(t){if(t instanceof c&&t.code===o)return new c(i[n],n);return t}(t),a}finally{y()}}();return{async get(t){if(e)return e.get(t);if(a)throw a;return(await m).get(t)},async collect(t){if(e)return e.collect(t);if(a)throw a;return(await m).collect(t)}}}function bt(r){return O(r,(async()=>{if(v(r))throw new c(i[e],e);try{return await import(/* webpackIgnore: true */r)}catch(t){throw new c(i[n],n)}}),(()=>{throw new c(i[t],t)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new c(i[o],o);return t}))}var _t={start:vt,isFingerprintError:a,withoutDefault:u};exports.default=_t,exports.isFingerprintError=a,exports.start=vt,exports.withoutDefault=u;
|
package/dist/fp.d.ts
CHANGED
package/dist/fp.esm.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fingerprint v4.0.0-beta.
|
|
2
|
+
* Fingerprint v4.0.0-beta.5 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
function t(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function n(t,n){return function(t,n){return Object.prototype.hasOwnProperty.call(t,n)}(t,n)?t[n]:void 0}function e(t){const n=new Uint8Array(t.length);for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r>127)return(new TextEncoder).encode(t);n[e]=r}return n}function r(n){if("function"==typeof TextDecoder){const t=(new TextDecoder).decode(n);if(t)return t}const e=t(n);return decodeURIComponent(escape(String.fromCharCode.apply(null,e)))}function o(t,n){return(t-n+256)%256}function i(t){if(t instanceof Array)return t.map(i);if(t&&"object"==typeof t){const n={};for(const e of Object.keys(t))n[e]=i(t[e]);return n}return t}function c(t){return a(t)?t:[t]}const a=Array.isArray;function u(t,n){return new Promise((e=>function(t,n,...e){const r=Date.now()+n;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...e)}),r-Date.now())};return i(),()=>clearTimeout(o)}(e,t,n)))}function s(t,n){return new Promise(((e,r)=>{let o=!1;null==n||n.then((()=>o=!0),(()=>o=!0));("function"==typeof t?s(Promise.resolve(),n).then(t):t).then((t=>{o||e(t)}),(t=>{o||r(t)}))}))}function f(t,n,e,r){const o=document,i="securitypolicyviolation";let c;const a=n=>{const e=new URL(t,location.href),{blockedURI:r}=n;r!==e.href&&r!==e.protocol.slice(0,-1)&&r!==e.origin||(c=n,u())};o.addEventListener(i,a);const u=()=>o.removeEventListener(i,a);return null==r||r.then(u,u),Promise.resolve().then(n).then((t=>(u(),t)),(t=>new Promise((t=>{const n=new MessageChannel;n.port1.onmessage=()=>t(),n.port2.postMessage(null)})).then((()=>{if(u(),c)return e(c);throw t}))))}function l(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(d(t))return!0;throw t}}function d(t){return t instanceof Error&&"TypeError"===t.name}function p(t){if(l(t))return t;const n=new URL(t);return n.search="",n.toString()}function h(t){return t.endsWith("/")?t:`${t}/`}const w="csp_block",y="invalid_endpoint",m="script_load_fail",g="endpoints_misconfigured",v="bundle_not_defined",b={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[w]:"Blocked by CSP",[y]:'The provided endpoint in "endpoints" parameter is not a valid URL',handle_agent_data:"Handle on demand agent data error",[m]:"Failed to load the JS script of the agent",[v]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",api_key_missing:"The `apiKey` option is not provided",api_key_invalid:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[g]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class A extends Error{constructor(t,n){super(t),this.name="FingerprintError",this.event_id=null,this.code=n}}function _(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}var k="4.0.0-beta.3";function U(t,n,e,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:u}=o,s={failedAttempts:[]},[f,l]=function(t,n,e,r){const o=function(t){const n=[...t];return{current:()=>n[0],postpone(){const t=n.shift();void 0!==t&&n.push(t)},exclude(){n.shift()}}}(t),i=function(t,n){let e=0;return()=>Math.random()*Math.min(n,t*Math.pow(2,e++))}(e,r),c=new Set;return[o.current(),(t,e,r)=>{const a=n(t,e,r);"exclude"===a.action?o.exclude():o.postpone();const u=()=>Math.max(0,t.getTime()+i()-Date.now());let s;s="number"==typeof a.delay?a.delay:u();const f=o.current();if(0===s&&f){Date.now()-t.getTime()<50&&(c.has(f)?s=u():c.add(f))}return void 0===f?void 0:[f,s]}]}(t,r,c,a),d=(p=[null==u?void 0:u.then((t=>s.aborted={resolve:!0,value:t}),(t=>s.aborted={resolve:!1,error:t})),$(f,i,n,e,l,s,u)],Promise.race(p.filter((t=>!!t)))).then((()=>s));var p;return{then:d.then.bind(d),current:s}}async function $(t,n,e,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<n;++t){const n=new Date;let f,l;try{f=await s((()=>e(a,t,c)),c)}catch(t){l=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(f){const t=r(f);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const d=o(n,f,l);if(!d)break;await s(u(d[1]),c),a=d[0]}}function x(t,n,e){const r=e instanceof A?e.code:null;if(r===w||r===y)return{action:"exclude",delay:0};if(r===v)return{action:"exclude",delay:"backoff"};if(r===m){return{action:"postpone",delay:Date.now()-t.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}function C(t,n){T(t,t.len+1),t.arr[t.len++]=n}function E(t,n){T(t,t.len+n.length),t.arr.set(n,t.len),t.len+=n.length}function T(t,n){if(t.arr.length<n){const e=new Uint8Array(Math.max(2*t.arr.length,n));e.set(t.arr),t.arr=e}}function D(n){const o={len:0,arr:new Uint8Array(128)},i=t(n);let c=0;const a=()=>(d(),i[c]===P?u():L(i[c])?s():p(X)?(c+=X.length,null):p(Y)?(c+=Y.length,!0):p(Z)?(c+=Z.length,!1):i[c]===H?f():i[c]===Q?l():h()),u=()=>{for(o.len=0;c++,i[c]!==P;){if(i[c]===W){if(c++,i[c]===F){const t=parseInt(r(i.subarray(c+1,c+5)),16);E(o,e(String.fromCharCode(t))),c+=4;continue}const t=nt[i[c]];if(t){C(o,t);continue}return h()}if(void 0===i[c])return h();C(o,i[c])}return c++,r(function(t){return t.arr.subarray(0,t.len)}(o))},s=()=>{const t=c;for(;i[c]===q||i[c]===N||i[c]===K||i[c]===z||L(i[c]);)c++;return Number(r(i.subarray(t,c)))},f=()=>{const t=[];for(c++;;){if(d(),i[c]===G){c++;break}if(t.length){if(i[c]!==R)return h();c++}t.push(a())}return t},l=()=>{const t={};let n=!0;for(c++;;){if(d(),i[c]===V){c++;break}if(!n){if(i[c]!==R)return h();c++,d()}if(i[c]!==P)return h();const e=u();if(d(),i[c]!==S)return h();c++,Object.defineProperty(t,e,{value:a(),configurable:!0,enumerable:!0,writable:!0}),n=!1}return t},d=()=>{for(;i[c]===j||i[c]===O||i[c]===M||i[c]===I;)c++},p=t=>{for(let n=0;n<t.length;n++)if(i[c+n]!==t[n])return!1;return!0},h=()=>{throw new SyntaxError("Unexpected "+(c<i.length?`byte ${c}`:"end"))},w=a();return d(),void 0!==i[c]&&h(),w}function L(t){return t>=B&&t<B+10||t===J}const P=34,R=44,S=58,j=32,I=9,M=13,O=10,W=92,B=48,N=101,F=117,K=69,z=43,J=45,q=46,H=91,G=93,Q=123,V=125,X=/*#__PURE__*/new Uint8Array([110,F,108,108]),Y=/*#__PURE__*/new Uint8Array([116,114,F,N]),Z=/*#__PURE__*/new Uint8Array([102,97,108,115,N]),tt={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},nt=/*#__PURE__*/(()=>{const t=new Uint8Array(128);for(const[n,e]of Object.entries(tt))t[e.charCodeAt(0)]=n.charCodeAt(0);return t})();const et="withoutDefault";function rt(t){return{__type__:et,value:t}}function ot(t){return!!t&&t.__type__===et}const it="https://fpnpmcdn.net/",ct=/*#__PURE__*/Symbol("default");function at(t,n,e=!1,r){const o=function(t){const{region:n,protocol:e}=t;let r=t.host;"us"!==n&&(r=`${n}.${r}`);return`${e}://${r}/`}(n);return e?function(t,n){const e="web",r=[],o=t===it?`${t}`:`${t}${e}`;if(ut(n))st(n.script,o,r,"script");else for(const t of ft(n))dt(t,[{defaultUrl:o,output:r,path:e}],!0);return{script:r}}(o,t):function(t,n,e){const r=[],o=[];if(ut(n))st(n.helper,t,r,"helper"),st(n.ingress,t,o,"ingress");else for(const i of ft(n))e?ht(wt(i,t),r,e):dt(i,[{defaultUrl:t,output:r}]),dt(i,[{defaultUrl:t,output:o}]);return{helper:r,get:o}}(o,t,r)}function ut(t){return!!t&&"object"==typeof t&&!Array.isArray(t)&&!ot(t)}function st(t,n,e,r){var o;for(const i of ft(t)){lt(e,i===ct?n:null===(o=pt(i,`\`${r}\` endpoint`))||void 0===o?void 0:o.href)}}function ft(t){return ot(t)?c(t.value):void 0===t?[ct]:[...c(t),ct]}function lt(t,n){void 0!==n&&t.push(n)}function dt(t,n,e=!1){var r;if(t===ct){for(const t of n)t.output.push(t.defaultUrl);return}e&&(t=yt((()=>p(t))));const o=pt(t,"`endpoints` value");if(!o)return;const i=h(o.pathname);for(const t of n){const n=null!==(r=t.path)&&void 0!==r?r:"";o.pathname=`${i}${n}`,t.output.push(o.href)}}function pt(t,n){const{location:e,URL:r}=window;try{return new r(t,e.href)}catch(e){if(d(e))return console.warn(`Ignoring an invalid ${n} ${JSON.stringify(t)}`),null;throw e}}function ht(t,n,e){const r=yt((()=>p(t)));n.push(e(h(r)))}function wt(t,n){return t===ct?n:t}function yt(t){try{return t()}catch(t){if(d(t))throw new A(b[y],y);throw t}}var mt=function(n,e){let r;return c=>(r||(r=function(n,e){return D(function(n,e,r){const i=()=>{throw new Error("Invalid data")},c=t(n);c.length<e.length+2&&i();for(let t=0;t<e.length;++t)o(c[1+t],c[0])!==e[t]&&i();const a=1+e.length,u=o(c[a],c[0]);c.length<a+1+u+r&&i();const s=a+1+u,f=s+r,l=new ArrayBuffer(c.length-f),d=new Uint8Array(l);for(let t=0;t<d.length;++t)d[t]=c[f+t]^c[s+t%r];return l}(new Uint32Array(n),[],e))}(n,e)),i(r[c]))}([3501680230,3964354670,1059981298,553689810,78837799,4072876069,3341640258,674045630,775995091,1123205934,2764252002,3932762910],5);const gt=mt(0);function vt(t){let e,r;const{picked:o,rest:i}=function(t,n){const e={},r={};for(const[o,i]of Object.entries(t))n.includes(o)?e[o]=i:r[o]=i;return{picked:e,rest:r}}(t,["apiKey","region"]),{apiKey:c,region:a}=o,u=n(t,"endpoints");if(!function(t,n){return!(void 0!==t&&"string"!=typeof t&&!ot(t))||(Array.isArray(t)?t.every((t=>"string"==typeof t)):!(!ut(t)||!t.type||t.type!==n))}(u,gt))throw new A(b[g],g);const[s,f]=function(){const t=[],n=()=>{t.push({time:new Date,state:document.visibilityState})},e=function(t,n,e,r){return t.addEventListener(n,e,r),()=>t.removeEventListener(n,e,r)}(document,"visibilitychange",n);return n(),[t,e]}();const l=async function(){try{if(!c||"string"!=typeof c)throw new Error("API key not provided");const t=function(t,n,e){const{script:r}=function(t,n,e=mt(1)){return r=at,o=t,i={region:n,host:e,protocol:mt(2)},r(o,i,!0);var r,o,i}(t,e||"us"),o=null==r?void 0:r.map((t=>function(t,n){const e=new URL(t,window.location.href),r=e.pathname,o="4";return e.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(n)}`,e.search=`?ci=jsl/${encodeURIComponent(k)}`,e.href}(t,n)));return o||[]}(u,c,a),[n,r]=await function(t,n){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const e=[],r=U(t,(async t=>{const r=new Date;try{const o=await n(t);return e.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(n){throw e.push({url:t,startedAt:r,finishedAt:new Date,error:n}),n}}),(t=>({result:t})),x,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,n)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,e]);else{const t=r.failedAttempts[0];n(t?t.error:new Error("No attempts were made"))}})).catch(n)}))}(t,bt),o=await n.start({...i,ldi:{attempts:r,visibilityStates:s}});return e=o,o}catch(t){throw r=function(t){if(t instanceof A&&t.code===v)return new A(b[m],m);return t}(t),r}finally{f()}}();return{async get(t){if(e)return e.get(t);if(r)throw r;return(await l).get(t)},async collect(t){if(e)return e.collect(t);if(r)throw r;return(await l).collect(t)}}}function bt(t){return f(t,(async()=>{if(l(t))throw new A(b[y],y);try{return await import(t)}catch(t){throw new A(b[m],m)}}),(()=>{throw new A(b[w],w)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new A(b[v],v);return t}))}var At={start:vt,isFingerprintError:_,withoutDefault:rt};export{At as default,_ as isFingerprintError,vt as start,rt as withoutDefault};
|
|
5
|
+
const t="csp_block",n="invalid_endpoint",e="script_load_fail",r="endpoints_misconfigured",o="bundle_not_defined",i={client_timeout:"Client timeout",network_connection:"Network connection error",network_abort:"Network request aborted",[t]:"Blocked by CSP",[n]:'The provided endpoint in "endpoints" parameter is not a valid URL',handle_agent_data:"Handle on demand agent data error",[e]:"Failed to load the JS script of the agent",[o]:"9319",bad_response_format:"Can't parse the backend response. Make sure the proper endpoints are used.",api_key_missing:"The `apiKey` option is not provided",api_key_invalid:"The `apiKey` option is not a string",cache_misconfigured:"The `cache` option is misconfigured",[r]:"The `endpoints` option is misconfigured",wrong_worker_option:"Wrong `worker` option, it should be a Worker instance",worker_initialization_failed:"Web Worker initialization failed",sandboxed_iframe:"Running inside sandboxed iframes is not supported"};class c extends Error{constructor(t,n){super(t),this.name="FingerprintError",this.event_id=null,this.code=n}}function a(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}const u="withoutDefault";function s(t){return{__type__:u,value:t}}function f(t){return!!t&&t.__type__===u}function l(t){return t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function d(t,n){return function(t,n){return Object.prototype.hasOwnProperty.call(t,n)}(t,n)?t[n]:void 0}function p(t){const n=new Uint8Array(t.length);for(let e=0;e<t.length;e++){const r=t.charCodeAt(e);if(r>127)return(new TextEncoder).encode(t);n[e]=r}return n}function h(t){if("function"==typeof TextDecoder){const n=(new TextDecoder).decode(t);if(n)return n}const n=l(t);return decodeURIComponent(escape(String.fromCharCode.apply(null,n)))}function w(t,n){return(t-n+256)%256}function y(t){if(t instanceof Array)return t.map(y);if(t&&"object"==typeof t){const n={};for(const e of Object.keys(t))n[e]=y(t[e]);return n}return t}function m(t){return g(t)?t:[t]}const g=Array.isArray;function v(t){if(URL.prototype)try{return new URL(t,location.href),!1}catch(t){if(b(t))return!0;throw t}}function b(t){return t instanceof Error&&"TypeError"===t.name}function A(t){if(v(t))return t;const n=new URL(t);return n.search="",n.toString()}function _(t){return t.endsWith("/")?t:`${t}/`}const k="https://fpnpmcdn.net/",U=/*#__PURE__*/Symbol("default");function $(t,n,e=!1,r){const o=e?function(t){const{protocol:n}=t;return`${n}://${new URL(k).host}/`}(n):function(t){const{region:n,protocol:e}=t;let r=t.host;"us"!==n&&(r=`${n}.${r}`);return`${e}://${r}/`}(n);return e?function(t,n){const e="web",r=[],o=t===k?`${t}`:`${t}${e}`;if(x(n))C(n.script,o,r,"script");else for(const t of E(n))D(t,[{defaultUrl:o,output:r,path:e}],!0);return{script:r}}(o,t):function(t,n,e){const r=[],o=[];if(x(n))C(n.helper,t,r,"helper"),C(n.ingress,t,o,"ingress");else for(const i of E(n))e?R(P(i,t),r,e):D(i,[{defaultUrl:t,output:r}]),D(i,[{defaultUrl:t,output:o}]);return{helper:r,get:o}}(o,t,r)}function x(t){return!!t&&"object"==typeof t&&!Array.isArray(t)&&!f(t)}function C(t,n,e,r){var o;for(const i of E(t)){T(e,i===U?n:null===(o=L(i,`\`${r}\` endpoint`))||void 0===o?void 0:o.href)}}function E(t){return f(t)?m(t.value):void 0===t?[U]:[...m(t),U]}function T(t,n){void 0!==n&&t.push(n)}function D(t,n,e=!1){var r;if(t===U){for(const t of n)t.output.push(t.defaultUrl);return}e&&(t=S((()=>A(t))));const o=L(t,"`endpoints` value");if(!o)return;const i=_(o.pathname);for(const t of n){const n=null!==(r=t.path)&&void 0!==r?r:"";o.pathname=`${i}${n}`,t.output.push(o.href)}}function L(t,n){const{location:e,URL:r}=window;try{return new r(t,e.href)}catch(e){if(b(e))return console.warn(`Ignoring an invalid ${n} ${JSON.stringify(t)}`),null;throw e}}function R(t,n,e){const r=S((()=>A(t)));n.push(e(_(r)))}function P(t,n){return t===U?n:t}function S(t){try{return t()}catch(t){if(b(t))throw new c(i[n],n);throw t}}function j(t,n){return new Promise((e=>function(t,n,...e){const r=Date.now()+n;let o=0;const i=()=>{o=setTimeout((()=>{Date.now()<r?i():t(...e)}),r-Date.now())};return i(),()=>clearTimeout(o)}(e,t,n)))}function I(t,n){return new Promise(((e,r)=>{let o=!1;null==n||n.then((()=>o=!0),(()=>o=!0));("function"==typeof t?I(Promise.resolve(),n).then(t):t).then((t=>{o||e(t)}),(t=>{o||r(t)}))}))}function M(t,n,e,r){const o=document,i="securitypolicyviolation";let c;const a=n=>{const e=new URL(t,location.href),{blockedURI:r}=n;r!==e.href&&r!==e.protocol.slice(0,-1)&&r!==e.origin||(c=n,u())};o.addEventListener(i,a);const u=()=>o.removeEventListener(i,a);return null==r||r.then(u,u),Promise.resolve().then(n).then((t=>(u(),t)),(t=>new Promise((t=>{const n=new MessageChannel;n.port1.onmessage=()=>t(),n.port2.postMessage(null)})).then((()=>{if(u(),c)return e(c);throw t}))))}var O="4.0.0-beta.5";function W(t,n){N(t,t.len+1),t.arr[t.len++]=n}function B(t,n){N(t,t.len+n.length),t.arr.set(n,t.len),t.len+=n.length}function N(t,n){if(t.arr.length<n){const e=new Uint8Array(Math.max(2*t.arr.length,n));e.set(t.arr),t.arr=e}}function F(t){const n={len:0,arr:new Uint8Array(128)},e=l(t);let r=0;const o=()=>(s(),e[r]===z?i():K(e[r])?c():f(st)?(r+=st.length,null):f(ft)?(r+=ft.length,!0):f(lt)?(r+=lt.length,!1):e[r]===it?a():e[r]===at?u():d()),i=()=>{for(n.len=0;r++,e[r]!==z;){if(e[r]===X){if(r++,e[r]===tt){const t=parseInt(h(e.subarray(r+1,r+5)),16);B(n,p(String.fromCharCode(t))),r+=4;continue}const t=pt[e[r]];if(t){W(n,t);continue}return d()}if(void 0===e[r])return d();W(n,e[r])}return r++,h(function(t){return t.arr.subarray(0,t.len)}(n))},c=()=>{const t=r;for(;e[r]===ot||e[r]===Z||e[r]===nt||e[r]===et||K(e[r]);)r++;return Number(h(e.subarray(t,r)))},a=()=>{const t=[];for(r++;;){if(s(),e[r]===ct){r++;break}if(t.length){if(e[r]!==J)return d();r++}t.push(o())}return t},u=()=>{const t={};let n=!0;for(r++;;){if(s(),e[r]===ut){r++;break}if(!n){if(e[r]!==J)return d();r++,s()}if(e[r]!==z)return d();const c=i();if(s(),e[r]!==q)return d();r++,Object.defineProperty(t,c,{value:o(),configurable:!0,enumerable:!0,writable:!0}),n=!1}return t},s=()=>{for(;e[r]===H||e[r]===V||e[r]===Q||e[r]===G;)r++},f=t=>{for(let n=0;n<t.length;n++)if(e[r+n]!==t[n])return!1;return!0},d=()=>{throw new SyntaxError("Unexpected "+(r<e.length?`byte ${r}`:"end"))},w=o();return s(),void 0!==e[r]&&d(),w}function K(t){return t>=Y&&t<Y+10||t===rt}const z=34,J=44,q=58,H=32,G=9,Q=13,V=10,X=92,Y=48,Z=101,tt=117,nt=69,et=43,rt=45,ot=46,it=91,ct=93,at=123,ut=125,st=/*#__PURE__*/new Uint8Array([110,tt,108,108]),ft=/*#__PURE__*/new Uint8Array([116,114,tt,Z]),lt=/*#__PURE__*/new Uint8Array([102,97,108,115,Z]),dt={'"':'"',"\\":"\\","\b":"b","\f":"f","\n":"n","\r":"r","\t":"t"},pt=/*#__PURE__*/(()=>{const t=new Uint8Array(128);for(const[n,e]of Object.entries(dt))t[e.charCodeAt(0)]=n.charCodeAt(0);return t})();var ht=function(t,n){let e;return r=>(e||(e=function(t,n){return F(function(t,n,e){const r=()=>{throw new Error("Invalid data")},o=l(t);o.length<n.length+2&&r();for(let t=0;t<n.length;++t)w(o[1+t],o[0])!==n[t]&&r();const i=1+n.length,c=w(o[i],o[0]);o.length<i+1+c+e&&r();const a=i+1+c,u=a+e,s=new ArrayBuffer(o.length-u),f=new Uint8Array(s);for(let t=0;t<f.length;++t)f[t]=o[u+t]^o[a+t%e];return s}(new Uint32Array(t),[],n))}(t,n)),y(e[r]))}([3501680230,3964354670,1059981298,553689810,78837799,4072876069,3341640258,674045630,775995091,1123205934,2764252002,3932762910],5);const wt=ht(0);function yt(t,n,e,r,o={}){const{maxAttemptCount:i=5,backoffBase:c=200,backoffCap:a=1e4,abort:u}=o,s={failedAttempts:[]},[f,l]=function(t,n,e,r){const o=function(t){const n=[...t];return{current:()=>n[0],postpone(){const t=n.shift();void 0!==t&&n.push(t)},exclude(){n.shift()}}}(t),i=function(t,n){let e=0;return()=>Math.random()*Math.min(n,t*Math.pow(2,e++))}(e,r),c=new Set;return[o.current(),(t,e,r)=>{const a=n(t,e,r);"exclude"===a.action?o.exclude():o.postpone();const u=()=>Math.max(0,t.getTime()+i()-Date.now());let s;s="number"==typeof a.delay?a.delay:u();const f=o.current();if(0===s&&f){Date.now()-t.getTime()<50&&(c.has(f)?s=u():c.add(f))}return void 0===f?void 0:[f,s]}]}(t,r,c,a),d=(p=[null==u?void 0:u.then((t=>s.aborted={resolve:!0,value:t}),(t=>s.aborted={resolve:!1,error:t})),mt(f,i,n,e,l,s,u)],Promise.race(p.filter((t=>!!t)))).then((()=>s));var p;return{then:d.then.bind(d),current:s}}async function mt(t,n,e,r,o,i,c){if(void 0===t)return;let a=t;for(let t=0;t<n;++t){const n=new Date;let u,s;try{u=await I((()=>e(a,t,c)),c)}catch(t){s=t,i.failedAttempts.push({level:0,endpoint:a,error:t})}if(u){const t=r(u);if("result"in t){i.result=t.result;break}if(i.failedAttempts.push({level:1,endpoint:a,error:t.error}),t.stop)break}const f=o(n,u,s);if(!f)break;await I(j(f[1]),c),a=f[0]}}function gt(r,i,a){const u=a instanceof c?a.code:null;if(u===t||u===n)return{action:"exclude",delay:0};if(u===o)return{action:"exclude",delay:"backoff"};if(u===e){return{action:"postpone",delay:Date.now()-r.getTime()<50?0:"backoff"}}return{action:"postpone",delay:"backoff"}}function vt(t){let n,a;const{picked:u,rest:s}=function(t,n){const e={},r={};for(const[o,i]of Object.entries(t))n.includes(o)?e[o]=i:r[o]=i;return{picked:e,rest:r}}(t,["apiKey","region"]),{apiKey:l,region:p}=u,h=d(t,"endpoints");if(!function(t,n){return!(void 0!==t&&"string"!=typeof t&&!f(t))||(Array.isArray(t)?t.every((t=>"string"==typeof t)):!(!x(t)||!t.type||t.type!==n))}(h,wt))throw new c(i[r],r);const[w,y]=function(){const t=[],n=()=>{t.push({time:new Date,state:document.visibilityState})},e=function(t,n,e,r){return t.addEventListener(n,e,r),()=>t.removeEventListener(n,e,r)}(document,"visibilitychange",n);return n(),[t,e]}();const m=async function(){try{if(!l||"string"!=typeof l)throw new Error("API key not provided");const t=function(t,n,e){const{script:r}=function(t,n,e=ht(1)){return r=$,o=t,i={region:n,host:e,protocol:ht(2)},r(o,i,!0);var r,o,i}(t,e||"us"),o=null==r?void 0:r.map((t=>function(t,n){const e=new URL(t,window.location.href),r=e.pathname,o="4";return e.pathname=`${r}${r.endsWith("/")?"":"/"}v${o}/${encodeURIComponent(n)}`,e.search=`?ci=jsl/${encodeURIComponent(O)}`,e.href}(t,n)));return o||[]}(h,l,p),[e,r]=await function(t,n){if(0===t.length)return Promise.reject(new TypeError("The list of script URL patterns is empty"));const e=[],r=yt(t,(async t=>{const r=new Date;try{const o=await n(t);return e.push({url:t,startedAt:r,finishedAt:new Date,error:void 0}),o}catch(n){throw e.push({url:t,startedAt:r,finishedAt:new Date,error:n}),n}}),(t=>({result:t})),gt,{maxAttemptCount:5,backoffBase:100,backoffCap:3e3});return new Promise(((t,n)=>{Promise.resolve(r).then((r=>{if(void 0!==r.result)t([r.result,e]);else{const t=r.failedAttempts[0];n(t?t.error:new Error("No attempts were made"))}})).catch(n)}))}(t,bt),o=await e.start({...s,ldi:{attempts:r,visibilityStates:w}});return n=o,o}catch(t){throw a=function(t){if(t instanceof c&&t.code===o)return new c(i[e],e);return t}(t),a}finally{y()}}();return{async get(t){if(n)return n.get(t);if(a)throw a;return(await m).get(t)},async collect(t){if(n)return n.collect(t);if(a)throw a;return(await m).collect(t)}}}function bt(r){return M(r,(async()=>{if(v(r))throw new c(i[n],n);try{return await import(/* webpackIgnore: true */r)}catch(t){throw new c(i[e],e)}}),(()=>{throw new c(i[t],t)})).then((t=>{if("function"!=typeof(null==t?void 0:t.start))throw new c(i[o],o);return t}))}var At={start:vt,isFingerprintError:a,withoutDefault:s};export{At as default,a as isFingerprintError,vt as start,s as withoutDefault};
|