@chainlink/external-adapter-framework 0.9.0 → 0.10.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/README.md +67 -0
- package/adapter/basic.d.ts +50 -6
- package/adapter/basic.js +173 -4
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +6 -6
- package/adapter/endpoint.js +1 -0
- package/adapter/endpoint.js.map +1 -1
- package/adapter/price.d.ts +38 -8
- package/adapter/price.js +43 -1
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +40 -15
- package/background-executor.js +21 -5
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +11 -17
- package/cache/index.js +9 -51
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +28 -11
- package/config/index.js +63 -46
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +17 -25
- package/examples/bank-frick/accounts.js +23 -13
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/config/index.d.ts +5 -0
- package/examples/bank-frick/config/index.js +5 -0
- package/examples/bank-frick/config/index.js.map +1 -1
- package/examples/bank-frick/index.d.ts +1 -15
- package/examples/bank-frick/index.js +1 -1
- package/examples/coingecko/src/config/index.d.ts +7 -0
- package/examples/coingecko/src/config/index.js +8 -1
- package/examples/coingecko/src/config/index.js.map +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +19 -4
- 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.d.ts +20 -3
- 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 +2 -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 +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 +18 -3
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +3 -1
- package/examples/coingecko/src/index.js.map +1 -1
- package/examples/cryptocompare/src/config/index.d.ts +7 -0
- package/examples/cryptocompare/src/config/index.js +8 -1
- package/examples/cryptocompare/src/config/index.js.map +1 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +14 -2
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +3 -1
- package/examples/cryptocompare/src/index.js.map +1 -1
- package/examples/genesis/config/index.d.ts +5 -0
- package/examples/genesis/config/index.js +5 -0
- package/examples/genesis/config/index.js.map +1 -1
- package/examples/genesis/index.js +1 -1
- package/examples/genesis/sseStream.d.ts +13 -2
- package/examples/genesis/sseStream.js +4 -1
- package/examples/genesis/sseStream.js.map +1 -1
- package/index.d.ts +1 -0
- 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/metrics/util.d.ts +5 -5
- package/metrics/util.js +2 -2
- package/metrics/util.js.map +1 -1
- package/package.json +7 -9
- package/rate-limiting/background/fixed-frequency.d.ts +2 -3
- 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 +2 -3
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/transports/batch-warming.d.ts +40 -18
- package/transports/batch-warming.js +45 -18
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +65 -31
- package/transports/index.js +2 -59
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +3 -3
- package/transports/metrics.js +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +42 -30
- package/transports/rest.js +25 -30
- package/transports/rest.js.map +1 -1
- package/transports/routing.d.ts +21 -0
- package/transports/routing.js +50 -0
- package/transports/routing.js.map +1 -0
- package/transports/sse.d.ts +40 -20
- package/transports/sse.js +10 -8
- package/transports/sse.js.map +1 -1
- package/transports/util.d.ts +3 -1
- package/transports/util.js +69 -39
- package/transports/util.js.map +1 -1
- package/transports/websocket.d.ts +41 -26
- package/transports/websocket.js +16 -19
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +2 -0
- package/util/logger.js +4 -7
- package/util/logger.js.map +1 -1
- package/util/request.d.ts +46 -10
- 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 +2 -4
- package/validation/error.js.map +1 -1
- package/validation/index.js +28 -18
- 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/examples/coingecko-old/batch-warming.d.ts +0 -7
- package/examples/coingecko-old/batch-warming.js +0 -54
- package/examples/coingecko-old/batch-warming.js.map +0 -1
- package/examples/coingecko-old/index.d.ts +0 -2
- package/examples/coingecko-old/index.js +0 -12
- package/examples/coingecko-old/index.js.map +0 -1
- package/examples/coingecko-old/rest.d.ts +0 -12
- package/examples/coingecko-old/rest.js +0 -55
- package/examples/coingecko-old/rest.js.map +0 -1
- package/examples/ncfx/config/index.d.ts +0 -12
- package/examples/ncfx/config/index.js +0 -16
- package/examples/ncfx/config/index.js.map +0 -1
- package/examples/ncfx/index.d.ts +0 -13
- package/examples/ncfx/index.js +0 -12
- package/examples/ncfx/index.js.map +0 -1
- package/examples/ncfx/websocket.d.ts +0 -47
- package/examples/ncfx/websocket.js +0 -74
- package/examples/ncfx/websocket.js.map +0 -1
- package/validation/override-functions.d.ts +0 -3
- package/validation/override-functions.js +0 -41
- package/validation/override-functions.js.map +0 -1
package/adapter/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import type EventSource from 'eventsource';
|
|
1
2
|
import Redis from 'ioredis';
|
|
2
|
-
import { AdapterEndpoint } from './endpoint';
|
|
3
|
-
import { CustomSettingsType, SettingsMap, AdapterConfig, BaseAdapterConfig } from '../config';
|
|
4
|
-
import { RequestRateLimiter, BackgroundExecuteRateLimiter, AdapterRateLimitTier } from '../rate-limiting';
|
|
5
|
-
import { Transport } from '../transports';
|
|
6
|
-
import { SubscriptionSetFactory } from '../util';
|
|
7
|
-
import { InputParameters } from '../validation';
|
|
8
3
|
import { Cache } from '../cache';
|
|
9
|
-
import
|
|
4
|
+
import { AdapterConfig, BaseAdapterConfig, SettingsMap } from '../config';
|
|
5
|
+
import { AdapterRateLimitTier, BackgroundExecuteRateLimiter, RequestRateLimiter } from '../rate-limiting';
|
|
6
|
+
import { Transport, TransportGenerics } from '../transports';
|
|
7
|
+
import { AdapterRequest, SubscriptionSetFactory } from '../util';
|
|
8
|
+
import { InputParameters } from '../validation';
|
|
9
|
+
import { Adapter } from './basic';
|
|
10
|
+
import { AdapterEndpoint } from './endpoint';
|
|
10
11
|
export declare type CustomAdapterSettings = SettingsMap & NegatedAdapterSettings;
|
|
11
12
|
declare type NegatedAdapterSettings = {
|
|
12
13
|
[K in keyof BaseAdapterConfig]?: never;
|
|
@@ -32,11 +33,13 @@ export interface AdapterDependencies {
|
|
|
32
33
|
* Context that will be used on background executions of a Transport.
|
|
33
34
|
* For example, the endpointName used to log statements or generate Cache keys.
|
|
34
35
|
*/
|
|
35
|
-
export interface
|
|
36
|
-
/** Endpoint
|
|
37
|
-
|
|
36
|
+
export interface EndpointContext<T extends EndpointGenerics> {
|
|
37
|
+
/** Endpoint name */
|
|
38
|
+
endpointName: string;
|
|
39
|
+
/** Input parameters for this endpoint */
|
|
40
|
+
inputParameters: InputParameters;
|
|
38
41
|
/** Initialized config for the adapter that the Transport can access */
|
|
39
|
-
adapterConfig: AdapterConfig<CustomSettings>;
|
|
42
|
+
adapterConfig: AdapterConfig<T['CustomSettings']>;
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* Structure to describe rate limits specs for the Adapter
|
|
@@ -45,12 +48,24 @@ export interface AdapterRateLimitingConfig {
|
|
|
45
48
|
/** Adapter rate limits, gotten from the specific tier requested */
|
|
46
49
|
tiers: Record<string, AdapterRateLimitTier>;
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Type to perform arbitrary modifications on an adapter request
|
|
53
|
+
*/
|
|
54
|
+
export declare type RequestTransform = (req: AdapterRequest) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Map of overrides objects (symbol -\> symbol) per adapter name
|
|
57
|
+
*/
|
|
58
|
+
export declare type Overrides = {
|
|
59
|
+
[adapterName: string]: {
|
|
60
|
+
[symbol: string]: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
48
63
|
/**
|
|
49
64
|
* Main structure of an External Adapter
|
|
50
65
|
*/
|
|
51
66
|
export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
52
67
|
/** Name of the adapter */
|
|
53
|
-
name: string
|
|
68
|
+
name: Uppercase<string>;
|
|
54
69
|
/** If present, the string that will be used for requests with no specified endpoint */
|
|
55
70
|
defaultEndpoint?: string;
|
|
56
71
|
/**
|
|
@@ -62,7 +77,7 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
|
62
77
|
* We also can't use generics, because if we had more than one transport with different requests (very likely)
|
|
63
78
|
* then those new types wouldn't match with each other.
|
|
64
79
|
*/
|
|
65
|
-
endpoints: AdapterEndpoint<any
|
|
80
|
+
endpoints: AdapterEndpoint<any>[];
|
|
66
81
|
/** Map of overrides to the default config values for an Adapter */
|
|
67
82
|
envDefaultOverrides?: Partial<BaseAdapterConfig>;
|
|
68
83
|
/** List of custom env vars for this particular adapter (e.g. RPC_URL) */
|
|
@@ -71,6 +86,10 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
|
71
86
|
rateLimiting?: AdapterRateLimitingConfig;
|
|
72
87
|
/** Overrides for converting the 'base' parameter that are hardcoded into the adapter. */
|
|
73
88
|
overrides?: Record<string, string>;
|
|
89
|
+
/** Transforms that will apply to the request before submitting it through the adapter request flow */
|
|
90
|
+
requestTransforms?: RequestTransform[];
|
|
91
|
+
/** Bootstrap function that will run when initializing the adapter */
|
|
92
|
+
bootstrap?: (adapter: Adapter<CustomSettings>) => Promise<void>;
|
|
74
93
|
}
|
|
75
94
|
/**
|
|
76
95
|
* Structure to describe rate limits specs for a specific adapter endpoint
|
|
@@ -83,19 +102,25 @@ export interface EndpointRateLimitingConfig {
|
|
|
83
102
|
*/
|
|
84
103
|
allocationPercentage: number;
|
|
85
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Helper type structure that contains the different types passed to the generic parameters of an AdapterEndpoint
|
|
107
|
+
*/
|
|
108
|
+
export declare type EndpointGenerics = TransportGenerics;
|
|
86
109
|
/**
|
|
87
110
|
* Structure to describe a specific endpoint in an [[Adapter]]
|
|
88
111
|
*/
|
|
89
|
-
export interface AdapterEndpointParams<
|
|
112
|
+
export interface AdapterEndpointParams<T extends EndpointGenerics> {
|
|
90
113
|
/** Name that will be used to match input params to this endpoint (case insensitive) */
|
|
91
114
|
name: string;
|
|
92
115
|
/** List of alternative endpoint names that will resolve to this same transport (case insensitive) */
|
|
93
116
|
aliases?: string[];
|
|
94
117
|
/** Transport that will be used to handle data processing and communication for this endpoint */
|
|
95
|
-
transport: Transport<
|
|
118
|
+
transport: Transport<T>;
|
|
96
119
|
/** Specification of what the body of a request hitting this endpoint should look like (used for validation) */
|
|
97
120
|
inputParameters: InputParameters;
|
|
98
121
|
/** Specific details related to the rate limiting for this endpoint in particular */
|
|
99
122
|
rateLimiting?: EndpointRateLimitingConfig;
|
|
123
|
+
/** Custom function that generates cache keys */
|
|
124
|
+
cacheKeyGenerator?: (data: Record<string, unknown>) => string;
|
|
100
125
|
}
|
|
101
126
|
export {};
|
package/background-executor.js
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.callBackgroundExecutes = void 0;
|
|
27
|
-
const util_1 = require("./util");
|
|
28
27
|
const metrics = __importStar(require("./metrics"));
|
|
28
|
+
const util_1 = require("./util");
|
|
29
29
|
const logger = (0, util_1.makeLogger)('BackgroundExecutor');
|
|
30
30
|
/**
|
|
31
31
|
* Very simple background loop that will call the [[Transport.backgroundExecute]] functions in all Transports.
|
|
@@ -47,14 +47,16 @@ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
|
|
|
47
47
|
clearTimeout(timeoutsMap[endpointName]);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// Checks if an individual transport has a backgroundExecute function, and executes it if it does
|
|
51
|
+
const callBackgroundExecute = (endpoint, transport) => {
|
|
52
|
+
const backgroundExecute = transport.backgroundExecute?.bind(transport);
|
|
52
53
|
if (!backgroundExecute) {
|
|
53
54
|
logger.debug(`Endpoint "${endpoint.name}" has no background execute, skipping...`);
|
|
54
|
-
|
|
55
|
+
return;
|
|
55
56
|
}
|
|
56
57
|
const context = {
|
|
57
|
-
|
|
58
|
+
endpointName: endpoint.name,
|
|
59
|
+
inputParameters: endpoint.inputParameters,
|
|
58
60
|
adapterConfig: adapter.config,
|
|
59
61
|
};
|
|
60
62
|
const handler = async () => {
|
|
@@ -76,6 +78,20 @@ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
|
|
|
76
78
|
};
|
|
77
79
|
// Start recursive async calls
|
|
78
80
|
handler();
|
|
81
|
+
};
|
|
82
|
+
for (const endpoint of adapter.endpoints) {
|
|
83
|
+
const { transport } = endpoint;
|
|
84
|
+
// Check if transport is a MetaTransport by casting and checking a known property (transports)
|
|
85
|
+
const castMeta = transport;
|
|
86
|
+
if (castMeta.transports) {
|
|
87
|
+
logger.debug(`Encountered MetaTransport ${transport.constructor.name}, calling backgroundExecute on all transports`);
|
|
88
|
+
for (const nestedTransport of Object.values(castMeta.transports)) {
|
|
89
|
+
callBackgroundExecute(endpoint, nestedTransport);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
callBackgroundExecute(endpoint, transport);
|
|
94
|
+
}
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
97
|
exports.callBackgroundExecutes = callBackgroundExecutes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-executor.js","sourceRoot":"","sources":["../../src/background-executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"background-executor.js","sourceRoot":"","sources":["../../src/background-executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAoC;AAEpC,iCAAmC;AAEnC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAE/C;;;;;;GAMG;AACI,KAAK,UAAU,sBAAsB,CAAC,OAAgB,EAAE,kBAAkC;IAC/F,uFAAuF;IACvF,4FAA4F;IAC5F,IAAI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,CAAA;YAEf,MAAM,CAAC,KAAK,CAAC,4CAA4C,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAA;YAC1E,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAA;YACnD,MAAM,CAAC,KAAK,CACV,6CAA6C,QAAQ,CAAC,IAAI,mBAAmB,UAAU,IAAI,CAC5F,CAAA;YAED,YAAY,EAAE,CAAA;YACd,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;QAC9D,CAAC,CAAA;QAED,8BAA8B;QAC9B,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IAED,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE;QACxC,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAA;QAE9B,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,SAA6C,CAAA;QAC9D,IAAI,QAAQ,CAAC,UAAU,EAAE;YACvB,MAAM,CAAC,KAAK,CACV,6BAA6B,SAAS,CAAC,WAAW,CAAC,IAAI,+CAA+C,CACvG,CAAA;YACD,KAAK,MAAM,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;gBAChE,qBAAqB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;aACjD;SACF;aAAM;YACL,qBAAqB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;SAC3C;KACF;AACH,CAAC;AA7ED,wDA6EC"}
|
package/cache/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AdapterEndpoint } from '../adapter';
|
|
2
1
|
import { AdapterConfig, SettingsMap } from '../config';
|
|
3
|
-
import {
|
|
2
|
+
import { AdapterResponse, sleep } from '../util';
|
|
3
|
+
import { InputParameters } from '../validation/input-params';
|
|
4
|
+
export * from './factory';
|
|
4
5
|
export * from './local';
|
|
5
6
|
export * from './redis';
|
|
6
|
-
export * from './factory';
|
|
7
7
|
/**
|
|
8
8
|
* An object describing an entry in the cache.
|
|
9
9
|
* @typeParam T - the type of the entry's value
|
|
@@ -49,13 +49,14 @@ export interface Cache<T = unknown> {
|
|
|
49
49
|
*/
|
|
50
50
|
delete: (key: string) => Promise<void>;
|
|
51
51
|
}
|
|
52
|
-
export declare const calculateCacheKey: <
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
export declare const calculateCacheKey: <T extends import("../transports").TransportGenerics>({ endpointName, inputParameters, adapterConfig, }: {
|
|
53
|
+
inputParameters: InputParameters;
|
|
54
|
+
endpointName: string;
|
|
55
|
+
adapterConfig: AdapterConfig<T["CustomSettings"]>;
|
|
55
56
|
}, data: unknown) => string;
|
|
56
|
-
export declare const calculateFeedId: <
|
|
57
|
-
|
|
58
|
-
adapterConfig: AdapterConfig<CustomSettings>;
|
|
57
|
+
export declare const calculateFeedId: <T extends import("../transports").TransportGenerics>({ inputParameters, adapterConfig, }: {
|
|
58
|
+
inputParameters: InputParameters;
|
|
59
|
+
adapterConfig: AdapterConfig<T["CustomSettings"]>;
|
|
59
60
|
}, data: unknown) => string;
|
|
60
61
|
/**
|
|
61
62
|
* Calculates a unique key from the provided data.
|
|
@@ -71,6 +72,7 @@ export declare const calculateFeedId: <Params, Result, CustomSettings extends Se
|
|
|
71
72
|
* ```
|
|
72
73
|
*/
|
|
73
74
|
export declare const calculateKey: <CustomSettings extends SettingsMap>(data: unknown, paramNames: string[], adapterConfig: AdapterConfig<CustomSettings>) => string;
|
|
75
|
+
export declare const calculateStaleness: (expirationTimestamp: number | undefined, ttl: number) => number;
|
|
74
76
|
/**
|
|
75
77
|
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
76
78
|
* amount of retries is exceeded, it returns undefined instead.
|
|
@@ -84,11 +86,3 @@ export declare const pollResponseFromCache: (cache: Cache<AdapterResponse>, key:
|
|
|
84
86
|
maxRetries: number;
|
|
85
87
|
sleep: number;
|
|
86
88
|
}, retry?: number) => Promise<AdapterResponse | undefined>;
|
|
87
|
-
/**
|
|
88
|
-
* Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
|
|
89
|
-
* a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
|
|
90
|
-
*
|
|
91
|
-
* @param adapter - an initialized adapter
|
|
92
|
-
* @returns the cache middleware function
|
|
93
|
-
*/
|
|
94
|
-
export declare const buildCacheMiddleware: AdapterMiddlewareBuilder;
|
package/cache/index.js
CHANGED
|
@@ -10,43 +10,30 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
17
|
+
exports.pollResponseFromCache = exports.calculateStaleness = exports.calculateKey = exports.calculateFeedId = exports.calculateCacheKey = void 0;
|
|
30
18
|
const util_1 = require("../util");
|
|
31
|
-
|
|
19
|
+
__exportStar(require("./factory"), exports);
|
|
32
20
|
__exportStar(require("./local"), exports);
|
|
33
21
|
__exportStar(require("./redis"), exports);
|
|
34
|
-
__exportStar(require("./factory"), exports);
|
|
35
22
|
const logger = (0, util_1.makeLogger)('Cache');
|
|
36
23
|
// Uses calculateKey to generate a unique key from the endpoint name, data, and input parameters
|
|
37
|
-
const calculateCacheKey = ({
|
|
38
|
-
const paramNames = Object.keys(
|
|
24
|
+
const calculateCacheKey = ({ endpointName, inputParameters, adapterConfig, }, data) => {
|
|
25
|
+
const paramNames = Object.keys(inputParameters);
|
|
39
26
|
if (paramNames.length === 0) {
|
|
40
27
|
logger.trace(`Using default cache key ${adapterConfig.DEFAULT_CACHE_KEY}`);
|
|
41
28
|
return adapterConfig.DEFAULT_CACHE_KEY;
|
|
42
29
|
}
|
|
43
|
-
const cacheKey = `${
|
|
30
|
+
const cacheKey = `${endpointName}-${(0, exports.calculateKey)(data, paramNames, adapterConfig)}`;
|
|
44
31
|
logger.trace(`Generated cache key for request: "${cacheKey}"`);
|
|
45
32
|
return cacheKey;
|
|
46
33
|
};
|
|
47
34
|
exports.calculateCacheKey = calculateCacheKey;
|
|
48
|
-
const calculateFeedId = ({
|
|
49
|
-
const paramNames = Object.keys(
|
|
35
|
+
const calculateFeedId = ({ inputParameters, adapterConfig, }, data) => {
|
|
36
|
+
const paramNames = Object.keys(inputParameters);
|
|
50
37
|
if (paramNames.length === 0) {
|
|
51
38
|
logger.trace(`Cannot generate Feed ID without input parameters`);
|
|
52
39
|
return 'N/A';
|
|
@@ -74,10 +61,6 @@ const calculateKey = (data, paramNames, adapterConfig) => {
|
|
|
74
61
|
const params = data;
|
|
75
62
|
let cacheKey = '';
|
|
76
63
|
for (const paramName of paramNames) {
|
|
77
|
-
// Ignore overrides param when generating cache keys
|
|
78
|
-
if (paramName === 'overrides') {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
64
|
const param = params[paramName];
|
|
82
65
|
if (param === undefined) {
|
|
83
66
|
continue;
|
|
@@ -104,7 +87,7 @@ const calculateKey = (data, paramNames, adapterConfig) => {
|
|
|
104
87
|
return cacheKey;
|
|
105
88
|
};
|
|
106
89
|
exports.calculateKey = calculateKey;
|
|
107
|
-
// Calculate the amount of time
|
|
90
|
+
// Calculate the amount of time a non-expired entry has been in the cache
|
|
108
91
|
const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
109
92
|
if (expirationTimestamp) {
|
|
110
93
|
const createTimestamp = expirationTimestamp - ttl;
|
|
@@ -116,6 +99,7 @@ const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
|
116
99
|
return ttl;
|
|
117
100
|
}
|
|
118
101
|
};
|
|
102
|
+
exports.calculateStaleness = calculateStaleness;
|
|
119
103
|
/**
|
|
120
104
|
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
121
105
|
* amount of retries is exceeded, it returns undefined instead.
|
|
@@ -146,30 +130,4 @@ const pollResponseFromCache = async (cache, key, options, retry = 0) => {
|
|
|
146
130
|
return (0, exports.pollResponseFromCache)(cache, key, options, retry + 1);
|
|
147
131
|
};
|
|
148
132
|
exports.pollResponseFromCache = pollResponseFromCache;
|
|
149
|
-
/**
|
|
150
|
-
* Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
|
|
151
|
-
* a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
|
|
152
|
-
*
|
|
153
|
-
* @param adapter - an initialized adapter
|
|
154
|
-
* @returns the cache middleware function
|
|
155
|
-
*/
|
|
156
|
-
const buildCacheMiddleware = (adapter) => async (req, res) => {
|
|
157
|
-
const response = await adapter.dependencies.cache.get(req.requestContext.cacheKey);
|
|
158
|
-
if (response) {
|
|
159
|
-
logger.debug('Found response from cache, sending that');
|
|
160
|
-
if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
161
|
-
const label = cacheMetrics.cacheMetricsLabel(req.requestContext.cacheKey, req.requestContext.meta?.metrics?.feedId || 'N/A', adapter.config.CACHE_TYPE);
|
|
162
|
-
// Record cache staleness and cache get count and value
|
|
163
|
-
const staleness = calculateStaleness(response.maxAge, adapter.config.CACHE_MAX_AGE);
|
|
164
|
-
cacheMetrics.cacheGet(label, response.result, staleness);
|
|
165
|
-
req.requestContext.meta = {
|
|
166
|
-
...req.requestContext.meta,
|
|
167
|
-
metrics: { ...req.requestContext.meta?.metrics, cacheHit: true },
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return res.send(response);
|
|
171
|
-
}
|
|
172
|
-
logger.debug('Did not find response in cache, moving to next middleware');
|
|
173
|
-
};
|
|
174
|
-
exports.buildCacheMiddleware = buildCacheMiddleware;
|
|
175
133
|
//# sourceMappingURL=index.js.map
|
package/cache/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,kCAA4D;AAG5D,4CAAyB;AACzB,0CAAuB;AACvB,0CAAuB;AAEvB,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,OAAO,CAAC,CAAA;AAoDlC,gGAAgG;AACzF,MAAM,iBAAiB,GAAG,CAC/B,EACE,YAAY,EACZ,eAAe,EACf,aAAa,GAKd,EACD,IAAa,EACL,EAAE;IACV,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;IAC/C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAC,KAAK,CAAC,2BAA2B,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAA;QAC1E,OAAO,aAAa,CAAC,iBAAiB,CAAA;KACvC;IACD,MAAM,QAAQ,GAAG,GAAG,YAAY,IAAI,IAAA,oBAAY,EAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,CAAA;IACnF,MAAM,CAAC,KAAK,CAAC,qCAAqC,QAAQ,GAAG,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C,EAAE;QAC5B,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACpD,OAAO,SAAS,CAAA;KACjB;IAED,MAAM,CAAC,KAAK,CAAC,gCAAgC,OAAO,CAAC,KAAK,kBAAkB,CAAC,CAAA;IAC7E,MAAM,IAAA,YAAK,EAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,IAAA,6BAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;AAC9D,CAAC,CAAA;AA/BY,QAAA,qBAAqB,yBA+BjC"}
|
package/config/index.d.ts
CHANGED
|
@@ -3,11 +3,6 @@ export declare const BaseSettings: {
|
|
|
3
3
|
readonly description: "The URL that certain transports use to retrieve data";
|
|
4
4
|
readonly type: "string";
|
|
5
5
|
};
|
|
6
|
-
readonly API_KEY: {
|
|
7
|
-
readonly description: "Default setting for an EA key";
|
|
8
|
-
readonly type: "string";
|
|
9
|
-
readonly sensitive: true;
|
|
10
|
-
};
|
|
11
6
|
readonly API_TIMEOUT: {
|
|
12
7
|
readonly description: "The number of milliseconds a request can be pending before returning a timeout error for data provider request";
|
|
13
8
|
readonly type: "number";
|
|
@@ -23,16 +18,31 @@ export declare const BaseSettings: {
|
|
|
23
18
|
readonly type: "string";
|
|
24
19
|
readonly default: "/";
|
|
25
20
|
};
|
|
21
|
+
readonly BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
22
|
+
readonly description: "Flag to toggle batch transport setup validation";
|
|
23
|
+
readonly type: "boolean";
|
|
24
|
+
readonly default: false;
|
|
25
|
+
};
|
|
26
26
|
readonly CACHE_MAX_AGE: {
|
|
27
27
|
readonly description: "Maximum amount of time (in ms) that a response will stay cached";
|
|
28
28
|
readonly type: "number";
|
|
29
29
|
readonly default: 90000;
|
|
30
30
|
};
|
|
31
|
+
readonly CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
32
|
+
readonly description: "Connection timeout for redis client";
|
|
33
|
+
readonly type: "number";
|
|
34
|
+
readonly default: 15000;
|
|
35
|
+
};
|
|
31
36
|
readonly CACHE_REDIS_HOST: {
|
|
32
37
|
readonly description: "Hostname for the Redis instance to be used";
|
|
33
38
|
readonly type: "string";
|
|
34
39
|
readonly default: "127.0.0.1";
|
|
35
40
|
};
|
|
41
|
+
readonly CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
42
|
+
readonly description: "Max cooldown (in ms) before attempting redis reconnection";
|
|
43
|
+
readonly type: "number";
|
|
44
|
+
readonly default: 3000;
|
|
45
|
+
};
|
|
36
46
|
readonly CACHE_REDIS_PASSWORD: {
|
|
37
47
|
readonly description: "The password required for redis auth";
|
|
38
48
|
readonly type: "string";
|
|
@@ -52,6 +62,10 @@ export declare const BaseSettings: {
|
|
|
52
62
|
readonly type: "number";
|
|
53
63
|
readonly default: 500;
|
|
54
64
|
};
|
|
65
|
+
readonly CACHE_REDIS_URL: {
|
|
66
|
+
readonly description: "The URL of the Redis server. Format: [redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]";
|
|
67
|
+
readonly type: "string";
|
|
68
|
+
};
|
|
55
69
|
readonly CACHE_TYPE: {
|
|
56
70
|
readonly description: "The type of cache to use throughout the EA";
|
|
57
71
|
readonly type: "enum";
|
|
@@ -127,6 +141,11 @@ export declare const BaseSettings: {
|
|
|
127
141
|
readonly type: "number";
|
|
128
142
|
readonly default: 0;
|
|
129
143
|
};
|
|
144
|
+
readonly RETRY: {
|
|
145
|
+
readonly type: "number";
|
|
146
|
+
readonly description: "Retry count for failed HTTP requests";
|
|
147
|
+
readonly default: 1;
|
|
148
|
+
};
|
|
130
149
|
readonly SSE_SUBSCRIPTION_UPDATE_SLEEP: {
|
|
131
150
|
readonly description: "Maximum amount of time (in ms) between each update to the set of subscribed feeds";
|
|
132
151
|
readonly type: "number";
|
|
@@ -151,11 +170,6 @@ export declare const BaseSettings: {
|
|
|
151
170
|
readonly description: "Override the base websocket URL within the EA.";
|
|
152
171
|
readonly type: "string";
|
|
153
172
|
};
|
|
154
|
-
readonly WS_API_KEY: {
|
|
155
|
-
readonly description: "The websocket API key to authenticate with";
|
|
156
|
-
readonly type: "string";
|
|
157
|
-
readonly sensitive: true;
|
|
158
|
-
};
|
|
159
173
|
readonly WS_SUBSCRIPTION_TTL: {
|
|
160
174
|
readonly description: "";
|
|
161
175
|
readonly type: "number";
|
|
@@ -208,10 +222,13 @@ export declare const BaseSettings: {
|
|
|
208
222
|
readonly type: "string";
|
|
209
223
|
};
|
|
210
224
|
};
|
|
211
|
-
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
|
|
225
|
+
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, envVarsPrefix, }: {
|
|
212
226
|
overrides?: Partial<BaseAdapterConfig> | undefined;
|
|
213
227
|
customSettings?: SettingsMap | undefined;
|
|
228
|
+
envVarsPrefix?: string | undefined;
|
|
214
229
|
}) => AdapterConfig<CustomSettings>;
|
|
230
|
+
export declare const validateAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>(adapterConfig: AdapterConfig<CustomSettings>, customSettings?: SettingsMap) => void;
|
|
231
|
+
export declare const getEnv: (name: string, config: Setting, prefix?: string) => SettingValueType | null;
|
|
215
232
|
declare type SettingValueType = string | number | boolean;
|
|
216
233
|
declare type SettingType<C extends Setting> = C['type'] extends 'string' ? string : C['type'] extends 'number' ? number : C['type'] extends 'boolean' ? boolean : C['type'] extends 'enum' ? C['options'] extends readonly string[] ? C['options'][number] : never : never;
|
|
217
234
|
declare type BaseSettingsType = typeof BaseSettings;
|
package/config/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Import { getRandomRequiredEnv, getRandomEnv, getEnv } from '../util'
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.buildAdapterConfig = exports.BaseSettings = void 0;
|
|
3
|
+
exports.getEnv = exports.validateAdapterConfig = exports.buildAdapterConfig = exports.BaseSettings = void 0;
|
|
5
4
|
exports.BaseSettings = {
|
|
6
5
|
// V2 compat
|
|
7
6
|
// ADAPTER_URL: {
|
|
@@ -12,11 +11,6 @@ exports.BaseSettings = {
|
|
|
12
11
|
description: 'The URL that certain transports use to retrieve data',
|
|
13
12
|
type: 'string',
|
|
14
13
|
},
|
|
15
|
-
API_KEY: {
|
|
16
|
-
description: 'Default setting for an EA key',
|
|
17
|
-
type: 'string',
|
|
18
|
-
sensitive: true,
|
|
19
|
-
},
|
|
20
14
|
API_TIMEOUT: {
|
|
21
15
|
description: 'The number of milliseconds a request can be pending before returning a timeout error for data provider request',
|
|
22
16
|
type: 'number',
|
|
@@ -32,6 +26,11 @@ exports.BaseSettings = {
|
|
|
32
26
|
type: 'string',
|
|
33
27
|
default: '/',
|
|
34
28
|
},
|
|
29
|
+
BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
30
|
+
description: 'Flag to toggle batch transport setup validation',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
default: false,
|
|
33
|
+
},
|
|
35
34
|
CACHE_MAX_AGE: {
|
|
36
35
|
description: 'Maximum amount of time (in ms) that a response will stay cached',
|
|
37
36
|
type: 'number',
|
|
@@ -45,10 +44,11 @@ exports.BaseSettings = {
|
|
|
45
44
|
// type: 'number',
|
|
46
45
|
// default: 30000,
|
|
47
46
|
// },
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
48
|
+
description: 'Connection timeout for redis client',
|
|
49
|
+
type: 'number',
|
|
50
|
+
default: 15000,
|
|
51
|
+
},
|
|
52
52
|
CACHE_REDIS_HOST: {
|
|
53
53
|
description: 'Hostname for the Redis instance to be used',
|
|
54
54
|
type: 'string',
|
|
@@ -59,10 +59,11 @@ exports.BaseSettings = {
|
|
|
59
59
|
// type: 'number',
|
|
60
60
|
// default: 500,
|
|
61
61
|
// },
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
63
|
+
description: 'Max cooldown (in ms) before attempting redis reconnection',
|
|
64
|
+
type: 'number',
|
|
65
|
+
default: 3000,
|
|
66
|
+
},
|
|
66
67
|
CACHE_REDIS_PASSWORD: {
|
|
67
68
|
description: 'The password required for redis auth',
|
|
68
69
|
type: 'string',
|
|
@@ -82,9 +83,10 @@ exports.BaseSettings = {
|
|
|
82
83
|
type: 'number',
|
|
83
84
|
default: 500,
|
|
84
85
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
CACHE_REDIS_URL: {
|
|
87
|
+
description: 'The URL of the Redis server. Format: [redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]',
|
|
88
|
+
type: 'string',
|
|
89
|
+
},
|
|
88
90
|
CACHE_TYPE: {
|
|
89
91
|
description: 'The type of cache to use throughout the EA',
|
|
90
92
|
type: 'enum',
|
|
@@ -188,10 +190,11 @@ exports.BaseSettings = {
|
|
|
188
190
|
// type: 'number',
|
|
189
191
|
// default: 5,
|
|
190
192
|
// },
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
RETRY: {
|
|
194
|
+
type: 'number',
|
|
195
|
+
description: 'Retry count for failed HTTP requests',
|
|
196
|
+
default: 1,
|
|
197
|
+
},
|
|
195
198
|
SSE_SUBSCRIPTION_UPDATE_SLEEP: {
|
|
196
199
|
description: 'Maximum amount of time (in ms) between each update to the set of subscribed feeds',
|
|
197
200
|
type: 'number',
|
|
@@ -220,11 +223,6 @@ exports.BaseSettings = {
|
|
|
220
223
|
description: 'Override the base websocket URL within the EA.',
|
|
221
224
|
type: 'string',
|
|
222
225
|
},
|
|
223
|
-
WS_API_KEY: {
|
|
224
|
-
description: 'The websocket API key to authenticate with',
|
|
225
|
-
type: 'string',
|
|
226
|
-
sensitive: true,
|
|
227
|
-
},
|
|
228
226
|
WS_SUBSCRIPTION_TTL: {
|
|
229
227
|
description: '',
|
|
230
228
|
type: 'number',
|
|
@@ -290,12 +288,11 @@ exports.BaseSettings = {
|
|
|
290
288
|
type: 'string',
|
|
291
289
|
},
|
|
292
290
|
};
|
|
293
|
-
const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
|
|
294
|
-
const validationErrors = [];
|
|
291
|
+
const buildAdapterConfig = ({ overrides = {}, customSettings = {}, envVarsPrefix = '', }) => {
|
|
295
292
|
const vars = {};
|
|
296
293
|
// Iterate base adapter env vars
|
|
297
294
|
for (const [key, config] of Object.entries(exports.BaseSettings)) {
|
|
298
|
-
const value = getEnv(key, config) ?? overrides?.[key] ?? config.default;
|
|
295
|
+
const value = (0, exports.getEnv)(key, config, envVarsPrefix) ?? overrides?.[key] ?? config.default;
|
|
299
296
|
vars[key] = value;
|
|
300
297
|
}
|
|
301
298
|
// Iterate custom vars
|
|
@@ -303,28 +300,47 @@ const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
|
|
|
303
300
|
if (exports.BaseSettings[key]) {
|
|
304
301
|
throw new Error(`Custom env var "${key}" declared, but a base framework env var with that name already exists.`);
|
|
305
302
|
}
|
|
306
|
-
const value = getEnv(key, config) ?? config.default;
|
|
307
|
-
// Check if a required setting has been provided
|
|
308
|
-
if (config.required && value === null) {
|
|
309
|
-
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
310
|
-
}
|
|
311
|
-
else if (config.validate) {
|
|
312
|
-
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
313
|
-
const validationRes = config.validate(value);
|
|
314
|
-
if (validationRes) {
|
|
315
|
-
validationErrors.push(`${key}: ${validationRes}`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
303
|
+
const value = (0, exports.getEnv)(key, config, envVarsPrefix) ?? config.default;
|
|
318
304
|
vars[key] = value;
|
|
319
305
|
}
|
|
306
|
+
return vars;
|
|
307
|
+
};
|
|
308
|
+
exports.buildAdapterConfig = buildAdapterConfig;
|
|
309
|
+
const validateAdapterConfig = (adapterConfig, customSettings = {}) => {
|
|
310
|
+
const validationErrors = [];
|
|
311
|
+
Object.entries(exports.BaseSettings)
|
|
312
|
+
.concat(Object.entries(customSettings || {}))
|
|
313
|
+
.forEach(([name, setting]) => {
|
|
314
|
+
validateSetting(name, adapterConfig[name], setting, validationErrors);
|
|
315
|
+
});
|
|
320
316
|
if (validationErrors.length > 0) {
|
|
321
317
|
throw new Error(`Validation failed for the following variables:\n ${validationErrors.join('\n')}`);
|
|
322
318
|
}
|
|
323
|
-
return vars;
|
|
324
319
|
};
|
|
325
|
-
exports.
|
|
326
|
-
const
|
|
327
|
-
|
|
320
|
+
exports.validateAdapterConfig = validateAdapterConfig;
|
|
321
|
+
const validateSetting = (key, value, config, validationErrors) => {
|
|
322
|
+
// Check if a required setting has been provided
|
|
323
|
+
if (config.required && (value === null || value === undefined)) {
|
|
324
|
+
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
325
|
+
}
|
|
326
|
+
else if (config.validate) {
|
|
327
|
+
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
328
|
+
const validationRes = config.validate(value);
|
|
329
|
+
if (validationRes) {
|
|
330
|
+
validationErrors.push(`${key}: ${validationRes}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const getEnvName = (name, prefix = '') => {
|
|
335
|
+
const envName = prefix ? `${prefix}_${name}` : name;
|
|
336
|
+
if (!isEnvNameValid(envName)) {
|
|
337
|
+
throw new Error(`Invalid environment var name: ${envName}. Only '/^[_a-z0-9]+$/i' is supported.`);
|
|
338
|
+
}
|
|
339
|
+
return envName;
|
|
340
|
+
};
|
|
341
|
+
const isEnvNameValid = (name) => /^[_a-z0-9]+$/i.test(name);
|
|
342
|
+
const getEnv = (name, config, prefix = '') => {
|
|
343
|
+
const value = process.env[getEnvName(name, prefix)];
|
|
328
344
|
if (!value) {
|
|
329
345
|
return null;
|
|
330
346
|
}
|
|
@@ -342,4 +358,5 @@ const getEnv = (name, config) => {
|
|
|
342
358
|
return value;
|
|
343
359
|
}
|
|
344
360
|
};
|
|
361
|
+
exports.getEnv = getEnv;
|
|
345
362
|
//# sourceMappingURL=index.js.map
|