Skip to content

Commit c47867f

Browse files
committed
Update LookupResponse and field validation to match current ipdata API
Add company object, carrier typing, threat intelligence fields (is_icloud_relay, is_datacenter, blocklists), and language code to the TypeScript interface. Add company to valid fields list while keeping organisation for backwards compatibility. Bump to 2.3.0. https://claude.ai/code/session_01UabaLo3R3sXovyxaZo2yCF
1 parent b820c02 commit c47867f

4 files changed

Lines changed: 50 additions & 4 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ipdata",
3-
"version": "2.2.4",
3+
"version": "2.3.0",
44
"description": "JavaScript library to gather information for an ip using https://ipdata.co.",
55
"main": "./lib/ipdata.js",
66
"scripts": {

src/ipdata.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,37 @@ describe('lookup()', () => {
136136
expect(info).toHaveProperty('status');
137137
});
138138
});
139+
140+
describe('company field', () => {
141+
it('should accept company as a valid select field', async () => {
142+
const info = await ipdata.lookup(TEST_IP, 'company');
143+
expect(info).toHaveProperty('company');
144+
expect(info).toHaveProperty('status');
145+
});
146+
147+
it('should accept company in fields array', async () => {
148+
const fields = ['ip', 'company'];
149+
const info = await ipdata.lookup(TEST_IP, undefined, fields);
150+
expect(info).toHaveProperty('ip', TEST_IP);
151+
expect(info).toHaveProperty('status');
152+
});
153+
});
154+
155+
describe('new API fields', () => {
156+
it('should return threat object with new fields', async () => {
157+
const info = await ipdata.lookup(TEST_IP);
158+
expect(info).toHaveProperty('threat');
159+
expect(info.threat).toHaveProperty('is_icloud_relay');
160+
expect(info.threat).toHaveProperty('is_datacenter');
161+
expect(info.threat).toHaveProperty('blocklists');
162+
});
163+
164+
it('should return languages with code field', async () => {
165+
const info = await ipdata.lookup(TEST_IP);
166+
expect(info.languages.length).toBeGreaterThan(0);
167+
expect(info.languages[0]).toHaveProperty('code');
168+
});
169+
});
139170
});
140171

141172
describe('bulkLookup()', () => {

src/ipdata.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const VALID_FIELDS = [
2121
'latitude',
2222
'longitude',
2323
'asn',
24+
'company',
2425
'organisation',
2526
'postal',
2627
'calling_code',
@@ -88,14 +89,25 @@ export interface LookupResponse {
8889
flag: string;
8990
emoji_flag: string;
9091
emoji_unicode: string;
92+
carrier?: {
93+
name: string;
94+
mcc: string;
95+
mnc: string;
96+
};
9197
asn: {
9298
asn: string;
9399
name: string;
94100
domain: string;
95101
route: string;
96102
type: string;
97103
};
98-
languages: { name: string; native: string }[];
104+
company?: {
105+
name: string;
106+
domain: string;
107+
network: string;
108+
type: string;
109+
};
110+
languages: { name: string; native: string; code?: string }[];
99111
currency: {
100112
name: string;
101113
code: string;
@@ -118,6 +130,9 @@ export interface LookupResponse {
118130
is_known_abuser: boolean;
119131
is_threat: boolean;
120132
is_bogon: boolean;
133+
is_icloud_relay?: boolean;
134+
is_datacenter?: boolean;
135+
blocklists?: { name: string; site: string; type: string }[];
121136
};
122137
count: number;
123138
status: number;

0 commit comments

Comments
 (0)