import {z} from 'zod' export type GetApiOrdersOrderIdInternalDocumentsArgs = {orderId: number, uploadedBy?: number | undefined, search?: string | undefined, sortBy?: ('id' | 'createdAt' | 'updatedAt' | 'title' | 'originalFileName' | 'orderId') | undefined, sortType?: ('ASC' | 'DESC') | undefined, page: number, size: number}; export type GetApiOrdersOrderIdInternalDocumentsOptions = {baseUrl?: string | undefined, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const internalDocumentUploaderDto = z.object({id: z.number(), firstName: z.string(), lastName: z.string(), email: z.string()}); export const orderInternalDocumentDto = z.object({id: z.number(), orderId: z.number(), fileName: z.string(), originalFileName: z.string(), filePath: z.string(), mimeType: z.string().optional(), fileSize: z.number().optional(), uploadedBy: z.number(), uploadedByUser: internalDocumentUploaderDto.nullable().optional(), title: z.string().optional(), notes: z.string().optional(), createdAt: z.string(), updatedAt: z.string()}); export const orderInternalDocumentListResponseDto = z.object({totalItems: z.number(), items: z.array(orderInternalDocumentDto), page: z.number(), size: z.number()}); 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 }; /** * List internal documents for an order * * GET /orders/{orderId}/internal-documents */ export const getApiOrdersOrderIdInternalDocuments = async (args: GetApiOrdersOrderIdInternalDocumentsArgs, options?: GetApiOrdersOrderIdInternalDocumentsOptions) => { const {baseUrl = "https://api.findmydocument.net", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.uploadedBy != null) query.append("uploadedBy", String(args.uploadedBy)) if (args.search != null) query.append("search", String(args.search)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.sortType != null) query.append("sortType", String(args.sortType)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders/${encodeURIComponent(String(args.orderId))}/internal-documents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(orderInternalDocumentListResponseDto, await res.json()) };