import {z} from 'zod' export type AdminCallPageTabRequest = 'completed' | 'cancelled' | 'archived'; export type GetApiAdminCallsPageArgs = {tab: AdminCallPageTabRequest, user_id?: (string | null) | undefined, limit: number, cursor?: (string | null) | undefined, search?: (string | null) | undefined}; export type GetApiAdminCallsPageOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const callParticipantRole = z.enum(["PRIMARY", "SECONDARY", "GUEST"]); export const note = z.object({note_id: z.string(), text: z.string().nullable().optional()}); export const callUserAssociationStatusResponse = z.enum(["PENDING", "CONFIRMED", "DECLINED"]); export const callRequestStatus = z.enum(["OPEN", "PAUSED", "CLOSED"]); export const callRequestDepth = z.enum(["LIMITED", "MODERATE", "DEEP"]); export const callRequestPosition = z.enum(["NONE", "BEAR", "BULL", "SKEPTIC"]); export const adminParticipantCallRequestHistoryResponse = z.object({status: callRequestStatus, depth: callRequestDepth.nullable().optional(), position: callRequestPosition, is_priority: z.boolean(), is_high_conviction: z.boolean(), notes: z.string().nullable().optional(), is_open_for_multiple_calls: z.boolean().nullable().optional(), call_ticker_lead_id: z.string().nullable().optional()}); export const callSource = z.enum(["call-dashboard", "mcp", "transcript-call-request-inbound", "earnings-outbound", "earnings-roundtable-outbound", "transcript-call-request-outbound", "weekly-priority-coverage-outbound", "priority-coverage-outbound", "call-schedule-table"]); export const adminParticipantCallTickerLeadResponse = z.object({source: callSource}); export const fundType = z.enum(["LONG_SHORT", "LONG_ONLY", "MARKET_NEUTRAL", "MULTI_STRATEGY"]); export const portfolioStyle = z.enum(["CONCENTRATED", "DIVERSIFIED"]); export const timeHorizon = z.enum(["SHORT_TERM", "MEDIUM_TERM", "LONG_TERM"]); export const notificationLogChannel = z.enum(["EMAIL", "SMS", "IN_APP"]); export const outreachNotificationResponse = z.object({channel: notificationLogChannel, kind: z.string(), sent_at: z.string()}); export const adminParticipantResponse = z.object({association_id: z.string(), user_id: z.string().nullable().optional(), guest_id: z.string().nullable().optional(), guest_name: z.string().nullable().optional(), guest_email: z.string().nullable().optional(), role: callParticipantRole, first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), note: note.nullable().optional(), user_note: z.string().nullable().optional(), is_first_call: z.boolean().nullable().optional(), status: callUserAssociationStatusResponse.nullable().optional(), updated_at: z.string().nullable().optional(), last_calendar_update: z.string().nullable().optional(), analyst_call_name: z.string().nullable().optional(), association_source_id: z.string().nullable().optional(), call_request_history: adminParticipantCallRequestHistoryResponse.nullable().optional(), call_ticker_lead: adminParticipantCallTickerLeadResponse.nullable().optional(), fund_type: fundType.nullable().optional(), portfolio_style: portfolioStyle.nullable().optional(), time_horizon: timeHorizon.nullable().optional(), outreach_notifications: z.array(outreachNotificationResponse).optional()}); export const callStatus = z.enum(["SCHEDULING", "CONFIRMED", "CANCELLED", "RESCHEDULING", "ARCHIVED"]); export const recordingStatus = z.enum(["PENDING", "RECORDING_PROCESSED", "TRANSCRIPT_REVIEW", "CONTENTFUL_REVIEW", "PUBLISHED", "CANCELLED"]); export const adminCallResponse = z.object({call_id: z.string(), participants: z.array(adminParticipantResponse).optional(), ticker: z.string(), status: callStatus, call_link: z.string().nullable(), call_date: z.string().nullable(), calendar_event_id: z.string().nullable().optional(), note: note.nullable().optional(), transcript_ids: z.array(z.string()).optional(), recording_status: recordingStatus.nullable().optional(), updated_at: z.string().nullable().optional(), is_priority: z.boolean().optional(), priority_info: z.record(z.string(), z.string()).optional(), is_live_session: z.boolean().optional(), awaiting_schedule_user_ids: z.array(z.string()).optional(), has_overlapping_availability: z.boolean().optional(), admin_action_required: z.boolean().optional()}); export const adminCallPageResponse = z.object({items: z.array(adminCallResponse), next_cursor: z.string().nullable().optional(), total_count: z.number().int().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 }; /** * List Calls Page * * GET /admin/calls/page */ export const getApiAdminCallsPage = async (args: GetApiAdminCallsPageArgs, options: GetApiAdminCallsPageOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.tab != null) query.append("tab", String(args.tab)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.search != null) query.append("search", String(args.search)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/admin/calls/page${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(adminCallPageResponse, await res.json()) };