export type GetApiNetlifyFunctionsGenerateQrArgs = {value: string, format?: ('svg' | 'png' | 'jpg' | 'webp' | 'pdf' | 'eps') | undefined, size?: number | undefined, margin?: number | undefined, bgColor?: string | undefined, fgColor?: string | undefined, errorCorrectionLevel?: ('L' | 'M' | 'Q' | 'H') | undefined, logo?: (string | null) | undefined}; export type GetApiNetlifyFunctionsGenerateQrOptions = {baseUrl?: string | undefined, AgentApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download a QR code asset via Netlify Function * * GET /.netlify/functions/generate-qr */ export const getApiNetlifyFunctionsGenerateQr = async (args: GetApiNetlifyFunctionsGenerateQrArgs, options?: GetApiNetlifyFunctionsGenerateQrOptions) => { const {baseUrl = "https://qrcodecrafter.com", fetch: fetchFn = fetch, AgentApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/svg+xml") if (args.value != null) query.append("value", String(args.value)) if (args.format != null) query.append("format", String(args.format)) if (args.size != null) query.append("size", String(args.size)) if (args.margin != null) query.append("margin", String(args.margin)) if (args.bgColor != null) query.append("bgColor", String(args.bgColor)) if (args.fgColor != null) query.append("fgColor", String(args.fgColor)) if (args.errorCorrectionLevel != null) query.append("errorCorrectionLevel", String(args.errorCorrectionLevel)) if (args.logo != null) query.append("logo", String(args.logo)) if (AgentApiKey !== undefined) headers.set("X-Agent-Api-Key", AgentApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/.netlify/functions/generate-qr${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 res.blob() };