@chainlink/external-adapter-framework 0.4.0 → 0.5.1

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 (213) hide show
  1. package/adapter/basic.d.ts +90 -0
  2. package/adapter/basic.js +325 -0
  3. package/adapter/basic.js.map +1 -0
  4. package/adapter/endpoint.d.ts +17 -0
  5. package/adapter/endpoint.js +20 -0
  6. package/adapter/endpoint.js.map +1 -0
  7. package/adapter/index.d.ts +4 -0
  8. package/adapter/index.js +21 -0
  9. package/adapter/index.js.map +1 -0
  10. package/adapter/price.d.ts +77 -0
  11. package/adapter/price.js +88 -0
  12. package/adapter/price.js.map +1 -0
  13. package/adapter/types.d.ts +124 -0
  14. package/adapter/types.js +3 -0
  15. package/adapter/types.js.map +1 -0
  16. package/background-executor.d.ts +9 -0
  17. package/background-executor.js +97 -0
  18. package/background-executor.js.map +1 -0
  19. package/cache/factory.d.ts +6 -0
  20. package/cache/factory.js +24 -0
  21. package/cache/factory.js.map +1 -0
  22. package/cache/index.d.ts +87 -0
  23. package/cache/index.js +133 -0
  24. package/cache/index.js.map +1 -0
  25. package/cache/local.d.ts +23 -0
  26. package/cache/local.js +84 -0
  27. package/cache/local.js.map +1 -0
  28. package/cache/metrics.d.ts +27 -0
  29. package/cache/metrics.js +121 -0
  30. package/cache/metrics.js.map +1 -0
  31. package/cache/redis.d.ts +16 -0
  32. package/cache/redis.js +101 -0
  33. package/cache/redis.js.map +1 -0
  34. package/config/index.d.ts +298 -0
  35. package/config/index.js +359 -0
  36. package/config/index.js.map +1 -0
  37. package/config/provider-limits.d.ts +27 -0
  38. package/config/provider-limits.js +75 -0
  39. package/config/provider-limits.js.map +1 -0
  40. package/examples/bank-frick/accounts.d.ts +45 -0
  41. package/examples/bank-frick/accounts.js +203 -0
  42. package/examples/bank-frick/accounts.js.map +1 -0
  43. package/examples/bank-frick/config/index.d.ts +17 -0
  44. package/examples/bank-frick/config/index.js +55 -0
  45. package/examples/bank-frick/config/index.js.map +1 -0
  46. package/examples/bank-frick/index.d.ts +2 -0
  47. package/examples/bank-frick/index.js +16 -0
  48. package/examples/bank-frick/index.js.map +1 -0
  49. package/examples/bank-frick/util.d.ts +4 -0
  50. package/examples/bank-frick/util.js +40 -0
  51. package/examples/bank-frick/util.js.map +1 -0
  52. package/examples/coingecko/src/config/index.d.ts +2 -0
  53. package/examples/coingecko/src/config/index.js +6 -0
  54. package/examples/coingecko/src/config/index.js.map +1 -0
  55. package/examples/coingecko/src/config/overrides.json +10825 -0
  56. package/examples/coingecko/src/crypto-utils.d.ts +62 -0
  57. package/examples/coingecko/src/crypto-utils.js +60 -0
  58. package/examples/coingecko/src/crypto-utils.js.map +1 -0
  59. package/examples/coingecko/src/endpoint/coins.d.ts +26 -0
  60. package/examples/coingecko/src/endpoint/coins.js +37 -0
  61. package/examples/coingecko/src/endpoint/coins.js.map +1 -0
  62. package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +3 -0
  63. package/examples/coingecko/src/endpoint/crypto-marketcap.js +30 -0
  64. package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -0
  65. package/examples/coingecko/src/endpoint/crypto-volume.d.ts +3 -0
  66. package/examples/coingecko/src/endpoint/crypto-volume.js +30 -0
  67. package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -0
  68. package/examples/coingecko/src/endpoint/crypto.d.ts +3 -0
  69. package/examples/coingecko/src/endpoint/crypto.js +28 -0
  70. package/examples/coingecko/src/endpoint/crypto.js.map +1 -0
  71. package/examples/coingecko/src/endpoint/dominance.d.ts +3 -0
  72. package/examples/coingecko/src/endpoint/dominance.js +28 -0
  73. package/examples/coingecko/src/endpoint/dominance.js.map +1 -0
  74. package/examples/coingecko/src/endpoint/global-marketcap.d.ts +3 -0
  75. package/examples/coingecko/src/endpoint/global-marketcap.js +28 -0
  76. package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -0
  77. package/examples/coingecko/src/endpoint/index.d.ts +6 -0
  78. package/examples/coingecko/src/endpoint/index.js +16 -0
  79. package/examples/coingecko/src/endpoint/index.js.map +1 -0
  80. package/examples/coingecko/src/global-utils.d.ts +42 -0
  81. package/examples/coingecko/src/global-utils.js +47 -0
  82. package/examples/coingecko/src/global-utils.js.map +1 -0
  83. package/examples/coingecko/src/index.d.ts +4 -0
  84. package/examples/coingecko/src/index.js +19 -0
  85. package/examples/coingecko/src/index.js.map +1 -0
  86. package/examples/coingecko-old/batch-warming.d.ts +7 -0
  87. package/examples/coingecko-old/batch-warming.js +54 -0
  88. package/examples/coingecko-old/batch-warming.js.map +1 -0
  89. package/examples/coingecko-old/index.d.ts +2 -0
  90. package/examples/coingecko-old/index.js +12 -0
  91. package/examples/coingecko-old/index.js.map +1 -0
  92. package/examples/coingecko-old/rest.d.ts +12 -0
  93. package/examples/coingecko-old/rest.js +55 -0
  94. package/examples/coingecko-old/rest.js.map +1 -0
  95. package/examples/cryptocompare/src/config/index.d.ts +2 -0
  96. package/examples/cryptocompare/src/config/index.js +6 -0
  97. package/examples/cryptocompare/src/config/index.js.map +1 -0
  98. package/examples/cryptocompare/src/endpoints/crypto.d.ts +40 -0
  99. package/examples/cryptocompare/src/endpoints/crypto.js +54 -0
  100. package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -0
  101. package/examples/cryptocompare/src/endpoints/index.d.ts +1 -0
  102. package/examples/cryptocompare/src/endpoints/index.js +6 -0
  103. package/examples/cryptocompare/src/endpoints/index.js.map +1 -0
  104. package/examples/cryptocompare/src/index.d.ts +4 -0
  105. package/examples/cryptocompare/src/index.js +14 -0
  106. package/examples/cryptocompare/src/index.js.map +1 -0
  107. package/examples/genesis/config/index.d.ts +7 -0
  108. package/examples/genesis/config/index.js +11 -0
  109. package/examples/genesis/config/index.js.map +1 -0
  110. package/examples/genesis/index.d.ts +2 -0
  111. package/examples/genesis/index.js +13 -0
  112. package/examples/genesis/index.js.map +1 -0
  113. package/examples/genesis/sseStream.d.ts +27 -0
  114. package/examples/genesis/sseStream.js +149 -0
  115. package/examples/genesis/sseStream.js.map +1 -0
  116. package/examples/ncfx/config/index.d.ts +12 -0
  117. package/examples/ncfx/config/index.js +16 -0
  118. package/examples/ncfx/config/index.js.map +1 -0
  119. package/examples/ncfx/index.d.ts +2 -0
  120. package/examples/ncfx/index.js +12 -0
  121. package/examples/ncfx/index.js.map +1 -0
  122. package/examples/ncfx/websocket.d.ts +37 -0
  123. package/examples/ncfx/websocket.js +74 -0
  124. package/examples/ncfx/websocket.js.map +1 -0
  125. package/index.d.ts +17 -0
  126. package/index.js +174 -0
  127. package/index.js.map +1 -0
  128. package/metrics/constants.d.ts +16 -0
  129. package/metrics/constants.js +26 -0
  130. package/metrics/constants.js.map +1 -0
  131. package/metrics/index.d.ts +19 -0
  132. package/metrics/index.js +139 -0
  133. package/metrics/index.js.map +1 -0
  134. package/metrics/util.d.ts +7 -0
  135. package/metrics/util.js +10 -0
  136. package/metrics/util.js.map +1 -0
  137. package/package.json +50 -42
  138. package/rate-limiting/background/fixed-frequency.d.ts +10 -0
  139. package/rate-limiting/background/fixed-frequency.js +36 -0
  140. package/rate-limiting/background/fixed-frequency.js.map +1 -0
  141. package/rate-limiting/index.d.ts +56 -0
  142. package/rate-limiting/index.js +86 -0
  143. package/rate-limiting/index.js.map +1 -0
  144. package/rate-limiting/metrics.d.ts +3 -0
  145. package/rate-limiting/metrics.js +45 -0
  146. package/rate-limiting/metrics.js.map +1 -0
  147. package/rate-limiting/request/simple-counting.d.ts +20 -0
  148. package/rate-limiting/request/simple-counting.js +63 -0
  149. package/rate-limiting/request/simple-counting.js.map +1 -0
  150. package/transports/batch-warming.d.ts +53 -0
  151. package/transports/batch-warming.js +136 -0
  152. package/transports/batch-warming.js.map +1 -0
  153. package/transports/index.d.ts +108 -0
  154. package/transports/index.js +56 -0
  155. package/transports/index.js.map +1 -0
  156. package/transports/inference-test.d.ts +0 -0
  157. package/transports/inference-test.js +202 -0
  158. package/transports/inference-test.js.map +1 -0
  159. package/transports/metrics.d.ts +25 -0
  160. package/transports/metrics.js +122 -0
  161. package/transports/metrics.js.map +1 -0
  162. package/transports/rest.d.ts +68 -0
  163. package/transports/rest.js +131 -0
  164. package/transports/rest.js.map +1 -0
  165. package/transports/routing.d.ts +21 -0
  166. package/transports/routing.js +50 -0
  167. package/transports/routing.js.map +1 -0
  168. package/transports/sse.d.ts +61 -0
  169. package/transports/sse.js +97 -0
  170. package/transports/sse.js.map +1 -0
  171. package/transports/util.d.ts +9 -0
  172. package/transports/util.js +87 -0
  173. package/transports/util.js.map +1 -0
  174. package/transports/websocket.d.ts +95 -0
  175. package/transports/websocket.js +164 -0
  176. package/transports/websocket.js.map +1 -0
  177. package/util/censor/censor-list.d.ts +9 -0
  178. package/util/censor/censor-list.js +13 -0
  179. package/util/censor/censor-list.js.map +1 -0
  180. package/util/index.d.ts +13 -0
  181. package/util/index.js +38 -0
  182. package/util/index.js.map +1 -0
  183. package/util/logger.d.ts +49 -0
  184. package/util/logger.js +123 -0
  185. package/util/logger.js.map +1 -0
  186. package/util/request.d.ts +138 -0
  187. package/util/request.js +3 -0
  188. package/util/request.js.map +1 -0
  189. package/util/subscription-set/expiring-sorted-set.d.ts +21 -0
  190. package/util/subscription-set/expiring-sorted-set.js +36 -0
  191. package/util/subscription-set/expiring-sorted-set.js.map +1 -0
  192. package/util/subscription-set/redis-sorted-set.d.ts +9 -0
  193. package/util/subscription-set/redis-sorted-set.js +29 -0
  194. package/util/subscription-set/redis-sorted-set.js.map +1 -0
  195. package/util/subscription-set/subscription-set.d.ts +19 -0
  196. package/util/subscription-set/subscription-set.js +28 -0
  197. package/util/subscription-set/subscription-set.js.map +1 -0
  198. package/util/test-payload-loader.d.ts +26 -0
  199. package/util/test-payload-loader.js +85 -0
  200. package/util/test-payload-loader.js.map +1 -0
  201. package/validation/error.d.ts +48 -0
  202. package/validation/error.js +78 -0
  203. package/validation/error.js.map +1 -0
  204. package/validation/index.d.ts +5 -0
  205. package/validation/index.js +102 -0
  206. package/validation/index.js.map +1 -0
  207. package/validation/input-params.d.ts +14 -0
  208. package/validation/input-params.js +3 -0
  209. package/validation/input-params.js.map +1 -0
  210. package/validation/input-validator.d.ts +16 -0
  211. package/validation/input-validator.js +123 -0
  212. package/validation/input-validator.js.map +1 -0
  213. package/README.md +0 -102
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterCustomError = exports.AdapterConnectionError = exports.AdapterDataProviderError = exports.AdapterTimeoutError = exports.AdapterRateLimitError = exports.AdapterInputError = exports.AdapterError = void 0;
4
+ const constants_1 = require("../metrics/constants");
5
+ class AdapterError extends Error {
6
+ constructor({ status = 'errored', statusCode = 500, name = 'AdapterError', message = 'There was an unexpected error in the adapter.', cause, url, errorResponse, feedID, providerStatusCode, metricsLabel = constants_1.HttpRequestType.ADAPTER_ERROR, }) {
7
+ super(message);
8
+ this.status = status;
9
+ this.statusCode = statusCode;
10
+ this.name = name;
11
+ this.message = message;
12
+ this.cause = cause;
13
+ if (url) {
14
+ this.url = url;
15
+ }
16
+ if (feedID) {
17
+ this.feedID = feedID;
18
+ }
19
+ this.errorResponse = errorResponse;
20
+ this.providerStatusCode = providerStatusCode;
21
+ this.metricsLabel = metricsLabel;
22
+ }
23
+ toJSONResponse() {
24
+ const showDebugInfo = process.env['NODE_ENV'] === 'development' || process.env['DEBUG'] === 'true';
25
+ const errorBasic = {
26
+ name: this.name,
27
+ message: this.message,
28
+ url: this.url,
29
+ errorResponse: this.errorResponse,
30
+ feedID: this.feedID,
31
+ };
32
+ const errorFull = { ...errorBasic, stack: this.stack, cause: this.cause };
33
+ return {
34
+ status: this.status,
35
+ statusCode: this.statusCode,
36
+ providerStatusCode: this.providerStatusCode,
37
+ error: showDebugInfo ? errorFull : errorBasic,
38
+ };
39
+ }
40
+ }
41
+ exports.AdapterError = AdapterError;
42
+ class AdapterInputError extends AdapterError {
43
+ constructor(input) {
44
+ super({ ...input, metricsLabel: constants_1.HttpRequestType.INPUT_ERROR });
45
+ }
46
+ }
47
+ exports.AdapterInputError = AdapterInputError;
48
+ class AdapterRateLimitError extends AdapterError {
49
+ constructor(input) {
50
+ super({ ...input, metricsLabel: constants_1.HttpRequestType.RATE_LIMIT_ERROR });
51
+ }
52
+ }
53
+ exports.AdapterRateLimitError = AdapterRateLimitError;
54
+ class AdapterTimeoutError extends AdapterError {
55
+ constructor(input) {
56
+ super({ ...input, metricsLabel: constants_1.HttpRequestType.TIMEOUT_ERROR });
57
+ }
58
+ }
59
+ exports.AdapterTimeoutError = AdapterTimeoutError;
60
+ class AdapterDataProviderError extends AdapterError {
61
+ constructor(input) {
62
+ super({ ...input, metricsLabel: constants_1.HttpRequestType.DP_ERROR });
63
+ }
64
+ }
65
+ exports.AdapterDataProviderError = AdapterDataProviderError;
66
+ class AdapterConnectionError extends AdapterError {
67
+ constructor(input) {
68
+ super({ ...input, metricsLabel: constants_1.HttpRequestType.CONNECTION_ERROR });
69
+ }
70
+ }
71
+ exports.AdapterConnectionError = AdapterConnectionError;
72
+ class AdapterCustomError extends AdapterError {
73
+ constructor(input) {
74
+ super({ ...input, metricsLabel: constants_1.HttpRequestType.CUSTOM_ERROR });
75
+ }
76
+ }
77
+ exports.AdapterCustomError = AdapterCustomError;
78
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/validation/error.ts"],"names":[],"mappings":";;;AAAA,oDAAsD;AAkBtD,MAAa,YAAa,SAAQ,KAAK;IAarC,YAAY,EACV,MAAM,GAAG,SAAS,EAClB,UAAU,GAAG,GAAG,EAChB,IAAI,GAAG,cAAc,EACrB,OAAO,GAAG,+CAA+C,EACzD,KAAK,EACL,GAAG,EACH,aAAa,EACb,MAAM,EACN,kBAAkB,EAClB,YAAY,GAAG,2BAAe,CAAC,aAAa,GACtB;QACtB,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI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CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,WAAW,EAAE,CAAC,CAAA;IAChE,CAAC;CACF;AAJD,8CAIC;AACD,MAAa,qBAAsB,SAAQ,YAAY;IACrD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACrE,CAAC;CACF;AAJD,sDAIC;AACD,MAAa,mBAAoB,SAAQ,YAAY;IACnD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,aAAa,EAAE,CAAC,CAAA;IAClE,CAAC;CACF;AAJD,kDAIC;AACD,MAAa,wBAAyB,SAAQ,YAAY;IACxD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC7D,CAAC;CACF;AAJD,4DAIC;AACD,MAAa,sBAAuB,SAAQ,YAAY;IACtD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACrE,CAAC;CACF;AAJD,wDAIC;AACD,MAAa,kBAAmB,SAAQ,YAAY;IAClD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,YAAY,EAAE,CAAC,CAAA;IACjE,CAAC;CACF;AAJD,gDAIC"}
@@ -0,0 +1,5 @@
1
+ import { FastifyReply, FastifyRequest } from 'fastify';
2
+ import { AdapterMiddlewareBuilder } from '../util/request';
3
+ export { InputParameters } from './input-params';
4
+ export declare const validatorMiddleware: AdapterMiddlewareBuilder;
5
+ export declare const errorCatchingMiddleware: (err: Error, req: FastifyRequest, res: FastifyReply) => void;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorCatchingMiddleware = exports.validatorMiddleware = void 0;
4
+ const cache_1 = require("../cache");
5
+ const util_1 = require("../metrics/util");
6
+ const util_2 = require("../util");
7
+ const error_1 = require("./error");
8
+ const errorCatcherLogger = (0, util_2.makeLogger)('ErrorCatchingMiddleware');
9
+ const validatorMiddleware = (adapter) => (req, reply, done) => {
10
+ if (req.headers['content-type'] !== 'application/json') {
11
+ throw new error_1.AdapterInputError({
12
+ message: 'Content type not "application/json", returning 400',
13
+ statusCode: 400,
14
+ });
15
+ }
16
+ if (!req.body) {
17
+ throw new error_1.AdapterInputError({
18
+ message: 'Body not present in adapter request, returning 400',
19
+ statusCode: 400,
20
+ });
21
+ }
22
+ // We can restrict usage of the raw request body everywhere in the framework
23
+ // by setting its type to EmptyBody, and we cast here (and only here)
24
+ const requestBody = req.body;
25
+ // Make endpoints case insensitive
26
+ const endpointParam = requestBody.endpoint?.toLowerCase() ||
27
+ requestBody.data?.endpoint?.toLowerCase() ||
28
+ adapter.defaultEndpoint;
29
+ if (!endpointParam) {
30
+ throw new error_1.AdapterInputError({
31
+ message: `Request body does not specify an endpoint, and there is no default endpoint configured for this adapter.`,
32
+ statusCode: 400,
33
+ });
34
+ }
35
+ const endpoint = adapter.endpointsMap[endpointParam];
36
+ if (!endpoint) {
37
+ throw new error_1.AdapterInputError({
38
+ message: `Adapter does not have a "${endpointParam}" endpoint.`,
39
+ statusCode: 404,
40
+ });
41
+ }
42
+ const validatedData = endpoint.validator.validateInput(req.body?.['data']);
43
+ req.requestContext = {
44
+ cacheKey: '',
45
+ data: validatedData,
46
+ endpointName: endpoint.name,
47
+ };
48
+ if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
49
+ // Add metrics meta which includes feedId to the request
50
+ // Perform prior to overrides to maintain consistent Feed IDs across adapters
51
+ const metrics = (0, util_1.getMetricsMeta)({
52
+ adapterEndpoint: endpoint,
53
+ adapterConfig: adapter.config,
54
+ }, validatedData);
55
+ req.requestContext = { ...req.requestContext, meta: { metrics } };
56
+ }
57
+ // Run any request transforms that might have been defined in the adapter.
58
+ // This is the last time modifications are supposed to happen to the request.
59
+ adapter.runRequestTransforms(req);
60
+ // Now that all the transformations have been applied, all that's left is calculating the cache key
61
+ if (endpoint.cacheKeyGenerator) {
62
+ let cacheKey;
63
+ cacheKey = endpoint.cacheKeyGenerator(req.requestContext.data);
64
+ if (cacheKey.length > adapter.config.MAX_COMMON_KEY_SIZE) {
65
+ errorCatcherLogger.warn(`Generated custom cache key for adapter request is bigger than the MAX_COMMON_KEY_SIZE and will be truncated`);
66
+ cacheKey = cacheKey.slice(0, adapter.config.MAX_COMMON_KEY_SIZE);
67
+ }
68
+ req.requestContext.cacheKey = cacheKey;
69
+ }
70
+ else {
71
+ req.requestContext.cacheKey = (0, cache_1.calculateCacheKey)({
72
+ adapterEndpoint: endpoint,
73
+ adapterConfig: adapter.config,
74
+ }, req.requestContext.data);
75
+ }
76
+ done();
77
+ };
78
+ exports.validatorMiddleware = validatorMiddleware;
79
+ const errorCatchingMiddleware = (err, req, res) => {
80
+ // Add adapter or generic error to request meta for metrics use
81
+ // There's a chance we have no request context if there was an error during input validation
82
+ if (req.requestContext) {
83
+ req.requestContext.meta = { ...req.requestContext?.meta, error: err };
84
+ }
85
+ // Add the request context to the error so that we can check things like incoming params, endpoint, etc
86
+ const errorWithContext = {
87
+ requestContext: req.requestContext,
88
+ ...err,
89
+ };
90
+ if (err instanceof error_1.AdapterError) {
91
+ // We want to log these as warn, because although they are to be expected, NOPs should
92
+ // Only use "correct" job specs and therefore not hit adapters with invalid requests.
93
+ errorCatcherLogger.warn(errorWithContext);
94
+ res.status(err.statusCode).send(err.toJSONResponse());
95
+ }
96
+ else {
97
+ errorCatcherLogger.error(errorWithContext);
98
+ res.status(500).send(err.message || 'There was an unexpected error in the adapter.');
99
+ }
100
+ };
101
+ exports.errorCatchingMiddleware = errorCatchingMiddleware;
102
+ //# s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AAG,IAAA,yBAAiB,EAC7C;YACE,eAAe,EAAE,QAAQ;YACzB,aAAa,EAAE,OAAO,CAAC,MAAM;SAC9B,EACD,GAAG,CAAC,cAAc,CAAC,IAAI,CACxB,CAAA;KACF;IAED,IAAI,EAAE,CAAA;AACR,CAAC,CAAA;AAxFU,QAAA,mBAAmB,uBAwF7B;AAEI,MAAM,uBAAuB,GAAG,CAAC,GAAU,EAAE,GAAmB,EAAE,GAAiB,EAAE,EAAE;IAC5F,+DAA+D;IAC/D,4FAA4F;IAC5F,IAAI,GAAG,CAAC,cAAc,EAAE;QACtB,GAAG,CAAC,cAAc,CAAC,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;KACtE;IAED,uGAAuG;IACvG,MAAM,gBAAgB,GAAG;QACvB,cAAc,EAAE,GAAG,CAAC,cAAc;QAClC,GAAG,GAAG;KACP,CAAA;IAED,IAAI,GAAG,YAAY,oBAAY,EAAE;QAC/B,sFAAsF;QACtF,qFAAqF;QACrF,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QACzC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,CAAA;KACtD;SAAM;QACL,kBAAkB,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;QAC1C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,+CAA+C,CAAC,CAAA;KACrF;AACH,CAAC,CAAA;AAtBY,QAAA,uBAAuB,2BAsBnC"}
@@ -0,0 +1,14 @@
1
+ export declare type Override = Map<string, Map<string, string>>;
2
+ export declare type InputParameter = {
3
+ aliases?: readonly string[];
4
+ description?: string;
5
+ type?: 'bigint' | 'boolean' | 'array' | 'number' | 'object' | 'string';
6
+ required?: boolean;
7
+ options?: unknown[];
8
+ default?: unknown;
9
+ dependsOn?: readonly string[];
10
+ exclusive?: readonly string[];
11
+ };
12
+ export declare type InputParameters = {
13
+ [name: string]: InputParameter;
14
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=input-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-params.js","sourceRoot":"","sources":["../../../src/validation/input-params.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import { InputParameters } from './input-params';
2
+ export declare type NormalizedInput = Record<string, unknown>;
3
+ export declare class InputValidator {
4
+ private readonly inputConfig;
5
+ private aliases;
6
+ constructor(inputConfig: InputParameters);
7
+ validateInput(input: Record<string, unknown>): NormalizedInput;
8
+ private initializeInputs;
9
+ private validateInputParamsSchema;
10
+ private validateRequiredConfig;
11
+ private validateOptions;
12
+ private validateTypes;
13
+ private validateDeps;
14
+ private getUsedKey;
15
+ private throwInvalid;
16
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InputValidator = void 0;
4
+ const error_1 = require("./error");
5
+ const util_1 = require("../util");
6
+ class InputValidator {
7
+ constructor(inputConfig) {
8
+ this.inputConfig = inputConfig;
9
+ this.aliases = {};
10
+ this.getUsedKey = (allKeys, input) => allKeys.find((k) => input && !(0, util_1.isEmpty)(input[k])) || '';
11
+ this.throwInvalid = (message) => {
12
+ throw new error_1.AdapterInputError({ statusCode: 400, message });
13
+ };
14
+ this.inputConfig = { ...inputConfig };
15
+ this.validateInputParamsSchema();
16
+ }
17
+ validateInput(input) {
18
+ const normalized = this.initializeInputs(input);
19
+ for (const configKey in this.inputConfig) {
20
+ this.validateRequiredConfig(configKey, normalized);
21
+ if (!(0, util_1.isEmpty)(normalized[configKey])) {
22
+ this.validateTypes(configKey, normalized);
23
+ this.validateOptions(configKey, normalized);
24
+ this.validateDeps(configKey, normalized);
25
+ }
26
+ }
27
+ return normalized;
28
+ }
29
+ initializeInputs(input) {
30
+ const normalized = {};
31
+ for (const paramName in this.inputConfig) {
32
+ const usedKey = this.getUsedKey(this.aliases[paramName], input);
33
+ normalized[paramName] =
34
+ !usedKey || (0, util_1.isEmpty)(input[usedKey]) ? this.inputConfig[paramName].default : input[usedKey];
35
+ }
36
+ return normalized;
37
+ }
38
+ validateInputParamsSchema() {
39
+ for (const configKey in this.inputConfig) {
40
+ const config = this.inputConfig[configKey];
41
+ if (config.required && config.default) {
42
+ throw new error_1.AdapterInputError({
43
+ statusCode: 400,
44
+ message: `${configKey} can't be required and have default value`,
45
+ });
46
+ }
47
+ const aliases = [configKey, ...(config.aliases ?? [])];
48
+ if (aliases.length !== new Set(aliases).size) {
49
+ throw new error_1.AdapterInputError({
50
+ statusCode: 400,
51
+ message: `Duplicate aliases`,
52
+ });
53
+ }
54
+ this.aliases[configKey] = aliases;
55
+ const deps = [...(config.dependsOn ?? []), ...(config.exclusive ?? [])];
56
+ if (!deps || !deps.length) {
57
+ continue;
58
+ }
59
+ deps.forEach((inputDepKey) => {
60
+ if (!this.inputConfig[inputDepKey]) {
61
+ throw new error_1.AdapterInputError({
62
+ statusCode: 400,
63
+ message: `Input dependency/exclusive '${inputDepKey}' is missing in input schema`,
64
+ });
65
+ }
66
+ });
67
+ }
68
+ }
69
+ validateRequiredConfig(configKey, normalized) {
70
+ if (!this.inputConfig[configKey].required) {
71
+ return;
72
+ }
73
+ if ((0, util_1.isEmpty)(normalized[configKey])) {
74
+ this.throwInvalid(`Required parameter ${configKey} must be non-null and non-empty`);
75
+ }
76
+ }
77
+ validateOptions(key, normalized) {
78
+ if (!this.inputConfig[key].options?.length) {
79
+ return;
80
+ }
81
+ if (!this.inputConfig[key].options?.includes(normalized[key])) {
82
+ this.throwInvalid(`${key} parameter must be one of following options: ${this.inputConfig[key].options?.join(',')}`);
83
+ }
84
+ }
85
+ validateTypes(key, normalized) {
86
+ const type = this.inputConfig[key].type;
87
+ if (!type) {
88
+ return;
89
+ }
90
+ if (['array', 'object'].includes(type)) {
91
+ if (type === 'array' &&
92
+ (!Array.isArray(normalized[key]) || normalized[key].length === 0)) {
93
+ this.throwInvalid(`${key} parameter must be a non-empty array`);
94
+ }
95
+ if (type === 'object' &&
96
+ normalized[key] &&
97
+ (Object.getPrototypeOf(normalized[key]) !== Object.prototype ||
98
+ Object.keys(normalized[key]).length === 0)) {
99
+ this.throwInvalid(`${key} parameter must be an object with at least one property`);
100
+ }
101
+ return;
102
+ }
103
+ else if (typeof normalized[key] !== type) {
104
+ this.throwInvalid(`${key} parameter must be of type ${type}`);
105
+ }
106
+ }
107
+ validateDeps(key, normalized) {
108
+ for (const dependency of this.inputConfig[key].dependsOn ?? []) {
109
+ const value = normalized[dependency];
110
+ if ((0, util_1.isEmpty)(value)) {
111
+ this.throwInvalid(`${key} dependency ${dependency} not supplied`);
112
+ }
113
+ }
114
+ for (const exclusive of this.inputConfig[key].exclusive ?? []) {
115
+ const value = normalized[exclusive];
116
+ if (!(0, util_1.isEmpty)(value)) {
117
+ this.throwInvalid(`${key} cannot be supplied concurrently with ${exclusive}`);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ exports.InputValidator = InputValidator;
123
+ //# sourceMappingURL=input-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-validator.js","sourceRoot":"","sources":["../../../src/validation/input-validator.ts"],"names":[],"mappings":";;;AACA,mCAA2C;AAC3C,kCAAiC;AAIjC,MAAa,cAAc;IAEzB,YAA6B,WAA4B;QAA5B,gBAAW,GAAX,WAAW,CAAiB;QADjD,YAAO,GAAgC,EAAE,CAAA;QAqIzC,eAAU,GAAG,CAAC,OAAiB,EAAE,KAA8B,EAAU,EAAE,CACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAEhD,iBAAY,GAAG,CAA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Ac,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,SAAS;oBAC1D,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAW,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,EACtD;gBACA,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,yDAAyD,CAAC,CAAA;aACnF;YACD,OAAM;SACP;aAAM,IAAI,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YAC1C,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,8BAA8B,IAAI,EAAE,CAAC,CAAA;SAC9D;IACH,CAAC;IAEO,YAAY,CAAC,GAAW,EAAE,UAA2B;QAC3D,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE;YAC9D,MAAM,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;YACpC,IAAI,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;gBAClB,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,eAAe,UAAU,eAAe,CAAC,CAAA;aAClE;SACF;QAED,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE;YAC7D,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;YACnC,IAAI,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;gBACnB,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,yCAAyC,SAAS,EAAE,CAAC,CAAA;aAC9E;SACF;IACH,CAAC;CAQF;AA5ID,wCA4IC"}
package/README.md DELETED
@@ -1,102 +0,0 @@
1
- # EA Framework v3
2
-
3
- External adapters and its core framework serve as middleware to facilitate connections between Chainlink Nodes and Data Providers (DP). Their main purpose is threefold:
4
-
5
- - Abstract provider specific details, specifically:
6
- - Transport (REST, WebSockets, RPC, SSE, etc.)
7
- - Authentication (login flows, keys)
8
- - Accept normalized request payloads and translate into the provider's interface (this also includes things like symbols/tickers)
9
- - Parse provider responses into the desired data points (e.g. price from crypto endpoint)
10
- - Make the overall system more efficient by using as few resources (e.g. API credits, networking traffic, CPU usage) as possible to fetch data, achieved by features like:
11
- - Caching: since DPs update data at various times and a request to their API incurs a certain latency, EAs keep a cache of values to
12
- - Provide responses to the Chainlink Nodes as quickly as possible
13
- - Communicate with DPs only when necessary
14
- - Cache Warming: in order to make as many of the requests to EAs be fulfilled from the cache, EAs fetch values from DPs asynchronously to keep the local ones fresh.
15
- - Batching: the CL Node requests feeds individually, but it's common for DPs to provide batch endpoints to get many data points at once. With Batching, EAs keep track of incoming requests and consolidate them into one batched request.
16
- - Rate limiting: the EA framework additionally checks request rates (frequency) to make sure they fall within acceptable limits (like quotas for the DP's API, or adjusting based on the NOP's API tier).
17
- - Perform off chain computations (think aggregations, indexing, or any sort of data processing)
18
-
19
- By providing a framework that gives users easy access to those features, we reduce the complexity required for Nodes to communicate with DPs since by using EAs there is only one standardized way to do so, while at the same time optimizing said communication so it's as resource efficient as possible. It also makes internal and external development easier and faster, by serving as a strict guideline to implement and add new providers.
20
-
21
- ## Qs
22
-
23
- - Store entire response in cache?
24
- - Check for valid result in adapter response?
25
-
26
- ## Env vars
27
-
28
- These are all existing env vars, marked DONE if they have been ported to this version, or N/A if the new version disregards them altogether.
29
-
30
- | Name | State | Comments |
31
- | :----------------------------------------- | :---: | :----------------------------------------------------------- |
32
- | ADAPTER_URL | - | |
33
- | API_ENDPOINT | √ | |
34
- | API_KEY | √ | |
35
- | API_TIMEOUT | √ | Sets timeout for axios request |
36
- | API_VERBOSE | √ | Does not return verbose on cache hit |
37
- | BASE_URL | √ | |
38
- | CACHE_ENABLED | N/A | Cache is integral to this fw, not including this for now |
39
- | CACHE_KEY_IGNORED_PROPS | N/A | Not applicable after feed ID generation logic change |
40
- | CACHE_KEY_GROUP | N/A | Grouping cache data is not needed in v3 |
41
- | CACHE_MAX_AGE | √ | |
42
- | CACHE_MAX_ITEMS | - | Should add when replacing obj in local impl with LRU package |
43
- | CACHE_MIN_AGE | - | Used for rate limiting |
44
- | CACHE_REDIS_CONNECTION_TIMEOUT | - | TODO: Redis |
45
- | CACHE_REDIS_HOST | √ | |
46
- | CACHE_REDIS_MAX_QUEUED_ITEMS | - | TODO: Redis |
47
- | CACHE_REDIS_MAX_RECONNECT_COOLDOWN | - | TODO: Redis |
48
- | CACHE_REDIS_PASSWORD | √ | |
49
- | CACHE_REDIS_PATH | √ | |
50
- | CACHE_REDIS_PORT | √ | |
51
- | CACHE_REDIS_TIMEOUT | √ | |
52
- | CACHE_REDIS_URL | - | TODO: Redis |
53
- | CACHE_TYPE | √ | |
54
- | CACHE_UPDATE_AGE_ON_GET | N/A | No longer used in EA currently, apparently |
55
- | DATA_PROVIDER_URL | - | Legacy var same as ADAPTER_URL |
56
- | DEBUG | √ | |
57
- | DEFAULT_WS_HEARTBEAT_INTERVAL | N/A | |
58
- | EA_HOST | √ | |
59
- | EA_PORT | √ | |
60
- | ERROR_CAPACITY | - | Error backoff is not currently in v3 |
61
- | EXPERIMENTAL_METRICS_ENABLED | √ | Maintaining for backwards compatibility. Defaults to true |
62
- | LOG_LEVEL | | |
63
- | METRICS_ENABLED | √ | Defaults to true |
64
- | METRICS_NAME | √ | |
65
- | METRICS_PORT | √ | |
66
- | METRICS_USE_BASE_URL | √ | |
67
- | NODE_ENV | | |
68
- | npm_package_version | | |
69
- | RATE_LIMIT_API_TIER | √ | |
70
- | RATE_LIMIT_CAPACITY | √ | Used for per minute rate limit if exists |
71
- | RATE_LIMIT_CAPACITY_MINUTE | √ | Used for per minute rate limit if exists |
72
- | RATE_LIMIT_CAPACITY_SECOND | √ | Used for per second rate limit if exists |
73
- | RATE_LIMIT_ENABLED | N/A | Rate limit always enabled in v3 |
74
- | RECORD | N/A | Not needed in v3 config for integration testing |
75
- | REQUEST_COALESCING_ENABLED | √ | Overrides transport config option if set |
76
- | REQUEST_COALESCING_ENTROPY_MAX | | |
77
- | REQUEST_COALESCING_INTERVAL | | |
78
- | REQUEST_COALESCING_INTERVAL_COEFFICIENT | | |
79
- | REQUEST_COALESCING_INTERVAL_MAX | | |
80
- | REQUEST_COALESCING_MAX_RETRIES | | |
81
- | RETRY | - | Retry mechanism not yet part of v3 |
82
- | SERVER_RATE_LIMIT_MAX | | |
83
- | SERVER_SLOW_DOWN_AFTER_FACTOR | | |
84
- | SERVER_SLOW_DOWN_DELAY_MS | | |
85
- | TIMEOUT | X | API_TIMEOUT is used for same purpose |
86
- | WARMUP_ENABLED | | |
87
- | WARMUP_INTERVAL | | |
88
- | WARMUP_SUBSCRIPTION_TTL | | |
89
- | WARMUP_UNHEALTHY_THRESHOLD | | |
90
- | WS_API_ENDPOINT | | |
91
- | WS_API_KEY | | |
92
- | WS_CONNECTION_KEY | N/A | Connection key is no longer used for WS in v3 |
93
- | WS_CONNECTION_LIMIT | | |
94
- | WS_CONNECTION_RETRY_DELAY | | |
95
- | WS_CONNECTION_RETRY_LIMIT | | |
96
- | WS_CONNECTION_TTL | | |
97
- | WS_ENABLED | N/A | Shouldn't be part of this fw |
98
- | WS_SUBSCRIPTION_LIMIT | | |
99
- | WS_SUBSCRIPTION_PRIORITY_LIST | | |
100
- | WS_SUBSCRIPTION_TTL | | |
101
- | WS_SUBSCRIPTION_UNRESPONSIVE_TTL | | |
102
- | WS_TIME_UNTIL_HANDLE_NEXT_MESSAGE_OVERRIDE | | |