/* * 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 { smartUnion } from "../../types/smartUnion.js"; import { AttachedCustomFieldCreate, AttachedCustomFieldCreate$Outbound, AttachedCustomFieldCreate$outboundSchema, } from "./attachedcustomfieldcreate.js"; import { ProductPriceCustomCreate, ProductPriceCustomCreate$Outbound, ProductPriceCustomCreate$outboundSchema, } from "./productpricecustomcreate.js"; import { ProductPriceFixedCreate, ProductPriceFixedCreate$Outbound, ProductPriceFixedCreate$outboundSchema, } from "./productpricefixedcreate.js"; import { ProductPriceFreeCreate, ProductPriceFreeCreate$Outbound, ProductPriceFreeCreate$outboundSchema, } from "./productpricefreecreate.js"; import { ProductPriceMeteredUnitCreate, ProductPriceMeteredUnitCreate$Outbound, ProductPriceMeteredUnitCreate$outboundSchema, } from "./productpricemeteredunitcreate.js"; import { ProductPriceSeatBasedCreate, ProductPriceSeatBasedCreate$Outbound, ProductPriceSeatBasedCreate$outboundSchema, } from "./productpriceseatbasedcreate.js"; import { ProductVisibility, ProductVisibility$outboundSchema, } from "./productvisibility.js"; import { SubscriptionRecurringInterval, SubscriptionRecurringInterval$outboundSchema, } from "./subscriptionrecurringinterval.js"; import { TrialInterval, TrialInterval$outboundSchema, } from "./trialinterval.js"; export type ProductCreateRecurringMetadata = string | number | number | boolean; export type ProductCreateRecurringPrices = | ProductPriceCustomCreate | ProductPriceFixedCreate | ProductPriceFreeCreate | ProductPriceMeteredUnitCreate | ProductPriceSeatBasedCreate; export type ProductCreateRecurring = { /** * Key-value object allowing you to store additional information. * * @remarks * * The key must be a string with a maximum length of **40 characters**. * The value must be either: * * * A string with a maximum length of **500 characters** * * An integer * * A floating-point number * * A boolean * * You can store up to **50 key-value pairs**. */ metadata?: { [k: string]: string | number | number | boolean } | undefined; /** * The name of the product. */ name: string; /** * The description of the product. */ description?: string | null | undefined; visibility?: ProductVisibility | undefined; /** * List of available prices for this product. It should contain at most one static price (fixed, custom or free), and any number of metered prices. Metered prices are not supported on one-time purchase products. */ prices: Array< | ProductPriceCustomCreate | ProductPriceFixedCreate | ProductPriceFreeCreate | ProductPriceMeteredUnitCreate | ProductPriceSeatBasedCreate >; /** * List of file IDs. Each one must be on the same organization as the product, of type `product_media` and correctly uploaded. */ medias?: Array | null | undefined; /** * List of custom fields to attach. */ attachedCustomFields?: Array | undefined; /** * The ID of the organization owning the product. **Required unless you use an organization token.** */ organizationId?: string | null | undefined; /** * The interval unit for the trial period. */ trialInterval?: TrialInterval | null | undefined; /** * The number of interval units for the trial period. */ trialIntervalCount?: number | null | undefined; recurringInterval: SubscriptionRecurringInterval; /** * 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. */ recurringIntervalCount?: number | undefined; }; /** @internal */ export type ProductCreateRecurringMetadata$Outbound = | string | number | number | boolean; /** @internal */ export const ProductCreateRecurringMetadata$outboundSchema: z.ZodMiniType< ProductCreateRecurringMetadata$Outbound, ProductCreateRecurringMetadata > = smartUnion([z.string(), z.int(), z.number(), z.boolean()]); export function productCreateRecurringMetadataToJSON( productCreateRecurringMetadata: ProductCreateRecurringMetadata, ): string { return JSON.stringify( ProductCreateRecurringMetadata$outboundSchema.parse( productCreateRecurringMetadata, ), ); } /** @internal */ export type ProductCreateRecurringPrices$Outbound = | ProductPriceCustomCreate$Outbound | ProductPriceFixedCreate$Outbound | ProductPriceFreeCreate$Outbound | ProductPriceMeteredUnitCreate$Outbound | ProductPriceSeatBasedCreate$Outbound; /** @internal */ export const ProductCreateRecurringPrices$outboundSchema: z.ZodMiniType< ProductCreateRecurringPrices$Outbound, ProductCreateRecurringPrices > = z.union([ ProductPriceCustomCreate$outboundSchema, ProductPriceFixedCreate$outboundSchema, ProductPriceFreeCreate$outboundSchema, ProductPriceMeteredUnitCreate$outboundSchema, ProductPriceSeatBasedCreate$outboundSchema, ]); export function productCreateRecurringPricesToJSON( productCreateRecurringPrices: ProductCreateRecurringPrices, ): string { return JSON.stringify( ProductCreateRecurringPrices$outboundSchema.parse( productCreateRecurringPrices, ), ); } /** @internal */ export type ProductCreateRecurring$Outbound = { metadata?: { [k: string]: string | number | number | boolean } | undefined; name: string; description?: string | null | undefined; visibility?: string | undefined; prices: Array< | ProductPriceCustomCreate$Outbound | ProductPriceFixedCreate$Outbound | ProductPriceFreeCreate$Outbound | ProductPriceMeteredUnitCreate$Outbound | ProductPriceSeatBasedCreate$Outbound >; medias?: Array | null | undefined; attached_custom_fields?: | Array | undefined; organization_id?: string | null | undefined; trial_interval?: string | null | undefined; trial_interval_count?: number | null | undefined; recurring_interval: string; recurring_interval_count: number; }; /** @internal */ export const ProductCreateRecurring$outboundSchema: z.ZodMiniType< ProductCreateRecurring$Outbound, ProductCreateRecurring > = z.pipe( z.object({ metadata: z.optional( z.record( z.string(), smartUnion([z.string(), z.int(), z.number(), z.boolean()]), ), ), name: z.string(), description: z.optional(z.nullable(z.string())), visibility: z.optional(ProductVisibility$outboundSchema), prices: z.array( z.union([ ProductPriceCustomCreate$outboundSchema, ProductPriceFixedCreate$outboundSchema, ProductPriceFreeCreate$outboundSchema, ProductPriceMeteredUnitCreate$outboundSchema, ProductPriceSeatBasedCreate$outboundSchema, ]), ), medias: z.optional(z.nullable(z.array(z.string()))), attachedCustomFields: z.optional( z.array(AttachedCustomFieldCreate$outboundSchema), ), organizationId: z.optional(z.nullable(z.string())), trialInterval: z.optional(z.nullable(TrialInterval$outboundSchema)), trialIntervalCount: z.optional(z.nullable(z.int())), recurringInterval: SubscriptionRecurringInterval$outboundSchema, recurringIntervalCount: z._default(z.int(), 1), }), z.transform((v) => { return remap$(v, { attachedCustomFields: "attached_custom_fields", organizationId: "organization_id", trialInterval: "trial_interval", trialIntervalCount: "trial_interval_count", recurringInterval: "recurring_interval", recurringIntervalCount: "recurring_interval_count", }); }), ); export function productCreateRecurringToJSON( productCreateRecurring: ProductCreateRecurring, ): string { return JSON.stringify( ProductCreateRecurring$outboundSchema.parse(productCreateRecurring), ); }