telesignenterprisesdk
Version:
This SDK enhances the functionality of the Telesign Self-service Node SDK, providing access to a broader range of Telesign APIs. See our source code on GitHub (https://github.com/TeleSign/node_telesign_enterprise) for installation instructions and other d
142 lines (123 loc) • 5.72 kB
JavaScript
const Telesign = require('telesignsdk');
const util = require('util')
const { getInstalledVersion, getVersionDependency } = require('./helpers.js');
/***
* PhoneID is a set of REST APIs that deliver deep phone number data attributes that help optimize the end user
* verification process and evaluate risk.
*
* TeleSign PhoneID provides a wide range of risk assessment indicators on the number to help confirm user identity,
* delivering real-time decision making throughout the number lifecycle and ensuring only legitimate users are
* creating accounts and accessing your applications.
*/
class PhoneID {
constructor(customerId,
apiKey,
restEndpoint = "https://rest-ww.telesign.com",
timeout = 10000,
userAgent = null) {
const sdkVersionOrigin = getInstalledVersion()
const sdkVersionDependency = getVersionDependency("telesignsdk")
this.rest = new Telesign(customerId, apiKey, restEndpoint, timeout, userAgent, "node_telesign_enterprise", sdkVersionOrigin, sdkVersionDependency).rest;
this.standardResource = "/v1/phoneid/standard/%s"
this.liveResource = "/v1/phoneid/live/%s"
this.numberDeactivationResource = "/v1/phoneid/number_deactivation/%s"
this.getInfoResource = "/v1/phoneid/%s"
this.getInfoAltResource = "/v1/phoneid"
}
/***
* The PhoneID Standard API that provides phone type and telecom carrier information to identify which phone
* numbers can receive SMS messages and/or a potential fraud risk.
*
* See https://developer.telesign.com/docs/rest_phoneid-standard for detailed API documentation.
*
* @param callback: Callback method to handle response.
* @param phoneNumber: Phone number associated with the event.
* @param optionalParams: Dictionary of all optional parameters.
* transaction.
*/
standard(callback, phoneNumber, optionalParams = null) {
var params = {
phone_number: phoneNumber
};
if (optionalParams != null) {
params = Object.assign(params, optionalParams)
}
this.rest.execute(callback, "GET", util.format(this.standardResource, phoneNumber), params);
}
/***
* The PhoneID Live API delivers insights such as whether a phone is active or disconnected, a device is reachable
* or unreachable and its roaming status.
*
* See https://developer.telesign.com/enterprise/reference/submitphonenumberforlivestatus for detailed API documentation.
*
* @param callback: Callback method to handle response.
* @param phoneNumber: Phone number associated with the event.
* @param ucid: A string that specifies one of the use case codes.
*/
live(callback, phoneNumber, ucid = null) {
const params = {};
if (ucid) {
params['ucid'] = ucid;
}
this.rest.execute(callback, "GET", util.format(this.liveResource, phoneNumber), params);
}
/***
* The PhoneID Number Deactivation API determines whether a phone number has been deactivated and when, based on
* carriers' phone number data and TeleSign's proprietary analysis.
*
* See https://developer.telesign.com/docs/rest_api-phoneid-number-deactivation for detailed API documentation.
*
* @param callback: Callback method to handle response.
* @param phoneNumber: Phone number associated with the event.
* @param ucid: A string that specifies one of the use case codes.
* @param optionalParams: Dictionary of all optional parameters.
* transaction.
*/
numberDeactivation(callback, phoneNumber, ucid, optionalParams = null) {
var params = {
phone_number: phoneNumber,
ucid: ucid
};
if (optionalParams != null) {
params = Object.assign(params, optionalParams)
}
this.rest.execute(callback, "GET", util.format(this.numberDeactivationResource, phoneNumber), params);
}
/**
* Enter a phone number with country code to receive detailed information about carrier, location, and other details.
*
* See https://developer.telesign.com/enterprise/reference/submitphonenumberforidentity for detailed API documentation.
*
* @param callback: Callback method to handle response.
* @param phoneNumber: Phone number associated with the event.
* @param optionalParams: Dictionary of all optional parameters.
*/
getInfo(callback, phoneNumber, optionalParams = {}) {
if (!optionalParams.hasOwnProperty('consent')) {
optionalParams.consent = {
method: 1
};
}
this.rest.execute(callback, "POST", util.format(this.getInfoResource, phoneNumber), optionalParams);
}
/**
* Enter a phone number with country code to receive detailed information about carrier, location, and other details.
*
* See https://developer.telesign.com/enterprise/reference/submitphonenumberforidentityalt for detailed API documentation.
*
* @param callback: Callback method to handle response.
* @param phoneNumber: Phone number associated with the event.
* @param optionalParams: Dictionary of all optional parameters.
*/
getInfoAlt(callback, phoneNumber, optionalParams = {}) {
optionalParams.phone_number = phoneNumber;
if (!optionalParams.hasOwnProperty('consent')) {
optionalParams.consent = {
method: 1
};
}
this.rest.setContentType("application/json");
this.rest.execute(callback, "POST", this.getInfoAltResource, optionalParams);
}
}
module.exports = PhoneID;