@chainlink/external-adapter-framework 0.0.46 → 0.0.56
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.d.ts +18 -1
- package/adapter.js +69 -3
- package/adapter.js.map +1 -0
- package/background-executor.js +31 -0
- package/background-executor.js.map +1 -0
- package/cache/factory.d.ts +2 -2
- package/cache/factory.js +11 -46
- package/cache/factory.js.map +1 -0
- package/cache/index.js +3 -2
- package/cache/index.js.map +1 -0
- package/cache/local.js.map +1 -0
- package/cache/metrics.js.map +1 -0
- package/cache/redis.js.map +1 -0
- package/config/index.d.ts +34 -0
- package/config/index.js +40 -62
- package/config/index.js.map +1 -0
- package/config/provider-limits.js.map +1 -0
- package/examples/bank-frick/accounts.d.ts +15 -1
- package/examples/bank-frick/accounts.js.map +1 -0
- package/examples/bank-frick/config/index.d.ts +15 -2
- package/examples/bank-frick/config/index.js.map +1 -0
- package/examples/bank-frick/index.d.ts +15 -1
- package/examples/bank-frick/index.js.map +1 -0
- package/examples/bank-frick/util.js.map +1 -0
- package/examples/coingecko/batch-warming.d.ts +7 -0
- package/examples/coingecko/batch-warming.js +54 -0
- package/examples/coingecko/batch-warming.js.map +1 -0
- package/examples/coingecko/index.d.ts +2 -0
- package/examples/coingecko/index.js +12 -0
- package/examples/coingecko/index.js.map +1 -0
- package/examples/coingecko/rest.d.ts +12 -0
- package/examples/coingecko/rest.js +55 -0
- package/examples/coingecko/rest.js.map +1 -0
- package/examples/coingecko/src/config/index.js.map +1 -0
- package/examples/coingecko/src/crypto-utils.d.ts +31 -0
- package/examples/coingecko/src/crypto-utils.js +60 -0
- package/examples/coingecko/src/crypto-utils.js.map +1 -0
- package/examples/coingecko/src/endpoint/coins.js +3 -1
- package/examples/coingecko/src/endpoint/coins.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +4 -4
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +1 -1
- package/examples/coingecko/src/endpoint/crypto-volume.js +4 -4
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -0
- package/examples/coingecko/src/endpoint/crypto.d.ts +1 -1
- package/examples/coingecko/src/endpoint/crypto.js +4 -4
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -0
- package/examples/coingecko/src/endpoint/dominance.d.ts +1 -1
- package/examples/coingecko/src/endpoint/dominance.js +4 -4
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -0
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +1 -1
- package/examples/coingecko/src/endpoint/global-marketcap.js +4 -4
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -0
- package/examples/coingecko/src/endpoint/index.js.map +1 -0
- package/examples/coingecko/src/global-utils.d.ts +27 -0
- package/examples/coingecko/src/global-utils.js +46 -0
- package/examples/coingecko/src/global-utils.js.map +1 -0
- package/examples/coingecko/src/index.d.ts +1 -1
- package/examples/coingecko/src/index.js.map +1 -0
- package/examples/coingecko-old/batch-warming.js.map +1 -0
- package/examples/coingecko-old/index.js.map +1 -0
- package/examples/coingecko-old/rest.js +4 -1
- package/examples/coingecko-old/rest.js.map +1 -0
- package/examples/genesis/config/index.d.ts +7 -0
- package/examples/genesis/config/index.js +10 -0
- package/examples/genesis/config/index.js.map +1 -0
- package/examples/genesis/index.d.ts +2 -0
- package/examples/genesis/index.js +12 -0
- package/examples/genesis/index.js.map +1 -0
- package/examples/genesis/sseStream.d.ts +16 -0
- package/examples/genesis/sseStream.js +141 -0
- package/examples/genesis/sseStream.js.map +1 -0
- package/examples/ncfx/config/index.js.map +1 -0
- package/examples/ncfx/index.js.map +1 -0
- package/examples/ncfx/websocket.js.map +1 -0
- package/index.js.map +1 -0
- package/metrics/constants.js.map +1 -0
- package/metrics/index.d.ts +2 -0
- package/metrics/index.js +12 -1
- package/metrics/index.js.map +1 -0
- package/metrics/util.js.map +1 -0
- package/package.json +7 -5
- package/rate-limiting/background/fixed-frequency.js +0 -3
- package/rate-limiting/background/fixed-frequency.js.map +1 -0
- package/rate-limiting/index.d.ts +1 -0
- package/rate-limiting/index.js +3 -2
- package/rate-limiting/index.js.map +1 -0
- package/rate-limiting/metrics.js.map +1 -0
- package/rate-limiting/request/simple-counting.js.map +1 -0
- package/transports/batch-warming.d.ts +2 -2
- package/transports/batch-warming.js +13 -6
- package/transports/batch-warming.js.map +1 -0
- package/transports/index.d.ts +2 -1
- package/transports/index.js +27 -0
- package/transports/index.js.map +1 -0
- package/transports/metrics.d.ts +3 -0
- package/transports/metrics.js +17 -1
- package/transports/metrics.js.map +1 -0
- package/transports/rest.d.ts +8 -2
- package/transports/rest.js +13 -13
- package/transports/rest.js.map +1 -0
- package/transports/sse.d.ts +41 -0
- package/transports/sse.js +95 -0
- package/transports/sse.js.map +1 -0
- package/transports/util.js.map +1 -0
- package/transports/websocket.d.ts +2 -2
- package/transports/websocket.js +12 -11
- package/transports/websocket.js.map +1 -0
- package/util/censor/censor-list.d.ts +9 -0
- package/util/censor/censor-list.js +12 -0
- package/util/censor/censor-list.js.map +1 -0
- package/util/index.d.ts +1 -0
- package/util/index.js +3 -1
- package/util/index.js.map +1 -0
- package/util/logger.d.ts +3 -0
- package/util/logger.js +20 -1
- package/util/logger.js.map +1 -0
- package/util/request.d.ts +52 -6
- package/util/request.js.map +1 -0
- package/util/subscription-set/expiring-sorted-set.d.ts +0 -1
- package/util/subscription-set/expiring-sorted-set.js +0 -12
- package/util/subscription-set/expiring-sorted-set.js.map +1 -0
- package/util/subscription-set/redis-sorted-set.d.ts +9 -0
- package/util/subscription-set/redis-sorted-set.js +28 -0
- package/util/subscription-set/redis-sorted-set.js.map +1 -0
- package/util/subscription-set/subscription-set.d.ts +5 -4
- package/util/subscription-set/subscription-set.js +13 -5
- package/util/subscription-set/subscription-set.js.map +1 -0
- package/util/test-payload-loader.js.map +1 -0
- package/validation/error.js.map +1 -0
- package/validation/index.js +10 -9
- package/validation/index.js.map +1 -0
- package/validation/input-params.d.ts +1 -1
- package/validation/input-params.js.map +1 -0
- package/validation/input-validator.d.ts +16 -0
- package/validation/input-validator.js +123 -0
- package/validation/input-validator.js.map +1 -0
- package/validation/override-functions.js.map +1 -0
package/util/request.d.ts
CHANGED
|
@@ -6,51 +6,97 @@ declare module 'fastify' {
|
|
|
6
6
|
requestContext: AdapterRequestContext;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Structure for the body of all requests that will be sent to the adapter
|
|
11
|
+
*/
|
|
9
12
|
export interface AdapterRequestBody<T = AdapterRequestData> {
|
|
13
|
+
/** Adapter endpoint (not to be confused with REST API endpoint) */
|
|
10
14
|
endpoint?: string;
|
|
15
|
+
/** Main data that will be validated and used on each adapter request */
|
|
11
16
|
data: T;
|
|
12
|
-
id?: string;
|
|
13
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Object that will be added to the request on a successful validation.
|
|
20
|
+
* Contains all the necessary information the adapter will need across the request execution.
|
|
21
|
+
*/
|
|
14
22
|
export declare type AdapterRequestContext<T = AdapterRequestData> = {
|
|
15
|
-
|
|
23
|
+
/** Name of the endpoint this payload should be directed to */
|
|
16
24
|
endpointName: string;
|
|
25
|
+
/** Precalculated cache key used to get and set corresponding values from the cache and subscription sets */
|
|
17
26
|
cacheKey: string;
|
|
27
|
+
/** Normalized and validated data coming from the request body */
|
|
18
28
|
data: T;
|
|
29
|
+
/** Metadata relevant to this particular request */
|
|
19
30
|
meta?: AdapterRequestMeta;
|
|
20
31
|
};
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Helper type to denote an empty body
|
|
34
|
+
*/
|
|
35
|
+
declare type EmptyBody = Record<string, never>;
|
|
36
|
+
/**
|
|
37
|
+
* Helper type to provide fastify for all adapter handlers
|
|
38
|
+
*/
|
|
39
|
+
export declare type AdapterRouteGeneric = {
|
|
40
|
+
/** Set to an empty record so the user does not access the raw request data and uses the Validated data from the context instead */
|
|
41
|
+
Body: EmptyBody;
|
|
23
42
|
};
|
|
24
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Structure for all requests incoming to this adapter
|
|
45
|
+
*/
|
|
46
|
+
export declare type AdapterRequest<T = AdapterRequestData> = FastifyRequest<AdapterRouteGeneric> & {
|
|
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 */
|
|
48
|
+
body: EmptyBody;
|
|
49
|
+
/** Container for all validated information that will be used by the framework across this request's lifecycle */
|
|
25
50
|
requestContext: AdapterRequestContext<T>;
|
|
26
51
|
};
|
|
27
52
|
/**
|
|
28
|
-
*
|
|
53
|
+
* Metadata for a particular request
|
|
29
54
|
*/
|
|
30
55
|
export interface AdapterRequestMeta {
|
|
56
|
+
/** Relevant metrics gathered for this request */
|
|
31
57
|
metrics?: AdapterMetricsMeta;
|
|
58
|
+
/** An error that ocurred somewhere along this requests' lifecycle */
|
|
32
59
|
error?: AdapterError | Error;
|
|
33
60
|
}
|
|
34
61
|
/**
|
|
35
62
|
* Meta info that pertains to exposing metrics
|
|
36
63
|
*/
|
|
37
64
|
export interface AdapterMetricsMeta {
|
|
65
|
+
/** String to uniquely identify a specific price feed */
|
|
38
66
|
feedId?: string;
|
|
67
|
+
/** Boolean to note if this request's response was found in the cache directly */
|
|
39
68
|
cacheHit?: boolean;
|
|
40
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Basic shape for the data within the request body
|
|
72
|
+
*/
|
|
41
73
|
export declare type AdapterRequestData = Record<string, unknown> & {
|
|
42
74
|
endpoint?: string;
|
|
43
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Helper type to hold the value from responses from a provider, and the adapter params they correspond to
|
|
78
|
+
*/
|
|
44
79
|
export interface ProviderResult<Params> {
|
|
80
|
+
/** The set of parameters that uniquely relate to the response */
|
|
45
81
|
params: Params;
|
|
82
|
+
/** */
|
|
46
83
|
value: unknown;
|
|
47
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Shape of the response body from the adapter
|
|
87
|
+
*/
|
|
48
88
|
export declare type AdapterResponse<T = unknown> = {
|
|
89
|
+
/** HTTP status code */
|
|
49
90
|
statusCode: number;
|
|
91
|
+
/** Response data, holds "result" for Flux Monitor */
|
|
50
92
|
data: T;
|
|
93
|
+
/** Result value used for OCR */
|
|
51
94
|
result: unknown;
|
|
95
|
+
/** Number detailing the maximum age of the result in the cache, will be replaced by telemetry eventually */
|
|
52
96
|
maxAge?: number;
|
|
97
|
+
/** Metadata relevant to this request */
|
|
53
98
|
meta?: AdapterRequestMeta;
|
|
54
99
|
};
|
|
55
100
|
export declare type Middleware = ((req: AdapterRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => FastifyReply | void) | ((req: AdapterRequest, reply: FastifyReply) => Promise<FastifyReply | void>);
|
|
56
101
|
export declare type AdapterMiddlewareBuilder = (adapter: Adapter) => Middleware;
|
|
102
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/util/request.ts"],"names":[],"mappings":""}
|
|
@@ -16,7 +16,6 @@ interface ExpiringSortedSetEntry<T> {
|
|
|
16
16
|
export declare class ExpiringSortedSet<T> implements SubscriptionSet<T> {
|
|
17
17
|
map: Map<string, ExpiringSortedSetEntry<T>>;
|
|
18
18
|
add(key: string, value: T, ttl: number): void;
|
|
19
|
-
get(key: string): T | undefined;
|
|
20
19
|
getAll(): T[];
|
|
21
20
|
}
|
|
22
21
|
export {};
|
|
@@ -17,18 +17,6 @@ class ExpiringSortedSet {
|
|
|
17
17
|
expirationTimestamp: Date.now() + ttl,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
get(key) {
|
|
21
|
-
const entry = this.map.get(key);
|
|
22
|
-
if (!entry) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
else if (entry.expirationTimestamp < Date.now()) {
|
|
26
|
-
return entry.value;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
this.map.delete(key);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
20
|
getAll() {
|
|
33
21
|
const results = [];
|
|
34
22
|
const now = Date.now();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiring-sorted-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/expiring-sorted-set.ts"],"names":[],"mappings":";;;AAWA;;;;;GAKG;AACH,MAAa,iBAAiB;IAA9B;QACE,QAAG,GAAG,IAAI,GAAG,EAAqC,CAAA;IAwBpD,CAAC;IAtBC,GAAG,CAAC,GAAW,EAAE,KAAQ,EAAE,GAAW;QACpC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,KAAK;YACL,mBAAmB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG;SACtC,CAAC,CAAA;IACJ,CAAC;IAED,MAAM;QACJ,MAAM,OAAO,GAAQ,EAAE,CAAA;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEtB,kDAAkD;QAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE;YAC7C,IAAI,KAAK,CAAC,mBAAmB,GAAG,GAAG,EAAE;gBACnC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA,CAAC,wDAAwD;aAC9E;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;aAC1B;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAzBD,8CAyBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Redis from 'ioredis';
|
|
2
|
+
import { SubscriptionSet } from './subscription-set';
|
|
3
|
+
export declare class RedisSubscriptionSet<T> implements SubscriptionSet<T> {
|
|
4
|
+
private redisClient;
|
|
5
|
+
private subscriptionSetKey;
|
|
6
|
+
constructor(redisClient: Redis, subscriptionSetKey: string);
|
|
7
|
+
add(key: string, value: T, ttl: number): Promise<undefined>;
|
|
8
|
+
getAll(): Promise<T[]>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisSubscriptionSet = void 0;
|
|
4
|
+
// Delimiter used to store both key and value in redis sorted set string field together
|
|
5
|
+
const DELIMITER = '>';
|
|
6
|
+
class RedisSubscriptionSet {
|
|
7
|
+
constructor(redisClient, subscriptionSetKey) {
|
|
8
|
+
this.redisClient = redisClient;
|
|
9
|
+
this.subscriptionSetKey = subscriptionSetKey;
|
|
10
|
+
}
|
|
11
|
+
async add(key, value, ttl) {
|
|
12
|
+
const storedValue = `${key}${DELIMITER}${JSON.stringify(value)}`;
|
|
13
|
+
await this.redisClient.zadd(this.subscriptionSetKey, Date.now() + ttl, storedValue);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
async getAll() {
|
|
17
|
+
// Remove expired keys from sorted set
|
|
18
|
+
await this.redisClient.zremrangebyscore(this.subscriptionSetKey, '-inf', Date.now());
|
|
19
|
+
const parsedRequests = [];
|
|
20
|
+
const validEntries = await this.redisClient.zrange(this.subscriptionSetKey, 0, -1);
|
|
21
|
+
validEntries.forEach((entry) => {
|
|
22
|
+
// Separate request and cache key prior to populating results array
|
|
23
|
+
parsedRequests.push(JSON.parse(entry.split(DELIMITER)[1]));
|
|
24
|
+
});
|
|
25
|
+
return parsedRequests;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.RedisSubscriptionSet = RedisSubscriptionSet;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-sorted-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/redis-sorted-set.ts"],"names":[],"mappings":";;;AAGA,uFAAuF;AACvF,MAAM,SAAS,GAAG,GAAG,CA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-6,13 +7,13 @@ import { AdapterConfig } from '../../config';
|
|
|
6
7
|
export interface SubscriptionSet<T> {
|
|
7
8
|
/** Add a new subscription to the set */
|
|
8
9
|
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
10
|
/** Get all subscriptions from the set as a list */
|
|
12
11
|
getAll(): PromiseOrValue<T[]>;
|
|
13
12
|
}
|
|
14
13
|
export declare class SubscriptionSetFactory {
|
|
15
14
|
private cacheType;
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
private redisClient?;
|
|
16
|
+
private adapterName?;
|
|
17
|
+
constructor(config: AdapterConfig, redisClient?: Redis, adapterName?: string);
|
|
18
|
+
buildSet<T>(endpointName: string): SubscriptionSet<T>;
|
|
18
19
|
}
|
|
@@ -2,17 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SubscriptionSetFactory = void 0;
|
|
4
4
|
const expiring_sorted_set_1 = require("./expiring-sorted-set");
|
|
5
|
+
const redis_sorted_set_1 = require("./redis-sorted-set");
|
|
5
6
|
class SubscriptionSetFactory {
|
|
6
|
-
constructor(config) {
|
|
7
|
+
constructor(config, redisClient, adapterName) {
|
|
7
8
|
this.cacheType = config.CACHE_TYPE;
|
|
9
|
+
this.redisClient = redisClient;
|
|
10
|
+
this.adapterName = adapterName;
|
|
8
11
|
}
|
|
9
|
-
buildSet() {
|
|
12
|
+
buildSet(endpointName) {
|
|
10
13
|
switch (this.cacheType) {
|
|
11
14
|
case 'local':
|
|
12
15
|
return new expiring_sorted_set_1.ExpiringSortedSet();
|
|
13
|
-
case 'redis':
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
case 'redis': {
|
|
17
|
+
if (!this.redisClient) {
|
|
18
|
+
throw new Error('Redis client undefined. Cannot create Redis subscription set');
|
|
19
|
+
}
|
|
20
|
+
// Identifier key used for the subscription set in redis
|
|
21
|
+
const subscriptionSetKey = `${this.adapterName}-${endpointName}-subscriptionSet`;
|
|
22
|
+
return new redis_sorted_set_1.RedisSubscriptionSet(this.redisClient, subscriptionSetKey);
|
|
23
|
+
}
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
26
|
}
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +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,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,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,7 +5,6 @@ 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 validator_1 = require("./validator");
|
|
9
8
|
const override_functions_1 = require("./override-functions");
|
|
10
9
|
const errorCatcherLogger = (0, util_2.makeLogger)('ErrorCatchingMiddleware');
|
|
11
10
|
const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
@@ -21,9 +20,12 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
21
20
|
statusCode: 400,
|
|
22
21
|
});
|
|
23
22
|
}
|
|
23
|
+
// We can restrict usage of the raw request body everywhere in the framework
|
|
24
|
+
// by setting its type to EmptyBody, and we cast here (and only here)
|
|
25
|
+
const requestBody = req.body;
|
|
24
26
|
// Make endpoints case insensitive
|
|
25
|
-
const endpointParam =
|
|
26
|
-
|
|
27
|
+
const endpointParam = requestBody.endpoint?.toLowerCase() ||
|
|
28
|
+
requestBody.data?.endpoint?.toLowerCase() ||
|
|
27
29
|
adapter.defaultEndpoint;
|
|
28
30
|
if (!endpointParam) {
|
|
29
31
|
throw new error_1.AdapterInputError({
|
|
@@ -38,12 +40,12 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
38
40
|
statusCode: 404,
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const validatedData = endpoint.validator
|
|
44
|
+
? endpoint.validator.validateInput(req.body?.['data'])
|
|
45
|
+
: req.body?.['data'];
|
|
43
46
|
req.requestContext = {
|
|
44
|
-
id: req.body.id || '1',
|
|
45
47
|
cacheKey: '',
|
|
46
|
-
data:
|
|
48
|
+
data: validatedData,
|
|
47
49
|
endpointName: endpoint.name,
|
|
48
50
|
};
|
|
49
51
|
if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
@@ -52,10 +54,9 @@ const validatorMiddleware = (adapter) => (req, reply, done) => {
|
|
|
52
54
|
const metrics = (0, util_1.getMetricsMeta)({
|
|
53
55
|
adapterEndpoint: endpoint,
|
|
54
56
|
adapterConfig: adapter.config,
|
|
55
|
-
},
|
|
57
|
+
}, validatedData);
|
|
56
58
|
req.requestContext = { ...req.requestContext, meta: { metrics } };
|
|
57
59
|
}
|
|
58
|
-
// TODO: Support `includes` and `tokenOverrides` overrides as needed
|
|
59
60
|
const requestParams = req.requestContext.data ?? {};
|
|
60
61
|
if (requestParams['tokenOverrides']) {
|
|
61
62
|
throw new Error('Token overrides not yet supported');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":";;;AAEA,oCAA4C;AAC5C,0CAAgD;AAChD,kCAAoC;AAEpC,mCAAyD;AACzD,6DAA6D;AAG7D,MAAM,kBAAkB,GAAG,IAAA,iBAAU,EAAC,yBAAyB,CAAC,CAAA;AAEzD,MAAM,mBAAmB,GAC9B,CAAC,OAAgB,EAAE,EAAE,CACrB,CAAC,GAAmB,EAAE,KAAmB,EAAE,IAA6B,EAAE,EAAE;IAC1E,IAAI,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,kBAAkB,EAAE;QACtD,MAAM,IAAI,yBAAiB,CAAC;YAC1B,OAAO,EAAE,oDAAoD;YAC7D,UAAU,EAAE,GAAG;SAChB,CAAC,CAAA;KACH;IAED,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;QACb,MAAM,IAAI,yBAAiB,CAAC;YAC1B,OAAO,EA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AG,CAAC,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAA;KACtE;AACH,CAAC,CAAA;AAfY,QAAA,uBAAuB,2BAenC"}
|
|
@@ -10,6 +10,6 @@ export declare type InputParameter = {
|
|
|
10
10
|
exclusive?: string[];
|
|
11
11
|
};
|
|
12
12
|
export declare type InputParameters = {
|
|
13
|
-
[name: string]: InputParameter
|
|
13
|
+
[name: string]: InputParameter;
|
|
14
14
|
};
|
|
15
15
|
export declare const baseInputParameters: InputParameters;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-params.js","sourceRoot":"","sources":["../../../src/validation/input-params.ts"],"names":[],"mappings":";;;AAiBa,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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InputParameters } from './input-params';
|
|
2
|
+
export declare type NormalizedInput = Record<string, unknown>;
|
|
3
|
+
export declare class InputValidator {
|
|
4
|
+
private readonly inputConfig;
|
|
5
|
+
private aliases;
|
|
6
|
+
constructor(inputConfig: InputParameters);
|
|
7
|
+
validateInput(input: any): NormalizedInput;
|
|
8
|
+
private initializeInputs;
|
|
9
|
+
private validateInputParamsSchema;
|
|
10
|
+
private validateRequiredConfig;
|
|
11
|
+
private validateOptions;
|
|
12
|
+
private validateTypes;
|
|
13
|
+
private validateDeps;
|
|
14
|
+
private getUsedKey;
|
|
15
|
+
private throwInvalid;
|
|
16
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InputValidator = void 0;
|
|
4
|
+
const input_params_1 = require("./input-params");
|
|
5
|
+
const error_1 = require("./error");
|
|
6
|
+
const util_1 = require("../util");
|
|
7
|
+
class InputValidator {
|
|
8
|
+
constructor(inputConfig) {
|
|
9
|
+
this.inputConfig = inputConfig;
|
|
10
|
+
this.aliases = {};
|
|
11
|
+
this.getUsedKey = (allKeys, input) => allKeys.find((k) => input && !(0, util_1.isEmpty)(input[k])) || '';
|
|
12
|
+
this.throwInvalid = (message) => {
|
|
13
|
+
throw new error_1.AdapterInputError({ statusCode: 400, message });
|
|
14
|
+
};
|
|
15
|
+
this.inputConfig = { ...input_params_1.baseInputParameters, ...inputConfig };
|
|
16
|
+
this.validateInputParamsSchema();
|
|
17
|
+
}
|
|
18
|
+
validateInput(input) {
|
|
19
|
+
const normalized = this.initializeInputs(input);
|
|
20
|
+
for (const configKey in this.inputConfig) {
|
|
21
|
+
this.validateRequiredConfig(configKey, normalized);
|
|
22
|
+
if (!(0, util_1.isEmpty)(normalized[configKey])) {
|
|
23
|
+
this.validateTypes(configKey, normalized);
|
|
24
|
+
this.validateOptions(configKey, normalized);
|
|
25
|
+
this.validateDeps(configKey, normalized);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return normalized;
|
|
29
|
+
}
|
|
30
|
+
initializeInputs(input) {
|
|
31
|
+
const normalized = {};
|
|
32
|
+
for (const paramName in this.inputConfig) {
|
|
33
|
+
const usedKey = this.getUsedKey(this.aliases[paramName], input);
|
|
34
|
+
normalized[paramName] =
|
|
35
|
+
!usedKey || (0, util_1.isEmpty)(input[usedKey]) ? this.inputConfig[paramName].default : input[usedKey];
|
|
36
|
+
}
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
validateInputParamsSchema() {
|
|
40
|
+
for (const configKey in this.inputConfig) {
|
|
41
|
+
const config = this.inputConfig[configKey];
|
|
42
|
+
if (config.required && config.default) {
|
|
43
|
+
throw new error_1.AdapterInputError({
|
|
44
|
+
statusCode: 400,
|
|
45
|
+
message: `${configKey} can't be required and have default value`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const aliases = [configKey, ...(config.aliases ?? [])];
|
|
49
|
+
if (aliases.length !== new Set(aliases).size) {
|
|
50
|
+
throw new error_1.AdapterInputError({
|
|
51
|
+
statusCode: 400,
|
|
52
|
+
message: `Duplicate aliases`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
this.aliases[configKey] = aliases;
|
|
56
|
+
const deps = [...(config.dependsOn ?? []), ...(config.exclusive ?? [])];
|
|
57
|
+
if (!deps || !deps.length) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
deps.forEach((inputDepKey) => {
|
|
61
|
+
if (!this.inputConfig[inputDepKey]) {
|
|
62
|
+
throw new error_1.AdapterInputError({
|
|
63
|
+
statusCode: 400,
|
|
64
|
+
message: `Input dependency/exclusive '${inputDepKey}' is missing in input schema`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
validateRequiredConfig(configKey, normalized) {
|
|
71
|
+
if (!this.inputConfig[configKey].required) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if ((0, util_1.isEmpty)(normalized[configKey])) {
|
|
75
|
+
this.throwInvalid(`Required parameter ${configKey} must be non-null and non-empty`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
validateOptions(key, normalized) {
|
|
79
|
+
if (!this.inputConfig[key].options?.length) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!this.inputConfig[key].options?.includes(normalized[key])) {
|
|
83
|
+
this.throwInvalid(`${key} parameter must be one of following options: ${this.inputConfig[key].options?.join(',')}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
validateTypes(key, normalized) {
|
|
87
|
+
const type = this.inputConfig[key].type;
|
|
88
|
+
if (!type) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (['array', 'object'].includes(type)) {
|
|
92
|
+
if (type === 'array' &&
|
|
93
|
+
(!Array.isArray(normalized[key]) || normalized[key].length === 0)) {
|
|
94
|
+
this.throwInvalid(`${key} parameter must be a non-empty array`);
|
|
95
|
+
}
|
|
96
|
+
if (type === 'object' &&
|
|
97
|
+
normalized[key] &&
|
|
98
|
+
(Object.getPrototypeOf(normalized[key]) !== Object.prototype ||
|
|
99
|
+
Object.keys(normalized[key]).length === 0)) {
|
|
100
|
+
this.throwInvalid(`${key} parameter must be an object with at least one property`);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
else if (typeof normalized[key] !== type) {
|
|
105
|
+
this.throwInvalid(`${key} parameter must be of type ${type}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
validateDeps(key, normalized) {
|
|
109
|
+
for (const dependency of this.inputConfig[key].dependsOn ?? []) {
|
|
110
|
+
const value = normalized[dependency];
|
|
111
|
+
if ((0, util_1.isEmpty)(value)) {
|
|
112
|
+
this.throwInvalid(`${key} dependency ${dependency} not supplied`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const exclusive of this.inputConfig[key].exclusive ?? []) {
|
|
116
|
+
const value = normalized[exclusive];
|
|
117
|
+
if (!(0, util_1.isEmpty)(value)) {
|
|
118
|
+
this.throwInvalid(`${key} cannot be supplied concurrently with ${exclusive}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.InputValidator = InputValidator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input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