import {z} from 'zod' export type UcEmail = {email: string, type?: ('WORK' | 'HOME' | 'OTHER') | undefined}; export type PropertyUcContactEmails = Array; export type UcTelephone = {telephone: string, type?: ('WORK' | 'HOME' | 'OTHER' | 'FAX' | 'MOBILE') | undefined}; export type PropertyUcContactTelephones = Array; export type UcMetadata = {id?: string | undefined, slug?: string | undefined, value?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined, namespace?: string | undefined, format?: ('TEXT' | 'NUMBER' | 'DATE' | 'BOOLEAN' | 'FILE' | 'TEXTAREA' | 'SINGLE_SELECT' | 'MULTIPLE_SELECT' | 'MEASUREMENT' | 'PRICE' | 'YES_NO' | 'CURRENCY' | 'URL') | undefined, extra_data?: ({[key: string]: unknown} | string | number | boolean | Array | string | number | boolean>) | undefined}; export type PropertyUcContactMetadata = Array; export type UcContact = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, name?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, title?: string | undefined, company?: string | undefined, emails?: PropertyUcContactEmails | undefined, telephones?: PropertyUcContactTelephones | undefined, metadata?: PropertyUcContactMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type PropertyUcRecordingContacts = Array; export type UcRecordingTranscript = {start_at?: string | undefined, end_at?: string | undefined, text: string, contact_id?: string | undefined, user_id?: string | undefined}; export type PropertyUcRecordingMediaTranscripts = Array; export type UcRecordingMedia = {start_at?: string | undefined, end_at?: string | undefined, language?: string | undefined, transcripts?: PropertyUcRecordingMediaTranscripts | undefined, transcript_download_url?: string | undefined, recording_download_url?: string | undefined}; export type PropertyUcRecordingMedia = Array; export type PropertyUcRecordingMetadata = Array; export type UcRecording = {id?: string | undefined, created_at?: string | undefined, updated_at?: string | undefined, start_at?: string | undefined, end_at?: string | undefined, expires_at?: string | undefined, call_id?: string | undefined, web_url?: string | undefined, contacts?: PropertyUcRecordingContacts | undefined, user_id?: string | undefined, media?: PropertyUcRecordingMedia | undefined, user_name?: string | undefined, user_phone?: string | undefined, type?: ('INBOUND' | 'OUTBOUND') | undefined, conversation_identifier?: string | undefined, metadata?: PropertyUcRecordingMetadata | undefined, raw?: {[key: string]: unknown} | undefined}; export type UpdateApiUcConnectionIdRecordingIdArgs = {fields?: (Array<'id' | 'created_at' | 'updated_at' | 'start_at' | 'end_at' | 'expires_at' | 'call_id' | 'web_url' | 'contacts' | 'user_id' | 'media' | 'user_name' | 'user_phone' | 'type' | 'conversation_identifier' | 'metadata' | 'raw'>) | undefined, raw?: string | undefined, connection_id: string, id: string, body: UcRecording}; export type UpdateApiUcConnectionIdRecordingIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const ucEmail = z.object({email: z.string(), type: z.enum(["WORK", "HOME", "OTHER"]).optional()}); export const propertyUcContactEmails = z.array(ucEmail); export const ucTelephone = z.object({telephone: z.string(), type: z.enum(["WORK", "HOME", "OTHER", "FAX", "MOBILE"]).optional()}); export const propertyUcContactTelephones = z.array(ucTelephone); export const ucMetadata = z.object({id: z.string().optional(), slug: z.string().optional(), value: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional(), namespace: z.string().optional(), format: z.enum(["TEXT", "NUMBER", "DATE", "BOOLEAN", "FILE", "TEXTAREA", "SINGLE_SELECT", "MULTIPLE_SELECT", "MEASUREMENT", "PRICE", "YES_NO", "CURRENCY", "URL"]).optional(), extra_data: z.union([z.record(z.string(), z.unknown()), z.string(), z.number(), z.boolean(), z.array(z.union([z.object({}), z.string(), z.number(), z.boolean()]))]).optional()}); export const propertyUcContactMetadata = z.array(ucMetadata); export const ucContact = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), title: z.string().optional(), company: z.string().optional(), emails: propertyUcContactEmails.optional(), telephones: propertyUcContactTelephones.optional(), metadata: propertyUcContactMetadata.optional(), raw: z.record(z.string(), z.unknown()).optional()}); export const propertyUcRecordingContacts = z.array(ucContact); export const ucRecordingTranscript = z.object({start_at: z.string().optional(), end_at: z.string().optional(), text: z.string(), contact_id: z.string().optional(), user_id: z.string().optional()}); export const propertyUcRecordingMediaTranscripts = z.array(ucRecordingTranscript); export const ucRecordingMedia = z.object({start_at: z.string().optional(), end_at: z.string().optional(), language: z.string().optional(), transcripts: propertyUcRecordingMediaTranscripts.optional(), transcript_download_url: z.string().optional(), recording_download_url: z.string().optional()}); export const propertyUcRecordingMedia = z.array(ucRecordingMedia); export const propertyUcRecordingMetadata = z.array(ucMetadata); export const ucRecording = z.object({id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), start_at: z.string().optional(), end_at: z.string().optional(), expires_at: z.string().optional(), call_id: z.string().optional(), web_url: z.string().optional(), contacts: propertyUcRecordingContacts.optional(), user_id: z.string().optional(), media: propertyUcRecordingMedia.optional(), user_name: z.string().optional(), user_phone: z.string().optional(), type: z.enum(["INBOUND", "OUTBOUND"]).optional(), conversation_identifier: z.string().optional(), metadata: propertyUcRecordingMetadata.optional(), raw: z.record(z.string(), z.unknown()).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 }; /** * Update a recording * * PUT /uc/{connection_id}/recording/{id} */ export const updateApiUcConnectionIdRecordingId = async (args: UpdateApiUcConnectionIdRecordingIdArgs, options?: UpdateApiUcConnectionIdRecordingIdOptions) => { const {baseUrl = "https://api.unified.to", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.raw != null) query.append("raw", String(args.raw)) if (jwt !== undefined) headers.set("authorization", jwt) const url = `${baseUrl.replace(/\/+$/, '')}/uc/${encodeURIComponent(String(args.connection_id))}/recording/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(ucRecording, await res.json()) };