mybase 1.0.51 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/jest.config.js +5 -0
- package/mybase.js +7 -7
- package/package.json +10 -4
- package/ts/funcs/Geoip2Paths.d.ts +7 -0
- package/ts/funcs/Geoip2Paths.js +22 -0
- package/ts/funcs/Geoip2Paths.test.ts +11 -0
- package/ts/funcs/Geoip2Paths.ts +26 -0
- package/ts/funcs/fileCacheIsValid.js +39 -0
- package/ts/funcs/fileCacheIsValid.ts +13 -0
- package/ts/funcs/hash_sha512.js +10 -0
- package/ts/funcs/hash_sha512.ts +7 -0
- package/ts/funcs/isLocal.d.ts +1 -0
- package/ts/funcs/isLocal.js +11 -0
- package/ts/funcs/isLocal.test.ts +16 -0
- package/ts/funcs/isLocal.ts +5 -0
- package/ts/funcs/randomString.d.ts +1 -0
- package/ts/funcs/randomString.js +7 -0
- package/ts/funcs/randomString.test.ts +15 -0
- package/ts/funcs/randomString.ts +5 -0
- package/ts/funcs/utcnow.d.ts +2 -0
- package/ts/funcs/utcnow.js +7 -0
- package/ts/funcs/utcnow.ts +5 -0
- package/ts/funcs/validIp.d.ts +1 -0
- package/ts/funcs/validIp.js +31 -0
- package/ts/funcs/validIp.test.ts +33 -0
- package/ts/funcs/validIp.ts +5 -0
- package/ts/funcs/vaultFill.js +96 -0
- package/ts/funcs/vaultFill.ts +89 -0
- package/ts/funcs/vaultRead.js +51 -0
- package/ts/funcs/vaultRead.ts +45 -0
- package/ts/funcs/wait.d.ts +1 -0
- package/ts/funcs/wait.js +9 -0
- package/ts/funcs/wait.ts +7 -0
- package/ts/global.js +15 -0
- package/ts/global.ts +10 -0
- package/ts/index.d.ts +6 -0
- package/ts/index.js +26 -0
- package/ts/index.test.ts +7 -0
- package/ts/index.ts +10 -0
- package/ts/types.d.ts +1 -0
- package/ts/types.js +2 -0
- package/ts/types.ts +1 -0
- package/tsconfig.json +113 -0
package/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Typescript support is being added
|
|
2
|
+
adding them slowly to the project
|
|
3
|
+
```
|
|
4
|
+
import { utcnow } from 'mybase/ts'
|
|
5
|
+
// types
|
|
6
|
+
import { UnixtimeShort } from 'mybase/ts/types'
|
|
7
|
+
```
|
|
2
8
|
|
|
9
|
+
# mybase
|
|
3
10
|
```
|
|
4
11
|
var { isLocal } = require('mybase')
|
|
5
12
|
```
|
package/jest.config.js
ADDED
package/mybase.js
CHANGED
|
@@ -112,11 +112,11 @@ function arrayRandomItem(arry,defaultValue=false) {
|
|
|
112
112
|
return defaultValue
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
function utcnow() {
|
|
115
|
+
function utcnow() { // ported
|
|
116
116
|
return Math.floor(Date.now() / 1000)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
function validIp(str) {
|
|
119
|
+
function validIp(str) { // ported
|
|
120
120
|
if (str && typeof str==='string') {
|
|
121
121
|
let splitted
|
|
122
122
|
if (splitted=str.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/)) {
|
|
@@ -130,7 +130,7 @@ function validIp(str) {
|
|
|
130
130
|
return false
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
function Geoip2Paths() {
|
|
133
|
+
function Geoip2Paths() { // ported
|
|
134
134
|
function firstExisting(paths) {
|
|
135
135
|
if (Array.isArray(paths))
|
|
136
136
|
for(let fpath of paths)
|
|
@@ -263,7 +263,7 @@ function vaultRead(vault, key, cache_in_minutes = 10) {
|
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
|
|
266
|
-
function vaultFill(vault, obj, ignoreError = false, keepCache=true) {
|
|
266
|
+
function vaultFill(vault, obj, ignoreError = false, keepCache=true) { // ported
|
|
267
267
|
// v2.1
|
|
268
268
|
// fills all strings with ^vault@/secret/... with proper vault values
|
|
269
269
|
// if you call it again, it does reload the configuration
|
|
@@ -363,7 +363,7 @@ function maxmindOpen(geoipFile) {
|
|
|
363
363
|
})
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
function isLocal() {
|
|
366
|
+
function isLocal() { // ported
|
|
367
367
|
return (os.type() === 'Darwin')
|
|
368
368
|
}
|
|
369
369
|
|
|
@@ -440,7 +440,7 @@ function object_shuffle(object) {
|
|
|
440
440
|
|
|
441
441
|
|
|
442
442
|
|
|
443
|
-
function randomString(length = 10, charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
|
|
443
|
+
function randomString(length = 10, charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") { // ported
|
|
444
444
|
var text = "";
|
|
445
445
|
for (var i = 0; i < length; i++)
|
|
446
446
|
text += charSet.charAt(Math.floor(Math.random() * charSet.length));
|
|
@@ -557,7 +557,7 @@ function sqlQuery(sqlHandle,query,values=[]) {
|
|
|
557
557
|
})
|
|
558
558
|
}
|
|
559
559
|
|
|
560
|
-
function wait(seconds=1){
|
|
560
|
+
function wait(seconds=1){ // ported
|
|
561
561
|
return new Promise((resolve,reject)=>{
|
|
562
562
|
setTimeout(resolve,seconds*1000)
|
|
563
563
|
})
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mybase",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "mybase.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "jest"
|
|
8
8
|
},
|
|
9
9
|
"author": "",
|
|
10
10
|
"license": "ISC",
|
|
@@ -12,19 +12,25 @@
|
|
|
12
12
|
"@7c/validurl": "0.0.3",
|
|
13
13
|
"aes-js": "^3.1.2",
|
|
14
14
|
"chalk": "^3.0.0",
|
|
15
|
-
"debug": "^4.3.
|
|
15
|
+
"debug": "^4.3.4",
|
|
16
16
|
"ip-range-check": "^0.2.0",
|
|
17
17
|
"ip6": "=0.2.7",
|
|
18
18
|
"ip6addr": "^0.2.5",
|
|
19
19
|
"js-sha512": "^0.8.0",
|
|
20
|
+
"node-vault": "^0.10.2",
|
|
20
21
|
"psl": "^1.9.0",
|
|
21
22
|
"punycode": "^2.1.1",
|
|
22
23
|
"validator": "^13.7.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
26
|
+
"@jest/globals": "^29.7.0",
|
|
27
|
+
"@types/debug": "^4.1.12",
|
|
28
|
+
"@types/jest": "^29.5.11",
|
|
29
|
+
"@types/node": "^20.11.5",
|
|
25
30
|
"chai": "^4.2.0",
|
|
26
31
|
"jest": "^29.7.0",
|
|
27
32
|
"mocha": "^8.2.1",
|
|
28
|
-
"should": "^13.2.3"
|
|
33
|
+
"should": "^13.2.3",
|
|
34
|
+
"ts-jest": "^29.1.1"
|
|
29
35
|
}
|
|
30
36
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Geoip2Paths = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
function Geoip2Paths() {
|
|
7
|
+
var _a, _b, _c, _d;
|
|
8
|
+
function firstExisting(paths) {
|
|
9
|
+
if (Array.isArray(paths))
|
|
10
|
+
for (let fpath of paths)
|
|
11
|
+
if (fs.existsSync(fpath))
|
|
12
|
+
return fpath;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
country: firstExisting(['/opt/geoip2/GeoIP2-Country.mmdb', '/usr/local/var/GeoIP/GeoIP2-Country.mmdb', '/var/lib/GeoIP/GeoIP2-Country.mmdb', '/usr/share/GeoIP/GeoIP2-Country.mmdb', path.join(__dirname, 'assets/GeoIP2-Country.mmdb'), path.join(((_a = require === null || require === void 0 ? void 0 : require.main) === null || _a === void 0 ? void 0 : _a.path) || __dirname, 'assets/GeoIP2-Country.mmdb')]),
|
|
17
|
+
city: firstExisting(['/opt/geoip2/GeoIP2-City.mmdb', '/usr/local/var/GeoIP/GeoIP2-City.mmdb', '/var/lib/GeoIP/GeoIP2-City.mmdb', '/usr/share/GeoIP/GeoIP2-City.mmdb', path.join(__dirname, 'assets/GeoIP2-City.mmdb'), path.join(((_b = require === null || require === void 0 ? void 0 : require.main) === null || _b === void 0 ? void 0 : _b.path) || __dirname, 'assets/GeoIP2-City.mmdb')]),
|
|
18
|
+
isp: firstExisting(['/opt/geoip2/GeoIP2-ISP.mmdb', '/usr/local/var/GeoIP/GeoIP2-ISP.mmdb', '/var/lib/GeoIP/GeoIP2-ISP.mmdb', '/usr/share/GeoIP/GeoIP2-ISP.mmdb', path.join(__dirname, 'assets/GeoIP2-ISP.mmdb'), path.join(((_c = require === null || require === void 0 ? void 0 : require.main) === null || _c === void 0 ? void 0 : _c.path) || __dirname, 'assets/GeoIP2-ISP.mmdb')]),
|
|
19
|
+
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.join(__dirname, 'assets/GeoIP2-Connection-Type.mmdb'), path.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')]),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.Geoip2Paths = Geoip2Paths;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Geoip2Paths } from './Geoip2Paths'
|
|
2
|
+
import * as fs from 'fs'
|
|
3
|
+
|
|
4
|
+
describe('Geoip2Paths', () => {
|
|
5
|
+
it('should return a valid path', () => {
|
|
6
|
+
const paths = Geoip2Paths()
|
|
7
|
+
expect(paths).toHaveProperty('country')
|
|
8
|
+
expect(typeof paths.country).toBe('string')
|
|
9
|
+
expect(fs.existsSync(paths.country as string)).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs = require('fs')
|
|
2
|
+
import path = require('path')
|
|
3
|
+
|
|
4
|
+
export type Geoip2Paths = {
|
|
5
|
+
country:string|false,
|
|
6
|
+
city:string|false,
|
|
7
|
+
isp:string|false,
|
|
8
|
+
ct:string|false,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export function Geoip2Paths() :Geoip2Paths {
|
|
13
|
+
function firstExisting(paths:Array<string>) : string|false {
|
|
14
|
+
if (Array.isArray(paths))
|
|
15
|
+
for(let fpath of paths)
|
|
16
|
+
if (fs.existsSync(fpath)) return fpath
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
country:firstExisting(['/opt/geoip2/GeoIP2-Country.mmdb','/usr/local/var/GeoIP/GeoIP2-Country.mmdb','/var/lib/GeoIP/GeoIP2-Country.mmdb','/usr/share/GeoIP/GeoIP2-Country.mmdb',path.join(__dirname, 'assets/GeoIP2-Country.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-Country.mmdb')]),
|
|
22
|
+
city:firstExisting(['/opt/geoip2/GeoIP2-City.mmdb','/usr/local/var/GeoIP/GeoIP2-City.mmdb','/var/lib/GeoIP/GeoIP2-City.mmdb','/usr/share/GeoIP/GeoIP2-City.mmdb',path.join(__dirname, 'assets/GeoIP2-City.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-City.mmdb')]),
|
|
23
|
+
isp:firstExisting(['/opt/geoip2/GeoIP2-ISP.mmdb','/usr/local/var/GeoIP/GeoIP2-ISP.mmdb','/var/lib/GeoIP/GeoIP2-ISP.mmdb','/usr/share/GeoIP/GeoIP2-ISP.mmdb',path.join(__dirname, 'assets/GeoIP2-ISP.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-ISP.mmdb')]),
|
|
24
|
+
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.join(__dirname, 'assets/GeoIP2-Connection-Type.mmdb'),path.join(require?.main?.path || __dirname, 'assets/GeoIP2-Connection-Type.mmdb')]),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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.fileCacheIsValid = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
function fileCacheIsValid(cacheFileName, cache_in_minutes = 60) {
|
|
29
|
+
if (fs.existsSync(cacheFileName)) {
|
|
30
|
+
const stat = fs.statSync(cacheFileName);
|
|
31
|
+
const mtime = new Date(stat.mtime).getTime();
|
|
32
|
+
if (Date.now() - mtime < cache_in_minutes * 60 * 1000) {
|
|
33
|
+
// cache is still valid
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
exports.fileCacheIsValid = fileCacheIsValid;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
|
|
3
|
+
export function fileCacheIsValid(cacheFileName : string, cache_in_minutes = 60) : boolean {
|
|
4
|
+
if (fs.existsSync(cacheFileName)) {
|
|
5
|
+
const stat = fs.statSync(cacheFileName)
|
|
6
|
+
const mtime = new Date(stat.mtime).getTime()
|
|
7
|
+
if (Date.now() - mtime < cache_in_minutes * 60 * 1000) {
|
|
8
|
+
// cache is still valid
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hash_sha512 = void 0;
|
|
4
|
+
const js_sha512_1 = require("js-sha512");
|
|
5
|
+
function hash_sha512(plainString) {
|
|
6
|
+
if (typeof plainString === 'string')
|
|
7
|
+
return (0, js_sha512_1.sha512)(plainString);
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
exports.hash_sha512 = hash_sha512;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isLocal(): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
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.isLocal = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
function isLocal() {
|
|
9
|
+
return (os_1.default.type() === 'Darwin');
|
|
10
|
+
}
|
|
11
|
+
exports.isLocal = isLocal;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isLocal } from './isLocal';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
|
|
4
|
+
describe('isLocal', () => {
|
|
5
|
+
it('should return true on Darwin OS', () => {
|
|
6
|
+
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
|
7
|
+
const result = isLocal();
|
|
8
|
+
expect(result).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return false on non-Darwin OS', () => {
|
|
12
|
+
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
|
13
|
+
const result = isLocal();
|
|
14
|
+
expect(result).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomString(length?: number, charSet?: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomString = void 0;
|
|
4
|
+
function randomString(length = 10, charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") {
|
|
5
|
+
return Array.from({ length }, () => charSet.charAt(Math.floor(Math.random() * charSet.length))).join('');
|
|
6
|
+
}
|
|
7
|
+
exports.randomString = randomString;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { randomString } from "./randomString";
|
|
2
|
+
|
|
3
|
+
test('randomString', () => {
|
|
4
|
+
// Test default length and character set
|
|
5
|
+
expect(randomString()).toHaveLength(10);
|
|
6
|
+
expect(randomString()).toMatch(/^[A-Za-z0-9]{10}$/);
|
|
7
|
+
|
|
8
|
+
// Test custom length and character set
|
|
9
|
+
expect(randomString(5, "abc")).toHaveLength(5);
|
|
10
|
+
expect(randomString(5, "abc")).toMatch(/^[abc]{5}$/);
|
|
11
|
+
|
|
12
|
+
// Test empty character set
|
|
13
|
+
expect(randomString(10, "")).toHaveLength(0);
|
|
14
|
+
expect(randomString(10, "")).toMatch(/^$/);
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validIp(IPAddress: string): number;
|
|
@@ -0,0 +1,31 @@
|
|
|
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;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.vaultFill = void 0;
|
|
13
|
+
const debug_1 = require("debug");
|
|
14
|
+
const vaultRead_1 = require("./vaultRead");
|
|
15
|
+
const dbg = (0, debug_1.debug)('vaultFill');
|
|
16
|
+
function vaultFill(vaultInstance, inputObject, ignoreError = false, keepCache = true) {
|
|
17
|
+
// v2.1
|
|
18
|
+
// fills all strings with ^vault@/secret/... with proper vault values
|
|
19
|
+
// if you call it again, it does reload the configuration
|
|
20
|
+
// v2.2
|
|
21
|
+
// supports keepCache - if vault fails, we will keep previous values instead of filling with false
|
|
22
|
+
return new Promise(function (resolve, reject) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
let vaultKeys = Array();
|
|
25
|
+
let vaultResults = {};
|
|
26
|
+
findVaultKeyMappings(inputObject, vaultKeys);
|
|
27
|
+
// read these keys from vault
|
|
28
|
+
for (let idx in vaultKeys) {
|
|
29
|
+
const val = vaultKeys[idx];
|
|
30
|
+
if (typeof val !== "string")
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
let got = yield (0, vaultRead_1.vaultRead)(vaultInstance, vaultKeys[idx]);
|
|
34
|
+
got['__vaultkey'] = val;
|
|
35
|
+
got['__vaultfilled'] = Date.now();
|
|
36
|
+
vaultResults[val] = got;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
dbg(`Could not read vaultKey '${val}'`, err);
|
|
40
|
+
if (!ignoreError)
|
|
41
|
+
vaultResults[val] = false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
fillVaultKeyMappings(inputObject, vaultResults, keepCache);
|
|
45
|
+
resolve(true);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.vaultFill = vaultFill;
|
|
50
|
+
function findVaultKeyMappings(config, keys = Array()) {
|
|
51
|
+
for (var i in config) {
|
|
52
|
+
if (config[i] !== null) {
|
|
53
|
+
if (typeof config[i] === 'object' && (config[i].constructor.name === 'Array' || config[i].constructor.name === 'Object'))
|
|
54
|
+
findVaultKeyMappings(config[i], keys);
|
|
55
|
+
// detect previously read vaultKey
|
|
56
|
+
if (i === '__vaultkey') {
|
|
57
|
+
if (!keys.includes(vaultKey))
|
|
58
|
+
keys.push(config[i]);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// --
|
|
62
|
+
if (typeof config[i] === 'string' && config[i].search(/^vault@/) == 0) {
|
|
63
|
+
var splitted = config[i].split(/vault@/);
|
|
64
|
+
if (splitted.length == 2) {
|
|
65
|
+
var vaultKey = splitted[1];
|
|
66
|
+
if (!keys.includes(vaultKey))
|
|
67
|
+
keys.push(vaultKey);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function fillVaultKeyMappings(config, vaultResults, keepCache = true) {
|
|
74
|
+
for (var i in config) {
|
|
75
|
+
if (config[i] !== null) {
|
|
76
|
+
if (config[i] && config[i].constructor.name === 'Object' && config[i].hasOwnProperty('__vaultkey')) {
|
|
77
|
+
if (keepCache) {
|
|
78
|
+
if (vaultResults[config[i]['__vaultkey']])
|
|
79
|
+
config[i] = vaultResults[config[i]['__vaultkey']];
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
config[i] = vaultResults[config[i]['__vaultkey']];
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (typeof config[i] === 'object' && (config[i].constructor.name === 'Array' || config[i].constructor.name === 'Object'))
|
|
86
|
+
fillVaultKeyMappings(config[i], vaultResults);
|
|
87
|
+
if (typeof config[i] === 'string' && config[i].search(/^vault@/) == 0) {
|
|
88
|
+
var splitted = config[i].split(/vault@/);
|
|
89
|
+
if (splitted.length == 2) {
|
|
90
|
+
var vaultKey = splitted[1];
|
|
91
|
+
config[i] = vaultResults[vaultKey];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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;
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wait(seconds?: number): Promise<void>;
|
package/ts/funcs/wait.js
ADDED
package/ts/funcs/wait.ts
ADDED
package/ts/global.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
package/ts/global.ts
ADDED
package/ts/index.d.ts
ADDED
package/ts/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./funcs/Geoip2Paths"), exports);
|
|
18
|
+
__exportStar(require("./funcs/isLocal"), exports);
|
|
19
|
+
__exportStar(require("./funcs/randomString"), exports);
|
|
20
|
+
__exportStar(require("./funcs/utcnow"), exports);
|
|
21
|
+
__exportStar(require("./funcs/validIp"), exports);
|
|
22
|
+
__exportStar(require("./funcs/wait"), exports);
|
|
23
|
+
__exportStar(require("./funcs/fileCacheIsValid"), exports);
|
|
24
|
+
__exportStar(require("./funcs/hash_sha512"), exports);
|
|
25
|
+
__exportStar(require("./funcs/vaultRead"), exports);
|
|
26
|
+
__exportStar(require("./funcs/vaultFill"), exports);
|
package/ts/index.test.ts
ADDED
package/ts/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./funcs/Geoip2Paths";
|
|
2
|
+
export * from "./funcs/isLocal"
|
|
3
|
+
export * from "./funcs/randomString"
|
|
4
|
+
export * from "./funcs/utcnow"
|
|
5
|
+
export * from "./funcs/validIp"
|
|
6
|
+
export * from "./funcs/wait"
|
|
7
|
+
export * from "./funcs/fileCacheIsValid"
|
|
8
|
+
export * from "./funcs/hash_sha512"
|
|
9
|
+
export * from "./funcs/vaultRead"
|
|
10
|
+
export * from "./funcs/vaultFill"
|
package/ts/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UnixtimeShort = number;
|
package/ts/types.js
ADDED
package/ts/types.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UnixtimeShort = number
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
43
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
44
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
45
|
+
|
|
46
|
+
/* JavaScript Support */
|
|
47
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
48
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
49
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
|
+
|
|
51
|
+
/* Emit */
|
|
52
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
59
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
62
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
63
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
64
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
65
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
67
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
68
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
69
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
70
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
74
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
75
|
+
|
|
76
|
+
/* Interop Constraints */
|
|
77
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
78
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
79
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
81
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
82
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
83
|
+
|
|
84
|
+
/* Type Checking */
|
|
85
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
86
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
87
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
92
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
93
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
94
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
95
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
96
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
97
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
98
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
99
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
100
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
101
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
102
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
103
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
104
|
+
|
|
105
|
+
/* Completeness */
|
|
106
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
107
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
108
|
+
|
|
109
|
+
},
|
|
110
|
+
"exclude": [
|
|
111
|
+
"**/*.test.ts",
|
|
112
|
+
]
|
|
113
|
+
}
|