import {z} from 'zod' export type GetApiV1OrgsOrgIdDashboardsDashboardIdArgs = {org_id: string, dashboard_id: string}; export type GetApiV1OrgsOrgIdDashboardsDashboardIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dashboardResourceAccess = z.object({domain: z.string().optional(), facet_path: z.string().optional(), query: z.string().optional(), scope: z.string().optional()}); export const dashboardTemplateVariable = z.object({identifier: z.string().optional(), view_value: z.unknown()}); export const dashboardSavedView = z.object({template_variables: z.array(dashboardTemplateVariable).optional()}); export const dashboardScreenshotStatus = z.enum(["pending", "ok", "error"]); export const dashboardScreenshot = z.object({dark_url: z.string().optional(), full_dark_url: z.string().optional(), full_light_url: z.string().optional(), last_triggered_at: z.string().optional(), last_updated_at: z.string().optional(), light_url: z.string().optional(), reported_error: z.boolean().optional(), status: dashboardScreenshotStatus.optional()}); export const dashboardSharingSecuritySettings = z.object({allowed_cidrs: z.array(z.string()).optional(), prefilter: z.string().optional(), shared_until: z.string().optional()}); export const dashboardDashboard = z.object({created: z.string().optional(), creator: z.string().optional(), dashboard_id: z.string().optional(), dashboard_name: z.string().optional(), definition: z.record(z.string(), z.unknown()).optional(), description: z.string().optional(), org_id: z.string().optional(), resource_accesses: z.array(dashboardResourceAccess).optional(), saved_views: z.record(z.string(), dashboardSavedView).optional(), screenshot: dashboardScreenshot.optional(), shared_hash: z.string().optional(), sharing_security_settings: dashboardSharingSecuritySettings.optional(), tags: z.array(z.string()).optional(), updated: z.string().optional(), updater: z.string().optional()}); export const getApiV1OrgsOrgIdDashboardsDashboardIdResponse = z.array(dashboardDashboard); 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 }; /** * Returns the dashboard for the given ID. * * GET /v1/orgs/{org_id}/dashboards/{dashboard_id} */ export const getApiV1OrgsOrgIdDashboardsDashboardId = async (args: GetApiV1OrgsOrgIdDashboardsDashboardIdArgs, options?: GetApiV1OrgsOrgIdDashboardsDashboardIdOptions) => { const {baseUrl = "https://api.edgedelta.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-ED-API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/orgs/${encodeURIComponent(String(args.org_id))}/dashboards/${encodeURIComponent(String(args.dashboard_id))}${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(getApiV1OrgsOrgIdDashboardsDashboardIdResponse, await res.json()) };