import {z} from 'zod' export type StreemApiAcceptExternalAudioRequest = {filename?: string | undefined, start_time?: string | undefined, audio_file_url?: string | undefined}; export type CreateApiV1RoomsRoomSidArtifactsExternalAudioArgs = {room_sid: string, body: StreemApiAcceptExternalAudioRequest}; export type CreateApiV1RoomsRoomSidArtifactsExternalAudioOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const streemApiArtifactRecordingTrack = z.object({bucket: z.string().optional(), filename: z.string().optional(), user_sid: z.string().optional(), track_type: z.string().optional(), codec: z.string().optional(), storage_url: z.string().optional(), status: z.enum(["STATUS_STARTED_RECORDING", "STATUS_FINISHED_RECORDING", "STATUS_TRANSFERRING", "STATUS_ERROR", "STATUS_FULFILLED", "STATUS_INVALID"]).optional(), requested_at: z.string().optional(), started_recording_at: z.string().optional(), finished_recording_at: z.string().optional(), started_transferring_at: z.string().optional(), errored_at: z.string().optional(), fulfilled_at: z.string().optional(), url: z.string().optional(), created_at: z.string().optional(), recording_source: z.enum(["SOURCE_TWILIO", "SOURCE_EXTERNAL", "SOURCE_MUXER", "SOURCE_ARAAS", "SOURCE_CHIME", "SOURCE_INVALID"]).optional(), source_recording_track_sid: z.string().optional(), deleted_at: z.string().optional()}); export const streemApiAcceptExternalAudioResponse = z.object({recording_track: streemApiArtifactRecordingTrack.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 }; /** * Upload external audio * * POST /v1/rooms/{room_sid}/artifacts/external-audio * * Also accepts auth: bearer-auth */ export const createApiV1RoomsRoomSidArtifactsExternalAudio = async (args: CreateApiV1RoomsRoomSidArtifactsExternalAudioArgs, options?: CreateApiV1RoomsRoomSidArtifactsExternalAudioOptions) => { const {baseUrl = "https://api.prod-us.streem.cloud", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKey.username}:${apiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/rooms/${encodeURIComponent(String(args.room_sid))}/artifacts/external-audio${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(streemApiAcceptExternalAudioResponse, await res.json()) };