import {z} from 'zod' export type PatchApiV3FulfillmentJobsIdArgs = {id: number, body: {notes?: (string | null) | undefined}}; export type PatchApiV3FulfillmentJobsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const productionJob = z.object({id: z.number().int().optional(), order: z.object({id: z.number().int().optional(), number: z.string().optional(), status: z.string().optional(), client: z.string().nullable().optional(), expected_delivery_at: z.string().nullable().optional()}).optional(), line: z.object({id: z.number().int().optional(), name: z.string().optional(), preview: z.string().nullable().optional(), design_id: z.number().int().nullable().optional()}).optional(), manufacturer_id: z.number().int().nullable().optional(), manufacturer_name: z.string().nullable().optional(), kind: z.enum(["production", "rework"]).optional(), status: z.enum(["pending", "sent", "in_progress", "done", "cancelled"]).optional(), allowed_transitions: z.array(z.string()).optional(), quantity: z.number().int().optional(), stl_url: z.string().nullable().optional(), stl_status: z.enum(["ready", "pending", "failed"]).optional(), stl_error: z.string().nullable().optional(), tech_sheet: z.object({}).optional(), notes: z.string().nullable().optional(), sent_at: z.string().nullable().optional(), started_at: z.string().nullable().optional(), done_at: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: 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 }; /** * Change the job notes * * PATCH /v3/fulfillment/jobs/{id} */ export const patchApiV3FulfillmentJobsId = async (args: PatchApiV3FulfillmentJobsIdArgs, options?: PatchApiV3FulfillmentJobsIdOptions) => { const {baseUrl = "https://api.rhinoartisan.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("apikey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/fulfillment/jobs/${encodeURIComponent(String(args.id))}${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(productionJob, await res.json()) };