import {z} from 'zod' export type IdParam = string; export type UserParam = string; export type DeletedParam = number; export type CreatedByParam = string; export type UpdatedByParam = string; export type CreatedAtParam = string; export type UpdatedAtParam = string; export type Reminder = {_id?: IdParam | undefined, user?: UserParam | undefined, deleted?: DeletedParam | undefined, createdBy?: CreatedByParam | undefined, updatedBy?: UpdatedByParam | undefined, createdAt?: CreatedAtParam | undefined, updatedAt?: UpdatedAtParam | undefined, provider?: string | undefined, appointment?: string | undefined, referral?: string | undefined, recall?: string | undefined, telehealth?: string | undefined, followup?: string | undefined, followupOperation?: ('created' | 'deleted' | 'updated') | undefined, facility?: string | undefined, patient?: string | undefined, patientForm?: string | undefined, message?: string | undefined, type?: ('appointment' | 'feedback' | 'referral' | 'outbound-referral' | 'followup' | 'patient-form' | 'recall' | 'telehealth' | 'waiting-room') | undefined, externalId?: ({source?: ('mandrill' | 'twilio' | 'nexmo' | 'sendgrid' | 'plivo' | 'awsses') | undefined, value?: string | undefined}) | undefined, sendAt?: string | undefined, sentAt?: string | undefined, contact?: Array | undefined, messageTemplate?: string | undefined, status?: ('scheduled' | 'pending' | 'queued' | 'sent' | 'confirmed' | 'emailOpened' | 'skipped' | 'delivered' | 'blocked') | undefined, statusReason?: string | undefined, replied?: number | undefined, repliedMessage?: string | undefined, originalRepliedMessage?: string | undefined, repliedTime?: string | undefined, paritalStatus?: (Array<{status?: ('scheduled' | 'pending' | 'queued' | 'sent' | 'confirmed' | 'emailOpened' | 'skipped' | 'delivered' | 'blocked') | undefined, statusReason?: string | undefined, channel?: ('sms' | 'email' | 'voice' | 'inapp' | 'chat' | 'fax' | 'whatsapp') | undefined, message?: string | undefined}>) | undefined, forcedTime?: boolean | undefined}; export type CreateApiRemindersArgs = {body: Reminder}; export type CreateApiRemindersOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const idParam = z.string().min(24).max(24); export const userParam = z.string().min(24).max(24); export const deletedParam = z.union([z.literal(0), z.literal(1)]); export const createdByParam = z.string().min(24).max(24); export const updatedByParam = z.string().min(24).max(24); export const createdAtParam = z.string(); export const updatedAtParam = z.string(); export const reminder = z.object({_id: idParam.optional(), user: userParam.optional(), deleted: deletedParam.optional(), createdBy: createdByParam.optional(), updatedBy: updatedByParam.optional(), createdAt: createdAtParam.optional(), updatedAt: updatedAtParam.optional(), provider: z.string().min(24).max(24).optional(), appointment: z.string().min(24).max(24).optional(), referral: z.string().min(24).max(24).optional(), recall: z.string().min(24).max(24).optional(), telehealth: z.string().min(24).max(24).optional(), followup: z.string().min(24).max(24).optional(), followupOperation: z.enum(["created", "deleted", "updated"]).optional(), facility: z.string().min(24).max(24).optional(), patient: z.string().min(24).max(24).optional(), patientForm: z.string().min(24).max(24).optional(), message: z.string().min(24).max(24).optional(), type: z.enum(["appointment", "feedback", "referral", "outbound-referral", "followup", "patient-form", "recall", "telehealth", "waiting-room"]).optional(), externalId: z.object({source: z.enum(["mandrill", "twilio", "nexmo", "sendgrid", "plivo", "awsses"]).optional(), value: z.string().optional()}).optional(), sendAt: z.string().optional(), sentAt: z.string().optional(), contact: z.array(z.string()).optional(), messageTemplate: z.string().optional(), status: z.enum(["scheduled", "pending", "queued", "sent", "confirmed", "emailOpened", "skipped", "delivered", "blocked"]).optional(), statusReason: z.string().optional(), replied: z.number().int().optional(), repliedMessage: z.string().optional(), originalRepliedMessage: z.string().optional(), repliedTime: z.string().optional(), paritalStatus: z.array(z.object({status: z.enum(["scheduled", "pending", "queued", "sent", "confirmed", "emailOpened", "skipped", "delivered", "blocked"]).optional(), statusReason: z.string().optional(), channel: z.enum(["sms", "email", "voice", "inapp", "chat", "fax", "whatsapp"]).optional(), message: z.string().min(24).max(24).optional()})).optional(), forcedTime: z.boolean().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 }; /** * Create reminder * * POST /reminders */ export const createApiReminders = async (args: CreateApiRemindersArgs, options?: CreateApiRemindersOptions) => { const {baseUrl = "https://api.lumahealth.io/api/v2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/reminders${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(reminder, await res.json()) };