npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dojah/deviceguard-web

v1.1.0

Published

Dojah DeviceGuard web SDK — device fingerprinting, device recall and fraud risk scoring.

Readme

@dojah/deviceguard-web

Web SDK for Dojah DeviceGuard: identifies the device, returns a stable deviceId and a risk score, and tracks user actions for fraud detection.

  • Zero dependencies, ~12 KB minified
  • Works with bundlers (ESM/CJS) or a plain <script> tag
  • Fingerprint payload is encrypted in transit when your server has payload encryption enabled
  • Safe to import during SSR — only call its methods in the browser

Get an API key

You need an API key (dg_…) and your DeviceGuard endpoint URL to use the SDK. To request them, email [email protected].

The key is used in the browser, so it isn't secret. Ask support to restrict it to your domains (origin allowlist) so it can't be used from other sites.

Install

npm install @dojah/deviceguard-web

Usage

import DeviceGuard from '@dojah/deviceguard-web';

const deviceGuard = new DeviceGuard({
  apiKey: 'dg_your_api_key',
  endpoint: 'https://your-deviceguard-server.com',
});

// Get device ID
const deviceId = await deviceGuard.getDeviceId();

// Record user action
await deviceGuard.recordAction('login', {
  userId: 'user-123',
  metadata: { source: 'web' }
});

Script tag

<script src="https://cdn.jsdelivr.net/npm/@dojah/deviceguard-web/dist/deviceguard.min.js"></script>
<script>
  const deviceGuard = new DeviceGuard({ apiKey: 'dg_your_api_key', endpoint: 'https://your-deviceguard-server.com' });
  deviceGuard.getDeviceId().then((deviceId) => console.log(deviceId));
</script>

Next.js / SSR

Importing is safe on the server, but fingerprinting needs a browser — call the SDK from useEffect or a client component:

'use client';
import { useEffect } from 'react';
import DeviceGuard from '@dojah/deviceguard-web';

useEffect(() => {
  new DeviceGuard({ apiKey, endpoint }).getDeviceId().then((deviceId) => { /* … */ });
}, []);

Verify on your server

Anything from the browser can be tampered with, including a riskScore read in the browser. Before making a trust decision, look the device up from your backend:

curl -X POST https://your-deviceguard-server.com/api/device/verify \
  -H "X-API-Key: dg_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"deviceId": "<deviceId from the browser>"}'
# → { "riskScore": 12, "isBlocked": false, "isTrusted": false, ... }
# 404 if the device isn't known to your workspace

Then allow, step up (e.g. OTP), or block based on the result.

API

| Method | Returns | |---|---| | new DeviceGuard(config) | config: apiKey, endpoint, timeout (ms, default 10000), retry (default true), debug (default false) | | init(apiKey?, endpoint?) | Promise<{ deviceId, riskScore, isNewDevice, country, ipAddress, device }> | | getDeviceId() | Promise<string> — identifies first if needed | | recordAction(action, { userId?, metadata? }) | Records an action (login, signup, payment, …) and links userId to this device. action ≤ 64 chars, metadata ≤ 4KB. Returns { success, userLinked, riskScore, alerts } | | track(action, metadata?) | Older form of recordAction; a userId inside metadata is also linked | | verifyDevice() | Promise<{ isBlocked, isTrusted, riskScore, … }> | | isDeviceBlocked() | Promise<boolean> | | getRiskScore() | Promise<number \| null> | | getFingerprint() | The raw collected fingerprint |

Notes

  • Requires an API key — requests without a valid key are rejected. Get one from [email protected].
  • Always verify server-side. Treat the deviceId sent from the browser as a claim; look it up from your backend before making trust decisions.
  • The SDK stores a random identifier in localStorage and a first-party cookie (_dg_cid) to recognise the device across visits.
  • If you use a Content Security Policy, allow your DeviceGuard endpoint in connect-src.