export type CreateApiWebhooksV2Args = {tokenAPI: string, cryptKey: string, body: {type: string, uuid: string, url: string}}; export type CreateApiWebhooksV2Options = {baseUrl?: string | undefined, sec0?: string | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; /** * Cadastrar ou Atualizar uma URL de Webhook (2.0) * * POST /webhooks/v2/ */ export const createApiWebhooksV2 = async (args: CreateApiWebhooksV2Args, options?: CreateApiWebhooksV2Options) => { const {baseUrl = "https://sandbox.d4sign.com.br/api/v1", fetch: fetchFn = fetch, sec0, sec1} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.tokenAPI != null) query.append("tokenAPI", String(args.tokenAPI)) if (args.cryptKey != null) query.append("cryptKey", String(args.cryptKey)) if (sec0 !== undefined) query.set("tokenAPI", sec0) if (sec1 !== undefined) query.set("cryptKey", sec1) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/v2/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };