@factset/frontgate-js-sdk 6.11.1 → 7.0.1
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/CHANGELOG.md +97 -40
- package/dist/lib/esnext/FrontgateClient.js +0 -3
- package/dist/lib/esnext/authentication/index.js +3 -4
- package/dist/lib/esnext/common/errors.js +0 -35
- package/dist/lib/esnext/common/functions.js +0 -84
- package/dist/lib/esnext/common/interfaces/index.js +0 -1
- package/dist/lib/esnext/compat/index.js +0 -3
- package/dist/lib/esnext/connection/index.js +19 -6
- package/dist/lib/esnext/connection/util/functions.js +0 -56
- package/dist/lib/esnext/index.js +0 -1
- package/dist/lib/esnext/message/index.js +1 -1
- package/dist/lib/esnext/message/interfaces/index.js +0 -1
- package/dist/lib/esnext/message/request/TransportLayerClientRequestHeader.js +1 -1
- package/dist/lib/esnext/message/request/raw/example/CreateNotationSearchRequest.js +1 -1
- package/dist/lib/esnext/message/request/raw/index.js +0 -1
- package/dist/lib/esnext/message/response/index.js +0 -5
- package/dist/lib/esnext/message/update/index.js +0 -1
- package/dist/lib/esnext/mixins/EndpointRequestMixin.js +1 -1
- package/dist/lib/esnext/mixins/RemoteLoggerMixin.js +29 -0
- package/dist/lib/esnext/mixins/auth/AppAuthMixin.js +79 -11
- package/dist/lib/esnext/mixins/auth/SessionAuthMixin.js +76 -36
- package/dist/lib/esnext/mixins/auth/UserCredentialAuthMixin.js +82 -12
- package/dist/lib/esnext/mixins/auth/UserPasswordAuthMixin.js +80 -13
- package/dist/lib/esnext/mixins/auth/index.js +0 -31
- package/dist/lib/esnext/mixins/index.js +1 -0
- package/dist/lib/esnext/mixins/subscription/EndpointSubscriptionMixin.js +149 -122
- package/dist/lib/esnext/version.js +1 -1
- package/dist/lib/node/FrontgateClient.js +0 -3
- package/dist/lib/node/authentication/index.js +4 -4
- package/dist/lib/node/common/errors.js +1 -41
- package/dist/lib/node/common/functions.js +0 -92
- package/dist/lib/node/common/interfaces/index.js +0 -1
- package/dist/lib/node/compat/index.js +0 -3
- package/dist/lib/node/connection/index.js +20 -6
- package/dist/lib/node/connection/util/functions.js +0 -63
- package/dist/lib/node/index.js +1 -3
- package/dist/lib/node/message/index.js +2 -1
- package/dist/lib/node/message/interfaces/index.js +0 -1
- package/dist/lib/node/message/request/TransportLayerClientRequestHeader.js +3 -3
- package/dist/lib/node/message/request/raw/example/CreateNotationSearchRequest.js +3 -3
- package/dist/lib/node/message/request/raw/index.js +0 -1
- package/dist/lib/node/message/response/index.js +0 -5
- package/dist/lib/node/message/update/index.js +0 -1
- package/dist/lib/node/mixins/EndpointRequestMixin.js +2 -2
- package/dist/lib/node/mixins/RemoteLoggerMixin.js +33 -0
- package/dist/lib/node/mixins/auth/AppAuthMixin.js +78 -10
- package/dist/lib/node/mixins/auth/SessionAuthMixin.js +75 -35
- package/dist/lib/node/mixins/auth/UserCredentialAuthMixin.js +80 -10
- package/dist/lib/node/mixins/auth/UserPasswordAuthMixin.js +78 -11
- package/dist/lib/node/mixins/auth/index.js +0 -33
- package/dist/lib/node/mixins/index.js +1 -0
- package/dist/lib/node/mixins/subscription/EndpointSubscriptionMixin.js +149 -122
- package/dist/lib/node/version.js +1 -1
- package/dist/lib/types/FrontgateClient.d.ts +0 -1
- package/dist/lib/types/authentication/index.d.ts +3 -4
- package/dist/lib/types/authentication/util/ChallengeResolver.d.ts +2 -1
- package/dist/lib/types/common/errors.d.ts +0 -21
- package/dist/lib/types/common/functions.d.ts +0 -8
- package/dist/lib/types/common/interfaces/index.d.ts +0 -1
- package/dist/lib/types/compat/index.d.ts +0 -3
- package/dist/lib/types/connection/index.d.ts +16 -6
- package/dist/lib/types/connection/util/functions.d.ts +0 -18
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/message/index.d.ts +1 -1
- package/dist/lib/types/message/interfaces/index.d.ts +0 -1
- package/dist/lib/types/message/request/TransportLayerClientRequestHeader.d.ts +1 -0
- package/dist/lib/types/message/request/raw/index.d.ts +0 -1
- package/dist/lib/types/message/response/index.d.ts +0 -5
- package/dist/lib/types/message/update/index.d.ts +0 -1
- package/dist/lib/types/mixins/AuthTokenRequestMixin.d.ts +1 -2
- package/dist/lib/types/mixins/EndpointRequestMixin.d.ts +1 -2
- package/dist/lib/types/mixins/HTTPProxyRequestMixin.d.ts +1 -4
- package/dist/lib/types/mixins/LoggerMixin.d.ts +1 -2
- package/dist/lib/types/mixins/MessageCompressorMixin.d.ts +1 -2
- package/dist/lib/types/mixins/OpenTelemetryMixin.d.ts +1 -2
- package/dist/lib/types/mixins/PingMixin.d.ts +1 -2
- package/dist/lib/types/mixins/ReconnectMixin.d.ts +1 -2
- package/dist/lib/types/mixins/RemoteLoggerMixin.d.ts +16 -0
- package/dist/lib/types/mixins/RequestMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/AppAuthMixin.d.ts +15 -8
- package/dist/lib/types/mixins/auth/CookieTokenAuthMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/FetchAuthenticationMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/SessionAuthMixin.d.ts +10 -5
- package/dist/lib/types/mixins/auth/TokenAuthMixin.d.ts +1 -2
- package/dist/lib/types/mixins/auth/UserCredentialAuthMixin.d.ts +15 -8
- package/dist/lib/types/mixins/auth/UserPasswordAuthMixin.d.ts +15 -8
- package/dist/lib/types/mixins/auth/index.d.ts +0 -8
- package/dist/lib/types/mixins/connection/FrontgateWSMixin.d.ts +1 -2
- package/dist/lib/types/mixins/index.d.ts +2 -1
- package/dist/lib/types/mixins/subscription/EndpointSubscriptionMixin.d.ts +4 -6
- package/dist/lib/types/mixins/subscription/RawSubscriptionMixin.d.ts +1 -2
- package/dist/lib/umd/mdg2.client.min.umd.js +1 -12
- package/dist/lib/umd/mdg2.client.umd.js +4061 -8138
- package/package.json +25 -28
- package/dist/lib/esnext/Mdg2Client.js +0 -185
- package/dist/lib/esnext/authentication/AbstractAuthentication.js +0 -49
- package/dist/lib/esnext/authentication/AppAuthentication.js +0 -70
- package/dist/lib/esnext/authentication/AuthenticationInterface.js +0 -1
- package/dist/lib/esnext/authentication/CookieTokenAuthentication.js +0 -18
- package/dist/lib/esnext/authentication/TokenAuthentication.js +0 -42
- package/dist/lib/esnext/authentication/UserCredentialAuthentication.js +0 -73
- package/dist/lib/esnext/authentication/UserPasswordAuthentication.js +0 -71
- package/dist/lib/esnext/common/Mdg2ClientOptions.js +0 -1
- package/dist/lib/esnext/common/constants.js +0 -10
- package/dist/lib/esnext/common/interfaces/observe/ObserveOptions.js +0 -1
- package/dist/lib/esnext/connection/AbstractFrontgateConnection.js +0 -324
- package/dist/lib/esnext/connection/ConnectionInterface.js +0 -1
- package/dist/lib/esnext/connection/FrontgateWSConnection.js +0 -281
- package/dist/lib/esnext/connection/JobPromise.js +0 -2
- package/dist/lib/esnext/connection/LatencyHandler.js +0 -1
- package/dist/lib/esnext/connection/LatencyTracker.js +0 -47
- package/dist/lib/esnext/connection/MessageProcessor.js +0 -1
- package/dist/lib/esnext/connection/util/Encoding.js +0 -14
- package/dist/lib/esnext/core/RequestModule.js +0 -349
- package/dist/lib/esnext/core/SubscriptionModule.js +0 -104
- package/dist/lib/esnext/core/subscription/EndpointHandler.js +0 -121
- package/dist/lib/esnext/core/subscription/SubjectManager.js +0 -39
- package/dist/lib/esnext/message/MessageFactory.js +0 -36
- package/dist/lib/esnext/message/guards.js +0 -21
- package/dist/lib/esnext/message/interfaces/JobObservable.js +0 -1
- package/dist/lib/esnext/message/request/raw/RawRequestFactory.js +0 -18
- package/dist/lib/esnext/message/response/AuthenticationByTokenResponse.js +0 -1
- package/dist/lib/esnext/message/response/CancelSubscriptionResponse.js +0 -3
- package/dist/lib/esnext/message/response/LoadNotificationMessage.js +0 -1
- package/dist/lib/esnext/message/response/PermissionDeniedResponse.js +0 -6
- package/dist/lib/esnext/message/response/RejectResponse.js +0 -9
- package/dist/lib/esnext/message/update/SubscriptionLossMessage.js +0 -10
- package/dist/lib/esnext/util/TimeOutWrapper.js +0 -51
- package/dist/lib/node/Mdg2Client.js +0 -189
- package/dist/lib/node/authentication/AbstractAuthentication.js +0 -53
- package/dist/lib/node/authentication/AppAuthentication.js +0 -74
- package/dist/lib/node/authentication/AuthenticationInterface.js +0 -2
- package/dist/lib/node/authentication/CookieTokenAuthentication.js +0 -22
- package/dist/lib/node/authentication/TokenAuthentication.js +0 -46
- package/dist/lib/node/authentication/UserCredentialAuthentication.js +0 -77
- package/dist/lib/node/authentication/UserPasswordAuthentication.js +0 -75
- package/dist/lib/node/common/Mdg2ClientOptions.js +0 -2
- package/dist/lib/node/common/constants.js +0 -13
- package/dist/lib/node/common/interfaces/observe/ObserveOptions.js +0 -2
- package/dist/lib/node/connection/AbstractFrontgateConnection.js +0 -328
- package/dist/lib/node/connection/ConnectionInterface.js +0 -2
- package/dist/lib/node/connection/FrontgateWSConnection.js +0 -288
- package/dist/lib/node/connection/JobPromise.js +0 -6
- package/dist/lib/node/connection/LatencyHandler.js +0 -2
- package/dist/lib/node/connection/LatencyTracker.js +0 -51
- package/dist/lib/node/connection/MessageProcessor.js +0 -2
- package/dist/lib/node/connection/util/Encoding.js +0 -18
- package/dist/lib/node/core/RequestModule.js +0 -353
- package/dist/lib/node/core/SubscriptionModule.js +0 -108
- package/dist/lib/node/core/subscription/EndpointHandler.js +0 -125
- package/dist/lib/node/core/subscription/SubjectManager.js +0 -43
- package/dist/lib/node/message/MessageFactory.js +0 -73
- package/dist/lib/node/message/guards.js +0 -30
- package/dist/lib/node/message/interfaces/JobObservable.js +0 -2
- package/dist/lib/node/message/request/raw/RawRequestFactory.js +0 -22
- package/dist/lib/node/message/response/AuthenticationByTokenResponse.js +0 -2
- package/dist/lib/node/message/response/CancelSubscriptionResponse.js +0 -7
- package/dist/lib/node/message/response/LoadNotificationMessage.js +0 -2
- package/dist/lib/node/message/response/PermissionDeniedResponse.js +0 -10
- package/dist/lib/node/message/response/RejectResponse.js +0 -13
- package/dist/lib/node/message/update/SubscriptionLossMessage.js +0 -14
- package/dist/lib/node/util/TimeOutWrapper.js +0 -55
- package/dist/lib/types/Mdg2Client.d.ts +0 -52
- package/dist/lib/types/authentication/AbstractAuthentication.d.ts +0 -17
- package/dist/lib/types/authentication/AppAuthentication.d.ts +0 -12
- package/dist/lib/types/authentication/AuthenticationInterface.d.ts +0 -9
- package/dist/lib/types/authentication/CookieTokenAuthentication.d.ts +0 -6
- package/dist/lib/types/authentication/TokenAuthentication.d.ts +0 -14
- package/dist/lib/types/authentication/UserCredentialAuthentication.d.ts +0 -13
- package/dist/lib/types/authentication/UserPasswordAuthentication.d.ts +0 -14
- package/dist/lib/types/common/Mdg2ClientOptions.d.ts +0 -12
- package/dist/lib/types/common/constants.d.ts +0 -11
- package/dist/lib/types/common/interfaces/observe/ObserveOptions.d.ts +0 -5
- package/dist/lib/types/connection/AbstractFrontgateConnection.d.ts +0 -116
- package/dist/lib/types/connection/ConnectionInterface.d.ts +0 -53
- package/dist/lib/types/connection/FrontgateWSConnection.d.ts +0 -23
- package/dist/lib/types/connection/JobPromise.d.ts +0 -3
- package/dist/lib/types/connection/LatencyHandler.d.ts +0 -1
- package/dist/lib/types/connection/LatencyTracker.d.ts +0 -13
- package/dist/lib/types/connection/MessageProcessor.d.ts +0 -2
- package/dist/lib/types/connection/util/Encoding.d.ts +0 -9
- package/dist/lib/types/core/RequestModule.d.ts +0 -78
- package/dist/lib/types/core/SubscriptionModule.d.ts +0 -24
- package/dist/lib/types/core/subscription/EndpointHandler.d.ts +0 -37
- package/dist/lib/types/core/subscription/SubjectManager.d.ts +0 -21
- package/dist/lib/types/message/MessageFactory.d.ts +0 -29
- package/dist/lib/types/message/guards.d.ts +0 -11
- package/dist/lib/types/message/interfaces/JobObservable.d.ts +0 -4
- package/dist/lib/types/message/request/raw/RawRequestFactory.d.ts +0 -4
- package/dist/lib/types/message/response/AuthenticationByTokenResponse.d.ts +0 -20
- package/dist/lib/types/message/response/CancelSubscriptionResponse.d.ts +0 -3
- package/dist/lib/types/message/response/LoadNotificationMessage.d.ts +0 -8
- package/dist/lib/types/message/response/PermissionDeniedResponse.d.ts +0 -4
- package/dist/lib/types/message/response/RejectResponse.d.ts +0 -5
- package/dist/lib/types/message/update/SubscriptionLossMessage.d.ts +0 -17
- package/dist/lib/types/util/TimeOutWrapper.d.ts +0 -12
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LatencyTracker = void 0;
|
|
4
|
-
const message_1 = require("../message");
|
|
5
|
-
class LatencyTracker {
|
|
6
|
-
constructor(cb, conn) {
|
|
7
|
-
this.cb = cb;
|
|
8
|
-
this.conn = conn;
|
|
9
|
-
this.isRequestPending = false;
|
|
10
|
-
this.request = new message_1.PingRequest();
|
|
11
|
-
}
|
|
12
|
-
start(interval) {
|
|
13
|
-
if (this.timeout !== undefined) {
|
|
14
|
-
throw new Error('LatencyTracker already running!');
|
|
15
|
-
}
|
|
16
|
-
this.conn.setMessageProcessor('Foundation::PingResponse', this.handlePingResponse.bind(this));
|
|
17
|
-
this.timeout = setInterval(() => {
|
|
18
|
-
if (!this.conn.isAuthenticated()) {
|
|
19
|
-
this.cb(undefined, undefined, undefined, 'Skipping ping request, connection not authenticated!');
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (this.isRequestPending) {
|
|
23
|
-
if (Date.now() - this.request.timeAtSender < LatencyTracker.MAX_RESPONSE_LATENCY_MS) {
|
|
24
|
-
this.cb(this.request.timeAtSender, undefined, undefined, 'Skipping ping request, previous request pending!');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
this.cb(this.request.timeAtSender, undefined, undefined, 'Clearing ping request, previous request exceeded timeout!');
|
|
28
|
-
}
|
|
29
|
-
this.isRequestPending = true;
|
|
30
|
-
this.request.resetTimeAtSender();
|
|
31
|
-
void this.conn.send(this.request.getPtlMessage());
|
|
32
|
-
}, interval);
|
|
33
|
-
if (typeof window === 'undefined') {
|
|
34
|
-
this.timeout.unref();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
stop() {
|
|
38
|
-
clearInterval(this.timeout);
|
|
39
|
-
this.timeout = undefined;
|
|
40
|
-
this.isRequestPending = false;
|
|
41
|
-
this.conn.removeMessageProcessor('Foundation::PingResponse');
|
|
42
|
-
}
|
|
43
|
-
handlePingResponse(msg) {
|
|
44
|
-
const resp = new message_1.PingResponse(msg);
|
|
45
|
-
this.cb(resp.timeOfRequest, resp.latencyTotal, resp.latencyAtPeer, undefined);
|
|
46
|
-
this.isRequestPending = false;
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.LatencyTracker = LatencyTracker;
|
|
51
|
-
LatencyTracker.MAX_RESPONSE_LATENCY_MS = 60 * 1000;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Encoding = void 0;
|
|
4
|
-
class Encoding {
|
|
5
|
-
static isSupportedEncoding(encoding) {
|
|
6
|
-
return Encoding.SUPPORTED_ENCODINGS.includes(encoding);
|
|
7
|
-
}
|
|
8
|
-
static isPlainJson(encoding) {
|
|
9
|
-
return Encoding.PLAIN_JSON_ENCODINGS.includes(encoding);
|
|
10
|
-
}
|
|
11
|
-
static isCompressedJson(encoding) {
|
|
12
|
-
return Encoding.COMPRESSED_ENCODINGS.includes(encoding);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.Encoding = Encoding;
|
|
16
|
-
Encoding.SUPPORTED_ENCODINGS = ['jsjson-v2', 'jsjsonc-v2'];
|
|
17
|
-
Encoding.PLAIN_JSON_ENCODINGS = ['jsjson-v2'];
|
|
18
|
-
Encoding.COMPRESSED_ENCODINGS = Encoding.SUPPORTED_ENCODINGS.filter((enc) => enc.includes('jsonc'));
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestModule = exports.DEFAULT_REQUEST_MODULE_OPTIONS = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
const message_1 = require("../message");
|
|
6
|
-
const MessageFactory_1 = require("../message/MessageFactory");
|
|
7
|
-
const authentication_1 = require("../authentication");
|
|
8
|
-
const TimeOutWrapper_1 = require("../util/TimeOutWrapper");
|
|
9
|
-
const functions_1 = require("../common/functions");
|
|
10
|
-
const api_1 = require("@opentelemetry/api");
|
|
11
|
-
const constants_1 = require("../common/constants");
|
|
12
|
-
exports.DEFAULT_REQUEST_MODULE_OPTIONS = {
|
|
13
|
-
defaultTimeoutInMs: constants_1.DEFAULT_TIMEOUT_IN_MS,
|
|
14
|
-
defaultTimeoutTokenInMs: constants_1.DEFAULT_TIMEOUT_TOKEN_IN_MS,
|
|
15
|
-
maxTimeoutsBeforeReconnect: constants_1.DEFAULT_MAX_TIMEOUTS_BEFORE_RECONNECT,
|
|
16
|
-
flagPermissionDenied: constants_1.DEFAULT_FLAG_PERMISSION_DENIED,
|
|
17
|
-
replaySubjectBufferSize: constants_1.DEFAULT_REPLAY_SUBJECT_BUFFER_SIZE,
|
|
18
|
-
};
|
|
19
|
-
class RequestModule {
|
|
20
|
-
constructor(getConnection, logger, options = exports.DEFAULT_REQUEST_MODULE_OPTIONS) {
|
|
21
|
-
this.getConnection = getConnection;
|
|
22
|
-
this.logger = logger;
|
|
23
|
-
this.options = options;
|
|
24
|
-
this.rejectResponsesTimeout = [50, 100, 200, 400, 800, 1600, 3200];
|
|
25
|
-
this.timeoutCounter = 0;
|
|
26
|
-
this.subscription = rxjs_1.Subscription.EMPTY;
|
|
27
|
-
this.chunks = new Map();
|
|
28
|
-
this.replaySubjectBufferSize = options.replaySubjectBufferSize;
|
|
29
|
-
this.requestSubject = new rxjs_1.ReplaySubject(this.replaySubjectBufferSize);
|
|
30
|
-
this.jobs = new Map();
|
|
31
|
-
}
|
|
32
|
-
setLogger(logger) {
|
|
33
|
-
this.logger = logger;
|
|
34
|
-
}
|
|
35
|
-
reset() {
|
|
36
|
-
this.logger.trace('requestModule.reset()');
|
|
37
|
-
this.requestSubject.complete();
|
|
38
|
-
this.requestSubject = new rxjs_1.ReplaySubject(this.replaySubjectBufferSize);
|
|
39
|
-
this.chunks.clear();
|
|
40
|
-
}
|
|
41
|
-
async requestWithQuality(msg, quality, timeOutInMs = this.options.defaultTimeoutInMs) {
|
|
42
|
-
if (quality === 'BST') {
|
|
43
|
-
return this.requestBestQuality(msg, timeOutInMs);
|
|
44
|
-
}
|
|
45
|
-
if (quality && Object.keys(message_1.TransportLayerClientRequestHeader.PRICE_QUALITY).includes(quality)) {
|
|
46
|
-
msg.header.setQuality(quality);
|
|
47
|
-
}
|
|
48
|
-
return this.request(msg, timeOutInMs);
|
|
49
|
-
}
|
|
50
|
-
async requestEndpoint(method, path, data, options, timeOutInMs = this.options.defaultTimeoutInMs) {
|
|
51
|
-
const highLevelRequest = new message_1.HighLevelRequest(method, path, data, options);
|
|
52
|
-
try {
|
|
53
|
-
const response = await this.request(highLevelRequest, timeOutInMs);
|
|
54
|
-
this.logger.info(`Endpoint Response: [${method}] ${path}`, { request: data, response: response.data });
|
|
55
|
-
return { response, data: response.data };
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
const error = (0, functions_1.errorHandler)(err);
|
|
59
|
-
this.logger.warn(`Endpoint Request Failed. ${error.message}`, err);
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async requestProxyEndpoint(method, path, body, options, timeOutInMs = this.options.defaultTimeoutInMs) {
|
|
64
|
-
const httpProxyRequest = new message_1.HTTPProxyRequest(method, path, options);
|
|
65
|
-
if (body) {
|
|
66
|
-
httpProxyRequest.setBody(body);
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const response = await this.request(httpProxyRequest, timeOutInMs);
|
|
70
|
-
this.logger.info(`Proxy Endpoint Response: [${method}] ${path}`, { request: body, response: response.data });
|
|
71
|
-
return { response, data: response.data };
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
const error = (0, functions_1.errorHandler)(err);
|
|
75
|
-
this.logger.warn(`Proxy Endpoint Request Failed. ${error.message}`, err);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
async requestAuthenticationToken(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.options.defaultTimeoutTokenInMs) {
|
|
80
|
-
const request = new message_1.AuthenticationTokenRequest(lifetimeSeconds, idUser, idApplication, timeOutInMs);
|
|
81
|
-
const response = await this.request(request, timeOutInMs);
|
|
82
|
-
return response.getToken();
|
|
83
|
-
}
|
|
84
|
-
async requestAuthenticationTokenExpiry(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.options.defaultTimeoutTokenInMs, otp = false) {
|
|
85
|
-
const request = new message_1.AuthenticationTokenRequest(lifetimeSeconds, idUser, idApplication, timeOutInMs, otp);
|
|
86
|
-
const res = (await this.request(request, timeOutInMs));
|
|
87
|
-
const token = res.getToken();
|
|
88
|
-
const expiry = res.getExpiry();
|
|
89
|
-
return { token, expiry };
|
|
90
|
-
}
|
|
91
|
-
async requestAuthenticationTokenFactorsForCookieAuthentication(lifetimeSeconds, idUser, idApplication, timeOutInMs = this.options.defaultTimeoutTokenInMs) {
|
|
92
|
-
const token = await this.requestAuthenticationToken(lifetimeSeconds, idUser, idApplication, timeOutInMs);
|
|
93
|
-
return new authentication_1.CookieTokenAuthenticationFactors(token);
|
|
94
|
-
}
|
|
95
|
-
onConnection() {
|
|
96
|
-
const connection = this.getConnection();
|
|
97
|
-
if (!connection) {
|
|
98
|
-
throw new Error('Runtime error: Please assign a connection to the client instance.');
|
|
99
|
-
}
|
|
100
|
-
if (this.subscription.closed) {
|
|
101
|
-
connection.onMessage = this.handleMessage.bind(this);
|
|
102
|
-
this.subscription = this.requestSubject.subscribe(this.sendRequest.bind(this));
|
|
103
|
-
this.logger.trace('onConnection');
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
setUpdateMessageHandler(handler) {
|
|
107
|
-
this.updateMessageHandler = handler;
|
|
108
|
-
}
|
|
109
|
-
setLossMessageHandler(handler) {
|
|
110
|
-
this.lossMessageHandler = handler;
|
|
111
|
-
}
|
|
112
|
-
async request(msg, timeOutInMs = this.options.defaultTimeoutInMs) {
|
|
113
|
-
const connection = this.getConnection();
|
|
114
|
-
if (!connection) {
|
|
115
|
-
throw new Error('Runtime error: Please assign a connection to the client instance.');
|
|
116
|
-
}
|
|
117
|
-
if (RequestModule.supportedPermissionDeniedResponseMessages(msg) && this.options.flagPermissionDenied) {
|
|
118
|
-
msg.header.setFlag('permission_denied_response');
|
|
119
|
-
}
|
|
120
|
-
if (RequestModule.supportsChunkedResponse(msg)) {
|
|
121
|
-
msg.header.setFlag('allow_chunked_response');
|
|
122
|
-
}
|
|
123
|
-
msg.header.setTimeout(timeOutInMs);
|
|
124
|
-
return api_1.trace.getTracer('MDG2Client').startActiveSpan('RequestModule.request', async (span) => {
|
|
125
|
-
msg.header.setTracing(span.spanContext());
|
|
126
|
-
const rejectReason = `Request timeout reached (${timeOutInMs} ms) for ${msg.getPtlMessage().Message}`;
|
|
127
|
-
const promise = new Promise((resolve, reject) => {
|
|
128
|
-
this.requestSubject.next({
|
|
129
|
-
msg,
|
|
130
|
-
insertedAt: Date.now(),
|
|
131
|
-
resolve,
|
|
132
|
-
reject,
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
return TimeOutWrapper_1.TimeoutWrapper.wrap(promise, timeOutInMs, rejectReason)
|
|
136
|
-
.then((message) => {
|
|
137
|
-
this.logger.trace('Reset timeout counter');
|
|
138
|
-
this.timeoutCounter = 0;
|
|
139
|
-
return message;
|
|
140
|
-
})
|
|
141
|
-
.catch((e) => {
|
|
142
|
-
if (e.code === 408) {
|
|
143
|
-
this.timeoutCounter++;
|
|
144
|
-
this.logger.trace(`Increment timeout counter to ${this.timeoutCounter}`);
|
|
145
|
-
const maxTimeouts = this.options.maxTimeoutsBeforeReconnect;
|
|
146
|
-
if (this.timeoutCounter === maxTimeouts) {
|
|
147
|
-
this.logger.warn(`Closing connection due to max number of timeouts reached (${maxTimeouts})`);
|
|
148
|
-
connection.close(true).catch((err) => {
|
|
149
|
-
this.logger.error('Error while closing connection', err);
|
|
150
|
-
});
|
|
151
|
-
this.timeoutCounter = 0;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const error = (0, functions_1.errorHandler)(e);
|
|
156
|
-
this.logger.trace(`Endpoint Request Failed. ${error.message}`);
|
|
157
|
-
}
|
|
158
|
-
throw e;
|
|
159
|
-
})
|
|
160
|
-
.finally(() => {
|
|
161
|
-
span.end();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
reRequest(job) {
|
|
166
|
-
this.requestSubject.next({ msg: job.msg, resolve: job.resolve, reject: job.reject });
|
|
167
|
-
}
|
|
168
|
-
async requestBestQuality(msg, timeOutInMs = this.options.defaultTimeoutInMs) {
|
|
169
|
-
const orderedPriceQuality = ['RLT', 'DLY', 'EOD'];
|
|
170
|
-
for (let i = 0; i < orderedPriceQuality.length; i++) {
|
|
171
|
-
msg.header.setQuality(orderedPriceQuality[i]);
|
|
172
|
-
const promise = this.request(msg, timeOutInMs);
|
|
173
|
-
try {
|
|
174
|
-
return await promise;
|
|
175
|
-
}
|
|
176
|
-
catch (err) {
|
|
177
|
-
this.logger.debug(`Failed to perform request in "${orderedPriceQuality[i]}" quality.`, err, msg);
|
|
178
|
-
}
|
|
179
|
-
if (i === orderedPriceQuality.length - 1) {
|
|
180
|
-
return promise;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return { Message: 'Should never happen', Version: 1 };
|
|
184
|
-
}
|
|
185
|
-
prependCollectedChunks(finalResponse) {
|
|
186
|
-
const chunks = this.chunks.get(finalResponse.header.id_job);
|
|
187
|
-
if (chunks === undefined) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
this.logger.trace('Prepending previous chunks to message', finalResponse);
|
|
191
|
-
let chunkedContent = '';
|
|
192
|
-
chunks.forEach((partialResponse) => {
|
|
193
|
-
this.logger.trace('Prepending previous chunk to message', partialResponse);
|
|
194
|
-
chunkedContent += partialResponse.body.value;
|
|
195
|
-
finalResponse.header.processingTime += partialResponse.header.processingTime;
|
|
196
|
-
});
|
|
197
|
-
chunkedContent += finalResponse.body.value;
|
|
198
|
-
finalResponse.body.value = chunkedContent;
|
|
199
|
-
this.chunks.delete(finalResponse.header.id_job);
|
|
200
|
-
}
|
|
201
|
-
collectChunk(partialResponse) {
|
|
202
|
-
if (this.chunks.has(partialResponse.header.id_job)) {
|
|
203
|
-
this.chunks.get(partialResponse.header.id_job)?.push(partialResponse);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
this.chunks.set(partialResponse.header.id_job, [partialResponse]);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
handleMessage(rawMessage) {
|
|
210
|
-
let msg;
|
|
211
|
-
if ((0, message_1.isHighLevelResponseMessage)(rawMessage)) {
|
|
212
|
-
if (MessageFactory_1.MessageFactory.hasNextChunk(rawMessage)) {
|
|
213
|
-
this.logger.trace('Received message chunk', rawMessage);
|
|
214
|
-
this.collectChunk(rawMessage);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
this.prependCollectedChunks(rawMessage);
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
msg = MessageFactory_1.MessageFactory.createMessage(rawMessage);
|
|
221
|
-
}
|
|
222
|
-
catch (createMessageError) {
|
|
223
|
-
this.logger.error('Problem while creating message', createMessageError, rawMessage);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
const { jobId } = msg;
|
|
227
|
-
const job = this.jobs.get(jobId);
|
|
228
|
-
if (msg.isUpdateMessage() && this.updateMessageHandler) {
|
|
229
|
-
this.updateMessageHandler(msg, jobId);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (msg.isLossMessage() && this.lossMessageHandler) {
|
|
233
|
-
this.lossMessageHandler(msg, jobId);
|
|
234
|
-
this.jobs.delete(jobId);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (!job) {
|
|
238
|
-
this.logger.error(`Could not find idJob ${jobId}`, rawMessage);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if ((0, message_1.isRejectResponse)(msg)) {
|
|
242
|
-
this.logger.debug(`RejectResponse received for idJob ${jobId}`, rawMessage);
|
|
243
|
-
this.rejectResponseHandler(job);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if ((0, message_1.isErrorResponse)(msg) || (0, message_1.isPermissionDeniedResponse)(msg)) {
|
|
247
|
-
const debugObject = {
|
|
248
|
-
request: job.request,
|
|
249
|
-
response: msg,
|
|
250
|
-
};
|
|
251
|
-
this.logger.warn(`Received ${msg.name} with idJob: ${jobId}`, debugObject);
|
|
252
|
-
job.reject(msg);
|
|
253
|
-
this.jobs.delete(jobId);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
this.logger.trace(`Received ${msg.name} with idJob: ${jobId}`, msg);
|
|
257
|
-
this.jobs.delete(jobId);
|
|
258
|
-
job.resolve(msg);
|
|
259
|
-
}
|
|
260
|
-
rejectResponseHandler(job) {
|
|
261
|
-
const rejectResponseTimeout = this.getRejectResponseTimeout(job.msg.header.getResendCounter());
|
|
262
|
-
const calculatedTimeout = job.expirationTime - Date.now() - rejectResponseTimeout;
|
|
263
|
-
if (calculatedTimeout < 1) {
|
|
264
|
-
const errorMessage = `Timeout for idJob ${job.msg.header.getJobId()}`;
|
|
265
|
-
this.logger.error(errorMessage);
|
|
266
|
-
job.reject(new message_1.ErrorResponse({
|
|
267
|
-
Message: 'Foundation::ErrorResponse',
|
|
268
|
-
Version: 1,
|
|
269
|
-
id_job: job.msg.header.getJobId(),
|
|
270
|
-
reason: 8,
|
|
271
|
-
details: errorMessage,
|
|
272
|
-
}));
|
|
273
|
-
}
|
|
274
|
-
this.logger.debug(`Retry request after ${rejectResponseTimeout}ms for idJob ${job.msg.header.getJobId()}`);
|
|
275
|
-
setTimeout(() => {
|
|
276
|
-
job.msg.header.setTimeout(calculatedTimeout);
|
|
277
|
-
job.msg.header.countResend();
|
|
278
|
-
this.reRequest(job);
|
|
279
|
-
}, rejectResponseTimeout);
|
|
280
|
-
}
|
|
281
|
-
getRejectResponseTimeout(resendCounter = 0) {
|
|
282
|
-
const lastIndex = this.rejectResponsesTimeout.length - 1;
|
|
283
|
-
return this.rejectResponsesTimeout[resendCounter] ?? this.rejectResponsesTimeout[lastIndex];
|
|
284
|
-
}
|
|
285
|
-
async sendRequest(req) {
|
|
286
|
-
const connection = this.getConnection();
|
|
287
|
-
if (!connection) {
|
|
288
|
-
req.reject('Runtime error: Please assign a connection to the client instance.');
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
while (!connection.isAuthenticated()) {
|
|
292
|
-
if (req.insertedAt && req.insertedAt + req.msg.header.getTimeout() < Date.now()) {
|
|
293
|
-
req.reject('sendRequest timeout reached');
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
await new Promise((resolve) => {
|
|
297
|
-
setTimeout(() => {
|
|
298
|
-
resolve('Timeout reached');
|
|
299
|
-
}, 1000);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
req.msg.header.setIdApplication(connection.auth.idApplication);
|
|
303
|
-
req.msg.header.setIdUser(connection.auth.idUser);
|
|
304
|
-
const json = req.msg.getPtlMessage();
|
|
305
|
-
const jobId = connection.send(json).idJob;
|
|
306
|
-
req.msg.header.setJobId(jobId);
|
|
307
|
-
const debugMsg = {
|
|
308
|
-
json,
|
|
309
|
-
};
|
|
310
|
-
if ((json.Message === message_1.HighLevelRequest.NAME || json.Message === message_1.HTTPProxyRequest.NAME) && typeof req.msg.getData === 'function') {
|
|
311
|
-
debugMsg.data = req.msg.getData();
|
|
312
|
-
}
|
|
313
|
-
const job = {
|
|
314
|
-
msg: req.msg,
|
|
315
|
-
expirationTime: Date.now() + req.msg.header.getTimeout(),
|
|
316
|
-
resolve: req.resolve,
|
|
317
|
-
reject: req.reject,
|
|
318
|
-
request: debugMsg,
|
|
319
|
-
};
|
|
320
|
-
this.jobs.set(jobId, job);
|
|
321
|
-
this.logger.trace(`Sending ${json.Message} with idJob: ${jobId}`, debugMsg);
|
|
322
|
-
}
|
|
323
|
-
clearPendingRequests() {
|
|
324
|
-
this.jobs.forEach((job, jobId) => {
|
|
325
|
-
const errorResponse = new message_1.ErrorResponse({
|
|
326
|
-
Message: 'Foundation::ErrorResponse',
|
|
327
|
-
header: {
|
|
328
|
-
id_job: jobId,
|
|
329
|
-
id_service: '0',
|
|
330
|
-
},
|
|
331
|
-
reason: {
|
|
332
|
-
value: 1001,
|
|
333
|
-
},
|
|
334
|
-
});
|
|
335
|
-
job.reject(errorResponse);
|
|
336
|
-
});
|
|
337
|
-
this.jobs.clear();
|
|
338
|
-
this.reset();
|
|
339
|
-
}
|
|
340
|
-
static supportedPermissionDeniedResponseMessages(msg) {
|
|
341
|
-
const supportedMessages = [message_1.HighLevelRequest];
|
|
342
|
-
for (const supportedMessage of supportedMessages) {
|
|
343
|
-
if (msg instanceof supportedMessage) {
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
static supportsChunkedResponse(msg) {
|
|
350
|
-
return msg instanceof message_1.HighLevelRequest && !msg.header.isFlagValueSet('add_subscription');
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
exports.RequestModule = RequestModule;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubscriptionModule = exports.DEFAULT_SUBSCRIPTION_MODULE_OPTIONS = void 0;
|
|
4
|
-
const constants_1 = require("../common/constants");
|
|
5
|
-
const message_1 = require("../message");
|
|
6
|
-
const EndpointHandler_1 = require("./subscription/EndpointHandler");
|
|
7
|
-
const SubjectManager_1 = require("./subscription/SubjectManager");
|
|
8
|
-
exports.DEFAULT_SUBSCRIPTION_MODULE_OPTIONS = {
|
|
9
|
-
shouldRestartSubscriptions: false,
|
|
10
|
-
};
|
|
11
|
-
class SubscriptionModule {
|
|
12
|
-
constructor(requestModule, logger, options = exports.DEFAULT_SUBSCRIPTION_MODULE_OPTIONS) {
|
|
13
|
-
this.logger = logger;
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.subjectManager = new SubjectManager_1.SubjectManager(this.logger);
|
|
16
|
-
this.handler = {
|
|
17
|
-
endpoint: new EndpointHandler_1.EndpointHandler(requestModule, this.subjectManager, this.logger),
|
|
18
|
-
};
|
|
19
|
-
requestModule.setUpdateMessageHandler(this.updateHandler.bind(this));
|
|
20
|
-
requestModule.setLossMessageHandler(this.lossHandler.bind(this));
|
|
21
|
-
}
|
|
22
|
-
setLogger(logger) {
|
|
23
|
-
this.logger = logger;
|
|
24
|
-
this.handler.endpoint.setLogger(logger);
|
|
25
|
-
}
|
|
26
|
-
observeEndpoint(method, path, data, options, requestOptions) {
|
|
27
|
-
return this.handler.endpoint.observe(method, path, data, options, requestOptions);
|
|
28
|
-
}
|
|
29
|
-
async unobserveEndpoint(idJob) {
|
|
30
|
-
return this.handler.endpoint.unobserve(idJob);
|
|
31
|
-
}
|
|
32
|
-
restartSubscriptions() {
|
|
33
|
-
this.handler.endpoint.restartSubscriptions();
|
|
34
|
-
}
|
|
35
|
-
clearPendingSubscriptions() {
|
|
36
|
-
this.subjectManager.jobs.forEach((subject, jobId) => {
|
|
37
|
-
const lossMsg = new message_1.SubscriptionLossMessage({
|
|
38
|
-
Message: 'Foundation::SubscriptionLossMessage',
|
|
39
|
-
Version: 2,
|
|
40
|
-
header: {
|
|
41
|
-
id_job: parseInt(jobId, 10),
|
|
42
|
-
id_service: 0,
|
|
43
|
-
},
|
|
44
|
-
reason: {
|
|
45
|
-
value: 1,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
subject.error(lossMsg);
|
|
49
|
-
});
|
|
50
|
-
this.subjectManager.jobs.clear();
|
|
51
|
-
}
|
|
52
|
-
clearPendingSubscription(idJob) {
|
|
53
|
-
this.subjectManager.jobs.forEach((subject, jobId) => {
|
|
54
|
-
if (idJob === Number(jobId)) {
|
|
55
|
-
const lossMsg = new message_1.SubscriptionLossMessage({
|
|
56
|
-
Message: 'Foundation::SubscriptionLossMessage',
|
|
57
|
-
Version: 2,
|
|
58
|
-
header: {
|
|
59
|
-
id_job: parseInt(jobId, 10),
|
|
60
|
-
id_service: 0,
|
|
61
|
-
},
|
|
62
|
-
reason: {
|
|
63
|
-
value: 1,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
subject.error(lossMsg);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
this.subjectManager.jobs.delete(idJob.toString());
|
|
70
|
-
}
|
|
71
|
-
lossHandler(msg) {
|
|
72
|
-
try {
|
|
73
|
-
const subject = this.findSubject(msg);
|
|
74
|
-
const { jobId } = msg;
|
|
75
|
-
this.logger.debug(`Received Loss Message ${msg.name}`, msg);
|
|
76
|
-
subject.error(`Subscription lost: ${JSON.stringify(msg)}`);
|
|
77
|
-
if (this.options.shouldRestartSubscriptions) {
|
|
78
|
-
this.handler.endpoint.restartSubscription(jobId);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
this.logger.warn('Received Loss Message but could not find corresponding subject', msg);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
updateHandler(msg) {
|
|
86
|
-
try {
|
|
87
|
-
const subject = this.findSubject(msg);
|
|
88
|
-
this.logger.debug(`Received Update Message ${msg.name}`, msg);
|
|
89
|
-
subject.next(msg);
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
this.logger.warn('Received Update Message but could not find corresponding subject', msg);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
findSubject(msg) {
|
|
96
|
-
if ((0, message_1.isHighLevelUpdate)(msg) || (0, message_1.isSubscriptionLossMessage)(msg)) {
|
|
97
|
-
const subject = this.subjectManager.findJobSubject(msg.jobId);
|
|
98
|
-
if (subject) {
|
|
99
|
-
return subject;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
throw new Error(`Received unknown message: ${msg.name}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.SubscriptionModule = SubscriptionModule;
|
|
106
|
-
SubscriptionModule.defaultObserveOptions = {
|
|
107
|
-
quality: constants_1.DEFAULT_QUALITY,
|
|
108
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EndpointHandler = void 0;
|
|
4
|
-
const fast_json_patch_1 = require("fast-json-patch");
|
|
5
|
-
const rxjs_1 = require("rxjs");
|
|
6
|
-
const operators_1 = require("rxjs/operators");
|
|
7
|
-
const message_1 = require("../../message");
|
|
8
|
-
const SubscriptionModule_1 = require("../SubscriptionModule");
|
|
9
|
-
const constants_1 = require("../../common/constants");
|
|
10
|
-
class EndpointHandler {
|
|
11
|
-
constructor(requestModule, subjectManager, logger) {
|
|
12
|
-
this.resultMapper = (0, operators_1.map)((response) => {
|
|
13
|
-
if ((0, message_1.isHighLevelUpdate)(response)) {
|
|
14
|
-
const patchedResponse = this.applyEndpointJsonPatchUpdate(response.jobId, response.data);
|
|
15
|
-
return { response: patchedResponse, data: patchedResponse.data };
|
|
16
|
-
}
|
|
17
|
-
return { response, data: response.data };
|
|
18
|
-
});
|
|
19
|
-
this.requestToJobMapper = new Map();
|
|
20
|
-
this.requestModule = requestModule;
|
|
21
|
-
this.subjectManager = subjectManager;
|
|
22
|
-
this.responses = {};
|
|
23
|
-
this.logger = logger;
|
|
24
|
-
}
|
|
25
|
-
setLogger(logger) {
|
|
26
|
-
this.logger = logger;
|
|
27
|
-
}
|
|
28
|
-
observe(method, path, data, options, requestOptions) {
|
|
29
|
-
this.validateOptions(options);
|
|
30
|
-
const subject = new rxjs_1.Subject();
|
|
31
|
-
const mainSubject = new rxjs_1.ReplaySubject(1);
|
|
32
|
-
const mainObservable = mainSubject.pipe((0, operators_1.switchAll)());
|
|
33
|
-
const observable = subject.asObservable().pipe(EndpointHandler.highLevelResponseFilter, this.resultMapper.bind(this));
|
|
34
|
-
this.requestModule
|
|
35
|
-
.requestEndpoint(method, path, data, { ...requestOptions, subscribe: true })
|
|
36
|
-
.then((result) => {
|
|
37
|
-
this.subjectManager.registerJobSubject(result.response.jobId, subject);
|
|
38
|
-
this.registerEndpointRequest(result.response.jobId, mainSubject, mainObservable, method, path, data, options);
|
|
39
|
-
this.registerEndpointResponse(result.response.jobId, result.response);
|
|
40
|
-
observable.idJob = result.response.jobId;
|
|
41
|
-
mainSubject.next(observable.pipe((0, operators_1.shareReplay)(1)));
|
|
42
|
-
mainObservable.idJob = result.response.jobId;
|
|
43
|
-
subject.next(result.response);
|
|
44
|
-
})
|
|
45
|
-
.catch((err) => {
|
|
46
|
-
this.logger.warn('Subscription request failed.', err);
|
|
47
|
-
mainSubject.error(err);
|
|
48
|
-
});
|
|
49
|
-
return mainObservable;
|
|
50
|
-
}
|
|
51
|
-
async unobserve(idJob) {
|
|
52
|
-
if (!this.subjectManager.hasJobSubject(idJob)) {
|
|
53
|
-
this.logger.warn(`Could not find subscription for idJob "${idJob}".`);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
await this.requestModule.request(new message_1.CancelSubscriptionRequest(idJob));
|
|
57
|
-
this.requestToJobMapper.delete(idJob.toString());
|
|
58
|
-
this.subjectManager.removeJobSubject(idJob);
|
|
59
|
-
}
|
|
60
|
-
findSubject(idJob) {
|
|
61
|
-
return this.subjectManager.getJobSubject(idJob);
|
|
62
|
-
}
|
|
63
|
-
registerEndpointResponse(idJob, response) {
|
|
64
|
-
this.responses[idJob] = response;
|
|
65
|
-
}
|
|
66
|
-
registerEndpointRequest(idJob, subject, observable, method, path, data, options, requestOptions) {
|
|
67
|
-
this.requestToJobMapper.set(idJob.toString(), { path, subject, observable, data, method, options, requestOptions });
|
|
68
|
-
}
|
|
69
|
-
applyEndpointJsonPatchUpdate(idJob, patch) {
|
|
70
|
-
const response = this.responses[idJob];
|
|
71
|
-
const result = (0, fast_json_patch_1.applyPatch)(response, patch).newDocument;
|
|
72
|
-
this.responses[idJob] = result;
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
restartSubscriptions() {
|
|
76
|
-
const oldSubscriptions = Array.from(this.subjectManager.jobs.keys());
|
|
77
|
-
const oldRequests = new Map(this.requestToJobMapper);
|
|
78
|
-
this.requestToJobMapper.clear();
|
|
79
|
-
this.subjectManager.jobs.clear();
|
|
80
|
-
oldSubscriptions.forEach((idJob) => {
|
|
81
|
-
const request = oldRequests.get(idJob);
|
|
82
|
-
if (request) {
|
|
83
|
-
this.resubscribe(request);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
restartSubscription(jobId) {
|
|
88
|
-
const oldRequests = new Map(this.requestToJobMapper);
|
|
89
|
-
this.requestToJobMapper.clear();
|
|
90
|
-
if (jobId) {
|
|
91
|
-
const request = oldRequests.get(jobId.toString());
|
|
92
|
-
if (request) {
|
|
93
|
-
setTimeout(() => {
|
|
94
|
-
this.resubscribe(request);
|
|
95
|
-
}, constants_1.DEFAULT_RESUBSCRIBE_WAIT_TIME_IN_MS);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
resubscribe(request) {
|
|
100
|
-
this.validateOptions(request.options);
|
|
101
|
-
const subject = new rxjs_1.Subject();
|
|
102
|
-
const observable = subject.asObservable().pipe(EndpointHandler.highLevelResponseFilter, this.resultMapper.bind(this));
|
|
103
|
-
this.requestModule
|
|
104
|
-
.requestEndpoint(request.method, request.path, request.data, { ...request.requestOptions, subscribe: true })
|
|
105
|
-
.then((result) => {
|
|
106
|
-
this.subjectManager.registerJobSubject(result.response.jobId, subject);
|
|
107
|
-
this.registerEndpointResponse(result.response.jobId, result.response);
|
|
108
|
-
request.observable.idJob = result.response.jobId;
|
|
109
|
-
request.subject.next(observable.pipe((0, operators_1.shareReplay)(1)));
|
|
110
|
-
subject.next(result.response);
|
|
111
|
-
this.registerEndpointRequest(result.response.jobId, request.subject, request.observable, request.method, request.path, request.data, request.options, request.requestOptions);
|
|
112
|
-
})
|
|
113
|
-
.catch((err) => {
|
|
114
|
-
this.logger.warn('Request failed during initial request for restarting endpoint subscription', err);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
validateOptions(options) {
|
|
118
|
-
const opts = { ...SubscriptionModule_1.SubscriptionModule.defaultObserveOptions, ...options };
|
|
119
|
-
if (opts.minInterval) {
|
|
120
|
-
this.logger.warn('Option `minInterval` is deprecated. Use _subscriptionMinimumInterval (GET) or meta.subscription.minimumInterval (POST) for server side throttling.');
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.EndpointHandler = EndpointHandler;
|
|
125
|
-
EndpointHandler.highLevelResponseFilter = (0, operators_1.filter)((response) => (0, message_1.isHighLevelResponse)(response) || (0, message_1.isHighLevelUpdate)(response));
|