otomato-sdk 2.0.50 → 2.0.52

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,4 +1,4 @@
1
- export const SDK_VERSION = '2.0.50';
1
+ export const SDK_VERSION = '2.0.51';
2
2
  export function compareVersions(v1, v2) {
3
3
  // Split the version strings into parts
4
4
  const v1Parts = v1.split('.').map(Number);
@@ -1,81 +1,67 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import ELK from 'elkjs/lib/elk.bundled.js';
11
- export const xSpacing = 700; // similar to Dagre’s node separation
1
+ // Note: Using 'dagre' for layered DAG layout
2
+ import * as dagre from '@dagrejs/dagre';
3
+ // or: import * as dagre from 'dagre';
4
+ export const xSpacing = 700; // used by dagre as node separation
12
5
  export const ySpacing = 75;
13
- export const ROOT_X = 400; // reference positions (if needed)
6
+ export const ROOT_X = 400; // we’ll keep references, but Dagre decides actual positions
14
7
  export const ROOT_Y = 120;
15
- // Create a single ELK instance for reuse
16
- const elk = new ELK();
17
8
  /**
18
- * ELK-based layout for workflow nodes.
19
- *
20
- * This function builds an ELK-compatible graph:
21
- * 1) It creates a root graph object with layout options.
22
- * 2) It adds all workflow nodes as children, with id, width, and height.
23
- * 3) It adds all edges (as ELK expects sources/targets arrays).
24
- * 4) It calls elk.layout() (asynchronously) to compute positions.
25
- * 5) It then updates each node in workflow.nodes with the computed positions.
26
- *
27
- * Note: ELK returns (x,y) for the top-left of each node’s bounding box.
28
- * If your SDK expects center positions, we adjust by adding half the width/height.
9
+ * Dagre-based layout for the “top-down” pass. We’re effectively ignoring the old
10
+ * manual code. Instead, we:
11
+ * 1) Build a dagre graph
12
+ * 2) Add all nodes & edges
13
+ * 3) dagre.layout(g)
14
+ * 4) Extract positions & write them back to workflow.nodes
29
15
  */
30
16
  export function positionWorkflowNodes(workflow) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- // 1) Create an ELK graph structure
33
- const elkGraph = {
34
- id: 'root',
35
- // Layout options can be tuned as needed.
36
- layoutOptions: {
37
- // 'DOWN' makes the layout top-to-bottom (like Dagre’s rankdir: 'TB')
38
- 'elk.direction': 'DOWN',
39
- // Space between nodes (ELK uses this for both horizontal and vertical spacing)
40
- 'elk.layered.spacing.nodeNode': ySpacing.toString(),
41
- // Add some padding around the graph
42
- 'elk.padding': '20', // you can also use "20,20,20,20" for (top,right,bottom,left)
43
- },
44
- // 2) Map workflow nodes to ELK “children”
45
- children: workflow.nodes.map((node) => ({
46
- id: node.getRef(),
47
- width: 100, // approximate width
48
- height: 50, // approximate height
49
- })),
50
- // 3) Map workflow edges to ELK “edges”
51
- edges: workflow.edges.map((edge) => ({
52
- id: `${edge.source.getRef()}_${edge.target.getRef()}`,
53
- sources: [edge.source.getRef()],
54
- targets: [edge.target.getRef()],
55
- // Optionally, you can pass edge-specific layout options here.
56
- })),
57
- };
58
- // 4) Run the ELK layout (this returns a Promise)
59
- const layout = yield elk.layout(elkGraph);
60
- // 5) Extract positions from ELK’s result and store them back on the workflow nodes.
61
- // ELK returns an array of children nodes with computed { x, y, width, height }.
62
- if (layout.children) {
63
- layout.children.forEach((elkNode) => {
64
- // Find the corresponding Node object by its unique reference
65
- const nodeObj = workflow.nodes.find((n) => n.getRef() === elkNode.id);
66
- if (!nodeObj)
67
- return;
68
- // ELK gives x,y as the top-left. To match Dagre’s “center” output, we add half the dimensions.
69
- const centerX = elkNode.x + (elkNode.width / 2);
70
- const centerY = elkNode.y + (elkNode.height / 2);
71
- nodeObj.setPosition(centerX, centerY);
72
- });
73
- }
17
+ // 1) Create a new directed graph
18
+ // doc: https://github.com/dagrejs/dagre
19
+ const g = new dagre.graphlib.Graph({ multigraph: false, compound: false });
20
+ g.setGraph({
21
+ // Some layout options:
22
+ rankdir: 'TB', // "top-bottom" layering
23
+ nodesep: xSpacing * 0.5, // horizontal spacing
24
+ ranksep: ySpacing, // vertical spacing between levels
25
+ marginx: 20, // how much margin to leave around the left/right
26
+ marginy: 20, // how much margin to leave around the top/bottom
27
+ });
28
+ g.setDefaultEdgeLabel(() => ({}));
29
+ // 2) Add nodes to the graph
30
+ // Dagre requires each node have an id and some approximate width/height
31
+ workflow.nodes.forEach((node) => {
32
+ const nodeId = node.getRef();
33
+ // For a typical text-based node, approximate width & height
34
+ g.setNode(nodeId, {
35
+ label: nodeId,
36
+ width: 100,
37
+ height: 50
38
+ });
39
+ });
40
+ // 3) Add edges
41
+ // Dagre identifies edges by (sourceId, targetId). We don’t need labels for layout,
42
+ // but we can store them if we want. If you rely on “true/false” ordering, we can tweak
43
+ // e.g. use edge label as a tie-break. (See advanced docs.)
44
+ workflow.edges.forEach((edge) => {
45
+ var _a;
46
+ const fromId = edge.source.getRef();
47
+ const toId = edge.target.getRef();
48
+ g.setEdge(fromId, toId, { label: (_a = edge.label) !== null && _a !== void 0 ? _a : '' });
49
+ });
50
+ // 4) Run Dagre layout
51
+ dagre.layout(g);
52
+ // 5) Extract positions from Dagre graph and store them back to your Node objects
53
+ g.nodes().forEach((nodeId) => {
54
+ const dagreNode = g.node(nodeId); // { x, y, width, height, ... }
55
+ const nodeObj = workflow.nodes.find((n) => n.getRef() === nodeId);
56
+ if (!nodeObj || !dagreNode)
57
+ return;
58
+ // Store x,y in your node’s position
59
+ nodeObj.setPosition(dagreNode.x, dagreNode.y);
74
60
  });
75
61
  }
76
62
  /**
77
- * The following helper functions remain unchanged,
78
- * as they depend only on your workflow model.
63
+ * We keep these helper functions the same for external usage (if your code or tests need them),
64
+ * but we’re not actively using them in the new Dagre-based layout.
79
65
  */
80
66
  export function getChildren(node, edges) {
81
67
  return edges
@@ -102,7 +88,9 @@ export function getEndNodePositions(workflow) {
102
88
  });
103
89
  }
104
90
  /**
105
- * Old methods for identifying “leaf” or starting nodes.
91
+ * In Dagre, we no longer do an explicit identify leaf nodes” or “center parents by average,”
92
+ * because the layout library handles that.
93
+ * But here’s your old method if something else depends on it.
106
94
  */
107
95
  export function identifyLeafNodes(workflow) {
108
96
  const sources = new Set(workflow.edges.map((edge) => edge.source.getRef()));
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Example workflow:
3
+ * Trigger -> Delay -> Condition
4
+ * ├─(true)─> Split(3)
5
+ * └─(false)-> Delay
6
+ */
7
+ export declare function conditionSplitDemo(): Promise<void>;
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "2.0.50";
1
+ export declare const SDK_VERSION = "2.0.51";
2
2
  export declare function compareVersions(v1: string, v2: string): number;
@@ -6,22 +6,17 @@ export declare const ySpacing = 75;
6
6
  export declare const ROOT_X = 400;
7
7
  export declare const ROOT_Y = 120;
8
8
  /**
9
- * ELK-based layout for workflow nodes.
10
- *
11
- * This function builds an ELK-compatible graph:
12
- * 1) It creates a root graph object with layout options.
13
- * 2) It adds all workflow nodes as children, with id, width, and height.
14
- * 3) It adds all edges (as ELK expects sources/targets arrays).
15
- * 4) It calls elk.layout() (asynchronously) to compute positions.
16
- * 5) It then updates each node in workflow.nodes with the computed positions.
17
- *
18
- * Note: ELK returns (x,y) for the top-left of each node’s bounding box.
19
- * If your SDK expects center positions, we adjust by adding half the width/height.
9
+ * Dagre-based layout for the “top-down” pass. We’re effectively ignoring the old
10
+ * manual code. Instead, we:
11
+ * 1) Build a dagre graph
12
+ * 2) Add all nodes & edges
13
+ * 3) dagre.layout(g)
14
+ * 4) Extract positions & write them back to workflow.nodes
20
15
  */
21
- export declare function positionWorkflowNodes(workflow: Workflow): Promise<void>;
16
+ export declare function positionWorkflowNodes(workflow: Workflow): void;
22
17
  /**
23
- * The following helper functions remain unchanged,
24
- * as they depend only on your workflow model.
18
+ * We keep these helper functions the same for external usage (if your code or tests need them),
19
+ * but we’re not actively using them in the new Dagre-based layout.
25
20
  */
26
21
  export declare function getChildren(node: Node, edges: Edge[]): Node[];
27
22
  export declare function getParents(node: Node, edges: Edge[]): Node[];
@@ -31,7 +26,9 @@ export declare function getEndNodePositions(workflow: Workflow): {
31
26
  y: number;
32
27
  }[];
33
28
  /**
34
- * Old methods for identifying “leaf” or starting nodes.
29
+ * In Dagre, we no longer do an explicit identify leaf nodes” or “center parents by average,”
30
+ * because the layout library handles that.
31
+ * But here’s your old method if something else depends on it.
35
32
  */
36
33
  export declare function identifyLeafNodes(workflow: Workflow): Node[];
37
34
  export declare function identityStartingNodes(workflow: Workflow): Node[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "2.0.50",
3
+ "version": "2.0.52",
4
4
  "description": "An SDK for building and managing automations on Otomato",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/types/src/index.d.ts",
@@ -43,9 +43,9 @@
43
43
  "typescript": "^5.4.5"
44
44
  },
45
45
  "dependencies": {
46
+ "@dagrejs/dagre": "^1.1.4",
46
47
  "axios": "^1.7.2",
47
48
  "dagre": "^0.8.5",
48
- "elkjs": "^0.9.3",
49
49
  "ethers": "^6.13.1",
50
50
  "jsonwebtoken": "^9.0.2",
51
51
  "mustache": "^4.2.0"