@chainlink/external-adapter-framework 0.0.12 → 0.0.15

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.
Files changed (220) hide show
  1. package/.eslintignore +1 -0
  2. package/.github/README.MD +35 -10
  3. package/.github/workflows/label.yaml +39 -0
  4. package/.github/workflows/publish.yaml +0 -3
  5. package/dist/examples/coingecko/test/e2e/adapter.test.ts.js +82953 -0
  6. package/dist/examples/coingecko/test/integration/adapter.test.ts.js +91672 -0
  7. package/dist/main.js +72703 -0
  8. package/jest.config.js +5 -0
  9. package/package.json +14 -3
  10. package/src/config/provider-limits.ts +14 -17
  11. package/src/examples/coingecko/src/config/index.ts +12 -0
  12. package/src/examples/coingecko/src/config/overrides.json +10826 -0
  13. package/src/examples/coingecko/src/cryptoUtils.ts +88 -0
  14. package/src/examples/coingecko/src/endpoint/coins.ts +54 -0
  15. package/src/examples/coingecko/src/endpoint/crypto-marketcap.ts +66 -0
  16. package/src/examples/coingecko/src/endpoint/crypto-volume.ts +66 -0
  17. package/src/examples/coingecko/src/endpoint/crypto.ts +63 -0
  18. package/src/examples/coingecko/src/endpoint/dominance.ts +40 -0
  19. package/src/examples/coingecko/src/endpoint/global-marketcap.ts +40 -0
  20. package/src/examples/coingecko/src/endpoint/index.ts +6 -0
  21. package/src/examples/coingecko/src/globalUtils.ts +78 -0
  22. package/src/examples/coingecko/src/index.ts +17 -0
  23. package/src/examples/coingecko/test/e2e/adapter.test.ts +278 -0
  24. package/src/examples/coingecko/test/integration/__snapshots__/adapter.test.ts.snap +15 -0
  25. package/src/examples/coingecko/test/integration/adapter.test.ts +281 -0
  26. package/src/examples/coingecko/test/integration/capturedRequests.json +1 -0
  27. package/src/examples/coingecko/test/integration/fixtures.ts +42 -0
  28. package/src/examples/{coingecko → coingecko-old}/batch-warming.ts +1 -0
  29. package/src/examples/{coingecko → coingecko-old}/index.ts +0 -0
  30. package/src/examples/{coingecko → coingecko-old}/rest.ts +0 -0
  31. package/src/transports/batch-warming.ts +7 -2
  32. package/src/transports/rest.ts +5 -1
  33. package/src/util/index.ts +1 -0
  34. package/src/util/recordRequests.ts +47 -0
  35. package/src/validation/overrideFunctions.ts +44 -0
  36. package/test/metrics/warmer-metrics.test.ts +1 -0
  37. package/test/{smoke.test.ts → smoke/smoke.test.ts} +13 -13
  38. package/{test-payload-fail.json → test/smoke/test-payload-fail.json} +0 -0
  39. package/{test-payload.js → test/smoke/test-payload.js} +0 -0
  40. package/{test-payload.json → test/smoke/test-payload.json} +0 -0
  41. package/test/transports/batch.test.ts +1 -0
  42. package/tsconfig.json +4 -1
  43. package/webpack.config.js +39 -5
  44. package/yarn-error.log +3778 -0
  45. package/dist/src/adapter.d.ts +0 -135
  46. package/dist/src/adapter.js +0 -145
  47. package/dist/src/background-executor.d.ts +0 -11
  48. package/dist/src/background-executor.js +0 -45
  49. package/dist/src/cache/factory.d.ts +0 -6
  50. package/dist/src/cache/factory.js +0 -55
  51. package/dist/src/cache/index.d.ts +0 -94
  52. package/dist/src/cache/index.js +0 -173
  53. package/dist/src/cache/local.d.ts +0 -23
  54. package/dist/src/cache/local.js +0 -83
  55. package/dist/src/cache/metrics.d.ts +0 -27
  56. package/dist/src/cache/metrics.js +0 -120
  57. package/dist/src/cache/redis.d.ts +0 -16
  58. package/dist/src/cache/redis.js +0 -100
  59. package/dist/src/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
  60. package/dist/src/config/index.d.ts +0 -214
  61. package/dist/src/config/index.js +0 -380
  62. package/dist/src/config/provider-limits.d.ts +0 -31
  63. package/dist/src/config/provider-limits.js +0 -75
  64. package/dist/src/examples/bank-frick/accounts.d.ts +0 -39
  65. package/dist/src/examples/bank-frick/accounts.js +0 -192
  66. package/dist/src/examples/bank-frick/config/index.d.ts +0 -4
  67. package/dist/src/examples/bank-frick/config/index.js +0 -54
  68. package/dist/src/examples/bank-frick/index.d.ts +0 -2
  69. package/dist/src/examples/bank-frick/index.js +0 -15
  70. package/dist/src/examples/bank-frick/util.d.ts +0 -4
  71. package/dist/src/examples/bank-frick/util.js +0 -39
  72. package/dist/src/examples/coingecko/batch-warming.d.ts +0 -7
  73. package/dist/src/examples/coingecko/batch-warming.js +0 -53
  74. package/dist/src/examples/coingecko/index.d.ts +0 -2
  75. package/dist/src/examples/coingecko/index.js +0 -11
  76. package/dist/src/examples/coingecko/rest.d.ts +0 -12
  77. package/dist/src/examples/coingecko/rest.js +0 -51
  78. package/dist/src/examples/ncfx/config/index.d.ts +0 -12
  79. package/dist/src/examples/ncfx/config/index.js +0 -15
  80. package/dist/src/examples/ncfx/index.d.ts +0 -13
  81. package/dist/src/examples/ncfx/index.js +0 -11
  82. package/dist/src/examples/ncfx/websocket.d.ts +0 -47
  83. package/dist/src/examples/ncfx/websocket.js +0 -73
  84. package/dist/src/index.d.ts +0 -11
  85. package/dist/src/index.js +0 -128
  86. package/dist/src/metrics/constants.d.ts +0 -16
  87. package/dist/src/metrics/constants.js +0 -25
  88. package/dist/src/metrics/index.d.ts +0 -15
  89. package/dist/src/metrics/index.js +0 -122
  90. package/dist/src/metrics/util.d.ts +0 -7
  91. package/dist/src/metrics/util.js +0 -9
  92. package/dist/src/package/adapter.d.ts +0 -88
  93. package/dist/src/package/adapter.js +0 -112
  94. package/dist/src/package/background-executor.d.ts +0 -11
  95. package/dist/src/package/background-executor.js +0 -45
  96. package/dist/src/package/cache/factory.d.ts +0 -6
  97. package/dist/src/package/cache/factory.js +0 -57
  98. package/dist/src/package/cache/index.d.ts +0 -90
  99. package/dist/src/package/cache/index.js +0 -169
  100. package/dist/src/package/cache/local.d.ts +0 -23
  101. package/dist/src/package/cache/local.js +0 -83
  102. package/dist/src/package/cache/metrics.d.ts +0 -27
  103. package/dist/src/package/cache/metrics.js +0 -120
  104. package/dist/src/package/cache/redis.d.ts +0 -16
  105. package/dist/src/package/cache/redis.js +0 -100
  106. package/dist/src/package/config/index.d.ts +0 -195
  107. package/dist/src/package/config/index.js +0 -365
  108. package/dist/src/package/config/provider-limits.d.ts +0 -31
  109. package/dist/src/package/config/provider-limits.js +0 -76
  110. package/dist/src/package/examples/coingecko/batch-warming.d.ts +0 -2
  111. package/dist/src/package/examples/coingecko/batch-warming.js +0 -52
  112. package/dist/src/package/examples/coingecko/index.d.ts +0 -2
  113. package/dist/src/package/examples/coingecko/index.js +0 -10
  114. package/dist/src/package/examples/coingecko/rest.d.ts +0 -2
  115. package/dist/src/package/examples/coingecko/rest.js +0 -50
  116. package/dist/src/package/examples/ncfx/config/index.d.ts +0 -12
  117. package/dist/src/package/examples/ncfx/config/index.js +0 -15
  118. package/dist/src/package/examples/ncfx/index.d.ts +0 -2
  119. package/dist/src/package/examples/ncfx/index.js +0 -10
  120. package/dist/src/package/examples/ncfx/websocket.d.ts +0 -36
  121. package/dist/src/package/examples/ncfx/websocket.js +0 -72
  122. package/dist/src/package/index.d.ts +0 -12
  123. package/dist/src/package/index.js +0 -92
  124. package/dist/src/package/metrics/constants.d.ts +0 -16
  125. package/dist/src/package/metrics/constants.js +0 -25
  126. package/dist/src/package/metrics/index.d.ts +0 -15
  127. package/dist/src/package/metrics/index.js +0 -123
  128. package/dist/src/package/metrics/util.d.ts +0 -3
  129. package/dist/src/package/metrics/util.js +0 -9
  130. package/dist/src/package/package.json +0 -72
  131. package/dist/src/package/rate-limiting/background/fixed-frequency.d.ts +0 -10
  132. package/dist/src/package/rate-limiting/background/fixed-frequency.js +0 -37
  133. package/dist/src/package/rate-limiting/index.d.ts +0 -54
  134. package/dist/src/package/rate-limiting/index.js +0 -63
  135. package/dist/src/package/rate-limiting/metrics.d.ts +0 -3
  136. package/dist/src/package/rate-limiting/metrics.js +0 -44
  137. package/dist/src/package/rate-limiting/request/simple-counting.d.ts +0 -20
  138. package/dist/src/package/rate-limiting/request/simple-counting.js +0 -62
  139. package/dist/src/package/test.d.ts +0 -1
  140. package/dist/src/package/test.js +0 -6
  141. package/dist/src/package/transports/batch-warming.d.ts +0 -34
  142. package/dist/src/package/transports/batch-warming.js +0 -101
  143. package/dist/src/package/transports/index.d.ts +0 -87
  144. package/dist/src/package/transports/index.js +0 -87
  145. package/dist/src/package/transports/metrics.d.ts +0 -21
  146. package/dist/src/package/transports/metrics.js +0 -105
  147. package/dist/src/package/transports/rest.d.ts +0 -43
  148. package/dist/src/package/transports/rest.js +0 -129
  149. package/dist/src/package/transports/util.d.ts +0 -8
  150. package/dist/src/package/transports/util.js +0 -85
  151. package/dist/src/package/transports/websocket.d.ts +0 -80
  152. package/dist/src/package/transports/websocket.js +0 -169
  153. package/dist/src/package/util/expiring-sorted-set.d.ts +0 -21
  154. package/dist/src/package/util/expiring-sorted-set.js +0 -47
  155. package/dist/src/package/util/index.d.ts +0 -11
  156. package/dist/src/package/util/index.js +0 -35
  157. package/dist/src/package/util/logger.d.ts +0 -42
  158. package/dist/src/package/util/logger.js +0 -62
  159. package/dist/src/package/util/request.d.ts +0 -55
  160. package/dist/src/package/util/request.js +0 -2
  161. package/dist/src/package/validation/error.d.ts +0 -50
  162. package/dist/src/package/validation/error.js +0 -79
  163. package/dist/src/package/validation/index.d.ts +0 -5
  164. package/dist/src/package/validation/index.js +0 -86
  165. package/dist/src/package/validation/input-params.d.ts +0 -15
  166. package/dist/src/package/validation/input-params.js +0 -30
  167. package/dist/src/package/validation/override-functions.d.ts +0 -3
  168. package/dist/src/package/validation/override-functions.js +0 -40
  169. package/dist/src/package/validation/preset-tokens.json +0 -23
  170. package/dist/src/package/validation/validator.d.ts +0 -47
  171. package/dist/src/package/validation/validator.js +0 -303
  172. package/dist/src/package.json +0 -72
  173. package/dist/src/rate-limiting/background/fixed-frequency.d.ts +0 -11
  174. package/dist/src/rate-limiting/background/fixed-frequency.js +0 -35
  175. package/dist/src/rate-limiting/index.d.ts +0 -55
  176. package/dist/src/rate-limiting/index.js +0 -63
  177. package/dist/src/rate-limiting/metrics.d.ts +0 -3
  178. package/dist/src/rate-limiting/metrics.js +0 -44
  179. package/dist/src/rate-limiting/request/simple-counting.d.ts +0 -21
  180. package/dist/src/rate-limiting/request/simple-counting.js +0 -62
  181. package/dist/src/test.d.ts +0 -1
  182. package/dist/src/test.js +0 -6
  183. package/dist/src/transports/batch-warming.d.ts +0 -35
  184. package/dist/src/transports/batch-warming.js +0 -101
  185. package/dist/src/transports/index.d.ts +0 -70
  186. package/dist/src/transports/index.js +0 -87
  187. package/dist/src/transports/metrics.d.ts +0 -22
  188. package/dist/src/transports/metrics.js +0 -105
  189. package/dist/src/transports/rest.d.ts +0 -44
  190. package/dist/src/transports/rest.js +0 -131
  191. package/dist/src/transports/util.d.ts +0 -8
  192. package/dist/src/transports/util.js +0 -85
  193. package/dist/src/transports/websocket.d.ts +0 -80
  194. package/dist/src/transports/websocket.js +0 -166
  195. package/dist/src/util/expiring-sorted-set.d.ts +0 -21
  196. package/dist/src/util/expiring-sorted-set.js +0 -47
  197. package/dist/src/util/index.d.ts +0 -12
  198. package/dist/src/util/index.js +0 -35
  199. package/dist/src/util/logger.d.ts +0 -42
  200. package/dist/src/util/logger.js +0 -62
  201. package/dist/src/util/request.d.ts +0 -57
  202. package/dist/src/util/request.js +0 -2
  203. package/dist/src/util/subscription-set/expiring-sorted-set.d.ts +0 -22
  204. package/dist/src/util/subscription-set/expiring-sorted-set.js +0 -47
  205. package/dist/src/util/subscription-set/subscription-set.d.ts +0 -18
  206. package/dist/src/util/subscription-set/subscription-set.js +0 -19
  207. package/dist/src/util/test-payload-loader.d.ts +0 -25
  208. package/dist/src/util/test-payload-loader.js +0 -83
  209. package/dist/src/validation/error.d.ts +0 -50
  210. package/dist/src/validation/error.js +0 -79
  211. package/dist/src/validation/index.d.ts +0 -5
  212. package/dist/src/validation/index.js +0 -91
  213. package/dist/src/validation/input-params.d.ts +0 -15
  214. package/dist/src/validation/input-params.js +0 -30
  215. package/dist/src/validation/override-functions.d.ts +0 -3
  216. package/dist/src/validation/override-functions.js +0 -40
  217. package/dist/src/validation/preset-tokens.json +0 -23
  218. package/dist/src/validation/validator.d.ts +0 -47
  219. package/dist/src/validation/validator.js +0 -303
  220. package/src/test.ts +0 -5
@@ -1,195 +0,0 @@
1
- export declare const BaseSettings: {
2
- readonly API_KEY: {
3
- readonly description: "Default setting for an EA key";
4
- readonly type: "string";
5
- };
6
- readonly BASE_URL: {
7
- readonly description: "Starting path for the EA handler endpoint";
8
- readonly type: "string";
9
- readonly default: "/";
10
- };
11
- readonly CACHE_MAX_AGE: {
12
- readonly description: "Maximum amount of time (in ms) that a response will stay cached";
13
- readonly type: "number";
14
- readonly default: 90000;
15
- };
16
- readonly CACHE_REDIS_HOST: {
17
- readonly description: "Hostname for the Redis instance to be used";
18
- readonly type: "string";
19
- readonly default: "127.0.0.1";
20
- };
21
- readonly CACHE_REDIS_PORT: {
22
- readonly description: "Port for the Redis instance to be used";
23
- readonly type: "number";
24
- readonly default: 6379;
25
- };
26
- readonly CACHE_TYPE: {
27
- readonly description: "The type of cache to use throughout the EA";
28
- readonly type: "enum";
29
- readonly default: "local";
30
- readonly options: readonly ["local", "redis"];
31
- };
32
- readonly CORRELATION_ID_ENABLED: {
33
- readonly description: "Flag to enable correlation IDs for sent requests in logging";
34
- readonly type: "boolean";
35
- readonly default: true;
36
- };
37
- readonly EA_PORT: {
38
- readonly description: "Port through which the EA will listen for REST requests (if mode is set to \"reader\" or \"reader-writer\")";
39
- readonly type: "number";
40
- readonly default: 8080;
41
- };
42
- readonly EXPERIMENTAL_METRICS_ENABLED: {
43
- readonly description: "Flag to specify whether or not to collect metrics. Used as fallback for METRICS_ENABLED";
44
- readonly type: "boolean";
45
- readonly default: true;
46
- };
47
- readonly LOG_LEVEL: {
48
- readonly description: "Minimum level required for logs to be output";
49
- readonly type: "string";
50
- readonly default: "info";
51
- };
52
- readonly METRICS_ENABLED: {
53
- readonly description: "Flag to specify whether or not to startup the metrics server";
54
- readonly type: "boolean";
55
- readonly default: true;
56
- };
57
- readonly METRICS_NAME: {
58
- readonly description: "Metrics name";
59
- readonly type: "string";
60
- };
61
- readonly METRICS_PORT: {
62
- readonly description: "Port metrics will be exposed to";
63
- readonly type: "number";
64
- readonly default: 9080;
65
- };
66
- readonly METRICS_USE_BASE_URL: {
67
- readonly description: "Flag to specify whether or not to prepend the BASE_URL to the metrics endpoint";
68
- readonly type: "boolean";
69
- };
70
- readonly RATE_LIMIT_API_TIER: {
71
- readonly description: "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.";
72
- readonly type: "string";
73
- };
74
- readonly WARMUP_SUBSCRIPTION_TTL: {
75
- readonly type: "number";
76
- readonly description: "";
77
- readonly default: 10000;
78
- };
79
- readonly CACHE_POLLING_MAX_RETRIES: {
80
- readonly description: "Max amount of times to attempt to find EA response in the cache after the Transport has been set up";
81
- readonly type: "number";
82
- readonly default: 10;
83
- };
84
- readonly CACHE_POLLING_SLEEP_MS: {
85
- readonly description: "The number of ms to sleep between each retry to fetch the EA response in the cache";
86
- readonly type: "number";
87
- readonly default: 200;
88
- };
89
- readonly DEFAULT_CACHE_KEY: {
90
- readonly description: "Default key to be used when one cannot be determined from request parameters";
91
- readonly type: "string";
92
- readonly default: "DEFAULT_CACHE_KEY";
93
- };
94
- readonly EA_HOST: {
95
- readonly description: "Host this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
96
- readonly type: "string";
97
- readonly default: "::";
98
- };
99
- readonly EA_MODE: {
100
- readonly description: "Port this EA will listen for REST requests on (if mode is set to \"reader\" or \"reader-writer\")";
101
- readonly type: "enum";
102
- readonly default: "reader-writer";
103
- readonly options: readonly ["reader", "writer", "reader-writer"];
104
- };
105
- readonly REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
106
- readonly description: "Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter";
107
- readonly type: "number";
108
- readonly default: 3;
109
- };
110
- readonly REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
111
- readonly description: "Time that the Rest Transport will wait between retries when blocked by the rate limiter";
112
- readonly type: "number";
113
- readonly default: 400;
114
- };
115
- };
116
- export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
117
- overrides?: Partial<BaseAdapterConfig> | undefined;
118
- customSettings?: SettingsMap | undefined;
119
- }) => AdapterConfig<CustomSettings>;
120
- declare type SettingValueType = string | number | boolean;
121
- 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;
122
- declare type BaseSettingsType = typeof BaseSettings;
123
- export declare type Setting = {
124
- type: 'string';
125
- description: string;
126
- options?: never;
127
- default?: string;
128
- validate?: (value?: string) => ValidationErrorMessage;
129
- required?: false;
130
- } | {
131
- type: 'string';
132
- description: string;
133
- options?: never;
134
- default?: string;
135
- validate?: (value: string) => ValidationErrorMessage;
136
- required: true;
137
- } | {
138
- type: 'number';
139
- description: string;
140
- options?: never;
141
- default?: number;
142
- validate?: (value?: number) => ValidationErrorMessage;
143
- required?: false;
144
- } | {
145
- type: 'number';
146
- description: string;
147
- options?: never;
148
- default?: number;
149
- validate?: (value: number) => ValidationErrorMessage;
150
- required: true;
151
- } | {
152
- type: 'boolean';
153
- description: string;
154
- options?: never;
155
- default?: boolean;
156
- validate?: (value?: boolean) => ValidationErrorMessage;
157
- required?: false;
158
- } | {
159
- type: 'boolean';
160
- description: string;
161
- options?: never;
162
- default?: boolean;
163
- validate?: (value: boolean) => ValidationErrorMessage;
164
- required: true;
165
- } | {
166
- type: 'enum';
167
- description: string;
168
- default?: string;
169
- options: readonly string[];
170
- validate?: (value?: string) => ValidationErrorMessage;
171
- required?: false;
172
- } | {
173
- type: 'enum';
174
- description: string;
175
- default?: string;
176
- options: readonly string[];
177
- validate?: (value: string) => ValidationErrorMessage;
178
- required: true;
179
- };
180
- export declare type AdapterConfigFromSettings<T extends SettingsMap> = {
181
- -readonly [K in keyof T as T[K] extends {
182
- default: SettingValueType;
183
- } ? K : T[K]['required'] extends true ? K : never]: SettingType<T[K]>;
184
- } & {
185
- -readonly [K in keyof T as T[K] extends {
186
- default: SettingValueType;
187
- } ? never : T[K]['required'] extends true ? never : K]?: SettingType<T[K]> | undefined;
188
- };
189
- export declare type BaseAdapterConfig = AdapterConfigFromSettings<BaseSettingsType>;
190
- export declare type AdapterConfig<T extends CustomSettingsType<T> = SettingsMap> = AdapterConfigFromSettings<T> & BaseAdapterConfig;
191
- export declare type CustomSettingsType<T = SettingsMap> = Record<keyof T, Setting>;
192
- export declare type EmptySettings = Record<string, never>;
193
- export declare type SettingsMap = Record<string, Setting>;
194
- export declare type ValidationErrorMessage = string | undefined;
195
- export {};
@@ -1,365 +0,0 @@
1
- "use strict";
2
- // Import { getRandomRequiredEnv, getRandomEnv, getEnv } from '../util'
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.buildAdapterConfig = exports.BaseSettings = void 0;
5
- exports.BaseSettings = {
6
- // V2 compat
7
- // TODO: Remove non used in v3 ones
8
- // API_ENDPOINT: {
9
- // type: 'string',
10
- // },
11
- API_KEY: {
12
- description: 'Default setting for an EA key',
13
- type: 'string',
14
- },
15
- // API_TIMEOUT: {
16
- // type: 'number',
17
- // default: 30000,
18
- // },
19
- // API_VERBOSE: {
20
- // type: 'boolean',
21
- // },
22
- BASE_URL: {
23
- description: 'Starting path for the EA handler endpoint',
24
- type: 'string',
25
- default: '/',
26
- },
27
- // CACHE_ENABLED: {
28
- // type: 'boolean',
29
- // default: true,
30
- // },
31
- // CACHE_KEY_GROUP: {
32
- // type: 'string',
33
- // },
34
- CACHE_MAX_AGE: {
35
- description: 'Maximum amount of time (in ms) that a response will stay cached',
36
- type: 'number',
37
- default: 90000,
38
- },
39
- // CACHE_MAX_ITEMS: {
40
- // type: 'number',
41
- // default: 1000,
42
- // },
43
- // CACHE_MIN_AGE: {
44
- // type: 'number',
45
- // default: 30000,
46
- // },
47
- // CACHE_REDIS_CONNECTION_TIMEOUT: {
48
- // type: 'number',
49
- // default: 15000,
50
- // },
51
- CACHE_REDIS_HOST: {
52
- description: 'Hostname for the Redis instance to be used',
53
- type: 'string',
54
- default: '127.0.0.1',
55
- },
56
- // CACHE_REDIS_MAX_QUEUED_ITEMS: {
57
- // type: 'number',
58
- // default: 100,
59
- // },
60
- // CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
61
- // type: 'number',
62
- // default: 3000,
63
- // },
64
- // CACHE_REDIS_PASSWORD: {
65
- // type: 'string',
66
- // },
67
- // CACHE_REDIS_PATH: {
68
- // type: 'string',
69
- // },
70
- CACHE_REDIS_PORT: {
71
- description: 'Port for the Redis instance to be used',
72
- type: 'number',
73
- default: 6379,
74
- },
75
- // CACHE_REDIS_TIMEOUT: {
76
- // type: 'number',
77
- // default: 500,
78
- // },
79
- // CACHE_REDIS_URL: {
80
- // type: 'string',
81
- // },
82
- CACHE_TYPE: {
83
- description: 'The type of cache to use throughout the EA',
84
- type: 'enum',
85
- default: 'local',
86
- options: ['local', 'redis'],
87
- },
88
- // CACHE_UPDATE_AGE_ON_GET: {
89
- // type: 'boolean',
90
- // default: false,
91
- // },
92
- CORRELATION_ID_ENABLED: {
93
- description: 'Flag to enable correlation IDs for sent requests in logging',
94
- type: 'boolean',
95
- default: true,
96
- },
97
- // DEBUG: {
98
- // type: 'boolean',
99
- // },
100
- // DEFAULT_WS_HEARTBEAT_INTERVAL: {
101
- // type: 'number',
102
- // default: 30000,
103
- // },
104
- EA_PORT: {
105
- description: 'Port through which the EA will listen for REST requests (if mode is set to "reader" or "reader-writer")',
106
- type: 'number',
107
- default: 8080,
108
- },
109
- // ENV_ADAPTER_URL: {
110
- // type: 'string',
111
- // },
112
- // ERROR_CAPACITY: {
113
- // type: 'number',
114
- // },
115
- EXPERIMENTAL_METRICS_ENABLED: {
116
- description: '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: '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.',
148
- type: 'string',
149
- },
150
- // RATE_LIMIT_CAPACITY_MINUTE: {
151
- // type: 'number',
152
- // },
153
- // RATE_LIMIT_CAPACITY_SECOND: {
154
- // type: 'number',
155
- // },
156
- // RATE_LIMIT_CAPACITY: {
157
- // type: 'number',
158
- // },
159
- // RATE_LIMIT_ENABLED: {
160
- // type: 'boolean',
161
- // default: true,
162
- // },
163
- // RECORD: {
164
- // type: 'boolean',
165
- // },
166
- // REQUEST_COALESCING_ENABLED: {
167
- // type: 'boolean',
168
- // },
169
- // REQUEST_COALESCING_ENTROPY_MAX: {
170
- // type: 'number',
171
- // default: 0,
172
- // },
173
- // REQUEST_COALESCING_INTERVAL_COEFFICIENT: {
174
- // type: 'number',
175
- // default: 2,
176
- // },
177
- // REQUEST_COALESCING_INTERVAL_MAX: {
178
- // type: 'number',
179
- // default: 1000,
180
- // },
181
- // REQUEST_COALESCING_INTERVAL: {
182
- // type: 'number',
183
- // default: 100,
184
- // },
185
- // REQUEST_COALESCING_MAX_RETRIES: {
186
- // type: 'number',
187
- // default: 5,
188
- // },
189
- // RETRY: {
190
- // type: 'boolean',
191
- // default: 1,
192
- // },
193
- // SERVER_RATE_LIMIT_MAX: {
194
- // type: 'number',
195
- // default: 250,
196
- // },
197
- // SERVER_SLOW_DOWN_AFTER_FACTOR: {
198
- // type: 'number',
199
- // default: 0.8,
200
- // },
201
- // SERVER_SLOW_DOWN_DELAY_MS: {
202
- // type: 'number',
203
- // default: 500,
204
- // },
205
- // TIMEOUT: {
206
- // type: 'number',
207
- // },
208
- // WARMUP_ENABLED: {
209
- // type: 'boolean',
210
- // default: true,
211
- // },
212
- // WARMUP_INTERVAL: {
213
- // type: 'number',
214
- // },
215
- WARMUP_SUBSCRIPTION_TTL: {
216
- type: 'number',
217
- description: '',
218
- default: 10000,
219
- },
220
- // WARMUP_UNHEALTHY_THRESHOLD: {
221
- // type: 'number',
222
- // default: 3,
223
- // },
224
- // WS_API_ENDPOINT: {
225
- // type: 'string',
226
- // },
227
- // WS_API_KEY: {
228
- // type: 'string',
229
- // },
230
- // WS_CONNECTION_KEY: {
231
- // type: 'string',
232
- // default: 1,
233
- // },
234
- // WS_CONNECTION_LIMIT: {
235
- // type: 'number',
236
- // default: 1,
237
- // },
238
- // WS_CONNECTION_RETRY_DELAY: {
239
- // type: 'number',
240
- // default: 1000,
241
- // },
242
- // WS_CONNECTION_RETRY_LIMIT: {
243
- // type: 'number',
244
- // default: 3,
245
- // },
246
- // WS_CONNECTION_TTL: {
247
- // type: 'number',
248
- // default: 70000,
249
- // },
250
- // WS_ENABLED: {
251
- // type: 'boolean',
252
- // default: false,
253
- // },
254
- // WS_SUBSCRIPTION_LIMIT: {
255
- // type: 'number',
256
- // default: 10,
257
- // },
258
- // WS_SUBSCRIPTION_PRIORITY_LIST: {
259
- // type: 'string',
260
- // },
261
- // WS_SUBSCRIPTION_TTL: {
262
- // type: 'number',
263
- // default: 120000,
264
- // },
265
- // WS_SUBSCRIPTION_UNRESPONSIVE_TTL: {
266
- // type: 'number',
267
- // default: false,
268
- // },
269
- // WS_TIME_UNTIL_HANDLE_NEXT_MESSAGE_OVERRIDE: {
270
- // type: 'number',
271
- // },
272
- // V3
273
- CACHE_POLLING_MAX_RETRIES: {
274
- description: 'Max amount of times to attempt to find EA response in the cache after the Transport has been set up',
275
- type: 'number',
276
- default: 10,
277
- },
278
- CACHE_POLLING_SLEEP_MS: {
279
- description: 'The number of ms to sleep between each retry to fetch the EA response in the cache',
280
- type: 'number',
281
- default: 200,
282
- },
283
- DEFAULT_CACHE_KEY: {
284
- description: 'Default key to be used when one cannot be determined from request parameters',
285
- type: 'string',
286
- default: 'DEFAULT_CACHE_KEY',
287
- },
288
- EA_HOST: {
289
- description: 'Host this EA will listen for REST requests on (if mode is set to "reader" or "reader-writer")',
290
- type: 'string',
291
- default: '::',
292
- },
293
- EA_MODE: {
294
- description: 'Port this EA will listen for REST requests on (if mode is set to "reader" or "reader-writer")',
295
- type: 'enum',
296
- default: 'reader-writer',
297
- options: ['reader', 'writer', 'reader-writer'],
298
- },
299
- REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
300
- description: 'Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter',
301
- type: 'number',
302
- default: 3,
303
- },
304
- REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
305
- description: 'Time that the Rest Transport will wait between retries when blocked by the rate limiter',
306
- type: 'number',
307
- default: 400,
308
- },
309
- // CACHE_KEY_IGNORED_PROPS : {
310
- // description: 'Properties to ignore when generating a feed ID for requests',
311
- // type: 'string'
312
- // }
313
- };
314
- const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
315
- const validationErrors = [];
316
- const vars = {};
317
- // Iterate base adapter env vars
318
- for (const [key, config] of Object.entries(exports.BaseSettings)) {
319
- const value = getEnv(key, config) ?? overrides?.[key] ?? config.default;
320
- vars[key] = value;
321
- }
322
- // Iterate custom vars
323
- for (const [key, config] of Object.entries(customSettings)) {
324
- if (exports.BaseSettings[key]) {
325
- throw new Error(`Custom env var "${key}" declared, but a base framework env var with that name already exists.`);
326
- }
327
- const value = getEnv(key, config) ?? config.default;
328
- // Check if a required setting has been provided
329
- if (config.required && value === null) {
330
- validationErrors.push(`${key}: Value is required, but none was provided`);
331
- }
332
- else if (config.validate) {
333
- // Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
334
- const validationRes = config.validate(value);
335
- if (validationRes) {
336
- validationErrors.push(`${key}: ${validationRes}`);
337
- }
338
- }
339
- vars[key] = value;
340
- }
341
- if (validationErrors.length > 0) {
342
- throw new Error(`Validation failed for the following variables:\n ${validationErrors.join('\n')}`);
343
- }
344
- return vars;
345
- };
346
- exports.buildAdapterConfig = buildAdapterConfig;
347
- const getEnv = (name, config) => {
348
- const value = process.env[name];
349
- if (!value) {
350
- return null;
351
- }
352
- switch (config.type) {
353
- case 'string':
354
- return value;
355
- case 'number':
356
- return parseInt(value);
357
- case 'boolean':
358
- return value === 'true';
359
- case 'enum':
360
- if (!config.options?.includes(value)) {
361
- throw new Error(`Env var "${name}" has value "${value}" which is not included in the valid options (${config.options})`);
362
- }
363
- return value;
364
- }
365
- };
@@ -1,31 +0,0 @@
1
- export declare const DEFAULT_MINUTE_RATE_LIMIT = 60;
2
- export declare const BURST_UNDEFINED_QUOTA_MULTIPLE = 2;
3
- export declare const DEFAULT_WS_CONNECTIONS = 2;
4
- export declare const DEFAULT_WS_SUBSCRIPTIONS = 10;
5
- declare type RateLimitTimeFrame = 'rateLimit1s' | 'rateLimit1m' | 'rateLimit1h';
6
- declare type HTTPTier = {
7
- rateLimit1s?: number;
8
- rateLimit1m?: number;
9
- rateLimit1h?: number;
10
- note?: string;
11
- };
12
- declare type WSTier = {
13
- connections: number;
14
- subscriptions: number;
15
- };
16
- export interface Limits {
17
- http: {
18
- [tierName: string]: HTTPTier;
19
- };
20
- ws: {
21
- [tierName: string]: WSTier;
22
- };
23
- }
24
- interface ProviderRateLimit {
25
- second: number;
26
- minute: number;
27
- }
28
- export declare const getHTTPLimit: (provider: string, limits: Limits, tier: string, timeframe: RateLimitTimeFrame) => number;
29
- export declare const getRateLimit: (provider: string, limits: Limits, tier: string) => ProviderRateLimit;
30
- export declare const getWSLimits: (provider: string, limits: Limits, tier: string) => WSTier;
31
- export {};
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWSLimits = exports.getRateLimit = exports.getHTTPLimit = exports.DEFAULT_WS_SUBSCRIPTIONS = exports.DEFAULT_WS_CONNECTIONS = exports.BURST_UNDEFINED_QUOTA_MULTIPLE = exports.DEFAULT_MINUTE_RATE_LIMIT = void 0;
4
- const util_1 = require("../util");
5
- exports.DEFAULT_MINUTE_RATE_LIMIT = 60;
6
- exports.BURST_UNDEFINED_QUOTA_MULTIPLE = 2;
7
- exports.DEFAULT_WS_CONNECTIONS = 2;
8
- exports.DEFAULT_WS_SUBSCRIPTIONS = 10;
9
- const logger = (0, util_1.makeLogger)('ProviderLimits');
10
- const getHTTPLimit = (provider, limits, tier, timeframe) => {
11
- const providerLimit = getProviderLimits(provider, limits, tier, 'http');
12
- return providerLimit?.[timeframe] || 0;
13
- };
14
- exports.getHTTPLimit = getHTTPLimit;
15
- const getRateLimit = (provider, limits, tier) => {
16
- const providerLimit = getProviderLimits(provider, limits, tier, 'http');
17
- return calculateRateLimit(providerLimit);
18
- };
19
- exports.getRateLimit = getRateLimit;
20
- const getWSLimits = (provider, limits, tier) => {
21
- const providerLimit = getProviderLimits(provider, limits, tier, 'ws');
22
- return calculateWSLimits(providerLimit);
23
- };
24
- exports.getWSLimits = getWSLimits;
25
- const getProviderLimits = (provider, limits, tier, protocol) => {
26
- const providerConfig = parseLimits(limits);
27
- if (!providerConfig) {
28
- throw new Error(`Rate Limit: Provider: "${provider}" doesn't match any provider spec in limits.json`);
29
- }
30
- const protocolConfig = providerConfig[protocol];
31
- if (!protocolConfig) {
32
- throw new Error(`Rate Limit: "${provider}" doesn't have any configuration for ${protocol} in limits.json`);
33
- }
34
- let limitsConfig = protocolConfig[tier.toLowerCase()];
35
- if (!limitsConfig) {
36
- logger.debug(`Rate Limit: "${provider} does not have tier ${tier} defined. Falling back to lowest tier"`);
37
- limitsConfig = Object.values(protocolConfig)?.[0];
38
- }
39
- if (!limitsConfig) {
40
- throw new Error(`Rate Limit: Provider: "${provider}" has no tiers defined for ${protocol} in limits.json`);
41
- }
42
- return limitsConfig;
43
- };
44
- const parseLimits = (limits) => {
45
- // const _mapObject = (fn: any) => (o: any) => Object.fromEntries(Object.entries(o).map(fn))
46
- const _mapObject = (fn) => (o) => Object.fromEntries([]);
47
- const _formatProtocol = _mapObject((entry) => {
48
- const [tierName, rest] = entry;
49
- return [tierName.toLowerCase(), { ...rest }];
50
- });
51
- const _formatProvider = (ls) => {
52
- const http = _formatProtocol(ls.http);
53
- const ws = _formatProtocol(ls?.ws);
54
- return { http, ws };
55
- };
56
- return _formatProvider(limits);
57
- };
58
- const calculateWSLimits = (providerLimit) => {
59
- return {
60
- connections: providerLimit.connections,
61
- subscriptions: providerLimit.subscriptions,
62
- };
63
- };
64
- const calculateRateLimit = (providerLimit) => {
65
- let quota = providerLimit.rateLimit1m;
66
- if (!quota && providerLimit?.rateLimit1h) {
67
- quota = providerLimit?.rateLimit1h / 60;
68
- }
69
- else if (!quota && providerLimit?.rateLimit1s) {
70
- quota = providerLimit?.rateLimit1s * 60;
71
- }
72
- return {
73
- second: providerLimit?.rateLimit1s || (quota / 60) * exports.BURST_UNDEFINED_QUOTA_MULTIPLE,
74
- minute: quota,
75
- };
76
- };
@@ -1,2 +0,0 @@
1
- import { AdapterEndpoint } from '../../adapter';
2
- export declare const batchEndpoint: AdapterEndpoint;