import {z} from 'zod' export type GetApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItemsArgs = {warehouseId: string, storageLocationId: string}; export type GetApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItemsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItemsResponse = z.object({data: z.array(z.object({productId: z.string().optional(), sku: z.string().optional(), quantity: z.number().optional(), qualityControlAttributes: z.array(z.object({quantity: z.number().optional(), batch: z.string().nullable().optional(), bestBeforeDate: z.string().nullable().optional(), serialNumbers: z.array(z.object({number: z.string().optional()})).optional()})).optional()})).optional(), extra: z.object({totalCount: z.number().int(), page: z.object({number: z.number().int(), size: 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 }; /** * List storage items V2 * * GET /api/v2/warehouses/{warehouseId}/storageLocations/{storageLocationId}/items */ export const getApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItems = async (args: GetApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItemsArgs, options?: GetApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItemsOptions) => { const {baseUrl = "https://xentral.xentral.biz", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/warehouses/${encodeURIComponent(String(args.warehouseId))}/storageLocations/${encodeURIComponent(String(args.storageLocationId))}/items${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(getApiApiV2WarehousesWarehouseIdStorageLocationsStorageLocationIdItemsResponse, await res.json()) };