Node.js SDK

Official Node.js client for SigninID.

Installation

npm install signinid

Basic Usage

import { SigninID } from 'signinid';

// Set SIGNINID_SECRET_KEY environment variable
const client = new SigninID();

// Wait for a new verification email to arrive
const email = await client.inbox.waitForNew({ to: 'user@test.com' });

// Extract the OTP
if (email) {
  console.log('Verification code:', email.detected_otp);
}

Configuration

The client reads from SIGNINID_SECRET_KEY environment variable by default.

// Using environment variable (recommended)
const client = new SigninID();

// Or pass secret key directly
const client = new SigninID({ secretKey: 'sk_live_...' });

// Custom timeout (default: 30000ms)
const client = new SigninID({ timeout: 60000 });

Client Options

OptionTypeDefaultDescription
secretKeystring | undefinedenv varSecret key (falls back to SIGNINID_SECRET_KEY)
timeoutnumber30000Request timeout in milliseconds

API Reference

client.inbox.waitForNew(params?)

Wait for a new email to arrive. Polls until a new email arrives or timeout is reached.

Example

const email = await client.inbox.waitForNew({ to: 'user@test.com' });
if (email) {
  console.log('OTP:', email.detected_otp);
}

Parameters

ParameterTypeDefaultDescription
tostring-Filter by recipient (partial match)
timeoutnumber30000Maximum wait time in milliseconds

Response Type: Promise<InboxEmail | null>

Returns null if timeout is reached.

FieldTypeDescription
email_idstringUnique identifier
detected_otpstring | nullAuto-extracted verification code
html_bodystring | nullHTML content
text_bodystring | nullPlain text content
from_addressstringSender email address
from_namestring | nullSender display name
to_addressesstring[]Recipient addresses
cc_addressesstring[] | nullCC addresses
subjectstring | nullEmail subject
received_atstringISO 8601 timestamp
message_idstring | nullRFC 5322 Message-ID
has_attachmentsbooleanHas attachments
attachment_countnumberNumber of attachments
spam_scorenumber | nullSpam score (lower is better)
spam_verdictPASS | FAIL | GRAY | nullSpam classification
spam_rulesSpamRules | nullDetailed spam analysis
virus_verdictSecurityVerdictVirus scan result
spf_verdictSecurityVerdictSPF authentication
dkim_verdictSecurityVerdictDKIM verification
dmarc_verdictSecurityVerdictDMARC compliance

client.inbox.latest(params?)

Get the most recent inbox email. Returns null if no email exists.

Example

const email = await client.inbox.latest({ to: 'user@test.com' });
if (email) {
  console.log('OTP:', email.detected_otp);
}

Parameters

ParameterTypeDefaultDescription
tostring-Filter by recipient (partial match)
afterDate | string-Only return emails after this timestamp

Response Type: Promise<InboxEmail | null>

FieldTypeDescription
email_idstringUnique identifier
detected_otpstring | nullAuto-extracted verification code
html_bodystring | nullHTML content
text_bodystring | nullPlain text content
from_addressstringSender email address
from_namestring | nullSender display name
to_addressesstring[]Recipient addresses
cc_addressesstring[] | nullCC addresses
subjectstring | nullEmail subject
received_atstringISO 8601 timestamp
message_idstring | nullRFC 5322 Message-ID
has_attachmentsbooleanHas attachments
attachment_countnumberNumber of attachments
spam_scorenumber | nullSpam score (lower is better)
spam_verdictPASS | FAIL | GRAY | nullSpam classification
spam_rulesSpamRules | nullDetailed spam analysis
virus_verdictSecurityVerdictVirus scan result
spf_verdictSecurityVerdictSPF authentication
dkim_verdictSecurityVerdictDKIM verification
dmarc_verdictSecurityVerdictDMARC compliance

client.inbox.get(emailId)

Get a single inbox email by ID.

Example

const email = await client.inbox.get('550e8400-e29b-41d4-a716-446655440000');
console.log('Subject:', email.subject);

Parameters

ParameterTypeRequiredDescription
emailIdstringYesThe email ID (UUID) to retrieve

Response Type: Promise<InboxEmail>

Throws NotFoundError if not found.

FieldTypeDescription
email_idstringUnique identifier
detected_otpstring | nullAuto-extracted verification code
html_bodystring | nullHTML content
text_bodystring | nullPlain text content
from_addressstringSender email address
from_namestring | nullSender display name
to_addressesstring[]Recipient addresses
cc_addressesstring[] | nullCC addresses
subjectstring | nullEmail subject
received_atstringISO 8601 timestamp
message_idstring | nullRFC 5322 Message-ID
has_attachmentsbooleanHas attachments
attachment_countnumberNumber of attachments
spam_scorenumber | nullSpam score (lower is better)
spam_verdictPASS | FAIL | GRAY | nullSpam classification
spam_rulesSpamRules | nullDetailed spam analysis
virus_verdictSecurityVerdictVirus scan result
spf_verdictSecurityVerdictSPF authentication
dkim_verdictSecurityVerdictDKIM verification
dmarc_verdictSecurityVerdictDMARC compliance

client.inbox.list(params?)

List inbox email IDs with pagination. Use get() to fetch full details.

Example

const { data: emailIds, pagination } = await client.inbox.list({ per_page: 20 });
for (const id of emailIds) {
  const email = await client.inbox.get(id);
  console.log(email.subject);
}

Parameters

ParameterTypeDefaultDescription
pagenumber1Page number (1, 2, 3...)
per_pagenumber10Results per page (1-100)
fromstring-Filter by sender (partial match)
tostring-Filter by recipient (partial match)
subjectstring-Filter by subject (partial match)
beforeDate | string-Emails before this date
afterDate | string-Emails after this date

Response Type: Promise<ListIdsResponse>

FieldTypeDescription
datastring[]Array of email IDs
pagination.pagenumberCurrent page number
pagination.per_pagenumberItems per page
pagination.returnednumberActual count returned
pagination.has_morebooleanMore results available

client.sent.latest(params?)

Get the most recent sent email. Returns null if no email exists.

Example

const email = await client.sent.latest({ to: 'user@example.com' });
if (email) {
  console.log('Spam score:', email.spam_score);
}

Parameters

ParameterTypeDefaultDescription
tostring-Filter by recipient (partial match)

Response Type: Promise<SentEmail | null>

FieldTypeDescription
email_idstringUnique identifier
detected_otpstring | nullAuto-extracted verification code
html_bodystring | nullHTML content
text_bodystring | nullPlain text content
from_addressstringSender email address
from_namestring | nullSender display name
to_addressesstring[]Recipient addresses
cc_addressesstring[] | nullCC addresses
bcc_addressesstring[] | nullBCC addresses
subjectstring | nullEmail subject
sent_atstringISO 8601 timestamp
message_idstring | nullRFC 5322 Message-ID
has_attachmentsbooleanHas attachments
attachment_countnumberNumber of attachments
spam_scorenumber | nullSpam score
spam_verdictPASS | FAIL | GRAY | nullSpam classification

client.sent.get(emailId)

Get a single sent email by ID.

Example

const email = await client.sent.get('660f9500-f39c-52e5-b827-557766551111');
console.log('Subject:', email.subject);

Parameters

ParameterTypeRequiredDescription
emailIdstringYesThe email ID (UUID) to retrieve

Response Type: Promise<SentEmail>

Throws NotFoundError if not found.

FieldTypeDescription
email_idstringUnique identifier
detected_otpstring | nullAuto-extracted verification code
html_bodystring | nullHTML content
text_bodystring | nullPlain text content
from_addressstringSender email address
from_namestring | nullSender display name
to_addressesstring[]Recipient addresses
cc_addressesstring[] | nullCC addresses
bcc_addressesstring[] | nullBCC addresses
subjectstring | nullEmail subject
sent_atstringISO 8601 timestamp
message_idstring | nullRFC 5322 Message-ID
has_attachmentsbooleanHas attachments
attachment_countnumberNumber of attachments
spam_scorenumber | nullSpam score
spam_verdictPASS | FAIL | GRAY | nullSpam classification

client.sent.list(params?)

List sent email IDs with pagination. Use get() to fetch full details.

Example

const { data: emailIds } = await client.sent.list({ per_page: 20 });
for (const id of emailIds) {
  const email = await client.sent.get(id);
  console.log(email.subject);
}

Parameters

ParameterTypeDefaultDescription
pagenumber1Page number (1, 2, 3...)
per_pagenumber10Results per page (1-100)
fromstring-Filter by sender (partial match)
tostring-Filter by recipient (partial match)
subjectstring-Filter by subject (partial match)
beforeDate | string-Emails before this date
afterDate | string-Emails after this date

Response Type: Promise<ListIdsResponse>

FieldTypeDescription
datastring[]Array of email IDs
pagination.pagenumberCurrent page number
pagination.per_pagenumberItems per page
pagination.returnednumberActual count returned
pagination.has_morebooleanMore results available

Error Handling

Error ClassWhen Thrown
AuthenticationErrorInvalid or missing API key
NotFoundErrorEmail not found
ValidationErrorInvalid request parameters
RateLimitErrorToo many requests (includes retryAfter)
NetworkErrorConnection failed
TimeoutErrorRequest timed out
import {
  SigninID,
  AuthenticationError,
  NotFoundError,
  ValidationError,
  RateLimitError,
} from 'signinid';

try {
  const email = await client.inbox.get('invalid-id');
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API key');
  } else if (error instanceof NotFoundError) {
    console.error('Email not found');
  } else if (error instanceof ValidationError) {
    console.error('Invalid parameters:', error.details);
  } else if (error instanceof RateLimitError) {
    console.error('Rate limited. Retry after:', error.retryAfter);
  }
}