import {z} from 'zod' export type GetApiV1WMSLocationsLocationIdAddressesArgs = {locationId: number, WMSAreaId?: string | undefined, Rack?: number | undefined, Shelf?: number | undefined, Bin?: number | undefined, WithoutGravity?: boolean | undefined, Filter?: string | undefined, Page?: number | undefined, PageSize?: number | undefined, SortColumn?: string | undefined, SortOrder?: string | undefined, Account: unknown}; export type GetApiV1WMSLocationsLocationIdAddressesOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const wMSLocationResponse = z.object({id: z.number().int().optional(), wmsLocationId: z.string().nullable().optional(), areaId: z.number().int().nullable().optional(), wmsAreaId: z.string().nullable().optional(), wmsAreaType: z.number().int().nullable().optional(), rack: z.number().int().nullable().optional(), shelf: z.number().int().nullable().optional(), bin: z.number().int().nullable().optional(), isDefault: z.boolean().nullable().optional()}); export const getApiV1WMSLocationsLocationIdAddressesResponse = z.array(wMSLocationResponse); 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 wms addresses * * GET /v1/WMSLocations/{locationId}/addresses */ export const getApiV1WMSLocationsLocationIdAddresses = async (args: GetApiV1WMSLocationsLocationIdAddressesArgs, options: GetApiV1WMSLocationsLocationIdAddressesOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.WMSAreaId != null) query.append("WMSAreaId", String(args.WMSAreaId)) if (args.Rack != null) query.append("Rack", String(args.Rack)) if (args.Shelf != null) query.append("Shelf", String(args.Shelf)) if (args.Bin != null) query.append("Bin", String(args.Bin)) if (args.WithoutGravity != null) query.append("WithoutGravity", String(args.WithoutGravity)) 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/WMSLocations/${encodeURIComponent(String(args.locationId))}/addresses${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(getApiV1WMSLocationsLocationIdAddressesResponse, await res.json()) };