export type CreateApiUuidArgs = {uuidstr: unknown}; export type CreateApiUuidOptions = {baseUrl?: string | undefined, XFungeneratorsApiSecret?: string | undefined, fetch?: typeof fetch | undefined}; /** * Parse a UUID string and return its version and check whether it is valid. * * POST /uuid */ export const createApiUuid = async (args: CreateApiUuidArgs, options?: CreateApiUuidOptions) => { 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.uuidstr != null) query.append("uuidstr", String(args.uuidstr)) 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: "POST", 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 };