import {z} from 'zod' export type GetApiInventoryItemIdIdArgs = {id: string}; export type GetApiInventoryItemIdIdOptions = {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 }; /** * query inventoryItem * * GET /inventoryItem/id/{id} */ export const getApiInventoryItemIdId = async (args: GetApiInventoryItemIdIdArgs, options: GetApiInventoryItemIdIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") 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: "GET", headers}) 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()) };