fiberx-backend-toolkit 0.0.48 → 0.0.50
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.
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Model } from "sequelize";
|
|
2
2
|
import { Request, Response, NextFunction, RequestHandler } from "express";
|
|
3
3
|
import { AuthenticatorOptions, DefaultRequestInfo, DefaultAccessTokenPayload, DefaultRefreshTokenPayload } from "../types/middle_ware_type";
|
|
4
|
-
declare class AuthenicationMiddleWare {
|
|
4
|
+
declare class AuthenicationMiddleWare<TRequestInfo extends DefaultRequestInfo = DefaultRequestInfo, TAccessPayload extends DefaultAccessTokenPayload = DefaultAccessTokenPayload, TRefreshPayload extends DefaultRefreshTokenPayload = DefaultRefreshTokenPayload, TSessionModel extends Model = Model, TLoginChallengeModel extends Model = Model, TActorModel extends Model = Model> {
|
|
5
5
|
private name;
|
|
6
6
|
private logger;
|
|
7
7
|
private readonly options;
|
|
8
|
-
constructor(options: AuthenticatorOptions);
|
|
8
|
+
constructor(options: AuthenticatorOptions<TRequestInfo, TAccessPayload, TRefreshPayload, TSessionModel, TLoginChallengeModel, TActorModel>);
|
|
9
9
|
/** Extract tokens + device info from request */
|
|
10
|
-
protected extractRequestInfo(req: Request): Promise<
|
|
11
|
-
protected validateAccessToken(access_token: string, request_info?:
|
|
12
|
-
protected validateRefreshToken(refresh_token: string, request_info?:
|
|
13
|
-
protected LoadActor(actor_type: string, actor_id: number | string, request_info?:
|
|
14
|
-
protected loadMemberSession(member_id: number | string, session_id: number | string, request_info?:
|
|
15
|
-
protected loadMemberLoginChallenge(member_id: number | string, challenge_id: number | string, request_info?:
|
|
10
|
+
protected extractRequestInfo(req: Request): Promise<TRequestInfo | null>;
|
|
11
|
+
protected validateAccessToken(access_token: string, request_info?: TRequestInfo): Promise<DefaultAccessTokenPayload | null>;
|
|
12
|
+
protected validateRefreshToken(refresh_token: string, request_info?: TRequestInfo): Promise<DefaultRefreshTokenPayload | null>;
|
|
13
|
+
protected LoadActor(actor_type: string, actor_id: number | string, request_info?: TRequestInfo): Promise<Model | null>;
|
|
14
|
+
protected loadMemberSession(member_id: number | string, session_id: number | string, request_info?: TRequestInfo, is_2fa_validated?: boolean): Promise<Model | null>;
|
|
15
|
+
protected loadMemberLoginChallenge(member_id: number | string, challenge_id: number | string, request_info?: TRequestInfo, is_2fa_validated?: boolean): Promise<Model | null>;
|
|
16
16
|
protected getActorPermissions(actor_id: number | string, role_ids: (number | string)[]): Promise<string[]>;
|
|
17
|
-
protected validateHasPermission(request_info:
|
|
18
|
-
setPermissionName(permission_name: string)
|
|
17
|
+
protected validateHasPermission(request_info: TRequestInfo): Promise<boolean>;
|
|
18
|
+
setPermissionName: (permission_name: string) => RequestHandler;
|
|
19
19
|
requireNoAuth(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
|
|
20
20
|
requirePartialAuth(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
|
|
21
21
|
requireFullAuth(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
|
|
@@ -77,7 +77,7 @@ class AuthenicationMiddleWare {
|
|
|
77
77
|
// -----------------------------------
|
|
78
78
|
// GENERIC MIDDLEWARES
|
|
79
79
|
// -----------------------------------
|
|
80
|
-
setPermissionName(permission_name) {
|
|
80
|
+
setPermissionName = (permission_name) => {
|
|
81
81
|
return async (req, res, next) => {
|
|
82
82
|
req.permission_name = permission_name;
|
|
83
83
|
this.logger.info(`[${this.name}] 🔐 Route permission set as ${permission_name} for request ${req.request_id}`);
|
|
@@ -90,7 +90,7 @@ class AuthenicationMiddleWare {
|
|
|
90
90
|
this.logger.success(`[${this.name}] ✅ Permission granted for request ${req.request_id} with required permission ${permission_name}`);
|
|
91
91
|
next();
|
|
92
92
|
};
|
|
93
|
-
}
|
|
93
|
+
};
|
|
94
94
|
async requireNoAuth(req, res, next) {
|
|
95
95
|
if (!this.options?.requireNoAuthMiddleWareMethod) {
|
|
96
96
|
return next();
|
|
@@ -161,12 +161,6 @@ __decorate([
|
|
|
161
161
|
__metadata("design:paramtypes", [Object]),
|
|
162
162
|
__metadata("design:returntype", Promise)
|
|
163
163
|
], AuthenicationMiddleWare.prototype, "validateHasPermission", null);
|
|
164
|
-
__decorate([
|
|
165
|
-
main_1.SafeExecuteUtil.safeExecuteThrow("authentication_middle_ware"),
|
|
166
|
-
__metadata("design:type", Function),
|
|
167
|
-
__metadata("design:paramtypes", [String]),
|
|
168
|
-
__metadata("design:returntype", Function)
|
|
169
|
-
], AuthenicationMiddleWare.prototype, "setPermissionName", null);
|
|
170
164
|
__decorate([
|
|
171
165
|
main_1.SafeExecuteUtil.safeExecuteThrow("authentication_middle_ware"),
|
|
172
166
|
__metadata("design:type", Function),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|