@fingerprint/agent 4.0.0-beta.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.
- package/LICENSE +4 -0
- package/README.md +85 -0
- package/dist/fp.cjs.min.js +5 -0
- package/dist/fp.d.ts +290 -0
- package/dist/fp.esm.min.js +5 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
This package is licensed according to the Terms of Service available here: https://dev.fingerprint.com/docs/terms-of-service.
|
|
2
|
+
Additionally your usage of this package may be licensed by the enterprise SaaS agreement with FingerprintJS, Inc, available to the enterprise customers.
|
|
3
|
+
For all licensing questions contact support@fingerprint.com
|
|
4
|
+
Copyright FingerprintJS, Inc 2025 (c)
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<br>
|
|
3
|
+
<a href="https://fingerprint.com">
|
|
4
|
+
<picture>
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://fingerprintjs.github.io/home/resources/logo_light.svg" />
|
|
6
|
+
<source media="(prefers-color-scheme: light)" srcset="https://fingerprintjs.github.io/home/resources/logo_dark.svg" />
|
|
7
|
+
<img src="https://fingerprintjs.github.io/home/resources/logo_dark.svg" alt="Fingerprint logo" width="312px" />
|
|
8
|
+
</picture>
|
|
9
|
+
</a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
Makes a website visitor identifier from a browser fingerprint.
|
|
13
|
+
Unlike cookies and local storage, fingerprint stays the same in incognito/private mode and even when browser data is purged.
|
|
14
|
+
Provides additional information and higher accuracy compared to Open Source FingerprintJS.
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
Get a pro key:
|
|
19
|
+
|
|
20
|
+
1. Register a new PRO account at [dashboard.fingerprint.com/signup](https://dashboard.fingerprint.com/signup) (there is a free trial)
|
|
21
|
+
2. After registration go to the [dashboard](https://dashboard.fingerprint.com) and select the created subscription
|
|
22
|
+
3. Go the "API Keys" page in the navigation side bar on the left side of the page
|
|
23
|
+
4. Copy a key with type "Public"
|
|
24
|
+
|
|
25
|
+
### Install from NPM
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm i @fingerprint/agent
|
|
29
|
+
# or
|
|
30
|
+
yarn add @fingerprint/agent
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import Fingerprint from '@fingerprint/agent'
|
|
35
|
+
|
|
36
|
+
// Initialize an agent at application startup.
|
|
37
|
+
const fpPromise = Fingerprint.start({ apiKey: 'your-pro-key' })
|
|
38
|
+
|
|
39
|
+
;(async () => {
|
|
40
|
+
// Get the visitor identifier when you need it.
|
|
41
|
+
const fp = await fpPromise
|
|
42
|
+
const result = await fp.get()
|
|
43
|
+
|
|
44
|
+
// This is the visitor identifier:
|
|
45
|
+
const visitorId = result.visitorId
|
|
46
|
+
console.log(visitorId)
|
|
47
|
+
})()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
[Run this code](https://stackblitz.com/edit/fpjs-pro-3-npm?file=index.js&devtoolsheight=100)
|
|
51
|
+
|
|
52
|
+
### Alternatively you can install from CDN
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script>
|
|
56
|
+
// Initialize the agent at application startup.
|
|
57
|
+
const fpPromise = import('https://fpjscdn.net/v4/your-pro-key')
|
|
58
|
+
.then(FingerprintJS => FingerprintJS.start())
|
|
59
|
+
|
|
60
|
+
// Get the visitor identifier when you need it.
|
|
61
|
+
fpPromise
|
|
62
|
+
.then(fp => fp.get())
|
|
63
|
+
.then(result => {
|
|
64
|
+
// This is the visitor identifier:
|
|
65
|
+
const visitorId = result.visitorId
|
|
66
|
+
console.log(visitorId)
|
|
67
|
+
})
|
|
68
|
+
</script>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Note that you need to replace `your-pro-key` with a public API key from the [dashboard](https://dashboard.fingerprint.com).
|
|
72
|
+
|
|
73
|
+
[Run this code](https://stackblitz.com/edit/fpjs-pro-3-cdn?file=index.html&devtoolsheight=100)
|
|
74
|
+
|
|
75
|
+
## See also
|
|
76
|
+
|
|
77
|
+
🍿 [Live demo](https://fingerprint.com/demo)
|
|
78
|
+
|
|
79
|
+
⏱ [How to upgrade from Open Source to Pro in 30 seconds](https://dev.fingerprint.com/v3/docs/migrating-from-fingerprintjs-to-fingerprint-pro#migrating-from-fingerprintjs-v3-open-source-to-pro)
|
|
80
|
+
|
|
81
|
+
⬆️ [How to migrate from Fingerprint version 2](https://dev.fingerprint.com/v3/docs/migrating-from-pro-v2)
|
|
82
|
+
|
|
83
|
+
📕 [Fingerprint documentation](https://dev.fingerprint.com)
|
|
84
|
+
|
|
85
|
+
▶️ [Video: use Fingerprint to prevent multiple signups](https://www.youtube.com/watch?v=jWX9P5_jZn8)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fingerprint v4.0.0-beta.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
|
|
3
|
+
*/
|
|
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;
|
package/dist/fp.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fingerprint v4.0.0-beta.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare const ERROR_CODE_CLIENT_TIMEOUT: "client_timeout";
|
|
6
|
+
declare const ERROR_CODE_NETWORK_CONNECTION: "network_connection";
|
|
7
|
+
declare const ERROR_CODE_NETWORK_ABORT: "network_abort";
|
|
8
|
+
declare const ERROR_CODE_CSP_BLOCK: "csp_block";
|
|
9
|
+
declare const ERROR_CODE_INVALID_ENDPOINT: "invalid_endpoint";
|
|
10
|
+
declare const ERROR_CODE_HANDLE_AGENT_DATA: "handle_agent_data";
|
|
11
|
+
declare const ERROR_CODE_SCRIPT_LOAD_FAIL: "script_load_fail";
|
|
12
|
+
declare const ERROR_CODE_BAD_RESPONSE_FORMAT: "bad_response_format";
|
|
13
|
+
declare const ERROR_CODE_SERVER_ERROR: "server_error";
|
|
14
|
+
declare const ERROR_CODE_API_KEY_MISSING: "api_key_missing";
|
|
15
|
+
declare const ERROR_CODE_API_KEY_INVALID: "api_key_invalid";
|
|
16
|
+
declare const ERROR_CODE_CACHE_MISCONFIGURED: "cache_misconfigured";
|
|
17
|
+
declare const ERROR_CODE_ENDPOINTS_MISCONFIGURED: "endpoints_misconfigured";
|
|
18
|
+
declare const ERROR_CODE_WRONG_WORKER_OPTION: "wrong_worker_option";
|
|
19
|
+
declare const ERROR_CODE_WORKER_INITIALIZATION_FAILED: "worker_initialization_failed";
|
|
20
|
+
/**
|
|
21
|
+
* Error code for cases when the script is loaded and executed, but the agent bundle variable is not defined.
|
|
22
|
+
* Means that the URL of a wrong script is given.
|
|
23
|
+
* For internal usage only, mustn't be thrown outside the loader.
|
|
24
|
+
*/
|
|
25
|
+
declare const ERROR_CODE_BUNDLE_NOT_DEFINED: "bundle_not_defined";
|
|
26
|
+
declare const ERROR_CODE_REQUEST_CANNOT_BE_PARSED: "request_cannot_be_parsed";
|
|
27
|
+
declare const ERROR_CODE_SECRET_API_KEY_REQUIRED: "secret_api_key_required";
|
|
28
|
+
declare const ERROR_CODE_SECRET_API_KEY_NOT_FOUND: "secret_api_key_not_found";
|
|
29
|
+
declare const ERROR_CODE_PUBLIC_API_KEY_REQUIRED: "public_api_key_required";
|
|
30
|
+
declare const ERROR_CODE_PUBLIC_API_KEY_NOT_FOUND: "public_api_key_not_found";
|
|
31
|
+
declare const ERROR_CODE_SUBSCRIPTION_NOT_ACTIVE: "subscription_not_active";
|
|
32
|
+
declare const ERROR_CODE_WRONG_REGION: "wrong_region";
|
|
33
|
+
declare const ERROR_CODE_FEATURE_NOT_ENABLED: "feature_not_enabled";
|
|
34
|
+
declare const ERROR_CODE_REQUEST_NOT_FOUND: "request_not_found";
|
|
35
|
+
declare const ERROR_CODE_VISITOR_NOT_FOUND: "visitor_not_found";
|
|
36
|
+
declare const ERROR_CODE_TOO_MANY_REQUESTS: "too_many_requests";
|
|
37
|
+
declare const ERROR_CODE_STATE_NOT_READY: "state_not_ready";
|
|
38
|
+
declare const ERROR_CODE_FAILED: "failed";
|
|
39
|
+
declare const ERROR_CODE_EVENT_NOT_FOUND: "event_not_found";
|
|
40
|
+
declare const ERROR_CODE_MISSING_MODULE: "missing_module";
|
|
41
|
+
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 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
|
+
* Expected error thrown by JS Agent
|
|
46
|
+
*/
|
|
47
|
+
interface FingerprintErrorInterface extends Error {
|
|
48
|
+
name: 'FingerprintError';
|
|
49
|
+
/** A machine-friendly code for the type of this error */
|
|
50
|
+
code: FingerprintErrorCode;
|
|
51
|
+
/** A unique id to refer to the error. Available only for errors originate on the server side. */
|
|
52
|
+
event_id: string | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Type guard to check if an error is a FingerprintError
|
|
56
|
+
*/
|
|
57
|
+
declare function isFingerprintError(error: unknown): error is FingerprintErrorInterface;
|
|
58
|
+
|
|
59
|
+
interface BinaryOutput {
|
|
60
|
+
byteArray(): Uint8Array;
|
|
61
|
+
blob(): Blob;
|
|
62
|
+
base64(): string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type PublicGetResult = {
|
|
66
|
+
/**
|
|
67
|
+
* Whether the result was obtained from the cache (instead of requesting from Fingerprint backend)
|
|
68
|
+
*/
|
|
69
|
+
cache_hit: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* A unique id associated with the successful request.
|
|
72
|
+
*/
|
|
73
|
+
event_id: string;
|
|
74
|
+
/**
|
|
75
|
+
* The visitor identifier.
|
|
76
|
+
* Backend excludes this field if zeroTrust mode is enabled.
|
|
77
|
+
*/
|
|
78
|
+
visitor_id?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Suspect score.
|
|
81
|
+
* Backend includes this field only if Smart Signals are enabled.
|
|
82
|
+
*/
|
|
83
|
+
suspect_score?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Sealed result, which is an encrypted content of the `/events` Server API response for this eventId, encoded in
|
|
86
|
+
* base64. The field will miss if Sealed Results are disabled or unavailable for another reason.
|
|
87
|
+
* Reach the support to enable.
|
|
88
|
+
*/
|
|
89
|
+
sealed_result: BinaryOutput | null;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Result of collecting on demand fingerprint data
|
|
93
|
+
*/
|
|
94
|
+
type CollectResult = string;
|
|
95
|
+
|
|
96
|
+
declare const enum CacheLocation {
|
|
97
|
+
SessionStorage = "sessionStorage",
|
|
98
|
+
LocalStorage = "localStorage",
|
|
99
|
+
Agent = "agent"
|
|
100
|
+
}
|
|
101
|
+
declare const enum CacheDuration {
|
|
102
|
+
OptimizeCost = "optimize-cost",
|
|
103
|
+
Aggressive = "aggressive"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type Region =
|
|
107
|
+
/** N. Virginia, USA */
|
|
108
|
+
'us'
|
|
109
|
+
/** Frankfurt, Germany */
|
|
110
|
+
| 'eu'
|
|
111
|
+
/** Mumbai, India */
|
|
112
|
+
| 'ap';
|
|
113
|
+
declare const withoutDefaultType = "withoutDefault";
|
|
114
|
+
/**
|
|
115
|
+
* This object wraps a parameter to tell JS Agent that you don't want to use the default value.
|
|
116
|
+
* Don't compose it manually, use `withoutDefault` instead.
|
|
117
|
+
*/
|
|
118
|
+
type WithoutDefault<T> = {
|
|
119
|
+
__type__: typeof withoutDefaultType;
|
|
120
|
+
value: T;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* One or many endpoint URLs.
|
|
124
|
+
* If multiple URLs are given, the agent will try them one by one until it finds a working one.
|
|
125
|
+
* If an empty array is given, the agent will throw an error.
|
|
126
|
+
*/
|
|
127
|
+
type EndpointUrl = string | readonly string[];
|
|
128
|
+
/**
|
|
129
|
+
* An endpoint for a specific HTTPS request.
|
|
130
|
+
* If `EndpointUrl` is used, the default URL is used as a fallback.
|
|
131
|
+
* If `WithoutDefault` is used, only the given URL is used.
|
|
132
|
+
*/
|
|
133
|
+
type Endpoint = EndpointUrl | WithoutDefault<EndpointUrl>;
|
|
134
|
+
/**
|
|
135
|
+
* The set of endpoints to use by JS Agent.
|
|
136
|
+
* If a single Endpoint is given, the specific endpoints are derived from it.
|
|
137
|
+
* Otherwise, each endpoint is configured separately; if a specific endpoint is omitted, the default one is used.
|
|
138
|
+
* You most likely need to set just a single endpoint.
|
|
139
|
+
*/
|
|
140
|
+
type Endpoints = Endpoint;
|
|
141
|
+
/**
|
|
142
|
+
* Cache configuration. `false` means that the cache is disabled.
|
|
143
|
+
*/
|
|
144
|
+
type CacheConfig = false | {
|
|
145
|
+
storage: `${CacheLocation}`;
|
|
146
|
+
duration: `${CacheDuration}` | number;
|
|
147
|
+
cachePrefix?: string;
|
|
148
|
+
};
|
|
149
|
+
type UrlHashing = {
|
|
150
|
+
/** Set to `true` to hash the path part of the URL (between the origin and `?`) */
|
|
151
|
+
path?: boolean;
|
|
152
|
+
/** Set to `true` to hash the query part of the URL (between `?` and `#`) */
|
|
153
|
+
query?: boolean;
|
|
154
|
+
/** Set to `true` to hash the fragment part of the URL (after `#`) */
|
|
155
|
+
fragment?: boolean;
|
|
156
|
+
};
|
|
157
|
+
type LoaderStartOptions = {
|
|
158
|
+
/**
|
|
159
|
+
* Public API key
|
|
160
|
+
*/
|
|
161
|
+
apiKey: string;
|
|
162
|
+
/**
|
|
163
|
+
* Region of the Fingerprint service server
|
|
164
|
+
* @default 'us'
|
|
165
|
+
*/
|
|
166
|
+
region?: Region;
|
|
167
|
+
/**
|
|
168
|
+
* API endpoints used by JS Agent
|
|
169
|
+
*/
|
|
170
|
+
endpoints?: Endpoints;
|
|
171
|
+
/**
|
|
172
|
+
* Override storages name (cookies, localStorage, etc).
|
|
173
|
+
* Should only be used when the default name conflicts with some of your existing names.
|
|
174
|
+
* @default '_vid_'
|
|
175
|
+
*/
|
|
176
|
+
storageKeyPrefix?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Information about libraries and services used to integrate the JS agent.
|
|
179
|
+
* Each array item means a separate integration, the order doesn't matter.
|
|
180
|
+
* An example of an integration library is Fingerprint React SDK.
|
|
181
|
+
*/
|
|
182
|
+
integrationInfo?: readonly string[];
|
|
183
|
+
/**
|
|
184
|
+
* Enables data collection for remote control detection.
|
|
185
|
+
* Once enabled, please contact our support team to active the result exposure.
|
|
186
|
+
* @see https://fingerprint.com/support/
|
|
187
|
+
*
|
|
188
|
+
* @default false
|
|
189
|
+
*
|
|
190
|
+
* @see https://dev.fingerprint.com/docs/smart-signals-overview#remote-control-tools-detection
|
|
191
|
+
*/
|
|
192
|
+
remoteControlDetection?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Hashes URL parts before sending them to Fingerprint the server.
|
|
195
|
+
* The sources of URLs: window.location.href, document.referrer.
|
|
196
|
+
* Сan be used to hide sensitive data (tokens, payment info, etc) that these URLs may contain.
|
|
197
|
+
*
|
|
198
|
+
* Example of URL stripping 'https://example.com/path?token=secret#anchor' -> 'https://example.com/oK-fhlv2N-ZzaBf0zlUuTN97jDbqdbwlTB0fCvdEtb8?E1kifZXhuoBEZ_zkQa60jyxcaHNX3QFaydaaIEtL7j0#eb-w4rp2udRHYG3bzElINPBaTBHesFLnS0nqMHo8W80'
|
|
199
|
+
*/
|
|
200
|
+
urlHashing?: UrlHashing;
|
|
201
|
+
/**
|
|
202
|
+
* `get` result cache configuration. By default, the cache is enabled.
|
|
203
|
+
*/
|
|
204
|
+
cache?: CacheConfig;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Options for requesting the visitor information
|
|
208
|
+
*/
|
|
209
|
+
type PublicGetOptions = {
|
|
210
|
+
/**
|
|
211
|
+
* Controls client-side timeout. Client timeout controls total time (both client-side and server-side) that any
|
|
212
|
+
* identification event is allowed to run. It doesn't include time when the page is in background (not visible).
|
|
213
|
+
* The value is in milliseconds.
|
|
214
|
+
* @default 10000
|
|
215
|
+
*/
|
|
216
|
+
timeout?: number;
|
|
217
|
+
/**
|
|
218
|
+
* `Tag` is a user-provided value or object that will be returned back to you in a webhook message.
|
|
219
|
+
* You may want to use the `tag` value to be able to associate a server-side webhook event with a web request of the
|
|
220
|
+
* current visitor.
|
|
221
|
+
*
|
|
222
|
+
* What values can be used as a `tag`?
|
|
223
|
+
* Anything that identifies a visitor or a request.
|
|
224
|
+
* You can pass the event_id as a `tag` and then get this event_id back in the webhook, associated with a visitorId.
|
|
225
|
+
*/
|
|
226
|
+
tag?: unknown;
|
|
227
|
+
/**
|
|
228
|
+
* `linkedId` is a way of linking current identification event with a custom identifier.
|
|
229
|
+
* This can be helpful to be able to filter API visit information later.
|
|
230
|
+
*/
|
|
231
|
+
linkedId?: string;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Options of collecting on demand fingerprint data
|
|
235
|
+
*/
|
|
236
|
+
type PublicCollectOptions = {
|
|
237
|
+
/**
|
|
238
|
+
* Controls client-side timeout. Client timeout controls total time (both client-side and server-side) that any
|
|
239
|
+
* identification event is allowed to run. It doesn't include time when the page is in background (not visible).
|
|
240
|
+
* The value is in milliseconds.
|
|
241
|
+
* @default 10000
|
|
242
|
+
*/
|
|
243
|
+
timeout?: number;
|
|
244
|
+
/**
|
|
245
|
+
* `Tag` is a user-provided value or object that will be returned back to you in a webhook message.
|
|
246
|
+
* You may want to use the `tag` value to be able to associate a server-side webhook event with a web request of the
|
|
247
|
+
* current visitor.
|
|
248
|
+
*
|
|
249
|
+
* What values can be used as a `tag`?
|
|
250
|
+
* Anything that identifies a visitor or a request.
|
|
251
|
+
* You can pass the event_id as a `tag` and then get this `event_id` back in the webhook, associated with a visitorId.
|
|
252
|
+
*/
|
|
253
|
+
tag?: unknown;
|
|
254
|
+
/**
|
|
255
|
+
* `linkedId` is a way of linking current identification event with a custom identifier.
|
|
256
|
+
* This can be helpful to be able to filter API visit information later.
|
|
257
|
+
*/
|
|
258
|
+
linkedId?: string;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Wraps a parameter to tell JS Agent that you don't want to use the default value
|
|
262
|
+
*/
|
|
263
|
+
declare function withoutDefault<T>(value: T): WithoutDefault<T>;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Agent object that can get visitor identifier
|
|
267
|
+
*/
|
|
268
|
+
interface PublicAgent {
|
|
269
|
+
/**
|
|
270
|
+
* Gets the visitor identifier.
|
|
271
|
+
* See the `ERROR_...` constants for expected error messages.
|
|
272
|
+
* When an error is emitted by the backend, it gets a `event_id` field, same as in successful result.
|
|
273
|
+
*/
|
|
274
|
+
get(options?: Readonly<PublicGetOptions>): Promise<PublicGetResult>;
|
|
275
|
+
/**
|
|
276
|
+
* Collects on demand fingerprint data.
|
|
277
|
+
*/
|
|
278
|
+
collect(options?: Readonly<PublicCollectOptions>): Promise<CollectResult>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
type StartOptions = LoaderStartOptions;
|
|
282
|
+
declare function start(options: StartOptions): PublicAgent;
|
|
283
|
+
|
|
284
|
+
declare const _default: {
|
|
285
|
+
start: typeof start;
|
|
286
|
+
isFingerprintError: typeof isFingerprintError;
|
|
287
|
+
withoutDefault: typeof withoutDefault;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export { type PublicAgent as Agent, type FingerprintErrorInterface as Error, type FingerprintErrorCode as ErrorCode, type PublicGetOptions as GetOptions, type PublicGetResult as GetResult, type StartOptions, _default as default, isFingerprintError, start, withoutDefault };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fingerprint v4.0.0-beta.0 - Copyright (c) FingerprintJS, Inc, 2025 (https://fingerprint.com)
|
|
3
|
+
*/
|
|
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};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fingerprint/agent",
|
|
3
|
+
"description": "Fingerprint JavaScript agent",
|
|
4
|
+
"version": "4.0.0-beta.0",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"browser",
|
|
7
|
+
"fingerprint",
|
|
8
|
+
"identification",
|
|
9
|
+
"fraud detection",
|
|
10
|
+
"browser fingerprint",
|
|
11
|
+
"device fingerprint"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://fingerprint.com",
|
|
14
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"email": "support@fingerprint.com"
|
|
17
|
+
},
|
|
18
|
+
"main": "dist/fp.cjs.min.js",
|
|
19
|
+
"module": "dist/fp.esm.min.js",
|
|
20
|
+
"types": "dist/fp.d.ts",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prepack": "cp ../../LICENSE ./LICENSE",
|
|
27
|
+
"build": "rimraf dist && rimraf tests/dist && yarn build:index && yarn build:mock-cdn && yarn build:ts",
|
|
28
|
+
"build:index": "ts-node ./resources/build_index.ts",
|
|
29
|
+
"build:mock-cdn": "ts-node ./resources/build_mock_cdn.ts",
|
|
30
|
+
"build:ts": "rollup -c rollup.config.ts --configPlugin \"@rollup/plugin-typescript={tsconfig:'tsconfig.rollupConfig.json',include:[/\\.ts$/i]}\""
|
|
31
|
+
}
|
|
32
|
+
}
|