@vonage/accounts 1.17.2 → 1.17.3
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/dist/{types → cjs}/accounts.d.ts +9 -4
- package/dist/cjs/accounts.js +107 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +198 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{types → cjs}/secrets.d.ts +7 -4
- package/dist/cjs/secrets.js +114 -0
- package/dist/{types → cjs}/types/AccountCallbacks.d.ts +3 -2
- package/dist/cjs/types/AccountCallbacks.js +18 -0
- package/dist/{types → cjs}/types/Response/APISecretResponse.d.ts +4 -2
- package/dist/cjs/types/Response/APISecretResponse.js +18 -0
- package/dist/{types → cjs}/types/Response/AccountUpdateResponse.d.ts +3 -2
- package/dist/cjs/types/Response/AccountUpdateResponse.js +18 -0
- package/dist/{types → cjs}/types/Response/GetBalanceResponse.d.ts +3 -2
- package/dist/cjs/types/Response/GetBalanceResponse.js +18 -0
- package/dist/{types → cjs}/types/Response/ListAPISecretsResponse.d.ts +4 -2
- package/dist/cjs/types/Response/ListAPISecretsResponse.js +18 -0
- package/dist/{types → cjs}/types/Response/TopUpBalanceResponse.d.ts +3 -2
- package/dist/cjs/types/Response/TopUpBalanceResponse.js +18 -0
- package/dist/cjs/types/Response/index.d.ts +6 -0
- package/dist/cjs/types/Response/index.js +18 -0
- package/dist/cjs/types/index.d.ts +7 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/esm/{accounts.js → accounts.d.mts} +13 -16
- package/dist/esm/accounts.mjs +6 -0
- package/dist/esm/chunk-AH2I45CK.mjs +90 -0
- package/dist/esm/chunk-B47CNM5C.mjs +0 -0
- package/dist/esm/chunk-BKKPM5GV.mjs +0 -0
- package/dist/esm/chunk-DZH5TJEI.mjs +0 -0
- package/dist/esm/chunk-EX4P4VER.mjs +0 -0
- package/dist/esm/chunk-FH36GGNJ.mjs +0 -0
- package/dist/esm/chunk-QS5DQYR7.mjs +0 -0
- package/dist/esm/chunk-R3PGV5SN.mjs +83 -0
- package/dist/esm/chunk-XH3JJPB6.mjs +0 -0
- package/dist/esm/chunk-ZH2BJGUB.mjs +0 -0
- package/dist/esm/index.d.mts +9 -0
- package/dist/esm/index.mjs +18 -0
- package/dist/esm/{secrets.js → secrets.d.mts} +12 -19
- package/dist/esm/secrets.mjs +6 -0
- package/dist/esm/types/AccountCallbacks.d.mts +24 -0
- package/dist/esm/types/AccountCallbacks.mjs +1 -0
- package/dist/esm/types/Response/APISecretResponse.d.mts +24 -0
- package/dist/esm/types/Response/APISecretResponse.mjs +1 -0
- package/dist/esm/types/Response/AccountUpdateResponse.d.mts +30 -0
- package/dist/esm/types/Response/AccountUpdateResponse.mjs +1 -0
- package/dist/esm/types/Response/GetBalanceResponse.d.mts +15 -0
- package/dist/esm/types/Response/GetBalanceResponse.mjs +1 -0
- package/dist/esm/types/Response/ListAPISecretsResponse.d.mts +29 -0
- package/dist/esm/types/Response/ListAPISecretsResponse.mjs +1 -0
- package/dist/esm/types/Response/TopUpBalanceResponse.d.mts +23 -0
- package/dist/esm/types/Response/TopUpBalanceResponse.mjs +1 -0
- package/dist/esm/types/Response/index.d.mts +6 -0
- package/dist/esm/types/Response/index.mjs +6 -0
- package/dist/esm/types/index.d.mts +7 -0
- package/dist/esm/types/index.mjs +8 -0
- package/package.json +24 -29
- package/dist/cjs/accounts.cjs +0 -106
- package/dist/cjs/accounts.js.map +0 -1
- package/dist/cjs/index.cjs +0 -23
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/secrets.cjs +0 -102
- package/dist/cjs/secrets.js.map +0 -1
- package/dist/cjs/types/AccountCallbacks.cjs +0 -3
- package/dist/cjs/types/AccountCallbacks.js.map +0 -1
- package/dist/cjs/types/Response/APISecretResponse.cjs +0 -3
- package/dist/cjs/types/Response/APISecretResponse.js.map +0 -1
- package/dist/cjs/types/Response/AccountUpdateResponse.cjs +0 -3
- package/dist/cjs/types/Response/AccountUpdateResponse.js.map +0 -1
- package/dist/cjs/types/Response/GetBalanceResponse.cjs +0 -3
- package/dist/cjs/types/Response/GetBalanceResponse.js.map +0 -1
- package/dist/cjs/types/Response/ListAPISecretsResponse.cjs +0 -3
- package/dist/cjs/types/Response/ListAPISecretsResponse.js.map +0 -1
- package/dist/cjs/types/Response/TopUpBalanceResponse.cjs +0 -3
- package/dist/cjs/types/Response/TopUpBalanceResponse.js.map +0 -1
- package/dist/cjs/types/Response/index.cjs +0 -22
- package/dist/cjs/types/Response/index.js.map +0 -1
- package/dist/cjs/types/index.cjs +0 -19
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/esm/accounts.js.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/secrets.js.map +0 -1
- package/dist/esm/types/AccountCallbacks.js +0 -2
- package/dist/esm/types/AccountCallbacks.js.map +0 -1
- package/dist/esm/types/Response/APISecretResponse.js +0 -2
- package/dist/esm/types/Response/APISecretResponse.js.map +0 -1
- package/dist/esm/types/Response/AccountUpdateResponse.js +0 -2
- package/dist/esm/types/Response/AccountUpdateResponse.js.map +0 -1
- package/dist/esm/types/Response/GetBalanceResponse.js +0 -2
- package/dist/esm/types/Response/GetBalanceResponse.js.map +0 -1
- package/dist/esm/types/Response/ListAPISecretsResponse.js +0 -2
- package/dist/esm/types/Response/ListAPISecretsResponse.js.map +0 -1
- package/dist/esm/types/Response/TopUpBalanceResponse.js +0 -2
- package/dist/esm/types/Response/TopUpBalanceResponse.js.map +0 -1
- package/dist/esm/types/Response/index.js +0 -6
- package/dist/esm/types/Response/index.js.map +0 -1
- package/dist/esm/types/index.js +0 -3
- package/dist/esm/types/index.js.map +0 -1
- package/dist/types/accounts.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/secrets.d.ts.map +0 -1
- package/dist/types/types/AccountCallbacks.d.ts.map +0 -1
- package/dist/types/types/Response/APISecretResponse.d.ts.map +0 -1
- package/dist/types/types/Response/AccountUpdateResponse.d.ts.map +0 -1
- package/dist/types/types/Response/GetBalanceResponse.d.ts.map +0 -1
- package/dist/types/types/Response/ListAPISecretsResponse.d.ts.map +0 -1
- package/dist/types/types/Response/TopUpBalanceResponse.d.ts.map +0 -1
- package/dist/types/types/Response/index.d.ts +0 -6
- package/dist/types/types/Response/index.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -3
- package/dist/types/types/index.d.ts.map +0 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AccountCallbacks
|
|
1
|
+
import { Client, AuthenticationType } from '@vonage/server-client';
|
|
2
|
+
import { AccountCallbacks } from './types/AccountCallbacks.js';
|
|
3
|
+
import { AccountUpdateResponse } from './types/Response/AccountUpdateResponse.js';
|
|
4
|
+
import { GetBalanceResponse } from './types/Response/GetBalanceResponse.js';
|
|
5
|
+
import { TopUpBalanceResponse } from './types/Response/TopUpBalanceResponse.js';
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Client class to interact with the Account API which enables users to manage
|
|
5
9
|
* their Vonage API Account programmatically.
|
|
@@ -31,7 +35,7 @@ import { AccountCallbacks, AccountUpdateResponse, GetBalanceResponse, TopUpBalan
|
|
|
31
35
|
* const accountClient = vonage.account;
|
|
32
36
|
* ```
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
declare class Accounts extends Client {
|
|
35
39
|
/**
|
|
36
40
|
* @see {@link Client.authType}
|
|
37
41
|
*/
|
|
@@ -91,4 +95,5 @@ export declare class Accounts extends Client {
|
|
|
91
95
|
*/
|
|
92
96
|
updateAccountCallbacks(callbacks: AccountCallbacks): Promise<AccountUpdateResponse>;
|
|
93
97
|
}
|
|
94
|
-
|
|
98
|
+
|
|
99
|
+
export { Accounts };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// lib/accounts.ts
|
|
21
|
+
var accounts_exports = {};
|
|
22
|
+
__export(accounts_exports, {
|
|
23
|
+
Accounts: () => Accounts
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(accounts_exports);
|
|
26
|
+
var import_server_client = require("@vonage/server-client");
|
|
27
|
+
var Accounts = class extends import_server_client.Client {
|
|
28
|
+
/**
|
|
29
|
+
* @see {@link Client.authType}
|
|
30
|
+
*/
|
|
31
|
+
authType = import_server_client.AuthenticationType.BASIC;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the current balance of the Vonage API account.
|
|
34
|
+
* @see {@link https://rest.nexmo.com/account/get-balance}
|
|
35
|
+
* @return {Promise<GetBalanceResponse>} The current balance of the account in EUR.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* const balance = await accontClient.getBalance();
|
|
40
|
+
*
|
|
41
|
+
* console.log(`The current account balance is ${balance.value} ${balance.currency}`);
|
|
42
|
+
* console.log(`Auto-reload is ${balance.autoReload ? 'enabled' : 'disabled'}`);
|
|
43
|
+
*/
|
|
44
|
+
async getBalance() {
|
|
45
|
+
const response = await this.sendGetRequest(
|
|
46
|
+
`${this.config.restHost}/account/get-balance`
|
|
47
|
+
);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Tops up the account balance when auto-reload is enabled.
|
|
52
|
+
* The top-up amount corresponds to the amount added when auto-reload was enabled.
|
|
53
|
+
* @see {@link https://rest.nexmo.com/account/top-up}
|
|
54
|
+
* @param {string} trx - The transaction reference for the balance addition and auto-reload activation.
|
|
55
|
+
* @return {Promise<TopUpBalanceResponse>} Response indicating the success of the operation.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
*
|
|
59
|
+
* const response = await accountClient.topUpBalance('00X123456Y7890123Z');
|
|
60
|
+
*
|
|
61
|
+
* if (response['error-code'] === '200') {
|
|
62
|
+
* console.log(`The account balance has been topped up`);
|
|
63
|
+
* } else {
|
|
64
|
+
* console.log(`The account balance could not be topped up`);
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
async topUpBalance(trx) {
|
|
69
|
+
const response = await this.sendFormSubmitRequest(
|
|
70
|
+
`${this.config.restHost}/account/top-up`,
|
|
71
|
+
{ trx }
|
|
72
|
+
);
|
|
73
|
+
return response.data;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Updates the default webhook URLs associated with the account for:
|
|
77
|
+
* - Inbound SMS messages
|
|
78
|
+
* - Delivery receipts
|
|
79
|
+
* @see {@link https://rest.nexmo.com/account/settings}
|
|
80
|
+
* @param {AccountCallbacks} callbacks - The new callback URLs for the account.
|
|
81
|
+
* @return {Promise<AccountUpdateResponse>} Details of the updated or current settings.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
*
|
|
85
|
+
* const callbacks = {
|
|
86
|
+
* moCallBackUrl: 'https://example.com/webhooks/inbound-sms',
|
|
87
|
+
* drCallBackUrl: 'https://example.com/webhooks/delivery-receipts',
|
|
88
|
+
* };
|
|
89
|
+
*
|
|
90
|
+
* const response = await accountClient.updateAccountCallbacks(callbacks);
|
|
91
|
+
*
|
|
92
|
+
* for (const [key, value] of Object.entries(response)) {
|
|
93
|
+
* console.log(`New ${key}: ${value}`);
|
|
94
|
+
* }
|
|
95
|
+
*/
|
|
96
|
+
async updateAccountCallbacks(callbacks) {
|
|
97
|
+
const response = await this.sendFormSubmitRequest(
|
|
98
|
+
`${this.config.restHost}/account/settings`,
|
|
99
|
+
callbacks
|
|
100
|
+
);
|
|
101
|
+
return response.data;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
Accounts
|
|
107
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Accounts } from './accounts.js';
|
|
2
|
+
export { Secrets } from './secrets.js';
|
|
3
|
+
export { AccountCallbacks } from './types/AccountCallbacks.js';
|
|
4
|
+
export { APISecretResponse } from './types/Response/APISecretResponse.js';
|
|
5
|
+
export { AccountUpdateResponse } from './types/Response/AccountUpdateResponse.js';
|
|
6
|
+
export { GetBalanceResponse } from './types/Response/GetBalanceResponse.js';
|
|
7
|
+
export { ListAPISecretsResponse } from './types/Response/ListAPISecretsResponse.js';
|
|
8
|
+
export { TopUpBalanceResponse } from './types/Response/TopUpBalanceResponse.js';
|
|
9
|
+
import '@vonage/server-client';
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// lib/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Accounts: () => Accounts,
|
|
24
|
+
Secrets: () => Secrets
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// lib/accounts.ts
|
|
29
|
+
var import_server_client = require("@vonage/server-client");
|
|
30
|
+
var Accounts = class extends import_server_client.Client {
|
|
31
|
+
/**
|
|
32
|
+
* @see {@link Client.authType}
|
|
33
|
+
*/
|
|
34
|
+
authType = import_server_client.AuthenticationType.BASIC;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the current balance of the Vonage API account.
|
|
37
|
+
* @see {@link https://rest.nexmo.com/account/get-balance}
|
|
38
|
+
* @return {Promise<GetBalanceResponse>} The current balance of the account in EUR.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* const balance = await accontClient.getBalance();
|
|
43
|
+
*
|
|
44
|
+
* console.log(`The current account balance is ${balance.value} ${balance.currency}`);
|
|
45
|
+
* console.log(`Auto-reload is ${balance.autoReload ? 'enabled' : 'disabled'}`);
|
|
46
|
+
*/
|
|
47
|
+
async getBalance() {
|
|
48
|
+
const response = await this.sendGetRequest(
|
|
49
|
+
`${this.config.restHost}/account/get-balance`
|
|
50
|
+
);
|
|
51
|
+
return response.data;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Tops up the account balance when auto-reload is enabled.
|
|
55
|
+
* The top-up amount corresponds to the amount added when auto-reload was enabled.
|
|
56
|
+
* @see {@link https://rest.nexmo.com/account/top-up}
|
|
57
|
+
* @param {string} trx - The transaction reference for the balance addition and auto-reload activation.
|
|
58
|
+
* @return {Promise<TopUpBalanceResponse>} Response indicating the success of the operation.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
*
|
|
62
|
+
* const response = await accountClient.topUpBalance('00X123456Y7890123Z');
|
|
63
|
+
*
|
|
64
|
+
* if (response['error-code'] === '200') {
|
|
65
|
+
* console.log(`The account balance has been topped up`);
|
|
66
|
+
* } else {
|
|
67
|
+
* console.log(`The account balance could not be topped up`);
|
|
68
|
+
* }
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
async topUpBalance(trx) {
|
|
72
|
+
const response = await this.sendFormSubmitRequest(
|
|
73
|
+
`${this.config.restHost}/account/top-up`,
|
|
74
|
+
{ trx }
|
|
75
|
+
);
|
|
76
|
+
return response.data;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Updates the default webhook URLs associated with the account for:
|
|
80
|
+
* - Inbound SMS messages
|
|
81
|
+
* - Delivery receipts
|
|
82
|
+
* @see {@link https://rest.nexmo.com/account/settings}
|
|
83
|
+
* @param {AccountCallbacks} callbacks - The new callback URLs for the account.
|
|
84
|
+
* @return {Promise<AccountUpdateResponse>} Details of the updated or current settings.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
*
|
|
88
|
+
* const callbacks = {
|
|
89
|
+
* moCallBackUrl: 'https://example.com/webhooks/inbound-sms',
|
|
90
|
+
* drCallBackUrl: 'https://example.com/webhooks/delivery-receipts',
|
|
91
|
+
* };
|
|
92
|
+
*
|
|
93
|
+
* const response = await accountClient.updateAccountCallbacks(callbacks);
|
|
94
|
+
*
|
|
95
|
+
* for (const [key, value] of Object.entries(response)) {
|
|
96
|
+
* console.log(`New ${key}: ${value}`);
|
|
97
|
+
* }
|
|
98
|
+
*/
|
|
99
|
+
async updateAccountCallbacks(callbacks) {
|
|
100
|
+
const response = await this.sendFormSubmitRequest(
|
|
101
|
+
`${this.config.restHost}/account/settings`,
|
|
102
|
+
callbacks
|
|
103
|
+
);
|
|
104
|
+
return response.data;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// lib/secrets.ts
|
|
109
|
+
var import_server_client2 = require("@vonage/server-client");
|
|
110
|
+
var Secrets = class extends import_server_client2.Client {
|
|
111
|
+
authType = import_server_client2.AuthenticationType.BASIC;
|
|
112
|
+
/**
|
|
113
|
+
* Create a new API secret for a given API key.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} apiKey - The API key to manage secrets for.
|
|
116
|
+
* @param {string} secret - The new secret. It must follow the provided rules:
|
|
117
|
+
* - Minimum 8 characters.
|
|
118
|
+
* - Maximum 25 characters.
|
|
119
|
+
* - At least 1 lowercase character.
|
|
120
|
+
* - At least 1 uppercase character.
|
|
121
|
+
* - At least 1 digit.
|
|
122
|
+
*
|
|
123
|
+
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the created API secret.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const { id } = await secretClient.createSecret(
|
|
127
|
+
* 'new-api-key',
|
|
128
|
+
* 'SuperSecret123!'
|
|
129
|
+
* );
|
|
130
|
+
*
|
|
131
|
+
* console.log(`Created secret with ID ${id}`);
|
|
132
|
+
*/
|
|
133
|
+
async createSecret(apiKey, secret) {
|
|
134
|
+
const response = await this.sendPostRequest(
|
|
135
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets`,
|
|
136
|
+
{ secret }
|
|
137
|
+
);
|
|
138
|
+
return response.data;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Revoke (delete) an existing API secret for a given API key.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} apiKey - The API key to manage secrets for.
|
|
144
|
+
* @param {string} id - The ID of the API secret to revoke.
|
|
145
|
+
* @return {Promise<void>} A promise that resolves when the secret has been revoked.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* await secretClient.deleteSecret('my-api-key', 'my-secret-id');
|
|
149
|
+
*/
|
|
150
|
+
async deleteSecret(apiKey, id) {
|
|
151
|
+
await this.sendDeleteRequest(
|
|
152
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets/${id}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Retrieve the details of a specific API secret for a given API key.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} apiKey - The API key to manage secrets for.
|
|
159
|
+
* @param {string} id - The ID of the API secret to retrieve.
|
|
160
|
+
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the API secret.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* const { id } = await secretClient.getSecret('my-api-key', 'my-secret-id');
|
|
164
|
+
* console.log(`Secret with ID ${id} has been retrieved`);
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
async getSecret(apiKey, id) {
|
|
168
|
+
const response = await this.sendGetRequest(
|
|
169
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets/${id}`
|
|
170
|
+
);
|
|
171
|
+
return response.data;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* List all the secrets associated with a particular API key.
|
|
175
|
+
*
|
|
176
|
+
* @param {string} apiKey - The API key for which to list secrets.
|
|
177
|
+
*
|
|
178
|
+
* @return {Promise<ListAPISecretsResponse>} A promise that resolves to an object containing a list of API secrets.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const response = await secretClient.listSecrets('my-api-key');
|
|
182
|
+
*
|
|
183
|
+
* for (const secret of response._embedded.secrets) {
|
|
184
|
+
* console.log(`Secret with ID ${secret.id} has been retrieved`);
|
|
185
|
+
* }
|
|
186
|
+
*/
|
|
187
|
+
async listSecrets(apiKey) {
|
|
188
|
+
const response = await this.sendGetRequest(
|
|
189
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets`
|
|
190
|
+
);
|
|
191
|
+
return response.data;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
Accounts,
|
|
197
|
+
Secrets
|
|
198
|
+
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { APISecretResponse
|
|
1
|
+
import { Client, AuthenticationType } from '@vonage/server-client';
|
|
2
|
+
import { APISecretResponse } from './types/Response/APISecretResponse.js';
|
|
3
|
+
import { ListAPISecretsResponse } from './types/Response/ListAPISecretsResponse.js';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Client class to interact with the Account API to create secrets in
|
|
5
7
|
* their Vonage API Account programmatically.
|
|
@@ -21,7 +23,7 @@ import { APISecretResponse, ListAPISecretsResponse } from './types/index.js';
|
|
|
21
23
|
* ```
|
|
22
24
|
*
|
|
23
25
|
*/
|
|
24
|
-
|
|
26
|
+
declare class Secrets extends Client {
|
|
25
27
|
protected authType: AuthenticationType;
|
|
26
28
|
/**
|
|
27
29
|
* Create a new API secret for a given API key.
|
|
@@ -85,4 +87,5 @@ export declare class Secrets extends Client {
|
|
|
85
87
|
*/
|
|
86
88
|
listSecrets(apiKey: string): Promise<ListAPISecretsResponse>;
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
|
|
91
|
+
export { Secrets };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// lib/secrets.ts
|
|
21
|
+
var secrets_exports = {};
|
|
22
|
+
__export(secrets_exports, {
|
|
23
|
+
Secrets: () => Secrets
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(secrets_exports);
|
|
26
|
+
var import_server_client = require("@vonage/server-client");
|
|
27
|
+
var Secrets = class extends import_server_client.Client {
|
|
28
|
+
authType = import_server_client.AuthenticationType.BASIC;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new API secret for a given API key.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} apiKey - The API key to manage secrets for.
|
|
33
|
+
* @param {string} secret - The new secret. It must follow the provided rules:
|
|
34
|
+
* - Minimum 8 characters.
|
|
35
|
+
* - Maximum 25 characters.
|
|
36
|
+
* - At least 1 lowercase character.
|
|
37
|
+
* - At least 1 uppercase character.
|
|
38
|
+
* - At least 1 digit.
|
|
39
|
+
*
|
|
40
|
+
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the created API secret.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const { id } = await secretClient.createSecret(
|
|
44
|
+
* 'new-api-key',
|
|
45
|
+
* 'SuperSecret123!'
|
|
46
|
+
* );
|
|
47
|
+
*
|
|
48
|
+
* console.log(`Created secret with ID ${id}`);
|
|
49
|
+
*/
|
|
50
|
+
async createSecret(apiKey, secret) {
|
|
51
|
+
const response = await this.sendPostRequest(
|
|
52
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets`,
|
|
53
|
+
{ secret }
|
|
54
|
+
);
|
|
55
|
+
return response.data;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Revoke (delete) an existing API secret for a given API key.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} apiKey - The API key to manage secrets for.
|
|
61
|
+
* @param {string} id - The ID of the API secret to revoke.
|
|
62
|
+
* @return {Promise<void>} A promise that resolves when the secret has been revoked.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* await secretClient.deleteSecret('my-api-key', 'my-secret-id');
|
|
66
|
+
*/
|
|
67
|
+
async deleteSecret(apiKey, id) {
|
|
68
|
+
await this.sendDeleteRequest(
|
|
69
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets/${id}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Retrieve the details of a specific API secret for a given API key.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} apiKey - The API key to manage secrets for.
|
|
76
|
+
* @param {string} id - The ID of the API secret to retrieve.
|
|
77
|
+
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the API secret.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const { id } = await secretClient.getSecret('my-api-key', 'my-secret-id');
|
|
81
|
+
* console.log(`Secret with ID ${id} has been retrieved`);
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
async getSecret(apiKey, id) {
|
|
85
|
+
const response = await this.sendGetRequest(
|
|
86
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets/${id}`
|
|
87
|
+
);
|
|
88
|
+
return response.data;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* List all the secrets associated with a particular API key.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} apiKey - The API key for which to list secrets.
|
|
94
|
+
*
|
|
95
|
+
* @return {Promise<ListAPISecretsResponse>} A promise that resolves to an object containing a list of API secrets.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const response = await secretClient.listSecrets('my-api-key');
|
|
99
|
+
*
|
|
100
|
+
* for (const secret of response._embedded.secrets) {
|
|
101
|
+
* console.log(`Secret with ID ${secret.id} has been retrieved`);
|
|
102
|
+
* }
|
|
103
|
+
*/
|
|
104
|
+
async listSecrets(apiKey) {
|
|
105
|
+
const response = await this.sendGetRequest(
|
|
106
|
+
`${this.config.apiHost}/accounts/${apiKey}/secrets`
|
|
107
|
+
);
|
|
108
|
+
return response.data;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
Secrets
|
|
114
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents the callbacks associated with an account.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
type AccountCallbacks = {
|
|
5
5
|
/**
|
|
6
6
|
* The default webhook URL for inbound SMS. If an SMS is received at a Vonage
|
|
7
7
|
* number that does not have its own inboud SMS webhook configured, Vonage
|
|
@@ -20,4 +20,5 @@ export type AccountCallbacks = {
|
|
|
20
20
|
*/
|
|
21
21
|
drCallBackUrl?: string;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
export type { AccountCallbacks };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// lib/types/AccountCallbacks.ts
|
|
17
|
+
var AccountCallbacks_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(AccountCallbacks_exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { APILinks } from '@vonage/server-client';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Represents the response structure for an individual API secret.
|
|
4
5
|
*
|
|
@@ -9,7 +10,7 @@ import { APILinks } from '@vonage/server-client';
|
|
|
9
10
|
*
|
|
10
11
|
* @see {@link APILinks}
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
type APISecretResponse = APILinks & {
|
|
13
14
|
/**
|
|
14
15
|
* The unique identifier for the API secret.
|
|
15
16
|
*/
|
|
@@ -19,4 +20,5 @@ export type APISecretResponse = APILinks & {
|
|
|
19
20
|
*/
|
|
20
21
|
created_at: string;
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
+
|
|
24
|
+
export type { APISecretResponse };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// lib/types/Response/APISecretResponse.ts
|
|
17
|
+
var APISecretResponse_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(APISecretResponse_exports);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @remarks
|
|
5
5
|
* Settings were updated if supplied; the details of the current settings are included in the response.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type AccountUpdateResponse = {
|
|
8
8
|
/**
|
|
9
9
|
* The current or updated inbound message webhook URI.
|
|
10
10
|
*/
|
|
@@ -26,4 +26,5 @@ export type AccountUpdateResponse = {
|
|
|
26
26
|
*/
|
|
27
27
|
'max-calls-per-second': number;
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
export type { AccountUpdateResponse };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// lib/types/Response/AccountUpdateResponse.ts
|
|
17
|
+
var AccountUpdateResponse_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(AccountUpdateResponse_exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents the response structure when querying for account balance.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
type GetBalanceResponse = {
|
|
5
5
|
/**
|
|
6
6
|
* The current balance value.
|
|
7
7
|
*/
|
|
@@ -11,4 +11,5 @@ export type GetBalanceResponse = {
|
|
|
11
11
|
*/
|
|
12
12
|
autoReload: boolean;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
export type { GetBalanceResponse };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// lib/types/Response/GetBalanceResponse.ts
|
|
17
|
+
var GetBalanceResponse_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(GetBalanceResponse_exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { APISecretResponse } from './APISecretResponse.js';
|
|
2
2
|
import { APILinks } from '@vonage/server-client';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Represents the response structure when listing API secrets.
|
|
5
6
|
*
|
|
@@ -12,7 +13,7 @@ import { APILinks } from '@vonage/server-client';
|
|
|
12
13
|
* parameters to these API endpoints.
|
|
13
14
|
*
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
type ListAPISecretsResponse = APILinks & {
|
|
16
17
|
/**
|
|
17
18
|
* Contains the embedded secrets information.
|
|
18
19
|
*/
|
|
@@ -24,4 +25,5 @@ export type ListAPISecretsResponse = APILinks & {
|
|
|
24
25
|
secrets: APISecretResponse[];
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
export type { ListAPISecretsResponse };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// lib/types/Response/ListAPISecretsResponse.ts
|
|
17
|
+
var ListAPISecretsResponse_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(ListAPISecretsResponse_exports);
|