@fnlb-project/shared 1.0.7 → 1.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/dist/errors/index.d.ts +36 -0
- package/dist/errors/index.js +1 -1
- package/dist/types/index.d.ts +40 -0
- package/package.json +2 -2
package/dist/errors/index.d.ts
CHANGED
|
@@ -63,10 +63,38 @@ declare const ErrorCodes: {
|
|
|
63
63
|
readonly ReleaseNotFound: GeneralErrorCodes.ReleaseNotFound;
|
|
64
64
|
readonly ReleaseVersionAlreadyExists: GeneralErrorCodes.ReleaseVersionAlreadyExists;
|
|
65
65
|
};
|
|
66
|
+
declare enum ErrorInputTypes {
|
|
67
|
+
Username = "username",
|
|
68
|
+
Email = "email",
|
|
69
|
+
Password = "password",
|
|
70
|
+
Shared = "shared"
|
|
71
|
+
}
|
|
66
72
|
declare enum ErrorTypes {
|
|
67
73
|
General = "general",
|
|
68
74
|
Input = "input"
|
|
69
75
|
}
|
|
76
|
+
export interface IBaseError {
|
|
77
|
+
message: string;
|
|
78
|
+
errorCode: ErrorCodes;
|
|
79
|
+
type: ErrorTypes;
|
|
80
|
+
}
|
|
81
|
+
export interface IGeneralError extends IBaseError {
|
|
82
|
+
errorCode: GeneralErrorCodes;
|
|
83
|
+
type: ErrorTypes.General;
|
|
84
|
+
}
|
|
85
|
+
export interface IInputError extends IBaseError {
|
|
86
|
+
errorCode: InputErrorCodes;
|
|
87
|
+
type: ErrorTypes.Input;
|
|
88
|
+
input: ErrorInputTypes;
|
|
89
|
+
}
|
|
90
|
+
export type IError = IInputError | IGeneralError;
|
|
91
|
+
export interface IErrorResponse {
|
|
92
|
+
type: "error";
|
|
93
|
+
errors: IError[];
|
|
94
|
+
}
|
|
95
|
+
export interface IParsedError extends IBaseError {
|
|
96
|
+
input?: ErrorInputTypes;
|
|
97
|
+
}
|
|
70
98
|
declare const errorMap: {
|
|
71
99
|
readonly "net.fnlb.errors.generic.unknown": {
|
|
72
100
|
readonly type: ErrorTypes.General;
|
|
@@ -183,6 +211,14 @@ declare const errorMap: {
|
|
|
183
211
|
};
|
|
184
212
|
export declare abstract class ErrorHandler {
|
|
185
213
|
static getError<T extends ErrorCodes>(error: T): (typeof errorMap)[T];
|
|
214
|
+
static getErrorResponse(errors: ErrorCodes | ErrorCodes[], input?: ErrorInputTypes): IErrorResponse;
|
|
215
|
+
static parseErrorResponse(error: any): IParsedError[] | null;
|
|
216
|
+
static isErrorResponse(error?: IErrorResponse): error is IErrorResponse;
|
|
217
|
+
private static parseErrorCode;
|
|
218
|
+
static handleErrors(code: string, error: any): [
|
|
219
|
+
number,
|
|
220
|
+
IErrorResponse
|
|
221
|
+
];
|
|
186
222
|
}
|
|
187
223
|
|
|
188
224
|
export {};
|
package/dist/errors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u;((n)=>{n.GenericUnknown="net.fnlb.errors.generic.unknown";n.GenericInternalError="net.fnlb.errors.generic.internal_error";n.GenericValidationFailed="net.fnlb.errors.generic.validation_failed";n.GenericParseFailed="net.fnlb.errors.generic.parse_failed";n.GenericNotFound="net.fnlb.errors.generic.not_found";n.CommonInvalidRequest="net.fnlb.errors.common.invalid_request";n.CommonUnableToProcessRequest="net.fnlb.errors.common.unable_to_process_request";n.CommonInvalidFieldsLength="net.fnlb.errors.common.invalid_body_fields_length";n.CommonRateLimitExceeded="net.fnlb.errors.common.rate_limit_exceeded";n.CommonUnableToSaveToDatabase="net.fnlb.errors.common.unable_to_save_to_database";n.AuthInvalidToken="net.fnlb.errors.auth.invalid_token";n.AuthInvalidAPIToken="net.fnlb.errors.auth.invalid_api_token";n.AuthInvalidCaptchaToken="net.fnlb.errors.auth.invalid_captcha_token";n.AuthUnauthorized="net.fnlb.errors.auth.unauthorized";n.AuthUserBanned="net.fnlb.errors.auth.user_banned";n.Oauth2InvalidCode="net.fnlb.errors.oauth2.invalid_code";n.Oauth2InvalidScope="net.fnlb.errors.oauth2.invalid_scope";n.Oauth2TokenInvalid="net.fnlb.errors.oauth2.token_invalid";n.Oauth2UnableToFetchUser="net.fnlb.errors.oauth2.unable_to_fetch_user";n.Oauth2UnableToFetchConnections="net.fnlb.errors.oauth2.unable_to_fetch_connections";n.Oauth2UserWithoutConnection="net.fnlb.errors.oauth2.user_without_connection";n.Oauth2ConnectionNotVerified="net.fnlb.errors.oauth2.connection_not_verified";n.ReleaseNotFound="net.fnlb.errors.release.no_release_found";n.ReleaseVersionAlreadyExists="net.fnlb.errors.release.version_already_exists"})(u||={});var h;((i)=>{i.LoginInvalidCredentials="net.fnlb.errors.login.invalid_credentials";i.LoginInvalidEmail="net.fnlb.errors.login.invalid_email";i.LoginInvalidOrUsedEmail="net.fnlb.errors.login.invalid_or_used_email";i.AuthPasswordConfirmationInvalid="net.fnlb.errors.auth.invalid_password_confirmation"})(h||={});var e={...u,...h};var d={[e.GenericUnknown]:{type:"general",message:"An unknown error occurred. This may be due to an unexpected condition in the server."},[e.GenericInternalError]:{type:"general",message:"An internal server error occurred. This may be due to an unhandled exception. Please try again."},[e.GenericValidationFailed]:{type:"general",message:"Validation of the request data failed."},[e.GenericParseFailed]:{type:"general",message:"The request could not be parsed. This may be due to a malformed input or an unsupported data format."},[e.GenericNotFound]:{type:"general",message:"The requested resource does not exist."},[e.CommonInvalidRequest]:{type:"general",message:"The request is not valid."},[e.CommonUnableToProcessRequest]:{type:"general",message:"Unable to process the request. Please try again."},[e.CommonInvalidFieldsLength]:{type:"general",message:"The body fields have an invalid length."},[e.CommonRateLimitExceeded]:{type:"general",message:"You are being rate limited."},[e.CommonUnableToSaveToDatabase]:{type:"general",message:"Unable to save changes. Please check all fields."},[e.AuthInvalidToken]:{type:"general",message:"Invalid token provided."},[e.AuthInvalidAPIToken]:{type:"general",message:"Invalid API token provided."},[e.AuthInvalidCaptchaToken]:{type:"general",message:"Sorry, the captcha was not resolved correctly. Please try again."},[e.AuthUnauthorized]:{type:"general",message:"You are not authorized to perform this action."},[e.AuthUserBanned]:{type:"general",message:"Your account is banned from the service."},[e.AuthPasswordConfirmationInvalid]:{type:"input",message:"Sorry, the password is invalid or does not match."},[e.LoginInvalidCredentials]:{type:"input",message:"The email or password is incorrect."},[e.LoginInvalidEmail]:{type:"input",message:"The email is invalid."},[e.LoginInvalidOrUsedEmail]:{type:"input",message:"The email is invalid or is already used."},[e.Oauth2InvalidCode]:{type:"general",message:"Unable to verify your request at this moment. Please try again later."},[e.Oauth2InvalidScope]:{type:"general",message:"Invalid scope provided."},[e.Oauth2TokenInvalid]:{type:"general",message:"Unable to verify Oauth2 token. Please try again later."},[e.Oauth2UnableToFetchUser]:{type:"general",message:"Unable to obtain user information. Please try again later."},[e.Oauth2UnableToFetchConnections]:{type:"general",message:"Unable to obtain user connections. Please try again later."},[e.Oauth2UserWithoutConnection]:{type:"general",message:"User does not have connections. Please try again later."},[e.Oauth2ConnectionNotVerified]:{type:"general",message:"User does have a connection, but the connection is not verified. Please try again later."},[e.ReleaseNotFound]:{type:"general",message:"Sorry, no release found. Please try again later."},[e.ReleaseVersionAlreadyExists]:{type:"general",message:"Release version already exists."}};class s{static getError(a){return d[a]}static getErrorResponse(a,t){if(Array.isArray(a))return{type:"error",errors:a.map((l)=>s.parseErrorCode(l,t))};else return{type:"error",errors:[s.parseErrorCode(a,t)]}}static parseErrorResponse(a){if(!s.isErrorResponse(a))return null;return a.errors}static isErrorResponse(a){return a?.type==="error"}static parseErrorCode(a,t){const{type:l,message:m}=s.getError(a);if(l==="input"){if(t===void 0)throw new Error("Input is required for Input errors");return{type:l,message:m,errorCode:a,input:t}}else return{type:l,message:m,errorCode:a}}static handleErrors(a,t){switch(a){case"VALIDATION":return[400,s.getErrorResponse(e.GenericValidationFailed)];case"NOT_FOUND":return[404,s.getErrorResponse(e.GenericNotFound)];case"PARSE":return[400,s.getErrorResponse(e.GenericParseFailed)];case"INTERNAL_SERVER_ERROR":return console.error(t),[500,s.getErrorResponse(e.GenericInternalError)];default:return console.error(t),[500,s.getErrorResponse(e.GenericUnknown)]}}}export{s as ErrorHandler};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -129,6 +129,24 @@ export declare enum Locales {
|
|
|
129
129
|
Pt = "pt",
|
|
130
130
|
Tr = "tr"
|
|
131
131
|
}
|
|
132
|
+
export type ConnectionSchema = {
|
|
133
|
+
id?: string;
|
|
134
|
+
username?: string;
|
|
135
|
+
};
|
|
136
|
+
export interface IClientAccount {
|
|
137
|
+
user: {
|
|
138
|
+
id: string;
|
|
139
|
+
username: string;
|
|
140
|
+
email: string;
|
|
141
|
+
apiToken: string;
|
|
142
|
+
connections?: {
|
|
143
|
+
discord?: ConnectionSchema;
|
|
144
|
+
epic?: ConnectionSchema;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
bots?: IDBBot[];
|
|
148
|
+
categories?: IDBCategory[];
|
|
149
|
+
}
|
|
132
150
|
export interface IDBBot {
|
|
133
151
|
id: string;
|
|
134
152
|
owner: string;
|
|
@@ -296,6 +314,28 @@ export interface IDBCategory {
|
|
|
296
314
|
}
|
|
297
315
|
export interface ICategory extends IDBCategory {
|
|
298
316
|
}
|
|
317
|
+
export interface IBaseError {
|
|
318
|
+
message: string;
|
|
319
|
+
errorCode: ErrorCodes;
|
|
320
|
+
type: ErrorTypes;
|
|
321
|
+
}
|
|
322
|
+
export interface IGeneralError extends IBaseError {
|
|
323
|
+
errorCode: GeneralErrorCodes;
|
|
324
|
+
type: ErrorTypes.General;
|
|
325
|
+
}
|
|
326
|
+
export interface IInputError extends IBaseError {
|
|
327
|
+
errorCode: InputErrorCodes;
|
|
328
|
+
type: ErrorTypes.Input;
|
|
329
|
+
input: ErrorInputTypes;
|
|
330
|
+
}
|
|
331
|
+
export type IError = IInputError | IGeneralError;
|
|
332
|
+
export interface IErrorResponse {
|
|
333
|
+
type: "error";
|
|
334
|
+
errors: IError[];
|
|
335
|
+
}
|
|
336
|
+
export interface IParsedError extends IBaseError {
|
|
337
|
+
input?: ErrorInputTypes;
|
|
338
|
+
}
|
|
299
339
|
export interface IDBUser {
|
|
300
340
|
id: string;
|
|
301
341
|
token: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnlb-project/shared",
|
|
3
3
|
"description": "FNLB Shared Library",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@biomejs/biome": "^1.8.3",
|
|
35
35
|
"@types/bun": "^1.1.6",
|
|
36
36
|
"bun-plugin-dts": "^0.2.3",
|
|
37
|
-
"typescript": "^5.5.
|
|
37
|
+
"typescript": "^5.5.4"
|
|
38
38
|
},
|
|
39
39
|
"packageManager": "bun@1.1.17"
|
|
40
40
|
}
|