Skip to content

Commit

Permalink
DEVEXP-520: E2E Verification/Start (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
asein-sinch authored Aug 28, 2024
1 parent 5df5cb0 commit ad92b7c
Show file tree
Hide file tree
Showing 27 changed files with 577 additions and 99 deletions.
20 changes: 10 additions & 10 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,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;
}
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.verifications.startPhoneCall(requestData);
console.log('Verification request sent! Please answer to the phone call ans listen to the OTP.');
const answers = await inquirer.prompt([
{
Expand Down Expand Up @@ -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.verifications.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/verifications/sms/start-sms.ts](./src/verification/verifications/sms/start-sms.ts) | `VERIFICATION_IDENTITY` |
| | [./src/verification/verifications/phonecall/start-phonecall.ts](./src/verification/verifications/phonecall/start-phonecall.ts) | `VERIFICATION_IDENTITY` |
| | [./src/verification/verifications/flashcall/start-flashcall.ts](./src/verification/verifications/flashcall/start-flashcall.ts) | `VERIFICATION_IDENTITY` |
| | [./src/verification/verifications/data/start-data.ts](./src/verification/verifications/data/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/phonecall/report-with-id_callout.ts) | `VERIFICATION_ID` + `VERIFICATION_CODE` |
| | [./src/verification/verifications/callout/report-with-identity_callout.ts](./src/verification/verifications/phonecall/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
8 changes: 4 additions & 4 deletions examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@
"sms:inbounds:list": "ts-node src/sms/inbounds/list.ts",
"sms:inbounds:get": "ts-node src/sms/inbounds/get.ts",
"verification:verifications:start-sms": "ts-node src/verification/verifications/sms/start-sms.ts",
"verification:verifications:start-callout": "ts-node src/verification/verifications/callout/start-callout.ts",
"verification:verifications:start-phonecall": "ts-node src/verification/verifications/phonecall/start-phonecall.ts",
"verification:verifications:start-flashcall": "ts-node src/verification/verifications/flashcall/start-flashcall.ts",
"verification:verifications:start-seamless": "ts-node src/verification/verifications/seamless/start-seamless.ts",
"verification:verifications:start-data": "ts-node src/verification/verifications/data/start-data.ts",
"verification:verifications:report-with-id:sms": "ts-node src/verification/verifications/sms/report-with-id_sms.ts",
"verification:verifications:report-with-id:callout": "ts-node src/verification/verifications/callout/report-with-id_callout.ts",
"verification:verifications:report-with-id:callout": "ts-node src/verification/verifications/phonecall/report-with-id_callout.ts",
"verification:verifications:report-with-id:flashcall": "ts-node src/verification/verifications/flashcall/report-with-id_flashcall.ts",
"verification:verifications:report-with-identity:sms": "ts-node src/verification/verifications/sms/report-with-identity_sms.ts",
"verification:verifications:report-with-identity:callout": "ts-node src/verification/verifications/callout/report-with-identity_callout.ts",
"verification:verifications:report-with-identity:callout": "ts-node src/verification/verifications/phonecall/report-with-identity_callout.ts",
"verification:verifications:report-with-identity:flashcall": "ts-node src/verification/verifications/flashcall/report-with-identity_flashcall.ts",
"verification:verification-status:verification-by-id": "ts-node src/verification/verification-status/verification-by-id.ts",
"verification:verification-status:verification-by-identity": "ts-node src/verification/verification-status/verification-by-identity.ts",
Expand Down
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.verifications.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);
}
})();
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-phonecall.ts instead */
(async () => {
console.log('*******************************');
console.log('* StartVerification - callout *');
Expand Down
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.verifications.startPhoneCall(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`Verification ID = ${response.id}`);
} else {
printFullResponse(response);
}
})();
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(' '),
};
3 changes: 2 additions & 1 deletion packages/verification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit ad92b7c

Please sign in to comment.