import {z} from 'zod' export type PatchApiChargesChargeUuidCancelProtestArgs = {charge_uuid: string}; export type PatchApiChargesChargeUuidCancelProtestOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiChargesChargeUuidCancelProtestResponse = z.object({uuid: z.string().optional(), charge_uuid: z.string().optional(), number: z.string().optional(), type_protest: z.string().optional(), human_state: z.string().optional(), square_ibge: z.string().optional(), status_certdox: z.string().optional(), grafeno_state_cd: z.string().optional(), debt_identification: z.unknown(), debt_type: z.unknown(), email_status: z.unknown(), deadline_to_desist: z.unknown(), created_at: z.string().optional(), canceled_at: z.string().optional(), deleted_at: z.unknown(), updated_at: z.string().optional(), batch_id: z.unknown(), certdox_errors: z.unknown(), value: z.string().optional(), name: z.string().optional(), document_number: z.string().optional(), account_number_with_dv: z.string().optional(), email_config_kind: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Cancelar protesto de cobrança * * PATCH /charges/{charge_uuid}/cancel_protest */ export const patchApiChargesChargeUuidCancelProtest = async (args: PatchApiChargesChargeUuidCancelProtestArgs, options?: PatchApiChargesChargeUuidCancelProtestOptions) => { 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 (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) if (sec1 !== undefined) headers.set("Authorization", sec1) const url = `${baseUrl.replace(/\/+$/, '')}/charges/${encodeURIComponent(String(args.charge_uuid))}/cancel_protest${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiChargesChargeUuidCancelProtestResponse, await res.json()) };