import {z} from 'zod' export type LumabotFlowRequest = {patient?: string | undefined, status?: ('started' | 'completed') | undefined, flowType?: ('welcome' | 'authenticate-patient' | 'speak-with-staff' | 'session-timeout' | 'knock-knock' | 'cul-de-sac' | 'feedback' | 'error' | 'no-availabilities' | 'regular') | undefined, completedAt?: string | undefined, processingStatus?: ('open' | 'in-progress' | 'closed') | undefined, processingStatusUpdatedBy?: string | undefined, processingStatusUpdatedAt?: string | undefined, appointment?: string | undefined, url?: string | undefined, currentItemId?: string | undefined, lumabotFlowTemplate?: string | undefined, lumabotFlowTemplateName?: string | undefined, language?: ('en' | 'es' | 'pt') | undefined, accessedFrom?: string | undefined, previousLumabotFlow?: string | undefined, nextLumabotFlow?: string | undefined, questions?: (Array<{answer?: ({id?: string | undefined, text?: string | undefined, createdAt: unknown, details?: Record | undefined}) | undefined, askedAt: unknown, id?: string | undefined, type?: string | undefined, squiggly?: string | undefined, title?: string | undefined, redirectType?: ('none' | 'goTo' | 'goToFlow' | 'goToPrevious' | 'isFinal' | 'externalUrl' | 'scheduler') | undefined, redirectValue?: string | undefined, validations?: ({required?: boolean | undefined}) | undefined, properties?: ({template?: string | undefined}) | undefined}>) | undefined, availabilities?: Array | undefined, facilities?: Array | undefined}; export type UpdateApiLumabotFlowsLumabotFlowIdArgs = {lumabotFlowId: string, body: LumabotFlowRequest}; export type UpdateApiLumabotFlowsLumabotFlowIdOptions = {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 lumabotFlowResponse = z.object({_id: idParam.optional(), user: userParam.optional(), deleted: deletedParam.optional(), createdBy: createdByParam.optional(), updatedBy: updatedByParam.optional(), createdAt: createdAtParam.optional(), updatedAt: updatedAtParam.optional(), patient: z.string().min(24).max(24).optional(), status: z.enum(["started", "completed"]).optional(), flowType: z.enum(["welcome", "authenticate-patient", "speak-with-staff", "session-timeout", "knock-knock", "cul-de-sac", "feedback", "error", "no-availabilities", "regular"]).optional(), completedAt: z.string().optional(), processingStatus: z.enum(["open", "in-progress", "closed"]).optional(), processingStatusUpdatedBy: z.string().min(24).max(24).optional(), processingStatusUpdatedAt: z.string().optional(), appointment: z.string().min(24).max(24).optional(), url: z.string().optional(), currentItemId: z.string().optional(), lumabotFlowTemplate: z.string().min(24).max(24).optional(), lumabotFlowTemplateName: z.string().optional(), language: z.enum(["en", "es", "pt"]).optional(), accessedFrom: z.string().optional(), previousLumabotFlow: z.string().min(24).max(24).optional(), nextLumabotFlow: z.string().min(24).max(24).optional(), questions: z.array(z.object({answer: z.object({id: z.string().optional(), text: z.string().optional(), createdAt: z.unknown(), details: z.object({}).optional()}).optional(), askedAt: z.unknown(), id: z.string().optional(), type: z.string().optional(), squiggly: z.string().optional(), title: z.string().optional(), redirectType: z.enum(["none", "goTo", "goToFlow", "goToPrevious", "isFinal", "externalUrl", "scheduler"]).optional(), redirectValue: z.string().optional(), validations: z.object({required: z.boolean().optional()}).optional(), properties: z.object({template: z.string().optional()}).optional()})).optional(), availabilities: z.array(z.string().min(24).max(24)).optional(), facilities: z.array(z.string().min(24).max(24)).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 a lumabotFlow * * PUT /lumabotFlows/{lumabotFlowId} */ export const updateApiLumabotFlowsLumabotFlowId = async (args: UpdateApiLumabotFlowsLumabotFlowIdArgs, options?: UpdateApiLumabotFlowsLumabotFlowIdOptions) => { 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(/\/+$/, '')}/lumabotFlows/${encodeURIComponent(String(args.lumabotFlowId))}${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(lumabotFlowResponse, await res.json()) };