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,395 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var plugin_exports = {};
|
|
28
|
+
__export(plugin_exports, {
|
|
29
|
+
PluginElasticReportServer: () => PluginElasticReportServer,
|
|
30
|
+
default: () => plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
33
|
+
var import_path = require("path");
|
|
34
|
+
var import_server = require("@nocobase/server");
|
|
35
|
+
var import_constants = require("../shared/constants");
|
|
36
|
+
var import_acl_guard = require("./acl-guard");
|
|
37
|
+
var import_ElasticReportMcpServer = require("./mcp/ElasticReportMcpServer");
|
|
38
|
+
var import_ElasticReportToolCatalog = require("./mcp/ElasticReportToolCatalog");
|
|
39
|
+
var import_ElasticsearchConnectionService = require("./services/ElasticsearchConnectionService");
|
|
40
|
+
var import_ElasticReportService = require("./services/ElasticReportService");
|
|
41
|
+
function isRecord(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
function getActionPayload(ctx) {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
const query = isRecord((_a = ctx.request) == null ? void 0 : _a.query) ? ctx.request.query : {};
|
|
47
|
+
const actionParams = isRecord((_b = ctx.action) == null ? void 0 : _b.params) ? ctx.action.params : {};
|
|
48
|
+
const body = isRecord((_c = ctx.request) == null ? void 0 : _c.body) ? ctx.request.body : {};
|
|
49
|
+
const paramValues = isRecord(actionParams.values) ? actionParams.values : {};
|
|
50
|
+
return {
|
|
51
|
+
...query,
|
|
52
|
+
...actionParams,
|
|
53
|
+
...body,
|
|
54
|
+
...paramValues
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function parseIdParam(value, label) {
|
|
58
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
59
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
60
|
+
const err = new Error(`${label} is required`);
|
|
61
|
+
err.status = 400;
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
class PluginElasticReportServer extends import_server.Plugin {
|
|
65
|
+
connectionService;
|
|
66
|
+
reportService;
|
|
67
|
+
mcpServer;
|
|
68
|
+
toolsCatalog = [];
|
|
69
|
+
schemaCollections = [import_constants.DATA_VIEWS_COLLECTION, import_constants.REPORTS_COLLECTION];
|
|
70
|
+
async beforeLoad() {
|
|
71
|
+
var _a;
|
|
72
|
+
await this.db.import({
|
|
73
|
+
directory: (0, import_path.resolve)(__dirname, "collections")
|
|
74
|
+
});
|
|
75
|
+
this.connectionService = new import_ElasticsearchConnectionService.ElasticsearchConnectionService(this.app);
|
|
76
|
+
this.reportService = new import_ElasticReportService.ElasticReportService(this.app, this.connectionService);
|
|
77
|
+
this.toolsCatalog = (0, import_ElasticReportToolCatalog.createElasticReportToolCatalog)(this.app, this.reportService);
|
|
78
|
+
this.mcpServer = new import_ElasticReportMcpServer.ElasticReportMcpServer({
|
|
79
|
+
version: ((_a = this.options) == null ? void 0 : _a.version) || "0.1.0",
|
|
80
|
+
tools: this.toolsCatalog,
|
|
81
|
+
logger: this.app.logger
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async load() {
|
|
85
|
+
this.registerServiceResource();
|
|
86
|
+
this.registerMcpEndpoint();
|
|
87
|
+
this.registerAclRules();
|
|
88
|
+
this.registerAITools();
|
|
89
|
+
await this.registerPluginMcpClientEntry();
|
|
90
|
+
this.app.on("beforeStop", async () => {
|
|
91
|
+
var _a;
|
|
92
|
+
await ((_a = this.connectionService) == null ? void 0 : _a.close());
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async install(_options) {
|
|
96
|
+
await this.ensureSchema();
|
|
97
|
+
}
|
|
98
|
+
async upgrade() {
|
|
99
|
+
await this.ensureSchema();
|
|
100
|
+
}
|
|
101
|
+
getApiBasePath() {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
const rawPrefix = ((_b = (_a = this.app.resourcer) == null ? void 0 : _a.options) == null ? void 0 : _b.prefix) ?? process.env.API_BASE_PATH ?? "/api";
|
|
104
|
+
const cleaned = rawPrefix.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
105
|
+
return cleaned;
|
|
106
|
+
}
|
|
107
|
+
getMcpEndpointPath() {
|
|
108
|
+
return `${this.getApiBasePath()}${import_constants.MCP_RELATIVE_PATH}`;
|
|
109
|
+
}
|
|
110
|
+
resolveInternalMcpUrl() {
|
|
111
|
+
const port = process.env.APP_PORT || "13000";
|
|
112
|
+
const host = process.env.ELASTIC_REPORT_MCP_INTERNAL_HOST || `http://127.0.0.1:${port}`;
|
|
113
|
+
return `${host.replace(/\/$/, "")}${this.getMcpEndpointPath()}`;
|
|
114
|
+
}
|
|
115
|
+
registerServiceResource() {
|
|
116
|
+
this.app.resourceManager.define({
|
|
117
|
+
name: import_constants.SERVICE_RESOURCE,
|
|
118
|
+
actions: {
|
|
119
|
+
listConnections: async (ctx, next) => {
|
|
120
|
+
ctx.body = await this.reportService.listConnections();
|
|
121
|
+
await next();
|
|
122
|
+
},
|
|
123
|
+
listIndices: async (ctx, next) => {
|
|
124
|
+
const payload = getActionPayload(ctx);
|
|
125
|
+
const dataSourceKey = typeof payload.dataSourceKey === "string" ? payload.dataSourceKey.trim() : "";
|
|
126
|
+
if (!dataSourceKey) {
|
|
127
|
+
ctx.throw(400, "dataSourceKey is required");
|
|
128
|
+
}
|
|
129
|
+
const indexPattern = typeof payload.indexPattern === "string" && payload.indexPattern.trim() ? payload.indexPattern.trim() : "*";
|
|
130
|
+
try {
|
|
131
|
+
ctx.body = await this.reportService.listIndices(dataSourceKey, indexPattern);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
ctx.throw(400, error instanceof Error ? error.message : String(error));
|
|
134
|
+
}
|
|
135
|
+
await next();
|
|
136
|
+
},
|
|
137
|
+
inspectFields: async (ctx, next) => {
|
|
138
|
+
const payload = getActionPayload(ctx);
|
|
139
|
+
try {
|
|
140
|
+
if (payload.dataViewId !== void 0 && payload.dataViewId !== null && String(payload.dataViewId).trim()) {
|
|
141
|
+
const refresh = payload.refresh === true || payload.refresh === "true";
|
|
142
|
+
ctx.body = await this.reportService.inspectDataViewFields(
|
|
143
|
+
parseIdParam(payload.dataViewId, "dataViewId"),
|
|
144
|
+
refresh
|
|
145
|
+
);
|
|
146
|
+
} else {
|
|
147
|
+
const dataSourceKey = typeof payload.dataSourceKey === "string" ? payload.dataSourceKey.trim() : "";
|
|
148
|
+
const indexPattern = typeof payload.indexPattern === "string" ? payload.indexPattern.trim() : "";
|
|
149
|
+
if (!dataSourceKey || !indexPattern) {
|
|
150
|
+
ctx.throw(400, "Either dataViewId or (dataSourceKey + indexPattern) is required");
|
|
151
|
+
}
|
|
152
|
+
const fields = await this.reportService.inspectFieldsBySource(dataSourceKey, indexPattern);
|
|
153
|
+
ctx.body = { fields };
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
157
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
158
|
+
}
|
|
159
|
+
await next();
|
|
160
|
+
},
|
|
161
|
+
upsertDataView: async (ctx, next) => {
|
|
162
|
+
const payload = getActionPayload(ctx);
|
|
163
|
+
try {
|
|
164
|
+
ctx.body = await this.reportService.upsertDataView(
|
|
165
|
+
{
|
|
166
|
+
...payload.id !== void 0 && payload.id !== null && String(payload.id).trim() !== "" ? { id: parseIdParam(payload.id, "id") } : {},
|
|
167
|
+
title: typeof payload.title === "string" ? payload.title : "",
|
|
168
|
+
dataSourceKey: typeof payload.dataSourceKey === "string" ? payload.dataSourceKey : "",
|
|
169
|
+
indexPattern: typeof payload.indexPattern === "string" ? payload.indexPattern : "",
|
|
170
|
+
timeField: typeof payload.timeField === "string" ? payload.timeField : null,
|
|
171
|
+
description: typeof payload.description === "string" ? payload.description : null
|
|
172
|
+
},
|
|
173
|
+
(0, import_ElasticReportService.extractCurrentUserId)(ctx)
|
|
174
|
+
);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
ctx.throw(400, error instanceof Error ? error.message : String(error));
|
|
177
|
+
}
|
|
178
|
+
await next();
|
|
179
|
+
},
|
|
180
|
+
previewReport: async (ctx, next) => {
|
|
181
|
+
const payload = getActionPayload(ctx);
|
|
182
|
+
try {
|
|
183
|
+
const dataViewId = parseIdParam(payload.dataViewId, "dataViewId");
|
|
184
|
+
ctx.body = await this.reportService.previewReport({
|
|
185
|
+
dataViewId,
|
|
186
|
+
spec: payload.spec,
|
|
187
|
+
overrides: isRecord(payload.overrides) ? payload.overrides : void 0
|
|
188
|
+
});
|
|
189
|
+
} catch (error) {
|
|
190
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
191
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
192
|
+
}
|
|
193
|
+
await next();
|
|
194
|
+
},
|
|
195
|
+
saveReport: async (ctx, next) => {
|
|
196
|
+
const payload = getActionPayload(ctx);
|
|
197
|
+
try {
|
|
198
|
+
ctx.body = await this.reportService.saveReport(
|
|
199
|
+
{
|
|
200
|
+
...payload.id !== void 0 && payload.id !== null && String(payload.id).trim() !== "" ? { id: parseIdParam(payload.id, "id") } : {},
|
|
201
|
+
title: typeof payload.title === "string" ? payload.title : "",
|
|
202
|
+
description: typeof payload.description === "string" ? payload.description : null,
|
|
203
|
+
dataViewId: parseIdParam(payload.dataViewId, "dataViewId"),
|
|
204
|
+
spec: payload.spec,
|
|
205
|
+
published: payload.published !== false
|
|
206
|
+
},
|
|
207
|
+
(0, import_ElasticReportService.extractCurrentUserId)(ctx)
|
|
208
|
+
);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
ctx.throw(400, error instanceof Error ? error.message : String(error));
|
|
211
|
+
}
|
|
212
|
+
await next();
|
|
213
|
+
},
|
|
214
|
+
listPublishedReports: async (ctx, next) => {
|
|
215
|
+
const payload = getActionPayload(ctx);
|
|
216
|
+
const search = typeof payload.search === "string" ? payload.search : void 0;
|
|
217
|
+
ctx.body = await this.reportService.listReports({
|
|
218
|
+
publishedOnly: true,
|
|
219
|
+
search
|
|
220
|
+
});
|
|
221
|
+
await next();
|
|
222
|
+
},
|
|
223
|
+
getReportMeta: async (ctx, next) => {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
const payload = getActionPayload(ctx);
|
|
226
|
+
const rawId = payload.reportId ?? ((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.filterByTk);
|
|
227
|
+
try {
|
|
228
|
+
const reportId = parseIdParam(rawId, "reportId");
|
|
229
|
+
const report = await this.reportService.getReport(reportId);
|
|
230
|
+
const isManager = (0, import_acl_guard.canManageReports)(this.app, ctx);
|
|
231
|
+
if (!isManager && !report.published) {
|
|
232
|
+
ctx.throw(404, "Report not found");
|
|
233
|
+
}
|
|
234
|
+
const { dataView, fields } = await this.reportService.inspectDataViewFields(report.dataViewId, false);
|
|
235
|
+
ctx.body = { report, dataView, fields };
|
|
236
|
+
} catch (error) {
|
|
237
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
238
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
239
|
+
}
|
|
240
|
+
await next();
|
|
241
|
+
},
|
|
242
|
+
runReport: async (ctx, next) => {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
const payload = getActionPayload(ctx);
|
|
245
|
+
const rawId = payload.reportId ?? ((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.filterByTk);
|
|
246
|
+
try {
|
|
247
|
+
const reportId = parseIdParam(rawId, "reportId");
|
|
248
|
+
const isManager = (0, import_acl_guard.canManageReports)(this.app, ctx);
|
|
249
|
+
ctx.body = await this.reportService.runSavedReport({
|
|
250
|
+
reportId,
|
|
251
|
+
overrides: isRecord(payload.overrides) ? payload.overrides : void 0,
|
|
252
|
+
requirePublished: !isManager
|
|
253
|
+
});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
256
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
257
|
+
}
|
|
258
|
+
await next();
|
|
259
|
+
},
|
|
260
|
+
getMcpInfo: async (ctx, next) => {
|
|
261
|
+
ctx.body = {
|
|
262
|
+
serverName: import_constants.MCP_SERVER_NAME,
|
|
263
|
+
endpointPath: this.getMcpEndpointPath(),
|
|
264
|
+
internalUrl: this.resolveInternalMcpUrl(),
|
|
265
|
+
useUserContext: true,
|
|
266
|
+
tools: this.mcpServer.getToolsMetadata()
|
|
267
|
+
};
|
|
268
|
+
await next();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
registerMcpEndpoint() {
|
|
274
|
+
const mcpActionHandler = async (ctx) => {
|
|
275
|
+
await this.mcpServer.handleRequest(ctx);
|
|
276
|
+
};
|
|
277
|
+
this.app.resourceManager.define({
|
|
278
|
+
name: import_constants.MCP_RESOURCE_NAME,
|
|
279
|
+
actions: {
|
|
280
|
+
list: mcpActionHandler,
|
|
281
|
+
create: mcpActionHandler
|
|
282
|
+
},
|
|
283
|
+
only: ["list", "create"]
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
registerAclRules() {
|
|
287
|
+
this.app.acl.allow(import_constants.SERVICE_RESOURCE, ["listPublishedReports", "getReportMeta", "runReport"], "loggedIn");
|
|
288
|
+
this.app.acl.allow(import_constants.MCP_RESOURCE_NAME, "*", "loggedIn");
|
|
289
|
+
this.app.acl.registerSnippet({
|
|
290
|
+
name: import_constants.ACL_SNIPPET,
|
|
291
|
+
actions: [
|
|
292
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:list`,
|
|
293
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:get`,
|
|
294
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:create`,
|
|
295
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:update`,
|
|
296
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:destroy`,
|
|
297
|
+
`${import_constants.REPORTS_COLLECTION}:list`,
|
|
298
|
+
`${import_constants.REPORTS_COLLECTION}:get`,
|
|
299
|
+
`${import_constants.REPORTS_COLLECTION}:create`,
|
|
300
|
+
`${import_constants.REPORTS_COLLECTION}:update`,
|
|
301
|
+
`${import_constants.REPORTS_COLLECTION}:destroy`,
|
|
302
|
+
`${import_constants.SERVICE_RESOURCE}:*`
|
|
303
|
+
]
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
registerAITools() {
|
|
307
|
+
var _a, _b, _c;
|
|
308
|
+
const toolsManager = (_a = this.app.aiManager) == null ? void 0 : _a.toolsManager;
|
|
309
|
+
if (!toolsManager) {
|
|
310
|
+
(_c = (_b = this.app.logger) == null ? void 0 : _b.info) == null ? void 0 : _c.call(
|
|
311
|
+
_b,
|
|
312
|
+
"[plugin-elastic-report] aiManager.toolsManager is not present; skipping direct AI tool registration"
|
|
313
|
+
);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
toolsManager.registerTools(
|
|
317
|
+
this.toolsCatalog.map((tool) => ({
|
|
318
|
+
scope: "CUSTOM",
|
|
319
|
+
defaultPermission: tool.defaultPermission,
|
|
320
|
+
execution: "backend",
|
|
321
|
+
introduction: {
|
|
322
|
+
title: tool.title,
|
|
323
|
+
about: tool.description
|
|
324
|
+
},
|
|
325
|
+
definition: {
|
|
326
|
+
name: `${import_constants.MCP_SERVER_NAME}-${tool.name}`,
|
|
327
|
+
description: tool.description,
|
|
328
|
+
schema: tool.inputSchema
|
|
329
|
+
},
|
|
330
|
+
invoke: async (ctx, args) => {
|
|
331
|
+
return tool.execute(isRecord(args) ? args : {}, ctx);
|
|
332
|
+
}
|
|
333
|
+
}))
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
async registerPluginMcpClientEntry() {
|
|
337
|
+
var _a, _b, _c;
|
|
338
|
+
const mcpManager = (_a = this.app.aiManager) == null ? void 0 : _a.mcpManager;
|
|
339
|
+
if (!mcpManager || typeof mcpManager.registerMCP !== "function") {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
await mcpManager.registerMCP({
|
|
344
|
+
[import_constants.MCP_SERVER_NAME]: {
|
|
345
|
+
title: "Elastic Report MCP",
|
|
346
|
+
description: "Dedicated MCP server for Kibana-style Elasticsearch reports and Data Views",
|
|
347
|
+
transport: "http",
|
|
348
|
+
url: this.resolveInternalMcpUrl(),
|
|
349
|
+
headers: {
|
|
350
|
+
Authorization: "Bearer {{ctx.request.token}}",
|
|
351
|
+
"X-Role": "{{ctx.request.headers.x-role}}"
|
|
352
|
+
},
|
|
353
|
+
useUserContext: true,
|
|
354
|
+
enabled: true
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
} catch (error) {
|
|
358
|
+
(_c = (_b = this.app.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[plugin-elastic-report] Could not pre-register MCP client entry:", error);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
async ensureCollectionSchema(collectionName) {
|
|
362
|
+
const collection = this.db.getCollection(collectionName);
|
|
363
|
+
if (!collection) return;
|
|
364
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
365
|
+
const tableName = collection.getTableNameWithSchema();
|
|
366
|
+
let columns = null;
|
|
367
|
+
try {
|
|
368
|
+
columns = await queryInterface.describeTable(tableName);
|
|
369
|
+
} catch {
|
|
370
|
+
await collection.model.sync();
|
|
371
|
+
columns = await queryInterface.describeTable(tableName);
|
|
372
|
+
}
|
|
373
|
+
const attributes = collection.model.rawAttributes;
|
|
374
|
+
for (const [attributeName, attribute] of Object.entries(attributes)) {
|
|
375
|
+
const columnName = attribute.field || attributeName;
|
|
376
|
+
if (columns && columnName in columns) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const columnDefinition = { ...attribute };
|
|
380
|
+
delete columnDefinition.Model;
|
|
381
|
+
delete columnDefinition.fieldName;
|
|
382
|
+
await queryInterface.addColumn(tableName, columnName, columnDefinition);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
async ensureSchema() {
|
|
386
|
+
for (const collectionName of this.schemaCollections) {
|
|
387
|
+
await this.ensureCollectionSchema(collectionName);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
var plugin_default = PluginElasticReportServer;
|
|
392
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
393
|
+
0 && (module.exports = {
|
|
394
|
+
PluginElasticReportServer
|
|
395
|
+
});
|
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var ElasticReportService_exports = {};
|
|
28
|
+
__export(ElasticReportService_exports, {
|
|
29
|
+
ElasticReportService: () => ElasticReportService,
|
|
30
|
+
extractCurrentUserId: () => extractCurrentUserId
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(ElasticReportService_exports);
|
|
33
|
+
var import_constants = require("../../shared/constants");
|
|
34
|
+
var import_ReportQueryCompiler = require("./ReportQueryCompiler");
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
function toPlainObject(modelOrRow) {
|
|
39
|
+
if (isRecord(modelOrRow) && typeof modelOrRow.toJSON === "function") {
|
|
40
|
+
const json = modelOrRow.toJSON();
|
|
41
|
+
return isRecord(json) ? json : {};
|
|
42
|
+
}
|
|
43
|
+
return isRecord(modelOrRow) ? modelOrRow : {};
|
|
44
|
+
}
|
|
45
|
+
function serializeDataView(row) {
|
|
46
|
+
const plain = toPlainObject(row);
|
|
47
|
+
return {
|
|
48
|
+
id: plain.id ?? "",
|
|
49
|
+
title: typeof plain.title === "string" ? plain.title : "",
|
|
50
|
+
dataSourceKey: typeof plain.dataSourceKey === "string" ? plain.dataSourceKey : "",
|
|
51
|
+
indexPattern: typeof plain.indexPattern === "string" ? plain.indexPattern : "",
|
|
52
|
+
timeField: typeof plain.timeField === "string" && plain.timeField.trim() ? plain.timeField.trim() : null,
|
|
53
|
+
description: typeof plain.description === "string" ? plain.description : null,
|
|
54
|
+
cachedFields: Array.isArray(plain.cachedFields) ? plain.cachedFields : null,
|
|
55
|
+
...typeof plain.createdAt === "string" ? { createdAt: plain.createdAt } : {},
|
|
56
|
+
...typeof plain.updatedAt === "string" ? { updatedAt: plain.updatedAt } : {}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function serializeReport(row) {
|
|
60
|
+
const plain = toPlainObject(row);
|
|
61
|
+
const spec = (0, import_ReportQueryCompiler.normalizeReportSpec)(plain.spec, plain.visualization);
|
|
62
|
+
return {
|
|
63
|
+
id: plain.id ?? "",
|
|
64
|
+
title: typeof plain.title === "string" ? plain.title : "",
|
|
65
|
+
description: typeof plain.description === "string" ? plain.description : null,
|
|
66
|
+
dataViewId: plain.dataViewId ?? "",
|
|
67
|
+
dataView: isRecord(plain.dataView) ? serializeDataView(plain.dataView) : null,
|
|
68
|
+
visualization: spec.visualization,
|
|
69
|
+
spec,
|
|
70
|
+
published: plain.published !== false,
|
|
71
|
+
...typeof plain.createdAt === "string" ? { createdAt: plain.createdAt } : {},
|
|
72
|
+
...typeof plain.updatedAt === "string" ? { updatedAt: plain.updatedAt } : {}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
class ElasticReportService {
|
|
76
|
+
constructor(app, connections) {
|
|
77
|
+
this.app = app;
|
|
78
|
+
this.connections = connections;
|
|
79
|
+
}
|
|
80
|
+
async listConnections() {
|
|
81
|
+
return this.connections.listConnections();
|
|
82
|
+
}
|
|
83
|
+
async listIndices(dataSourceKey, indexPattern = "*") {
|
|
84
|
+
const client = await this.connections.getClient(dataSourceKey);
|
|
85
|
+
return client.readIndices(indexPattern);
|
|
86
|
+
}
|
|
87
|
+
async listDataViews() {
|
|
88
|
+
const repo = this.app.db.getRepository(import_constants.DATA_VIEWS_COLLECTION);
|
|
89
|
+
const rows = await repo.find({ sort: ["-id"] });
|
|
90
|
+
return rows.map(serializeDataView);
|
|
91
|
+
}
|
|
92
|
+
async getDataView(dataViewId) {
|
|
93
|
+
const repo = this.app.db.getRepository(import_constants.DATA_VIEWS_COLLECTION);
|
|
94
|
+
const row = await repo.findOne({ filterByTk: dataViewId });
|
|
95
|
+
if (!row) {
|
|
96
|
+
throw new Error(`Data view "${String(dataViewId)}" was not found`);
|
|
97
|
+
}
|
|
98
|
+
return serializeDataView(row);
|
|
99
|
+
}
|
|
100
|
+
async inspectFieldsBySource(dataSourceKey, indexPattern) {
|
|
101
|
+
const client = await this.connections.getClient(dataSourceKey);
|
|
102
|
+
return client.inspectFields(indexPattern);
|
|
103
|
+
}
|
|
104
|
+
async inspectDataViewFields(dataViewId, refresh = false) {
|
|
105
|
+
const dataView = await this.getDataView(dataViewId);
|
|
106
|
+
if (!refresh && Array.isArray(dataView.cachedFields) && dataView.cachedFields.length > 0) {
|
|
107
|
+
return { dataView, fields: dataView.cachedFields };
|
|
108
|
+
}
|
|
109
|
+
const fields = await this.inspectFieldsBySource(dataView.dataSourceKey, dataView.indexPattern);
|
|
110
|
+
const repo = this.app.db.getRepository(import_constants.DATA_VIEWS_COLLECTION);
|
|
111
|
+
await repo.update({
|
|
112
|
+
filterByTk: dataView.id,
|
|
113
|
+
values: { cachedFields: fields }
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
dataView: { ...dataView, cachedFields: fields },
|
|
117
|
+
fields
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async upsertDataView(input, userId) {
|
|
121
|
+
var _a, _b, _c, _d;
|
|
122
|
+
const title = (_a = input.title) == null ? void 0 : _a.trim();
|
|
123
|
+
const dataSourceKey = (_b = input.dataSourceKey) == null ? void 0 : _b.trim();
|
|
124
|
+
const indexPattern = (_c = input.indexPattern) == null ? void 0 : _c.trim();
|
|
125
|
+
if (!title) throw new Error("Data view title is required");
|
|
126
|
+
if (!dataSourceKey) throw new Error("Elasticsearch dataSourceKey is required");
|
|
127
|
+
if (!indexPattern) throw new Error("Index pattern is required");
|
|
128
|
+
const fields = await this.inspectFieldsBySource(dataSourceKey, indexPattern);
|
|
129
|
+
let timeField = ((_d = input.timeField) == null ? void 0 : _d.trim()) || null;
|
|
130
|
+
if (!timeField) {
|
|
131
|
+
const autoDate = fields.find((f) => f.name === "@timestamp" && (f.type === "date" || f.type === "date_nanos")) ?? fields.find((f) => f.type === "date" || f.type === "date_nanos");
|
|
132
|
+
timeField = (autoDate == null ? void 0 : autoDate.name) ?? null;
|
|
133
|
+
}
|
|
134
|
+
const repo = this.app.db.getRepository(import_constants.DATA_VIEWS_COLLECTION);
|
|
135
|
+
const values = {
|
|
136
|
+
title,
|
|
137
|
+
dataSourceKey,
|
|
138
|
+
indexPattern,
|
|
139
|
+
timeField,
|
|
140
|
+
description: input.description ?? null,
|
|
141
|
+
cachedFields: fields
|
|
142
|
+
};
|
|
143
|
+
if (input.id !== void 0 && input.id !== null && String(input.id).trim() !== "") {
|
|
144
|
+
await repo.update({
|
|
145
|
+
filterByTk: input.id,
|
|
146
|
+
values
|
|
147
|
+
});
|
|
148
|
+
return this.getDataView(input.id);
|
|
149
|
+
}
|
|
150
|
+
if (userId !== void 0) {
|
|
151
|
+
values.createdById = userId;
|
|
152
|
+
}
|
|
153
|
+
const created = await repo.create({ values });
|
|
154
|
+
return serializeDataView(created);
|
|
155
|
+
}
|
|
156
|
+
async listReports(options) {
|
|
157
|
+
var _a;
|
|
158
|
+
const repo = this.app.db.getRepository(import_constants.REPORTS_COLLECTION);
|
|
159
|
+
const filter = {};
|
|
160
|
+
if (options == null ? void 0 : options.publishedOnly) {
|
|
161
|
+
filter.published = true;
|
|
162
|
+
}
|
|
163
|
+
if ((_a = options == null ? void 0 : options.search) == null ? void 0 : _a.trim()) {
|
|
164
|
+
filter.title = { $includes: options.search.trim() };
|
|
165
|
+
}
|
|
166
|
+
const rows = await repo.find({
|
|
167
|
+
filter,
|
|
168
|
+
appends: ["dataView"],
|
|
169
|
+
sort: ["-updatedAt", "-id"]
|
|
170
|
+
});
|
|
171
|
+
return rows.map(serializeReport);
|
|
172
|
+
}
|
|
173
|
+
async getReport(reportId) {
|
|
174
|
+
const repo = this.app.db.getRepository(import_constants.REPORTS_COLLECTION);
|
|
175
|
+
const row = await repo.findOne({
|
|
176
|
+
filterByTk: reportId,
|
|
177
|
+
appends: ["dataView"]
|
|
178
|
+
});
|
|
179
|
+
if (!row) {
|
|
180
|
+
throw new Error(`Report "${String(reportId)}" was not found`);
|
|
181
|
+
}
|
|
182
|
+
return serializeReport(row);
|
|
183
|
+
}
|
|
184
|
+
async saveReport(input, userId) {
|
|
185
|
+
var _a;
|
|
186
|
+
const title = (_a = input.title) == null ? void 0 : _a.trim();
|
|
187
|
+
if (!title) {
|
|
188
|
+
throw new Error("Report title is required");
|
|
189
|
+
}
|
|
190
|
+
const dataView = await this.getDataView(input.dataViewId);
|
|
191
|
+
const spec = (0, import_ReportQueryCompiler.normalizeReportSpec)(input.spec);
|
|
192
|
+
const repo = this.app.db.getRepository(import_constants.REPORTS_COLLECTION);
|
|
193
|
+
const values = {
|
|
194
|
+
title,
|
|
195
|
+
description: input.description ?? null,
|
|
196
|
+
dataViewId: dataView.id,
|
|
197
|
+
visualization: spec.visualization,
|
|
198
|
+
spec,
|
|
199
|
+
published: input.published !== false,
|
|
200
|
+
...userId !== void 0 ? { updatedById: userId } : {}
|
|
201
|
+
};
|
|
202
|
+
if (input.id !== void 0 && input.id !== null && String(input.id).trim() !== "") {
|
|
203
|
+
await repo.update({
|
|
204
|
+
filterByTk: input.id,
|
|
205
|
+
values
|
|
206
|
+
});
|
|
207
|
+
return this.getReport(input.id);
|
|
208
|
+
}
|
|
209
|
+
if (userId !== void 0) {
|
|
210
|
+
values.createdById = userId;
|
|
211
|
+
}
|
|
212
|
+
const created = await repo.create({ values });
|
|
213
|
+
const plain = toPlainObject(created);
|
|
214
|
+
return this.getReport(plain.id);
|
|
215
|
+
}
|
|
216
|
+
async previewReport(params) {
|
|
217
|
+
const { dataView, fields } = await this.inspectDataViewFields(params.dataViewId, false);
|
|
218
|
+
const normalizedSpec = (0, import_ReportQueryCompiler.normalizeReportSpec)(params.spec);
|
|
219
|
+
const { body, effectiveSpec } = (0, import_ReportQueryCompiler.compileSearchRequest)({
|
|
220
|
+
spec: normalizedSpec,
|
|
221
|
+
overrides: params.overrides,
|
|
222
|
+
timeField: dataView.timeField,
|
|
223
|
+
fields,
|
|
224
|
+
maxRowsCap: params.forMcp ? import_constants.MAX_MCP_PREVIEW_SIZE : import_constants.MAX_UI_PAGE_SIZE
|
|
225
|
+
});
|
|
226
|
+
const client = await this.connections.getClient(dataView.dataSourceKey);
|
|
227
|
+
const rawSearch = await client.search(dataView.indexPattern, body);
|
|
228
|
+
const result = (0, import_ReportQueryCompiler.parseSearchResponse)(rawSearch, body, effectiveSpec, dataView.timeField);
|
|
229
|
+
return { dataView, result };
|
|
230
|
+
}
|
|
231
|
+
async runSavedReport(params) {
|
|
232
|
+
var _a, _b, _c;
|
|
233
|
+
const report = await this.getReport(params.reportId);
|
|
234
|
+
if (params.requirePublished && !report.published) {
|
|
235
|
+
throw new Error(`Report "${report.title}" is not published`);
|
|
236
|
+
}
|
|
237
|
+
const runtimeOverrides = report.spec.allowInteractiveControls === false ? {
|
|
238
|
+
page: (_a = params.overrides) == null ? void 0 : _a.page,
|
|
239
|
+
pageSize: (_b = params.overrides) == null ? void 0 : _b.pageSize,
|
|
240
|
+
searchAfter: (_c = params.overrides) == null ? void 0 : _c.searchAfter
|
|
241
|
+
} : params.overrides;
|
|
242
|
+
const { dataView, result } = await this.previewReport({
|
|
243
|
+
dataViewId: report.dataViewId,
|
|
244
|
+
spec: report.spec,
|
|
245
|
+
overrides: runtimeOverrides,
|
|
246
|
+
forMcp: params.forMcp
|
|
247
|
+
});
|
|
248
|
+
return { report, dataView, result };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function extractCurrentUserId(ctx) {
|
|
252
|
+
var _a, _b, _c, _d;
|
|
253
|
+
const stateUser = (_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
|
|
254
|
+
if (stateUser !== void 0 && stateUser !== null) return stateUser;
|
|
255
|
+
const authUser = (_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.id;
|
|
256
|
+
if (authUser !== void 0 && authUser !== null) return authUser;
|
|
257
|
+
return void 0;
|
|
258
|
+
}
|
|
259
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
260
|
+
0 && (module.exports = {
|
|
261
|
+
ElasticReportService,
|
|
262
|
+
extractCurrentUserId
|
|
263
|
+
});
|