@fnlb-project/shared 1.1.2 → 1.2.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.
@@ -213,7 +213,8 @@ export declare abstract class ErrorHandler {
213
213
  static getError<T extends ErrorCodes>(error: T): (typeof errorMap)[T];
214
214
  static getErrorResponse(errors: ErrorCodes | ErrorCodes[], input?: ErrorInputTypes): IErrorResponse;
215
215
  static parseErrorResponse(error: any): IParsedError[] | null;
216
- static isErrorResponse(error?: IErrorResponse): error is IErrorResponse;
216
+ static isErrorResponse(error?: any): error is IErrorResponse;
217
+ static isParsedErrorResponse(error?: any): error is IParsedError[];
217
218
  private static parseErrorCode;
218
219
  static handleErrors(code: string, error: any): [
219
220
  number,
@@ -1 +1 @@
1
- var d;((a)=>{a.GenericUnknown="net.fnlb.errors.generic.unknown";a.GenericInternalError="net.fnlb.errors.generic.internal_error";a.GenericValidationFailed="net.fnlb.errors.generic.validation_failed";a.GenericParseFailed="net.fnlb.errors.generic.parse_failed";a.GenericNotFound="net.fnlb.errors.generic.not_found";a.CommonInvalidRequest="net.fnlb.errors.common.invalid_request";a.CommonUnableToProcessRequest="net.fnlb.errors.common.unable_to_process_request";a.CommonInvalidFieldsLength="net.fnlb.errors.common.invalid_body_fields_length";a.CommonRateLimitExceeded="net.fnlb.errors.common.rate_limit_exceeded";a.CommonUnableToSaveToDatabase="net.fnlb.errors.common.unable_to_save_to_database";a.AuthInvalidToken="net.fnlb.errors.auth.invalid_token";a.AuthInvalidAPIToken="net.fnlb.errors.auth.invalid_api_token";a.AuthInvalidCaptchaToken="net.fnlb.errors.auth.invalid_captcha_token";a.AuthUnauthorized="net.fnlb.errors.auth.unauthorized";a.AuthUserBanned="net.fnlb.errors.auth.user_banned";a.Oauth2InvalidCode="net.fnlb.errors.oauth2.invalid_code";a.Oauth2InvalidScope="net.fnlb.errors.oauth2.invalid_scope";a.Oauth2TokenInvalid="net.fnlb.errors.oauth2.token_invalid";a.Oauth2UnableToFetchUser="net.fnlb.errors.oauth2.unable_to_fetch_user";a.Oauth2UnableToFetchConnections="net.fnlb.errors.oauth2.unable_to_fetch_connections";a.Oauth2UserWithoutConnection="net.fnlb.errors.oauth2.user_without_connection";a.Oauth2ConnectionNotVerified="net.fnlb.errors.oauth2.connection_not_verified";a.ReleaseNotFound="net.fnlb.errors.release.no_release_found";a.ReleaseVersionAlreadyExists="net.fnlb.errors.release.version_already_exists"})(d||={});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={...d,...h};var m={[e.GenericUnknown]:{type:"general",message:"An unknown error occurred. Please try again later."},[e.GenericInternalError]:{type:"general",message:"An internal error occurred. Please try again later."},[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 later."},[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 connections. Please try again later."},[e.Oauth2UserWithoutConnection]:{type:"general",message:"No connections found. Please add a connection and try again later."},[e.Oauth2ConnectionNotVerified]:{type:"general",message:"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(n){return m[n]??m[e.GenericUnknown]}static getErrorResponse(n,t){if(Array.isArray(n))return{type:"error",errors:n.map((l)=>s.parseErrorCode(l,t))};else return{type:"error",errors:[s.parseErrorCode(n,t)]}}static parseErrorResponse(n){if(!s.isErrorResponse(n))return null;return n.errors}static isErrorResponse(n){return n?.type==="error"}static parseErrorCode(n,t){const{type:l,message:u}=s.getError(n);if(l==="input"){if(t===void 0)throw new Error("Input is required for Input errors");return{type:l,message:u,errorCode:n,input:t}}else return{type:l,message:u,errorCode:n}}static handleErrors(n,t){switch(n){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};
1
+ var d;((a)=>{a.GenericUnknown="net.fnlb.errors.generic.unknown";a.GenericInternalError="net.fnlb.errors.generic.internal_error";a.GenericValidationFailed="net.fnlb.errors.generic.validation_failed";a.GenericParseFailed="net.fnlb.errors.generic.parse_failed";a.GenericNotFound="net.fnlb.errors.generic.not_found";a.CommonInvalidRequest="net.fnlb.errors.common.invalid_request";a.CommonUnableToProcessRequest="net.fnlb.errors.common.unable_to_process_request";a.CommonInvalidFieldsLength="net.fnlb.errors.common.invalid_body_fields_length";a.CommonRateLimitExceeded="net.fnlb.errors.common.rate_limit_exceeded";a.CommonUnableToSaveToDatabase="net.fnlb.errors.common.unable_to_save_to_database";a.AuthInvalidToken="net.fnlb.errors.auth.invalid_token";a.AuthInvalidAPIToken="net.fnlb.errors.auth.invalid_api_token";a.AuthInvalidCaptchaToken="net.fnlb.errors.auth.invalid_captcha_token";a.AuthUnauthorized="net.fnlb.errors.auth.unauthorized";a.AuthUserBanned="net.fnlb.errors.auth.user_banned";a.Oauth2InvalidCode="net.fnlb.errors.oauth2.invalid_code";a.Oauth2InvalidScope="net.fnlb.errors.oauth2.invalid_scope";a.Oauth2TokenInvalid="net.fnlb.errors.oauth2.token_invalid";a.Oauth2UnableToFetchUser="net.fnlb.errors.oauth2.unable_to_fetch_user";a.Oauth2UnableToFetchConnections="net.fnlb.errors.oauth2.unable_to_fetch_connections";a.Oauth2UserWithoutConnection="net.fnlb.errors.oauth2.user_without_connection";a.Oauth2ConnectionNotVerified="net.fnlb.errors.oauth2.connection_not_verified";a.ReleaseNotFound="net.fnlb.errors.release.no_release_found";a.ReleaseVersionAlreadyExists="net.fnlb.errors.release.version_already_exists"})(d||={});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={...d,...h};var m={[e.GenericUnknown]:{type:"general",message:"An unknown error occurred. Please try again later."},[e.GenericInternalError]:{type:"general",message:"An internal error occurred. Please try again later."},[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 later."},[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 connections. Please try again later."},[e.Oauth2UserWithoutConnection]:{type:"general",message:"No connections found. Please add a connection and try again later."},[e.Oauth2ConnectionNotVerified]:{type:"general",message:"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(n){return m[n]??m[e.GenericUnknown]}static getErrorResponse(n,t){if(Array.isArray(n))return{type:"error",errors:n.map((l)=>s.parseErrorCode(l,t))};else return{type:"error",errors:[s.parseErrorCode(n,t)]}}static parseErrorResponse(n){if(!s.isErrorResponse(n))return null;return n.errors}static isErrorResponse(n){return n?.type==="error"}static isParsedErrorResponse(n){return n?.[0]?.type==="error"}static parseErrorCode(n,t){const{type:l,message:u}=s.getError(n);if(l==="input"){if(t===void 0)throw new Error("Input is required for Input errors");return{type:l,message:u,errorCode:n,input:t}}else return{type:l,message:u,errorCode:n}}static handleErrors(n,t){switch(n){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};
@@ -0,0 +1,99 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ declare enum GeneralErrorCodes {
4
+ GenericUnknown = "net.fnlb.errors.generic.unknown",
5
+ GenericInternalError = "net.fnlb.errors.generic.internal_error",
6
+ GenericValidationFailed = "net.fnlb.errors.generic.validation_failed",
7
+ GenericParseFailed = "net.fnlb.errors.generic.parse_failed",
8
+ GenericNotFound = "net.fnlb.errors.generic.not_found",
9
+ CommonInvalidRequest = "net.fnlb.errors.common.invalid_request",
10
+ CommonUnableToProcessRequest = "net.fnlb.errors.common.unable_to_process_request",
11
+ CommonInvalidFieldsLength = "net.fnlb.errors.common.invalid_body_fields_length",
12
+ CommonRateLimitExceeded = "net.fnlb.errors.common.rate_limit_exceeded",
13
+ CommonUnableToSaveToDatabase = "net.fnlb.errors.common.unable_to_save_to_database",
14
+ AuthInvalidToken = "net.fnlb.errors.auth.invalid_token",
15
+ AuthInvalidAPIToken = "net.fnlb.errors.auth.invalid_api_token",
16
+ AuthInvalidCaptchaToken = "net.fnlb.errors.auth.invalid_captcha_token",
17
+ AuthUnauthorized = "net.fnlb.errors.auth.unauthorized",
18
+ AuthUserBanned = "net.fnlb.errors.auth.user_banned",
19
+ Oauth2InvalidCode = "net.fnlb.errors.oauth2.invalid_code",
20
+ Oauth2InvalidScope = "net.fnlb.errors.oauth2.invalid_scope",
21
+ Oauth2TokenInvalid = "net.fnlb.errors.oauth2.token_invalid",
22
+ Oauth2UnableToFetchUser = "net.fnlb.errors.oauth2.unable_to_fetch_user",
23
+ Oauth2UnableToFetchConnections = "net.fnlb.errors.oauth2.unable_to_fetch_connections",
24
+ Oauth2UserWithoutConnection = "net.fnlb.errors.oauth2.user_without_connection",
25
+ Oauth2ConnectionNotVerified = "net.fnlb.errors.oauth2.connection_not_verified",
26
+ ReleaseNotFound = "net.fnlb.errors.release.no_release_found",
27
+ ReleaseVersionAlreadyExists = "net.fnlb.errors.release.version_already_exists"
28
+ }
29
+ declare enum InputErrorCodes {
30
+ LoginInvalidCredentials = "net.fnlb.errors.login.invalid_credentials",
31
+ LoginInvalidEmail = "net.fnlb.errors.login.invalid_email",
32
+ LoginInvalidOrUsedEmail = "net.fnlb.errors.login.invalid_or_used_email",
33
+ AuthPasswordConfirmationInvalid = "net.fnlb.errors.auth.invalid_password_confirmation"
34
+ }
35
+ export type ErrorCodes = GeneralErrorCodes | InputErrorCodes;
36
+ declare const ErrorCodes: {
37
+ readonly LoginInvalidCredentials: InputErrorCodes.LoginInvalidCredentials;
38
+ readonly LoginInvalidEmail: InputErrorCodes.LoginInvalidEmail;
39
+ readonly LoginInvalidOrUsedEmail: InputErrorCodes.LoginInvalidOrUsedEmail;
40
+ readonly AuthPasswordConfirmationInvalid: InputErrorCodes.AuthPasswordConfirmationInvalid;
41
+ readonly GenericUnknown: GeneralErrorCodes.GenericUnknown;
42
+ readonly GenericInternalError: GeneralErrorCodes.GenericInternalError;
43
+ readonly GenericValidationFailed: GeneralErrorCodes.GenericValidationFailed;
44
+ readonly GenericParseFailed: GeneralErrorCodes.GenericParseFailed;
45
+ readonly GenericNotFound: GeneralErrorCodes.GenericNotFound;
46
+ readonly CommonInvalidRequest: GeneralErrorCodes.CommonInvalidRequest;
47
+ readonly CommonUnableToProcessRequest: GeneralErrorCodes.CommonUnableToProcessRequest;
48
+ readonly CommonInvalidFieldsLength: GeneralErrorCodes.CommonInvalidFieldsLength;
49
+ readonly CommonRateLimitExceeded: GeneralErrorCodes.CommonRateLimitExceeded;
50
+ readonly CommonUnableToSaveToDatabase: GeneralErrorCodes.CommonUnableToSaveToDatabase;
51
+ readonly AuthInvalidToken: GeneralErrorCodes.AuthInvalidToken;
52
+ readonly AuthInvalidAPIToken: GeneralErrorCodes.AuthInvalidAPIToken;
53
+ readonly AuthInvalidCaptchaToken: GeneralErrorCodes.AuthInvalidCaptchaToken;
54
+ readonly AuthUnauthorized: GeneralErrorCodes.AuthUnauthorized;
55
+ readonly AuthUserBanned: GeneralErrorCodes.AuthUserBanned;
56
+ readonly Oauth2InvalidCode: GeneralErrorCodes.Oauth2InvalidCode;
57
+ readonly Oauth2InvalidScope: GeneralErrorCodes.Oauth2InvalidScope;
58
+ readonly Oauth2TokenInvalid: GeneralErrorCodes.Oauth2TokenInvalid;
59
+ readonly Oauth2UnableToFetchUser: GeneralErrorCodes.Oauth2UnableToFetchUser;
60
+ readonly Oauth2UnableToFetchConnections: GeneralErrorCodes.Oauth2UnableToFetchConnections;
61
+ readonly Oauth2UserWithoutConnection: GeneralErrorCodes.Oauth2UserWithoutConnection;
62
+ readonly Oauth2ConnectionNotVerified: GeneralErrorCodes.Oauth2ConnectionNotVerified;
63
+ readonly ReleaseNotFound: GeneralErrorCodes.ReleaseNotFound;
64
+ readonly ReleaseVersionAlreadyExists: GeneralErrorCodes.ReleaseVersionAlreadyExists;
65
+ };
66
+ declare enum ErrorInputTypes {
67
+ Username = "username",
68
+ Email = "email",
69
+ Password = "password",
70
+ Shared = "shared"
71
+ }
72
+ declare enum ErrorTypes {
73
+ General = "general",
74
+ Input = "input"
75
+ }
76
+ export interface IBaseError {
77
+ message: string;
78
+ errorCode: ErrorCodes;
79
+ type: ErrorTypes;
80
+ }
81
+ export interface IParsedError extends IBaseError {
82
+ input?: ErrorInputTypes;
83
+ }
84
+ export type RequestOptions = {
85
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
86
+ headers?: Record<string, string>;
87
+ body?: any;
88
+ };
89
+ export declare abstract class HTTP {
90
+ static get<TResponse>(service: string, endpoint: string, options?: Omit<RequestOptions, "method">): Promise<TResponse | IParsedError[]>;
91
+ static post<TResponse>(service: string, endpoint: string, options?: Omit<RequestOptions, "method">): Promise<TResponse | IParsedError[]>;
92
+ static put<TResponse>(service: string, endpoint: string, options?: Omit<RequestOptions, "method">): Promise<TResponse | IParsedError[]>;
93
+ static patch<TResponse>(service: string, endpoint: string, options?: Omit<RequestOptions, "method">): Promise<TResponse | IParsedError[]>;
94
+ static delete<TResponse>(service: string, endpoint: string, options?: Omit<RequestOptions, "method">): Promise<TResponse | IParsedError[]>;
95
+ static fetch<TResponse>(service: string, endpoint: string, options: RequestOptions): Promise<TResponse | IParsedError[]>;
96
+ private static parseResponse;
97
+ }
98
+
99
+ export {};
@@ -0,0 +1 @@
1
+ var h;((s)=>{s.GenericUnknown="net.fnlb.errors.generic.unknown";s.GenericInternalError="net.fnlb.errors.generic.internal_error";s.GenericValidationFailed="net.fnlb.errors.generic.validation_failed";s.GenericParseFailed="net.fnlb.errors.generic.parse_failed";s.GenericNotFound="net.fnlb.errors.generic.not_found";s.CommonInvalidRequest="net.fnlb.errors.common.invalid_request";s.CommonUnableToProcessRequest="net.fnlb.errors.common.unable_to_process_request";s.CommonInvalidFieldsLength="net.fnlb.errors.common.invalid_body_fields_length";s.CommonRateLimitExceeded="net.fnlb.errors.common.rate_limit_exceeded";s.CommonUnableToSaveToDatabase="net.fnlb.errors.common.unable_to_save_to_database";s.AuthInvalidToken="net.fnlb.errors.auth.invalid_token";s.AuthInvalidAPIToken="net.fnlb.errors.auth.invalid_api_token";s.AuthInvalidCaptchaToken="net.fnlb.errors.auth.invalid_captcha_token";s.AuthUnauthorized="net.fnlb.errors.auth.unauthorized";s.AuthUserBanned="net.fnlb.errors.auth.user_banned";s.Oauth2InvalidCode="net.fnlb.errors.oauth2.invalid_code";s.Oauth2InvalidScope="net.fnlb.errors.oauth2.invalid_scope";s.Oauth2TokenInvalid="net.fnlb.errors.oauth2.token_invalid";s.Oauth2UnableToFetchUser="net.fnlb.errors.oauth2.unable_to_fetch_user";s.Oauth2UnableToFetchConnections="net.fnlb.errors.oauth2.unable_to_fetch_connections";s.Oauth2UserWithoutConnection="net.fnlb.errors.oauth2.user_without_connection";s.Oauth2ConnectionNotVerified="net.fnlb.errors.oauth2.connection_not_verified";s.ReleaseNotFound="net.fnlb.errors.release.no_release_found";s.ReleaseVersionAlreadyExists="net.fnlb.errors.release.version_already_exists"})(h||={});var p;((l)=>{l.LoginInvalidCredentials="net.fnlb.errors.login.invalid_credentials";l.LoginInvalidEmail="net.fnlb.errors.login.invalid_email";l.LoginInvalidOrUsedEmail="net.fnlb.errors.login.invalid_or_used_email";l.AuthPasswordConfirmationInvalid="net.fnlb.errors.auth.invalid_password_confirmation"})(p||={});var e={...h,...p};var o={[e.GenericUnknown]:{type:"general",message:"An unknown error occurred. Please try again later."},[e.GenericInternalError]:{type:"general",message:"An internal error occurred. Please try again later."},[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 later."},[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 connections. Please try again later."},[e.Oauth2UserWithoutConnection]:{type:"general",message:"No connections found. Please add a connection and try again later."},[e.Oauth2ConnectionNotVerified]:{type:"general",message:"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 i{static getError(n){return o[n]??o[e.GenericUnknown]}static getErrorResponse(n,a){if(Array.isArray(n))return{type:"error",errors:n.map((t)=>i.parseErrorCode(t,a))};else return{type:"error",errors:[i.parseErrorCode(n,a)]}}static parseErrorResponse(n){if(!i.isErrorResponse(n))return null;return n.errors}static isErrorResponse(n){return n?.type==="error"}static isParsedErrorResponse(n){return n?.[0]?.type==="error"}static parseErrorCode(n,a){const{type:t,message:m}=i.getError(n);if(t==="input"){if(a===void 0)throw new Error("Input is required for Input errors");return{type:t,message:m,errorCode:n,input:a}}else return{type:t,message:m,errorCode:n}}static handleErrors(n,a){switch(n){case"VALIDATION":return[400,i.getErrorResponse(e.GenericValidationFailed)];case"NOT_FOUND":return[404,i.getErrorResponse(e.GenericNotFound)];case"PARSE":return[400,i.getErrorResponse(e.GenericParseFailed)];case"INTERNAL_SERVER_ERROR":return console.error(a),[500,i.getErrorResponse(e.GenericInternalError)];default:return console.error(a),[500,i.getErrorResponse(e.GenericUnknown)]}}}class u{static get(n,a,t){return this.fetch(n,a,{...t,method:"GET"})}static post(n,a,t){return this.fetch(n,a,{...t,method:"POST"})}static put(n,a,t){return this.fetch(n,a,{...t,method:"PUT"})}static patch(n,a,t){return this.fetch(n,a,{...t,method:"PATCH"})}static delete(n,a,t){return this.fetch(n,a,{...t,method:"DELETE"})}static async fetch(n,a,t){const m={...t,body:JSON.stringify(t.body),headers:t.headers},l=await fetch(n+a,m);return u.parseResponse(l)}static parseResponse(n){if(n.headers.get("Content-Type")?.startsWith("application/json")){const t=n.json();return i.parseErrorResponse(t)??t}throw new Error("Unknown response type")}}export{u as HTTP};
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.1.2",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -21,6 +21,10 @@
21
21
  "types": "./dist/errors/index.d.ts",
22
22
  "default": "./dist/errors/index.js"
23
23
  },
24
+ "./http": {
25
+ "types": "./dist/http/index.d.ts",
26
+ "default": "./dist/http/index.js"
27
+ },
24
28
  "./types": {
25
29
  "types": "./dist/types/index.d.ts",
26
30
  "default": "./dist/types/index.js"