@thumbmarkjs/thumbmarkjs 1.0.0-rc.0 → 1.0.0-rc.2
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/README.md +45 -47
- package/dist/thumbmark.cjs.js +1 -1
- package/dist/thumbmark.cjs.js.map +1 -1
- package/dist/thumbmark.esm.d.ts +0 -3
- package/dist/thumbmark.esm.js +1 -1
- package/dist/thumbmark.esm.js.map +1 -1
- package/dist/thumbmark.umd.js +1 -1
- package/dist/thumbmark.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/audio/index.ts +1 -1
- package/src/components/canvas/index.ts +1 -1
- package/src/components/fonts/index.ts +1 -1
- package/src/components/permissions/index.ts +27 -33
- package/src/factory.ts +1 -1
- package/src/{utils → functions}/filterComponents.ts +1 -1
- package/src/{fingerprint → functions}/functions.test.ts +1 -1
- package/src/{fingerprint/functions.ts → functions/index.ts} +22 -8
- package/src/{fingerprint → functions}/legacy_functions.ts +2 -2
- package/src/index.ts +3 -3
- package/src/{fingerprint/options.ts → options.ts} +2 -5
- package/src/thumbmark.ts +3 -3
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// ===================== Imports =====================
|
|
18
|
-
import { defaultOptions, optionsInterface } from "
|
|
18
|
+
import { defaultOptions, optionsInterface } from "../options";
|
|
19
19
|
import {
|
|
20
20
|
timeoutInstance,
|
|
21
21
|
componentInterface,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import { hash } from "../utils/hash";
|
|
27
27
|
import { raceAllPerformance } from "../utils/raceAll";
|
|
28
28
|
import * as packageJson from '../../package.json';
|
|
29
|
-
import { filterThumbmarkData } from '
|
|
29
|
+
import { filterThumbmarkData } from './filterComponents'
|
|
30
30
|
|
|
31
31
|
// ===================== Types & Interfaces =====================
|
|
32
32
|
|
|
@@ -48,7 +48,8 @@ interface infoInterface {
|
|
|
48
48
|
},
|
|
49
49
|
uniqueness?: {
|
|
50
50
|
score: number | string
|
|
51
|
-
}
|
|
51
|
+
},
|
|
52
|
+
timed_out?: boolean; // added for timeout handling
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
@@ -106,9 +107,9 @@ export const getApiPromise = (
|
|
|
106
107
|
return currentApiPromise;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
// 3. Otherwise, initiate a new API call.
|
|
110
|
-
const endpoint = 'https://api
|
|
111
|
-
|
|
110
|
+
// 3. Otherwise, initiate a new API call with timeout.
|
|
111
|
+
const endpoint = 'https://api.thumbmarkjs.com/thumbmark';
|
|
112
|
+
const fetchPromise = fetch(endpoint, {
|
|
112
113
|
method: 'POST',
|
|
113
114
|
headers: {
|
|
114
115
|
'x-api-key': options.api_key!,
|
|
@@ -135,6 +136,19 @@ export const getApiPromise = (
|
|
|
135
136
|
return null;
|
|
136
137
|
});
|
|
137
138
|
|
|
139
|
+
// Timeout logic
|
|
140
|
+
const timeoutMs = options.timeout || 5000;
|
|
141
|
+
const timeoutPromise = new Promise<apiResponse>((resolve) => {
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
resolve({
|
|
144
|
+
thumbmark: hash(JSON.stringify(components)),
|
|
145
|
+
info: { timed_out: true },
|
|
146
|
+
version: packageJson.version,
|
|
147
|
+
});
|
|
148
|
+
}, timeoutMs);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
currentApiPromise = Promise.race([fetchPromise, timeoutPromise]);
|
|
138
152
|
return currentApiPromise;
|
|
139
153
|
};
|
|
140
154
|
|
|
@@ -201,8 +215,8 @@ export async function resolveClientComponents(
|
|
|
201
215
|
: opts?.include?.length === 0 || opts?.include?.includes(key)
|
|
202
216
|
);
|
|
203
217
|
const keys = filtered.map(([key]) => key);
|
|
204
|
-
const promises = filtered.map(([_, fn]) => fn());
|
|
205
|
-
const resolvedValues = await raceAllPerformance(promises, opts?.timeout ||
|
|
218
|
+
const promises = filtered.map(([_, fn]) => fn(options));
|
|
219
|
+
const resolvedValues = await raceAllPerformance(promises, opts?.timeout || 5000, timeoutInstance);
|
|
206
220
|
|
|
207
221
|
const elapsed: Record<string, number> = {};
|
|
208
222
|
const resolvedComponentsRaw: Record<string, componentInterface> = {};
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { componentInterface } from '../factory'
|
|
7
|
-
import { options} from '
|
|
8
|
-
import { resolveClientComponents, getThumbmark } from '
|
|
7
|
+
import { options} from '../options'
|
|
8
|
+
import { resolveClientComponents, getThumbmark } from '.';
|
|
9
9
|
import { tm_component_promises } from "../factory";
|
|
10
10
|
|
|
11
11
|
/**
|
package/src/index.ts
CHANGED
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
getFingerprint,
|
|
3
3
|
getFingerprintData,
|
|
4
4
|
getFingerprintPerformance
|
|
5
|
-
} from './
|
|
6
|
-
import { getThumbmark, getVersion } from './
|
|
7
|
-
import { setOption } from './
|
|
5
|
+
} from './functions/legacy_functions'
|
|
6
|
+
import { getThumbmark, getVersion } from './functions'
|
|
7
|
+
import { setOption } from './options'
|
|
8
8
|
import { includeComponent } from './factory'
|
|
9
9
|
import { Thumbmark } from './thumbmark'
|
|
10
10
|
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export interface optionsInterface {
|
|
2
2
|
exclude?: string[],
|
|
3
3
|
include?: string[],
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
permissions_to_check?: PermissionName[], // new option
|
|
7
|
-
retries?: number, // new option
|
|
8
|
-
timeout?: number, // new option
|
|
4
|
+
permissions_to_check?: PermissionName[],
|
|
5
|
+
timeout?: number,
|
|
9
6
|
logging?: boolean,
|
|
10
7
|
api_key?: string,
|
|
11
8
|
cache_api_call?: boolean,
|
package/src/thumbmark.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { optionsInterface } from "./
|
|
2
|
-
import { getThumbmark, getVersion, includeComponent as globalIncludeComponent } from './
|
|
3
|
-
import { defaultOptions } from "./
|
|
1
|
+
import { optionsInterface } from "./options";
|
|
2
|
+
import { getThumbmark, getVersion, includeComponent as globalIncludeComponent } from './functions';
|
|
3
|
+
import { defaultOptions } from "./options";
|
|
4
4
|
import { componentInterface } from "./factory";
|
|
5
5
|
|
|
6
6
|
/**
|