@chainlink/external-adapter-framework 0.0.6 → 0.0.8
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 +88 -0
- package/adapter.js +112 -0
- package/background-executor.d.ts +11 -0
- package/background-executor.js +45 -0
- package/cache/factory.d.ts +6 -0
- package/cache/factory.js +57 -0
- package/cache/index.d.ts +90 -0
- package/cache/index.js +169 -0
- package/cache/local.d.ts +23 -0
- package/cache/local.js +83 -0
- package/cache/metrics.d.ts +27 -0
- package/cache/metrics.js +120 -0
- package/cache/redis.d.ts +16 -0
- package/cache/redis.js +100 -0
- package/chainlink-external-adapter-framework-v0.0.8.tgz +0 -0
- package/config/index.d.ts +195 -0
- package/config/index.js +365 -0
- package/config/provider-limits.d.ts +31 -0
- package/config/provider-limits.js +75 -0
- package/examples/coingecko/batch-warming.d.ts +2 -0
- package/examples/coingecko/batch-warming.js +52 -0
- package/examples/coingecko/index.d.ts +2 -0
- package/examples/coingecko/index.js +10 -0
- package/examples/coingecko/rest.d.ts +2 -0
- package/examples/coingecko/rest.js +50 -0
- package/examples/ncfx/config/index.d.ts +12 -0
- package/examples/ncfx/config/index.js +15 -0
- package/examples/ncfx/index.d.ts +2 -0
- package/examples/ncfx/index.js +10 -0
- package/examples/ncfx/websocket.d.ts +36 -0
- package/examples/ncfx/websocket.js +72 -0
- package/index.d.ts +12 -0
- package/index.js +92 -0
- package/metrics/constants.d.ts +16 -0
- package/metrics/constants.js +25 -0
- package/metrics/index.d.ts +15 -0
- package/metrics/index.js +123 -0
- package/metrics/util.d.ts +3 -0
- package/metrics/util.js +9 -0
- package/package/adapter.d.ts +88 -0
- package/package/adapter.js +112 -0
- package/package/background-executor.d.ts +11 -0
- package/package/background-executor.js +45 -0
- package/package/cache/factory.d.ts +6 -0
- package/package/cache/factory.js +57 -0
- package/package/cache/index.d.ts +90 -0
- package/package/cache/index.js +169 -0
- package/package/cache/local.d.ts +23 -0
- package/package/cache/local.js +83 -0
- package/package/cache/metrics.d.ts +27 -0
- package/package/cache/metrics.js +120 -0
- package/package/cache/redis.d.ts +16 -0
- package/package/cache/redis.js +100 -0
- package/package/config/index.d.ts +195 -0
- package/package/config/index.js +365 -0
- package/package/config/provider-limits.d.ts +31 -0
- package/package/config/provider-limits.js +75 -0
- package/package/examples/coingecko/batch-warming.d.ts +2 -0
- package/package/examples/coingecko/batch-warming.js +52 -0
- package/package/examples/coingecko/index.d.ts +2 -0
- package/package/examples/coingecko/index.js +10 -0
- package/package/examples/coingecko/rest.d.ts +2 -0
- package/package/examples/coingecko/rest.js +50 -0
- package/package/examples/ncfx/config/index.d.ts +12 -0
- package/package/examples/ncfx/config/index.js +15 -0
- package/package/examples/ncfx/index.d.ts +2 -0
- package/package/examples/ncfx/index.js +10 -0
- package/package/examples/ncfx/websocket.d.ts +36 -0
- package/package/examples/ncfx/websocket.js +72 -0
- package/package/index.d.ts +12 -0
- package/package/index.js +92 -0
- package/package/metrics/constants.d.ts +16 -0
- package/package/metrics/constants.js +25 -0
- package/package/metrics/index.d.ts +15 -0
- package/package/metrics/index.js +123 -0
- package/package/metrics/util.d.ts +3 -0
- package/package/metrics/util.js +9 -0
- package/package/package.json +69 -0
- package/package/rate-limiting/background/fixed-frequency.d.ts +10 -0
- package/package/rate-limiting/background/fixed-frequency.js +37 -0
- package/package/rate-limiting/index.d.ts +54 -0
- package/package/rate-limiting/index.js +63 -0
- package/package/rate-limiting/metrics.d.ts +3 -0
- package/package/rate-limiting/metrics.js +44 -0
- package/package/rate-limiting/request/simple-counting.d.ts +20 -0
- package/package/rate-limiting/request/simple-counting.js +62 -0
- package/package/test.d.ts +1 -0
- package/package/test.js +6 -0
- package/package/transports/batch-warming.d.ts +34 -0
- package/package/transports/batch-warming.js +101 -0
- package/package/transports/index.d.ts +87 -0
- package/package/transports/index.js +87 -0
- package/package/transports/metrics.d.ts +21 -0
- package/package/transports/metrics.js +105 -0
- package/package/transports/rest.d.ts +43 -0
- package/package/transports/rest.js +129 -0
- package/package/transports/util.d.ts +8 -0
- package/package/transports/util.js +85 -0
- package/package/transports/websocket.d.ts +80 -0
- package/package/transports/websocket.js +169 -0
- package/package/util/expiring-sorted-set.d.ts +21 -0
- package/package/util/expiring-sorted-set.js +47 -0
- package/package/util/index.d.ts +11 -0
- package/package/util/index.js +35 -0
- package/package/util/logger.d.ts +42 -0
- package/package/util/logger.js +62 -0
- package/package/util/request.d.ts +55 -0
- package/package/util/request.js +2 -0
- package/package/validation/error.d.ts +50 -0
- package/package/validation/error.js +79 -0
- package/package/validation/index.d.ts +5 -0
- package/package/validation/index.js +86 -0
- package/package/validation/input-params.d.ts +15 -0
- package/package/validation/input-params.js +30 -0
- package/package/validation/override-functions.d.ts +3 -0
- package/package/validation/override-functions.js +40 -0
- package/package/validation/preset-tokens.json +23 -0
- package/package/validation/validator.d.ts +47 -0
- package/package/validation/validator.js +303 -0
- package/package.json +1 -1
- package/rate-limiting/background/fixed-frequency.d.ts +10 -0
- package/rate-limiting/background/fixed-frequency.js +37 -0
- package/rate-limiting/index.d.ts +54 -0
- package/rate-limiting/index.js +63 -0
- package/rate-limiting/metrics.d.ts +3 -0
- package/rate-limiting/metrics.js +44 -0
- package/rate-limiting/request/simple-counting.d.ts +20 -0
- package/rate-limiting/request/simple-counting.js +62 -0
- package/test.d.ts +1 -0
- package/test.js +6 -0
- package/transports/batch-warming.d.ts +34 -0
- package/transports/batch-warming.js +101 -0
- package/transports/index.d.ts +87 -0
- package/transports/index.js +87 -0
- package/transports/metrics.d.ts +21 -0
- package/transports/metrics.js +105 -0
- package/transports/rest.d.ts +43 -0
- package/transports/rest.js +129 -0
- package/transports/util.d.ts +8 -0
- package/transports/util.js +85 -0
- package/transports/websocket.d.ts +80 -0
- package/transports/websocket.js +169 -0
- package/util/expiring-sorted-set.d.ts +21 -0
- package/util/expiring-sorted-set.js +47 -0
- package/util/index.d.ts +11 -0
- package/util/index.js +35 -0
- package/util/logger.d.ts +42 -0
- package/util/logger.js +62 -0
- package/util/request.d.ts +55 -0
- package/util/request.js +2 -0
- package/validation/error.d.ts +50 -0
- package/validation/error.js +79 -0
- package/validation/index.d.ts +5 -0
- package/validation/index.js +86 -0
- package/validation/input-params.d.ts +15 -0
- package/validation/input-params.js +30 -0
- package/validation/override-functions.d.ts +3 -0
- package/validation/override-functions.js +40 -0
- package/validation/preset-tokens.json +23 -0
- package/validation/validator.d.ts +47 -0
- package/validation/validator.js +303 -0
- package/.c8rc.json +0 -3
- package/.eslintignore +0 -9
- package/.eslintrc.js +0 -96
- package/.github/README.MD +0 -17
- package/.github/actions/setup/action.yaml +0 -13
- package/.github/workflows/main.yaml +0 -39
- package/.github/workflows/publish.yaml +0 -17
- package/.prettierignore +0 -13
- package/.yarnrc +0 -0
- package/README.md +0 -103
- package/docker-compose.yaml +0 -35
- package/src/adapter.ts +0 -236
- package/src/background-executor.ts +0 -53
- package/src/cache/factory.ts +0 -28
- package/src/cache/index.ts +0 -236
- package/src/cache/local.ts +0 -73
- package/src/cache/metrics.ts +0 -112
- package/src/cache/redis.ts +0 -93
- package/src/config/index.ts +0 -501
- package/src/config/provider-limits.ts +0 -130
- package/src/examples/coingecko/batch-warming.ts +0 -79
- package/src/examples/coingecko/index.ts +0 -9
- package/src/examples/coingecko/rest.ts +0 -77
- package/src/examples/ncfx/config/index.ts +0 -12
- package/src/examples/ncfx/index.ts +0 -9
- package/src/examples/ncfx/websocket.ts +0 -100
- package/src/index.ts +0 -106
- package/src/metrics/constants.ts +0 -23
- package/src/metrics/index.ts +0 -116
- package/src/metrics/util.ts +0 -11
- package/src/rate-limiting/background/fixed-frequency.ts +0 -47
- package/src/rate-limiting/index.ts +0 -100
- package/src/rate-limiting/metrics.ts +0 -18
- package/src/rate-limiting/request/simple-counting.ts +0 -76
- package/src/test.ts +0 -5
- package/src/transports/batch-warming.ts +0 -121
- package/src/transports/index.ts +0 -173
- package/src/transports/metrics.ts +0 -95
- package/src/transports/rest.ts +0 -161
- package/src/transports/util.ts +0 -63
- package/src/transports/websocket.ts +0 -238
- package/src/util/expiring-sorted-set.ts +0 -52
- package/src/util/index.ts +0 -20
- package/src/util/logger.ts +0 -69
- package/src/util/request.ts +0 -115
- package/src/validation/error.ts +0 -116
- package/src/validation/index.ts +0 -101
- package/src/validation/input-params.ts +0 -45
- package/src/validation/override-functions.ts +0 -44
- package/src/validation/preset-tokens.json +0 -23
- package/src/validation/validator.ts +0 -384
- package/test/adapter.test.ts +0 -27
- package/test/background-executor.test.ts +0 -109
- package/test/cache/cache-key.test.ts +0 -96
- package/test/cache/helper.ts +0 -101
- package/test/cache/local.test.ts +0 -54
- package/test/cache/redis.test.ts +0 -89
- package/test/correlation.test.ts +0 -114
- package/test/index.test.ts +0 -37
- package/test/metrics/feed-id.test.ts +0 -33
- package/test/metrics/helper.ts +0 -14
- package/test/metrics/labels.test.ts +0 -36
- package/test/metrics/metrics.test.ts +0 -267
- package/test/metrics/redis-metrics.test.ts +0 -113
- package/test/metrics/warmer-metrics.test.ts +0 -192
- package/test/metrics/ws-metrics.test.ts +0 -225
- package/test/rate-limit-config.test.ts +0 -243
- package/test/transports/batch.test.ts +0 -465
- package/test/transports/rest.test.ts +0 -242
- package/test/transports/websocket.test.ts +0 -183
- package/test/tsconfig.json +0 -5
- package/test/util.ts +0 -76
- package/test/validation.test.ts +0 -169
- package/test.sh +0 -20
- package/tsconfig.json +0 -24
- package/typedoc.json +0 -6
package/src/cache/metrics.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import * as client from 'prom-client'
|
|
2
|
-
|
|
3
|
-
interface CacheMetricsLabels {
|
|
4
|
-
participant_id: string
|
|
5
|
-
feed_id: string
|
|
6
|
-
cache_type: string
|
|
7
|
-
// Is_from_ws?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const cacheGet = (label: CacheMetricsLabels, value: unknown, staleness: number) => {
|
|
11
|
-
if (typeof value === 'number' || typeof value === 'string') {
|
|
12
|
-
const parsedValue = Number(value)
|
|
13
|
-
if (!Number.isNaN(parsedValue) && Number.isFinite(parsedValue)) {
|
|
14
|
-
cacheDataGetValues.labels(label).set(parsedValue)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
cacheDataGetCount.labels(label).inc()
|
|
18
|
-
cacheDataStalenessSeconds.labels(label).set(staleness)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const cacheSet = (label: CacheMetricsLabels, maxAge: number) => {
|
|
22
|
-
cacheDataSetCount.labels(label).inc()
|
|
23
|
-
cacheDataMaxAge.labels(label).set(maxAge)
|
|
24
|
-
cacheDataStalenessSeconds.labels(label).set(0)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const cacheMetricsLabel = (cacheKey: string, feedId: string, cacheType: string) => ({
|
|
28
|
-
participant_id: cacheKey,
|
|
29
|
-
feed_id: feedId,
|
|
30
|
-
cache_type: cacheType,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
export enum CacheTypes {
|
|
34
|
-
Redis = 'redis',
|
|
35
|
-
Local = 'local',
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum CMD_SENT_STATUS {
|
|
39
|
-
TIMEOUT = 'TIMEOUT',
|
|
40
|
-
FAIL = 'FAIL',
|
|
41
|
-
SUCCESS = 'SUCCESS',
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const baseLabels = [
|
|
45
|
-
'feed_id',
|
|
46
|
-
'participant_id',
|
|
47
|
-
'cache_type',
|
|
48
|
-
'is_from_ws',
|
|
49
|
-
'experimental',
|
|
50
|
-
] as const
|
|
51
|
-
|
|
52
|
-
// Skipping this metrics for v3
|
|
53
|
-
// const cache_execution_duration_seconds = new client.Histogram({
|
|
54
|
-
// name: 'cache_execution_duration_seconds',
|
|
55
|
-
// help: 'A histogram bucket of the distribution of cache execution durations',
|
|
56
|
-
// labelNames: [...baseLabels, 'cache_hit'] as const,
|
|
57
|
-
// buckets: [0.01, 0.1, 1, 10],
|
|
58
|
-
// })
|
|
59
|
-
|
|
60
|
-
const cacheDataGetCount = new client.Counter({
|
|
61
|
-
name: 'cache_data_get_count',
|
|
62
|
-
help: 'A counter that increments every time a value is fetched from the cache',
|
|
63
|
-
labelNames: baseLabels,
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const cacheDataGetValues = new client.Gauge({
|
|
67
|
-
name: 'cache_data_get_values',
|
|
68
|
-
help: 'A gauge keeping track of values being fetched from cache',
|
|
69
|
-
labelNames: baseLabels,
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const cacheDataMaxAge = new client.Gauge({
|
|
73
|
-
name: 'cache_data_max_age',
|
|
74
|
-
help: 'A gauge tracking the max age of stored values in the cache',
|
|
75
|
-
labelNames: baseLabels,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const cacheDataSetCount = new client.Counter({
|
|
79
|
-
name: 'cache_data_set_count',
|
|
80
|
-
help: 'A counter that increments every time a value is set to the cache',
|
|
81
|
-
labelNames: [...baseLabels, 'status_code'],
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const cacheDataStalenessSeconds = new client.Gauge({
|
|
85
|
-
name: 'cache_data_staleness_seconds',
|
|
86
|
-
help: 'Observes the staleness of the data returned',
|
|
87
|
-
labelNames: baseLabels,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// Redis Metrics
|
|
91
|
-
export const redisConnectionsOpen = new client.Counter({
|
|
92
|
-
name: 'redis_connections_open',
|
|
93
|
-
help: 'The number of redis connections that are open',
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
export const redisRetriesCount = new client.Counter({
|
|
97
|
-
name: 'redis_retries_count',
|
|
98
|
-
help: 'The number of retries that have been made to establish a redis connection',
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
export const redisCommandsSentCount = new client.Counter({
|
|
102
|
-
name: 'redis_commands_sent_count',
|
|
103
|
-
help: 'The number of redis commands sent',
|
|
104
|
-
labelNames: ['status', 'function_name'],
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
// Cache Warmer Metrics
|
|
108
|
-
export const cacheWarmerCount = new client.Gauge({
|
|
109
|
-
name: 'cache_warmer_get_count',
|
|
110
|
-
help: 'The number of cache warmers running',
|
|
111
|
-
labelNames: ['isBatched'] as const,
|
|
112
|
-
})
|
package/src/cache/redis.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import Redis from 'ioredis'
|
|
2
|
-
import { AdapterResponse, makeLogger } from '../util'
|
|
3
|
-
import { Cache, CacheEntry } from './index'
|
|
4
|
-
import * as cacheMetrics from './metrics'
|
|
5
|
-
|
|
6
|
-
const logger = makeLogger('RedisCache')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Redis implementation of a Cache. It uses a simple js Object, storing entries with both
|
|
10
|
-
* a value and an expiration timestamp. Expired entries are deleted on reads (i.e. no background gc/upkeep).
|
|
11
|
-
*
|
|
12
|
-
* @typeParam T - the type for the entries' values
|
|
13
|
-
*/
|
|
14
|
-
// TODO: Add error handling for redis command failures
|
|
15
|
-
export class RedisCache<T = unknown> implements Cache<T> {
|
|
16
|
-
constructor(private client: Redis) {}
|
|
17
|
-
|
|
18
|
-
async get(key: string): Promise<T | undefined> {
|
|
19
|
-
logger.trace(`Getting key ${key}`)
|
|
20
|
-
const value = await this.client.get(key)
|
|
21
|
-
|
|
22
|
-
// Record get command sent to Redis
|
|
23
|
-
cacheMetrics.redisCommandsSentCount
|
|
24
|
-
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'get' })
|
|
25
|
-
.inc()
|
|
26
|
-
|
|
27
|
-
if (!value) {
|
|
28
|
-
logger.debug(`No entry in redis cache for key "${key}", returning undefined`)
|
|
29
|
-
return undefined
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return JSON.parse(value) as T // TODO: Check for invalid parsing
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async delete(key: string): Promise<void> {
|
|
36
|
-
logger.trace(`Deleting key ${key}`)
|
|
37
|
-
await this.client.del(key)
|
|
38
|
-
|
|
39
|
-
// Record delete command sent to Redis
|
|
40
|
-
cacheMetrics.redisCommandsSentCount
|
|
41
|
-
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'delete' })
|
|
42
|
-
.inc()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async set(key: string, value: T, ttl: number): Promise<void> {
|
|
46
|
-
logger.trace(`Setting key ${key}`)
|
|
47
|
-
// TODO: Check for invalid stringify
|
|
48
|
-
await this.client.set(key, JSON.stringify(value), 'PX', ttl)
|
|
49
|
-
|
|
50
|
-
// Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
|
|
51
|
-
const feedId = (value as unknown as AdapterResponse).meta?.metrics?.feedId
|
|
52
|
-
if (feedId) {
|
|
53
|
-
// Record cache set count, max age, and staleness (set to 0 for cache set)
|
|
54
|
-
const label = cacheMetrics.cacheMetricsLabel(key, feedId, cacheMetrics.CacheTypes.Redis)
|
|
55
|
-
cacheMetrics.cacheSet(label, ttl)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Record set command sent to Redis
|
|
59
|
-
cacheMetrics.redisCommandsSentCount
|
|
60
|
-
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'set' })
|
|
61
|
-
.inc()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async setMany(entries: CacheEntry<T>[], ttl: number): Promise<void> {
|
|
65
|
-
logger.trace(`Setting a bunch of keys`)
|
|
66
|
-
// Unfortunately, there's no ttl for mset
|
|
67
|
-
let chain = this.client.multi()
|
|
68
|
-
|
|
69
|
-
for (const entry of entries) {
|
|
70
|
-
chain = chain.set(entry.key, JSON.stringify(entry.value), 'PX', ttl)
|
|
71
|
-
|
|
72
|
-
// TODO: Move to after error handling once implemented to avoid recording cache sets that failed
|
|
73
|
-
// Only record metrics if feed Id is present, otherwise assuming value is not adapter response to record
|
|
74
|
-
const feedId = (entry.value as unknown as AdapterResponse).meta?.metrics?.feedId
|
|
75
|
-
if (feedId) {
|
|
76
|
-
// Record cache set count, max age, and staleness (set to 0 for cache set)
|
|
77
|
-
const label = cacheMetrics.cacheMetricsLabel(
|
|
78
|
-
entry.key,
|
|
79
|
-
feedId,
|
|
80
|
-
cacheMetrics.CacheTypes.Redis,
|
|
81
|
-
)
|
|
82
|
-
cacheMetrics.cacheSet(label, ttl)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
await chain.exec()
|
|
87
|
-
|
|
88
|
-
// Record setMany command sent to Redis
|
|
89
|
-
cacheMetrics.redisCommandsSentCount
|
|
90
|
-
.labels({ status: cacheMetrics.CMD_SENT_STATUS.SUCCESS, function_name: 'exec' })
|
|
91
|
-
.inc()
|
|
92
|
-
}
|
|
93
|
-
}
|
package/src/config/index.ts
DELETED
|
@@ -1,501 +0,0 @@
|
|
|
1
|
-
// Import { getRandomRequiredEnv, getRandomEnv, getEnv } from '../util'
|
|
2
|
-
|
|
3
|
-
export const BaseSettings = {
|
|
4
|
-
// V2 compat
|
|
5
|
-
// TODO: Remove non used in v3 ones
|
|
6
|
-
// API_ENDPOINT: {
|
|
7
|
-
// type: 'string',
|
|
8
|
-
// },
|
|
9
|
-
API_KEY: {
|
|
10
|
-
description: 'Default setting for an EA key',
|
|
11
|
-
type: 'string',
|
|
12
|
-
},
|
|
13
|
-
// API_TIMEOUT: {
|
|
14
|
-
// type: 'number',
|
|
15
|
-
// default: 30000,
|
|
16
|
-
// },
|
|
17
|
-
// API_VERBOSE: {
|
|
18
|
-
// type: 'boolean',
|
|
19
|
-
// },
|
|
20
|
-
BASE_URL: {
|
|
21
|
-
description: 'Starting path for the EA handler endpoint',
|
|
22
|
-
type: 'string',
|
|
23
|
-
default: '/',
|
|
24
|
-
},
|
|
25
|
-
// CACHE_ENABLED: {
|
|
26
|
-
// type: 'boolean',
|
|
27
|
-
// default: true,
|
|
28
|
-
// },
|
|
29
|
-
// CACHE_KEY_GROUP: {
|
|
30
|
-
// type: 'string',
|
|
31
|
-
// },
|
|
32
|
-
CACHE_MAX_AGE: {
|
|
33
|
-
description: 'Maximum amount of time (in ms) that a response will stay cached',
|
|
34
|
-
type: 'number',
|
|
35
|
-
default: 90000,
|
|
36
|
-
},
|
|
37
|
-
// CACHE_MAX_ITEMS: {
|
|
38
|
-
// type: 'number',
|
|
39
|
-
// default: 1000,
|
|
40
|
-
// },
|
|
41
|
-
// CACHE_MIN_AGE: {
|
|
42
|
-
// type: 'number',
|
|
43
|
-
// default: 30000,
|
|
44
|
-
// },
|
|
45
|
-
// CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
46
|
-
// type: 'number',
|
|
47
|
-
// default: 15000,
|
|
48
|
-
// },
|
|
49
|
-
CACHE_REDIS_HOST: {
|
|
50
|
-
description: 'Hostname for the Redis instance to be used',
|
|
51
|
-
type: 'string',
|
|
52
|
-
default: '127.0.0.1',
|
|
53
|
-
},
|
|
54
|
-
// CACHE_REDIS_MAX_QUEUED_ITEMS: {
|
|
55
|
-
// type: 'number',
|
|
56
|
-
// default: 100,
|
|
57
|
-
// },
|
|
58
|
-
// CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
59
|
-
// type: 'number',
|
|
60
|
-
// default: 3000,
|
|
61
|
-
// },
|
|
62
|
-
// CACHE_REDIS_PASSWORD: {
|
|
63
|
-
// type: 'string',
|
|
64
|
-
// },
|
|
65
|
-
// CACHE_REDIS_PATH: {
|
|
66
|
-
// type: 'string',
|
|
67
|
-
// },
|
|
68
|
-
CACHE_REDIS_PORT: {
|
|
69
|
-
description: 'Port for the Redis instance to be used',
|
|
70
|
-
type: 'number',
|
|
71
|
-
default: 6379,
|
|
72
|
-
},
|
|
73
|
-
// CACHE_REDIS_TIMEOUT: {
|
|
74
|
-
// type: 'number',
|
|
75
|
-
// default: 500,
|
|
76
|
-
// },
|
|
77
|
-
// CACHE_REDIS_URL: {
|
|
78
|
-
// type: 'string',
|
|
79
|
-
// },
|
|
80
|
-
CACHE_TYPE: {
|
|
81
|
-
description: 'The type of cache to use throughout the EA',
|
|
82
|
-
type: 'enum',
|
|
83
|
-
default: 'local',
|
|
84
|
-
options: ['local', 'redis'],
|
|
85
|
-
},
|
|
86
|
-
// CACHE_UPDATE_AGE_ON_GET: {
|
|
87
|
-
// type: 'boolean',
|
|
88
|
-
// default: false,
|
|
89
|
-
// },
|
|
90
|
-
CORRELATION_ID_ENABLED: {
|
|
91
|
-
description: 'Flag to enable correlation IDs for sent requests in logging',
|
|
92
|
-
type: 'boolean',
|
|
93
|
-
default: true,
|
|
94
|
-
},
|
|
95
|
-
// DEBUG: {
|
|
96
|
-
// type: 'boolean',
|
|
97
|
-
// },
|
|
98
|
-
// DEFAULT_WS_HEARTBEAT_INTERVAL: {
|
|
99
|
-
// type: 'number',
|
|
100
|
-
// default: 30000,
|
|
101
|
-
// },
|
|
102
|
-
EA_PORT: {
|
|
103
|
-
description:
|
|
104
|
-
'Port through which the EA will listen for REST requests (if mode is set to "reader" or "reader-writer")',
|
|
105
|
-
type: 'number',
|
|
106
|
-
default: 8080,
|
|
107
|
-
},
|
|
108
|
-
// ENV_ADAPTER_URL: {
|
|
109
|
-
// type: 'string',
|
|
110
|
-
// },
|
|
111
|
-
// ERROR_CAPACITY: {
|
|
112
|
-
// type: 'number',
|
|
113
|
-
// },
|
|
114
|
-
EXPERIMENTAL_METRICS_ENABLED: {
|
|
115
|
-
description:
|
|
116
|
-
'Flag to specify whether or not to collect metrics. Used as fallback for METRICS_ENABLED',
|
|
117
|
-
type: 'boolean',
|
|
118
|
-
default: true,
|
|
119
|
-
},
|
|
120
|
-
// LEGACY_ENV_ADAPTER_URL: {
|
|
121
|
-
// type: 'string',
|
|
122
|
-
// },
|
|
123
|
-
LOG_LEVEL: {
|
|
124
|
-
description: 'Minimum level required for logs to be output',
|
|
125
|
-
type: 'string',
|
|
126
|
-
default: 'info',
|
|
127
|
-
},
|
|
128
|
-
METRICS_ENABLED: {
|
|
129
|
-
description: 'Flag to specify whether or not to startup the metrics server',
|
|
130
|
-
type: 'boolean',
|
|
131
|
-
default: true,
|
|
132
|
-
},
|
|
133
|
-
METRICS_NAME: {
|
|
134
|
-
description: 'Metrics name',
|
|
135
|
-
type: 'string',
|
|
136
|
-
},
|
|
137
|
-
METRICS_PORT: {
|
|
138
|
-
description: 'Port metrics will be exposed to',
|
|
139
|
-
type: 'number',
|
|
140
|
-
default: 9080,
|
|
141
|
-
},
|
|
142
|
-
METRICS_USE_BASE_URL: {
|
|
143
|
-
description: 'Flag to specify whether or not to prepend the BASE_URL to the metrics endpoint',
|
|
144
|
-
type: 'boolean',
|
|
145
|
-
},
|
|
146
|
-
RATE_LIMIT_API_TIER: {
|
|
147
|
-
description:
|
|
148
|
-
'Rate limiting tier to use from the available options for the adapter. If not present, the adapter will run using the first tier on the list.',
|
|
149
|
-
type: 'string',
|
|
150
|
-
},
|
|
151
|
-
// RATE_LIMIT_CAPACITY_MINUTE: {
|
|
152
|
-
// type: 'number',
|
|
153
|
-
// },
|
|
154
|
-
// RATE_LIMIT_CAPACITY_SECOND: {
|
|
155
|
-
// type: 'number',
|
|
156
|
-
// },
|
|
157
|
-
// RATE_LIMIT_CAPACITY: {
|
|
158
|
-
// type: 'number',
|
|
159
|
-
// },
|
|
160
|
-
// RATE_LIMIT_ENABLED: {
|
|
161
|
-
// type: 'boolean',
|
|
162
|
-
// default: true,
|
|
163
|
-
// },
|
|
164
|
-
// RECORD: {
|
|
165
|
-
// type: 'boolean',
|
|
166
|
-
// },
|
|
167
|
-
// REQUEST_COALESCING_ENABLED: {
|
|
168
|
-
// type: 'boolean',
|
|
169
|
-
// },
|
|
170
|
-
// REQUEST_COALESCING_ENTROPY_MAX: {
|
|
171
|
-
// type: 'number',
|
|
172
|
-
// default: 0,
|
|
173
|
-
// },
|
|
174
|
-
// REQUEST_COALESCING_INTERVAL_COEFFICIENT: {
|
|
175
|
-
// type: 'number',
|
|
176
|
-
// default: 2,
|
|
177
|
-
// },
|
|
178
|
-
// REQUEST_COALESCING_INTERVAL_MAX: {
|
|
179
|
-
// type: 'number',
|
|
180
|
-
// default: 1000,
|
|
181
|
-
// },
|
|
182
|
-
// REQUEST_COALESCING_INTERVAL: {
|
|
183
|
-
// type: 'number',
|
|
184
|
-
// default: 100,
|
|
185
|
-
// },
|
|
186
|
-
// REQUEST_COALESCING_MAX_RETRIES: {
|
|
187
|
-
// type: 'number',
|
|
188
|
-
// default: 5,
|
|
189
|
-
// },
|
|
190
|
-
// RETRY: {
|
|
191
|
-
// type: 'boolean',
|
|
192
|
-
// default: 1,
|
|
193
|
-
// },
|
|
194
|
-
// SERVER_RATE_LIMIT_MAX: {
|
|
195
|
-
// type: 'number',
|
|
196
|
-
// default: 250,
|
|
197
|
-
// },
|
|
198
|
-
// SERVER_SLOW_DOWN_AFTER_FACTOR: {
|
|
199
|
-
// type: 'number',
|
|
200
|
-
// default: 0.8,
|
|
201
|
-
// },
|
|
202
|
-
// SERVER_SLOW_DOWN_DELAY_MS: {
|
|
203
|
-
// type: 'number',
|
|
204
|
-
// default: 500,
|
|
205
|
-
// },
|
|
206
|
-
// TIMEOUT: {
|
|
207
|
-
// type: 'number',
|
|
208
|
-
// },
|
|
209
|
-
// WARMUP_ENABLED: {
|
|
210
|
-
// type: 'boolean',
|
|
211
|
-
// default: true,
|
|
212
|
-
// },
|
|
213
|
-
// WARMUP_INTERVAL: {
|
|
214
|
-
// type: 'number',
|
|
215
|
-
// },
|
|
216
|
-
WARMUP_SUBSCRIPTION_TTL: {
|
|
217
|
-
type: 'number',
|
|
218
|
-
description: '',
|
|
219
|
-
default: 10000,
|
|
220
|
-
},
|
|
221
|
-
// WARMUP_UNHEALTHY_THRESHOLD: {
|
|
222
|
-
// type: 'number',
|
|
223
|
-
// default: 3,
|
|
224
|
-
// },
|
|
225
|
-
// WS_API_ENDPOINT: {
|
|
226
|
-
// type: 'string',
|
|
227
|
-
// },
|
|
228
|
-
// WS_API_KEY: {
|
|
229
|
-
// type: 'string',
|
|
230
|
-
// },
|
|
231
|
-
// WS_CONNECTION_KEY: {
|
|
232
|
-
// type: 'string',
|
|
233
|
-
// default: 1,
|
|
234
|
-
// },
|
|
235
|
-
// WS_CONNECTION_LIMIT: {
|
|
236
|
-
// type: 'number',
|
|
237
|
-
// default: 1,
|
|
238
|
-
// },
|
|
239
|
-
// WS_CONNECTION_RETRY_DELAY: {
|
|
240
|
-
// type: 'number',
|
|
241
|
-
// default: 1000,
|
|
242
|
-
// },
|
|
243
|
-
// WS_CONNECTION_RETRY_LIMIT: {
|
|
244
|
-
// type: 'number',
|
|
245
|
-
// default: 3,
|
|
246
|
-
// },
|
|
247
|
-
// WS_CONNECTION_TTL: {
|
|
248
|
-
// type: 'number',
|
|
249
|
-
// default: 70000,
|
|
250
|
-
// },
|
|
251
|
-
// WS_ENABLED: {
|
|
252
|
-
// type: 'boolean',
|
|
253
|
-
// default: false,
|
|
254
|
-
// },
|
|
255
|
-
// WS_SUBSCRIPTION_LIMIT: {
|
|
256
|
-
// type: 'number',
|
|
257
|
-
// default: 10,
|
|
258
|
-
// },
|
|
259
|
-
// WS_SUBSCRIPTION_PRIORITY_LIST: {
|
|
260
|
-
// type: 'string',
|
|
261
|
-
// },
|
|
262
|
-
// WS_SUBSCRIPTION_TTL: {
|
|
263
|
-
// type: 'number',
|
|
264
|
-
// default: 120000,
|
|
265
|
-
// },
|
|
266
|
-
// WS_SUBSCRIPTION_UNRESPONSIVE_TTL: {
|
|
267
|
-
// type: 'number',
|
|
268
|
-
// default: false,
|
|
269
|
-
// },
|
|
270
|
-
// WS_TIME_UNTIL_HANDLE_NEXT_MESSAGE_OVERRIDE: {
|
|
271
|
-
// type: 'number',
|
|
272
|
-
// },
|
|
273
|
-
|
|
274
|
-
// V3
|
|
275
|
-
CACHE_POLLING_MAX_RETRIES: {
|
|
276
|
-
description:
|
|
277
|
-
'Max amount of times to attempt to find EA response in the cache after the Transport has been set up',
|
|
278
|
-
type: 'number',
|
|
279
|
-
default: 10,
|
|
280
|
-
},
|
|
281
|
-
CACHE_POLLING_SLEEP_MS: {
|
|
282
|
-
description:
|
|
283
|
-
'The number of ms to sleep between each retry to fetch the EA response in the cache',
|
|
284
|
-
type: 'number',
|
|
285
|
-
default: 200,
|
|
286
|
-
},
|
|
287
|
-
DEFAULT_CACHE_KEY: {
|
|
288
|
-
description: 'Default key to be used when one cannot be determined from request parameters',
|
|
289
|
-
type: 'string',
|
|
290
|
-
default: 'DEFAULT_CACHE_KEY',
|
|
291
|
-
},
|
|
292
|
-
EA_HOST: {
|
|
293
|
-
description:
|
|
294
|
-
'Host this EA will listen for REST requests on (if mode is set to "reader" or "reader-writer")',
|
|
295
|
-
type: 'string',
|
|
296
|
-
default: '::',
|
|
297
|
-
},
|
|
298
|
-
EA_MODE: {
|
|
299
|
-
description:
|
|
300
|
-
'Port this EA will listen for REST requests on (if mode is set to "reader" or "reader-writer")',
|
|
301
|
-
type: 'enum',
|
|
302
|
-
default: 'reader-writer',
|
|
303
|
-
options: ['reader', 'writer', 'reader-writer'],
|
|
304
|
-
},
|
|
305
|
-
REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
|
|
306
|
-
description:
|
|
307
|
-
'Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter',
|
|
308
|
-
type: 'number',
|
|
309
|
-
default: 3,
|
|
310
|
-
},
|
|
311
|
-
REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
|
|
312
|
-
description:
|
|
313
|
-
'Time that the Rest Transport will wait between retries when blocked by the rate limiter',
|
|
314
|
-
type: 'number',
|
|
315
|
-
default: 400,
|
|
316
|
-
},
|
|
317
|
-
// CACHE_KEY_IGNORED_PROPS : {
|
|
318
|
-
// description: 'Properties to ignore when generating a feed ID for requests',
|
|
319
|
-
// type: 'string'
|
|
320
|
-
// }
|
|
321
|
-
} as const
|
|
322
|
-
|
|
323
|
-
export const buildAdapterConfig = <
|
|
324
|
-
CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings,
|
|
325
|
-
>({
|
|
326
|
-
overrides = {} as Partial<BaseAdapterConfig>,
|
|
327
|
-
customSettings = {} as SettingsMap,
|
|
328
|
-
}): AdapterConfig<CustomSettings> => {
|
|
329
|
-
const validationErrors = [] as string[]
|
|
330
|
-
const vars = {} as Record<string, SettingValueType | undefined>
|
|
331
|
-
|
|
332
|
-
// Iterate base adapter env vars
|
|
333
|
-
for (const [key, config] of Object.entries(BaseSettings) as Array<
|
|
334
|
-
[keyof BaseAdapterConfig, Setting]
|
|
335
|
-
>) {
|
|
336
|
-
const value = getEnv(key as string, config) ?? overrides?.[key] ?? config.default
|
|
337
|
-
vars[key] = value
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Iterate custom vars
|
|
341
|
-
for (const [key, config] of Object.entries(customSettings) as Array<[string, Setting]>) {
|
|
342
|
-
if ((BaseSettings as Record<string, unknown>)[key as string]) {
|
|
343
|
-
throw new Error(
|
|
344
|
-
`Custom env var "${key}" declared, but a base framework env var with that name already exists.`,
|
|
345
|
-
)
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const value = getEnv(key as string, config) ?? config.default
|
|
349
|
-
|
|
350
|
-
// Check if a required setting has been provided
|
|
351
|
-
if (config.required && value === null) {
|
|
352
|
-
validationErrors.push(`${key}: Value is required, but none was provided`)
|
|
353
|
-
} else if (config.validate) {
|
|
354
|
-
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
355
|
-
const validationRes = (
|
|
356
|
-
config.validate as unknown as (value?: SettingValueType) => ValidationErrorMessage
|
|
357
|
-
)(value)
|
|
358
|
-
if (validationRes) {
|
|
359
|
-
validationErrors.push(`${key}: ${validationRes}`)
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
vars[key] = value
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (validationErrors.length > 0) {
|
|
366
|
-
throw new Error(
|
|
367
|
-
`Validation failed for the following variables:\n ${validationErrors.join('\n')}`,
|
|
368
|
-
)
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return vars as AdapterConfig<CustomSettings>
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const getEnv = (name: string, config: Setting): SettingValueType | null => {
|
|
375
|
-
const value = process.env[name]
|
|
376
|
-
if (!value) {
|
|
377
|
-
return null
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
switch (config.type) {
|
|
381
|
-
case 'string':
|
|
382
|
-
return value
|
|
383
|
-
case 'number':
|
|
384
|
-
return parseInt(value)
|
|
385
|
-
case 'boolean':
|
|
386
|
-
return value === 'true'
|
|
387
|
-
case 'enum':
|
|
388
|
-
if (!config.options?.includes(value)) {
|
|
389
|
-
throw new Error(
|
|
390
|
-
`Env var "${name}" has value "${value}" which is not included in the valid options (${config.options})`,
|
|
391
|
-
)
|
|
392
|
-
}
|
|
393
|
-
return value
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
type SettingValueType = string | number | boolean
|
|
398
|
-
type SettingType<C extends Setting> = C['type'] extends 'string'
|
|
399
|
-
? string
|
|
400
|
-
: C['type'] extends 'number'
|
|
401
|
-
? number
|
|
402
|
-
: C['type'] extends 'boolean'
|
|
403
|
-
? boolean
|
|
404
|
-
: C['type'] extends 'enum'
|
|
405
|
-
? C['options'] extends readonly string[]
|
|
406
|
-
? C['options'][number]
|
|
407
|
-
: never
|
|
408
|
-
: never
|
|
409
|
-
type BaseSettingsType = typeof BaseSettings
|
|
410
|
-
export type Setting =
|
|
411
|
-
| {
|
|
412
|
-
type: 'string'
|
|
413
|
-
description: string
|
|
414
|
-
options?: never
|
|
415
|
-
default?: string
|
|
416
|
-
validate?: (value?: string) => ValidationErrorMessage
|
|
417
|
-
required?: false
|
|
418
|
-
}
|
|
419
|
-
| {
|
|
420
|
-
type: 'string'
|
|
421
|
-
description: string
|
|
422
|
-
options?: never
|
|
423
|
-
default?: string
|
|
424
|
-
validate?: (value: string) => ValidationErrorMessage
|
|
425
|
-
required: true
|
|
426
|
-
}
|
|
427
|
-
| {
|
|
428
|
-
type: 'number'
|
|
429
|
-
description: string
|
|
430
|
-
options?: never
|
|
431
|
-
default?: number
|
|
432
|
-
validate?: (value?: number) => ValidationErrorMessage
|
|
433
|
-
required?: false
|
|
434
|
-
}
|
|
435
|
-
| {
|
|
436
|
-
type: 'number'
|
|
437
|
-
description: string
|
|
438
|
-
options?: never
|
|
439
|
-
default?: number
|
|
440
|
-
validate?: (value: number) => ValidationErrorMessage
|
|
441
|
-
required: true
|
|
442
|
-
}
|
|
443
|
-
| {
|
|
444
|
-
type: 'boolean'
|
|
445
|
-
description: string
|
|
446
|
-
options?: never
|
|
447
|
-
default?: boolean
|
|
448
|
-
validate?: (value?: boolean) => ValidationErrorMessage
|
|
449
|
-
required?: false
|
|
450
|
-
}
|
|
451
|
-
| {
|
|
452
|
-
type: 'boolean'
|
|
453
|
-
description: string
|
|
454
|
-
options?: never
|
|
455
|
-
default?: boolean
|
|
456
|
-
validate?: (value: boolean) => ValidationErrorMessage
|
|
457
|
-
required: true
|
|
458
|
-
}
|
|
459
|
-
| {
|
|
460
|
-
type: 'enum'
|
|
461
|
-
description: string
|
|
462
|
-
default?: string
|
|
463
|
-
options: readonly string[]
|
|
464
|
-
validate?: (value?: string) => ValidationErrorMessage
|
|
465
|
-
required?: false
|
|
466
|
-
}
|
|
467
|
-
| {
|
|
468
|
-
type: 'enum'
|
|
469
|
-
description: string
|
|
470
|
-
default?: string
|
|
471
|
-
options: readonly string[]
|
|
472
|
-
validate?: (value: string) => ValidationErrorMessage
|
|
473
|
-
required: true
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
export type AdapterConfigFromSettings<T extends SettingsMap> = {
|
|
477
|
-
-readonly [K in keyof T as T[K] extends {
|
|
478
|
-
default: SettingValueType
|
|
479
|
-
}
|
|
480
|
-
? K
|
|
481
|
-
: T[K]['required'] extends true
|
|
482
|
-
? K
|
|
483
|
-
: never]: SettingType<T[K]>
|
|
484
|
-
} & {
|
|
485
|
-
-readonly [K in keyof T as T[K] extends {
|
|
486
|
-
default: SettingValueType
|
|
487
|
-
}
|
|
488
|
-
? never
|
|
489
|
-
: T[K]['required'] extends true
|
|
490
|
-
? never
|
|
491
|
-
: K]?: SettingType<T[K]> | undefined
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export type BaseAdapterConfig = AdapterConfigFromSettings<BaseSettingsType>
|
|
495
|
-
export type AdapterConfig<T extends CustomSettingsType<T> = SettingsMap> =
|
|
496
|
-
AdapterConfigFromSettings<T> & BaseAdapterConfig
|
|
497
|
-
|
|
498
|
-
export type CustomSettingsType<T = SettingsMap> = Record<keyof T, Setting>
|
|
499
|
-
export type EmptySettings = Record<string, never>
|
|
500
|
-
export type SettingsMap = Record<string, Setting>
|
|
501
|
-
export type ValidationErrorMessage = string | undefined
|