@chainlink/external-adapter-framework 0.0.15 → 0.0.17

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 (186) hide show
  1. package/adapter.js +128 -0
  2. package/background-executor.js +45 -0
  3. package/cache/factory.js +58 -0
  4. package/cache/index.js +173 -0
  5. package/cache/local.js +83 -0
  6. package/cache/metrics.js +120 -0
  7. package/cache/redis.js +100 -0
  8. package/chainlink-external-adapter-framework-v0.0.6.tgz +0 -0
  9. package/config/index.js +366 -0
  10. package/config/provider-limits.js +74 -0
  11. package/examples/bank-frick/accounts.js +192 -0
  12. package/examples/bank-frick/config/index.js +54 -0
  13. package/examples/bank-frick/index.js +15 -0
  14. package/examples/bank-frick/util.js +39 -0
  15. package/examples/coingecko/batch-warming.js +53 -0
  16. package/examples/coingecko/index.js +11 -0
  17. package/examples/coingecko/rest.js +51 -0
  18. package/examples/coingecko/src/config/index.js +13 -0
  19. package/examples/coingecko/src/config/overrides.json +10826 -0
  20. package/examples/coingecko/src/cryptoUtils.js +41 -0
  21. package/examples/coingecko/src/endpoint/coins.js +33 -0
  22. package/examples/coingecko/src/endpoint/crypto-marketcap.js +46 -0
  23. package/examples/coingecko/src/endpoint/crypto-volume.js +46 -0
  24. package/examples/coingecko/src/endpoint/crypto.js +47 -0
  25. package/examples/coingecko/src/endpoint/dominance.js +26 -0
  26. package/examples/coingecko/src/endpoint/global-marketcap.js +26 -0
  27. package/examples/coingecko/src/endpoint/index.js +15 -0
  28. package/examples/coingecko/src/globalUtils.js +48 -0
  29. package/examples/coingecko/src/index.js +14 -0
  30. package/examples/coingecko/test/e2e/adapter.test.js +262 -0
  31. package/examples/coingecko/test/integration/adapter.test.js +264 -0
  32. package/examples/coingecko/test/integration/capturedRequests.json +1 -0
  33. package/examples/coingecko/test/integration/fixtures.js +41 -0
  34. package/examples/coingecko-old/batch-warming.js +53 -0
  35. package/examples/coingecko-old/index.js +11 -0
  36. package/examples/coingecko-old/rest.js +51 -0
  37. package/examples/ncfx/config/index.js +15 -0
  38. package/examples/ncfx/index.js +11 -0
  39. package/examples/ncfx/websocket.js +73 -0
  40. package/index.js +127 -0
  41. package/metrics/constants.js +25 -0
  42. package/metrics/index.js +122 -0
  43. package/metrics/util.js +9 -0
  44. package/package.json +5 -15
  45. package/rate-limiting/background/fixed-frequency.js +35 -0
  46. package/rate-limiting/index.js +84 -0
  47. package/rate-limiting/metrics.js +44 -0
  48. package/rate-limiting/request/simple-counting.js +62 -0
  49. package/test.js +6 -0
  50. package/transports/batch-warming.js +101 -0
  51. package/transports/index.js +87 -0
  52. package/transports/metrics.js +105 -0
  53. package/transports/rest.js +138 -0
  54. package/transports/util.js +86 -0
  55. package/transports/websocket.js +166 -0
  56. package/util/index.js +35 -0
  57. package/util/logger.js +62 -0
  58. package/util/recordRequests.js +45 -0
  59. package/util/request.js +2 -0
  60. package/util/subscription-set/expiring-sorted-set.js +47 -0
  61. package/util/subscription-set/subscription-set.js +19 -0
  62. package/util/test-payload-loader.js +83 -0
  63. package/validation/error.js +79 -0
  64. package/validation/index.js +91 -0
  65. package/validation/input-params.js +30 -0
  66. package/validation/override-functions.js +40 -0
  67. package/validation/overrideFunctions.js +40 -0
  68. package/validation/preset-tokens.json +23 -0
  69. package/validation/validator.js +303 -0
  70. package/.c8rc.json +0 -3
  71. package/.eslintignore +0 -10
  72. package/.eslintrc.js +0 -96
  73. package/.github/README.MD +0 -42
  74. package/.github/actions/setup/action.yaml +0 -13
  75. package/.github/workflows/label.yaml +0 -39
  76. package/.github/workflows/main.yaml +0 -39
  77. package/.github/workflows/publish.yaml +0 -17
  78. package/.prettierignore +0 -13
  79. package/.yarnrc +0 -0
  80. package/README.md +0 -103
  81. package/dist/examples/coingecko/test/e2e/adapter.test.ts.js +0 -82953
  82. package/dist/examples/coingecko/test/integration/adapter.test.ts.js +0 -91672
  83. package/dist/main.js +0 -72703
  84. package/docker-compose.yaml +0 -35
  85. package/env.sh +0 -54
  86. package/env2.sh +0 -55
  87. package/jest.config.js +0 -5
  88. package/publish.sh +0 -0
  89. package/src/adapter.ts +0 -263
  90. package/src/background-executor.ts +0 -52
  91. package/src/cache/factory.ts +0 -26
  92. package/src/cache/index.ts +0 -258
  93. package/src/cache/local.ts +0 -73
  94. package/src/cache/metrics.ts +0 -112
  95. package/src/cache/redis.ts +0 -93
  96. package/src/config/index.ts +0 -517
  97. package/src/config/provider-limits.ts +0 -127
  98. package/src/examples/bank-frick/README.MD +0 -10
  99. package/src/examples/bank-frick/accounts.ts +0 -246
  100. package/src/examples/bank-frick/config/index.ts +0 -53
  101. package/src/examples/bank-frick/index.ts +0 -13
  102. package/src/examples/bank-frick/types.d.ts +0 -38
  103. package/src/examples/bank-frick/util.ts +0 -55
  104. package/src/examples/coingecko/src/config/index.ts +0 -12
  105. package/src/examples/coingecko/src/config/overrides.json +0 -10826
  106. package/src/examples/coingecko/src/cryptoUtils.ts +0 -88
  107. package/src/examples/coingecko/src/endpoint/coins.ts +0 -54
  108. package/src/examples/coingecko/src/endpoint/crypto-marketcap.ts +0 -66
  109. package/src/examples/coingecko/src/endpoint/crypto-volume.ts +0 -66
  110. package/src/examples/coingecko/src/endpoint/crypto.ts +0 -63
  111. package/src/examples/coingecko/src/endpoint/dominance.ts +0 -40
  112. package/src/examples/coingecko/src/endpoint/global-marketcap.ts +0 -40
  113. package/src/examples/coingecko/src/endpoint/index.ts +0 -6
  114. package/src/examples/coingecko/src/globalUtils.ts +0 -78
  115. package/src/examples/coingecko/src/index.ts +0 -17
  116. package/src/examples/coingecko/test/e2e/adapter.test.ts +0 -278
  117. package/src/examples/coingecko/test/integration/__snapshots__/adapter.test.ts.snap +0 -15
  118. package/src/examples/coingecko/test/integration/adapter.test.ts +0 -281
  119. package/src/examples/coingecko/test/integration/capturedRequests.json +0 -1
  120. package/src/examples/coingecko/test/integration/fixtures.ts +0 -42
  121. package/src/examples/coingecko-old/batch-warming.ts +0 -79
  122. package/src/examples/coingecko-old/index.ts +0 -9
  123. package/src/examples/coingecko-old/rest.ts +0 -77
  124. package/src/examples/ncfx/config/index.ts +0 -12
  125. package/src/examples/ncfx/index.ts +0 -9
  126. package/src/examples/ncfx/websocket.ts +0 -99
  127. package/src/index.ts +0 -149
  128. package/src/metrics/constants.ts +0 -23
  129. package/src/metrics/index.ts +0 -115
  130. package/src/metrics/util.ts +0 -18
  131. package/src/rate-limiting/background/fixed-frequency.ts +0 -45
  132. package/src/rate-limiting/index.ts +0 -100
  133. package/src/rate-limiting/metrics.ts +0 -18
  134. package/src/rate-limiting/request/simple-counting.ts +0 -76
  135. package/src/transports/batch-warming.ts +0 -127
  136. package/src/transports/index.ts +0 -152
  137. package/src/transports/metrics.ts +0 -95
  138. package/src/transports/rest.ts +0 -168
  139. package/src/transports/util.ts +0 -63
  140. package/src/transports/websocket.ts +0 -245
  141. package/src/util/index.ts +0 -23
  142. package/src/util/logger.ts +0 -69
  143. package/src/util/recordRequests.ts +0 -47
  144. package/src/util/request.ts +0 -117
  145. package/src/util/subscription-set/expiring-sorted-set.ts +0 -54
  146. package/src/util/subscription-set/subscription-set.ts +0 -35
  147. package/src/util/test-payload-loader.ts +0 -87
  148. package/src/validation/error.ts +0 -116
  149. package/src/validation/index.ts +0 -110
  150. package/src/validation/input-params.ts +0 -45
  151. package/src/validation/override-functions.ts +0 -44
  152. package/src/validation/overrideFunctions.ts +0 -44
  153. package/src/validation/preset-tokens.json +0 -23
  154. package/src/validation/validator.ts +0 -384
  155. package/test/adapter.test.ts +0 -27
  156. package/test/background-executor.test.ts +0 -108
  157. package/test/cache/cache-key.test.ts +0 -114
  158. package/test/cache/helper.ts +0 -100
  159. package/test/cache/local.test.ts +0 -54
  160. package/test/cache/redis.test.ts +0 -89
  161. package/test/correlation.test.ts +0 -114
  162. package/test/index.test.ts +0 -37
  163. package/test/metrics/feed-id.test.ts +0 -38
  164. package/test/metrics/helper.ts +0 -14
  165. package/test/metrics/labels.test.ts +0 -36
  166. package/test/metrics/metrics.test.ts +0 -267
  167. package/test/metrics/redis-metrics.test.ts +0 -113
  168. package/test/metrics/warmer-metrics.test.ts +0 -193
  169. package/test/metrics/ws-metrics.test.ts +0 -225
  170. package/test/rate-limit-config.test.ts +0 -242
  171. package/test/smoke/smoke.test.ts +0 -166
  172. package/test/smoke/test-payload-fail.json +0 -3
  173. package/test/smoke/test-payload.js +0 -22
  174. package/test/smoke/test-payload.json +0 -7
  175. package/test/transports/batch.test.ts +0 -466
  176. package/test/transports/rest.test.ts +0 -242
  177. package/test/transports/websocket.test.ts +0 -183
  178. package/test/tsconfig.json +0 -5
  179. package/test/util.ts +0 -77
  180. package/test/validation.test.ts +0 -178
  181. package/test.sh +0 -20
  182. package/test2.sh +0 -2
  183. package/tsconfig.json +0 -28
  184. package/typedoc.json +0 -6
  185. package/webpack.config.js +0 -57
  186. package/yarn-error.log +0 -3778
@@ -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,12 +0,0 @@
1
- export const NAME = 'COINGECKO'
2
-
3
- export const DEFAULT_ENDPOINT = 'crypto'
4
- export const DEFAULT_API_ENDPOINT = 'https://api.coingecko.com/api/v3'
5
- export const PRO_API_ENDPOINT = 'https://pro-api.coingecko.com/api/v3'
6
-
7
- export const customSettings = {
8
- API_KEY: {
9
- description: 'API key for the CoinGecko API',
10
- type: 'string',
11
- },
12
- } as const