import {z} from 'zod' export type GetApiCustomerOrderShipmentItemsIdArgs = {id: string, 'X-STOREFRONT-KEY': string, 'X-Locale'?: string | undefined, 'X-Channel'?: string | undefined, 'X-Currency'?: string | undefined}; export type GetApiCustomerOrderShipmentItemsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerOrderShipmentItem = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), sku: z.string().nullable().optional(), qty: z.number().int().nullable().optional(), weight: z.number().nullable().optional(), price: z.number().nullable().optional(), basePrice: z.number().nullable().optional(), total: z.number().nullable().optional(), baseTotal: z.number().nullable().optional(), priceInclTax: z.number().optional(), basePriceInclTax: z.number().optional(), productId: z.string().nullable().optional(), productType: z.string().nullable().optional(), additional: z.array(z.unknown()).nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), shipment: 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 CustomerOrderShipmentItem resource. * * GET /customer-order-shipment-items/{id} */ export const getApiCustomerOrderShipmentItemsId = async (args: GetApiCustomerOrderShipmentItemsIdArgs, options?: GetApiCustomerOrderShipmentItemsIdOptions) => { 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-shipment-items/${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(customerOrderShipmentItem, await res.json()) };