otomato-sdk 1.2.0 → 1.2.1
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/sandbox.js +9 -0
- package/dist/src/constants/Blocks.js +379 -284
- package/dist/src/models/Node.js +11 -4
- package/dist/src/models/Trigger.js +6 -3
- package/dist/src/utils/typeValidator.js +2 -1
- package/dist/test/action.spec.js +19 -16
- package/dist/test/automation.spec.js +7 -6
- package/dist/test/node.spec.js +8 -12
- package/dist/test/trigger.spec.js +7 -2
- package/dist/test/typeValidator.spec.js +2 -1
- package/dist/types/examples/sandbox.d.ts +1 -0
- package/dist/types/src/constants/Blocks.d.ts +52 -14
- package/dist/types/src/models/Parameter.d.ts +1 -1
- package/dist/types/src/models/Trigger.d.ts +1 -0
- package/examples/create-action.ts +2 -2
- package/examples/create-automation.ts +2 -8
- package/examples/create-trigger.ts +2 -2
- package/examples/sandbox.ts +12 -0
- package/package.json +1 -1
- package/src/constants/Blocks.ts +379 -283
- package/src/models/Node.ts +10 -4
- package/src/models/Parameter.ts +1 -1
- package/src/models/Trigger.ts +8 -4
- package/src/utils/typeValidator.ts +2 -1
- package/test/action.spec.ts +10 -8
- package/test/automation.spec.ts +7 -6
- package/test/node.spec.ts +8 -12
- package/test/trigger.spec.ts +7 -2
- package/test/typeValidator.spec.ts +2 -1
- package/src/constants/json.json +0 -16
package/src/models/Node.ts
CHANGED
|
@@ -92,7 +92,15 @@ export class Node {
|
|
|
92
92
|
|
|
93
93
|
getParameters(): { [key: string]: any } {
|
|
94
94
|
return Object.keys(this.parameters).reduce((acc, key) => {
|
|
95
|
-
|
|
95
|
+
if (key.startsWith('abiParams.')) {
|
|
96
|
+
const abiKey = key.replace('abiParams.', '');
|
|
97
|
+
if (!acc.abi) {
|
|
98
|
+
acc.abi = { parameters: {} };
|
|
99
|
+
}
|
|
100
|
+
acc.abi.parameters[abiKey] = this.parameters[key].value;
|
|
101
|
+
} else {
|
|
102
|
+
acc[key] = this.parameters[key].value;
|
|
103
|
+
}
|
|
96
104
|
return acc;
|
|
97
105
|
}, {} as { [key: string]: any });
|
|
98
106
|
}
|
|
@@ -102,9 +110,7 @@ export class Node {
|
|
|
102
110
|
id: this.id,
|
|
103
111
|
ref: this.ref,
|
|
104
112
|
type: this.class,
|
|
105
|
-
|
|
106
|
-
parameters: this.getParameters(),
|
|
107
|
-
}
|
|
113
|
+
parameters: this.getParameters(),
|
|
108
114
|
};
|
|
109
115
|
if (this.position) {
|
|
110
116
|
json.position = this.position;
|
package/src/models/Parameter.ts
CHANGED
package/src/models/Trigger.ts
CHANGED
|
@@ -9,24 +9,28 @@ export class Trigger extends Node {
|
|
|
9
9
|
this.type = trigger.type;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
private notAPollingTrigger(): boolean {
|
|
13
|
+
return this.type === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
setCondition(value: string): void {
|
|
13
|
-
if (this.
|
|
17
|
+
if (this.notAPollingTrigger()) {
|
|
14
18
|
throw new Error('Condition setting is not applicable for subscription based triggers.');
|
|
15
19
|
}
|
|
16
20
|
this.setParameter('condition', value);
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
setComparisonValue(value: number): void {
|
|
20
|
-
if (this.
|
|
24
|
+
if (this.notAPollingTrigger()) {
|
|
21
25
|
throw new Error('Comparison value setting is not applicable for subscription based triggers.');
|
|
22
26
|
}
|
|
23
27
|
this.setParameter('comparisonValue', value);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
setInterval(value: number): void {
|
|
27
|
-
if (this.
|
|
31
|
+
if (this.notAPollingTrigger()) {
|
|
28
32
|
throw new Error('Interval setting is not applicable for subscription based triggers.');
|
|
29
33
|
}
|
|
30
34
|
this.setParameter('interval', value);
|
|
31
35
|
}
|
|
32
|
-
}
|
|
36
|
+
}
|
|
@@ -24,10 +24,11 @@ export function validateType(expectedType: string, value: any): boolean {
|
|
|
24
24
|
return typeof value === 'string' && isValidUrl(value);
|
|
25
25
|
case 'phone_number':
|
|
26
26
|
return typeof value === 'string' && isValidPhoneNumber(value);
|
|
27
|
+
case 'string':
|
|
27
28
|
case 'paragraph':
|
|
28
29
|
return typeof value === 'string';
|
|
29
30
|
case 'logic_operator':
|
|
30
|
-
const validOperators = new Set(['
|
|
31
|
+
const validOperators = new Set(['gte', 'gt', 'lte', 'lt', 'eq', 'neq']);
|
|
31
32
|
return typeof value === 'string' && validOperators.has(value);
|
|
32
33
|
case 'any':
|
|
33
34
|
return true;
|
package/test/action.spec.ts
CHANGED
|
@@ -39,6 +39,8 @@ describe('Action Class', () => {
|
|
|
39
39
|
const json = transferAction.toJSON();
|
|
40
40
|
expect(json).to.deep.equal({
|
|
41
41
|
id: ACTIONS.TOKENS.ERC20.TRANSFER.id,
|
|
42
|
+
ref: transferAction.getRef(),
|
|
43
|
+
type: 'action',
|
|
42
44
|
parameters: {
|
|
43
45
|
chainId: CHAINS.ETHEREUM,
|
|
44
46
|
'abiParams.value': 1000,
|
|
@@ -48,7 +50,7 @@ describe('Action Class', () => {
|
|
|
48
50
|
});
|
|
49
51
|
});
|
|
50
52
|
|
|
51
|
-
it('should create an SMS action and set parameters correctly', () => {
|
|
53
|
+
/*it('should create an SMS action and set parameters correctly', () => {
|
|
52
54
|
const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
53
55
|
smsAction.setParams("phoneNumber", "+1234567890");
|
|
54
56
|
smsAction.setParams("text", "Hello, this is a test message!");
|
|
@@ -56,16 +58,16 @@ describe('Action Class', () => {
|
|
|
56
58
|
const params = smsAction.getParameters();
|
|
57
59
|
expect(params.phoneNumber).to.equal("+1234567890");
|
|
58
60
|
expect(params.text).to.equal("Hello, this is a test message!");
|
|
59
|
-
})
|
|
61
|
+
});*/
|
|
60
62
|
|
|
61
63
|
it('should create a Slack action and set parameters correctly', () => {
|
|
62
|
-
const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK);
|
|
64
|
+
const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
63
65
|
slackAction.setParams("webhook", "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
64
|
-
slackAction.setParams("
|
|
66
|
+
slackAction.setParams("message", "This is a test message!");
|
|
65
67
|
|
|
66
68
|
const params = slackAction.getParameters();
|
|
67
69
|
expect(params.webhook).to.equal("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX");
|
|
68
|
-
expect(params.
|
|
70
|
+
expect(params.message).to.equal("This is a test message!");
|
|
69
71
|
});
|
|
70
72
|
|
|
71
73
|
it('should throw an error for invalid parameter type', () => {
|
|
@@ -79,12 +81,12 @@ describe('Action Class', () => {
|
|
|
79
81
|
});
|
|
80
82
|
|
|
81
83
|
it('should throw an error for invalid URL', () => {
|
|
82
|
-
const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK);
|
|
84
|
+
const slackAction = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
83
85
|
expect(() => slackAction.setParams("webhook", "invalid_url")).to.throw('Invalid type for parameter webhook. Expected url.');
|
|
84
86
|
});
|
|
85
87
|
|
|
86
|
-
it('should throw an error for invalid phone number', () => {
|
|
88
|
+
/*it('should throw an error for invalid phone number', () => {
|
|
87
89
|
const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
88
90
|
expect(() => smsAction.setParams("phoneNumber", "invalid_phone_number")).to.throw('Invalid type for parameter phoneNumber. Expected phone_number.');
|
|
89
|
-
})
|
|
91
|
+
});*/
|
|
90
92
|
});
|
package/test/automation.spec.ts
CHANGED
|
@@ -18,9 +18,9 @@ describe('Automation Class', () => {
|
|
|
18
18
|
action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
19
19
|
action1.setPosition(1, 0);
|
|
20
20
|
|
|
21
|
-
const action2 = new Action(ACTIONS.NOTIFICATIONS.
|
|
22
|
-
action2.setParams("
|
|
23
|
-
action2.setParams("
|
|
21
|
+
const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
22
|
+
action2.setParams("webhook", "https://webhook.url");
|
|
23
|
+
action2.setParams("message", "This is a test message");
|
|
24
24
|
action2.setPosition(2, 0);
|
|
25
25
|
|
|
26
26
|
const automation = new Automation("Test Automation", [trigger, action1, action2]);
|
|
@@ -29,6 +29,7 @@ describe('Automation Class', () => {
|
|
|
29
29
|
expect(json).to.deep.equal({
|
|
30
30
|
name: "Test Automation",
|
|
31
31
|
nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
|
|
32
|
+
edges: []
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -74,9 +75,9 @@ describe('Automation Class', () => {
|
|
|
74
75
|
action1.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
75
76
|
action1.setPosition(1, 0);
|
|
76
77
|
|
|
77
|
-
const action2 = new Action(ACTIONS.NOTIFICATIONS.
|
|
78
|
-
action2.setParams("
|
|
79
|
-
action2.setParams("
|
|
78
|
+
const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
79
|
+
action2.setParams("webhook", "https://webhook.url");
|
|
80
|
+
action2.setParams("message", "This is a test message");
|
|
80
81
|
action2.setPosition(2, 0);
|
|
81
82
|
|
|
82
83
|
const automation = new Automation("Test Automation", [trigger]);
|
package/test/node.spec.ts
CHANGED
|
@@ -81,12 +81,10 @@ describe('Node Class', () => {
|
|
|
81
81
|
expect(json).to.deep.equal({
|
|
82
82
|
id: 5,
|
|
83
83
|
ref: node.getRef(),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
89
|
-
}
|
|
84
|
+
type: 'testClass',
|
|
85
|
+
parameters: {
|
|
86
|
+
chainId: 1,
|
|
87
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
90
88
|
}
|
|
91
89
|
});
|
|
92
90
|
});
|
|
@@ -106,14 +104,12 @@ describe('Node Class', () => {
|
|
|
106
104
|
|
|
107
105
|
const json = node.toJSON();
|
|
108
106
|
expect(json).to.deep.equal({
|
|
107
|
+
type: 'testClass',
|
|
109
108
|
id: 6,
|
|
110
109
|
ref: node.getRef(),
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
chainId: 1,
|
|
115
|
-
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
116
|
-
}
|
|
110
|
+
parameters: {
|
|
111
|
+
chainId: 1,
|
|
112
|
+
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
117
113
|
},
|
|
118
114
|
position: {x: 1, y: 2}
|
|
119
115
|
});
|
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
|
id: TRIGGERS.TOKENS.ERC20.TRANSFER.id,
|
|
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
|
|
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
|
-
}
|