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

@torknetwork/sdk

v1.0.0

Published

Tork Governance SDK - PII detection, policy enforcement, and AI agent governance for JavaScript/TypeScript

Readme

@torknetwork/sdk

Official JavaScript/TypeScript SDK for Tork Governance - AI agent governance, PII detection, and policy enforcement.

Installation

npm install @torknetwork/sdk

Quick Start

PII Detection & Redaction

import { PIIRedactor } from '@torknetwork/sdk';

const redactor = new PIIRedactor();

// Detect PII
const matches = redactor.detect('Email: [email protected], SSN: 123-45-6789');
console.log(matches);
// [
//   { type: 'EMAIL', value: '[email protected]', start: 7, end: 23, confidence: 0.95 },
//   { type: 'SSN', value: '123-45-6789', start: 30, end: 41, confidence: 0.95 }
// ]

// Redact PII
const result = redactor.redact('My email is [email protected]');
console.log(result.redacted);
// 'My email is [EMAIL]'

Governance Engine (Local)

import { GovernanceEngine } from '@torknetwork/sdk';

const engine = new GovernanceEngine();

const result = engine.evaluate({
  agentId: 'my-agent',
  payload: { message: 'User SSN is 123-45-6789' }
});

console.log(result.decision);     // 'block'
console.log(result.score);        // 25
console.log(result.piiMatches);   // [{ type: 'SSN', ... }]
console.log(result.receipt.id);   // 'tork_xxx_yyy'

API Client

import { TorkClient } from '@torknetwork/sdk';

const client = new TorkClient({
  apiKey: 'your-api-key'
});

// Evaluate via API
const result = await client.evaluate({
  agentId: 'my-agent',
  payload: { message: 'Hello world' }
});

// Get agent score
const score = await client.getScore('my-agent');

Express Middleware

import express from 'express';
import { torkMiddleware } from '@torknetwork/sdk/express';

const app = express();
app.use(express.json());

// Add governance middleware
app.use('/api', torkMiddleware({
  agentId: 'my-api',
  mode: 'enforce',
  localMode: true,
  excludePaths: ['/health']
}));

app.post('/api/chat', (req, res) => {
  // req.body is automatically redacted if PII was found
  // req.tork contains the governance result
  res.json({ received: req.body });
});

Features

PII Detection (20+ Types)

| Type | Example | |------|---------| | EMAIL | [email protected] | | PHONE | (555) 123-4567 | | SSN | 123-45-6789 | | CREDIT_CARD | 4532-0151-1283-0366 | | IP_ADDRESS | 192.168.1.1 | | AWS_ACCESS_KEY | AKIAIOSFODNN7EXAMPLE | | AWS_SECRET_KEY | wJalrXUtnFEMI/K7MDENG... | | GITHUB_TOKEN | ghp_xxxxxxxxxxxx | | STRIPE_KEY | sk_live_xxxxx | | JWT_TOKEN | eyJhbGciOiJ... | | IBAN | DE89370400440532013000 | | PASSPORT | A12345678 | | PRIVATE_KEY | -----BEGIN PRIVATE KEY----- | | And more... | |

Governance Decisions

  • allow - Request is safe
  • block - Request contains high-risk content
  • redact - PII detected and redacted
  • review - Flagged for human review

Risk Scoring

Each PII type has a risk weight (0-35). Scores are calculated based on:

  • Type of PII found
  • Detection confidence
  • Number of occurrences

| Risk Level | Score Range | |------------|-------------| | Low | 0-20 | | Medium | 20-50 | | High | 50-80 | | Critical | 80-100 |

API Reference

PIIRedactor

const redactor = new PIIRedactor({
  types: ['EMAIL', 'SSN'],      // Filter PII types
  minConfidence: 0.8,            // Minimum confidence threshold
  replacement: '[REDACTED]',     // Custom replacement text
});

redactor.detect(text: string): PIIMatch[]
redactor.redact(text: string): RedactionResult
redactor.containsPII(text: string): boolean
redactor.getSummary(text: string): Record<PIIType, number>

GovernanceEngine

const engine = new GovernanceEngine({
  policies: [...],              // Custom policy rules
  piiTypes: ['EMAIL', 'SSN'],   // PII types to scan
  thresholds: {
    block: 80,
    review: 50,
    redact: 20,
  },
});

engine.evaluate(request): EvaluationResult
engine.addPolicy(policy): void
engine.removePolicy(policyId): boolean
engine.getPolicies(): PolicyRule[]

TorkClient

const client = new TorkClient({
  apiKey: 'xxx',
  baseUrl: 'https://api.tork.network',
  timeout: 30000,
  retries: 3,
});

await client.evaluate({ agentId, payload }): EvaluateResponse
await client.redact(text): RedactResponse
await client.getScore(agentId): ScoreResponse
await client.getAuditLogs(agentId, options): AuditLogsResponse

Express Middleware

import { torkMiddleware, piiRedactionMiddleware } from '@torknetwork/sdk/express';

// Full governance
app.use(torkMiddleware({
  agentId: 'my-api',
  mode: 'enforce',       // 'enforce' | 'warn' | 'audit'
  localMode: true,       // Use local engine (no API calls)
  apiKey: 'xxx',         // Required if localMode: false
  excludePaths: ['/health'],
  onDecision: (result, req, res) => { ... },
}));

// PII redaction only
app.use(piiRedactionMiddleware({
  agentId: 'my-api',
}));

Custom Policies

const engine = new GovernanceEngine({
  policies: [
    {
      id: 'block-secrets',
      name: 'Block Secrets',
      condition: {
        piiTypes: ['AWS_SECRET_KEY', 'PRIVATE_KEY'],
      },
      action: 'block',
      priority: 100,
    },
    {
      id: 'review-keywords',
      name: 'Review Sensitive Keywords',
      condition: {
        keywords: ['confidential', 'internal only'],
        riskScoreThreshold: 30,
      },
      action: 'review',
      priority: 50,
    },
    {
      id: 'custom-check',
      name: 'Custom Check',
      condition: {
        custom: (request, piiMatches) => {
          return request.context?.userId === 'admin';
        },
      },
      action: 'allow',
      priority: 200,
    },
  ],
});

License

MIT - see LICENSE