Skip to content

feat: verify v2 #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The following is a list of Vonage APIs and whether the Node Server SDK provides
| Reports API | Beta | ❌ |
| SMS API | General Availability | ✅ |
| Verify API | General Availability | ✅ |
| Verify v2 API | Beta | ✅ |
| Voice API | General Availability | ✅ |

[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk
Expand Down
4 changes: 4 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const config: Config.InitialOptions = {
displayName: 'VERIFY',
testMatch: ['<rootDir>/packages/verify/__tests__/**/*.test.ts'],
},
{
displayName: 'VERIFY 2',
testMatch: ['<rootDir>/packages/verify2/__tests__/**/*.test.ts'],
},
{
displayName: 'VETCH',
testMatch: ['<rootDir>/packages/vetch/__tests__/**/*.test.ts'],
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions packages/server-client/lib/enums/GenericErrorCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export enum GenericErrors {
LOW_BALANCE = 'low-balance',
UNAUTHORIZED = 'unauthorized',
FORBIDDEN = 'forbidden',
NOT_FOUND = 'not-found',
UNPROVISIONED = 'unprovisioned',
ACCOUNT_SUSPENDED = 'account-suspended',
JWT_EXPIRED = 'jwt-expired',
JWT_REVOKED = 'jwt-revoked',
INVALID_API_KEY = 'invalid-api-key',
INVALID_SIGNATURE = 'invalid-signature',
INVALID_IP = 'invalid-ip',
MULTIPLE_AUTH_METHODS = 'multiple-auth-methods',
INVALID_ID = 'invalid-id',
INVALID_JSON = 'invalid-json',
WRONG_VERB = 'wrong-verb',
ACCEPT_HEADER = 'accept-header',
CONTENT_TYPE_HEADER = 'content-type-header',
UNAVAILABLE_LEGAL = 'unavailable-legal',
APPLICATION_SUSPENDED = 'application-suspended',
}
2 changes: 2 additions & 0 deletions packages/server-client/lib/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './AuthenticationType';
export * from './GenericErrorCodes';
4 changes: 2 additions & 2 deletions packages/server-client/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Client } from './client';
export { AuthenticationType } from './enums/AuthenticationType';
export { APILink, APILinks } from './types';
export * from './enums/';
export * from './types';
1 change: 1 addition & 0 deletions packages/server-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ The following is a list of Vonage APIs and whether the Node Server SDK provides
| Reports API | Beta | ❌ |
| SMS API | General Availability | ✅ |
| Verify API | General Availability | ✅ |
| Verify v2 API | Beta | ✅ |
| Voice API | General Availability | ✅ |


Expand Down
83 changes: 83 additions & 0 deletions packages/verify2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Vonage Verify SDK for Node.js

![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/Vonage/vonage-node-sdk/ci.yml?branch=3.x)
[![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/verify2)
[![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/verify2?label=License&style=flat-square)][license]

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

This is the Vonage Verify (for version 2) 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].

For full API documentation refer to
[developer.vonage.com](https://developer.vonage.com/).

- [Installation](#installation)
- [Usage](#using-the-vonage-verify-sdk)
- [Promises](#promises)
- [Testing](#testing)

## Installation

### With NPM

```bash
npm install @vonage/verify2
```

### With Yarn

```bash
yarn add @vonage/verify2
```

## Using the Vonage Verify v2 SDK

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 Messages API. All you need to do is
`require('@vonage/verify')`, and use the returned object to create your own
client.

```js
const { Auth } = require('@vonage/auth')
const { Verify2 } = require('@vonage/verify2')

const credentials = new Auth({
applicationId: APP_ID,
privateKey: PRIAVTE_KEY,
})
const options = {}
const verifyClient = new Verify2(credentials, options)
```

Where `credentials` is any option from [`@vonage/auth`](https://github.com/Vonage/vonage-node-sdk/tree/3.x/readme/packages/auth#options),
and `options` is any option from [`@vonage/server-client`](https://github.com/Vonage/vonage-node-sdk/tree/3.x/readme/packages/server-client#options)

## 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 resp = await verifyClient.checkCode(VERIFY_REQUEST_ID, CODE)

vonage.verify2
.checkCode(VERIFY_REQUEST_ID, CODE)
.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
43 changes: 43 additions & 0 deletions packages/verify2/__tests__/__dataSets__/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CheckCodeRequest } from '../../lib/types';

export default [
{
label: 'check code',
request: [
'/v2/verify/091e717f-8715-41a0-a3f0-cc04912deaa1',
'POST',
{
code: '123456',
} as CheckCodeRequest,
],
response: [200],
method: 'post',
clientMethod: 'checkCode',
parameters: ['091e717f-8715-41a0-a3f0-cc04912deaa1', '123456'],
expected: true,
},
{
label: 'error when request not found',
request: [
'/v2/verify/091e717f-8715-41a0-a3f0-cc04912deaa1',
'POST',
{
code: '123456',
} as CheckCodeRequest,
],
response: [
404,
{
title: 'Not Found',
type: 'https://developer.vonage.com/api-errors#not-found',
detail: 'Request <id> was not found or it has been verified already.',
instance: 'bf0ca0bf927b3b52e3cb03217e1a1ddf',
},
],
method: 'post',
clientMethod: 'checkCode',
parameters: ['091e717f-8715-41a0-a3f0-cc04912deaa1', '123456'],
expected: true,
error: 'Request failed with status code 404',
},
];
13 changes: 13 additions & 0 deletions packages/verify2/__tests__/__dataSets__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import requestTests from './verify';
import checkTests from './check';

export default [
{
label: 'Request tests',
tests: requestTests,
},
{
label: 'Check tests',
tests: checkTests,
},
];
Loading