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/src/constants/Blocks.ts
CHANGED
|
@@ -9,11 +9,12 @@ const TRIGGER_TYPE = {
|
|
|
9
9
|
export const TRIGGERS = {
|
|
10
10
|
"TOKENS": {
|
|
11
11
|
"ERC20": {
|
|
12
|
-
"
|
|
12
|
+
"description": "The most used standard for tokens on ethereum compatible blockchains",
|
|
13
|
+
"chains": [
|
|
13
14
|
0
|
|
14
15
|
],
|
|
16
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp",
|
|
15
17
|
"TRANSFER": {
|
|
16
|
-
"id": 1,
|
|
17
18
|
"name": "Transfer token",
|
|
18
19
|
"description": "This block gets triggered when someone transfers the ERC20 configured in the params",
|
|
19
20
|
"type": 0,
|
|
@@ -45,10 +46,11 @@ export const TRIGGERS = {
|
|
|
45
46
|
"description": "The contract address of the ERC20",
|
|
46
47
|
"mandatory": true
|
|
47
48
|
},
|
|
48
|
-
] as Parameter[]
|
|
49
|
+
] as Parameter[],
|
|
50
|
+
"blockId": 1,
|
|
51
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
|
|
49
52
|
},
|
|
50
53
|
"BALANCE": {
|
|
51
|
-
"id": 5,
|
|
52
54
|
"name": "ERC20 balance check",
|
|
53
55
|
"description": "Fetches the balance of an ERC20 and checks it against the specified condition.",
|
|
54
56
|
"type": 1,
|
|
@@ -85,17 +87,20 @@ export const TRIGGERS = {
|
|
|
85
87
|
"type": "integer",
|
|
86
88
|
"description": "The waiting time between each polling"
|
|
87
89
|
},
|
|
88
|
-
] as Parameter[]
|
|
90
|
+
] as Parameter[],
|
|
91
|
+
"blockId": 5,
|
|
92
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
},
|
|
92
96
|
"YIELD": {
|
|
93
97
|
"SPLICE_FI": {
|
|
94
|
-
"
|
|
98
|
+
"description": "Split any yield-bearing asset into separate yield and principal components",
|
|
99
|
+
"chains": [
|
|
95
100
|
43334
|
|
96
101
|
],
|
|
102
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png",
|
|
97
103
|
"SWAP": {
|
|
98
|
-
"id": 2,
|
|
99
104
|
"name": "Splice Finance Swap",
|
|
100
105
|
"description": "Swap in Splice Finance",
|
|
101
106
|
"type": 0,
|
|
@@ -126,10 +131,11 @@ export const TRIGGERS = {
|
|
|
126
131
|
"type": "int256",
|
|
127
132
|
"description": "Net SY to account"
|
|
128
133
|
},
|
|
129
|
-
] as Parameter[]
|
|
134
|
+
] as Parameter[],
|
|
135
|
+
"blockId": 2,
|
|
136
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png"
|
|
130
137
|
},
|
|
131
138
|
"LIQUIDITY_REMOVED": {
|
|
132
|
-
"id": 6,
|
|
133
139
|
"name": "Liquidity Removed",
|
|
134
140
|
"description": "Liquidity removed in Splice Finance",
|
|
135
141
|
"type": 0,
|
|
@@ -165,10 +171,11 @@ export const TRIGGERS = {
|
|
|
165
171
|
"type": "uint256",
|
|
166
172
|
"description": "Net SY out"
|
|
167
173
|
},
|
|
168
|
-
] as Parameter[]
|
|
174
|
+
] as Parameter[],
|
|
175
|
+
"blockId": 6,
|
|
176
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png"
|
|
169
177
|
},
|
|
170
178
|
"MARKET_CREATION": {
|
|
171
|
-
"id": 7,
|
|
172
179
|
"name": "Market Creation",
|
|
173
180
|
"description": "Market creation in Splice Finance",
|
|
174
181
|
"type": 0,
|
|
@@ -199,10 +206,11 @@ export const TRIGGERS = {
|
|
|
199
206
|
"type": "uint256",
|
|
200
207
|
"description": "LN fee rate root"
|
|
201
208
|
},
|
|
202
|
-
] as Parameter[]
|
|
209
|
+
] as Parameter[],
|
|
210
|
+
"blockId": 7,
|
|
211
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png"
|
|
203
212
|
},
|
|
204
213
|
"INTEREST_RATE_UPDATE": {
|
|
205
|
-
"id": 9,
|
|
206
214
|
"name": "Interest Rate Update",
|
|
207
215
|
"description": "Interest rate update in Splice Finance",
|
|
208
216
|
"type": 0,
|
|
@@ -230,17 +238,20 @@ export const TRIGGERS = {
|
|
|
230
238
|
"0xbF14932e1A7962C77D0b31be80075936bE1A43D4"
|
|
231
239
|
]
|
|
232
240
|
},
|
|
233
|
-
] as Parameter[]
|
|
241
|
+
] as Parameter[],
|
|
242
|
+
"blockId": 9,
|
|
243
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/splicefi.png"
|
|
234
244
|
}
|
|
235
245
|
}
|
|
236
246
|
},
|
|
237
247
|
"LENDING": {
|
|
238
248
|
"ASTARIA": {
|
|
239
|
-
"
|
|
249
|
+
"description": "Astaria is an oracle-less, intent-based, fixed-rate lending protocol supporting unlimited loan durations for any asset",
|
|
250
|
+
"chains": [
|
|
240
251
|
43334
|
|
241
252
|
],
|
|
253
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/astaria.png",
|
|
242
254
|
"LEND_RECALLED": {
|
|
243
|
-
"id": 8,
|
|
244
255
|
"name": "Lend Recalled",
|
|
245
256
|
"description": "Lend recalled in Astaria",
|
|
246
257
|
"type": 0,
|
|
@@ -261,18 +272,21 @@ export const TRIGGERS = {
|
|
|
261
272
|
"type": "uint256",
|
|
262
273
|
"description": "End time"
|
|
263
274
|
},
|
|
264
|
-
] as Parameter[]
|
|
275
|
+
] as Parameter[],
|
|
276
|
+
"blockId": 8,
|
|
277
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/astaria.png"
|
|
265
278
|
}
|
|
266
279
|
}
|
|
267
280
|
},
|
|
268
281
|
"DEXES": {
|
|
269
282
|
"ODOS": {
|
|
270
|
-
"
|
|
283
|
+
"description": "Smart Order Routing across multiple blockchain protocols, 700+ Liquidity Sources and thousands of token pairs, delivering ultimate savings to users",
|
|
284
|
+
"chains": [
|
|
271
285
|
43334,
|
|
272
286
|
1
|
|
273
287
|
],
|
|
288
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/odos.jpg",
|
|
274
289
|
"SWAP": {
|
|
275
|
-
"id": 4,
|
|
276
290
|
"name": "Odos Swap",
|
|
277
291
|
"description": "Swap on Odos",
|
|
278
292
|
"type": 0,
|
|
@@ -309,17 +323,20 @@ export const TRIGGERS = {
|
|
|
309
323
|
"type": "address",
|
|
310
324
|
"description": "Output token address"
|
|
311
325
|
},
|
|
312
|
-
] as Parameter[]
|
|
326
|
+
] as Parameter[],
|
|
327
|
+
"blockId": 4,
|
|
328
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/odos.jpg"
|
|
313
329
|
}
|
|
314
330
|
}
|
|
315
331
|
},
|
|
316
332
|
"SOCIALS": {
|
|
317
333
|
"MODE_NAME_SERVICE": {
|
|
318
|
-
"
|
|
334
|
+
"description": "Next generation of Mode Mainnet Domains",
|
|
335
|
+
"chains": [
|
|
319
336
|
43334
|
|
320
337
|
],
|
|
338
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/modens.png",
|
|
321
339
|
"NAME_REGISTERED": {
|
|
322
|
-
"id": 3,
|
|
323
340
|
"name": "Name Registered",
|
|
324
341
|
"description": "Name registered in Mode Name Service",
|
|
325
342
|
"type": 0,
|
|
@@ -340,17 +357,20 @@ export const TRIGGERS = {
|
|
|
340
357
|
"type": "uint256",
|
|
341
358
|
"description": "Expiration time"
|
|
342
359
|
},
|
|
343
|
-
] as Parameter[]
|
|
360
|
+
] as Parameter[],
|
|
361
|
+
"blockId": 3,
|
|
362
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/modens.png"
|
|
344
363
|
}
|
|
345
364
|
}
|
|
346
365
|
},
|
|
347
366
|
"PRICE_ACTION": {
|
|
348
367
|
"ON_CHAIN_PRICE_MOVEMENT": {
|
|
349
|
-
"
|
|
368
|
+
"description": "Triggers based on the movement of on-chain prices against specified currencies",
|
|
369
|
+
"chains": [
|
|
350
370
|
0
|
|
351
371
|
],
|
|
372
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/trend-up.png",
|
|
352
373
|
"PRICE_MOVEMENT_AGAINST_CURRENCY": {
|
|
353
|
-
"id": 10,
|
|
354
374
|
"name": "On-Chain Price Movement Against Fiat Currency",
|
|
355
375
|
"description": "This trigger activates when the on-chain price of an asset moves against a specified currency based on the given condition.",
|
|
356
376
|
"type": 2,
|
|
@@ -383,7 +403,9 @@ export const TRIGGERS = {
|
|
|
383
403
|
"type": "erc20",
|
|
384
404
|
"description": "The asset that you want to track"
|
|
385
405
|
},
|
|
386
|
-
] as Parameter[]
|
|
406
|
+
] as Parameter[],
|
|
407
|
+
"blockId": 10,
|
|
408
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/trend-up.png"
|
|
387
409
|
}
|
|
388
410
|
}
|
|
389
411
|
}
|
|
@@ -392,8 +414,9 @@ export const TRIGGERS = {
|
|
|
392
414
|
export const ACTIONS = {
|
|
393
415
|
"NOTIFICATIONS": {
|
|
394
416
|
"SLACK": {
|
|
417
|
+
"description": "Slack is a messaging app for businesses that connects people to the information they need.",
|
|
418
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/slack.png",
|
|
395
419
|
"SEND_MESSAGE": {
|
|
396
|
-
"id": 100002,
|
|
397
420
|
"name": "Send message",
|
|
398
421
|
"type": 0,
|
|
399
422
|
"description": "Notifies you by sending a Slack message to the channel of your choice",
|
|
@@ -408,12 +431,15 @@ export const ACTIONS = {
|
|
|
408
431
|
"type": "paragraph",
|
|
409
432
|
"description": "The text content to send"
|
|
410
433
|
},
|
|
411
|
-
] as Parameter[]
|
|
434
|
+
] as Parameter[],
|
|
435
|
+
"blockId": 100002,
|
|
436
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/slack.png"
|
|
412
437
|
}
|
|
413
438
|
},
|
|
414
439
|
"DISCORD": {
|
|
440
|
+
"description": "Discord is a communication service to talk with your favorite communities.",
|
|
441
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/discord.png",
|
|
415
442
|
"SEND_MESSAGE": {
|
|
416
|
-
"id": 100003,
|
|
417
443
|
"name": "Send message",
|
|
418
444
|
"type": 0,
|
|
419
445
|
"description": "Notifies you by sending a Discord message to the channel of your choice",
|
|
@@ -428,12 +454,15 @@ export const ACTIONS = {
|
|
|
428
454
|
"type": "paragraph",
|
|
429
455
|
"description": "The text content to send"
|
|
430
456
|
},
|
|
431
|
-
] as Parameter[]
|
|
457
|
+
] as Parameter[],
|
|
458
|
+
"blockId": 100003,
|
|
459
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/discord.png"
|
|
432
460
|
}
|
|
433
461
|
},
|
|
434
462
|
"TELEGRAM": {
|
|
463
|
+
"description": "Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.",
|
|
464
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/telegram.jpeg",
|
|
435
465
|
"SEND_MESSAGE": {
|
|
436
|
-
"id": 100001,
|
|
437
466
|
"name": "Send message",
|
|
438
467
|
"type": 0,
|
|
439
468
|
"description": "Notifies you by sending a Telegram message to the chat of your choice",
|
|
@@ -448,17 +477,20 @@ export const ACTIONS = {
|
|
|
448
477
|
"type": "paragraph",
|
|
449
478
|
"description": "The text content to send"
|
|
450
479
|
},
|
|
451
|
-
] as Parameter[]
|
|
480
|
+
] as Parameter[],
|
|
481
|
+
"blockId": 100001,
|
|
482
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/telegram.jpeg"
|
|
452
483
|
}
|
|
453
484
|
}
|
|
454
485
|
},
|
|
455
486
|
"TOKENS": {
|
|
456
487
|
"ERC20": {
|
|
457
|
-
"
|
|
488
|
+
"description": "The most used standard for tokens on ethereum compatible blockchains",
|
|
489
|
+
"chains": [
|
|
458
490
|
0
|
|
459
491
|
],
|
|
492
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp",
|
|
460
493
|
"TRANSFER": {
|
|
461
|
-
"id": 100004,
|
|
462
494
|
"name": "Transfer token",
|
|
463
495
|
"description": "Transfers an ERC20 token",
|
|
464
496
|
"type": 1,
|
|
@@ -484,7 +516,9 @@ export const ACTIONS = {
|
|
|
484
516
|
"type": "erc20",
|
|
485
517
|
"description": "The contract address of the ERC20"
|
|
486
518
|
},
|
|
487
|
-
] as Parameter[]
|
|
519
|
+
] as Parameter[],
|
|
520
|
+
"blockId": 100004,
|
|
521
|
+
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
|
|
488
522
|
}
|
|
489
523
|
}
|
|
490
524
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './constants/tokens.js';
|
|
|
5
5
|
|
|
6
6
|
// Exporting models
|
|
7
7
|
export * from './models/Action.js';
|
|
8
|
-
export * from './models/
|
|
8
|
+
export * from './models/Workflow.js';
|
|
9
9
|
export * from './models/Condition.js';
|
|
10
10
|
export * from './models/Parameter.js';
|
|
11
11
|
export * from './models/Trigger.js';
|
package/src/models/Action.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Parameter } from './Parameter.js';
|
|
|
2
2
|
import { Node, Position } from './Node.js';
|
|
3
3
|
|
|
4
4
|
export class Action extends Node {
|
|
5
|
-
constructor(action: {
|
|
5
|
+
constructor(action: { blockId: number; name: string; description: string; parameters: Parameter[], image: string, ref?: string, position?: Position }) {
|
|
6
6
|
super({ ...action, class: 'action' });
|
|
7
7
|
}
|
|
8
8
|
}
|
package/src/models/Condition.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface COndition {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
key: string;
|
|
3
|
+
type: string;
|
|
4
|
+
description: string;
|
|
5
|
+
value: any;
|
|
6
|
+
}
|
package/src/models/Edge.ts
CHANGED
|
@@ -25,9 +25,15 @@ export class Edge {
|
|
|
25
25
|
|
|
26
26
|
toJSON(): { [key: string]: any } {
|
|
27
27
|
return {
|
|
28
|
-
id: this.id,
|
|
29
28
|
source: this.source.getRef(),
|
|
30
29
|
target: this.target.getRef(),
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
|
|
33
|
+
static fromJSON(json: { [key: string]: any }): Edge {
|
|
34
|
+
return new Edge({
|
|
35
|
+
source: json.source,
|
|
36
|
+
target: json.target,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/models/Node.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
// Assuming you have the ACTIONS constant defined as you provided
|
|
2
|
+
|
|
1
3
|
import { Parameter } from './Parameter.js';
|
|
2
4
|
import { validateType } from '../utils/typeValidator.js';
|
|
5
|
+
import { ACTIONS, TRIGGERS } from '../constants/Blocks.js';
|
|
3
6
|
|
|
4
7
|
export interface Position {
|
|
5
8
|
x: number;
|
|
@@ -10,23 +13,27 @@ let nodeCounter = 0;
|
|
|
10
13
|
const generatedRefs = new Set<string>();
|
|
11
14
|
|
|
12
15
|
export class Node {
|
|
13
|
-
id:
|
|
16
|
+
id: string | null = null;
|
|
17
|
+
blockId: number;
|
|
14
18
|
name: string;
|
|
15
19
|
description: string;
|
|
16
20
|
parameters: { [key: string]: Parameter };
|
|
17
21
|
keyMap: { [key: string]: string };
|
|
18
22
|
position?: Position;
|
|
19
23
|
ref: string;
|
|
20
|
-
class: string;
|
|
24
|
+
class: string;
|
|
25
|
+
image: string;
|
|
21
26
|
|
|
22
|
-
constructor(node: {
|
|
23
|
-
this.id =
|
|
27
|
+
constructor(node: { blockId: number; name: string; description: string; parameters: Parameter[], ref?: string, position?: Position, class: string; image: string }) {
|
|
28
|
+
this.id = null;
|
|
29
|
+
this.blockId = node.blockId;
|
|
24
30
|
this.name = node.name;
|
|
25
31
|
this.description = node.description;
|
|
32
|
+
this.image = node.image;
|
|
26
33
|
this.parameters = {};
|
|
27
34
|
this.keyMap = {};
|
|
28
|
-
this.class = node.class;
|
|
29
|
-
|
|
35
|
+
this.class = node.class;
|
|
36
|
+
|
|
30
37
|
if (node.ref) {
|
|
31
38
|
this.ref = node.ref;
|
|
32
39
|
} else {
|
|
@@ -48,6 +55,10 @@ export class Node {
|
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
setId(id: string): void {
|
|
59
|
+
this.id = id;
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
setChainId(value: number): void {
|
|
52
63
|
this.setParameter('chainId', value);
|
|
53
64
|
}
|
|
@@ -109,6 +120,7 @@ export class Node {
|
|
|
109
120
|
const json: { [key: string]: any } = {
|
|
110
121
|
id: this.id,
|
|
111
122
|
ref: this.ref,
|
|
123
|
+
blockId: this.blockId,
|
|
112
124
|
type: this.class,
|
|
113
125
|
parameters: this.getParameters(),
|
|
114
126
|
};
|
|
@@ -121,4 +133,66 @@ export class Node {
|
|
|
121
133
|
private getSimplifiedKey(key: string): string {
|
|
122
134
|
return key.replace(/[.\[\]]/g, '_');
|
|
123
135
|
}
|
|
136
|
+
|
|
137
|
+
static fromJSON(json: { [key: string]: any }): Node {
|
|
138
|
+
|
|
139
|
+
let enriched = findActionByBlockId(json.blockId);
|
|
140
|
+
if (!enriched)
|
|
141
|
+
enriched = findTriggerByBlockId(json.blockId);
|
|
142
|
+
if (!enriched)
|
|
143
|
+
enriched = {name: "Unknown", description: "Unknown", image: "Unknown"}
|
|
144
|
+
|
|
145
|
+
const parameters = Object.keys(json.parameters).map(key => ({
|
|
146
|
+
key,
|
|
147
|
+
type: typeof json.parameters[key], // Assuming type can be derived from the value's type
|
|
148
|
+
description: '', // Add appropriate description if needed
|
|
149
|
+
value: json.parameters[key]
|
|
150
|
+
}));
|
|
151
|
+
const node = new Node({
|
|
152
|
+
blockId: json.blockId,
|
|
153
|
+
name: enriched.name,
|
|
154
|
+
description: enriched.description,
|
|
155
|
+
image: enriched.image,
|
|
156
|
+
parameters,
|
|
157
|
+
ref: json.ref,
|
|
158
|
+
position: json.position,
|
|
159
|
+
class: json.type
|
|
160
|
+
});
|
|
161
|
+
node.setId(json.id);
|
|
162
|
+
return node;
|
|
163
|
+
}
|
|
124
164
|
}
|
|
165
|
+
|
|
166
|
+
const findActionByBlockId = (blockId: number): { name: string; description: string; image: string } | null => {
|
|
167
|
+
for (const category in ACTIONS) {
|
|
168
|
+
for (const service in (ACTIONS as any)[category]) {
|
|
169
|
+
for (const actionKey in (ACTIONS as any)[category][service]) {
|
|
170
|
+
if ((ACTIONS as any)[category][service][actionKey].blockId === blockId) {
|
|
171
|
+
return {
|
|
172
|
+
name: (ACTIONS as any)[category][service][actionKey].name,
|
|
173
|
+
description: (ACTIONS as any)[category][service][actionKey].description,
|
|
174
|
+
image: (ACTIONS as any)[category][service][actionKey].image,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const findTriggerByBlockId = (blockId: number): { name: string; description: string; image: string } | null => {
|
|
184
|
+
for (const category in TRIGGERS) {
|
|
185
|
+
for (const service in (TRIGGERS as any)[category]) {
|
|
186
|
+
for (const triggerKey in (TRIGGERS as any)[category][service]) {
|
|
187
|
+
if ((TRIGGERS as any)[category][service][triggerKey].blockId === blockId) {
|
|
188
|
+
return {
|
|
189
|
+
name: (TRIGGERS as any)[category][service][triggerKey].name,
|
|
190
|
+
description: (TRIGGERS as any)[category][service][triggerKey].description,
|
|
191
|
+
image: (TRIGGERS as any)[category][service][triggerKey].image,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
};
|
package/src/models/Parameter.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface Parameter {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
key: string;
|
|
3
|
+
type: string;
|
|
4
|
+
description: string;
|
|
5
|
+
value?: any;
|
|
6
|
+
}
|
package/src/models/Trigger.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Node, Position } from './Node.js';
|
|
|
4
4
|
export class Trigger extends Node {
|
|
5
5
|
type: number;
|
|
6
6
|
|
|
7
|
-
constructor(trigger: {
|
|
7
|
+
constructor(trigger: { blockId: number; name: string; description: string; type: number; parameters: Parameter[], image: string, ref?: string, position?: Position }) {
|
|
8
8
|
super({ ...trigger, class: 'trigger' });
|
|
9
9
|
this.type = trigger.type;
|
|
10
10
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Node } from './Node.js';
|
|
2
|
+
import { Edge } from './Edge.js';
|
|
3
|
+
import { apiServices } from '../services/ApiService.js';
|
|
4
|
+
|
|
5
|
+
export class Workflow {
|
|
6
|
+
id: string | null = null;
|
|
7
|
+
name: string;
|
|
8
|
+
nodes: Node[];
|
|
9
|
+
edges: Edge[];
|
|
10
|
+
|
|
11
|
+
constructor(name: string = '', nodes: Node[] = [], edges: Edge[] = []) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.nodes = nodes;
|
|
14
|
+
this.edges = edges;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setName(name: string): void {
|
|
18
|
+
this.name = name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
addNode(node: Node): void {
|
|
22
|
+
this.nodes.push(node);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
addNodes(nodes: Node[]): void {
|
|
26
|
+
this.nodes.push(...nodes);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addEdge(edge: Edge): void {
|
|
30
|
+
this.edges.push(edge);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addEdges(edges: Edge[]): void {
|
|
34
|
+
this.edges.push(...edges);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
toJSON() {
|
|
38
|
+
return {
|
|
39
|
+
id: this.id,
|
|
40
|
+
name: this.name,
|
|
41
|
+
nodes: this.nodes.map(node => node.toJSON()),
|
|
42
|
+
edges: this.edges.map(edge => edge.toJSON()),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async create() {
|
|
47
|
+
const response = await apiServices.post('/workflows', this.toJSON());
|
|
48
|
+
this.id = response.id; // Assign the returned ID to the workflow instance
|
|
49
|
+
|
|
50
|
+
// Assign IDs to the nodes based on the response
|
|
51
|
+
response.nodes.forEach((nodeResponse: any) => {
|
|
52
|
+
const node = this.nodes.find(n => n.getRef() === nodeResponse.ref);
|
|
53
|
+
if (node) {
|
|
54
|
+
node.setId(nodeResponse.id);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return response;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async load(workflowId: string): Promise<Workflow> {
|
|
62
|
+
const response = await apiServices.get(`/workflows/${workflowId}`);
|
|
63
|
+
this.id = response.id;
|
|
64
|
+
this.name = response.name;
|
|
65
|
+
this.nodes = response.nodes.map((nodeData: any) => Node.fromJSON(nodeData));
|
|
66
|
+
this.edges = response.edges.map((edgeData: any) => Edge.fromJSON(edgeData));
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -2,30 +2,37 @@
|
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
|
|
4
4
|
const API_CONFIG = {
|
|
5
|
-
BASE_URL: '
|
|
5
|
+
BASE_URL: 'https://staging-api.otomato.xyz/api',
|
|
6
6
|
HEADERS: {
|
|
7
|
-
'Content-Type': 'application/json'
|
|
7
|
+
'Content-Type': 'application/json',
|
|
8
8
|
}
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
|
|
11
11
|
const axiosInstance = axios.create({
|
|
12
12
|
baseURL: API_CONFIG.BASE_URL,
|
|
13
13
|
headers: API_CONFIG.HEADERS
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
16
|
+
class ApiServices {
|
|
17
|
+
private cookie: string | null = null;
|
|
18
|
+
|
|
19
|
+
setCookie(cookie: string) {
|
|
20
|
+
this.cookie = `token=${cookie}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async post(url: string, data: any) {
|
|
24
|
+
const headers = this.cookie ? { 'Cookie': this.cookie } : {};
|
|
25
|
+
const response = await axiosInstance.post(url, data, { headers });
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async get(url: string) {
|
|
30
|
+
const headers = this.cookie ? { 'Cookie': this.cookie } : {};
|
|
31
|
+
const response = await axiosInstance.get(url, { headers });
|
|
32
|
+
return response.data;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// You can add other methods (get, put, delete) similarly
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const apiServices = new ApiServices();
|
package/test/action.spec.ts
CHANGED
|
@@ -38,7 +38,7 @@ describe('Action Class', () => {
|
|
|
38
38
|
|
|
39
39
|
const json = transferAction.toJSON();
|
|
40
40
|
expect(json).to.deep.equal({
|
|
41
|
-
|
|
41
|
+
blockId: ACTIONS.TOKENS.ERC20.TRANSFER.blockId,
|
|
42
42
|
ref: transferAction.getRef(),
|
|
43
43
|
type: 'action',
|
|
44
44
|
parameters: {
|