@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,49 @@
1
+ /// <reference types="node" />
2
+ import pino from 'pino';
3
+ import { AdapterRequest } from './request';
4
+ import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
5
+ import { AsyncLocalStorage } from 'node:async_hooks';
6
+ import { CensorKeyValue } from './censor/censor-list';
7
+ export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
8
+ export declare type Store = {
9
+ correlationId: string;
10
+ };
11
+ export declare const COLORS: string[];
12
+ export declare const colorFactory: (colors: string[]) => () => string;
13
+ /**
14
+ * Instead of using a global logger instance, we want to force using a child logger
15
+ * with a specific layer set in it, so that we can filter logs by where they're output from.
16
+ *
17
+ * Details on what each log level represents:
18
+ * "trace": Forensic debugging of issues on a local machine.
19
+ * "debug": Detailed logging level to get more context from users on their environments.
20
+ * "info": High-level informational messages, to describe at a glance the high level state of the system.
21
+ * "warn": A mild error occurred that might require non-urgent action.
22
+ * "error": An unexpected error occurred during the regular operation of a well-maintained EA.
23
+ * "fatal": The EA encountered an unrecoverable problem and had to exit.
24
+ *
25
+ * Full reference this is based on can be found at
26
+ * https://github.com/smartcontractkit/documentation/blob/main/docs/Node%20Operators/configuration-variables.md#log_level
27
+ *
28
+ * @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
29
+ * @returns a layer specific logger
30
+ */
31
+ export declare const makeLogger: (layer: string) => pino.Logger<{
32
+ level: string;
33
+ hooks: {
34
+ logMethod(this: pino.Logger<pino.LoggerOptions>, inputArgs: [msg: string, ...args: any[]], method: pino.LogFn): void;
35
+ };
36
+ mixin(): {};
37
+ transport: {
38
+ target: string;
39
+ options: {
40
+ levelFirst: boolean;
41
+ levelLabel: string;
42
+ ignore: string;
43
+ messageFormat: string;
44
+ translateTime: string;
45
+ };
46
+ } | undefined;
47
+ } & pino.ChildLoggerOptions>;
48
+ export declare const loggingContextMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;
49
+ export declare function censor(obj: any, censorList: CensorKeyValue[]): any;
package/util/logger.js ADDED
@@ -0,0 +1,123 @@
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.censor = exports.loggingContextMiddleware = exports.makeLogger = exports.colorFactory = exports.COLORS = exports.asyncLocalStorage = void 0;
7
+ const pino_1 = __importDefault(require("pino"));
8
+ const config_1 = require("../config");
9
+ const crypto_1 = require("crypto");
10
+ const node_async_hooks_1 = require("node:async_hooks");
11
+ const censor_list_1 = __importDefault(require("./censor/censor-list"));
12
+ exports.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
13
+ const debugTransport = {
14
+ target: 'pino-pretty',
15
+ options: {
16
+ levelFirst: true,
17
+ levelLabel: 'level',
18
+ ignore: 'layer,pid,hostname,correlationId,color',
19
+ messageFormat: `\x1b[0m[{correlationId}] {color}[{layer}]\x1b[0m {msg}`,
20
+ translateTime: 'yyyy-mm-dd HH:MM:ss.l',
21
+ },
22
+ };
23
+ // Base logger, shouldn't be used because we want layers to be specified
24
+ const baseLogger = (0, pino_1.default)({
25
+ level: process.env['LOG_LEVEL']?.toLowerCase() || config_1.BaseSettings.LOG_LEVEL.default,
26
+ hooks: {
27
+ logMethod(inputArgs, method) {
28
+ // Censor each argument of logger
29
+ const censorList = censor_list_1.default.getAll();
30
+ return method.apply(this, inputArgs.map((arg) => censor(arg, censorList)));
31
+ },
32
+ },
33
+ mixin() {
34
+ if (process.env['CORRELATION_ID_ENABLED'] !== 'false') {
35
+ const store = exports.asyncLocalStorage.getStore();
36
+ if (store) {
37
+ return store;
38
+ }
39
+ }
40
+ return {};
41
+ },
42
+ transport: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
43
+ ? debugTransport
44
+ : undefined,
45
+ });
46
+ exports.COLORS = [
47
+ '\u001b[31;1m',
48
+ '\u001b[32m',
49
+ '\u001b[33m',
50
+ '\u001b[34m',
51
+ '\u001b[35m',
52
+ '\u001b[36m',
53
+ '\u001b[38;2;121;85;72m',
54
+ '\u001b[92m',
55
+ '\u001b[93m',
56
+ '\u001b[94m',
57
+ '\u001b[95m',
58
+ '\u001b[96m',
59
+ '\u001b[38;5;202m',
60
+ '\u001b[38;5;31m',
61
+ '\u001b[38;5;130m',
62
+ '\u001b[38;2;255;122;92m',
63
+ '\u001b[38;2;46;125;50m',
64
+ '\u001b[38;2;129;168;37m',
65
+ '\u001b[38;2;175;180;43m',
66
+ '\u001b[91m',
67
+ '\u001b[38;2;63;81;181m',
68
+ ];
69
+ const colorFactory = (colors) => {
70
+ let index = -1;
71
+ return () => {
72
+ index++;
73
+ if (index > colors.length - 1) {
74
+ index = 0;
75
+ }
76
+ return colors[index];
77
+ };
78
+ };
79
+ exports.colorFactory = colorFactory;
80
+ const getNextColor = (0, exports.colorFactory)(exports.COLORS);
81
+ /**
82
+ * Instead of using a global logger instance, we want to force using a child logger
83
+ * with a specific layer set in it, so that we can filter logs by where they're output from.
84
+ *
85
+ * Details on what each log level represents:
86
+ * "trace": Forensic debugging of issues on a local machine.
87
+ * "debug": Detailed logging level to get more context from users on their environments.
88
+ * "info": High-level informational messages, to describe at a glance the high level state of the system.
89
+ * "warn": A mild error occurred that might require non-urgent action.
90
+ * "error": An unexpected error occurred during the regular operation of a well-maintained EA.
91
+ * "fatal": The EA encountered an unrecoverable problem and had to exit.
92
+ *
93
+ * Full reference this is based on can be found at
94
+ * https://github.com/smartcontractkit/documentation/blob/main/docs/Node%20Operators/configuration-variables.md#log_level
95
+ *
96
+ * @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
97
+ * @returns a layer specific logger
98
+ */
99
+ const makeLogger = (layer) => baseLogger.child({
100
+ layer,
101
+ color: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
102
+ ? getNextColor()
103
+ : undefined,
104
+ });
105
+ exports.makeLogger = makeLogger;
106
+ const loggingContextMiddleware = (req, res, done) => {
107
+ const correlationId = req.headers['x-correlation-id'] || (0, crypto_1.randomUUID)();
108
+ exports.asyncLocalStorage.run({ correlationId: correlationId }, () => {
109
+ done();
110
+ });
111
+ };
112
+ exports.loggingContextMiddleware = loggingContextMiddleware;
113
+ // Obj is typed as "any" because it could be a variety of structures in the logger
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
+ function censor(obj, censorList) {
116
+ let stringified = JSON.stringify(obj);
117
+ censorList.forEach((entry) => {
118
+ stringified = stringified.replace(entry.value, `[${entry.key} REDACTED]`);
119
+ });
120
+ return JSON.parse(stringified);
121
+ }
122
+ exports.censor = censor;
123
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,sCAAwC;AAGxC,mCAAmC;AACnC,uDAAoD;AACpD,uEAAiE;AAEpD,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAE,CAAA;AAMxD,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,aAAa;IACrB,OAAO,EAAE;QACP,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,OAAO;QACnB,MAAM,EAAE,wCAAwC;QAChD,aAAa,EAAE,wDAAwD;QACvE,aAAa,EAAE,uBAAuB;KACvC;CACF,CAAA;AAED,wEAAwE;AACxE,MAAM,UAAU,GAAG,IAAA,cAAI,EAAC;IACtB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,IAAI,qBAAY,CAAC,SAAS,CAAC,OAAO;IAChF,KAAK,EAAE;QACL,SAAS,CAAC,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BAMC"}
@@ -0,0 +1,138 @@
1
+ import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify';
2
+ import { Adapter } from '../adapter';
3
+ import { AdapterError } from '../validation/error';
4
+ declare module 'fastify' {
5
+ interface FastifyRequest {
6
+ requestContext: AdapterRequestContext;
7
+ }
8
+ }
9
+ export declare type Merge<T1, T2> = {
10
+ [K in keyof T1 | keyof T2]: K extends keyof T2 ? T2[K] : K extends keyof T1 ? T1[K] : never;
11
+ };
12
+ /**
13
+ * Structure for the body of all requests that will be sent to the adapter
14
+ */
15
+ export interface AdapterRequestBody<T = AdapterRequestData> {
16
+ /** Adapter endpoint (not to be confused with REST API endpoint) */
17
+ endpoint?: string;
18
+ /** Main data that will be validated and used on each adapter request */
19
+ data: T;
20
+ }
21
+ /**
22
+ * Object that will be added to the request on a successful validation.
23
+ * Contains all the necessary information the adapter will need across the request execution.
24
+ */
25
+ export declare type AdapterRequestContext<T = AdapterRequestData> = {
26
+ /** Name of the endpoint this payload should be directed to */
27
+ endpointName: string;
28
+ /** Precalculated cache key used to get and set corresponding values from the cache and subscription sets */
29
+ cacheKey: string;
30
+ /** Normalized and validated data coming from the request body */
31
+ data: T;
32
+ /** Metadata relevant to this particular request */
33
+ meta?: AdapterRequestMeta;
34
+ };
35
+ /**
36
+ * Helper type to denote an empty body
37
+ */
38
+ declare type EmptyBody = Record<string, never>;
39
+ /**
40
+ * Helper type to provide fastify for all adapter handlers
41
+ */
42
+ export declare type AdapterRouteGeneric = {
43
+ /** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
44
+ Body: EmptyBody;
45
+ };
46
+ /**
47
+ * Structure for all requests incoming to this adapter
48
+ */
49
+ export declare type AdapterRequest<T extends RequestGenerics = RequestGenerics> = FastifyRequest<AdapterRouteGeneric> & {
50
+ /** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
51
+ body: EmptyBody;
52
+ /** Container for all validated information that will be used by the framework across this request's lifecycle */
53
+ requestContext: AdapterRequestContext<T['Params']>;
54
+ };
55
+ /**
56
+ * Metadata for a particular request
57
+ */
58
+ export interface AdapterRequestMeta {
59
+ /** Relevant metrics gathered for this request */
60
+ metrics?: AdapterMetricsMeta;
61
+ /** An error that ocurred somewhere along this requests' lifecycle */
62
+ error?: AdapterError | Error;
63
+ }
64
+ /**
65
+ * Meta info that pertains to exposing metrics
66
+ */
67
+ export interface AdapterMetricsMeta {
68
+ /** String to uniquely identify a specific price feed */
69
+ feedId?: string;
70
+ /** Boolean to note if this request's response was found in the cache directly */
71
+ cacheHit?: boolean;
72
+ }
73
+ /**
74
+ * Basic shape for the data within the request body
75
+ */
76
+ export declare type AdapterRequestData = Record<string, unknown> & {
77
+ endpoint?: string;
78
+ };
79
+ /**
80
+ * Helper type to hold the value from responses from a provider, and the adapter params they correspond to.
81
+ */
82
+ export interface ProviderResult<T extends {
83
+ Request: RequestGenerics;
84
+ Response: ResponseGenerics;
85
+ }> {
86
+ /** The set of parameters that uniquely relate to the response */
87
+ params: T['Request']['Params'];
88
+ /** Value that will be included in the result property of the response */
89
+ value: T['Response']['Result'];
90
+ }
91
+ export declare type EmptyObject = Object;
92
+ /**
93
+ * Helper struct type that provides detail about the incoming Adapter Request
94
+ */
95
+ export declare type RequestGenerics = {
96
+ /**
97
+ * Type for the parameters sent to the EA in the data property of the body.
98
+ */
99
+ Params: EmptyObject;
100
+ };
101
+ /**
102
+ * Helper struct type that provides detail about the outgoing Adapter Response
103
+ */
104
+ export declare type ResponseGenerics = {
105
+ /**
106
+ * Type for the data property of the response.
107
+ */
108
+ Data: unknown;
109
+ /**
110
+ * Type for the result property of the response.
111
+ * This is mostly used for OCR, and corresponds to one "word" when talking about it from an on-chain perspective.
112
+ */
113
+ Result: string | number | null;
114
+ };
115
+ /**
116
+ * Shape of the response body from the adapter
117
+ */
118
+ export declare type AdapterResponse<T extends ResponseGenerics = ResponseGenerics> = {
119
+ /** HTTP status code */
120
+ statusCode: number;
121
+ /** Response data, holds "result" for Flux Monitor */
122
+ data: T['Data'];
123
+ /** Result value used for OCR */
124
+ result: T['Result'];
125
+ /** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
126
+ maxAge?: number;
127
+ /** Metadata relevant to this request */
128
+ meta?: AdapterRequestMeta;
129
+ };
130
+ export declare type SingleNumberResultResponse = {
131
+ Result: number;
132
+ Data: {
133
+ result: number;
134
+ };
135
+ };
136
+ export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
137
+ export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
138
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/util/request.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import { SubscriptionSet } from './subscription-set';
2
+ /**
3
+ * An object describing an entry in the expiring sorted set.
4
+ * @typeParam T - the type of the entry's value
5
+ */
6
+ interface ExpiringSortedSetEntry<T> {
7
+ value: T;
8
+ expirationTimestamp: number;
9
+ }
10
+ /**
11
+ * This class implements a set of unique items, each of which has an expiration timestamp.
12
+ * On reads, items that have expired will be deleted from the set and not returned.
13
+ *
14
+ * @typeParam T - the type of the set entries' values
15
+ */
16
+ export declare class ExpiringSortedSet<T> implements SubscriptionSet<T> {
17
+ map: Map<string, ExpiringSortedSetEntry<T>>;
18
+ add(key: string, value: T, ttl: number): void;
19
+ getAll(): T[];
20
+ }
21
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpiringSortedSet = void 0;
4
+ /**
5
+ * This class implements a set of unique items, each of which has an expiration timestamp.
6
+ * On reads, items that have expired will be deleted from the set and not returned.
7
+ *
8
+ * @typeParam T - the type of the set entries' values
9
+ */
10
+ class ExpiringSortedSet {
11
+ constructor() {
12
+ this.map = new Map();
13
+ }
14
+ add(key, value, ttl) {
15
+ this.map.set(key, {
16
+ value,
17
+ expirationTimestamp: Date.now() + ttl,
18
+ });
19
+ }
20
+ getAll() {
21
+ const results = [];
22
+ const now = Date.now();
23
+ // Since we're iterating, might as well prune here
24
+ for (const [key, entry] of this.map.entries()) {
25
+ if (entry.expirationTimestamp < now) {
26
+ this.map.delete(key); // In theory, this shouldn't happen frequently for feeds
27
+ }
28
+ else {
29
+ results.push(entry.value);
30
+ }
31
+ }
32
+ return results;
33
+ }
34
+ }
35
+ exports.ExpiringSortedSet = ExpiringSortedSet;
36
+ //# sourceMappingURL=expiring-sorted-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expiring-sorted-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/expiring-sorted-set.ts"],"names":[],"mappings":";;;AAWA;;;;;GAKG;AACH,MAAa,iBAAiB;IAA9B;QACE,QAAG,GAAG,IAAI,GAAG,EAAqC,CAAA;IAwBpD,CAAC;IAtBC,GAAG,CAAC,GAAW,EAAE,KAAQ,EAAE,GAAW;QACpC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,KAAK;YACL,mBAAmB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG;SACtC,CAAC,CAAA;IACJ,CAAC;IAED,MAAM;QACJ,MAAM,OAAO,GAAQ,EAAE,CAAA;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEtB,kDAAkD;QAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE;YAC7C,IAAI,KAAK,CAAC,mBAAmB,GAAG,GAAG,EAAE;gBACnC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA,CAAC,wDAAwD;aAC9E;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;aAC1B;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAzBD,8CAyBC"}
@@ -0,0 +1,9 @@
1
+ import Redis from 'ioredis';
2
+ import { SubscriptionSet } from './subscription-set';
3
+ export declare class RedisSubscriptionSet<T> implements SubscriptionSet<T> {
4
+ private redisClient;
5
+ private subscriptionSetKey;
6
+ constructor(redisClient: Redis, subscriptionSetKey: string);
7
+ add(key: string, value: T, ttl: number): Promise<undefined>;
8
+ getAll(): Promise<T[]>;
9
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisSubscriptionSet = void 0;
4
+ // Delimiter used to store both key and value in redis sorted set string field together
5
+ const DELIMITER = '>';
6
+ class RedisSubscriptionSet {
7
+ constructor(redisClient, subscriptionSetKey) {
8
+ this.redisClient = redisClient;
9
+ this.subscriptionSetKey = subscriptionSetKey;
10
+ }
11
+ async add(key, value, ttl) {
12
+ const storedValue = `${key}${DELIMITER}${JSON.stringify(value)}`;
13
+ await this.redisClient.zadd(this.subscriptionSetKey, Date.now() + ttl, storedValue);
14
+ return;
15
+ }
16
+ async getAll() {
17
+ // Remove expired keys from sorted set
18
+ await this.redisClient.zremrangebyscore(this.subscriptionSetKey, '-inf', Date.now());
19
+ const parsedRequests = [];
20
+ const validEntries = await this.redisClient.zrange(this.subscriptionSetKey, 0, -1);
21
+ validEntries.forEach((entry) => {
22
+ // Separate request and cache key prior to populating results array
23
+ parsedRequests.push(JSON.parse(entry.split(DELIMITER)[1]));
24
+ });
25
+ return parsedRequests;
26
+ }
27
+ }
28
+ exports.RedisSubscriptionSet = RedisSubscriptionSet;
29
+ //# sourceMappingURL=redis-sorted-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-sorted-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/redis-sorted-set.ts"],"names":[],"mappings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
+ /**
5
+ * Set to hold items to subscribe to from a provider (regardless of protocol)
6
+ */
7
+ export interface SubscriptionSet<T> {
8
+ /** Add a new subscription to the set */
9
+ add(key: string, value: T, ttl: number): PromiseOrValue<void>;
10
+ /** Get all subscriptions from the set as a list */
11
+ getAll(): PromiseOrValue<T[]>;
12
+ }
13
+ export declare class SubscriptionSetFactory {
14
+ private cacheType;
15
+ private redisClient?;
16
+ private adapterName?;
17
+ constructor(config: AdapterConfig, adapterName: string, redisClient?: Redis);
18
+ buildSet<T>(endpointName: string): SubscriptionSet<T>;
19
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscriptionSetFactory = void 0;
4
+ const expiring_sorted_set_1 = require("./expiring-sorted-set");
5
+ const redis_sorted_set_1 = require("./redis-sorted-set");
6
+ class SubscriptionSetFactory {
7
+ constructor(config, adapterName, redisClient) {
8
+ this.cacheType = config.CACHE_TYPE;
9
+ this.redisClient = redisClient;
10
+ this.adapterName = adapterName;
11
+ }
12
+ buildSet(endpointName) {
13
+ switch (this.cacheType) {
14
+ case 'local':
15
+ return new expiring_sorted_set_1.ExpiringSortedSet();
16
+ case 'redis': {
17
+ if (!this.redisClient) {
18
+ throw new Error('Redis client undefined. Cannot create Redis subscription set');
19
+ }
20
+ // Identifier key used for the subscription set in redis
21
+ const subscriptionSetKey = `${this.adapterName}-${endpointName}-subscriptionSet`;
22
+ return new redis_sorted_set_1.RedisSubscriptionSet(this.redisClient, subscriptionSetKey);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ exports.SubscriptionSetFactory = SubscriptionSetFactory;
28
+ //# sourceMappingURL=subscription-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,WAAmB;QACzE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,QAAQ,CAAI,YAAoB;QAC9B,QAAQ,IAAI,CAAC,SAAS,EAAE;YACtB,KAAK,OAAO;gBACV,OAAO,IAAI,uCAAiB,EAAK,CAAA;YACnC,KAAK,OAAO,CAAC,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBACrB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;iBAChF;gBACD,wDAAwD;gBACxD,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,YAAY,kBAAkB,CAAA;gBAChF,OAAO,IAAI,uCAAoB,CAAI,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF;AAzBD,wDAyBC"}
@@ -0,0 +1,26 @@
1
+ import { AdapterRequestData } from './request';
2
+ /**
3
+ * The test payload read in from filesystem
4
+ */
5
+ export interface Payload {
6
+ requests: Array<AdapterRequestData>;
7
+ }
8
+ /**
9
+ * Test payload with discriminated union so we can tell when we should just do
10
+ * a simple liveness check rather than a sample request
11
+ */
12
+ declare type TestPayload = (Payload & {
13
+ isDefault: false;
14
+ }) | {
15
+ isDefault: true;
16
+ };
17
+ /**
18
+ * Load in a JSON file containing a test payload for the current adapter,
19
+ * used in healthchecks to make sample requests
20
+ *
21
+ * @param fileName - name of file that contains the test payload data for the smoke endpoint
22
+ * @returns the parsed payload with individual requests
23
+ */
24
+ export declare function loadTestPayload(fileName?: string): TestPayload;
25
+ export declare function resolvePayload(fileName?: string): Payload | null;
26
+ export {};
@@ -0,0 +1,85 @@
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.resolvePayload = exports.loadTestPayload = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const logger_1 = require("./logger");
11
+ const logger = (0, logger_1.makeLogger)('TestPayloadLoader');
12
+ /**
13
+ * Load in a JSON file containing a test payload for the current adapter,
14
+ * used in healthchecks to make sample requests
15
+ *
16
+ * @param fileName - name of file that contains the test payload data for the smoke endpoint
17
+ * @returns the parsed payload with individual requests
18
+ */
19
+ function loadTestPayload(fileName) {
20
+ const ajv = new ajv_1.default();
21
+ const schema = {
22
+ type: 'object',
23
+ required: ['requests'],
24
+ properties: {
25
+ requests: {
26
+ type: 'array',
27
+ items: {
28
+ type: 'object',
29
+ required: [],
30
+ },
31
+ },
32
+ },
33
+ };
34
+ const validate = ajv.compile(schema);
35
+ try {
36
+ const payload = resolvePayload(fileName);
37
+ if (!validate(payload) || !payload?.requests) {
38
+ throw Error(JSON.stringify(validate?.errors || 'Could not validate schema for test payload'));
39
+ }
40
+ return { ...payload, isDefault: false };
41
+ }
42
+ catch (e) {
43
+ logger.warn(`Could not load payload: ${e.message}`);
44
+ logger.warn('Falling back to default empty payload');
45
+ return { isDefault: true };
46
+ }
47
+ }
48
+ exports.loadTestPayload = loadTestPayload;
49
+ function resolvePayload(fileName) {
50
+ try {
51
+ let payload = null;
52
+ // Find test payload by specified name, fallback to default names if not found
53
+ if (fileName && fs_1.default.existsSync(path_1.default.join(process.cwd(), fileName))) {
54
+ payload = require(path_1.default.join(process.cwd(), fileName));
55
+ }
56
+ else if (fileName && fs_1.default.existsSync(`./${fileName}`)) {
57
+ payload = require(`./${fileName}`);
58
+ }
59
+ // Search for test payload js first if no filename specified or found
60
+ else if (fs_1.default.existsSync(path_1.default.resolve('.', 'test-payload.js'))) {
61
+ payload = require(path_1.default.join(process.cwd(), 'test-payload.js'));
62
+ }
63
+ else if (fs_1.default.existsSync(`./test-payload.js`)) {
64
+ payload = require(`./test-payload.js`);
65
+ }
66
+ // Search for test payload json second if no filename specified or found
67
+ else if (fs_1.default.existsSync(path_1.default.join(process.cwd(), 'test-payload.json'))) {
68
+ payload = require(path_1.default.join(process.cwd(), 'test-payload.json'));
69
+ }
70
+ else if (fs_1.default.existsSync(`./test-payload.json`)) {
71
+ payload = require(`./test-payload.json`);
72
+ }
73
+ if (typeof payload === 'string') {
74
+ return JSON.parse(payload);
75
+ }
76
+ else {
77
+ return payload;
78
+ }
79
+ }
80
+ catch {
81
+ return null;
82
+ }
83
+ }
84
+ exports.resolvePayload = resolvePayload;
85
+ //# sourceMappingURL=test-payload-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-payload-loader.js","sourceRoot":"","sources":["../../../src/util/test-payload-loader.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,4CAAmB;AACnB,gDAAuB;AACvB,qCAAqC;AAGrC,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,mBAAmB,CAAC,CAAA;AAe9C;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,QAAiB;IAC/C,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC;QACtB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,EAAE;iBACb;aACF;SACF;KACF,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI;QACF,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE;YAC5C,MAAM,KAAK,CAA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E;aACnE,IAAI,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAC,EAAE;YACrE,OAAO,GAAG,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAC,CAAA;SACjE;aAAM,IAAI,YAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE;YAC/C,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;SACzC;QACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;SAC3B;aAAM;YACL,OAAO,OAAO,CAAA;SACf;KACF;IAAC,MAAM;QACN,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AA7BD,wCA6BC"}
@@ -0,0 +1,48 @@
1
+ import { HttpRequestType } from '../metrics/constants';
2
+ declare type ErrorBasic = {
3
+ name: string;
4
+ message: string;
5
+ };
6
+ declare type ErrorFull = ErrorBasic & {
7
+ stack: string;
8
+ cause: string;
9
+ };
10
+ export declare type AdapterErrorResponse = {
11
+ status: string;
12
+ statusCode: number;
13
+ providerStatusCode?: number;
14
+ error: ErrorBasic | ErrorFull;
15
+ };
16
+ export declare class AdapterError extends Error {
17
+ status: string;
18
+ statusCode: number;
19
+ cause: unknown;
20
+ url?: string;
21
+ errorResponse: unknown;
22
+ feedID?: string;
23
+ providerStatusCode?: number;
24
+ metricsLabel?: HttpRequestType;
25
+ name: string;
26
+ message: string;
27
+ constructor({ status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
28
+ toJSONResponse(): AdapterErrorResponse;
29
+ }
30
+ export declare class AdapterInputError extends AdapterError {
31
+ constructor(input: Partial<AdapterError>);
32
+ }
33
+ export declare class AdapterRateLimitError extends AdapterError {
34
+ constructor(input: Partial<AdapterError>);
35
+ }
36
+ export declare class AdapterTimeoutError extends AdapterError {
37
+ constructor(input: Partial<AdapterError>);
38
+ }
39
+ export declare class AdapterDataProviderError extends AdapterError {
40
+ constructor(input: Partial<AdapterError>);
41
+ }
42
+ export declare class AdapterConnectionError extends AdapterError {
43
+ constructor(input: Partial<AdapterError>);
44
+ }
45
+ export declare class AdapterCustomError extends AdapterError {
46
+ constructor(input: Partial<AdapterError>);
47
+ }
48
+ export {};