Node.js SDK
Node.js SDK
Section titled “Node.js SDK”Official Node.js SDK for SSH-KLM.
Installation
Section titled “Installation”npm install @qcecuring/ssh-sdk# oryarn add @qcecuring/ssh-sdkRequirements
Section titled “Requirements”- Node.js 18.x or later
- TypeScript 5.x (optional, types included)
Quick Start
Section titled “Quick Start”import { QcClient } from '@qcecuring/ssh-sdk';
const client = new QcClient({ apiKey: process.env.SSHKLM_API_KEY, baseUrl: 'https://api.qcecuring.com' // Optional});
// List hostsconst hosts = await client.ssh.listHosts();console.log(hosts);Configuration
Section titled “Configuration”const client = new QcClient({ apiKey: 'sk_live_...', baseUrl: 'https://api.qcecuring.com', timeout: 30000, // 30 seconds retries: 3, debug: false});TypeScript Support
Section titled “TypeScript Support”Full TypeScript support with type definitions:
import { QcClient, Host, SshKey, RotationPolicy } from '@qcecuring/ssh-sdk';
const client = new QcClient({ apiKey: process.env.API_KEY! });
const hosts: Host[] = await client.ssh.listHosts();const keys: SshKey[] = await client.ssh.listKeys({ hostId: hosts[0].id });Common Operations
Section titled “Common Operations”Discovery
Section titled “Discovery”// Start discoveryconst scan = await client.ssh.startDiscovery({ hosts: ['*.example.com']});
// Wait for completionconst result = await client.ssh.waitForScan(scan.id, { timeout: 300000, pollInterval: 5000});Rotation
Section titled “Rotation”// Rotate keyawait client.ssh.rotateKey({ keyId: 'key_123', algorithm: 'ed25519'});Ephemeral Access
Section titled “Ephemeral Access”const creds = await client.ssh.requestEphemeral({ host: 'server.example.com', username: 'admin', ttl: 300});
// Use credentialsconsole.log(creds.privateKey);Error Handling
Section titled “Error Handling”import { QcClient, QcError, RateLimitError } from '@qcecuring/ssh-sdk';
try { await client.ssh.rotateKey({ keyId: 'invalid' });} catch (error) { if (error instanceof RateLimitError) { await sleep(error.retryAfter); // Retry... } else if (error instanceof QcError) { console.error(`Error: ${error.code} - ${error.message}`); }}