diff --git a/examples/integrated-flows-examples/src/verification/app.ts b/examples/integrated-flows-examples/src/verification/app.ts index 5c3cf202..f3b00a82 100644 --- a/examples/integrated-flows-examples/src/verification/app.ts +++ b/examples/integrated-flows-examples/src/verification/app.ts @@ -18,9 +18,9 @@ dotenv.config(); enum VerificationMethods { SMS ='sms', - CALLOUT = 'callout', + PHONE_CALL = 'phone call', FLASH_CALL = 'flash call', - SEAMLESS = 'seamless', + DATA = 'data', } inquirer.prompt([ @@ -41,13 +41,13 @@ dotenv.config(); case VerificationMethods.SMS: startSmsVerificationFlow(answers.phoneNumber); break; - case VerificationMethods.CALLOUT: - startCalloutVerificationFlow(answers.phoneNumber); + case VerificationMethods.PHONE_CALL: + startPhoneCallVerificationFlow(answers.phoneNumber); break; case VerificationMethods.FLASH_CALL: startFlashCallVerificationFlow(answers.phoneNumber); break; - case VerificationMethods.SEAMLESS: + case VerificationMethods.DATA: startSeamlessVerificationFlow(answers.phoneNumber); break; } @@ -55,7 +55,7 @@ dotenv.config(); const startSmsVerificationFlow = async (phoneNumber: string) => { const requestData = Verification.startVerificationHelper.buildSmsRequest(phoneNumber); - const response = await sinch.verification.verifications.startSms(requestData); + const response = await sinch.verification.startVerifications.startSms(requestData); console.log('Verification request sent! Please check the SMS on your you phone to get the OTP.'); const answers = await inquirer.prompt([ { @@ -72,9 +72,9 @@ dotenv.config(); }; - const startCalloutVerificationFlow = async (phoneNumber: string) => { - const requestData = Verification.startVerificationHelper.buildCalloutRequest(phoneNumber); - const response = await sinch.verification.verifications.startCallout(requestData); + const startPhoneCallVerificationFlow = async (phoneNumber: string) => { + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest(phoneNumber); + const response = await sinch.verification.startVerifications.startPhoneCall(requestData); console.log('Verification request sent! Please answer to the phone call ans listen to the OTP.'); const answers = await inquirer.prompt([ { @@ -91,7 +91,7 @@ dotenv.config(); const startFlashCallVerificationFlow = async (phoneNumber: string) => { const requestData = Verification.startVerificationHelper.buildFlashCallRequest(phoneNumber); - const response = await sinch.verification.verifications.startFlashCall(requestData); + const response = await sinch.verification.startVerifications.startFlashCall(requestData); console.log('Verification request sent! Please check the phone number calling you.'); const answers = await inquirer.prompt([ { @@ -109,10 +109,10 @@ dotenv.config(); }; const startSeamlessVerificationFlow = async (phoneNumber: string) => { - const requestData = Verification.startVerificationHelper.buildSeamlessRequest(phoneNumber); + const requestData = Verification.startVerificationHelper.buildDataRequest(phoneNumber); let response; try { - response = await sinch.verification.verifications.startSeamless(requestData); + response = await sinch.verification.startVerifications.startData(requestData); } catch (error: any) { console.log(`Impossible to process the seamless verification: ${error.data})`); return; diff --git a/examples/simple-examples/README.md b/examples/simple-examples/README.md index 9352335e..05cab7c4 100644 --- a/examples/simple-examples/README.md +++ b/examples/simple-examples/README.md @@ -149,20 +149,21 @@ yarn run numbers:regions:list ### Verification -| Service | Sample application name and location | Required parameters | -|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| -| Verifications | [./src/verification/verifications/sms/start-sms.ts](./src/verification/verifications/sms/start-sms.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verifications/sms/report-with-id_sms.ts](./src/verification/verifications/sms/report-with-id_sms.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | -| | [./src/verification/verifications/sms/report-with-identity_sms.ts](./src/verification/verifications/sms/report-with-identity_sms.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | -| | [./src/verification/verifications/flashcall/start-flashcall.ts](./src/verification/verifications/flashcall/start-flashcall.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verifications/flashcall/report-with-id_flashcall.ts](./src/verification/verifications/flashcall/report-with-id_flashcall.ts) | `VERIFICATION_ID` + `VERIFICATION_CLI` | -| | [./src/verification/verifications/flashcall/report-with-identity_flashcall.ts](./src/verification/verifications/flashcall/report-with-identity_flashcall.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CLI` | -| | [./src/verification/verifications/callout/start-callout.ts](./src/verification/verifications/callout/start-callout.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verifications/callout/report-with-id_callout.ts](./src/verification/verifications/callout/report-with-id_callout.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | -| | [./src/verification/verifications/callout/report-with-identity_callout.ts](./src/verification/verifications/callout/report-with-identity_callout.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | -| Verification-status | [./src/verification/verification-status/verification-by-id.ts](./src/verification/verification-status/verification-by-id.ts) | `VERIFICATION_ID` | -| | [./src/verification/verification-status/verification-by-identity.ts](./src/verification/verification-status/verification-by-identity.ts) | `VERIFICATION_IDENTITY` | -| | [./src/verification/verification-status/verification-by-reference.ts](./src/verification/verification-status/verification-by-reference.ts) | `VERIFICATION_REFERENCE` | +| Service | Sample application name and location | Required parameters | +|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| +| Start Verifications | [./src/verification/start/start-sms.ts](./src/verification/start/start-sms.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/start/start-phonecall.ts](./src/verification/start/start-phonecall.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/start/start-flashcall.ts](./src/verification/start/start-flashcall.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/start/start-data.ts](./src/verification/start/start-data.ts) | `VERIFICATION_IDENTITY` | +| Verifications | [./src/verification/verifications/sms/report-with-id_sms.ts](./src/verification/verifications/sms/report-with-id_sms.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | +| | [./src/verification/verifications/sms/report-with-identity_sms.ts](./src/verification/verifications/sms/report-with-identity_sms.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | +| | [./src/verification/verifications/flashcall/report-with-id_flashcall.ts](./src/verification/verifications/flashcall/report-with-id_flashcall.ts) | `VERIFICATION_ID` + `VERIFICATION_CLI` | +| | [./src/verification/verifications/flashcall/report-with-identity_flashcall.ts](./src/verification/verifications/flashcall/report-with-identity_flashcall.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CLI` | +| | [./src/verification/verifications/callout/report-with-id_callout.ts](./src/verification/verifications/callout/report-with-id_callout.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` | +| | [./src/verification/verifications/callout/report-with-identity_callout.ts](./src/verification/verifications/callout/report-with-identity_callout.ts) | `VERIFICATION_IDENTITY` + `VERIFICATION_CODE` | +| Verification-status | [./src/verification/verification-status/verification-by-id.ts](./src/verification/verification-status/verification-by-id.ts) | `VERIFICATION_ID` | +| | [./src/verification/verification-status/verification-by-identity.ts](./src/verification/verification-status/verification-by-identity.ts) | `VERIFICATION_IDENTITY` | +| | [./src/verification/verification-status/verification-by-reference.ts](./src/verification/verification-status/verification-by-reference.ts) | `VERIFICATION_REFERENCE` | ### Voice diff --git a/examples/simple-examples/src/verification/start/start-data.ts b/examples/simple-examples/src/verification/start/start-data.ts new file mode 100644 index 00000000..9bd7307e --- /dev/null +++ b/examples/simple-examples/src/verification/start/start-data.ts @@ -0,0 +1,32 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../config'; + +(async () => { + console.log('****************************'); + console.log('* StartVerification - data *'); + console.log('****************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + + const requestData = Verification.startVerificationHelper.buildDataRequest( + verificationIdentity, + `test-reference-for-seamless-verification_${verificationIdentity}`, + ); + + const verificationService = initVerificationService(); + const response = await verificationService.startVerifications.startData(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Verification ID = ${response.id}`); + console.log(`Data verification specific field: targetUri = ${response.seamless?.targetUri}`); + } else { + printFullResponse(response); + } +})(); diff --git a/examples/simple-examples/src/verification/start/start-flashcall.ts b/examples/simple-examples/src/verification/start/start-flashcall.ts new file mode 100644 index 00000000..6bc29856 --- /dev/null +++ b/examples/simple-examples/src/verification/start/start-flashcall.ts @@ -0,0 +1,33 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../config'; + +(async () => { + console.log('*********************************'); + console.log('* StartVerification - flashCall *'); + console.log('*********************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + + const requestData = Verification.startVerificationHelper.buildFlashCallRequest( + verificationIdentity, + `test-reference-for-flashCall-verification_${verificationIdentity}`, + 20, + ); + + const verificationService = initVerificationService(); + const response = await verificationService.startVerifications.startFlashCall(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Verification ID = ${response.id}`); + console.log(`FlashCall verification specific field: cliFilter = ${response.flashCall?.cliFilter}`); + } else { + printFullResponse(response); + } +})(); diff --git a/examples/simple-examples/src/verification/start/start-phonecall.ts b/examples/simple-examples/src/verification/start/start-phonecall.ts new file mode 100644 index 00000000..fe5aa1d7 --- /dev/null +++ b/examples/simple-examples/src/verification/start/start-phonecall.ts @@ -0,0 +1,31 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../config'; + +(async () => { + console.log('**********************************'); + console.log('* StartVerification - phoneCall *'); + console.log('**********************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest( + verificationIdentity, + `test-reference-for-callout-verification_${verificationIdentity}`, + ); + + const verificationService = initVerificationService(); + const response = await verificationService.startVerifications.startPhoneCall(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Verification ID = ${response.id}`); + } else { + printFullResponse(response); + } +})(); diff --git a/examples/simple-examples/src/verification/start/start-sms.ts b/examples/simple-examples/src/verification/start/start-sms.ts new file mode 100644 index 00000000..51869c94 --- /dev/null +++ b/examples/simple-examples/src/verification/start/start-sms.ts @@ -0,0 +1,36 @@ +import { Verification } from '@sinch/sdk-core'; +import { + getPrintFormat, + getVerificationIdentityFromConfig, + initVerificationService, + printFullResponse, +} from '../../config'; + +(async () => { + console.log('***************************'); + console.log('* StartVerification - SMS *'); + console.log('***************************'); + + const verificationIdentity = getVerificationIdentityFromConfig(); + + const requestData = Verification.startVerificationHelper.buildSmsRequest( + verificationIdentity, + `test-reference-for-sms-verification_${verificationIdentity}`, + { + locale: 'sv-SE', + }, + ); + + const verificationService = initVerificationService(); + const response = await verificationService.startVerifications.startSms(requestData); + + const printFormat = getPrintFormat(process.argv); + + if (printFormat === 'pretty') { + console.log(`Verification ID = ${response.id}`); + console.log(`SMS verification specific field: template = ${response.sms?.template}`); + } else { + printFullResponse(response); + } + +})(); diff --git a/examples/simple-examples/src/verification/verifications/callout/start-callout.ts b/examples/simple-examples/src/verification/verifications/callout/start-callout.ts index 1a0a6ddb..11cf58c3 100644 --- a/examples/simple-examples/src/verification/verifications/callout/start-callout.ts +++ b/examples/simple-examples/src/verification/verifications/callout/start-callout.ts @@ -6,6 +6,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ../../start/start-phonecall.ts instead */ (async () => { console.log('*******************************'); console.log('* StartVerification - callout *'); diff --git a/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts b/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts index 125cf583..07615bad 100644 --- a/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts +++ b/examples/simple-examples/src/verification/verifications/flashcall/start-flashcall.ts @@ -6,6 +6,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ../../start/start-flashcall.ts instead */ (async () => { console.log('*********************************'); console.log('* StartVerification - flashCall *'); diff --git a/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts b/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts index c72e5555..f6ea52b2 100644 --- a/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts +++ b/examples/simple-examples/src/verification/verifications/seamless/start-seamless.ts @@ -6,6 +6,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ../../start/start-data.ts instead */ (async () => { console.log('********************************'); console.log('* StartVerification - seamless *'); @@ -25,7 +26,7 @@ import { if (printFormat === 'pretty') { console.log(`Verification ID = ${response.id}`); - console.log(`Seamless verification specific field: template = ${response.seamless?.targetUri}`); + console.log(`Seamless verification specific field: targetUri = ${response.seamless?.targetUri}`); } else { printFullResponse(response); } diff --git a/examples/simple-examples/src/verification/verifications/sms/start-sms.ts b/examples/simple-examples/src/verification/verifications/sms/start-sms.ts index 75abfea2..11308321 100644 --- a/examples/simple-examples/src/verification/verifications/sms/start-sms.ts +++ b/examples/simple-examples/src/verification/verifications/sms/start-sms.ts @@ -6,6 +6,7 @@ import { printFullResponse, } from '../../../config'; +/** @deprecated see ../../start/start-sms.ts instead */ (async () => { console.log('***************************'); console.log('* StartVerification - SMS *'); diff --git a/packages/verification/README.md b/packages/verification/README.md index 7a7631a4..5524a2fd 100644 --- a/packages/verification/README.md +++ b/packages/verification/README.md @@ -50,19 +50,22 @@ const sinch = new SinchClient(credentials); const verificationService: VerificationService = sinch.verification; // Build the request data -const requestData: Verification.StartVerificationRequestData = { - initiateVerificationRequestBody: { +const requestData: Verification.StartSmsVerificationRequestData = { + startVerificationWithSmsRequestBody: { identity: { type: 'number', endpoint: '+17813334444', }, - method: 'sms', + smsOptions: { + codeType: 'Alphanumeric', + locale: 'sv-SE', + }, }, }; // Use the 'verification' service registered on the Sinch client -const verificationInitResponse: Verification.InitiateVerificationResponse - = await verificationService.verifications.start(requestData); +const startVerificationResponse: Verification.StartSmsVerificationResponse + = await verificationService.startVerifications.startSms(requestData); ``` ### Standalone @@ -87,19 +90,22 @@ const credentials: ApplicationCredentials = { const verificationService = new VerificationService(credentials); // Build the request data -const requestData: Verification.StartVerificationRequestData = { - initiateVerificationRequestBody: { +const requestData: Verification.StartSmsVerificationRequestData = { + startVerificationWithSmsRequestBody: { identity: { type: 'number', endpoint: '+17813334444', }, - method: 'sms', + smsOptions: { + codeType: 'Alphanumeric', + locale: 'sv-SE', + }, }, }; // Use the standalone declaration of the 'verification' service -const verificationInitResponse: Verification.InitiateVerificationResponse - = await verificationService.verifications.start(requestData); +const startVerificationResponse: Verification.StartSmsVerificationResponse + = await verificationService.startVerifications.startSms(requestData); ``` ## Promises @@ -108,18 +114,18 @@ All the methods that interact with the Sinch APIs use Promises. You can use `awa ```typescript // Method 1: Wait for the Promise to complete (you need to be in an 'async' method) -let verificationInitResponse: Verification.InitiateVerificationResponse; +let startVerificationResponse: Verification.StartSmsVerificationResponse; try { - verificationInitResponse = await verificationService.verifications.start(requestData); - console.log(`Verification ID = ${verificationInitResponse.id}`); + startVerificationResponse = await verificationService.startVerifications.startSms(requestData); + console.log(`Verification ID = ${startVerificationResponse.id}`); } catch (error: any) { - console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.initiateVerificationRequestBody.identity.endpoint}`); + console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.startVerificationWithSmsRequestBody.identity.endpoint}`); } // Method 2: Resolve the promise -verificationService.verifications.start(requestData) +verificationService.startVerifications.startSms(requestData) .then(response => console.log(`Verification ID = ${response.id}`)) - .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.initiateVerificationRequestBody.identity.endpoint}`)); + .catch(error => console.error(`ERROR ${error.statusCode}: Impossible to start the verification for the number ${requestData.startVerificationWithSmsRequestBody.identity.endpoint}`)); ``` ## Contact diff --git a/packages/verification/cucumber.js b/packages/verification/cucumber.js new file mode 100644 index 00000000..691a9809 --- /dev/null +++ b/packages/verification/cucumber.js @@ -0,0 +1,8 @@ +module.exports = { + default: [ + 'tests/e2e/features/**/*.feature', + '--require-module ts-node/register', + '--require tests/rest/v1/**/*.steps.ts', + `--format-options '{"snippetInterface": "synchronous"}'`, + ].join(' '), +}; diff --git a/packages/verification/package.json b/packages/verification/package.json index fe951ea8..1213ac53 100644 --- a/packages/verification/package.json +++ b/packages/verification/package.json @@ -25,7 +25,8 @@ "scripts": { "build": "yarn run clean && yarn run compile", "clean": "rimraf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo", - "compile": "tsc -p tsconfig.build.json && tsc -p tsconfig.tests.json && rimraf dist/tests tsconfig.build.tsbuildinfo" + "compile": "tsc -p tsconfig.build.json && tsc -p tsconfig.tests.json && rimraf dist/tests tsconfig.build.tsbuildinfo", + "test:e2e": "cucumber-js" }, "dependencies": { "@sinch/sdk-client": "^1.1.0" diff --git a/packages/verification/src/models/v1/helper.ts b/packages/verification/src/models/v1/helper.ts index 44735e07..817dcc9f 100644 --- a/packages/verification/src/models/v1/helper.ts +++ b/packages/verification/src/models/v1/helper.ts @@ -6,13 +6,23 @@ import { ReportSmsVerificationByIdentityRequestData, ReportSmsVerificationByIdRequestData, StartCalloutVerificationRequestData, + StartDataVerificationRequestData, StartFlashCallVerificationRequestData, + StartPhoneCallVerificationRequestData, StartSeamlessVerificationRequestData, StartSmsVerificationRequestData, } from './requests'; import { SmsOptions } from './start-verification-request'; export const startVerificationHelper = { + /** + * Builds a request object for starting an SMS verification process. + * + * @param {string} phoneNumber - The phone number to which the verification SMS should be sent. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @param {SmsOptions} [smsOptions] - Optional parameters for configuring the SMS verification request, with default values assumed for all contained values if not provided. + * @return {StartSmsVerificationRequestData} The constructed SMS verification request data. + */ buildSmsRequest: ( phoneNumber: string, reference?: string, @@ -33,6 +43,44 @@ export const startVerificationHelper = { }, }; }, + /** + * Builds a request object for starting a phone call verification process. + * + * @param {string} phoneNumber - The phone number to which the verification call should be made. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @param {string} [locale] - An optional language-region identifier to use for the verification call. + * @return {StartPhoneCallVerificationRequestData} The request data object for initiating the phone call verification. + */ + buildPhoneCallRequest: ( + phoneNumber: string, + reference?: string, + locale?: string, + ): StartPhoneCallVerificationRequestData => { + return { + startVerificationWithPhoneCallRequestBody: { + identity: { + type: 'number', + endpoint: phoneNumber, + }, + reference, + ...(locale !== undefined) ? { + phoneCallOptions: { + speech: { + locale, + }, + }, + } : {}, + }, + }; + }, + /** + * Builds a callout request body with the provided phone number, reference, and locale. + * + * @param {string} phoneNumber - The phone number to which the callout will be made. + * @param {string} [reference] - An optional reference identifier for the callout. + * @param {string} [locale] - An optional locale string to specify the language or region for the callout. + * @return {StartCalloutVerificationRequestData} The constructed callout request object. + * @deprecated */ buildCalloutRequest: ( phoneNumber: string, reference?: string, @@ -55,6 +103,14 @@ export const startVerificationHelper = { }, }; }, + /** + * Builds a request object for starting a flash call verification process. + * + * @param {string} phoneNumber - The phone number to which the flash call verification should be made. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @param {number} [dialTimeout] - An optional timeout value in seconds for how long to wait for the flash call to be answered. + * @return {StartFlashCallVerificationRequestData} The request data object for initiating the flash call verification. + */ buildFlashCallRequest: ( phoneNumber: string, reference?: string, @@ -75,6 +131,35 @@ export const startVerificationHelper = { }, }; }, + /** + * Builds a request object for initiating a data verification process. + * + * @param {string} phoneNumber - The phone number to be verified. + * @param {string} [reference] - An optional reference identifier used to pass your own reference in the request for tracking purposes. + * @return {StartDataVerificationRequestData} The request data object used to start the data verification. + */ + buildDataRequest: ( + phoneNumber: string, + reference?: string, + ): StartDataVerificationRequestData => { + return { + startDataVerificationRequestBody: { + identity: { + type: 'number', + endpoint: phoneNumber, + }, + reference, + }, + }; + }, + /** + * Builds a seamless verification request body with the provided phone number and optional reference. + * + * @param {string} phoneNumber - The phone number to verify. + * @param {string} [reference] - An optional reference identifier for the verification request. + * @return {StartSeamlessVerificationRequestData} The constructed seamless verification request data. + * @deprecated + */ buildSeamlessRequest: ( phoneNumber: string, reference?: string, diff --git a/packages/verification/src/models/v1/index.ts b/packages/verification/src/models/v1/index.ts index eeb783e2..cea9c020 100644 --- a/packages/verification/src/models/v1/index.ts +++ b/packages/verification/src/models/v1/index.ts @@ -6,16 +6,16 @@ export * from './verification-report-request'; export * from './start-sms-verification-response'; export * from './sms-verification-report-response'; export * from './sms-verification-status-response'; -// Models associated to Callout verification workflow -export * from './start-callout-verification-response'; +// Models associated to PhoneCall verification workflow +export * from './start-phonecall-verification-response'; export * from './callout-verification-report-response'; export * from './callout-verification-status-response'; // Models associated to Flashcall verification workflow export * from './start-flashcall-verification-response'; export * from './flashcall-verification-report-response'; export * from './flashcall-verification-status-response'; -// Models associated to Seamless verification workflow -export * from './start-seamless-verification-response'; +// Models associated to Data verification workflow +export * from './start-data-verification-response'; // Wrapper for the various types of Verification Status Response export * from './verification-status-response'; // Models associated to callback events diff --git a/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts b/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts index 2c8e064a..0842d3d0 100644 --- a/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts +++ b/packages/verification/src/models/v1/requests/verifications/verifications-request-data.ts @@ -4,9 +4,11 @@ import { SmsVerificationReportRequest, } from '../../verification-report-request'; import { + StartDataVerification, StartSeamlessVerification, StartVerificationWithCallout, StartVerificationWithFlashCall, + StartVerificationWithPhoneCall, StartVerificationWithSms, } from '../../start-verification-request'; @@ -60,11 +62,22 @@ export interface StartFlashCallVerificationRequestData { 'startVerificationWithFlashCallRequestBody': StartVerificationWithFlashCall; } +export interface StartPhoneCallVerificationRequestData { + 'startVerificationWithPhoneCallRequestBody': StartVerificationWithPhoneCall; +} + +/** @deprecated */ export interface StartCalloutVerificationRequestData { /** Request body to start a verification with a callout */ 'startVerificationWithCalloutRequestBody': StartVerificationWithCallout; } +export interface StartDataVerificationRequestData { + /** Request body to start a seamless verification */ + 'startDataVerificationRequestBody': StartDataVerification; +} + +/** @deprecated */ export interface StartSeamlessVerificationRequestData { /** Request body to start a seamless verification */ 'startSeamlessVerificationRequestBody': StartSeamlessVerification; diff --git a/packages/verification/src/models/v1/start-callout-verification-response/index.ts b/packages/verification/src/models/v1/start-callout-verification-response/index.ts deleted file mode 100644 index 1700cf35..00000000 --- a/packages/verification/src/models/v1/start-callout-verification-response/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { StartCalloutVerificationResponse } from './start-callout-verification-response'; diff --git a/packages/verification/src/models/v1/start-data-verification-response/index.ts b/packages/verification/src/models/v1/start-data-verification-response/index.ts new file mode 100644 index 00000000..3d6f1c8f --- /dev/null +++ b/packages/verification/src/models/v1/start-data-verification-response/index.ts @@ -0,0 +1,4 @@ +export type { + StartSeamlessVerificationResponse, + StartDataVerificationResponse, +} from './start-data-verification-response'; diff --git a/packages/verification/src/models/v1/start-seamless-verification-response/start-seamless-verification-response.ts b/packages/verification/src/models/v1/start-data-verification-response/start-data-verification-response.ts similarity index 76% rename from packages/verification/src/models/v1/start-seamless-verification-response/start-seamless-verification-response.ts rename to packages/verification/src/models/v1/start-data-verification-response/start-data-verification-response.ts index 8adc5156..0d4f1160 100644 --- a/packages/verification/src/models/v1/start-seamless-verification-response/start-seamless-verification-response.ts +++ b/packages/verification/src/models/v1/start-data-verification-response/start-data-verification-response.ts @@ -1,7 +1,9 @@ import { LinksObject } from '../links-object'; -export interface StartSeamlessVerificationResponse { +/** @deprecated */ +export type StartSeamlessVerificationResponse = StartDataVerificationResponse; +export interface StartDataVerificationResponse { /** Verification identifier used to query for status. */ id: string; /** The value of the method used for the Verification. For Data Verifications, this will always be `seamless`. */ @@ -13,7 +15,6 @@ export interface StartSeamlessVerificationResponse { } interface SeamlessContent { - /** The target URI. */ targetUri?: string; } diff --git a/packages/verification/src/models/v1/start-phonecall-verification-response/index.ts b/packages/verification/src/models/v1/start-phonecall-verification-response/index.ts new file mode 100644 index 00000000..b282e686 --- /dev/null +++ b/packages/verification/src/models/v1/start-phonecall-verification-response/index.ts @@ -0,0 +1,4 @@ +export type { + StartCalloutVerificationResponse, + StartPhoneCallVerificationResponse, +} from './start-phonecall-verification-response'; diff --git a/packages/verification/src/models/v1/start-callout-verification-response/start-callout-verification-response.ts b/packages/verification/src/models/v1/start-phonecall-verification-response/start-phonecall-verification-response.ts similarity index 67% rename from packages/verification/src/models/v1/start-callout-verification-response/start-callout-verification-response.ts rename to packages/verification/src/models/v1/start-phonecall-verification-response/start-phonecall-verification-response.ts index ced322ae..7d407f37 100644 --- a/packages/verification/src/models/v1/start-callout-verification-response/start-callout-verification-response.ts +++ b/packages/verification/src/models/v1/start-phonecall-verification-response/start-phonecall-verification-response.ts @@ -1,7 +1,9 @@ import { LinksObject } from '../links-object'; -export interface StartCalloutVerificationResponse { +/** @deprecated */ +export type StartCalloutVerificationResponse = StartPhoneCallVerificationResponse; +export interface StartPhoneCallVerificationResponse { /** Verification identifier used to query for status. */ id?: string; /** The value of the method used for the Verification. For Phone Call Verifications, this will always be `callout`. */ diff --git a/packages/verification/src/models/v1/start-seamless-verification-response/index.ts b/packages/verification/src/models/v1/start-seamless-verification-response/index.ts deleted file mode 100644 index 45916e62..00000000 --- a/packages/verification/src/models/v1/start-seamless-verification-response/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { StartSeamlessVerificationResponse } from './start-seamless-verification-response'; diff --git a/packages/verification/src/models/v1/start-verification-request/index.ts b/packages/verification/src/models/v1/start-verification-request/index.ts index 8cd6484e..90fb96f1 100644 --- a/packages/verification/src/models/v1/start-verification-request/index.ts +++ b/packages/verification/src/models/v1/start-verification-request/index.ts @@ -2,11 +2,16 @@ export type { StartVerificationBase, StartVerificationWithSms, StartVerificationWithFlashCall, + StartVerificationWithPhoneCall, + StartVerificationWithPhoneCallServerModel, StartVerificationWithCallout, + StartDataVerification, StartSeamlessVerification, SmsOptions, CodeType, + PhoneCallOptions, CalloutOptions, + PhoneCallOptionsSpeech, CalloutOptionsSpeech, FlashCallOptions, } from './start-verification-request'; diff --git a/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts b/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts index cc32b2d3..f49dd57b 100644 --- a/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts +++ b/packages/verification/src/models/v1/start-verification-request/start-verification-request.ts @@ -10,11 +10,25 @@ export interface StartVerificationWithFlashCall extends StartVerificationBase { flashCallOptions?: FlashCallOptions; } +export interface StartVerificationWithPhoneCall extends StartVerificationBase { + /** @see PhoneCallOptions */ + phoneCallOptions?: PhoneCallOptions; +} + +export interface StartVerificationWithPhoneCallServerModel extends StartVerificationBase { + /** @see CalloutOptions */ + calloutOptions?: CalloutOptions; +} + +/** @deprecated */ export interface StartVerificationWithCallout extends StartVerificationBase { /** @see CalloutOptions */ calloutOptions?: CalloutOptions; } +export interface StartDataVerification extends StartVerificationBase {} + +/** @deprecated */ export interface StartSeamlessVerification extends StartVerificationBase {} export interface StartVerificationBase { @@ -50,18 +64,23 @@ export interface FlashCallOptions { dialTimeout?: number; } +/** @deprecated */ +export type CalloutOptions = PhoneCallOptions; + /** * An optional object for Phone Call Verification, with default values assumed for all contained values if not provided. */ -export interface CalloutOptions { - /** @see CalloutOptionsSpeech */ - speech?: CalloutOptionsSpeech; +export interface PhoneCallOptions { + /** @see PhoneCallOptionsSpeech */ + speech?: PhoneCallOptionsSpeech; } +/** @deprecated */ +export type CalloutOptionsSpeech = PhoneCallOptionsSpeech; /** * Text-To-Speech engine settings */ -export interface CalloutOptionsSpeech { +export interface PhoneCallOptionsSpeech { /** A `language-region` identifier according to [IANA](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry). Only a subset of those identifiers is accepted. */ locale?: string; } diff --git a/packages/verification/src/rest/v1/index.ts b/packages/verification/src/rest/v1/index.ts index 248310a9..e586074f 100644 --- a/packages/verification/src/rest/v1/index.ts +++ b/packages/verification/src/rest/v1/index.ts @@ -1,4 +1,5 @@ export * from './callbacks'; +export * from './start-verifications'; export * from './verification-status'; export * from './verifications'; export * from './enums'; diff --git a/packages/verification/src/rest/v1/start-verifications/index.ts b/packages/verification/src/rest/v1/start-verifications/index.ts new file mode 100644 index 00000000..9d5217d0 --- /dev/null +++ b/packages/verification/src/rest/v1/start-verifications/index.ts @@ -0,0 +1,2 @@ +export * from './start-verifications-api'; +export * from './start-verifications-api.jest.fixture'; diff --git a/packages/verification/src/rest/v1/start-verifications/start-verifications-api.jest.fixture.ts b/packages/verification/src/rest/v1/start-verifications/start-verifications-api.jest.fixture.ts new file mode 100644 index 00000000..1521206f --- /dev/null +++ b/packages/verification/src/rest/v1/start-verifications/start-verifications-api.jest.fixture.ts @@ -0,0 +1,38 @@ +import { StartVerificationsApi } from './start-verifications-api'; +import { + StartDataVerificationRequestData, + StartDataVerificationResponse, + StartFlashCallVerificationRequestData, + StartFlashCallVerificationResponse, + StartPhoneCallVerificationRequestData, + StartPhoneCallVerificationResponse, + StartSmsVerificationRequestData, + StartSmsVerificationResponse, +} from '../../../models'; + +export class StartVerificationsApiFixture implements Partial> { + /** + * Fixture associated to function startSms + */ + public startSms: jest.Mock, + [StartSmsVerificationRequestData]> = jest.fn(); + /** + * Fixture associated to function startFlashCall + */ + public startFlashCall: jest.Mock< + Promise, + [StartFlashCallVerificationRequestData]> = jest.fn(); + /** + * Fixture associated to function startPhoneCall + */ + public startPhoneCall: jest.Mock, + [StartPhoneCallVerificationRequestData]> = jest.fn(); + /** + * Fixture associated to function startData + */ + public startData: jest.Mock< + Promise, + [StartDataVerificationRequestData]> = jest.fn(); +} diff --git a/packages/verification/src/rest/v1/start-verifications/start-verifications-api.ts b/packages/verification/src/rest/v1/start-verifications/start-verifications-api.ts new file mode 100644 index 00000000..6b1fb016 --- /dev/null +++ b/packages/verification/src/rest/v1/start-verifications/start-verifications-api.ts @@ -0,0 +1,203 @@ +import { VerificationDomainApi } from '../verification-domain-api'; +import { RequestBody, SinchClientParameters } from '@sinch/sdk-client'; +import { + StartDataVerificationRequestData, + StartDataVerificationResponse, + StartFlashCallVerificationRequestData, + StartFlashCallVerificationResponse, + StartPhoneCallVerificationRequestData, + StartPhoneCallVerificationResponse, + StartSmsVerificationRequestData, + StartSmsVerificationResponse, + StartVerificationWithPhoneCall, + StartVerificationWithSms, +} from '../../../models'; + +export class StartVerificationsApi extends VerificationDomainApi { + + /** + * Initialize your interface + * + * @param {SinchClientParameters} sinchClientParameters - The parameters used to initialize the API Client. + */ + constructor(sinchClientParameters: SinchClientParameters) { + super(sinchClientParameters, 'VerificationsApi'); + } + + /** + * Start verification with SMS + * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. + * @param { StartSmsVerificationRequestData } data - The data to provide to the API call. + */ + public async startSms(data: StartSmsVerificationRequestData): Promise { + this.client = this.getSinchClient(); + (data.startVerificationWithSmsRequestBody as any).method = 'sms'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + if (data.startVerificationWithSmsRequestBody.smsOptions?.locale !== undefined) { + headers['Accept-Language'] = data.startVerificationWithSmsRequestBody.smsOptions.locale; + } + + // Special fields handling: see method for details + const requestDataBody = this.performStartSmsRequestBodyTransformation(data.startVerificationWithSmsRequestBody); + + const body: RequestBody = requestDataBody + ? JSON.stringify(requestDataBody) + : '{}'; + const path = '/verification/v1/verifications'; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'StartVerificationWithSms', + }); + } + + performStartSmsRequestBodyTransformation(body: StartVerificationWithSms): StartVerificationWithSms { + const requestDataBody = { ...body }; + if (requestDataBody.smsOptions?.expiry !== undefined) { + const expiry = requestDataBody.smsOptions?.expiry; + if (expiry instanceof Date) { + requestDataBody.smsOptions.expiry = this.formatTime(expiry); + } + } + // Remove the `locale` property from the body as it is used as a header parameter for the API call + delete requestDataBody.smsOptions?.locale; + + return requestDataBody; + } + + formatTime(date: Date): string { + // Assume the hours needs to be set at the UTC time + Pad single-digit components with leading zeros + const formattedHours = String(date.getUTCHours()).padStart(2, '0'); + const formattedMinutes = String(date.getUTCMinutes()).padStart(2, '0'); + const formattedSeconds = String(date.getUTCSeconds()).padStart(2, '0'); + + // Concatenate the components with colons to form the formatted time string + return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`; + } + + /** + * Start verification with a FlashCall + * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. + * @param { StartFlashCallVerificationRequestData } data - The data to provide to the API call. + */ + public async startFlashCall( + data: StartFlashCallVerificationRequestData, + ): Promise { + this.client = this.getSinchClient(); + (data.startVerificationWithFlashCallRequestBody as any).method = 'flashcall'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = data['startVerificationWithFlashCallRequestBody'] + ? JSON.stringify(data['startVerificationWithFlashCallRequestBody']) + : '{}'; + const path = '/verification/v1/verifications'; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'StartVerificationWithFlashCall', + }); + } + + /** + * Start verification with a phone call + * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. + * @param { StartPhoneCallVerificationRequestData } data - The data to provide to the API call. + */ + public async startPhoneCall( + data: StartPhoneCallVerificationRequestData, + ): Promise { + this.client = this.getSinchClient(); + (data.startVerificationWithPhoneCallRequestBody as any).method = 'callout'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + // Special fields handling: see method for details + const requestDataBody = this.performStartPhoneCallRequestBodyTransformation( + data.startVerificationWithPhoneCallRequestBody); + + const body: RequestBody = requestDataBody + ? JSON.stringify(requestDataBody) + : '{}'; + + const path = '/verification/v1/verifications'; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'StartVerificationWithPhoneCall', + }); + } + + performStartPhoneCallRequestBodyTransformation(body: StartVerificationWithPhoneCall): StartVerificationWithPhoneCall { + const requestDataBody = { ...body }; + if (requestDataBody.phoneCallOptions !== undefined) { + (requestDataBody as any).calloutOptions = { ...requestDataBody.phoneCallOptions }; + delete requestDataBody.phoneCallOptions; + } + return requestDataBody; + } + + /** + * Start data verification + * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. + * @param { StartDataVerificationRequestData } data - The data to provide to the API call. + */ + public async startData(data: StartDataVerificationRequestData): Promise { + this.client = this.getSinchClient(); + (data.startDataVerificationRequestBody as any).method = 'seamless'; + const getParams = this.client.extractQueryParams(data, [] as never[]); + const headers: { [key: string]: string | undefined } = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }; + + const body: RequestBody = data['startDataVerificationRequestBody'] + ? JSON.stringify(data['startDataVerificationRequestBody']) + : '{}'; + const path = '/verification/v1/verifications'; + const basePathUrl = this.client.apiClientOptions.hostname + path; + + const requestOptions + = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); + const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); + + return this.client.processCall({ + url, + requestOptions, + apiName: this.apiName, + operationId: 'StartDataVerification', + }); + } + +} diff --git a/packages/verification/src/rest/v1/verification-service.ts b/packages/verification/src/rest/v1/verification-service.ts index ba1f98d3..bb06aae7 100644 --- a/packages/verification/src/rest/v1/verification-service.ts +++ b/packages/verification/src/rest/v1/verification-service.ts @@ -1,6 +1,7 @@ import { SinchClientParameters } from '@sinch/sdk-client'; import { VerificationStatusApi } from './verification-status'; import { VerificationsApi } from './verifications'; +import { StartVerificationsApi } from './start-verifications'; /** * The Verification Service exposes the following APIs: @@ -9,6 +10,8 @@ import { VerificationsApi } from './verifications'; */ export class VerificationService { public readonly verificationStatus: VerificationStatusApi; + public readonly startVerifications: StartVerificationsApi; + /** @deprecated */ public readonly verifications: VerificationsApi; /** @@ -22,6 +25,7 @@ export class VerificationService { */ constructor(params: SinchClientParameters) { this.verificationStatus = new VerificationStatusApi(params); + this.startVerifications = new StartVerificationsApi(params); this.verifications = new VerificationsApi(params); } @@ -31,6 +35,7 @@ export class VerificationService { */ public setHostname(hostname: string) { this.verificationStatus.setHostname(hostname); + this.startVerifications.setHostname(hostname); this.verifications.setHostname(hostname); } } diff --git a/packages/verification/src/rest/v1/verifications/verifications-api.ts b/packages/verification/src/rest/v1/verifications/verifications-api.ts index 0a38a183..e89e90a6 100644 --- a/packages/verification/src/rest/v1/verifications/verifications-api.ts +++ b/packages/verification/src/rest/v1/verifications/verifications-api.ts @@ -16,16 +16,18 @@ import { StartFlashCallVerificationRequestData, StartCalloutVerificationRequestData, StartSeamlessVerificationRequestData, - StartVerificationWithSms, } from '../../../models'; import { RequestBody, SinchClientParameters, } from '@sinch/sdk-client'; import { VerificationDomainApi } from '../verification-domain-api'; +import { StartVerificationsApi } from '../start-verifications/start-verifications-api'; export class VerificationsApi extends VerificationDomainApi { + startVerificationsApi: StartVerificationsApi; + /** * Initialize your interface * @@ -33,6 +35,7 @@ export class VerificationsApi extends VerificationDomainApi { */ constructor(sinchClientParameters: SinchClientParameters) { super(sinchClientParameters, 'VerificationsApi'); + this.startVerificationsApi = new StartVerificationsApi(sinchClientParameters); } /** @@ -245,102 +248,30 @@ export class VerificationsApi extends VerificationDomainApi { * Start verification with SMS * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. * @param { StartSmsVerificationRequestData } data - The data to provide to the API call. + * @deprecated */ public async startSms(data: StartSmsVerificationRequestData): Promise { - this.client = this.getSinchClient(); - (data.startVerificationWithSmsRequestBody as any).method = 'sms'; - const getParams = this.client.extractQueryParams(data, [] as never[]); - const headers: { [key: string]: string | undefined } = { - 'Content-Type': 'application/json; charset=UTF-8', - 'Accept': 'application/json', - }; - if (data.startVerificationWithSmsRequestBody.smsOptions?.locale !== undefined) { - headers['Accept-Language'] = data.startVerificationWithSmsRequestBody.smsOptions.locale; - } - - // Special fields handling: see method for details - const requestDataBody = this.performStartSmsRequestBodyTransformation(data.startVerificationWithSmsRequestBody); - - const body: RequestBody = requestDataBody - ? JSON.stringify(requestDataBody) - : '{}'; - const path = '/verification/v1/verifications'; - const basePathUrl = this.client.apiClientOptions.hostname + path; - - const requestOptions - = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); - const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); - - return this.client.processCall({ - url, - requestOptions, - apiName: this.apiName, - operationId: 'StartVerificationWithSms', - }); - } - - performStartSmsRequestBodyTransformation(body: StartVerificationWithSms): StartVerificationWithSms { - const requestDataBody = { ...body }; - if (requestDataBody.smsOptions?.expiry !== undefined) { - const expiry = requestDataBody.smsOptions?.expiry; - if (expiry instanceof Date) { - requestDataBody.smsOptions.expiry = this.formatTime(expiry); - } - } - // Remove the `locale` property from the body as it is used as a header parameter for the API call - delete requestDataBody.smsOptions?.locale; - - return requestDataBody; + return this.startVerificationsApi.startSms(data); } - formatTime(date: Date): string { - // Assume the hours needs to be set at the UTC time + Pad single-digit components with leading zeros - const formattedHours = String(date.getUTCHours()).padStart(2, '0'); - const formattedMinutes = String(date.getUTCMinutes()).padStart(2, '0'); - const formattedSeconds = String(date.getUTCSeconds()).padStart(2, '0'); - - // Concatenate the components with colons to form the formatted time string - return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`; - } /** * Start verification with a FlashCall * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. * @param { StartFlashCallVerificationRequestData } data - The data to provide to the API call. + * @deprecated */ public async startFlashCall( data: StartFlashCallVerificationRequestData, ): Promise { - this.client = this.getSinchClient(); - (data.startVerificationWithFlashCallRequestBody as any).method = 'flashcall'; - const getParams = this.client.extractQueryParams(data, [] as never[]); - const headers: { [key: string]: string | undefined } = { - 'Content-Type': 'application/json; charset=UTF-8', - 'Accept': 'application/json', - }; - - const body: RequestBody = data['startVerificationWithFlashCallRequestBody'] - ? JSON.stringify(data['startVerificationWithFlashCallRequestBody']) - : '{}'; - const path = '/verification/v1/verifications'; - const basePathUrl = this.client.apiClientOptions.hostname + path; - - const requestOptions - = await this.client.prepareOptions(basePathUrl, 'POST', getParams, headers, body || undefined, path); - const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams); - - return this.client.processCall({ - url, - requestOptions, - apiName: this.apiName, - operationId: 'StartVerificationWithFlashCall', - }); + return this.startVerificationsApi.startFlashCall(data); } /** * Start verification with a callout * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. * @param { StartCalloutVerificationRequestData } data - The data to provide to the API call. + * @deprecated */ public async startCallout(data: StartCalloutVerificationRequestData): Promise { this.client = this.getSinchClient(); @@ -373,6 +304,7 @@ export class VerificationsApi extends VerificationDomainApi { * Start seamless verification (= data verification) * This method is used by the mobile and web Verification SDKs to start a verification. It can also be used to request a verification from your backend, by making a request. * @param { StartSeamlessVerificationRequestData } data - The data to provide to the API call. + * @deprecated */ public async startSeamless(data: StartSeamlessVerificationRequestData): Promise { this.client = this.getSinchClient(); diff --git a/packages/verification/tests/rest/v1/start/start-verifications-api.test.ts b/packages/verification/tests/rest/v1/start/start-verifications-api.test.ts new file mode 100644 index 00000000..307d88fa --- /dev/null +++ b/packages/verification/tests/rest/v1/start/start-verifications-api.test.ts @@ -0,0 +1,189 @@ +import { + ApiClientOptions, + SigningRequest, + Verification, + StartVerificationsApi, + StartVerificationsApiFixture, +} from '../../../../src'; + +const _links: Verification.LinksObject[] = [ + { + rel: 'status', + href: 'https://dc-euc1-std.verification.api.sinch.com/verification/v1/verifications/id/some_verification_id', + method: 'GET', + }, + { + rel: 'report', + href: 'https://dc-euc1-std.verification.api.sinch.com/verification/v1/verifications/id/some_verification_id', + method: 'PUT', + }, +]; + +describe('StartVerificationsApi', () => { + let startVerificationsApi: StartVerificationsApi; + let fixture: StartVerificationsApiFixture; + let apiClientOptions: ApiClientOptions; + + beforeEach(() => { + fixture = new StartVerificationsApiFixture(); + apiClientOptions = { + projectId: 'Test_ProjectId', + requestPlugins: [new SigningRequest('keyId', 'keySecret')], + }; + startVerificationsApi = new StartVerificationsApi(apiClientOptions); + }); + + describe ('startVerification', () => { + it('should make a POST request to start a verification with an SMS', async () => { + // Given + const smsOptions: Verification.SmsOptions = { + locale: 'sv-SE', + }; + const requestData = Verification.startVerificationHelper.buildSmsRequest('+46700000000', undefined, smsOptions); + const expectedResponse: Verification.StartSmsVerificationResponse = { + id: 'some_verification_id', + method: 'sms', + sms: { + template: 'Din verifieringskod är {{CODE}}.', + interceptionTimeout: 298, + }, + _links, + }; + + // When + fixture.startSms.mockResolvedValue(expectedResponse); + startVerificationsApi.startSms = fixture.startSms; + const response = await startVerificationsApi.startSms(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.startSms).toHaveBeenCalledWith(requestData); + }); + + it('should format the expiry field', () => { + const requestData = Verification.startVerificationHelper.buildSmsRequest( + '+46700000000', + undefined, + { expiry: new Date('2024-02-10T13:22:34.685Z') }); + const expectedResult: Verification.StartVerificationWithSms = { + identity: { + endpoint: '+46700000000', + type: 'number', + }, + smsOptions: { + expiry: '13:22:34', + }, + }; + const formattedRequestData = startVerificationsApi.performStartSmsRequestBodyTransformation( + requestData.startVerificationWithSmsRequestBody); + expect(formattedRequestData).toEqual(expectedResult); + }); + + it('should leave the expiry field unchanged', () => { + const requestData = Verification.startVerificationHelper.buildSmsRequest( + '+46700000000', + undefined, + { expiry: '15:15:15' }); + const expectedResult: Verification.StartVerificationWithSms = { + identity: { + endpoint: '+46700000000', + type: 'number', + }, + smsOptions: { + expiry: '15:15:15', + }, + }; + const formattedRequestData= startVerificationsApi.performStartSmsRequestBodyTransformation( + requestData.startVerificationWithSmsRequestBody); + expect(formattedRequestData).toEqual(expectedResult); + }); + + it('should make a POST request to start a verification with a FlashCall', async () => { + // Given + const requestData = Verification.startVerificationHelper.buildFlashCallRequest('+46700000000', undefined, 30); + const expectedResponse: Verification.StartFlashCallVerificationResponse = { + id: 'some_verification_id', + method: 'flashcall', + flashCall: { + cliFilter: '(.*)70123(.*)', + interceptionTimeout: 60, + reportTimeout: 120, + denyCallAfter: 120, + }, + _links, + }; + + // When + fixture.startFlashCall.mockResolvedValue(expectedResponse); + startVerificationsApi.startFlashCall = fixture.startFlashCall; + const response = await startVerificationsApi.startFlashCall(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.startFlashCall).toHaveBeenCalledWith(requestData); + }); + + it('should make a POST request to start a verification with a PhoneCall', async () => { + // Given + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest('+46700000000'); + const expectedResponse: Verification.StartPhoneCallVerificationResponse = { + id: 'some_verification_id', + method: 'callout', + _links, + }; + + // When + fixture.startPhoneCall.mockResolvedValue(expectedResponse); + startVerificationsApi.startPhoneCall = fixture.startPhoneCall; + const response = await startVerificationsApi.startPhoneCall(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.startPhoneCall).toHaveBeenCalledWith(requestData); + }); + + it('should format the startPhoneCall request body', () => { + const requestData = Verification.startVerificationHelper.buildPhoneCallRequest( + '+46700000000', + undefined, + 'en-US'); + const expectedResult: Verification.StartVerificationWithPhoneCallServerModel = { + identity: { + endpoint: '+46700000000', + type: 'number', + }, + calloutOptions: { + speech: { + locale: 'en-US', + }, + }, + }; + const formattedRequestData = startVerificationsApi.performStartPhoneCallRequestBodyTransformation( + requestData.startVerificationWithPhoneCallRequestBody); + expect(formattedRequestData).toEqual(expectedResult); + }); + + it('should make a POST request to start a data verification (seamless)', async () => { + // Given + const requestData = Verification.startVerificationHelper.buildDataRequest('+46700000000'); + const expectedResponse: Verification.StartDataVerificationResponse = { + id: 'some_verification_id', + method: 'seamless', + seamless: { + targetUri: 'https://target-uri.com', + }, + }; + + // When + fixture.startData.mockResolvedValue(expectedResponse); + startVerificationsApi.startData = fixture.startData; + const response = await startVerificationsApi.startData(requestData); + + // Then + expect(response).toEqual(expectedResponse); + expect(fixture.startData).toHaveBeenCalledWith(requestData); + }); + + }); + +}); diff --git a/packages/verification/tests/rest/v1/start/start.steps.ts b/packages/verification/tests/rest/v1/start/start.steps.ts new file mode 100644 index 00000000..523bb14d --- /dev/null +++ b/packages/verification/tests/rest/v1/start/start.steps.ts @@ -0,0 +1,139 @@ +import { StartVerificationsApi, VerificationService, Verification } from '../../../../src'; +import { Given, When, Then } from '@cucumber/cucumber'; +import * as assert from 'assert'; +import { RequestFailedError } from '@sinch/sdk-client/src'; + +let startVerificationApi: StartVerificationsApi; +let startSmsVerificationResponse: Verification.StartSmsVerificationResponse; +let startPhoneCallVerificationResponse: Verification.StartPhoneCallVerificationResponse; +let startFlashCallVerificationResponse: Verification.StartFlashCallVerificationResponse; +let startDataVerificationResponseError: RequestFailedError; + +Given('the Verification service "Start" is available', () => { + const verificationService = new VerificationService({ + applicationKey: 'appKey', + applicationSecret: 'appSecret', + verificationHostname: 'http://localhost:3018', + }); + startVerificationApi = verificationService.startVerifications; +}); + +When('I send a request to start a verification with a SMS', async () => { + startSmsVerificationResponse = await startVerificationApi.startSms({ + startVerificationWithSmsRequestBody: { + identity: { + type: 'number', + endpoint: '+46123456789', + }, + smsOptions: { + codeType: 'Alphanumeric', + locale: 'sv-SE', + }, + }, + }); +}); + +Then('the response contains the details of a verification started with a SMS', () => { + assert.equal(startSmsVerificationResponse.id, '1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(startSmsVerificationResponse.method, 'sms'); + assert.ok(startSmsVerificationResponse.sms); + assert.equal(startSmsVerificationResponse.sms.template, 'Din verifieringskod är {{CODE}}.'); + assert.equal(startSmsVerificationResponse.sms.interceptionTimeout, 198); + assert.ok(startSmsVerificationResponse._links); + const statusLink = startSmsVerificationResponse._links[0]; + assert.equal(statusLink.rel, 'status'); + assert.equal(statusLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(statusLink.method, 'GET'); + const reportLink = startSmsVerificationResponse._links[1]; + assert.equal(reportLink.rel, 'report'); + assert.equal(reportLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d00d-f00dfeed1337'); + assert.equal(reportLink.method, 'PUT'); +}); + +When('I send a request to start a verification with a Phone Call', async () => { + startPhoneCallVerificationResponse = await startVerificationApi.startPhoneCall({ + startVerificationWithPhoneCallRequestBody: { + identity: { + type: 'number', + endpoint: '+33612345678', + }, + phoneCallOptions: { + speech: { + locale: 'fr-FR', + }, + }, + }, + }); +}); + +Then('the response contains the details of a verification started with a Phone Call', () => { + assert.equal(startPhoneCallVerificationResponse.id, '1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(startPhoneCallVerificationResponse.method, 'callout'); + assert.ok(startPhoneCallVerificationResponse._links); + const statusLink = startPhoneCallVerificationResponse._links[0]; + assert.equal(statusLink.rel, 'status'); + assert.equal(statusLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(statusLink.method, 'GET'); + const reportLink = startPhoneCallVerificationResponse._links[1]; + assert.equal(reportLink.rel, 'report'); + assert.equal(reportLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d11d-f00dfeed1337'); + assert.equal(reportLink.method, 'PUT'); +}); + +When('I send a request to start a verification with a Flash Call', async () => { + startFlashCallVerificationResponse = await startVerificationApi.startFlashCall({ + startVerificationWithFlashCallRequestBody: { + identity: { + type: 'number', + endpoint: '+33612345678', + }, + flashCallOptions: { + dialTimeout: 10, + }, + reference: 'flashcall-verification-test-e2e', + }, + }); +}); + +Then('the response contains the details of a verification started with a Flash Call', () => { + assert.equal(startFlashCallVerificationResponse.id, '1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(startFlashCallVerificationResponse.method, 'flashcall'); + assert.ok(startFlashCallVerificationResponse.flashCall); + assert.equal(startFlashCallVerificationResponse.flashCall.cliFilter, '(.*)8156(.*)'); + assert.equal(startFlashCallVerificationResponse.flashCall.interceptionTimeout, 45); + assert.equal(startFlashCallVerificationResponse.flashCall.reportTimeout, 75); + assert.equal(startFlashCallVerificationResponse.flashCall.denyCallAfter, 0); + assert.ok(startFlashCallVerificationResponse._links); + const statusLink = startFlashCallVerificationResponse._links[0]; + assert.equal(statusLink.rel, 'status'); + assert.equal(statusLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(statusLink.method, 'GET'); + const reportLink = startFlashCallVerificationResponse._links[1]; + assert.equal(reportLink.rel, 'report'); + assert.equal(reportLink.href, 'http://localhost:3018/verification/v1/verifications/id/1ce0ffee-c0de-5eed-d22d-f00dfeed1337'); + assert.equal(reportLink.method, 'PUT'); +}); + +When('I send a request to start a Data verification for a not available destination', async () => { + try { + await startVerificationApi.startData({ + startDataVerificationRequestBody: { + identity: { + type: 'number', + endpoint: '+17818880008', + }, + }, + }); + } catch (e: any) { + startDataVerificationResponseError = e as RequestFailedError; + } +}); + +Then('the response contains the error details of a Data verification', () => { + assert.equal(startDataVerificationResponseError.statusCode, 403); + assert.ok(startDataVerificationResponseError.data); + const errorDetails = JSON.parse(startDataVerificationResponseError.data) as Verification.VerificationError; + assert.equal(errorDetails.errorCode, 40300); + assert.equal(errorDetails.message, 'Seamless verification not available for given destination.'); + assert.equal(errorDetails.reference, 'c01dc0de-c4db-44f1-5ca1-da9159d21c191'); +}); diff --git a/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts b/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts index 13256578..b9c97f5d 100644 --- a/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts +++ b/packages/verification/tests/rest/v1/verifications/verifications-api.test.ts @@ -59,44 +59,6 @@ describe('VerificationsApi', () => { expect(fixture.startSms).toHaveBeenCalledWith(requestData); }); - it('should format the expiry field', () => { - const requestData = Verification.startVerificationHelper.buildSmsRequest( - '+46700000000', - undefined, - { expiry: new Date('2024-02-10T13:22:34.685Z') }); - const expectedResult: Verification.StartVerificationWithSms = { - identity: { - endpoint: '+46700000000', - type: 'number', - }, - smsOptions: { - expiry: '13:22:34', - }, - }; - const formattedRequestData - = verificationsApi.performStartSmsRequestBodyTransformation(requestData.startVerificationWithSmsRequestBody); - expect(formattedRequestData).toEqual(expectedResult); - }); - - it('should leave the expiry field unchanged', () => { - const requestData = Verification.startVerificationHelper.buildSmsRequest( - '+46700000000', - undefined, - { expiry: '15:15:15' }); - const expectedResult: Verification.StartVerificationWithSms = { - identity: { - endpoint: '+46700000000', - type: 'number', - }, - smsOptions: { - expiry: '15:15:15', - }, - }; - const formattedRequestData - = verificationsApi.performStartSmsRequestBodyTransformation(requestData.startVerificationWithSmsRequestBody); - expect(formattedRequestData).toEqual(expectedResult); - }); - it('should make a POST request to start a verification with a FlashCall', async () => { // Given const requestData = Verification.startVerificationHelper.buildFlashCallRequest('+46700000000', undefined, 30);