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,401 @@
|
|
|
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 { Client, type ClientOptions } from '@elastic/elasticsearch';
|
|
11
|
+
import type { Application } from '@nocobase/server';
|
|
12
|
+
import type { EsConnectionSummary, EsFieldCapability } from '../../shared/types';
|
|
13
|
+
|
|
14
|
+
export interface EsReadOnlyClient {
|
|
15
|
+
readIndices(indexPattern?: string): Promise<string[]>;
|
|
16
|
+
inspectFields(indexPattern: string): Promise<EsFieldCapability[]>;
|
|
17
|
+
search(indexPattern: string, body: Record<string, unknown>): Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface RawEsClientLike {
|
|
21
|
+
cat?: {
|
|
22
|
+
indices: (params: { index: string; format: 'json'; h: 'index' }) => Promise<unknown>;
|
|
23
|
+
};
|
|
24
|
+
fieldCaps?: (params: { index: string; fields: string }) => Promise<unknown>;
|
|
25
|
+
indices?: {
|
|
26
|
+
getMapping: (params: { index: string }) => Promise<unknown>;
|
|
27
|
+
};
|
|
28
|
+
search: (params: { index: string; body?: Record<string, unknown>; [key: string]: unknown }) => Promise<unknown>;
|
|
29
|
+
close?: () => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface DataSourceConnectionOptions {
|
|
33
|
+
nodes?: string;
|
|
34
|
+
username?: string;
|
|
35
|
+
password?: string;
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
indexPattern?: string;
|
|
38
|
+
rejectUnauthorized?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
42
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isRawEsClientLike(value: unknown): value is RawEsClientLike {
|
|
46
|
+
return isRecord(value) && typeof value.search === 'function';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function normaliseApiKey(raw: string): string {
|
|
50
|
+
const trimmed = raw.trim();
|
|
51
|
+
if (trimmed.includes(':')) {
|
|
52
|
+
return Buffer.from(trimmed).toString('base64');
|
|
53
|
+
}
|
|
54
|
+
return trimmed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function extractConnectionOptions(raw: unknown): DataSourceConnectionOptions {
|
|
58
|
+
if (!isRecord(raw)) return {};
|
|
59
|
+
if (typeof raw.nodes === 'string') return raw as DataSourceConnectionOptions;
|
|
60
|
+
if (isRecord(raw.options)) return raw.options as DataSourceConnectionOptions;
|
|
61
|
+
return raw as DataSourceConnectionOptions;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function buildEsClientOptions(opts: DataSourceConnectionOptions): ClientOptions {
|
|
65
|
+
const nodes = (opts.nodes || 'http://localhost:9200')
|
|
66
|
+
.split(',')
|
|
67
|
+
.map((item) => item.trim())
|
|
68
|
+
.filter(Boolean);
|
|
69
|
+
const clientOpts: ClientOptions = {
|
|
70
|
+
nodes,
|
|
71
|
+
requestTimeout: 20000,
|
|
72
|
+
};
|
|
73
|
+
if (opts.apiKey) {
|
|
74
|
+
clientOpts.auth = { apiKey: normaliseApiKey(opts.apiKey) };
|
|
75
|
+
} else if (opts.username) {
|
|
76
|
+
clientOpts.auth = {
|
|
77
|
+
username: opts.username,
|
|
78
|
+
password: opts.password || '',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (opts.rejectUnauthorized === false) {
|
|
82
|
+
clientOpts.tls = { rejectUnauthorized: false };
|
|
83
|
+
}
|
|
84
|
+
return clientOpts;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function assertSafeIndexPattern(indexPattern: string): string {
|
|
88
|
+
const clean = indexPattern.trim();
|
|
89
|
+
if (!clean) {
|
|
90
|
+
throw new Error('Index pattern is required');
|
|
91
|
+
}
|
|
92
|
+
if (clean.includes('/') || clean.includes('..') || clean.includes('?') || clean.includes('#')) {
|
|
93
|
+
throw new Error('Invalid index pattern');
|
|
94
|
+
}
|
|
95
|
+
const segments = clean
|
|
96
|
+
.split(',')
|
|
97
|
+
.map((s) => s.trim())
|
|
98
|
+
.filter(Boolean);
|
|
99
|
+
if (segments.length === 0) {
|
|
100
|
+
throw new Error('Index pattern is required');
|
|
101
|
+
}
|
|
102
|
+
if (segments.some((seg) => seg.startsWith('.') && seg !== '.*')) {
|
|
103
|
+
throw new Error('System dot-indices cannot be queried in reports');
|
|
104
|
+
}
|
|
105
|
+
return segments.join(',');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const AGGREGATABLE_ES_TYPES = new Set([
|
|
109
|
+
'keyword',
|
|
110
|
+
'constant_keyword',
|
|
111
|
+
'wildcard',
|
|
112
|
+
'long',
|
|
113
|
+
'integer',
|
|
114
|
+
'short',
|
|
115
|
+
'byte',
|
|
116
|
+
'double',
|
|
117
|
+
'float',
|
|
118
|
+
'half_float',
|
|
119
|
+
'scaled_float',
|
|
120
|
+
'unsigned_long',
|
|
121
|
+
'boolean',
|
|
122
|
+
'date',
|
|
123
|
+
'date_nanos',
|
|
124
|
+
'ip',
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
function flattenMappingProperties(
|
|
128
|
+
properties: Record<string, unknown>,
|
|
129
|
+
prefix = '',
|
|
130
|
+
out: Map<string, EsFieldCapability> = new Map(),
|
|
131
|
+
): Map<string, EsFieldCapability> {
|
|
132
|
+
for (const [name, rawDef] of Object.entries(properties)) {
|
|
133
|
+
if (!isRecord(rawDef)) continue;
|
|
134
|
+
const fullPath = prefix ? `${prefix}.${name}` : name;
|
|
135
|
+
const esType = typeof rawDef.type === 'string' ? rawDef.type : undefined;
|
|
136
|
+
|
|
137
|
+
if (esType) {
|
|
138
|
+
const aggregatable = AGGREGATABLE_ES_TYPES.has(esType);
|
|
139
|
+
out.set(fullPath, {
|
|
140
|
+
name: fullPath,
|
|
141
|
+
type: esType,
|
|
142
|
+
searchable: esType !== 'binary',
|
|
143
|
+
aggregatable,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (isRecord(rawDef.fields)) {
|
|
148
|
+
for (const [subName, rawSub] of Object.entries(rawDef.fields)) {
|
|
149
|
+
if (!isRecord(rawSub)) continue;
|
|
150
|
+
const subType = typeof rawSub.type === 'string' ? rawSub.type : 'keyword';
|
|
151
|
+
const subPath = `${fullPath}.${subName}`;
|
|
152
|
+
out.set(subPath, {
|
|
153
|
+
name: subPath,
|
|
154
|
+
type: subType,
|
|
155
|
+
searchable: true,
|
|
156
|
+
aggregatable: AGGREGATABLE_ES_TYPES.has(subType),
|
|
157
|
+
isSubfield: true,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isRecord(rawDef.properties)) {
|
|
163
|
+
flattenMappingProperties(rawDef.properties, fullPath, out);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function normalizeFieldCapabilitiesResponse(rawFieldCaps: unknown): EsFieldCapability[] {
|
|
170
|
+
const root = isRecord(rawFieldCaps) && isRecord(rawFieldCaps.fields) ? rawFieldCaps.fields : {};
|
|
171
|
+
const map = new Map<string, EsFieldCapability>();
|
|
172
|
+
|
|
173
|
+
for (const [fieldName, typeBuckets] of Object.entries(root)) {
|
|
174
|
+
if (fieldName.startsWith('_') && fieldName !== '_id' && fieldName !== '_index') {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!isRecord(typeBuckets)) continue;
|
|
178
|
+
|
|
179
|
+
let chosenType = 'string';
|
|
180
|
+
let searchable = false;
|
|
181
|
+
let aggregatable = false;
|
|
182
|
+
|
|
183
|
+
for (const [typeName, rawCap] of Object.entries(typeBuckets)) {
|
|
184
|
+
if (!isRecord(rawCap)) continue;
|
|
185
|
+
chosenType = typeName;
|
|
186
|
+
if (rawCap.searchable === true) searchable = true;
|
|
187
|
+
if (rawCap.aggregatable === true) aggregatable = true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
map.set(fieldName, {
|
|
191
|
+
name: fieldName,
|
|
192
|
+
type: chosenType,
|
|
193
|
+
searchable,
|
|
194
|
+
aggregatable,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return linkKeywordSubfields(map);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function linkKeywordSubfields(map: Map<string, EsFieldCapability>): EsFieldCapability[] {
|
|
202
|
+
for (const [name, cap] of map.entries()) {
|
|
203
|
+
const keywordCandidate = `${name}.keyword`;
|
|
204
|
+
const sub = map.get(keywordCandidate);
|
|
205
|
+
if (sub && sub.aggregatable) {
|
|
206
|
+
cap.keywordSubfield = keywordCandidate;
|
|
207
|
+
sub.isSubfield = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return Array.from(map.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function wrapEsClient(rawClient: RawEsClientLike): EsReadOnlyClient {
|
|
215
|
+
return {
|
|
216
|
+
async readIndices(indexPattern = '*'): Promise<string[]> {
|
|
217
|
+
const safePattern = indexPattern.trim() || '*';
|
|
218
|
+
if (!rawClient.cat?.indices) {
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
const response = await rawClient.cat.indices({
|
|
222
|
+
index: safePattern,
|
|
223
|
+
format: 'json',
|
|
224
|
+
h: 'index',
|
|
225
|
+
});
|
|
226
|
+
const unwrapped = isRecord(response) && Array.isArray(response.body) ? response.body : response;
|
|
227
|
+
if (!Array.isArray(unwrapped)) return [];
|
|
228
|
+
return unwrapped
|
|
229
|
+
.map((row) => (isRecord(row) && typeof row.index === 'string' ? row.index.trim() : ''))
|
|
230
|
+
.filter((idx) => Boolean(idx) && !idx.startsWith('.'))
|
|
231
|
+
.sort((a, b) => a.localeCompare(b));
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
async inspectFields(indexPattern: string): Promise<EsFieldCapability[]> {
|
|
235
|
+
const safePattern = assertSafeIndexPattern(indexPattern);
|
|
236
|
+
if (rawClient.fieldCaps) {
|
|
237
|
+
const raw = await rawClient.fieldCaps({
|
|
238
|
+
index: safePattern,
|
|
239
|
+
fields: '*',
|
|
240
|
+
});
|
|
241
|
+
const unwrapped = isRecord(raw) && isRecord(raw.body) ? raw.body : raw;
|
|
242
|
+
const parsed = normalizeFieldCapabilitiesResponse(unwrapped);
|
|
243
|
+
if (parsed.length > 0) {
|
|
244
|
+
return parsed;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (rawClient.indices?.getMapping) {
|
|
249
|
+
const rawMapping = await rawClient.indices.getMapping({ index: safePattern });
|
|
250
|
+
const unwrapped = isRecord(rawMapping) && isRecord(rawMapping.body) ? rawMapping.body : rawMapping;
|
|
251
|
+
if (isRecord(unwrapped)) {
|
|
252
|
+
const merged = new Map<string, EsFieldCapability>();
|
|
253
|
+
for (const indexEntry of Object.values(unwrapped)) {
|
|
254
|
+
if (!isRecord(indexEntry)) continue;
|
|
255
|
+
const mappings = isRecord(indexEntry.mappings) ? indexEntry.mappings : undefined;
|
|
256
|
+
const props = mappings && isRecord(mappings.properties) ? mappings.properties : undefined;
|
|
257
|
+
if (props) {
|
|
258
|
+
flattenMappingProperties(props, '', merged);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return linkKeywordSubfields(merged);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return [];
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
async search(indexPattern: string, body: Record<string, unknown>): Promise<unknown> {
|
|
269
|
+
const safePattern = assertSafeIndexPattern(indexPattern);
|
|
270
|
+
// Elasticsearch v8 client accepts top-level search params (`{ index, ...body }`).
|
|
271
|
+
const response = await rawClient.search({
|
|
272
|
+
index: safePattern,
|
|
273
|
+
...body,
|
|
274
|
+
});
|
|
275
|
+
return isRecord(response) && isRecord(response.body) ? response.body : response;
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export class ElasticsearchConnectionService {
|
|
281
|
+
private readonly fallbackClients = new Map<string, Client>();
|
|
282
|
+
|
|
283
|
+
constructor(private readonly app: Application) {}
|
|
284
|
+
|
|
285
|
+
async close(): Promise<void> {
|
|
286
|
+
const clients = Array.from(this.fallbackClients.values());
|
|
287
|
+
this.fallbackClients.clear();
|
|
288
|
+
await Promise.allSettled(clients.map((client) => client.close()));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Discover all Elasticsearch data sources configured via `plugin-data-source-elasticsearch`
|
|
293
|
+
* without leaking sensitive credentials (`password`, `apiKey`).
|
|
294
|
+
*/
|
|
295
|
+
async listConnections(): Promise<EsConnectionSummary[]> {
|
|
296
|
+
const byKey = new Map<string, EsConnectionSummary>();
|
|
297
|
+
|
|
298
|
+
const dsManager = this.app.dataSourceManager as unknown as {
|
|
299
|
+
dataSources?: Map<string, unknown>;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
if (dsManager?.dataSources instanceof Map) {
|
|
303
|
+
for (const [key, ds] of dsManager.dataSources.entries()) {
|
|
304
|
+
if (!isRecord(ds)) continue;
|
|
305
|
+
const cm = isRecord(ds.collectionManager) ? ds.collectionManager : undefined;
|
|
306
|
+
const pubOpts = typeof ds.publicOptions === 'function' ? ds.publicOptions() : undefined;
|
|
307
|
+
const opts = extractConnectionOptions(pubOpts ?? ds.options);
|
|
308
|
+
const isEs = isRawEsClientLike(cm?.esClient) || ds.constructor?.name === 'ElasticsearchDataSource';
|
|
309
|
+
if (!isEs) continue;
|
|
310
|
+
|
|
311
|
+
byKey.set(key, {
|
|
312
|
+
key,
|
|
313
|
+
displayName: typeof ds.displayName === 'string' && ds.displayName ? ds.displayName : key,
|
|
314
|
+
status: 'loaded',
|
|
315
|
+
...(typeof opts.indexPattern === 'string' ? { indexPattern: opts.indexPattern } : {}),
|
|
316
|
+
...(typeof opts.nodes === 'string' ? { nodes: opts.nodes } : {}),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
const repo = this.app.db.getRepository('dataSources');
|
|
323
|
+
if (repo) {
|
|
324
|
+
const rows = await repo.find({
|
|
325
|
+
filter: { type: 'elasticsearch' },
|
|
326
|
+
});
|
|
327
|
+
for (const row of rows) {
|
|
328
|
+
const plain = typeof row?.toJSON === 'function' ? row.toJSON() : row;
|
|
329
|
+
if (!isRecord(plain) || typeof plain.key !== 'string' || !plain.key.trim()) continue;
|
|
330
|
+
const key = plain.key.trim();
|
|
331
|
+
const opts = extractConnectionOptions(plain.options);
|
|
332
|
+
const existing = byKey.get(key);
|
|
333
|
+
byKey.set(key, {
|
|
334
|
+
key,
|
|
335
|
+
displayName:
|
|
336
|
+
typeof plain.displayName === 'string' && plain.displayName.trim()
|
|
337
|
+
? plain.displayName.trim()
|
|
338
|
+
: existing?.displayName ?? key,
|
|
339
|
+
status: typeof plain.status === 'string' ? plain.status : existing?.status ?? 'configured',
|
|
340
|
+
...(typeof opts.indexPattern === 'string'
|
|
341
|
+
? { indexPattern: opts.indexPattern }
|
|
342
|
+
: existing?.indexPattern
|
|
343
|
+
? { indexPattern: existing.indexPattern }
|
|
344
|
+
: {}),
|
|
345
|
+
...(typeof opts.nodes === 'string'
|
|
346
|
+
? { nodes: opts.nodes }
|
|
347
|
+
: existing?.nodes
|
|
348
|
+
? { nodes: existing.nodes }
|
|
349
|
+
: {}),
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
} catch {
|
|
354
|
+
// `dataSources` table may not exist in lightweight unit test setups without plugin-data-source-manager.
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return Array.from(byKey.values()).sort((a, b) => a.displayName.localeCompare(b.displayName));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
async getClient(dataSourceKey: string): Promise<EsReadOnlyClient> {
|
|
361
|
+
const cleanKey = dataSourceKey.trim();
|
|
362
|
+
if (!cleanKey) {
|
|
363
|
+
throw new Error('Elasticsearch dataSourceKey is required');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const liveDs = this.app.dataSourceManager?.get(cleanKey) as unknown;
|
|
367
|
+
if (
|
|
368
|
+
isRecord(liveDs) &&
|
|
369
|
+
isRecord(liveDs.collectionManager) &&
|
|
370
|
+
isRawEsClientLike(liveDs.collectionManager.esClient)
|
|
371
|
+
) {
|
|
372
|
+
return wrapEsClient(liveDs.collectionManager.esClient);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const cached = this.fallbackClients.get(cleanKey);
|
|
376
|
+
if (cached) {
|
|
377
|
+
return wrapEsClient(cached as unknown as RawEsClientLike);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const repo = this.app.db.getRepository('dataSources');
|
|
381
|
+
const record = repo
|
|
382
|
+
? await repo.findOne({
|
|
383
|
+
filter: { key: cleanKey, type: 'elasticsearch' },
|
|
384
|
+
})
|
|
385
|
+
: null;
|
|
386
|
+
|
|
387
|
+
if (!record) {
|
|
388
|
+
throw new Error(`Elasticsearch data source "${cleanKey}" was not found or is not loaded`);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const plain = typeof record.toJSON === 'function' ? record.toJSON() : record;
|
|
392
|
+
const opts = extractConnectionOptions(isRecord(plain) ? plain.options : undefined);
|
|
393
|
+
if (!opts.nodes) {
|
|
394
|
+
throw new Error(`Elasticsearch data source "${cleanKey}" has no configured nodes`);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const client = new Client(buildEsClientOptions(opts));
|
|
398
|
+
this.fallbackClients.set(cleanKey, client);
|
|
399
|
+
return wrapEsClient(client as unknown as RawEsClientLike);
|
|
400
|
+
}
|
|
401
|
+
}
|