raiton 3.0.2 → 3.1.0
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/CHANGELOG.md +15 -15
- package/README.md +1 -1
- package/build/bin/index.mjs +240 -2
- package/package.json +3 -4
- package/scripts/update-version.ts +5 -5
- package/source/bin/cli.ts +1 -1
- package/source/commands/artifact.command.ts +2 -2
- package/source/commands/build.command.ts +2 -2
- package/source/core/application.ts +19 -14
- package/source/core/builder.ts +2 -2
- package/source/core/bytes.util.ts +2 -2
- package/source/core/config/config.ts +7 -7
- package/source/core/config/define.ts +3 -3
- package/source/core/controller/builder.ts +2 -2
- package/source/core/guards.ts +43 -0
- package/source/core/hooks.ts +4 -4
- package/source/core/injection/injection.ts +6 -5
- package/source/core/plugins/plugin.ts +3 -3
- package/source/core/raiton.ts +2 -2
- package/source/core/router/route.ts +3 -3
- package/source/core/router/router.ts +2 -2
- package/source/core/server.ts +3 -3
- package/source/core/thread.ts +6 -5
- package/source/sdk/artifacts.ts +2 -2
- package/source/sdk/decorators/guard.decorator.ts +23 -0
- package/source/sdk/decorators/index.ts +2 -1
- package/source/sdk/decorators/injection.decorator.ts +2 -2
- package/source/sdk/decorators/parametrable.ts +2 -2
- package/source/sdk/encryption.ts +15 -15
- package/source/sdk/env.ts +5 -5
- package/source/sdk/plugins/body-parser.plugin.ts +3 -3
- package/source/sdk/plugins/security/body-limit.ts +2 -2
- package/source/sdk/plugins/security/cors.ts +2 -2
- package/source/sdk/plugins/security/headers.ts +2 -2
- package/source/sdk/plugins/security/method-guard.ts +2 -2
- package/source/sdk/plugins/security/rate-limit.ts +2 -2
- package/source/sdk/utilities/utilities.util.ts +2 -2
- package/source/types/application.ts +4 -4
- package/source/types/artifact.ts +2 -43
- package/source/types/builder.ts +5 -5
- package/source/types/config.ts +3 -3
- package/source/types/controller.ts +4 -4
- package/source/types/contruct.ts +1 -1
- package/source/types/core.ts +3 -5
- package/source/types/directory.ts +1 -1
- package/source/types/encryption.ts +21 -12
- package/source/types/generic.ts +2 -2
- package/source/types/guard.ts +12 -0
- package/source/types/index.ts +1 -3
- package/source/types/injection.ts +2 -2
- package/source/types/lifecycle.ts +3 -3
- package/source/types/middleware.ts +4 -4
- package/source/types/plugin.ts +3 -5
- package/source/types/raiton.ts +3 -3
- package/source/types/responses.ts +9 -6
- package/source/types/router.ts +3 -3
- package/source/types/server.ts +3 -3
- package/source/types/thread.ts +3 -3
- package/source/types/utilities.ts +1 -1
- package/source/types/values.ts +2 -2
- package/source/types/access-guards.ts +0 -4
- package/source/types/http-responses.ts +0 -8
- package/source/types/scheme.ts +0 -153
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {GuardDeclaration} from "../types";
|
|
2
|
+
import {Logger} from "@protorians/logger";
|
|
3
|
+
|
|
4
|
+
export class RaitonGuards {
|
|
5
|
+
protected static _map: Map<string, GuardDeclaration> = new Map();
|
|
6
|
+
|
|
7
|
+
static set(name: string, guard: GuardDeclaration): typeof this {
|
|
8
|
+
this._map.set(name, guard);
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get(name: string): GuardDeclaration | undefined {
|
|
13
|
+
return this._map.get(name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static remove(name: string): typeof this {
|
|
17
|
+
this._map.delete(name);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static removeAll(): typeof this {
|
|
22
|
+
Logger.error('Removing all guards');
|
|
23
|
+
this._map.clear();
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static enabled(name: string): boolean {
|
|
28
|
+
const guard = this.get(name);
|
|
29
|
+
return (!guard) ? false : guard.enabled;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static enable(name: string): typeof this {
|
|
33
|
+
const guard = this.get(name);
|
|
34
|
+
if(guard) guard.enabled = true;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static disable(name: string){
|
|
39
|
+
const guard = this.get(name);
|
|
40
|
+
if(guard) guard.enabled = false;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/source/core/hooks.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {HookNameType, HookHandlerCallable} from '../types'
|
|
2
2
|
|
|
3
3
|
export class HookStore {
|
|
4
|
-
private hooks = new Map<
|
|
4
|
+
private hooks = new Map<HookNameType, HookHandlerCallable[]>()
|
|
5
5
|
|
|
6
|
-
add(name:
|
|
6
|
+
add(name: HookNameType, handler: HookHandlerCallable) {
|
|
7
7
|
const list = this.hooks.get(name) ?? []
|
|
8
8
|
list.push(handler)
|
|
9
9
|
this.hooks.set(name, list)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
async run(name:
|
|
12
|
+
async run(name: HookNameType, ctx: any) {
|
|
13
13
|
const list = this.hooks.get(name)
|
|
14
14
|
if (!list) return
|
|
15
15
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type {
|
|
2
|
+
import type {ConstructorType, ContainerDefinitionInterface} from "../../types";
|
|
3
3
|
import {LifetimeEnum, TextUtility} from "@protorians/core";
|
|
4
4
|
import {Logger} from "@protorians/logger";
|
|
5
5
|
import {METADATA_KEYS} from "../../sdk/constants";
|
|
@@ -30,20 +30,21 @@ export class Injection {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
static clear(): void {
|
|
33
|
+
Logger.error('Clearing injection container');
|
|
33
34
|
this._classes.clear();
|
|
34
35
|
this._instances.clear();
|
|
35
36
|
this._dependents.clear();
|
|
36
37
|
this._artifactPaths.clear();
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
static normalizeName(name: string): string {
|
|
40
|
+
protected static normalizeName(name: string): string {
|
|
40
41
|
const stableName = camelCase(name);
|
|
41
42
|
return stableName[0].toLowerCase() + stableName.slice(1);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
static registry(
|
|
45
46
|
name: string,
|
|
46
|
-
construct:
|
|
47
|
+
construct: ConstructorType,
|
|
47
48
|
lifetime: LifetimeEnum = LifetimeEnum.SINGLETON,
|
|
48
49
|
scope?: Symbol
|
|
49
50
|
): typeof this {
|
|
@@ -54,7 +55,7 @@ export class Injection {
|
|
|
54
55
|
return this;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
static updateConstruct(name: string, construct:
|
|
58
|
+
static updateConstruct(name: string, construct: ConstructorType): typeof this {
|
|
58
59
|
const name_ = this.normalizeName(name);
|
|
59
60
|
this._classes.set(name_, {...this._classes.get(this.normalizeName(name))!, construct});
|
|
60
61
|
return this;
|
|
@@ -208,7 +209,7 @@ export class Injection {
|
|
|
208
209
|
this.clear();
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
static resolve<T>(construct:
|
|
212
|
+
static resolve<T>(construct: ConstructorType<T>): T {
|
|
212
213
|
const metadata: ContainerDefinitionInterface = Reflect.getMetadata(METADATA_KEYS.CONTAINER, construct);
|
|
213
214
|
|
|
214
215
|
if (!metadata)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginInterface, PluginCallable } from '../../types'
|
|
2
2
|
|
|
3
3
|
export function definePlugin(
|
|
4
|
-
setup:
|
|
4
|
+
setup: PluginCallable,
|
|
5
5
|
name?: string
|
|
6
|
-
):
|
|
6
|
+
): PluginInterface {
|
|
7
7
|
return { setup, name }
|
|
8
8
|
}
|
package/source/core/raiton.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {RaitonSignalMapInterface, ThreadInterface} from "../types";
|
|
2
2
|
import {ISignalStack, Signal} from "@protorians/core";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export class Raiton {
|
|
6
6
|
protected static _thread: ThreadInterface | undefined;
|
|
7
7
|
|
|
8
|
-
static readonly signals: ISignalStack<
|
|
8
|
+
static readonly signals: ISignalStack<RaitonSignalMapInterface> = new Signal.Stack<RaitonSignalMapInterface>()
|
|
9
9
|
static title: string = 'Protorians Raiton';
|
|
10
10
|
static identifier: string = 'raiton';
|
|
11
11
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {RouteDefinitionInterface} from '../../types/router'
|
|
2
2
|
|
|
3
3
|
export class Route {
|
|
4
4
|
method: string
|
|
5
5
|
path: string
|
|
6
6
|
version?: string
|
|
7
|
-
handler:
|
|
7
|
+
handler: RouteDefinitionInterface['handler']
|
|
8
8
|
parameters: Record<string, string> = {}
|
|
9
9
|
|
|
10
|
-
constructor(def:
|
|
10
|
+
constructor(def: RouteDefinitionInterface) {
|
|
11
11
|
this.method = def.method
|
|
12
12
|
this.path = def.path
|
|
13
13
|
this.version = def.version
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {RouteHandlerCallable} from '../../types'
|
|
2
2
|
import {HttpMethod} from "../../sdk/enums";
|
|
3
3
|
import {Route} from './route'
|
|
4
4
|
import {RouteMatcher} from './matcher'
|
|
@@ -6,7 +6,7 @@ import {RouteMatcher} from './matcher'
|
|
|
6
6
|
export class Router {
|
|
7
7
|
private matcher = new RouteMatcher()
|
|
8
8
|
|
|
9
|
-
add(method: HttpMethod, path: string, handler:
|
|
9
|
+
add(method: HttpMethod, path: string, handler: RouteHandlerCallable, version?: string) {
|
|
10
10
|
const route = new Route({
|
|
11
11
|
method,
|
|
12
12
|
path,
|
package/source/core/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {ServerInterface,
|
|
1
|
+
import type {ServerInterface, ServerOptionsInterface} from "../types";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export class Server implements ServerInterface {
|
|
@@ -14,12 +14,12 @@ export class Server implements ServerInterface {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
|
-
public readonly options:
|
|
17
|
+
public readonly options: ServerOptionsInterface
|
|
18
18
|
) {
|
|
19
19
|
Server.instance = this;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
option<K extends keyof
|
|
22
|
+
option<K extends keyof ServerOptionsInterface>(key: K): ServerOptionsInterface[K] {
|
|
23
23
|
return this.options[key];
|
|
24
24
|
}
|
|
25
25
|
|
package/source/core/thread.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type {
|
|
|
3
3
|
RuntimeAdapterInterface,
|
|
4
4
|
RuntimeServerInterface,
|
|
5
5
|
ThreadInterface,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ThreadOptionsInterface,
|
|
7
|
+
ThreadSetupOptionsInterface,
|
|
8
8
|
ThreadWaitCallable,
|
|
9
9
|
} from "../types";
|
|
10
10
|
import {EventMessageEnum, RuntimeType} from "../sdk/enums";
|
|
@@ -37,7 +37,7 @@ export class RaitonThread implements ThreadInterface {
|
|
|
37
37
|
|
|
38
38
|
constructor(
|
|
39
39
|
public readonly builder: BuilderInterface,
|
|
40
|
-
protected _options:
|
|
40
|
+
protected _options: ThreadOptionsInterface = {}
|
|
41
41
|
) {
|
|
42
42
|
this.appDir = process.cwd();
|
|
43
43
|
RaitonThread.instance = this;
|
|
@@ -72,7 +72,7 @@ export class RaitonThread implements ThreadInterface {
|
|
|
72
72
|
return null;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
public setup({application, runtime}:
|
|
75
|
+
public setup({application, runtime}: ThreadSetupOptionsInterface): this {
|
|
76
76
|
const defaultRuntime = typeof Bun !== 'undefined' ? RuntimeType.Bun : RuntimeType.Node;
|
|
77
77
|
this.runtime = new Runtime(runtime || defaultRuntime);
|
|
78
78
|
this.application = application;
|
|
@@ -106,7 +106,8 @@ export class RaitonThread implements ThreadInterface {
|
|
|
106
106
|
await this.runtimeServer.listen(port, hostname)
|
|
107
107
|
if (this.builder.source) await ControllerBuilder.scan(this.builder.source)
|
|
108
108
|
|
|
109
|
-
Logger.log(LBadge.info('
|
|
109
|
+
Logger.log(LBadge.info('Local access:'), `http://localhost:${port}${prefix ?? ''}`,)
|
|
110
|
+
Logger.log(LBadge.info('LAN access:'), `http://${displayHostname}:${port}${prefix ?? ''}`,)
|
|
110
111
|
return this;
|
|
111
112
|
}
|
|
112
113
|
}
|
package/source/sdk/artifacts.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Injection} from "../core/injection";
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
-
import type {
|
|
3
|
+
import type {ConstructorType} from "../types";
|
|
4
4
|
import {Raiton} from "../core/raiton";
|
|
5
5
|
import {isArtifact, isControllerArtifact} from "./utilities";
|
|
6
6
|
|
|
@@ -59,7 +59,7 @@ export class Artifacts {
|
|
|
59
59
|
|
|
60
60
|
if (typeof name === 'string' && Injection.has(name)) {
|
|
61
61
|
if (filename) Injection.registerArtifactPath(name, filename);
|
|
62
|
-
Injection.updateConstruct(name, mod as
|
|
62
|
+
Injection.updateConstruct(name, mod as ConstructorType)
|
|
63
63
|
|
|
64
64
|
const dependents = Injection.getDependents(name);
|
|
65
65
|
for (const dependent of dependents) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {GuardOptions} from "../../types";
|
|
2
|
+
import {Middleware} from "./middleware.decorator";
|
|
3
|
+
import {RaitonGuards} from "../../core/guards";
|
|
4
|
+
import {HttpStatus} from "../enums";
|
|
5
|
+
|
|
6
|
+
export function createGuardDecoration({name, handler}: GuardOptions) {
|
|
7
|
+
return Middleware(async ({next, context}) => {
|
|
8
|
+
const guard = RaitonGuards.get(name);
|
|
9
|
+
|
|
10
|
+
if (!guard) RaitonGuards.set(name, {name, handler, enabled: true})
|
|
11
|
+
if (guard && !guard.enabled) return next();
|
|
12
|
+
|
|
13
|
+
const response = await handler({context, next})
|
|
14
|
+
|
|
15
|
+
if (response) return next()
|
|
16
|
+
|
|
17
|
+
context.reply.status(HttpStatus.FORBIDDEN)
|
|
18
|
+
return context.reply.send({
|
|
19
|
+
error: true,
|
|
20
|
+
message: 'Forbidden'
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type {
|
|
2
|
+
import type {ConstructorType} from "../../types/contruct";
|
|
3
3
|
import {Injection} from "../../core/injection";
|
|
4
4
|
import {LifetimeEnum} from "@protorians/core";
|
|
5
5
|
import {Logger} from "@protorians/logger";
|
|
@@ -7,7 +7,7 @@ import {METADATA_KEYS} from "../constants";
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
export function Injectable(lifetime?: LifetimeEnum, name?: string, scope?: any) {
|
|
10
|
-
return function <T extends
|
|
10
|
+
return function <T extends ConstructorType>(target: T) {
|
|
11
11
|
const metadata = {
|
|
12
12
|
name: name || target.name,
|
|
13
13
|
construct: target,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type {
|
|
2
|
+
import type {ContextInterface, ParamMetaInterface} from "../../types";
|
|
3
3
|
import {METADATA_KEYS, Parametrable} from "..";
|
|
4
4
|
|
|
5
|
-
function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context:
|
|
5
|
+
function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context: ContextInterface) => any) {
|
|
6
6
|
return (key?: string) => {
|
|
7
7
|
return (target: any, propertyKey: string, index: number) => {
|
|
8
8
|
const params = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, target.constructor) || {}
|
package/source/sdk/encryption.ts
CHANGED
|
@@ -2,7 +2,7 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import argon2, {Options} from "argon2";
|
|
3
3
|
import {HashAlgoEnum, PasswordAlgoEnum} from "./enums";
|
|
4
4
|
import bcrypt from "bcrypt";
|
|
5
|
-
import {
|
|
5
|
+
import {DerivationOptionsInterface, EncryptionResultType, ScryptOptionsInterface} from "../types";
|
|
6
6
|
|
|
7
7
|
export class Encryption {
|
|
8
8
|
static get algos() {
|
|
@@ -24,7 +24,7 @@ export class Encryption {
|
|
|
24
24
|
return this.make(value).then(result => result === hash);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
async make(value: string, options?:
|
|
27
|
+
async make(value: string, options?: DerivationOptionsInterface | ScryptOptionsInterface): Promise<EncryptionResultType> {
|
|
28
28
|
if (!value) {
|
|
29
29
|
throw new Error('Value cannot be empty');
|
|
30
30
|
}
|
|
@@ -45,9 +45,9 @@ export class Encryption {
|
|
|
45
45
|
case HashAlgoEnum.SHA3_512:
|
|
46
46
|
return this.sha3_512(value);
|
|
47
47
|
case HashAlgoEnum.PBKDF2:
|
|
48
|
-
return this.pbkdf2(value, options as
|
|
48
|
+
return this.pbkdf2(value, options as DerivationOptionsInterface | undefined);
|
|
49
49
|
case HashAlgoEnum.SCRYPT:
|
|
50
|
-
return this.scrypt(value, options as
|
|
50
|
+
return this.scrypt(value, options as ScryptOptionsInterface | undefined);
|
|
51
51
|
case HashAlgoEnum.ARGON2ID:
|
|
52
52
|
case HashAlgoEnum.BCRYPT:
|
|
53
53
|
return this.password(value);
|
|
@@ -56,35 +56,35 @@ export class Encryption {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
protected sha256(value: string):
|
|
59
|
+
protected sha256(value: string): EncryptionResultType {
|
|
60
60
|
return crypto.createHash("sha256").update(value).digest("hex");
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
protected sha512(value: string):
|
|
63
|
+
protected sha512(value: string): EncryptionResultType {
|
|
64
64
|
return crypto.createHash("sha512").update(value).digest("hex");
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
protected md5(value: string):
|
|
67
|
+
protected md5(value: string): EncryptionResultType {
|
|
68
68
|
return crypto.createHash("md5").update(value).digest("hex");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
protected ripemd160(value: string):
|
|
71
|
+
protected ripemd160(value: string): EncryptionResultType {
|
|
72
72
|
return crypto.createHash("ripemd160").update(value).digest("hex");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
protected blake2b(value: string):
|
|
75
|
+
protected blake2b(value: string): EncryptionResultType {
|
|
76
76
|
return crypto.createHash("blake2b512").update(value).digest("hex");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
protected sha3_256(value: string):
|
|
79
|
+
protected sha3_256(value: string): EncryptionResultType {
|
|
80
80
|
return crypto.createHash("sha3-256").update(value).digest("hex");
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
protected sha3_512(value: string):
|
|
83
|
+
protected sha3_512(value: string): EncryptionResultType {
|
|
84
84
|
return crypto.createHash("sha3-512").update(value).digest("hex");
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
protected pbkdf2(value: string, options?:
|
|
87
|
+
protected pbkdf2(value: string, options?: DerivationOptionsInterface): EncryptionResultType {
|
|
88
88
|
const {salt, iterations, keylen, digest} = options || {};
|
|
89
89
|
const usedSalt = salt ?? crypto.randomBytes(16).toString("hex");
|
|
90
90
|
const usedIterations = iterations ?? 100_000;
|
|
@@ -96,8 +96,8 @@ export class Encryption {
|
|
|
96
96
|
return `pbkdf2$${usedDigest}$${usedIterations}$${usedSalt}$${derived}`;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
protected scrypt(value: string, options?:
|
|
100
|
-
const {salt, keylen, cost, blockSize, parallelization} = options || {} as
|
|
99
|
+
protected scrypt(value: string, options?: ScryptOptionsInterface): EncryptionResultType {
|
|
100
|
+
const {salt, keylen, cost, blockSize, parallelization} = options || {} as ScryptOptionsInterface;
|
|
101
101
|
const usedSalt = salt ?? crypto.randomBytes(16).toString("hex");
|
|
102
102
|
const usedKeylen = keylen ?? 64;
|
|
103
103
|
const usedCost = cost ?? 16384; // N
|
|
@@ -120,7 +120,7 @@ export class Encryption {
|
|
|
120
120
|
|
|
121
121
|
async password(value: string, options?: (Options & {
|
|
122
122
|
raw?: boolean
|
|
123
|
-
}) | (string | number) | undefined): Promise<
|
|
123
|
+
}) | (string | number) | undefined): Promise<EncryptionResultType> {
|
|
124
124
|
switch (this.algo) {
|
|
125
125
|
case HashAlgoEnum.ARGON2ID: {
|
|
126
126
|
return await argon2.hash(value, {
|
package/source/sdk/env.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {GenericValueType} from "../types/generic";
|
|
2
2
|
import {getType} from "./utilities";
|
|
3
3
|
|
|
4
|
-
export function env<T>(key: string, type?:
|
|
4
|
+
export function env<T>(key: string, type?: GenericValueType): T | undefined {
|
|
5
5
|
const value = process.env[key];
|
|
6
|
-
type = type || getType(value) as
|
|
6
|
+
type = type || getType(value) as GenericValueType;
|
|
7
7
|
|
|
8
8
|
if (value) {
|
|
9
9
|
switch (type) {
|
|
@@ -28,10 +28,10 @@ export function env<T>(key: string, type?: IGenericValue): T | undefined {
|
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function envGroup(key: string): Record<string,
|
|
31
|
+
export function envGroup(key: string): Record<string, GenericValueType | undefined> {
|
|
32
32
|
const filtered = Object.entries(process.env)
|
|
33
33
|
.filter(([index]) => key.startsWith(index))
|
|
34
|
-
const gen: Record<string,
|
|
34
|
+
const gen: Record<string, GenericValueType | undefined> = {}
|
|
35
35
|
|
|
36
36
|
for (const [index, value] of filtered)
|
|
37
37
|
gen[index] = env(value as any, undefined)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {MiddlewareParametersInterface, PluginInterface} from "../../types";
|
|
2
2
|
import {RequestContext} from "../../core/context";
|
|
3
3
|
import {Logger} from "@protorians/logger";
|
|
4
4
|
import {tryParseJson} from "../utilities/json.util";
|
|
5
5
|
|
|
6
|
-
export function bodyParserPlugin():
|
|
6
|
+
export function bodyParserPlugin(): PluginInterface {
|
|
7
7
|
return {
|
|
8
8
|
name: 'body-parser-plugin',
|
|
9
9
|
setup: (scope) => {
|
|
10
|
-
scope.use(async ({context, next}:
|
|
10
|
+
scope.use(async ({context, next}: MiddlewareParametersInterface) => {
|
|
11
11
|
const contentType = context.req.headers.get('content-type') || '';
|
|
12
12
|
|
|
13
13
|
if (context.req.body && !context.state.bodyParsed) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {
|
|
2
|
+
import {MiddlewareParametersInterface} from "../../../types";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const secureBodyLimit = (maxBytes = 1_000_000) =>
|
|
6
6
|
definePlugin((scope) => {
|
|
7
|
-
scope.use(async ({context, next}:
|
|
7
|
+
scope.use(async ({context, next}: MiddlewareParametersInterface) => {
|
|
8
8
|
const len = Number(
|
|
9
9
|
context.req.headers.get('content-length') ?? 0
|
|
10
10
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {
|
|
2
|
+
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
|
|
3
3
|
|
|
4
4
|
export interface CorsOptions {
|
|
5
5
|
origin?: string | string[]
|
|
@@ -9,7 +9,7 @@ export interface CorsOptions {
|
|
|
9
9
|
|
|
10
10
|
export const secureCors = (opts: CorsOptions = {}) =>
|
|
11
11
|
definePlugin((scope) => {
|
|
12
|
-
scope.use(async ({context, next}:
|
|
12
|
+
scope.use(async ({context, next}: MiddlewareParametersInterface) => {
|
|
13
13
|
const origin = context.req.headers.get('origin')
|
|
14
14
|
|
|
15
15
|
if (opts.origin) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {
|
|
2
|
+
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const secureHeaders = definePlugin((scope) => {
|
|
6
|
-
scope.use(async ({context, next}:
|
|
6
|
+
scope.use(async ({context, next}: MiddlewareParametersInterface) => {
|
|
7
7
|
context.reply.header('X-Content-Type-Options', 'nosniff')
|
|
8
8
|
context.reply.header('X-Frame-Options', 'DENY')
|
|
9
9
|
context.reply.header('Referrer-Policy', 'no-referrer')
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {
|
|
2
|
+
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export const secureMethodGuard = (allowed: string[]) =>
|
|
6
6
|
definePlugin((scope) => {
|
|
7
|
-
scope.use(async ({context, next}:
|
|
7
|
+
scope.use(async ({context, next}: MiddlewareParametersInterface) => {
|
|
8
8
|
if (!allowed.includes(context.req.method)) {
|
|
9
9
|
context.reply.status(405)
|
|
10
10
|
return context.send({ error: 'Method not allowed' })
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {definePlugin} from "../../../core/plugins";
|
|
2
|
-
import {
|
|
2
|
+
import {ContextInterface, MiddlewareParametersInterface, MiddlewareNextCallable} from "../../../types";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export interface RateLimitOptions {
|
|
@@ -16,7 +16,7 @@ export const secureRateLimit = (
|
|
|
16
16
|
const windowMs = opts.windowMs ?? 60_000
|
|
17
17
|
const max = opts.max ?? 100
|
|
18
18
|
|
|
19
|
-
scope.use(async ({context, next}:
|
|
19
|
+
scope.use(async ({context, next}: MiddlewareParametersInterface) => {
|
|
20
20
|
const ip =
|
|
21
21
|
context.req.remoteAddress ?? 'unknown'
|
|
22
22
|
const now = Date.now()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {GenericValuesType} from "../../types";
|
|
2
2
|
|
|
3
|
-
export function getType(value: any):
|
|
3
|
+
export function getType(value: any): GenericValuesType {
|
|
4
4
|
if (typeof value === "string") return "string";
|
|
5
5
|
if (typeof value === "boolean") return "boolean";
|
|
6
6
|
if (typeof value === "bigint") return "bigInt";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {HttpMethod} from "../sdk";
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface ApplicationConfigInterface {
|
|
4
4
|
workdir?: string;
|
|
5
5
|
hostname?: string;
|
|
6
6
|
port?: number;
|
|
@@ -12,13 +12,13 @@ export interface ApplicationConfig {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface ApplicationInterface {
|
|
15
|
-
readonly config:
|
|
15
|
+
readonly config: ApplicationConfigInterface;
|
|
16
16
|
|
|
17
17
|
get hostname(): string;
|
|
18
18
|
|
|
19
|
-
setOption<K extends keyof
|
|
19
|
+
setOption<K extends keyof ApplicationConfigInterface>(key: K, value: ApplicationConfigInterface[K]): this;
|
|
20
20
|
|
|
21
|
-
setOptions(options:
|
|
21
|
+
setOptions(options: ApplicationConfigInterface): this;
|
|
22
22
|
|
|
23
23
|
register(plugin: any): this;
|
|
24
24
|
|
package/source/types/artifact.ts
CHANGED
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
id: string;
|
|
3
|
-
timestamp: Date;
|
|
4
|
-
size: number;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface ArtifactsConfig {
|
|
1
|
+
export interface ArtifactsConfigInterface {
|
|
8
2
|
types: string[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// export type ArtifactDecoratorHandler = () => void;
|
|
12
|
-
|
|
13
|
-
// export interface ArtifactDecorator {
|
|
14
|
-
// syntax: RegExp;
|
|
15
|
-
// handler: ArtifactDecoratorHandler;
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
// export interface ArtifactOptions {
|
|
19
|
-
// readonly artifact: string;
|
|
20
|
-
// readonly provider: string;
|
|
21
|
-
// readonly decorator: ArtifactDecorator;
|
|
22
|
-
// verbose?: boolean;
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
// export interface ArtifactInterface {
|
|
26
|
-
// readonly options: ArtifactOptions;
|
|
27
|
-
// readonly directory: string;
|
|
28
|
-
// readonly file: string;
|
|
29
|
-
// readonly workdir: string;
|
|
30
|
-
//
|
|
31
|
-
// get files(): string[];
|
|
32
|
-
//
|
|
33
|
-
// get extensions(): string[];
|
|
34
|
-
//
|
|
35
|
-
// scan(): string[];
|
|
36
|
-
//
|
|
37
|
-
// generate(): boolean;
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// export interface ArtifactEntry {
|
|
41
|
-
// vendor: string;
|
|
42
|
-
// decorator: string;
|
|
43
|
-
// pattern: string;
|
|
44
|
-
// }
|
|
3
|
+
}
|
package/source/types/builder.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {WatchEventType} from "node:fs";
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface BuildCommandOptionsInterface {
|
|
4
4
|
develop?: boolean;
|
|
5
5
|
bootstrap?: boolean;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export interface
|
|
8
|
+
export interface BuilderConfigInterface {
|
|
9
9
|
development?: boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export type
|
|
12
|
+
export type BuilderBootCallableType = (builder: BuilderInterface) => Promise<void>
|
|
13
13
|
|
|
14
14
|
export interface BuilderInterface {
|
|
15
15
|
readonly workdir: string;
|
|
16
|
-
readonly options:
|
|
16
|
+
readonly options: BuilderConfigInterface;
|
|
17
17
|
// readonly signal: ISignalStack<BuilderSignalMap>;
|
|
18
18
|
|
|
19
19
|
// get context(): BuildContext<BuildOptions> | null;
|
|
@@ -36,7 +36,7 @@ export interface BuilderInterface {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
export interface
|
|
39
|
+
export interface BuilderHMRDeclarationInterface {
|
|
40
40
|
filename: string;
|
|
41
41
|
timestamp?: number;
|
|
42
42
|
version?: number;
|
package/source/types/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ArtifactsConfigInterface} from "./artifact";
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface ConfigurableInterface {
|
|
4
4
|
rootDir: string;
|
|
5
5
|
version: string;
|
|
6
|
-
artifacts?:
|
|
6
|
+
artifacts?: ArtifactsConfigInterface
|
|
7
7
|
}
|