import {z} from 'zod' export type GetApiV1GarnishmentsGarnishmentIdArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, garnishment_id: string}; export type GetApiV1GarnishmentsGarnishmentIdOptions = {baseUrl?: string | undefined, CompanyAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const garnishmentChildSupport = z.object({state: z.string().optional(), payment_period: z.enum(["Every week", "Every other week", "Twice per month", "Monthly"]).optional(), fips_code: z.string().optional(), case_number: z.string().nullable().optional(), order_number: z.string().nullable().optional(), remittance_number: z.string().nullable().optional()}).nullable(); export const garnishment = z.object({uuid: z.string(), version: z.string().optional(), employee_uuid: z.string().optional(), active: z.boolean().optional(), amount: z.string().optional(), description: z.string().optional(), court_ordered: z.boolean().optional(), times: z.number().int().nullable().optional(), recurring: z.boolean().optional(), annual_maximum: z.string().nullable().optional(), total_amount: z.string().nullable().optional(), pay_period_maximum: z.string().nullable().optional(), deduct_as_percentage: z.boolean().optional(), garnishment_type: z.enum(["child_support", "federal_tax_lien", "state_tax_lien", "student_loan", "creditor_garnishment", "federal_loan", "other_garnishment"]).nullable().optional(), child_support: garnishmentChildSupport.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 garnishment * * GET /v1/garnishments/{garnishment_id} */ export const getApiV1GarnishmentsGarnishmentId = async (args: GetApiV1GarnishmentsGarnishmentIdArgs, options?: GetApiV1GarnishmentsGarnishmentIdOptions) => { const {baseUrl = "https://api.gusto-demo.com", fetch: fetchFn = fetch, CompanyAccessAuth} = 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 (CompanyAccessAuth !== undefined) headers.set('authorization', `Bearer ${CompanyAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/garnishments/${encodeURIComponent(String(args.garnishment_id))}${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(garnishment, await res.json()) };