otomato-sdk 1.2.0 → 1.3.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-action.js +2 -2
- package/dist/examples/create-automation.js +2 -8
- package/dist/examples/create-trigger.js +2 -2
- package/dist/examples/create-workflow.js +44 -0
- package/dist/examples/load-workflow.js +16 -0
- package/dist/examples/sandbox.js +18 -0
- package/dist/src/constants/Blocks.js +422 -293
- package/dist/src/index.js +1 -1
- package/dist/src/models/Edge.js +6 -1
- package/dist/src/models/Node.js +79 -6
- package/dist/src/models/Trigger.js +6 -3
- package/dist/src/models/Workflow.js +67 -0
- package/dist/src/services/ApiService.js +24 -18
- package/dist/src/utils/typeValidator.js +2 -1
- package/dist/test/action.spec.js +20 -17
- package/dist/test/automation.spec.js +26 -25
- package/dist/test/node.spec.js +34 -30
- package/dist/test/trigger.spec.js +8 -3
- package/dist/test/typeValidator.spec.js +2 -1
- package/dist/types/examples/create-workflow.d.ts +1 -0
- package/dist/types/examples/load-workflow.d.ts +1 -0
- package/dist/types/examples/sandbox.d.ts +1 -0
- package/dist/types/src/constants/Blocks.d.ts +101 -29
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/models/Action.d.ts +2 -1
- package/dist/types/src/models/Edge.d.ts +3 -0
- package/dist/types/src/models/Node.d.ts +9 -2
- package/dist/types/src/models/Parameter.d.ts +1 -1
- package/dist/types/src/models/Trigger.d.ts +3 -1
- package/dist/types/src/models/Workflow.d.ts +26 -0
- package/dist/types/src/services/ApiService.d.ts +8 -3
- package/examples/create-action.ts +2 -2
- package/examples/create-trigger.ts +2 -2
- package/examples/create-workflow.ts +44 -0
- package/examples/load-workflow.ts +10 -0
- package/package.json +2 -3
- package/src/constants/Blocks.ts +422 -292
- package/src/index.ts +1 -1
- package/src/models/Action.ts +1 -1
- package/src/models/Condition.ts +5 -5
- package/src/models/Edge.ts +8 -2
- package/src/models/Node.ts +90 -10
- package/src/models/Parameter.ts +5 -5
- package/src/models/Trigger.ts +9 -5
- package/src/models/Workflow.ts +69 -0
- package/src/services/ApiService.ts +26 -19
- package/src/utils/typeValidator.ts +2 -1
- package/test/action.spec.ts +11 -9
- package/test/automation.spec.ts +27 -26
- package/test/node.spec.ts +34 -30
- package/test/trigger.spec.ts +8 -3
- package/test/typeValidator.spec.ts +2 -1
- package/examples/create-automation.ts +0 -41
- package/src/constants/json.json +0 -16
- package/src/models/Automation.ts +0 -47
package/test/node.spec.ts
CHANGED
|
@@ -10,11 +10,12 @@ describe('Node Class', () => {
|
|
|
10
10
|
|
|
11
11
|
it('should create a node without coordinates', () => {
|
|
12
12
|
const node = new Node({
|
|
13
|
-
|
|
13
|
+
blockId: 1,
|
|
14
14
|
name: 'Test Node',
|
|
15
15
|
description: 'A node for testing',
|
|
16
16
|
parameters: DEFAULT_PARAMETERS,
|
|
17
|
-
class: 'testClass'
|
|
17
|
+
class: 'testClass',
|
|
18
|
+
image: 'a',
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
expect(node.position).to.be.undefined;
|
|
@@ -22,12 +23,13 @@ describe('Node Class', () => {
|
|
|
22
23
|
|
|
23
24
|
it('should create a node with coordinates', () => {
|
|
24
25
|
const node = new Node({
|
|
25
|
-
|
|
26
|
+
blockId: 2,
|
|
26
27
|
name: 'Test Node with Coordinates',
|
|
27
28
|
description: 'A node for testing with coordinates',
|
|
28
29
|
parameters: DEFAULT_PARAMETERS,
|
|
29
30
|
class: 'testClass',
|
|
30
|
-
position: {x: 100, y: 200}
|
|
31
|
+
position: {x: 100, y: 200},
|
|
32
|
+
image: 'a',
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
expect(node.position?.x).to.equal(100);
|
|
@@ -36,11 +38,12 @@ describe('Node Class', () => {
|
|
|
36
38
|
|
|
37
39
|
it('should set and get coordinates correctly', () => {
|
|
38
40
|
const node = new Node({
|
|
39
|
-
|
|
41
|
+
blockId: 3,
|
|
40
42
|
name: 'Test Node for Coordinates',
|
|
41
43
|
description: 'A node for testing coordinate setting',
|
|
42
44
|
parameters: DEFAULT_PARAMETERS,
|
|
43
|
-
class: 'testClass'
|
|
45
|
+
class: 'testClass',
|
|
46
|
+
image: 'a',
|
|
44
47
|
});
|
|
45
48
|
|
|
46
49
|
node.setPosition(300, 400);
|
|
@@ -50,11 +53,12 @@ describe('Node Class', () => {
|
|
|
50
53
|
|
|
51
54
|
it('should create a node and set parameters correctly', () => {
|
|
52
55
|
const node = new Node({
|
|
53
|
-
|
|
56
|
+
blockId: 4,
|
|
54
57
|
name: 'Test Node for Parameters',
|
|
55
58
|
description: 'A node for testing parameter setting',
|
|
56
59
|
parameters: DEFAULT_PARAMETERS,
|
|
57
|
-
class: 'testClass'
|
|
60
|
+
class: 'testClass',
|
|
61
|
+
image: 'a',
|
|
58
62
|
});
|
|
59
63
|
|
|
60
64
|
node.setChainId(1);
|
|
@@ -67,11 +71,12 @@ describe('Node Class', () => {
|
|
|
67
71
|
|
|
68
72
|
it('should be able to export a node as json without coordinates', () => {
|
|
69
73
|
const node = new Node({
|
|
70
|
-
|
|
74
|
+
blockId: 5,
|
|
71
75
|
name: 'Test Node for JSON',
|
|
72
76
|
description: 'A node for testing JSON export',
|
|
73
77
|
parameters: DEFAULT_PARAMETERS,
|
|
74
|
-
class: 'testClass'
|
|
78
|
+
class: 'testClass',
|
|
79
|
+
image: 'a',
|
|
75
80
|
});
|
|
76
81
|
|
|
77
82
|
node.setChainId(1);
|
|
@@ -79,26 +84,25 @@ describe('Node Class', () => {
|
|
|
79
84
|
|
|
80
85
|
const json = node.toJSON();
|
|
81
86
|
expect(json).to.deep.equal({
|
|
82
|
-
|
|
87
|
+
blockId: 5,
|
|
83
88
|
ref: node.getRef(),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
89
|
-
}
|
|
89
|
+
type: 'testClass',
|
|
90
|
+
parameters: {
|
|
91
|
+
chainId: 1,
|
|
92
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
90
93
|
}
|
|
91
94
|
});
|
|
92
95
|
});
|
|
93
96
|
|
|
94
97
|
it('should be able to export a node as json with coordinates', () => {
|
|
95
98
|
const node = new Node({
|
|
96
|
-
|
|
99
|
+
blockId: 6,
|
|
97
100
|
name: 'Test Node for JSON with Coordinates',
|
|
98
101
|
description: 'A node for testing JSON export with coordinates',
|
|
99
102
|
parameters: DEFAULT_PARAMETERS,
|
|
100
103
|
class: 'testClass',
|
|
101
|
-
position: {x: 1, y: 2}
|
|
104
|
+
position: {x: 1, y: 2},
|
|
105
|
+
image: 'a',
|
|
102
106
|
});
|
|
103
107
|
|
|
104
108
|
node.setChainId(1);
|
|
@@ -106,14 +110,12 @@ describe('Node Class', () => {
|
|
|
106
110
|
|
|
107
111
|
const json = node.toJSON();
|
|
108
112
|
expect(json).to.deep.equal({
|
|
109
|
-
|
|
113
|
+
type: 'testClass',
|
|
114
|
+
blockId: 6,
|
|
110
115
|
ref: node.getRef(),
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
chainId: 1,
|
|
115
|
-
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
116
|
-
}
|
|
116
|
+
parameters: {
|
|
117
|
+
chainId: 1,
|
|
118
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
117
119
|
},
|
|
118
120
|
position: {x: 1, y: 2}
|
|
119
121
|
});
|
|
@@ -121,22 +123,24 @@ describe('Node Class', () => {
|
|
|
121
123
|
|
|
122
124
|
it('should throw an error for invalid parameter type', () => {
|
|
123
125
|
const node = new Node({
|
|
124
|
-
|
|
126
|
+
blockId: 7,
|
|
125
127
|
name: 'Test Node for Invalid Parameter Type',
|
|
126
128
|
description: 'A node for testing invalid parameter type',
|
|
127
129
|
parameters: DEFAULT_PARAMETERS,
|
|
128
|
-
class: 'testClass'
|
|
130
|
+
class: 'testClass',
|
|
131
|
+
image: 'a',
|
|
129
132
|
});
|
|
130
133
|
expect(() => node.setParams("chainId", "invalid")).to.throw('Invalid type for parameter chainId. Expected integer.');
|
|
131
134
|
});
|
|
132
135
|
|
|
133
136
|
it('should throw an error for invalid address', () => {
|
|
134
137
|
const node = new Node({
|
|
135
|
-
|
|
138
|
+
blockId: 8,
|
|
136
139
|
name: 'Test Node for Invalid Address',
|
|
137
140
|
description: 'A node for testing invalid address',
|
|
138
141
|
parameters: DEFAULT_PARAMETERS,
|
|
139
|
-
class: 'testClass'
|
|
142
|
+
class: 'testClass',
|
|
143
|
+
image: 'a',
|
|
140
144
|
});
|
|
141
145
|
expect(() => node.setParams("contractAddress", "invalid_address")).to.throw('Invalid type for parameter contractAddress. Expected address.');
|
|
142
146
|
});
|
package/test/trigger.spec.ts
CHANGED
|
@@ -37,12 +37,16 @@ describe('Trigger Class', () => {
|
|
|
37
37
|
transferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
38
38
|
|
|
39
39
|
const json = transferTrigger.toJSON();
|
|
40
|
+
console.log(json);
|
|
40
41
|
expect(json).to.deep.equal({
|
|
41
|
-
|
|
42
|
+
blockId: TRIGGERS.TOKENS.ERC20.TRANSFER.blockId,
|
|
43
|
+
ref: transferTrigger.getRef(),
|
|
44
|
+
type: 'trigger',
|
|
42
45
|
parameters: {
|
|
43
46
|
chainId: CHAINS.ETHEREUM,
|
|
44
47
|
'abiParams.value': 1000,
|
|
45
48
|
'abiParams.to': DEFAULT_ADDRESS,
|
|
49
|
+
'abiParams.from': null,
|
|
46
50
|
contractAddress: getToken(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
47
51
|
}
|
|
48
52
|
});
|
|
@@ -53,7 +57,7 @@ describe('Trigger Class', () => {
|
|
|
53
57
|
balanceTrigger.setChainId(CHAINS.ETHEREUM);
|
|
54
58
|
balanceTrigger.setParams("account", DEFAULT_ADDRESS);
|
|
55
59
|
balanceTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
56
|
-
balanceTrigger.setCondition("
|
|
60
|
+
balanceTrigger.setCondition("gte");
|
|
57
61
|
balanceTrigger.setComparisonValue(45000);
|
|
58
62
|
balanceTrigger.setInterval(5000);
|
|
59
63
|
|
|
@@ -61,7 +65,8 @@ describe('Trigger Class', () => {
|
|
|
61
65
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
62
66
|
expect(params['abiParams.account']).to.equal(DEFAULT_ADDRESS);
|
|
63
67
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
64
|
-
|
|
68
|
+
console.log(balanceTrigger.toJSON());
|
|
69
|
+
expect(balanceTrigger.toJSON().parameters.condition).to.equal("gte");
|
|
65
70
|
expect(balanceTrigger.toJSON().parameters.comparisonValue).to.equal(45000);
|
|
66
71
|
expect(balanceTrigger.toJSON().parameters.interval).to.equal(5000);
|
|
67
72
|
});
|
|
@@ -58,7 +58,8 @@ describe('Type Validator Utility Functions', () => {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('should validate logic operators', () => {
|
|
61
|
-
expect(validateType('logic_operator', '
|
|
61
|
+
expect(validateType('logic_operator', 'gte')).to.be.true;
|
|
62
|
+
expect(validateType('logic_operator', '>')).to.be.false;
|
|
62
63
|
expect(validateType('logic_operator', 'invalid_operator')).to.be.false;
|
|
63
64
|
});
|
|
64
65
|
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ACTIONS, Action, TRIGGERS, Trigger, Automation, CHAINS, getToken, Edge } from '../src/index.js';
|
|
2
|
-
|
|
3
|
-
const main = async () => {
|
|
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
|
-
});
|
|
12
|
-
usdcTransferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
13
|
-
usdcTransferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
14
|
-
usdcTransferTrigger.setPosition(0, 0);
|
|
15
|
-
|
|
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
|
-
});
|
|
23
|
-
slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
24
|
-
slackAction.setParams("text", "USDC has been transferred!");
|
|
25
|
-
slackAction.setPosition(0, -10);
|
|
26
|
-
|
|
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);
|
|
35
|
-
|
|
36
|
-
console.log(JSON.stringify(automation.toJSON(), null, 2));
|
|
37
|
-
|
|
38
|
-
//await automation.save();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
main();
|
package/src/constants/json.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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/models/Automation.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Node } from './Node.js';
|
|
2
|
-
import { Edge } from './Edge.js';
|
|
3
|
-
import { apiServices } from '../services/ApiService.js';
|
|
4
|
-
|
|
5
|
-
export class Automation {
|
|
6
|
-
name: string;
|
|
7
|
-
nodes: Node[];
|
|
8
|
-
edges: Edge[];
|
|
9
|
-
|
|
10
|
-
constructor(name: string, nodes: Node[] = [], edges: Edge[] = []) {
|
|
11
|
-
this.name = name;
|
|
12
|
-
this.nodes = nodes;
|
|
13
|
-
this.edges = edges;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
setName(name: string): void {
|
|
17
|
-
this.name = name;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
addNode(node: Node): void {
|
|
21
|
-
this.nodes.push(node);
|
|
22
|
-
}
|
|
23
|
-
|
|
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);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
toJSON() {
|
|
37
|
-
return {
|
|
38
|
-
name: this.name,
|
|
39
|
-
nodes: this.nodes.map(node => node.toJSON()),
|
|
40
|
-
edges: this.edges.map(edge => edge.toJSON()),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async save() {
|
|
45
|
-
return apiServices.post('/workflows', this.toJSON());
|
|
46
|
-
}
|
|
47
|
-
}
|