Skip to content

Commit 00add3f

Browse files
authored
Merge pull request #514 from maxmind/ip-response
Make IP address response optional
2 parents 958ca5f + 2c9f8c2 commit 00add3f

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/response/models/insights.spec.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Insights()', () => {
1010

1111
const model = new Insights(input);
1212

13-
expect(model.ipAddress.country).toBeUndefined();
13+
expect(model.ipAddress?.country).toBeUndefined();
1414
});
1515

1616
it('handles empty location responses', () => {
@@ -20,7 +20,17 @@ describe('Insights()', () => {
2020

2121
const model = new Insights(input);
2222

23-
expect(model.ipAddress.location).toBeUndefined();
23+
expect(model.ipAddress?.location).toBeUndefined();
24+
});
25+
26+
it('handles empty IP address responses', () => {
27+
let input = cloneDeep(insights) as any;
28+
input = input.response.full;
29+
delete input.ip_address;
30+
31+
const model = new Insights(input);
32+
33+
expect(model.ipAddress).toBeUndefined();
2434
});
2535

2636
it('allows /email/domain/first_seen to be accessed', () => {

src/response/models/insights.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class Insights extends Score {
2828
/**
2929
* An object containing GeoIP2 and minFraud Insights information about the IP address.
3030
*/
31-
public readonly ipAddress: records.IpAddress;
31+
public readonly ipAddress?: records.IpAddress;
3232
/**
3333
* An object containing minFraud data related to the shipping address used in the transaction.
3434
*/
@@ -65,7 +65,11 @@ export default class Insights extends Score {
6565

6666
private getIpAddress(
6767
response: webRecords.InsightsResponse
68-
): records.IpAddress {
68+
): records.IpAddress | undefined {
69+
if (!response.ip_address) {
70+
return undefined;
71+
}
72+
6973
const insights = new GeoInsights(response.ip_address) as records.IpAddress;
7074

7175
if (insights.country && response.ip_address.country) {

src/response/models/score.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class Score {
2020
/**
2121
* An object containing information about the IP address's risk.
2222
*/
23-
public readonly ipAddress: records.ScoreIpAddress;
23+
public readonly ipAddress?: records.ScoreIpAddress;
2424
/**
2525
* The approximate number of queries remaining for this service before your
2626
* account runs out of funds.

src/response/web-records.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export interface ScoreResponse {
146146
readonly disposition?: DispositionWebRecord;
147147
readonly funds_remaining: number;
148148
readonly id: string;
149-
readonly ip_address: ScoreIpAddress;
149+
readonly ip_address?: ScoreIpAddress;
150150
readonly queries_remaining: number;
151151
readonly risk_score: number;
152152
readonly warnings?: Warning[];

0 commit comments

Comments
 (0)