@sellout/utils 0.0.401 → 0.0.402
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/IPStack.js +25 -4
- package/.dist/IPStack.js.map +1 -1
- package/package.json +2 -2
- package/src/IPStack.ts +26 -4
package/.dist/IPStack.js
CHANGED
|
@@ -12,7 +12,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.gecodeIPAddress = void 0;
|
|
13
13
|
const request = require("request-promise-native");
|
|
14
14
|
const env_1 = require("./env");
|
|
15
|
+
const EMPTY_GEOLOCATION = {
|
|
16
|
+
city: null,
|
|
17
|
+
region_code: null,
|
|
18
|
+
zip: null,
|
|
19
|
+
country_code: null,
|
|
20
|
+
latitude: null,
|
|
21
|
+
longitude: null,
|
|
22
|
+
};
|
|
15
23
|
function gecodeIPAddress(ipAddress) {
|
|
24
|
+
var _a;
|
|
16
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
26
|
// Return mock data for load testing
|
|
18
27
|
if (env_1.LOAD_TEST_ENABLED) {
|
|
@@ -26,10 +35,22 @@ function gecodeIPAddress(ipAddress) {
|
|
|
26
35
|
longitude: 114.1631
|
|
27
36
|
};
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
try {
|
|
39
|
+
const url = `http://api.ipstack.com/${ipAddress}?access_key=${env_1.IP_STACK_API_KEY}`;
|
|
40
|
+
const response = yield request.get(url, {
|
|
41
|
+
json: true
|
|
42
|
+
});
|
|
43
|
+
// IPStack returns success false
|
|
44
|
+
if (response && response.success === false) {
|
|
45
|
+
console.warn(`IPStack API error for ${ipAddress}: ${((_a = response === null || response === void 0 ? void 0 : response.error) === null || _a === void 0 ? void 0 : _a.type) || 'unknown'}`);
|
|
46
|
+
return EMPTY_GEOLOCATION;
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.warn(`IPStack request failed for ${ipAddress}: ${e.message}`);
|
|
52
|
+
return EMPTY_GEOLOCATION;
|
|
53
|
+
}
|
|
33
54
|
});
|
|
34
55
|
}
|
|
35
56
|
exports.gecodeIPAddress = gecodeIPAddress;
|
package/.dist/IPStack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IPStack.js","sourceRoot":"","sources":["../src/IPStack.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkD;AAClD,+BAGe;AAEf,SAAsB,eAAe,CAAC,SAAS
|
|
1
|
+
{"version":3,"file":"IPStack.js","sourceRoot":"","sources":["../src/IPStack.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkD;AAClD,+BAGe;AAEf,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,IAAI;IACV,WAAW,EAAE,IAAI;IACjB,GAAG,EAAE,IAAI;IACT,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF,SAAsB,eAAe,CAAC,SAAS;;;QAC7C,oCAAoC;QACpC,IAAG,uBAAiB,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;YACtC,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI;gBACjB,GAAG,EAAE,OAAO;gBACZ,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,OAAO;gBACjB,SAAS,EAAE,QAAQ;aACpB,CAAC;SACH;QAED,IAAI;YACF,MAAM,GAAG,GAAG,0BAA0B,SAAS,eAAe,sBAAgB,EAAE,CAAC;YACjF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE;gBACtC,IAAI,EAAE,IAAI;aACX,CAAC,CAAC;YAEH,gCAAgC;YAChC,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,EAAE;gBAC1C,OAAO,CAAC,IAAI,CAAC,yBAAyB,SAAS,KAAK,CAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,0CAAE,IAAI,KAAI,SAAS,EAAE,CAAC,CAAC;gBAC1F,OAAO,iBAAiB,CAAC;aAC1B;YAED,OAAO,QAAQ,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,8BAA8B,SAAS,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtE,OAAO,iBAAiB,CAAC;SAC1B;;CACF;AA/BD,0CA+BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sellout/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.402",
|
|
4
4
|
"description": "Sellout.io utils",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "npm run build",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"nodemon": "^2.0.22",
|
|
25
25
|
"typescript": "^4.4.2"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "d6f566351e195612423566b5e4b776abf4d3bf40"
|
|
28
28
|
}
|
package/src/IPStack.ts
CHANGED
|
@@ -4,6 +4,15 @@ import {
|
|
|
4
4
|
LOAD_TEST_ENABLED,
|
|
5
5
|
} from "./env";
|
|
6
6
|
|
|
7
|
+
const EMPTY_GEOLOCATION = {
|
|
8
|
+
city: null,
|
|
9
|
+
region_code: null,
|
|
10
|
+
zip: null,
|
|
11
|
+
country_code: null,
|
|
12
|
+
latitude: null,
|
|
13
|
+
longitude: null,
|
|
14
|
+
};
|
|
15
|
+
|
|
7
16
|
export async function gecodeIPAddress(ipAddress) {
|
|
8
17
|
// Return mock data for load testing
|
|
9
18
|
if(LOAD_TEST_ENABLED) {
|
|
@@ -18,8 +27,21 @@ export async function gecodeIPAddress(ipAddress) {
|
|
|
18
27
|
};
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
try {
|
|
31
|
+
const url = `http://api.ipstack.com/${ipAddress}?access_key=${IP_STACK_API_KEY}`;
|
|
32
|
+
const response = await request.get(url, {
|
|
33
|
+
json: true
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// IPStack returns success false
|
|
37
|
+
if (response && response.success === false) {
|
|
38
|
+
console.warn(`IPStack API error for ${ipAddress}: ${response?.error?.type || 'unknown'}`);
|
|
39
|
+
return EMPTY_GEOLOCATION;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return response;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.warn(`IPStack request failed for ${ipAddress}: ${e.message}`);
|
|
45
|
+
return EMPTY_GEOLOCATION;
|
|
46
|
+
}
|
|
25
47
|
}
|