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
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Algorithm } from './Algorithm'
|
|
2
|
-
import { SecretLengthError } from './errors/SecretLengthError'
|
|
3
|
-
|
|
4
|
-
const secretLength = {
|
|
5
|
-
[Algorithm.AES128]: 16,
|
|
6
|
-
[Algorithm.AES192]: 24,
|
|
7
|
-
[Algorithm.AES256]: 32,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const validateSecretLength = (algorithm: Algorithm, secret: string): void => {
|
|
11
|
-
if (Buffer.from(secret).length !== secretLength[algorithm]) {
|
|
12
|
-
throw new SecretLengthError()
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
validateSecretLength,
|
|
18
|
-
}
|
package/cli/Args.ts
DELETED
package/cli/Command.ts
DELETED
package/cli/getArgs.ts
DELETED
package/cli/parseArgs.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import yargsParser from 'yargs-parser'
|
|
2
|
-
import type { Args } from './Args'
|
|
3
|
-
|
|
4
|
-
const parseArgs = (args: string[]): Args => {
|
|
5
|
-
const parsed = yargsParser(args, {
|
|
6
|
-
configuration: {
|
|
7
|
-
'boolean-negation': false,
|
|
8
|
-
'camel-case-expansion': true,
|
|
9
|
-
'dot-notation': false,
|
|
10
|
-
'duplicate-arguments-array': false,
|
|
11
|
-
'flatten-duplicate-arrays': false,
|
|
12
|
-
'greedy-arrays': false,
|
|
13
|
-
'parse-numbers': false,
|
|
14
|
-
'parse-positional-numbers': false,
|
|
15
|
-
'short-option-groups': true,
|
|
16
|
-
'strip-dashed': true,
|
|
17
|
-
},
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const positional = parsed._ as string[]
|
|
21
|
-
|
|
22
|
-
const optional = parsed as Record<string, boolean | string | undefined>
|
|
23
|
-
|
|
24
|
-
delete optional._
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
positional,
|
|
28
|
-
optional,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
parseArgs,
|
|
34
|
-
}
|
package/cli/utils/exit.ts
DELETED
package/cli/utils/formatList.ts
DELETED
package/cli/utils/formatTable.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { EOL } from 'os'
|
|
2
|
-
|
|
3
|
-
const formatTable = (table: string[][]): string => {
|
|
4
|
-
const colLength: number[] = []
|
|
5
|
-
|
|
6
|
-
table.forEach((row) => {
|
|
7
|
-
['', ...row].forEach((col, i) => {
|
|
8
|
-
colLength[i] = col.length > (colLength[i] ?? 0)
|
|
9
|
-
? col.length
|
|
10
|
-
: colLength[i] ?? 0
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
return table
|
|
15
|
-
.map((row) => {
|
|
16
|
-
return ['', ...row]
|
|
17
|
-
.map((col, i) => { return col.padEnd(colLength[i], ' ') })
|
|
18
|
-
.join(' ')
|
|
19
|
-
})
|
|
20
|
-
.join(EOL)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
formatTable,
|
|
25
|
-
}
|
package/cli/utils/formatText.ts
DELETED
package/cli/utils/print.ts
DELETED
package/cli/utils/printLn.ts
DELETED
package/config/Config.ts
DELETED
package/config/Properties.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseError } from '../../error/BaseError'
|
|
2
|
-
|
|
3
|
-
class PropertyParseError extends BaseError {
|
|
4
|
-
public constructor(name: string, source: string, message: string) {
|
|
5
|
-
super(`failed parsing property "${name}" from ${source}: ${message}`)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
PropertyParseError,
|
|
11
|
-
}
|
package/config/getConfig.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { getPropertyEnvVar } from './getPropertyEnvVar'
|
|
2
|
-
import { parseProperty } from './parseProperty'
|
|
3
|
-
import { readFile } from './readFile'
|
|
4
|
-
import { validatePropertyName } from './validatePropertyName'
|
|
5
|
-
import type { Config } from './Config'
|
|
6
|
-
import type { Properties } from './Properties'
|
|
7
|
-
import type { Args } from '../cli/Args'
|
|
8
|
-
import type { Env } from '../env/Env'
|
|
9
|
-
|
|
10
|
-
const getConfig = <Type extends Config>(params: {
|
|
11
|
-
properties: Properties<Type>,
|
|
12
|
-
file?: {
|
|
13
|
-
path: string,
|
|
14
|
-
required?: boolean,
|
|
15
|
-
},
|
|
16
|
-
env?: Env,
|
|
17
|
-
args?: Args,
|
|
18
|
-
}): Type => {
|
|
19
|
-
const file = params.file
|
|
20
|
-
? readFile(params.file.path, params.file.required)
|
|
21
|
-
: {}
|
|
22
|
-
|
|
23
|
-
const env: Env = params.env ?? {}
|
|
24
|
-
|
|
25
|
-
const args: Args = params.args ?? { positional: [], optional: {} }
|
|
26
|
-
|
|
27
|
-
const config: Config = {}
|
|
28
|
-
|
|
29
|
-
for (const name in params.properties) {
|
|
30
|
-
validatePropertyName(name)
|
|
31
|
-
|
|
32
|
-
config[name] = parseProperty(
|
|
33
|
-
name,
|
|
34
|
-
params.properties[name].parser,
|
|
35
|
-
params.properties[name].default,
|
|
36
|
-
file[name],
|
|
37
|
-
env[getPropertyEnvVar(name)],
|
|
38
|
-
args.optional[name],
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return config as Type
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
getConfig,
|
|
47
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const capitalLetterRegex = /[A-Z]/gu
|
|
2
|
-
|
|
3
|
-
const capitalLetterReplacer = (letter: string): string => {
|
|
4
|
-
return `_${letter}`
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const getPropertyEnvVar = (name: string): string => {
|
|
8
|
-
return name
|
|
9
|
-
.replace(capitalLetterRegex, capitalLetterReplacer)
|
|
10
|
-
.toUpperCase()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
getPropertyEnvVar,
|
|
15
|
-
}
|
package/config/parseProperty.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { PropertyParseError } from './errors/PropertyParseError'
|
|
2
|
-
import type { Parser } from '../parser/Parser'
|
|
3
|
-
|
|
4
|
-
const parseProperty = <Type>(
|
|
5
|
-
name: string,
|
|
6
|
-
parser: Parser<Type>,
|
|
7
|
-
defaultValue: any,
|
|
8
|
-
fileValue: any,
|
|
9
|
-
envValue: any,
|
|
10
|
-
argsValue: any,
|
|
11
|
-
): Type => {
|
|
12
|
-
const sources = [
|
|
13
|
-
{
|
|
14
|
-
name: 'command line arguments',
|
|
15
|
-
value: argsValue,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: 'environment variables',
|
|
19
|
-
value: envValue,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: 'configuration file',
|
|
23
|
-
value: fileValue,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: 'default value',
|
|
27
|
-
value: defaultValue,
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
const source = sources.find((s) => {
|
|
32
|
-
return s.value !== undefined
|
|
33
|
-
}) || {
|
|
34
|
-
name: 'undefined value',
|
|
35
|
-
value: undefined,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
return parser(source.value)
|
|
40
|
-
} catch (error) {
|
|
41
|
-
throw new PropertyParseError(name, source.name, (error as Error).message)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
parseProperty,
|
|
47
|
-
}
|
package/config/readFile.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra'
|
|
2
|
-
import { FileReadError } from './errors/FileReadError'
|
|
3
|
-
|
|
4
|
-
const readFile = (path: string, required = false): Record<string, any> => {
|
|
5
|
-
let json: any = {}
|
|
6
|
-
let fileExists: boolean
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
fileExists = fs.existsSync(path)
|
|
10
|
-
if (fileExists) {
|
|
11
|
-
json = fs.readJsonSync(path)
|
|
12
|
-
}
|
|
13
|
-
} catch (error) {
|
|
14
|
-
throw new FileReadError(path, (error as Error).message)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (required && !fileExists) {
|
|
18
|
-
throw new FileReadError(path, 'missing file')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
typeof json !== 'object'
|
|
23
|
-
|| Array.isArray(json)
|
|
24
|
-
|| json === null
|
|
25
|
-
) {
|
|
26
|
-
throw new FileReadError(path, 'invalid content')
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return json as Record<string, any>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
readFile,
|
|
34
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { PropertyNameError } from './errors/PropertyNameError'
|
|
2
|
-
|
|
3
|
-
const propertyNameRegex = /^[a-z](?:[0-9A-Za-z])*$/u
|
|
4
|
-
|
|
5
|
-
const validatePropertyName = (name: string): void => {
|
|
6
|
-
if (!propertyNameRegex.test(name)) {
|
|
7
|
-
throw new PropertyNameError(name)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
validatePropertyName,
|
|
13
|
-
}
|
package/env/Env.ts
DELETED
package/env/getEnv.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { readFile } from './readFile'
|
|
2
|
-
import type { Env } from './Env'
|
|
3
|
-
|
|
4
|
-
const getEnv = (params?: {
|
|
5
|
-
file?: {
|
|
6
|
-
path: string,
|
|
7
|
-
required?: boolean,
|
|
8
|
-
},
|
|
9
|
-
}): Env => {
|
|
10
|
-
let file: Env = {}
|
|
11
|
-
|
|
12
|
-
if (params?.file) {
|
|
13
|
-
file = readFile(params.file.path, params.file.required)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
...file,
|
|
18
|
-
...process.env as Env,
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
getEnv,
|
|
24
|
-
}
|
package/env/readFile.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv'
|
|
2
|
-
import fs from 'fs-extra'
|
|
3
|
-
import { FileReadError } from './errors/FileReadError'
|
|
4
|
-
import type { Env } from './Env'
|
|
5
|
-
|
|
6
|
-
const readFile = (path: string, required = false): Env => {
|
|
7
|
-
try {
|
|
8
|
-
if (fs.existsSync(path)) {
|
|
9
|
-
return dotenv.parse(fs.readFileSync(path))
|
|
10
|
-
}
|
|
11
|
-
} catch (error) {
|
|
12
|
-
throw new FileReadError(path, (error as Error).message)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (required) {
|
|
16
|
-
throw new FileReadError(path, 'missing file')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
readFile,
|
|
24
|
-
}
|
package/error/BaseError.ts
DELETED
package/jwt/Algorithm.ts
DELETED
package/jwt/Jwt.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { SignJWT, jwtVerify } from 'jose'
|
|
2
|
-
import { validateSecretLength } from './validateSecretLength'
|
|
3
|
-
import type { Algorithm } from './Algorithm'
|
|
4
|
-
import type { Payload } from './Payload'
|
|
5
|
-
|
|
6
|
-
class Jwt {
|
|
7
|
-
private readonly algorithm: Algorithm
|
|
8
|
-
|
|
9
|
-
private readonly secret: Uint8Array
|
|
10
|
-
|
|
11
|
-
public constructor(params: {
|
|
12
|
-
algorithm: Algorithm,
|
|
13
|
-
secret: string,
|
|
14
|
-
}) {
|
|
15
|
-
validateSecretLength(params.algorithm, params.secret)
|
|
16
|
-
|
|
17
|
-
this.algorithm = params.algorithm
|
|
18
|
-
this.secret = new TextEncoder().encode(params.secret)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async createToken(payload: Payload): Promise<string> {
|
|
22
|
-
return new SignJWT(payload)
|
|
23
|
-
.setProtectedHeader({
|
|
24
|
-
typ: 'JWT',
|
|
25
|
-
alg: this.algorithm,
|
|
26
|
-
})
|
|
27
|
-
.sign(this.secret)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public async verifyToken<Type extends Payload>(
|
|
31
|
-
token: string,
|
|
32
|
-
timestamp: number,
|
|
33
|
-
): Promise<Type | undefined> {
|
|
34
|
-
try {
|
|
35
|
-
const { payload } = await jwtVerify(token, this.secret, {
|
|
36
|
-
typ: 'JWT',
|
|
37
|
-
currentDate: new Date(timestamp * 1000),
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
return payload as Type
|
|
41
|
-
} catch (error) {
|
|
42
|
-
return undefined
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
Jwt,
|
|
49
|
-
}
|
package/jwt/Payload.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Algorithm } from './Algorithm'
|
|
2
|
-
import { SecretLengthError } from './errors/SecretLengthError'
|
|
3
|
-
|
|
4
|
-
const minSecretLength = {
|
|
5
|
-
[Algorithm.HS256]: 32,
|
|
6
|
-
[Algorithm.HS384]: 48,
|
|
7
|
-
[Algorithm.HS512]: 64,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const validateSecretLength = (algorithm: Algorithm, secret: string): void => {
|
|
11
|
-
if (Buffer.from(secret).length < minSecretLength[algorithm]) {
|
|
12
|
-
throw new SecretLengthError()
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
validateSecretLength,
|
|
18
|
-
}
|
package/logger/Level.ts
DELETED
package/logger/Logger.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
Logger,
|
|
19
|
-
}
|