import {z} from 'zod' export type GetApiApiV1NewHirePacketsArgs = {page?: number | undefined, pageSize?: number | undefined}; export type GetApiApiV1NewHirePacketsOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const newHirePacketPublicApi = z.object({id: z.number().int().nullable().optional(), employeeId: z.number().int().optional(), contactEmployeeId: z.number().int().nullable().optional(), requiresPersonalInformation: z.boolean().optional(), requiresPhoto: z.boolean().optional(), requiresPersonalQuestions: z.boolean().optional(), arriveByTime: z.string().nullable().optional(), location: z.string().nullable().optional(), sentDatetime: z.string().nullable().optional(), viewedDatetime: z.string().nullable().optional(), completedDatetime: z.string().nullable().optional(), createdByUserId: z.number().int().nullable().optional(), createdDatetime: z.string().nullable().optional(), sendGetToKnowYouEmail: z.boolean().optional(), getToKnowYouEmailSent: z.boolean().nullable().optional(), showPayrollState: z.boolean().nullable().optional(), showPayrollFederal: z.boolean().nullable().optional(), showPayrollDirectDeposit: z.boolean().nullable().optional(), nhpConfigurationId: z.number().int().nullable().optional(), nhpTemplateId: z.number().int().nullable().optional(), countNhpGtkySent: z.number().int().nullable().optional(), cancelled: z.boolean().optional(), includePhotoOption: z.boolean().optional(), status: z.enum(["cancelled", "completed", "sent", "draft"]).optional()}); export const getApiApiV1NewHirePacketsResponse = z.object({newHirePackets: z.array(newHirePacketPublicApi).optional(), page: z.number().int().optional(), pageSize: z.number().int().optional(), totalCount: z.number().int().optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * List new hire packets * * GET /api/v1/new-hire-packets */ export const getApiApiV1NewHirePackets = async (args: GetApiApiV1NewHirePacketsArgs, options?: GetApiApiV1NewHirePacketsOptions) => { const {baseUrl = "https://companySubDomain.bamboohr.com", fetch: fetchFn = fetch, oauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (oauth !== undefined) headers.set('authorization', `Bearer ${oauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/new-hire-packets${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(getApiApiV1NewHirePacketsResponse, await res.json()) };