plugin-elastic-report 0.0.0-stage → 0.7.0

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.
Files changed (272) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +34 -0
  2. package/client-v2.d.ts +2 -0
  3. package/client-v2.js +1 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  7. package/dist/client/index.js +10 -0
  8. package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
  9. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  10. package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
  11. package/dist/client-v2/index.js +10 -0
  12. package/dist/externalVersion.js +21 -0
  13. package/dist/index.js +48 -0
  14. package/dist/locale/en-US.json +198 -0
  15. package/dist/locale/vi-VN.json +198 -0
  16. package/dist/locale/zh-CN.json +198 -0
  17. package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
  18. package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
  19. package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
  20. package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
  21. package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
  22. package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
  23. package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
  24. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
  25. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
  26. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
  27. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
  28. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
  29. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
  30. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
  31. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
  32. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
  33. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
  34. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
  35. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
  36. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
  37. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
  38. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
  39. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
  40. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
  41. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
  42. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
  43. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
  44. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
  45. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
  46. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
  47. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
  48. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
  49. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
  50. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
  51. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
  52. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
  53. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
  54. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
  55. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
  56. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
  57. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
  58. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
  59. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
  60. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
  61. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
  62. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
  63. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
  64. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
  65. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
  66. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
  67. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
  68. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
  69. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
  70. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
  71. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
  72. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
  73. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
  74. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
  75. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
  76. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
  77. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
  78. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
  79. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
  80. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
  81. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
  82. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
  83. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
  84. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
  85. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
  86. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
  87. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
  88. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
  89. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
  90. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
  91. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
  92. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
  93. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
  94. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
  95. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
  96. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
  97. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
  98. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
  99. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
  100. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
  101. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
  102. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
  103. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
  104. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
  105. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
  106. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
  107. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
  108. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
  109. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
  110. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
  111. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
  112. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
  113. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
  114. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
  115. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
  116. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
  117. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
  118. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
  119. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
  120. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
  121. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
  122. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
  123. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
  124. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
  125. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
  126. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
  127. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
  128. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
  129. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
  130. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
  131. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
  132. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
  133. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
  134. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
  135. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
  136. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
  137. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
  138. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
  139. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
  140. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
  141. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
  142. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
  143. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
  144. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
  145. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
  146. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
  147. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
  148. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
  149. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
  150. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
  151. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
  152. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
  153. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
  154. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
  155. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
  156. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
  157. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
  158. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
  159. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
  160. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
  161. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
  162. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
  163. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
  164. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
  165. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
  166. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
  167. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
  168. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
  169. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
  170. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
  171. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
  172. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
  173. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
  174. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
  175. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
  176. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
  177. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
  178. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
  179. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
  180. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
  181. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
  182. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
  183. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
  184. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
  185. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
  186. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
  187. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
  188. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
  189. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
  190. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
  191. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
  192. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
  193. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
  194. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
  195. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
  196. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
  197. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
  198. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
  199. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
  200. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
  201. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
  202. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
  203. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
  204. package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
  205. package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
  206. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
  207. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
  208. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
  209. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
  210. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
  211. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
  212. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
  213. package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
  214. package/dist/server/acl-guard.js +179 -0
  215. package/dist/server/collections/es-report-data-views.js +85 -0
  216. package/dist/server/collections/es-reports.js +101 -0
  217. package/dist/server/index.js +58 -0
  218. package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
  219. package/dist/server/mcp/ElasticReportToolCatalog.js +639 -0
  220. package/dist/server/plugin.js +529 -0
  221. package/dist/server/services/ElasticReportService.js +377 -0
  222. package/dist/server/services/ElasticsearchConnectionService.js +572 -0
  223. package/dist/server/services/ReportExportService.js +243 -0
  224. package/dist/server/services/ReportQueryCompiler.js +1299 -0
  225. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  226. package/dist/shared/constants.js +96 -0
  227. package/dist/shared/types.js +24 -0
  228. package/package.json +62 -4
  229. package/server.d.ts +2 -0
  230. package/server.js +1 -0
  231. package/src/client/index.tsx +34 -0
  232. package/src/client/workflow-instructions.tsx +44 -0
  233. package/src/client-v2/__tests__/elastic-report.test.tsx +791 -0
  234. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  235. package/src/client-v2/api.ts +320 -0
  236. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  237. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -0
  238. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  239. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  240. package/src/client-v2/components/ElasticReportBlock.tsx +306 -0
  241. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -0
  242. package/src/client-v2/components/HighlightText.tsx +50 -0
  243. package/src/client-v2/components/ReportSelect.tsx +85 -0
  244. package/src/client-v2/index.tsx +14 -0
  245. package/src/client-v2/locale.ts +23 -0
  246. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  247. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -0
  248. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -0
  249. package/src/client-v2/plugin.tsx +72 -0
  250. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  251. package/src/client-v2/workflow/instructions.tsx +149 -0
  252. package/src/index.ts +11 -0
  253. package/src/locale/en-US.json +198 -0
  254. package/src/locale/vi-VN.json +198 -0
  255. package/src/locale/zh-CN.json +198 -0
  256. package/src/server/__tests__/query-compiler.test.ts +620 -0
  257. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -0
  258. package/src/server/acl-guard.ts +194 -0
  259. package/src/server/collections/es-report-data-views.ts +64 -0
  260. package/src/server/collections/es-reports.ts +80 -0
  261. package/src/server/index.ts +15 -0
  262. package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
  263. package/src/server/mcp/ElasticReportToolCatalog.ts +663 -0
  264. package/src/server/plugin.ts +599 -0
  265. package/src/server/services/ElasticReportService.ts +486 -0
  266. package/src/server/services/ElasticsearchConnectionService.ts +728 -0
  267. package/src/server/services/ReportExportService.ts +282 -0
  268. package/src/server/services/ReportQueryCompiler.ts +1552 -0
  269. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  270. package/src/shared/constants.ts +36 -0
  271. package/src/shared/types.ts +272 -0
  272. package/README.md +0 -3
@@ -0,0 +1,572 @@
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 ElasticsearchConnectionService_exports = {};
28
+ __export(ElasticsearchConnectionService_exports, {
29
+ ElasticsearchConnectionService: () => ElasticsearchConnectionService,
30
+ buildEsClientOptions: () => buildEsClientOptions,
31
+ inferConnectionModes: () => inferConnectionModes,
32
+ normalizeFieldCapabilitiesResponse: () => normalizeFieldCapabilitiesResponse
33
+ });
34
+ module.exports = __toCommonJS(ElasticsearchConnectionService_exports);
35
+ var import_elasticsearch = require("@elastic/elasticsearch");
36
+ function isRecord(value) {
37
+ return typeof value === "object" && value !== null && !Array.isArray(value);
38
+ }
39
+ function toNonEmptyString(value) {
40
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
41
+ }
42
+ function isRawEsClientLike(value) {
43
+ return isRecord(value) && typeof value.search === "function";
44
+ }
45
+ function normaliseApiKey(raw) {
46
+ const trimmed = raw.trim();
47
+ if (trimmed.includes(":")) {
48
+ return Buffer.from(trimmed).toString("base64");
49
+ }
50
+ return trimmed;
51
+ }
52
+ function normalizeCaFingerprint(raw) {
53
+ const cleaned = raw.replace(/[\s:]/g, "").toLowerCase();
54
+ if (!/^[0-9a-f]{64}$/.test(cleaned)) {
55
+ throw new Error("Invalid CA SHA-256 fingerprint: expected 64 hexadecimal characters");
56
+ }
57
+ return cleaned;
58
+ }
59
+ function inferConnectionModes(opts) {
60
+ const endpointMode = opts.endpointMode === "cloud" || opts.endpointMode === "nodes" ? opts.endpointMode : toNonEmptyString(opts.cloudId) ? "cloud" : "nodes";
61
+ let authMode = "none";
62
+ if (opts.authMode === "none" || opts.authMode === "basic" || opts.authMode === "apiKey" || opts.authMode === "bearer") {
63
+ authMode = opts.authMode;
64
+ } else if (opts.hasBearerToken === true || toNonEmptyString(opts.bearerToken)) {
65
+ authMode = "bearer";
66
+ } else if (opts.hasApiKey === true || toNonEmptyString(opts.apiKey)) {
67
+ authMode = "apiKey";
68
+ } else if (toNonEmptyString(opts.username)) {
69
+ authMode = "basic";
70
+ }
71
+ let tlsMode = "verify";
72
+ if (opts.tlsMode === "verify" || opts.tlsMode === "caFingerprint" || opts.tlsMode === "caCert" || opts.tlsMode === "skip") {
73
+ tlsMode = opts.tlsMode;
74
+ } else if (toNonEmptyString(opts.caFingerprint)) {
75
+ tlsMode = "caFingerprint";
76
+ } else if (opts.hasCaCert === true || toNonEmptyString(opts.caCert)) {
77
+ tlsMode = "caCert";
78
+ } else if (opts.rejectUnauthorized === false) {
79
+ tlsMode = "skip";
80
+ }
81
+ return { endpointMode, authMode, tlsMode };
82
+ }
83
+ function extractConnectionOptions(raw) {
84
+ if (!isRecord(raw)) return {};
85
+ if (typeof raw.nodes === "string" || typeof raw.cloudId === "string" || typeof raw.endpointMode === "string") {
86
+ return raw;
87
+ }
88
+ if (isRecord(raw.options)) return raw.options;
89
+ return raw;
90
+ }
91
+ function buildEsClientOptions(opts) {
92
+ const { endpointMode, authMode, tlsMode } = inferConnectionModes(opts);
93
+ const timeoutMs = typeof opts.requestTimeoutMs === "number" && Number.isFinite(opts.requestTimeoutMs) && opts.requestTimeoutMs >= 1e3 ? Math.min(3e5, Math.trunc(opts.requestTimeoutMs)) : 3e4;
94
+ const clientOpts = {
95
+ requestTimeout: timeoutMs
96
+ };
97
+ if (endpointMode === "cloud") {
98
+ const cloudId = toNonEmptyString(opts.cloudId);
99
+ if (!cloudId) {
100
+ throw new Error("Elasticsearch data source has no configured Cloud ID");
101
+ }
102
+ clientOpts.cloud = { id: cloudId };
103
+ } else {
104
+ const nodes = (opts.nodes || "http://localhost:9200").split(",").map((item) => item.trim()).filter(Boolean);
105
+ clientOpts.nodes = nodes;
106
+ }
107
+ if (authMode === "bearer") {
108
+ const bearer = toNonEmptyString(opts.bearerToken);
109
+ if (bearer) {
110
+ clientOpts.auth = { bearer };
111
+ }
112
+ } else if (authMode === "apiKey") {
113
+ const apiKey = toNonEmptyString(opts.apiKey);
114
+ if (apiKey) {
115
+ clientOpts.auth = { apiKey: normaliseApiKey(apiKey) };
116
+ }
117
+ } else if (authMode === "basic") {
118
+ const username = toNonEmptyString(opts.username);
119
+ if (username) {
120
+ clientOpts.auth = {
121
+ username,
122
+ password: opts.password || ""
123
+ };
124
+ }
125
+ }
126
+ const servername = toNonEmptyString(opts.tlsServerName);
127
+ if (tlsMode === "caFingerprint") {
128
+ const fp = toNonEmptyString(opts.caFingerprint);
129
+ if (fp) {
130
+ clientOpts.caFingerprint = normalizeCaFingerprint(fp);
131
+ clientOpts.tls = {
132
+ rejectUnauthorized: false,
133
+ ...servername ? { servername } : {}
134
+ };
135
+ } else if (servername) {
136
+ clientOpts.tls = { servername };
137
+ }
138
+ } else if (tlsMode === "caCert") {
139
+ const ca = toNonEmptyString(opts.caCert);
140
+ clientOpts.tls = {
141
+ ...ca ? { ca } : {},
142
+ rejectUnauthorized: true,
143
+ ...servername ? { servername } : {}
144
+ };
145
+ } else if (tlsMode === "skip") {
146
+ clientOpts.tls = {
147
+ rejectUnauthorized: false,
148
+ ...servername ? { servername } : {}
149
+ };
150
+ } else if (servername) {
151
+ clientOpts.tls = {
152
+ rejectUnauthorized: true,
153
+ servername
154
+ };
155
+ }
156
+ if (typeof opts.maxRetries === "number" && Number.isFinite(opts.maxRetries) && opts.maxRetries >= 0) {
157
+ clientOpts.maxRetries = Math.min(10, Math.trunc(opts.maxRetries));
158
+ }
159
+ if (opts.compression === true) {
160
+ clientOpts.compression = true;
161
+ }
162
+ return clientOpts;
163
+ }
164
+ function assertSafeIndexPattern(indexPattern) {
165
+ const clean = indexPattern.trim();
166
+ if (!clean) {
167
+ throw new Error("Index pattern is required");
168
+ }
169
+ if (clean.includes("/") || clean.includes("..") || clean.includes("?") || clean.includes("#")) {
170
+ throw new Error("Invalid index pattern");
171
+ }
172
+ const segments = clean.split(",").map((s) => s.trim()).filter(Boolean);
173
+ if (segments.length === 0) {
174
+ throw new Error("Index pattern is required");
175
+ }
176
+ if (segments.some((seg) => seg.startsWith(".") && seg !== ".*")) {
177
+ throw new Error("System dot-indices cannot be queried in reports");
178
+ }
179
+ return segments.join(",");
180
+ }
181
+ const AGGREGATABLE_ES_TYPES = /* @__PURE__ */ new Set([
182
+ "keyword",
183
+ "constant_keyword",
184
+ "wildcard",
185
+ "long",
186
+ "integer",
187
+ "short",
188
+ "byte",
189
+ "double",
190
+ "float",
191
+ "half_float",
192
+ "scaled_float",
193
+ "unsigned_long",
194
+ "boolean",
195
+ "date",
196
+ "date_nanos",
197
+ "ip"
198
+ ]);
199
+ function flattenMappingProperties(properties, prefix = "", out = /* @__PURE__ */ new Map()) {
200
+ for (const [name, rawDef] of Object.entries(properties)) {
201
+ if (!isRecord(rawDef)) continue;
202
+ const fullPath = prefix ? `${prefix}.${name}` : name;
203
+ const esType = typeof rawDef.type === "string" ? rawDef.type : void 0;
204
+ if (esType) {
205
+ const aggregatable = AGGREGATABLE_ES_TYPES.has(esType);
206
+ out.set(fullPath, {
207
+ name: fullPath,
208
+ type: esType,
209
+ searchable: esType !== "binary",
210
+ aggregatable
211
+ });
212
+ }
213
+ if (isRecord(rawDef.fields)) {
214
+ for (const [subName, rawSub] of Object.entries(rawDef.fields)) {
215
+ if (!isRecord(rawSub)) continue;
216
+ const subType = typeof rawSub.type === "string" ? rawSub.type : "keyword";
217
+ const subPath = `${fullPath}.${subName}`;
218
+ out.set(subPath, {
219
+ name: subPath,
220
+ type: subType,
221
+ searchable: true,
222
+ aggregatable: AGGREGATABLE_ES_TYPES.has(subType),
223
+ isSubfield: true
224
+ });
225
+ }
226
+ }
227
+ if (isRecord(rawDef.properties)) {
228
+ flattenMappingProperties(rawDef.properties, fullPath, out);
229
+ }
230
+ }
231
+ return out;
232
+ }
233
+ function normalizeFieldCapabilitiesResponse(rawFieldCaps) {
234
+ const root = isRecord(rawFieldCaps) && isRecord(rawFieldCaps.fields) ? rawFieldCaps.fields : {};
235
+ const map = /* @__PURE__ */ new Map();
236
+ for (const [fieldName, typeBuckets] of Object.entries(root)) {
237
+ if (fieldName.startsWith("_") && fieldName !== "_id" && fieldName !== "_index") {
238
+ continue;
239
+ }
240
+ if (!isRecord(typeBuckets)) continue;
241
+ let chosenType = "string";
242
+ let searchable = false;
243
+ let aggregatable = false;
244
+ for (const [typeName, rawCap] of Object.entries(typeBuckets)) {
245
+ if (!isRecord(rawCap)) continue;
246
+ chosenType = typeName;
247
+ if (rawCap.searchable === true) searchable = true;
248
+ if (rawCap.aggregatable === true) aggregatable = true;
249
+ }
250
+ map.set(fieldName, {
251
+ name: fieldName,
252
+ type: chosenType,
253
+ searchable,
254
+ aggregatable
255
+ });
256
+ }
257
+ return linkKeywordSubfields(map);
258
+ }
259
+ function linkKeywordSubfields(map) {
260
+ for (const [name, cap] of map.entries()) {
261
+ const keywordCandidate = `${name}.keyword`;
262
+ const sub = map.get(keywordCandidate);
263
+ if (sub && sub.aggregatable) {
264
+ cap.keywordSubfield = keywordCandidate;
265
+ sub.isSubfield = true;
266
+ }
267
+ }
268
+ return Array.from(map.values()).sort((a, b) => a.name.localeCompare(b.name));
269
+ }
270
+ function collectResolvedIndexNames(rawResolve, out) {
271
+ const unwrapped = isRecord(rawResolve) && isRecord(rawResolve.body) ? rawResolve.body : rawResolve;
272
+ if (!isRecord(unwrapped)) return;
273
+ for (const bucketKey of ["indices", "data_streams", "aliases"]) {
274
+ const arr = unwrapped[bucketKey];
275
+ if (!Array.isArray(arr)) continue;
276
+ for (const entry of arr) {
277
+ if (!isRecord(entry) || entry.open === false) continue;
278
+ const name = toNonEmptyString(entry.name);
279
+ if (name && !name.startsWith(".")) {
280
+ out.add(name);
281
+ }
282
+ }
283
+ }
284
+ }
285
+ function wrapEsClient(rawClient) {
286
+ return {
287
+ async testConnection(indexPattern = "*") {
288
+ var _a;
289
+ const safePattern = assertSafeIndexPattern(indexPattern || "*");
290
+ if (typeof rawClient.info === "function") {
291
+ try {
292
+ const rawInfo = await rawClient.info();
293
+ const info = isRecord(rawInfo) && isRecord(rawInfo.body) ? rawInfo.body : rawInfo;
294
+ const clusterName = isRecord(info) ? toNonEmptyString(info.cluster_name) : void 0;
295
+ const versionObj = isRecord(info) && isRecord(info.version) ? info.version : void 0;
296
+ const version = versionObj ? toNonEmptyString(versionObj.number) : void 0;
297
+ if (clusterName || version) {
298
+ return {
299
+ ok: true,
300
+ ...clusterName ? { clusterName } : {},
301
+ ...version ? { version } : {}
302
+ };
303
+ }
304
+ } catch (err) {
305
+ const statusCode = isRecord(err) && typeof err.statusCode === "number" ? err.statusCode : void 0;
306
+ if (statusCode === 403 && rawClient.fieldCaps) {
307
+ await rawClient.fieldCaps({ index: safePattern, fields: "@timestamp" });
308
+ return { ok: true, limitedPrivileges: true };
309
+ }
310
+ throw err;
311
+ }
312
+ }
313
+ if (typeof ((_a = rawClient.cluster) == null ? void 0 : _a.health) === "function") {
314
+ try {
315
+ const rawHealth = await rawClient.cluster.health();
316
+ const health = isRecord(rawHealth) && isRecord(rawHealth.body) ? rawHealth.body : rawHealth;
317
+ const clusterName = isRecord(health) ? toNonEmptyString(health.cluster_name) : void 0;
318
+ if (clusterName) {
319
+ return { ok: true, clusterName };
320
+ }
321
+ } catch (err) {
322
+ const statusCode = isRecord(err) && typeof err.statusCode === "number" ? err.statusCode : void 0;
323
+ if (statusCode === 403 && rawClient.fieldCaps) {
324
+ await rawClient.fieldCaps({ index: safePattern, fields: "@timestamp" });
325
+ return { ok: true, limitedPrivileges: true };
326
+ }
327
+ throw err;
328
+ }
329
+ }
330
+ if (typeof rawClient.ping === "function") {
331
+ const pong = await rawClient.ping();
332
+ if (pong) {
333
+ return { ok: true };
334
+ }
335
+ }
336
+ if (rawClient.fieldCaps) {
337
+ await rawClient.fieldCaps({ index: safePattern, fields: "@timestamp" });
338
+ return { ok: true };
339
+ }
340
+ return { ok: true };
341
+ },
342
+ async readIndices(indexPattern = "*") {
343
+ var _a, _b, _c, _d;
344
+ const safePattern = assertSafeIndexPattern(indexPattern || "*");
345
+ const names = /* @__PURE__ */ new Set();
346
+ const resolvePromise = typeof ((_a = rawClient.indices) == null ? void 0 : _a.resolveIndex) === "function" ? rawClient.indices.resolveIndex({ name: safePattern }) : Promise.resolve(null);
347
+ const catPromise = typeof ((_b = rawClient.cat) == null ? void 0 : _b.indices) === "function" ? rawClient.cat.indices({ index: safePattern, format: "json", h: "index" }) : Promise.resolve(null);
348
+ const [resolveOutcome, catOutcome] = await Promise.allSettled([resolvePromise, catPromise]);
349
+ if (resolveOutcome.status === "fulfilled" && resolveOutcome.value) {
350
+ collectResolvedIndexNames(resolveOutcome.value, names);
351
+ }
352
+ if (catOutcome.status === "fulfilled" && catOutcome.value) {
353
+ const unwrapped = isRecord(catOutcome.value) && Array.isArray(catOutcome.value.body) ? catOutcome.value.body : catOutcome.value;
354
+ if (Array.isArray(unwrapped)) {
355
+ for (const row of unwrapped) {
356
+ const idx = isRecord(row) ? toNonEmptyString(row.index) : void 0;
357
+ if (idx && !idx.startsWith(".")) {
358
+ names.add(idx);
359
+ }
360
+ }
361
+ }
362
+ }
363
+ if (resolveOutcome.status === "rejected" && (catOutcome.status === "rejected" || typeof ((_c = rawClient.cat) == null ? void 0 : _c.indices) !== "function")) {
364
+ throw resolveOutcome.reason;
365
+ }
366
+ if (catOutcome.status === "rejected" && typeof ((_d = rawClient.indices) == null ? void 0 : _d.resolveIndex) !== "function") {
367
+ throw catOutcome.reason;
368
+ }
369
+ if (resolveOutcome.status === "rejected" && catOutcome.status === "rejected") {
370
+ throw catOutcome.reason || resolveOutcome.reason;
371
+ }
372
+ return Array.from(names).sort((a, b) => a.localeCompare(b));
373
+ },
374
+ async inspectFields(indexPattern) {
375
+ var _a;
376
+ const safePattern = assertSafeIndexPattern(indexPattern);
377
+ if (rawClient.fieldCaps) {
378
+ const raw = await rawClient.fieldCaps({
379
+ index: safePattern,
380
+ fields: "*"
381
+ });
382
+ const unwrapped = isRecord(raw) && isRecord(raw.body) ? raw.body : raw;
383
+ const parsed = normalizeFieldCapabilitiesResponse(unwrapped);
384
+ if (parsed.length > 0) {
385
+ return parsed;
386
+ }
387
+ }
388
+ if ((_a = rawClient.indices) == null ? void 0 : _a.getMapping) {
389
+ const rawMapping = await rawClient.indices.getMapping({ index: safePattern });
390
+ const unwrapped = isRecord(rawMapping) && isRecord(rawMapping.body) ? rawMapping.body : rawMapping;
391
+ if (isRecord(unwrapped)) {
392
+ const merged = /* @__PURE__ */ new Map();
393
+ for (const indexEntry of Object.values(unwrapped)) {
394
+ if (!isRecord(indexEntry)) continue;
395
+ const mappings = isRecord(indexEntry.mappings) ? indexEntry.mappings : void 0;
396
+ const props = mappings && isRecord(mappings.properties) ? mappings.properties : void 0;
397
+ if (props) {
398
+ flattenMappingProperties(props, "", merged);
399
+ }
400
+ }
401
+ return linkKeywordSubfields(merged);
402
+ }
403
+ }
404
+ return [];
405
+ },
406
+ async openPit(indexPattern, keepAlive = "1m") {
407
+ const safePattern = assertSafeIndexPattern(indexPattern);
408
+ if (typeof rawClient.openPointInTime !== "function") {
409
+ return null;
410
+ }
411
+ try {
412
+ const raw = await rawClient.openPointInTime({
413
+ index: safePattern,
414
+ keep_alive: keepAlive
415
+ });
416
+ const unwrapped = isRecord(raw) && isRecord(raw.body) ? raw.body : raw;
417
+ return isRecord(unwrapped) && typeof unwrapped.id === "string" && unwrapped.id ? unwrapped.id : null;
418
+ } catch {
419
+ return null;
420
+ }
421
+ },
422
+ async closePit(pitId) {
423
+ if (!pitId || typeof rawClient.closePointInTime !== "function") {
424
+ return;
425
+ }
426
+ try {
427
+ await rawClient.closePointInTime({ id: pitId });
428
+ } catch {
429
+ }
430
+ },
431
+ async search(indexPattern, body, options) {
432
+ if (options == null ? void 0 : options.pitId) {
433
+ const response2 = await rawClient.search({
434
+ ...body,
435
+ pit: {
436
+ id: options.pitId,
437
+ keep_alive: options.keepAlive ?? "1m"
438
+ }
439
+ });
440
+ return isRecord(response2) && isRecord(response2.body) ? response2.body : response2;
441
+ }
442
+ const safePattern = assertSafeIndexPattern(indexPattern);
443
+ const response = await rawClient.search({
444
+ index: safePattern,
445
+ ...body
446
+ });
447
+ return isRecord(response) && isRecord(response.body) ? response.body : response;
448
+ }
449
+ };
450
+ }
451
+ class ElasticsearchConnectionService {
452
+ constructor(app) {
453
+ this.app = app;
454
+ }
455
+ fallbackClients = /* @__PURE__ */ new Map();
456
+ async close() {
457
+ const entries = Array.from(this.fallbackClients.values());
458
+ this.fallbackClients.clear();
459
+ await Promise.allSettled(entries.map((entry) => entry.client.close()));
460
+ }
461
+ /**
462
+ * Discover all Elasticsearch data sources configured via `plugin-data-source-elasticsearch`
463
+ * without leaking sensitive credentials (`password`, `apiKey`, `bearerToken`, `caCert`).
464
+ */
465
+ async listConnections() {
466
+ var _a;
467
+ const byKey = /* @__PURE__ */ new Map();
468
+ const dsManager = this.app.dataSourceManager;
469
+ if ((dsManager == null ? void 0 : dsManager.dataSources) instanceof Map) {
470
+ for (const [key, ds] of dsManager.dataSources.entries()) {
471
+ if (!isRecord(ds)) continue;
472
+ const cm = isRecord(ds.collectionManager) ? ds.collectionManager : void 0;
473
+ const pubOpts = typeof ds.publicOptions === "function" ? ds.publicOptions() : void 0;
474
+ const opts = extractConnectionOptions(pubOpts ?? ds.options);
475
+ const isEs = isRawEsClientLike(cm == null ? void 0 : cm.esClient) || ((_a = ds.constructor) == null ? void 0 : _a.name) === "ElasticsearchDataSource";
476
+ if (!isEs) continue;
477
+ const modes = inferConnectionModes(opts);
478
+ byKey.set(key, {
479
+ key,
480
+ displayName: typeof ds.displayName === "string" && ds.displayName ? ds.displayName : key,
481
+ status: "loaded",
482
+ endpointMode: modes.endpointMode,
483
+ authMode: modes.authMode,
484
+ tlsMode: modes.tlsMode,
485
+ cloudConfigured: modes.endpointMode === "cloud",
486
+ ...typeof opts.indexPattern === "string" ? { indexPattern: opts.indexPattern } : {},
487
+ ...typeof opts.nodes === "string" ? { nodes: opts.nodes } : {}
488
+ });
489
+ }
490
+ }
491
+ try {
492
+ const repo = this.app.db.getRepository("dataSources");
493
+ if (repo) {
494
+ const rows = await repo.find({
495
+ filter: { type: "elasticsearch" }
496
+ });
497
+ for (const row of rows) {
498
+ const plain = typeof (row == null ? void 0 : row.toJSON) === "function" ? row.toJSON() : row;
499
+ if (!isRecord(plain) || typeof plain.key !== "string" || !plain.key.trim()) continue;
500
+ const key = plain.key.trim();
501
+ const opts = extractConnectionOptions(plain.options);
502
+ const modes = inferConnectionModes(opts);
503
+ const existing = byKey.get(key);
504
+ byKey.set(key, {
505
+ key,
506
+ displayName: typeof plain.displayName === "string" && plain.displayName.trim() ? plain.displayName.trim() : (existing == null ? void 0 : existing.displayName) ?? key,
507
+ status: typeof plain.status === "string" ? plain.status : (existing == null ? void 0 : existing.status) ?? "configured",
508
+ endpointMode: modes.endpointMode,
509
+ authMode: modes.authMode,
510
+ tlsMode: modes.tlsMode,
511
+ cloudConfigured: modes.endpointMode === "cloud",
512
+ ...typeof opts.indexPattern === "string" ? { indexPattern: opts.indexPattern } : (existing == null ? void 0 : existing.indexPattern) ? { indexPattern: existing.indexPattern } : {},
513
+ ...typeof opts.nodes === "string" ? { nodes: opts.nodes } : (existing == null ? void 0 : existing.nodes) ? { nodes: existing.nodes } : {}
514
+ });
515
+ }
516
+ }
517
+ } catch {
518
+ }
519
+ return Array.from(byKey.values()).sort((a, b) => a.displayName.localeCompare(b.displayName));
520
+ }
521
+ async getClient(dataSourceKey) {
522
+ var _a;
523
+ const cleanKey = dataSourceKey.trim();
524
+ if (!cleanKey) {
525
+ throw new Error("Elasticsearch dataSourceKey is required");
526
+ }
527
+ const liveDs = (_a = this.app.dataSourceManager) == null ? void 0 : _a.get(cleanKey);
528
+ if (isRecord(liveDs) && isRecord(liveDs.collectionManager) && isRawEsClientLike(liveDs.collectionManager.esClient)) {
529
+ return wrapEsClient(liveDs.collectionManager.esClient);
530
+ }
531
+ const repo = this.app.db.getRepository("dataSources");
532
+ const record = repo ? await repo.findOne({
533
+ filter: { key: cleanKey, type: "elasticsearch" }
534
+ }) : null;
535
+ if (!record) {
536
+ const existingCached = this.fallbackClients.get(cleanKey);
537
+ if (existingCached) {
538
+ return wrapEsClient(existingCached.client);
539
+ }
540
+ throw new Error(`Elasticsearch data source "${cleanKey}" was not found or is not loaded`);
541
+ }
542
+ const plain = typeof record.toJSON === "function" ? record.toJSON() : record;
543
+ const opts = extractConnectionOptions(isRecord(plain) ? plain.options : void 0);
544
+ const { endpointMode } = inferConnectionModes(opts);
545
+ if (endpointMode === "cloud") {
546
+ if (!toNonEmptyString(opts.cloudId)) {
547
+ throw new Error(`Elasticsearch data source "${cleanKey}" has no configured Cloud ID`);
548
+ }
549
+ } else if (!toNonEmptyString(opts.nodes)) {
550
+ throw new Error(`Elasticsearch data source "${cleanKey}" has no configured nodes`);
551
+ }
552
+ const signature = JSON.stringify(opts);
553
+ const cached = this.fallbackClients.get(cleanKey);
554
+ if (cached && cached.signature === signature) {
555
+ return wrapEsClient(cached.client);
556
+ }
557
+ if (cached) {
558
+ await cached.client.close().catch(() => void 0);
559
+ this.fallbackClients.delete(cleanKey);
560
+ }
561
+ const client = new import_elasticsearch.Client(buildEsClientOptions(opts));
562
+ this.fallbackClients.set(cleanKey, { signature, client });
563
+ return wrapEsClient(client);
564
+ }
565
+ }
566
+ // Annotate the CommonJS export names for ESM import in node:
567
+ 0 && (module.exports = {
568
+ ElasticsearchConnectionService,
569
+ buildEsClientOptions,
570
+ inferConnectionModes,
571
+ normalizeFieldCapabilitiesResponse
572
+ });