import {z} from 'zod' export type GetApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDateArgs = {format: 'JSON' | 'XML', date: string}; export type GetApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDateOptions = {baseUrl?: string | undefined, apiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const news = z.object({NewsID: z.number().int().optional(), Source: z.string().nullable().optional(), Updated: z.string().nullable().optional(), TimeAgo: z.string().nullable().optional(), Title: z.string().nullable().optional(), Content: z.string().nullable().optional(), Url: z.string().nullable().optional(), TermsOfUse: z.string().nullable().optional(), Author: z.string().nullable().optional(), Categories: z.string().nullable().optional(), PlayerID: z.number().int().nullable().optional(), TeamID: z.number().int().nullable().optional(), Team: z.string().nullable().optional(), PlayerID2: z.number().int().nullable().optional(), TeamID2: z.number().int().nullable().optional(), Team2: z.string().nullable().optional(), OriginalSource: z.string().nullable().optional(), OriginalSourceUrl: z.string().nullable().optional()}); export const getApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDateResponse = z.array(news); 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 }; /** * Premium News - by Date * * GET /v3/mlb/news-rotoballer/{format}/RotoBallerPremiumNewsByDate/{date} * * Also accepts auth: apiKeyQuery */ export const getApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDate = async (args: GetApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDateArgs, options?: GetApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDateOptions) => { const {baseUrl = "https://api.sportsdata.io", fetch: fetchFn = fetch, apiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyHeader !== undefined) headers.set("Ocp-Apim-Subscription-Key", apiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v3/mlb/news-rotoballer/${encodeURIComponent(String(args.format))}/RotoBallerPremiumNewsByDate/${encodeURIComponent(String(args.date))}${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(getApiV3MlbNewsRotoballerFormatRotoBallerPremiumNewsByDateDateResponse, await res.json()) };