@chainlink/external-adapter-framework 0.0.111 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/adapter/basic.d.ts +37 -3
  2. package/adapter/basic.js +138 -2
  3. package/adapter/basic.js.map +1 -1
  4. package/adapter/price.d.ts +33 -5
  5. package/adapter/price.js +41 -2
  6. package/adapter/price.js.map +1 -1
  7. package/adapter/types.d.ts +18 -1
  8. package/cache/index.d.ts +3 -10
  9. package/cache/index.js +4 -46
  10. package/cache/index.js.map +1 -1
  11. package/cache/redis.d.ts +1 -8
  12. package/cache/redis.js +22 -39
  13. package/cache/redis.js.map +1 -1
  14. package/config/index.d.ts +6 -1
  15. package/config/index.js +20 -12
  16. package/config/index.js.map +1 -1
  17. package/examples/bank-frick/accounts.d.ts +2 -3
  18. package/examples/bank-frick/accounts.js +1 -4
  19. package/examples/bank-frick/accounts.js.map +1 -1
  20. package/examples/bank-frick/config/index.d.ts +1 -1
  21. package/examples/coingecko/src/crypto-utils.d.ts +5 -5
  22. package/examples/coingecko/src/crypto-utils.js +1 -2
  23. package/examples/coingecko/src/crypto-utils.js.map +1 -1
  24. package/examples/coingecko/src/endpoint/coins.js.map +1 -1
  25. package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +1 -1
  26. package/examples/coingecko/src/endpoint/crypto-marketcap.js +2 -2
  27. package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -1
  28. package/examples/coingecko/src/endpoint/crypto-volume.d.ts +1 -1
  29. package/examples/coingecko/src/endpoint/crypto-volume.js +2 -2
  30. package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -1
  31. package/examples/coingecko/src/endpoint/crypto.d.ts +1 -4
  32. package/examples/coingecko/src/endpoint/crypto.js +2 -2
  33. package/examples/coingecko/src/endpoint/crypto.js.map +1 -1
  34. package/examples/coingecko/src/endpoint/dominance.d.ts +1 -1
  35. package/examples/coingecko/src/endpoint/dominance.js +2 -2
  36. package/examples/coingecko/src/endpoint/dominance.js.map +1 -1
  37. package/examples/coingecko/src/endpoint/global-marketcap.d.ts +1 -1
  38. package/examples/coingecko/src/endpoint/global-marketcap.js +2 -2
  39. package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -1
  40. package/examples/coingecko/src/global-utils.d.ts +3 -3
  41. package/examples/coingecko/src/global-utils.js.map +1 -1
  42. package/examples/coingecko/src/index.d.ts +1 -1
  43. package/examples/coingecko-old/batch-warming.d.ts +1 -1
  44. package/examples/coingecko-old/batch-warming.js +2 -2
  45. package/examples/coingecko-old/batch-warming.js.map +1 -1
  46. package/examples/coingecko-old/rest.js.map +1 -1
  47. package/examples/cryptocompare/src/endpoints/crypto.d.ts +1 -1
  48. package/examples/cryptocompare/src/index.d.ts +1 -1
  49. package/examples/genesis/sseStream.d.ts +2 -2
  50. package/examples/genesis/sseStream.js +15 -8
  51. package/examples/genesis/sseStream.js.map +1 -1
  52. package/examples/ncfx/websocket.d.ts +1 -1
  53. package/index.d.ts +3 -1
  54. package/index.js +4 -6
  55. package/index.js.map +1 -1
  56. package/metrics/index.d.ts +2 -0
  57. package/metrics/index.js +5 -4
  58. package/metrics/index.js.map +1 -1
  59. package/package.json +4 -7
  60. package/rate-limiting/index.d.ts +2 -2
  61. package/transports/batch-warming.d.ts +9 -9
  62. package/transports/batch-warming.js +40 -13
  63. package/transports/batch-warming.js.map +1 -1
  64. package/transports/index.d.ts +23 -26
  65. package/transports/index.js +2 -59
  66. package/transports/index.js.map +1 -1
  67. package/transports/metrics.d.ts +1 -1
  68. package/transports/rest.d.ts +5 -4
  69. package/transports/rest.js +16 -22
  70. package/transports/rest.js.map +1 -1
  71. package/transports/sse.d.ts +6 -7
  72. package/transports/sse.js +2 -6
  73. package/transports/sse.js.map +1 -1
  74. package/transports/websocket.d.ts +6 -7
  75. package/transports/websocket.js +5 -9
  76. package/transports/websocket.js.map +1 -1
  77. package/util/logger.d.ts +4 -0
  78. package/util/logger.js +45 -4
  79. package/util/logger.js.map +1 -1
  80. package/util/subscription-set/subscription-set.d.ts +1 -1
  81. package/util/subscription-set/subscription-set.js +1 -1
  82. package/util/subscription-set/subscription-set.js.map +1 -1
  83. package/util/test-payload-loader.d.ts +1 -0
  84. package/util/test-payload-loader.js +2 -1
  85. package/util/test-payload-loader.js.map +1 -1
  86. package/validation/error.d.ts +1 -3
  87. package/validation/error.js +1 -3
  88. package/validation/error.js.map +1 -1
  89. package/validation/index.js +12 -14
  90. package/validation/index.js.map +1 -1
  91. package/validation/input-params.d.ts +0 -1
  92. package/validation/input-params.js +0 -28
  93. package/validation/input-params.js.map +1 -1
  94. package/validation/input-validator.js +1 -2
  95. package/validation/input-validator.js.map +1 -1
  96. package/adapter.d.ts +0 -156
  97. package/adapter.js +0 -200
  98. package/adapter.js.map +0 -1
  99. package/examples/coingecko/batch-warming.d.ts +0 -7
  100. package/examples/coingecko/batch-warming.js +0 -54
  101. package/examples/coingecko/batch-warming.js.map +0 -1
  102. package/examples/coingecko/index.d.ts +0 -2
  103. package/examples/coingecko/index.js +0 -12
  104. package/examples/coingecko/index.js.map +0 -1
  105. package/examples/coingecko/rest.d.ts +0 -12
  106. package/examples/coingecko/rest.js +0 -55
  107. package/examples/coingecko/rest.js.map +0 -1
  108. package/examples/coingecko/src/cryptoUtils.d.ts +0 -31
  109. package/examples/coingecko/src/cryptoUtils.js +0 -60
  110. package/examples/coingecko/src/globalUtils.d.ts +0 -27
  111. package/examples/coingecko/src/globalUtils.js +0 -46
  112. package/validation/override-functions.d.ts +0 -3
  113. package/validation/override-functions.js +0 -41
  114. package/validation/override-functions.js.map +0 -1
  115. package/validation/preset-tokens.json +0 -23
  116. package/validation/validator.d.ts +0 -47
  117. package/validation/validator.js +0 -303
@@ -1,10 +1,11 @@
1
1
  import { SettingsMap, BaseAdapterConfig, AdapterConfig } from '../config';
2
+ import { AdapterRequest, AdapterResponse } from '../util';
2
3
  import { AdapterEndpoint } from './endpoint';
3
- import { AdapterDependencies, AdapterParams, AdapterRateLimitingConfig, CustomAdapterSettings } from './types';
4
+ import { AdapterDependencies, AdapterParams, AdapterRateLimitingConfig, CustomAdapterSettings, RequestTransform } from './types';
4
5
  /**
5
6
  * Main class to represent an External Adapter
6
7
  */
7
- export declare class Adapter<CustomSettings extends CustomAdapterSettings = SettingsMap> implements AdapterParams<CustomSettings> {
8
+ export declare class Adapter<CustomSettings extends CustomAdapterSettings = SettingsMap> implements Omit<AdapterParams<CustomSettings>, 'bootstrap'> {
8
9
  name: string;
9
10
  defaultEndpoint?: string | undefined;
10
11
  endpoints: AdapterEndpoint<unknown, unknown, CustomSettings>[];
@@ -12,13 +13,16 @@ export declare class Adapter<CustomSettings extends CustomAdapterSettings = Sett
12
13
  customSettings?: SettingsMap | undefined;
13
14
  rateLimiting?: AdapterRateLimitingConfig | undefined;
14
15
  overrides?: Record<string, string> | undefined;
16
+ requestTransforms?: RequestTransform[];
15
17
  initialized: boolean;
16
18
  /** Object containing alias translations for all endpoints */
17
19
  endpointsMap: Record<string, AdapterEndpoint<unknown, unknown, CustomSettings>>;
18
20
  /** Initialized dependencies that the adapter will use */
19
21
  dependencies: AdapterDependencies;
20
22
  /** Configuration params for various adapter properties */
21
- config: AdapterConfig;
23
+ config: AdapterConfig<CustomSettings>;
24
+ /** Bootstrap function that will run when initializing the adapter */
25
+ private readonly bootstrap?;
22
26
  constructor(params: AdapterParams<CustomSettings>);
23
27
  /**
24
28
  * Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
@@ -49,4 +53,34 @@ export declare class Adapter<CustomSettings extends CustomAdapterSettings = Sett
49
53
  * @returns a set of AdapterDependencies all initialized
50
54
  */
51
55
  initializeDependencies(inputDependencies?: Partial<AdapterDependencies>): AdapterDependencies;
56
+ /**
57
+ * Attempts to find a value from the Cache and return that if found.
58
+ *
59
+ * @param req - the incoming request to this adapter
60
+ * @returns the cached value if exists
61
+ */
62
+ findResponseInCache(req: AdapterRequest): Promise<AdapterResponse | undefined>;
63
+ /**
64
+ * Default request transform that takes requests and manipulates
65
+ *
66
+ * @param adapter - the current adapter
67
+ * @param req - the current adapter request
68
+ * @returns the modified (or new) request
69
+ */
70
+ symbolOverrider(req: AdapterRequest): AdapterRequest<import("../util").AdapterRequestData>;
71
+ /**
72
+ * Takes the incoming request and applies all request transforms in the adapter
73
+ *
74
+ * @param req - the current adapter request
75
+ * @returns the request after passing through all request transforms
76
+ */
77
+ runRequestTransforms(req: AdapterRequest): void;
78
+ /**
79
+ * Function to serve as middleware to pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
80
+ *
81
+ * @param req - the incoming request to this adapter
82
+ * @param replySent - a promise that resolves when the reply has already been sent
83
+ * @returns a simple Promise when it's done
84
+ */
85
+ handleRequest(req: AdapterRequest, replySent: Promise<unknown>): Promise<AdapterResponse>;
52
86
  }
package/adapter/basic.js CHANGED
@@ -31,9 +31,11 @@ const ioredis_1 = __importDefault(require("ioredis"));
31
31
  const cache_1 = require("../cache");
32
32
  const cacheMetrics = __importStar(require("../cache/metrics"));
33
33
  const config_1 = require("../config");
34
+ const transportMetrics = __importStar(require("../transports/metrics"));
34
35
  const rate_limiting_1 = require("../rate-limiting");
35
36
  const util_1 = require("../util");
36
37
  const censor_list_1 = __importDefault(require("../util/censor/censor-list"));
38
+ const error_1 = require("../validation/error");
37
39
  const logger = (0, util_1.makeLogger)('Adapter');
38
40
  /**
39
41
  * Main class to represent an External Adapter
@@ -52,6 +54,8 @@ class Adapter {
52
54
  this.customSettings = params.customSettings;
53
55
  this.rateLimiting = params.rateLimiting;
54
56
  this.overrides = params.overrides;
57
+ this.requestTransforms = [this.symbolOverrider.bind(this), ...(params.requestTransforms || [])];
58
+ this.bootstrap = params.bootstrap;
55
59
  this.config = (0, config_1.buildAdapterConfig)({
56
60
  overrides: this.envDefaultOverrides,
57
61
  customSettings: this.customSettings,
@@ -67,6 +71,9 @@ class Adapter {
67
71
  if (this.initialized) {
68
72
  throw new Error('This adapter has already been initialized!');
69
73
  }
74
+ if (this.bootstrap) {
75
+ await this.bootstrap(this);
76
+ }
70
77
  this.dependencies = this.initializeDependencies(dependencies);
71
78
  for (const endpoint of this.endpoints) {
72
79
  // Add aliases to map to use in validation
@@ -132,7 +139,10 @@ class Adapter {
132
139
  buildCensorList() {
133
140
  const censorList = Object.entries(config_1.BaseSettings)
134
141
  .concat(Object.entries(this.customSettings || {}))
135
- .filter(([name, setting]) => setting && setting.type === 'string' && setting.sensitive && this.config[name])
142
+ .filter(([name, setting]) => setting &&
143
+ setting.type === 'string' &&
144
+ setting.sensitive &&
145
+ this.config[name])
136
146
  .map(([name]) => ({
137
147
  key: name,
138
148
  // Escaping potential special characters in values before creating regex
@@ -177,10 +187,136 @@ class Adapter {
177
187
  dependencies.backgroundExecuteRateLimiter = new rate_limiting_1.FixedFrequencyRateLimiter().initialize(this.endpoints, rateLimitingTier);
178
188
  }
179
189
  if (!dependencies.subscriptionSetFactory) {
180
- dependencies.subscriptionSetFactory = new util_1.SubscriptionSetFactory(this.config, dependencies.redisClient, this.name);
190
+ dependencies.subscriptionSetFactory = new util_1.SubscriptionSetFactory(this.config, this.name, dependencies.redisClient);
181
191
  }
182
192
  return dependencies;
183
193
  }
194
+ /**
195
+ * Attempts to find a value from the Cache and return that if found.
196
+ *
197
+ * @param req - the incoming request to this adapter
198
+ * @returns the cached value if exists
199
+ */
200
+ async findResponseInCache(req) {
201
+ const response = await this.dependencies.cache.get(req.requestContext.cacheKey);
202
+ if (response) {
203
+ if (this.config.METRICS_ENABLED && this.config.EXPERIMENTAL_METRICS_ENABLED) {
204
+ const label = cacheMetrics.cacheMetricsLabel(req.requestContext.cacheKey, req.requestContext.meta?.metrics?.feedId || 'N/A', this.config.CACHE_TYPE);
205
+ // Record cache staleness and cache get count and value
206
+ const staleness = (0, cache_1.calculateStaleness)(response.maxAge, this.config.CACHE_MAX_AGE);
207
+ cacheMetrics.cacheGet(label, response.result, staleness);
208
+ req.requestContext.meta = {
209
+ ...req.requestContext.meta,
210
+ metrics: { ...req.requestContext.meta?.metrics, cacheHit: true },
211
+ };
212
+ }
213
+ return response;
214
+ }
215
+ }
216
+ /**
217
+ * Default request transform that takes requests and manipulates
218
+ *
219
+ * @param adapter - the current adapter
220
+ * @param req - the current adapter request
221
+ * @returns the modified (or new) request
222
+ */
223
+ symbolOverrider(req) {
224
+ const requestOverrides = req.requestContext.data?.['overrides']?.[this.name];
225
+ const base = req.requestContext.data['base'];
226
+ // Perform overrides specified in the request payload
227
+ if (requestOverrides) {
228
+ req.requestContext.data['base'] = requestOverrides[base] ?? base;
229
+ }
230
+ // Perform hardcoded adapter overrides
231
+ if (this.overrides) {
232
+ req.requestContext.data['base'] = this.overrides[base] ?? base;
233
+ }
234
+ return req;
235
+ }
236
+ /**
237
+ * Takes the incoming request and applies all request transforms in the adapter
238
+ *
239
+ * @param req - the current adapter request
240
+ * @returns the request after passing through all request transforms
241
+ */
242
+ runRequestTransforms(req) {
243
+ if (!this.requestTransforms) {
244
+ return;
245
+ }
246
+ for (const transform of this.requestTransforms) {
247
+ transform(req);
248
+ }
249
+ }
250
+ /**
251
+ * Function to serve as middleware to pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
252
+ *
253
+ * @param req - the incoming request to this adapter
254
+ * @param replySent - a promise that resolves when the reply has already been sent
255
+ * @returns a simple Promise when it's done
256
+ */
257
+ async handleRequest(req, replySent) {
258
+ // Get transport, must be here because it's already checked in the validator
259
+ const transport = this.endpointsMap[req.requestContext.endpointName].transport;
260
+ // First try to find the response in our cache, keep it ready
261
+ const cachedResponse = await this.findResponseInCache(req);
262
+ // Next we fire off the transport's registration of the request if defined, regardless of if we already have a cached response.
263
+ // This is necessary to ensure things like subscription sets are updated each time we get a request
264
+ let requestRegistrationPromise;
265
+ if (transport.registerRequest) {
266
+ const handler = async () => {
267
+ // If we already have a cached response, wait for it to be sent back before continuing with registration
268
+ // This way we respond to incoming requests from the cache as fast as possible
269
+ if (cachedResponse) {
270
+ await replySent;
271
+ }
272
+ // Disable the non-null assertion error, since we're checking this exists in the if above
273
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
274
+ return transport.registerRequest(req, this.config);
275
+ };
276
+ // Execute the registration handler without blocking
277
+ logger.debug(`Firing request registration handler${cachedResponse ? ' (cached response already sent)' : ''}`);
278
+ requestRegistrationPromise = handler();
279
+ }
280
+ // Now that we have dealt with request registration, we can return the cached response if present
281
+ if (cachedResponse) {
282
+ logger.debug('Found response from cache, sending that');
283
+ return cachedResponse;
284
+ }
285
+ // If there was no cached response, execute the foregroundExecute if defined
286
+ const immediateResponse = transport.foregroundExecute && (await transport.foregroundExecute(req, this.config));
287
+ if (immediateResponse) {
288
+ logger.debug('Got immediate response from transport, sending as response');
289
+ return immediateResponse;
290
+ }
291
+ // Finally, either because there was no synchronous execute or because it returned an empty response,
292
+ // we wait for the cache to be filled (either from background work started in the sync execute, or the backgroundExecute).
293
+ // We can wait for the request registration to have finished here, since we're going to be sleeping for the cache anyways,
294
+ // and it's useful in case the registration throws a promise so that it doesn't go unhandled.
295
+ await requestRegistrationPromise;
296
+ // Observe the idle time taken for polling response
297
+ const metricsTimer = transportMetrics.transportPollingDurationSeconds
298
+ .labels({ endpoint: req.requestContext.endpointName })
299
+ .startTimer();
300
+ logger.debug('Transport is set up, polling cache for response...');
301
+ const response = await (0, cache_1.pollResponseFromCache)(this.dependencies.cache, req.requestContext.cacheKey, {
302
+ maxRetries: this.config.CACHE_POLLING_MAX_RETRIES,
303
+ sleep: this.config.CACHE_POLLING_SLEEP_MS,
304
+ });
305
+ metricsTimer({ succeeded: String(!!response) });
306
+ if (response) {
307
+ logger.debug('Got a response from polling the cache, sending that back');
308
+ return response;
309
+ }
310
+ // Record polling mechanism failure to return response
311
+ transportMetrics.transportPollingFailureCount
312
+ .labels({ endpoint: req.requestContext.endpointName })
313
+ .inc();
314
+ logger.debug('Ran out of polling attempts, returning timeout');
315
+ throw new error_1.AdapterTimeoutError({
316
+ message: 'Timed out waiting for provider result.',
317
+ statusCode: 504,
318
+ });
319
+ }
184
320
  }
185
321
  exports.Adapter = Adapter;
186
322
  //# sourceMappingURL=basic.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"basic.js","sourceRoot":"","sources":["../../../src/adapter/basic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA2B;AAC3B,oCAAuC;AACvC,+DAAgD;AAChD,sCAMkB;AAClB,oDAIyB;AACzB,kCAA4D;AAC5D,6EAAuE;AASvE,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,SAAS,CAAC,CAAA;AAEpC;;GAEG;AACH,MAAa,OAAO;IAwBlB,YAAY,MAAqC;QAZjD,uBAAuB;QACvB,gBAAW,GAAG,KAAK,CAAA;QAEnB,6DAA6D;QAC7D,iBAAY,GAAsE,EAAE,CAAA;QASlF,mBAAmB;QACnB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACvB,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,EAAE,WAAW,EAAE,CAAA;QAC5D,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAA;QACrD,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAA;QAC3C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAA;QACvC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QAEjC,IAAI,CAAC,MAAM,GAAG,IAAA,2BAAkB,EAAC;YAC/B,SAAS,EAAE,IAAI,CAAC,mBAAmB;YACnC,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,CAAC,CAAA;QAEF,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAC7B,IAAI,CAAC,6BAA6B,EAAE,CAAA;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAC,YAA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AmB,CAAC;YAC5B,OAAO,EAAE,wCAAwC;YACjD,UAAU,EAAE,GAAG;SAChB,CAAC,CAAA;IACJ,CAAC;CACF;AApYD,0BAoYC"}
@@ -1,6 +1,7 @@
1
- import { Adapter, AdapterEndpointParams, AdapterParams } from './index';
2
- import { AdapterEndpoint } from './endpoint';
3
1
  import { SettingsMap } from '../config';
2
+ import { AdapterRequest, AdapterRequestContext, AdapterResponse } from '../util';
3
+ import { AdapterEndpoint } from './endpoint';
4
+ import { Adapter, AdapterEndpointParams, AdapterParams } from './index';
4
5
  /**
5
6
  * Type for the base input parameter config that any [[PriceEndpoint]] must extend
6
7
  */
@@ -9,7 +10,7 @@ export declare type PriceEndpointInputParameters = {
9
10
  aliases: readonly ['from', 'coin', ...string[]];
10
11
  type: 'string';
11
12
  description: 'The symbol of symbols of the currency to query';
12
- required: true;
13
+ required: false;
13
14
  };
14
15
  quote: {
15
16
  aliases: readonly ['to', 'market', ...string[]];
@@ -25,10 +26,26 @@ export declare const priceEndpointInputParameters: PriceEndpointInputParameters;
25
26
  /**
26
27
  * Type for base input params for a PriceEndpoint
27
28
  */
28
- declare type PriceEndpointParams = {
29
+ export declare type PriceEndpointParams = {
29
30
  base: string;
30
31
  quote: string;
31
32
  };
33
+ /**
34
+ * Structure of an "includes" file.
35
+ * Include pairs describe an incoming price feed request, and the details specify
36
+ */
37
+ export declare type IncludesFile = IncludePair[];
38
+ declare type IncludeDetails = {
39
+ from: string;
40
+ to: string;
41
+ inverse: boolean;
42
+ };
43
+ declare type IncludePair = {
44
+ from: string;
45
+ to: string;
46
+ includes: IncludeDetails[];
47
+ };
48
+ declare type IncludesMap = Record<string, Record<string, IncludeDetails>>;
32
49
  /**
33
50
  * A PriceEndpoint is a specific type of AdapterEndpoint. Meant to comply with standard practices for
34
51
  * Data Feeds, its InputParameters must extend the basic ones (base/quote).
@@ -38,10 +55,21 @@ export declare class PriceEndpoint<Params extends PriceEndpointParams, ProviderR
38
55
  inputParameters: PriceEndpointInputParameters;
39
56
  });
40
57
  }
58
+ declare type PriceAdapterRequest<T> = AdapterRequest<T> & {
59
+ requestContext: AdapterRequestContext<T> & {
60
+ priceMeta: {
61
+ inverse: boolean;
62
+ };
63
+ };
64
+ };
41
65
  /**
42
66
  * A PriceAdapter is a specific kind of Adapter that includes at least one PriceEnpoint.
43
67
  */
44
68
  export declare class PriceAdapter<CustomSettings extends SettingsMap> extends Adapter<CustomSettings> {
45
- constructor(params: AdapterParams<CustomSettings>);
69
+ includesMap?: IncludesMap;
70
+ constructor(params: AdapterParams<CustomSettings> & {
71
+ includes?: IncludesFile;
72
+ });
73
+ handleRequest(req: PriceAdapterRequest<PriceEndpointParams>, replySent: Promise<unknown>): Promise<AdapterResponse>;
46
74
  }
47
75
  export {};
package/adapter/price.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PriceAdapter = exports.PriceEndpoint = exports.priceEndpointInputParameters = void 0;
4
- const index_1 = require("./index");
5
4
  const endpoint_1 = require("./endpoint");
5
+ const index_1 = require("./index");
6
6
  /**
7
7
  * Base input parameter config that any [[PriceEndpoint]] must extend
8
8
  */
@@ -11,7 +11,7 @@ exports.priceEndpointInputParameters = {
11
11
  aliases: ['from', 'coin'],
12
12
  type: 'string',
13
13
  description: 'The symbol of symbols of the currency to query',
14
- required: true,
14
+ required: false,
15
15
  },
16
16
  quote: {
17
17
  aliases: ['to', 'market'],
@@ -30,6 +30,16 @@ class PriceEndpoint extends endpoint_1.AdapterEndpoint {
30
30
  }
31
31
  }
32
32
  exports.PriceEndpoint = PriceEndpoint;
33
+ const buildIncludesMap = (includesFile) => {
34
+ const includesMap = {};
35
+ for (const { from, to, includes } of includesFile) {
36
+ if (!includesMap[from]) {
37
+ includesMap[from] = {};
38
+ }
39
+ includesMap[from][to] = includes[0];
40
+ }
41
+ return includesMap;
42
+ };
33
43
  /**
34
44
  * A PriceAdapter is a specific kind of Adapter that includes at least one PriceEnpoint.
35
45
  */
@@ -40,6 +50,35 @@ class PriceAdapter extends index_1.Adapter {
40
50
  throw new Error(`This PriceAdapter's list of endpoints does not contain a valid PriceEndpoint`);
41
51
  }
42
52
  super(params);
53
+ if (params.includes) {
54
+ // Build includes map for constant lookups
55
+ this.includesMap = buildIncludesMap(params.includes);
56
+ const requestTransform = (req) => {
57
+ const priceRequest = req;
58
+ const requestData = priceRequest.requestContext.data;
59
+ const includesDetails = this.includesMap?.[requestData.base]?.[requestData.quote];
60
+ if (includesDetails) {
61
+ requestData.base = includesDetails.from || requestData.base;
62
+ requestData.quote = includesDetails.to || requestData.quote;
63
+ }
64
+ const inverse = includesDetails?.inverse || false;
65
+ priceRequest.requestContext.priceMeta = {
66
+ inverse,
67
+ };
68
+ };
69
+ this.requestTransforms?.push(requestTransform);
70
+ }
71
+ }
72
+ async handleRequest(req, replySent) {
73
+ const response = await super.handleRequest(req, replySent);
74
+ if (this.includesMap) {
75
+ // We need to search in the reverse order (quote -> base) because the request transform will have inverted the pair
76
+ const includes = this.includesMap[req.requestContext.data.quote]?.[req.requestContext.data.base];
77
+ if (includes && includes.inverse) {
78
+ response.result = 1 / response.result;
79
+ }
80
+ }
81
+ return response;
43
82
  }
44
83
  }
45
84
  exports.PriceAdapter = PriceAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"price.js","sourceRoot":"","sources":["../../../src/adapter/price.ts"],"names":[],"mappings":";;;AAAA,mCAAuE;AACvE,yCAA4C;AAqB5C;;GAEG;AACU,QAAA,4BAA4B,GAAiC;IACxE,IAAI,EAAE;QACJ,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;QACzB,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,gDAAgD;QAC7D,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC;QACzB,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,0CAA0C;QACvD,QAAQ,EAAE,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AC,CAAA;YAED,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAA;SAC/C;IACH,CAAC;IAEQ,KAAK,CAAC,aAAa,CAC1B,GAA6C,EAC7C,SAA2B;QAE3B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;QAE1D,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,mHAAmH;YACnH,MAAM,QAAQ,GACZ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjF,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,EAAE;gBAChC,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAI,QAAQ,CAAC,MAAiB,CAAA;aAClD;SACF;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AA1DD,oCA0DC"}
@@ -3,10 +3,11 @@ import { AdapterEndpoint } from './endpoint';
3
3
  import { CustomSettingsType, SettingsMap, AdapterConfig, BaseAdapterConfig } from '../config';
4
4
  import { RequestRateLimiter, BackgroundExecuteRateLimiter, AdapterRateLimitTier } from '../rate-limiting';
5
5
  import { Transport } from '../transports';
6
- import { SubscriptionSetFactory } from '../util';
6
+ import { AdapterRequest, SubscriptionSetFactory } from '../util';
7
7
  import { InputParameters } from '../validation';
8
8
  import { Cache } from '../cache';
9
9
  import type EventSource from 'eventsource';
10
+ import { Adapter } from './basic';
10
11
  export declare type CustomAdapterSettings = SettingsMap & NegatedAdapterSettings;
11
12
  declare type NegatedAdapterSettings = {
12
13
  [K in keyof BaseAdapterConfig]?: never;
@@ -45,6 +46,18 @@ export interface AdapterRateLimitingConfig {
45
46
  /** Adapter rate limits, gotten from the specific tier requested */
46
47
  tiers: Record<string, AdapterRateLimitTier>;
47
48
  }
49
+ /**
50
+ * Type to perform arbitrary modifications on an adapter request
51
+ */
52
+ export declare type RequestTransform = (req: AdapterRequest) => void;
53
+ /**
54
+ * Map of overrides objects (symbol -\> symbol) per adapter name
55
+ */
56
+ export declare type Overrides = {
57
+ [adapterName: string]: {
58
+ [symbol: string]: string;
59
+ };
60
+ };
48
61
  /**
49
62
  * Main structure of an External Adapter
50
63
  */
@@ -71,6 +84,10 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
71
84
  rateLimiting?: AdapterRateLimitingConfig;
72
85
  /** Overrides for converting the 'base' parameter that are hardcoded into the adapter. */
73
86
  overrides?: Record<string, string>;
87
+ /** Transforms that will apply to the request before submitting it through the adapter request flow */
88
+ requestTransforms?: RequestTransform[];
89
+ /** Bootstrap function that will run when initializing the adapter */
90
+ bootstrap?: (adapter: Adapter<CustomSettings>) => Promise<void>;
74
91
  }
75
92
  /**
76
93
  * Structure to describe rate limits specs for a specific adapter endpoint
package/cache/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AdapterEndpoint } from '../adapter';
2
2
  import { AdapterConfig, SettingsMap } from '../config';
3
- import { AdapterMiddlewareBuilder, AdapterResponse, sleep } from '../util';
3
+ import { AdapterResponse, sleep } from '../util';
4
+ export * from './factory';
4
5
  export * from './local';
5
6
  export * from './redis';
6
- export * from './factory';
7
7
  /**
8
8
  * An object describing an entry in the cache.
9
9
  * @typeParam T - the type of the entry's value
@@ -71,6 +71,7 @@ export declare const calculateFeedId: <Params, Result, CustomSettings extends Se
71
71
  * ```
72
72
  */
73
73
  export declare const calculateKey: <CustomSettings extends SettingsMap>(data: unknown, paramNames: string[], adapterConfig: AdapterConfig<CustomSettings>) => string;
74
+ export declare const calculateStaleness: (expirationTimestamp: number | undefined, ttl: number) => number;
74
75
  /**
75
76
  * Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
76
77
  * amount of retries is exceeded, it returns undefined instead.
@@ -84,11 +85,3 @@ export declare const pollResponseFromCache: (cache: Cache<AdapterResponse>, key:
84
85
  maxRetries: number;
85
86
  sleep: number;
86
87
  }, retry?: number) => Promise<AdapterResponse | undefined>;
87
- /**
88
- * Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
89
- * a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
90
- *
91
- * @param adapter - an initialized adapter
92
- * @returns the cache middleware function
93
- */
94
- export declare const buildCacheMiddleware: AdapterMiddlewareBuilder;
package/cache/index.js CHANGED
@@ -10,28 +10,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
15
  };
28
16
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.buildCacheMiddleware = exports.pollResponseFromCache = exports.calculateKey = exports.calculateFeedId = exports.calculateCacheKey = void 0;
17
+ exports.pollResponseFromCache = exports.calculateStaleness = exports.calculateKey = exports.calculateFeedId = exports.calculateCacheKey = void 0;
30
18
  const util_1 = require("../util");
31
- const cacheMetrics = __importStar(require("./metrics"));
19
+ __exportStar(require("./factory"), exports);
32
20
  __exportStar(require("./local"), exports);
33
21
  __exportStar(require("./redis"), exports);
34
- __exportStar(require("./factory"), exports);
35
22
  const logger = (0, util_1.makeLogger)('Cache');
36
23
  // Uses calculateKey to generate a unique key from the endpoint name, data, and input parameters
37
24
  const calculateCacheKey = ({ adapterEndpoint, adapterConfig, }, data) => {
@@ -74,10 +61,6 @@ const calculateKey = (data, paramNames, adapterConfig) => {
74
61
  const params = data;
75
62
  let cacheKey = '';
76
63
  for (const paramName of paramNames) {
77
- // Ignore overrides param when generating cache keys
78
- if (paramName === 'overrides') {
79
- continue;
80
- }
81
64
  const param = params[paramName];
82
65
  if (param === undefined) {
83
66
  continue;
@@ -104,7 +87,7 @@ const calculateKey = (data, paramNames, adapterConfig) => {
104
87
  return cacheKey;
105
88
  };
106
89
  exports.calculateKey = calculateKey;
107
- // Calculate the amount of time the non-expired entry has been in the cache
90
+ // Calculate the amount of time a non-expired entry has been in the cache
108
91
  const calculateStaleness = (expirationTimestamp, ttl) => {
109
92
  if (expirationTimestamp) {
110
93
  const createTimestamp = expirationTimestamp - ttl;
@@ -116,6 +99,7 @@ const calculateStaleness = (expirationTimestamp, ttl) => {
116
99
  return ttl;
117
100
  }
118
101
  };
102
+ exports.calculateStaleness = calculateStaleness;
119
103
  /**
120
104
  * Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
121
105
  * amount of retries is exceeded, it returns undefined instead.
@@ -146,30 +130,4 @@ const pollResponseFromCache = async (cache, key, options, retry = 0) => {
146
130
  return (0, exports.pollResponseFromCache)(cache, key, options, retry + 1);
147
131
  };
148
132
  exports.pollResponseFromCache = pollResponseFromCache;
149
- /**
150
- * Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
151
- * a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
152
- *
153
- * @param adapter - an initialized adapter
154
- * @returns the cache middleware function
155
- */
156
- const buildCacheMiddleware = (adapter) => async (req, res) => {
157
- const response = await adapter.dependencies.cache.get(req.requestContext.cacheKey);
158
- if (response) {
159
- logger.debug('Found response from cache, sending that');
160
- if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
161
- const label = cacheMetrics.cacheMetricsLabel(req.requestContext.cacheKey, req.requestContext.meta?.metrics?.feedId || 'N/A', adapter.config.CACHE_TYPE);
162
- // Record cache staleness and cache get count and value
163
- const staleness = calculateStaleness(response.maxAge, adapter.config.CACHE_MAX_AGE);
164
- cacheMetrics.cacheGet(label, response.result, staleness);
165
- req.requestContext.meta = {
166
- ...req.requestContext.meta,
167
- metrics: { ...req.requestContext.meta?.metrics, cacheHit: true },
168
- };
169
- }
170
- return res.send(response);
171
- }
172
- logger.debug('Did not find response in cache, moving to next middleware');
173
- };
174
- exports.buildCacheMiddleware = buildCacheMiddleware;
175
133
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,kCAMgB;AAChB,wDAAyC;AAEzC,0CAAuB;AACvB,0CAAuB;AACvB,4CAAyB;AAEzB,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,OAAO,CAAC,CAAA;AAoDlC,gGAAgG;AACzF,MAAM,iBAAiB,GAAG,CAC/B,EACE,eAAe,EACf,aAAa,GAId,EACD,IAAa,EACL,EAAE;IACV,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAC,KAAK,CAAC,2BAA2B,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAA;QAC1E,OAAO,aAAa,CAAC,iBAAiB,CAAA;KACvC;IACD,MAAM,QAAQ,GAAG,GAAG,eAAe,CAAC,IAAI,IAAI,IAAA,oBAAY,EAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,CAAA;IAC3F,MAAM,CAAC,KAAK,CAAC,qCAAqC,QAAQ,GAAG,CAAC,CAAA;IAC9D,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAlBY,QAAA,iBAAiB,qBAkB7B;AAEM,MAAM,eAAe,GAAG,C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C,KAAK,CAAC,CAAA;IAE1B,OAAO,IAAA,6BAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;AAC9D,CAAC,CAAA;AA/BY,QAAA,qBAAqB,yBA+BjC"}
package/cache/redis.d.ts CHANGED
@@ -1,21 +1,14 @@
1
- import Redis, { Callback } from 'ioredis';
1
+ import Redis from 'ioredis';
2
2
  import { Cache, CacheEntry } from './index';
3
- /**
4
- * Common callback for redis commands that logs success/fail and throws on fail
5
- * @param {string} message - message to log on error
6
- * @param {string} functionName - name of the redis function where this callback was used, used for metrics
7
- */
8
3
  /**
9
4
  * Redis implementation of a Cache. It uses a simple js Object, storing entries with both
10
5
  * a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
11
6
  *
12
7
  * @typeParam T - the type for the entries' values
13
- * @param {boolean} alwaysFail - if true, error callback will always throw an error (used for testing)
14
8
  */
15
9
  export declare class RedisCache<T = unknown> implements Cache<T> {
16
10
  private client;
17
11
  constructor(client: Redis);
18
- commandCallback(message: string, functionName: string): Callback;
19
12
  get(key: string): Promise<T | undefined>;
20
13
  delete(key: string): Promise<void>;
21
14
  set(key: string, value: T, ttl: number): Promise<void>;