import {z} from 'zod' export type CreateApiLuccaFilesApiUploadsArgs = {Accept: 'application/json', 'Content-Type': 'multipart/form-data', body: BodyInit}; export type CreateApiLuccaFilesApiUploadsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const file = z.object({id: z.string().optional(), name: z.string().optional(), createdAt: z.string().optional(), deletedAt: z.string().nullable().optional(), contentLength: z.number().int().gte(1).optional(), contentType: z.enum(["eml message/rfc822", "image/heic", "image/heif", "image/jpe", "image/jpg", "image/pjpeg", "image/gif", "image/bmp", "image/tif", "image/tiff", "image/x-dcraw", "image/x-jb2", "image/x-jbig2", "image/x-jpf", "image/x-ms-bmp", "image/x-panasonic-raw", "image/x-pcx", "image/x-icon", "image/x-png", "image/vnd.microsoft.icon", "image/webp", "image/x-portable-anymap", "text/plain", "text/csv", "text/rtf", "text/calendar", "text/comma-separated-values", "text/markdown", "application/pdf", "application/msword", "application/xls", "application/x-csv", "application/ms-excel", "application/vnd.ms-office", "application/vnd.ms-word", "application/vnd.ms-outlook", "application/vnd.ms-powerpoint", "application/vnd.ms-excel", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.oasis.opendocument.presentation", "application/vnd.oasis.opendocument.graphics", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "application/vnd.openxmlformats-officedocument.presentationml.template", "application/x-7z-compressed", "application/rar", "application/x-rar", "application/zip", "application/csv", "application/rtf", "application/text", "application/txt", "application/x-pdf"]).optional(), extension: z.string().optional(), totalPages: z.number().int().gte(0).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 }; /** * Upload a file * * POST /lucca-files/api/uploads */ export const createApiLuccaFilesApiUploads = async (args: CreateApiLuccaFilesApiUploadsArgs, options?: CreateApiLuccaFilesApiUploadsOptions) => { const {baseUrl = "https://example.ilucca.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) const url = `${baseUrl.replace(/\/+$/, '')}/lucca-files/api/uploads${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(file, await res.json()) };