import {z} from 'zod' export type JTLDataContractsKeysWarenlagerKey = string; export type GetApiV2WarehousesWarehouseIdStoragelocationsArgs = {'x-tenant-id': string, pageNumber?: number | undefined, pageSize?: number | undefined, warehouseId: JTLDataContractsKeysWarenlagerKey, 'x-runas'?: string | undefined, 'x-companyid'?: string | undefined}; export type GetApiV2WarehousesWarehouseIdStoragelocationsOptions = {baseUrl?: string | undefined, oauth2AuthorizationCode?: string | undefined, fetch?: typeof fetch | undefined}; export const jTLDataContractsKeysWarenLagerPlatzKey = z.string(); export const jTLDataContractsKeysWarenlagerKey = z.string(); export const jTLWawiRestContractsModelsV1WarehouseStorageLocationType = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), scope: z.array(z.string()).optional()}); export const jTLWawiRestContractsModelsV1CommonDimensions = z.object({length: z.number().optional(), width: z.number().optional(), height: z.number().optional()}); export const jTLWawiRestContractsModelsV1WarehouseStorageLocation = z.object({id: jTLDataContractsKeysWarenLagerPlatzKey.optional(), warehouseId: jTLDataContractsKeysWarenlagerKey.optional(), name: z.string().optional(), storageLocationType: jTLWawiRestContractsModelsV1WarehouseStorageLocationType.optional(), sortNumber: z.number().int().optional(), priority: z.number().int().optional(), lockForShipment: z.boolean().optional(), lockForAvailability: z.boolean().optional(), comment: z.string().optional(), dimensions: jTLWawiRestContractsModelsV1CommonDimensions.optional()}); export const jTLWawiRestContractsModelsPagedListOfJTLWawiRestContractsModelsV1WarehouseStorageLocation = z.object({totalItems: z.number().int().optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), items: z.array(jTLWawiRestContractsModelsV1WarehouseStorageLocation).optional(), totalPages: z.number().int().optional(), hasPreviousPage: z.boolean().optional(), hasNextPage: z.boolean().optional(), nextPageNumber: z.number().int().optional(), previousPageNumber: 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 }; /** * Query Storage Locations * * GET /v2/warehouses/{warehouseId}/storagelocations * * Also accepts auth: oauth2-client-credentials */ export const getApiV2WarehousesWarehouseIdStoragelocations = async (args: GetApiV2WarehousesWarehouseIdStoragelocationsArgs, options?: GetApiV2WarehousesWarehouseIdStoragelocationsOptions) => { const {baseUrl = "https://scx-sbx.api.jtl-software.com", fetch: fetchFn = fetch, oauth2AuthorizationCode} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-tenant-id'] != null) headers.set("x-tenant-id", String(args['x-tenant-id'])) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args['x-runas'] != null) headers.set("x-runas", String(args['x-runas'])) if (args['x-companyid'] != null) headers.set("x-companyid", String(args['x-companyid'])) if (oauth2AuthorizationCode !== undefined) headers.set('authorization', `Bearer ${oauth2AuthorizationCode}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/warehouses/${encodeURIComponent(String(args.warehouseId))}/storagelocations${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(jTLWawiRestContractsModelsPagedListOfJTLWawiRestContractsModelsV1WarehouseStorageLocation, await res.json()) };