import {z} from 'zod' export type UpdateApiOrdersOrderIdAttachmentsAttachmentIdArgs = {orderId: number, attachmentId: number, body: string}; export type UpdateApiOrdersOrderIdAttachmentsAttachmentIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({link: z.string().optional()}); export const orderAttachmentGet = z.object({filename: z.string().optional(), printerType: z.enum(["LABEL_PRINTER", "DOCUMENT_PRINTER", "DOCUMENT_PRINTER_2_A6", "DOCUMENT_PRINTER_2_FOLIO"]), attachmentPlacement: z.enum(["INSIDE_PACKAGE", "OUTSIDE_PACKAGE"]), copyCount: z.number().int().gte(1), printingType: z.enum(["ORDER", "SHIPMENT"]).optional(), fileKey: z.string().optional(), mimeType: z.string().optional(), id: z.number().int().optional(), url: link.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 }; /** * Updates the order attachment * * PUT /orders/{orderId}/attachments/{attachmentId} */ export const updateApiOrdersOrderIdAttachmentsAttachmentId = async (args: UpdateApiOrdersOrderIdAttachmentsAttachmentIdArgs, options?: UpdateApiOrdersOrderIdAttachmentsAttachmentIdOptions) => { const {baseUrl = "https://api.quivo.co", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/orders/${encodeURIComponent(String(args.orderId))}/attachments/${encodeURIComponent(String(args.attachmentId))}${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(orderAttachmentGet, await res.json()) };