import {z} from 'zod' export type GetApiV1FredCalendarArgs = {startDate?: string | undefined, endDate?: string | undefined, minImportance?: string | undefined, limit?: number | undefined, country?: string | undefined}; export type GetApiV1FredCalendarOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listingNotice = z.object({status: z.string().nullable().optional(), ticker: z.string().nullable().optional(), delistedOn: z.string().nullable().optional(), successorTicker: z.string().nullable().optional()}); export const fredReleaseDateDto = z.object({date: z.string().optional(), release: z.string().nullable().optional(), countryCode: z.string().nullable().optional(), publisher: z.string().nullable().optional(), referencePeriod: z.string().nullable().optional(), importance: z.string().nullable().optional(), series: z.array(z.string()).nullable().optional()}); export const pageMeta = z.object({limit: z.number().int().optional(), offset: z.number().int().optional(), count: z.number().int().optional(), hasMore: z.boolean().optional(), total: z.number().int().nullable().optional()}); export const fredReleaseDateDtoPagedResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(fredReleaseDateDto).nullable().optional(), meta: pageMeta.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 }; /** * Economic release calendar — scheduled (upcoming) and recent publication dates of US and Canadian macro data releases, chronological, with the indicator series each release updates and an importance tier per release (High = tier-1 scheduled market movers such as CPI, PPI, jobs, GDP, PCE, retail sales; Medium = other genuine scheduled prints; Low = daily rate/market levels). FOMC meetings are NOT included — FRED's release feed has no real FOMC meeting dates; use the Federal Reserve's published meeting calendar for those. The low tier emits several daily-rate rows per business day, so the default page can clip the window — check meta.hasMore, raise limit, or pass minImportance=medium/high. * * GET /v1/fred/calendar */ export const getApiV1FredCalendar = async (args: GetApiV1FredCalendarArgs, options?: GetApiV1FredCalendarOptions) => { const {baseUrl = "https://api.equibles.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.minImportance != null) query.append("minImportance", String(args.minImportance)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.country != null) query.append("country", String(args.country)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/fred/calendar${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(fredReleaseDateDtoPagedResponse, await res.json()) };