import {z} from 'zod' export type GetApiApiNewsMyArticlesArgs = {perPage?: number | undefined, company?: string | undefined, agency?: string | undefined, team?: string | undefined, category?: string | undefined, subcategory?: string | undefined, league?: string | undefined, newsTag?: string | undefined, publishedAfter?: string | undefined, publishedBefore?: string | undefined}; export type GetApiApiNewsMyArticlesOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const curatedNews = z.object({id: z.number().int().optional(), url: z.string().optional(), is_active: z.number().int().optional(), reporter_id: z.number().int().optional(), title: z.string().optional(), description: z.string().optional(), image: z.string().optional(), created_at: z.string().optional(), content_markdown: z.string().optional(), ingestion_request_id: z.string().optional(), updated_at: z.string().optional(), published_at: z.string().optional()}); export const getApiApiNewsMyArticlesResponse = z.object({current_page: z.number().int().optional(), data: z.array(curatedNews).optional(), first_page_url: z.string().nullable().optional(), from: z.number().int().nullable().optional(), last_page: z.number().int().optional(), last_page_url: z.string().optional(), next_page_url: z.string().nullable().optional(), path: z.string().optional(), per_page: z.number().int().optional(), prev_page_url: z.string().nullable().optional(), to: z.number().int().nullable().optional(), total: z.number().int().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 }; /** * List current user's curated news articles * * GET /api/news/my-articles */ export const getApiApiNewsMyArticles = async (args: GetApiApiNewsMyArticlesArgs, options: GetApiApiNewsMyArticlesOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.perPage != null) query.append("perPage", String(args.perPage)) if (args.company != null) query.append("company", String(args.company)) if (args.agency != null) query.append("agency", String(args.agency)) if (args.team != null) query.append("team", String(args.team)) if (args.category != null) query.append("category", String(args.category)) if (args.subcategory != null) query.append("subcategory", String(args.subcategory)) if (args.league != null) query.append("league", String(args.league)) if (args.newsTag != null) query.append("newsTag", String(args.newsTag)) if (args.publishedAfter != null) query.append("publishedAfter", String(args.publishedAfter)) if (args.publishedBefore != null) query.append("publishedBefore", String(args.publishedBefore)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/news/my-articles${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(getApiApiNewsMyArticlesResponse, await res.json()) };