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 🙏

© 2026 – Pkg Stats / Ryan Hefner

scaleway-tem

v1.0.0

Published

A clean, type-safe, and fluent Node.js library for sending emails via Scaleway's Transactional Email (TEM) service.

Readme

Scaleway Transactional Email (TEM) Node.js Library

A clean, type-safe, and fluent Node.js library for sending emails via Scaleway's Transactional Email (TEM) service. It also supports the Strategy Pattern to allow switching between different email providers (e.g., SMTP/Mailpit for testing).

Features

  • 🚀 Fluent Builder Pattern: Easily construct complex emails.
  • 🛡️ Type-Safe: Written in TypeScript with full type definitions.
  • 🔌 Strategy Pattern: Switch between Scaleway TEM and SMTP (e.g., Mailpit) easily.
  • 🛠️ Utilities: Helper functions like fileToBase64 for easy attachment handling.
  • 🌍 Scaleway Specific: Tailored for Scaleway's TEM API (v1alpha1).

Table of Contents

Prerequisites

  • Node.js >= 18.0.0
  • A Scaleway account with Transactional Email activated (for production use).

Installation

npm install scaleway-tem-node
# or
yarn add scaleway-tem-node
# or
pnpm add scaleway-tem-node

Configuration

Scaleway TEM

To use Scaleway's Transactional Email service, you need a ScalewayTransporter.

import { ScalewayTransporter } from 'scaleway-tem-node';

const transporter = new ScalewayTransporter({
  secretKey: process.env.SCW_SECRET_KEY, // Your Scaleway Secret Key
  projectId: process.env.SCW_DEFAULT_PROJECT_ID, // Your Project ID
  region: 'fr-par', // Optional: defaults to 'fr-par'
});

SMTP (Development/Testing)

For local development or testing, you can use the SmtpTransporter. This is compatible with tools like Mailpit or any standard SMTP server.

import { SmtpTransporter } from 'scaleway-tem-node';

const transporter = new SmtpTransporter({
  host: 'localhost',
  port: 1025,
  // secure: false, // true for 465, false for other ports
  // auth: {
  //   user: 'user',
  //   pass: 'pass',
  // },
});

Usage

1. Initialize the Client

Pass your configured transporter to the EmailClient.

import { EmailClient, ScalewayTransporter } from 'scaleway-tem-node';

const transporter = new ScalewayTransporter({ /* config */ });
const client = new EmailClient(transporter);

2. Build and Send an Email

Use the EmailBuilder to construct your email.

import { EmailBuilder, fileToBase64 } from 'scaleway-tem-node';

async function sendEmail() {
  // Helper to read file as base64
  const pdfContent = await fileToBase64('./invoice.pdf');

  const email = new EmailBuilder()
    .setFrom('[email protected]', 'My Service')
    .addTo('[email protected]', 'John Doe')
    .setSubject('Your Invoice')
    .setText('Please find your invoice attached.')
    .setHtml('<p>Please find your <b>invoice</b> attached.</p>')
    .addAttachment('invoice.pdf', 'application/pdf', pdfContent)
    .build();

  const result = await client.sendEmail(email);
  console.log('Email sent with ID:', result.id);
}

3. Advanced Usage

The builder supports CC, BCC, custom headers, and scheduling.

const email = new EmailBuilder()
  .setFrom('[email protected]')
  .addTo('[email protected]')
  .addCc('[email protected]')
  .addBcc('[email protected]')
  .addHeader('X-Custom-ID', '12345')
  .setSendBefore(new Date(Date.now() + 3600 * 1000)) // Send before 1 hour from now
  .build();

API Reference

EmailClient

The main entry point for sending emails.

  • constructor(transporter: EmailTransporter)
  • sendEmail(email: DraftEmail | CreateEmailRequest): Promise<Email>
    • Sends the email using the configured transporter.
  • setTransporter(transporter: EmailTransporter): void
    • Switch the transporter at runtime (e.g., based on environment).

EmailBuilder

A fluent interface for creating email objects.

  • setFrom(email: string, name?: string): Set sender.
  • addTo(email: string, name?: string): Add primary recipient.
  • addCc(email: string, name?: string): Add carbon copy recipient.
  • addBcc(email: string, name?: string): Add blind carbon copy recipient.
  • setSubject(subject: string): Set email subject.
  • setText(text: string): Set plain text content.
  • setHtml(html: string): Set HTML content.
  • addAttachment(name: string, type: string, content: string): Add attachment (content must be Base64).
  • addHeader(key: string, value: string): Add custom header.
  • setSendBefore(date: Date): Set expiration time (Scaleway specific).
  • build(): DraftEmail: Returns the constructed email object.

Transporters

ScalewayTransporter

  • Implements EmailTransporter.
  • Uses Scaleway's REST API.
  • Config: { secretKey: string; projectId: string; region?: 'fr-par' }

SmtpTransporter

  • Implements EmailTransporter.
  • Uses nodemailer under the hood.
  • Config: Standard Nodemailer SMTP transport options (host, port, auth, etc.).

Error Handling

The library throws errors if the API call fails or validation fails.

try {
  await client.sendEmail(email);
} catch (error) {
  if (error instanceof Error) {
    console.error('Error message:', error.message);
  }
  // Scaleway specific errors might contain more details in the message
}

Contributing

Contributions are welcome!

  1. Clone the repository.
  2. Install dependencies: npm install
  3. Run tests: npm test
  4. Build: npm run build

License

MIT