import {z} from 'zod' export type PropertyCalendarWebinarOrganizer = {user_id?: string | undefined, email?: string | undefined, name?: string | undefined, status?: ('ACCEPTED' | 'REJECTED' | 'TENTATIVE') | undefined, required?: boolean | undefined, is_cohost?: boolean | undefined}; export type CalendarWebinarPanelist = {email?: string | undefined, name?: string | undefined, is_required?: boolean | undefined, join_url?: string | undefined, join_password?: string | undefined, status?: ('ACCEPTED' | 'REJECTED' | 'TENTATIVE') | undefined}; export type PropertyCalendarWebinarPanelists = Array; export type CalendarWebinarRegistrant = {email?: string | undefined, name?: string | undefined, registration_reference?: string | undefined, registration_status?: ('PENDING' | 'APPROVED' | 'REJECTED' | 'CANCELLED') | undefined, registered_at?: string | undefined}; export type PropertyCalendarWebinarRegistrants = Array; export type CalendarConference = {conference_identifier?: string | undefined, url?: string | undefined, label?: string | undefined, telephone?: string | undefined, participant_access_code?: string | undefined, host_access_code?: string | undefined, notes?: string | undefined, country_code?: string | undefined, region_code?: string | undefined}; export type PropertyCalendarWebinarConference = Array; export type PropertyCalendarEventRecurrenceOnDays = Array<'SU' | 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA'>; export type PropertyCalendarEventRecurrenceOnMonths = Array; export type PropertyCalendarEventRecurrenceOnMonthDays = Array; export type PropertyCalendarEventRecurrenceOnWeeks = Array; export type PropertyCalendarEventRecurrenceOnYearDays = Array; export type PropertyCalendarEventRecurrenceExcludedDates = Array; export type PropertyCalendarEventRecurrenceIncludedDates = Array; export type CalendarEventRecurrence = {frequency?: ('DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY') | undefined, interval?: number | undefined, count?: number | undefined, end_at?: string | undefined, on_days?: PropertyCalendarEventRecurrenceOnDays | undefined, on_months?: PropertyCalendarEventRecurrenceOnMonths | undefined, on_month_days?: PropertyCalendarEventRecurrenceOnMonthDays | undefined, on_weeks?: PropertyCalendarEventRecurrenceOnWeeks | undefined, on_year_days?: PropertyCalendarEventRecurrenceOnYearDays | undefined, week_start?: ('SU' | 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA') | undefined, excluded_dates?: PropertyCalendarEventRecurrenceExcludedDates | undefined, included_dates?: PropertyCalendarEventRecurrenceIncludedDates | undefined, timezone?: string | undefined}; export type PropertyCalendarWebinarRecurrence = Array; export type CalendarMetadata = {id?: string | undefined, slug?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined}; export type PropertyCalendarWebinarMetadata = Array; export type CalendarWebinar = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, calendar_id?: string | undefined, subject?: string | undefined, start_at?: string | undefined, end_at?: string | undefined, timezone?: string | undefined, notes?: string | undefined, status?: ('CANCELED' | 'CONFIRMED' | 'TENTATIVE') | undefined, organizer?: PropertyCalendarWebinarOrganizer | undefined, join_url?: string | undefined, web_url?: string | undefined, panelists?: PropertyCalendarWebinarPanelists | undefined, registrants?: PropertyCalendarWebinarRegistrants | undefined, panelist_password?: string | undefined, registrant_password?: string | undefined, conference?: PropertyCalendarWebinarConference | undefined, recurrence?: PropertyCalendarWebinarRecurrence | undefined, capacity?: number | undefined, is_webcast?: boolean | undefined, is_enabled?: boolean | undefined, is_auto_approve?: boolean | undefined, require_first_name?: boolean | undefined, require_last_name?: boolean | undefined, require_email?: boolean | undefined, require_company?: boolean | undefined, require_job_title?: boolean | undefined, require_address?: boolean | undefined, require_phone?: boolean | undefined, has_qa?: boolean | undefined, has_polls?: boolean | undefined, has_recording?: boolean | undefined, metadata?: PropertyCalendarWebinarMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type CreateApiCalendarConnectionIdWebinarArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'calendar_id' | 'subject' | 'start_at' | 'end_at' | 'timezone' | 'notes' | 'status' | 'organizer' | 'join_url' | 'web_url' | 'panelists' | 'registrants' | 'panelist_password' | 'registrant_password' | 'conference' | 'recurrence' | 'capacity' | 'is_webcast' | 'is_enabled' | 'is_auto_approve' | 'require_first_name' | 'require_last_name' | 'require_email' | 'require_company' | 'require_job_title' | 'require_address' | 'require_phone' | 'has_qa' | 'has_polls' | 'has_recording' | 'metadata' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, body: CalendarWebinar}; export type CreateApiCalendarConnectionIdWebinarOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const propertyCalendarWebinarOrganizer = z.object({user_id: z.string().optional(), email: z.string().optional(), name: z.string().optional(), status: z.enum(["ACCEPTED", "REJECTED", "TENTATIVE"]).optional(), required: z.boolean().optional(), is_cohost: z.boolean().optional()}); export const calendarWebinarPanelist = z.object({email: z.string().optional(), name: z.string().optional(), is_required: z.boolean().optional(), join_url: z.string().optional(), join_password: z.string().optional(), status: z.enum(["ACCEPTED", "REJECTED", "TENTATIVE"]).optional()}); export const propertyCalendarWebinarPanelists = z.array(calendarWebinarPanelist); export const calendarWebinarRegistrant = z.object({email: z.string().optional(), name: z.string().optional(), registration_reference: z.string().optional(), registration_status: z.enum(["PENDING", "APPROVED", "REJECTED", "CANCELLED"]).optional(), registered_at: z.string().optional()}); export const propertyCalendarWebinarRegistrants = z.array(calendarWebinarRegistrant); export const calendarConference = z.object({conference_identifier: z.string().optional(), url: z.string().optional(), label: z.string().optional(), telephone: z.string().optional(), participant_access_code: z.string().optional(), host_access_code: z.string().optional(), notes: z.string().optional(), country_code: z.string().optional(), region_code: z.string().optional()}); export const propertyCalendarWebinarConference = z.array(calendarConference); export const propertyCalendarEventRecurrenceOnDays = z.array(z.enum(["SU", "MO", "TU", "WE", "TH", "FR", "SA"])); export const propertyCalendarEventRecurrenceOnMonths = z.array(z.number()); export const propertyCalendarEventRecurrenceOnMonthDays = z.array(z.number()); export const propertyCalendarEventRecurrenceOnWeeks = z.array(z.number()); export const propertyCalendarEventRecurrenceOnYearDays = z.array(z.number()); export const propertyCalendarEventRecurrenceExcludedDates = z.array(z.string()); export const propertyCalendarEventRecurrenceIncludedDates = z.array(z.string()); export const calendarEventRecurrence = z.object({frequency: z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]).optional(), interval: z.number().optional(), count: z.number().optional(), end_at: z.string().optional(), on_days: propertyCalendarEventRecurrenceOnDays.optional(), on_months: propertyCalendarEventRecurrenceOnMonths.optional(), on_month_days: propertyCalendarEventRecurrenceOnMonthDays.optional(), on_weeks: propertyCalendarEventRecurrenceOnWeeks.optional(), on_year_days: propertyCalendarEventRecurrenceOnYearDays.optional(), week_start: z.enum(["SU", "MO", "TU", "WE", "TH", "FR", "SA"]).optional(), excluded_dates: propertyCalendarEventRecurrenceExcludedDates.optional(), included_dates: propertyCalendarEventRecurrenceIncludedDates.optional(), timezone: z.string().optional()}); export const propertyCalendarWebinarRecurrence = z.array(calendarEventRecurrence); export const calendarMetadata = z.object({id: z.string().optional(), slug: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional()}); export const propertyCalendarWebinarMetadata = z.array(calendarMetadata); export const calendarWebinar = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), calendar_id: z.string().optional(), subject: z.string().optional(), start_at: z.string().optional(), end_at: z.string().optional(), timezone: z.string().optional(), notes: z.string().optional(), status: z.enum(["CANCELED", "CONFIRMED", "TENTATIVE"]).optional(), organizer: propertyCalendarWebinarOrganizer.optional(), join_url: z.string().optional(), web_url: z.string().optional(), panelists: propertyCalendarWebinarPanelists.optional(), registrants: propertyCalendarWebinarRegistrants.optional(), panelist_password: z.string().optional(), registrant_password: z.string().optional(), conference: propertyCalendarWebinarConference.optional(), recurrence: propertyCalendarWebinarRecurrence.optional(), capacity: z.number().optional(), is_webcast: z.boolean().optional(), is_enabled: z.boolean().optional(), is_auto_approve: z.boolean().optional(), require_first_name: z.boolean().optional(), require_last_name: z.boolean().optional(), require_email: z.boolean().optional(), require_company: z.boolean().optional(), require_job_title: z.boolean().optional(), require_address: z.boolean().optional(), require_phone: z.boolean().optional(), has_qa: z.boolean().optional(), has_polls: z.boolean().optional(), has_recording: z.boolean().optional(), metadata: propertyCalendarWebinarMetadata.optional(), raw: z.record(z.string(), z.unknown()).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 }; /** * Create a webinar * * POST /calendar/{connection_id}/webinar */ export const createApiCalendarConnectionIdWebinar = async (args: CreateApiCalendarConnectionIdWebinarArgs, options?: CreateApiCalendarConnectionIdWebinarOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/calendar/${encodeURIComponent(String(args.connection_id))}/webinar${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(calendarWebinar, await res.json()) };