@gzl10/nexus-backend 0.18.0 → 0.19.1
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/app-error-CKbYJQ9V.d.ts +136 -0
- package/dist/cli.js +531 -288
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -135
- package/dist/index.js +632 -147
- package/dist/index.js.map +1 -1
- package/dist/main.js +632 -147
- package/dist/main.js.map +1 -1
- package/dist/migration-helpers/index.d.ts +63 -0
- package/dist/migration-helpers/index.js +12116 -0
- package/dist/migration-helpers/index.js.map +1 -0
- package/dist/testing/index.d.ts +81 -0
- package/dist/testing/index.js +1675 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +17 -3
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for i18n-friendly error handling.
|
|
3
|
+
* Frontend translates these codes to localized messages.
|
|
4
|
+
*
|
|
5
|
+
* Format: CATEGORY_ACTION_REASON
|
|
6
|
+
*
|
|
7
|
+
* Categories: AUTH, USER, ROLE, VALIDATION, STORAGE, PERMISSION, RESOURCE, SYSTEM
|
|
8
|
+
*/
|
|
9
|
+
declare const ErrorCodes: {
|
|
10
|
+
readonly AUTH_INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS";
|
|
11
|
+
readonly AUTH_TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED";
|
|
12
|
+
readonly AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID";
|
|
13
|
+
readonly AUTH_TOKEN_REQUIRED: "AUTH_TOKEN_REQUIRED";
|
|
14
|
+
readonly AUTH_OTP_REQUIRED: "AUTH_OTP_REQUIRED";
|
|
15
|
+
readonly AUTH_OTP_INVALID: "AUTH_OTP_INVALID";
|
|
16
|
+
readonly AUTH_REFRESH_TOKEN_REQUIRED: "AUTH_REFRESH_TOKEN_REQUIRED";
|
|
17
|
+
readonly AUTH_REFRESH_TOKEN_INVALID: "AUTH_REFRESH_TOKEN_INVALID";
|
|
18
|
+
readonly AUTH_REFRESH_TOKEN_EXPIRED: "AUTH_REFRESH_TOKEN_EXPIRED";
|
|
19
|
+
readonly AUTH_SESSION_NOT_FOUND: "AUTH_SESSION_NOT_FOUND";
|
|
20
|
+
readonly AUTH_SESSION_SELF_REVOKE: "AUTH_SESSION_SELF_REVOKE";
|
|
21
|
+
readonly AUTH_VERIFICATION_CODE_INVALID: "AUTH_VERIFICATION_CODE_INVALID";
|
|
22
|
+
readonly AUTH_REGISTRATION_DISABLED: "AUTH_REGISTRATION_DISABLED";
|
|
23
|
+
readonly AUTH_AUTO_CREATE_DISABLED: "AUTH_AUTO_CREATE_DISABLED";
|
|
24
|
+
readonly USER_NOT_FOUND: "USER_NOT_FOUND";
|
|
25
|
+
readonly USER_EMAIL_EXISTS: "USER_EMAIL_EXISTS";
|
|
26
|
+
readonly USER_NOT_AUTHENTICATED: "USER_NOT_AUTHENTICATED";
|
|
27
|
+
readonly ROLE_NOT_FOUND: "ROLE_NOT_FOUND";
|
|
28
|
+
readonly ROLE_NAME_EXISTS: "ROLE_NAME_EXISTS";
|
|
29
|
+
readonly ROLE_SYSTEM_PROTECTED: "ROLE_SYSTEM_PROTECTED";
|
|
30
|
+
readonly ROLE_HAS_USERS: "ROLE_HAS_USERS";
|
|
31
|
+
readonly ROLE_DEFAULT_NOT_FOUND: "ROLE_DEFAULT_NOT_FOUND";
|
|
32
|
+
readonly PERMISSION_DENIED: "PERMISSION_DENIED";
|
|
33
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
34
|
+
readonly VALIDATION_FIELD_REQUIRED: "VALIDATION_FIELD_REQUIRED";
|
|
35
|
+
readonly VALIDATION_FIELD_INVALID: "VALIDATION_FIELD_INVALID";
|
|
36
|
+
readonly VALIDATION_JSON_MALFORMED: "VALIDATION_JSON_MALFORMED";
|
|
37
|
+
readonly STORAGE_FILE_NOT_FOUND: "STORAGE_FILE_NOT_FOUND";
|
|
38
|
+
readonly STORAGE_FILE_TOO_LARGE: "STORAGE_FILE_TOO_LARGE";
|
|
39
|
+
readonly STORAGE_FILE_TYPE_NOT_ALLOWED: "STORAGE_FILE_TYPE_NOT_ALLOWED";
|
|
40
|
+
readonly STORAGE_PAYLOAD_TOO_LARGE: "STORAGE_PAYLOAD_TOO_LARGE";
|
|
41
|
+
readonly RESOURCE_NOT_FOUND: "RESOURCE_NOT_FOUND";
|
|
42
|
+
readonly RESOURCE_CONFLICT: "RESOURCE_CONFLICT";
|
|
43
|
+
readonly RESOURCE_CREATE_NOT_SUPPORTED: "RESOURCE_CREATE_NOT_SUPPORTED";
|
|
44
|
+
readonly RESOURCE_UPDATE_NOT_SUPPORTED: "RESOURCE_UPDATE_NOT_SUPPORTED";
|
|
45
|
+
readonly RESOURCE_DELETE_NOT_SUPPORTED: "RESOURCE_DELETE_NOT_SUPPORTED";
|
|
46
|
+
readonly MODULE_NOT_FOUND: "MODULE_NOT_FOUND";
|
|
47
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
48
|
+
readonly AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED";
|
|
49
|
+
readonly DB_CONSTRAINT_UNIQUE: "DB_CONSTRAINT_UNIQUE";
|
|
50
|
+
readonly DB_CONSTRAINT_FK: "DB_CONSTRAINT_FK";
|
|
51
|
+
readonly DB_CONNECTION_ERROR: "DB_CONNECTION_ERROR";
|
|
52
|
+
readonly DATABASE_NOT_READY: "DATABASE_NOT_READY";
|
|
53
|
+
readonly SYSTEM_INTERNAL_ERROR: "SYSTEM_INTERNAL_ERROR";
|
|
54
|
+
};
|
|
55
|
+
type ErrorCode = typeof ErrorCodes[keyof typeof ErrorCodes];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Parameters for creating an AppError with i18n support
|
|
59
|
+
*/
|
|
60
|
+
interface AppErrorParams {
|
|
61
|
+
/** Error code for i18n translation (e.g., 'AUTH_INVALID_CREDENTIALS') */
|
|
62
|
+
code: ErrorCode;
|
|
63
|
+
/** Fallback message in English (used if frontend doesn't have translation) */
|
|
64
|
+
message?: string;
|
|
65
|
+
/** Interpolation values for the translated message (e.g., { resource: 'User' }) */
|
|
66
|
+
interpolation?: Record<string, string | number>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Base application error with i18n support.
|
|
70
|
+
*
|
|
71
|
+
* Can be created with:
|
|
72
|
+
* - String message (legacy, backward compatible)
|
|
73
|
+
* - AppErrorParams object (new, with code and interpolation)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Legacy usage
|
|
77
|
+
* throw new AppError('Something went wrong', 400)
|
|
78
|
+
*
|
|
79
|
+
* // New usage with i18n
|
|
80
|
+
* throw new AppError({
|
|
81
|
+
* code: ErrorCodes.USER_NOT_FOUND,
|
|
82
|
+
* message: 'User not found',
|
|
83
|
+
* interpolation: { resource: 'User' }
|
|
84
|
+
* }, 404)
|
|
85
|
+
*/
|
|
86
|
+
declare class AppError extends Error {
|
|
87
|
+
readonly statusCode: number;
|
|
88
|
+
readonly code: ErrorCode;
|
|
89
|
+
readonly interpolation?: Record<string, string | number>;
|
|
90
|
+
readonly details?: unknown;
|
|
91
|
+
constructor(params: AppErrorParams | string, statusCode?: number, details?: unknown);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resource not found error (404)
|
|
95
|
+
*/
|
|
96
|
+
declare class NotFoundError extends AppError {
|
|
97
|
+
constructor(resource?: string);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Authentication required error (401)
|
|
101
|
+
*/
|
|
102
|
+
declare class UnauthorizedError extends AppError {
|
|
103
|
+
constructor(codeOrMessage?: ErrorCode | string, message?: string);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Access denied error (403)
|
|
107
|
+
*/
|
|
108
|
+
declare class ForbiddenError extends AppError {
|
|
109
|
+
constructor(codeOrMessage?: ErrorCode | string, message?: string);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Resource conflict error (409)
|
|
113
|
+
*/
|
|
114
|
+
declare class ConflictError extends AppError {
|
|
115
|
+
constructor(codeOrMessage?: ErrorCode | string, message?: string);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Standard validation error detail
|
|
119
|
+
*/
|
|
120
|
+
interface ValidationDetail {
|
|
121
|
+
path: string;
|
|
122
|
+
message: string;
|
|
123
|
+
/** Error code for i18n translation */
|
|
124
|
+
code?: string;
|
|
125
|
+
/** Interpolation values */
|
|
126
|
+
interpolation?: Record<string, string | number>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Validation error with field-level details (400)
|
|
130
|
+
*/
|
|
131
|
+
declare class ValidationError extends AppError {
|
|
132
|
+
readonly details: ValidationDetail[];
|
|
133
|
+
constructor(messageOrCode?: string | ErrorCode, details?: ValidationDetail[]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { AppError as A, ConflictError as C, ErrorCodes as E, ForbiddenError as F, NotFoundError as N, UnauthorizedError as U, ValidationError as V, type AppErrorParams as a, type ErrorCode as b, type ValidationDetail as c };
|