@chainlink/external-adapter-framework 0.5.62 → 0.6.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 +1 -2
- package/adapter/basic.js +6 -24
- package/adapter/basic.js.map +1 -1
- package/adapter/types.d.ts +5 -7
- package/background-executor.js +1 -2
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +5 -6
- package/cache/index.js +5 -5
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +11 -12
- package/config/index.js +23 -24
- package/config/index.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/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 +3 -4
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +2 -2
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/global-utils.d.ts +2 -2
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +0 -2
- package/examples/coingecko/src/index.js.map +1 -1
- 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 -2
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +0 -2
- 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/index.d.ts +1 -2
- package/index.js.map +1 -1
- package/metrics/util.d.ts +3 -3
- package/metrics/util.js +2 -2
- package/metrics/util.js.map +1 -1
- package/package.json +3 -3
- package/transports/batch-warming.d.ts +6 -10
- package/transports/batch-warming.js +2 -2
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +3 -3
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +20 -15
- package/transports/rest.js +5 -8
- package/transports/rest.js.map +1 -1
- package/transports/routing.d.ts +1 -2
- package/transports/routing.js +1 -11
- package/transports/routing.js.map +1 -1
- package/transports/sse.d.ts +6 -6
- package/transports/sse.js +1 -2
- package/transports/sse.js.map +1 -1
- package/transports/util.d.ts +1 -3
- package/transports/util.js +39 -69
- package/transports/util.js.map +1 -1
- package/transports/websocket.d.ts +11 -15
- package/transports/websocket.js +27 -44
- package/transports/websocket.js.map +1 -1
- package/validation/index.js +2 -3
- package/validation/index.js.map +1 -1
- package/README.md +0 -67
- 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/util/data-validation.d.ts +0 -15
- package/util/data-validation.js +0 -61
- package/util/data-validation.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
package/transports/util.d.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { AdapterConfig, SettingsMap } from '../config';
|
|
|
4
4
|
* Performs axios request along with metrics recording and error handling
|
|
5
5
|
*
|
|
6
6
|
* @param request - axios request config
|
|
7
|
-
* @param config - the adapter config containing the env vars
|
|
8
|
-
* @param checkForRateLimit - async function to check and wait for rate limit
|
|
9
7
|
* @returns axios response for the request
|
|
10
8
|
*/
|
|
11
|
-
export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap>(request: AxiosRequestConfig<ProviderRequestBody>, config: AdapterConfig<CustomSettings
|
|
9
|
+
export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap>(request: AxiosRequestConfig<ProviderRequestBody>, config: AdapterConfig<CustomSettings>): Promise<AxiosResponse<ProviderResponseBody>>;
|
package/transports/util.js
CHANGED
|
@@ -30,88 +30,58 @@ exports.axiosRequest = void 0;
|
|
|
30
30
|
const axios_1 = __importDefault(require("axios"));
|
|
31
31
|
const error_1 = require("../validation/error");
|
|
32
32
|
const transportMetrics = __importStar(require("./metrics"));
|
|
33
|
-
const util_1 = require("../util");
|
|
34
33
|
/**
|
|
35
34
|
* Performs axios request along with metrics recording and error handling
|
|
36
35
|
*
|
|
37
36
|
* @param request - axios request config
|
|
38
|
-
* @param config - the adapter config containing the env vars
|
|
39
|
-
* @param checkForRateLimit - async function to check and wait for rate limit
|
|
40
37
|
* @returns axios response for the request
|
|
41
38
|
*/
|
|
42
|
-
async function axiosRequest(request, config
|
|
39
|
+
async function axiosRequest(request, config) {
|
|
43
40
|
const responseTimer = transportMetrics.dataProviderRequestDurationSeconds.startTimer();
|
|
44
41
|
let providerResponse;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
try {
|
|
43
|
+
request.timeout = config.API_TIMEOUT;
|
|
44
|
+
providerResponse = await axios_1.default.request(request);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
const error = e;
|
|
48
|
+
// Request error
|
|
49
|
+
let providerStatusCode;
|
|
50
|
+
let adapterError;
|
|
51
|
+
if (error.code === 'ECONNABORTED') {
|
|
52
|
+
adapterError = new error_1.AdapterTimeoutError({});
|
|
53
|
+
providerStatusCode = error?.response?.status ?? 504;
|
|
54
|
+
adapterError.name = 'Data Provider Request Timeout error';
|
|
58
55
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let providerStatusCode;
|
|
63
|
-
let adapterError;
|
|
64
|
-
if (error.code === 'ECONNABORTED') {
|
|
65
|
-
providerStatusCode = error?.response?.status ?? 504;
|
|
66
|
-
adapterError = new error_1.AdapterTimeoutError({
|
|
67
|
-
statusCode: 504,
|
|
68
|
-
name: 'Data Provider Request Timeout error',
|
|
69
|
-
providerStatusCode: error?.response?.status ?? 504,
|
|
70
|
-
message: error?.message,
|
|
71
|
-
cause: error,
|
|
72
|
-
errorResponse: error?.response?.data,
|
|
73
|
-
url: request.url,
|
|
74
|
-
});
|
|
75
|
-
// Record count of failed data provider request
|
|
76
|
-
transportMetrics.dataProviderRequests
|
|
77
|
-
.labels(transportMetrics.dataProviderMetricsLabel(providerStatusCode, request.method))
|
|
78
|
-
.inc();
|
|
79
|
-
throw adapterError;
|
|
80
|
-
}
|
|
81
|
-
if (exponent >= maxRetries) {
|
|
82
|
-
if (error?.response?.status) {
|
|
83
|
-
adapterError = new error_1.AdapterDataProviderError({});
|
|
84
|
-
providerStatusCode = error?.response?.status;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
adapterError = new error_1.AdapterConnectionError({});
|
|
88
|
-
providerStatusCode = 0; // 0 -> connection error
|
|
89
|
-
}
|
|
90
|
-
// Record count of failed data provider request
|
|
91
|
-
transportMetrics.dataProviderRequests
|
|
92
|
-
.labels(transportMetrics.dataProviderMetricsLabel(providerStatusCode, request.method))
|
|
93
|
-
.inc();
|
|
94
|
-
adapterError.statusCode = 200;
|
|
95
|
-
adapterError.providerStatusCode = providerStatusCode;
|
|
96
|
-
adapterError.message = error?.message;
|
|
97
|
-
adapterError.cause = error;
|
|
98
|
-
adapterError.errorResponse = error?.response?.data;
|
|
99
|
-
adapterError.url = request.url;
|
|
100
|
-
throw adapterError;
|
|
101
|
-
}
|
|
102
|
-
return _exponentialDelayRetry(exponent);
|
|
56
|
+
else if (error?.response?.status) {
|
|
57
|
+
adapterError = new error_1.AdapterDataProviderError({});
|
|
58
|
+
providerStatusCode = error?.response?.status;
|
|
103
59
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
60
|
+
else {
|
|
61
|
+
adapterError = new error_1.AdapterConnectionError({});
|
|
62
|
+
providerStatusCode = 0; // 0 -> connection error
|
|
107
63
|
}
|
|
108
|
-
// Record count of
|
|
64
|
+
// Record count of failed data provider request
|
|
109
65
|
transportMetrics.dataProviderRequests
|
|
110
|
-
.labels(transportMetrics.dataProviderMetricsLabel(
|
|
66
|
+
.labels(transportMetrics.dataProviderMetricsLabel(providerStatusCode, request.method))
|
|
111
67
|
.inc();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
68
|
+
adapterError.statusCode = 200;
|
|
69
|
+
adapterError.providerStatusCode = providerStatusCode;
|
|
70
|
+
adapterError.message = error?.message;
|
|
71
|
+
adapterError.cause = error;
|
|
72
|
+
adapterError.errorResponse = error?.response?.data;
|
|
73
|
+
adapterError.url = request.url;
|
|
74
|
+
throw adapterError;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// Record time taken for data provider request for success or failure
|
|
78
|
+
responseTimer();
|
|
79
|
+
}
|
|
80
|
+
// Record count of successful data provider requests
|
|
81
|
+
transportMetrics.dataProviderRequests
|
|
82
|
+
.labels(transportMetrics.dataProviderMetricsLabel(providerResponse.status, request.method))
|
|
83
|
+
.inc();
|
|
84
|
+
return providerResponse;
|
|
115
85
|
}
|
|
116
86
|
exports.axiosRequest = axiosRequest;
|
|
117
87
|
//# sourceMappingURL=util.js.map
|
package/transports/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/transports/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4E;AAE5E,+CAK4B;AAC5B,4DAA6C;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/transports/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4E;AAE5E,+CAK4B;AAC5B,4DAA6C;AAE7C;;;;;GAKG;AACI,KAAK,UAAU,YAAY,CAKhC,OAAgD,EAChD,MAAqC;IAErC,MAAM,aAAa,GAAG,gBAAgB,CAAC,kCAAkC,CAAC,UAAU,EAAE,CAAA;IACtF,IAAI,gBAAqD,CAAA;IACzD,IAAI;QACF,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAA;QACpC,gBAAgB,GAAG,MAAM,eAAK,CAAC,OAAO,CAAuB,OAAO,CAAC,CAAA;KACtE;IAAC,OAAO,CAAU,EAAE;QACnB,MAAM,KAAK,GAAG,CAAe,CAAA;QAC7B,gBAAgB;QAChB,IAAI,kBAAsC,CAAA;QAC1C,IAAI,YAA0B,CAAA;QAC9B,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;YACjC,YAAY,GAAG,IAAI,2BAAmB,CAAC,EAAE,CAAC,CAAA;YAC1C,kBAAkB,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAA;YACnD,YAAY,CAAC,IAAI,GAAG,qCAAqC,CAAA;SAC1D;aAAM,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE;YAClC,YAAY,GAAG,IAAI,gCAAwB,CAAC,EAAE,CAAC,CAAA;YAC/C,kBAAkB,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAA;SAC7C;aAAM;YACL,YAAY,GAAG,IAAI,8BAAsB,CAAC,EAAE,CAAC,CAAA;YAC7C,kBAAkB,GAAG,CAAC,CAAA,CAAC,wBAAwB;SAChD;QACD,+CAA+C;QAC/C,gBAAgB,CAAC,oBAAoB;aAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;aACrF,GAAG,EAAE,CAAA;QAER,YAAY,CAAC,UAAU,GAAG,GAAG,CAAA;QAC7B,YAAY,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;QACpD,YAAY,CAAC,OAAO,GAAG,KAAK,EAAE,OAAO,CAAA;QACrC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAA;QAC1B,YAAY,CAAC,aAAa,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAA;QAClD,YAAY,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QAE9B,MAAM,YAAY,CAAA;KACnB;YAAS;QACR,qEAAqE;QACrE,aAAa,EAAE,CAAA;KAChB;IAED,oDAAoD;IACpD,gBAAgB,CAAC,oBAAoB;SAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;SAC1F,GAAG,EAAE,CAAA;IAER,OAAO,gBAAgB,CAAA;AACzB,CAAC;AArDD,oCAqDC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WebSocket, { ClientOptions, RawData } from 'ws';
|
|
2
|
-
import {
|
|
2
|
+
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
4
|
import { AdapterConfig } from '../config';
|
|
5
5
|
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
@@ -18,19 +18,18 @@ export declare class WebSocketClassProvider {
|
|
|
18
18
|
*/
|
|
19
19
|
export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics> {
|
|
20
20
|
/** Endpoint to which to open the WS connection*/
|
|
21
|
-
url: (context:
|
|
21
|
+
url: (context: AdapterContext<T>) => string;
|
|
22
22
|
/** Optional parameters used when establishing the WebSocket connection */
|
|
23
|
-
options?: (context:
|
|
23
|
+
options?: (context: AdapterContext<T>) => ClientOptions;
|
|
24
24
|
/** Map of handlers for different WS lifecycle events */
|
|
25
25
|
handlers: {
|
|
26
26
|
/**
|
|
27
|
-
* Handles when the WS is successfully opened
|
|
28
|
-
* Optional since logic is not always needed on connection.
|
|
27
|
+
* Handles when the WS is successfully opened
|
|
29
28
|
*
|
|
30
29
|
* @param wsConnection - the WebSocket with an established connection
|
|
31
30
|
* @returns an empty Promise, or void
|
|
32
31
|
*/
|
|
33
|
-
open
|
|
32
|
+
open: (wsConnection: WebSocket, context: AdapterContext<T>) => Promise<void> | void;
|
|
34
33
|
/**
|
|
35
34
|
* Handles when the WS receives a message
|
|
36
35
|
*
|
|
@@ -38,24 +37,24 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
38
37
|
* @param context - the background context for the Adapter
|
|
39
38
|
* @returns a list of cache entries of adapter responses to set in the cache
|
|
40
39
|
*/
|
|
41
|
-
message: (message: T['Provider']['WsMessage'], context:
|
|
40
|
+
message: (message: T['Provider']['WsMessage'], context: AdapterContext<T>) => ProviderResult<T>[] | undefined;
|
|
42
41
|
};
|
|
43
42
|
/** Map of "builders", functions that will be used to prepare specific WS messages */
|
|
44
|
-
builders
|
|
43
|
+
builders: {
|
|
45
44
|
/**
|
|
46
45
|
* Builds a WS message that will be sent to subscribe to a specific feed
|
|
47
46
|
*
|
|
48
47
|
* @param params - the body of the adapter request
|
|
49
48
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
50
49
|
*/
|
|
51
|
-
subscribeMessage
|
|
50
|
+
subscribeMessage: (params: T['Request']['Params']) => unknown;
|
|
52
51
|
/**
|
|
53
52
|
* Builds a WS message that will be sent to unsubscribe to a specific feed
|
|
54
53
|
*
|
|
55
54
|
* @param params - the body of the adapter request
|
|
56
55
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
57
56
|
*/
|
|
58
|
-
unsubscribeMessage
|
|
57
|
+
unsubscribeMessage: (params: T['Request']['Params']) => unknown;
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
60
|
/**
|
|
@@ -86,14 +85,11 @@ export declare class WebSocketTransport<T extends WebsocketTransportGenerics> im
|
|
|
86
85
|
subscriptionSet: SubscriptionSet<T['Request']['Params']>;
|
|
87
86
|
localSubscriptions: T['Request']['Params'][];
|
|
88
87
|
wsConnection: WebSocket;
|
|
89
|
-
currentUrl: string;
|
|
90
88
|
constructor(config: WebSocketTransportConfig<T>);
|
|
91
89
|
initialize(dependencies: AdapterDependencies, config: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
92
90
|
registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
93
|
-
connectionClosed(): boolean;
|
|
94
91
|
serializeMessage(payload: unknown): string;
|
|
95
92
|
deserializeMessage(data: WebSocket.Data): T['Provider']['WsMessage'];
|
|
96
|
-
establishWsConnection(context:
|
|
97
|
-
|
|
98
|
-
backgroundExecute(context: EndpointContext<T>): Promise<number>;
|
|
93
|
+
establishWsConnection(context: AdapterContext<T>): Promise<unknown>;
|
|
94
|
+
backgroundExecute(context: AdapterContext<T>): Promise<number>;
|
|
99
95
|
}
|
package/transports/websocket.js
CHANGED
|
@@ -55,7 +55,6 @@ class WebSocketTransport {
|
|
|
55
55
|
// The double sets serve to create a simple polling mechanism instead of needing a subscription
|
|
56
56
|
// This one would not; this is always local state
|
|
57
57
|
this.localSubscriptions = [];
|
|
58
|
-
this.currentUrl = '';
|
|
59
58
|
}
|
|
60
59
|
async initialize(dependencies, config, endpointName) {
|
|
61
60
|
this.cache = dependencies.cache;
|
|
@@ -66,32 +65,29 @@ class WebSocketTransport {
|
|
|
66
65
|
logger.debug(`Adding entry to subscription set (ttl: ${config.WS_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
67
66
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
68
67
|
}
|
|
69
|
-
connectionClosed() {
|
|
70
|
-
return !this.wsConnection || this.wsConnection.readyState === ws_1.default.CLOSED;
|
|
71
|
-
}
|
|
72
68
|
serializeMessage(payload) {
|
|
73
69
|
return typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
74
70
|
}
|
|
75
71
|
deserializeMessage(data) {
|
|
76
72
|
return JSON.parse(data.toString());
|
|
77
73
|
}
|
|
78
|
-
establishWsConnection(context
|
|
74
|
+
establishWsConnection(context) {
|
|
79
75
|
return new Promise((resolve) => {
|
|
80
76
|
const ctor = WebSocketClassProvider.get();
|
|
77
|
+
const url = context.adapterConfig.WS_API_ENDPOINT || this.config.url(context);
|
|
78
|
+
const options = this.config.options && this.config.options(context);
|
|
81
79
|
this.wsConnection = new ctor(url, undefined, options);
|
|
82
80
|
this.wsConnection.addEventListener('open', async (event) => {
|
|
83
81
|
logger.debug(`Opened websocket connection. (event type ${event.type})`);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
logger.debug('Successfully executed connection opened handler');
|
|
87
|
-
}
|
|
82
|
+
await this.config.handlers.open(this.wsConnection, context);
|
|
83
|
+
logger.debug('Successfully executed connection opened handler');
|
|
88
84
|
// Record active ws connections by incrementing count on open
|
|
89
85
|
transportMetrics.wsConnectionActive.inc();
|
|
90
86
|
resolve(true);
|
|
91
87
|
});
|
|
92
88
|
this.wsConnection.addEventListener('message', async (event) => {
|
|
93
89
|
const parsed = this.deserializeMessage(event.data);
|
|
94
|
-
logger.trace(`Got ws message: ${
|
|
90
|
+
logger.trace(`Got ws message: ${parsed}`);
|
|
95
91
|
const results = this.config.handlers.message(parsed, context);
|
|
96
92
|
if (Array.isArray(results)) {
|
|
97
93
|
const responses = (0, _1.buildCacheEntriesFromResults)(results, context);
|
|
@@ -114,31 +110,29 @@ class WebSocketTransport {
|
|
|
114
110
|
});
|
|
115
111
|
});
|
|
116
112
|
}
|
|
117
|
-
async sendMessages(context, subscribes, unsubscribes) {
|
|
118
|
-
const serializedSubscribes = subscribes.map(this.serializeMessage);
|
|
119
|
-
const serializedUnsubscribes = unsubscribes.map(this.serializeMessage);
|
|
120
|
-
const messages = serializedSubscribes.concat(serializedUnsubscribes);
|
|
121
|
-
for (const message of messages) {
|
|
122
|
-
this.wsConnection.send(message);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
113
|
// Unlike cache warming, this execute will manage subscriptions
|
|
126
114
|
async backgroundExecute(context) {
|
|
127
115
|
logger.debug('Starting background execute, getting subscriptions from sorted set');
|
|
128
116
|
const desiredSubs = await this.subscriptionSet.getAll();
|
|
129
117
|
// Keep track of active subscriptions for background execute
|
|
130
118
|
transportMetrics.bgExecuteSubscriptionSetCount
|
|
131
|
-
.labels({ endpoint: context.
|
|
119
|
+
.labels({ endpoint: context.adapterEndpoint.name, transport_type: 'websocket' })
|
|
132
120
|
.set(desiredSubs.length);
|
|
133
121
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
134
|
-
const
|
|
135
|
-
const
|
|
122
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.map((ls) => JSON.stringify(ls)).includes(JSON.stringify(s)));
|
|
123
|
+
const subscribes = subscribeParams
|
|
124
|
+
.map(this.config.builders.subscribeMessage)
|
|
125
|
+
.map(this.serializeMessage);
|
|
126
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.map((ds) => JSON.stringify(ds)).includes(JSON.stringify(s)));
|
|
127
|
+
const unsubscribes = unsubscribeParams
|
|
128
|
+
.map(this.config.builders.unsubscribeMessage)
|
|
129
|
+
.map(this.serializeMessage);
|
|
136
130
|
logger.debug(`${subscribes.length} new subscriptions; ${unsubscribes.length} to unsubscribe`);
|
|
137
131
|
if (subscribes.length) {
|
|
138
|
-
logger.trace(`Will subscribe to: ${
|
|
132
|
+
logger.trace(`Will subscribe to: ${subscribes}`);
|
|
139
133
|
}
|
|
140
134
|
if (unsubscribes.length) {
|
|
141
|
-
logger.trace(`Will unsubscribe to: ${
|
|
135
|
+
logger.trace(`Will unsubscribe to: ${unsubscribes}`);
|
|
142
136
|
}
|
|
143
137
|
// New subs && no connection -> connect -> add subs
|
|
144
138
|
// No new subs && no connection -> skip
|
|
@@ -146,35 +140,24 @@ class WebSocketTransport {
|
|
|
146
140
|
// No new subs && connection -> unsubs only
|
|
147
141
|
if (!subscribes.length && !this.wsConnection) {
|
|
148
142
|
logger.debug('No entries in subscription set and no established connection, skipping');
|
|
149
|
-
return this.rateLimiter.msUntilNextExecution(context.
|
|
150
|
-
}
|
|
151
|
-
const urlFromConfig = await this.config.url(context, desiredSubs);
|
|
152
|
-
const urlChanged = this.currentUrl !== urlFromConfig;
|
|
153
|
-
let connectionClosed = this.connectionClosed();
|
|
154
|
-
// 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...`);
|
|
157
|
-
this.wsConnection.close();
|
|
158
|
-
connectionClosed = true;
|
|
143
|
+
return this.rateLimiter.msUntilNextExecution(context.adapterEndpoint.name);
|
|
159
144
|
}
|
|
160
|
-
|
|
161
|
-
if (connectionClosed && desiredSubs.length) {
|
|
145
|
+
if (!this.wsConnection && subscribes.length) {
|
|
162
146
|
logger.debug('No established connection and new subscriptions available, connecting to WS');
|
|
163
|
-
|
|
164
|
-
this.currentUrl = urlFromConfig;
|
|
165
|
-
await this.establishWsConnection(context, urlFromConfig, options);
|
|
147
|
+
await this.establishWsConnection(context);
|
|
166
148
|
}
|
|
167
|
-
if
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
149
|
+
logger.debug('Sending subs/unsubs if there are any');
|
|
150
|
+
const messages = unsubscribes.concat(subscribes);
|
|
151
|
+
for (const message of messages) {
|
|
152
|
+
logger.trace(`Sending message: ${JSON.stringify(message)}`);
|
|
153
|
+
this.wsConnection.send(message);
|
|
171
154
|
}
|
|
172
155
|
// Record WS message and subscription metrics
|
|
173
|
-
transportMetrics.recordWsMessageMetrics(context,
|
|
156
|
+
transportMetrics.recordWsMessageMetrics(context, subscribeParams, unsubscribeParams);
|
|
174
157
|
logger.debug('Setting local state to cache value');
|
|
175
158
|
this.localSubscriptions = desiredSubs;
|
|
176
159
|
logger.debug('Background execute complete');
|
|
177
|
-
return this.rateLimiter.msUntilNextExecution(context.
|
|
160
|
+
return this.rateLimiter.msUntilNextExecution(context.adapterEndpoint.name);
|
|
178
161
|
}
|
|
179
162
|
}
|
|
180
163
|
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,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,IAAI,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,GAAG;QACR,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;;AATH,wDAUC;AATQ,2BAAI,GAAmB,YAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAsD;AAW7C,oBAXF,YAAS,CAWE;AANl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,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;AAxJD,gDAwJC"}
|
package/validation/index.js
CHANGED
|
@@ -49,7 +49,7 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
49
49
|
// Add metrics meta which includes feedId to the request
|
|
50
50
|
// Perform prior to overrides to maintain consistent Feed IDs across adapters
|
|
51
51
|
const metrics = (0, util_1.getMetricsMeta)({
|
|
52
|
-
|
|
52
|
+
adapterEndpoint: endpoint,
|
|
53
53
|
adapterConfig: adapter.config,
|
|
54
54
|
}, validatedData);
|
|
55
55
|
req.requestContext = { ...req.requestContext, meta: { metrics } };
|
|
@@ -69,8 +69,7 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
71
|
req.requestContext.cacheKey = (0, cache_1.calculateCacheKey)({
|
|
72
|
-
|
|
73
|
-
inputParameters: endpoint.inputParameters,
|
|
72
|
+
adapterEndpoint: endpoint,
|
|
74
73
|
adapterConfig: adapter.config,
|
|
75
74
|
}, req.requestContext.data);
|
|
76
75
|
}
|
package/validation/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":";;;AAEA,oCAA4C;AAC5C,0CAAgD;AAChD,kCAAoC;AAEpC,mCAAyD;AAGzD,MAAM,kBAAkB,GAAG,IAAA,iBAAU,EAAC,yBAAyB,CAAC,CAAA;AAEzD,MAAM,mBAAmB,GAC9B,CAAC,OAAgB,EAAE,EAAE,CAC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Warning**
|
|
4
|
-
> This framework is in a Beta state, and under active development. While many of the features from version 2 are present, they have not been tested extensively enough to mark this as production ready. You can find v2 in the [External Adapters Monorepo](https://github.com/smartcontractkit/external-adapters-js)
|
|
5
|
-
|
|
6
|
-
Framework to create External adapters, microservices that serve as middleware to facilitate connections between Chainlink Nodes and Data Providers (DP).
|
|
7
|
-
|
|
8
|
-
## Requirements
|
|
9
|
-
|
|
10
|
-
- Node.js 16+
|
|
11
|
-
- Yarn
|
|
12
|
-
|
|
13
|
-
### Optional development tools
|
|
14
|
-
|
|
15
|
-
If available, consider setting up your development environment with:
|
|
16
|
-
|
|
17
|
-
- ESLint
|
|
18
|
-
- Prettier
|
|
19
|
-
|
|
20
|
-
Note that both of the above are not necessary, but PRs submitted to the repo will be blocked from merging unless they comply with the linting and formatting rules.
|
|
21
|
-
|
|
22
|
-
## Setup
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
yarn # Install yarn dependencies
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Guides & Docs
|
|
29
|
-
|
|
30
|
-
- [Basics](./docs/basics.md)
|
|
31
|
-
- Porting a v2 EA to v3
|
|
32
|
-
- Creating a new v3 EA
|
|
33
|
-
- Transports
|
|
34
|
-
- Basic
|
|
35
|
-
- REST
|
|
36
|
-
- WebSocket
|
|
37
|
-
- SSE
|
|
38
|
-
- Meta
|
|
39
|
-
- Routing
|
|
40
|
-
|
|
41
|
-
## Testing
|
|
42
|
-
|
|
43
|
-
The EA framework is tested by a suite of integration tests located [here](./test).
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
yarn test
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Publishing releases
|
|
50
|
-
|
|
51
|
-
### Automatic
|
|
52
|
-
|
|
53
|
-
The normal flow for publishing a release is through a series o GitHub actions that are triggered when a PR is closed by merging with the base branch. Full details about our workflows can be found in [./.github/WORKFLOW-README.MD]. A summary of our publish workflow follows:
|
|
54
|
-
|
|
55
|
-
1. Close a PR containing your changes
|
|
56
|
-
2. If the PR was merged and if it contains a version label instruction (patch, minor, major, none), a new PR will be created that contains the result of running `npm version LABEL` on master with the original PR author assigned as a reviewer.
|
|
57
|
-
3. A link to the newly created version bump PR will be added to your original PR. Click on that link, and approve it to be merged.
|
|
58
|
-
4. Close the version bump PR. If merged, the package will be published to npm.
|
|
59
|
-
5. When the publish workflow finishes, a comment will be added to the version bump PR that tells you if it ran successfully
|
|
60
|
-
|
|
61
|
-
This adds an extra step (approving a version bump PR) that has to be taken every time a PR is merged. This is annoying, but it is an effective workaround for permissions issues when running against protected branches, and eliminates the need for the PR author to manually update their branch's version by referring to master.
|
|
62
|
-
|
|
63
|
-
### Manual
|
|
64
|
-
|
|
65
|
-
If you need to publish a release manually, you can do so by running `yarn release` at the project root
|
|
66
|
-
|
|
67
|
-
This runs a script that publishes the package from dist/src. If you publish from the root directory, imports will be in the form of: `import {something} from "@chainlink/external-adapter-framework/src/some_directory"`. By publishing the package from dist/src, the "src" part of the import path gets dropped, which looks cleaner: `import {something} from "@chainlink/external-adapter-framework/some_directory"`.
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AdapterEndpoint } from '../../adapter';
|
|
2
|
-
interface AdapterRequestParams {
|
|
3
|
-
base: string;
|
|
4
|
-
quote: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const batchEndpoint: AdapterEndpoint<AdapterRequestParams, import("../../transports").BackgroundStoredResultType, import("../../config").SettingsMap>;
|
|
7
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.batchEndpoint = void 0;
|
|
4
|
-
const adapter_1 = require("../../adapter");
|
|
5
|
-
const batch_warming_1 = require("../../transports/batch-warming");
|
|
6
|
-
const DEFAULT_URL = 'https://pro-api.coingecko.com/api/v3';
|
|
7
|
-
const inputParameters = {
|
|
8
|
-
coinid: {
|
|
9
|
-
description: 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
|
|
10
|
-
required: false,
|
|
11
|
-
},
|
|
12
|
-
base: {
|
|
13
|
-
aliases: ['from', 'coin'],
|
|
14
|
-
description: 'The symbol or array of symbols of the currency to query',
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
quote: {
|
|
18
|
-
aliases: ['to', 'market'],
|
|
19
|
-
description: 'The symbol of the currency to convert to',
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
|
|
24
|
-
prepareRequest: (params, config) => {
|
|
25
|
-
return {
|
|
26
|
-
baseURL: DEFAULT_URL,
|
|
27
|
-
url: '/simple/price',
|
|
28
|
-
method: 'GET',
|
|
29
|
-
params: {
|
|
30
|
-
ids: [...new Set(params.map((p) => p.base))].join(','),
|
|
31
|
-
vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
|
|
32
|
-
x_cg_pro_api_key: config.API_KEY,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
parseResponse: (params, res) => {
|
|
37
|
-
const entries = [];
|
|
38
|
-
for (const [base, entry] of Object.entries(res.data)) {
|
|
39
|
-
for (const [quote, price] of Object.entries(entry)) {
|
|
40
|
-
entries.push({
|
|
41
|
-
params: { base, quote },
|
|
42
|
-
value: price,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return entries;
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
exports.batchEndpoint = new adapter_1.AdapterEndpoint({
|
|
50
|
-
name: 'batch',
|
|
51
|
-
transport: batchEndpointTransport,
|
|
52
|
-
inputParameters,
|
|
53
|
-
});
|
|
54
|
-
//# sourceMappingURL=batch-warming.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"batch-warming.js","sourceRoot":"","sources":["../../../../src/examples/coing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,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACpD,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBAClD,OAAO,CAAC,IAAI,CAAC;oBACX,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;oBACvB,KAAK,EAAE,KAAK;iBACb,CAAC,CAAA;aACH;SACF;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF,CAAC,CAAA;AAEW,QAAA,aAAa,GAAG,IAAI,yBAAe,CAAC;IAC/C,IAAI,EAAE,OAAO;IACb,SAAS,EAAE,sBAAsB;IACjC,eAAe;CAChB,CAAC,CAAA"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.adapter = void 0;
|
|
4
|
-
const adapter_1 = require("../../adapter");
|
|
5
|
-
const batch_warming_1 = require("./batch-warming");
|
|
6
|
-
const rest_1 = require("./rest");
|
|
7
|
-
exports.adapter = new adapter_1.Adapter({
|
|
8
|
-
name: 'coingecko',
|
|
9
|
-
defaultEndpoint: 'batch',
|
|
10
|
-
endpoints: [rest_1.restEndpoint, batch_warming_1.batchEndpoint],
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/examples/coingecko-old/index.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,mDAA+C;AAC/C,iCAAqC;AAExB,QAAA,OAAO,GAAG,IAAI,iBAAO,CAAC;IACjC,IAAI,EAAE,WAAW;IACjB,eAAe,EAAE,OAAO;IACxB,SAAS,EAAE,CAAC,mBAAY,EAAE,6BAAa,CAAC;CACzC,CAAC,CAAA"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AdapterEndpoint } from '../../adapter';
|
|
2
|
-
interface AdapterRequestParams {
|
|
3
|
-
base: string;
|
|
4
|
-
quote: string;
|
|
5
|
-
}
|
|
6
|
-
interface ProviderResponseBody {
|
|
7
|
-
[base: string]: {
|
|
8
|
-
[quote: string]: number;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export declare const restEndpoint: AdapterEndpoint<AdapterRequestParams, ProviderResponseBody, import("../../config").SettingsMap>;
|
|
12
|
-
export {};
|