import {z} from 'zod' export type ProductMeasurements = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsbestInc = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsboxzooka = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsdearSystems = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsdeposco = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementseverstox = {length: number | null, width: number | null, height: number | null, unit?: ('cm' | 'in') | undefined, weight: number | null, weight_unit?: ('kg' | 'oz' | 'lb') | undefined}; export type ProductMeasurementsflexport = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsinfoplus = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ExtendedPropertySchema = {name: string, value: string, type: 'Attribute' | 'Channel' | 'Compatibility' | 'Condition' | 'Fulfilment SKU' | 'Other' | 'Shipping' | 'StockItem Label'}; export type ProductMeasurementslinnworks = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementslogiwa = {length: number | null, width: number | null, height: number | null, unit?: ('cm' | 'in') | undefined, weight: number | null, weight_unit?: ('kg' | 'oz' | 'lb') | undefined}; export type ProductMeasurementsluminous = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsmasonhub = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type NimbleProductMeasurements = {length?: number | undefined, width?: number | undefined, height?: number | undefined, weight?: number | undefined, unit: 'cm' | 'in', weight_unit: 'kg' | 'oz' | 'lb'}; export type ProductMeasurementsportless = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsshipfusion = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsshiphero = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsshipstream = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsskusavvy = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type SupplierSchema = {supplier_id: string} | {supplier_name: string}; export type ProductMeasurementsskuvault = {weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementstlogistics = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type ProductMeasurementsunleashed = {length: number | null, width: number | null, height: number | null, unit: 'cm' | 'in' | null, weight: number | null, weight_unit: 'kg' | 'oz' | 'lb' | null}; export type UpdatewmsProductInputSchema = {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurements | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, unit_price?: number | undefined, country_of_origin?: string | undefined, harmonized_code?: string | undefined, measurements?: ProductMeasurementsbestInc | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: (ProductMeasurementsboxzooka | null) | undefined, unit_price?: number | undefined, country_of_origin?: string | undefined, harmonized_code?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, name?: string | undefined, unit_price?: number | undefined, country_of_origin?: string | undefined, harmonized_code?: string | undefined, customs_description?: string | undefined, cost?: number | undefined, active?: boolean | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, sku?: string | undefined, measurements?: (ProductMeasurementsdearSystems | null) | undefined, costing_method?: ('FIFO' | 'Special - Batch' | 'Special - Serial Number' | 'FIFO - Serial Number' | 'FIFO - Batch' | 'FEFO - Batch' | 'FEFO - Serial Number') | undefined, gtin?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: (ProductMeasurementsdeposco | null) | undefined, active?: boolean | undefined} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: (ProductMeasurementseverstox | null) | undefined, active?: boolean | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: (string | null) | undefined, warehouse_customer_id: string | null} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, measurements?: ProductMeasurementsflexport | undefined, country_of_origin?: string | undefined, harmonized_code?: string | undefined, customs_value?: number | undefined, customs_description?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, warehouse_customer_id?: string | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurementsinfoplus | undefined, price?: number | undefined} | {trackstar_tags?: (Array | null) | undefined, sku: string, gtin: string, price?: number | undefined} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, name?: string | undefined, gtin?: string | undefined, unit_price?: number | undefined, extended_properties?: Array | undefined, measurements?: ProductMeasurementslinnworks | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurementslogiwa | undefined, unit_price?: number | undefined, harmonized_code?: string | undefined, item_type?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, warehouse_customer_id?: (string | null) | undefined, sku?: string | undefined, name?: string | undefined, description?: string | undefined, gtin?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurementsluminous | undefined, category_id?: number | undefined} | {trackstar_tags?: (Array | null) | undefined, name: string, measurements: ProductMeasurementsmasonhub, gtin?: string | undefined, description: string, customer_bar_code: string, brand_name: string, category: string, sub_category: string, vendor_brand_code: string, customer_brand_code: string, vendor_style: string} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, vendor_sku?: string | undefined, description: string, gtin: string, name?: string | undefined, measurements: NimbleProductMeasurements} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, country_of_origin?: string | undefined, harmonized_code?: string | undefined, measurements?: ProductMeasurementsportless | undefined} | {trackstar_tags?: (Array | null) | undefined, name: string, measurements?: (ProductMeasurementsshipfusion | null) | undefined, price?: number | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurementsshiphero | undefined, harmonized_code?: string | undefined, country_of_origin?: string | undefined, customs_description?: string | undefined, standard_manufacturer_product_id?: string | undefined, non_standard_manufacturer_product_id?: string | undefined, merchant_product_id?: string | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurementsshipstream | undefined} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, measurements?: ProductMeasurementsskusavvy | undefined, price?: number | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, classification?: string | undefined, supplier_object?: SupplierSchema | undefined, brand?: string | undefined, measurements: ProductMeasurementsskuvault} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, country_of_origin?: string | undefined, harmonized_code?: string | undefined, measurements?: (ProductMeasurementstlogistics | null) | undefined, batch_required?: true | undefined, expiry_required?: boolean | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, gtin?: string | undefined, measurements?: ProductMeasurementsunleashed | undefined} | {trackstar_tags?: (Array | null) | undefined, name?: string | undefined, unit_price?: number | undefined} | {trackstar_tags?: (Array | null) | undefined, sku?: string | undefined, name?: string | undefined, gtin: string}; export type UpdateApiWmsProductsProductIdArgs = {product_id: string, 'x-trackstar-api-key': string, 'x-trackstar-access-token': string, 'Idempotency-Key'?: string | undefined, body: UpdatewmsProductInputSchema}; export type UpdateApiWmsProductsProductIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const productInventoryItems = z.object({inventory_item_id: z.string(), sku: z.string().nullable(), unit_quantity: z.number().int()}); export const productSupplier = z.object({supplier_id: z.string(), supplier_name: z.string().nullable()}); export const productSupplierProducts = z.object({supplier_id: z.string(), supplier_name: z.string().nullable(), external_id: z.string().nullable(), unit_cost: z.string().nullable()}); export const wmsProductApiItemSchema = z.object({id: z.string(), warehouse_customer_id: z.string().nullable(), created_date: z.string(), updated_date: z.string(), name: z.string(), sku: z.string().nullable(), gtin: z.string().nullable(), unit_price: z.number().nullable(), inventory_items: z.array(productInventoryItems), is_kit: z.boolean(), active: z.boolean(), supplier_object: productSupplier.nullable(), country_of_origin: z.string().nullable(), harmonized_code: z.string().nullable(), supplier_products: z.array(productSupplierProducts), categories: z.array(z.string()), image_urls: z.array(z.string()), external_system_url: z.string().nullable(), trackstar_tags: z.array(z.unknown()).nullable(), additional_fields: z.record(z.string(), z.unknown()), trackstar_created_date: z.string(), trackstar_updated_date: z.string()}); export const wmsUpdateProductResponse = z.object({data: wmsProductApiItemSchema.optional(), id: z.string(), unused_fields: z.array(z.string())}); 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 Product * * PUT /wms/products/{product_id} */ export const updateApiWmsProductsProductId = async (args: UpdateApiWmsProductsProductIdArgs, options?: UpdateApiWmsProductsProductIdOptions) => { const {baseUrl = "https://production.trackstarhq.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-trackstar-api-key'] != null) headers.set("x-trackstar-api-key", String(args['x-trackstar-api-key'])) if (args['x-trackstar-access-token'] != null) headers.set("x-trackstar-access-token", String(args['x-trackstar-access-token'])) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/wms/products/${encodeURIComponent(String(args.product_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(wmsUpdateProductResponse, await res.json()) };