@chainlink/external-adapter-framework 0.15.1 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/index.js +1 -1
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +45 -0
- package/examples/bank-frick/accounts.js +203 -0
- package/examples/bank-frick/accounts.js.map +1 -0
- package/examples/bank-frick/config/index.d.ts +17 -0
- package/examples/bank-frick/config/index.js +55 -0
- package/examples/bank-frick/config/index.js.map +1 -0
- package/examples/bank-frick/index.d.ts +2 -0
- package/examples/bank-frick/index.js +16 -0
- package/examples/bank-frick/index.js.map +1 -0
- package/examples/bank-frick/util.d.ts +4 -0
- package/examples/bank-frick/util.js +40 -0
- package/examples/bank-frick/util.js.map +1 -0
- package/examples/coingecko/src/config/index.d.ts +2 -0
- package/examples/coingecko/src/config/index.js +6 -0
- package/examples/coingecko/src/config/index.js.map +1 -0
- package/examples/coingecko/src/config/overrides.json +10825 -0
- package/examples/coingecko/src/crypto-utils.d.ts +62 -0
- package/examples/coingecko/src/crypto-utils.js +60 -0
- package/examples/coingecko/src/crypto-utils.js.map +1 -0
- package/examples/coingecko/src/endpoint/coins.d.ts +26 -0
- package/examples/coingecko/src/endpoint/coins.js +37 -0
- package/examples/coingecko/src/endpoint/coins.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +30 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js +30 -0
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto.d.ts +3 -0
- package/examples/coingecko/src/endpoint/crypto.js +28 -0
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -0
- package/examples/coingecko/src/endpoint/dominance.d.ts +3 -0
- package/examples/coingecko/src/endpoint/dominance.js +28 -0
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -0
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +3 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js +28 -0
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/index.d.ts +6 -0
- package/examples/coingecko/src/endpoint/index.js +16 -0
- package/examples/coingecko/src/endpoint/index.js.map +1 -0
- package/examples/coingecko/src/global-utils.d.ts +42 -0
- package/examples/coingecko/src/global-utils.js +47 -0
- package/examples/coingecko/src/global-utils.js.map +1 -0
- package/examples/coingecko/src/index.d.ts +4 -0
- package/examples/coingecko/src/index.js +19 -0
- package/examples/coingecko/src/index.js.map +1 -0
- package/examples/cryptocompare/src/config/index.d.ts +2 -0
- package/examples/cryptocompare/src/config/index.js +6 -0
- package/examples/cryptocompare/src/config/index.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +40 -0
- package/examples/cryptocompare/src/endpoints/crypto.js +54 -0
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/index.d.ts +1 -0
- package/examples/cryptocompare/src/endpoints/index.js +6 -0
- package/examples/cryptocompare/src/endpoints/index.js.map +1 -0
- package/examples/cryptocompare/src/index.d.ts +4 -0
- package/examples/cryptocompare/src/index.js +14 -0
- package/examples/cryptocompare/src/index.js.map +1 -0
- package/examples/genesis/config/index.d.ts +7 -0
- package/examples/genesis/config/index.js +11 -0
- package/examples/genesis/config/index.js.map +1 -0
- package/examples/genesis/index.d.ts +2 -0
- package/examples/genesis/index.js +13 -0
- package/examples/genesis/index.js.map +1 -0
- package/examples/genesis/sseStream.d.ts +27 -0
- package/examples/genesis/sseStream.js +149 -0
- package/examples/genesis/sseStream.js.map +1 -0
- package/package.json +1 -1
- package/rate-limiting/request/simple-counting.d.ts +1 -1
- package/rate-limiting/request/simple-counting.js +8 -12
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/scripts/generator/index.d.ts +1 -0
- package/scripts/generator/index.js +5 -0
- package/scripts/generator/index.js.map +1 -0
- package/scripts/generator/lib.d.ts +1 -0
- package/scripts/generator/lib.js +170 -0
- package/scripts/generator/lib.js.map +1 -0
- package/scripts/generator/workspace.d.ts +21 -0
- package/scripts/generator/workspace.js +76 -0
- package/scripts/generator/workspace.js.map +1 -0
- package/transports/batch-warming.d.ts +8 -20
- package/transports/batch-warming.js +68 -55
- package/transports/batch-warming.js.map +1 -1
- package/transports/meta/routing.d.ts +1 -1
- package/transports/meta/routing.js +1 -1
- package/transports/meta/routing.js.map +1 -1
- package/transports/routing.d.ts +22 -0
- package/transports/routing.js +60 -0
- package/transports/routing.js.map +1 -0
- package/util/request.d.ts +25 -25
|
@@ -0,0 +1,76 @@
|
|
|
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.getWorkspacePackages = exports.PUBLIC_ADAPTER_TYPES = void 0;
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
28
|
+
const fs_1 = require("fs");
|
|
29
|
+
const path_1 = require("path");
|
|
30
|
+
const s = __importStar(require("shelljs"));
|
|
31
|
+
/**
|
|
32
|
+
* Types of adapters that are publically consumed
|
|
33
|
+
*/
|
|
34
|
+
exports.PUBLIC_ADAPTER_TYPES = ['sources'];
|
|
35
|
+
const scope = '@chainlink/';
|
|
36
|
+
function getWorkspacePackages(additionalTypes = []) {
|
|
37
|
+
const adapterTypes = exports.PUBLIC_ADAPTER_TYPES.concat(additionalTypes);
|
|
38
|
+
const workspaces = JSON.parse(s.exec('yarn workspaces info', { silent: true }));
|
|
39
|
+
return Object.keys(workspaces)
|
|
40
|
+
.map((name) => ({ name, location: workspaces[name].location }))
|
|
41
|
+
.map(({ location, name }) => {
|
|
42
|
+
const pkg = getJsonFile((0, path_1.join)(location, 'package.json'));
|
|
43
|
+
return {
|
|
44
|
+
location,
|
|
45
|
+
name,
|
|
46
|
+
descopedName: name.replace(scope, ''),
|
|
47
|
+
type: location.split('/')[1],
|
|
48
|
+
version: pkg.version,
|
|
49
|
+
framework: '3',
|
|
50
|
+
};
|
|
51
|
+
})
|
|
52
|
+
.filter((v) => adapterTypes.includes(v.type))
|
|
53
|
+
.map((p) => {
|
|
54
|
+
let tsconf;
|
|
55
|
+
try {
|
|
56
|
+
tsconf = getJsonFile((0, path_1.join)(p.location, 'tsconfig.json'));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
warnLog(`${(0, path_1.join)(p.location, 'tsconfig.json')} does not exist`);
|
|
60
|
+
}
|
|
61
|
+
return { ...p, tsconf };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.getWorkspacePackages = getWorkspacePackages;
|
|
65
|
+
function getJsonFile(path) {
|
|
66
|
+
return JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param str The string to log
|
|
70
|
+
*/
|
|
71
|
+
function warnLog(str) {
|
|
72
|
+
if (process.env['DEBUG']) {
|
|
73
|
+
console.warn(str);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../../../../src/scripts/generator/workspace.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,2BAAiC;AACjC,+BAA2B;AAC3B,2CAA4B;AAe5B;;GAEG;AACU,QAAA,oBAAoB,GAAG,CAAC,SAAS,CAAC,CAAA;AAC/C,MAAM,KAAK,GAAG,aAAa,CAAA;AAG3B,SAAgB,oBAAoB,CAAC,kBAA4B,EAAE;IACjE,MAAM,YAAY,GAAG,4BAAoB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;IACjE,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAC/E,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;SAC3B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,QAAkB,EAAuB,CAAA,CAAC;SAC5F,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAoB,EAAE,EAAE;QAC5C,MAAM,GAAG,GAAwB,WAAW,CAAC,IAAA,WAAI,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAA;QAE5E,OAAO;YACL,QAAQ;YACR,IAAI;YACJ,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;YACrC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,SAAS,EAAE,GAAG;SACf,CAAA;IACH,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC5C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,IAAI,MAA4B,CAAA;QAChC,IAAI;YACF,MAAM,GAAG,WAAW,CAAC,IAAA,WAAI,EAAC,CAAC,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAA;SACxD;QAAC,MAAM;YACN,OAAO,CAAC,GAAG,IAAA,WAAI,EAAC,CAAC,CAAC,QAAQ,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAA;SAC/D;QAED,OAAO,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,CAAC,CAAC,CAAA;AACN,CAAC;AA5BD,oDA4BC;AACD,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;AAChD,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,GAAW;IAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;KAClB;AACH,CAAC"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { EndpointContext } from '../adapter';
|
|
3
3
|
import { AdapterConfig } from '../config';
|
|
4
|
-
import { ProviderResult } from '../util/request';
|
|
5
|
-
import {
|
|
6
|
-
import { TransportDependencies, TransportGenerics } from './';
|
|
4
|
+
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
5
|
+
import { TransportGenerics } from './';
|
|
7
6
|
import { SubscriptionTransport } from './abstract/subscription';
|
|
8
7
|
/**
|
|
9
8
|
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
10
9
|
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
11
10
|
*/
|
|
12
|
-
|
|
11
|
+
type BatchWarmingTransportGenerics = TransportGenerics & {
|
|
13
12
|
/**
|
|
14
13
|
* Type details for any provider specific interfaces.
|
|
15
14
|
*/
|
|
@@ -24,20 +23,11 @@ declare type HttpTransportGenerics = TransportGenerics & {
|
|
|
24
23
|
ResponseBody: unknown;
|
|
25
24
|
};
|
|
26
25
|
};
|
|
27
|
-
/**
|
|
28
|
-
* Structure containing the association between EA params and a provider request.
|
|
29
|
-
*/
|
|
30
|
-
declare type ProviderRequestConfig<T extends HttpTransportGenerics> = {
|
|
31
|
-
/** The input paramters for requests that will get responses from the request in this struct */
|
|
32
|
-
params: T['Request']['Params'][];
|
|
33
|
-
/** The request that will be sent to the data provider to fetch values for the params in this struct */
|
|
34
|
-
request: AxiosRequestConfig<T['Provider']['RequestBody']>;
|
|
35
|
-
};
|
|
36
26
|
/**
|
|
37
27
|
* Config object that is provided to the BatchWarmingTransport constructor.
|
|
38
28
|
*/
|
|
39
|
-
export interface
|
|
40
|
-
|
|
29
|
+
export interface BatchWarmingTransportConfig<T extends BatchWarmingTransportGenerics> {
|
|
30
|
+
prepareRequest: (params: T['Request']['Params'][], config: AdapterConfig<T['CustomSettings']>) => AxiosRequestConfig<T['Provider']['RequestBody']>;
|
|
41
31
|
parseResponse: (params: T['Request']['Params'][], res: AxiosResponse<T['Provider']['ResponseBody']>, config: AdapterConfig<T['CustomSettings']>) => ProviderResult<T>[];
|
|
42
32
|
}
|
|
43
33
|
/**
|
|
@@ -50,15 +40,13 @@ export interface HttpTransportConfig<T extends HttpTransportGenerics> {
|
|
|
50
40
|
*
|
|
51
41
|
* @typeParam T - all types related to the [[Transport]]
|
|
52
42
|
*/
|
|
53
|
-
export declare class
|
|
43
|
+
export declare class BatchWarmingTransport<T extends BatchWarmingTransportGenerics> extends SubscriptionTransport<T> {
|
|
54
44
|
private config;
|
|
55
45
|
WARMER_ACTIVE: boolean;
|
|
56
|
-
|
|
57
|
-
constructor(config: HttpTransportConfig<T>);
|
|
58
|
-
initialize(dependencies: TransportDependencies<T>, config: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
46
|
+
constructor(config: BatchWarmingTransportConfig<T>);
|
|
59
47
|
getSubscriptionTtlFromConfig(config: AdapterConfig<T['CustomSettings']>): number;
|
|
48
|
+
registerRequest(req: AdapterRequest<T['Request']>, config: AdapterConfig<T['CustomSettings']>): Promise<void>;
|
|
60
49
|
backgroundHandler(context: EndpointContext<T>, entries: T['Request']['Params'][]): Promise<void>;
|
|
61
|
-
private handleRequest;
|
|
62
50
|
private makeRequest;
|
|
63
51
|
}
|
|
64
52
|
export {};
|
|
@@ -23,14 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const axios_1 = require("axios");
|
|
26
|
+
exports.BatchWarmingTransport = void 0;
|
|
28
27
|
const cacheMetrics = __importStar(require("../cache/metrics"));
|
|
29
28
|
const rateLimitMetrics = __importStar(require("../rate-limiting/metrics"));
|
|
30
29
|
const util_1 = require("../util");
|
|
31
|
-
const requester_1 = require("../util/requester");
|
|
32
30
|
const error_1 = require("../validation/error");
|
|
33
31
|
const subscription_1 = require("./abstract/subscription");
|
|
32
|
+
const util_2 = require("./util");
|
|
34
33
|
const WARMUP_BATCH_REQUEST_ID = '9002';
|
|
35
34
|
const logger = (0, util_1.makeLogger)('BatchWarmingTransport');
|
|
36
35
|
/**
|
|
@@ -43,7 +42,7 @@ const logger = (0, util_1.makeLogger)('BatchWarmingTransport');
|
|
|
43
42
|
*
|
|
44
43
|
* @typeParam T - all types related to the [[Transport]]
|
|
45
44
|
*/
|
|
46
|
-
class
|
|
45
|
+
class BatchWarmingTransport extends subscription_1.SubscriptionTransport {
|
|
47
46
|
constructor(config) {
|
|
48
47
|
super();
|
|
49
48
|
this.config = config;
|
|
@@ -51,13 +50,23 @@ class HttpTransport extends subscription_1.SubscriptionTransport {
|
|
|
51
50
|
// Used for recording the cache warmer active metrics accurately
|
|
52
51
|
this.WARMER_ACTIVE = false;
|
|
53
52
|
}
|
|
54
|
-
async initialize(dependencies, config, endpointName) {
|
|
55
|
-
await super.initialize(dependencies, config, endpointName);
|
|
56
|
-
this.requester = new requester_1.Requester(dependencies.requestRateLimiter, config);
|
|
57
|
-
}
|
|
58
53
|
getSubscriptionTtlFromConfig(config) {
|
|
59
54
|
return config.WARMUP_SUBSCRIPTION_TTL;
|
|
60
55
|
}
|
|
56
|
+
async registerRequest(req, config) {
|
|
57
|
+
if (config.BATCH_TRANSPORT_SETUP_VALIDATION) {
|
|
58
|
+
const response = await this.makeRequest([req.requestContext.data], config);
|
|
59
|
+
if (!response.results.length) {
|
|
60
|
+
throw new error_1.AdapterError({
|
|
61
|
+
statusCode: 200,
|
|
62
|
+
providerStatusCode: response.providerResponse.status,
|
|
63
|
+
message: response.providerResponse.message ||
|
|
64
|
+
'There was an error while validating the incoming request before adding to the batch subscription set',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return super.registerRequest(req, config);
|
|
69
|
+
}
|
|
61
70
|
async backgroundHandler(context, entries) {
|
|
62
71
|
if (!entries.length) {
|
|
63
72
|
logger.debug('No entries in batch warming set, skipping');
|
|
@@ -73,65 +82,69 @@ class HttpTransport extends subscription_1.SubscriptionTransport {
|
|
|
73
82
|
cacheMetrics.cacheWarmerCount.labels({ isBatched: 'true' }).inc();
|
|
74
83
|
this.WARMER_ACTIVE = true;
|
|
75
84
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const requests = Array.isArray(rawRequests) ? rawRequests : [rawRequests];
|
|
79
|
-
logger.trace(`Queueing ${requests.length} requests`);
|
|
80
|
-
await Promise.all(requests.map((r) => this.handleRequest(r, context.adapterConfig)));
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
async handleRequest(requestConfig, adapterConfig) {
|
|
84
|
-
const results = await this.makeRequest(requestConfig, adapterConfig);
|
|
85
|
-
if (!results.length) {
|
|
85
|
+
const response = await this.makeRequest(entries, context.adapterConfig);
|
|
86
|
+
if (!response.results?.length) {
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
89
|
logger.debug('Setting adapter responses in cache');
|
|
89
|
-
await this.responseCache.write(results);
|
|
90
|
+
await this.responseCache.write(response.results);
|
|
91
|
+
// Record cost of data provider call
|
|
92
|
+
const cost = rateLimitMetrics.retrieveCost(response.providerResponse.data);
|
|
93
|
+
rateLimitMetrics.rateLimitCreditsSpentTotal
|
|
94
|
+
.labels({
|
|
95
|
+
feed_id: 'N/A',
|
|
96
|
+
participant_id: WARMUP_BATCH_REQUEST_ID,
|
|
97
|
+
})
|
|
98
|
+
.inc(cost);
|
|
99
|
+
return;
|
|
90
100
|
}
|
|
91
|
-
async makeRequest(
|
|
101
|
+
async makeRequest(entries, config) {
|
|
102
|
+
logger.trace(`Have ${entries.length} entries in batch, preparing request...`);
|
|
103
|
+
const request = this.config.prepareRequest(entries, config);
|
|
104
|
+
logger.trace(`Sending request to data provider: ${JSON.stringify(request)}`);
|
|
105
|
+
const providerDataRequested = Date.now();
|
|
106
|
+
let providerResponse;
|
|
92
107
|
try {
|
|
93
|
-
|
|
94
|
-
// Parse responses and apply timestamps
|
|
95
|
-
const results = this.config
|
|
96
|
-
.parseResponse(requestConfig.params, requesterResult.response, adapterConfig)
|
|
97
|
-
.map((r) => {
|
|
98
|
-
const result = r;
|
|
99
|
-
const partialResponse = r.response;
|
|
100
|
-
result.response.timestamps = {
|
|
101
|
-
...requesterResult.timestamps,
|
|
102
|
-
providerIndicatedTime: partialResponse.timestamps?.providerIndicatedTime,
|
|
103
|
-
};
|
|
104
|
-
return result;
|
|
105
|
-
});
|
|
106
|
-
// Record cost of data provider call
|
|
107
|
-
const cost = rateLimitMetrics.retrieveCost(requesterResult.response.data);
|
|
108
|
-
rateLimitMetrics.rateLimitCreditsSpentTotal
|
|
109
|
-
.labels({
|
|
110
|
-
feed_id: 'N/A',
|
|
111
|
-
participant_id: WARMUP_BATCH_REQUEST_ID,
|
|
112
|
-
})
|
|
113
|
-
.inc(cost);
|
|
114
|
-
return results;
|
|
108
|
+
providerResponse = await (0, util_2.axiosRequest)(request, config);
|
|
115
109
|
}
|
|
116
110
|
catch (e) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
const err = e.cause;
|
|
112
|
+
const providerDataReceived = Date.now();
|
|
113
|
+
logger.warn(`There was an error while performing the batch request: ${e}`);
|
|
114
|
+
return {
|
|
115
|
+
results: entries.map((entry) => ({
|
|
121
116
|
params: entry,
|
|
122
117
|
response: {
|
|
123
|
-
errorMessage: `Provider request failed with status ${
|
|
118
|
+
errorMessage: `Provider request failed with status ${err?.status}: "${err?.response?.data}"`,
|
|
124
119
|
statusCode: 502,
|
|
125
|
-
timestamps:
|
|
120
|
+
timestamps: {
|
|
121
|
+
providerDataRequested,
|
|
122
|
+
providerDataReceived,
|
|
123
|
+
providerIndicatedTime: undefined,
|
|
124
|
+
},
|
|
126
125
|
},
|
|
127
|
-
}))
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
logger.error(e);
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
126
|
+
})),
|
|
127
|
+
providerResponse: e,
|
|
128
|
+
};
|
|
133
129
|
}
|
|
130
|
+
const providerDataReceived = Date.now();
|
|
131
|
+
// Parse responses and apply timestamps
|
|
132
|
+
const results = this.config.parseResponse(entries, providerResponse, config).map((r) => {
|
|
133
|
+
const result = r;
|
|
134
|
+
const partialResponse = r.response;
|
|
135
|
+
result.response.timestamps = {
|
|
136
|
+
providerDataRequested,
|
|
137
|
+
providerDataReceived,
|
|
138
|
+
providerIndicatedTime: partialResponse.timestamps?.providerIndicatedTime,
|
|
139
|
+
};
|
|
140
|
+
return result;
|
|
141
|
+
});
|
|
142
|
+
logger.debug(`Got response from provider, parsing (raw body: ${providerResponse.data})`);
|
|
143
|
+
return {
|
|
144
|
+
results,
|
|
145
|
+
providerResponse,
|
|
146
|
+
};
|
|
134
147
|
}
|
|
135
148
|
}
|
|
136
|
-
exports.
|
|
149
|
+
exports.BatchWarmingTransport = BatchWarmingTransport;
|
|
137
150
|
//# sourceMappingURL=batch-warming.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-warming.js","sourceRoot":"","sources":["../../../src/transports/batch-warming.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"batch-warming.js","sourceRoot":"","sources":["../../../src/transports/batch-warming.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+DAAgD;AAEhD,2EAA4D;AAC5D,kCAAoC;AAOpC,+CAA4E;AAE5E,0DAA+D;AAC/D,iCAAqC;AAErC,MAAM,uBAAuB,GAAG,MAAM,CAAA;AAEtC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,uBAAuB,CAAC,CAAA;AAsClD;;;;;;;;;GASG;AACH,MAAa,qBAEX,SAAQ,oCAAwB;IAKhC,YAAoB,MAAsC;QACxD,KAAK,EAAE,CAAA;QADW,WAAM,GAAN,MAAM,CAAgC;QAJ1D,uGAAuG;QACvG,gEAAgE;QAChE,kBAAa,GAAG,KAAK,CAAA;IAIrB,CAAC;IAED,4BAA4B,CAAC,MAA0C;QACrE,OAAO,MAAM,CAAC,uBAAuB,CAAA;IACvC,CA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CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;oBAC/B,MAAM,EAAE,KAAK;oBACb,QAAQ,EAAE;wBACR,YAAY,EAAE,uCAAuC,GAAG,EAAE,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,IAAI,GAAG;wBAC5F,UAAU,EAAE,GAAG;wBACf,UAAU,EAAE;4BACV,qBAAqB;4BACrB,oBAAoB;4BACpB,qBAAqB,EAAE,SAAS;yBACjC;qBACF;iBACF,CAAC,CAAC;gBACH,gBAAgB,EAAE,CAAkB;aACrC,CAAA;SACF;QACD,MAAM,oBAAoB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEvC,uCAAuC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACrF,MAAM,MAAM,GAAG,CAAiC,CAAA;YAChD,MAAM,eAAe,GAAG,CAAC,CAAC,QAAoD,CAAA;YAC9E,MAAM,CAAC,QAAQ,CAAC,UAAU,GAAG;gBAC3B,qBAAqB;gBACrB,oBAAoB;gBACpB,qBAAqB,EAAE,eAAe,CAAC,UAAU,EAAE,qBAAqB;aACzE,CAAA;YACD,OAAO,MAAM,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,KAAK,CAAC,kDAAkD,gBAAgB,CAAC,IAAI,GAAG,CAAC,CAAA;QACxF,OAAO;YACL,OAAO;YACP,gBAAgB;SACjB,CAAA;IACH,CAAC;CACF;AAtID,sDAsIC"}
|
|
@@ -15,7 +15,7 @@ export declare class RoutingTransport<T extends TransportGenerics> implements Me
|
|
|
15
15
|
private route;
|
|
16
16
|
constructor(transports: {
|
|
17
17
|
[key: string]: Transport<T>;
|
|
18
|
-
}, route: (req: AdapterRequest<T['Request']>, adapterConfig
|
|
18
|
+
}, route: (req: AdapterRequest<T['Request']>, adapterConfig: AdapterConfig<T['CustomSettings']>) => string);
|
|
19
19
|
responseCache: ResponseCache<{
|
|
20
20
|
Request: T['Request'];
|
|
21
21
|
Response: T['Response'];
|
|
@@ -36,7 +36,7 @@ class RoutingTransport {
|
|
|
36
36
|
}
|
|
37
37
|
resolveTransport(req, adapterConfig) {
|
|
38
38
|
logger.debug(`routing request using `, req.requestContext.data);
|
|
39
|
-
const key = this.route(req, adapterConfig
|
|
39
|
+
const key = this.route(req, adapterConfig);
|
|
40
40
|
if (!this.transports[key]) {
|
|
41
41
|
logger.error(`No transport found for key ${key}`);
|
|
42
42
|
throw new error_1.AdapterError({ statusCode: 400, message: `No transport found for ${key}` });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../../src/transports/meta/routing.ts"],"names":[],"mappings":";;;AAGA,qCAAwE;AACxE,kDAAqD;AAGrD,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;IAOJ,KAAK,CAAC,UAAU,CACd,YAAsC,EACtC,aAAiD,EACjD,YAAoB;QAEpB,MAAM,CAAC,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,aAAa,CAAC,CAAA;QAC9E,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE;YACxD,MAAM,CAAC,KAAK,CAAC,0BAA0B,IAAI,KAAK,SAAS,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAA;YAC9E,OAAO,SAAS,CAAC,UAA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,CAAC,WAAW,CAAC,IAAI,qBAAqB,GAAG,EAAE,CAAC,CAAA;QAC3E,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,oFAAoF;IACpF,wDAAwD;IACxD,KAAK,CAAC,iBAAiB,CACrB,GAAiC,EACjC,aAAiD;QAEjD,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QAC3D,IAAI,SAAS,CAAC,iBAAiB,EAAE;YAC/B,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;YAChE,OAAO,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;SACvD;QACD,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAA;IACzE,CAAC;CACF;AA3ED,4CA2EC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAA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E;YACzB,MAAM,CAAC,KAAK,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAA;YACjD,MAAM,IAAI,oBAAY,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,0BAA0B,GAAG,EAAE,EAAE,CAAC,CAAA;SACtF;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QACtC,MAAM,CAAC,KAAK,CAAC,SAAS,SAAS,CAAC,WAAW,CAAC,IAAI,qBAAqB,GAAG,EAAE,CAAC,CAAA;QAC3E,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,oFAAoF;IACpF,wDAAwD;IACxD,KAAK,CAAC,iBAAiB,CACrB,GAAiC,EACjC,aAAiD;QAEjD,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QAC3D,IAAI,SAAS,CAAC,iBAAiB,EAAE;YAC/B,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;YAChE,OAAO,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;SACvD;QACD,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAA;IACzE,CAAC;CACF;AApED,4CAoEC"}
|
package/util/request.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare module 'fastify' {
|
|
|
6
6
|
requestContext: AdapterRequestContext;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type Merge<T1, T2> = {
|
|
10
10
|
[K in keyof T1 | keyof T2]: K extends keyof T2 ? T2[K] : K extends keyof T1 ? T1[K] : never;
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
@@ -22,7 +22,7 @@ export interface AdapterRequestBody<T = AdapterRequestData> {
|
|
|
22
22
|
* Object that will be added to the request on a successful validation.
|
|
23
23
|
* Contains all the necessary information the adapter will need across the request execution.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type AdapterRequestContext<T = AdapterRequestData> = {
|
|
26
26
|
/** Name of the endpoint this payload should be directed to */
|
|
27
27
|
endpointName: string;
|
|
28
28
|
/** Precalculated cache key used to get and set corresponding values from the cache and subscription sets */
|
|
@@ -35,18 +35,18 @@ export declare type AdapterRequestContext<T = AdapterRequestData> = {
|
|
|
35
35
|
/**
|
|
36
36
|
* Helper type to denote an empty body
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
type EmptyBody = Record<string, never>;
|
|
39
39
|
/**
|
|
40
40
|
* Helper type to provide fastify for all adapter handlers
|
|
41
41
|
*/
|
|
42
|
-
export
|
|
42
|
+
export type AdapterRouteGeneric = {
|
|
43
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
44
|
Body: EmptyBody;
|
|
45
45
|
};
|
|
46
46
|
/**
|
|
47
47
|
* Structure for all requests incoming to this adapter
|
|
48
48
|
*/
|
|
49
|
-
export
|
|
49
|
+
export type AdapterRequest<T extends RequestGenerics = RequestGenerics> = FastifyRequest<AdapterRouteGeneric> & {
|
|
50
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
51
|
body: EmptyBody;
|
|
52
52
|
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
@@ -73,23 +73,23 @@ export interface AdapterMetricsMeta {
|
|
|
73
73
|
/**
|
|
74
74
|
* Basic shape for the data within the request body
|
|
75
75
|
*/
|
|
76
|
-
export
|
|
76
|
+
export type AdapterRequestData = Record<string, unknown> & {
|
|
77
77
|
endpoint?: string;
|
|
78
78
|
};
|
|
79
|
-
export
|
|
79
|
+
export type ProviderResultGenerics = {
|
|
80
80
|
Request: RequestGenerics;
|
|
81
81
|
Response: ResponseGenerics;
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to.
|
|
85
85
|
*/
|
|
86
|
-
export
|
|
86
|
+
export type ProviderResult<T extends ProviderResultGenerics> = {
|
|
87
87
|
/** The set of parameters that uniquely relate to the response */
|
|
88
88
|
params: T['Request']['Params'];
|
|
89
89
|
/** Value that will be included in the result property of the response */
|
|
90
90
|
response: PartialAdapterResponse<T['Response']>;
|
|
91
91
|
};
|
|
92
|
-
export
|
|
92
|
+
export type TimestampedProviderResult<T extends ProviderResultGenerics> = Pick<ProviderResult<T>, 'params'> & {
|
|
93
93
|
/** Value that will be included in the result property of the response, with timestamps applied */
|
|
94
94
|
response: TimestampedAdapterResponse<T['Response']>;
|
|
95
95
|
};
|
|
@@ -97,11 +97,11 @@ export declare type TimestampedProviderResult<T extends ProviderResultGenerics>
|
|
|
97
97
|
* Here we do actually want an object, since unknown could be a primitive.
|
|
98
98
|
* The rule itself does say "marginally better"
|
|
99
99
|
*/
|
|
100
|
-
export
|
|
100
|
+
export type EmptyObject = Object;
|
|
101
101
|
/**
|
|
102
102
|
* Helper struct type that provides detail about the incoming Adapter Request
|
|
103
103
|
*/
|
|
104
|
-
export
|
|
104
|
+
export type RequestGenerics = {
|
|
105
105
|
/**
|
|
106
106
|
* Type for the parameters sent to the EA in the data property of the body.
|
|
107
107
|
*/
|
|
@@ -110,7 +110,7 @@ export declare type RequestGenerics = {
|
|
|
110
110
|
/**
|
|
111
111
|
* Helper struct type that provides detail about the outgoing Adapter Response
|
|
112
112
|
*/
|
|
113
|
-
export
|
|
113
|
+
export type ResponseGenerics = {
|
|
114
114
|
/**
|
|
115
115
|
* Type for the data property of the response.
|
|
116
116
|
*/
|
|
@@ -124,7 +124,7 @@ export declare type ResponseGenerics = {
|
|
|
124
124
|
/**
|
|
125
125
|
* Details for timestamps to be included in the response
|
|
126
126
|
*/
|
|
127
|
-
|
|
127
|
+
type ResponseTimestamps = {
|
|
128
128
|
/** Time at which data was received from the provider */
|
|
129
129
|
providerDataReceived: number;
|
|
130
130
|
/** Time indicated by the provider representing the time at which this value was calculated/set/valid */
|
|
@@ -147,14 +147,14 @@ export declare type ResponseTimestamps = {
|
|
|
147
147
|
/**
|
|
148
148
|
* Object with timestamps that will be present in both successful and provider error responses
|
|
149
149
|
*/
|
|
150
|
-
|
|
150
|
+
type TimestampedResponseObject = {
|
|
151
151
|
/** Timestamps relevant for data provider timings */
|
|
152
152
|
timestamps: ResponseTimestamps;
|
|
153
153
|
};
|
|
154
154
|
/**
|
|
155
155
|
* Response from the EA to send when manually storing an error in the cache
|
|
156
156
|
*/
|
|
157
|
-
|
|
157
|
+
type ProviderErrorResponse = {
|
|
158
158
|
/** Status code for the errored response */
|
|
159
159
|
statusCode: number;
|
|
160
160
|
/** Error message that will be sent back from the adapter */
|
|
@@ -167,11 +167,11 @@ declare type ProviderErrorResponse = {
|
|
|
167
167
|
/**
|
|
168
168
|
* Provider error response with timestamps added
|
|
169
169
|
*/
|
|
170
|
-
export
|
|
170
|
+
export type TimestampedProviderErrorResponse = ProviderErrorResponse & TimestampedResponseObject;
|
|
171
171
|
/**
|
|
172
172
|
* The most basic data that needs to be manually set for an adapter response.
|
|
173
173
|
*/
|
|
174
|
-
export
|
|
174
|
+
export type PartialSuccessfulResponse<T extends ResponseGenerics> = {
|
|
175
175
|
/** Response data, holds "result" for Flux Monitor */
|
|
176
176
|
data: T['Data'];
|
|
177
177
|
/** Result value used for OCR */
|
|
@@ -184,11 +184,11 @@ export declare type PartialSuccessfulResponse<T extends ResponseGenerics> = {
|
|
|
184
184
|
/**
|
|
185
185
|
* Partial EA response, with timestamps added
|
|
186
186
|
*/
|
|
187
|
-
|
|
187
|
+
type TimestampedSuccessfulResponse<T extends ResponseGenerics> = PartialSuccessfulResponse<T> & TimestampedResponseObject;
|
|
188
188
|
/**
|
|
189
189
|
* Full EA successful response, with metadata and defaults added
|
|
190
190
|
*/
|
|
191
|
-
|
|
191
|
+
type SuccessfulResponse<T extends ResponseGenerics> = TimestampedSuccessfulResponse<T> & {
|
|
192
192
|
/** Metadata relevant to this request */
|
|
193
193
|
meta?: AdapterRequestMeta;
|
|
194
194
|
/** HTTP status code, by default will be set to 200 */
|
|
@@ -197,21 +197,21 @@ declare type SuccessfulResponse<T extends ResponseGenerics> = TimestampedSuccess
|
|
|
197
197
|
/**
|
|
198
198
|
* Response body from the EA, before timestamps, defaults and metadata are filled in
|
|
199
199
|
*/
|
|
200
|
-
export
|
|
200
|
+
export type PartialAdapterResponse<T extends ResponseGenerics = ResponseGenerics> = PartialSuccessfulResponse<T> | ProviderErrorResponse;
|
|
201
201
|
/**
|
|
202
202
|
* Response body from the EA with timestamps, before defaults and metadata are filled in
|
|
203
203
|
*/
|
|
204
|
-
export
|
|
204
|
+
export type TimestampedAdapterResponse<T extends ResponseGenerics = ResponseGenerics> = TimestampedSuccessfulResponse<T> | TimestampedProviderErrorResponse;
|
|
205
205
|
/**
|
|
206
206
|
* Shape of the response body from the adapter
|
|
207
207
|
*/
|
|
208
|
-
export
|
|
209
|
-
export
|
|
208
|
+
export type AdapterResponse<T extends ResponseGenerics = ResponseGenerics> = SuccessfulResponse<T> | TimestampedProviderErrorResponse;
|
|
209
|
+
export type SingleNumberResultResponse = {
|
|
210
210
|
Result: number;
|
|
211
211
|
Data: {
|
|
212
212
|
result: number;
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
|
-
export
|
|
216
|
-
export
|
|
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
217
|
export {};
|