import {z} from 'zod' export type GetApiWorkspacesWorkspaceIdInvoicesArgs = {body: {sort_order?: string | undefined, per_page?: number | undefined, page?: number | undefined, sort_field?: string | undefined}}; export type GetApiWorkspacesWorkspaceIdInvoicesOptions = {baseUrl: string, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const modelsUserInvoiceItem = z.object({amount: z.number().optional(), description: z.string().optional(), item_id: z.number().int().optional(), quantity: z.number().optional()}); export const modelsUserInvoiceTax = z.object({amount: z.number().optional(), name: z.string().optional(), tax_id: z.number().int().optional()}); export const modelsUserInvoice = z.object({billing_address: z.string().optional(), created_at: z.string().optional(), currency: z.string().optional(), date: z.string().optional(), deleted_at: z.string().optional(), document_id: z.string().optional(), due_date: z.string().optional(), items: z.array(modelsUserInvoiceItem).optional(), message: z.string().optional(), payment_terms: z.string().optional(), purchase_number: z.string().optional(), taxes: z.array(modelsUserInvoiceTax).optional(), updated_at: z.string().optional(), user_id: z.number().int().optional(), user_invoice_id: z.number().int().optional(), workspace_address: z.string().optional(), workspace_id: z.number().int().optional(), workspace_logo: z.string().optional()}); export const getApiWorkspacesWorkspaceIdInvoicesResponse = z.array(modelsUserInvoice); 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 }; /** * Get workspace invoices. * * GET /workspaces/{workspace_id}/invoices */ export const getApiWorkspacesWorkspaceIdInvoices = async (args: GetApiWorkspacesWorkspaceIdInvoicesArgs, options: GetApiWorkspacesWorkspaceIdInvoicesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/invoices${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiWorkspacesWorkspaceIdInvoicesResponse, await res.json()) };