@fingerprint/agent 4.0.0-beta.5 → 4.0.0

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Fingerprint v4.0.0-beta.5 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
2
+ * Fingerprint v4.0.0 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
3
3
  */
4
4
 
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;
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=Symbol("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=S((()=>_(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=S((()=>_(t)));e.push(n(A(r)))}function R(t,e){return t===U?e:t}function S(t){try{return t()}catch(t){if(b(t))throw new c(i[e],e);throw t}}function j(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";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(j(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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Fingerprint v4.0.0-beta.5 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
2
+ * Fingerprint v4.0.0 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
3
3
  */
4
4
 
5
5
  declare const ERROR_CODE_CLIENT_TIMEOUT: "client_timeout";
@@ -112,36 +112,31 @@ type Region =
112
112
  | 'eu'
113
113
  /** Mumbai, India */
114
114
  | 'ap';
115
- declare const withoutDefaultType = "withoutDefault";
115
+ declare const withoutDefaultType: unique symbol;
116
116
  /**
117
117
  * This object wraps a parameter to tell JS Agent that you don't want to use the default value.
118
118
  * Don't compose it manually, use `withoutDefault` instead.
119
119
  */
120
120
  type WithoutDefault<T> = {
121
- __type__: typeof withoutDefaultType;
122
- value: T;
121
+ readonly __type__: typeof withoutDefaultType;
122
+ readonly value: T;
123
123
  };
124
124
  /**
125
125
  * One or many endpoint URLs.
126
126
  * If multiple URLs are given, the agent will try them one by one until it finds a working one.
127
- * If an empty array is given, the agent will throw an error.
127
+ * If an empty array is given, the agent will use default fallback value.
128
128
  */
129
129
  type EndpointUrl = string | readonly string[];
130
130
  /**
131
131
  * An endpoint for a specific HTTPS request.
132
- * If `EndpointUrl` is used, the default URL is used as a fallback.
133
- * If `WithoutDefault` is used, only the given URL is used.
132
+ * - Passing an `EndpointUrl` uses that URL, with the default still available as a fallback.
133
+ * - Wrapping with `withoutDefault(...)` disables fallback and uses only the provided value.
134
134
  */
135
135
  type Endpoint = EndpointUrl | WithoutDefault<EndpointUrl>;
136
136
  /**
137
- * The set of endpoints to use by JS Agent.
138
- * If a single Endpoint is given, the specific endpoints are derived from it.
139
- * Otherwise, each endpoint is configured separately; if a specific endpoint is omitted, the default one is used.
140
- * You most likely need to set just a single endpoint.
141
- */
142
- type Endpoints = Endpoint;
143
- /**
144
- * Cache configuration. Omit this property to disable caching.
137
+ * Configuration for caching agent results.
138
+ * Specified via the `cache` option in `LoaderStartOptions`.
139
+ * Disabled by default when not provided.
145
140
  */
146
141
  type CacheConfig = {
147
142
  storage: `${CacheLocation}`;
@@ -169,7 +164,7 @@ type LoaderStartOptions = {
169
164
  /**
170
165
  * API endpoints used by JS Agent
171
166
  */
172
- endpoints?: Endpoints;
167
+ endpoints?: Endpoint;
173
168
  /**
174
169
  * Override storages name (cookies, localStorage, etc).
175
170
  * Should only be used when the default name conflicts with some of your existing names.
@@ -184,7 +179,7 @@ type LoaderStartOptions = {
184
179
  integrationInfo?: readonly string[];
185
180
  /**
186
181
  * Enables data collection for remote control detection.
187
- * Once enabled, please contact our support team to active the result exposure.
182
+ * Once enabled, please contact our support team to activate the result exposure.
188
183
  * @see https://fingerprint.com/support/
189
184
  *
190
185
  * @default false
@@ -201,7 +196,10 @@ type LoaderStartOptions = {
201
196
  */
202
197
  urlHashing?: UrlHashing;
203
198
  /**
204
- * `get` result cache configuration. By default, the cache is enabled.
199
+ * Enables caching the result of the `get` call.
200
+ * Has no default value and cache is not being used if not specified.
201
+ * @see CacheConfig for details.
202
+ * @default: undefined - caching is disabled
205
203
  */
206
204
  cache?: CacheConfig;
207
205
  };
@@ -235,30 +233,7 @@ type PublicGetOptions = {
235
233
  /**
236
234
  * Options of collecting on demand fingerprint data
237
235
  */
238
- type PublicCollectOptions = {
239
- /**
240
- * Controls client-side timeout. Client timeout controls total time (both client-side and server-side) that any
241
- * identification event is allowed to run. It doesn't include time when the page is in background (not visible).
242
- * The value is in milliseconds.
243
- * @default 10000
244
- */
245
- timeout?: number;
246
- /**
247
- * `Tag` is a user-provided value or object that will be returned back to you in a webhook message.
248
- * You may want to use the `tag` value to be able to associate a server-side webhook event with a web request of the
249
- * current visitor.
250
- *
251
- * What values can be used as a `tag`?
252
- * Anything that identifies a visitor or a request.
253
- * You can pass the event_id as a `tag` and then get this `event_id` back in the webhook, associated with a visitorId.
254
- */
255
- tag?: unknown;
256
- /**
257
- * `linkedId` is a way of linking current identification event with a custom identifier.
258
- * This can be helpful to be able to filter API visit information later.
259
- */
260
- linkedId?: string;
261
- };
236
+ type PublicCollectOptions = PublicGetOptions;
262
237
  /**
263
238
  * Wraps a parameter to tell JS Agent that you don't want to use the default value
264
239
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Fingerprint v4.0.0-beta.5 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
2
+ * Fingerprint v4.0.0 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
3
3
  */
4
4
 
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};
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=/*#__PURE__*/Symbol("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";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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fingerprint/agent",
3
3
  "description": "Fingerprint JavaScript agent",
4
- "version": "4.0.0-beta.5",
4
+ "version": "4.0.0",
5
5
  "keywords": [
6
6
  "browser",
7
7
  "fingerprint",