@objectstack/runtime 3.0.7 → 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.
package/dist/index.d.ts CHANGED
@@ -111,7 +111,7 @@ interface DispatcherPluginConfig {
111
111
  * - /packages (package management)
112
112
 
113
113
  * - /storage (file storage)
114
- * - /automation (triggers)
114
+ * - /automation (CRUD + triggers + runs)
115
115
  *
116
116
  * Usage:
117
117
  * ```ts
@@ -513,8 +513,19 @@ declare class HttpDispatcher {
513
513
  /**
514
514
  * Handles Automation requests
515
515
  * path: sub-path after /automation/
516
- */
517
- handleAutomation(path: string, method: string, body: any, context: HttpProtocolContext): Promise<HttpDispatcherResult>;
516
+ *
517
+ * Routes:
518
+ * GET / → listFlows
519
+ * GET /:name → getFlow
520
+ * POST / → createFlow (registerFlow)
521
+ * PUT /:name → updateFlow
522
+ * DELETE /:name → deleteFlow (unregisterFlow)
523
+ * POST /:name/trigger → execute (legacy: trigger/:name also supported)
524
+ * POST /:name/toggle → toggleFlow
525
+ * GET /:name/runs → listRuns
526
+ * GET /:name/runs/:runId → getRun
527
+ */
528
+ handleAutomation(path: string, method: string, body: any, context: HttpProtocolContext, query?: any): Promise<HttpDispatcherResult>;
518
529
  private getServicesMap;
519
530
  private getService;
520
531
  /**
package/dist/index.js CHANGED
@@ -679,18 +679,93 @@ var HttpDispatcher = class {
679
679
  /**
680
680
  * Handles Automation requests
681
681
  * path: sub-path after /automation/
682
+ *
683
+ * Routes:
684
+ * GET / → listFlows
685
+ * GET /:name → getFlow
686
+ * POST / → createFlow (registerFlow)
687
+ * PUT /:name → updateFlow
688
+ * DELETE /:name → deleteFlow (unregisterFlow)
689
+ * POST /:name/trigger → execute (legacy: trigger/:name also supported)
690
+ * POST /:name/toggle → toggleFlow
691
+ * GET /:name/runs → listRuns
692
+ * GET /:name/runs/:runId → getRun
682
693
  */
683
- async handleAutomation(path, method, body, context) {
694
+ async handleAutomation(path, method, body, context, query) {
684
695
  const automationService = this.getService(CoreServiceName.enum.automation);
685
696
  if (!automationService) return { handled: false };
686
697
  const m = method.toUpperCase();
687
- const parts = path.replace(/^\/+/, "").split("/");
698
+ const parts = path.replace(/^\/+/, "").split("/").filter(Boolean);
688
699
  if (parts[0] === "trigger" && parts[1] && m === "POST") {
689
700
  const triggerName = parts[1];
690
701
  if (typeof automationService.trigger === "function") {
691
702
  const result = await automationService.trigger(triggerName, body, { request: context.request });
692
703
  return { handled: true, response: this.success(result) };
693
704
  }
705
+ if (typeof automationService.execute === "function") {
706
+ const result = await automationService.execute(triggerName, body);
707
+ return { handled: true, response: this.success(result) };
708
+ }
709
+ }
710
+ if (parts.length === 0 && m === "GET") {
711
+ if (typeof automationService.listFlows === "function") {
712
+ const names = await automationService.listFlows();
713
+ return { handled: true, response: this.success({ flows: names, total: names.length, hasMore: false }) };
714
+ }
715
+ }
716
+ if (parts.length === 0 && m === "POST") {
717
+ if (typeof automationService.registerFlow === "function") {
718
+ automationService.registerFlow(body?.name, body);
719
+ return { handled: true, response: this.success(body) };
720
+ }
721
+ }
722
+ if (parts.length >= 1) {
723
+ const name = parts[0];
724
+ if (parts[1] === "trigger" && m === "POST") {
725
+ if (typeof automationService.execute === "function") {
726
+ const result = await automationService.execute(name, body);
727
+ return { handled: true, response: this.success(result) };
728
+ }
729
+ }
730
+ if (parts[1] === "toggle" && m === "POST") {
731
+ if (typeof automationService.toggleFlow === "function") {
732
+ await automationService.toggleFlow(name, body?.enabled ?? true);
733
+ return { handled: true, response: this.success({ name, enabled: body?.enabled ?? true }) };
734
+ }
735
+ }
736
+ if (parts[1] === "runs" && parts[2] && m === "GET") {
737
+ if (typeof automationService.getRun === "function") {
738
+ const run = await automationService.getRun(parts[2]);
739
+ if (!run) return { handled: true, response: this.error("Execution not found", 404) };
740
+ return { handled: true, response: this.success(run) };
741
+ }
742
+ }
743
+ if (parts[1] === "runs" && !parts[2] && m === "GET") {
744
+ if (typeof automationService.listRuns === "function") {
745
+ const options = query ? { limit: query.limit ? Number(query.limit) : void 0, cursor: query.cursor } : void 0;
746
+ const runs = await automationService.listRuns(name, options);
747
+ return { handled: true, response: this.success({ runs, hasMore: false }) };
748
+ }
749
+ }
750
+ if (parts.length === 1 && m === "GET") {
751
+ if (typeof automationService.getFlow === "function") {
752
+ const flow = await automationService.getFlow(name);
753
+ if (!flow) return { handled: true, response: this.error("Flow not found", 404) };
754
+ return { handled: true, response: this.success(flow) };
755
+ }
756
+ }
757
+ if (parts.length === 1 && m === "PUT") {
758
+ if (typeof automationService.registerFlow === "function") {
759
+ automationService.registerFlow(name, body?.definition ?? body);
760
+ return { handled: true, response: this.success(body?.definition ?? body) };
761
+ }
762
+ }
763
+ if (parts.length === 1 && m === "DELETE") {
764
+ if (typeof automationService.unregisterFlow === "function") {
765
+ automationService.unregisterFlow(name);
766
+ return { handled: true, response: this.success({ name, deleted: true }) };
767
+ }
768
+ }
694
769
  }
695
770
  return { handled: false };
696
771
  }
@@ -765,7 +840,7 @@ var HttpDispatcher = class {
765
840
  return this.handleUi(cleanPath.substring(3), query, context);
766
841
  }
767
842
  if (cleanPath.startsWith("/automation")) {
768
- return this.handleAutomation(cleanPath.substring(11), method, body, context);
843
+ return this.handleAutomation(cleanPath.substring(11), method, body, context, query);
769
844
  }
770
845
  if (cleanPath.startsWith("/analytics")) {
771
846
  return this.handleAnalytics(cleanPath.substring(10), method, body, context);
@@ -994,6 +1069,46 @@ function createDispatcherPlugin(config = {}) {
994
1069
  errorResponse(err, res);
995
1070
  }
996
1071
  });
1072
+ server.get(`${prefix}/automation`, async (req, res) => {
1073
+ try {
1074
+ const result = await dispatcher.handleAutomation("", "GET", {}, { request: req });
1075
+ sendResult(result, res);
1076
+ } catch (err) {
1077
+ errorResponse(err, res);
1078
+ }
1079
+ });
1080
+ server.post(`${prefix}/automation`, async (req, res) => {
1081
+ try {
1082
+ const result = await dispatcher.handleAutomation("", "POST", req.body, { request: req });
1083
+ sendResult(result, res);
1084
+ } catch (err) {
1085
+ errorResponse(err, res);
1086
+ }
1087
+ });
1088
+ server.get(`${prefix}/automation/:name`, async (req, res) => {
1089
+ try {
1090
+ const result = await dispatcher.handleAutomation(`${req.params.name}`, "GET", {}, { request: req });
1091
+ sendResult(result, res);
1092
+ } catch (err) {
1093
+ errorResponse(err, res);
1094
+ }
1095
+ });
1096
+ server.put(`${prefix}/automation/:name`, async (req, res) => {
1097
+ try {
1098
+ const result = await dispatcher.handleAutomation(`${req.params.name}`, "PUT", req.body, { request: req });
1099
+ sendResult(result, res);
1100
+ } catch (err) {
1101
+ errorResponse(err, res);
1102
+ }
1103
+ });
1104
+ server.delete(`${prefix}/automation/:name`, async (req, res) => {
1105
+ try {
1106
+ const result = await dispatcher.handleAutomation(`${req.params.name}`, "DELETE", {}, { request: req });
1107
+ sendResult(result, res);
1108
+ } catch (err) {
1109
+ errorResponse(err, res);
1110
+ }
1111
+ });
997
1112
  server.post(`${prefix}/automation/trigger/:name`, async (req, res) => {
998
1113
  try {
999
1114
  const result = await dispatcher.handleAutomation(`trigger/${req.params.name}`, "POST", req.body, { request: req });
@@ -1002,6 +1117,38 @@ function createDispatcherPlugin(config = {}) {
1002
1117
  errorResponse(err, res);
1003
1118
  }
1004
1119
  });
1120
+ server.post(`${prefix}/automation/:name/trigger`, async (req, res) => {
1121
+ try {
1122
+ const result = await dispatcher.handleAutomation(`${req.params.name}/trigger`, "POST", req.body, { request: req });
1123
+ sendResult(result, res);
1124
+ } catch (err) {
1125
+ errorResponse(err, res);
1126
+ }
1127
+ });
1128
+ server.post(`${prefix}/automation/:name/toggle`, async (req, res) => {
1129
+ try {
1130
+ const result = await dispatcher.handleAutomation(`${req.params.name}/toggle`, "POST", req.body, { request: req });
1131
+ sendResult(result, res);
1132
+ } catch (err) {
1133
+ errorResponse(err, res);
1134
+ }
1135
+ });
1136
+ server.get(`${prefix}/automation/:name/runs`, async (req, res) => {
1137
+ try {
1138
+ const result = await dispatcher.handleAutomation(`${req.params.name}/runs`, "GET", {}, { request: req }, req.query);
1139
+ sendResult(result, res);
1140
+ } catch (err) {
1141
+ errorResponse(err, res);
1142
+ }
1143
+ });
1144
+ server.get(`${prefix}/automation/:name/runs/:runId`, async (req, res) => {
1145
+ try {
1146
+ const result = await dispatcher.handleAutomation(`${req.params.name}/runs/${req.params.runId}`, "GET", {}, { request: req });
1147
+ sendResult(result, res);
1148
+ } catch (err) {
1149
+ errorResponse(err, res);
1150
+ }
1151
+ });
1005
1152
  ctx.logger.info("Dispatcher bridge routes registered", { prefix });
1006
1153
  }
1007
1154
  };