-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
1,133 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NetworkClient } from '../../lib'; | ||
import { SDKTestCase, testPrivateKey } from '../../../../testHelpers'; | ||
|
||
export default [ | ||
{ | ||
label: 'retrieve all conversations', | ||
baseUrl: 'https://api.nexmo.com', | ||
clientMethod: 'addAuthenticationToRequest', | ||
reqHeaders: { | ||
authorization: (value) => value.startsWith('Bearer '), | ||
}, | ||
client: new NetworkClient( | ||
{ | ||
privateKey: testPrivateKey, | ||
applicationId: 'my-application', | ||
msisdn: '447700900000', | ||
}, | ||
), | ||
requests: [ | ||
[`/v1/conversations`, 'GET'], | ||
], | ||
responses: [ | ||
[ | ||
200, | ||
], | ||
], | ||
generator: false, | ||
error: false, | ||
expected: [], | ||
} | ||
] as SDKTestCase<NetworkClient>[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NetworkClient } from '../lib'; | ||
import { VetchOptions, VetchResponse } from '@vonage/vetch'; | ||
|
||
export const BASE_URL = 'https://api.nexmo.com/'; | ||
|
||
export class TestNetworkClient extends NetworkClient { | ||
async testRequest<T = void>(request: VetchOptions): Promise<VetchResponse<T>> { | ||
return await this.sendRequest<T>(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { NetworkAuthParameters, NetworkClient } from '../lib'; | ||
import nock from 'nock'; | ||
import { BASE_URL } from './common'; | ||
import testDataSets from './__dataSets__'; | ||
import { SDKTestCase, TestTuple, getResults } from '../../../testHelpers'; | ||
|
||
describe.each<TestTuple>(testDataSets)('$label', ({tests}) => { | ||
let client; | ||
let scope; | ||
|
||
beforeEach(function () { | ||
scope = nock(BASE_URL, { | ||
reqheaders: { | ||
authorization: (value) => value.startsWith('Bearer '), | ||
}, | ||
}).persist(); | ||
}); | ||
|
||
afterEach(function () { | ||
client = null; | ||
scope = null; | ||
nock.cleanAll(); | ||
}); | ||
|
||
test.each<SDKTestCase>(tests)( | ||
'Can $label using: $clientMethod', | ||
async ({ | ||
generator, | ||
requests, | ||
responses, | ||
client, | ||
clientMethod, | ||
parameters, | ||
expected, | ||
}) => { | ||
|
||
requests.forEach((request, index) => { | ||
scope.intercept(...request).reply(...responses[index]); | ||
}); | ||
|
||
const results = await getResults( | ||
generator, | ||
client, | ||
clientMethod, | ||
parameters, | ||
); | ||
|
||
expect(results).toEqual(expected); | ||
expect(nock.isDone()).toBeTruthy(); | ||
|
||
expect(results).toEqual(expected); | ||
expect(nock.isDone()).toBeTruthy(); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './purpose'; | ||
export * from './scope'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.