@chainlink/external-adapter-framework 0.12.1 → 0.13.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 (63) hide show
  1. package/adapter/basic.js +9 -4
  2. package/adapter/basic.js.map +1 -1
  3. package/adapter/endpoint.d.ts +9 -1
  4. package/adapter/endpoint.js +23 -0
  5. package/adapter/endpoint.js.map +1 -1
  6. package/cache/index.d.ts +4 -2
  7. package/cache/index.js +2 -2
  8. package/cache/index.js.map +1 -1
  9. package/cache/local.d.ts +2 -0
  10. package/cache/local.js +2 -31
  11. package/cache/local.js.map +1 -1
  12. package/cache/metrics.d.ts +5 -2
  13. package/cache/metrics.js +19 -3
  14. package/cache/metrics.js.map +1 -1
  15. package/cache/redis.d.ts +2 -0
  16. package/cache/redis.js +7 -9
  17. package/cache/redis.js.map +1 -1
  18. package/cache/response.d.ts +36 -0
  19. package/cache/response.js +97 -0
  20. package/cache/response.js.map +1 -0
  21. package/config/index.d.ts +6 -6
  22. package/config/index.js +6 -10
  23. package/config/index.js.map +1 -1
  24. package/index.js +4 -1
  25. package/index.js.map +1 -1
  26. package/metrics/util.d.ts +1 -1
  27. package/metrics/util.js +2 -2
  28. package/metrics/util.js.map +1 -1
  29. package/package.json +2 -2
  30. package/rate-limiting/metrics.js +1 -1
  31. package/rate-limiting/metrics.js.map +1 -1
  32. package/transports/abstract/streaming.d.ts +34 -0
  33. package/transports/abstract/streaming.js +44 -0
  34. package/transports/abstract/streaming.js.map +1 -0
  35. package/transports/abstract/subscription.d.ts +38 -0
  36. package/transports/abstract/subscription.js +63 -0
  37. package/transports/abstract/subscription.js.map +1 -0
  38. package/transports/batch-warming.d.ts +7 -12
  39. package/transports/batch-warming.js +42 -28
  40. package/transports/batch-warming.js.map +1 -1
  41. package/transports/index.d.ts +20 -13
  42. package/transports/index.js +0 -35
  43. package/transports/index.js.map +1 -1
  44. package/transports/meta/index.d.ts +1 -0
  45. package/transports/meta/index.js +18 -0
  46. package/transports/meta/index.js.map +1 -0
  47. package/transports/{routing.d.ts → meta/routing.d.ts} +11 -5
  48. package/transports/{routing.js → meta/routing.js} +6 -6
  49. package/transports/meta/routing.js.map +1 -0
  50. package/transports/metrics.d.ts +11 -4
  51. package/transports/metrics.js +30 -20
  52. package/transports/metrics.js.map +1 -1
  53. package/transports/rest.d.ts +10 -7
  54. package/transports/rest.js +22 -12
  55. package/transports/rest.js.map +1 -1
  56. package/transports/sse.d.ts +8 -12
  57. package/transports/sse.js +29 -39
  58. package/transports/sse.js.map +1 -1
  59. package/transports/websocket.d.ts +15 -14
  60. package/transports/websocket.js +87 -60
  61. package/transports/websocket.js.map +1 -1
  62. package/util/request.d.ts +90 -11
  63. package/transports/routing.js.map +0 -1
@@ -1,11 +1,9 @@
1
1
  import WebSocket, { ClientOptions, RawData } from 'ws';
2
- import { AdapterDependencies, EndpointContext } from '../adapter';
3
- import { Cache } from '../cache';
2
+ import { EndpointContext } from '../adapter';
4
3
  import { AdapterConfig } from '../config';
5
- import { BackgroundExecuteRateLimiter } from '../rate-limiting';
6
- import { SubscriptionSet } from '../util';
7
- import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
8
- import { Transport, TransportGenerics } from './';
4
+ import { ProviderResult } from '../util/request';
5
+ import { TransportGenerics } from './';
6
+ import { StreamingTransport, SubscriptionDeltas } from './abstract/streaming';
9
7
  export { WebSocket, RawData as WebSocketRawData };
10
8
  declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined, options?: ClientOptions) => WebSocket;
11
9
  export declare class WebSocketClassProvider {
@@ -79,21 +77,24 @@ declare type WebsocketTransportGenerics = TransportGenerics & {
79
77
  *
80
78
  * @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[WebsocketTransportGenerics]])
81
79
  */
82
- export declare class WebSocketTransport<T extends WebsocketTransportGenerics> implements Transport<T> {
80
+ export declare class WebSocketTransport<T extends WebsocketTransportGenerics> extends StreamingTransport<T> {
83
81
  private config;
84
- cache: Cache<AdapterResponse<T['Response']>>;
85
- rateLimiter: BackgroundExecuteRateLimiter;
86
- subscriptionSet: SubscriptionSet<T['Request']['Params']>;
87
- localSubscriptions: T['Request']['Params'][];
88
82
  wsConnection: WebSocket;
89
83
  currentUrl: string;
84
+ lastMessageReceivedAt: number;
85
+ connectionOpenedAt: number;
90
86
  constructor(config: WebSocketTransportConfig<T>);
91
- initialize(dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
92
- registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
87
+ getSubscriptionTtlFromConfig(config: AdapterConfig<T['CustomSettings']>): number;
93
88
  connectionClosed(): boolean;
94
89
  serializeMessage(payload: unknown): string;
95
90
  deserializeMessage(data: WebSocket.Data): T['Provider']['WsMessage'];
91
+ buildConnectionHandlers(context: EndpointContext<T>, connectionReadyResolve: (value: unknown) => void): {
92
+ open: (event: WebSocket.Event) => Promise<void>;
93
+ message: (event: WebSocket.MessageEvent) => Promise<void>;
94
+ error: (event: WebSocket.ErrorEvent) => Promise<void>;
95
+ close: (event: WebSocket.CloseEvent) => void;
96
+ };
96
97
  establishWsConnection(context: EndpointContext<T>, url: string, options?: WebSocket.ClientOptions | undefined): Promise<unknown>;
97
98
  sendMessages(context: EndpointContext<T>, subscribes: unknown[], unsubscribes: unknown[]): Promise<void>;
98
- backgroundExecute(context: EndpointContext<T>): Promise<number>;
99
+ streamHandler(context: EndpointContext<T>, subscriptions: SubscriptionDeltas<T['Request']['Params']>): Promise<void>;
99
100
  }
@@ -30,8 +30,8 @@ exports.WebSocketTransport = exports.WebSocketClassProvider = exports.WebSocket
30
30
  const ws_1 = __importDefault(require("ws"));
31
31
  exports.WebSocket = ws_1.default;
32
32
  const util_1 = require("../util");
33
- const _1 = require("./");
34
33
  const transportMetrics = __importStar(require("./metrics"));
34
+ const streaming_1 = require("./abstract/streaming");
35
35
  const logger = (0, util_1.makeLogger)('WebSocketTransport');
36
36
  class WebSocketClassProvider {
37
37
  static set(ctor) {
@@ -49,22 +49,16 @@ WebSocketClassProvider.ctor = ws_1.default;
49
49
  *
50
50
  * @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[WebsocketTransportGenerics]])
51
51
  */
52
- class WebSocketTransport {
52
+ class WebSocketTransport extends streaming_1.StreamingTransport {
53
53
  constructor(config) {
54
+ super();
54
55
  this.config = config;
55
- // The double sets serve to create a simple polling mechanism instead of needing a subscription
56
- // This one would not; this is always local state
57
- this.localSubscriptions = [];
58
56
  this.currentUrl = '';
57
+ this.lastMessageReceivedAt = 0;
58
+ this.connectionOpenedAt = 0;
59
59
  }
60
- async initialize(dependencies, config, endpointName) {
61
- this.cache = dependencies.cache;
62
- this.rateLimiter = dependencies.backgroundExecuteRateLimiter;
63
- this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
64
- }
65
- async registerRequest(req, config) {
66
- logger.debug(`Adding entry to subscription set (ttl: ${config.WS_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
67
- await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
60
+ getSubscriptionTtlFromConfig(config) {
61
+ return config.WS_SUBSCRIPTION_TTL;
68
62
  }
69
63
  connectionClosed() {
70
64
  return !this.wsConnection || this.wsConnection.readyState === ws_1.default.CLOSED;
@@ -75,11 +69,10 @@ class WebSocketTransport {
75
69
  deserializeMessage(data) {
76
70
  return JSON.parse(data.toString());
77
71
  }
78
- establishWsConnection(context, url, options) {
79
- return new Promise((resolve) => {
80
- const ctor = WebSocketClassProvider.get();
81
- this.wsConnection = new ctor(url, undefined, options);
82
- this.wsConnection.addEventListener('open', async (event) => {
72
+ buildConnectionHandlers(context, connectionReadyResolve) {
73
+ return {
74
+ // Called when the WS connection is opened
75
+ open: async (event) => {
83
76
  logger.debug(`Opened websocket connection. (event type ${event.type})`);
84
77
  if (this.config.handlers.open) {
85
78
  await this.config.handlers.open(this.wsConnection, context);
@@ -87,31 +80,64 @@ class WebSocketTransport {
87
80
  }
88
81
  // Record active ws connections by incrementing count on open
89
82
  transportMetrics.wsConnectionActive.inc();
90
- resolve(true);
91
- });
92
- this.wsConnection.addEventListener('message', async (event) => {
83
+ connectionReadyResolve(true);
84
+ },
85
+ // Called when any message is received by the open connection
86
+ message: async (event) => {
93
87
  const parsed = this.deserializeMessage(event.data);
94
88
  logger.trace(`Got ws message: ${event.data}`);
95
- const results = this.config.handlers.message(parsed, context);
89
+ const providerDataReceived = Date.now();
90
+ const results = this.config.handlers.message(parsed, context)?.map((r) => {
91
+ const result = r;
92
+ const partialResponse = r.response;
93
+ result.response.timestamps = {
94
+ providerDataStreamEstablished: this.providerDataStreamEstablished,
95
+ providerDataReceived,
96
+ providerIndicatedTime: partialResponse.timestamps?.providerIndicatedTime,
97
+ };
98
+ return result;
99
+ });
96
100
  if (Array.isArray(results)) {
97
- const responses = (0, _1.buildCacheEntriesFromResults)(results, context);
98
- logger.trace(`Writing ${responses.length} responses to cache`);
99
- await this.cache.setMany(responses, context.adapterConfig.CACHE_MAX_AGE);
101
+ // Updating the last message received time here, to only care about messages we use
102
+ this.lastMessageReceivedAt = Date.now();
103
+ logger.trace(`Writing ${results.length} responses to cache`);
104
+ await this.responseCache.write(results);
100
105
  }
101
- });
102
- this.wsConnection.addEventListener('error', async (event) => {
106
+ // Do this after writing so we get the values to the cache ASAP
107
+ // We're not calculating feedId or subscription because this is only a single message,
108
+ // and it could in theory contain more than one value to set to the cache
109
+ transportMetrics.wsMessageTotal
110
+ .labels({
111
+ direction: 'received',
112
+ })
113
+ .inc();
114
+ },
115
+ // Called when an error is thrown by the connection
116
+ error: async (event) => {
103
117
  logger.debug(`Error occurred in web socket connection. Error: ${event.error} ; Message: ${event.message}`);
104
118
  // Record connection error count
105
119
  transportMetrics.wsConnectionErrors
106
120
  .labels(transportMetrics.connectionErrorLabels(event.message))
107
121
  .inc();
108
- });
109
- this.wsConnection.addEventListener('close', (event) => {
122
+ },
123
+ // Called when the WS connection closes for any reason
124
+ close: (event) => {
110
125
  logger.debug(`Closed websocket connection. Code: ${event.code} ; reason: ${event.reason?.toString()}`);
111
126
  // Record active ws connections by decrementing count on close
112
127
  // Using URL in label since connection_key is removed from v3
113
128
  transportMetrics.wsConnectionActive.dec();
114
- });
129
+ },
130
+ };
131
+ }
132
+ establishWsConnection(context, url, options) {
133
+ return new Promise((resolve) => {
134
+ const ctor = WebSocketClassProvider.get();
135
+ const handlers = this.buildConnectionHandlers(context, resolve);
136
+ this.wsConnection = new ctor(url, undefined, options);
137
+ this.wsConnection.addEventListener('open', handlers.open);
138
+ this.wsConnection.addEventListener('message', handlers.message);
139
+ this.wsConnection.addEventListener('error', handlers.error);
140
+ this.wsConnection.addEventListener('close', handlers.close);
115
141
  });
116
142
  }
117
143
  async sendMessages(context, subscribes, unsubscribes) {
@@ -122,59 +148,60 @@ class WebSocketTransport {
122
148
  this.wsConnection.send(message);
123
149
  }
124
150
  }
125
- // Unlike cache warming, this execute will manage subscriptions
126
- async backgroundExecute(context) {
127
- logger.debug('Starting background execute, getting subscriptions from sorted set');
128
- const desiredSubs = await this.subscriptionSet.getAll();
129
- // Keep track of active subscriptions for background execute
130
- transportMetrics.bgExecuteSubscriptionSetCount
131
- .labels({ endpoint: context.endpointName, transport_type: 'websocket' })
132
- .set(desiredSubs.length);
133
- logger.debug('Generating delta (subscribes & unsubscribes)');
134
- const subscribes = desiredSubs.filter((s) => !this.localSubscriptions.map((ls) => JSON.stringify(ls)).includes(JSON.stringify(s)));
135
- const unsubscribes = this.localSubscriptions.filter((s) => !desiredSubs.map((ds) => JSON.stringify(ds)).includes(JSON.stringify(s)));
136
- logger.debug(`${subscribes.length} new subscriptions; ${unsubscribes.length} to unsubscribe`);
137
- if (subscribes.length) {
138
- logger.trace(`Will subscribe to: ${JSON.stringify(subscribes)}`);
139
- }
140
- if (unsubscribes.length) {
141
- logger.trace(`Will unsubscribe to: ${JSON.stringify(unsubscribes)}`);
142
- }
151
+ async streamHandler(context, subscriptions) {
143
152
  // New subs && no connection -> connect -> add subs
144
153
  // No new subs && no connection -> skip
145
154
  // New subs && connection -> add subs
146
155
  // No new subs && connection -> unsubs only
147
- if (!subscribes.length && !this.wsConnection) {
156
+ if (!subscriptions.new.length && !this.wsConnection) {
148
157
  logger.debug('No entries in subscription set and no established connection, skipping');
149
- return this.rateLimiter.msUntilNextExecution(context.endpointName);
158
+ return;
150
159
  }
151
- const urlFromConfig = await this.config.url(context, desiredSubs);
160
+ // We want to check if the URL we calculate is different from the one currently connected.
161
+ // This is because some providers handle subscriptions on the URLs and not through messages.
162
+ const urlFromConfig = await this.config.url(context, subscriptions.desired);
152
163
  const urlChanged = this.currentUrl !== urlFromConfig;
164
+ // We want to check that if we have a connection, it hasn't gone stale. That is,
165
+ // since opening it, have we had any activity from the provider.
166
+ const now = Date.now();
167
+ const timeSinceLastMessage = Math.max(0, now - this.lastMessageReceivedAt);
168
+ const timeSinceConnectionOpened = Math.max(0, now - this.connectionOpenedAt);
169
+ const timeSinceLastActivity = Math.min(timeSinceLastMessage, timeSinceConnectionOpened);
170
+ const connectionUnresponsive = timeSinceLastActivity > 0 &&
171
+ timeSinceLastActivity > context.adapterConfig.WS_SUBSCRIPTION_UNRESPONSIVE_TTL;
153
172
  let connectionClosed = this.connectionClosed();
154
173
  // Check if we should close the current connection
155
- if (!connectionClosed && urlChanged) {
156
- logger.info(`Websocket url has changed from ${this.currentUrl} to ${urlFromConfig}, closing connection...`);
174
+ if (!connectionClosed && (urlChanged || connectionUnresponsive)) {
175
+ const reason = urlChanged
176
+ ? `Websocket url has changed from ${this.currentUrl} to ${urlFromConfig}, closing connection...`
177
+ : `Last message was received ${timeSinceLastMessage} ago, exceeding the threshold of ${context.adapterConfig.WS_SUBSCRIPTION_UNRESPONSIVE_TTL}ms, closing connection...`;
178
+ logger.info(reason);
157
179
  this.wsConnection.close();
158
180
  connectionClosed = true;
181
+ // If the connection was closed, the new subscriptions should be the desired ones
182
+ subscriptions.new = subscriptions.desired;
183
+ if (subscriptions.new.length) {
184
+ logger.trace(`Connection will be reopened and will subscribe to new and resubscribe to existing: ${JSON.stringify(subscriptions.new)}`);
185
+ }
159
186
  }
160
187
  // Check if we need to open a new connection
161
- if (connectionClosed && desiredSubs.length) {
188
+ if (connectionClosed && subscriptions.desired.length) {
162
189
  logger.debug('No established connection and new subscriptions available, connecting to WS');
163
190
  const options = this.config.options && (await this.config.options(context));
164
191
  this.currentUrl = urlFromConfig;
192
+ // Need to write this now, otherwise there could be messages sent with values before the open handler finishes
193
+ this.providerDataStreamEstablished = Date.now();
165
194
  await this.establishWsConnection(context, urlFromConfig, options);
195
+ this.connectionOpenedAt = Date.now();
166
196
  }
167
197
  if (this.config.builders) {
168
198
  logger.debug('Sending subs/unsubs if there are any');
169
199
  const { subscribeMessage, unsubscribeMessage } = this.config.builders;
170
- await this.sendMessages(context, subscribeMessage ? subscribes.map(subscribeMessage) : subscribes, unsubscribeMessage ? unsubscribes.map(unsubscribeMessage) : unsubscribes);
200
+ await this.sendMessages(context, subscribeMessage ? subscriptions.new.map(subscribeMessage) : subscriptions.new, unsubscribeMessage ? subscriptions.stale.map(unsubscribeMessage) : subscriptions.stale);
171
201
  }
172
202
  // Record WS message and subscription metrics
173
- transportMetrics.recordWsMessageMetrics(context, subscribes, unsubscribes);
174
- logger.debug('Setting local state to cache value');
175
- this.localSubscriptions = desiredSubs;
176
- logger.debug('Background execute complete');
177
- return this.rateLimiter.msUntilNextExecution(context.endpointName);
203
+ transportMetrics.recordWsMessageMetrics(context, subscriptions.new, subscriptions.stale);
204
+ return;
178
205
  }
179
206
  }
180
207
  exports.WebSocketTransport = WebSocketTransport;
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAsD;AAW7C,oBAXF,YAAS,CAWE;AANlB,kCA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6CAA6C;QAC7C,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;QAExF,OAAM;IACR,CAAC;CACF;AA1MD,gDA0MC"}
package/util/request.d.ts CHANGED
@@ -76,18 +76,27 @@ export interface AdapterMetricsMeta {
76
76
  export declare type AdapterRequestData = Record<string, unknown> & {
77
77
  endpoint?: string;
78
78
  };
79
+ export declare type ProviderResultGenerics = {
80
+ Request: RequestGenerics;
81
+ Response: ResponseGenerics;
82
+ };
79
83
  /**
80
84
  * Helper type to hold the value from responses from a provider, and the adapter params they correspond to.
81
85
  */
82
- export interface ProviderResult<T extends {
83
- Request: RequestGenerics;
84
- Response: ResponseGenerics;
85
- }> {
86
+ export declare type ProviderResult<T extends ProviderResultGenerics> = {
86
87
  /** The set of parameters that uniquely relate to the response */
87
88
  params: T['Request']['Params'];
88
89
  /** Value that will be included in the result property of the response */
89
- value: T['Response']['Result'];
90
- }
90
+ response: PartialAdapterResponse<T['Response']>;
91
+ };
92
+ export declare type TimestampedProviderResult<T extends ProviderResultGenerics> = Pick<ProviderResult<T>, 'params'> & {
93
+ /** Value that will be included in the result property of the response, with timestamps applied */
94
+ response: TimestampedAdapterResponse<T['Response']>;
95
+ };
96
+ /**
97
+ * Here we do actually want an object, since unknown could be a primitive.
98
+ * The rule itself does say "marginally better"
99
+ */
91
100
  export declare type EmptyObject = Object;
92
101
  /**
93
102
  * Helper struct type that provides detail about the incoming Adapter Request
@@ -113,20 +122,90 @@ export declare type ResponseGenerics = {
113
122
  Result: string | number | null;
114
123
  };
115
124
  /**
116
- * Shape of the response body from the adapter
125
+ * Details for timestamps to be included in the response
126
+ */
127
+ declare type ResponseTimestamps = {
128
+ /** Time at which data was received from the provider */
129
+ providerDataReceived: number;
130
+ /** Time indicated by the provider representing the time at which this value was calculated/set/valid */
131
+ providerIndicatedTime: number | undefined;
132
+ } & ({
133
+ /**
134
+ * For sync protocols (request -\> response).
135
+ * Time at which data was requested from the provider.
136
+ */
137
+ providerDataRequested: number;
138
+ providerDataStreamEstablished?: never;
139
+ } | {
140
+ /**
141
+ * For async protocols (subscription -\> n events received).
142
+ * Time at which a data stream was established for the provider.
143
+ */
144
+ providerDataStreamEstablished: number;
145
+ providerDataRequested?: never;
146
+ });
147
+ /**
148
+ * Object with timestamps that will be present in both successful and provider error responses
149
+ */
150
+ declare type TimestampedResponseObject = {
151
+ /** Timestamps relevant for data provider timings */
152
+ timestamps: ResponseTimestamps;
153
+ };
154
+ /**
155
+ * Response from the EA to send when manually storing an error in the cache
117
156
  */
118
- export declare type AdapterResponse<T extends ResponseGenerics = ResponseGenerics> = {
119
- /** HTTP status code */
157
+ declare type ProviderErrorResponse = {
158
+ /** Status code for the errored response */
120
159
  statusCode: number;
160
+ /** Error message that will be sent back from the adapter */
161
+ errorMessage: string;
162
+ } & {
163
+ data?: never;
164
+ result?: never;
165
+ meta?: never;
166
+ };
167
+ /**
168
+ * Provider error response with timestamps added
169
+ */
170
+ export declare type TimestampedProviderErrorResponse = ProviderErrorResponse & TimestampedResponseObject;
171
+ /**
172
+ * The most basic data that needs to be manually set for an adapter response.
173
+ */
174
+ export declare type PartialSuccessfulResponse<T extends ResponseGenerics> = {
121
175
  /** Response data, holds "result" for Flux Monitor */
122
176
  data: T['Data'];
123
177
  /** Result value used for OCR */
124
178
  result: T['Result'];
125
- /** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
126
- maxAge?: number;
179
+ /** Optionally, specify manually some of the timestamps here */
180
+ timestamps?: Pick<ResponseTimestamps, 'providerIndicatedTime'>;
181
+ } & {
182
+ errorMessage?: never;
183
+ };
184
+ /**
185
+ * Partial EA response, with timestamps added
186
+ */
187
+ declare type TimestampedSuccessfulResponse<T extends ResponseGenerics> = PartialSuccessfulResponse<T> & TimestampedResponseObject;
188
+ /**
189
+ * Full EA successful response, with metadata and defaults added
190
+ */
191
+ declare type SuccessfulResponse<T extends ResponseGenerics> = TimestampedSuccessfulResponse<T> & {
127
192
  /** Metadata relevant to this request */
128
193
  meta?: AdapterRequestMeta;
194
+ /** HTTP status code, by default will be set to 200 */
195
+ statusCode: number;
129
196
  };
197
+ /**
198
+ * Response body from the EA, before timestamps, defaults and metadata are filled in
199
+ */
200
+ export declare type PartialAdapterResponse<T extends ResponseGenerics = ResponseGenerics> = PartialSuccessfulResponse<T> | ProviderErrorResponse;
201
+ /**
202
+ * Response body from the EA with timestamps, before defaults and metadata are filled in
203
+ */
204
+ export declare type TimestampedAdapterResponse<T extends ResponseGenerics = ResponseGenerics> = TimestampedSuccessfulResponse<T> | TimestampedProviderErrorResponse;
205
+ /**
206
+ * Shape of the response body from the adapter
207
+ */
208
+ export declare type AdapterResponse<T extends ResponseGenerics = ResponseGenerics> = SuccessfulResponse<T> | TimestampedProviderErrorResponse;
130
209
  export declare type SingleNumberResultResponse = {
131
210
  Result: number;
132
211
  Data: {
@@ -1 +0,0 @@
1
- {"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../src/transports/routing.ts"],"names":[],"mappings":";;;AAEA,kCAAqE;AACrE,+CAAkD;AAGlD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,kBAAkB,CAAC,CAAA;AAE7C;;;;GAIG;AACH,MAAa,gBAAgB;IAI3B;IACE,6GAA6G;IACtG,UAA2C;IAClD,+FAA+F;IACvF,KAGG;QALJ,eAAU,GAAV,UAAU,CAAiC;QAE1C,UAAK,GAAL,KAAK,CAGF;IACV,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,aAAiD,EACjD,YAAoB;QAEpB,MAAM,CAAC,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,aAAa,CAAC,CAAA;QAC9E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;YACjD,M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