@fingerprint/agent 4.0.0-beta.0 → 4.0.0-beta.3

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.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
2
+ * Fingerprint v4.0.0-beta.3 - 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(p(t))return!0;throw t}}function p(t){return t instanceof Error&&"TypeError"===t.name}function d(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"};class A extends Error{constructor(t,e){super(t),this.name="FingerprintError",this.event_id=null,this.code=e}}function _(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}var k="4.0.0-beta.0";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),p=(d=[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(d.filter((t=>!!t)))).then((()=>u));var d;return{then:p.then.bind(p),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 p=o(e,f,l);if(!p)break;await u(s(p[1]),c),a=p[0]}}function $(t,e,n){const r=n instanceof A?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=()=>(p(),i[c]===L?s():P(i[c])?u():d(X)?(c+=X.length,null):d(Y)?(c+=Y.length,!0):d(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(p(),i[c]===G){c++;break}if(t.length){if(i[c]!==j)return h();c++}t.push(a())}return t},l=()=>{const t={};let e=!0;for(c++;;){if(p(),i[c]===V){c++;break}if(!e){if(i[c]!==j)return h();c++,p()}if(i[c]!==L)return h();const n=s();if(p(),i[c]!==R)return h();c++,Object.defineProperty(t,n,{value:a(),configurable:!0,enumerable:!0,writable:!0}),e=!1}return t},p=()=>{for(;i[c]===S||i[c]===I||i[c]===O||i[c]===M;)c++},d=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 p(),void 0!==i[c]&&h(),w}function P(t){return t>=B&&t<B+10||t===J}const L=34,j=44,R=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://procdn.fpjs.sh/",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))pt(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):pt(i,[{defaultUrl:t,output:r}]),pt(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=dt(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 pt(t,e,n=!1){var r;if(t===ct){for(const t of e)t.output.push(t.defaultUrl);return}n&&(t=d(t));const o=dt(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 dt(t,e){const{location:n,URL:r}=window;try{return new r(t,n.href)}catch(n){if(p(n))return console.warn(`Ignoring an invalid ${e} ${JSON.stringify(t)}`),null;throw n}}function ht(t,e,n){const r=d(t);e.push(n(h(r)))}function wt(t,e){return t===ct?e:t}var yt=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),p=new Uint8Array(l);for(let t=0;t<p.length;++t)p[t]=c[f+t]^c[u+t%r];return l}(new Uint32Array(e),[],n))}(e,n)),i(r[c]))}([439367991,3755695058,2994309441,699872689,2637020853,582660409,4260854182,3090456625,1039937467,4231181739,1845343016,2880386032,2256118065],5);const mt=yt(0);function gt(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,mt))throw new A(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=yt(1)){return r=at,o=t,i={region:e,host:n,protocol:yt(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,vt),o=await e.start({...i,ldi:{attempts:r,visibilityStates:u}});return n=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(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 vt(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 bt={start:gt,isFingerprintError:_,withoutDefault:rt};exports.default=bt,exports.isFingerprintError=_,exports.start=gt,exports.withoutDefault=rt;
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;
package/dist/fp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Fingerprint v4.0.0-beta.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
2
+ * Fingerprint v4.0.0-beta.3 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
3
3
  */
4
4
 
5
5
  declare const ERROR_CODE_CLIENT_TIMEOUT: "client_timeout";
@@ -17,6 +17,7 @@ declare const ERROR_CODE_CACHE_MISCONFIGURED: "cache_misconfigured";
17
17
  declare const ERROR_CODE_ENDPOINTS_MISCONFIGURED: "endpoints_misconfigured";
18
18
  declare const ERROR_CODE_WRONG_WORKER_OPTION: "wrong_worker_option";
19
19
  declare const ERROR_CODE_WORKER_INITIALIZATION_FAILED: "worker_initialization_failed";
20
+ declare const ERROR_CODE_SANDBOXED_IFRAME: "sandboxed_iframe";
20
21
  /**
21
22
  * Error code for cases when the script is loaded and executed, but the agent bundle variable is not defined.
22
23
  * Means that the URL of a wrong script is given.
@@ -39,7 +40,7 @@ declare const ERROR_CODE_FAILED: "failed";
39
40
  declare const ERROR_CODE_EVENT_NOT_FOUND: "event_not_found";
40
41
  declare const ERROR_CODE_MISSING_MODULE: "missing_module";
41
42
  declare const ERROR_CODE_PAYLOAD_TOO_LARGE: "payload_too_large";
42
- type ApiErrorCode = typeof ERROR_CODE_REQUEST_CANNOT_BE_PARSED | typeof ERROR_CODE_SECRET_API_KEY_REQUIRED | typeof ERROR_CODE_SECRET_API_KEY_NOT_FOUND | typeof ERROR_CODE_PUBLIC_API_KEY_REQUIRED | typeof ERROR_CODE_PUBLIC_API_KEY_NOT_FOUND | typeof ERROR_CODE_SUBSCRIPTION_NOT_ACTIVE | typeof ERROR_CODE_WRONG_REGION | typeof ERROR_CODE_FEATURE_NOT_ENABLED | typeof ERROR_CODE_REQUEST_NOT_FOUND | typeof ERROR_CODE_VISITOR_NOT_FOUND | typeof ERROR_CODE_TOO_MANY_REQUESTS | typeof ERROR_CODE_STATE_NOT_READY | typeof ERROR_CODE_FAILED | typeof ERROR_CODE_EVENT_NOT_FOUND | typeof ERROR_CODE_MISSING_MODULE | typeof ERROR_CODE_PAYLOAD_TOO_LARGE;
43
+ type ApiErrorCode = typeof ERROR_CODE_REQUEST_CANNOT_BE_PARSED | typeof ERROR_CODE_SECRET_API_KEY_REQUIRED | typeof ERROR_CODE_SECRET_API_KEY_NOT_FOUND | typeof ERROR_CODE_PUBLIC_API_KEY_REQUIRED | typeof ERROR_CODE_PUBLIC_API_KEY_NOT_FOUND | typeof ERROR_CODE_SUBSCRIPTION_NOT_ACTIVE | typeof ERROR_CODE_WRONG_REGION | typeof ERROR_CODE_FEATURE_NOT_ENABLED | typeof ERROR_CODE_REQUEST_NOT_FOUND | typeof ERROR_CODE_VISITOR_NOT_FOUND | typeof ERROR_CODE_TOO_MANY_REQUESTS | typeof ERROR_CODE_STATE_NOT_READY | typeof ERROR_CODE_FAILED | typeof ERROR_CODE_EVENT_NOT_FOUND | typeof ERROR_CODE_MISSING_MODULE | typeof ERROR_CODE_PAYLOAD_TOO_LARGE | typeof ERROR_CODE_SANDBOXED_IFRAME;
43
44
  type FingerprintErrorCode = typeof ERROR_CODE_CLIENT_TIMEOUT | typeof ERROR_CODE_NETWORK_CONNECTION | typeof ERROR_CODE_NETWORK_ABORT | typeof ERROR_CODE_CSP_BLOCK | typeof ERROR_CODE_INVALID_ENDPOINT | typeof ERROR_CODE_HANDLE_AGENT_DATA | typeof ERROR_CODE_SCRIPT_LOAD_FAIL | typeof ERROR_CODE_BUNDLE_NOT_DEFINED | typeof ERROR_CODE_BAD_RESPONSE_FORMAT | typeof ERROR_CODE_SERVER_ERROR | typeof ERROR_CODE_API_KEY_MISSING | typeof ERROR_CODE_API_KEY_INVALID | typeof ERROR_CODE_CACHE_MISCONFIGURED | typeof ERROR_CODE_ENDPOINTS_MISCONFIGURED | typeof ERROR_CODE_WRONG_WORKER_OPTION | typeof ERROR_CODE_WORKER_INITIALIZATION_FAILED | ApiErrorCode;
44
45
  /**
45
46
  * Expected error thrown by JS Agent
@@ -64,9 +65,10 @@ interface BinaryOutput {
64
65
 
65
66
  type PublicGetResult = {
66
67
  /**
67
- * Whether the result was obtained from the cache (instead of requesting from Fingerprint backend)
68
+ * Whether the result was obtained from the cache (instead of requesting from Fingerprint backend).
69
+ * This field is only present when caching is enabled.
68
70
  */
69
- cache_hit: boolean;
71
+ cache_hit?: boolean;
70
72
  /**
71
73
  * A unique id associated with the successful request.
72
74
  */
@@ -139,9 +141,9 @@ type Endpoint = EndpointUrl | WithoutDefault<EndpointUrl>;
139
141
  */
140
142
  type Endpoints = Endpoint;
141
143
  /**
142
- * Cache configuration. `false` means that the cache is disabled.
144
+ * Cache configuration. Omit this property to disable caching.
143
145
  */
144
- type CacheConfig = false | {
146
+ type CacheConfig = {
145
147
  storage: `${CacheLocation}`;
146
148
  duration: `${CacheDuration}` | number;
147
149
  cachePrefix?: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Fingerprint v4.0.0-beta.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
2
+ * Fingerprint v4.0.0-beta.3 - 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"};class A extends Error{constructor(t,n){super(t),this.name="FingerprintError",this.event_id=null,this.code=n}}function k(t){return null!==t&&"object"==typeof t&&"name"in t&&"FingerprintError"===t.name&&"code"in t}var _="4.0.0-beta.0";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 C(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 x(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){x(o,t);continue}return h()}if(void 0===i[c])return h();x(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]!==j)return h();c++,Object.defineProperty(t,e,{value:a(),configurable:!0,enumerable:!0,writable:!0}),n=!1}return t},d=()=>{for(;i[c]===S||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,j=58,S=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://procdn.fpjs.sh/",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=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=p(t);n.push(e(h(r)))}function wt(t,n){return t===ct?n:t}var yt=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]))}([439367991,3755695058,2994309441,699872689,2637020853,582660409,4260854182,3090456625,1039937467,4231181739,1845343016,2880386032,2256118065],5);const mt=yt(0);function gt(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,mt))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=yt(1)){return r=at,o=t,i={region:n,host:e,protocol:yt(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(_)}`,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})),C,{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,vt),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 vt(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 bt={start:gt,isFingerprintError:k,withoutDefault:rt};export{bt as default,k as isFingerprintError,gt as start,rt as withoutDefault};
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};
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.0",
4
+ "version": "4.0.0-beta.3",
5
5
  "keywords": [
6
6
  "browser",
7
7
  "fingerprint",