otomato-sdk 1.2.1 → 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-workflow.js +44 -0
- package/dist/examples/load-workflow.js +16 -0
- package/dist/examples/sandbox.js +18 -9
- package/dist/src/constants/Blocks.js +69 -35
- package/dist/src/index.js +1 -1
- package/dist/src/models/Edge.js +6 -1
- package/dist/src/models/Node.js +68 -2
- package/dist/src/models/Workflow.js +67 -0
- package/dist/src/services/ApiService.js +24 -18
- package/dist/test/action.spec.js +1 -1
- package/dist/test/automation.spec.js +19 -19
- package/dist/test/node.spec.js +26 -18
- package/dist/test/trigger.spec.js +1 -1
- package/dist/types/examples/create-workflow.d.ts +1 -0
- package/dist/types/examples/load-workflow.d.ts +1 -0
- package/dist/types/src/constants/Blocks.d.ts +55 -21
- 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/Trigger.d.ts +2 -1
- package/dist/types/src/models/Workflow.d.ts +26 -0
- package/dist/types/src/services/ApiService.d.ts +8 -3
- package/examples/create-workflow.ts +44 -0
- package/examples/load-workflow.ts +10 -0
- package/package.json +2 -3
- package/src/constants/Blocks.ts +69 -35
- 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 +80 -6
- package/src/models/Parameter.ts +5 -5
- package/src/models/Trigger.ts +1 -1
- package/src/models/Workflow.ts +69 -0
- package/src/services/ApiService.ts +26 -19
- package/test/action.spec.ts +1 -1
- package/test/automation.spec.ts +20 -20
- package/test/node.spec.ts +26 -18
- package/test/trigger.spec.ts +1 -1
- package/examples/create-automation.ts +0 -35
- package/examples/sandbox.ts +0 -12
- package/src/models/Automation.ts +0 -47
package/test/automation.spec.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import {
|
|
2
|
+
import { Workflow } from '../src/models/Workflow.js';
|
|
3
3
|
import { Trigger } from '../src/models/Trigger.js';
|
|
4
4
|
import { Action } from '../src/models/Action.js';
|
|
5
5
|
import { TRIGGERS, ACTIONS, getToken, CHAINS } from '../src/index.js';
|
|
6
6
|
|
|
7
|
-
describe('
|
|
8
|
-
it('should create
|
|
7
|
+
describe('Workflow Class', () => {
|
|
8
|
+
it('should create a workflow with a trigger and actions', () => {
|
|
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);
|
|
@@ -23,29 +23,29 @@ describe('Automation Class', () => {
|
|
|
23
23
|
action2.setParams("message", "This is a test message");
|
|
24
24
|
action2.setPosition(2, 0);
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const workflow = new Workflow("Test Workflow", [trigger, action1, action2]);
|
|
27
27
|
|
|
28
|
-
const json =
|
|
28
|
+
const json = workflow.toJSON();
|
|
29
29
|
expect(json).to.deep.equal({
|
|
30
|
-
name: "Test
|
|
30
|
+
name: "Test Workflow",
|
|
31
31
|
nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
|
|
32
32
|
edges: []
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it('should set the name of the
|
|
36
|
+
it('should set the name of the workflow', () => {
|
|
37
37
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
38
38
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
39
39
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
40
40
|
trigger.setPosition(0, 0);
|
|
41
41
|
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const workflow = new Workflow("Initial Name", [trigger]);
|
|
43
|
+
workflow.setName("Updated Name");
|
|
44
44
|
|
|
45
|
-
expect(
|
|
45
|
+
expect(workflow.name).to.equal("Updated Name");
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('should add a trigger to the
|
|
48
|
+
it('should add a trigger to the workflow', () => {
|
|
49
49
|
const initialTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
50
50
|
initialTrigger.setChainId(CHAINS.ETHEREUM);
|
|
51
51
|
initialTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
@@ -56,13 +56,13 @@ describe('Automation Class', () => {
|
|
|
56
56
|
newTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
57
57
|
newTrigger.setPosition(1, 0);
|
|
58
58
|
|
|
59
|
-
const
|
|
60
|
-
|
|
59
|
+
const workflow = new Workflow("Test Workflow", [initialTrigger]);
|
|
60
|
+
workflow.addNode(newTrigger);
|
|
61
61
|
|
|
62
|
-
expect(
|
|
62
|
+
expect(workflow.nodes).to.deep.equal([initialTrigger, newTrigger]);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it('should add actions to the
|
|
65
|
+
it('should add actions to the workflow', () => {
|
|
66
66
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
67
67
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
68
68
|
trigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
@@ -80,10 +80,10 @@ describe('Automation Class', () => {
|
|
|
80
80
|
action2.setParams("message", "This is a test message");
|
|
81
81
|
action2.setPosition(2, 0);
|
|
82
82
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const workflow = new Workflow("Test Workflow", [trigger]);
|
|
84
|
+
workflow.addNode(action1);
|
|
85
|
+
workflow.addNode(action2);
|
|
86
86
|
|
|
87
|
-
expect(
|
|
87
|
+
expect(workflow.nodes).to.deep.equal([trigger, action1, action2]);
|
|
88
88
|
});
|
|
89
|
-
});
|
|
89
|
+
});
|
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,7 +84,7 @@ 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
89
|
type: 'testClass',
|
|
85
90
|
parameters: {
|
|
@@ -91,12 +96,13 @@ describe('Node Class', () => {
|
|
|
91
96
|
|
|
92
97
|
it('should be able to export a node as json with coordinates', () => {
|
|
93
98
|
const node = new Node({
|
|
94
|
-
|
|
99
|
+
blockId: 6,
|
|
95
100
|
name: 'Test Node for JSON with Coordinates',
|
|
96
101
|
description: 'A node for testing JSON export with coordinates',
|
|
97
102
|
parameters: DEFAULT_PARAMETERS,
|
|
98
103
|
class: 'testClass',
|
|
99
|
-
position: {x: 1, y: 2}
|
|
104
|
+
position: {x: 1, y: 2},
|
|
105
|
+
image: 'a',
|
|
100
106
|
});
|
|
101
107
|
|
|
102
108
|
node.setChainId(1);
|
|
@@ -105,7 +111,7 @@ describe('Node Class', () => {
|
|
|
105
111
|
const json = node.toJSON();
|
|
106
112
|
expect(json).to.deep.equal({
|
|
107
113
|
type: 'testClass',
|
|
108
|
-
|
|
114
|
+
blockId: 6,
|
|
109
115
|
ref: node.getRef(),
|
|
110
116
|
parameters: {
|
|
111
117
|
chainId: 1,
|
|
@@ -117,22 +123,24 @@ describe('Node Class', () => {
|
|
|
117
123
|
|
|
118
124
|
it('should throw an error for invalid parameter type', () => {
|
|
119
125
|
const node = new Node({
|
|
120
|
-
|
|
126
|
+
blockId: 7,
|
|
121
127
|
name: 'Test Node for Invalid Parameter Type',
|
|
122
128
|
description: 'A node for testing invalid parameter type',
|
|
123
129
|
parameters: DEFAULT_PARAMETERS,
|
|
124
|
-
class: 'testClass'
|
|
130
|
+
class: 'testClass',
|
|
131
|
+
image: 'a',
|
|
125
132
|
});
|
|
126
133
|
expect(() => node.setParams("chainId", "invalid")).to.throw('Invalid type for parameter chainId. Expected integer.');
|
|
127
134
|
});
|
|
128
135
|
|
|
129
136
|
it('should throw an error for invalid address', () => {
|
|
130
137
|
const node = new Node({
|
|
131
|
-
|
|
138
|
+
blockId: 8,
|
|
132
139
|
name: 'Test Node for Invalid Address',
|
|
133
140
|
description: 'A node for testing invalid address',
|
|
134
141
|
parameters: DEFAULT_PARAMETERS,
|
|
135
|
-
class: 'testClass'
|
|
142
|
+
class: 'testClass',
|
|
143
|
+
image: 'a',
|
|
136
144
|
});
|
|
137
145
|
expect(() => node.setParams("contractAddress", "invalid_address")).to.throw('Invalid type for parameter contractAddress. Expected address.');
|
|
138
146
|
});
|
package/test/trigger.spec.ts
CHANGED
|
@@ -39,7 +39,7 @@ describe('Trigger Class', () => {
|
|
|
39
39
|
const json = transferTrigger.toJSON();
|
|
40
40
|
console.log(json);
|
|
41
41
|
expect(json).to.deep.equal({
|
|
42
|
-
|
|
42
|
+
blockId: TRIGGERS.TOKENS.ERC20.TRANSFER.blockId,
|
|
43
43
|
ref: transferTrigger.getRef(),
|
|
44
44
|
type: 'trigger',
|
|
45
45
|
parameters: {
|
|
@@ -1,35 +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(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
17
|
-
slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
18
|
-
slackAction.setParams("message", "USDC has been transferred!");
|
|
19
|
-
slackAction.setPosition(0, -10);
|
|
20
|
-
|
|
21
|
-
const automation = new Automation("USDC Transfer Notification", [usdcTransferTrigger, slackAction]);
|
|
22
|
-
|
|
23
|
-
const edge = new Edge({
|
|
24
|
-
source: usdcTransferTrigger,
|
|
25
|
-
target: slackAction,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
automation.addEdge(edge);
|
|
29
|
-
|
|
30
|
-
console.log(JSON.stringify(automation.toJSON(), null, 2));
|
|
31
|
-
|
|
32
|
-
//await automation.save();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
main();
|
package/examples/sandbox.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { TRIGGERS, getToken, CHAINS, Trigger } from '../src/index.js';
|
|
2
|
-
|
|
3
|
-
const trigger = new Trigger(TRIGGERS.PRICE_ACTION.ON_CHAIN_PRICE_MOVEMENT.PRICE_MOVEMENT_AGAINST_CURRENCY);
|
|
4
|
-
|
|
5
|
-
trigger.setChainId(CHAINS.MODE);
|
|
6
|
-
trigger.setComparisonValue(3200);
|
|
7
|
-
trigger.setCondition("gte");
|
|
8
|
-
trigger.setParams('currency', 'USD');
|
|
9
|
-
trigger.setParams('contractAddress', getToken(CHAINS.MODE, 'MODE').contractAddress);
|
|
10
|
-
trigger.setPosition(1, 0);
|
|
11
|
-
|
|
12
|
-
console.log(JSON.stringify(trigger.toJSON(), null, 2));
|
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
|
-
}
|