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

@courierx/client

v2.0.0

Published

Node.js client for CourierX API

Readme

@courierx/client

Official Node.js client for CourierX email delivery API

npm version

Installation

npm install @courierx/client

Quick Start

import { CourierXClient } from '@courierx/client';

const client = new CourierXClient({
  apiKey: 'your-api-key'
});

const result = await client.send({
  to: ['[email protected]'],
  from: '[email protected]',
  subject: 'Hello from CourierX',
  html: '<p>Hello World!</p>'
});

console.log(`Email sent: ${result.messageId}`);

Features

  • TypeScript Support - Full type safety and IntelliSense
  • Promise-based API - Modern async/await support
  • Automatic Retries - Built-in retry logic for failures
  • Error Handling - Detailed error messages and status codes
  • HMAC Authentication - Optional request signing
  • Rate Limit Handling - Automatic backoff on limits

Authentication

// API Key (required)
const client = new CourierXClient({
  apiKey: 'your-api-key'
});

// With HMAC signing (optional, enhanced security)
const client = new CourierXClient({
  apiKey: 'your-api-key',
  hmacSecret: 'your-hmac-secret',
  enableHmac: true
});

API Reference

Send Email

const result = await client.send({
  to: ['[email protected]'],           // required
  from: '[email protected]',      // required  
  subject: 'Your Subject',            // required
  html: '<p>HTML content</p>',        // optional
  text: 'Plain text content',         // optional
  attachments: [{                     // optional
    filename: 'document.pdf',
    content: 'base64-content',
    contentType: 'application/pdf'
  }],
  headers: { 'X-Custom': 'value' },   // optional
  tags: ['welcome', 'onboarding'],    // optional
  metadata: { userId: '123' }         // optional
});

Get Account Info

const account = await client.me();
console.log(`Rate limit: ${account.usage.remainingThisHour}/${account.product.rateLimitPerHour}`);

Error Handling

import { CourierXError, RateLimitError, ValidationError } from '@courierx/client';

try {
  await client.send(emailRequest);
} catch (error) {
  if (error instanceof RateLimitError) {
    console.log(`Rate limited. Retry after: ${error.retryAfter}s`);
  } else if (error instanceof ValidationError) {
    console.log(`Validation error: ${error.message}`);
  } else if (error instanceof CourierXError) {
    console.log(`API error: ${error.message} (${error.statusCode})`);
  }
}

Configuration

const client = new CourierXClient({
  apiKey: 'your-api-key',
  baseUrl: 'https://api.courierx.dev',  // optional
  timeout: 30000,                       // optional (30s)
  retries: 3,                          // optional
  retryDelay: 1000,                    // optional (1s)
  hmacSecret: 'your-hmac-secret',      // optional
  enableHmac: false                    // optional
});

Environment Variables

COURIERX_API_KEY=your-api-key
COURIERX_BASE_URL=https://api.courierx.dev
COURIERX_HMAC_SECRET=your-hmac-secret
// Auto-loads from environment
const client = new CourierXClient();

Examples

With Attachments

import { readFileSync } from 'fs';

const pdfContent = readFileSync('document.pdf').toString('base64');

await client.send({
  to: ['[email protected]'],
  from: '[email protected]',
  subject: 'Your document',
  html: '<p>Document attached.</p>',
  attachments: [{
    filename: 'document.pdf',
    content: pdfContent,
    contentType: 'application/pdf'
  }]
});

Bulk Email

const users = [
  { email: '[email protected]', name: 'John' },
  { email: '[email protected]', name: 'Jane' }
];

for (const user of users) {
  await client.send({
    to: [user.email],
    from: '[email protected]',
    subject: `Hello ${user.name}!`,
    html: `<p>Hello ${user.name}!</p>`,
    metadata: { userId: user.id },
    tags: ['newsletter']
  });
}

TypeScript

Full type safety included:

import type { SendRequest, SendResponse } from '@courierx/client';

const request: SendRequest = { /* ... */ };
const response: SendResponse = await client.send(request);

License

MIT