@chainlink/external-adapter-framework 0.0.15 → 0.0.17

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 (186) hide show
  1. package/adapter.js +128 -0
  2. package/background-executor.js +45 -0
  3. package/cache/factory.js +58 -0
  4. package/cache/index.js +173 -0
  5. package/cache/local.js +83 -0
  6. package/cache/metrics.js +120 -0
  7. package/cache/redis.js +100 -0
  8. package/chainlink-external-adapter-framework-v0.0.6.tgz +0 -0
  9. package/config/index.js +366 -0
  10. package/config/provider-limits.js +74 -0
  11. package/examples/bank-frick/accounts.js +192 -0
  12. package/examples/bank-frick/config/index.js +54 -0
  13. package/examples/bank-frick/index.js +15 -0
  14. package/examples/bank-frick/util.js +39 -0
  15. package/examples/coingecko/batch-warming.js +53 -0
  16. package/examples/coingecko/index.js +11 -0
  17. package/examples/coingecko/rest.js +51 -0
  18. package/examples/coingecko/src/config/index.js +13 -0
  19. package/examples/coingecko/src/config/overrides.json +10826 -0
  20. package/examples/coingecko/src/cryptoUtils.js +41 -0
  21. package/examples/coingecko/src/endpoint/coins.js +33 -0
  22. package/examples/coingecko/src/endpoint/crypto-marketcap.js +46 -0
  23. package/examples/coingecko/src/endpoint/crypto-volume.js +46 -0
  24. package/examples/coingecko/src/endpoint/crypto.js +47 -0
  25. package/examples/coingecko/src/endpoint/dominance.js +26 -0
  26. package/examples/coingecko/src/endpoint/global-marketcap.js +26 -0
  27. package/examples/coingecko/src/endpoint/index.js +15 -0
  28. package/examples/coingecko/src/globalUtils.js +48 -0
  29. package/examples/coingecko/src/index.js +14 -0
  30. package/examples/coingecko/test/e2e/adapter.test.js +262 -0
  31. package/examples/coingecko/test/integration/adapter.test.js +264 -0
  32. package/examples/coingecko/test/integration/capturedRequests.json +1 -0
  33. package/examples/coingecko/test/integration/fixtures.js +41 -0
  34. package/examples/coingecko-old/batch-warming.js +53 -0
  35. package/examples/coingecko-old/index.js +11 -0
  36. package/examples/coingecko-old/rest.js +51 -0
  37. package/examples/ncfx/config/index.js +15 -0
  38. package/examples/ncfx/index.js +11 -0
  39. package/examples/ncfx/websocket.js +73 -0
  40. package/index.js +127 -0
  41. package/metrics/constants.js +25 -0
  42. package/metrics/index.js +122 -0
  43. package/metrics/util.js +9 -0
  44. package/package.json +5 -15
  45. package/rate-limiting/background/fixed-frequency.js +35 -0
  46. package/rate-limiting/index.js +84 -0
  47. package/rate-limiting/metrics.js +44 -0
  48. package/rate-limiting/request/simple-counting.js +62 -0
  49. package/test.js +6 -0
  50. package/transports/batch-warming.js +101 -0
  51. package/transports/index.js +87 -0
  52. package/transports/metrics.js +105 -0
  53. package/transports/rest.js +138 -0
  54. package/transports/util.js +86 -0
  55. package/transports/websocket.js +166 -0
  56. package/util/index.js +35 -0
  57. package/util/logger.js +62 -0
  58. package/util/recordRequests.js +45 -0
  59. package/util/request.js +2 -0
  60. package/util/subscription-set/expiring-sorted-set.js +47 -0
  61. package/util/subscription-set/subscription-set.js +19 -0
  62. package/util/test-payload-loader.js +83 -0
  63. package/validation/error.js +79 -0
  64. package/validation/index.js +91 -0
  65. package/validation/input-params.js +30 -0
  66. package/validation/override-functions.js +40 -0
  67. package/validation/overrideFunctions.js +40 -0
  68. package/validation/preset-tokens.json +23 -0
  69. package/validation/validator.js +303 -0
  70. package/.c8rc.json +0 -3
  71. package/.eslintignore +0 -10
  72. package/.eslintrc.js +0 -96
  73. package/.github/README.MD +0 -42
  74. package/.github/actions/setup/action.yaml +0 -13
  75. package/.github/workflows/label.yaml +0 -39
  76. package/.github/workflows/main.yaml +0 -39
  77. package/.github/workflows/publish.yaml +0 -17
  78. package/.prettierignore +0 -13
  79. package/.yarnrc +0 -0
  80. package/README.md +0 -103
  81. package/dist/examples/coingecko/test/e2e/adapter.test.ts.js +0 -82953
  82. package/dist/examples/coingecko/test/integration/adapter.test.ts.js +0 -91672
  83. package/dist/main.js +0 -72703
  84. package/docker-compose.yaml +0 -35
  85. package/env.sh +0 -54
  86. package/env2.sh +0 -55
  87. package/jest.config.js +0 -5
  88. package/publish.sh +0 -0
  89. package/src/adapter.ts +0 -263
  90. package/src/background-executor.ts +0 -52
  91. package/src/cache/factory.ts +0 -26
  92. package/src/cache/index.ts +0 -258
  93. package/src/cache/local.ts +0 -73
  94. package/src/cache/metrics.ts +0 -112
  95. package/src/cache/redis.ts +0 -93
  96. package/src/config/index.ts +0 -517
  97. package/src/config/provider-limits.ts +0 -127
  98. package/src/examples/bank-frick/README.MD +0 -10
  99. package/src/examples/bank-frick/accounts.ts +0 -246
  100. package/src/examples/bank-frick/config/index.ts +0 -53
  101. package/src/examples/bank-frick/index.ts +0 -13
  102. package/src/examples/bank-frick/types.d.ts +0 -38
  103. package/src/examples/bank-frick/util.ts +0 -55
  104. package/src/examples/coingecko/src/config/index.ts +0 -12
  105. package/src/examples/coingecko/src/config/overrides.json +0 -10826
  106. package/src/examples/coingecko/src/cryptoUtils.ts +0 -88
  107. package/src/examples/coingecko/src/endpoint/coins.ts +0 -54
  108. package/src/examples/coingecko/src/endpoint/crypto-marketcap.ts +0 -66
  109. package/src/examples/coingecko/src/endpoint/crypto-volume.ts +0 -66
  110. package/src/examples/coingecko/src/endpoint/crypto.ts +0 -63
  111. package/src/examples/coingecko/src/endpoint/dominance.ts +0 -40
  112. package/src/examples/coingecko/src/endpoint/global-marketcap.ts +0 -40
  113. package/src/examples/coingecko/src/endpoint/index.ts +0 -6
  114. package/src/examples/coingecko/src/globalUtils.ts +0 -78
  115. package/src/examples/coingecko/src/index.ts +0 -17
  116. package/src/examples/coingecko/test/e2e/adapter.test.ts +0 -278
  117. package/src/examples/coingecko/test/integration/__snapshots__/adapter.test.ts.snap +0 -15
  118. package/src/examples/coingecko/test/integration/adapter.test.ts +0 -281
  119. package/src/examples/coingecko/test/integration/capturedRequests.json +0 -1
  120. package/src/examples/coingecko/test/integration/fixtures.ts +0 -42
  121. package/src/examples/coingecko-old/batch-warming.ts +0 -79
  122. package/src/examples/coingecko-old/index.ts +0 -9
  123. package/src/examples/coingecko-old/rest.ts +0 -77
  124. package/src/examples/ncfx/config/index.ts +0 -12
  125. package/src/examples/ncfx/index.ts +0 -9
  126. package/src/examples/ncfx/websocket.ts +0 -99
  127. package/src/index.ts +0 -149
  128. package/src/metrics/constants.ts +0 -23
  129. package/src/metrics/index.ts +0 -115
  130. package/src/metrics/util.ts +0 -18
  131. package/src/rate-limiting/background/fixed-frequency.ts +0 -45
  132. package/src/rate-limiting/index.ts +0 -100
  133. package/src/rate-limiting/metrics.ts +0 -18
  134. package/src/rate-limiting/request/simple-counting.ts +0 -76
  135. package/src/transports/batch-warming.ts +0 -127
  136. package/src/transports/index.ts +0 -152
  137. package/src/transports/metrics.ts +0 -95
  138. package/src/transports/rest.ts +0 -168
  139. package/src/transports/util.ts +0 -63
  140. package/src/transports/websocket.ts +0 -245
  141. package/src/util/index.ts +0 -23
  142. package/src/util/logger.ts +0 -69
  143. package/src/util/recordRequests.ts +0 -47
  144. package/src/util/request.ts +0 -117
  145. package/src/util/subscription-set/expiring-sorted-set.ts +0 -54
  146. package/src/util/subscription-set/subscription-set.ts +0 -35
  147. package/src/util/test-payload-loader.ts +0 -87
  148. package/src/validation/error.ts +0 -116
  149. package/src/validation/index.ts +0 -110
  150. package/src/validation/input-params.ts +0 -45
  151. package/src/validation/override-functions.ts +0 -44
  152. package/src/validation/overrideFunctions.ts +0 -44
  153. package/src/validation/preset-tokens.json +0 -23
  154. package/src/validation/validator.ts +0 -384
  155. package/test/adapter.test.ts +0 -27
  156. package/test/background-executor.test.ts +0 -108
  157. package/test/cache/cache-key.test.ts +0 -114
  158. package/test/cache/helper.ts +0 -100
  159. package/test/cache/local.test.ts +0 -54
  160. package/test/cache/redis.test.ts +0 -89
  161. package/test/correlation.test.ts +0 -114
  162. package/test/index.test.ts +0 -37
  163. package/test/metrics/feed-id.test.ts +0 -38
  164. package/test/metrics/helper.ts +0 -14
  165. package/test/metrics/labels.test.ts +0 -36
  166. package/test/metrics/metrics.test.ts +0 -267
  167. package/test/metrics/redis-metrics.test.ts +0 -113
  168. package/test/metrics/warmer-metrics.test.ts +0 -193
  169. package/test/metrics/ws-metrics.test.ts +0 -225
  170. package/test/rate-limit-config.test.ts +0 -242
  171. package/test/smoke/smoke.test.ts +0 -166
  172. package/test/smoke/test-payload-fail.json +0 -3
  173. package/test/smoke/test-payload.js +0 -22
  174. package/test/smoke/test-payload.json +0 -7
  175. package/test/transports/batch.test.ts +0 -466
  176. package/test/transports/rest.test.ts +0 -242
  177. package/test/transports/websocket.test.ts +0 -183
  178. package/test/tsconfig.json +0 -5
  179. package/test/util.ts +0 -77
  180. package/test/validation.test.ts +0 -178
  181. package/test.sh +0 -20
  182. package/test2.sh +0 -2
  183. package/tsconfig.json +0 -28
  184. package/typedoc.json +0 -6
  185. package/webpack.config.js +0 -57
  186. package/yarn-error.log +0 -3778
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructEntry = exports.buildBatchedRequestBody = void 0;
4
+ const config_1 = require("./config");
5
+ const logger_1 = require("../../../util/logger");
6
+ const buildBatchedRequestBody = (params, config) => {
7
+ return {
8
+ baseURL: config.API_KEY ? config_1.PRO_API_ENDPOINT : config_1.DEFAULT_API_ENDPOINT,
9
+ url: '/simple/price',
10
+ method: 'GET',
11
+ params: {
12
+ ids: [...new Set(params.map((p) => p.coinid ?? p.base))].join(','),
13
+ vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
14
+ x_cg_pro_api_key: config.API_KEY,
15
+ },
16
+ };
17
+ };
18
+ exports.buildBatchedRequestBody = buildBatchedRequestBody;
19
+ const logger = (0, logger_1.makeLogger)('CoinGecko Crypto Batched');
20
+ const constructEntry = (res, requestPayload, resultPath) => {
21
+ const coinId = requestPayload.coinid ?? requestPayload.base;
22
+ const dataForCoin = res.data[coinId];
23
+ const dataForQuote = dataForCoin ? dataForCoin[resultPath] : undefined;
24
+ if (!dataForQuote) {
25
+ logger.warn(`Data for "${requestPayload.quote}" not found for token "${coinId}".`);
26
+ return;
27
+ }
28
+ const entry = {
29
+ params: requestPayload,
30
+ value: dataForQuote,
31
+ };
32
+ if (requestPayload.coinid) {
33
+ entry.params.coinid = requestPayload.coinid;
34
+ }
35
+ else {
36
+ entry.params.base = requestPayload.base;
37
+ }
38
+ delete entry.params.overrides;
39
+ return entry;
40
+ };
41
+ exports.constructEntry = constructEntry;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = exports.inputParameters = void 0;
4
+ const transports_1 = require("../../../../../src/transports");
5
+ const config_1 = require("../config");
6
+ exports.inputParameters = {};
7
+ const restEndpointTransport = new transports_1.RestTransport({
8
+ prepareRequest: (_, config) => {
9
+ const baseURL = config.API_KEY ? config_1.PRO_API_ENDPOINT : config_1.DEFAULT_API_ENDPOINT;
10
+ const params = config.API_KEY ? { x_cg_pro_api_key: config.API_KEY } : undefined;
11
+ return {
12
+ baseURL,
13
+ url: '/coins/list',
14
+ method: 'GET',
15
+ params,
16
+ };
17
+ },
18
+ parseResponse: (req, res) => {
19
+ return {
20
+ data: res.data,
21
+ statusCode: 200,
22
+ result: res.data,
23
+ };
24
+ },
25
+ options: {
26
+ coalescing: true,
27
+ },
28
+ });
29
+ exports.endpoint = {
30
+ name: 'coins',
31
+ transport: restEndpointTransport,
32
+ inputParameters: exports.inputParameters,
33
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = exports.inputParameters = void 0;
4
+ const batch_warming_1 = require("../../../../transports/batch-warming");
5
+ const input_params_1 = require("../../../../validation/input-params");
6
+ const cryptoUtils_1 = require("../cryptoUtils");
7
+ exports.inputParameters = {
8
+ overrides: input_params_1.baseInputParameters['overrides'],
9
+ coinid: {
10
+ description: 'The CoinGecko id or to query',
11
+ required: false,
12
+ },
13
+ base: {
14
+ aliases: ['from', 'coin'],
15
+ description: 'The symbol of symbols of the currency to query',
16
+ required: false,
17
+ },
18
+ quote: {
19
+ aliases: ['to', 'market'],
20
+ description: 'The symbol of the currency to convert to',
21
+ required: true,
22
+ },
23
+ };
24
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
25
+ prepareRequest: (params, context) => {
26
+ const requestBody = (0, cryptoUtils_1.buildBatchedRequestBody)(params, context.adapterConfig);
27
+ requestBody.params.include_market_cap = true;
28
+ return requestBody;
29
+ },
30
+ parseResponse: (params, res) => {
31
+ const entries = [];
32
+ for (const requestPayload of params) {
33
+ const entry = (0, cryptoUtils_1.constructEntry)(res, requestPayload, `${requestPayload.quote.toLowerCase()}_market_cap`);
34
+ if (entry) {
35
+ entries.push(entry);
36
+ }
37
+ }
38
+ return entries;
39
+ },
40
+ });
41
+ exports.endpoint = {
42
+ name: 'marketcap',
43
+ aliases: ['crypto-marketcap'],
44
+ transport: batchEndpointTransport,
45
+ inputParameters: exports.inputParameters,
46
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = exports.inputParameters = void 0;
4
+ const batch_warming_1 = require("../../../../transports/batch-warming");
5
+ const input_params_1 = require("../../../../validation/input-params");
6
+ const cryptoUtils_1 = require("../cryptoUtils");
7
+ exports.inputParameters = {
8
+ overrides: input_params_1.baseInputParameters['overrides'],
9
+ coinid: {
10
+ description: 'The CoinGecko id or to query',
11
+ required: false,
12
+ },
13
+ base: {
14
+ aliases: ['from', 'coin'],
15
+ description: 'The symbol of symbols of the currency to query',
16
+ required: false,
17
+ },
18
+ quote: {
19
+ aliases: ['to', 'market'],
20
+ description: 'The symbol of the currency to convert to',
21
+ required: true,
22
+ },
23
+ };
24
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
25
+ prepareRequest: (params, context) => {
26
+ const requestBody = (0, cryptoUtils_1.buildBatchedRequestBody)(params, context.adapterConfig);
27
+ requestBody.params.include_24hr_vol = true;
28
+ return requestBody;
29
+ },
30
+ parseResponse: (params, res) => {
31
+ const entries = [];
32
+ for (const requestPayload of params) {
33
+ const entry = (0, cryptoUtils_1.constructEntry)(res, requestPayload, `${requestPayload.quote.toLowerCase()}_24h_vol`);
34
+ if (entry) {
35
+ entries.push(entry);
36
+ }
37
+ }
38
+ return entries;
39
+ },
40
+ });
41
+ exports.endpoint = {
42
+ name: 'volume',
43
+ aliases: ['crypto-volume'],
44
+ transport: batchEndpointTransport,
45
+ inputParameters: exports.inputParameters,
46
+ };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = exports.inputParameters = void 0;
4
+ const batch_warming_1 = require("../../../../transports/batch-warming");
5
+ const input_params_1 = require("../../../../validation/input-params");
6
+ const cryptoUtils_1 = require("../cryptoUtils");
7
+ exports.inputParameters = {
8
+ overrides: input_params_1.baseInputParameters['overrides'],
9
+ coinid: {
10
+ description: 'The CoinGecko id or to query',
11
+ required: false,
12
+ },
13
+ base: {
14
+ aliases: ['from', 'coin'],
15
+ description: 'The symbol of symbols of the currency to query',
16
+ required: false,
17
+ },
18
+ quote: {
19
+ aliases: ['to', 'market'],
20
+ description: 'The symbol of the currency to convert to',
21
+ required: true,
22
+ },
23
+ };
24
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
25
+ prepareRequest: (params, context) => {
26
+ return (0, cryptoUtils_1.buildBatchedRequestBody)(params, context.adapterConfig);
27
+ },
28
+ parseResponse: (params, res) => {
29
+ const entries = [];
30
+ for (const requestPayload of params) {
31
+ const entry = (0, cryptoUtils_1.constructEntry)(res, requestPayload, requestPayload.quote.toLowerCase());
32
+ // NOTE: the `entries` array is going to be shorter than the `params` array if one of the params has a bad token.
33
+ // Is that okay? I did this to avoid caching an invalid value for transient DP issues. Just want to make
34
+ // sure this works within the core framework
35
+ if (entry) {
36
+ entries.push(entry);
37
+ }
38
+ }
39
+ return entries;
40
+ },
41
+ });
42
+ exports.endpoint = {
43
+ name: 'crypto',
44
+ aliases: ['crypto-batched', 'batched', 'batch'],
45
+ transport: batchEndpointTransport,
46
+ inputParameters: exports.inputParameters,
47
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = void 0;
4
+ const batch_warming_1 = require("../../../../transports/batch-warming");
5
+ const globalUtils_1 = require("../globalUtils");
6
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
7
+ prepareRequest: (params, context) => {
8
+ return (0, globalUtils_1.buildGlobalRequestBody)(context.adapterConfig);
9
+ },
10
+ parseResponse: (params, res) => {
11
+ const entries = [];
12
+ for (const requestPayload of params) {
13
+ const entry = (0, globalUtils_1.constructEntry)(res, requestPayload, 'market_cap_percentage');
14
+ if (entry) {
15
+ entries.push(entry);
16
+ }
17
+ }
18
+ return entries;
19
+ },
20
+ });
21
+ exports.endpoint = {
22
+ name: 'dominance',
23
+ aliases: ['market_cap_percentage'],
24
+ transport: batchEndpointTransport,
25
+ inputParameters: globalUtils_1.inputParameters,
26
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endpoint = void 0;
4
+ const batch_warming_1 = require("../../../../transports/batch-warming");
5
+ const globalUtils_1 = require("../globalUtils");
6
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
7
+ prepareRequest: (params, context) => {
8
+ return (0, globalUtils_1.buildGlobalRequestBody)(context.adapterConfig);
9
+ },
10
+ parseResponse: (params, res) => {
11
+ const entries = [];
12
+ for (const requestPayload of params) {
13
+ const entry = (0, globalUtils_1.constructEntry)(res, requestPayload, 'total_market_cap');
14
+ if (entry) {
15
+ entries.push(entry);
16
+ }
17
+ }
18
+ return entries;
19
+ },
20
+ });
21
+ exports.endpoint = {
22
+ name: 'globalmarketcap',
23
+ aliases: ['total_market_cap'],
24
+ transport: batchEndpointTransport,
25
+ inputParameters: globalUtils_1.inputParameters,
26
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cryptoVolume = exports.dominance = exports.globalMarketcap = exports.cryptoMarketcap = exports.crypto = exports.coins = void 0;
4
+ var coins_1 = require("./coins");
5
+ Object.defineProperty(exports, "coins", { enumerable: true, get: function () { return coins_1.endpoint; } });
6
+ var crypto_1 = require("./crypto");
7
+ Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return crypto_1.endpoint; } });
8
+ var crypto_marketcap_1 = require("./crypto-marketcap");
9
+ Object.defineProperty(exports, "cryptoMarketcap", { enumerable: true, get: function () { return crypto_marketcap_1.endpoint; } });
10
+ var global_marketcap_1 = require("./global-marketcap");
11
+ Object.defineProperty(exports, "globalMarketcap", { enumerable: true, get: function () { return global_marketcap_1.endpoint; } });
12
+ var dominance_1 = require("./dominance");
13
+ Object.defineProperty(exports, "dominance", { enumerable: true, get: function () { return dominance_1.endpoint; } });
14
+ var crypto_volume_1 = require("./crypto-volume");
15
+ Object.defineProperty(exports, "cryptoVolume", { enumerable: true, get: function () { return crypto_volume_1.endpoint; } });
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructEntry = exports.buildGlobalRequestBody = exports.inputParameters = void 0;
4
+ const config_1 = require("./config");
5
+ const logger_1 = require("../../../util/logger");
6
+ const logger = (0, logger_1.makeLogger)('CoinGecko Global Batched');
7
+ exports.inputParameters = {
8
+ market: {
9
+ aliases: ['to', 'quote'],
10
+ description: 'The ticker of the coin to query',
11
+ required: true,
12
+ },
13
+ };
14
+ const buildGlobalRequestBody = (config) => {
15
+ const apiKey = {
16
+ x_cg_pro_api_key: config.API_KEY,
17
+ };
18
+ return {
19
+ baseURL: config.API_KEY ? config_1.PRO_API_ENDPOINT : config_1.DEFAULT_API_ENDPOINT,
20
+ url: '/global',
21
+ method: 'GET',
22
+ params: apiKey,
23
+ };
24
+ };
25
+ exports.buildGlobalRequestBody = buildGlobalRequestBody;
26
+ const constructEntry = (res, requestPayload, resultPath) => {
27
+ const resultData = res.data.data;
28
+ if (!resultData) {
29
+ logger.warn(`Data not found".`);
30
+ return;
31
+ }
32
+ const totalMarketcapData = resultData[resultPath];
33
+ if (!totalMarketcapData) {
34
+ logger.warn(`Data for "${resultPath}" not found".`);
35
+ return;
36
+ }
37
+ const result = totalMarketcapData[requestPayload.market.toLowerCase()];
38
+ if (!result) {
39
+ logger.warn(`Data for "${requestPayload.market}" not found".`);
40
+ return;
41
+ }
42
+ const entry = {
43
+ params: requestPayload,
44
+ value: result,
45
+ };
46
+ return entry;
47
+ };
48
+ exports.constructEntry = constructEntry;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.adapter = void 0;
7
+ const overrides_json_1 = __importDefault(require("./config/overrides.json"));
8
+ const endpoint_1 = require("./endpoint");
9
+ exports.adapter = {
10
+ defaultEndpoint: 'crypto',
11
+ name: 'coingecko',
12
+ endpoints: [endpoint_1.crypto, endpoint_1.coins, endpoint_1.cryptoMarketcap, endpoint_1.cryptoVolume, endpoint_1.dominance, endpoint_1.globalMarketcap],
13
+ overrides: overrides_json_1.default['coingecko'],
14
+ };
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* eslint-disable max-nested-callbacks */
7
+ const index_1 = require("../../src/index");
8
+ const __1 = require("../../../..");
9
+ const supertest_1 = __importDefault(require("supertest"));
10
+ let adapterServer;
11
+ function sleep(ms) {
12
+ // eslint-disable-next-line
13
+ return new Promise((resolve) => setTimeout(resolve, ms));
14
+ }
15
+ describe('execute', () => {
16
+ const id = '1';
17
+ let req;
18
+ jest.setTimeout(10000);
19
+ const successfulRequests = {
20
+ crypto: {
21
+ id,
22
+ data: {
23
+ base: 'ETH',
24
+ quote: 'USD',
25
+ },
26
+ },
27
+ cryptoWithCoinid: {
28
+ id,
29
+ data: {
30
+ coinid: 'bitcoin',
31
+ quote: 'USD',
32
+ },
33
+ },
34
+ cryptoWithOverride: {
35
+ id,
36
+ data: {
37
+ base: 'BTC',
38
+ quote: 'EUR',
39
+ overrides: {
40
+ coingecko: {
41
+ BTC: 'solana',
42
+ },
43
+ },
44
+ },
45
+ },
46
+ coins: {
47
+ id,
48
+ endpoint: 'coins',
49
+ },
50
+ marketcap: {
51
+ id,
52
+ endpoint: 'marketcap',
53
+ data: {
54
+ base: 'ETH',
55
+ quote: 'USD',
56
+ },
57
+ },
58
+ volume: {
59
+ id,
60
+ endpoint: 'volume',
61
+ data: {
62
+ base: 'ETH',
63
+ quote: 'USD',
64
+ },
65
+ },
66
+ globalmarketcap: {
67
+ id,
68
+ endpoint: 'globalmarketcap',
69
+ data: {
70
+ market: 'ETH',
71
+ },
72
+ },
73
+ dominance: {
74
+ id,
75
+ endpoint: 'dominance',
76
+ data: {
77
+ market: 'ETH',
78
+ },
79
+ },
80
+ };
81
+ const errorRequests = {
82
+ cryptoWithBadSymbol: {
83
+ id,
84
+ data: {
85
+ base: 'ZWXK',
86
+ quote: 'USD',
87
+ },
88
+ },
89
+ cryptoWithBadOverride: {
90
+ id,
91
+ data: {
92
+ base: 'LINK',
93
+ quote: 'USD',
94
+ overrides: {
95
+ coingecko: {
96
+ LINK: 'badtokenid',
97
+ },
98
+ },
99
+ },
100
+ },
101
+ dominanceWithBadSymbol: {
102
+ id,
103
+ endpoint: 'dominance',
104
+ data: {
105
+ market: 'ZWXK',
106
+ },
107
+ },
108
+ };
109
+ beforeAll(async () => {
110
+ try {
111
+ adapterServer = await (0, __1.expose)(index_1.adapter);
112
+ req = (0, supertest_1.default)('localhost:8080');
113
+ }
114
+ catch {
115
+ throw new Error('Could not start server when running CoinGecko e2e tests');
116
+ }
117
+ if (!adapterServer) {
118
+ throw new Error('Could not start server when running CoinGecko e2e tests');
119
+ }
120
+ // Send inital requests to warm the cache
121
+ const pendingRequests = [];
122
+ for (const reqData of Object.values(successfulRequests)) {
123
+ pendingRequests.push(req.post('/').send(reqData));
124
+ }
125
+ for (const reqData of Object.values(errorRequests)) {
126
+ pendingRequests.push(req.post('/').send(reqData));
127
+ }
128
+ // Wait for all the pending requests to be complete
129
+ Promise.all(pendingRequests);
130
+ // Sleep while the cache is filled
131
+ await sleep(5000);
132
+ });
133
+ afterAll((done) => {
134
+ if (adapterServer) {
135
+ adapterServer.close(done());
136
+ }
137
+ });
138
+ describe('crypto api', () => {
139
+ it('should return success', async () => {
140
+ // Send inital request to warm cache
141
+ const response = await req
142
+ .post('/')
143
+ .send(successfulRequests.crypto)
144
+ .set('Accept', '*/*')
145
+ .set('Content-Type', 'application/json')
146
+ .expect(200);
147
+ expect(response.body.result).toBeGreaterThan(0);
148
+ });
149
+ it('should return success with coinid', async () => {
150
+ const response = await req
151
+ .post('/')
152
+ .send(successfulRequests.cryptoWithCoinid)
153
+ .set('Accept', '*/*')
154
+ .set('Content-Type', 'application/json')
155
+ .expect('Content-Type', /json/)
156
+ .expect(200);
157
+ expect(response.body.result).toBeGreaterThan(0);
158
+ });
159
+ it('should return error message for bad symbol', async () => {
160
+ await req
161
+ .post('/')
162
+ .send(errorRequests.cryptoWithBadSymbol)
163
+ .set('Accept', '*/*')
164
+ .set('Content-Type', 'application/json')
165
+ .expect(504);
166
+ });
167
+ it('should return success with override', async () => {
168
+ const response = await req
169
+ .post('/')
170
+ .send(successfulRequests.cryptoWithOverride)
171
+ .set('Accept', '*/*')
172
+ .set('Content-Type', 'application/json')
173
+ .expect('Content-Type', /json/)
174
+ .expect(200);
175
+ expect(response.body.result).toBeGreaterThan(0);
176
+ });
177
+ it('should return 504 for bad override', async () => {
178
+ const response = await req
179
+ .post('/')
180
+ .send(errorRequests.cryptoWithBadOverride)
181
+ .set('Accept', '*/*')
182
+ .set('Content-Type', 'application/json')
183
+ .expect(504);
184
+ expect(typeof response.body.result === 'string');
185
+ });
186
+ it('should return 504 for bad symbol', async () => {
187
+ await req
188
+ .post('/')
189
+ .send(errorRequests.cryptoWithBadSymbol)
190
+ .set('Accept', '*/*')
191
+ .set('Content-Type', 'application/json')
192
+ .expect(504);
193
+ });
194
+ });
195
+ describe('coins api', () => {
196
+ it('should return success', async () => {
197
+ await req
198
+ .post('/')
199
+ .send(successfulRequests.coins)
200
+ .set('Accept', '*/*')
201
+ .set('Content-Type', 'application/json')
202
+ .expect('Content-Type', /json/)
203
+ .expect(200);
204
+ });
205
+ });
206
+ describe('volume api', () => {
207
+ it('should return success', async () => {
208
+ const response = await req
209
+ .post('/')
210
+ .send(successfulRequests.volume)
211
+ .set('Accept', '*/*')
212
+ .set('Content-Type', 'application/json')
213
+ .expect('Content-Type', /json/)
214
+ .expect(200);
215
+ expect(response.body.result).toBeGreaterThan(0);
216
+ });
217
+ });
218
+ describe('marketcap api', () => {
219
+ it('should return success', async () => {
220
+ const response = await req
221
+ .post('/')
222
+ .send(successfulRequests.marketcap)
223
+ .set('Accept', '*/*')
224
+ .set('Content-Type', 'application/json')
225
+ .expect('Content-Type', /json/)
226
+ .expect(200);
227
+ expect(response.body.result).toBeGreaterThan(0);
228
+ });
229
+ });
230
+ describe('globalmarketcap api', () => {
231
+ it('should return success', async () => {
232
+ const response = await req
233
+ .post('/')
234
+ .send(successfulRequests.globalmarketcap)
235
+ .set('Accept', '*/*')
236
+ .set('Content-Type', 'application/json')
237
+ .expect('Content-Type', /json/)
238
+ .expect(200);
239
+ expect(response.body.result).toBeGreaterThan(0);
240
+ });
241
+ });
242
+ describe('dominance api', () => {
243
+ it('should return success', async () => {
244
+ const response = await req
245
+ .post('/')
246
+ .send(successfulRequests.dominance)
247
+ .set('Accept', '*/*')
248
+ .set('Content-Type', 'application/json')
249
+ .expect('Content-Type', /json/)
250
+ .expect(200);
251
+ expect(response.body.result).toBeGreaterThan(0);
252
+ });
253
+ it('should return 504 for bad symbol', async () => {
254
+ await req
255
+ .post('/')
256
+ .send(errorRequests.dominanceWithBadSymbol)
257
+ .set('Accept', '*/*')
258
+ .set('Content-Type', 'application/json')
259
+ .expect(504);
260
+ });
261
+ });
262
+ });