export type GetApiHistoryArgs = {action?: ('create' | 'update' | 'delete') | undefined, type: unknown, search: unknown, limit?: number | undefined, page?: number | undefined, order?: ('id' | 'created_at' | 'action') | undefined, order_dir?: ('asc' | 'desc') | undefined}; export type GetApiHistoryOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Display a listing of entries * * GET /history */ export const getApiHistory = async (args: GetApiHistoryArgs, options?: GetApiHistoryOptions) => { const {baseUrl = "https://www.rcac.purdue.edu/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.action != null) query.append("action", String(args.action)) if (args.type != null) query.append("type", String(args.type)) if (args.search != null) query.append("search", String(args.search)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args.order != null) query.append("order", String(args.order)) if (args.order_dir != null) query.append("order_dir", String(args.order_dir)) const url = `${baseUrl.replace(/\/+$/, '')}/history${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };