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

deerdawn

v1.0.1

Published

Official Node.js SDK for DeerDawn - AI governance and decision control platform

Readme

DeerDawn Node.js SDK

Official Node.js client library for DeerDawn - AI governance and decision control platform.

Installation

npm install deerdawn

Quick Start

const { Deerdawn } = require('deerdawn');

// Initialize client
const deerdawn = new Deerdawn({
  apiKey: 'dd_prod_xxxxx' // Get from https://app.deerdawn.com/api-keys
});

// Evaluate a decision
const result = await deerdawn.evaluateDecision({
  action_type: 'send_email',
  trace_id: 'user-123-action-456',
  payload: {
    recipient: '[email protected]',
    subject: 'Hello World'
  }
});

if (result.decision === 'allow') {
  console.log('Action allowed');
  // Proceed with sending email
} else {
  console.log('Action blocked:', result.reason);
}

TypeScript Support

The SDK is written in TypeScript and includes full type definitions:

import { Deerdawn, EvaluateDecisionRequest, EvaluateDecisionResponse } from 'deerdawn';

const deerdawn = new Deerdawn({
  apiKey: process.env.DEERDAWN_API_KEY!
});

const request: EvaluateDecisionRequest = {
  action_type: 'database_write',
  trace_id: 'req-789',
  payload: { table: 'users', operation: 'delete' }
};

const response: EvaluateDecisionResponse = await deerdawn.evaluateDecision(request);

Configuration

const deerdawn = new Deerdawn({
  apiKey: 'dd_prod_xxxxx',      // Required: Your API key
  baseUrl: 'https://api.deerdawn.com', // Optional: API base URL (default shown)
  timeout: 5000,                // Optional: Request timeout in ms (default: 5000)
  maxRetries: 3,                // Optional: Max retry attempts (default: 3)
  debug: false                  // Optional: Enable debug logging (default: false)
});

API Reference

evaluateDecision(request)

Evaluate an action against your policies.

Parameters:

  • action_type (string, required): Type of action (e.g., "send_email", "database_write")
  • trace_id (string, required): Unique trace identifier for correlation
  • payload (object, optional): Additional context data

Returns: Promise<EvaluateDecisionResponse>

  • decision: "allow" | "deny" | "escalate"
  • reason: Human-readable explanation
  • policy_id: ID of matched policy (if any)
  • latency_ms: Evaluation latency
  • decision_id: Decision log ID

Example:

const result = await deerdawn.evaluateDecision({
  action_type: 'refund_payment',
  trace_id: 'order-12345',
  payload: {
    amount: 99.99,
    currency: 'USD',
    reason: 'customer_request'
  }
});

console.log(`Decision: ${result.decision}`);
console.log(`Reason: ${result.reason}`);
console.log(`Latency: ${result.latency_ms}ms`);

listPolicies()

Get all policies for your organization.

Returns: Promise<Policy[]>

Example:

const policies = await deerdawn.listPolicies();

policies.forEach(policy => {
  console.log(`${policy.name}: ${policy.decision} (priority: ${policy.priority})`);
});

createPolicy(policy)

Create a new policy.

Parameters:

  • name (string): Policy name
  • action_types (string[]): Action types this policy applies to
  • conditions (array): Condition expressions
  • decision (string): "allow", "deny", or "escalate"
  • priority (number): Evaluation priority (lower = higher priority)
  • enabled (boolean): Whether policy is active
  • description (string, optional): Policy description

Returns: Promise<Policy>

Example:

const policy = await deerdawn.createPolicy({
  name: 'Auto-approve refunds under $100',
  action_types: ['refund_payment'],
  conditions: [
    {
      field: 'payload.amount',
      operator: 'lt',
      value: 100
    }
  ],
  decision: 'allow',
  priority: 10,
  enabled: true,
  description: 'Automatically approve small refunds'
});

deletePolicy(policyId)

Delete a policy.

Parameters:

  • policyId (string): Policy ID to delete

Returns: Promise<void>

Example:

await deerdawn.deletePolicy('pol_abc123');

listDecisions(filters?)

Get decision logs with optional filters.

Parameters:

  • decision (string, optional): Filter by decision type ("allow", "deny", "escalate")
  • trace_id (string, optional): Filter by trace ID

Returns: Promise<Decision[]>

Example:

// Get all denied decisions
const deniedDecisions = await deerdawn.listDecisions({ decision: 'deny' });

// Get decisions for a specific trace
const traceDecisions = await deerdawn.listDecisions({ trace_id: 'user-123' });

getDecision(decisionId)

Get a specific decision by ID.

Parameters:

  • decisionId (string): Decision ID

Returns: Promise<Decision>

Example:

const decision = await deerdawn.getDecision('dec_xyz789');
console.log(decision.payload);

Error Handling

The SDK throws DeerDawnAPIError for API errors:

import { Deerdawn, DeerDawnAPIError } from 'deerdawn';

try {
  const result = await deerdawn.evaluateDecision({
    action_type: 'send_email',
    trace_id: 'test-123'
  });
} catch (error) {
  if (error instanceof DeerDawnAPIError) {
    console.error(`API Error (${error.status}): ${error.message}`);
    console.error(`Error code: ${error.code}`);
  } else {
    console.error('Unexpected error:', error);
  }
}

Common Error Codes

  • 401 Unauthorized: Invalid API key
  • 402 Payment Required: Plan limit exceeded
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Internal Server Error: Server error (automatically retried)

Retry Logic

The SDK automatically retries failed requests with exponential backoff:

  • Retries on 5xx errors and network failures
  • Default: 3 retry attempts
  • Backoff: 1s, 2s, 4s

Configure retry behavior:

const deerdawn = new Deerdawn({
  apiKey: 'dd_prod_xxxxx',
  maxRetries: 5  // More aggressive retries
});

Debug Mode

Enable debug logging to troubleshoot issues:

const deerdawn = new Deerdawn({
  apiKey: 'dd_prod_xxxxx',
  debug: true
});

// Outputs:
// [DeerDawn] POST https://api.deerdawn.com/api/v1/decisions:evaluate
// [DeerDawn] Request body: { action_type: 'send_email', ... }
// [DeerDawn] Response status: 200
// [DeerDawn] Response body: { decision: 'allow', ... }

Examples

AI Agent with DeerDawn Guardrails

const { Deerdawn } = require('deerdawn');
const deerdawn = new Deerdawn({ apiKey: process.env.DEERDAWN_API_KEY });

async function executeAgentAction(actionType, params) {
  // Check permission before executing
  const decision = await deerdawn.evaluateDecision({
    action_type: actionType,
    trace_id: `agent-${Date.now()}`,
    payload: params
  });

  if (decision.decision === 'deny') {
    throw new Error(`Action blocked: ${decision.reason}`);
  }

  if (decision.decision === 'escalate') {
    console.log('Action requires human approval');
    // Queue for manual review
    return { status: 'pending', reason: decision.reason };
  }

  // Proceed with action
  return performAction(actionType, params);
}

// Use in your agent
await executeAgentAction('send_email', {
  recipient: '[email protected]',
  subject: 'AI-generated report'
});

Express.js Middleware

const express = require('express');
const { Deerdawn } = require('deerdawn');

const app = express();
const deerdawn = new Deerdawn({ apiKey: process.env.DEERDAWN_API_KEY });

async function checkPermission(actionType) {
  return async (req, res, next) => {
    try {
      const decision = await deerdawn.evaluateDecision({
        action_type: actionType,
        trace_id: req.headers['x-trace-id'] || `req-${Date.now()}`,
        payload: {
          user: req.user,
          ...req.body
        }
      });

      if (decision.decision !== 'allow') {
        return res.status(403).json({
          error: 'forbidden',
          reason: decision.reason
        });
      }

      next();
    } catch (error) {
      res.status(500).json({ error: 'decision_check_failed' });
    }
  };
}

// Protect routes
app.post('/api/refunds', checkPermission('refund_payment'), (req, res) => {
  // Process refund
});

Support

  • Documentation: https://deerdawn.com/docs
  • API Reference: https://deerdawn.com/docs/api-reference
  • Issues: https://github.com/deerdawn/deerdawn-sdk-node/issues
  • Email: [email protected]

License

MIT