import {z} from 'zod' export type GetApiIntegrationsCalendarIntegrationIdCalendarsArgs = {integration_id: number, limit?: number | undefined, selected?: boolean | undefined, page_token?: string | undefined}; export type GetApiIntegrationsCalendarIntegrationIdCalendarsOptions = {baseUrl: string, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const modelsCalendar = z.object({background_color: z.string().optional(), calendar_id: z.number().int().optional(), calendar_integration_id: z.number().int().optional(), created_at: z.string().optional(), default_planned_task_id: z.number().int().optional(), default_project_id: z.number().int().optional(), default_workspace_id: z.number().int().optional(), deleted_at: z.string().optional(), external_id: z.string().optional(), foreground_color: z.string().optional(), name: z.string().optional(), remind_tracking: z.boolean().optional(), selected: z.boolean().optional(), updated_at: z.string().optional()}); export const handlercalendarCalendarsResponse = z.object({calendars: z.array(modelsCalendar).optional(), next_page_token: z.string().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 }; /** * Get all calendars for a given integration. * * GET /integrations/calendar/{integration_id}/calendars */ export const getApiIntegrationsCalendarIntegrationIdCalendars = async (args: GetApiIntegrationsCalendarIntegrationIdCalendarsArgs, options: GetApiIntegrationsCalendarIntegrationIdCalendarsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.selected != null) query.append("selected", String(args.selected)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/integrations/calendar/${encodeURIComponent(String(args.integration_id))}/calendars${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(handlercalendarCalendarsResponse, await res.json()) };