otomato-sdk 1.5.4 → 1.5.6
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/src/constants/Blocks.js +11 -4
- package/dist/src/constants/WorkflowTemplates.js +1 -1
- package/dist/src/constants/tokens.js +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/models/Action.js +10 -5
- package/dist/src/models/Node.js +1 -5
- package/dist/src/models/SessionKeyPermission.js +87 -0
- package/dist/src/models/Trigger.js +0 -9
- package/dist/src/models/Workflow.js +18 -0
- package/dist/types/examples/sessionKeyPermissions.d.ts +1 -0
- package/dist/types/src/constants/Blocks.d.ts +5 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/models/Action.d.ts +2 -1
- package/dist/types/src/models/Node.d.ts +0 -3
- package/dist/types/src/models/SessionKeyPermission.d.ts +19 -0
- package/dist/types/src/models/Trigger.d.ts +0 -3
- package/dist/types/src/models/Workflow.d.ts +2 -0
- package/dist/types/test/sessionKeyPermission.spec.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
const TRIGGER_TYPE = {
|
|
2
|
-
SUBSCRIPTION: 0,
|
|
3
|
-
POLLING: 1,
|
|
4
|
-
};
|
|
5
1
|
export const TRIGGERS = {
|
|
6
2
|
"TOKENS": {
|
|
7
3
|
"ERC20": {
|
|
@@ -538,6 +534,17 @@ export const ACTIONS = {
|
|
|
538
534
|
"description": "The contract address of the ERC20"
|
|
539
535
|
},
|
|
540
536
|
],
|
|
537
|
+
"permissions": {
|
|
538
|
+
"approvedTargets": [
|
|
539
|
+
"$contractAddress"
|
|
540
|
+
],
|
|
541
|
+
"label": [
|
|
542
|
+
"Transfer $tokenSymbol($chainId, $contractAddress)"
|
|
543
|
+
],
|
|
544
|
+
"labelNotAuthorized": [
|
|
545
|
+
"Transfer $otherTokenSymbol($chainId, $contractAddress)"
|
|
546
|
+
]
|
|
547
|
+
},
|
|
541
548
|
"blockId": 100004,
|
|
542
549
|
"image": "https://otomato-sdk-images.s3.eu-west-1.amazonaws.com/ethereum.webp"
|
|
543
550
|
}
|
|
@@ -3,7 +3,7 @@ export const WORKFLOW_TEMPLATES_TAGS = {
|
|
|
3
3
|
NFTS: 'NFTs',
|
|
4
4
|
SOCIALS: 'Socials',
|
|
5
5
|
TRADING: 'Trading',
|
|
6
|
-
ON_CHAIN_MONITORING: 'On
|
|
6
|
+
ON_CHAIN_MONITORING: 'On-chain monitoring'
|
|
7
7
|
};
|
|
8
8
|
const createModeTransferNotificationWorkflow = () => {
|
|
9
9
|
const modeTransferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
@@ -22,7 +22,7 @@ export const TOKENS = {
|
|
|
22
22
|
image: "https://static.debank.com/image/chain/logo_url/eth/42ba589cd077e7bdd97db6480b0ff61d.png"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
contractAddress: "
|
|
25
|
+
contractAddress: "0xdac17f958d2ee523a2206206994597c13d831ec7",
|
|
26
26
|
name: "USDT",
|
|
27
27
|
symbol: "USDT",
|
|
28
28
|
decimals: 18,
|
package/dist/src/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './models/Parameter.js';
|
|
|
11
11
|
export * from './models/Trigger.js';
|
|
12
12
|
export * from './models/Node.js';
|
|
13
13
|
export * from './models/Edge.js';
|
|
14
|
+
export * from './models/SessionKeyPermission.js';
|
|
14
15
|
// Exporting services
|
|
15
16
|
export * from './services/ApiService.js';
|
|
16
17
|
export * from './utils/helpers.js';
|
|
@@ -10,12 +10,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { Node } from './Node.js';
|
|
11
11
|
import { ACTIONS } from '../constants/Blocks.js';
|
|
12
12
|
import { typeIsNumber } from '../utils/typeValidator.js';
|
|
13
|
+
import { SessionKeyPermission } from './SessionKeyPermission.js';
|
|
13
14
|
export class Action extends Node {
|
|
14
15
|
constructor(action) {
|
|
15
16
|
super(Object.assign(Object.assign({}, action), { class: 'action', parentInfo: findActionByBlockId(action.blockId).parentInfo }));
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
getSessionKeyPermissions() {
|
|
19
|
+
const parentBlock = findActionByBlockId(this.blockId).block;
|
|
20
|
+
if (!parentBlock.permissions)
|
|
21
|
+
return null;
|
|
22
|
+
const permissions = SessionKeyPermission.fromJSON(parentBlock.permissions);
|
|
23
|
+
permissions.fill('contractAddress', this.getParameter('contractAddress'));
|
|
24
|
+
permissions.fill('chainId', this.getParameter('chainId'));
|
|
25
|
+
permissions.fillMethod();
|
|
26
|
+
return permissions;
|
|
19
27
|
}
|
|
20
28
|
static fromJSON(json) {
|
|
21
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -44,9 +52,6 @@ export class Action extends Node {
|
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
break;
|
|
47
|
-
case 'interval':
|
|
48
|
-
// ignore
|
|
49
|
-
break;
|
|
50
55
|
default:
|
|
51
56
|
action.setParams(key, value);
|
|
52
57
|
break;
|
package/dist/src/models/Node.js
CHANGED
|
@@ -105,9 +105,6 @@ export class Node {
|
|
|
105
105
|
return acc;
|
|
106
106
|
}, {});
|
|
107
107
|
}
|
|
108
|
-
getStaticParameters() {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
108
|
toJSON() {
|
|
112
109
|
const serializeBigInt = (key, value) => {
|
|
113
110
|
if (typeof value === 'bigint') {
|
|
@@ -124,14 +121,13 @@ export class Node {
|
|
|
124
121
|
return value;
|
|
125
122
|
}
|
|
126
123
|
};
|
|
127
|
-
const staticParameters = this.getStaticParameters() || {};
|
|
128
124
|
const json = {
|
|
129
125
|
id: this.id,
|
|
130
126
|
ref: this.ref,
|
|
131
127
|
blockId: this.blockId,
|
|
132
128
|
type: this.class,
|
|
133
129
|
state: this.state,
|
|
134
|
-
parameters: Object.assign(
|
|
130
|
+
parameters: Object.assign({}, this.getParameters()),
|
|
135
131
|
};
|
|
136
132
|
if (this.position) {
|
|
137
133
|
json.position = this.position;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getToken } from "../constants/tokens.js";
|
|
2
|
+
export class SessionKeyPermission {
|
|
3
|
+
constructor({ approvedTargets = [], label = [], labelNotAuthorized = [], } = {}) {
|
|
4
|
+
this.approvedTargets = approvedTargets;
|
|
5
|
+
this.label = label;
|
|
6
|
+
this.labelNotAuthorized = labelNotAuthorized;
|
|
7
|
+
}
|
|
8
|
+
fill(key, value) {
|
|
9
|
+
const replacePlaceholder = (target) => {
|
|
10
|
+
const placeholder = `$${key}`;
|
|
11
|
+
if (target.includes(placeholder)) {
|
|
12
|
+
return target.replace(placeholder, value);
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
this.approvedTargets = this.approvedTargets.map(replacePlaceholder);
|
|
17
|
+
this.label = this.label.map(replacePlaceholder);
|
|
18
|
+
this.labelNotAuthorized = this.labelNotAuthorized.map(replacePlaceholder);
|
|
19
|
+
}
|
|
20
|
+
fillMethod() {
|
|
21
|
+
const executeMethod = (target) => {
|
|
22
|
+
const methodPattern = /\$(\w+)\(([^)]+)\)/g;
|
|
23
|
+
return target.replace(methodPattern, (match, methodName, params) => {
|
|
24
|
+
const paramList = params.split(',').map((param) => param.trim());
|
|
25
|
+
switch (methodName) {
|
|
26
|
+
case 'tokenSymbol': {
|
|
27
|
+
const [chainId, address] = paramList;
|
|
28
|
+
const token = getToken(parseInt(chainId, 10), address);
|
|
29
|
+
return token ? token.symbol : match;
|
|
30
|
+
}
|
|
31
|
+
case 'otherTokenSymbol': {
|
|
32
|
+
const [chainId, address] = paramList;
|
|
33
|
+
const symbol = getDifferentToken(parseInt(chainId, 10), address);
|
|
34
|
+
return symbol;
|
|
35
|
+
}
|
|
36
|
+
// Add other methods here as needed
|
|
37
|
+
default:
|
|
38
|
+
return match;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
this.approvedTargets = this.approvedTargets.map(executeMethod);
|
|
43
|
+
this.label = this.label.map(executeMethod);
|
|
44
|
+
this.labelNotAuthorized = this.labelNotAuthorized.map(executeMethod);
|
|
45
|
+
}
|
|
46
|
+
toJSON() {
|
|
47
|
+
const containsPlaceholder = this.approvedTargets.some(target => target.includes('$'));
|
|
48
|
+
if (containsPlaceholder) {
|
|
49
|
+
throw new Error('Approved targets contain unresolved placeholders.');
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
approvedTargets: this.approvedTargets,
|
|
53
|
+
label: this.label,
|
|
54
|
+
labelNotAuthorized: this.labelNotAuthorized,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
static fromJSON(json) {
|
|
58
|
+
if (!json || !Array.isArray(json.approvedTargets)) {
|
|
59
|
+
console.error('Invalid JSON object for SessionKeyPermission:', json);
|
|
60
|
+
throw new Error('Invalid JSON object for SessionKeyPermission');
|
|
61
|
+
}
|
|
62
|
+
return new SessionKeyPermission(json);
|
|
63
|
+
}
|
|
64
|
+
merge(other) {
|
|
65
|
+
// Merge approvedTargets
|
|
66
|
+
const uniqueTargets = new Set(this.approvedTargets);
|
|
67
|
+
other.approvedTargets.forEach(target => uniqueTargets.add(target));
|
|
68
|
+
this.approvedTargets = Array.from(uniqueTargets);
|
|
69
|
+
// Merge labels
|
|
70
|
+
const uniqueLabels = new Set(this.label);
|
|
71
|
+
other.label.forEach(lbl => uniqueLabels.add(lbl));
|
|
72
|
+
this.label = Array.from(uniqueLabels);
|
|
73
|
+
// Merge labelNotAuthorized
|
|
74
|
+
const uniqueLabelsNotAuthorized = new Set(this.labelNotAuthorized);
|
|
75
|
+
other.labelNotAuthorized.forEach(lbl => uniqueLabelsNotAuthorized.add(lbl));
|
|
76
|
+
this.labelNotAuthorized = Array.from(uniqueLabelsNotAuthorized);
|
|
77
|
+
// Remove labels from labelNotAuthorized if they are present in label
|
|
78
|
+
this.labelNotAuthorized = this.labelNotAuthorized.filter(lbl => !this.label.includes(lbl));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const getDifferentToken = (chain, contractAddress) => {
|
|
82
|
+
var _a;
|
|
83
|
+
const tokenSymbol = (_a = getToken(chain, contractAddress)) === null || _a === void 0 ? void 0 : _a.symbol;
|
|
84
|
+
if (!tokenSymbol || tokenSymbol !== 'WETH')
|
|
85
|
+
return 'WETH';
|
|
86
|
+
return 'USDT';
|
|
87
|
+
};
|
|
@@ -30,12 +30,6 @@ export class Trigger extends Node {
|
|
|
30
30
|
}
|
|
31
31
|
this.setParameter('comparisonValue', value);
|
|
32
32
|
}
|
|
33
|
-
getStaticParameters() {
|
|
34
|
-
if (!this.notAPollingTrigger()) {
|
|
35
|
-
return { interval: 5000 };
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
33
|
static fromJSON(json) {
|
|
40
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
35
|
const enriched = findTriggerByBlockId(json.blockId);
|
|
@@ -69,9 +63,6 @@ export class Trigger extends Node {
|
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
break;
|
|
72
|
-
case 'interval':
|
|
73
|
-
// ignore
|
|
74
|
-
break;
|
|
75
66
|
default:
|
|
76
67
|
trigger.setParams(key, value);
|
|
77
68
|
break;
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { Node } from './Node.js';
|
|
11
11
|
import { Edge } from './Edge.js';
|
|
12
12
|
import { apiServices } from '../services/ApiService.js';
|
|
13
|
+
import { SessionKeyPermission } from './SessionKeyPermission.js';
|
|
13
14
|
export class Workflow {
|
|
14
15
|
constructor(name = '', nodes = [], edges = []) {
|
|
15
16
|
this.id = null;
|
|
@@ -191,4 +192,21 @@ export class Workflow {
|
|
|
191
192
|
}
|
|
192
193
|
});
|
|
193
194
|
}
|
|
195
|
+
getSessionKeyPermissions() {
|
|
196
|
+
const permissions = new SessionKeyPermission();
|
|
197
|
+
for (const node of this.nodes) {
|
|
198
|
+
try {
|
|
199
|
+
if (node.class === 'action' && 'getSessionKeyPermissions' in node) {
|
|
200
|
+
const nodePermissions = node.getSessionKeyPermissions();
|
|
201
|
+
if (nodePermissions) {
|
|
202
|
+
permissions.merge(nodePermissions);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.error(`Error getting session key permissions for node ${node.getRef()}:`, error);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return permissions;
|
|
211
|
+
}
|
|
194
212
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -197,6 +197,11 @@ export declare const ACTIONS: {
|
|
|
197
197
|
type: number;
|
|
198
198
|
method: string;
|
|
199
199
|
parameters: Parameter[];
|
|
200
|
+
permissions: {
|
|
201
|
+
approvedTargets: string[];
|
|
202
|
+
label: string[];
|
|
203
|
+
labelNotAuthorized: string[];
|
|
204
|
+
};
|
|
200
205
|
blockId: number;
|
|
201
206
|
image: string;
|
|
202
207
|
};
|
|
@@ -9,6 +9,7 @@ export * from './models/Parameter.js';
|
|
|
9
9
|
export * from './models/Trigger.js';
|
|
10
10
|
export * from './models/Node.js';
|
|
11
11
|
export * from './models/Edge.js';
|
|
12
|
+
export * from './models/SessionKeyPermission.js';
|
|
12
13
|
export * from './services/ApiService.js';
|
|
13
14
|
export * from './utils/helpers.js';
|
|
14
15
|
export * from './utils/typeValidator.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Parameter } from './Parameter.js';
|
|
2
2
|
import { Node, ParentInfo, Position, NodeState } from './Node.js';
|
|
3
|
+
import { SessionKeyPermission } from './SessionKeyPermission.js';
|
|
3
4
|
export declare class Action extends Node {
|
|
4
5
|
constructor(action: {
|
|
5
6
|
blockId: number;
|
|
@@ -12,7 +13,7 @@ export declare class Action extends Node {
|
|
|
12
13
|
parentInfo?: ParentInfo;
|
|
13
14
|
state?: NodeState;
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
+
getSessionKeyPermissions(): SessionKeyPermission | null;
|
|
16
17
|
static fromJSON(json: {
|
|
17
18
|
[key: string]: any;
|
|
18
19
|
}): Promise<Action>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class SessionKeyPermission {
|
|
2
|
+
approvedTargets: string[];
|
|
3
|
+
label: string[];
|
|
4
|
+
labelNotAuthorized: string[];
|
|
5
|
+
constructor({ approvedTargets, label, labelNotAuthorized, }?: {
|
|
6
|
+
approvedTargets?: string[];
|
|
7
|
+
label?: string[];
|
|
8
|
+
labelNotAuthorized?: string[];
|
|
9
|
+
});
|
|
10
|
+
fill(key: string, value: any): void;
|
|
11
|
+
fillMethod(): void;
|
|
12
|
+
toJSON(): {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
static fromJSON(json: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}): SessionKeyPermission;
|
|
18
|
+
merge(other: SessionKeyPermission): void;
|
|
19
|
+
}
|
|
@@ -17,9 +17,6 @@ export declare class Trigger extends Node {
|
|
|
17
17
|
private notAPollingTrigger;
|
|
18
18
|
setCondition(value: string): void;
|
|
19
19
|
setComparisonValue(value: number): void;
|
|
20
|
-
getStaticParameters(): {
|
|
21
|
-
interval: number;
|
|
22
|
-
} | null;
|
|
23
20
|
static fromJSON(json: {
|
|
24
21
|
[key: string]: any;
|
|
25
22
|
}): Promise<Trigger>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Node } from './Node.js';
|
|
2
2
|
import { Edge } from './Edge.js';
|
|
3
|
+
import { SessionKeyPermission } from './SessionKeyPermission.js';
|
|
3
4
|
export type WorkflowState = 'inactive' | 'active' | 'failed' | 'completed';
|
|
4
5
|
export declare class Workflow {
|
|
5
6
|
id: string | null;
|
|
@@ -44,4 +45,5 @@ export declare class Workflow {
|
|
|
44
45
|
success: boolean;
|
|
45
46
|
error?: string;
|
|
46
47
|
}>;
|
|
48
|
+
getSessionKeyPermissions(): SessionKeyPermission;
|
|
47
49
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|