import {z} from 'zod' export type GetApiV1CompaniesCompanyCodeOrSidCallLogArgs = {company_code_or_sid: string, page_size?: number | undefined, page_token?: string | undefined, filter?: string | undefined, start_time?: string | undefined, end_time?: string | undefined, group_names?: Array | undefined, call_statuses?: Array | undefined, has_room_notes?: boolean | undefined, call_source_codes?: Array | undefined, filter_transferred?: boolean | undefined}; export type GetApiV1CompaniesCompanyCodeOrSidCallLogOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const streemApiCallLogParticipant = z.object({user_sid: z.string().optional(), external_user_id: z.string().optional(), name: z.string().optional(), avatar_url: z.string().optional(), phone: z.string().optional(), is_expert: z.boolean().optional()}); export const streemApiArtifactCounts = z.object({gps_position: z.number().int().optional(), mesh: z.number().int().optional(), recording: z.number().int().optional(), recording_track: z.number().int().optional(), streemshot: z.number().int().optional(), transcription: z.number().int().optional(), sceneshot: z.number().int().optional(), layout_estimation: z.number().int().optional(), textured_mesh: z.number().int().optional(), bookmark: z.number().int().optional(), room_outcome_report: z.number().int().optional()}); 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 streemApiArtifactGpsPosition = z.object({sourced_from_user_sid: z.string().optional(), sourced_from_device_sid: z.string().optional(), client_created_at: z.string().optional(), latitude_degrees: z.number().optional(), longitude_degrees: z.number().optional(), accuracy_meters: z.number().optional(), formatted_address: z.string().optional(), deleted_at: z.string().optional()}); export const streemApiCallLogRoomInvitation = z.object({from_user: streemApiCallLogParticipant.optional(), to_user: streemApiCallLogParticipant.optional()}); export const googleProtobufDuration = z.object({seconds: z.number().int().optional(), nanos: z.number().int().optional()}); export const streemApiCallLogEntry = z.object({room_sid: z.string().optional(), start_time: z.string().optional(), end_time: z.string().optional(), participants: z.array(streemApiCallLogParticipant).optional(), missed: z.boolean().optional(), onsite: z.boolean().optional(), artifact_counts: streemApiArtifactCounts.optional(), share_url: z.string().optional(), reference_id: z.string().optional(), created_by_user_sid: z.string().optional(), note: streemApiNote.optional(), latest_gps_position: streemApiArtifactGpsPosition.optional(), invitations: z.array(streemApiCallLogRoomInvitation).optional(), favorite: z.boolean().optional(), integration_id: z.string().optional(), call_status: z.enum(["STATUS_SUCCESSFUL", "STATUS_CANCELED", "STATUS_REJECTED", "STATUS_TIMED_OUT", "STATUS_INVALID"]).optional(), canceled_call_ring_time_in_secs: z.string().optional(), call_duration: googleProtobufDuration.optional(), transferred: z.boolean().optional(), requeued: z.boolean().optional()}); export const streemApiGetCompanyCallLogResponse = z.object({call_log_entries: z.array(streemApiCallLogEntry).optional(), next_page_token: z.string().optional(), total_size: 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 }; /** * Get Call Log * * GET /v1/companies/{company_code_or_sid}/call-log * * Also accepts auth: bearer-auth */ export const getApiV1CompaniesCompanyCodeOrSidCallLog = async (args: GetApiV1CompaniesCompanyCodeOrSidCallLogArgs, options?: GetApiV1CompaniesCompanyCodeOrSidCallLogOptions) => { 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 (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) for (const item of args.group_names ?? []) query.append("group_names", String(item)) for (const item of args.call_statuses ?? []) query.append("call_statuses", String(item)) if (args.has_room_notes != null) query.append("has_room_notes", String(args.has_room_notes)) for (const item of args.call_source_codes ?? []) query.append("call_source_codes", String(item)) if (args.filter_transferred != null) query.append("filter_transferred", String(args.filter_transferred)) if (apiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKey.username}:${apiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.company_code_or_sid))}/call-log${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(streemApiGetCompanyCallLogResponse, await res.json()) };