import {z} from 'zod' export type GetApiV1CustomDataSetsOptions = {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 webDataFeedSummaryDto = z.object({id: z.string().optional(), name: z.string().nullable().optional(), status: z.string().nullable().optional(), access: z.string().nullable().optional(), visibility: z.string().nullable().optional(), intervalHours: z.number().int().optional(), nextRunAt: z.string().nullable().optional(), latestRunStatus: z.string().nullable().optional(), failureReason: z.string().nullable().optional(), latestVerifiedAt: z.string().nullable().optional()}); export const webDataFeedSummaryDtoListResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(webDataFeedSummaryDto).nullable().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 }; /** * Lists the trackers (recurring web data feeds) owned by the API-key account. This * endpoint is read-only and never contacts a source website. Create and manage trackers in the * Equibles Portal under Dashboard → Trackers. * * GET /v1/custom-data-sets */ export const getApiV1CustomDataSets = async (options?: GetApiV1CustomDataSetsOptions) => { 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 (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/custom-data-sets${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(webDataFeedSummaryDtoListResponse, await res.json()) };