@chainlink/external-adapter-framework 0.3.7 → 0.4.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 (210) hide show
  1. package/README.md +102 -0
  2. package/package.json +42 -50
  3. package/adapter/basic.d.ts +0 -86
  4. package/adapter/basic.js +0 -323
  5. package/adapter/basic.js.map +0 -1
  6. package/adapter/endpoint.d.ts +0 -17
  7. package/adapter/endpoint.js +0 -19
  8. package/adapter/endpoint.js.map +0 -1
  9. package/adapter/index.d.ts +0 -4
  10. package/adapter/index.js +0 -21
  11. package/adapter/index.js.map +0 -1
  12. package/adapter/price.d.ts +0 -75
  13. package/adapter/price.js +0 -88
  14. package/adapter/price.js.map +0 -1
  15. package/adapter/types.d.ts +0 -118
  16. package/adapter/types.js +0 -3
  17. package/adapter/types.js.map +0 -1
  18. package/background-executor.d.ts +0 -9
  19. package/background-executor.js +0 -97
  20. package/background-executor.js.map +0 -1
  21. package/cache/factory.d.ts +0 -6
  22. package/cache/factory.js +0 -24
  23. package/cache/factory.js.map +0 -1
  24. package/cache/index.d.ts +0 -87
  25. package/cache/index.js +0 -133
  26. package/cache/index.js.map +0 -1
  27. package/cache/local.d.ts +0 -23
  28. package/cache/local.js +0 -84
  29. package/cache/local.js.map +0 -1
  30. package/cache/metrics.d.ts +0 -27
  31. package/cache/metrics.js +0 -121
  32. package/cache/metrics.js.map +0 -1
  33. package/cache/redis.d.ts +0 -16
  34. package/cache/redis.js +0 -101
  35. package/cache/redis.js.map +0 -1
  36. package/config/index.d.ts +0 -297
  37. package/config/index.js +0 -353
  38. package/config/index.js.map +0 -1
  39. package/config/provider-limits.d.ts +0 -27
  40. package/config/provider-limits.js +0 -75
  41. package/config/provider-limits.js.map +0 -1
  42. package/examples/bank-frick/accounts.d.ts +0 -52
  43. package/examples/bank-frick/accounts.js +0 -190
  44. package/examples/bank-frick/accounts.js.map +0 -1
  45. package/examples/bank-frick/config/index.d.ts +0 -17
  46. package/examples/bank-frick/config/index.js +0 -55
  47. package/examples/bank-frick/config/index.js.map +0 -1
  48. package/examples/bank-frick/index.d.ts +0 -16
  49. package/examples/bank-frick/index.js +0 -16
  50. package/examples/bank-frick/index.js.map +0 -1
  51. package/examples/bank-frick/util.d.ts +0 -4
  52. package/examples/bank-frick/util.js +0 -40
  53. package/examples/bank-frick/util.js.map +0 -1
  54. package/examples/coingecko/src/config/index.d.ts +0 -2
  55. package/examples/coingecko/src/config/index.js +0 -6
  56. package/examples/coingecko/src/config/index.js.map +0 -1
  57. package/examples/coingecko/src/config/overrides.json +0 -10825
  58. package/examples/coingecko/src/crypto-utils.d.ts +0 -48
  59. package/examples/coingecko/src/crypto-utils.js +0 -60
  60. package/examples/coingecko/src/crypto-utils.js.map +0 -1
  61. package/examples/coingecko/src/endpoint/coins.d.ts +0 -9
  62. package/examples/coingecko/src/endpoint/coins.js +0 -37
  63. package/examples/coingecko/src/endpoint/coins.js.map +0 -1
  64. package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +0 -3
  65. package/examples/coingecko/src/endpoint/crypto-marketcap.js +0 -30
  66. package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +0 -1
  67. package/examples/coingecko/src/endpoint/crypto-volume.d.ts +0 -3
  68. package/examples/coingecko/src/endpoint/crypto-volume.js +0 -30
  69. package/examples/coingecko/src/endpoint/crypto-volume.js.map +0 -1
  70. package/examples/coingecko/src/endpoint/crypto.d.ts +0 -2
  71. package/examples/coingecko/src/endpoint/crypto.js +0 -28
  72. package/examples/coingecko/src/endpoint/crypto.js.map +0 -1
  73. package/examples/coingecko/src/endpoint/dominance.d.ts +0 -3
  74. package/examples/coingecko/src/endpoint/dominance.js +0 -28
  75. package/examples/coingecko/src/endpoint/dominance.js.map +0 -1
  76. package/examples/coingecko/src/endpoint/global-marketcap.d.ts +0 -3
  77. package/examples/coingecko/src/endpoint/global-marketcap.js +0 -28
  78. package/examples/coingecko/src/endpoint/global-marketcap.js.map +0 -1
  79. package/examples/coingecko/src/endpoint/index.d.ts +0 -6
  80. package/examples/coingecko/src/endpoint/index.js +0 -16
  81. package/examples/coingecko/src/endpoint/index.js.map +0 -1
  82. package/examples/coingecko/src/global-utils.d.ts +0 -27
  83. package/examples/coingecko/src/global-utils.js +0 -47
  84. package/examples/coingecko/src/global-utils.js.map +0 -1
  85. package/examples/coingecko/src/index.d.ts +0 -4
  86. package/examples/coingecko/src/index.js +0 -19
  87. package/examples/coingecko/src/index.js.map +0 -1
  88. package/examples/coingecko-old/batch-warming.d.ts +0 -7
  89. package/examples/coingecko-old/batch-warming.js +0 -54
  90. package/examples/coingecko-old/batch-warming.js.map +0 -1
  91. package/examples/coingecko-old/index.d.ts +0 -2
  92. package/examples/coingecko-old/index.js +0 -12
  93. package/examples/coingecko-old/index.js.map +0 -1
  94. package/examples/coingecko-old/rest.d.ts +0 -12
  95. package/examples/coingecko-old/rest.js +0 -55
  96. package/examples/coingecko-old/rest.js.map +0 -1
  97. package/examples/cryptocompare/src/config/index.d.ts +0 -2
  98. package/examples/cryptocompare/src/config/index.js +0 -6
  99. package/examples/cryptocompare/src/config/index.js.map +0 -1
  100. package/examples/cryptocompare/src/endpoints/crypto.d.ts +0 -28
  101. package/examples/cryptocompare/src/endpoints/crypto.js +0 -54
  102. package/examples/cryptocompare/src/endpoints/crypto.js.map +0 -1
  103. package/examples/cryptocompare/src/endpoints/index.d.ts +0 -1
  104. package/examples/cryptocompare/src/endpoints/index.js +0 -6
  105. package/examples/cryptocompare/src/endpoints/index.js.map +0 -1
  106. package/examples/cryptocompare/src/index.d.ts +0 -4
  107. package/examples/cryptocompare/src/index.js +0 -14
  108. package/examples/cryptocompare/src/index.js.map +0 -1
  109. package/examples/genesis/config/index.d.ts +0 -7
  110. package/examples/genesis/config/index.js +0 -11
  111. package/examples/genesis/config/index.js.map +0 -1
  112. package/examples/genesis/index.d.ts +0 -2
  113. package/examples/genesis/index.js +0 -13
  114. package/examples/genesis/index.js.map +0 -1
  115. package/examples/genesis/sseStream.d.ts +0 -16
  116. package/examples/genesis/sseStream.js +0 -149
  117. package/examples/genesis/sseStream.js.map +0 -1
  118. package/examples/ncfx/config/index.d.ts +0 -12
  119. package/examples/ncfx/config/index.js +0 -16
  120. package/examples/ncfx/config/index.js.map +0 -1
  121. package/examples/ncfx/index.d.ts +0 -13
  122. package/examples/ncfx/index.js +0 -12
  123. package/examples/ncfx/index.js.map +0 -1
  124. package/examples/ncfx/websocket.d.ts +0 -47
  125. package/examples/ncfx/websocket.js +0 -74
  126. package/examples/ncfx/websocket.js.map +0 -1
  127. package/index.d.ts +0 -17
  128. package/index.js +0 -174
  129. package/index.js.map +0 -1
  130. package/metrics/constants.d.ts +0 -16
  131. package/metrics/constants.js +0 -26
  132. package/metrics/constants.js.map +0 -1
  133. package/metrics/index.d.ts +0 -19
  134. package/metrics/index.js +0 -139
  135. package/metrics/index.js.map +0 -1
  136. package/metrics/util.d.ts +0 -7
  137. package/metrics/util.js +0 -10
  138. package/metrics/util.js.map +0 -1
  139. package/rate-limiting/background/fixed-frequency.d.ts +0 -11
  140. package/rate-limiting/background/fixed-frequency.js +0 -36
  141. package/rate-limiting/background/fixed-frequency.js.map +0 -1
  142. package/rate-limiting/index.d.ts +0 -56
  143. package/rate-limiting/index.js +0 -86
  144. package/rate-limiting/index.js.map +0 -1
  145. package/rate-limiting/metrics.d.ts +0 -3
  146. package/rate-limiting/metrics.js +0 -45
  147. package/rate-limiting/metrics.js.map +0 -1
  148. package/rate-limiting/request/simple-counting.d.ts +0 -21
  149. package/rate-limiting/request/simple-counting.js +0 -63
  150. package/rate-limiting/request/simple-counting.js.map +0 -1
  151. package/transports/batch-warming.d.ts +0 -35
  152. package/transports/batch-warming.js +0 -138
  153. package/transports/batch-warming.js.map +0 -1
  154. package/transports/index.d.ts +0 -87
  155. package/transports/index.js +0 -56
  156. package/transports/index.js.map +0 -1
  157. package/transports/metrics.d.ts +0 -25
  158. package/transports/metrics.js +0 -122
  159. package/transports/metrics.js.map +0 -1
  160. package/transports/rest.d.ts +0 -51
  161. package/transports/rest.js +0 -133
  162. package/transports/rest.js.map +0 -1
  163. package/transports/routing.d.ts +0 -23
  164. package/transports/routing.js +0 -52
  165. package/transports/routing.js.map +0 -1
  166. package/transports/sse.d.ts +0 -40
  167. package/transports/sse.js +0 -92
  168. package/transports/sse.js.map +0 -1
  169. package/transports/util.d.ts +0 -9
  170. package/transports/util.js +0 -87
  171. package/transports/util.js.map +0 -1
  172. package/transports/websocket.d.ts +0 -81
  173. package/transports/websocket.js +0 -165
  174. package/transports/websocket.js.map +0 -1
  175. package/util/censor/censor-list.d.ts +0 -9
  176. package/util/censor/censor-list.js +0 -13
  177. package/util/censor/censor-list.js.map +0 -1
  178. package/util/index.d.ts +0 -13
  179. package/util/index.js +0 -38
  180. package/util/index.js.map +0 -1
  181. package/util/logger.d.ts +0 -49
  182. package/util/logger.js +0 -123
  183. package/util/logger.js.map +0 -1
  184. package/util/request.d.ts +0 -102
  185. package/util/request.js +0 -3
  186. package/util/request.js.map +0 -1
  187. package/util/subscription-set/expiring-sorted-set.d.ts +0 -21
  188. package/util/subscription-set/expiring-sorted-set.js +0 -36
  189. package/util/subscription-set/expiring-sorted-set.js.map +0 -1
  190. package/util/subscription-set/redis-sorted-set.d.ts +0 -9
  191. package/util/subscription-set/redis-sorted-set.js +0 -29
  192. package/util/subscription-set/redis-sorted-set.js.map +0 -1
  193. package/util/subscription-set/subscription-set.d.ts +0 -19
  194. package/util/subscription-set/subscription-set.js +0 -28
  195. package/util/subscription-set/subscription-set.js.map +0 -1
  196. package/util/test-payload-loader.d.ts +0 -26
  197. package/util/test-payload-loader.js +0 -85
  198. package/util/test-payload-loader.js.map +0 -1
  199. package/validation/error.d.ts +0 -48
  200. package/validation/error.js +0 -78
  201. package/validation/error.js.map +0 -1
  202. package/validation/index.d.ts +0 -5
  203. package/validation/index.js +0 -91
  204. package/validation/index.js.map +0 -1
  205. package/validation/input-params.d.ts +0 -14
  206. package/validation/input-params.js +0 -3
  207. package/validation/input-params.js.map +0 -1
  208. package/validation/input-validator.d.ts +0 -16
  209. package/validation/input-validator.js +0 -123
  210. package/validation/input-validator.js.map +0 -1
@@ -1,51 +0,0 @@
1
- import { AdapterRequest, AdapterResponse } from '../util/request';
2
- import { Transport } from './';
3
- import { Cache } from '../cache';
4
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
5
- import { AdapterConfig, SettingsMap } from '../config';
6
- import { RequestRateLimiter } from '../rate-limiting';
7
- import { AdapterDependencies } from '../adapter';
8
- export { AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse };
9
- /**
10
- * Transport implementation that takes incoming requests, transforms them into a DataProvider request,
11
- * and executes that request returning the response immediately from the `setup` function.
12
- * Optionally, setting the `coalescing` option to `true` will make it so once a request is in flight,
13
- * new adapter requests for the same feed will not trigger a new one, but return an empty promise from
14
- * the setup instead so the normal cache polling mechanism is used.
15
- *
16
- * @typeParam AdapterParams - interface for the adapter request body
17
- * @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
18
- * @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
19
- */
20
- export declare class RestTransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
21
- protected config: {
22
- prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
23
- parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
24
- options: {
25
- requestCoalescing: {
26
- enabled: boolean;
27
- entropyMax?: number;
28
- };
29
- };
30
- };
31
- inFlightPrefix: string;
32
- cache: Cache<AdapterResponse<ProviderResponseBody>>;
33
- inFlightCache: Cache<boolean>;
34
- rateLimiter: RequestRateLimiter;
35
- constructor(config: {
36
- prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
37
- parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
38
- options: {
39
- requestCoalescing: {
40
- enabled: boolean;
41
- entropyMax?: number;
42
- };
43
- };
44
- });
45
- initialize(dependencies: AdapterDependencies, config: AdapterConfig<CustomSettings>): Promise<void>;
46
- protected waitUntilUnderRateLimit(options: {
47
- maxRetries: number;
48
- msBetweenRetries: number;
49
- }, retry?: number): Promise<void>;
50
- foregroundExecute(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<AdapterResponse<ProviderResponseBody> | undefined>;
51
- }
@@ -1,133 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.RestTransport = void 0;
27
- const util_1 = require("../util");
28
- const error_1 = require("../validation/error");
29
- const util_2 = require("./util");
30
- const rateLimitMetrics = __importStar(require("../rate-limiting/metrics"));
31
- const IN_FLIGHT_PREFIX = 'InFlight';
32
- const logger = (0, util_1.makeLogger)('RestTransport');
33
- /**
34
- * Transport implementation that takes incoming requests, transforms them into a DataProvider request,
35
- * and executes that request returning the response immediately from the `setup` function.
36
- * Optionally, setting the `coalescing` option to `true` will make it so once a request is in flight,
37
- * new adapter requests for the same feed will not trigger a new one, but return an empty promise from
38
- * the setup instead so the normal cache polling mechanism is used.
39
- *
40
- * @typeParam AdapterParams - interface for the adapter request body
41
- * @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
42
- * @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
43
- */
44
- class RestTransport {
45
- constructor(config) {
46
- this.config = config;
47
- }
48
- async initialize(dependencies, config) {
49
- this.inFlightPrefix = `${IN_FLIGHT_PREFIX}-`;
50
- this.cache = dependencies.cache;
51
- this.inFlightCache = dependencies.cache;
52
- this.rateLimiter = dependencies.requestRateLimiter;
53
- // Allow enabling/disabling request coalescing through env var
54
- this.config.options.requestCoalescing.enabled = config.REQUEST_COALESCING_ENABLED;
55
- this.config.options.requestCoalescing.entropyMax = config.REQUEST_COALESCING_ENTROPY_MAX;
56
- }
57
- async waitUntilUnderRateLimit(options, retry = 0) {
58
- if (this.rateLimiter.isUnderLimits()) {
59
- logger.trace('Incoming request would not be under limits, moving on');
60
- return;
61
- }
62
- if (retry >= options.maxRetries) {
63
- throw new error_1.AdapterError({
64
- statusCode: 504,
65
- message: `REST Transport timed out while waiting for rate limit availability (max retries: ${options.maxRetries})`,
66
- });
67
- }
68
- logger.debug(`Request would be over rate limits, sleeping for ${options.msBetweenRetries}`);
69
- await (0, util_1.sleep)(options.msBetweenRetries);
70
- await this.waitUntilUnderRateLimit(options, retry + 1);
71
- }
72
- async foregroundExecute(req, config) {
73
- // Add some entropy here because of possible scenario where the key won't be set before multiple
74
- // other instances in a burst request try to access the coalescing key.
75
- const randomMs = Math.random() * (this.config.options.requestCoalescing.entropyMax || 0);
76
- await (0, util_1.sleep)(randomMs);
77
- // Check if request is in flight if coalescing is enabled
78
- const inFlight = this.config.options.requestCoalescing.enabled &&
79
- (await this.cache.get(this.inFlightPrefix + req.requestContext.cacheKey));
80
- if (inFlight) {
81
- logger.debug('Request is in flight, transport has been set up');
82
- return;
83
- }
84
- else if (this.config.options.requestCoalescing.enabled) {
85
- // If it wasn't in flight and coalescing is disabled, register it as in flight
86
- const ttl = config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES *
87
- config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES;
88
- logger.debug('Setting up rest transport, setting request in flight in cache');
89
- await this.inFlightCache.set(this.inFlightPrefix + req.requestContext.cacheKey, true, ttl + 100); // Can't use Infinity for things like Redis
90
- }
91
- const request = await this.config.prepareRequest(req, config);
92
- logger.trace('Check if we are under rate limits to perform request');
93
- await this.waitUntilUnderRateLimit({
94
- maxRetries: config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES,
95
- msBetweenRetries: config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES,
96
- });
97
- logger.trace('Sending request to data provider...');
98
- const providerResponse = await (0, util_2.axiosRequest)(request, config);
99
- logger.debug(`Got response from provider, parsing (raw body: ${providerResponse.data})`);
100
- const parsedResponse = await this.config.parseResponse(req, providerResponse, config);
101
- if (config.API_VERBOSE) {
102
- parsedResponse.data = providerResponse.data;
103
- }
104
- if (config.METRICS_ENABLED && config.EXPERIMENTAL_METRICS_ENABLED) {
105
- parsedResponse.maxAge = Date.now() + config.CACHE_MAX_AGE;
106
- parsedResponse.meta = {
107
- metrics: { feedId: req.requestContext.meta?.metrics?.feedId || 'N/A' },
108
- };
109
- }
110
- logger.debug('Setting provider response in cache');
111
- await this.cache.set(req.requestContext.cacheKey, parsedResponse, config.CACHE_MAX_AGE);
112
- // Record cost of data provider call
113
- const cost = rateLimitMetrics.retrieveCost(providerResponse.data);
114
- rateLimitMetrics.rateLimitCreditsSpentTotal
115
- .labels({
116
- feed_id: req.requestContext.meta?.metrics?.feedId || 'N/A',
117
- participant_id: req.requestContext.cacheKey,
118
- })
119
- .inc(cost);
120
- // Update cacheHit flag in request meta for metrics use
121
- req.requestContext.meta = {
122
- ...req.requestContext.meta,
123
- metrics: { ...req.requestContext.meta?.metrics, cacheHit: false },
124
- };
125
- if (this.config.options.requestCoalescing.enabled) {
126
- logger.debug('Set provider response in cache, removing in flight from cache');
127
- await this.cache.delete(this.inFlightPrefix);
128
- }
129
- return parsedResponse;
130
- }
131
- }
132
- exports.RestTransport = RestTransport;
133
- //# sourceMappingURL=rest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../src/transports/rest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCAA2C;AAG3C,+CAAkD;AAClD,iCAAqC;AACrC,2EAA4D;AAK5D,MAAM,gBAAgB,GAAG,UAAU,CAAA;AAEnC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,eAAe,CAAC,CAAA;AAE1C;;;;;;;;;;GAUG;AACH,MAAa,aAAa;IAYxB,YACY,MAkBT;QAlBS,WAAM,GAAN,MAAM,CAkBf;IACA,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,MAAqC;QAErC,IAAI,CAAC,cAAc,GAAG,GAAG,gBAAgB,GAAG,CAAA;QAC5C,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAAqD,CAAA;QAC/E,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC,KAAuB,CAAA;QACzD,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,kBAAkB,CAAA;QAElD,8DAA8D;QAC9D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,GAAG,MAAM,CAAC,0BAA0B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+0,0 @@
1
- import { AdapterRequest, AdapterResponse } from '../util/request';
2
- import { MetaTransport, Transport } from './';
3
- import { AdapterConfig, SettingsMap } from '../config';
4
- import { AdapterDependencies } from '../adapter';
5
- /**
6
- * Transport implementation that takes 2 or more transports and a function that determines with transport to use.
7
- *
8
- * @typeParam AdapterParams - interface for the adapter request body
9
- * @typeParam AdapterResult - interface for the adapter's response body
10
- * @typeParam CustomSettings - interface for the adapter's custom settings.
11
- */
12
- export declare class RoutingTransport<AdapterParams, AdapterResult, CustomSettings extends SettingsMap> implements MetaTransport<AdapterParams, AdapterResult, CustomSettings> {
13
- transports: {
14
- [key: string]: Transport<unknown, unknown, CustomSettings>;
15
- };
16
- private route;
17
- constructor(transports: {
18
- [key: string]: Transport<unknown, unknown, CustomSettings>;
19
- }, route: (req: AdapterRequest<AdapterParams>, adapterConfig?: AdapterConfig<CustomSettings>) => string);
20
- initialize(dependencies: AdapterDependencies, adapterConfig: AdapterConfig<CustomSettings>, endpointName: string): Promise<void>;
21
- private resolveTransport;
22
- foregroundExecute(req: AdapterRequest<AdapterParams>, adapterConfig: AdapterConfig<CustomSettings>): Promise<AdapterResponse<any> | void>;
23
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoutingTransport = void 0;
4
- const util_1 = require("../util");
5
- const error_1 = require("../validation/error");
6
- const logger = (0, util_1.makeLogger)('RoutingTransport');
7
- /**
8
- * Transport implementation that takes 2 or more transports and a function that determines with transport to use.
9
- *
10
- * @typeParam AdapterParams - interface for the adapter request body
11
- * @typeParam AdapterResult - interface for the adapter's response body
12
- * @typeParam CustomSettings - interface for the adapter's custom settings.
13
- */
14
- class RoutingTransport {
15
- constructor(
16
- // This is public for tests, which sometimes need the underlying transport for things like ticking the clock
17
- transports,
18
- // Route should return to a string key that corresponds to a transport in the transports object
19
- route) {
20
- this.transports = transports;
21
- this.route = route;
22
- }
23
- async initialize(dependencies, adapterConfig, endpointName) {
24
- logger.debug(`Initializing ${Object.keys(this.transports).length} transports`);
25
- Object.entries(this.transports).forEach(([k, v]) => {
26
- logger.debug(`Initializing transport ${k} (${v.constructor.name})`);
27
- v.initialize(dependencies, adapterConfig, endpointName);
28
- });
29
- }
30
- resolveTransport(req, adapterConfig) {
31
- logger.debug(`routing request using`, req.params);
32
- const key = this.route(req, adapterConfig || undefined);
33
- if (!this.transports[key]) {
34
- throw new error_1.AdapterError({ statusCode: 400, message: `No transport found for ${key}` });
35
- }
36
- const transport = this.transports[key];
37
- logger.debug(`Found ${transport.constructor.name} corresponding to ${key}`);
38
- return transport;
39
- }
40
- // Allow AdapterResponse<any> below since we don't know what the adapter will return
41
- /* eslint-disable @typescript-eslint/no-explicit-any */
42
- async foregroundExecute(req, adapterConfig) {
43
- const transport = this.resolveTransport(req, adapterConfig);
44
- if (transport.foregroundExecute) {
45
- logger.debug(`Running foregroundExecute on retrieved transport`);
46
- return transport.foregroundExecute(req, adapterConfig);
47
- }
48
- logger.debug(`Retrieved transport doesn't implement foregroundExecute`);
49
- }
50
- }
51
- exports.RoutingTransport = RoutingTransport;
52
- //# sourceMappingURL=routing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../src/transports/routing.ts"],"names":[],"mappings":";;;AAEA,kCAAoC;AAGpC,+CAAkD;AAElD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,kBAAkB,CAAC,CAAA;AAE7C;;;;;;GAMG;AAEH,MAAa,gBAAgB;IAI3B;IACE,6GAA6G;IACtG,UAA0E;IAEjF,+FAA+F;IACvF,KAGG;QANJ,eAAU,GAAV,UAAU,CAAgE;QAGzE,UAAK,GAAL,KAAK,CAGF;IACV,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,aAA4C,EAC5C,YAAoB;QAEpB,MAAM,CAAC,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,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AAE,aAAa,CAAC,CAAA;SACvD;QACD,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAA;IACzE,CAAC;CACF;AAtDD,4CAsDC"}
@@ -1,40 +0,0 @@
1
- import { Cache } from '../cache';
2
- import EventSource from 'eventsource';
3
- import { SettingsMap, AdapterConfig } from '../config';
4
- import { AxiosRequestConfig } from 'axios';
5
- import { SubscriptionSet } from '../util';
6
- import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
7
- import { BackgroundStoredResultType, Transport } from './';
8
- import { AdapterContext, AdapterDependencies } from '../adapter';
9
- export interface SSEConfig {
10
- url: string;
11
- eventSourceInitDict?: EventSource.EventSourceInitDict;
12
- }
13
- export declare class SSETransport<AdapterParams, ProviderRequestBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, BackgroundStoredResultType, CustomSettings> {
14
- private config;
15
- EventSource: typeof EventSource;
16
- cache: Cache<AdapterResponse<BackgroundStoredResultType>>;
17
- eventListeners: {
18
- type: string;
19
- parseResponse: (evt: MessageEvent) => ProviderResult<AdapterParams>;
20
- }[];
21
- sseConnection?: EventSource;
22
- subscriptionSet: SubscriptionSet<AdapterParams>;
23
- timeOfLastReq: number;
24
- localSubscriptions: AdapterParams[];
25
- constructor(config: {
26
- prepareSSEConnectionConfig: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => SSEConfig;
27
- prepareKeepAliveRequest: (context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
28
- prepareSubscriptionRequest: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
29
- prepareUnsubscriptionRequest: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
30
- eventListeners: {
31
- type: string;
32
- parseResponse: (evt: MessageEvent) => ProviderResult<AdapterParams>[];
33
- }[];
34
- keepaliveSleepMs?: number;
35
- pollingSleepMs?: number;
36
- });
37
- initialize(dependencies: AdapterDependencies, config: AdapterConfig<CustomSettings>, endpointName: string): Promise<void>;
38
- registerRequest(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
39
- backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
40
- }
package/transports/sse.js DELETED
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SSETransport = void 0;
7
- const eventsource_1 = __importDefault(require("eventsource"));
8
- const axios_1 = __importDefault(require("axios"));
9
- const util_1 = require("../util");
10
- const _1 = require("./");
11
- const logger = (0, util_1.makeLogger)('SSETransport');
12
- class SSETransport {
13
- constructor(config) {
14
- this.config = config;
15
- this.EventSource = eventsource_1.default;
16
- this.timeOfLastReq = 0;
17
- // The double sets serve to create a simple polling mechanism instead of needing a subscription
18
- // This one would not; this is always local state
19
- this.localSubscriptions = [];
20
- }
21
- async initialize(dependencies, config, endpointName) {
22
- this.cache = dependencies.cache;
23
- this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
24
- if (dependencies.eventSource) {
25
- this.EventSource = dependencies.eventSource;
26
- }
27
- }
28
- async registerRequest(req, config) {
29
- logger.debug(`Adding entry to subscription set (ttl: ${config.SSE_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
30
- await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.SSE_SUBSCRIPTION_TTL);
31
- }
32
- // Unlike cache warming, this execute will manage subscriptions
33
- async backgroundExecute(context) {
34
- logger.debug('Starting background execute, getting subscriptions from sorted set');
35
- const desiredSubs = await this.subscriptionSet.getAll();
36
- logger.debug('Generating delta (subscribes & unsubscribes)');
37
- const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
38
- const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
39
- logger.debug(`${subscribeParams.length} new subscriptions; ${unsubscribeParams.length} to unsubscribe`);
40
- if (subscribeParams.length) {
41
- logger.trace(`Will subscribe to: ${subscribeParams}`);
42
- }
43
- if (unsubscribeParams.length) {
44
- logger.trace(`Will unsubscribe to: ${unsubscribeParams}`);
45
- }
46
- if ((subscribeParams.length || unsubscribeParams.length) &&
47
- (!this.sseConnection || this.sseConnection.readyState !== this.sseConnection.OPEN)) {
48
- logger.debug('No established connection and new subscriptions available, connecting to SSE');
49
- const sseConfig = this.config.prepareSSEConnectionConfig(subscribeParams, context);
50
- this.sseConnection = new this.EventSource(sseConfig.url, sseConfig.eventSourceInitDict);
51
- const eventHandlerGenerator = (listener) => {
52
- return (e) => {
53
- const providerResponses = listener.parseResponse(e);
54
- const cacheEntries = (0, _1.buildCacheEntriesFromResults)(providerResponses, context);
55
- this.cache.setMany(cacheEntries, context.adapterConfig.CACHE_MAX_AGE);
56
- };
57
- };
58
- this.config.eventListeners.forEach((listener) => {
59
- this.sseConnection?.addEventListener(listener.type, eventHandlerGenerator(listener));
60
- });
61
- }
62
- const makeRequest = async (req) => {
63
- try {
64
- const res = await axios_1.default.request(req);
65
- logger.debug(res.data, `response status ${res.statusText} from keepalive request`);
66
- }
67
- catch (err) {
68
- logger.error(err, `Error on keepalive request`);
69
- }
70
- this.timeOfLastReq = Date.now();
71
- };
72
- if (subscribeParams.length) {
73
- const subscribeRequest = this.config.prepareSubscriptionRequest(subscribeParams, context);
74
- makeRequest(subscribeRequest);
75
- }
76
- if (unsubscribeParams.length) {
77
- const unsubscribeRequest = this.config.prepareUnsubscriptionRequest(unsubscribeParams, context);
78
- makeRequest(unsubscribeRequest);
79
- }
80
- if (desiredSubs.length &&
81
- Date.now() - this.timeOfLastReq > context.adapterConfig.SSE_KEEPALIVE_SLEEP) {
82
- const prepareKeepAliveRequest = this.config.prepareKeepAliveRequest(context);
83
- makeRequest(prepareKeepAliveRequest);
84
- }
85
- logger.debug('Setting local state to cache value');
86
- this.localSubscriptions = desiredSubs;
87
- logger.debug('Background execute complete');
88
- return context.adapterConfig.SSE_SUBSCRIPTION_UPDATE_SLEEP;
89
- }
90
- }
91
- exports.SSETransport = SSETransport;
92
- //# sourceMappingURL=sse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;AACA,8DAAqC;AAErC,kDAAiD;AACjD,kCAAqD;AAErD,yBAAwF;AAGxF,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,cAAc,CAAC,CAAA;AAOzC,MAAa,YAAY;IAiBvB,YACU,MAsBP;QAtBO,WAAM,GAAN,MAAM,CAsBb;QArCH,gBAAW,GAAuB,qBAAW,CAAA;QAQ7C,kBAAa,GAAG,CAAC,CAAA;QAEjB,+FAA+F;QAC/F,iDAAiD;QACjD,uBAAkB,GAAoB,EAAE,CAAA;IA0BrC,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,MAAqC,EACrC,YAAoB;QAEpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAA2D,CAAA;QACrF,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC,sBAAsB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;QACjF,IAAI,YAAY,CAAC,WAAW,EAAE;YAC5B,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,WAAW,CAAA;SAC5C;IACH,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,GAAkC,EAClC,MAAqC;QAErC,MAAM,CAAC,KAAK,CACV,0CAA0C,MAAM,CAAC,oBAAoB,OAAO,GAAG,CAAC,cAAc,CAAC,QAAQ,OAAO,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CACxI,CAAA;QACD,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAC5B,GAAG,CAAC,cAAc,CAAC,QAAQ,EAC3B,GAAG,CAAC,cAAc,CAAC,IAAI,EACvB,MAAM,CAAC,oBAAoB,CAC5B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AAW,CAAC,gBAAgB,CAAC,CAAA;SAC9B;QACD,IAAI,iBAAiB,CAAC,MAAM,EAAE;YAC5B,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,4BAA4B,CACjE,iBAAiB,EACjB,OAAO,CACR,CAAA;YACD,WAAW,CAAC,kBAAkB,CAAC,CAAA;SAChC;QACD,IACE,WAAW,CAAC,MAAM;YAClB,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,mBAAmB,EAC3E;YACA,MAAM,uBAAuB,GAAG,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAA;YAC5E,WAAW,CAAC,uBAAuB,CAAC,CAAA;SACrC;QAED,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,OAAO,CAAC,aAAa,CAAC,6BAA6B,CAAA;IAC5D,CAAC;CACF;AAhJD,oCAgJC"}
@@ -1,9 +0,0 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { AdapterConfig, SettingsMap } from '../config';
3
- /**
4
- * Performs axios request along with metrics recording and error handling
5
- *
6
- * @param request - axios request config
7
- * @returns axios response for the request
8
- */
9
- export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap>(request: AxiosRequestConfig<ProviderRequestBody>, config: AdapterConfig<CustomSettings>): Promise<AxiosResponse<ProviderResponseBody>>;
@@ -1,87 +0,0 @@
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.axiosRequest = void 0;
30
- const axios_1 = __importDefault(require("axios"));
31
- const error_1 = require("../validation/error");
32
- const transportMetrics = __importStar(require("./metrics"));
33
- /**
34
- * Performs axios request along with metrics recording and error handling
35
- *
36
- * @param request - axios request config
37
- * @returns axios response for the request
38
- */
39
- async function axiosRequest(request, config) {
40
- const responseTimer = transportMetrics.dataProviderRequestDurationSeconds.startTimer();
41
- let providerResponse;
42
- try {
43
- request.timeout = config.API_TIMEOUT;
44
- providerResponse = await axios_1.default.request(request);
45
- }
46
- catch (e) {
47
- const error = e;
48
- // Request error
49
- let providerStatusCode;
50
- let adapterError;
51
- if (error.code === 'ECONNABORTED') {
52
- adapterError = new error_1.AdapterTimeoutError({});
53
- providerStatusCode = error?.response?.status ?? 504;
54
- adapterError.name = 'Data Provider Request Timeout error';
55
- }
56
- else if (error?.response?.status) {
57
- adapterError = new error_1.AdapterDataProviderError({});
58
- providerStatusCode = error?.response?.status;
59
- }
60
- else {
61
- adapterError = new error_1.AdapterConnectionError({});
62
- providerStatusCode = 0; // 0 -> connection error
63
- }
64
- // Record count of failed data provider request
65
- transportMetrics.dataProviderRequests
66
- .labels(transportMetrics.dataProviderMetricsLabel(providerStatusCode, request.method))
67
- .inc();
68
- adapterError.statusCode = 200;
69
- adapterError.providerStatusCode = providerStatusCode;
70
- adapterError.message = error?.message;
71
- adapterError.cause = error;
72
- adapterError.errorResponse = error?.response?.data;
73
- adapterError.url = request.url;
74
- throw adapterError;
75
- }
76
- finally {
77
- // Record time taken for data provider request for success or failure
78
- responseTimer();
79
- }
80
- // Record count of successful data provider requests
81
- transportMetrics.dataProviderRequests
82
- .labels(transportMetrics.dataProviderMetricsLabel(providerResponse.status, request.method))
83
- .inc();
84
- return providerResponse;
85
- }
86
- exports.axiosRequest = axiosRequest;
87
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/transports/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4E;AAE5E,+CAK4B;AAC5B,4DAA6C;AAE7C;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAKhC,OAAgD,EAChD,MAAqC;IAErC,MAAM,aAAa,GAAG,gBAAgB,CAAC,kCAAkC,CAAC,UAAU,EAAE,CAAA;IACtF,IAAI,gBAAqD,CAAA;IACzD,IAAI;QACF,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAA;QACpC,gBAAgB,GAAG,MAAM,eAAK,CAAC,OAAO,CAAuB,OAAO,CAAC,CAAA;KACtE;IAAC,OAAO,CAAU,EAAE;QACnB,MAAM,KAAK,GAAG,CAAe,CAAA;QAC7B,gBAAgB;QAChB,IAAI,kBAAsC,CAAA;QAC1C,IAAI,YAA0B,CAAA;QAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;YACjC,YAAY,GAAG,IAAI,2BAAmB,CAAC,EAAE,CAAC,CAAA;YAC1C,kBAAkB,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAA;YACnD,YAAY,CAAC,IAAI,GAAG,qCAAqC,CAAA;SAC1D;aAAM,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;YAClC,YAAY,GAAG,IAAI,gCAAwB,CAAC,EAAE,CAAC,CAAA;YAC/C,kBAAkB,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAA;SAC7C;aAAM;YACL,YAAY,GAAG,IAAI,8BAAsB,CAAC,EAAE,CAAC,CAAA;YAC7C,kBAAkB,GAAG,CAAC,CAAA,CAAC,wBAAwB;SAChD;QACD,+CAA+C;QAC/C,gBAAgB,CAAC,oBAAoB;aAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;aACrF,GAAG,EAAE,CAAA;QAER,YAAY,CAAC,UAAU,GAAG,GAAG,CAAA;QAC7B,YAAY,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;QACpD,YAAY,CAAC,OAAO,GAAG,KAAK,EAAE,OAAO,CAAA;QACrC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAA;QAC1B,YAAY,CAAC,aAAa,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAA;QAClD,YAAY,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QAE9B,MAAM,YAAY,CAAA;KACnB;YAAS;QACR,qEAAqE;QACrE,aAAa,EAAE,CAAA;KAChB;IAED,oDAAoD;IACpD,gBAAgB,CAAC,oBAAoB;SAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;SAC1F,GAAG,EAAE,CAAA;IAER,OAAO,gBAAgB,CAAA;AACzB,CAAC;AArDD,oCAqDC"}
@@ -1,81 +0,0 @@
1
- import WebSocket, { ClientOptions, RawData } from 'ws';
2
- import { AdapterContext, AdapterDependencies } from '../adapter';
3
- import { Cache } from '../cache';
4
- import { AdapterConfig, SettingsMap } from '../config';
5
- import { BackgroundExecuteRateLimiter } from '../rate-limiting';
6
- import { SubscriptionSet } from '../util';
7
- import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
8
- import { Transport, BackgroundStoredResultType } from './';
9
- export { WebSocket, RawData as WebSocketRawData };
10
- declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined, options?: ClientOptions) => WebSocket;
11
- export declare class WebSocketClassProvider {
12
- static ctor: WebSocketClass;
13
- static set(ctor: WebSocketClass): void;
14
- static get(): WebSocketClass;
15
- }
16
- /**
17
- * Config object that is provided to the WebSocketTransport constructor.
18
- */
19
- export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> {
20
- /** Endpoint to which to open the WS connection*/
21
- url: (context: AdapterContext<CustomSettings>) => string;
22
- /** Optional parameters used when establishing the WebSocket connection */
23
- options?: (context: AdapterContext<CustomSettings>) => ClientOptions;
24
- /** Map of handlers for different WS lifecycle events */
25
- handlers: {
26
- /**
27
- * Handles when the WS is successfully opened
28
- *
29
- * @param wsConnection - the WebSocket with an established connection
30
- * @returns an empty Promise, or void
31
- */
32
- open: (wsConnection: WebSocket, context: AdapterContext<CustomSettings>) => Promise<void> | void;
33
- /**
34
- * Handles when the WS receives a message
35
- *
36
- * @param message - the message received by the WS
37
- * @param context - the background context for the Adapter
38
- * @returns a list of cache entries of adapter responses to set in the cache
39
- */
40
- message: (message: ProviderDataMessage, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[] | undefined;
41
- };
42
- /** Map of "builders", functions that will be used to prepare specific WS messages */
43
- builders: {
44
- /**
45
- * Builds a WS message that will be sent to subscribe to a specific feed
46
- *
47
- * @param params - the body of the adapter request
48
- * @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
49
- */
50
- subscribeMessage: (params: AdapterParams) => unknown;
51
- /**
52
- * Builds a WS message that will be sent to unsubscribe to a specific feed
53
- *
54
- * @param params - the body of the adapter request
55
- * @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
56
- */
57
- unsubscribeMessage: (params: AdapterParams) => unknown;
58
- };
59
- }
60
- /**
61
- * Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
62
- * through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
63
- *
64
- * @typeParam AdapterParams - interface for the adapter request body
65
- * @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
66
- */
67
- export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams, BackgroundStoredResultType, CustomSettings> {
68
- private config;
69
- cache: Cache<AdapterResponse<BackgroundStoredResultType>>;
70
- rateLimiter: BackgroundExecuteRateLimiter;
71
- subscriptionSet: SubscriptionSet<AdapterParams>;
72
- localSubscriptions: AdapterParams[];
73
- wsConnection: WebSocket;
74
- constructor(config: WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings>);
75
- initialize(dependencies: AdapterDependencies, config: AdapterConfig<CustomSettings>, endpointName: string): Promise<void>;
76
- registerRequest(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
77
- serializeMessage(payload: unknown): string;
78
- deserializeMessage(data: WebSocket.Data): ProviderDataMessage;
79
- establishWsConnection(context: AdapterContext<CustomSettings>): Promise<unknown>;
80
- backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
81
- }