import {z} from 'zod' export type GetApiV1WMSItemLocationParamsArgs = {locationId?: number | undefined, itemId?: number | undefined, vendorAccountId?: number | undefined, Filter?: string | undefined, Page?: number | undefined, PageSize?: number | undefined, SortColumn?: string | undefined, SortOrder?: string | undefined, Account: unknown}; export type GetApiV1WMSItemLocationParamsOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const ilpServiceLevel = z.union([z.literal(70), z.literal(95), z.literal(99), z.literal(100)]); export const weightType = z.union([z.literal(0), z.literal(1)]); export const itemLocationBarcodeResponse = z.object({barcode: z.string().nullable().optional(), unitId: z.string().nullable().optional(), weight: z.number().optional(), weightType: weightType.optional(), isWeightAdjusted: z.boolean().optional()}); export const itemLocationParamsResponse = z.object({id: z.number().int().optional(), itemId: z.number().int().optional(), itemCode: z.string().nullable().optional(), itemName: z.string().nullable().optional(), inventDimId: z.number().int().optional(), locationId: z.number().int().optional(), locationName: z.string().nullable().optional(), wmsLocationId: z.string().nullable().optional(), wmsAreaType: z.number().int().nullable().optional(), bufferLevel: z.number().optional(), minOrderQty: z.number().optional(), orderUnitId: z.string().nullable().optional(), minSalesQty: z.number().optional(), salesUnitId: z.string().nullable().optional(), dlvIntervalDays: z.number().int().optional(), dlvDurationDays: z.number().int().optional(), vendorAccountId: z.number().int().nullable().optional(), vendorAccountName: z.string().nullable().optional(), vendorAccountCode: z.string().nullable().optional(), serviceLevel: ilpServiceLevel.optional(), barcodes: z.array(itemLocationBarcodeResponse).nullable().optional(), deL_Alternatives: z.array(z.string()).nullable().optional(), imageUrl: z.string().nullable().optional()}); export const getApiV1WMSItemLocationParamsResponse = z.array(itemLocationParamsResponse); 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 location item parameters * * GET /v1/WMSItemLocationParams */ export const getApiV1WMSItemLocationParams = async (args: GetApiV1WMSItemLocationParamsArgs, options: GetApiV1WMSItemLocationParamsOptions) => { 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.vendorAccountId != null) query.append("vendorAccountId", String(args.vendorAccountId)) 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.Account != null) query.append("Account", String(args.Account)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/WMSItemLocationParams${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(getApiV1WMSItemLocationParamsResponse, await res.json()) };