Skip to content

Commit

Permalink
DEVEXP-520: E2E Verification/Start
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch committed Aug 23, 2024
1 parent 5df5cb0 commit aefdf24
Show file tree
Hide file tree
Showing 33 changed files with 927 additions and 173 deletions.
24 changes: 12 additions & 12 deletions examples/integrated-flows-examples/src/verification/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -41,21 +41,21 @@ 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;
}
});

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([
{
Expand All @@ -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([
{
Expand All @@ -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([
{
Expand All @@ -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;
Expand Down
29 changes: 15 additions & 14 deletions examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions examples/simple-examples/src/verification/start/start-data.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();
33 changes: 33 additions & 0 deletions examples/simple-examples/src/verification/start/start-flashcall.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();
31 changes: 31 additions & 0 deletions examples/simple-examples/src/verification/start/start-phonecall.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();
36 changes: 36 additions & 0 deletions examples/simple-examples/src/verification/start/start-sms.ts
Original file line number Diff line number Diff line change
@@ -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);
}

})();
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
printFullResponse,
} from '../../../config';

/** @deprecated see ../../start/start-phonecall.ts instead */
(async () => {
console.log('*******************************');
console.log('* StartVerification - callout *');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
printFullResponse,
} from '../../../config';

/** @deprecated see ../../start/start-flashcall.ts instead */
(async () => {
console.log('*********************************');
console.log('* StartVerification - flashCall *');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
printFullResponse,
} from '../../../config';

/** @deprecated see ../../start/start-data.ts instead */
(async () => {
console.log('********************************');
console.log('* StartVerification - seamless *');
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
printFullResponse,
} from '../../../config';

/** @deprecated see ../../start/start-sms.ts instead */
(async () => {
console.log('***************************');
console.log('* StartVerification - SMS *');
Expand Down
38 changes: 22 additions & 16 deletions packages/verification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions packages/verification/cucumber.js
Original file line number Diff line number Diff line change
@@ -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(' '),
};
Loading

0 comments on commit aefdf24

Please sign in to comment.