import {z} from 'zod' export type GetApiV1PayrollDigestsPayrollDigestUuidArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, payroll_digest_uuid: string}; export type GetApiV1PayrollDigestsPayrollDigestUuidOptions = {baseUrl?: string | undefined, SystemAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const payrollDigestResults = z.object({uuid: z.string(), idempotency_key: z.string(), status: z.enum(["pending", "processing", "completed", "failed"]), submitted_at: z.string(), completed_at: z.string().nullable().optional(), submitted_items: z.number().int().nullable().optional(), processed_items: z.number().int().optional(), excluded_items: z.number().int().optional(), results: z.array(z.object({idx: z.number().int().optional(), entity_type: z.literal("company").optional(), uuid: z.string().optional(), name: z.string().optional(), status: z.enum(["success", "partial_success", "failed"]).optional(), blockers: z.array(z.object({type: z.string().optional(), description: z.string().optional()})).optional(), payrolls: z.array(z.object({payroll_uuid: z.string().nullable().optional(), payroll_type: z.string().optional(), display_title: z.string().optional(), auto_payroll: z.boolean().optional(), status: z.string().optional(), pay_period: z.object({start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), check_date: z.string().nullable().optional(), run_payroll_by: z.string().nullable().optional()}).optional(), pay_schedule: z.object({uuid: z.string().optional(), frequency: z.string().optional(), custom_name: z.string().nullable().optional()}).nullable().optional(), totals: z.object({total_debit_amount: z.string().optional(), net_pay: z.string().optional(), total_employer_cost: z.string().optional()}).nullable().optional()})).optional()})).optional(), exclusions: z.array(z.object({idx: z.number().int().optional(), entity_type: z.literal("company").optional(), uuid: z.string().optional(), status: z.literal("failed").optional(), category: z.enum(["not_found", "company_inactive", "duplicate", "internal_error"]).optional(), message: 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 }; /** * Get a payroll digest batch * * GET /v1/payroll_digests/{payroll_digest_uuid} */ export const getApiV1PayrollDigestsPayrollDigestUuid = async (args: GetApiV1PayrollDigestsPayrollDigestUuidArgs, options?: GetApiV1PayrollDigestsPayrollDigestUuidOptions) => { 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 (SystemAccessAuth !== undefined) headers.set('authorization', `Bearer ${SystemAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/payroll_digests/${encodeURIComponent(String(args.payroll_digest_uuid))}${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(payrollDigestResults, await res.json()) };