mybase 1.1.33 → 1.1.34

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 (124) hide show
  1. package/package.json +5 -1
  2. package/jest/isLANIp.test.js +0 -36
  3. package/jest/isLoopbackIP.test.js +0 -31
  4. package/jest.config.js +0 -6
  5. package/ts/funcs/Geoip2Paths.d.ts +0 -7
  6. package/ts/funcs/Geoip2Paths.js +0 -26
  7. package/ts/funcs/Geoip2Paths.test.ts +0 -11
  8. package/ts/funcs/Geoip2Paths.ts +0 -26
  9. package/ts/funcs/MaxRuntimeHours.d.ts +0 -1
  10. package/ts/funcs/MaxRuntimeHours.js +0 -11
  11. package/ts/funcs/MaxRuntimeHours.ts +0 -7
  12. package/ts/funcs/asJSON.d.ts +0 -1
  13. package/ts/funcs/asJSON.js +0 -14
  14. package/ts/funcs/asJSON.test.js +0 -72
  15. package/ts/funcs/asJSON.ts +0 -6
  16. package/ts/funcs/ensureFolder.d.ts +0 -3
  17. package/ts/funcs/ensureFolder.js +0 -50
  18. package/ts/funcs/ensureFolder.test.ts +0 -79
  19. package/ts/funcs/ensureFolder.ts +0 -21
  20. package/ts/funcs/fileCacheIsValid.d.ts +0 -1
  21. package/ts/funcs/fileCacheIsValid.js +0 -40
  22. package/ts/funcs/fileCacheIsValid.ts +0 -13
  23. package/ts/funcs/getMysql1.d.ts +0 -8
  24. package/ts/funcs/getMysql1.js +0 -62
  25. package/ts/funcs/getMysql1.ts +0 -41
  26. package/ts/funcs/getMysql2.d.ts +0 -9
  27. package/ts/funcs/getMysql2.js +0 -62
  28. package/ts/funcs/getMysql2.ts +0 -42
  29. package/ts/funcs/getWeekNumber.d.ts +0 -1
  30. package/ts/funcs/getWeekNumber.js +0 -36
  31. package/ts/funcs/getWeekNumber.test.ts +0 -9
  32. package/ts/funcs/getWeekNumber.ts +0 -31
  33. package/ts/funcs/hash_sha512.d.ts +0 -1
  34. package/ts/funcs/hash_sha512.js +0 -11
  35. package/ts/funcs/hash_sha512.ts +0 -7
  36. package/ts/funcs/initMysql2Pool.d.ts +0 -3
  37. package/ts/funcs/initMysql2Pool.js +0 -39
  38. package/ts/funcs/initMysql2Pool.ts +0 -11
  39. package/ts/funcs/int2ip.d.ts +0 -1
  40. package/ts/funcs/int2ip.js +0 -18
  41. package/ts/funcs/int2ip.test.js +0 -33
  42. package/ts/funcs/int2ip.ts +0 -9
  43. package/ts/funcs/ip2int.d.ts +0 -1
  44. package/ts/funcs/ip2int.js +0 -18
  45. package/ts/funcs/ip2int.test.js +0 -30
  46. package/ts/funcs/ip2int.ts +0 -10
  47. package/ts/funcs/isLANIp.d.ts +0 -4
  48. package/ts/funcs/isLANIp.js +0 -47
  49. package/ts/funcs/isLANIp.test.ts +0 -59
  50. package/ts/funcs/isLANIp.ts +0 -37
  51. package/ts/funcs/isLocal.d.ts +0 -1
  52. package/ts/funcs/isLocal.js +0 -12
  53. package/ts/funcs/isLocal.test.ts +0 -16
  54. package/ts/funcs/isLocal.ts +0 -5
  55. package/ts/funcs/isLoopbackIP.d.ts +0 -4
  56. package/ts/funcs/isLoopbackIP.js +0 -42
  57. package/ts/funcs/isLoopbackIP.test.ts +0 -72
  58. package/ts/funcs/isLoopbackIP.ts +0 -32
  59. package/ts/funcs/promiseTimeout.d.ts +0 -1
  60. package/ts/funcs/promiseTimeout.js +0 -19
  61. package/ts/funcs/promiseTimeout.test.js +0 -104
  62. package/ts/funcs/promiseTimeout.ts +0 -19
  63. package/ts/funcs/randomIP.d.ts +0 -1
  64. package/ts/funcs/randomIP.js +0 -11
  65. package/ts/funcs/randomIP.test.ts +0 -16
  66. package/ts/funcs/randomIP.ts +0 -10
  67. package/ts/funcs/randomIP6.d.ts +0 -1
  68. package/ts/funcs/randomIP6.js +0 -17
  69. package/ts/funcs/randomIP6.test.js +0 -18
  70. package/ts/funcs/randomIP6.ts +0 -12
  71. package/ts/funcs/randomString.d.ts +0 -1
  72. package/ts/funcs/randomString.js +0 -8
  73. package/ts/funcs/randomString.test.ts +0 -15
  74. package/ts/funcs/randomString.ts +0 -5
  75. package/ts/funcs/randomTCPPort.d.ts +0 -12
  76. package/ts/funcs/randomTCPPort.js +0 -88
  77. package/ts/funcs/randomTCPPort.test.ts +0 -62
  78. package/ts/funcs/randomTCPPort.ts +0 -58
  79. package/ts/funcs/randomUTFString.d.ts +0 -1
  80. package/ts/funcs/randomUTFString.js +0 -31
  81. package/ts/funcs/randomUTFString.test.ts +0 -44
  82. package/ts/funcs/randomUTFString.ts +0 -33
  83. package/ts/funcs/utcnow.d.ts +0 -2
  84. package/ts/funcs/utcnow.js +0 -8
  85. package/ts/funcs/utcnow.ts +0 -5
  86. package/ts/funcs/validEmail.d.ts +0 -1
  87. package/ts/funcs/validEmail.js +0 -21
  88. package/ts/funcs/validEmail.test.js +0 -31
  89. package/ts/funcs/validEmail.ts +0 -13
  90. package/ts/funcs/validIp.d.ts +0 -1
  91. package/ts/funcs/validIp.js +0 -32
  92. package/ts/funcs/validIp.test.ts +0 -33
  93. package/ts/funcs/validIp.ts +0 -5
  94. package/ts/funcs/vaultFill.d.ts +0 -2
  95. package/ts/funcs/vaultFill.js +0 -86
  96. package/ts/funcs/vaultFill.ts +0 -89
  97. package/ts/funcs/vaultRead.d.ts +0 -2
  98. package/ts/funcs/vaultRead.js +0 -52
  99. package/ts/funcs/vaultRead.ts +0 -45
  100. package/ts/funcs/wait.d.ts +0 -1
  101. package/ts/funcs/wait.js +0 -10
  102. package/ts/funcs/wait.ts +0 -7
  103. package/ts/global.d.ts +0 -1
  104. package/ts/global.js +0 -16
  105. package/ts/global.ts +0 -10
  106. package/ts/index.d.ts +0 -30
  107. package/ts/index.js +0 -48
  108. package/ts/index.test.ts +0 -7
  109. package/ts/index.ts +0 -33
  110. package/ts/models/IPAddress.d.ts +0 -40
  111. package/ts/models/IPAddress.js +0 -254
  112. package/ts/models/IPAddress.test.ts +0 -393
  113. package/ts/models/IPAddress.ts +0 -271
  114. package/ts/models/Timespan.d.ts +0 -18
  115. package/ts/models/Timespan.js +0 -52
  116. package/ts/models/Timespan.ts +0 -63
  117. package/ts/models/Unixtime.d.ts +0 -32
  118. package/ts/models/Unixtime.js +0 -137
  119. package/ts/models/Unixtime.test.ts +0 -102
  120. package/ts/models/Unixtime.ts +0 -164
  121. package/ts/types.d.ts +0 -1
  122. package/ts/types.js +0 -3
  123. package/ts/types.ts +0 -1
  124. package/tsconfig.json +0 -36
@@ -1,44 +0,0 @@
1
- import { randomUTFString } from './randomUTFString';
2
-
3
- describe('randomUTFString', () => {
4
- const asciiCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
5
- let extendedCharset =
6
- 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ' + // Accented Latin characters
7
- 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρσςτυφχψω' + // Greek
8
- 'אבגדהוזחטיךכלםמןנסעפצקרשת' + // Hebrew
9
- //Arabic
10
- 'ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي' +
11
- // Persian
12
- 'آ ا ب پ ت ث ج چ ح خ د ذ ر ز ژ س ش ص ض ط ظ ع غ ف ق ک گ ل م ن و ه ی' +
13
- // Turkish
14
- 'a b c ç d e f g ğ h ı i j k l m n o ö p r s ş t u ü v y z' +
15
- 'A B C Ç D E F G Ğ H I İ J K L M N O Ö P R S Ş T U Ü V Y Z' +
16
- // More Emojis
17
- '🙂🤔😍😂👍🚀❤️🎉' +
18
- 'абвгдежзийклмнопрстуфхцчшщъыьэюя' + // Cyrillic (Russian, etc.)
19
- '日本語中文한국어' + // Japanese, Chinese, Korean characters
20
- '🙂🤔😍😂👍🚀❤️🎉' // Emojis
21
- it('should generate a random string within the specified length range', () => {
22
- const minLength = 5;
23
- const maxLength = 10;
24
- const result = randomUTFString(minLength, maxLength);
25
- expect(result.length).toBeGreaterThanOrEqual(minLength);
26
- expect(result.length).toBeLessThanOrEqual(maxLength+1); // utf8 characters can be 1-4 bytes long
27
- });
28
-
29
- it('should include ASCII characters by default', () => {
30
- const result = randomUTFString(500, 400);
31
-
32
- expect(result).toMatch(new RegExp(`[${asciiCharacters}]`));
33
- });
34
-
35
- it('should exclude ASCII characters when includeAscii is set to false', () => {
36
- const result = randomUTFString(500, 1000, false);
37
- expect(result).not.toMatch(new RegExp(`[${asciiCharacters}]`));
38
- });
39
-
40
- it('should include extended characters when includeAscii is set to true', () => {
41
- const result = randomUTFString(500, 1000, true);
42
- expect(result).toMatch(new RegExp(`[${extendedCharset}]`));
43
- });
44
- });
@@ -1,33 +0,0 @@
1
-
2
-
3
-
4
- export function randomUTFString(minLength: number, maxLength: number, includeAscii:boolean=true): string {
5
- // Extended characters set including various languages and symbols
6
- let characters =
7
- 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ' + // Accented Latin characters
8
- 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρσςτυφχψω' + // Greek
9
- 'אבגדהוזחטיךכלםמןנסעפצקרשת' + // Hebrew
10
- //Arabic
11
- 'ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي' +
12
- // Persian
13
- 'آ ا ب پ ت ث ج چ ح خ د ذ ر ز ژ س ش ص ض ط ظ ع غ ف ق ک گ ل م ن و ه ی' +
14
- // Turkish
15
- 'ğıöşü' +
16
- 'ĞİÖŞÜ ' +
17
- // More Emojis
18
- '🙂🤔😍😂👍🚀❤️🎉' +
19
- 'бвгдежзийклмнопрстуфхцчшщъыьэюя' + // Cyrillic (Russian, etc.)
20
- '日本語中文한국어' + // Japanese, Chinese, Korean characters
21
- '🙂🤔😍😂👍🚀❤️🎉' // Emojis
22
-
23
- if (includeAscii) characters += 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
24
-
25
- const charactersLength = Array.from(characters).length
26
- const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength
27
- let result = ''
28
-
29
- for (let i = 0; i < length; i++)
30
- result += Array.from(characters)[Math.floor(Math.random() * charactersLength)]
31
-
32
- return result
33
- }
@@ -1,2 +0,0 @@
1
- import { UnixtimeShort } from '../types';
2
- export declare function utcnow(): UnixtimeShort;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.utcnow = void 0;
4
- function utcnow() {
5
- return Math.floor(Date.now() / 1000);
6
- }
7
- exports.utcnow = utcnow;
8
- //# sourceMappingURL=utcnow.js.map
@@ -1,5 +0,0 @@
1
- import { UnixtimeShort } from '../types'
2
-
3
- export function utcnow() : UnixtimeShort {
4
- return Math.floor(Date.now() / 1000)
5
- }
@@ -1 +0,0 @@
1
- export declare function validEmail(email: string): boolean;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validEmail = void 0;
7
- const validator_1 = __importDefault(require("validator"));
8
- function validEmail(email) {
9
- if (typeof email === 'string')
10
- return validator_1.default.isEmail(email); // validator needs a string
11
- return false;
12
- // giving up old style, was not reliable
13
- // taken from https://www.w3resource.com/javascript/form/email-validation.php
14
- // strange looking emails might be indeed valid
15
- // check https://www.w3resource.com/javascript/form/example-javascript-form-validation-email-REC-2822.html
16
- if (typeof email === 'string')
17
- email = email.toLowerCase().trim();
18
- return (/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/).test(email);
19
- }
20
- exports.validEmail = validEmail;
21
- //# sourceMappingURL=validEmail.js.map
@@ -1,31 +0,0 @@
1
- const { validEmail } = require('./validEmail')
2
-
3
- // since we use validator, we do not need to test it further
4
- // detailed tests with millions of emails are in tests/ folder which is .gitignored
5
-
6
- describe('validEmail', () => {
7
- test('should return true for a valid email', () => {
8
- const email = 'test@example.com'
9
- expect(validEmail(email)).toBe(true)
10
- })
11
-
12
- test('should return false for an invalid email', () => {
13
- const email = 'invalidemail'
14
- expect(validEmail(email)).toBe(false)
15
- })
16
-
17
- test('should return false for an empty email', () => {
18
- const email = ''
19
- expect(validEmail(email)).toBe(false)
20
- })
21
-
22
- test('should return false for a null email', () => {
23
- const email = null
24
- expect(validEmail(email)).toBe(false)
25
- })
26
-
27
- test('should return false for a non-string email', () => {
28
- const email = 12345
29
- expect(validEmail(email)).toBe(false)
30
- })
31
- })
@@ -1,13 +0,0 @@
1
- import validator from 'validator'
2
-
3
- export function validEmail(email:string) {
4
- if (typeof email==='string')
5
- return validator.isEmail(email) // validator needs a string
6
- return false
7
- // giving up old style, was not reliable
8
- // taken from https://www.w3resource.com/javascript/form/email-validation.php
9
- // strange looking emails might be indeed valid
10
- // check https://www.w3resource.com/javascript/form/example-javascript-form-validation-email-REC-2822.html
11
- if (typeof email==='string') email=email.toLowerCase().trim()
12
- return (/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/).test(email)
13
- }
@@ -1 +0,0 @@
1
- export declare function validIp(IPAddress: string): number;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.validIp = void 0;
27
- const net = __importStar(require("net"));
28
- function validIp(IPAddress) {
29
- return net.isIP(IPAddress);
30
- }
31
- exports.validIp = validIp;
32
- //# sourceMappingURL=validIp.js.map
@@ -1,33 +0,0 @@
1
- import { validIp } from './validIp';
2
-
3
- describe('validIp', () => {
4
- it('should return true for a valid IP address', () => {
5
- const ipAddress = '192.168.0.1';
6
- const result = validIp(ipAddress);
7
- expect(result).toBe(4);
8
- });
9
-
10
- it('should return false for an invalid IP address', () => {
11
- const ipAddress = '256.0.0.1';
12
- const result = validIp(ipAddress);
13
- expect(result).toBe(0);
14
- });
15
-
16
- it('should support IPv6', () => {
17
- const ipAddress = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
18
- const result = validIp(ipAddress);
19
- expect(result).toBe(6);
20
- })
21
-
22
- it('invalid IPv6', () => {
23
- const ipAddress = '2001:0db8:85a3:0000:0000:8a2e:0370:7334:0000';
24
- const result = validIp(ipAddress);
25
- expect(result).toBe(0);
26
- })
27
-
28
- it('should support IPv6 shorthand', () => {
29
- const ipAddress = '2001:db8:85a3::8a2e:370:7334';
30
- const result = validIp(ipAddress);
31
- expect(result).toBe(6);
32
- })
33
- })
@@ -1,5 +0,0 @@
1
- import * as net from 'net'
2
-
3
- export function validIp(IPAddress: string): number {
4
- return net.isIP(IPAddress)
5
- }
@@ -1,2 +0,0 @@
1
- import nodeVault from "node-vault";
2
- export declare function vaultFill(vaultInstance: nodeVault.client, inputObject: any, ignoreError?: boolean, keepCache?: boolean): Promise<unknown>;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vaultFill = void 0;
4
- const debug_1 = require("debug");
5
- const vaultRead_1 = require("./vaultRead");
6
- const dbg = (0, debug_1.debug)('vaultFill');
7
- function vaultFill(vaultInstance, inputObject, ignoreError = false, keepCache = true) {
8
- // v2.1
9
- // fills all strings with ^vault@/secret/... with proper vault values
10
- // if you call it again, it does reload the configuration
11
- // v2.2
12
- // supports keepCache - if vault fails, we will keep previous values instead of filling with false
13
- return new Promise(async function (resolve, reject) {
14
- let vaultKeys = Array();
15
- let vaultResults = {};
16
- findVaultKeyMappings(inputObject, vaultKeys);
17
- // read these keys from vault
18
- for (let idx in vaultKeys) {
19
- const val = vaultKeys[idx];
20
- if (typeof val !== "string")
21
- continue;
22
- try {
23
- let got = await (0, vaultRead_1.vaultRead)(vaultInstance, vaultKeys[idx]);
24
- got['__vaultkey'] = val;
25
- got['__vaultfilled'] = Date.now();
26
- vaultResults[val] = got;
27
- }
28
- catch (err) {
29
- dbg(`Could not read vaultKey '${val}'`, err);
30
- if (!ignoreError)
31
- vaultResults[val] = false;
32
- }
33
- }
34
- fillVaultKeyMappings(inputObject, vaultResults, keepCache);
35
- resolve(true);
36
- });
37
- }
38
- exports.vaultFill = vaultFill;
39
- function findVaultKeyMappings(config, keys = Array()) {
40
- for (var i in config) {
41
- if (config[i] !== null) {
42
- if (typeof config[i] === 'object' && (config[i].constructor.name === 'Array' || config[i].constructor.name === 'Object'))
43
- findVaultKeyMappings(config[i], keys);
44
- // detect previously read vaultKey
45
- if (i === '__vaultkey') {
46
- if (!keys.includes(vaultKey))
47
- keys.push(config[i]);
48
- continue;
49
- }
50
- // --
51
- if (typeof config[i] === 'string' && config[i].search(/^vault@/) == 0) {
52
- var splitted = config[i].split(/vault@/);
53
- if (splitted.length == 2) {
54
- var vaultKey = splitted[1];
55
- if (!keys.includes(vaultKey))
56
- keys.push(vaultKey);
57
- }
58
- }
59
- }
60
- }
61
- }
62
- function fillVaultKeyMappings(config, vaultResults, keepCache = true) {
63
- for (var i in config) {
64
- if (config[i] !== null) {
65
- if (config[i] && config[i].constructor.name === 'Object' && config[i].hasOwnProperty('__vaultkey')) {
66
- if (keepCache) {
67
- if (vaultResults[config[i]['__vaultkey']])
68
- config[i] = vaultResults[config[i]['__vaultkey']];
69
- }
70
- else
71
- config[i] = vaultResults[config[i]['__vaultkey']];
72
- continue;
73
- }
74
- if (typeof config[i] === 'object' && (config[i].constructor.name === 'Array' || config[i].constructor.name === 'Object'))
75
- fillVaultKeyMappings(config[i], vaultResults);
76
- if (typeof config[i] === 'string' && config[i].search(/^vault@/) == 0) {
77
- var splitted = config[i].split(/vault@/);
78
- if (splitted.length == 2) {
79
- var vaultKey = splitted[1];
80
- config[i] = vaultResults[vaultKey];
81
- }
82
- }
83
- }
84
- }
85
- }
86
- //# sourceMappingURL=vaultFill.js.map
@@ -1,89 +0,0 @@
1
- import { debug } from "debug"
2
- import nodeVault from "node-vault";
3
- import { vaultRead } from "./vaultRead";
4
- const dbg = debug('vaultFill')
5
-
6
- export function vaultFill(vaultInstance: nodeVault.client, inputObject: any, ignoreError = false, keepCache = true) {
7
- // v2.1
8
- // fills all strings with ^vault@/secret/... with proper vault values
9
- // if you call it again, it does reload the configuration
10
- // v2.2
11
- // supports keepCache - if vault fails, we will keep previous values instead of filling with false
12
- return new Promise(async function (resolve, reject) {
13
- let vaultKeys = Array<string>()
14
- let vaultResults: any = {}
15
- findVaultKeyMappings(inputObject, vaultKeys)
16
-
17
- // read these keys from vault
18
- for (let idx in vaultKeys) {
19
- const val = vaultKeys[idx]
20
- if (typeof val !== "string") continue
21
-
22
- try {
23
- let got = await vaultRead(vaultInstance, vaultKeys[idx])
24
- got['__vaultkey'] = val
25
- got['__vaultfilled'] = Date.now()
26
- vaultResults[val]=got
27
- }
28
- catch (err) {
29
-
30
- dbg(`Could not read vaultKey '${val}'`, err)
31
- if (!ignoreError) vaultResults[val]=false
32
- }
33
- }
34
-
35
- fillVaultKeyMappings(inputObject, vaultResults, keepCache)
36
-
37
- resolve(true)
38
- })
39
- }
40
-
41
-
42
- function findVaultKeyMappings(config: any, keys = Array<string>()) {
43
- for (var i in config) {
44
- if (config[i] !== null) {
45
- if (typeof config[i] === 'object' && (config[i].constructor.name === 'Array' || config[i].constructor.name === 'Object'))
46
- findVaultKeyMappings(config[i], keys)
47
-
48
- // detect previously read vaultKey
49
- if (i === '__vaultkey') {
50
- if (!keys.includes(vaultKey)) keys.push(config[i])
51
- continue
52
- }
53
- // --
54
- if (typeof config[i] === 'string' && config[i].search(/^vault@/) == 0) {
55
- var splitted = config[i].split(/vault@/)
56
- if (splitted.length == 2) {
57
- var vaultKey = splitted[1]
58
- if (!keys.includes(vaultKey)) keys.push(vaultKey)
59
- }
60
- }
61
- }
62
- }
63
- }
64
-
65
- function fillVaultKeyMappings(config: any, vaultResults:any, keepCache = true) {
66
- for (var i in config) {
67
- if (config[i] !== null) {
68
-
69
- if (config[i] && config[i].constructor.name === 'Object' && config[i].hasOwnProperty('__vaultkey')) {
70
- if (keepCache) {
71
- if (vaultResults[config[i]['__vaultkey']]) config[i] = vaultResults[config[i]['__vaultkey']]
72
- }
73
-
74
- else
75
- config[i] = vaultResults[config[i]['__vaultkey']]
76
- continue
77
- }
78
- if (typeof config[i] === 'object' && (config[i].constructor.name === 'Array' || config[i].constructor.name === 'Object'))
79
- fillVaultKeyMappings(config[i], vaultResults)
80
- if (typeof config[i] === 'string' && config[i].search(/^vault@/) == 0) {
81
- var splitted = config[i].split(/vault@/)
82
- if (splitted.length == 2) {
83
- var vaultKey = splitted[1]
84
- config[i] = vaultResults[vaultKey]
85
- }
86
- }
87
- }
88
- }
89
- }
@@ -1,2 +0,0 @@
1
- import nodeVault from "node-vault";
2
- export declare function vaultRead(vaultInstance: nodeVault.client, vaultKey: string, cache_in_minutes?: number): Promise<any>;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.vaultRead = void 0;
7
- const debug_1 = require("debug");
8
- const path_1 = __importDefault(require("path"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const node_fs_1 = require("node:fs");
11
- const fileCacheIsValid_1 = require("./fileCacheIsValid");
12
- const global_1 = require("../global");
13
- const hash_sha512_1 = require("./hash_sha512");
14
- const dbg = (0, debug_1.debug)('vaultRead');
15
- // need to implement it better
16
- function vaultRead(vaultInstance, vaultKey, cache_in_minutes = 10) {
17
- // v2 - supports caching
18
- return new Promise((resolve, reject) => {
19
- let cache_file = path_1.default.join(global_1.vault_cache_folder, (0, hash_sha512_1.hash_sha512)(`${vaultInstance.endpoint}/${vaultKey}`));
20
- if (cache_in_minutes > 0 && (0, fileCacheIsValid_1.fileCacheIsValid)(cache_file, cache_in_minutes))
21
- return resolve(JSON.parse((0, node_fs_1.readFileSync)(cache_file).toString()));
22
- vaultInstance.read(vaultKey).then((r) => {
23
- if (r.data) {
24
- dbg(`vault ${vaultKey} - success`);
25
- if (cache_in_minutes > 0)
26
- try {
27
- fs_1.default.writeFileSync(cache_file, JSON.stringify(r.data));
28
- fs_1.default.chmodSync(cache_file, 0o600);
29
- }
30
- catch (_) { }
31
- return resolve(r.data);
32
- }
33
- dbg(`vault ${vaultKey} - failed`);
34
- reject(r);
35
- }).catch(e => {
36
- dbg(`exception inside vaultRead`, e);
37
- // we will still return latest information from cache
38
- try {
39
- dbg(`returning vault@${vaultKey} from cache due to error`);
40
- if (fs_1.default.existsSync(cache_file))
41
- return resolve(JSON.parse(fs_1.default.readFileSync(cache_file).toString()));
42
- }
43
- catch (e2) {
44
- // content of the file is invalid
45
- console.log(e2);
46
- }
47
- reject(e);
48
- });
49
- });
50
- }
51
- exports.vaultRead = vaultRead;
52
- //# sourceMappingURL=vaultRead.js.map
@@ -1,45 +0,0 @@
1
- import { debug } from "debug"
2
- import nodeVault from "node-vault";
3
- import path from "path";
4
- import fs from "fs";
5
- import { readFileSync } from 'node:fs';
6
- import { fileCacheIsValid } from "./fileCacheIsValid";
7
- import { vault_cache_folder } from "../global";
8
- import { hash_sha512 } from "./hash_sha512";
9
- const dbg = debug('vaultRead')
10
-
11
- // need to implement it better
12
-
13
- export function vaultRead(vaultInstance: nodeVault.client, vaultKey: string, cache_in_minutes = 10) : Promise<any> {
14
- // v2 - supports caching
15
- return new Promise((resolve, reject) => {
16
- let cache_file = path.join(vault_cache_folder, hash_sha512(`${vaultInstance.endpoint}/${vaultKey}`))
17
-
18
- if (cache_in_minutes > 0 && fileCacheIsValid(cache_file, cache_in_minutes))
19
- return resolve(JSON.parse(readFileSync(cache_file as string).toString()))
20
-
21
- vaultInstance.read(vaultKey).then((r) => {
22
- if (r.data) {
23
- dbg(`vault ${vaultKey} - success`)
24
- if (cache_in_minutes > 0)
25
- try { fs.writeFileSync(cache_file, JSON.stringify(r.data)); fs.chmodSync(cache_file, 0o600); } catch (_) { }
26
- return resolve(r.data);
27
- }
28
- dbg(`vault ${vaultKey} - failed`)
29
- reject(r);
30
- }).catch(e => {
31
- dbg(`exception inside vaultRead`, e)
32
- // we will still return latest information from cache
33
- try {
34
- dbg(`returning vault@${vaultKey} from cache due to error`)
35
- if (fs.existsSync(cache_file))
36
- return resolve(JSON.parse(fs.readFileSync(cache_file as string).toString()))
37
- } catch (e2) {
38
- // content of the file is invalid
39
- console.log(e2)
40
- }
41
-
42
- reject(e);
43
- })
44
- })
45
- }
@@ -1 +0,0 @@
1
- export declare function wait(seconds?: number): Promise<void>;
package/ts/funcs/wait.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wait = void 0;
4
- function wait(seconds = 1) {
5
- return new Promise((resolve, reject) => {
6
- setTimeout(resolve, seconds * 1000);
7
- });
8
- }
9
- exports.wait = wait;
10
- //# sourceMappingURL=wait.js.map
package/ts/funcs/wait.ts DELETED
@@ -1,7 +0,0 @@
1
-
2
-
3
- export function wait(seconds=1) : Promise<void> {
4
- return new Promise((resolve,reject)=>{
5
- setTimeout(resolve,seconds*1000)
6
- })
7
- }
package/ts/global.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare let vault_cache_folder: string;
package/ts/global.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.vault_cache_folder = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- exports.vault_cache_folder = '/var/tmp/vault-cache';
9
- try {
10
- if (!fs_1.default.existsSync(exports.vault_cache_folder))
11
- fs_1.default.mkdirSync(exports.vault_cache_folder);
12
- }
13
- catch (e) {
14
- console.log(e);
15
- }
16
- //# sourceMappingURL=global.js.map
package/ts/global.ts DELETED
@@ -1,10 +0,0 @@
1
- import fs from 'fs'
2
-
3
- export let vault_cache_folder = '/var/tmp/vault-cache'
4
-
5
- try {
6
- if (!fs.existsSync(vault_cache_folder))
7
- fs.mkdirSync(vault_cache_folder)
8
- } catch(e) {
9
- console.log(e)
10
- }
package/ts/index.d.ts DELETED
@@ -1,30 +0,0 @@
1
- export * from "./funcs/getWeekNumber";
2
- export * from "./funcs/Geoip2Paths";
3
- export * from "./funcs/isLocal";
4
- export * from "./funcs/randomString";
5
- export * from "./funcs/utcnow";
6
- export * from "./funcs/validIp";
7
- export * from "./funcs/wait";
8
- export * from "./funcs/fileCacheIsValid";
9
- export * from "./funcs/hash_sha512";
10
- export * from "./funcs/vaultRead";
11
- export * from "./funcs/vaultFill";
12
- export * from "./funcs/asJSON";
13
- export * from "./funcs/promiseTimeout";
14
- export * from "./funcs/randomIP";
15
- export * from "./funcs/ip2int";
16
- export * from "./funcs/int2ip";
17
- export * from "./funcs/randomIP6";
18
- export * from "./funcs/randomTCPPort";
19
- export * from "./funcs/validEmail";
20
- export * from "./funcs/isLoopbackIP";
21
- export * from "./funcs/isLANIp";
22
- export * from "./funcs/getMysql1";
23
- export * from "./funcs/getMysql2";
24
- export * from "./funcs/initMysql2Pool";
25
- export * from "./funcs/randomUTFString";
26
- export * from "./funcs/MaxRuntimeHours";
27
- export * from "./funcs/ensureFolder";
28
- export * from "./models/Unixtime";
29
- export * from "./models/Timespan";
30
- export * from "./models/IPAddress";