import {z} from 'zod' export type ContentStatus = 'Draft' | 'Active'; export type EntityIdType = 'WscId' | 'ServiceProviderId'; export type GetApiV1StoriesArgs = {ApiKey: string, Title?: string | undefined, LabelsFilterExpression?: string | undefined, Statuses?: Array | undefined, Geo?: string | undefined, OnlyLive?: boolean | undefined, 'UpdateTime.From'?: string | undefined, 'UpdateTime.To'?: string | undefined, 'CreateTime.From'?: string | undefined, 'CreateTime.To'?: string | undefined, 'Entities.Game.WscId'?: number | undefined, 'Entities.Game.ServiceProviderId'?: string | undefined, 'Entities.Team.WscId'?: number | undefined, 'Entities.Team.ServiceProviderId'?: string | undefined, 'Entities.Player.WscId'?: number | undefined, 'Entities.Player.ServiceProviderId'?: string | undefined, 'Entities.Round.WscId'?: number | undefined, 'Entities.Round.ServiceProviderId'?: string | undefined, 'Entities.Season.WscId'?: number | undefined, 'Entities.Season.ServiceProviderId'?: string | undefined, 'Entities.IdType'?: EntityIdType | undefined, PageNum?: number | undefined, PageSize?: number | undefined}; export type GetApiV1StoriesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const contentType = z.enum(["Story", "Moment", "Video"]); export const assetVideoAspectRatio = z.enum(["Square", "Horizontal", "Vertical", "Unknown", "FourToFive", "FiveToFour", "ThreeToFour", "FourToThree", "TwoToOne", "OneToTwo", "SevenToEight", "EightToSeven", "TwoToThree", "ThreeToOne", "ThreeToTwo", "OneToThree", "ThreeToEight", "FiveToOne"]); export const contentStatus = z.enum(["Draft", "Active"]); export const thumbnailDTO = z.object({url: z.string().nullable().optional(), aspectRatio: assetVideoAspectRatio.optional()}); export const geoTargeting = z.object({includedGeos: z.array(z.string()).nullable().optional(), excludedGeos: z.array(z.string()).nullable().optional()}); export const metadataEntityIds = z.object({provider: z.string().nullable().optional(), providerId: z.string().nullable().optional(), wscId: z.number().int().optional()}); export const contentMetadata = z.object({competition: metadataEntityIds.optional(), competitions: z.array(metadataEntityIds).nullable().optional(), game: metadataEntityIds.optional(), team: metadataEntityIds.optional(), player: metadataEntityIds.optional(), round: metadataEntityIds.optional(), season: metadataEntityIds.optional()}); export const executionTimeType = z.enum(["None", "PreGame", "InGame", "PostGame"]); export const pageDTO = z.object({id: z.string().nullable().optional(), index: z.number().int().optional(), duration: z.number().nullable().optional(), thumbnails: z.array(thumbnailDTO).nullable().optional(), createTime: z.string().optional(), updateTime: z.string().optional(), metadata: contentMetadata.optional(), extraInfo: z.record(z.string(), z.string().nullable()).nullable().optional()}); export const labelDTO = z.object({title: z.string().nullable().optional(), identifier: z.string().nullable().optional()}); export const storyDTO = z.object({id: z.string().nullable().optional(), type: contentType.optional(), title: z.string().nullable().optional(), description: z.string().nullable().optional(), version: z.number().int().optional(), aspectRatios: z.array(assetVideoAspectRatio).nullable().optional(), status: contentStatus.optional(), isLive: z.boolean().optional(), createTime: z.string().optional(), updateTime: z.string().optional(), thumbnails: z.array(thumbnailDTO).nullable().optional(), geoTargeting: geoTargeting.optional(), metadata: contentMetadata.optional(), executionTimeType: executionTimeType.optional(), htmlUrl: z.string().nullable().optional(), pages: z.array(pageDTO).nullable().optional(), labels: z.array(labelDTO).nullable().optional(), extraInfo: z.record(z.string(), z.string().nullable()).nullable().optional()}); export const storyDTOPaginationSearchResponse = z.object({totalItems: z.number().int().optional(), result: z.array(storyDTO).nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get stories * * GET /v1/stories */ export const getApiV1Stories = async (args: GetApiV1StoriesArgs, options?: GetApiV1StoriesOptions) => { const {baseUrl = "https://blazefeed.clipro.tv", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ApiKey != null) query.append("ApiKey", String(args.ApiKey)) if (args.Title != null) query.append("Title", String(args.Title)) if (args.LabelsFilterExpression != null) query.append("LabelsFilterExpression", String(args.LabelsFilterExpression)) for (const item of args.Statuses ?? []) query.append("Statuses", String(item)) if (args.Geo != null) query.append("Geo", String(args.Geo)) if (args.OnlyLive != null) query.append("OnlyLive", String(args.OnlyLive)) if (args['UpdateTime.From'] != null) query.append("UpdateTime.From", String(args['UpdateTime.From'])) if (args['UpdateTime.To'] != null) query.append("UpdateTime.To", String(args['UpdateTime.To'])) if (args['CreateTime.From'] != null) query.append("CreateTime.From", String(args['CreateTime.From'])) if (args['CreateTime.To'] != null) query.append("CreateTime.To", String(args['CreateTime.To'])) if (args['Entities.Game.WscId'] != null) query.append("Entities.Game.WscId", String(args['Entities.Game.WscId'])) if (args['Entities.Game.ServiceProviderId'] != null) query.append("Entities.Game.ServiceProviderId", String(args['Entities.Game.ServiceProviderId'])) if (args['Entities.Team.WscId'] != null) query.append("Entities.Team.WscId", String(args['Entities.Team.WscId'])) if (args['Entities.Team.ServiceProviderId'] != null) query.append("Entities.Team.ServiceProviderId", String(args['Entities.Team.ServiceProviderId'])) if (args['Entities.Player.WscId'] != null) query.append("Entities.Player.WscId", String(args['Entities.Player.WscId'])) if (args['Entities.Player.ServiceProviderId'] != null) query.append("Entities.Player.ServiceProviderId", String(args['Entities.Player.ServiceProviderId'])) if (args['Entities.Round.WscId'] != null) query.append("Entities.Round.WscId", String(args['Entities.Round.WscId'])) if (args['Entities.Round.ServiceProviderId'] != null) query.append("Entities.Round.ServiceProviderId", String(args['Entities.Round.ServiceProviderId'])) if (args['Entities.Season.WscId'] != null) query.append("Entities.Season.WscId", String(args['Entities.Season.WscId'])) if (args['Entities.Season.ServiceProviderId'] != null) query.append("Entities.Season.ServiceProviderId", String(args['Entities.Season.ServiceProviderId'])) if (args['Entities.IdType'] != null) query.append("Entities.IdType", String(args['Entities.IdType'])) if (args.PageNum != null) query.append("PageNum", String(args.PageNum)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stories${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(storyDTOPaginationSearchResponse, await res.json()) };