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 BroadcastTemplate = {_id?: IdParam | undefined, user?: UserParam | undefined, deleted?: DeletedParam | undefined, createdBy?: CreatedByParam | undefined, updatedBy?: UpdatedByParam | undefined, createdAt?: CreatedAtParam | undefined, updatedAt?: UpdatedAtParam | undefined, status?: ('draft' | 'complete') | undefined, title?: string | undefined, message?: string | undefined, patientMessageTemplate?: string | undefined, messageOverrides?: (Array<{text?: string | undefined, language?: string | undefined, channel?: string | undefined, subject?: string | undefined, patientMessageTemplate?: IdParam | undefined, secureChat?: boolean | undefined}>) | undefined, messages?: (Array<{enabled?: boolean | undefined, text?: string | undefined, language?: string | undefined, channel?: (Array<'sms' | 'email' | 'voice'>) | undefined, secureChat?: boolean | undefined, subject?: string | undefined, patientMessageTemplate?: IdParam | undefined}>) | undefined, campaign?: string | undefined, mapping?: Record | undefined, secureChat?: boolean | undefined, shouldUseUploadedContacts?: boolean | undefined, shouldUsePrimaryContactOnly?: boolean | undefined, sendAt?: string | undefined, configuration?: ({throttling?: ({enabled?: boolean | undefined, value?: number | undefined, interval?: ({value?: number | undefined, unit?: ('minutes' | 'hours') | undefined}) | undefined}) | undefined, batching?: ({enabled?: boolean | undefined, batchSize?: number | undefined, batchInterval?: number | undefined, batchUnit?: ('minutes' | 'hours') | undefined}) | undefined, contactPreference?: ('all-contacts' | 'active-contact-only' | 'primary-contact-only' | 'uploaded-contact-only') | undefined, messagesPerPatient?: ('one-message-per-patient' | 'multiple-messages-per-patient') | undefined, disabledChannels?: (Array<'sms' | 'email' | 'voice'>) | undefined, scheduledAt?: (string | null) | undefined, filters?: ({estimatedAppointmentCount?: number | undefined, facilities?: Array | undefined, providers?: Array | undefined, appointmentTypes?: Array | undefined, appointmentStatus?: Array | undefined, appointmentDate?: ({startDate?: string | undefined, endDate?: string | undefined, dateFilterType?: ('custom-range' | 'specific-date' | 'after-specific-date') | undefined}) | undefined}) | undefined, appointments?: ({include?: Array | undefined, exclude?: Array | undefined}) | undefined, responseHandling?: ({onResponse?: ('ignore-response' | 'send-to-hub') | undefined, assignee?: string | undefined}) | undefined, rowProcessingRange?: ({from?: number | undefined, to?: number | undefined}) | undefined}) | undefined, allowedSquigglies?: Array | undefined, fileUpload?: IdParam | undefined}; export type UpdateApiBroadcastTemplatesBroadcastTemplateIdArgs = {body: BroadcastTemplate}; export type UpdateApiBroadcastTemplatesBroadcastTemplateIdOptions = {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 broadcastTemplate = z.object({_id: idParam.optional(), user: userParam.optional(), deleted: deletedParam.optional(), createdBy: createdByParam.optional(), updatedBy: updatedByParam.optional(), createdAt: createdAtParam.optional(), updatedAt: updatedAtParam.optional(), status: z.enum(["draft", "complete"]).optional(), title: z.string().optional(), message: z.string().optional(), patientMessageTemplate: z.string().optional(), messageOverrides: z.array(z.object({text: z.string().optional(), language: z.string().optional(), channel: z.string().optional(), subject: z.string().optional(), patientMessageTemplate: idParam.optional(), secureChat: z.boolean().optional()})).optional(), messages: z.array(z.object({enabled: z.boolean().optional(), text: z.string().optional(), language: z.string().optional(), channel: z.array(z.enum(["sms", "email", "voice"])).optional(), secureChat: z.boolean().optional(), subject: z.string().optional(), patientMessageTemplate: idParam.optional()})).optional(), campaign: z.string().optional(), mapping: z.object({}).optional(), secureChat: z.boolean().optional(), shouldUseUploadedContacts: z.boolean().optional(), shouldUsePrimaryContactOnly: z.boolean().optional(), sendAt: z.string().optional(), configuration: z.object({throttling: z.object({enabled: z.boolean().optional(), value: z.number().optional(), interval: z.object({value: z.number().optional(), unit: z.enum(["minutes", "hours"]).optional()}).optional()}).optional(), batching: z.object({enabled: z.boolean().optional(), batchSize: z.number().int().optional(), batchInterval: z.number().int().gte(1).optional(), batchUnit: z.enum(["minutes", "hours"]).optional()}).optional(), contactPreference: z.enum(["all-contacts", "active-contact-only", "primary-contact-only", "uploaded-contact-only"]).optional(), messagesPerPatient: z.enum(["one-message-per-patient", "multiple-messages-per-patient"]).optional(), disabledChannels: z.array(z.enum(["sms", "email", "voice"])).optional(), scheduledAt: z.string().nullable().optional(), filters: z.object({estimatedAppointmentCount: z.number().int().optional(), facilities: z.array(idParam).optional(), providers: z.array(idParam).optional(), appointmentTypes: z.array(idParam).optional(), appointmentStatus: z.array(z.string()).optional(), appointmentDate: z.object({startDate: z.string().optional(), endDate: z.string().optional(), dateFilterType: z.enum(["custom-range", "specific-date", "after-specific-date"]).optional()}).optional()}).optional(), appointments: z.object({include: z.array(idParam).optional(), exclude: z.array(idParam).optional()}).optional(), responseHandling: z.object({onResponse: z.enum(["ignore-response", "send-to-hub"]).optional(), assignee: z.string().optional()}).optional(), rowProcessingRange: z.object({from: z.number().int().optional(), to: z.number().int().optional()}).optional()}).optional(), allowedSquigglies: z.array(z.string()).optional(), fileUpload: idParam.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 broadcast template * * PUT /broadcastTemplates/{broadcastTemplateId} */ export const updateApiBroadcastTemplatesBroadcastTemplateId = async (args: UpdateApiBroadcastTemplatesBroadcastTemplateIdArgs, options?: UpdateApiBroadcastTemplatesBroadcastTemplateIdOptions) => { 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(/\/+$/, '')}/broadcastTemplates/${encodeURIComponent(String(args.broadcastTemplateId))}${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(broadcastTemplate, await res.json()) };