@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/transports/rest.d.ts
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import { AdapterRequest, AdapterResponse } from '../util/request';
|
|
2
|
-
import { Transport
|
|
2
|
+
import { Transport } from './';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
4
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
5
|
-
import { AdapterConfig } from '../config';
|
|
5
|
+
import { AdapterConfig, SettingsMap } from '../config';
|
|
6
6
|
import { RequestRateLimiter } from '../rate-limiting';
|
|
7
7
|
import { AdapterDependencies } from '../adapter';
|
|
8
8
|
export { AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse };
|
|
9
|
-
/**
|
|
10
|
-
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
11
|
-
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
12
|
-
*/
|
|
13
|
-
declare type RestTransportGenerics = TransportGenerics & {
|
|
14
|
-
/**
|
|
15
|
-
* Type details for any provider specific interfaces.
|
|
16
|
-
*/
|
|
17
|
-
Provider: {
|
|
18
|
-
/**
|
|
19
|
-
* Structure of the body of the request that will be sent to the data provider.
|
|
20
|
-
*/
|
|
21
|
-
RequestBody: unknown;
|
|
22
|
-
/**
|
|
23
|
-
* Structure for the body of the response coming from the data provider.
|
|
24
|
-
*/
|
|
25
|
-
ResponseBody: unknown;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
9
|
/**
|
|
29
10
|
* Transport implementation that takes incoming requests, transforms them into a DataProvider request,
|
|
30
11
|
* and executes that request returning the response immediately from the `setup` function.
|
|
@@ -32,12 +13,14 @@ declare type RestTransportGenerics = TransportGenerics & {
|
|
|
32
13
|
* new adapter requests for the same feed will not trigger a new one, but return an empty promise from
|
|
33
14
|
* the setup instead so the normal cache polling mechanism is used.
|
|
34
15
|
*
|
|
35
|
-
* @typeParam
|
|
16
|
+
* @typeParam AdapterParams - interface for the adapter request body
|
|
17
|
+
* @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
|
|
18
|
+
* @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
|
|
36
19
|
*/
|
|
37
|
-
export declare class RestTransport<
|
|
20
|
+
export declare class RestTransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
|
|
38
21
|
protected config: {
|
|
39
|
-
prepareRequest: (req: AdapterRequest<
|
|
40
|
-
parseResponse: (req: AdapterRequest<
|
|
22
|
+
prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
|
|
23
|
+
parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
|
|
41
24
|
options: {
|
|
42
25
|
requestCoalescing: {
|
|
43
26
|
enabled: boolean;
|
|
@@ -46,12 +29,11 @@ export declare class RestTransport<T extends RestTransportGenerics> implements T
|
|
|
46
29
|
};
|
|
47
30
|
};
|
|
48
31
|
inFlightPrefix: string;
|
|
49
|
-
cache: Cache
|
|
50
|
-
inFlightCache: Cache<boolean>;
|
|
32
|
+
cache: Cache;
|
|
51
33
|
rateLimiter: RequestRateLimiter;
|
|
52
34
|
constructor(config: {
|
|
53
|
-
prepareRequest: (req: AdapterRequest<
|
|
54
|
-
parseResponse: (req: AdapterRequest<
|
|
35
|
+
prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
|
|
36
|
+
parseResponse: (req: AdapterRequest<AdapterParams>, res: AxiosResponse<ProviderResponseBody>, config: AdapterConfig<CustomSettings>) => AdapterResponse<ProviderResponseBody> | Promise<AdapterResponse<ProviderResponseBody>>;
|
|
55
37
|
options: {
|
|
56
38
|
requestCoalescing: {
|
|
57
39
|
enabled: boolean;
|
|
@@ -59,10 +41,11 @@ export declare class RestTransport<T extends RestTransportGenerics> implements T
|
|
|
59
41
|
};
|
|
60
42
|
};
|
|
61
43
|
});
|
|
62
|
-
initialize(dependencies: AdapterDependencies, config: AdapterConfig
|
|
44
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig): Promise<void>;
|
|
45
|
+
hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
|
|
63
46
|
protected waitUntilUnderRateLimit(options: {
|
|
64
47
|
maxRetries: number;
|
|
65
48
|
msBetweenRetries: number;
|
|
66
49
|
}, retry?: number): Promise<void>;
|
|
67
|
-
|
|
50
|
+
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<AdapterResponse<ProviderResponseBody> | undefined>;
|
|
68
51
|
}
|
package/transports/rest.js
CHANGED
|
@@ -37,7 +37,9 @@ const logger = (0, util_1.makeLogger)('RestTransport');
|
|
|
37
37
|
* new adapter requests for the same feed will not trigger a new one, but return an empty promise from
|
|
38
38
|
* the setup instead so the normal cache polling mechanism is used.
|
|
39
39
|
*
|
|
40
|
-
* @typeParam
|
|
40
|
+
* @typeParam AdapterParams - interface for the adapter request body
|
|
41
|
+
* @typeParam ProviderRequestBody - interface for the body of the request to the Data Provider
|
|
42
|
+
* @typeParam ProviderResponseBody - interface for the body of the Data Provider's response
|
|
41
43
|
*/
|
|
42
44
|
class RestTransport {
|
|
43
45
|
constructor(config) {
|
|
@@ -46,12 +48,30 @@ class RestTransport {
|
|
|
46
48
|
async initialize(dependencies, config) {
|
|
47
49
|
this.inFlightPrefix = `${IN_FLIGHT_PREFIX}-`;
|
|
48
50
|
this.cache = dependencies.cache;
|
|
49
|
-
this.inFlightCache = dependencies.cache;
|
|
50
51
|
this.rateLimiter = dependencies.requestRateLimiter;
|
|
51
52
|
// Allow enabling/disabling request coalescing through env var
|
|
52
53
|
this.config.options.requestCoalescing.enabled = config.REQUEST_COALESCING_ENABLED;
|
|
53
54
|
this.config.options.requestCoalescing.entropyMax = config.REQUEST_COALESCING_ENTROPY_MAX;
|
|
54
55
|
}
|
|
56
|
+
async hasBeenSetUp(req) {
|
|
57
|
+
if (!this.config.options.requestCoalescing.enabled) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// Add some entropy here because of possible scenario where the key won't be set before multiple
|
|
61
|
+
// other instances in a burst request try to access the coalescing key.
|
|
62
|
+
const randomMs = Math.random() * (this.config.options.requestCoalescing.entropyMax || 0);
|
|
63
|
+
await (0, util_1.sleep)(randomMs);
|
|
64
|
+
// Check if request is in flight
|
|
65
|
+
const inFlight = await this.cache.get(this.inFlightPrefix + req.requestContext.cacheKey);
|
|
66
|
+
if (inFlight) {
|
|
67
|
+
logger.debug('Request is in flight, transport has been set up');
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
logger.debug('Request not in flight, transport not set up');
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
55
75
|
async waitUntilUnderRateLimit(options, retry = 0) {
|
|
56
76
|
if (this.rateLimiter.isUnderLimits()) {
|
|
57
77
|
logger.trace('Incoming request would not be under limits, moving on');
|
|
@@ -67,24 +87,12 @@ class RestTransport {
|
|
|
67
87
|
await (0, util_1.sleep)(options.msBetweenRetries);
|
|
68
88
|
await this.waitUntilUnderRateLimit(options, retry + 1);
|
|
69
89
|
}
|
|
70
|
-
async
|
|
71
|
-
|
|
72
|
-
// other instances in a burst request try to access the coalescing key.
|
|
73
|
-
const randomMs = Math.random() * (this.config.options.requestCoalescing.entropyMax || 0);
|
|
74
|
-
await (0, util_1.sleep)(randomMs);
|
|
75
|
-
// Check if request is in flight if coalescing is enabled
|
|
76
|
-
const inFlight = this.config.options.requestCoalescing.enabled &&
|
|
77
|
-
(await this.cache.get(this.inFlightPrefix + req.requestContext.cacheKey));
|
|
78
|
-
if (inFlight) {
|
|
79
|
-
logger.debug('Request is in flight, transport has been set up');
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
else if (this.config.options.requestCoalescing.enabled) {
|
|
83
|
-
// If it wasn't in flight and coalescing is disabled, register it as in flight
|
|
90
|
+
async setup(req, config) {
|
|
91
|
+
if (this.config.options.requestCoalescing.enabled) {
|
|
84
92
|
const ttl = config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES *
|
|
85
93
|
config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES;
|
|
86
94
|
logger.debug('Setting up rest transport, setting request in flight in cache');
|
|
87
|
-
await this.
|
|
95
|
+
await this.cache.set(this.inFlightPrefix + req.requestContext.cacheKey, true, ttl + 100); // Can't use Infinity for things like Redis
|
|
88
96
|
}
|
|
89
97
|
const request = await this.config.prepareRequest(req, config);
|
|
90
98
|
logger.trace('Check if we are under rate limits to perform request');
|
package/transports/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../src/transports/rest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCAA2C;AAG3C,+CAAkD;AAClD,iCAAqC;AACrC,2EAA4D;AAK5D,MAAM,gBAAgB,GAAG,UAAU,CAAA;AAEnC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,eAAe,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../src/transports/rest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kCAA2C;AAG3C,+CAAkD;AAClD,iCAAqC;AACrC,2EAA4D;AAK5D,MAAM,gBAAgB,GAAG,UAAU,CAAA;AAEnC,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,eAAe,CAAC,CAAA;AAE1C;;;;;;;;;;GAUG;AACH,MAAa,aAAa;IAWxB,YACY,MAkBT;QAlBS,WAAM,GAAN,MAAM,CAkBf;IACA,CAAC;IAEJ,KAAK,C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CAAC,cAAc,CAAC,IAAI,GAAG;YACxB,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI;YAC1B,OAAO,EAAE,EAAE,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;SAClE,CAAA;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE;YACjD,MAAM,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAA;YAC7E,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC7C;QAED,OAAO,cAAc,CAAA;IACvB,CAAC;CACF;AA1JD,sCA0JC"}
|
package/transports/sse.d.ts
CHANGED
|
@@ -1,61 +1,41 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import EventSource from 'eventsource';
|
|
3
|
-
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
4
1
|
import { Cache } from '../cache';
|
|
5
|
-
import
|
|
2
|
+
import EventSource from 'eventsource';
|
|
3
|
+
import { SettingsMap, AdapterConfig } from '../config';
|
|
4
|
+
import { AxiosRequestConfig } from 'axios';
|
|
6
5
|
import { SubscriptionSet } from '../util';
|
|
7
|
-
import { AdapterRequest,
|
|
8
|
-
import { Transport
|
|
6
|
+
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
7
|
+
import { Transport } from './';
|
|
8
|
+
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
9
9
|
export interface SSEConfig {
|
|
10
10
|
url: string;
|
|
11
11
|
eventSourceInitDict?: EventSource.EventSourceInitDict;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
15
|
-
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
16
|
-
*/
|
|
17
|
-
declare type SSETransportGenerics = TransportGenerics & {
|
|
18
|
-
/**
|
|
19
|
-
* Type details for any provider specific interfaces.
|
|
20
|
-
*/
|
|
21
|
-
Provider: {
|
|
22
|
-
/**
|
|
23
|
-
* Structure of the body of the request that will be sent to the data provider.
|
|
24
|
-
*/
|
|
25
|
-
RequestBody: unknown;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Transport implementation that establishes a long lived connection to a server using the SSE protocol and subcribes to updates.
|
|
30
|
-
*
|
|
31
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[SSETransportGenerics]])
|
|
32
|
-
*/
|
|
33
|
-
export declare class SSETransport<T extends SSETransportGenerics> implements Transport<T> {
|
|
13
|
+
export declare class SSETransport<AdapterParams, ProviderRequestBody, ProviderResponseBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, ProviderResponseBody, CustomSettings> {
|
|
34
14
|
private config;
|
|
35
15
|
EventSource: typeof EventSource;
|
|
36
|
-
cache: Cache
|
|
16
|
+
cache: Cache;
|
|
37
17
|
eventListeners: {
|
|
38
18
|
type: string;
|
|
39
|
-
parseResponse: (evt: MessageEvent) => ProviderResult<
|
|
19
|
+
parseResponse: (evt: MessageEvent) => ProviderResult<AdapterParams>;
|
|
40
20
|
}[];
|
|
41
21
|
sseConnection?: EventSource;
|
|
42
|
-
subscriptionSet: SubscriptionSet<
|
|
22
|
+
subscriptionSet: SubscriptionSet<AdapterParams>;
|
|
43
23
|
timeOfLastReq: number;
|
|
44
|
-
localSubscriptions:
|
|
24
|
+
localSubscriptions: AdapterParams[];
|
|
45
25
|
constructor(config: {
|
|
46
|
-
prepareSSEConnectionConfig: (params:
|
|
47
|
-
prepareKeepAliveRequest
|
|
48
|
-
prepareSubscriptionRequest: (params:
|
|
49
|
-
prepareUnsubscriptionRequest: (params:
|
|
26
|
+
prepareSSEConnectionConfig: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => SSEConfig;
|
|
27
|
+
prepareKeepAliveRequest: (context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
|
|
28
|
+
prepareSubscriptionRequest: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
|
|
29
|
+
prepareUnsubscriptionRequest: (params: AdapterParams[], context: AdapterContext<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody>;
|
|
50
30
|
eventListeners: {
|
|
51
31
|
type: string;
|
|
52
|
-
parseResponse: (evt: MessageEvent) => ProviderResult<
|
|
32
|
+
parseResponse: (evt: MessageEvent) => ProviderResult<AdapterParams>[];
|
|
53
33
|
}[];
|
|
54
34
|
keepaliveSleepMs?: number;
|
|
55
35
|
pollingSleepMs?: number;
|
|
56
36
|
});
|
|
57
|
-
initialize(dependencies: AdapterDependencies, config: AdapterConfig<
|
|
58
|
-
|
|
59
|
-
|
|
37
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<SettingsMap>, endpointName: string): Promise<void>;
|
|
38
|
+
hasBeenSetUp(): Promise<boolean>;
|
|
39
|
+
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
40
|
+
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
60
41
|
}
|
|
61
|
-
export {};
|
package/transports/sse.js
CHANGED
|
@@ -4,16 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SSETransport = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
7
|
const eventsource_1 = __importDefault(require("eventsource"));
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const util_1 = require("../util");
|
|
10
10
|
const _1 = require("./");
|
|
11
11
|
const logger = (0, util_1.makeLogger)('SSETransport');
|
|
12
|
-
/**
|
|
13
|
-
* Transport implementation that establishes a long lived connection to a server using the SSE protocol and subcribes to updates.
|
|
14
|
-
*
|
|
15
|
-
* @typeParam T - Helper struct type that will be used to pass types to the generic parameters (check [[SSETransportGenerics]])
|
|
16
|
-
*/
|
|
17
12
|
class SSETransport {
|
|
18
13
|
constructor(config) {
|
|
19
14
|
this.config = config;
|
|
@@ -30,8 +25,11 @@ class SSETransport {
|
|
|
30
25
|
this.EventSource = dependencies.eventSource;
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
|
-
async
|
|
34
|
-
|
|
28
|
+
async hasBeenSetUp() {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async setup(req, config) {
|
|
32
|
+
logger.debug(`Adding entry to subscription set: [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
35
33
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.SSE_SUBSCRIPTION_TTL);
|
|
36
34
|
}
|
|
37
35
|
// Unlike cache warming, this execute will manage subscriptions
|
|
@@ -39,6 +37,7 @@ class SSETransport {
|
|
|
39
37
|
logger.debug('Starting background execute, getting subscriptions from sorted set');
|
|
40
38
|
const desiredSubs = await this.subscriptionSet.getAll();
|
|
41
39
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
40
|
+
// TODO: More efficient algorithm, this is really easy to read, but high(er) time complexity
|
|
42
41
|
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
43
42
|
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
44
43
|
logger.debug(`${subscribeParams.length} new subscriptions; ${unsubscribeParams.length} to unsubscribe`);
|
|
@@ -82,8 +81,7 @@ class SSETransport {
|
|
|
82
81
|
const unsubscribeRequest = this.config.prepareUnsubscriptionRequest(unsubscribeParams, context);
|
|
83
82
|
makeRequest(unsubscribeRequest);
|
|
84
83
|
}
|
|
85
|
-
if (
|
|
86
|
-
desiredSubs.length &&
|
|
84
|
+
if (desiredSubs.length &&
|
|
87
85
|
Date.now() - this.timeOfLastReq > context.adapterConfig.SSE_KEEPALIVE_SLEEP) {
|
|
88
86
|
const prepareKeepAliveRequest = this.config.prepareKeepAliveRequest(context);
|
|
89
87
|
makeRequest(prepareKeepAliveRequest);
|
package/transports/sse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;AACA,8DAAqC;AAErC,kDAAiD;AACjD,kCAAqD;AAErD,yBAA4D;AAG5D,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,cAAc,CAAC,CAAA;AAOzC,MAAa,YAAY;IAqBvB,YACU,MAsBP;QAtBO,WAAM,GAAN,MAAM,CAsBb;QArCH,gBAAW,GAAuB,qBAAW,CAAA;QAQ7C,kBAAa,GAAG,CAAC,CAAA;QAEjB,+FAA+F;QAC/F,iDAAiD;QACjD,uBAAkB,GAAoB,EAAE,CAAA;IA0BrC,CAAC;IAEJ,KAAK,CAAC,UAAU,CACd,YAAiC,EACjC,MAAkC,EAClC,YAAoB;QAEpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAA;QAC/B,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC,sBAAsB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;QACjF,IAAI,YAAY,CAAC,WAAW,EAAE;YAC5B,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,WAAW,CAAA;SAC5C;IACH,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,CAAC,KAAK,CACT,GAAkC,EAClC,MAAqC;QAErC,MAAM,CAAC,KAAK,CACV,sCAAsC,GAAG,CAAC,cAAc,CAAC,QAAQ,OAAO,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAClG,CAAA;QACD,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAC5B,GA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AAM,EAAE;YAC1B,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,eAAe,EAAE,OAAO,CAAC,CAAA;YACzF,WAAW,CAAC,gBAAgB,CAAC,CAAA;SAC9B;QACD,IAAI,iBAAiB,CAAC,MAAM,EAAE;YAC5B,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,4BAA4B,CACjE,iBAAiB,EACjB,OAAO,CACR,CAAA;YACD,WAAW,CAAC,kBAAkB,CAAC,CAAA;SAChC;QACD,IACE,WAAW,CAAC,MAAM;YAClB,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,mBAAmB,EAC3E;YACA,MAAM,uBAAuB,GAAG,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAA;YAC5E,WAAW,CAAC,uBAAuB,CAAC,CAAA;SACrC;QAED,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,OAAO,CAAC,aAAa,CAAC,6BAA6B,CAAA;IAC5D,CAAC;CACF;AAzJD,oCAyJC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import WebSocket
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
2
|
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
|
-
import { AdapterConfig } from '../config';
|
|
4
|
+
import { AdapterConfig, SettingsMap } from '../config';
|
|
5
5
|
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
6
6
|
import { SubscriptionSet } from '../util';
|
|
7
|
-
import { AdapterRequest,
|
|
8
|
-
import { Transport
|
|
9
|
-
|
|
10
|
-
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined, options?: ClientOptions) => WebSocket;
|
|
7
|
+
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
8
|
+
import { Transport } from './';
|
|
9
|
+
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined) => WebSocket;
|
|
11
10
|
export declare class WebSocketClassProvider {
|
|
12
11
|
static ctor: WebSocketClass;
|
|
13
12
|
static set(ctor: WebSocketClass): void;
|
|
@@ -16,11 +15,9 @@ export declare class WebSocketClassProvider {
|
|
|
16
15
|
/**
|
|
17
16
|
* Config object that is provided to the WebSocketTransport constructor.
|
|
18
17
|
*/
|
|
19
|
-
export interface WebSocketTransportConfig<
|
|
18
|
+
export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> {
|
|
20
19
|
/** Endpoint to which to open the WS connection*/
|
|
21
|
-
url: (context: AdapterContext<
|
|
22
|
-
/** Optional parameters used when establishing the WebSocket connection */
|
|
23
|
-
options?: (context: AdapterContext<T>) => ClientOptions;
|
|
20
|
+
url: (context: AdapterContext<CustomSettings>) => string;
|
|
24
21
|
/** Map of handlers for different WS lifecycle events */
|
|
25
22
|
handlers: {
|
|
26
23
|
/**
|
|
@@ -29,7 +26,7 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
29
26
|
* @param wsConnection - the WebSocket with an established connection
|
|
30
27
|
* @returns an empty Promise, or void
|
|
31
28
|
*/
|
|
32
|
-
open: (wsConnection: WebSocket, context: AdapterContext<
|
|
29
|
+
open: (wsConnection: WebSocket, context: AdapterContext<CustomSettings>) => Promise<void> | void;
|
|
33
30
|
/**
|
|
34
31
|
* Handles when the WS receives a message
|
|
35
32
|
*
|
|
@@ -37,7 +34,7 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
37
34
|
* @param context - the background context for the Adapter
|
|
38
35
|
* @returns a list of cache entries of adapter responses to set in the cache
|
|
39
36
|
*/
|
|
40
|
-
message: (message:
|
|
37
|
+
message: (message: ProviderDataMessage, context: AdapterContext<CustomSettings>) => ProviderResult<AdapterParams>[] | undefined;
|
|
41
38
|
};
|
|
42
39
|
/** Map of "builders", functions that will be used to prepare specific WS messages */
|
|
43
40
|
builders: {
|
|
@@ -47,49 +44,37 @@ export interface WebSocketTransportConfig<T extends WebsocketTransportGenerics>
|
|
|
47
44
|
* @param params - the body of the adapter request
|
|
48
45
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
49
46
|
*/
|
|
50
|
-
subscribeMessage: (params:
|
|
47
|
+
subscribeMessage: (params: AdapterParams) => unknown;
|
|
51
48
|
/**
|
|
52
49
|
* Builds a WS message that will be sent to unsubscribe to a specific feed
|
|
53
50
|
*
|
|
54
51
|
* @param params - the body of the adapter request
|
|
55
52
|
* @returns the WS message (can be any type as long as the [[WebSocket]] doesn't complain)
|
|
56
53
|
*/
|
|
57
|
-
unsubscribeMessage: (params:
|
|
54
|
+
unsubscribeMessage: (params: AdapterParams) => unknown;
|
|
58
55
|
};
|
|
59
56
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Helper struct type that will be used to pass types to the generic parameters of a Transport.
|
|
62
|
-
* Extends the common TransportGenerics, adding Provider specific types for this Batch endpoint.
|
|
63
|
-
*/
|
|
64
|
-
declare type WebsocketTransportGenerics = TransportGenerics & {
|
|
65
|
-
/**
|
|
66
|
-
* Type details for any provider specific interfaces.
|
|
67
|
-
*/
|
|
68
|
-
Provider: {
|
|
69
|
-
/**
|
|
70
|
-
* Structure of any message that will come through the websocket connection.
|
|
71
|
-
*/
|
|
72
|
-
WsMessage: unknown;
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
57
|
/**
|
|
76
58
|
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
77
59
|
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
78
60
|
*
|
|
79
|
-
* @typeParam
|
|
61
|
+
* @typeParam AdapterParams - interface for the adapter request body
|
|
62
|
+
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
80
63
|
*/
|
|
81
|
-
export declare class WebSocketTransport<
|
|
64
|
+
export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams, null, CustomSettings> {
|
|
82
65
|
private config;
|
|
83
|
-
cache: Cache
|
|
66
|
+
cache: Cache;
|
|
84
67
|
rateLimiter: BackgroundExecuteRateLimiter;
|
|
85
|
-
subscriptionSet: SubscriptionSet<
|
|
86
|
-
localSubscriptions:
|
|
68
|
+
subscriptionSet: SubscriptionSet<AdapterParams>;
|
|
69
|
+
localSubscriptions: AdapterParams[];
|
|
87
70
|
wsConnection: WebSocket;
|
|
88
|
-
constructor(config: WebSocketTransportConfig<
|
|
89
|
-
initialize(dependencies: AdapterDependencies,
|
|
90
|
-
|
|
71
|
+
constructor(config: WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings>);
|
|
72
|
+
initialize(dependencies: AdapterDependencies, _: AdapterConfig, endpointName: string): Promise<void>;
|
|
73
|
+
hasBeenSetUp(): Promise<boolean>;
|
|
74
|
+
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
91
75
|
serializeMessage(payload: unknown): string;
|
|
92
|
-
deserializeMessage(data: WebSocket.Data):
|
|
93
|
-
establishWsConnection(context: AdapterContext<
|
|
94
|
-
backgroundExecute(context: AdapterContext<
|
|
76
|
+
deserializeMessage(data: WebSocket.Data): ProviderDataMessage;
|
|
77
|
+
establishWsConnection(context: AdapterContext<CustomSettings>): Promise<unknown>;
|
|
78
|
+
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
95
79
|
}
|
|
80
|
+
export {};
|
package/transports/websocket.js
CHANGED
|
@@ -26,9 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.WebSocketTransport = exports.WebSocketClassProvider =
|
|
29
|
+
exports.WebSocketTransport = exports.WebSocketClassProvider = void 0;
|
|
30
30
|
const ws_1 = __importDefault(require("ws"));
|
|
31
|
-
exports.WebSocket = ws_1.default;
|
|
32
31
|
const util_1 = require("../util");
|
|
33
32
|
const _1 = require("./");
|
|
34
33
|
const transportMetrics = __importStar(require("./metrics"));
|
|
@@ -47,7 +46,8 @@ WebSocketClassProvider.ctor = ws_1.default;
|
|
|
47
46
|
* Transport implementation that takes incoming requests, adds them to an [[subscriptionSet]] and,
|
|
48
47
|
* through a WebSocket connection, subscribes to the relevant feeds to populate the cache.
|
|
49
48
|
*
|
|
50
|
-
* @typeParam
|
|
49
|
+
* @typeParam AdapterParams - interface for the adapter request body
|
|
50
|
+
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
51
51
|
*/
|
|
52
52
|
class WebSocketTransport {
|
|
53
53
|
constructor(config) {
|
|
@@ -56,13 +56,17 @@ class WebSocketTransport {
|
|
|
56
56
|
// This one would not; this is always local state
|
|
57
57
|
this.localSubscriptions = [];
|
|
58
58
|
}
|
|
59
|
-
async initialize(dependencies,
|
|
59
|
+
async initialize(dependencies, _, endpointName) {
|
|
60
60
|
this.cache = dependencies.cache;
|
|
61
61
|
this.rateLimiter = dependencies.backgroundExecuteRateLimiter;
|
|
62
62
|
this.subscriptionSet = dependencies.subscriptionSetFactory.buildSet(endpointName);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// This might need coalescing to avoid too frequent ttl updates
|
|
65
|
+
async hasBeenSetUp() {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
async setup(req, config) {
|
|
69
|
+
logger.debug(`Adding entry to subscription set: [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
66
70
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
67
71
|
}
|
|
68
72
|
serializeMessage(payload) {
|
|
@@ -75,8 +79,7 @@ class WebSocketTransport {
|
|
|
75
79
|
return new Promise((resolve) => {
|
|
76
80
|
const ctor = WebSocketClassProvider.get();
|
|
77
81
|
const url = context.adapterConfig.WS_API_ENDPOINT || this.config.url(context);
|
|
78
|
-
|
|
79
|
-
this.wsConnection = new ctor(url, undefined, options);
|
|
82
|
+
this.wsConnection = new ctor(url);
|
|
80
83
|
this.wsConnection.addEventListener('open', async (event) => {
|
|
81
84
|
logger.debug(`Opened websocket connection. (event type ${event.type})`);
|
|
82
85
|
await this.config.handlers.open(this.wsConnection, context);
|
|
@@ -119,11 +122,11 @@ class WebSocketTransport {
|
|
|
119
122
|
.labels({ endpoint: context.adapterEndpoint.name, transport_type: 'websocket' })
|
|
120
123
|
.set(desiredSubs.length);
|
|
121
124
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
122
|
-
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.
|
|
125
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
123
126
|
const subscribes = subscribeParams
|
|
124
127
|
.map(this.config.builders.subscribeMessage)
|
|
125
128
|
.map(this.serializeMessage);
|
|
126
|
-
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.
|
|
129
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
127
130
|
const unsubscribes = unsubscribeParams
|
|
128
131
|
.map(this.config.builders.unsubscribeMessage)
|
|
129
132
|
.map(this.serializeMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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/logger.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import pino from 'pino';
|
|
|
3
3
|
import { AdapterRequest } from './request';
|
|
4
4
|
import { FastifyReply, HookHandlerDoneFunction } from 'fastify';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
-
import { CensorKeyValue } from './censor/censor-list';
|
|
7
6
|
export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
|
|
8
7
|
export declare type Store = {
|
|
9
8
|
correlationId: string;
|
|
@@ -46,4 +45,3 @@ export declare const makeLogger: (layer: string) => pino.Logger<{
|
|
|
46
45
|
} | undefined;
|
|
47
46
|
} & pino.ChildLoggerOptions>;
|
|
48
47
|
export declare const loggingContextMiddleware: (req: AdapterRequest, res: FastifyReply, done: HookHandlerDoneFunction) => void;
|
|
49
|
-
export declare function censor(obj: any, censorList: CensorKeyValue[]): any;
|
package/util/logger.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.loggingContextMiddleware = exports.makeLogger = exports.colorFactory = exports.COLORS = exports.asyncLocalStorage = void 0;
|
|
7
7
|
const pino_1 = __importDefault(require("pino"));
|
|
8
8
|
const config_1 = require("../config");
|
|
9
9
|
const crypto_1 = require("crypto");
|
|
@@ -39,7 +39,9 @@ const baseLogger = (0, pino_1.default)({
|
|
|
39
39
|
}
|
|
40
40
|
return {};
|
|
41
41
|
},
|
|
42
|
-
transport: process.env['DEBUG'] === 'true'
|
|
42
|
+
transport: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
43
|
+
? debugTransport
|
|
44
|
+
: undefined,
|
|
43
45
|
});
|
|
44
46
|
exports.COLORS = [
|
|
45
47
|
'\u001b[31;1m',
|
|
@@ -96,7 +98,9 @@ const getNextColor = (0, exports.colorFactory)(exports.COLORS);
|
|
|
96
98
|
*/
|
|
97
99
|
const makeLogger = (layer) => baseLogger.child({
|
|
98
100
|
layer,
|
|
99
|
-
color: process.env['DEBUG'] === 'true'
|
|
101
|
+
color: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
102
|
+
? getNextColor()
|
|
103
|
+
: undefined,
|
|
100
104
|
});
|
|
101
105
|
exports.makeLogger = makeLogger;
|
|
102
106
|
const loggingContextMiddleware = (req, res, done) => {
|
|
@@ -115,5 +119,4 @@ function censor(obj, censorList) {
|
|
|
115
119
|
});
|
|
116
120
|
return JSON.parse(stringified);
|
|
117
121
|
}
|
|
118
|
-
exports.censor = censor;
|
|
119
122
|
//# sourceMappingURL=logger.js.map
|
package/util/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/util/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,sCAAwC;AAGxC,mCAAmC;AACnC,uDAAoD;AACpD,uEAAiE;AAEpD,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAE,CAAA;AAMxD,MAAM,cAAc,GAAG;IACrB,MAAM,EAAE,aAAa;IACrB,OAAO,EAAE;QACP,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,OAAO;QACnB,MAAM,EAAE,wCAAwC;QAChD,aAAa,EAAE,wDAAwD;QACvE,aAAa,EAAE,uBAAuB;KACvC;CACF,CAAA;AAED,wEAAwE;AACxE,MAAM,UAAU,GAAG,IAAA,cAAI,EAAC;IACtB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,IAAI,qBAAY,CAAC,SAAS,CAAC,OAAO;IAChF,KAAK,EAAE;QACL,SAAS,CAAC,SAAS,EAAE,MAAM;YACzB,iCAAiC;YACjC,MAAM,UAAU,GAAG,qBAAU,CAAC,MAAM,EAAE,CAAA;YACtC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