import {z} from 'zod' export type GetApiApiOrgIdPublicDashboardsArgs = {org_id: string}; export type GetApiApiOrgIdPublicDashboardsOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const publicLinkStatus = z.enum(["live", "paused", "not_viewed", "needs_attention", "expired", "dashboard_deleted", "disabled"]); export const publicDashboardTimeRange = z.union([z.object({secs: z.number().int(), type: z.literal("relative")}), z.object({end: z.number().int(), start: z.number().int(), type: z.literal("absolute")})]); export const timeRangePolicy = z.object({default: publicDashboardTimeRange, ranges: z.array(publicDashboardTimeRange)}); export const publicLinkView = z.object({access_count: z.number().int(), created_at: z.number().int(), dashboard_id: z.string(), dashboard_title: z.string().nullable().optional(), enabled: z.boolean(), expires_at: z.number().int().nullable().optional(), folder_id: z.string().nullable().optional(), folder_name: z.string().nullable().optional(), frozen_variables: z.record(z.string(), z.unknown()), id: z.string(), last_accessed_at: z.number().int().nullable().optional(), name: z.string(), published_by: z.string(), publisher_left: z.boolean(), refresh_secs: z.number().int(), slug: z.string().nullable().optional(), status: publicLinkStatus, time_range: timeRangePolicy, updated_at: z.number().int(), updated_by: z.string().nullable().optional()}); export const publicLinkList = z.object({list: z.array(publicLinkView)}); 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 }; /** * List public dashboard links of an organization * * GET /api/{org_id}/public_dashboards */ export const getApiApiOrgIdPublicDashboards = async (args: GetApiApiOrgIdPublicDashboardsArgs, options: GetApiApiOrgIdPublicDashboardsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/public_dashboards${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(publicLinkList, await res.json()) };