otomato-sdk 2.0.456 → 2.0.457

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/README.md CHANGED
@@ -37,7 +37,7 @@ npm install otomato-sdk
37
37
 
38
38
  For the first example, set the following environment variables:
39
39
  * `API_URL`: Should be set to `https://api.otomato.xyz/api`.
40
- * `AUTH_TOKEN`: Obtain this by following the [Authentication](#authentication) instructions.
40
+ * `AUTH_TOKEN`: Obtain this by following the [Authentication](#authentication) instructions. Alternatively, you can use an `API_KEY` instead.
41
41
 
42
42
  Alternatively, you can replace these placeholder values directly in the example code.
43
43
 
@@ -55,15 +55,18 @@ async function simpleEthPriceMonitor() {
55
55
  const API_URL = process.env.API_URL || "https://api.otomato.xyz/api";
56
56
  const EMAIL_ADDRESS = process.env.EMAIL_ADDRESS || "your-email@example.com"; // Replace with your email or set as ENV var
57
57
  const AUTH_TOKEN = process.env.AUTH_TOKEN;
58
+ const API_KEY = process.env.API_KEY;
58
59
 
59
- if (!AUTH_TOKEN) {
60
- console.error("Error: AUTH_TOKEN is not set. Please set it as an environment variable or directly in the code.");
60
+ if (!AUTH_TOKEN || !API_KEY) {
61
+ console.error("Error: AUTH_TOKEN or API_KEY is not set. Please set it as an environment variable or directly in the code.");
61
62
  return;
62
63
  }
63
64
  if (EMAIL_ADDRESS === "your-email@example.com") {
64
65
  console.warn("Warning: EMAIL_ADDRESS is set to the default. Replace with your email to receive notifications.");
65
66
  }
66
67
  apiServices.setUrl(API_URL);
68
+ // Use either an API key or an auth token:
69
+ // apiServices.setApiKey(process.env.API_KEY);
67
70
  apiServices.setAuth(AUTH_TOKEN);
68
71
 
69
72
  const priceTrigger = new Trigger(TRIGGERS.TOKENS.PRICE.PRICE_MOVEMENT_AGAINST_CURRENCY);
@@ -133,7 +136,35 @@ simpleEthPriceMonitor();
133
136
 
134
137
  ### Authentication
135
138
 
136
- Before interacting with the Otomato SDK, you need to authenticate your account. This is done by obtaining an `AUTH_TOKEN`.
139
+ Before interacting with the Otomato SDK, you need to authenticate. There are two approaches:
140
+
141
+ #### Option 1: API Key (Recommended)
142
+
143
+ API keys are the simplest way to authenticate.
144
+
145
+ ```js
146
+ import { apiServices } from 'otomato-sdk';
147
+
148
+ apiServices.setUrl('https://api.otomato.xyz/api');
149
+ apiServices.setApiKey('sk_live_xxxx_...');
150
+ ```
151
+
152
+ Set it via environment variable:
153
+ ```
154
+ API_URL=https://api.otomato.xyz/api
155
+ API_KEY=sk_live_xxxx_...
156
+ ```
157
+
158
+ ```js
159
+ apiServices.setUrl(process.env.API_URL);
160
+ apiServices.setApiKey(process.env.API_KEY);
161
+ ```
162
+
163
+ > **Note:** If both an API key and an auth token are set, the API key takes priority.
164
+
165
+ #### Option 2: Auth Token
166
+
167
+ You can also authenticate using an `AUTH_TOKEN` obtained from the web app or programmatically.
137
168
 
138
169
  **How to get an `AUTH_TOKEN`:**
139
170
 
@@ -150,9 +181,9 @@ Before interacting with the Otomato SDK, you need to authenticate your account.
150
181
  async function getAuthToken(walletAddress, accessCode, ownerAddress, signFunction) {
151
182
  try {
152
183
  // Ensure chainId is defined, e.g., CHAINS.ETHEREUM or your specific chain
153
- const chainId = CHAINS.ETHEREUM;
184
+ const chainId = CHAINS.ETHEREUM;
154
185
  const loginPayload = await apiServices.generateLoginPayload(walletAddress, chainId, accessCode, ownerAddress);
155
-
186
+
156
187
  // The signFunction needs to be implemented by you, using your preferred wallet library (ethers.js, web3.js, etc.)
157
188
  // It takes the JSON string of loginPayload and returns a signature.
158
189
  // Example: const signature = await ethersSigner.signMessage(JSON.stringify(loginPayload));
@@ -397,4 +428,4 @@ We welcome contributions to enhance the Otomato SDK! Please follow these steps:
397
428
 
398
429
  ## License
399
430
 
400
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
431
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = '2.0.456';
1
+ export const SDK_VERSION = '2.0.457';
2
2
  export function compareVersions(v1, v2) {
3
3
  // Split the version strings into parts
4
4
  const v1Parts = v1.split('.').map(Number);
@@ -12,33 +12,41 @@ const axiosInstance = axios.create({
12
12
  class ApiServices {
13
13
  constructor() {
14
14
  this.auth = null;
15
+ this.apiKey = null;
15
16
  }
16
17
  setAuth(auth) {
17
18
  this.auth = auth;
18
19
  }
20
+ setApiKey(apiKey) {
21
+ this.apiKey = apiKey;
22
+ }
19
23
  setUrl(baseUrl) {
20
24
  axiosInstance.defaults.baseURL = baseUrl;
21
25
  }
26
+ getAuthHeaders() {
27
+ if (this.apiKey) {
28
+ return { 'X-API-KEY': this.apiKey };
29
+ }
30
+ if (this.auth) {
31
+ return { 'Authorization': this.auth };
32
+ }
33
+ return {};
34
+ }
22
35
  async post(url, data) {
23
- const headers = this.auth ? { 'Authorization': this.auth } : {};
24
- return await axiosInstance.post(url, data, { headers });
36
+ return await axiosInstance.post(url, data, { headers: this.getAuthHeaders() });
25
37
  }
26
38
  async patch(url, data) {
27
- const headers = this.auth ? { 'Authorization': this.auth } : {};
28
- return await axiosInstance.patch(url, data, { headers });
39
+ return await axiosInstance.patch(url, data, { headers: this.getAuthHeaders() });
29
40
  }
30
41
  async put(url, data) {
31
- const headers = this.auth ? { 'Authorization': this.auth } : {};
32
- return await axiosInstance.put(url, data, { headers });
42
+ return await axiosInstance.put(url, data, { headers: this.getAuthHeaders() });
33
43
  }
34
44
  async get(url) {
35
- const headers = this.auth ? { 'Authorization': this.auth } : {};
36
- const response = await axiosInstance.get(url, { headers });
45
+ const response = await axiosInstance.get(url, { headers: this.getAuthHeaders() });
37
46
  return response.data;
38
47
  }
39
48
  async delete(url) {
40
- const headers = this.auth ? { 'Authorization': this.auth } : {};
41
- return await axiosInstance.delete(url, { headers });
49
+ return await axiosInstance.delete(url, { headers: this.getAuthHeaders() });
42
50
  }
43
51
  async generateLoginPayload(address, chainId, referralCode, ownerWalletAddress) {
44
52
  const headers = { 'Content-Type': 'application/json' };
@@ -61,10 +69,10 @@ class ApiServices {
61
69
  return response.data;
62
70
  }
63
71
  async getWorkflowsOfUser(offset, limit, isActive, query) {
64
- if (!this.auth) {
65
- throw new Error('Authorization token is required');
72
+ if (!this.auth && !this.apiKey) {
73
+ throw new Error('Authorization token or API key is required');
66
74
  }
67
- const headers = { 'Authorization': this.auth };
75
+ const headers = this.getAuthHeaders();
68
76
  // Set defaults for offset and limit if not provided
69
77
  const finalOffset = offset ?? 0;
70
78
  const finalLimit = limit ?? 8;
@@ -84,12 +92,12 @@ class ApiServices {
84
92
  return response.data;
85
93
  }
86
94
  async getSessionKeyPermissions(workflowId) {
87
- if (!this.auth) {
88
- throw new Error('Authorization token is required');
95
+ if (!this.auth && !this.apiKey) {
96
+ throw new Error('Authorization token or API key is required');
89
97
  }
90
98
  try {
91
99
  const url = `/workflows/${workflowId}/verify-contracts`;
92
- const headers = { Authorization: this.auth };
100
+ const headers = this.getAuthHeaders();
93
101
  const response = await axiosInstance.post(url, {}, { headers });
94
102
  return response.data; // Return the data from the response
95
103
  }
@@ -0,0 +1,4 @@
1
+ /*************************************
2
+ * 6. Main Workflow Builder
3
+ *************************************/
4
+ export declare function aggregatorWorkflow(): Promise<void>;
@@ -0,0 +1,7 @@
1
+ /*************************************
2
+ * File: stop-lending-aggregator.ts
3
+ *************************************/
4
+ /*************************************
5
+ * 3. Build the 'Stop Lending Aggregator' Workflow
6
+ *************************************/
7
+ export declare function stopLendingAggregator(): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "2.0.456";
1
+ export declare const SDK_VERSION = "2.0.457";
2
2
  export declare function compareVersions(v1: string, v2: string): number;
@@ -1,7 +1,10 @@
1
1
  declare class ApiServices {
2
2
  private auth;
3
+ private apiKey;
3
4
  setAuth(auth: string): void;
5
+ setApiKey(apiKey: string): void;
4
6
  setUrl(baseUrl: string): void;
7
+ private getAuthHeaders;
5
8
  post(url: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
6
9
  patch(url: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
7
10
  put(url: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "otomato-sdk",
3
- "version": "2.0.456",
3
+ "version": "2.0.457",
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",