Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/zoom

src/webinars/delete.ts

48 lines · 1.2 KB · TypeScript
import { isConfirmed, isDryRun, normalizeWebinarLocator, pickAuthInput, request } from '../core.ts'

/**
 * Delete a Zoom webinar.
 *
 * Pass `dryRun: true` to preview the request. Live deletes require `confirm: true`.
 *
 * @example
 * import deleteZoomWebinar from 'kody:@kody/zoom/webinars/delete'
 * const preview = await deleteZoomWebinar({ webinarId: '22222222222', dryRun: true })
 */
export default async function deleteZoomWebinar(params: Record<string, unknown> = {}) {
	const auth = pickAuthInput(params)
	const { webinarId, occurrenceId } = normalizeWebinarLocator(params)

	if (isDryRun(params)) {
		return {
			dryRun: true,
			wouldDelete: true,
			webinarId,
			occurrenceId: occurrenceId ?? null,
			path: `/webinars/${webinarId}`,
			auth,
		}
	}

	if (!isConfirmed(params)) {
		throw new Error(
			`Deleting webinar ${webinarId} requires dryRun: true (preview) or confirm: true (live write).`,
		)
	}

	const response = await request<unknown>({
		...auth,
		method: 'DELETE',
		path: `/webinars/${webinarId}`,
		query: occurrenceId ? { occurrence_id: occurrenceId } : undefined,
		throwOnError: true,
		confirm: true,
	})

	return {
		ok: true,
		webinarId,
		status: response.status,
		auth: response.auth,
	}
}