@cadenza.io/service 1.9.35 → 1.9.36

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.mts CHANGED
@@ -317,6 +317,7 @@ interface SchemaDefinition {
317
317
  type SecurityProfile = "low" | "medium" | "high";
318
318
  type NetworkMode = "internal" | "exposed" | "exposed-high-sec" | "auto" | "dev";
319
319
  type ServerOptions = {
320
+ customServiceId?: string;
320
321
  loadBalance?: boolean;
321
322
  useSocket?: boolean;
322
323
  log?: boolean;
package/dist/index.d.ts CHANGED
@@ -317,6 +317,7 @@ interface SchemaDefinition {
317
317
  type SecurityProfile = "low" | "medium" | "high";
318
318
  type NetworkMode = "internal" | "exposed" | "exposed-high-sec" | "auto" | "dev";
319
319
  type ServerOptions = {
320
+ customServiceId?: string;
320
321
  loadBalance?: boolean;
321
322
  useSocket?: boolean;
322
323
  log?: boolean;
package/dist/index.js CHANGED
@@ -994,14 +994,27 @@ var RestController = class _RestController {
994
994
  (ctx) => {
995
995
  const app = ctx.__app;
996
996
  app.post("/handshake", (req, res) => {
997
- console.log("handshake", req.body);
998
- CadenzaService.broker.emit("meta.rest.handshake", req.body);
999
- res.send({ __status: "success" });
997
+ try {
998
+ console.log("handshake", req);
999
+ CadenzaService.broker.emit("meta.rest.handshake", req);
1000
+ res.send({ __status: "success" });
1001
+ } catch (e) {
1002
+ console.error("Error in handshake", e);
1003
+ res.send({ __status: "error" });
1004
+ }
1000
1005
  });
1001
1006
  app.post("/delegation", (req, res) => {
1002
- const ctx2 = req.body;
1003
- const routineExecId = ctx2.__routineExecId || (0, import_uuid3.v4)();
1004
- console.log("delegation", ctx2);
1007
+ let routineExecId;
1008
+ let ctx2;
1009
+ try {
1010
+ ctx2 = req;
1011
+ routineExecId = ctx2.__routineExecId || (0, import_uuid3.v4)();
1012
+ console.log("delegation", ctx2);
1013
+ } catch (e) {
1014
+ console.error("Error in delegation", e);
1015
+ res.send({ __status: "error" });
1016
+ return;
1017
+ }
1005
1018
  CadenzaService.createEphemeralMetaTask(
1006
1019
  "Resolve delegation",
1007
1020
  (endCtx) => res.json({
@@ -1028,9 +1041,16 @@ var RestController = class _RestController {
1028
1041
  CadenzaService.broker.emit("meta.rest.delegation_requested", ctx2);
1029
1042
  });
1030
1043
  app.post("/signal", (req, res) => {
1031
- const ctx2 = req.body;
1032
- console.log("signal", ctx2);
1033
- res.send({ __status: "success" });
1044
+ let ctx2;
1045
+ try {
1046
+ ctx2 = req;
1047
+ console.log("signal", ctx2);
1048
+ res.send({ __status: "success" });
1049
+ } catch (e) {
1050
+ console.error("Error in signal", e);
1051
+ res.send({ __status: "error" });
1052
+ return;
1053
+ }
1034
1054
  CadenzaService.broker.emit(ctx2.__signalName, ctx2.__context);
1035
1055
  });
1036
1056
  app.get("/status", (req, res) => {
@@ -3508,7 +3528,7 @@ var CadenzaService = class {
3508
3528
  * @throws Error if name invalid or duplicate.
3509
3529
  */
3510
3530
  static createCadenzaService(serviceName, description = "", options = {}) {
3511
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k;
3531
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l;
3512
3532
  if (this.serviceCreated) return;
3513
3533
  this.bootstrap();
3514
3534
  import_core3.default.validateName(serviceName);
@@ -3569,7 +3589,7 @@ var CadenzaService = class {
3569
3589
  });
3570
3590
  });
3571
3591
  console.log("Creating service...");
3572
- import_core3.default.broker.emit("meta.create_service_requested", {
3592
+ const initContext = {
3573
3593
  data: {
3574
3594
  name: serviceName,
3575
3595
  description,
@@ -3584,7 +3604,14 @@ var CadenzaService = class {
3584
3604
  __networkMode: options.networkMode,
3585
3605
  __retryCount: options.retryCount,
3586
3606
  __cadenzaDBConnect: (_k = options.cadenzaDB) == null ? void 0 : _k.connect
3587
- });
3607
+ };
3608
+ if ((_l = options.cadenzaDB) == null ? void 0 : _l.connect) {
3609
+ import_core3.default.createEphemeralMetaTask("Create service", (_, emit) => __async(this, null, function* () {
3610
+ emit("meta.create_service_requested", initContext);
3611
+ })).doOn("meta.fetch.handshake_complete");
3612
+ } else {
3613
+ import_core3.default.broker.emit("meta.create_service_requested", initContext);
3614
+ }
3588
3615
  this.createEphemeralMetaTask("Handle service setup completion", (ctx) => {
3589
3616
  GraphMetadataController.instance;
3590
3617
  return true;