-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(number-insight-v2): added support for number insight v2
- Loading branch information
Showing
27 changed files
with
320 additions
and
0 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 @@ | ||
# `number-insight-v2` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const numberInsightV2 = require('number-insight-v2'); | ||
// 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,8 @@ | ||
import postTests from './post'; | ||
|
||
export default [ | ||
{ | ||
label: 'Check For Fraud', | ||
tests: postTests, | ||
}, | ||
]; |
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,69 @@ | ||
import { | ||
Status, | ||
FraudCheckResponse, | ||
FraudCheckParameters, | ||
Insight, | ||
FraudCheck, | ||
Label, | ||
RiskRecommendation, | ||
FraudScoreResponse, | ||
} from '../../lib'; | ||
|
||
const params = { | ||
type: 'phone', | ||
phone: '16127779311', | ||
insights: [Insight.SIM_SWAP, Insight.FRAUD_SCORE], | ||
} as FraudCheckParameters; | ||
|
||
const fraudCheck = { | ||
requestId: '00000000-0000-0000-0000-000000000000', | ||
type: 'phone', | ||
phone: { | ||
phone: '16127779311', | ||
carrier: 'Google (Grand Central) - SVR', | ||
type: 'VOIP', | ||
}, | ||
fraudScore: { | ||
riskScore: '20', | ||
riskRecommendation: RiskRecommendation.ALLOW, | ||
label: Label.LOW, | ||
status: Status.COMPLETED, | ||
}, | ||
simSwap: { | ||
status: Status.COMPLETED, | ||
swapped: false, | ||
}, | ||
} as FraudCheck; | ||
|
||
const response = { | ||
request_id: '00000000-0000-0000-0000-000000000000', | ||
type: 'phone', | ||
phone: { | ||
phone: '16127779311', | ||
carrier: 'Google (Grand Central) - SVR', | ||
type: 'VOIP', | ||
}, | ||
fraud_score: { | ||
risk_score: '20', | ||
risk_recommendation: 'allow', | ||
label: 'low', | ||
status: 'completed', | ||
} as FraudScoreResponse, | ||
sim_swap: { | ||
status: 'completed', | ||
swapped: false, | ||
}, | ||
} as FraudCheckResponse; | ||
|
||
export default [ | ||
{ | ||
label: 'check for fraud', | ||
requests: [[`/v2/ni`, 'POST', params]], | ||
responses: [[200, response]], | ||
clientMethod: 'checkForFraud', | ||
parameters: [params], | ||
generator: false, | ||
error: false, | ||
expected: fraudCheck, | ||
}, | ||
]; |
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 @@ | ||
export const BASE_URL = 'https://api.nexmo.com/'; |
48 changes: 48 additions & 0 deletions
48
packages/number-insight-v2/__tests__/numberInsightV2.test.ts
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,48 @@ | ||
import { NumberInsightV2 } from '../lib/index'; | ||
import nock from 'nock'; | ||
import { Auth } from '@vonage/auth'; | ||
import { BASE_URL } from './common'; | ||
import testDataSets from './__dataSets__/index'; | ||
import { readFileSync } from 'fs'; | ||
|
||
const key = readFileSync(`${__dirname}/private.test.key`).toString(); | ||
|
||
describe.each(testDataSets)('$label', ({ tests }) => { | ||
let client; | ||
let scope; | ||
|
||
beforeEach(function () { | ||
client = new NumberInsightV2( | ||
new Auth({ | ||
privateKey: key, | ||
applicationId: 'my-application', | ||
}), | ||
); | ||
|
||
scope = nock(BASE_URL, { | ||
reqheaders: { | ||
authorization: (value) => value.startsWith('Bearer '), | ||
}, | ||
}).persist(); | ||
}); | ||
|
||
afterEach(function () { | ||
client = null; | ||
scope = null; | ||
nock.cleanAll(); | ||
}); | ||
|
||
test.each(tests)( | ||
'Can $label using: $clientMethod', | ||
async ({ requests, responses, clientMethod, parameters, expected }) => { | ||
requests.forEach((request, index) => { | ||
scope.intercept(...request).reply(...responses[index]); | ||
}); | ||
|
||
const result = await client[clientMethod](...parameters); | ||
|
||
expect(result).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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDTH8cEhJKsu2hB | ||
ucgs0Blf3tvgdXuIa5sMRI3zIZGok8jqaj6DC0WdM1eiJlQCWnVL0vR25MkopMZN | ||
MTphoaVpdK9wywMVx7PsgMCDXJjW77QFJFbbcbV9KG2xvMsjJGttmVrn+9aPpCnX | ||
yT27bWkTR0k/wCAvra/st5MDKg2kB3SMc+97zlO3GqIkJJKfKYQFAO8oRBcsZ1Bx | ||
ydPWTQvyLYW15Cjv30aIGLfceFwDeUOBgBsesGFtcXvVF6sVxd5D/USunX/9es95 | ||
Rdr4+9Qq4tIKZRkBz2KWD0eo256wmmq2lQoGaR9x6XgLHhUlsi6OXILcyChi2Qcc | ||
a01Hn7YvAgMBAAECggEAJsS+lIdNsddmIS+e4Q/DoRW49aJNM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PXECgYEA4MCEm9EyrguEO51am8va | ||
OjIAiQMkj/iyjsMDL8eH0VM+OMdieHwbkKyajyrB9dFikvWfxiuo3dU1N5vJTzty | ||
LmzkB8M/rKlAYKD8iKA8cRun4tKzRepHT3JPMu0GYTfcP9ovs5F3aEjX+UuWOO7n | ||
doWDENAr/VU1RNCDwFdxYFg= | ||
-----END PRIVATE KEY----- |
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 './insight'; | ||
export * from './label'; | ||
export * from './riskRecommendation'; | ||
export * from './status'; |
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 enum Insight { | ||
FRAUD_SCORE = 'fraud_score', | ||
SIM_SWAP = 'sim_swap', | ||
} |
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,5 @@ | ||
export enum Label { | ||
LOW = 'low', | ||
MEDIUM = 'medium', | ||
HIGH = 'high', | ||
} |
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,5 @@ | ||
export enum RiskRecommendation { | ||
ALLOW = 'allow', | ||
FLAG = 'flag', | ||
BLOCK = 'block', | ||
} |
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 enum Status { | ||
COMPLETED = 'completed', | ||
FAILED = 'failed', | ||
} |
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,3 @@ | ||
export * from './enums'; | ||
export * from './numberInsightV2'; | ||
export * from './types'; |
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,15 @@ | ||
import { Client, AuthenticationType } from '@vonage/server-client'; | ||
import { FraudCheckParameters, FraudScore, FraudScoreResponse } from './types'; | ||
|
||
export class NumberInsightV2 extends Client { | ||
protected authType = AuthenticationType.JWT; | ||
|
||
async checkForFraud(params: FraudCheckParameters): Promise<FraudScore> { | ||
const resp = await this.sendPostRequest<FraudScoreResponse>( | ||
`${this.config.apiHost}/v2/ni`, | ||
params, | ||
); | ||
|
||
return Client.transformers.camelCaseObjectKeys(resp?.data, true); | ||
} | ||
} |
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 @@ | ||
import { PhoneInfo } from './phoneInfo'; | ||
import { FraudScore } from './fraudScore'; | ||
import { SimSwap } from './simSwap'; | ||
|
||
export type FraudCheck = { | ||
requestId: string; | ||
type: 'phone'; | ||
phone: PhoneInfo; | ||
fraudScore?: FraudScore; | ||
simSwap?: SimSwap; | ||
}; |
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 @@ | ||
import { RiskRecommendation, Label, Status } from '../enums'; | ||
|
||
export type FraudScore = { | ||
riskScore: string; | ||
riskRecommendation: RiskRecommendation; | ||
label: Label; | ||
status: Status; | ||
}; |
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,7 @@ | ||
export * from './fraudCheck'; | ||
export * from './fraudScore'; | ||
export * from './parameters'; | ||
export * from './phoneInfo'; | ||
export * from './requests'; | ||
export * from './responses'; | ||
export * from './simSwap'; |
7 changes: 7 additions & 0 deletions
7
packages/number-insight-v2/lib/types/parameters/fraudParameters.ts
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,7 @@ | ||
import { Insight } from '../../enums/'; | ||
|
||
export type FraudCheckParameters = { | ||
type: 'phone'; | ||
phone: string; | ||
insights: Insight[]; | ||
}; |
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 @@ | ||
export * from './fraudParameters'; |
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,5 @@ | ||
export type PhoneInfo = { | ||
phone: string; | ||
carrier?: string; | ||
type?: string; | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/number-insight-v2/lib/types/requests/fraudCheckRequest.ts
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,7 @@ | ||
import { Insight } from '../../enums'; | ||
|
||
export type FraudCheckRequest = { | ||
type: 'phone'; | ||
phone: string; | ||
insights: Insight[]; | ||
}; |
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 @@ | ||
export * from './fraudCheckRequest'; |
9 changes: 9 additions & 0 deletions
9
packages/number-insight-v2/lib/types/responses/fraudCheckResponse.ts
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 { FraudCheck } from '../fraudCheck'; | ||
import { FraudScoreResponse } from './fraudScoreResponse'; | ||
import { SimSwap } from '../simSwap'; | ||
|
||
export type FraudCheckResponse = { | ||
request_id: string; | ||
fraud_score: FraudScoreResponse; | ||
sim_swap: SimSwap; | ||
} & Omit<FraudCheck, 'requestId' | 'fraudScore' | 'simSwap'>; |
7 changes: 7 additions & 0 deletions
7
packages/number-insight-v2/lib/types/responses/fraudScoreResponse.ts
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,7 @@ | ||
import { RiskRecommendation } from '../../enums'; | ||
import { FraudScore } from '../fraudScore'; | ||
|
||
export type FraudScoreResponse = { | ||
risk_score: string; | ||
risk_recommendation: RiskRecommendation; | ||
} & Omit<FraudScore, 'riskRecommendation' | 'riskScore'>; |
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 './fraudCheckResponse'; | ||
export * from './fraudScoreResponse'; |
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,7 @@ | ||
import { Status } from '../enums/'; | ||
|
||
export type SimSwap = { | ||
status: Status; | ||
swapped?: boolean; | ||
reason?: string; | ||
}; |
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,36 @@ | ||
{ | ||
"name": "@vonage/number-insight-v2", | ||
"version": "1.0.0", | ||
"description": "Number Insight v2 is designed to give fraud scores for Application Integrations.", | ||
"homepage": "https://github.com/vonage/vonage-node-sdk/tree/main/packages/number-insight-v2#readme", | ||
"bugs": { | ||
"url": "https://github.com/Vonage/vonage-node-sdk/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Vonage/vonage-node-sdk.git" | ||
}, | ||
"license": "Apache-2.0", | ||
"author": "Chuck MANCHUCK Reeves <[email protected]>", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"build": "npm run clean && npm run compile", | ||
"clean": "npx shx rm -rf dist tsconfig.tsbuildinfo", | ||
"compile": "npx tsc --build --verbose" | ||
}, | ||
"dependencies": { | ||
"@vonage/server-client": "1.8.2" | ||
}, | ||
"devDependencies": { | ||
"@vonage/auth": "1.6.0", | ||
"nock": "13.3.3" | ||
} | ||
} |