@chainlink/external-adapter-framework 0.7.1 → 0.8.0
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/adapter/basic.d.ts +6 -50
- package/adapter/basic.js +2 -165
- package/adapter/basic.js.map +1 -1
- package/adapter/endpoint.d.ts +6 -6
- package/adapter/endpoint.js +0 -1
- package/adapter/endpoint.js.map +1 -1
- package/adapter/price.d.ts +8 -38
- package/adapter/price.js +1 -43
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +14 -37
- package/background-executor.js +4 -19
- package/background-executor.js.map +1 -1
- package/cache/index.d.ts +16 -9
- package/cache/index.js +46 -4
- package/cache/index.js.map +1 -1
- package/config/index.d.ts +1 -19
- package/config/index.js +29 -54
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +25 -17
- package/examples/bank-frick/accounts.js +13 -23
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/index.d.ts +15 -1
- package/examples/bank-frick/index.js +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +4 -18
- package/examples/coingecko/src/crypto-utils.js +2 -1
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.d.ts +3 -20
- package/examples/coingecko/src/endpoint/coins.js +2 -2
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-marketcap.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-volume.d.ts +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js +2 -2
- package/examples/coingecko/src/endpoint/crypto-volume.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto.d.ts +4 -2
- package/examples/coingecko/src/endpoint/crypto.js +2 -2
- package/examples/coingecko/src/endpoint/crypto.js.map +1 -1
- package/examples/coingecko/src/endpoint/dominance.d.ts +2 -2
- package/examples/coingecko/src/endpoint/dominance.js +2 -2
- package/examples/coingecko/src/endpoint/dominance.js.map +1 -1
- package/examples/coingecko/src/endpoint/global-marketcap.d.ts +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js +2 -2
- package/examples/coingecko/src/endpoint/global-marketcap.js.map +1 -1
- package/examples/coingecko/src/global-utils.d.ts +3 -18
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.js +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +7 -0
- package/examples/coingecko-old/batch-warming.js +54 -0
- package/examples/coingecko-old/batch-warming.js.map +1 -0
- package/examples/coingecko-old/index.d.ts +2 -0
- package/examples/coingecko-old/index.js +12 -0
- package/examples/coingecko-old/index.js.map +1 -0
- package/examples/coingecko-old/rest.d.ts +12 -0
- package/examples/coingecko-old/rest.js +55 -0
- package/examples/coingecko-old/rest.js.map +1 -0
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +2 -14
- package/examples/cryptocompare/src/endpoints/crypto.js.map +1 -1
- package/examples/cryptocompare/src/index.js +1 -1
- package/examples/genesis/index.js +1 -1
- package/examples/genesis/sseStream.d.ts +2 -13
- package/examples/genesis/sseStream.js +1 -4
- package/examples/genesis/sseStream.js.map +1 -1
- package/examples/ncfx/config/index.d.ts +12 -0
- package/examples/ncfx/config/index.js +16 -0
- package/examples/ncfx/config/index.js.map +1 -0
- package/examples/ncfx/index.d.ts +13 -0
- package/examples/ncfx/index.js +12 -0
- package/examples/ncfx/index.js.map +1 -0
- package/examples/ncfx/websocket.d.ts +47 -0
- package/examples/ncfx/websocket.js +74 -0
- package/examples/ncfx/websocket.js.map +1 -0
- package/index.d.ts +0 -1
- package/index.js +6 -4
- package/index.js.map +1 -1
- package/metrics/index.d.ts +0 -2
- package/metrics/index.js +4 -5
- package/metrics/index.js.map +1 -1
- package/metrics/util.d.ts +5 -5
- package/metrics/util.js.map +1 -1
- package/package.json +9 -7
- package/rate-limiting/background/fixed-frequency.d.ts +3 -2
- package/rate-limiting/background/fixed-frequency.js.map +1 -1
- package/rate-limiting/index.d.ts +4 -4
- package/rate-limiting/index.js +1 -1
- package/rate-limiting/index.js.map +1 -1
- package/rate-limiting/request/simple-counting.d.ts +3 -2
- package/rate-limiting/request/simple-counting.js.map +1 -1
- package/transports/batch-warming.d.ts +15 -33
- package/transports/batch-warming.js +16 -43
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +31 -65
- package/transports/index.js +59 -2
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +2 -2
- package/transports/metrics.js +2 -2
- package/transports/metrics.js.map +1 -1
- package/transports/rest.d.ts +14 -31
- package/transports/rest.js +25 -17
- package/transports/rest.js.map +1 -1
- package/transports/sse.d.ts +20 -40
- package/transports/sse.js +8 -10
- package/transports/sse.js.map +1 -1
- package/transports/websocket.d.ts +25 -40
- package/transports/websocket.js +13 -10
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +0 -2
- package/util/logger.js +7 -4
- package/util/logger.js.map +1 -1
- package/util/request.d.ts +10 -46
- package/util/subscription-set/subscription-set.d.ts +1 -1
- package/util/subscription-set/subscription-set.js +1 -1
- package/util/subscription-set/subscription-set.js.map +1 -1
- package/util/test-payload-loader.d.ts +0 -1
- package/util/test-payload-loader.js +1 -2
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +3 -1
- package/validation/error.js +4 -2
- package/validation/error.js.map +1 -1
- package/validation/index.js +17 -26
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +1 -0
- package/validation/input-params.js +28 -0
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +2 -1
- package/validation/input-validator.js.map +1 -1
- package/validation/override-functions.d.ts +3 -0
- package/validation/override-functions.js +41 -0
- package/validation/override-functions.js.map +1 -0
- package/README.md +0 -67
- package/transports/routing.d.ts +0 -21
- package/transports/routing.js +0 -50
- package/transports/routing.js.map +0 -1
package/adapter/types.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type EventSource from 'eventsource';
|
|
2
1
|
import Redis from 'ioredis';
|
|
3
|
-
import { Cache } from '../cache';
|
|
4
|
-
import { AdapterConfig, BaseAdapterConfig, SettingsMap } from '../config';
|
|
5
|
-
import { AdapterRateLimitTier, BackgroundExecuteRateLimiter, RequestRateLimiter } from '../rate-limiting';
|
|
6
|
-
import { Transport, TransportGenerics } from '../transports';
|
|
7
|
-
import { AdapterRequest, SubscriptionSetFactory } from '../util';
|
|
8
|
-
import { InputParameters } from '../validation';
|
|
9
|
-
import { Adapter } from './basic';
|
|
10
2
|
import { AdapterEndpoint } from './endpoint';
|
|
3
|
+
import { CustomSettingsType, SettingsMap, AdapterConfig, BaseAdapterConfig } from '../config';
|
|
4
|
+
import { RequestRateLimiter, BackgroundExecuteRateLimiter, AdapterRateLimitTier } from '../rate-limiting';
|
|
5
|
+
import { Transport } from '../transports';
|
|
6
|
+
import { SubscriptionSetFactory } from '../util';
|
|
7
|
+
import { InputParameters } from '../validation';
|
|
8
|
+
import { Cache } from '../cache';
|
|
9
|
+
import type EventSource from 'eventsource';
|
|
11
10
|
export declare type CustomAdapterSettings = SettingsMap & NegatedAdapterSettings;
|
|
12
11
|
declare type NegatedAdapterSettings = {
|
|
13
12
|
[K in keyof BaseAdapterConfig]?: never;
|
|
@@ -33,11 +32,11 @@ export interface AdapterDependencies {
|
|
|
33
32
|
* Context that will be used on background executions of a Transport.
|
|
34
33
|
* For example, the endpointName used to log statements or generate Cache keys.
|
|
35
34
|
*/
|
|
36
|
-
export interface AdapterContext<
|
|
35
|
+
export interface AdapterContext<CustomSettings extends CustomSettingsType<CustomSettings> = SettingsMap> {
|
|
37
36
|
/** Endpoint instance within the adapter that the Transport is related to */
|
|
38
|
-
adapterEndpoint: AdapterEndpoint<
|
|
37
|
+
adapterEndpoint: AdapterEndpoint<unknown, unknown, CustomSettings>;
|
|
39
38
|
/** Initialized config for the adapter that the Transport can access */
|
|
40
|
-
adapterConfig: AdapterConfig<
|
|
39
|
+
adapterConfig: AdapterConfig<CustomSettings>;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Structure to describe rate limits specs for the Adapter
|
|
@@ -46,24 +45,12 @@ export interface AdapterRateLimitingConfig {
|
|
|
46
45
|
/** Adapter rate limits, gotten from the specific tier requested */
|
|
47
46
|
tiers: Record<string, AdapterRateLimitTier>;
|
|
48
47
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Type to perform arbitrary modifications on an adapter request
|
|
51
|
-
*/
|
|
52
|
-
export declare type RequestTransform = (req: AdapterRequest) => void;
|
|
53
|
-
/**
|
|
54
|
-
* Map of overrides objects (symbol -\> symbol) per adapter name
|
|
55
|
-
*/
|
|
56
|
-
export declare type Overrides = {
|
|
57
|
-
[adapterName: string]: {
|
|
58
|
-
[symbol: string]: string;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
48
|
/**
|
|
62
49
|
* Main structure of an External Adapter
|
|
63
50
|
*/
|
|
64
51
|
export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
65
52
|
/** Name of the adapter */
|
|
66
|
-
name:
|
|
53
|
+
name: string;
|
|
67
54
|
/** If present, the string that will be used for requests with no specified endpoint */
|
|
68
55
|
defaultEndpoint?: string;
|
|
69
56
|
/**
|
|
@@ -75,7 +62,7 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
|
75
62
|
* We also can't use generics, because if we had more than one transport with different requests (very likely)
|
|
76
63
|
* then those new types wouldn't match with each other.
|
|
77
64
|
*/
|
|
78
|
-
endpoints: AdapterEndpoint<any>[];
|
|
65
|
+
endpoints: AdapterEndpoint<any, any, CustomSettings>[];
|
|
79
66
|
/** Map of overrides to the default config values for an Adapter */
|
|
80
67
|
envDefaultOverrides?: Partial<BaseAdapterConfig>;
|
|
81
68
|
/** List of custom env vars for this particular adapter (e.g. RPC_URL) */
|
|
@@ -84,10 +71,6 @@ export interface AdapterParams<CustomSettings extends SettingsMap> {
|
|
|
84
71
|
rateLimiting?: AdapterRateLimitingConfig;
|
|
85
72
|
/** Overrides for converting the 'base' parameter that are hardcoded into the adapter. */
|
|
86
73
|
overrides?: Record<string, string>;
|
|
87
|
-
/** Transforms that will apply to the request before submitting it through the adapter request flow */
|
|
88
|
-
requestTransforms?: RequestTransform[];
|
|
89
|
-
/** Bootstrap function that will run when initializing the adapter */
|
|
90
|
-
bootstrap?: (adapter: Adapter<CustomSettings>) => Promise<void>;
|
|
91
74
|
}
|
|
92
75
|
/**
|
|
93
76
|
* Structure to describe rate limits specs for a specific adapter endpoint
|
|
@@ -100,25 +83,19 @@ export interface EndpointRateLimitingConfig {
|
|
|
100
83
|
*/
|
|
101
84
|
allocationPercentage: number;
|
|
102
85
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Helper type structure that contains the different types passed to the generic parameters of an AdapterEndpoint
|
|
105
|
-
*/
|
|
106
|
-
export declare type EndpointGenerics = TransportGenerics;
|
|
107
86
|
/**
|
|
108
87
|
* Structure to describe a specific endpoint in an [[Adapter]]
|
|
109
88
|
*/
|
|
110
|
-
export interface AdapterEndpointParams<
|
|
89
|
+
export interface AdapterEndpointParams<Params, Result, CustomSettings extends SettingsMap> {
|
|
111
90
|
/** Name that will be used to match input params to this endpoint (case insensitive) */
|
|
112
91
|
name: string;
|
|
113
92
|
/** List of alternative endpoint names that will resolve to this same transport (case insensitive) */
|
|
114
93
|
aliases?: string[];
|
|
115
94
|
/** Transport that will be used to handle data processing and communication for this endpoint */
|
|
116
|
-
transport: Transport<
|
|
95
|
+
transport: Transport<Params, Result, CustomSettings>;
|
|
117
96
|
/** Specification of what the body of a request hitting this endpoint should look like (used for validation) */
|
|
118
97
|
inputParameters: InputParameters;
|
|
119
98
|
/** Specific details related to the rate limiting for this endpoint in particular */
|
|
120
99
|
rateLimiting?: EndpointRateLimitingConfig;
|
|
121
|
-
/** Custom function that generates cache keys */
|
|
122
|
-
cacheKeyGenerator?: (data: Record<string, unknown>) => string;
|
|
123
100
|
}
|
|
124
101
|
export {};
|
package/background-executor.js
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.callBackgroundExecutes = void 0;
|
|
27
|
-
const metrics = __importStar(require("./metrics"));
|
|
28
27
|
const util_1 = require("./util");
|
|
28
|
+
const metrics = __importStar(require("./metrics"));
|
|
29
29
|
const logger = (0, util_1.makeLogger)('BackgroundExecutor');
|
|
30
30
|
/**
|
|
31
31
|
* Very simple background loop that will call the [[Transport.backgroundExecute]] functions in all Transports.
|
|
@@ -47,12 +47,11 @@ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
|
|
|
47
47
|
clearTimeout(timeoutsMap[endpointName]);
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const backgroundExecute = transport.backgroundExecute?.bind(transport);
|
|
50
|
+
for (const endpoint of adapter.endpoints) {
|
|
51
|
+
const backgroundExecute = endpoint.transport.backgroundExecute?.bind(endpoint.transport);
|
|
53
52
|
if (!backgroundExecute) {
|
|
54
53
|
logger.debug(`Endpoint "${endpoint.name}" has no background execute, skipping...`);
|
|
55
|
-
|
|
54
|
+
continue;
|
|
56
55
|
}
|
|
57
56
|
const context = {
|
|
58
57
|
adapterEndpoint: endpoint,
|
|
@@ -77,20 +76,6 @@ async function callBackgroundExecutes(adapter, apiShutdownPromise) {
|
|
|
77
76
|
};
|
|
78
77
|
// Start recursive async calls
|
|
79
78
|
handler();
|
|
80
|
-
};
|
|
81
|
-
for (const endpoint of adapter.endpoints) {
|
|
82
|
-
const { transport } = endpoint;
|
|
83
|
-
// Check if transport is a MetaTransport by casting and checking a known property (transports)
|
|
84
|
-
const castMeta = transport;
|
|
85
|
-
if (castMeta.transports) {
|
|
86
|
-
logger.debug(`Encountered MetaTransport ${transport.constructor.name}, calling backgroundExecute on all transports`);
|
|
87
|
-
for (const nestedTransport of Object.values(castMeta.transports)) {
|
|
88
|
-
callBackgroundExecute(endpoint, nestedTransport);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
callBackgroundExecute(endpoint, transport);
|
|
93
|
-
}
|
|
94
79
|
}
|
|
95
80
|
}
|
|
96
81
|
exports.callBackgroundExecutes = callBackgroundExecutes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-executor.js","sourceRoot":"","sources":["../../src/background-executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAoC;AAEpC,
|
|
1
|
+
{"version":3,"file":"background-executor.js","sourceRoot":"","sources":["../../src/background-executor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAmC;AACnC,mDAAoC;AAEpC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAE/C;;;;;;GAMG;AACI,KAAK,UAAU,sBAAsB,CAAC,OAAgB,EAAE,kBAAkC;IAC/F,uFAAuF;IACvF,4FAA4F;IAC5F,IAAI,YAAY,GAAG,KAAK,CAAA;IACxB,MAAM,WAAW,GAEb,EAAE,CAAA;IAEN,kBAAkB,EAAE,IAAI,CAAC,GAAG,EAAE;QAC5B,YAAY,GAAG,IAAI,CAAA;QACnB,KAAK,MAAM,YAAY,IAAI,WAAW,EAAE;YACtC,MAAM,CAAC,KAAK,CAAC,kCAAkC,YAAY,GAAG,CAAC,CAAA;YAC/D,WAAW,CAAC,YAAY,CAAC,CAAC,KAAK,EAAE,CAAA;YACjC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAA;SACxC;IACH,CAAC,CAAC,CAAA;IAEF,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE;QACxC,MAAM,iBAAiB,GAAG,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS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{ AdapterResponse, sleep } from '../util';
|
|
4
|
-
export * from './factory';
|
|
3
|
+
import { AdapterMiddlewareBuilder, AdapterResponse, sleep } from '../util';
|
|
5
4
|
export * from './local';
|
|
6
5
|
export * from './redis';
|
|
6
|
+
export * from './factory';
|
|
7
7
|
/**
|
|
8
8
|
* An object describing an entry in the cache.
|
|
9
9
|
* @typeParam T - the type of the entry's value
|
|
@@ -49,13 +49,13 @@ export interface Cache<T = unknown> {
|
|
|
49
49
|
*/
|
|
50
50
|
delete: (key: string) => Promise<void>;
|
|
51
51
|
}
|
|
52
|
-
export declare const calculateCacheKey: <
|
|
53
|
-
adapterEndpoint: AdapterEndpoint<
|
|
54
|
-
adapterConfig: AdapterConfig<
|
|
52
|
+
export declare const calculateCacheKey: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
|
|
53
|
+
adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
|
|
54
|
+
adapterConfig: AdapterConfig<CustomSettings>;
|
|
55
55
|
}, data: unknown) => string;
|
|
56
|
-
export declare const calculateFeedId: <
|
|
57
|
-
adapterEndpoint: AdapterEndpoint<
|
|
58
|
-
adapterConfig: AdapterConfig<
|
|
56
|
+
export declare const calculateFeedId: <Params, Result, CustomSettings extends SettingsMap>({ adapterEndpoint, adapterConfig, }: {
|
|
57
|
+
adapterEndpoint: AdapterEndpoint<Params, Result, CustomSettings>;
|
|
58
|
+
adapterConfig: AdapterConfig<CustomSettings>;
|
|
59
59
|
}, data: unknown) => string;
|
|
60
60
|
/**
|
|
61
61
|
* Calculates a unique key from the provided data.
|
|
@@ -71,7 +71,6 @@ export declare const calculateFeedId: <T extends import("../transports").Transpo
|
|
|
71
71
|
* ```
|
|
72
72
|
*/
|
|
73
73
|
export declare const calculateKey: <CustomSettings extends SettingsMap>(data: unknown, paramNames: string[], adapterConfig: AdapterConfig<CustomSettings>) => string;
|
|
74
|
-
export declare const calculateStaleness: (expirationTimestamp: number | undefined, ttl: number) => number;
|
|
75
74
|
/**
|
|
76
75
|
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
77
76
|
* amount of retries is exceeded, it returns undefined instead.
|
|
@@ -85,3 +84,11 @@ export declare const pollResponseFromCache: (cache: Cache<AdapterResponse>, key:
|
|
|
85
84
|
maxRetries: number;
|
|
86
85
|
sleep: number;
|
|
87
86
|
}, retry?: number) => Promise<AdapterResponse | undefined>;
|
|
87
|
+
/**
|
|
88
|
+
* Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
|
|
89
|
+
* a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
|
|
90
|
+
*
|
|
91
|
+
* @param adapter - an initialized adapter
|
|
92
|
+
* @returns the cache middleware function
|
|
93
|
+
*/
|
|
94
|
+
export declare const buildCacheMiddleware: AdapterMiddlewareBuilder;
|
package/cache/index.js
CHANGED
|
@@ -10,15 +10,28 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
13
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
27
|
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
29
|
+
exports.buildCacheMiddleware = exports.pollResponseFromCache = exports.calculateKey = exports.calculateFeedId = exports.calculateCacheKey = void 0;
|
|
18
30
|
const util_1 = require("../util");
|
|
19
|
-
|
|
31
|
+
const cacheMetrics = __importStar(require("./metrics"));
|
|
20
32
|
__exportStar(require("./local"), exports);
|
|
21
33
|
__exportStar(require("./redis"), exports);
|
|
34
|
+
__exportStar(require("./factory"), exports);
|
|
22
35
|
const logger = (0, util_1.makeLogger)('Cache');
|
|
23
36
|
// Uses calculateKey to generate a unique key from the endpoint name, data, and input parameters
|
|
24
37
|
const calculateCacheKey = ({ adapterEndpoint, adapterConfig, }, data) => {
|
|
@@ -61,6 +74,10 @@ const calculateKey = (data, paramNames, adapterConfig) => {
|
|
|
61
74
|
const params = data;
|
|
62
75
|
let cacheKey = '';
|
|
63
76
|
for (const paramName of paramNames) {
|
|
77
|
+
// Ignore overrides param when generating cache keys
|
|
78
|
+
if (paramName === 'overrides') {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
64
81
|
const param = params[paramName];
|
|
65
82
|
if (param === undefined) {
|
|
66
83
|
continue;
|
|
@@ -87,7 +104,7 @@ const calculateKey = (data, paramNames, adapterConfig) => {
|
|
|
87
104
|
return cacheKey;
|
|
88
105
|
};
|
|
89
106
|
exports.calculateKey = calculateKey;
|
|
90
|
-
// Calculate the amount of time
|
|
107
|
+
// Calculate the amount of time the non-expired entry has been in the cache
|
|
91
108
|
const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
92
109
|
if (expirationTimestamp) {
|
|
93
110
|
const createTimestamp = expirationTimestamp - ttl;
|
|
@@ -99,7 +116,6 @@ const calculateStaleness = (expirationTimestamp, ttl) => {
|
|
|
99
116
|
return ttl;
|
|
100
117
|
}
|
|
101
118
|
};
|
|
102
|
-
exports.calculateStaleness = calculateStaleness;
|
|
103
119
|
/**
|
|
104
120
|
* Polls the provided Cache for an AdapterResponse set in the provided key. If the maximum
|
|
105
121
|
* amount of retries is exceeded, it returns undefined instead.
|
|
@@ -130,4 +146,30 @@ const pollResponseFromCache = async (cache, key, options, retry = 0) => {
|
|
|
130
146
|
return (0, exports.pollResponseFromCache)(cache, key, options, retry + 1);
|
|
131
147
|
};
|
|
132
148
|
exports.pollResponseFromCache = pollResponseFromCache;
|
|
149
|
+
/**
|
|
150
|
+
* Given a Cache instance in the adapter dependencies, builds a middleware function that will perform
|
|
151
|
+
* a get from said Cache and return that if found; otherwise it'll continue the middleware chain.
|
|
152
|
+
*
|
|
153
|
+
* @param adapter - an initialized adapter
|
|
154
|
+
* @returns the cache middleware function
|
|
155
|
+
*/
|
|
156
|
+
const buildCacheMiddleware = (adapter) => async (req, res) => {
|
|
157
|
+
const response = await adapter.dependencies.cache.get(req.requestContext.cacheKey);
|
|
158
|
+
if (response) {
|
|
159
|
+
logger.debug('Found response from cache, sending that');
|
|
160
|
+
if (adapter.config.METRICS_ENABLED && adapter.config.EXPERIMENTAL_METRICS_ENABLED) {
|
|
161
|
+
const label = cacheMetrics.cacheMetricsLabel(req.requestContext.cacheKey, req.requestContext.meta?.metrics?.feedId || 'N/A', adapter.config.CACHE_TYPE);
|
|
162
|
+
// Record cache staleness and cache get count and value
|
|
163
|
+
const staleness = calculateStaleness(response.maxAge, adapter.config.CACHE_MAX_AGE);
|
|
164
|
+
cacheMetrics.cacheGet(label, response.result, staleness);
|
|
165
|
+
req.requestContext.meta = {
|
|
166
|
+
...req.requestContext.meta,
|
|
167
|
+
metrics: { ...req.requestContext.meta?.metrics, cacheHit: true },
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return res.send(response);
|
|
171
|
+
}
|
|
172
|
+
logger.debug('Did not find response in cache, moving to next middleware');
|
|
173
|
+
};
|
|
174
|
+
exports.buildCacheMiddleware = buildCacheMiddleware;
|
|
133
175
|
//# sourceMappingURL=index.js.map
|
package/cache/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cache/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,kCAMgB;AAChB,wDAAyC;AAEzC,0CAAuB;AACvB,0CAAuB;AACvB,4CAAyB;AAEzB,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,OAAO,CAAC,CAAA;AAoDlC,gGAAgG;AACzF,MAAM,iBAAiB,GAAG,CAC/B,EACE,eAAe,EACf,aAAa,GAId,EACD,IAAa,EACL,EAAE;IACV,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAC,KAAK,CAAC,2BAA2B,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAA;QAC1E,OAAO,aAAa,CAAC,iBAAiB,CAAA;KACvC;IACD,MAAM,QAAQ,GAAG,GAAG,eAAe,CAAC,IAAI,IAAI,IAAA,oBAAY,EAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,CAAA;IAC3F,MAAM,CAAC,KAAK,CAAC,qCAAqC,QAAQ,GAAG,CAAC,CAAA;IAC9D,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAlBY,QAAA,iBAAiB,qBAkB7B;AAEM,MAAM,eAAe,GAAG,CAC7B,EACE,eAAe,EACf,aAAa,GAId,EACD,IAAa,EACL,EAAE;IACV,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;IAC/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;QAChE,OAAO,KAAK,CAAA;KACb;IACD,OAAO,IAAA,oBAAY,EAAC,IA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ts
CHANGED
|
@@ -23,31 +23,16 @@ export declare const BaseSettings: {
|
|
|
23
23
|
readonly type: "string";
|
|
24
24
|
readonly default: "/";
|
|
25
25
|
};
|
|
26
|
-
readonly BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
27
|
-
readonly description: "Flag to toggle batch transport setup validation";
|
|
28
|
-
readonly type: "boolean";
|
|
29
|
-
readonly default: false;
|
|
30
|
-
};
|
|
31
26
|
readonly CACHE_MAX_AGE: {
|
|
32
27
|
readonly description: "Maximum amount of time (in ms) that a response will stay cached";
|
|
33
28
|
readonly type: "number";
|
|
34
29
|
readonly default: 90000;
|
|
35
30
|
};
|
|
36
|
-
readonly CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
37
|
-
readonly description: "Connection timeout for redis client";
|
|
38
|
-
readonly type: "number";
|
|
39
|
-
readonly default: 15000;
|
|
40
|
-
};
|
|
41
31
|
readonly CACHE_REDIS_HOST: {
|
|
42
32
|
readonly description: "Hostname for the Redis instance to be used";
|
|
43
33
|
readonly type: "string";
|
|
44
34
|
readonly default: "127.0.0.1";
|
|
45
35
|
};
|
|
46
|
-
readonly CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
47
|
-
readonly description: "Max cooldown (in ms) before attempting redis reconnection";
|
|
48
|
-
readonly type: "number";
|
|
49
|
-
readonly default: 3000;
|
|
50
|
-
};
|
|
51
36
|
readonly CACHE_REDIS_PASSWORD: {
|
|
52
37
|
readonly description: "The password required for redis auth";
|
|
53
38
|
readonly type: "string";
|
|
@@ -223,13 +208,10 @@ export declare const BaseSettings: {
|
|
|
223
208
|
readonly type: "string";
|
|
224
209
|
};
|
|
225
210
|
};
|
|
226
|
-
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings,
|
|
211
|
+
export declare const buildAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>({ overrides, customSettings, }: {
|
|
227
212
|
overrides?: Partial<BaseAdapterConfig> | undefined;
|
|
228
213
|
customSettings?: SettingsMap | undefined;
|
|
229
|
-
envVarsPrefix?: string | undefined;
|
|
230
214
|
}) => AdapterConfig<CustomSettings>;
|
|
231
|
-
export declare const validateAdapterConfig: <CustomSettings extends CustomSettingsType<CustomSettings> = EmptySettings>(adapterConfig: AdapterConfig<CustomSettings>, customSettings?: SettingsMap) => void;
|
|
232
|
-
export declare const getEnv: (name: string, config: Setting, prefix?: string) => SettingValueType | null;
|
|
233
215
|
declare type SettingValueType = string | number | boolean;
|
|
234
216
|
declare type SettingType<C extends Setting> = C['type'] extends 'string' ? string : C['type'] extends 'number' ? number : C['type'] extends 'boolean' ? boolean : C['type'] extends 'enum' ? C['options'] extends readonly string[] ? C['options'][number] : never : never;
|
|
235
217
|
declare type BaseSettingsType = typeof BaseSettings;
|
package/config/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Import { getRandomRequiredEnv, getRandomEnv, getEnv } from '../util'
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
+
exports.buildAdapterConfig = exports.BaseSettings = void 0;
|
|
4
5
|
exports.BaseSettings = {
|
|
5
6
|
// V2 compat
|
|
6
7
|
// ADAPTER_URL: {
|
|
@@ -31,11 +32,6 @@ exports.BaseSettings = {
|
|
|
31
32
|
type: 'string',
|
|
32
33
|
default: '/',
|
|
33
34
|
},
|
|
34
|
-
BATCH_TRANSPORT_SETUP_VALIDATION: {
|
|
35
|
-
description: 'Flag to toggle batch transport setup validation',
|
|
36
|
-
type: 'boolean',
|
|
37
|
-
default: false,
|
|
38
|
-
},
|
|
39
35
|
CACHE_MAX_AGE: {
|
|
40
36
|
description: 'Maximum amount of time (in ms) that a response will stay cached',
|
|
41
37
|
type: 'number',
|
|
@@ -49,11 +45,10 @@ exports.BaseSettings = {
|
|
|
49
45
|
// type: 'number',
|
|
50
46
|
// default: 30000,
|
|
51
47
|
// },
|
|
52
|
-
CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
48
|
+
// CACHE_REDIS_CONNECTION_TIMEOUT: {
|
|
49
|
+
// type: 'number',
|
|
50
|
+
// default: 15000,
|
|
51
|
+
// },
|
|
57
52
|
CACHE_REDIS_HOST: {
|
|
58
53
|
description: 'Hostname for the Redis instance to be used',
|
|
59
54
|
type: 'string',
|
|
@@ -64,11 +59,10 @@ exports.BaseSettings = {
|
|
|
64
59
|
// type: 'number',
|
|
65
60
|
// default: 500,
|
|
66
61
|
// },
|
|
67
|
-
CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
62
|
+
// CACHE_REDIS_MAX_RECONNECT_COOLDOWN: {
|
|
63
|
+
// type: 'number',
|
|
64
|
+
// default: 3000,
|
|
65
|
+
// },
|
|
72
66
|
CACHE_REDIS_PASSWORD: {
|
|
73
67
|
description: 'The password required for redis auth',
|
|
74
68
|
type: 'string',
|
|
@@ -296,11 +290,12 @@ exports.BaseSettings = {
|
|
|
296
290
|
type: 'string',
|
|
297
291
|
},
|
|
298
292
|
};
|
|
299
|
-
const buildAdapterConfig = ({ overrides = {}, customSettings = {},
|
|
293
|
+
const buildAdapterConfig = ({ overrides = {}, customSettings = {}, }) => {
|
|
294
|
+
const validationErrors = [];
|
|
300
295
|
const vars = {};
|
|
301
296
|
// Iterate base adapter env vars
|
|
302
297
|
for (const [key, config] of Object.entries(exports.BaseSettings)) {
|
|
303
|
-
const value =
|
|
298
|
+
const value = getEnv(key, config) ?? overrides?.[key] ?? config.default;
|
|
304
299
|
vars[key] = value;
|
|
305
300
|
}
|
|
306
301
|
// Iterate custom vars
|
|
@@ -308,47 +303,28 @@ const buildAdapterConfig = ({ overrides = {}, customSettings = {}, envVarsPrefix
|
|
|
308
303
|
if (exports.BaseSettings[key]) {
|
|
309
304
|
throw new Error(`Custom env var "${key}" declared, but a base framework env var with that name already exists.`);
|
|
310
305
|
}
|
|
311
|
-
const value =
|
|
306
|
+
const value = getEnv(key, config) ?? config.default;
|
|
307
|
+
// Check if a required setting has been provided
|
|
308
|
+
if (config.required && value === null) {
|
|
309
|
+
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
310
|
+
}
|
|
311
|
+
else if (config.validate) {
|
|
312
|
+
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
313
|
+
const validationRes = config.validate(value);
|
|
314
|
+
if (validationRes) {
|
|
315
|
+
validationErrors.push(`${key}: ${validationRes}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
312
318
|
vars[key] = value;
|
|
313
319
|
}
|
|
314
|
-
return vars;
|
|
315
|
-
};
|
|
316
|
-
exports.buildAdapterConfig = buildAdapterConfig;
|
|
317
|
-
const validateAdapterConfig = (adapterConfig, customSettings = {}) => {
|
|
318
|
-
const validationErrors = [];
|
|
319
|
-
Object.entries(exports.BaseSettings)
|
|
320
|
-
.concat(Object.entries(customSettings || {}))
|
|
321
|
-
.forEach(([name, setting]) => {
|
|
322
|
-
validateSetting(name, adapterConfig[name], setting, validationErrors);
|
|
323
|
-
});
|
|
324
320
|
if (validationErrors.length > 0) {
|
|
325
321
|
throw new Error(`Validation failed for the following variables:\n ${validationErrors.join('\n')}`);
|
|
326
322
|
}
|
|
323
|
+
return vars;
|
|
327
324
|
};
|
|
328
|
-
exports.
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
if (config.required && (value === null || value === undefined)) {
|
|
332
|
-
validationErrors.push(`${key}: Value is required, but none was provided`);
|
|
333
|
-
}
|
|
334
|
-
else if (config.validate) {
|
|
335
|
-
// Cast validate to unknown because TS can't select one of multiple variants of the validate function signature
|
|
336
|
-
const validationRes = config.validate(value);
|
|
337
|
-
if (validationRes) {
|
|
338
|
-
validationErrors.push(`${key}: ${validationRes}`);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
const getEnvName = (name, prefix = '') => {
|
|
343
|
-
const envName = prefix ? `${prefix}_${name}` : name;
|
|
344
|
-
if (!isEnvNameValid(envName)) {
|
|
345
|
-
throw new Error(`Invalid environment var name: ${envName}. Only '/^[_a-z0-9]+$/i' is supported.`);
|
|
346
|
-
}
|
|
347
|
-
return envName;
|
|
348
|
-
};
|
|
349
|
-
const isEnvNameValid = (name) => /^[_a-z0-9]+$/i.test(name);
|
|
350
|
-
const getEnv = (name, config, prefix = '') => {
|
|
351
|
-
const value = process.env[getEnvName(name, prefix)];
|
|
325
|
+
exports.buildAdapterConfig = buildAdapterConfig;
|
|
326
|
+
const getEnv = (name, config) => {
|
|
327
|
+
const value = process.env[name];
|
|
352
328
|
if (!value) {
|
|
353
329
|
return null;
|
|
354
330
|
}
|
|
@@ -366,5 +342,4 @@ const getEnv = (name, config, prefix = '') => {
|
|
|
366
342
|
return value;
|
|
367
343
|
}
|
|
368
344
|
};
|
|
369
|
-
exports.getEnv = getEnv;
|
|
370
345
|
//# sourceMappingURL=index.js.map
|
package/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";AAAA,uEAAuE;;;AAE1D,QAAA,YAAY,GAAG;IAC1B,YAAY;IACZ,iBAAiB;IACjB,qFAAqF;IACrF,oBAAoB;IACpB,KAAK;IACL,YAAY,EAAE;QACZ,WAAW,EAAE,sDAAsD;QACnE,IAAI,EAAE,QAAQ;KACf;IACD,OAAO,EAAE;QACP,WAAW,EAAE,+BAA+B;QAC5C,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,IAAI;KAChB;IACD,WAAW,EAAE;QACX,WAAW,EACT,gHAAgH;QAClH,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,KAAK;KACf;IACD,WAA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IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CACb,oDAAoD,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClF,CAAA;KACF;IAED,OAAO,IAAqC,CAAA;AAC9C,CAAC,CAAA;AAjDY,QAAA,kBAAkB,sBAiD9B;AAED,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,MAAe,EAA2B,EAAE;IACxE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;IAED,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,QAAQ;YACX,OAAO,KAAK,CAAA;QACd,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;QACxB,KAAK,SAAS;YACZ,OAAO,KAAK,KAAK,MAAM,CAAA;QACzB,KAAK,MAAM;YACT,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACpC,MAAM,IAAI,KAAK,CACb,YAAY,IAAI,gBAAgB,KAAK,iDAAiD,MAAM,CAAC,OAAO,GAAG,CACxG,CAAA;aACF;YACD,OAAO,KAAK,CAAA;KACf;AACH,CAAC,CAAA"}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { AdapterDependencies, AdapterEndpoint } from '../../adapter';
|
|
3
|
-
import { Cache } from '../../cache';
|
|
4
|
-
import { AdapterConfig } from '../../config';
|
|
5
|
-
import { Transport } from '../../transports';
|
|
6
|
-
import { AdapterRequest, AdapterResponse, SingleNumberResultResponse } from '../../util';
|
|
7
|
-
import { customSettings } from './config';
|
|
8
2
|
import { AdapterInputParameters, BankFrickAccountsRequestSchema, BankFrickAccountsResponseSchema, SigningAlgorithm } from './types';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
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';
|
|
16
9
|
/**
|
|
17
10
|
* RestTransport implementation for Bank Frick, which has unusually complex requirements for an EA
|
|
18
11
|
* The RestTransport is generally built to make a single request and return a single response.
|
|
@@ -21,10 +14,11 @@ export declare type AccountsEndpointTypes = {
|
|
|
21
14
|
* This transport does all the heavy lifting in setup(), which is where the paging happens, and it
|
|
22
15
|
* also has complex retry logic that will attempt to refresh the JWT when certain HTTP errors occur
|
|
23
16
|
*/
|
|
24
|
-
export declare class BankFrickAccountsTransport implements Transport<
|
|
17
|
+
export declare class BankFrickAccountsTransport implements Transport<AdapterInputParameters, number, typeof customSettings> {
|
|
25
18
|
token: string;
|
|
26
|
-
cache: Cache
|
|
19
|
+
cache: Cache;
|
|
27
20
|
initialize(dependencies: AdapterDependencies): Promise<void>;
|
|
21
|
+
hasBeenSetUp(): Promise<boolean>;
|
|
28
22
|
/**
|
|
29
23
|
* Creates an AxiosRequestConfig object for fetching a page of accounts from the Bank Frick API
|
|
30
24
|
*/
|
|
@@ -40,6 +34,20 @@ export declare class BankFrickAccountsTransport implements Transport<AccountsEnd
|
|
|
40
34
|
* Fetches pages of data from the Bank Frick API, scans for accounts by IBAN, and returns the balance
|
|
41
35
|
* of all found accounts. Returns a 404 if any IBAN isn't found.
|
|
42
36
|
*/
|
|
43
|
-
|
|
37
|
+
setup(req: AdapterRequest<AdapterInputParameters>, config: AdapterConfig<typeof customSettings>): Promise<AdapterResponse<number>>;
|
|
44
38
|
}
|
|
45
|
-
export declare const accountsRestEndpoint: AdapterEndpoint<
|
|
39
|
+
export declare const accountsRestEndpoint: AdapterEndpoint<AdapterInputParameters, number, {
|
|
40
|
+
readonly PAGE_SIZE: {
|
|
41
|
+
readonly description: "The number of accounts to fetch per call to /accounts. Must be >= 1 and <= 500.";
|
|
42
|
+
readonly type: "number";
|
|
43
|
+
readonly required: false;
|
|
44
|
+
readonly default: 500;
|
|
45
|
+
readonly validate: (value?: number | undefined) => string | undefined;
|
|
46
|
+
};
|
|
47
|
+
readonly PRIVATE_KEY: {
|
|
48
|
+
readonly description: "";
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly required: true;
|
|
51
|
+
readonly validate: (value: string) => string | undefined;
|
|
52
|
+
};
|
|
53
|
+
}>;
|