import {z} from 'zod' export type GetApiApiV1EmployeedependentsIdArgs = {AcceptHeaderParameter?: ('application/xml' | 'application/json') | undefined, id: number}; export type GetApiApiV1EmployeedependentsIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const employeeDependentsResponse = z.object({"Employee Dependents": z.array(z.object({id: z.string().optional(), employeeId: z.string().optional(), firstName: z.string().optional(), middleName: z.string().nullable().optional(), lastName: z.string().optional(), relationship: z.string().optional(), gender: z.string().optional(), maskedSSN: z.string().nullable().optional(), maskedSIN: z.string().nullable().optional(), dateOfBirth: z.string().optional(), addressLine1: z.string().nullable().optional(), addressLine2: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), zipCode: z.string().nullable().optional(), homePhone: z.string().nullable().optional(), country: z.string().nullable().optional(), isUsCitizen: z.enum(["yes", "no"]).nullable().optional(), isStudent: z.enum(["yes", "no"]).nullable().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 Employee Dependent * * GET /api/v1/employeedependents/{id} * * Also accepts auth: oauth, oauth */ export const getApiApiV1EmployeedependentsId = async (args: GetApiApiV1EmployeedependentsIdArgs, options?: GetApiApiV1EmployeedependentsIdOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.AcceptHeaderParameter != null) headers.set("AcceptHeaderParameter", String(args.AcceptHeaderParameter)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/employeedependents/${encodeURIComponent(String(args.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(employeeDependentsResponse, await res.json()) };