import {z} from 'zod' export type GetApiV1PropertyPropertyIdActivityArgs = {property_id: string, start_date?: (string | null) | undefined, end_date?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1PropertyPropertyIdActivityOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const tourType = z.enum(["sgt", "guided", "virtual"]); export const appointmentEvent = z.object({event_id: z.string(), type: z.literal("Appointment").optional(), event_date: z.string(), tour_type: tourType, appointment_time: z.string(), appointment_id: z.string(), is_full_day: z.boolean().optional(), virtual_tour_link: z.string().optional()}); export const showEvent = z.object({event_id: z.string(), type: z.literal("Show").optional(), event_date: z.string(), appointment_id: z.string().optional(), access_code: z.string().optional()}); export const noShowEvent = z.object({event_id: z.string(), type: z.literal("NoShow").optional(), event_date: z.string(), appointment_id: z.string()}); export const appointmentCanceledEvent = z.object({event_id: z.string(), type: z.literal("AppointmentCanceled").optional(), event_date: z.string(), appointment_id: z.string()}); export const leadNoteEvent = z.object({event_id: z.string(), type: z.literal("LeadNote").optional(), event_date: z.string(), note: z.string()}); export const senderRole = z.enum(["lead", "elise", "agent", "vendor"]); export const emailEvent = z.object({event_id: z.string(), type: z.literal("Email").optional(), event_date: z.string(), sender: senderRole, subject: z.string(), message: z.string(), to_addresses: z.array(z.string()).optional(), cc_addresses: z.array(z.string()).optional(), from_address: z.string().optional()}); export const textEvent = z.object({event_id: z.string(), type: z.literal("Text").optional(), event_date: z.string(), sender: senderRole, message: z.string(), to_phone_number: z.string().optional(), from_phone_number: z.string().optional()}); export const voiceEvent = z.object({event_id: z.string(), type: z.literal("Voice").optional(), event_date: z.string(), sender: z.string(), summary: z.string()}); export const eliseAIEliseApiModelProspectProspectStatus = z.enum(["ApplicationStarted", "ApplicationCompleted", "ApplicationApproved", "ApplicationRejected", "ApplicationCanceled", "LeaseStarted", "LeaseApproved", "LeasePartiallyCompleted", "LeaseCompleted"]); export const statusUpdatedEvent = z.object({event_id: z.string(), type: z.literal("StatusUpdated").optional(), event_date: z.string(), status: eliseAIEliseApiModelProspectProspectStatus}); export const agentTakeoverEvent = z.object({event_id: z.string(), type: z.literal("AgentTakeover").optional(), event_date: z.string(), reason: z.string().optional()}); export const eliseReactivatedEvent = z.object({event_id: z.string(), type: z.literal("EliseReactivated").optional(), event_date: z.string()}); export const conversationMedium = z.enum(["EMAIL", "SMS", "VOICE"]); export const optOutEvent = z.object({event_id: z.string(), type: z.literal("OptOut").optional(), event_date: z.string(), mediums: z.array(conversationMedium)}); export const optInEvent = z.object({event_id: z.string(), type: z.literal("OptIn").optional(), event_date: z.string(), mediums: z.array(conversationMedium)}); export const webchatEvent = z.object({event_id: z.string(), type: z.literal("Webchat").optional(), event_date: z.string(), sender: z.string(), message: z.string()}); export const surveyLinkType = z.literal("PostTourSurvey"); export const surveyLinkEvent = z.object({event_id: z.string(), type: z.literal("SurveyLink").optional(), event_date: z.string(), survey_link: z.string(), survey_link_type: surveyLinkType}); export const prospectVerificationStatus = z.enum(["NOT_STARTED", "STARTED", "FAILED", "SUCCESSFUL", "ERROR", "EXPIRED", "CANCELLED", "PENDING_REVIEW"]); export const idVerificationStatusEvent = z.object({event_id: z.string(), type: z.literal("IdVerificationStatus").optional(), event_date: z.string(), status: prospectVerificationStatus, provider: z.string(), expiration_date: z.string().optional(), verification_id: z.string().optional(), metadata: z.object({}).optional()}); export const event = z.discriminatedUnion("type", [appointmentEvent, showEvent, noShowEvent, appointmentCanceledEvent, leadNoteEvent, emailEvent, textEvent, voiceEvent, statusUpdatedEvent, agentTakeoverEvent, eliseReactivatedEvent, optOutEvent, optInEvent, webchatEvent, surveyLinkEvent, idVerificationStatusEvent]); export const responsibility = z.enum(["Leasing", "Maintenance", "Billing", "Renewals", "EmergencyMaintenance", "Lockouts", "SafetyAndSecurity", "Concierge"]); export const activity = z.object({event: event, prospect_id: z.string().optional(), resident_id: z.string().optional(), responsibility: responsibility}); export const getApiV1PropertyPropertyIdActivityResponse = z.array(activity); 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 Property Activity * * GET /v1/property/{property_id}/activity */ export const getApiV1PropertyPropertyIdActivity = async (args: GetApiV1PropertyPropertyIdActivityArgs, options?: GetApiV1PropertyPropertyIdActivityOptions) => { const {baseUrl = "https://api.eliseai.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/property/${encodeURIComponent(String(args.property_id))}/activity${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(getApiV1PropertyPropertyIdActivityResponse, await res.json()) };