import {z} from 'zod' export type GetApiV1EventsArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, starting_after_uuid?: string | undefined, resource_uuid?: string | undefined, limit?: string | undefined, event_type?: string | undefined, sort_order?: ('asc' | 'desc') | undefined}; export type GetApiV1EventsOptions = {baseUrl?: string | undefined, SystemAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const event = z.object({uuid: z.string(), event_type: z.string().optional(), resource_type: z.literal("Company").optional(), resource_uuid: z.string().optional(), entity_type: z.string().optional(), entity_uuid: z.string().optional(), timestamp: z.number().int().optional()}); export const eventList = z.array(event); 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 all events * * GET /v1/events */ export const getApiV1Events = async (args: GetApiV1EventsArgs, options?: GetApiV1EventsOptions) => { 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.starting_after_uuid != null) query.append("starting_after_uuid", String(args.starting_after_uuid)) if (args.resource_uuid != null) query.append("resource_uuid", String(args.resource_uuid)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.event_type != null) query.append("event_type", String(args.event_type)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (SystemAccessAuth !== undefined) headers.set('authorization', `Bearer ${SystemAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/events${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(eventList, await res.json()) };