@oas-tools/oas-telemetry 0.7.1 → 0.8.0-alpha.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 (167) hide show
  1. package/.env.example +21 -2
  2. package/README.md +1 -2
  3. package/dist/cjs/config/bootConfig.cjs +19 -14
  4. package/dist/cjs/config/config.cjs +112 -125
  5. package/dist/cjs/config/config.types.cjs +1 -4
  6. package/dist/cjs/docs/openapi.yaml +158 -4
  7. package/dist/cjs/index.cjs +27 -30
  8. package/dist/cjs/routesManager.cjs +62 -70
  9. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbLogExporter.cjs +202 -190
  10. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.cjs +204 -99
  11. package/dist/cjs/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.cjs +152 -116
  12. package/dist/cjs/telemetry/custom-implementations/instrumentations/logsInstrumentation.cjs +92 -0
  13. package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/Chunk.cjs +159 -0
  14. package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/Series.cjs +168 -0
  15. package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/SeriesRegistry.cjs +389 -0
  16. package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/types.cjs +2 -0
  17. package/dist/cjs/telemetry/custom-implementations/metrics/tsdb/utils.cjs +77 -0
  18. package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.cjs +65 -63
  19. package/dist/cjs/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.cjs +63 -62
  20. package/dist/cjs/telemetry/custom-implementations/utils/circular.cjs +47 -47
  21. package/dist/cjs/telemetry/custom-implementations/utils/storagePath.cjs +39 -0
  22. package/dist/cjs/telemetry/custom-implementations/wrappers.cjs +141 -138
  23. package/dist/cjs/telemetry/initializeTelemetry.cjs +35 -91
  24. package/dist/cjs/telemetry/telemetryConfigurator.cjs +70 -72
  25. package/dist/cjs/telemetry/telemetryRegistry.cjs +45 -31
  26. package/dist/cjs/tlm-ai/agent.cjs +49 -64
  27. package/dist/cjs/tlm-ai/aiController.cjs +54 -76
  28. package/dist/cjs/tlm-ai/aiRoutes.cjs +17 -20
  29. package/dist/cjs/tlm-ai/aiService.cjs +91 -95
  30. package/dist/cjs/tlm-ai/tools.cjs +177 -174
  31. package/dist/cjs/tlm-auth/authController.cjs +80 -123
  32. package/dist/cjs/tlm-auth/authMiddleware.cjs +25 -30
  33. package/dist/cjs/tlm-auth/authRoutes.cjs +11 -14
  34. package/dist/cjs/tlm-log/logController.cjs +171 -116
  35. package/dist/cjs/tlm-log/logRoutes.cjs +20 -20
  36. package/dist/cjs/tlm-metric/metricsController.cjs +211 -121
  37. package/dist/cjs/tlm-metric/metricsRoutes.cjs +23 -20
  38. package/dist/cjs/tlm-plugin/pluginController.cjs +128 -140
  39. package/dist/cjs/tlm-plugin/pluginProcess.cjs +89 -94
  40. package/dist/cjs/tlm-plugin/pluginRoutes.cjs +11 -14
  41. package/dist/cjs/tlm-plugin/pluginService.cjs +73 -74
  42. package/dist/cjs/tlm-trace/traceController.cjs +169 -117
  43. package/dist/cjs/tlm-trace/traceRoutes.cjs +20 -20
  44. package/dist/cjs/tlm-ui/uiRoutes.cjs +63 -32
  45. package/dist/cjs/tlm-util/utilController.cjs +68 -70
  46. package/dist/cjs/tlm-util/utilRoutes.cjs +51 -63
  47. package/dist/cjs/types/index.cjs +2 -5
  48. package/dist/cjs/utils/logger.cjs +38 -43
  49. package/dist/cjs/utils/regexUtils.cjs +22 -22
  50. package/dist/esm/config/bootConfig.js +6 -0
  51. package/dist/esm/config/config.js +1 -2
  52. package/dist/esm/docs/openapi.yaml +158 -4
  53. package/dist/esm/index.js +9 -8
  54. package/dist/esm/routesManager.js +6 -10
  55. package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbLogExporter.js +47 -8
  56. package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.js +164 -48
  57. package/dist/esm/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.js +69 -29
  58. package/dist/esm/telemetry/custom-implementations/instrumentations/logsInstrumentation.js +85 -0
  59. package/dist/esm/telemetry/custom-implementations/metrics/tsdb/Chunk.js +155 -0
  60. package/dist/esm/telemetry/custom-implementations/metrics/tsdb/Series.js +164 -0
  61. package/dist/esm/telemetry/custom-implementations/metrics/tsdb/SeriesRegistry.js +382 -0
  62. package/dist/esm/telemetry/custom-implementations/metrics/tsdb/types.js +1 -0
  63. package/dist/esm/telemetry/custom-implementations/metrics/tsdb/utils.js +74 -0
  64. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.js +2 -1
  65. package/dist/esm/telemetry/custom-implementations/processors/dynamicMultiSpanProcessor.js +1 -1
  66. package/dist/esm/telemetry/custom-implementations/utils/storagePath.js +33 -0
  67. package/dist/esm/telemetry/custom-implementations/wrappers.js +5 -2
  68. package/dist/esm/telemetry/initializeTelemetry.js +27 -69
  69. package/dist/esm/telemetry/telemetryConfigurator.js +42 -40
  70. package/dist/esm/telemetry/telemetryRegistry.js +12 -1
  71. package/dist/esm/tlm-ai/agent.js +5 -3
  72. package/dist/esm/tlm-ai/aiController.js +3 -3
  73. package/dist/esm/tlm-ai/aiService.js +6 -2
  74. package/dist/esm/tlm-ai/tools.js +5 -9
  75. package/dist/esm/tlm-auth/authController.js +3 -2
  76. package/dist/esm/tlm-log/logController.js +84 -4
  77. package/dist/esm/tlm-log/logRoutes.js +5 -2
  78. package/dist/esm/tlm-metric/metricsController.js +172 -49
  79. package/dist/esm/tlm-metric/metricsRoutes.js +10 -4
  80. package/dist/esm/tlm-plugin/pluginController.js +6 -11
  81. package/dist/esm/tlm-plugin/pluginService.js +2 -4
  82. package/dist/esm/tlm-trace/traceController.js +102 -16
  83. package/dist/esm/tlm-trace/traceRoutes.js +5 -2
  84. package/dist/esm/tlm-ui/uiRoutes.js +5 -5
  85. package/dist/esm/tlm-util/utilController.js +3 -9
  86. package/dist/esm/tlm-util/utilRoutes.js +2 -2
  87. package/dist/types/config/bootConfig.d.ts +4 -0
  88. package/dist/types/config/config.d.ts +36 -7
  89. package/dist/types/config/config.types.d.ts +6 -0
  90. package/dist/types/index.d.ts +2 -3
  91. package/dist/types/telemetry/custom-implementations/exporters/InMemoryDbLogExporter.d.ts +4 -1
  92. package/dist/types/telemetry/custom-implementations/exporters/InMemoryDbMetricExporter.d.ts +60 -15
  93. package/dist/types/telemetry/custom-implementations/exporters/InMemoryDbSpanExporter.d.ts +9 -4
  94. package/dist/types/telemetry/custom-implementations/instrumentations/logsInstrumentation.d.ts +23 -0
  95. package/dist/types/telemetry/custom-implementations/metrics/tsdb/Chunk.d.ts +49 -0
  96. package/dist/types/telemetry/custom-implementations/metrics/tsdb/Series.d.ts +67 -0
  97. package/dist/types/telemetry/custom-implementations/metrics/tsdb/SeriesRegistry.d.ts +69 -0
  98. package/dist/types/telemetry/custom-implementations/metrics/tsdb/types.d.ts +68 -0
  99. package/dist/types/telemetry/custom-implementations/metrics/tsdb/utils.d.ts +21 -0
  100. package/dist/types/telemetry/custom-implementations/processors/dynamicMultiLogProcessor.d.ts +2 -2
  101. package/dist/types/telemetry/custom-implementations/utils/storagePath.d.ts +12 -0
  102. package/dist/types/telemetry/custom-implementations/wrappers.d.ts +1 -1
  103. package/dist/types/telemetry/telemetryConfigurator.d.ts +1 -1
  104. package/dist/types/telemetry/telemetryRegistry.d.ts +8 -0
  105. package/dist/types/tlm-ai/agent.d.ts +1 -1
  106. package/dist/types/tlm-ai/aiService.d.ts +1 -1
  107. package/dist/types/tlm-log/logController.d.ts +2 -0
  108. package/dist/types/tlm-metric/metricsController.d.ts +16 -2
  109. package/dist/types/tlm-trace/traceController.d.ts +3 -1
  110. package/dist/types/types/index.d.ts +2 -2
  111. package/dist/ui/assets/{ApiDocsPage-C_VVPPHa.js → ApiDocsPage-BFUrXE5F.js} +2 -2
  112. package/dist/ui/assets/CollapsibleCard-STA1GVQO.js +1 -0
  113. package/dist/ui/assets/DevToolsPage-BRSfZqO_.js +1 -0
  114. package/dist/ui/assets/LandingPage-DzeDy7q7.js +6 -0
  115. package/dist/ui/assets/LogsPage-BeiFrV2X.js +1 -0
  116. package/dist/ui/assets/{NotFoundPage-B3quk3P1.js → NotFoundPage-fRNOatbM.js} +1 -1
  117. package/dist/ui/assets/PluginCreatePage-Ch_RXsdf.js +50 -0
  118. package/dist/ui/assets/PluginPage-Cl65ZZ_n.js +27 -0
  119. package/dist/ui/assets/TraceSpansPage-BoK4M5Hh.js +6 -0
  120. package/dist/ui/assets/VirtualizedListPanel-zcj0v7DL.js +16 -0
  121. package/dist/ui/assets/alert-BkNVKxJN.js +1133 -0
  122. package/dist/ui/assets/badge-CN7FeufU.js +1 -0
  123. package/dist/ui/assets/{chevron-down-CPsvsmqj.js → chevron-down-CG--ounh.js} +1 -1
  124. package/dist/ui/assets/{chevron-up-Df9jMo1X.js → chevron-up-B6tzMAOm.js} +1 -1
  125. package/dist/ui/assets/{circle-alert-DOPQPvU8.js → circle-alert-BDF8Tq9y.js} +1 -1
  126. package/dist/ui/assets/dialog-BrpWNk36.js +15 -0
  127. package/dist/ui/assets/index-6xOVKwKn.js +305 -0
  128. package/dist/ui/assets/index-D6f1KjWV.css +1 -0
  129. package/dist/ui/assets/index-D96rVSkR.js +1 -0
  130. package/dist/ui/assets/info-99kuqpbx.js +6 -0
  131. package/dist/ui/assets/{input-Dzvg_ZEZ.js → input-B-01QDg_.js} +1 -1
  132. package/dist/ui/assets/label-CQLeZjM1.js +1 -0
  133. package/dist/ui/assets/{loader-circle-CrvlRy5o.js → loader-circle-BoDGk-BO.js} +1 -1
  134. package/dist/ui/assets/{loginPage-qa4V-B70.js → loginPage-8F4EEd1B.js} +1 -1
  135. package/dist/ui/assets/metrics-page-D1GxaB_c.css +1 -0
  136. package/dist/ui/assets/metrics-page-DPtteXqY.js +31 -0
  137. package/dist/ui/assets/popover-DS_8DYYt.js +11 -0
  138. package/dist/ui/assets/select-DYjegiXi.js +6 -0
  139. package/dist/ui/assets/separator-DGsRxIrl.js +6 -0
  140. package/dist/ui/assets/severityOptions-DEOvJqC9.js +11 -0
  141. package/dist/ui/assets/square-pen-DPhgYz6O.js +6 -0
  142. package/dist/ui/assets/switch-Di9NJH2A.js +1 -0
  143. package/dist/ui/assets/trace-DJq1miYa.js +1 -0
  144. package/dist/ui/assets/upload-BiLTpCnX.js +11 -0
  145. package/dist/ui/assets/{utilService-DNyqzwj0.js → utilService-CNZOmadC.js} +1 -1
  146. package/dist/ui/assets/wand-sparkles-CPoBNFFg.js +6 -0
  147. package/dist/ui/index.html +2 -2
  148. package/package.json +44 -48
  149. package/dist/ui/assets/CollapsibleCard-B3KR_8mL.js +0 -1
  150. package/dist/ui/assets/DevToolsPage-OyZcDcmw.js +0 -1
  151. package/dist/ui/assets/LandingPage-CppFBA6K.js +0 -6
  152. package/dist/ui/assets/LogsPage-9Fq8GArS.js +0 -26
  153. package/dist/ui/assets/PluginCreatePage-X_aCH4t4.js +0 -50
  154. package/dist/ui/assets/PluginPage-DMDSihrZ.js +0 -27
  155. package/dist/ui/assets/alert-jQ9HCPIf.js +0 -1133
  156. package/dist/ui/assets/badge-CNq0-mH5.js +0 -1
  157. package/dist/ui/assets/card-DFAwwhN3.js +0 -1
  158. package/dist/ui/assets/index-BkD6DijD.js +0 -15
  159. package/dist/ui/assets/index-CERGVYZK.js +0 -292
  160. package/dist/ui/assets/index-CSIPf9qw.css +0 -1
  161. package/dist/ui/assets/label-DuVnkZ4q.js +0 -1
  162. package/dist/ui/assets/select-DhS8YUtJ.js +0 -1
  163. package/dist/ui/assets/separator-isK4chBP.js +0 -6
  164. package/dist/ui/assets/severityOptions-O38dSOfk.js +0 -11
  165. package/dist/ui/assets/switch-Z3mImG9n.js +0 -1
  166. package/dist/ui/assets/tabs-_77MUUQe.js +0 -16
  167. package/dist/ui/assets/upload-C1LT4Gkb.js +0 -16
@@ -1,157 +1,145 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.registerPlugin = exports.listPlugins = exports.deletePlugin = exports.deactivatePlugin = exports.activatePlugin = void 0;
7
- var _axios = _interopRequireDefault(require("axios"));
8
- var _child_process = require("child_process");
9
- var _path = _interopRequireDefault(require("path"));
10
- var _logger = _interopRequireDefault(require("../utils/logger.cjs"));
11
- var _pluginService = require("./pluginService.cjs");
12
- var _url = require("url");
13
- const _excluded = ["process"];
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
16
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deletePlugin = exports.deactivatePlugin = exports.activatePlugin = exports.registerPlugin = exports.listPlugins = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const child_process_1 = require("child_process");
9
+ const path_1 = __importDefault(require("path"));
10
+ const logger_js_1 = __importDefault(require("../utils/logger.cjs"));
11
+ const pluginService_js_1 = require("./pluginService.cjs");
12
+ const url_1 = require("url");
17
13
  const listPlugins = (req, res) => {
18
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
- const plugins = _pluginService.pluginService.getPlugins().map(_ref => {
20
- let {
21
- process
22
- } = _ref,
23
- rest = _objectWithoutProperties(_ref, _excluded);
24
- return rest;
25
- });
26
- res.send({
27
- pluginsCount: plugins.length,
28
- plugins
29
- });
14
+ const plugins = pluginService_js_1.pluginService.getPlugins().map(({ process, ...rest }) => rest);
15
+ res.send({
16
+ pluginsCount: plugins.length,
17
+ plugins,
18
+ });
30
19
  };
31
20
  exports.listPlugins = listPlugins;
32
21
  const registerPlugin = async (req, res) => {
33
- const pluginResource = req.body;
34
- _logger.default.debug(`Plugin Registration Request: ${JSON.stringify(req.body, null, 2)}...`);
35
- // Validate id
36
- if (!pluginResource.id || typeof pluginResource.id !== "string") {
37
- res.status(400).send("Plugin id must be provided and must be a string");
38
- return;
39
- }
40
- // Check duplicate
41
- if (_pluginService.pluginService.getPlugins().find(p => p.id === pluginResource.id)) {
42
- res.status(400).send(`Plugin with id "${pluginResource.id}" already exists.`);
43
- return;
44
- }
45
- // Validate inputs
46
- if (!pluginResource.url && !pluginResource.code) {
47
- res.status(400).send("Plugin code or URL must be provided");
48
- return;
49
- }
50
- if (!pluginResource.moduleFormat) {
51
- res.status(400).send("Plugin moduleFormat must be provided (cjs|esm)");
52
- return;
53
- }
54
- // Fetch code
55
- let pluginCode;
56
- try {
57
- if (pluginResource.code) {
58
- pluginCode = pluginResource.code;
59
- } else {
60
- console.log(pluginResource.url);
61
- const response = await _axios.default.get(pluginResource.url);
62
- pluginCode = response.data;
22
+ const pluginResource = req.body;
23
+ logger_js_1.default.debug(`Plugin Registration Request: ${JSON.stringify(req.body, null, 2)}...`);
24
+ // Validate id
25
+ if (!pluginResource.id || typeof pluginResource.id !== "string") {
26
+ res.status(400).send("Plugin id must be provided and must be a string");
27
+ return;
28
+ }
29
+ // Check duplicate
30
+ if (pluginService_js_1.pluginService.getPlugins().find((p) => p.id === pluginResource.id)) {
31
+ res.status(400).send(`Plugin with id "${pluginResource.id}" already exists.`);
32
+ return;
33
+ }
34
+ // Validate inputs
35
+ if (!pluginResource.url && !pluginResource.code) {
36
+ res.status(400).send("Plugin code or URL must be provided");
37
+ return;
38
+ }
39
+ if (!pluginResource.moduleFormat) {
40
+ res.status(400).send("Plugin moduleFormat must be provided (cjs|esm)");
41
+ return;
42
+ }
43
+ // Fetch code
44
+ let pluginCode;
45
+ try {
46
+ if (pluginResource.code) {
47
+ pluginCode = pluginResource.code;
48
+ }
49
+ else {
50
+ console.log(pluginResource.url);
51
+ const response = await axios_1.default.get(pluginResource.url);
52
+ pluginCode = response.data;
53
+ }
54
+ pluginResource.sourceCode = pluginCode;
63
55
  }
64
- pluginResource.sourceCode = pluginCode;
65
- } catch (err) {
66
- res.status(400).send(`Error fetching plugin code: ${err}`);
67
- return;
68
- }
69
- if (!pluginCode) {
70
- res.status(400).send("Plugin code could not be loaded");
71
- return;
72
- }
73
- const isCjs = typeof __filename !== "undefined" && typeof __dirname !== "undefined";
74
- const __filenameUniversal = isCjs ? __filename : (0, _url.fileURLToPath)(require('url').pathToFileURL(__filename).toString());
75
- const __dirnameUniversal = isCjs ? __dirname : _path.default.dirname(__filenameUniversal);
76
- const pluginProcessFile = isCjs ? "pluginProcess.cjs" : "pluginProcess.js";
77
- const child = (0, _child_process.fork)(_path.default.resolve(__dirnameUniversal, pluginProcessFile), [], {
78
- stdio: ["pipe", "pipe", "pipe", "ipc"]
79
- });
80
- child.stdout?.on("data", data => {
81
- _logger.default.info(`[Plugin ${pluginResource.id}] STDOUT: ${data.toString().trim()}`);
82
- });
83
- child.stderr?.on("data", data => {
84
- _logger.default.error(`[Plugin ${pluginResource.id}] STDERR: ${data.toString().trim()}`);
85
- });
86
- child.on("message", msg => {
87
- if (msg.event === "loaded") {
88
- pluginResource.name = msg.name;
89
- pluginResource.active = true;
90
- pluginResource.process = child;
91
- _pluginService.pluginService.pushPlugin(pluginResource);
92
- res.status(201).send(`Plugin ${msg.name} registered`);
93
- } else if (msg.event === "error") {
94
- res.status(400).send(`Error loading plugin: ${msg.error}`);
56
+ catch (err) {
57
+ res.status(400).send(`Error fetching plugin code: ${err}`);
58
+ return;
95
59
  }
96
- });
97
- child.on("exit", code => {
98
- pluginResource.active = false;
99
- pluginResource.process = undefined;
100
- _logger.default.warn(`Plugin ${pluginResource.id} exited (code: ${code})`);
101
- });
102
- child.on("disconnect", () => {
103
- pluginResource.active = false;
104
- pluginResource.process = undefined;
105
- _logger.default.warn(`Plugin ${pluginResource.id} disconnected`);
106
- });
107
- child.on("error", err => {
108
- pluginResource.active = false;
109
- pluginResource.process = undefined;
110
- _logger.default.error(`Plugin ${pluginResource.id} error: ${err.message}`);
111
- });
112
- // Send data to child
113
- child.send({
114
- type: "load",
115
- pluginResource
116
- });
60
+ if (!pluginCode) {
61
+ res.status(400).send("Plugin code could not be loaded");
62
+ return;
63
+ }
64
+ const isCjs = typeof __filename !== "undefined" && typeof __dirname !== "undefined";
65
+ // @ts-ignore -- import.meta no existe en el build CJS
66
+ const currentDirectory = isCjs ? __dirname : path_1.default.dirname((0, url_1.fileURLToPath)(__filename));
67
+ const pluginProcessFile = isCjs
68
+ ? "pluginProcess.cjs"
69
+ : "pluginProcess.cjs";
70
+ const child = (0, child_process_1.fork)(path_1.default.resolve(currentDirectory, pluginProcessFile), [], {
71
+ stdio: ["pipe", "pipe", "pipe", "ipc"],
72
+ });
73
+ child.stdout?.on("data", (data) => {
74
+ logger_js_1.default.info(`[Plugin ${pluginResource.id}] STDOUT: ${data.toString().trim()}`);
75
+ });
76
+ child.stderr?.on("data", (data) => {
77
+ logger_js_1.default.error(`[Plugin ${pluginResource.id}] STDERR: ${data.toString().trim()}`);
78
+ });
79
+ child.on("message", (msg) => {
80
+ if (msg.event === "loaded") {
81
+ pluginResource.name = msg.name;
82
+ pluginResource.active = true;
83
+ pluginResource.process = child;
84
+ pluginService_js_1.pluginService.pushPlugin(pluginResource);
85
+ res.status(201).send(`Plugin ${msg.name} registered`);
86
+ }
87
+ else if (msg.event === "error") {
88
+ res.status(400).send(`Error loading plugin: ${msg.error}`);
89
+ }
90
+ });
91
+ child.on("exit", (code) => {
92
+ pluginResource.active = false;
93
+ pluginResource.process = undefined;
94
+ logger_js_1.default.warn(`Plugin ${pluginResource.id} exited (code: ${code})`);
95
+ });
96
+ child.on("disconnect", () => {
97
+ pluginResource.active = false;
98
+ pluginResource.process = undefined;
99
+ logger_js_1.default.warn(`Plugin ${pluginResource.id} disconnected`);
100
+ });
101
+ child.on("error", (err) => {
102
+ pluginResource.active = false;
103
+ pluginResource.process = undefined;
104
+ logger_js_1.default.error(`Plugin ${pluginResource.id} error: ${err.message}`);
105
+ });
106
+ // Send data to child
107
+ child.send({
108
+ type: "load",
109
+ pluginResource,
110
+ });
117
111
  };
118
112
  exports.registerPlugin = registerPlugin;
119
113
  const activatePlugin = (req, res) => {
120
- const {
121
- id
122
- } = req.params;
123
- const plugin = _pluginService.pluginService.getPlugins().find(p => p.id === id);
124
- if (!plugin) {
125
- res.status(404).send(`Plugin with id "${id}" not found.`);
126
- return;
127
- }
128
- _pluginService.pluginService.activatePlugin(id);
129
- res.status(200).send(`Plugin "${id}" activated.`);
114
+ const id = req.params.id;
115
+ const plugin = pluginService_js_1.pluginService.getPlugins().find((p) => p.id === id);
116
+ if (!plugin) {
117
+ res.status(404).send(`Plugin with id "${id}" not found.`);
118
+ return;
119
+ }
120
+ pluginService_js_1.pluginService.activatePlugin(id);
121
+ res.status(200).send(`Plugin "${id}" activated.`);
130
122
  };
131
123
  exports.activatePlugin = activatePlugin;
132
124
  const deactivatePlugin = (req, res) => {
133
- const {
134
- id
135
- } = req.params;
136
- const plugin = _pluginService.pluginService.getPlugins().find(p => p.id === id);
137
- if (!plugin) {
138
- res.status(404).send(`Plugin with id "${id}" not found.`);
139
- return;
140
- }
141
- _pluginService.pluginService.deactivatePlugin(id); // This only sets active to false
142
- res.status(200).send(`Plugin "${id}" deactivated.`);
125
+ const id = req.params.id;
126
+ const plugin = pluginService_js_1.pluginService.getPlugins().find((p) => p.id === id);
127
+ if (!plugin) {
128
+ res.status(404).send(`Plugin with id "${id}" not found.`);
129
+ return;
130
+ }
131
+ pluginService_js_1.pluginService.deactivatePlugin(id); // This only sets active to false
132
+ res.status(200).send(`Plugin "${id}" deactivated.`);
143
133
  };
144
134
  exports.deactivatePlugin = deactivatePlugin;
145
135
  const deletePlugin = (req, res) => {
146
- const {
147
- id
148
- } = req.params;
149
- const plugin = _pluginService.pluginService.getPlugins().find(p => p.id === id);
150
- if (!plugin) {
151
- res.status(404).send(`Plugin with id "${id}" not found.`);
152
- return;
153
- }
154
- _pluginService.pluginService.deletePlugin(id); // kills child inside service
155
- res.status(200).send(`Plugin "${id}" deleted.`);
136
+ const id = req.params.id;
137
+ const plugin = pluginService_js_1.pluginService.getPlugins().find((p) => p.id === id);
138
+ if (!plugin) {
139
+ res.status(404).send(`Plugin with id "${id}" not found.`);
140
+ return;
141
+ }
142
+ pluginService_js_1.pluginService.deletePlugin(id); // kills child inside service
143
+ res.status(200).send(`Plugin "${id}" deleted.`);
156
144
  };
157
- exports.deletePlugin = deletePlugin;
145
+ exports.deletePlugin = deletePlugin;
@@ -1,110 +1,105 @@
1
1
  "use strict";
2
-
3
- var _importFromString = require("import-from-string");
4
- var _dynamicInstaller = require("dynamic-installer");
5
2
  // pluginProcess.js
6
3
  // Runs inside a child process, isolated from the main app
4
+ Object.defineProperty(exports, "__esModule", { value: true });
7
5
  // @ts-expect-error no types
8
-
6
+ const import_from_string_1 = require("import-from-string");
7
+ const dynamic_installer_1 = require("dynamic-installer");
9
8
  let plugin;
10
9
  const log = (...args) => {
11
- console.log(`[PluginProcess:${process.pid}]`, ...args);
10
+ console.log(`[PluginProcess:${process.pid}]`, ...args);
12
11
  };
13
- process.on("message", async msg => {
14
- if (msg.type === "load") {
15
- try {
16
- const pluginResource = normalizePluginResource(msg.pluginResource);
17
- if (pluginResource.install && Array.isArray(pluginResource.install.dependencies) && pluginResource.install.dependencies.length > 0) {
18
- log("Installing dependencies for plugin: " + pluginResource.name);
19
- const dependenciesStatus = await (0, _dynamicInstaller.installDependencies)(pluginResource.install);
20
- console.dir(dependenciesStatus);
21
- if (!dependenciesStatus.success) {
22
- const detailsFailed = dependenciesStatus.details.filter(detail => detail.success === false);
23
- if (pluginResource.install.ignoreErrors === true) {
24
- log(`Warning: Error installing dependencies: ${JSON.stringify(detailsFailed)}. Continuing as ignoreErrors is true.`);
25
- } else {
26
- process.send?.({
27
- event: "error",
28
- error: `Error installing dependencies: ${JSON.stringify(detailsFailed)}`
29
- });
30
- return;
31
- }
12
+ process.on("message", async (msg) => {
13
+ if (msg.type === "load") {
14
+ try {
15
+ const pluginResource = normalizePluginResource(msg.pluginResource);
16
+ if (pluginResource.install && Array.isArray(pluginResource.install.dependencies) && pluginResource.install.dependencies.length > 0) {
17
+ log("Installing dependencies for plugin: " + pluginResource.name);
18
+ const dependenciesStatus = await (0, dynamic_installer_1.installDependencies)(pluginResource.install);
19
+ console.dir(dependenciesStatus);
20
+ if (!dependenciesStatus.success) {
21
+ const detailsFailed = dependenciesStatus.details.filter(detail => detail.success === false);
22
+ if (pluginResource.install.ignoreErrors === true) {
23
+ log(`Warning: Error installing dependencies: ${JSON.stringify(detailsFailed)}. Continuing as ignoreErrors is true.`);
24
+ }
25
+ else {
26
+ process.send?.({ event: "error", error: `Error installing dependencies: ${JSON.stringify(detailsFailed)}` });
27
+ return;
28
+ }
29
+ }
30
+ }
31
+ let module;
32
+ if (pluginResource?.moduleFormat?.toLowerCase() === "esm") {
33
+ module = await (0, import_from_string_1.importFromString)(pluginResource.sourceCode);
34
+ }
35
+ else {
36
+ module = await (0, import_from_string_1.requireFromString)(pluginResource.sourceCode);
37
+ }
38
+ plugin = module.default?.plugin ?? module.plugin;
39
+ if (!plugin)
40
+ throw new Error("Plugin must export a valid 'plugin' object");
41
+ for (const fn of ["load", "isConfigured"]) {
42
+ if (typeof plugin[fn] !== "function") {
43
+ throw new Error(`Plugin is missing required function "${fn}"`);
44
+ }
45
+ }
46
+ await plugin.load(pluginResource.config);
47
+ if (!plugin.isConfigured()) {
48
+ throw new Error("Plugin could not be configured");
49
+ }
50
+ process.send?.({ event: "loaded", name: pluginResource.name || pluginResource.id || "unknown" });
32
51
  }
33
- }
34
- let module;
35
- if (pluginResource?.moduleFormat?.toLowerCase() === "esm") {
36
- module = await (0, _importFromString.importFromString)(pluginResource.sourceCode);
37
- } else {
38
- module = await (0, _importFromString.requireFromString)(pluginResource.sourceCode);
39
- }
40
- plugin = module.default?.plugin ?? module.plugin;
41
- if (!plugin) throw new Error("Plugin must export a valid 'plugin' object");
42
- for (const fn of ["load", "isConfigured"]) {
43
- if (typeof plugin[fn] !== "function") {
44
- throw new Error(`Plugin is missing required function "${fn}"`);
52
+ catch (err) {
53
+ process.send?.({ event: "error", error: err.message });
54
+ process.exit(1);
45
55
  }
46
- }
47
- await plugin.load(pluginResource.config);
48
- if (!plugin.isConfigured()) {
49
- throw new Error("Plugin could not be configured");
50
- }
51
- process.send?.({
52
- event: "loaded",
53
- name: pluginResource.name || pluginResource.id || "unknown"
54
- });
55
- } catch (err) {
56
- process.send?.({
57
- event: "error",
58
- error: err.message
59
- });
60
- process.exit(1);
61
56
  }
62
- }
63
- // Forward log/metric/trace calls
64
- if (msg.type === "newLog" && plugin?.newLog) {
65
- plugin.newLog(msg.payload);
66
- }
67
- if (msg.type === "newMetric" && plugin?.newMetric) {
68
- plugin.newMetric(msg.payload);
69
- }
70
- if (msg.type === "newTrace" && plugin?.newTrace) {
71
- plugin.newTrace(msg.payload);
72
- }
73
- if (msg.type === "unload") {
74
- if (plugin && typeof plugin.unload === "function") {
75
- await plugin.unload();
57
+ // Forward log/metric/trace calls
58
+ if (msg.type === "newLog" && plugin?.newLog) {
59
+ plugin.newLog(msg.payload);
60
+ }
61
+ if (msg.type === "newMetric" && plugin?.newMetric) {
62
+ plugin.newMetric(msg.payload);
63
+ }
64
+ if (msg.type === "newTrace" && plugin?.newTrace) {
65
+ plugin.newTrace(msg.payload);
66
+ }
67
+ if (msg.type === "unload") {
68
+ if (plugin && typeof plugin.unload === "function") {
69
+ await plugin.unload();
70
+ }
71
+ process.send?.({ event: "unloaded" });
72
+ process.exit(0);
76
73
  }
77
- process.send?.({
78
- event: "unloaded"
79
- });
80
- process.exit(0);
81
- }
82
74
  });
83
75
  function normalizePluginResource(raw) {
84
- let resource = raw;
85
- // case: received as stringified JSON
86
- if (typeof raw === "string") {
87
- try {
88
- resource = JSON.parse(raw);
89
- } catch (err) {
90
- throw new Error("Invalid pluginResource JSON: " + err.message);
76
+ let resource = raw;
77
+ // case: received as stringified JSON
78
+ if (typeof raw === "string") {
79
+ try {
80
+ resource = JSON.parse(raw);
81
+ }
82
+ catch (err) {
83
+ throw new Error("Invalid pluginResource JSON: " + err.message);
84
+ }
91
85
  }
92
- }
93
- // normalize install
94
- if (typeof resource.install === "string") {
95
- try {
96
- resource.install = JSON.parse(resource.install);
97
- } catch (err) {
98
- throw new Error("Invalid install JSON: " + err.message);
86
+ // normalize install
87
+ if (typeof resource.install === "string") {
88
+ try {
89
+ resource.install = JSON.parse(resource.install);
90
+ }
91
+ catch (err) {
92
+ throw new Error("Invalid install JSON: " + err.message);
93
+ }
99
94
  }
100
- }
101
- // normalize config
102
- if (typeof resource.config === "string") {
103
- try {
104
- resource.config = JSON.parse(resource.config);
105
- } catch (err) {
106
- throw new Error("Invalid config JSON: " + err.message);
95
+ // normalize config
96
+ if (typeof resource.config === "string") {
97
+ try {
98
+ resource.config = JSON.parse(resource.config);
99
+ }
100
+ catch (err) {
101
+ throw new Error("Invalid config JSON: " + err.message);
102
+ }
107
103
  }
108
- }
109
- return resource;
110
- }
104
+ return resource;
105
+ }
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getPluginRoutes = void 0;
7
- var _express = require("express");
8
- var _pluginController = require("./pluginController.cjs");
4
+ const express_1 = require("express");
5
+ const pluginController_js_1 = require("./pluginController.cjs");
9
6
  const getPluginRoutes = () => {
10
- const router = (0, _express.Router)();
11
- router.get('/', _pluginController.listPlugins);
12
- router.post('/', _pluginController.registerPlugin);
13
- router.post('/:id/activate', _pluginController.activatePlugin);
14
- router.post('/:id/deactivate', _pluginController.deactivatePlugin);
15
- router.delete('/:id', _pluginController.deletePlugin);
16
- return router;
7
+ const router = (0, express_1.Router)();
8
+ router.get('/', pluginController_js_1.listPlugins);
9
+ router.post('/', pluginController_js_1.registerPlugin);
10
+ router.post('/:id/activate', pluginController_js_1.activatePlugin);
11
+ router.post('/:id/deactivate', pluginController_js_1.deactivatePlugin);
12
+ router.delete('/:id', pluginController_js_1.deletePlugin);
13
+ return router;
17
14
  };
18
- exports.getPluginRoutes = getPluginRoutes;
15
+ exports.getPluginRoutes = getPluginRoutes;