import { calendlyRequest, uuidFromUri } from './client.ts' import { mapEventType } from './models.ts' import type { CalendlyAuthInput, CalendlyEventTypeSummary } from './types.ts' import { optionalString, requireRecord } from './types.ts' import { requireAuthMode } from './auth.ts' export type GetEventTypeInput = CalendlyAuthInput & { /** Event type uuid or full `https://api.calendly.com/event_types/{uuid}` URI. */ eventType?: string /** Alias of `eventType`. */ uuid?: string } /** * Read one Calendly event type by uuid or URI. * @example * import getEventType from 'kody:@kody/calendly/get-event-type' * const eventType = await getEventType({ eventType: 'AAAAAAAAAAAAAAAA' }) */ export async function getEventType(input: GetEventTypeInput): Promise { const eventType = optionalString(input.eventType, 'eventType') ?? optionalString(input.uuid, 'uuid') if (!eventType) throw new Error('get-event-type requires eventType (uuid is accepted as an alias).') const result = await calendlyRequest({ ...input, operation: 'eventTypes.read', path: `/event_types/${uuidFromUri(eventType)}`, }) return mapEventType(result.data) } /** * Read one Calendly event type by uuid or URI. * @example * import getEventType from 'kody:@kody/calendly/get-event-type' * const eventType = await getEventType({ uuid: 'AAAAAAAAAAAAAAAA' }) */ export default async function getEventTypeEntrypoint( params: Partial & Record = {}, ) { const input = requireRecord(params, 'get-event-type') return getEventType({ eventType: optionalString(input.eventType, 'eventType') ?? 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), }) }