@chainlink/external-adapter-framework 0.0.19 → 0.0.21

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 (77) hide show
  1. package/adapter.d.ts +139 -0
  2. package/background-executor.d.ts +9 -0
  3. package/background-executor.js +9 -4
  4. package/cache/factory.d.ts +6 -0
  5. package/cache/index.d.ts +94 -0
  6. package/cache/local.d.ts +23 -0
  7. package/cache/metrics.d.ts +27 -0
  8. package/cache/redis.d.ts +16 -0
  9. package/config/index.d.ts +258 -0
  10. package/config/provider-limits.d.ts +27 -0
  11. package/examples/bank-frick/accounts.d.ts +39 -0
  12. package/examples/bank-frick/config/index.d.ts +4 -0
  13. package/examples/bank-frick/index.d.ts +2 -0
  14. package/examples/bank-frick/util.d.ts +4 -0
  15. package/examples/coingecko/batch-warming.d.ts +7 -0
  16. package/examples/coingecko/index.d.ts +2 -0
  17. package/examples/coingecko/rest.d.ts +12 -0
  18. package/examples/coingecko/src/config/index.d.ts +2 -0
  19. package/examples/coingecko/src/config/index.js +1 -9
  20. package/examples/coingecko/src/config/overrides.json +0 -1
  21. package/examples/coingecko/src/cryptoUtils.d.ts +31 -0
  22. package/examples/coingecko/src/cryptoUtils.js +20 -1
  23. package/examples/coingecko/src/endpoint/coins.d.ts +9 -0
  24. package/examples/coingecko/src/endpoint/coins.js +3 -2
  25. package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +3 -0
  26. package/examples/coingecko/src/endpoint/crypto-marketcap.js +5 -22
  27. package/examples/coingecko/src/endpoint/crypto-volume.d.ts +3 -0
  28. package/examples/coingecko/src/endpoint/crypto-volume.js +5 -22
  29. package/examples/coingecko/src/endpoint/crypto.d.ts +3 -0
  30. package/examples/coingecko/src/endpoint/crypto.js +5 -25
  31. package/examples/coingecko/src/endpoint/dominance.d.ts +3 -0
  32. package/examples/coingecko/src/endpoint/dominance.js +4 -3
  33. package/examples/coingecko/src/endpoint/global-marketcap.d.ts +3 -0
  34. package/examples/coingecko/src/endpoint/global-marketcap.js +4 -3
  35. package/examples/coingecko/src/endpoint/index.d.ts +6 -0
  36. package/examples/coingecko/src/globalUtils.d.ts +27 -0
  37. package/examples/coingecko/src/globalUtils.js +6 -8
  38. package/examples/coingecko/src/index.d.ts +4 -0
  39. package/examples/coingecko/src/index.js +7 -3
  40. package/examples/coingecko-old/batch-warming.d.ts +7 -0
  41. package/examples/coingecko-old/index.d.ts +2 -0
  42. package/examples/coingecko-old/rest.d.ts +12 -0
  43. package/examples/ncfx/config/index.d.ts +12 -0
  44. package/examples/ncfx/index.d.ts +13 -0
  45. package/examples/ncfx/websocket.d.ts +47 -0
  46. package/index.d.ts +11 -0
  47. package/index.js +24 -7
  48. package/metrics/constants.d.ts +16 -0
  49. package/metrics/index.d.ts +15 -0
  50. package/metrics/index.js +7 -3
  51. package/metrics/util.d.ts +7 -0
  52. package/package.json +10 -4
  53. package/rate-limiting/background/fixed-frequency.d.ts +11 -0
  54. package/rate-limiting/index.d.ts +55 -0
  55. package/rate-limiting/metrics.d.ts +3 -0
  56. package/rate-limiting/request/simple-counting.d.ts +21 -0
  57. package/test.d.ts +1 -0
  58. package/transports/batch-warming.d.ts +35 -0
  59. package/transports/batch-warming.js +1 -1
  60. package/transports/index.d.ts +73 -0
  61. package/transports/index.js +3 -1
  62. package/transports/metrics.d.ts +22 -0
  63. package/transports/rest.d.ts +44 -0
  64. package/transports/util.d.ts +9 -0
  65. package/transports/websocket.d.ts +80 -0
  66. package/util/index.d.ts +12 -0
  67. package/util/logger.d.ts +42 -0
  68. package/util/request.d.ts +56 -0
  69. package/util/subscription-set/expiring-sorted-set.d.ts +22 -0
  70. package/util/subscription-set/subscription-set.d.ts +18 -0
  71. package/util/test-payload-loader.d.ts +25 -0
  72. package/validation/error.d.ts +50 -0
  73. package/validation/index.d.ts +5 -0
  74. package/validation/index.js +4 -2
  75. package/validation/input-params.d.ts +15 -0
  76. package/validation/override-functions.d.ts +3 -0
  77. package/validation/validator.d.ts +47 -0
package/adapter.d.ts ADDED
@@ -0,0 +1,139 @@
1
+ import { Cache } from './cache';
2
+ import { AdapterConfig, BaseAdapterConfig, CustomSettingsType, SettingsMap } from './config';
3
+ import { AdapterRateLimitTier, BackgroundExecuteRateLimiter, RequestRateLimiter } from './rate-limiting';
4
+ import { Transport } from './transports';
5
+ import { SubscriptionSetFactory } from './util';
6
+ import { InputParameters } from './validation/input-params';
7
+ /**
8
+ * Dependencies that will be injected into the Adapter on startup
9
+ */
10
+ export interface AdapterDependencies {
11
+ /** Specific instance of the Cache the adapter will use (e.g. Local, Redis, etc.) */
12
+ cache: Cache;
13
+ /** Shared instance of the request rate limiter */
14
+ requestRateLimiter: RequestRateLimiter;
15
+ /** Shared instance of the background execute rate limiter */
16
+ backgroundExecuteRateLimiter: BackgroundExecuteRateLimiter;
17
+ /** Factory to create subscription sets based on the specified cache type */
18
+ subscriptionSetFactory: SubscriptionSetFactory;
19
+ }
20
+ /**
21
+ * Context that will be used on background executions of a Transport.
22
+ * For example, the endpointName used to log statements or generate Cache keys.
23
+ */
24
+ export interface AdapterContext<CustomSettings extends CustomSettingsType<CustomSettings> = SettingsMap> {
25
+ /** Endpoint instance within the adapter that the Transport is related to */
26
+ adapterEndpoint: AdapterEndpoint<unknown, unknown, CustomSettings>;
27
+ /** Initialized config for the adapter that the Transport can access */
28
+ adapterConfig: AdapterConfig<CustomSettings>;
29
+ }
30
+ /**
31
+ * Structure to describe rate limits specs for the Adapter
32
+ */
33
+ interface AdapterRateLimitingConfig {
34
+ /** Adapter rate limits, gotten from the specific tier requested */
35
+ tiers: Record<string, AdapterRateLimitTier>;
36
+ }
37
+ /**
38
+ * Main structure of an External Adapter
39
+ */
40
+ export interface AdapterParams<CustomSettings extends SettingsMap> {
41
+ /** Name of the adapter */
42
+ name: string;
43
+ /** If present, the string that will be used for requests with no specified endpoint */
44
+ defaultEndpoint?: string;
45
+ /**
46
+ * List of [[AdapterEndpoint]]s in the adapter. This is purposefully typed any; it's the correct type in this case.
47
+ *
48
+ * When you try to create an adapter and you provide an endpoint, if these generics were set to "unknown" instead
49
+ * what would happen is that Typescript would check if the types match, and would fail to assign unknown to the
50
+ * specific Params or Result in the transport itself.
51
+ * We also can't use generics, because if we had more than one transport with different requests (very likely)
52
+ * then those new types wouldn't match with each other.
53
+ */
54
+ endpoints: AdapterEndpoint<any, any, CustomSettings>[];
55
+ /** Map of overrides to the default config values for an Adapter */
56
+ envDefaultOverrides?: Partial<BaseAdapterConfig>;
57
+ /** List of custom env vars for this particular adapter (e.g. RPC_URL) */
58
+ customSettings?: SettingsMap;
59
+ /** Configuration relevant to outbound (EA --\> DP) communication rate limiting */
60
+ rateLimiting?: AdapterRateLimitingConfig;
61
+ /** Overrides for converting the 'base' parameter that are hardcoded into the adapter. */
62
+ overrides?: Record<string, string>;
63
+ }
64
+ /**
65
+ * Structure to describe rate limits specs for a specific adapter endpoint
66
+ */
67
+ export interface EndpointRateLimitingConfig {
68
+ /**
69
+ * How much of the total limit for the adapter will be assigned to this specific endpoint.
70
+ * Should be a non-zero positive number up to 100.
71
+ * Endpoints in the same adapter without a specific allocation will divide the remaining limits equally.
72
+ */
73
+ allocationPercentage: number;
74
+ }
75
+ /**
76
+ * Structure to describe a specific endpoint in an [[Adapter]]
77
+ */
78
+ export interface AdapterEndpointParams<Params, Result, CustomSettings extends SettingsMap> {
79
+ /** Name that will be used to match input params to this endpoint (case insensitive) */
80
+ name: string;
81
+ /** List of alternative endpoint names that will resolve to this same transport (case insensitive) */
82
+ aliases?: string[];
83
+ /** Transport that will be used to handle data processing and communication for this endpoint */
84
+ transport: Transport<Params, Result, CustomSettings>;
85
+ /** Specification of what the body of a request hitting this endpoint should look like (used for validation) */
86
+ inputParameters: InputParameters;
87
+ /** Specific details related to the rate limiting for this endpoint in particular */
88
+ rateLimiting?: EndpointRateLimitingConfig;
89
+ }
90
+ export declare class AdapterEndpoint<Params, Result, CustomSettings extends SettingsMap> implements AdapterEndpointParams<Params, Result, CustomSettings> {
91
+ name: string;
92
+ aliases?: string[] | undefined;
93
+ transport: Transport<Params, Result, CustomSettings>;
94
+ inputParameters: InputParameters;
95
+ rateLimiting?: EndpointRateLimitingConfig | undefined;
96
+ constructor(params: AdapterEndpointParams<Params, Result, CustomSettings>);
97
+ }
98
+ export declare class Adapter<CustomSettings extends SettingsMap = SettingsMap> implements AdapterParams<CustomSettings> {
99
+ name: string;
100
+ defaultEndpoint?: string | undefined;
101
+ endpoints: AdapterEndpoint<unknown, unknown, CustomSettings>[];
102
+ envDefaultOverrides?: Partial<BaseAdapterConfig> | undefined;
103
+ customSettings?: SettingsMap | undefined;
104
+ rateLimiting?: AdapterRateLimitingConfig | undefined;
105
+ overrides?: Record<string, string> | undefined;
106
+ initialized: boolean;
107
+ /** Object containing alias translations for all endpoints */
108
+ endpointsMap: Record<string, AdapterEndpoint<unknown, unknown, CustomSettings>>;
109
+ /** Initialized dependencies that the adapter will use */
110
+ dependencies: AdapterDependencies;
111
+ /** Configuration params for various adapter properties */
112
+ config: AdapterConfig;
113
+ constructor(params: AdapterParams<CustomSettings>);
114
+ /**
115
+ * Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
116
+ * Additionally, it builds a map out of all the endpoint names and aliases (checking for duplicates).
117
+ */
118
+ initialize(dependencies?: Partial<AdapterDependencies>): Promise<void>;
119
+ /**
120
+ * Takes an adapter and normalizes all endpoint names and aliases, as well as the default endpoint.
121
+ * i.e. makes them lowercase for now
122
+ */
123
+ private normalizeEndpointNames;
124
+ /**
125
+ * This function will take an adapter structure and go through each endpoint, calculating
126
+ * each one's allocation of the total rate limits that are set for the adapter as a whole.
127
+ *
128
+ */
129
+ private calculateRateLimitAllocations;
130
+ /**
131
+ * This function will process dependencies for an adapter, such as caches or rate limiters,
132
+ * in order to inject them into transports and other relevant places later in the lifecycle.
133
+ *
134
+ * @param inputDependencies - a partial obj of initialized dependencies to override the created ones
135
+ * @returns a set of AdapterDependencies all initialized
136
+ */
137
+ initializeDependencies(inputDependencies?: Partial<AdapterDependencies>): AdapterDependencies;
138
+ }
139
+ export {};
@@ -0,0 +1,9 @@
1
+ import { Adapter } from './adapter';
2
+ /**
3
+ * Very simple background loop that will call the [[Transport.backgroundExecute]] functions in all Transports.
4
+ * It gets the time in ms to wait as the return value from those functions, and sleeps until next execution.
5
+ *
6
+ * @param adapter - an initialized External Adapter
7
+ * @param server - the http server to attach an on close listener to
8
+ */
9
+ export declare function callBackgroundExecutes(adapter: Adapter, apiShutdownPromise?: Promise<void>): Promise<void>;
@@ -10,12 +10,18 @@ const logger = (0, util_1.makeLogger)('BackgroundExecutor');
10
10
  * @param adapter - an initialized External Adapter
11
11
  * @param server - the http server to attach an on close listener to
12
12
  */
13
- async function callBackgroundExecutes(adapter, server) {
13
+ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
14
14
  // Set up variable to check later on to see if we need to stop this background "thread"
15
15
  // If no server is provided, the listener won't be set and serverClosed will always be false
16
16
  let serverClosed = false;
17
- server?.on('close', () => {
17
+ const timeoutsMap = {};
18
+ apiShutdownPromise?.then(() => {
18
19
  serverClosed = true;
20
+ for (const endpointName in timeoutsMap) {
21
+ logger.debug(`Clearing timeout for endpoint "${endpointName}"`);
22
+ timeoutsMap[endpointName].unref();
23
+ clearTimeout(timeoutsMap[endpointName]);
24
+ }
19
25
  });
20
26
  for (const endpoint of adapter.endpoints) {
21
27
  const backgroundExecute = endpoint.transport.backgroundExecute?.bind(endpoint.transport);
@@ -35,8 +41,7 @@ async function callBackgroundExecutes(adapter, server) {
35
41
  logger.debug(`Calling background execute for endpoint "${endpoint.name}"`);
36
42
  const timeToWait = await backgroundExecute(context);
37
43
  logger.debug(`Finished background execute for endpoint "${endpoint.name}", sleeping for ${timeToWait}ms`);
38
- await (0, util_1.sleep)(timeToWait);
39
- handler();
44
+ timeoutsMap[endpoint.name] = setTimeout(handler, timeToWait);
40
45
  };
41
46
  // Start recursive async calls
42
47
  handler();
@@ -0,0 +1,6 @@
1
+ import { AdapterConfig } from '../config';
2
+ import { LocalCache } from './local';
3
+ import { RedisCache } from './redis';
4
+ export declare class CacheFactory {
5
+ static buildCache(config: AdapterConfig): LocalCache<unknown> | RedisCache<unknown> | undefined;
6
+ }
@@ -0,0 +1,94 @@
1
+ import { AdapterEndpoint } from '../adapter';
2
+ import { AdapterConfig, SettingsMap } from '../config';
3
+ import { AdapterMiddlewareBuilder, AdapterResponse, sleep } from '../util';
4
+ export * from './local';
5
+ export * from './redis';
6
+ export * from './factory';
7
+ /**
8
+ * An object describing an entry in the cache.
9
+ * @typeParam T - the type of the entry's value
10
+ */
11
+ export interface CacheEntry<T> {
12
+ key: string;
13
+ value: T;
14
+ }
15
+ /**
16
+ * Generic interface for a local or remote Cache.
17
+ * @typeParam T - the type of the cache entries' values
18
+ */
19
+ export interface Cache<T = unknown> {
20
+ /**
21
+ * Gets an item from the Cache.
22
+ *
23
+ * @param key - the key of the desired entry for which to fetch its value
24
+ * @returns a Promise of the entry's value, or undefined if not found / expired.
25
+ */
26
+ get: (key: string) => Promise<T | undefined>;
27
+ /**
28
+ * Sets an item in the Cache.
29
+ *
30
+ * @param key - the key of the new entry
31
+ * @param value - the value of the new entry
32
+ * @param ttl - the time in milliseconds until the entry expires
33
+ * @returns an empty Promise that resolves when the entry has been set
34
+ */
35
+ set: (key: string, value: T, ttl: number) => Promise<void>;
36
+ /**
37
+ * Sets a list of items in the Cache.
38
+ *
39
+ * @param entries - a list of cache entries
40
+ * @param ttl - the time in milliseconds until the entries expire
41
+ * @returns an empty Promise that resolves when all entries have been set
42
+ */
43
+ setMany: (entries: CacheEntry<T>[], ttl: number) => Promise<void>;
44
+ /**
45
+ * Deletes the specified item from the Cache
46
+ *
47
+ * @param key - the key of the entry to be deleted
48
+ * @returns an empty Promise that resolves when the entry has been deleted
49
+ */
50
+ delete: (key: string) => Promise<void>;
51
+ }
52
+ export declare const calculateCacheKey: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
53
+ adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
54
+ adapterConfig: AdapterConfig<CustomSettings>;
55
+ }, data: unknown) => string;
56
+ export declare const calculateFeedId: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
57
+ adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
58
+ adapterConfig: AdapterConfig<CustomSettings>;
59
+ }, data: unknown) => string;
60
+ /**
61
+ * Calculates a unique key from the provided data.
62
+ *
63
+ * @param data - the request data/body, i.e. the adapter input params
64
+ * @param paramNames - the keys from adapter endpoint input parameters
65
+ * @returns the calculated unique key
66
+ *
67
+ * @example
68
+ * ```
69
+ * calculateKey({ base: 'ETH', quote: 'BTC' }, ['base','quote'])
70
+ * // equals `|base:eth|quote:btc`
71
+ * ```
72
+ */
73
+ export declare const calculateKey: <CustomSettings extends SettingsMap>(data: unknown, paramNames: string[], adapterConfig: AdapterConfig<CustomSettings>) => string;
74
+ /**
75
+ * Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
76
+ * amount of retries is exceeded, it returns undefined instead.
77
+ *
78
+ * @param cache - a Cache instance
79
+ * @param key - the key generated from an AdapterRequest that corresponds to the desired AdapterResponse
80
+ * @param retry - current retry, only for internal use
81
+ * @returns the AdapterResponse if found, else undefined
82
+ */
83
+ export declare const pollResponseFromCache: (cache: Cache<AdapterResponse>, key: string, options: {
84
+ maxRetries: number;
85
+ sleep: number;
86
+ }, 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;
@@ -0,0 +1,23 @@
1
+ import { Cache, CacheEntry } from './index';
2
+ /**
3
+ * Type for a value stored in a LocalCache entry.
4
+ *
5
+ * @typeParam T - the type for the entry's value
6
+ */
7
+ export interface LocalCacheEntry<T> {
8
+ expirationTimestamp: number;
9
+ value: T;
10
+ }
11
+ /**
12
+ * Local implementation of a Cache. It uses a simple js Object, storing entries with both
13
+ * a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
14
+ *
15
+ * @typeParam T - the type for the entries' values
16
+ */
17
+ export declare class LocalCache<T = unknown> implements Cache<T> {
18
+ store: Record<string, LocalCacheEntry<T>>;
19
+ get(key: string): Promise<T | undefined>;
20
+ delete(key: string): Promise<void>;
21
+ set(key: string, value: T, ttl: number): Promise<void>;
22
+ setMany(entries: CacheEntry<T>[], ttl: number): Promise<void>;
23
+ }
@@ -0,0 +1,27 @@
1
+ import * as client from 'prom-client';
2
+ interface CacheMetricsLabels {
3
+ participant_id: string;
4
+ feed_id: string;
5
+ cache_type: string;
6
+ }
7
+ export declare const cacheGet: (label: CacheMetricsLabels, value: unknown, staleness: number) => void;
8
+ export declare const cacheSet: (label: CacheMetricsLabels, maxAge: number) => void;
9
+ export declare const cacheMetricsLabel: (cacheKey: string, feedId: string, cacheType: string) => {
10
+ participant_id: string;
11
+ feed_id: string;
12
+ cache_type: string;
13
+ };
14
+ export declare enum CacheTypes {
15
+ Redis = "redis",
16
+ Local = "local"
17
+ }
18
+ export declare enum CMD_SENT_STATUS {
19
+ TIMEOUT = "TIMEOUT",
20
+ FAIL = "FAIL",
21
+ SUCCESS = "SUCCESS"
22
+ }
23
+ export declare const redisConnectionsOpen: client.Counter<string>;
24
+ export declare const redisRetriesCount: client.Counter<string>;
25
+ export declare const redisCommandsSentCount: client.Counter<"status" | "function_name">;
26
+ export declare const cacheWarmerCount: client.Gauge<"isBatched">;
27
+ export {};
@@ -0,0 +1,16 @@
1
+ import Redis from 'ioredis';
2
+ import { Cache, CacheEntry } from './index';
3
+ /**
4
+ * Redis implementation of a Cache. It uses a simple js Object, storing entries with both
5
+ * a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
6
+ *
7
+ * @typeParam T - the type for the entries' values
8
+ */
9
+ export declare class RedisCache<T = unknown> implements Cache<T> {
10
+ private client;
11
+ constructor(client: Redis);
12
+ get(key: string): Promise<T | undefined>;
13
+ delete(key: string): Promise<void>;
14
+ set(key: string, value: T, ttl: number): Promise<void>;
15
+ setMany(entries: CacheEntry<T>[], ttl: number): Promise<void>;
16
+ }
@@ -0,0 +1,258 @@
1
+ export declare const BaseSettings: {
2
+ readonly API_ENDPOINT: {
3
+ readonly description: "The URL that certain transports use to retrieve data";
4
+ readonly type: "string";
5
+ };
6
+ readonly API_KEY: {
7
+ readonly description: "Default setting for an EA key";
8
+ readonly type: "string";
9
+ };
10
+ readonly API_TIMEOUT: {
11
+ readonly description: "The number of milliseconds a request can be pending before returning a timeout error for data provider request";
12
+ readonly type: "number";
13
+ readonly default: 30000;
14
+ };
15
+ readonly API_VERBOSE: {
16
+ readonly description: "Toggle whether the response from the EA should contain just the results or also include the full response body from the queried API.";
17
+ readonly type: "boolean";
18
+ readonly default: false;
19
+ };
20
+ readonly BASE_URL: {
21
+ readonly description: "Starting path for the EA handler endpoint";
22
+ readonly type: "string";
23
+ readonly default: "/";
24
+ };
25
+ readonly CACHE_MAX_AGE: {
26
+ readonly description: "Maximum amount of time (in ms) that a response will stay cached";
27
+ readonly type: "number";
28
+ readonly default: 90000;
29
+ };
30
+ readonly CACHE_REDIS_HOST: {
31
+ readonly description: "Hostname for the Redis instance to be used";
32
+ readonly type: "string";
33
+ readonly default: "127.0.0.1";
34
+ };
35
+ readonly CACHE_REDIS_PASSWORD: {
36
+ readonly description: "The password required for redis auth";
37
+ readonly type: "string";
38
+ };
39
+ readonly CACHE_REDIS_PATH: {
40
+ readonly description: "The UNIX socket string of the Redis server";
41
+ readonly type: "string";
42
+ };
43
+ readonly CACHE_REDIS_PORT: {
44
+ readonly description: "Port for the Redis instance to be used";
45
+ readonly type: "number";
46
+ readonly default: 6379;
47
+ };
48
+ readonly CACHE_REDIS_TIMEOUT: {
49
+ readonly description: "Timeout to fail a Redis server request if no response (ms)";
50
+ readonly type: "number";
51
+ readonly default: 500;
52
+ };
53
+ readonly CACHE_TYPE: {
54
+ readonly description: "The type of cache to use throughout the EA";
55
+ readonly type: "enum";
56
+ readonly default: "local";
57
+ readonly options: readonly ["local", "redis"];
58
+ };
59
+ readonly CORRELATION_ID_ENABLED: {
60
+ readonly description: "Flag to enable correlation IDs for sent requests in logging";
61
+ readonly type: "boolean";
62
+ readonly default: true;
63
+ };
64
+ readonly DEBUG: {
65
+ readonly description: "Toggles debug mode";
66
+ readonly type: "boolean";
67
+ readonly default: false;
68
+ };
69
+ readonly EA_PORT: {
70
+ readonly description: "Port through which the EA will listen for REST requests (if mode is set to \"reader\" or \"reader-writer\")";
71
+ readonly type: "number";
72
+ readonly default: 8080;
73
+ };
74
+ readonly EXPERIMENTAL_METRICS_ENABLED: {
75
+ readonly description: "Flag to specify whether or not to collect metrics. Used as fallback for METRICS_ENABLED";
76
+ readonly type: "boolean";
77
+ readonly default: true;
78
+ };
79
+ readonly LOG_LEVEL: {
80
+ readonly description: "Minimum level required for logs to be output";
81
+ readonly type: "string";
82
+ readonly default: "info";
83
+ };
84
+ readonly METRICS_ENABLED: {
85
+ readonly description: "Flag to specify whether or not to startup the metrics server";
86
+ readonly type: "boolean";
87
+ readonly default: true;
88
+ };
89
+ readonly METRICS_NAME: {
90
+ readonly description: "Metrics name";
91
+ readonly type: "string";
92
+ };
93
+ readonly METRICS_PORT: {
94
+ readonly description: "Port metrics will be exposed to";
95
+ readonly type: "number";
96
+ readonly default: 9080;
97
+ };
98
+ readonly METRICS_USE_BASE_URL: {
99
+ readonly description: "Flag to specify whether or not to prepend the BASE_URL to the metrics endpoint";
100
+ readonly type: "boolean";
101
+ };
102
+ readonly RATE_LIMIT_API_TIER: {
103
+ readonly description: "Rate limiting tier to use from the available options for the adapter. If not present, the adapter will run using the first tier on the list.";
104
+ readonly type: "string";
105
+ };
106
+ readonly RATE_LIMIT_CAPACITY: {
107
+ readonly description: "Used as rate limit capacity per minute and ignores tier settings if defined";
108
+ readonly type: "number";
109
+ };
110
+ readonly RATE_LIMIT_CAPACITY_MINUTE: {
111
+ readonly description: "Used as rate limit capacity per minute and ignores tier settings if defined. Supercedes RATE_LIMIT_CAPACITY if both vars are set";
112
+ readonly type: "number";
113
+ };
114
+ readonly RATE_LIMIT_CAPACITY_SECOND: {
115
+ readonly description: "Used as rate limit capacity per second and ignores tier settings if defined";
116
+ readonly type: "number";
117
+ };
118
+ readonly REQUEST_COALESCING_ENABLED: {
119
+ readonly description: "Enable request coalescing";
120
+ readonly type: "boolean";
121
+ };
122
+ readonly WARMUP_SUBSCRIPTION_TTL: {
123
+ readonly type: "number";
124
+ readonly description: "TTL for batch warmer subscriptions";
125
+ readonly default: 10000;
126
+ };
127
+ readonly WS_SUBSCRIPTION_TTL: {
128
+ readonly description: "";
129
+ readonly type: "number";
130
+ readonly default: 120000;
131
+ };
132
+ readonly CACHE_POLLING_MAX_RETRIES: {
133
+ readonly description: "Max amount of times to attempt to find EA response in the cache after the Transport has been set up";
134
+ readonly type: "number";
135
+ readonly default: 10;
136
+ };
137
+ readonly CACHE_POLLING_SLEEP_MS: {
138
+ readonly description: "The number of ms to sleep between each retry to fetch the EA response in the cache";
139
+ readonly type: "number";
140
+ readonly default: 200;
141
+ };
142
+ readonly DEFAULT_CACHE_KEY: {
143
+ readonly description: "Default key to be used when one cannot be determined from request parameters";
144
+ readonly type: "string";
145
+ readonly default: "DEFAULT_CACHE_KEY";
146
+ };
147
+ readonly EA_HOST: {
148
+ readonly description: "Host this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
149
+ readonly type: "string";
150
+ readonly default: "::";
151
+ };
152
+ readonly EA_MODE: {
153
+ readonly description: "Port this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
154
+ readonly type: "enum";
155
+ readonly default: "reader-writer";
156
+ readonly options: readonly ["reader", "writer", "reader-writer"];
157
+ };
158
+ readonly MAX_COMMON_KEY_SIZE: {
159
+ readonly description: "Maximum amount of characters that the common part of the cache key or feed ID can have";
160
+ readonly type: "number";
161
+ readonly default: 300;
162
+ readonly validate: (value?: number) => "MAX_COMMON_KEY_SIZE must be a number between 150 and 500" | undefined;
163
+ };
164
+ readonly REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
165
+ readonly description: "Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter";
166
+ readonly type: "number";
167
+ readonly default: 3;
168
+ };
169
+ readonly REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
170
+ readonly description: "Time that the Rest Transport will wait between retries when blocked by the rate limiter";
171
+ readonly type: "number";
172
+ readonly default: 400;
173
+ };
174
+ readonly SMOKE_TEST_PAYLOAD_FILE_NAME: {
175
+ readonly description: "Name of the test payload file used for the smoke endpoint";
176
+ readonly type: "string";
177
+ };
178
+ };
179
+ export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
180
+ overrides?: Partial<BaseAdapterConfig> | undefined;
181
+ customSettings?: SettingsMap | undefined;
182
+ }) => AdapterConfig<CustomSettings>;
183
+ declare type SettingValueType = string | number | boolean;
184
+ declare type SettingType<C extends Setting> = C['type'] extends 'string' ? string : C['type'] extends 'number' ? number : C['type'] extends 'boolean' ? boolean : C['type'] extends 'enum' ? C['options'] extends readonly string[] ? C['options'][number] : never : never;
185
+ declare type BaseSettingsType = typeof BaseSettings;
186
+ export declare type Setting = {
187
+ type: 'string';
188
+ description: string;
189
+ options?: never;
190
+ default?: string;
191
+ validate?: (value?: string) => ValidationErrorMessage;
192
+ required?: false;
193
+ } | {
194
+ type: 'string';
195
+ description: string;
196
+ options?: never;
197
+ default?: string;
198
+ validate?: (value: string) => ValidationErrorMessage;
199
+ required: true;
200
+ } | {
201
+ type: 'number';
202
+ description: string;
203
+ options?: never;
204
+ default?: number;
205
+ validate?: (value?: number) => ValidationErrorMessage;
206
+ required?: false;
207
+ } | {
208
+ type: 'number';
209
+ description: string;
210
+ options?: never;
211
+ default?: number;
212
+ validate?: (value: number) => ValidationErrorMessage;
213
+ required: true;
214
+ } | {
215
+ type: 'boolean';
216
+ description: string;
217
+ options?: never;
218
+ default?: boolean;
219
+ validate?: (value?: boolean) => ValidationErrorMessage;
220
+ required?: false;
221
+ } | {
222
+ type: 'boolean';
223
+ description: string;
224
+ options?: never;
225
+ default?: boolean;
226
+ validate?: (value: boolean) => ValidationErrorMessage;
227
+ required: true;
228
+ } | {
229
+ type: 'enum';
230
+ description: string;
231
+ default?: string;
232
+ options: readonly string[];
233
+ validate?: (value?: string) => ValidationErrorMessage;
234
+ required?: false;
235
+ } | {
236
+ type: 'enum';
237
+ description: string;
238
+ default?: string;
239
+ options: readonly string[];
240
+ validate?: (value: string) => ValidationErrorMessage;
241
+ required: true;
242
+ };
243
+ export declare type AdapterConfigFromSettings<T extends SettingsMap> = {
244
+ -readonly [K in keyof T as T[K] extends {
245
+ default: SettingValueType;
246
+ } ? K : T[K]['required'] extends true ? K : never]: SettingType<T[K]>;
247
+ } & {
248
+ -readonly [K in keyof T as T[K] extends {
249
+ default: SettingValueType;
250
+ } ? never : T[K]['required'] extends true ? never : K]?: SettingType<T[K]> | undefined;
251
+ };
252
+ export declare type BaseAdapterConfig = AdapterConfigFromSettings<BaseSettingsType>;
253
+ export declare type AdapterConfig<T extends CustomSettingsType<T> = SettingsMap> = AdapterConfigFromSettings<T> & BaseAdapterConfig;
254
+ export declare type CustomSettingsType<T = SettingsMap> = Record<keyof T, Setting>;
255
+ export declare type EmptySettings = Record<string, never>;
256
+ export declare type SettingsMap = Record<string, Setting>;
257
+ export declare type ValidationErrorMessage = string | undefined;
258
+ export {};
@@ -0,0 +1,27 @@
1
+ export declare const DEFAULT_MINUTE_RATE_LIMIT = 60;
2
+ export declare const BURST_UNDEFINED_QUOTA_MULTIPLE = 2;
3
+ export declare const DEFAULT_WS_CONNECTIONS = 2;
4
+ export declare const DEFAULT_WS_SUBSCRIPTIONS = 10;
5
+ declare type RateLimitTimeFrame = 'rateLimit1s' | 'rateLimit1m' | 'rateLimit1h';
6
+ declare type HTTPTier = {
7
+ rateLimit1s?: number;
8
+ rateLimit1m?: number;
9
+ rateLimit1h?: number;
10
+ note?: string;
11
+ };
12
+ declare type WSTier = {
13
+ connections: number;
14
+ subscriptions: number;
15
+ };
16
+ export interface Limits {
17
+ http: Record<string, HTTPTier>;
18
+ ws: Record<string, WSTier>;
19
+ }
20
+ interface ProviderRateLimit {
21
+ second: number;
22
+ minute: number;
23
+ }
24
+ export declare const getHTTPLimit: (provider: string, limits: Limits, tier: string, timeframe: RateLimitTimeFrame) => number;
25
+ export declare const getRateLimit: (provider: string, limits: Limits, tier: string) => ProviderRateLimit;
26
+ export declare const getWSLimits: (provider: string, limits: Limits, tier: string) => WSTier;
27
+ export {};