-
Notifications
You must be signed in to change notification settings - Fork 181
/
numberInsightV2.ts
71 lines (68 loc) · 2.18 KB
/
numberInsightV2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Client, AuthenticationType } from '@vonage/server-client';
import { FraudCheck, FraudCheckParameters, FraudScoreResponse } from './types';
/**
* Number Insight v2 is designed to give fraud scores for Application Integrations.
* This class represents the client for making fraud check requests.
*/
export class NumberInsightV2 extends Client {
protected authType = AuthenticationType.BASIC;
/**
* Make a fraud check request with the provided parameters.
*
* @param {FraudCheckParameters} params - The parameters for the fraud check request.
* @return {Promise<FraudScore>} - A Promise that resolves with the fraud score response.
* @example
* Check for fraud on a phone number.
* ```ts
* import { Insight } from '@vonage/number-insight-v2';
* const score = await client.numberInsightV2.checkForFraud({
* type: 'phone',
* number: '447700900000',
* insights: [
* Insight.FRAUD_SCORE,
* ],
* });
* console.log(`Fraud score: ${score.riskScore}`);
* ```
*
* @example
* Check for SIM swap on a phone number.
* ```ts
* import { Insight } from '@vonage/number-insight-v2';
* const score = await client.numberInsightV2.checkForFraud({
* type: 'phone',
* number: '447700900000',
* insights: [
* Insight.SIM_SWAP,
* ],
* });
* console.log(`SIM swap detected: ${score.simSwap ? 'Yes' : 'No'}`);
* ```
*
* @example
* Check both fraud score and SIM swap on a phone number.
* ```ts
* import { Insight } from '@vonage/number-insight-v2';
* const score = await client.numberInsightV2.checkForFraud({
* type: 'phone',
* number: '447700900000',
* insights: [
* Insight.SIM_SWAP,
* Insight.FRAUD_SCORE,
* ],
* });
* console.log(`SIM swap detected: ${score.simSwap ? 'Yes' : 'No'}`);
* console.log(`Fraud score: ${score.riskScore}`);
* ```
*/
async checkForFraud(params: FraudCheckParameters): Promise<FraudCheck> {
const resp = await this.sendPostRequest<FraudScoreResponse>(
`${this.config.apiHost}/v2/ni`,
params,
);
return Client.transformers.camelCaseObjectKeys(
resp?.data,
true,
) as FraudCheck;
}
}