import {z} from 'zod' export type Partner = number; export type BusinessUnit = number; export type TaxNumber = string; export type StartDate = string; export type EndDate = string; export type PageIndex = number; export type PageSize = number; export type CreateApiGetRefundPixOutByDateArgs = {body: {Method: string, PartnerId: Partner, BusinessUnitId: BusinessUnit, TaxNumber: TaxNumber, StartDate: StartDate, EndDate: EndDate, PageIndex?: PageIndex | undefined, PageSize?: PageSize | undefined}}; export type CreateApiGetRefundPixOutByDateOptions = {baseUrl?: string | undefined, BASE64UsernamePassword?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiGetRefundPixOutByDateResponse = z.object({Success: z.string().min(1).optional(), Message: z.string().min(1).optional(), RefundPixOutList: z.array(z.object({DocumentNumber: z.number().optional(), EndToEndId: z.string().optional(), RefundCode: z.string().min(1).optional(), PixOutIdentifier: z.string().optional(), RefundValue: z.string().optional(), RefundDate: z.string().min(1).optional(), CustomerMessage: z.string().min(1).optional(), DrawerName: z.string().min(1).optional(), DrawerTaxNumber: z.string().min(1).optional(), DrawerISPB: z.string().min(1).optional(), DrawerBankCode: z.string().min(1).optional(), DrawerBankBranch: z.string().min(1).optional(), DrawerBankAccount: z.string().min(1).optional(), DrawerBankAccountDigit: z.string().min(1).optional(), DraweeName: z.string().min(1).optional(), DraweeTaxNumber: z.string().min(1).optional(), DraweeISPB: z.string().min(1).optional(), DraweeBankCode: z.string().min(1).optional(), DraweeBankBranch: z.string().min(1).optional(), DraweeBankAccount: z.string().min(1).optional(), DraweeBankAccountDigit: z.string().min(1).optional(), InitiationEndToEndId: z.string().optional(), InitiationDocument: z.string().optional()})).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 }; /** * GetRefundPixOutByDate * * POST /GetRefundPixOutByDate */ export const createApiGetRefundPixOutByDate = async (args: CreateApiGetRefundPixOutByDateArgs, options?: CreateApiGetRefundPixOutByDateOptions) => { const {baseUrl = "https://sandboxapi.fitbank.com.br/main/execute", fetch: fetchFn = fetch, BASE64UsernamePassword} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BASE64UsernamePassword !== undefined) headers.set('authorization', `Basic ${btoa(`${BASE64UsernamePassword.username}:${BASE64UsernamePassword.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/GetRefundPixOutByDate${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 validateResponse(createApiGetRefundPixOutByDateResponse, await res.json()) };