@fnlb-project/shared 1.5.5 → 1.5.7

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.
@@ -1 +1 @@
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.AuthForbidden="net.fnlb.errors.auth.forbidden";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 h;((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"})(h||={});var e={...d,...h};var u={[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 lack the necessary authorization to perform this action."},[e.AuthForbidden]:{type:"general",message:"You do not have permission 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 u[n]??u[e.GenericUnknown]}static getErrorResponse(n,i){if(Array.isArray(n))return{type:"error",errors:n.map((t)=>l.parseErrorCode(t,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:t,message:a}=l.getError(n);if(t==="input"){if(i===void 0)throw new Error("Input is required for Input errors");return{type:t,message:a,errorCode:n,input:i}}else return{type:t,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 p{static get(n,i,t,a){return this.request(n,i,t,{...a,method:"GET"})}static post(n,i,t,a){return this.request(n,i,t,{...a,method:"POST"})}static put(n,i,t,a){return this.request(n,i,t,{...a,method:"PUT"})}static patch(n,i,t,a){return this.request(n,i,t,{...a,method:"PATCH"})}static delete(n,i,t,a){return this.request(n,i,t,{...a,method:"DELETE"})}static async request(n,i,t,a){let o={...a,body:a.body?JSON.stringify(a.body):void 0,headers:a.headers??{}};if(t)o.headers.Authorization=t;if(!o.headers["Content-Type"]&&o.body)o.headers["Content-Type"]="application/json";let c=await fetch(n+i,o);return p.parseResponse(c)}static async parseResponse(n){if(n.headers.get("Content-Type")?.includes("text/plain")){let t=await n.text(),a=l.parseErrorResponse(t);if(a)return{data:void 0,errors:a};return{data:t,errors:void 0}}else{let 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};
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.AuthForbidden="net.fnlb.errors.auth.forbidden";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 h;((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"})(h||={});var e={...d,...h};var u={[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 lack the necessary authorization to perform this action."},[e.AuthForbidden]:{type:"general",message:"You do not have permission 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 u[n]??u[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 p{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 o={...a,body:a.body?JSON.stringify(a.body):void 0,headers:a.headers??{}};if(s)o.headers.Authorization=s;if(!o.headers["Content-Type"]&&o.body)o.headers["Content-Type"]="application/json";let c=await fetch(n+i,o);return p.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};if(!n.ok)throw new Error(`Request failed with status code ${n.status}: ${s}`);return{data:s,errors:void 0}}else{let s=await n.json(),a=l.parseErrorResponse(s);if(a)return{data:void 0,errors:a};if(!n.ok)throw new Error(`Request failed with status code ${n.status}: ${JSON.stringify(s,null,2)}`);return{data:s,errors:void 0}}}}export{p as HTTP};
@@ -10,6 +10,17 @@ export declare abstract class AuthUtil {
10
10
  export declare abstract class PromiseUtil {
11
11
  static wait(ms: number): Promise<void>;
12
12
  }
13
+ export declare class TemporalMap<Key, Value> extends Map<Key, {
14
+ handle: Timer;
15
+ value: Value;
16
+ }> {
17
+ private readonly ttl;
18
+ constructor(ttl: number);
19
+ pull(key: Key): Value | undefined;
20
+ push(key: Key, value: Value): this;
21
+ remove(key: Key): boolean;
22
+ modify(key: Key, value: Value): boolean;
23
+ }
13
24
  export declare abstract class TextUtil {
14
25
  static cutText(text: string, maxLength: number, addDots?: boolean): string;
15
26
  }
@@ -1 +1 @@
1
- class s{static encodeToken(n,r){let t=Buffer.from(n,"hex"),e=Buffer.from(r,"hex"),i=Buffer.from([t.length]);return Buffer.concat([new Uint8Array(i),new Uint8Array(t),new Uint8Array(e)]).toString("base64url")}static decodeToken(n){let r=Buffer.from(n,"base64url"),t=r[0];if(!t||t>=r.length)return null;let e=r.subarray(1,1+t).toString("hex"),i=r.subarray(1+t).toString("hex");return{id:e,auth:i}}}class o{static wait(n){return new Promise((r)=>setTimeout(r,n))}}class a{static cutText(n,r,t=!0){return n.length>r?`${n.slice(0,t?Math.max(r-3,0):r)}${t?"...":""}`:n}}export{a as TextUtil,o as PromiseUtil,s as AuthUtil};
1
+ class u{static encodeToken(e,t){let r=Buffer.from(e,"hex"),n=Buffer.from(t,"hex"),i=Buffer.from([r.length]);return Buffer.concat([new Uint8Array(i),new Uint8Array(r),new Uint8Array(n)]).toString("base64url")}static decodeToken(e){let t=Buffer.from(e,"base64url"),r=t[0];if(!r||r>=t.length)return null;let n=t.subarray(1,1+r).toString("hex"),i=t.subarray(1+r).toString("hex");return{id:n,auth:i}}}class s{static wait(e){return new Promise((t)=>setTimeout(t,e))}}class a extends Map{ttl;constructor(e){super();this.ttl=e}pull(e){return super.get(e)?.value}push(e,t){let r=setTimeout(()=>this.delete(e),this.ttl);return super.set(e,{handle:r,value:t})}remove(e){let t=this.get(e);if(t)clearTimeout(t.handle);return super.delete(e)}modify(e,t){let r=super.get(e);if(r)return r.value=t,!0;return!1}}class o{static cutText(e,t,r=!0){return e.length>t?`${e.slice(0,r?Math.max(t-3,0):t)}${r?"...":""}`:e}}export{o as TextUtil,a as TemporalMap,s as PromiseUtil,u as AuthUtil};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fnlb-project/shared",
3
- "version": "1.5.5",
3
+ "version": "1.5.7",
4
4
  "description": "FNLB Shared Library",
5
5
  "files": ["dist"],
6
6
  "author": "FNLB-Project",