import {z} from 'zod' export type CustomBankBilletsObject = {amount_cents: number, expire_at: string}; export type InstallmentObject = {id?: number | undefined, bank_billet_account_id: number, bank_billet_layout_id?: (number | null) | undefined, amount: number, customer_id?: (number | null) | undefined, customer_person_name: string, customer_cnpj_cpf: string, customer_state: string, customer_city_name: string, customer_zipcode: string, customer_address: string, customer_address_complement?: string | undefined, customer_address_number?: string | undefined, customer_email?: string | undefined, customer_email_cc?: string | undefined, customer_neighborhood: string, customer_phone_number?: string | undefined, customer_ignore_email?: (boolean | null) | undefined, customer_ignore_sms?: (boolean | null) | undefined, customer_mobile_local_code?: (string | null) | undefined, customer_mobile_number?: (string | null) | undefined, customer_nickname?: (string | null) | undefined, customer_notes?: (string | null) | undefined, customer_contact_person?: (string | null) | undefined, customer_update?: (string | null) | undefined, start_at: string, end_at?: (string | null) | undefined, cycle?: ('biweekly' | 'bimonthly' | 'monthly' | 'quarterly' | 'semiannual' | 'annual' | null) | undefined, total: number, custom_bank_billets?: (Array | null) | undefined, bank_billet_ids?: (Array | null) | undefined, interest_type?: (0 | 1 | 2 | null) | undefined, days_for_interest?: (number | null) | undefined, interest_percentage?: (number | null) | undefined, interest_value?: (number | null) | undefined, interest_days_type?: (0 | 1 | null) | undefined, fine_type?: (0 | 1 | 2 | null) | undefined, days_for_fine?: (number | null) | undefined, fine_percentage?: (number | null) | undefined, fine_value?: (number | null) | undefined, discount_type?: (0 | 1 | 2 | null) | undefined, days_for_discount?: (number | null) | undefined, discount_percentage?: (number | null) | undefined, discount_value?: (number | null) | undefined, days_for_second_discount?: (number | null) | undefined, second_discount_percentage?: (number | null) | undefined, second_discount_value?: (number | null) | undefined, days_for_third_discount?: (number | null) | undefined, third_discount_percentage?: (number | null) | undefined, third_discount_value?: (number | null) | undefined, tags?: (Array | null) | undefined, guarantor_name?: (string | null) | undefined, guarantor_cnpj_cpf?: (string | null) | undefined, guarantor_address_number?: (string | null) | undefined, guarantor_neighborhood?: (string | null) | undefined, guarantor_phone_number?: (string | null) | undefined, guarantor_city_name?: (string | null) | undefined, guarantor_state?: (string | null) | undefined, guarantor_zipcode?: (string | null) | undefined, guarantor_address?: (string | null) | undefined, guarantor_address_complement?: (string | null) | undefined, description?: (string | null) | undefined, instructions?: (string | null) | undefined, document_date?: (string | null) | undefined, document_type: '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', document_number?: (string | null) | undefined, days_for_revoke?: (number | null) | undefined, days_for_negativation?: (number | null) | undefined, days_for_sue?: (number | null) | undefined, divergent_payment_type?: ( | 1 | 2 | 3 | 4 | null) | undefined, divergent_payment_value_type?: ( | 1 | 2 | null) | undefined, divergent_payment_maximum_value?: (number | null) | undefined, divergent_payment_minimum_value?: (number | null) | undefined, divergent_payment_maximum_percentage?: (number | null) | undefined, divergent_payment_minimum_percentage?: (number | null) | undefined, divergent_payment_limit?: (number | null) | undefined, prevent_registration?: (boolean | null) | undefined, notes?: (string | null) | undefined, custom_attachment_name?: (string | null) | undefined, created_via_api?: (boolean | null) | undefined, created_at?: (string | null) | undefined, updated_at?: (string | null) | undefined, payment_count?: (number | null) | undefined, url?: (string | null) | undefined, status?: ('created' | 'processed' | 'generated') | undefined, import_id?: (number | null) | undefined, ignore_whatsapp?: (boolean | null) | undefined}; export type CreateApiV1InstallmentsArgs = {'User-Agent'?: string | undefined, 'X-Idempotency-Key'?: string | undefined, body: InstallmentObject}; export type CreateApiV1InstallmentsOptions = {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 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 }; /** * Criar um CarnĂª * * POST /v1/installments */ export const createApiV1Installments = async (args: CreateApiV1InstallmentsArgs, options?: CreateApiV1InstallmentsOptions) => { const {baseUrl = "https://api-sandbox.kobana.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args['X-Idempotency-Key'] != null) headers.set("X-Idempotency-Key", String(args['X-Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/installments${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(installmentObject, await res.json()) };