otomato-sdk 1.3.2 → 1.3.3
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/services/ApiService.js +33 -2
- package/dist/test/action.spec.js +12 -6
- package/dist/test/automation.spec.js +1 -0
- package/dist/test/node.spec.js +2 -0
- package/dist/test/trigger.spec.js +13 -8
- package/dist/types/src/services/ApiService.d.ts +7 -0
- package/package.json +4 -2
- package/src/services/ApiService.ts +33 -2
- package/test/action.spec.ts +13 -6
- package/test/automation.spec.ts +1 -0
- package/test/node.spec.ts +6 -4
- package/test/trigger.spec.ts +13 -8
|
@@ -7,8 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
// networkService.ts
|
|
11
10
|
import axios from 'axios';
|
|
11
|
+
import jwt from 'jsonwebtoken';
|
|
12
12
|
const API_CONFIG = {
|
|
13
13
|
BASE_URL: 'https://staging-api.otomato.xyz/api',
|
|
14
14
|
HEADERS: {
|
|
@@ -22,7 +22,6 @@ const axiosInstance = axios.create({
|
|
|
22
22
|
class ApiServices {
|
|
23
23
|
constructor() {
|
|
24
24
|
this.auth = null;
|
|
25
|
-
// You can add other methods (get, put, delete) similarly
|
|
26
25
|
}
|
|
27
26
|
setAuth(auth) {
|
|
28
27
|
this.auth = auth;
|
|
@@ -42,5 +41,37 @@ class ApiServices {
|
|
|
42
41
|
return response.data;
|
|
43
42
|
});
|
|
44
43
|
}
|
|
44
|
+
generateLoginPayload(address, chainId) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
47
|
+
const response = yield axiosInstance.post('/auth/generate-payload', { address, chainId }, { headers });
|
|
48
|
+
return response.data;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getToken(loginPayload, signature) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
54
|
+
const body = {
|
|
55
|
+
payload: loginPayload,
|
|
56
|
+
signature,
|
|
57
|
+
};
|
|
58
|
+
const response = yield axiosInstance.post('/auth/token', body, { headers });
|
|
59
|
+
const cookie = response.headers['set-cookie'];
|
|
60
|
+
const token = response.data.token;
|
|
61
|
+
console.log('cookie:', cookie);
|
|
62
|
+
console.log('token:', token);
|
|
63
|
+
// Decode the JWT token
|
|
64
|
+
const decodedToken = jwt.decode(token, { complete: true });
|
|
65
|
+
console.log('decodedToken:', decodedToken);
|
|
66
|
+
return { token, cookie, decodedToken };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
verifyToken(token) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
72
|
+
const response = yield axiosInstance.post('/auth/verify-token', { token }, { headers });
|
|
73
|
+
return response.data;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
45
76
|
}
|
|
46
77
|
export const apiServices = new ApiServices();
|
package/dist/test/action.spec.js
CHANGED
|
@@ -5,9 +5,10 @@ describe('Action Class', () => {
|
|
|
5
5
|
it('should create a transfer action without parameters', () => {
|
|
6
6
|
const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
7
7
|
const params = transferAction.getParameters();
|
|
8
|
+
console.log(params);
|
|
8
9
|
expect(params.chainId).to.be.null;
|
|
9
|
-
expect(params
|
|
10
|
-
expect(params
|
|
10
|
+
expect(params.abi.parameters.value).to.be.null;
|
|
11
|
+
expect(params.abi.parameters.to).to.be.null;
|
|
11
12
|
expect(params.contractAddress).to.be.null;
|
|
12
13
|
});
|
|
13
14
|
it('should create a transfer action and set parameters correctly', () => {
|
|
@@ -18,8 +19,8 @@ describe('Action Class', () => {
|
|
|
18
19
|
transferAction.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
19
20
|
const params = transferAction.getParameters();
|
|
20
21
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
21
|
-
expect(params
|
|
22
|
-
expect(params
|
|
22
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
23
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
23
24
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
24
25
|
});
|
|
25
26
|
it('should be able to export an action as json', () => {
|
|
@@ -33,10 +34,15 @@ describe('Action Class', () => {
|
|
|
33
34
|
blockId: ACTIONS.TOKENS.ERC20.TRANSFER.blockId,
|
|
34
35
|
ref: transferAction.getRef(),
|
|
35
36
|
type: 'action',
|
|
37
|
+
id: null,
|
|
36
38
|
parameters: {
|
|
37
39
|
chainId: CHAINS.ETHEREUM,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
abi: {
|
|
41
|
+
parameters: {
|
|
42
|
+
to: DEFAULT_ADDRESS,
|
|
43
|
+
value: 1000
|
|
44
|
+
}
|
|
45
|
+
},
|
|
40
46
|
contractAddress: getToken(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
41
47
|
}
|
|
42
48
|
});
|
package/dist/test/node.spec.js
CHANGED
|
@@ -73,6 +73,7 @@ describe('Node Class', () => {
|
|
|
73
73
|
const json = node.toJSON();
|
|
74
74
|
expect(json).to.deep.equal({
|
|
75
75
|
blockId: 5,
|
|
76
|
+
id: null,
|
|
76
77
|
ref: node.getRef(),
|
|
77
78
|
type: 'testClass',
|
|
78
79
|
parameters: {
|
|
@@ -97,6 +98,7 @@ describe('Node Class', () => {
|
|
|
97
98
|
expect(json).to.deep.equal({
|
|
98
99
|
type: 'testClass',
|
|
99
100
|
blockId: 6,
|
|
101
|
+
id: null,
|
|
100
102
|
ref: node.getRef(),
|
|
101
103
|
parameters: {
|
|
102
104
|
chainId: 1,
|
|
@@ -6,8 +6,8 @@ describe('Trigger Class', () => {
|
|
|
6
6
|
const transferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
7
7
|
const params = transferTrigger.getParameters();
|
|
8
8
|
expect(params.chainId).to.be.null;
|
|
9
|
-
expect(params
|
|
10
|
-
expect(params
|
|
9
|
+
expect(params.abi.parameters.value).to.equal(null);
|
|
10
|
+
expect(params.abi.parameters.to).to.equal(null);
|
|
11
11
|
expect(params.contractAddress).to.be.null;
|
|
12
12
|
});
|
|
13
13
|
it('should create a transfer trigger and set parameters correctly', () => {
|
|
@@ -18,8 +18,8 @@ describe('Trigger Class', () => {
|
|
|
18
18
|
transferTrigger.setContractAddress(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
19
19
|
const params = transferTrigger.getParameters();
|
|
20
20
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
21
|
-
expect(params
|
|
22
|
-
expect(params
|
|
21
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
22
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
23
23
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
24
24
|
});
|
|
25
25
|
it('should be able to export a trigger as json', () => {
|
|
@@ -33,12 +33,17 @@ describe('Trigger Class', () => {
|
|
|
33
33
|
expect(json).to.deep.equal({
|
|
34
34
|
blockId: TRIGGERS.TOKENS.ERC20.TRANSFER.blockId,
|
|
35
35
|
ref: transferTrigger.getRef(),
|
|
36
|
+
id: null,
|
|
36
37
|
type: 'trigger',
|
|
37
38
|
parameters: {
|
|
38
39
|
chainId: CHAINS.ETHEREUM,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
abi: {
|
|
41
|
+
parameters: {
|
|
42
|
+
value: 1000,
|
|
43
|
+
to: DEFAULT_ADDRESS,
|
|
44
|
+
from: null
|
|
45
|
+
}
|
|
46
|
+
},
|
|
42
47
|
contractAddress: getToken(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
43
48
|
}
|
|
44
49
|
});
|
|
@@ -53,7 +58,7 @@ describe('Trigger Class', () => {
|
|
|
53
58
|
balanceTrigger.setInterval(5000);
|
|
54
59
|
const params = balanceTrigger.getParameters();
|
|
55
60
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
56
|
-
expect(params
|
|
61
|
+
expect(params.abi.parameters.account).to.equal(DEFAULT_ADDRESS);
|
|
57
62
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
58
63
|
console.log(balanceTrigger.toJSON());
|
|
59
64
|
expect(balanceTrigger.toJSON().parameters.condition).to.equal("gte");
|
|
@@ -3,6 +3,13 @@ declare class ApiServices {
|
|
|
3
3
|
setAuth(auth: string): void;
|
|
4
4
|
post(url: string, data: any): Promise<any>;
|
|
5
5
|
get(url: string): Promise<any>;
|
|
6
|
+
generateLoginPayload(address: string, chainId: number): Promise<any>;
|
|
7
|
+
getToken(loginPayload: any, signature: string): Promise<{
|
|
8
|
+
token: any;
|
|
9
|
+
cookie: string[] | undefined;
|
|
10
|
+
decodedToken: any;
|
|
11
|
+
}>;
|
|
12
|
+
verifyToken(token: string): Promise<any>;
|
|
6
13
|
}
|
|
7
14
|
export declare const apiServices: ApiServices;
|
|
8
15
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otomato-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "An SDK for building and managing automations on Otomato",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/axios": "^0.14.0",
|
|
25
25
|
"@types/chai": "^4.3.16",
|
|
26
|
+
"@types/jsonwebtoken": "^9.0.6",
|
|
26
27
|
"@types/mocha": "^10.0.6",
|
|
27
28
|
"@types/node": "^20.14.2",
|
|
28
29
|
"chai": "^5.1.1",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"axios": "^1.7.2",
|
|
35
|
-
"ethers": "^6.13.0"
|
|
36
|
+
"ethers": "^6.13.0",
|
|
37
|
+
"jsonwebtoken": "^9.0.2"
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// networkService.ts
|
|
2
1
|
import axios from 'axios';
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
3
3
|
|
|
4
4
|
const API_CONFIG = {
|
|
5
5
|
BASE_URL: 'https://staging-api.otomato.xyz/api',
|
|
@@ -33,7 +33,38 @@ class ApiServices {
|
|
|
33
33
|
return response.data;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
async generateLoginPayload(address: string, chainId: number) {
|
|
37
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
38
|
+
const response = await axiosInstance.post('/auth/generate-payload', { address, chainId }, { headers });
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async getToken(loginPayload: any, signature: string) {
|
|
43
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
44
|
+
const body = {
|
|
45
|
+
payload: loginPayload,
|
|
46
|
+
signature,
|
|
47
|
+
};
|
|
48
|
+
const response = await axiosInstance.post('/auth/token', body, { headers });
|
|
49
|
+
|
|
50
|
+
const cookie = response.headers['set-cookie'];
|
|
51
|
+
const token = response.data.token;
|
|
52
|
+
|
|
53
|
+
console.log('cookie:', cookie);
|
|
54
|
+
console.log('token:', token);
|
|
55
|
+
|
|
56
|
+
// Decode the JWT token
|
|
57
|
+
const decodedToken: any = jwt.decode(token, { complete: true });
|
|
58
|
+
console.log('decodedToken:', decodedToken);
|
|
59
|
+
|
|
60
|
+
return { token, cookie, decodedToken };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async verifyToken(token: string) {
|
|
64
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
65
|
+
const response = await axiosInstance.post('/auth/verify-token', { token }, { headers });
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
37
68
|
}
|
|
38
69
|
|
|
39
70
|
export const apiServices = new ApiServices();
|
package/test/action.spec.ts
CHANGED
|
@@ -9,9 +9,11 @@ describe('Action Class', () => {
|
|
|
9
9
|
const transferAction = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
10
10
|
const params = transferAction.getParameters();
|
|
11
11
|
|
|
12
|
+
console.log(params)
|
|
13
|
+
|
|
12
14
|
expect(params.chainId).to.be.null;
|
|
13
|
-
expect(params
|
|
14
|
-
expect(params
|
|
15
|
+
expect(params.abi.parameters.value).to.be.null;
|
|
16
|
+
expect(params.abi.parameters.to).to.be.null;
|
|
15
17
|
expect(params.contractAddress).to.be.null;
|
|
16
18
|
});
|
|
17
19
|
|
|
@@ -24,8 +26,8 @@ describe('Action Class', () => {
|
|
|
24
26
|
|
|
25
27
|
const params = transferAction.getParameters();
|
|
26
28
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
27
|
-
expect(params
|
|
28
|
-
expect(params
|
|
29
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
30
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
29
31
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
30
32
|
});
|
|
31
33
|
|
|
@@ -41,10 +43,15 @@ describe('Action Class', () => {
|
|
|
41
43
|
blockId: ACTIONS.TOKENS.ERC20.TRANSFER.blockId,
|
|
42
44
|
ref: transferAction.getRef(),
|
|
43
45
|
type: 'action',
|
|
46
|
+
id: null,
|
|
44
47
|
parameters: {
|
|
45
48
|
chainId: CHAINS.ETHEREUM,
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
abi: {
|
|
50
|
+
parameters: {
|
|
51
|
+
to: DEFAULT_ADDRESS,
|
|
52
|
+
value: 1000
|
|
53
|
+
}
|
|
54
|
+
},
|
|
48
55
|
contractAddress: getToken(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
49
56
|
}
|
|
50
57
|
});
|
package/test/automation.spec.ts
CHANGED
package/test/node.spec.ts
CHANGED
|
@@ -7,7 +7,7 @@ const DEFAULT_PARAMETERS: Parameter[] = [
|
|
|
7
7
|
];
|
|
8
8
|
|
|
9
9
|
describe('Node Class', () => {
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
it('should create a node without coordinates', () => {
|
|
12
12
|
const node = new Node({
|
|
13
13
|
blockId: 1,
|
|
@@ -28,7 +28,7 @@ describe('Node Class', () => {
|
|
|
28
28
|
description: 'A node for testing with coordinates',
|
|
29
29
|
parameters: DEFAULT_PARAMETERS,
|
|
30
30
|
class: 'testClass',
|
|
31
|
-
position: {x: 100, y: 200},
|
|
31
|
+
position: { x: 100, y: 200 },
|
|
32
32
|
image: 'a',
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -85,6 +85,7 @@ describe('Node Class', () => {
|
|
|
85
85
|
const json = node.toJSON();
|
|
86
86
|
expect(json).to.deep.equal({
|
|
87
87
|
blockId: 5,
|
|
88
|
+
id: null,
|
|
88
89
|
ref: node.getRef(),
|
|
89
90
|
type: 'testClass',
|
|
90
91
|
parameters: {
|
|
@@ -101,7 +102,7 @@ describe('Node Class', () => {
|
|
|
101
102
|
description: 'A node for testing JSON export with coordinates',
|
|
102
103
|
parameters: DEFAULT_PARAMETERS,
|
|
103
104
|
class: 'testClass',
|
|
104
|
-
position: {x: 1, y: 2},
|
|
105
|
+
position: { x: 1, y: 2 },
|
|
105
106
|
image: 'a',
|
|
106
107
|
});
|
|
107
108
|
|
|
@@ -112,12 +113,13 @@ describe('Node Class', () => {
|
|
|
112
113
|
expect(json).to.deep.equal({
|
|
113
114
|
type: 'testClass',
|
|
114
115
|
blockId: 6,
|
|
116
|
+
id: null,
|
|
115
117
|
ref: node.getRef(),
|
|
116
118
|
parameters: {
|
|
117
119
|
chainId: 1,
|
|
118
120
|
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
119
121
|
},
|
|
120
|
-
position: {x: 1, y: 2}
|
|
122
|
+
position: { x: 1, y: 2 }
|
|
121
123
|
});
|
|
122
124
|
});
|
|
123
125
|
|
package/test/trigger.spec.ts
CHANGED
|
@@ -10,8 +10,8 @@ describe('Trigger Class', () => {
|
|
|
10
10
|
const params = transferTrigger.getParameters();
|
|
11
11
|
|
|
12
12
|
expect(params.chainId).to.be.null;
|
|
13
|
-
expect(params
|
|
14
|
-
expect(params
|
|
13
|
+
expect(params.abi.parameters.value).to.equal(null);
|
|
14
|
+
expect(params.abi.parameters.to).to.equal(null);
|
|
15
15
|
expect(params.contractAddress).to.be.null;
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -24,8 +24,8 @@ describe('Trigger Class', () => {
|
|
|
24
24
|
|
|
25
25
|
const params = transferTrigger.getParameters();
|
|
26
26
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
27
|
-
expect(params
|
|
28
|
-
expect(params
|
|
27
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
28
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
29
29
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -41,12 +41,17 @@ describe('Trigger Class', () => {
|
|
|
41
41
|
expect(json).to.deep.equal({
|
|
42
42
|
blockId: TRIGGERS.TOKENS.ERC20.TRANSFER.blockId,
|
|
43
43
|
ref: transferTrigger.getRef(),
|
|
44
|
+
id: null,
|
|
44
45
|
type: 'trigger',
|
|
45
46
|
parameters: {
|
|
46
47
|
chainId: CHAINS.ETHEREUM,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
abi: {
|
|
49
|
+
parameters: {
|
|
50
|
+
value: 1000,
|
|
51
|
+
to: DEFAULT_ADDRESS,
|
|
52
|
+
from: null
|
|
53
|
+
}
|
|
54
|
+
},
|
|
50
55
|
contractAddress: getToken(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
51
56
|
}
|
|
52
57
|
});
|
|
@@ -63,7 +68,7 @@ describe('Trigger Class', () => {
|
|
|
63
68
|
|
|
64
69
|
const params = balanceTrigger.getParameters();
|
|
65
70
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
66
|
-
expect(params
|
|
71
|
+
expect(params.abi.parameters.account).to.equal(DEFAULT_ADDRESS);
|
|
67
72
|
expect(params.contractAddress).to.equal(getToken(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
68
73
|
console.log(balanceTrigger.toJSON());
|
|
69
74
|
expect(balanceTrigger.toJSON().parameters.condition).to.equal("gte");
|