import {z} from 'zod' export type GetApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjectionsArgs = {format: 'JSON' | 'XML'}; export type GetApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjectionsOptions = {baseUrl?: string | undefined, apiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const dfsSlatePlayerOwnershipProjection = z.object({SlateID: z.number().int().optional(), PlayerID: z.number().int().optional(), ProjectedOwnershipPercentage: z.number().optional(), IsCaptain: z.boolean().optional()}); export const dfsSlateWithOwnershipProjection = z.object({SlateID: z.number().int().optional(), Operator: z.string().nullable().optional(), OperatorSlateID: z.number().int().nullable().optional(), OperatorName: z.string().nullable().optional(), OperatorDay: z.string().nullable().optional(), OperatorStartTime: z.string().nullable().optional(), SlateOwnershipProjections: z.array(dfsSlatePlayerOwnershipProjection).optional()}); export const getApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjectionsResponse = z.array(dfsSlateWithOwnershipProjection); 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 }; /** * DFS Slate Ownership Projections - Upcoming * * GET /v3/mlb/projections/{format}/UpcomingDfsSlateOwnershipProjections * * Also accepts auth: apiKeyQuery */ export const getApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjections = async (args: GetApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjectionsArgs, options?: GetApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjectionsOptions) => { 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/projections/${encodeURIComponent(String(args.format))}/UpcomingDfsSlateOwnershipProjections${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(getApiV3MlbProjectionsFormatUpcomingDfsSlateOwnershipProjectionsResponse, await res.json()) };