Socket
Socket
Sign inDemoInstall

@vonage/server-client

Package Overview
Dependencies
Maintainers
39
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/server-client - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

dist/enums/GenericErrorCodes.d.ts

30

dist/client.d.ts

@@ -1,24 +0,13 @@

import { AuthInterface } from '@vonage/auth';
import { ResponseTypes, VetchResponse } from '@vonage/vetch';
import { AuthInterface, AuthParams } from '@vonage/auth';
import { VetchResponse, VetchOptions, HTTPMethods } from '@vonage/vetch';
import { AuthenticationType } from './enums/AuthenticationType';
import * as transfomers from './transformers';
import { ConfigParams } from './types/index';
export declare abstract class Client {
static transformers: typeof transfomers;
protected authType?: AuthenticationType;
protected auth: AuthInterface;
protected config: {
restHost: string;
apiHost: string;
videoHost: string;
responseType: string;
timeout: number;
};
constructor(credentials: AuthInterface, options?: {
restHost: string;
apiHost: string;
videoHost: string;
responseType: ResponseTypes;
timeout: number;
});
static transformers: typeof transfomers;
addAuthenticationToRequest(request: any): Promise<any>;
protected config: ConfigParams;
constructor(credentials: AuthInterface | AuthParams, options?: ConfigParams);
addAuthenticationToRequest(request: VetchOptions): Promise<VetchOptions>;
sendDeleteRequest<T>(url: string): Promise<VetchResponse<T>>;

@@ -40,3 +29,6 @@ sendFormSubmitRequest<T>(url: string, payload?: {

}): Promise<VetchResponse<T>>;
sendRequest<T>(request: any): Promise<VetchResponse<T>>;
sendRequestWithData<T>(method: HTTPMethods, url: string, payload?: {
[key: string]: any;
}): Promise<VetchResponse<T>>;
sendRequest<T>(request: VetchOptions): Promise<VetchResponse<T>>;
}

@@ -37,2 +37,3 @@ "use strict";

class Client {
static transformers = transfomers;
authType;

@@ -42,21 +43,15 @@ auth;

constructor(credentials, options) {
if (typeof credentials.getQueryParams === 'undefined') {
credentials = new auth_1.Auth(credentials);
}
this.auth = credentials;
this.auth = !Object.prototype.hasOwnProperty.call(credentials, 'getQueryParams')
? new auth_1.Auth(credentials)
: credentials;
this.config = {
restHost: null,
apiHost: null,
videoHost: null,
responseType: null,
restHost: options?.restHost || 'https://rest.nexmo.com',
apiHost: options?.apiHost || 'https://api.nexmo.com',
videoHost: options?.videoHost || 'https://video.api.vonage.com',
responseType: options?.responseType || vetch_1.ResponseTypes.json,
timeout: null,
};
this.config.restHost = options?.restHost || 'https://rest.nexmo.com';
this.config.apiHost = options?.apiHost || 'https://api.nexmo.com';
this.config.videoHost
= options?.videoHost || 'https://video.api.vonage.com';
this.config.responseType = options?.responseType || vetch_1.ResponseTypes.json;
}
static transformers = transfomers;
async addAuthenticationToRequest(request) {
let requestPath = 'data';
log(`adding ${this.authType || 'api key/secret'} to request`);

@@ -68,3 +63,3 @@ switch (this.authType) {

});
break;
return request;
case AuthenticationType_1.AuthenticationType.JWT:

@@ -74,19 +69,25 @@ request.headers = Object.assign({}, request.headers, {

});
break;
return request;
case AuthenticationType_1.AuthenticationType.QUERY_KEY_SECRET:
request.params = request.params || {};
request.params = Object.assign({}, request.params, await this.auth.getQueryParams(request.params));
break;
requestPath = 'params';
case AuthenticationType_1.AuthenticationType.KEY_SECRET:
default:
if (request.method === 'GET') {
request.params = request.params || {};
request.params = Object.assign({}, request.params, await this.auth.getQueryParams(request.params));
}
else {
request.data = request.data || {};
request.data = Object.assign({}, request.data, await this.auth.getQueryParams(request.data));
}
break;
}
if (['GET', 'DELETE'].includes(request.method)) {
requestPath = 'params';
}
const authParams = await this.auth.getQueryParams({});
let params = {
...request[requestPath],
...authParams,
};
if (!request[requestPath]
&& this.authType !== AuthenticationType_1.AuthenticationType.QUERY_KEY_SECRET) {
requestPath = 'body';
params = new URLSearchParams({
...Object.fromEntries(request.body.entries()),
...authParams,
});
}
request[requestPath] = params;
return request;

@@ -97,3 +98,3 @@ }

url,
method: 'DELETE',
method: vetch_1.HTTPMethods.DELETE,
};

@@ -105,11 +106,8 @@ return await this.sendRequest(request);

url,
body: new URLSearchParams(payload),
method: 'POST',
method: vetch_1.HTTPMethods.POST,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
...(payload ? { body: new URLSearchParams(payload) } : {}),
};
if (!payload) {
delete request.body;
}
return await this.sendRequest(request);

@@ -120,55 +118,30 @@ }

url,
params: queryParams,
method: 'GET',
method: vetch_1.HTTPMethods.GET,
...(queryParams ? { params: queryParams } : {}),
};
if (!queryParams) {
delete request.params;
}
return await this.sendRequest(request);
}
async sendPatchRequest(url, payload) {
const request = {
url,
data: payload,
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
};
if (!payload) {
delete request.data;
}
return await this.sendRequest(request);
return this.sendRequestWithData(vetch_1.HTTPMethods.PATCH, url, payload);
}
async sendPostRequest(url, payload) {
const request = {
url,
data: payload,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
if (!payload) {
delete request.data;
}
return await this.sendRequest(request);
return this.sendRequestWithData(vetch_1.HTTPMethods.POST, url, payload);
}
async sendPutRequest(url, payload) {
sendPutRequest(url, payload) {
return this.sendRequestWithData(vetch_1.HTTPMethods.PUT, url, payload);
}
async sendRequestWithData(method, url, payload) {
const request = {
url,
data: payload,
method: 'PUT',
method: method,
headers: {
'Content-Type': 'application/json',
},
...(payload ? { data: payload } : {}),
};
if (!payload) {
delete request.data;
}
return await this.sendRequest(request);
}
async sendRequest(request) {
request.timeout = this.config.timeout;
request = await this.addAuthenticationToRequest(request);
request.timeout = this.config.timeout;
const result = await (0, vetch_1.request)(request);

@@ -175,0 +148,0 @@ return result;

@@ -5,3 +5,4 @@ export declare enum AuthenticationType {

KEY_SECRET = "key_secret",
QUERY_KEY_SECRET = "query_key_secret"
QUERY_KEY_SECRET = "query_key_secret",
SIGNATURE = "signature"
}

@@ -10,3 +10,4 @@ "use strict";

AuthenticationType["QUERY_KEY_SECRET"] = "query_key_secret";
AuthenticationType["SIGNATURE"] = "signature";
})(AuthenticationType = exports.AuthenticationType || (exports.AuthenticationType = {}));
//# sourceMappingURL=AuthenticationType.js.map
export { Client } from './client';
export { AuthenticationType } from './enums/AuthenticationType';
export { APILink, APILinks } from './types';
export * from './enums/';
export * from './types';
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationType = exports.Client = void 0;
exports.Client = void 0;
var client_1 = require("./client");
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
var AuthenticationType_1 = require("./enums/AuthenticationType");
Object.defineProperty(exports, "AuthenticationType", { enumerable: true, get: function () { return AuthenticationType_1.AuthenticationType; } });
__exportStar(require("./enums/"), exports);
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

@@ -1,10 +0,1 @@

export type APILink = {
href: string;
};
export type APILinks = {
_links: {
self: APILink;
next?: APILink;
prev?: APILink;
};
};
export * from './types/index';
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./types/index"), exports);
//# sourceMappingURL=types.js.map
{
"name": "@vonage/server-client",
"version": "1.2.0",
"version": "1.3.0",
"description": "Core services related to talking to the Vonage APIs",

@@ -30,4 +30,4 @@ "homepage": "https://developer.vonage.com",

"dependencies": {
"@vonage/auth": "^1.1.2",
"@vonage/vetch": "^1.1.2",
"@vonage/auth": "^1.2.0",
"@vonage/vetch": "^1.2.0",
"debug": "^4.3.4",

@@ -40,2 +40,5 @@ "lodash.camelcase": "^4.3.0",

},
"devDependencies": {
"nock": "^13.3.0"
},
"publishConfig": {

@@ -42,0 +45,0 @@ "directory": "dist"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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