geoip-lite2 2.1.42 → 2.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/README.md +15 -18
- package/geoip-data/city.checksum +1 -0
- package/geoip-data/country.checksum +1 -0
- package/{data → geoip-data}/geoip-city-names.dat +0 -0
- package/{data → geoip-data}/geoip-city.dat +0 -0
- package/{data → geoip-data}/geoip-city6.dat +0 -0
- package/{data → geoip-data}/geoip-country.dat +0 -0
- package/{data → geoip-data}/geoip-country6.dat +0 -0
- package/index.d.ts +10 -6
- package/lib/fsWatcher.js +69 -1
- package/lib/main.js +501 -1
- package/lib/utils.js +86 -1
- package/lib-minified/fsWatcher.js +1 -0
- package/lib-minified/main.js +1 -0
- package/lib-minified/utils.js +1 -0
- package/minify.js +55 -0
- package/package.json +12 -14
- package/test/example.js +7 -0
- package/test/geo-lookup.js +55 -1
- package/test/index.test.js +227 -1
- package/test/memory_usage.js +4 -1
- package/test/other.js +6 -1
- package/test/setInterval.js +16 -1
- package/utils/updatedb.js +609 -1
- package/utils-minified/updatedb.js +1 -0
- package/data/city.checksum +0 -1
- package/data/country.checksum +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<br>
|
|
6
6
|
<p>
|
|
7
7
|
A native <a href="https://nodejs.org" target="_blank" title="Open nodejs.org">Node.js</a> API for the GeoLite data from MaxMind.<br>
|
|
8
|
-
This product includes GeoLite data created by MaxMind, available from
|
|
8
|
+
This product includes GeoLite data created by MaxMind, available from <a href="https://www.maxmind.com" target="_blank" title="Open www.maxmind.com">maxmind.com</a>.
|
|
9
9
|
</p>
|
|
10
10
|
<a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
|
|
11
11
|
<img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
|
|
@@ -18,28 +18,30 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
# 🚀 Improved GeoIP Module by [Sefinek](https://sefinek.net)
|
|
21
|
-
This module is an enhanced and updated version of [geoip-lite](https://github.com/geoip-lite/node-geoip),
|
|
21
|
+
This module is an enhanced and updated version of [geoip-lite](https://github.com/geoip-lite/node-geoip), carefully designed to meet the latest programming standards.
|
|
22
22
|
|
|
23
|
-
All components have
|
|
24
|
-
The module now
|
|
23
|
+
All components have been thoroughly updated to ensure optimal performance and functionality.
|
|
24
|
+
The module now runs even faster, thanks to file minification!
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
This improvement strengthens testing and contributes to the overall reliability of the module.
|
|
26
|
+
Furthermore, the testing process has been improved with the adoption of the [Jest](https://www.npmjs.com/package/jest) testing library.
|
|
28
27
|
|
|
29
28
|
> I am not the primary creator of this! All copyright rights belong to the original [authors](AUTHORS).
|
|
30
29
|
|
|
31
30
|
|
|
31
|
+
## ⚠️ Important
|
|
32
|
+
Remember to regularly update the Maxmind database. You'll need the token for this.
|
|
33
|
+
|
|
34
|
+
|
|
32
35
|
## 🌠 Version without a Local Database
|
|
33
36
|
This module requires a significant amount of RAM because geolocation data is stored in memory.
|
|
34
|
-
However, you can always
|
|
35
|
-
|
|
37
|
+
However, you can always opt for the official alternative, the [geoip2-api](https://www.npmjs.com/package/geoip2-api) module, which sends requests to an API server and retrieves information about specific IP addresses directly from there.
|
|
36
38
|
|
|
37
39
|
### ✨ Demonstration
|
|
38
40
|
You can see this module in action using my [official API](https://api.sefinek.net). The API interface is public and can be safely used in your projects without any limits. Happy coding!
|
|
39
41
|
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
42
|
+
- Specific IP: https://api.sefinek.net/api/v2/geoip/109.207.159.255
|
|
43
|
+
- Client's IP: https://api.sefinek.net/api/v2/geoip/me
|
|
44
|
+
- Documentation: https://api.sefinek.net/docs/v2
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
## 📑 Introduction
|
|
@@ -93,13 +95,12 @@ console.log(geo);
|
|
|
93
95
|
|
|
94
96
|
|
|
95
97
|
## 🛠️ Installation
|
|
96
|
-
|
|
97
98
|
### 1. Get the library
|
|
98
99
|
```cmd
|
|
99
100
|
npm install geoip-lite2
|
|
100
101
|
```
|
|
101
102
|
|
|
102
|
-
### 2. Update the datafiles (
|
|
103
|
+
### 2. Update the datafiles (recommended)
|
|
103
104
|
Run `cd node_modules/geoip-lite2 && npm run updatedb license_key=YOUR_LICENSE_KEY` to update the data files. (Replace `YOUR_LICENSE_KEY` with your license key obtained from [maxmind.com](https://support.maxmind.com/hc/en-us/articles/4407111582235-Generate-a-License-Key))
|
|
104
105
|
|
|
105
106
|
You can create maxmind account [here](https://www.maxmind.com/en/geolite2/signup).
|
|
@@ -180,7 +181,7 @@ npm run updatedb-force license_key=YOUR_LICENSE_KEY
|
|
|
180
181
|
|
|
181
182
|
You can also run it by doing:
|
|
182
183
|
```shell
|
|
183
|
-
node ./node_modules/geoip-lite2/
|
|
184
|
+
node ./node_modules/geoip-lite2/utils/updatedb.js license_key=YOUR_LICENSE_KEY
|
|
184
185
|
```
|
|
185
186
|
|
|
186
187
|
### Ways to reload data in your app when update finished
|
|
@@ -250,10 +251,6 @@ console.log(process.memoryUsage());
|
|
|
250
251
|
```
|
|
251
252
|
|
|
252
253
|
|
|
253
|
-
## 🔀 Alternatives
|
|
254
|
-
If your use-case requires doing less than 100 queries through the lifetime of your application or if you need really fast latency on start-up, you might want to look into [fast-geoip](https://github.com/onramper/fast-geoip) a package with a compatible API that is optimized for serverless environments and provides faster boot times and lower memory consumption at the expense of longer lookup times.
|
|
255
|
-
|
|
256
|
-
|
|
257
254
|
## 🔖 References
|
|
258
255
|
- [Documentation from MaxMind](https://www.maxmind.com/app/iso3166)
|
|
259
256
|
- [ISO 3166 (1 & 2) codes](https://en.wikipedia.org/wiki/ISO_3166)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
86914bd2508c1dd336fc25b2e73700447ccf11bca63ea6cdec6f427314770d09 GeoLite2-City-CSV_20241018.zip
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aa9b53b486d2411cfcb92da8197a45d8aecb20f17ff4c1f6b17bd32bd2237e51 GeoLite2-Country-CSV_20241018.zip
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
CHANGED
|
@@ -2,23 +2,25 @@ declare module 'geoip-lite2' {
|
|
|
2
2
|
export const cmp: number | null;
|
|
3
3
|
|
|
4
4
|
interface GeoIp2Location {
|
|
5
|
-
range: [number, number];
|
|
5
|
+
range: [number | null, number | null];
|
|
6
6
|
country: string;
|
|
7
7
|
region: string;
|
|
8
8
|
eu: '0' | '1';
|
|
9
9
|
timezone: string;
|
|
10
10
|
city: string;
|
|
11
|
-
ll: [number, number];
|
|
11
|
+
ll: [number | null, number | null];
|
|
12
12
|
metro: number;
|
|
13
13
|
area: number;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function lookup(ip: string): GeoIp2Location | null;
|
|
17
|
-
function pretty(
|
|
16
|
+
function lookup(ip: string | number): GeoIp2Location | null;
|
|
17
|
+
function pretty(n: string | number | any[]): string;
|
|
18
18
|
|
|
19
19
|
function reloadDataSync(): void;
|
|
20
|
-
function reloadData(callback: () => void): void
|
|
21
|
-
function startWatchingDataUpdate(): void;
|
|
20
|
+
function reloadData(callback: (err?: Error | null) => void): Promise<void>;
|
|
21
|
+
function startWatchingDataUpdate(callback: () => void): void;
|
|
22
|
+
function stopWatchingDataUpdate(): void;
|
|
23
|
+
function clear(): void;
|
|
22
24
|
|
|
23
25
|
export {
|
|
24
26
|
lookup,
|
|
@@ -26,5 +28,7 @@ declare module 'geoip-lite2' {
|
|
|
26
28
|
reloadDataSync,
|
|
27
29
|
reloadData,
|
|
28
30
|
startWatchingDataUpdate,
|
|
31
|
+
stopWatchingDataUpdate,
|
|
32
|
+
clear
|
|
29
33
|
};
|
|
30
34
|
}
|
package/lib/fsWatcher.js
CHANGED
|
@@ -1 +1,69 @@
|
|
|
1
|
-
const{access
|
|
1
|
+
const { access, constants, watch } = require('fs');
|
|
2
|
+
const { join } = require('path');
|
|
3
|
+
const FSWatcher = {};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Takes an FSWatcher object and closes it.
|
|
7
|
+
* @param {string} name - The name of the watcher to close.
|
|
8
|
+
*/
|
|
9
|
+
const stopWatching = name => FSWatcher[name].close();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Takes a directory/file and watch for change. Upon change, call the callback.
|
|
13
|
+
*
|
|
14
|
+
* @param {String} name - name of this watcher
|
|
15
|
+
* @param {String} directory - path to the directory to watch
|
|
16
|
+
* @param {String} [filename] - (optional) specific filename to watch for, watches for all files in the directory if unspecified
|
|
17
|
+
* @param {Number} cdDelay - delay to wait before triggering the callback
|
|
18
|
+
* @param {Function} callback - function() - called when changes are detected
|
|
19
|
+
*/
|
|
20
|
+
const makeFsWatchFilter = (name, directory, filename, cdDelay, callback) => {
|
|
21
|
+
let cdId = null;
|
|
22
|
+
|
|
23
|
+
// Delete the cdId and callback the outer function
|
|
24
|
+
function timeoutCallback() {
|
|
25
|
+
cdId = null;
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// This function is called when there is a change in the data directory
|
|
30
|
+
// It sets a timer to wait for the change to be completed
|
|
31
|
+
function onWatchEvent(event, changedFile) {
|
|
32
|
+
// Check to make sure changedFile is not null
|
|
33
|
+
if (!changedFile) return;
|
|
34
|
+
|
|
35
|
+
const filePath = join(directory, changedFile);
|
|
36
|
+
if (!filename || filename === changedFile) {
|
|
37
|
+
access(filePath, constants.F_OK, err => {
|
|
38
|
+
if (err) return console.error(err);
|
|
39
|
+
|
|
40
|
+
// At this point, a new file system activity has been detected,
|
|
41
|
+
// We have to wait for file transfer to be finished before moving on.
|
|
42
|
+
|
|
43
|
+
// If a cdId already exists, we delete it
|
|
44
|
+
if (cdId !== null) {
|
|
45
|
+
clearTimeout(cdId);
|
|
46
|
+
cdId = null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Once the cdDelay has passed, the timeoutCallback function will be called
|
|
50
|
+
cdId = setTimeout(timeoutCallback, cdDelay);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Manage the case where filename is missing (because it's optional)
|
|
56
|
+
if (typeof cdDelay === 'function') {
|
|
57
|
+
callback = cdDelay;
|
|
58
|
+
cdDelay = filename;
|
|
59
|
+
filename = null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (FSWatcher[name]) {
|
|
63
|
+
stopWatching(name);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
FSWatcher[name] = watch(directory, onWatchEvent);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports = { makeFsWatchFilter, stopWatching };
|