import {z} from 'zod' export type GetApiApiV1ArticlesIdArgs = {id: string, include_peripheral?: boolean | undefined, 'If-None-Match'?: string | undefined, 'If-Modified-Since'?: string | undefined}; export type GetApiApiV1ArticlesIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const articleDetail = z.object({id: z.string(), title: z.string(), article_url: z.string(), content_type: z.enum(["news", "analysis", "press_release", "market_commentary", "market_news", "trading_halt", "trading_event", "other"]), published_at: z.string(), updated_at: z.string(), category: z.object({id: z.string().optional(), name: z.string().optional()}), source: z.object({id: z.string().optional(), name: z.string().optional(), domain: z.string().optional(), source_type: z.enum(["news_publication", "wire_service", "press_release", "government", "trade_publication", "blog", "stock_exchange", "research"]).optional()}), company_ids: z.array(z.string()), country: z.string().nullable(), event_id: z.string().nullable().optional(), source_title: z.string().optional(), summary: z.string().optional(), story_ids: z.array(z.string()).optional(), companies: z.array(z.object({id: z.string(), name: z.string(), ticker: z.string().nullable().optional(), is_primary: z.boolean(), association_tier: z.enum(["principal", "peripheral"])})).optional(), key_points: z.array(z.string()).optional()}); export const getApiApiV1ArticlesIdResponse = z.object({article: articleDetail.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 Article Details * * GET /api/v1/articles/{id} */ export const getApiApiV1ArticlesId = async (args: GetApiApiV1ArticlesIdArgs, options?: GetApiApiV1ArticlesIdOptions) => { const {baseUrl = "https://nordicfinancialnews.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_peripheral != null) query.append("include_peripheral", String(args.include_peripheral)) if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) if (args['If-Modified-Since'] != null) headers.set("If-Modified-Since", String(args['If-Modified-Since'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/articles/${encodeURIComponent(String(args.id))}${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(getApiApiV1ArticlesIdResponse, await res.json()) };