@objectstack/runtime 3.0.8 → 3.0.9

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @objectstack/runtime@3.0.8 build /home/runner/work/spec/spec/packages/runtime
2
+ > @objectstack/runtime@3.0.9 build /home/runner/work/spec/spec/packages/runtime
3
3
  > tsup --config ../../tsup.config.ts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist/index.cjs 47.63 KB
14
- CJS dist/index.cjs.map 104.13 KB
15
- CJS ⚡️ Build success in 117ms
16
- ESM dist/index.js 45.75 KB
17
- ESM dist/index.js.map 104.06 KB
18
- ESM ⚡️ Build success in 117ms
13
+ CJS dist/index.cjs 53.97 KB
14
+ CJS dist/index.cjs.map 116.68 KB
15
+ CJS ⚡️ Build success in 141ms
16
+ ESM dist/index.js 52.09 KB
17
+ ESM dist/index.js.map 116.61 KB
18
+ ESM ⚡️ Build success in 143ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 6114ms
21
- DTS dist/index.d.ts 19.94 KB
22
- DTS dist/index.d.cts 19.94 KB
20
+ DTS ⚡️ Build success in 7223ms
21
+ DTS dist/index.d.ts 20.49 KB
22
+ DTS dist/index.d.cts 20.49 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @objectstack/runtime
2
2
 
3
+ ## 3.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [15e0df6]
8
+ - @objectstack/spec@3.0.9
9
+ - @objectstack/core@3.0.9
10
+ - @objectstack/rest@3.0.9
11
+ - @objectstack/types@3.0.9
12
+
3
13
  ## 3.0.8
4
14
 
5
15
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -715,18 +715,93 @@ var HttpDispatcher = class {
715
715
  /**
716
716
  * Handles Automation requests
717
717
  * path: sub-path after /automation/
718
+ *
719
+ * Routes:
720
+ * GET / → listFlows
721
+ * GET /:name → getFlow
722
+ * POST / → createFlow (registerFlow)
723
+ * PUT /:name → updateFlow
724
+ * DELETE /:name → deleteFlow (unregisterFlow)
725
+ * POST /:name/trigger → execute (legacy: trigger/:name also supported)
726
+ * POST /:name/toggle → toggleFlow
727
+ * GET /:name/runs → listRuns
728
+ * GET /:name/runs/:runId → getRun
718
729
  */
719
- async handleAutomation(path, method, body, context) {
730
+ async handleAutomation(path, method, body, context, query) {
720
731
  const automationService = this.getService(import_system.CoreServiceName.enum.automation);
721
732
  if (!automationService) return { handled: false };
722
733
  const m = method.toUpperCase();
723
- const parts = path.replace(/^\/+/, "").split("/");
734
+ const parts = path.replace(/^\/+/, "").split("/").filter(Boolean);
724
735
  if (parts[0] === "trigger" && parts[1] && m === "POST") {
725
736
  const triggerName = parts[1];
726
737
  if (typeof automationService.trigger === "function") {
727
738
  const result = await automationService.trigger(triggerName, body, { request: context.request });
728
739
  return { handled: true, response: this.success(result) };
729
740
  }
741
+ if (typeof automationService.execute === "function") {
742
+ const result = await automationService.execute(triggerName, body);
743
+ return { handled: true, response: this.success(result) };
744
+ }
745
+ }
746
+ if (parts.length === 0 && m === "GET") {
747
+ if (typeof automationService.listFlows === "function") {
748
+ const names = await automationService.listFlows();
749
+ return { handled: true, response: this.success({ flows: names, total: names.length, hasMore: false }) };
750
+ }
751
+ }
752
+ if (parts.length === 0 && m === "POST") {
753
+ if (typeof automationService.registerFlow === "function") {
754
+ automationService.registerFlow(body?.name, body);
755
+ return { handled: true, response: this.success(body) };
756
+ }
757
+ }
758
+ if (parts.length >= 1) {
759
+ const name = parts[0];
760
+ if (parts[1] === "trigger" && m === "POST") {
761
+ if (typeof automationService.execute === "function") {
762
+ const result = await automationService.execute(name, body);
763
+ return { handled: true, response: this.success(result) };
764
+ }
765
+ }
766
+ if (parts[1] === "toggle" && m === "POST") {
767
+ if (typeof automationService.toggleFlow === "function") {
768
+ await automationService.toggleFlow(name, body?.enabled ?? true);
769
+ return { handled: true, response: this.success({ name, enabled: body?.enabled ?? true }) };
770
+ }
771
+ }
772
+ if (parts[1] === "runs" && parts[2] && m === "GET") {
773
+ if (typeof automationService.getRun === "function") {
774
+ const run = await automationService.getRun(parts[2]);
775
+ if (!run) return { handled: true, response: this.error("Execution not found", 404) };
776
+ return { handled: true, response: this.success(run) };
777
+ }
778
+ }
779
+ if (parts[1] === "runs" && !parts[2] && m === "GET") {
780
+ if (typeof automationService.listRuns === "function") {
781
+ const options = query ? { limit: query.limit ? Number(query.limit) : void 0, cursor: query.cursor } : void 0;
782
+ const runs = await automationService.listRuns(name, options);
783
+ return { handled: true, response: this.success({ runs, hasMore: false }) };
784
+ }
785
+ }
786
+ if (parts.length === 1 && m === "GET") {
787
+ if (typeof automationService.getFlow === "function") {
788
+ const flow = await automationService.getFlow(name);
789
+ if (!flow) return { handled: true, response: this.error("Flow not found", 404) };
790
+ return { handled: true, response: this.success(flow) };
791
+ }
792
+ }
793
+ if (parts.length === 1 && m === "PUT") {
794
+ if (typeof automationService.registerFlow === "function") {
795
+ automationService.registerFlow(name, body?.definition ?? body);
796
+ return { handled: true, response: this.success(body?.definition ?? body) };
797
+ }
798
+ }
799
+ if (parts.length === 1 && m === "DELETE") {
800
+ if (typeof automationService.unregisterFlow === "function") {
801
+ automationService.unregisterFlow(name);
802
+ return { handled: true, response: this.success({ name, deleted: true }) };
803
+ }
804
+ }
730
805
  }
731
806
  return { handled: false };
732
807
  }
@@ -801,7 +876,7 @@ var HttpDispatcher = class {
801
876
  return this.handleUi(cleanPath.substring(3), query, context);
802
877
  }
803
878
  if (cleanPath.startsWith("/automation")) {
804
- return this.handleAutomation(cleanPath.substring(11), method, body, context);
879
+ return this.handleAutomation(cleanPath.substring(11), method, body, context, query);
805
880
  }
806
881
  if (cleanPath.startsWith("/analytics")) {
807
882
  return this.handleAnalytics(cleanPath.substring(10), method, body, context);
@@ -1030,6 +1105,46 @@ function createDispatcherPlugin(config = {}) {
1030
1105
  errorResponse(err, res);
1031
1106
  }
1032
1107
  });
1108
+ server.get(`${prefix}/automation`, async (req, res) => {
1109
+ try {
1110
+ const result = await dispatcher.handleAutomation("", "GET", {}, { request: req });
1111
+ sendResult(result, res);
1112
+ } catch (err) {
1113
+ errorResponse(err, res);
1114
+ }
1115
+ });
1116
+ server.post(`${prefix}/automation`, async (req, res) => {
1117
+ try {
1118
+ const result = await dispatcher.handleAutomation("", "POST", req.body, { request: req });
1119
+ sendResult(result, res);
1120
+ } catch (err) {
1121
+ errorResponse(err, res);
1122
+ }
1123
+ });
1124
+ server.get(`${prefix}/automation/:name`, async (req, res) => {
1125
+ try {
1126
+ const result = await dispatcher.handleAutomation(`${req.params.name}`, "GET", {}, { request: req });
1127
+ sendResult(result, res);
1128
+ } catch (err) {
1129
+ errorResponse(err, res);
1130
+ }
1131
+ });
1132
+ server.put(`${prefix}/automation/:name`, async (req, res) => {
1133
+ try {
1134
+ const result = await dispatcher.handleAutomation(`${req.params.name}`, "PUT", req.body, { request: req });
1135
+ sendResult(result, res);
1136
+ } catch (err) {
1137
+ errorResponse(err, res);
1138
+ }
1139
+ });
1140
+ server.delete(`${prefix}/automation/:name`, async (req, res) => {
1141
+ try {
1142
+ const result = await dispatcher.handleAutomation(`${req.params.name}`, "DELETE", {}, { request: req });
1143
+ sendResult(result, res);
1144
+ } catch (err) {
1145
+ errorResponse(err, res);
1146
+ }
1147
+ });
1033
1148
  server.post(`${prefix}/automation/trigger/:name`, async (req, res) => {
1034
1149
  try {
1035
1150
  const result = await dispatcher.handleAutomation(`trigger/${req.params.name}`, "POST", req.body, { request: req });
@@ -1038,6 +1153,38 @@ function createDispatcherPlugin(config = {}) {
1038
1153
  errorResponse(err, res);
1039
1154
  }
1040
1155
  });
1156
+ server.post(`${prefix}/automation/:name/trigger`, async (req, res) => {
1157
+ try {
1158
+ const result = await dispatcher.handleAutomation(`${req.params.name}/trigger`, "POST", req.body, { request: req });
1159
+ sendResult(result, res);
1160
+ } catch (err) {
1161
+ errorResponse(err, res);
1162
+ }
1163
+ });
1164
+ server.post(`${prefix}/automation/:name/toggle`, async (req, res) => {
1165
+ try {
1166
+ const result = await dispatcher.handleAutomation(`${req.params.name}/toggle`, "POST", req.body, { request: req });
1167
+ sendResult(result, res);
1168
+ } catch (err) {
1169
+ errorResponse(err, res);
1170
+ }
1171
+ });
1172
+ server.get(`${prefix}/automation/:name/runs`, async (req, res) => {
1173
+ try {
1174
+ const result = await dispatcher.handleAutomation(`${req.params.name}/runs`, "GET", {}, { request: req }, req.query);
1175
+ sendResult(result, res);
1176
+ } catch (err) {
1177
+ errorResponse(err, res);
1178
+ }
1179
+ });
1180
+ server.get(`${prefix}/automation/:name/runs/:runId`, async (req, res) => {
1181
+ try {
1182
+ const result = await dispatcher.handleAutomation(`${req.params.name}/runs/${req.params.runId}`, "GET", {}, { request: req });
1183
+ sendResult(result, res);
1184
+ } catch (err) {
1185
+ errorResponse(err, res);
1186
+ }
1187
+ });
1041
1188
  ctx.logger.info("Dispatcher bridge routes registered", { prefix });
1042
1189
  }
1043
1190
  };