export type GetApiWebhooksArgs = {'p[per_page]'?: string | undefined, 'p[page]'?: string | undefined}; export type GetApiWebhooksOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; /** * Listar URLs de notificação cadastradas * * GET /webhooks */ export const getApiWebhooks = async (args: GetApiWebhooksArgs, options?: GetApiWebhooksOptions) => { const {baseUrl = "https://pagamentos.grafeno.be/api/v2", fetch: fetchFn = fetch, sec0, sec1} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['p[per_page]'] != null) query.append("p[per_page]", String(args['p[per_page]'])) if (args['p[page]'] != null) query.append("p[page]", String(args['p[page]'])) if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) if (sec1 !== undefined) headers.set("Authorization", sec1) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks${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 };