/* * 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 { 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"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * Filter by organization ID. */ export type MetricsExportQueryParamOrganizationIDFilter = | string | Array; /** * Filter by product ID. */ export type MetricsExportQueryParamProductIDFilter = 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 MetricsExportQueryParamProductBillingTypeFilter = | ProductBillingType | Array; /** * Filter by customer ID. */ export type MetricsExportQueryParamCustomerIDFilter = string | Array; export type MetricsExportRequest = { /** * 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 include in the export. If not provided, all metrics are exported. */ metrics?: Array | null | undefined; }; export type MetricsExportResponse = any | string; /** @internal */ export type MetricsExportQueryParamOrganizationIDFilter$Outbound = | string | Array; /** @internal */ export const MetricsExportQueryParamOrganizationIDFilter$outboundSchema: z.ZodMiniType< MetricsExportQueryParamOrganizationIDFilter$Outbound, MetricsExportQueryParamOrganizationIDFilter > = smartUnion([z.string(), z.array(z.string())]); export function metricsExportQueryParamOrganizationIDFilterToJSON( metricsExportQueryParamOrganizationIDFilter: MetricsExportQueryParamOrganizationIDFilter, ): string { return JSON.stringify( MetricsExportQueryParamOrganizationIDFilter$outboundSchema.parse( metricsExportQueryParamOrganizationIDFilter, ), ); } /** @internal */ export type MetricsExportQueryParamProductIDFilter$Outbound = | string | Array; /** @internal */ export const MetricsExportQueryParamProductIDFilter$outboundSchema: z.ZodMiniType< MetricsExportQueryParamProductIDFilter$Outbound, MetricsExportQueryParamProductIDFilter > = smartUnion([z.string(), z.array(z.string())]); export function metricsExportQueryParamProductIDFilterToJSON( metricsExportQueryParamProductIDFilter: MetricsExportQueryParamProductIDFilter, ): string { return JSON.stringify( MetricsExportQueryParamProductIDFilter$outboundSchema.parse( metricsExportQueryParamProductIDFilter, ), ); } /** @internal */ export type MetricsExportQueryParamProductBillingTypeFilter$Outbound = | string | Array; /** @internal */ export const MetricsExportQueryParamProductBillingTypeFilter$outboundSchema: z.ZodMiniType< MetricsExportQueryParamProductBillingTypeFilter$Outbound, MetricsExportQueryParamProductBillingTypeFilter > = smartUnion([ ProductBillingType$outboundSchema, z.array(ProductBillingType$outboundSchema), ]); export function metricsExportQueryParamProductBillingTypeFilterToJSON( metricsExportQueryParamProductBillingTypeFilter: MetricsExportQueryParamProductBillingTypeFilter, ): string { return JSON.stringify( MetricsExportQueryParamProductBillingTypeFilter$outboundSchema.parse( metricsExportQueryParamProductBillingTypeFilter, ), ); } /** @internal */ export type MetricsExportQueryParamCustomerIDFilter$Outbound = | string | Array; /** @internal */ export const MetricsExportQueryParamCustomerIDFilter$outboundSchema: z.ZodMiniType< MetricsExportQueryParamCustomerIDFilter$Outbound, MetricsExportQueryParamCustomerIDFilter > = smartUnion([z.string(), z.array(z.string())]); export function metricsExportQueryParamCustomerIDFilterToJSON( metricsExportQueryParamCustomerIDFilter: MetricsExportQueryParamCustomerIDFilter, ): string { return JSON.stringify( MetricsExportQueryParamCustomerIDFilter$outboundSchema.parse( metricsExportQueryParamCustomerIDFilter, ), ); } /** @internal */ export type MetricsExportRequest$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 MetricsExportRequest$outboundSchema: z.ZodMiniType< MetricsExportRequest$Outbound, MetricsExportRequest > = 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 metricsExportRequestToJSON( metricsExportRequest: MetricsExportRequest, ): string { return JSON.stringify( MetricsExportRequest$outboundSchema.parse(metricsExportRequest), ); } /** @internal */ export const MetricsExportResponse$inboundSchema: z.ZodMiniType< MetricsExportResponse, unknown > = smartUnion([z.any(), z.string()]); export function metricsExportResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => MetricsExportResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'MetricsExportResponse' from JSON`, ); }