@chainlink/external-adapter-framework 0.9.0 → 0.10.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.
- package/README.md +67 -0
- package/adapter/basic.d.ts +51 -7
- package/adapter/basic.js +184 -4
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +6 -6
- package/adapter/endpoint.js +1 -0
- package/adapter/endpoint.js.map +1 -1
- package/adapter/price.d.ts +38 -8
- package/adapter/price.js +43 -1
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +40 -15
- package/background-executor.js +21 -5
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +11 -17
- package/cache/index.js +9 -51
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +28 -11
- package/config/index.js +63 -46
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +17 -25
- package/examples/bank-frick/accounts.js +23 -13
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/config/index.d.ts +5 -0
- package/examples/bank-frick/config/index.js +5 -0
- package/examples/bank-frick/config/index.js.map +1 -1
- package/examples/bank-frick/index.d.ts +1 -15
- package/examples/bank-frick/index.js +1 -1
- package/examples/coingecko/src/config/index.d.ts +7 -0
- package/examples/coingecko/src/config/index.js +8 -1
- package/examples/coingecko/src/config/index.js.map +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +19 -4
- package/examples/coingecko/src/crypto-utils.js +1 -2
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +20 -3
- package/examples/coingecko/src/endpoint/coins.js +2 -2
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto.d.ts +2 -4
- package/examples/coingecko/src/endpoint/crypto.js +2 -2
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -1
- package/examples/coingecko/src/endpoint/dominance.d.ts +2 -2
- package/examples/coingecko/src/endpoint/dominance.js +2 -2
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -1
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -1
- package/examples/coingecko/src/global-utils.d.ts +18 -3
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +3 -1
- package/examples/coingecko/src/index.js.map +1 -1
- package/examples/cryptocompare/src/config/index.d.ts +7 -0
- package/examples/cryptocompare/src/config/index.js +8 -1
- package/examples/cryptocompare/src/config/index.js.map +1 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +14 -2
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +3 -1
- package/examples/cryptocompare/src/index.js.map +1 -1
- package/examples/genesis/config/index.d.ts +5 -0
- package/examples/genesis/config/index.js +5 -0
- package/examples/genesis/config/index.js.map +1 -1
- package/examples/genesis/index.js +1 -1
- package/examples/genesis/sseStream.d.ts +13 -2
- package/examples/genesis/sseStream.js +4 -1
- package/examples/genesis/sseStream.js.map +1 -1
- package/index.d.ts +2 -1
- package/index.js +4 -6
- package/index.js.map +1 -1
- package/metrics/index.d.ts +2 -0
- package/metrics/index.js +5 -4
- package/metrics/index.js.map +1 -1
- package/metrics/util.d.ts +5 -5
- package/metrics/util.js +2 -2
- package/metrics/util.js.map +1 -1
- package/package.json +8 -10
- package/rate-limiting/background/fixed-frequency.d.ts +2 -3
- package/rate-limiting/background/fixed-frequency.js.map +1 -1
- package/rate-limiting/index.d.ts +4 -4
- package/rate-limiting/index.js +1 -1
- package/rate-limiting/index.js.map +1 -1
- package/rate-limiting/request/simple-counting.d.ts +2 -3
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/transports/batch-warming.d.ts +40 -18
- package/transports/batch-warming.js +45 -18
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +65 -31
- package/transports/index.js +2 -59
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +3 -3
- package/transports/metrics.js +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +42 -30
- package/transports/rest.js +25 -30
- package/transports/rest.js.map +1 -1
- package/transports/routing.d.ts +22 -0
- package/transports/routing.js +60 -0
- package/transports/routing.js.map +1 -0
- package/transports/sse.d.ts +40 -20
- package/transports/sse.js +10 -8
- package/transports/sse.js.map +1 -1
- package/transports/util.d.ts +3 -1
- package/transports/util.js +69 -39
- package/transports/util.js.map +1 -1
- package/transports/websocket.d.ts +41 -26
- package/transports/websocket.js +16 -19
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +2 -0
- package/util/logger.js +4 -7
- package/util/logger.js.map +1 -1
- package/util/request.d.ts +46 -10
- package/util/subscription-set/subscription-set.d.ts +1 -1
- package/util/subscription-set/subscription-set.js +1 -1
- package/util/subscription-set/subscription-set.js.map +1 -1
- package/util/test-payload-loader.d.ts +1 -0
- package/util/test-payload-loader.js +2 -1
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +1 -3
- package/validation/error.js +2 -4
- package/validation/error.js.map +1 -1
- package/validation/index.js +28 -18
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +0 -1
- package/validation/input-params.js +0 -28
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +1 -2
- package/validation/input-validator.js.map +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +0 -7
- package/examples/coingecko-old/batch-warming.js +0 -54
- package/examples/coingecko-old/batch-warming.js.map +0 -1
- package/examples/coingecko-old/index.d.ts +0 -2
- package/examples/coingecko-old/index.js +0 -12
- package/examples/coingecko-old/index.js.map +0 -1
- package/examples/coingecko-old/rest.d.ts +0 -12
- package/examples/coingecko-old/rest.js +0 -55
- package/examples/coingecko-old/rest.js.map +0 -1
- package/examples/ncfx/config/index.d.ts +0 -12
- package/examples/ncfx/config/index.js +0 -16
- package/examples/ncfx/config/index.js.map +0 -1
- package/examples/ncfx/index.d.ts +0 -13
- package/examples/ncfx/index.js +0 -12
- package/examples/ncfx/index.js.map +0 -1
- package/examples/ncfx/websocket.d.ts +0 -47
- package/examples/ncfx/websocket.js +0 -74
- package/examples/ncfx/websocket.js.map +0 -1
- package/validation/override-functions.d.ts +0 -3
- package/validation/override-functions.js +0 -41
- package/validation/override-functions.js.map +0 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
|
-
import {
|
|
1
|
+
import WebSocket, { ClientOptions, RawData } from 'ws';
|
|
2
|
+
import { EndpointContext, AdapterDependencies } from '../adapter';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
|
-
import { AdapterConfig
|
|
4
|
+
import { AdapterConfig } from '../config';
|
|
5
5
|
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
6
6
|
import { SubscriptionSet } from '../util';
|
|
7
|
-
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
8
|
-
import { Transport } from './';
|
|
9
|
-
|
|
7
|
+
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
8
|
+
import { Transport, TransportGenerics } from './';
|
|
9
|
+
export { WebSocket, RawData as WebSocketRawData };
|
|
10
|
+
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined, options?: ClientOptions) => WebSocket;
|
|
10
11
|
export declare class WebSocketClassProvider {
|
|
11
12
|
static ctor: WebSocketClass;
|
|
12
13
|
static set(ctor: WebSocketClass): void;
|
|
@@ -15,9 +16,11 @@ export declare class WebSocketClassProvider {
|
|
|
15
16
|
/**
|
|
16
17
|
* Config object that is provided to the WebSocketTransport constructor.
|
|
17
18
|
*/
|
|
18
|
-
export interface WebSocketTransportConfig<
|
|
19
|
+
export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics> {
|
|
19
20
|
/** Endpoint to which to open the WS connection*/
|
|
20
|
-
url: (context:
|
|
21
|
+
url: (context: EndpointContext<T>) => Promise<string> | string;
|
|
22
|
+
/** Optional parameters used when establishing the WebSocket connection */
|
|
23
|
+
options?: (context: EndpointContext<T>) => Promise<ClientOptions> | ClientOptions;
|
|
21
24
|
/** Map of handlers for different WS lifecycle events */
|
|
22
25
|
handlers: {
|
|
23
26
|
/**
|
|
@@ -26,7 +29,7 @@ export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, Cu
|
|
|
26
29
|
* @param wsConnection - the WebSocket with an established connection
|
|
27
30
|
* @returns an empty Promise, or void
|
|
28
31
|
*/
|
|
29
|
-
open: (wsConnection: WebSocket, context:
|
|
32
|
+
open: (wsConnection: WebSocket, context: EndpointContext<T>) => Promise<void> | void;
|
|
30
33
|
/**
|
|
31
34
|
* Handles when the WS receives a message
|
|
32
35
|
*
|
|
@@ -34,7 +37,7 @@ export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, Cu
|
|
|
34
37
|
* @param context - the background context for the Adapter
|
|
35
38
|
* @returns a list of cache entries of adapter responses to set in the cache
|
|
36
39
|
*/
|
|
37
|
-
message: (message:
|
|
40
|
+
message: (message: T['Provider']['WsMessage'], context: EndpointContext<T>) => ProviderResult<T>[] | undefined;
|
|
38
41
|
};
|
|
39
42
|
/** Map of "builders", functions that will be used to prepare specific WS messages */
|
|
40
43
|
builders: {
|
|
@@ -44,37 +47,49 @@ export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, Cu
|
|
|
44
47
|
* @param params - the body of the adapter request
|
|
45
48
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
46
49
|
*/
|
|
47
|
-
subscribeMessage: (params:
|
|
50
|
+
subscribeMessage: (params: T['Request']['Params']) => unknown;
|
|
48
51
|
/**
|
|
49
52
|
* Builds a WS message that will be sent to unsubscribe to a specific feed
|
|
50
53
|
*
|
|
51
54
|
* @param params - the body of the adapter request
|
|
52
55
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
53
56
|
*/
|
|
54
|
-
unsubscribeMessage: (params:
|
|
57
|
+
unsubscribeMessage: (params: T['Request']['Params']) => unknown;
|
|
55
58
|
};
|
|
56
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
62
|
+
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
63
|
+
*/
|
|
64
|
+
declare type WebsocketTransportGenerics = TransportGenerics & {
|
|
65
|
+
/**
|
|
66
|
+
* Type details for any provider specific interfaces.
|
|
67
|
+
*/
|
|
68
|
+
Provider: {
|
|
69
|
+
/**
|
|
70
|
+
* Structure of any message that will come through the websocket connection.
|
|
71
|
+
*/
|
|
72
|
+
WsMessage: unknown;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
57
75
|
/**
|
|
58
76
|
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
59
77
|
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
60
78
|
*
|
|
61
|
-
* @typeParam
|
|
62
|
-
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
79
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[WebsocketTransportGenerics]])
|
|
63
80
|
*/
|
|
64
|
-
export declare class WebSocketTransport<
|
|
81
|
+
export declare class WebSocketTransport<T extends WebsocketTransportGenerics> implements Transport<T> {
|
|
65
82
|
private config;
|
|
66
|
-
cache: Cache
|
|
83
|
+
cache: Cache<AdapterResponse<T['Response']>>;
|
|
67
84
|
rateLimiter: BackgroundExecuteRateLimiter;
|
|
68
|
-
subscriptionSet: SubscriptionSet<
|
|
69
|
-
localSubscriptions:
|
|
85
|
+
subscriptionSet: SubscriptionSet<T['Request']['Params']>;
|
|
86
|
+
localSubscriptions: T['Request']['Params'][];
|
|
70
87
|
wsConnection: WebSocket;
|
|
71
|
-
constructor(config: WebSocketTransportConfig<
|
|
72
|
-
initialize(dependencies: AdapterDependencies,
|
|
73
|
-
|
|
74
|
-
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
88
|
+
constructor(config: WebSocketTransportConfig<T>);
|
|
89
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
90
|
+
registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
75
91
|
serializeMessage(payload: unknown): string;
|
|
76
|
-
deserializeMessage(data: WebSocket.Data):
|
|
77
|
-
establishWsConnection(context:
|
|
78
|
-
backgroundExecute(context:
|
|
92
|
+
deserializeMessage(data: WebSocket.Data): T['Provider']['WsMessage'];
|
|
93
|
+
establishWsConnection(context: EndpointContext<T>, url: string, options?: WebSocket.ClientOptions | undefined): Promise<unknown>;
|
|
94
|
+
backgroundExecute(context: EndpointContext<T>): Promise<number>;
|
|
79
95
|
}
|
|
80
|
-
export {};
|
package/transports/websocket.js
CHANGED
|
@@ -26,8 +26,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.WebSocketTransport = exports.WebSocketClassProvider = void 0;
|
|
29
|
+
exports.WebSocketTransport = exports.WebSocketClassProvider = exports.WebSocket = void 0;
|
|
30
30
|
const ws_1 = __importDefault(require("ws"));
|
|
31
|
+
exports.WebSocket = ws_1.default;
|
|
31
32
|
const util_1 = require("../util");
|
|
32
33
|
const _1 = require("./");
|
|
33
34
|
const transportMetrics = __importStar(require("./metrics"));
|
|
@@ -46,8 +47,7 @@ WebSocketClassProvider.ctor = ws_1.default;
|
|
|
46
47
|
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
47
48
|
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
48
49
|
*
|
|
49
|
-
* @typeParam
|
|
50
|
-
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
50
|
+
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[WebsocketTransportGenerics]])
|
|
51
51
|
*/
|
|
52
52
|
class WebSocketTransport {
|
|
53
53
|
constructor(config) {
|
|
@@ -56,17 +56,13 @@ class WebSocketTransport {
|
|
|
56
56
|
// This one would not; this is always local state
|
|
57
57
|
this.localSubscriptions = [];
|
|
58
58
|
}
|
|
59
|
-
async initialize(dependencies,
|
|
59
|
+
async initialize(dependencies, config, endpointName) {
|
|
60
60
|
this.cache = dependencies.cache;
|
|
61
61
|
this.rateLimiter = dependencies.backgroundExecuteRateLimiter;
|
|
62
62
|
this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
async setup(req, config) {
|
|
69
|
-
logger.debug(`Adding entry to subscription set: [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
64
|
+
async registerRequest(req, config) {
|
|
65
|
+
logger.debug(`Adding entry to subscription set (ttl: ${config.WS_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
70
66
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
71
67
|
}
|
|
72
68
|
serializeMessage(payload) {
|
|
@@ -75,11 +71,10 @@ class WebSocketTransport {
|
|
|
75
71
|
deserializeMessage(data) {
|
|
76
72
|
return JSON.parse(data.toString());
|
|
77
73
|
}
|
|
78
|
-
establishWsConnection(context) {
|
|
74
|
+
establishWsConnection(context, url, options) {
|
|
79
75
|
return new Promise((resolve) => {
|
|
80
76
|
const ctor = WebSocketClassProvider.get();
|
|
81
|
-
|
|
82
|
-
this.wsConnection = new ctor(url);
|
|
77
|
+
this.wsConnection = new ctor(url, undefined, options);
|
|
83
78
|
this.wsConnection.addEventListener('open', async (event) => {
|
|
84
79
|
logger.debug(`Opened websocket connection. (event type ${event.type})`);
|
|
85
80
|
await this.config.handlers.open(this.wsConnection, context);
|
|
@@ -119,14 +114,14 @@ class WebSocketTransport {
|
|
|
119
114
|
const desiredSubs = await this.subscriptionSet.getAll();
|
|
120
115
|
// Keep track of active subscriptions for background execute
|
|
121
116
|
transportMetrics.bgExecuteSubscriptionSetCount
|
|
122
|
-
.labels({ endpoint: context.
|
|
117
|
+
.labels({ endpoint: context.endpointName, transport_type: 'websocket' })
|
|
123
118
|
.set(desiredSubs.length);
|
|
124
119
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
125
|
-
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
120
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.map((ls) => JSON.stringify(ls)).includes(JSON.stringify(s)));
|
|
126
121
|
const subscribes = subscribeParams
|
|
127
122
|
.map(this.config.builders.subscribeMessage)
|
|
128
123
|
.map(this.serializeMessage);
|
|
129
|
-
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
124
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.map((ds) => JSON.stringify(ds)).includes(JSON.stringify(s)));
|
|
130
125
|
const unsubscribes = unsubscribeParams
|
|
131
126
|
.map(this.config.builders.unsubscribeMessage)
|
|
132
127
|
.map(this.serializeMessage);
|
|
@@ -143,11 +138,13 @@ class WebSocketTransport {
|
|
|
143
138
|
// No new subs && connection -> unsubs only
|
|
144
139
|
if (!subscribes.length && !this.wsConnection) {
|
|
145
140
|
logger.debug('No entries in subscription set and no established connection, skipping');
|
|
146
|
-
return this.rateLimiter.msUntilNextExecution(context.
|
|
141
|
+
return this.rateLimiter.msUntilNextExecution(context.endpointName);
|
|
147
142
|
}
|
|
148
143
|
if (!this.wsConnection && subscribes.length) {
|
|
149
144
|
logger.debug('No established connection and new subscriptions available, connecting to WS');
|
|
150
|
-
await this.
|
|
145
|
+
const url = context.adapterConfig.WS_API_ENDPOINT || (await this.config.url(context));
|
|
146
|
+
const options = this.config.options && (await this.config.options(context));
|
|
147
|
+
await this.establishWsConnection(context, url, options);
|
|
151
148
|
}
|
|
152
149
|
logger.debug('Sending subs/unsubs if there are any');
|
|
153
150
|
const messages = unsubscribes.concat(subscribes);
|
|
@@ -160,7 +157,7 @@ class WebSocketTransport {
|
|
|
160
157
|
logger.debug('Setting local state to cache value');
|
|
161
158
|
this.localSubscriptions = desiredSubs;
|
|
162
159
|
logger.debug('Background execute complete');
|
|
163
|
-
return this.rateLimiter.msUntilNextExecution(context.
|
|
160
|
+
return this.rateLimiter.msUntilNextExecution(context.endpointName);
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
163
|
exports.WebSocketTransport = WebSocketTransport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAsD;AAW7C,oBAXF,YAAS,CAWE;AANlB,kCAAqD;AAErD,yBAA+E;AAC/E,4DAA6C;AAK7C,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAQ/C,MAAa,sBAAsB;IAGjC,MAAM,CAAC,GAAG,CAAC,IAAoB;QAC7B,IAAI,CAAC,IAAI,GAAG,IAA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AC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;IACpE,CAAC;CACF;AA5JD,gDA4JC"}
|
package/util/logger.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import pino from 'pino';
|
|
|
3
3
|
import { AdapterRequest } from './request';
|
|
4
4
|
import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
+
import { CensorKeyValue } from './censor/censor-list';
|
|
6
7
|
export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
|
|
7
8
|
export declare type Store = {
|
|
8
9
|
correlationId: string;
|
|
@@ -45,3 +46,4 @@ export declare const makeLogger: (layer: string) => pino.Logger<{
|
|
|
45
46
|
} | undefined;
|
|
46
47
|
} & pino.ChildLoggerOptions>;
|
|
47
48
|
export declare const loggingContextMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;
|
|
49
|
+
export declare function censor(obj: any, censorList: CensorKeyValue[]): any;
|
package/util/logger.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loggingContextMiddleware = exports.makeLogger = exports.colorFactory = exports.COLORS = exports.asyncLocalStorage = void 0;
|
|
6
|
+
exports.censor = exports.loggingContextMiddleware = exports.makeLogger = exports.colorFactory = exports.COLORS = exports.asyncLocalStorage = void 0;
|
|
7
7
|
const pino_1 = __importDefault(require("pino"));
|
|
8
8
|
const config_1 = require("../config");
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
@@ -39,9 +39,7 @@ const baseLogger = (0, pino_1.default)({
|
|
|
39
39
|
}
|
|
40
40
|
return {};
|
|
41
41
|
},
|
|
42
|
-
transport: process.env['DEBUG'] === 'true'
|
|
43
|
-
? debugTransport
|
|
44
|
-
: undefined,
|
|
42
|
+
transport: process.env['DEBUG'] === 'true' ? debugTransport : undefined,
|
|
45
43
|
});
|
|
46
44
|
exports.COLORS = [
|
|
47
45
|
'\u001b[31;1m',
|
|
@@ -98,9 +96,7 @@ const getNextColor = (0, exports.colorFactory)(exports.COLORS);
|
|
|
98
96
|
*/
|
|
99
97
|
const makeLogger = (layer) => baseLogger.child({
|
|
100
98
|
layer,
|
|
101
|
-
color: process.env['DEBUG'] === 'true'
|
|
102
|
-
? getNextColor()
|
|
103
|
-
: undefined,
|
|
99
|
+
color: process.env['DEBUG'] === 'true' ? getNextColor() : undefined,
|
|
104
100
|
});
|
|
105
101
|
exports.makeLogger = makeLogger;
|
|
106
102
|
const loggingContextMiddleware = (req, res, done) => {
|
|
@@ -119,4 +115,5 @@ function censor(obj, censorList) {
|
|
|
119
115
|
});
|
|
120
116
|
return JSON.parse(stringified);
|
|
121
117
|
}
|
|
118
|
+
exports.censor = censor;
|
|
122
119
|
//# sourceMappingURL=logger.js.map
|
package/util/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,sCAAwC;AAGxC,mCAAmC;AACnC,uDAAoD;AACpD,uEAAiE;AAEpD,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAE,CAAA;AAMxD,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,aAAa;IACrB,OAAO,EAAE;QACP,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,OAAO;QACnB,MAAM,EAAE,wCAAwC;QAChD,aAAa,EAAE,wDAAwD;QACvE,aAAa,EAAE,uBAAuB;KACvC;CACF,CAAA;AAED,wEAAwE;AACxE,MAAM,UAAU,GAAG,IAAA,cAAI,EAAC;IACtB,KAAK,EAAE,OAA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;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
export declare type Merge<T1, T2> = {
|
|
10
|
+
[K in keyof T1 | keyof T2]: K extends keyof T2 ? T2[K] : K extends keyof T1 ? T1[K] : never;
|
|
11
|
+
};
|
|
9
12
|
/**
|
|
10
13
|
* Structure for the body of all requests that will be sent to the adapter
|
|
11
14
|
*/
|
|
@@ -43,11 +46,11 @@ export declare type AdapterRouteGeneric = {
|
|
|
43
46
|
/**
|
|
44
47
|
* Structure for all requests incoming to this adapter
|
|
45
48
|
*/
|
|
46
|
-
export declare type AdapterRequest<T =
|
|
49
|
+
export declare type AdapterRequest<T extends RequestGenerics = RequestGenerics> = FastifyRequest<AdapterRouteGeneric> & {
|
|
47
50
|
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
48
51
|
body: EmptyBody;
|
|
49
52
|
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
50
|
-
requestContext: AdapterRequestContext<T>;
|
|
53
|
+
requestContext: AdapterRequestContext<T['Params']>;
|
|
51
54
|
};
|
|
52
55
|
/**
|
|
53
56
|
* Metadata for a particular request
|
|
@@ -74,29 +77,62 @@ export declare type AdapterRequestData = Record<string, unknown> & {
|
|
|
74
77
|
endpoint?: string;
|
|
75
78
|
};
|
|
76
79
|
/**
|
|
77
|
-
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
80
|
+
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to.
|
|
78
81
|
*/
|
|
79
|
-
export interface ProviderResult<
|
|
82
|
+
export interface ProviderResult<T extends {
|
|
83
|
+
Request: RequestGenerics;
|
|
84
|
+
Response: ResponseGenerics;
|
|
85
|
+
}> {
|
|
80
86
|
/** The set of parameters that uniquely relate to the response */
|
|
81
|
-
params: Params;
|
|
82
|
-
/**
|
|
83
|
-
value:
|
|
87
|
+
params: T['Request']['Params'];
|
|
88
|
+
/** Value that will be included in the result property of the response */
|
|
89
|
+
value: T['Response']['Result'];
|
|
84
90
|
}
|
|
91
|
+
export declare type EmptyObject = Object;
|
|
92
|
+
/**
|
|
93
|
+
* Helper struct type that provides detail about the incoming Adapter Request
|
|
94
|
+
*/
|
|
95
|
+
export declare type RequestGenerics = {
|
|
96
|
+
/**
|
|
97
|
+
* Type for the parameters sent to the EA in the data property of the body.
|
|
98
|
+
*/
|
|
99
|
+
Params: EmptyObject;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Helper struct type that provides detail about the outgoing Adapter Response
|
|
103
|
+
*/
|
|
104
|
+
export declare type ResponseGenerics = {
|
|
105
|
+
/**
|
|
106
|
+
* Type for the data property of the response.
|
|
107
|
+
*/
|
|
108
|
+
Data: unknown;
|
|
109
|
+
/**
|
|
110
|
+
* Type for the result property of the response.
|
|
111
|
+
* This is mostly used for OCR, and corresponds to one "word" when talking about it from an on-chain perspective.
|
|
112
|
+
*/
|
|
113
|
+
Result: string | number | null;
|
|
114
|
+
};
|
|
85
115
|
/**
|
|
86
116
|
* Shape of the response body from the adapter
|
|
87
117
|
*/
|
|
88
|
-
export declare type AdapterResponse<T =
|
|
118
|
+
export declare type AdapterResponse<T extends ResponseGenerics = ResponseGenerics> = {
|
|
89
119
|
/** HTTP status code */
|
|
90
120
|
statusCode: number;
|
|
91
121
|
/** Response data, holds "result" for Flux Monitor */
|
|
92
|
-
data: T;
|
|
122
|
+
data: T['Data'];
|
|
93
123
|
/** Result value used for OCR */
|
|
94
|
-
result:
|
|
124
|
+
result: T['Result'];
|
|
95
125
|
/** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
|
|
96
126
|
maxAge?: number;
|
|
97
127
|
/** Metadata relevant to this request */
|
|
98
128
|
meta?: AdapterRequestMeta;
|
|
99
129
|
};
|
|
130
|
+
export declare type SingleNumberResultResponse = {
|
|
131
|
+
Result: number;
|
|
132
|
+
Data: {
|
|
133
|
+
result: number;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
100
136
|
export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
101
137
|
export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
|
|
102
138
|
export {};
|
|
@@ -14,6 +14,6 @@ export declare class SubscriptionSetFactory {
|
|
|
14
14
|
private cacheType;
|
|
15
15
|
private redisClient?;
|
|
16
16
|
private adapterName?;
|
|
17
|
-
constructor(config: AdapterConfig,
|
|
17
|
+
constructor(config: AdapterConfig, adapterName: string, redisClient?: Redis);
|
|
18
18
|
buildSet<T>(endpointName: string): SubscriptionSet<T>;
|
|
19
19
|
}
|
|
@@ -4,7 +4,7 @@ exports.SubscriptionSetFactory = void 0;
|
|
|
4
4
|
const expiring_sorted_set_1 = require("./expiring-sorted-set");
|
|
5
5
|
const redis_sorted_set_1 = require("./redis-sorted-set");
|
|
6
6
|
class SubscriptionSetFactory {
|
|
7
|
-
constructor(config,
|
|
7
|
+
constructor(config, adapterName, redisClient) {
|
|
8
8
|
this.cacheType = config.CACHE_TYPE;
|
|
9
9
|
this.redisClient = redisClient;
|
|
10
10
|
this.adapterName = adapterName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,WAAmB;QACzE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,QAAQ,CAAI,YAAoB;QAC9B,QAAQ,IAAI,CAAC,SAAS,EAAE;YACtB,KAAK,OAAO;gBACV,OAAO,IAAI,uCAAiB,EAAK,CAAA;YACnC,KAAK,OAAO,CAAC,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBACrB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;iBAChF;gBACD,wDAAwD;gBACxD,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,YAAY,kBAAkB,CAAA;gBAChF,OAAO,IAAI,uCAAoB,CAAI,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF;AAzBD,wDAyBC"}
|
|
@@ -22,4 +22,5 @@ declare type TestPayload = (Payload & {
|
|
|
22
22
|
* @returns the parsed payload with individual requests
|
|
23
23
|
*/
|
|
24
24
|
export declare function loadTestPayload(fileName?: string): TestPayload;
|
|
25
|
+
export declare function resolvePayload(fileName?: string): Payload | null;
|
|
25
26
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadTestPayload = void 0;
|
|
6
|
+
exports.resolvePayload = exports.loadTestPayload = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -81,4 +81,5 @@ function resolvePayload(fileName) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
+
exports.resolvePayload = resolvePayload;
|
|
84
85
|
//# sourceMappingURL=test-payload-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-payload-loader.js","sourceRoot":"","sources":["../../../src/util/test-payload-loader.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,4CAAmB;AACnB,gDAAuB;AACvB,qCAAqC;AAGrC,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,mBAAmB,CAAC,CAAA;AAe9C;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,QAAiB;IAC/C,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC;QACtB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,EAAE;iBACb;aACF;SACF;KACF,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI;QACF,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE;YAC5C,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,4CAA4C,CAAC,CAAC,CAAA;SAC9F;QACD,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;KACxC;IAAC,OAAO,CAAU,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,2BAA4B,CAAW,CAAC,OAAO,EAAE,CAAC,CAAA;QAC9D,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;QACpD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;KAC3B;AACH,CAAC;AA3BD,0CA2BC;AAED,
|
|
1
|
+
{"version":3,"file":"test-payload-loader.js","sourceRoot":"","sources":["../../../src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C,MAAM;QACN,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AA7BD,wCA6BC"}
|
package/validation/error.d.ts
CHANGED
|
@@ -8,14 +8,12 @@ declare type ErrorFull = ErrorBasic & {
|
|
|
8
8
|
cause: string;
|
|
9
9
|
};
|
|
10
10
|
export declare type AdapterErrorResponse = {
|
|
11
|
-
jobRunID: string;
|
|
12
11
|
status: string;
|
|
13
12
|
statusCode: number;
|
|
14
13
|
providerStatusCode?: number;
|
|
15
14
|
error: ErrorBasic | ErrorFull;
|
|
16
15
|
};
|
|
17
16
|
export declare class AdapterError extends Error {
|
|
18
|
-
jobRunID: string;
|
|
19
17
|
status: string;
|
|
20
18
|
statusCode: number;
|
|
21
19
|
cause: unknown;
|
|
@@ -26,7 +24,7 @@ export declare class AdapterError extends Error {
|
|
|
26
24
|
metricsLabel?: HttpRequestType;
|
|
27
25
|
name: string;
|
|
28
26
|
message: string;
|
|
29
|
-
constructor({
|
|
27
|
+
constructor({ status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
30
28
|
toJSONResponse(): AdapterErrorResponse;
|
|
31
29
|
}
|
|
32
30
|
export declare class AdapterInputError extends AdapterError {
|
package/validation/error.js
CHANGED
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AdapterCustomError = exports.AdapterConnectionError = exports.AdapterDataProviderError = exports.AdapterTimeoutError = exports.AdapterRateLimitError = exports.AdapterInputError = exports.AdapterError = void 0;
|
|
4
4
|
const constants_1 = require("../metrics/constants");
|
|
5
5
|
class AdapterError extends Error {
|
|
6
|
-
constructor({
|
|
6
|
+
constructor({ status = 'errored', statusCode = 500, name = 'AdapterError', message = 'There was an unexpected error in the adapter.', cause, url, errorResponse, feedID, providerStatusCode, metricsLabel = constants_1.HttpRequestType.ADAPTER_ERROR, }) {
|
|
7
7
|
super(message);
|
|
8
|
-
this.jobRunID = jobRunID;
|
|
9
8
|
this.status = status;
|
|
10
9
|
this.statusCode = statusCode;
|
|
11
10
|
this.name = name;
|
|
@@ -22,7 +21,7 @@ class AdapterError extends Error {
|
|
|
22
21
|
this.metricsLabel = metricsLabel;
|
|
23
22
|
}
|
|
24
23
|
toJSONResponse() {
|
|
25
|
-
const showDebugInfo = process.env['
|
|
24
|
+
const showDebugInfo = process.env['DEBUG'] === 'true';
|
|
26
25
|
const errorBasic = {
|
|
27
26
|
name: this.name,
|
|
28
27
|
message: this.message,
|
|
@@ -32,7 +31,6 @@ class AdapterError extends Error {
|
|
|
32
31
|
};
|
|
33
32
|
const errorFull = { ...errorBasic, stack: this.stack, cause: this.cause };
|
|
34
33
|
return {
|
|
35
|
-
jobRunID: this.jobRunID,
|
|
36
34
|
status: this.status,
|
|
37
35
|
statusCode: this.statusCode,
|
|
38
36
|
providerStatusCode: this.providerStatusCode,
|
package/validation/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/validation/error.ts"],"names":[],"mappings":";;;AAAA,oDAAsD;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/validation/error.ts"],"names":[],"mappings":";;;AAAA,oDAAsD;AAkBtD,MAAa,YAAa,SAAQ,KAAK;IAarC,YAAY,EACV,MAAM,GAAG,SAAS,EAClB,UAAU,GAAG,GAAG,EAChB,IAAI,GAAG,cAAc,EACrB,OAAO,GAAG,+CAA+C,EACzD,KAAK,EACL,GAAG,EACH,aAAa,EACb,MAAM,EACN,kBAAkB,EAClB,YAAY,GAAG,2BAAe,CAAC,aAAa,GACtB;QACtB,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,C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GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACrE,CAAC;CACF;AAJD,sDAIC;AACD,MAAa,mBAAoB,SAAQ,YAAY;IACnD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,aAAa,EAAE,CAAC,CAAA;IAClE,CAAC;CACF;AAJD,kDAIC;AACD,MAAa,wBAAyB,SAAQ,YAAY;IACxD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC7D,CAAC;CACF;AAJD,4DAIC;AACD,MAAa,sBAAuB,SAAQ,YAAY;IACtD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACrE,CAAC;CACF;AAJD,wDAIC;AACD,MAAa,kBAAmB,SAAQ,YAAY;IAClD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,YAAY,EAAE,CAAC,CAAA;IACjE,CAAC;CACF;AAJD,gDAIC"}
|
package/validation/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const cache_1 = require("../cache");
|
|
|
5
5
|
const util_1 = require("../metrics/util");
|
|
6
6
|
const util_2 = require("../util");
|
|
7
7
|
const error_1 = require("./error");
|
|
8
|
-
const override_functions_1 = require("./override-functions");
|
|
9
8
|
const errorCatcherLogger = (0, util_2.makeLogger)('ErrorCatchingMiddleware');
|
|
10
9
|
const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
11
10
|
if (req.headers['content-type'] !== 'application/json') {
|
|
@@ -40,7 +39,7 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
40
39
|
statusCode: 404,
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
|
-
const validatedData = endpoint.validator.validateInput(
|
|
42
|
+
const validatedData = endpoint.validator.validateInput(requestBody.data);
|
|
44
43
|
req.requestContext = {
|
|
45
44
|
cacheKey: '',
|
|
46
45
|
data: validatedData,
|
|
@@ -50,25 +49,31 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
50
49
|
// Add metrics meta which includes feedId to the request
|
|
51
50
|
// Perform prior to overrides to maintain consistent Feed IDs across adapters
|
|
52
51
|
const metrics = (0, util_1.getMetricsMeta)({
|
|
53
|
-
|
|
52
|
+
inputParameters: endpoint.inputParameters,
|
|
54
53
|
adapterConfig: adapter.config,
|
|
55
54
|
}, validatedData);
|
|
56
55
|
req.requestContext = { ...req.requestContext, meta: { metrics } };
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
// Run any request transforms that might have been defined in the adapter.
|
|
58
|
+
// This is the last time modifications are supposed to happen to the request.
|
|
59
|
+
adapter.runRequestTransforms(req);
|
|
60
|
+
// Now that all the transformations have been applied, all that's left is calculating the cache key
|
|
61
|
+
if (endpoint.cacheKeyGenerator) {
|
|
62
|
+
let cacheKey;
|
|
63
|
+
cacheKey = endpoint.cacheKeyGenerator(req.requestContext.data);
|
|
64
|
+
if (cacheKey.length > adapter.config.MAX_COMMON_KEY_SIZE) {
|
|
65
|
+
errorCatcherLogger.warn(`Generated custom cache key for adapter request is bigger than the MAX_COMMON_KEY_SIZE and will be truncated`);
|
|
66
|
+
cacheKey = cacheKey.slice(0, adapter.config.MAX_COMMON_KEY_SIZE);
|
|
67
|
+
}
|
|
68
|
+
req.requestContext.cacheKey = cacheKey;
|
|
61
69
|
}
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
else {
|
|
71
|
+
req.requestContext.cacheKey = (0, cache_1.calculateCacheKey)({
|
|
72
|
+
endpointName: endpoint.name,
|
|
73
|
+
inputParameters: endpoint.inputParameters,
|
|
74
|
+
adapterConfig: adapter.config,
|
|
75
|
+
}, req.requestContext.data);
|
|
64
76
|
}
|
|
65
|
-
// Swaps the 'base' parameter if any overrides are found in the request or the adapter configuration
|
|
66
|
-
// Supports 'base' input as string or string[]
|
|
67
|
-
(0, override_functions_1.performSymbolOverrides)(adapter, req);
|
|
68
|
-
req.requestContext.cacheKey = (0, cache_1.calculateCacheKey)({
|
|
69
|
-
adapterEndpoint: endpoint,
|
|
70
|
-
adapterConfig: adapter.config,
|
|
71
|
-
}, req.requestContext.data);
|
|
72
77
|
done();
|
|
73
78
|
};
|
|
74
79
|
exports.validatorMiddleware = validatorMiddleware;
|
|
@@ -78,15 +83,20 @@ const errorCatchingMiddleware = (err, req, res) => {
|
|
|
78
83
|
if (req.requestContext) {
|
|
79
84
|
req.requestContext.meta = { ...req.requestContext?.meta, error: err };
|
|
80
85
|
}
|
|
86
|
+
// Add the request context to the error so that we can check things like incoming params, endpoint, etc
|
|
87
|
+
const errorWithContext = {
|
|
88
|
+
requestContext: req.requestContext,
|
|
89
|
+
...err,
|
|
90
|
+
};
|
|
81
91
|
if (err instanceof error_1.AdapterError) {
|
|
82
92
|
// We want to log these as warn, because although they are to be expected, NOPs should
|
|
83
93
|
// Only use "correct" job specs and therefore not hit adapters with invalid requests.
|
|
84
|
-
errorCatcherLogger.warn(
|
|
94
|
+
errorCatcherLogger.warn(errorWithContext);
|
|
85
95
|
res.status(err.statusCode).send(err.toJSONResponse());
|
|
86
96
|
}
|
|
87
97
|
else {
|
|
88
|
-
errorCatcherLogger.error(
|
|
89
|
-
res.status(
|
|
98
|
+
errorCatcherLogger.error(errorWithContext);
|
|
99
|
+
res.status(500).send(err.message || 'There was an unexpected error in the adapter.');
|
|
90
100
|
}
|
|
91
101
|
};
|
|
92
102
|
exports.errorCatchingMiddleware = errorCatchingMiddleware;
|