@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,45 +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.recordRequests = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const recordRequests = (requestConfig, providerResponse) => {
9
- let recordedRequests = {};
10
- try {
11
- recordedRequests = JSON.parse(fs_1.default.readFileSync('capturedRequests.json').toString());
12
- }
13
- catch { } // eslint-disable-line no-empty
14
- let baseUrl = requestConfig.baseURL;
15
- baseUrl =
16
- nthIndexOf(baseUrl, '/', 3) === -1 ? baseUrl : baseUrl.slice(0, nthIndexOf(baseUrl, '/', 3));
17
- const recordedRequest = {
18
- method: requestConfig.method,
19
- path: providerResponse.request.path,
20
- data: requestConfig.data,
21
- response: providerResponse.data,
22
- statusCode: providerResponse.status,
23
- };
24
- if (!recordedRequests[baseUrl]) {
25
- recordedRequests[baseUrl] = [recordedRequest];
26
- }
27
- else if (recordedRequests[baseUrl].every((r) => {
28
- return r.path !== recordedRequest.path;
29
- })) {
30
- recordedRequests[baseUrl].push(recordedRequest);
31
- }
32
- fs_1.default.writeFileSync('capturedRequests.json', JSON.stringify(recordedRequests));
33
- };
34
- exports.recordRequests = recordRequests;
35
- const nthIndexOf = (input, match, n) => {
36
- let i = -1;
37
- let n_ = n;
38
- while (n_-- && i++ < input.length) {
39
- i = input.indexOf(match, i);
40
- if (i < 0) {
41
- break;
42
- }
43
- }
44
- return i;
45
- };
package/util/request.d.ts DELETED
@@ -1,56 +0,0 @@
1
- import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify';
2
- import { Adapter } from '../adapter';
3
- import { AdapterError } from '../validation/error';
4
- declare module 'fastify' {
5
- interface FastifyRequest {
6
- requestContext: AdapterRequestContext;
7
- }
8
- }
9
- export interface AdapterRequestBody<T = AdapterRequestData> {
10
- endpoint?: string;
11
- data: T;
12
- id?: string;
13
- }
14
- export declare type AdapterRequestContext<T = AdapterRequestData> = {
15
- id: string;
16
- endpointName: string;
17
- cacheKey: string;
18
- data: T;
19
- meta?: AdapterRequestMeta;
20
- };
21
- export declare type AdapterRouteGeneric<T = AdapterRequestData> = {
22
- Body: AdapterRequestBody<T>;
23
- };
24
- export declare type AdapterRequest<T = AdapterRequestData> = FastifyRequest<AdapterRouteGeneric<T>> & {
25
- requestContext: AdapterRequestContext<T>;
26
- };
27
- /**
28
- * Meta info that pertains to exposing metrics
29
- */
30
- export interface AdapterRequestMeta {
31
- metrics?: AdapterMetricsMeta;
32
- error?: AdapterError | Error;
33
- }
34
- /**
35
- * Meta info that pertains to exposing metrics
36
- */
37
- export interface AdapterMetricsMeta {
38
- feedId?: string;
39
- cacheHit?: boolean;
40
- }
41
- export declare type AdapterRequestData = Record<string, unknown> & {
42
- endpoint?: string;
43
- };
44
- export interface ProviderResult<Params> {
45
- params: Params;
46
- value: unknown;
47
- }
48
- export declare type AdapterResponse<T = unknown> = {
49
- statusCode: number;
50
- data: T;
51
- result: unknown;
52
- maxAge?: number;
53
- meta?: AdapterRequestMeta;
54
- };
55
- export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
56
- export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
@@ -1,22 +0,0 @@
1
- import { SubscriptionSet } from './subscription-set';
2
- /**
3
- * An object describing an entry in the expiring sorted set.
4
- * @typeParam T - the type of the entry's value
5
- */
6
- interface ExpiringSortedSetEntry<T> {
7
- value: T;
8
- expirationTimestamp: number;
9
- }
10
- /**
11
- * This class implements a set of unique items, each of which has an expiration timestamp.
12
- * On reads, items that have expired will be deleted from the set and not returned.
13
- *
14
- * @typeParam T - the type of the set entries' values
15
- */
16
- export declare class ExpiringSortedSet<T> implements SubscriptionSet<T> {
17
- map: Map<string, ExpiringSortedSetEntry<T>>;
18
- add(key: string, value: T, ttl: number): void;
19
- get(key: string): T | undefined;
20
- getAll(): T[];
21
- }
22
- export {};
@@ -1,18 +0,0 @@
1
- import { PromiseOrValue } from '..';
2
- import { AdapterConfig } from '../../config';
3
- /**
4
- * Set to hold items to subscribe to from a provider (regardless of protocol)
5
- */
6
- export interface SubscriptionSet<T> {
7
- /** Add a new subscription to the set */
8
- add(key: string, value: T, ttl: number): PromiseOrValue<void>;
9
- /** Get a specific subscription from the set */
10
- get(key: string): PromiseOrValue<T | undefined>;
11
- /** Get all subscriptions from the set as a list */
12
- getAll(): PromiseOrValue<T[]>;
13
- }
14
- export declare class SubscriptionSetFactory {
15
- private cacheType;
16
- constructor(config: AdapterConfig);
17
- buildSet<T>(): SubscriptionSet<T>;
18
- }
@@ -1,25 +0,0 @@
1
- import { AdapterRequestData } from './request';
2
- /**
3
- * The test payload read in from filesystem
4
- */
5
- export interface Payload {
6
- requests: Array<AdapterRequestData>;
7
- }
8
- /**
9
- * Test payload with discriminated union so we can tell when we should just do
10
- * a simple liveness check rather than a sample request
11
- */
12
- declare type TestPayload = (Payload & {
13
- isDefault: false;
14
- }) | {
15
- isDefault: true;
16
- };
17
- /**
18
- * Load in a JSON file containing a test payload for the current adapter,
19
- * used in healthchecks to make sample requests
20
- *
21
- * @param fileName - name of file that contains the test payload data for the smoke endpoint
22
- * @returns the parsed payload with individual requests
23
- */
24
- export declare function loadTestPayload(fileName?: string): TestPayload;
25
- export {};
@@ -1,50 +0,0 @@
1
- import { HttpRequestType } from '../metrics/constants';
2
- declare type ErrorBasic = {
3
- name: string;
4
- message: string;
5
- };
6
- declare type ErrorFull = ErrorBasic & {
7
- stack: string;
8
- cause: string;
9
- };
10
- export declare type AdapterErrorResponse = {
11
- jobRunID: string;
12
- status: string;
13
- statusCode: number;
14
- providerStatusCode?: number;
15
- error: ErrorBasic | ErrorFull;
16
- };
17
- export declare class AdapterError extends Error {
18
- jobRunID: string;
19
- status: string;
20
- statusCode: number;
21
- cause: unknown;
22
- url?: string;
23
- errorResponse: unknown;
24
- feedID?: string;
25
- providerStatusCode?: number;
26
- metricsLabel?: HttpRequestType;
27
- name: string;
28
- message: string;
29
- constructor({ jobRunID, status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
30
- toJSONResponse(): AdapterErrorResponse;
31
- }
32
- export declare class AdapterInputError extends AdapterError {
33
- constructor(input: Partial<AdapterError>);
34
- }
35
- export declare class AdapterRateLimitError extends AdapterError {
36
- constructor(input: Partial<AdapterError>);
37
- }
38
- export declare class AdapterTimeoutError extends AdapterError {
39
- constructor(input: Partial<AdapterError>);
40
- }
41
- export declare class AdapterDataProviderError extends AdapterError {
42
- constructor(input: Partial<AdapterError>);
43
- }
44
- export declare class AdapterConnectionError extends AdapterError {
45
- constructor(input: Partial<AdapterError>);
46
- }
47
- export declare class AdapterCustomError extends AdapterError {
48
- constructor(input: Partial<AdapterError>);
49
- }
50
- export {};
@@ -1,5 +0,0 @@
1
- import { FastifyReply, FastifyRequest } from 'fastify';
2
- import { AdapterMiddlewareBuilder } from '../util/request';
3
- export { InputParameters } from './input-params';
4
- export declare const validatorMiddleware: AdapterMiddlewareBuilder;
5
- export declare const errorCatchingMiddleware: (err: Error, req: FastifyRequest, res: FastifyReply) => void;
@@ -1,15 +0,0 @@
1
- export declare type Override = Map<string, Map<string, string>>;
2
- export declare type InputParameter = {
3
- aliases?: string[];
4
- description?: string;
5
- type?: 'bigint' | 'boolean' | 'array' | 'number' | 'object' | 'string';
6
- required?: boolean;
7
- options?: unknown[];
8
- default?: unknown;
9
- dependsOn?: string[];
10
- exclusive?: string[];
11
- };
12
- export declare type InputParameters = {
13
- [name: string]: InputParameter | boolean | string[];
14
- };
15
- export declare const baseInputParameters: InputParameters;
@@ -1,3 +0,0 @@
1
- import { Adapter } from '../adapter';
2
- import { AdapterRequest } from '../util/request';
3
- export declare const performSymbolOverrides: (adapter: Adapter, req: AdapterRequest) => void;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.performSymbolOverrides = void 0;
4
- const performSymbolOverrides = (adapter, req) => {
5
- let adapterOverrides = {};
6
- if (req.requestContext.data &&
7
- req.requestContext.data['overrides'] &&
8
- req.requestContext.data['overrides'][adapter.name]) {
9
- adapterOverrides = req.requestContext.data['overrides'][adapter.name];
10
- }
11
- if (!Array.isArray(req.requestContext.data['base'])) {
12
- // Perform overrides specified in the request payload
13
- req.requestContext.data['base'] =
14
- adapterOverrides[req.requestContext.data['base']] ?? req.requestContext.data['base'];
15
- // Perform hardcoded overrides
16
- if (adapter.overrides) {
17
- req.requestContext.data['base'] =
18
- adapter.overrides[req.requestContext.data['base']] ??
19
- req.requestContext.data['base'];
20
- }
21
- return;
22
- }
23
- let requestedSymbols = req.requestContext.data['base'];
24
- for (let i = 0; i < requestedSymbols.length; i++) {
25
- const symbol = requestedSymbols[i];
26
- // Perform overrides specified in the request payload
27
- let overriddenSymbol = adapterOverrides[symbol.toUpperCase()] ?? adapterOverrides[symbol.toLowerCase()];
28
- // Perform hardcoded overrides
29
- if (adapter.overrides) {
30
- overriddenSymbol =
31
- adapter.overrides[symbol.toUpperCase()] ??
32
- adapter.overrides[symbol.toLowerCase()] ??
33
- overriddenSymbol;
34
- }
35
- requestedSymbols[i] = overriddenSymbol ?? requestedSymbols[i];
36
- }
37
- requestedSymbols = requestedSymbols.length > 1 ? requestedSymbols : requestedSymbols[1];
38
- req.requestContext.data['base'] = requestedSymbols;
39
- };
40
- exports.performSymbolOverrides = performSymbolOverrides;
@@ -1,47 +0,0 @@
1
- import { AdapterError, AdapterErrorResponse } from './error';
2
- import { InputParameters, Override } from './input-params';
3
- export declare type OverrideType = 'overrides' | 'tokenOverrides' | 'includes';
4
- declare type InputType = {
5
- id?: string;
6
- data?: any;
7
- };
8
- export interface ValidatorOptions {
9
- shouldThrowError?: boolean;
10
- includes?: any[];
11
- overrides?: any;
12
- }
13
- export declare type IncludePair = {
14
- from: string;
15
- to: string;
16
- adapters?: string[];
17
- inverse?: boolean;
18
- tokens?: boolean;
19
- };
20
- export declare type Includes = {
21
- from: string;
22
- to: string;
23
- includes: IncludePair[];
24
- };
25
- export declare class Validator {
26
- input: InputType;
27
- inputConfigs: InputParameters;
28
- inputOptions: Record<string, any[]>;
29
- validatorOptions: ValidatorOptions;
30
- validated: any;
31
- error: AdapterError | undefined;
32
- errored: AdapterErrorResponse | undefined;
33
- constructor(input?: InputType, inputConfigs?: {}, inputOptions?: {}, validatorOptions?: ValidatorOptions);
34
- validateInput(): void;
35
- validateOverrides(path: 'overrides' | 'tokenOverrides', preset: Record<string, any>): void;
36
- checkDuplicateInputParams(inputConfig: InputParameters): void;
37
- validateIncludeOverrides(): void;
38
- parseError(error: unknown): void;
39
- formatOverride: (param: any) => Override;
40
- formatIncludeOverrides: (param: any) => Override;
41
- throwInvalid: (message: string) => void;
42
- validateObjectParam(key: string, shouldThrowError?: boolean): void;
43
- validateOptionalParam(param: any, key: string, options: any[]): void;
44
- validateRequiredParam(param: any, key: string, options: any[]): void;
45
- getUsedKey(key: string, keyArray: string[]): string | undefined;
46
- }
47
- export {};