/* * 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 { ClosedEnum } from "../../types/enums.js"; import { BillingCadence, BillingCadence$outboundSchema, } from "./billing-cadence.js"; import { BillingPeriod, BillingPeriod$outboundSchema, } from "./billing-period.js"; import { FilterCondition, FilterCondition$Outbound, FilterCondition$outboundSchema, } from "./filter-condition.js"; import { SortCondition, SortCondition$Outbound, SortCondition$outboundSchema, } from "./sort-condition.js"; import { Status, Status$outboundSchema } from "./status.js"; import { SubscriptionStatus, SubscriptionStatus$outboundSchema, } from "./subscription-status.js"; import { SubscriptionType, SubscriptionType$outboundSchema, } from "./subscription-type.js"; export const SubscriptionFilterOrder = { Asc: "asc", Desc: "desc", } as const; export type SubscriptionFilterOrder = ClosedEnum< typeof SubscriptionFilterOrder >; export type SubscriptionFilter = { /** * ActiveAt filters subscriptions that are active at the given time */ activeAt?: Date | undefined; /** * BillingCadence filters by billing cadence */ billingCadence?: Array | undefined; /** * BillingPeriod filters by billing period */ billingPeriod?: Array | undefined; /** * CustomerID filters by customer ID */ customerId?: string | undefined; /** * CustomerIDs filters by customer IDs */ customerIds?: Array | undefined; /** * EffectiveDateForUpdate selects subscriptions that need a billing-period pass on or before this time: * * @remarks * current_period_end <= date OR (cancel_at IS NOT NULL AND cancel_at <= date). * When nil, period/cancel cutoff logic is not applied by this field (see TimeRangeFilter for legacy period-end filtering). */ effectiveDateForUpdate?: string | undefined; endTime?: Date | undefined; expand?: string | undefined; /** * ExternalCustomerID filters by external customer ID */ externalCustomerId?: string | undefined; filters?: Array | undefined; /** * InvoicingCustomerIDs filters by invoicing customer ID */ invoicingCustomerIds?: Array | undefined; limit?: number | undefined; offset?: number | undefined; order?: SubscriptionFilterOrder | undefined; /** * ParentSubscriptionIDs filters by parent subscription IDs */ parentSubscriptionIds?: Array | undefined; /** * PlanID filters by plan ID */ planId?: string | undefined; sort?: Array | undefined; startTime?: Date | undefined; status?: Status | undefined; subscriptionIds?: Array | undefined; /** * SubscriptionStatus filters by subscription status */ subscriptionStatus?: Array | undefined; /** * SubscriptionType filters by subscription type */ subscriptionType?: Array | undefined; /** * TrialEndDueLTE, when set, restricts to subscriptions with trial_end not nil and trial_end <= trial_end_due_lte. * * @remarks * Use with subscription_status trialing for trial-end cron processing. */ trialEndDueLte?: Date | undefined; /** * WithCouponAssociations eager-loads coupon associations and their coupons. * * @remarks * * Kept separate from WithLineItems because the coupon_associations table has no * index leading with subscription_id, so Ent's edge load degrades to a full table * scan. Only set it when the response actually surfaces the associations; the * service layer back-fills it from expand="coupon_associations". */ withCouponAssociations?: boolean | undefined; /** * WithLineItems includes line items in the response. * * @remarks * * Deprecated: use expand="subscription_line_items" instead. Retained for * backwards compatibility and for internal callers that need to force-disable * line item loading (set to false). The service layer ORs this with the * expand check before invoking the repository. */ withLineItems?: boolean | undefined; }; /** @internal */ export const SubscriptionFilterOrder$outboundSchema: z.ZodMiniEnum< typeof SubscriptionFilterOrder > = z.enum(SubscriptionFilterOrder); /** @internal */ export type SubscriptionFilter$Outbound = { active_at?: string | undefined; billing_cadence?: Array | undefined; billing_period?: Array | undefined; customer_id?: string | undefined; customer_ids?: Array | undefined; effective_date_for_update?: string | undefined; end_time?: string | undefined; expand?: string | undefined; external_customer_id?: string | undefined; filters?: Array | undefined; invoicing_customer_ids?: Array | undefined; limit?: number | undefined; offset?: number | undefined; order?: string | undefined; parent_subscription_ids?: Array | undefined; plan_id?: string | undefined; sort?: Array | undefined; start_time?: string | undefined; status?: string | undefined; subscription_ids?: Array | undefined; subscription_status?: Array | undefined; subscription_type?: Array | undefined; trial_end_due_lte?: string | undefined; with_coupon_associations?: boolean | undefined; with_line_items?: boolean | undefined; }; /** @internal */ export const SubscriptionFilter$outboundSchema: z.ZodMiniType< SubscriptionFilter$Outbound, SubscriptionFilter > = z.pipe( z.object({ activeAt: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), billingCadence: z.optional(z.array(BillingCadence$outboundSchema)), billingPeriod: z.optional(z.array(BillingPeriod$outboundSchema)), customerId: z.optional(z.string()), customerIds: z.optional(z.array(z.string())), effectiveDateForUpdate: z.optional(z.string()), endTime: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), expand: z.optional(z.string()), externalCustomerId: z.optional(z.string()), filters: z.optional(z.array(FilterCondition$outboundSchema)), invoicingCustomerIds: z.optional(z.array(z.string())), limit: z.optional(z.int()), offset: z.optional(z.int()), order: z.optional(SubscriptionFilterOrder$outboundSchema), parentSubscriptionIds: z.optional(z.array(z.string())), planId: z.optional(z.string()), sort: z.optional(z.array(SortCondition$outboundSchema)), startTime: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), status: z.optional(Status$outboundSchema), subscriptionIds: z.optional(z.array(z.string())), subscriptionStatus: z.optional(z.array(SubscriptionStatus$outboundSchema)), subscriptionType: z.optional(z.array(SubscriptionType$outboundSchema)), trialEndDueLte: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), withCouponAssociations: z.optional(z.boolean()), withLineItems: z.optional(z.boolean()), }), z.transform((v) => { return remap$(v, { activeAt: "active_at", billingCadence: "billing_cadence", billingPeriod: "billing_period", customerId: "customer_id", customerIds: "customer_ids", effectiveDateForUpdate: "effective_date_for_update", endTime: "end_time", externalCustomerId: "external_customer_id", invoicingCustomerIds: "invoicing_customer_ids", parentSubscriptionIds: "parent_subscription_ids", planId: "plan_id", startTime: "start_time", subscriptionIds: "subscription_ids", subscriptionStatus: "subscription_status", subscriptionType: "subscription_type", trialEndDueLte: "trial_end_due_lte", withCouponAssociations: "with_coupon_associations", withLineItems: "with_line_items", }); }), ); export function subscriptionFilterToJSON( subscriptionFilter: SubscriptionFilter, ): string { return JSON.stringify( SubscriptionFilter$outboundSchema.parse(subscriptionFilter), ); }