Installation

Install the CyberVault SDK using your preferred package manager. The package supports both CommonJS and ES Modules.

Install via Package Manager

bash
npm install @cybervault/node-sdk
💡
Peer Dependencies The SDK requires Node.js 18 or higher. For browser-based bundling (e.g., Next.js), ensure you configure externalization for the crypto module.

Quick Start

Initialize the SDK with your API key and start detecting threats in just a few lines of code.

typescript
import { CyberVault } from '@cybervault/node-sdk';

// Initialize the client with your API key
const cv = new CyberVault({
  apiKey: process.env.CV_API_KEY,
  environment: 'production', // or 'sandbox'
  timeout: 5000 // milliseconds
});

// Scan a payload for threats
async function analyzePayload(data: string) {
  try {
    const result = await cv.threats.scan({
      content: data,
      mode: 'deep'
    });

    if (result.isThreat) {
      console.warn(`Threat detected: ${result.threatType}`);
      // Trigger incident response
      await cv.incidents.report(result);
    }

    return result;
  } catch (error) {
    console.error('Scan failed:', error);
    throw error;
  }
}

// Usage
analyzePayload('Suspicious input string...');
⚠️
Secure Your API Key Never hardcode your API key in your source code. Use environment variables or a secrets manager. The SDK will throw a ConfigurationError if no key is provided.

Configuration

The SDK accepts a configuration object during initialization. All options are optional except apiKey.

Parameter Type Required Description
apiKey string Required Your CyberVault API key obtained from the dashboard.
environment 'production' | 'sandbox' Optional Target environment. Defaults to production.
timeout number Optional Request timeout in milliseconds. Defaults to 10000.
retries number Optional Number of retry attempts on failure. Defaults to 3.
logger Logger | boolean Optional Custom logger instance or false to disable. Defaults to console.
webhooks WebhookConfig Optional Configuration for local webhook listeners for real-time events.

API Reference

threats.scan()

Performs a comprehensive threat analysis on the provided content using CyberVault's AI engine.

typescript
interface ScanOptions {
  content: string | Buffer;      // Data to scan
  mode: 'quick' | 'deep' | 'full'; // Scan depth
  tags?: string[];                // Custom metadata tags
}

interface ScanResult {
  scanId: string;
  isThreat: boolean;
  threatType: string | null;
  confidence: number; // 0.0 to 1.0
  indicators: Indicator[];
  timestamp: Date;
}

compliance.check()

Validates data or system configurations against specified compliance frameworks (SOC2, GDPR, HIPAA, etc.).

typescript
const report = await cv.compliance.check({
  framework: 'SOC2',
  target: 'user-data-pipeline',
  includeRemediation: true
});

console.log(report.score); // e.g., 94.5
console.log(report.violations); // Array of violations

TypeScript Support

The SDK is written in TypeScript and ships with complete type definitions. No additional @types package is required.

bash
// Full type safety out of the box
import type { ScanOptions, CyberVaultError } from '@cybervault/node-sdk';

Error Handling

The SDK throws specific error classes to help you handle failures gracefully.

Error Class Description Common Cause
CyberVaultAuthenticationError Invalid or missing API key. Typo in key, expired token.
CyberVaultRateLimitError Too many requests. Exceeded plan limits.
CyberVaultNetworkError Connection timeout or DNS failure. Network issues, firewall blocking.
CyberVaultValidationError Invalid input parameters. Wrong data types, missing fields.
typescript
import { CyberVaultRateLimitError } from '@cybervault/node-sdk';

try {
  await cv.threats.scan('...');
} catch (error) {
  if (error instanceof CyberVaultRateLimitError) {
    console.warn('Rate limited. Retrying in 5s...');
    // Implement exponential backoff
  }
}