initial commit

This commit is contained in:
2025-08-01 21:42:02 +02:00
commit 69da9f42d4
25 changed files with 659 additions and 0 deletions

37
src/api/ezpp.ts Normal file
View File

@@ -0,0 +1,37 @@
import { type Method, createFetch } from '@better-fetch/fetch';
import type { HeadersInit } from 'bun';
const apiClient = createFetch({
baseURL: 'https://api.ez-pp.farm/',
throw: true,
});
export type ApiResponse<T> = { data: T; error: undefined } | { data: undefined; error: Error };
export const fetchApi = async <T>(
route: string,
options?: {
query?: Record<string, unknown>;
headers?: HeadersInit;
method?: Method;
params?: Record<string, unknown>;
timeout?: number;
signal?: AbortSignal;
}
): Promise<ApiResponse<T>> => {
try {
const data = await apiClient<T>(route, {
query: options?.query,
headers: options?.headers ?? {
accept: 'application/json',
},
method: options?.method ?? 'GET',
params: options?.params,
timeout: options?.timeout,
signal: options?.signal,
});
return { data, error: undefined };
} catch (err) {
return { data: undefined, error: err as Error };
}
};