/* * 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 { AggregationType, AggregationType$outboundSchema, } from "./aggregation-type.js"; import { WindowSize, WindowSize$outboundSchema } from "./window-size.js"; export type GetUsageRequest = { aggregationType: AggregationType; /** * BillingAnchor enables custom monthly billing periods for usage aggregation. * * @remarks * * When to use: * - WindowSize = "MONTH" AND you need custom monthly periods (not calendar months) * - Subscription billing that doesn't align with calendar months * - Example: Customer signed up on 15th, so billing periods are 15th to 15th * * When NOT to use: * - WindowSize != "MONTH" (ignored for DAY, HOUR, WEEK, etc.) * - Standard calendar-based billing (1st to 1st of each month) * * Example values: * - "2024-03-05T14:30:45.123456789Z" (5th of each month at 2:30:45 PM) * - "2024-01-15T00:00:00Z" (15th of each month at midnight) * - "2024-02-29T12:00:00Z" (29th of each month at noon - handles leap years) */ billingAnchor?: Date | undefined; bucketSize?: WindowSize | undefined; customerId?: string | undefined; endTime?: Date | undefined; eventName: string; externalCustomerId?: string | undefined; filters?: { [k: string]: Array } | undefined; /** * GroupBy lists the analytics group_by dimensions. * * @remarks * - "source" — group by event source column * - "properties.X" — group by JSON property X */ groupBy?: Array | undefined; /** * GroupByProperty is the property name in event.properties to group by before aggregating. * * @remarks * When set, aggregation is applied per unique value of this property within each bucket, * then the per-group results are summed to produce the bucket total. * * Deprecated: prefer GroupBy []string{"properties."} for parity with * other analytics endpoints. ToUsageParams translates this field into * GroupBy when GroupBy is otherwise empty. */ groupByProperty?: string | undefined; multiplier?: string | undefined; /** * will be empty/ignored in case of COUNT */ propertyName?: string | undefined; startTime?: Date | undefined; timezone?: string | undefined; windowSize?: WindowSize | undefined; }; /** @internal */ export type GetUsageRequest$Outbound = { aggregation_type: string; billing_anchor?: string | undefined; bucket_size?: string | undefined; customer_id?: string | undefined; end_time?: string | undefined; event_name: string; external_customer_id?: string | undefined; filters?: { [k: string]: Array } | undefined; group_by?: Array | undefined; group_by_property?: string | undefined; multiplier?: string | undefined; property_name?: string | undefined; start_time?: string | undefined; timezone?: string | undefined; window_size?: string | undefined; }; /** @internal */ export const GetUsageRequest$outboundSchema: z.ZodMiniType< GetUsageRequest$Outbound, GetUsageRequest > = z.pipe( z.object({ aggregationType: AggregationType$outboundSchema, billingAnchor: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), bucketSize: z.optional(WindowSize$outboundSchema), customerId: z.optional(z.string()), endTime: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), eventName: z.string(), externalCustomerId: z.optional(z.string()), filters: z.optional(z.record(z.string(), z.array(z.string()))), groupBy: z.optional(z.array(z.string())), groupByProperty: z.optional(z.string()), multiplier: z.optional(z.string()), propertyName: z.optional(z.string()), startTime: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), timezone: z.optional(z.string()), windowSize: z.optional(WindowSize$outboundSchema), }), z.transform((v) => { return remap$(v, { aggregationType: "aggregation_type", billingAnchor: "billing_anchor", bucketSize: "bucket_size", customerId: "customer_id", endTime: "end_time", eventName: "event_name", externalCustomerId: "external_customer_id", groupBy: "group_by", groupByProperty: "group_by_property", propertyName: "property_name", startTime: "start_time", windowSize: "window_size", }); }), ); export function getUsageRequestToJSON( getUsageRequest: GetUsageRequest, ): string { return JSON.stringify(GetUsageRequest$outboundSchema.parse(getUsageRequest)); }