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 🙏

© 2024 – Pkg Stats / Ryan Hefner

otp-device-sync

v1.1.22

Published

lib bounded to opt-device-sync infrastructure that gets OTP from devices

Downloads

442

Readme

OTP Device Sync Library Documentation (NPM)

The otp-device-sync library provides functions to retrieve OTP codes from SMS, email, and time-based sources, facilitating multi-factor authentication (MFA) management in automated testing environments. This documentation explains the installation, usage, and available functions in the otp-device-sync package.

Installation

Install the library from NPM:

npm install otp-device-sync

Importing Functions

The library exports three primary functions for retrieving OTPs from different sources:

import { getTimeBasedCode, getMailComponents, getSMSCode } from 'otp-device-sync'

Each function targets a specific OTP source (time-based, email, or SMS), allowing you to retrieve OTP codes dynamically for 2FA in automated tests.


Function Reference

1. getTimeBasedCode

Retrieves a Time-Based One-Time Password (TOTP) for a specified user and service.

const otpCode = await getTimeBasedCode(user, service, {
  verbose: true,
  registeredKey: 'YOUR_REGISTERED_KEY'
});
  • Parameters:

    • user: The TOTP user label (e.g., account or email).
    • service: The TOTP issuer name.
    • options: { verbose?: boolean, registeredKey: string }
  • Returns: Promise<string> - The OTP code.


2. getMailComponents

Retrieves OTP from an email, returning both the OTP code and email content.

const emailData = await getMailComponents(user, service, {
  verbose: true,
  timeout: 300000,
  registeredKey: 'YOUR_REGISTERED_KEY'
});
  • Parameters:

    • user: The test user's email.
    • service: Identifier for the service sending the OTP.
    • options: { verbose?: boolean, timeout?: number, registeredKey: string }
  • Returns: Promise<{ code: string, text: string, html: string }> - The OTP code, plain text, and HTML content of the email.


3. getSMSCode

Retrieves OTP sent by SMS, for MFA workflows based on text messages.

const smsOTP = await getSMSCode(user, service, {
  verbose: true,
  timeout: 300000,
  registeredKey: 'YOUR_REGISTERED_KEY'
});
  • Parameters:

    • user: The test user's phone number.
    • service: SMS sender identifier.
    • options: { verbose?: boolean, timeout?: number, registeredKey: string }
  • Returns: Promise<{ code: string }> - The OTP code.


Example Usage

Each function can be called in test scripts or any automated setup to handle OTP-based MFA. Here’s a sample using all three functions:

import { getTimeBasedCode, getMailComponents, getSMSCode } from 'otp-device-sync';

// Fetch TOTP
const otpCode = await getTimeBasedCode('[email protected]', 'ServiceName', {
  verbose: true,
  registeredKey: 'YOUR_REGISTERED_KEY'
});
console.log(`TOTP Code: ${otpCode}`);

// Fetch Email OTP
const emailData = await getMailComponents('[email protected]', 'ServiceName', {
  verbose: true,
  timeout: 300000,
  registeredKey: 'YOUR_REGISTERED_KEY'
});
console.log(`Email OTP: ${emailData.code}, Content: ${emailData.text}`);

// Fetch SMS OTP
const smsData = await getSMSCode('1234567890', 'ServiceName', {
  verbose: true,
  timeout: 300000,
  registeredKey: 'YOUR_REGISTERED_KEY'
});
console.log(`SMS OTP: ${smsData.code}`);

Notes

  • Environment Configuration: Ensure API_BASE_URL is configured in your environment to connect to the backend OTP retrieval service.
  • Error Handling: Each function provides verbose logging for error handling. Enable verbose: true in options to see detailed output for troubleshooting.
  • Timeout: Adjust the timeout in getMailComponents and getSMSCode as needed.

This setup enables efficient MFA management in tests by automating OTP retrieval, making it ideal for end-to-end testing with OTP Device Sync.