@steerprotocol/data-connector-loader 0.0.4 → 0.0.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/lib/index.d.ts CHANGED
@@ -2,6 +2,9 @@ import { DataConnector } from './dataConnector';
2
2
  export declare class DataConnectorExecution {
3
3
  private dataConnector;
4
4
  constructor(dataConnector: DataConnector);
5
+ private delay;
6
+ private log;
7
+ private fetchData;
5
8
  execute<T>(vaultAddress: string, _vaultConfig: string): Promise<Array<T>>;
6
9
  private downloadWasmBundle;
7
10
  }
package/lib/index.js CHANGED
@@ -19,6 +19,34 @@ class DataConnectorExecution {
19
19
  constructor(dataConnector) {
20
20
  this.dataConnector = dataConnector;
21
21
  }
22
+ delay(ms) {
23
+ return new Promise((resolve) => setTimeout(resolve, ms));
24
+ }
25
+ // create function to perform console logs
26
+ log(...args) {
27
+ if (process.env.DEBUG === 'true') {
28
+ console.log(...args);
29
+ }
30
+ }
31
+ fetchData(request, attempts) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ // intentionally kept console logs to debug
34
+ this.log('Request payload: =============', request);
35
+ attempts = attempts + 1;
36
+ const axInstance = axios_1.default.create();
37
+ const response = (yield axInstance.request(request)).data;
38
+ this.log('API Response: =============', response);
39
+ if ('errors' in response && response['errors'].length > 0) {
40
+ if (attempts < 3) {
41
+ return yield this.fetchData(request, attempts);
42
+ }
43
+ else {
44
+ throw new Error('Maximum retry attempts reached');
45
+ }
46
+ }
47
+ return response;
48
+ });
49
+ }
22
50
  execute(vaultAddress, _vaultConfig) {
23
51
  return __awaiter(this, void 0, void 0, function* () {
24
52
  // get current timestamp
@@ -54,15 +82,16 @@ class DataConnectorExecution {
54
82
  let request = yield this.dataConnector.execute('');
55
83
  let response;
56
84
  while (request != 'true') {
57
- const parsedRequest = yield pluginManager.process(JSON.parse(request));
85
+ const parsedRequest = yield pluginManager.process(typeof request == 'string' ? JSON.parse(request) : request);
58
86
  // On Chain
59
87
  if (this.dataConnector.configObj.isChainRead == true) {
60
88
  response = yield this.dataConnector.view(parsedRequest);
61
89
  }
62
90
  else {
63
91
  // Axios logic (off-chain)
64
- const ax_instance = axios_1.default.create();
65
- response = (yield ax_instance.request(parsedRequest)).data;
92
+ // add a delay on the request
93
+ yield this.delay(1000);
94
+ response = yield this.fetchData(parsedRequest, 0);
66
95
  }
67
96
  // break;
68
97
  request = yield this.dataConnector.execute(JSON.stringify(response));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerprotocol/data-connector-loader",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "App Loader for Steer Protocol",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",