import {z} from 'zod' export type CreateApiNetworksBillingsAffiliatesInvoicestableArgs = {page?: number | undefined, page_size?: number | undefined, body: {search_terms?: Array<{search_type: 'name', value: string}> | undefined, filters?: ({network_affiliate_ids?: Array | undefined, network_affiliate_invoice_ids?: Array | undefined, account_manager_ids?: Array | undefined, min_start_time?: string | undefined, max_end_time?: string | undefined, min_balance?: number | undefined, max_balance?: number | undefined, affiliate_invoice_status?: ('paid' | 'unpaid' | 'deleted') | undefined, is_hidden_affiliate?: ('visible' | 'hidden') | undefined, payment_terms?: Array | undefined}) | undefined}}; export type CreateApiNetworksBillingsAffiliatesInvoicestableOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiNetworksBillingsAffiliatesInvoicestableResponse = z.object({invoices: z.array(z.object({network_affiliate_invoice_id: z.number().int().optional(), network_id: z.number().int().optional(), network_affiliate_id: z.number().int().optional(), network_affiliate_name: z.string().optional(), affiliate_invoice_status: z.enum(["paid", "unpaid", "deleted"]).optional(), start_time: z.string().optional(), end_time: z.string().optional(), timezone_id: z.number().int().optional(), balance: z.number().optional(), billed: z.number().optional(), paid: z.number().optional(), currency_id: z.string().optional(), payment_terms: z.number().int().optional(), is_hidden_affiliate: z.boolean().optional(), public_notes: z.string().optional(), internal_notes: z.string().optional(), payment_type: z.string().optional(), is_payable: z.boolean().optional(), payment_status: z.string().optional(), paid_date: z.number().int().optional(), time_created: z.number().int().optional(), time_saved: z.number().int().optional()})).optional(), paging: z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total_count: z.number().int().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 }; /** * Find Partner Invoices (Advanced) * * POST /networks/billings/affiliates/invoicestable */ export const createApiNetworksBillingsAffiliatesInvoicestable = async (args: CreateApiNetworksBillingsAffiliatesInvoicestableArgs, options?: CreateApiNetworksBillingsAffiliatesInvoicestableOptions) => { const {baseUrl = "https://api.eflow.team/v1", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (APIKey !== undefined) headers.set("X-Eflow-Api-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/networks/billings/affiliates/invoicestable${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(createApiNetworksBillingsAffiliatesInvoicestableResponse, await res.json()) };