@alacard-project/shared 1.0.0 → 1.0.3
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/dist/config/base-config.service.d.ts +25 -0
- package/dist/config/base-config.service.js +87 -0
- package/dist/config/base-config.service.js.map +1 -0
- package/dist/constants/auth-config.constants.d.ts +8 -0
- package/dist/constants/auth-config.constants.js +12 -0
- package/dist/constants/auth-config.constants.js.map +1 -0
- package/dist/constants/auth.constants.d.ts +31 -0
- package/dist/constants/auth.constants.js +35 -0
- package/dist/constants/auth.constants.js.map +1 -0
- package/dist/constants/common.constants.d.ts +8 -0
- package/dist/constants/common.constants.js +12 -0
- package/dist/constants/common.constants.js.map +1 -0
- package/dist/constants/env.constants.d.ts +21 -4
- package/dist/constants/env.constants.js +21 -4
- package/dist/constants/env.constants.js.map +1 -1
- package/dist/constants/error-messages.d.ts +1 -0
- package/dist/constants/error-messages.js +13 -0
- package/dist/constants/error-messages.js.map +1 -0
- package/dist/constants/grpc.constants.d.ts +26 -0
- package/dist/constants/grpc.constants.js +26 -0
- package/dist/constants/grpc.constants.js.map +1 -1
- package/dist/constants/index.d.ts +10 -2
- package/dist/constants/index.js +10 -2
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/logging-messages.constants.d.ts +12 -0
- package/dist/constants/logging-messages.constants.js +16 -0
- package/dist/constants/logging-messages.constants.js.map +1 -0
- package/dist/constants/microservices.constants.d.ts +18 -0
- package/dist/constants/microservices.constants.js +22 -0
- package/dist/constants/microservices.constants.js.map +1 -0
- package/dist/constants/monitoring.constants.d.ts +51 -0
- package/dist/constants/monitoring.constants.js +55 -0
- package/dist/constants/monitoring.constants.js.map +1 -0
- package/dist/constants/routes.constants.d.ts +20 -0
- package/dist/constants/routes.constants.js +24 -0
- package/dist/constants/routes.constants.js.map +1 -0
- package/dist/constants/tokens.constants.d.ts +6 -0
- package/dist/constants/tokens.constants.js +10 -0
- package/dist/constants/tokens.constants.js.map +1 -0
- package/dist/contracts/auth.contract.d.ts +88 -0
- package/dist/contracts/auth.contract.js +3 -0
- package/dist/contracts/auth.contract.js.map +1 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/decorators/scopes.decorator.d.ts +2 -0
- package/dist/decorators/scopes.decorator.js +8 -0
- package/dist/decorators/scopes.decorator.js.map +1 -0
- package/dist/dto/auth.dto.d.ts +41 -0
- package/dist/dto/auth.dto.js +53 -0
- package/dist/dto/auth.dto.js.map +1 -0
- package/dist/dto/index.d.ts +2 -0
- package/dist/dto/index.js +19 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/dto/logging.dto.d.ts +29 -0
- package/dist/dto/logging.dto.js +146 -0
- package/dist/dto/logging.dto.js.map +1 -0
- package/dist/enums/{environment.enum.js → env.enum.js} +1 -1
- package/dist/enums/env.enum.js.map +1 -0
- package/dist/enums/error.enum.d.ts +19 -0
- package/dist/enums/error.enum.js +24 -0
- package/dist/enums/error.enum.js.map +1 -0
- package/dist/enums/events.enum.d.ts +20 -0
- package/dist/enums/events.enum.js +14 -0
- package/dist/enums/events.enum.js.map +1 -0
- package/dist/enums/health.enum.d.ts +7 -0
- package/dist/enums/health.enum.js +12 -0
- package/dist/enums/health.enum.js.map +1 -0
- package/dist/enums/index.d.ts +8 -5
- package/dist/enums/index.js +8 -5
- package/dist/enums/index.js.map +1 -1
- package/dist/enums/{log-level.enum.js → logging.enum.js} +1 -1
- package/dist/enums/logging.enum.js.map +1 -0
- package/dist/enums/{notification-type.enum.js → notification.enum.js} +1 -1
- package/dist/enums/notification.enum.js.map +1 -0
- package/dist/enums/permission.enum.d.ts +18 -0
- package/dist/enums/permission.enum.js +23 -0
- package/dist/enums/permission.enum.js.map +1 -0
- package/dist/enums/user.enum.d.ts +8 -0
- package/dist/enums/{user-role.enum.js → user.enum.js} +4 -2
- package/dist/enums/user.enum.js.map +1 -0
- package/dist/errors/app.error.d.ts +17 -0
- package/dist/errors/app.error.js +29 -0
- package/dist/errors/app.error.js.map +1 -0
- package/dist/errors/error-map.d.ts +7 -0
- package/dist/errors/error-map.js +92 -0
- package/dist/errors/error-map.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/types/auth.types.d.ts +5 -0
- package/dist/types/config.types.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/monitoring.types.d.ts +60 -0
- package/dist/types/monitoring.types.js +3 -0
- package/dist/types/monitoring.types.js.map +1 -0
- package/dist/types/user.types.d.ts +10 -0
- package/dist/types/user.types.js +3 -0
- package/dist/types/user.types.js.map +1 -0
- package/dist/utils/app.utils.d.ts +8 -0
- package/dist/utils/app.utils.js +25 -0
- package/dist/utils/app.utils.js.map +1 -0
- package/dist/utils/health.utils.d.ts +8 -0
- package/dist/utils/health.utils.js +60 -0
- package/dist/utils/health.utils.js.map +1 -0
- package/dist/utils/logging-client.d.ts +7 -0
- package/dist/utils/logging-client.js +22 -0
- package/dist/utils/logging-client.js.map +1 -0
- package/dist/utils/prometheus.utils.d.ts +9 -0
- package/dist/utils/prometheus.utils.js +66 -0
- package/dist/utils/prometheus.utils.js.map +1 -0
- package/dist/utils/user.utils.d.ts +1 -0
- package/dist/utils/user.utils.js +7 -0
- package/dist/utils/user.utils.js.map +1 -0
- package/package.json +9 -8
- package/src/config/base-config.service.ts +101 -0
- package/src/constants/auth-config.constants.ts +9 -0
- package/src/constants/auth.constants.ts +34 -0
- package/src/constants/common.constants.ts +9 -0
- package/src/constants/env.constants.ts +21 -4
- package/src/constants/error-messages.ts +10 -0
- package/src/constants/grpc.constants.ts +26 -0
- package/src/constants/index.ts +10 -2
- package/src/constants/logging-messages.constants.ts +15 -0
- package/src/constants/microservices.constants.ts +18 -0
- package/src/constants/monitoring.constants.ts +71 -0
- package/src/constants/routes.constants.ts +21 -0
- package/src/constants/tokens.constants.ts +6 -0
- package/src/contracts/auth.contract.ts +98 -0
- package/src/contracts/index.ts +1 -0
- package/src/decorators/scopes.decorator.ts +4 -0
- package/src/dto/auth.dto.ts +62 -0
- package/src/dto/index.ts +2 -0
- package/src/{logging/dto/log-filter.dto.ts → dto/logging.dto.ts} +1 -1
- package/src/enums/error.enum.ts +26 -0
- package/src/enums/events.enum.ts +22 -0
- package/src/enums/health.enum.ts +7 -0
- package/src/enums/index.ts +8 -5
- package/src/enums/permission.enum.ts +31 -0
- package/src/enums/{user-role.enum.ts → user.enum.ts} +3 -1
- package/src/errors/app.error.ts +33 -0
- package/src/errors/error-map.ts +95 -0
- package/src/index.ts +10 -1
- package/src/types/auth.types.ts +5 -0
- package/src/types/config.types.ts +4 -2
- package/src/types/index.ts +2 -1
- package/src/types/monitoring.types.ts +79 -0
- package/src/types/user.types.ts +11 -0
- package/src/utils/app.utils.ts +54 -0
- package/src/utils/health.utils.ts +72 -0
- package/src/utils/logging-client.ts +21 -0
- package/src/utils/prometheus.utils.ts +114 -0
- package/src/utils/user.utils.ts +3 -0
- package/dist/constants/services.constants.d.ts +0 -6
- package/dist/constants/services.constants.js +0 -10
- package/dist/constants/services.constants.js.map +0 -1
- package/dist/enums/environment.enum.js.map +0 -1
- package/dist/enums/error-code.enum.d.ts +0 -8
- package/dist/enums/error-code.enum.js +0 -13
- package/dist/enums/error-code.enum.js.map +0 -1
- package/dist/enums/log-level.enum.js.map +0 -1
- package/dist/enums/notification-type.enum.js.map +0 -1
- package/dist/enums/user-role.enum.d.ts +0 -6
- package/dist/enums/user-role.enum.js.map +0 -1
- package/dist/logging/enums/log-level.enum.d.ts +0 -7
- package/dist/logging/enums/log-level.enum.js +0 -12
- package/dist/logging/enums/log-level.enum.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/proto/token.proto +0 -50
- package/src/constants/services.constants.ts +0 -6
- package/src/enums/error-code.enum.ts +0 -8
- package/src/logging/index.ts +0 -1
- /package/dist/enums/{environment.enum.d.ts → env.enum.d.ts} +0 -0
- /package/dist/enums/{log-level.enum.d.ts → logging.enum.d.ts} +0 -0
- /package/dist/enums/{notification-type.enum.d.ts → notification.enum.d.ts} +0 -0
- /package/src/enums/{environment.enum.ts → env.enum.ts} +0 -0
- /package/src/enums/{log-level.enum.ts → logging.enum.ts} +0 -0
- /package/src/enums/{notification-type.enum.ts → notification.enum.ts} +0 -0
package/src/contracts/index.ts
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { IsEmail, IsString, MinLength, IsEnum, IsOptional } from 'class-validator';
|
|
2
|
+
import { UserRole } from '../enums/user.enum';
|
|
3
|
+
|
|
4
|
+
export class RegisterDto {
|
|
5
|
+
@IsEmail()
|
|
6
|
+
email!: string;
|
|
7
|
+
|
|
8
|
+
@IsString()
|
|
9
|
+
@MinLength(8)
|
|
10
|
+
password!: string;
|
|
11
|
+
|
|
12
|
+
@IsEnum(UserRole)
|
|
13
|
+
@IsOptional()
|
|
14
|
+
role?: UserRole;
|
|
15
|
+
|
|
16
|
+
@IsString()
|
|
17
|
+
@IsOptional()
|
|
18
|
+
firstName?: string;
|
|
19
|
+
|
|
20
|
+
@IsString()
|
|
21
|
+
@IsOptional()
|
|
22
|
+
lastName?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class LoginDto {
|
|
26
|
+
@IsEmail()
|
|
27
|
+
email!: string;
|
|
28
|
+
|
|
29
|
+
@IsString()
|
|
30
|
+
password!: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface UserResponse {
|
|
34
|
+
id: string;
|
|
35
|
+
email: string;
|
|
36
|
+
role: UserRole;
|
|
37
|
+
firstName: string;
|
|
38
|
+
lastName: string;
|
|
39
|
+
middleName?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
isActive: boolean;
|
|
42
|
+
createdAt?: string;
|
|
43
|
+
updatedAt?: string;
|
|
44
|
+
password?: string;
|
|
45
|
+
shortName?: string;
|
|
46
|
+
internalPhone?: string;
|
|
47
|
+
mobilePhone?: string;
|
|
48
|
+
facsimileSignature?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface UserProfileDto {
|
|
52
|
+
id: string;
|
|
53
|
+
email: string;
|
|
54
|
+
role: string;
|
|
55
|
+
isActive: boolean;
|
|
56
|
+
createdAt: Date;
|
|
57
|
+
updatedAt: Date;
|
|
58
|
+
fullName: string;
|
|
59
|
+
position: string;
|
|
60
|
+
department: string;
|
|
61
|
+
emailVerified: boolean;
|
|
62
|
+
}
|
package/src/dto/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export enum ErrorCode {
|
|
2
|
+
// Auth Errors
|
|
3
|
+
AUTH_USER_NOT_FOUND = 'AUTH_USER_NOT_FOUND',
|
|
4
|
+
AUTH_USER_ALREADY_EXISTS = 'AUTH_USER_ALREADY_EXISTS',
|
|
5
|
+
AUTH_USER_INACTIVE = 'AUTH_USER_INACTIVE',
|
|
6
|
+
AUTH_INVALID_PASSWORD = 'AUTH_INVALID_PASSWORD',
|
|
7
|
+
AUTH_INVALID_TOKEN = 'AUTH_INVALID_TOKEN',
|
|
8
|
+
AUTH_TOKEN_EXPIRED = 'AUTH_TOKEN_EXPIRED',
|
|
9
|
+
AUTH_ACCESS_DENIED = 'AUTH_ACCESS_DENIED',
|
|
10
|
+
AUTH_INSUFFICIENT_SCOPES = 'AUTH_INSUFFICIENT_SCOPES',
|
|
11
|
+
AUTH_INVALID_CREDENTIALS = 'AUTH_INVALID_CREDENTIALS',
|
|
12
|
+
|
|
13
|
+
// Config Errors
|
|
14
|
+
CONFIG_NOT_FOUND = 'CONFIG_NOT_FOUND',
|
|
15
|
+
CONFIG_LOAD_FAILED = 'CONFIG_LOAD_FAILED',
|
|
16
|
+
|
|
17
|
+
// Logging Errors
|
|
18
|
+
LOG_WRITE_FAILED = 'LOG_WRITE_FAILED',
|
|
19
|
+
LOG_READ_FAILED = 'LOG_READ_FAILED',
|
|
20
|
+
|
|
21
|
+
// General Errors
|
|
22
|
+
INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR',
|
|
23
|
+
BAD_REQUEST = 'BAD_REQUEST',
|
|
24
|
+
NOT_FOUND = 'NOT_FOUND',
|
|
25
|
+
VALIDATION_ERROR = 'VALIDATION_ERROR',
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export enum ServiceEventType {
|
|
2
|
+
AUTH_USER_REGISTERED = 'auth.user.registered',
|
|
3
|
+
AUTH_USER_LOGGED_IN = 'auth.user.logged_in',
|
|
4
|
+
AUTH_PASSWORD_RESET_REQUESTED = 'auth.password_reset_requested',
|
|
5
|
+
AUTH_PASSWORD_RESET_SUCCESS = 'auth.password_reset_success',
|
|
6
|
+
USER_PROFILE_UPDATED = 'user.profile_updated',
|
|
7
|
+
USER_DELETED = 'user.deleted',
|
|
8
|
+
AUTH_USER_BLOCKED = 'auth.user.blocked',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AuthUserRegisteredEvent {
|
|
12
|
+
userId: string;
|
|
13
|
+
email: string;
|
|
14
|
+
role: string;
|
|
15
|
+
occurredAt: Date;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AuthUserBlockedEvent {
|
|
19
|
+
userId: string;
|
|
20
|
+
reason?: string;
|
|
21
|
+
blockedAt: Date;
|
|
22
|
+
}
|
package/src/enums/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './user
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
1
|
+
export * from './env.enum';
|
|
2
|
+
export * from './user.enum';
|
|
3
|
+
export * from './health.enum';
|
|
4
|
+
export * from './logging.enum';
|
|
5
|
+
export * from './notification.enum';
|
|
6
|
+
export * from './error.enum';
|
|
7
|
+
export * from './permission.enum';
|
|
8
|
+
export * from './events.enum';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export enum PermissionScope {
|
|
2
|
+
// User Management
|
|
3
|
+
USERS_VIEW = 'users:view',
|
|
4
|
+
USERS_MANAGE = 'users:manage',
|
|
5
|
+
|
|
6
|
+
// Auth Management
|
|
7
|
+
ROLES_MANAGE = 'roles:manage',
|
|
8
|
+
PERMISSIONS_MANAGE = 'permissions:manage',
|
|
9
|
+
|
|
10
|
+
// Client Management
|
|
11
|
+
CLIENTS_VIEW = 'clients:view',
|
|
12
|
+
CLIENTS_MANAGE = 'clients:manage',
|
|
13
|
+
|
|
14
|
+
// Partner Management
|
|
15
|
+
PARTNERS_VIEW = 'partners:view',
|
|
16
|
+
PARTNERS_MANAGE = 'partners:manage',
|
|
17
|
+
|
|
18
|
+
// Financial/Accounting
|
|
19
|
+
INVOICES_VIEW = 'invoices:view',
|
|
20
|
+
INVOICES_MANAGE = 'invoices:manage',
|
|
21
|
+
TRANSACTIONS_VIEW = 'transactions:view',
|
|
22
|
+
TRANSACTIONS_MANAGE = 'transactions:manage',
|
|
23
|
+
|
|
24
|
+
// System Config
|
|
25
|
+
CONFIG_VIEW = 'config:view',
|
|
26
|
+
CONFIG_MANAGE = 'config:manage',
|
|
27
|
+
|
|
28
|
+
// Logging/Monitoring
|
|
29
|
+
LOGS_VIEW = 'logs:view',
|
|
30
|
+
METRICS_VIEW = 'metrics:view',
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ErrorCode } from '../enums/error.enum';
|
|
2
|
+
import { ERROR_MAP } from './error-map';
|
|
3
|
+
|
|
4
|
+
export class AppError extends Error {
|
|
5
|
+
public readonly code: ErrorCode;
|
|
6
|
+
public readonly statusCode: number;
|
|
7
|
+
public readonly description?: string;
|
|
8
|
+
public readonly metadata?: any;
|
|
9
|
+
|
|
10
|
+
constructor(code: ErrorCode, customMessage?: string, metadata?: any) {
|
|
11
|
+
const errorDetail = ERROR_MAP[code] || ERROR_MAP[ErrorCode.INTERNAL_SERVER_ERROR];
|
|
12
|
+
super(customMessage || errorDetail.message);
|
|
13
|
+
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.statusCode = errorDetail.statusCode;
|
|
16
|
+
this.description = errorDetail.description;
|
|
17
|
+
this.metadata = metadata;
|
|
18
|
+
|
|
19
|
+
Object.setPrototypeOf(this, AppError.prototype);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toJSON() {
|
|
23
|
+
return {
|
|
24
|
+
success: false,
|
|
25
|
+
error: {
|
|
26
|
+
code: this.code,
|
|
27
|
+
message: this.message,
|
|
28
|
+
description: this.description,
|
|
29
|
+
metadata: this.metadata,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ErrorCode } from '../enums/error.enum';
|
|
2
|
+
|
|
3
|
+
export interface ErrorDetail {
|
|
4
|
+
message: string;
|
|
5
|
+
statusCode: number;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const ERROR_MAP: Record<ErrorCode, ErrorDetail> = {
|
|
10
|
+
[ErrorCode.AUTH_USER_NOT_FOUND]: {
|
|
11
|
+
message: 'User not found',
|
|
12
|
+
statusCode: 404,
|
|
13
|
+
description: 'The requested user could not be found in the system.',
|
|
14
|
+
},
|
|
15
|
+
[ErrorCode.AUTH_USER_ALREADY_EXISTS]: {
|
|
16
|
+
message: 'User already exists',
|
|
17
|
+
statusCode: 409,
|
|
18
|
+
description: 'A user with this email already exists.',
|
|
19
|
+
},
|
|
20
|
+
[ErrorCode.AUTH_USER_INACTIVE]: {
|
|
21
|
+
message: 'User is inactive',
|
|
22
|
+
statusCode: 403,
|
|
23
|
+
description: 'The user account is currently deactivated.',
|
|
24
|
+
},
|
|
25
|
+
[ErrorCode.AUTH_INVALID_PASSWORD]: {
|
|
26
|
+
message: 'Invalid password',
|
|
27
|
+
statusCode: 401,
|
|
28
|
+
description: 'The provided password does not match.',
|
|
29
|
+
},
|
|
30
|
+
[ErrorCode.AUTH_INVALID_TOKEN]: {
|
|
31
|
+
message: 'Invalid token',
|
|
32
|
+
statusCode: 401,
|
|
33
|
+
description: 'The provided authentication token is invalid or malformed.',
|
|
34
|
+
},
|
|
35
|
+
[ErrorCode.AUTH_TOKEN_EXPIRED]: {
|
|
36
|
+
message: 'Token expired',
|
|
37
|
+
statusCode: 401,
|
|
38
|
+
description: 'The authentication token has expired. Please log in again.',
|
|
39
|
+
},
|
|
40
|
+
[ErrorCode.AUTH_ACCESS_DENIED]: {
|
|
41
|
+
message: 'Access denied',
|
|
42
|
+
statusCode: 403,
|
|
43
|
+
description: 'You do not have permission to perform this action.',
|
|
44
|
+
},
|
|
45
|
+
[ErrorCode.AUTH_INSUFFICIENT_SCOPES]: {
|
|
46
|
+
message: 'Insufficient scopes',
|
|
47
|
+
statusCode: 403,
|
|
48
|
+
description: 'Your token does not have the required scopes for this resource.',
|
|
49
|
+
},
|
|
50
|
+
[ErrorCode.AUTH_INVALID_CREDENTIALS]: {
|
|
51
|
+
message: 'Invalid credentials',
|
|
52
|
+
statusCode: 401,
|
|
53
|
+
description: 'The email or password you entered is incorrect.',
|
|
54
|
+
},
|
|
55
|
+
[ErrorCode.CONFIG_NOT_FOUND]: {
|
|
56
|
+
message: 'Configuration not found',
|
|
57
|
+
statusCode: 404,
|
|
58
|
+
description: 'The requested configuration key was not found.',
|
|
59
|
+
},
|
|
60
|
+
[ErrorCode.CONFIG_LOAD_FAILED]: {
|
|
61
|
+
message: 'Configuration load failed',
|
|
62
|
+
statusCode: 500,
|
|
63
|
+
description: 'Failed to load configuration from the source.',
|
|
64
|
+
},
|
|
65
|
+
[ErrorCode.LOG_WRITE_FAILED]: {
|
|
66
|
+
message: 'Log write failed',
|
|
67
|
+
statusCode: 500,
|
|
68
|
+
description: 'Failed to write log to the destination.',
|
|
69
|
+
},
|
|
70
|
+
[ErrorCode.LOG_READ_FAILED]: {
|
|
71
|
+
message: 'Log read failed',
|
|
72
|
+
statusCode: 500,
|
|
73
|
+
description: 'Failed to read logs from the source.',
|
|
74
|
+
},
|
|
75
|
+
[ErrorCode.INTERNAL_SERVER_ERROR]: {
|
|
76
|
+
message: 'Internal server error',
|
|
77
|
+
statusCode: 500,
|
|
78
|
+
description: 'An unexpected error occurred on the server.',
|
|
79
|
+
},
|
|
80
|
+
[ErrorCode.BAD_REQUEST]: {
|
|
81
|
+
message: 'Bad request',
|
|
82
|
+
statusCode: 400,
|
|
83
|
+
description: 'The request is invalid or cannot be served.',
|
|
84
|
+
},
|
|
85
|
+
[ErrorCode.NOT_FOUND]: {
|
|
86
|
+
message: 'Resource not found',
|
|
87
|
+
statusCode: 404,
|
|
88
|
+
description: 'The requested resource could not be found.',
|
|
89
|
+
},
|
|
90
|
+
[ErrorCode.VALIDATION_ERROR]: {
|
|
91
|
+
message: 'Validation error',
|
|
92
|
+
statusCode: 422,
|
|
93
|
+
description: 'The provided data failed validation.',
|
|
94
|
+
},
|
|
95
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,14 @@ export * from './enums';
|
|
|
2
2
|
export * from './constants';
|
|
3
3
|
export * from './types';
|
|
4
4
|
export * from './contracts';
|
|
5
|
+
export * from './dto';
|
|
6
|
+
export * from './errors/app.error';
|
|
7
|
+
export * from './errors/error-map';
|
|
8
|
+
export * from './decorators/scopes.decorator';
|
|
5
9
|
export * from './utils/proto-path';
|
|
6
|
-
export * from './logging';
|
|
10
|
+
export * from './utils/logging-client';
|
|
11
|
+
export * from './config/base-config.service';
|
|
12
|
+
export * from './utils/user.utils';
|
|
13
|
+
export * from './utils/prometheus.utils';
|
|
14
|
+
export * from './utils/app.utils';
|
|
15
|
+
export * from './utils/health.utils';
|
package/src/types/auth.types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Environment } from '../enums/env.enum';
|
|
2
|
+
|
|
1
3
|
export interface IBaseConfig {
|
|
2
|
-
environment:
|
|
4
|
+
environment: Environment;
|
|
3
5
|
}
|
|
4
6
|
|
|
5
7
|
export interface DbConfig {
|
|
@@ -21,7 +23,7 @@ export interface AppConfig {
|
|
|
21
23
|
port: number;
|
|
22
24
|
host?: string;
|
|
23
25
|
serviceName: string;
|
|
24
|
-
environment?:
|
|
26
|
+
environment?: Environment;
|
|
25
27
|
version?: string;
|
|
26
28
|
description?: string;
|
|
27
29
|
databaseUrl?: string;
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prometheus Metrics Types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface PrometheusMetric {
|
|
6
|
+
name: string;
|
|
7
|
+
help: string;
|
|
8
|
+
type: 'counter' | 'gauge' | 'histogram' | 'summary';
|
|
9
|
+
labelNames?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MetricValue {
|
|
13
|
+
value: number;
|
|
14
|
+
labels?: Record<string, string>;
|
|
15
|
+
timestamp?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ServiceMetrics {
|
|
19
|
+
serviceName: string;
|
|
20
|
+
timestamp: Date;
|
|
21
|
+
metrics: {
|
|
22
|
+
// HTTP Metrics
|
|
23
|
+
httpRequestsTotal?: number;
|
|
24
|
+
httpRequestDuration?: number;
|
|
25
|
+
httpErrorsTotal?: number;
|
|
26
|
+
|
|
27
|
+
// Database Metrics
|
|
28
|
+
dbConnectionsActive?: number;
|
|
29
|
+
dbConnectionsIdle?: number;
|
|
30
|
+
dbQueryDuration?: number;
|
|
31
|
+
dbQueriesTotal?: number;
|
|
32
|
+
|
|
33
|
+
// System Metrics
|
|
34
|
+
cpuUsage?: number;
|
|
35
|
+
memoryUsage?: number;
|
|
36
|
+
heapUsed?: number;
|
|
37
|
+
heapTotal?: number;
|
|
38
|
+
|
|
39
|
+
// Application Metrics
|
|
40
|
+
activeUsers?: number;
|
|
41
|
+
requestsPerSecond?: number;
|
|
42
|
+
errorRate?: number;
|
|
43
|
+
|
|
44
|
+
// Custom Metrics
|
|
45
|
+
[key: string]: number | undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface HealthCheckResult {
|
|
50
|
+
status: 'healthy' | 'unhealthy' | 'degraded';
|
|
51
|
+
checks: {
|
|
52
|
+
[component: string]: {
|
|
53
|
+
status: 'up' | 'down';
|
|
54
|
+
message?: string;
|
|
55
|
+
responseTime?: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
timestamp: Date;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface GrafanaDashboard {
|
|
62
|
+
id: string;
|
|
63
|
+
title: string;
|
|
64
|
+
panels: GrafanaPanel[];
|
|
65
|
+
tags: string[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface GrafanaPanel {
|
|
69
|
+
id: number;
|
|
70
|
+
title: string;
|
|
71
|
+
type: 'graph' | 'singlestat' | 'table' | 'heatmap';
|
|
72
|
+
targets: GrafanaTarget[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface GrafanaTarget {
|
|
76
|
+
expr: string; // Prometheus query
|
|
77
|
+
legendFormat?: string;
|
|
78
|
+
refId: string;
|
|
79
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { UserResponse } from '../dto/auth.dto';
|
|
3
|
+
import { GetUserByIdGrpcRequest, GetUserByEmailGrpcRequest } from '../contracts/auth.contract';
|
|
4
|
+
|
|
5
|
+
export interface IUserService {
|
|
6
|
+
getUserById(data: GetUserByIdGrpcRequest): Observable<UserResponse>;
|
|
7
|
+
getUserByEmail(data: GetUserByEmailGrpcRequest): Observable<UserResponse>;
|
|
8
|
+
createUser(data: any): Observable<UserResponse>;
|
|
9
|
+
updateUser(data: any): Observable<UserResponse>;
|
|
10
|
+
deleteUser(data: any): Observable<any>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Setup Utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { INestApplication, ValidationPipe } from '@nestjs/common';
|
|
6
|
+
import { API_PREFIX } from '../constants/http.constants';
|
|
7
|
+
import helmet from 'helmet';
|
|
8
|
+
|
|
9
|
+
export interface AppSetupOptions {
|
|
10
|
+
corsOrigins?: string[];
|
|
11
|
+
apiPrefix?: string;
|
|
12
|
+
helmet?: boolean;
|
|
13
|
+
validation?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Setup standard NestJS application middleware
|
|
18
|
+
*/
|
|
19
|
+
export function setupStandardApp(
|
|
20
|
+
app: INestApplication,
|
|
21
|
+
options: AppSetupOptions = {}
|
|
22
|
+
): void {
|
|
23
|
+
const {
|
|
24
|
+
corsOrigins = ['*'],
|
|
25
|
+
apiPrefix = API_PREFIX.V1,
|
|
26
|
+
helmet: useHelmet = true,
|
|
27
|
+
validation = true,
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
// CORS
|
|
31
|
+
app.enableCors({
|
|
32
|
+
origin: corsOrigins,
|
|
33
|
+
credentials: true,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// API Prefix
|
|
37
|
+
app.setGlobalPrefix(apiPrefix);
|
|
38
|
+
|
|
39
|
+
// Security
|
|
40
|
+
if (useHelmet) {
|
|
41
|
+
app.use(helmet());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Validation
|
|
45
|
+
if (validation) {
|
|
46
|
+
app.useGlobalPipes(
|
|
47
|
+
new ValidationPipe({
|
|
48
|
+
whitelist: true,
|
|
49
|
+
forbidNonWhitelisted: true,
|
|
50
|
+
transform: true,
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health Check Utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ComponentHealth {
|
|
6
|
+
status: 'up' | 'down';
|
|
7
|
+
message?: string;
|
|
8
|
+
responseTime?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create Prisma health check function
|
|
13
|
+
*/
|
|
14
|
+
export function createPrismaHealthCheck(prisma: any) {
|
|
15
|
+
return async (): Promise<ComponentHealth> => {
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
try {
|
|
18
|
+
await prisma.$queryRaw`SELECT 1`;
|
|
19
|
+
return {
|
|
20
|
+
status: 'up',
|
|
21
|
+
responseTime: Date.now() - start,
|
|
22
|
+
};
|
|
23
|
+
} catch (error: any) {
|
|
24
|
+
return {
|
|
25
|
+
status: 'down',
|
|
26
|
+
message: error.message,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create Redis health check function
|
|
34
|
+
*/
|
|
35
|
+
export function createRedisHealthCheck(redis: any) {
|
|
36
|
+
return async (): Promise<ComponentHealth> => {
|
|
37
|
+
const start = Date.now();
|
|
38
|
+
try {
|
|
39
|
+
await redis.ping();
|
|
40
|
+
return {
|
|
41
|
+
status: 'up',
|
|
42
|
+
responseTime: Date.now() - start,
|
|
43
|
+
};
|
|
44
|
+
} catch (error: any) {
|
|
45
|
+
return {
|
|
46
|
+
status: 'down',
|
|
47
|
+
message: error.message,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create gRPC service health check function
|
|
55
|
+
*/
|
|
56
|
+
export function createGrpcHealthCheck(client: any, methodName: string = 'ping') {
|
|
57
|
+
return async (): Promise<ComponentHealth> => {
|
|
58
|
+
const start = Date.now();
|
|
59
|
+
try {
|
|
60
|
+
await client[methodName]({});
|
|
61
|
+
return {
|
|
62
|
+
status: 'up',
|
|
63
|
+
responseTime: Date.now() - start,
|
|
64
|
+
};
|
|
65
|
+
} catch (error: any) {
|
|
66
|
+
return {
|
|
67
|
+
status: 'down',
|
|
68
|
+
message: error.message,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class LoggingClient {
|
|
2
|
+
logInfo(message: string, context?: any) {
|
|
3
|
+
console.log(`[INFO] ${message}`, context || '');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
logWarn(message: string, context?: any) {
|
|
7
|
+
console.warn(`[WARN] ${message}`, context || '');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
logError(message: string, context?: any) {
|
|
11
|
+
console.error(`[ERROR] ${message}`, context || '');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
logUserAction(userId: string, email: string, action: string, resource: string, details?: any) {
|
|
15
|
+
console.log(`[USER_ACTION] ${action} by ${email} (${userId}) on ${resource}`, details || '');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
updateServiceStatus(serviceName: string, status: string, version: string, uptime: number, metadata?: string) {
|
|
19
|
+
console.log(`[SERVICE_STATUS] ${serviceName} is ${status} (v${version}, uptime: ${uptime}s)`, metadata || '');
|
|
20
|
+
}
|
|
21
|
+
}
|