@chainlink/external-adapter-framework 0.0.8 → 0.0.12
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/.c8rc.json +3 -0
- package/.eslintignore +9 -0
- package/.eslintrc.js +96 -0
- package/.github/README.MD +17 -0
- package/.github/actions/setup/action.yaml +13 -0
- package/.github/workflows/main.yaml +39 -0
- package/.github/workflows/publish.yaml +20 -0
- package/.prettierignore +13 -0
- package/.yarnrc +0 -0
- package/README.md +103 -0
- package/dist/src/adapter.d.ts +135 -0
- package/dist/src/adapter.js +145 -0
- package/{package → dist/src}/background-executor.d.ts +2 -2
- package/{background-executor.js → dist/src/background-executor.js} +0 -0
- package/{cache → dist/src/cache}/factory.d.ts +0 -0
- package/{package → dist/src}/cache/factory.js +0 -2
- package/{package → dist/src}/cache/index.d.ts +10 -6
- package/{package → dist/src}/cache/index.js +13 -9
- package/{cache → dist/src/cache}/local.d.ts +0 -0
- package/{cache → dist/src/cache}/local.js +0 -0
- package/{cache → dist/src/cache}/metrics.d.ts +0 -0
- package/{cache → dist/src/cache}/metrics.js +0 -0
- package/{cache → dist/src/cache}/redis.d.ts +0 -0
- package/{package → dist/src}/cache/redis.js +5 -5
- package/dist/src/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
- package/{package → dist/src}/config/index.d.ts +20 -1
- package/{package → dist/src}/config/index.js +24 -9
- package/{config → dist/src/config}/provider-limits.d.ts +0 -0
- package/{config → dist/src/config}/provider-limits.js +0 -0
- package/dist/src/examples/bank-frick/accounts.d.ts +39 -0
- package/dist/src/examples/bank-frick/accounts.js +192 -0
- package/dist/src/examples/bank-frick/config/index.d.ts +4 -0
- package/dist/src/examples/bank-frick/config/index.js +54 -0
- package/dist/src/examples/bank-frick/index.d.ts +2 -0
- package/dist/src/examples/bank-frick/index.js +15 -0
- package/dist/src/examples/bank-frick/util.d.ts +4 -0
- package/dist/src/examples/bank-frick/util.js +39 -0
- package/dist/src/examples/coingecko/batch-warming.d.ts +7 -0
- package/{package → dist/src}/examples/coingecko/batch-warming.js +3 -2
- package/dist/src/examples/coingecko/index.d.ts +2 -0
- package/{package → dist/src}/examples/coingecko/index.js +3 -2
- package/dist/src/examples/coingecko/rest.d.ts +12 -0
- package/{package → dist/src}/examples/coingecko/rest.js +3 -2
- package/{examples → dist/src/examples}/ncfx/config/index.d.ts +0 -0
- package/{examples → dist/src/examples}/ncfx/config/index.js +0 -0
- package/dist/src/examples/ncfx/index.d.ts +13 -0
- package/{package → dist/src}/examples/ncfx/index.js +3 -2
- package/{package → dist/src}/examples/ncfx/websocket.d.ts +12 -1
- package/{package → dist/src}/examples/ncfx/websocket.js +3 -2
- package/{package → dist/src}/index.d.ts +2 -3
- package/{package → dist/src}/index.js +55 -19
- package/{metrics → dist/src/metrics}/constants.d.ts +0 -0
- package/{metrics → dist/src/metrics}/constants.js +0 -0
- package/{metrics → dist/src/metrics}/index.d.ts +0 -0
- package/{package → dist/src}/metrics/index.js +0 -1
- package/dist/src/metrics/util.d.ts +7 -0
- package/{package → dist/src}/metrics/util.js +2 -2
- package/{adapter.d.ts → dist/src/package/adapter.d.ts} +2 -2
- package/{adapter.js → dist/src/package/adapter.js} +0 -0
- package/{background-executor.d.ts → dist/src/package/background-executor.d.ts} +0 -0
- package/{package → dist/src/package}/background-executor.js +0 -0
- package/{package → dist/src/package}/cache/factory.d.ts +0 -0
- package/{cache → dist/src/package/cache}/factory.js +0 -0
- package/{cache → dist/src/package/cache}/index.d.ts +0 -0
- package/{cache → dist/src/package/cache}/index.js +0 -0
- package/{package → dist/src/package}/cache/local.d.ts +0 -0
- package/{package → dist/src/package}/cache/local.js +0 -0
- package/{package → dist/src/package}/cache/metrics.d.ts +0 -0
- package/{package → dist/src/package}/cache/metrics.js +0 -0
- package/{package → dist/src/package}/cache/redis.d.ts +0 -0
- package/{cache → dist/src/package/cache}/redis.js +0 -0
- package/{config → dist/src/package/config}/index.d.ts +0 -0
- package/{config → dist/src/package/config}/index.js +0 -0
- package/{package → dist/src/package}/config/provider-limits.d.ts +0 -0
- package/{package → dist/src/package}/config/provider-limits.js +2 -1
- package/{examples → dist/src/package/examples}/coingecko/batch-warming.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/batch-warming.js +0 -0
- package/{examples → dist/src/package/examples}/coingecko/index.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/index.js +0 -0
- package/{examples → dist/src/package/examples}/coingecko/rest.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/rest.js +0 -0
- package/{package → dist/src/package}/examples/ncfx/config/index.d.ts +0 -0
- package/{package → dist/src/package}/examples/ncfx/config/index.js +0 -0
- package/{examples → dist/src/package/examples}/ncfx/index.d.ts +0 -0
- package/{examples → dist/src/package/examples}/ncfx/index.js +0 -0
- package/{examples → dist/src/package/examples}/ncfx/websocket.d.ts +0 -0
- package/{examples → dist/src/package/examples}/ncfx/websocket.js +0 -0
- package/{index.d.ts → dist/src/package/index.d.ts} +1 -1
- package/{index.js → dist/src/package/index.js} +0 -0
- package/{package → dist/src/package}/metrics/constants.d.ts +0 -0
- package/{package → dist/src/package}/metrics/constants.js +0 -0
- package/{package → dist/src/package}/metrics/index.d.ts +0 -0
- package/{metrics → dist/src/package/metrics}/index.js +0 -0
- package/{metrics → dist/src/package/metrics}/util.d.ts +0 -0
- package/{metrics → dist/src/package/metrics}/util.js +0 -0
- package/dist/src/package/package.json +72 -0
- package/{package → dist/src/package}/rate-limiting/background/fixed-frequency.d.ts +0 -0
- package/{package → dist/src/package}/rate-limiting/background/fixed-frequency.js +0 -0
- package/{package → dist/src/package}/rate-limiting/index.d.ts +2 -2
- package/{package → dist/src/package}/rate-limiting/index.js +0 -0
- package/{package → dist/src/package}/rate-limiting/metrics.d.ts +0 -0
- package/{package → dist/src/package}/rate-limiting/metrics.js +0 -0
- package/{package → dist/src/package}/rate-limiting/request/simple-counting.d.ts +0 -0
- package/{package → dist/src/package}/rate-limiting/request/simple-counting.js +0 -0
- package/{package → dist/src/package}/test.d.ts +0 -0
- package/{package → dist/src/package}/test.js +0 -0
- package/{package → dist/src/package}/transports/batch-warming.d.ts +0 -0
- package/{package → dist/src/package}/transports/batch-warming.js +0 -0
- package/{package → dist/src/package}/transports/index.d.ts +0 -0
- package/{package → dist/src/package}/transports/index.js +0 -0
- package/{package → dist/src/package}/transports/metrics.d.ts +1 -1
- package/{package → dist/src/package}/transports/metrics.js +0 -0
- package/{package → dist/src/package}/transports/rest.d.ts +0 -0
- package/{package → dist/src/package}/transports/rest.js +0 -0
- package/{package → dist/src/package}/transports/util.d.ts +0 -0
- package/{package → dist/src/package}/transports/util.js +0 -0
- package/{package → dist/src/package}/transports/websocket.d.ts +0 -0
- package/{package → dist/src/package}/transports/websocket.js +0 -0
- package/{package → dist/src/package}/util/expiring-sorted-set.d.ts +0 -0
- package/{package → dist/src/package}/util/expiring-sorted-set.js +0 -0
- package/{package → dist/src/package}/util/index.d.ts +0 -0
- package/{package → dist/src/package}/util/index.js +0 -0
- package/{package → dist/src/package}/util/logger.d.ts +0 -0
- package/{package → dist/src/package}/util/logger.js +0 -0
- package/{package → dist/src/package}/util/request.d.ts +0 -0
- package/{package → dist/src/package}/util/request.js +0 -0
- package/{package → dist/src/package}/validation/error.d.ts +0 -0
- package/{package → dist/src/package}/validation/error.js +0 -0
- package/{package → dist/src/package}/validation/index.d.ts +0 -0
- package/{package → dist/src/package}/validation/index.js +0 -0
- package/{package → dist/src/package}/validation/input-params.d.ts +0 -0
- package/{package → dist/src/package}/validation/input-params.js +0 -0
- package/{package → dist/src/package}/validation/override-functions.d.ts +0 -0
- package/{package → dist/src/package}/validation/override-functions.js +0 -0
- package/{package → dist/src/package}/validation/preset-tokens.json +0 -0
- package/{package → dist/src/package}/validation/validator.d.ts +0 -0
- package/{package → dist/src/package}/validation/validator.js +0 -0
- package/{package → dist/src}/package.json +5 -2
- package/{rate-limiting → dist/src/rate-limiting}/background/fixed-frequency.d.ts +2 -1
- package/{rate-limiting → dist/src/rate-limiting}/background/fixed-frequency.js +0 -2
- package/{rate-limiting → dist/src/rate-limiting}/index.d.ts +4 -3
- package/{rate-limiting → dist/src/rate-limiting}/index.js +0 -0
- package/{rate-limiting → dist/src/rate-limiting}/metrics.d.ts +0 -0
- package/{rate-limiting → dist/src/rate-limiting}/metrics.js +0 -0
- package/{rate-limiting → dist/src/rate-limiting}/request/simple-counting.d.ts +2 -1
- package/{rate-limiting → dist/src/rate-limiting}/request/simple-counting.js +0 -0
- package/{test.d.ts → dist/src/test.d.ts} +0 -0
- package/{test.js → dist/src/test.js} +2 -2
- package/{transports → dist/src/transports}/batch-warming.d.ts +4 -3
- package/{transports → dist/src/transports}/batch-warming.js +4 -4
- package/{transports → dist/src/transports}/index.d.ts +5 -22
- package/{transports → dist/src/transports}/index.js +3 -3
- package/{transports → dist/src/transports}/metrics.d.ts +4 -3
- package/{transports → dist/src/transports}/metrics.js +2 -2
- package/{transports → dist/src/transports}/rest.d.ts +2 -1
- package/{transports → dist/src/transports}/rest.js +3 -1
- package/{transports → dist/src/transports}/util.d.ts +0 -0
- package/{transports → dist/src/transports}/util.js +0 -0
- package/{transports → dist/src/transports}/websocket.d.ts +7 -7
- package/{transports → dist/src/transports}/websocket.js +8 -11
- package/{util → dist/src/util}/expiring-sorted-set.d.ts +0 -0
- package/{util → dist/src/util}/expiring-sorted-set.js +0 -0
- package/{util → dist/src/util}/index.d.ts +2 -1
- package/{util → dist/src/util}/index.js +1 -1
- package/{util → dist/src/util}/logger.d.ts +0 -0
- package/{util → dist/src/util}/logger.js +0 -0
- package/{util → dist/src/util}/request.d.ts +5 -3
- package/{util → dist/src/util}/request.js +0 -0
- package/dist/src/util/subscription-set/expiring-sorted-set.d.ts +22 -0
- package/dist/src/util/subscription-set/expiring-sorted-set.js +47 -0
- package/dist/src/util/subscription-set/subscription-set.d.ts +18 -0
- package/dist/src/util/subscription-set/subscription-set.js +19 -0
- package/dist/src/util/test-payload-loader.d.ts +25 -0
- package/dist/src/util/test-payload-loader.js +83 -0
- package/{validation → dist/src/validation}/error.d.ts +4 -4
- package/{validation → dist/src/validation}/error.js +1 -1
- package/{validation → dist/src/validation}/index.d.ts +0 -0
- package/{validation → dist/src/validation}/index.js +8 -3
- package/{validation → dist/src/validation}/input-params.d.ts +0 -0
- package/{validation → dist/src/validation}/input-params.js +0 -0
- package/dist/src/validation/override-functions.d.ts +3 -0
- package/{validation → dist/src/validation}/override-functions.js +0 -0
- package/{validation → dist/src/validation}/preset-tokens.json +0 -0
- package/{validation → dist/src/validation}/validator.d.ts +0 -0
- package/{validation → dist/src/validation}/validator.js +0 -0
- package/docker-compose.yaml +35 -0
- package/env.sh +54 -0
- package/env2.sh +55 -0
- package/package.json +5 -3
- package/publish.sh +0 -0
- package/src/adapter.ts +263 -0
- package/src/background-executor.ts +52 -0
- package/src/cache/factory.ts +26 -0
- package/src/cache/index.ts +258 -0
- package/src/cache/local.ts +73 -0
- package/src/cache/metrics.ts +112 -0
- package/src/cache/redis.ts +93 -0
- package/src/config/index.ts +517 -0
- package/src/config/provider-limits.ts +130 -0
- package/src/examples/bank-frick/README.MD +10 -0
- package/src/examples/bank-frick/accounts.ts +246 -0
- package/src/examples/bank-frick/config/index.ts +53 -0
- package/src/examples/bank-frick/index.ts +13 -0
- package/src/examples/bank-frick/types.d.ts +38 -0
- package/src/examples/bank-frick/util.ts +55 -0
- package/src/examples/coingecko/batch-warming.ts +78 -0
- package/src/examples/coingecko/index.ts +9 -0
- package/src/examples/coingecko/rest.ts +77 -0
- package/src/examples/ncfx/config/index.ts +12 -0
- package/src/examples/ncfx/index.ts +9 -0
- package/src/examples/ncfx/websocket.ts +99 -0
- package/src/index.ts +149 -0
- package/src/metrics/constants.ts +23 -0
- package/src/metrics/index.ts +115 -0
- package/src/metrics/util.ts +18 -0
- package/src/rate-limiting/background/fixed-frequency.ts +45 -0
- package/src/rate-limiting/index.ts +100 -0
- package/src/rate-limiting/metrics.ts +18 -0
- package/src/rate-limiting/request/simple-counting.ts +76 -0
- package/src/test.ts +5 -0
- package/src/transports/batch-warming.ts +122 -0
- package/src/transports/index.ts +152 -0
- package/src/transports/metrics.ts +95 -0
- package/src/transports/rest.ts +164 -0
- package/src/transports/util.ts +63 -0
- package/src/transports/websocket.ts +245 -0
- package/src/util/index.ts +22 -0
- package/src/util/logger.ts +69 -0
- package/src/util/request.ts +117 -0
- package/src/util/subscription-set/expiring-sorted-set.ts +54 -0
- package/src/util/subscription-set/subscription-set.ts +35 -0
- package/src/util/test-payload-loader.ts +87 -0
- package/src/validation/error.ts +116 -0
- package/src/validation/index.ts +110 -0
- package/src/validation/input-params.ts +45 -0
- package/src/validation/override-functions.ts +44 -0
- package/src/validation/preset-tokens.json +23 -0
- package/src/validation/validator.ts +384 -0
- package/test/adapter.test.ts +27 -0
- package/test/background-executor.test.ts +108 -0
- package/test/cache/cache-key.test.ts +114 -0
- package/test/cache/helper.ts +100 -0
- package/test/cache/local.test.ts +54 -0
- package/test/cache/redis.test.ts +89 -0
- package/test/correlation.test.ts +114 -0
- package/test/index.test.ts +37 -0
- package/test/metrics/feed-id.test.ts +38 -0
- package/test/metrics/helper.ts +14 -0
- package/test/metrics/labels.test.ts +36 -0
- package/test/metrics/metrics.test.ts +267 -0
- package/test/metrics/redis-metrics.test.ts +113 -0
- package/test/metrics/warmer-metrics.test.ts +192 -0
- package/test/metrics/ws-metrics.test.ts +225 -0
- package/test/rate-limit-config.test.ts +242 -0
- package/test/smoke.test.ts +166 -0
- package/test/transports/batch.test.ts +465 -0
- package/test/transports/rest.test.ts +242 -0
- package/test/transports/websocket.test.ts +183 -0
- package/test/tsconfig.json +5 -0
- package/test/util.ts +77 -0
- package/test/validation.test.ts +178 -0
- package/test-payload-fail.json +3 -0
- package/test-payload.js +22 -0
- package/test-payload.json +7 -0
- package/test.sh +20 -0
- package/test2.sh +2 -0
- package/tsconfig.json +25 -0
- package/typedoc.json +6 -0
- package/webpack.config.js +23 -0
- package/chainlink-external-adapter-framework-v0.0.8.tgz +0 -0
- package/package/adapter.d.ts +0 -88
- package/package/adapter.js +0 -112
- package/package/examples/coingecko/batch-warming.d.ts +0 -2
- package/package/examples/coingecko/index.d.ts +0 -2
- package/package/examples/coingecko/rest.d.ts +0 -2
- package/package/examples/ncfx/index.d.ts +0 -2
- package/package/metrics/util.d.ts +0 -3
- package/validation/override-functions.d.ts +0 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.batchEndpoint = void 0;
|
|
4
|
+
const adapter_1 = require("../../adapter");
|
|
4
5
|
const batch_warming_1 = require("../../transports/batch-warming");
|
|
5
6
|
const DEFAULT_URL = 'https://pro-api.coingecko.com/api/v3';
|
|
6
7
|
const inputParameters = {
|
|
@@ -45,8 +46,8 @@ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
|
|
|
45
46
|
return entries;
|
|
46
47
|
},
|
|
47
48
|
});
|
|
48
|
-
exports.batchEndpoint = {
|
|
49
|
+
exports.batchEndpoint = new adapter_1.AdapterEndpoint({
|
|
49
50
|
name: 'batch',
|
|
50
51
|
transport: batchEndpointTransport,
|
|
51
52
|
inputParameters,
|
|
52
|
-
};
|
|
53
|
+
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.adapter = void 0;
|
|
4
|
+
const adapter_1 = require("../../adapter");
|
|
4
5
|
const batch_warming_1 = require("./batch-warming");
|
|
5
6
|
const rest_1 = require("./rest");
|
|
6
|
-
exports.adapter = {
|
|
7
|
+
exports.adapter = new adapter_1.Adapter({
|
|
7
8
|
name: 'coingecko',
|
|
8
9
|
defaultEndpoint: 'batch',
|
|
9
10
|
endpoints: [rest_1.restEndpoint, batch_warming_1.batchEndpoint],
|
|
10
|
-
};
|
|
11
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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 {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.restEndpoint = void 0;
|
|
4
|
+
const adapter_1 = require("../../adapter");
|
|
4
5
|
const transports_1 = require("../../transports");
|
|
5
6
|
const DEFAULT_URL = 'https://api.coingecko.com/api/v3';
|
|
6
7
|
const inputParameters = {
|
|
@@ -42,9 +43,9 @@ const restEndpointTransport = new transports_1.RestTransport({
|
|
|
42
43
|
coalescing: true,
|
|
43
44
|
},
|
|
44
45
|
});
|
|
45
|
-
exports.restEndpoint = {
|
|
46
|
+
exports.restEndpoint = new adapter_1.AdapterEndpoint({
|
|
46
47
|
name: 'rest',
|
|
47
48
|
aliases: ['qwe'],
|
|
48
49
|
transport: restEndpointTransport,
|
|
49
50
|
inputParameters,
|
|
50
|
-
};
|
|
51
|
+
});
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Adapter } from '../../adapter';
|
|
2
|
+
export declare const adapter: Adapter<{
|
|
3
|
+
readonly USERNAME: {
|
|
4
|
+
readonly description: "Username for the NCFX API";
|
|
5
|
+
readonly type: "string";
|
|
6
|
+
readonly required: true;
|
|
7
|
+
};
|
|
8
|
+
readonly PASSWORD: {
|
|
9
|
+
readonly description: "Password for the NCFX API";
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
readonly required: true;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.adapter = void 0;
|
|
4
|
+
const adapter_1 = require("../../adapter");
|
|
4
5
|
const config_1 = require("./config");
|
|
5
6
|
const websocket_1 = require("./websocket");
|
|
6
|
-
exports.adapter = {
|
|
7
|
+
exports.adapter = new adapter_1.Adapter({
|
|
7
8
|
name: 'ncfx',
|
|
8
9
|
endpoints: [websocket_1.webSocketEndpoint],
|
|
9
10
|
customSettings: config_1.customSettings,
|
|
10
|
-
};
|
|
11
|
+
});
|
|
@@ -32,5 +32,16 @@ export declare const websocketTransport: WebSocketTransport<AdapterRequestParams
|
|
|
32
32
|
readonly required: true;
|
|
33
33
|
};
|
|
34
34
|
}>;
|
|
35
|
-
export declare const webSocketEndpoint: AdapterEndpoint
|
|
35
|
+
export declare const webSocketEndpoint: AdapterEndpoint<AdapterRequestParams, unknown, {
|
|
36
|
+
readonly USERNAME: {
|
|
37
|
+
readonly description: "Username for the NCFX API";
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
readonly required: true;
|
|
40
|
+
};
|
|
41
|
+
readonly PASSWORD: {
|
|
42
|
+
readonly description: "Password for the NCFX API";
|
|
43
|
+
readonly type: "string";
|
|
44
|
+
readonly required: true;
|
|
45
|
+
};
|
|
46
|
+
}>;
|
|
36
47
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.webSocketEndpoint = exports.websocketTransport = exports.inputParameters = void 0;
|
|
4
|
+
const adapter_1 = require("../../adapter");
|
|
4
5
|
const websocket_1 = require("../../transports/websocket");
|
|
5
6
|
const util_1 = require("../../util");
|
|
6
7
|
exports.inputParameters = {
|
|
@@ -65,8 +66,8 @@ exports.websocketTransport = new websocket_1.WebSocketTransport({
|
|
|
65
66
|
}),
|
|
66
67
|
},
|
|
67
68
|
});
|
|
68
|
-
exports.webSocketEndpoint = {
|
|
69
|
+
exports.webSocketEndpoint = new adapter_1.AdapterEndpoint({
|
|
69
70
|
name: 'websocket',
|
|
70
71
|
transport: exports.websocketTransport,
|
|
71
72
|
inputParameters: exports.inputParameters,
|
|
72
|
-
};
|
|
73
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Server } from 'http';
|
|
2
|
-
import { Adapter } from './adapter';
|
|
3
|
-
import { AdapterDependencies } from './transports';
|
|
2
|
+
import { Adapter, AdapterDependencies } from './adapter';
|
|
4
3
|
/**
|
|
5
4
|
* Main function for the framework.
|
|
6
5
|
* Initializes config and dependencies, uses those to initialize Transports, and starts listening for requests.
|
|
@@ -9,4 +8,4 @@ import { AdapterDependencies } from './transports';
|
|
|
9
8
|
* @param dependencies - an optional object with adapter dependencies to inject
|
|
10
9
|
* @returns a Promise that resolves to the http.Server listening for connections
|
|
11
10
|
*/
|
|
12
|
-
export declare const expose: (adapter: Adapter, dependencies?: Partial<AdapterDependencies>
|
|
11
|
+
export declare const expose: (adapter: Adapter, dependencies?: Partial<AdapterDependencies>) => Promise<Server | undefined>;
|
|
@@ -6,13 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.expose = void 0;
|
|
7
7
|
const fastify_1 = __importDefault(require("fastify"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
-
const adapter_1 = require("./adapter");
|
|
10
9
|
const background_executor_1 = require("./background-executor");
|
|
11
10
|
const cache_1 = require("./cache");
|
|
12
|
-
const config_1 = require("./config");
|
|
13
11
|
const metrics_1 = require("./metrics");
|
|
14
12
|
const transports_1 = require("./transports");
|
|
15
13
|
const util_1 = require("./util");
|
|
14
|
+
const test_payload_loader_1 = require("./util/test-payload-loader");
|
|
16
15
|
const validation_1 = require("./validation");
|
|
17
16
|
const logger = (0, util_1.makeLogger)('Main');
|
|
18
17
|
const VERSION = process.env['npm_package_version'];
|
|
@@ -25,22 +24,18 @@ const VERSION = process.env['npm_package_version'];
|
|
|
25
24
|
* @returns a Promise that resolves to the http.Server listening for connections
|
|
26
25
|
*/
|
|
27
26
|
const expose = async (adapter, dependencies) => {
|
|
28
|
-
const config = (0, config_1.buildAdapterConfig)({
|
|
29
|
-
overrides: adapter.envDefaultOverrides,
|
|
30
|
-
customSettings: adapter.customSettings,
|
|
31
|
-
});
|
|
32
27
|
// Initialize adapter (create dependencies, inject them, build endpoint map, etc.)
|
|
33
|
-
|
|
28
|
+
await adapter.initialize(dependencies);
|
|
34
29
|
let server = undefined;
|
|
35
|
-
if (config.METRICS_ENABLED && config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
36
|
-
(0, metrics_1.setupMetricsServer)(adapter.name, config);
|
|
30
|
+
if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
31
|
+
(0, metrics_1.setupMetricsServer)(adapter.name, adapter.config);
|
|
37
32
|
}
|
|
38
|
-
if (config.EA_MODE === 'reader' || config.EA_MODE === 'reader-writer') {
|
|
33
|
+
if (adapter.config.EA_MODE === 'reader' || adapter.config.EA_MODE === 'reader-writer') {
|
|
39
34
|
// Main REST API server to handle incoming requests
|
|
40
|
-
const app = await buildRestApi(
|
|
35
|
+
const app = await buildRestApi(adapter);
|
|
41
36
|
// Start listening for incoming requests
|
|
42
37
|
try {
|
|
43
|
-
await app.listen(config.EA_PORT, config.EA_HOST);
|
|
38
|
+
await app.listen(adapter.config.EA_PORT, adapter.config.EA_HOST);
|
|
44
39
|
}
|
|
45
40
|
catch (err) {
|
|
46
41
|
logger.fatal(`There was an error when starting the EA server: ${err}`);
|
|
@@ -52,10 +47,10 @@ const expose = async (adapter, dependencies) => {
|
|
|
52
47
|
else {
|
|
53
48
|
logger.info('REST API is disabled; this instance will not process incoming requests.');
|
|
54
49
|
}
|
|
55
|
-
if (config.EA_MODE === 'writer' || config.EA_MODE === 'reader-writer') {
|
|
50
|
+
if (adapter.config.EA_MODE === 'writer' || adapter.config.EA_MODE === 'reader-writer') {
|
|
56
51
|
// Start background loop that will take care of calling any async Transports
|
|
57
52
|
logger.info('Starting background execution loop');
|
|
58
|
-
(0, background_executor_1.callBackgroundExecutes)(
|
|
53
|
+
(0, background_executor_1.callBackgroundExecutes)(adapter, server);
|
|
59
54
|
}
|
|
60
55
|
else {
|
|
61
56
|
logger.info('Background executor is disabled; this instance will not perform async background executes.');
|
|
@@ -63,7 +58,8 @@ const expose = async (adapter, dependencies) => {
|
|
|
63
58
|
return server;
|
|
64
59
|
};
|
|
65
60
|
exports.expose = expose;
|
|
66
|
-
async function buildRestApi(
|
|
61
|
+
async function buildRestApi(adapter) {
|
|
62
|
+
const { config } = adapter;
|
|
67
63
|
const app = (0, fastify_1.default)();
|
|
68
64
|
// Add healthcheck endpoint before middlewares to bypass them
|
|
69
65
|
app.get((0, path_1.join)(config.BASE_URL, 'health'), (req, res) => {
|
|
@@ -71,11 +67,11 @@ async function buildRestApi(config, initializedAdapter) {
|
|
|
71
67
|
});
|
|
72
68
|
// Use global error handling
|
|
73
69
|
app.setErrorHandler(validation_1.errorCatchingMiddleware);
|
|
74
|
-
const transportHandler = await (0, transports_1.buildTransportHandler)(
|
|
70
|
+
const transportHandler = await (0, transports_1.buildTransportHandler)(adapter);
|
|
75
71
|
app.register(async (router) => {
|
|
76
72
|
// Set up "middlewares" (hooks in fastify)
|
|
77
|
-
router.addHook('preHandler', (0, validation_1.validatorMiddleware)(
|
|
78
|
-
router.addHook('preHandler', (0, cache_1.buildCacheMiddleware)(
|
|
73
|
+
router.addHook('preHandler', (0, validation_1.validatorMiddleware)(adapter));
|
|
74
|
+
router.addHook('preHandler', (0, cache_1.buildCacheMiddleware)(adapter));
|
|
79
75
|
if (config['CORRELATION_ID_ENABLED']) {
|
|
80
76
|
router.addHook('onRequest', util_1.loggingContextMiddleware);
|
|
81
77
|
}
|
|
@@ -83,10 +79,50 @@ async function buildRestApi(config, initializedAdapter) {
|
|
|
83
79
|
url: config.BASE_URL,
|
|
84
80
|
method: 'POST',
|
|
85
81
|
handler: transportHandler,
|
|
86
|
-
});
|
|
82
|
+
});
|
|
87
83
|
if (config.METRICS_ENABLED && config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
88
84
|
router.addHook('onResponse', metrics_1.buildMetricsMiddleware);
|
|
89
85
|
}
|
|
90
86
|
});
|
|
87
|
+
// Add smoke endpoint after middleware which are needed for tests
|
|
88
|
+
buildSmokeEndpoint(app, config);
|
|
91
89
|
return app;
|
|
92
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Adds the /smoke endpoint to the API for smoke testing the adapter
|
|
93
|
+
*
|
|
94
|
+
* @param app - the Fastify instance
|
|
95
|
+
* @param config - the initialized adapter config
|
|
96
|
+
*/
|
|
97
|
+
function buildSmokeEndpoint(app, config) {
|
|
98
|
+
const testPayload = (0, test_payload_loader_1.loadTestPayload)(config.SMOKE_TEST_PAYLOAD_FILE_NAME);
|
|
99
|
+
app.get((0, path_1.join)(config.BASE_URL, 'smoke'), async (_, res) => {
|
|
100
|
+
if (testPayload.isDefault) {
|
|
101
|
+
return res.status(200).send('OK');
|
|
102
|
+
}
|
|
103
|
+
const errors = [];
|
|
104
|
+
for (const index in testPayload.requests) {
|
|
105
|
+
try {
|
|
106
|
+
const request = { id: index, data: testPayload.requests[index] };
|
|
107
|
+
// Use Fastify's app inject to pass smoke requests internally
|
|
108
|
+
const response = await app.inject({
|
|
109
|
+
method: 'POST',
|
|
110
|
+
url: '/',
|
|
111
|
+
payload: request,
|
|
112
|
+
});
|
|
113
|
+
const parsedResponse = JSON.parse(response.body);
|
|
114
|
+
// Throw error if not 2xx status code
|
|
115
|
+
if (parsedResponse.statusCode < 200 || parsedResponse.statusCode > 299) {
|
|
116
|
+
throw Error('Smoke test request failed');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
errors.push(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (errors.length > 0) {
|
|
124
|
+
return res.status(500).send(errors);
|
|
125
|
+
}
|
|
126
|
+
return res.status(200).send('OK');
|
|
127
|
+
});
|
|
128
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -86,7 +86,6 @@ const buildHttpRequestMetricsLabel = (feedId, error, cacheHit) => {
|
|
|
86
86
|
}
|
|
87
87
|
else if (error instanceof Error) {
|
|
88
88
|
// If error present and not instance of generic Error, unexpected failure occurred
|
|
89
|
-
// TODO: Build label with 500 error and withold dp status? Status sent as 200 in error handler
|
|
90
89
|
labels.type = constants_1.HttpRequestType.ADAPTER_ERROR;
|
|
91
90
|
labels.status_code = 500;
|
|
92
91
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AdapterMetricsMeta, AdapterRequestData } from '../util';
|
|
2
|
+
import { AdapterEndpoint } from '../adapter';
|
|
3
|
+
import { AdapterConfig, SettingsMap } from '../config';
|
|
4
|
+
export declare const getMetricsMeta: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
|
|
5
|
+
adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
|
|
6
|
+
adapterConfig: AdapterConfig<CustomSettings>;
|
|
7
|
+
}, data: AdapterRequestData) => AdapterMetricsMeta;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMetricsMeta = void 0;
|
|
4
4
|
const cache_1 = require("../cache");
|
|
5
|
-
const getMetricsMeta = (
|
|
6
|
-
const feedId = (0, cache_1.calculateFeedId)(
|
|
5
|
+
const getMetricsMeta = ({ adapterEndpoint, adapterConfig, }, data) => {
|
|
6
|
+
const feedId = (0, cache_1.calculateFeedId)({ adapterEndpoint, adapterConfig }, data);
|
|
7
7
|
return { feedId };
|
|
8
8
|
};
|
|
9
9
|
exports.getMetricsMeta = getMetricsMeta;
|
|
@@ -74,7 +74,7 @@ export interface InitializedAdapter extends Adapter {
|
|
|
74
74
|
* @param rateLimitingConfig - details from the adapter regarding rate limiting
|
|
75
75
|
* @returns a set of AdapterDependencies all initialized
|
|
76
76
|
*/
|
|
77
|
-
export declare const initializeDependencies: (adapter: Adapter, config: AdapterConfig, inputDependencies?: Partial<AdapterDependencies>
|
|
77
|
+
export declare const initializeDependencies: (adapter: Adapter, config: AdapterConfig, inputDependencies?: Partial<AdapterDependencies>) => AdapterDependencies;
|
|
78
78
|
/**
|
|
79
79
|
* Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
|
|
80
80
|
* Additionally, it builds a map out of all the endpoint names and aliases (checking for duplicates).
|
|
@@ -84,5 +84,5 @@ export declare const initializeDependencies: (adapter: Adapter, config: AdapterC
|
|
|
84
84
|
* @param config - configuration variables already processed and validated
|
|
85
85
|
* @returns - the adapter with all transports initialized and aliases map built
|
|
86
86
|
*/
|
|
87
|
-
export declare const initializeAdapter: (adapter: Adapter, config: AdapterConfig, dependencies?: Partial<AdapterDependencies>
|
|
87
|
+
export declare const initializeAdapter: (adapter: Adapter, config: AdapterConfig, dependencies?: Partial<AdapterDependencies>) => Promise<InitializedAdapter>;
|
|
88
88
|
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -42,7 +42,8 @@ const getProviderLimits = (provider, limits, tier, protocol) => {
|
|
|
42
42
|
return limitsConfig;
|
|
43
43
|
};
|
|
44
44
|
const parseLimits = (limits) => {
|
|
45
|
-
const _mapObject = (fn) => (o) => Object.fromEntries(Object.entries(o).map(fn))
|
|
45
|
+
// const _mapObject = (fn: any) => (o: any) => Object.fromEntries(Object.entries(o).map(fn))
|
|
46
|
+
const _mapObject = (fn) => (o) => Object.fromEntries([]);
|
|
46
47
|
const _formatProtocol = _mapObject((entry) => {
|
|
47
48
|
const [tierName, rest] = entry;
|
|
48
49
|
return [tierName.toLowerCase(), { ...rest }];
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -9,4 +9,4 @@ import { AdapterDependencies } from './transports';
|
|
|
9
9
|
* @param dependencies - an optional object with adapter dependencies to inject
|
|
10
10
|
* @returns a Promise that resolves to the http.Server listening for connections
|
|
11
11
|
*/
|
|
12
|
-
export declare const expose: (adapter: Adapter, dependencies?: Partial<AdapterDependencies>
|
|
12
|
+
export declare const expose: (adapter: Adapter, dependencies?: Partial<AdapterDependencies>) => Promise<Server | undefined>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chainlink/external-adapter-framework",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"axios": "^0.27.2",
|
|
8
|
+
"fastify": "^3.29.0",
|
|
9
|
+
"ioredis": "^5.0.4",
|
|
10
|
+
"pino": "^7.9.2",
|
|
11
|
+
"prom-client": "13.2.0",
|
|
12
|
+
"ts-node": "^10.9.1",
|
|
13
|
+
"typescript": "^4.6.3",
|
|
14
|
+
"ws": "^8.5.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"start": "ts-node src/test.ts",
|
|
18
|
+
"generate-docs": "typedoc src/**/*.ts",
|
|
19
|
+
"test": "LOG_LEVEL=error EA_PORT=0 c8 ava",
|
|
20
|
+
"test-debug": "LOG_LEVEL=trace DEBUG=true EA_PORT=0 c8 ava --verbose",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"lint": "eslint ./src"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@sinonjs/fake-timers": "^9.1.2",
|
|
26
|
+
"@types/node": "^18.6.5",
|
|
27
|
+
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
28
|
+
"@types/ws": "^8.5.3",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
30
|
+
"@typescript-eslint/parser": "^5.17.0",
|
|
31
|
+
"ava": "^4.2.0",
|
|
32
|
+
"c8": "^7.11.2",
|
|
33
|
+
"eslint": "^8.14.0",
|
|
34
|
+
"eslint-config-prettier": "^8.5.0",
|
|
35
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
36
|
+
"mock-socket": "^9.1.3",
|
|
37
|
+
"nock": "^13.2.4",
|
|
38
|
+
"pino-pretty": "^7.6.0",
|
|
39
|
+
"prettier": "^2.6.1",
|
|
40
|
+
"ts-loader": "^9.3.1",
|
|
41
|
+
"typedoc": "^0.22.15",
|
|
42
|
+
"webpack": "^5.74.0",
|
|
43
|
+
"webpack-cli": "^4.10.0"
|
|
44
|
+
},
|
|
45
|
+
"prettier": {
|
|
46
|
+
"semi": false,
|
|
47
|
+
"singleQuote": true,
|
|
48
|
+
"printWidth": 100,
|
|
49
|
+
"endOfLine": "auto",
|
|
50
|
+
"trailingComma": "all",
|
|
51
|
+
"arrowParens": "always"
|
|
52
|
+
},
|
|
53
|
+
"optionalDependencies": {
|
|
54
|
+
"bufferutil": "^4.0.6",
|
|
55
|
+
"utf-8-validate": "^5.0.9"
|
|
56
|
+
},
|
|
57
|
+
"ava": {
|
|
58
|
+
"files": [
|
|
59
|
+
"test/**/*.test.ts"
|
|
60
|
+
],
|
|
61
|
+
"extensions": [
|
|
62
|
+
"ts"
|
|
63
|
+
],
|
|
64
|
+
"require": [
|
|
65
|
+
"ts-node/register"
|
|
66
|
+
],
|
|
67
|
+
"workerThreads": false,
|
|
68
|
+
"environmentVariables": {
|
|
69
|
+
"METRICS_ENABLED": "false"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -43,7 +43,7 @@ export interface BackgroundExecuteRateLimiter extends RateLimiter {
|
|
|
43
43
|
* @param limits - the rate limit tier set for the adapter
|
|
44
44
|
* @returns the most restrictive of the set options, in requests per second
|
|
45
45
|
*/
|
|
46
|
-
export declare const consolidateTierLimits: (limits?: AdapterRateLimitTier
|
|
46
|
+
export declare const consolidateTierLimits: (limits?: AdapterRateLimitTier) => number;
|
|
47
47
|
/**
|
|
48
48
|
* Validates rate limiting tiers specified for the adapter, and returns the one to use.
|
|
49
49
|
*
|
|
@@ -51,4 +51,4 @@ export declare const consolidateTierLimits: (limits?: AdapterRateLimitTier | und
|
|
|
51
51
|
* @param selectedTier - chosen API tier from settings, if present
|
|
52
52
|
* @returns the specified API tier, or a default one if none are specified
|
|
53
53
|
*/
|
|
54
|
-
export declare const getRateLimitingTier: (tiers?: Record<string, AdapterRateLimitTier
|
|
54
|
+
export declare const getRateLimitingTier: (tiers?: Record<string, AdapterRateLimitTier>, selectedTier?: string) => AdapterRateLimitTier | undefined;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as client from 'prom-client';
|
|
2
2
|
import { AdapterContext } from '.';
|
|
3
|
-
export declare const dataProviderMetricsLabel: (providerStatusCode?: number
|
|
3
|
+
export declare const dataProviderMetricsLabel: (providerStatusCode?: number, method?: string) => {
|
|
4
4
|
provider_status_code: number | undefined;
|
|
5
5
|
method: string;
|
|
6
6
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|