@vonage/accounts 0.2.6 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -5
- package/package.json +40 -40
package/README.md
CHANGED
|
@@ -1,11 +1,122 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vonage Accounts SDK for Node.js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
 [](https://codecov.io/gh/Vonage/vonage-server-sdk) 
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](../../CODE_OF_CONDUCT.md) [][../../LICENSE.TXT]
|
|
6
6
|
|
|
7
|
+
<img src="https://developer.nexmo.com/images/logos/vbc-logo.svg" height="48px" alt="Vonage" />
|
|
8
|
+
|
|
9
|
+
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].
|
|
10
|
+
|
|
11
|
+
We recommend using this package as part of the overall [`@vonage/server-sdk` package](https://github.com/vonage/vonage-node-sdk).
|
|
12
|
+
|
|
13
|
+
For full API documentation refer to [developer.nexmo.com](https://developer.nexmo.com/).
|
|
14
|
+
|
|
15
|
+
* [Installation](#installation)
|
|
16
|
+
* [Constructor](#constructor)
|
|
17
|
+
* [Callbacks](#callbacks)
|
|
18
|
+
* [Testing](#testing)
|
|
19
|
+
* [Examples](#examples)
|
|
20
|
+
* [Supported APIs](#supported-apis)
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
You can also use this SDK standalone if you only need access to just the Accounts API.
|
|
27
|
+
### With NPM
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @vonage/account
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### With Yarn
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
yarn add @vonage/account
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Using the Vonage Accounts SDK
|
|
40
|
+
|
|
41
|
+
### As part of the Vonage Server SDK
|
|
42
|
+
|
|
43
|
+
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.
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
const { Vonage } = require('@vonage/server-sdk');
|
|
47
|
+
|
|
48
|
+
const vonage = new Vonage({
|
|
49
|
+
apiKey: API_KEY,
|
|
50
|
+
apiSecret: API_SECRET,
|
|
51
|
+
applicationId: APP_ID,
|
|
52
|
+
privateKey: PRIVATE_KEY_PATH,
|
|
53
|
+
signatureSecret: SIGNATURE_SECRET,
|
|
54
|
+
signatureMethod: SIGNATURE_METHOD
|
|
55
|
+
}, options);
|
|
56
|
+
|
|
57
|
+
const balance = await vonage.accounts.getBalance();
|
|
7
58
|
```
|
|
8
|
-
const accounts = require('@vonage/accounts');
|
|
9
59
|
|
|
10
|
-
|
|
60
|
+
### Standalone
|
|
61
|
+
|
|
62
|
+
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.
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
const { Auth } = require('@vonage/auth');
|
|
66
|
+
const { Accounts } = require('@vonage/account');
|
|
67
|
+
|
|
68
|
+
const accountClient = new Accounts(new Auth({
|
|
69
|
+
apiKey: API_KEY,
|
|
70
|
+
apiSecret: API_SECRET,
|
|
71
|
+
}), options);
|
|
11
72
|
```
|
|
73
|
+
|
|
74
|
+
* `apiKey` - API Key from Vonage API. If `applicationId` and `privateKey` are present, `apiKey` is optional.
|
|
75
|
+
* `apiSecret` - API SECRET from Vonage API. If `applicationId` and `privateKey` are present, `apiSecret` is optional.
|
|
76
|
+
* `options` is an object that can contain:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
{
|
|
80
|
+
// If true, log information to the console
|
|
81
|
+
debug: true|false,
|
|
82
|
+
// append info the the User-Agent sent to Nexmo
|
|
83
|
+
// e.g. pass 'my-app' for /nexmo-node/1.0.0/4.2.7/my-app
|
|
84
|
+
appendToUserAgent: string,
|
|
85
|
+
// Set a custom logger
|
|
86
|
+
logger: {
|
|
87
|
+
log: function() {level, args...}
|
|
88
|
+
info: function() {args...},
|
|
89
|
+
warn: function() {args...}
|
|
90
|
+
},
|
|
91
|
+
// Set a custom timeout for requests to Nexmo in milliseconds. Defaults to the standard for Node http requests, which is 120,000 ms.
|
|
92
|
+
timeout: integer,
|
|
93
|
+
// Set a custom host for requests instead of api.nexmo.com
|
|
94
|
+
apiHost: string,
|
|
95
|
+
// Set a custom host for requests instead of rest.nexmo.com
|
|
96
|
+
restHost: string
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Promises
|
|
101
|
+
|
|
102
|
+
Most methods that interact with the Vonage API uses Promises. You can either resolve these yourself, or use `await` to
|
|
103
|
+
wait for a response.
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
const balance = await accountClient.getBalance();
|
|
107
|
+
|
|
108
|
+
accountClient.getBalance()
|
|
109
|
+
.then(resp => console.log(resp))
|
|
110
|
+
.catch(err => console.error(err));
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Testing
|
|
114
|
+
|
|
115
|
+
Run:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm run test
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk
|
|
122
|
+
[license]: ../../LICENSE.txt
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
"name": "@vonage/accounts",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Vonage Account Management API",
|
|
5
|
+
"homepage": "https://developer.vonage.com",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Vonage/vonage-node-sdk/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Vonage/vonage-node-sdk.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"author": "Chris Tankersley <chris@ctankersley.com>",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"directories": {
|
|
18
|
+
"lib": "dist",
|
|
19
|
+
"test": "__tests__"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"/dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "npm run clean && npm run compile",
|
|
26
|
+
"clean": "tsc -b --clean",
|
|
27
|
+
"compile": "tsc -p tsconfig.json",
|
|
28
|
+
"format": "prettier --write \"lib/**/*.ts\"",
|
|
29
|
+
"lint": "tslint -p tsconfig.json",
|
|
30
|
+
"prepublishOnly": "npm run build && npm run test && npm run lint",
|
|
31
|
+
"test": "npx jest",
|
|
32
|
+
"test-watch": "npx jest --watch",
|
|
33
|
+
"preversion": "npm run lint",
|
|
34
|
+
"version": "npm run format && git add -A lib"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@vonage/server-client": "^1.0.1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"directory": "dist"
|
|
41
|
+
}
|
|
42
42
|
}
|