import {z} from 'zod' export type GetApiStoresStoreIdInboundShipmentsInboundShipmentIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const inboundShipmentLocationSchema = z.object({id: z.string(), name: z.string()}); export const inboundShipmentMoneySchema = z.object({amount: z.string(), currency: z.string()}); export const inboundShipmentOrderRefSchema = z.object({id: z.string(), name: z.string()}); export const inboundShipmentFileSchema = z.object({id: z.string(), title: z.string(), url: z.string(), content_type: z.string(), created_at: z.string()}); export const inboundShipmentDetailSchema = z.object({id: z.string(), shipment_id: z.string().nullable(), status: z.enum(["PENDING", "IN_TRANSIT", "PARTIALLY_RECEIVED", "RECEIVED"]), location: inboundShipmentLocationSchema, carrier: z.string().nullable(), tracking_number: z.string().nullable(), tracking_url: z.string().nullable(), estimated_arrival_date: z.string().nullable(), actual_arrival_date: z.string().nullable(), freight_type: z.string().nullable(), payment_terms: z.string().nullable(), freight_cost: inboundShipmentMoneySchema, duty_cost: inboundShipmentMoneySchema, items: z.array(z.object({id: z.string(), product: z.object({id: z.string(), title: z.string(), sku: z.string().nullable(), image_url: z.string().nullable().optional(), upc: z.string().nullable().optional()}), quantity: z.number().int(), received_quantity: z.number().int(), damaged_quantity: z.number().int(), missing_quantity: z.number().int(), discrepancy: z.number().int().optional(), packing_mode: z.string().optional()})), sku_count: z.number().int(), item_count: z.number().int(), received_count: z.number().int(), created_at: z.string(), updated_at: z.string(), custom_volume_cubic_meters: z.number().nullable(), purchase_orders: z.array(inboundShipmentOrderRefSchema), transfer_orders: z.array(inboundShipmentOrderRefSchema), files: z.array(inboundShipmentFileSchema), damaged_count: z.number().int(), missing_count: z.number().int()}); export const getApiStoresStoreIdInboundShipmentsInboundShipmentIdResponse = z.object({inbound_shipment: inboundShipmentDetailSchema}); 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 Inbound Shipment * * GET /stores/{storeId}/inbound-shipments/{inboundShipmentId} */ export const getApiStoresStoreIdInboundShipmentsInboundShipmentId = async (options?: GetApiStoresStoreIdInboundShipmentsInboundShipmentIdOptions) => { const {baseUrl = "https://api.getredo.com/v2.2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/stores/${encodeURIComponent(String(args.storeId))}/inbound-shipments/${encodeURIComponent(String(args.inboundShipmentId))}${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(getApiStoresStoreIdInboundShipmentsInboundShipmentIdResponse, await res.json()) };