import {z} from 'zod' export type GetApiRcvideoV1AccountAccountIdRecordingsArgs = {accountId: string, pageToken?: string | undefined, perPage?: number | undefined}; export type GetApiRcvideoV1AccountAccountIdRecordingsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const host = z.object({accountId: z.string().optional(), extensionId: z.string().optional(), displayName: z.string().optional()}); export const cloudRecording = z.object({id: z.string(), shortId: z.string(), startTime: z.string(), duration: z.number().int().optional(), displayName: z.string(), hostInfo: host, mediaLink: z.string(), url: z.string(), expiresIn: z.string().optional()}); export const paging = z.object({currentPageToken: z.string(), nextPageToken: z.string().optional()}); export const cloudRecordings = z.object({recordings: z.array(cloudRecording), paging: paging}); 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 }; /** * List Account Recordings * * GET /rcvideo/v1/account/{accountId}/recordings */ export const getApiRcvideoV1AccountAccountIdRecordings = async (args: GetApiRcvideoV1AccountAccountIdRecordingsArgs, options?: GetApiRcvideoV1AccountAccountIdRecordingsOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/rcvideo/v1/account/${encodeURIComponent(String(args.accountId))}/recordings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(cloudRecordings, await res.json()) };