@fnlb-project/shared 1.4.4 → 1.4.5
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/http/index.js +1 -1
- package/package.json +1 -1
package/dist/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var d;((
|
|
1
|
+
var d;((t)=>{t.GenericUnknown="net.fnlb.errors.generic.unknown";t.GenericInternalError="net.fnlb.errors.generic.internal_error";t.GenericValidationFailed="net.fnlb.errors.generic.validation_failed";t.GenericParseFailed="net.fnlb.errors.generic.parse_failed";t.GenericNotFound="net.fnlb.errors.generic.not_found";t.CommonInvalidRequest="net.fnlb.errors.common.invalid_request";t.CommonUnableToProcessRequest="net.fnlb.errors.common.unable_to_process_request";t.CommonInvalidFieldsLength="net.fnlb.errors.common.invalid_body_fields_length";t.CommonRateLimitExceeded="net.fnlb.errors.common.rate_limit_exceeded";t.CommonUnableToSaveToDatabase="net.fnlb.errors.common.unable_to_save_to_database";t.AuthInvalidToken="net.fnlb.errors.auth.invalid_token";t.AuthInvalidAPIToken="net.fnlb.errors.auth.invalid_api_token";t.AuthInvalidCaptchaToken="net.fnlb.errors.auth.invalid_captcha_token";t.AuthUnauthorized="net.fnlb.errors.auth.unauthorized";t.AuthUserBanned="net.fnlb.errors.auth.user_banned";t.Oauth2InvalidCode="net.fnlb.errors.oauth2.invalid_code";t.Oauth2InvalidScope="net.fnlb.errors.oauth2.invalid_scope";t.Oauth2TokenInvalid="net.fnlb.errors.oauth2.token_invalid";t.Oauth2UnableToFetchUser="net.fnlb.errors.oauth2.unable_to_fetch_user";t.Oauth2UnableToFetchConnections="net.fnlb.errors.oauth2.unable_to_fetch_connections";t.Oauth2UserWithoutConnection="net.fnlb.errors.oauth2.user_without_connection";t.Oauth2ConnectionNotVerified="net.fnlb.errors.oauth2.connection_not_verified";t.ReleaseNotFound="net.fnlb.errors.release.no_release_found";t.ReleaseVersionAlreadyExists="net.fnlb.errors.release.version_already_exists"})(d||={});var p;((u)=>{u.LoginInvalidCredentials="net.fnlb.errors.login.invalid_credentials";u.LoginInvalidEmail="net.fnlb.errors.login.invalid_email";u.LoginInvalidOrUsedEmail="net.fnlb.errors.login.invalid_or_used_email";u.AuthPasswordConfirmationInvalid="net.fnlb.errors.auth.invalid_password_confirmation"})(p||={});var e={...d,...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 l{static getError(n){return o[n]??o[e.GenericUnknown]}static getErrorResponse(n,i){if(Array.isArray(n))return{type:"error",errors:n.map((s)=>l.parseErrorCode(s,i))};else return{type:"error",errors:[l.parseErrorCode(n,i)]}}static parseErrorResponse(n){if(!l.isErrorResponse(n))return null;return n.errors}static isErrorResponse(n){return n?.type==="error"}static parseErrorCode(n,i){let{type:s,message:a}=l.getError(n);if(s==="input"){if(i===void 0)throw new Error("Input is required for Input errors");return{type:s,message:a,errorCode:n,input:i}}else return{type:s,message:a,errorCode:n}}static handleErrors(n,i){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(i),[500,l.getErrorResponse(e.GenericInternalError)];default:return console.error(i),[500,l.getErrorResponse(e.GenericUnknown)]}}}class h{static get(n,i,s,a){return this.request(n,i,s,{...a,method:"GET"})}static post(n,i,s,a){return this.request(n,i,s,{...a,method:"POST"})}static put(n,i,s,a){return this.request(n,i,s,{...a,method:"PUT"})}static patch(n,i,s,a){return this.request(n,i,s,{...a,method:"PATCH"})}static delete(n,i,s,a){return this.request(n,i,s,{...a,method:"DELETE"})}static async request(n,i,s,a){let u={...a,body:a.body?JSON.stringify(a.body):void 0,headers:a.headers??{}};if(s)u.headers.Authorization=s;let c=await fetch(n+i,u);return h.parseResponse(c)}static async parseResponse(n){if(n.headers.get("Content-Type")?.includes("text/plain")){let s=await n.text(),a=l.parseErrorResponse(s);if(a)return{data:void 0,errors:a};return{data:s,errors:void 0}}else{let s=await n.json(),a=l.parseErrorResponse(s);if(a)return{data:void 0,errors:a};return{data:s,errors:void 0}}}}export{h as HTTP};
|