import {z} from 'zod' export type GetApiV1RoomsRoomSidNoteArgs = {room_sid: string}; export type GetApiV1RoomsRoomSidNoteOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const streemApiNote = z.object({sid: z.string().optional(), created_by_user_sid: z.string().optional(), created_at: z.string().optional(), scope: z.enum(["SCOPE_ROOM", "SCOPE_STREEMSHOT", "SCOPE_INVALID"]).optional(), scope_sid: z.string().optional(), last_updated_by_user_sid: z.string().optional(), last_updated_at: z.string().optional(), text: z.string().optional(), deleted_at: z.string().optional(), is_finalizable: z.boolean().optional(), finalized_at: z.string().optional(), revision_number: z.number().int().optional()}); export const streemApiGetRoomNoteResponse = z.object({note: streemApiNote.optional(), room_sid: z.string().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 Room Note * * GET /v1/rooms/{room_sid}/note * * Also accepts auth: bearer-auth */ export const getApiV1RoomsRoomSidNote = async (args: GetApiV1RoomsRoomSidNoteArgs, options?: GetApiV1RoomsRoomSidNoteOptions) => { const {baseUrl = "https://api.prod-us.streem.cloud", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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))}/note${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(streemApiGetRoomNoteResponse, await res.json()) };