import {z} from 'zod' export type GetApiStoresStoreIdInboundShipmentsArgs = {'X-Page-Continue'?: string | undefined, 'X-Page-Size'?: number | undefined, status?: ('PENDING' | 'IN_TRANSIT' | 'PARTIALLY_RECEIVED' | 'RECEIVED') | undefined, location_id?: string | undefined, created_at_min?: string | undefined, created_at_max?: string | undefined}; export type GetApiStoresStoreIdInboundShipmentsOptions = {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 inboundShipmentProductSummarySchema = z.object({id: z.string(), title: z.string(), sku: z.string().nullable(), image_url: z.string().nullable().optional()}); export const inboundShipmentItemListSchema = z.object({id: z.string(), product: inboundShipmentProductSummarySchema, quantity: z.number().int(), received_quantity: z.number().int(), damaged_quantity: z.number().int(), missing_quantity: z.number().int()}); export const inboundShipmentListSchema = 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(inboundShipmentItemListSchema), sku_count: z.number().int(), item_count: z.number().int(), received_count: z.number().int(), created_at: z.string(), updated_at: z.string()}); export const getApiStoresStoreIdInboundShipmentsResponse = z.object({inbound_shipments: z.array(inboundShipmentListSchema)}); 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 }; /** * List Inbound Shipments * * GET /stores/{storeId}/inbound-shipments */ export const getApiStoresStoreIdInboundShipments = async (args: GetApiStoresStoreIdInboundShipmentsArgs, options?: GetApiStoresStoreIdInboundShipmentsOptions) => { 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 (args['X-Page-Continue'] != null) headers.set("X-Page-Continue", String(args['X-Page-Continue'])) if (args['X-Page-Size'] != null) headers.set("X-Page-Size", String(args['X-Page-Size'])) if (args.status != null) query.append("status", String(args.status)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.created_at_min != null) query.append("created_at_min", String(args.created_at_min)) if (args.created_at_max != null) query.append("created_at_max", String(args.created_at_max)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/stores/${encodeURIComponent(String(args.storeId))}/inbound-shipments${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(getApiStoresStoreIdInboundShipmentsResponse, await res.json()) };