/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { smartUnion } from "../../types/smartUnion.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { BenefitPublic, BenefitPublic$inboundSchema } from "./benefitpublic.js"; import { LegacyRecurringProductPrice, LegacyRecurringProductPrice$inboundSchema, } from "./legacyrecurringproductprice.js"; import { ProductMediaFileRead, ProductMediaFileRead$inboundSchema, } from "./productmediafileread.js"; import { ProductPrice, ProductPrice$inboundSchema } from "./productprice.js"; import { ProductVisibility, ProductVisibility$inboundSchema, } from "./productvisibility.js"; import { SubscriptionRecurringInterval, SubscriptionRecurringInterval$inboundSchema, } from "./subscriptionrecurringinterval.js"; import { TrialInterval, TrialInterval$inboundSchema } from "./trialinterval.js"; export type CustomerProductPrices = LegacyRecurringProductPrice | ProductPrice; /** * Schema of a product for customer portal. */ export type CustomerProduct = { /** * The ID of the object. */ id: string; /** * Creation timestamp of the object. */ createdAt: Date; /** * Last modification timestamp of the object. */ modifiedAt: Date | null; /** * The interval unit for the trial period. */ trialInterval: TrialInterval | null; /** * The number of interval units for the trial period. */ trialIntervalCount: number | null; /** * The name of the product. */ name: string; /** * The description of the product. */ description: string | null; visibility: ProductVisibility; /** * The recurring interval of the product. If `None`, the product is a one-time purchase. */ recurringInterval: SubscriptionRecurringInterval | null; /** * Number of interval units of the subscription. If this is set to 1 the charge will happen every interval (e.g. every month), if set to 2 it will be every other month, and so on. None for one-time products. */ recurringIntervalCount: number | null; /** * Whether the product is a subscription. */ isRecurring: boolean; /** * Whether the product is archived and no longer available. */ isArchived: boolean; /** * The ID of the organization owning the product. */ organizationId: string; /** * List of available prices for this product. */ prices: Array; /** * The benefits granted by the product. */ benefits: Array; /** * The medias associated to the product. */ medias: Array; }; /** @internal */ export const CustomerProductPrices$inboundSchema: z.ZodMiniType< CustomerProductPrices, unknown > = smartUnion([ LegacyRecurringProductPrice$inboundSchema, ProductPrice$inboundSchema, ]); export function customerProductPricesFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CustomerProductPrices$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CustomerProductPrices' from JSON`, ); } /** @internal */ export const CustomerProduct$inboundSchema: z.ZodMiniType< CustomerProduct, unknown > = z.pipe( z.object({ id: z.string(), created_at: z.pipe( z.iso.datetime({ offset: true }), z.transform(v => new Date(v)), ), modified_at: z.nullable( z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))), ), trial_interval: z.nullable(TrialInterval$inboundSchema), trial_interval_count: z.nullable(z.int()), name: z.string(), description: z.nullable(z.string()), visibility: ProductVisibility$inboundSchema, recurring_interval: z.nullable(SubscriptionRecurringInterval$inboundSchema), recurring_interval_count: z.nullable(z.int()), is_recurring: z.boolean(), is_archived: z.boolean(), organization_id: z.string(), prices: z.array( smartUnion([ LegacyRecurringProductPrice$inboundSchema, ProductPrice$inboundSchema, ]), ), benefits: z.array(BenefitPublic$inboundSchema), medias: z.array(ProductMediaFileRead$inboundSchema), }), z.transform((v) => { return remap$(v, { "created_at": "createdAt", "modified_at": "modifiedAt", "trial_interval": "trialInterval", "trial_interval_count": "trialIntervalCount", "recurring_interval": "recurringInterval", "recurring_interval_count": "recurringIntervalCount", "is_recurring": "isRecurring", "is_archived": "isArchived", "organization_id": "organizationId", }); }), ); export function customerProductFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CustomerProduct$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CustomerProduct' from JSON`, ); }