import {z} from 'zod' export type GetApiV1VideosIdClipsClipIdKeyEventsArgs = {id: string, clipId: string, startTimeMs?: number | undefined, endTimeMs?: number | undefined}; export type GetApiV1VideosIdClipsClipIdKeyEventsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const clipKeyEvent = z.object({isRepeat: z.boolean(), key: z.string().nullable(), kind: z.enum(["down", "up", "modifiersChanged"]), modifiers: z.array(z.enum(["control", "option", "shift", "command", "capsLock", "function"])), timestampMs: z.number().gte(0)}); export const listClipKeyEventsResponse = z.object({events: z.array(clipKeyEvent)}); 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 key presses on a clip * * GET /v1/videos/{id}/clips/{clipId}/key-events */ export const getApiV1VideosIdClipsClipIdKeyEvents = async (args: GetApiV1VideosIdClipsClipIdKeyEventsArgs, options?: GetApiV1VideosIdClipsClipIdKeyEventsOptions) => { const {baseUrl = "https://api.tella.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startTimeMs != null) query.append("startTimeMs", String(args.startTimeMs)) if (args.endTimeMs != null) query.append("endTimeMs", String(args.endTimeMs)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/videos/${encodeURIComponent(String(args.id))}/clips/${encodeURIComponent(String(args.clipId))}/key-events${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(listClipKeyEventsResponse, await res.json()) };