bootifyjs 1.2.0 → 1.3.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/README.md +1 -1
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +20 -4
- package/dist/api.js.map +1 -1
- package/dist/auth/examples/basic-usage.d.ts +2 -1
- package/dist/auth/examples/basic-usage.d.ts.map +1 -1
- package/dist/auth/examples/basic-usage.js +3 -2
- package/dist/auth/examples/basic-usage.js.map +1 -1
- package/dist/auth/index.d.ts +6 -8
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +11 -11
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/middleware/AuthMiddleware.js.map +1 -1
- package/dist/cache/bootstrap.js +1 -1
- package/dist/cache/bootstrap.js.map +1 -1
- package/dist/cache/index.d.ts +2 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -1
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/{in-memory-cache.store.d.ts → stores/in-memory-cache.store.d.ts} +1 -1
- package/dist/cache/stores/in-memory-cache.store.d.ts.map +1 -0
- package/dist/cache/{in-memory-cache.store.js → stores/in-memory-cache.store.js} +1 -1
- package/dist/cache/stores/in-memory-cache.store.js.map +1 -0
- package/dist/cache/stores/index.d.ts +3 -0
- package/dist/cache/stores/index.d.ts.map +1 -0
- package/dist/cache/stores/index.js +20 -0
- package/dist/cache/stores/index.js.map +1 -0
- package/dist/cache/stores/redis-cache.store.d.ts +8 -0
- package/dist/cache/stores/redis-cache.store.d.ts.map +1 -0
- package/dist/cache/stores/redis-cache.store.js +39 -0
- package/dist/cache/stores/redis-cache.store.js.map +1 -0
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/router.js +3 -3
- package/dist/core/router.js.map +1 -1
- package/dist/events/bootstrap.d.ts +13 -1
- package/dist/events/bootstrap.d.ts.map +1 -1
- package/dist/events/bootstrap.js +30 -2
- package/dist/events/bootstrap.js.map +1 -1
- package/dist/events/buffered-event-bus.service.d.ts +135 -0
- package/dist/events/buffered-event-bus.service.d.ts.map +1 -0
- package/dist/events/buffered-event-bus.service.js +420 -0
- package/dist/events/buffered-event-bus.service.js.map +1 -0
- package/dist/events/config/buffered-event-config.d.ts +153 -0
- package/dist/events/config/buffered-event-config.d.ts.map +1 -0
- package/dist/events/config/buffered-event-config.js +181 -0
- package/dist/events/config/buffered-event-config.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -0
- package/dist/events/index.js.map +1 -1
- package/dist/events/metrics/event-metrics.d.ts +175 -0
- package/dist/events/metrics/event-metrics.d.ts.map +1 -0
- package/dist/events/metrics/event-metrics.js +235 -0
- package/dist/events/metrics/event-metrics.js.map +1 -0
- package/dist/events/monitoring/health-monitor.d.ts +142 -0
- package/dist/events/monitoring/health-monitor.d.ts.map +1 -0
- package/dist/events/monitoring/health-monitor.js +492 -0
- package/dist/events/monitoring/health-monitor.js.map +1 -0
- package/dist/events/retry/retry-handler.d.ts +112 -0
- package/dist/events/retry/retry-handler.d.ts.map +1 -0
- package/dist/events/retry/retry-handler.js +218 -0
- package/dist/events/retry/retry-handler.js.map +1 -0
- package/dist/events/shared-buffer.d.ts +92 -0
- package/dist/events/shared-buffer.d.ts.map +1 -0
- package/dist/events/shared-buffer.js +179 -0
- package/dist/events/shared-buffer.js.map +1 -0
- package/dist/events/worker/event-processor.worker.d.ts +75 -0
- package/dist/events/worker/event-processor.worker.d.ts.map +1 -0
- package/dist/events/worker/event-processor.worker.js +293 -0
- package/dist/events/worker/event-processor.worker.js.map +1 -0
- package/dist/events/worker/worker-manager.d.ts +132 -0
- package/dist/events/worker/worker-manager.d.ts.map +1 -0
- package/dist/events/worker/worker-manager.js +436 -0
- package/dist/events/worker/worker-manager.js.map +1 -0
- package/dist/examples/auth/auth.middleware.d.ts +0 -26
- package/dist/examples/auth/auth.middleware.d.ts.map +1 -1
- package/dist/examples/auth/auth.middleware.js +0 -185
- package/dist/examples/auth/auth.middleware.js.map +1 -1
- package/dist/examples/controllers/auth.controller.d.ts +0 -63
- package/dist/examples/controllers/auth.controller.d.ts.map +1 -1
- package/dist/examples/controllers/auth.controller.js +247 -282
- package/dist/examples/controllers/auth.controller.js.map +1 -1
- package/dist/examples/events/buffered-event-example.d.ts +71 -0
- package/dist/examples/events/buffered-event-example.d.ts.map +1 -0
- package/dist/examples/events/buffered-event-example.js +182 -0
- package/dist/examples/events/buffered-event-example.js.map +1 -0
- package/dist/examples/events/integration-test.d.ts +10 -0
- package/dist/examples/events/integration-test.d.ts.map +1 -0
- package/dist/examples/events/integration-test.js +147 -0
- package/dist/examples/events/integration-test.js.map +1 -0
- package/dist/examples/index.d.ts +1 -0
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +11 -7
- package/dist/examples/index.js.map +1 -1
- package/dist/examples/todos/schema.d.ts +4 -4
- package/package.json +2 -1
- package/dist/cache/in-memory-cache.store.d.ts.map +0 -1
- package/dist/cache/in-memory-cache.store.js.map +0 -1
- package/dist/examples/authorization-examples.d.ts +0 -67
- package/dist/examples/authorization-examples.d.ts.map +0 -1
- package/dist/examples/authorization-examples.js +0 -202
- package/dist/examples/authorization-examples.js.map +0 -1
- package/dist/examples/controllers/todo-updated.controller.d.ts +0 -103
- package/dist/examples/controllers/todo-updated.controller.d.ts.map +0 -1
- package/dist/examples/controllers/todo-updated.controller.js +0 -328
- package/dist/examples/controllers/todo-updated.controller.js.map +0 -1
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts +0 -114
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts.map +0 -1
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js +0 -329
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js.map +0 -1
- package/dist/examples/jwt-auth-example.d.ts +0 -47
- package/dist/examples/jwt-auth-example.d.ts.map +0 -1
- package/dist/examples/jwt-auth-example.js +0 -316
- package/dist/examples/jwt-auth-example.js.map +0 -1
- package/dist/examples/services/user.service.d.ts +0 -99
- package/dist/examples/services/user.service.d.ts.map +0 -1
- package/dist/examples/services/user.service.js +0 -281
- package/dist/examples/services/user.service.js.map +0 -1
- package/dist/examples/test-auth-flow.d.ts +0 -56
- package/dist/examples/test-auth-flow.d.ts.map +0 -1
- package/dist/examples/test-auth-flow.js +0 -449
- package/dist/examples/test-auth-flow.js.map +0 -1
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization Examples using JWT Middleware
|
|
3
|
-
*
|
|
4
|
-
* This file demonstrates different ways to implement authorization
|
|
5
|
-
* using the built-in JWT middleware methods as alternatives to
|
|
6
|
-
* the current authorize() middleware.
|
|
7
|
-
*/
|
|
8
|
-
import { FastifyInstance } from 'fastify';
|
|
9
|
-
import { AuthMiddleware } from '../auth/middleware/AuthMiddleware';
|
|
10
|
-
/**
|
|
11
|
-
* 1. requireAuth() - Basic authentication with optional roles/permissions
|
|
12
|
-
* 2. requireRoles() - Role-based authorization
|
|
13
|
-
* 3. requirePermissions() - Permission-based authorization
|
|
14
|
-
* 4. requireStrategy() - Strategy-specific authorization
|
|
15
|
-
* 5. optionalAuth() - Optional authentication
|
|
16
|
-
*/
|
|
17
|
-
export declare class AuthorizedTodoController {
|
|
18
|
-
private jwtAuthMiddleware;
|
|
19
|
-
constructor(jwtAuthMiddleware: AuthMiddleware);
|
|
20
|
-
createTodoWithRoles(body: any): Promise<{
|
|
21
|
-
message: string;
|
|
22
|
-
}>;
|
|
23
|
-
createTodoWithPermissions(body: any): Promise<{
|
|
24
|
-
message: string;
|
|
25
|
-
}>;
|
|
26
|
-
createTodoWithBoth(body: any): Promise<{
|
|
27
|
-
message: string;
|
|
28
|
-
}>;
|
|
29
|
-
adminOnlyEndpoint(): Promise<{
|
|
30
|
-
message: string;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
export declare function setupAuthorizationExamples(app: FastifyInstance, jwtAuthMiddleware: AuthMiddleware): void;
|
|
34
|
-
export declare const AuthorizedTodoControllerExample = "\n// Instead of:\n@UseMiddleware(authorize(['manager']))\nasync createTodo(@Body() body: z.infer<typeof todoSchema>) {\n // ...\n}\n\n// You can use:\n@UseMiddleware(this.jwtAuthMiddleware.requireRoles(['manager']))\nasync createTodo(@Body() body: z.infer<typeof todoSchema>) {\n // ...\n}\n\n// Or for more granular control:\n@UseMiddleware(this.jwtAuthMiddleware.requirePermissions(['todo:create']))\nasync createTodo(@Body() body: z.infer<typeof todoSchema>) {\n // ...\n}\n\n// Or combined:\n@UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt'], ['manager'], ['todo:create']))\nasync createTodo(@Body() body: z.infer<typeof todoSchema>) {\n // ...\n}\n";
|
|
35
|
-
export declare const AuthorizationComparison: {
|
|
36
|
-
current: {
|
|
37
|
-
method: string;
|
|
38
|
-
description: string;
|
|
39
|
-
pros: string[];
|
|
40
|
-
cons: string[];
|
|
41
|
-
};
|
|
42
|
-
jwtMiddleware: {
|
|
43
|
-
method: string;
|
|
44
|
-
description: string;
|
|
45
|
-
pros: string[];
|
|
46
|
-
cons: string[];
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export declare const AuthorizationBestPractices: {
|
|
50
|
-
roles: {
|
|
51
|
-
description: string;
|
|
52
|
-
example: string;
|
|
53
|
-
};
|
|
54
|
-
permissions: {
|
|
55
|
-
description: string;
|
|
56
|
-
example: string;
|
|
57
|
-
};
|
|
58
|
-
combined: {
|
|
59
|
-
description: string;
|
|
60
|
-
example: string;
|
|
61
|
-
};
|
|
62
|
-
strategy: {
|
|
63
|
-
description: string;
|
|
64
|
-
example: string;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
//# sourceMappingURL=authorization-examples.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-examples.d.ts","sourceRoot":"","sources":["../../src/examples/authorization-examples.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAOnE;;;;;;GAMG;AAGH,qBACa,wBAAwB;IACvB,OAAO,CAAC,iBAAiB;gBAAjB,iBAAiB,EAAE,cAAc;IAK/C,mBAAmB,CAAS,IAAI,EAAE,GAAG;;;IAQrC,yBAAyB,CAAS,IAAI,EAAE,GAAG;;;IAQ3C,kBAAkB,CAAS,IAAI,EAAE,GAAG;;;IAQpC,iBAAiB;;;CAIxB;AAGD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,QA4CjG;AAGD,eAAO,MAAM,+BAA+B,8pBAwB3C,CAAC;AAGF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;CAkBnC,CAAC;AAGF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;CAiBtC,CAAC"}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Authorization Examples using JWT Middleware
|
|
4
|
-
*
|
|
5
|
-
* This file demonstrates different ways to implement authorization
|
|
6
|
-
* using the built-in JWT middleware methods as alternatives to
|
|
7
|
-
* the current authorize() middleware.
|
|
8
|
-
*/
|
|
9
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
-
};
|
|
15
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
17
|
-
};
|
|
18
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
19
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.AuthorizationBestPractices = exports.AuthorizationComparison = exports.AuthorizedTodoControllerExample = exports.AuthorizedTodoController = void 0;
|
|
23
|
-
exports.setupAuthorizationExamples = setupAuthorizationExamples;
|
|
24
|
-
const AuthMiddleware_1 = require("../auth/middleware/AuthMiddleware");
|
|
25
|
-
const decorators_1 = require("../core/decorators");
|
|
26
|
-
// Example 1: Using JWT Middleware Authorization Methods
|
|
27
|
-
// These are the built-in methods available in AuthMiddleware:
|
|
28
|
-
/**
|
|
29
|
-
* 1. requireAuth() - Basic authentication with optional roles/permissions
|
|
30
|
-
* 2. requireRoles() - Role-based authorization
|
|
31
|
-
* 3. requirePermissions() - Permission-based authorization
|
|
32
|
-
* 4. requireStrategy() - Strategy-specific authorization
|
|
33
|
-
* 5. optionalAuth() - Optional authentication
|
|
34
|
-
*/
|
|
35
|
-
// Example Controller showing different authorization patterns
|
|
36
|
-
let AuthorizedTodoController = class AuthorizedTodoController {
|
|
37
|
-
constructor(jwtAuthMiddleware) {
|
|
38
|
-
this.jwtAuthMiddleware = jwtAuthMiddleware;
|
|
39
|
-
}
|
|
40
|
-
// Method 1: Using requireRoles() - Similar to current authorize(['manager'])
|
|
41
|
-
async createTodoWithRoles(body) {
|
|
42
|
-
// Only users with 'manager' or 'admin' roles can access
|
|
43
|
-
return { message: 'Todo created by authorized user' };
|
|
44
|
-
}
|
|
45
|
-
// Method 2: Using requirePermissions() - More granular control
|
|
46
|
-
async createTodoWithPermissions(body) {
|
|
47
|
-
// Only users with 'todo:create' permission can access
|
|
48
|
-
return { message: 'Todo created with permission check' };
|
|
49
|
-
}
|
|
50
|
-
// Method 3: Using requireAuth() with both roles and permissions
|
|
51
|
-
async createTodoWithBoth(body) {
|
|
52
|
-
// Users need both manager role AND todo:create permission
|
|
53
|
-
return { message: 'Todo created with comprehensive authorization' };
|
|
54
|
-
}
|
|
55
|
-
// Method 4: Using requireStrategy() - Strategy-specific authorization
|
|
56
|
-
async adminOnlyEndpoint() {
|
|
57
|
-
// Only JWT strategy with admin role
|
|
58
|
-
return { message: 'Admin-only content' };
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
exports.AuthorizedTodoController = AuthorizedTodoController;
|
|
62
|
-
__decorate([
|
|
63
|
-
(0, decorators_1.Post)('/create-with-roles'),
|
|
64
|
-
(0, decorators_1.UseMiddleware)( /* Pass the middleware function here */),
|
|
65
|
-
__param(0, (0, decorators_1.Body)()),
|
|
66
|
-
__metadata("design:type", Function),
|
|
67
|
-
__metadata("design:paramtypes", [Object]),
|
|
68
|
-
__metadata("design:returntype", Promise)
|
|
69
|
-
], AuthorizedTodoController.prototype, "createTodoWithRoles", null);
|
|
70
|
-
__decorate([
|
|
71
|
-
(0, decorators_1.Post)('/create-with-permissions'),
|
|
72
|
-
(0, decorators_1.UseMiddleware)( /* Pass the middleware function here */),
|
|
73
|
-
__param(0, (0, decorators_1.Body)()),
|
|
74
|
-
__metadata("design:type", Function),
|
|
75
|
-
__metadata("design:paramtypes", [Object]),
|
|
76
|
-
__metadata("design:returntype", Promise)
|
|
77
|
-
], AuthorizedTodoController.prototype, "createTodoWithPermissions", null);
|
|
78
|
-
__decorate([
|
|
79
|
-
(0, decorators_1.Post)('/create-with-both'),
|
|
80
|
-
(0, decorators_1.UseMiddleware)( /* Pass the middleware function here */),
|
|
81
|
-
__param(0, (0, decorators_1.Body)()),
|
|
82
|
-
__metadata("design:type", Function),
|
|
83
|
-
__metadata("design:paramtypes", [Object]),
|
|
84
|
-
__metadata("design:returntype", Promise)
|
|
85
|
-
], AuthorizedTodoController.prototype, "createTodoWithBoth", null);
|
|
86
|
-
__decorate([
|
|
87
|
-
(0, decorators_1.Get)('/admin-only'),
|
|
88
|
-
(0, decorators_1.UseMiddleware)( /* Pass the middleware function here */),
|
|
89
|
-
__metadata("design:type", Function),
|
|
90
|
-
__metadata("design:paramtypes", []),
|
|
91
|
-
__metadata("design:returntype", Promise)
|
|
92
|
-
], AuthorizedTodoController.prototype, "adminOnlyEndpoint", null);
|
|
93
|
-
exports.AuthorizedTodoController = AuthorizedTodoController = __decorate([
|
|
94
|
-
(0, decorators_1.Controller)('/api/todos'),
|
|
95
|
-
__metadata("design:paramtypes", [AuthMiddleware_1.AuthMiddleware])
|
|
96
|
-
], AuthorizedTodoController);
|
|
97
|
-
// Example of how to use these in practice:
|
|
98
|
-
function setupAuthorizationExamples(app, jwtAuthMiddleware) {
|
|
99
|
-
// 1. Role-based authorization (equivalent to current authorize(['manager']))
|
|
100
|
-
app.post('/todos/create-role-based', {
|
|
101
|
-
preHandler: jwtAuthMiddleware.requireRoles(['manager', 'admin'])
|
|
102
|
-
}, async (request, reply) => {
|
|
103
|
-
return { message: 'Todo created - role-based auth' };
|
|
104
|
-
});
|
|
105
|
-
// 2. Permission-based authorization (more granular)
|
|
106
|
-
app.post('/todos/create-permission-based', {
|
|
107
|
-
preHandler: jwtAuthMiddleware.requirePermissions(['todo:create', 'todo:write'])
|
|
108
|
-
}, async (request, reply) => {
|
|
109
|
-
return { message: 'Todo created - permission-based auth' };
|
|
110
|
-
});
|
|
111
|
-
// 3. Combined role and permission authorization
|
|
112
|
-
app.post('/todos/create-combined', {
|
|
113
|
-
preHandler: jwtAuthMiddleware.requireAuth(['jwt'], // strategies
|
|
114
|
-
['manager', 'admin'], // required roles
|
|
115
|
-
['todo:create'] // required permissions
|
|
116
|
-
)
|
|
117
|
-
}, async (request, reply) => {
|
|
118
|
-
return { message: 'Todo created - combined auth' };
|
|
119
|
-
});
|
|
120
|
-
// 4. Strategy-specific with roles
|
|
121
|
-
app.post('/todos/create-jwt-only', {
|
|
122
|
-
preHandler: jwtAuthMiddleware.requireStrategy('jwt', ['manager'])
|
|
123
|
-
}, async (request, reply) => {
|
|
124
|
-
return { message: 'Todo created - JWT strategy with manager role' };
|
|
125
|
-
});
|
|
126
|
-
// 5. Optional authentication (user info available if authenticated)
|
|
127
|
-
app.get('/todos/public-with-optional-auth', {
|
|
128
|
-
preHandler: jwtAuthMiddleware.optionalAuth(['jwt', 'api-key'])
|
|
129
|
-
}, async (request, reply) => {
|
|
130
|
-
const user = request.user;
|
|
131
|
-
if (user) {
|
|
132
|
-
return { message: `Hello ${user.email}, here are your todos` };
|
|
133
|
-
}
|
|
134
|
-
return { message: 'Public todos (not authenticated)' };
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// How to modify your existing TodoController:
|
|
138
|
-
exports.AuthorizedTodoControllerExample = `
|
|
139
|
-
// Instead of:
|
|
140
|
-
@UseMiddleware(authorize(['manager']))
|
|
141
|
-
async createTodo(@Body() body: z.infer<typeof todoSchema>) {
|
|
142
|
-
// ...
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// You can use:
|
|
146
|
-
@UseMiddleware(this.jwtAuthMiddleware.requireRoles(['manager']))
|
|
147
|
-
async createTodo(@Body() body: z.infer<typeof todoSchema>) {
|
|
148
|
-
// ...
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Or for more granular control:
|
|
152
|
-
@UseMiddleware(this.jwtAuthMiddleware.requirePermissions(['todo:create']))
|
|
153
|
-
async createTodo(@Body() body: z.infer<typeof todoSchema>) {
|
|
154
|
-
// ...
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Or combined:
|
|
158
|
-
@UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt'], ['manager'], ['todo:create']))
|
|
159
|
-
async createTodo(@Body() body: z.infer<typeof todoSchema>) {
|
|
160
|
-
// ...
|
|
161
|
-
}
|
|
162
|
-
`;
|
|
163
|
-
// Comparison of approaches:
|
|
164
|
-
exports.AuthorizationComparison = {
|
|
165
|
-
current: {
|
|
166
|
-
method: 'authorize(["manager"])',
|
|
167
|
-
description: 'Simple role-based check using custom middleware',
|
|
168
|
-
pros: ['Simple to use', 'Clear syntax'],
|
|
169
|
-
cons: ['Limited to roles only', 'Separate from auth system', 'No permission support']
|
|
170
|
-
},
|
|
171
|
-
jwtMiddleware: {
|
|
172
|
-
method: 'jwtAuthMiddleware.requireRoles(["manager"])',
|
|
173
|
-
description: 'Built-in JWT middleware authorization',
|
|
174
|
-
pros: [
|
|
175
|
-
'Integrated with authentication system',
|
|
176
|
-
'Supports roles, permissions, and strategies',
|
|
177
|
-
'Consistent with JWT auth flow',
|
|
178
|
-
'More flexible and powerful'
|
|
179
|
-
],
|
|
180
|
-
cons: ['Slightly more verbose', 'Requires middleware instance']
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
// Best practices for authorization:
|
|
184
|
-
exports.AuthorizationBestPractices = {
|
|
185
|
-
roles: {
|
|
186
|
-
description: 'Use for broad access control (admin, manager, user)',
|
|
187
|
-
example: 'jwtAuthMiddleware.requireRoles(["admin", "manager"])'
|
|
188
|
-
},
|
|
189
|
-
permissions: {
|
|
190
|
-
description: 'Use for specific action control (create, read, update, delete)',
|
|
191
|
-
example: 'jwtAuthMiddleware.requirePermissions(["todo:create", "todo:update"])'
|
|
192
|
-
},
|
|
193
|
-
combined: {
|
|
194
|
-
description: 'Use when you need both role and permission checks',
|
|
195
|
-
example: 'jwtAuthMiddleware.requireAuth(["jwt"], ["manager"], ["todo:create"])'
|
|
196
|
-
},
|
|
197
|
-
strategy: {
|
|
198
|
-
description: 'Use when different auth strategies have different access levels',
|
|
199
|
-
example: 'jwtAuthMiddleware.requireStrategy("jwt", ["admin"])'
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
//# sourceMappingURL=authorization-examples.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-examples.js","sourceRoot":"","sources":["../../src/examples/authorization-examples.ts"],"names":[],"mappings":";A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;QACL,WAAW,EAAE,qDAAqD;QAClE,OAAO,EAAE,sDAAsD;KAChE;IACD,WAAW,EAAE;QACX,WAAW,EAAE,gEAAgE;QAC7E,OAAO,EAAE,sEAAsE;KAChF;IACD,QAAQ,EAAE;QACR,WAAW,EAAE,mDAAmD;QAChE,OAAO,EAAE,sEAAsE;KAChF;IACD,QAAQ,EAAE;QACR,WAAW,EAAE,iEAAiE;QAC9E,OAAO,EAAE,qDAAqD;KAC/D;CACF,CAAC"}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { TodoService } from '../services/todo.service';
|
|
3
|
-
import { AuthMiddleware } from '../../auth/middleware/AuthMiddleware';
|
|
4
|
-
declare const todoSchema: z.ZodObject<{
|
|
5
|
-
text: z.ZodString;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
text: string;
|
|
8
|
-
}, {
|
|
9
|
-
text: string;
|
|
10
|
-
}>;
|
|
11
|
-
/**
|
|
12
|
-
* Updated TodoController using JWT Middleware Authorization
|
|
13
|
-
*
|
|
14
|
-
* This shows how to replace authorize(['manager']) with JWT middleware methods
|
|
15
|
-
*/
|
|
16
|
-
export declare class TodoController {
|
|
17
|
-
private readonly todoService;
|
|
18
|
-
constructor(todoService: TodoService);
|
|
19
|
-
private tracingService;
|
|
20
|
-
private authManager;
|
|
21
|
-
private jwtAuthMiddleware;
|
|
22
|
-
private logger;
|
|
23
|
-
getAllTodos(): {
|
|
24
|
-
id: string;
|
|
25
|
-
text: string;
|
|
26
|
-
completed: boolean;
|
|
27
|
-
}[];
|
|
28
|
-
getTodoById(id: string): {
|
|
29
|
-
id: string;
|
|
30
|
-
text: string;
|
|
31
|
-
completed: boolean;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* OPTION 1: Direct replacement using requireRoles
|
|
35
|
-
* This is the most direct replacement for authorize(['manager'])
|
|
36
|
-
*/
|
|
37
|
-
createTodoOption1(body: z.infer<typeof todoSchema>): Promise<{
|
|
38
|
-
id: string;
|
|
39
|
-
text: string;
|
|
40
|
-
completed: boolean;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* OPTION 2: Using requireAuth with explicit strategy and roles
|
|
44
|
-
* More explicit about authentication strategy
|
|
45
|
-
*/
|
|
46
|
-
createTodoOption2(body: z.infer<typeof todoSchema>): Promise<{
|
|
47
|
-
id: string;
|
|
48
|
-
text: string;
|
|
49
|
-
completed: boolean;
|
|
50
|
-
}>;
|
|
51
|
-
/**
|
|
52
|
-
* OPTION 3: Permission-based authorization
|
|
53
|
-
* More granular control using permissions instead of roles
|
|
54
|
-
*/
|
|
55
|
-
createTodoOption3(body: z.infer<typeof todoSchema>): Promise<{
|
|
56
|
-
id: string;
|
|
57
|
-
text: string;
|
|
58
|
-
completed: boolean;
|
|
59
|
-
}>;
|
|
60
|
-
/**
|
|
61
|
-
* OPTION 4: Combined role and permission check
|
|
62
|
-
* Most secure - requires both role AND permission
|
|
63
|
-
*/
|
|
64
|
-
createTodoOption4(body: z.infer<typeof todoSchema>): Promise<{
|
|
65
|
-
id: string;
|
|
66
|
-
text: string;
|
|
67
|
-
completed: boolean;
|
|
68
|
-
}>;
|
|
69
|
-
/**
|
|
70
|
-
* YOUR ORIGINAL METHOD - Updated to use JWT middleware
|
|
71
|
-
* This is how you would update your existing createTodo method
|
|
72
|
-
*/
|
|
73
|
-
createTodo(body: z.infer<typeof todoSchema>): Promise<{
|
|
74
|
-
id: string;
|
|
75
|
-
text: string;
|
|
76
|
-
completed: boolean;
|
|
77
|
-
}>;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* IMPORTANT: To make this work, you need to:
|
|
81
|
-
*
|
|
82
|
-
* 1. Register JWT middleware in your DI container (in src/examples/index.ts):
|
|
83
|
-
*
|
|
84
|
-
* container.register('JwtAuthMiddleware', {
|
|
85
|
-
* useFactory: () => jwtAuthMiddleware
|
|
86
|
-
* })
|
|
87
|
-
*
|
|
88
|
-
* 2. The middleware methods are commented out because decorators can't access
|
|
89
|
-
* instance properties. You have two solutions:
|
|
90
|
-
*
|
|
91
|
-
* Solution A: Use manual route registration (see registerTodoRoutes function below)
|
|
92
|
-
* Solution B: Create a factory function that returns the middleware
|
|
93
|
-
*
|
|
94
|
-
* 3. Update your user model to include roles/permissions that match what
|
|
95
|
-
* you're checking for (e.g., 'manager' role, 'todo:create' permission)
|
|
96
|
-
*/
|
|
97
|
-
/**
|
|
98
|
-
* Solution A: Manual Route Registration
|
|
99
|
-
* Use this approach if decorators don't work with instance methods
|
|
100
|
-
*/
|
|
101
|
-
export declare function registerTodoRoutes(app: any, todoController: TodoController, jwtAuthMiddleware: AuthMiddleware): void;
|
|
102
|
-
export {};
|
|
103
|
-
//# sourceMappingURL=todo-updated.controller.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"todo-updated.controller.d.ts","sourceRoot":"","sources":["../../../src/examples/controllers/todo-updated.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAoBvB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AAUrE,QAAA,MAAM,UAAU;;;;;;EAIH,CAAA;AAQb;;;;GAIG;AACH,qBAGa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAGrD,OAAO,CAAC,cAAc,CAAiB;IAGvC,OAAO,CAAC,WAAW,CAAc;IAIjC,OAAO,CAAC,iBAAiB,CAAiB;IAE1C,OAAO,CAAC,MAAM,CAAS;IAGvB,WAAW;;;;;IAUX,WAAW,CAAc,EAAE,EAAE,MAAM;;;;;IAKnC;;;OAGG;IAkBG,iBAAiB,CAAS,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC;;;;;IAMhE;;;OAGG;IAiBG,iBAAiB,CA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