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

@trustgateai/sdk

v1.4.0

Published

TrustGate Node.js SDK with Shadow AI detection and workflow context

Readme

trustgate-node

TrustGate Node.js SDK with Shadow AI detection: workflow context, middleware for Vercel AI SDK and LangChain, n8n header helper, and SSE streaming.

Install

npm install trustgate-node

Optional peer dependencies for middleware:

npm install ai @ai-sdk/openai          # Vercel AI SDK
npm install @langchain/openai         # LangChain

Core client

import { TrustGate, getWorkflowContextFromEnv } from 'trustgate-node';

const client = new TrustGate({
  baseUrl: process.env.TRUSTGATE_BASE_URL!,
  apiKey: process.env.TRUSTGATE_API_KEY,
  // workflowContext optional; otherwise read from process.env (n8n, Vercel, GitHub)
});

// Non-streaming
const res = await client.fetch('/v1/chat/completions', {
  method: 'POST',
  body: JSON.stringify({ model: 'gpt-4', messages: [...] }),
});

// SSE streaming (workflow_id sent in request for background attribution)
const streamRes = await client.fetchStream('/v1/chat/completions', {
  method: 'POST',
  body: JSON.stringify({ model: 'gpt-4', messages: [...], stream: true }),
});
// Consume streamRes.body (ReadableStream) as usual for SSE

Context provider

Workflow metadata is read from process.env so TrustGate can attribute traffic (Shadow AI detection):

| Source | Example env vars | |---------|-------------------| | n8n | N8N_WORKFLOW_ID, N8N_EXECUTION_ID, N8N_WORKFLOW_NAME | | Vercel | VERCEL, VERCEL_ENV, VERCEL_URL, VERCEL_GIT_* | | GitHub | GITHUB_ACTION, GITHUB_WORKFLOW, GITHUB_RUN_ID, GITHUB_REPOSITORY |

import { getWorkflowContextFromEnv } from 'trustgate-node';

const ctx = getWorkflowContextFromEnv();
// { source: 'n8n', workflow_id: '...', execution_id: '...', metadata: {...} }

Middleware: Vercel AI SDK

Point the OpenAI provider at TrustGate so all calls go through the gateway with workflow context:

import { createOpenAI } from '@ai-sdk/openai';
import { createTrustGateOpenAIOptions } from 'trustgate-node/middleware/vercel-ai';

const openai = createOpenAI(
  createTrustGateOpenAIOptions({
    baseUrl: process.env.TRUSTGATE_BASE_URL!,
    apiKey: process.env.TRUSTGATE_API_KEY,
  })
);

// Use with streamText / generateText as usual
import { streamText } from 'ai';
const result = streamText({
  model: openai('gpt-4'),
  messages: [{ role: 'user', content: 'Hello' }],
});

Middleware: LangChain

Use TrustGate as the OpenAI endpoint for LangChain with one config object:

import { ChatOpenAI } from '@langchain/openai';
import { createTrustGateLangChainConfig } from 'trustgate-node/middleware/langchain';

const config = createTrustGateLangChainConfig({
  baseUrl: process.env.TRUSTGATE_BASE_URL!,
  apiKey: process.env.TRUSTGATE_API_KEY,
});

const llm = new ChatOpenAI({
  ...config,
  modelName: 'gpt-4',
  temperature: 0,
});

n8n HTTP Request node: header snippet

Get a pre-formatted JSON object of headers for n8n “HTTP Request” nodes so each request includes TrustGate auth and workflow context:

import { getN8nHeaderSnippet } from 'trustgate-node';

const { headers, json } = getN8nHeaderSnippet();
// headers: [ { name: 'X-Trustgate-Source', value: 'n8n' }, ... ]
// json: '{"X-Trustgate-Source":"n8n","X-Trustgate-Workflow-Id":"...", ...}'

In n8n, set Send Headers (or equivalent) to the headers array or paste the json into your node config. You can pass apiKey and baseUrl explicitly or rely on TRUSTGATE_API_KEY and TRUSTGATE_BASE_URL in the environment.

Streaming (SSE)

  • Use client.fetchStream(path, init, options) for SSE endpoints. The client sets Accept: text/event-stream and sends workflow context (e.g. workflow_id) in the initial request, so the gateway can attribute the background stream.
  • The returned Response body is the raw stream; consume it with response.body.getReader() or pass through to your framework’s SSE handling.

License

MIT