@k03mad/ip2geo 7.0.4 → 7.2.0

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/.husky/pre-commit CHANGED
@@ -1,2 +1 @@
1
- npm run lint
2
- npm run test
1
+ ./node_modules/.bin/run-p -c lint test
package/app/lib/ip2geo.js CHANGED
@@ -2,7 +2,6 @@ import os from 'node:os';
2
2
  import path from 'node:path';
3
3
 
4
4
  import {request} from '@k03mad/request';
5
- import {logErrorExit} from '@k03mad/simple-log';
6
5
 
7
6
  import {
8
7
  collectOutputData,
@@ -68,7 +67,11 @@ export const ip2geo = async ({
68
67
  rps = DEFAULT_RPS,
69
68
  } = {}) => {
70
69
  if (ip) {
71
- const mapCache = readFromMapCache(ip, cacheMap, cacheMapMaxEntries);
70
+ const mapCache = readFromMapCache(
71
+ ip,
72
+ cacheMap,
73
+ cacheMapMaxEntries,
74
+ );
72
75
 
73
76
  if (mapCache) {
74
77
  return mapCache;
@@ -76,12 +79,19 @@ export const ip2geo = async ({
76
79
 
77
80
  const fsCache = await readFromFsCache(
78
81
  ip,
79
- cacheDir, cacheFileName,
80
- cacheFileSeparator, cacheFileNewline,
82
+ cacheDir,
83
+ cacheFileName,
84
+ cacheFileSeparator,
85
+ cacheFileNewline,
81
86
  );
82
87
 
83
88
  if (fsCache) {
84
- writeToMapCache(fsCache, cacheMap, cacheMapMaxEntries);
89
+ writeToMapCache(
90
+ fsCache,
91
+ cacheMap,
92
+ cacheMapMaxEntries,
93
+ );
94
+
85
95
  return fsCache;
86
96
  }
87
97
  }
@@ -90,11 +100,11 @@ export const ip2geo = async ({
90
100
  const {body} = await request(reqUrl, {}, {rps});
91
101
 
92
102
  if (!body?.ip) {
93
- logErrorExit([
103
+ throw new Error([
94
104
  'API error',
95
105
  `request: ${reqUrl}`,
96
- `response body: ${body}`,
97
- ]);
106
+ `response body: ${JSON.stringify(body)}`,
107
+ ].join('\n'));
98
108
  }
99
109
 
100
110
  const outputData = collectOutputData([
@@ -113,12 +123,19 @@ export const ip2geo = async ({
113
123
  body?.connection?.domain,
114
124
  ]);
115
125
 
116
- writeToMapCache(outputData, cacheMap, cacheMapMaxEntries);
126
+ writeToMapCache(
127
+ outputData,
128
+ cacheMap,
129
+ cacheMapMaxEntries,
130
+ );
117
131
 
118
132
  await writeToFsCache(
119
- body.ip, outputData,
120
- cacheDir, cacheFileName,
121
- cacheFileSeparator, cacheFileNewline,
133
+ body.ip,
134
+ outputData,
135
+ cacheDir,
136
+ cacheFileName,
137
+ cacheFileSeparator,
138
+ cacheFileNewline,
122
139
  );
123
140
 
124
141
  return outputData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/ip2geo",
3
- "version": "7.0.4",
3
+ "version": "7.2.0",
4
4
  "description": "GeoIP library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -19,24 +19,23 @@
19
19
  "node": ">=20"
20
20
  },
21
21
  "dependencies": {
22
- "@k03mad/request": "5.6.3",
23
- "@k03mad/simple-log": "2.1.2",
22
+ "@k03mad/request": "5.7.0",
23
+ "@k03mad/simple-log": "2.1.4",
24
24
  "chalk": "5.3.0",
25
- "debug": "4.3.4"
25
+ "debug": "4.3.5"
26
26
  },
27
27
  "devDependencies": {
28
- "@k03mad/eslint-config": "20.6.0",
28
+ "@k03mad/eslint-config": "22.1.0",
29
29
  "eslint": "8.57.0",
30
30
  "husky": "9.0.11",
31
- "mocha": "10.4.0"
31
+ "mocha": "10.4.0",
32
+ "npm-run-all": "4.1.5"
32
33
  },
33
34
  "scripts": {
34
35
  "lint": "npm run lint:eslint",
35
36
  "lint:eslint": "eslint ./ --cache",
36
37
  "test": "rm -rfv ./.geoip && mocha tests",
37
- "clean": "npm run clean:modules && npm run clean:eslint:cache",
38
- "clean:modules": "rm -rf ./node_modules || true",
39
- "clean:eslint:cache": "rm -rf .eslintcache || true",
38
+ "clean": "rm -rf ./node_modules .eslintcache || true",
40
39
  "setup": "npm run clean && npm run setup:pnpm",
41
40
  "setup:pnpm": "npm i pnpm -g && pnpm i",
42
41
  "prepare": "husky || true"
package/tests/default.js CHANGED
@@ -38,7 +38,7 @@ describe(testName, () => {
38
38
 
39
39
  Object.keys(REQUEST_IPV4).forEach(key => {
40
40
  it(`should have "${key}" in request response`, () => {
41
- assert.ok(data[key]);
41
+ assert.ok(Object.hasOwn(data, key));
42
42
  });
43
43
  });
44
44
 
@@ -25,8 +25,8 @@ export const REQUEST_IPV4_MAP_OFF_ONLY = {
25
25
  regionCode: 'ZH',
26
26
  city: 'Zürich',
27
27
  connectionAsn: 19_281,
28
- connectionOrg: 'Quad9',
29
- connectionIsp: 'Quad9',
28
+ connectionOrg: 'Quad',
29
+ connectionIsp: 'Quad',
30
30
  connectionDomain: 'quad9.net',
31
31
  };
32
32
 
@@ -40,8 +40,8 @@ export const REQUEST_IPV6 = {
40
40
  region: 'North Holland',
41
41
  regionCode: 'NH',
42
42
  city: 'Amsterdam',
43
- connectionAsn: 0,
44
- connectionOrg: '',
45
- connectionIsp: 'NetActuate Inc',
43
+ connectionAsn: 36_236,
44
+ connectionOrg: 'Netactuate INC',
45
+ connectionIsp: 'Netactuate, INC',
46
46
  connectionDomain: '',
47
47
  };