otomato-sdk 1.1.0 → 1.2.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.
- package/dist/examples/create-automation.js +25 -7
- package/dist/src/index.js +1 -0
- package/dist/src/models/Action.js +1 -1
- package/dist/src/models/Automation.js +15 -9
- package/dist/src/models/Edge.js +25 -0
- package/dist/src/models/Node.js +29 -10
- package/dist/src/models/Trigger.js +1 -1
- package/dist/test/automation.spec.js +19 -11
- package/dist/test/node.spec.js +39 -25
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/models/Action.d.ts +3 -3
- package/dist/types/src/models/Automation.d.ts +12 -10
- package/dist/types/src/models/Edge.d.ts +14 -0
- package/dist/types/src/models/Node.d.ts +12 -5
- package/dist/types/src/models/Trigger.d.ts +3 -3
- package/examples/create-automation.ts +28 -8
- package/package.json +4 -3
- package/src/constants/json.json +16 -0
- package/src/index.ts +1 -0
- package/src/models/Action.ts +4 -4
- package/src/models/Automation.ts +22 -14
- package/src/models/Edge.ts +33 -0
- package/src/models/Node.ts +42 -11
- package/src/models/Trigger.ts +4 -4
- package/test/automation.spec.ts +19 -11
- package/test/node.spec.ts +37 -25
|
@@ -7,18 +7,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { ACTIONS, Action, TRIGGERS, Trigger, Automation, CHAINS, getToken } from '../src/index.js';
|
|
10
|
+
import { ACTIONS, Action, TRIGGERS, Trigger, Automation, CHAINS, getToken, Edge } from '../src/index.js';
|
|
11
11
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
const usdcTransferTrigger = new Trigger(
|
|
12
|
+
const usdcTransferTrigger = new Trigger({
|
|
13
|
+
id: TRIGGERS.TOKENS.ERC20.TRANSFER.id,
|
|
14
|
+
name: TRIGGERS.TOKENS.ERC20.TRANSFER.name,
|
|
15
|
+
description: TRIGGERS.TOKENS.ERC20.TRANSFER.description,
|
|
16
|
+
type: TRIGGERS.TOKENS.ERC20.TRANSFER.type,
|
|
17
|
+
parameters: TRIGGERS.TOKENS.ERC20.TRANSFER.parameters,
|
|
18
|
+
ref: 'n-1',
|
|
19
|
+
});
|
|
13
20
|
usdcTransferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
14
21
|
usdcTransferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
15
|
-
usdcTransferTrigger.
|
|
16
|
-
const slackAction = new Action(
|
|
22
|
+
usdcTransferTrigger.setPosition(0, 0);
|
|
23
|
+
const slackAction = new Action({
|
|
24
|
+
id: ACTIONS.NOTIFICATIONS.SLACK.id,
|
|
25
|
+
name: ACTIONS.NOTIFICATIONS.SLACK.name,
|
|
26
|
+
description: ACTIONS.NOTIFICATIONS.SLACK.description,
|
|
27
|
+
parameters: ACTIONS.NOTIFICATIONS.SLACK.parameters,
|
|
28
|
+
// not forced to provide a ref id, it will generate it
|
|
29
|
+
});
|
|
17
30
|
slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
18
31
|
slackAction.setParams("text", "USDC has been transferred!");
|
|
19
|
-
slackAction.
|
|
20
|
-
const automation = new Automation("USDC Transfer Notification", usdcTransferTrigger,
|
|
32
|
+
slackAction.setPosition(0, -10);
|
|
33
|
+
const automation = new Automation("USDC Transfer Notification", [usdcTransferTrigger, slackAction]);
|
|
34
|
+
const edge = new Edge({
|
|
35
|
+
source: usdcTransferTrigger,
|
|
36
|
+
target: slackAction,
|
|
37
|
+
});
|
|
38
|
+
automation.addEdge(edge);
|
|
21
39
|
console.log(JSON.stringify(automation.toJSON(), null, 2));
|
|
22
|
-
|
|
40
|
+
//await automation.save();
|
|
23
41
|
});
|
|
24
42
|
main();
|
package/dist/src/index.js
CHANGED
|
@@ -9,25 +9,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { apiServices } from '../services/ApiService.js';
|
|
11
11
|
export class Automation {
|
|
12
|
-
constructor(name,
|
|
12
|
+
constructor(name, nodes = [], edges = []) {
|
|
13
13
|
this.name = name;
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
14
|
+
this.nodes = nodes;
|
|
15
|
+
this.edges = edges;
|
|
16
16
|
}
|
|
17
17
|
setName(name) {
|
|
18
18
|
this.name = name;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
this.
|
|
20
|
+
addNode(node) {
|
|
21
|
+
this.nodes.push(node);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
this.
|
|
23
|
+
addNodes(nodes) {
|
|
24
|
+
this.nodes.push(...nodes);
|
|
25
|
+
}
|
|
26
|
+
addEdge(edge) {
|
|
27
|
+
this.edges.push(edge);
|
|
28
|
+
}
|
|
29
|
+
addEdges(edges) {
|
|
30
|
+
this.edges.push(...edges);
|
|
25
31
|
}
|
|
26
32
|
toJSON() {
|
|
27
33
|
return {
|
|
28
34
|
name: this.name,
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
nodes: this.nodes.map(node => node.toJSON()),
|
|
36
|
+
edges: this.edges.map(edge => edge.toJSON()),
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
save() {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
let edgeCounter = 0;
|
|
2
|
+
const generatedEdgeIds = new Set();
|
|
3
|
+
export class Edge {
|
|
4
|
+
constructor(edge) {
|
|
5
|
+
if (edge.id) {
|
|
6
|
+
this.id = edge.id;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
this.id = `e-${++edgeCounter}`;
|
|
10
|
+
while (generatedEdgeIds.has(this.id)) {
|
|
11
|
+
this.id = `e-${++edgeCounter}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
generatedEdgeIds.add(this.id);
|
|
15
|
+
this.source = edge.source;
|
|
16
|
+
this.target = edge.target;
|
|
17
|
+
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return {
|
|
20
|
+
id: this.id,
|
|
21
|
+
source: this.source.getRef(),
|
|
22
|
+
target: this.target.getRef(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/src/models/Node.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { validateType } from '../utils/typeValidator.js';
|
|
2
|
+
let nodeCounter = 0;
|
|
3
|
+
const generatedRefs = new Set();
|
|
2
4
|
export class Node {
|
|
3
5
|
constructor(node) {
|
|
4
6
|
this.id = node.id;
|
|
@@ -6,13 +8,25 @@ export class Node {
|
|
|
6
8
|
this.description = node.description;
|
|
7
9
|
this.parameters = {};
|
|
8
10
|
this.keyMap = {};
|
|
11
|
+
this.class = node.class; // Set class property
|
|
12
|
+
if (node.ref) {
|
|
13
|
+
this.ref = node.ref;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.ref = `n-${++nodeCounter}`;
|
|
17
|
+
while (generatedRefs.has(this.ref)) {
|
|
18
|
+
this.ref = `n-${++nodeCounter}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
generatedRefs.add(this.ref);
|
|
9
22
|
node.parameters.forEach(param => {
|
|
10
23
|
this.parameters[param.key] = Object.assign(Object.assign({}, param), { value: null });
|
|
11
24
|
const simplifiedKey = this.getSimplifiedKey(param.key);
|
|
12
25
|
this.keyMap[simplifiedKey] = param.key;
|
|
13
26
|
});
|
|
14
|
-
|
|
15
|
-
|
|
27
|
+
if (node.position) {
|
|
28
|
+
this.position = node.position;
|
|
29
|
+
}
|
|
16
30
|
}
|
|
17
31
|
setChainId(value) {
|
|
18
32
|
this.setParameter('chainId', value);
|
|
@@ -24,9 +38,11 @@ export class Node {
|
|
|
24
38
|
const fullKey = this.parameters[`abiParams.${key}`] ? `abiParams.${key}` : key;
|
|
25
39
|
this.setParameter(fullKey, value);
|
|
26
40
|
}
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
-
|
|
41
|
+
setPosition(x, y) {
|
|
42
|
+
this.position = { x, y };
|
|
43
|
+
}
|
|
44
|
+
getRef() {
|
|
45
|
+
return this.ref;
|
|
30
46
|
}
|
|
31
47
|
setParameter(key, value) {
|
|
32
48
|
if (key in this.parameters) {
|
|
@@ -59,12 +75,15 @@ export class Node {
|
|
|
59
75
|
toJSON() {
|
|
60
76
|
const json = {
|
|
61
77
|
id: this.id,
|
|
62
|
-
|
|
78
|
+
ref: this.ref,
|
|
79
|
+
type: this.class,
|
|
80
|
+
data: {
|
|
81
|
+
parameters: this.getParameters(),
|
|
82
|
+
}
|
|
63
83
|
};
|
|
64
|
-
if (this.
|
|
65
|
-
json.
|
|
66
|
-
|
|
67
|
-
json.y = this.y;
|
|
84
|
+
if (this.position) {
|
|
85
|
+
json.position = this.position;
|
|
86
|
+
}
|
|
68
87
|
return json;
|
|
69
88
|
}
|
|
70
89
|
getSimplifiedKey(key) {
|
|
@@ -8,27 +8,30 @@ describe('Automation Class', () => {
|
|
|
8
8
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
9
9
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
10
10
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
11
|
+
trigger.setPosition(0, 0);
|
|
11
12
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
12
13
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
13
14
|
action1.setParams("value", 1000);
|
|
14
15
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
15
16
|
action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
17
|
+
action1.setPosition(1, 0);
|
|
16
18
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
17
19
|
action2.setParams("phoneNumber", "+1234567890");
|
|
18
20
|
action2.setParams("text", "This is a test message");
|
|
19
|
-
|
|
21
|
+
action2.setPosition(2, 0);
|
|
22
|
+
const automation = new Automation("Test Automation", [trigger, action1, action2]);
|
|
20
23
|
const json = automation.toJSON();
|
|
21
24
|
expect(json).to.deep.equal({
|
|
22
25
|
name: "Test Automation",
|
|
23
|
-
|
|
24
|
-
actions: [action1.toJSON(), action2.toJSON()],
|
|
26
|
+
nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
|
|
25
27
|
});
|
|
26
28
|
});
|
|
27
29
|
it('should set the name of the automation', () => {
|
|
28
30
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
29
31
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
30
32
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
31
|
-
|
|
33
|
+
trigger.setPosition(0, 0);
|
|
34
|
+
const automation = new Automation("Initial Name", [trigger]);
|
|
32
35
|
automation.setName("Updated Name");
|
|
33
36
|
expect(automation.name).to.equal("Updated Name");
|
|
34
37
|
});
|
|
@@ -36,28 +39,33 @@ describe('Automation Class', () => {
|
|
|
36
39
|
const initialTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
37
40
|
initialTrigger.setChainId(CHAINS.ETHEREUM);
|
|
38
41
|
initialTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
42
|
+
initialTrigger.setPosition(0, 0);
|
|
39
43
|
const newTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
40
44
|
newTrigger.setChainId(CHAINS.ETHEREUM);
|
|
41
45
|
newTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
42
|
-
|
|
43
|
-
automation
|
|
44
|
-
|
|
46
|
+
newTrigger.setPosition(1, 0);
|
|
47
|
+
const automation = new Automation("Test Automation", [initialTrigger]);
|
|
48
|
+
automation.addNode(newTrigger);
|
|
49
|
+
expect(automation.nodes).to.deep.equal([initialTrigger, newTrigger]);
|
|
45
50
|
});
|
|
46
51
|
it('should add actions to the automation', () => {
|
|
47
52
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
48
53
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
49
54
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
55
|
+
trigger.setPosition(0, 0);
|
|
50
56
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
51
57
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
52
58
|
action1.setParams("value", 1000);
|
|
53
59
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
54
60
|
action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
61
|
+
action1.setPosition(1, 0);
|
|
55
62
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
56
63
|
action2.setParams("phoneNumber", "+1234567890");
|
|
57
64
|
action2.setParams("text", "This is a test message");
|
|
58
|
-
|
|
59
|
-
automation
|
|
60
|
-
automation.
|
|
61
|
-
|
|
65
|
+
action2.setPosition(2, 0);
|
|
66
|
+
const automation = new Automation("Test Automation", [trigger]);
|
|
67
|
+
automation.addNode(action1);
|
|
68
|
+
automation.addNode(action2);
|
|
69
|
+
expect(automation.nodes).to.deep.equal([trigger, action1, action2]);
|
|
62
70
|
});
|
|
63
71
|
});
|
package/dist/test/node.spec.js
CHANGED
|
@@ -10,40 +10,44 @@ describe('Node Class', () => {
|
|
|
10
10
|
id: 1,
|
|
11
11
|
name: 'Test Node',
|
|
12
12
|
description: 'A node for testing',
|
|
13
|
-
parameters: DEFAULT_PARAMETERS
|
|
13
|
+
parameters: DEFAULT_PARAMETERS,
|
|
14
|
+
class: 'testClass'
|
|
14
15
|
});
|
|
15
|
-
expect(node.
|
|
16
|
-
expect(node.y).to.be.undefined;
|
|
16
|
+
expect(node.position).to.be.undefined;
|
|
17
17
|
});
|
|
18
18
|
it('should create a node with coordinates', () => {
|
|
19
|
+
var _a, _b;
|
|
19
20
|
const node = new Node({
|
|
20
21
|
id: 2,
|
|
21
22
|
name: 'Test Node with Coordinates',
|
|
22
23
|
description: 'A node for testing with coordinates',
|
|
23
24
|
parameters: DEFAULT_PARAMETERS,
|
|
24
|
-
|
|
25
|
-
y: 200
|
|
25
|
+
class: 'testClass',
|
|
26
|
+
position: { x: 100, y: 200 }
|
|
26
27
|
});
|
|
27
|
-
expect(node.x).to.equal(100);
|
|
28
|
-
expect(node.y).to.equal(200);
|
|
28
|
+
expect((_a = node.position) === null || _a === void 0 ? void 0 : _a.x).to.equal(100);
|
|
29
|
+
expect((_b = node.position) === null || _b === void 0 ? void 0 : _b.y).to.equal(200);
|
|
29
30
|
});
|
|
30
31
|
it('should set and get coordinates correctly', () => {
|
|
32
|
+
var _a, _b;
|
|
31
33
|
const node = new Node({
|
|
32
34
|
id: 3,
|
|
33
35
|
name: 'Test Node for Coordinates',
|
|
34
36
|
description: 'A node for testing coordinate setting',
|
|
35
|
-
parameters: DEFAULT_PARAMETERS
|
|
37
|
+
parameters: DEFAULT_PARAMETERS,
|
|
38
|
+
class: 'testClass'
|
|
36
39
|
});
|
|
37
|
-
node.
|
|
38
|
-
expect(node.x).to.equal(300);
|
|
39
|
-
expect(node.y).to.equal(400);
|
|
40
|
+
node.setPosition(300, 400);
|
|
41
|
+
expect((_a = node.position) === null || _a === void 0 ? void 0 : _a.x).to.equal(300);
|
|
42
|
+
expect((_b = node.position) === null || _b === void 0 ? void 0 : _b.y).to.equal(400);
|
|
40
43
|
});
|
|
41
44
|
it('should create a node and set parameters correctly', () => {
|
|
42
45
|
const node = new Node({
|
|
43
46
|
id: 4,
|
|
44
47
|
name: 'Test Node for Parameters',
|
|
45
48
|
description: 'A node for testing parameter setting',
|
|
46
|
-
parameters: DEFAULT_PARAMETERS
|
|
49
|
+
parameters: DEFAULT_PARAMETERS,
|
|
50
|
+
class: 'testClass'
|
|
47
51
|
});
|
|
48
52
|
node.setChainId(1);
|
|
49
53
|
node.setContractAddress("0x0000000000000000000000000000000000000000");
|
|
@@ -56,16 +60,21 @@ describe('Node Class', () => {
|
|
|
56
60
|
id: 5,
|
|
57
61
|
name: 'Test Node for JSON',
|
|
58
62
|
description: 'A node for testing JSON export',
|
|
59
|
-
parameters: DEFAULT_PARAMETERS
|
|
63
|
+
parameters: DEFAULT_PARAMETERS,
|
|
64
|
+
class: 'testClass'
|
|
60
65
|
});
|
|
61
66
|
node.setChainId(1);
|
|
62
67
|
node.setContractAddress("0x0000000000000000000000000000000000000000");
|
|
63
68
|
const json = node.toJSON();
|
|
64
69
|
expect(json).to.deep.equal({
|
|
65
70
|
id: 5,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
ref: node.getRef(),
|
|
72
|
+
class: 'testClass',
|
|
73
|
+
data: {
|
|
74
|
+
parameters: {
|
|
75
|
+
chainId: 1,
|
|
76
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
});
|
|
71
80
|
});
|
|
@@ -75,20 +84,23 @@ describe('Node Class', () => {
|
|
|
75
84
|
name: 'Test Node for JSON with Coordinates',
|
|
76
85
|
description: 'A node for testing JSON export with coordinates',
|
|
77
86
|
parameters: DEFAULT_PARAMETERS,
|
|
78
|
-
|
|
79
|
-
y:
|
|
87
|
+
class: 'testClass',
|
|
88
|
+
position: { x: 1, y: 2 }
|
|
80
89
|
});
|
|
81
90
|
node.setChainId(1);
|
|
82
91
|
node.setContractAddress("0x0000000000000000000000000000000000000000");
|
|
83
92
|
const json = node.toJSON();
|
|
84
93
|
expect(json).to.deep.equal({
|
|
85
94
|
id: 6,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
ref: node.getRef(),
|
|
96
|
+
class: 'testClass',
|
|
97
|
+
data: {
|
|
98
|
+
parameters: {
|
|
99
|
+
chainId: 1,
|
|
100
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
101
|
+
}
|
|
89
102
|
},
|
|
90
|
-
x:
|
|
91
|
-
y: 200
|
|
103
|
+
position: { x: 1, y: 2 }
|
|
92
104
|
});
|
|
93
105
|
});
|
|
94
106
|
it('should throw an error for invalid parameter type', () => {
|
|
@@ -96,7 +108,8 @@ describe('Node Class', () => {
|
|
|
96
108
|
id: 7,
|
|
97
109
|
name: 'Test Node for Invalid Parameter Type',
|
|
98
110
|
description: 'A node for testing invalid parameter type',
|
|
99
|
-
parameters: DEFAULT_PARAMETERS
|
|
111
|
+
parameters: DEFAULT_PARAMETERS,
|
|
112
|
+
class: 'testClass'
|
|
100
113
|
});
|
|
101
114
|
expect(() => node.setParams("chainId", "invalid")).to.throw('Invalid type for parameter chainId. Expected integer.');
|
|
102
115
|
});
|
|
@@ -105,7 +118,8 @@ describe('Node Class', () => {
|
|
|
105
118
|
id: 8,
|
|
106
119
|
name: 'Test Node for Invalid Address',
|
|
107
120
|
description: 'A node for testing invalid address',
|
|
108
|
-
parameters: DEFAULT_PARAMETERS
|
|
121
|
+
parameters: DEFAULT_PARAMETERS,
|
|
122
|
+
class: 'testClass'
|
|
109
123
|
});
|
|
110
124
|
expect(() => node.setParams("contractAddress", "invalid_address")).to.throw('Invalid type for parameter contractAddress. Expected address.');
|
|
111
125
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
|
-
import { Node } from './Node.js';
|
|
2
|
+
import { Node, Position } from './Node.js';
|
|
3
3
|
export declare class Action extends Node {
|
|
4
4
|
constructor(action: {
|
|
5
5
|
id: number;
|
|
6
6
|
name: string;
|
|
7
7
|
description: string;
|
|
8
8
|
parameters: Parameter[];
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
ref?: string;
|
|
10
|
+
position?: Position;
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Node } from './Node.js';
|
|
2
|
+
import { Edge } from './Edge.js';
|
|
3
3
|
export declare class Automation {
|
|
4
4
|
name: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor(name: string,
|
|
5
|
+
nodes: Node[];
|
|
6
|
+
edges: Edge[];
|
|
7
|
+
constructor(name: string, nodes?: Node[], edges?: Edge[]);
|
|
8
8
|
setName(name: string): void;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
addNode(node: Node): void;
|
|
10
|
+
addNodes(nodes: Node[]): void;
|
|
11
|
+
addEdge(edge: Edge): void;
|
|
12
|
+
addEdges(edges: Edge[]): void;
|
|
11
13
|
toJSON(): {
|
|
12
14
|
name: string;
|
|
13
|
-
|
|
15
|
+
nodes: {
|
|
14
16
|
[key: string]: any;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
+
}[];
|
|
18
|
+
edges: {
|
|
17
19
|
[key: string]: any;
|
|
18
20
|
}[];
|
|
19
21
|
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
|
+
export interface Position {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
2
6
|
export declare class Node {
|
|
3
7
|
id: number;
|
|
4
8
|
name: string;
|
|
@@ -9,20 +13,23 @@ export declare class Node {
|
|
|
9
13
|
keyMap: {
|
|
10
14
|
[key: string]: string;
|
|
11
15
|
};
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
position?: Position;
|
|
17
|
+
ref: string;
|
|
18
|
+
class: string;
|
|
14
19
|
constructor(node: {
|
|
15
20
|
id: number;
|
|
16
21
|
name: string;
|
|
17
22
|
description: string;
|
|
18
23
|
parameters: Parameter[];
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
ref?: string;
|
|
25
|
+
position?: Position;
|
|
26
|
+
class: string;
|
|
21
27
|
});
|
|
22
28
|
setChainId(value: number): void;
|
|
23
29
|
setContractAddress(value: string): void;
|
|
24
30
|
setParams(key: string, value: any): void;
|
|
25
|
-
|
|
31
|
+
setPosition(x: number, y: number): void;
|
|
32
|
+
getRef(): string;
|
|
26
33
|
protected setParameter(key: string, value: any): void;
|
|
27
34
|
getParameter(key: string): any;
|
|
28
35
|
getParameters(): {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
|
-
import { Node } from './Node.js';
|
|
2
|
+
import { Node, Position } from './Node.js';
|
|
3
3
|
export declare class Trigger extends Node {
|
|
4
4
|
type: number;
|
|
5
5
|
constructor(trigger: {
|
|
@@ -8,8 +8,8 @@ export declare class Trigger extends Node {
|
|
|
8
8
|
description: string;
|
|
9
9
|
type: number;
|
|
10
10
|
parameters: Parameter[];
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
ref?: string;
|
|
12
|
+
position?: Position;
|
|
13
13
|
});
|
|
14
14
|
setCondition(value: string): void;
|
|
15
15
|
setComparisonValue(value: number): void;
|
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import { ACTIONS, Action, TRIGGERS, Trigger, Automation, CHAINS, getToken } from '../src/index.js';
|
|
1
|
+
import { ACTIONS, Action, TRIGGERS, Trigger, Automation, CHAINS, getToken, Edge } from '../src/index.js';
|
|
2
2
|
|
|
3
3
|
const main = async () => {
|
|
4
|
-
const usdcTransferTrigger = new Trigger(
|
|
4
|
+
const usdcTransferTrigger = new Trigger({
|
|
5
|
+
id: TRIGGERS.TOKENS.ERC20.TRANSFER.id,
|
|
6
|
+
name: TRIGGERS.TOKENS.ERC20.TRANSFER.name,
|
|
7
|
+
description: TRIGGERS.TOKENS.ERC20.TRANSFER.description,
|
|
8
|
+
type: TRIGGERS.TOKENS.ERC20.TRANSFER.type,
|
|
9
|
+
parameters: TRIGGERS.TOKENS.ERC20.TRANSFER.parameters,
|
|
10
|
+
ref: 'n-1',
|
|
11
|
+
});
|
|
5
12
|
usdcTransferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
6
13
|
usdcTransferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
7
|
-
usdcTransferTrigger.
|
|
14
|
+
usdcTransferTrigger.setPosition(0, 0);
|
|
8
15
|
|
|
9
|
-
const slackAction = new Action(
|
|
16
|
+
const slackAction = new Action({
|
|
17
|
+
id: ACTIONS.NOTIFICATIONS.SLACK.id,
|
|
18
|
+
name: ACTIONS.NOTIFICATIONS.SLACK.name,
|
|
19
|
+
description: ACTIONS.NOTIFICATIONS.SLACK.description,
|
|
20
|
+
parameters: ACTIONS.NOTIFICATIONS.SLACK.parameters,
|
|
21
|
+
// not forced to provide a ref id, it will generate it
|
|
22
|
+
});
|
|
10
23
|
slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
11
24
|
slackAction.setParams("text", "USDC has been transferred!");
|
|
12
|
-
slackAction.
|
|
25
|
+
slackAction.setPosition(0, -10);
|
|
13
26
|
|
|
14
|
-
const automation = new Automation("USDC Transfer Notification", usdcTransferTrigger,
|
|
27
|
+
const automation = new Automation("USDC Transfer Notification", [usdcTransferTrigger, slackAction]);
|
|
28
|
+
|
|
29
|
+
const edge = new Edge({
|
|
30
|
+
source: usdcTransferTrigger,
|
|
31
|
+
target: slackAction,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
automation.addEdge(edge);
|
|
15
35
|
|
|
16
36
|
console.log(JSON.stringify(automation.toJSON(), null, 2));
|
|
17
37
|
|
|
18
|
-
await automation.save();
|
|
38
|
+
//await automation.save();
|
|
19
39
|
}
|
|
20
40
|
|
|
21
|
-
main();
|
|
41
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otomato-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "npx tsc",
|
|
10
|
-
"test": "mocha --config .mocharc.json"
|
|
10
|
+
"test": "mocha --config .mocharc.json",
|
|
11
|
+
"publish": "npm publish"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [
|
|
13
14
|
"sdk",
|
|
@@ -34,4 +35,4 @@
|
|
|
34
35
|
"axios": "^1.7.2",
|
|
35
36
|
"ethers": "^6.13.0"
|
|
36
37
|
}
|
|
37
|
-
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": 1,
|
|
3
|
+
"refId": "n-1",
|
|
4
|
+
"data": {
|
|
5
|
+
"parameters": {
|
|
6
|
+
"chainId": 1,
|
|
7
|
+
"abiParams.value": null,
|
|
8
|
+
"abiParams.to": null,
|
|
9
|
+
"contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
"position": {
|
|
13
|
+
"x": 0,
|
|
14
|
+
"y": 0
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './models/Condition.js';
|
|
|
10
10
|
export * from './models/Parameter.js';
|
|
11
11
|
export * from './models/Trigger.js';
|
|
12
12
|
export * from './models/Node.js';
|
|
13
|
+
export * from './models/Edge.js';
|
|
13
14
|
|
|
14
15
|
// Exporting services
|
|
15
16
|
export * from './services/ApiService.js';
|
package/src/models/Action.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
|
-
import { Node } from './Node.js';
|
|
2
|
+
import { Node, Position } from './Node.js';
|
|
3
3
|
|
|
4
4
|
export class Action extends Node {
|
|
5
|
-
constructor(action: { id: number; name: string; description: string; parameters: Parameter[],
|
|
6
|
-
super(action);
|
|
5
|
+
constructor(action: { id: number; name: string; description: string; parameters: Parameter[], ref?: string, position?: Position }) {
|
|
6
|
+
super({ ...action, class: 'action' });
|
|
7
7
|
}
|
|
8
|
-
}
|
|
8
|
+
}
|
package/src/models/Automation.ts
CHANGED
|
@@ -1,39 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Node } from './Node.js';
|
|
2
|
+
import { Edge } from './Edge.js';
|
|
3
3
|
import { apiServices } from '../services/ApiService.js';
|
|
4
4
|
|
|
5
5
|
export class Automation {
|
|
6
6
|
name: string;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
nodes: Node[];
|
|
8
|
+
edges: Edge[];
|
|
9
9
|
|
|
10
|
-
constructor(name: string,
|
|
10
|
+
constructor(name: string, nodes: Node[] = [], edges: Edge[] = []) {
|
|
11
11
|
this.name = name;
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this.nodes = nodes;
|
|
13
|
+
this.edges = edges;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
setName(name: string): void {
|
|
17
17
|
this.name = name;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
this.
|
|
20
|
+
addNode(node: Node): void {
|
|
21
|
+
this.nodes.push(node);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
this.
|
|
24
|
+
addNodes(nodes: Node[]): void {
|
|
25
|
+
this.nodes.push(...nodes);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
addEdge(edge: Edge): void {
|
|
29
|
+
this.edges.push(edge);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
addEdges(edges: Edge[]): void {
|
|
33
|
+
this.edges.push(...edges);
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
toJSON() {
|
|
29
37
|
return {
|
|
30
38
|
name: this.name,
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
nodes: this.nodes.map(node => node.toJSON()),
|
|
40
|
+
edges: this.edges.map(edge => edge.toJSON()),
|
|
33
41
|
};
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
async save() {
|
|
37
45
|
return apiServices.post('/workflows', this.toJSON());
|
|
38
46
|
}
|
|
39
|
-
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Node } from './Node.js';
|
|
2
|
+
|
|
3
|
+
let edgeCounter = 0;
|
|
4
|
+
const generatedEdgeIds = new Set<string>();
|
|
5
|
+
|
|
6
|
+
export class Edge {
|
|
7
|
+
id: string;
|
|
8
|
+
source: Node;
|
|
9
|
+
target: Node;
|
|
10
|
+
|
|
11
|
+
constructor(edge: { id?: string, source: Node, target: Node }) {
|
|
12
|
+
if (edge.id) {
|
|
13
|
+
this.id = edge.id;
|
|
14
|
+
} else {
|
|
15
|
+
this.id = `e-${++edgeCounter}`;
|
|
16
|
+
while (generatedEdgeIds.has(this.id)) {
|
|
17
|
+
this.id = `e-${++edgeCounter}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
generatedEdgeIds.add(this.id);
|
|
21
|
+
|
|
22
|
+
this.source = edge.source;
|
|
23
|
+
this.target = edge.target;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
toJSON(): { [key: string]: any } {
|
|
27
|
+
return {
|
|
28
|
+
id: this.id,
|
|
29
|
+
source: this.source.getRef(),
|
|
30
|
+
target: this.target.getRef(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/models/Node.ts
CHANGED
|
@@ -1,28 +1,51 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
2
|
import { validateType } from '../utils/typeValidator.js';
|
|
3
3
|
|
|
4
|
+
export interface Position {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let nodeCounter = 0;
|
|
10
|
+
const generatedRefs = new Set<string>();
|
|
11
|
+
|
|
4
12
|
export class Node {
|
|
5
13
|
id: number;
|
|
6
14
|
name: string;
|
|
7
15
|
description: string;
|
|
8
16
|
parameters: { [key: string]: Parameter };
|
|
9
17
|
keyMap: { [key: string]: string };
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
position?: Position;
|
|
19
|
+
ref: string;
|
|
20
|
+
class: string; // Updated to use class instead of type
|
|
12
21
|
|
|
13
|
-
constructor(node: { id: number; name: string; description: string; parameters: Parameter[],
|
|
22
|
+
constructor(node: { id: number; name: string; description: string; parameters: Parameter[], ref?: string, position?: Position, class: string }) {
|
|
14
23
|
this.id = node.id;
|
|
15
24
|
this.name = node.name;
|
|
16
25
|
this.description = node.description;
|
|
17
26
|
this.parameters = {};
|
|
18
27
|
this.keyMap = {};
|
|
28
|
+
this.class = node.class; // Set class property
|
|
29
|
+
|
|
30
|
+
if (node.ref) {
|
|
31
|
+
this.ref = node.ref;
|
|
32
|
+
} else {
|
|
33
|
+
this.ref = `n-${++nodeCounter}`;
|
|
34
|
+
while (generatedRefs.has(this.ref)) {
|
|
35
|
+
this.ref = `n-${++nodeCounter}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
generatedRefs.add(this.ref);
|
|
39
|
+
|
|
19
40
|
node.parameters.forEach(param => {
|
|
20
41
|
this.parameters[param.key] = { ...param, value: null };
|
|
21
42
|
const simplifiedKey = this.getSimplifiedKey(param.key);
|
|
22
43
|
this.keyMap[simplifiedKey] = param.key;
|
|
23
44
|
});
|
|
24
|
-
|
|
25
|
-
|
|
45
|
+
|
|
46
|
+
if (node.position) {
|
|
47
|
+
this.position = node.position;
|
|
48
|
+
}
|
|
26
49
|
}
|
|
27
50
|
|
|
28
51
|
setChainId(value: number): void {
|
|
@@ -38,9 +61,12 @@ export class Node {
|
|
|
38
61
|
this.setParameter(fullKey, value);
|
|
39
62
|
}
|
|
40
63
|
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
|
|
64
|
+
setPosition(x: number, y: number): void {
|
|
65
|
+
this.position = { x, y };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getRef(): string {
|
|
69
|
+
return this.ref;
|
|
44
70
|
}
|
|
45
71
|
|
|
46
72
|
protected setParameter(key: string, value: any): void {
|
|
@@ -74,10 +100,15 @@ export class Node {
|
|
|
74
100
|
toJSON(): { [key: string]: any } {
|
|
75
101
|
const json: { [key: string]: any } = {
|
|
76
102
|
id: this.id,
|
|
77
|
-
|
|
103
|
+
ref: this.ref,
|
|
104
|
+
type: this.class,
|
|
105
|
+
data: {
|
|
106
|
+
parameters: this.getParameters(),
|
|
107
|
+
}
|
|
78
108
|
};
|
|
79
|
-
if (this.
|
|
80
|
-
|
|
109
|
+
if (this.position) {
|
|
110
|
+
json.position = this.position;
|
|
111
|
+
}
|
|
81
112
|
return json;
|
|
82
113
|
}
|
|
83
114
|
|
package/src/models/Trigger.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
|
-
import { Node } from './Node.js';
|
|
2
|
+
import { Node, Position } from './Node.js';
|
|
3
3
|
|
|
4
4
|
export class Trigger extends Node {
|
|
5
5
|
type: number;
|
|
6
6
|
|
|
7
|
-
constructor(trigger: { id: number; name: string; description: string; type: number; parameters: Parameter[],
|
|
8
|
-
super(trigger);
|
|
7
|
+
constructor(trigger: { id: number; name: string; description: string; type: number; parameters: Parameter[], ref?: string, position?: Position }) {
|
|
8
|
+
super({ ...trigger, class: 'trigger' });
|
|
9
9
|
this.type = trigger.type;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -29,4 +29,4 @@ export class Trigger extends Node {
|
|
|
29
29
|
}
|
|
30
30
|
this.setParameter('interval', value);
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|
package/test/automation.spec.ts
CHANGED
|
@@ -9,24 +9,26 @@ describe('Automation Class', () => {
|
|
|
9
9
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
10
10
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
11
11
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
12
|
+
trigger.setPosition(0, 0);
|
|
12
13
|
|
|
13
14
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
14
15
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
15
16
|
action1.setParams("value", 1000);
|
|
16
17
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
17
18
|
action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
19
|
+
action1.setPosition(1, 0);
|
|
18
20
|
|
|
19
21
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
20
22
|
action2.setParams("phoneNumber", "+1234567890");
|
|
21
23
|
action2.setParams("text", "This is a test message");
|
|
24
|
+
action2.setPosition(2, 0);
|
|
22
25
|
|
|
23
|
-
const automation = new Automation("Test Automation", trigger,
|
|
26
|
+
const automation = new Automation("Test Automation", [trigger, action1, action2]);
|
|
24
27
|
|
|
25
28
|
const json = automation.toJSON();
|
|
26
29
|
expect(json).to.deep.equal({
|
|
27
30
|
name: "Test Automation",
|
|
28
|
-
|
|
29
|
-
actions: [action1.toJSON(), action2.toJSON()],
|
|
31
|
+
nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
|
|
@@ -34,8 +36,9 @@ describe('Automation Class', () => {
|
|
|
34
36
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
35
37
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
36
38
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
39
|
+
trigger.setPosition(0, 0);
|
|
37
40
|
|
|
38
|
-
const automation = new Automation("Initial Name", trigger);
|
|
41
|
+
const automation = new Automation("Initial Name", [trigger]);
|
|
39
42
|
automation.setName("Updated Name");
|
|
40
43
|
|
|
41
44
|
expect(automation.name).to.equal("Updated Name");
|
|
@@ -45,36 +48,41 @@ describe('Automation Class', () => {
|
|
|
45
48
|
const initialTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
46
49
|
initialTrigger.setChainId(CHAINS.ETHEREUM);
|
|
47
50
|
initialTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
51
|
+
initialTrigger.setPosition(0, 0);
|
|
48
52
|
|
|
49
53
|
const newTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
50
54
|
newTrigger.setChainId(CHAINS.ETHEREUM);
|
|
51
55
|
newTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
56
|
+
newTrigger.setPosition(1, 0);
|
|
52
57
|
|
|
53
|
-
const automation = new Automation("Test Automation", initialTrigger);
|
|
54
|
-
automation.
|
|
58
|
+
const automation = new Automation("Test Automation", [initialTrigger]);
|
|
59
|
+
automation.addNode(newTrigger);
|
|
55
60
|
|
|
56
|
-
expect(automation.
|
|
61
|
+
expect(automation.nodes).to.deep.equal([initialTrigger, newTrigger]);
|
|
57
62
|
});
|
|
58
63
|
|
|
59
64
|
it('should add actions to the automation', () => {
|
|
60
65
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
61
66
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
62
67
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
68
|
+
trigger.setPosition(0, 0);
|
|
63
69
|
|
|
64
70
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
65
71
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
66
72
|
action1.setParams("value", 1000);
|
|
67
73
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
68
74
|
action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
75
|
+
action1.setPosition(1, 0);
|
|
69
76
|
|
|
70
77
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
71
78
|
action2.setParams("phoneNumber", "+1234567890");
|
|
72
79
|
action2.setParams("text", "This is a test message");
|
|
80
|
+
action2.setPosition(2, 0);
|
|
73
81
|
|
|
74
|
-
const automation = new Automation("Test Automation", trigger);
|
|
75
|
-
automation.
|
|
76
|
-
automation.
|
|
82
|
+
const automation = new Automation("Test Automation", [trigger]);
|
|
83
|
+
automation.addNode(action1);
|
|
84
|
+
automation.addNode(action2);
|
|
77
85
|
|
|
78
|
-
expect(automation.
|
|
86
|
+
expect(automation.nodes).to.deep.equal([trigger, action1, action2]);
|
|
79
87
|
});
|
|
80
88
|
});
|
package/test/node.spec.ts
CHANGED
|
@@ -13,11 +13,11 @@ describe('Node Class', () => {
|
|
|
13
13
|
id: 1,
|
|
14
14
|
name: 'Test Node',
|
|
15
15
|
description: 'A node for testing',
|
|
16
|
-
parameters: DEFAULT_PARAMETERS
|
|
16
|
+
parameters: DEFAULT_PARAMETERS,
|
|
17
|
+
class: 'testClass'
|
|
17
18
|
});
|
|
18
19
|
|
|
19
|
-
expect(node.
|
|
20
|
-
expect(node.y).to.be.undefined;
|
|
20
|
+
expect(node.position).to.be.undefined;
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it('should create a node with coordinates', () => {
|
|
@@ -26,12 +26,12 @@ describe('Node Class', () => {
|
|
|
26
26
|
name: 'Test Node with Coordinates',
|
|
27
27
|
description: 'A node for testing with coordinates',
|
|
28
28
|
parameters: DEFAULT_PARAMETERS,
|
|
29
|
-
|
|
30
|
-
y: 200
|
|
29
|
+
class: 'testClass',
|
|
30
|
+
position: {x: 100, y: 200}
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
expect(node.x).to.equal(100);
|
|
34
|
-
expect(node.y).to.equal(200);
|
|
33
|
+
expect(node.position?.x).to.equal(100);
|
|
34
|
+
expect(node.position?.y).to.equal(200);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('should set and get coordinates correctly', () => {
|
|
@@ -39,12 +39,13 @@ describe('Node Class', () => {
|
|
|
39
39
|
id: 3,
|
|
40
40
|
name: 'Test Node for Coordinates',
|
|
41
41
|
description: 'A node for testing coordinate setting',
|
|
42
|
-
parameters: DEFAULT_PARAMETERS
|
|
42
|
+
parameters: DEFAULT_PARAMETERS,
|
|
43
|
+
class: 'testClass'
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
node.
|
|
46
|
-
expect(node.x).to.equal(300);
|
|
47
|
-
expect(node.y).to.equal(400);
|
|
46
|
+
node.setPosition(300, 400);
|
|
47
|
+
expect(node.position?.x).to.equal(300);
|
|
48
|
+
expect(node.position?.y).to.equal(400);
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
it('should create a node and set parameters correctly', () => {
|
|
@@ -52,7 +53,8 @@ describe('Node Class', () => {
|
|
|
52
53
|
id: 4,
|
|
53
54
|
name: 'Test Node for Parameters',
|
|
54
55
|
description: 'A node for testing parameter setting',
|
|
55
|
-
parameters: DEFAULT_PARAMETERS
|
|
56
|
+
parameters: DEFAULT_PARAMETERS,
|
|
57
|
+
class: 'testClass'
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
node.setChainId(1);
|
|
@@ -68,7 +70,8 @@ describe('Node Class', () => {
|
|
|
68
70
|
id: 5,
|
|
69
71
|
name: 'Test Node for JSON',
|
|
70
72
|
description: 'A node for testing JSON export',
|
|
71
|
-
parameters: DEFAULT_PARAMETERS
|
|
73
|
+
parameters: DEFAULT_PARAMETERS,
|
|
74
|
+
class: 'testClass'
|
|
72
75
|
});
|
|
73
76
|
|
|
74
77
|
node.setChainId(1);
|
|
@@ -77,9 +80,13 @@ describe('Node Class', () => {
|
|
|
77
80
|
const json = node.toJSON();
|
|
78
81
|
expect(json).to.deep.equal({
|
|
79
82
|
id: 5,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
ref: node.getRef(),
|
|
84
|
+
class: 'testClass',
|
|
85
|
+
data: {
|
|
86
|
+
parameters: {
|
|
87
|
+
chainId: 1,
|
|
88
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
91
|
});
|
|
85
92
|
});
|
|
@@ -90,8 +97,8 @@ describe('Node Class', () => {
|
|
|
90
97
|
name: 'Test Node for JSON with Coordinates',
|
|
91
98
|
description: 'A node for testing JSON export with coordinates',
|
|
92
99
|
parameters: DEFAULT_PARAMETERS,
|
|
93
|
-
|
|
94
|
-
y:
|
|
100
|
+
class: 'testClass',
|
|
101
|
+
position: {x: 1, y: 2}
|
|
95
102
|
});
|
|
96
103
|
|
|
97
104
|
node.setChainId(1);
|
|
@@ -100,12 +107,15 @@ describe('Node Class', () => {
|
|
|
100
107
|
const json = node.toJSON();
|
|
101
108
|
expect(json).to.deep.equal({
|
|
102
109
|
id: 6,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
ref: node.getRef(),
|
|
111
|
+
class: 'testClass',
|
|
112
|
+
data: {
|
|
113
|
+
parameters: {
|
|
114
|
+
chainId: 1,
|
|
115
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
116
|
+
}
|
|
106
117
|
},
|
|
107
|
-
x:
|
|
108
|
-
y: 200
|
|
118
|
+
position: {x: 1, y: 2}
|
|
109
119
|
});
|
|
110
120
|
});
|
|
111
121
|
|
|
@@ -114,7 +124,8 @@ describe('Node Class', () => {
|
|
|
114
124
|
id: 7,
|
|
115
125
|
name: 'Test Node for Invalid Parameter Type',
|
|
116
126
|
description: 'A node for testing invalid parameter type',
|
|
117
|
-
parameters: DEFAULT_PARAMETERS
|
|
127
|
+
parameters: DEFAULT_PARAMETERS,
|
|
128
|
+
class: 'testClass'
|
|
118
129
|
});
|
|
119
130
|
expect(() => node.setParams("chainId", "invalid")).to.throw('Invalid type for parameter chainId. Expected integer.');
|
|
120
131
|
});
|
|
@@ -124,7 +135,8 @@ describe('Node Class', () => {
|
|
|
124
135
|
id: 8,
|
|
125
136
|
name: 'Test Node for Invalid Address',
|
|
126
137
|
description: 'A node for testing invalid address',
|
|
127
|
-
parameters: DEFAULT_PARAMETERS
|
|
138
|
+
parameters: DEFAULT_PARAMETERS,
|
|
139
|
+
class: 'testClass'
|
|
128
140
|
});
|
|
129
141
|
expect(() => node.setParams("contractAddress", "invalid_address")).to.throw('Invalid type for parameter contractAddress. Expected address.');
|
|
130
142
|
});
|