Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Vonage/vonage-node-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @vonage/server-sdk@3.0.0
Choose a base ref
...
head repository: Vonage/vonage-node-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: @vonage/server-sdk@3.0.1
Choose a head ref
  • 8 commits
  • 27 files changed
  • 1 contributor

Commits on Nov 9, 2022

  1. Updated main README

    dragonmantank committed Nov 9, 2022

    Unverified

    The email in this signature doesn’t match the committer email.
    Copy the full SHA
    78947fb View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6a7b7c3 View commit details
  3. Added number insights

    dragonmantank committed Nov 9, 2022
    Copy the full SHA
    8e69ff6 View commit details
  4. Merge pull request #719 from Vonage/v3-docs

    V3 docs
    dragonmantank authored Nov 9, 2022
    Copy the full SHA
    b02dff0 View commit details

Commits on Nov 10, 2022

  1. Copy the full SHA
    71c4fcb View commit details
  2. Merge pull request #720 from Vonage/v3-docs

    Added verify and voice, and fixed a few typos in Number Insights
    dragonmantank authored Nov 10, 2022
    Copy the full SHA
    bf72c44 View commit details
  3. Copy the full SHA
    34ab564 View commit details
  4. Publish

     - @vonage/accounts@1.0.1
     - @vonage/applications@1.0.1
     - @vonage/messages@1.0.1
     - @vonage/number-insights@1.0.1
     - @vonage/numbers@1.0.1
     - @vonage/pricing@1.0.1
     - @vonage/server-client@1.0.1
     - @Vonage/server-sdk@3.0.1
     - @vonage/sms@1.0.1
     - @Vonage/verify@1.0.1
     - @vonage/vetch@1.0.1
     - @vonage/video@1.0.1
     - @vonage/voice@1.0.1
    dragonmantank committed Nov 10, 2022
    Copy the full SHA
    e2457c8 View commit details
36 changes: 11 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ npm install @vonage/server-sdk
## Constructor

```js
const Vonage = require('@vonage/server-sdk');
const { Vonage } = require('@vonage/server-sdk');

const vonage = new Vonage({
apiKey: API_KEY,
@@ -73,39 +73,25 @@ Options are:
}
```

## Callbacks
## Promises

All methods expect a `callback` function to be passed in, with a method signature of `(error, response)` where:

* `error` - is an Error object if the API call returns an error, or `null` if the API call was successful.
* `response` - is an Object, with the API response if the API call was successful, or `null` if there was an error.
This SDK uses Promises to return data. Each method call will have a return value that can be
manipulated in a `.then()` chain, and errors can be caught using `.catch()`.

Example:

```js
callback = (error, response) => {
if (error) {
console.error(error)
}

if (response) {
console.log(response)
}
}
await vonage.sms.send({to, from, text})
.then(resp => { console.log('Message sent successfully'); console.log(resp); })
.catch(err => { console.log('There was an error sending the messages.'); console.error(err); });
```

## Testing

Run:

```bash
npm test
```

Or to continually watch and run tests as you change the code:

```bash
npm run test-watch
lerna run test
```

## Examples
@@ -125,12 +111,12 @@ The following is a list of Vonage APIs and whether the Node Server SDK provides
| Conversation API | Beta ||
| Dispatch API | Beta ||
| External Accounts API | Beta ||
| Media API | Beta ||
| Messages API | Beta ||
| Media API | Beta ||
| Messages API | Beta ||
| Number Insight API | General Availability ||
| Number Management API | General Availability ||
| Pricing API | General Availability ||
| Redact API | Developer Preview ||
| Redact API | Developer Preview ||
| Reports API | Beta ||
| SMS API | General Availability ||
| Verify API | General Availability ||
121 changes: 116 additions & 5 deletions packages/accounts/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,122 @@
# `@vonage/accounts`
# Vonage Accounts 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/github/v/release/vonage/vonage-node-sdk?logo=npm&style=flat-square)

## Usage
[![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-sdk?label=License&style=flat-square)][../../LICENSE.TXT]

<img src="https://developer.nexmo.com/images/logos/vbc-logo.svg" height="48px" alt="Vonage" />

This is the Vonage Account SDK for Node.js 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.nexmo.com](https://developer.nexmo.com/).

* [Installation](#installation)
* [Constructor](#constructor)
* [Callbacks](#callbacks)
* [Testing](#testing)
* [Examples](#examples)
* [Supported APIs](#supported-apis)

## Installation

We recommend using this SDK as part of the overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk). Please see the main package for installation.

You can also use this SDK standalone if you only need access to just the Accounts API.
### With NPM

```bash
npm install @vonage/account
```

### With Yarn

```bash
yarn add @vonage/account
```

## Using the Vonage Accounts SDK

### As part of the Vonage Server SDK

If you are using this SDK as part of the Vonage Server SDK, you can access it as the `accounts` property off of the client that you instantiate.

```js
const { Vonage } = require('@vonage/server-sdk');

const vonage = new Vonage({
apiKey: API_KEY,
apiSecret: API_SECRET,
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
signatureSecret: SIGNATURE_SECRET,
signatureMethod: SIGNATURE_METHOD
}, options);

const balance = await vonage.accounts.getBalance();
```
const accounts = require('@vonage/accounts');

// TODO: DEMONSTRATE API
### Standalone

The SDK can be used standalone from the main [Vonage Server SDK for Node.js](https://github.com/vonage/vonage-node-sdk) if you only need to use the Account APIs. All you need to do is `require('@vonage/account')`, and use the returned object to create your own client.

```js
const { Auth } = require('@vonage/auth');
const { Accounts } = require('@vonage/account');

const accountClient = new Accounts(new Auth({
apiKey: API_KEY,
apiSecret: API_SECRET,
}), options);
```

* `apiKey` - API Key from Vonage API. If `applicationId` and `privateKey` are present, `apiKey` is optional.
* `apiSecret` - API SECRET from Vonage API. If `applicationId` and `privateKey` are present, `apiSecret` is optional.
* `options` is an object that can contain:

```js
{
// If true, log information to the console
debug: true|false,
// append info the the User-Agent sent to Nexmo
// e.g. pass 'my-app' for /nexmo-node/1.0.0/4.2.7/my-app
appendToUserAgent: string,
// Set a custom logger
logger: {
log: function() {level, args...}
info: function() {args...},
warn: function() {args...}
},
// Set a custom timeout for requests to Nexmo in milliseconds. Defaults to the standard for Node http requests, which is 120,000 ms.
timeout: integer,
// Set a custom host for requests instead of api.nexmo.com
apiHost: string,
// Set a custom host for requests instead of rest.nexmo.com
restHost: string
}
```

## Promises

Most methods that interact with the Vonage API uses Promises. You can either resolve these yourself, or use `await` to
wait for a response.

```js
const balance = await accountClient.getBalance();

accountClient.getBalance()
.then(resp => console.log(resp))
.catch(err => console.error(err));
```

## 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
4 changes: 2 additions & 2 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vonage/accounts",
"version": "1.0.0",
"version": "1.0.1",
"description": "Vonage Account Management API",
"homepage": "https://developer.vonage.com",
"bugs": {
@@ -34,7 +34,7 @@
"version": "npm run format && git add -A lib"
},
"dependencies": {
"@vonage/server-client": "^1.0.0"
"@vonage/server-client": "^1.0.1"
},
"publishConfig": {
"directory": "dist"
63 changes: 63 additions & 0 deletions packages/accounts/v2_TO_v3_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Migration guide from Vonage Node SDK 2.x to 3.x

## Installation

The package name has changed, and is now a companion to the core Vonage Node SDK. You can continue to use the `@vonage/server-sdk` package or now use the Accounts SDK as a standalone package. If you would like to continue to use the full SDK, simply update the version number to `^3.0` and follow this migration guide.

If you would like to use this SDK as a standalone package, you can install it using:

```console
$ npm install @vonage/accounts
```
## Setup

### With the Vonage Server SDK
If you are using the main Vonage Node Server SDK, you will just need to configure it using a Vonage API Key and Secret. Setup is the same for any other key/secret-based application. The accounts client will then be available as `vonage.accounts`.

```js
const Vonage = require('@vonage/server-sdk');

const vonage = new Vonage({
applicationId: APP_ID,
privateKey: PRIVATE_KEY_PATH,
});

vonage.accounts.getBalance()
.then(resp => console.log(resp))
.catch(err => console.error(err));
```

Please note that the accessor has changed from `vonage.account` to `vonage.accounts`.

The Secrets API is also now accessed differently, and has moved from `vonage.account` to `vonage.secrets`.

### Standalone
This module is also capable of working as a standalone module. The only difference is that you create an `Accounts` or `Secrets` object and pass the credentials there.

```js
const { Accounts, Secrets } = require('@vonage/accounts');
```

Functionality-wise, the standalone version works just as the wrapped SDK version.

## Callbacks vs Promises

The Node SDK v3.x uses Promises instead of callbacks. Customers will need to convert their callbacks to work with the responses returned from the calls.

## TypeScript

The module is fully written in TypeScript. While the users will be interacting with the transpiled JavaScript code, IDEs and TypeScript compilers should provide a better experience than previous versions of the Vonage Node Server SDK.

## Changed Methods

| 2.x Method | 3.x Method | Notes |
|----------------|---------------|-------|
| `vonage.account.getBalance()` | `vonage.accounts.getBalance()` | |
| `vonage.account.changePassword()` | N/A | You will need to delete and create a secret |
| `vonage.account.updateSMSCallback()` | `vonage.accounts.updateAccountCallbacks()` | The new method allows multiple callbacks to be updated at once |
| `vonage.account.updateDeliveryReceiptCallback()` | `vonage.accounts.updateAccountCallbacks()` | The new method allows multiple callbacks to be updated at once |
| `vonage.account.topUp()` | `vonage.accounts.topUpBalance()` | The method was renamed to better reflect what is being topped up |
| `vonage.account.listSecrets()` | `vonage.secrets.listSecrets()` | This method was moved to the `secrets` accessor |
| `vonage.account.getSecret()` | `vonage.secrets.getSecret()` | This method was moved to the `secrets` accessor |
| `vonage.account.deleteSecret()` | `vonage.secrets.deleteSecret()` | This method was moved to the `secrets` accessor |
| - | `vonage.secrets.createSecret()` | This method was added to allow secret creation |
Loading