Beta Version: The API is under active development and may change without notice. Not recommended for production use until stable version is released.

API Reference

Reference documentation for the OTPDock client.

Installation

npm install @otpdock/client

OtpDockClient

Class

The main client for interacting with OTPDock services.

new OtpDockClient(apiKey, config?)

Parameters

ParameterTypeDescription
apiKey
string
Your OTPDock API key
configoptional
Config
Optional configuration options
import { OtpDockClient } from '@otpdock/client';

const client = new OtpDockClient('your_api_key_here', {
  debug: false
});

generateTemporaryInbox(options?): Promise<TemporaryInbox>

Creates a new temporary email inbox for testing.

Parameters

ParameterTypeDescription
options.prefixoptional
string
Prefix for the generated email address
Default: undefined

Returns

A new TemporaryInbox instance
Promise<TemporaryInbox>
const inbox = await client.generateTemporaryInbox({
  prefix: 'test' // Optional: Add prefix to the generated email
});

console.log(inbox.email); // e.g. test-abc123@otpdock.com

TemporaryInbox

Class

Represents a temporary email inbox for receiving OTP codes.

Properties

ParameterTypeDescription
email
string
The email address of this inbox

getOtp(options?): Promise<string>

Waits for and retrieves an OTP code from the inbox.

Parameters

ParameterTypeDescription
options.timeoutoptional
number
Maximum time to wait in milliseconds
Default: 10000
options.intervaloptional
number
Polling interval in milliseconds
Default: 1000
options.sinceoptional
number
Only check emails after this timestamp
Default: Date.now()
options.extractOtpoptional
(emailBody: string) => string | null
Custom function to extract OTP from email body

Returns

The extracted OTP code
Promise<string>

Throws

  • When OTP email is not received within timeout period
  • When OTP cannot be extracted from the email
  • When API request fails
const otp = await inbox.getOtp({
  timeout: 20000,
  interval: 1000,
  since: Date.now(),
  extractOtp: (emailBody) => {
    const match = emailBody.match(/your-regex-here/);
    return match ? match[1] : null;
  }
});

Type Definitions

Config

type Config = {
  /**
   * Enable detailed logging
   * @default false
   */
  debug?: boolean;
};

GenerateInboxOptions

type GenerateInboxOptions = {
  /**
   * Prefix for the generated email address
   * @example "test" -> "test-abc123@otpdock.com"
   */
  prefix?: string;
};

GetOtpOptions

type GetOtpOptions = {
  /**
   * Maximum time to wait for OTP in milliseconds
   * @default 10000
   */
  timeout?: number;

  /**
   * Polling interval in milliseconds
   * @default 1000
   */
  interval?: number;

  /**
   * Only check emails after this timestamp
   * @default Date.now()
   */
  since?: number;

  /**
   * Custom function to extract OTP from email body
   */
  extractOtp?: (emailBody: string) => string | null;
};