/* * 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 From = Date | number; /** * End timestamp for the query range (exclusive) */ export type To = Date | number; /** * The time step to aggregate viewership metrics by */ export enum TimeStep { Hour = "hour", Day = "day", Week = "week", Month = "month", Year = "year", } export enum QueryParamBreakdownBy { PlaybackId = "playbackId", DeviceType = "deviceType", Device = "device", Cpu = "cpu", Os = "os", Browser = "browser", BrowserEngine = "browserEngine", Continent = "continent", Country = "country", Subdivision = "subdivision", Timezone = "timezone", Geohash = "geohash", ViewerId = "viewerId", CreatorId = "creatorId", } export type GetViewershipMetricsRequest = { /** * The playback ID to filter the query results. This can be a canonical * * @remarks * playback ID from Livepeer assets or streams, or dStorage identifiers * for assets */ playbackId?: string | undefined; /** * 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?: TimeStep | 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 GetViewershipMetricsResponse = { /** * 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 From$inboundSchema: z.ZodType = z .union([ z.string().datetime({ offset: true }).transform(v => new Date(v)), z.number().int(), ]); /** @internal */ export type From$Outbound = string | number; /** @internal */ export const From$outboundSchema: z.ZodType = 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 From$ { /** @deprecated use `From$inboundSchema` instead. */ export const inboundSchema = From$inboundSchema; /** @deprecated use `From$outboundSchema` instead. */ export const outboundSchema = From$outboundSchema; /** @deprecated use `From$Outbound` instead. */ export type Outbound = From$Outbound; } export function fromToJSON(from: From): string { return JSON.stringify(From$outboundSchema.parse(from)); } export function fromFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => From$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'From' from JSON`, ); } /** @internal */ export const To$inboundSchema: z.ZodType = z.union([ z.string().datetime({ offset: true }).transform(v => new Date(v)), z.number().int(), ]); /** @internal */ export type To$Outbound = string | number; /** @internal */ export const To$outboundSchema: z.ZodType = 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 To$ { /** @deprecated use `To$inboundSchema` instead. */ export const inboundSchema = To$inboundSchema; /** @deprecated use `To$outboundSchema` instead. */ export const outboundSchema = To$outboundSchema; /** @deprecated use `To$Outbound` instead. */ export type Outbound = To$Outbound; } export function toToJSON(to: To): string { return JSON.stringify(To$outboundSchema.parse(to)); } export function toFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => To$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'To' from JSON`, ); } /** @internal */ export const TimeStep$inboundSchema: z.ZodNativeEnum = z .nativeEnum(TimeStep); /** @internal */ export const TimeStep$outboundSchema: z.ZodNativeEnum = TimeStep$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace TimeStep$ { /** @deprecated use `TimeStep$inboundSchema` instead. */ export const inboundSchema = TimeStep$inboundSchema; /** @deprecated use `TimeStep$outboundSchema` instead. */ export const outboundSchema = TimeStep$outboundSchema; } /** @internal */ export const QueryParamBreakdownBy$inboundSchema: z.ZodNativeEnum< typeof QueryParamBreakdownBy > = z.nativeEnum(QueryParamBreakdownBy); /** @internal */ export const QueryParamBreakdownBy$outboundSchema: z.ZodNativeEnum< typeof QueryParamBreakdownBy > = QueryParamBreakdownBy$inboundSchema; /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace QueryParamBreakdownBy$ { /** @deprecated use `QueryParamBreakdownBy$inboundSchema` instead. */ export const inboundSchema = QueryParamBreakdownBy$inboundSchema; /** @deprecated use `QueryParamBreakdownBy$outboundSchema` instead. */ export const outboundSchema = QueryParamBreakdownBy$outboundSchema; } /** @internal */ export const GetViewershipMetricsRequest$inboundSchema: z.ZodType< GetViewershipMetricsRequest, z.ZodTypeDef, unknown > = z.object({ playbackId: z.string().optional(), 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: TimeStep$inboundSchema.optional(), assetId: z.string().optional(), streamId: z.string().optional(), creatorId: z.string().optional(), "breakdownBy[]": z.array(QueryParamBreakdownBy$inboundSchema).optional(), }).transform((v) => { return remap$(v, { "breakdownBy[]": "breakdownBy", }); }); /** @internal */ export type GetViewershipMetricsRequest$Outbound = { playbackId?: string | undefined; 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 GetViewershipMetricsRequest$outboundSchema: z.ZodType< GetViewershipMetricsRequest$Outbound, z.ZodTypeDef, GetViewershipMetricsRequest > = z.object({ playbackId: z.string().optional(), 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: TimeStep$outboundSchema.optional(), assetId: z.string().optional(), streamId: z.string().optional(), creatorId: z.string().optional(), breakdownBy: z.array(QueryParamBreakdownBy$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 GetViewershipMetricsRequest$ { /** @deprecated use `GetViewershipMetricsRequest$inboundSchema` instead. */ export const inboundSchema = GetViewershipMetricsRequest$inboundSchema; /** @deprecated use `GetViewershipMetricsRequest$outboundSchema` instead. */ export const outboundSchema = GetViewershipMetricsRequest$outboundSchema; /** @deprecated use `GetViewershipMetricsRequest$Outbound` instead. */ export type Outbound = GetViewershipMetricsRequest$Outbound; } export function getViewershipMetricsRequestToJSON( getViewershipMetricsRequest: GetViewershipMetricsRequest, ): string { return JSON.stringify( GetViewershipMetricsRequest$outboundSchema.parse( getViewershipMetricsRequest, ), ); } export function getViewershipMetricsRequestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetViewershipMetricsRequest$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetViewershipMetricsRequest' from JSON`, ); } /** @internal */ export const GetViewershipMetricsResponse$inboundSchema: z.ZodType< GetViewershipMetricsResponse, 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 GetViewershipMetricsResponse$Outbound = { ContentType: string; StatusCode: number; RawResponse: never; data?: Array | undefined; error?: components.ErrorT$Outbound | undefined; }; /** @internal */ export const GetViewershipMetricsResponse$outboundSchema: z.ZodType< GetViewershipMetricsResponse$Outbound, z.ZodTypeDef, GetViewershipMetricsResponse > = 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 GetViewershipMetricsResponse$ { /** @deprecated use `GetViewershipMetricsResponse$inboundSchema` instead. */ export const inboundSchema = GetViewershipMetricsResponse$inboundSchema; /** @deprecated use `GetViewershipMetricsResponse$outboundSchema` instead. */ export const outboundSchema = GetViewershipMetricsResponse$outboundSchema; /** @deprecated use `GetViewershipMetricsResponse$Outbound` instead. */ export type Outbound = GetViewershipMetricsResponse$Outbound; } export function getViewershipMetricsResponseToJSON( getViewershipMetricsResponse: GetViewershipMetricsResponse, ): string { return JSON.stringify( GetViewershipMetricsResponse$outboundSchema.parse( getViewershipMetricsResponse, ), ); } export function getViewershipMetricsResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => GetViewershipMetricsResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'GetViewershipMetricsResponse' from JSON`, ); }