bootifyjs 1.1.8 → 1.2.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 +89 -0
- package/dist/api.d.ts +4 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +25 -10
- package/dist/api.js.map +1 -1
- package/dist/auth/AuthManager.d.ts +68 -0
- package/dist/auth/AuthManager.d.ts.map +1 -0
- package/dist/auth/AuthManager.js +239 -0
- package/dist/auth/AuthManager.js.map +1 -0
- package/dist/auth/examples/basic-usage.d.ts +29 -0
- package/dist/auth/examples/basic-usage.d.ts.map +1 -0
- package/dist/auth/examples/basic-usage.js +390 -0
- package/dist/auth/examples/basic-usage.js.map +1 -0
- package/dist/auth/index.d.ts +72 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +118 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts +110 -0
- package/dist/auth/middleware/AuthMiddleware.d.ts.map +1 -0
- package/dist/auth/middleware/AuthMiddleware.js +336 -0
- package/dist/auth/middleware/AuthMiddleware.js.map +1 -0
- package/dist/auth/storage/RedisTokenStorage.d.ts +92 -0
- package/dist/auth/storage/RedisTokenStorage.d.ts.map +1 -0
- package/dist/auth/storage/RedisTokenStorage.js +207 -0
- package/dist/auth/storage/RedisTokenStorage.js.map +1 -0
- package/dist/auth/strategies/ApiKeyStrategy.d.ts +64 -0
- package/dist/auth/strategies/ApiKeyStrategy.d.ts.map +1 -0
- package/dist/auth/strategies/ApiKeyStrategy.js +391 -0
- package/dist/auth/strategies/ApiKeyStrategy.js.map +1 -0
- package/dist/auth/strategies/JwtStrategy.d.ts +46 -0
- package/dist/auth/strategies/JwtStrategy.d.ts.map +1 -0
- package/dist/auth/strategies/JwtStrategy.js +310 -0
- package/dist/auth/strategies/JwtStrategy.js.map +1 -0
- package/dist/auth/types.d.ts +130 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +50 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/config/AppConfig.d.ts +4 -7
- package/dist/config/AppConfig.d.ts.map +1 -1
- package/dist/config/AppConfig.js +13 -6
- package/dist/config/AppConfig.js.map +1 -1
- package/dist/constants/index.d.ts +61 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +75 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/decorators.d.ts +7 -7
- package/dist/core/decorators.d.ts.map +1 -1
- package/dist/core/decorators.js +8 -7
- package/dist/core/decorators.js.map +1 -1
- package/dist/core/di-container.d.ts +1 -1
- package/dist/core/di-container.d.ts.map +1 -1
- package/dist/core/di-container.js +3 -3
- package/dist/core/di-container.js.map +1 -1
- package/dist/events/event-bus.service.d.ts.map +1 -1
- package/dist/events/event-bus.service.js +2 -0
- package/dist/events/event-bus.service.js.map +1 -1
- package/dist/examples/auth/auth.middleware.d.ts +27 -0
- package/dist/examples/auth/auth.middleware.d.ts.map +1 -0
- package/dist/examples/auth/auth.middleware.js +187 -0
- package/dist/examples/auth/auth.middleware.js.map +1 -0
- package/dist/examples/auth/authorization.middleware.d.ts +1 -0
- package/dist/examples/auth/authorization.middleware.d.ts.map +1 -0
- package/dist/examples/auth/authorization.middleware.js +2 -0
- package/dist/examples/auth/authorization.middleware.js.map +1 -0
- package/dist/examples/auth/context.extractor.d.ts +1 -0
- package/dist/examples/auth/context.extractor.d.ts.map +1 -0
- package/dist/examples/auth/context.extractor.js +2 -0
- package/dist/examples/auth/context.extractor.js.map +1 -0
- package/dist/examples/auth/example.d.ts +1 -0
- package/dist/examples/auth/example.d.ts.map +1 -0
- package/dist/examples/auth/example.js +2 -0
- package/dist/examples/auth/example.js.map +1 -0
- package/dist/examples/auth/provider.d.ts +1 -0
- package/dist/examples/auth/provider.d.ts.map +1 -0
- package/dist/examples/auth/provider.js +2 -0
- package/dist/examples/auth/provider.js.map +1 -0
- package/dist/examples/auth/users.d.ts +1 -0
- package/dist/examples/auth/users.d.ts.map +1 -0
- package/dist/examples/auth/users.js +2 -0
- package/dist/examples/auth/users.js.map +1 -0
- package/dist/examples/authorization-examples.d.ts +67 -0
- package/dist/examples/authorization-examples.d.ts.map +1 -0
- package/dist/examples/authorization-examples.js +202 -0
- package/dist/examples/authorization-examples.js.map +1 -0
- package/dist/examples/controllers/auth.controller.d.ts +64 -0
- package/dist/examples/controllers/auth.controller.d.ts.map +1 -0
- package/dist/examples/controllers/auth.controller.js +284 -0
- package/dist/examples/controllers/auth.controller.js.map +1 -0
- package/dist/examples/controllers/health.controller.d.ts +1 -0
- package/dist/examples/controllers/health.controller.d.ts.map +1 -1
- package/dist/examples/controllers/health.controller.js +6 -0
- package/dist/examples/controllers/health.controller.js.map +1 -1
- package/dist/examples/controllers/todo-updated.controller.d.ts +103 -0
- package/dist/examples/controllers/todo-updated.controller.d.ts.map +1 -0
- package/dist/examples/controllers/todo-updated.controller.js +328 -0
- package/dist/examples/controllers/todo-updated.controller.js.map +1 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts +114 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.d.ts.map +1 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js +329 -0
- package/dist/examples/controllers/todo-with-jwt-auth.controller.js.map +1 -0
- package/dist/examples/controllers/todo.controller.d.ts +4 -2
- package/dist/examples/controllers/todo.controller.d.ts.map +1 -1
- package/dist/examples/controllers/todo.controller.js +44 -18
- package/dist/examples/controllers/todo.controller.js.map +1 -1
- package/dist/examples/events/TodoEventHandler.d.ts +4 -1
- package/dist/examples/events/TodoEventHandler.d.ts.map +1 -1
- package/dist/examples/events/TodoEventHandler.js +8 -4
- package/dist/examples/events/TodoEventHandler.js.map +1 -1
- package/dist/examples/global-middleware-example.d.ts +2 -0
- package/dist/examples/global-middleware-example.d.ts.map +1 -0
- package/dist/examples/global-middleware-example.js +94 -0
- package/dist/examples/global-middleware-example.js.map +1 -0
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +81 -25
- package/dist/examples/index.js.map +1 -1
- package/dist/examples/jwt-auth-example.d.ts +47 -0
- package/dist/examples/jwt-auth-example.d.ts.map +1 -0
- package/dist/examples/jwt-auth-example.js +316 -0
- package/dist/examples/jwt-auth-example.js.map +1 -0
- package/dist/examples/services/todo.service.d.ts +3 -2
- package/dist/examples/services/todo.service.d.ts.map +1 -1
- package/dist/examples/services/todo.service.js +12 -2
- package/dist/examples/services/todo.service.js.map +1 -1
- package/dist/examples/services/user.service.d.ts +99 -0
- package/dist/examples/services/user.service.d.ts.map +1 -0
- package/dist/examples/services/user.service.js +281 -0
- package/dist/examples/services/user.service.js.map +1 -0
- package/dist/examples/simple-auth-example.d.ts +7 -0
- package/dist/examples/simple-auth-example.d.ts.map +1 -0
- package/dist/examples/simple-auth-example.js +106 -0
- package/dist/examples/simple-auth-example.js.map +1 -0
- package/dist/examples/test-auth-flow.d.ts +56 -0
- package/dist/examples/test-auth-flow.d.ts.map +1 -0
- package/dist/examples/test-auth-flow.js +449 -0
- package/dist/examples/test-auth-flow.js.map +1 -0
- package/dist/examples/todos/schema.d.ts +8 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/logging/config/logging.config.d.ts +0 -32
- package/dist/logging/config/logging.config.d.ts.map +1 -1
- package/dist/logging/config/logging.config.js +43 -49
- package/dist/logging/config/logging.config.js.map +1 -1
- package/dist/logging/core/logger.d.ts +2 -0
- package/dist/logging/core/logger.d.ts.map +1 -1
- package/dist/logging/core/logger.js +6 -0
- package/dist/logging/core/logger.js.map +1 -1
- package/dist/logging/core/logger.provider.d.ts.map +1 -1
- package/dist/logging/core/logger.provider.js +24 -12
- package/dist/logging/core/logger.provider.js.map +1 -1
- package/dist/logging/core/startup.logger.d.ts +1 -1
- package/dist/logging/core/startup.logger.d.ts.map +1 -1
- package/dist/logging/core/startup.logger.js +6 -3
- package/dist/logging/core/startup.logger.js.map +1 -1
- package/dist/logging/core/tracing.service.d.ts +32 -0
- package/dist/logging/core/tracing.service.d.ts.map +1 -0
- package/dist/logging/core/tracing.service.js +165 -0
- package/dist/logging/core/tracing.service.js.map +1 -0
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/logging/index.js +3 -2
- package/dist/logging/index.js.map +1 -1
- package/dist/middleware/auth-context.extractor.d.ts +5 -0
- package/dist/middleware/auth-context.extractor.d.ts.map +1 -0
- package/dist/middleware/auth-context.extractor.js +114 -0
- package/dist/middleware/auth-context.extractor.js.map +1 -0
- package/dist/middleware/auth.middleware.d.ts +16 -2
- package/dist/middleware/auth.middleware.d.ts.map +1 -1
- package/dist/middleware/auth.middleware.js +110 -13
- package/dist/middleware/auth.middleware.js.map +1 -1
- package/dist/middleware/authorization.middleware.d.ts +21 -0
- package/dist/middleware/authorization.middleware.d.ts.map +1 -0
- package/dist/middleware/authorization.middleware.js +55 -0
- package/dist/middleware/authorization.middleware.js.map +1 -0
- package/dist/middleware/context.middleware.d.ts +12 -2
- package/dist/middleware/context.middleware.d.ts.map +1 -1
- package/dist/middleware/context.middleware.js +43 -17
- package/dist/middleware/context.middleware.js.map +1 -1
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/request-logger.middleware.d.ts +2 -0
- package/dist/middleware/request-logger.middleware.d.ts.map +1 -1
- package/dist/middleware/request-logger.middleware.js +22 -1
- package/dist/middleware/request-logger.middleware.js.map +1 -1
- package/dist/middleware/tracing.middleware.d.ts +15 -0
- package/dist/middleware/tracing.middleware.d.ts.map +1 -0
- package/dist/middleware/tracing.middleware.js +36 -0
- package/dist/middleware/tracing.middleware.js.map +1 -0
- package/package.json +10 -2
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TodoWithJwtAuthController = void 0;
|
|
16
|
+
exports.setupTodoWithJwtAuth = setupTodoWithJwtAuth;
|
|
17
|
+
exports.registerTodoJwtAuthRoutes = registerTodoJwtAuthRoutes;
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const decorators_1 = require("../../cache/decorators");
|
|
20
|
+
const decorators_2 = require("../../core/decorators");
|
|
21
|
+
const decorators_3 = require("../../logging/core/decorators");
|
|
22
|
+
const logger_1 = require("../../logging/core/logger");
|
|
23
|
+
const tracing_service_1 = require("../../logging/core/tracing.service");
|
|
24
|
+
const todo_service_1 = require("../services/todo.service");
|
|
25
|
+
const auth_1 = require("../../auth");
|
|
26
|
+
const todoSchema = zod_1.z
|
|
27
|
+
.object({
|
|
28
|
+
text: zod_1.z.string().min(2, 'Text cannot be empty'),
|
|
29
|
+
})
|
|
30
|
+
.required();
|
|
31
|
+
const getTodoByIdSchema = {
|
|
32
|
+
params: zod_1.z.object({
|
|
33
|
+
id: zod_1.z.string().regex(/^\d+$/, 'ID must be a numeric string'),
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Enhanced TodoController using JWT Middleware Authorization
|
|
38
|
+
*
|
|
39
|
+
* This controller demonstrates different authorization patterns
|
|
40
|
+
* using the built-in JWT middleware methods instead of the
|
|
41
|
+
* separate authorize() middleware.
|
|
42
|
+
*/
|
|
43
|
+
let TodoWithJwtAuthController = class TodoWithJwtAuthController {
|
|
44
|
+
constructor(todoService) {
|
|
45
|
+
this.todoService = todoService;
|
|
46
|
+
}
|
|
47
|
+
// Method to set the JWT middleware (called during setup)
|
|
48
|
+
setJwtMiddleware(middleware) {
|
|
49
|
+
this.jwtAuthMiddleware = middleware;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Public endpoint - no authentication required
|
|
53
|
+
*/
|
|
54
|
+
async getPublicTodos() {
|
|
55
|
+
this.logger.info('Fetching public todos');
|
|
56
|
+
return await this.todoService.getAllTodos();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Optional authentication - user info available if authenticated
|
|
60
|
+
*/
|
|
61
|
+
// Note: In practice, you'd need to pass the middleware function here
|
|
62
|
+
// @UseMiddleware(this.jwtAuthMiddleware.optionalAuth(['jwt', 'api-key']))
|
|
63
|
+
async getTodosWithOptionalAuth() {
|
|
64
|
+
// Access user info if available: (request as any).user
|
|
65
|
+
this.logger.info('Fetching todos with optional auth');
|
|
66
|
+
return await this.todoService.getAllTodos();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Basic authentication required - any authenticated user
|
|
70
|
+
*/
|
|
71
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt', 'api-key']))
|
|
72
|
+
async getAuthenticatedTodos() {
|
|
73
|
+
this.logger.info('Fetching todos for authenticated user');
|
|
74
|
+
return await this.todoService.getAllTodos();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Role-based authorization - equivalent to authorize(['manager'])
|
|
78
|
+
*/
|
|
79
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireRoles(['manager', 'admin']))
|
|
80
|
+
async createTodoRoleBased(body) {
|
|
81
|
+
this.logger.info('Creating todo with role-based auth', body);
|
|
82
|
+
return await this.todoService.createTodo(body.text);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Permission-based authorization - more granular control
|
|
86
|
+
*/
|
|
87
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requirePermissions(['todo:create', 'todo:write']))
|
|
88
|
+
async createTodoPermissionBased(body) {
|
|
89
|
+
this.logger.info('Creating todo with permission-based auth', body);
|
|
90
|
+
return await this.todoService.createTodo(body.text);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Combined role and permission authorization
|
|
94
|
+
*/
|
|
95
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt'], ['manager', 'admin'], ['todo:create']))
|
|
96
|
+
async createTodoCombined(body) {
|
|
97
|
+
this.logger.info('Creating todo with combined auth', body);
|
|
98
|
+
return await this.todoService.createTodo(body.text);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Strategy-specific authorization - JWT only with admin role
|
|
102
|
+
*/
|
|
103
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireStrategy('jwt', ['admin']))
|
|
104
|
+
async adminOnlyEndpoint(body) {
|
|
105
|
+
this.logger.info('Admin-only endpoint accessed');
|
|
106
|
+
return { message: 'Admin-only content', data: body };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get todo by ID with caching and role-based auth
|
|
110
|
+
*/
|
|
111
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireRoles(['user', 'manager', 'admin']))
|
|
112
|
+
async getTodoById(id) {
|
|
113
|
+
this.logger.info(`Fetching todo with ID: ${id}`);
|
|
114
|
+
return await this.todoService.getTodoById(id);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Update todo - requires specific permissions
|
|
118
|
+
*/
|
|
119
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requirePermissions(['todo:update']))
|
|
120
|
+
async updateTodo(id, body) {
|
|
121
|
+
this.logger.info(`Updating todo ${id}`, body);
|
|
122
|
+
// Implementation would go here
|
|
123
|
+
return { id, ...body, updated: true };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Delete todo - admin or owner only
|
|
127
|
+
*/
|
|
128
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt'], ['admin'], ['todo:delete']))
|
|
129
|
+
async deleteTodo(id) {
|
|
130
|
+
this.logger.info(`Deleting todo ${id}`);
|
|
131
|
+
// Implementation would go here
|
|
132
|
+
return { message: `Todo ${id} deleted` };
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
exports.TodoWithJwtAuthController = TodoWithJwtAuthController;
|
|
136
|
+
__decorate([
|
|
137
|
+
(0, decorators_2.Autowired)(tracing_service_1.TracingService),
|
|
138
|
+
__metadata("design:type", tracing_service_1.TracingService)
|
|
139
|
+
], TodoWithJwtAuthController.prototype, "tracingService", void 0);
|
|
140
|
+
__decorate([
|
|
141
|
+
(0, decorators_2.Autowired)('AuthManager'),
|
|
142
|
+
__metadata("design:type", auth_1.AuthManager)
|
|
143
|
+
], TodoWithJwtAuthController.prototype, "authManager", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, decorators_2.Autowired)(logger_1.Logger),
|
|
146
|
+
__metadata("design:type", logger_1.Logger
|
|
147
|
+
// We need to inject the JWT middleware to use its authorization methods
|
|
148
|
+
)
|
|
149
|
+
], TodoWithJwtAuthController.prototype, "logger", void 0);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, decorators_2.Get)('/public'),
|
|
152
|
+
__metadata("design:type", Function),
|
|
153
|
+
__metadata("design:paramtypes", []),
|
|
154
|
+
__metadata("design:returntype", Promise)
|
|
155
|
+
], TodoWithJwtAuthController.prototype, "getPublicTodos", null);
|
|
156
|
+
__decorate([
|
|
157
|
+
(0, decorators_2.Get)('/optional-auth')
|
|
158
|
+
// Note: In practice, you'd need to pass the middleware function here
|
|
159
|
+
// @UseMiddleware(this.jwtAuthMiddleware.optionalAuth(['jwt', 'api-key']))
|
|
160
|
+
,
|
|
161
|
+
__metadata("design:type", Function),
|
|
162
|
+
__metadata("design:paramtypes", []),
|
|
163
|
+
__metadata("design:returntype", Promise)
|
|
164
|
+
], TodoWithJwtAuthController.prototype, "getTodosWithOptionalAuth", null);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, decorators_2.Get)('/authenticated')
|
|
167
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt', 'api-key']))
|
|
168
|
+
,
|
|
169
|
+
__metadata("design:type", Function),
|
|
170
|
+
__metadata("design:paramtypes", []),
|
|
171
|
+
__metadata("design:returntype", Promise)
|
|
172
|
+
], TodoWithJwtAuthController.prototype, "getAuthenticatedTodos", null);
|
|
173
|
+
__decorate([
|
|
174
|
+
(0, decorators_2.Post)('/create-role-based'),
|
|
175
|
+
(0, decorators_2.Schema)({
|
|
176
|
+
body: todoSchema,
|
|
177
|
+
responses: {
|
|
178
|
+
201: zod_1.z.object({
|
|
179
|
+
id: zod_1.z.string(),
|
|
180
|
+
text: zod_1.z.string(),
|
|
181
|
+
completed: zod_1.z.boolean(),
|
|
182
|
+
}),
|
|
183
|
+
},
|
|
184
|
+
})
|
|
185
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireRoles(['manager', 'admin']))
|
|
186
|
+
,
|
|
187
|
+
__param(0, (0, decorators_2.Body)()),
|
|
188
|
+
__metadata("design:type", Function),
|
|
189
|
+
__metadata("design:paramtypes", [void 0]),
|
|
190
|
+
__metadata("design:returntype", Promise)
|
|
191
|
+
], TodoWithJwtAuthController.prototype, "createTodoRoleBased", null);
|
|
192
|
+
__decorate([
|
|
193
|
+
(0, decorators_2.Post)('/create-permission-based'),
|
|
194
|
+
(0, decorators_2.Schema)({
|
|
195
|
+
body: todoSchema,
|
|
196
|
+
})
|
|
197
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requirePermissions(['todo:create', 'todo:write']))
|
|
198
|
+
,
|
|
199
|
+
__param(0, (0, decorators_2.Body)()),
|
|
200
|
+
__metadata("design:type", Function),
|
|
201
|
+
__metadata("design:paramtypes", [void 0]),
|
|
202
|
+
__metadata("design:returntype", Promise)
|
|
203
|
+
], TodoWithJwtAuthController.prototype, "createTodoPermissionBased", null);
|
|
204
|
+
__decorate([
|
|
205
|
+
(0, decorators_2.Post)('/create-combined'),
|
|
206
|
+
(0, decorators_3.Audit)({
|
|
207
|
+
action: 'create',
|
|
208
|
+
resource: 'todo',
|
|
209
|
+
}),
|
|
210
|
+
(0, decorators_2.Schema)({
|
|
211
|
+
body: todoSchema,
|
|
212
|
+
})
|
|
213
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt'], ['manager', 'admin'], ['todo:create']))
|
|
214
|
+
,
|
|
215
|
+
__param(0, (0, decorators_2.Body)()),
|
|
216
|
+
__metadata("design:type", Function),
|
|
217
|
+
__metadata("design:paramtypes", [void 0]),
|
|
218
|
+
__metadata("design:returntype", Promise)
|
|
219
|
+
], TodoWithJwtAuthController.prototype, "createTodoCombined", null);
|
|
220
|
+
__decorate([
|
|
221
|
+
(0, decorators_2.Post)('/admin-only')
|
|
222
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireStrategy('jwt', ['admin']))
|
|
223
|
+
,
|
|
224
|
+
__param(0, (0, decorators_2.Body)()),
|
|
225
|
+
__metadata("design:type", Function),
|
|
226
|
+
__metadata("design:paramtypes", [Object]),
|
|
227
|
+
__metadata("design:returntype", Promise)
|
|
228
|
+
], TodoWithJwtAuthController.prototype, "adminOnlyEndpoint", null);
|
|
229
|
+
__decorate([
|
|
230
|
+
(0, decorators_2.Get)('/:id'),
|
|
231
|
+
(0, decorators_1.Cacheable)({ key: 'todo', ttl: 60 }),
|
|
232
|
+
(0, decorators_2.Schema)(getTodoByIdSchema)
|
|
233
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireRoles(['user', 'manager', 'admin']))
|
|
234
|
+
,
|
|
235
|
+
__param(0, (0, decorators_2.Param)('id')),
|
|
236
|
+
__metadata("design:type", Function),
|
|
237
|
+
__metadata("design:paramtypes", [String]),
|
|
238
|
+
__metadata("design:returntype", Promise)
|
|
239
|
+
], TodoWithJwtAuthController.prototype, "getTodoById", null);
|
|
240
|
+
__decorate([
|
|
241
|
+
(0, decorators_2.Post)('/:id/update'),
|
|
242
|
+
(0, decorators_2.Schema)({
|
|
243
|
+
params: zod_1.z.object({ id: zod_1.z.string() }),
|
|
244
|
+
body: todoSchema,
|
|
245
|
+
})
|
|
246
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requirePermissions(['todo:update']))
|
|
247
|
+
,
|
|
248
|
+
__param(0, (0, decorators_2.Param)('id')),
|
|
249
|
+
__param(1, (0, decorators_2.Body)()),
|
|
250
|
+
__metadata("design:type", Function),
|
|
251
|
+
__metadata("design:paramtypes", [String, void 0]),
|
|
252
|
+
__metadata("design:returntype", Promise)
|
|
253
|
+
], TodoWithJwtAuthController.prototype, "updateTodo", null);
|
|
254
|
+
__decorate([
|
|
255
|
+
(0, decorators_2.Post)('/:id/delete'),
|
|
256
|
+
(0, decorators_2.Schema)({
|
|
257
|
+
params: zod_1.z.object({ id: zod_1.z.string() }),
|
|
258
|
+
})
|
|
259
|
+
// @UseMiddleware(this.jwtAuthMiddleware.requireAuth(['jwt'], ['admin'], ['todo:delete']))
|
|
260
|
+
,
|
|
261
|
+
__param(0, (0, decorators_2.Param)('id')),
|
|
262
|
+
__metadata("design:type", Function),
|
|
263
|
+
__metadata("design:paramtypes", [String]),
|
|
264
|
+
__metadata("design:returntype", Promise)
|
|
265
|
+
], TodoWithJwtAuthController.prototype, "deleteTodo", null);
|
|
266
|
+
exports.TodoWithJwtAuthController = TodoWithJwtAuthController = __decorate([
|
|
267
|
+
(0, decorators_3.Loggable)(),
|
|
268
|
+
(0, decorators_2.Controller)('/api/todos-jwt'),
|
|
269
|
+
__metadata("design:paramtypes", [todo_service_1.TodoService])
|
|
270
|
+
], TodoWithJwtAuthController);
|
|
271
|
+
/**
|
|
272
|
+
* Helper function to setup the controller with JWT middleware
|
|
273
|
+
*/
|
|
274
|
+
function setupTodoWithJwtAuth(controller, jwtAuthMiddleware) {
|
|
275
|
+
controller.setJwtMiddleware(jwtAuthMiddleware);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Example of how to register routes manually with Fastify
|
|
279
|
+
* (Alternative to using decorators)
|
|
280
|
+
*/
|
|
281
|
+
function registerTodoJwtAuthRoutes(app, todoService, jwtAuthMiddleware) {
|
|
282
|
+
// Role-based authorization
|
|
283
|
+
app.post('/api/todos/create-role', {
|
|
284
|
+
preHandler: jwtAuthMiddleware.requireRoles(['manager', 'admin'])
|
|
285
|
+
}, async (request, reply) => {
|
|
286
|
+
const { text } = request.body;
|
|
287
|
+
const result = await todoService.createTodo(text);
|
|
288
|
+
return result;
|
|
289
|
+
});
|
|
290
|
+
// Permission-based authorization
|
|
291
|
+
app.post('/api/todos/create-permission', {
|
|
292
|
+
preHandler: jwtAuthMiddleware.requirePermissions(['todo:create'])
|
|
293
|
+
}, async (request, reply) => {
|
|
294
|
+
const { text } = request.body;
|
|
295
|
+
const result = await todoService.createTodo(text);
|
|
296
|
+
return result;
|
|
297
|
+
});
|
|
298
|
+
// Combined authorization
|
|
299
|
+
app.post('/api/todos/create-combined', {
|
|
300
|
+
preHandler: jwtAuthMiddleware.requireAuth(['jwt'], // strategies
|
|
301
|
+
['manager'], // roles
|
|
302
|
+
['todo:create'] // permissions
|
|
303
|
+
)
|
|
304
|
+
}, async (request, reply) => {
|
|
305
|
+
const { text } = request.body;
|
|
306
|
+
const result = await todoService.createTodo(text);
|
|
307
|
+
return result;
|
|
308
|
+
});
|
|
309
|
+
// Optional authentication
|
|
310
|
+
app.get('/api/todos/optional', {
|
|
311
|
+
preHandler: jwtAuthMiddleware.optionalAuth(['jwt', 'api-key'])
|
|
312
|
+
}, async (request, reply) => {
|
|
313
|
+
const user = request.user;
|
|
314
|
+
const todos = await todoService.getAllTodos();
|
|
315
|
+
if (user) {
|
|
316
|
+
return {
|
|
317
|
+
message: `Hello ${user.email || user.username}`,
|
|
318
|
+
todos,
|
|
319
|
+
authenticated: true
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
message: 'Public access',
|
|
324
|
+
todos: todos.slice(0, 5), // Limited for non-authenticated users
|
|
325
|
+
authenticated: false
|
|
326
|
+
};
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=todo-with-jwt-auth.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo-with-jwt-auth.controller.js","sourceRoot":"","sources":["../../../src/examples/controllers/todo-with-jwt-auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuMA,oDAKC;AAMD,8DAyDC;AA3QD,6BAAuB;AACvB,uDAAkD;AAClD,sDAS8B;AAC9B,8DAA+D;AAC/D,sDAAkD;AAClD,wEAAmE;AACnE,2DAAsD;AACtD,qCAAwC;AAGxC,MAAM,UAAU,GAAG,OAAC;KACjB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC;CAChD,CAAC;KACD,QAAQ,EAAE,CAAA;AAEb,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;QACf,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC;KAC7D,CAAC;CACH,CAAA;AAED;;;;;;GAMG;AAGI,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAczD,yDAAyD;IACzD,gBAAgB,CAAC,UAA0B;QACzC,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAA;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EAAE;QACpC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACzB,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,CAAA;QAE7C,IAAI,IAAI,EAAE,CAAC;YACT,OAAO;gBACL,OAAO,EAAE,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE;gBAC/C,KAAK;gBACL,aAAa,EAAE,IAAI;aACpB,CAAA;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,eAAe;YACxB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,sCAAsC;YAChE,aAAa,EAAE,KAAK;SACrB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -10,6 +10,8 @@ declare const todoSchema: z.ZodObject<{
|
|
|
10
10
|
export declare class TodoController {
|
|
11
11
|
private readonly todoService;
|
|
12
12
|
constructor(todoService: TodoService);
|
|
13
|
+
private tracingService;
|
|
14
|
+
private authManager;
|
|
13
15
|
private logger;
|
|
14
16
|
getAllTodos(): {
|
|
15
17
|
id: string;
|
|
@@ -21,11 +23,11 @@ export declare class TodoController {
|
|
|
21
23
|
text: string;
|
|
22
24
|
completed: boolean;
|
|
23
25
|
};
|
|
24
|
-
createTodo(body: z.infer<typeof todoSchema>): {
|
|
26
|
+
createTodo(body: z.infer<typeof todoSchema>): Promise<{
|
|
25
27
|
id: string;
|
|
26
28
|
text: string;
|
|
27
29
|
completed: boolean;
|
|
28
|
-
}
|
|
30
|
+
}>;
|
|
29
31
|
}
|
|
30
32
|
export {};
|
|
31
33
|
//# sourceMappingURL=todo.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todo.controller.d.ts","sourceRoot":"","sources":["../../../src/examples/controllers/todo.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"todo.controller.d.ts","sourceRoot":"","sources":["../../../src/examples/controllers/todo.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAiBvB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAUtD,QAAA,MAAM,UAAU;;;;;;EAIH,CAAA;AAUb,qBAGa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAGrD,OAAO,CAAC,cAAc,CAAiB;IAGvC,OAAO,CAAC,WAAW,CAAc;IAEjC,OAAO,CAAC,MAAM,CAAS;IAGvB,WAAW;;;;;IAkBX,WAAW,CAAc,EAAE,EAAE,MAAM;;;;;IAqB7B,UAAU,CAAS,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC;;;;;CAc1D"}
|
|
@@ -14,13 +14,15 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TodoController = void 0;
|
|
16
16
|
const zod_1 = require("zod");
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const auth_1 = require("../../auth");
|
|
18
|
+
const decorators_1 = require("../../cache/decorators");
|
|
19
|
+
const decorators_2 = require("../../core/decorators");
|
|
19
20
|
const di_container_1 = require("../../core/di-container");
|
|
20
21
|
const request_context_service_1 = require("../../core/request-context.service");
|
|
21
|
-
const decorators_2 = require("../../cache/decorators");
|
|
22
22
|
const decorators_3 = require("../../logging/core/decorators");
|
|
23
23
|
const logger_1 = require("../../logging/core/logger");
|
|
24
|
+
const tracing_service_1 = require("../../logging/core/tracing.service");
|
|
25
|
+
const todo_service_1 = require("../services/todo.service");
|
|
24
26
|
const createTodoSchema = {
|
|
25
27
|
body: zod_1.z
|
|
26
28
|
.object({
|
|
@@ -42,49 +44,69 @@ let TodoController = class TodoController {
|
|
|
42
44
|
constructor(todoService) {
|
|
43
45
|
this.todoService = todoService;
|
|
44
46
|
}
|
|
45
|
-
// @UseMiddleware(authMiddleware)
|
|
46
47
|
getAllTodos() {
|
|
47
48
|
const context = di_container_1.container.resolve(request_context_service_1.RequestContextService);
|
|
49
|
+
// const span = this.tracingService.spanStart('get.all.todos', {
|
|
50
|
+
// name: 'get all todos',
|
|
51
|
+
// })
|
|
48
52
|
console.log(context.store());
|
|
49
53
|
const logger1 = di_container_1.container.resolve(logger_1.Logger);
|
|
50
54
|
logger1.info('Hello from logger 1 get all todo');
|
|
51
55
|
console.log(this.logger === logger1);
|
|
52
56
|
this.logger.info('Hello from get all todo');
|
|
57
|
+
// this.tracingService.spanEnd(span, 'ok')
|
|
53
58
|
return this.todoService.getAllTodos();
|
|
54
59
|
}
|
|
55
60
|
getTodoById(id) {
|
|
56
61
|
this.logger.info('Hello from get todo by id');
|
|
57
62
|
return this.todoService.getTodoById(id);
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
// @UseMiddleware(authorize(['manager']))
|
|
65
|
+
async createTodo(body) {
|
|
66
|
+
// const span = this.tracingService.spanStart('create.todo.controller', {
|
|
67
|
+
// name: 'create todo controller',
|
|
68
|
+
// hello: 'world',
|
|
69
|
+
// company: 'Jiocinema',
|
|
70
|
+
// })
|
|
71
|
+
// this.tracingService.addTags({
|
|
72
|
+
// text: body.text,
|
|
73
|
+
// })
|
|
60
74
|
this.logger.info('Hello from create todo', body);
|
|
61
|
-
|
|
75
|
+
const data = await this.todoService.createTodo(body.text);
|
|
76
|
+
// this.tracingService.spanEnd(span, 'ok')
|
|
77
|
+
return data;
|
|
62
78
|
}
|
|
63
79
|
};
|
|
64
80
|
exports.TodoController = TodoController;
|
|
65
81
|
__decorate([
|
|
66
|
-
(0,
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
(0, decorators_2.Autowired)(tracing_service_1.TracingService),
|
|
83
|
+
__metadata("design:type", tracing_service_1.TracingService)
|
|
84
|
+
], TodoController.prototype, "tracingService", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, decorators_2.Autowired)('AuthManager'),
|
|
87
|
+
__metadata("design:type", auth_1.AuthManager)
|
|
88
|
+
], TodoController.prototype, "authManager", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, decorators_2.Get)('/'),
|
|
69
91
|
__metadata("design:type", Function),
|
|
70
92
|
__metadata("design:paramtypes", []),
|
|
71
93
|
__metadata("design:returntype", void 0)
|
|
72
94
|
], TodoController.prototype, "getAllTodos", null);
|
|
73
95
|
__decorate([
|
|
74
|
-
(0,
|
|
75
|
-
(0,
|
|
76
|
-
__param(0, (0,
|
|
96
|
+
(0, decorators_2.Get)('/:id'),
|
|
97
|
+
(0, decorators_1.Cacheable)({ key: 'todo', ttl: 60 }),
|
|
98
|
+
__param(0, (0, decorators_2.Param)('id')),
|
|
77
99
|
__metadata("design:type", Function),
|
|
78
100
|
__metadata("design:paramtypes", [String]),
|
|
79
101
|
__metadata("design:returntype", void 0)
|
|
80
102
|
], TodoController.prototype, "getTodoById", null);
|
|
81
103
|
__decorate([
|
|
82
|
-
(0,
|
|
104
|
+
(0, decorators_2.Post)('/'),
|
|
83
105
|
(0, decorators_3.Audit)({
|
|
84
106
|
action: 'create',
|
|
85
107
|
resource: 'todo',
|
|
86
108
|
}),
|
|
87
|
-
(0,
|
|
109
|
+
(0, decorators_2.Schema)({
|
|
88
110
|
body: todoSchema,
|
|
89
111
|
responses: {
|
|
90
112
|
201: zod_1.z.object({
|
|
@@ -93,15 +115,19 @@ __decorate([
|
|
|
93
115
|
completed: zod_1.z.boolean(),
|
|
94
116
|
}),
|
|
95
117
|
},
|
|
96
|
-
})
|
|
97
|
-
|
|
118
|
+
})
|
|
119
|
+
// @UseMiddleware(authorize(['manager']))
|
|
120
|
+
,
|
|
121
|
+
__param(0, (0, decorators_2.Body)()),
|
|
98
122
|
__metadata("design:type", Function),
|
|
99
123
|
__metadata("design:paramtypes", [void 0]),
|
|
100
|
-
__metadata("design:returntype",
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
101
125
|
], TodoController.prototype, "createTodo", null);
|
|
102
126
|
exports.TodoController = TodoController = __decorate([
|
|
103
127
|
(0, decorators_3.Loggable)(),
|
|
104
|
-
(0,
|
|
128
|
+
(0, decorators_2.Controller)('/todos')
|
|
129
|
+
// @UseMiddleware(authenticate(process.env.JWT_SECRET || 'your-secret-key'))
|
|
130
|
+
,
|
|
105
131
|
__metadata("design:paramtypes", [todo_service_1.TodoService])
|
|
106
132
|
], TodoController);
|
|
107
133
|
//# sourceMappingURL=todo.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todo.controller.js","sourceRoot":"","sources":["../../../src/examples/controllers/todo.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6BAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"todo.controller.js","sourceRoot":"","sources":["../../../src/examples/controllers/todo.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6BAAuB;AACvB,qCAAwC;AACxC,uDAAkD;AAClD,sDAQ8B;AAC9B,0DAAmD;AACnD,gFAA0E;AAC1E,8DAA+D;AAC/D,sDAAkD;AAClD,wEAAmE;AACnE,2DAAsD;AAEtD,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,OAAC;SACJ,MAAM,CAAC;QACN,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC;KAChD,CAAC;SACD,QAAQ,EAAE;CACd,CAAA;AAED,MAAM,UAAU,GAAG,OAAC;KACjB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC;CAChD,CAAC;KACD,QAAQ,EAAE,CAAA;AAEb,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;QACf,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KA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;IACb,CAAC;CACF,CAAA;AAjEY,wCAAc;AAIjB;IADP,IAAA,sBAAS,EAAC,gCAAc,CAAC;8BACD,gCAAc;sDAAA;AAG/B;IADP,IAAA,sBAAS,EAAC,aAAa,CAAC;8BACH,kBAAW;mDAAA;AAKjC;IADC,IAAA,gBAAG,EAAC,GAAG,CAAC;;;;iDAeR;AAID;IAFC,IAAA,gBAAG,EAAC,MAAM,CAAC;IACX,IAAA,sBAAS,EAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IACvB,WAAA,IAAA,kBAAK,EAAC,IAAI,CAAC,CAAA;;;;iDAGvB;AAkBK;IAhBL,IAAA,iBAAI,EAAC,GAAG,CAAC;IACT,IAAA,kBAAK,EAAC;QACL,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,MAAM;KACjB,CAAC;IACD,IAAA,mBAAM,EAAC;QACN,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE;YACT,GAAG,EAAE,OAAC,CAAC,MAAM,CAAC;gBACZ,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;gBACd,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;gBAChB,SAAS,EAAE,OAAC,CAAC,OAAO,EAAE;aACvB,CAAC;SACH;KACF,CAAC;IACF,yCAAyC;;IACvB,WAAA,IAAA,iBAAI,GAAE,CAAA;;;;gDAavB;yBAhEU,cAAc;IAH1B,IAAA,qBAAQ,GAAE;IACV,IAAA,uBAAU,EAAC,QAAQ,CAAC;IACrB,4EAA4E;;qCAEhC,0BAAW;GAD1C,cAAc,CAiE1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TodoEventHandler.d.ts","sourceRoot":"","sources":["../../../src/examples/events/TodoEventHandler.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"TodoEventHandler.d.ts","sourceRoot":"","sources":["../../../src/examples/events/TodoEventHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,qBAEa,gBAAgB;IAE3B,MAAM,CAAC,KAAK,EAAE,gBAAgB;CAM/B"}
|
|
@@ -9,23 +9,27 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TodoEventHandler = void 0;
|
|
12
13
|
const decorators_1 = require("../../core/decorators");
|
|
13
14
|
const decorators_2 = require("../../events/decorators");
|
|
14
15
|
const todo_events_1 = require("./todo.events");
|
|
15
16
|
let TodoEventHandler = class TodoEventHandler {
|
|
16
17
|
handle(event) {
|
|
17
|
-
console.log('TodoEventHandler'
|
|
18
|
-
console.log('
|
|
18
|
+
console.log('🎯 TodoEventHandler.handle() called!');
|
|
19
|
+
console.log('📧 Event received:', event);
|
|
20
|
+
console.log('📧 Event type:', event?.type);
|
|
21
|
+
console.log('📧 Event payload:', event?.payload);
|
|
19
22
|
}
|
|
20
23
|
};
|
|
24
|
+
exports.TodoEventHandler = TodoEventHandler;
|
|
21
25
|
__decorate([
|
|
22
26
|
(0, decorators_2.OnEvent)('todo.created'),
|
|
23
27
|
__metadata("design:type", Function),
|
|
24
28
|
__metadata("design:paramtypes", [todo_events_1.TodoCreatedEvent]),
|
|
25
29
|
__metadata("design:returntype", void 0)
|
|
26
30
|
], TodoEventHandler.prototype, "handle", null);
|
|
27
|
-
TodoEventHandler = __decorate([
|
|
28
|
-
(0, decorators_1.Component)(),
|
|
31
|
+
exports.TodoEventHandler = TodoEventHandler = __decorate([
|
|
32
|
+
(0, decorators_1.Component)({ eager: true }),
|
|
29
33
|
(0, decorators_2.EventListener)()
|
|
30
34
|
], TodoEventHandler);
|
|
31
35
|
//# sourceMappingURL=TodoEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TodoEventHandler.js","sourceRoot":"","sources":["../../../src/examples/events/TodoEventHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TodoEventHandler.js","sourceRoot":"","sources":["../../../src/examples/events/TodoEventHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sDAAiD;AACjD,wDAAgE;AAChE,+CAAgD;AAIzC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAE3B,MAAM,CAAC,KAAuB;QAC5B,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAA;QACnD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAA;QACxC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC1C,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IAClD,CAAC;CACF,CAAA;AARY,4CAAgB;AAE3B;IADC,IAAA,oBAAO,EAAC,cAAc,CAAC;;qCACV,8BAAgB;;8CAK7B;2BAPU,gBAAgB;IAF5B,IAAA,sBAAS,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1B,IAAA,0BAAa,GAAE;GACH,gBAAgB,CAQ5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-middleware-example.d.ts","sourceRoot":"","sources":["../../src/examples/global-middleware-example.ts"],"names":[],"mappings":"AA8DA,wBAAsB,6BAA6B,kBAkBlD"}
|