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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../../src/examples/auth/auth.middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../../src/examples/auth/auth.middleware.ts"],"names":[],"mappings":""}
|
|
@@ -1,64 +1 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
declare const loginSchema: z.ZodObject<{
|
|
3
|
-
username: z.ZodString;
|
|
4
|
-
password: z.ZodString;
|
|
5
|
-
}, "strip", z.ZodTypeAny, {
|
|
6
|
-
password: string;
|
|
7
|
-
username: string;
|
|
8
|
-
}, {
|
|
9
|
-
password: string;
|
|
10
|
-
username: string;
|
|
11
|
-
}>;
|
|
12
|
-
declare const refreshTokenSchema: z.ZodObject<{
|
|
13
|
-
refreshToken: z.ZodString;
|
|
14
|
-
}, "strip", z.ZodTypeAny, {
|
|
15
|
-
refreshToken: string;
|
|
16
|
-
}, {
|
|
17
|
-
refreshToken: string;
|
|
18
|
-
}>;
|
|
19
|
-
export declare class AuthController {
|
|
20
|
-
login(body: z.infer<typeof loginSchema>): Promise<{
|
|
21
|
-
accessToken: string;
|
|
22
|
-
refreshToken: string;
|
|
23
|
-
expiresIn: number;
|
|
24
|
-
tokenType: "Bearer" | "API-Key";
|
|
25
|
-
user: {
|
|
26
|
-
id: string;
|
|
27
|
-
username: string | undefined;
|
|
28
|
-
email: string | undefined;
|
|
29
|
-
roles: string[];
|
|
30
|
-
};
|
|
31
|
-
}>;
|
|
32
|
-
refreshToken(body: z.infer<typeof refreshTokenSchema>): Promise<{
|
|
33
|
-
accessToken: string;
|
|
34
|
-
refreshToken: string;
|
|
35
|
-
expiresIn: number;
|
|
36
|
-
tokenType: "Bearer" | "API-Key";
|
|
37
|
-
}>;
|
|
38
|
-
logout(body: z.infer<typeof refreshTokenSchema>): Promise<{
|
|
39
|
-
message: string;
|
|
40
|
-
}>;
|
|
41
|
-
getAuthInfo(): Promise<{
|
|
42
|
-
authenticated: boolean;
|
|
43
|
-
message: string;
|
|
44
|
-
instructions: {
|
|
45
|
-
login: string;
|
|
46
|
-
testCredentials: {
|
|
47
|
-
admin: {
|
|
48
|
-
username: string;
|
|
49
|
-
password: string;
|
|
50
|
-
};
|
|
51
|
-
manager: {
|
|
52
|
-
username: string;
|
|
53
|
-
password: string;
|
|
54
|
-
};
|
|
55
|
-
user: {
|
|
56
|
-
username: string;
|
|
57
|
-
password: string;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
}>;
|
|
62
|
-
}
|
|
63
|
-
export {};
|
|
64
1
|
//# sourceMappingURL=auth.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../../src/examples/controllers/auth.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../../src/examples/controllers/auth.controller.ts"],"names":[],"mappings":""}
|
|
@@ -1,284 +1,249 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
__param(0, (0, decorators_1.Body)()),
|
|
250
|
-
__metadata("design:type", Function),
|
|
251
|
-
__metadata("design:paramtypes", [void 0]),
|
|
252
|
-
__metadata("design:returntype", Promise)
|
|
253
|
-
], AuthController.prototype, "logout", null);
|
|
254
|
-
__decorate([
|
|
255
|
-
(0, decorators_1.Get)('/info'),
|
|
256
|
-
(0, decorators_1.Schema)({
|
|
257
|
-
responses: {
|
|
258
|
-
200: zod_1.z.object({
|
|
259
|
-
authenticated: zod_1.z.boolean(),
|
|
260
|
-
message: zod_1.z.string().optional(),
|
|
261
|
-
instructions: zod_1.z.object({
|
|
262
|
-
login: zod_1.z.string(),
|
|
263
|
-
testCredentials: zod_1.z.record(zod_1.z.object({
|
|
264
|
-
username: zod_1.z.string(),
|
|
265
|
-
password: zod_1.z.string()
|
|
266
|
-
}))
|
|
267
|
-
}).optional(),
|
|
268
|
-
user: zod_1.z.object({
|
|
269
|
-
id: zod_1.z.string(),
|
|
270
|
-
username: zod_1.z.string().optional(),
|
|
271
|
-
email: zod_1.z.string().optional(),
|
|
272
|
-
roles: zod_1.z.array(zod_1.z.string())
|
|
273
|
-
}).optional()
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
}),
|
|
277
|
-
__metadata("design:type", Function),
|
|
278
|
-
__metadata("design:paramtypes", []),
|
|
279
|
-
__metadata("design:returntype", Promise)
|
|
280
|
-
], AuthController.prototype, "getAuthInfo", null);
|
|
281
|
-
exports.AuthController = AuthController = __decorate([
|
|
282
|
-
(0, decorators_1.Controller)('/auth')
|
|
283
|
-
], AuthController);
|
|
2
|
+
// import { z } from 'zod';
|
|
3
|
+
// import { FastifyRequest, FastifyReply } from 'fastify';
|
|
4
|
+
// import {
|
|
5
|
+
// Body,
|
|
6
|
+
// Controller,
|
|
7
|
+
// Get,
|
|
8
|
+
// Post,
|
|
9
|
+
// Schema
|
|
10
|
+
// } from '../../core/decorators';
|
|
11
|
+
// import { AuthManager } from '../../auth/AuthManager';
|
|
12
|
+
// import { JwtStrategy } from '../../auth/strategies/JwtStrategy';
|
|
13
|
+
// import { RedisTokenStorage } from '../../auth/storage/RedisTokenStorage';
|
|
14
|
+
// import { User, AuthContext } from '../../auth/types';
|
|
15
|
+
// const loginSchema = z.object({
|
|
16
|
+
// username: z.string().min(1, 'Username is required'),
|
|
17
|
+
// password: z.string().min(1, 'Password is required')
|
|
18
|
+
// });
|
|
19
|
+
// const refreshTokenSchema = z.object({
|
|
20
|
+
// refreshToken: z.string().min(1, 'Refresh token is required')
|
|
21
|
+
// });
|
|
22
|
+
// // Mock users for testing
|
|
23
|
+
// const MOCK_USERS: User[] = [
|
|
24
|
+
// {
|
|
25
|
+
// id: '1',
|
|
26
|
+
// username: 'admin',
|
|
27
|
+
// email: 'admin@example.com',
|
|
28
|
+
// roles: ['admin', 'manager', 'user'],
|
|
29
|
+
// permissions: ['read', 'write', 'delete', 'admin'],
|
|
30
|
+
// metadata: { password: 'admin123' },
|
|
31
|
+
// createdAt: new Date(),
|
|
32
|
+
// lastLoginAt: new Date()
|
|
33
|
+
// },
|
|
34
|
+
// {
|
|
35
|
+
// id: '2',
|
|
36
|
+
// username: 'manager',
|
|
37
|
+
// email: 'manager@example.com',
|
|
38
|
+
// roles: ['manager', 'user'],
|
|
39
|
+
// permissions: ['read', 'write'],
|
|
40
|
+
// metadata: { password: 'manager123' },
|
|
41
|
+
// createdAt: new Date(),
|
|
42
|
+
// lastLoginAt: new Date()
|
|
43
|
+
// },
|
|
44
|
+
// {
|
|
45
|
+
// id: '3',
|
|
46
|
+
// username: 'user',
|
|
47
|
+
// email: 'user@example.com',
|
|
48
|
+
// roles: ['user'],
|
|
49
|
+
// permissions: ['read'],
|
|
50
|
+
// metadata: { password: 'user123' },
|
|
51
|
+
// createdAt: new Date(),
|
|
52
|
+
// lastLoginAt: new Date()
|
|
53
|
+
// }
|
|
54
|
+
// ];
|
|
55
|
+
// // Mock Redis client for demo
|
|
56
|
+
// const mockRedisClient = {
|
|
57
|
+
// set: async (key: string, value: string, options?: any) => 'OK',
|
|
58
|
+
// get: async (key: string) => null,
|
|
59
|
+
// del: async (key: string) => 1,
|
|
60
|
+
// exists: async (key: string) => 0
|
|
61
|
+
// };
|
|
62
|
+
// // Initialize auth system
|
|
63
|
+
// const tokenStorage = new RedisTokenStorage(mockRedisClient as any);
|
|
64
|
+
// const jwtStrategy = new JwtStrategy();
|
|
65
|
+
// const authManager = new AuthManager({
|
|
66
|
+
// defaultStrategy: 'jwt',
|
|
67
|
+
// tokenStorage
|
|
68
|
+
// });
|
|
69
|
+
// // Initialize auth system
|
|
70
|
+
// let authInitialized = false;
|
|
71
|
+
// async function initializeAuth() {
|
|
72
|
+
// if (!authInitialized) {
|
|
73
|
+
// await authManager.registerStrategy(jwtStrategy, {
|
|
74
|
+
// strategy: 'jwt',
|
|
75
|
+
// options: {
|
|
76
|
+
// secret: process.env.JWT_SECRET || 'your-secret-key',
|
|
77
|
+
// accessTokenExpiry: '15m',
|
|
78
|
+
// refreshTokenExpiry: '7d',
|
|
79
|
+
// issuer: 'bootifyjs-auth',
|
|
80
|
+
// audience: 'bootifyjs-app',
|
|
81
|
+
// isDefault: true
|
|
82
|
+
// }
|
|
83
|
+
// });
|
|
84
|
+
// authInitialized = true;
|
|
85
|
+
// }
|
|
86
|
+
// }
|
|
87
|
+
// @Controller('/auth')
|
|
88
|
+
// export class AuthController {
|
|
89
|
+
// @Post('/login')
|
|
90
|
+
// @Schema({
|
|
91
|
+
// body: loginSchema,
|
|
92
|
+
// responses: {
|
|
93
|
+
// 200: z.object({
|
|
94
|
+
// token: z.string(),
|
|
95
|
+
// user: z.object({
|
|
96
|
+
// id: z.string(),
|
|
97
|
+
// username: z.string(),
|
|
98
|
+
// email: z.string(),
|
|
99
|
+
// roles: z.array(z.string())
|
|
100
|
+
// })
|
|
101
|
+
// }),
|
|
102
|
+
// 401: z.object({
|
|
103
|
+
// error: z.string(),
|
|
104
|
+
// message: z.string()
|
|
105
|
+
// })
|
|
106
|
+
// }
|
|
107
|
+
// })
|
|
108
|
+
// async login(@Body() body: z.infer<typeof loginSchema>) {
|
|
109
|
+
// const { username, password } = body;
|
|
110
|
+
// // Find user
|
|
111
|
+
// const user = MOCK_USERS.find(u => u.username === username && u.metadata?.password === password);
|
|
112
|
+
// if (!user) {
|
|
113
|
+
// throw new Error('Invalid credentials');
|
|
114
|
+
// }
|
|
115
|
+
// // Create auth context
|
|
116
|
+
// const context: AuthContext = {
|
|
117
|
+
// type: 'login',
|
|
118
|
+
// strategy: 'jwt',
|
|
119
|
+
// request: {} as any,
|
|
120
|
+
// headers: {},
|
|
121
|
+
// body: { username, password },
|
|
122
|
+
// query: {}
|
|
123
|
+
// };
|
|
124
|
+
// // Authenticate using auth manager
|
|
125
|
+
// const authResult = await authManager.authenticate(context, 'jwt');
|
|
126
|
+
// if (!authResult.success || !authResult.tokens) {
|
|
127
|
+
// throw new Error('Authentication failed');
|
|
128
|
+
// }
|
|
129
|
+
// // Update last login
|
|
130
|
+
// user.lastLoginAt = new Date();
|
|
131
|
+
// return {
|
|
132
|
+
// accessToken: authResult.tokens.accessToken,
|
|
133
|
+
// refreshToken: authResult.tokens.refreshToken,
|
|
134
|
+
// expiresIn: authResult.tokens.expiresIn,
|
|
135
|
+
// tokenType: authResult.tokens.tokenType,
|
|
136
|
+
// user: {
|
|
137
|
+
// id: user.id,
|
|
138
|
+
// username: user.username,
|
|
139
|
+
// email: user.email,
|
|
140
|
+
// roles: user.roles
|
|
141
|
+
// }
|
|
142
|
+
// };
|
|
143
|
+
// }
|
|
144
|
+
// @Post('/refresh')
|
|
145
|
+
// @Schema({
|
|
146
|
+
// body: refreshTokenSchema,
|
|
147
|
+
// responses: {
|
|
148
|
+
// 200: z.object({
|
|
149
|
+
// accessToken: z.string(),
|
|
150
|
+
// refreshToken: z.string(),
|
|
151
|
+
// expiresIn: z.number(),
|
|
152
|
+
// tokenType: z.string()
|
|
153
|
+
// }),
|
|
154
|
+
// 401: z.object({
|
|
155
|
+
// error: z.string(),
|
|
156
|
+
// message: z.string()
|
|
157
|
+
// })
|
|
158
|
+
// }
|
|
159
|
+
// })
|
|
160
|
+
// async refreshToken(@Body() body: z.infer<typeof refreshTokenSchema>) {
|
|
161
|
+
// const { refreshToken } = body;
|
|
162
|
+
// const context: AuthContext = {
|
|
163
|
+
// type: 'refresh',
|
|
164
|
+
// strategy: 'jwt',
|
|
165
|
+
// request: {} as any,
|
|
166
|
+
// headers: {},
|
|
167
|
+
// body: { refreshToken },
|
|
168
|
+
// query: {}
|
|
169
|
+
// };
|
|
170
|
+
// const refreshResult = await authManager.refresh(refreshToken, context, 'jwt');
|
|
171
|
+
// if (!refreshResult.success || !refreshResult.tokens) {
|
|
172
|
+
// throw new Error('Token refresh failed');
|
|
173
|
+
// }
|
|
174
|
+
// return {
|
|
175
|
+
// accessToken: refreshResult.tokens.accessToken,
|
|
176
|
+
// refreshToken: refreshResult.tokens.refreshToken,
|
|
177
|
+
// expiresIn: refreshResult.tokens.expiresIn,
|
|
178
|
+
// tokenType: refreshResult.tokens.tokenType
|
|
179
|
+
// };
|
|
180
|
+
// }
|
|
181
|
+
// @Post('/logout')
|
|
182
|
+
// @Schema({
|
|
183
|
+
// body: refreshTokenSchema,
|
|
184
|
+
// responses: {
|
|
185
|
+
// 200: z.object({
|
|
186
|
+
// message: z.string()
|
|
187
|
+
// }),
|
|
188
|
+
// 400: z.object({
|
|
189
|
+
// error: z.string(),
|
|
190
|
+
// message: z.string()
|
|
191
|
+
// })
|
|
192
|
+
// }
|
|
193
|
+
// })
|
|
194
|
+
// async logout(@Body() body: z.infer<typeof refreshTokenSchema>) {
|
|
195
|
+
// const { refreshToken } = body;
|
|
196
|
+
// const context: AuthContext = {
|
|
197
|
+
// type: 'revoke',
|
|
198
|
+
// strategy: 'jwt',
|
|
199
|
+
// request: {} as any,
|
|
200
|
+
// headers: {},
|
|
201
|
+
// body: { refreshToken },
|
|
202
|
+
// query: {}
|
|
203
|
+
// };
|
|
204
|
+
// const revokeResult = await authManager.revoke(refreshToken, context, 'jwt');
|
|
205
|
+
// if (!revokeResult) {
|
|
206
|
+
// throw new Error('Logout failed');
|
|
207
|
+
// }
|
|
208
|
+
// return {
|
|
209
|
+
// message: 'Successfully logged out'
|
|
210
|
+
// };
|
|
211
|
+
// }
|
|
212
|
+
// @Get('/info')
|
|
213
|
+
// @Schema({
|
|
214
|
+
// responses: {
|
|
215
|
+
// 200: z.object({
|
|
216
|
+
// authenticated: z.boolean(),
|
|
217
|
+
// message: z.string().optional(),
|
|
218
|
+
// instructions: z.object({
|
|
219
|
+
// login: z.string(),
|
|
220
|
+
// testCredentials: z.record(z.object({
|
|
221
|
+
// username: z.string(),
|
|
222
|
+
// password: z.string()
|
|
223
|
+
// }))
|
|
224
|
+
// }).optional(),
|
|
225
|
+
// user: z.object({
|
|
226
|
+
// id: z.string(),
|
|
227
|
+
// username: z.string().optional(),
|
|
228
|
+
// email: z.string().optional(),
|
|
229
|
+
// roles: z.array(z.string())
|
|
230
|
+
// }).optional()
|
|
231
|
+
// })
|
|
232
|
+
// }
|
|
233
|
+
// })
|
|
234
|
+
// async getAuthInfo() {
|
|
235
|
+
// return {
|
|
236
|
+
// authenticated: false,
|
|
237
|
+
// message: 'Authentication info endpoint - use middleware to get authenticated user data',
|
|
238
|
+
// instructions: {
|
|
239
|
+
// login: 'POST /auth/login with username and password',
|
|
240
|
+
// testCredentials: {
|
|
241
|
+
// admin: { username: 'admin', password: 'admin123' },
|
|
242
|
+
// manager: { username: 'manager', password: 'manager123' },
|
|
243
|
+
// user: { username: 'user', password: 'user123' }
|
|
244
|
+
// }
|
|
245
|
+
// }
|
|
246
|
+
// };
|
|
247
|
+
// }
|
|
248
|
+
// }
|
|
284
249
|
//# sourceMappingURL=auth.controller.js.map
|