Node.js client

Zero dependencies — copy this file into your project:

// inboxdome.mjs
export class InboxDome {
  constructor(apiKey, base = 'https://inboxdome.com') {
    this.apiKey = apiKey;
    this.base = base;
  }

  async #req(path, init = {}) {
    const res = await fetch(this.base + path, {
      ...init,
      headers: {
        Authorization: `Bearer ${this.apiKey}`,
        'Content-Type': 'application/json',
        ...init.headers,
      },
    });
    if (!res.ok) {
      const body = await res.json().catch(() => ({}));
      throw new Error(body.error?.message ?? `HTTP ${res.status}`);
    }
    return res.status === 204 ? null : res.json();
  }

  async createInbox(opts = {}) {
    return (await this.#req('/v1/inboxes', { method: 'POST', body: JSON.stringify(opts) })).inbox;
  }
  async listMessages(inboxId) {
    return (await this.#req(`/v1/inboxes/${inboxId}/messages`)).data;
  }
  async getMessage(inboxId, messageId) {
    return (await this.#req(`/v1/inboxes/${inboxId}/messages/${messageId}`)).message;
  }
  async waitForMessage(inboxId, timeoutSeconds = 30) {
    return this.#req(`/v1/inboxes/${inboxId}/wait?timeoutSeconds=${timeoutSeconds}`);
  }
  async waitForOtp(inboxId, timeoutSeconds = 30) {
    const r = await this.#req(`/v1/inboxes/${inboxId}/wait?for=otp&timeoutSeconds=${timeoutSeconds}`);
    return r.otp.value;
  }
  async deleteInbox(inboxId) {
    await this.#req(`/v1/inboxes/${inboxId}`, { method: 'DELETE' });
  }
}

Usage

import { InboxDome } from './inboxdome.mjs';

const client = new InboxDome(process.env.INBOXDOME_KEY);
const inbox = await client.createInbox();
console.log('Use this address:', inbox.emailAddress);

// ... trigger the email in your app ...

const code = await client.waitForOtp(inbox.id, 45);
console.log('OTP:', code);

API reference →