@steerprotocol/data-connector-loader 2.1.0 → 3.0.0

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.
Files changed (52) hide show
  1. package/lib/{base → esm/bundle}/bundleBase.d.ts +7 -5
  2. package/lib/esm/bundle/bundleBase.js +127 -0
  3. package/lib/{bundle/bundleExecution.d.ts → esm/bundle/bundleDataConnector.d.ts} +2 -1
  4. package/lib/esm/bundle/bundleDataConnector.js +57 -0
  5. package/lib/esm/execution/executionApp.d.ts +17 -0
  6. package/lib/esm/execution/executionApp.js +304 -0
  7. package/lib/{loader/loaderBase.d.ts → esm/execution/executionBase.d.ts} +2 -2
  8. package/lib/esm/execution/executionBase.js +95 -0
  9. package/lib/esm/execution/executionDataConnector.d.ts +9 -0
  10. package/lib/esm/execution/executionDataConnector.js +90 -0
  11. package/lib/esm/index.d.ts +5 -0
  12. package/lib/esm/index.js +5 -0
  13. package/lib/esm/package.json +1 -0
  14. package/lib/esm/types.d.ts +104 -0
  15. package/lib/esm/types.js +1 -0
  16. package/lib/esm/utils/blockFinder.js +20 -0
  17. package/lib/esm/utils/consts.d.ts +4 -0
  18. package/lib/esm/utils/consts.js +4 -0
  19. package/lib/esm/utils/pluginManager.js +67 -0
  20. package/lib/esm/utils/utils.d.ts +16 -0
  21. package/lib/esm/utils/utils.js +119 -0
  22. package/lib/execution/executionApp.d.ts +3 -3
  23. package/lib/execution/executionApp.js +78 -80
  24. package/lib/execution/executionDataConnector.d.ts +2 -2
  25. package/lib/index.d.ts +1 -0
  26. package/lib/index.js +15 -0
  27. package/lib/types.d.ts +1 -1
  28. package/lib/utils/consts.js +2 -2
  29. package/lib/utils/utils.d.ts +5 -5
  30. package/lib/utils/utils.js +5 -5
  31. package/package.json +33 -3
  32. package/lib/base/bundleBase.js +0 -119
  33. package/lib/base/loaderBase.d.ts +0 -14
  34. package/lib/base/loaderBase.js +0 -111
  35. package/lib/blockFinder.js +0 -36
  36. package/lib/bundle/bundleApp.d.ts +0 -6
  37. package/lib/bundle/bundleApp.js +0 -11
  38. package/lib/bundle/bundleExecution.js +0 -42
  39. package/lib/bundleDataConnector.d.ts +0 -7
  40. package/lib/bundleDataConnector.js +0 -42
  41. package/lib/bundleExecution.d.ts +0 -7
  42. package/lib/bundleExecution.js +0 -42
  43. package/lib/dataConnector.d.ts +0 -27
  44. package/lib/dataConnector.js +0 -133
  45. package/lib/execution/executionBundle.d.ts +0 -5
  46. package/lib/execution/executionBundle.js +0 -29
  47. package/lib/loader/loaderBase.js +0 -111
  48. package/lib/pluginManager.js +0 -84
  49. package/lib/utils.d.ts +0 -2
  50. package/lib/utils.js +0 -28
  51. /package/lib/{blockFinder.d.ts → esm/utils/blockFinder.d.ts} +0 -0
  52. /package/lib/{pluginManager.d.ts → esm/utils/pluginManager.d.ts} +0 -0
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.PluginManager = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- class PluginManager {
18
- constructor() {
19
- this.registeredPluginConfigs = [];
20
- }
21
- registerFromPublicConfig() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { data: dataConnectorPlugins } = yield axios_1.default.get('https://ro81h8hq6b.execute-api.us-east-1.amazonaws.com/data-connector-plugins');
24
- for (const plugin of dataConnectorPlugins) {
25
- this.registerPluginConfig(plugin.name, plugin.domain, plugin.headers);
26
- }
27
- });
28
- }
29
- registerPluginConfig(name, domain, headers) {
30
- this.registeredPluginConfigs.push({ name, domain, headers });
31
- }
32
- findMatchingPluginConfigs(url) {
33
- const matchingHeaders = {};
34
- for (const pluginConfig of this.registeredPluginConfigs) {
35
- if (url.includes(pluginConfig.domain)) {
36
- Object.assign(matchingHeaders, pluginConfig.headers);
37
- }
38
- }
39
- return matchingHeaders;
40
- }
41
- interpolateEnvVars(str) {
42
- return str.replace(/\{\{(\w+)\}\}/g, (_match, envVar) => {
43
- const envValue = process.env[envVar];
44
- if (envValue === undefined) {
45
- console.log(`Environment variable '${envVar}' not found.`);
46
- return '';
47
- }
48
- return envValue;
49
- });
50
- }
51
- interpolateHeaders(headers) {
52
- const interpolatedHeaders = {};
53
- for (const [key, value] of Object.entries(headers)) {
54
- interpolatedHeaders[key] = typeof value === 'string' ? this.interpolateEnvVars(value) : value;
55
- }
56
- return interpolatedHeaders;
57
- }
58
- process(config) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- if (!config.url) {
61
- throw new Error('Request URL is not provided');
62
- }
63
- const matchingHeaders = this.findMatchingPluginConfigs(config.url);
64
- const interpolatedHeaders = this.interpolateHeaders(matchingHeaders);
65
- const updatedHeaders = Object.assign(Object.assign({}, config.headers), interpolatedHeaders);
66
- const updatedConfig = Object.assign(Object.assign({}, config), { headers: updatedHeaders });
67
- return updatedConfig;
68
- });
69
- }
70
- }
71
- exports.PluginManager = PluginManager;
72
- // // Usage example:
73
- // (async () => {
74
- // const headerMerger = new PluginManager();
75
- // headerMerger.registerPluginConfig('Example API', 'example.com', { 'X-Custom-Header': '{{MY_ENV_VAR}}' });
76
- // process.env['MY_ENV_VAR'] = 'ExampleValue';
77
- // const requestConfig: AxiosRequestConfig = {
78
- // url: 'https://example.com/api/some-resource',
79
- // method: 'GET',
80
- // };
81
- // const updatedRequestConfig = await headerMerger.process(requestConfig);
82
- // const response = await axios(updatedRequestConfig);
83
- // console.log(response.data);
84
- // })();
package/lib/utils.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { Candle } from "@steerprotocol/app-loader";
2
- export declare const extendOHLCV: (rawData: Candle[], period: number, endTimestamp: number) => Candle[];
package/lib/utils.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extendOHLCV = void 0;
4
- // The purpose of this function is to look at the end timestamp and extend the current candle array so that it backfills any missing candles up to the end timestamp
5
- const extendOHLCV = (rawData, period, endTimestamp) => {
6
- // Sort rawData by timestamp
7
- const sortedData = rawData.sort((a, b) => a.timestamp - b.timestamp);
8
- const lastCandle = sortedData[sortedData.length - 1];
9
- const startTimestamp = lastCandle ? lastCandle.timestamp : endTimestamp;
10
- // Calculate the number of periods to backfill
11
- const periodsToBackfill = Math.floor(((endTimestamp - startTimestamp)) / 1000 / period);
12
- // Backfill the candles
13
- for (let i = 0; i < periodsToBackfill; i++) {
14
- const candleWidth = (period * (i + 1));
15
- const newCandle = {
16
- timestamp: startTimestamp + candleWidth,
17
- open: lastCandle.open,
18
- high: lastCandle.open,
19
- low: lastCandle.open,
20
- close: lastCandle.open,
21
- volume: 0, // You may need to replace these with appropriate logic
22
- };
23
- sortedData.push(newCandle);
24
- }
25
- // Return the converted data
26
- return sortedData;
27
- };
28
- exports.extendOHLCV = extendOHLCV;