@chainlink/external-adapter-framework 0.0.22 → 0.0.25

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.
Files changed (78) hide show
  1. package/cache/factory.js +27 -0
  2. package/cache/index.js +16 -1
  3. package/cache/local.js +26 -0
  4. package/cache/redis.js +45 -0
  5. package/package.json +2 -2
  6. package/transports/batch-warming.js +36 -0
  7. package/transports/rest.js +32 -0
  8. package/transports/util.js +33 -0
  9. package/transports/websocket.js +31 -0
  10. package/adapter.d.ts +0 -139
  11. package/background-executor.d.ts +0 -9
  12. package/cache/factory.d.ts +0 -6
  13. package/cache/index.d.ts +0 -94
  14. package/cache/local.d.ts +0 -23
  15. package/cache/metrics.d.ts +0 -27
  16. package/cache/redis.d.ts +0 -16
  17. package/config/index.d.ts +0 -258
  18. package/config/provider-limits.d.ts +0 -27
  19. package/examples/bank-frick/accounts.d.ts +0 -39
  20. package/examples/bank-frick/config/index.d.ts +0 -4
  21. package/examples/bank-frick/index.d.ts +0 -2
  22. package/examples/bank-frick/util.d.ts +0 -4
  23. package/examples/coingecko/batch-warming.d.ts +0 -7
  24. package/examples/coingecko/batch-warming.js +0 -53
  25. package/examples/coingecko/index.d.ts +0 -2
  26. package/examples/coingecko/index.js +0 -11
  27. package/examples/coingecko/rest.d.ts +0 -12
  28. package/examples/coingecko/rest.js +0 -51
  29. package/examples/coingecko/src/config/index.d.ts +0 -2
  30. package/examples/coingecko/src/cryptoUtils.d.ts +0 -31
  31. package/examples/coingecko/src/endpoint/coins.d.ts +0 -9
  32. package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +0 -3
  33. package/examples/coingecko/src/endpoint/crypto-volume.d.ts +0 -3
  34. package/examples/coingecko/src/endpoint/crypto.d.ts +0 -3
  35. package/examples/coingecko/src/endpoint/dominance.d.ts +0 -3
  36. package/examples/coingecko/src/endpoint/global-marketcap.d.ts +0 -3
  37. package/examples/coingecko/src/endpoint/index.d.ts +0 -6
  38. package/examples/coingecko/src/globalUtils.d.ts +0 -27
  39. package/examples/coingecko/src/index.d.ts +0 -4
  40. package/examples/coingecko/test/e2e/adapter.test.js +0 -262
  41. package/examples/coingecko/test/integration/adapter.test.js +0 -264
  42. package/examples/coingecko/test/integration/capturedRequests.json +0 -1
  43. package/examples/coingecko/test/integration/fixtures.js +0 -41
  44. package/examples/coingecko-old/batch-warming.d.ts +0 -7
  45. package/examples/coingecko-old/index.d.ts +0 -2
  46. package/examples/coingecko-old/rest.d.ts +0 -12
  47. package/examples/ncfx/config/index.d.ts +0 -12
  48. package/examples/ncfx/index.d.ts +0 -13
  49. package/examples/ncfx/websocket.d.ts +0 -47
  50. package/index.d.ts +0 -11
  51. package/metrics/constants.d.ts +0 -16
  52. package/metrics/index.d.ts +0 -15
  53. package/metrics/util.d.ts +0 -7
  54. package/rate-limiting/background/fixed-frequency.d.ts +0 -11
  55. package/rate-limiting/index.d.ts +0 -55
  56. package/rate-limiting/metrics.d.ts +0 -3
  57. package/rate-limiting/request/simple-counting.d.ts +0 -21
  58. package/test.d.ts +0 -1
  59. package/test.js +0 -6
  60. package/transports/batch-warming.d.ts +0 -35
  61. package/transports/index.d.ts +0 -73
  62. package/transports/metrics.d.ts +0 -22
  63. package/transports/rest.d.ts +0 -44
  64. package/transports/util.d.ts +0 -9
  65. package/transports/websocket.d.ts +0 -80
  66. package/util/index.d.ts +0 -12
  67. package/util/logger.d.ts +0 -42
  68. package/util/recordRequests.js +0 -45
  69. package/util/request.d.ts +0 -56
  70. package/util/subscription-set/expiring-sorted-set.d.ts +0 -22
  71. package/util/subscription-set/subscription-set.d.ts +0 -18
  72. package/util/test-payload-loader.d.ts +0 -25
  73. package/validation/error.d.ts +0 -50
  74. package/validation/index.d.ts +0 -5
  75. package/validation/input-params.d.ts +0 -15
  76. package/validation/override-functions.d.ts +0 -3
  77. package/validation/overrideFunctions.js +0 -40
  78. package/validation/validator.d.ts +0 -47
@@ -1,41 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createMocks = void 0;
7
- const nock_1 = __importDefault(require("nock"));
8
- const capturedRequests_json_1 = __importDefault(require("./capturedRequests.json"));
9
- // This is a generic fixture file that can be copy-pasted to generate fixtures from a
10
- // capturedRequests.json file. To generate a capturedRequests.json file,
11
- // set env var RECORD=true and run e2e tests.
12
- const createMocks = () => {
13
- const mocks = [];
14
- for (const baseUrl in capturedRequests_json_1.default) {
15
- const mock = (0, nock_1.default)(baseUrl, { encodedQueryParams: true });
16
- for (const request of capturedRequests_json_1.default[baseUrl]) {
17
- if (request.method === 'GET') {
18
- mock
19
- .get((uri) => {
20
- const deconstructedRequestUrl = uri.split(/[?=,&]+/);
21
- const deconstructedMockUrl = request.path.split(/[?=,&]+/);
22
- return (deconstructedRequestUrl.sort().join(',') === deconstructedMockUrl.sort().join(','));
23
- })
24
- .times(100)
25
- .reply(request.statusCode, () => request.response, [
26
- 'Content-Type',
27
- 'application/json',
28
- 'Connection',
29
- 'close',
30
- 'Vary',
31
- 'Accept-Encoding',
32
- 'Vary',
33
- 'Origin',
34
- ]);
35
- }
36
- }
37
- mocks.push(mock);
38
- }
39
- return mocks;
40
- };
41
- exports.createMocks = createMocks;
@@ -1,7 +0,0 @@
1
- import { AdapterEndpoint } from '../../adapter';
2
- interface AdapterRequestParams {
3
- base: string;
4
- quote: string;
5
- }
6
- export declare const batchEndpoint: AdapterEndpoint<AdapterRequestParams, unknown, import("../../config").SettingsMap>;
7
- export {};
@@ -1,2 +0,0 @@
1
- import { Adapter } from '../../adapter';
2
- export declare const adapter: Adapter<import("../../config").SettingsMap>;
@@ -1,12 +0,0 @@
1
- import { AdapterEndpoint } from '../../adapter';
2
- interface AdapterRequestParams {
3
- base: string;
4
- quote: string;
5
- }
6
- interface ProviderResponseBody {
7
- [base: string]: {
8
- [quote: string]: number;
9
- };
10
- }
11
- export declare const restEndpoint: AdapterEndpoint<AdapterRequestParams, ProviderResponseBody, import("../../config").SettingsMap>;
12
- export {};
@@ -1,12 +0,0 @@
1
- export declare const customSettings: {
2
- readonly USERNAME: {
3
- readonly description: "Username for the NCFX API";
4
- readonly type: "string";
5
- readonly required: true;
6
- };
7
- readonly PASSWORD: {
8
- readonly description: "Password for the NCFX API";
9
- readonly type: "string";
10
- readonly required: true;
11
- };
12
- };
@@ -1,13 +0,0 @@
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,47 +0,0 @@
1
- import { AdapterEndpoint } from '../../adapter';
2
- import { WebSocketTransport } from '../../transports/websocket';
3
- import { InputParameters } from '../../validation';
4
- interface AdapterRequestParams {
5
- base: string;
6
- quote: string;
7
- }
8
- export declare const inputParameters: InputParameters;
9
- interface ProviderMessage {
10
- timestamp: string;
11
- currencyPair: string;
12
- bid: number;
13
- offer: number;
14
- mid: number;
15
- changes: [
16
- {
17
- period: string;
18
- change: number;
19
- percentage: number;
20
- }
21
- ];
22
- }
23
- export declare const websocketTransport: WebSocketTransport<AdapterRequestParams, ProviderMessage[], {
24
- readonly USERNAME: {
25
- readonly description: "Username for the NCFX API";
26
- readonly type: "string";
27
- readonly required: true;
28
- };
29
- readonly PASSWORD: {
30
- readonly description: "Password for the NCFX API";
31
- readonly type: "string";
32
- readonly required: true;
33
- };
34
- }>;
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
- }>;
47
- export {};
package/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { FastifyInstance } from 'fastify';
2
- import { Adapter, AdapterDependencies } from './adapter';
3
- /**
4
- * Main function for the framework.
5
- * Initializes config and dependencies, uses those to initialize Transports, and starts listening for requests.
6
- *
7
- * @param adapter - an object describing an External Adapter
8
- * @param dependencies - an optional object with adapter dependencies to inject
9
- * @returns a Promise that resolves to the http.Server listening for connections
10
- */
11
- export declare const expose: (adapter: Adapter, dependencies?: Partial<AdapterDependencies>) => Promise<FastifyInstance | undefined>;
@@ -1,16 +0,0 @@
1
- export declare enum HttpRequestType {
2
- CACHE_HIT = "cacheHit",
3
- DATA_PROVIDER_HIT = "dataProviderHit",
4
- ADAPTER_ERROR = "adapterError",
5
- INPUT_ERROR = "inputError",
6
- RATE_LIMIT_ERROR = "rateLimitError",
7
- DP_ERROR = "dataProviderError",
8
- TIMEOUT_ERROR = "timeoutError",
9
- CONNECTION_ERROR = "connectionError",
10
- CUSTOM_ERROR = "customError"
11
- }
12
- /**
13
- * Maxiumum number of characters that a feedId can contain.
14
- */
15
- export declare const MAX_FEED_ID_LENGTH = 300;
16
- export declare const requestDurationBuckets: number[];
@@ -1,15 +0,0 @@
1
- import * as client from 'prom-client';
2
- import { AdapterRequest } from '../util';
3
- import { AdapterConfig } from '../config';
4
- import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
5
- export declare function setupMetricsServer(name: string, config: AdapterConfig): void;
6
- export declare const setupMetrics: (name: string, config: AdapterConfig) => void;
7
- /**
8
- * Builds metrics middleware that records end to end EA response times
9
- * and count of requests
10
- *
11
- * @returns the cache middleware function
12
- */
13
- export declare const buildMetricsMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;
14
- export declare const httpRequestsTotal: client.Counter<"type" | "method" | "status_code" | "retry" | "is_cache_warming" | "feed_id" | "provider_status_code">;
15
- export declare const httpRequestDurationSeconds: client.Histogram<string>;
package/metrics/util.d.ts DELETED
@@ -1,7 +0,0 @@
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;
@@ -1,11 +0,0 @@
1
- import { AdapterRateLimitTier, BackgroundExecuteRateLimiter } from '..';
2
- import { AdapterEndpoint } from '../../adapter';
3
- import { SettingsMap } from '../../config';
4
- export declare const DEFAULT_SHARED_MS_BETWEEN_REQUESTS = 5000;
5
- export declare class FixedFrequencyRateLimiter implements BackgroundExecuteRateLimiter {
6
- msBetweenRequestsMap: {
7
- [endpointName: string]: number;
8
- };
9
- initialize<Params, Result, CustomSettings extends SettingsMap>(endpoints: AdapterEndpoint<Params, Result, CustomSettings>[], limits?: AdapterRateLimitTier): this;
10
- msUntilNextExecution(endpointName: string): number;
11
- }
@@ -1,55 +0,0 @@
1
- import { AdapterEndpoint } from '../adapter';
2
- import { AdapterConfig, SettingsMap } from '../config';
3
- export * from './request/simple-counting';
4
- export * from './background/fixed-frequency';
5
- export interface AdapterRateLimitTier {
6
- rateLimit1s?: number;
7
- rateLimit1m?: number;
8
- rateLimit1h?: number;
9
- note?: string;
10
- }
11
- /**
12
- * Common interface for all RateLimiter classes to implement
13
- */
14
- export interface RateLimiter {
15
- /**
16
- * Method to ensure all RateLimiters can be initialized in the same manner.
17
- *
18
- * @param limits - settings for how much throughput to allow for the Adapter
19
- * @param endpoints - list of adapter endpoints
20
- */
21
- initialize<Params, Result, CustomSettings extends SettingsMap>(endpoints: AdapterEndpoint<Params, Result, CustomSettings>[], limits: AdapterRateLimitTier): this;
22
- }
23
- /**
24
- * RequestRateLimiters perform checks agains imminent outbound requests for any transport.
25
- */
26
- export interface RequestRateLimiter extends RateLimiter {
27
- /**
28
- * This method will check using whatever strategy is implemented to determine if
29
- * this request can be processed. If so, it returns true; if not, returns false.
30
- */
31
- isUnderLimits(): boolean;
32
- }
33
- /**
34
- * BackgroundExecuteFrequencyRateLimiters will implement custom logic to calculate
35
- * the period of time to wait between background executions for a transport.
36
- */
37
- export interface BackgroundExecuteRateLimiter extends RateLimiter {
38
- msUntilNextExecution(endpointName: string): number;
39
- }
40
- /**
41
- * This method will convert all possible settings for a rate limit tier and
42
- * convert them all to requests per second, returning the lowest one
43
- *
44
- * @param limits - the rate limit tier set for the adapter
45
- * @returns the most restrictive of the set options, in requests per second
46
- */
47
- export declare const consolidateTierLimits: (limits?: AdapterRateLimitTier) => number;
48
- /**
49
- * Validates rate limiting tiers specified for the adapter, and returns the one to use.
50
- *
51
- * @param config - the adapter config containing the env vars
52
- * @param tiers - the adapter config listing the different available API tiers
53
- * @returns the specified API tier, or a default one if none are specified
54
- */
55
- export declare const getRateLimitingTier: (config: AdapterConfig, tiers?: Record<string, AdapterRateLimitTier>) => AdapterRateLimitTier | undefined;
@@ -1,3 +0,0 @@
1
- import * as client from 'prom-client';
2
- export declare const retrieveCost: <ProviderResponseBody>(data: ProviderResponseBody) => number;
3
- export declare const rateLimitCreditsSpentTotal: client.Counter<"feed_id" | "participant_id">;
@@ -1,21 +0,0 @@
1
- import { AdapterRateLimitTier, RateLimiter } from '..';
2
- import { AdapterEndpoint } from '../../adapter';
3
- import { SettingsMap } from '../../config';
4
- /**
5
- * This rate limiter is the simplest stateful option.
6
- * On startup, it'll compare the different thresholds for each tier, calculate them all
7
- * in the finest window we'll use (seconds), and use the most restrictive one.
8
- * This is so if the EA were to restart, we don't need to worry about persisting state
9
- * for things like daily quotas. The downside is that this does not work well for bursty
10
- * loads or spikes, in cases where e.g. the per second limit is high but daily quotas low.
11
- */
12
- export declare class SimpleCountingRateLimiter implements RateLimiter {
13
- latestSecondInterval: number;
14
- requestsThisSecond: number;
15
- latestMinuteInterval: number;
16
- requestsThisMinute: number;
17
- perSecondLimit: number;
18
- perMinuteLimit: number;
19
- initialize<Params, Result, CustomSettings extends SettingsMap>(endpoints: AdapterEndpoint<Params, Result, CustomSettings>[], limits?: AdapterRateLimitTier): this;
20
- isUnderLimits(): boolean;
21
- }
package/test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/test.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- const src_1 = require("./examples/coingecko/src");
5
- // Start sample adapter
6
- (0, _1.expose)(src_1.adapter);
@@ -1,35 +0,0 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { Cache } from '../cache';
3
- import { AdapterConfig, SettingsMap } from '../config';
4
- import { BackgroundExecuteRateLimiter } from '../rate-limiting';
5
- import { SubscriptionSet } from '../util';
6
- import { AdapterRequest, ProviderResult } from '../util/request';
7
- import { Transport } from './';
8
- import { AdapterContext, AdapterDependencies } from '../adapter';
9
- /**
10
- * Transport implementation that takes incoming batches requests and keeps a warm cache of values.
11
- * Within the setup function, adapter params are added to an set that also keeps track and expires values.
12
- * In the background execute, the list of non-expired items in the set is fetched.
13
- * Then, the list is passed through the `prepareRequest` function, that returns an AxiosRequestConfig.
14
- * The Data Provider response is, they are passed through the `parseResponse` function to create a [[CacheEntry]] list.
15
- * Finally, the items in that [[CacheEntry]] list are set in the Cache so the Adapter can fetch values from there.
16
- *
17
- * @typeParam AdapterParams - interface for the adapter request body
18
- * @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
19
- * @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
20
- */
21
- export declare class BatchWarmingTransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
22
- private config;
23
- cache: Cache;
24
- rateLimiter: BackgroundExecuteRateLimiter;
25
- subscriptionSet: SubscriptionSet<AdapterParams>;
26
- WARMER_ACTIVE: boolean;
27
- constructor(config: {
28
- prepareRequest: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
29
- parseResponse: (params: AdapterParams[], res: AxiosResponse<ProviderResponseBody>, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[];
30
- });
31
- initialize(dependencies: AdapterDependencies): Promise<void>;
32
- hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
33
- setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
34
- backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
35
- }
@@ -1,73 +0,0 @@
1
- import { FastifyReply } from 'fastify';
2
- import { AdapterContext, AdapterDependencies, Adapter } from '../adapter';
3
- import { CacheEntry } from '../cache';
4
- import { AdapterConfig, SettingsMap } from '../config';
5
- import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
6
- export * from './batch-warming';
7
- export * from './rest';
8
- export * from './websocket';
9
- /**
10
- * Generic interface for a Transport.
11
- * A Transport defines the way in which an AdapterEndpoint will process incoming requests to
12
- * fetch data from a Data Provider. The setup phase will take care of the former, while the
13
- * backgroundExecute will be in charge of the latter.
14
- * This separation gives us the ability of splitting these concerns, and optionally parallelizing
15
- * the reading and writing of data to a centralized Cache.
16
- *
17
- * @typeParam Params - the structure of the AdapterRequest's body
18
- * @typeParam Result - the structure of the AdapterResponse's body
19
- */
20
- export interface Transport<Params, Result, CustomSettings extends SettingsMap> {
21
- /**
22
- * Initializes the transport in the Adapter context.
23
- *
24
- * @param dependencies - Adapter dependencies (e.g. cache instance)
25
- * @param config - Adapter config containing env vars
26
- * @returns an empty Promise
27
- */
28
- initialize: (dependencies: AdapterDependencies, config: AdapterConfig) => Promise<void>;
29
- /**
30
- * Checks if the Transport has already set up the incoming request.
31
- * This will likely use the cacheKey generated in the provided request.
32
- *
33
- * @param req - the incoming AdapterRequest
34
- * @returns a Promise that returns true if setup is in place
35
- */
36
- hasBeenSetUp: (req: AdapterRequest<Params>) => Promise<boolean>;
37
- /**
38
- * Sets up the incoming request within the Transport.
39
- * In other words, it means that the Adapter has recognized this request, and will begin
40
- * fetching the necessary data from a Data Provider.
41
- *
42
- * @param req - the incoming AdapterRequest
43
- * @param config - common configuration for the Adapter as a whole
44
- * @returns a Promise that _optionally_ returns an AdapterResponse, if the Transport has the capability of
45
- * immediately fetching data and returning it without the background process.
46
- */
47
- setup: (req: AdapterRequest<Params>, config: AdapterConfig<CustomSettings>) => Promise<AdapterResponse<Result> | void>;
48
- /**
49
- * If the Transport relies on an async mechanism, implementing this function will make it
50
- * so the background task executor calls it on Adapter startup.
51
- *
52
- * @param context - background context for the execution (e.g. endpoint name)
53
- */
54
- backgroundExecute?: (context: AdapterContext<CustomSettings>) => Promise<number>;
55
- }
56
- /**
57
- * Helper method to build cache entries to set after getting a bunch of responses from a DP.
58
- *
59
- * @param results - a list of results coming from a DataProvider
60
- * @param context - context for the Adapter
61
- * @returns a list of CacheEntries of AdapterResponses
62
- */
63
- export declare const buildCacheEntriesFromResults: <Params, CustomSettings extends SettingsMap>(results: ProviderResult<Params>[], context: AdapterContext<CustomSettings>) => CacheEntry<AdapterResponse<{
64
- result: unknown;
65
- }>>[];
66
- /**
67
- * Takes an Adapter, its configuration, and its dependencies, and it creates an express middleware
68
- * that will pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
69
- *
70
- * @param adapter - main adapter object, already initialized
71
- * @returns the transport handler middleware function
72
- */
73
- export declare const buildTransportHandler: (adapter: Adapter) => (req: AdapterRequest, reply: FastifyReply) => Promise<never>;
@@ -1,22 +0,0 @@
1
- import * as client from 'prom-client';
2
- import { AdapterContext } from '../adapter';
3
- import { SettingsMap } from '../config';
4
- export declare const dataProviderMetricsLabel: (providerStatusCode?: number, method?: string) => {
5
- provider_status_code: number | undefined;
6
- method: string;
7
- };
8
- export declare const dataProviderRequests: client.Counter<"method" | "provider_status_code">;
9
- export declare const dataProviderRequestDurationSeconds: client.Histogram<string>;
10
- export declare const connectionErrorLabels: (message: string) => {
11
- message: string;
12
- };
13
- export declare const messageSubsLabels: (feed_id: string, cache_key: string) => {
14
- feed_id: string;
15
- subscription_key: string;
16
- };
17
- export declare const recordWsMessageMetrics: <AdapterParams, CustomSettings extends SettingsMap>(context: AdapterContext<CustomSettings>, subscribes: AdapterParams[], unsubscrices: AdapterParams[]) => void;
18
- export declare const wsConnectionActive: client.Gauge<"url">;
19
- export declare const wsConnectionErrors: client.Counter<"message" | "url">;
20
- export declare const wsSubscriptionActive: client.Gauge<"feed_id" | "connection_url" | "subscription_key">;
21
- export declare const wsSubscriptionTotal: client.Counter<"feed_id" | "connection_url" | "subscription_key">;
22
- export declare const wsMessageTotal: client.Counter<"feed_id" | "subscription_key">;
@@ -1,44 +0,0 @@
1
- import { AdapterRequest, AdapterResponse } from '../util/request';
2
- import { Transport } from './';
3
- import { Cache } from '../cache';
4
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
5
- import { AdapterConfig, SettingsMap } from '../config';
6
- import { RequestRateLimiter } from '../rate-limiting';
7
- import { AdapterDependencies } from '../adapter';
8
- /**
9
- * Transport implementation that takes incoming requests, transforms them into a DataProvider request,
10
- * and executes that request returning the response immediately from the `setup` function.
11
- * Optionally, setting the `coalescing` option to `true` will make it so once a request is in flight,
12
- * new adapter requests for the same feed will not trigger a new one, but return an empty promise from
13
- * the setup instead so the normal cache polling mechanism is used.
14
- *
15
- * @typeParam AdapterParams - interface for the adapter request body
16
- * @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
17
- * @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
18
- */
19
- export declare class RestTransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
20
- protected config: {
21
- prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
22
- parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
23
- options: {
24
- coalescing: boolean;
25
- };
26
- };
27
- inFlightPrefix: string;
28
- cache: Cache;
29
- rateLimiter: RequestRateLimiter;
30
- constructor(config: {
31
- prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
32
- parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
33
- options: {
34
- coalescing: boolean;
35
- };
36
- });
37
- initialize(dependencies: AdapterDependencies, config: AdapterConfig): Promise<void>;
38
- hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
39
- protected waitUntilUnderRateLimit(options: {
40
- maxRetries: number;
41
- msBetweenRetries: number;
42
- }, retry?: number): Promise<void>;
43
- setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<AdapterResponse<ProviderResponseBody> | undefined>;
44
- }
@@ -1,9 +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
- * @returns axios response for the request
8
- */
9
- export declare function axiosRequest<ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap>(request: AxiosRequestConfig<ProviderRequestBody>, config: AdapterConfig<CustomSettings>): Promise<AxiosResponse<ProviderResponseBody>>;
@@ -1,80 +0,0 @@
1
- import WebSocket from 'ws';
2
- import { AdapterContext, AdapterDependencies } from '../adapter';
3
- import { Cache } from '../cache';
4
- import { AdapterConfig, SettingsMap } from '../config';
5
- import { BackgroundExecuteRateLimiter } from '../rate-limiting';
6
- import { SubscriptionSet } from '../util';
7
- import { AdapterRequest, ProviderResult } from '../util/request';
8
- import { Transport } from './';
9
- declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined) => WebSocket;
10
- export declare class WebSocketClassProvider {
11
- static ctor: WebSocketClass;
12
- static set(ctor: WebSocketClass): void;
13
- static get(): WebSocketClass;
14
- }
15
- /**
16
- * Config object that is provided to the WebSocketTransport constructor.
17
- */
18
- export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> {
19
- /** Endpoint to which to open the WS connection*/
20
- url: string;
21
- /** Map of handlers for different WS lifecycle events */
22
- handlers: {
23
- /**
24
- * Handles when the WS is successfully opened
25
- *
26
- * @param wsConnection - the WebSocket with an established connection
27
- * @returns an empty Promise, or void
28
- */
29
- open: (wsConnection: WebSocket, context: AdapterContext<CustomSettings>) => Promise<void> | void;
30
- /**
31
- * Handles when the WS receives a message
32
- *
33
- * @param message - the message received by the WS
34
- * @param context - the background context for the Adapter
35
- * @returns a list of cache entries of adapter responses to set in the cache
36
- */
37
- message: (message: ProviderDataMessage, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[];
38
- };
39
- /** Map of "builders", functions that will be used to prepare specific WS messages */
40
- builders: {
41
- /**
42
- * Builds a WS message that will be sent to subscribe to a specific feed
43
- *
44
- * @param params - the body of the adapter request
45
- * @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
46
- */
47
- subscribeMessage: (params: AdapterParams) => unknown;
48
- /**
49
- * Builds a WS message that will be sent to unsubscribe to a specific feed
50
- *
51
- * @param params - the body of the adapter request
52
- * @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
53
- */
54
- unsubscribeMessage: (params: AdapterParams) => unknown;
55
- };
56
- }
57
- /**
58
- * Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
59
- * through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
60
- *
61
- * @typeParam AdapterParams - interface for the adapter request body
62
- * @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
63
- */
64
- export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams, null, CustomSettings> {
65
- private config;
66
- cache: Cache;
67
- rateLimiter: BackgroundExecuteRateLimiter;
68
- subscriptionSet: SubscriptionSet<AdapterParams>;
69
- localSubscriptions: AdapterParams[];
70
- wsConnection: WebSocket;
71
- constructor(config: WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings>);
72
- initialize(dependencies: AdapterDependencies): Promise<void>;
73
- hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
74
- setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
75
- serializeMessage(payload: unknown): string;
76
- deserializeMessage(data: WebSocket.Data): ProviderDataMessage;
77
- establishWsConnection(context: AdapterContext<CustomSettings>): Promise<unknown>;
78
- backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
79
- }
80
- export {};
package/util/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export * from './request';
2
- export * from './logger';
3
- export * from './subscription-set/subscription-set';
4
- /**
5
- * Sleeps for the provided number of milliseconds
6
- * @param ms - The number of milliseconds to sleep for
7
- * @returns a Promise that resolves once the specified time passes
8
- */
9
- export declare const sleep: (ms: number) => Promise<void>;
10
- export declare const isObject: (o: unknown) => boolean;
11
- export declare const isArray: (o: unknown) => boolean;
12
- export declare type PromiseOrValue<T> = Promise<T> | T;
package/util/logger.d.ts DELETED
@@ -1,42 +0,0 @@
1
- /// <reference types="node" />
2
- import pino from 'pino';
3
- import { AdapterRequest } from './request';
4
- import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
5
- import { AsyncLocalStorage } from 'node:async_hooks';
6
- export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
7
- export declare type Store = {
8
- correlationId: string;
9
- };
10
- /**
11
- * Instead of using a global logger instance, we want to force using a child logger
12
- * with a specific layer set in it, so that we can filter logs by where they're output from.
13
- *
14
- * Details on what each log level represents:
15
- * "trace": Forensic debugging of issues on a local machine.
16
- * "debug": Detailed logging level to get more context from users on their environments.
17
- * "info": High-level informational messages, to describe at a glance the high level state of the system.
18
- * "warn": A mild error occurred that might require non-urgent action.
19
- * "error": An unexpected error occurred during the regular operation of a well-maintained EA.
20
- * "fatal": The EA encountered an unrecoverable problem and had to exit.
21
- *
22
- * Full reference this is based on can be found at
23
- * https://github.com/smartcontractkit/documentation/blob/main/docs/Node%20Operators/configuration-variables.md#log_level
24
- *
25
- * @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
26
- * @returns a layer specific logger
27
- */
28
- export declare const makeLogger: (layer: string) => pino.Logger<{
29
- level: string;
30
- mixin(): {};
31
- transport: {
32
- target: string;
33
- options: {
34
- levelFirst: boolean;
35
- levelLabel: string;
36
- ignore: string;
37
- messageFormat: string;
38
- translateTime: string;
39
- };
40
- } | undefined;
41
- } & pino.ChildLoggerOptions>;
42
- export declare const loggingContextMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;