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

@trace-id/embed

v0.1.1

Published

Trace inside your own backend: device identification and fraud signals with no separate server. Plug in your database (MongoDB, Postgres) and framework (Express, Fastify, NestJS, Next.js).

Readme

@trace-id/embed

Trace inside your own backend. No separate server, no new database: device identification and fraud signals run in the app you already have, on the database you already run.

npm install @trace-id/embed

Three steps

1. Create Trace once, with your database.

import { createTrace } from '@trace-id/embed';
import { mongoStorage } from '@trace-id/embed/mongo';       // or postgresStorage, or memoryStorage for tests

export const trace = createTrace({
  storage: mongoStorage(db),                              // your existing MongoDB Db
  secret: process.env.TRACE_SECRET!,                      // 32+ random characters, kept stable
});

2. Mount one route for the browser SDK (pick your framework below). It serves /trace/v1/identify on your own API.

3. In the browser, point the SDK at your API; on your server, verify and decide.

// browser
const client = createClient({ apiKey: 'pk_embed', endpoint: 'https://api.yourapp.com/trace' });
const { eventId } = await client.get({ linkedId: user.id });

// your signup / login / payment handler: an in-process call, not an HTTP request
const event = await trace.verify(body.eventId);
if (event.suspectScore >= 60) return block();
if (event.signals.multiAccount.detected) flagForReview(event);

The browser SDK requires an apiKey that starts with pk_. Any value works unless you set publicKey in createTrace, which then has to match.

Mount it on your framework

| Framework | Code | | --- | --- | | Express / Connect | app.use(toNodeHandler(trace)) from @trace-id/embed/node | | Fastify | registerFastify(app, trace) from @trace-id/embed/fastify | | NestJS (Fastify adapter) | registerFastify(app.getHttpAdapter().getInstance(), trace) in main.ts | | NestJS (Express adapter) | app.use(toNodeHandler(trace)) in main.ts | | Next.js (route handler) | app/trace/[...path]/route.ts: const h = toFetchHandler(trace); export { h as POST, h as OPTIONS } | | Hono, Bun, Deno, Remix, SvelteKit | toFetchHandler(trace) from @trace-id/embed/fetch | | Anything else | await trace.identify(body, { ip, headers }), then send result as JSON and setCookie as a header |

All adapters take { prefix } (default /trace). Set your framework's trust-proxy option so the client IP is right.

Pick your storage

| Database | Code | Notes | | --- | --- | --- | | MongoDB | mongoStorage(db, { eventRetentionDays: 90 }) | Seven trace_ collections (two for the fraud score) with their own indexes. Retention is a TTL index. | | Postgres | postgresStorage(pool) | Seven trace_ tables, created on first use. One transaction per identification. | | Memory | memoryStorage() | Tests and local development. Not shared between processes. | | Your own | Implement TraceStorage | About 20 small queries. Run storageContract() from the source to check it. |

Counters

The velocity and high-activity signals count events per visitor, IP and account. By default the counts live in your process. With several instances, share them on your Redis:

import { redisCounters } from '@trace-id/embed';
createTrace({ storage, secret, counters: redisCounters(redis) });   // an ioredis client; keys prefixed trace:vel

What you can call

| Method | Use | | --- | --- | | trace.verify(eventId) | The verified event for a decision. Throws TraceError 404/410 if unknown or older than the window (60 min). | | trace.event(eventId) | The same, without the window, for your admin. | | trace.device(deviceId) | Every browser and account on a device: multi-accounting, ban evasion. | | trace.visitorEvents(visitorId) | A visitor's history, newest first. | | trace.deleteVisitor(visitorId) | Data requests (also deletes the visitor's fraud labels). | | trace.label(eventId, 'payment', true) | Your verdict for one fraud type: a chargeback (true), a review that cleared it (false). | | trace.unlabel(eventId, label), trace.eventLabels(eventId) | Undo a label; list an event's labels. | | trace.fraudModels(), trace.trainFraudModels() | Models per fraud type with their cross-validated AUC; retrain now. |

Fraud score. Once a fraud type has 30 labels (at least 5 fraud and 5 legit), Trace trains a model on which signals fired and every new event gets fraudScores: [{ label, probability, reasons }]. Models retrain 30 s after the last label change. Same limits as the server: 20 types, newest 50,000 labels per type. A custom adapter without the optional label methods keeps working; label calls then throw 501. See the API reference.

onEvent in createTrace receives every event in-process: push it to your queue, moderation tools or logs instead of running webhooks.

Options

scoring (weights and thresholds; default scoring.default.json), ipIntel (Tor, datacenter, VPN, proxy and country: createIpIntel() from @trace-id/ip-intel combines IP data providers and lists), ipStorage (truncated by default, or full, hashed, none), crossBrowser (default on), cookie (first-party visitor cookie, default on), publicKey, verifyWindowMinutes, sealKey, crawlers ({ ranges } from fetchCrawlerRanges() verifies AI crawlers by published IP ranges; false turns crawler checks off), fraudScore (false turns it off, or { retrainAfterMs }), onEvent, log.

Same engine as the server

The standalone Trace server uses this package's core for matching, tokens and validation, so results are identical, and it is covered by the same accuracy benchmark. Use the server when you want Trace as its own service with a dashboard; use @trace-id/embed when you want it inside your app.