Ƭrivumo Docs
SDK's

Node.js

Use the Trivumo Node.js SDK to generate email addresses, wait for messages, and validate email workflows in your automated tests.


The Trivumo Node.js SDK makes it easy to test email-driven workflows such as account verification, password resets, magic links, invitations, and one-time passwords.

Installation

npm install trivumo

Usage

Create a Client

import { TrivumoClient } from 'trivumo';

const trivumo = new TrivumoClient({
  apiKey: process.env.TRIVUMO_API_KEY!,
  domain: 'sandbox.trivumo.com',
});

Generate an Email Address

const email = trivumo.generateEmail();

console.log(email);
// x7k2m9qp@sandbox.trivumo.com

With a custom username:

const email = trivumo.generateEmail('john');

console.log(email);
// john@sandbox.trivumo.com

Wait for an Email

const message = await trivumo.waitForMessage({
  to: email,
  subject: 'Verify your account',
});

The returned message includes:

  • Metadata
  • HTML content
  • Plain text content
  • Extracted links
  • Extracted images
  • Verification codes and OTPs
  • Email headers

Trigger an Action and Wait for an Email

const message = await trivumo.waitForMessageAfter(
  () => page.click('[type=submit]'),
  {
    to: email,
    subject: 'Verify your account',
  }
);

Only emails received after the action are considered.

Access Verification Codes

const message = await trivumo.waitForMessage({
  to: email,
});

const otp =
  message.html?.codes[0] ??
  message.text?.codes[0];

console.log(otp);
const message = await trivumo.waitForMessage({
  to: email,
});

const verificationLink =
  message.html?.links[0]?.href;

await page.goto(verificationLink!);

Get a Message

const message = await trivumo.getMessage(
  referenceId
);

Search Messages

const messages = await trivumo.getMessages({
  to: email,
});

Example:

const messages = await trivumo.getMessages({
  subject: 'Password Reset',
  receivedAfter: Date.now() - 60_000,
});

API Reference

TrivumoClient

constructor

Creates a new client.

ParameterType
optionsTrivumoClientOptions
const trivumo = new TrivumoClient({
  apiKey: process.env.TRIVUMO_API_KEY!,
  domain: 'sandbox.trivumo.com',
});

generateEmail

Generates a unique email address.

generateEmail(username?: string): string

waitForMessage

Waits until a matching email is received.

ParameterType
filtersMessageFilters
optionsWaitForMessageOptions

Returns: MessageDetails

const message = await trivumo.waitForMessage({
  to: email,
});

waitForMessageAfter

Executes an action and waits for a matching email received afterward.

ParameterType
action() => Promise<unknown> | unknown
filtersMessageFilters
optionsWaitForMessageOptions

Returns: MessageDetails

const message = await trivumo.waitForMessageAfter(
  () => page.click('[type=submit]'),
  {
    to: email,
  }
);

getMessage

Retrieves a message by its reference ID.

ParameterType
referenceIdstring

Returns: MessageDetails

const message = await trivumo.getMessage(
  referenceId
);

getMessages

Searches for messages matching the supplied filters.

ParameterType
filtersMessageFilters

Returns: PaginatedResponse < Message >

const messages = await trivumo.getMessages({
  subject: 'Password Reset',
});

Type Reference

TrivumoClientOptions

interface TrivumoClientOptions {
  apiKey: string;
  domain: string;
  baseUrl?: string;
  timeout?: number;
  retries?: number;
}
PropertyTypeDescription
apiKeystringYour Trivumo API key.
domainstringInbox domain assigned to your team.
baseUrlstringOverride the API endpoint.
timeoutnumberHTTP request timeout in milliseconds.
retriesnumberRetry attempts for transient failures.

MessageFilters

interface MessageFilters {
  subject?: string;
  from?: string;
  to?: string;
  receivedAfter?: number;
}
PropertyTypeDescription
subjectstringFilter by email subject.
fromstringFilter by sender address.
tostringFilter by recipient address.
receivedAfternumberUnix timestamp in milliseconds.

WaitForMessageOptions

interface WaitForMessageOptions {
  timeout?: number;
  pollInterval?: number;
}
PropertyTypeDescription
timeoutnumberMaximum time to wait before throwing an error.
pollIntervalnumberTime between polling attempts.

Message

interface Message {
  id: string;
  referenceId: string;
  subject: string;
  from: string;
  to: string;
  receivedAt: string;
}
PropertyTypeDescription
idstringInternal message identifier.
referenceIdstringStable message reference.
subjectstringEmail subject.
fromstringSender address.
tostringRecipient address.
receivedAtstringISO timestamp when received.

interface Header {
  key: string;
  originalKey: string;
  value: string;
}
PropertyTypeDescription
keystringLowercase header name.
originalKeystringOriginal header name.
valuestringHeader value.

interface ExtractedLink {
  href: string;
  text: string | null;
}
PropertyTypeDescription
hrefstringDestination URL.
textstringnull

ExtractedImage

interface ExtractedImage {
  alt: string | null;
  url: string | null;
  base64: string | null;
}
PropertyTypeDescription
altstringnull
urlstringnull
base64stringnull

MessageBodyPart

interface MessageBodyPart {
  body: string;
  codes: string[];
  links: ExtractedLink[];
  images: ExtractedImage[];
}
PropertyType
bodystring
codesstring[]
linksExtractedLink[]
imagesExtractedImage[]

MessageContent

interface MessageContent {
  headers: Header[];
  html: MessageBodyPart | null;
  text: MessageBodyPart | null;
}
PropertyType
headersHeader[]
htmlMessageBodyPart
textMessageBodyPart

MessageDetails

interface MessageDetails extends Message, MessageContent {}

Complete email including metadata, headers, HTML content, plain text content, extracted links, images, and verification codes.

Composed from:

Example:

const message = await trivumo.waitForMessage({
  to: email,
});

console.log(message.subject);
console.log(message.html?.codes[0]);
console.log(message.html?.links[0]?.href);

PaginatedResponse

export interface PaginatedResponse<T> {
    page: number
    totalPages: number
    data: T[]
}
PropertyType
pagenumber
totalPagesnumber
dataT[]

On this page