Skip to content

Repository files navigation

Fingerprint logo

Build statuscoverageCurrent NPM versionMonthly downloads from NPMDiscord server

Fingerprint Server Node.js SDK

Fingerprint is a device intelligence platform offering industry-leading accuracy.

The Fingerprint Server Node SDK is an easy way to interact with the Fingerprint Server API from your Node application. You can search, update, or delete identification events.

Requirements

TypeScript support:

  • TypeScript 4.5.5 or higher

Supported runtimes:

  • Node.js 18 LTS or higher (we support all Node LTS releases before end-of-life).

  • Deno and Bun might work but are not actively tested.

  • "Edge" runtimes might work with some modifications but are not actively tested.

    Details

    See "edge" runtimes compatibility

    This SDK can be made compatible with JavaScript "edge" runtimes that do not support all Node APIs, for example, Vercel Edge Runtime, or Cloudflare Workers.

    To make it work, replace the SDK's built-in fetch function (which relies on Node APIs) with the runtime's native fetch function. Pass the function into the constructor with proper binding:

    constclient=newFingerprintServerApiClient({region: Region.EU,apiKey: apiKey,fetch: fetch.bind(globalThis),})

How to install

Install the package using your favorite package manager:

  • NPM:

    npm i @fingerprint/node-sdk
  • Yarn:

    yarn add @fingerprint/node-sdk
  • pnpm:

    pnpm i @fingerprint/node-sdk

Getting started

Initialize the client instance and use it to make API requests. You need to specify your Fingerprint Secret API key and the region of your Fingerprint workspace.

import{FingerprintServerApiClient,Region,}from'@fingerprint/node-sdk'constclient=newFingerprintServerApiClient({apiKey: '<SECRET_API_KEY>',region: Region.Global,})// Get visit history of a specific visitorclient.searchEvents({visitor_id: '<visitorId>'}).then((visitorHistory)=>{console.log(visitorHistory)})// Get a specific identification eventclient.getEvent('<eventId>').then((event)=>{console.log(event)})// Get an event with a ruleset evaluationclient.getEvent('<eventId>',{ruleset_id: '<rulesetId>'}).then((event)=>{console.log(event.rule_action?.type)// 'allow' or 'block'})// Search for identification eventsclient.searchEvents({limit: 10,// pagination_key: previousSearchResult.pagination_key,suspect: true,}).then((events)=>{console.log(events)})

See the Examples folder for more detailed examples.

Error handling

Most failures are a ServerApiError, thrown when the Server API responds with a structured error. It exposes a strongly typed errorCode (ErrorCode) alongside statusCode, responseBody, and the raw response:

import{ServerApiError,FingerprintServerApiClient,Region}from'@fingerprint/node-sdk'constclient=newFingerprintServerApiClient({apiKey: '<SECRET_API_KEY>',region: Region.Global,})try{constevent=awaitclient.getEvent(eventId)console.log(JSON.stringify(event,null,2))}catch(error){if(errorinstanceofServerApiError){// `errorCode` is strongly typed as `ErrorCode`if(error.errorCode==='event_not_found'){console.log('This event does not exist')}console.log(`error ${error.statusCode} (${error.errorCode}): `,error.message)console.log(error.responseBody)// parsed response body}}

Other errors, all subclasses of SdkError:

  • TooManyRequestsError — a ServerApiError thrown when the request is throttled (HTTP 429).
  • RequestError — the base class of ServerApiError, thrown when the response doesn't match the Server API error shape (e.g. a proxy error). Its errorCode is a free-form string placeholder from statusText. Since ServerApiError extends it, error instanceof RequestError catches both.
  • SdkError — the base of all SDK errors; also thrown for network failures and malformed responses.

Webhooks

Webhook types

When handling Webhooks coming from Fingerprint, you can cast the payload as the built-in Event type:

import{Event}from'@fingerprint/node-sdk'constevent=eventWebhookBodyasunknownasEvent

Webhook signature validation

Customers on the Enterprise plan can enable Webhook signatures to cryptographically verify the authenticity of incoming webhooks. This SDK provides a utility method for verifying the HMAC signature of the incoming webhook request.

To learn more, see example/validateWebhookSignature.mjs or read the API Reference.

Sealed results

This SDK provides utility methods for decrypting sealed results. Use the below code to unseal results:

import{unsealEventsResponse,DecryptionAlgorithm}from'@fingerprint/node-sdk'constsealedData=process.env.BASE64_SEALED_RESULTconstdecryptionKey=process.env.BASE64_KEYconstunsealedData=awaitunsealEventsResponse(Buffer.from(sealedData,'base64'),[{key: Buffer.from(decryptionKey,'base64'),algorithm: DecryptionAlgorithm.Aes256Gcm,},])console.log(JSON.stringify(unsealedData,null,2))

To learn more, refer to the example located in example/unsealResult.mjs.

Deleting visitor data

Customers on the Enterprise plan can Delete all data associated with a specific visitor to comply with privacy regulations. See example/deleteVisitor.mjs or the API Reference.

API Reference

See the full API reference.

Semantic versioning

  • Changes to types in this repository are considered non-breaking and are usually released as PATCH or MINOR semver changes (otherwise every schema addition would be a major version upgrade).
  • It is highly recommended that you lock your package version to a specific PATCH release and upgrade with the expectation that types may be upgraded between any release.
  • The runtime (non-type-related) public API of the Node SDK still follows semver strictly.

Support and feedback

To report problems, ask questions, or provide feedback, please use Issues. If you need private support, you can email us at oss-support@fingerprint.com.

License

This project is licensed under the MIT license.