@fingerprint/node-sdk 7.0.0-test.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/dist/index.mjs ADDED
@@ -0,0 +1,587 @@
1
+ /**
2
+ * Fingerprint Server Node.js SDK v7.0.0-test.0 - Copyright (c) FingerprintJS, Inc, 2026 (https://fingerprint.com)
3
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
4
+ */
5
+
6
+ import crypto, { createDecipheriv } from 'crypto';
7
+ import { inflateRaw } from 'zlib';
8
+ import { promisify } from 'util';
9
+ import { Buffer } from 'buffer';
10
+
11
+ var Region;
12
+ (function (Region) {
13
+ Region["EU"] = "EU";
14
+ Region["AP"] = "AP";
15
+ Region["Global"] = "Global";
16
+ })(Region || (Region = {}));
17
+
18
+ var version = "7.0.0-test.0";
19
+
20
+ const apiVersion = 'v4';
21
+ const euRegionUrl = 'https://eu.api.fpjs.io/';
22
+ const apRegionUrl = 'https://ap.api.fpjs.io/';
23
+ const globalRegionUrl = 'https://api.fpjs.io/';
24
+ function getIntegrationInfo() {
25
+ return `fingerprint-pro-server-node-sdk/${version}`;
26
+ }
27
+ function serializeQueryStringParams(params) {
28
+ const entries = [];
29
+ for (const [key, value] of Object.entries(params)) {
30
+ if (value == null) {
31
+ continue;
32
+ }
33
+ if (Array.isArray(value)) {
34
+ for (const v of value) {
35
+ if (v == null) {
36
+ continue;
37
+ }
38
+ entries.push([key, String(v)]);
39
+ }
40
+ }
41
+ else {
42
+ entries.push([key, String(value)]);
43
+ }
44
+ }
45
+ const urlSearchParams = new URLSearchParams(entries);
46
+ return urlSearchParams.toString();
47
+ }
48
+ function getServerApiUrl(region) {
49
+ switch (region) {
50
+ case Region.EU:
51
+ return euRegionUrl;
52
+ case Region.AP:
53
+ return apRegionUrl;
54
+ case Region.Global:
55
+ return globalRegionUrl;
56
+ default:
57
+ throw new Error('Unsupported region');
58
+ }
59
+ }
60
+ /**
61
+ * Formats a URL for the FingerprintJS server API by replacing placeholders and
62
+ * appending query string parameters.
63
+ *
64
+ * @internal
65
+ *
66
+ * @param {GetRequestPathOptions<Path, Method>} options
67
+ * @param {Path} options.path - The path of the API endpoint
68
+ * @param {string[]} [options.pathParams] - Path parameters to be replaced in the path
69
+ * @param {QueryParams<Path, Method>["queryParams"]} [options.queryParams] - Query string
70
+ * parameters to be appended to the URL
71
+ * @param {Region} options.region - The region of the API endpoint
72
+ * @param {Method} options.method - The method of the API endpoint
73
+ *
74
+ * @returns {string} The formatted URL with parameters replaced and query string
75
+ * parameters appended
76
+ */
77
+ function getRequestPath({ path, pathParams, queryParams, region,
78
+ // method mention here so that it can be referenced in JSDoc
79
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
80
+ method: _, }) {
81
+ // Step 1: Extract the path parameters (placeholders) from the path
82
+ const placeholders = Array.from(path.matchAll(/{(.*?)}/g)).map((match) => match[1]);
83
+ // Step 2: Replace the placeholders with provided pathParams
84
+ let formattedPath = `${apiVersion}${path}`;
85
+ placeholders.forEach((placeholder, index) => {
86
+ if (pathParams?.[index]) {
87
+ formattedPath = formattedPath.replace(`{${placeholder}}`, pathParams[index]);
88
+ }
89
+ else {
90
+ throw new Error(`Missing path parameter for ${placeholder}`);
91
+ }
92
+ });
93
+ const queryStringParameters = {
94
+ ...(queryParams ?? {}),
95
+ ii: getIntegrationInfo(),
96
+ };
97
+ const url = new URL(getServerApiUrl(region ?? Region.Global));
98
+ url.pathname = formattedPath;
99
+ url.search = serializeQueryStringParams(queryStringParameters);
100
+ return url.toString();
101
+ }
102
+
103
+ class SdkError extends Error {
104
+ response;
105
+ constructor(message, response, cause) {
106
+ super(message, { cause });
107
+ this.response = response;
108
+ this.name = this.constructor.name;
109
+ }
110
+ }
111
+ class RequestError extends SdkError {
112
+ // HTTP Status code
113
+ statusCode;
114
+ // API error code
115
+ errorCode;
116
+ // API error response
117
+ responseBody;
118
+ // Raw HTTP response
119
+ response;
120
+ constructor(message, body, statusCode, errorCode, response) {
121
+ super(message, response);
122
+ this.responseBody = body;
123
+ this.response = response;
124
+ this.errorCode = errorCode;
125
+ this.statusCode = statusCode;
126
+ }
127
+ static unknown(response) {
128
+ return new RequestError('Unknown error', undefined, response.status, response.statusText, response);
129
+ }
130
+ static fromErrorResponse(body, response) {
131
+ return new RequestError(body.error.message, body, response.status, body.error.code, response);
132
+ }
133
+ }
134
+ /**
135
+ * Error that indicate that the request was throttled.
136
+ * */
137
+ class TooManyRequestsError extends RequestError {
138
+ constructor(body, response) {
139
+ super(body.error.message, body, 429, body.error.code, response);
140
+ }
141
+ }
142
+
143
+ function isErrorResponse(value) {
144
+ return Boolean(value &&
145
+ typeof value === 'object' &&
146
+ 'error' in value &&
147
+ typeof value.error === 'object' &&
148
+ value.error &&
149
+ 'code' in value.error &&
150
+ 'message' in value.error);
151
+ }
152
+
153
+ function toError(e) {
154
+ if (e && typeof e === 'object' && 'message' in e) {
155
+ return e;
156
+ }
157
+ return new Error(String(e));
158
+ }
159
+
160
+ class FingerprintServerApiClient {
161
+ region;
162
+ apiKey;
163
+ fetch;
164
+ defaultHeaders;
165
+ /**
166
+ * FingerprintJS server API client used to fetch data from FingerprintJS
167
+ * @constructor
168
+ * @param {Options} options - Options for FingerprintJS server API client
169
+ */
170
+ constructor(options) {
171
+ if (!options.apiKey) {
172
+ throw Error('Api key is not set');
173
+ }
174
+ // These type assertions are safe because the Options type allows the
175
+ // region or authentication mode to be specified as a string or an enum value.
176
+ // The resulting JS from using the enum value or the string is identical.
177
+ this.region = options.region ?? Region.Global;
178
+ this.apiKey = options.apiKey;
179
+ this.fetch = options.fetch ?? fetch;
180
+ this.defaultHeaders = {
181
+ Authorization: `Bearer ${this.apiKey}`,
182
+ ...options.defaultHeaders,
183
+ };
184
+ }
185
+ /**
186
+ * Retrieves a specific identification event with the information from each activated product — Identification and all active [Smart signals](https://dev.fingerprint.com/docs/smart-signals-overview).
187
+ *
188
+ * @param eventId - identifier of the event
189
+ * @param {object|undefined} options - Optional `getEvent` operation options
190
+ * @param {string|undefined} options.ruleset_id - Optional ruleset ID to evaluate against the event
191
+ *
192
+ * @returns {Promise<Event>} - promise with event response. For more information, see the [Server API documentation](https://dev.fingerprint.com/reference/getevent).
193
+ *
194
+ * @example
195
+ * ```javascript Handling an event
196
+ * client
197
+ * .getEvent('<eventId>')
198
+ * .then((event) => console.log(event))
199
+ * .catch((error) => {
200
+ * if (error instanceof RequestError) {
201
+ * console.log(error.statusCode, error.message)
202
+ * // Access raw response in error
203
+ * console.log(error.response)
204
+ * }
205
+ * })
206
+ * ```
207
+ *
208
+ * @example Handling an event with rule_action
209
+ * ```javascript
210
+ * client
211
+ * .getEvent('<eventId>', { ruleset_id: '<rulesetId>' })
212
+ * .then((event) => {
213
+ * const ruleAction = event.rule_action
214
+ * if (ruleAction?.type === 'block') {
215
+ * console.log('Blocked by rule:', ruleAction.rule_id, ruleAction.status_code)
216
+ * }
217
+ * })
218
+ * .catch((error) => {
219
+ * if (error instanceof RequestError) {
220
+ * console.log(error.statusCode, error.message)
221
+ * }
222
+ * })
223
+ * ```
224
+ * */
225
+ async getEvent(eventId, options) {
226
+ if (!eventId) {
227
+ throw new TypeError('eventId is not set');
228
+ }
229
+ return this.callApi({
230
+ path: '/events/{event_id}',
231
+ pathParams: [eventId],
232
+ method: 'get',
233
+ queryParams: options,
234
+ });
235
+ }
236
+ /**
237
+ * Update an event with a given event ID
238
+ * @description Change information in existing events specified by `eventId` or *flag suspicious events*.
239
+ *
240
+ * When an event is created, it is assigned `linkedId` and `tag` submitted through the JS agent parameters. This information might not be available on the client so the Server API allows for updating the attributes after the fact.
241
+ *
242
+ * **Warning** It's not possible to update events older than one month.
243
+ *
244
+ * @param body - Data to update the event with.
245
+ * @param eventId The unique event [identifier](https://docs.fingerprint.com/reference/js-agent-v4-get-function#event_id).
246
+ *
247
+ * @return {Promise<void>}
248
+ *
249
+ * @example
250
+ * ```javascript
251
+ * const body = {
252
+ * linked_id: 'linked_id',
253
+ * suspect: false,
254
+ * }
255
+ *
256
+ * client
257
+ * .updateEvent(body, '<eventId>')
258
+ * .then(() => {
259
+ * // Event was successfully updated
260
+ * })
261
+ * .catch((error) => {
262
+ * if (error instanceof RequestError) {
263
+ * console.log(error.statusCode, error.message)
264
+ * // Access raw response in error
265
+ * console.log(error.response)
266
+ *
267
+ * if(error.statusCode === 409) {
268
+ * // Event is not mutable yet, wait a couple of seconds and retry the update.
269
+ * }
270
+ * }
271
+ * })
272
+ * ```
273
+ */
274
+ async updateEvent(body, eventId) {
275
+ if (!body) {
276
+ throw new TypeError('body is not set');
277
+ }
278
+ if (!eventId) {
279
+ throw new TypeError('eventId is not set');
280
+ }
281
+ return this.callApi({
282
+ path: '/events/{event_id}',
283
+ pathParams: [eventId],
284
+ method: 'patch',
285
+ body: JSON.stringify(body),
286
+ });
287
+ }
288
+ /**
289
+ * Delete data by visitor ID
290
+ * Request deleting all data associated with the specified visitor ID. This API is useful for compliance with privacy regulations. All delete requests are queued:
291
+ * Recent data (10 days or newer) belonging to the specified visitor will be deleted within 24 hours. * Data from older (11 days or more) identification events will be deleted after 90 days.
292
+ * If you are interested in using this API, please [contact our support team](https://fingerprint.com/support/) to activate it for you. Otherwise, you will receive a 403.
293
+ *
294
+ * @param visitorId The [visitor ID](https://dev.fingerprint.com/docs/js-agent#visitorid) you want to delete.*
295
+ *
296
+ * @return {Promise<void>} Promise that resolves when the deletion request is successfully queued
297
+ *
298
+ * @example
299
+ * ```javascript
300
+ * client
301
+ * .deleteVisitorData('<visitorId>')
302
+ * .then(() => {
303
+ * // Data deletion request was successfully queued
304
+ * })
305
+ * .catch((error) => {
306
+ * if (error instanceof RequestError) {
307
+ * console.log(error.statusCode, error.message)
308
+ * // Access raw response in error
309
+ * console.log(error.response)
310
+ * }
311
+ * })
312
+ * ```
313
+ */
314
+ async deleteVisitorData(visitorId) {
315
+ if (!visitorId) {
316
+ throw new TypeError('visitorId is not set');
317
+ }
318
+ return this.callApi({
319
+ path: '/visitors/{visitor_id}',
320
+ pathParams: [visitorId],
321
+ method: 'delete',
322
+ });
323
+ }
324
+ /**
325
+ * Search for identification events, including Smart Signals, using
326
+ * multiple filtering criteria. If you don't provide `start` or `end`
327
+ * parameters, the default search range is the last 7 days.
328
+ *
329
+ * Please note that events include mobile signals (e.g. `rootApps`) even if
330
+ * the request originated from a non-mobile platform. We recommend you
331
+ * **ignore** mobile signals for such requests.
332
+ *
333
+ * @param {SearchEventsFilter} filter - Events filter
334
+ * @param {number} filter.limit - Limit the number of events returned. Must be greater than 0.
335
+ * @param {string|undefined} filter.pagination_key - Use `pagination_key` to get the next page of results.
336
+ * @param {string|undefined} filter.visitor_id - Unique [visitor identifier](https://dev.fingerprint.com/reference/get-function#visitorid) issued by Fingerprint Identification. Filter for events matching this `visitor_id`.
337
+ * @param {string|undefined} filter.bot - Filter events by the bot detection result, specifically:
338
+ * - events where any kind of bot was detected.
339
+ * - events where a good bot was detected.
340
+ * - events where a bad bot was detected.
341
+ * - events where no bot was detected.
342
+ *
343
+ * Allowed values: `all`, `good`, `bad`, `none`.
344
+ * @param {string|undefined} filter.ip_address - Filter events by IP address range. The range can be as specific as a
345
+ * single IP (/32 for IPv4 or /128 for IPv6).
346
+ * All ip_address filters must use CIDR notation, for example,
347
+ * 10.0.0.0/24, 192.168.0.1/32
348
+ * @param {string|undefined} filter.linked_id - Filter events by your custom identifier.
349
+ * You can use [linked IDs](https://dev.fingerprint.com/reference/get-function#linkedid) to
350
+ * associate identification requests with your own identifier, for
351
+ * example, session ID, purchase ID, or transaction ID. You can then
352
+ * use this `linked_id` parameter to retrieve all events associated
353
+ * with your custom identifier.
354
+ * @param {string|undefined} filter.url - Filter events by the URL (`url` property) associated with the event.
355
+ * @param {string|undefined} filter.origin - Filter events by the origin field of the event. Origin could be the website domain or mobile app bundle ID (eg: com.foo.bar)
356
+ * @param {number|undefined} filter.start - Filter events with a timestamp greater than the start time, in Unix time (milliseconds).
357
+ * @param {number|undefined} filter.end - Filter events with a timestamp smaller than the end time, in Unix time (milliseconds).
358
+ * @param {boolean|undefined} filter.reverse - Sort events in reverse timestamp order.
359
+ * @param {boolean|undefined} filter.suspect - Filter events previously tagged as suspicious via the [Update API](https://dev.fingerprint.com/reference/updateevent).
360
+ * @param {boolean|undefined} filter.vpn - Filter events by VPN Detection result.
361
+ * @param {boolean|undefined} filter.virtual_machine - Filter events by Virtual Machine Detection result.
362
+ * @param {boolean|undefined} filter.tampering - Filter events by Browser Tampering Detection result.
363
+ * @param {boolean|undefined} filter.anti_detect_browser - Filter events by Anti-detect Browser Detection result.
364
+ * @param {boolean|undefined} filter.incognito - Filter events by Browser Incognito Detection result.
365
+ * @param {boolean|undefined} filter.privacy_settings - Filter events by Privacy Settings Detection result.
366
+ * @param {boolean|undefined} filter.jailbroken - Filter events by Jailbroken Device Detection result.
367
+ * @param {boolean|undefined} filter.frida - Filter events by Frida Detection result.
368
+ * @param {boolean|undefined} filter.factory_reset - Filter events by Factory Reset Detection result.
369
+ * @param {boolean|undefined} filter.cloned_app - Filter events by Cloned App Detection result.
370
+ * @param {boolean|undefined} filter.emulator - Filter events by Android Emulator Detection result.
371
+ * @param {boolean|undefined} filter.root_apps - Filter events by Rooted Device Detection result.
372
+ * @param {'high'|'medium'|'low'|undefined} filter.vpn_confidence - Filter events by VPN Detection result confidence level.
373
+ * @param {number|undefined} filter.min_suspect_score - Filter events with Suspect Score result above a provided minimum threshold.
374
+ * @param {boolean|undefined} filter.developer_tools - Filter events by Developer Tools detection result.
375
+ * @param {boolean|undefined} filter.location_spoofing - Filter events by Location Spoofing detection result.
376
+ * @param {boolean|undefined} filter.mitm_attack - Filter events by MITM (Man-in-the-Middle) Attack detection result.
377
+ * @param {boolean|undefined} filter.proxy - Filter events by Proxy detection result.
378
+ * @param {string|undefined} filter.sdk_version - Filter events by a specific SDK version associated with the identification event (`sdk.version` property).
379
+ * @param {string|undefined} filter.sdk_platform - Filter events by the SDK Platform associated with the identification event (`sdk.platform` property).
380
+ * @param {string[]|undefined} filter.environment - Filter for events by providing one or more environment IDs (`environment_id` property).
381
+ * */
382
+ async searchEvents(filter) {
383
+ return this.callApi({
384
+ path: '/events',
385
+ method: 'get',
386
+ queryParams: filter,
387
+ });
388
+ }
389
+ async callApi(options) {
390
+ const url = getRequestPath({
391
+ ...options,
392
+ region: this.region,
393
+ });
394
+ let response;
395
+ try {
396
+ response = await this.fetch(url, {
397
+ method: options.method.toUpperCase(),
398
+ headers: {
399
+ ...this.defaultHeaders,
400
+ ...options.headers,
401
+ },
402
+ body: options.body,
403
+ });
404
+ }
405
+ catch (e) {
406
+ throw new SdkError('Network or fetch error', undefined, e);
407
+ }
408
+ const contentType = response.headers.get('content-type') ?? '';
409
+ const isJson = contentType.includes('application/json');
410
+ if (response.ok) {
411
+ const hasNoBody = response.status === 204 || response.headers.get('content-length') === '0';
412
+ if (hasNoBody) {
413
+ return undefined;
414
+ }
415
+ if (!isJson) {
416
+ throw new SdkError('Expected JSON response but received non-JSON content type', response);
417
+ }
418
+ let data;
419
+ try {
420
+ data = await response.clone().json();
421
+ }
422
+ catch (e) {
423
+ throw new SdkError('Failed to parse JSON response', response, toError(e));
424
+ }
425
+ return data;
426
+ }
427
+ let errPayload;
428
+ try {
429
+ errPayload = await response.clone().json();
430
+ }
431
+ catch (e) {
432
+ throw new SdkError('Failed to parse JSON response', response, toError(e));
433
+ }
434
+ if (isErrorResponse(errPayload)) {
435
+ if (response.status === 429) {
436
+ throw new TooManyRequestsError(errPayload, response);
437
+ }
438
+ throw new RequestError(errPayload.error.message, errPayload, response.status, errPayload.error.code, response);
439
+ }
440
+ throw RequestError.unknown(response);
441
+ }
442
+ }
443
+
444
+ class UnsealError extends Error {
445
+ key;
446
+ error;
447
+ constructor(key, error) {
448
+ let msg = `Unable to decrypt sealed data`;
449
+ if (error) {
450
+ msg = msg.concat(`: ${error.message}`);
451
+ }
452
+ super(msg);
453
+ this.key = key;
454
+ this.error = error;
455
+ this.name = 'UnsealError';
456
+ }
457
+ }
458
+ class UnsealAggregateError extends Error {
459
+ errors;
460
+ constructor(errors) {
461
+ super('Unable to decrypt sealed data');
462
+ this.errors = errors;
463
+ this.name = 'UnsealAggregateError';
464
+ }
465
+ addError(error) {
466
+ this.errors.push(error);
467
+ }
468
+ toString() {
469
+ return this.errors.map((e) => e.toString()).join('\n');
470
+ }
471
+ }
472
+
473
+ const asyncInflateRaw = promisify(inflateRaw);
474
+ var DecryptionAlgorithm;
475
+ (function (DecryptionAlgorithm) {
476
+ DecryptionAlgorithm["Aes256Gcm"] = "aes-256-gcm";
477
+ })(DecryptionAlgorithm || (DecryptionAlgorithm = {}));
478
+ const SEALED_HEADER = Buffer.from([0x9e, 0x85, 0xdc, 0xed]);
479
+ function isEventResponse(data) {
480
+ return Boolean(data && typeof data === 'object' && 'event_id' in data && 'timestamp' in data);
481
+ }
482
+ /**
483
+ * @private
484
+ * */
485
+ function parseEventsResponse(unsealed) {
486
+ const json = JSON.parse(unsealed);
487
+ if (!isEventResponse(json)) {
488
+ throw new Error('Sealed data is not valid events response');
489
+ }
490
+ return json;
491
+ }
492
+ /**
493
+ * Decrypts the sealed response with the provided keys.
494
+ * The SDK will try to decrypt the result with each key until it succeeds.
495
+ * To learn more about sealed results visit: https://dev.fingerprint.com/docs/sealed-client-results
496
+ * @throws UnsealAggregateError
497
+ * @throws Error
498
+ */
499
+ async function unsealEventsResponse(sealedData, decryptionKeys) {
500
+ const unsealed = await unseal(sealedData, decryptionKeys);
501
+ return parseEventsResponse(unsealed);
502
+ }
503
+ /**
504
+ * @private
505
+ * */
506
+ async function unseal(sealedData, decryptionKeys) {
507
+ if (sealedData.subarray(0, SEALED_HEADER.length).toString('hex') !== SEALED_HEADER.toString('hex')) {
508
+ throw new Error('Invalid sealed data header');
509
+ }
510
+ const errors = new UnsealAggregateError([]);
511
+ for (const decryptionKey of decryptionKeys) {
512
+ switch (decryptionKey.algorithm) {
513
+ case DecryptionAlgorithm.Aes256Gcm:
514
+ try {
515
+ return await unsealAes256Gcm(sealedData, decryptionKey.key);
516
+ }
517
+ catch (e) {
518
+ errors.addError(new UnsealError(decryptionKey, e));
519
+ continue;
520
+ }
521
+ default:
522
+ throw new Error(`Unsupported decryption algorithm: ${decryptionKey.algorithm}`);
523
+ }
524
+ }
525
+ throw errors;
526
+ }
527
+ async function unsealAes256Gcm(sealedData, decryptionKey) {
528
+ const nonceLength = 12;
529
+ const nonce = sealedData.subarray(SEALED_HEADER.length, SEALED_HEADER.length + nonceLength);
530
+ const authTag = sealedData.subarray(-16);
531
+ const ciphertext = sealedData.subarray(SEALED_HEADER.length + nonceLength, -16);
532
+ const decipher = createDecipheriv('aes-256-gcm', decryptionKey, nonce).setAuthTag(authTag);
533
+ const compressed = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
534
+ const payload = await asyncInflateRaw(compressed);
535
+ return payload.toString();
536
+ }
537
+
538
+ function isValidHmacSignature(signature, data, secret) {
539
+ return signature === crypto.createHmac('sha256', secret).update(data).digest('hex');
540
+ }
541
+ /**
542
+ * Verifies the HMAC signature extracted from the "fpjs-event-signature" header of the incoming request. This is a part of the webhook signing process, which is available only for enterprise customers.
543
+ * If you wish to enable it, please contact our support: https://fingerprint.com/support
544
+ *
545
+ * @param {IsValidWebhookSignatureParams} params
546
+ * @param {string} params.header - The value of the "fpjs-event-signature" header.
547
+ * @param {Buffer} params.data - The raw data of the incoming request.
548
+ * @param {string} params.secret - The secret key used to sign the request.
549
+ *
550
+ * @return {boolean} true if the signature is valid, false otherwise.
551
+ *
552
+ * @example
553
+ * ```javascript
554
+ * // Webhook endpoint handler
555
+ * export async function POST(request: Request) {
556
+ * try {
557
+ * const secret = process.env.WEBHOOK_SIGNATURE_SECRET;
558
+ * const header = request.headers.get("fpjs-event-signature");
559
+ * const data = Buffer.from(await request.arrayBuffer());
560
+ *
561
+ * if (!isValidWebhookSignature({ header, data, secret })) {
562
+ * return Response.json(
563
+ * { message: "Webhook signature is invalid." },
564
+ * { status: 403 },
565
+ * );
566
+ * }
567
+ *
568
+ * return Response.json({ message: "Webhook received." });
569
+ * } catch (error) {
570
+ * return Response.json({ error }, { status: 500 });
571
+ * }
572
+ * }
573
+ * ```
574
+ */
575
+ function isValidWebhookSignature(params) {
576
+ const { header, data, secret } = params;
577
+ const signatures = header.split(',');
578
+ for (const signature of signatures) {
579
+ const [version, hash] = signature.split('=');
580
+ if (version === 'v1' && isValidHmacSignature(hash, data, secret)) {
581
+ return true;
582
+ }
583
+ }
584
+ return false;
585
+ }
586
+
587
+ export { DecryptionAlgorithm, FingerprintServerApiClient, Region, RequestError, SdkError, TooManyRequestsError, UnsealAggregateError, UnsealError, isValidWebhookSignature, parseEventsResponse, unseal, unsealEventsResponse };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@fingerprint/node-sdk",
3
+ "version": "7.0.0-test.0",
4
+ "description": "Node.js wrapper for Fingerprint Server API",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs",
13
+ "node": "./dist/index.mjs"
14
+ }
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/fingerprintjs/node-sdk"
19
+ },
20
+ "engines": {
21
+ "node": ">=18.17.0"
22
+ },
23
+ "keywords": [],
24
+ "author": "FingerprintJS, Inc (https://fingerprint.com)",
25
+ "license": "MIT",
26
+ "lint-staged": {
27
+ "*.ts": "pnpm run lint:fix"
28
+ },
29
+ "config": {
30
+ "commitizen": {
31
+ "path": "./node_modules/cz-conventional-changelog"
32
+ }
33
+ },
34
+ "devDependencies": {
35
+ "@changesets/cli": "^2.27.8",
36
+ "@commitlint/cli": "^19.2.1",
37
+ "@fingerprintjs/changesets-changelog-format": "^0.2.0",
38
+ "@fingerprintjs/commit-lint-dx-team": "^0.1.0",
39
+ "@fingerprintjs/conventional-changelog-dx-team": "^0.1.0",
40
+ "@fingerprintjs/eslint-config-dx-team": "^0.1.0",
41
+ "@fingerprintjs/prettier-config-dx-team": "^0.2.0",
42
+ "@fingerprintjs/tsconfig-dx-team": "^0.0.2",
43
+ "@rollup/plugin-json": "^6.1.0",
44
+ "@rollup/plugin-typescript": "^11.1.6",
45
+ "@types/jest": "^29.5.12",
46
+ "@types/node": "^20.11.30",
47
+ "buffer": "^6.0.3",
48
+ "commitizen": "^4.3.0",
49
+ "cz-conventional-changelog": "^3.3.0",
50
+ "husky": "^9.0.11",
51
+ "jest": "^29.7.0",
52
+ "lint-staged": "^15.2.2",
53
+ "openapi-typescript": "^7.4.2",
54
+ "rimraf": "^5.0.5",
55
+ "rollup": "^4.34.9",
56
+ "rollup-plugin-dts": "^6.1.0",
57
+ "rollup-plugin-license": "^3.3.1",
58
+ "rollup-plugin-peer-deps-external": "^2.2.4",
59
+ "ts-jest": "^29.1.2",
60
+ "tslib": "^2.6.2",
61
+ "typedoc": "^0.27.9",
62
+ "typescript": "^5.4.0",
63
+ "yaml": "^2.6.0"
64
+ },
65
+ "scripts": {
66
+ "build": "rimraf dist && rollup -c rollup.config.js --bundleConfigAsCjs",
67
+ "lint": "eslint --ext .js,.ts --ignore-path .gitignore --max-warnings 0 .",
68
+ "lint:fix": "pnpm lint --fix",
69
+ "test": "jest",
70
+ "test:coverage": "jest --coverage",
71
+ "test:dts": "tsc --noEmit --isolatedModules dist/index.d.ts",
72
+ "generateTypes": "node generate.mjs && pnpm lint:fix",
73
+ "docs": "typedoc src/index.ts --out docs"
74
+ }
75
+ }