import {z} from 'zod' export type EmployeeDependent = {employeeId: string, firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, relationship?: string | undefined, gender?: string | undefined, ssn?: string | undefined, sin?: string | undefined, dateOfBirth?: string | undefined, addressLine1?: string | undefined, addressLine2?: string | undefined, city?: string | undefined, state?: string | undefined, zipCode?: string | undefined, homePhone?: string | undefined, country?: string | undefined, isUsCitizen?: ('yes' | 'no') | undefined, isStudent?: ('yes' | 'no') | undefined}; export type CreateApiApiV1EmployeedependentsArgs = {body: EmployeeDependent}; export type CreateApiApiV1EmployeedependentsOptions = {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 }; /** * Create Employee Dependent * * POST /api/v1/employeedependents * * Also accepts auth: oauth, oauth */ export const createApiApiV1Employeedependents = async (args: CreateApiApiV1EmployeedependentsArgs, options?: CreateApiApiV1EmployeedependentsOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/employeedependents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) 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()) };