apeframework 0.0.0-dev.20 → 0.0.0-dev.21
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/LICENSE +1 -1
- package/cipher/Algorithm.js +2 -4
- package/cipher/Cipher.js +9 -15
- package/cipher/errors/DecryptError.js +3 -6
- package/cipher/errors/SecretLengthError.js +3 -6
- package/cipher/validateSecretLength.js +7 -10
- package/cli/Args.js +1 -2
- package/cli/Command.js +1 -2
- package/cli/getArgs.js +3 -6
- package/cli/parseArgs.js +3 -9
- package/cli/utils/exit.js +1 -4
- package/cli/utils/formatList.js +3 -6
- package/cli/utils/formatTable.js +3 -6
- package/cli/utils/formatText.js +3 -6
- package/cli/utils/print.js +1 -4
- package/cli/utils/printLn.js +3 -6
- package/config/Config.js +1 -2
- package/config/Properties.js +1 -2
- package/config/errors/FileReadError.js +3 -6
- package/config/errors/PropertyNameError.js +3 -6
- package/config/errors/PropertyParseError.js +3 -6
- package/config/getConfig.js +8 -11
- package/config/getPropertyEnvVar.js +1 -4
- package/config/parseProperty.js +3 -6
- package/config/readFile.js +8 -14
- package/config/validatePropertyName.js +3 -6
- package/env/Env.js +1 -2
- package/env/errors/FileReadError.js +3 -6
- package/env/getEnv.js +3 -6
- package/env/readFile.js +8 -14
- package/error/BaseError.js +1 -4
- package/jwt/Algorithm.js +2 -4
- package/jwt/Jwt.js +6 -9
- package/jwt/Payload.js +1 -2
- package/jwt/errors/SecretLengthError.js +3 -6
- package/jwt/validateSecretLength.js +7 -10
- package/logger/Level.js +2 -4
- package/logger/Logger.js +1 -4
- package/logger/Severity.js +2 -4
- package/logger/adapters/file/FileLogger.js +11 -17
- package/logger/adapters/file/errors/FileInitError.js +3 -6
- package/logger/adapters/file/initFile.js +6 -12
- package/logger/adapters/noop/NoopLogger.js +3 -6
- package/logger/adapters/stdio/StdioLogger.js +11 -17
- package/mailer/Address.js +1 -2
- package/mailer/Attachment.js +1 -2
- package/mailer/Event.js +1 -2
- package/mailer/List.js +1 -2
- package/mailer/Location.js +1 -2
- package/mailer/Mail.js +1 -2
- package/mailer/Mailer.js +16 -19
- package/mailer/Method.js +2 -4
- package/mailer/adapters/noop/NoopMailer.js +5 -8
- package/mailer/adapters/smtp/SmtpMailer.js +19 -25
- package/mailer/adapters/smtp/getAddress.js +1 -4
- package/mailer/adapters/smtp/getAddresses.js +3 -6
- package/mailer/adapters/smtp/getAttachments.js +1 -4
- package/mailer/errors/AddressEmailError.js +3 -6
- package/mailer/errors/EventAttachmentUrlError.js +3 -6
- package/mailer/errors/EventGeolocationError.js +3 -6
- package/mailer/errors/EventUrlError.js +3 -6
- package/mailer/errors/ListUrlError.js +3 -6
- package/mailer/getIcalendar.js +3 -6
- package/mailer/validateAddressEmail.js +5 -8
- package/mailer/validateEventAttachmentUrl.js +5 -8
- package/mailer/validateEventGeolocation.js +5 -8
- package/mailer/validateEventUrl.js +5 -8
- package/mailer/validateListUrl.js +5 -8
- package/package.json +2 -4
- package/parser/Parser.js +1 -2
- package/parser/errors/ParseError.js +3 -6
- package/parser/factories/enum/createEnumParser.js +3 -6
- package/parser/factories/unit/Unit.js +1 -2
- package/parser/factories/unit/createUnitParser.js +8 -11
- package/parser/parseBoolean.js +3 -6
- package/parser/parseBytes.js +3 -6
- package/parser/parseInteger.js +6 -9
- package/parser/parseMilliseconds.js +3 -6
- package/parser/parseNumber.js +4 -7
- package/parser/parseString.js +3 -6
- package/pwd/Pwd.js +6 -12
- package/pwd/errors/HashRoundsError.js +3 -6
- package/pwd/validateHashRounds.js +3 -6
- package/server/ErrorHandler.js +1 -2
- package/server/Format.js +1 -2
- package/server/Handler.js +1 -2
- package/server/Method.js +2 -4
- package/server/OpenApiFormat.js +2 -4
- package/server/Route.js +1 -2
- package/server/Schema.js +1 -2
- package/server/Server.js +15 -21
- package/server/getAjv.js +5 -11
- package/tls/Tls.js +1 -2
- package/tls/errors/FileReadError.js +3 -6
- package/tls/getTls.js +5 -8
- package/tls/readFile.js +7 -13
- package/utils/getRandomHexString.js +3 -6
- package/utils/getTimestamp.js +1 -4
- package/utils/isValidEmail.js +1 -4
- package/utils/isValidGeolocation.js +1 -4
- package/utils/isValidHexString.js +1 -4
- package/utils/isValidIsoDate.js +1 -4
- package/utils/isValidJwtToken.js +1 -4
- package/utils/isValidUrl.js +1 -4
- package/utils/isValidUuid.js +1 -4
- package/utils/wait.js +1 -4
- package/cipher/Algorithm.ts +0 -9
- package/cipher/Cipher.ts +0 -46
- package/cipher/errors/DecryptError.ts +0 -11
- package/cipher/errors/SecretLengthError.ts +0 -11
- package/cipher/validateSecretLength.ts +0 -18
- package/cli/Args.ts +0 -8
- package/cli/Command.ts +0 -7
- package/cli/getArgs.ts +0 -10
- package/cli/parseArgs.ts +0 -34
- package/cli/utils/exit.ts +0 -7
- package/cli/utils/formatList.ts +0 -11
- package/cli/utils/formatTable.ts +0 -25
- package/cli/utils/formatText.ts +0 -9
- package/cli/utils/print.ts +0 -7
- package/cli/utils/printLn.ts +0 -9
- package/config/Config.ts +0 -5
- package/config/Properties.ts +0 -12
- package/config/errors/FileReadError.ts +0 -11
- package/config/errors/PropertyNameError.ts +0 -11
- package/config/errors/PropertyParseError.ts +0 -11
- package/config/getConfig.ts +0 -47
- package/config/getPropertyEnvVar.ts +0 -15
- package/config/parseProperty.ts +0 -47
- package/config/readFile.ts +0 -34
- package/config/validatePropertyName.ts +0 -13
- package/env/Env.ts +0 -5
- package/env/errors/FileReadError.ts +0 -11
- package/env/getEnv.ts +0 -24
- package/env/readFile.ts +0 -24
- package/error/BaseError.ts +0 -12
- package/jwt/Algorithm.ts +0 -9
- package/jwt/Jwt.ts +0 -49
- package/jwt/Payload.ts +0 -14
- package/jwt/errors/SecretLengthError.ts +0 -11
- package/jwt/validateSecretLength.ts +0 -18
- package/logger/Level.ts +0 -13
- package/logger/Logger.ts +0 -19
- package/logger/Severity.ts +0 -12
- package/logger/adapters/file/FileLogger.ts +0 -87
- package/logger/adapters/file/errors/FileInitError.ts +0 -11
- package/logger/adapters/file/initFile.ts +0 -18
- package/logger/adapters/noop/NoopLogger.ts +0 -21
- package/logger/adapters/stdio/StdioLogger.ts +0 -89
- package/mailer/Address.ts +0 -8
- package/mailer/Attachment.ts +0 -11
- package/mailer/Event.ts +0 -20
- package/mailer/List.ts +0 -10
- package/mailer/Location.ts +0 -12
- package/mailer/Mail.ts +0 -23
- package/mailer/Mailer.ts +0 -69
- package/mailer/Method.ts +0 -8
- package/mailer/adapters/noop/NoopMailer.ts +0 -15
- package/mailer/adapters/smtp/SmtpMailer.ts +0 -74
- package/mailer/adapters/smtp/getAddress.ts +0 -15
- package/mailer/adapters/smtp/getAddresses.ts +0 -17
- package/mailer/adapters/smtp/getAttachments.ts +0 -20
- package/mailer/errors/AddressEmailError.ts +0 -11
- package/mailer/errors/EventAttachmentUrlError.ts +0 -11
- package/mailer/errors/EventGeolocationError.ts +0 -11
- package/mailer/errors/EventUrlError.ts +0 -11
- package/mailer/errors/ListUrlError.ts +0 -11
- package/mailer/getIcalendar.ts +0 -39
- package/mailer/validateAddressEmail.ts +0 -12
- package/mailer/validateEventAttachmentUrl.ts +0 -12
- package/mailer/validateEventGeolocation.ts +0 -15
- package/mailer/validateEventUrl.ts +0 -12
- package/mailer/validateListUrl.ts +0 -12
- package/parser/Parser.ts +0 -5
- package/parser/errors/ParseError.ts +0 -11
- package/parser/factories/enum/createEnumParser.ts +0 -21
- package/parser/factories/unit/Unit.ts +0 -8
- package/parser/factories/unit/createUnitParser.ts +0 -50
- package/parser/parseBoolean.ts +0 -33
- package/parser/parseBytes.ts +0 -55
- package/parser/parseInteger.ts +0 -23
- package/parser/parseMilliseconds.ts +0 -31
- package/parser/parseNumber.ts +0 -22
- package/parser/parseString.ts +0 -16
- package/pwd/Pwd.ts +0 -31
- package/pwd/errors/HashRoundsError.ts +0 -11
- package/pwd/validateHashRounds.ts +0 -11
- package/server/ErrorHandler.ts +0 -11
- package/server/Format.ts +0 -15
- package/server/Handler.ts +0 -10
- package/server/Method.ts +0 -11
- package/server/OpenApiFormat.ts +0 -8
- package/server/Route.ts +0 -16
- package/server/Schema.ts +0 -13
- package/server/Server.ts +0 -134
- package/server/getAjv.ts +0 -26
- package/tls/Tls.ts +0 -10
- package/tls/errors/FileReadError.ts +0 -11
- package/tls/getTls.ts +0 -24
- package/tls/readFile.ts +0 -18
- package/utils/getRandomHexString.ts +0 -9
- package/utils/getTimestamp.ts +0 -7
- package/utils/isValidEmail.ts +0 -9
- package/utils/isValidGeolocation.ts +0 -10
- package/utils/isValidHexString.ts +0 -9
- package/utils/isValidIsoDate.ts +0 -9
- package/utils/isValidJwtToken.ts +0 -9
- package/utils/isValidUrl.ts +0 -21
- package/utils/isValidUuid.ts +0 -10
- package/utils/wait.ts +0 -9
package/LICENSE
CHANGED
package/cipher/Algorithm.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Algorithm = void 0;
|
|
4
1
|
var Algorithm;
|
|
5
2
|
(function (Algorithm) {
|
|
6
3
|
Algorithm["AES128"] = "aes-128-cbc";
|
|
7
4
|
Algorithm["AES192"] = "aes-192-cbc";
|
|
8
5
|
Algorithm["AES256"] = "aes-256-cbc";
|
|
9
|
-
})(Algorithm || (
|
|
6
|
+
})(Algorithm || (Algorithm = {}));
|
|
7
|
+
export { Algorithm, };
|
package/cipher/Cipher.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Cipher = void 0;
|
|
7
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
const DecryptError_1 = require("./errors/DecryptError");
|
|
9
|
-
const validateSecretLength_1 = require("./validateSecretLength");
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { DecryptError } from './errors/DecryptError';
|
|
3
|
+
import { validateSecretLength } from './validateSecretLength';
|
|
10
4
|
class Cipher {
|
|
11
5
|
algorithm;
|
|
12
6
|
secret;
|
|
13
7
|
constructor(params) {
|
|
14
|
-
|
|
8
|
+
validateSecretLength(params.algorithm, params.secret);
|
|
15
9
|
this.algorithm = params.algorithm;
|
|
16
10
|
this.secret = Buffer.from(params.secret, 'utf8');
|
|
17
11
|
}
|
|
18
12
|
encrypt(string) {
|
|
19
|
-
const iv =
|
|
20
|
-
const cipher =
|
|
13
|
+
const iv = crypto.randomBytes(16);
|
|
14
|
+
const cipher = crypto.createCipheriv(this.algorithm, this.secret, iv);
|
|
21
15
|
return iv.toString('hex')
|
|
22
16
|
+ cipher.update(string, 'utf8', 'hex')
|
|
23
17
|
+ cipher.final('hex');
|
|
@@ -25,14 +19,14 @@ class Cipher {
|
|
|
25
19
|
decrypt(string) {
|
|
26
20
|
const buffer = Buffer.from(string, 'hex');
|
|
27
21
|
const iv = buffer.subarray(0, 16);
|
|
28
|
-
const decipher =
|
|
22
|
+
const decipher = crypto.createDecipheriv(this.algorithm, this.secret, iv);
|
|
29
23
|
try {
|
|
30
24
|
return decipher.update(buffer.subarray(16), undefined, 'utf8')
|
|
31
25
|
+ decipher.final('utf8');
|
|
32
26
|
}
|
|
33
27
|
catch (error) {
|
|
34
|
-
throw new
|
|
28
|
+
throw new DecryptError(error.message);
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
|
|
32
|
+
export { Cipher, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DecryptError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class DecryptError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class DecryptError extends BaseError {
|
|
6
3
|
constructor(message) {
|
|
7
4
|
super(`failed decrypting string: ${message}`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { DecryptError, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SecretLengthError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class SecretLengthError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class SecretLengthError extends BaseError {
|
|
6
3
|
constructor() {
|
|
7
4
|
super('invalid secret length');
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { SecretLengthError, };
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.validateSecretLength = void 0;
|
|
4
|
-
const Algorithm_1 = require("./Algorithm");
|
|
5
|
-
const SecretLengthError_1 = require("./errors/SecretLengthError");
|
|
1
|
+
import { Algorithm } from './Algorithm';
|
|
2
|
+
import { SecretLengthError } from './errors/SecretLengthError';
|
|
6
3
|
const secretLength = {
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
4
|
+
[Algorithm.AES128]: 16,
|
|
5
|
+
[Algorithm.AES192]: 24,
|
|
6
|
+
[Algorithm.AES256]: 32,
|
|
10
7
|
};
|
|
11
8
|
const validateSecretLength = (algorithm, secret) => {
|
|
12
9
|
if (Buffer.from(secret).length !== secretLength[algorithm]) {
|
|
13
|
-
throw new
|
|
10
|
+
throw new SecretLengthError();
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
|
-
|
|
13
|
+
export { validateSecretLength, };
|
package/cli/Args.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cli/Command.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cli/getArgs.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getArgs = void 0;
|
|
4
|
-
const parseArgs_1 = require("./parseArgs");
|
|
1
|
+
import { parseArgs } from './parseArgs';
|
|
5
2
|
const getArgs = () => {
|
|
6
|
-
return
|
|
3
|
+
return parseArgs(process.argv.slice(2));
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { getArgs, };
|
package/cli/parseArgs.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
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.parseArgs = void 0;
|
|
7
|
-
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
1
|
+
import yargsParser from 'yargs-parser';
|
|
8
2
|
const parseArgs = (args) => {
|
|
9
|
-
const parsed = (
|
|
3
|
+
const parsed = yargsParser(args, {
|
|
10
4
|
configuration: {
|
|
11
5
|
'boolean-negation': false,
|
|
12
6
|
'camel-case-expansion': true,
|
|
@@ -28,4 +22,4 @@ const parseArgs = (args) => {
|
|
|
28
22
|
optional,
|
|
29
23
|
};
|
|
30
24
|
};
|
|
31
|
-
|
|
25
|
+
export { parseArgs, };
|
package/cli/utils/exit.js
CHANGED
package/cli/utils/formatList.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatList = void 0;
|
|
4
|
-
const os_1 = require("os");
|
|
1
|
+
import { EOL } from 'os';
|
|
5
2
|
const formatList = (list) => {
|
|
6
3
|
return list
|
|
7
4
|
.map((item) => { return ` ${item}`; })
|
|
8
|
-
.join(
|
|
5
|
+
.join(EOL);
|
|
9
6
|
};
|
|
10
|
-
|
|
7
|
+
export { formatList, };
|
package/cli/utils/formatTable.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatTable = void 0;
|
|
4
|
-
const os_1 = require("os");
|
|
1
|
+
import { EOL } from 'os';
|
|
5
2
|
const formatTable = (table) => {
|
|
6
3
|
const colLength = [];
|
|
7
4
|
table.forEach((row) => {
|
|
@@ -17,6 +14,6 @@ const formatTable = (table) => {
|
|
|
17
14
|
.map((col, i) => { return col.padEnd(colLength[i], ' '); })
|
|
18
15
|
.join(' ');
|
|
19
16
|
})
|
|
20
|
-
.join(
|
|
17
|
+
.join(EOL);
|
|
21
18
|
};
|
|
22
|
-
|
|
19
|
+
export { formatTable, };
|
package/cli/utils/formatText.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatText = void 0;
|
|
4
|
-
const os_1 = require("os");
|
|
1
|
+
import { EOL } from 'os';
|
|
5
2
|
const formatText = (text) => {
|
|
6
|
-
return text.join(
|
|
3
|
+
return text.join(EOL);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { formatText, };
|
package/cli/utils/print.js
CHANGED
package/cli/utils/printLn.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printLn = void 0;
|
|
4
|
-
const os_1 = require("os");
|
|
1
|
+
import { EOL } from 'os';
|
|
5
2
|
const printLn = (s) => {
|
|
6
|
-
process.stdout.write(`${s}${
|
|
3
|
+
process.stdout.write(`${s}${EOL}`);
|
|
7
4
|
};
|
|
8
|
-
|
|
5
|
+
export { printLn, };
|
package/config/Config.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/config/Properties.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FileReadError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class FileReadError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class FileReadError extends BaseError {
|
|
6
3
|
constructor(path, message) {
|
|
7
4
|
super(`failed reading file "${path}": ${message}`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { FileReadError, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PropertyNameError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class PropertyNameError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class PropertyNameError extends BaseError {
|
|
6
3
|
constructor(name) {
|
|
7
4
|
super(`invalid property name "${name}"`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { PropertyNameError, };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PropertyParseError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class PropertyParseError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class PropertyParseError extends BaseError {
|
|
6
3
|
constructor(name, source, message) {
|
|
7
4
|
super(`failed parsing property "${name}" from ${source}: ${message}`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { PropertyParseError, };
|
package/config/getConfig.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const parseProperty_1 = require("./parseProperty");
|
|
6
|
-
const readFile_1 = require("./readFile");
|
|
7
|
-
const validatePropertyName_1 = require("./validatePropertyName");
|
|
1
|
+
import { getPropertyEnvVar } from './getPropertyEnvVar';
|
|
2
|
+
import { parseProperty } from './parseProperty';
|
|
3
|
+
import { readFile } from './readFile';
|
|
4
|
+
import { validatePropertyName } from './validatePropertyName';
|
|
8
5
|
const getConfig = (params) => {
|
|
9
6
|
const file = params.file
|
|
10
|
-
?
|
|
7
|
+
? readFile(params.file.path, params.file.required)
|
|
11
8
|
: {};
|
|
12
9
|
const env = params.env ?? {};
|
|
13
10
|
const args = params.args ?? { positional: [], optional: {} };
|
|
14
11
|
const config = {};
|
|
15
12
|
for (const name in params.properties) {
|
|
16
|
-
|
|
17
|
-
config[name] =
|
|
13
|
+
validatePropertyName(name);
|
|
14
|
+
config[name] = parseProperty(name, params.properties[name].parser, params.properties[name].default, file[name], env[getPropertyEnvVar(name)], args.optional[name]);
|
|
18
15
|
}
|
|
19
16
|
return config;
|
|
20
17
|
};
|
|
21
|
-
|
|
18
|
+
export { getConfig, };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPropertyEnvVar = void 0;
|
|
4
1
|
const capitalLetterRegex = /[A-Z]/gu;
|
|
5
2
|
const capitalLetterReplacer = (letter) => {
|
|
6
3
|
return `_${letter}`;
|
|
@@ -10,4 +7,4 @@ const getPropertyEnvVar = (name) => {
|
|
|
10
7
|
.replace(capitalLetterRegex, capitalLetterReplacer)
|
|
11
8
|
.toUpperCase();
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
export { getPropertyEnvVar, };
|
package/config/parseProperty.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseProperty = void 0;
|
|
4
|
-
const PropertyParseError_1 = require("./errors/PropertyParseError");
|
|
1
|
+
import { PropertyParseError } from './errors/PropertyParseError';
|
|
5
2
|
const parseProperty = (name, parser, defaultValue, fileValue, envValue, argsValue) => {
|
|
6
3
|
const sources = [
|
|
7
4
|
{
|
|
@@ -31,7 +28,7 @@ const parseProperty = (name, parser, defaultValue, fileValue, envValue, argsValu
|
|
|
31
28
|
return parser(source.value);
|
|
32
29
|
}
|
|
33
30
|
catch (error) {
|
|
34
|
-
throw new
|
|
31
|
+
throw new PropertyParseError(name, source.name, error.message);
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
|
-
|
|
34
|
+
export { parseProperty, };
|
package/config/readFile.js
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readFile = void 0;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const FileReadError_1 = require("./errors/FileReadError");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { FileReadError } from './errors/FileReadError';
|
|
9
3
|
const readFile = (path, required = false) => {
|
|
10
4
|
let json = {};
|
|
11
5
|
let fileExists;
|
|
12
6
|
try {
|
|
13
|
-
fileExists =
|
|
7
|
+
fileExists = fs.existsSync(path);
|
|
14
8
|
if (fileExists) {
|
|
15
|
-
json =
|
|
9
|
+
json = fs.readJsonSync(path);
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
12
|
catch (error) {
|
|
19
|
-
throw new
|
|
13
|
+
throw new FileReadError(path, error.message);
|
|
20
14
|
}
|
|
21
15
|
if (required && !fileExists) {
|
|
22
|
-
throw new
|
|
16
|
+
throw new FileReadError(path, 'missing file');
|
|
23
17
|
}
|
|
24
18
|
if (typeof json !== 'object'
|
|
25
19
|
|| Array.isArray(json)
|
|
26
20
|
|| json === null) {
|
|
27
|
-
throw new
|
|
21
|
+
throw new FileReadError(path, 'invalid content');
|
|
28
22
|
}
|
|
29
23
|
return json;
|
|
30
24
|
};
|
|
31
|
-
|
|
25
|
+
export { readFile, };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validatePropertyName = void 0;
|
|
4
|
-
const PropertyNameError_1 = require("./errors/PropertyNameError");
|
|
1
|
+
import { PropertyNameError } from './errors/PropertyNameError';
|
|
5
2
|
const propertyNameRegex = /^[a-z](?:[0-9A-Za-z])*$/u;
|
|
6
3
|
const validatePropertyName = (name) => {
|
|
7
4
|
if (!propertyNameRegex.test(name)) {
|
|
8
|
-
throw new
|
|
5
|
+
throw new PropertyNameError(name);
|
|
9
6
|
}
|
|
10
7
|
};
|
|
11
|
-
|
|
8
|
+
export { validatePropertyName, };
|
package/env/Env.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FileReadError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class FileReadError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class FileReadError extends BaseError {
|
|
6
3
|
constructor(path, message) {
|
|
7
4
|
super(`failed reading file "${path}": ${message}`);
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { FileReadError, };
|
package/env/getEnv.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnv = void 0;
|
|
4
|
-
const readFile_1 = require("./readFile");
|
|
1
|
+
import { readFile } from './readFile';
|
|
5
2
|
const getEnv = (params) => {
|
|
6
3
|
let file = {};
|
|
7
4
|
if (params?.file) {
|
|
8
|
-
file =
|
|
5
|
+
file = readFile(params.file.path, params.file.required);
|
|
9
6
|
}
|
|
10
7
|
return {
|
|
11
8
|
...file,
|
|
12
9
|
...process.env,
|
|
13
10
|
};
|
|
14
11
|
};
|
|
15
|
-
|
|
12
|
+
export { getEnv, };
|
package/env/readFile.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readFile = void 0;
|
|
7
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const FileReadError_1 = require("./errors/FileReadError");
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { FileReadError } from './errors/FileReadError';
|
|
10
4
|
const readFile = (path, required = false) => {
|
|
11
5
|
try {
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
6
|
+
if (fs.existsSync(path)) {
|
|
7
|
+
return dotenv.parse(fs.readFileSync(path));
|
|
14
8
|
}
|
|
15
9
|
}
|
|
16
10
|
catch (error) {
|
|
17
|
-
throw new
|
|
11
|
+
throw new FileReadError(path, error.message);
|
|
18
12
|
}
|
|
19
13
|
if (required) {
|
|
20
|
-
throw new
|
|
14
|
+
throw new FileReadError(path, 'missing file');
|
|
21
15
|
}
|
|
22
16
|
return {};
|
|
23
17
|
};
|
|
24
|
-
|
|
18
|
+
export { readFile, };
|
package/error/BaseError.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseError = void 0;
|
|
4
1
|
class BaseError extends Error {
|
|
5
2
|
constructor(message) {
|
|
6
3
|
super(message);
|
|
@@ -9,4 +6,4 @@ class BaseError extends Error {
|
|
|
9
6
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
|
|
9
|
+
export { BaseError, };
|
package/jwt/Algorithm.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Algorithm = void 0;
|
|
4
1
|
var Algorithm;
|
|
5
2
|
(function (Algorithm) {
|
|
6
3
|
Algorithm["HS256"] = "HS256";
|
|
7
4
|
Algorithm["HS384"] = "HS384";
|
|
8
5
|
Algorithm["HS512"] = "HS512";
|
|
9
|
-
})(Algorithm || (
|
|
6
|
+
})(Algorithm || (Algorithm = {}));
|
|
7
|
+
export { Algorithm, };
|
package/jwt/Jwt.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Jwt = void 0;
|
|
4
|
-
const jose_1 = require("jose");
|
|
5
|
-
const validateSecretLength_1 = require("./validateSecretLength");
|
|
1
|
+
import { SignJWT, jwtVerify } from 'jose';
|
|
2
|
+
import { validateSecretLength } from './validateSecretLength';
|
|
6
3
|
class Jwt {
|
|
7
4
|
algorithm;
|
|
8
5
|
secret;
|
|
9
6
|
constructor(params) {
|
|
10
|
-
|
|
7
|
+
validateSecretLength(params.algorithm, params.secret);
|
|
11
8
|
this.algorithm = params.algorithm;
|
|
12
9
|
this.secret = new TextEncoder().encode(params.secret);
|
|
13
10
|
}
|
|
14
11
|
async createToken(payload) {
|
|
15
|
-
return new
|
|
12
|
+
return new SignJWT(payload)
|
|
16
13
|
.setProtectedHeader({
|
|
17
14
|
typ: 'JWT',
|
|
18
15
|
alg: this.algorithm,
|
|
@@ -21,7 +18,7 @@ class Jwt {
|
|
|
21
18
|
}
|
|
22
19
|
async verifyToken(token, timestamp) {
|
|
23
20
|
try {
|
|
24
|
-
const { payload } = await
|
|
21
|
+
const { payload } = await jwtVerify(token, this.secret, {
|
|
25
22
|
typ: 'JWT',
|
|
26
23
|
currentDate: new Date(timestamp * 1000),
|
|
27
24
|
});
|
|
@@ -32,4 +29,4 @@ class Jwt {
|
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
export { Jwt, };
|
package/jwt/Payload.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SecretLengthError = void 0;
|
|
4
|
-
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class SecretLengthError extends BaseError_1.BaseError {
|
|
1
|
+
import { BaseError } from '../../error/BaseError';
|
|
2
|
+
class SecretLengthError extends BaseError {
|
|
6
3
|
constructor() {
|
|
7
4
|
super('invalid secret length');
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
|
|
7
|
+
export { SecretLengthError, };
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.validateSecretLength = void 0;
|
|
4
|
-
const Algorithm_1 = require("./Algorithm");
|
|
5
|
-
const SecretLengthError_1 = require("./errors/SecretLengthError");
|
|
1
|
+
import { Algorithm } from './Algorithm';
|
|
2
|
+
import { SecretLengthError } from './errors/SecretLengthError';
|
|
6
3
|
const minSecretLength = {
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
4
|
+
[Algorithm.HS256]: 32,
|
|
5
|
+
[Algorithm.HS384]: 48,
|
|
6
|
+
[Algorithm.HS512]: 64,
|
|
10
7
|
};
|
|
11
8
|
const validateSecretLength = (algorithm, secret) => {
|
|
12
9
|
if (Buffer.from(secret).length < minSecretLength[algorithm]) {
|
|
13
|
-
throw new
|
|
10
|
+
throw new SecretLengthError();
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
|
-
|
|
13
|
+
export { validateSecretLength, };
|
package/logger/Level.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Level = void 0;
|
|
4
1
|
var Level;
|
|
5
2
|
(function (Level) {
|
|
6
3
|
Level["TRACE"] = "trace";
|
|
@@ -10,4 +7,5 @@ var Level;
|
|
|
10
7
|
Level["ERROR"] = "error";
|
|
11
8
|
Level["FATAL"] = "fatal";
|
|
12
9
|
Level["OFF"] = "off";
|
|
13
|
-
})(Level || (
|
|
10
|
+
})(Level || (Level = {}));
|
|
11
|
+
export { Level, };
|