servcraft 0.1.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/.dockerignore +45 -0
- package/.env.example +46 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc +11 -0
- package/Dockerfile +76 -0
- package/Dockerfile.dev +31 -0
- package/README.md +232 -0
- package/commitlint.config.js +24 -0
- package/dist/cli/index.cjs +3968 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +3945 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +2458 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +828 -0
- package/dist/index.d.ts +828 -0
- package/dist/index.js +2332 -0
- package/dist/index.js.map +1 -0
- package/docker-compose.prod.yml +118 -0
- package/docker-compose.yml +147 -0
- package/eslint.config.js +27 -0
- package/npm-cache/_cacache/content-v2/sha512/1c/d0/03440d500a0487621aad1d6402978340698976602046db8e24fa03c01ee6c022c69b0582f969042d9442ee876ac35c038e960dd427d1e622fa24b8eb7dba +0 -0
- package/npm-cache/_cacache/content-v2/sha512/42/55/28b493ca491833e5aab0e9c3108d29ab3f36c248ca88f45d4630674fce9130959e56ae308797ac2b6328fa7f09a610b9550ed09cb971d039876d293fc69d +0 -0
- package/npm-cache/_cacache/content-v2/sha512/e0/12/f360dc9315ee5f17844a0c8c233ee6bf7c30837c4a02ea0d56c61c7f7ab21c0e958e50ed2c57c59f983c762b93056778c9009b2398ffc26def0183999b13 +0 -0
- package/npm-cache/_cacache/content-v2/sha512/ed/b0/fae1161902898f4c913c67d7f6cdf6be0665aec3b389b9c4f4f0a101ca1da59badf1b59c4e0030f5223023b8d63cfe501c46a32c20c895d4fb3f11ca2232 +0 -0
- package/npm-cache/_cacache/index-v5/58/94/c2cba79e0f16b4c10e95a87e32255741149e8222cc314a476aab67c39cc0 +5 -0
- package/npm-cache/_update-notifier-last-checked +0 -0
- package/package.json +112 -0
- package/prisma/schema.prisma +157 -0
- package/src/cli/commands/add-module.ts +422 -0
- package/src/cli/commands/db.ts +137 -0
- package/src/cli/commands/docs.ts +16 -0
- package/src/cli/commands/generate.ts +459 -0
- package/src/cli/commands/init.ts +640 -0
- package/src/cli/index.ts +32 -0
- package/src/cli/templates/controller.ts +67 -0
- package/src/cli/templates/dynamic-prisma.ts +89 -0
- package/src/cli/templates/dynamic-schemas.ts +232 -0
- package/src/cli/templates/dynamic-types.ts +60 -0
- package/src/cli/templates/module-index.ts +33 -0
- package/src/cli/templates/prisma-model.ts +17 -0
- package/src/cli/templates/repository.ts +104 -0
- package/src/cli/templates/routes.ts +70 -0
- package/src/cli/templates/schemas.ts +26 -0
- package/src/cli/templates/service.ts +58 -0
- package/src/cli/templates/types.ts +27 -0
- package/src/cli/utils/docs-generator.ts +47 -0
- package/src/cli/utils/field-parser.ts +315 -0
- package/src/cli/utils/helpers.ts +89 -0
- package/src/config/env.ts +80 -0
- package/src/config/index.ts +97 -0
- package/src/core/index.ts +5 -0
- package/src/core/logger.ts +43 -0
- package/src/core/server.ts +132 -0
- package/src/database/index.ts +7 -0
- package/src/database/prisma.ts +54 -0
- package/src/database/seed.ts +59 -0
- package/src/index.ts +63 -0
- package/src/middleware/error-handler.ts +73 -0
- package/src/middleware/index.ts +3 -0
- package/src/middleware/security.ts +116 -0
- package/src/modules/audit/audit.service.ts +192 -0
- package/src/modules/audit/index.ts +2 -0
- package/src/modules/audit/types.ts +37 -0
- package/src/modules/auth/auth.controller.ts +182 -0
- package/src/modules/auth/auth.middleware.ts +87 -0
- package/src/modules/auth/auth.routes.ts +123 -0
- package/src/modules/auth/auth.service.ts +142 -0
- package/src/modules/auth/index.ts +49 -0
- package/src/modules/auth/schemas.ts +52 -0
- package/src/modules/auth/types.ts +69 -0
- package/src/modules/email/email.service.ts +212 -0
- package/src/modules/email/index.ts +10 -0
- package/src/modules/email/templates.ts +213 -0
- package/src/modules/email/types.ts +57 -0
- package/src/modules/swagger/index.ts +3 -0
- package/src/modules/swagger/schema-builder.ts +263 -0
- package/src/modules/swagger/swagger.service.ts +169 -0
- package/src/modules/swagger/types.ts +68 -0
- package/src/modules/user/index.ts +30 -0
- package/src/modules/user/schemas.ts +49 -0
- package/src/modules/user/types.ts +78 -0
- package/src/modules/user/user.controller.ts +139 -0
- package/src/modules/user/user.repository.ts +156 -0
- package/src/modules/user/user.routes.ts +199 -0
- package/src/modules/user/user.service.ts +145 -0
- package/src/modules/validation/index.ts +18 -0
- package/src/modules/validation/validator.ts +104 -0
- package/src/types/common.ts +61 -0
- package/src/types/index.ts +10 -0
- package/src/utils/errors.ts +66 -0
- package/src/utils/index.ts +33 -0
- package/src/utils/pagination.ts +38 -0
- package/src/utils/response.ts +63 -0
- package/tests/integration/auth.test.ts +59 -0
- package/tests/setup.ts +17 -0
- package/tests/unit/modules/validation.test.ts +88 -0
- package/tests/unit/utils/errors.test.ts +113 -0
- package/tests/unit/utils/pagination.test.ts +82 -0
- package/tsconfig.json +33 -0
- package/tsup.config.ts +14 -0
- package/vitest.config.ts +34 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import pino, { Logger } from 'pino';
|
|
3
|
+
export { Logger } from 'pino';
|
|
4
|
+
import { z, ZodTypeAny } from 'zod';
|
|
5
|
+
|
|
6
|
+
interface LoggerConfig {
|
|
7
|
+
level: string;
|
|
8
|
+
pretty: boolean;
|
|
9
|
+
name?: string;
|
|
10
|
+
}
|
|
11
|
+
declare function createLogger(config?: Partial<LoggerConfig>): Logger;
|
|
12
|
+
declare const logger: pino.Logger;
|
|
13
|
+
|
|
14
|
+
interface ServerConfig {
|
|
15
|
+
port: number;
|
|
16
|
+
host: string;
|
|
17
|
+
logger?: Logger;
|
|
18
|
+
trustProxy?: boolean;
|
|
19
|
+
bodyLimit?: number;
|
|
20
|
+
requestTimeout?: number;
|
|
21
|
+
}
|
|
22
|
+
declare class Server {
|
|
23
|
+
private app;
|
|
24
|
+
private config;
|
|
25
|
+
private logger;
|
|
26
|
+
private isShuttingDown;
|
|
27
|
+
constructor(config?: Partial<ServerConfig>);
|
|
28
|
+
get instance(): FastifyInstance;
|
|
29
|
+
private setupHealthCheck;
|
|
30
|
+
private setupGracefulShutdown;
|
|
31
|
+
shutdown(exitCode?: number): Promise<void>;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
declare function createServer(config?: Partial<ServerConfig>): Server;
|
|
35
|
+
|
|
36
|
+
declare const envSchema: z.ZodObject<{
|
|
37
|
+
NODE_ENV: z.ZodDefault<z.ZodEnum<["development", "staging", "production", "test"]>>;
|
|
38
|
+
PORT: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
|
|
39
|
+
HOST: z.ZodDefault<z.ZodString>;
|
|
40
|
+
DATABASE_URL: z.ZodOptional<z.ZodString>;
|
|
41
|
+
JWT_SECRET: z.ZodOptional<z.ZodString>;
|
|
42
|
+
JWT_ACCESS_EXPIRES_IN: z.ZodDefault<z.ZodString>;
|
|
43
|
+
JWT_REFRESH_EXPIRES_IN: z.ZodDefault<z.ZodString>;
|
|
44
|
+
CORS_ORIGIN: z.ZodDefault<z.ZodString>;
|
|
45
|
+
RATE_LIMIT_MAX: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
|
|
46
|
+
RATE_LIMIT_WINDOW_MS: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
|
|
47
|
+
SMTP_HOST: z.ZodOptional<z.ZodString>;
|
|
48
|
+
SMTP_PORT: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
49
|
+
SMTP_USER: z.ZodOptional<z.ZodString>;
|
|
50
|
+
SMTP_PASS: z.ZodOptional<z.ZodString>;
|
|
51
|
+
SMTP_FROM: z.ZodOptional<z.ZodString>;
|
|
52
|
+
REDIS_URL: z.ZodOptional<z.ZodString>;
|
|
53
|
+
SWAGGER_ENABLED: z.ZodEffects<z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"true">, z.ZodLiteral<"false">]>>, boolean, "true" | "false" | undefined>;
|
|
54
|
+
SWAGGER_ROUTE: z.ZodDefault<z.ZodString>;
|
|
55
|
+
SWAGGER_TITLE: z.ZodDefault<z.ZodString>;
|
|
56
|
+
SWAGGER_DESCRIPTION: z.ZodDefault<z.ZodString>;
|
|
57
|
+
SWAGGER_VERSION: z.ZodDefault<z.ZodString>;
|
|
58
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<["fatal", "error", "warn", "info", "debug", "trace"]>>;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
NODE_ENV: "development" | "staging" | "production" | "test";
|
|
61
|
+
PORT: number;
|
|
62
|
+
HOST: string;
|
|
63
|
+
JWT_ACCESS_EXPIRES_IN: string;
|
|
64
|
+
JWT_REFRESH_EXPIRES_IN: string;
|
|
65
|
+
CORS_ORIGIN: string;
|
|
66
|
+
RATE_LIMIT_MAX: number;
|
|
67
|
+
RATE_LIMIT_WINDOW_MS: number;
|
|
68
|
+
SWAGGER_ENABLED: boolean;
|
|
69
|
+
SWAGGER_ROUTE: string;
|
|
70
|
+
SWAGGER_TITLE: string;
|
|
71
|
+
SWAGGER_DESCRIPTION: string;
|
|
72
|
+
SWAGGER_VERSION: string;
|
|
73
|
+
LOG_LEVEL: "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
|
74
|
+
DATABASE_URL?: string | undefined;
|
|
75
|
+
JWT_SECRET?: string | undefined;
|
|
76
|
+
SMTP_HOST?: string | undefined;
|
|
77
|
+
SMTP_PORT?: number | undefined;
|
|
78
|
+
SMTP_USER?: string | undefined;
|
|
79
|
+
SMTP_PASS?: string | undefined;
|
|
80
|
+
SMTP_FROM?: string | undefined;
|
|
81
|
+
REDIS_URL?: string | undefined;
|
|
82
|
+
}, {
|
|
83
|
+
NODE_ENV?: "development" | "staging" | "production" | "test" | undefined;
|
|
84
|
+
PORT?: string | undefined;
|
|
85
|
+
HOST?: string | undefined;
|
|
86
|
+
DATABASE_URL?: string | undefined;
|
|
87
|
+
JWT_SECRET?: string | undefined;
|
|
88
|
+
JWT_ACCESS_EXPIRES_IN?: string | undefined;
|
|
89
|
+
JWT_REFRESH_EXPIRES_IN?: string | undefined;
|
|
90
|
+
CORS_ORIGIN?: string | undefined;
|
|
91
|
+
RATE_LIMIT_MAX?: string | undefined;
|
|
92
|
+
RATE_LIMIT_WINDOW_MS?: string | undefined;
|
|
93
|
+
SMTP_HOST?: string | undefined;
|
|
94
|
+
SMTP_PORT?: string | undefined;
|
|
95
|
+
SMTP_USER?: string | undefined;
|
|
96
|
+
SMTP_PASS?: string | undefined;
|
|
97
|
+
SMTP_FROM?: string | undefined;
|
|
98
|
+
REDIS_URL?: string | undefined;
|
|
99
|
+
SWAGGER_ENABLED?: "true" | "false" | undefined;
|
|
100
|
+
SWAGGER_ROUTE?: string | undefined;
|
|
101
|
+
SWAGGER_TITLE?: string | undefined;
|
|
102
|
+
SWAGGER_DESCRIPTION?: string | undefined;
|
|
103
|
+
SWAGGER_VERSION?: string | undefined;
|
|
104
|
+
LOG_LEVEL?: "fatal" | "error" | "warn" | "info" | "debug" | "trace" | undefined;
|
|
105
|
+
}>;
|
|
106
|
+
type Env = z.infer<typeof envSchema>;
|
|
107
|
+
declare const env: {
|
|
108
|
+
NODE_ENV: "development" | "staging" | "production" | "test";
|
|
109
|
+
PORT: number;
|
|
110
|
+
HOST: string;
|
|
111
|
+
JWT_ACCESS_EXPIRES_IN: string;
|
|
112
|
+
JWT_REFRESH_EXPIRES_IN: string;
|
|
113
|
+
CORS_ORIGIN: string;
|
|
114
|
+
RATE_LIMIT_MAX: number;
|
|
115
|
+
RATE_LIMIT_WINDOW_MS: number;
|
|
116
|
+
SWAGGER_ENABLED: boolean;
|
|
117
|
+
SWAGGER_ROUTE: string;
|
|
118
|
+
SWAGGER_TITLE: string;
|
|
119
|
+
SWAGGER_DESCRIPTION: string;
|
|
120
|
+
SWAGGER_VERSION: string;
|
|
121
|
+
LOG_LEVEL: "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
|
122
|
+
DATABASE_URL?: string | undefined;
|
|
123
|
+
JWT_SECRET?: string | undefined;
|
|
124
|
+
SMTP_HOST?: string | undefined;
|
|
125
|
+
SMTP_PORT?: number | undefined;
|
|
126
|
+
SMTP_USER?: string | undefined;
|
|
127
|
+
SMTP_PASS?: string | undefined;
|
|
128
|
+
SMTP_FROM?: string | undefined;
|
|
129
|
+
REDIS_URL?: string | undefined;
|
|
130
|
+
};
|
|
131
|
+
declare function isDevelopment(): boolean;
|
|
132
|
+
declare function isProduction(): boolean;
|
|
133
|
+
declare function isTest(): boolean;
|
|
134
|
+
declare function isStaging(): boolean;
|
|
135
|
+
|
|
136
|
+
interface AppConfig {
|
|
137
|
+
env: Env;
|
|
138
|
+
server: {
|
|
139
|
+
port: number;
|
|
140
|
+
host: string;
|
|
141
|
+
};
|
|
142
|
+
jwt: {
|
|
143
|
+
secret: string;
|
|
144
|
+
accessExpiresIn: string;
|
|
145
|
+
refreshExpiresIn: string;
|
|
146
|
+
};
|
|
147
|
+
security: {
|
|
148
|
+
corsOrigin: string | string[];
|
|
149
|
+
rateLimit: {
|
|
150
|
+
max: number;
|
|
151
|
+
windowMs: number;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
email: {
|
|
155
|
+
host?: string;
|
|
156
|
+
port?: number;
|
|
157
|
+
user?: string;
|
|
158
|
+
pass?: string;
|
|
159
|
+
from?: string;
|
|
160
|
+
};
|
|
161
|
+
database: {
|
|
162
|
+
url?: string;
|
|
163
|
+
};
|
|
164
|
+
redis: {
|
|
165
|
+
url?: string;
|
|
166
|
+
};
|
|
167
|
+
swagger: {
|
|
168
|
+
enabled: boolean;
|
|
169
|
+
route: string;
|
|
170
|
+
title: string;
|
|
171
|
+
description: string;
|
|
172
|
+
version: string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
declare function createConfig(): AppConfig;
|
|
176
|
+
declare const config: AppConfig;
|
|
177
|
+
|
|
178
|
+
declare function registerErrorHandler(app: FastifyInstance): void;
|
|
179
|
+
|
|
180
|
+
interface SecurityOptions {
|
|
181
|
+
helmet?: boolean;
|
|
182
|
+
cors?: boolean;
|
|
183
|
+
rateLimit?: boolean;
|
|
184
|
+
}
|
|
185
|
+
declare function registerSecurity(app: FastifyInstance, options?: SecurityOptions): Promise<void>;
|
|
186
|
+
declare function registerBruteForceProtection(app: FastifyInstance, routePrefix: string, options?: {
|
|
187
|
+
max?: number;
|
|
188
|
+
timeWindow?: number;
|
|
189
|
+
}): Promise<void>;
|
|
190
|
+
|
|
191
|
+
declare function success<T>(reply: FastifyReply, data: T, statusCode?: number): FastifyReply;
|
|
192
|
+
declare function created<T>(reply: FastifyReply, data: T): FastifyReply;
|
|
193
|
+
declare function noContent(reply: FastifyReply): FastifyReply;
|
|
194
|
+
declare function error(reply: FastifyReply, message: string, statusCode?: number, errors?: Record<string, string[]>): FastifyReply;
|
|
195
|
+
declare function notFound(reply: FastifyReply, message?: string): FastifyReply;
|
|
196
|
+
declare function unauthorized(reply: FastifyReply, message?: string): FastifyReply;
|
|
197
|
+
declare function forbidden(reply: FastifyReply, message?: string): FastifyReply;
|
|
198
|
+
declare function badRequest(reply: FastifyReply, message?: string, errors?: Record<string, string[]>): FastifyReply;
|
|
199
|
+
declare function conflict(reply: FastifyReply, message?: string): FastifyReply;
|
|
200
|
+
declare function internalError(reply: FastifyReply, message?: string): FastifyReply;
|
|
201
|
+
|
|
202
|
+
interface BaseEntity {
|
|
203
|
+
id: string;
|
|
204
|
+
createdAt: Date;
|
|
205
|
+
updatedAt: Date;
|
|
206
|
+
}
|
|
207
|
+
interface PaginationParams {
|
|
208
|
+
page: number;
|
|
209
|
+
limit: number;
|
|
210
|
+
sortBy?: string;
|
|
211
|
+
sortOrder?: 'asc' | 'desc';
|
|
212
|
+
}
|
|
213
|
+
interface PaginatedResult<T> {
|
|
214
|
+
data: T[];
|
|
215
|
+
meta: {
|
|
216
|
+
total: number;
|
|
217
|
+
page: number;
|
|
218
|
+
limit: number;
|
|
219
|
+
totalPages: number;
|
|
220
|
+
hasNextPage: boolean;
|
|
221
|
+
hasPrevPage: boolean;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
interface ApiResponse<T = unknown> {
|
|
225
|
+
success: boolean;
|
|
226
|
+
data?: T;
|
|
227
|
+
message?: string;
|
|
228
|
+
errors?: Record<string, string[]>;
|
|
229
|
+
}
|
|
230
|
+
type ServiceResult<T, E = Error> = {
|
|
231
|
+
success: true;
|
|
232
|
+
data: T;
|
|
233
|
+
} | {
|
|
234
|
+
success: false;
|
|
235
|
+
error: E;
|
|
236
|
+
message: string;
|
|
237
|
+
};
|
|
238
|
+
interface Repository<T extends BaseEntity> {
|
|
239
|
+
findById(id: string): Promise<T | null>;
|
|
240
|
+
findMany(params?: PaginationParams): Promise<PaginatedResult<T>>;
|
|
241
|
+
create(data: Omit<T, keyof BaseEntity>): Promise<T>;
|
|
242
|
+
update(id: string, data: Partial<Omit<T, keyof BaseEntity>>): Promise<T | null>;
|
|
243
|
+
delete(id: string): Promise<boolean>;
|
|
244
|
+
}
|
|
245
|
+
type ControllerHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
246
|
+
interface Module {
|
|
247
|
+
name: string;
|
|
248
|
+
register(app: FastifyInstance): Promise<void>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
declare const DEFAULT_PAGE = 1;
|
|
252
|
+
declare const DEFAULT_LIMIT = 20;
|
|
253
|
+
declare const MAX_LIMIT = 100;
|
|
254
|
+
declare function parsePaginationParams(query: Record<string, unknown>): PaginationParams;
|
|
255
|
+
declare function createPaginatedResult<T>(data: T[], total: number, params: PaginationParams): PaginatedResult<T>;
|
|
256
|
+
declare function getSkip(params: PaginationParams): number;
|
|
257
|
+
|
|
258
|
+
declare class AppError extends Error {
|
|
259
|
+
readonly statusCode: number;
|
|
260
|
+
readonly isOperational: boolean;
|
|
261
|
+
readonly errors?: Record<string, string[]>;
|
|
262
|
+
constructor(message: string, statusCode?: number, isOperational?: boolean, errors?: Record<string, string[]>);
|
|
263
|
+
}
|
|
264
|
+
declare class NotFoundError extends AppError {
|
|
265
|
+
constructor(resource?: string);
|
|
266
|
+
}
|
|
267
|
+
declare class UnauthorizedError extends AppError {
|
|
268
|
+
constructor(message?: string);
|
|
269
|
+
}
|
|
270
|
+
declare class ForbiddenError extends AppError {
|
|
271
|
+
constructor(message?: string);
|
|
272
|
+
}
|
|
273
|
+
declare class BadRequestError extends AppError {
|
|
274
|
+
constructor(message?: string, errors?: Record<string, string[]>);
|
|
275
|
+
}
|
|
276
|
+
declare class ConflictError extends AppError {
|
|
277
|
+
constructor(message?: string);
|
|
278
|
+
}
|
|
279
|
+
declare class ValidationError extends AppError {
|
|
280
|
+
constructor(errors: Record<string, string[]>);
|
|
281
|
+
}
|
|
282
|
+
declare class TooManyRequestsError extends AppError {
|
|
283
|
+
constructor(message?: string);
|
|
284
|
+
}
|
|
285
|
+
declare function isAppError(error: unknown): error is AppError;
|
|
286
|
+
|
|
287
|
+
interface JwtPayload {
|
|
288
|
+
sub: string;
|
|
289
|
+
email: string;
|
|
290
|
+
role: string;
|
|
291
|
+
type: 'access' | 'refresh';
|
|
292
|
+
iat?: number;
|
|
293
|
+
exp?: number;
|
|
294
|
+
}
|
|
295
|
+
interface TokenPair {
|
|
296
|
+
accessToken: string;
|
|
297
|
+
refreshToken: string;
|
|
298
|
+
expiresIn: number;
|
|
299
|
+
}
|
|
300
|
+
interface AuthUser {
|
|
301
|
+
id: string;
|
|
302
|
+
email: string;
|
|
303
|
+
role: string;
|
|
304
|
+
}
|
|
305
|
+
interface AuthenticatedRequest extends FastifyRequest {
|
|
306
|
+
user: AuthUser;
|
|
307
|
+
}
|
|
308
|
+
interface LoginCredentials {
|
|
309
|
+
email: string;
|
|
310
|
+
password: string;
|
|
311
|
+
}
|
|
312
|
+
interface RegisterData {
|
|
313
|
+
email: string;
|
|
314
|
+
password: string;
|
|
315
|
+
name?: string;
|
|
316
|
+
}
|
|
317
|
+
interface RefreshTokenData {
|
|
318
|
+
refreshToken: string;
|
|
319
|
+
}
|
|
320
|
+
interface PasswordResetRequest {
|
|
321
|
+
email: string;
|
|
322
|
+
}
|
|
323
|
+
interface PasswordResetConfirm {
|
|
324
|
+
token: string;
|
|
325
|
+
password: string;
|
|
326
|
+
}
|
|
327
|
+
interface ChangePasswordData {
|
|
328
|
+
currentPassword: string;
|
|
329
|
+
newPassword: string;
|
|
330
|
+
}
|
|
331
|
+
declare module 'fastify' {
|
|
332
|
+
interface FastifyRequest {
|
|
333
|
+
user: AuthUser;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
declare module '@fastify/jwt' {
|
|
337
|
+
interface FastifyJWT {
|
|
338
|
+
payload: JwtPayload;
|
|
339
|
+
user: AuthUser;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
declare class AuthService {
|
|
344
|
+
private app;
|
|
345
|
+
private readonly SALT_ROUNDS;
|
|
346
|
+
constructor(app: FastifyInstance);
|
|
347
|
+
hashPassword(password: string): Promise<string>;
|
|
348
|
+
verifyPassword(password: string, hash: string): Promise<boolean>;
|
|
349
|
+
generateTokenPair(user: AuthUser): TokenPair;
|
|
350
|
+
private parseExpiration;
|
|
351
|
+
verifyAccessToken(token: string): Promise<JwtPayload>;
|
|
352
|
+
verifyRefreshToken(token: string): Promise<JwtPayload>;
|
|
353
|
+
blacklistToken(token: string): void;
|
|
354
|
+
isTokenBlacklisted(token: string): boolean;
|
|
355
|
+
cleanupBlacklist(): void;
|
|
356
|
+
}
|
|
357
|
+
declare function createAuthService(app: FastifyInstance): AuthService;
|
|
358
|
+
|
|
359
|
+
type UserStatus = 'active' | 'inactive' | 'suspended' | 'banned';
|
|
360
|
+
type UserRole = 'user' | 'admin' | 'moderator' | 'super_admin';
|
|
361
|
+
interface User extends BaseEntity {
|
|
362
|
+
email: string;
|
|
363
|
+
password: string;
|
|
364
|
+
name?: string;
|
|
365
|
+
role: UserRole;
|
|
366
|
+
status: UserStatus;
|
|
367
|
+
emailVerified: boolean;
|
|
368
|
+
lastLoginAt?: Date;
|
|
369
|
+
metadata?: Record<string, unknown>;
|
|
370
|
+
}
|
|
371
|
+
interface CreateUserData {
|
|
372
|
+
email: string;
|
|
373
|
+
password: string;
|
|
374
|
+
name?: string;
|
|
375
|
+
role?: UserRole;
|
|
376
|
+
}
|
|
377
|
+
interface UpdateUserData {
|
|
378
|
+
email?: string;
|
|
379
|
+
name?: string;
|
|
380
|
+
role?: UserRole;
|
|
381
|
+
status?: UserStatus;
|
|
382
|
+
emailVerified?: boolean;
|
|
383
|
+
metadata?: Record<string, unknown>;
|
|
384
|
+
}
|
|
385
|
+
interface UserFilters {
|
|
386
|
+
status?: UserStatus;
|
|
387
|
+
role?: UserRole;
|
|
388
|
+
search?: string;
|
|
389
|
+
emailVerified?: boolean;
|
|
390
|
+
}
|
|
391
|
+
interface Permission {
|
|
392
|
+
id: string;
|
|
393
|
+
name: string;
|
|
394
|
+
description?: string;
|
|
395
|
+
resource: string;
|
|
396
|
+
action: 'create' | 'read' | 'update' | 'delete' | 'manage';
|
|
397
|
+
}
|
|
398
|
+
interface Role {
|
|
399
|
+
id: string;
|
|
400
|
+
name: UserRole;
|
|
401
|
+
description?: string;
|
|
402
|
+
permissions: Permission[];
|
|
403
|
+
}
|
|
404
|
+
declare const DEFAULT_ROLE_PERMISSIONS: Record<UserRole, string[]>;
|
|
405
|
+
|
|
406
|
+
declare class UserRepository {
|
|
407
|
+
findById(id: string): Promise<User | null>;
|
|
408
|
+
findByEmail(email: string): Promise<User | null>;
|
|
409
|
+
findMany(params: PaginationParams, filters?: UserFilters): Promise<PaginatedResult<User>>;
|
|
410
|
+
create(data: CreateUserData): Promise<User>;
|
|
411
|
+
update(id: string, data: UpdateUserData): Promise<User | null>;
|
|
412
|
+
updatePassword(id: string, password: string): Promise<User | null>;
|
|
413
|
+
updateLastLogin(id: string): Promise<User | null>;
|
|
414
|
+
delete(id: string): Promise<boolean>;
|
|
415
|
+
count(filters?: UserFilters): Promise<number>;
|
|
416
|
+
clear(): Promise<void>;
|
|
417
|
+
}
|
|
418
|
+
declare function createUserRepository(): UserRepository;
|
|
419
|
+
|
|
420
|
+
declare class UserService {
|
|
421
|
+
private repository;
|
|
422
|
+
constructor(repository: UserRepository);
|
|
423
|
+
findById(id: string): Promise<User | null>;
|
|
424
|
+
findByEmail(email: string): Promise<User | null>;
|
|
425
|
+
findMany(params: PaginationParams, filters?: UserFilters): Promise<PaginatedResult<Omit<User, 'password'>>>;
|
|
426
|
+
create(data: CreateUserData): Promise<User>;
|
|
427
|
+
update(id: string, data: UpdateUserData): Promise<User>;
|
|
428
|
+
updatePassword(id: string, hashedPassword: string): Promise<User>;
|
|
429
|
+
updateLastLogin(id: string): Promise<User>;
|
|
430
|
+
delete(id: string): Promise<void>;
|
|
431
|
+
suspend(id: string): Promise<User>;
|
|
432
|
+
ban(id: string): Promise<User>;
|
|
433
|
+
activate(id: string): Promise<User>;
|
|
434
|
+
verifyEmail(id: string): Promise<User>;
|
|
435
|
+
changeRole(id: string, role: UserRole): Promise<User>;
|
|
436
|
+
hasPermission(role: UserRole, permission: string): boolean;
|
|
437
|
+
getPermissions(role: UserRole): string[];
|
|
438
|
+
}
|
|
439
|
+
declare function createUserService(repository?: UserRepository): UserService;
|
|
440
|
+
|
|
441
|
+
declare class AuthController {
|
|
442
|
+
private authService;
|
|
443
|
+
private userService;
|
|
444
|
+
constructor(authService: AuthService, userService: UserService);
|
|
445
|
+
register(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
446
|
+
login(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
447
|
+
refresh(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
448
|
+
logout(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
449
|
+
me(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
450
|
+
changePassword(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
451
|
+
}
|
|
452
|
+
declare function createAuthController(authService: AuthService, userService: UserService): AuthController;
|
|
453
|
+
|
|
454
|
+
declare function createAuthMiddleware(authService: AuthService): (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
455
|
+
declare function createRoleMiddleware(allowedRoles: string[]): (request: FastifyRequest, _reply: FastifyReply) => Promise<void>;
|
|
456
|
+
declare function createPermissionMiddleware(requiredPermissions: string[]): (request: FastifyRequest, _reply: FastifyReply) => Promise<void>;
|
|
457
|
+
declare function createOptionalAuthMiddleware(authService: AuthService): (request: FastifyRequest, _reply: FastifyReply) => Promise<void>;
|
|
458
|
+
|
|
459
|
+
declare const loginSchema: z.ZodObject<{
|
|
460
|
+
email: z.ZodString;
|
|
461
|
+
password: z.ZodString;
|
|
462
|
+
}, "strip", z.ZodTypeAny, {
|
|
463
|
+
email: string;
|
|
464
|
+
password: string;
|
|
465
|
+
}, {
|
|
466
|
+
email: string;
|
|
467
|
+
password: string;
|
|
468
|
+
}>;
|
|
469
|
+
declare const registerSchema: z.ZodObject<{
|
|
470
|
+
email: z.ZodString;
|
|
471
|
+
password: z.ZodString;
|
|
472
|
+
name: z.ZodOptional<z.ZodString>;
|
|
473
|
+
}, "strip", z.ZodTypeAny, {
|
|
474
|
+
email: string;
|
|
475
|
+
password: string;
|
|
476
|
+
name?: string | undefined;
|
|
477
|
+
}, {
|
|
478
|
+
email: string;
|
|
479
|
+
password: string;
|
|
480
|
+
name?: string | undefined;
|
|
481
|
+
}>;
|
|
482
|
+
declare const refreshTokenSchema: z.ZodObject<{
|
|
483
|
+
refreshToken: z.ZodString;
|
|
484
|
+
}, "strip", z.ZodTypeAny, {
|
|
485
|
+
refreshToken: string;
|
|
486
|
+
}, {
|
|
487
|
+
refreshToken: string;
|
|
488
|
+
}>;
|
|
489
|
+
declare const passwordResetRequestSchema: z.ZodObject<{
|
|
490
|
+
email: z.ZodString;
|
|
491
|
+
}, "strip", z.ZodTypeAny, {
|
|
492
|
+
email: string;
|
|
493
|
+
}, {
|
|
494
|
+
email: string;
|
|
495
|
+
}>;
|
|
496
|
+
declare const passwordResetConfirmSchema: z.ZodObject<{
|
|
497
|
+
token: z.ZodString;
|
|
498
|
+
password: z.ZodString;
|
|
499
|
+
}, "strip", z.ZodTypeAny, {
|
|
500
|
+
password: string;
|
|
501
|
+
token: string;
|
|
502
|
+
}, {
|
|
503
|
+
password: string;
|
|
504
|
+
token: string;
|
|
505
|
+
}>;
|
|
506
|
+
declare const changePasswordSchema: z.ZodObject<{
|
|
507
|
+
currentPassword: z.ZodString;
|
|
508
|
+
newPassword: z.ZodString;
|
|
509
|
+
}, "strip", z.ZodTypeAny, {
|
|
510
|
+
currentPassword: string;
|
|
511
|
+
newPassword: string;
|
|
512
|
+
}, {
|
|
513
|
+
currentPassword: string;
|
|
514
|
+
newPassword: string;
|
|
515
|
+
}>;
|
|
516
|
+
type LoginInput = z.infer<typeof loginSchema>;
|
|
517
|
+
type RegisterInput = z.infer<typeof registerSchema>;
|
|
518
|
+
type RefreshTokenInput = z.infer<typeof refreshTokenSchema>;
|
|
519
|
+
type PasswordResetRequestInput = z.infer<typeof passwordResetRequestSchema>;
|
|
520
|
+
type PasswordResetConfirmInput = z.infer<typeof passwordResetConfirmSchema>;
|
|
521
|
+
type ChangePasswordInput = z.infer<typeof changePasswordSchema>;
|
|
522
|
+
|
|
523
|
+
declare function registerAuthModule(app: FastifyInstance): Promise<AuthService>;
|
|
524
|
+
|
|
525
|
+
declare class UserController {
|
|
526
|
+
private userService;
|
|
527
|
+
constructor(userService: UserService);
|
|
528
|
+
list(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
529
|
+
getById(request: FastifyRequest<{
|
|
530
|
+
Params: {
|
|
531
|
+
id: string;
|
|
532
|
+
};
|
|
533
|
+
}>, reply: FastifyReply): Promise<void>;
|
|
534
|
+
update(request: FastifyRequest<{
|
|
535
|
+
Params: {
|
|
536
|
+
id: string;
|
|
537
|
+
};
|
|
538
|
+
}>, reply: FastifyReply): Promise<void>;
|
|
539
|
+
delete(request: FastifyRequest<{
|
|
540
|
+
Params: {
|
|
541
|
+
id: string;
|
|
542
|
+
};
|
|
543
|
+
}>, reply: FastifyReply): Promise<void>;
|
|
544
|
+
suspend(request: FastifyRequest<{
|
|
545
|
+
Params: {
|
|
546
|
+
id: string;
|
|
547
|
+
};
|
|
548
|
+
}>, reply: FastifyReply): Promise<void>;
|
|
549
|
+
ban(request: FastifyRequest<{
|
|
550
|
+
Params: {
|
|
551
|
+
id: string;
|
|
552
|
+
};
|
|
553
|
+
}>, reply: FastifyReply): Promise<void>;
|
|
554
|
+
activate(request: FastifyRequest<{
|
|
555
|
+
Params: {
|
|
556
|
+
id: string;
|
|
557
|
+
};
|
|
558
|
+
}>, reply: FastifyReply): Promise<void>;
|
|
559
|
+
getProfile(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
560
|
+
updateProfile(request: FastifyRequest, reply: FastifyReply): Promise<void>;
|
|
561
|
+
}
|
|
562
|
+
declare function createUserController(userService: UserService): UserController;
|
|
563
|
+
|
|
564
|
+
declare const userStatusEnum: z.ZodEnum<["active", "inactive", "suspended", "banned"]>;
|
|
565
|
+
declare const userRoleEnum: z.ZodEnum<["user", "admin", "moderator", "super_admin"]>;
|
|
566
|
+
declare const createUserSchema: z.ZodObject<{
|
|
567
|
+
email: z.ZodString;
|
|
568
|
+
password: z.ZodString;
|
|
569
|
+
name: z.ZodOptional<z.ZodString>;
|
|
570
|
+
role: z.ZodDefault<z.ZodOptional<z.ZodEnum<["user", "admin", "moderator", "super_admin"]>>>;
|
|
571
|
+
}, "strip", z.ZodTypeAny, {
|
|
572
|
+
email: string;
|
|
573
|
+
password: string;
|
|
574
|
+
role: "user" | "admin" | "moderator" | "super_admin";
|
|
575
|
+
name?: string | undefined;
|
|
576
|
+
}, {
|
|
577
|
+
email: string;
|
|
578
|
+
password: string;
|
|
579
|
+
name?: string | undefined;
|
|
580
|
+
role?: "user" | "admin" | "moderator" | "super_admin" | undefined;
|
|
581
|
+
}>;
|
|
582
|
+
declare const updateUserSchema: z.ZodObject<{
|
|
583
|
+
email: z.ZodOptional<z.ZodString>;
|
|
584
|
+
name: z.ZodOptional<z.ZodString>;
|
|
585
|
+
role: z.ZodOptional<z.ZodEnum<["user", "admin", "moderator", "super_admin"]>>;
|
|
586
|
+
status: z.ZodOptional<z.ZodEnum<["active", "inactive", "suspended", "banned"]>>;
|
|
587
|
+
emailVerified: z.ZodOptional<z.ZodBoolean>;
|
|
588
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
589
|
+
}, "strip", z.ZodTypeAny, {
|
|
590
|
+
status?: "active" | "inactive" | "suspended" | "banned" | undefined;
|
|
591
|
+
name?: string | undefined;
|
|
592
|
+
email?: string | undefined;
|
|
593
|
+
role?: "user" | "admin" | "moderator" | "super_admin" | undefined;
|
|
594
|
+
emailVerified?: boolean | undefined;
|
|
595
|
+
metadata?: Record<string, unknown> | undefined;
|
|
596
|
+
}, {
|
|
597
|
+
status?: "active" | "inactive" | "suspended" | "banned" | undefined;
|
|
598
|
+
name?: string | undefined;
|
|
599
|
+
email?: string | undefined;
|
|
600
|
+
role?: "user" | "admin" | "moderator" | "super_admin" | undefined;
|
|
601
|
+
emailVerified?: boolean | undefined;
|
|
602
|
+
metadata?: Record<string, unknown> | undefined;
|
|
603
|
+
}>;
|
|
604
|
+
declare const updateProfileSchema: z.ZodObject<{
|
|
605
|
+
name: z.ZodOptional<z.ZodString>;
|
|
606
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
607
|
+
}, "strip", z.ZodTypeAny, {
|
|
608
|
+
name?: string | undefined;
|
|
609
|
+
metadata?: Record<string, unknown> | undefined;
|
|
610
|
+
}, {
|
|
611
|
+
name?: string | undefined;
|
|
612
|
+
metadata?: Record<string, unknown> | undefined;
|
|
613
|
+
}>;
|
|
614
|
+
declare const userQuerySchema: z.ZodObject<{
|
|
615
|
+
page: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
616
|
+
limit: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
617
|
+
sortBy: z.ZodOptional<z.ZodString>;
|
|
618
|
+
sortOrder: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
|
|
619
|
+
status: z.ZodOptional<z.ZodEnum<["active", "inactive", "suspended", "banned"]>>;
|
|
620
|
+
role: z.ZodOptional<z.ZodEnum<["user", "admin", "moderator", "super_admin"]>>;
|
|
621
|
+
search: z.ZodOptional<z.ZodString>;
|
|
622
|
+
emailVerified: z.ZodOptional<z.ZodEffects<z.ZodString, boolean, string>>;
|
|
623
|
+
}, "strip", z.ZodTypeAny, {
|
|
624
|
+
status?: "active" | "inactive" | "suspended" | "banned" | undefined;
|
|
625
|
+
search?: string | undefined;
|
|
626
|
+
role?: "user" | "admin" | "moderator" | "super_admin" | undefined;
|
|
627
|
+
page?: number | undefined;
|
|
628
|
+
limit?: number | undefined;
|
|
629
|
+
sortBy?: string | undefined;
|
|
630
|
+
sortOrder?: "asc" | "desc" | undefined;
|
|
631
|
+
emailVerified?: boolean | undefined;
|
|
632
|
+
}, {
|
|
633
|
+
status?: "active" | "inactive" | "suspended" | "banned" | undefined;
|
|
634
|
+
search?: string | undefined;
|
|
635
|
+
role?: "user" | "admin" | "moderator" | "super_admin" | undefined;
|
|
636
|
+
page?: string | undefined;
|
|
637
|
+
limit?: string | undefined;
|
|
638
|
+
sortBy?: string | undefined;
|
|
639
|
+
sortOrder?: "asc" | "desc" | undefined;
|
|
640
|
+
emailVerified?: string | undefined;
|
|
641
|
+
}>;
|
|
642
|
+
type CreateUserInput = z.infer<typeof createUserSchema>;
|
|
643
|
+
type UpdateUserInput = z.infer<typeof updateUserSchema>;
|
|
644
|
+
type UpdateProfileInput = z.infer<typeof updateProfileSchema>;
|
|
645
|
+
type UserQueryInput = z.infer<typeof userQuerySchema>;
|
|
646
|
+
|
|
647
|
+
declare function registerUserModule(app: FastifyInstance, authService: AuthService): Promise<void>;
|
|
648
|
+
|
|
649
|
+
interface EmailConfig {
|
|
650
|
+
host: string;
|
|
651
|
+
port: number;
|
|
652
|
+
secure?: boolean;
|
|
653
|
+
auth: {
|
|
654
|
+
user: string;
|
|
655
|
+
pass: string;
|
|
656
|
+
};
|
|
657
|
+
from: string;
|
|
658
|
+
}
|
|
659
|
+
interface EmailOptions {
|
|
660
|
+
to: string | string[];
|
|
661
|
+
subject: string;
|
|
662
|
+
html?: string;
|
|
663
|
+
text?: string;
|
|
664
|
+
template?: string;
|
|
665
|
+
data?: Record<string, unknown>;
|
|
666
|
+
attachments?: EmailAttachment[];
|
|
667
|
+
replyTo?: string;
|
|
668
|
+
cc?: string | string[];
|
|
669
|
+
bcc?: string | string[];
|
|
670
|
+
}
|
|
671
|
+
interface EmailAttachment {
|
|
672
|
+
filename: string;
|
|
673
|
+
content?: string | Buffer;
|
|
674
|
+
path?: string;
|
|
675
|
+
contentType?: string;
|
|
676
|
+
}
|
|
677
|
+
interface EmailResult {
|
|
678
|
+
success: boolean;
|
|
679
|
+
messageId?: string;
|
|
680
|
+
error?: string;
|
|
681
|
+
}
|
|
682
|
+
type EmailTemplate = 'welcome' | 'verify-email' | 'password-reset' | 'password-changed' | 'login-alert' | 'account-suspended' | 'custom';
|
|
683
|
+
interface TemplateData {
|
|
684
|
+
appName?: string;
|
|
685
|
+
userName?: string;
|
|
686
|
+
userEmail?: string;
|
|
687
|
+
actionUrl?: string;
|
|
688
|
+
token?: string;
|
|
689
|
+
expiresIn?: string;
|
|
690
|
+
ipAddress?: string;
|
|
691
|
+
userAgent?: string;
|
|
692
|
+
[key: string]: unknown;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
declare class EmailService {
|
|
696
|
+
private transporter;
|
|
697
|
+
private config;
|
|
698
|
+
constructor(emailConfig?: Partial<EmailConfig>);
|
|
699
|
+
send(options: EmailOptions): Promise<EmailResult>;
|
|
700
|
+
sendTemplate(to: string, template: string, data: TemplateData): Promise<EmailResult>;
|
|
701
|
+
sendWelcome(email: string, name: string, verifyUrl?: string): Promise<EmailResult>;
|
|
702
|
+
sendVerifyEmail(email: string, name: string, verifyUrl: string): Promise<EmailResult>;
|
|
703
|
+
sendPasswordReset(email: string, name: string, resetUrl: string): Promise<EmailResult>;
|
|
704
|
+
sendPasswordChanged(email: string, name: string, ipAddress?: string, userAgent?: string): Promise<EmailResult>;
|
|
705
|
+
sendLoginAlert(email: string, name: string, ipAddress: string, userAgent: string, location?: string): Promise<EmailResult>;
|
|
706
|
+
verify(): Promise<boolean>;
|
|
707
|
+
private htmlToText;
|
|
708
|
+
}
|
|
709
|
+
declare function getEmailService(): EmailService;
|
|
710
|
+
declare function createEmailService(config?: Partial<EmailConfig>): EmailService;
|
|
711
|
+
|
|
712
|
+
declare function renderTemplate(templateName: string, data: Record<string, unknown>): string;
|
|
713
|
+
declare function renderCustomTemplate(htmlTemplate: string, data: Record<string, unknown>): string;
|
|
714
|
+
|
|
715
|
+
declare function validateBody<T extends ZodTypeAny>(schema: T, data: unknown): z.infer<T>;
|
|
716
|
+
declare function validateQuery<T extends ZodTypeAny>(schema: T, data: unknown): z.infer<T>;
|
|
717
|
+
declare function validateParams<T extends ZodTypeAny>(schema: T, data: unknown): z.infer<T>;
|
|
718
|
+
declare function validate<T extends ZodTypeAny>(schema: T, data: unknown): z.infer<T>;
|
|
719
|
+
declare const idParamSchema: z.ZodObject<{
|
|
720
|
+
id: z.ZodString;
|
|
721
|
+
}, "strip", z.ZodTypeAny, {
|
|
722
|
+
id: string;
|
|
723
|
+
}, {
|
|
724
|
+
id: string;
|
|
725
|
+
}>;
|
|
726
|
+
declare const paginationSchema: z.ZodObject<{
|
|
727
|
+
page: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>>;
|
|
728
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>>;
|
|
729
|
+
sortBy: z.ZodOptional<z.ZodString>;
|
|
730
|
+
sortOrder: z.ZodDefault<z.ZodOptional<z.ZodEnum<["asc", "desc"]>>>;
|
|
731
|
+
}, "strip", z.ZodTypeAny, {
|
|
732
|
+
page: number;
|
|
733
|
+
limit: number;
|
|
734
|
+
sortOrder: "asc" | "desc";
|
|
735
|
+
sortBy?: string | undefined;
|
|
736
|
+
}, {
|
|
737
|
+
page?: string | undefined;
|
|
738
|
+
limit?: string | undefined;
|
|
739
|
+
sortBy?: string | undefined;
|
|
740
|
+
sortOrder?: "asc" | "desc" | undefined;
|
|
741
|
+
}>;
|
|
742
|
+
declare const searchSchema: z.ZodObject<{
|
|
743
|
+
q: z.ZodOptional<z.ZodString>;
|
|
744
|
+
search: z.ZodOptional<z.ZodString>;
|
|
745
|
+
}, "strip", z.ZodTypeAny, {
|
|
746
|
+
search?: string | undefined;
|
|
747
|
+
q?: string | undefined;
|
|
748
|
+
}, {
|
|
749
|
+
search?: string | undefined;
|
|
750
|
+
q?: string | undefined;
|
|
751
|
+
}>;
|
|
752
|
+
declare const emailSchema: z.ZodString;
|
|
753
|
+
declare const passwordSchema: z.ZodString;
|
|
754
|
+
declare const urlSchema: z.ZodString;
|
|
755
|
+
declare const phoneSchema: z.ZodString;
|
|
756
|
+
declare const dateSchema: z.ZodDate;
|
|
757
|
+
declare const futureDateSchema: z.ZodEffects<z.ZodDate, Date, Date>;
|
|
758
|
+
declare const pastDateSchema: z.ZodEffects<z.ZodDate, Date, Date>;
|
|
759
|
+
type IdParam = z.infer<typeof idParamSchema>;
|
|
760
|
+
type PaginationInput = z.infer<typeof paginationSchema>;
|
|
761
|
+
|
|
762
|
+
type AuditAction = 'create' | 'read' | 'update' | 'delete' | 'login' | 'logout' | 'register' | 'password_change' | 'password_reset' | 'email_verify' | 'role_change' | 'status_change' | 'settings_change';
|
|
763
|
+
interface AuditLogEntry {
|
|
764
|
+
userId?: string;
|
|
765
|
+
action: AuditAction | string;
|
|
766
|
+
resource: string;
|
|
767
|
+
resourceId?: string;
|
|
768
|
+
oldValue?: Record<string, unknown>;
|
|
769
|
+
newValue?: Record<string, unknown>;
|
|
770
|
+
ipAddress?: string;
|
|
771
|
+
userAgent?: string;
|
|
772
|
+
metadata?: Record<string, unknown>;
|
|
773
|
+
}
|
|
774
|
+
interface AuditLogQuery {
|
|
775
|
+
userId?: string;
|
|
776
|
+
action?: string;
|
|
777
|
+
resource?: string;
|
|
778
|
+
resourceId?: string;
|
|
779
|
+
startDate?: Date;
|
|
780
|
+
endDate?: Date;
|
|
781
|
+
page?: number;
|
|
782
|
+
limit?: number;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
declare class AuditService {
|
|
786
|
+
log(entry: AuditLogEntry): Promise<void>;
|
|
787
|
+
query(params: AuditLogQuery): Promise<PaginatedResult<AuditLogEntry & {
|
|
788
|
+
id: string;
|
|
789
|
+
createdAt: Date;
|
|
790
|
+
}>>;
|
|
791
|
+
findByUser(userId: string, limit?: number): Promise<(AuditLogEntry & {
|
|
792
|
+
id: string;
|
|
793
|
+
createdAt: Date;
|
|
794
|
+
})[]>;
|
|
795
|
+
findByResource(resource: string, resourceId: string, limit?: number): Promise<(AuditLogEntry & {
|
|
796
|
+
id: string;
|
|
797
|
+
createdAt: Date;
|
|
798
|
+
})[]>;
|
|
799
|
+
logCreate(resource: string, resourceId: string, userId?: string, newValue?: Record<string, unknown>, meta?: {
|
|
800
|
+
ipAddress?: string;
|
|
801
|
+
userAgent?: string;
|
|
802
|
+
}): Promise<void>;
|
|
803
|
+
logUpdate(resource: string, resourceId: string, userId?: string, oldValue?: Record<string, unknown>, newValue?: Record<string, unknown>, meta?: {
|
|
804
|
+
ipAddress?: string;
|
|
805
|
+
userAgent?: string;
|
|
806
|
+
}): Promise<void>;
|
|
807
|
+
logDelete(resource: string, resourceId: string, userId?: string, oldValue?: Record<string, unknown>, meta?: {
|
|
808
|
+
ipAddress?: string;
|
|
809
|
+
userAgent?: string;
|
|
810
|
+
}): Promise<void>;
|
|
811
|
+
logLogin(userId: string, meta?: {
|
|
812
|
+
ipAddress?: string;
|
|
813
|
+
userAgent?: string;
|
|
814
|
+
}): Promise<void>;
|
|
815
|
+
logLogout(userId: string, meta?: {
|
|
816
|
+
ipAddress?: string;
|
|
817
|
+
userAgent?: string;
|
|
818
|
+
}): Promise<void>;
|
|
819
|
+
logPasswordChange(userId: string, meta?: {
|
|
820
|
+
ipAddress?: string;
|
|
821
|
+
userAgent?: string;
|
|
822
|
+
}): Promise<void>;
|
|
823
|
+
clear(): Promise<void>;
|
|
824
|
+
}
|
|
825
|
+
declare function getAuditService(): AuditService;
|
|
826
|
+
declare function createAuditService(): AuditService;
|
|
827
|
+
|
|
828
|
+
export { type ApiResponse, type AppConfig, AppError, type AuditAction, type AuditLogEntry, type AuditLogQuery, AuditService, AuthController, AuthService, type AuthUser, type AuthenticatedRequest, BadRequestError, type BaseEntity, type ChangePasswordData, type ChangePasswordInput, ConflictError, type ControllerHandler, type CreateUserData, type CreateUserInput, DEFAULT_LIMIT, DEFAULT_PAGE, DEFAULT_ROLE_PERMISSIONS, type EmailAttachment, type EmailConfig, type EmailOptions, type EmailResult, EmailService, type EmailTemplate, type Env, ForbiddenError, type IdParam, type JwtPayload, type LoggerConfig, type LoginCredentials, type LoginInput, MAX_LIMIT, type Module, NotFoundError, type PaginatedResult, type PaginationInput, type PaginationParams, type PasswordResetConfirm, type PasswordResetConfirmInput, type PasswordResetRequest, type PasswordResetRequestInput, type Permission, type RefreshTokenData, type RefreshTokenInput, type RegisterData, type RegisterInput, type Repository, type Role, type SecurityOptions, Server, type ServerConfig, type ServiceResult, type TemplateData, type TokenPair, TooManyRequestsError, UnauthorizedError, type UpdateProfileInput, type UpdateUserData, type UpdateUserInput, type User, UserController, type UserFilters, type UserQueryInput, UserRepository, type UserRole, UserService, type UserStatus, ValidationError, badRequest, changePasswordSchema, config, conflict, createAuditService, createAuthController, createAuthMiddleware, createAuthService, createConfig, createEmailService, createLogger, createOptionalAuthMiddleware, createPaginatedResult, createPermissionMiddleware, createRoleMiddleware, createServer, createUserController, createUserRepository, createUserSchema, createUserService, created, dateSchema, emailSchema, env, error, forbidden, futureDateSchema, getAuditService, getEmailService, getSkip, idParamSchema, internalError, isAppError, isDevelopment, isProduction, isStaging, isTest, logger, loginSchema, noContent, notFound, paginationSchema, parsePaginationParams, passwordResetConfirmSchema, passwordResetRequestSchema, passwordSchema, pastDateSchema, phoneSchema, refreshTokenSchema, registerAuthModule, registerBruteForceProtection, registerErrorHandler, registerSchema, registerSecurity, registerUserModule, renderCustomTemplate, renderTemplate, searchSchema, success, unauthorized, updateProfileSchema, updateUserSchema, urlSchema, userQuerySchema, userRoleEnum, userStatusEnum, validate, validateBody, validateParams, validateQuery };
|