/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as components from "../components/index.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * Start timestamp for the query range (inclusive) */ export type QueryParamFrom = Date | number; /** * End timestamp for the query range (exclusive) */ export type QueryParamTo = Date | number; /** * The time step to aggregate viewership metrics by */ export enum QueryParamTimeStep { Hour = "hour", Day = "day", Week = "week", Month = "month", Year = "year", } export enum GetCreatorViewershipMetricsQueryParamBreakdownBy { DeviceType = "deviceType", Device = "device", Cpu = "cpu", Os = "os", Browser = "browser", BrowserEngine = "browserEngine", Continent = "continent", Country = "country", Subdivision = "subdivision", Timezone = "timezone", ViewerId = "viewerId", } export type GetCreatorViewershipMetricsRequest = { /** * Start timestamp for the query range (inclusive) */ from?: Date | number | undefined; /** * End timestamp for the query range (exclusive) */ to?: Date | number | undefined; /** * The time step to aggregate viewership metrics by */ timeStep?: QueryParamTimeStep | undefined; /** * The asset ID to filter metrics for */ assetId?: string | undefined; /** * The stream ID to filter metrics for */ streamId?: string | undefined; /** * The creator ID to filter the query results */ creatorId?: string | undefined; /** * The list of fields to break down the query results. Specify this * * @remarks * query-string multiple times to break down by multiple fields. */ breakdownBy?: | Array | undefined; }; export type GetCreatorViewershipMetricsResponse = { /** * HTTP response content type for this operation */ contentType: string; /** * HTTP response status code for this operation */ statusCode: number; /** * Raw HTTP response; suitable for custom response parsing */ rawResponse: Response; /** * A list of Metric objects */ data?: Array | undefined; /** * Error */ error?: components.ErrorT | undefined; }; /** @internal */ export const QueryParamFrom$inboundSchema: z.ZodType< QueryParamFrom, z.ZodTypeDef, unknown > = z.union([ z.string().datetime({ offset: true }).transform(v => new Date(v)), z.number().int(), ]); /** @internal */ export type QueryParamFrom$Outbound = string | number; /** @internal */ export const QueryParamFrom$outboundSchema: z.ZodType< QueryParamFrom$Outbound, z.ZodTypeDef, QueryParamFrom > = z.union([z.date().transform(v => v.toISOString()), z.number().int()]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace QueryParamFrom$ { /** @deprecated use `QueryParamFrom$inboundSchema` instead. */ export const inboundSchema = QueryParamFrom$inboundSchema; /** @deprecated use `QueryParamFrom$outboundSchema` instead. */ export const outboundSchema = QueryParamFrom$outboundSchema; /** @deprecated use `QueryParamFrom$Outbound` instead. */ export type Outbound = QueryParamFrom$Outbound; } export function queryParamFromToJSON(queryParamFrom: QueryParamFrom): string { return JSON.stringify(QueryParamFrom$outboundSchema.parse(queryParamFrom)); } export function queryParamFromFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => QueryParamFrom$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'QueryParamFrom' from JSON`, ); } /** @internal */ export const QueryParamTo$inboundSchema: z.ZodType< QueryParamTo, z.ZodTypeDef, unknown > = z.union([ z.string().datetime({ offset: true }).transform(v => new Date(v)), z.number().int(), ]); /** @internal */ export type QueryParamTo$Outbound = string | number; /** @internal */ export const QueryParamTo$outboundSchema: z.ZodType< QueryParamTo$Outbound, z.ZodTypeDef, QueryParamTo > = z.union([z.date().transform(v => v.toISOString()), z.number().int()]); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace QueryParamTo$ { /** @deprecated use `QueryParamTo$inboundSchema` instead. */ export const inboundSchema = QueryParamTo$inboundSchema; /** @deprecated use `QueryParamTo$outboundSchema` instead. */ export const outboundSchema = QueryParamTo$outboundSchema; /** @deprecated use `QueryParamTo$Outbound` instead. */ export type Outbound = QueryParamTo$Outbound; } export function queryParamToToJSON(queryParamTo: QueryParamTo): string { return JSON.stringify(QueryParamTo$outboundSchema.parse(queryParamTo)); } export function queryParamToFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => QueryParamTo$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'QueryParamTo' from JSON`, ); } /** @internal */ export const QueryParamTimeStep$inboundSchema: z.ZodNativeEnum< typeof QueryParamTimeStep > = z.nativeEnum(QueryParamTimeStep); /** @internal */ export const QueryParamTimeStep$outboundSchema: z.ZodNativeEnum< typeof QueryParamTimeStep > = QueryParamTimeStep$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace QueryParamTimeStep$ { /** @deprecated use `QueryParamTimeStep$inboundSchema` instead. */ export const inboundSchema = QueryParamTimeStep$inboundSchema; /** @deprecated use `QueryParamTimeStep$outboundSchema` instead. */ export const outboundSchema = QueryParamTimeStep$outboundSchema; } /** @internal */ export const GetCreatorViewershipMetricsQueryParamBreakdownBy$inboundSchema: z.ZodNativeEnum = z .nativeEnum(GetCreatorViewershipMetricsQueryParamBreakdownBy); /** @internal */ export const GetCreatorViewershipMetricsQueryParamBreakdownBy$outboundSchema: z.ZodNativeEnum = GetCreatorViewershipMetricsQueryParamBreakdownBy$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace GetCreatorViewershipMetricsQueryParamBreakdownBy$ { /** @deprecated use `GetCreatorViewershipMetricsQueryParamBreakdownBy$inboundSchema` instead. */ export const inboundSchema = GetCreatorViewershipMetricsQueryParamBreakdownBy$inboundSchema; /** @deprecated use `GetCreatorViewershipMetricsQueryParamBreakdownBy$outboundSchema` instead. */ export const outboundSchema = GetCreatorViewershipMetricsQueryParamBreakdownBy$outboundSchema; } /** @internal */ export const GetCreatorViewershipMetricsRequest$inboundSchema: z.ZodType< GetCreatorViewershipMetricsRequest, z.ZodTypeDef, unknown > = z.object({ from: z.union([ z.string().datetime({ offset: true }).transform(v => new Date(v)), z.number().int(), ]).optional(), to: z.union([ z.string().datetime({ offset: true }).transform(v => new Date(v)), z.number().int(), ]).optional(), timeStep: QueryParamTimeStep$inboundSchema.optional(), assetId: z.string().optional(), streamId: z.string().optional(), creatorId: z.string().optional(), "breakdownBy[]": z.array( GetCreatorViewershipMetricsQueryParamBreakdownBy$inboundSchema, ).optional(), }).transform((v) => { return remap$(v, { "breakdownBy[]": "breakdownBy", }); }); /** @internal */ export type GetCreatorViewershipMetricsRequest$Outbound = { from?: string | number | undefined; to?: string | number | undefined; timeStep?: string | undefined; assetId?: string | undefined; streamId?: string | undefined; creatorId?: string | undefined; "breakdownBy[]"?: Array | undefined; }; /** @internal */ export const GetCreatorViewershipMetricsRequest$outboundSchema: z.ZodType< GetCreatorViewershipMetricsRequest$Outbound, z.ZodTypeDef, GetCreatorViewershipMetricsRequest > = z.object({ from: z.union([z.date().transform(v => v.toISOString()), z.number().int()]) .optional(), to: z.union([z.date().transform(v => v.toISOString()), z.number().int()]) .optional(), timeStep: QueryParamTimeStep$outboundSchema.optional(), assetId: z.string().optional(), streamId: z.string().optional(), creatorId: z.string().optional(), breakdownBy: z.array( GetCreatorViewershipMetricsQueryParamBreakdownBy$outboundSchema, ).optional(), }).transform((v) => { return remap$(v, { breakdownBy: "breakdownBy[]", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace GetCreatorViewershipMetricsRequest$ { /** @deprecated use `GetCreatorViewershipMetricsRequest$inboundSchema` instead. */ export const inboundSchema = GetCreatorViewershipMetricsRequest$inboundSchema; /** @deprecated use `GetCreatorViewershipMetricsRequest$outboundSchema` instead. */ export const outboundSchema = GetCreatorViewershipMetricsRequest$outboundSchema; /** @deprecated use `GetCreatorViewershipMetricsRequest$Outbound` instead. */ export type Outbound = GetCreatorViewershipMetricsRequest$Outbound; } export function getCreatorViewershipMetricsRequestToJSON( getCreatorViewershipMetricsRequest: GetCreatorViewershipMetricsRequest, ): string { return JSON.stringify( GetCreatorViewershipMetricsRequest$outboundSchema.parse( getCreatorViewershipMetricsRequest, ), ); } export function getCreatorViewershipMetricsRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCreatorViewershipMetricsRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCreatorViewershipMetricsRequest' from JSON`, ); } /** @internal */ export const GetCreatorViewershipMetricsResponse$inboundSchema: z.ZodType< GetCreatorViewershipMetricsResponse, z.ZodTypeDef, unknown > = z.object({ ContentType: z.string(), StatusCode: z.number().int(), RawResponse: z.instanceof(Response), data: z.array(components.ViewershipMetric$inboundSchema).optional(), error: components.ErrorT$inboundSchema.optional(), }).transform((v) => { return remap$(v, { "ContentType": "contentType", "StatusCode": "statusCode", "RawResponse": "rawResponse", }); }); /** @internal */ export type GetCreatorViewershipMetricsResponse$Outbound = { ContentType: string; StatusCode: number; RawResponse: never; data?: Array | undefined; error?: components.ErrorT$Outbound | undefined; }; /** @internal */ export const GetCreatorViewershipMetricsResponse$outboundSchema: z.ZodType< GetCreatorViewershipMetricsResponse$Outbound, z.ZodTypeDef, GetCreatorViewershipMetricsResponse > = z.object({ contentType: z.string(), statusCode: z.number().int(), rawResponse: z.instanceof(Response).transform(() => { throw new Error("Response cannot be serialized"); }), data: z.array(components.ViewershipMetric$outboundSchema).optional(), error: components.ErrorT$outboundSchema.optional(), }).transform((v) => { return remap$(v, { contentType: "ContentType", statusCode: "StatusCode", rawResponse: "RawResponse", }); }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace GetCreatorViewershipMetricsResponse$ { /** @deprecated use `GetCreatorViewershipMetricsResponse$inboundSchema` instead. */ export const inboundSchema = GetCreatorViewershipMetricsResponse$inboundSchema; /** @deprecated use `GetCreatorViewershipMetricsResponse$outboundSchema` instead. */ export const outboundSchema = GetCreatorViewershipMetricsResponse$outboundSchema; /** @deprecated use `GetCreatorViewershipMetricsResponse$Outbound` instead. */ export type Outbound = GetCreatorViewershipMetricsResponse$Outbound; } export function getCreatorViewershipMetricsResponseToJSON( getCreatorViewershipMetricsResponse: GetCreatorViewershipMetricsResponse, ): string { return JSON.stringify( GetCreatorViewershipMetricsResponse$outboundSchema.parse( getCreatorViewershipMetricsResponse, ), ); } export function getCreatorViewershipMetricsResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetCreatorViewershipMetricsResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetCreatorViewershipMetricsResponse' from JSON`, ); }