@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,192 @@
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.accountsRestEndpoint = exports.BankFrickAccountsTransport = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const util_1 = require("./util");
9
+ const util_2 = require("../../util");
10
+ const error_1 = require("../../validation/error");
11
+ const adapter_1 = require("../../adapter");
12
+ const logger = (0, util_2.makeLogger)('BankFrickTransport');
13
+ // Note: this is a shallow pattern that only checks for a country code since IBANs in the sandbox are invalid
14
+ const ibanPattern = /^[A-Z]{2}[A-Z\d]{14,30}$/;
15
+ const inputParameters = {
16
+ ibanIDs: {
17
+ description: 'The list of account ids included in the sum of balances',
18
+ required: true,
19
+ type: 'array',
20
+ },
21
+ signingAlgorithm: {
22
+ description: 'What signing algorithm is used to sign and verify authorization data, one of rsa-sha256, rsa-sha384, or rsa-sha512',
23
+ required: false,
24
+ type: 'string',
25
+ default: 'rsa-sha512',
26
+ options: ['rsa-sha256', 'rsa-sha384', 'rsa-sha512'],
27
+ },
28
+ };
29
+ // See here for all expected error returned by the API: https://developers.bankfrick.li/docs#errors
30
+ const AuthErrors = {
31
+ 401: 'No JWT token provided or token is invalid',
32
+ 403: 'API key is invalid or any other condition is hindering the login', // Unclear if this is fatal or not
33
+ };
34
+ const FatalErrors = {
35
+ 400: "Invalid parameters passed to Bank Frick's API",
36
+ 423: "Authorization is valid, but the user's account is locked",
37
+ };
38
+ /**
39
+ * RestTransport implementation for Bank Frick, which has unusually complex requirements for an EA
40
+ * The RestTransport is generally built to make a single request and return a single response.
41
+ * This transport instead is used to fetch and process pages of data, and also requires a JWT to run
42
+ *
43
+ * This transport does all the heavy lifting in setup(), which is where the paging happens, and it
44
+ * also has complex retry logic that will attempt to refresh the JWT when certain HTTP errors occur
45
+ */
46
+ class BankFrickAccountsTransport {
47
+ async initialize(dependencies) {
48
+ this.cache = dependencies.cache;
49
+ }
50
+ async hasBeenSetUp() {
51
+ return false; // Return false since we aren't coalescing requests
52
+ }
53
+ /**
54
+ * Creates an AxiosRequestConfig object for fetching a page of accounts from the Bank Frick API
55
+ */
56
+ prepareRequest(firstPosition, inputParams, config) {
57
+ const { API_ENDPOINT, BASE_URL, PAGE_SIZE } = config;
58
+ return {
59
+ baseURL: API_ENDPOINT + BASE_URL,
60
+ url: 'accounts',
61
+ method: 'GET',
62
+ params: {
63
+ firstPosition,
64
+ maxResults: PAGE_SIZE,
65
+ },
66
+ headers: {
67
+ Authorization: `Bearer ${this.token}`,
68
+ },
69
+ };
70
+ }
71
+ /**
72
+ * Request with retry logic for Bank Frick's API. In addition to standard retry logic, this function
73
+ * compares errors against expected errors from the Bank Frick API, and will throw without retries
74
+ * on a known fatal error, or try to refresh the JWT on a known auth error
75
+ **/
76
+ async makeRequest(axiosRequest, config, signingAlgorithm) {
77
+ let retryNumber = 0;
78
+ let response = await axios_1.default.request(axiosRequest);
79
+ while (response.status !== 200) {
80
+ retryNumber++;
81
+ logger.warn('Encountered error when fetching accounts from Bank Frick:', response.status, response.statusText);
82
+ // Evaluate whether the error was fatal, auth, or transient and whether we've exceeded the max number of retries.
83
+ // Throw on fatal, refresh token on auth error, pass on transient until we've exhausted our retries
84
+ if (FatalErrors[response.status]) {
85
+ throw new error_1.AdapterError({
86
+ statusCode: response.status,
87
+ message: response.statusText,
88
+ });
89
+ }
90
+ else if (AuthErrors[response.status]) {
91
+ // We've encountered a known auth error, so try to refresh the token before making another request
92
+ logger.info('Auth error received from the Bank Frick API, attempting to refresh the token');
93
+ this.token = await (0, util_1.generateJWT)(config, signingAlgorithm);
94
+ }
95
+ else if (retryNumber === config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES) {
96
+ throw new error_1.AdapterError({
97
+ statusCode: 504,
98
+ message: `Bank Frick transport hit the max number of retries (${config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES} retries) and aborted`,
99
+ });
100
+ }
101
+ logger.debug(`Sleeping for ${config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES}ms before retrying`);
102
+ await (0, util_2.sleep)(config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES);
103
+ response = await axios_1.default.request(axiosRequest);
104
+ }
105
+ return response;
106
+ }
107
+ validateInputParams(params) {
108
+ const encounteredIds = {};
109
+ const errors = [];
110
+ const { ibanIDs } = params;
111
+ ibanIDs.forEach((v) => {
112
+ if (!v.match(ibanPattern)) {
113
+ errors.push(`Invalid IBAN: ${v}`);
114
+ }
115
+ encounteredIds[v] += 1;
116
+ if (encounteredIds[v] > 1) {
117
+ errors.push(`The following IBAN appears more than once in the input parameters: ${v}`);
118
+ }
119
+ });
120
+ return errors;
121
+ }
122
+ /**
123
+ * Fetches pages of data from the Bank Frick API, scans for accounts by IBAN, and returns the balance
124
+ * of all found accounts. Returns a 404 if any IBAN isn't found.
125
+ */
126
+ async setup(req, config) {
127
+ const { ibanIDs, signingAlgorithm } = req.requestContext.data;
128
+ const { PAGE_SIZE = 500 } = config;
129
+ logger.debug(`Validating input: ${JSON.stringify(req.requestContext.data)}`);
130
+ // Scan ibanIDs for duplicates and invalid IBANs
131
+ const validationErrors = this.validateInputParams(req.requestContext.data);
132
+ if (validationErrors.length > 0) {
133
+ throw new error_1.AdapterError({
134
+ statusCode: 420,
135
+ message: `Received the following errors when validating inputParameters:\n ${validationErrors.join('\n')}`,
136
+ });
137
+ }
138
+ // Refresh the token if it isn't set
139
+ if (!this.token) {
140
+ this.token = await (0, util_1.generateJWT)(config, signingAlgorithm);
141
+ }
142
+ let sum = 0;
143
+ let position = 0;
144
+ const keys = ibanIDs;
145
+ logger.info("Fetching accounts from Bank Frick's API...");
146
+ while (keys.length > 0) {
147
+ // TODO Fetching and processing pages can be run concurrently
148
+ const axiosRequest = this.prepareRequest(position, req.requestContext.data, config);
149
+ const response = await this.makeRequest(axiosRequest, config, signingAlgorithm);
150
+ logger.debug(`Evaluating accounts from page ${position / PAGE_SIZE}`);
151
+ response.data.accounts.forEach((v) => {
152
+ logger.trace(`Evaluating ${v.account} (iban: ${v.iban}, type: ${v.type})`);
153
+ const index = ibanIDs.indexOf(v.iban);
154
+ if (index > -1) {
155
+ keys.splice(index, 1);
156
+ sum += v.balance;
157
+ logger.trace(`Found account: ${v.account} (iban: ${v.iban}) with balance of ${v.balance}`);
158
+ logger.trace(`Running sum: ${sum}, number of ibans left to find: ${keys.length}/${ibanIDs.length}`);
159
+ }
160
+ });
161
+ if (!response.data.moreResults) {
162
+ logger.debug('No more results, breaking out of account query loop');
163
+ break;
164
+ }
165
+ position += PAGE_SIZE || 0;
166
+ }
167
+ // 404 if one or more accounts were not found
168
+ if (keys.length > 0) {
169
+ logger.error(`Could not find all accounts, returning 404: ${keys.join(', ')}`);
170
+ const res = {
171
+ data: 0,
172
+ statusCode: 404,
173
+ result: 0,
174
+ };
175
+ await this.cache.set(req.requestContext.cacheKey, res, config.CACHE_MAX_AGE);
176
+ }
177
+ logger.debug('Was able to find all accounts, returning balance across all accounts: ', sum);
178
+ const res = {
179
+ data: sum,
180
+ statusCode: 200,
181
+ result: sum,
182
+ };
183
+ await this.cache.set(req.requestContext.cacheKey, res, config.CACHE_MAX_AGE);
184
+ return res;
185
+ }
186
+ }
187
+ exports.BankFrickAccountsTransport = BankFrickAccountsTransport;
188
+ exports.accountsRestEndpoint = new adapter_1.AdapterEndpoint({
189
+ name: 'accounts',
190
+ transport: new BankFrickAccountsTransport(),
191
+ inputParameters,
192
+ });
@@ -0,0 +1,54 @@
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.customSettings = exports.signingAlgorithms = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const util_1 = require("../../../util");
9
+ const logger = (0, util_1.makeLogger)('BankFrickConfig');
10
+ // Used for enum options and validation
11
+ exports.signingAlgorithms = ['rsa-sha256', 'rsa-sha384', 'rsa-sha512'];
12
+ const MAX_PAGE_SIZE = 500;
13
+ exports.customSettings = {
14
+ PAGE_SIZE: {
15
+ description: 'The number of accounts to fetch per call to /accounts. Must be >= 1 and <= 500.',
16
+ type: 'number',
17
+ required: false,
18
+ default: MAX_PAGE_SIZE,
19
+ validate: (value) => {
20
+ if (!value) {
21
+ return '';
22
+ }
23
+ else if (value < 1) {
24
+ return `PAGE_SIZE must be at least >= 1, was ${value}`;
25
+ }
26
+ else if (value > MAX_PAGE_SIZE) {
27
+ return `PAGE_SIZE must be <= 500, was ${value}`;
28
+ }
29
+ },
30
+ },
31
+ PRIVATE_KEY: {
32
+ description: '',
33
+ type: 'string',
34
+ required: true,
35
+ validate: (value) => {
36
+ const failedAlgos = [];
37
+ for (const algorithm of exports.signingAlgorithms) {
38
+ const body = { example: 123 };
39
+ try {
40
+ crypto_1.default.sign(algorithm, Buffer.from(JSON.stringify(body)), value);
41
+ logger.trace("Successfully tested PRIVATE_KEY by signing with algorithm '%s'", algorithm);
42
+ }
43
+ catch {
44
+ logger.trace("PRIVATE_KEY failed to sign message with algorithm '%s'", algorithm);
45
+ failedAlgos.push(algorithm);
46
+ }
47
+ }
48
+ if (failedAlgos.length > 0) {
49
+ return `Failed to sign a dummy body using $PRIVATE_KEY with the following algorithms ${failedAlgos.join(',')}`;
50
+ }
51
+ logger.debug('$PRIVATE_KEY successfully signed a dummy body with all supported algorithms');
52
+ },
53
+ },
54
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adapter = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const accounts_1 = require("./accounts");
6
+ const config_1 = require("./config");
7
+ exports.adapter = new adapter_1.Adapter({
8
+ name: 'bank-frick',
9
+ defaultEndpoint: 'accounts',
10
+ endpoints: [accounts_1.accountsRestEndpoint],
11
+ customSettings: config_1.customSettings,
12
+ envDefaultOverrides: {
13
+ API_ENDPOINT: 'https://olbsandbox.bankfrick.li/webapi/v2',
14
+ },
15
+ });
@@ -0,0 +1,39 @@
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.generateJWT = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const util_1 = require("../../util");
10
+ const logger = (0, util_1.makeLogger)('BankFrickUtil');
11
+ // Used by all endpoints requiring authentication
12
+ const generateJWT = async (config, signingAlgorithm = 'rsa-sha512') => {
13
+ logger.info("Generating a new JWT because we don't have one in config.token");
14
+ const { API_KEY, PRIVATE_KEY, API_ENDPOINT } = config;
15
+ // All of these are required, so validation should have failed prior to this line
16
+ if (!API_KEY || !PRIVATE_KEY) {
17
+ throw new Error('API_KEY, PRIVATE_KEY, and PASSWORD all must be defined to get a new token\n' +
18
+ 'Received: \n' +
19
+ `API_KEY: ${API_KEY}\n` +
20
+ `PRIVATE_KEY: ${PRIVATE_KEY}`);
21
+ }
22
+ const data = {
23
+ key: API_KEY,
24
+ };
25
+ const signature = crypto_1.default.sign(signingAlgorithm, Buffer.from(JSON.stringify(data)), PRIVATE_KEY);
26
+ const options = {
27
+ method: 'POST',
28
+ baseURL: API_ENDPOINT,
29
+ url: `authorize`,
30
+ headers: {
31
+ Signature: signature.toString('base64'),
32
+ algorithm: signingAlgorithm,
33
+ },
34
+ data,
35
+ };
36
+ const response = await axios_1.default.request(options);
37
+ return response.data.token;
38
+ };
39
+ exports.generateJWT = generateJWT;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.batchEndpoint = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const batch_warming_1 = require("../../transports/batch-warming");
6
+ const DEFAULT_URL = 'https://pro-api.coingecko.com/api/v3';
7
+ const inputParameters = {
8
+ coinid: {
9
+ description: 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
10
+ required: false,
11
+ },
12
+ base: {
13
+ aliases: ['from', 'coin'],
14
+ description: 'The symbol or array of symbols of the currency to query',
15
+ required: true,
16
+ },
17
+ quote: {
18
+ aliases: ['to', 'market'],
19
+ description: 'The symbol of the currency to convert to',
20
+ required: true,
21
+ },
22
+ };
23
+ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
24
+ prepareRequest: (params, context) => {
25
+ return {
26
+ baseURL: DEFAULT_URL,
27
+ url: '/simple/price',
28
+ method: 'GET',
29
+ params: {
30
+ ids: [...new Set(params.map((p) => p.base))].join(','),
31
+ vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
32
+ x_cg_pro_api_key: context.adapterConfig.API_KEY,
33
+ },
34
+ };
35
+ },
36
+ parseResponse: (res) => {
37
+ const entries = [];
38
+ for (const [base, entry] of Object.entries(res.data)) {
39
+ for (const [quote, price] of Object.entries(entry)) {
40
+ entries.push({
41
+ params: { base, quote },
42
+ value: price,
43
+ });
44
+ }
45
+ }
46
+ return entries;
47
+ },
48
+ });
49
+ exports.batchEndpoint = new adapter_1.AdapterEndpoint({
50
+ name: 'batch',
51
+ transport: batchEndpointTransport,
52
+ inputParameters,
53
+ });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adapter = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const batch_warming_1 = require("./batch-warming");
6
+ const rest_1 = require("./rest");
7
+ exports.adapter = new adapter_1.Adapter({
8
+ name: 'coingecko',
9
+ defaultEndpoint: 'batch',
10
+ endpoints: [rest_1.restEndpoint, batch_warming_1.batchEndpoint],
11
+ });
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restEndpoint = void 0;
4
+ const adapter_1 = require("../../adapter");
5
+ const transports_1 = require("../../transports");
6
+ const DEFAULT_URL = 'https://api.coingecko.com/api/v3';
7
+ const inputParameters = {
8
+ coinid: {
9
+ description: 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
10
+ required: false,
11
+ },
12
+ base: {
13
+ aliases: ['from', 'coin'],
14
+ description: 'The symbol or array of symbols of the currency to query',
15
+ required: true,
16
+ },
17
+ quote: {
18
+ aliases: ['to', 'market'],
19
+ description: 'The symbol of the currency to convert to',
20
+ required: true,
21
+ },
22
+ };
23
+ const restEndpointTransport = new transports_1.RestTransport({
24
+ prepareRequest: (req) => {
25
+ return {
26
+ baseURL: DEFAULT_URL,
27
+ url: '/simple/price',
28
+ method: 'GET',
29
+ params: {
30
+ ids: req.requestContext.data.base,
31
+ vs_currencies: req.requestContext.data.quote,
32
+ },
33
+ };
34
+ },
35
+ parseResponse: (req, res) => {
36
+ return {
37
+ data: res.data,
38
+ statusCode: 200,
39
+ result: res.data[req.requestContext.data.base]?.[req.requestContext.data.quote],
40
+ };
41
+ },
42
+ options: {
43
+ coalescing: true,
44
+ },
45
+ });
46
+ exports.restEndpoint = new adapter_1.AdapterEndpoint({
47
+ name: 'rest',
48
+ aliases: ['qwe'],
49
+ transport: restEndpointTransport,
50
+ inputParameters,
51
+ });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customSettings = exports.PRO_API_ENDPOINT = exports.DEFAULT_API_ENDPOINT = exports.DEFAULT_ENDPOINT = exports.NAME = void 0;
4
+ exports.NAME = 'COINGECKO';
5
+ exports.DEFAULT_ENDPOINT = 'crypto';
6
+ exports.DEFAULT_API_ENDPOINT = 'https://api.coingecko.com/api/v3';
7
+ exports.PRO_API_ENDPOINT = 'https://pro-api.coingecko.com/api/v3';
8
+ exports.customSettings = {
9
+ API_KEY: {
10
+ description: 'API key for the CoinGecko API',
11
+ type: 'string',
12
+ },
13
+ };