/* * 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 { AttachedCustomField, AttachedCustomField$inboundSchema, AttachedCustomField$Outbound, AttachedCustomField$outboundSchema, } from "./attachedcustomfield.js"; import { Benefit, Benefit$inboundSchema, Benefit$Outbound, Benefit$outboundSchema, } from "./benefit.js"; import { LegacyRecurringProductPrice, LegacyRecurringProductPrice$inboundSchema, LegacyRecurringProductPrice$Outbound, LegacyRecurringProductPrice$outboundSchema, } from "./legacyrecurringproductprice.js"; import { MetadataOutputType, MetadataOutputType$inboundSchema, MetadataOutputType$Outbound, MetadataOutputType$outboundSchema, } from "./metadataoutputtype.js"; import { ProductMediaFileRead, ProductMediaFileRead$inboundSchema, ProductMediaFileRead$Outbound, ProductMediaFileRead$outboundSchema, } from "./productmediafileread.js"; import { ProductPrice, ProductPrice$inboundSchema, ProductPrice$Outbound, ProductPrice$outboundSchema, } from "./productprice.js"; import { ProductVisibility, ProductVisibility$inboundSchema, ProductVisibility$outboundSchema, } from "./productvisibility.js"; import { SubscriptionRecurringInterval, SubscriptionRecurringInterval$inboundSchema, SubscriptionRecurringInterval$outboundSchema, } from "./subscriptionrecurringinterval.js"; import { TrialInterval, TrialInterval$inboundSchema, TrialInterval$outboundSchema, } from "./trialinterval.js"; export type Prices = LegacyRecurringProductPrice | ProductPrice; /** * A product. */ export type Product = { /** * 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; metadata: { [k: string]: MetadataOutputType }; /** * List of prices for this product. */ prices: Array; /** * List of benefits granted by the product. */ benefits: Array; /** * List of medias associated to the product. */ medias: Array; /** * List of custom fields attached to the product. */ attachedCustomFields: Array; }; /** @internal */ export const Prices$inboundSchema: z.ZodMiniType = smartUnion([ LegacyRecurringProductPrice$inboundSchema, ProductPrice$inboundSchema, ]); /** @internal */ export type Prices$Outbound = | LegacyRecurringProductPrice$Outbound | ProductPrice$Outbound; /** @internal */ export const Prices$outboundSchema: z.ZodMiniType = smartUnion([ LegacyRecurringProductPrice$outboundSchema, ProductPrice$outboundSchema, ]); export function pricesToJSON(prices: Prices): string { return JSON.stringify(Prices$outboundSchema.parse(prices)); } export function pricesFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Prices$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Prices' from JSON`, ); } /** @internal */ export const Product$inboundSchema: z.ZodMiniType = 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(), metadata: z.record(z.string(), MetadataOutputType$inboundSchema), prices: z.array( smartUnion([ LegacyRecurringProductPrice$inboundSchema, ProductPrice$inboundSchema, ]), ), benefits: z.array(Benefit$inboundSchema), medias: z.array(ProductMediaFileRead$inboundSchema), attached_custom_fields: z.array(AttachedCustomField$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", "attached_custom_fields": "attachedCustomFields", }); }), ); /** @internal */ export type Product$Outbound = { id: string; created_at: string; modified_at: string | null; trial_interval: string | null; trial_interval_count: number | null; name: string; description: string | null; visibility: string; recurring_interval: string | null; recurring_interval_count: number | null; is_recurring: boolean; is_archived: boolean; organization_id: string; metadata: { [k: string]: MetadataOutputType$Outbound }; prices: Array; benefits: Array; medias: Array; attached_custom_fields: Array; }; /** @internal */ export const Product$outboundSchema: z.ZodMiniType = z.pipe( z.object({ id: z.string(), createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())), modifiedAt: z.nullable( z.pipe(z.date(), z.transform(v => v.toISOString())), ), trialInterval: z.nullable(TrialInterval$outboundSchema), trialIntervalCount: z.nullable(z.int()), name: z.string(), description: z.nullable(z.string()), visibility: ProductVisibility$outboundSchema, recurringInterval: z.nullable( SubscriptionRecurringInterval$outboundSchema, ), recurringIntervalCount: z.nullable(z.int()), isRecurring: z.boolean(), isArchived: z.boolean(), organizationId: z.string(), metadata: z.record(z.string(), MetadataOutputType$outboundSchema), prices: z.array( smartUnion([ LegacyRecurringProductPrice$outboundSchema, ProductPrice$outboundSchema, ]), ), benefits: z.array(Benefit$outboundSchema), medias: z.array(ProductMediaFileRead$outboundSchema), attachedCustomFields: z.array(AttachedCustomField$outboundSchema), }), z.transform((v) => { return remap$(v, { createdAt: "created_at", modifiedAt: "modified_at", trialInterval: "trial_interval", trialIntervalCount: "trial_interval_count", recurringInterval: "recurring_interval", recurringIntervalCount: "recurring_interval_count", isRecurring: "is_recurring", isArchived: "is_archived", organizationId: "organization_id", attachedCustomFields: "attached_custom_fields", }); }), ); 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`, ); }