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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@try-veil/veil-gateway

v0.0.1

Published

Node.js SDK for Veil API Gateway Management Server

Readme

Veil Node.js SDK

A comprehensive TypeScript/JavaScript SDK for the Veil API Gateway Management Server. This SDK provides a simple and intuitive interface for managing API configurations, API keys, and routing through the Veil Caddy module.

Installation

npm install @veil/nodejs-sdk

Quick Start

import { VeilClient } from '@veil/nodejs-sdk';

// Create a client instance
const client = new VeilClient({
  baseUrl: 'http://localhost:2020', // Management API URL
  timeout: 30000
});

// Onboard a new API
const response = await client.onboardAPI({
  path: '/weather/*',
  upstream: 'http://localhost:8083/weather',
  required_subscription: 'weather-subscription',
  methods: ['GET'],
  required_headers: ['X-Test-Header'],
  api_keys: [{
    key: 'weather-api-key-1',
    name: 'Weather API Key',
    is_active: true
  }]
});

console.log('API onboarded:', response);

Features

  • Complete API Management: Onboard, update, patch, and delete API configurations
  • API Key Management: Add, delete, and manage API key status
  • TypeScript Support: Full type definitions included
  • Error Handling: Comprehensive error handling with detailed error information
  • Promise-based: Modern async/await support
  • Configurable: Flexible client configuration options

API Reference

Client Configuration

interface VeilClientOptions {
  baseUrl?: string;      // Default: 'http://localhost:2020'
  timeout?: number;      // Default: 30000ms
  headers?: Record<string, string>; // Additional headers
}

API Management

Onboard API

await client.onboardAPI({
  path: '/api/*',
  upstream: 'http://localhost:8080/api',
  required_subscription: 'premium',
  methods: ['GET', 'POST'],
  required_headers: ['Authorization'],
  api_keys: [{
    key: 'api-key-123',
    name: 'Production Key',
    is_active: true
  }]
});

Update API

await client.updateAPI('/api/*', {
  path: '/api/*',
  upstream: 'http://localhost:8081/api',
  methods: ['GET', 'POST', 'PUT'],
  // ... other fields
});

Partial Update API

await client.patchAPI('/api/*', {
  upstream: 'http://localhost:8082/api'
});

Delete API

await client.deleteAPI('/api/*');

API Key Management

Add API Keys

await client.addAPIKeys({
  path: '/api/*',
  api_keys: [{
    key: 'new-key-456',
    name: 'New API Key',
    is_active: true
  }]
});

Update API Key Status

await client.updateAPIKeyStatus({
  path: '/api/*',
  api_key: 'api-key-123',
  is_active: false
});

Delete API Key

await client.deleteAPIKey({
  path: '/api/*',
  api_key: 'api-key-123'
});

Error Handling

The SDK provides comprehensive error handling through the VeilError class:

import { VeilError } from '@veil/nodejs-sdk';

try {
  await client.onboardAPI(apiConfig);
} catch (error) {
  if (error instanceof VeilError) {
    console.error('Veil API Error:', error.message);
    console.error('Status Code:', error.status);
    console.error('Response:', error.response);
  } else {
    console.error('Unexpected error:', error);
  }
}

Examples

Complete API Lifecycle

import { VeilClient } from '@veil/nodejs-sdk';

const client = new VeilClient();

async function apiLifecycle() {
  try {
    // 1. Onboard a new API
    const onboardResponse = await client.onboardAPI({
      path: '/weather/*',
      upstream: 'http://localhost:8083/weather',
      required_subscription: 'weather-subscription',
      methods: ['GET'],
      required_headers: ['X-Test-Header'],
      api_keys: [{
        key: 'initial-weather-key',
        name: 'Initial Weather Key',
        is_active: true
      }]
    });
    
    console.log('✅ API onboarded:', onboardResponse.message);

    // 2. Add additional API keys
    await client.addAPIKeys({
      path: '/weather/*',
      api_keys: [{
        key: 'additional-weather-key',
        name: 'Additional Weather Key',
        is_active: true
      }]
    });
    
    console.log('✅ API keys added');

    // 3. Deactivate a key
    await client.updateAPIKeyStatus({
      path: '/weather/*',
      api_key: 'initial-weather-key',
      is_active: false
    });
    
    console.log('✅ API key deactivated');

    // 4. Update API configuration
    await client.patchAPI('/weather/*', {
      methods: ['GET', 'POST']
    });
    
    console.log('✅ API updated');

    // 5. Clean up - delete API
    await client.deleteAPI('/weather/*');
    console.log('✅ API deleted');

  } catch (error) {
    console.error('❌ Error:', error.message);
  }
}

apiLifecycle();

Multiple Environment Setup

import { VeilClient } from '@veil/nodejs-sdk';

// Development environment
const devClient = new VeilClient({
  baseUrl: 'http://localhost:2020'
});

// Production environment
const prodClient = new VeilClient({
  baseUrl: 'https://api-gateway.prod.example.com',
  timeout: 60000,
  headers: {
    'X-Environment': 'production'
  }
});

TypeScript Support

The SDK is written in TypeScript and provides complete type definitions:

import type { 
  APIOnboardRequest, 
  APIResponse, 
  APIConfig,
  VeilClientOptions 
} from '@veil/nodejs-sdk';

const config: APIOnboardRequest = {
  path: '/api/*',
  upstream: 'http://localhost:8080',
  methods: ['GET', 'POST'],
  // TypeScript will provide autocomplete and validation
};

Architecture

The Veil system operates on two main ports:

  • Port 2020: Management API for onboarding and configuration (this SDK)
  • Port 2021: Proxied APIs with validation and key authentication

This SDK interacts with the management API (port 2020) to configure the gateway. Your applications will then make requests to the proxied APIs (port 2021) using the configured API keys.

Contributing

Contributions are welcome! Please see the main Veil repository for contribution guidelines.

License

MIT License - see LICENSE file for details.

Support

For issues and questions:

  • GitHub Issues: https://github.com/try-veil/veil/issues
  • Documentation: https://github.com/try-veil/veil#readme