node-ipdox 1.0.5 → 1.0.6
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/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -0
- package/dist/ipdox.d.ts +4 -3
- package/dist/ipdox.d.ts.map +1 -0
- package/dist/ipdox.js +141 -157
- package/dist/ipdox.js.map +1 -0
- package/dist/types/IPDOXConstructor.d.ts +1 -0
- package/dist/types/IPDOXConstructor.d.ts.map +1 -0
- package/dist/types/IPDOXConstructor.js +1 -0
- package/dist/types/IPDOXConstructor.js.map +1 -0
- package/dist/types/IPDOXRequest.d.ts +1 -0
- package/dist/types/IPDOXRequest.d.ts.map +1 -0
- package/dist/types/IPDOXRequest.js +1 -0
- package/dist/types/IPDOXRequest.js.map +1 -0
- package/dist/types/IPDOXResponse.d.ts +1 -0
- package/dist/types/IPDOXResponse.d.ts.map +1 -0
- package/dist/types/IPDOXResponse.js +1 -0
- package/dist/types/IPDOXResponse.js.map +1 -0
- package/dist/utils/apis.d.ts +1 -0
- package/dist/utils/apis.d.ts.map +1 -0
- package/dist/utils/apis.js +1 -0
- package/dist/utils/apis.js.map +1 -0
- package/package.json +13 -9
- package/dist/integration/ipdox.providers.int.test.d.ts +0 -1
- package/dist/integration/ipdox.providers.int.test.js +0 -50
- package/dist/ipdox.test.d.ts +0 -1
- package/dist/ipdox.test.js +0 -86
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _IPDox from "./ipdox";
|
|
1
|
+
import _IPDox from "./ipdox.js";
|
|
2
2
|
/**
|
|
3
3
|
* Main Class
|
|
4
4
|
*/
|
|
@@ -6,12 +6,13 @@ export declare const IPDox: typeof _IPDox;
|
|
|
6
6
|
/**
|
|
7
7
|
* Constructor type
|
|
8
8
|
*/
|
|
9
|
-
export { IPDOXConstructor } from "./types/IPDOXConstructor";
|
|
9
|
+
export type { IPDOXConstructor } from "./types/IPDOXConstructor.js";
|
|
10
10
|
/**
|
|
11
11
|
* Params type
|
|
12
12
|
*/
|
|
13
|
-
export { IPDOXRequest } from "./types/IPDOXRequest";
|
|
13
|
+
export type { IPDOXRequest } from "./types/IPDOXRequest.js";
|
|
14
14
|
/**
|
|
15
15
|
* Response type
|
|
16
16
|
*/
|
|
17
|
-
export { IPDOXResponse } from "./types/IPDOXResponse";
|
|
17
|
+
export type { IPDOXResponse } from "./types/IPDOXResponse.js";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,YAAY,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,KAAK,eAAS,CAAC;AAE5B;;GAEG;AACH,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;GAEG;AACH,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;GAEG;AACH,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.IPDox = void 0;
|
|
7
|
-
const
|
|
7
|
+
const ipdox_js_1 = __importDefault(require("./ipdox.js"));
|
|
8
8
|
/**
|
|
9
9
|
* Main Class
|
|
10
10
|
*/
|
|
11
|
-
exports.IPDox =
|
|
11
|
+
exports.IPDox = ipdox_js_1.default;
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgC;AAEhC;;GAEG;AACU,QAAA,KAAK,GAAG,kBAAM,CAAC"}
|
package/dist/ipdox.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IPDOXRequest } from "./types/IPDOXRequest";
|
|
2
|
-
import { IPDOXResponse } from "./types/IPDOXResponse";
|
|
3
|
-
import { IPDOXConstructor } from "./types/IPDOXConstructor";
|
|
1
|
+
import { IPDOXRequest } from "./types/IPDOXRequest.js";
|
|
2
|
+
import { IPDOXResponse } from "./types/IPDOXResponse.js";
|
|
3
|
+
import { IPDOXConstructor } from "./types/IPDOXConstructor.js";
|
|
4
4
|
declare class IPDox {
|
|
5
5
|
private cache;
|
|
6
6
|
private maxRetries;
|
|
@@ -28,3 +28,4 @@ declare class IPDox {
|
|
|
28
28
|
private fetchIPAPIDotCo;
|
|
29
29
|
}
|
|
30
30
|
export default IPDox;
|
|
31
|
+
//# sourceMappingURL=ipdox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipdox.d.ts","sourceRoot":"","sources":["../src/ipdox.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAI/D,cAAM,KAAK;IACV,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;;;OAMG;gBAEF,EACC,aAAoB,EACpB,WAAsB,EACtB,UAAe,EACf,GAAE,gBAIF;IASF;;;;;;OAMG;IACG,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAqDrE,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,aAAa;YAIP,sBAAsB;YA4BtB,oBAAoB;YA4BpB,eAAe;YA4Bf,eAAe;CAyB7B;AAED,eAAe,KAAK,CAAC"}
|
package/dist/ipdox.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
const axios_1 = __importDefault(require("axios"));
|
|
16
|
-
const
|
|
7
|
+
const apis_js_1 = require("./utils/apis.js");
|
|
17
8
|
const lru_cache_1 = require("lru-cache");
|
|
18
9
|
class IPDox {
|
|
10
|
+
cache;
|
|
11
|
+
maxRetries;
|
|
19
12
|
/**
|
|
20
13
|
* @description Creates an instance of IPDox.
|
|
21
14
|
* @param {IPDOXConstructor} params
|
|
@@ -41,169 +34,160 @@ class IPDox {
|
|
|
41
34
|
* @returns {Promise<IPDOXResponse | undefined>} - Promise of the response or undefined
|
|
42
35
|
* @memberof IPDox
|
|
43
36
|
*/
|
|
44
|
-
doxIP(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
async doxIP({ ip }) {
|
|
38
|
+
// Check that the ip is valid
|
|
39
|
+
if (!ip || ip === "") {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
// Check if the IP is already in the cache
|
|
43
|
+
if (this.cache.has(ip)) {
|
|
44
|
+
const cachedResponse = this.cache.get(ip);
|
|
45
|
+
if (cachedResponse) {
|
|
46
|
+
return cachedResponse;
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
}
|
|
49
|
+
// Select a random API
|
|
50
|
+
let randomAPI = this.selectRandomAPI();
|
|
51
|
+
let response = null;
|
|
52
|
+
let retries = 0;
|
|
53
|
+
// Fetch data from the API
|
|
54
|
+
while (!response && retries < this.maxRetries) {
|
|
55
|
+
try {
|
|
56
|
+
switch (randomAPI) {
|
|
57
|
+
case apis_js_1.GeoAPIs.IP_HYPHEN_API_DOT_COM:
|
|
58
|
+
response = await this.fetchIPHyphenAPIDotCom(ip);
|
|
59
|
+
break;
|
|
60
|
+
case apis_js_1.GeoAPIs.FREE_IP_API_DOT_COM:
|
|
61
|
+
response = await this.fetchFreeIPAPIDotCom(ip);
|
|
62
|
+
break;
|
|
63
|
+
case apis_js_1.GeoAPIs.IPWHO_DOT_IS:
|
|
64
|
+
response = await this.fetchIPWhoDotIs(ip);
|
|
65
|
+
break;
|
|
66
|
+
case apis_js_1.GeoAPIs.IPAPI_DOT_CO:
|
|
67
|
+
response = await this.fetchIPAPIDotCo(ip);
|
|
68
|
+
break;
|
|
55
69
|
}
|
|
56
70
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Fetch data from the API
|
|
62
|
-
while (!response && retries < this.maxRetries) {
|
|
63
|
-
try {
|
|
64
|
-
switch (randomAPI) {
|
|
65
|
-
case apis_1.GeoAPIs.IP_HYPHEN_API_DOT_COM:
|
|
66
|
-
response = yield this.fetchIPHyphenAPIDotCom(ip);
|
|
67
|
-
break;
|
|
68
|
-
case apis_1.GeoAPIs.FREE_IP_API_DOT_COM:
|
|
69
|
-
response = yield this.fetchFreeIPAPIDotCom(ip);
|
|
70
|
-
break;
|
|
71
|
-
case apis_1.GeoAPIs.IPWHO_DOT_IS:
|
|
72
|
-
response = yield this.fetchIPWhoDotIs(ip);
|
|
73
|
-
break;
|
|
74
|
-
case apis_1.GeoAPIs.IPAPI_DOT_CO:
|
|
75
|
-
response = yield this.fetchIPAPIDotCo(ip);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
// If the promise is rejected, select another random API and try again
|
|
81
|
-
randomAPI = this.selectRandomAPI();
|
|
82
|
-
retries++;
|
|
83
|
-
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
// If the promise is rejected, select another random API and try again
|
|
73
|
+
randomAPI = this.selectRandomAPI();
|
|
74
|
+
retries++;
|
|
84
75
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
}
|
|
77
|
+
// If max retries reached and no response, return undefined
|
|
78
|
+
if (retries === this.maxRetries && !response) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
// Return the response
|
|
82
|
+
return response ? response : undefined;
|
|
92
83
|
}
|
|
93
84
|
selectRandomAPI() {
|
|
94
85
|
// Get a random entry from the enum
|
|
95
|
-
const randomEntry = Object.entries(
|
|
86
|
+
const randomEntry = Object.entries(apis_js_1.GeoAPIs)[Math.floor(Math.random() * Object.entries(apis_js_1.GeoAPIs).length)];
|
|
96
87
|
// Return the random entry
|
|
97
88
|
return randomEntry[1];
|
|
98
89
|
}
|
|
99
90
|
cacheResponse(ip, response) {
|
|
100
91
|
this.cache.set(ip, response);
|
|
101
92
|
}
|
|
102
|
-
fetchIPHyphenAPIDotCom(ip) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
});
|
|
93
|
+
async fetchIPHyphenAPIDotCom(ip) {
|
|
94
|
+
const requestURL = apis_js_1.GeoAPIs.IP_HYPHEN_API_DOT_COM + ip + "?fields=24899583";
|
|
95
|
+
const response = await axios_1.default.get(requestURL);
|
|
96
|
+
if (response.data.status === "success") {
|
|
97
|
+
const formattedResponse = {
|
|
98
|
+
ip: response.data.query,
|
|
99
|
+
country: response.data.countryCode,
|
|
100
|
+
city: response.data.city,
|
|
101
|
+
continent: response.data.continentCode,
|
|
102
|
+
latitude: response.data.lat,
|
|
103
|
+
longitude: response.data.lon,
|
|
104
|
+
zip: response.data.zip,
|
|
105
|
+
isp: response.data.isp,
|
|
106
|
+
proxy: response.data.proxy,
|
|
107
|
+
isHosting: response.data.hosting,
|
|
108
|
+
timeZone: response.data.timezone,
|
|
109
|
+
source: "ip-api.com"
|
|
110
|
+
};
|
|
111
|
+
this.cacheResponse(ip, formattedResponse);
|
|
112
|
+
return Promise.resolve(formattedResponse);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return Promise.reject();
|
|
116
|
+
}
|
|
128
117
|
}
|
|
129
|
-
fetchFreeIPAPIDotCom(ip) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
});
|
|
118
|
+
async fetchFreeIPAPIDotCom(ip) {
|
|
119
|
+
const requestURL = apis_js_1.GeoAPIs.FREE_IP_API_DOT_COM + ip;
|
|
120
|
+
const response = await axios_1.default.get(requestURL);
|
|
121
|
+
if (response.data.ipVersion === 4) {
|
|
122
|
+
const formattedResponse = {
|
|
123
|
+
ip: response.data.ipAddress,
|
|
124
|
+
country: response.data.countryCode,
|
|
125
|
+
city: response.data.cityName,
|
|
126
|
+
continent: response.data.continentCode,
|
|
127
|
+
latitude: response.data.latitude,
|
|
128
|
+
longitude: response.data.longitude,
|
|
129
|
+
zip: response.data.zipCode,
|
|
130
|
+
isp: response.data.isp,
|
|
131
|
+
proxy: response.data.proxy,
|
|
132
|
+
isHosting: response.data.hosting,
|
|
133
|
+
timeZone: response.data.timeZones[0],
|
|
134
|
+
source: "freeipapi.com"
|
|
135
|
+
};
|
|
136
|
+
this.cacheResponse(ip, formattedResponse);
|
|
137
|
+
return Promise.resolve(formattedResponse);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return Promise.reject();
|
|
141
|
+
}
|
|
155
142
|
}
|
|
156
|
-
fetchIPWhoDotIs(ip) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
});
|
|
143
|
+
async fetchIPWhoDotIs(ip) {
|
|
144
|
+
const requestURL = apis_js_1.GeoAPIs.IPWHO_DOT_IS + ip;
|
|
145
|
+
const response = await axios_1.default.get(requestURL);
|
|
146
|
+
if (response.data.success) {
|
|
147
|
+
const formattedResponse = {
|
|
148
|
+
ip: response.data.ip,
|
|
149
|
+
country: response.data.country_code,
|
|
150
|
+
city: response.data.city,
|
|
151
|
+
continent: response.data.continent_code,
|
|
152
|
+
latitude: response.data.latitude,
|
|
153
|
+
longitude: response.data.longitude,
|
|
154
|
+
zip: response.data.postal,
|
|
155
|
+
isp: response.data.connection.isp,
|
|
156
|
+
proxy: false,
|
|
157
|
+
isHosting: false,
|
|
158
|
+
timeZone: response.data.timezone.id,
|
|
159
|
+
source: "ipwho.is"
|
|
160
|
+
};
|
|
161
|
+
this.cacheResponse(ip, formattedResponse);
|
|
162
|
+
return Promise.resolve(formattedResponse);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return Promise.reject();
|
|
166
|
+
}
|
|
182
167
|
}
|
|
183
|
-
fetchIPAPIDotCo(ip) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
});
|
|
168
|
+
async fetchIPAPIDotCo(ip) {
|
|
169
|
+
const requestURL = apis_js_1.GeoAPIs.IPAPI_DOT_CO + ip + "/json";
|
|
170
|
+
const response = await axios_1.default.get(requestURL);
|
|
171
|
+
if (response.data.ip) {
|
|
172
|
+
const formattedResponse = {
|
|
173
|
+
ip: response.data.ip,
|
|
174
|
+
country: response.data.country_code,
|
|
175
|
+
city: response.data.city,
|
|
176
|
+
continent: response.data.continent_code,
|
|
177
|
+
latitude: response.data.latitude,
|
|
178
|
+
longitude: response.data.longitude,
|
|
179
|
+
zip: response.data.postal,
|
|
180
|
+
isp: response.data.org,
|
|
181
|
+
timeZone: response.data.timezone,
|
|
182
|
+
source: "ipapi.co"
|
|
183
|
+
};
|
|
184
|
+
this.cacheResponse(ip, formattedResponse);
|
|
185
|
+
return Promise.resolve(formattedResponse);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
return Promise.reject();
|
|
189
|
+
}
|
|
207
190
|
}
|
|
208
191
|
}
|
|
209
192
|
exports.default = IPDox;
|
|
193
|
+
//# sourceMappingURL=ipdox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipdox.js","sourceRoot":"","sources":["../src/ipdox.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAI1B,6CAA0C;AAC1C,yCAAqC;AAErC,MAAM,KAAK;IACF,KAAK,CAAkC;IACvC,UAAU,CAAS;IAE3B;;;;;;OAMG;IACH,YACC,EACC,aAAa,GAAG,IAAI,EACpB,WAAW,GAAG,QAAQ,EACtB,UAAU,GAAG,EAAE,KACM;QACrB,aAAa,EAAE,IAAI;QACnB,WAAW,EAAE,QAAQ;QACrB,UAAU,EAAE,EAAE;KACd;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,oBAAQ,CAAwB;YAChD,GAAG,EAAE,aAAa;YAClB,GAAG,EAAE,WAAW;SAChB,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,EAAgB;QAC/B,6BAA6B;QAC7B,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACtB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,0CAA0C;QAC1C,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACxB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAE1C,IAAI,cAAc,EAAE,CAAC;gBACpB,OAAO,cAAc,CAAC;YACvB,CAAC;QACF,CAAC;QAED,sBAAsB;QACtB,IAAI,SAAS,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACvC,IAAI,QAAQ,GAAyB,IAAI,CAAC;QAC1C,IAAI,OAAO,GAAG,C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gBACxC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACpB,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;gBACnC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI;gBACxB,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,cAAc;gBACvC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;gBAChC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS;gBAClC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;gBACzB,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG;gBACtB,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;gBAChC,MAAM,EAAE,UAAU;aAClB,CAAC;YAEF,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,iBAAiB,CAAC,CAAC;YAE1C,OAAO,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACP,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;QACzB,CAAC;IACF,CAAC;CACD;AAED,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPDOXConstructor.d.ts","sourceRoot":"","sources":["../../src/types/IPDOXConstructor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPDOXConstructor.js","sourceRoot":"","sources":["../../src/types/IPDOXConstructor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPDOXRequest.d.ts","sourceRoot":"","sources":["../../src/types/IPDOXRequest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;CACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPDOXRequest.js","sourceRoot":"","sources":["../../src/types/IPDOXRequest.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPDOXResponse.d.ts","sourceRoot":"","sources":["../../src/types/IPDOXResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE;QACX,KAAK,EAAE,OAAO,CAAC;QACf,KAAK,EAAE,OAAO,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IPDOXResponse.js","sourceRoot":"","sources":["../../src/types/IPDOXResponse.ts"],"names":[],"mappings":""}
|
package/dist/utils/apis.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apis.d.ts","sourceRoot":"","sources":["../../src/utils/apis.ts"],"names":[],"mappings":"AAAA,oBAAY,OAAO;IAClB,qBAAqB,4BAA4B;IACjD,mBAAmB,oCAAoC;IACvD,YAAY,sBAAsB;IAClC,YAAY,sBAAsB;CAClC"}
|
package/dist/utils/apis.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apis.js","sourceRoot":"","sources":["../../src/utils/apis.ts"],"names":[],"mappings":";;;AAAA,IAAY,OAKX;AALD,WAAY,OAAO;IAClB,4DAAiD,CAAA;IACjD,kEAAuD,CAAA;IACvD,6CAAkC,CAAA;IAClC,6CAAkC,CAAA;AACnC,CAAC,EALW,OAAO,uBAAP,OAAO,QAKlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-ipdox",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "node-ipdox is a Node.js library for GeoIP lookup, leveraging various free GeoIP APIs. It provides a unified response format and incorporates local caching to minimize duplicate requests.",
|
|
5
5
|
"author": "Mikel Calvo <contact@mikecalvo.net> (www.mikelcalvo.net)",
|
|
6
6
|
"keywords": [
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"readmeFilename": "README.md",
|
|
17
|
-
"homepage": "https://github.com/
|
|
18
|
-
"bugs": { "url": "https://github.com/
|
|
17
|
+
"homepage": "https://github.com/MikelCalvo/ipdox#readme",
|
|
18
|
+
"bugs": { "url": "https://github.com/MikelCalvo/ipdox/issues" },
|
|
19
19
|
"main": "./dist/index.js",
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"files": ["dist"],
|
|
@@ -28,13 +28,17 @@
|
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
|
-
"url": "git+https://github.com/
|
|
31
|
+
"url": "git+https://github.com/MikelCalvo/node-ipdox.git"
|
|
32
32
|
},
|
|
33
|
-
"
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": true
|
|
36
|
+
},
|
|
37
|
+
"dependencies": { "axios": "1.13.2", "lru-cache": "^11.2.4" },
|
|
34
38
|
"devDependencies": {
|
|
35
|
-
"@types/node": "
|
|
36
|
-
"prettier": "3.
|
|
37
|
-
"typescript": "^5.9.
|
|
38
|
-
"vitest": "
|
|
39
|
+
"@types/node": "25.0.2",
|
|
40
|
+
"prettier": "3.7.4",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"vitest": "4.0.15"
|
|
39
43
|
}
|
|
40
44
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const vitest_1 = require("vitest");
|
|
13
|
-
const index_1 = require("../index");
|
|
14
|
-
const RUN = process.env.RUN_INTEGRATION === "1";
|
|
15
|
-
const TEST_IP = process.env.TEST_IP || "8.8.8.8";
|
|
16
|
-
// Run only when explicitly enabled
|
|
17
|
-
(RUN ? vitest_1.describe : vitest_1.describe.skip)("Integration: real providers", () => {
|
|
18
|
-
(0, vitest_1.it)("ipwho.is", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
const ipdox = new index_1.IPDox({ maxRetries: 1 });
|
|
20
|
-
// @ts-expect-error call provider directly to avoid randomness
|
|
21
|
-
const r = yield ipdox.fetchIPWhoDotIs(TEST_IP);
|
|
22
|
-
(0, vitest_1.expect)(r).toBeTruthy();
|
|
23
|
-
(0, vitest_1.expect)(r.source).toBe("ipwho.is");
|
|
24
|
-
(0, vitest_1.expect)(r.ip).toBeTypeOf("string");
|
|
25
|
-
}), 20000);
|
|
26
|
-
(0, vitest_1.it)("ip-api.com", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
const ipdox = new index_1.IPDox({ maxRetries: 1 });
|
|
28
|
-
// @ts-expect-error call provider directly to avoid randomness
|
|
29
|
-
const r = yield ipdox.fetchIPHyphenAPIDotCom(TEST_IP);
|
|
30
|
-
(0, vitest_1.expect)(r).toBeTruthy();
|
|
31
|
-
(0, vitest_1.expect)(r.source).toBe("ip-api.com");
|
|
32
|
-
(0, vitest_1.expect)(r.ip).toBeTypeOf("string");
|
|
33
|
-
}), 20000);
|
|
34
|
-
(0, vitest_1.it)("freeipapi.com", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
const ipdox = new index_1.IPDox({ maxRetries: 1 });
|
|
36
|
-
// @ts-expect-error call provider directly to avoid randomness
|
|
37
|
-
const r = yield ipdox.fetchFreeIPAPIDotCom(TEST_IP);
|
|
38
|
-
(0, vitest_1.expect)(r).toBeTruthy();
|
|
39
|
-
(0, vitest_1.expect)(r.source).toBe("freeipapi.com");
|
|
40
|
-
(0, vitest_1.expect)(r.ip).toBeTypeOf("string");
|
|
41
|
-
}), 20000);
|
|
42
|
-
(0, vitest_1.it)("ipapi.co", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const ipdox = new index_1.IPDox({ maxRetries: 1 });
|
|
44
|
-
// @ts-expect-error call provider directly to avoid randomness
|
|
45
|
-
const r = yield ipdox.fetchIPAPIDotCo(TEST_IP);
|
|
46
|
-
(0, vitest_1.expect)(r).toBeTruthy();
|
|
47
|
-
(0, vitest_1.expect)(r.source).toBe("ipapi.co");
|
|
48
|
-
(0, vitest_1.expect)(r.ip).toBeTypeOf("string");
|
|
49
|
-
}), 20000);
|
|
50
|
-
});
|
package/dist/ipdox.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/ipdox.test.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const vitest_1 = require("vitest");
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const index_1 = require("./index");
|
|
18
|
-
vitest_1.vi.mock("axios");
|
|
19
|
-
const mockedAxios = axios_1.default;
|
|
20
|
-
(0, vitest_1.describe)("IPDox", () => {
|
|
21
|
-
(0, vitest_1.beforeEach)(() => {
|
|
22
|
-
vitest_1.vi.clearAllMocks();
|
|
23
|
-
});
|
|
24
|
-
(0, vitest_1.it)("returns undefined for empty ip", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const ipdox = new index_1.IPDox();
|
|
26
|
-
const res = yield ipdox.doxIP({ ip: "" });
|
|
27
|
-
(0, vitest_1.expect)(res).toBeUndefined();
|
|
28
|
-
}));
|
|
29
|
-
(0, vitest_1.it)("formats response from ipwho.is provider", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const ipdox = new index_1.IPDox({ maxRetries: 1 });
|
|
31
|
-
mockedAxios.get = vitest_1.vi.fn().mockResolvedValue({
|
|
32
|
-
data: {
|
|
33
|
-
success: true,
|
|
34
|
-
ip: "8.8.8.8",
|
|
35
|
-
country_code: "US",
|
|
36
|
-
city: "Mountain View",
|
|
37
|
-
continent_code: "NA",
|
|
38
|
-
latitude: 37.386,
|
|
39
|
-
longitude: -122.0838,
|
|
40
|
-
postal: "94039",
|
|
41
|
-
connection: { isp: "Google LLC" },
|
|
42
|
-
timezone: { id: "America/Los_Angeles" }
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
// Call provider directly to avoid randomness
|
|
46
|
-
// @ts-expect-error Accessing class method for test
|
|
47
|
-
const r = yield ipdox.fetchIPWhoDotIs("8.8.8.8");
|
|
48
|
-
(0, vitest_1.expect)(r).toMatchObject({
|
|
49
|
-
ip: "8.8.8.8",
|
|
50
|
-
country: "US",
|
|
51
|
-
city: "Mountain View",
|
|
52
|
-
continent: "NA",
|
|
53
|
-
latitude: 37.386,
|
|
54
|
-
longitude: -122.0838,
|
|
55
|
-
zip: "94039",
|
|
56
|
-
isp: "Google LLC",
|
|
57
|
-
timeZone: "America/Los_Angeles",
|
|
58
|
-
source: "ipwho.is"
|
|
59
|
-
});
|
|
60
|
-
}));
|
|
61
|
-
(0, vitest_1.it)("caches responses by ip", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
const ipdox = new index_1.IPDox({ maxRetries: 1 });
|
|
63
|
-
mockedAxios.get = vitest_1.vi.fn().mockResolvedValue({
|
|
64
|
-
data: {
|
|
65
|
-
success: true,
|
|
66
|
-
ip: "1.1.1.1",
|
|
67
|
-
country_code: "AU",
|
|
68
|
-
city: "Sydney",
|
|
69
|
-
continent_code: "OC",
|
|
70
|
-
latitude: -33.86,
|
|
71
|
-
longitude: 151.21,
|
|
72
|
-
postal: "2000",
|
|
73
|
-
connection: { isp: "Cloudflare" },
|
|
74
|
-
timezone: { id: "Australia/Sydney" }
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
// @ts-expect-error Accessing class method for test
|
|
78
|
-
const r1 = yield ipdox.fetchIPWhoDotIs("1.1.1.1");
|
|
79
|
-
(0, vitest_1.expect)(r1).toBeTruthy();
|
|
80
|
-
// Second call should be served from cache; axios.get should not be called again if provider is called through cache path
|
|
81
|
-
// @ts-expect-error Use cache via public doxIP path
|
|
82
|
-
ipdox.cache.set("1.1.1.1", r1);
|
|
83
|
-
const r2 = yield ipdox.doxIP({ ip: "1.1.1.1" });
|
|
84
|
-
(0, vitest_1.expect)(r2).toEqual(r1);
|
|
85
|
-
}));
|
|
86
|
-
});
|