@naturalcycles/nodejs-lib 13.1.0 → 13.1.1
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/bin/del.js +3 -2
- package/dist/bin/generate-build-info.js +8 -7
- package/dist/bin/json2env.js +3 -2
- package/dist/bin/kpy.js +3 -2
- package/dist/bin/secrets-decrypt.js +3 -2
- package/dist/bin/secrets-encrypt.js +3 -2
- package/dist/bin/secrets-gen-key.js +5 -4
- package/dist/bin/slack-this.js +3 -2
- package/dist/colors/colors.d.ts +1 -1
- package/dist/colors/colors.js +31 -30
- package/dist/fs/del.js +11 -10
- package/dist/fs/fs.util.d.ts +1 -1
- package/dist/fs/fs.util.js +42 -41
- package/dist/fs/json2env.js +6 -5
- package/dist/fs/kpy.js +8 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/infra/process.util.js +8 -7
- package/dist/jwt/jwt.service.d.ts +1 -1
- package/dist/jwt/jwt.service.js +6 -5
- package/dist/secret/secrets-decrypt.util.js +9 -8
- package/dist/secret/secrets-encrypt.util.js +8 -7
- package/dist/security/crypto.util.js +9 -8
- package/dist/security/hash.util.js +4 -3
- package/dist/security/id.util.js +4 -3
- package/dist/security/secret.util.js +7 -6
- package/dist/stream/ndjson/ndjsonStreamForEach.js +3 -2
- package/dist/stream/ndjson/pipelineFromNDJsonFile.js +4 -3
- package/dist/stream/ndjson/pipelineToNDJsonFile.js +4 -3
- package/dist/util/env.util.js +3 -2
- package/dist/util/exec.util.js +4 -3
- package/dist/util/git.util.js +9 -8
- package/dist/util/zip.util.js +6 -5
- package/dist/validation/ajv/getAjv.js +2 -1
- package/dist/validation/joi/joi.extensions.d.ts +1 -1
- package/dist/validation/joi/joi.extensions.js +3 -2
- package/dist/validation/joi/number.extensions.d.ts +1 -1
- package/dist/validation/joi/string.extensions.d.ts +1 -1
- package/package.json +1 -1
- package/src/bin/del.ts +1 -1
- package/src/bin/generate-build-info.ts +3 -3
- package/src/bin/json2env.ts +1 -1
- package/src/bin/kpy.ts +1 -1
- package/src/bin/secrets-decrypt.ts +1 -1
- package/src/bin/secrets-encrypt.ts +1 -1
- package/src/bin/secrets-gen-key.ts +2 -2
- package/src/bin/slack-this.ts +1 -1
- package/src/colors/colors.ts +2 -2
- package/src/fs/del.ts +2 -2
- package/src/fs/fs.util.ts +3 -3
- package/src/fs/json2env.ts +1 -1
- package/src/fs/kpy.ts +1 -1
- package/src/index.ts +2 -2
- package/src/infra/process.util.ts +1 -1
- package/src/jwt/jwt.service.ts +1 -1
- package/src/secret/secrets-decrypt.util.ts +2 -2
- package/src/secret/secrets-encrypt.util.ts +2 -2
- package/src/security/crypto.util.ts +1 -1
- package/src/security/hash.util.ts +1 -1
- package/src/security/id.util.ts +1 -1
- package/src/security/secret.util.ts +1 -1
- package/src/stream/ndjson/ndjsonStreamForEach.ts +1 -1
- package/src/stream/ndjson/pipelineFromNDJsonFile.ts +1 -1
- package/src/stream/ndjson/pipelineToNDJsonFile.ts +1 -1
- package/src/util/env.util.ts +1 -1
- package/src/util/exec.util.ts +1 -1
- package/src/util/git.util.ts +2 -2
- package/src/util/zip.util.ts +1 -1
- package/src/validation/joi/joi.extensions.ts +1 -1
- package/src/validation/joi/number.extensions.ts +1 -1
- package/src/validation/joi/string.extensions.ts +1 -1
package/dist/fs/kpy.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.kpySync = exports.kpy = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
const colors_1 = require("../colors/colors");
|
|
7
8
|
const index_1 = require("../index");
|
|
@@ -15,9 +16,9 @@ async function kpy(opt) {
|
|
|
15
16
|
kpyLogFilenames(opt, filenames);
|
|
16
17
|
const overwrite = !opt.noOverwrite;
|
|
17
18
|
await Promise.all(filenames.map(async (filename) => {
|
|
18
|
-
const basename =
|
|
19
|
-
const srcFilename =
|
|
20
|
-
const destFilename =
|
|
19
|
+
const basename = node_path_1.default.basename(filename);
|
|
20
|
+
const srcFilename = node_path_1.default.resolve(opt.baseDir, filename);
|
|
21
|
+
const destFilename = node_path_1.default.resolve(opt.outputDir, opt.flat ? basename : filename);
|
|
21
22
|
if (!opt.dry) {
|
|
22
23
|
if (opt.move) {
|
|
23
24
|
await (0, index_1._movePath)(srcFilename, destFilename, {
|
|
@@ -45,9 +46,9 @@ function kpySync(opt) {
|
|
|
45
46
|
kpyLogFilenames(opt, filenames);
|
|
46
47
|
const overwrite = !opt.noOverwrite;
|
|
47
48
|
filenames.forEach(filename => {
|
|
48
|
-
const basename =
|
|
49
|
-
const srcFilename =
|
|
50
|
-
const destFilename =
|
|
49
|
+
const basename = node_path_1.default.basename(filename);
|
|
50
|
+
const srcFilename = node_path_1.default.resolve(opt.baseDir, filename);
|
|
51
|
+
const destFilename = node_path_1.default.resolve(opt.outputDir, opt.flat ? basename : filename);
|
|
51
52
|
if (!opt.dry) {
|
|
52
53
|
if (opt.move) {
|
|
53
54
|
(0, index_1._movePathSync)(srcFilename, destFilename, { force: overwrite });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
import
|
|
2
|
+
import fastGlob from 'fast-glob';
|
|
3
3
|
import type { Options as FastGlobOptions } from 'fast-glob';
|
|
4
|
-
import
|
|
4
|
+
import globby from 'globby';
|
|
5
5
|
import type { GlobbyOptions } from 'globby';
|
|
6
6
|
import type { AnySchema, ValidationErrorItem, AlternativesSchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema } from 'joi';
|
|
7
7
|
export * from './buffer/buffer.util';
|
package/dist/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Ajv = exports.fastGlob = exports.globby = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const ajv_1 = require("ajv");
|
|
5
|
+
const ajv_1 = tslib_1.__importDefault(require("ajv"));
|
|
6
6
|
exports.Ajv = ajv_1.default;
|
|
7
|
-
const
|
|
8
|
-
exports.fastGlob =
|
|
9
|
-
const
|
|
10
|
-
exports.globby =
|
|
7
|
+
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
|
8
|
+
exports.fastGlob = fast_glob_1.default;
|
|
9
|
+
const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
10
|
+
exports.globby = globby_1.default;
|
|
11
11
|
tslib_1.__exportStar(require("./buffer/buffer.util"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./diff/tableDiff"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./infra/process.util"), exports);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processSharedUtil = exports.memoryUsageFull = exports.memoryUsage = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_os_1 = tslib_1.__importDefault(require("node:os"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
function memoryUsage() {
|
|
7
8
|
const { rss, external, heapUsed, heapTotal } = process.memoryUsage();
|
|
@@ -15,8 +16,8 @@ function memoryUsage() {
|
|
|
15
16
|
exports.memoryUsage = memoryUsage;
|
|
16
17
|
function memoryUsageFull() {
|
|
17
18
|
const { rss, external, heapUsed, heapTotal } = process.memoryUsage();
|
|
18
|
-
const totalMem =
|
|
19
|
-
const freeMem =
|
|
19
|
+
const totalMem = node_os_1.default.totalmem();
|
|
20
|
+
const freeMem = node_os_1.default.freemem();
|
|
20
21
|
return {
|
|
21
22
|
rss: (0, js_lib_1._mb)(rss),
|
|
22
23
|
heapTotal: (0, js_lib_1._mb)(heapTotal),
|
|
@@ -39,7 +40,7 @@ class ProcessUtil {
|
|
|
39
40
|
setTimeout(() => clearInterval(this.timer), afterMillis);
|
|
40
41
|
}
|
|
41
42
|
cpuAvg() {
|
|
42
|
-
const avg =
|
|
43
|
+
const avg = node_os_1.default.loadavg();
|
|
43
44
|
return {
|
|
44
45
|
avg1: avg[0].toFixed(2),
|
|
45
46
|
avg5: avg[1].toFixed(2),
|
|
@@ -47,9 +48,9 @@ class ProcessUtil {
|
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
cpuInfo() {
|
|
50
|
-
const c =
|
|
51
|
+
const c = node_os_1.default.cpus()[0];
|
|
51
52
|
return {
|
|
52
|
-
count:
|
|
53
|
+
count: node_os_1.default.cpus().length,
|
|
53
54
|
model: c.model,
|
|
54
55
|
speed: c.speed,
|
|
55
56
|
};
|
|
@@ -72,7 +73,7 @@ class ProcessUtil {
|
|
|
72
73
|
}
|
|
73
74
|
getCPUInfo() {
|
|
74
75
|
// eslint-disable-next-line unicorn/no-array-reduce
|
|
75
|
-
return
|
|
76
|
+
return node_os_1.default.cpus().reduce((r, cpu) => {
|
|
76
77
|
r['idle'] += cpu.times.idle;
|
|
77
78
|
Object.values(cpu.times).forEach(m => (r['total'] += m));
|
|
78
79
|
return r;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { AnyObject, ErrorData, JWTString } from '@naturalcycles/js-lib';
|
|
3
3
|
import { AnySchema } from 'joi';
|
|
4
4
|
import type { Algorithm, VerifyOptions, JwtHeader, SignOptions } from 'jsonwebtoken';
|
|
5
|
-
import
|
|
5
|
+
import jsonwebtoken from 'jsonwebtoken';
|
|
6
6
|
export { jsonwebtoken };
|
|
7
7
|
export type { Algorithm, VerifyOptions, SignOptions, JwtHeader };
|
|
8
8
|
export interface JWTServiceCfg {
|
package/dist/jwt/jwt.service.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JWTService = exports.jsonwebtoken = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
|
-
const
|
|
6
|
-
exports.jsonwebtoken =
|
|
6
|
+
const jsonwebtoken_1 = tslib_1.__importDefault(require("jsonwebtoken"));
|
|
7
|
+
exports.jsonwebtoken = jsonwebtoken_1.default;
|
|
7
8
|
const joi_shared_schemas_1 = require("../validation/joi/joi.shared.schemas");
|
|
8
9
|
const joi_validation_util_1 = require("../validation/joi/joi.validation.util");
|
|
9
10
|
// todo: define JWTError and list possible options
|
|
@@ -30,7 +31,7 @@ class JWTService {
|
|
|
30
31
|
if (schema) {
|
|
31
32
|
(0, joi_validation_util_1.validate)(payload, schema);
|
|
32
33
|
}
|
|
33
|
-
return
|
|
34
|
+
return jsonwebtoken_1.default.sign(payload, this.cfg.privateKey, {
|
|
34
35
|
algorithm: this.cfg.algorithm,
|
|
35
36
|
noTimestamp: true,
|
|
36
37
|
...this.cfg.signOptions,
|
|
@@ -40,7 +41,7 @@ class JWTService {
|
|
|
40
41
|
verify(token, schema, opt = {}, publicKey) {
|
|
41
42
|
(0, js_lib_1._assert)(this.cfg.publicKey, 'JWTService: publicKey is required to be able to verify, but not provided');
|
|
42
43
|
try {
|
|
43
|
-
const data =
|
|
44
|
+
const data = jsonwebtoken_1.default.verify(token, publicKey || this.cfg.publicKey, {
|
|
44
45
|
algorithms: [this.cfg.algorithm],
|
|
45
46
|
...this.cfg.verifyOptions,
|
|
46
47
|
...opt,
|
|
@@ -60,7 +61,7 @@ class JWTService {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
decode(token, schema) {
|
|
63
|
-
const data =
|
|
64
|
+
const data = jsonwebtoken_1.default.decode(token, {
|
|
64
65
|
complete: true,
|
|
65
66
|
});
|
|
66
67
|
(0, js_lib_1._assert)(data?.payload, 'invalid token, decoded value is empty', {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.secretsDecrypt = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
8
|
const colors_1 = require("../colors/colors");
|
|
8
9
|
const index_1 = require("../index");
|
|
@@ -23,22 +24,22 @@ function secretsDecrypt(dir, file, encKeyBuffer, del = false, jsonMode = false)
|
|
|
23
24
|
filenames.forEach(filename => {
|
|
24
25
|
let plainFilename;
|
|
25
26
|
if (jsonMode) {
|
|
26
|
-
(0, js_lib_1._assert)(filename.endsWith('.json'), `${
|
|
27
|
-
(0, js_lib_1._assert)(!filename.endsWith('.plain.json'), `${
|
|
27
|
+
(0, js_lib_1._assert)(filename.endsWith('.json'), `${node_path_1.default.basename(filename)} MUST end with '.json'`);
|
|
28
|
+
(0, js_lib_1._assert)(!filename.endsWith('.plain.json'), `${node_path_1.default.basename(filename)} MUST NOT end with '.plain.json'`);
|
|
28
29
|
plainFilename = filename.replace('.json', '.plain.json');
|
|
29
30
|
const json = (0, crypto_util_1.decryptObject)((0, index_1._readJsonSync)(filename), encKeyBuffer);
|
|
30
31
|
(0, index_1._writeJsonSync)(plainFilename, json, { spaces: 2 });
|
|
31
32
|
}
|
|
32
33
|
else {
|
|
33
|
-
const enc =
|
|
34
|
+
const enc = node_fs_1.default.readFileSync(filename);
|
|
34
35
|
const plain = (0, crypto_util_1.decryptRandomIVBuffer)(enc, encKeyBuffer);
|
|
35
36
|
plainFilename = filename.slice(0, filename.length - '.enc'.length);
|
|
36
|
-
|
|
37
|
+
node_fs_1.default.writeFileSync(plainFilename, plain);
|
|
37
38
|
}
|
|
38
39
|
if (del) {
|
|
39
|
-
|
|
40
|
+
node_fs_1.default.unlinkSync(filename);
|
|
40
41
|
}
|
|
41
|
-
console.log(` ${
|
|
42
|
+
console.log(` ${node_path_1.default.basename(filename)} > ${node_path_1.default.basename(plainFilename)}`);
|
|
42
43
|
});
|
|
43
44
|
console.log(`decrypted ${(0, colors_1.yellow)(filenames.length)} files in ${(0, colors_1.dimGrey)(dir.join(' '))}`);
|
|
44
45
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.secretsEncrypt = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
8
|
const colors_1 = require("../colors/colors");
|
|
8
9
|
const index_1 = require("../index");
|
|
@@ -22,21 +23,21 @@ function secretsEncrypt(pattern, file, encKeyBuffer, del = false, jsonMode = fal
|
|
|
22
23
|
let encFilename;
|
|
23
24
|
filenames.forEach(filename => {
|
|
24
25
|
if (jsonMode) {
|
|
25
|
-
(0, js_lib_1._assert)(filename.endsWith('.plain.json'), `${
|
|
26
|
+
(0, js_lib_1._assert)(filename.endsWith('.plain.json'), `${node_path_1.default.basename(filename)} MUST end with '.plain.json'`);
|
|
26
27
|
encFilename = filename.replace('.plain', '');
|
|
27
28
|
const json = (0, crypto_util_1.encryptObject)((0, index_1._readJsonSync)(filename), encKeyBuffer);
|
|
28
29
|
(0, index_1._writeJsonSync)(encFilename, json, { spaces: 2 });
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
const plain =
|
|
32
|
+
const plain = node_fs_1.default.readFileSync(filename);
|
|
32
33
|
const enc = (0, crypto_util_1.encryptRandomIVBuffer)(plain, encKeyBuffer);
|
|
33
34
|
encFilename = `${filename}.enc`;
|
|
34
|
-
|
|
35
|
+
node_fs_1.default.writeFileSync(encFilename, enc);
|
|
35
36
|
}
|
|
36
37
|
if (del) {
|
|
37
|
-
|
|
38
|
+
node_fs_1.default.unlinkSync(filename);
|
|
38
39
|
}
|
|
39
|
-
console.log(` ${
|
|
40
|
+
console.log(` ${node_path_1.default.basename(filename)} > ${node_path_1.default.basename(encFilename)}`);
|
|
40
41
|
});
|
|
41
42
|
console.log(`encrypted ${(0, colors_1.yellow)(filenames.length)} files in (${(0, colors_1.dimGrey)(pattern.join(' '))})`);
|
|
42
43
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.encryptString = exports.decryptString = exports.encryptObject = exports.decryptObject = exports.decryptRandomIVBuffer = exports.encryptRandomIVBuffer = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
const hash_util_1 = require("./hash.util");
|
|
7
8
|
const algorithm = 'aes-256-cbc';
|
|
@@ -12,8 +13,8 @@ function encryptRandomIVBuffer(input, secretKeyBuffer) {
|
|
|
12
13
|
// sha256 to match aes-256 key length
|
|
13
14
|
const key = (0, hash_util_1.sha256AsBuffer)(secretKeyBuffer);
|
|
14
15
|
// Random iv to achieve non-deterministic encryption (but deterministic decryption)
|
|
15
|
-
const iv =
|
|
16
|
-
const cipher =
|
|
16
|
+
const iv = node_crypto_1.default.randomBytes(16);
|
|
17
|
+
const cipher = node_crypto_1.default.createCipheriv(algorithm, key, iv);
|
|
17
18
|
return Buffer.concat([iv, cipher.update(input), cipher.final()]);
|
|
18
19
|
}
|
|
19
20
|
exports.encryptRandomIVBuffer = encryptRandomIVBuffer;
|
|
@@ -26,7 +27,7 @@ function decryptRandomIVBuffer(input, secretKeyBuffer) {
|
|
|
26
27
|
// iv is first 16 bytes of encrypted buffer, the rest is payload
|
|
27
28
|
const iv = input.subarray(0, 16);
|
|
28
29
|
const payload = input.subarray(16);
|
|
29
|
-
const decipher =
|
|
30
|
+
const decipher = node_crypto_1.default.createDecipheriv(algorithm, key, iv);
|
|
30
31
|
return Buffer.concat([decipher.update(payload), decipher.final()]);
|
|
31
32
|
}
|
|
32
33
|
exports.decryptRandomIVBuffer = decryptRandomIVBuffer;
|
|
@@ -38,7 +39,7 @@ function decryptObject(obj, secretKeyBuffer) {
|
|
|
38
39
|
const { key, iv } = getCryptoParams(secretKeyBuffer);
|
|
39
40
|
const r = {};
|
|
40
41
|
(0, js_lib_1._stringMapEntries)(obj).forEach(([k, v]) => {
|
|
41
|
-
const decipher =
|
|
42
|
+
const decipher = node_crypto_1.default.createDecipheriv(algorithm, key, iv);
|
|
42
43
|
r[k] = decipher.update(v, 'base64', 'utf8') + decipher.final('utf8');
|
|
43
44
|
});
|
|
44
45
|
return r;
|
|
@@ -52,7 +53,7 @@ function encryptObject(obj, secretKeyBuffer) {
|
|
|
52
53
|
const { key, iv } = getCryptoParams(secretKeyBuffer);
|
|
53
54
|
const r = {};
|
|
54
55
|
(0, js_lib_1._stringMapEntries)(obj).forEach(([k, v]) => {
|
|
55
|
-
const cipher =
|
|
56
|
+
const cipher = node_crypto_1.default.createCipheriv(algorithm, key, iv);
|
|
56
57
|
r[k] = cipher.update(v, 'utf8', 'base64') + cipher.final('base64');
|
|
57
58
|
});
|
|
58
59
|
return r;
|
|
@@ -66,7 +67,7 @@ exports.encryptObject = encryptObject;
|
|
|
66
67
|
*/
|
|
67
68
|
function decryptString(str, secretKeyBuffer) {
|
|
68
69
|
const { key, iv } = getCryptoParams(secretKeyBuffer);
|
|
69
|
-
const decipher =
|
|
70
|
+
const decipher = node_crypto_1.default.createDecipheriv(algorithm, key, iv);
|
|
70
71
|
return decipher.update(str, 'base64', 'utf8') + decipher.final('utf8');
|
|
71
72
|
}
|
|
72
73
|
exports.decryptString = decryptString;
|
|
@@ -78,7 +79,7 @@ exports.decryptString = decryptString;
|
|
|
78
79
|
*/
|
|
79
80
|
function encryptString(str, secretKeyBuffer) {
|
|
80
81
|
const { key, iv } = getCryptoParams(secretKeyBuffer);
|
|
81
|
-
const cipher =
|
|
82
|
+
const cipher = node_crypto_1.default.createCipheriv(algorithm, key, iv);
|
|
82
83
|
return cipher.update(str, 'utf8', 'base64') + cipher.final('base64');
|
|
83
84
|
}
|
|
84
85
|
exports.encryptString = encryptString;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bufferToBase64 = exports.stringToBase64 = exports.base64ToBuffer = exports.base64ToString = exports.base64 = exports.hashAsBuffer = exports.hash = exports.sha256AsBuffer = exports.sha256AsBase64 = exports.sha256 = exports.md5AsBuffer = exports.md5AsBase64 = exports.md5 = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
5
6
|
function md5(s) {
|
|
6
7
|
return hash(s, 'md5');
|
|
7
8
|
}
|
|
@@ -27,11 +28,11 @@ function sha256AsBuffer(s) {
|
|
|
27
28
|
}
|
|
28
29
|
exports.sha256AsBuffer = sha256AsBuffer;
|
|
29
30
|
function hash(s, algorithm) {
|
|
30
|
-
return
|
|
31
|
+
return node_crypto_1.default.createHash(algorithm).update(s).digest('hex');
|
|
31
32
|
}
|
|
32
33
|
exports.hash = hash;
|
|
33
34
|
function hashAsBuffer(s, algorithm) {
|
|
34
|
-
return
|
|
35
|
+
return node_crypto_1.default.createHash(algorithm).update(s).digest();
|
|
35
36
|
}
|
|
36
37
|
exports.hashAsBuffer = hashAsBuffer;
|
|
37
38
|
function base64(s) {
|
package/dist/security/id.util.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringIdBase64Url = exports.stringIdBase64 = exports.stringIdBase62 = exports.stringId = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
5
6
|
const nanoid_1 = require("./nanoid");
|
|
6
7
|
/**
|
|
7
8
|
* Generate cryptographically-secure string id.
|
|
@@ -26,7 +27,7 @@ exports.stringIdBase62 = (0, nanoid_1.nanoIdCustomAlphabet)(nanoid_1.ALPHABET_AL
|
|
|
26
27
|
* Dividable by 4 lengths produce ids with no padding `=` characters, which is optimal.
|
|
27
28
|
*/
|
|
28
29
|
function stringIdBase64(size = 16) {
|
|
29
|
-
return
|
|
30
|
+
return node_crypto_1.default.randomBytes(size * 0.75).toString('base64');
|
|
30
31
|
}
|
|
31
32
|
exports.stringIdBase64 = stringIdBase64;
|
|
32
33
|
/**
|
|
@@ -38,6 +39,6 @@ exports.stringIdBase64 = stringIdBase64;
|
|
|
38
39
|
* Base64url always produces strings without a padding character `=`, by design.
|
|
39
40
|
*/
|
|
40
41
|
function stringIdBase64Url(size = 16) {
|
|
41
|
-
return
|
|
42
|
+
return node_crypto_1.default.randomBytes(size * 0.75).toString('base64url');
|
|
42
43
|
}
|
|
43
44
|
exports.stringIdBase64Url = stringIdBase64Url;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setSecretMap = exports.getSecretMap = exports.secretOptional = exports.secret = exports.loadSecretsFromEncryptedJsonFileValues = exports.loadSecretsFromEncryptedJsonFile = exports.removeSecretsFromEnv = exports.loadSecretsFromEnv = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
const crypto_util_1 = require("./crypto.util");
|
|
7
8
|
let loaded = false;
|
|
@@ -44,16 +45,16 @@ exports.removeSecretsFromEnv = removeSecretsFromEnv;
|
|
|
44
45
|
* For "json-values encrypted" style - use `loadSecretsFromEncryptedJsonFileValues`
|
|
45
46
|
*/
|
|
46
47
|
function loadSecretsFromEncryptedJsonFile(filePath, secretEncryptionKey) {
|
|
47
|
-
(0, js_lib_1._assert)(
|
|
48
|
+
(0, js_lib_1._assert)(node_fs_1.default.existsSync(filePath), `loadSecretsFromEncryptedJsonFile() cannot load from path: ${filePath}`);
|
|
48
49
|
let secrets;
|
|
49
50
|
if (secretEncryptionKey) {
|
|
50
|
-
const buf =
|
|
51
|
+
const buf = node_fs_1.default.readFileSync(filePath);
|
|
51
52
|
const encKeyBuffer = Buffer.from(secretEncryptionKey, 'base64');
|
|
52
53
|
const plain = (0, crypto_util_1.decryptRandomIVBuffer)(buf, encKeyBuffer).toString('utf8');
|
|
53
54
|
secrets = JSON.parse(plain);
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
56
|
-
secrets = JSON.parse(
|
|
57
|
+
secrets = JSON.parse(node_fs_1.default.readFileSync(filePath, 'utf8'));
|
|
57
58
|
}
|
|
58
59
|
Object.entries(secrets).forEach(([k, v]) => (secretMap[k.toUpperCase()] = v));
|
|
59
60
|
loaded = true;
|
|
@@ -67,8 +68,8 @@ exports.loadSecretsFromEncryptedJsonFile = loadSecretsFromEncryptedJsonFile;
|
|
|
67
68
|
* For whole-file encryption - use `loadSecretsFromEncryptedJsonFile`
|
|
68
69
|
*/
|
|
69
70
|
function loadSecretsFromEncryptedJsonFileValues(filePath, secretEncryptionKey) {
|
|
70
|
-
(0, js_lib_1._assert)(
|
|
71
|
-
let secrets = JSON.parse(
|
|
71
|
+
(0, js_lib_1._assert)(node_fs_1.default.existsSync(filePath), `loadSecretsFromEncryptedJsonFileValues() cannot load from path: ${filePath}`);
|
|
72
|
+
let secrets = JSON.parse(node_fs_1.default.readFileSync(filePath, 'utf8'));
|
|
72
73
|
if (secretEncryptionKey) {
|
|
73
74
|
const encKeyBuffer = Buffer.from(secretEncryptionKey, 'base64');
|
|
74
75
|
secrets = (0, crypto_util_1.decryptObject)(secrets, encKeyBuffer);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ndjsonStreamForEach = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
const node_zlib_1 = require("node:zlib");
|
|
6
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
8
|
const __1 = require("../..");
|
|
@@ -12,7 +13,7 @@ async function ndjsonStreamForEach(mapper, opt) {
|
|
|
12
13
|
(0, __1.requireFileToExist)(opt.inputFilePath);
|
|
13
14
|
const transformUnzip = opt.inputFilePath.endsWith('.gz') ? [(0, node_zlib_1.createUnzip)()] : [];
|
|
14
15
|
await (0, __1._pipeline)([
|
|
15
|
-
|
|
16
|
+
node_fs_1.default.createReadStream(opt.inputFilePath),
|
|
16
17
|
...transformUnzip,
|
|
17
18
|
(0, __1.transformSplit)(),
|
|
18
19
|
(0, __1.transformJsonParse)(),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pipelineFromNDJsonFile = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const node_zlib_1 = require("node:zlib");
|
|
5
|
-
const
|
|
6
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
8
|
const __1 = require("../..");
|
|
8
9
|
const colors_1 = require("../../colors/colors");
|
|
@@ -15,10 +16,10 @@ async function pipelineFromNDJsonFile(streams, opt) {
|
|
|
15
16
|
const { filePath, gzip, separator } = opt;
|
|
16
17
|
const started = Date.now();
|
|
17
18
|
let rows = 0;
|
|
18
|
-
const { size: sizeBytes } =
|
|
19
|
+
const { size: sizeBytes } = node_fs_1.default.statSync(filePath);
|
|
19
20
|
console.log(`<< ${(0, colors_1.grey)(filePath)} ${(0, colors_1.dimWhite)((0, js_lib_1._hb)(sizeBytes))} started...`);
|
|
20
21
|
await (0, __1._pipeline)([
|
|
21
|
-
|
|
22
|
+
node_fs_1.default.createReadStream(filePath),
|
|
22
23
|
...(gzip ? [(0, node_zlib_1.createUnzip)(opt.zlibOptions)] : []),
|
|
23
24
|
(0, __1.transformSplit)(separator),
|
|
24
25
|
(0, transformJsonParse_1.transformJsonParse)(opt),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pipelineToNDJsonFile = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const node_zlib_1 = require("node:zlib");
|
|
5
|
-
const
|
|
6
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
8
|
const __1 = require("../..");
|
|
8
9
|
const colors_1 = require("../../colors/colors");
|
|
@@ -27,9 +28,9 @@ async function pipelineToNDJsonFile(streams, opt) {
|
|
|
27
28
|
(0, __1.transformTap)(() => rows++),
|
|
28
29
|
(0, transformToNDJson_1.transformToNDJson)(opt),
|
|
29
30
|
...(gzip ? [(0, node_zlib_1.createGzip)(opt.zlibOptions)] : []),
|
|
30
|
-
|
|
31
|
+
node_fs_1.default.createWriteStream(filePath),
|
|
31
32
|
]);
|
|
32
|
-
const { size: sizeBytes } =
|
|
33
|
+
const { size: sizeBytes } = node_fs_1.default.statSync(filePath);
|
|
33
34
|
const stats = ndjson_model_1.NDJsonStats.create({
|
|
34
35
|
tookMillis: Date.now() - started,
|
|
35
36
|
rows,
|
package/dist/util/env.util.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requireFileToExist = exports.requireEnvKeys = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
require("dotenv/config"); // ensure .env is read before requiring keys
|
|
6
7
|
/**
|
|
7
8
|
* @example
|
|
@@ -22,7 +23,7 @@ function requireEnvKeys(...keys) {
|
|
|
22
23
|
}
|
|
23
24
|
exports.requireEnvKeys = requireEnvKeys;
|
|
24
25
|
function requireFileToExist(filePath) {
|
|
25
|
-
if (!
|
|
26
|
+
if (!node_fs_1.default.existsSync(filePath)) {
|
|
26
27
|
throw new Error(`Required file should exist: ${filePath}`);
|
|
27
28
|
}
|
|
28
29
|
}
|
package/dist/util/exec.util.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.execVoidCommandSync = exports.execVoidCommand = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
|
|
5
6
|
async function execVoidCommand(cmd, args = [], opt = {}) {
|
|
6
7
|
logExec(cmd, args, opt);
|
|
7
8
|
await new Promise(resolve => {
|
|
8
|
-
const p =
|
|
9
|
+
const p = node_child_process_1.default.spawn(cmd, [...args], {
|
|
9
10
|
stdio: 'inherit',
|
|
10
11
|
// shell: true,
|
|
11
12
|
...opt,
|
|
@@ -26,7 +27,7 @@ async function execVoidCommand(cmd, args = [], opt = {}) {
|
|
|
26
27
|
exports.execVoidCommand = execVoidCommand;
|
|
27
28
|
function execVoidCommandSync(cmd, args = [], opt = {}) {
|
|
28
29
|
logExec(cmd, args, opt);
|
|
29
|
-
const r =
|
|
30
|
+
const r = node_child_process_1.default.spawnSync(cmd, [...args], {
|
|
30
31
|
encoding: 'utf8',
|
|
31
32
|
stdio: 'inherit',
|
|
32
33
|
// shell: true, // removing shell breaks executing `tsc`
|
package/dist/util/git.util.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gitCurrentRepoName = exports.gitCurrentBranchName = exports.gitCurrentCommitTimestamp = exports.gitCurrentCommitSha = exports.gitPush = exports.gitPull = exports.gitIsAhead = exports.gitCommitAll = exports.gitHasUncommittedChanges = exports.commitMessageToTitleMessage = exports.getLastGitCommitMsg = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
7
|
const colors_1 = require("../colors/colors");
|
|
7
8
|
function getLastGitCommitMsg() {
|
|
8
9
|
return execSync('git log -1 --pretty=%B');
|
|
@@ -17,7 +18,7 @@ exports.commitMessageToTitleMessage = commitMessageToTitleMessage;
|
|
|
17
18
|
function gitHasUncommittedChanges() {
|
|
18
19
|
// git diff-index --quiet HEAD -- || echo "untracked"
|
|
19
20
|
try {
|
|
20
|
-
|
|
21
|
+
node_child_process_1.default.execSync('git diff-index --quiet HEAD --', {
|
|
21
22
|
encoding: 'utf8',
|
|
22
23
|
});
|
|
23
24
|
return false;
|
|
@@ -37,7 +38,7 @@ function gitCommitAll(msg) {
|
|
|
37
38
|
// const args = ['commit', '-a', '--no-verify', '-m', msg]
|
|
38
39
|
console.log((0, colors_1.grey)(cmd));
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
+
node_child_process_1.default.execSync(cmd, {
|
|
41
42
|
stdio: 'inherit',
|
|
42
43
|
});
|
|
43
44
|
return true;
|
|
@@ -61,7 +62,7 @@ exports.gitIsAhead = gitIsAhead;
|
|
|
61
62
|
function gitPull() {
|
|
62
63
|
const cmd = 'git pull';
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
node_child_process_1.default.execSync(cmd, {
|
|
65
66
|
stdio: 'inherit',
|
|
66
67
|
});
|
|
67
68
|
}
|
|
@@ -76,7 +77,7 @@ function gitPush() {
|
|
|
76
77
|
cmd += ` --set-upstream origin ${branchName}`;
|
|
77
78
|
}
|
|
78
79
|
console.log((0, colors_1.grey)(cmd));
|
|
79
|
-
|
|
80
|
+
node_child_process_1.default.execSync(cmd, {
|
|
80
81
|
stdio: 'inherit',
|
|
81
82
|
});
|
|
82
83
|
}
|
|
@@ -96,11 +97,11 @@ function gitCurrentBranchName() {
|
|
|
96
97
|
exports.gitCurrentBranchName = gitCurrentBranchName;
|
|
97
98
|
function gitCurrentRepoName() {
|
|
98
99
|
const originUrl = execSync('git config --get remote.origin.url');
|
|
99
|
-
return
|
|
100
|
+
return node_path_1.default.basename(originUrl, '.git');
|
|
100
101
|
}
|
|
101
102
|
exports.gitCurrentRepoName = gitCurrentRepoName;
|
|
102
103
|
function execSync(cmd) {
|
|
103
|
-
return
|
|
104
|
+
return node_child_process_1.default
|
|
104
105
|
.execSync(cmd, {
|
|
105
106
|
encoding: 'utf8',
|
|
106
107
|
// stdio: 'inherit', // no, otherwise we don't get the output returned
|
package/dist/util/zip.util.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gunzipToString = exports.gzipString = exports.gunzipBuffer = exports.gzipBuffer = exports.inflateToString = exports.deflateString = exports.inflateBuffer = exports.deflateBuffer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const node_util_1 = require("node:util");
|
|
5
|
-
const
|
|
6
|
-
const deflate = (0, node_util_1.promisify)(
|
|
7
|
-
const inflate = (0, node_util_1.promisify)(
|
|
8
|
-
const gzip = (0, node_util_1.promisify)(
|
|
9
|
-
const gunzip = (0, node_util_1.promisify)(
|
|
6
|
+
const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
|
|
7
|
+
const deflate = (0, node_util_1.promisify)(node_zlib_1.default.deflate.bind(node_zlib_1.default));
|
|
8
|
+
const inflate = (0, node_util_1.promisify)(node_zlib_1.default.inflate.bind(node_zlib_1.default));
|
|
9
|
+
const gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip.bind(node_zlib_1.default));
|
|
10
|
+
const gunzip = (0, node_util_1.promisify)(node_zlib_1.default.gunzip.bind(node_zlib_1.default));
|
|
10
11
|
// string > compressed buffer
|
|
11
12
|
/**
|
|
12
13
|
* deflateBuffer uses `deflate`.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAjv = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ajv_1 = tslib_1.__importDefault(require("ajv"));
|
|
5
6
|
const AJV_OPTIONS = {
|
|
6
7
|
removeAdditional: true,
|
|
7
8
|
allErrors: true,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Joi = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const joi_1 = tslib_1.__importDefault(require("joi"));
|
|
5
6
|
const number_extensions_1 = require("./number.extensions");
|
|
6
7
|
const string_extensions_1 = require("./string.extensions");
|
|
7
8
|
/**
|
|
8
9
|
* This is the only right place to import Joi from
|
|
9
10
|
*/
|
|
10
11
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
-
exports.Joi =
|
|
12
|
+
exports.Joi = joi_1.default.defaults(schema => {
|
|
12
13
|
// hack to prevent infinite recursion due to .empty('') where '' is a stringSchema itself
|
|
13
14
|
if (schema.type === 'string') {
|
|
14
15
|
return (schema
|