import {z} from 'zod' export type GetApiApiV2ResourceManagementBookingsBookingIdArgs = {Authorization: string, bookingId: string, include?: string | undefined, exclude?: string | undefined, keyList?: string | undefined}; export type GetApiApiV2ResourceManagementBookingsBookingIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const extBookingCapacityData = z.object({unit: z.enum(["hours", "percentage", "fraction"]), timeGranularity: z.enum(["daily", "weekly", "monthly"]).nullable().optional(), capacity: z.number()}); export const extBooking = z.object({creatorEmail: z.string(), createdAt: z.number().int(), bookingId: z.number().int().nullable().optional(), startDateIso: z.string().optional(), endDateIso: z.string().optional(), bookedCapacity: extBookingCapacityData.nullable().optional(), lastModifiedAt: z.number().int().nullable().optional(), endDate: z.number().int().optional(), lastModifierEmail: z.string().nullable().optional(), extBookingId: z.string(), startDate: z.number().int().optional(), extDemandId: z.string().nullable().optional(), employeeId: z.string(), bookingStatus: z.enum(["pending", "approved", "rejected"]), bookingType: z.enum(["demand", "leave", "optional_holiday", "blocker"])}); export const bookingSchema = z.object({createdAt: z.number().int().nullable().optional(), updatedBy: z.string().nullable().optional(), isArchived: z.boolean().nullable().optional(), startDateIso: z.string().optional(), extData: extBooking.nullable().optional(), capacity: z.number(), startDate: z.number().int().optional(), archivedAt: z.number().int().nullable().optional(), bookingStatus: z.enum(["pending", "approved", "rejected"]), bookingId: z.number().int().nullable().optional(), demandId: z.number().int().nullable().optional(), endDate: z.number().int().optional(), updatedAt: z.number().int().nullable().optional(), employeeProfileId: z.number().int().nullable().optional(), bookingType: z.enum(["demand", "leave", "optional_holiday", "blocker"]), endDateIso: z.string().optional(), createdBy: z.string().nullable().optional(), employeeEmail: z.string()}); 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 Booking * * GET /api/v2/resource_management/bookings/{bookingId} */ export const getApiApiV2ResourceManagementBookingsBookingId = async (args: GetApiApiV2ResourceManagementBookingsBookingIdArgs, options?: GetApiApiV2ResourceManagementBookingsBookingIdOptions) => { const {baseUrl = "https://apiv2.eightfold.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.include != null) query.append("include", String(args.include)) if (args.exclude != null) query.append("exclude", String(args.exclude)) if (args.keyList != null) query.append("keyList", String(args.keyList)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/resource_management/bookings/${encodeURIComponent(String(args.bookingId))}${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(bookingSchema, await res.json()) };