/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { AmountDecimal, AmountDecimal$inboundSchema, AmountDecimal$Outbound, AmountDecimal$outboundSchema, } from "./amountdecimal.js"; import { ProductImageMetadata, ProductImageMetadata$inboundSchema, ProductImageMetadata$Outbound, ProductImageMetadata$outboundSchema, } from "./productimagemetadata.js"; import { ProductOptionGroup, ProductOptionGroup$inboundSchema, ProductOptionGroup$Outbound, ProductOptionGroup$outboundSchema, } from "./productoptiongroup.js"; /** * A good or service offered by a merchant. */ export type Product = { /** * Unique identifier for a product. */ productID: string; title: string; /** * A detailed description of the product. * * @remarks * * - Must be valid UTF-8 text * - Supports Markdown for formatting * - HTML is not permitted and will be rejected */ description?: string | undefined; /** * A product's starting price, before applying modifiers. */ basePrice: AmountDecimal; /** * Optional configuration options for a product, such as size or color. */ optionGroups?: Array | undefined; /** * Optional images associated with the product. */ images?: Array | undefined; /** * The date and time when the product was added. */ createdOn: Date; /** * The date and time when the product was last updated. */ updatedOn: Date; /** * The date and time when the product was disabled. */ disabledOn?: Date | undefined; }; /** @internal */ export const Product$inboundSchema: z.ZodType = z.object({ productID: z.string(), title: z.string(), description: z.string().optional(), basePrice: AmountDecimal$inboundSchema, optionGroups: z.array(ProductOptionGroup$inboundSchema).optional(), images: z.array(ProductImageMetadata$inboundSchema).optional(), createdOn: z.string().datetime({ offset: true }).transform(v => new Date(v) ), updatedOn: z.string().datetime({ offset: true }).transform(v => new Date(v) ), disabledOn: z.string().datetime({ offset: true }).transform(v => new Date(v) ).optional(), }); /** @internal */ export type Product$Outbound = { productID: string; title: string; description?: string | undefined; basePrice: AmountDecimal$Outbound; optionGroups?: Array | undefined; images?: Array | undefined; createdOn: string; updatedOn: string; disabledOn?: string | undefined; }; /** @internal */ export const Product$outboundSchema: z.ZodType< Product$Outbound, z.ZodTypeDef, Product > = z.object({ productID: z.string(), title: z.string(), description: z.string().optional(), basePrice: AmountDecimal$outboundSchema, optionGroups: z.array(ProductOptionGroup$outboundSchema).optional(), images: z.array(ProductImageMetadata$outboundSchema).optional(), createdOn: z.date().transform(v => v.toISOString()), updatedOn: z.date().transform(v => v.toISOString()), disabledOn: z.date().transform(v => v.toISOString()).optional(), }); export function productToJSON(product: Product): string { return JSON.stringify(Product$outboundSchema.parse(product)); } export function productFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Product$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Product' from JSON`, ); }