plugin-elastic-report 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/elastic-report/SKILLS.md +32 -0
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/851.488fdbf5bc5b6a36.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +20 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +99 -0
- package/dist/locale/vi-VN.json +99 -0
- package/dist/locale/zh-CN.json +99 -0
- package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
- package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
- package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
- package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
- package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
- package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
- package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
- package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
- package/dist/server/acl-guard.js +107 -0
- package/dist/server/collections/es-report-data-views.js +79 -0
- package/dist/server/collections/es-reports.js +95 -0
- package/dist/server/index.js +58 -0
- package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +417 -0
- package/dist/server/plugin.js +395 -0
- package/dist/server/services/ElasticReportService.js +263 -0
- package/dist/server/services/ElasticsearchConnectionService.js +332 -0
- package/dist/server/services/ReportQueryCompiler.js +858 -0
- package/dist/shared/constants.js +81 -0
- package/dist/shared/types.js +24 -0
- package/package.json +61 -4
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/index.tsx +19 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +311 -0
- package/src/client-v2/api.ts +224 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +399 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +160 -0
- package/src/client-v2/components/ElasticReportRenderer.tsx +707 -0
- package/src/client-v2/components/HighlightText.tsx +50 -0
- package/src/client-v2/components/ReportSelect.tsx +72 -0
- package/src/client-v2/index.tsx +14 -0
- package/src/client-v2/locale.ts +23 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +85 -0
- package/src/client-v2/pages/ElasticReportManager.tsx +1047 -0
- package/src/client-v2/plugin.tsx +52 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +99 -0
- package/src/locale/vi-VN.json +99 -0
- package/src/locale/zh-CN.json +99 -0
- package/src/server/__tests__/query-compiler.test.ts +231 -0
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +377 -0
- package/src/server/acl-guard.ts +103 -0
- package/src/server/collections/es-report-data-views.ts +58 -0
- package/src/server/collections/es-reports.ts +74 -0
- package/src/server/index.ts +15 -0
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
- package/src/server/mcp/ElasticReportToolCatalog.ts +417 -0
- package/src/server/plugin.ts +431 -0
- package/src/server/services/ElasticReportService.ts +326 -0
- package/src/server/services/ElasticsearchConnectionService.ts +401 -0
- package/src/server/services/ReportQueryCompiler.ts +1017 -0
- package/src/shared/constants.ts +29 -0
- package/src/shared/types.ts +175 -0
- package/README.md +0 -3
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createServer, type IncomingMessage, type Server } from 'http';
|
|
11
|
+
import type { AddressInfo } from 'net';
|
|
12
|
+
import { createMockServer, type MockServer } from '@nocobase/test';
|
|
13
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
14
|
+
import PluginDataSourceElasticsearch from '../../../../plugin-data-source-elasticsearch/src/server/plugin';
|
|
15
|
+
import PluginElasticReportServer from '../plugin';
|
|
16
|
+
|
|
17
|
+
function readBody(req: IncomingMessage): Promise<string> {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const chunks: Buffer[] = [];
|
|
20
|
+
req.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
21
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('plugin-elastic-report REST, DataSource reuse, ACL, and MCP integration', () => {
|
|
26
|
+
let app: MockServer;
|
|
27
|
+
let upstream: Server;
|
|
28
|
+
let esUrl = '';
|
|
29
|
+
let viewerAgent: ReturnType<MockServer['agent']>;
|
|
30
|
+
let builderAgent: ReturnType<MockServer['agent']>;
|
|
31
|
+
const capturedSearchBodies: Array<Record<string, unknown>> = [];
|
|
32
|
+
|
|
33
|
+
beforeAll(async () => {
|
|
34
|
+
upstream = createServer(async (req, res) => {
|
|
35
|
+
const url = req.url || '/';
|
|
36
|
+
const rawBody = await readBody(req);
|
|
37
|
+
res.setHeader('x-elastic-product', 'Elasticsearch');
|
|
38
|
+
res.setHeader('content-type', 'application/json');
|
|
39
|
+
|
|
40
|
+
if (req.method === 'HEAD' || url === '/') {
|
|
41
|
+
res.statusCode = 200;
|
|
42
|
+
res.end(JSON.stringify({ name: 'mock-es', version: { number: '8.17.0' } }));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (url.includes('_cluster/health')) {
|
|
47
|
+
res.end(JSON.stringify({ cluster_name: 'test-es', status: 'green' }));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (url.includes('_cat/indices')) {
|
|
52
|
+
res.end(JSON.stringify([{ index: 'logs-2026.11.29' }, { index: 'logs-2026.11.30' }]));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (url.includes('_field_caps')) {
|
|
57
|
+
res.end(
|
|
58
|
+
JSON.stringify({
|
|
59
|
+
indices: ['logs-2026.11.29', 'logs-2026.11.30'],
|
|
60
|
+
fields: {
|
|
61
|
+
'@timestamp': {
|
|
62
|
+
date: { type: 'date', searchable: true, aggregatable: true },
|
|
63
|
+
},
|
|
64
|
+
service: {
|
|
65
|
+
text: { type: 'text', searchable: true, aggregatable: false },
|
|
66
|
+
},
|
|
67
|
+
'service.keyword': {
|
|
68
|
+
keyword: { type: 'keyword', searchable: true, aggregatable: true },
|
|
69
|
+
},
|
|
70
|
+
status: {
|
|
71
|
+
integer: { type: 'integer', searchable: true, aggregatable: true },
|
|
72
|
+
},
|
|
73
|
+
latency_ms: {
|
|
74
|
+
double: { type: 'double', searchable: true, aggregatable: true },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (url.includes('_mapping')) {
|
|
83
|
+
res.end(
|
|
84
|
+
JSON.stringify({
|
|
85
|
+
'logs-2026.11.30': {
|
|
86
|
+
mappings: {
|
|
87
|
+
properties: {
|
|
88
|
+
'@timestamp': { type: 'date' },
|
|
89
|
+
service: { type: 'text', fields: { keyword: { type: 'keyword' } } },
|
|
90
|
+
status: { type: 'integer' },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (url.includes('_search')) {
|
|
100
|
+
const parsedBody = rawBody ? (JSON.parse(rawBody) as Record<string, unknown>) : {};
|
|
101
|
+
capturedSearchBodies.push(parsedBody);
|
|
102
|
+
res.end(
|
|
103
|
+
JSON.stringify({
|
|
104
|
+
took: 5,
|
|
105
|
+
hits: {
|
|
106
|
+
total: { value: 2, relation: 'eq' },
|
|
107
|
+
hits: [
|
|
108
|
+
{
|
|
109
|
+
_index: 'logs-2026.11.30',
|
|
110
|
+
_id: 'hit-1',
|
|
111
|
+
sort: [1732920000000],
|
|
112
|
+
_source: {
|
|
113
|
+
'@timestamp': '2026-11-30T01:00:00Z',
|
|
114
|
+
service: 'checkout',
|
|
115
|
+
status: 502,
|
|
116
|
+
latency_ms: 340,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
_index: 'logs-2026.11.30',
|
|
121
|
+
_id: 'hit-2',
|
|
122
|
+
sort: [1732910000000],
|
|
123
|
+
_source: {
|
|
124
|
+
'@timestamp': '2026-11-30T00:50:00Z',
|
|
125
|
+
service: 'checkout',
|
|
126
|
+
status: 500,
|
|
127
|
+
latency_ms: 210,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
aggregations: {
|
|
133
|
+
es_time_histogram: {
|
|
134
|
+
buckets: [{ key_as_string: '2026-11-30T00:00:00Z', key: 1732910000000, doc_count: 2 }],
|
|
135
|
+
},
|
|
136
|
+
es_buckets: {
|
|
137
|
+
buckets: [{ key: 'checkout', doc_count: 2, es_metric: { value: 275 } }],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
res.end(JSON.stringify({}));
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
await new Promise<void>((resolve) => upstream.listen(0, '127.0.0.1', resolve));
|
|
149
|
+
esUrl = `http://127.0.0.1:${(upstream.address() as AddressInfo).port}`;
|
|
150
|
+
|
|
151
|
+
app = await createMockServer({
|
|
152
|
+
acl: true,
|
|
153
|
+
resourcer: {
|
|
154
|
+
prefix: '/api',
|
|
155
|
+
},
|
|
156
|
+
plugins: [
|
|
157
|
+
'field-sort',
|
|
158
|
+
'system-settings',
|
|
159
|
+
'users',
|
|
160
|
+
'auth',
|
|
161
|
+
'acl',
|
|
162
|
+
'data-source-manager',
|
|
163
|
+
'data-source-main',
|
|
164
|
+
'error-handler',
|
|
165
|
+
[PluginDataSourceElasticsearch, { name: 'plugin-data-source-elasticsearch' }],
|
|
166
|
+
[PluginElasticReportServer, { name: 'plugin-elastic-report' }],
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Register an Elasticsearch data source record as plugin-data-source-elasticsearch does
|
|
171
|
+
await app.db.getRepository('dataSources').create({
|
|
172
|
+
values: {
|
|
173
|
+
key: 'es_logs_cluster',
|
|
174
|
+
displayName: 'ES Logs Cluster',
|
|
175
|
+
type: 'elasticsearch',
|
|
176
|
+
enabled: true,
|
|
177
|
+
options: {
|
|
178
|
+
nodes: esUrl,
|
|
179
|
+
indexPattern: 'logs-*',
|
|
180
|
+
addAllCollections: false,
|
|
181
|
+
selectedCollections: [],
|
|
182
|
+
password: 'super-secret-password',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
for (const roleName of ['report-viewer', 'report-builder']) {
|
|
188
|
+
await app.db.getRepository('roles').create({
|
|
189
|
+
values: {
|
|
190
|
+
name: roleName,
|
|
191
|
+
title: roleName,
|
|
192
|
+
snippets: roleName === 'report-builder' ? ['pm.elastic-report'] : [],
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
const user = await app.db.getRepository('users').create({
|
|
196
|
+
values: { username: roleName, roles: [roleName] },
|
|
197
|
+
});
|
|
198
|
+
const agent = await app.agent().login(user, roleName);
|
|
199
|
+
if (roleName === 'report-viewer') viewerAgent = agent;
|
|
200
|
+
else builderAgent = agent;
|
|
201
|
+
}
|
|
202
|
+
app.acl.getRole('report-builder').snippets.add('pm.elastic-report');
|
|
203
|
+
}, 120000);
|
|
204
|
+
|
|
205
|
+
afterAll(async () => {
|
|
206
|
+
await app?.destroy();
|
|
207
|
+
if (upstream) {
|
|
208
|
+
await new Promise<void>((resolve) => upstream.close(() => resolve()));
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('blocks unprivileged viewers from managing connections or saving reports while never leaking ES secrets', async () => {
|
|
213
|
+
const deniedConn = await viewerAgent.resource('esReportService').listConnections();
|
|
214
|
+
expect(deniedConn.status).toBe(403);
|
|
215
|
+
|
|
216
|
+
const allowedConn = await builderAgent.resource('esReportService').listConnections();
|
|
217
|
+
expect(allowedConn.status).toBe(200);
|
|
218
|
+
expect(allowedConn.body.data).toEqual([
|
|
219
|
+
expect.objectContaining({
|
|
220
|
+
key: 'es_logs_cluster',
|
|
221
|
+
displayName: 'ES Logs Cluster',
|
|
222
|
+
}),
|
|
223
|
+
]);
|
|
224
|
+
expect(JSON.stringify(allowedConn.body)).not.toContain('super-secret-password');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('supports full AI Employee MCP workflow over /api/elastic-report-mcp and enforces viewer/builder ACL', async () => {
|
|
228
|
+
// 1. Unauthenticated request to MCP endpoint is rejected
|
|
229
|
+
const anonRes = await app
|
|
230
|
+
.agent()
|
|
231
|
+
.post('/api/elastic-report-mcp')
|
|
232
|
+
.send({ jsonrpc: '2.0', id: 1, method: 'initialize', params: {} });
|
|
233
|
+
expect([401, 403]).toContain(anonRes.status);
|
|
234
|
+
|
|
235
|
+
// 2. Initialize & list tools as report-builder
|
|
236
|
+
const initRes = await builderAgent
|
|
237
|
+
.post('/api/elastic-report-mcp')
|
|
238
|
+
.send({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-03-26' } });
|
|
239
|
+
expect(initRes.status).toBe(200);
|
|
240
|
+
expect(initRes.body.result.serverInfo.name).toBe('elastic-report');
|
|
241
|
+
|
|
242
|
+
const listToolsRes = await builderAgent
|
|
243
|
+
.post('/api/elastic-report-mcp')
|
|
244
|
+
.send({ jsonrpc: '2.0', id: 2, method: 'tools/list' });
|
|
245
|
+
expect(listToolsRes.status).toBe(200);
|
|
246
|
+
const toolNames = (listToolsRes.body.result.tools as Array<{ name: string }>).map((t) => t.name);
|
|
247
|
+
expect(toolNames).toEqual(
|
|
248
|
+
expect.arrayContaining([
|
|
249
|
+
'es_list_connections',
|
|
250
|
+
'es_upsert_data_view',
|
|
251
|
+
'es_inspect_fields',
|
|
252
|
+
'es_preview_report',
|
|
253
|
+
'es_save_report',
|
|
254
|
+
'es_list_reports',
|
|
255
|
+
]),
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
// 3. Viewer cannot invoke write MCP tool `es_upsert_data_view`
|
|
259
|
+
const viewerWriteMcp = await viewerAgent.post('/api/elastic-report-mcp').send({
|
|
260
|
+
jsonrpc: '2.0',
|
|
261
|
+
id: 3,
|
|
262
|
+
method: 'tools/call',
|
|
263
|
+
params: {
|
|
264
|
+
name: 'es_upsert_data_view',
|
|
265
|
+
arguments: {
|
|
266
|
+
title: 'Unauthorized DV',
|
|
267
|
+
dataSourceKey: 'es_logs_cluster',
|
|
268
|
+
indexPattern: 'logs-*',
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
expect(viewerWriteMcp.status).toBe(200);
|
|
273
|
+
expect(viewerWriteMcp.body.result.isError).toBe(true);
|
|
274
|
+
expect(viewerWriteMcp.body.result.content[0].text).toContain('403');
|
|
275
|
+
|
|
276
|
+
// 4. Builder creates Data View via MCP -> auto-detects @timestamp via _field_caps
|
|
277
|
+
const createDvMcp = await builderAgent.post('/api/elastic-report-mcp').send({
|
|
278
|
+
jsonrpc: '2.0',
|
|
279
|
+
id: 4,
|
|
280
|
+
method: 'tools/call',
|
|
281
|
+
params: {
|
|
282
|
+
name: 'es_upsert_data_view',
|
|
283
|
+
arguments: {
|
|
284
|
+
title: 'Production Logs',
|
|
285
|
+
dataSourceKey: 'es_logs_cluster',
|
|
286
|
+
indexPattern: 'logs-*',
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
expect(createDvMcp.body.result.isError).toBe(false);
|
|
291
|
+
const dvPayload = JSON.parse(createDvMcp.body.result.content[0].text) as {
|
|
292
|
+
dataView: { id: number; timeField: string };
|
|
293
|
+
fieldCount: number;
|
|
294
|
+
};
|
|
295
|
+
expect(dvPayload.dataView.timeField).toBe('@timestamp');
|
|
296
|
+
expect(dvPayload.fieldCount).toBe(5);
|
|
297
|
+
|
|
298
|
+
// 5. Builder previews and saves a Kibana Table Report via MCP
|
|
299
|
+
const previewMcp = await builderAgent.post('/api/elastic-report-mcp').send({
|
|
300
|
+
jsonrpc: '2.0',
|
|
301
|
+
id: 5,
|
|
302
|
+
method: 'tools/call',
|
|
303
|
+
params: {
|
|
304
|
+
name: 'es_preview_report',
|
|
305
|
+
arguments: {
|
|
306
|
+
dataViewId: dvPayload.dataView.id,
|
|
307
|
+
spec: {
|
|
308
|
+
visualization: 'table',
|
|
309
|
+
query: 'status >= 500 AND service: "checkout"',
|
|
310
|
+
sort: [{ field: 'service', order: 'asc' }],
|
|
311
|
+
timeRange: { preset: 'last_24h' },
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
expect(previewMcp.body.result.isError).toBe(false);
|
|
317
|
+
const previewData = JSON.parse(previewMcp.body.result.content[0].text) as { total: number };
|
|
318
|
+
expect(previewData.total).toBe(2);
|
|
319
|
+
|
|
320
|
+
const saveMcp = await builderAgent.post('/api/elastic-report-mcp').send({
|
|
321
|
+
jsonrpc: '2.0',
|
|
322
|
+
id: 6,
|
|
323
|
+
method: 'tools/call',
|
|
324
|
+
params: {
|
|
325
|
+
name: 'es_save_report',
|
|
326
|
+
arguments: {
|
|
327
|
+
title: 'Checkout 5xx Errors',
|
|
328
|
+
dataViewId: dvPayload.dataView.id,
|
|
329
|
+
published: true,
|
|
330
|
+
spec: {
|
|
331
|
+
visualization: 'table',
|
|
332
|
+
query: 'status >= 500',
|
|
333
|
+
filters: [{ field: 'service', operator: 'eq', value: 'checkout' }],
|
|
334
|
+
sort: [{ field: '@timestamp', order: 'desc' }],
|
|
335
|
+
timeRange: { preset: 'last_24h' },
|
|
336
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
expect(saveMcp.body.result.isError).toBe(false);
|
|
342
|
+
const savedReportPayload = JSON.parse(saveMcp.body.result.content[0].text) as {
|
|
343
|
+
report: { id: number; title: string };
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// 6. Regular page viewer can list published reports (for ReportSelect), fetch GET getReportMeta?reportId=..., and execute the saved report with interactive overrides!
|
|
347
|
+
const publishedList = await viewerAgent.get('/api/esReportService:listPublishedReports?search=Checkout');
|
|
348
|
+
expect(publishedList.status).toBe(200);
|
|
349
|
+
expect(publishedList.body.data).toEqual([
|
|
350
|
+
expect.objectContaining({
|
|
351
|
+
id: savedReportPayload.report.id,
|
|
352
|
+
title: 'Checkout 5xx Errors',
|
|
353
|
+
}),
|
|
354
|
+
]);
|
|
355
|
+
|
|
356
|
+
const metaRes = await viewerAgent.get(
|
|
357
|
+
`/api/esReportService:getReportMeta?reportId=${savedReportPayload.report.id}`,
|
|
358
|
+
);
|
|
359
|
+
expect(metaRes.status).toBe(200);
|
|
360
|
+
expect(metaRes.body.data.report.title).toBe('Checkout 5xx Errors');
|
|
361
|
+
expect(metaRes.body.data.fields.length).toBeGreaterThan(0);
|
|
362
|
+
|
|
363
|
+
const runRes = await viewerAgent.resource('esReportService').runReport({
|
|
364
|
+
values: {
|
|
365
|
+
reportId: savedReportPayload.report.id,
|
|
366
|
+
overrides: {
|
|
367
|
+
query: 'status >= 502',
|
|
368
|
+
page: 1,
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
expect(runRes.status).toBe(200);
|
|
373
|
+
expect(runRes.body.data.result.total).toBe(2);
|
|
374
|
+
expect(runRes.body.data.result.rows[0].source.service).toBe('checkout');
|
|
375
|
+
expect(capturedSearchBodies.length).toBeGreaterThanOrEqual(2);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@nocobase/actions';
|
|
11
|
+
import type { Application } from '@nocobase/server';
|
|
12
|
+
import { REPORTS_COLLECTION, SERVICE_RESOURCE } from '../shared/constants';
|
|
13
|
+
import { extractCurrentUserId } from './services/ElasticReportService';
|
|
14
|
+
|
|
15
|
+
function getCurrentRoles(ctx?: Partial<Context>): string[] {
|
|
16
|
+
const roles = new Set<string>();
|
|
17
|
+
const state = ctx?.state as
|
|
18
|
+
| {
|
|
19
|
+
currentRole?: unknown;
|
|
20
|
+
currentRoles?: unknown;
|
|
21
|
+
currentUser?: { roles?: Array<{ name?: string } | string> };
|
|
22
|
+
}
|
|
23
|
+
| undefined;
|
|
24
|
+
|
|
25
|
+
if (typeof state?.currentRole === 'string' && state.currentRole.trim()) {
|
|
26
|
+
roles.add(state.currentRole.trim());
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(state?.currentRoles)) {
|
|
29
|
+
for (const r of state.currentRoles) {
|
|
30
|
+
if (typeof r === 'string' && r.trim()) roles.add(r.trim());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const headerRole = ctx?.request?.headers?.['x-role'];
|
|
34
|
+
if (typeof headerRole === 'string' && headerRole.trim()) {
|
|
35
|
+
roles.add(headerRole.trim());
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(state?.currentUser?.roles)) {
|
|
38
|
+
for (const r of state.currentUser.roles) {
|
|
39
|
+
if (typeof r === 'string' && r.trim()) roles.add(r.trim());
|
|
40
|
+
else if (r && typeof r === 'object' && typeof r.name === 'string' && r.name.trim()) {
|
|
41
|
+
roles.add(r.name.trim());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return Array.from(roles);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function assertAuthenticated(ctx?: Partial<Context>): void {
|
|
49
|
+
const userId = extractCurrentUserId(ctx);
|
|
50
|
+
if (userId === undefined || userId === null || String(userId).trim() === '') {
|
|
51
|
+
const err = new Error('Authentication required') as Error & { status?: number };
|
|
52
|
+
err.status = 401;
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function canManageReports(app: Application, ctx?: Partial<Context>): boolean {
|
|
58
|
+
const userId = extractCurrentUserId(ctx);
|
|
59
|
+
if (userId === undefined || userId === null) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const roles = getCurrentRoles(ctx);
|
|
64
|
+
if (roles.includes('root') || roles.includes('admin')) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (roles.length === 0) {
|
|
69
|
+
// When invoked from an internal authenticated session that has not narrowed `x-role`,
|
|
70
|
+
// defer to whether `acl` explicitly restricts `saveReport`.
|
|
71
|
+
const aclLike = app.acl as unknown as {
|
|
72
|
+
can?: (opts: { role: string; resource: string; action: string }) => unknown;
|
|
73
|
+
};
|
|
74
|
+
if (typeof aclLike?.can !== 'function') {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return Boolean(aclLike.can({ role: 'member', resource: SERVICE_RESOURCE, action: 'saveReport' }));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const aclLike = app.acl as unknown as {
|
|
81
|
+
can?: (opts: { role: string; resource: string; action: string }) => unknown;
|
|
82
|
+
};
|
|
83
|
+
if (typeof aclLike?.can !== 'function') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return roles.some(
|
|
88
|
+
(role) =>
|
|
89
|
+
Boolean(aclLike.can({ role, resource: SERVICE_RESOURCE, action: 'saveReport' })) ||
|
|
90
|
+
Boolean(aclLike.can({ role, resource: REPORTS_COLLECTION, action: 'create' })),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function assertCanManageReports(app: Application, ctx?: Partial<Context>): void {
|
|
95
|
+
assertAuthenticated(ctx);
|
|
96
|
+
if (!canManageReports(app, ctx)) {
|
|
97
|
+
const err = new Error('Permission denied: Elastic Report management access is required') as Error & {
|
|
98
|
+
status?: number;
|
|
99
|
+
};
|
|
100
|
+
err.status = 403;
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { defineCollection } from '@nocobase/database';
|
|
11
|
+
import { DATA_VIEWS_COLLECTION } from '../../shared/constants';
|
|
12
|
+
|
|
13
|
+
export default defineCollection({
|
|
14
|
+
name: DATA_VIEWS_COLLECTION,
|
|
15
|
+
title: 'Elasticsearch Report Data Views',
|
|
16
|
+
filterTargetKey: 'id',
|
|
17
|
+
autoGenId: true,
|
|
18
|
+
timestamps: true,
|
|
19
|
+
fields: [
|
|
20
|
+
{
|
|
21
|
+
type: 'string',
|
|
22
|
+
name: 'title',
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'string',
|
|
27
|
+
name: 'dataSourceKey',
|
|
28
|
+
allowNull: false,
|
|
29
|
+
index: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: 'string',
|
|
33
|
+
name: 'indexPattern',
|
|
34
|
+
allowNull: false,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'string',
|
|
38
|
+
name: 'timeField',
|
|
39
|
+
allowNull: true,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
name: 'description',
|
|
44
|
+
allowNull: true,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'json',
|
|
48
|
+
name: 'cachedFields',
|
|
49
|
+
allowNull: true,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'context',
|
|
53
|
+
name: 'createdById',
|
|
54
|
+
dataIndex: 'state.currentUser.id',
|
|
55
|
+
createOnly: true,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { defineCollection } from '@nocobase/database';
|
|
11
|
+
import { DATA_VIEWS_COLLECTION, REPORTS_COLLECTION } from '../../shared/constants';
|
|
12
|
+
|
|
13
|
+
export default defineCollection({
|
|
14
|
+
name: REPORTS_COLLECTION,
|
|
15
|
+
title: 'Elasticsearch Reports',
|
|
16
|
+
filterTargetKey: 'id',
|
|
17
|
+
autoGenId: true,
|
|
18
|
+
timestamps: true,
|
|
19
|
+
fields: [
|
|
20
|
+
{
|
|
21
|
+
type: 'string',
|
|
22
|
+
name: 'title',
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
name: 'description',
|
|
28
|
+
allowNull: true,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: 'bigInt',
|
|
32
|
+
name: 'dataViewId',
|
|
33
|
+
allowNull: false,
|
|
34
|
+
index: true,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'belongsTo',
|
|
38
|
+
name: 'dataView',
|
|
39
|
+
target: DATA_VIEWS_COLLECTION,
|
|
40
|
+
foreignKey: 'dataViewId',
|
|
41
|
+
targetKey: 'id',
|
|
42
|
+
constraints: false,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'string',
|
|
46
|
+
name: 'visualization',
|
|
47
|
+
allowNull: false,
|
|
48
|
+
defaultValue: 'table',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'json',
|
|
52
|
+
name: 'spec',
|
|
53
|
+
allowNull: false,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'boolean',
|
|
57
|
+
name: 'published',
|
|
58
|
+
allowNull: false,
|
|
59
|
+
defaultValue: true,
|
|
60
|
+
index: true,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'context',
|
|
64
|
+
name: 'createdById',
|
|
65
|
+
dataIndex: 'state.currentUser.id',
|
|
66
|
+
createOnly: true,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'context',
|
|
70
|
+
name: 'updatedById',
|
|
71
|
+
dataIndex: 'state.currentUser.id',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { PluginElasticReportServer, default } from './plugin';
|
|
11
|
+
export * from './services/ReportQueryCompiler';
|
|
12
|
+
export * from './services/ElasticsearchConnectionService';
|
|
13
|
+
export * from './services/ElasticReportService';
|
|
14
|
+
export * from './mcp/ElasticReportMcpServer';
|
|
15
|
+
export * from './mcp/ElasticReportToolCatalog';
|