@chainlink/external-adapter-framework 0.23.2 → 0.24.2
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 +12 -7
- package/adapter/basic.js +2 -2
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +2 -2
- package/adapter/endpoint.js.map +1 -1
- package/adapter/types.d.ts +2 -2
- package/config/provider-limits.js +3 -3
- package/config/provider-limits.js.map +1 -1
- package/package.json +1 -1
- package/transports/meta/routing.d.ts +22 -9
- package/transports/meta/routing.js +34 -8
- package/transports/meta/routing.js.map +1 -1
- package/transports/websocket.js +1 -0
- package/transports/websocket.js.map +1 -1
- package/util/types.d.ts +1 -6
- package/validation/index.d.ts +1 -1
- package/validation/input-params.d.ts +6 -1
- package/examples/bank-frick/accounts.d.ts +0 -45
- package/examples/bank-frick/accounts.js +0 -203
- package/examples/bank-frick/accounts.js.map +0 -1
- package/examples/bank-frick/config/index.d.ts +0 -17
- package/examples/bank-frick/config/index.js +0 -55
- package/examples/bank-frick/config/index.js.map +0 -1
- package/examples/bank-frick/index.d.ts +0 -2
- package/examples/bank-frick/index.js +0 -16
- package/examples/bank-frick/index.js.map +0 -1
- package/examples/bank-frick/util.d.ts +0 -4
- package/examples/bank-frick/util.js +0 -40
- package/examples/bank-frick/util.js.map +0 -1
- package/examples/coingecko/src/config/index.d.ts +0 -2
- package/examples/coingecko/src/config/index.js +0 -6
- package/examples/coingecko/src/config/index.js.map +0 -1
- package/examples/coingecko/src/config/overrides.json +0 -10825
- package/examples/coingecko/src/crypto-utils.d.ts +0 -62
- package/examples/coingecko/src/crypto-utils.js +0 -60
- package/examples/coingecko/src/crypto-utils.js.map +0 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +0 -26
- package/examples/coingecko/src/endpoint/coins.js +0 -37
- package/examples/coingecko/src/endpoint/coins.js.map +0 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +0 -3
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +0 -30
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +0 -1
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +0 -3
- package/examples/coingecko/src/endpoint/crypto-volume.js +0 -30
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +0 -1
- package/examples/coingecko/src/endpoint/crypto.d.ts +0 -3
- package/examples/coingecko/src/endpoint/crypto.js +0 -28
- package/examples/coingecko/src/endpoint/crypto.js.map +0 -1
- package/examples/coingecko/src/endpoint/dominance.d.ts +0 -3
- package/examples/coingecko/src/endpoint/dominance.js +0 -28
- package/examples/coingecko/src/endpoint/dominance.js.map +0 -1
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +0 -3
- package/examples/coingecko/src/endpoint/global-marketcap.js +0 -28
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +0 -1
- package/examples/coingecko/src/endpoint/index.d.ts +0 -6
- package/examples/coingecko/src/endpoint/index.js +0 -16
- package/examples/coingecko/src/endpoint/index.js.map +0 -1
- package/examples/coingecko/src/global-utils.d.ts +0 -42
- package/examples/coingecko/src/global-utils.js +0 -47
- package/examples/coingecko/src/global-utils.js.map +0 -1
- package/examples/coingecko/src/index.d.ts +0 -4
- package/examples/coingecko/src/index.js +0 -19
- package/examples/coingecko/src/index.js.map +0 -1
- package/examples/cryptocompare/src/config/index.d.ts +0 -2
- package/examples/cryptocompare/src/config/index.js +0 -6
- package/examples/cryptocompare/src/config/index.js.map +0 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +0 -40
- package/examples/cryptocompare/src/endpoints/crypto.js +0 -54
- package/examples/cryptocompare/src/endpoints/crypto.js.map +0 -1
- package/examples/cryptocompare/src/endpoints/index.d.ts +0 -1
- package/examples/cryptocompare/src/endpoints/index.js +0 -6
- package/examples/cryptocompare/src/endpoints/index.js.map +0 -1
- package/examples/cryptocompare/src/index.d.ts +0 -4
- package/examples/cryptocompare/src/index.js +0 -14
- package/examples/cryptocompare/src/index.js.map +0 -1
- package/examples/genesis/config/index.d.ts +0 -7
- package/examples/genesis/config/index.js +0 -11
- package/examples/genesis/config/index.js.map +0 -1
- package/examples/genesis/index.d.ts +0 -2
- package/examples/genesis/index.js +0 -13
- package/examples/genesis/index.js.map +0 -1
- package/examples/genesis/sseStream.d.ts +0 -27
- package/examples/genesis/sseStream.js +0 -149
- package/examples/genesis/sseStream.js.map +0 -1
- package/rate-limiting/background/fixed-frequency.d.ts +0 -10
- package/rate-limiting/background/fixed-frequency.js +0 -36
- package/rate-limiting/background/fixed-frequency.js.map +0 -1
- package/rate-limiting/metrics.d.ts +0 -1
- package/rate-limiting/metrics.js +0 -16
- package/rate-limiting/metrics.js.map +0 -1
- package/rate-limiting/request/simple-counting.d.ts +0 -20
- package/rate-limiting/request/simple-counting.js +0 -63
- package/rate-limiting/request/simple-counting.js.map +0 -1
- package/scripts/generator/index.d.ts +0 -1
- package/scripts/generator/index.js +0 -5
- package/scripts/generator/index.js.map +0 -1
- package/scripts/generator/lib.d.ts +0 -1
- package/scripts/generator/lib.js +0 -170
- package/scripts/generator/lib.js.map +0 -1
- package/scripts/generator/workspace.d.ts +0 -21
- package/scripts/generator/workspace.js +0 -76
- package/scripts/generator/workspace.js.map +0 -1
- package/transports/batch-warming.d.ts +0 -52
- package/transports/batch-warming.js +0 -150
- package/transports/batch-warming.js.map +0 -1
- package/transports/rest.d.ts +0 -66
- package/transports/rest.js +0 -144
- package/transports/rest.js.map +0 -1
- package/transports/routing.d.ts +0 -22
- package/transports/routing.js +0 -60
- package/transports/routing.js.map +0 -1
- package/transports/util.d.ts +0 -11
- package/transports/util.js +0 -117
- package/transports/util.js.map +0 -1
- package/util/metrics.d.ts +0 -8
- package/util/metrics.js +0 -50
- package/util/metrics.js.map +0 -1
- package/util/request.d.ts +0 -217
- package/util/request.js +0 -3
- package/util/request.js.map +0 -1
package/transports/rest.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.RestTransport = void 0;
|
|
27
|
-
const rateLimitMetrics = __importStar(require("../rate-limiting/metrics"));
|
|
28
|
-
const util_1 = require("../util");
|
|
29
|
-
const error_1 = require("../validation/error");
|
|
30
|
-
const util_2 = require("./util");
|
|
31
|
-
const IN_FLIGHT_PREFIX = 'InFlight';
|
|
32
|
-
const logger = (0, util_1.makeLogger)('RestTransport');
|
|
33
|
-
/**
|
|
34
|
-
* Transport implementation that takes incoming requests, transforms them into a DataProvider request,
|
|
35
|
-
* and executes that request returning the response immediately from the `setup` function.
|
|
36
|
-
* Optionally, setting the `coalescing` option to `true` will make it so once a request is in flight,
|
|
37
|
-
* new adapter requests for the same feed will not trigger a new one, but return an empty promise from
|
|
38
|
-
* the setup instead so the normal cache polling mechanism is used.
|
|
39
|
-
*
|
|
40
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[RestTransportGenerics]])
|
|
41
|
-
*/
|
|
42
|
-
class RestTransport {
|
|
43
|
-
constructor(config) {
|
|
44
|
-
this.config = config;
|
|
45
|
-
}
|
|
46
|
-
async initialize(dependencies, config) {
|
|
47
|
-
this.responseCache = dependencies.responseCache;
|
|
48
|
-
this.inFlightPrefix = `${IN_FLIGHT_PREFIX}-`;
|
|
49
|
-
this.inFlightCache = dependencies.cache;
|
|
50
|
-
this.rateLimiter = dependencies.requestRateLimiter;
|
|
51
|
-
// Allow enabling/disabling request coalescing through env var
|
|
52
|
-
this.config.options.requestCoalescing.enabled = config.REQUEST_COALESCING_ENABLED;
|
|
53
|
-
this.config.options.requestCoalescing.entropyMax = config.REQUEST_COALESCING_ENTROPY_MAX;
|
|
54
|
-
}
|
|
55
|
-
async waitUntilUnderRateLimit(options, retry = 0) {
|
|
56
|
-
if (this.rateLimiter.isUnderLimits()) {
|
|
57
|
-
logger.trace('Incoming request would not be under limits, moving on');
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (retry >= options.maxRetries) {
|
|
61
|
-
throw new error_1.AdapterError({
|
|
62
|
-
statusCode: 504,
|
|
63
|
-
message: `REST Transport timed out while waiting for rate limit availability (max retries: ${options.maxRetries})`,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
logger.debug(`Request would be over rate limits, sleeping for ${options.msBetweenRetries}`);
|
|
67
|
-
await (0, util_1.sleep)(options.msBetweenRetries);
|
|
68
|
-
await this.waitUntilUnderRateLimit(options, retry + 1);
|
|
69
|
-
}
|
|
70
|
-
async foregroundExecute(req, config) {
|
|
71
|
-
// Add some entropy here because of possible scenario where the key won't be set before multiple
|
|
72
|
-
// other instances in a burst request try to access the coalescing key.
|
|
73
|
-
const randomMs = Math.random() * (this.config.options.requestCoalescing.entropyMax || 0);
|
|
74
|
-
await (0, util_1.sleep)(randomMs);
|
|
75
|
-
// Check if request is in flight if coalescing is enabled
|
|
76
|
-
const inFlightKey = this.inFlightPrefix + req.requestContext.cacheKey;
|
|
77
|
-
const inFlight = this.config.options.requestCoalescing.enabled && (await this.inFlightCache.get(inFlightKey));
|
|
78
|
-
if (inFlight) {
|
|
79
|
-
logger.debug('Request is in flight, transport has been set up');
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
else if (this.config.options.requestCoalescing.enabled) {
|
|
83
|
-
// If it wasn't in flight and coalescing is disabled, register it as in flight
|
|
84
|
-
const ttl = config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES *
|
|
85
|
-
config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES;
|
|
86
|
-
logger.debug('Setting up rest transport, setting request in flight in cache');
|
|
87
|
-
await this.inFlightCache.set(inFlightKey, true, ttl + 100); // Can't use Infinity for things like Redis
|
|
88
|
-
}
|
|
89
|
-
const request = await this.config.prepareRequest(req, config);
|
|
90
|
-
logger.trace('Check if we are under rate limits to perform request');
|
|
91
|
-
const checkForRateLimit = async () => {
|
|
92
|
-
return this.waitUntilUnderRateLimit({
|
|
93
|
-
maxRetries: config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES,
|
|
94
|
-
msBetweenRetries: config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES,
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
await checkForRateLimit();
|
|
98
|
-
logger.trace('Sending request to data provider...');
|
|
99
|
-
const providerDataRequested = Date.now();
|
|
100
|
-
const providerResponse = await (0, util_2.axiosRequest)(request, config, checkForRateLimit);
|
|
101
|
-
const providerDataReceived = Date.now();
|
|
102
|
-
logger.debug(`Got response from provider, parsing (raw body: ${providerResponse.data})`);
|
|
103
|
-
const response = (await this.config.parseResponse(req, providerResponse, config));
|
|
104
|
-
response.timestamps = {
|
|
105
|
-
providerDataRequested,
|
|
106
|
-
providerDataReceived,
|
|
107
|
-
providerIndicatedTime: response.timestamps?.providerIndicatedTime,
|
|
108
|
-
};
|
|
109
|
-
if (config.API_VERBOSE) {
|
|
110
|
-
response.data = providerResponse.data;
|
|
111
|
-
}
|
|
112
|
-
if (config.METRICS_ENABLED && config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
113
|
-
response.meta = {
|
|
114
|
-
metrics: { feedId: req.requestContext.meta?.metrics?.feedId || 'N/A' },
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
const result = {
|
|
118
|
-
params: req.requestContext.data,
|
|
119
|
-
response,
|
|
120
|
-
};
|
|
121
|
-
logger.debug('Setting provider response in cache');
|
|
122
|
-
await this.responseCache.write([result]);
|
|
123
|
-
// Record cost of data provider call
|
|
124
|
-
const cost = rateLimitMetrics.retrieveCost(providerResponse.data);
|
|
125
|
-
rateLimitMetrics.rateLimitCreditsSpentTotal
|
|
126
|
-
.labels({
|
|
127
|
-
feed_id: req.requestContext.meta?.metrics?.feedId || 'N/A',
|
|
128
|
-
participant_id: req.requestContext.cacheKey,
|
|
129
|
-
})
|
|
130
|
-
.inc(cost);
|
|
131
|
-
// Update cacheHit flag in request meta for metrics use
|
|
132
|
-
req.requestContext.meta = {
|
|
133
|
-
...req.requestContext.meta,
|
|
134
|
-
metrics: { ...req.requestContext.meta?.metrics, cacheHit: false },
|
|
135
|
-
};
|
|
136
|
-
if (this.config.options.requestCoalescing.enabled) {
|
|
137
|
-
logger.debug('Set provider response in cache, removing in flight from cache');
|
|
138
|
-
await this.inFlightCache.delete(inFlightKey);
|
|
139
|
-
}
|
|
140
|
-
return response;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.RestTransport = RestTransport;
|
|
144
|
-
//# sourceMappingURL=rest.js.map
|
package/transports/rest.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../src/transports/rest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EAAE,GAAG,CAAC,cAAc,CAAC,IAAI;YAC/B,QAAQ;SACT,CAAA;QAED,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QAExC,oCAAoC;QACpC,MAAM,IAAI,GAAG,gBAAgB,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;QACjE,gBAAgB,CAAC,0BAA0B;aACxC,MAAM,CAAC;YACN,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;YAC1D,cAAc,EAAE,GAAG,CAAC,cAAc,CAAC,QAAQ;SAC5C,CAAC;aACD,GAAG,CAAC,IAAI,CAAC,CAAA;QAEZ,uDAAuD;QACvD,GAAG,CAAC,cAAc,CAAC,IAAI,GAAG;YACxB,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI;YAC1B,OAAO,EAAE,EAAE,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;SAClE,CAAA;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE;YACjD,MAAM,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAA;YAC7E,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;SAC7C;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AAlJD,sCAkJC"}
|
package/transports/routing.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AdapterDependencies } from '../adapter';
|
|
2
|
-
import { AdapterConfig } from '../config';
|
|
3
|
-
import { AdapterRequest, AdapterResponse } from '../util';
|
|
4
|
-
import { MetaTransport, Transport, TransportGenerics } from './';
|
|
5
|
-
/**
|
|
6
|
-
* Transport implementation that takes 2 or more transports and a function that determines with transport to use.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[TransportGenerics]])
|
|
9
|
-
*/
|
|
10
|
-
export declare class RoutingTransport<T extends TransportGenerics> implements MetaTransport<T> {
|
|
11
|
-
transports: {
|
|
12
|
-
[key: string]: Transport<T>;
|
|
13
|
-
};
|
|
14
|
-
private route;
|
|
15
|
-
constructor(transports: {
|
|
16
|
-
[key: string]: Transport<T>;
|
|
17
|
-
}, route: (req: AdapterRequest<T['Request']>, adapterConfig?: AdapterConfig<T['CustomSettings']>) => string);
|
|
18
|
-
initialize(dependencies: AdapterDependencies, adapterConfig: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
19
|
-
registerRequest(req: AdapterRequest<T['Request']>, adapterConfig: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
20
|
-
private resolveTransport;
|
|
21
|
-
foregroundExecute(req: AdapterRequest<T['Request']>, adapterConfig: AdapterConfig<T['CustomSettings']>): Promise<AdapterResponse<any> | void>;
|
|
22
|
-
}
|
package/transports/routing.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoutingTransport = void 0;
|
|
4
|
-
const util_1 = require("../util");
|
|
5
|
-
const error_1 = require("../validation/error");
|
|
6
|
-
const logger = (0, util_1.makeLogger)('RoutingTransport');
|
|
7
|
-
/**
|
|
8
|
-
* Transport implementation that takes 2 or more transports and a function that determines with transport to use.
|
|
9
|
-
*
|
|
10
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[TransportGenerics]])
|
|
11
|
-
*/
|
|
12
|
-
class RoutingTransport {
|
|
13
|
-
constructor(
|
|
14
|
-
// This is public for tests, which sometimes need the underlying transport for things like ticking the clock
|
|
15
|
-
transports,
|
|
16
|
-
// Route should return to a string key that corresponds to a transport in the transports object
|
|
17
|
-
route) {
|
|
18
|
-
this.transports = transports;
|
|
19
|
-
this.route = route;
|
|
20
|
-
}
|
|
21
|
-
async initialize(dependencies, adapterConfig, endpointName) {
|
|
22
|
-
logger.debug(`Initializing ${Object.keys(this.transports).length} transports`);
|
|
23
|
-
Object.entries(this.transports).forEach(([k, v]) => {
|
|
24
|
-
logger.debug(`Initializing transport ${k} (${v.constructor.name})`);
|
|
25
|
-
v.initialize(dependencies, adapterConfig, endpointName);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async registerRequest(req, adapterConfig) {
|
|
29
|
-
logger.debug(`registering request using `, req.requestContext.data);
|
|
30
|
-
const transport = this.resolveTransport(req, adapterConfig);
|
|
31
|
-
if (transport.registerRequest) {
|
|
32
|
-
logger.debug(`Running registerRequest on retrieved transport`);
|
|
33
|
-
return transport.registerRequest(req, adapterConfig);
|
|
34
|
-
}
|
|
35
|
-
logger.debug(`Retrieved transport doesn't implement registerRequest`);
|
|
36
|
-
}
|
|
37
|
-
resolveTransport(req, adapterConfig) {
|
|
38
|
-
logger.debug(`routing request using `, req.requestContext.data);
|
|
39
|
-
const key = this.route(req, adapterConfig || undefined);
|
|
40
|
-
if (!this.transports[key]) {
|
|
41
|
-
logger.error(`No transport found for key ${key}`);
|
|
42
|
-
throw new error_1.AdapterError({ statusCode: 400, message: `No transport found for ${key}` });
|
|
43
|
-
}
|
|
44
|
-
const transport = this.transports[key];
|
|
45
|
-
logger.debug(`Found ${transport.constructor.name} corresponding to ${key}`);
|
|
46
|
-
return transport;
|
|
47
|
-
}
|
|
48
|
-
// Allow AdapterResponse<any> below since we don't know what the adapter will return
|
|
49
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
50
|
-
async foregroundExecute(req, adapterConfig) {
|
|
51
|
-
const transport = this.resolveTransport(req, adapterConfig);
|
|
52
|
-
if (transport.foregroundExecute) {
|
|
53
|
-
logger.debug(`Running foregroundExecute on retrieved transport`);
|
|
54
|
-
return transport.foregroundExecute(req, adapterConfig);
|
|
55
|
-
}
|
|
56
|
-
logger.debug(`Retrieved transport doesn't implement foregroundExecute`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.RoutingTransport = RoutingTransport;
|
|
60
|
-
//# sourceMappingURL=routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../src/transports/routing.ts"],"names":[],"mappings":";;;AAEA,kCAAqE;AACrE,+CAAkD;AAGlD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,kBAAkB,CAAC,CAAA;AAE7C;;;;GAIG;AACH,MAAa,gBAAgB;IAI3B;IACE,6GAA6G;IACtG,UAA2C;IAClD,+FAA+F;IACvF,KAGG;QALJ,eAAU,GAAV,UAAU,CAAiC;QAE1C,UAAK,GAAL,KAAK,CAGF;IACV,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,aAAiD,EACjD,YAAoB;QAEpB,MAAM,CAAC,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,aAAa,CAAC,CAAA;QAC9E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;YACjD,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAA;YACnE,CAAC,CAAC,UAAU,CAAC,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,GAAiC,EACjC,aAAiD;QAEjD,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAEnE,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAA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;QACD,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAA;IACzE,CAAC;CACF;AApED,4CAoEC"}
|
package/transports/util.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { AdapterConfig, SettingsMap } from '../config';
|
|
3
|
-
/**
|
|
4
|
-
* Performs axios request along with metrics recording and error handling
|
|
5
|
-
*
|
|
6
|
-
* @param request - axios request config
|
|
7
|
-
* @param config - the adapter config containing the env vars
|
|
8
|
-
* @param checkForRateLimit - async function to check and wait for rate limit
|
|
9
|
-
* @returns axios response for the request
|
|
10
|
-
*/
|
|
11
|
-
export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap>(request: AxiosRequestConfig<ProviderRequestBody>, config: AdapterConfig<CustomSettings>, checkForRateLimit?: () => Promise<void>): Promise<AxiosResponse<ProviderResponseBody>>;
|
package/transports/util.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.axiosRequest = void 0;
|
|
30
|
-
const axios_1 = __importDefault(require("axios"));
|
|
31
|
-
const error_1 = require("../validation/error");
|
|
32
|
-
const transportMetrics = __importStar(require("./metrics"));
|
|
33
|
-
const util_1 = require("../util");
|
|
34
|
-
/**
|
|
35
|
-
* Performs axios request along with metrics recording and error handling
|
|
36
|
-
*
|
|
37
|
-
* @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
|
-
* @returns axios response for the request
|
|
41
|
-
*/
|
|
42
|
-
async function axiosRequest(request, config, checkForRateLimit) {
|
|
43
|
-
const responseTimer = transportMetrics.dataProviderRequestDurationSeconds.startTimer();
|
|
44
|
-
let providerResponse;
|
|
45
|
-
const maxRetries = config.RETRY;
|
|
46
|
-
const initialExponent = 1;
|
|
47
|
-
const retry = async (exponent) => {
|
|
48
|
-
const _exponentialDelayRetry = async (exp) => {
|
|
49
|
-
await (0, util_1.sleep)((2 ** exp + Math.random()) * 1000);
|
|
50
|
-
if (checkForRateLimit) {
|
|
51
|
-
await checkForRateLimit();
|
|
52
|
-
}
|
|
53
|
-
return retry(exp + 1);
|
|
54
|
-
};
|
|
55
|
-
try {
|
|
56
|
-
request.timeout = config.API_TIMEOUT;
|
|
57
|
-
providerResponse = await axios_1.default.request(request);
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
const error = e;
|
|
61
|
-
// Request error
|
|
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);
|
|
103
|
-
}
|
|
104
|
-
finally {
|
|
105
|
-
// Record time taken for data provider request for success or failure
|
|
106
|
-
responseTimer();
|
|
107
|
-
}
|
|
108
|
-
// Record count of successful data provider requests
|
|
109
|
-
transportMetrics.dataProviderRequests
|
|
110
|
-
.labels(transportMetrics.dataProviderMetricsLabel(providerResponse.status, request.method))
|
|
111
|
-
.inc();
|
|
112
|
-
return providerResponse;
|
|
113
|
-
};
|
|
114
|
-
return retry(initialExponent);
|
|
115
|
-
}
|
|
116
|
-
exports.axiosRequest = axiosRequest;
|
|
117
|
-
//# sourceMappingURL=util.js.map
|
package/transports/util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/transports/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4E;AAE5E,+CAK4B;AAC5B,4DAA6C;AAC7C,kCAA+B;AAE/B;;;;;;;GAOG;AACI,KAAK,UAAU,YAAY,CAKhC,OAAgD,EAChD,MAAqC,EACrC,iBAAuC;IAEvC,MAAM,aAAa,GAAG,gBAAgB,CAAC,kCAAkC,CAAC,UAAU,EAAE,CAAA;IACtF,IAAI,gBAAqD,CAAA;IACzD,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAA;IAC/B,MAAM,eAAe,GAAG,CAAC,CAAA;IAEzB,MAAM,KAAK,GAAG,KAAK,EAAE,QAAgB,EAAgD,EAAE;QACrF,MAAM,sBAAsB,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE;YACnD,MAAM,IAAA,YAAK,EAAC,CAAC,CAAC,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAC9C,IAAI,iBAAiB,EAAE;gBACrB,MAAM,iBAAiB,EAAE,CAAA;aAC1B;YACD,OAAO,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;QACvB,CAAC,CAAA;QAED,IAAI;YACF,OAAO,CAAC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C;gBAC/C,gBAAgB,CAAC,oBAAoB;qBAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;qBACrF,GAAG,EAAE,CAAA;gBAER,YAAY,CAAC,UAAU,GAAG,GAAG,CAAA;gBAC7B,YAAY,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;gBACpD,YAAY,CAAC,OAAO,GAAG,KAAK,EAAE,OAAO,CAAA;gBACrC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAA;gBAC1B,YAAY,CAAC,aAAa,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAA;gBAClD,YAAY,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;gBAE9B,MAAM,YAAY,CAAA;aACnB;YAED,OAAO,sBAAsB,CAAC,QAAQ,CAAC,CAAA;SACxC;gBAAS;YACR,qEAAqE;YACrE,aAAa,EAAE,CAAA;SAChB;QAED,oDAAoD;QACpD,gBAAgB,CAAC,oBAAoB;aAClC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;aAC1F,GAAG,EAAE,CAAA;QAER,OAAO,gBAAgB,CAAA;IACzB,CAAC,CAAA;IAED,OAAO,KAAK,CAAC,eAAe,CAAC,CAAA;AAC/B,CAAC;AAzFD,oCAyFC"}
|
package/util/metrics.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as client from 'prom-client';
|
|
2
|
-
import { Metrics } from '../metrics';
|
|
3
|
-
export declare const requestMetrics: Metrics<{
|
|
4
|
-
dataProviderRequests: client.Counter<"method" | "provider_status_code">;
|
|
5
|
-
dataProviderRequestDurationSeconds: client.Histogram<string>;
|
|
6
|
-
requesterQueueSize: client.Gauge<string>;
|
|
7
|
-
requesterQueueOverflow: client.Counter<string>;
|
|
8
|
-
}>;
|
package/util/metrics.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.requestMetrics = void 0;
|
|
27
|
-
const client = __importStar(require("prom-client"));
|
|
28
|
-
const metrics_1 = require("../metrics");
|
|
29
|
-
const constants_1 = require("../metrics/constants");
|
|
30
|
-
exports.requestMetrics = new metrics_1.Metrics(() => ({
|
|
31
|
-
dataProviderRequests: new client.Counter({
|
|
32
|
-
name: 'data_provider_requests',
|
|
33
|
-
help: 'The number of http requests that are made to a data provider',
|
|
34
|
-
labelNames: ['method', 'provider_status_code'],
|
|
35
|
-
}),
|
|
36
|
-
dataProviderRequestDurationSeconds: new client.Histogram({
|
|
37
|
-
name: 'data_provider_request_duration_seconds',
|
|
38
|
-
help: 'A histogram bucket of the distribution of data provider request durations',
|
|
39
|
-
buckets: constants_1.requestDurationBuckets,
|
|
40
|
-
}),
|
|
41
|
-
requesterQueueSize: new client.Gauge({
|
|
42
|
-
name: 'requester_queue_size',
|
|
43
|
-
help: 'The number of provider http requests currently queued to be executed',
|
|
44
|
-
}),
|
|
45
|
-
requesterQueueOverflow: new client.Counter({
|
|
46
|
-
name: 'requester_queue_overflow',
|
|
47
|
-
help: 'Total times the requester queue replaced the oldest item to avoid an overflow',
|
|
48
|
-
}),
|
|
49
|
-
}));
|
|
50
|
-
//# sourceMappingURL=metrics.js.map
|
package/util/metrics.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/util/metrics.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AACrC,wCAAoC;AACpC,oDAA6D;AAEhD,QAAA,cAAc,GAAG,IAAI,iBAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/C,oBAAoB,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC;QACvC,IAAI,EAAE,wBAAwB;QAC9B,IAAI,EAAE,8DAA8D;QACpE,UAAU,EAAE,CAAC,QAAQ,EAAE,sBAAsB,CAAU;KACxD,CAAC;IACF,kCAAkC,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC;QACvD,IAAI,EAAE,wCAAwC;QAC9C,IAAI,EAAE,2EAA2E;QACjF,OAAO,EAAE,kCAAsB;KAChC,CAAC;IACF,kBAAkB,EAAE,IAAI,MAAM,CAAC,KAAK,CAAC;QACnC,IAAI,EAAE,sBAAsB;QAC5B,IAAI,EAAE,sEAAsE;KAC7E,CAAC;IACF,sBAAsB,EAAE,IAAI,MAAM,CAAC,OAAO,CAAC;QACzC,IAAI,EAAE,0BAA0B;QAChC,IAAI,EAAE,+EAA+E;KACtF,CAAC;CACH,CAAC,CAAC,CAAA"}
|
package/util/request.d.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify';
|
|
2
|
-
import { Adapter } from '../adapter';
|
|
3
|
-
import { AdapterError } from '../validation/error';
|
|
4
|
-
declare module 'fastify' {
|
|
5
|
-
interface FastifyRequest {
|
|
6
|
-
requestContext: AdapterRequestContext;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export 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
|
-
/**
|
|
13
|
-
* Structure for the body of all requests that will be sent to the adapter
|
|
14
|
-
*/
|
|
15
|
-
export interface AdapterRequestBody<T = AdapterRequestData> {
|
|
16
|
-
/** Adapter endpoint (not to be confused with REST API endpoint) */
|
|
17
|
-
endpoint?: string;
|
|
18
|
-
/** Main data that will be validated and used on each adapter request */
|
|
19
|
-
data: T;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Object that will be added to the request on a successful validation.
|
|
23
|
-
* Contains all the necessary information the adapter will need across the request execution.
|
|
24
|
-
*/
|
|
25
|
-
export type AdapterRequestContext<T = AdapterRequestData> = {
|
|
26
|
-
/** Name of the endpoint this payload should be directed to */
|
|
27
|
-
endpointName: string;
|
|
28
|
-
/** Precalculated cache key used to get and set corresponding values from the cache and subscription sets */
|
|
29
|
-
cacheKey: string;
|
|
30
|
-
/** Normalized and validated data coming from the request body */
|
|
31
|
-
data: T;
|
|
32
|
-
/** Metadata relevant to this particular request */
|
|
33
|
-
meta?: AdapterRequestMeta;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Helper type to denote an empty body
|
|
37
|
-
*/
|
|
38
|
-
type EmptyBody = Record<string, never>;
|
|
39
|
-
/**
|
|
40
|
-
* Helper type to provide fastify for all adapter handlers
|
|
41
|
-
*/
|
|
42
|
-
export type AdapterRouteGeneric = {
|
|
43
|
-
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
44
|
-
Body: EmptyBody;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Structure for all requests incoming to this adapter
|
|
48
|
-
*/
|
|
49
|
-
export type AdapterRequest<T extends RequestGenerics = RequestGenerics> = FastifyRequest<AdapterRouteGeneric> & {
|
|
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 */
|
|
51
|
-
body: EmptyBody;
|
|
52
|
-
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
53
|
-
requestContext: AdapterRequestContext<T['Params']>;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Metadata for a particular request
|
|
57
|
-
*/
|
|
58
|
-
export interface AdapterRequestMeta {
|
|
59
|
-
/** Relevant metrics gathered for this request */
|
|
60
|
-
metrics?: AdapterMetricsMeta;
|
|
61
|
-
/** An error that ocurred somewhere along this requests' lifecycle */
|
|
62
|
-
error?: AdapterError | Error;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Meta info that pertains to exposing metrics
|
|
66
|
-
*/
|
|
67
|
-
export interface AdapterMetricsMeta {
|
|
68
|
-
/** String to uniquely identify a specific price feed */
|
|
69
|
-
feedId?: string;
|
|
70
|
-
/** Boolean to note if this request's response was found in the cache directly */
|
|
71
|
-
cacheHit?: boolean;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Basic shape for the data within the request body
|
|
75
|
-
*/
|
|
76
|
-
export type AdapterRequestData = Record<string, unknown> & {
|
|
77
|
-
endpoint?: string;
|
|
78
|
-
};
|
|
79
|
-
export type ProviderResultGenerics = {
|
|
80
|
-
Request: RequestGenerics;
|
|
81
|
-
Response: ResponseGenerics;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to.
|
|
85
|
-
*/
|
|
86
|
-
export type ProviderResult<T extends ProviderResultGenerics> = {
|
|
87
|
-
/** The set of parameters that uniquely relate to the response */
|
|
88
|
-
params: T['Request']['Params'];
|
|
89
|
-
/** Value that will be included in the result property of the response */
|
|
90
|
-
response: PartialAdapterResponse<T['Response']>;
|
|
91
|
-
};
|
|
92
|
-
export type TimestampedProviderResult<T extends ProviderResultGenerics> = Pick<ProviderResult<T>, 'params'> & {
|
|
93
|
-
/** Value that will be included in the result property of the response, with timestamps applied */
|
|
94
|
-
response: TimestampedAdapterResponse<T['Response']>;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Here we do actually want an object, since unknown could be a primitive.
|
|
98
|
-
* The rule itself does say "marginally better"
|
|
99
|
-
*/
|
|
100
|
-
export type EmptyObject = Object;
|
|
101
|
-
/**
|
|
102
|
-
* Helper struct type that provides detail about the incoming Adapter Request
|
|
103
|
-
*/
|
|
104
|
-
export type RequestGenerics = {
|
|
105
|
-
/**
|
|
106
|
-
* Type for the parameters sent to the EA in the data property of the body.
|
|
107
|
-
*/
|
|
108
|
-
Params: EmptyObject;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Helper struct type that provides detail about the outgoing Adapter Response
|
|
112
|
-
*/
|
|
113
|
-
export type ResponseGenerics = {
|
|
114
|
-
/**
|
|
115
|
-
* Type for the data property of the response.
|
|
116
|
-
*/
|
|
117
|
-
Data: unknown;
|
|
118
|
-
/**
|
|
119
|
-
* Type for the result property of the response.
|
|
120
|
-
* This is mostly used for OCR, and corresponds to one "word" when talking about it from an on-chain perspective.
|
|
121
|
-
*/
|
|
122
|
-
Result: string | number | null;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Details for timestamps to be included in the response
|
|
126
|
-
*/
|
|
127
|
-
type ResponseTimestamps = {
|
|
128
|
-
/** Time at which data was received from the provider */
|
|
129
|
-
providerDataReceived: number;
|
|
130
|
-
/** Time indicated by the provider representing the time at which this value was calculated/set/valid */
|
|
131
|
-
providerIndicatedTime: number | undefined;
|
|
132
|
-
} & ({
|
|
133
|
-
/**
|
|
134
|
-
* For sync protocols (request -\> response).
|
|
135
|
-
* Time at which data was requested from the provider.
|
|
136
|
-
*/
|
|
137
|
-
providerDataRequested: number;
|
|
138
|
-
providerDataStreamEstablished?: never;
|
|
139
|
-
} | {
|
|
140
|
-
/**
|
|
141
|
-
* For async protocols (subscription -\> n events received).
|
|
142
|
-
* Time at which a data stream was established for the provider.
|
|
143
|
-
*/
|
|
144
|
-
providerDataStreamEstablished: number;
|
|
145
|
-
providerDataRequested?: never;
|
|
146
|
-
});
|
|
147
|
-
/**
|
|
148
|
-
* Object with timestamps that will be present in both successful and provider error responses
|
|
149
|
-
*/
|
|
150
|
-
type TimestampedResponseObject = {
|
|
151
|
-
/** Timestamps relevant for data provider timings */
|
|
152
|
-
timestamps: ResponseTimestamps;
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Response from the EA to send when manually storing an error in the cache
|
|
156
|
-
*/
|
|
157
|
-
type ProviderErrorResponse = {
|
|
158
|
-
/** Status code for the errored response */
|
|
159
|
-
statusCode: number;
|
|
160
|
-
/** Error message that will be sent back from the adapter */
|
|
161
|
-
errorMessage: string;
|
|
162
|
-
} & {
|
|
163
|
-
data?: never;
|
|
164
|
-
result?: never;
|
|
165
|
-
meta?: never;
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Provider error response with timestamps added
|
|
169
|
-
*/
|
|
170
|
-
export type TimestampedProviderErrorResponse = ProviderErrorResponse & TimestampedResponseObject;
|
|
171
|
-
/**
|
|
172
|
-
* The most basic data that needs to be manually set for an adapter response.
|
|
173
|
-
*/
|
|
174
|
-
export type PartialSuccessfulResponse<T extends ResponseGenerics> = {
|
|
175
|
-
/** Response data, holds "result" for Flux Monitor */
|
|
176
|
-
data: T['Data'];
|
|
177
|
-
/** Result value used for OCR */
|
|
178
|
-
result: T['Result'];
|
|
179
|
-
/** Optionally, specify manually some of the timestamps here */
|
|
180
|
-
timestamps?: Pick<ResponseTimestamps, 'providerIndicatedTime'>;
|
|
181
|
-
} & {
|
|
182
|
-
errorMessage?: never;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Partial EA response, with timestamps added
|
|
186
|
-
*/
|
|
187
|
-
type TimestampedSuccessfulResponse<T extends ResponseGenerics> = PartialSuccessfulResponse<T> & TimestampedResponseObject;
|
|
188
|
-
/**
|
|
189
|
-
* Full EA successful response, with metadata and defaults added
|
|
190
|
-
*/
|
|
191
|
-
type SuccessfulResponse<T extends ResponseGenerics> = TimestampedSuccessfulResponse<T> & {
|
|
192
|
-
/** Metadata relevant to this request */
|
|
193
|
-
meta?: AdapterRequestMeta;
|
|
194
|
-
/** HTTP status code, by default will be set to 200 */
|
|
195
|
-
statusCode: number;
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* Response body from the EA, before timestamps, defaults and metadata are filled in
|
|
199
|
-
*/
|
|
200
|
-
export type PartialAdapterResponse<T extends ResponseGenerics = ResponseGenerics> = PartialSuccessfulResponse<T> | ProviderErrorResponse;
|
|
201
|
-
/**
|
|
202
|
-
* Response body from the EA with timestamps, before defaults and metadata are filled in
|
|
203
|
-
*/
|
|
204
|
-
export type TimestampedAdapterResponse<T extends ResponseGenerics = ResponseGenerics> = TimestampedSuccessfulResponse<T> | TimestampedProviderErrorResponse;
|
|
205
|
-
/**
|
|
206
|
-
* Shape of the response body from the adapter
|
|
207
|
-
*/
|
|
208
|
-
export type AdapterResponse<T extends ResponseGenerics = ResponseGenerics> = SuccessfulResponse<T> | TimestampedProviderErrorResponse;
|
|
209
|
-
export type SingleNumberResultResponse = {
|
|
210
|
-
Result: number;
|
|
211
|
-
Data: {
|
|
212
|
-
result: number;
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
export type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
216
|
-
export type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
|
|
217
|
-
export {};
|