import {z} from 'zod' export type CubicDimension = {height?: number | undefined, length?: number | undefined, width?: number | undefined}; export type Weight = {weight?: number | undefined, weightUnit?: ('LB' | 'KG') | undefined}; export type DimensionalWeight = {cubicDimension?: CubicDimension | undefined, lengthUnit?: ('IN' | 'CM' | 'FT' | 'M') | undefined, packageType?: ('BAG' | 'BALE' | 'BOX' | 'BUCKET' | 'BUNDLE' | 'CAN' | 'CARTON' | 'CASE' | 'COIL' | 'CRATE' | 'CYLINDER' | 'DRUM' | 'PAIL' | 'PLT' | 'PIECES' | 'REEL' | 'ROLL' | 'SKID' | 'TOTE' | 'TUBE' | 'EACH' | 'FLAT' | 'LOOSE') | undefined, quantity?: number | undefined, weight?: Weight | undefined}; export type InventoryIdentifier = {description?: string | undefined, type?: ('DEPARTMENT' | 'SUB_DEPARTMENT' | 'CATEGORY' | 'GROUP' | 'FAMILY' | 'GENDER' | 'VENDOR' | 'MANUFACTURER' | 'PROMOTION' | 'SECTOR' | 'DIVISION' | 'CLASS' | 'SUB_CLASS' | 'CODE' | 'SEASON') | undefined, value?: string | undefined}; export type LineItemHazmatDetail = {hazardClass?: string | undefined, identificationNumber?: string | undefined, packingGroup?: ('I' | 'II' | 'III' | 'NONE') | undefined, properShippingName?: string | undefined}; export type Currency = 'USD' | 'CAD' | 'MXN' | 'EUR'; export type MonetaryValue = {amount?: number | undefined, currency?: Currency | undefined}; export type OffsetDateTimeWindow = {endDateTime?: string | undefined, startDateTime?: string | undefined}; export type InventoryItem = {consumeByDateTime?: string | undefined, description?: string | undefined, externalID?: string | undefined, id?: string | undefined, inventoryDimensionalWeight?: DimensionalWeight | undefined, inventoryIdentifiers?: Array | undefined, lineItemHazmatDetail?: LineItemHazmatDetail | undefined, manufacturedDateTime?: string | undefined, orderIds?: Array | undefined, packagedDateTime?: string | undefined, perUnitCost?: MonetaryValue | undefined, perUnitRetailValue?: MonetaryValue | undefined, perishable?: boolean | undefined, promotionalDateTimeWindow?: OffsetDateTimeWindow | undefined, sellByDateTime?: string | undefined, serialNumber?: string | undefined, shipmentIds?: Array | undefined, stockKeepingUnit?: string | undefined, taxable?: boolean | undefined, universalProductCode?: string | undefined}; export type UpdateApiApiV4InventoryItemsIdArgs = {id: string, body: InventoryItem}; export type UpdateApiApiV4InventoryItemsIdOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const inventoryId = z.object({id: z.string().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 }; /** * Update an existing item. * * PUT /api/v4/inventory/items/{id} */ export const updateApiApiV4InventoryItemsId = async (args: UpdateApiApiV4InventoryItemsIdArgs, options?: UpdateApiApiV4InventoryItemsIdOptions) => { const {baseUrl = "https://na12.api.project44.com", fetch: fetchFn = fetch, oAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oAuth2 !== undefined) headers.set('authorization', `Bearer ${oAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/inventory/items/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(inventoryId, await res.json()) };