import {z} from 'zod' export type GetApiApiOrgIdPublicDashboardsStatusArgs = {org_id: string, ids?: string | undefined}; export type GetApiApiOrgIdPublicDashboardsStatusOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const rangeState = z.enum(["cached", "not_cached", "building", "needs_attention"]); export const notAvailableReason = z.enum(["unauthorized", "unsupported", "no_query", "too_large", "too_many_panels", "truncated", "build_error", "too_old", "changed"]); export const withheldPanel = z.object({panel_id: z.string(), reason: notAvailableReason}); export const rangeStatus = z.object({built_at: z.number().int().nullable().optional(), incomplete_count: z.number().int().gte(0), key: z.string(), last_error: z.string().nullable().optional(), next_retry_at: z.number().int().nullable().optional(), sources: z.record(z.string(), z.array(z.array(z.string()))).nullable().optional(), state: rangeState, unavailable_count: z.number().int().gte(0), withheld_panels: z.array(withheldPanel)}); export const linkStatusReport = z.object({access_count: z.number().int(), last_accessed_at: z.number().int().nullable().optional(), link_id: z.string(), ranges: z.array(rangeStatus)}); export const linkStatusList = z.object({list: z.array(linkStatusReport)}); 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 the status of public dashboard links * * GET /api/{org_id}/public_dashboards/status */ export const getApiApiOrgIdPublicDashboardsStatus = async (args: GetApiApiOrgIdPublicDashboardsStatusArgs, options: GetApiApiOrgIdPublicDashboardsStatusOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ids != null) query.append("ids", String(args.ids)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/public_dashboards/status${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(linkStatusList, await res.json()) };