@chainlink/external-adapter-framework 0.0.111 → 0.2.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 +37 -3
- package/adapter/basic.js +138 -2
- package/adapter/basic.js.map +1 -1
- package/adapter/price.d.ts +33 -5
- package/adapter/price.js +41 -2
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +18 -1
- package/cache/index.d.ts +3 -10
- package/cache/index.js +4 -46
- package/cache/index.js.map +1 -1
- package/cache/redis.d.ts +1 -8
- package/cache/redis.js +22 -39
- package/cache/redis.js.map +1 -1
- package/config/index.d.ts +6 -1
- package/config/index.js +20 -12
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +2 -3
- package/examples/bank-frick/accounts.js +1 -4
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/config/index.d.ts +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +5 -5
- package/examples/coingecko/src/crypto-utils.js +1 -2
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +1 -1
- 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 +1 -1
- 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 +1 -4
- 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 +1 -1
- 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 +1 -1
- 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 -3
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.d.ts +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +1 -1
- package/examples/coingecko-old/batch-warming.js +2 -2
- package/examples/coingecko-old/batch-warming.js.map +1 -1
- package/examples/coingecko-old/rest.js.map +1 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +1 -1
- package/examples/cryptocompare/src/index.d.ts +1 -1
- package/examples/genesis/sseStream.d.ts +2 -2
- package/examples/genesis/sseStream.js +15 -8
- package/examples/genesis/sseStream.js.map +1 -1
- package/examples/ncfx/websocket.d.ts +1 -1
- package/index.d.ts +3 -1
- package/index.js +4 -6
- package/index.js.map +1 -1
- package/metrics/index.d.ts +2 -0
- package/metrics/index.js +5 -4
- package/metrics/index.js.map +1 -1
- package/package.json +4 -7
- package/rate-limiting/index.d.ts +2 -2
- package/transports/batch-warming.d.ts +9 -9
- package/transports/batch-warming.js +40 -13
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +23 -26
- package/transports/index.js +2 -59
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +1 -1
- package/transports/rest.d.ts +5 -4
- package/transports/rest.js +16 -22
- package/transports/rest.js.map +1 -1
- package/transports/sse.d.ts +6 -7
- package/transports/sse.js +2 -6
- package/transports/sse.js.map +1 -1
- package/transports/websocket.d.ts +6 -7
- package/transports/websocket.js +5 -9
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +4 -0
- package/util/logger.js +45 -4
- package/util/logger.js.map +1 -1
- 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 +1 -0
- package/util/test-payload-loader.js +2 -1
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +1 -3
- package/validation/error.js +1 -3
- package/validation/error.js.map +1 -1
- package/validation/index.js +12 -14
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +0 -1
- package/validation/input-params.js +0 -28
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +1 -2
- package/validation/input-validator.js.map +1 -1
- package/adapter.d.ts +0 -156
- package/adapter.js +0 -200
- package/adapter.js.map +0 -1
- package/examples/coingecko/batch-warming.d.ts +0 -7
- package/examples/coingecko/batch-warming.js +0 -54
- package/examples/coingecko/batch-warming.js.map +0 -1
- package/examples/coingecko/index.d.ts +0 -2
- package/examples/coingecko/index.js +0 -12
- package/examples/coingecko/index.js.map +0 -1
- package/examples/coingecko/rest.d.ts +0 -12
- package/examples/coingecko/rest.js +0 -55
- package/examples/coingecko/rest.js.map +0 -1
- package/examples/coingecko/src/cryptoUtils.d.ts +0 -31
- package/examples/coingecko/src/cryptoUtils.js +0 -60
- package/examples/coingecko/src/globalUtils.d.ts +0 -27
- package/examples/coingecko/src/globalUtils.js +0 -46
- package/validation/override-functions.d.ts +0 -3
- package/validation/override-functions.js +0 -41
- package/validation/override-functions.js.map +0 -1
- package/validation/preset-tokens.json +0 -23
- package/validation/validator.d.ts +0 -47
- package/validation/validator.js +0 -303
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.restEndpoint = void 0;
|
|
4
|
-
const adapter_1 = require("../../adapter");
|
|
5
|
-
const transports_1 = require("../../transports");
|
|
6
|
-
const DEFAULT_URL = 'https://api.coingecko.com/api/v3';
|
|
7
|
-
const inputParameters = {
|
|
8
|
-
coinid: {
|
|
9
|
-
description: 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
|
|
10
|
-
required: false,
|
|
11
|
-
},
|
|
12
|
-
base: {
|
|
13
|
-
aliases: ['from', 'coin'],
|
|
14
|
-
description: 'The symbol or array of symbols of the currency to query',
|
|
15
|
-
required: true,
|
|
16
|
-
},
|
|
17
|
-
quote: {
|
|
18
|
-
aliases: ['to', 'market'],
|
|
19
|
-
description: 'The symbol of the currency to convert to',
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const restEndpointTransport = new transports_1.RestTransport({
|
|
24
|
-
prepareRequest: (req) => {
|
|
25
|
-
return {
|
|
26
|
-
baseURL: DEFAULT_URL,
|
|
27
|
-
url: '/simple/price',
|
|
28
|
-
method: 'GET',
|
|
29
|
-
params: {
|
|
30
|
-
ids: req.requestContext.data.base,
|
|
31
|
-
vs_currencies: req.requestContext.data.quote,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
parseResponse: (req, res) => {
|
|
36
|
-
return {
|
|
37
|
-
data: res.data,
|
|
38
|
-
statusCode: 200,
|
|
39
|
-
result: res.data[req.requestContext.data.base]?.[req.requestContext.data.quote],
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
options: {
|
|
43
|
-
requestCoalescing: {
|
|
44
|
-
enabled: true,
|
|
45
|
-
entropyMax: 0,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
exports.restEndpoint = new adapter_1.AdapterEndpoint({
|
|
50
|
-
name: 'rest',
|
|
51
|
-
aliases: ['qwe'],
|
|
52
|
-
transport: restEndpointTransport,
|
|
53
|
-
inputParameters,
|
|
54
|
-
});
|
|
55
|
-
//# sourceMappingURL=rest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/examples/coingecko/rest.ts"],"names":[],"mappings":";;;AACA,2CAA+C;AAC/C,iDAAgD;AAIhD,MAAM,WAAW,GAAG,kCAAkC,CAAA;AAOtD,MAAM,eAAe,GAAoB;IACvC,MAAM,EAAE;QACN,WAAW,EACT,8IAA8I;QAChJ,QAAQ,EAAE,KAAK;KAChB;IACD,IAAI,EAAE;QACJ,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,yDAAyD;QACtE,QAAQ,EAAE,IAAI;KACf;IACD,KAAK,EAAE;QACL,OAAO,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC;QACzB,WAAW,EAAE,0CAA0C;QACvD,QAAQ,EAAE,IAAI;KACf;CACF,CAAA;AAaD,MAAM,qBAAqB,GAAG,IAAI,0BAAa,CAAC;IAC9C,cAAc,EAAE,CACd,GAAyC,EACA,EAAE;QAC3C,OAAO;YACL,OAAO,EAAE,WAAW;YACpB,GAAG,EAAE,eAAe;YACpB,MAAM,EAAE,KAAK;YACb,MAAM,EAAE;gBACN,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI;gBACjC,aAAa,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK;aAC7C;SACF,CAAA;IACH,CAAC;IACD,aAAa,EAAE,CACb,GAAyC,EACzC,GAAwC,EACD,EAAE;QACzC,OAAO;YACL,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,UAAU,EAAE,GAAG;YACf,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC;SAChF,CAAA;IACH,CAAC;IACD,OAAO,EAAE;QACP,iBAAiB,EAAE;YACjB,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,CAAC;SACd;KACF;CACF,CAAC,CAAA;AAEW,QAAA,YAAY,GAAG,IAAI,yBAAe,CAAC;IAC9C,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,SAAS,EAAE,qBAAqB;IAChC,eAAe;CAChB,CAAC,CAAA"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { AdapterConfig } from '../../../config';
|
|
3
|
-
import { InputParameters } from '../../../validation';
|
|
4
|
-
export interface CryptoRequestParams {
|
|
5
|
-
coinid?: string;
|
|
6
|
-
base?: string;
|
|
7
|
-
quote: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const cryptoInputParams: InputParameters;
|
|
10
|
-
export interface ProviderRequestBody {
|
|
11
|
-
ids: string;
|
|
12
|
-
vs_currencies: string;
|
|
13
|
-
include_market_cap?: boolean;
|
|
14
|
-
include_24hr_vol?: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface ProviderResponseBody {
|
|
17
|
-
[base: string]: {
|
|
18
|
-
[quote: string]: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
interface ResultEntryWithoutOverrides {
|
|
22
|
-
value: number;
|
|
23
|
-
params: {
|
|
24
|
-
quote: string;
|
|
25
|
-
base?: string;
|
|
26
|
-
coinid?: string;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export declare const buildBatchedRequestBody: (params: CryptoRequestParams[], config: AdapterConfig) => AxiosRequestConfig<ProviderRequestBody>;
|
|
30
|
-
export declare const constructEntry: (res: AxiosResponse<ProviderResponseBody>, requestPayload: CryptoRequestParams, resultPath: string) => ResultEntryWithoutOverrides | undefined;
|
|
31
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constructEntry = exports.buildBatchedRequestBody = exports.cryptoInputParams = void 0;
|
|
4
|
-
const config_1 = require("./config");
|
|
5
|
-
const logger_1 = require("../../../util/logger");
|
|
6
|
-
exports.cryptoInputParams = {
|
|
7
|
-
coinid: {
|
|
8
|
-
description: 'The CoinGecko id or to query',
|
|
9
|
-
type: 'string',
|
|
10
|
-
required: false,
|
|
11
|
-
},
|
|
12
|
-
base: {
|
|
13
|
-
aliases: ['from', 'coin'],
|
|
14
|
-
type: 'string',
|
|
15
|
-
description: 'The symbol of symbols of the currency to query',
|
|
16
|
-
required: false,
|
|
17
|
-
},
|
|
18
|
-
quote: {
|
|
19
|
-
aliases: ['to', 'market'],
|
|
20
|
-
type: 'string',
|
|
21
|
-
description: 'The symbol of the currency to convert to',
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
const buildBatchedRequestBody = (params, config) => {
|
|
26
|
-
return {
|
|
27
|
-
baseURL: config.API_KEY ? config_1.PRO_API_ENDPOINT : config_1.DEFAULT_API_ENDPOINT,
|
|
28
|
-
url: '/simple/price',
|
|
29
|
-
method: 'GET',
|
|
30
|
-
params: {
|
|
31
|
-
ids: [...new Set(params.map((p) => p.coinid ?? p.base))].join(','),
|
|
32
|
-
vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
|
|
33
|
-
x_cg_pro_api_key: config.API_KEY,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
exports.buildBatchedRequestBody = buildBatchedRequestBody;
|
|
38
|
-
const logger = (0, logger_1.makeLogger)('CoinGecko Crypto Batched');
|
|
39
|
-
const constructEntry = (res, requestPayload, resultPath) => {
|
|
40
|
-
const coinId = requestPayload.coinid ?? requestPayload.base;
|
|
41
|
-
const dataForCoin = res.data[coinId];
|
|
42
|
-
const dataForQuote = dataForCoin ? dataForCoin[resultPath] : undefined;
|
|
43
|
-
if (!dataForQuote) {
|
|
44
|
-
logger.warn(`Data for "${requestPayload.quote}" not found for token "${coinId}".`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const entry = {
|
|
48
|
-
params: requestPayload,
|
|
49
|
-
value: dataForQuote,
|
|
50
|
-
};
|
|
51
|
-
if (requestPayload.coinid) {
|
|
52
|
-
entry.params.coinid = requestPayload.coinid;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
entry.params.base = requestPayload.base;
|
|
56
|
-
}
|
|
57
|
-
delete entry.params.overrides;
|
|
58
|
-
return entry;
|
|
59
|
-
};
|
|
60
|
-
exports.constructEntry = constructEntry;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { InputParameters } from '../../../validation';
|
|
3
|
-
export declare const inputParameters: InputParameters;
|
|
4
|
-
export interface AdapterRequestParams {
|
|
5
|
-
market: string;
|
|
6
|
-
}
|
|
7
|
-
export interface ProviderResponseBody {
|
|
8
|
-
data: {
|
|
9
|
-
active_cryptocurrencies: number;
|
|
10
|
-
upcoming_icos: number;
|
|
11
|
-
ongoing_icos: number;
|
|
12
|
-
ended_icos: number;
|
|
13
|
-
markets: number;
|
|
14
|
-
total_market_cap: Record<string, number>;
|
|
15
|
-
total_volume: Record<string, number>;
|
|
16
|
-
market_cap_percentage: Record<string, number>;
|
|
17
|
-
market_cap_change_percentage_24h_usd: number;
|
|
18
|
-
updated_at: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
interface ResultEntry {
|
|
22
|
-
value: number;
|
|
23
|
-
params: AdapterRequestParams;
|
|
24
|
-
}
|
|
25
|
-
export declare const buildGlobalRequestBody: (apiKey?: string | undefined) => AxiosRequestConfig<never>;
|
|
26
|
-
export declare const constructEntry: (res: AxiosResponse<ProviderResponseBody>, requestPayload: AdapterRequestParams, resultPath: 'total_market_cap' | 'market_cap_percentage') => ResultEntry | undefined;
|
|
27
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constructEntry = exports.buildGlobalRequestBody = exports.inputParameters = void 0;
|
|
4
|
-
const config_1 = require("./config");
|
|
5
|
-
const logger_1 = require("../../../util/logger");
|
|
6
|
-
const logger = (0, logger_1.makeLogger)('CoinGecko Global Batched');
|
|
7
|
-
exports.inputParameters = {
|
|
8
|
-
market: {
|
|
9
|
-
aliases: ['to', 'quote'],
|
|
10
|
-
description: 'The ticker of the coin to query',
|
|
11
|
-
required: true,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
const buildGlobalRequestBody = (apiKey) => {
|
|
15
|
-
return {
|
|
16
|
-
baseURL: apiKey ? config_1.PRO_API_ENDPOINT : config_1.DEFAULT_API_ENDPOINT,
|
|
17
|
-
url: '/global',
|
|
18
|
-
method: 'GET',
|
|
19
|
-
params: {
|
|
20
|
-
x_cg_pro_api_key: apiKey,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
exports.buildGlobalRequestBody = buildGlobalRequestBody;
|
|
25
|
-
const constructEntry = (res, requestPayload, resultPath) => {
|
|
26
|
-
const resultData = res.data.data;
|
|
27
|
-
if (!resultData) {
|
|
28
|
-
logger.warn(`Data not found".`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const totalMarketcapData = resultData[resultPath];
|
|
32
|
-
if (!totalMarketcapData) {
|
|
33
|
-
logger.warn(`Data for "${resultPath}" not found".`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const result = totalMarketcapData[requestPayload.market.toLowerCase()];
|
|
37
|
-
if (!result) {
|
|
38
|
-
logger.warn(`Data for "${requestPayload.market}" not found".`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
params: requestPayload,
|
|
43
|
-
value: result,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
exports.constructEntry = constructEntry;
|
|
@@ -1,41 +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;
|
|
41
|
-
//# sourceMappingURL=override-functions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,IAAI;QACvB,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC;QACnC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAe,CAAC,OAAO,CAAC,IAAI,CAAC,EACjE;QACA,gBAAgB,GAAI,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAe,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;KACrF;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE;QACnD,qDAAqD;QACrD,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;YAC7B,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAW,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAChG,8BAA8B;QAC9B,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC;gBAC7B,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAW,CAAC;oBAC5D,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;SAClC;QACD,OAAM;KACP;IACD,IAAI,gBAAgB,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAChD,MAAM,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;QAClC,qDAAqD;QACrD,IAAI,gBAAgB,GAClB,gBAAgB,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAClF,8BAA8B;QAC9B,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"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ethereum": {
|
|
3
|
-
"LINK": "0x514910771af9ca656af840dff83e8264ecf986ca",
|
|
4
|
-
"WETH": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
|
|
5
|
-
"ETH": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
6
|
-
"stETH": "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
|
|
7
|
-
"DIGG": "0x798d1be841a82a273720ce31c822c61a67a601c3",
|
|
8
|
-
"WBTC": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
|
|
9
|
-
"RAI": "0x03ab458634910aad20ef5f1c8ee96f1d6ac54919",
|
|
10
|
-
"RGT": "0xD291E7a03283640FDc51b121aC401383A46cC623",
|
|
11
|
-
"RARI": "0xFca59Cd816aB1eaD66534D82bc21E7515cE441CF",
|
|
12
|
-
"SFI": "0xb753428af26e81097e7fd17f40c88aaa3e04902c",
|
|
13
|
-
"LDO": "0x5a98fcbea516cf06857215779fd812ca3bef1b32",
|
|
14
|
-
"VSP": "0x1b40183EFB4Dd766f11bDa7A7c3AD8982e998421",
|
|
15
|
-
"USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
16
|
-
"USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
17
|
-
"DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
|
18
|
-
"FRAX": "0x853d955aCEf822Db058eb8505911ED77F175b99e",
|
|
19
|
-
"BOND": "0x0391d2021f89dc339f60fff84546ea23e337750f",
|
|
20
|
-
"FEI": "0x956f47f50a910163d8bf957cf5846d573e7f87ca",
|
|
21
|
-
"TRIBE": "0xc7283b66Eb1EB5FB86327f08e1B5816b0720212B"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -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 {};
|
package/validation/validator.js
DELETED
|
@@ -1,303 +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.Validator = void 0;
|
|
7
|
-
const error_1 = require("./error");
|
|
8
|
-
const input_params_1 = require("./input-params");
|
|
9
|
-
const util_1 = require("../util");
|
|
10
|
-
const preset_tokens_json_1 = __importDefault(require("./preset-tokens.json"));
|
|
11
|
-
// Don't want to get requester in just yet, only copying the static method 'errored'
|
|
12
|
-
const requesterErrored = (jobRunID = '1', error = undefined, statusCode = 500, feedID = undefined) => {
|
|
13
|
-
if (error instanceof error_1.AdapterError) {
|
|
14
|
-
error.jobRunID = jobRunID;
|
|
15
|
-
if (feedID) {
|
|
16
|
-
error.feedID = feedID;
|
|
17
|
-
}
|
|
18
|
-
return error.toJSONResponse();
|
|
19
|
-
}
|
|
20
|
-
if (error instanceof Error) {
|
|
21
|
-
return new error_1.AdapterError({
|
|
22
|
-
jobRunID,
|
|
23
|
-
statusCode,
|
|
24
|
-
message: error.message,
|
|
25
|
-
cause: error,
|
|
26
|
-
feedID,
|
|
27
|
-
}).toJSONResponse();
|
|
28
|
-
}
|
|
29
|
-
return new error_1.AdapterError({ jobRunID, statusCode, message: error, feedID }).toJSONResponse();
|
|
30
|
-
};
|
|
31
|
-
class Validator {
|
|
32
|
-
constructor(input = { id: '1', data: {} }, inputConfigs = {}, inputOptions = {}, validatorOptions = {}) {
|
|
33
|
-
// OverrideSymbol = (adapter: string, symbol?: string | string[]): string | string[] => {
|
|
34
|
-
// Const defaultSymbol = symbol || this.validated.data.base
|
|
35
|
-
// If (!defaultSymbol) this.throwInvalid(`Required parameter not supplied: base`)
|
|
36
|
-
// // TODO: Will never be reached, because the presetSymbols are used as default overrides
|
|
37
|
-
// If (!this.validated.overrides) return defaultSymbol
|
|
38
|
-
// If (!Array.isArray(defaultSymbol))
|
|
39
|
-
// Return (
|
|
40
|
-
// This.validated.overrides.get(adapter.toLowerCase())?.get(defaultSymbol.toLowerCase()) ||
|
|
41
|
-
// DefaultSymbol
|
|
42
|
-
// )
|
|
43
|
-
// Const multiple: string[] = []
|
|
44
|
-
// For (const sym of defaultSymbol) {
|
|
45
|
-
// Const overrided = this.validated.overrides.get(adapter.toLowerCase())?.get(sym.toLowerCase())
|
|
46
|
-
// If (!overrided) multiple.push(sym)
|
|
47
|
-
// Else multiple.push(overrided)
|
|
48
|
-
// }
|
|
49
|
-
// Return multiple
|
|
50
|
-
// }
|
|
51
|
-
// OverrideToken = (symbol: string, network = 'ethereum'): string | undefined => {
|
|
52
|
-
// Return this.validated.tokenOverrides?.get(network.toLowerCase())?.get(symbol.toLowerCase())
|
|
53
|
-
// }
|
|
54
|
-
// OverrideIncludes = (from: string, to: string): IncludePair | undefined => {
|
|
55
|
-
// // Search through `presetIncludes` to find matching override for adapter and to/from pairing.
|
|
56
|
-
// Const pairs = (
|
|
57
|
-
// This.validated.includes?.filter(
|
|
58
|
-
// (val: string | Includes) => typeof val !== 'string',
|
|
59
|
-
// ) as Includes[]
|
|
60
|
-
// ).filter(
|
|
61
|
-
// (pair) =>
|
|
62
|
-
// Pair.from.toLowerCase() === from.toLowerCase() &&
|
|
63
|
-
// Pair.to.toLowerCase() === to.toLowerCase(),
|
|
64
|
-
// )
|
|
65
|
-
// If (!pairs || !pairs[0] || !pairs[0].includes || !pairs[0].includes[0]) {
|
|
66
|
-
// Return
|
|
67
|
-
// }
|
|
68
|
-
// Return pairs[0].includes[0]
|
|
69
|
-
// }
|
|
70
|
-
// OverrideReverseLookup = (adapter: string, type: OverrideType, symbol: string): string => {
|
|
71
|
-
// Const overrides: Map<string, string> | undefined = this.validated?.[type]?.get(
|
|
72
|
-
// Adapter.toLowerCase(),
|
|
73
|
-
// )
|
|
74
|
-
// If (!overrides) return symbol
|
|
75
|
-
// Let originalSymbol: string | undefined
|
|
76
|
-
// Overrides.forEach((overridden, original) => {
|
|
77
|
-
// If (overridden.toLowerCase() === symbol.toLowerCase()) originalSymbol = original
|
|
78
|
-
// })
|
|
79
|
-
// Return originalSymbol || symbol
|
|
80
|
-
// }
|
|
81
|
-
this.formatOverride = (param) => {
|
|
82
|
-
const _throwInvalid = () => this.throwInvalid(`Parameter supplied with wrong format: "override"`);
|
|
83
|
-
if (!(0, util_1.isObject)(param)) {
|
|
84
|
-
_throwInvalid();
|
|
85
|
-
}
|
|
86
|
-
const _isValid = Object.values(param).every(util_1.isObject);
|
|
87
|
-
if (!_isValid) {
|
|
88
|
-
_throwInvalid();
|
|
89
|
-
}
|
|
90
|
-
const _keyToLowerCase = (entry) => {
|
|
91
|
-
return [entry[0].toLowerCase(), entry[1]];
|
|
92
|
-
};
|
|
93
|
-
return new Map(Object.entries(param)
|
|
94
|
-
.map(_keyToLowerCase)
|
|
95
|
-
.map(([key, value]) => [key, new Map(Object.entries(value).map(_keyToLowerCase))]));
|
|
96
|
-
};
|
|
97
|
-
this.formatIncludeOverrides = (param) => {
|
|
98
|
-
const _throwInvalid = () => this.throwInvalid(`Parameter supplied with wrong format: "includes"`);
|
|
99
|
-
if (!(0, util_1.isArray)(param)) {
|
|
100
|
-
_throwInvalid();
|
|
101
|
-
}
|
|
102
|
-
const _isValid = Object.values(param).every((val) => (0, util_1.isObject)(val) || typeof val === 'string');
|
|
103
|
-
if (!_isValid) {
|
|
104
|
-
_throwInvalid();
|
|
105
|
-
}
|
|
106
|
-
return param;
|
|
107
|
-
};
|
|
108
|
-
this.throwInvalid = (message) => {
|
|
109
|
-
throw new error_1.AdapterError({ jobRunID: this.validated.id, statusCode: 400, message });
|
|
110
|
-
};
|
|
111
|
-
this.input = { ...input };
|
|
112
|
-
if (!this.input.id) {
|
|
113
|
-
this.input.id = '1';
|
|
114
|
-
} // TODO Please remove these once "no any" strict typing is enabled
|
|
115
|
-
if (!this.input.data) {
|
|
116
|
-
this.input.data = {};
|
|
117
|
-
}
|
|
118
|
-
this.inputConfigs = { ...input_params_1.baseInputParameters, ...inputConfigs };
|
|
119
|
-
this.inputOptions = { ...inputOptions };
|
|
120
|
-
this.validatorOptions = {
|
|
121
|
-
shouldThrowError: true,
|
|
122
|
-
includes: [],
|
|
123
|
-
overrides: {},
|
|
124
|
-
...validatorOptions,
|
|
125
|
-
};
|
|
126
|
-
this.validated = { id: this.input.id, data: {} };
|
|
127
|
-
this.validateInput();
|
|
128
|
-
this.validateOverrides('overrides', this.validatorOptions.overrides);
|
|
129
|
-
this.validateOverrides('tokenOverrides', preset_tokens_json_1.default);
|
|
130
|
-
this.validateIncludeOverrides();
|
|
131
|
-
this.checkDuplicateInputParams(inputConfigs);
|
|
132
|
-
}
|
|
133
|
-
validateInput() {
|
|
134
|
-
try {
|
|
135
|
-
for (const key in this.inputConfigs) {
|
|
136
|
-
this.validateObjectParam(key, this.validatorOptions.shouldThrowError);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch (e) {
|
|
140
|
-
this.parseError(e);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
validateOverrides(path, preset) {
|
|
144
|
-
try {
|
|
145
|
-
if (!this.input.data?.[path]) {
|
|
146
|
-
this.validated[path] = this.formatOverride(preset);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
this.validated[path] = this.formatOverride({ ...preset, ...this.input.data[path] });
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
this.parseError(e);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
checkDuplicateInputParams(inputConfig) {
|
|
156
|
-
let aliases = [];
|
|
157
|
-
for (const key in inputConfig) {
|
|
158
|
-
const param = inputConfig[key];
|
|
159
|
-
if (Array.isArray(param)) {
|
|
160
|
-
aliases = aliases.concat(param);
|
|
161
|
-
}
|
|
162
|
-
else if (typeof inputConfig === 'boolean') {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
aliases.push(key);
|
|
167
|
-
if (typeof param === 'object' && 'aliases' in param && Array.isArray(param.aliases)) {
|
|
168
|
-
aliases = aliases.concat(param.aliases);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (aliases.length !== new Set(aliases).size) {
|
|
173
|
-
this.throwInvalid('Duplicate Input Aliases');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
validateIncludeOverrides() {
|
|
177
|
-
try {
|
|
178
|
-
this.validated.includes = this.formatIncludeOverrides([
|
|
179
|
-
...(Array.isArray(this.input.data?.includes) ? this.input.data.includes : []),
|
|
180
|
-
...(this.validatorOptions.includes || []),
|
|
181
|
-
]);
|
|
182
|
-
}
|
|
183
|
-
catch (e) {
|
|
184
|
-
this.parseError(e);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
parseError(error) {
|
|
188
|
-
if (!(error instanceof Error)) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const message = 'Error validating input.';
|
|
192
|
-
if (error instanceof error_1.AdapterError) {
|
|
193
|
-
this.error = error;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
this.error = new error_1.AdapterError({
|
|
197
|
-
jobRunID: this.validated.id,
|
|
198
|
-
statusCode: 400,
|
|
199
|
-
message,
|
|
200
|
-
cause: error,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
this.errored = requesterErrored(this.validated.id, this.error);
|
|
204
|
-
if (this.validatorOptions.shouldThrowError) {
|
|
205
|
-
throw this.error;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
validateObjectParam(key, shouldThrowError = true) {
|
|
209
|
-
const inputConfig = this.inputConfigs[key];
|
|
210
|
-
const usedKey = this.getUsedKey(key, inputConfig.aliases ?? []);
|
|
211
|
-
const param = usedKey
|
|
212
|
-
? this.input.data[usedKey] ?? inputConfig.default
|
|
213
|
-
: inputConfig.default;
|
|
214
|
-
if (shouldThrowError) {
|
|
215
|
-
const paramIsDefined = !(param === undefined || param === null || param === '');
|
|
216
|
-
if (inputConfig.required && !paramIsDefined) {
|
|
217
|
-
this.throwInvalid(`Required parameter ${key} must be non-null and non-empty`);
|
|
218
|
-
}
|
|
219
|
-
if (paramIsDefined) {
|
|
220
|
-
if (inputConfig.type) {
|
|
221
|
-
const primitiveTypes = ['boolean', 'number', 'bigint', 'string'];
|
|
222
|
-
if (![...primitiveTypes, 'array', 'object'].includes(inputConfig.type)) {
|
|
223
|
-
this.throwInvalid(`${key} parameter has unrecognized type ${inputConfig.type}`);
|
|
224
|
-
}
|
|
225
|
-
if (primitiveTypes.includes(inputConfig.type) && typeof param !== inputConfig.type) {
|
|
226
|
-
this.throwInvalid(`${key} parameter must be of type ${inputConfig.type}`);
|
|
227
|
-
}
|
|
228
|
-
if (inputConfig.type === 'array' && (!Array.isArray(param) || param.length === 0)) {
|
|
229
|
-
this.throwInvalid(`${key} parameter must be a non-empty array`);
|
|
230
|
-
}
|
|
231
|
-
if (inputConfig.type === 'object' &&
|
|
232
|
-
(!param ||
|
|
233
|
-
Array.isArray(param) ||
|
|
234
|
-
typeof param !== inputConfig.type ||
|
|
235
|
-
Object.keys(param).length === 0)) {
|
|
236
|
-
this.throwInvalid(`${key} parameter must be an object with at least one property`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
// If (inputConfig.options) {
|
|
240
|
-
// Const tolcase = (o: any) => (typeof o === 'string' ? o.toLowerCase() : o)
|
|
241
|
-
// Const formattedOptions = inputConfig.options.map(tolcase)
|
|
242
|
-
// Const formattedParam = tolcase(param)
|
|
243
|
-
// If (!formattedOptions.includes(formattedParam))
|
|
244
|
-
// This.throwInvalid(
|
|
245
|
-
// `${key} parameter '${formattedParam}' is not in the set of available options: ${formattedOptions.join(
|
|
246
|
-
// ',',
|
|
247
|
-
// )}`,
|
|
248
|
-
// )
|
|
249
|
-
// }
|
|
250
|
-
// For (const dependency of inputConfig.dependsOn ?? []) {
|
|
251
|
-
// Const usedDependencyKey = this.getUsedKey(
|
|
252
|
-
// Dependency,
|
|
253
|
-
// (this.inputConfigs[dependency] as InputParameter).aliases ?? [],
|
|
254
|
-
// )
|
|
255
|
-
// If (!usedDependencyKey) this.throwInvalid(`${key} dependency ${dependency} not supplied`)
|
|
256
|
-
// }
|
|
257
|
-
// For (const exclusive of inputConfig.exclusive ?? []) {
|
|
258
|
-
// Const usedExclusiveKey = this.getUsedKey(
|
|
259
|
-
// Exclusive,
|
|
260
|
-
// (this.inputConfigs[exclusive] as InputParameter).aliases ?? [],
|
|
261
|
-
// )
|
|
262
|
-
// If (usedExclusiveKey)
|
|
263
|
-
// This.throwInvalid(`${key} cannot be supplied concurrently with ${exclusive}`)
|
|
264
|
-
// }
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
this.validated.data[key] = param;
|
|
268
|
-
}
|
|
269
|
-
validateOptionalParam(param, key, options) {
|
|
270
|
-
if (param && options) {
|
|
271
|
-
if (!Array.isArray(options)) {
|
|
272
|
-
this.throwInvalid(`Parameter options for ${key} must be of an Array type`);
|
|
273
|
-
}
|
|
274
|
-
if (!options.includes(param)) {
|
|
275
|
-
this.throwInvalid(`${param} is not a supported ${key} option. Must be one of ${options}`);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
this.validated.data[key] = param;
|
|
279
|
-
}
|
|
280
|
-
validateRequiredParam(param, key, options) {
|
|
281
|
-
if (typeof param === 'undefined' || param === '') {
|
|
282
|
-
this.throwInvalid(`Required parameter not supplied: ${key}`);
|
|
283
|
-
}
|
|
284
|
-
if (options) {
|
|
285
|
-
if (!Array.isArray(options)) {
|
|
286
|
-
this.throwInvalid(`Parameter options for ${key} must be of an Array type`);
|
|
287
|
-
}
|
|
288
|
-
if (!options.includes(param)) {
|
|
289
|
-
this.throwInvalid(`${param} is not a supported ${key} option. Must be one of ${options.join(' || ')}`);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
this.validated.data[key] = param;
|
|
293
|
-
}
|
|
294
|
-
getUsedKey(key, keyArray) {
|
|
295
|
-
const comparisonArray = [...keyArray];
|
|
296
|
-
if (!comparisonArray.includes(key)) {
|
|
297
|
-
comparisonArray.push(key);
|
|
298
|
-
}
|
|
299
|
-
const inputParamKeys = Object.keys(this.input.data);
|
|
300
|
-
return inputParamKeys.find((k) => comparisonArray.includes(k));
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
exports.Validator = Validator;
|