@vonage/verify
Version:
Verify API provides a choice of routes for sending a code to a user. You can use this to confirm a user's contact information, as a second factor when authenticating users, or for step-up authentication.
226 lines (223 loc) • 9.01 kB
text/typescript
import { Client, AuthenticationType } from '@vonage/server-client';
import { Command } from './enums/Command.mjs';
import { PSD2Parameters } from './types/PSD2Parameters.mjs';
import { VerificationParameters } from './types/VerificationParams.mjs';
import { VerifyCheck } from './types/VerifyCheck.mjs';
import { VerifyCheckError } from './types/VerifyCheckError.mjs';
import { VerifyControl } from './types/VerifyControl.mjs';
import { VerifyControlError } from './types/VerifyControlError.mjs';
import { VerifyError } from './types/VerifyError.mjs';
import { VerifyRequest } from './types/VerifyRequest.mjs';
import { VerifySearch } from './types/VerifySearch.mjs';
import { VerifySearchError } from './types/VerifySearchError.mjs';
import './enums/VerifyLanguages.mjs';
import './enums/Workflows.mjs';
import './types/Response/VerifyRequestResponse.mjs';
import './types/Response/VerifyCheckErrorResponse.mjs';
import './enums/CheckStatus.mjs';
import './types/Response/VerifyControlResponse.mjs';
import './types/Response/VerifySearchResponse.mjs';
import './types/Response/SearchCheckInformationResponse.mjs';
import './enums/SearchCheckStatus.mjs';
import './types/Response/SearchEventInformationResponse.mjs';
import './enums/SearchEventTypes.mjs';
import './enums/SearchStatus.mjs';
import './types/VerifySearchCheck.mjs';
import './types/Response/VerifyCheckResponse.mjs';
import './types/Response/VerifySearchErrorResponse.mjs';
/**
* The Verify class provides methods for managing and performing verification processes using the Vonage Verify API.
*
* It allows you to initiate new verification requests, check verification codes, search for verification request
* details, and perform control actions like canceling or triggering the next event for a verification process.
*
* @example
* Create a standalone Verify client
*
* ```ts
* import { Verify } from '@vonage/verify';
*
* const verifyClient = new Verify({
* apiKey: VONAGE_API_KEY,
* apiSecret: VONAGE_API_SECRET
* });
* ```
*
* @example
* Create an Verify 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 verifyClient = vonage.verify;
* ```
*/
declare class Verify extends Client {
protected authType?: AuthenticationType;
/**
* Sends a control command for a specific verification request.
*
* @param {Command} command - The control command to send, either "cancel" or "trigger_next_event".
* @param {string} requestId - The request ID of the verification to control.
* @return {Promise<VerifyControl | VerifyControlError>} A Promise that resolves to a `VerifyControl` object containing the control response on success or a `VerifyControlError` object on error.
* @throws {VerifyControlError} If an error occurs while sending the control command.
*
* @example
* Cancel a verification request
* ```ts
* import { Command, CheckStatus } from '@vonage/verify';
*
* const result = await verifyClient.sendControl(Command.CANCEL, 'REQUEST_ID')
* if (result.status === CheckStatus.SUCCESS) {
* console.log('Verification request canceled.');
* console.log(result.status);
* } else {
* console.log('Error canceling verification request.');
* console.log(result.errorText);
* }
* ```
*
* @example
* Trigger the next event for a verification request
* ```ts
* import { Command, CheckStatus } from '@vonage/verify';
*
* const result = await verifyClient.sendControl(Command.TRIGGER_NEXT_EVENT, 'REQUEST_ID')
* if (result.status === CheckStatus.SUCCESS) {
* console.log('Next event triggered');
* console.log(result.status);
* } else {
* console.log('Error triggering next event');
* console.log(result.errorText);
* }
* ```
*/
sendControl(command: Command, requestId: string): Promise<VerifyControl | VerifyControlError>;
/**
* Cancels a specific verification request.
*
* @param {string} requestId - The request ID of the verification to cancel.
* @return {Promise<VerifyControl | VerifyControlError>} A Promise that resolves to a `VerifyControl` object containing the control response on success or a `VerifyControlError` object on error.
* @throws {VerifyControlError} If an error occurs while canceling the verification request.
*
* @example
* ```ts
* import { CheckStatus } from '@vonage/verify';
*
* const result = await verifyClient.cancel('REQUEST_ID')
*
* if (result.status === CheckStatus.SUCCESS) {
* console.log('Verification request canceled.');
* console.log(result.status);
* } else {
* console.log('Error canceling verification request.');
* console.log(result.errorText);
* }
* ```
*
*/
cancel(requestId: string): Promise<VerifyControl | VerifyControlError>;
/**
* Triggers the next verification event for a specific verification request.
*
* @param {string} requestId - The request ID of the verification to trigger the next event for.
* @return {Promise<VerifyControl | VerifyControlError>} A Promise that resolves to a `VerifyControl` object containing the control response on success or a `VerifyControlError` object on error.
* @throws {VerifyControlError} If an error occurs while triggering the next verification event.
*
* @example
* ```ts
* import { CheckStatus } from '@vonage/verify';
*
* const result = await verifyClient.trigger('REQUEST_ID')
*
* if (result.status === CheckStatus.SUCCESS) {
* console.log('Verification request canceled.');
* console.log(result.status);
* } else {
* console.log('Error canceling verification request.');
* console.log(result.errorText);
* }
* ```
*/
trigger(requestId: string): Promise<VerifyControl | VerifyControlError>;
/**
* Checks the verification code for a specific verification request.
*
* @param {string} requestId - The request ID of the verification to check.
* @param {string} code - The verification code to check against.
* @return {Promise<VerifyCheck | VerifyCheckError>} A Promise that resolves to a `VerifyCheck` object containing the verification result on success or a `VerifyCheckError` object on error.
* @throws {VerifyCheckError} If an error occurs during the verification check.
*
* @example
* ```ts
* import { CheckStatus } from '@vonage/verify';
*
* const result = await verifyClient.check('REQUEST_ID', 'CODE')
* if (result.status === CheckStatus.SUCCESS) {
* console.log('Verification code is valid.');
* } else {
* console.log('Verification code is invalid.');
* }
* ```
*/
check(requestId: string, code: string): Promise<VerifyCheck | VerifyCheckError>;
/**
* Searches for the status of a verification request by its request ID.
*
* @param {string} requestId - The request ID of the verification to search for.
* @return {Promise<VerifySearch | VerifySearchError>} A `VerifySearch` object containing the verification details on success or a `VerifySearchError` object on error.
*
* @example
* ```ts
* const result = await verifyClient.search('REQUEST_ID')
* if (result.errorText) {
* console.log(`Request found with error ${result.errorText}`);
* } else {
* console.log(`Request found and submitted on ${result.dateSubmitted}`);
* }
* ```
*/
search(requestId: string): Promise<VerifySearch | VerifySearchError>;
/**
* Starts a verification request.
*
* @param {VerificationParameters | PSD2Parameters} request - The verification parameters for the request.
* @return {Promise<VerifyError | VerifyRequest>} A `VerifyError` object on error or a `VerifyRequest` object on success.
*
* @example
* ```ts
* const result = await verifyClient.start({
* number: TO_NUMBER,
* brand: BRAND_NAME
* });
*
* if (result.requestId) {
* console.log(`Request started with id ${result.requestId}`);
* } else {
* console.log(`Request failed with error: ${result.errorText}`);
* }
* ```
*
* @example
* Start a request with PSD2 parameters
* ```ts
* const result = await verifyClient.start({
* number: TO_NUMBER,
* payee: PAYEE,
* amount: AMOUNT,
* })
* if (result.requestId) {
* console.log(`Request started with id ${result.requestId}`);
* } else {
* console.log(`Request failed with error: ${result.errorText}`);
* }
* ```
*/
start(request: VerificationParameters | PSD2Parameters): Promise<VerifyError | VerifyRequest>;
}
export { Verify };