import {z} from 'zod' export type GetApiBetaBusinessHoursSchedulesScheduleIdUpcomingArgs = {scheduleId: string, days?: number | undefined}; export type GetApiBetaBusinessHoursSchedulesScheduleIdUpcomingOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const exception1 = z.object({}); export const holiday1 = z.object({}); export const regular2 = z.object({}); export const businessHourType = z.union([exception1, holiday1, regular2]); export const closed1 = z.object({}); export const open1 = z.object({}); export const businessHourStatus1 = z.union([closed1, open1]); export const timeInterval1 = z.object({startTime: z.string(), endTime: z.string()}); export const recurring1 = z.object({dayOfMonth: z.number().int().optional(), monthOfYear: z.number().int().optional(), holiday: z.string().optional()}); export const businessHour = z.object({name: z.string(), dayOfWeek: z.number().int().optional(), businessHourType: businessHourType, status: businessHourStatus1, intervals: z.array(timeInterval1).optional(), recurring: recurring1.optional(), startDate: z.string(), nextDate: z.string().optional()}); export const businessHoursUpcomingSchedule = z.object({id: z.string(), name: z.string(), timezone: z.string(), businessHours: z.array(businessHour).optional()}); export const getUpcomingBusinessHoursScheduleResult = z.object({schedule: businessHoursUpcomingSchedule}); export const getUpcomingBusinessHoursScheduleOutput = z.object({data: getUpcomingBusinessHoursScheduleResult}); 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 the upcoming business hours schedule. * * GET /beta/business-hours/schedules/{scheduleId}/upcoming */ export const getApiBetaBusinessHoursSchedulesScheduleIdUpcoming = async (args: GetApiBetaBusinessHoursSchedulesScheduleIdUpcomingArgs, options?: GetApiBetaBusinessHoursSchedulesScheduleIdUpcomingOptions) => { const {baseUrl = "https://dev.dixa.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.days != null) query.append("days", String(args.days)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/beta/business-hours/schedules/${encodeURIComponent(String(args.scheduleId))}/upcoming${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(getUpcomingBusinessHoursScheduleOutput, await res.json()) };