utilitas 1989.9.9 → 1989.9.13
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/index.mjs +0 -1
- package/lib/email.mjs +1 -1
- package/lib/event.mjs +1 -1
- package/lib/network.mjs +2 -2
- package/lib/shot.mjs +10 -0
- package/package.json +5 -2
package/index.mjs
CHANGED
|
@@ -10,7 +10,6 @@ export * as mailjet from 'node-mailjet';
|
|
|
10
10
|
export * as math from 'mathjs';
|
|
11
11
|
export * as mysql from 'mysql2/promise';
|
|
12
12
|
export * as ping from 'ping';
|
|
13
|
-
export * as publicIp from 'public-ip';
|
|
14
13
|
export * as qs from 'qs';
|
|
15
14
|
export * as redis from 'ioredis';
|
|
16
15
|
export * as sentry from '@sentry/node';
|
package/lib/email.mjs
CHANGED
|
@@ -21,7 +21,7 @@ const init = async (options) => {
|
|
|
21
21
|
client = engine(options);
|
|
22
22
|
break;
|
|
23
23
|
case 'MAILJET':
|
|
24
|
-
engine = await import('node-mailjet');
|
|
24
|
+
engine = (await import('node-mailjet')).default;
|
|
25
25
|
client = engine.connect(options.apiKey, options.apiSecret);
|
|
26
26
|
break;
|
|
27
27
|
default:
|
package/lib/event.mjs
CHANGED
|
@@ -81,7 +81,7 @@ const bulk = async (absDir, options) => {
|
|
|
81
81
|
file => /\.mjs$/i.test(file) && !file.startsWith('.')
|
|
82
82
|
), []];
|
|
83
83
|
for (let file of files) {
|
|
84
|
-
const mod = await import(path.join(absDir, file));
|
|
84
|
+
const mod = { ...await import(path.join(absDir, file)) };
|
|
85
85
|
if (!mod.run) { continue; }
|
|
86
86
|
mod.name = mod.name || file.replace(/^(.*)\.mjs$/i, '$1');
|
|
87
87
|
pmsRun.push(load(mod, options));
|
package/lib/network.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { getCurrentIp } from './shot.mjs';
|
|
1
2
|
import * as shell from './shell.mjs';
|
|
2
3
|
import * as utilitas from './utilitas.mjs';
|
|
3
4
|
import fetch from 'node-fetch';
|
|
4
5
|
import geoIp from 'fast-geoip';
|
|
5
6
|
import libPing from 'ping';
|
|
6
|
-
import publicIp from 'public-ip';
|
|
7
7
|
|
|
8
8
|
const log = (content) => { return utilitas.modLog(content, 'network'); };
|
|
9
9
|
|
|
@@ -87,7 +87,7 @@ const pickFastestHttpServer = async (urls, options = {}) => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
const getCurrentPosition = async () => {
|
|
90
|
-
const ip = await
|
|
90
|
+
const ip = await getCurrentIp();
|
|
91
91
|
utilitas.assert(ip, 'Network is unreachable.', 500);
|
|
92
92
|
const loc = await geoIp.lookup(ip);
|
|
93
93
|
utilitas.assert(loc, 'Error detecting geolocation.', 500);
|
package/lib/shot.mjs
CHANGED
|
@@ -24,6 +24,14 @@ const checkVersion = async (pack) => {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
const getCurrentIp = async (options) => {
|
|
28
|
+
const resp = await get(
|
|
29
|
+
'https://ifconfig.me/all.json', { encode: 'JSON', ...options || {} }
|
|
30
|
+
);
|
|
31
|
+
utilitas.assert(resp?.content?.ip_addr, 'Error detecting IP address.', 500);
|
|
32
|
+
return options?.raw ? resp : resp.content.ip_addr;
|
|
33
|
+
};
|
|
34
|
+
|
|
27
35
|
const getCurrentPosition = async () => {
|
|
28
36
|
const url = 'https://geolocation-db.com/json/';
|
|
29
37
|
const rp = await fetch(url).then(res => res.json());
|
|
@@ -67,9 +75,11 @@ const get = async (url, options) => {
|
|
|
67
75
|
};
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
export default get;
|
|
70
79
|
export {
|
|
71
80
|
checkVersion,
|
|
72
81
|
get,
|
|
73
82
|
getCurrentPosition,
|
|
83
|
+
getCurrentIp,
|
|
74
84
|
getVersionOnNpm,
|
|
75
85
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utilitas",
|
|
3
3
|
"description": "Just another common utility for Node.js.",
|
|
4
|
-
"version": "1989.9.
|
|
4
|
+
"version": "1989.9.13",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
7
|
"main": "index.mjs",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=16.x"
|
|
11
|
+
},
|
|
9
12
|
"scripts": {
|
|
10
13
|
"start": "node index.mjs",
|
|
11
14
|
"debug": "node --inspect --trace-warnings debug.mjs",
|
|
@@ -34,7 +37,7 @@
|
|
|
34
37
|
"mathjs": "^10.1.0",
|
|
35
38
|
"mysql2": "^2.3.3",
|
|
36
39
|
"node-fetch": "^2.6.7",
|
|
37
|
-
"node-mailjet": "^3.3.
|
|
40
|
+
"node-mailjet": "^3.3.5",
|
|
38
41
|
"ping": "^0.4.1",
|
|
39
42
|
"public-ip": "^5.0.0",
|
|
40
43
|
"qs": "^6.10.3",
|