@chainlink/external-adapter-framework 0.0.12 → 0.0.14

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 (278) hide show
  1. package/adapter.d.ts +107 -0
  2. package/adapter.js +115 -0
  3. package/{dist/src/package/background-executor.d.ts → background-executor.d.ts} +0 -0
  4. package/{dist/src/background-executor.js → background-executor.js} +0 -0
  5. package/{dist/src/cache → cache}/factory.d.ts +0 -0
  6. package/{dist/src/cache → cache}/factory.js +0 -0
  7. package/{dist/src/cache → cache}/index.d.ts +8 -8
  8. package/{dist/src/cache → cache}/index.js +0 -0
  9. package/{dist/src/cache → cache}/local.d.ts +0 -0
  10. package/{dist/src/cache → cache}/local.js +0 -0
  11. package/{dist/src/cache → cache}/metrics.d.ts +0 -0
  12. package/{dist/src/cache → cache}/metrics.js +0 -0
  13. package/{dist/src/cache → cache}/redis.d.ts +0 -0
  14. package/{dist/src/cache → cache}/redis.js +0 -0
  15. package/{dist/src/chainlink-external-adapter-framework-0.0.6.tgz → chainlink-external-adapter-framework-0.0.6.tgz} +0 -0
  16. package/{dist/src/config → config}/index.d.ts +0 -5
  17. package/{dist/src/config → config}/index.js +5 -5
  18. package/{dist/src/config → config}/provider-limits.d.ts +0 -0
  19. package/{dist/src/config → config}/provider-limits.js +5 -1
  20. package/{dist/src/examples → examples}/bank-frick/accounts.d.ts +1 -1
  21. package/{dist/src/examples → examples}/bank-frick/accounts.js +2 -3
  22. package/{dist/src/examples → examples}/bank-frick/config/index.d.ts +0 -0
  23. package/{dist/src/examples → examples}/bank-frick/config/index.js +0 -0
  24. package/{dist/src/package/examples/coingecko → examples/bank-frick}/index.d.ts +0 -0
  25. package/{dist/src/examples → examples}/bank-frick/index.js +2 -3
  26. package/{dist/src/examples → examples}/bank-frick/util.d.ts +0 -0
  27. package/{dist/src/examples → examples}/bank-frick/util.js +0 -0
  28. package/{dist/src/package/examples → examples}/coingecko/batch-warming.d.ts +0 -0
  29. package/{dist/src/package/examples → examples}/coingecko/batch-warming.js +0 -0
  30. package/{dist/src/package/examples/ncfx → examples/coingecko}/index.d.ts +0 -0
  31. package/{dist/src/package/examples → examples}/coingecko/index.js +0 -0
  32. package/{dist/src/package/examples → examples}/coingecko/rest.d.ts +0 -0
  33. package/{dist/src/package/examples → examples}/coingecko/rest.js +0 -0
  34. package/{dist/src/examples → examples}/ncfx/config/index.d.ts +0 -0
  35. package/{dist/src/examples → examples}/ncfx/config/index.js +0 -0
  36. package/examples/ncfx/index.d.ts +2 -0
  37. package/{dist/src/package/examples → examples}/ncfx/index.js +0 -0
  38. package/{dist/src/package/examples → examples}/ncfx/websocket.d.ts +0 -0
  39. package/{dist/src/package/examples → examples}/ncfx/websocket.js +0 -0
  40. package/{dist/src/index.d.ts → index.d.ts} +0 -0
  41. package/{dist/src/index.js → index.js} +18 -13
  42. package/{dist/src/metrics → metrics}/constants.d.ts +0 -0
  43. package/{dist/src/metrics → metrics}/constants.js +0 -0
  44. package/{dist/src/metrics → metrics}/index.d.ts +0 -0
  45. package/{dist/src/metrics → metrics}/index.js +0 -0
  46. package/metrics/util.d.ts +7 -0
  47. package/{dist/src/metrics → metrics}/util.js +0 -0
  48. package/{dist/src/package → package}/adapter.d.ts +0 -0
  49. package/{dist/src/package → package}/adapter.js +0 -0
  50. package/{dist/src → package}/background-executor.d.ts +2 -2
  51. package/{dist/src/package → package}/background-executor.js +0 -0
  52. package/{dist/src/package → package}/cache/factory.d.ts +0 -0
  53. package/{dist/src/package → package}/cache/factory.js +0 -0
  54. package/{dist/src/package → package}/cache/index.d.ts +0 -0
  55. package/{dist/src/package → package}/cache/index.js +0 -0
  56. package/{dist/src/package → package}/cache/local.d.ts +0 -0
  57. package/{dist/src/package → package}/cache/local.js +0 -0
  58. package/{dist/src/package → package}/cache/metrics.d.ts +0 -0
  59. package/{dist/src/package → package}/cache/metrics.js +0 -0
  60. package/{dist/src/package → package}/cache/redis.d.ts +0 -0
  61. package/{dist/src/package → package}/cache/redis.js +0 -0
  62. package/{dist/src/package → package}/config/index.d.ts +0 -0
  63. package/{dist/src/package → package}/config/index.js +0 -0
  64. package/{dist/src/package → package}/config/provider-limits.d.ts +0 -0
  65. package/{dist/src/package → package}/config/provider-limits.js +0 -0
  66. package/package/examples/coingecko/batch-warming.d.ts +2 -0
  67. package/{dist/src → package}/examples/coingecko/batch-warming.js +2 -3
  68. package/package/examples/coingecko/index.d.ts +2 -0
  69. package/{dist/src → package}/examples/coingecko/index.js +2 -3
  70. package/package/examples/coingecko/rest.d.ts +2 -0
  71. package/{dist/src → package}/examples/coingecko/rest.js +2 -3
  72. package/{dist/src/package → package}/examples/ncfx/config/index.d.ts +0 -0
  73. package/{dist/src/package → package}/examples/ncfx/config/index.js +0 -0
  74. package/package/examples/ncfx/index.d.ts +2 -0
  75. package/{dist/src → package}/examples/ncfx/index.js +2 -3
  76. package/{dist/src → package}/examples/ncfx/websocket.d.ts +1 -12
  77. package/{dist/src → package}/examples/ncfx/websocket.js +2 -3
  78. package/{dist/src/package → package}/index.d.ts +0 -0
  79. package/{dist/src/package → package}/index.js +0 -0
  80. package/{dist/src/package → package}/metrics/constants.d.ts +0 -0
  81. package/{dist/src/package → package}/metrics/constants.js +0 -0
  82. package/{dist/src/package → package}/metrics/index.d.ts +0 -0
  83. package/{dist/src/package → package}/metrics/index.js +0 -0
  84. package/{dist/src/package → package}/metrics/util.d.ts +0 -0
  85. package/{dist/src/package → package}/metrics/util.js +0 -0
  86. package/{dist/src → package}/package.json +0 -0
  87. package/{dist/src/package → package}/rate-limiting/background/fixed-frequency.d.ts +0 -0
  88. package/{dist/src/package → package}/rate-limiting/background/fixed-frequency.js +0 -0
  89. package/{dist/src/package → package}/rate-limiting/index.d.ts +0 -0
  90. package/{dist/src/package → package}/rate-limiting/index.js +0 -0
  91. package/{dist/src/package → package}/rate-limiting/metrics.d.ts +0 -0
  92. package/{dist/src/package → package}/rate-limiting/metrics.js +0 -0
  93. package/{dist/src/package → package}/rate-limiting/request/simple-counting.d.ts +0 -0
  94. package/{dist/src/package → package}/rate-limiting/request/simple-counting.js +0 -0
  95. package/{dist/src/package → package}/test.d.ts +0 -0
  96. package/{dist/src/package → package}/test.js +0 -0
  97. package/{dist/src/package → package}/transports/batch-warming.d.ts +0 -0
  98. package/{dist/src/package → package}/transports/batch-warming.js +0 -0
  99. package/{dist/src/package → package}/transports/index.d.ts +0 -0
  100. package/{dist/src/package → package}/transports/index.js +0 -0
  101. package/{dist/src/package → package}/transports/metrics.d.ts +0 -0
  102. package/{dist/src/package → package}/transports/metrics.js +0 -0
  103. package/{dist/src/package → package}/transports/rest.d.ts +0 -0
  104. package/{dist/src/package → package}/transports/rest.js +0 -0
  105. package/{dist/src/package → package}/transports/util.d.ts +0 -0
  106. package/{dist/src/package → package}/transports/util.js +0 -0
  107. package/{dist/src/package → package}/transports/websocket.d.ts +0 -0
  108. package/{dist/src/package → package}/transports/websocket.js +0 -0
  109. package/{dist/src/package → package}/util/expiring-sorted-set.d.ts +0 -0
  110. package/{dist/src/package → package}/util/expiring-sorted-set.js +0 -0
  111. package/{dist/src/package → package}/util/index.d.ts +0 -0
  112. package/{dist/src/package → package}/util/index.js +0 -0
  113. package/{dist/src/package → package}/util/logger.d.ts +0 -0
  114. package/{dist/src/package → package}/util/logger.js +0 -0
  115. package/{dist/src/package → package}/util/request.d.ts +0 -0
  116. package/{dist/src/package → package}/util/request.js +0 -0
  117. package/{dist/src/package → package}/validation/error.d.ts +0 -0
  118. package/{dist/src/package → package}/validation/error.js +0 -0
  119. package/{dist/src/package → package}/validation/index.d.ts +0 -0
  120. package/{dist/src/package → package}/validation/index.js +0 -0
  121. package/{dist/src/package → package}/validation/input-params.d.ts +0 -0
  122. package/{dist/src/package → package}/validation/input-params.js +0 -0
  123. package/{dist/src/package → package}/validation/override-functions.d.ts +0 -0
  124. package/{dist/src/package → package}/validation/override-functions.js +0 -0
  125. package/{dist/src/package → package}/validation/preset-tokens.json +0 -0
  126. package/{dist/src/package → package}/validation/validator.d.ts +0 -0
  127. package/{dist/src/package → package}/validation/validator.js +0 -0
  128. package/package.json +1 -1
  129. package/{dist/src/rate-limiting → rate-limiting}/background/fixed-frequency.d.ts +1 -2
  130. package/{dist/src/rate-limiting → rate-limiting}/background/fixed-frequency.js +0 -0
  131. package/{dist/src/rate-limiting → rate-limiting}/index.d.ts +1 -2
  132. package/{dist/src/rate-limiting → rate-limiting}/index.js +0 -0
  133. package/{dist/src/rate-limiting → rate-limiting}/metrics.d.ts +0 -0
  134. package/{dist/src/rate-limiting → rate-limiting}/metrics.js +0 -0
  135. package/{dist/src/rate-limiting → rate-limiting}/request/simple-counting.d.ts +1 -2
  136. package/{dist/src/rate-limiting → rate-limiting}/request/simple-counting.js +0 -0
  137. package/{dist/src/test.d.ts → test.d.ts} +0 -0
  138. package/{dist/src/test.js → test.js} +0 -0
  139. package/{dist/src/transports → transports}/batch-warming.d.ts +0 -0
  140. package/{dist/src/transports → transports}/batch-warming.js +0 -0
  141. package/{dist/src/transports → transports}/index.d.ts +2 -2
  142. package/{dist/src/transports → transports}/index.js +0 -0
  143. package/{dist/src/transports → transports}/metrics.d.ts +1 -2
  144. package/{dist/src/transports → transports}/metrics.js +0 -0
  145. package/{dist/src/transports → transports}/rest.d.ts +0 -0
  146. package/{dist/src/transports → transports}/rest.js +0 -0
  147. package/{dist/src/transports → transports}/util.d.ts +0 -0
  148. package/{dist/src/transports → transports}/util.js +0 -0
  149. package/{dist/src/transports → transports}/websocket.d.ts +3 -2
  150. package/{dist/src/transports → transports}/websocket.js +6 -4
  151. package/{dist/src/util → util}/expiring-sorted-set.d.ts +0 -0
  152. package/{dist/src/util → util}/expiring-sorted-set.js +0 -0
  153. package/{dist/src/util → util}/index.d.ts +0 -0
  154. package/{dist/src/util → util}/index.js +0 -0
  155. package/{dist/src/util → util}/logger.d.ts +0 -0
  156. package/{dist/src/util → util}/logger.js +0 -0
  157. package/{dist/src/util → util}/request.d.ts +2 -2
  158. package/{dist/src/util → util}/request.js +0 -0
  159. package/{dist/src/util → util}/subscription-set/expiring-sorted-set.d.ts +0 -0
  160. package/{dist/src/util → util}/subscription-set/expiring-sorted-set.js +0 -0
  161. package/{dist/src/util → util}/subscription-set/subscription-set.d.ts +0 -0
  162. package/{dist/src/util → util}/subscription-set/subscription-set.js +0 -0
  163. package/{dist/src/util → util}/test-payload-loader.d.ts +0 -0
  164. package/{dist/src/util → util}/test-payload-loader.js +0 -0
  165. package/{dist/src/validation → validation}/error.d.ts +2 -2
  166. package/{dist/src/validation → validation}/error.js +0 -0
  167. package/{dist/src/validation → validation}/index.d.ts +0 -0
  168. package/{dist/src/validation → validation}/index.js +0 -0
  169. package/{dist/src/validation → validation}/input-params.d.ts +0 -0
  170. package/{dist/src/validation → validation}/input-params.js +0 -0
  171. package/validation/override-functions.d.ts +3 -0
  172. package/{dist/src/validation → validation}/override-functions.js +0 -0
  173. package/{dist/src/validation → validation}/preset-tokens.json +0 -0
  174. package/{dist/src/validation → validation}/validator.d.ts +0 -0
  175. package/{dist/src/validation → validation}/validator.js +0 -0
  176. package/.c8rc.json +0 -3
  177. package/.eslintignore +0 -9
  178. package/.eslintrc.js +0 -96
  179. package/.github/README.MD +0 -17
  180. package/.github/actions/setup/action.yaml +0 -13
  181. package/.github/workflows/main.yaml +0 -39
  182. package/.github/workflows/publish.yaml +0 -20
  183. package/.prettierignore +0 -13
  184. package/.yarnrc +0 -0
  185. package/README.md +0 -103
  186. package/dist/src/adapter.d.ts +0 -135
  187. package/dist/src/adapter.js +0 -145
  188. package/dist/src/examples/bank-frick/index.d.ts +0 -2
  189. package/dist/src/examples/coingecko/batch-warming.d.ts +0 -7
  190. package/dist/src/examples/coingecko/index.d.ts +0 -2
  191. package/dist/src/examples/coingecko/rest.d.ts +0 -12
  192. package/dist/src/examples/ncfx/index.d.ts +0 -13
  193. package/dist/src/metrics/util.d.ts +0 -7
  194. package/dist/src/package/package.json +0 -72
  195. package/dist/src/validation/override-functions.d.ts +0 -3
  196. package/docker-compose.yaml +0 -35
  197. package/env.sh +0 -54
  198. package/env2.sh +0 -55
  199. package/publish.sh +0 -0
  200. package/src/adapter.ts +0 -263
  201. package/src/background-executor.ts +0 -52
  202. package/src/cache/factory.ts +0 -26
  203. package/src/cache/index.ts +0 -258
  204. package/src/cache/local.ts +0 -73
  205. package/src/cache/metrics.ts +0 -112
  206. package/src/cache/redis.ts +0 -93
  207. package/src/config/index.ts +0 -517
  208. package/src/config/provider-limits.ts +0 -130
  209. package/src/examples/bank-frick/README.MD +0 -10
  210. package/src/examples/bank-frick/accounts.ts +0 -246
  211. package/src/examples/bank-frick/config/index.ts +0 -53
  212. package/src/examples/bank-frick/index.ts +0 -13
  213. package/src/examples/bank-frick/types.d.ts +0 -38
  214. package/src/examples/bank-frick/util.ts +0 -55
  215. package/src/examples/coingecko/batch-warming.ts +0 -78
  216. package/src/examples/coingecko/index.ts +0 -9
  217. package/src/examples/coingecko/rest.ts +0 -77
  218. package/src/examples/ncfx/config/index.ts +0 -12
  219. package/src/examples/ncfx/index.ts +0 -9
  220. package/src/examples/ncfx/websocket.ts +0 -99
  221. package/src/index.ts +0 -149
  222. package/src/metrics/constants.ts +0 -23
  223. package/src/metrics/index.ts +0 -115
  224. package/src/metrics/util.ts +0 -18
  225. package/src/rate-limiting/background/fixed-frequency.ts +0 -45
  226. package/src/rate-limiting/index.ts +0 -100
  227. package/src/rate-limiting/metrics.ts +0 -18
  228. package/src/rate-limiting/request/simple-counting.ts +0 -76
  229. package/src/test.ts +0 -5
  230. package/src/transports/batch-warming.ts +0 -122
  231. package/src/transports/index.ts +0 -152
  232. package/src/transports/metrics.ts +0 -95
  233. package/src/transports/rest.ts +0 -164
  234. package/src/transports/util.ts +0 -63
  235. package/src/transports/websocket.ts +0 -245
  236. package/src/util/index.ts +0 -22
  237. package/src/util/logger.ts +0 -69
  238. package/src/util/request.ts +0 -117
  239. package/src/util/subscription-set/expiring-sorted-set.ts +0 -54
  240. package/src/util/subscription-set/subscription-set.ts +0 -35
  241. package/src/util/test-payload-loader.ts +0 -87
  242. package/src/validation/error.ts +0 -116
  243. package/src/validation/index.ts +0 -110
  244. package/src/validation/input-params.ts +0 -45
  245. package/src/validation/override-functions.ts +0 -44
  246. package/src/validation/preset-tokens.json +0 -23
  247. package/src/validation/validator.ts +0 -384
  248. package/test/adapter.test.ts +0 -27
  249. package/test/background-executor.test.ts +0 -108
  250. package/test/cache/cache-key.test.ts +0 -114
  251. package/test/cache/helper.ts +0 -100
  252. package/test/cache/local.test.ts +0 -54
  253. package/test/cache/redis.test.ts +0 -89
  254. package/test/correlation.test.ts +0 -114
  255. package/test/index.test.ts +0 -37
  256. package/test/metrics/feed-id.test.ts +0 -38
  257. package/test/metrics/helper.ts +0 -14
  258. package/test/metrics/labels.test.ts +0 -36
  259. package/test/metrics/metrics.test.ts +0 -267
  260. package/test/metrics/redis-metrics.test.ts +0 -113
  261. package/test/metrics/warmer-metrics.test.ts +0 -192
  262. package/test/metrics/ws-metrics.test.ts +0 -225
  263. package/test/rate-limit-config.test.ts +0 -242
  264. package/test/smoke.test.ts +0 -166
  265. package/test/transports/batch.test.ts +0 -465
  266. package/test/transports/rest.test.ts +0 -242
  267. package/test/transports/websocket.test.ts +0 -183
  268. package/test/tsconfig.json +0 -5
  269. package/test/util.ts +0 -77
  270. package/test/validation.test.ts +0 -178
  271. package/test-payload-fail.json +0 -3
  272. package/test-payload.js +0 -22
  273. package/test-payload.json +0 -7
  274. package/test.sh +0 -20
  275. package/test2.sh +0 -2
  276. package/tsconfig.json +0 -25
  277. package/typedoc.json +0 -6
  278. package/webpack.config.js +0 -23
package/adapter.d.ts ADDED
@@ -0,0 +1,107 @@
1
+ import { Cache } from './cache';
2
+ import { AdapterConfig, BaseAdapterConfig, CustomSettingsType, SettingsMap } from './config';
3
+ import { AdapterRateLimitTier, BackgroundExecuteRateLimiter, RequestRateLimiter } from './rate-limiting';
4
+ import { Transport } from './transports';
5
+ import { SubscriptionSetFactory } from './util';
6
+ import { InputParameters } from './validation/input-params';
7
+ /**
8
+ * Dependencies that will be injected into the Adapter on startup
9
+ */
10
+ export interface AdapterDependencies {
11
+ cache: Cache;
12
+ requestRateLimiter: RequestRateLimiter;
13
+ backgroundExecuteRateLimiter: BackgroundExecuteRateLimiter;
14
+ subscriptionSetFactory: SubscriptionSetFactory;
15
+ }
16
+ /**
17
+ * Context that will be used on background executions of a Transport.
18
+ * For example, the endpointName used to log statements or generate Cache keys.
19
+ */
20
+ export interface AdapterContext<CustomSettings extends CustomSettingsType<CustomSettings> = SettingsMap> {
21
+ adapterEndpoint: AdapterEndpoint;
22
+ adapterConfig: AdapterConfig<CustomSettings>;
23
+ }
24
+ /**
25
+ * Structure to describe rate limits specs for the Adapter
26
+ */
27
+ interface AdapterRateLimitingConfig {
28
+ /** Adapter rate limits, gotten from the specific tier requested */
29
+ tiers: Record<string, AdapterRateLimitTier>;
30
+ }
31
+ /**
32
+ * Main structure of an External Adapter
33
+ */
34
+ export interface Adapter {
35
+ /** Name of the adapter */
36
+ name: string;
37
+ /** If present, the string that will be used for requests with no specified endpoint */
38
+ defaultEndpoint?: string;
39
+ /** List of [[AdapterEndpoint]]s in the adapter */
40
+ endpoints: AdapterEndpoint[];
41
+ /** Map of overrides to the default config values for an Adapter */
42
+ envDefaultOverrides?: Partial<BaseAdapterConfig>;
43
+ /** List of custom env vars for this particular adapter (e.g. RPC_URL) */
44
+ customSettings?: SettingsMap;
45
+ /** Configuration relevant to outbound (EA --\> DP) communication rate limiting */
46
+ rateLimiting?: AdapterRateLimitingConfig;
47
+ /** Overrides for converting the 'base' parameter that are hardcoded into the adapter. */
48
+ overrides?: Record<string, string>;
49
+ }
50
+ /**
51
+ * Structure to describe rate limits specs for a specific adapter endpoint
52
+ */
53
+ export interface EndpointRateLimitingConfig {
54
+ /**
55
+ * How much of the total limit for the adapter will be assigned to this specific endpoint.
56
+ * Should be a non-zero positive number up to 100.
57
+ * Endpoints in the same adapter without a specific allocation will divide the remaining limits equally.
58
+ */
59
+ allocationPercentage: number;
60
+ }
61
+ /**
62
+ * Structure to describe a specific endpoint in an [[Adapter]]
63
+ */
64
+ export interface AdapterEndpoint {
65
+ /** Name that will be used to match input params to this endpoint (case insensitive) */
66
+ name: string;
67
+ /** List of alternative endpoint names that will resolve to this same transport (case insensitive) */
68
+ aliases?: string[];
69
+ /** Transport that will be used to handle data processing and communication for this endpoint */
70
+ transport: Transport<any, any, any>;
71
+ /** Specification of what the body of a request hitting this endpoint should look like (used for validation) */
72
+ inputParameters: InputParameters;
73
+ /** Specific details related to the rate limiting for this endpoint in particular */
74
+ rateLimiting?: EndpointRateLimitingConfig;
75
+ }
76
+ /**
77
+ * Structure to describe an adapter that has been initialized
78
+ */
79
+ export interface InitializedAdapter extends Adapter {
80
+ /** Object containing alias translations for all endpoints */
81
+ endpointsMap: Record<string, AdapterEndpoint>;
82
+ /** Initialized dependencies that the adapter will use */
83
+ dependencies: AdapterDependencies;
84
+ /** Configuration params for various adapter properties */
85
+ config: AdapterConfig;
86
+ }
87
+ /**
88
+ * This function will process dependencies for an adapter, such as caches or rate limiters,
89
+ * in order to inject them into transports and other relevant places later in the lifecycle.
90
+ *
91
+ * @param config - the configuration for this adapter
92
+ * @param inputDependencies - a partial obj of initialized dependencies to override the created ones
93
+ * @param rateLimitingConfig - details from the adapter regarding rate limiting
94
+ * @returns a set of AdapterDependencies all initialized
95
+ */
96
+ export declare const initializeDependencies: (adapter: Adapter, config: AdapterConfig, inputDependencies?: Partial<AdapterDependencies>) => AdapterDependencies;
97
+ /**
98
+ * Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
99
+ * Additionally, it builds a map out of all the endpoint names and aliases (checking for duplicates).
100
+ *
101
+ * @param adapter - an instance of an Adapter
102
+ * @param dependencies - dependencies that the adapter will need at initialization
103
+ * @param config - configuration variables already processed and validated
104
+ * @returns - the adapter with all transports initialized and aliases map built
105
+ */
106
+ export declare const initializeAdapter: (adapter: Adapter, config: AdapterConfig, dependencies?: Partial<AdapterDependencies>) => Promise<InitializedAdapter>;
107
+ export {};
package/adapter.js ADDED
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initializeAdapter = exports.initializeDependencies = void 0;
4
+ const cache_1 = require("./cache");
5
+ const rate_limiting_1 = require("./rate-limiting");
6
+ const util_1 = require("./util");
7
+ const logger = (0, util_1.makeLogger)('Adapter');
8
+ /**
9
+ * This function will take an adapter structure and go through each endpoint, calculating
10
+ * each one's allocation of the total rate limits that are set for the adapter as a whole.
11
+ *
12
+ * @param adapter - the adapter to initialize rate limiting for
13
+ */
14
+ const calculateRateLimitAllocations = (adapter) => {
15
+ const numberOfEndpoints = adapter.endpoints.length;
16
+ const endpointsWithExplicitAllocations = adapter.endpoints.filter((e) => e.rateLimiting);
17
+ const totalExplicitAllocation = endpointsWithExplicitAllocations
18
+ .map((e) => e.rateLimiting?.allocationPercentage || 0)
19
+ .reduce((sum, next) => sum + next, 0);
20
+ if (totalExplicitAllocation > 100) {
21
+ throw new Error('The total allocation set for all endpoints summed cannot exceed 100%');
22
+ }
23
+ if (totalExplicitAllocation === 100 &&
24
+ numberOfEndpoints - endpointsWithExplicitAllocations.length > 0) {
25
+ throw new Error('The explicit allocation is at 100% but there are endpoints with implicit allocation');
26
+ }
27
+ const implicitAllocation = 100 - totalExplicitAllocation;
28
+ logger.debug('Adapter rate limit allocations:');
29
+ for (const endpoint of adapter.endpoints) {
30
+ if (!endpoint.rateLimiting) {
31
+ endpoint.rateLimiting = {
32
+ allocationPercentage: implicitAllocation / (numberOfEndpoints - endpointsWithExplicitAllocations.length),
33
+ };
34
+ }
35
+ logger.debug(`Endpoint [${endpoint.name}] - ${endpoint.rateLimiting?.allocationPercentage}%`);
36
+ }
37
+ };
38
+ /**
39
+ * This function will process dependencies for an adapter, such as caches or rate limiters,
40
+ * in order to inject them into transports and other relevant places later in the lifecycle.
41
+ *
42
+ * @param config - the configuration for this adapter
43
+ * @param inputDependencies - a partial obj of initialized dependencies to override the created ones
44
+ * @param rateLimitingConfig - details from the adapter regarding rate limiting
45
+ * @returns a set of AdapterDependencies all initialized
46
+ */
47
+ const initializeDependencies = (adapter, config, inputDependencies) => {
48
+ const dependencies = inputDependencies || {};
49
+ if (!dependencies.cache) {
50
+ dependencies.cache = cache_1.CacheFactory.buildCache(config);
51
+ }
52
+ // In the future we might want something more complex, but for now it's better to simplify
53
+ // and just use the same rate limiting for everything. Once we have a more complex use case we
54
+ // can think of ways to make this more configurable.
55
+ const rateLimitingTier = (0, rate_limiting_1.getRateLimitingTier)(adapter.rateLimiting?.tiers, config.RATE_LIMIT_API_TIER);
56
+ if (!dependencies.requestRateLimiter) {
57
+ dependencies.requestRateLimiter = new rate_limiting_1.SimpleCountingRateLimiter().initialize(adapter.endpoints, rateLimitingTier);
58
+ }
59
+ if (!dependencies.backgroundExecuteRateLimiter) {
60
+ dependencies.backgroundExecuteRateLimiter = new rate_limiting_1.FixedFrequencyRateLimiter().initialize(adapter.endpoints, rateLimitingTier);
61
+ }
62
+ if (!dependencies.subscriptionSetFactory) {
63
+ dependencies.subscriptionSetFactory = new util_1.SubscriptionSetFactory(config);
64
+ }
65
+ return dependencies;
66
+ };
67
+ exports.initializeDependencies = initializeDependencies;
68
+ /**
69
+ * Takes an adapter and normalizes all endpoint names and aliases, as well as the default endpoint.
70
+ * i.e. makes them lowercase for now
71
+ * @param adapter - an instance of an Adapter
72
+ */
73
+ const normalizeEndpointNames = (adapter) => {
74
+ // Make endpoints case insensitive, including default
75
+ adapter.defaultEndpoint = adapter.defaultEndpoint?.toLowerCase();
76
+ for (const endpoint of adapter.endpoints) {
77
+ endpoint.name = endpoint.name.toLowerCase();
78
+ endpoint.aliases = endpoint.aliases?.map((a) => a.toLowerCase());
79
+ }
80
+ };
81
+ /**
82
+ * Initializes all of the [[Transport]]s in the adapter, passing along any [[AdapterDependencies]] and [[AdapterConfig]].
83
+ * Additionally, it builds a map out of all the endpoint names and aliases (checking for duplicates).
84
+ *
85
+ * @param adapter - an instance of an Adapter
86
+ * @param dependencies - dependencies that the adapter will need at initialization
87
+ * @param config - configuration variables already processed and validated
88
+ * @returns - the adapter with all transports initialized and aliases map built
89
+ */
90
+ const initializeAdapter = async (adapter, config, dependencies) => {
91
+ normalizeEndpointNames(adapter);
92
+ calculateRateLimitAllocations(adapter);
93
+ const initializedDependencies = (0, exports.initializeDependencies)(adapter, config, dependencies);
94
+ const endpointsMap = {};
95
+ for (const endpoint of adapter.endpoints) {
96
+ // Add aliases to map to use in validation
97
+ const aliases = [endpoint.name, ...(endpoint.aliases || [])];
98
+ for (const alias of aliases) {
99
+ if (endpointsMap[alias]) {
100
+ throw new Error(`Duplicate endpoint / alias: "${alias}"`);
101
+ }
102
+ endpointsMap[alias] = endpoint;
103
+ }
104
+ logger.debug(`Initializing transport for endpoint "${endpoint.name}"...`);
105
+ await endpoint.transport.initialize(initializedDependencies);
106
+ }
107
+ logger.debug('Adapter initialization complete.');
108
+ return {
109
+ ...adapter,
110
+ endpointsMap,
111
+ dependencies: initializedDependencies,
112
+ config,
113
+ };
114
+ };
115
+ exports.initializeAdapter = initializeAdapter;
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  import { AdapterEndpoint } from '../adapter';
2
- import { AdapterConfig, SettingsMap } from '../config';
2
+ import { AdapterConfig } from '../config';
3
3
  import { AdapterMiddlewareBuilder, AdapterResponse, sleep } from '../util';
4
4
  export * from './local';
5
5
  export * from './redis';
@@ -49,13 +49,13 @@ export interface Cache<T = unknown> {
49
49
  */
50
50
  delete: (key: string) => Promise<void>;
51
51
  }
52
- export declare const calculateCacheKey: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
53
- adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
54
- adapterConfig: AdapterConfig<CustomSettings>;
52
+ export declare const calculateCacheKey: ({ adapterEndpoint, adapterConfig, }: {
53
+ adapterEndpoint: AdapterEndpoint;
54
+ adapterConfig: AdapterConfig;
55
55
  }, data: unknown) => string;
56
- export declare const calculateFeedId: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
57
- adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
58
- adapterConfig: AdapterConfig<CustomSettings>;
56
+ export declare const calculateFeedId: ({ adapterEndpoint, adapterConfig, }: {
57
+ adapterEndpoint: AdapterEndpoint;
58
+ adapterConfig: AdapterConfig;
59
59
  }, data: unknown) => string;
60
60
  /**
61
61
  * Calculates a unique key from the provided data.
@@ -70,7 +70,7 @@ export declare const calculateFeedId: <Params, Result, CustomSettings extends Se
70
70
  * // equals `|base:eth|quote:btc`
71
71
  * ```
72
72
  */
73
- export declare const calculateKey: <CustomSettings extends SettingsMap>(data: unknown, paramNames: string[], adapterConfig: AdapterConfig<CustomSettings>) => string;
73
+ export declare const calculateKey: (data: unknown, paramNames: string[], adapterConfig: AdapterConfig) => string;
74
74
  /**
75
75
  * Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
76
76
  * amount of retries is exceeded, it returns undefined instead.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -80,11 +80,6 @@ export declare const BaseSettings: {
80
80
  readonly description: "TTL for batch warmer subscriptions";
81
81
  readonly default: 10000;
82
82
  };
83
- readonly WS_SUBSCRIPTION_TTL: {
84
- readonly description: "";
85
- readonly type: "number";
86
- readonly default: 120000;
87
- };
88
83
  readonly CACHE_POLLING_MAX_RETRIES: {
89
84
  readonly description: "Max amount of times to attempt to find EA response in the cache after the Transport has been set up";
90
85
  readonly type: "number";
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.buildAdapterConfig = exports.BaseSettings = void 0;
5
5
  exports.BaseSettings = {
6
6
  // V2 compat
7
+ // TODO: Remove non used in v3 ones
7
8
  API_ENDPOINT: {
8
9
  description: 'The URL that the certain transports use to retrieve data',
9
10
  type: 'string',
@@ -258,11 +259,10 @@ exports.BaseSettings = {
258
259
  // WS_SUBSCRIPTION_PRIORITY_LIST: {
259
260
  // type: 'string',
260
261
  // },
261
- WS_SUBSCRIPTION_TTL: {
262
- description: '',
263
- type: 'number',
264
- default: 120000,
265
- },
262
+ // WS_SUBSCRIPTION_TTL: {
263
+ // type: 'number',
264
+ // default: 120000,
265
+ // },
266
266
  // WS_SUBSCRIPTION_UNRESPONSIVE_TTL: {
267
267
  // type: 'number',
268
268
  // default: false,
File without changes
@@ -42,7 +42,11 @@ const getProviderLimits = (provider, limits, tier, protocol) => {
42
42
  return limitsConfig;
43
43
  };
44
44
  const parseLimits = (limits) => {
45
- const _mapObject = (fn) => (o) => Object.fromEntries(Object.entries(o).map(fn));
45
+ const _mapObject = (fn) => (o) => {
46
+ const entries = Object.entries(o);
47
+ const mapped = entries.map(fn);
48
+ return Object.fromEntries(mapped);
49
+ };
46
50
  const _formatProtocol = _mapObject((entry) => {
47
51
  const [tierName, rest] = entry;
48
52
  return [tierName.toLowerCase(), { ...rest }];
@@ -36,4 +36,4 @@ export declare class BankFrickAccountsTransport implements Transport<AdapterInpu
36
36
  */
37
37
  setup(req: AdapterRequest<AdapterInputParameters>, config: AdapterConfig<typeof customSettings>): Promise<AdapterResponse<number>>;
38
38
  }
39
- export declare const accountsRestEndpoint: AdapterEndpoint<AdapterInputParameters, number, import("../../config").SettingsMap>;
39
+ export declare const accountsRestEndpoint: AdapterEndpoint;
@@ -8,7 +8,6 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const util_1 = require("./util");
9
9
  const util_2 = require("../../util");
10
10
  const error_1 = require("../../validation/error");
11
- const adapter_1 = require("../../adapter");
12
11
  const logger = (0, util_2.makeLogger)('BankFrickTransport');
13
12
  // Note: this is a shallow pattern that only checks for a country code since IBANs in the sandbox are invalid
14
13
  const ibanPattern = /^[A-Z]{2}[A-Z\d]{14,30}$/;
@@ -185,8 +184,8 @@ class BankFrickAccountsTransport {
185
184
  }
186
185
  }
187
186
  exports.BankFrickAccountsTransport = BankFrickAccountsTransport;
188
- exports.accountsRestEndpoint = new adapter_1.AdapterEndpoint({
187
+ exports.accountsRestEndpoint = {
189
188
  name: 'accounts',
190
189
  transport: new BankFrickAccountsTransport(),
191
190
  inputParameters,
192
- });
191
+ };
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.adapter = void 0;
4
- const adapter_1 = require("../../adapter");
5
4
  const accounts_1 = require("./accounts");
6
5
  const config_1 = require("./config");
7
- exports.adapter = new adapter_1.Adapter({
6
+ exports.adapter = {
8
7
  name: 'bank-frick',
9
8
  defaultEndpoint: 'accounts',
10
9
  endpoints: [accounts_1.accountsRestEndpoint],
@@ -12,4 +11,4 @@ exports.adapter = new adapter_1.Adapter({
12
11
  envDefaultOverrides: {
13
12
  API_ENDPOINT: 'https://olbsandbox.bankfrick.li/webapi/v2',
14
13
  },
15
- });
14
+ };
@@ -0,0 +1,2 @@
1
+ import { Adapter } from '../../adapter';
2
+ export declare const adapter: Adapter;
File without changes
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.expose = void 0;
7
7
  const fastify_1 = __importDefault(require("fastify"));
8
8
  const path_1 = require("path");
9
+ const adapter_1 = require("./adapter");
9
10
  const background_executor_1 = require("./background-executor");
10
11
  const cache_1 = require("./cache");
12
+ const config_1 = require("./config");
11
13
  const metrics_1 = require("./metrics");
12
14
  const transports_1 = require("./transports");
13
15
  const util_1 = require("./util");
@@ -24,18 +26,22 @@ const VERSION = process.env['npm_package_version'];
24
26
  * @returns a Promise that resolves to the http.Server listening for connections
25
27
  */
26
28
  const expose = async (adapter, dependencies) => {
29
+ const config = (0, config_1.buildAdapterConfig)({
30
+ overrides: adapter.envDefaultOverrides,
31
+ customSettings: adapter.customSettings,
32
+ });
27
33
  // Initialize adapter (create dependencies, inject them, build endpoint map, etc.)
28
- await adapter.initialize(dependencies);
34
+ const initializedAdapter = await (0, adapter_1.initializeAdapter)(adapter, config, dependencies);
29
35
  let server = undefined;
30
- if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
31
- (0, metrics_1.setupMetricsServer)(adapter.name, adapter.config);
36
+ if (config.METRICS_ENABLED && config.EXPERIMENTAL_METRICS_ENABLED) {
37
+ (0, metrics_1.setupMetricsServer)(adapter.name, config);
32
38
  }
33
- if (adapter.config.EA_MODE === 'reader' || adapter.config.EA_MODE === 'reader-writer') {
39
+ if (config.EA_MODE === 'reader' || config.EA_MODE === 'reader-writer') {
34
40
  // Main REST API server to handle incoming requests
35
- const app = await buildRestApi(adapter);
41
+ const app = await buildRestApi(config, initializedAdapter);
36
42
  // Start listening for incoming requests
37
43
  try {
38
- await app.listen(adapter.config.EA_PORT, adapter.config.EA_HOST);
44
+ await app.listen(config.EA_PORT, config.EA_HOST);
39
45
  }
40
46
  catch (err) {
41
47
  logger.fatal(`There was an error when starting the EA server: ${err}`);
@@ -47,10 +53,10 @@ const expose = async (adapter, dependencies) => {
47
53
  else {
48
54
  logger.info('REST API is disabled; this instance will not process incoming requests.');
49
55
  }
50
- if (adapter.config.EA_MODE === 'writer' || adapter.config.EA_MODE === 'reader-writer') {
56
+ if (config.EA_MODE === 'writer' || config.EA_MODE === 'reader-writer') {
51
57
  // Start background loop that will take care of calling any async Transports
52
58
  logger.info('Starting background execution loop');
53
- (0, background_executor_1.callBackgroundExecutes)(adapter, server);
59
+ (0, background_executor_1.callBackgroundExecutes)(initializedAdapter, server);
54
60
  }
55
61
  else {
56
62
  logger.info('Background executor is disabled; this instance will not perform async background executes.');
@@ -58,8 +64,7 @@ const expose = async (adapter, dependencies) => {
58
64
  return server;
59
65
  };
60
66
  exports.expose = expose;
61
- async function buildRestApi(adapter) {
62
- const { config } = adapter;
67
+ async function buildRestApi(config, initializedAdapter) {
63
68
  const app = (0, fastify_1.default)();
64
69
  // Add healthcheck endpoint before middlewares to bypass them
65
70
  app.get((0, path_1.join)(config.BASE_URL, 'health'), (req, res) => {
@@ -67,11 +72,11 @@ async function buildRestApi(adapter) {
67
72
  });
68
73
  // Use global error handling
69
74
  app.setErrorHandler(validation_1.errorCatchingMiddleware);
70
- const transportHandler = await (0, transports_1.buildTransportHandler)(adapter);
75
+ const transportHandler = await (0, transports_1.buildTransportHandler)(initializedAdapter);
71
76
  app.register(async (router) => {
72
77
  // Set up "middlewares" (hooks in fastify)
73
- router.addHook('preHandler', (0, validation_1.validatorMiddleware)(adapter));
74
- router.addHook('preHandler', (0, cache_1.buildCacheMiddleware)(adapter));
78
+ router.addHook('preHandler', (0, validation_1.validatorMiddleware)(initializedAdapter));
79
+ router.addHook('preHandler', (0, cache_1.buildCacheMiddleware)(initializedAdapter));
75
80
  if (config['CORRELATION_ID_ENABLED']) {
76
81
  router.addHook('onRequest', util_1.loggingContextMiddleware);
77
82
  }
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ import { AdapterMetricsMeta, AdapterRequestData } from '../util';
2
+ import { AdapterEndpoint } from '../adapter';
3
+ import { AdapterConfig } from '../config';
4
+ export declare const getMetricsMeta: ({ adapterEndpoint, adapterConfig, }: {
5
+ adapterEndpoint: AdapterEndpoint;
6
+ adapterConfig: AdapterConfig;
7
+ }, data: AdapterRequestData) => AdapterMetricsMeta;
File without changes
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Server } from 'http';
3
- import { Adapter } from './adapter';
3
+ import { InitializedAdapter } from './adapter';
4
4
  /**
5
5
  * Very simple background loop that will call the [[Transport.backgroundExecute]] functions in all Transports.
6
6
  * It gets the time in ms to wait as the return value from those functions, and sleeps until next execution.
@@ -8,4 +8,4 @@ import { Adapter } from './adapter';
8
8
  * @param adapter - an initialized External Adapter
9
9
  * @param server - the http server to attach an on close listener to
10
10
  */
11
- export declare function callBackgroundExecutes(adapter: Adapter, server?: Server): Promise<void>;
11
+ export declare function callBackgroundExecutes(adapter: InitializedAdapter, server?: Server): Promise<void>;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ import { AdapterEndpoint } from '../../adapter';
2
+ export declare const batchEndpoint: AdapterEndpoint;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.batchEndpoint = void 0;
4
- const adapter_1 = require("../../adapter");
5
4
  const batch_warming_1 = require("../../transports/batch-warming");
6
5
  const DEFAULT_URL = 'https://pro-api.coingecko.com/api/v3';
7
6
  const inputParameters = {
@@ -46,8 +45,8 @@ const batchEndpointTransport = new batch_warming_1.BatchWarmingTransport({
46
45
  return entries;
47
46
  },
48
47
  });
49
- exports.batchEndpoint = new adapter_1.AdapterEndpoint({
48
+ exports.batchEndpoint = {
50
49
  name: 'batch',
51
50
  transport: batchEndpointTransport,
52
51
  inputParameters,
53
- });
52
+ };
@@ -0,0 +1,2 @@
1
+ import { Adapter } from '../../adapter';
2
+ export declare const adapter: Adapter;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.adapter = void 0;
4
- const adapter_1 = require("../../adapter");
5
4
  const batch_warming_1 = require("./batch-warming");
6
5
  const rest_1 = require("./rest");
7
- exports.adapter = new adapter_1.Adapter({
6
+ exports.adapter = {
8
7
  name: 'coingecko',
9
8
  defaultEndpoint: 'batch',
10
9
  endpoints: [rest_1.restEndpoint, batch_warming_1.batchEndpoint],
11
- });
10
+ };