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

digits-nodejs-client

v2.0.3

Published

Digits webclient for node.js

Downloads

4

Readme

Standard - JavaScript Style Guide

This is fork of https://github.com/vvanghelue/digits-server-client with following changes

  • rewrote in es6 using async and await (but transpiled using async-to-gen to support Node.js >= v6)
  • added better error handeling support
  • implemented phoneNumber validation using libphonenumber-js

What ?

Node.js alternative to https://docs.fabric.io/web/digits/getting-started.html

Getting started

digits-nodejs-client need the latest Node.js(recommended v6.10) that supports ES6, you can check that requirements with node.green. Or if you still wanna use older version, you can use it with babel-register.

Installation

$ npm install --save digits-nodejs-client

How to use

After you install the package. You can include digits-nodejs-client within your code like this:

var DigitsClient = require('digits-nodejs-client');

Create client

All API operations can be used through a client. So we need to create a Digits client. It takes an object as parameter with these properties:

  • digitsConsumerKey (required and should be a string)
  • digitsHost (required and should be a string)
var digits = new DigitsClient({
	digitsConsumerKey: 'myConsumerKey',
	digitsHost: "https://mydomain.com" //MUST BE HTTPS
});

Note: To get these credentials, read : here

Send code

sendVerificationCode method sends verification code to given phoneNumber. It takes an object as parameter with these following properties:

  • phoneNumber
    • required
    • type String
  • countryCode
    • required
    • type String i.e two-letter ISO country code (like US)
  • headers
    • required
    • type Object with user-agent and accept-language as required properties
  • method
    • optional
    • type String i.e either sms or voicecall
    • default is sms

Example:

digits.sendVerificationCode({
	phoneNumber: '0648446907',
	countryCode: 'FR',
	headers: req.headers // for express.js,
	// method: "voicecall" (sms by default)
}).then(function (registrationToken) {
	//eyJsb2dpblZlcmlmaWNhdGlvblJlcXVlc3RJZCI6InV...
	console.log(registrationToken);
}).then(null, function (error) {
	// error.message
	// error.statusCode
});

As seen in the example in success case it return registrationToken as a result which will be used for verifying the code later. If any errors occured while sending the code then an error is thrown with message and statusCode as properties.

| message | statusCode | |---------| -----------| |Error: Please Configure Digits ConsumerKey and Host| 500| |Error: You attempted to reach Digits by Twitter from a website different than the registered URL for. If you are the website owner, go to our Digits for Web docs to learn more about how to register the correct URL.| 400 | |Error: Unable to get Digits web session| 500| |Error: Please provide req headers: {"user-agent": ...., "accept-language": .....}| 400| |Error: Please provide both phoneNumber and countryCode| 400| |Error: Provided phoneNumber is invalid| 400| |Error: Unable to parse Digits response| 500|

Verify code

It takes an object as parameter with these following properties

  • registrationToken
    • required
    • type String
    • It is the token you got as a result from ``sendVerificationCode` method
  • code
    • required
    • type String
    • It the verfication code sent to given phoneNumber
  • headers
    • required
    • type Object with user-agent and accept-language as required properties

Example:

digits.verifyCode({
	registrationToken: 'eyJsb2dpblZlcmlmaWNhdGlvblJlcXVlc3RJZCI6InV...',
	code: '196099',
	headers: req.headers
}).then(function (result) {
	//{ success: true, phone: '+33648446907'}
	//{ success: false, phone: '+33648446907', errors: []}
	console.log(result);
}).then(null, function (error) {
	// error.message
	// error.statusCode
});

As seen in the example in success case it returns a result object which has following properties

  • success
    • true if code is verified successfully
    • false if code or token are expired or invalid (more in errors property)
  • phone
    • It contains the verified phoneNumber
  • errors
    • It is present when success: false only

    • It contains a message why the verification failed

    • Example:

        "errors": [
          {
            "code": 235,
            "message": "The login verification request has expired"
          }
        ]

If any errors occured while verifying the code then an error is thrown with message and statusCode as properties.

| message | statusCode | |---------| -----------| |Error: Please Configure Digits ConsumerKey and Host| 500| |Error: You attempted to reach Digits by Twitter from a website different than the registered URL for. If you are the website owner, go to our Digits for Web docs to learn more about how to register the correct URL.| 400 | |Error: Unable to get Digits web session| 500| |Error: Please provide req headers: {"user-agent": ...., "accept-language": .....}| 400| |Error: Please provide both registrationToken and code| 400| |Error: Provided registrationToken is invalid(i.e not base64 encoded string)| 400| |Error: Unable to parse Digits response| 500|