import {z} from 'zod' export type HolidayCompanyHolidayAudienceV1 = {mode?: ('ALL_EMPLOYEES' | 'FILTERED' | 'SPECIFIC_EMPLOYEES') | undefined, filterListValueIds?: Array | undefined, specificEmployeeIds?: Array | undefined, additionalEmployeeIds?: Array | undefined, exemptEmployeeIds?: Array | undefined}; export type HolidayCompanyHolidayPayStatusHoursV1 = {employmentStatusListValueId?: number | undefined, hours?: string | undefined}; export type HolidayCompanyHolidayPayV1 = {mode?: ('HOURS_BY_STATUS' | 'MULTIPLIER') | undefined, defaultHours?: (string | null) | undefined, hoursByEmploymentStatus?: Array | undefined, multiplier?: (string | null) | undefined} | null; export type HolidayCreateCompanyHolidayRequestV1 = {globalHolidayUuid?: (string | null) | undefined, name?: (string | null) | undefined, startDate?: (string | null) | undefined, endDate?: (string | null) | undefined, isPublic?: boolean | undefined, countryCodes?: (Array | null) | undefined, audience: HolidayCompanyHolidayAudienceV1, holidayPay?: (HolidayCompanyHolidayPayV1 | null) | undefined}; export type CreateApiApiV1HolidaysArgs = {body: HolidayCreateCompanyHolidayRequestV1}; export type CreateApiApiV1HolidaysOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const holidayCompanyHolidayAudienceV1 = z.object({mode: z.enum(["ALL_EMPLOYEES", "FILTERED", "SPECIFIC_EMPLOYEES"]).optional(), filterListValueIds: z.array(z.number().int()).optional(), specificEmployeeIds: z.array(z.number().int()).optional(), additionalEmployeeIds: z.array(z.number().int()).optional(), exemptEmployeeIds: z.array(z.number().int()).optional()}); export const holidayCompanyHolidayPayStatusHoursV1 = z.object({employmentStatusListValueId: z.number().int().optional(), hours: z.string().optional()}); export const holidayCompanyHolidayPayV1 = z.object({mode: z.enum(["HOURS_BY_STATUS", "MULTIPLIER"]).optional(), defaultHours: z.string().nullable().optional(), hoursByEmploymentStatus: z.array(holidayCompanyHolidayPayStatusHoursV1).optional(), multiplier: z.string().nullable().optional()}).nullable(); export const holidayCompanyHolidayV1 = z.object({id: z.number().int().optional(), name: z.string().optional(), startDate: z.string().optional(), endDate: z.string().nullable().optional(), isPublic: z.boolean().optional(), countryCodes: z.array(z.string()).optional(), audience: holidayCompanyHolidayAudienceV1.optional(), holidayPay: holidayCompanyHolidayPayV1.nullable().optional(), globalHolidayUuid: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), deletedAt: z.string().nullable().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 Company Holiday * * POST /api/v1/holidays * * Also accepts auth: oauth */ export const createApiApiV1Holidays = async (args: CreateApiApiV1HolidaysArgs, options?: CreateApiApiV1HolidaysOptions) => { 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/holidays${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(holidayCompanyHolidayV1, await res.json()) };