@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,90 @@
1
+ import { SettingsMap, BaseAdapterConfig, AdapterConfig } from '../config';
2
+ import { AdapterRequest, AdapterResponse, Merge } from '../util';
3
+ import { AdapterEndpoint } from './endpoint';
4
+ import { AdapterDependencies, AdapterParams, AdapterRateLimitingConfig, CustomAdapterSettings, EndpointGenerics, RequestTransform } from './types';
5
+ /**
6
+ * Main class to represent an External Adapter
7
+ */
8
+ export declare class Adapter<CustomSettings extends CustomAdapterSettings = SettingsMap> implements Omit<AdapterParams<CustomSettings>, 'bootstrap'> {
9
+ name: Uppercase<string>;
10
+ defaultEndpoint?: string | undefined;
11
+ endpoints: AdapterEndpoint<Merge<EndpointGenerics, {
12
+ CustomSettings: CustomSettings;
13
+ }>>[];
14
+ envDefaultOverrides?: Partial<BaseAdapterConfig> | undefined;
15
+ customSettings?: SettingsMap | undefined;
16
+ rateLimiting?: AdapterRateLimitingConfig | undefined;
17
+ overrides?: Record<string, string> | undefined;
18
+ requestTransforms?: RequestTransform[];
19
+ initialized: boolean;
20
+ /** Object containing alias translations for all endpoints */
21
+ endpointsMap: Record<string, AdapterEndpoint<Merge<EndpointGenerics, {
22
+ CustomSettings: CustomSettings;
23
+ }>>>;
24
+ /** Initialized dependencies that the adapter will use */
25
+ dependencies: AdapterDependencies;
26
+ /** Configuration params for various adapter properties */
27
+ config: AdapterConfig<CustomSettings>;
28
+ /** Bootstrap function that will run when initializing the adapter */
29
+ private readonly bootstrap?;
30
+ constructor(params: AdapterParams<CustomSettings>);
31
+ /**
32
+ * Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
33
+ * Additionally, it builds a map out of all the endpoint names and aliases (checking for duplicates).
34
+ */
35
+ initialize(dependencies?: Partial<AdapterDependencies>): Promise<void>;
36
+ /**
37
+ * Takes an adapter and normalizes all endpoint names and aliases, as well as the default endpoint.
38
+ * i.e. makes them lowercase for now
39
+ */
40
+ private normalizeEndpointNames;
41
+ /**
42
+ * This function will take an adapter structure and go through each endpoint, calculating
43
+ * each one's allocation of the total rate limits that are set for the adapter as a whole.
44
+ *
45
+ */
46
+ private calculateRateLimitAllocations;
47
+ /**
48
+ * Creates a list of key/value pairs that need to be censored in the logs
49
+ * using the sensitive flag in the adapter config
50
+ */
51
+ private buildCensorList;
52
+ /**
53
+ * This function will process dependencies for an adapter, such as caches or rate limiters,
54
+ * in order to inject them into transports and other relevant places later in the lifecycle.
55
+ *
56
+ * @param inputDependencies - a partial obj of initialized dependencies to override the created ones
57
+ * @returns a set of AdapterDependencies all initialized
58
+ */
59
+ initializeDependencies(inputDependencies?: Partial<AdapterDependencies>): AdapterDependencies;
60
+ /**
61
+ * Attempts to find a value from the Cache and return that if found.
62
+ *
63
+ * @param req - the incoming request to this adapter
64
+ * @returns the cached value if exists
65
+ */
66
+ findResponseInCache(req: AdapterRequest): Promise<AdapterResponse | undefined>;
67
+ /**
68
+ * Default request transform that takes requests and manipulates
69
+ *
70
+ * @param adapter - the current adapter
71
+ * @param req - the current adapter request
72
+ * @returns the modified (or new) request
73
+ */
74
+ symbolOverrider(req: AdapterRequest): AdapterRequest<import("../util").RequestGenerics>;
75
+ /**
76
+ * Takes the incoming request and applies all request transforms in the adapter
77
+ *
78
+ * @param req - the current adapter request
79
+ * @returns the request after passing through all request transforms
80
+ */
81
+ runRequestTransforms(req: AdapterRequest): void;
82
+ /**
83
+ * Function to serve as middleware to pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
84
+ *
85
+ * @param req - the incoming request to this adapter
86
+ * @param replySent - a promise that resolves when the reply has already been sent
87
+ * @returns a simple Promise when it's done
88
+ */
89
+ handleRequest(req: AdapterRequest, replySent: Promise<unknown>): Promise<AdapterResponse>;
90
+ }
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Adapter = void 0;
30
+ const ioredis_1 = __importDefault(require("ioredis"));
31
+ const cache_1 = require("../cache");
32
+ const cacheMetrics = __importStar(require("../cache/metrics"));
33
+ const config_1 = require("../config");
34
+ const transportMetrics = __importStar(require("../transports/metrics"));
35
+ const rate_limiting_1 = require("../rate-limiting");
36
+ const util_1 = require("../util");
37
+ const censor_list_1 = __importDefault(require("../util/censor/censor-list"));
38
+ const error_1 = require("../validation/error");
39
+ const logger = (0, util_1.makeLogger)('Adapter');
40
+ /**
41
+ * Main class to represent an External Adapter
42
+ */
43
+ class Adapter {
44
+ constructor(params) {
45
+ // After initialization
46
+ this.initialized = false;
47
+ /** Object containing alias translations for all endpoints */
48
+ this.endpointsMap = {};
49
+ // Copy over params
50
+ this.name = params.name;
51
+ this.defaultEndpoint = params.defaultEndpoint?.toLowerCase();
52
+ this.endpoints = params.endpoints;
53
+ this.envDefaultOverrides = params.envDefaultOverrides;
54
+ this.customSettings = params.customSettings;
55
+ this.rateLimiting = params.rateLimiting;
56
+ this.overrides = params.overrides;
57
+ this.requestTransforms = [this.symbolOverrider.bind(this), ...(params.requestTransforms || [])];
58
+ this.bootstrap = params.bootstrap;
59
+ this.config = (0, config_1.buildAdapterConfig)({
60
+ overrides: this.envDefaultOverrides,
61
+ customSettings: this.customSettings,
62
+ });
63
+ this.normalizeEndpointNames();
64
+ this.calculateRateLimitAllocations();
65
+ }
66
+ /**
67
+ * Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
68
+ * Additionally, it builds a map out of all the endpoint names and aliases (checking for duplicates).
69
+ */
70
+ async initialize(dependencies) {
71
+ if (this.initialized) {
72
+ throw new Error('This adapter has already been initialized!');
73
+ }
74
+ // Building configs during initialization to avoid validation errors during construction
75
+ (0, config_1.validateAdapterConfig)(this.config, this.customSettings);
76
+ if (this.bootstrap) {
77
+ await this.bootstrap(this);
78
+ }
79
+ this.dependencies = this.initializeDependencies(dependencies);
80
+ for (const endpoint of this.endpoints) {
81
+ // Add aliases to map to use in validation
82
+ const aliases = [endpoint.name, ...(endpoint.aliases || [])];
83
+ for (const alias of aliases) {
84
+ if (this.endpointsMap[alias]) {
85
+ throw new Error(`Duplicate endpoint / alias: "${alias}"`);
86
+ }
87
+ this.endpointsMap[alias] = endpoint;
88
+ }
89
+ logger.debug(`Initializing transport for endpoint "${endpoint.name}"...`);
90
+ await endpoint.transport.initialize(this.dependencies, this.config, endpoint.name);
91
+ }
92
+ // Build list of key/values that need to be redacted in logs
93
+ // Populates the static array in CensorList to use in censor-transport
94
+ this.buildCensorList();
95
+ logger.debug('Adapter initialization complete.');
96
+ this.initialized = true;
97
+ }
98
+ /**
99
+ * Takes an adapter and normalizes all endpoint names and aliases, as well as the default endpoint.
100
+ * i.e. makes them lowercase for now
101
+ */
102
+ normalizeEndpointNames() {
103
+ for (const endpoint of this.endpoints) {
104
+ endpoint.name = endpoint.name.toLowerCase();
105
+ endpoint.aliases = endpoint.aliases?.map((a) => a.toLowerCase());
106
+ }
107
+ }
108
+ /**
109
+ * This function will take an adapter structure and go through each endpoint, calculating
110
+ * each one's allocation of the total rate limits that are set for the adapter as a whole.
111
+ *
112
+ */
113
+ calculateRateLimitAllocations() {
114
+ const numberOfEndpoints = this.endpoints.length;
115
+ const endpointsWithExplicitAllocations = this.endpoints.filter((e) => e.rateLimiting);
116
+ const totalExplicitAllocation = endpointsWithExplicitAllocations
117
+ .map((e) => e.rateLimiting?.allocationPercentage || 0)
118
+ .reduce((sum, next) => sum + next, 0);
119
+ if (totalExplicitAllocation > 100) {
120
+ throw new Error('The total allocation set for all endpoints summed cannot exceed 100%');
121
+ }
122
+ if (totalExplicitAllocation === 100 &&
123
+ numberOfEndpoints - endpointsWithExplicitAllocations.length > 0) {
124
+ throw new Error('The explicit allocation is at 100% but there are endpoints with implicit allocation');
125
+ }
126
+ const implicitAllocation = 100 - totalExplicitAllocation;
127
+ logger.debug('Adapter rate limit allocations:');
128
+ for (const endpoint of this.endpoints) {
129
+ if (!endpoint.rateLimiting) {
130
+ endpoint.rateLimiting = {
131
+ allocationPercentage: implicitAllocation / (numberOfEndpoints - endpointsWithExplicitAllocations.length),
132
+ };
133
+ }
134
+ logger.debug(`Endpoint [${endpoint.name}] - ${endpoint.rateLimiting?.allocationPercentage}%`);
135
+ }
136
+ }
137
+ /**
138
+ * Creates a list of key/value pairs that need to be censored in the logs
139
+ * using the sensitive flag in the adapter config
140
+ */
141
+ buildCensorList() {
142
+ const censorList = Object.entries(config_1.BaseSettings)
143
+ .concat(Object.entries(this.customSettings || {}))
144
+ .filter(([name, setting]) => setting &&
145
+ setting.type === 'string' &&
146
+ setting.sensitive &&
147
+ this.config[name])
148
+ .map(([name]) => ({
149
+ key: name,
150
+ // Escaping potential special characters in values before creating regex
151
+ value: new RegExp(
152
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
153
+ this.config[name].replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi'),
154
+ }));
155
+ censor_list_1.default.set(censorList);
156
+ }
157
+ /**
158
+ * This function will process dependencies for an adapter, such as caches or rate limiters,
159
+ * in order to inject them into transports and other relevant places later in the lifecycle.
160
+ *
161
+ * @param inputDependencies - a partial obj of initialized dependencies to override the created ones
162
+ * @returns a set of AdapterDependencies all initialized
163
+ */
164
+ initializeDependencies(inputDependencies) {
165
+ const dependencies = inputDependencies || {};
166
+ if (!dependencies.redisClient) {
167
+ if (this.config.CACHE_TYPE === 'redis') {
168
+ dependencies.redisClient = new ioredis_1.default({
169
+ enableAutoPipelining: true,
170
+ host: this.config.CACHE_REDIS_HOST,
171
+ port: this.config.CACHE_REDIS_PORT,
172
+ password: this.config.CACHE_REDIS_PASSWORD,
173
+ path: this.config.CACHE_REDIS_PATH,
174
+ timeout: this.config.CACHE_REDIS_TIMEOUT,
175
+ });
176
+ dependencies.redisClient.on('connect', () => {
177
+ cacheMetrics.redisConnectionsOpen.inc();
178
+ });
179
+ }
180
+ }
181
+ if (!dependencies.cache) {
182
+ dependencies.cache = cache_1.CacheFactory.buildCache(this.config.CACHE_TYPE, dependencies.redisClient);
183
+ }
184
+ const rateLimitingTier = (0, rate_limiting_1.getRateLimitingTier)(this.config, this.rateLimiting?.tiers);
185
+ if (!dependencies.requestRateLimiter) {
186
+ dependencies.requestRateLimiter = new rate_limiting_1.SimpleCountingRateLimiter().initialize(this.endpoints, rateLimitingTier);
187
+ }
188
+ if (!dependencies.backgroundExecuteRateLimiter) {
189
+ dependencies.backgroundExecuteRateLimiter = new rate_limiting_1.FixedFrequencyRateLimiter().initialize(this.endpoints, rateLimitingTier);
190
+ }
191
+ if (!dependencies.subscriptionSetFactory) {
192
+ dependencies.subscriptionSetFactory = new util_1.SubscriptionSetFactory(this.config, this.name, dependencies.redisClient);
193
+ }
194
+ return dependencies;
195
+ }
196
+ /**
197
+ * Attempts to find a value from the Cache and return that if found.
198
+ *
199
+ * @param req - the incoming request to this adapter
200
+ * @returns the cached value if exists
201
+ */
202
+ async findResponseInCache(req) {
203
+ const response = await this.dependencies.cache.get(req.requestContext.cacheKey);
204
+ if (response) {
205
+ if (this.config.METRICS_ENABLED && this.config.EXPERIMENTAL_METRICS_ENABLED) {
206
+ const label = cacheMetrics.cacheMetricsLabel(req.requestContext.cacheKey, req.requestContext.meta?.metrics?.feedId || 'N/A', this.config.CACHE_TYPE);
207
+ // Record cache staleness and cache get count and value
208
+ const staleness = (0, cache_1.calculateStaleness)(response.maxAge, this.config.CACHE_MAX_AGE);
209
+ cacheMetrics.cacheGet(label, response.result, staleness);
210
+ req.requestContext.meta = {
211
+ ...req.requestContext.meta,
212
+ metrics: { ...req.requestContext.meta?.metrics, cacheHit: true },
213
+ };
214
+ }
215
+ return response;
216
+ }
217
+ }
218
+ /**
219
+ * Default request transform that takes requests and manipulates
220
+ *
221
+ * @param adapter - the current adapter
222
+ * @param req - the current adapter request
223
+ * @returns the modified (or new) request
224
+ */
225
+ symbolOverrider(req) {
226
+ const rawRequestBody = req.body;
227
+ const requestOverrides = rawRequestBody.data?.overrides?.[this.name.toLowerCase()];
228
+ const base = req.requestContext.data['base'];
229
+ // Perform overrides specified in the request payload
230
+ if (requestOverrides?.[base]) {
231
+ req.requestContext.data['base'] = requestOverrides[base];
232
+ }
233
+ // Perform hardcoded adapter overrides
234
+ if (this.overrides?.[base]) {
235
+ req.requestContext.data['base'] = this.overrides[base];
236
+ }
237
+ return req;
238
+ }
239
+ /**
240
+ * Takes the incoming request and applies all request transforms in the adapter
241
+ *
242
+ * @param req - the current adapter request
243
+ * @returns the request after passing through all request transforms
244
+ */
245
+ runRequestTransforms(req) {
246
+ if (!this.requestTransforms) {
247
+ return;
248
+ }
249
+ for (const transform of this.requestTransforms) {
250
+ transform(req);
251
+ }
252
+ }
253
+ /**
254
+ * Function to serve as middleware to pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
255
+ *
256
+ * @param req - the incoming request to this adapter
257
+ * @param replySent - a promise that resolves when the reply has already been sent
258
+ * @returns a simple Promise when it's done
259
+ */
260
+ async handleRequest(req, replySent) {
261
+ // Get transport, must be here because it's already checked in the validator
262
+ const transport = this.endpointsMap[req.requestContext.endpointName].transport;
263
+ // First try to find the response in our cache, keep it ready
264
+ const cachedResponse = await this.findResponseInCache(req);
265
+ // Next we fire off the transport's registration of the request if defined, regardless of if we already have a cached response.
266
+ // This is necessary to ensure things like subscription sets are updated each time we get a request
267
+ let requestRegistrationPromise;
268
+ if (transport.registerRequest) {
269
+ const handler = async () => {
270
+ // If we already have a cached response, wait for it to be sent back before continuing with registration
271
+ // This way we respond to incoming requests from the cache as fast as possible
272
+ if (cachedResponse) {
273
+ await replySent;
274
+ }
275
+ // Disable the non-null assertion error, since we're checking this exists in the if above
276
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
277
+ return transport.registerRequest(req, this.config);
278
+ };
279
+ // Execute the registration handler without blocking
280
+ logger.debug(`Firing request registration handler${cachedResponse ? ' (cached response already sent)' : ''}`);
281
+ requestRegistrationPromise = handler();
282
+ }
283
+ // Now that we have dealt with request registration, we can return the cached response if present
284
+ if (cachedResponse) {
285
+ logger.debug('Found response from cache, sending that');
286
+ return cachedResponse;
287
+ }
288
+ // If there was no cached response, execute the foregroundExecute if defined
289
+ const immediateResponse = transport.foregroundExecute && (await transport.foregroundExecute(req, this.config));
290
+ if (immediateResponse) {
291
+ logger.debug('Got immediate response from transport, sending as response');
292
+ return immediateResponse;
293
+ }
294
+ // Finally, either because there was no synchronous execute or because it returned an empty response,
295
+ // we wait for the cache to be filled (either from background work started in the sync execute, or the backgroundExecute).
296
+ // We can wait for the request registration to have finished here, since we're going to be sleeping for the cache anyways,
297
+ // and it's useful in case the registration throws a promise so that it doesn't go unhandled.
298
+ await requestRegistrationPromise;
299
+ // Observe the idle time taken for polling response
300
+ const metricsTimer = transportMetrics.transportPollingDurationSeconds
301
+ .labels({ endpoint: req.requestContext.endpointName })
302
+ .startTimer();
303
+ logger.debug('Transport is set up, polling cache for response...');
304
+ const response = await (0, cache_1.pollResponseFromCache)(this.dependencies.cache, req.requestContext.cacheKey, {
305
+ maxRetries: this.config.CACHE_POLLING_MAX_RETRIES,
306
+ sleep: this.config.CACHE_POLLING_SLEEP_MS,
307
+ });
308
+ metricsTimer({ succeeded: String(!!response) });
309
+ if (response) {
310
+ logger.debug('Got a response from polling the cache, sending that back');
311
+ return response;
312
+ }
313
+ // Record polling mechanism failure to return response
314
+ transportMetrics.transportPollingFailureCount
315
+ .labels({ endpoint: req.requestContext.endpointName })
316
+ .inc();
317
+ logger.debug('Ran out of polling attempts, returning timeout');
318
+ throw new error_1.AdapterTimeoutError({
319
+ message: 'Timed out waiting for provider result.',
320
+ statusCode: 504,
321
+ });
322
+ }
323
+ }
324
+ exports.Adapter = Adapter;
325
+ //# sourceMappingURL=basic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.js","sourceRoot":"","sources":["../../../src/adapter/basic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA2B;AAC3B,oCAAyF;AACzF,+DAAgD;AAChD,sCAOkB;AAClB,wEAAyD;AACzD,oDAIyB;AACzB,kCAAoG;AACpG,6EAAuE;AAWvE,+CAAyD;AAEzD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,SAAS,CAAC,CAAA;AAEpC;;GAEG;AACH,MAAa,OAAO;IA+BlB,YAAY,MAAqC;QAlBjD,uBAAuB;QACvB,gBAAW,GAAG,KAAK,CAAA;QAEnB,6DAA6D;QAC7D,iBAAY,GAGR,EAAE,CAAA;QAYJ,mBAAmB;QACnB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACvB,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eA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../validation';
3
+ import { InputValidator } from '../validation/input-validator';
4
+ import { AdapterEndpointParams, EndpointGenerics, EndpointRateLimitingConfig } from './types';
5
+ /**
6
+ * Main class to represent an endpoint within an External Adapter
7
+ */
8
+ export declare class AdapterEndpoint<T extends EndpointGenerics> implements AdapterEndpointParams<T> {
9
+ name: string;
10
+ aliases?: string[] | undefined;
11
+ transport: Transport<T> | MetaTransport<T>;
12
+ inputParameters: InputParameters;
13
+ rateLimiting?: EndpointRateLimitingConfig | undefined;
14
+ validator: InputValidator;
15
+ cacheKeyGenerator?: (data: Record<string, unknown>) => string;
16
+ constructor(params: AdapterEndpointParams<T>);
17
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdapterEndpoint = void 0;
4
+ const input_validator_1 = require("../validation/input-validator");
5
+ /**
6
+ * Main class to represent an endpoint within an External Adapter
7
+ */
8
+ class AdapterEndpoint {
9
+ constructor(params) {
10
+ this.name = params.name;
11
+ this.aliases = params.aliases;
12
+ this.transport = params.transport;
13
+ this.inputParameters = params.inputParameters;
14
+ this.rateLimiting = params.rateLimiting;
15
+ this.validator = new input_validator_1.InputValidator(this.inputParameters);
16
+ this.cacheKeyGenerator = params.cacheKeyGenerator;
17
+ }
18
+ }
19
+ exports.AdapterEndpoint = AdapterEndpoint;
20
+ //# sourceMappingURL=endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../../src/adapter/endpoint.ts"],"names":[],"mappings":";;;AAEA,mEAA8D;AAG9D;;GAEG;AACH,MAAa,eAAe;IAS1B,YAAY,MAAgC;QAC1C,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAA;QAC7C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAA;QACvC,IAAI,CAAC,SAAS,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QACzD,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAA;IACnD,CAAC;CACF;AAlBD,0CAkBC"}
@@ -0,0 +1,4 @@
1
+ export * from './basic';
2
+ export * from './price';
3
+ export * from './endpoint';
4
+ export * from './types';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./basic"), exports);
18
+ __exportStar(require("./price"), exports);
19
+ __exportStar(require("./endpoint"), exports);
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapter/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,0CAAuB;AACvB,6CAA0B;AAC1B,0CAAuB"}
@@ -0,0 +1,77 @@
1
+ import { SettingsMap } from '../config';
2
+ import { AdapterRequest, AdapterRequestContext, AdapterResponse, RequestGenerics } from '../util';
3
+ import { AdapterEndpoint } from './endpoint';
4
+ import { Adapter, AdapterEndpointParams, AdapterParams, EndpointGenerics } from './index';
5
+ /**
6
+ * Type for the base input parameter config that any [[PriceEndpoint]] must extend
7
+ */
8
+ export declare type PriceEndpointInputParameters = {
9
+ base: {
10
+ aliases: readonly ['from', 'coin', ...string[]];
11
+ type: 'string';
12
+ description: 'The symbol of symbols of the currency to query';
13
+ required: boolean;
14
+ };
15
+ quote: {
16
+ aliases: readonly ['to', 'market', ...string[]];
17
+ type: 'string';
18
+ description: 'The symbol of the currency to convert to';
19
+ required: boolean;
20
+ };
21
+ };
22
+ /**
23
+ * Base input parameter config that any [[PriceEndpoint]] must extend
24
+ */
25
+ export declare const priceEndpointInputParameters: PriceEndpointInputParameters;
26
+ /**
27
+ * Type for base input params for a PriceEndpoint
28
+ */
29
+ export declare type PriceEndpointParams = {
30
+ base: string;
31
+ quote: string;
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>>;
49
+ /**
50
+ * A PriceEndpoint is a specific type of AdapterEndpoint. Meant to comply with standard practices for
51
+ * Data Feeds, its InputParameters must extend the basic ones (base/quote).
52
+ */
53
+ export declare class PriceEndpoint<T extends EndpointGenerics> extends AdapterEndpoint<T> {
54
+ constructor(params: AdapterEndpointParams<T> & {
55
+ inputParameters: PriceEndpointInputParameters;
56
+ });
57
+ }
58
+ declare type PriceAdapterRequest<T extends RequestGenerics> = AdapterRequest<T> & {
59
+ requestContext: AdapterRequestContext<T> & {
60
+ priceMeta: {
61
+ inverse: boolean;
62
+ };
63
+ };
64
+ };
65
+ /**
66
+ * A PriceAdapter is a specific kind of Adapter that includes at least one PriceEnpoint.
67
+ */
68
+ export declare class PriceAdapter<CustomSettings extends SettingsMap> extends Adapter<CustomSettings> {
69
+ includesMap?: IncludesMap;
70
+ constructor(params: AdapterParams<CustomSettings> & {
71
+ includes?: IncludesFile;
72
+ });
73
+ handleRequest(req: PriceAdapterRequest<{
74
+ Params: PriceEndpointParams;
75
+ }>, replySent: Promise<unknown>): Promise<AdapterResponse>;
76
+ }
77
+ export {};