ip-finder-client 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -16
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -19
- package/dist/index.mjs +17 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ip-finder-client
|
|
2
2
|
|
|
3
|
-
A lightweight, zero-dependency Node.js
|
|
3
|
+
A lightweight, zero-dependency Node.js SDK for IP geolocation, ASN lookup, and network information.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -19,11 +19,10 @@ pnpm add ip-finder-client
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import {
|
|
22
|
+
import { IPInsight } from 'ip-finder-client';
|
|
23
23
|
|
|
24
|
-
const client = new
|
|
25
|
-
apiKey: 'your-api-key'
|
|
26
|
-
baseUrl: 'https://api.your-domain.com' // Your API endpoint
|
|
24
|
+
const client = new IPInsight({
|
|
25
|
+
apiKey: 'your-api-key'
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
// Look up an IP address
|
|
@@ -37,13 +36,10 @@ console.log(result.asn?.organization); // "Google LLC"
|
|
|
37
36
|
## Configuration
|
|
38
37
|
|
|
39
38
|
```typescript
|
|
40
|
-
const client = new
|
|
39
|
+
const client = new IPInsight({
|
|
41
40
|
// Required: Your API key
|
|
42
41
|
apiKey: 'your-api-key',
|
|
43
42
|
|
|
44
|
-
// Optional: API base URL (defaults to production)
|
|
45
|
-
baseUrl: 'https://api.your-domain.com',
|
|
46
|
-
|
|
47
43
|
// Optional: Request timeout in ms (default: 10000)
|
|
48
44
|
timeout: 5000,
|
|
49
45
|
|
|
@@ -101,7 +97,7 @@ Look up multiple IP addresses in parallel.
|
|
|
101
97
|
const results = await client.lookupBatch(['8.8.8.8', '1.1.1.1', '9.9.9.9']);
|
|
102
98
|
|
|
103
99
|
results.forEach(result => {
|
|
104
|
-
if (result instanceof
|
|
100
|
+
if (result instanceof IPInsightError) {
|
|
105
101
|
console.error(`Error: ${result.message}`);
|
|
106
102
|
} else {
|
|
107
103
|
console.log(`${result.ip}: ${result.geo?.country}`);
|
|
@@ -132,12 +128,12 @@ console.log(client.rateLimit);
|
|
|
132
128
|
## Error Handling
|
|
133
129
|
|
|
134
130
|
```typescript
|
|
135
|
-
import {
|
|
131
|
+
import { IPInsight, IPInsightError } from 'ip-finder-client';
|
|
136
132
|
|
|
137
133
|
try {
|
|
138
134
|
const result = await client.lookup('invalid-ip');
|
|
139
135
|
} catch (error) {
|
|
140
|
-
if (error instanceof
|
|
136
|
+
if (error instanceof IPInsightError) {
|
|
141
137
|
console.error(`API Error: ${error.message}`);
|
|
142
138
|
console.error(`Status Code: ${error.statusCode}`);
|
|
143
139
|
console.error(`Error Code: ${error.code}`);
|
|
@@ -166,9 +162,9 @@ try {
|
|
|
166
162
|
## CommonJS Usage
|
|
167
163
|
|
|
168
164
|
```javascript
|
|
169
|
-
const {
|
|
165
|
+
const { IPInsight } = require('ip-finder-client');
|
|
170
166
|
|
|
171
|
-
const client = new
|
|
167
|
+
const client = new IPInsight({ apiKey: 'your-api-key' });
|
|
172
168
|
```
|
|
173
169
|
|
|
174
170
|
## Factory Function
|
|
@@ -179,8 +175,7 @@ Alternatively, use the factory function:
|
|
|
179
175
|
import { createClient } from 'ip-finder-client';
|
|
180
176
|
|
|
181
177
|
const client = createClient({
|
|
182
|
-
apiKey: 'your-api-key'
|
|
183
|
-
baseUrl: 'https://api.your-domain.com'
|
|
178
|
+
apiKey: 'your-api-key'
|
|
184
179
|
});
|
|
185
180
|
```
|
|
186
181
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import type { IPFinderConfig, IPLookupResult, APIError, RateLimitInfo, GeoLocation, ASNInfo, NetworkInfo } from './types';
|
|
2
2
|
export type { IPFinderConfig, IPLookupResult, APIError, RateLimitInfo, GeoLocation, ASNInfo, NetworkInfo, };
|
|
3
3
|
/**
|
|
4
|
-
* Custom error class for
|
|
4
|
+
* Custom error class for IPInsight API errors
|
|
5
5
|
*/
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class IPInsightError extends Error {
|
|
7
7
|
readonly statusCode: number;
|
|
8
8
|
readonly code?: string;
|
|
9
9
|
constructor(message: string, statusCode: number, code?: string);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* IPInsight client for looking up IP address information
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* import {
|
|
16
|
+
* import { IPInsight } from 'ip-finder-client';
|
|
17
17
|
*
|
|
18
|
-
* const client = new
|
|
18
|
+
* const client = new IPInsight({ apiKey: 'your-api-key' });
|
|
19
19
|
* const result = await client.lookup('8.8.8.8');
|
|
20
20
|
* console.log(result.geo?.country); // "United States"
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
export declare class
|
|
23
|
+
export declare class IPInsight {
|
|
24
24
|
private readonly apiKey;
|
|
25
25
|
private readonly baseUrl;
|
|
26
26
|
private readonly timeout;
|
|
@@ -62,7 +62,7 @@ export declare class IPFinder {
|
|
|
62
62
|
* results.forEach(r => console.log(r.ip, r.geo?.country));
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
65
|
-
lookupBatch(ips: string[]): Promise<(IPLookupResult |
|
|
65
|
+
lookupBatch(ips: string[]): Promise<(IPLookupResult | IPInsightError)[]>;
|
|
66
66
|
/**
|
|
67
67
|
* Check if the API is healthy and reachable
|
|
68
68
|
*
|
|
@@ -74,10 +74,10 @@ export declare class IPFinder {
|
|
|
74
74
|
private sleep;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* Create a new
|
|
77
|
+
* Create a new IPInsight client instance
|
|
78
78
|
*
|
|
79
79
|
* @param config - Client configuration
|
|
80
|
-
* @returns New
|
|
80
|
+
* @returns New IPInsight instance
|
|
81
81
|
*
|
|
82
82
|
* @example
|
|
83
83
|
* ```ts
|
|
@@ -91,6 +91,6 @@ export declare class IPFinder {
|
|
|
91
91
|
* const result = await client.lookup('8.8.8.8');
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
|
-
export declare function createClient(config: IPFinderConfig):
|
|
95
|
-
export default
|
|
94
|
+
export declare function createClient(config: IPFinderConfig): IPInsight;
|
|
95
|
+
export default IPInsight;
|
|
96
96
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,EACZ,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,GACZ,CAAC;AAMF;;GAEG;AACH,qBAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,EACZ,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,GACZ,CAAC;AAMF;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAO/D;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,4CAA4C;IACrC,SAAS,CAAC,EAAE,aAAa,CAAC;gBAErB,MAAM,EAAE,cAAc;IAWlC;;;;;;;;;;;;;OAaG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA+BjD;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;IAO3C;;;;;;;;;;;OAWG;IACG,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,cAAc,GAAG,cAAc,CAAC,EAAE,CAAC;IAqB9E;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;YAgBvB,KAAK;IAuDnB,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,KAAK;CAGd;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAE9D;AAGD,eAAe,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,27 +20,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
IPInsight: () => IPInsight,
|
|
24
|
+
IPInsightError: () => IPInsightError,
|
|
25
25
|
createClient: () => createClient,
|
|
26
26
|
default: () => src_default
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
var DEFAULT_BASE_URL = "https://
|
|
29
|
+
var DEFAULT_BASE_URL = "https://api.ipwhere.site";
|
|
30
30
|
var DEFAULT_TIMEOUT = 1e4;
|
|
31
31
|
var DEFAULT_RETRIES = 2;
|
|
32
|
-
var
|
|
32
|
+
var IPInsightError = class _IPInsightError extends Error {
|
|
33
33
|
statusCode;
|
|
34
34
|
code;
|
|
35
35
|
constructor(message, statusCode, code) {
|
|
36
36
|
super(message);
|
|
37
|
-
this.name = "
|
|
37
|
+
this.name = "IPInsightError";
|
|
38
38
|
this.statusCode = statusCode;
|
|
39
39
|
this.code = code;
|
|
40
|
-
Object.setPrototypeOf(this,
|
|
40
|
+
Object.setPrototypeOf(this, _IPInsightError.prototype);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
var
|
|
43
|
+
var IPInsight = class {
|
|
44
44
|
apiKey;
|
|
45
45
|
baseUrl;
|
|
46
46
|
timeout;
|
|
@@ -82,7 +82,7 @@ var IPFinder = class {
|
|
|
82
82
|
return response;
|
|
83
83
|
} catch (err) {
|
|
84
84
|
lastError = err;
|
|
85
|
-
if (err instanceof
|
|
85
|
+
if (err instanceof IPInsightError && err.statusCode >= 400 && err.statusCode < 500) {
|
|
86
86
|
throw err;
|
|
87
87
|
}
|
|
88
88
|
if (attempt < this.retries) {
|
|
@@ -124,10 +124,10 @@ var IPFinder = class {
|
|
|
124
124
|
return result.value;
|
|
125
125
|
}
|
|
126
126
|
const err = result.reason;
|
|
127
|
-
if (err instanceof
|
|
127
|
+
if (err instanceof IPInsightError) {
|
|
128
128
|
return err;
|
|
129
129
|
}
|
|
130
|
-
return new
|
|
130
|
+
return new IPInsightError(
|
|
131
131
|
err?.message || "Unknown error",
|
|
132
132
|
0,
|
|
133
133
|
"BATCH_ERROR"
|
|
@@ -173,7 +173,7 @@ var IPFinder = class {
|
|
|
173
173
|
errorBody = await response.json();
|
|
174
174
|
} catch {
|
|
175
175
|
}
|
|
176
|
-
throw new
|
|
176
|
+
throw new IPInsightError(
|
|
177
177
|
errorBody?.error || `HTTP ${response.status}`,
|
|
178
178
|
response.status,
|
|
179
179
|
errorBody?.code
|
|
@@ -183,16 +183,16 @@ var IPFinder = class {
|
|
|
183
183
|
return data;
|
|
184
184
|
} catch (err) {
|
|
185
185
|
clearTimeout(timeoutId);
|
|
186
|
-
if (err instanceof
|
|
186
|
+
if (err instanceof IPInsightError) {
|
|
187
187
|
throw err;
|
|
188
188
|
}
|
|
189
189
|
if (err instanceof Error) {
|
|
190
190
|
if (err.name === "AbortError") {
|
|
191
|
-
throw new
|
|
191
|
+
throw new IPInsightError("Request timeout", 408, "TIMEOUT");
|
|
192
192
|
}
|
|
193
|
-
throw new
|
|
193
|
+
throw new IPInsightError(err.message, 0, "NETWORK_ERROR");
|
|
194
194
|
}
|
|
195
|
-
throw new
|
|
195
|
+
throw new IPInsightError("Unknown error", 0, "UNKNOWN");
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
parseRateLimitHeaders(headers) {
|
|
@@ -212,12 +212,12 @@ var IPFinder = class {
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
function createClient(config) {
|
|
215
|
-
return new
|
|
215
|
+
return new IPInsight(config);
|
|
216
216
|
}
|
|
217
|
-
var src_default =
|
|
217
|
+
var src_default = IPInsight;
|
|
218
218
|
// Annotate the CommonJS export names for ESM import in node:
|
|
219
219
|
0 && (module.exports = {
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
IPInsight,
|
|
221
|
+
IPInsightError,
|
|
222
222
|
createClient
|
|
223
223
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
var DEFAULT_BASE_URL = "https://
|
|
2
|
+
var DEFAULT_BASE_URL = "https://api.ipwhere.site";
|
|
3
3
|
var DEFAULT_TIMEOUT = 1e4;
|
|
4
4
|
var DEFAULT_RETRIES = 2;
|
|
5
|
-
var
|
|
5
|
+
var IPInsightError = class _IPInsightError extends Error {
|
|
6
6
|
statusCode;
|
|
7
7
|
code;
|
|
8
8
|
constructor(message, statusCode, code) {
|
|
9
9
|
super(message);
|
|
10
|
-
this.name = "
|
|
10
|
+
this.name = "IPInsightError";
|
|
11
11
|
this.statusCode = statusCode;
|
|
12
12
|
this.code = code;
|
|
13
|
-
Object.setPrototypeOf(this,
|
|
13
|
+
Object.setPrototypeOf(this, _IPInsightError.prototype);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
var
|
|
16
|
+
var IPInsight = class {
|
|
17
17
|
apiKey;
|
|
18
18
|
baseUrl;
|
|
19
19
|
timeout;
|
|
@@ -55,7 +55,7 @@ var IPFinder = class {
|
|
|
55
55
|
return response;
|
|
56
56
|
} catch (err) {
|
|
57
57
|
lastError = err;
|
|
58
|
-
if (err instanceof
|
|
58
|
+
if (err instanceof IPInsightError && err.statusCode >= 400 && err.statusCode < 500) {
|
|
59
59
|
throw err;
|
|
60
60
|
}
|
|
61
61
|
if (attempt < this.retries) {
|
|
@@ -97,10 +97,10 @@ var IPFinder = class {
|
|
|
97
97
|
return result.value;
|
|
98
98
|
}
|
|
99
99
|
const err = result.reason;
|
|
100
|
-
if (err instanceof
|
|
100
|
+
if (err instanceof IPInsightError) {
|
|
101
101
|
return err;
|
|
102
102
|
}
|
|
103
|
-
return new
|
|
103
|
+
return new IPInsightError(
|
|
104
104
|
err?.message || "Unknown error",
|
|
105
105
|
0,
|
|
106
106
|
"BATCH_ERROR"
|
|
@@ -146,7 +146,7 @@ var IPFinder = class {
|
|
|
146
146
|
errorBody = await response.json();
|
|
147
147
|
} catch {
|
|
148
148
|
}
|
|
149
|
-
throw new
|
|
149
|
+
throw new IPInsightError(
|
|
150
150
|
errorBody?.error || `HTTP ${response.status}`,
|
|
151
151
|
response.status,
|
|
152
152
|
errorBody?.code
|
|
@@ -156,16 +156,16 @@ var IPFinder = class {
|
|
|
156
156
|
return data;
|
|
157
157
|
} catch (err) {
|
|
158
158
|
clearTimeout(timeoutId);
|
|
159
|
-
if (err instanceof
|
|
159
|
+
if (err instanceof IPInsightError) {
|
|
160
160
|
throw err;
|
|
161
161
|
}
|
|
162
162
|
if (err instanceof Error) {
|
|
163
163
|
if (err.name === "AbortError") {
|
|
164
|
-
throw new
|
|
164
|
+
throw new IPInsightError("Request timeout", 408, "TIMEOUT");
|
|
165
165
|
}
|
|
166
|
-
throw new
|
|
166
|
+
throw new IPInsightError(err.message, 0, "NETWORK_ERROR");
|
|
167
167
|
}
|
|
168
|
-
throw new
|
|
168
|
+
throw new IPInsightError("Unknown error", 0, "UNKNOWN");
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
parseRateLimitHeaders(headers) {
|
|
@@ -185,12 +185,12 @@ var IPFinder = class {
|
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
187
|
function createClient(config) {
|
|
188
|
-
return new
|
|
188
|
+
return new IPInsight(config);
|
|
189
189
|
}
|
|
190
|
-
var src_default =
|
|
190
|
+
var src_default = IPInsight;
|
|
191
191
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
IPInsight,
|
|
193
|
+
IPInsightError,
|
|
194
194
|
createClient,
|
|
195
195
|
src_default as default
|
|
196
196
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ip-finder-client",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Lightweight
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Lightweight SDK for IP geolocation, ASN lookup, and network information",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|