import { calendlyRequest, uuidFromUri } from './client.ts' import { mapScheduledEvent } from './models.ts' import type { CalendlyAuthInput, CalendlyScheduledEventSummary } from './types.ts' import { optionalString, requireRecord } from './types.ts' import { requireAuthMode } from './auth.ts' export type GetScheduledEventInput = CalendlyAuthInput & { /** Scheduled event uuid or full URI. */ event?: string /** Alias of `event`. */ uuid?: string } /** * Read one Calendly scheduled event by uuid or URI. * @example * import getScheduledEvent from 'kody:@kody/calendly/get-scheduled-event' * const event = await getScheduledEvent({ event: 'AAAAAAAAAAAAAAAA' }) */ export async function getScheduledEvent( input: GetScheduledEventInput, ): Promise { const event = optionalString(input.event, 'event') ?? optionalString(input.uuid, 'uuid') if (!event) throw new Error('get-scheduled-event requires event (uuid is accepted as an alias).') const result = await calendlyRequest({ ...input, operation: 'scheduledEvents.read', path: `/scheduled_events/${uuidFromUri(event)}`, }) return mapScheduledEvent(result.data) } /** * Read one Calendly scheduled event by uuid or URI. * @example * import getScheduledEvent from 'kody:@kody/calendly/get-scheduled-event' * const event = await getScheduledEvent({ uuid: 'AAAAAAAAAAAAAAAA' }) */ export default async function getScheduledEventEntrypoint( params: Partial & Record = {}, ) { const input = requireRecord(params, 'get-scheduled-event') return getScheduledEvent({ event: optionalString(input.event, 'event') ?? optionalString(input.uuid, 'uuid'), uuid: optionalString(input.uuid, 'uuid'), integrationName: optionalString(input.integrationName, 'integrationName'), integration: optionalString(input.integration, 'integration'), account: optionalString(input.account, 'account'), secretName: optionalString(input.secretName, 'secretName'), auth: requireAuthMode(input.auth), }) }