@chainlink/external-adapter-framework 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +3 -0
- package/.eslintignore +9 -0
- package/.eslintrc.js +96 -0
- package/.github/README.MD +17 -0
- package/.github/actions/setup/action.yaml +13 -0
- package/.github/workflows/main.yaml +39 -0
- package/.github/workflows/publish.yaml +20 -0
- package/.prettierignore +13 -0
- package/.yarnrc +0 -0
- package/README.md +103 -0
- package/dist/src/adapter.d.ts +135 -0
- package/dist/src/adapter.js +145 -0
- package/dist/src/background-executor.d.ts +11 -0
- package/{background-executor.js → dist/src/background-executor.js} +0 -0
- package/{cache → dist/src/cache}/factory.d.ts +0 -0
- package/dist/src/cache/factory.js +55 -0
- package/dist/src/cache/index.d.ts +94 -0
- package/dist/src/cache/index.js +173 -0
- package/{cache → dist/src/cache}/local.d.ts +0 -0
- package/{cache → dist/src/cache}/local.js +0 -0
- package/{cache → dist/src/cache}/metrics.d.ts +0 -0
- package/{cache → dist/src/cache}/metrics.js +0 -0
- package/{cache → dist/src/cache}/redis.d.ts +0 -0
- package/dist/src/cache/redis.js +100 -0
- package/dist/src/chainlink-external-adapter-framework-0.0.6.tgz +0 -0
- package/dist/src/config/index.d.ts +214 -0
- package/dist/src/config/index.js +380 -0
- package/{config → dist/src/config}/provider-limits.d.ts +0 -0
- package/{config → dist/src/config}/provider-limits.js +1 -1
- package/dist/src/examples/bank-frick/accounts.d.ts +39 -0
- package/dist/src/examples/bank-frick/accounts.js +192 -0
- package/dist/src/examples/bank-frick/config/index.d.ts +4 -0
- package/dist/src/examples/bank-frick/config/index.js +54 -0
- package/dist/src/examples/bank-frick/index.d.ts +2 -0
- package/dist/src/examples/bank-frick/index.js +15 -0
- package/dist/src/examples/bank-frick/util.d.ts +4 -0
- package/dist/src/examples/bank-frick/util.js +39 -0
- package/dist/src/examples/coingecko/batch-warming.d.ts +7 -0
- package/dist/src/examples/coingecko/batch-warming.js +53 -0
- package/dist/src/examples/coingecko/index.d.ts +2 -0
- package/dist/src/examples/coingecko/index.js +11 -0
- package/dist/src/examples/coingecko/rest.d.ts +12 -0
- package/dist/src/examples/coingecko/rest.js +51 -0
- package/{examples → dist/src/examples}/ncfx/config/index.d.ts +0 -0
- package/{examples → dist/src/examples}/ncfx/config/index.js +0 -0
- package/dist/src/examples/ncfx/index.d.ts +13 -0
- package/dist/src/examples/ncfx/index.js +11 -0
- package/dist/src/examples/ncfx/websocket.d.ts +47 -0
- package/dist/src/examples/ncfx/websocket.js +73 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +128 -0
- package/{metrics → dist/src/metrics}/constants.d.ts +0 -0
- package/{metrics → dist/src/metrics}/constants.js +0 -0
- package/{metrics → dist/src/metrics}/index.d.ts +0 -0
- package/dist/src/metrics/index.js +122 -0
- package/dist/src/metrics/util.d.ts +7 -0
- package/dist/src/metrics/util.js +9 -0
- package/{adapter.d.ts → dist/src/package/adapter.d.ts} +0 -0
- package/{adapter.js → dist/src/package/adapter.js} +0 -0
- package/{background-executor.d.ts → dist/src/package/background-executor.d.ts} +0 -0
- package/dist/src/package/background-executor.js +45 -0
- package/dist/src/package/cache/factory.d.ts +6 -0
- package/{cache → dist/src/package/cache}/factory.js +0 -0
- package/{cache → dist/src/package/cache}/index.d.ts +0 -0
- package/{cache → dist/src/package/cache}/index.js +0 -0
- package/dist/src/package/cache/local.d.ts +23 -0
- package/dist/src/package/cache/local.js +83 -0
- package/dist/src/package/cache/metrics.d.ts +27 -0
- package/dist/src/package/cache/metrics.js +120 -0
- package/dist/src/package/cache/redis.d.ts +16 -0
- package/{cache → dist/src/package/cache}/redis.js +0 -0
- package/{config → dist/src/package/config}/index.d.ts +0 -0
- package/{config → dist/src/package/config}/index.js +0 -0
- package/dist/src/package/config/provider-limits.d.ts +31 -0
- package/dist/src/package/config/provider-limits.js +76 -0
- package/{examples → dist/src/package/examples}/coingecko/batch-warming.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/batch-warming.js +0 -0
- package/{examples → dist/src/package/examples}/coingecko/index.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/index.js +0 -0
- package/{examples → dist/src/package/examples}/coingecko/rest.d.ts +0 -0
- package/{examples → dist/src/package/examples}/coingecko/rest.js +0 -0
- package/dist/src/package/examples/ncfx/config/index.d.ts +12 -0
- package/dist/src/package/examples/ncfx/config/index.js +15 -0
- package/{examples → dist/src/package/examples}/ncfx/index.d.ts +0 -0
- package/{examples → dist/src/package/examples}/ncfx/index.js +0 -0
- package/{examples → dist/src/package/examples}/ncfx/websocket.d.ts +0 -0
- package/{examples → dist/src/package/examples}/ncfx/websocket.js +0 -0
- package/{index.d.ts → dist/src/package/index.d.ts} +0 -0
- package/{index.js → dist/src/package/index.js} +0 -0
- package/dist/src/package/metrics/constants.d.ts +16 -0
- package/dist/src/package/metrics/constants.js +25 -0
- package/dist/src/package/metrics/index.d.ts +15 -0
- package/{metrics → dist/src/package/metrics}/index.js +0 -0
- package/{metrics → dist/src/package/metrics}/util.d.ts +0 -0
- package/{metrics → dist/src/package/metrics}/util.js +0 -0
- package/dist/src/package/package.json +72 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/background/fixed-frequency.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/background/fixed-frequency.js +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/index.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/index.js +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/metrics.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/metrics.js +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/request/simple-counting.d.ts +0 -0
- package/{rate-limiting → dist/src/package/rate-limiting}/request/simple-counting.js +0 -0
- package/{test.d.ts → dist/src/package/test.d.ts} +0 -0
- package/{test.js → dist/src/package/test.js} +0 -0
- package/{transports → dist/src/package/transports}/batch-warming.d.ts +0 -0
- package/{transports → dist/src/package/transports}/batch-warming.js +0 -0
- package/{transports → dist/src/package/transports}/index.d.ts +0 -0
- package/{transports → dist/src/package/transports}/index.js +0 -0
- package/{transports → dist/src/package/transports}/metrics.d.ts +0 -0
- package/{transports → dist/src/package/transports}/metrics.js +0 -0
- package/{transports → dist/src/package/transports}/rest.d.ts +0 -0
- package/{transports → dist/src/package/transports}/rest.js +0 -0
- package/{transports → dist/src/package/transports}/util.d.ts +0 -0
- package/{transports → dist/src/package/transports}/util.js +0 -0
- package/{transports → dist/src/package/transports}/websocket.d.ts +0 -0
- package/{transports → dist/src/package/transports}/websocket.js +0 -0
- package/{util → dist/src/package/util}/expiring-sorted-set.d.ts +0 -0
- package/{util → dist/src/package/util}/expiring-sorted-set.js +0 -0
- package/{util → dist/src/package/util}/index.d.ts +0 -0
- package/{util → dist/src/package/util}/index.js +0 -0
- package/{util → dist/src/package/util}/logger.d.ts +0 -0
- package/{util → dist/src/package/util}/logger.js +0 -0
- package/{util → dist/src/package/util}/request.d.ts +0 -0
- package/{util → dist/src/package/util}/request.js +0 -0
- package/{validation → dist/src/package/validation}/error.d.ts +0 -0
- package/{validation → dist/src/package/validation}/error.js +0 -0
- package/{validation → dist/src/package/validation}/index.d.ts +0 -0
- package/{validation → dist/src/package/validation}/index.js +0 -0
- package/{validation → dist/src/package/validation}/input-params.d.ts +0 -0
- package/{validation → dist/src/package/validation}/input-params.js +0 -0
- package/{validation → dist/src/package/validation}/override-functions.d.ts +0 -0
- package/{validation → dist/src/package/validation}/override-functions.js +0 -0
- package/{validation → dist/src/package/validation}/preset-tokens.json +0 -0
- package/{validation → dist/src/package/validation}/validator.d.ts +0 -0
- package/{validation → dist/src/package/validation}/validator.js +0 -0
- package/dist/src/package.json +72 -0
- package/dist/src/rate-limiting/background/fixed-frequency.d.ts +11 -0
- package/dist/src/rate-limiting/background/fixed-frequency.js +35 -0
- package/dist/src/rate-limiting/index.d.ts +55 -0
- package/dist/src/rate-limiting/index.js +63 -0
- package/dist/src/rate-limiting/metrics.d.ts +3 -0
- package/dist/src/rate-limiting/metrics.js +44 -0
- package/dist/src/rate-limiting/request/simple-counting.d.ts +21 -0
- package/dist/src/rate-limiting/request/simple-counting.js +62 -0
- package/dist/src/test.d.ts +1 -0
- package/dist/src/test.js +6 -0
- package/dist/src/transports/batch-warming.d.ts +35 -0
- package/dist/src/transports/batch-warming.js +101 -0
- package/dist/src/transports/index.d.ts +70 -0
- package/dist/src/transports/index.js +87 -0
- package/dist/src/transports/metrics.d.ts +22 -0
- package/dist/src/transports/metrics.js +105 -0
- package/dist/src/transports/rest.d.ts +44 -0
- package/dist/src/transports/rest.js +131 -0
- package/dist/src/transports/util.d.ts +8 -0
- package/dist/src/transports/util.js +85 -0
- package/dist/src/transports/websocket.d.ts +80 -0
- package/dist/src/transports/websocket.js +166 -0
- package/dist/src/util/expiring-sorted-set.d.ts +21 -0
- package/dist/src/util/expiring-sorted-set.js +47 -0
- package/dist/src/util/index.d.ts +12 -0
- package/dist/src/util/index.js +35 -0
- package/dist/src/util/logger.d.ts +42 -0
- package/dist/src/util/logger.js +62 -0
- package/dist/src/util/request.d.ts +57 -0
- package/dist/src/util/request.js +2 -0
- package/dist/src/util/subscription-set/expiring-sorted-set.d.ts +22 -0
- package/dist/src/util/subscription-set/expiring-sorted-set.js +47 -0
- package/dist/src/util/subscription-set/subscription-set.d.ts +18 -0
- package/dist/src/util/subscription-set/subscription-set.js +19 -0
- package/dist/src/util/test-payload-loader.d.ts +25 -0
- package/dist/src/util/test-payload-loader.js +83 -0
- package/dist/src/validation/error.d.ts +50 -0
- package/dist/src/validation/error.js +79 -0
- package/dist/src/validation/index.d.ts +5 -0
- package/dist/src/validation/index.js +91 -0
- package/dist/src/validation/input-params.d.ts +15 -0
- package/dist/src/validation/input-params.js +30 -0
- package/dist/src/validation/override-functions.d.ts +3 -0
- package/dist/src/validation/override-functions.js +40 -0
- package/dist/src/validation/preset-tokens.json +23 -0
- package/dist/src/validation/validator.d.ts +47 -0
- package/dist/src/validation/validator.js +303 -0
- package/docker-compose.yaml +35 -0
- package/env.sh +54 -0
- package/env2.sh +55 -0
- package/package.json +5 -3
- package/publish.sh +0 -0
- package/src/adapter.ts +263 -0
- package/src/background-executor.ts +52 -0
- package/src/cache/factory.ts +26 -0
- package/src/cache/index.ts +258 -0
- package/src/cache/local.ts +73 -0
- package/src/cache/metrics.ts +112 -0
- package/src/cache/redis.ts +93 -0
- package/src/config/index.ts +517 -0
- package/src/config/provider-limits.ts +130 -0
- package/src/examples/bank-frick/README.MD +10 -0
- package/src/examples/bank-frick/accounts.ts +246 -0
- package/src/examples/bank-frick/config/index.ts +53 -0
- package/src/examples/bank-frick/index.ts +13 -0
- package/src/examples/bank-frick/types.d.ts +38 -0
- package/src/examples/bank-frick/util.ts +55 -0
- package/src/examples/coingecko/batch-warming.ts +78 -0
- package/src/examples/coingecko/index.ts +9 -0
- package/src/examples/coingecko/rest.ts +77 -0
- package/src/examples/ncfx/config/index.ts +12 -0
- package/src/examples/ncfx/index.ts +9 -0
- package/src/examples/ncfx/websocket.ts +99 -0
- package/src/index.ts +149 -0
- package/src/metrics/constants.ts +23 -0
- package/src/metrics/index.ts +115 -0
- package/src/metrics/util.ts +18 -0
- package/src/rate-limiting/background/fixed-frequency.ts +45 -0
- package/src/rate-limiting/index.ts +100 -0
- package/src/rate-limiting/metrics.ts +18 -0
- package/src/rate-limiting/request/simple-counting.ts +76 -0
- package/src/test.ts +5 -0
- package/src/transports/batch-warming.ts +122 -0
- package/src/transports/index.ts +152 -0
- package/src/transports/metrics.ts +95 -0
- package/src/transports/rest.ts +164 -0
- package/src/transports/util.ts +63 -0
- package/src/transports/websocket.ts +245 -0
- package/src/util/index.ts +22 -0
- package/src/util/logger.ts +69 -0
- package/src/util/request.ts +117 -0
- package/src/util/subscription-set/expiring-sorted-set.ts +54 -0
- package/src/util/subscription-set/subscription-set.ts +35 -0
- package/src/util/test-payload-loader.ts +87 -0
- package/src/validation/error.ts +116 -0
- package/src/validation/index.ts +110 -0
- package/src/validation/input-params.ts +45 -0
- package/src/validation/override-functions.ts +44 -0
- package/src/validation/preset-tokens.json +23 -0
- package/src/validation/validator.ts +384 -0
- package/test/adapter.test.ts +27 -0
- package/test/background-executor.test.ts +108 -0
- package/test/cache/cache-key.test.ts +114 -0
- package/test/cache/helper.ts +100 -0
- package/test/cache/local.test.ts +54 -0
- package/test/cache/redis.test.ts +89 -0
- package/test/correlation.test.ts +114 -0
- package/test/index.test.ts +37 -0
- package/test/metrics/feed-id.test.ts +38 -0
- package/test/metrics/helper.ts +14 -0
- package/test/metrics/labels.test.ts +36 -0
- package/test/metrics/metrics.test.ts +267 -0
- package/test/metrics/redis-metrics.test.ts +113 -0
- package/test/metrics/warmer-metrics.test.ts +192 -0
- package/test/metrics/ws-metrics.test.ts +225 -0
- package/test/rate-limit-config.test.ts +242 -0
- package/test/smoke.test.ts +166 -0
- package/test/transports/batch.test.ts +465 -0
- package/test/transports/rest.test.ts +242 -0
- package/test/transports/websocket.test.ts +183 -0
- package/test/tsconfig.json +5 -0
- package/test/util.ts +77 -0
- package/test/validation.test.ts +178 -0
- package/test-payload-fail.json +3 -0
- package/test-payload.js +22 -0
- package/test-payload.json +7 -0
- package/test.sh +20 -0
- package/test2.sh +2 -0
- package/tsconfig.json +25 -0
- package/typedoc.json +6 -0
- package/webpack.config.js +23 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Import { getRandomRequiredEnv, getRandomEnv, getEnv } from '../util'
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.buildAdapterConfig = exports.BaseSettings = void 0;
|
|
5
|
+
exports.BaseSettings = {
|
|
6
|
+
// V2 compat
|
|
7
|
+
API_ENDPOINT: {
|
|
8
|
+
description: 'The URL that the certain transports use to retrieve data',
|
|
9
|
+
type: 'string',
|
|
10
|
+
},
|
|
11
|
+
API_KEY: {
|
|
12
|
+
description: 'Default setting for an EA key',
|
|
13
|
+
type: 'string',
|
|
14
|
+
},
|
|
15
|
+
// API_TIMEOUT: {
|
|
16
|
+
// type: 'number',
|
|
17
|
+
// default: 30000,
|
|
18
|
+
// },
|
|
19
|
+
// API_VERBOSE: {
|
|
20
|
+
// type: 'boolean',
|
|
21
|
+
// },
|
|
22
|
+
BASE_URL: {
|
|
23
|
+
description: 'Starting path for the EA handler endpoint',
|
|
24
|
+
type: 'string',
|
|
25
|
+
default: '/',
|
|
26
|
+
},
|
|
27
|
+
// CACHE_ENABLED: {
|
|
28
|
+
// type: 'boolean',
|
|
29
|
+
// default: true,
|
|
30
|
+
// },
|
|
31
|
+
// CACHE_KEY_GROUP: {
|
|
32
|
+
// type: 'string',
|
|
33
|
+
// },
|
|
34
|
+
CACHE_MAX_AGE: {
|
|
35
|
+
description: 'Maximum amount of time (in ms) that a response will stay cached',
|
|
36
|
+
type: 'number',
|
|
37
|
+
default: 90000,
|
|
38
|
+
},
|
|
39
|
+
// CACHE_MAX_ITEMS: {
|
|
40
|
+
// type: 'number',
|
|
41
|
+
// default: 1000,
|
|
42
|
+
// },
|
|
43
|
+
// CACHE_MIN_AGE: {
|
|
44
|
+
// type: 'number',
|
|
45
|
+
// default: 30000,
|
|
46
|
+
// },
|
|
47
|
+
// CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
48
|
+
// type: 'number',
|
|
49
|
+
// default: 15000,
|
|
50
|
+
// },
|
|
51
|
+
CACHE_REDIS_HOST: {
|
|
52
|
+
description: 'Hostname for the Redis instance to be used',
|
|
53
|
+
type: 'string',
|
|
54
|
+
default: '127.0.0.1',
|
|
55
|
+
},
|
|
56
|
+
// CACHE_REDIS_MAX_QUEUED_ITEMS: {
|
|
57
|
+
// type: 'number',
|
|
58
|
+
// default: 100,
|
|
59
|
+
// },
|
|
60
|
+
// CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
61
|
+
// type: 'number',
|
|
62
|
+
// default: 3000,
|
|
63
|
+
// },
|
|
64
|
+
// CACHE_REDIS_PASSWORD: {
|
|
65
|
+
// type: 'string',
|
|
66
|
+
// },
|
|
67
|
+
// CACHE_REDIS_PATH: {
|
|
68
|
+
// type: 'string',
|
|
69
|
+
// },
|
|
70
|
+
CACHE_REDIS_PORT: {
|
|
71
|
+
description: 'Port for the Redis instance to be used',
|
|
72
|
+
type: 'number',
|
|
73
|
+
default: 6379,
|
|
74
|
+
},
|
|
75
|
+
// CACHE_REDIS_TIMEOUT: {
|
|
76
|
+
// type: 'number',
|
|
77
|
+
// default: 500,
|
|
78
|
+
// },
|
|
79
|
+
// CACHE_REDIS_URL: {
|
|
80
|
+
// type: 'string',
|
|
81
|
+
// },
|
|
82
|
+
CACHE_TYPE: {
|
|
83
|
+
description: 'The type of cache to use throughout the EA',
|
|
84
|
+
type: 'enum',
|
|
85
|
+
default: 'local',
|
|
86
|
+
options: ['local', 'redis'],
|
|
87
|
+
},
|
|
88
|
+
// CACHE_UPDATE_AGE_ON_GET: {
|
|
89
|
+
// type: 'boolean',
|
|
90
|
+
// default: false,
|
|
91
|
+
// },
|
|
92
|
+
CORRELATION_ID_ENABLED: {
|
|
93
|
+
description: 'Flag to enable correlation IDs for sent requests in logging',
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
default: true,
|
|
96
|
+
},
|
|
97
|
+
// DEBUG: {
|
|
98
|
+
// type: 'boolean',
|
|
99
|
+
// },
|
|
100
|
+
// DEFAULT_WS_HEARTBEAT_INTERVAL: {
|
|
101
|
+
// type: 'number',
|
|
102
|
+
// default: 30000,
|
|
103
|
+
// },
|
|
104
|
+
EA_PORT: {
|
|
105
|
+
description: 'Port through which the EA will listen for REST requests (if mode is set to "reader" or "reader-writer")',
|
|
106
|
+
type: 'number',
|
|
107
|
+
default: 8080,
|
|
108
|
+
},
|
|
109
|
+
// ENV_ADAPTER_URL: {
|
|
110
|
+
// type: 'string',
|
|
111
|
+
// },
|
|
112
|
+
// ERROR_CAPACITY: {
|
|
113
|
+
// type: 'number',
|
|
114
|
+
// },
|
|
115
|
+
EXPERIMENTAL_METRICS_ENABLED: {
|
|
116
|
+
description: 'Flag to specify whether or not to collect metrics. Used as fallback for METRICS_ENABLED',
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
default: true,
|
|
119
|
+
},
|
|
120
|
+
// LEGACY_ENV_ADAPTER_URL: {
|
|
121
|
+
// type: 'string',
|
|
122
|
+
// },
|
|
123
|
+
LOG_LEVEL: {
|
|
124
|
+
description: 'Minimum level required for logs to be output',
|
|
125
|
+
type: 'string',
|
|
126
|
+
default: 'info',
|
|
127
|
+
},
|
|
128
|
+
METRICS_ENABLED: {
|
|
129
|
+
description: 'Flag to specify whether or not to startup the metrics server',
|
|
130
|
+
type: 'boolean',
|
|
131
|
+
default: true,
|
|
132
|
+
},
|
|
133
|
+
METRICS_NAME: {
|
|
134
|
+
description: 'Metrics name',
|
|
135
|
+
type: 'string',
|
|
136
|
+
},
|
|
137
|
+
METRICS_PORT: {
|
|
138
|
+
description: 'Port metrics will be exposed to',
|
|
139
|
+
type: 'number',
|
|
140
|
+
default: 9080,
|
|
141
|
+
},
|
|
142
|
+
METRICS_USE_BASE_URL: {
|
|
143
|
+
description: 'Flag to specify whether or not to prepend the BASE_URL to the metrics endpoint',
|
|
144
|
+
type: 'boolean',
|
|
145
|
+
},
|
|
146
|
+
RATE_LIMIT_API_TIER: {
|
|
147
|
+
description: 'Rate limiting tier to use from the available options for the adapter. If not present, the adapter will run using the first tier on the list.',
|
|
148
|
+
type: 'string',
|
|
149
|
+
},
|
|
150
|
+
// RATE_LIMIT_CAPACITY_MINUTE: {
|
|
151
|
+
// type: 'number',
|
|
152
|
+
// },
|
|
153
|
+
// RATE_LIMIT_CAPACITY_SECOND: {
|
|
154
|
+
// type: 'number',
|
|
155
|
+
// },
|
|
156
|
+
// RATE_LIMIT_CAPACITY: {
|
|
157
|
+
// type: 'number',
|
|
158
|
+
// },
|
|
159
|
+
// RATE_LIMIT_ENABLED: {
|
|
160
|
+
// type: 'boolean',
|
|
161
|
+
// default: true,
|
|
162
|
+
// },
|
|
163
|
+
// RECORD: {
|
|
164
|
+
// type: 'boolean',
|
|
165
|
+
// },
|
|
166
|
+
// REQUEST_COALESCING_ENABLED: {
|
|
167
|
+
// type: 'boolean',
|
|
168
|
+
// },
|
|
169
|
+
// REQUEST_COALESCING_ENTROPY_MAX: {
|
|
170
|
+
// type: 'number',
|
|
171
|
+
// default: 0,
|
|
172
|
+
// },
|
|
173
|
+
// REQUEST_COALESCING_INTERVAL_COEFFICIENT: {
|
|
174
|
+
// type: 'number',
|
|
175
|
+
// default: 2,
|
|
176
|
+
// },
|
|
177
|
+
// REQUEST_COALESCING_INTERVAL_MAX: {
|
|
178
|
+
// type: 'number',
|
|
179
|
+
// default: 1000,
|
|
180
|
+
// },
|
|
181
|
+
// REQUEST_COALESCING_INTERVAL: {
|
|
182
|
+
// type: 'number',
|
|
183
|
+
// default: 100,
|
|
184
|
+
// },
|
|
185
|
+
// REQUEST_COALESCING_MAX_RETRIES: {
|
|
186
|
+
// type: 'number',
|
|
187
|
+
// default: 5,
|
|
188
|
+
// },
|
|
189
|
+
// RETRY: {
|
|
190
|
+
// type: 'boolean',
|
|
191
|
+
// default: 1,
|
|
192
|
+
// },
|
|
193
|
+
// SERVER_RATE_LIMIT_MAX: {
|
|
194
|
+
// type: 'number',
|
|
195
|
+
// default: 250,
|
|
196
|
+
// },
|
|
197
|
+
// SERVER_SLOW_DOWN_AFTER_FACTOR: {
|
|
198
|
+
// type: 'number',
|
|
199
|
+
// default: 0.8,
|
|
200
|
+
// },
|
|
201
|
+
// SERVER_SLOW_DOWN_DELAY_MS: {
|
|
202
|
+
// type: 'number',
|
|
203
|
+
// default: 500,
|
|
204
|
+
// },
|
|
205
|
+
// TIMEOUT: {
|
|
206
|
+
// type: 'number',
|
|
207
|
+
// },
|
|
208
|
+
// WARMUP_ENABLED: {
|
|
209
|
+
// type: 'boolean',
|
|
210
|
+
// default: true,
|
|
211
|
+
// },
|
|
212
|
+
// WARMUP_INTERVAL: {
|
|
213
|
+
// type: 'number',
|
|
214
|
+
// },
|
|
215
|
+
WARMUP_SUBSCRIPTION_TTL: {
|
|
216
|
+
type: 'number',
|
|
217
|
+
description: 'TTL for batch warmer subscriptions',
|
|
218
|
+
default: 10000,
|
|
219
|
+
},
|
|
220
|
+
// WARMUP_UNHEALTHY_THRESHOLD: {
|
|
221
|
+
// type: 'number',
|
|
222
|
+
// default: 3,
|
|
223
|
+
// },
|
|
224
|
+
// WS_API_ENDPOINT: {
|
|
225
|
+
// type: 'string',
|
|
226
|
+
// },
|
|
227
|
+
// WS_API_KEY: {
|
|
228
|
+
// type: 'string',
|
|
229
|
+
// },
|
|
230
|
+
// WS_CONNECTION_KEY: {
|
|
231
|
+
// type: 'string',
|
|
232
|
+
// default: 1,
|
|
233
|
+
// },
|
|
234
|
+
// WS_CONNECTION_LIMIT: {
|
|
235
|
+
// type: 'number',
|
|
236
|
+
// default: 1,
|
|
237
|
+
// },
|
|
238
|
+
// WS_CONNECTION_RETRY_DELAY: {
|
|
239
|
+
// type: 'number',
|
|
240
|
+
// default: 1000,
|
|
241
|
+
// },
|
|
242
|
+
// WS_CONNECTION_RETRY_LIMIT: {
|
|
243
|
+
// type: 'number',
|
|
244
|
+
// default: 3,
|
|
245
|
+
// },
|
|
246
|
+
// WS_CONNECTION_TTL: {
|
|
247
|
+
// type: 'number',
|
|
248
|
+
// default: 70000,
|
|
249
|
+
// },
|
|
250
|
+
// WS_ENABLED: {
|
|
251
|
+
// type: 'boolean',
|
|
252
|
+
// default: false,
|
|
253
|
+
// },
|
|
254
|
+
// WS_SUBSCRIPTION_LIMIT: {
|
|
255
|
+
// type: 'number',
|
|
256
|
+
// default: 10,
|
|
257
|
+
// },
|
|
258
|
+
// WS_SUBSCRIPTION_PRIORITY_LIST: {
|
|
259
|
+
// type: 'string',
|
|
260
|
+
// },
|
|
261
|
+
WS_SUBSCRIPTION_TTL: {
|
|
262
|
+
description: '',
|
|
263
|
+
type: 'number',
|
|
264
|
+
default: 120000,
|
|
265
|
+
},
|
|
266
|
+
// WS_SUBSCRIPTION_UNRESPONSIVE_TTL: {
|
|
267
|
+
// type: 'number',
|
|
268
|
+
// default: false,
|
|
269
|
+
// },
|
|
270
|
+
// WS_TIME_UNTIL_HANDLE_NEXT_MESSAGE_OVERRIDE: {
|
|
271
|
+
// type: 'number',
|
|
272
|
+
// },
|
|
273
|
+
// V3
|
|
274
|
+
CACHE_POLLING_MAX_RETRIES: {
|
|
275
|
+
description: 'Max amount of times to attempt to find EA response in the cache after the Transport has been set up',
|
|
276
|
+
type: 'number',
|
|
277
|
+
default: 10,
|
|
278
|
+
},
|
|
279
|
+
CACHE_POLLING_SLEEP_MS: {
|
|
280
|
+
description: 'The number of ms to sleep between each retry to fetch the EA response in the cache',
|
|
281
|
+
type: 'number',
|
|
282
|
+
default: 200,
|
|
283
|
+
},
|
|
284
|
+
DEFAULT_CACHE_KEY: {
|
|
285
|
+
description: 'Default key to be used when one cannot be determined from request parameters',
|
|
286
|
+
type: 'string',
|
|
287
|
+
default: 'DEFAULT_CACHE_KEY',
|
|
288
|
+
},
|
|
289
|
+
EA_HOST: {
|
|
290
|
+
description: 'Host this EA will listen for REST requests on (if mode is set to "reader" or "reader-writer")',
|
|
291
|
+
type: 'string',
|
|
292
|
+
default: '::',
|
|
293
|
+
},
|
|
294
|
+
EA_MODE: {
|
|
295
|
+
description: 'Port this EA will listen for REST requests on (if mode is set to "reader" or "reader-writer")',
|
|
296
|
+
type: 'enum',
|
|
297
|
+
default: 'reader-writer',
|
|
298
|
+
options: ['reader', 'writer', 'reader-writer'],
|
|
299
|
+
},
|
|
300
|
+
REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES: {
|
|
301
|
+
description: 'Maximum amount of times the Rest Transport will attempt to set up a request when blocked by the rate limiter',
|
|
302
|
+
type: 'number',
|
|
303
|
+
default: 3,
|
|
304
|
+
},
|
|
305
|
+
REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES: {
|
|
306
|
+
description: 'Time that the Rest Transport will wait between retries when blocked by the rate limiter',
|
|
307
|
+
type: 'number',
|
|
308
|
+
default: 400,
|
|
309
|
+
},
|
|
310
|
+
MAX_COMMON_KEY_SIZE: {
|
|
311
|
+
description: 'Maximum amount of characters that the common part of the cache key or feed ID can have',
|
|
312
|
+
type: 'number',
|
|
313
|
+
default: 300,
|
|
314
|
+
validate: (value) => {
|
|
315
|
+
if (!(value && value >= 150 && value <= 500)) {
|
|
316
|
+
return 'MAX_COMMON_KEY_SIZE must be a number between 150 and 500';
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
// CACHE_KEY_IGNORED_PROPS : {
|
|
321
|
+
// description: 'Properties to ignore when generating a feed ID for requests',
|
|
322
|
+
// type: 'string'
|
|
323
|
+
// }
|
|
324
|
+
SMOKE_TEST_PAYLOAD_FILE_NAME: {
|
|
325
|
+
description: 'Name of the test payload file used for the smoke endpoint',
|
|
326
|
+
type: 'string',
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
|
|
330
|
+
const validationErrors = [];
|
|
331
|
+
const vars = {};
|
|
332
|
+
// Iterate base adapter env vars
|
|
333
|
+
for (const [key, config] of Object.entries(exports.BaseSettings)) {
|
|
334
|
+
const value = getEnv(key, config) ?? overrides?.[key] ?? config.default;
|
|
335
|
+
vars[key] = value;
|
|
336
|
+
}
|
|
337
|
+
// Iterate custom vars
|
|
338
|
+
for (const [key, config] of Object.entries(customSettings)) {
|
|
339
|
+
if (exports.BaseSettings[key]) {
|
|
340
|
+
throw new Error(`Custom env var "${key}" declared, but a base framework env var with that name already exists.`);
|
|
341
|
+
}
|
|
342
|
+
const value = getEnv(key, config) ?? config.default;
|
|
343
|
+
// Check if a required setting has been provided
|
|
344
|
+
if (config.required && value === null) {
|
|
345
|
+
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
346
|
+
}
|
|
347
|
+
else if (config.validate) {
|
|
348
|
+
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
349
|
+
const validationRes = config.validate(value);
|
|
350
|
+
if (validationRes) {
|
|
351
|
+
validationErrors.push(`${key}: ${validationRes}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
vars[key] = value;
|
|
355
|
+
}
|
|
356
|
+
if (validationErrors.length > 0) {
|
|
357
|
+
throw new Error(`Validation failed for the following variables:\n ${validationErrors.join('\n')}`);
|
|
358
|
+
}
|
|
359
|
+
return vars;
|
|
360
|
+
};
|
|
361
|
+
exports.buildAdapterConfig = buildAdapterConfig;
|
|
362
|
+
const getEnv = (name, config) => {
|
|
363
|
+
const value = process.env[name];
|
|
364
|
+
if (!value) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
switch (config.type) {
|
|
368
|
+
case 'string':
|
|
369
|
+
return value;
|
|
370
|
+
case 'number':
|
|
371
|
+
return parseInt(value);
|
|
372
|
+
case 'boolean':
|
|
373
|
+
return value === 'true';
|
|
374
|
+
case 'enum':
|
|
375
|
+
if (!config.options?.includes(value)) {
|
|
376
|
+
throw new Error(`Env var "${name}" has value "${value}" which is not included in the valid options (${config.options})`);
|
|
377
|
+
}
|
|
378
|
+
return value;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
File without changes
|
|
@@ -42,7 +42,7 @@ const getProviderLimits = (provider, limits, tier, protocol) => {
|
|
|
42
42
|
return limitsConfig;
|
|
43
43
|
};
|
|
44
44
|
const parseLimits = (limits) => {
|
|
45
|
-
const _mapObject = (fn) => (o) => Object.fromEntries(
|
|
45
|
+
const _mapObject = (fn) => (o) => Object.fromEntries(Object.entries(o).map(fn));
|
|
46
46
|
const _formatProtocol = _mapObject((entry) => {
|
|
47
47
|
const [tierName, rest] = entry;
|
|
48
48
|
return [tierName.toLowerCase(), { ...rest }];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { AdapterInputParameters, BankFrickAccountsRequestSchema, BankFrickAccountsResponseSchema, SigningAlgorithm } from './types';
|
|
3
|
+
import { customSettings } from './config';
|
|
4
|
+
import { Transport } from '../../transports';
|
|
5
|
+
import { AdapterRequest, AdapterResponse } from '../../util';
|
|
6
|
+
import { AdapterConfig } from '../../config';
|
|
7
|
+
import { Cache } from '../../cache';
|
|
8
|
+
import { AdapterDependencies, AdapterEndpoint } from '../../adapter';
|
|
9
|
+
/**
|
|
10
|
+
* RestTransport implementation for Bank Frick, which has unusually complex requirements for an EA
|
|
11
|
+
* The RestTransport is generally built to make a single request and return a single response.
|
|
12
|
+
* This transport instead is used to fetch and process pages of data, and also requires a JWT to run
|
|
13
|
+
*
|
|
14
|
+
* This transport does all the heavy lifting in setup(), which is where the paging happens, and it
|
|
15
|
+
* also has complex retry logic that will attempt to refresh the JWT when certain HTTP errors occur
|
|
16
|
+
*/
|
|
17
|
+
export declare class BankFrickAccountsTransport implements Transport<AdapterInputParameters, number, typeof customSettings> {
|
|
18
|
+
token: string;
|
|
19
|
+
cache: Cache;
|
|
20
|
+
initialize(dependencies: AdapterDependencies): Promise<void>;
|
|
21
|
+
hasBeenSetUp(): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an AxiosRequestConfig object for fetching a page of accounts from the Bank Frick API
|
|
24
|
+
*/
|
|
25
|
+
prepareRequest(firstPosition: number, inputParams: AdapterInputParameters, config: AdapterConfig<typeof customSettings>): AxiosRequestConfig<BankFrickAccountsRequestSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Request with retry logic for Bank Frick's API. In addition to standard retry logic, this function
|
|
28
|
+
* compares errors against expected errors from the Bank Frick API, and will throw without retries
|
|
29
|
+
* on a known fatal error, or try to refresh the JWT on a known auth error
|
|
30
|
+
**/
|
|
31
|
+
makeRequest(axiosRequest: AxiosRequestConfig<BankFrickAccountsRequestSchema>, config: AdapterConfig<typeof customSettings>, signingAlgorithm?: SigningAlgorithm): Promise<AxiosResponse<BankFrickAccountsResponseSchema>>;
|
|
32
|
+
validateInputParams(params: AdapterInputParameters): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Fetches pages of data from the Bank Frick API, scans for accounts by IBAN, and returns the balance
|
|
35
|
+
* of all found accounts. Returns a 404 if any IBAN isn't found.
|
|
36
|
+
*/
|
|
37
|
+
setup(req: AdapterRequest<AdapterInputParameters>, config: AdapterConfig<typeof customSettings>): Promise<AdapterResponse<number>>;
|
|
38
|
+
}
|
|
39
|
+
export declare const accountsRestEndpoint: AdapterEndpoint<AdapterInputParameters, number, import("../../config").SettingsMap>;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.accountsRestEndpoint = exports.BankFrickAccountsTransport = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
const util_2 = require("../../util");
|
|
10
|
+
const error_1 = require("../../validation/error");
|
|
11
|
+
const adapter_1 = require("../../adapter");
|
|
12
|
+
const logger = (0, util_2.makeLogger)('BankFrickTransport');
|
|
13
|
+
// Note: this is a shallow pattern that only checks for a country code since IBANs in the sandbox are invalid
|
|
14
|
+
const ibanPattern = /^[A-Z]{2}[A-Z\d]{14,30}$/;
|
|
15
|
+
const inputParameters = {
|
|
16
|
+
ibanIDs: {
|
|
17
|
+
description: 'The list of account ids included in the sum of balances',
|
|
18
|
+
required: true,
|
|
19
|
+
type: 'array',
|
|
20
|
+
},
|
|
21
|
+
signingAlgorithm: {
|
|
22
|
+
description: 'What signing algorithm is used to sign and verify authorization data, one of rsa-sha256, rsa-sha384, or rsa-sha512',
|
|
23
|
+
required: false,
|
|
24
|
+
type: 'string',
|
|
25
|
+
default: 'rsa-sha512',
|
|
26
|
+
options: ['rsa-sha256', 'rsa-sha384', 'rsa-sha512'],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
// See here for all expected error returned by the API: https://developers.bankfrick.li/docs#errors
|
|
30
|
+
const AuthErrors = {
|
|
31
|
+
401: 'No JWT token provided or token is invalid',
|
|
32
|
+
403: 'API key is invalid or any other condition is hindering the login', // Unclear if this is fatal or not
|
|
33
|
+
};
|
|
34
|
+
const FatalErrors = {
|
|
35
|
+
400: "Invalid parameters passed to Bank Frick's API",
|
|
36
|
+
423: "Authorization is valid, but the user's account is locked",
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* RestTransport implementation for Bank Frick, which has unusually complex requirements for an EA
|
|
40
|
+
* The RestTransport is generally built to make a single request and return a single response.
|
|
41
|
+
* This transport instead is used to fetch and process pages of data, and also requires a JWT to run
|
|
42
|
+
*
|
|
43
|
+
* This transport does all the heavy lifting in setup(), which is where the paging happens, and it
|
|
44
|
+
* also has complex retry logic that will attempt to refresh the JWT when certain HTTP errors occur
|
|
45
|
+
*/
|
|
46
|
+
class BankFrickAccountsTransport {
|
|
47
|
+
async initialize(dependencies) {
|
|
48
|
+
this.cache = dependencies.cache;
|
|
49
|
+
}
|
|
50
|
+
async hasBeenSetUp() {
|
|
51
|
+
return false; // Return false since we aren't coalescing requests
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates an AxiosRequestConfig object for fetching a page of accounts from the Bank Frick API
|
|
55
|
+
*/
|
|
56
|
+
prepareRequest(firstPosition, inputParams, config) {
|
|
57
|
+
const { API_ENDPOINT, BASE_URL, PAGE_SIZE } = config;
|
|
58
|
+
return {
|
|
59
|
+
baseURL: API_ENDPOINT + BASE_URL,
|
|
60
|
+
url: 'accounts',
|
|
61
|
+
method: 'GET',
|
|
62
|
+
params: {
|
|
63
|
+
firstPosition,
|
|
64
|
+
maxResults: PAGE_SIZE,
|
|
65
|
+
},
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${this.token}`,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Request with retry logic for Bank Frick's API. In addition to standard retry logic, this function
|
|
73
|
+
* compares errors against expected errors from the Bank Frick API, and will throw without retries
|
|
74
|
+
* on a known fatal error, or try to refresh the JWT on a known auth error
|
|
75
|
+
**/
|
|
76
|
+
async makeRequest(axiosRequest, config, signingAlgorithm) {
|
|
77
|
+
let retryNumber = 0;
|
|
78
|
+
let response = await axios_1.default.request(axiosRequest);
|
|
79
|
+
while (response.status !== 200) {
|
|
80
|
+
retryNumber++;
|
|
81
|
+
logger.warn('Encountered error when fetching accounts from Bank Frick:', response.status, response.statusText);
|
|
82
|
+
// Evaluate whether the error was fatal, auth, or transient and whether we've exceeded the max number of retries.
|
|
83
|
+
// Throw on fatal, refresh token on auth error, pass on transient until we've exhausted our retries
|
|
84
|
+
if (FatalErrors[response.status]) {
|
|
85
|
+
throw new error_1.AdapterError({
|
|
86
|
+
statusCode: response.status,
|
|
87
|
+
message: response.statusText,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if (AuthErrors[response.status]) {
|
|
91
|
+
// We've encountered a known auth error, so try to refresh the token before making another request
|
|
92
|
+
logger.info('Auth error received from the Bank Frick API, attempting to refresh the token');
|
|
93
|
+
this.token = await (0, util_1.generateJWT)(config, signingAlgorithm);
|
|
94
|
+
}
|
|
95
|
+
else if (retryNumber === config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES) {
|
|
96
|
+
throw new error_1.AdapterError({
|
|
97
|
+
statusCode: 504,
|
|
98
|
+
message: `Bank Frick transport hit the max number of retries (${config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES} retries) and aborted`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
logger.debug(`Sleeping for ${config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES}ms before retrying`);
|
|
102
|
+
await (0, util_2.sleep)(config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES);
|
|
103
|
+
response = await axios_1.default.request(axiosRequest);
|
|
104
|
+
}
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
validateInputParams(params) {
|
|
108
|
+
const encounteredIds = {};
|
|
109
|
+
const errors = [];
|
|
110
|
+
const { ibanIDs } = params;
|
|
111
|
+
ibanIDs.forEach((v) => {
|
|
112
|
+
if (!v.match(ibanPattern)) {
|
|
113
|
+
errors.push(`Invalid IBAN: ${v}`);
|
|
114
|
+
}
|
|
115
|
+
encounteredIds[v] += 1;
|
|
116
|
+
if (encounteredIds[v] > 1) {
|
|
117
|
+
errors.push(`The following IBAN appears more than once in the input parameters: ${v}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return errors;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Fetches pages of data from the Bank Frick API, scans for accounts by IBAN, and returns the balance
|
|
124
|
+
* of all found accounts. Returns a 404 if any IBAN isn't found.
|
|
125
|
+
*/
|
|
126
|
+
async setup(req, config) {
|
|
127
|
+
const { ibanIDs, signingAlgorithm } = req.requestContext.data;
|
|
128
|
+
const { PAGE_SIZE = 500 } = config;
|
|
129
|
+
logger.debug(`Validating input: ${JSON.stringify(req.requestContext.data)}`);
|
|
130
|
+
// Scan ibanIDs for duplicates and invalid IBANs
|
|
131
|
+
const validationErrors = this.validateInputParams(req.requestContext.data);
|
|
132
|
+
if (validationErrors.length > 0) {
|
|
133
|
+
throw new error_1.AdapterError({
|
|
134
|
+
statusCode: 420,
|
|
135
|
+
message: `Received the following errors when validating inputParameters:\n ${validationErrors.join('\n')}`,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Refresh the token if it isn't set
|
|
139
|
+
if (!this.token) {
|
|
140
|
+
this.token = await (0, util_1.generateJWT)(config, signingAlgorithm);
|
|
141
|
+
}
|
|
142
|
+
let sum = 0;
|
|
143
|
+
let position = 0;
|
|
144
|
+
const keys = ibanIDs;
|
|
145
|
+
logger.info("Fetching accounts from Bank Frick's API...");
|
|
146
|
+
while (keys.length > 0) {
|
|
147
|
+
// TODO Fetching and processing pages can be run concurrently
|
|
148
|
+
const axiosRequest = this.prepareRequest(position, req.requestContext.data, config);
|
|
149
|
+
const response = await this.makeRequest(axiosRequest, config, signingAlgorithm);
|
|
150
|
+
logger.debug(`Evaluating accounts from page ${position / PAGE_SIZE}`);
|
|
151
|
+
response.data.accounts.forEach((v) => {
|
|
152
|
+
logger.trace(`Evaluating ${v.account} (iban: ${v.iban}, type: ${v.type})`);
|
|
153
|
+
const index = ibanIDs.indexOf(v.iban);
|
|
154
|
+
if (index > -1) {
|
|
155
|
+
keys.splice(index, 1);
|
|
156
|
+
sum += v.balance;
|
|
157
|
+
logger.trace(`Found account: ${v.account} (iban: ${v.iban}) with balance of ${v.balance}`);
|
|
158
|
+
logger.trace(`Running sum: ${sum}, number of ibans left to find: ${keys.length}/${ibanIDs.length}`);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
if (!response.data.moreResults) {
|
|
162
|
+
logger.debug('No more results, breaking out of account query loop');
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
position += PAGE_SIZE || 0;
|
|
166
|
+
}
|
|
167
|
+
// 404 if one or more accounts were not found
|
|
168
|
+
if (keys.length > 0) {
|
|
169
|
+
logger.error(`Could not find all accounts, returning 404: ${keys.join(', ')}`);
|
|
170
|
+
const res = {
|
|
171
|
+
data: 0,
|
|
172
|
+
statusCode: 404,
|
|
173
|
+
result: 0,
|
|
174
|
+
};
|
|
175
|
+
await this.cache.set(req.requestContext.cacheKey, res, config.CACHE_MAX_AGE);
|
|
176
|
+
}
|
|
177
|
+
logger.debug('Was able to find all accounts, returning balance across all accounts: ', sum);
|
|
178
|
+
const res = {
|
|
179
|
+
data: sum,
|
|
180
|
+
statusCode: 200,
|
|
181
|
+
result: sum,
|
|
182
|
+
};
|
|
183
|
+
await this.cache.set(req.requestContext.cacheKey, res, config.CACHE_MAX_AGE);
|
|
184
|
+
return res;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.BankFrickAccountsTransport = BankFrickAccountsTransport;
|
|
188
|
+
exports.accountsRestEndpoint = new adapter_1.AdapterEndpoint({
|
|
189
|
+
name: 'accounts',
|
|
190
|
+
transport: new BankFrickAccountsTransport(),
|
|
191
|
+
inputParameters,
|
|
192
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.customSettings = exports.signingAlgorithms = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const util_1 = require("../../../util");
|
|
9
|
+
const logger = (0, util_1.makeLogger)('BankFrickConfig');
|
|
10
|
+
// Used for enum options and validation
|
|
11
|
+
exports.signingAlgorithms = ['rsa-sha256', 'rsa-sha384', 'rsa-sha512'];
|
|
12
|
+
const MAX_PAGE_SIZE = 500;
|
|
13
|
+
exports.customSettings = {
|
|
14
|
+
PAGE_SIZE: {
|
|
15
|
+
description: 'The number of accounts to fetch per call to /accounts. Must be >= 1 and <= 500.',
|
|
16
|
+
type: 'number',
|
|
17
|
+
required: false,
|
|
18
|
+
default: MAX_PAGE_SIZE,
|
|
19
|
+
validate: (value) => {
|
|
20
|
+
if (!value) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
else if (value < 1) {
|
|
24
|
+
return `PAGE_SIZE must be at least >= 1, was ${value}`;
|
|
25
|
+
}
|
|
26
|
+
else if (value > MAX_PAGE_SIZE) {
|
|
27
|
+
return `PAGE_SIZE must be <= 500, was ${value}`;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
PRIVATE_KEY: {
|
|
32
|
+
description: '',
|
|
33
|
+
type: 'string',
|
|
34
|
+
required: true,
|
|
35
|
+
validate: (value) => {
|
|
36
|
+
const failedAlgos = [];
|
|
37
|
+
for (const algorithm of exports.signingAlgorithms) {
|
|
38
|
+
const body = { example: 123 };
|
|
39
|
+
try {
|
|
40
|
+
crypto_1.default.sign(algorithm, Buffer.from(JSON.stringify(body)), value);
|
|
41
|
+
logger.trace("Successfully tested PRIVATE_KEY by signing with algorithm '%s'", algorithm);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
logger.trace("PRIVATE_KEY failed to sign message with algorithm '%s'", algorithm);
|
|
45
|
+
failedAlgos.push(algorithm);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (failedAlgos.length > 0) {
|
|
49
|
+
return `Failed to sign a dummy body using $PRIVATE_KEY with the following algorithms ${failedAlgos.join(',')}`;
|
|
50
|
+
}
|
|
51
|
+
logger.debug('$PRIVATE_KEY successfully signed a dummy body with all supported algorithms');
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|