/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { Amount, Amount$inboundSchema, Amount$Outbound, Amount$outboundSchema, } from "./amount.js"; export type CartItem = { /** * The name of a given item. */ name: string; /** * This value is used by Bolt as an external reference to a given item. */ reference: string; /** * A human-readable description of this cart item. */ description?: string | undefined; /** * A monetary amount, i.e. a base unit amount and a supported currency. */ totalAmount: Amount; /** * The item's unit price, i.e. the cost of a single item exclusive of tax and discounts. */ unitPrice: number; /** * The number of units that comprise this cart item. */ quantity: number; /** * Used to provide a link to the image associated with the item. */ imageUrl?: string | undefined; }; /** @internal */ export const CartItem$inboundSchema: z.ZodType< CartItem, z.ZodTypeDef, unknown > = z.object({ name: z.string(), reference: z.string(), description: z.string().optional(), total_amount: Amount$inboundSchema, unit_price: z.number().int(), quantity: z.number().int(), image_url: z.string().optional(), }).transform((v) => { return remap$(v, { "total_amount": "totalAmount", "unit_price": "unitPrice", "image_url": "imageUrl", }); }); /** @internal */ export type CartItem$Outbound = { name: string; reference: string; description?: string | undefined; total_amount: Amount$Outbound; unit_price: number; quantity: number; image_url?: string | undefined; }; /** @internal */ export const CartItem$outboundSchema: z.ZodType< CartItem$Outbound, z.ZodTypeDef, CartItem > = z.object({ name: z.string(), reference: z.string(), description: z.string().optional(), totalAmount: Amount$outboundSchema, unitPrice: z.number().int(), quantity: z.number().int(), imageUrl: z.string().optional(), }).transform((v) => { return remap$(v, { totalAmount: "total_amount", unitPrice: "unit_price", imageUrl: "image_url", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace CartItem$ { /** @deprecated use `CartItem$inboundSchema` instead. */ export const inboundSchema = CartItem$inboundSchema; /** @deprecated use `CartItem$outboundSchema` instead. */ export const outboundSchema = CartItem$outboundSchema; /** @deprecated use `CartItem$Outbound` instead. */ export type Outbound = CartItem$Outbound; } export function cartItemToJSON(cartItem: CartItem): string { return JSON.stringify(CartItem$outboundSchema.parse(cartItem)); } export function cartItemFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CartItem$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CartItem' from JSON`, ); }