@chainlink/external-adapter-framework 0.8.1 → 0.9.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.
- package/adapter/basic.d.ts +6 -50
- package/adapter/basic.js +2 -165
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +6 -6
- package/adapter/endpoint.js +0 -1
- package/adapter/endpoint.js.map +1 -1
- package/adapter/price.d.ts +8 -38
- package/adapter/price.js +1 -43
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +14 -37
- package/background-executor.js +4 -19
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +16 -9
- package/cache/index.js +46 -4
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +11 -19
- package/config/index.js +39 -54
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +25 -17
- package/examples/bank-frick/accounts.js +13 -23
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/config/index.d.ts +0 -5
- package/examples/bank-frick/config/index.js +0 -5
- package/examples/bank-frick/config/index.js.map +1 -1
- package/examples/bank-frick/index.d.ts +15 -1
- package/examples/bank-frick/index.js +1 -1
- package/examples/coingecko/src/config/index.d.ts +0 -7
- package/examples/coingecko/src/config/index.js +1 -8
- package/examples/coingecko/src/config/index.js.map +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +4 -19
- package/examples/coingecko/src/crypto-utils.js +2 -1
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +3 -20
- 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 +4 -2
- 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 +3 -18
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +1 -3
- package/examples/coingecko/src/index.js.map +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +7 -0
- package/examples/coingecko-old/batch-warming.js +54 -0
- package/examples/coingecko-old/batch-warming.js.map +1 -0
- package/examples/coingecko-old/index.d.ts +2 -0
- package/examples/coingecko-old/index.js +12 -0
- package/examples/coingecko-old/index.js.map +1 -0
- package/examples/coingecko-old/rest.d.ts +12 -0
- package/examples/coingecko-old/rest.js +55 -0
- package/examples/coingecko-old/rest.js.map +1 -0
- package/examples/cryptocompare/src/config/index.d.ts +0 -7
- package/examples/cryptocompare/src/config/index.js +1 -8
- package/examples/cryptocompare/src/config/index.js.map +1 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +2 -14
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +1 -3
- package/examples/cryptocompare/src/index.js.map +1 -1
- package/examples/genesis/config/index.d.ts +0 -5
- package/examples/genesis/config/index.js +0 -5
- package/examples/genesis/config/index.js.map +1 -1
- package/examples/genesis/index.js +1 -1
- package/examples/genesis/sseStream.d.ts +2 -13
- package/examples/genesis/sseStream.js +1 -4
- package/examples/genesis/sseStream.js.map +1 -1
- package/examples/ncfx/config/index.d.ts +12 -0
- package/examples/ncfx/config/index.js +16 -0
- package/examples/ncfx/config/index.js.map +1 -0
- package/examples/ncfx/index.d.ts +13 -0
- package/examples/ncfx/index.js +12 -0
- package/examples/ncfx/index.js.map +1 -0
- package/examples/ncfx/websocket.d.ts +47 -0
- package/examples/ncfx/websocket.js +74 -0
- package/examples/ncfx/websocket.js.map +1 -0
- package/index.d.ts +0 -1
- package/index.js +6 -4
- package/index.js.map +1 -1
- package/metrics/index.d.ts +0 -2
- package/metrics/index.js +4 -5
- package/metrics/index.js.map +1 -1
- package/metrics/util.d.ts +5 -5
- package/metrics/util.js.map +1 -1
- package/package.json +9 -7
- package/rate-limiting/background/fixed-frequency.d.ts +3 -2
- 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 +3 -2
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/transports/batch-warming.d.ts +17 -39
- package/transports/batch-warming.js +16 -43
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +31 -65
- package/transports/index.js +59 -2
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +2 -2
- package/transports/metrics.js +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +30 -42
- package/transports/rest.js +25 -17
- package/transports/rest.js.map +1 -1
- package/transports/sse.d.ts +20 -40
- package/transports/sse.js +8 -10
- package/transports/sse.js.map +1 -1
- package/transports/websocket.d.ts +25 -40
- package/transports/websocket.js +16 -13
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +0 -2
- package/util/logger.js +7 -4
- package/util/logger.js.map +1 -1
- package/util/request.d.ts +10 -46
- 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 +0 -1
- package/util/test-payload-loader.js +1 -2
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +3 -1
- package/validation/error.js +4 -2
- package/validation/error.js.map +1 -1
- package/validation/index.js +17 -26
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +1 -0
- package/validation/input-params.js +28 -0
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +2 -1
- package/validation/input-validator.js.map +1 -1
- package/validation/override-functions.d.ts +3 -0
- package/validation/override-functions.js +41 -0
- package/validation/override-functions.js.map +1 -0
- package/README.md +0 -67
- package/transports/routing.d.ts +0 -21
- package/transports/routing.js +0 -50
- package/transports/routing.js.map +0 -1
package/transports/sse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;AACA,8DAAqC;AAErC,kDAAiD;AACjD,kCAAqD;AAErD,yBAA4D;AAG5D,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,cAAc,CAAC,CAAA;AAOzC,MAAa,YAAY;IAqBvB,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,MAAkC,EAClC,YAAoB;QAEpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAA;QAC/B,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,C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apterDependencies } from '../adapter';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
|
-
import { AdapterConfig } from '../config';
|
|
4
|
+
import { AdapterConfig, SettingsMap } from '../config';
|
|
5
5
|
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
6
6
|
import { SubscriptionSet } from '../util';
|
|
7
|
-
import { AdapterRequest,
|
|
8
|
-
import { Transport
|
|
9
|
-
|
|
10
|
-
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined, options?: ClientOptions) => WebSocket;
|
|
7
|
+
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
8
|
+
import { Transport } from './';
|
|
9
|
+
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined) => WebSocket;
|
|
11
10
|
export declare class WebSocketClassProvider {
|
|
12
11
|
static ctor: WebSocketClass;
|
|
13
12
|
static set(ctor: WebSocketClass): void;
|
|
@@ -16,11 +15,9 @@ export declare class WebSocketClassProvider {
|
|
|
16
15
|
/**
|
|
17
16
|
* Config object that is provided to the WebSocketTransport constructor.
|
|
18
17
|
*/
|
|
19
|
-
export interface WebSocketTransportConfig<
|
|
18
|
+
export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> {
|
|
20
19
|
/** Endpoint to which to open the WS connection*/
|
|
21
|
-
url: (context: AdapterContext<
|
|
22
|
-
/** Optional parameters used when establishing the WebSocket connection */
|
|
23
|
-
options?: (context: AdapterContext<T>) => Promise<ClientOptions> | ClientOptions;
|
|
20
|
+
url: (context: AdapterContext<CustomSettings>) => string;
|
|
24
21
|
/** Map of handlers for different WS lifecycle events */
|
|
25
22
|
handlers: {
|
|
26
23
|
/**
|
|
@@ -29,7 +26,7 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
29
26
|
* @param wsConnection - the WebSocket with an established connection
|
|
30
27
|
* @returns an empty Promise, or void
|
|
31
28
|
*/
|
|
32
|
-
open: (wsConnection: WebSocket, context: AdapterContext<
|
|
29
|
+
open: (wsConnection: WebSocket, context: AdapterContext<CustomSettings>) => Promise<void> | void;
|
|
33
30
|
/**
|
|
34
31
|
* Handles when the WS receives a message
|
|
35
32
|
*
|
|
@@ -37,7 +34,7 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
37
34
|
* @param context - the background context for the Adapter
|
|
38
35
|
* @returns a list of cache entries of adapter responses to set in the cache
|
|
39
36
|
*/
|
|
40
|
-
message: (message:
|
|
37
|
+
message: (message: ProviderDataMessage, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[] | undefined;
|
|
41
38
|
};
|
|
42
39
|
/** Map of "builders", functions that will be used to prepare specific WS messages */
|
|
43
40
|
builders: {
|
|
@@ -47,49 +44,37 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
47
44
|
* @param params - the body of the adapter request
|
|
48
45
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
49
46
|
*/
|
|
50
|
-
subscribeMessage: (params:
|
|
47
|
+
subscribeMessage: (params: AdapterParams) => unknown;
|
|
51
48
|
/**
|
|
52
49
|
* Builds a WS message that will be sent to unsubscribe to a specific feed
|
|
53
50
|
*
|
|
54
51
|
* @param params - the body of the adapter request
|
|
55
52
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
56
53
|
*/
|
|
57
|
-
unsubscribeMessage: (params:
|
|
54
|
+
unsubscribeMessage: (params: AdapterParams) => unknown;
|
|
58
55
|
};
|
|
59
56
|
}
|
|
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
|
-
};
|
|
75
57
|
/**
|
|
76
58
|
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
77
59
|
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
78
60
|
*
|
|
79
|
-
* @typeParam
|
|
61
|
+
* @typeParam AdapterParams - interface for the adapter request body
|
|
62
|
+
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
80
63
|
*/
|
|
81
|
-
export declare class WebSocketTransport<
|
|
64
|
+
export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams, null, CustomSettings> {
|
|
82
65
|
private config;
|
|
83
|
-
cache: Cache
|
|
66
|
+
cache: Cache;
|
|
84
67
|
rateLimiter: BackgroundExecuteRateLimiter;
|
|
85
|
-
subscriptionSet: SubscriptionSet<
|
|
86
|
-
localSubscriptions:
|
|
68
|
+
subscriptionSet: SubscriptionSet<AdapterParams>;
|
|
69
|
+
localSubscriptions: AdapterParams[];
|
|
87
70
|
wsConnection: WebSocket;
|
|
88
|
-
constructor(config: WebSocketTransportConfig<
|
|
89
|
-
initialize(dependencies: AdapterDependencies,
|
|
90
|
-
|
|
71
|
+
constructor(config: WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings>);
|
|
72
|
+
initialize(dependencies: AdapterDependencies, _: AdapterConfig, endpointName: string): Promise<void>;
|
|
73
|
+
hasBeenSetUp(): Promise<boolean>;
|
|
74
|
+
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
91
75
|
serializeMessage(payload: unknown): string;
|
|
92
|
-
deserializeMessage(data: WebSocket.Data):
|
|
93
|
-
establishWsConnection(context: AdapterContext<
|
|
94
|
-
backgroundExecute(context: AdapterContext<
|
|
76
|
+
deserializeMessage(data: WebSocket.Data): ProviderDataMessage;
|
|
77
|
+
establishWsConnection(context: AdapterContext<CustomSettings>): Promise<unknown>;
|
|
78
|
+
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
95
79
|
}
|
|
80
|
+
export {};
|
package/transports/websocket.js
CHANGED
|
@@ -26,9 +26,8 @@ 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 =
|
|
29
|
+
exports.WebSocketTransport = exports.WebSocketClassProvider = void 0;
|
|
30
30
|
const ws_1 = __importDefault(require("ws"));
|
|
31
|
-
exports.WebSocket = ws_1.default;
|
|
32
31
|
const util_1 = require("../util");
|
|
33
32
|
const _1 = require("./");
|
|
34
33
|
const transportMetrics = __importStar(require("./metrics"));
|
|
@@ -47,7 +46,8 @@ WebSocketClassProvider.ctor = ws_1.default;
|
|
|
47
46
|
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
48
47
|
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
49
48
|
*
|
|
50
|
-
* @typeParam
|
|
49
|
+
* @typeParam AdapterParams - interface for the adapter request body
|
|
50
|
+
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
51
51
|
*/
|
|
52
52
|
class WebSocketTransport {
|
|
53
53
|
constructor(config) {
|
|
@@ -56,13 +56,17 @@ 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, _, 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
|
-
|
|
64
|
+
// This might need coalescing to avoid too frequent ttl updates
|
|
65
|
+
async hasBeenSetUp() {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
async setup(req, config) {
|
|
69
|
+
logger.debug(`Adding entry to subscription set: [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
66
70
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
67
71
|
}
|
|
68
72
|
serializeMessage(payload) {
|
|
@@ -71,10 +75,11 @@ class WebSocketTransport {
|
|
|
71
75
|
deserializeMessage(data) {
|
|
72
76
|
return JSON.parse(data.toString());
|
|
73
77
|
}
|
|
74
|
-
establishWsConnection(context
|
|
78
|
+
establishWsConnection(context) {
|
|
75
79
|
return new Promise((resolve) => {
|
|
76
80
|
const ctor = WebSocketClassProvider.get();
|
|
77
|
-
|
|
81
|
+
const url = context.adapterConfig.WS_API_ENDPOINT || this.config.url(context);
|
|
82
|
+
this.wsConnection = new ctor(url);
|
|
78
83
|
this.wsConnection.addEventListener('open', async (event) => {
|
|
79
84
|
logger.debug(`Opened websocket connection. (event type ${event.type})`);
|
|
80
85
|
await this.config.handlers.open(this.wsConnection, context);
|
|
@@ -117,11 +122,11 @@ class WebSocketTransport {
|
|
|
117
122
|
.labels({ endpoint: context.adapterEndpoint.name, transport_type: 'websocket' })
|
|
118
123
|
.set(desiredSubs.length);
|
|
119
124
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
120
|
-
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.
|
|
125
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
121
126
|
const subscribes = subscribeParams
|
|
122
127
|
.map(this.config.builders.subscribeMessage)
|
|
123
128
|
.map(this.serializeMessage);
|
|
124
|
-
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.
|
|
129
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
125
130
|
const unsubscribes = unsubscribeParams
|
|
126
131
|
.map(this.config.builders.unsubscribeMessage)
|
|
127
132
|
.map(this.serializeMessage);
|
|
@@ -142,9 +147,7 @@ class WebSocketTransport {
|
|
|
142
147
|
}
|
|
143
148
|
if (!this.wsConnection && subscribes.length) {
|
|
144
149
|
logger.debug('No established connection and new subscriptions available, connecting to WS');
|
|
145
|
-
|
|
146
|
-
const options = this.config.options && (await this.config.options(context));
|
|
147
|
-
await this.establishWsConnection(context, url, options);
|
|
150
|
+
await this.establishWsConnection(context);
|
|
148
151
|
}
|
|
149
152
|
logger.debug('Sending subs/unsubs if there are any');
|
|
150
153
|
const messages = unsubscribes.concat(subscribes);
|
|
@@ -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,4CAA0B;AAK1B,kCAAqD;AAErD,yBAA4D;AAC5D,4DAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAI/C,MAAa,sBAAsB;IAGjC,MAAM,CAAC,GAAG,CAAC,IAAoB;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,GAAG;QACR,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;;AATH,wDAUC;AATQ,2BAAI,GAAmB,YAAS,CAAA;AAiEzC;;;;;;GAMG;AACH,MAAa,kBAAkB;IAgB7B,YACU,MAAoF;QAApF,WAAM,GAAN,MAAM,CAA8E;QAP9F,+FAA+F;QAC/F,iDAAiD;QACjD,uBAAk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,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;SAC1C;QAED,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAChD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC3D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAChC;QAED,6CAA6C;QAC7C,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAA;QAEpF,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAC5E,CAAC;CACF;AA/JD,gDA+JC"}
|
package/util/logger.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ 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';
|
|
7
6
|
export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
|
|
8
7
|
export declare type Store = {
|
|
9
8
|
correlationId: string;
|
|
@@ -46,4 +45,3 @@ export declare const makeLogger: (layer: string) => pino.Logger<{
|
|
|
46
45
|
} | undefined;
|
|
47
46
|
} & pino.ChildLoggerOptions>;
|
|
48
47
|
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.
|
|
6
|
+
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,7 +39,9 @@ const baseLogger = (0, pino_1.default)({
|
|
|
39
39
|
}
|
|
40
40
|
return {};
|
|
41
41
|
},
|
|
42
|
-
transport: process.env['DEBUG'] === 'true'
|
|
42
|
+
transport: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
43
|
+
? debugTransport
|
|
44
|
+
: undefined,
|
|
43
45
|
});
|
|
44
46
|
exports.COLORS = [
|
|
45
47
|
'\u001b[31;1m',
|
|
@@ -96,7 +98,9 @@ const getNextColor = (0, exports.colorFactory)(exports.COLORS);
|
|
|
96
98
|
*/
|
|
97
99
|
const makeLogger = (layer) => baseLogger.child({
|
|
98
100
|
layer,
|
|
99
|
-
color: process.env['DEBUG'] === 'true'
|
|
101
|
+
color: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
102
|
+
? getNextColor()
|
|
103
|
+
: undefined,
|
|
100
104
|
});
|
|
101
105
|
exports.makeLogger = makeLogger;
|
|
102
106
|
const loggingContextMiddleware = (req, res, done) => {
|
|
@@ -115,5 +119,4 @@ function censor(obj, censorList) {
|
|
|
115
119
|
});
|
|
116
120
|
return JSON.parse(stringified);
|
|
117
121
|
}
|
|
118
|
-
exports.censor = censor;
|
|
119
122
|
//# 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,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,IAAI,qBAAY,CAAC,SAAS,CAAC,OAAO;IAChF,KAAK,EAAE;QACL,SAAS,CAAC,SAAS,EAAE,MAAM;YACzB,iCAAiC;YACjC,MAAM,UAAU,GAAG,qBAAU,CAAC,MAAM,EAAE,CAAA;YACtC,OAAO,MAAM,CAAC,KAAK,CACjB,IAAI,EACJ,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAA2B,CAC1E,CAAA;QACH,CAAC;KACF;IACD,KAAK;QACH,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,KAAK,OAAO,EAAE;YACrD,MAAM,KAAK,GAAG,yBAAiB,CAAC,QAAQ,EAAW,CAAA;YACnD,IAAI,KAAK,EAAE;gBACT,OAAO,KAAK,CAAA;aACb;SACF;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IACD,SAAS,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":";;;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AAE,aAAa,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE;QAC3D,IAAI,EAAE,CAAA;IACR,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AATY,QAAA,wBAAwB,4BASpC;AAED,kFAAkF;AAClF,8DAA8D;AAC9D,SAAS,MAAM,CAAC,GAAQ,EAAE,UAA4B;IACpD,IAAI,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACrC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,GAAG,YAAY,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AAChC,CAAC"}
|
package/util/request.d.ts
CHANGED
|
@@ -6,9 +6,6 @@ declare module 'fastify' {
|
|
|
6
6
|
requestContext: AdapterRequestContext;
|
|
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
|
-
};
|
|
12
9
|
/**
|
|
13
10
|
* Structure for the body of all requests that will be sent to the adapter
|
|
14
11
|
*/
|
|
@@ -46,11 +43,11 @@ export declare type AdapterRouteGeneric = {
|
|
|
46
43
|
/**
|
|
47
44
|
* Structure for all requests incoming to this adapter
|
|
48
45
|
*/
|
|
49
|
-
export declare type AdapterRequest<T
|
|
46
|
+
export declare type AdapterRequest<T = AdapterRequestData> = FastifyRequest<AdapterRouteGeneric> & {
|
|
50
47
|
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
51
48
|
body: EmptyBody;
|
|
52
49
|
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
53
|
-
requestContext: AdapterRequestContext<T
|
|
50
|
+
requestContext: AdapterRequestContext<T>;
|
|
54
51
|
};
|
|
55
52
|
/**
|
|
56
53
|
* Metadata for a particular request
|
|
@@ -77,62 +74,29 @@ export declare type AdapterRequestData = Record<string, unknown> & {
|
|
|
77
74
|
endpoint?: string;
|
|
78
75
|
};
|
|
79
76
|
/**
|
|
80
|
-
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
77
|
+
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
81
78
|
*/
|
|
82
|
-
export interface ProviderResult<
|
|
83
|
-
Request: RequestGenerics;
|
|
84
|
-
Response: ResponseGenerics;
|
|
85
|
-
}> {
|
|
79
|
+
export interface ProviderResult<Params> {
|
|
86
80
|
/** The set of parameters that uniquely relate to the response */
|
|
87
|
-
params:
|
|
88
|
-
/**
|
|
89
|
-
value:
|
|
81
|
+
params: Params;
|
|
82
|
+
/** */
|
|
83
|
+
value: unknown;
|
|
90
84
|
}
|
|
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
|
-
};
|
|
115
85
|
/**
|
|
116
86
|
* Shape of the response body from the adapter
|
|
117
87
|
*/
|
|
118
|
-
export declare type AdapterResponse<T
|
|
88
|
+
export declare type AdapterResponse<T = unknown> = {
|
|
119
89
|
/** HTTP status code */
|
|
120
90
|
statusCode: number;
|
|
121
91
|
/** Response data, holds "result" for Flux Monitor */
|
|
122
|
-
data: T
|
|
92
|
+
data: T;
|
|
123
93
|
/** Result value used for OCR */
|
|
124
|
-
result:
|
|
94
|
+
result: unknown;
|
|
125
95
|
/** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
|
|
126
96
|
maxAge?: number;
|
|
127
97
|
/** Metadata relevant to this request */
|
|
128
98
|
meta?: AdapterRequestMeta;
|
|
129
99
|
};
|
|
130
|
-
export declare type SingleNumberResultResponse = {
|
|
131
|
-
Result: number;
|
|
132
|
-
Data: {
|
|
133
|
-
result: number;
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
100
|
export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
137
101
|
export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
|
|
138
102
|
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, redisClient?: Redis, adapterName?: string);
|
|
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, redisClient, adapterName) {
|
|
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,WAAoB;QAC1E,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,5 +22,4 @@ 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;
|
|
26
25
|
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.
|
|
6
|
+
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,5 +81,4 @@ function resolvePayload(fileName) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
exports.resolvePayload = resolvePayload;
|
|
85
84
|
//# 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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A;SACvC;QACD,wEAAwE;aACnE,IAAI,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAC,EAAE;YACrE,OAAO,GAAG,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC,CAAC,CAAA;SACjE;aAAM,IAAI,YAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE;YAC/C,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;SACzC;QACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;SAC3B;aAAM;YACL,OAAO,OAAO,CAAA;SACf;KACF;IAAC,MAAM;QACN,OAAO,IAAI,CAAA;KACZ;AACH,CAAC"}
|
package/validation/error.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ declare type ErrorFull = ErrorBasic & {
|
|
|
8
8
|
cause: string;
|
|
9
9
|
};
|
|
10
10
|
export declare type AdapterErrorResponse = {
|
|
11
|
+
jobRunID: string;
|
|
11
12
|
status: string;
|
|
12
13
|
statusCode: number;
|
|
13
14
|
providerStatusCode?: number;
|
|
14
15
|
error: ErrorBasic | ErrorFull;
|
|
15
16
|
};
|
|
16
17
|
export declare class AdapterError extends Error {
|
|
18
|
+
jobRunID: string;
|
|
17
19
|
status: string;
|
|
18
20
|
statusCode: number;
|
|
19
21
|
cause: unknown;
|
|
@@ -24,7 +26,7 @@ export declare class AdapterError extends Error {
|
|
|
24
26
|
metricsLabel?: HttpRequestType;
|
|
25
27
|
name: string;
|
|
26
28
|
message: string;
|
|
27
|
-
constructor({ status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
29
|
+
constructor({ jobRunID, status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
28
30
|
toJSONResponse(): AdapterErrorResponse;
|
|
29
31
|
}
|
|
30
32
|
export declare class AdapterInputError extends AdapterError {
|
package/validation/error.js
CHANGED
|
@@ -3,8 +3,9 @@ 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({ status = 'errored', statusCode = 500, name = 'AdapterError', message = '
|
|
6
|
+
constructor({ jobRunID = '1', status = 'errored', statusCode = 500, name = 'AdapterError', message = 'An error occurred.', cause, url, errorResponse, feedID, providerStatusCode, metricsLabel = constants_1.HttpRequestType.ADAPTER_ERROR, }) {
|
|
7
7
|
super(message);
|
|
8
|
+
this.jobRunID = jobRunID;
|
|
8
9
|
this.status = status;
|
|
9
10
|
this.statusCode = statusCode;
|
|
10
11
|
this.name = name;
|
|
@@ -21,7 +22,7 @@ class AdapterError extends Error {
|
|
|
21
22
|
this.metricsLabel = metricsLabel;
|
|
22
23
|
}
|
|
23
24
|
toJSONResponse() {
|
|
24
|
-
const showDebugInfo = process.env['DEBUG'] === 'true';
|
|
25
|
+
const showDebugInfo = process.env['NODE_ENV'] === 'development' || process.env['DEBUG'] === 'true';
|
|
25
26
|
const errorBasic = {
|
|
26
27
|
name: this.name,
|
|
27
28
|
message: this.message,
|
|
@@ -31,6 +32,7 @@ class AdapterError extends Error {
|
|
|
31
32
|
};
|
|
32
33
|
const errorFull = { ...errorBasic, stack: this.stack, cause: this.cause };
|
|
33
34
|
return {
|
|
35
|
+
jobRunID: this.jobRunID,
|
|
34
36
|
status: this.status,
|
|
35
37
|
statusCode: this.statusCode,
|
|
36
38
|
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;AAmBtD,MAAa,YAAa,SAAQ,KAAK;IAcrC,YAAY,EACV,QAAQ,GAAG,GAAG,EACd,MAAM,GAAG,SAAS,EAClB,UAAU,GAAG,GAAG,EAChB,IAAI,GAAG,cAAc,EACrB,OAAO,GAAG,oBAAoB,EAC9B,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,QAAQ,GAAG,QAAQ,CAAA;QACxB,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,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;SACf;QACD,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACrB;QACD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;QAC5C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,cAAc;QACZ,MAAM,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,MAAM,CAAA;QAC9E,MAAM,UAAU,GAAG;YACjB,IAAI,EAAE,IAAI,CAAC,IAA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7D,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,6 +5,7 @@ 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");
|
|
8
9
|
const errorCatcherLogger = (0, util_2.makeLogger)('ErrorCatchingMiddleware');
|
|
9
10
|
const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
10
11
|
if (req.headers['content-type'] !== 'application/json') {
|
|
@@ -39,7 +40,7 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
39
40
|
statusCode: 404,
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
const validatedData = endpoint.validator.validateInput(
|
|
43
|
+
const validatedData = endpoint.validator.validateInput(req.body?.['data']);
|
|
43
44
|
req.requestContext = {
|
|
44
45
|
cacheKey: '',
|
|
45
46
|
data: validatedData,
|
|
@@ -54,25 +55,20 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
54
55
|
}, validatedData);
|
|
55
56
|
req.requestContext = { ...req.requestContext, meta: { metrics } };
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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;
|
|
58
|
+
const requestParams = req.requestContext.data ?? {};
|
|
59
|
+
if (requestParams['tokenOverrides']) {
|
|
60
|
+
throw new Error('Token overrides not yet supported');
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
adapterEndpoint: endpoint,
|
|
73
|
-
adapterConfig: adapter.config,
|
|
74
|
-
}, req.requestContext.data);
|
|
62
|
+
if (requestParams['includes']) {
|
|
63
|
+
throw new Error('Includes not yet supported');
|
|
75
64
|
}
|
|
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);
|
|
76
72
|
done();
|
|
77
73
|
};
|
|
78
74
|
exports.validatorMiddleware = validatorMiddleware;
|
|
@@ -82,20 +78,15 @@ const errorCatchingMiddleware = (err, req, res) => {
|
|
|
82
78
|
if (req.requestContext) {
|
|
83
79
|
req.requestContext.meta = { ...req.requestContext?.meta, error: err };
|
|
84
80
|
}
|
|
85
|
-
// Add the request context to the error so that we can check things like incoming params, endpoint, etc
|
|
86
|
-
const errorWithContext = {
|
|
87
|
-
requestContext: req.requestContext,
|
|
88
|
-
...err,
|
|
89
|
-
};
|
|
90
81
|
if (err instanceof error_1.AdapterError) {
|
|
91
82
|
// We want to log these as warn, because although they are to be expected, NOPs should
|
|
92
83
|
// Only use "correct" job specs and therefore not hit adapters with invalid requests.
|
|
93
|
-
errorCatcherLogger.warn(
|
|
84
|
+
errorCatcherLogger.warn(err);
|
|
94
85
|
res.status(err.statusCode).send(err.toJSONResponse());
|
|
95
86
|
}
|
|
96
87
|
else {
|
|
97
|
-
errorCatcherLogger.error(
|
|
98
|
-
res.status(
|
|
88
|
+
errorCatcherLogger.error(err);
|
|
89
|
+
res.status(200).send('There was an unexpected error in the adapter.');
|
|
99
90
|
}
|
|
100
91
|
};
|
|
101
92
|
exports.errorCatchingMiddleware = errorCatchingMiddleware;
|