@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
@@ -1,246 +0,0 @@
1
- import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
2
- import {
3
- Account,
4
- AdapterInputParameters,
5
- BankFrickAccountsRequestSchema,
6
- BankFrickAccountsResponseSchema,
7
- SigningAlgorithm,
8
- } from './types'
9
- import { customSettings } from './config'
10
- import { Transport } from '../../transports'
11
- import { generateJWT } from './util'
12
- import { AdapterRequest, AdapterResponse, makeLogger, sleep } from '../../util'
13
- import { AdapterConfig } from '../../config'
14
- import { AdapterError } from '../../validation/error'
15
- import { Cache } from '../../cache'
16
- import { InputParameters } from '../../validation'
17
- import { AdapterDependencies, AdapterEndpoint } from '../../adapter'
18
-
19
- const logger = makeLogger('BankFrickTransport')
20
-
21
- // Note: this is a shallow pattern that only checks for a country code since IBANs in the sandbox are invalid
22
- const ibanPattern = /^[A-Z]{2}[A-Z\d]{14,30}$/
23
- const inputParameters: InputParameters = {
24
- ibanIDs: {
25
- description: 'The list of account ids included in the sum of balances',
26
- required: true,
27
- type: 'array',
28
- },
29
- signingAlgorithm: {
30
- description:
31
- 'What signing algorithm is used to sign and verify authorization data, one of rsa-sha256, rsa-sha384, or rsa-sha512',
32
- required: false,
33
- type: 'string',
34
- default: 'rsa-sha512',
35
- options: ['rsa-sha256', 'rsa-sha384', 'rsa-sha512'],
36
- },
37
- }
38
-
39
- // See here for all expected error returned by the API: https://developers.bankfrick.li/docs#errors
40
- const AuthErrors: { [key: number]: string } = {
41
- 401: 'No JWT token provided or token is invalid',
42
- 403: 'API key is invalid or any other condition is hindering the login', // Unclear if this is fatal or not
43
- }
44
- const FatalErrors: { [key: number]: string } = {
45
- 400: "Invalid parameters passed to Bank Frick's API",
46
- 423: "Authorization is valid, but the user's account is locked",
47
- }
48
-
49
- /**
50
- * RestTransport implementation for Bank Frick, which has unusually complex requirements for an EA
51
- * The RestTransport is generally built to make a single request and return a single response.
52
- * This transport instead is used to fetch and process pages of data, and also requires a JWT to run
53
- *
54
- * This transport does all the heavy lifting in setup(), which is where the paging happens, and it
55
- * also has complex retry logic that will attempt to refresh the JWT when certain HTTP errors occur
56
- */
57
- export class BankFrickAccountsTransport
58
- implements Transport<AdapterInputParameters, number, typeof customSettings>
59
- {
60
- // Global variable to keep the token. Token is provisioned when the accounts endpoint is hit.
61
- // Each instance of the EA will have their own token by design
62
- token!: string
63
- cache!: Cache
64
-
65
- async initialize(dependencies: AdapterDependencies): Promise<void> {
66
- this.cache = dependencies.cache
67
- }
68
-
69
- async hasBeenSetUp() {
70
- return false // Return false since we aren't coalescing requests
71
- }
72
-
73
- /**
74
- * Creates an AxiosRequestConfig object for fetching a page of accounts from the Bank Frick API
75
- */
76
- prepareRequest(
77
- firstPosition: number,
78
- inputParams: AdapterInputParameters,
79
- config: AdapterConfig<typeof customSettings>,
80
- ): AxiosRequestConfig<BankFrickAccountsRequestSchema> {
81
- const { API_ENDPOINT, BASE_URL, PAGE_SIZE } = config
82
-
83
- return {
84
- baseURL: API_ENDPOINT + BASE_URL,
85
- url: 'accounts',
86
- method: 'GET',
87
- params: {
88
- firstPosition,
89
- maxResults: PAGE_SIZE,
90
- },
91
- headers: {
92
- Authorization: `Bearer ${this.token}`,
93
- },
94
- }
95
- }
96
-
97
- /**
98
- * Request with retry logic for Bank Frick's API. In addition to standard retry logic, this function
99
- * compares errors against expected errors from the Bank Frick API, and will throw without retries
100
- * on a known fatal error, or try to refresh the JWT on a known auth error
101
- **/
102
- async makeRequest(
103
- axiosRequest: AxiosRequestConfig<BankFrickAccountsRequestSchema>,
104
- config: AdapterConfig<typeof customSettings>,
105
- signingAlgorithm?: SigningAlgorithm,
106
- ): Promise<AxiosResponse<BankFrickAccountsResponseSchema>> {
107
- let retryNumber = 0
108
- let response = await axios.request(axiosRequest)
109
- while (response.status !== 200) {
110
- retryNumber++
111
- logger.warn(
112
- 'Encountered error when fetching accounts from Bank Frick:',
113
- response.status,
114
- response.statusText,
115
- )
116
-
117
- // Evaluate whether the error was fatal, auth, or transient and whether we've exceeded the max number of retries.
118
- // Throw on fatal, refresh token on auth error, pass on transient until we've exhausted our retries
119
- if (FatalErrors[response.status]) {
120
- throw new AdapterError({
121
- statusCode: response.status,
122
- message: response.statusText,
123
- })
124
- } else if (AuthErrors[response.status]) {
125
- // We've encountered a known auth error, so try to refresh the token before making another request
126
- logger.info('Auth error received from the Bank Frick API, attempting to refresh the token')
127
- this.token = await generateJWT(config, signingAlgorithm)
128
- } else if (retryNumber === config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES) {
129
- throw new AdapterError({
130
- statusCode: 504,
131
- message: `Bank Frick transport hit the max number of retries (${config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES} retries) and aborted`,
132
- })
133
- }
134
-
135
- logger.debug(
136
- `Sleeping for ${config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES}ms before retrying`,
137
- )
138
- await sleep(config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES)
139
- response = await axios.request(axiosRequest)
140
- }
141
- return response
142
- }
143
-
144
- validateInputParams(params: AdapterInputParameters): string[] {
145
- const encounteredIds: { [key: string]: number } = {}
146
- const errors: string[] = []
147
- const { ibanIDs } = params
148
-
149
- ibanIDs.forEach((v) => {
150
- if (!v.match(ibanPattern)) {
151
- errors.push(`Invalid IBAN: ${v}`)
152
- }
153
- encounteredIds[v] += 1
154
- if (encounteredIds[v] > 1) {
155
- errors.push(`The following IBAN appears more than once in the input parameters: ${v}`)
156
- }
157
- })
158
- return errors
159
- }
160
-
161
- /**
162
- * Fetches pages of data from the Bank Frick API, scans for accounts by IBAN, and returns the balance
163
- * of all found accounts. Returns a 404 if any IBAN isn't found.
164
- */
165
- async setup(
166
- req: AdapterRequest<AdapterInputParameters>,
167
- config: AdapterConfig<typeof customSettings>,
168
- ): Promise<AdapterResponse<number>> {
169
- const { ibanIDs, signingAlgorithm } = req.requestContext.data
170
- const { PAGE_SIZE = 500 } = config
171
-
172
- logger.debug(`Validating input: ${JSON.stringify(req.requestContext.data)}`)
173
-
174
- // Scan ibanIDs for duplicates and invalid IBANs
175
- const validationErrors = this.validateInputParams(req.requestContext.data)
176
- if (validationErrors.length > 0) {
177
- throw new AdapterError({
178
- statusCode: 420,
179
- message: `Received the following errors when validating inputParameters:\n ${validationErrors.join(
180
- '\n',
181
- )}`,
182
- })
183
- }
184
-
185
- // Refresh the token if it isn't set
186
- if (!this.token) {
187
- this.token = await generateJWT(config, signingAlgorithm)
188
- }
189
-
190
- let sum = 0
191
- let position = 0
192
- const keys = ibanIDs
193
- logger.info("Fetching accounts from Bank Frick's API...")
194
- while (keys.length > 0) {
195
- // TODO Fetching and processing pages can be run concurrently
196
- const axiosRequest = this.prepareRequest(position, req.requestContext.data, config)
197
- const response = await this.makeRequest(axiosRequest, config, signingAlgorithm)
198
-
199
- logger.debug(`Evaluating accounts from page ${position / PAGE_SIZE}`)
200
- response.data.accounts.forEach((v: Account) => {
201
- logger.trace(`Evaluating ${v.account} (iban: ${v.iban}, type: ${v.type})`)
202
- const index = ibanIDs.indexOf(v.iban)
203
- if (index > -1) {
204
- keys.splice(index, 1)
205
- sum += v.balance
206
- logger.trace(`Found account: ${v.account} (iban: ${v.iban}) with balance of ${v.balance}`)
207
- logger.trace(
208
- `Running sum: ${sum}, number of ibans left to find: ${keys.length}/${ibanIDs.length}`,
209
- )
210
- }
211
- })
212
-
213
- if (!response.data.moreResults) {
214
- logger.debug('No more results, breaking out of account query loop')
215
- break
216
- }
217
- position += PAGE_SIZE || 0
218
- }
219
-
220
- // 404 if one or more accounts were not found
221
- if (keys.length > 0) {
222
- logger.error(`Could not find all accounts, returning 404: ${keys.join(', ')}`)
223
- const res = {
224
- data: 0,
225
- statusCode: 404,
226
- result: 0,
227
- }
228
- await this.cache.set(req.requestContext.cacheKey, res, config.CACHE_MAX_AGE)
229
- }
230
-
231
- logger.debug('Was able to find all accounts, returning balance across all accounts: ', sum)
232
- const res = {
233
- data: sum,
234
- statusCode: 200,
235
- result: sum,
236
- }
237
- await this.cache.set(req.requestContext.cacheKey, res, config.CACHE_MAX_AGE)
238
- return res
239
- }
240
- }
241
-
242
- export const accountsRestEndpoint: AdapterEndpoint = {
243
- name: 'accounts',
244
- transport: new BankFrickAccountsTransport(),
245
- inputParameters,
246
- }
@@ -1,53 +0,0 @@
1
- import { SettingsMap } from '../../../config'
2
- import crypto from 'crypto'
3
- import { SigningAlgorithm } from '../types'
4
- import { makeLogger } from '../../../util'
5
-
6
- const logger = makeLogger('BankFrickConfig')
7
-
8
- // Used for enum options and validation
9
- export const signingAlgorithms: SigningAlgorithm[] = ['rsa-sha256', 'rsa-sha384', 'rsa-sha512']
10
- const MAX_PAGE_SIZE = 500
11
-
12
- export const customSettings: SettingsMap = {
13
- PAGE_SIZE: {
14
- description: 'The number of accounts to fetch per call to /accounts. Must be >= 1 and <= 500.',
15
- type: 'number',
16
- required: false,
17
- default: MAX_PAGE_SIZE,
18
- validate: (value) => {
19
- if (!value) {
20
- return ''
21
- } else if (value < 1) {
22
- return `PAGE_SIZE must be at least >= 1, was ${value}`
23
- } else if (value > MAX_PAGE_SIZE) {
24
- return `PAGE_SIZE must be <= 500, was ${value}`
25
- }
26
- },
27
- },
28
- PRIVATE_KEY: {
29
- description: '',
30
- type: 'string',
31
- required: true,
32
- validate: (value) => {
33
- const failedAlgos: SigningAlgorithm[] = []
34
- for (const algorithm of signingAlgorithms) {
35
- const body = { example: 123 }
36
- try {
37
- crypto.sign(algorithm, Buffer.from(JSON.stringify(body)), value)
38
- logger.trace("Successfully tested PRIVATE_KEY by signing with algorithm '%s'", algorithm)
39
- } catch {
40
- logger.trace("PRIVATE_KEY failed to sign message with algorithm '%s'", algorithm)
41
- failedAlgos.push(algorithm)
42
- }
43
- }
44
-
45
- if (failedAlgos.length > 0) {
46
- return `Failed to sign a dummy body using $PRIVATE_KEY with the following algorithms ${failedAlgos.join(
47
- ',',
48
- )}`
49
- }
50
- logger.debug('$PRIVATE_KEY successfully signed a dummy body with all supported algorithms')
51
- },
52
- },
53
- } as const
@@ -1,13 +0,0 @@
1
- import { Adapter } from '../../adapter'
2
- import { accountsRestEndpoint } from './accounts'
3
- import { customSettings } from './config'
4
-
5
- export const adapter: Adapter = {
6
- name: 'bank-frick',
7
- defaultEndpoint: 'accounts',
8
- endpoints: [accountsRestEndpoint],
9
- customSettings,
10
- envDefaultOverrides: {
11
- API_ENDPOINT: 'https://olbsandbox.bankfrick.li/webapi/v2',
12
- },
13
- }
@@ -1,38 +0,0 @@
1
- export interface Account {
2
- account: string // The account number of the account
3
- type: string // The type of the account
4
- iban: string // The iban of the account if exists
5
- customer: string // The customer data of the account which consists of the customer number and name
6
- currency: string // The account currency
7
- balance: number // The current account balance
8
- available: number // The available amount of the account as defined in the online banking
9
- }
10
- /**
11
- * Types representing what we send/receive from the bank frick api
12
- * See https://developers.bankfrick.li/docs#data-types for details
13
- */
14
- export interface BankFrickAccountsResponseSchema {
15
- errors?: string[]
16
- date: Date
17
- moreResults: boolean
18
- resultSetSize: number
19
- accounts: Account[]
20
- }
21
- export interface BankFrickAccountsRequestSchema {
22
- firstPosition: number
23
- maxResults: number
24
- }
25
-
26
- /**
27
- * Types representing the input parameters and response of the adapter
28
- */
29
- export interface AdapterInputParameters {
30
- ibanIDs: string[]
31
- signingAlgorithm?: SigningAlgorithm
32
- }
33
-
34
- /**
35
- * These are the options from the docs, but it's hard to see. See the first paragraph from this
36
- * page for details: https://developers.bankfrick.li/docs#getting-started-signatures
37
- */
38
- export type SigningAlgorithm = 'dsa-sha512' | 'rsa-sha256' | 'rsa-sha384' | 'rsa-sha512'
@@ -1,55 +0,0 @@
1
- import crypto from 'crypto'
2
- import { SigningAlgorithm } from './types'
3
- import { customSettings } from './config'
4
- import axios, { AxiosRequestConfig } from 'axios'
5
- import { makeLogger } from '../../util'
6
- import { AdapterConfig } from '../../config'
7
-
8
- interface TokenResponseBody {
9
- errors?: string[]
10
- token: string
11
- }
12
- interface TokenRequestBody {
13
- key: string
14
- }
15
-
16
- const logger = makeLogger('BankFrickUtil')
17
-
18
- // Used by all endpoints requiring authentication
19
- export const generateJWT = async (
20
- config: AdapterConfig<typeof customSettings>,
21
- signingAlgorithm: SigningAlgorithm = 'rsa-sha512',
22
- ): Promise<string> => {
23
- logger.info("Generating a new JWT because we don't have one in config.token")
24
- const { API_KEY, PRIVATE_KEY, API_ENDPOINT } = config
25
-
26
- // All of these are required, so validation should have failed prior to this line
27
- if (!API_KEY || !PRIVATE_KEY) {
28
- throw new Error(
29
- 'API_KEY, PRIVATE_KEY, and PASSWORD all must be defined to get a new token\n' +
30
- 'Received: \n' +
31
- `API_KEY: ${API_KEY}\n` +
32
- `PRIVATE_KEY: ${PRIVATE_KEY}`,
33
- )
34
- }
35
-
36
- const data: TokenRequestBody = {
37
- key: API_KEY,
38
- }
39
-
40
- const signature = crypto.sign(signingAlgorithm, Buffer.from(JSON.stringify(data)), PRIVATE_KEY)
41
- const options: AxiosRequestConfig<TokenRequestBody> = {
42
- method: 'POST',
43
- baseURL: API_ENDPOINT,
44
- url: `authorize`,
45
- headers: {
46
- Signature: signature.toString('base64'),
47
- algorithm: signingAlgorithm,
48
- },
49
- data,
50
- }
51
-
52
- const response = await axios.request<TokenResponseBody>(options)
53
-
54
- return response.data.token
55
- }
@@ -1,78 +0,0 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios'
2
- import { AdapterContext, AdapterEndpoint } from '../../adapter'
3
- import { BatchWarmingTransport } from '../../transports/batch-warming'
4
- import { ProviderResult } from '../../util'
5
- import { InputParameters } from '../../validation'
6
-
7
- const DEFAULT_URL = 'https://pro-api.coingecko.com/api/v3'
8
-
9
- interface AdapterRequestParams {
10
- base: string
11
- quote: string
12
- }
13
-
14
- const inputParameters: InputParameters = {
15
- coinid: {
16
- description:
17
- 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
18
- required: false,
19
- },
20
- base: {
21
- aliases: ['from', 'coin'],
22
- description: 'The symbol or array of symbols of the currency to query',
23
- required: true,
24
- },
25
- quote: {
26
- aliases: ['to', 'market'],
27
- description: 'The symbol of the currency to convert to',
28
- required: true,
29
- },
30
- }
31
- interface ProviderRequestBody {
32
- ids: string
33
- vs_currencies: string
34
- }
35
-
36
- interface ProviderResponseBody {
37
- [base: string]: {
38
- [quote: string]: number
39
- }
40
- }
41
-
42
- const batchEndpointTransport = new BatchWarmingTransport({
43
- prepareRequest: (
44
- params: AdapterRequestParams[],
45
- context: AdapterContext,
46
- ): AxiosRequestConfig<ProviderRequestBody> => {
47
- return {
48
- baseURL: DEFAULT_URL,
49
- url: '/simple/price',
50
- method: 'GET',
51
- params: {
52
- ids: [...new Set(params.map((p) => p.base))].join(','),
53
- vs_currencies: [...new Set(params.map((p) => p.quote))].join(','),
54
- x_cg_pro_api_key: context.adapterConfig.API_KEY,
55
- },
56
- }
57
- },
58
- parseResponse: (
59
- res: AxiosResponse<ProviderResponseBody>,
60
- ): ProviderResult<AdapterRequestParams>[] => {
61
- const entries = [] as ProviderResult<AdapterRequestParams>[]
62
- for (const [base, entry] of Object.entries(res.data)) {
63
- for (const [quote, price] of Object.entries(entry)) {
64
- entries.push({
65
- params: { base, quote },
66
- value: price,
67
- })
68
- }
69
- }
70
- return entries
71
- },
72
- })
73
-
74
- export const batchEndpoint: AdapterEndpoint = {
75
- name: 'batch',
76
- transport: batchEndpointTransport,
77
- inputParameters,
78
- }
@@ -1,9 +0,0 @@
1
- import { Adapter } from '../../adapter'
2
- import { batchEndpoint } from './batch-warming'
3
- import { restEndpoint } from './rest'
4
-
5
- export const adapter: Adapter = {
6
- name: 'coingecko',
7
- defaultEndpoint: 'batch',
8
- endpoints: [restEndpoint, batchEndpoint],
9
- }
@@ -1,77 +0,0 @@
1
- import { AxiosRequestConfig, AxiosResponse } from 'axios'
2
- import { AdapterEndpoint } from '../../adapter'
3
- import { RestTransport } from '../../transports'
4
- import { AdapterRequest, AdapterResponse } from '../../util'
5
- import { InputParameters } from '../../validation'
6
-
7
- const DEFAULT_URL = 'https://api.coingecko.com/api/v3'
8
-
9
- interface AdapterRequestParams {
10
- base: string
11
- quote: string
12
- }
13
-
14
- const inputParameters: InputParameters = {
15
- coinid: {
16
- description:
17
- 'The CoinGecko id or array of ids of the coin(s) to query (Note: because of current limitations to use a dummy base will need to be supplied)',
18
- required: false,
19
- },
20
- base: {
21
- aliases: ['from', 'coin'],
22
- description: 'The symbol or array of symbols of the currency to query',
23
- required: true,
24
- },
25
- quote: {
26
- aliases: ['to', 'market'],
27
- description: 'The symbol of the currency to convert to',
28
- required: true,
29
- },
30
- }
31
-
32
- interface ProviderRequestBody {
33
- ids: string
34
- vs_currencies: string
35
- }
36
-
37
- interface ProviderResponseBody {
38
- [base: string]: {
39
- [quote: string]: number
40
- }
41
- }
42
-
43
- const restEndpointTransport = new RestTransport({
44
- prepareRequest: (
45
- req: AdapterRequest<AdapterRequestParams>,
46
- ): AxiosRequestConfig<ProviderRequestBody> => {
47
- return {
48
- baseURL: DEFAULT_URL,
49
- url: '/simple/price',
50
- method: 'GET',
51
- params: {
52
- ids: req.requestContext.data.base,
53
- vs_currencies: req.requestContext.data.quote,
54
- },
55
- }
56
- },
57
- parseResponse: (
58
- req: AdapterRequest<AdapterRequestParams>,
59
- res: AxiosResponse<ProviderResponseBody>,
60
- ): AdapterResponse<ProviderResponseBody> => {
61
- return {
62
- data: res.data,
63
- statusCode: 200,
64
- result: res.data[req.requestContext.data.base]?.[req.requestContext.data.quote],
65
- }
66
- },
67
- options: {
68
- coalescing: true,
69
- },
70
- })
71
-
72
- export const restEndpoint: AdapterEndpoint = {
73
- name: 'rest',
74
- aliases: ['qwe'],
75
- transport: restEndpointTransport,
76
- inputParameters,
77
- }
@@ -1,12 +0,0 @@
1
- export const customSettings = {
2
- USERNAME: {
3
- description: 'Username for the NCFX API',
4
- type: 'string',
5
- required: true,
6
- },
7
- PASSWORD: {
8
- description: 'Password for the NCFX API',
9
- type: 'string',
10
- required: true,
11
- },
12
- } as const
@@ -1,9 +0,0 @@
1
- import { Adapter } from '../../adapter'
2
- import { customSettings } from './config'
3
- import { webSocketEndpoint } from './websocket'
4
-
5
- export const adapter: Adapter = {
6
- name: 'ncfx',
7
- endpoints: [webSocketEndpoint],
8
- customSettings,
9
- }
@@ -1,99 +0,0 @@
1
- import { RawData, WebSocket } from 'ws'
2
- import { AdapterContext, AdapterEndpoint } from '../../adapter'
3
- import { WebSocketTransport } from '../../transports/websocket'
4
- import { ProviderResult, makeLogger } from '../../util'
5
- import { InputParameters } from '../../validation'
6
- import { customSettings } from './config'
7
-
8
- interface AdapterRequestParams {
9
- base: string
10
- quote: string
11
- }
12
-
13
- export const inputParameters: InputParameters = {
14
- base: {
15
- aliases: ['from', 'coin'],
16
- description: 'The symbol of the currency to query',
17
- required: true,
18
- },
19
- quote: {
20
- aliases: ['to', 'market'],
21
- description: 'The symbol of the currency to convert to',
22
- required: true,
23
- },
24
- }
25
-
26
- interface ProviderMessage {
27
- timestamp: string
28
- currencyPair: string
29
- bid: number
30
- offer: number
31
- mid: number
32
- changes: [
33
- {
34
- period: string
35
- change: number
36
- percentage: number
37
- },
38
- ]
39
- }
40
-
41
- const logger = makeLogger('NcfxWebSocketTransport')
42
-
43
- export const websocketTransport = new WebSocketTransport({
44
- url: 'wss://feed.newchangefx.com/cryptodata',
45
- handlers: {
46
- open(connection: WebSocket, context: AdapterContext<typeof customSettings>) {
47
- return new Promise((resolve, reject) => {
48
- // Set up listener
49
- connection.on('message', (data: RawData) => {
50
- const parsed = JSON.parse(data.toString())
51
- if (parsed.Message?.startsWith('Logged in as user')) {
52
- logger.info('Got logged in response, connection is ready')
53
- resolve()
54
- } else {
55
- reject(new Error('Unexpected message after WS connection open'))
56
- }
57
- })
58
- // Send login payload
59
- connection.send(
60
- JSON.stringify({
61
- request: 'login',
62
- username: context.adapterConfig.USERNAME,
63
- password: context.adapterConfig.PASSWORD,
64
- }),
65
- )
66
- })
67
- },
68
-
69
- message(message: ProviderMessage[]): ProviderResult<AdapterRequestParams>[] {
70
- if (!Array.isArray(message)) {
71
- logger.debug('WS message is not array, skipping')
72
- return []
73
- }
74
- return message.map((m) => {
75
- const [base, quote] = m.currencyPair.split('/')
76
- return {
77
- params: { base, quote },
78
- value: m.offer,
79
- }
80
- })
81
- },
82
- },
83
- builders: {
84
- subscribeMessage: (params: AdapterRequestParams) => ({
85
- request: 'subscribe',
86
- ccy: `${params.base}/${params.quote}`,
87
- }),
88
- unsubscribeMessage: (params: AdapterRequestParams) => ({
89
- request: 'unsubscribe',
90
- ccy: `${params.base}/${params.quote}`,
91
- }),
92
- },
93
- })
94
-
95
- export const webSocketEndpoint: AdapterEndpoint = {
96
- name: 'websocket',
97
- transport: websocketTransport,
98
- inputParameters,
99
- }