import {z} from 'zod' export type GetApiRestApiV1ProjectsProjectIdDashboardsArgs = {projectId: string}; export type GetApiRestApiV1ProjectsProjectIdDashboardsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jsonNode = z.object({}); export const gridsterItemDTO = z.object({cols: z.number().int().optional(), dragEnabled: z.boolean().optional(), maxItemCols: z.number().int().optional(), maxItemRows: z.number().int().optional(), minItemCols: z.number().int().optional(), minItemRows: z.number().int().optional(), resizeEnabled: z.boolean().optional(), rows: z.number().int().optional(), x: z.number().int().optional(), y: z.number().int().optional()}); export const widgetConfigDTO = z.object({config: jsonNode.optional(), gridsterItem: gridsterItemDTO, id: z.string().optional(), title: z.string().max(100).optional(), type: z.enum(["ACCOUNT_STATUS", "REAL_TIME_PNL", "ACCOUNT", "TERMINAL", "OPEN_INVOICES", "PROJECT_BALANCE", "FINANCIAL_OVERVIEW", "LOGS", "AUDIT_LOGS", "NOTES", "DIVIDER", "CLOCK", "WEATHER"])}); export const userDashboardConfigDTO = z.object({createdAt: z.string().optional(), description: z.string().max(500).optional(), id: z.string().optional(), isDefault: z.boolean().optional(), modifiedAt: z.string().optional(), name: z.string().min(1).max(100), projectId: z.string().optional(), sortOrder: z.number().int().optional(), widgets: z.array(widgetConfigDTO).optional()}); export const dashboardStorageDTO = z.object({dashboards: z.array(userDashboardConfigDTO).optional(), syncedAt: 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 }; /** * Get all dashboards * * GET /rest/api/v1/projects/{projectId}/dashboards */ export const getApiRestApiV1ProjectsProjectIdDashboards = async (args: GetApiRestApiV1ProjectsProjectIdDashboardsArgs, options?: GetApiRestApiV1ProjectsProjectIdDashboardsOptions) => { 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 (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/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(dashboardStorageDTO, await res.json()) };