import {z} from 'zod' export type GetApiCustomerOrderShipmentsIdArgs = {id: string, 'X-STOREFRONT-KEY': string, 'X-Locale'?: string | undefined, 'X-Channel'?: string | undefined, 'X-Currency'?: string | undefined}; export type GetApiCustomerOrderShipmentsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerOrderShipment = z.object({id: z.number().int().optional(), status: z.string().nullable().optional(), totalQty: z.number().int().nullable().optional(), totalWeight: z.number().nullable().optional(), carrierCode: z.string().nullable().optional(), carrierTitle: z.string().nullable().optional(), trackNumber: z.string().nullable().optional(), emailSent: z.boolean().optional(), customerId: z.number().int().nullable().optional(), customerType: z.string().nullable().optional(), inventorySourceId: z.number().int().nullable().optional(), inventorySourceName: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), shippingNumber: z.string().optional(), items: z.array(z.string()).optional(), shippingAddress: z.string().optional(), billingAddress: 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 }; /** * Retrieves a CustomerOrderShipment resource. * * GET /customer-order-shipments/{id} */ export const getApiCustomerOrderShipmentsId = async (args: GetApiCustomerOrderShipmentsIdArgs, options?: GetApiCustomerOrderShipmentsIdOptions) => { const {baseUrl = "http://localhost:8000/api/shop", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-STOREFRONT-KEY'] != null) headers.set("X-STOREFRONT-KEY", String(args['X-STOREFRONT-KEY'])) if (args['X-Locale'] != null) headers.set("X-Locale", String(args['X-Locale'])) if (args['X-Channel'] != null) headers.set("X-Channel", String(args['X-Channel'])) if (args['X-Currency'] != null) headers.set("X-Currency", String(args['X-Currency'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer-order-shipments/${encodeURIComponent(String(args.id))}${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(customerOrderShipment, await res.json()) };