@chainlink/external-adapter-framework 0.0.111 → 0.2.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 +37 -3
- package/adapter/basic.js +138 -2
- package/adapter/basic.js.map +1 -1
- package/adapter/price.d.ts +33 -5
- package/adapter/price.js +41 -2
- package/adapter/price.js.map +1 -1
- package/adapter/types.d.ts +18 -1
- package/cache/index.d.ts +3 -10
- package/cache/index.js +4 -46
- package/cache/index.js.map +1 -1
- package/cache/redis.d.ts +1 -8
- package/cache/redis.js +22 -39
- package/cache/redis.js.map +1 -1
- package/config/index.d.ts +6 -1
- package/config/index.js +20 -12
- package/config/index.js.map +1 -1
- package/examples/bank-frick/accounts.d.ts +2 -3
- package/examples/bank-frick/accounts.js +1 -4
- package/examples/bank-frick/accounts.js.map +1 -1
- package/examples/bank-frick/config/index.d.ts +1 -1
- package/examples/coingecko/src/crypto-utils.d.ts +5 -5
- package/examples/coingecko/src/crypto-utils.js +1 -2
- package/examples/coingecko/src/crypto-utils.js.map +1 -1
- package/examples/coingecko/src/endpoint/coins.js.map +1 -1
- package/examples/coingecko/src/endpoint/crypto-marketcap.d.ts +1 -1
- 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 +1 -1
- 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 +1 -4
- 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 +1 -1
- 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 +1 -1
- 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 -3
- package/examples/coingecko/src/global-utils.js.map +1 -1
- package/examples/coingecko/src/index.d.ts +1 -1
- package/examples/coingecko-old/batch-warming.d.ts +1 -1
- package/examples/coingecko-old/batch-warming.js +2 -2
- package/examples/coingecko-old/batch-warming.js.map +1 -1
- package/examples/coingecko-old/rest.js.map +1 -1
- package/examples/cryptocompare/src/endpoints/crypto.d.ts +1 -1
- package/examples/cryptocompare/src/index.d.ts +1 -1
- package/examples/genesis/sseStream.d.ts +2 -2
- package/examples/genesis/sseStream.js +15 -8
- package/examples/genesis/sseStream.js.map +1 -1
- package/examples/ncfx/websocket.d.ts +1 -1
- package/index.d.ts +3 -1
- package/index.js +4 -6
- package/index.js.map +1 -1
- package/metrics/index.d.ts +2 -0
- package/metrics/index.js +5 -4
- package/metrics/index.js.map +1 -1
- package/package.json +4 -7
- package/rate-limiting/index.d.ts +2 -2
- package/transports/batch-warming.d.ts +9 -9
- package/transports/batch-warming.js +40 -13
- package/transports/batch-warming.js.map +1 -1
- package/transports/index.d.ts +23 -26
- package/transports/index.js +2 -59
- package/transports/index.js.map +1 -1
- package/transports/metrics.d.ts +1 -1
- package/transports/rest.d.ts +5 -4
- package/transports/rest.js +16 -22
- package/transports/rest.js.map +1 -1
- package/transports/sse.d.ts +6 -7
- package/transports/sse.js +2 -6
- package/transports/sse.js.map +1 -1
- package/transports/websocket.d.ts +6 -7
- package/transports/websocket.js +5 -9
- package/transports/websocket.js.map +1 -1
- package/util/logger.d.ts +4 -0
- package/util/logger.js +45 -4
- package/util/logger.js.map +1 -1
- 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 +1 -0
- package/util/test-payload-loader.js +2 -1
- package/util/test-payload-loader.js.map +1 -1
- package/validation/error.d.ts +1 -3
- package/validation/error.js +1 -3
- package/validation/error.js.map +1 -1
- package/validation/index.js +12 -14
- package/validation/index.js.map +1 -1
- package/validation/input-params.d.ts +0 -1
- package/validation/input-params.js +0 -28
- package/validation/input-params.js.map +1 -1
- package/validation/input-validator.js +1 -2
- package/validation/input-validator.js.map +1 -1
- package/adapter.d.ts +0 -156
- package/adapter.js +0 -200
- package/adapter.js.map +0 -1
- package/examples/coingecko/batch-warming.d.ts +0 -7
- package/examples/coingecko/batch-warming.js +0 -54
- package/examples/coingecko/batch-warming.js.map +0 -1
- package/examples/coingecko/index.d.ts +0 -2
- package/examples/coingecko/index.js +0 -12
- package/examples/coingecko/index.js.map +0 -1
- package/examples/coingecko/rest.d.ts +0 -12
- package/examples/coingecko/rest.js +0 -55
- package/examples/coingecko/rest.js.map +0 -1
- package/examples/coingecko/src/cryptoUtils.d.ts +0 -31
- package/examples/coingecko/src/cryptoUtils.js +0 -60
- package/examples/coingecko/src/globalUtils.d.ts +0 -27
- package/examples/coingecko/src/globalUtils.js +0 -46
- package/validation/override-functions.d.ts +0 -3
- package/validation/override-functions.js +0 -41
- package/validation/override-functions.js.map +0 -1
- package/validation/preset-tokens.json +0 -23
- package/validation/validator.d.ts +0 -47
- package/validation/validator.js +0 -303
package/transports/index.js
CHANGED
|
@@ -10,31 +10,16 @@ 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
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
17
|
+
exports.buildCacheEntriesFromResults = void 0;
|
|
30
18
|
const cache_1 = require("../cache");
|
|
31
|
-
const util_1 = require("../util");
|
|
32
|
-
const transportMetrics = __importStar(require("./metrics"));
|
|
33
19
|
__exportStar(require("./batch-warming"), exports);
|
|
34
20
|
__exportStar(require("./rest"), exports);
|
|
35
|
-
__exportStar(require("./websocket"), exports);
|
|
36
21
|
__exportStar(require("./sse"), exports);
|
|
37
|
-
|
|
22
|
+
__exportStar(require("./websocket"), exports);
|
|
38
23
|
/**
|
|
39
24
|
* Helper method to build cache entries to set after getting a bunch of responses from a DP.
|
|
40
25
|
*
|
|
@@ -68,46 +53,4 @@ const buildCacheEntriesFromResults = (results, context) => results.map((r) => {
|
|
|
68
53
|
return cacheEntry;
|
|
69
54
|
});
|
|
70
55
|
exports.buildCacheEntriesFromResults = buildCacheEntriesFromResults;
|
|
71
|
-
/**
|
|
72
|
-
* Takes an Adapter, its configuration, and its dependencies, and it creates an express middleware
|
|
73
|
-
* that will pass along the AdapterRequest to the appropriate Transport (acc. to the endpoint in the req.)
|
|
74
|
-
*
|
|
75
|
-
* @param adapter - main adapter object, already initialized
|
|
76
|
-
* @returns the transport handler middleware function
|
|
77
|
-
*/
|
|
78
|
-
const buildTransportHandler = (adapter) => async (req, reply) => {
|
|
79
|
-
// Get transport, must be here because it's already checked in the validator
|
|
80
|
-
const transport = adapter.endpointsMap[req.requestContext.endpointName].transport;
|
|
81
|
-
// Set up transport if it hasn't been done already
|
|
82
|
-
if (!(await transport.hasBeenSetUp(req))) {
|
|
83
|
-
logger.debug('Transport not set up yet, doing so...');
|
|
84
|
-
const immediateResponse = await transport.setup(req, adapter.config);
|
|
85
|
-
if (immediateResponse) {
|
|
86
|
-
logger.debug('Got immediate response from transport, sending as response');
|
|
87
|
-
return reply.send(immediateResponse);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Observe the idle time taken for polling response
|
|
91
|
-
const metricsTimer = transportMetrics.transportPollingDurationSeconds
|
|
92
|
-
.labels({ endpoint: req.requestContext.endpointName })
|
|
93
|
-
.startTimer();
|
|
94
|
-
logger.debug('Transport is set up, polling cache for response...');
|
|
95
|
-
const response = await (0, cache_1.pollResponseFromCache)(adapter.dependencies.cache, req.requestContext.cacheKey, {
|
|
96
|
-
maxRetries: adapter.config.CACHE_POLLING_MAX_RETRIES,
|
|
97
|
-
sleep: adapter.config.CACHE_POLLING_SLEEP_MS,
|
|
98
|
-
});
|
|
99
|
-
metricsTimer({ succeeded: String(!!response) });
|
|
100
|
-
if (response) {
|
|
101
|
-
logger.debug('Got a response from the cache, sending that back');
|
|
102
|
-
return reply.send(response);
|
|
103
|
-
}
|
|
104
|
-
// Record polling mechanism failure to return response
|
|
105
|
-
transportMetrics.transportPollingFailureCount
|
|
106
|
-
.labels({ endpoint: req.requestContext.endpointName })
|
|
107
|
-
.inc();
|
|
108
|
-
logger.debug('Ran out of polling attempts, returning timeout');
|
|
109
|
-
reply.statusCode = 504;
|
|
110
|
-
return reply.send();
|
|
111
|
-
};
|
|
112
|
-
exports.buildTransportHandler = buildTransportHandler;
|
|
113
56
|
//# sourceMappingURL=index.js.map
|
package/transports/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transports/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transports/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,oCAAgF;AAIhF,kDAA+B;AAC/B,yCAAsB;AACtB,wCAAqB;AACrB,8CAA2B;AA0E3B;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,CAC1C,OAAiC,EACjC,OAAuC,EACoB,EAAE,CAC7D,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;IAChB,MAAM,UAAU,GAAG;QACjB,GAAG,EAAE,IAAA,yBAAiB,EAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QACzC,KAAK,EAAE;YACL,MAAM,EAAE,CAAC,CAAC,KAAK;YACf,UAAU,EAAE,GAAG;YACf,IAAI,EAAE;gBACJ,MAAM,EAAE,CAAC,CAAC,KAAK;aAChB;SACF;KACF,CAAA;IAED,IACE,OAAO,CAAC,aAAa,CAAC,eAAe;QACrC,OAAO,CAAC,aAAa,CAAC,4BAA4B,EAClD;QACA,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,aAAa;YACxD,IAAI,EAAE;gBACJ,OAAO,EAAE;oBACP,MAAM,EAAE,IAAA,uBAAe,EAAC,OAAyB,EAAE,CAAC,CAAC,MAAM,CAAC;iBAC7D;aACF;SACF,CAAA;QACD,UAAU,CAAC,KAAK,GAAG,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAA;KACvD;IACD,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA;AA/BS,QAAA,4BAA4B,gCA+BrC"}
|
package/transports/metrics.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as client from 'prom-client';
|
|
2
2
|
import { AdapterContext } from '../adapter';
|
|
3
3
|
import { SettingsMap } from '../config';
|
|
4
|
-
export declare const dataProviderMetricsLabel: (providerStatusCode?: number
|
|
4
|
+
export declare const dataProviderMetricsLabel: (providerStatusCode?: number, method?: string) => {
|
|
5
5
|
provider_status_code: number | undefined;
|
|
6
6
|
method: string;
|
|
7
7
|
};
|
package/transports/rest.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
|
5
5
|
import { AdapterConfig, SettingsMap } from '../config';
|
|
6
6
|
import { RequestRateLimiter } from '../rate-limiting';
|
|
7
7
|
import { AdapterDependencies } from '../adapter';
|
|
8
|
+
export { AxiosRequestConfig as HttpRequestConfig, AxiosResponse as HttpResponse };
|
|
8
9
|
/**
|
|
9
10
|
* Transport implementation that takes incoming requests, transforms them into a DataProvider request,
|
|
10
11
|
* and executes that request returning the response immediately from the `setup` function.
|
|
@@ -28,7 +29,8 @@ export declare class RestTransport<AdapterParams, ProviderRequestBody, ProviderR
|
|
|
28
29
|
};
|
|
29
30
|
};
|
|
30
31
|
inFlightPrefix: string;
|
|
31
|
-
cache: Cache
|
|
32
|
+
cache: Cache<AdapterResponse<ProviderResponseBody>>;
|
|
33
|
+
inFlightCache: Cache<boolean>;
|
|
32
34
|
rateLimiter: RequestRateLimiter;
|
|
33
35
|
constructor(config: {
|
|
34
36
|
prepareRequest: (req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>) => AxiosRequestConfig<ProviderRequestBody> | Promise<AxiosRequestConfig<ProviderRequestBody>>;
|
|
@@ -40,11 +42,10 @@ export declare class RestTransport<AdapterParams, ProviderRequestBody, ProviderR
|
|
|
40
42
|
};
|
|
41
43
|
};
|
|
42
44
|
});
|
|
43
|
-
initialize(dependencies: AdapterDependencies, config: AdapterConfig): Promise<void>;
|
|
44
|
-
hasBeenSetUp(req: AdapterRequest<AdapterParams>): Promise<boolean>;
|
|
45
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
45
46
|
protected waitUntilUnderRateLimit(options: {
|
|
46
47
|
maxRetries: number;
|
|
47
48
|
msBetweenRetries: number;
|
|
48
49
|
}, retry?: number): Promise<void>;
|
|
49
|
-
|
|
50
|
+
foregroundExecute(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<AdapterResponse<ProviderResponseBody> | undefined>;
|
|
50
51
|
}
|
package/transports/rest.js
CHANGED
|
@@ -48,30 +48,12 @@ class RestTransport {
|
|
|
48
48
|
async initialize(dependencies, config) {
|
|
49
49
|
this.inFlightPrefix = `${IN_FLIGHT_PREFIX}-`;
|
|
50
50
|
this.cache = dependencies.cache;
|
|
51
|
+
this.inFlightCache = dependencies.cache;
|
|
51
52
|
this.rateLimiter = dependencies.requestRateLimiter;
|
|
52
53
|
// Allow enabling/disabling request coalescing through env var
|
|
53
54
|
this.config.options.requestCoalescing.enabled = config.REQUEST_COALESCING_ENABLED;
|
|
54
55
|
this.config.options.requestCoalescing.entropyMax = config.REQUEST_COALESCING_ENTROPY_MAX;
|
|
55
56
|
}
|
|
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
|
-
}
|
|
75
57
|
async waitUntilUnderRateLimit(options, retry = 0) {
|
|
76
58
|
if (this.rateLimiter.isUnderLimits()) {
|
|
77
59
|
logger.trace('Incoming request would not be under limits, moving on');
|
|
@@ -87,12 +69,24 @@ class RestTransport {
|
|
|
87
69
|
await (0, util_1.sleep)(options.msBetweenRetries);
|
|
88
70
|
await this.waitUntilUnderRateLimit(options, retry + 1);
|
|
89
71
|
}
|
|
90
|
-
async
|
|
91
|
-
|
|
72
|
+
async foregroundExecute(req, config) {
|
|
73
|
+
// Add some entropy here because of possible scenario where the key won't be set before multiple
|
|
74
|
+
// other instances in a burst request try to access the coalescing key.
|
|
75
|
+
const randomMs = Math.random() * (this.config.options.requestCoalescing.entropyMax || 0);
|
|
76
|
+
await (0, util_1.sleep)(randomMs);
|
|
77
|
+
// Check if request is in flight if coalescing is enabled
|
|
78
|
+
const inFlight = this.config.options.requestCoalescing.enabled &&
|
|
79
|
+
(await this.cache.get(this.inFlightPrefix + req.requestContext.cacheKey));
|
|
80
|
+
if (inFlight) {
|
|
81
|
+
logger.debug('Request is in flight, transport has been set up');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
else if (this.config.options.requestCoalescing.enabled) {
|
|
85
|
+
// If it wasn't in flight and coalescing is disabled, register it as in flight
|
|
92
86
|
const ttl = config.REST_TRANSPORT_MAX_RATE_LIMIT_RETRIES *
|
|
93
87
|
config.REST_TRANSPORT_MS_BETWEEN_RATE_LIMIT_RETRIES;
|
|
94
88
|
logger.debug('Setting up rest transport, setting request in flight in cache');
|
|
95
|
-
await this.
|
|
89
|
+
await this.inFlightCache.set(this.inFlightPrefix + req.requestContext.cacheKey, true, ttl + 100); // Can't use Infinity for things like Redis
|
|
96
90
|
}
|
|
97
91
|
const request = await this.config.prepareRequest(req, config);
|
|
98
92
|
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;
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../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C,0BAA0B;aACxC,MAAM,CAAC;YACN,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,IAAI,KAAK;YAC1D,cAAc,EAAE,GAAG,CAAC,cAAc,CAAC,QAAQ;SAC5C,CAAC;aACD,GAAG,CAAC,IAAI,CAAC,CAAA;QAEZ,uDAAuD;QACvD,GAAG,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;AA3JD,sCA2JC"}
|
package/transports/sse.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ import EventSource from 'eventsource';
|
|
|
3
3
|
import { SettingsMap, AdapterConfig } from '../config';
|
|
4
4
|
import { AxiosRequestConfig } from 'axios';
|
|
5
5
|
import { SubscriptionSet } from '../util';
|
|
6
|
-
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
7
|
-
import { Transport } from './';
|
|
6
|
+
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
7
|
+
import { BackgroundStoredResultType, Transport } from './';
|
|
8
8
|
import { AdapterContext, AdapterDependencies } from '../adapter';
|
|
9
9
|
export interface SSEConfig {
|
|
10
10
|
url: string;
|
|
11
11
|
eventSourceInitDict?: EventSource.EventSourceInitDict;
|
|
12
12
|
}
|
|
13
|
-
export declare class SSETransport<AdapterParams, ProviderRequestBody,
|
|
13
|
+
export declare class SSETransport<AdapterParams, ProviderRequestBody, CustomSettings extends SettingsMap> implements Transport<AdapterParams, BackgroundStoredResultType, CustomSettings> {
|
|
14
14
|
private config;
|
|
15
15
|
EventSource: typeof EventSource;
|
|
16
|
-
cache: Cache
|
|
16
|
+
cache: Cache<AdapterResponse<BackgroundStoredResultType>>;
|
|
17
17
|
eventListeners: {
|
|
18
18
|
type: string;
|
|
19
19
|
parseResponse: (evt: MessageEvent) => ProviderResult<AdapterParams>;
|
|
@@ -34,8 +34,7 @@ export declare class SSETransport<AdapterParams, ProviderRequestBody, ProviderRe
|
|
|
34
34
|
keepaliveSleepMs?: number;
|
|
35
35
|
pollingSleepMs?: number;
|
|
36
36
|
});
|
|
37
|
-
initialize(dependencies: AdapterDependencies, config: AdapterConfig<
|
|
38
|
-
|
|
39
|
-
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
37
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<CustomSettings>, endpointName: string): Promise<void>;
|
|
38
|
+
registerRequest(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
40
39
|
backgroundExecute(context: AdapterContext<CustomSettings>): Promise<number>;
|
|
41
40
|
}
|
package/transports/sse.js
CHANGED
|
@@ -25,11 +25,8 @@ class SSETransport {
|
|
|
25
25
|
this.EventSource = dependencies.eventSource;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
async
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
async setup(req, config) {
|
|
32
|
-
logger.debug(`Adding entry to subscription set: [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
28
|
+
async registerRequest(req, config) {
|
|
29
|
+
logger.debug(`Adding entry to subscription set (ttl: ${config.SSE_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
33
30
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.SSE_SUBSCRIPTION_TTL);
|
|
34
31
|
}
|
|
35
32
|
// Unlike cache warming, this execute will manage subscriptions
|
|
@@ -37,7 +34,6 @@ class SSETransport {
|
|
|
37
34
|
logger.debug('Starting background execute, getting subscriptions from sorted set');
|
|
38
35
|
const desiredSubs = await this.subscriptionSet.getAll();
|
|
39
36
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
40
|
-
// TODO: More efficient algorithm, this is really easy to read, but high(er) time complexity
|
|
41
37
|
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
42
38
|
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
43
39
|
logger.debug(`${subscribeParams.length} new subscriptions; ${unsubscribeParams.length} to unsubscribe`);
|
package/transports/sse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;AACA,8DAAqC;AAErC,kDAAiD;AACjD,kCAAqD;AAErD,
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/transports/sse.ts"],"names":[],"mappings":";;;;;;AACA,8DAAqC;AAErC,kDAAiD;AACjD,kCAAqD;AAErD,yBAAwF;AAGxF,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,cAAc,CAAC,CAAA;AAOzC,MAAa,YAAY;IAiBvB,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,MAAqC,EACrC,YAAoB;QAEpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,KAA2D,CAAA;QACrF,IAAI,CAAC,eAAe,GAAG,YAAY,CAAC,sBAAsB,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../cache';
|
|
|
4
4
|
import { AdapterConfig, SettingsMap } from '../config';
|
|
5
5
|
import { BackgroundExecuteRateLimiter } from '../rate-limiting';
|
|
6
6
|
import { SubscriptionSet } from '../util';
|
|
7
|
-
import { AdapterRequest, ProviderResult } from '../util/request';
|
|
8
|
-
import { Transport } from './';
|
|
7
|
+
import { AdapterRequest, AdapterResponse, ProviderResult } from '../util/request';
|
|
8
|
+
import { Transport, BackgroundStoredResultType } from './';
|
|
9
9
|
declare type WebSocketClass = new (url: string, protocols?: string | string[] | undefined) => WebSocket;
|
|
10
10
|
export declare class WebSocketClassProvider {
|
|
11
11
|
static ctor: WebSocketClass;
|
|
@@ -61,17 +61,16 @@ export interface WebSocketTransportConfig<AdapterParams, ProviderDataMessage, Cu
|
|
|
61
61
|
* @typeParam AdapterParams - interface for the adapter request body
|
|
62
62
|
* @typeParam ProviderDataMessage - interface for a WS message containing processable data (i.e. not part of open/close/login/etc)
|
|
63
63
|
*/
|
|
64
|
-
export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams,
|
|
64
|
+
export declare class WebSocketTransport<AdapterParams, ProviderDataMessage, CustomSettings extends SettingsMap> implements Transport<AdapterParams, BackgroundStoredResultType, CustomSettings> {
|
|
65
65
|
private config;
|
|
66
|
-
cache: Cache
|
|
66
|
+
cache: Cache<AdapterResponse<BackgroundStoredResultType>>;
|
|
67
67
|
rateLimiter: BackgroundExecuteRateLimiter;
|
|
68
68
|
subscriptionSet: SubscriptionSet<AdapterParams>;
|
|
69
69
|
localSubscriptions: AdapterParams[];
|
|
70
70
|
wsConnection: WebSocket;
|
|
71
71
|
constructor(config: WebSocketTransportConfig<AdapterParams, ProviderDataMessage, CustomSettings>);
|
|
72
|
-
initialize(dependencies: AdapterDependencies,
|
|
73
|
-
|
|
74
|
-
setup(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
72
|
+
initialize(dependencies: AdapterDependencies, config: AdapterConfig<CustomSettings>, endpointName: string): Promise<void>;
|
|
73
|
+
registerRequest(req: AdapterRequest<AdapterParams>, config: AdapterConfig<CustomSettings>): Promise<void>;
|
|
75
74
|
serializeMessage(payload: unknown): string;
|
|
76
75
|
deserializeMessage(data: WebSocket.Data): ProviderDataMessage;
|
|
77
76
|
establishWsConnection(context: AdapterContext<CustomSettings>): Promise<unknown>;
|
package/transports/websocket.js
CHANGED
|
@@ -56,17 +56,13 @@ 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, config, 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
|
-
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
async setup(req, config) {
|
|
69
|
-
logger.debug(`Adding entry to subscription set: [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
64
|
+
async registerRequest(req, config) {
|
|
65
|
+
logger.debug(`Adding entry to subscription set (ttl: ${config.WS_SUBSCRIPTION_TTL}): [${req.requestContext.cacheKey}] = ${req.requestContext.data}`);
|
|
70
66
|
await this.subscriptionSet.add(req.requestContext.cacheKey, req.requestContext.data, config.WS_SUBSCRIPTION_TTL);
|
|
71
67
|
}
|
|
72
68
|
serializeMessage(payload) {
|
|
@@ -122,11 +118,11 @@ class WebSocketTransport {
|
|
|
122
118
|
.labels({ endpoint: context.adapterEndpoint.name, transport_type: 'websocket' })
|
|
123
119
|
.set(desiredSubs.length);
|
|
124
120
|
logger.debug('Generating delta (subscribes & unsubscribes)');
|
|
125
|
-
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.includes(s));
|
|
121
|
+
const subscribeParams = desiredSubs.filter((s) => !this.localSubscriptions.map((ls) => JSON.stringify(ls)).includes(JSON.stringify(s)));
|
|
126
122
|
const subscribes = subscribeParams
|
|
127
123
|
.map(this.config.builders.subscribeMessage)
|
|
128
124
|
.map(this.serializeMessage);
|
|
129
|
-
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.includes(s));
|
|
125
|
+
const unsubscribeParams = this.localSubscriptions.filter((s) => !desiredSubs.map((ds) => JSON.stringify(ds)).includes(JSON.stringify(s)));
|
|
130
126
|
const unsubscribes = unsubscribeParams
|
|
131
127
|
.map(this.config.builders.unsubscribeMessage)
|
|
132
128
|
.map(this.serializeMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA0B;AAK1B,kCAAqD;AAErD,
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/transports/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA0B;AAK1B,kCAAqD;AAErD,yBAAwF;AACxF,4DAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,oBAAoB,CAAC,CAAA;AAI/C,MAAa,sBAAsB;IAGjC,MAAM,CAAC,GAAG,CAAC,IAAoB;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,GAAG;QACR,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;;AATH,wDAUC;AATQ,2BAAI,GAAmB,YAAS,CAAA;AAiEzC;;;;;;GAMG;AACH,MAAa,kBAAkB;IAgB7B,YACU,MAAoF;QAApF,WAAM,GAAN,MAAM,CAA8E;QAP9F,+FAA+F;QAC/F,iDAAiD;QACjD,uBAAkB,GAAoB,EAAE,CAAA;IAMrC,CAAC;IAEJ,KAAK,CA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;SAC3E;QAED,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,UAAU,CAAC,MAAM,EAAE;YAC3C,MAAM,CAAC,KAAK,CAAC,6EAA6E,CAAC,CAAA;YAC3F,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;SAC1C;QAED,MAAM,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAChD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC3D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAChC;QAED,6CAA6C;QAC7C,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAA;QAEpF,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAA;QAErC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAC5E,CAAC;CACF;AA9JD,gDA8JC"}
|
package/util/logger.d.ts
CHANGED
|
@@ -3,10 +3,13 @@ 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';
|
|
6
7
|
export declare const asyncLocalStorage: AsyncLocalStorage<unknown>;
|
|
7
8
|
export declare type Store = {
|
|
8
9
|
correlationId: string;
|
|
9
10
|
};
|
|
11
|
+
export declare const COLORS: string[];
|
|
12
|
+
export declare const colorFactory: (colors: string[]) => () => string;
|
|
10
13
|
/**
|
|
11
14
|
* Instead of using a global logger instance, we want to force using a child logger
|
|
12
15
|
* with a specific layer set in it, so that we can filter logs by where they're output from.
|
|
@@ -43,3 +46,4 @@ export declare const makeLogger: (layer: string) => pino.Logger<{
|
|
|
43
46
|
} | undefined;
|
|
44
47
|
} & pino.ChildLoggerOptions>;
|
|
45
48
|
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.loggingContextMiddleware = exports.makeLogger = exports.asyncLocalStorage = void 0;
|
|
6
|
+
exports.censor = 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");
|
|
@@ -15,8 +15,8 @@ const debugTransport = {
|
|
|
15
15
|
options: {
|
|
16
16
|
levelFirst: true,
|
|
17
17
|
levelLabel: 'level',
|
|
18
|
-
ignore: 'layer,pid,hostname,correlationId',
|
|
19
|
-
messageFormat:
|
|
18
|
+
ignore: 'layer,pid,hostname,correlationId,color',
|
|
19
|
+
messageFormat: `\x1b[0m[{correlationId}] {color}[{layer}]\x1b[0m {msg}`,
|
|
20
20
|
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
|
21
21
|
},
|
|
22
22
|
};
|
|
@@ -43,6 +43,41 @@ const baseLogger = (0, pino_1.default)({
|
|
|
43
43
|
? debugTransport
|
|
44
44
|
: undefined,
|
|
45
45
|
});
|
|
46
|
+
exports.COLORS = [
|
|
47
|
+
'\u001b[31;1m',
|
|
48
|
+
'\u001b[32m',
|
|
49
|
+
'\u001b[33m',
|
|
50
|
+
'\u001b[34m',
|
|
51
|
+
'\u001b[35m',
|
|
52
|
+
'\u001b[36m',
|
|
53
|
+
'\u001b[38;2;121;85;72m',
|
|
54
|
+
'\u001b[92m',
|
|
55
|
+
'\u001b[93m',
|
|
56
|
+
'\u001b[94m',
|
|
57
|
+
'\u001b[95m',
|
|
58
|
+
'\u001b[96m',
|
|
59
|
+
'\u001b[38;5;202m',
|
|
60
|
+
'\u001b[38;5;31m',
|
|
61
|
+
'\u001b[38;5;130m',
|
|
62
|
+
'\u001b[38;2;255;122;92m',
|
|
63
|
+
'\u001b[38;2;46;125;50m',
|
|
64
|
+
'\u001b[38;2;129;168;37m',
|
|
65
|
+
'\u001b[38;2;175;180;43m',
|
|
66
|
+
'\u001b[91m',
|
|
67
|
+
'\u001b[38;2;63;81;181m',
|
|
68
|
+
];
|
|
69
|
+
const colorFactory = (colors) => {
|
|
70
|
+
let index = -1;
|
|
71
|
+
return () => {
|
|
72
|
+
index++;
|
|
73
|
+
if (index > colors.length - 1) {
|
|
74
|
+
index = 0;
|
|
75
|
+
}
|
|
76
|
+
return colors[index];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.colorFactory = colorFactory;
|
|
80
|
+
const getNextColor = (0, exports.colorFactory)(exports.COLORS);
|
|
46
81
|
/**
|
|
47
82
|
* Instead of using a global logger instance, we want to force using a child logger
|
|
48
83
|
* with a specific layer set in it, so that we can filter logs by where they're output from.
|
|
@@ -61,7 +96,12 @@ const baseLogger = (0, pino_1.default)({
|
|
|
61
96
|
* @param layer - the layer name to include in the logs (e.g. "SomeMiddleware", "RedisCache", etc.)
|
|
62
97
|
* @returns a layer specific logger
|
|
63
98
|
*/
|
|
64
|
-
const makeLogger = (layer) => baseLogger.child({
|
|
99
|
+
const makeLogger = (layer) => baseLogger.child({
|
|
100
|
+
layer,
|
|
101
|
+
color: process.env['DEBUG'] === 'true' || process.env['NODE_ENV'] === 'development'
|
|
102
|
+
? getNextColor()
|
|
103
|
+
: undefined,
|
|
104
|
+
});
|
|
65
105
|
exports.makeLogger = makeLogger;
|
|
66
106
|
const loggingContextMiddleware = (req, res, done) => {
|
|
67
107
|
const correlationId = req.headers['x-correlation-id'] || (0, crypto_1.randomUUID)();
|
|
@@ -79,4 +119,5 @@ function censor(obj, censorList) {
|
|
|
79
119
|
});
|
|
80
120
|
return JSON.parse(stringified);
|
|
81
121
|
}
|
|
122
|
+
exports.censor = censor;
|
|
82
123
|
//# 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,
|
|
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,wE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GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,GAAG,YAAY,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AAChC,CAAC;AAND,wBAMC"}
|
|
@@ -14,6 +14,6 @@ export declare class SubscriptionSetFactory {
|
|
|
14
14
|
private cacheType;
|
|
15
15
|
private redisClient?;
|
|
16
16
|
private adapterName?;
|
|
17
|
-
constructor(config: AdapterConfig,
|
|
17
|
+
constructor(config: AdapterConfig, adapterName: string, redisClient?: Redis);
|
|
18
18
|
buildSet<T>(endpointName: string): SubscriptionSet<T>;
|
|
19
19
|
}
|
|
@@ -4,7 +4,7 @@ exports.SubscriptionSetFactory = void 0;
|
|
|
4
4
|
const expiring_sorted_set_1 = require("./expiring-sorted-set");
|
|
5
5
|
const redis_sorted_set_1 = require("./redis-sorted-set");
|
|
6
6
|
class SubscriptionSetFactory {
|
|
7
|
-
constructor(config,
|
|
7
|
+
constructor(config, adapterName, redisClient) {
|
|
8
8
|
this.cacheType = config.CACHE_TYPE;
|
|
9
9
|
this.redisClient = redisClient;
|
|
10
10
|
this.adapterName = adapterName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"subscription-set.js","sourceRoot":"","sources":["../../../../src/util/subscription-set/subscription-set.ts"],"names":[],"mappings":";;;AAGA,+DAAyD;AACzD,yDAAyD;AAazD,MAAa,sBAAsB;IAKjC,YAAY,MAAqB,EAAE,WAAmB,EAAE,WAAmB;QACzE,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,QAAQ,CAAI,YAAoB;QAC9B,QAAQ,IAAI,CAAC,SAAS,EAAE;YACtB,KAAK,OAAO;gBACV,OAAO,IAAI,uCAAiB,EAAK,CAAA;YACnC,KAAK,OAAO,CAAC,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;oBACrB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;iBAChF;gBACD,wDAAwD;gBACxD,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,YAAY,kBAAkB,CAAA;gBAChF,OAAO,IAAI,uCAAoB,CAAI,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;aACzE;SACF;IACH,CAAC;CACF;AAzBD,wDAyBC"}
|
|
@@ -22,4 +22,5 @@ declare type TestPayload = (Payload & {
|
|
|
22
22
|
* @returns the parsed payload with individual requests
|
|
23
23
|
*/
|
|
24
24
|
export declare function loadTestPayload(fileName?: string): TestPayload;
|
|
25
|
+
export declare function resolvePayload(fileName?: string): Payload | null;
|
|
25
26
|
export {};
|
|
@@ -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.loadTestPayload = void 0;
|
|
6
|
+
exports.resolvePayload = exports.loadTestPayload = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -81,4 +81,5 @@ function resolvePayload(fileName) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
+
exports.resolvePayload = resolvePayload;
|
|
84
85
|
//# sourceMappingURL=test-payload-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-payload-loader.js","sourceRoot":"","sources":["../../../src/util/test-payload-loader.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAqB;AACrB,4CAAmB;AACnB,gDAAuB;AACvB,qCAAqC;AAGrC,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,mBAAmB,CAAC,CAAA;AAe9C;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,QAAiB;IAC/C,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAA;IACrB,MAAM,MAAM,GAAG;QACb,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC;QACtB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,EAAE;iBACb;aACF;SACF;KACF,CAAA;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpC,IAAI;QACF,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAA;QACxC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE;YAC5C,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,4CAA4C,CAAC,CAAC,CAAA;SAC9F;QACD,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;KACxC;IAAC,OAAO,CAAU,EAAE;QACnB,MAAM,CAAC,IAAI,CAAC,2BAA4B,CAAW,CAAC,OAAO,EAAE,CAAC,CAAA;QAC9D,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;QACpD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;KAC3B;AACH,CAAC;AA3BD,0CA2BC;AAED,
|
|
1
|
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C3B;aAAM;YACL,OAAO,OAAO,CAAA;SACf;KACF;IAAC,MAAM;QACN,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AA7BD,wCA6BC"}
|
package/validation/error.d.ts
CHANGED
|
@@ -8,14 +8,12 @@ declare type ErrorFull = ErrorBasic & {
|
|
|
8
8
|
cause: string;
|
|
9
9
|
};
|
|
10
10
|
export declare type AdapterErrorResponse = {
|
|
11
|
-
jobRunID: string;
|
|
12
11
|
status: string;
|
|
13
12
|
statusCode: number;
|
|
14
13
|
providerStatusCode?: number;
|
|
15
14
|
error: ErrorBasic | ErrorFull;
|
|
16
15
|
};
|
|
17
16
|
export declare class AdapterError extends Error {
|
|
18
|
-
jobRunID: string;
|
|
19
17
|
status: string;
|
|
20
18
|
statusCode: number;
|
|
21
19
|
cause: unknown;
|
|
@@ -26,7 +24,7 @@ export declare class AdapterError extends Error {
|
|
|
26
24
|
metricsLabel?: HttpRequestType;
|
|
27
25
|
name: string;
|
|
28
26
|
message: string;
|
|
29
|
-
constructor({
|
|
27
|
+
constructor({ status, statusCode, name, message, cause, url, errorResponse, feedID, providerStatusCode, metricsLabel, }: Partial<AdapterError>);
|
|
30
28
|
toJSONResponse(): AdapterErrorResponse;
|
|
31
29
|
}
|
|
32
30
|
export declare class AdapterInputError extends AdapterError {
|
package/validation/error.js
CHANGED
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AdapterCustomError = exports.AdapterConnectionError = exports.AdapterDataProviderError = exports.AdapterTimeoutError = exports.AdapterRateLimitError = exports.AdapterInputError = exports.AdapterError = void 0;
|
|
4
4
|
const constants_1 = require("../metrics/constants");
|
|
5
5
|
class AdapterError extends Error {
|
|
6
|
-
constructor({
|
|
6
|
+
constructor({ status = 'errored', statusCode = 500, name = 'AdapterError', message = 'There was an unexpected error in the adapter.', cause, url, errorResponse, feedID, providerStatusCode, metricsLabel = constants_1.HttpRequestType.ADAPTER_ERROR, }) {
|
|
7
7
|
super(message);
|
|
8
|
-
this.jobRunID = jobRunID;
|
|
9
8
|
this.status = status;
|
|
10
9
|
this.statusCode = statusCode;
|
|
11
10
|
this.name = name;
|
|
@@ -32,7 +31,6 @@ class AdapterError extends Error {
|
|
|
32
31
|
};
|
|
33
32
|
const errorFull = { ...errorBasic, stack: this.stack, cause: this.cause };
|
|
34
33
|
return {
|
|
35
|
-
jobRunID: this.jobRunID,
|
|
36
34
|
status: this.status,
|
|
37
35
|
statusCode: this.statusCode,
|
|
38
36
|
providerStatusCode: this.providerStatusCode,
|