/* * 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 { RFCDate } from "../../types/rfcdate.js"; import { smartUnion } from "../../types/smartUnion.js"; import { ProductBillingType, ProductBillingType$outboundSchema, } from "../components/productbillingtype.js"; import { TimeInterval, TimeInterval$outboundSchema, } from "../components/timeinterval.js"; /** * Filter by organization ID. */ export type MetricsGetQueryParamOrganizationIDFilter = string | Array; /** * Filter by product ID. */ export type MetricsGetQueryParamProductIDFilter = string | Array; /** * Filter by billing type. `recurring` will filter data corresponding to subscriptions creations or renewals. `one_time` will filter data corresponding to one-time purchases. */ export type QueryParamProductBillingTypeFilter = | ProductBillingType | Array; /** * Filter by customer ID. */ export type MetricsGetQueryParamCustomerIDFilter = string | Array; export type MetricsGetRequest = { /** * Start date. */ startDate: RFCDate; /** * End date. */ endDate: RFCDate; /** * Timezone to use for the timestamps. Default is UTC. */ timezone?: string | undefined; /** * Interval between two timestamps. */ interval: TimeInterval; /** * Filter by organization ID. */ organizationId?: string | Array | null | undefined; /** * Filter by product ID. */ productId?: string | Array | null | undefined; /** * Filter by billing type. `recurring` will filter data corresponding to subscriptions creations or renewals. `one_time` will filter data corresponding to one-time purchases. */ billingType?: | ProductBillingType | Array | null | undefined; /** * Filter by customer ID. */ customerId?: string | Array | null | undefined; /** * List of metric slugs to focus on. When provided, only the queries needed for these metrics will be executed, improving performance. If not provided, all metrics are returned. */ metrics?: Array | null | undefined; }; /** @internal */ export type MetricsGetQueryParamOrganizationIDFilter$Outbound = | string | Array; /** @internal */ export const MetricsGetQueryParamOrganizationIDFilter$outboundSchema: z.ZodMiniType< MetricsGetQueryParamOrganizationIDFilter$Outbound, MetricsGetQueryParamOrganizationIDFilter > = smartUnion([z.string(), z.array(z.string())]); export function metricsGetQueryParamOrganizationIDFilterToJSON( metricsGetQueryParamOrganizationIDFilter: MetricsGetQueryParamOrganizationIDFilter, ): string { return JSON.stringify( MetricsGetQueryParamOrganizationIDFilter$outboundSchema.parse( metricsGetQueryParamOrganizationIDFilter, ), ); } /** @internal */ export type MetricsGetQueryParamProductIDFilter$Outbound = | string | Array; /** @internal */ export const MetricsGetQueryParamProductIDFilter$outboundSchema: z.ZodMiniType< MetricsGetQueryParamProductIDFilter$Outbound, MetricsGetQueryParamProductIDFilter > = smartUnion([z.string(), z.array(z.string())]); export function metricsGetQueryParamProductIDFilterToJSON( metricsGetQueryParamProductIDFilter: MetricsGetQueryParamProductIDFilter, ): string { return JSON.stringify( MetricsGetQueryParamProductIDFilter$outboundSchema.parse( metricsGetQueryParamProductIDFilter, ), ); } /** @internal */ export type QueryParamProductBillingTypeFilter$Outbound = | string | Array; /** @internal */ export const QueryParamProductBillingTypeFilter$outboundSchema: z.ZodMiniType< QueryParamProductBillingTypeFilter$Outbound, QueryParamProductBillingTypeFilter > = smartUnion([ ProductBillingType$outboundSchema, z.array(ProductBillingType$outboundSchema), ]); export function queryParamProductBillingTypeFilterToJSON( queryParamProductBillingTypeFilter: QueryParamProductBillingTypeFilter, ): string { return JSON.stringify( QueryParamProductBillingTypeFilter$outboundSchema.parse( queryParamProductBillingTypeFilter, ), ); } /** @internal */ export type MetricsGetQueryParamCustomerIDFilter$Outbound = | string | Array; /** @internal */ export const MetricsGetQueryParamCustomerIDFilter$outboundSchema: z.ZodMiniType< MetricsGetQueryParamCustomerIDFilter$Outbound, MetricsGetQueryParamCustomerIDFilter > = smartUnion([z.string(), z.array(z.string())]); export function metricsGetQueryParamCustomerIDFilterToJSON( metricsGetQueryParamCustomerIDFilter: MetricsGetQueryParamCustomerIDFilter, ): string { return JSON.stringify( MetricsGetQueryParamCustomerIDFilter$outboundSchema.parse( metricsGetQueryParamCustomerIDFilter, ), ); } /** @internal */ export type MetricsGetRequest$Outbound = { start_date: string; end_date: string; timezone: string; interval: string; organization_id?: string | Array | null | undefined; product_id?: string | Array | null | undefined; billing_type?: string | Array | null | undefined; customer_id?: string | Array | null | undefined; metrics?: Array | null | undefined; }; /** @internal */ export const MetricsGetRequest$outboundSchema: z.ZodMiniType< MetricsGetRequest$Outbound, MetricsGetRequest > = z.pipe( z.object({ startDate: z.pipe( z.custom(x => x instanceof RFCDate), z.transform(v => v.toString()), ), endDate: z.pipe( z.custom(x => x instanceof RFCDate), z.transform(v => v.toString()), ), timezone: z._default(z.string(), "UTC"), interval: TimeInterval$outboundSchema, organizationId: z.optional( z.nullable(smartUnion([z.string(), z.array(z.string())])), ), productId: z.optional( z.nullable(smartUnion([z.string(), z.array(z.string())])), ), billingType: z.optional( z.nullable( smartUnion([ ProductBillingType$outboundSchema, z.array(ProductBillingType$outboundSchema), ]), ), ), customerId: z.optional( z.nullable(smartUnion([z.string(), z.array(z.string())])), ), metrics: z.optional(z.nullable(z.array(z.string()))), }), z.transform((v) => { return remap$(v, { startDate: "start_date", endDate: "end_date", organizationId: "organization_id", productId: "product_id", billingType: "billing_type", customerId: "customer_id", }); }), ); export function metricsGetRequestToJSON( metricsGetRequest: MetricsGetRequest, ): string { return JSON.stringify( MetricsGetRequest$outboundSchema.parse(metricsGetRequest), ); }