import {z} from 'zod' export type Visibility = {public?: boolean | undefined, sharedOrganizationIds?: Array | undefined}; export type HistoryItemUpdate = {organizationId?: string | undefined, visibility?: Visibility | undefined}; export type PatchApiApiV1HistoryId4nOrganizationIdSequenceIdArgs = {id4n: string, organizationId: string, sequenceId: number, body: HistoryItemUpdate}; export type PatchApiApiV1HistoryId4nOrganizationIdSequenceIdOptions = {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 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 }; /** * Update history item * * PATCH /api/v1/history/{id4n}/{organizationId}/{sequenceId} */ export const patchApiApiV1HistoryId4nOrganizationIdSequenceId = async (args: PatchApiApiV1HistoryId4nOrganizationIdSequenceIdArgs, options: PatchApiApiV1HistoryId4nOrganizationIdSequenceIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/history/${encodeURIComponent(String(args.id4n))}/${encodeURIComponent(String(args.organizationId))}/${encodeURIComponent(String(args.sequenceId))}${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(historyItem, await res.json()) };