export type HourMinuteDto = {hour: number, minute: number}; export type SlotDto = {start: HourMinuteDto, end: HourMinuteDto}; export type TimeSlotDto = {day: number, slots: Array}; export type CreateScheduleDto = {name: string, timezone: string, timeSlots: Array, isDefault?: boolean | undefined}; export type CreateApiV1SchedulesArgs = {body: CreateScheduleDto}; export type CreateApiV1SchedulesOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a schedule * * POST /v1/schedules */ export const createApiV1Schedules = async (args: CreateApiV1SchedulesArgs, options: CreateApiV1SchedulesOptions) => { const {baseUrl, fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/schedules${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 undefined };