import {z} from 'zod' export type Fields = Array<'hostRoomUrl' | 'viewerRoomUrl'>; export type CreateApiMeetingsArgs = {body: {endDate: string, startDate?: string | undefined, isLocked?: boolean | undefined, roomMode?: ('group' | 'normal') | undefined, roomNamePrefix?: string | undefined, roomNamePattern?: ('uuid' | 'human-short') | undefined, templateType?: 'viewerMode' | undefined, recording?: ({type: 'none' | 'local' | 'cloud', destination: {provider: 's3' | 'whereby', authenticationType?: ('accessKey' | 'roleBased') | undefined, bucket?: string | undefined, accessKeyId?: string | undefined, accessKeySecret?: string | undefined, fileFormat?: ('mkv' | 'mp4') | undefined, oidcRoleArn?: string | undefined}, startTrigger: 'none' | 'prompt' | 'automatic' | 'automatic-2nd-participant'}) | undefined, liveTranscription?: ({destination: {provider: 's3' | 'whereby', authenticationType?: ('accessKey' | 'roleBased') | undefined, bucket?: string | undefined, accessKeyId?: string | undefined, accessKeySecret?: string | undefined, region?: string | undefined, oidcRoleArn?: string | undefined}, startTrigger: 'none' | 'manual' | 'automatic' | 'automatic-2nd-participant', language?: ('ca,' | 'zh,' | 'zh-TW,' | 'cs,' | 'da,' | 'nl,' | 'en,' | 'en-US,' | 'en-GB,' | 'fi,' | 'fr,' | 'de,' | 'de-CH,' | 'el,' | 'hi,' | 'id,' | 'it,' | 'ja,' | 'ko,' | 'lv,' | 'ms,' | 'no,' | 'pl,' | 'pt,' | 'pt-BR,' | 'ro,' | 'ru,' | 'sk,' | 'es,' | 'sv,' | 'th,' | 'uk,' | 'vi,') | undefined, liveCaptions?: boolean | undefined}) | undefined, streaming?: ({destination: {url: string}, startTrigger: 'none' | 'prompt' | 'automatic'}) | undefined, fields?: Fields | undefined}}; export type CreateApiMeetingsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const meeting = z.object({meetingId: z.string(), roomName: z.string().optional(), roomUrl: z.string(), startDate: z.string().optional(), endDate: z.string(), hostRoomUrl: z.string().optional(), viewerRoomUrl: z.string().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 meeting * * POST /meetings */ export const createApiMeetings = async (args: CreateApiMeetingsArgs, options?: CreateApiMeetingsOptions) => { const {baseUrl = "https://api.whereby.dev/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/meetings${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(meeting, await res.json()) };