mybase 1.1.44 → 1.1.46

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 (44) hide show
  1. package/README.md +6 -0
  2. package/mybase.js +1 -0
  3. package/package.json +1 -1
  4. package/ts/funcs/Geoip2Paths.js +1 -2
  5. package/ts/funcs/MaxRuntimeHours.js +1 -2
  6. package/ts/funcs/asJSON.js +1 -2
  7. package/ts/funcs/ensureFolder.d.ts +0 -1
  8. package/ts/funcs/ensureFolder.js +18 -9
  9. package/ts/funcs/fileCacheIsValid.js +18 -9
  10. package/ts/funcs/getMysql1.js +18 -9
  11. package/ts/funcs/getMysql2.js +18 -9
  12. package/ts/funcs/getWeekNumber.js +1 -2
  13. package/ts/funcs/hash_sha512.js +1 -2
  14. package/ts/funcs/initMysql2Pool.js +18 -9
  15. package/ts/funcs/int2ip.js +1 -2
  16. package/ts/funcs/ip2int.js +1 -2
  17. package/ts/funcs/isLANIp.d.ts +0 -1
  18. package/ts/funcs/isLANIp.js +2 -2
  19. package/ts/funcs/isLocal.js +1 -2
  20. package/ts/funcs/isLoopbackIP.d.ts +0 -1
  21. package/ts/funcs/isLoopbackIP.js +2 -2
  22. package/ts/funcs/knexConnection.js +1 -2
  23. package/ts/funcs/promiseTimeout.js +1 -2
  24. package/ts/funcs/randomIP.js +1 -2
  25. package/ts/funcs/randomIP6.js +1 -2
  26. package/ts/funcs/randomString.js +1 -2
  27. package/ts/funcs/randomTCPPort.js +18 -9
  28. package/ts/funcs/randomUTFString.js +1 -2
  29. package/ts/funcs/utcnow.js +1 -2
  30. package/ts/funcs/validEmail.js +1 -2
  31. package/ts/funcs/validIp.js +18 -9
  32. package/ts/funcs/vaultFill.js +1 -2
  33. package/ts/funcs/vaultRead.js +3 -4
  34. package/ts/funcs/vaultRead.ts +1 -1
  35. package/ts/funcs/wait.js +1 -2
  36. package/ts/index.d.ts +1 -0
  37. package/ts/index.js +1 -0
  38. package/ts/index.ts +2 -1
  39. package/ts/models/IPAddress.d.ts +0 -1
  40. package/ts/models/Interfaces.d.ts +16 -0
  41. package/ts/models/Interfaces.js +48 -0
  42. package/ts/models/Interfaces.ts +58 -0
  43. package/ts/models/OTPGenerator.js +17 -7
  44. package/tsconfig.tsbuildinfo +1 -0
package/README.md CHANGED
@@ -11,6 +11,12 @@ import { UnixtimeShort } from 'mybase/ts/types'
11
11
  var { isLocal } = require('mybase')
12
12
  ```
13
13
 
14
+ ## Models
15
+ - Interfaces
16
+ - Unixtime
17
+ - Timespan
18
+ - OTPGenerator
19
+ - IPAddress
14
20
 
15
21
  # Methods
16
22
  `vaultRead(vaultHandle,key) <Promise>` : Reads Vault Key
package/mybase.js CHANGED
@@ -118,6 +118,7 @@ function utcnow() { // ported
118
118
  }
119
119
 
120
120
  function validIp(str) { // ported
121
+ console.log(`WARNING: validIp is deprecated, use validIpNative or IPAddress model`)
121
122
  if (str && typeof str==='string') {
122
123
  let splitted
123
124
  if (splitted=str.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mybase",
3
- "version": "1.1.44",
3
+ "version": "1.1.46",
4
4
  "description": "",
5
5
  "main": "mybase.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Geoip2Paths = void 0;
6
+ exports.Geoip2Paths = Geoip2Paths;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  function Geoip2Paths() {
@@ -22,5 +22,4 @@ function Geoip2Paths() {
22
22
  ct: firstExisting(['/opt/geoip2/GeoIP2-Connection-Type.mmdb', '/usr/local/var/GeoIP/GeoIP2-Connection-Type.mmdb', '/var/lib/GeoIP/GeoIP2-Connection-Type.mmdb', '/usr/share/GeoIP/GeoIP2-Connection-Type.mmdb', path_1.default.join(__dirname, 'assets/GeoIP2-Connection-Type.mmdb'), path_1.default.join(((_d = require === null || require === void 0 ? void 0 : require.main) === null || _d === void 0 ? void 0 : _d.path) || __dirname, 'assets/GeoIP2-Connection-Type.mmdb')]),
23
23
  };
24
24
  }
25
- exports.Geoip2Paths = Geoip2Paths;
26
25
  //# sourceMappingURL=Geoip2Paths.js.map
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MaxRuntimeHours = void 0;
3
+ exports.MaxRuntimeHours = MaxRuntimeHours;
4
4
  function MaxRuntimeHours(hours = 24) {
5
5
  setTimeout(() => {
6
6
  console.log(`Max runtime of ${hours} hours reached, exiting`);
7
7
  process.exit(0);
8
8
  }, hours * 60 * 60 * 1000);
9
9
  }
10
- exports.MaxRuntimeHours = MaxRuntimeHours;
11
10
  //# sourceMappingURL=MaxRuntimeHours.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asJSON = void 0;
3
+ exports.asJSON = asJSON;
4
4
  function asJSON(inputString) {
5
5
  if (!inputString || typeof inputString !== 'string')
6
6
  return false;
@@ -10,5 +10,4 @@ function asJSON(inputString) {
10
10
  catch (_) { }
11
11
  return false;
12
12
  }
13
- exports.asJSON = asJSON;
14
13
  //# sourceMappingURL=asJSON.js.map
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import { MakeDirectoryOptions } from 'fs';
3
2
  export declare function ensureFolder(folderPath: string, options?: MakeDirectoryOptions | null): string;
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ensureFolder = void 0;
39
+ exports.ensureFolder = ensureFolder;
30
40
  const debug_1 = __importDefault(require("debug"));
31
41
  const fs = __importStar(require("fs"));
32
42
  const dbg = (0, debug_1.default)('_mybase:ensureFolder');
@@ -46,5 +56,4 @@ function ensureFolder(folderPath, options) {
46
56
  fs.mkdirSync(folderPath, options);
47
57
  return folderPath;
48
58
  }
49
- exports.ensureFolder = ensureFolder;
50
59
  //# sourceMappingURL=ensureFolder.js.map
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.fileCacheIsValid = void 0;
36
+ exports.fileCacheIsValid = fileCacheIsValid;
27
37
  const fs = __importStar(require("fs"));
28
38
  function fileCacheIsValid(cacheFileName, cache_in_minutes = 60) {
29
39
  if (fs.existsSync(cacheFileName)) {
@@ -36,5 +46,4 @@ function fileCacheIsValid(cacheFileName, cache_in_minutes = 60) {
36
46
  }
37
47
  return false;
38
48
  }
39
- exports.fileCacheIsValid = fileCacheIsValid;
40
49
  //# sourceMappingURL=fileCacheIsValid.js.map
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getMysql1 = void 0;
39
+ exports.getMysql1 = getMysql1;
30
40
  const mysql1 = __importStar(require("mysql"));
31
41
  const debug_1 = __importDefault(require("debug"));
32
42
  const dbg = (0, debug_1.default)("getMysql1");
@@ -58,5 +68,4 @@ async function getMysql1(config, pingInterval = 0) {
58
68
  });
59
69
  });
60
70
  }
61
- exports.getMysql1 = getMysql1;
62
71
  //# sourceMappingURL=getMysql1.js.map
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getMysql2 = void 0;
39
+ exports.getMysql2 = getMysql2;
30
40
  const mysql2 = __importStar(require("mysql2"));
31
41
  const debug_1 = __importDefault(require("debug"));
32
42
  const dbg = (0, debug_1.default)("getMysql2");
@@ -58,5 +68,4 @@ async function getMysql2(config, pingInterval = 0) {
58
68
  });
59
69
  });
60
70
  }
61
- exports.getMysql2 = getMysql2;
62
71
  //# sourceMappingURL=getMysql2.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWeekNumber = void 0;
3
+ exports.getWeekNumber = getWeekNumber;
4
4
  // credit: https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
5
5
  /* For a given date, get the ISO week number
6
6
 
@@ -32,5 +32,4 @@ function getWeekNumber(d = new Date()) {
32
32
  // Return the week number
33
33
  return weekNo;
34
34
  }
35
- exports.getWeekNumber = getWeekNumber;
36
35
  //# sourceMappingURL=getWeekNumber.js.map
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hash_sha512 = void 0;
3
+ exports.hash_sha512 = hash_sha512;
4
4
  const js_sha512_1 = require("js-sha512");
5
5
  function hash_sha512(plainString) {
6
6
  if (typeof plainString === 'string')
7
7
  return (0, js_sha512_1.sha512)(plainString);
8
8
  return "";
9
9
  }
10
- exports.hash_sha512 = hash_sha512;
11
10
  //# sourceMappingURL=hash_sha512.js.map
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.initMysql2Pool = void 0;
39
+ exports.initMysql2Pool = initMysql2Pool;
30
40
  const mysql2 = __importStar(require("mysql2"));
31
41
  const debug_1 = __importDefault(require("debug"));
32
42
  const dbg = (0, debug_1.default)("initMysql2Pool");
@@ -35,5 +45,4 @@ function initMysql2Pool(sqlServer) {
35
45
  dbg(`creating mysql pool to ${sqlServer.host}@${sqlServer.db} as connectionUri=${connectionUri}`);
36
46
  return mysql2.createPool(connectionUri);
37
47
  }
38
- exports.initMysql2Pool = initMysql2Pool;
39
48
  //# sourceMappingURL=initMysql2Pool.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.int2ip = void 0;
6
+ exports.int2ip = int2ip;
7
7
  const net_1 = __importDefault(require("net"));
8
8
  //we only support ipv4
9
9
  function int2ip(ipInt) {
@@ -14,5 +14,4 @@ function int2ip(ipInt) {
14
14
  throw new Error(`Invalid IP: ${ip4}`);
15
15
  return ip4;
16
16
  }
17
- exports.int2ip = int2ip;
18
17
  //# sourceMappingURL=int2ip.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ip2int = void 0;
6
+ exports.ip2int = ip2int;
7
7
  const net_1 = __importDefault(require("net"));
8
8
  // function int2ip (ipInt) {
9
9
  // return ( (ipInt>>>24) +'.' + (ipInt>>16 & 255) +'.' + (ipInt>>8 & 255) +'.' + (ipInt & 255) );
@@ -14,5 +14,4 @@ function ip2int(ip) {
14
14
  throw new Error(`Invalid IP: ${ip}`);
15
15
  return ip.split('.').reduce(function (ipInt, octet) { return (ipInt << 8) + parseInt(octet, 10); }, 0) >>> 0;
16
16
  }
17
- exports.ip2int = ip2int;
18
17
  //# sourceMappingURL=ip2int.js.map
@@ -1,4 +1,3 @@
1
- /// <reference types="@root/ip6addr" />
2
1
  import ip6addr from 'ip6addr';
3
2
  export declare const private_network_cidrs: ip6addr.CIDR[];
4
3
  export declare function isLANIp(ip: string): boolean;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isLANIp = exports.private_network_cidrs = void 0;
6
+ exports.private_network_cidrs = void 0;
7
+ exports.isLANIp = isLANIp;
7
8
  const ip6addr_1 = __importDefault(require("ip6addr"));
8
9
  const net_1 = __importDefault(require("net"));
9
10
  exports.private_network_cidrs = [
@@ -35,7 +36,6 @@ function isLANIp(ip) {
35
36
  }
36
37
  return false;
37
38
  }
38
- exports.isLANIp = isLANIp;
39
39
  function normalizeIp(ip) {
40
40
  // also support ipv6
41
41
  if (net_1.default.isIP(ip) === 0)
@@ -3,10 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isLocal = void 0;
6
+ exports.isLocal = isLocal;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  function isLocal() {
9
9
  return (os_1.default.type() === 'Darwin');
10
10
  }
11
- exports.isLocal = isLocal;
12
11
  //# sourceMappingURL=isLocal.js.map
@@ -1,4 +1,3 @@
1
- /// <reference types="@root/ip6addr" />
2
1
  import ip6addr from 'ip6addr';
3
2
  export declare const local_network_cidrs: ip6addr.CIDR[];
4
3
  export declare function isLoopbackIP(ip: string): boolean;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isLoopbackIP = exports.local_network_cidrs = void 0;
6
+ exports.local_network_cidrs = void 0;
7
+ exports.isLoopbackIP = isLoopbackIP;
7
8
  const ip6addr_1 = __importDefault(require("ip6addr"));
8
9
  const net_1 = __importDefault(require("net"));
9
10
  exports.local_network_cidrs = [
@@ -30,7 +31,6 @@ function isLoopbackIP(ip) {
30
31
  }
31
32
  return false;
32
33
  }
33
- exports.isLoopbackIP = isLoopbackIP;
34
34
  function normalizeIp(ip) {
35
35
  // also support ipv6
36
36
  if (net_1.default.isIP(ip) === 0)
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.knexConnection = void 0;
6
+ exports.knexConnection = knexConnection;
7
7
  const debug_1 = __importDefault(require("debug"));
8
8
  const knex_1 = __importDefault(require("knex"));
9
9
  const dbg = (0, debug_1.default)('_knexConnection');
@@ -40,5 +40,4 @@ function knexConnection(connection, poolConfiguration = {
40
40
  }
41
41
  });
42
42
  }
43
- exports.knexConnection = knexConnection;
44
43
  //# sourceMappingURL=knexConnection.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promiseTimeout = void 0;
3
+ exports.promiseTimeout = promiseTimeout;
4
4
  function promiseTimeout(miliseconds, inputPromise, onTimeout = 'TIMEDOUT') {
5
5
  // Create a promise that rejects in <miliseconds> milliseconds
6
6
  let timeout = new Promise((resolve, reject) => {
@@ -15,5 +15,4 @@ function promiseTimeout(miliseconds, inputPromise, onTimeout = 'TIMEDOUT') {
15
15
  timeout
16
16
  ]);
17
17
  }
18
- exports.promiseTimeout = promiseTimeout;
19
18
  //# sourceMappingURL=promiseTimeout.js.map
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomIP = void 0;
3
+ exports.randomIP = randomIP;
4
4
  function randomIP() {
5
5
  function int2ip(ipInt) {
6
6
  return ((ipInt >>> 24) + '.' + (ipInt >> 16 & 255) + '.' + (ipInt >> 8 & 255) + '.' + (ipInt & 255));
7
7
  }
8
8
  return int2ip(Math.random() * Math.pow(2, 32));
9
9
  }
10
- exports.randomIP = randomIP;
11
10
  //# sourceMappingURL=randomIP.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.randomIP6 = void 0;
6
+ exports.randomIP6 = randomIP6;
7
7
  const crypto_1 = require("crypto");
8
8
  // const ip6 = require('ip6')
9
9
  //@ts-ignore
@@ -13,5 +13,4 @@ function randomIP6() {
13
13
  const bytes = (0, crypto_1.randomBytes)(16);
14
14
  return ip6_1.default.abbreviate(ip6_1.default.normalize(((_a = bytes.toString('hex').match(/.{1,4}/g)) === null || _a === void 0 ? void 0 : _a.join(':')) || '0000:0000:0000:0000:0000:0000:0000:0000'));
15
15
  }
16
- exports.randomIP6 = randomIP6;
17
16
  //# sourceMappingURL=randomIP6.js.map
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomString = void 0;
3
+ exports.randomString = randomString;
4
4
  function randomString(length = 10, charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
5
5
  return Array.from({ length }, () => charSet.charAt(Math.floor(Math.random() * charSet.length))).join('');
6
6
  }
7
- exports.randomString = randomString;
8
7
  //# sourceMappingURL=randomString.js.map
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.randomTCPPort = void 0;
36
+ exports.randomTCPPort = randomTCPPort;
27
37
  const net = __importStar(require("net"));
28
38
  /**
29
39
  * This function returns a random port number that is not in use and we should validate this port number by trying to listen to it and releasing
@@ -84,5 +94,4 @@ async function randomTCPPort(timeout = 1000, fromPort = 1025, untilPort = 65534,
84
94
  return resolve(false);
85
95
  });
86
96
  }
87
- exports.randomTCPPort = randomTCPPort;
88
97
  //# sourceMappingURL=randomTCPPort.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomUTFString = void 0;
3
+ exports.randomUTFString = randomUTFString;
4
4
  function randomUTFString(minLength, maxLength, includeAscii = true) {
5
5
  // Extended characters set including various languages and symbols
6
6
  let characters = 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ' + // Accented Latin characters
@@ -27,5 +27,4 @@ function randomUTFString(minLength, maxLength, includeAscii = true) {
27
27
  result += Array.from(characters)[Math.floor(Math.random() * charactersLength)];
28
28
  return result;
29
29
  }
30
- exports.randomUTFString = randomUTFString;
31
30
  //# sourceMappingURL=randomUTFString.js.map
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.utcnow = void 0;
3
+ exports.utcnow = utcnow;
4
4
  function utcnow() {
5
5
  return Math.floor(Date.now() / 1000);
6
6
  }
7
- exports.utcnow = utcnow;
8
7
  //# sourceMappingURL=utcnow.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validEmail = void 0;
6
+ exports.validEmail = validEmail;
7
7
  const validator_1 = __importDefault(require("validator"));
8
8
  function validEmail(email) {
9
9
  if (typeof email === 'string')
@@ -17,5 +17,4 @@ function validEmail(email) {
17
17
  email = email.toLowerCase().trim();
18
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
19
  }
20
- exports.validEmail = validEmail;
21
20
  //# sourceMappingURL=validEmail.js.map
@@ -15,18 +15,27 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.validIp = void 0;
36
+ exports.validIp = validIp;
27
37
  const net = __importStar(require("net"));
28
38
  function validIp(IPAddress) {
29
39
  return net.isIP(IPAddress);
30
40
  }
31
- exports.validIp = validIp;
32
41
  //# sourceMappingURL=validIp.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vaultFill = void 0;
3
+ exports.vaultFill = vaultFill;
4
4
  const debug_1 = require("debug");
5
5
  const vaultRead_1 = require("./vaultRead");
6
6
  const dbg = (0, debug_1.debug)('vaultFill');
@@ -35,7 +35,6 @@ function vaultFill(vaultInstance, inputObject, ignoreError = false, keepCache =
35
35
  resolve(true);
36
36
  });
37
37
  }
38
- exports.vaultFill = vaultFill;
39
38
  function findVaultKeyMappings(config, keys = Array()) {
40
39
  for (var i in config) {
41
40
  if (config[i] !== null) {
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.vaultRead = void 0;
6
+ exports.vaultRead = vaultRead;
7
7
  const debug_1 = require("debug");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
- const node_fs_1 = require("node:fs");
10
+ const fs_2 = require("fs");
11
11
  const fileCacheIsValid_1 = require("./fileCacheIsValid");
12
12
  const global_1 = require("../global");
13
13
  const hash_sha512_1 = require("./hash_sha512");
@@ -18,7 +18,7 @@ function vaultRead(vaultInstance, vaultKey, cache_in_minutes = 10) {
18
18
  return new Promise((resolve, reject) => {
19
19
  let cache_file = path_1.default.join(global_1.vault_cache_folder, (0, hash_sha512_1.hash_sha512)(`${vaultInstance.endpoint}/${vaultKey}`));
20
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()));
21
+ return resolve(JSON.parse((0, fs_2.readFileSync)(cache_file).toString()));
22
22
  vaultInstance.read(vaultKey).then((r) => {
23
23
  if (r.data) {
24
24
  dbg(`vault ${vaultKey} - success`);
@@ -48,5 +48,4 @@ function vaultRead(vaultInstance, vaultKey, cache_in_minutes = 10) {
48
48
  });
49
49
  });
50
50
  }
51
- exports.vaultRead = vaultRead;
52
51
  //# sourceMappingURL=vaultRead.js.map
@@ -2,7 +2,7 @@ import { debug } from "debug"
2
2
  import nodeVault from "node-vault";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
- import { readFileSync } from 'node:fs';
5
+ import { readFileSync } from 'fs';
6
6
  import { fileCacheIsValid } from "./fileCacheIsValid";
7
7
  import { vault_cache_folder } from "../global";
8
8
  import { hash_sha512 } from "./hash_sha512";
package/ts/funcs/wait.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wait = void 0;
3
+ exports.wait = wait;
4
4
  function wait(seconds = 1) {
5
5
  return new Promise((resolve, reject) => {
6
6
  setTimeout(resolve, seconds * 1000);
7
7
  });
8
8
  }
9
- exports.wait = wait;
10
9
  //# sourceMappingURL=wait.js.map
package/ts/index.d.ts CHANGED
@@ -30,3 +30,4 @@ export * from "./models/Unixtime";
30
30
  export * from "./models/Timespan";
31
31
  export * from "./models/IPAddress";
32
32
  export * from "./models/OTPGenerator";
33
+ export * from "./models/Interfaces";
package/ts/index.js CHANGED
@@ -47,4 +47,5 @@ __exportStar(require("./models/Unixtime"), exports);
47
47
  __exportStar(require("./models/Timespan"), exports);
48
48
  __exportStar(require("./models/IPAddress"), exports);
49
49
  __exportStar(require("./models/OTPGenerator"), exports);
50
+ __exportStar(require("./models/Interfaces"), exports);
50
51
  //# sourceMappingURL=index.js.map
package/ts/index.ts CHANGED
@@ -28,10 +28,11 @@ export * from "./funcs/ensureFolder"
28
28
  export * from "./funcs/knexConnection"
29
29
 
30
30
 
31
+
31
32
  // models
32
33
  export * from "./models/Unixtime"
33
34
  export * from "./models/Timespan"
34
35
  export * from "./models/IPAddress"
35
36
  export * from "./models/OTPGenerator"
36
-
37
+ export * from "./models/Interfaces"
37
38
 
@@ -1,4 +1,3 @@
1
- /// <reference types="@root/ip6addr" />
2
1
  import ip6addr, { ToStringOpts } from 'ip6addr';
3
2
  export declare class IPAddress {
4
3
  private _ip;
@@ -0,0 +1,16 @@
1
+ interface NetworkInterfaceInfo {
2
+ name: string;
3
+ ipv4: string[];
4
+ ipv6: string[];
5
+ }
6
+ export declare class Interfaces {
7
+ static findByName(name: string): NetworkInterfaceInfo | null;
8
+ static findByNamePrefix(prefix: string): NetworkInterfaceInfo[];
9
+ static findByIp(ip: string): NetworkInterfaceInfo | null;
10
+ static asApiServerConfig(ifaces: string[], port: number): {
11
+ ip: string;
12
+ port: number;
13
+ }[];
14
+ static getInterfaces(): NetworkInterfaceInfo[];
15
+ }
16
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Interfaces = void 0;
4
+ const os_1 = require("os");
5
+ class Interfaces {
6
+ static findByName(name) {
7
+ const ifaces = this.getInterfaces();
8
+ const iface = ifaces.find(iface => iface.name === name);
9
+ return iface || null;
10
+ }
11
+ static findByNamePrefix(prefix) {
12
+ const ifaces = this.getInterfaces();
13
+ return ifaces.filter(iface => iface.name.startsWith(prefix));
14
+ }
15
+ static findByIp(ip) {
16
+ const ifaces = this.getInterfaces();
17
+ const iface = ifaces.find(iface => iface.ipv4.includes(ip) || iface.ipv6.includes(ip));
18
+ return iface || null;
19
+ }
20
+ static asApiServerConfig(ifaces, port) {
21
+ const ret = [];
22
+ for (const iface of ifaces) {
23
+ const i = this.findByName(iface);
24
+ if (i)
25
+ ret.push({ ip: i.ipv4[0], port: port });
26
+ }
27
+ return ret;
28
+ }
29
+ static getInterfaces() {
30
+ const interfaces = (0, os_1.networkInterfaces)();
31
+ const result = [];
32
+ for (const name of Object.keys(interfaces)) {
33
+ const networkInterface = interfaces[name];
34
+ if (networkInterface) {
35
+ const ipv4 = networkInterface.filter(info => info.family === 'IPv4').map(info => info.address);
36
+ const ipv6 = networkInterface.filter(info => info.family === 'IPv6').map(info => info.address);
37
+ result.push({
38
+ name,
39
+ ipv4,
40
+ ipv6
41
+ });
42
+ }
43
+ }
44
+ return result;
45
+ }
46
+ }
47
+ exports.Interfaces = Interfaces;
48
+ //# sourceMappingURL=Interfaces.js.map
@@ -0,0 +1,58 @@
1
+ import { networkInterfaces } from 'os';
2
+
3
+ interface NetworkInterfaceInfo {
4
+ name: string;
5
+ ipv4: string[];
6
+ ipv6: string[];
7
+ }
8
+
9
+
10
+ export class Interfaces {
11
+
12
+ static findByName(name: string): NetworkInterfaceInfo | null {
13
+ const ifaces = this.getInterfaces()
14
+ const iface = ifaces.find(iface => iface.name === name)
15
+ return iface || null
16
+ }
17
+
18
+ static findByNamePrefix(prefix: string): NetworkInterfaceInfo[] {
19
+ const ifaces = this.getInterfaces()
20
+ return ifaces.filter(iface => iface.name.startsWith(prefix))
21
+ }
22
+
23
+ static findByIp(ip: string): NetworkInterfaceInfo | null {
24
+ const ifaces = this.getInterfaces()
25
+ const iface = ifaces.find(iface => iface.ipv4.includes(ip) || iface.ipv6.includes(ip))
26
+ return iface || null
27
+ }
28
+
29
+ static asApiServerConfig(ifaces:string[], port:number): {ip:string,port:number}[] {
30
+ const ret: {ip:string,port:number}[] = []
31
+ for (const iface of ifaces) {
32
+ const i = this.findByName(iface)
33
+ if (i) ret.push({ip:i.ipv4[0],port:port})
34
+ }
35
+ return ret
36
+ }
37
+
38
+ static getInterfaces(): NetworkInterfaceInfo[] {
39
+ const interfaces = networkInterfaces();
40
+ const result: NetworkInterfaceInfo[] = [];
41
+
42
+ for (const name of Object.keys(interfaces)) {
43
+ const networkInterface = interfaces[name];
44
+ if (networkInterface) {
45
+ const ipv4 = networkInterface.filter(info => info.family === 'IPv4').map(info => info.address);
46
+ const ipv6 = networkInterface.filter(info => info.family === 'IPv6').map(info => info.address);
47
+
48
+ result.push({
49
+ name,
50
+ ipv4,
51
+ ipv6
52
+ });
53
+ }
54
+ }
55
+
56
+ return result;
57
+ }
58
+ }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.OTPGenerator = void 0;
27
37
  const crypto = __importStar(require("crypto"));
@@ -0,0 +1 @@
1
+ {"root":["./ip6addr.d.ts","./ts/global.ts","./ts/index.ts","./ts/types.ts","./ts/funcs/geoip2paths.ts","./ts/funcs/maxruntimehours.ts","./ts/funcs/asjson.ts","./ts/funcs/ensurefolder.ts","./ts/funcs/filecacheisvalid.ts","./ts/funcs/getmysql1.ts","./ts/funcs/getmysql2.ts","./ts/funcs/getweeknumber.ts","./ts/funcs/hash_sha512.ts","./ts/funcs/initmysql2pool.ts","./ts/funcs/int2ip.ts","./ts/funcs/ip2int.ts","./ts/funcs/islanip.ts","./ts/funcs/islocal.ts","./ts/funcs/isloopbackip.ts","./ts/funcs/knexconnection.ts","./ts/funcs/promisetimeout.ts","./ts/funcs/randomip.ts","./ts/funcs/randomip6.ts","./ts/funcs/randomstring.ts","./ts/funcs/randomtcpport.ts","./ts/funcs/randomutfstring.ts","./ts/funcs/utcnow.ts","./ts/funcs/validemail.ts","./ts/funcs/validip.ts","./ts/funcs/vaultfill.ts","./ts/funcs/vaultread.ts","./ts/funcs/wait.ts","./ts/models/ipaddress.ts","./ts/models/interfaces.ts","./ts/models/otpgenerator.ts","./ts/models/timespan.ts","./ts/models/unixtime.ts"],"version":"5.7.2"}