import {z} from 'zod' export type GetApiV1InstallmentsArgs = {'User-Agent'?: string | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiV1InstallmentsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customBankBilletsObject = z.object({amount_cents: z.number().int(), expire_at: z.string()}); export const installmentObject = z.object({id: z.number().int().optional(), bank_billet_account_id: z.number().int(), bank_billet_layout_id: z.number().int().nullable().optional(), amount: z.number(), customer_id: z.number().int().nullable().optional(), customer_person_name: z.string().max(120), customer_cnpj_cpf: z.string().max(20), customer_state: z.string().max(2), customer_city_name: z.string().max(60), customer_zipcode: z.string().max(8), customer_address: z.string().max(255), customer_address_complement: z.string().max(120).optional(), customer_address_number: z.string().max(10).optional(), customer_email: z.string().max(80).optional(), customer_email_cc: z.string().max(80).optional(), customer_neighborhood: z.string().max(80), customer_phone_number: z.string().max(11).optional(), customer_ignore_email: z.boolean().nullable().optional(), customer_ignore_sms: z.boolean().nullable().optional(), customer_mobile_local_code: z.string().max(2).nullable().optional(), customer_mobile_number: z.string().max(9).nullable().optional(), customer_nickname: z.string().max(255).nullable().optional(), customer_notes: z.string().nullable().optional(), customer_contact_person: z.string().max(120).nullable().optional(), customer_update: z.string().max(120).nullable().optional(), start_at: z.string(), end_at: z.string().nullable().optional(), cycle: z.enum(["biweekly", "bimonthly", "monthly", "quarterly", "semiannual", "annual"]).max(20).nullable().optional(), total: z.number().int().lte(300), custom_bank_billets: z.array(customBankBilletsObject).nullable().optional(), bank_billet_ids: z.array(z.number().int()).nullable().optional(), interest_type: z.union([z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), days_for_interest: z.number().int().nullable().optional(), interest_percentage: z.number().nullable().optional(), interest_value: z.number().nullable().optional(), interest_days_type: z.union([z.literal(0), z.literal(1)]).nullable().optional(), fine_type: z.union([z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), days_for_fine: z.number().int().nullable().optional(), fine_percentage: z.number().nullable().optional(), fine_value: z.number().nullable().optional(), discount_type: z.union([z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), days_for_discount: z.number().int().nullable().optional(), discount_percentage: z.number().nullable().optional(), discount_value: z.number().nullable().optional(), days_for_second_discount: z.number().int().nullable().optional(), second_discount_percentage: z.number().nullable().optional(), second_discount_value: z.number().nullable().optional(), days_for_third_discount: z.number().int().nullable().optional(), third_discount_percentage: z.number().nullable().optional(), third_discount_value: z.number().nullable().optional(), tags: z.array(z.string()).nullable().optional(), guarantor_name: z.string().max(100).nullable().optional(), guarantor_cnpj_cpf: z.string().max(20).nullable().optional(), guarantor_address_number: z.string().max(10).nullable().optional(), guarantor_neighborhood: z.string().max(80).nullable().optional(), guarantor_phone_number: z.string().max(11).nullable().optional(), guarantor_city_name: z.string().max(60).nullable().optional(), guarantor_state: z.string().max(2).nullable().optional(), guarantor_zipcode: z.string().max(8).nullable().optional(), guarantor_address: z.string().max(255).nullable().optional(), guarantor_address_complement: z.string().max(60).nullable().optional(), description: z.string().nullable().optional(), instructions: z.string().nullable().optional(), document_date: z.string().nullable().optional(), document_type: z.enum(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "99"]).max(2), document_number: z.string().nullable().optional(), days_for_revoke: z.number().int().nullable().optional(), days_for_negativation: z.number().int().nullable().optional(), days_for_sue: z.number().int().nullable().optional(), divergent_payment_type: z.union([z.literal(null), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).nullable().optional(), divergent_payment_value_type: z.union([z.literal(null), z.literal(1), z.literal(2)]).nullable().optional(), divergent_payment_maximum_value: z.number().nullable().optional(), divergent_payment_minimum_value: z.number().nullable().optional(), divergent_payment_maximum_percentage: z.number().nullable().optional(), divergent_payment_minimum_percentage: z.number().nullable().optional(), divergent_payment_limit: z.number().int().nullable().optional(), prevent_registration: z.boolean().nullable().optional(), notes: z.string().nullable().optional(), custom_attachment_name: z.string().nullable().optional(), created_via_api: z.boolean().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), payment_count: z.number().int().nullable().optional(), url: z.string().nullable().optional(), status: z.enum(["created", "processed", "generated"]).optional(), import_id: z.number().int().nullable().optional(), ignore_whatsapp: z.boolean().nullable().optional()}); export const getApiV1InstallmentsResponse = z.array(installmentObject); 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 }; /** * Listar CarnĂªs * * GET /v1/installments */ export const getApiV1Installments = async (args: GetApiV1InstallmentsArgs, options?: GetApiV1InstallmentsOptions) => { const {baseUrl = "https://api-sandbox.kobana.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/installments${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 validateResponse(getApiV1InstallmentsResponse, await res.json()) };