// // Typescript API generated from gofiber backend // Copyright (C) 2022 - 2025 Fabio Prada // // This file was generated by github.com/millevolte/ts-rpc // // Mar 15, 2026 16:33:29 UTC // export interface ApiRestResponse { data?: unknown; error: string | null; } function isApiRestResponse(data: unknown): data is ApiRestResponse { return ( typeof data === "object" && data !== null && Object.prototype.hasOwnProperty.call(data, "data") && Object.prototype.hasOwnProperty.call(data, "error") ); } function normalizeError(error: unknown): Error { if (error instanceof DOMException && error.name === "AbortError") { return new Error("api.error.timeouterror"); } if (error instanceof TypeError && error.message === "Failed to fetch") { return new Error("api.error.connectionerror"); } if (error instanceof Error) { return error; } return new Error(String(error)); } export default class Api { apiUrl: string; localStorage: Storage | null; constructor(apiurl: string) { this.apiUrl = apiurl; this.localStorage = window.localStorage; } async request( method: string, url: string, data: unknown, timeout = 7000, upload = false, ): Promise { const headers: { [key: string]: string } = { "Cache-Control": "no-cache", }; if (!upload) { headers["Content-Type"] = "application/json"; } if (this.localStorage) { const auth = this.localStorage.getItem("Auth-Token"); if (auth) { headers["Auth-Token"] = auth; } } const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), timeout); const requestOptions: RequestInit = { method, cache: "no-store", mode: "cors", credentials: "include", headers, signal: controller.signal, }; if (upload) { requestOptions.body = data as FormData; } else if (data !== null && data !== undefined) { requestOptions.body = JSON.stringify(data); } try { const response = await fetch(url, requestOptions); if (!response.ok) { throw new Error("api.error." + response.statusText); } if (this.localStorage) { const jwt = response.headers.get("Auth-Token"); if (jwt) { this.localStorage.setItem("Auth-Token", jwt); } } const responseData = (await response.json()) as unknown; if (!isApiRestResponse(responseData)) { throw new Error("api.error.wrongdatatype"); } if (responseData.error) { throw new Error(responseData.error); } return responseData; } catch (error: unknown) { throw normalizeError(error); } finally { clearTimeout(timeoutId); } } processResult(result: ApiRestResponse): { data: unknown; error: string | null; } { if (typeof result.data !== "object") { return { data: result.data, error: null }; } if (!result.data) { result.data = {}; } return { data: result.data, error: null }; } processError(error: unknown): { data: unknown; error: string | null; } { const normalizedError = normalizeError(error); if (normalizedError.message === "api.error.timeouterror") { Object.defineProperty(normalizedError, "__api_error__", { value: normalizedError.message, writable: false, }); return { data: null, error: normalizedError.message }; } if (normalizedError.message === "api.error.connectionerror") { Object.defineProperty(normalizedError, "__api_error__", { value: normalizedError.message, writable: false, }); return { data: null, error: normalizedError.message }; } return { data: null, error: normalizedError.message, }; } async POST( url: string, data: unknown, timeout?: number, ): Promise<{ data: unknown; error: string | null; }> { try { const upload = url.includes("/upload/"); const result = await this.request( "POST", this.apiUrl + url, data, timeout, upload, ); return this.processResult(result); } catch (error: unknown) { return this.processError(error); } } async GET( url: string, timeout?: number, ): Promise<{ data: unknown; error: string | null; }> { try { const result = await this.request( "GET", this.apiUrl + url, null, timeout, ); return this.processResult(result); } catch (error: unknown) { return this.processError(error); } } async UPLOAD( url: string, data: unknown, timeout?: number, ): Promise<{ data: unknown; error: string | null; }> { try { const result = await this.request( "POST", this.apiUrl + url, data, timeout, true, ); return this.processResult(result); } catch (error: unknown) { return this.processError(error); } } } const api = new Api("http://localhost:3000"); // Global Declarations export type Nullable = T | null; export type Record = { [P in K]: T }; // // package controllers // export interface LoginRequest { username: string; password: string; } export interface RefreshRequest { refresh_token: string; } export interface SimpleResponse { message: string; } export interface ForgotPasswordRequest { email: string; } export interface ResetPasswordRequest { token: string; password: string; } export interface ListUsersRequest { page: number; pageSize: number; } // // package models // export interface UserPreferencesShort { useIdle: boolean; idleTimeout: number; useIdlePassword: boolean; idlePin: string; useDirectLogin: boolean; useQuadcodeLogin: boolean; sendNoticesMail: boolean; language: string; } export interface UserShort { email: string; name: string; roles: UserRoles; status: UserStatus; uuid: string; details: Nullable; preferences: Nullable; avatar: Nullable; } export interface UserCreateInput { name: string; email: string; password: string; roles: UserRoles; status: UserStatus; types: UserTypes; avatar: Nullable; details: Nullable; preferences: Nullable; } export interface UserDetailsShort { title: string; firstName: string; lastName: string; address: string; city: string; zipCode: string; country: string; phone: string; } export type UserRoles = string[]; export type UserStatus = (typeof EnumUserStatus)[keyof typeof EnumUserStatus]; export type UserTypes = string[]; export type UsersShort = UserShort[]; export const EnumUserStatus = { UserStatusPending: "pending", UserStatusActive: "active", UserStatusDisabled: "disabled", } as const; // // package routes // // Typescript: TSEndpoint= path=/auth/password/valid; name=validToken; method=POST; request=string; response=controllers.SimpleResponse // internal/http/routes/auth_routes.go Line: 40 export const validToken = async ( data: string, ): Promise<{ data: SimpleResponse; error: Nullable }> => { return (await api.POST("/auth/password/valid", data)) as { data: SimpleResponse; error: Nullable; }; }; // Typescript: TSEndpoint= path=/maildebug; name=mailDebug; method=GET; response=routes.[]MailDebugItem // internal/http/routes/system_routes.go Line: 48 export const mailDebug = async (): Promise<{ data: MailDebugItem[]; error: Nullable; }> => { return (await api.GET("/maildebug")) as { data: MailDebugItem[]; error: Nullable; }; }; // Typescript: TSEndpoint= path=/admin/users; name=listUsers; method=POST; request=controllers.ListUsersRequest; response=models.[]UserShort // internal/http/routes/admin_routes.go Line: 12 export const listUsers = async ( data: ListUsersRequest, ): Promise<{ data: UserShort[]; error: Nullable }> => { return (await api.POST("/admin/users", data)) as { data: UserShort[]; error: Nullable; }; }; // Typescript: TSEndpoint= path=/auth/register; name=register; method=POST; request=models.UserCreateInput; response=models.UserShort // internal/http/routes/auth_routes.go Line: 31 export const register = async ( data: UserCreateInput, ): Promise<{ data: UserShort; error: Nullable }> => { return (await api.POST("/auth/register", data)) as { data: UserShort; error: Nullable; }; }; // Typescript: TSEndpoint= path=/metrics; name=metrics; method=GET; response=string // internal/http/routes/system_routes.go Line: 37 export const metrics = async (): Promise<{ data: string; error: Nullable; }> => { return (await api.GET("/metrics")) as { data: string; error: Nullable; }; }; // Typescript: TSEndpoint= path=/auth/login; name=login; method=POST; request=controllers.LoginRequest; response=auth.TokenPair // internal/http/routes/auth_routes.go Line: 22 export const login = async ( data: LoginRequest, ): Promise<{ data: TokenPair; error: Nullable }> => { return (await api.POST("/auth/login", data)) as { data: TokenPair; error: Nullable; }; }; // Typescript: TSEndpoint= path=/auth/refresh; name=refresh; method=POST; request=controllers.RefreshRequest; response=auth.TokenPair // internal/http/routes/auth_routes.go Line: 25 export const refresh = async ( data: RefreshRequest, ): Promise<{ data: TokenPair; error: Nullable }> => { return (await api.POST("/auth/refresh", data)) as { data: TokenPair; error: Nullable; }; }; // Typescript: TSEndpoint= path=/auth/password/forgot; name=forgotPassword; method=POST; request=controllers.ForgotPasswordRequest; response=controllers.SimpleResponse // internal/http/routes/auth_routes.go Line: 34 export const forgotPassword = async ( data: ForgotPasswordRequest, ): Promise<{ data: SimpleResponse; error: Nullable }> => { return (await api.POST("/auth/password/forgot", data)) as { data: SimpleResponse; error: Nullable; }; }; // Typescript: TSEndpoint= path=/auth/password/reset; name=resetPassword; method=POST; request=controllers.ResetPasswordRequest; response=controllers.SimpleResponse // internal/http/routes/auth_routes.go Line: 37 export const resetPassword = async ( data: ResetPasswordRequest, ): Promise<{ data: SimpleResponse; error: Nullable }> => { return (await api.POST("/auth/password/reset", data)) as { data: SimpleResponse; error: Nullable; }; }; // Typescript: TSEndpoint= path=/health; name=health; method=GET; response=string // internal/http/routes/system_routes.go Line: 34 export const health = async (): Promise<{ data: string; error: Nullable; }> => { return (await api.GET("/health")) as { data: string; error: Nullable; }; }; // Typescript: TSEndpoint= path=/auth/me; name=me; method=GET; response=models.UserShort // internal/http/routes/auth_routes.go Line: 28 export const me = async (): Promise<{ data: UserShort; error: Nullable; }> => { return (await api.GET("/auth/me")) as { data: UserShort; error: Nullable; }; }; export interface FormRequest { req: string; count: number; } export interface FormResponse { test: string; } export interface MailDebugItem { name: string; content: string; } // // package auth // export interface TokenPair { access_token: string; refresh_token: string; }