import {z} from 'zod' export type UpdateReferralDocumentRequest = {description?: (string | null) | undefined}; export type PatchApiPublicRdvmReferralsReferralIdDocumentsDocumentIdArgs = {referralId: string, documentId: string, sessionId?: string | undefined, clinicId?: string | undefined, body: UpdateReferralDocumentRequest}; export type PatchApiPublicRdvmReferralsReferralIdDocumentsDocumentIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const rdvmDocumentDto = z.object({id: z.string().optional(), referralId: z.string().optional(), documentType: z.string().optional(), fileName: z.string().optional(), description: z.string().nullable().optional(), fileSizeBytes: z.union([z.number().int(), z.string()]).optional(), mimeType: z.string().nullable().optional(), uploadedByName: z.string().nullable().optional(), uploadedAt: z.string().optional(), isSent: z.boolean().optional(), sentAt: z.string().nullable().optional(), source: z.string().optional(), canDelete: 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 }; /** * Update the description on a referral document (RDVM can only update their own uploads) * * PATCH /public/rdvm/referrals/{referralId}/documents/{documentId} */ export const patchApiPublicRdvmReferralsReferralIdDocumentsDocumentId = async (args: PatchApiPublicRdvmReferralsReferralIdDocumentsDocumentIdArgs, options?: PatchApiPublicRdvmReferralsReferralIdDocumentsDocumentIdOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", 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 (args.sessionId != null) query.append("sessionId", String(args.sessionId)) if (args.clinicId != null) query.append("clinicId", String(args.clinicId)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/rdvm/referrals/${encodeURIComponent(String(args.referralId))}/documents/${encodeURIComponent(String(args.documentId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(rdvmDocumentDto, await res.json()) };