Skip to content

Commit

Permalink
feat: adding network apis
Browse files Browse the repository at this point in the history
  • Loading branch information
manchuck committed Aug 20, 2024
1 parent f2e355d commit 4380e03
Show file tree
Hide file tree
Showing 49 changed files with 1,163 additions and 23 deletions.
20 changes: 18 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const config: Config.InitialOptions = {
testMatch: ['<rootDir>/packages/media/__tests__/**/*.test.ts'],
coveragePathIgnorePatterns: ['node_modules', '__tests__'],
},
{
...projectDefault,
displayName: 'MEETINGS',
testMatch: ['<rootDir>/packages/meetings/__tests__/**/*.test.ts'],
coveragePathIgnorePatterns: ['node_modules', '__tests__'],
},
{
...projectDefault,
displayName: 'MESSAGES',
Expand All @@ -68,10 +74,20 @@ const config: Config.InitialOptions = {
},
{
...projectDefault,
displayName: 'MEETINGS',
testMatch: ['<rootDir>/packages/meetings/__tests__/**/*.test.ts'],
displayName: 'NETWORK CLIENT',
testMatch: ['<rootDir>/packages/network-client/__tests__/**/*.test.ts'],
coveragePathIgnorePatterns: ['node_modules', '__tests__'],
},
// {
// displayName: 'NETWORK SIM SWAP',
// testMatch: ['<rootDir>/packages/network-sim-swap/__tests__/**/*.test.ts'],
// coveragePathIgnorePatterns: ['node_modules', '__tests__'],
// },
// {
// displayName: 'NETWORK NUMBER VERIFICATION',
// testMatch: ['<rootDir>/packages/network-sim-swap/__tests__/**/*.test.ts'],
// coveragePathIgnorePatterns: ['node_modules', '__tests__'],
// },
{
...projectDefault,
displayName: 'NUMBER INSIGHT V2',
Expand Down
11 changes: 11 additions & 0 deletions packages/network-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# `network-auth`

> TODO: description
## Usage

```
const networkAuth = require('network-auth');
// TODO: DEMONSTRATE API
```
119 changes: 119 additions & 0 deletions packages/network-client/__tests__/__dataSets__/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
NetworkClient,
Purpose,
Scope,
} from '../../lib';
import { SDKTestCase, testPrivateKey } from '../../../../testHelpers';
import { AuthenticationType } from '@vonage/server-client';

class CIBAClient extends NetworkClient {
protected authType?: AuthenticationType = AuthenticationType.CIBA

protected _purpose = Purpose.FRAUD_PREVENTION_AND_DETECTION;
protected _scope = Scope.NUMBER_VERIFICATION_VERIFY_READ;
}

export default [
{
label: 'can get CIBA request',
baseUrl: 'https://api-eu.vonage.com',
clientMethod: 'getCIBARequest',
reqHeaders: {
authorization: (value) => value.startsWith('Bearer '),
},
client: new CIBAClient(
{
privateKey: testPrivateKey,
applicationId: 'my-application',
msisdn: '447700900000',
},
),
requests: [
[
'/oauth2/bc-authorize',
'POST',
{
login_hint: `tel:+447700900000`,
scope: `openid dpv:${Purpose.FRAUD_PREVENTION_AND_DETECTION}#${Scope.NUMBER_VERIFICATION_VERIFY_READ}`,
},
],
],
responses: [
[
200,
{
auth_req_id: 'auth-req-id',
}
],
],
generator: false,
error: false,
expected: 'auth-req-id'
},
// {
// label: 'error when requesting CIBA token returns 401',
// baseUrl: 'https://api-eu.vonage.com',
// clientMethod: 'getCIBAToken',
// reqHeaders: {
// authorization: (value) => value.startsWith('Bearer '),
// },
// client: new CIBAClient(
// {
// privateKey: testPrivateKey,
// applicationId: 'my-application',
// msisdn: '447700900000',
// },
// ),
// requests: [
// [
// '/oauth2/bc-authorize',
// 'POST',
// {
// login_hint: `tel:+447700900000`,
// scope: `openid dpv:${Purpose.FRAUD_PREVENTION_AND_DETECTION}#${Scope.NUMBER_VERIFICATION_VERIFY_READ}`,
// },
// ],
// ],
// responses: [
// [
// 401,
// ],
// ],
// generator: false,
// error: 'A 401 was returned when trying to get authorization. Some possible reasons for this:- The application id or private key are invalid. - You have not setup the Network API correctly for your application .',
// expected: {foo: 'bar'}
// },
// {
// label: 'error when requesting CIBA token returns 400',
// baseUrl: 'https://api-eu.vonage.com',
// clientMethod: 'getCIBAToken',
// reqHeaders: {
// authorization: (value) => value.startsWith('Bearer '),
// },
// client: new CIBAClient(
// {
// privateKey: testPrivateKey,
// applicationId: 'my-application',
// msisdn: '447700900000',
// },
// ),
// requests: [
// [
// '/oauth2/bc-authorize',
// 'POST',
// {
// login_hint: `tel:+447700900000`,
// scope: `openid dpv:${Purpose.FRAUD_PREVENTION_AND_DETECTION}#${Scope.NUMBER_VERIFICATION_VERIFY_READ}`,
// },
// ],
// ],
// responses: [
// [
// 400,
// ],
// ],
// generator: false,
// error: 'It appears you have not enabled the Network API for your account. Please contact your account manager to enable this feature. ',
// expected: {foo: 'bar'}
// }
] as SDKTestCase<CIBAClient>[];
9 changes: 9 additions & 0 deletions packages/network-client/__tests__/__dataSets__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import getTests from './get';

export default [
{
name: 'GET tests',
tests: getTests,
},
];

5 changes: 5 additions & 0 deletions packages/network-client/__tests__/networkClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import testDataSets from './__dataSets__';
import { VonageTest } from '../../../testHelpers';

VonageTest(testDataSets);

2 changes: 2 additions & 0 deletions packages/network-client/lib/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './purpose';
export * from './scope';
9 changes: 9 additions & 0 deletions packages/network-client/lib/enums/purpose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Netowrk API purposes for generating the scope
*/
export enum Purpose {
/**
* Purpose for Fraud Prevention and Detection
*/
FRAUD_PREVENTION_AND_DETECTION = 'FraudPreventionAndDetection',
}
14 changes: 14 additions & 0 deletions packages/network-client/lib/enums/scope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Scopes for the API
*/
export enum Scope {
/**
* Check for SIM Swap
*/
CHECK_SIM_SWAP = 'check-sim-swap',

/**
* Number Verification
*/
NUMBER_VERIFICATION_VERIFY_READ = 'number-verification-verify-read',
}
4 changes: 4 additions & 0 deletions packages/network-client/lib/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './invalidScopeError';
export * from './missingScopeError';
export * from './missingPurposeError';
export * from './invalidPurposeError';
8 changes: 8 additions & 0 deletions packages/network-client/lib/errors/invalidPurposeError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Error thrown when purpose is invalid
*/
export class InvalidPurposeError extends Error {
constructor() {
super(`You did not set a purpose for this request. Please set a proper purpose for this request.`);
}
}
8 changes: 8 additions & 0 deletions packages/network-client/lib/errors/invalidScopeError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Error thrown when scope is invalid
*/
export class InvalidScopeError extends Error {
constructor() {
super(`You did not set a scope for this request. Please set a proper scope for this request.`);
}
}
8 changes: 8 additions & 0 deletions packages/network-client/lib/errors/missingPurposeError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Error thrown when purpose is invalid
*/
export class MissingPurposeError extends Error {
constructor() {
super(`You did not set a purpose for this request.`);
}
}
8 changes: 8 additions & 0 deletions packages/network-client/lib/errors/missingScopeError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Error thrown when no scope is set for a request.
*/
export class MissingScopeError extends Error {
constructor() {
super(`You did not set a scope for this request.`);
}
}
4 changes: 4 additions & 0 deletions packages/network-client/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './errors';
export * from './networkClient';
export * from './types';
export * from './enums';
Loading

0 comments on commit 4380e03

Please sign in to comment.