import {z} from 'zod' export type InventorySerialNumber = {serialNumber: string, status: 'CHECKED' | 'EXPECTED' | 'MANUALLY' | 'MISSING'}; export type InventoryItem = {id?: string | undefined, version?: string | undefined, articleId?: string | undefined, batchNumber?: string | undefined, comment?: string | undefined, countedQuantity?: unknown | undefined, createdDate?: number | undefined, expectedQuantity?: unknown | undefined, expirationDate?: number | undefined, inboundDate?: number | undefined, inventoryId: string, inventorySerialNumbers?: Array | undefined, inventoryTransportReferenceId?: string | undefined, lastModifiedDate?: number | undefined, manualPosition?: boolean | undefined, orderItemId?: string | undefined, positionNumber?: string | undefined, replacementValue?: unknown | undefined, storagePlaceId?: string | undefined}; export type UpdateApiInventoryItemIdIdArgs = {id: string, dryRun?: boolean | undefined, body: InventoryItem}; export type UpdateApiInventoryItemIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const inventorySerialNumber = z.object({serialNumber: z.string(), status: z.enum(["CHECKED", "EXPECTED", "MANUALLY", "MISSING"])}); export const inventoryItem = z.object({id: z.string().optional(), version: z.string().optional(), articleId: z.string().optional(), batchNumber: z.string().optional(), comment: z.string().optional(), countedQuantity: z.string().optional(), createdDate: z.number().int().optional(), expectedQuantity: z.string().optional(), expirationDate: z.number().int().optional(), inboundDate: z.number().int().optional(), inventoryId: z.string(), inventorySerialNumbers: z.array(inventorySerialNumber).optional(), inventoryTransportReferenceId: z.string().optional(), lastModifiedDate: z.number().int().optional(), manualPosition: z.boolean().optional(), orderItemId: z.string().optional(), positionNumber: z.string().optional(), replacementValue: z.string().optional(), storagePlaceId: 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 }; /** * update inventoryItem * * PUT /inventoryItem/id/{id} */ export const updateApiInventoryItemIdId = async (args: UpdateApiInventoryItemIdIdArgs, options: UpdateApiInventoryItemIdIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/inventoryItem/id/${encodeURIComponent(String(args.id))}${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(inventoryItem, await res.json()) };