Socket
Socket
Sign inDemoInstall

@vonage/server-client

Package Overview
Dependencies
Maintainers
37
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.0.6 to 1.0.7

dist/client.js.map

4

dist/client.d.ts

@@ -21,6 +21,2 @@ import { AuthInterface } from '@vonage/auth';

});
/**
* Adds authentication to a request
* By default we add key/secret. Individual clients may override this with whatever they want.
*/
addAuthenticationToRequest(request: any): any;

@@ -27,0 +23,0 @@ sendDeleteRequest<T>(url: string): Promise<VetchResponse<T>>;

@@ -1,20 +0,8 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const auth_1 = require("@vonage/auth");
const vetch_1 = require("@vonage/vetch");
const AuthenticationType_1 = require("./enums/AuthenticationType");
class Client {
import { Auth } from '@vonage/auth';
import { request as vetchRequest, ResponseTypes, } from '@vonage/vetch';
import { AuthenticationType } from './enums/AuthenticationType';
export class Client {
constructor(credentials, options) {
if (typeof credentials.getQueryParams === 'undefined') {
credentials = new auth_1.Auth(credentials);
credentials = new Auth(credentials);
}

@@ -29,15 +17,11 @@ this.auth = credentials;

};
this.config.restHost = (options === null || options === void 0 ? void 0 : options.restHost) || 'https://rest.nexmo.com';
this.config.apiHost = (options === null || options === void 0 ? void 0 : options.apiHost) || 'https://api.nexmo.com';
this.config.restHost = options?.restHost || 'https://rest.nexmo.com';
this.config.apiHost = options?.apiHost || 'https://api.nexmo.com';
this.config.videoHost =
(options === null || options === void 0 ? void 0 : options.videoHost) || 'https://video.api.vonage.com';
this.config.responseType = (options === null || options === void 0 ? void 0 : options.responseType) || vetch_1.ResponseTypes.json;
options?.videoHost || 'https://video.api.vonage.com';
this.config.responseType = options?.responseType || ResponseTypes.json;
}
/**
* Adds authentication to a request
* By default we add key/secret. Individual clients may override this with whatever they want.
*/
addAuthenticationToRequest(request) {
switch (this.authType) {
case AuthenticationType_1.AuthenticationType.BASIC:
case AuthenticationType.BASIC:
request.headers = Object.assign({}, request.headers, {

@@ -47,3 +31,3 @@ Authorization: this.auth.createBasicHeader(),

break;
case AuthenticationType_1.AuthenticationType.JWT:
case AuthenticationType.JWT:
request.headers = Object.assign({}, request.headers, {

@@ -53,7 +37,7 @@ Authorization: this.auth.createBearerHeader(),

break;
case AuthenticationType_1.AuthenticationType.QUERY_KEY_SECRET:
case AuthenticationType.QUERY_KEY_SECRET:
request.params = request.params || {};
request.params = Object.assign({}, request.params, this.auth.getQueryParams(request.params));
break;
case AuthenticationType_1.AuthenticationType.KEY_SECRET:
case AuthenticationType.KEY_SECRET:
default:

@@ -72,97 +56,83 @@ if (request.method === 'GET') {

}
sendDeleteRequest(url) {
return __awaiter(this, void 0, void 0, function* () {
const request = {
url,
method: 'DELETE',
};
return yield this.sendRequest(request);
});
async sendDeleteRequest(url) {
const request = {
url,
method: 'DELETE',
};
return await this.sendRequest(request);
}
sendFormSubmitRequest(url, payload) {
return __awaiter(this, void 0, void 0, function* () {
const request = {
url,
body: new URLSearchParams(payload),
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
if (!payload) {
delete request.body;
}
return yield this.sendRequest(request);
});
async sendFormSubmitRequest(url, payload) {
const request = {
url,
body: new URLSearchParams(payload),
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
if (!payload) {
delete request.body;
}
return await this.sendRequest(request);
}
sendGetRequest(url, queryParams) {
return __awaiter(this, void 0, void 0, function* () {
const request = {
url,
params: queryParams,
method: 'GET',
};
if (!queryParams) {
delete request.params;
}
return yield this.sendRequest(request);
});
async sendGetRequest(url, queryParams) {
const request = {
url,
params: queryParams,
method: 'GET',
};
if (!queryParams) {
delete request.params;
}
return await this.sendRequest(request);
}
sendPatchRequest(url, payload) {
return __awaiter(this, void 0, void 0, function* () {
const request = {
url,
data: payload,
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
};
if (!payload) {
delete request.data;
}
return yield 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);
}
sendPostRequest(url, payload) {
return __awaiter(this, void 0, void 0, function* () {
const request = {
url,
data: payload,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
if (!payload) {
delete request.data;
}
return yield this.sendRequest(request);
});
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);
}
sendPutRequest(url, payload) {
return __awaiter(this, void 0, void 0, function* () {
const request = {
url,
data: payload,
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
};
if (!payload) {
delete request.data;
}
return yield this.sendRequest(request);
});
async sendPutRequest(url, payload) {
const request = {
url,
data: payload,
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
};
if (!payload) {
delete request.data;
}
return await this.sendRequest(request);
}
sendRequest(request) {
return __awaiter(this, void 0, void 0, function* () {
request = this.addAuthenticationToRequest(request);
request.timeout = this.config.timeout;
const result = yield (0, vetch_1.request)(request);
return result;
});
async sendRequest(request) {
request = this.addAuthenticationToRequest(request);
request.timeout = this.config.timeout;
const result = await vetchRequest(request);
return result;
}
}
exports.Client = Client;
//# sourceMappingURL=client.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationType = void 0;
var AuthenticationType;
export var AuthenticationType;
(function (AuthenticationType) {

@@ -10,2 +7,3 @@ AuthenticationType["BASIC"] = "basic";

AuthenticationType["QUERY_KEY_SECRET"] = "query_key_secret";
})(AuthenticationType = exports.AuthenticationType || (exports.AuthenticationType = {}));
})(AuthenticationType || (AuthenticationType = {}));
//# sourceMappingURL=AuthenticationType.js.map

@@ -1,7 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationType = 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; } });
export { Client } from './client';
export { AuthenticationType } from './enums/AuthenticationType';
//# sourceMappingURL=index.js.map
{
"name": "@vonage/server-client",
"version": "1.0.6",
"version": "1.0.7",
"description": "Core services related to talking to the Vonage APIs",

@@ -15,2 +15,3 @@ "homepage": "https://developer.vonage.com",

"author": "Chris Tankersley <chris@ctankersley.com>",
"type": "module",
"main": "dist/index.js",

@@ -27,20 +28,13 @@ "types": "dist/index.d.ts",

"build": "npm run clean && npm run compile",
"clean": "tsc -b --clean",
"compile": "tsc -p tsconfig.json",
"format": "prettier --write \"lib/**/*.ts\"",
"lint": "tslint -p tsconfig.json",
"prepublishOnly": "npm run build && npm run test && npm run lint",
"test": "npx jest",
"test-watch": "npx jest --watch",
"preversion": "npm run lint",
"version": "npm run format && git add -A lib"
"clean": "npx shx rm -rf dist tsconfig.tsbuildinfo",
"compile": "npx tsc --build --verbose"
},
"dependencies": {
"@vonage/auth": "^1.0.3",
"@vonage/jwt": "^1.0.3",
"@vonage/vetch": "^1.0.4"
"@vonage/auth": "^1.0.4",
"@vonage/vetch": "^1.0.5"
},
"publishConfig": {
"directory": "dist"
}
},
"gitHead": "328f18e5c8a458cb4d06d7955ec2399a6ce6f5d8"
}

@@ -1,11 +0,88 @@

# `@vonage/server-client`
# Vonage Auth SDK for Node.js
> TODO: description
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/vonage/vonage-node-sdk/Vonage/3.x?logo=github&style=flat-square&label=Workflow%20Build)
[![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk)
![Latest Release](https://img.shields.io/npm/v/@vonage/server-client)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](../../CODE_OF_CONDUCT.md)
[![License](https://img.shields.io/npm/l/@vonage/server-client?label=License&style=flat-square)][license]
## Usage
<img src="https://developer.nexmo.com/images/logos/vbc-logo.svg" height="48px" alt="Vonage" />
This is the Vonage Server Client SDK for Node.js used to wrap the authentication
headers/signatures for use with [Vonage APIs](https://www.vonage.com/). To use
it you will need a Vonage account. Sign up [for free at vonage.com][signup].
We recommend using this package as part of the overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk).
For full API documentation refer to [developer.vonage.com](https://developer.vonage.com/).
* [Installation](#installation)
* [Usage](#using-the-vonage-auth-sdk)
* [Options](#options)
* [Testing](#testing)
## Installation
### With NPM
```bash
npm install @vonage/server-client
```
const serverClient = require('@vonage/server-client');
// TODO: DEMONSTRATE API
### With Yarn
```bash
yarn add @vonage/server-client
```
## Using the Vonage Server-Client SDK
To create a client, you will need to pass in a `@vonage/auth` object.
```js
const { Auth } = require('@vonage/auth');
const { Client } = require('@vonage/server-client');
const vonageClient = new Client (new Auth({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
}),
options,
);
```
You will now be able to send requests using the client:
```js
const response = await vonageClient.sendGetRequest('https://rest.nexmo.com/account/numbers')
```
### Options
The constructor for the client takes in two parameters `credentials` and
`options`. `credentials` is either an [`Auth`](https://github.com/Vonage/vonage-node-sdk/blob/3.x/packages/auth/lib/auth.ts#L13)
or an `object` containing the settings from [`AuthInterface`](https://github.com/Vonage/vonage-node-sdk/blob/3.x/packages/auth/lib/types.ts#L35).
`options` allows adjusting api endpoints and the request timeout.
* `restHost: string` (optional) - Allows overwriting the default `https://rest.nexmo.com`.
* `apiHost: string` (optional) - Allows overwriting the default `https://api.nexmo.com`.
* `videoHost: string` (optional) - Allows overwriting the default `https://video.api.vonage.com`.
* `responseType: 'json' | null` (optional) - Allows setting the response data as
`text` or `json` decoded.
* `timeout: int` (optional) - Set a custom timeout for requests to Vonage in
milliseconds. Defaults to the standard for Node http requests, which is 120,000 ms.
## Testing
Run:
```bash
npm run test
```
[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk
[license]: ../../LICENSE.txt
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