@chainlink/external-adapter-framework 0.7.1 → 0.8.0
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/adapter/basic.d.ts +6 -50
- package/adapter/basic.js +2 -165
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +6 -6
- package/adapter/endpoint.js +0 -1
- package/adapter/endpoint.js.map +1 -1
- package/adapter/price.d.ts +8 -38
- package/adapter/price.js +1 -43
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +14 -37
- package/background-executor.js +4 -19
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +16 -9
- package/cache/index.js +46 -4
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +1 -19
- package/config/index.js +29 -54
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +25 -17
- package/examples/bank-frick/accounts.js +13 -23
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/index.d.ts +15 -1
- package/examples/bank-frick/index.js +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +4 -18
- package/examples/coingecko/src/crypto-utils.js +2 -1
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +3 -20
- package/examples/coingecko/src/endpoint/coins.js +2 -2
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto.d.ts +4 -2
- package/examples/coingecko/src/endpoint/crypto.js +2 -2
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -1
- package/examples/coingecko/src/endpoint/dominance.d.ts +2 -2
- package/examples/coingecko/src/endpoint/dominance.js +2 -2
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -1
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -1
- package/examples/coingecko/src/global-utils.d.ts +3 -18
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +7 -0
- package/examples/coingecko-old/batch-warming.js +54 -0
- package/examples/coingecko-old/batch-warming.js.map +1 -0
- package/examples/coingecko-old/index.d.ts +2 -0
- package/examples/coingecko-old/index.js +12 -0
- package/examples/coingecko-old/index.js.map +1 -0
- package/examples/coingecko-old/rest.d.ts +12 -0
- package/examples/coingecko-old/rest.js +55 -0
- package/examples/coingecko-old/rest.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +2 -14
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +1 -1
- package/examples/genesis/index.js +1 -1
- package/examples/genesis/sseStream.d.ts +2 -13
- package/examples/genesis/sseStream.js +1 -4
- package/examples/genesis/sseStream.js.map +1 -1
- package/examples/ncfx/config/index.d.ts +12 -0
- package/examples/ncfx/config/index.js +16 -0
- package/examples/ncfx/config/index.js.map +1 -0
- package/examples/ncfx/index.d.ts +13 -0
- package/examples/ncfx/index.js +12 -0
- package/examples/ncfx/index.js.map +1 -0
- package/examples/ncfx/websocket.d.ts +47 -0
- package/examples/ncfx/websocket.js +74 -0
- package/examples/ncfx/websocket.js.map +1 -0
- package/index.d.ts +0 -1
- package/index.js +6 -4
- package/index.js.map +1 -1
- package/metrics/index.d.ts +0 -2
- package/metrics/index.js +4 -5
- package/metrics/index.js.map +1 -1
- package/metrics/util.d.ts +5 -5
- package/metrics/util.js.map +1 -1
- package/package.json +9 -7
- package/rate-limiting/background/fixed-frequency.d.ts +3 -2
- package/rate-limiting/background/fixed-frequency.js.map +1 -1
- package/rate-limiting/index.d.ts +4 -4
- package/rate-limiting/index.js +1 -1
- package/rate-limiting/index.js.map +1 -1
- package/rate-limiting/request/simple-counting.d.ts +3 -2
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/transports/batch-warming.d.ts +15 -33
- package/transports/batch-warming.js +16 -43
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +31 -65
- package/transports/index.js +59 -2
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +2 -2
- package/transports/metrics.js +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +14 -31
- package/transports/rest.js +25 -17
- package/transports/rest.js.map +1 -1
- package/transports/sse.d.ts +20 -40
- package/transports/sse.js +8 -10
- package/transports/sse.js.map +1 -1
- package/transports/websocket.d.ts +25 -40
- package/transports/websocket.js +13 -10
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +0 -2
- package/util/logger.js +7 -4
- package/util/logger.js.map +1 -1
- package/util/request.d.ts +10 -46
- package/util/subscription-set/subscription-set.d.ts +1 -1
- package/util/subscription-set/subscription-set.js +1 -1
- package/util/subscription-set/subscription-set.js.map +1 -1
- package/util/test-payload-loader.d.ts +0 -1
- package/util/test-payload-loader.js +1 -2
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +3 -1
- package/validation/error.js +4 -2
- package/validation/error.js.map +1 -1
- package/validation/index.js +17 -26
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +1 -0
- package/validation/input-params.js +28 -0
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +2 -1
- package/validation/input-validator.js.map +1 -1
- package/validation/override-functions.d.ts +3 -0
- package/validation/override-functions.js +41 -0
- package/validation/override-functions.js.map +1 -0
- package/README.md +0 -67
- package/transports/routing.d.ts +0 -21
- package/transports/routing.js +0 -50
- package/transports/routing.js.map +0 -1
package/util/request.d.ts
CHANGED
|
@@ -6,9 +6,6 @@ declare module 'fastify' {
|
|
|
6
6
|
requestContext: AdapterRequestContext;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export declare type Merge<T1, T2> = {
|
|
10
|
-
[K in keyof T1 | keyof T2]: K extends keyof T2 ? T2[K] : K extends keyof T1 ? T1[K] : never;
|
|
11
|
-
};
|
|
12
9
|
/**
|
|
13
10
|
* Structure for the body of all requests that will be sent to the adapter
|
|
14
11
|
*/
|
|
@@ -46,11 +43,11 @@ export declare type AdapterRouteGeneric = {
|
|
|
46
43
|
/**
|
|
47
44
|
* Structure for all requests incoming to this adapter
|
|
48
45
|
*/
|
|
49
|
-
export declare type AdapterRequest<T
|
|
46
|
+
export declare type AdapterRequest<T = AdapterRequestData> = FastifyRequest<AdapterRouteGeneric> & {
|
|
50
47
|
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
51
48
|
body: EmptyBody;
|
|
52
49
|
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
53
|
-
requestContext: AdapterRequestContext<T
|
|
50
|
+
requestContext: AdapterRequestContext<T>;
|
|
54
51
|
};
|
|
55
52
|
/**
|
|
56
53
|
* Metadata for a particular request
|
|
@@ -77,62 +74,29 @@ export declare type AdapterRequestData = Record<string, unknown> & {
|
|
|
77
74
|
endpoint?: string;
|
|
78
75
|
};
|
|
79
76
|
/**
|
|
80
|
-
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
77
|
+
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
81
78
|
*/
|
|
82
|
-
export interface ProviderResult<
|
|
83
|
-
Request: RequestGenerics;
|
|
84
|
-
Response: ResponseGenerics;
|
|
85
|
-
}> {
|
|
79
|
+
export interface ProviderResult<Params> {
|
|
86
80
|
/** The set of parameters that uniquely relate to the response */
|
|
87
|
-
params:
|
|
88
|
-
/**
|
|
89
|
-
value:
|
|
81
|
+
params: Params;
|
|
82
|
+
/** */
|
|
83
|
+
value: unknown;
|
|
90
84
|
}
|
|
91
|
-
export declare type EmptyObject = Object;
|
|
92
|
-
/**
|
|
93
|
-
* Helper struct type that provides detail about the incoming Adapter Request
|
|
94
|
-
*/
|
|
95
|
-
export declare type RequestGenerics = {
|
|
96
|
-
/**
|
|
97
|
-
* Type for the parameters sent to the EA in the data property of the body.
|
|
98
|
-
*/
|
|
99
|
-
Params: EmptyObject;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Helper struct type that provides detail about the outgoing Adapter Response
|
|
103
|
-
*/
|
|
104
|
-
export declare type ResponseGenerics = {
|
|
105
|
-
/**
|
|
106
|
-
* Type for the data property of the response.
|
|
107
|
-
*/
|
|
108
|
-
Data: unknown;
|
|
109
|
-
/**
|
|
110
|
-
* Type for the result property of the response.
|
|
111
|
-
* This is mostly used for OCR, and corresponds to one "word" when talking about it from an on-chain perspective.
|
|
112
|
-
*/
|
|
113
|
-
Result: string | number | null;
|
|
114
|
-
};
|
|
115
85
|
/**
|
|
116
86
|
* Shape of the response body from the adapter
|
|
117
87
|
*/
|
|
118
|
-
export declare type AdapterResponse<T
|
|
88
|
+
export declare type AdapterResponse<T = unknown> = {
|
|
119
89
|
/** HTTP status code */
|
|
120
90
|
statusCode: number;
|
|
121
91
|
/** Response data, holds "result" for Flux Monitor */
|
|
122
|
-
data: T
|
|
92
|
+
data: T;
|
|
123
93
|
/** Result value used for OCR */
|
|
124
|
-
result:
|
|
94
|
+
result: unknown;
|
|
125
95
|
/** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
|
|
126
96
|
maxAge?: number;
|
|
127
97
|
/** Metadata relevant to this request */
|
|
128
98
|
meta?: AdapterRequestMeta;
|
|
129
99
|
};
|
|
130
|
-
export declare type SingleNumberResultResponse = {
|
|
131
|
-
Result: number;
|
|
132
|
-
Data: {
|
|
133
|
-
result: number;
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
100
|
export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
137
101
|
export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
|
|
138
102
|
export {};
|
|
@@ -14,6 +14,6 @@ export declare class SubscriptionSetFactory {
|
|
|
14
14
|
private cacheType;
|
|
15
15
|
private redisClient?;
|
|
16
16
|
private adapterName?;
|
|
17
|
-
constructor(config: AdapterConfig,
|
|
17
|
+
constructor(config: AdapterConfig, redisClient?: Redis, adapterName?: string);
|
|
18
18
|
buildSet<T>(endpointName: string): SubscriptionSet<T>;
|
|
19
19
|
}
|
|
@@ -4,7 +4,7 @@ exports.SubscriptionSetFactory = void 0;
|
|
|
4
4
|
const expiring_sorted_set_1 = require("./expiring-sorted-set");
|
|
5
5
|
const redis_sorted_set_1 = require("./redis-sorted-set");
|
|
6
6
|
class SubscriptionSetFactory {
|
|
7
|
-
constructor(config,
|
|
7
|
+
constructor(config, redisClient, adapterName) {
|
|
8
8
|
this.cacheType = config.CACHE_TYPE;
|
|
9
9
|
this.redisClient = redisClient;
|
|
10
10
|
this.adapterName = adapterName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,WAAoB;QAC1E,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,QAAQ,CAAI,YAAoB;QAC9B,QAAQ,IAAI,CAAC,SAAS,EAAE;YACtB,KAAK,OAAO;gBACV,OAAO,IAAI,uCAAiB,EAAK,CAAA;YACnC,KAAK,OAAO,CAAC,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBACrB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;iBAChF;gBACD,wDAAwD;gBACxD,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,YAAY,kBAAkB,CAAA;gBAChF,OAAO,IAAI,uCAAoB,CAAI,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF;AAzBD,wDAyBC"}
|
|
@@ -22,5 +22,4 @@ declare type TestPayload = (Payload & {
|
|
|
22
22
|
* @returns the parsed payload with individual requests
|
|
23
23
|
*/
|
|
24
24
|
export declare function loadTestPayload(fileName?: string): TestPayload;
|
|
25
|
-
export declare function resolvePayload(fileName?: string): Payload | null;
|
|
26
25
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.loadTestPayload = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -81,5 +81,4 @@ function resolvePayload(fileName) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
exports.resolvePayload = resolvePayload;
|
|
85
84
|
//# sourceMappingURL=test-payload-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-payload-loader.js","sourceRoot":"","sources":["../../../src/util/test-payload-loader.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,4CAAmB;AACnB,gDAAuB;AACvB,qCAAqC;AAGrC,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,mBAAmB,CAAC,CAAA;AAe9C;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,QAAiB;IAC/C,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC;QACtB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,EAAE;iBACb;aACF;SACF;KACF,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI;QACF,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE;YAC5C,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,4CAA4C,CAAC,CAAC,CAAA;SAC9F;QACD,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;KACxC;IAAC,OAAO,CAAU,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,2BAA4B,CAAW,CAAC,OAAO,EAAE,CAAC,CAAA;QAC9D,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;QACpD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;KAC3B;AACH,CAAC;AA3BD,0CA2BC;AAED,
|
|
1
|
+
{"version":3,"file":"test-payload-loader.js","sourceRoot":"","sources":["../../../src/util/test-payload-loader.ts"],"names":[],"mappings":";;;;;;AA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CAAC"}
|
package/validation/error.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ declare type ErrorFull = ErrorBasic & {
|
|
|
8
8
|
cause: string;
|
|
9
9
|
};
|
|
10
10
|
export declare type AdapterErrorResponse = {
|
|
11
|
+
jobRunID: string;
|
|
11
12
|
status: string;
|
|
12
13
|
statusCode: number;
|
|
13
14
|
providerStatusCode?: number;
|
|
14
15
|
error: ErrorBasic | ErrorFull;
|
|
15
16
|
};
|
|
16
17
|
export declare class AdapterError extends Error {
|
|
18
|
+
jobRunID: string;
|
|
17
19
|
status: string;
|
|
18
20
|
statusCode: number;
|
|
19
21
|
cause: unknown;
|
|
@@ -24,7 +26,7 @@ export declare class AdapterError extends Error {
|
|
|
24
26
|
metricsLabel?: HttpRequestType;
|
|
25
27
|
name: string;
|
|
26
28
|
message: string;
|
|
27
|
-
constructor({ status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
29
|
+
constructor({ jobRunID, status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
28
30
|
toJSONResponse(): AdapterErrorResponse;
|
|
29
31
|
}
|
|
30
32
|
export declare class AdapterInputError extends AdapterError {
|
package/validation/error.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AdapterCustomError = exports.AdapterConnectionError = exports.AdapterDataProviderError = exports.AdapterTimeoutError = exports.AdapterRateLimitError = exports.AdapterInputError = exports.AdapterError = void 0;
|
|
4
4
|
const constants_1 = require("../metrics/constants");
|
|
5
5
|
class AdapterError extends Error {
|
|
6
|
-
constructor({ status = 'errored', statusCode = 500, name = 'AdapterError', message = '
|
|
6
|
+
constructor({ jobRunID = '1', status = 'errored', statusCode = 500, name = 'AdapterError', message = 'An error occurred.', cause, url, errorResponse, feedID, providerStatusCode, metricsLabel = constants_1.HttpRequestType.ADAPTER_ERROR, }) {
|
|
7
7
|
super(message);
|
|
8
|
+
this.jobRunID = jobRunID;
|
|
8
9
|
this.status = status;
|
|
9
10
|
this.statusCode = statusCode;
|
|
10
11
|
this.name = name;
|
|
@@ -21,7 +22,7 @@ class AdapterError extends Error {
|
|
|
21
22
|
this.metricsLabel = metricsLabel;
|
|
22
23
|
}
|
|
23
24
|
toJSONResponse() {
|
|
24
|
-
const showDebugInfo = process.env['DEBUG'] === 'true';
|
|
25
|
+
const showDebugInfo = process.env['NODE_ENV'] === 'development' || process.env['DEBUG'] === 'true';
|
|
25
26
|
const errorBasic = {
|
|
26
27
|
name: this.name,
|
|
27
28
|
message: this.message,
|
|
@@ -31,6 +32,7 @@ class AdapterError extends Error {
|
|
|
31
32
|
};
|
|
32
33
|
const errorFull = { ...errorBasic, stack: this.stack, cause: this.cause };
|
|
33
34
|
return {
|
|
35
|
+
jobRunID: this.jobRunID,
|
|
34
36
|
status: this.status,
|
|
35
37
|
statusCode: this.statusCode,
|
|
36
38
|
providerStatusCode: this.providerStatusCode,
|
package/validation/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/validation/error.ts"],"names":[],"mappings":";;;AAAA,oDAAsD;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/validation/error.ts"],"names":[],"mappings":";;;AAAA,oDAAsD;AAmBtD,MAAa,YAAa,SAAQ,KAAK;IAcrC,YAAY,EACV,QAAQ,GAAG,GAAG,EACd,MAAM,GAAG,SAAS,EAClB,UAAU,GAAG,GAAG,EAChB,IAAI,GAAG,cAAc,EACrB,OAAO,GAAG,oBAAoB,EAC9B,KAAK,EACL,GAAG,EACH,aAAa,EACb,MAAM,EACN,kBAAkB,EAClB,YAAY,GAAG,2BAAe,CAAC,aAAa,GACtB;QACtB,KAAK,CAAC,OAAO,CAAC,CAAA;QAEd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,MAAM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EC;AAED,MAAa,iBAAkB,SAAQ,YAAY;IACjD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,WAAW,EAAE,CAAC,CAAA;IAChE,CAAC;CACF;AAJD,8CAIC;AACD,MAAa,qBAAsB,SAAQ,YAAY;IACrD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACrE,CAAC;CACF;AAJD,sDAIC;AACD,MAAa,mBAAoB,SAAQ,YAAY;IACnD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,aAAa,EAAE,CAAC,CAAA;IAClE,CAAC;CACF;AAJD,kDAIC;AACD,MAAa,wBAAyB,SAAQ,YAAY;IACxD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC7D,CAAC;CACF;AAJD,4DAIC;AACD,MAAa,sBAAuB,SAAQ,YAAY;IACtD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,gBAAgB,EAAE,CAAC,CAAA;IACrE,CAAC;CACF;AAJD,wDAIC;AACD,MAAa,kBAAmB,SAAQ,YAAY;IAClD,YAAY,KAA4B;QACtC,KAAK,CAAC,EAAE,GAAG,KAAK,EAAE,YAAY,EAAE,2BAAe,CAAC,YAAY,EAAE,CAAC,CAAA;IACjE,CAAC;CACF;AAJD,gDAIC"}
|
package/validation/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const cache_1 = require("../cache");
|
|
|
5
5
|
const util_1 = require("../metrics/util");
|
|
6
6
|
const util_2 = require("../util");
|
|
7
7
|
const error_1 = require("./error");
|
|
8
|
+
const override_functions_1 = require("./override-functions");
|
|
8
9
|
const errorCatcherLogger = (0, util_2.makeLogger)('ErrorCatchingMiddleware');
|
|
9
10
|
const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
10
11
|
if (req.headers['content-type'] !== 'application/json') {
|
|
@@ -39,7 +40,7 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
39
40
|
statusCode: 404,
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
|
-
const validatedData = endpoint.validator.validateInput(
|
|
43
|
+
const validatedData = endpoint.validator.validateInput(req.body?.['data']);
|
|
43
44
|
req.requestContext = {
|
|
44
45
|
cacheKey: '',
|
|
45
46
|
data: validatedData,
|
|
@@ -54,25 +55,20 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
54
55
|
}, validatedData);
|
|
55
56
|
req.requestContext = { ...req.requestContext, meta: { metrics } };
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// Now that all the transformations have been applied, all that's left is calculating the cache key
|
|
61
|
-
if (endpoint.cacheKeyGenerator) {
|
|
62
|
-
let cacheKey;
|
|
63
|
-
cacheKey = endpoint.cacheKeyGenerator(req.requestContext.data);
|
|
64
|
-
if (cacheKey.length > adapter.config.MAX_COMMON_KEY_SIZE) {
|
|
65
|
-
errorCatcherLogger.warn(`Generated custom cache key for adapter request is bigger than the MAX_COMMON_KEY_SIZE and will be truncated`);
|
|
66
|
-
cacheKey = cacheKey.slice(0, adapter.config.MAX_COMMON_KEY_SIZE);
|
|
67
|
-
}
|
|
68
|
-
req.requestContext.cacheKey = cacheKey;
|
|
58
|
+
const requestParams = req.requestContext.data ?? {};
|
|
59
|
+
if (requestParams['tokenOverrides']) {
|
|
60
|
+
throw new Error('Token overrides not yet supported');
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
adapterEndpoint: endpoint,
|
|
73
|
-
adapterConfig: adapter.config,
|
|
74
|
-
}, req.requestContext.data);
|
|
62
|
+
if (requestParams['includes']) {
|
|
63
|
+
throw new Error('Includes not yet supported');
|
|
75
64
|
}
|
|
65
|
+
// Swaps the 'base' parameter if any overrides are found in the request or the adapter configuration
|
|
66
|
+
// Supports 'base' input as string or string[]
|
|
67
|
+
(0, override_functions_1.performSymbolOverrides)(adapter, req);
|
|
68
|
+
req.requestContext.cacheKey = (0, cache_1.calculateCacheKey)({
|
|
69
|
+
adapterEndpoint: endpoint,
|
|
70
|
+
adapterConfig: adapter.config,
|
|
71
|
+
}, req.requestContext.data);
|
|
76
72
|
done();
|
|
77
73
|
};
|
|
78
74
|
exports.validatorMiddleware = validatorMiddleware;
|
|
@@ -82,20 +78,15 @@ const errorCatchingMiddleware = (err, req, res) => {
|
|
|
82
78
|
if (req.requestContext) {
|
|
83
79
|
req.requestContext.meta = { ...req.requestContext?.meta, error: err };
|
|
84
80
|
}
|
|
85
|
-
// Add the request context to the error so that we can check things like incoming params, endpoint, etc
|
|
86
|
-
const errorWithContext = {
|
|
87
|
-
requestContext: req.requestContext,
|
|
88
|
-
...err,
|
|
89
|
-
};
|
|
90
81
|
if (err instanceof error_1.AdapterError) {
|
|
91
82
|
// We want to log these as warn, because although they are to be expected, NOPs should
|
|
92
83
|
// Only use "correct" job specs and therefore not hit adapters with invalid requests.
|
|
93
|
-
errorCatcherLogger.warn(
|
|
84
|
+
errorCatcherLogger.warn(err);
|
|
94
85
|
res.status(err.statusCode).send(err.toJSONResponse());
|
|
95
86
|
}
|
|
96
87
|
else {
|
|
97
|
-
errorCatcherLogger.error(
|
|
98
|
-
res.status(
|
|
88
|
+
errorCatcherLogger.error(err);
|
|
89
|
+
res.status(200).send('There was an unexpected error in the adapter.');
|
|
99
90
|
}
|
|
100
91
|
};
|
|
101
92
|
exports.errorCatchingMiddleware = errorCatchingMiddleware;
|
package/validation/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":";;;AAEA,oCAA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CAAA;AACR,CAAC,CAAA;AAlFU,QAAA,mBAAmB,uBAkF7B;AAEI,MAAM,uBAAuB,GAAG,CAAC,GAAU,EAAE,GAAmB,EAAE,GAAiB,EAAE,EAAE;IAC5F,+DAA+D;IAC/D,4FAA4F;IAC5F,IAAI,GAAG,CAAC,cAAc,EAAE;QACtB,GAAG,CAAC,cAAc,CAAC,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;KACtE;IACD,IAAI,GAAG,YAAY,oBAAY,EAAE;QAC/B,sFAAsF;QACtF,qFAAqF;QACrF,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,CAAA;KACtD;SAAM;QACL,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC7B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAA;KACtE;AACH,CAAC,CAAA;AAfY,QAAA,uBAAuB,2BAenC"}
|
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseInputParameters = void 0;
|
|
4
|
+
exports.baseInputParameters = {
|
|
5
|
+
endpoint: {
|
|
6
|
+
description: 'The External Adapter "endpoint" name to use.',
|
|
7
|
+
required: false,
|
|
8
|
+
type: 'string',
|
|
9
|
+
},
|
|
10
|
+
resultPath: {
|
|
11
|
+
description: 'The path to key into the API response the retrieve the result',
|
|
12
|
+
required: false,
|
|
13
|
+
// Type: 'string', TODO: Once multiple types are supported this could be string or array of strings
|
|
14
|
+
},
|
|
15
|
+
overrides: {
|
|
16
|
+
description: 'Override the mapping of token symbols to another token symbol',
|
|
17
|
+
required: false,
|
|
18
|
+
// Type: 'string', TODO: Once complex types are supported this could be { [adapter: string]: { [token: string]: string } }
|
|
19
|
+
},
|
|
20
|
+
tokenOverrides: {
|
|
21
|
+
description: 'Override the mapping of token symbols to smart contract address',
|
|
22
|
+
required: false,
|
|
23
|
+
// Type: 'string', TODO: Once complex types are supported this could be { [network: string]: { [token: string]: string } }
|
|
24
|
+
},
|
|
25
|
+
includes: {
|
|
26
|
+
description: 'Override the array of includes that holds additional input parameters when matching a pair of symbols',
|
|
27
|
+
required: false,
|
|
28
|
+
// Type: 'string', TODO: Once complex types are supported this could be { from: string, to: string, includes: [{ from: string, to: string, adapters: string[], inverse: boolean, tokens: boolean }] } }[]
|
|
29
|
+
},
|
|
30
|
+
};
|
|
3
31
|
//# sourceMappingURL=input-params.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-params.js","sourceRoot":"","sources":["../../../src/validation/input-params.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"input-params.js","sourceRoot":"","sources":["../../../src/validation/input-params.ts"],"names":[],"mappings":";;;AAkBa,QAAA,mBAAmB,GAAoB;IAClD,QAAQ,EAAE;QACR,WAAW,EAAE,8CAA8C;QAC3D,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,QAAQ;KACf;IACD,UAAU,EAAE;QACV,WAAW,EAAE,+DAA+D;QAC5E,QAAQ,EAAE,KAAK;QACf,mGAAmG;KACpG;IACD,SAAS,EAAE;QACT,WAAW,EAAE,+DAA+D;QAC5E,QAAQ,EAAE,KAAK;QACf,0HAA0H;KAC3H;IACD,cAAc,EAAE;QACd,WAAW,EAAE,iEAAiE;QAC9E,QAAQ,EAAE,KAAK;QACf,0HAA0H;KAC3H;IACD,QAAQ,EAAE;QACR,WAAW,EACT,uGAAuG;QACzG,QAAQ,EAAE,KAAK;QACf,yMAAyM;KAC1M;CACF,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InputValidator = void 0;
|
|
4
|
+
const input_params_1 = require("./input-params");
|
|
4
5
|
const error_1 = require("./error");
|
|
5
6
|
const util_1 = require("../util");
|
|
6
7
|
class InputValidator {
|
|
@@ -11,7 +12,7 @@ class InputValidator {
|
|
|
11
12
|
this.throwInvalid = (message) => {
|
|
12
13
|
throw new error_1.AdapterInputError({ statusCode: 400, message });
|
|
13
14
|
};
|
|
14
|
-
this.inputConfig = { ...inputConfig };
|
|
15
|
+
this.inputConfig = { ...input_params_1.baseInputParameters, ...inputConfig };
|
|
15
16
|
this.validateInputParamsSchema();
|
|
16
17
|
}
|
|
17
18
|
validateInput(input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-validator.js","sourceRoot":"","sources":["../../../src/validation/input-validator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"input-validator.js","sourceRoot":"","sources":["../../../src/validation/input-validator.ts"],"names":[],"mappings":";;;AAAA,iDAAqE;AACrE,mCAA2C;AAC3C,kCAAiC;AAIjC,MAAa,cAAc;IAEzB,YAA6B,WAA4B;QAA5B,gBAAW,GAAX,WAAW,CAAiB;QADjD,YAAO,GAAgC,EAAE,CAAA;QAqIzC,eAAU,GAAG,CAAC,OAAiB,EAAE,KAA8B,EAAU,EAAE,CACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QAEhD,iBAAY,GAAG,CAAC,OAAe,EAAQ,EAAE;YAC/C,MAAM,IAAI,yBAAiB,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;QAC3D,CAAC,CAAA;QAxIC,IAAI,CAAC,WAAW,GAAG,EAAE,GAAG,kCAAmB,EAAE,GAAG,WAAW,EAAE,CAAA;QAC7D,IAAI,CAAC,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AyD,CAAC,CAAA;aACnF;YACD,OAAM;SACP;aAAM,IAAI,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YAC1C,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,8BAA8B,IAAI,EAAE,CAAC,CAAA;SAC9D;IACH,CAAC;IAEO,YAAY,CAAC,GAAW,EAAE,UAA2B;QAC3D,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE;YAC9D,MAAM,KAAK,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;YACpC,IAAI,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;gBAClB,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,eAAe,UAAU,eAAe,CAAC,CAAA;aAClE;SACF;QAED,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,EAAE;YAC7D,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;YACnC,IAAI,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;gBACnB,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,yCAAyC,SAAS,EAAE,CAAC,CAAA;aAC9E;SACF;IACH,CAAC;CAQF;AA5ID,wCA4IC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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;
|
|
41
|
+
//# sourceMappingURL=override-functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"override-functions.js","sourceRoot":"","sources":["../../../src/validation/override-functions.ts"],"names":[],"mappings":";;;AAKO,MAAM,sBAAsB,GAAG,CAAC,OAAgB,EAAE,GAAmB,EAAE,EAAE;IAC9E,IAAI,gBAAgB,GAAG,EAA4B,CAAA;IACnD,IACE,GAAG,CAAC,cAAc,CAAC,IA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AC9B,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,gBAAgB;gBACd,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;oBACvC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;oBACvC,gBAAgB,CAAA;SACnB;QACD,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAA;KAC9D;IACD,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;IACvF,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAA;AACpD,CAAC,CAAA;AAtCY,QAAA,sBAAsB,0BAsClC"}
|
package/README.md
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# EA Framework v3
|
|
2
|
-
|
|
3
|
-
> **Warning**
|
|
4
|
-
> This framework is in a Beta state, and under active development. While many of the features from version 2 are present, they have not been tested extensively enough to mark this as production ready. You can find v2 in the [External Adapters Monorepo](https://github.com/smartcontractkit/external-adapters-js)
|
|
5
|
-
|
|
6
|
-
Framework to create External adapters, microservices that serve as middleware to facilitate connections between Chainlink Nodes and Data Providers (DP).
|
|
7
|
-
|
|
8
|
-
## Requirements
|
|
9
|
-
|
|
10
|
-
- Node.js 16+
|
|
11
|
-
- Yarn
|
|
12
|
-
|
|
13
|
-
### Optional development tools
|
|
14
|
-
|
|
15
|
-
If available, consider setting up your development environment with:
|
|
16
|
-
|
|
17
|
-
- ESLint
|
|
18
|
-
- Prettier
|
|
19
|
-
|
|
20
|
-
Note that both of the above are not necessary, but PRs submitted to the repo will be blocked from merging unless they comply with the linting and formatting rules.
|
|
21
|
-
|
|
22
|
-
## Setup
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
yarn # Install yarn dependencies
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Guides & Docs
|
|
29
|
-
|
|
30
|
-
- [Basics](./docs/basics.md)
|
|
31
|
-
- Porting a v2 EA to v3
|
|
32
|
-
- Creating a new v3 EA
|
|
33
|
-
- Transports
|
|
34
|
-
- Basic
|
|
35
|
-
- REST
|
|
36
|
-
- WebSocket
|
|
37
|
-
- SSE
|
|
38
|
-
- Meta
|
|
39
|
-
- Routing
|
|
40
|
-
|
|
41
|
-
## Testing
|
|
42
|
-
|
|
43
|
-
The EA framework is tested by a suite of integration tests located [here](./test).
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
yarn test
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Publishing releases
|
|
50
|
-
|
|
51
|
-
### Automatic
|
|
52
|
-
|
|
53
|
-
The normal flow for publishing a release is through a series o GitHub actions that are triggered when a PR is closed by merging with the base branch. Full details about our workflows can be found in [./.github/WORKFLOW-README.MD]. A summary of our publish workflow follows:
|
|
54
|
-
|
|
55
|
-
1. Close a PR containing your changes
|
|
56
|
-
2. If the PR was merged and if it contains a version label instruction (patch, minor, major, none), a new PR will be created that contains the result of running `npm version LABEL` on master with the original PR author assigned as a reviewer.
|
|
57
|
-
3. A link to the newly created version bump PR will be added to your original PR. Click on that link, and approve it to be merged.
|
|
58
|
-
4. Close the version bump PR. If merged, the package will be published to npm.
|
|
59
|
-
5. When the publish workflow finishes, a comment will be added to the version bump PR that tells you if it ran successfully
|
|
60
|
-
|
|
61
|
-
This adds an extra step (approving a version bump PR) that has to be taken every time a PR is merged. This is annoying, but it is an effective workaround for permissions issues when running against protected branches, and eliminates the need for the PR author to manually update their branch's version by referring to master.
|
|
62
|
-
|
|
63
|
-
### Manual
|
|
64
|
-
|
|
65
|
-
If you need to publish a release manually, you can do so by running `yarn release` at the project root
|
|
66
|
-
|
|
67
|
-
This runs a script that publishes the package from dist/src. If you publish from the root directory, imports will be in the form of: `import {something} from "@chainlink/external-adapter-framework/src/some_directory"`. By publishing the package from dist/src, the "src" part of the import path gets dropped, which looks cleaner: `import {something} from "@chainlink/external-adapter-framework/some_directory"`.
|
package/transports/routing.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AdapterDependencies } from '../adapter';
|
|
2
|
-
import { AdapterConfig } from '../config';
|
|
3
|
-
import { AdapterRequest, AdapterResponse } from '../util/request';
|
|
4
|
-
import { MetaTransport, Transport, TransportGenerics } from './';
|
|
5
|
-
/**
|
|
6
|
-
* Transport implementation that takes 2 or more transports and a function that determines with transport to use.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[TransportGenerics]])
|
|
9
|
-
*/
|
|
10
|
-
export declare class RoutingTransport<T extends TransportGenerics> implements MetaTransport<T> {
|
|
11
|
-
transports: {
|
|
12
|
-
[key: string]: Transport<T>;
|
|
13
|
-
};
|
|
14
|
-
private route;
|
|
15
|
-
constructor(transports: {
|
|
16
|
-
[key: string]: Transport<T>;
|
|
17
|
-
}, route: (req: AdapterRequest<T['Request']>, adapterConfig?: AdapterConfig<T['CustomSettings']>) => string);
|
|
18
|
-
initialize(dependencies: AdapterDependencies, adapterConfig: AdapterConfig<T['CustomSettings']>, endpointName: string): Promise<void>;
|
|
19
|
-
private resolveTransport;
|
|
20
|
-
foregroundExecute(req: AdapterRequest<T['Request']>, adapterConfig: AdapterConfig<T['CustomSettings']>): Promise<AdapterResponse<any> | void>;
|
|
21
|
-
}
|
package/transports/routing.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RoutingTransport = void 0;
|
|
4
|
-
const util_1 = require("../util");
|
|
5
|
-
const error_1 = require("../validation/error");
|
|
6
|
-
const logger = (0, util_1.makeLogger)('RoutingTransport');
|
|
7
|
-
/**
|
|
8
|
-
* Transport implementation that takes 2 or more transports and a function that determines with transport to use.
|
|
9
|
-
*
|
|
10
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[TransportGenerics]])
|
|
11
|
-
*/
|
|
12
|
-
class RoutingTransport {
|
|
13
|
-
constructor(
|
|
14
|
-
// This is public for tests, which sometimes need the underlying transport for things like ticking the clock
|
|
15
|
-
transports,
|
|
16
|
-
// Route should return to a string key that corresponds to a transport in the transports object
|
|
17
|
-
route) {
|
|
18
|
-
this.transports = transports;
|
|
19
|
-
this.route = route;
|
|
20
|
-
}
|
|
21
|
-
async initialize(dependencies, adapterConfig, endpointName) {
|
|
22
|
-
logger.debug(`Initializing ${Object.keys(this.transports).length} transports`);
|
|
23
|
-
Object.entries(this.transports).forEach(([k, v]) => {
|
|
24
|
-
logger.debug(`Initializing transport ${k} (${v.constructor.name})`);
|
|
25
|
-
v.initialize(dependencies, adapterConfig, endpointName);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
resolveTransport(req, adapterConfig) {
|
|
29
|
-
logger.debug(`routing request using`, req.params);
|
|
30
|
-
const key = this.route(req, adapterConfig || undefined);
|
|
31
|
-
if (!this.transports[key]) {
|
|
32
|
-
throw new error_1.AdapterError({ statusCode: 400, message: `No transport found for ${key}` });
|
|
33
|
-
}
|
|
34
|
-
const transport = this.transports[key];
|
|
35
|
-
logger.debug(`Found ${transport.constructor.name} corresponding to ${key}`);
|
|
36
|
-
return transport;
|
|
37
|
-
}
|
|
38
|
-
// Allow AdapterResponse<any> below since we don't know what the adapter will return
|
|
39
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
40
|
-
async foregroundExecute(req, adapterConfig) {
|
|
41
|
-
const transport = this.resolveTransport(req, adapterConfig);
|
|
42
|
-
if (transport.foregroundExecute) {
|
|
43
|
-
logger.debug(`Running foregroundExecute on retrieved transport`);
|
|
44
|
-
return transport.foregroundExecute(req, adapterConfig);
|
|
45
|
-
}
|
|
46
|
-
logger.debug(`Retrieved transport doesn't implement foregroundExecute`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.RoutingTransport = RoutingTransport;
|
|
50
|
-
//# sourceMappingURL=routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../../../src/transports/routing.ts"],"names":[],"mappings":";;;AAEA,kCAAoC;AAEpC,+CAAkD;AAGlD,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,kBAAkB,CAAC,CAAA;AAE7C;;;;GAIG;AACH,MAAa,gBAAgB;IAI3B;IACE,6GAA6G;IACtG,UAA2C;IAElD,+FAA+F;IACvF,KAGG;QANJ,eAAU,GAAV,UAAU,CAAiC;QAG1C,UAAK,GAAL,KAAK,CAGF;IACV,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,aAAiD,EACjD,YAAoB;QAEpB,MAAM,CAAC,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,aAAa,CAAC,CAAA;QAC9E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;YACjD,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,CAAA;YACnE,CAAC,CAAC,UAAU,CAAC,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,gBAAgB,CACtB,GAAiC,EACjC,aAAkD;QAElD,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,aAAa,IAAI,SAAS,CAAC,CAAA;QACvD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACzB,MAAM,IAAI,oBA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