export type GetApiUuidArgs = {limit?: number | undefined}; export type GetApiUuidOptions = {baseUrl?: string | undefined, XFungeneratorsApiSecret?: string | undefined, fetch?: typeof fetch | undefined}; /** * Generate a random UUID (v4). * * GET /uuid */ export const getApiUuid = async (args: GetApiUuidArgs, options?: GetApiUuidOptions) => { const {baseUrl = "https://api.fungenerators.com", fetch: fetchFn = fetch, XFungeneratorsApiSecret} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (XFungeneratorsApiSecret !== undefined) headers.set("X-Fungenerators-Api-Secret", XFungeneratorsApiSecret) const url = `${baseUrl.replace(/\/+$/, '')}/uuid${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 (await res.json()) as unknown };