import {z} from 'zod' export type GetApiApiV1PublicHistoryId4nArgs = {id4n: string, offset?: number | undefined, limit?: number | undefined}; export type GetApiApiV1PublicHistoryId4nOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const visibility = z.object({public: z.boolean().optional(), sharedOrganizationIds: z.array(z.string()).optional()}); export const historyItem = z.object({additionalProperties: z.record(z.string(), z.string()).optional(), organizationId: z.string(), ownerOrganizationId: z.string().optional(), sequenceId: z.number().int().optional(), timestamp: z.number().int().optional(), type: z.enum(["CREATED", "DESTROYED", "RECYCLED", "SHIPMENT_PREPARED", "STORED", "RETRIEVED_FROM_STORAGE", "PACKAGED", "DISPATCHED", "RECEIVED", "DELIVERY_REFUSED", "REPROCESSING_STARTED", "REPROCESSING_STEP_STARTED", "REPROCESSING_STEP_CANCELLED", "REPROCESSING_STEP_FINISHED", "REPROCESSING_CANCELLED", "REPROCESSING_FINISHED", "DISASSEMBLED", "MAINTENANCE_STARTED", "MAINTENANCE_STEP_STARTED", "MAINTENANCE_STEP_CANCELLED", "MAINTENANCE_STEP_FINISHED", "MAINTENANCE_CANCELLED", "MAINTENANCE_FINISHED", "PRODUCTION_STARTED", "PRODUCTION_CANCELLED", "PRODUCTION_FINISHED", "PRODUCTION_STEP_STARTED", "PRODUCTION_STEP_CANCELLED", "PRODUCTION_STEP_FINISHED", "QUALITY_CHECK_PERFORMED"]), visibility: visibility.optional()}); export const paginatedResponseOfHistoryItem = z.object({elements: z.array(historyItem), limit: z.number().int(), offset: z.number().int(), total: z.number().int().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 }; /** * Shows the public history of the given GUID * * GET /api/v1/public/history/{id4n} */ export const getApiApiV1PublicHistoryId4n = async (args: GetApiApiV1PublicHistoryId4nArgs, options: GetApiApiV1PublicHistoryId4nOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/public/history/${encodeURIComponent(String(args.id4n))}${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(paginatedResponseOfHistoryItem, await res.json()) };