import {z} from 'zod' export type ModelsUserInvoiceItem = {amount?: number | undefined, description?: string | undefined, item_id?: number | undefined, quantity?: number | undefined}; export type ModelsUserInvoiceTax = {amount?: number | undefined, name?: string | undefined, tax_id?: number | undefined}; export type ModelsUserInvoice = {billing_address?: string | undefined, created_at?: string | undefined, currency?: string | undefined, date?: string | undefined, deleted_at?: string | undefined, document_id?: string | undefined, due_date?: string | undefined, items?: Array | undefined, message?: string | undefined, payment_terms?: string | undefined, purchase_number?: string | undefined, taxes?: Array | undefined, updated_at?: string | undefined, user_id?: number | undefined, user_invoice_id?: number | undefined, workspace_address?: string | undefined, workspace_id?: number | undefined, workspace_logo?: string | undefined}; export type CreateApiWorkspacesWorkspaceIdInvoicesArgs = {workspace_id: number, body: ModelsUserInvoice}; export type CreateApiWorkspacesWorkspaceIdInvoicesOptions = {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 createApiWorkspacesWorkspaceIdInvoicesResponse = 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 }; /** * Create user invoice * * POST /workspaces/{workspace_id}/invoices */ export const createApiWorkspacesWorkspaceIdInvoices = async (args: CreateApiWorkspacesWorkspaceIdInvoicesArgs, options: CreateApiWorkspacesWorkspaceIdInvoicesOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "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(createApiWorkspacesWorkspaceIdInvoicesResponse, await res.json()) };