apeframework 0.0.0-dev.3 → 0.0.0-dev.5
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 +0 -14
- package/api/Api.d.ts +28 -0
- package/api/Api.js +72 -0
- package/api/Api.ts +104 -0
- package/api/Endpoint.d.ts +12 -0
- package/api/Endpoint.ts +16 -0
- package/api/ErrorHandler.d.ts +3 -0
- package/api/ErrorHandler.ts +11 -0
- package/api/Handler.d.ts +3 -0
- package/api/Handler.ts +10 -0
- package/api/Method.d.ts +8 -0
- package/api/Method.js +11 -0
- package/api/Method.ts +11 -0
- package/api/Schema.d.ts +9 -0
- package/api/Schema.ts +13 -0
- package/cipher/Cipher.js +2 -2
- package/cipher/Cipher.ts +2 -2
- package/cipher/errors/{CipherDecryptError.d.ts → DecryptError.d.ts} +2 -2
- package/cipher/errors/{CipherDecryptError.js → DecryptError.js} +3 -3
- package/cipher/errors/{CipherDecryptError.ts → DecryptError.ts} +2 -2
- package/cipher/errors/SecretLengthError.d.ts +5 -0
- package/{jwt/errors/JwtSecretLengthError.js → cipher/errors/SecretLengthError.js} +3 -3
- package/{jwt/errors/JwtSecretLengthError.ts → cipher/errors/SecretLengthError.ts} +2 -2
- package/cipher/validateSecretLength.js +2 -2
- package/cipher/validateSecretLength.ts +2 -2
- package/cli/utils/print.d.ts +2 -0
- package/cli/utils/{write.js → print.js} +3 -3
- package/cli/utils/print.ts +7 -0
- package/cli/utils/printLn.d.ts +2 -0
- package/cli/utils/{writeLn.js → printLn.js} +3 -3
- package/cli/utils/{writeLn.ts → printLn.ts} +2 -2
- package/{env/errors/EnvFileReadError.d.ts → config/errors/FileReadError.d.ts} +2 -2
- package/{tls/errors/TlsFileReadError.js → config/errors/FileReadError.js} +3 -3
- package/{env/errors/EnvFileReadError.ts → config/errors/FileReadError.ts} +2 -2
- package/config/errors/PropertyNameError.d.ts +5 -0
- package/config/errors/{ConfigPropertyNameError.js → PropertyNameError.js} +3 -3
- package/config/errors/{ConfigPropertyNameError.ts → PropertyNameError.ts} +2 -2
- package/config/errors/PropertyParseError.d.ts +5 -0
- package/config/errors/PropertyParseError.js +10 -0
- package/config/errors/PropertyParseError.ts +11 -0
- package/config/parseProperty.js +2 -2
- package/config/parseProperty.ts +2 -2
- package/config/readFile.js +4 -4
- package/config/readFile.ts +4 -4
- package/config/validatePropertyName.js +2 -2
- package/config/validatePropertyName.ts +2 -2
- package/{tls/errors/TlsFileReadError.d.ts → env/errors/FileReadError.d.ts} +2 -2
- package/env/errors/{EnvFileReadError.js → FileReadError.js} +3 -3
- package/{tls/errors/TlsFileReadError.ts → env/errors/FileReadError.ts} +2 -2
- package/env/readFile.js +3 -3
- package/env/readFile.ts +3 -3
- package/jwt/Jwt.d.ts +0 -6
- package/jwt/Jwt.js +8 -34
- package/jwt/Jwt.ts +8 -51
- package/jwt/Payload.d.ts +7 -3
- package/jwt/Payload.ts +7 -3
- package/jwt/errors/SecretLengthError.d.ts +5 -0
- package/{cipher/errors/CipherSecretLengthError.js → jwt/errors/SecretLengthError.js} +3 -3
- package/{cipher/errors/CipherSecretLengthError.ts → jwt/errors/SecretLengthError.ts} +2 -2
- package/jwt/validateSecretLength.js +2 -2
- package/jwt/validateSecretLength.ts +2 -2
- package/logger/Level.d.ts +7 -6
- package/logger/Level.js +7 -6
- package/logger/Level.ts +7 -6
- package/logger/Logger.d.ts +9 -9
- package/logger/Logger.js +4 -0
- package/logger/Logger.ts +15 -9
- package/logger/Severity.d.ts +6 -7
- package/logger/Severity.js +6 -7
- package/logger/Severity.ts +6 -7
- package/logger/adapters/file/FileLogger.d.ts +5 -5
- package/logger/adapters/file/FileLogger.js +17 -17
- package/logger/adapters/file/FileLogger.ts +19 -19
- package/logger/adapters/noop/NoopLogger.d.ts +2 -2
- package/logger/adapters/noop/NoopLogger.js +2 -1
- package/logger/adapters/noop/NoopLogger.ts +2 -2
- package/logger/adapters/stdio/StdioLogger.d.ts +5 -5
- package/logger/adapters/stdio/StdioLogger.js +19 -17
- package/logger/adapters/stdio/StdioLogger.ts +21 -19
- package/mailer/Event.d.ts +4 -4
- package/mailer/Event.ts +4 -4
- package/mailer/{EventLocation.d.ts → Location.d.ts} +2 -2
- package/mailer/Location.js +2 -0
- package/mailer/{EventLocation.ts → Location.ts} +2 -2
- package/mailer/Mailer.d.ts +5 -4
- package/mailer/Mailer.js +48 -0
- package/mailer/Mailer.ts +63 -4
- package/mailer/Method.d.ts +5 -0
- package/mailer/Method.js +8 -0
- package/mailer/{EventMethod.ts → Method.ts} +2 -2
- package/mailer/adapters/noop/NoopMailer.d.ts +3 -3
- package/mailer/adapters/noop/NoopMailer.js +3 -2
- package/mailer/adapters/noop/NoopMailer.ts +3 -3
- package/mailer/adapters/smtp/SmtpMailer.d.ts +3 -3
- package/mailer/adapters/smtp/SmtpMailer.js +4 -2
- package/mailer/adapters/smtp/SmtpMailer.ts +5 -3
- package/mailer/errors/AddressEmailError.d.ts +5 -0
- package/mailer/errors/{MailerAddressEmailError.js → AddressEmailError.js} +3 -3
- package/mailer/errors/{MailerAddressEmailError.ts → AddressEmailError.ts} +2 -2
- package/mailer/errors/EventAttachmentUrlError.d.ts +5 -0
- package/mailer/errors/{MailerEventAttachmentUrlError.js → EventAttachmentUrlError.js} +3 -3
- package/mailer/errors/{MailerEventAttachmentUrlError.ts → EventAttachmentUrlError.ts} +2 -2
- package/mailer/errors/{MailerEventGeolocationError.d.ts → EventGeolocationError.d.ts} +2 -2
- package/mailer/errors/{MailerEventGeolocationError.js → EventGeolocationError.js} +3 -3
- package/mailer/errors/{MailerEventGeolocationError.ts → EventGeolocationError.ts} +2 -2
- package/mailer/errors/EventUrlError.d.ts +5 -0
- package/mailer/errors/{MailerEventUrlError.js → EventUrlError.js} +3 -3
- package/mailer/errors/{MailerEventUrlError.ts → EventUrlError.ts} +2 -2
- package/mailer/errors/{MailerListUrlError.d.ts → ListUrlError.d.ts} +2 -2
- package/mailer/errors/{MailerListUrlError.js → ListUrlError.js} +3 -3
- package/mailer/errors/{MailerListUrlError.ts → ListUrlError.ts} +2 -2
- package/mailer/validateAddressEmail.js +2 -2
- package/mailer/validateAddressEmail.ts +2 -2
- package/mailer/validateEventAttachmentUrl.js +2 -2
- package/mailer/validateEventAttachmentUrl.ts +2 -2
- package/mailer/validateEventGeolocation.js +2 -2
- package/mailer/validateEventGeolocation.ts +2 -2
- package/mailer/validateEventUrl.js +2 -2
- package/mailer/validateEventUrl.ts +2 -2
- package/mailer/validateListUrl.js +2 -2
- package/mailer/validateListUrl.ts +2 -2
- package/package.json +1 -5
- package/parser/errors/{ParserInputError.d.ts → ParseError.d.ts} +2 -2
- package/parser/errors/ParseError.js +10 -0
- package/parser/errors/ParseError.ts +11 -0
- package/parser/factories/unit/createUnitParser.js +3 -3
- package/parser/factories/unit/createUnitParser.ts +3 -3
- package/parser/parseBoolean.js +2 -2
- package/parser/parseBoolean.ts +2 -2
- package/parser/parseInteger.js +3 -3
- package/parser/parseInteger.ts +3 -3
- package/parser/parseNumber.js +3 -3
- package/parser/parseNumber.ts +3 -3
- package/parser/parseString.js +2 -2
- package/parser/parseString.ts +2 -2
- package/pwd/errors/{PwdHashRoundsError.d.ts → HashRoundsError.d.ts} +2 -2
- package/pwd/errors/{PwdHashRoundsError.js → HashRoundsError.js} +3 -3
- package/pwd/errors/{PwdHashRoundsError.ts → HashRoundsError.ts} +2 -2
- package/pwd/validateHashRounds.js +2 -2
- package/pwd/validateHashRounds.ts +2 -2
- package/{config/errors/ConfigFileReadError.d.ts → tls/errors/FileReadError.d.ts} +2 -2
- package/{config/errors/ConfigFileReadError.js → tls/errors/FileReadError.js} +3 -3
- package/{config/errors/ConfigFileReadError.ts → tls/errors/FileReadError.ts} +2 -2
- package/tls/readFile.js +3 -3
- package/tls/readFile.ts +3 -3
- package/cipher/errors/CipherSecretLengthError.d.ts +0 -5
- package/cli/utils/write.d.ts +0 -2
- package/cli/utils/write.ts +0 -7
- package/cli/utils/writeLn.d.ts +0 -2
- package/config/errors/ConfigParseError.d.ts +0 -5
- package/config/errors/ConfigParseError.js +0 -10
- package/config/errors/ConfigParseError.ts +0 -11
- package/config/errors/ConfigPropertyNameError.d.ts +0 -5
- package/db/ColumnBuilder.d.ts +0 -13
- package/db/ColumnBuilder.js +0 -42
- package/db/ColumnBuilder.ts +0 -61
- package/db/Database.d.ts +0 -19
- package/db/Database.js +0 -49
- package/db/Database.ts +0 -74
- package/db/Driver.d.ts +0 -30
- package/db/Driver.ts +0 -33
- package/db/NullConstraint.d.ts +0 -2
- package/db/NullConstraint.ts +0 -5
- package/db/ReferentialAction.d.ts +0 -2
- package/db/ReferentialAction.ts +0 -5
- package/db/TableBuilder.d.ts +0 -49
- package/db/TableBuilder.js +0 -234
- package/db/TableBuilder.ts +0 -367
- package/db/adapters/mysql/createMysqlDatabase.d.ts +0 -12
- package/db/adapters/mysql/createMysqlDatabase.js +0 -32
- package/db/adapters/mysql/createMysqlDatabase.ts +0 -39
- package/db/adapters/mysql/driver.d.ts +0 -3
- package/db/adapters/mysql/driver.js +0 -43
- package/db/adapters/mysql/driver.ts +0 -45
- package/db/adapters/mysql/typeCast.d.ts +0 -2
- package/db/adapters/mysql/typeCast.js +0 -17
- package/db/adapters/mysql/typeCast.ts +0 -18
- package/db/adapters/postgres/driver.d.ts +0 -3
- package/db/adapters/postgres/driver.js +0 -43
- package/db/adapters/postgres/driver.ts +0 -45
- package/db/adapters/sqlite/driver.d.ts +0 -3
- package/db/adapters/sqlite/driver.js +0 -43
- package/db/adapters/sqlite/driver.ts +0 -45
- package/db/errors/DbColumnLengthError.d.ts +0 -5
- package/db/errors/DbColumnLengthError.js +0 -10
- package/db/errors/DbColumnLengthError.ts +0 -11
- package/db/errors/DbColumnMaxLengthError.d.ts +0 -5
- package/db/errors/DbColumnMaxLengthError.js +0 -10
- package/db/errors/DbColumnMaxLengthError.ts +0 -11
- package/db/errors/DbColumnPrecisionError.d.ts +0 -5
- package/db/errors/DbColumnPrecisionError.js +0 -10
- package/db/errors/DbColumnPrecisionError.ts +0 -11
- package/db/errors/DbColumnScaleError.d.ts +0 -5
- package/db/errors/DbColumnScaleError.js +0 -10
- package/db/errors/DbColumnScaleError.ts +0 -11
- package/db/getConstraintName.d.ts +0 -2
- package/db/getConstraintName.js +0 -15
- package/db/getConstraintName.ts +0 -18
- package/db/getReferentialActionSql.d.ts +0 -3
- package/db/getReferentialActionSql.js +0 -12
- package/db/getReferentialActionSql.ts +0 -17
- package/db/setNullConstraint.d.ts +0 -4
- package/db/setNullConstraint.js +0 -9
- package/db/setNullConstraint.ts +0 -15
- package/db/validateColumnLength.d.ts +0 -2
- package/db/validateColumnLength.js +0 -10
- package/db/validateColumnLength.ts +0 -11
- package/db/validateColumnMaxLength.d.ts +0 -2
- package/db/validateColumnMaxLength.js +0 -10
- package/db/validateColumnMaxLength.ts +0 -11
- package/db/validateColumnPrecision.d.ts +0 -2
- package/db/validateColumnPrecision.js +0 -14
- package/db/validateColumnPrecision.ts +0 -15
- package/jwt/errors/JwtSecretLengthError.d.ts +0 -5
- package/mailer/EventMethod.d.ts +0 -5
- package/mailer/EventMethod.js +0 -8
- package/mailer/errors/MailerAddressEmailError.d.ts +0 -5
- package/mailer/errors/MailerEventAttachmentUrlError.d.ts +0 -5
- package/mailer/errors/MailerEventUrlError.d.ts +0 -5
- package/parser/errors/ParserInputError.js +0 -10
- package/parser/errors/ParserInputError.ts +0 -11
- /package/{db/Driver.js → api/Endpoint.js} +0 -0
- /package/{db/NullConstraint.js → api/ErrorHandler.js} +0 -0
- /package/{db/ReferentialAction.js → api/Handler.js} +0 -0
- /package/{mailer/EventLocation.js → api/Schema.js} +0 -0
package/config/parseProperty.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseProperty = void 0;
|
|
4
|
-
const
|
|
4
|
+
const PropertyParseError_1 = require("./errors/PropertyParseError");
|
|
5
5
|
const parseProperty = (name, parser, defaultValue, fileValue, envValue, argsValue) => {
|
|
6
6
|
const sources = [
|
|
7
7
|
{
|
|
@@ -31,7 +31,7 @@ const parseProperty = (name, parser, defaultValue, fileValue, envValue, argsValu
|
|
|
31
31
|
return parser(source.value);
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new PropertyParseError_1.PropertyParseError(name, source.name, error.message);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
exports.parseProperty = parseProperty;
|
package/config/parseProperty.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropertyParseError } from './errors/PropertyParseError'
|
|
2
2
|
import type { Parser } from '../parser/Parser'
|
|
3
3
|
|
|
4
4
|
const parseProperty = <Type>(
|
|
@@ -38,7 +38,7 @@ const parseProperty = <Type>(
|
|
|
38
38
|
try {
|
|
39
39
|
return parser(source.value)
|
|
40
40
|
} catch (error) {
|
|
41
|
-
throw new
|
|
41
|
+
throw new PropertyParseError(name, source.name, (error as Error).message)
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
package/config/readFile.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readFile = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const
|
|
8
|
+
const FileReadError_1 = require("./errors/FileReadError");
|
|
9
9
|
const readFile = (path, required = false) => {
|
|
10
10
|
let json = {};
|
|
11
11
|
let fileExists;
|
|
@@ -16,15 +16,15 @@ const readFile = (path, required = false) => {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
|
-
throw new
|
|
19
|
+
throw new FileReadError_1.FileReadError(path, error.message);
|
|
20
20
|
}
|
|
21
21
|
if (required && !fileExists) {
|
|
22
|
-
throw new
|
|
22
|
+
throw new FileReadError_1.FileReadError(path, 'missing file');
|
|
23
23
|
}
|
|
24
24
|
if (typeof json !== 'object'
|
|
25
25
|
|| Array.isArray(json)
|
|
26
26
|
|| json === null) {
|
|
27
|
-
throw new
|
|
27
|
+
throw new FileReadError_1.FileReadError(path, 'invalid content');
|
|
28
28
|
}
|
|
29
29
|
return json;
|
|
30
30
|
};
|
package/config/readFile.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'fs-extra'
|
|
2
|
-
import {
|
|
2
|
+
import { FileReadError } from './errors/FileReadError'
|
|
3
3
|
|
|
4
4
|
const readFile = (path: string, required = false): Record<string, any> => {
|
|
5
5
|
let json: any = {}
|
|
@@ -11,11 +11,11 @@ const readFile = (path: string, required = false): Record<string, any> => {
|
|
|
11
11
|
json = fs.readJsonSync(path)
|
|
12
12
|
}
|
|
13
13
|
} catch (error) {
|
|
14
|
-
throw new
|
|
14
|
+
throw new FileReadError(path, (error as Error).message)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (required && !fileExists) {
|
|
18
|
-
throw new
|
|
18
|
+
throw new FileReadError(path, 'missing file')
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
if (
|
|
@@ -23,7 +23,7 @@ const readFile = (path: string, required = false): Record<string, any> => {
|
|
|
23
23
|
|| Array.isArray(json)
|
|
24
24
|
|| json === null
|
|
25
25
|
) {
|
|
26
|
-
throw new
|
|
26
|
+
throw new FileReadError(path, 'invalid content')
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
return json as Record<string, any>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validatePropertyName = void 0;
|
|
4
|
-
const
|
|
4
|
+
const PropertyNameError_1 = require("./errors/PropertyNameError");
|
|
5
5
|
const propertyNameRegex = /^[a-z](?:[0-9A-Za-z])*$/u;
|
|
6
6
|
const validatePropertyName = (name) => {
|
|
7
7
|
if (!propertyNameRegex.test(name)) {
|
|
8
|
-
throw new
|
|
8
|
+
throw new PropertyNameError_1.PropertyNameError(name);
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
exports.validatePropertyName = validatePropertyName;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropertyNameError } from './errors/PropertyNameError'
|
|
2
2
|
|
|
3
3
|
const propertyNameRegex = /^[a-z](?:[0-9A-Za-z])*$/u
|
|
4
4
|
|
|
5
5
|
const validatePropertyName = (name: string): void => {
|
|
6
6
|
if (!propertyNameRegex.test(name)) {
|
|
7
|
-
throw new
|
|
7
|
+
throw new PropertyNameError(name)
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FileReadError = void 0;
|
|
4
4
|
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class
|
|
5
|
+
class FileReadError extends BaseError_1.BaseError {
|
|
6
6
|
constructor(path, message) {
|
|
7
7
|
super(`failed reading file "${path}": ${message}`);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
exports.
|
|
10
|
+
exports.FileReadError = FileReadError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseError } from '../../error/BaseError'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class FileReadError extends BaseError {
|
|
4
4
|
public constructor(path: string, message: string) {
|
|
5
5
|
super(`failed reading file "${path}": ${message}`)
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
FileReadError,
|
|
11
11
|
}
|
package/env/readFile.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.readFile = void 0;
|
|
7
7
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const
|
|
9
|
+
const FileReadError_1 = require("./errors/FileReadError");
|
|
10
10
|
const readFile = (path, required = false) => {
|
|
11
11
|
try {
|
|
12
12
|
if (fs_extra_1.default.existsSync(path)) {
|
|
@@ -14,10 +14,10 @@ const readFile = (path, required = false) => {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
catch (error) {
|
|
17
|
-
throw new
|
|
17
|
+
throw new FileReadError_1.FileReadError(path, error.message);
|
|
18
18
|
}
|
|
19
19
|
if (required) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new FileReadError_1.FileReadError(path, 'missing file');
|
|
21
21
|
}
|
|
22
22
|
return {};
|
|
23
23
|
};
|
package/env/readFile.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dotenv from 'dotenv'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
|
-
import {
|
|
3
|
+
import { FileReadError } from './errors/FileReadError'
|
|
4
4
|
import type { Env } from './Env'
|
|
5
5
|
|
|
6
6
|
const readFile = (path: string, required = false): Env => {
|
|
@@ -9,11 +9,11 @@ const readFile = (path: string, required = false): Env => {
|
|
|
9
9
|
return dotenv.parse(fs.readFileSync(path))
|
|
10
10
|
}
|
|
11
11
|
} catch (error) {
|
|
12
|
-
throw new
|
|
12
|
+
throw new FileReadError(path, (error as Error).message)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (required) {
|
|
16
|
-
throw new
|
|
16
|
+
throw new FileReadError(path, 'missing file')
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
return {}
|
package/jwt/Jwt.d.ts
CHANGED
|
@@ -3,15 +3,9 @@ import type { Payload } from './Payload';
|
|
|
3
3
|
declare class Jwt {
|
|
4
4
|
private readonly algorithm;
|
|
5
5
|
private readonly secret;
|
|
6
|
-
private readonly issuer;
|
|
7
|
-
private readonly audience;
|
|
8
|
-
private readonly expiration;
|
|
9
6
|
constructor(params: {
|
|
10
7
|
algorithm: Algorithm;
|
|
11
8
|
secret: string;
|
|
12
|
-
issuer: string;
|
|
13
|
-
audience: string;
|
|
14
|
-
expiration?: number;
|
|
15
9
|
});
|
|
16
10
|
createToken(payload: Payload): Promise<string>;
|
|
17
11
|
verifyToken<Type extends Payload>(token: string, timestamp: number): Promise<Type | undefined>;
|
package/jwt/Jwt.js
CHANGED
|
@@ -6,52 +6,26 @@ const validateSecretLength_1 = require("./validateSecretLength");
|
|
|
6
6
|
class Jwt {
|
|
7
7
|
algorithm;
|
|
8
8
|
secret;
|
|
9
|
-
issuer;
|
|
10
|
-
audience;
|
|
11
|
-
expiration;
|
|
12
9
|
constructor(params) {
|
|
13
10
|
(0, validateSecretLength_1.validateSecretLength)(params.algorithm, params.secret);
|
|
14
11
|
this.algorithm = params.algorithm;
|
|
15
12
|
this.secret = new TextEncoder().encode(params.secret);
|
|
16
|
-
this.issuer = params.issuer;
|
|
17
|
-
this.audience = params.audience;
|
|
18
|
-
this.expiration = params.expiration;
|
|
19
13
|
}
|
|
20
14
|
async createToken(payload) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
.setAudience(this.audience)
|
|
28
|
-
.setSubject(payload.subject)
|
|
29
|
-
.setIssuedAt(payload.issuedAt);
|
|
30
|
-
if (this.expiration) {
|
|
31
|
-
jwt.setExpirationTime(payload.issuedAt + this.expiration);
|
|
32
|
-
}
|
|
33
|
-
if (payload.id) {
|
|
34
|
-
jwt.setJti(payload.id);
|
|
35
|
-
}
|
|
36
|
-
return jwt.sign(this.secret);
|
|
15
|
+
return new jose_1.SignJWT(payload)
|
|
16
|
+
.setProtectedHeader({
|
|
17
|
+
typ: 'JWT',
|
|
18
|
+
alg: this.algorithm,
|
|
19
|
+
})
|
|
20
|
+
.sign(this.secret);
|
|
37
21
|
}
|
|
38
22
|
async verifyToken(token, timestamp) {
|
|
39
23
|
try {
|
|
40
|
-
const { payload
|
|
24
|
+
const { payload } = await (0, jose_1.jwtVerify)(token, this.secret, {
|
|
41
25
|
typ: 'JWT',
|
|
42
|
-
algorithms: [this.algorithm],
|
|
43
|
-
audience: this.audience,
|
|
44
26
|
currentDate: new Date(timestamp * 1000),
|
|
45
27
|
});
|
|
46
|
-
|
|
47
|
-
return !['iss', 'aud', 'sub', 'iat', 'exp', 'jti'].includes(key);
|
|
48
|
-
}));
|
|
49
|
-
return {
|
|
50
|
-
subject: jwt.sub,
|
|
51
|
-
issuedAt: jwt.iat,
|
|
52
|
-
...jwt.jti ? { id: jwt.jti } : {},
|
|
53
|
-
...payload,
|
|
54
|
-
};
|
|
28
|
+
return payload;
|
|
55
29
|
}
|
|
56
30
|
catch (error) {
|
|
57
31
|
return undefined;
|
package/jwt/Jwt.ts
CHANGED
|
@@ -8,53 +8,23 @@ class Jwt {
|
|
|
8
8
|
|
|
9
9
|
private readonly secret: Uint8Array
|
|
10
10
|
|
|
11
|
-
private readonly issuer: string
|
|
12
|
-
|
|
13
|
-
private readonly audience: string
|
|
14
|
-
|
|
15
|
-
private readonly expiration: number | undefined
|
|
16
|
-
|
|
17
11
|
public constructor(params: {
|
|
18
12
|
algorithm: Algorithm,
|
|
19
13
|
secret: string,
|
|
20
|
-
issuer: string,
|
|
21
|
-
audience: string,
|
|
22
|
-
expiration?: number,
|
|
23
14
|
}) {
|
|
24
15
|
validateSecretLength(params.algorithm, params.secret)
|
|
25
16
|
|
|
26
17
|
this.algorithm = params.algorithm
|
|
27
18
|
this.secret = new TextEncoder().encode(params.secret)
|
|
28
|
-
this.issuer = params.issuer
|
|
29
|
-
this.audience = params.audience
|
|
30
|
-
this.expiration = params.expiration
|
|
31
19
|
}
|
|
32
20
|
|
|
33
21
|
public async createToken(payload: Payload): Promise<string> {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
jwt
|
|
43
|
-
.setProtectedHeader({ typ: 'JWT', alg: this.algorithm })
|
|
44
|
-
.setIssuer(this.issuer)
|
|
45
|
-
.setAudience(this.audience)
|
|
46
|
-
.setSubject(payload.subject)
|
|
47
|
-
.setIssuedAt(payload.issuedAt)
|
|
48
|
-
|
|
49
|
-
if (this.expiration) {
|
|
50
|
-
jwt.setExpirationTime(payload.issuedAt + this.expiration)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (payload.id) {
|
|
54
|
-
jwt.setJti(payload.id)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return jwt.sign(this.secret)
|
|
22
|
+
return new SignJWT(payload)
|
|
23
|
+
.setProtectedHeader({
|
|
24
|
+
typ: 'JWT',
|
|
25
|
+
alg: this.algorithm,
|
|
26
|
+
})
|
|
27
|
+
.sign(this.secret)
|
|
58
28
|
}
|
|
59
29
|
|
|
60
30
|
public async verifyToken<Type extends Payload>(
|
|
@@ -62,25 +32,12 @@ class Jwt {
|
|
|
62
32
|
timestamp: number,
|
|
63
33
|
): Promise<Type | undefined> {
|
|
64
34
|
try {
|
|
65
|
-
const { payload
|
|
35
|
+
const { payload } = await jwtVerify(token, this.secret, {
|
|
66
36
|
typ: 'JWT',
|
|
67
|
-
algorithms: [this.algorithm],
|
|
68
|
-
audience: this.audience,
|
|
69
37
|
currentDate: new Date(timestamp * 1000),
|
|
70
38
|
})
|
|
71
39
|
|
|
72
|
-
|
|
73
|
-
Object.entries(jwt).filter(([key]) => {
|
|
74
|
-
return !['iss', 'aud', 'sub', 'iat', 'exp', 'jti'].includes(key)
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
subject: jwt.sub,
|
|
80
|
-
issuedAt: jwt.iat,
|
|
81
|
-
...jwt.jti ? { id: jwt.jti } : {},
|
|
82
|
-
...payload,
|
|
83
|
-
} as Type
|
|
40
|
+
return payload as Type
|
|
84
41
|
} catch (error) {
|
|
85
42
|
return undefined
|
|
86
43
|
}
|
package/jwt/Payload.d.ts
CHANGED
package/jwt/Payload.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SecretLengthError = void 0;
|
|
4
4
|
const BaseError_1 = require("../../error/BaseError");
|
|
5
|
-
class
|
|
5
|
+
class SecretLengthError extends BaseError_1.BaseError {
|
|
6
6
|
constructor() {
|
|
7
7
|
super('invalid secret length');
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
exports.
|
|
10
|
+
exports.SecretLengthError = SecretLengthError;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseError } from '../../error/BaseError'
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class SecretLengthError extends BaseError {
|
|
4
4
|
public constructor() {
|
|
5
5
|
super('invalid secret length')
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
SecretLengthError,
|
|
11
11
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateSecretLength = void 0;
|
|
4
4
|
const Algorithm_1 = require("./Algorithm");
|
|
5
|
-
const
|
|
5
|
+
const SecretLengthError_1 = require("./errors/SecretLengthError");
|
|
6
6
|
const minSecretLength = {
|
|
7
7
|
[Algorithm_1.Algorithm.HS256]: 32,
|
|
8
8
|
[Algorithm_1.Algorithm.HS384]: 48,
|
|
@@ -10,7 +10,7 @@ const minSecretLength = {
|
|
|
10
10
|
};
|
|
11
11
|
const validateSecretLength = (algorithm, secret) => {
|
|
12
12
|
if (Buffer.from(secret).length < minSecretLength[algorithm]) {
|
|
13
|
-
throw new
|
|
13
|
+
throw new SecretLengthError_1.SecretLengthError();
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
exports.validateSecretLength = validateSecretLength;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Algorithm } from './Algorithm'
|
|
2
|
-
import {
|
|
2
|
+
import { SecretLengthError } from './errors/SecretLengthError'
|
|
3
3
|
|
|
4
4
|
const minSecretLength = {
|
|
5
5
|
[Algorithm.HS256]: 32,
|
|
@@ -9,7 +9,7 @@ const minSecretLength = {
|
|
|
9
9
|
|
|
10
10
|
const validateSecretLength = (algorithm: Algorithm, secret: string): void => {
|
|
11
11
|
if (Buffer.from(secret).length < minSecretLength[algorithm]) {
|
|
12
|
-
throw new
|
|
12
|
+
throw new SecretLengthError()
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
package/logger/Level.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
declare enum Level {
|
|
2
|
-
TRACE =
|
|
3
|
-
DEBUG =
|
|
4
|
-
INFO =
|
|
5
|
-
WARN =
|
|
6
|
-
ERROR =
|
|
7
|
-
FATAL =
|
|
2
|
+
TRACE = "trace",
|
|
3
|
+
DEBUG = "debug",
|
|
4
|
+
INFO = "info",
|
|
5
|
+
WARN = "warn",
|
|
6
|
+
ERROR = "error",
|
|
7
|
+
FATAL = "fatal",
|
|
8
|
+
OFF = "off"
|
|
8
9
|
}
|
|
9
10
|
export { Level, };
|
package/logger/Level.js
CHANGED
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Level = void 0;
|
|
4
4
|
var Level;
|
|
5
5
|
(function (Level) {
|
|
6
|
-
Level[
|
|
7
|
-
Level[
|
|
8
|
-
Level[
|
|
9
|
-
Level[
|
|
10
|
-
Level[
|
|
11
|
-
Level[
|
|
6
|
+
Level["TRACE"] = "trace";
|
|
7
|
+
Level["DEBUG"] = "debug";
|
|
8
|
+
Level["INFO"] = "info";
|
|
9
|
+
Level["WARN"] = "warn";
|
|
10
|
+
Level["ERROR"] = "error";
|
|
11
|
+
Level["FATAL"] = "fatal";
|
|
12
|
+
Level["OFF"] = "off";
|
|
12
13
|
})(Level || (exports.Level = Level = {}));
|
package/logger/Level.ts
CHANGED
package/logger/Logger.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
trace
|
|
3
|
-
debug
|
|
4
|
-
info
|
|
5
|
-
warn
|
|
6
|
-
error
|
|
7
|
-
fatal
|
|
8
|
-
close
|
|
1
|
+
declare abstract class Logger {
|
|
2
|
+
abstract trace(message: string, data?: unknown): void;
|
|
3
|
+
abstract debug(message: string, data?: unknown): void;
|
|
4
|
+
abstract info(message: string, data?: unknown): void;
|
|
5
|
+
abstract warn(message: string, data?: unknown): void;
|
|
6
|
+
abstract error(message: string, data?: unknown): void;
|
|
7
|
+
abstract fatal(message: string, data?: unknown): void;
|
|
8
|
+
abstract close(): Promise<void>;
|
|
9
9
|
}
|
|
10
|
-
export {
|
|
10
|
+
export { Logger, };
|
package/logger/Logger.js
CHANGED
package/logger/Logger.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
trace
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
abstract class Logger {
|
|
2
|
+
public abstract trace(message: string, data?: unknown): void
|
|
3
|
+
|
|
4
|
+
public abstract debug(message: string, data?: unknown): void
|
|
5
|
+
|
|
6
|
+
public abstract info(message: string, data?: unknown): void
|
|
7
|
+
|
|
8
|
+
public abstract warn(message: string, data?: unknown): void
|
|
9
|
+
|
|
10
|
+
public abstract error(message: string, data?: unknown): void
|
|
11
|
+
|
|
12
|
+
public abstract fatal(message: string, data?: unknown): void
|
|
13
|
+
|
|
14
|
+
public abstract close(): Promise<void>
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
export {
|
|
12
|
-
|
|
18
|
+
Logger,
|
|
13
19
|
}
|
package/logger/Severity.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
declare enum Severity {
|
|
2
|
-
TRACE =
|
|
3
|
-
DEBUG =
|
|
4
|
-
INFO =
|
|
5
|
-
WARN =
|
|
6
|
-
ERROR =
|
|
7
|
-
FATAL =
|
|
8
|
-
OFF = "off"
|
|
2
|
+
TRACE = 10,
|
|
3
|
+
DEBUG = 20,
|
|
4
|
+
INFO = 30,
|
|
5
|
+
WARN = 40,
|
|
6
|
+
ERROR = 50,
|
|
7
|
+
FATAL = 60
|
|
9
8
|
}
|
|
10
9
|
export { Severity, };
|
package/logger/Severity.js
CHANGED
|
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Severity = void 0;
|
|
4
4
|
var Severity;
|
|
5
5
|
(function (Severity) {
|
|
6
|
-
Severity["TRACE"] = "
|
|
7
|
-
Severity["DEBUG"] = "
|
|
8
|
-
Severity["INFO"] = "
|
|
9
|
-
Severity["WARN"] = "
|
|
10
|
-
Severity["ERROR"] = "
|
|
11
|
-
Severity["FATAL"] = "
|
|
12
|
-
Severity["OFF"] = "off";
|
|
6
|
+
Severity[Severity["TRACE"] = 10] = "TRACE";
|
|
7
|
+
Severity[Severity["DEBUG"] = 20] = "DEBUG";
|
|
8
|
+
Severity[Severity["INFO"] = 30] = "INFO";
|
|
9
|
+
Severity[Severity["WARN"] = 40] = "WARN";
|
|
10
|
+
Severity[Severity["ERROR"] = 50] = "ERROR";
|
|
11
|
+
Severity[Severity["FATAL"] = 60] = "FATAL";
|
|
13
12
|
})(Severity || (exports.Severity = Severity = {}));
|
package/logger/Severity.ts
CHANGED