import {z} from 'zod' export type GetApiV2AssetsUserMediaAssetIdArgs = {user_media_asset_id: string}; export type GetApiV2AssetsUserMediaAssetIdOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const assetContentType = z.enum(["image/webp", "image/jpeg", "image/png", "image/svg+xml", "image/gif", "video/mp4", "video/webm", "video/quicktime", "audio/wav", "audio/mpeg", "audio/ogg", "audio/aac", "audio/flac", "audio/mp4", "audio/webm", "font/otf", "font/ttf", "font/woff", "application/font-woff", "font/woff2", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.synthesia.studio-video", "application/vnd.synthesia.studio-imported-video", "application/vnd.synthesia.studio-dubbed-video", "application/vnd.synthesia.studio-photo-avatar-video", "application/vnd.synthesia.studio-synthesia-academy-video", "application/vnd.synthesia.studio-synthesia-feature-overview-video", "application/vnd.synthesia.studio-synthesia-example-video", "application/vnd.synthesia.studio-synthesia-demo-video", "application/vnd.synthesia.studio-synthesia-welcome-webinar-video", "application/vnd.synthesia.studio-user-template", "application/vnd.synthesia.studio-synthesia-template", "application/vnd.synthesia.studio-synthesia-processed-gif", "application/vnd.synthesia.studio-user-course", "application/vnd.synthesia.font-family", "application/vnd.synthesia.folder", "application/json", "application/x-xliff+xml", "application/pdf", "text/csv"]); export const publicApiUserUploadedAssetStatus = z.enum(["awaiting_upload", "processing", "error", "ready"]); export const languageBCP47 = z.enum(["af", "sq", "am", "ar", "ar-DZ", "ar-BH", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LY", "ar-MA", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-AE", "ar-YE", "hy", "as", "az", "ba", "eu", "be", "bn", "bs", "br", "bg", "my", "ca", "zh", "zh-CN", "zh-HK", "zh-TW", "hr", "cs", "da", "nl", "nl-BE", "nl-NL", "en", "en-AU", "en-CA", "en-GB", "en-HK", "en-IN", "en-IE", "en-KE", "en-MX", "en-NZ", "en-NG", "en-PH", "en-SG", "en-ZA", "en-TZ", "en-US", "et", "fo", "fil", "fi", "fr", "fr-BE", "fr-CA", "fr-FR", "fr-CH", "gl", "ka", "de", "de-AT", "de-DE", "de-CH", "el", "gu", "ht", "ha", "haw", "he", "hi", "hu", "is", "id", "ga", "it", "ja", "jw", "kn", "kk", "km", "ko", "lo", "la", "lv", "ln", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "ne", "no", "nb", "nn", "oc", "or", "pa", "ps", "fa", "pl", "pt", "pt-BR", "pt-PT", "ro", "ru", "sa", "sr", "sn", "sd", "si", "sk", "sl", "so", "es", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-CU", "es-DO", "es-EC", "es-SV", "es-GQ", "es-GT", "es-HN", "es-LA", "es-MX", "es-NI", "es-PA", "es-PY", "es-PE", "es-PR", "es-ES", "es-US", "es-UY", "es-VE", "su", "sw", "sv", "tl", "tg", "ta", "ta-IN", "ta-SG", "ta-LK", "tt", "te", "th", "bo", "tr", "tk", "uk", "ur", "uz", "vi", "cy", "yi", "yo", "zu", "und"]); export const getPublicApiMediaAssetMetadataResponse = z.object({detectedLanguage: languageBCP47.nullable().optional()}); export const publicApiUserUploadedAssetErrorCodes = z.enum(["asset_upload", "language_detect", "unknown"]); export const getPublicApiUserUploadedAssetResponse = z.object({id: z.string(), title: z.string(), contentType: assetContentType, status: publicApiUserUploadedAssetStatus, metadata: getPublicApiMediaAssetMetadataResponse, errorCode: publicApiUserUploadedAssetErrorCodes.nullable().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 }; /** * Get user media asset * * GET /v2/assets/{user_media_asset_id} */ export const getApiV2AssetsUserMediaAssetId = async (args: GetApiV2AssetsUserMediaAssetIdArgs, options?: GetApiV2AssetsUserMediaAssetIdOptions) => { const {baseUrl = "https://api.synthesia.io", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/assets/${encodeURIComponent(String(args.user_media_asset_id))}${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(getPublicApiUserUploadedAssetResponse, await res.json()) };