import {z} from 'zod' export type GetApiV1ItemQuantitiesStockValueArgs = {locationId?: number | undefined, itemId?: number | undefined, wmsLocationId?: string | undefined, itemBatch?: string | undefined, Filter?: string | undefined, Page?: number | undefined, PageSize?: number | undefined, SortColumn?: string | undefined, SortOrder?: string | undefined, asOf: string, showZero?: boolean | undefined, showOnlyIlpOnHand?: boolean | undefined, Account: unknown}; export type GetApiV1ItemQuantitiesStockValueOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const inventDimResponse = z.object({id: z.number().int().optional(), locationId: z.number().int().nullable().optional(), locationName: z.string().nullable().optional(), wmsLocationId: z.string().nullable().optional(), batchId: z.string().nullable().optional()}); export const itemStockValueResponse = z.object({itemId: z.number().int().optional(), name: z.string().nullable().optional(), code: z.string().nullable().optional(), qty: z.number().optional(), inventDim: inventDimResponse.optional(), salesValue: z.number().optional(), purchaseValue: z.number().optional()}); export const itemStockValueResponsePagedResult = z.object({pageSize: z.number().int().optional(), page: z.number().int().optional(), totalCount: z.number().int().optional(), filteredCount: z.number().int().optional(), data: z.array(itemStockValueResponse).nullable().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 }; /** * Get the stock value for location items * * GET /v1/ItemQuantities/stockValue */ export const getApiV1ItemQuantitiesStockValue = async (args: GetApiV1ItemQuantitiesStockValueArgs, options: GetApiV1ItemQuantitiesStockValueOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.locationId != null) query.append("locationId", String(args.locationId)) if (args.itemId != null) query.append("itemId", String(args.itemId)) if (args.wmsLocationId != null) query.append("wmsLocationId", String(args.wmsLocationId)) if (args.itemBatch != null) query.append("itemBatch", String(args.itemBatch)) if (args.Filter != null) query.append("Filter", String(args.Filter)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.SortColumn != null) query.append("SortColumn", String(args.SortColumn)) if (args.SortOrder != null) query.append("SortOrder", String(args.SortOrder)) if (args.asOf != null) query.append("asOf", String(args.asOf)) if (args.showZero != null) query.append("showZero", String(args.showZero)) if (args.showOnlyIlpOnHand != null) query.append("showOnlyIlpOnHand", String(args.showOnlyIlpOnHand)) if (args.Account != null) query.append("Account", String(args.Account)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/ItemQuantities/stockValue${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(itemStockValueResponsePagedResult, await res.json()) };