import {z} from 'zod' export type GetApiV1PrintJobsIdStopsReceiptIdArgs = {id: number, receiptId: string}; export type GetApiV1PrintJobsIdStopsReceiptIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1PrintJobsIdStopsReceiptIdResponse = z.object({id: z.string(), job_id: z.number().int().gte(1), printer_id: z.string(), start_attempt_id: z.string(), claim_generation: z.string(), expected_device_task_id: z.string(), command_outcome: z.enum(["unknown", "acknowledged", "rejected", "not_delivered"]), confirmation: z.enum(["pending", "confirmed", "unconfirmed", "rejected", "already_ended", "unsupported"]), requested_at: z.string(), deadline_at: z.string(), confirmed_at: z.string().nullable(), abort_acknowledged: z.boolean().optional(), reason: z.enum(["printer_family_unsupported", "job_already_ended"]).nullable(), printerFamily: z.string().nullable(), jobStatus: z.string(), message: z.string().nullable()}); 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 }; /** * Recover a Stop receipt using fresh observation without another abort * * GET /v1/print-jobs/{id}/stops/{receiptId} * * Also accepts auth: bearerAuth */ export const getApiV1PrintJobsIdStopsReceiptId = async (args: GetApiV1PrintJobsIdStopsReceiptIdArgs, options?: GetApiV1PrintJobsIdStopsReceiptIdOptions) => { const {baseUrl = "https://api.printhiv3d.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/print-jobs/${encodeURIComponent(String(args.id))}/stops/${encodeURIComponent(String(args.receiptId))}${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(getApiV1PrintJobsIdStopsReceiptIdResponse, await res.json()) };