@naturalcycles/nodejs-lib 12.103.2 → 13.0.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.
Files changed (70) hide show
  1. package/dist/bin/del.js +2 -2
  2. package/dist/bin/generate-build-info.js +6 -6
  3. package/dist/bin/json2env.js +4 -4
  4. package/dist/bin/kpy.js +2 -2
  5. package/dist/bin/secrets-decrypt.js +8 -7
  6. package/dist/bin/secrets-encrypt.js +9 -8
  7. package/dist/bin/secrets-gen-key.js +3 -3
  8. package/dist/bin/slack-this.js +2 -2
  9. package/dist/colors/colors.d.ts +28 -0
  10. package/dist/colors/colors.js +33 -1
  11. package/dist/fs/del.js +1 -1
  12. package/dist/fs/fs.util.d.ts +136 -23
  13. package/dist/fs/fs.util.js +53 -25
  14. package/dist/fs/json2env.d.ts +4 -0
  15. package/dist/fs/json2env.js +16 -5
  16. package/dist/fs/kpy.js +1 -1
  17. package/dist/index.d.ts +4 -1
  18. package/dist/index.js +4 -1
  19. package/dist/secret/secrets-decrypt.util.d.ts +3 -2
  20. package/dist/secret/secrets-decrypt.util.js +7 -5
  21. package/dist/secret/secrets-encrypt.util.d.ts +3 -2
  22. package/dist/secret/secrets-encrypt.util.js +4 -4
  23. package/dist/security/crypto.util.d.ts +22 -12
  24. package/dist/security/crypto.util.js +33 -23
  25. package/dist/security/secret.util.js +4 -2
  26. package/dist/stream/ndjson/ndjson.model.js +1 -1
  27. package/dist/stream/ndjson/pipelineFromNDJsonFile.js +1 -1
  28. package/dist/stream/ndjson/pipelineToNDJsonFile.js +1 -1
  29. package/dist/stream/sizeStack.js +1 -1
  30. package/dist/stream/transform/transformLogProgress.js +2 -3
  31. package/dist/stream/transform/transformMap.js +1 -1
  32. package/dist/stream/transform/transformMapSync.js +1 -1
  33. package/dist/util/git.util.js +1 -1
  34. package/package.json +1 -1
  35. package/readme.md +1 -1
  36. package/src/bin/del.ts +1 -1
  37. package/src/bin/generate-build-info.ts +2 -2
  38. package/src/bin/json2env.ts +2 -2
  39. package/src/bin/kpy.ts +1 -1
  40. package/src/bin/secrets-decrypt.ts +8 -6
  41. package/src/bin/secrets-encrypt.ts +9 -7
  42. package/src/bin/secrets-gen-key.ts +2 -2
  43. package/src/bin/slack-this.ts +1 -1
  44. package/src/colors/colors.ts +35 -0
  45. package/src/fs/del.ts +1 -1
  46. package/src/fs/fs.util.ts +53 -30
  47. package/src/fs/json2env.ts +15 -4
  48. package/src/fs/kpy.ts +1 -1
  49. package/src/index.ts +4 -1
  50. package/src/secret/secrets-decrypt.util.ts +9 -6
  51. package/src/secret/secrets-encrypt.util.ts +5 -5
  52. package/src/security/crypto.util.ts +34 -24
  53. package/src/security/secret.util.ts +4 -2
  54. package/src/stream/ndjson/ndjson.model.ts +1 -1
  55. package/src/stream/ndjson/pipelineFromNDJsonFile.ts +1 -1
  56. package/src/stream/ndjson/pipelineToNDJsonFile.ts +1 -1
  57. package/src/stream/sizeStack.ts +1 -1
  58. package/src/stream/transform/transformLogProgress.ts +1 -2
  59. package/src/stream/transform/transformMap.ts +1 -1
  60. package/src/stream/transform/transformMapSync.ts +1 -1
  61. package/src/util/git.util.ts +1 -1
  62. package/dist/colors/index.d.ts +0 -28
  63. package/dist/colors/index.js +0 -35
  64. package/dist/fs/index.d.ts +0 -3
  65. package/dist/fs/index.js +0 -6
  66. package/src/colors/index.ts +0 -35
  67. package/src/fs/index.ts +0 -3
  68. /package/dist/script/{index.d.ts → runScript.d.ts} +0 -0
  69. /package/dist/script/{index.js → runScript.js} +0 -0
  70. /package/src/script/{index.ts → runScript.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -78,8 +78,11 @@ export * from './validation/joi/joi.model';
78
78
  export * from './validation/joi/joi.shared.schemas';
79
79
  export * from './validation/joi/joi.validation.error';
80
80
  export * from './validation/joi/joi.validation.util';
81
- export * from './script';
81
+ export * from './script/runScript';
82
82
  export * from './jwt/jwt.service';
83
83
  export * from './fs/fs.util';
84
+ export * from './fs/del';
85
+ export * from './fs/json2env';
86
+ export * from './fs/kpy';
84
87
  export type { GlobbyOptions, FastGlobOptions, ValidationErrorItem, Got, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema, };
85
88
  export { globby, fastGlob, RequestError, TimeoutError, Ajv };
package/dist/index.js CHANGED
@@ -83,6 +83,9 @@ tslib_1.__exportStar(require("./validation/joi/joi.model"), exports);
83
83
  tslib_1.__exportStar(require("./validation/joi/joi.shared.schemas"), exports);
84
84
  tslib_1.__exportStar(require("./validation/joi/joi.validation.error"), exports);
85
85
  tslib_1.__exportStar(require("./validation/joi/joi.validation.util"), exports);
86
- tslib_1.__exportStar(require("./script"), exports);
86
+ tslib_1.__exportStar(require("./script/runScript"), exports);
87
87
  tslib_1.__exportStar(require("./jwt/jwt.service"), exports);
88
88
  tslib_1.__exportStar(require("./fs/fs.util"), exports);
89
+ tslib_1.__exportStar(require("./fs/del"), exports);
90
+ tslib_1.__exportStar(require("./fs/json2env"), exports);
91
+ tslib_1.__exportStar(require("./fs/kpy"), exports);
@@ -1,7 +1,8 @@
1
+ /// <reference types="node" />
1
2
  export interface DecryptCLIOptions {
2
3
  dir: string[];
3
4
  file?: string;
4
- encKey: string;
5
+ encKeyBuffer: Buffer;
5
6
  del?: boolean;
6
7
  jsonMode?: boolean;
7
8
  }
@@ -9,4 +10,4 @@ export interface DecryptCLIOptions {
9
10
  * Decrypts all files in given directory (*.enc), saves decrypted versions without ending `.enc`.
10
11
  * Using provided encKey.
11
12
  */
12
- export declare function secretsDecrypt(dir: string[], file: string | undefined, encKey: string, del?: boolean, jsonMode?: boolean): void;
13
+ export declare function secretsDecrypt(dir: string[], file: string | undefined, encKeyBuffer: Buffer, del?: boolean, jsonMode?: boolean): void;
@@ -4,17 +4,19 @@ exports.secretsDecrypt = void 0;
4
4
  const path = require("node:path");
5
5
  const fs = require("node:fs");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
- const colors_1 = require("../colors");
7
+ const colors_1 = require("../colors/colors");
8
8
  const index_1 = require("../index");
9
9
  const crypto_util_1 = require("../security/crypto.util");
10
10
  // Debug it like this:
11
- // yarn tsn ./src/bin/secrets-decrypt.ts --file ./src/test/secrets2.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
12
11
  // yarn tsn ./src/bin/secrets-encrypt.ts --file ./src/test/secrets2.plain.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
12
+ // yarn tsn ./src/bin/secrets-decrypt.ts --file ./src/test/secrets2.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
13
+ // yarn tsn ./src/bin/secrets-encrypt.ts --file ./src/test/secrets.json -encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
14
+ // yarn tsn ./src/bin/secrets-decrypt.ts --file ./src/test/secrets.json.enc -encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
13
15
  /**
14
16
  * Decrypts all files in given directory (*.enc), saves decrypted versions without ending `.enc`.
15
17
  * Using provided encKey.
16
18
  */
17
- function secretsDecrypt(dir, file, encKey, del = false, jsonMode = false) {
19
+ function secretsDecrypt(dir, file, encKeyBuffer, del = false, jsonMode = false) {
18
20
  // If `file` is provided - only this one file is used
19
21
  const patterns = file ? [file] : dir.map(d => `${d}/**/*.enc`);
20
22
  const filenames = index_1.fastGlob.sync(patterns);
@@ -24,12 +26,12 @@ function secretsDecrypt(dir, file, encKey, del = false, jsonMode = false) {
24
26
  (0, js_lib_1._assert)(filename.endsWith('.json'), `${path.basename(filename)} MUST end with '.json'`);
25
27
  (0, js_lib_1._assert)(!filename.endsWith('.plain.json'), `${path.basename(filename)} MUST NOT end with '.plain.json'`);
26
28
  plainFilename = filename.replace('.json', '.plain.json');
27
- const json = (0, crypto_util_1.decryptObject)((0, index_1._readJsonSync)(filename), encKey);
29
+ const json = (0, crypto_util_1.decryptObject)((0, index_1._readJsonSync)(filename), encKeyBuffer);
28
30
  (0, index_1._writeJsonSync)(plainFilename, json, { spaces: 2 });
29
31
  }
30
32
  else {
31
33
  const enc = fs.readFileSync(filename);
32
- const plain = (0, crypto_util_1.decryptRandomIVBuffer)(enc, encKey);
34
+ const plain = (0, crypto_util_1.decryptRandomIVBuffer)(enc, encKeyBuffer);
33
35
  plainFilename = filename.slice(0, filename.length - '.enc'.length);
34
36
  fs.writeFileSync(plainFilename, plain);
35
37
  }
@@ -1,7 +1,8 @@
1
+ /// <reference types="node" />
1
2
  export interface EncryptCLIOptions {
2
3
  pattern: string[];
3
4
  file?: string;
4
- encKey: string;
5
+ encKeyBuffer: Buffer;
5
6
  del?: boolean;
6
7
  jsonMode?: boolean;
7
8
  }
@@ -9,4 +10,4 @@ export interface EncryptCLIOptions {
9
10
  * Encrypts all files in given directory (except *.enc), saves encrypted versions as filename.ext.enc.
10
11
  * Using provided encKey.
11
12
  */
12
- export declare function secretsEncrypt(pattern: string[], file: string | undefined, encKey: string, del?: boolean, jsonMode?: boolean): void;
13
+ export declare function secretsEncrypt(pattern: string[], file: string | undefined, encKeyBuffer: Buffer, del?: boolean, jsonMode?: boolean): void;
@@ -4,14 +4,14 @@ exports.secretsEncrypt = void 0;
4
4
  const fs = require("node:fs");
5
5
  const path = require("node:path");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
- const colors_1 = require("../colors");
7
+ const colors_1 = require("../colors/colors");
8
8
  const index_1 = require("../index");
9
9
  const crypto_util_1 = require("../security/crypto.util");
10
10
  /**
11
11
  * Encrypts all files in given directory (except *.enc), saves encrypted versions as filename.ext.enc.
12
12
  * Using provided encKey.
13
13
  */
14
- function secretsEncrypt(pattern, file, encKey, del = false, jsonMode = false) {
14
+ function secretsEncrypt(pattern, file, encKeyBuffer, del = false, jsonMode = false) {
15
15
  const patterns = file
16
16
  ? [file]
17
17
  : [
@@ -24,12 +24,12 @@ function secretsEncrypt(pattern, file, encKey, del = false, jsonMode = false) {
24
24
  if (jsonMode) {
25
25
  (0, js_lib_1._assert)(filename.endsWith('.plain.json'), `${path.basename(filename)} MUST end with '.plain.json'`);
26
26
  encFilename = filename.replace('.plain', '');
27
- const json = (0, crypto_util_1.encryptObject)((0, index_1._readJsonSync)(filename), encKey);
27
+ const json = (0, crypto_util_1.encryptObject)((0, index_1._readJsonSync)(filename), encKeyBuffer);
28
28
  (0, index_1._writeJsonSync)(encFilename, json, { spaces: 2 });
29
29
  }
30
30
  else {
31
31
  const plain = fs.readFileSync(filename);
32
- const enc = (0, crypto_util_1.encryptRandomIVBuffer)(plain, encKey);
32
+ const enc = (0, crypto_util_1.encryptRandomIVBuffer)(plain, encKeyBuffer);
33
33
  encFilename = `${filename}.enc`;
34
34
  fs.writeFileSync(encFilename, enc);
35
35
  }
@@ -1,24 +1,34 @@
1
1
  /// <reference types="node" />
2
2
  import { Base64String, StringMap } from '@naturalcycles/js-lib';
3
3
  /**
4
- * Using aes-256-cbc
4
+ * Using aes-256-cbc.
5
5
  */
6
- export declare function encryptRandomIVBuffer(input: Buffer, secretKeyBase64: Base64String): Buffer;
6
+ export declare function encryptRandomIVBuffer(input: Buffer, secretKeyBuffer: Buffer): Buffer;
7
7
  /**
8
- * Using aes-256-cbc
8
+ * Using aes-256-cbc.
9
9
  */
10
- export declare function decryptRandomIVBuffer(input: Buffer, secretKeyBase64: Base64String): Buffer;
10
+ export declare function decryptRandomIVBuffer(input: Buffer, secretKeyBuffer: Buffer): Buffer;
11
11
  /**
12
- * Decrypts all object values.
13
- * Returns object with decrypted values.
12
+ * Decrypts all object values (base64 strings).
13
+ * Returns object with decrypted values (utf8 strings).
14
14
  */
15
- export declare function decryptObject(obj: StringMap<Base64String>, secretKey: string): StringMap;
16
- export declare function encryptObject(obj: StringMap, secretKey: string): StringMap<Base64String>;
15
+ export declare function decryptObject(obj: StringMap<Base64String>, secretKeyBuffer: Buffer): StringMap;
17
16
  /**
18
- * Using aes-256-cbc
17
+ * Encrypts all object values (utf8 strings).
18
+ * Returns object with encrypted values (base64 strings).
19
19
  */
20
- export declare function decryptString(str: Base64String, secretKey: string): string;
20
+ export declare function encryptObject(obj: StringMap, secretKeyBuffer: Buffer): StringMap<Base64String>;
21
21
  /**
22
- * Using aes-256-cbc
22
+ * Using aes-256-cbc.
23
+ *
24
+ * Input is base64 string.
25
+ * Output is utf8 string.
23
26
  */
24
- export declare function encryptString(str: string, secretKey: string): Base64String;
27
+ export declare function decryptString(str: Base64String, secretKeyBuffer: Buffer): string;
28
+ /**
29
+ * Using aes-256-cbc.
30
+ *
31
+ * Input is utf8 string.
32
+ * Output is base64 string.
33
+ */
34
+ export declare function encryptString(str: string, secretKeyBuffer: Buffer): Base64String;
@@ -6,11 +6,11 @@ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const hash_util_1 = require("./hash.util");
7
7
  const algorithm = 'aes-256-cbc';
8
8
  /**
9
- * Using aes-256-cbc
9
+ * Using aes-256-cbc.
10
10
  */
11
- function encryptRandomIVBuffer(input, secretKeyBase64) {
12
- // md5 to match aes-256 key length of 32 bytes
13
- const key = (0, hash_util_1.md5)(Buffer.from(secretKeyBase64, 'base64'));
11
+ function encryptRandomIVBuffer(input, secretKeyBuffer) {
12
+ // sha256 to match aes-256 key length
13
+ const key = (0, hash_util_1.sha256AsBuffer)(secretKeyBuffer);
14
14
  // Random iv to achieve non-deterministic encryption (but deterministic decryption)
15
15
  const iv = crypto.randomBytes(16);
16
16
  const cipher = crypto.createCipheriv(algorithm, key, iv);
@@ -18,11 +18,11 @@ function encryptRandomIVBuffer(input, secretKeyBase64) {
18
18
  }
19
19
  exports.encryptRandomIVBuffer = encryptRandomIVBuffer;
20
20
  /**
21
- * Using aes-256-cbc
21
+ * Using aes-256-cbc.
22
22
  */
23
- function decryptRandomIVBuffer(input, secretKeyBase64) {
24
- // md5 to match aes-256 key length of 32 bytes
25
- const key = (0, hash_util_1.md5)(Buffer.from(secretKeyBase64, 'base64'));
23
+ function decryptRandomIVBuffer(input, secretKeyBuffer) {
24
+ // sha256 to match aes-256 key length
25
+ const key = (0, hash_util_1.sha256AsBuffer)(secretKeyBuffer);
26
26
  // iv is first 16 bytes of encrypted buffer, the rest is payload
27
27
  const iv = input.subarray(0, 16);
28
28
  const payload = input.subarray(16);
@@ -31,11 +31,11 @@ function decryptRandomIVBuffer(input, secretKeyBase64) {
31
31
  }
32
32
  exports.decryptRandomIVBuffer = decryptRandomIVBuffer;
33
33
  /**
34
- * Decrypts all object values.
35
- * Returns object with decrypted values.
34
+ * Decrypts all object values (base64 strings).
35
+ * Returns object with decrypted values (utf8 strings).
36
36
  */
37
- function decryptObject(obj, secretKey) {
38
- const { key, iv } = getCryptoParams(secretKey);
37
+ function decryptObject(obj, secretKeyBuffer) {
38
+ const { key, iv } = getCryptoParams(secretKeyBuffer);
39
39
  const r = {};
40
40
  (0, js_lib_1._stringMapEntries)(obj).forEach(([k, v]) => {
41
41
  const decipher = crypto.createDecipheriv(algorithm, key, iv);
@@ -44,8 +44,12 @@ function decryptObject(obj, secretKey) {
44
44
  return r;
45
45
  }
46
46
  exports.decryptObject = decryptObject;
47
- function encryptObject(obj, secretKey) {
48
- const { key, iv } = getCryptoParams(secretKey);
47
+ /**
48
+ * Encrypts all object values (utf8 strings).
49
+ * Returns object with encrypted values (base64 strings).
50
+ */
51
+ function encryptObject(obj, secretKeyBuffer) {
52
+ const { key, iv } = getCryptoParams(secretKeyBuffer);
49
53
  const r = {};
50
54
  (0, js_lib_1._stringMapEntries)(obj).forEach(([k, v]) => {
51
55
  const cipher = crypto.createCipheriv(algorithm, key, iv);
@@ -55,25 +59,31 @@ function encryptObject(obj, secretKey) {
55
59
  }
56
60
  exports.encryptObject = encryptObject;
57
61
  /**
58
- * Using aes-256-cbc
62
+ * Using aes-256-cbc.
63
+ *
64
+ * Input is base64 string.
65
+ * Output is utf8 string.
59
66
  */
60
- function decryptString(str, secretKey) {
61
- const { key, iv } = getCryptoParams(secretKey);
67
+ function decryptString(str, secretKeyBuffer) {
68
+ const { key, iv } = getCryptoParams(secretKeyBuffer);
62
69
  const decipher = crypto.createDecipheriv(algorithm, key, iv);
63
70
  return decipher.update(str, 'base64', 'utf8') + decipher.final('utf8');
64
71
  }
65
72
  exports.decryptString = decryptString;
66
73
  /**
67
- * Using aes-256-cbc
74
+ * Using aes-256-cbc.
75
+ *
76
+ * Input is utf8 string.
77
+ * Output is base64 string.
68
78
  */
69
- function encryptString(str, secretKey) {
70
- const { key, iv } = getCryptoParams(secretKey);
79
+ function encryptString(str, secretKeyBuffer) {
80
+ const { key, iv } = getCryptoParams(secretKeyBuffer);
71
81
  const cipher = crypto.createCipheriv(algorithm, key, iv);
72
82
  return cipher.update(str, 'utf8', 'base64') + cipher.final('base64');
73
83
  }
74
84
  exports.encryptString = encryptString;
75
- function getCryptoParams(secretKey) {
76
- const key = (0, hash_util_1.md5)(secretKey);
77
- const iv = (0, hash_util_1.md5)(secretKey + key).slice(0, 16);
85
+ function getCryptoParams(secretKeyBuffer) {
86
+ const key = (0, hash_util_1.sha256AsBuffer)(secretKeyBuffer);
87
+ const iv = (0, hash_util_1.md5AsBuffer)(Buffer.concat([secretKeyBuffer, key]));
78
88
  return { key, iv };
79
89
  }
@@ -48,7 +48,8 @@ function loadSecretsFromEncryptedJsonFile(filePath, secretEncryptionKey) {
48
48
  let secrets;
49
49
  if (secretEncryptionKey) {
50
50
  const buf = fs.readFileSync(filePath);
51
- const plain = (0, crypto_util_1.decryptRandomIVBuffer)(buf, secretEncryptionKey).toString('utf8');
51
+ const encKeyBuffer = Buffer.from(secretEncryptionKey, 'base64');
52
+ const plain = (0, crypto_util_1.decryptRandomIVBuffer)(buf, encKeyBuffer).toString('utf8');
52
53
  secrets = JSON.parse(plain);
53
54
  }
54
55
  else {
@@ -69,7 +70,8 @@ function loadSecretsFromEncryptedJsonFileValues(filePath, secretEncryptionKey) {
69
70
  (0, js_lib_1._assert)(fs.existsSync(filePath), `loadSecretsFromEncryptedJsonFileValues() cannot load from path: ${filePath}`);
70
71
  let secrets = JSON.parse(fs.readFileSync(filePath, 'utf8'));
71
72
  if (secretEncryptionKey) {
72
- secrets = (0, crypto_util_1.decryptObject)(secrets, secretEncryptionKey);
73
+ const encKeyBuffer = Buffer.from(secretEncryptionKey, 'base64');
74
+ secrets = (0, crypto_util_1.decryptObject)(secrets, encKeyBuffer);
73
75
  }
74
76
  Object.entries(secrets).forEach(([k, v]) => (secretMap[k.toUpperCase()] = v));
75
77
  loaded = true;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NDJsonStats = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const colors_1 = require("../../colors");
5
+ const colors_1 = require("../../colors/colors");
6
6
  class NDJsonStats {
7
7
  constructor() {
8
8
  this.tookMillis = 0;
@@ -5,7 +5,7 @@ const node_zlib_1 = require("node:zlib");
5
5
  const fs = require("node:fs");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const __1 = require("../..");
8
- const colors_1 = require("../../colors");
8
+ const colors_1 = require("../../colors/colors");
9
9
  const ndjson_model_1 = require("./ndjson.model");
10
10
  const transformJsonParse_1 = require("./transformJsonParse");
11
11
  /**
@@ -5,7 +5,7 @@ const node_zlib_1 = require("node:zlib");
5
5
  const fs = require("node:fs");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const __1 = require("../..");
8
- const colors_1 = require("../../colors");
8
+ const colors_1 = require("../../colors/colors");
9
9
  const ndjson_model_1 = require("./ndjson.model");
10
10
  const transformToNDJson_1 = require("./transformToNDJson");
11
11
  /**
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SizeStack = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const colors_1 = require("../colors");
5
+ const colors_1 = require("../colors/colors");
6
6
  const zip_util_1 = require("../util/zip.util");
7
7
  class SizeStack extends js_lib_1.NumberStack {
8
8
  constructor(name, size) {
@@ -4,11 +4,10 @@ exports.transformLogProgress = void 0;
4
4
  const node_stream_1 = require("node:stream");
5
5
  const node_util_1 = require("node:util");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
- const colors_1 = require("../../colors");
8
- const colors_2 = require("../../colors/colors");
7
+ const colors_1 = require("../../colors/colors");
9
8
  const sizeStack_1 = require("../sizeStack");
10
9
  const inspectOpt = {
11
- colors: colors_2.hasColors,
10
+ colors: colors_1.hasColors,
12
11
  breakLength: 300,
13
12
  };
14
13
  /**
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformMap = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const through2Concurrent = require("through2-concurrent");
6
- const colors_1 = require("../../colors");
6
+ const colors_1 = require("../../colors/colors");
7
7
  const stream_util_1 = require("../stream.util");
8
8
  // doesn't work, cause here we don't construct our Transform instance ourselves
9
9
  // export class TransformMap extends AbortableTransform {}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformMapSync = exports.TransformMapSync = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const colors_1 = require("../../colors");
5
+ const colors_1 = require("../../colors/colors");
6
6
  const pipeline_1 = require("../pipeline/pipeline");
7
7
  const stream_util_1 = require("../stream.util");
8
8
  class TransformMapSync extends pipeline_1.AbortableTransform {
@@ -3,7 +3,7 @@ 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
4
  const cp = require("node:child_process");
5
5
  const path = require("node:path");
6
- const colors_1 = require("../colors");
6
+ const colors_1 = require("../colors/colors");
7
7
  function getLastGitCommitMsg() {
8
8
  return execSync('git log -1 --pretty=%B');
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.103.2",
3
+ "version": "13.0.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
package/readme.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![Maintainability](https://api.codeclimate.com/v1/badges/119a3b4735c4ed81cf84/maintainability)](https://codeclimate.com/github/NaturalCycles/nodejs-lib/maintainability)
9
9
  [![Test Coverage](https://api.codeclimate.com/v1/badges/119a3b4735c4ed81cf84/test_coverage)](https://codeclimate.com/github/NaturalCycles/nodejs-lib/test_coverage)
10
10
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
11
- [![Actions](https://github.com/NaturalCycles/nodejs-lib/workflows/default/badge.svg)](https://github.com/NaturalCycles/nodejs-lib/actions)
11
+ [![Actions](https://github.com/NaturalCycles/nodejs-lib/workflows/ci/badge.svg)](https://github.com/NaturalCycles/nodejs-lib/actions)
12
12
 
13
13
  # [Documentation](https://naturalcycles.github.io/nodejs-lib/)
14
14
 
package/src/bin/del.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as yargs from 'yargs'
4
4
  import { delSync } from '../fs/del'
5
- import { runScript } from '../script'
5
+ import { runScript } from '../script/runScript'
6
6
 
7
7
  runScript(async () => {
8
8
  const { _: patterns, ...opt } = yargs.demandCommand(1).options({
@@ -3,8 +3,8 @@
3
3
  import * as fs from 'node:fs'
4
4
  import * as path from 'node:path'
5
5
  import * as yargs from 'yargs'
6
- import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs'
7
- import { runScript } from '../script'
6
+ import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs/json2env'
7
+ import { runScript } from '../script/runScript'
8
8
  import { generateBuildInfo } from '../util/buildInfo.util'
9
9
 
10
10
  runScript(async () => {
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import * as yargs from 'yargs'
4
- import { json2env } from '../fs'
5
- import { runScript } from '../script'
4
+ import { json2env } from '../fs/json2env'
5
+ import { runScript } from '../script/runScript'
6
6
 
7
7
  runScript(() => {
8
8
  const { argv } = yargs.demandCommand(1).options({
package/src/bin/kpy.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as yargs from 'yargs'
4
4
  import { kpySync } from '../fs/kpy'
5
- import { runScript } from '../script'
5
+ import { runScript } from '../script/runScript'
6
6
 
7
7
  runScript(() => {
8
8
  const {
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import * as yargs from 'yargs'
4
- import { dimGrey } from '../colors'
5
- import { runScript } from '../script'
4
+ import { dimGrey } from '../colors/colors'
5
+ import { runScript } from '../script/runScript'
6
6
  import { DecryptCLIOptions, secretsDecrypt } from '../secret/secrets-decrypt.util'
7
7
 
8
8
  runScript(() => {
9
- const { dir, file, encKey, del, jsonMode } = getDecryptCLIOptions()
9
+ const { dir, file, encKeyBuffer, del, jsonMode } = getDecryptCLIOptions()
10
10
 
11
- secretsDecrypt(dir, file, encKey, del, jsonMode)
11
+ secretsDecrypt(dir, file, encKeyBuffer, del, jsonMode)
12
12
  })
13
13
 
14
14
  function getDecryptCLIOptions(): DecryptCLIOptions {
@@ -27,7 +27,7 @@ function getDecryptCLIOptions(): DecryptCLIOptions {
27
27
  },
28
28
  encKey: {
29
29
  type: 'string',
30
- desc: 'Encryption key',
30
+ desc: 'Encryption key as base64 encoded string',
31
31
  // demandOption: true,
32
32
  // default: process.env.SECRET_ENCRYPTION_KEY!,
33
33
  },
@@ -63,6 +63,8 @@ function getDecryptCLIOptions(): DecryptCLIOptions {
63
63
  }
64
64
  }
65
65
 
66
+ const encKeyBuffer = Buffer.from(encKey, 'base64')
67
+
66
68
  // `as any` because @types/yargs can't handle string[] type properly
67
- return { dir: dir as any, file, encKey, del, jsonMode }
69
+ return { dir: dir as any, file, encKeyBuffer, del, jsonMode }
68
70
  }
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import * as yargs from 'yargs'
4
- import { dimGrey } from '../colors'
5
- import { runScript } from '../script'
4
+ import { dimGrey } from '../colors/colors'
5
+ import { runScript } from '../script/runScript'
6
6
  import { EncryptCLIOptions, secretsEncrypt } from '../secret/secrets-encrypt.util'
7
7
 
8
8
  runScript(() => {
9
- const { pattern, file, encKey, del, jsonMode } = getEncryptCLIOptions()
9
+ const { pattern, file, encKeyBuffer, del, jsonMode } = getEncryptCLIOptions()
10
10
 
11
- secretsEncrypt(pattern, file, encKey, del, jsonMode)
11
+ secretsEncrypt(pattern, file, encKeyBuffer, del, jsonMode)
12
12
  })
13
13
 
14
14
  function getEncryptCLIOptions(): EncryptCLIOptions {
@@ -18,7 +18,7 @@ function getEncryptCLIOptions(): EncryptCLIOptions {
18
18
  pattern: {
19
19
  type: 'string',
20
20
  array: true,
21
- desc: 'Globby pattern for secrets. Can be many.',
21
+ desc: 'Globby pattern for secrets. Can be multiple.',
22
22
  // demandOption: true,
23
23
  default: './secret/**',
24
24
  },
@@ -28,7 +28,7 @@ function getEncryptCLIOptions(): EncryptCLIOptions {
28
28
  },
29
29
  encKey: {
30
30
  type: 'string',
31
- desc: 'Encryption key',
31
+ desc: 'Encryption key as base64 encoded string',
32
32
  // demandOption: true,
33
33
  // default: process.env.SECRET_ENCRYPTION_KEY!,
34
34
  },
@@ -65,6 +65,8 @@ function getEncryptCLIOptions(): EncryptCLIOptions {
65
65
  }
66
66
  }
67
67
 
68
+ const encKeyBuffer = Buffer.from(encKey, 'base64')
69
+
68
70
  // `as any` because @types/yargs can't handle string[] type properly
69
- return { pattern: pattern as any, file, encKey, del, jsonMode }
71
+ return { pattern: pattern as any, file, encKeyBuffer, del, jsonMode }
70
72
  }
@@ -2,8 +2,8 @@
2
2
 
3
3
  import * as crypto from 'node:crypto'
4
4
  import * as yargs from 'yargs'
5
- import { dimGrey } from '../colors'
6
- import { runScript } from '../script'
5
+ import { dimGrey } from '../colors/colors'
6
+ import { runScript } from '../script/runScript'
7
7
 
8
8
  runScript(() => {
9
9
  const { sizeBytes } = yargs.option('sizeBytes', {
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as yargs from 'yargs'
4
4
  import { SlackService } from '..'
5
- import { runScript } from '../script'
5
+ import { runScript } from '../script/runScript'
6
6
 
7
7
  runScript(async () => {
8
8
  const {
@@ -1,4 +1,7 @@
1
1
  import * as tty from 'node:tty'
2
+ import * as chalk from 'chalk'
3
+
4
+ export { chalk }
2
5
 
3
6
  /**
4
7
  * Based on: https://github.com/sindresorhus/yoctocolors/pull/5
@@ -6,3 +9,35 @@ import * as tty from 'node:tty'
6
9
  * @experimental
7
10
  */
8
11
  export const hasColors = !process.env['NO_COLOR'] && tty.WriteStream.prototype.hasColors()
12
+
13
+ // The point of re-exporting is:
14
+ // 1. Fix typings to allow to pass `number` (very common case)
15
+ // 2. Easier/shorter to import, rather than from 'chalk'
16
+ // export type ColorFn = (...args: (string | number)[]) => string
17
+
18
+ export const white = chalk.white
19
+ export const dimWhite = chalk.dim.white
20
+ export const boldWhite = chalk.bold.white
21
+ export const inverseWhite = chalk.inverse.white
22
+ export const grey = chalk.grey
23
+ export const dimGrey = chalk.dim.grey
24
+ export const boldGrey = chalk.bold.grey
25
+ export const yellow = chalk.yellow
26
+ export const dimYellow = chalk.dim.yellow
27
+ export const boldYellow = chalk.bold.yellow
28
+ export const inverseYellow = chalk.inverse.yellow
29
+ export const green = chalk.green
30
+ export const dimGreen = chalk.dim.green
31
+ export const boldGreen = chalk.bold.green
32
+ export const red = chalk.red
33
+ export const dimRed = chalk.dim.red
34
+ export const boldRed = chalk.bold.red
35
+ export const blue = chalk.blue
36
+ export const dimBlue = chalk.dim.blue
37
+ export const boldBlue = chalk.bold.blue
38
+ export const magenta = chalk.magenta
39
+ export const dimMagenta = chalk.dim.magenta
40
+ export const boldMagenta = chalk.bold.magenta
41
+ export const cyan = chalk.cyan
42
+ export const dimCyan = chalk.dim.cyan
43
+ export const boldCyan = chalk.bold.cyan
package/src/fs/del.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as fs from 'node:fs'
2
2
  import * as fsp from 'node:fs/promises'
3
3
  import { pFilter, pMap, _since } from '@naturalcycles/js-lib'
4
- import { dimGrey, yellow } from '../colors'
4
+ import { dimGrey, yellow } from '../colors/colors'
5
5
  import { _pathExists, _pathExistsSync, globby } from '../index'
6
6
 
7
7
  export interface DelOptions {