@chainlink/external-adapter-framework 0.0.19 → 0.0.21

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 (77) hide show
  1. package/adapter.d.ts +139 -0
  2. package/background-executor.d.ts +9 -0
  3. package/background-executor.js +9 -4
  4. package/cache/factory.d.ts +6 -0
  5. package/cache/index.d.ts +94 -0
  6. package/cache/local.d.ts +23 -0
  7. package/cache/metrics.d.ts +27 -0
  8. package/cache/redis.d.ts +16 -0
  9. package/config/index.d.ts +258 -0
  10. package/config/provider-limits.d.ts +27 -0
  11. package/examples/bank-frick/accounts.d.ts +39 -0
  12. package/examples/bank-frick/config/index.d.ts +4 -0
  13. package/examples/bank-frick/index.d.ts +2 -0
  14. package/examples/bank-frick/util.d.ts +4 -0
  15. package/examples/coingecko/batch-warming.d.ts +7 -0
  16. package/examples/coingecko/index.d.ts +2 -0
  17. package/examples/coingecko/rest.d.ts +12 -0
  18. package/examples/coingecko/src/config/index.d.ts +2 -0
  19. package/examples/coingecko/src/config/index.js +1 -9
  20. package/examples/coingecko/src/config/overrides.json +0 -1
  21. package/examples/coingecko/src/cryptoUtils.d.ts +31 -0
  22. package/examples/coingecko/src/cryptoUtils.js +20 -1
  23. package/examples/coingecko/src/endpoint/coins.d.ts +9 -0
  24. package/examples/coingecko/src/endpoint/coins.js +3 -2
  25. package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +3 -0
  26. package/examples/coingecko/src/endpoint/crypto-marketcap.js +5 -22
  27. package/examples/coingecko/src/endpoint/crypto-volume.d.ts +3 -0
  28. package/examples/coingecko/src/endpoint/crypto-volume.js +5 -22
  29. package/examples/coingecko/src/endpoint/crypto.d.ts +3 -0
  30. package/examples/coingecko/src/endpoint/crypto.js +5 -25
  31. package/examples/coingecko/src/endpoint/dominance.d.ts +3 -0
  32. package/examples/coingecko/src/endpoint/dominance.js +4 -3
  33. package/examples/coingecko/src/endpoint/global-marketcap.d.ts +3 -0
  34. package/examples/coingecko/src/endpoint/global-marketcap.js +4 -3
  35. package/examples/coingecko/src/endpoint/index.d.ts +6 -0
  36. package/examples/coingecko/src/globalUtils.d.ts +27 -0
  37. package/examples/coingecko/src/globalUtils.js +6 -8
  38. package/examples/coingecko/src/index.d.ts +4 -0
  39. package/examples/coingecko/src/index.js +7 -3
  40. package/examples/coingecko-old/batch-warming.d.ts +7 -0
  41. package/examples/coingecko-old/index.d.ts +2 -0
  42. package/examples/coingecko-old/rest.d.ts +12 -0
  43. package/examples/ncfx/config/index.d.ts +12 -0
  44. package/examples/ncfx/index.d.ts +13 -0
  45. package/examples/ncfx/websocket.d.ts +47 -0
  46. package/index.d.ts +11 -0
  47. package/index.js +24 -7
  48. package/metrics/constants.d.ts +16 -0
  49. package/metrics/index.d.ts +15 -0
  50. package/metrics/index.js +7 -3
  51. package/metrics/util.d.ts +7 -0
  52. package/package.json +10 -4
  53. package/rate-limiting/background/fixed-frequency.d.ts +11 -0
  54. package/rate-limiting/index.d.ts +55 -0
  55. package/rate-limiting/metrics.d.ts +3 -0
  56. package/rate-limiting/request/simple-counting.d.ts +21 -0
  57. package/test.d.ts +1 -0
  58. package/transports/batch-warming.d.ts +35 -0
  59. package/transports/batch-warming.js +1 -1
  60. package/transports/index.d.ts +73 -0
  61. package/transports/index.js +3 -1
  62. package/transports/metrics.d.ts +22 -0
  63. package/transports/rest.d.ts +44 -0
  64. package/transports/util.d.ts +9 -0
  65. package/transports/websocket.d.ts +80 -0
  66. package/util/index.d.ts +12 -0
  67. package/util/logger.d.ts +42 -0
  68. package/util/request.d.ts +56 -0
  69. package/util/subscription-set/expiring-sorted-set.d.ts +22 -0
  70. package/util/subscription-set/subscription-set.d.ts +18 -0
  71. package/util/test-payload-loader.d.ts +25 -0
  72. package/validation/error.d.ts +50 -0
  73. package/validation/index.d.ts +5 -0
  74. package/validation/index.js +4 -2
  75. package/validation/input-params.d.ts +15 -0
  76. package/validation/override-functions.d.ts +3 -0
  77. package/validation/validator.d.ts +47 -0
@@ -0,0 +1,56 @@
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;
@@ -0,0 +1,22 @@
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 {};
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,25 @@
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 {};
@@ -0,0 +1,50 @@
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 {};
@@ -0,0 +1,5 @@
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;
@@ -39,7 +39,6 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
39
39
  });
40
40
  }
41
41
  // Validate data using validator from v2
42
- // TODO: See if we want to change this whole thing
43
42
  const validator = new validator_1.Validator(req.body, endpoint.inputParameters);
44
43
  req.requestContext = {
45
44
  id: req.body.id || '1',
@@ -76,7 +75,10 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
76
75
  exports.validatorMiddleware = validatorMiddleware;
77
76
  const errorCatchingMiddleware = (err, req, res) => {
78
77
  // Add adapter or generic error to request meta for metrics use
79
- req.requestContext.meta = { ...req.requestContext.meta, error: err };
78
+ // There's a chance we have no request context if there was an error during input validation
79
+ if (req.requestContext) {
80
+ req.requestContext.meta = { ...req.requestContext?.meta, error: err };
81
+ }
80
82
  if (err instanceof error_1.AdapterError) {
81
83
  // We want to log these as warn, because although they are to be expected, NOPs should
82
84
  // Only use "correct" job specs and therefore not hit adapters with invalid requests.
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,3 @@
1
+ import { Adapter } from '../adapter';
2
+ import { AdapterRequest } from '../util/request';
3
+ export declare const performSymbolOverrides: (adapter: Adapter, req: AdapterRequest) => void;
@@ -0,0 +1,47 @@
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 {};