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

@bandwidth/messaging

Package Overview
Dependencies
Maintainers
9
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bandwidth/messaging - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

lib/Environments.js

18

lib/APIHelper.js

@@ -12,3 +12,2 @@ /**

class APIHelper {
/**

@@ -37,9 +36,16 @@ * Replaces template parameters in the given url

const element = parameters[keys[iter]];
if (element === null) {
if (element.value === null) {
replaceValue = '';
} else if (element instanceof Array) {
replaceValue = element.map(el => encodeURIComponent(el));
replaceValue = replaceValue.join('/');
} else if (element.value instanceof Array) {
if (element.encode === true) {
replaceValue = element.value.map(el => encodeURIComponent(el));
replaceValue = replaceValue.join('/');
} else {
replaceValue = element.value.join('/');
}
} else if (element.encode === true) {
replaceValue = encodeURIComponent(element.value.toString());
} else {
replaceValue = encodeURIComponent(element.toString());
replaceValue = element.value.toString();
}

@@ -46,0 +52,0 @@ queryString = queryString.replace(`{${keys[iter]}}`, replaceValue);

@@ -9,7 +9,16 @@ /**

const servers = require('./Servers');
const environments = require('./Environments');
const apiHelper = require('./APIHelper');
const environmentsMap = [];
environmentsMap[environments.PRODUCTION] = [];
environmentsMap[environments.CUSTOM] = [];
environmentsMap[environments.PRODUCTION][servers.MDEFAULT] =
'https://messaging.bandwidth.com/api/v2';
environmentsMap[environments.CUSTOM][servers.MDEFAULT] = '{base_url}';
const Configuration = {
// The base Uri for API calls
BASEURI: 'https://messaging.bandwidth.com/api/v2',
// The username to use with basic authentication

@@ -23,4 +32,28 @@ // TODO: Replace the BasicAuthUserName with an appropriate value

/**
* base_url
* @type {string}
*/
baseUrl: 'https://www.example.com',
/**
* Current API environment
* @type {string}
*/
currentEnvironment: environments.PRODUCTION,
/**
* Get base URI for a server in the current API environment
* @param {string|null} server Server name
* @return {string} Base URI for server
*/
getBaseUri(server) {
const url = environmentsMap[this.currentEnvironment][server || servers.MDEFAULT];
const urlParams = {
baseUrl: { value: this.baseUrl, encode: false },
};
return apiHelper.appendUrlWithTemplateParameters(url, urlParams);
},
};
module.exports = Configuration;

@@ -30,3 +30,3 @@ /**

// prepare query string for API call
const _baseUri = _configuration.BASEURI;
const _baseUri = _configuration.getBaseUri();

@@ -36,3 +36,3 @@ let _pathUrl = '/users/{userId}/media';

_pathUrl = _apiHelper.appendUrlWithTemplateParameters(_pathUrl, {
userId,
userId: { value: userId, encode: true },
});

@@ -65,6 +65,2 @@

let errorResponse;
let response = '';
if (_context.response.body) {
response = JSON.parse(_context.response.body);
}
if (_error) {

@@ -82,3 +78,3 @@ errorResponse = _baseController.validateResponse(_context);

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '400 Request is malformed or invalid';

@@ -93,3 +89,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '401 The specified user does not have access to the account';

@@ -104,3 +100,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '403 The user does not have access to this API';

@@ -115,3 +111,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '404 Path not found';

@@ -126,3 +122,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '415 The content-type of the request is incorrect';

@@ -137,3 +133,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '429 The rate limit has been reached';

@@ -169,3 +165,3 @@ mappedObject.context = _context;

// prepare query string for API call
const _baseUri = _configuration.BASEURI;
const _baseUri = _configuration.getBaseUri();

@@ -175,4 +171,4 @@ let _pathUrl = '/users/{userId}/media/{mediaId}';

_pathUrl = _apiHelper.appendUrlWithTemplateParameters(_pathUrl, {
userId,
mediaId,
userId: { value: userId, encode: true },
mediaId: { value: mediaId, encode: false },
});

@@ -203,6 +199,2 @@

let errorResponse;
let response = '';
if (_context.response.body) {
response = JSON.parse(_context.response.body);
}
if (_error) {

@@ -217,3 +209,3 @@ errorResponse = _baseController.validateResponse(_context);

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '400 Request is malformed or invalid';

@@ -228,3 +220,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '401 The specified user does not have access to the account';

@@ -239,3 +231,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '403 The user does not have access to this API';

@@ -250,3 +242,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '404 Path not found';

@@ -261,3 +253,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '415 The content-type of the request is incorrect';

@@ -272,3 +264,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '429 The rate limit has been reached';

@@ -314,3 +306,3 @@ mappedObject.context = _context;

// prepare query string for API call
const _baseUri = _configuration.BASEURI;
const _baseUri = _configuration.getBaseUri();

@@ -320,4 +312,4 @@ let _pathUrl = '/users/{userId}/media/{mediaId}';

_pathUrl = _apiHelper.appendUrlWithTemplateParameters(_pathUrl, {
userId,
mediaId,
userId: { value: userId, encode: true },
mediaId: { value: mediaId, encode: false },
});

@@ -353,6 +345,2 @@

let errorResponse;
let response = '';
if (_context.response.body) {
response = JSON.parse(_context.response.body);
}
if (_error) {

@@ -367,3 +355,3 @@ errorResponse = _baseController.validateResponse(_context);

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '400 Request is malformed or invalid';

@@ -378,3 +366,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '401 The specified user does not have access to the account';

@@ -389,3 +377,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '403 The user does not have access to this API';

@@ -400,3 +388,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '404 Path not found';

@@ -411,3 +399,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '415 The content-type of the request is incorrect';

@@ -422,3 +410,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '429 The rate limit has been reached';

@@ -454,3 +442,3 @@ mappedObject.context = _context;

// prepare query string for API call
const _baseUri = _configuration.BASEURI;
const _baseUri = _configuration.getBaseUri();

@@ -460,4 +448,4 @@ let _pathUrl = '/users/{userId}/media/{mediaId}';

_pathUrl = _apiHelper.appendUrlWithTemplateParameters(_pathUrl, {
userId,
mediaId,
userId: { value: userId, encode: true },
mediaId: { value: mediaId, encode: false },
});

@@ -488,6 +476,2 @@

let errorResponse;
let response = '';
if (_context.response.body) {
response = JSON.parse(_context.response.body);
}
if (_error) {

@@ -502,3 +486,3 @@ errorResponse = _baseController.validateResponse(_context);

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '400 Request is malformed or invalid';

@@ -513,3 +497,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '401 The specified user does not have access to the account';

@@ -524,3 +508,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '403 The user does not have access to this API';

@@ -535,3 +519,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '404 Path not found';

@@ -546,3 +530,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '415 The content-type of the request is incorrect';

@@ -557,3 +541,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '429 The rate limit has been reached';

@@ -589,3 +573,3 @@ mappedObject.context = _context;

// prepare query string for API call
const _baseUri = _configuration.BASEURI;
const _baseUri = _configuration.getBaseUri();

@@ -595,3 +579,3 @@ let _pathUrl = '/users/{userId}/messages';

_pathUrl = _apiHelper.appendUrlWithTemplateParameters(_pathUrl, {
userId,
userId: { value: userId, encode: true },
});

@@ -625,6 +609,2 @@

let errorResponse;
let response = '';
if (_context.response.body) {
response = JSON.parse(_context.response.body);
}
if (_error) {

@@ -641,3 +621,3 @@ errorResponse = _baseController.validateResponse(_context);

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '400 Request is malformed or invalid';

@@ -652,3 +632,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '401 The specified user does not have access to the account';

@@ -663,3 +643,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '403 The user does not have access to this API';

@@ -674,3 +654,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '404 Path not found';

@@ -685,3 +665,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '415 The content-type of the request is incorrect';

@@ -696,3 +676,3 @@ mappedObject.context = _context;

const mappedObject = _baseController.getObjectMapper()
.mapObject(response, 'MessagingException');
.mapObject(JSON.parse(_context.response.body), 'MessagingException');
mappedObject.reason = '429 The rate limit has been reached';

@@ -699,0 +679,0 @@ mappedObject.context = _context;

@@ -9,3 +9,3 @@ /**

/**
/**
* Creates an instance of APIException

@@ -12,0 +12,0 @@ */

@@ -10,2 +10,3 @@ /**

const Configuration = require('./configuration');
const Environments = require('./Environments');
const APIController = require('./Controllers/APIController');

@@ -25,2 +26,3 @@ const Media = require('./Models/Media');

Configuration,
Environments,
// controllers of MessagingLib

@@ -27,0 +29,0 @@ APIController,

{
"name": "@bandwidth/messaging",
"version": "2.0.2",
"version": "2.0.3",
"description": "Bandwidth's HTTP Messaging platform",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

# Getting started
## Developer Docs
* [Bandwidth API Developer Docs](https://dev.bandwidth.com)
## Other Node SDKs

@@ -285,1 +288,2 @@ * Numbers: https://github.com/Bandwidth/node-numbers

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