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