node-ipinfo
Advanced tools
Comparing version 3.3.0 to 3.4.0
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -36,3 +40,3 @@ if (k2 === undefined) k2 = k; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -39,0 +43,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -54,3 +54,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
var version_1 = __importDefault(require("./version")); | ||
var clientUserAgent = "IPinfoClient/nodejs/" + version_1.default; | ||
var clientUserAgent = "IPinfoClient/nodejs/".concat(version_1.default); | ||
var IPinfoWrapper = (function () { | ||
@@ -72,149 +72,162 @@ function IPinfoWrapper(token, cache, timeout) { | ||
IPinfoWrapper.cacheKey = function (k) { | ||
return k + ":" + common_1.CACHE_VSN; | ||
return "".concat(k, ":").concat(common_1.CACHE_VSN); | ||
}; | ||
IPinfoWrapper.prototype.lookupIp = function (ip) { | ||
var _this = this; | ||
if (this.isBogon(ip)) { | ||
var ipinfo_1 = {}; | ||
ipinfo_1.bogon = true; | ||
ipinfo_1.ip = ip; | ||
return new Promise(function (resolve) { | ||
resolve(ipinfo_1); | ||
}); | ||
} | ||
var data = this.cache.get(IPinfoWrapper.cacheKey(ip)); | ||
if (data) { | ||
return new Promise(function (resolve) { | ||
resolve(data); | ||
}); | ||
} | ||
var config = { | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: "Bearer " + this.token, | ||
"Content-Type": "application/json", | ||
"User-Agent": clientUserAgent | ||
}, | ||
method: "GET", | ||
host: common_1.HOST, | ||
path: "/" + ip, | ||
timeout: this.timeout | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
var req = https_1.default.request(config, function (res) { | ||
var data = ""; | ||
res.on("data", function (chunk) { | ||
data += chunk; | ||
}); | ||
if (!_this.is4xxOr5xx(res.statusCode)) { | ||
res.on("close", function () { | ||
var ipinfo = JSON.parse(data); | ||
if (ipinfo.country) { | ||
ipinfo.countryCode = ipinfo.country; | ||
ipinfo.country = | ||
_this.countries[ipinfo.countryCode]; | ||
ipinfo.countryFlag = | ||
_this.countriesFlags[ipinfo.countryCode]; | ||
ipinfo.countryCurrency = | ||
_this.countriesCurrencies[ipinfo.countryCode]; | ||
ipinfo.continent = | ||
_this.continets[ipinfo.countryCode]; | ||
ipinfo.isEU = _this.euCountries.includes(ipinfo.countryCode); | ||
} | ||
if (ipinfo.abuse && ipinfo.abuse.country) { | ||
ipinfo.abuse.countryCode = | ||
ipinfo.abuse.country; | ||
ipinfo.abuse.country = | ||
_this.countries[ipinfo.abuse.countryCode]; | ||
} | ||
_this.cache.set(IPinfoWrapper.cacheKey(ip), ipinfo); | ||
resolve(ipinfo); | ||
}); | ||
res.on("error", function (error) { | ||
reject(error); | ||
}); | ||
} | ||
else { | ||
if (res.statusCode === 429) { | ||
reject(new apiLimitError_1.default()); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var ipinfo, data, config; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (this.isBogon(ip)) { | ||
ipinfo = {}; | ||
ipinfo.bogon = true; | ||
ipinfo.ip = ip; | ||
return [2, ipinfo]; | ||
} | ||
else { | ||
res.on("close", function () { | ||
reject(new Error(data)); | ||
}); | ||
return [4, this.cache.get(IPinfoWrapper.cacheKey(ip))]; | ||
case 1: | ||
data = _a.sent(); | ||
if (data) { | ||
return [2, data]; | ||
} | ||
} | ||
}); | ||
req.on("error", function (error) { | ||
reject(error); | ||
}); | ||
req.end(); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
config = { | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: "Bearer ".concat(this.token), | ||
"Content-Type": "application/json", | ||
"User-Agent": clientUserAgent | ||
}, | ||
method: "GET", | ||
host: common_1.HOST, | ||
path: "/".concat(ip), | ||
timeout: this.timeout | ||
}; | ||
return [2, new Promise(function (resolve, reject) { | ||
try { | ||
var req = https_1.default.request(config, function (res) { | ||
var data = ""; | ||
res.on("data", function (chunk) { | ||
data += chunk; | ||
}); | ||
if (!_this.is4xxOr5xx(res.statusCode)) { | ||
res.on("close", function () { | ||
var ipinfo = JSON.parse(data); | ||
if (ipinfo.country) { | ||
ipinfo.countryCode = ipinfo.country; | ||
ipinfo.country = | ||
_this.countries[ipinfo.countryCode]; | ||
ipinfo.countryFlag = | ||
_this.countriesFlags[ipinfo.countryCode]; | ||
ipinfo.countryCurrency = | ||
_this.countriesCurrencies[ipinfo.countryCode]; | ||
ipinfo.continent = | ||
_this.continets[ipinfo.countryCode]; | ||
ipinfo.isEU = _this.euCountries.includes(ipinfo.countryCode); | ||
} | ||
if (ipinfo.abuse && ipinfo.abuse.country) { | ||
ipinfo.abuse.countryCode = | ||
ipinfo.abuse.country; | ||
ipinfo.abuse.country = | ||
_this.countries[ipinfo.abuse.countryCode]; | ||
} | ||
_this.cache.set(IPinfoWrapper.cacheKey(ip), ipinfo); | ||
resolve(ipinfo); | ||
}); | ||
res.on("error", function (error) { | ||
reject(error); | ||
}); | ||
} | ||
else { | ||
if (res.statusCode === 429) { | ||
reject(new apiLimitError_1.default()); | ||
} | ||
else { | ||
res.on("close", function () { | ||
reject(new Error(data)); | ||
}); | ||
} | ||
} | ||
}); | ||
req.on("error", function (error) { | ||
reject(error); | ||
}); | ||
req.end(); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
IPinfoWrapper.prototype.lookupASN = function (asn) { | ||
var _this = this; | ||
var data = this.cache.get(IPinfoWrapper.cacheKey(asn)); | ||
if (data) { | ||
return new Promise(function (resolve) { | ||
resolve(data); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var data, config; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, this.cache.get(IPinfoWrapper.cacheKey(asn))]; | ||
case 1: | ||
data = _a.sent(); | ||
if (data) { | ||
return [2, data]; | ||
} | ||
config = { | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: "Bearer ".concat(this.token), | ||
"Content-Type": "application/json", | ||
"User-Agent": clientUserAgent | ||
}, | ||
method: "GET", | ||
host: common_1.HOST, | ||
path: "/".concat(asn, "/json"), | ||
timeout: this.timeout | ||
}; | ||
return [2, new Promise(function (resolve, reject) { | ||
try { | ||
var req = https_1.default.request(config, function (res) { | ||
var data = ""; | ||
res.on("data", function (chunk) { | ||
data += chunk; | ||
}); | ||
if (!_this.is4xxOr5xx(res.statusCode)) { | ||
res.on("close", function () { | ||
var asnResp = JSON.parse(data); | ||
if (asnResp.country) { | ||
asnResp.countryCode = asnResp.country; | ||
asnResp.country = | ||
_this.countries[asnResp.countryCode]; | ||
} | ||
_this.cache.set(IPinfoWrapper.cacheKey(asn), asnResp); | ||
resolve(asnResp); | ||
}); | ||
res.on("error", function (error) { | ||
reject(error); | ||
}); | ||
} | ||
else { | ||
if (res.statusCode === 429) { | ||
reject(new apiLimitError_1.default()); | ||
} | ||
else { | ||
res.on("close", function () { | ||
reject(new Error(data)); | ||
}); | ||
} | ||
} | ||
}); | ||
req.on("error", function (error) { | ||
reject(error); | ||
}); | ||
req.end(); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
})]; | ||
} | ||
}); | ||
} | ||
var config = { | ||
headers: { | ||
Accept: "application/json", | ||
Authorization: "Bearer " + this.token, | ||
"Content-Type": "application/json", | ||
"User-Agent": clientUserAgent | ||
}, | ||
method: "GET", | ||
host: common_1.HOST, | ||
path: "/" + asn + "/json", | ||
timeout: this.timeout | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
var req = https_1.default.request(config, function (res) { | ||
var data = ""; | ||
res.on("data", function (chunk) { | ||
data += chunk; | ||
}); | ||
if (!_this.is4xxOr5xx(res.statusCode)) { | ||
res.on("close", function () { | ||
var asnResp = JSON.parse(data); | ||
if (asnResp.country) { | ||
asnResp.countryCode = asnResp.country; | ||
asnResp.country = | ||
_this.countries[asnResp.countryCode]; | ||
} | ||
_this.cache.set(IPinfoWrapper.cacheKey(asn), asnResp); | ||
resolve(asnResp); | ||
}); | ||
res.on("error", function (error) { | ||
reject(error); | ||
}); | ||
} | ||
else { | ||
if (res.statusCode === 429) { | ||
reject(new apiLimitError_1.default()); | ||
} | ||
else { | ||
res.on("close", function () { | ||
reject(new Error(data)); | ||
}); | ||
} | ||
} | ||
}); | ||
req.on("error", function (error) { | ||
reject(error); | ||
}); | ||
req.end(); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
@@ -233,3 +246,3 @@ }; | ||
Accept: "application/json", | ||
Authorization: "Bearer " + this.token, | ||
Authorization: "Bearer ".concat(this.token), | ||
"Content-Type": "application/json", | ||
@@ -287,3 +300,3 @@ "Content-Length": ipsData.length, | ||
Accept: "application/json", | ||
Authorization: "Bearer " + this.token, | ||
Authorization: "Bearer ".concat(this.token), | ||
"Content-Type": "application/json", | ||
@@ -295,3 +308,3 @@ "Content-Length": ipsData.length, | ||
host: common_1.HOST, | ||
path: "/batch" + (filter ? "?filter=1" : ""), | ||
path: "/batch".concat(filter ? "?filter=1" : ""), | ||
timeout: batchTimeout | ||
@@ -345,3 +358,3 @@ }; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, lookupUrls, promises, i, end, resDetails, batchPromise, totalTimeoutReached, totalTimeoutRef, timeoutPromise; | ||
var result, lookupUrls, _i, urls_1, url, cachedUrl, promises, i, end, resDetails, batchPromise, totalTimeoutReached, totalTimeoutRef, timeoutPromise; | ||
var _this = this; | ||
@@ -353,5 +366,3 @@ return __generator(this, function (_a) { | ||
if (urls.length == 0) { | ||
return [2, new Promise(function (resolve) { | ||
resolve(result); | ||
})]; | ||
return [2, result]; | ||
} | ||
@@ -362,15 +373,23 @@ if (batchSize <= 0 || batchSize > common_1.BATCH_MAX_SIZE) { | ||
lookupUrls = []; | ||
urls.forEach(function (url) { | ||
var cachedUrl = _this.cache.get(IPinfoWrapper.cacheKey(url)); | ||
if (cachedUrl) { | ||
result[url] = cachedUrl; | ||
} | ||
else { | ||
lookupUrls.push(url); | ||
} | ||
}); | ||
_i = 0, urls_1 = urls; | ||
_a.label = 1; | ||
case 1: | ||
if (!(_i < urls_1.length)) return [3, 4]; | ||
url = urls_1[_i]; | ||
return [4, this.cache.get(IPinfoWrapper.cacheKey(url))]; | ||
case 2: | ||
cachedUrl = _a.sent(); | ||
if (cachedUrl) { | ||
result[url] = cachedUrl; | ||
} | ||
else { | ||
lookupUrls.push(url); | ||
} | ||
_a.label = 3; | ||
case 3: | ||
_i++; | ||
return [3, 1]; | ||
case 4: | ||
if (lookupUrls.length == 0) { | ||
return [2, new Promise(function (resolve) { | ||
resolve(result); | ||
})]; | ||
return [2, result]; | ||
} | ||
@@ -429,3 +448,3 @@ promises = []; | ||
})]; | ||
case 1: return [2, _a.sent()]; | ||
case 5: return [2, _a.sent()]; | ||
} | ||
@@ -432,0 +451,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
declare const VERSION = "3.3.0"; | ||
declare const VERSION = "3.4.0"; | ||
export default VERSION; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var VERSION = "3.3.0"; | ||
var VERSION = "3.4.0"; | ||
exports.default = VERSION; |
{ | ||
"name": "node-ipinfo", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Official Node client library for IPinfo", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114943
2075
24