import { isConfirmed, isDryRun, normalizeUserLocator, pickAuthInput, request } from '../core.ts' import { asRecord, buildWebinarBody, slimWebinar } from '../shape.ts' /** * Create a Zoom webinar. * * Pass `dryRun: true` to preview the request. Live creates require `confirm: true`. * * @example * import createZoomWebinar from 'kody:@kody/zoom/webinars/create' * const preview = await createZoomWebinar({ * topic: 'Example webinar', * type: 5, * dryRun: true, * }) */ export default async function createZoomWebinar(params: Record = {}) { const auth = pickAuthInput(params) const { userId } = normalizeUserLocator(params) const body = buildWebinarBody(params) if (!body.topic || typeof body.topic !== 'string') { throw new Error('topic is required to create a webinar.') } if (isDryRun(params)) { return { dryRun: true, wouldCreate: true, userId, path: `/users/${userId}/webinars`, body, auth, } } if (!isConfirmed(params)) { throw new Error( `Creating a webinar for ${userId} requires dryRun: true (preview) or confirm: true (live write).`, ) } const response = await request>({ ...auth, method: 'POST', path: `/users/${userId}/webinars`, body, throwOnError: true, confirm: true, }) return { ...slimWebinar(asRecord(response.data)), auth: response.auth, } }