import {z} from 'zod' export type GetApiAttendanceEntitlementsArgs = {$top?: number | undefined, $skip?: number | undefined, $filter?: string | undefined, $select?: Array | undefined, $orderby?: string | undefined, $count?: boolean | undefined}; export type GetApiAttendanceEntitlementsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const entitlementModel = z.object({EmployeeId: z.string().max(36).nullable().optional(), AbsenceReasonId: z.string().max(36).nullable().optional(), EntitlementYearName: z.string().max(50).nullable().optional(), Open: z.boolean().optional(), StartDate: z.string().nullable().optional(), EndDate: z.string().nullable().optional(), Narrative: z.string().max(3524).nullable().optional(), BaseDays: z.number().optional(), BaseMinutes: z.number().int().nullable().optional(), CarryDays: z.number().optional(), CarryMinutes: z.number().int().nullable().optional(), CarryUseByDate: z.string().nullable().optional(), CarryLostDays: z.number().nullable().optional(), CarryLostMinutes: z.number().int().nullable().optional(), ManualAdjustmentDays: z.number().optional(), ManualAdjustmentMinutes: z.number().int().nullable().optional(), ServiceLengthAdjustmentDays: z.number().optional(), ServiceLengthAdjustmentMinutes: z.number().int().nullable().optional(), NewStarterAdjustmentDays: z.number().optional(), NewStarterAdjustmentMinutes: z.number().int().nullable().optional(), LeaverAdjusmentDays: z.number().optional(), LeaverAdjusmentMinutes: z.number().int().nullable().optional(), LeaverAdjustmentDays: z.number().nullable().optional(), LeaverAdjustmentMinutes: z.number().int().nullable().optional(), PartTimeAdjustmentDays: z.number().optional(), PartTimeAdjustmentMinutes: z.number().int().nullable().optional(), BankHolidayAdjustmentDays: z.number().optional(), BankHolidayAdjustmentMinutes: z.number().int().nullable().optional(), BuySellDays: z.number().optional(), BuySellMinutes: z.number().int().nullable().optional(), TotalEntitlementDays: z.number().nullable().optional(), TotalEntitlementMinutes: z.number().int().nullable().optional(), SourceSystemId: z.string().max(36).nullable().optional(), SourceSystemCreatedOn: z.string().nullable().optional(), SourceSystemLastModifiedOn: z.string().nullable().optional(), Id: z.string().max(36).nullable().optional(), CreatedOn: z.string().optional(), CreatedBy: z.string().max(36).nullable().optional(), LastModifiedOn: z.string().nullable().optional(), LastModifiedBy: z.string().max(36).nullable().optional()}); export const entitlementQueryModel = z.object({"@odata.context": z.string().nullable().optional(), "@odata.count": z.number().int().nullable().optional(), "@odata.nextlink": z.string().nullable().optional(), value: z.array(entitlementModel).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 }; /** * Gets a list of Entitlements. * * GET /attendance/entitlements */ export const getApiAttendanceEntitlements = async (args: GetApiAttendanceEntitlementsArgs, options?: GetApiAttendanceEntitlementsOptions) => { const {baseUrl = "https://api.iris.co.uk/hr/v2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.$top != null) query.append("$top", String(args.$top)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$select != null) query.append("$select", args.$select.join(',')) if (args.$orderby != null) query.append("$orderby", String(args.$orderby)) if (args.$count != null) query.append("$count", String(args.$count)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/attendance/entitlements${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(entitlementQueryModel, await res.json()) };