@lara-node/middlewares 0.1.3 → 0.1.4
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/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +10 -6
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
+
import { Request, Response, NextFunction } from "express";
|
|
3
|
+
import { RuleFn, RuleSpec } from "@lara-node/validator";
|
|
4
|
+
export declare const asyncLocalStorage: AsyncLocalStorage<Record<string, any>>;
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Express {
|
|
7
|
+
interface Request {
|
|
8
|
+
user?: {
|
|
9
|
+
id: number | string;
|
|
10
|
+
email?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
roles?: string[];
|
|
13
|
+
permissions?: string[];
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
validate: <T extends Record<string, any>>(payloadOrRules?: any, rulesMaybe?: Record<string, RuleSpec> | Record<string, string | RuleFn>, customMessages?: Record<string, string>) => Promise<T>;
|
|
17
|
+
}
|
|
18
|
+
interface Response {
|
|
19
|
+
jsonAsync: <T>(data: T) => Promise<Response>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export declare class AsyncContextMiddleware {
|
|
24
|
+
handle(req: Request, _res: Response, next: NextFunction): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class RequestLoggerMiddleware {
|
|
27
|
+
handle(req: Request, res: Response, next: NextFunction): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class ValidatorMiddleware {
|
|
30
|
+
handle(req: Request & {
|
|
31
|
+
validate?: any;
|
|
32
|
+
}, _res: Response, next: NextFunction): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class ResponseExtenderMiddleware {
|
|
35
|
+
handle(_req: Request, res: Response, next: NextFunction): void;
|
|
36
|
+
}
|
|
37
|
+
export interface AuthMiddlewareOptions {
|
|
38
|
+
userLoader?: (uid: string | number) => Promise<{
|
|
39
|
+
id: number | string;
|
|
40
|
+
roles?: string[];
|
|
41
|
+
permissions?: string[];
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
} | null>;
|
|
44
|
+
decryptToken?: (token: string) => string;
|
|
45
|
+
}
|
|
46
|
+
export declare class AuthMiddleware {
|
|
47
|
+
private userLoader?;
|
|
48
|
+
private decryptFn?;
|
|
49
|
+
constructor(options?: AuthMiddlewareOptions);
|
|
50
|
+
handle(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
51
|
+
toHandler(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export declare class AuthorizeByStatusMiddleware {
|
|
54
|
+
handle(req: Request, res: Response, next: NextFunction): void;
|
|
55
|
+
}
|
|
56
|
+
export declare class ErrorHandlerMiddleware {
|
|
57
|
+
handle(err: any, _req: Request, res: Response, _next: NextFunction): void;
|
|
58
|
+
toHandler(): (err: any, req: Request, res: Response, next: NextFunction) => void;
|
|
59
|
+
}
|
|
60
|
+
export declare function authorizeRoles(...roles: string[]): (req: Request, res: Response, next: NextFunction) => void;
|
|
61
|
+
export declare function authorizePermissions(...perms: string[]): (req: Request, res: Response, next: NextFunction) => void;
|
|
62
|
+
export declare const asyncContextMiddleware: AsyncContextMiddleware;
|
|
63
|
+
export declare const requestLoggerMiddleware: RequestLoggerMiddleware;
|
|
64
|
+
export declare const validatorMiddleware: ValidatorMiddleware;
|
|
65
|
+
export declare const responseExtenderMiddleware: ResponseExtenderMiddleware;
|
|
66
|
+
export declare const authorizeByStatusMiddleware: AuthorizeByStatusMiddleware;
|
|
67
|
+
export declare const errorHandlerMiddleware: ErrorHandlerMiddleware;
|
|
68
|
+
export declare const asyncContext: (req: Request, res: Response, next: NextFunction) => void;
|
|
69
|
+
export declare const requestLogger: (req: Request, res: Response, next: NextFunction) => void;
|
|
70
|
+
export declare const validatorAttach: (req: Request, res: Response, next: NextFunction) => void;
|
|
71
|
+
export declare const responseExtender: (req: Request, res: Response, next: NextFunction) => void;
|
|
72
|
+
export declare const authorizeByStatus: (req: Request, res: Response, next: NextFunction) => void;
|
|
73
|
+
export declare const errorHandler: (err: any, req: Request, res: Response, next: NextFunction) => void;
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,EAA6B,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKnF,eAAO,MAAM,iBAAiB,wCAA+C,CAAC;AAI9E,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE;gBACL,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;gBACpB,KAAK,CAAC,EAAE,MAAM,CAAC;gBACf,IAAI,CAAC,EAAE,MAAM,CAAC;gBACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;gBACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;gBACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;aACpB,CAAC;YACF,QAAQ,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACtC,cAAc,CAAC,EAAE,GAAG,EACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACvE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACpC,OAAO,CAAC,CAAC,CAAC,CAAC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AAM,aAAa,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAC7B,CAAC;AACjD,eAAO,MAAM,eAAe,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SACnC,CAAC;AAC7C,eAAO,MAAM,gBAAgB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAC7B,CAAC;AACpD,eAAO,MAAM,iBAAiB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAC7B,CAAC;AACrD,eAAO,MAAM,YAAY,GAAI,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lara-node/middlewares",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Predefined class-based middleware for Lara-Node applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
9
13
|
},
|
|
10
14
|
"files": [
|
|
11
15
|
"dist",
|
|
@@ -16,8 +20,8 @@
|
|
|
16
20
|
},
|
|
17
21
|
"dependencies": {
|
|
18
22
|
"jsonwebtoken": "^9.0.2",
|
|
19
|
-
"@lara-node/
|
|
20
|
-
"@lara-node/
|
|
23
|
+
"@lara-node/db": "0.1.1",
|
|
24
|
+
"@lara-node/validator": "0.1.3"
|
|
21
25
|
},
|
|
22
26
|
"devDependencies": {
|
|
23
27
|
"@types/express": "^5.0.6",
|
|
@@ -31,8 +35,8 @@
|
|
|
31
35
|
"express": "^5.2.1"
|
|
32
36
|
},
|
|
33
37
|
"scripts": {
|
|
34
|
-
"build": "tsdown src/index.ts --format esm --out-dir dist --
|
|
35
|
-
"dev": "tsdown src/index.ts --format esm --out-dir dist --
|
|
38
|
+
"build": "tsdown src/index.ts --format esm --out-dir dist && tsc --emitDeclarationOnly",
|
|
39
|
+
"dev": "tsdown src/index.ts --format esm --out-dir dist --watch",
|
|
36
40
|
"clean": "rimraf dist",
|
|
37
41
|
"typecheck": "tsc --noEmit"
|
|
38
42
|
}
|