export type GetApiHandsArgs = {cards?: Array | undefined}; export type GetApiHandsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * GET /hands */ export const getApiHands = async (args: GetApiHandsArgs, options: GetApiHandsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() for (const item of args.cards ?? []) query.append("cards", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/hands${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 };