import {z} from 'zod' export type GetApiV1InvoicesInvoicePeriodArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, invoice_period: string, page?: number | undefined, per?: number | undefined, company_uuids?: string | undefined}; export type GetApiV1InvoicesInvoicePeriodOptions = {baseUrl?: string | undefined, SystemAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceData = z.object({active_companies: z.array(z.object({company_uuid: z.string().optional(), active_employees: z.number().int().optional(), active_contractors: z.number().int().optional(), initial_invoice_period: z.string().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 }; /** * Retrieve invoicing data for companies * * GET /v1/invoices/{invoice_period} */ export const getApiV1InvoicesInvoicePeriod = async (args: GetApiV1InvoicesInvoicePeriodArgs, options?: GetApiV1InvoicesInvoicePeriodOptions) => { const {baseUrl = "https://api.gusto-demo.com", fetch: fetchFn = fetch, SystemAccessAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Gusto-API-Version'] != null) headers.set("X-Gusto-API-Version", String(args['X-Gusto-API-Version'])) if (args.page != null) query.append("page", String(args.page)) if (args.per != null) query.append("per", String(args.per)) if (args.company_uuids != null) query.append("company_uuids", String(args.company_uuids)) if (SystemAccessAuth !== undefined) headers.set('authorization', `Bearer ${SystemAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/invoices/${encodeURIComponent(String(args.invoice_period))}${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(invoiceData, await res.json()) };