import {z} from 'zod' export type GetApiV1CompanyBenefitsCompanyBenefitIdArgs = {'X-Gusto-API-Version'?: '2026-06-15' | undefined, company_benefit_id: string, with_employee_benefits?: boolean | undefined, include?: 'all_benefits' | undefined}; export type GetApiV1CompanyBenefitsCompanyBenefitIdOptions = {baseUrl?: string | undefined, CompanyAccessAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const companyBenefitWithEmployeeBenefits = z.object({version: z.string().optional(), company_uuid: z.string().optional(), uuid: z.string(), benefit_type: z.number().int().optional(), active: z.boolean().optional(), description: z.string().min(1).optional(), source: z.enum(["internal", "external", "partnered"]).optional(), partner_name: z.string().nullable().optional(), deletable: z.boolean().optional(), supports_percentage_amounts: z.boolean().optional(), responsible_for_employer_taxes: z.boolean().optional(), responsible_for_employee_w2: z.boolean().optional(), catch_up_type: z.enum(["elective", "deemed"]).nullable().optional(), employee_benefits: z.array(z.object({employee_uuid: z.string().optional(), company_benefit_uuid: z.string().optional(), active: z.boolean().optional(), deduct_as_percentage: z.boolean().optional(), employee_deduction: z.string().optional(), company_contribution: z.string().optional(), effective_date: z.string().optional(), expiration_date: z.string().optional(), contribution: z.object({type: z.string().optional(), value: z.union([z.string(), z.object({tiers: z.array(z.object({rate: z.string().optional(), threshold: z.string().optional(), threshold_delta: z.string().optional()})).optional()})]).optional()}).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 company benefit * * GET /v1/company_benefits/{company_benefit_id} */ export const getApiV1CompanyBenefitsCompanyBenefitId = async (args: GetApiV1CompanyBenefitsCompanyBenefitIdArgs, options?: GetApiV1CompanyBenefitsCompanyBenefitIdOptions) => { 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 (args.with_employee_benefits != null) query.append("with_employee_benefits", String(args.with_employee_benefits)) if (args.include != null) query.append("include", String(args.include)) if (CompanyAccessAuth !== undefined) headers.set('authorization', `Bearer ${CompanyAccessAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/company_benefits/${encodeURIComponent(String(args.company_benefit_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(companyBenefitWithEmployeeBenefits, await res.json()) };