utilitas 1989.8.84 → 1989.9.2
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 +5 -0
- package/index.mjs +75 -0
- package/lib/{cache.js → cache.mjs} +7 -9
- package/lib/{dbio.js → dbio.mjs} +4 -6
- package/lib/{email.js → email.mjs} +7 -6
- package/lib/{encryption.js → encryption.mjs} +4 -6
- package/lib/{event.js → event.mjs} +16 -22
- package/lib/{network.js → network.mjs} +7 -9
- package/lib/{sentinel.js → sentinel.mjs} +4 -6
- package/lib/{shell.js → shell.mjs} +5 -7
- package/lib/{shot.js → shot.mjs} +8 -10
- package/lib/{sms.js → sms.mjs} +7 -8
- package/lib/{storage.js → storage.mjs} +9 -11
- package/lib/{tape.js → tape.mjs} +6 -8
- package/lib/{uoid.js → uoid.mjs} +6 -6
- package/lib/{utilitas.js → utilitas.mjs} +6 -6
- package/package.json +17 -17
- package/index.js +0 -41
package/README.md
CHANGED
package/index.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as fileType from 'file-type';
|
|
2
|
+
import * as math from 'mathjs';
|
|
3
|
+
import * as uuid from 'uuid';
|
|
4
|
+
import base64url from 'base64url';
|
|
5
|
+
import cache from './lib/cache.mjs';
|
|
6
|
+
import colors from 'colors/safe.js';
|
|
7
|
+
import dbio from './lib/dbio.mjs';
|
|
8
|
+
import email from './lib/email.mjs';
|
|
9
|
+
import encryption from './lib/encryption.mjs';
|
|
10
|
+
import event from './lib/event.mjs';
|
|
11
|
+
import fetch from 'node-fetch';
|
|
12
|
+
import geoIp from 'fast-geoip';
|
|
13
|
+
import ini from 'ini';
|
|
14
|
+
import jwt from 'jsonwebtoken';
|
|
15
|
+
import mailgun from 'mailgun-js';
|
|
16
|
+
import mailjet from 'node-mailjet';
|
|
17
|
+
import mysql from 'mysql2/promise';
|
|
18
|
+
import network from './lib/network.mjs';
|
|
19
|
+
import ping from 'ping';
|
|
20
|
+
import publicIp from 'public-ip';
|
|
21
|
+
import qs from 'qs';
|
|
22
|
+
import redis from 'ioredis';
|
|
23
|
+
import sentinel from './lib/sentinel.mjs';
|
|
24
|
+
import sentry from '@sentry/node';
|
|
25
|
+
import shell from './lib/shell.mjs';
|
|
26
|
+
import shot from './lib/shot.mjs';
|
|
27
|
+
import sms from './lib/sms.mjs';
|
|
28
|
+
import storage from './lib/storage.mjs';
|
|
29
|
+
import tape from './lib/tape.mjs';
|
|
30
|
+
import telesign from 'telesignsdk';
|
|
31
|
+
import twilio from 'twilio';
|
|
32
|
+
import uoid from './lib/uoid.mjs';
|
|
33
|
+
import utilitas from './lib/utilitas.mjs';
|
|
34
|
+
import winston from 'winston';
|
|
35
|
+
import winstonPapertrail from 'winston-papertrail-mproved';
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
// dependencies
|
|
39
|
+
base64url,
|
|
40
|
+
colors,
|
|
41
|
+
fetch,
|
|
42
|
+
fileType,
|
|
43
|
+
geoIp,
|
|
44
|
+
ini,
|
|
45
|
+
jwt,
|
|
46
|
+
mailgun,
|
|
47
|
+
mailjet,
|
|
48
|
+
math,
|
|
49
|
+
mysql,
|
|
50
|
+
ping,
|
|
51
|
+
publicIp,
|
|
52
|
+
qs,
|
|
53
|
+
redis,
|
|
54
|
+
sentry,
|
|
55
|
+
telesign,
|
|
56
|
+
twilio,
|
|
57
|
+
uuid,
|
|
58
|
+
winston,
|
|
59
|
+
winstonPapertrail,
|
|
60
|
+
// features
|
|
61
|
+
cache,
|
|
62
|
+
dbio,
|
|
63
|
+
email,
|
|
64
|
+
encryption,
|
|
65
|
+
event,
|
|
66
|
+
network,
|
|
67
|
+
sentinel,
|
|
68
|
+
shell,
|
|
69
|
+
shot,
|
|
70
|
+
sms,
|
|
71
|
+
storage,
|
|
72
|
+
tape,
|
|
73
|
+
uoid,
|
|
74
|
+
utilitas,
|
|
75
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import utilitas from './utilitas.mjs';
|
|
2
|
+
|
|
3
|
+
const log = (content) => { return utilitas.modLog(content, 'cache'); };
|
|
4
|
+
|
|
5
|
+
let redis;
|
|
2
6
|
|
|
3
7
|
const defaultOptions = {
|
|
4
8
|
port: 6379, host: '127.0.0.1', family: 4, db: 0, connectTimeout: 1000 * 3,
|
|
5
9
|
};
|
|
6
10
|
|
|
7
|
-
let ioredis, redis;
|
|
8
|
-
|
|
9
|
-
const log = (content) => { return utilitas.modLog(content, 'cache'); };
|
|
10
|
-
|
|
11
11
|
const init = async (options) => {
|
|
12
12
|
if ((options = options === '@' ? defaultOptions : options)) {
|
|
13
|
-
ioredis =
|
|
13
|
+
const ioredis = await import('ioredis');
|
|
14
14
|
redis = new ioredis(options);
|
|
15
15
|
if (!options.silent) {
|
|
16
16
|
log(`Initialized: redis://${redis.options.host}`
|
|
@@ -21,7 +21,7 @@ const init = async (options) => {
|
|
|
21
21
|
return redis;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
export default {
|
|
25
25
|
init,
|
|
26
26
|
// set,
|
|
27
27
|
// get,
|
|
@@ -42,8 +42,6 @@ module.exports = {
|
|
|
42
42
|
// pUnLock
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const utilitas = require('./utilitas');
|
|
46
|
-
|
|
47
45
|
// https://github.com/luin/ioredis
|
|
48
46
|
|
|
49
47
|
// var getKey = function(type, id, callback) {
|
package/lib/{dbio.js → dbio.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import utilitas from './utilitas.mjs';
|
|
2
2
|
|
|
3
3
|
const defaultPort = 3306;
|
|
4
4
|
const orders = { '+': 'ASC', '-': 'DESC' };
|
|
@@ -9,11 +9,11 @@ const comparison = ['=', '>', '<', '<>', '!='];
|
|
|
9
9
|
const fieldNoQuote = [fieldAny, fieldCount];
|
|
10
10
|
const log = (content) => { return utilitas.modLog(content, 'dbio'); };
|
|
11
11
|
|
|
12
|
-
let
|
|
12
|
+
let pool;
|
|
13
13
|
|
|
14
14
|
const init = async (options) => {
|
|
15
15
|
if (options) {
|
|
16
|
-
mysql =
|
|
16
|
+
const mysql = await import('mysql2/promise.js');
|
|
17
17
|
pool = mysql.createPool(options);
|
|
18
18
|
if (!options.silent) {
|
|
19
19
|
log(`Initialized: mysql://${options.user}@${options.host}`
|
|
@@ -261,7 +261,7 @@ const deleteAll = async (table, options) => {
|
|
|
261
261
|
return await execute(assembleDelete(table));
|
|
262
262
|
};
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
export default {
|
|
265
265
|
assembleInsert,
|
|
266
266
|
assembleQuery,
|
|
267
267
|
assembleSet,
|
|
@@ -287,5 +287,3 @@ module.exports = {
|
|
|
287
287
|
updateByKeyValue,
|
|
288
288
|
upsert,
|
|
289
289
|
};
|
|
290
|
-
|
|
291
|
-
const utilitas = require('./utilitas');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import utilitas from './utilitas.mjs';
|
|
2
2
|
|
|
3
3
|
const log = (content) => { return utilitas.modLog(content, 'email'); };
|
|
4
4
|
|
|
5
|
-
let senderName, senderEmail, provider,
|
|
5
|
+
let senderName, senderEmail, provider, client;
|
|
6
6
|
|
|
7
7
|
const throwInvalidProvider = (message, status) => {
|
|
8
8
|
utilitas.throwError(message || 'Invalid email provider.', status || 500);
|
|
@@ -14,13 +14,14 @@ const init = async (options) => {
|
|
|
14
14
|
senderEmail = options.senderEmail;
|
|
15
15
|
senderName = options.senderName || (await utilitas.which()).name;
|
|
16
16
|
provider = utilitas.trim(options.provider, { case: 'UP' });
|
|
17
|
+
let engine;
|
|
17
18
|
switch (provider) {
|
|
18
19
|
case 'MAILGUN':
|
|
19
|
-
engine =
|
|
20
|
+
engine = await import('mailgun-js');
|
|
20
21
|
client = engine(options);
|
|
21
22
|
break;
|
|
22
23
|
case 'MAILJET':
|
|
23
|
-
engine =
|
|
24
|
+
engine = await import('node-mailjet');
|
|
24
25
|
client = engine.connect(options.apiKey, options.apiSecret);
|
|
25
26
|
break;
|
|
26
27
|
default:
|
|
@@ -87,14 +88,14 @@ const send = async (email, subject, text, html, args, options) => {
|
|
|
87
88
|
}, html ? { html } : {}));
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
+
export default {
|
|
91
92
|
getSenderName,
|
|
92
93
|
init,
|
|
93
94
|
rawSend,
|
|
94
95
|
send,
|
|
95
96
|
};
|
|
96
97
|
|
|
97
|
-
|
|
98
|
+
|
|
98
99
|
|
|
99
100
|
// (async () => {
|
|
100
101
|
// init({
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import qs from 'qs';
|
|
2
4
|
|
|
3
5
|
const defaultAlgorithm = 'sha256';
|
|
4
6
|
|
|
@@ -45,7 +47,7 @@ const digestObject = (object, algorithm) => {
|
|
|
45
47
|
return hash(getSortedQueryString(object), algorithm);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
export default {
|
|
49
51
|
defaultAlgorithm,
|
|
50
52
|
digestObject,
|
|
51
53
|
getSortedQueryString,
|
|
@@ -56,7 +58,3 @@ module.exports = {
|
|
|
56
58
|
sha256,
|
|
57
59
|
sha256File,
|
|
58
60
|
};
|
|
59
|
-
|
|
60
|
-
const crypto = require('crypto');
|
|
61
|
-
const fs = require('fs');
|
|
62
|
-
const qs = require('qs');
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import utilitas from './utilitas.mjs';
|
|
2
6
|
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
3
8
|
const jobs = {};
|
|
4
|
-
|
|
5
|
-
let timer = null;
|
|
6
|
-
|
|
7
9
|
const sToMs = (sec) => { return 1000 * (isNaN(sec = Number(sec)) ? 0 : sec); };
|
|
8
|
-
|
|
9
10
|
const unLock = (name) => { return jobs[name].lock = 0; };
|
|
10
|
-
|
|
11
11
|
const list = () => { return jobs; };
|
|
12
12
|
|
|
13
|
+
let timer = null;
|
|
14
|
+
|
|
13
15
|
const log = (content, job, options) => {
|
|
14
16
|
options = Object.assign({ time: true }, options || {});
|
|
15
17
|
if (!job || !jobs[job] || !jobs[job].silent
|
|
@@ -34,14 +36,11 @@ const exec = async () => {
|
|
|
34
36
|
jobs[i].lastRun = now;
|
|
35
37
|
try {
|
|
36
38
|
if (tryLock(i, now, jobs[i].timeout)) {
|
|
37
|
-
log('Locked, skipped.', i);
|
|
38
|
-
continue;
|
|
39
|
+
log('Locked, skipped.', i); continue;
|
|
39
40
|
}
|
|
40
41
|
log('Emit...', i);
|
|
41
42
|
await jobs[i].function();
|
|
42
|
-
} catch (err) {
|
|
43
|
-
log(err, i);
|
|
44
|
-
}
|
|
43
|
+
} catch (err) { log(err, i); }
|
|
45
44
|
log('Done.', i);
|
|
46
45
|
unLock(i);
|
|
47
46
|
}
|
|
@@ -78,10 +77,10 @@ const bulk = async (absDir, options) => {
|
|
|
78
77
|
const pms = [];
|
|
79
78
|
log(`SERVICES: ${absDir}`);
|
|
80
79
|
(fs.readdirSync(absDir) || []).filter((file) => {
|
|
81
|
-
return /\.
|
|
82
|
-
}).forEach((file) => {
|
|
83
|
-
const filename = file.replace(/^(.*)\.
|
|
84
|
-
const mod =
|
|
80
|
+
return /\.mjs$/i.test(file) && file.indexOf('.') !== 0;
|
|
81
|
+
}).forEach(async (file) => {
|
|
82
|
+
const filename = file.replace(/^(.*)\.mjs$/i, '$1');
|
|
83
|
+
const mod = await import(path.join(absDir, file));
|
|
85
84
|
if (mod.run) {
|
|
86
85
|
mod.name = mod.name || filename;
|
|
87
86
|
pms.push(load(mod, options));
|
|
@@ -104,15 +103,10 @@ const end = async () => {
|
|
|
104
103
|
log('Terminated.');
|
|
105
104
|
};
|
|
106
105
|
|
|
107
|
-
|
|
106
|
+
export default {
|
|
108
107
|
bulk,
|
|
108
|
+
end,
|
|
109
109
|
list,
|
|
110
110
|
load,
|
|
111
111
|
loop,
|
|
112
|
-
end,
|
|
113
112
|
};
|
|
114
|
-
|
|
115
|
-
const utilitas = require('./utilitas');
|
|
116
|
-
const uuidv4 = require('uuid').v4;
|
|
117
|
-
const path = require('path');
|
|
118
|
-
const fs = require('fs');
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import geoIp from 'fast-geoip';
|
|
3
|
+
import libPing from 'ping';
|
|
4
|
+
import publicIp from 'public-ip';
|
|
5
|
+
import shell from './shell.mjs';
|
|
6
|
+
import utilitas from './utilitas.mjs';
|
|
2
7
|
|
|
3
8
|
const log = (content) => { return utilitas.modLog(content, 'network'); };
|
|
4
9
|
|
|
@@ -89,17 +94,10 @@ const getCurrentPosition = async () => {
|
|
|
89
94
|
return Object.assign(loc, { ip });
|
|
90
95
|
};
|
|
91
96
|
|
|
92
|
-
|
|
97
|
+
export default {
|
|
93
98
|
getCurrentPosition,
|
|
94
99
|
httping,
|
|
95
100
|
pickFastestHost,
|
|
96
101
|
pickFastestHttpServer,
|
|
97
102
|
ping,
|
|
98
103
|
};
|
|
99
|
-
|
|
100
|
-
const utilitas = require('./utilitas');
|
|
101
|
-
const publicIp = require('public-ip');
|
|
102
|
-
const libPing = require('ping');
|
|
103
|
-
const fetch = require('node-fetch').default;
|
|
104
|
-
const geoIp = require('fast-geoip');
|
|
105
|
-
const shell = require('./shell');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import utilitas from './utilitas.mjs';
|
|
2
2
|
|
|
3
3
|
const log = (str, opts) => { return utilitas.modLog(str, 'sentinel', opts); };
|
|
4
4
|
|
|
5
|
-
let sentry
|
|
5
|
+
let sentry;
|
|
6
6
|
|
|
7
7
|
const integrations = (integrations) => {
|
|
8
8
|
return integrations.filter(x => {
|
|
@@ -13,7 +13,7 @@ const integrations = (integrations) => {
|
|
|
13
13
|
|
|
14
14
|
const init = async (options) => {
|
|
15
15
|
if (options) {
|
|
16
|
-
sentry =
|
|
16
|
+
sentry = await import('@sentry/node');
|
|
17
17
|
sentry.init(Object.assign({ integrations }, options));
|
|
18
18
|
if (!options.silent) { log(`Initialized, dsn: ${options.dsn} .`); }
|
|
19
19
|
}
|
|
@@ -21,8 +21,6 @@ const init = async (options) => {
|
|
|
21
21
|
return sentry;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
export default {
|
|
25
25
|
init,
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
const utilitas = require('./utilitas');
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import childProcess from 'child_process';
|
|
2
|
+
import util from 'util';
|
|
3
|
+
import utilitas from './utilitas.mjs';
|
|
2
4
|
|
|
3
5
|
const log = (content) => { return utilitas.modLog(content, 'shell'); };
|
|
4
6
|
const vF = (cmd, cbf) => { log(`Can not run in browser: ${cmd}`); cbf(); };
|
|
7
|
+
const pmsExec = util.promisify(childProcess && childProcess?.exec || vF);
|
|
5
8
|
|
|
6
9
|
const assertCommand = (command) => {
|
|
7
10
|
utilitas.assert(command, 'Command is required.', 500);
|
|
@@ -31,14 +34,9 @@ const assertExist = async (bin, er, code = 500) => {
|
|
|
31
34
|
utilitas.assert(await exist(bin), er || `Command not found: ${bin}.`, code);
|
|
32
35
|
};
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
export default {
|
|
35
38
|
assertExist,
|
|
36
39
|
exec,
|
|
37
40
|
exist,
|
|
38
41
|
which,
|
|
39
42
|
};
|
|
40
|
-
|
|
41
|
-
const childProcess = require('child_process');
|
|
42
|
-
const utilitas = require('./utilitas');
|
|
43
|
-
const util = require('util');
|
|
44
|
-
const pmsExec = util.promisify(childProcess && childProcess?.exec || vF);
|
package/lib/{shot.js → shot.mjs}
RENAMED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import * as fileType from 'file-type';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
import storage from './storage.mjs';
|
|
4
|
+
import utilitas from './utilitas.mjs';
|
|
2
5
|
|
|
3
6
|
const defFetchOpt = { redirect: 'follow', follow: 3, timeout: 1000 * 10 };
|
|
4
7
|
|
|
@@ -22,7 +25,7 @@ const checkVersion = async (pack) => {
|
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
const getCurrentPosition = async () => {
|
|
25
|
-
const url =
|
|
28
|
+
const url = 'https://geolocation-db.com/json/';
|
|
26
29
|
const rp = await fetch(url).then(res => res.json());
|
|
27
30
|
utilitas.assert(rp, 'Network is unreachable.', 500);
|
|
28
31
|
utilitas.assert(rp.country_code, 'Error detecting geolocation.', 500);
|
|
@@ -36,7 +39,7 @@ const get = async (url, options) => {
|
|
|
36
39
|
const r = await fetch(url, { defFetchOpt, ...options.fetch || {} });
|
|
37
40
|
const ts = (b) => { return b.toString('utf8'); };
|
|
38
41
|
const [htpMime, buffer] = [r.headers.get('content-type'), await r.buffer()];
|
|
39
|
-
const bufMime = utilitas.extract(await fileType.
|
|
42
|
+
const bufMime = utilitas.extract(await fileType.fileTypeFromBuffer(buffer), 'mime');
|
|
40
43
|
let [mimeType, content] = [bufMime || htpMime, null];
|
|
41
44
|
switch (options.encode) {
|
|
42
45
|
case 'BUFFER':
|
|
@@ -64,14 +67,9 @@ const get = async (url, options) => {
|
|
|
64
67
|
};
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
get,
|
|
70
|
+
export default {
|
|
69
71
|
checkVersion,
|
|
72
|
+
get,
|
|
70
73
|
getCurrentPosition,
|
|
71
74
|
getVersionOnNpm,
|
|
72
75
|
};
|
|
73
|
-
|
|
74
|
-
const utilitas = require('./utilitas');
|
|
75
|
-
const fileType = require('file-type');
|
|
76
|
-
const storage = require('./storage');
|
|
77
|
-
const fetch = require('node-fetch').default;
|
package/lib/{sms.js → sms.mjs}
RENAMED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import util from 'util';
|
|
2
|
+
import utilitas from './utilitas.mjs';
|
|
2
3
|
|
|
3
4
|
const defaultTeleSignApi = 'https://rest-api.telesign.com';
|
|
4
5
|
const defaultTimeout = 1000 * 10 // 10 secs
|
|
5
6
|
const log = (content) => { return utilitas.modLog(content, 'sms'); };
|
|
6
7
|
|
|
7
|
-
let sender,
|
|
8
|
+
let sender, provider, client, sendFunc;
|
|
8
9
|
|
|
9
10
|
const throwInvalidProvider = (message, status) => {
|
|
10
11
|
utilitas.throwError(message || 'Invalid SMS provider.', status || 500);
|
|
@@ -13,15 +14,16 @@ const throwInvalidProvider = (message, status) => {
|
|
|
13
14
|
const init = async (options) => {
|
|
14
15
|
if (options) {
|
|
15
16
|
provider = utilitas.trim(options.provider, { case: 'UP' });
|
|
17
|
+
let engine;
|
|
16
18
|
switch (provider) {
|
|
17
19
|
case 'TWILIO':
|
|
18
20
|
utilitas.assert(sender = options.phoneNumber,
|
|
19
21
|
'Sender phone number is required.', 500);
|
|
20
|
-
engine =
|
|
22
|
+
engine = await import('twilio');
|
|
21
23
|
client = new engine(options.accountSid, options.authToken);
|
|
22
24
|
break;
|
|
23
25
|
case 'TELESIGN':
|
|
24
|
-
engine =
|
|
26
|
+
engine = await import('telesignsdk');
|
|
25
27
|
client = new engine(
|
|
26
28
|
options.customerId, options.apiKey,
|
|
27
29
|
options.rest_endpoint || defaultTeleSignApi,
|
|
@@ -58,10 +60,7 @@ const send = async (phone, message) => {
|
|
|
58
60
|
}
|
|
59
61
|
};
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
export default {
|
|
62
64
|
init,
|
|
63
65
|
send,
|
|
64
66
|
};
|
|
65
|
-
|
|
66
|
-
const utilitas = require('./utilitas');
|
|
67
|
-
const util = require('util');
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import ini from 'ini';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import utilitas from './utilitas.mjs';
|
|
2
7
|
|
|
3
8
|
const [encoding, mode] = ['utf8', '0644'];
|
|
4
9
|
|
|
@@ -12,7 +17,7 @@ const stringify = (data, opts) => {
|
|
|
12
17
|
|
|
13
18
|
const writeTempFile = async (data, options) => {
|
|
14
19
|
let { filename, encoding: ec, mode: md, prefix, suffix: s } = options || {};
|
|
15
|
-
filename = `${prefix || ''}${filename ||
|
|
20
|
+
filename = `${prefix || ''}${filename || uuidv4()}${s ? `.${s}` : ''}`;
|
|
16
21
|
if (String(ec).toUpperCase() === 'JSON') {
|
|
17
22
|
data = stringify(data, options); ec = null;
|
|
18
23
|
}
|
|
@@ -144,7 +149,7 @@ const exists = async (fp) => {
|
|
|
144
149
|
try { return await fs.promises.stat(fp); } catch (_) { return null; }
|
|
145
150
|
};
|
|
146
151
|
|
|
147
|
-
|
|
152
|
+
export default {
|
|
148
153
|
assertPath,
|
|
149
154
|
encodeBase64DataURL,
|
|
150
155
|
exists,
|
|
@@ -157,11 +162,4 @@ module.exports = {
|
|
|
157
162
|
writeIni,
|
|
158
163
|
writeJson,
|
|
159
164
|
writeTempFile,
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const fs = require('fs');
|
|
163
|
-
const ini = require('ini');
|
|
164
|
-
const os = require('os');
|
|
165
|
-
const path = require('path');
|
|
166
|
-
const utilitas = require('./utilitas');
|
|
167
|
-
const uuid = require('uuid');
|
|
165
|
+
};
|
package/lib/{tape.js → tape.mjs}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import utilitas from './utilitas.mjs';
|
|
2
2
|
|
|
3
3
|
// https://github.com/winstonjs/winston#logging-levels
|
|
4
4
|
// const levels = ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly'];
|
|
@@ -61,8 +61,8 @@ const init = async (options) => {
|
|
|
61
61
|
options.provider, { case: 'UP' }
|
|
62
62
|
) || providerDefault;
|
|
63
63
|
options = await getDefaultOptions(provider, options);
|
|
64
|
-
winston =
|
|
65
|
-
papertrail =
|
|
64
|
+
winston = await import('winston');
|
|
65
|
+
papertrail = await import('winston-papertrail-mproved');
|
|
66
66
|
papertrailConnection = new papertrail.PapertrailConnection(options);
|
|
67
67
|
papertrailConnection.on('error', handleError);
|
|
68
68
|
papertrailConnection.on('connect', handleConnect);
|
|
@@ -88,10 +88,8 @@ const end = async () => {
|
|
|
88
88
|
}, 1000);
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
init,
|
|
93
|
-
getLogger,
|
|
91
|
+
export default {
|
|
94
92
|
end,
|
|
93
|
+
getLogger,
|
|
94
|
+
init,
|
|
95
95
|
};
|
|
96
|
-
|
|
97
|
-
const utilitas = require('./utilitas');
|
package/lib/{uoid.js → uoid.mjs}
RENAMED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import * as uuid from 'uuid';
|
|
3
|
+
import encryption from './encryption.mjs';
|
|
4
|
+
import utilitas from './utilitas.mjs';
|
|
2
5
|
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
3
7
|
const uuidRegTxt = '[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}';
|
|
4
8
|
|
|
5
9
|
const getTimestampFromUuid = (uuid) => {
|
|
@@ -26,13 +30,9 @@ const getRfcUrlNamespaceUuid = (url) => {
|
|
|
26
30
|
return uuid.v5(url, uuid.v5.URL);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
export default {
|
|
30
34
|
uuidRegTxt,
|
|
31
35
|
create,
|
|
32
36
|
getRfcUrlNamespaceUuid,
|
|
33
37
|
getTimestampFromUuid,
|
|
34
38
|
};
|
|
35
|
-
|
|
36
|
-
const encryption = require('./encryption');
|
|
37
|
-
const utilitas = require('./utilitas');
|
|
38
|
-
const uuid = require('uuid');
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import colors from 'colors/safe.js';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import storage from './storage.mjs';
|
|
2
5
|
|
|
3
6
|
Object.values = Object.values || ((obj) => {
|
|
4
7
|
return Object.keys(obj).map((key) => {
|
|
@@ -10,6 +13,7 @@ RegExp.escape = RegExp.escape || ((str) => { //$& means the whole matched string
|
|
|
10
13
|
return String(str).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
14
|
}); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
12
15
|
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
17
|
const invalidTime = 'Invalid time.';
|
|
14
18
|
|
|
15
19
|
const tryOpts = {
|
|
@@ -609,7 +613,7 @@ const purgeEmoji = (any, replace = '') => {
|
|
|
609
613
|
);
|
|
610
614
|
};
|
|
611
615
|
|
|
612
|
-
|
|
616
|
+
export default {
|
|
613
617
|
arrayEqual,
|
|
614
618
|
assembleApiUrl,
|
|
615
619
|
assembleUrl,
|
|
@@ -689,7 +693,3 @@ module.exports = {
|
|
|
689
693
|
verifyUuid,
|
|
690
694
|
which,
|
|
691
695
|
};
|
|
692
|
-
|
|
693
|
-
const storage = require('./storage');
|
|
694
|
-
const colors = require('colors/safe');
|
|
695
|
-
const path = require('path');
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utilitas",
|
|
3
3
|
"description": "Just another common utility for Node.js.",
|
|
4
|
-
"version": "1989.
|
|
4
|
+
"version": "1989.9.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/Leask/utilitas",
|
|
7
|
-
"main": "index.
|
|
7
|
+
"main": "index.mjs",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
|
-
"start": "node index.
|
|
10
|
-
"debug": "node --inspect --trace-warnings debug.
|
|
11
|
-
"test": "node --inspect --trace-warnings test.
|
|
10
|
+
"start": "node index.mjs",
|
|
11
|
+
"debug": "node --inspect --trace-warnings debug.mjs",
|
|
12
|
+
"test": "node --inspect --trace-warnings test.mjs",
|
|
12
13
|
"ncuinit": "npm install -g npm-check-updates",
|
|
13
|
-
"updep": "npx ncu -u && npm install && npm install
|
|
14
|
+
"updep": "npx ncu -u && npm install && npm install node-fetch@2 && ( git commit -am 'update dependencies' || true )",
|
|
14
15
|
"gitsync": "git pull && git push",
|
|
15
|
-
"
|
|
16
|
-
"prepublishOnly": "npm version patch && npm run gitsync"
|
|
16
|
+
"prepublishOnly": "npm version patch && npm run updep && npm run gitsync"
|
|
17
17
|
},
|
|
18
18
|
"author": "Leask Wong <i@leaskh.com>",
|
|
19
19
|
"license": "MIT",
|
|
@@ -25,23 +25,23 @@
|
|
|
25
25
|
"@sentry/node": "^6.16.1",
|
|
26
26
|
"base64url": "^3.0.1",
|
|
27
27
|
"colors": "1.4.0",
|
|
28
|
-
"fast-geoip": "^1.1.
|
|
29
|
-
"file-type": "^
|
|
28
|
+
"fast-geoip": "^1.1.54",
|
|
29
|
+
"file-type": "^17.1.1",
|
|
30
30
|
"ini": "github:Leask/ini",
|
|
31
|
-
"ioredis": "^4.28.
|
|
31
|
+
"ioredis": "^4.28.3",
|
|
32
32
|
"jsonwebtoken": "^8.5.1",
|
|
33
33
|
"mailgun-js": "^0.22.0",
|
|
34
|
-
"mathjs": "^10.0
|
|
34
|
+
"mathjs": "^10.1.0",
|
|
35
35
|
"mysql2": "^2.3.3",
|
|
36
|
-
"node-fetch": "^2.6.
|
|
36
|
+
"node-fetch": "^2.6.7",
|
|
37
37
|
"node-mailjet": "^3.3.4",
|
|
38
38
|
"ping": "^0.4.1",
|
|
39
|
-
"public-ip": "^
|
|
40
|
-
"qs": "^6.10.
|
|
39
|
+
"public-ip": "^5.0.0",
|
|
40
|
+
"qs": "^6.10.3",
|
|
41
41
|
"telesignsdk": "^2.2.1",
|
|
42
|
-
"twilio": "^3.
|
|
42
|
+
"twilio": "^3.73.0",
|
|
43
43
|
"uuid": "^8.3.2",
|
|
44
|
-
"winston": "^3.
|
|
44
|
+
"winston": "^3.4.0",
|
|
45
45
|
"winston-papertrail-mproved": "^1.0.7"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
// dependencies
|
|
5
|
-
base64url: require('base64url'),
|
|
6
|
-
colors: require('colors/safe'),
|
|
7
|
-
fetch: require('node-fetch').default,
|
|
8
|
-
fileType: require('file-type'),
|
|
9
|
-
geoIp: require('fast-geoip'),
|
|
10
|
-
ini: require('ini'),
|
|
11
|
-
jwt: require('jsonwebtoken'),
|
|
12
|
-
mailgun: require('mailgun-js'),
|
|
13
|
-
mailjet: require('node-mailjet'),
|
|
14
|
-
math: require('mathjs'),
|
|
15
|
-
mysql: require('mysql2/promise'),
|
|
16
|
-
ping: require('ping'),
|
|
17
|
-
publicIp: require('public-ip'),
|
|
18
|
-
qs: require('qs'),
|
|
19
|
-
redis: require('ioredis'),
|
|
20
|
-
sentry: require('@sentry/node'),
|
|
21
|
-
telesign: require('telesignsdk'),
|
|
22
|
-
twilio: require('twilio'),
|
|
23
|
-
uuid: require('uuid'),
|
|
24
|
-
winston: require('winston'),
|
|
25
|
-
winstonPapertrail: require('winston-papertrail-mproved'),
|
|
26
|
-
// features
|
|
27
|
-
cache: require('./lib/cache'),
|
|
28
|
-
dbio: require('./lib/dbio'),
|
|
29
|
-
email: require('./lib/email'),
|
|
30
|
-
encryption: require('./lib/encryption'),
|
|
31
|
-
event: require('./lib/event'),
|
|
32
|
-
network: require('./lib/network'),
|
|
33
|
-
sentinel: require('./lib/sentinel'),
|
|
34
|
-
shell: require('./lib/shell'),
|
|
35
|
-
shot: require('./lib/shot'),
|
|
36
|
-
sms: require('./lib/sms'),
|
|
37
|
-
storage: require('./lib/storage'),
|
|
38
|
-
tape: require('./lib/tape'),
|
|
39
|
-
uoid: require('./lib/uoid'),
|
|
40
|
-
utilitas: require('./lib/utilitas'),
|
|
41
|
-
};
|