@vonage/accounts
Advanced tools
Comparing version 1.9.0 to 1.10.0
import { AuthenticationType, Client } from '@vonage/server-client'; | ||
import { AccountCallbacks } from './interfaces/AccountCallbacks'; | ||
import { AccountUpdateResponse } from './interfaces/Response/AccountUpdateResponse'; | ||
import { GetBalanceResponse } from './interfaces/Response/GetBalanceResponse'; | ||
import { TopUpBalanceResponse } from './interfaces/Response/TopUpBalanceResponse'; | ||
import { AccountCallbacks, AccountUpdateResponse, GetBalanceResponse, TopUpBalanceResponse } from './types'; | ||
/** | ||
* Client class to interact with the Account API which enables users to manage | ||
* their Vonage API Account programmatically. | ||
* @see {@link https://developer.nexmo.com/en/account/overview} | ||
* | ||
* @example | ||
* Create a standalone Account client | ||
* | ||
* ```ts | ||
* import { Accounts } from '@vonage/account'; | ||
* | ||
* const accountClient = new Accounts({ | ||
* apiKey: VONAGE_API_KEY, | ||
* apiSecret: VONAGE_API_SECRET | ||
* }); | ||
* ``` | ||
* | ||
* @example | ||
* Create an Account client from the Vonage client | ||
* | ||
* ```ts | ||
* import { Vonage } from '@vonage/server-client'; | ||
* | ||
* const vonage = new Vonage({ | ||
* apiKey: VONAGE_API_KEY, | ||
* apiSecret: VONAGE_API_SECRET | ||
* }); | ||
* | ||
* const accountClient = vonage.account; | ||
* ``` | ||
*/ | ||
export declare class Accounts extends Client { | ||
/** | ||
* @see {@link Client.authType} | ||
*/ | ||
protected authType: AuthenticationType; | ||
/** | ||
* Retrieves the current balance of the Vonage API account. | ||
* @see {@link https://rest.nexmo.com/account/get-balance} | ||
* @return {Promise<GetBalanceResponse>} The current balance of the account in EUR. | ||
* | ||
* @example | ||
* | ||
* const balance = await accontClient.getBalance(); | ||
* | ||
* console.log(`The current account balance is ${balance.value} ${balance.currency}`); | ||
* console.log(`Auto-reload is ${balance.autoReload ? 'enabled' : 'disabled'}`); | ||
*/ | ||
getBalance(): Promise<GetBalanceResponse>; | ||
/** | ||
* Tops up the account balance when auto-reload is enabled. | ||
* The top-up amount corresponds to the amount added when auto-reload was enabled. | ||
* @see {@link https://rest.nexmo.com/account/top-up} | ||
* @param {string} trx - The transaction reference for the balance addition and auto-reload activation. | ||
* @return {Promise<TopUpBalanceResponse>} Response indicating the success of the operation. | ||
* | ||
* @example | ||
* | ||
* const response = await accountClient.topUpBalance('00X123456Y7890123Z'); | ||
* | ||
* if (response['error-code'] === '200') { | ||
* console.log(`The account balance has been topped up`); | ||
* } else { | ||
* console.log(`The account balance could not be topped up`); | ||
* } | ||
* | ||
*/ | ||
topUpBalance(trx: string): Promise<TopUpBalanceResponse>; | ||
/** | ||
* Updates the default webhook URLs associated with the account for: | ||
* - Inbound SMS messages | ||
* - Delivery receipts | ||
* @see {@link https://rest.nexmo.com/account/settings} | ||
* @param {AccountCallbacks} callbacks - The new callback URLs for the account. | ||
* @return {Promise<AccountUpdateResponse>} Details of the updated or current settings. | ||
* | ||
* @example | ||
* | ||
* const callbacks = { | ||
* moCallBackUrl: 'https://example.com/webhooks/inbound-sms', | ||
* drCallBackUrl: 'https://example.com/webhooks/delivery-receipts', | ||
* }; | ||
* | ||
* const response = await accountClient.updateAccountCallbacks(callbacks); | ||
* | ||
* for (const [key, value] of Object.entries(response)) { | ||
* console.log(`New ${key}: ${value}`); | ||
* } | ||
*/ | ||
updateAccountCallbacks(callbacks: AccountCallbacks): Promise<AccountUpdateResponse>; | ||
} |
@@ -5,4 +5,53 @@ "use strict"; | ||
const server_client_1 = require("@vonage/server-client"); | ||
/** | ||
* Client class to interact with the Account API which enables users to manage | ||
* their Vonage API Account programmatically. | ||
* @see {@link https://developer.nexmo.com/en/account/overview} | ||
* | ||
* @example | ||
* Create a standalone Account client | ||
* | ||
* ```ts | ||
* import { Accounts } from '@vonage/account'; | ||
* | ||
* const accountClient = new Accounts({ | ||
* apiKey: VONAGE_API_KEY, | ||
* apiSecret: VONAGE_API_SECRET | ||
* }); | ||
* ``` | ||
* | ||
* @example | ||
* Create an Account client from the Vonage client | ||
* | ||
* ```ts | ||
* import { Vonage } from '@vonage/server-client'; | ||
* | ||
* const vonage = new Vonage({ | ||
* apiKey: VONAGE_API_KEY, | ||
* apiSecret: VONAGE_API_SECRET | ||
* }); | ||
* | ||
* const accountClient = vonage.account; | ||
* ``` | ||
*/ | ||
class Accounts extends server_client_1.Client { | ||
authType = server_client_1.AuthenticationType.QUERY_KEY_SECRET; | ||
constructor() { | ||
super(...arguments); | ||
/** | ||
* @see {@link Client.authType} | ||
*/ | ||
this.authType = server_client_1.AuthenticationType.QUERY_KEY_SECRET; | ||
} | ||
/** | ||
* Retrieves the current balance of the Vonage API account. | ||
* @see {@link https://rest.nexmo.com/account/get-balance} | ||
* @return {Promise<GetBalanceResponse>} The current balance of the account in EUR. | ||
* | ||
* @example | ||
* | ||
* const balance = await accontClient.getBalance(); | ||
* | ||
* console.log(`The current account balance is ${balance.value} ${balance.currency}`); | ||
* console.log(`Auto-reload is ${balance.autoReload ? 'enabled' : 'disabled'}`); | ||
*/ | ||
async getBalance() { | ||
@@ -12,2 +61,20 @@ const response = await this.sendGetRequest(`${this.config.restHost}/account/get-balance`); | ||
} | ||
/** | ||
* Tops up the account balance when auto-reload is enabled. | ||
* The top-up amount corresponds to the amount added when auto-reload was enabled. | ||
* @see {@link https://rest.nexmo.com/account/top-up} | ||
* @param {string} trx - The transaction reference for the balance addition and auto-reload activation. | ||
* @return {Promise<TopUpBalanceResponse>} Response indicating the success of the operation. | ||
* | ||
* @example | ||
* | ||
* const response = await accountClient.topUpBalance('00X123456Y7890123Z'); | ||
* | ||
* if (response['error-code'] === '200') { | ||
* console.log(`The account balance has been topped up`); | ||
* } else { | ||
* console.log(`The account balance could not be topped up`); | ||
* } | ||
* | ||
*/ | ||
async topUpBalance(trx) { | ||
@@ -17,2 +84,23 @@ const response = await this.sendFormSubmitRequest(`${this.config.restHost}/account/top-up`, { trx }); | ||
} | ||
/** | ||
* Updates the default webhook URLs associated with the account for: | ||
* - Inbound SMS messages | ||
* - Delivery receipts | ||
* @see {@link https://rest.nexmo.com/account/settings} | ||
* @param {AccountCallbacks} callbacks - The new callback URLs for the account. | ||
* @return {Promise<AccountUpdateResponse>} Details of the updated or current settings. | ||
* | ||
* @example | ||
* | ||
* const callbacks = { | ||
* moCallBackUrl: 'https://example.com/webhooks/inbound-sms', | ||
* drCallBackUrl: 'https://example.com/webhooks/delivery-receipts', | ||
* }; | ||
* | ||
* const response = await accountClient.updateAccountCallbacks(callbacks); | ||
* | ||
* for (const [key, value] of Object.entries(response)) { | ||
* console.log(`New ${key}: ${value}`); | ||
* } | ||
*/ | ||
async updateAccountCallbacks(callbacks) { | ||
@@ -24,2 +112,1 @@ const response = await this.sendFormSubmitRequest(`${this.config.restHost}/account/settings`, callbacks); | ||
exports.Accounts = Accounts; | ||
//# sourceMappingURL=accounts.js.map |
export { Accounts } from './accounts'; | ||
export { Secrets } from './secrets'; | ||
export * from './types'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,2 +22,2 @@ exports.Secrets = exports.Accounts = void 0; | ||
Object.defineProperty(exports, "Secrets", { enumerable: true, get: function () { return secrets_1.Secrets; } }); | ||
//# sourceMappingURL=index.js.map | ||
__exportStar(require("./types"), exports); |
import { AuthenticationType, Client } from '@vonage/server-client'; | ||
import { APISecretResponse } from './interfaces/Response/APISecretResponse'; | ||
import { ListAPISecretsResponse } from './interfaces/Response/ListAPISecretsResponse'; | ||
import { APISecretResponse, ListAPISecretsResponse } from './types'; | ||
/** | ||
* Client class to interact with the Account API to create secrets in | ||
* their Vonage API Account programmatically. | ||
* | ||
* @remarks | ||
* This client is only available as a standalone client. It cannot be | ||
* instantiated from the server-sdk package. | ||
* | ||
* @example | ||
* Create a standalone Secret client | ||
* | ||
* ```ts | ||
* import { Secrets } from '@vonage/account'; | ||
* | ||
* const secretClient = new Secrets({ | ||
* apiKey: VONAGE_API_KEY, | ||
* apiSecret: VONAGE_API_SECRET | ||
* }); | ||
* ``` | ||
* | ||
*/ | ||
export declare class Secrets extends Client { | ||
protected authType: AuthenticationType; | ||
/** | ||
* Create a new API secret for a given API key. | ||
* | ||
* @param {string} apiKey - The API key to manage secrets for. | ||
* @param {string} secret - The new secret. It must follow the provided rules: | ||
* - Minimum 8 characters. | ||
* - Maximum 25 characters. | ||
* - At least 1 lowercase character. | ||
* - At least 1 uppercase character. | ||
* - At least 1 digit. | ||
* | ||
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the created API secret. | ||
* | ||
* @example | ||
* const { id } = await secretClient.createSecret( | ||
* 'new-api-key', | ||
* 'SuperSecret123!' | ||
* ); | ||
* | ||
* console.log(`Created secret with ID ${id}`); | ||
*/ | ||
createSecret(apiKey: string, secret: string): Promise<APISecretResponse>; | ||
/** | ||
* Revoke (delete) an existing API secret for a given API key. | ||
* | ||
* @param {string} apiKey - The API key to manage secrets for. | ||
* @param {string} id - The ID of the API secret to revoke. | ||
* @return {Promise<void>} A promise that resolves when the secret has been revoked. | ||
* | ||
* @example | ||
* await secretClient.deleteSecret('my-api-key', 'my-secret-id'); | ||
*/ | ||
deleteSecret(apiKey: string, id: string): Promise<void>; | ||
/** | ||
* Retrieve the details of a specific API secret for a given API key. | ||
* | ||
* @param {string} apiKey - The API key to manage secrets for. | ||
* @param {string} id - The ID of the API secret to retrieve. | ||
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the API secret. | ||
* | ||
* @example | ||
* const { id } = await secretClient.getSecret('my-api-key', 'my-secret-id'); | ||
* console.log(`Secret with ID ${id} has been retrieved`); | ||
* | ||
*/ | ||
getSecret(apiKey: string, id: string): Promise<APISecretResponse>; | ||
/** | ||
* List all the secrets associated with a particular API key. | ||
* | ||
* @param {string} apiKey - The API key for which to list secrets. | ||
* | ||
* @return {Promise<ListAPISecretsResponse>} A promise that resolves to an object containing a list of API secrets. | ||
* | ||
* @example | ||
* const response = await secretClient.listSecrets('my-api-key'); | ||
* | ||
* for (const secret of response._embedded.secrets) { | ||
* console.log(`Secret with ID ${secret.id} has been retrieved`); | ||
* } | ||
*/ | ||
listSecrets(apiKey: string): Promise<ListAPISecretsResponse>; | ||
} |
@@ -5,4 +5,49 @@ "use strict"; | ||
const server_client_1 = require("@vonage/server-client"); | ||
/** | ||
* Client class to interact with the Account API to create secrets in | ||
* their Vonage API Account programmatically. | ||
* | ||
* @remarks | ||
* This client is only available as a standalone client. It cannot be | ||
* instantiated from the server-sdk package. | ||
* | ||
* @example | ||
* Create a standalone Secret client | ||
* | ||
* ```ts | ||
* import { Secrets } from '@vonage/account'; | ||
* | ||
* const secretClient = new Secrets({ | ||
* apiKey: VONAGE_API_KEY, | ||
* apiSecret: VONAGE_API_SECRET | ||
* }); | ||
* ``` | ||
* | ||
*/ | ||
class Secrets extends server_client_1.Client { | ||
authType = server_client_1.AuthenticationType.BASIC; | ||
constructor() { | ||
super(...arguments); | ||
this.authType = server_client_1.AuthenticationType.BASIC; | ||
} | ||
/** | ||
* Create a new API secret for a given API key. | ||
* | ||
* @param {string} apiKey - The API key to manage secrets for. | ||
* @param {string} secret - The new secret. It must follow the provided rules: | ||
* - Minimum 8 characters. | ||
* - Maximum 25 characters. | ||
* - At least 1 lowercase character. | ||
* - At least 1 uppercase character. | ||
* - At least 1 digit. | ||
* | ||
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the created API secret. | ||
* | ||
* @example | ||
* const { id } = await secretClient.createSecret( | ||
* 'new-api-key', | ||
* 'SuperSecret123!' | ||
* ); | ||
* | ||
* console.log(`Created secret with ID ${id}`); | ||
*/ | ||
async createSecret(apiKey, secret) { | ||
@@ -12,5 +57,27 @@ const response = await this.sendPostRequest(`${this.config.apiHost}/accounts/${apiKey}/secrets`, { secret }); | ||
} | ||
/** | ||
* Revoke (delete) an existing API secret for a given API key. | ||
* | ||
* @param {string} apiKey - The API key to manage secrets for. | ||
* @param {string} id - The ID of the API secret to revoke. | ||
* @return {Promise<void>} A promise that resolves when the secret has been revoked. | ||
* | ||
* @example | ||
* await secretClient.deleteSecret('my-api-key', 'my-secret-id'); | ||
*/ | ||
async deleteSecret(apiKey, id) { | ||
await this.sendDeleteRequest(`${this.config.apiHost}/accounts/${apiKey}/secrets/${id}`); | ||
} | ||
/** | ||
* Retrieve the details of a specific API secret for a given API key. | ||
* | ||
* @param {string} apiKey - The API key to manage secrets for. | ||
* @param {string} id - The ID of the API secret to retrieve. | ||
* @return {Promise<APISecretResponse>} A promise that resolves to an object representing the API secret. | ||
* | ||
* @example | ||
* const { id } = await secretClient.getSecret('my-api-key', 'my-secret-id'); | ||
* console.log(`Secret with ID ${id} has been retrieved`); | ||
* | ||
*/ | ||
async getSecret(apiKey, id) { | ||
@@ -20,2 +87,16 @@ const response = await this.sendGetRequest(`${this.config.apiHost}/accounts/${apiKey}/secrets/${id}`); | ||
} | ||
/** | ||
* List all the secrets associated with a particular API key. | ||
* | ||
* @param {string} apiKey - The API key for which to list secrets. | ||
* | ||
* @return {Promise<ListAPISecretsResponse>} A promise that resolves to an object containing a list of API secrets. | ||
* | ||
* @example | ||
* const response = await secretClient.listSecrets('my-api-key'); | ||
* | ||
* for (const secret of response._embedded.secrets) { | ||
* console.log(`Secret with ID ${secret.id} has been retrieved`); | ||
* } | ||
*/ | ||
async listSecrets(apiKey) { | ||
@@ -27,2 +108,1 @@ const response = await this.sendGetRequest(`${this.config.apiHost}/accounts/${apiKey}/secrets`); | ||
exports.Secrets = Secrets; | ||
//# sourceMappingURL=secrets.js.map |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@vonage/accounts", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "Vonage Account Management API", | ||
@@ -14,3 +15,12 @@ "homepage": "https://developer.vonage.com", | ||
"license": "Apache-2.0", | ||
"author": "Chris Tankersley <chris@ctankersley.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Chris Tankersley", | ||
"url": "https://github.com/dragonmantank" | ||
}, | ||
{ | ||
"name": "Chuck \"MANCHUCK\" Reeves", | ||
"url": "https://github.com/manchuck" | ||
} | ||
], | ||
"main": "dist/index.js", | ||
@@ -28,9 +38,10 @@ "types": "dist/index.d.ts", | ||
"clean": "npx shx rm -rf dist tsconfig.tsbuildinfo", | ||
"compile": "npx tsc --build --verbose" | ||
"compile": "npx tsc --build --verbose", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"@vonage/server-client": "^1.9.0" | ||
"@vonage/server-client": "^1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@vonage/auth": "^1.7.0", | ||
"@vonage/auth": "^1.8.0", | ||
"nock": "^13.3.4" | ||
@@ -40,4 +51,3 @@ }, | ||
"directory": "dist" | ||
}, | ||
"gitHead": "328f18e5c8a458cb4d06d7955ec2399a6ce6f5d8" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26685
606
24
1