import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdEconomicCalendarRiskHeatmapArgs = {projectId: string, from?: string | undefined, to?: string | undefined, currencies?: string | undefined}; export type GetApiRestApiV1ProjectsProjectIdEconomicCalendarRiskHeatmapOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const riskHeatCellDTO = z.object({currencyCode: z.string().optional(), day: z.string().optional(), highImpact: z.number().int().optional(), mediumImpact: z.number().int().optional(), score: z.number().int().optional(), topEventTitle: z.string().optional()}); export const riskHeatmapDTO = z.object({cells: z.array(riskHeatCellDTO).optional(), currencies: z.array(z.string()).optional(), days: z.array(z.string()).optional(), fromUtc: z.string().optional(), toUtc: z.string().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 }; /** * Event load per day and currency * * GET /rest/api/v1/projects/{projectId}/economicCalendar/riskHeatmap */ export const getApiRestApiV1ProjectsProjectIdEconomicCalendarRiskHeatmap = async (args: GetApiRestApiV1ProjectsProjectIdEconomicCalendarRiskHeatmapArgs, options?: GetApiRestApiV1ProjectsProjectIdEconomicCalendarRiskHeatmapOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.currencies != null) query.append("currencies", String(args.currencies)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/economicCalendar/riskHeatmap${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(riskHeatmapDTO, await res.json()) };