import {z} from 'zod' export type UpdateApiV1Hl7SystemsIdInterfacesInterfaceIdArgs = {id: string, interfaceId: string, body: {name?: string | undefined, messageTypes?: Array | undefined, url?: string | undefined, method?: ('POST' | 'PUT') | undefined, headers?: {[key: string]: string} | undefined, username: unknown, password: unknown, interfaceName: unknown, enabled?: boolean | undefined}}; export type UpdateApiV1Hl7SystemsIdInterfacesInterfaceIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1Hl7SystemsIdInterfacesInterfaceIdResponse = z.object({_id: z.string(), sendingApplication: z.string(), sendingFacility: z.string(), receivingApplication: z.string(), receivingFacility: z.string(), systemKey: z.string(), name: z.string(), status: z.enum(["unmapped", "active", "disabled"]), interfaces: z.array(z.object({id: z.string(), name: z.string(), messageTypes: z.array(z.string()), url: z.string(), method: z.enum(["POST", "PUT"]).optional(), headers: z.record(z.string(), z.string()).optional(), username: z.string().optional(), password: z.string().optional(), interfaceName: z.string().optional(), enabled: z.boolean()})).optional(), brandId: z.string().optional(), autoRegistered: z.boolean().optional(), firstSeenAt: z.string().optional(), lastSeenAt: z.string().optional(), messageCount: z.number().int().optional(), lastMessageType: z.string().optional(), notes: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().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 HL7 System Interface * * PUT /v1/hl7-systems/{id}/interfaces/{interfaceId} */ export const updateApiV1Hl7SystemsIdInterfacesInterfaceId = async (args: UpdateApiV1Hl7SystemsIdInterfacesInterfaceIdArgs, options?: UpdateApiV1Hl7SystemsIdInterfacesInterfaceIdOptions) => { const {baseUrl = "https://api.bluehive.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/hl7-systems/${encodeURIComponent(String(args.id))}/interfaces/${encodeURIComponent(String(args.interfaceId))}${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(updateApiV1Hl7SystemsIdInterfacesInterfaceIdResponse, await res.json()) };