@fnlb-project/shared 1.2.1 → 1.3.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.
@@ -214,7 +214,6 @@ export declare abstract class ErrorHandler {
214
214
  static getErrorResponse(errors: ErrorCodes | ErrorCodes[], input?: ErrorInputTypes): IErrorResponse;
215
215
  static parseErrorResponse(error: any): IParsedError[] | null;
216
216
  static isErrorResponse(error?: any): error is IErrorResponse;
217
- static isParsedErrorResponse(error?: any): error is IParsedError[];
218
217
  private static parseErrorCode;
219
218
  static handleErrors(code: string, error: any): [
220
219
  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 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};
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};
@@ -86,13 +86,20 @@ export type RequestOptions = {
86
86
  headers?: Record<string, string>;
87
87
  body?: any;
88
88
  };
89
+ export type ResponseObject<TResponse> = {
90
+ readonly data: undefined;
91
+ readonly errors: IParsedError[];
92
+ } | {
93
+ readonly data: TResponse;
94
+ readonly errors: undefined;
95
+ };
89
96
  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[]>;
97
+ static get<TResponse>(service: string, endpoint: string, token?: string | undefined, options?: Omit<RequestOptions, "method">): Promise<ResponseObject<TResponse>>;
98
+ static post<TResponse>(service: string, endpoint: string, token?: string | undefined, options?: Omit<RequestOptions, "method">): Promise<ResponseObject<TResponse>>;
99
+ static put<TResponse>(service: string, endpoint: string, token?: string | undefined, options?: Omit<RequestOptions, "method">): Promise<ResponseObject<TResponse>>;
100
+ static patch<TResponse>(service: string, endpoint: string, token?: string | undefined, options?: Omit<RequestOptions, "method">): Promise<ResponseObject<TResponse>>;
101
+ static delete<TResponse>(service: string, endpoint: string, token?: string | undefined, options?: Omit<RequestOptions, "method">): Promise<ResponseObject<TResponse>>;
102
+ static request<TResponse>(service: string, endpoint: string, token: string | undefined, options: RequestOptions): Promise<ResponseObject<TResponse>>;
96
103
  private static parseResponse;
97
104
  }
98
105
 
@@ -1 +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};
1
+ var d;((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"})(d||={});var u;((o)=>{o.LoginInvalidCredentials="net.fnlb.errors.login.invalid_credentials";o.LoginInvalidEmail="net.fnlb.errors.login.invalid_email";o.LoginInvalidOrUsedEmail="net.fnlb.errors.login.invalid_or_used_email";o.AuthPasswordConfirmationInvalid="net.fnlb.errors.auth.invalid_password_confirmation"})(u||={});var e={...d,...u};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 l{static getError(n){return m[n]??m[e.GenericUnknown]}static getErrorResponse(n,t){if(Array.isArray(n))return{type:"error",errors:n.map((a)=>l.parseErrorCode(a,t))};else return{type:"error",errors:[l.parseErrorCode(n,t)]}}static parseErrorResponse(n){if(!l.isErrorResponse(n))return null;return n.errors}static isErrorResponse(n){return n?.type==="error"}static parseErrorCode(n,t){const{type:a,message:i}=l.getError(n);if(a==="input"){if(t===void 0)throw new Error("Input is required for Input errors");return{type:a,message:i,errorCode:n,input:t}}else return{type:a,message:i,errorCode:n}}static handleErrors(n,t){switch(n){case"VALIDATION":return[400,l.getErrorResponse(e.GenericValidationFailed)];case"NOT_FOUND":return[404,l.getErrorResponse(e.GenericNotFound)];case"PARSE":return[400,l.getErrorResponse(e.GenericParseFailed)];case"INTERNAL_SERVER_ERROR":return console.error(t),[500,l.getErrorResponse(e.GenericInternalError)];default:return console.error(t),[500,l.getErrorResponse(e.GenericUnknown)]}}}class p{static get(n,t,a,i){return this.request(n,t,a,{...i,method:"GET"})}static post(n,t,a,i){return this.request(n,t,a,{...i,method:"POST"})}static put(n,t,a,i){return this.request(n,t,a,{...i,method:"PUT"})}static patch(n,t,a,i){return this.request(n,t,a,{...i,method:"PATCH"})}static delete(n,t,a,i){return this.request(n,t,a,{...i,method:"DELETE"})}static async request(n,t,a,i){const o={...i,body:i.body?JSON.stringify(i.body):void 0,headers:i.headers??{}};if(a)o.headers.Authorization=a;const h=await fetch(n+t,o);return p.parseResponse(h)}static async parseResponse(n){const t=await n.json(),a=l.parseErrorResponse(t);if(a)return{data:void 0,errors:a};return{data:t,errors:void 0}}}export{p 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.2.1",
4
+ "version": "1.3.0",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "access": "public"