Skip to content
On this page

Node.js SDK

Official Node.js client for the Aegis API. Supports Node.js 18+.

Installation

bash
npm install @aegis-tech/sdk

Quick Start

typescript
import { Aegis } from '@aegis-tech/sdk';

const client = new Aegis({
  apiKey: process.env.AEGIS_API_KEY,
  environment: 'production',
});

// Verify a CPF
const result = await client.verify.cpf({
  cpf: '12345678901',
  name: 'JOAO SILVA SANTOS',
});

console.log(result.status); // 'verified'
console.log(result.score);  // 723

Configuration

typescript
const client = new Aegis({
  apiKey: process.env.AEGIS_API_KEY,
  environment: 'production', // or 'sandbox'
  timeout: 10000,            // ms
  retries: 3,                // auto-retry
  webhookSecret: 'whsec_...',
});

Methods

verify.cpf()

typescript
const result = await client.verify.cpf({
  cpf: '12345678901',
  name: 'JOAO SILVA SANTOS',
  birthDate: '1990-01-15',
});

verify.cnpj()

typescript
const result = await client.verify.cnpj({
  cnpj: '12345678000199',
  companyName: 'ACME LTDA',
});

credit.score()

typescript
const result = await client.credit.score({
  cpf: '12345678901',
});

Error Handling

typescript
import { AegisError, RateLimitError } from '@aegis-tech/sdk';

try {
  const result = await client.verify.cpf({ cpf: '12345678901' });
} catch (error) {
  if (error instanceof RateLimitError) {
    console.log('Rate limited, retry after:', error.retryAfter);
  } else if (error instanceof AegisError) {
    console.log('API error:', error.code, error.message);
  }
}

Webhook Verification

typescript
import { verifyWebhookSignature } from '@aegis-tech/sdk';

app.post('/webhooks/aegis', (req, res) => {
  const isValid = verifyWebhookSignature(
    req.body,
    req.headers['x-aegis-signature'],
    process.env.AEGIS_WEBHOOK_SECRET!
  );
  
  if (!isValid) return res.status(401).send('Invalid');
  
  const { event, data } = req.body;
  res.status(200).send('OK');
});

GitHub

github.com/aegis-tech/node-sdk

Released under the MIT License.