@steerprotocol/data-connector-loader 0.0.5 → 0.0.7

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
@@ -8,15 +8,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.DataConnectorExecution = void 0;
13
- // eslint-disable-next-line @typescript-eslint/no-var-requires
14
- const axios = require('axios');
16
+ const axios_1 = __importDefault(require("axios"));
15
17
  const pluginManager_1 = require("./pluginManager");
16
18
  class DataConnectorExecution {
17
19
  constructor(dataConnector) {
18
20
  this.dataConnector = dataConnector;
19
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
+ }
20
50
  execute(vaultAddress, _vaultConfig) {
21
51
  return __awaiter(this, void 0, void 0, function* () {
22
52
  // get current timestamp
@@ -36,10 +66,6 @@ class DataConnectorExecution {
36
66
  if (!connectorConfig.bundleHash) {
37
67
  continue;
38
68
  }
39
- this.dataConnector.setExecutionContext({
40
- executionTimestamp,
41
- epochLength: Number(vaultConfig.strategyConfigData.epochLength)
42
- });
43
69
  // Append vault address to config
44
70
  if (vaultAddress) {
45
71
  connectorConfig.configData.vaultAddress = vaultAddress;
@@ -48,19 +74,24 @@ class DataConnectorExecution {
48
74
  if (!this.dataConnector.module) {
49
75
  yield this.dataConnector.load();
50
76
  }
77
+ this.dataConnector.setExecutionContext({
78
+ executionTimestamp,
79
+ epochLength: Number(vaultConfig.strategyConfigData.epochLength)
80
+ });
51
81
  // get first request
52
82
  let request = yield this.dataConnector.execute('');
53
83
  let response;
54
84
  while (request != 'true') {
55
- const parsedRequest = yield pluginManager.process(JSON.parse(request));
85
+ const parsedRequest = yield pluginManager.process(typeof request == 'string' ? JSON.parse(request) : request);
56
86
  // On Chain
57
87
  if (this.dataConnector.configObj.isChainRead == true) {
58
88
  response = yield this.dataConnector.view(parsedRequest);
59
89
  }
60
90
  else {
61
91
  // Axios logic (off-chain)
62
- const ax_instance = axios.create();
63
- 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);
64
95
  }
65
96
  // break;
66
97
  request = yield this.dataConnector.execute(JSON.stringify(response));
@@ -73,7 +104,7 @@ class DataConnectorExecution {
73
104
  }
74
105
  downloadWasmBundle(ipfsHash) {
75
106
  return __awaiter(this, void 0, void 0, function* () {
76
- const response = yield axios.get(`https://steerprotocol.mypinata.cloud/ipfs/${ipfsHash}`, {
107
+ const response = yield axios_1.default.get(`https://steerprotocol.mypinata.cloud/ipfs/${ipfsHash}`, {
77
108
  responseType: 'arraybuffer',
78
109
  });
79
110
  const wasmFile = new Uint8Array(response.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerprotocol/data-connector-loader",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "App Loader for Steer Protocol",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",