Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

telesignsdk

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telesignsdk - npm Package Compare versions

Comparing version 2.2.3 to 3.0.0

src/Constants.js

14

LICENSE.txt

@@ -1,9 +0,9 @@

Copyright (c) 2017 TeleSign Corp.
Copyright (c) 2023 Telesign Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

@@ -10,0 +10,0 @@ The above copyright notice and this permission notice shall be included in all

{
"name": "telesignsdk",
"version": "2.2.3",
"version": "3.0.0",
"description": "Official TeleSign SDK for Rest APIs including Messaging (SMS), Score, PhoneID, Voice, and AppVerify",

@@ -11,18 +11,7 @@ "repository": {

"scripts": {
"test": "node ./test/testClients.js | tap-spec",
"coverage": "istanbul cover ./test/*.js"
"test": "node ./test/test.suite.js"
},
"dependencies": {
"os": "0.1.1",
"querystring": "0.2.0",
"request": "^2.88.0",
"urijs": "^1.18.10",
"uuid-v4.js": "1.0.2"
},
"devDependencies": {
"istanbul": "^0.4.5",
"proxyquire": "^1.8.0",
"sinon": "^3.0.0",
"tap-spec": "^4.1.1",
"tape": "^4.7.0"
},

@@ -29,0 +18,0 @@ "keywords": [

@@ -1,125 +0,42 @@

[<img src="/node_banner.jpg">](https://developer.telesign.com)
[<img src="https://img.shields.io/travis/TeleSign/node_telesign.svg">](https://travis-ci.org/TeleSign/node_telesign) [<img src="https://img.shields.io/codecov/c/github/TeleSign/node_telesign.svg">](https://codecov.io/gh/TeleSign/node_telesign) [![npm](https://img.shields.io/npm/v/telesignsdk.svg)](https://www.npmjs.com/package/telesignsdk) [![npm](https://img.shields.io/npm/l/telesignsdk.svg)](https://github.com/TeleSign/node_telesign/blob/master/LICENSE.txt)
[![npm](https://img.shields.io/npm/v/telesignsdk.svg)](https://www.npmjs.com/package/telesignsdk) [![license](https://img.shields.io/npm/l/telesignsdk.svg)](https://github.com/TeleSign/node_telesign/blob/master/LICENSE.txt)
TeleSign Node.js SDK
=================
# TeleSign Self-service Node.js SDK
TeleSign is a communications platform as a service (CPaaS) company, founded on security. Since 2005, TeleSign has
been a trusted partner to the world’s leading websites and mobile applications, helping secure billions of end-user
accounts. Today, TeleSign’s data-driven, cloud communications platform is changing the way businesses engage with
customers and prevent fraud.
[Telesign](https://telesign.com) connects, protects, and defends the customer experience with intelligence from billions of digital interactions and mobile signals. Through developer-friendly APIs that deliver user verification, digital identity, and omnichannel communications, we help the world's largest brands secure onboarding, maintain account integrity, prevent fraud, and streamline omnichannel engagement.
For more information about TeleSign, visit our [website](http://www.TeleSign.com>).
## Requirements
* **Node.js 6+**
* **npm** *(Optional)* - This package manager isn't required to use this SDK, but it is required to use the installation instructions below.
Documentation
-------------
> **NOTE:**
>
> These instructions are for MacOS. They will need to be adapted if you are installing on Windows.
Code documentation is included in the SDK. Complete documentation, quick start guides and reference material
for the TeleSign API is available within the [TeleSign Standard Documentation](https://standard.telesign.com/).
## Installation
Follow these steps to add this SDK as a dependency to your project.
Installation
------------
1. *(Optional)* Create a new directory for your Node.js project. Skip this step if you already have created a project. If you plan to create multiple Node.js projects that use Telesign, we recommend that you group them within a `telesign_integrations` directory.
To add the TeleSign Node.js SDK using NPM to your Node.js project:
```
npm install telesignsdk -save
cd ~/code/local
mkdir telesign_integrations
cd telesign_integrations
mkdir {your project name}
cd {your project name}
```
If you have already cloned this SDK, you can using the following command
```
npm install /path/to/sdk -save
```
2. Install the SDK as a dependency in the top-level directory of your project using the command below. Once the SDK is installed, you should see a message in the terminal notifying you that you have successfully installed the SDK.
Node.js **6+** is required for the TeleSign Node.js SDK.
`npm install telesignsdk --save`
Authentication
--------------
## Authentication
You will need a Customer ID and API Key in order to use TeleSign’s API. If you already have an account you can retrieve
them from your account dashboard within the [Portal](https://portal.telesign.com/login). If you have not signed up
yet, sign up [here](https://portal.telesign.com/signup).
If you use a Telesign SDK to make your request, authentication is handled behind-the-scenes for you. All you need to provide is your Customer ID and API Key(or password). The SDKs apply Digest authentication whenever they make a request to a Telesign service where it is supported. Intelligence uses Basic authentication.
## What's next
Dependencies
------------
We make use of popular, feature-rich and well-tested open-source libraries to perform the underlying functionality of
the SDK. These dependencies are managed by the community accepted package manager. If you are unable to add these
additional third party dependencies to your project we have ensured that the SDK code is easy to read and can serve as
sample code. We have also made sure that more complicated functions such as generate_telesign_headers can be easily
extracted from the SDK and used 'as is' in your project.
Examples
========
**How to Run**
1. Edit file and replace values for API Key, Customer ID, and mobile_number
2. Run the file via : node filename.js
Example: You can run the 1_send_message.js with the following command
```
node examples/messaging/1_send_message.js
```
Sample code: Messaging (SMS)
----------------------------------------
After installing the SDK, begin by including the telesign SDK and declaring customerId, apiKey, restEndpoint, and
timeout variables.
Setup Telesign Client
```javascript
var TeleSignSDK = require('telesignsdk');
var customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"; // find in portal.telesign.com
var apiKey = "EXAMPLE----TE8sTgg45yusumoN4BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
var restEndpoint = "https://rest-api.telesign.com";
var timeout = 10*1000; // 10 secs
var telesign = new TeleSignSDK( customerId,
apiKey,
restEndpoint,
timeout // optional
);
```
Send an SMS
```javascript
var phoneNumber = "phone_number"; // Your end user’s phone number, as a string of digits without spaces or
// punctuation, beginning with the country dialing code (for example, “1” for North America)
var message = "You're scheduled for a dentist appointment at 2:30PM.";
var messageType = "ARN"; // ARN = Alerts, Reminders, and Notifications; OTP = One time password; MKT = Marketing
var referenceId = null; // need this to check status later
telesign.sms.message(function(err, reply){
if(err){
console.log("Error: Could not reach TeleSign's servers");
console.error(err); // network failure likely cause for error
}
else{
console.log("YAY!, the SMS message is being sent now by TeleSign!");
console.log(reply);
referenceId=reply.reference_id; // save the reference_id to check status of the message
}
},
phoneNumber,
message,
messageType
);
```
Further reading
---------------
* If you are using the trial account, make sure you understand it has some limitations.
Use only the phone number you have verified.
* For documentation, see the [TeleSign Standard Documentation](https://standard.telesign.com).
* Code examples can be found [here](/examples).
* Learn to send a request to Telesign with code with one of our [tutorials](https://developer.telesign.com/enterprise/docs/tutorials).
* Browse our [Developer Portal](https://developer.telesign.com) for tutorials, how-to guides, reference content, and more.
* Check out our [sample code](https://github.com/TeleSign/sample_code) on GitHub.

@@ -9,3 +9,4 @@ const RestClient = require("./RestClient.js");

constructor(customerId,
constructor(requestWrapper,
customerId,
apiKey,

@@ -15,3 +16,3 @@ restEndpoint = null,

userAgent = null) {
super(customerId, apiKey, restEndpoint, timeout, userAgent);
super(requestWrapper, customerId, apiKey, restEndpoint, timeout, userAgent);

@@ -18,0 +19,0 @@ this.appverify_resource = "/v1/mobile/verification/status/";

@@ -10,3 +10,4 @@ const RestClient = require("./RestClient.js");

constructor(customerId,
constructor(requestWrapper,
customerId,
apiKey,

@@ -16,3 +17,3 @@ restEndpoint = null,

userAgent = null) {
super(customerId, apiKey, restEndpoint, timeout, userAgent);
super(requestWrapper, customerId, apiKey, restEndpoint, timeout, userAgent);

@@ -19,0 +20,0 @@ this.messaging_resource = "/v1/messaging";

@@ -9,3 +9,4 @@ const RestClient = require("./RestClient.js");

constructor(customerId,
constructor(requestWrapper,
customerId,
apiKey,

@@ -15,3 +16,3 @@ restEndpoint = null,

useragent = null) {
super(customerId, apiKey, restEndpoint, timeout, useragent);
super(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);

@@ -18,0 +19,0 @@ this.phoneid_resource = "/v1/phoneid/";

@@ -1,8 +0,5 @@

const os = require('os');
const request = require('request');
const uuidV4Js = require("uuid-v4.js");
const crypto = require("crypto");
const URI = require('urijs');
const querystring = require('querystring');
const packagejson = require('../package.json');
const fs = require('fs');
const path = require('path');
const Constants = require('./Constants.js');

@@ -17,7 +14,10 @@ /***

constructor(customerId,
constructor(requestWrapper,
customerId,
apiKey,
restEndpoint = "https://rest-api.telesign.com",
timeout = 15000,
userAgent = null) {
userAgent = null,
contentType = "application/x-www-form-urlencoded") {
this.requestWrapper = requestWrapper
this.customerId = customerId;

@@ -27,10 +27,15 @@ this.apiKey = apiKey;

this.timeout = timeout;
this.contentType = "application/x-www-form-urlencoded";
this.contentType = contentType ;
try {
if (userAgent === null) {
this.userAgent = `TeleSignSDK/ECMAScript-Node v ${packagejson.version}`
+ ` ${os.arch()}`
+ `/${os.platform()}`
+ `-v${os.release()}`; // Generates a Node useragent - helpful in diagnosing errors
const packageJsonPath = path.join(__dirname, '..', 'package.json')
const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
const packageData = JSON.parse(packageJson);
const version = packageData.version;
this.userAgent = `TeleSignSDK/ECMAScript-Node v ${version}`
+ ` ${process.arch}`
+ `/${process.platform}`
+ ` ${process.release.name}`
+ `/${process.version}`; // Generates a Node useragent - helpful in diagnosing errors
}

@@ -64,2 +69,3 @@ }

* @param userAgent: (optional) User Agent associated with the request, as a string.
* @param authMethod : (optional) Authentication type. For ex: Basic, HMAC etc
* @returns headers: {{Authorization: string, Date: *, Content-Type: string,

@@ -76,3 +82,4 @@ * x-ts-auth-method: string, x-ts-nonce: *}}

nonce = null,
userAgent = null) {
userAgent = null,
authMethod=null) {

@@ -84,3 +91,3 @@ if (date == null) {

if (nonce == null) {
nonce = uuidV4Js(); // generates a Random NONCE (Number Used Only Once)
nonce = crypto.randomUUID(); // generates a Random NONCE (Number Used Only Once)
}

@@ -90,3 +97,3 @@

contentType : "";
var authMethod = "HMAC-SHA256";
var authMethod = authMethod!=null ? authMethod: Constants.AuthMethodNames.HMAC_SHA256;

@@ -104,13 +111,16 @@ var urlencoded = "";

"\n" + resource;
if(authMethod === Constants.AuthMethodNames.BASIC){
var authorization = "Basic " + Buffer.from(customerId + ":" + apiKey).toString('base64');
}else{
var signedStrUTF8 = stringToSignBuilder.toString('utf8');
var decodedAPIKey = Buffer.from(apiKey, 'base64');
var signedStrUTF8 = stringToSignBuilder.toString('utf8');
var decodedAPIKey = Buffer.from(apiKey, 'base64');
var jsSignature = crypto.createHmac("sha256", decodedAPIKey)
.update(signedStrUTF8)
.digest("base64")
.toString('utf8');
// console.log("js Signature: " + jsSignature);
var jsSignature = crypto.createHmac("sha256", decodedAPIKey)
.update(signedStrUTF8)
.digest("base64")
.toString('utf8');
// console.log("js Signature: " + jsSignature);
var authorization = "TSA " + customerId + ":" + jsSignature;
var authorization = "TSA " + customerId + ":" + jsSignature;
}
var headers = {

@@ -136,5 +146,6 @@ "Authorization": authorization,

* @param resource: The partial resource URI to perform the request against, as a string.
* @param authMethod: (optional) Authentication type. For ex: Basic, HMAC etc
* @param params: Body params to perform the HTTP request with, as a dictionary.
*/
execute(callback, methodName, resource, params = null) {
execute(callback, methodName, resource, params = null, authMethod = null, nonce = null, date = null) {
var telesignURL = this.restEndpoint + resource;

@@ -145,3 +156,4 @@ var bodyData = this.contentType=="application/json" ? "{}" : null;

if (this.contentType == "application/x-www-form-urlencoded") {
bodyData = querystring.stringify(params);
const urlSearchParams = new URLSearchParams(params);
bodyData = urlSearchParams.toString();
} else {

@@ -154,6 +166,8 @@ bodyData = JSON.stringify(params);

if (params != null) {
telesignURL = URI(this.restEndpoint + resource).query(params).toString();
var url = new URL(this.restEndpoint + resource);
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
telesignURL = url.toString();
}
else {
telesignURL = URI(this.restEndpoint + resource).toString();
telesignURL = new URL(this.restEndpoint + resource).toString();
}

@@ -168,9 +182,10 @@ }

bodyData,
null,
null,
this.userAgent);
date !== null ? date : null,
nonce,
this.userAgent,
authMethod);
var requestParams = {
headers: headers,
uri: telesignURL,
url: telesignURL,
method: methodName,

@@ -184,7 +199,7 @@ timeout: this.timeout

request(requestParams, function (err, res, bodyStr) {
this.requestWrapper.request(requestParams, function (err, res, bodyStr) {
if (err) {
console.error(`FATAL ERROR: ${new Date()}`
console.error(`FATAL ERROR: ${date !== null ? date : new Date()}`
+ ` Problems contacting Telesign Servers. Check your internet connection.`);

@@ -191,0 +206,0 @@

@@ -7,3 +7,4 @@ const RestClient = require('./RestClient.js');

class ScoreClient extends RestClient {
constructor(customerId,
constructor(requestWrapper,
customerId,
apiKey,

@@ -14,3 +15,3 @@ restEndpoint = null,

super(customerId, apiKey, restEndpoint, timeout, userAgent);
super(requestWrapper, customerId, apiKey, restEndpoint, timeout, userAgent);

@@ -17,0 +18,0 @@ this.scoreResource = "/v1/score/";

@@ -7,2 +7,4 @@ const RestClient = require('./RestClient.js');

const AppVerifyClient = require('./AppVerifyClient.js');
const IntelligenceClient = require('./IntelligenceClient.js');
const { FetchRequestWrapper } = require('./RequestWrapper')

@@ -16,9 +18,11 @@ module.exports = class TeleSign {

this.rest = new RestClient(customerId, apiKey, restEndpoint, timeout, useragent);
this.sms = new MessagingClient(customerId, apiKey, restEndpoint, timeout, useragent);
this.voice = new VoiceClient(customerId, apiKey, restEndpoint, timeout, useragent);
this.score = new ScoreClient(customerId, apiKey, restEndpoint, timeout, useragent);
this.phoneid = new PhoneIDClient(customerId, apiKey, restEndpoint, timeout, useragent);
this.appverify = new AppVerifyClient(customerId, apiKey, restEndpoint, timeout, useragent);
const requestWrapper = new FetchRequestWrapper();
this.rest = new RestClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
this.sms = new MessagingClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
this.voice = new VoiceClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
this.score = new ScoreClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
this.phoneid = new PhoneIDClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
this.appverify = new AppVerifyClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
this.intelligence = new IntelligenceClient(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);
}
};

@@ -10,3 +10,4 @@ const RestClient = require('./RestClient.js');

constructor(customerId,
constructor(requestWrapper,
customerId,
apiKey,

@@ -16,3 +17,3 @@ restEndpoint = null,

useragent = null) {
super(customerId, apiKey, restEndpoint, timeout, useragent);
super(requestWrapper, customerId, apiKey, restEndpoint, timeout, useragent);

@@ -19,0 +20,0 @@ this.voice_resource = "/v1/voice";

@@ -0,0 +0,0 @@ TeleSign Node.js SDK Examples

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc