@factset/frontgate-js-sdk 7.1.4 → 7.1.5
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 +45 -24
- package/dist/lib/esnext/common/errors.js +4 -5
- package/dist/lib/esnext/index.js +1 -0
- package/dist/lib/esnext/message/interfaces/PtlMessage.js +4 -0
- package/dist/lib/esnext/message/interfaces/index.js +1 -0
- package/dist/lib/esnext/message/request/AuthenticationByTokenRequest.js +2 -2
- package/dist/lib/esnext/message/request/AuthenticationRequest.js +2 -0
- package/dist/lib/esnext/message/request/ConfigurationRequest.js +3 -3
- package/dist/lib/esnext/message/response/AuthenticationTokenResponse.js +3 -11
- package/dist/lib/esnext/message/response/HTTPProxyResponse.js +0 -4
- package/dist/lib/esnext/message/response/Mdg2Response.js +4 -1
- package/dist/lib/esnext/message/response/PingResponse.js +0 -6
- package/dist/lib/esnext/message/response/index.js +0 -3
- package/dist/lib/esnext/mixins/AuthTokenRequestMixin.js +1 -1
- package/dist/lib/esnext/mixins/EndpointRequestMixin.js +7 -7
- package/dist/lib/esnext/mixins/HTTPProxyRequestMixin.js +1 -1
- package/dist/lib/esnext/mixins/OpenTelemetryMixin.js +2 -1
- package/dist/lib/esnext/mixins/PingMixin.js +5 -1
- package/dist/lib/esnext/mixins/RequestMixin.js +6 -1
- package/dist/lib/esnext/mixins/auth/AppAuthMixin.js +3 -3
- package/dist/lib/esnext/mixins/auth/SessionAuthMixin.js +4 -4
- package/dist/lib/esnext/mixins/auth/UserCredentialAuthMixin.js +3 -3
- package/dist/lib/esnext/mixins/auth/UserPasswordAuthMixin.js +3 -3
- package/dist/lib/esnext/mixins/connection/FrontgateWSMixin.js +11 -9
- package/dist/lib/esnext/mixins/subscription/DataObserver.js +1 -2
- package/dist/lib/esnext/mixins/subscription/EndpointSubscriptionMixin.js +13 -12
- package/dist/lib/esnext/mixins/subscription/RawSubscriptionMixin.js +28 -15
- package/dist/lib/esnext/version.js +1 -1
- package/dist/lib/node/common/errors.js +6 -7
- package/dist/lib/node/index.js +1 -0
- package/dist/lib/node/message/interfaces/PtlMessage.js +11 -0
- package/dist/lib/node/message/interfaces/index.js +1 -0
- package/dist/lib/node/message/request/AuthenticationByTokenRequest.js +2 -2
- package/dist/lib/node/message/request/AuthenticationRequest.js +2 -0
- package/dist/lib/node/message/request/ConfigurationRequest.js +3 -3
- package/dist/lib/node/message/response/AuthenticationTokenResponse.js +3 -11
- package/dist/lib/node/message/response/HTTPProxyResponse.js +0 -4
- package/dist/lib/node/message/response/Mdg2Response.js +4 -1
- package/dist/lib/node/message/response/PingResponse.js +0 -6
- package/dist/lib/node/message/response/index.js +0 -3
- package/dist/lib/node/mixins/AuthTokenRequestMixin.js +1 -1
- package/dist/lib/node/mixins/EndpointRequestMixin.js +7 -7
- package/dist/lib/node/mixins/HTTPProxyRequestMixin.js +1 -1
- package/dist/lib/node/mixins/OpenTelemetryMixin.js +2 -1
- package/dist/lib/node/mixins/PingMixin.js +5 -1
- package/dist/lib/node/mixins/RequestMixin.js +6 -1
- package/dist/lib/node/mixins/auth/AppAuthMixin.js +3 -3
- package/dist/lib/node/mixins/auth/SessionAuthMixin.js +4 -4
- package/dist/lib/node/mixins/auth/UserCredentialAuthMixin.js +3 -3
- package/dist/lib/node/mixins/auth/UserPasswordAuthMixin.js +3 -3
- package/dist/lib/node/mixins/connection/FrontgateWSMixin.js +11 -9
- package/dist/lib/node/mixins/subscription/DataObserver.js +1 -2
- package/dist/lib/node/mixins/subscription/EndpointSubscriptionMixin.js +12 -11
- package/dist/lib/node/mixins/subscription/RawSubscriptionMixin.js +27 -14
- package/dist/lib/node/version.js +1 -1
- package/dist/lib/types/common/errors.d.ts +4 -8
- package/dist/lib/types/common/interfaces/index.d.ts +0 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/message/interfaces/PtlMessage.d.ts +486 -0
- package/dist/lib/types/message/interfaces/index.d.ts +1 -0
- package/dist/lib/types/message/request/AbstractMdg2Request.d.ts +3 -3
- package/dist/lib/types/message/request/AuthenticationByTokenRequest.d.ts +5 -2
- package/dist/lib/types/message/request/AuthenticationRequest.d.ts +10 -9
- package/dist/lib/types/message/request/AuthenticationTokenRequest.d.ts +2 -1
- package/dist/lib/types/message/request/CancelSubscriptionRequest.d.ts +2 -1
- package/dist/lib/types/message/request/ConfigurationRequest.d.ts +7 -2
- package/dist/lib/types/message/request/HTTPProxyRequest.d.ts +2 -2
- package/dist/lib/types/message/request/HighLevelRequest.d.ts +2 -2
- package/dist/lib/types/message/request/PingRequest.d.ts +2 -8
- package/dist/lib/types/message/request/TransportLayerClientRequestHeader.d.ts +3 -26
- package/dist/lib/types/message/response/AuthenticationTokenResponse.d.ts +3 -3
- package/dist/lib/types/message/response/HTTPProxyResponse.d.ts +8 -24
- package/dist/lib/types/message/response/HighLevelResponse.d.ts +3 -1
- package/dist/lib/types/message/response/Mdg2Response.d.ts +6 -4
- package/dist/lib/types/message/response/PingResponse.d.ts +2 -1
- package/dist/lib/types/message/response/index.d.ts +0 -3
- package/dist/lib/types/message/update/HighLevelUpdate.d.ts +3 -1
- package/dist/lib/types/mixins/connection/index.d.ts +9 -3
- package/dist/lib/types/mixins/subscription/DataObserver.d.ts +2 -3
- package/dist/lib/umd/mdg2.client.min.umd.js +1 -1
- package/dist/lib/umd/mdg2.client.umd.js +169 -154
- package/package.json +2 -2
- package/dist/lib/esnext/common/interfaces/PtlMessage.js +0 -1
- package/dist/lib/esnext/message/response/AuthenticationResponse.js +0 -1
- package/dist/lib/esnext/message/response/ConfigurationResponse.js +0 -1
- package/dist/lib/esnext/message/response/DisconnectionMessage.js +0 -1
- package/dist/lib/esnext/message/response/ErrorResponse.js +0 -9
- package/dist/lib/node/common/interfaces/PtlMessage.js +0 -2
- package/dist/lib/node/message/response/AuthenticationResponse.js +0 -2
- package/dist/lib/node/message/response/ConfigurationResponse.js +0 -2
- package/dist/lib/node/message/response/DisconnectionMessage.js +0 -2
- package/dist/lib/node/message/response/ErrorResponse.js +0 -13
- package/dist/lib/types/common/interfaces/PtlMessage.d.ts +0 -5
- package/dist/lib/types/message/response/AuthenticationResponse.d.ts +0 -37
- package/dist/lib/types/message/response/ConfigurationResponse.d.ts +0 -44
- package/dist/lib/types/message/response/DisconnectionMessage.d.ts +0 -7
- package/dist/lib/types/message/response/ErrorResponse.d.ts +0 -5
|
@@ -4,8 +4,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
import { createExtendedMixinFactory, FrontgateClientEndpointDataObserver } from '../';
|
|
7
|
+
import { UnexpectedResponseError } from '../../common/errors';
|
|
7
8
|
import { LogLevel } from '../../logger';
|
|
8
|
-
import { HighLevelRequest,
|
|
9
|
+
import { HighLevelRequest, HighLevelUpdate, CancelSubscriptionRequest } from '../../message';
|
|
9
10
|
import { useTimeout, addRandomnessToTime } from '../../util/functions';
|
|
10
11
|
export const endpointSubscriptions = (originalConfig) => {
|
|
11
12
|
const mixinEndpointSubscribable = (Base) => {
|
|
@@ -52,9 +53,9 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
52
53
|
.callHook('frontgateConnection:sendMessage', subscriptionMsg)
|
|
53
54
|
.then(() => {
|
|
54
55
|
this.hooks.hookOnce(`frontgateConnection:response:${subscriptionMsg.callbackId}`, (response) => {
|
|
55
|
-
if (
|
|
56
|
+
if (response.Message !== 'Foundation::HighLevelResponse' && response.Message !== 'HighLevelResponse') {
|
|
56
57
|
this.log(LogLevel.ERROR, `Unexpected response: ${response.Message}`);
|
|
57
|
-
reject(new
|
|
58
|
+
reject(new UnexpectedResponseError(response));
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
61
|
let hlResponseData;
|
|
@@ -79,7 +80,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
let removeMessageUpdateHook = this.hooks.hook(`frontgateConnection:response:${subscriptionMsg.callbackId}`, (update) => {
|
|
82
|
-
if (
|
|
83
|
+
if (update.Message !== 'Foundation::HighLevelUpdate' && update.Message !== 'HighLevelUpdate') {
|
|
83
84
|
if (update.Message.includes('SubscriptionLoss')) {
|
|
84
85
|
this.log(LogLevel.DEBUG, `Received: ${update.Message}`);
|
|
85
86
|
setTimeout(() => {
|
|
@@ -89,7 +90,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
92
|
this.log(LogLevel.ERROR, `Unexpected response: ${response.Message}`);
|
|
92
|
-
observer.pushError(new
|
|
93
|
+
observer.pushError(new UnexpectedResponseError(update));
|
|
93
94
|
removeMessageUpdateHook();
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
@@ -99,7 +100,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
99
100
|
}
|
|
100
101
|
catch (e) {
|
|
101
102
|
this.log(LogLevel.ERROR, `Failed to parse response: ${update.body.value}`);
|
|
102
|
-
observer.pushError(e);
|
|
103
|
+
observer.pushError(new Error('Failed to parse response', { cause: e }));
|
|
103
104
|
return;
|
|
104
105
|
}
|
|
105
106
|
observer.pushPatchData(hlUpdate.data);
|
|
@@ -111,8 +112,8 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
111
112
|
let removeResubscribeHookOnce;
|
|
112
113
|
const resubscribePromise = new Promise((res, rej) => {
|
|
113
114
|
removeResubscribeHookOnce = this.hooks.hookOnce(`frontgateConnection:response:${subscriptionMsg.callbackId}`, (resp) => {
|
|
114
|
-
if (
|
|
115
|
-
const err = new
|
|
115
|
+
if (resp.Message !== 'Foundation::HighLevelResponse' && resp.Message !== 'HighLevelResponse') {
|
|
116
|
+
const err = new UnexpectedResponseError(resp);
|
|
116
117
|
this.log(LogLevel.ERROR, `Unexpected response: ${resp.Message}`);
|
|
117
118
|
removeMessageUpdateHook();
|
|
118
119
|
rej(err);
|
|
@@ -136,7 +137,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
136
137
|
return;
|
|
137
138
|
}
|
|
138
139
|
removeMessageUpdateHook = this.hooks.hook(`frontgateConnection:response:${resp.header.id_job}`, (update) => {
|
|
139
|
-
if (
|
|
140
|
+
if (update.Message !== 'Foundation::HighLevelUpdate' && update.Message !== 'HighLevelUpdate') {
|
|
140
141
|
if (update.Message.includes('SubscriptionLoss')) {
|
|
141
142
|
this.log(LogLevel.DEBUG, `Received: ${update.Message}`);
|
|
142
143
|
setTimeout(() => {
|
|
@@ -145,7 +146,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
148
|
this.log(LogLevel.ERROR, `Unexpected response: ${update.Message}`);
|
|
148
|
-
const err = new
|
|
149
|
+
const err = new UnexpectedResponseError(update);
|
|
149
150
|
observer.pushError(err);
|
|
150
151
|
return;
|
|
151
152
|
}
|
|
@@ -155,7 +156,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
155
156
|
}
|
|
156
157
|
catch (e) {
|
|
157
158
|
this.log(LogLevel.ERROR, `Failed to parse response: ${update.body.value}`);
|
|
158
|
-
observer.pushError(e);
|
|
159
|
+
observer.pushError(new Error('Failed to parse response', { cause: e }));
|
|
159
160
|
return;
|
|
160
161
|
}
|
|
161
162
|
observer.pushPatchData(hlUpdate.data);
|
|
@@ -169,7 +170,7 @@ export const endpointSubscriptions = (originalConfig) => {
|
|
|
169
170
|
catch (e) {
|
|
170
171
|
removeResubscribeHookOnce?.();
|
|
171
172
|
subscriptionZombie = true;
|
|
172
|
-
observer.pushError(new
|
|
173
|
+
observer.pushError(new Error('Resubscribe failed', { cause: e }));
|
|
173
174
|
}
|
|
174
175
|
};
|
|
175
176
|
const removeReconnectHook = this.hooks.hook('reconnect:success', resubscribe);
|
|
@@ -4,9 +4,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
import { createExtendedMixinFactory, FrontgateClientDataObserver } from '../';
|
|
7
|
+
import { hasJobIdInHeader, isServiceAndNotationBased } from '../../message/interfaces';
|
|
7
8
|
import { LogLevel } from '../../logger';
|
|
8
|
-
import {
|
|
9
|
+
import { CancelSubscriptionRequest } from '../../message';
|
|
9
10
|
import { useTimeout } from '../../util/functions';
|
|
11
|
+
import { UnexpectedResponseError } from '../../common/errors';
|
|
10
12
|
export const rawSubscriptions = () => {
|
|
11
13
|
const mixinRawSubscribable = (Base) => {
|
|
12
14
|
var _instances, _subscriptions, _rawSubscriptionHelper, _a;
|
|
@@ -45,20 +47,27 @@ export const rawSubscriptions = () => {
|
|
|
45
47
|
await this.hooks.callHook('frontgateConnection:sendMessage', subscriptionMsg);
|
|
46
48
|
const promise = new Promise((resolve, reject) => {
|
|
47
49
|
this.hooks.hookOnce(`frontgateConnection:response:${subscriptionMsg.callbackId}`, (response) => {
|
|
48
|
-
if (response.Message.includes('Error') || response.Message.includes('PermissionDenied')) {
|
|
50
|
+
if (response.Message.includes('Error') || response.Message.includes('PermissionDenied') || !hasJobIdInHeader(response)) {
|
|
49
51
|
this.log(LogLevel.ERROR, `Unexpected response: ${response.Message}`);
|
|
50
|
-
reject(new
|
|
52
|
+
reject(new UnexpectedResponseError(response));
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
let subscriptionKey = response.header.id_job.toString();
|
|
56
|
+
let idService = -1;
|
|
57
|
+
let idNotation = -1;
|
|
58
|
+
if (subscriptionType === 'connection' && isServiceAndNotationBased(response)) {
|
|
59
|
+
idService = response.header.id_service;
|
|
60
|
+
idNotation = response.id_notation;
|
|
61
|
+
subscriptionKey = `${idService}-${idNotation}`;
|
|
62
|
+
}
|
|
54
63
|
const cancelationRequest = typeof CancelationRequestConstructor === 'undefined'
|
|
55
64
|
? new CancelSubscriptionRequest(response.header.id_job)
|
|
56
|
-
: new CancelationRequestConstructor(
|
|
65
|
+
: new CancelationRequestConstructor(idService, idNotation);
|
|
57
66
|
const observer = new FrontgateClientDataObserver(response.header.id_job, response);
|
|
58
67
|
let removeMessageUpdateHook = this.hooks.hook(`frontgateConnection:response:${subscriptionKey}`, (update) => {
|
|
59
|
-
if (update.Message
|
|
68
|
+
if (update.Message === 'Foundation::ErrorResponse') {
|
|
60
69
|
this.log(LogLevel.ERROR, `Unexpected response: ${response.Message}`);
|
|
61
|
-
observer.pushError(new
|
|
70
|
+
observer.pushError(new UnexpectedResponseError(update));
|
|
62
71
|
return;
|
|
63
72
|
}
|
|
64
73
|
observer.pushData(update);
|
|
@@ -69,22 +78,26 @@ export const rawSubscriptions = () => {
|
|
|
69
78
|
await this.hooks.callHook('frontgateConnection:sendMessage', subscriptionMsg);
|
|
70
79
|
const resubscribePromise = new Promise((res, rej) => {
|
|
71
80
|
this.hooks.hookOnce(`frontgateConnection:response:${subscriptionMsg.callbackId}`, (resubscribeResponse) => {
|
|
72
|
-
if (resubscribeResponse.Message
|
|
73
|
-
const err = new
|
|
81
|
+
if (resubscribeResponse.Message === 'Foundation::ErrorResponse' || !hasJobIdInHeader(resubscribeResponse)) {
|
|
82
|
+
const err = new UnexpectedResponseError(resubscribeResponse);
|
|
74
83
|
this.log(LogLevel.ERROR, `Unexpected resp: ${resubscribeResponse.Message}`);
|
|
75
84
|
rej(err);
|
|
76
85
|
return;
|
|
77
86
|
}
|
|
78
|
-
|
|
87
|
+
let resubscriptionKey = response.header.id_job.toString();
|
|
88
|
+
if (subscriptionType === 'connection' && isServiceAndNotationBased(resubscribeResponse)) {
|
|
89
|
+
idService = resubscribeResponse.header.id_service;
|
|
90
|
+
idNotation = resubscribeResponse.id_notation;
|
|
91
|
+
resubscriptionKey = `${idService}-${idNotation}`;
|
|
92
|
+
}
|
|
79
93
|
const resubscriptionCancelationRequest = typeof CancelationRequestConstructor === 'undefined'
|
|
80
94
|
? new CancelSubscriptionRequest(resubscribeResponse.header.id_job)
|
|
81
|
-
: new CancelationRequestConstructor(
|
|
95
|
+
: new CancelationRequestConstructor(idService, idNotation);
|
|
82
96
|
observer.idJob = resubscribeResponse.header.id_job;
|
|
83
97
|
removeMessageUpdateHook = this.hooks.hook(`frontgateConnection:response:${resubscriptionKey}`, (update) => {
|
|
84
|
-
if (update.Message
|
|
98
|
+
if (update.Message === 'Foundation::ErrorResponse') {
|
|
85
99
|
this.log(LogLevel.ERROR, `Unexpected response: ${update.Message}`);
|
|
86
|
-
|
|
87
|
-
observer.pushError(err);
|
|
100
|
+
observer.pushError(new UnexpectedResponseError(update));
|
|
88
101
|
return;
|
|
89
102
|
}
|
|
90
103
|
observer.unsubscribe = () => {
|
|
@@ -116,7 +129,7 @@ export const rawSubscriptions = () => {
|
|
|
116
129
|
await useTimeout(timeOutInMs, 'Request timeout reached', resubscribePromise);
|
|
117
130
|
}
|
|
118
131
|
catch (e) {
|
|
119
|
-
observer.pushError(new
|
|
132
|
+
observer.pushError(new Error('Reconnect Failed', { cause: e }));
|
|
120
133
|
}
|
|
121
134
|
});
|
|
122
135
|
observer.unsubscribe = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PACKAGE_JSON = { version: '7.1.
|
|
1
|
+
export const PACKAGE_JSON = { version: '7.1.5', package: '@factset/frontgate-js-sdk' };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
7
|
-
this.
|
|
8
|
-
this.code = 408;
|
|
3
|
+
exports.UnexpectedResponseError = void 0;
|
|
4
|
+
class UnexpectedResponseError extends Error {
|
|
5
|
+
constructor(response) {
|
|
6
|
+
super(`Unexpected response: ${response.Message}`);
|
|
7
|
+
this.response = response;
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
|
-
exports.
|
|
10
|
+
exports.UnexpectedResponseError = UnexpectedResponseError;
|
package/dist/lib/node/index.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.useTimeout = exports.FrontgateClient = exports.FrontgateClientBuilder =
|
|
|
18
18
|
__exportStar(require("./authentication"), exports);
|
|
19
19
|
__exportStar(require("./connection"), exports);
|
|
20
20
|
__exportStar(require("./message"), exports);
|
|
21
|
+
__exportStar(require("./message/interfaces"), exports);
|
|
21
22
|
__exportStar(require("./common/interfaces"), exports);
|
|
22
23
|
__exportStar(require("./common/types"), exports);
|
|
23
24
|
__exportStar(require("./logger"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPtlMessageWithHeader = exports.isServiceAndNotationBased = exports.hasJobIdInHeader = exports.hasJobIdInRoot = void 0;
|
|
4
|
+
const hasJobIdInRoot = (msg) => typeof msg.id_job !== 'undefined';
|
|
5
|
+
exports.hasJobIdInRoot = hasJobIdInRoot;
|
|
6
|
+
const hasJobIdInHeader = (msg) => typeof msg.header?.id_job !== 'undefined';
|
|
7
|
+
exports.hasJobIdInHeader = hasJobIdInHeader;
|
|
8
|
+
const isServiceAndNotationBased = (msg) => typeof msg.header?.id_service !== 'undefined' && typeof msg.id_notation !== 'undefined';
|
|
9
|
+
exports.isServiceAndNotationBased = isServiceAndNotationBased;
|
|
10
|
+
const isPtlMessageWithHeader = (msg) => msg.header !== undefined;
|
|
11
|
+
exports.isPtlMessageWithHeader = isPtlMessageWithHeader;
|
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./HighLevelRequestMethod"), exports);
|
|
18
18
|
__exportStar(require("./HighLevelRequestOptions"), exports);
|
|
19
19
|
__exportStar(require("./HTTPProxyRequestOptions"), exports);
|
|
20
|
+
__exportStar(require("./PtlMessage"), exports);
|
|
@@ -24,10 +24,10 @@ class AuthenticationByTokenRequest {
|
|
|
24
24
|
maximum_receivable_message_size: 1048576,
|
|
25
25
|
flags: 0,
|
|
26
26
|
cache_authentication_salt: {
|
|
27
|
-
value:
|
|
27
|
+
value: { b64: '' },
|
|
28
28
|
},
|
|
29
29
|
cache_authentication_encrypted_secret: {
|
|
30
|
-
encrypted_secret:
|
|
30
|
+
encrypted_secret: { b64: '' },
|
|
31
31
|
},
|
|
32
32
|
};
|
|
33
33
|
}
|
|
@@ -70,10 +70,10 @@ class ConfigurationRequest {
|
|
|
70
70
|
if (typeof challenge === 'string') {
|
|
71
71
|
return Buffer.from(challenge, 'utf-8');
|
|
72
72
|
}
|
|
73
|
-
if (
|
|
74
|
-
return Buffer.from(challenge
|
|
73
|
+
if (Array.isArray(challenge)) {
|
|
74
|
+
return Buffer.from(challenge);
|
|
75
75
|
}
|
|
76
|
-
return Buffer.from(challenge);
|
|
76
|
+
return Buffer.from(challenge.b64, 'base64');
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
exports.ConfigurationRequest = ConfigurationRequest;
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthenticationTokenResponse = void 0;
|
|
4
|
-
const Mdg2Response_1 = require("./Mdg2Response");
|
|
5
4
|
const types_1 = require("../types");
|
|
6
|
-
class AuthenticationTokenResponse
|
|
5
|
+
class AuthenticationTokenResponse {
|
|
7
6
|
constructor(raw) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
throw new Error('Token not set in AuthenticationTokenResponse');
|
|
11
|
-
}
|
|
12
|
-
if (!this.raw.expiry.microseconds) {
|
|
13
|
-
throw new Error('Expiry not set in AuthenticationTokenResponse');
|
|
14
|
-
}
|
|
15
|
-
this.token = this.raw.token.value.b64;
|
|
16
|
-
this.expiry = parseInt((0, types_1.timeToMilliseconds)(this.raw.expiry.microseconds), 10);
|
|
7
|
+
this.token = raw.token.value.b64;
|
|
8
|
+
this.expiry = parseInt((0, types_1.timeToMilliseconds)(raw.expiry.microseconds), 10);
|
|
17
9
|
}
|
|
18
10
|
getToken() {
|
|
19
11
|
return this.token;
|
|
@@ -13,16 +13,12 @@ class HTTPProxyResponse extends Mdg2Response_1.Mdg2Response {
|
|
|
13
13
|
catch (error) {
|
|
14
14
|
throw new Error(`Could not parse HTTPProxyResponse: ${error}`);
|
|
15
15
|
}
|
|
16
|
-
this.responseInfo = this.raw.info;
|
|
17
16
|
this.statusReason = this.raw.response.status_reason;
|
|
18
17
|
this.statusCode = this.raw.response.status_code.value;
|
|
19
18
|
}
|
|
20
19
|
get data() {
|
|
21
20
|
return this.responseData;
|
|
22
21
|
}
|
|
23
|
-
get meta() {
|
|
24
|
-
return this.responseData.meta;
|
|
25
|
-
}
|
|
26
22
|
get status() {
|
|
27
23
|
return {
|
|
28
24
|
code: this.statusCode,
|
|
@@ -15,7 +15,10 @@ class Mdg2Response {
|
|
|
15
15
|
return this.raw.header.id_job;
|
|
16
16
|
}
|
|
17
17
|
get serviceId() {
|
|
18
|
-
|
|
18
|
+
if (this.raw.Message === 'Foundation::HTTPProxyResponse' || this.raw.Message === 'Foundation::HighLevelResponse') {
|
|
19
|
+
return this.raw.header.id_service;
|
|
20
|
+
}
|
|
21
|
+
throw new Error('Invalid message type');
|
|
19
22
|
}
|
|
20
23
|
isUpdateMessage() {
|
|
21
24
|
if (!Object.hasOwnProperty.call(this.raw, 'header')) {
|
|
@@ -4,12 +4,6 @@ exports.PingResponse = void 0;
|
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
class PingResponse {
|
|
6
6
|
constructor(raw) {
|
|
7
|
-
if (raw.Message !== PingResponse.NAME) {
|
|
8
|
-
throw new Error(`Unsupported message=${raw.Message}`);
|
|
9
|
-
}
|
|
10
|
-
if (raw.Version !== PingResponse.VERSION) {
|
|
11
|
-
throw new Error(`Unsupported version=${raw.Version} for message=${raw.Message}`);
|
|
12
|
-
}
|
|
13
7
|
this._timeReceivedResponse = Date.now();
|
|
14
8
|
this._timeAtSender = Number((0, types_1.timeToMilliseconds)(raw.time_at_sender.microseconds));
|
|
15
9
|
this._timeFromRequest = Number((0, types_1.timeToMilliseconds)(raw.time_from_request.microseconds));
|
|
@@ -15,9 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./AuthenticationTokenResponse"), exports);
|
|
18
|
-
__exportStar(require("./ConfigurationResponse"), exports);
|
|
19
|
-
__exportStar(require("./DisconnectionMessage"), exports);
|
|
20
|
-
__exportStar(require("./ErrorResponse"), exports);
|
|
21
18
|
__exportStar(require("./HighLevelResponse"), exports);
|
|
22
19
|
__exportStar(require("./HTTPProxyResponse"), exports);
|
|
23
20
|
__exportStar(require("./Mdg2Response"), exports);
|
|
@@ -18,7 +18,7 @@ const authTokenRequest = () => {
|
|
|
18
18
|
await this.hooks.callHook('frontgateConnection:sendMessage', msg);
|
|
19
19
|
const promise = new Promise((resolve, reject) => {
|
|
20
20
|
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
21
|
-
if (
|
|
21
|
+
if (response.Message !== 'Foundation::AuthenticationTokenResponse') {
|
|
22
22
|
reject(JSON.stringify(response));
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -38,19 +38,19 @@ const endpointRequest = (config) => {
|
|
|
38
38
|
const hookResponse = () => {
|
|
39
39
|
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
40
40
|
try {
|
|
41
|
-
if (
|
|
41
|
+
if (response.Message !== 'Foundation::HighLevelResponse' && response.Message !== 'HighLevelResponse') {
|
|
42
42
|
reject(JSON.stringify(response));
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
if (!__classPrivateFieldGet(this, _instances, "m", _hasNextChunk).call(this, response)) {
|
|
46
46
|
chunkedData.push({
|
|
47
|
-
body: response.body
|
|
48
|
-
processingTime: response.header
|
|
47
|
+
body: response.body.value,
|
|
48
|
+
processingTime: response.header.processing_time,
|
|
49
49
|
});
|
|
50
50
|
const hlResponse = new message_1.HighLevelResponse({
|
|
51
51
|
...response,
|
|
52
52
|
body: { value: chunkedData.map((chunk) => chunk.body).join('') },
|
|
53
|
-
header: { ...response.header,
|
|
53
|
+
header: { ...response.header, processing_time: chunkedData.reduce((acc, chunk) => acc + chunk.processingTime, 0) },
|
|
54
54
|
});
|
|
55
55
|
resolve({
|
|
56
56
|
response: hlResponse,
|
|
@@ -59,8 +59,8 @@ const endpointRequest = (config) => {
|
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
61
|
chunkedData.push({
|
|
62
|
-
body: response.body
|
|
63
|
-
processingTime: response.header
|
|
62
|
+
body: response.body.value,
|
|
63
|
+
processingTime: response.header.processing_time,
|
|
64
64
|
});
|
|
65
65
|
hookResponse();
|
|
66
66
|
}
|
|
@@ -78,7 +78,7 @@ const endpointRequest = (config) => {
|
|
|
78
78
|
},
|
|
79
79
|
_instances = new WeakSet(),
|
|
80
80
|
_hasNextChunk = function _hasNextChunk(msg) {
|
|
81
|
-
return (
|
|
81
|
+
return (msg.header.flags & message_2.FLAG_HAS_NEXT_CHUNK) === message_2.FLAG_HAS_NEXT_CHUNK;
|
|
82
82
|
},
|
|
83
83
|
_a;
|
|
84
84
|
};
|
|
@@ -22,7 +22,7 @@ const httpProxyRequest = () => {
|
|
|
22
22
|
const promise = new Promise((resolve, reject) => {
|
|
23
23
|
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
24
24
|
try {
|
|
25
|
-
if (
|
|
25
|
+
if (response.Message !== 'Foundation::HTTPProxyResponse') {
|
|
26
26
|
reject(JSON.stringify(response));
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.encodeSpanContext = exports.openTelemetry = void 0;
|
|
9
9
|
const api_1 = require("@opentelemetry/api");
|
|
10
10
|
const _1 = require(".");
|
|
11
|
+
const interfaces_1 = require("../message/interfaces");
|
|
11
12
|
const openTelemetry = () => {
|
|
12
13
|
const mixinOpenTelemetry = (Base) => {
|
|
13
14
|
var _instances, _createSpanHeader, _a;
|
|
@@ -16,7 +17,7 @@ const openTelemetry = () => {
|
|
|
16
17
|
super(...args);
|
|
17
18
|
_instances.add(this);
|
|
18
19
|
this.hooks.hook('frontgateConnection:beforeSerializeMessage', (msg) => {
|
|
19
|
-
if (
|
|
20
|
+
if ((0, interfaces_1.isPtlMessageWithHeader)(msg)) {
|
|
20
21
|
api_1.trace.getTracer('frontgate-js-sdk').startActiveSpan('frontgateConnection:sendMessage', (span) => {
|
|
21
22
|
const spanHeader = __classPrivateFieldGet(this, _instances, "m", _createSpanHeader).call(this, span.spanContext());
|
|
22
23
|
if (spanHeader) {
|
|
@@ -15,8 +15,12 @@ const pingRequests = () => {
|
|
|
15
15
|
callbackId: 'PingResponse',
|
|
16
16
|
};
|
|
17
17
|
await this.hooks.callHook('frontgateConnection:sendMessage', msg);
|
|
18
|
-
const promise = new Promise((resolve) => {
|
|
18
|
+
const promise = new Promise((resolve, reject) => {
|
|
19
19
|
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
20
|
+
if (response.Message !== 'Foundation::PingResponse') {
|
|
21
|
+
reject(JSON.stringify(response));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
20
24
|
const pong = new message_1.PingResponse(response);
|
|
21
25
|
resolve(pong);
|
|
22
26
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requests = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const errors_1 = require("../common/errors");
|
|
5
6
|
const message_1 = require("../message");
|
|
6
7
|
const functions_1 = require("../util/functions");
|
|
7
8
|
const requests = () => {
|
|
@@ -15,8 +16,12 @@ const requests = () => {
|
|
|
15
16
|
callbackId: '',
|
|
16
17
|
};
|
|
17
18
|
await this.hooks.callHook('frontgateConnection:sendMessage', msg);
|
|
18
|
-
const promise = new Promise((resolve) => {
|
|
19
|
+
const promise = new Promise((resolve, reject) => {
|
|
19
20
|
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
21
|
+
if (response.Message !== 'Foundation::HighLevelResponse' && response.Message !== 'HighLevelResponse') {
|
|
22
|
+
reject(new errors_1.UnexpectedResponseError(response));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
20
25
|
const mdg2Response = new message_1.Mdg2Response(response);
|
|
21
26
|
resolve(mdg2Response);
|
|
22
27
|
});
|
|
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.appAuth = void 0;
|
|
15
15
|
const _1 = require("../.");
|
|
16
|
+
const errors_1 = require("../../common/errors");
|
|
16
17
|
const compat_1 = require("../../compat");
|
|
17
18
|
const connection_1 = require("../../connection");
|
|
18
19
|
const logger_1 = require("../../logger");
|
|
@@ -62,9 +63,8 @@ const appAuth = (idApplication, idUser, clientCredentials, deploymentStage) => {
|
|
|
62
63
|
return new compat_1.AuthenticationRequest(options);
|
|
63
64
|
},
|
|
64
65
|
_createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
66
|
+
if (msg.Message !== 'Foundation::AuthenticationResponse') {
|
|
67
|
+
throw new errors_1.UnexpectedResponseError(msg);
|
|
68
68
|
}
|
|
69
69
|
const { challenge } = msg.challenge;
|
|
70
70
|
const options = {
|
|
@@ -21,6 +21,7 @@ const logger_1 = require("../../logger");
|
|
|
21
21
|
const message_1 = require("../../message");
|
|
22
22
|
const crypto_1 = require("crypto");
|
|
23
23
|
const functions_1 = require("../../util/functions");
|
|
24
|
+
const errors_1 = require("../../common/errors");
|
|
24
25
|
const sessionAuth = (config, idApplication, username, password, deploymentStage) => {
|
|
25
26
|
const mixinSessionAuth = (Base) => {
|
|
26
27
|
var _instances, _tokenConnectionAttempt, _logOut, _mdg2wstoken, _sharedSecret, _clientSecret, _requestOtpAuthenticationTokenForSessionHandling, _toUrlBase64, _createAuthenticationRequest, _createConfigurationRequest, _createTransportLayerRequestHeaderConfigurationRequest, _submit, _a;
|
|
@@ -137,7 +138,7 @@ const sessionAuth = (config, idApplication, username, password, deploymentStage)
|
|
|
137
138
|
await this.hooks.callHook('frontgateConnection:sendMessage', msg);
|
|
138
139
|
const promise = new Promise((resolve, reject) => {
|
|
139
140
|
this.hooks.hookOnce(`frontgateConnection:response:${msg.callbackId}`, (response) => {
|
|
140
|
-
if (
|
|
141
|
+
if (response.Message !== 'Foundation::AuthenticationTokenResponse') {
|
|
141
142
|
reject(JSON.stringify(response));
|
|
142
143
|
return;
|
|
143
144
|
}
|
|
@@ -166,9 +167,8 @@ const sessionAuth = (config, idApplication, username, password, deploymentStage)
|
|
|
166
167
|
return new compat_1.AuthenticationRequest(options);
|
|
167
168
|
},
|
|
168
169
|
_createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
170
|
+
if (msg.Message !== 'Foundation::AuthenticationResponse') {
|
|
171
|
+
throw new errors_1.UnexpectedResponseError(msg);
|
|
172
172
|
}
|
|
173
173
|
if (msg.id_user === authentication_1.ID_USER_AUTHENTICATED) {
|
|
174
174
|
void this.hooks.callHook('frontgateConnection:setIdApp', authentication_1.ID_APP_AUTHENTICATED);
|
|
@@ -18,6 +18,7 @@ const compat_1 = require("../../compat");
|
|
|
18
18
|
const authentication_1 = require("../../authentication");
|
|
19
19
|
const crypto_1 = require("crypto");
|
|
20
20
|
const logger_1 = require("../../logger");
|
|
21
|
+
const errors_1 = require("../../common/errors");
|
|
21
22
|
const userCredentialAuth = (idApplication, username, credentials, deploymentStage) => {
|
|
22
23
|
const mixinUserCredentialAuth = (Base) => {
|
|
23
24
|
var _instances, _sharedSecret, _clientSecret, _createAuthenticationRequest, _createConfigurationRequest, _createTransportLayerRequestHeaderConfigurationRequest, _submit, _a;
|
|
@@ -61,9 +62,8 @@ const userCredentialAuth = (idApplication, username, credentials, deploymentStag
|
|
|
61
62
|
return new compat_1.AuthenticationRequest(options);
|
|
62
63
|
},
|
|
63
64
|
_createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
65
|
+
if (msg.Message !== 'Foundation::AuthenticationResponse') {
|
|
66
|
+
throw new errors_1.UnexpectedResponseError(msg);
|
|
67
67
|
}
|
|
68
68
|
if (msg.id_user === authentication_1.ID_USER_AUTHENTICATED) {
|
|
69
69
|
void this.hooks.callHook('frontgateConnection:setIdApp', authentication_1.ID_APP_AUTHENTICATED);
|
|
@@ -18,6 +18,7 @@ const authentication_1 = require("../../authentication");
|
|
|
18
18
|
const compat_1 = require("../../compat");
|
|
19
19
|
const logger_1 = require("../../logger");
|
|
20
20
|
const crypto_1 = require("crypto");
|
|
21
|
+
const errors_1 = require("../../common/errors");
|
|
21
22
|
const userPasswordAuth = (idApplication, username, password, deploymentStage) => {
|
|
22
23
|
const mixinUserPasswordAuth = (Base) => {
|
|
23
24
|
var _instances, _sharedSecret, _clientSecret, _createAuthenticationRequest, _createConfigurationRequest, _createTransportLayerRequestHeaderConfigurationRequest, _submit, _a;
|
|
@@ -56,9 +57,8 @@ const userPasswordAuth = (idApplication, username, password, deploymentStage) =>
|
|
|
56
57
|
return new compat_1.AuthenticationRequest(options);
|
|
57
58
|
},
|
|
58
59
|
_createConfigurationRequest = function _createConfigurationRequest(msg, conf) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error(`Expected message "${expectedMessage}" but received "${msg.Message}"`);
|
|
60
|
+
if (msg.Message !== 'Foundation::AuthenticationResponse') {
|
|
61
|
+
throw new errors_1.UnexpectedResponseError(msg);
|
|
62
62
|
}
|
|
63
63
|
if (msg.id_user === authentication_1.ID_USER_AUTHENTICATED) {
|
|
64
64
|
void this.hooks.callHook('frontgateConnection:setIdApp', authentication_1.ID_APP_AUTHENTICATED);
|