import {z} from 'zod' export type CreateTranscriptionRequest = {sourceUrl?: string | undefined, uploadId?: string | undefined, language?: (string | null) | undefined, translationLanguage?: (string | null) | undefined, transcriptionScript?: ('native' | 'roman') | undefined}; export type CreateApiAutomationCreateTranscriptionArgs = {body: CreateTranscriptionRequest}; export type CreateApiAutomationCreateTranscriptionOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const videoGenre = z.enum(["talking", "screenshare", "gaming"]); export const videoOrientation = z.enum(["landscape", "portrait", "square"]); export const transcriptionScript = z.enum(["native", "roman"]); export const videoFileMeta = z.object({width: z.number().int().optional(), height: z.number().int().optional(), aspectRatio: z.string().optional(), size: z.number().optional(), bitrate: z.number().optional(), fps: z.number().optional(), duration: z.number().optional(), rotation: z.number().int().optional(), resolution: z.number().int().optional(), codec: z.string().optional(), codecFullName: z.string().optional(), codecTag: z.string().optional(), format: z.string().optional(), formatFullName: z.string().optional()}); export const projectUrls = z.object({videoFile: z.string().optional(), audioFile: z.string().optional(), transcription: z.string().optional(), transcription_srt: z.string().optional(), transcription_vtt: z.string().optional(), transcription_csv: z.string().optional(), transcription_txt: z.string().optional()}); export const automationProject = z.object({id: z.string().optional(), title: z.string().optional(), thumbnail: z.string().optional(), billedDuration: z.number().optional(), status: z.enum(["queued", "prepped", "draft", "processing", "finalizing", "completed", "invalid", "expired", "failed", "error"]).optional(), projectType: z.enum(["clipping", "captions", "reframe", "dubbing", "transcription"]).optional(), source: z.enum(["Upload", "Youtube", "Vimeo", "TwitchVod", "Twitter", "RumbleEmbed", "Generic"]).optional(), genre: videoGenre.optional(), topics: z.array(z.string()).optional(), clipDurations: z.array(z.array(z.number().int())).optional(), selectedStart: z.number().nullable().optional(), selectedEnd: z.number().nullable().optional(), exportResolution: z.number().int().optional(), exportOrientation: videoOrientation.optional(), captionsPreset: z.string().nullable().optional(), enableCaptions: z.boolean().optional(), enableEmojis: z.boolean().optional(), enableHighlights: z.boolean().optional(), language: z.string().nullable().optional(), dubbingLanguage: z.string().nullable().optional(), translateTranscription: z.boolean().optional(), translationLanguages: z.array(z.string()).optional(), transcriptionScript: transcriptionScript.optional(), metadata: videoFileMeta.optional(), urls: projectUrls.optional(), createdAt: z.number().int().optional(), updatedAt: z.number().int().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 Transcription * * POST /automation/create-transcription */ export const createApiAutomationCreateTranscription = async (args: CreateApiAutomationCreateTranscriptionArgs, options?: CreateApiAutomationCreateTranscriptionOptions) => { const {baseUrl = "https://public.reap.video/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/automation/create-transcription${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(automationProject, await res.json()) };