@brokerize/client 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/apiCtx.d.ts +10 -2
- package/dist/apiCtx.js +4 -4
- package/dist/authorizedApiContext.d.ts +5 -0
- package/dist/authorizedApiContext.js +12 -4
- package/dist/cjs/apiCtx.d.ts +10 -2
- package/dist/cjs/apiCtx.js +4 -4
- package/dist/cjs/authorizedApiContext.d.ts +5 -0
- package/dist/cjs/authorizedApiContext.js +11 -3
- package/dist/cjs/errors.d.ts +74 -0
- package/dist/cjs/errors.js +95 -1
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/modelExports.d.ts +3 -0
- package/dist/cjs/modelExports.js +5 -1
- package/dist/cjs/swagger/models/BrokerClientCfg.d.ts +7 -0
- package/dist/cjs/swagger/models/BrokerClientCfg.js +5 -0
- package/dist/cjs/swagger/models/BrokerMeta.d.ts +15 -0
- package/dist/cjs/swagger/models/BrokerMeta.js +2 -0
- package/dist/cjs/swagger/models/ClientConfigUpdateOAuthLoginForm.d.ts +12 -1
- package/dist/cjs/swagger/models/ClientConfigUpdateOAuthLoginForm.js +2 -0
- package/dist/cjs/swagger/models/OAuthLoginFormConfig.d.ts +12 -1
- package/dist/cjs/swagger/models/OAuthLoginFormConfig.js +2 -0
- package/dist/cjs/swagger/models/Order.d.ts +9 -1
- package/dist/cjs/swagger/models/OrderCreate.d.ts +2 -1
- package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfo.d.ts +60 -0
- package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfo.js +51 -0
- package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfoStatus.d.ts +22 -0
- package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfoStatus.js +35 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoComplete.d.ts +7 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoComplete.js +6 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoCompleteSpecifics.d.ts +7 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoCompleteSpecifics.js +5 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoIncomplete.d.ts +7 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoIncomplete.js +6 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoIncompleteSpecifics.d.ts +7 -0
- package/dist/cjs/swagger/models/PortfolioSyncInfoIncompleteSpecifics.js +5 -0
- package/dist/cjs/swagger/models/SmartbrokerClientCfg.d.ts +27 -0
- package/dist/cjs/swagger/models/SmartbrokerClientCfg.js +46 -0
- package/dist/cjs/swagger/models/SummarizedTrade.d.ts +14 -0
- package/dist/cjs/swagger/models/SummarizedTrade.js +4 -0
- package/dist/cjs/swagger/models/TradeWarning.d.ts +31 -1
- package/dist/cjs/swagger/models/TradeWarning.js +13 -0
- package/dist/cjs/swagger/models/TradeWarningReason.d.ts +46 -0
- package/dist/cjs/swagger/models/TradeWarningReason.js +59 -0
- package/dist/cjs/swagger/models/index.d.ts +4 -0
- package/dist/cjs/swagger/models/index.js +4 -0
- package/dist/cjs/websocketClient.d.ts +109 -2
- package/dist/cjs/websocketClient.js +416 -74
- package/dist/cjs/websocketTypes.d.ts +10 -0
- package/dist/client.d.ts +437 -61
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +89 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -5
- package/dist/modelExports.d.ts +3 -0
- package/dist/modelExports.js +2 -0
- package/dist/swagger/models/BrokerClientCfg.d.ts +7 -0
- package/dist/swagger/models/BrokerClientCfg.js +5 -0
- package/dist/swagger/models/BrokerMeta.d.ts +15 -0
- package/dist/swagger/models/BrokerMeta.js +2 -0
- package/dist/swagger/models/ClientConfigUpdateOAuthLoginForm.d.ts +12 -1
- package/dist/swagger/models/ClientConfigUpdateOAuthLoginForm.js +2 -0
- package/dist/swagger/models/OAuthLoginFormConfig.d.ts +12 -1
- package/dist/swagger/models/OAuthLoginFormConfig.js +2 -0
- package/dist/swagger/models/Order.d.ts +9 -1
- package/dist/swagger/models/OrderCreate.d.ts +2 -1
- package/dist/swagger/models/PortfolioOrderDetailsSyncInfo.d.ts +60 -0
- package/dist/swagger/models/PortfolioOrderDetailsSyncInfo.js +45 -0
- package/dist/swagger/models/PortfolioOrderDetailsSyncInfoStatus.d.ts +22 -0
- package/dist/swagger/models/PortfolioOrderDetailsSyncInfoStatus.js +29 -0
- package/dist/swagger/models/PortfolioSyncInfoComplete.d.ts +7 -0
- package/dist/swagger/models/PortfolioSyncInfoComplete.js +6 -0
- package/dist/swagger/models/PortfolioSyncInfoCompleteSpecifics.d.ts +7 -0
- package/dist/swagger/models/PortfolioSyncInfoCompleteSpecifics.js +5 -0
- package/dist/swagger/models/PortfolioSyncInfoIncomplete.d.ts +7 -0
- package/dist/swagger/models/PortfolioSyncInfoIncomplete.js +6 -0
- package/dist/swagger/models/PortfolioSyncInfoIncompleteSpecifics.d.ts +7 -0
- package/dist/swagger/models/PortfolioSyncInfoIncompleteSpecifics.js +5 -0
- package/dist/swagger/models/SmartbrokerClientCfg.d.ts +27 -0
- package/dist/swagger/models/SmartbrokerClientCfg.js +40 -0
- package/dist/swagger/models/SummarizedTrade.d.ts +14 -0
- package/dist/swagger/models/SummarizedTrade.js +4 -0
- package/dist/swagger/models/TradeWarning.d.ts +31 -1
- package/dist/swagger/models/TradeWarning.js +13 -0
- package/dist/swagger/models/TradeWarningReason.d.ts +46 -0
- package/dist/swagger/models/TradeWarningReason.js +53 -0
- package/dist/swagger/models/index.d.ts +4 -0
- package/dist/swagger/models/index.js +4 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/websocketClient.d.ts +109 -2
- package/dist/websocketClient.js +416 -74
- package/dist/websocketTypes.d.ts +10 -0
- package/package.json +11 -10
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* https://openapi-generator.tech
|
|
9
9
|
* Do not edit the class manually.
|
|
10
10
|
*/
|
|
11
|
+
import { Security } from "./Security";
|
|
12
|
+
import { TradeWarningReason } from "./TradeWarningReason";
|
|
11
13
|
/**
|
|
12
14
|
*
|
|
13
15
|
* @export
|
|
@@ -15,11 +17,39 @@
|
|
|
15
17
|
*/
|
|
16
18
|
export interface TradeWarning {
|
|
17
19
|
/**
|
|
18
|
-
*
|
|
20
|
+
* Date in the format YYYY-MM-DD for validityType: 'GTD'
|
|
21
|
+
* Date in the format Date ISO string YYYY-MM-DDThh:mm:ss.fffZ for validityType: 'GTDT'
|
|
22
|
+
* @type {string}
|
|
23
|
+
* @memberof TradeWarning
|
|
24
|
+
*/
|
|
25
|
+
fromDate?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Human-readable description, currently German or English depending on where it originates. Meant
|
|
28
|
+
* as a fallback for displaying something at all — a client that knows `reason` should build its
|
|
29
|
+
* own text from the structured fields instead.
|
|
19
30
|
* @type {string}
|
|
20
31
|
* @memberof TradeWarning
|
|
21
32
|
*/
|
|
22
33
|
message: string;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @type {TradeWarningReason}
|
|
37
|
+
* @memberof TradeWarning
|
|
38
|
+
*/
|
|
39
|
+
reason: TradeWarningReason;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @type {Security}
|
|
43
|
+
* @memberof TradeWarning
|
|
44
|
+
*/
|
|
45
|
+
security?: Security;
|
|
46
|
+
/**
|
|
47
|
+
* Date in the format YYYY-MM-DD for validityType: 'GTD'
|
|
48
|
+
* Date in the format Date ISO string YYYY-MM-DDThh:mm:ss.fffZ for validityType: 'GTDT'
|
|
49
|
+
* @type {string}
|
|
50
|
+
* @memberof TradeWarning
|
|
51
|
+
*/
|
|
52
|
+
toDate?: string;
|
|
23
53
|
}
|
|
24
54
|
export declare function TradeWarningFromJSON(json: any): TradeWarning;
|
|
25
55
|
export declare function TradeWarningFromJSONTyped(json: any, ignoreDiscriminator: boolean): TradeWarning;
|
|
@@ -16,6 +16,9 @@ exports.TradeWarningFromJSON = TradeWarningFromJSON;
|
|
|
16
16
|
exports.TradeWarningFromJSONTyped = TradeWarningFromJSONTyped;
|
|
17
17
|
exports.TradeWarningToJSONRecursive = TradeWarningToJSONRecursive;
|
|
18
18
|
exports.TradeWarningToJSON = TradeWarningToJSON;
|
|
19
|
+
const runtime_1 = require("../runtime");
|
|
20
|
+
const Security_1 = require("./Security");
|
|
21
|
+
const TradeWarningReason_1 = require("./TradeWarningReason");
|
|
19
22
|
function TradeWarningFromJSON(json) {
|
|
20
23
|
return TradeWarningFromJSONTyped(json, false);
|
|
21
24
|
}
|
|
@@ -24,7 +27,13 @@ function TradeWarningFromJSONTyped(json, ignoreDiscriminator) {
|
|
|
24
27
|
return json;
|
|
25
28
|
}
|
|
26
29
|
return {
|
|
30
|
+
fromDate: !(0, runtime_1.exists)(json, "fromDate") ? undefined : json["fromDate"],
|
|
27
31
|
message: json["message"],
|
|
32
|
+
reason: (0, TradeWarningReason_1.TradeWarningReasonFromJSON)(json["reason"]),
|
|
33
|
+
security: !(0, runtime_1.exists)(json, "security")
|
|
34
|
+
? undefined
|
|
35
|
+
: (0, Security_1.SecurityFromJSON)(json["security"]),
|
|
36
|
+
toDate: !(0, runtime_1.exists)(json, "toDate") ? undefined : json["toDate"],
|
|
28
37
|
};
|
|
29
38
|
}
|
|
30
39
|
function TradeWarningToJSONRecursive(value, ignoreParent = false) {
|
|
@@ -35,7 +44,11 @@ function TradeWarningToJSONRecursive(value, ignoreParent = false) {
|
|
|
35
44
|
return null;
|
|
36
45
|
}
|
|
37
46
|
return {
|
|
47
|
+
fromDate: value.fromDate,
|
|
38
48
|
message: value.message,
|
|
49
|
+
reason: (0, TradeWarningReason_1.TradeWarningReasonToJSON)(value.reason),
|
|
50
|
+
security: (0, Security_1.SecurityToJSON)(value.security),
|
|
51
|
+
toDate: value.toDate,
|
|
39
52
|
};
|
|
40
53
|
}
|
|
41
54
|
function TradeWarningToJSON(value) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* brokerize
|
|
3
|
+
* The brokerize API allows clients to implement multi-brokerage with a unified interface. For more information, visit brokerize.com
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
8
|
+
* https://openapi-generator.tech
|
|
9
|
+
* Do not edit the class manually.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Why a trade or portfolio-history computation could not give a complete answer. Clients switch on
|
|
13
|
+
* this instead of parsing `TradeWarning.message`, which is free text and may change at any time.
|
|
14
|
+
*
|
|
15
|
+
* - `executionsWithoutTimestamp`: order executions carry no execution time, so they cannot be placed
|
|
16
|
+
* on a timeline and were ignored altogether.
|
|
17
|
+
* - `inconsistentOrderHistory`: the executions of one security contradict each other or the reported
|
|
18
|
+
* holding (more sold than ever bought, a quantity that goes negative). Nothing can be reconstructed
|
|
19
|
+
* from them, so the security is left out of the value history and its trades are not reported.
|
|
20
|
+
* - `positionNotFullyExplained`: the order archive covers only part of a position — typical for
|
|
21
|
+
* brokers that return just the most recent weeks. What is held today is known, but its history
|
|
22
|
+
* reaches further back than the executions do.
|
|
23
|
+
* - `missingEodPrice`: no closing price was available for the security on some days; it was valued
|
|
24
|
+
* with the last price known before them.
|
|
25
|
+
* - `missingFxRate`: no exchange rate to the portfolio currency exists for the security's currency, so
|
|
26
|
+
* its amounts are *not* converted and the totals they enter are off by the conversion.
|
|
27
|
+
* - `unknownBuyPrice`: no purchase price could be determined for a position, so it is missing from the
|
|
28
|
+
* buy value (and from the profit it implies).
|
|
29
|
+
* - `realizedPnlUnavailable`: the completed trades could not be computed at all, which leaves the
|
|
30
|
+
* realized profit/loss empty rather than wrong.
|
|
31
|
+
* @export
|
|
32
|
+
*/
|
|
33
|
+
export declare const TradeWarningReason: {
|
|
34
|
+
readonly ExecutionsWithoutTimestamp: "executionsWithoutTimestamp";
|
|
35
|
+
readonly InconsistentOrderHistory: "inconsistentOrderHistory";
|
|
36
|
+
readonly OrderDetailsIncomplete: "orderDetailsIncomplete";
|
|
37
|
+
readonly PositionNotFullyExplained: "positionNotFullyExplained";
|
|
38
|
+
readonly MissingEodPrice: "missingEodPrice";
|
|
39
|
+
readonly MissingFxRate: "missingFxRate";
|
|
40
|
+
readonly UnknownBuyPrice: "unknownBuyPrice";
|
|
41
|
+
readonly RealizedPnlUnavailable: "realizedPnlUnavailable";
|
|
42
|
+
};
|
|
43
|
+
export type TradeWarningReason = (typeof TradeWarningReason)[keyof typeof TradeWarningReason];
|
|
44
|
+
export declare function TradeWarningReasonFromJSON(json: any): TradeWarningReason;
|
|
45
|
+
export declare function TradeWarningReasonFromJSONTyped(json: any, ignoreDiscriminator: boolean): TradeWarningReason;
|
|
46
|
+
export declare function TradeWarningReasonToJSON(value?: TradeWarningReason | null): any;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* brokerize
|
|
6
|
+
* The brokerize API allows clients to implement multi-brokerage with a unified interface. For more information, visit brokerize.com
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TradeWarningReason = void 0;
|
|
16
|
+
exports.TradeWarningReasonFromJSON = TradeWarningReasonFromJSON;
|
|
17
|
+
exports.TradeWarningReasonFromJSONTyped = TradeWarningReasonFromJSONTyped;
|
|
18
|
+
exports.TradeWarningReasonToJSON = TradeWarningReasonToJSON;
|
|
19
|
+
/**
|
|
20
|
+
* Why a trade or portfolio-history computation could not give a complete answer. Clients switch on
|
|
21
|
+
* this instead of parsing `TradeWarning.message`, which is free text and may change at any time.
|
|
22
|
+
*
|
|
23
|
+
* - `executionsWithoutTimestamp`: order executions carry no execution time, so they cannot be placed
|
|
24
|
+
* on a timeline and were ignored altogether.
|
|
25
|
+
* - `inconsistentOrderHistory`: the executions of one security contradict each other or the reported
|
|
26
|
+
* holding (more sold than ever bought, a quantity that goes negative). Nothing can be reconstructed
|
|
27
|
+
* from them, so the security is left out of the value history and its trades are not reported.
|
|
28
|
+
* - `positionNotFullyExplained`: the order archive covers only part of a position — typical for
|
|
29
|
+
* brokers that return just the most recent weeks. What is held today is known, but its history
|
|
30
|
+
* reaches further back than the executions do.
|
|
31
|
+
* - `missingEodPrice`: no closing price was available for the security on some days; it was valued
|
|
32
|
+
* with the last price known before them.
|
|
33
|
+
* - `missingFxRate`: no exchange rate to the portfolio currency exists for the security's currency, so
|
|
34
|
+
* its amounts are *not* converted and the totals they enter are off by the conversion.
|
|
35
|
+
* - `unknownBuyPrice`: no purchase price could be determined for a position, so it is missing from the
|
|
36
|
+
* buy value (and from the profit it implies).
|
|
37
|
+
* - `realizedPnlUnavailable`: the completed trades could not be computed at all, which leaves the
|
|
38
|
+
* realized profit/loss empty rather than wrong.
|
|
39
|
+
* @export
|
|
40
|
+
*/
|
|
41
|
+
exports.TradeWarningReason = {
|
|
42
|
+
ExecutionsWithoutTimestamp: "executionsWithoutTimestamp",
|
|
43
|
+
InconsistentOrderHistory: "inconsistentOrderHistory",
|
|
44
|
+
OrderDetailsIncomplete: "orderDetailsIncomplete",
|
|
45
|
+
PositionNotFullyExplained: "positionNotFullyExplained",
|
|
46
|
+
MissingEodPrice: "missingEodPrice",
|
|
47
|
+
MissingFxRate: "missingFxRate",
|
|
48
|
+
UnknownBuyPrice: "unknownBuyPrice",
|
|
49
|
+
RealizedPnlUnavailable: "realizedPnlUnavailable",
|
|
50
|
+
};
|
|
51
|
+
function TradeWarningReasonFromJSON(json) {
|
|
52
|
+
return TradeWarningReasonFromJSONTyped(json, false);
|
|
53
|
+
}
|
|
54
|
+
function TradeWarningReasonFromJSONTyped(json, ignoreDiscriminator) {
|
|
55
|
+
return json;
|
|
56
|
+
}
|
|
57
|
+
function TradeWarningReasonToJSON(value) {
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
@@ -183,6 +183,8 @@ export * from "./PagesConfigurationResponse";
|
|
|
183
183
|
export * from "./Portfolio";
|
|
184
184
|
export * from "./PortfolioCalendarDateRange";
|
|
185
185
|
export * from "./PortfolioCalendarItem";
|
|
186
|
+
export * from "./PortfolioOrderDetailsSyncInfo";
|
|
187
|
+
export * from "./PortfolioOrderDetailsSyncInfoStatus";
|
|
186
188
|
export * from "./PortfolioQuotes";
|
|
187
189
|
export * from "./PortfolioSyncInfo";
|
|
188
190
|
export * from "./PortfolioSyncInfoComplete";
|
|
@@ -230,6 +232,7 @@ export * from "./SessionSyncInfoSyncedAllOf";
|
|
|
230
232
|
export * from "./SessionSyncInfoSyncedSpecifics";
|
|
231
233
|
export * from "./SetClientConfigRequest";
|
|
232
234
|
export * from "./SizeUnitConstraint";
|
|
235
|
+
export * from "./SmartbrokerClientCfg";
|
|
233
236
|
export * from "./StringMapByOrderModel";
|
|
234
237
|
export * from "./SummarizedTrade";
|
|
235
238
|
export * from "./SyncError";
|
|
@@ -256,6 +259,7 @@ export * from "./TradeStatisticsDateRange";
|
|
|
256
259
|
export * from "./TradeStatisticsHoldingPeriodInDays";
|
|
257
260
|
export * from "./TradeStatisticsItem";
|
|
258
261
|
export * from "./TradeWarning";
|
|
262
|
+
export * from "./TradeWarningReason";
|
|
259
263
|
export * from "./TradingSessionLifetime";
|
|
260
264
|
export * from "./TrailingDistance";
|
|
261
265
|
export * from "./TriggerSync200Response";
|
|
@@ -201,6 +201,8 @@ __exportStar(require("./PagesConfigurationResponse"), exports);
|
|
|
201
201
|
__exportStar(require("./Portfolio"), exports);
|
|
202
202
|
__exportStar(require("./PortfolioCalendarDateRange"), exports);
|
|
203
203
|
__exportStar(require("./PortfolioCalendarItem"), exports);
|
|
204
|
+
__exportStar(require("./PortfolioOrderDetailsSyncInfo"), exports);
|
|
205
|
+
__exportStar(require("./PortfolioOrderDetailsSyncInfoStatus"), exports);
|
|
204
206
|
__exportStar(require("./PortfolioQuotes"), exports);
|
|
205
207
|
__exportStar(require("./PortfolioSyncInfo"), exports);
|
|
206
208
|
__exportStar(require("./PortfolioSyncInfoComplete"), exports);
|
|
@@ -248,6 +250,7 @@ __exportStar(require("./SessionSyncInfoSyncedAllOf"), exports);
|
|
|
248
250
|
__exportStar(require("./SessionSyncInfoSyncedSpecifics"), exports);
|
|
249
251
|
__exportStar(require("./SetClientConfigRequest"), exports);
|
|
250
252
|
__exportStar(require("./SizeUnitConstraint"), exports);
|
|
253
|
+
__exportStar(require("./SmartbrokerClientCfg"), exports);
|
|
251
254
|
__exportStar(require("./StringMapByOrderModel"), exports);
|
|
252
255
|
__exportStar(require("./SummarizedTrade"), exports);
|
|
253
256
|
__exportStar(require("./SyncError"), exports);
|
|
@@ -274,6 +277,7 @@ __exportStar(require("./TradeStatisticsDateRange"), exports);
|
|
|
274
277
|
__exportStar(require("./TradeStatisticsHoldingPeriodInDays"), exports);
|
|
275
278
|
__exportStar(require("./TradeStatisticsItem"), exports);
|
|
276
279
|
__exportStar(require("./TradeWarning"), exports);
|
|
280
|
+
__exportStar(require("./TradeWarningReason"), exports);
|
|
277
281
|
__exportStar(require("./TradingSessionLifetime"), exports);
|
|
278
282
|
__exportStar(require("./TrailingDistance"), exports);
|
|
279
283
|
__exportStar(require("./TriggerSync200Response"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Auth } from "./apiCtx";
|
|
2
2
|
import { AuthorizedApiContext } from "./authorizedApiContext";
|
|
3
3
|
import { WebSocket } from "./dependencyDefinitions/webSocket";
|
|
4
|
+
import { BrokerizeWebSocketError } from "./errors";
|
|
4
5
|
import type { SubscribeDecoupledOperation, SubscribeInvalidateDetails } from "./websocketTypes";
|
|
5
6
|
export declare class BrokerizeWebSocketClientImpl implements BrokerizeWebSocketClient {
|
|
6
7
|
private _url;
|
|
@@ -18,18 +19,70 @@ export declare class BrokerizeWebSocketClientImpl implements BrokerizeWebSocketC
|
|
|
18
19
|
private _lastNonFatalError;
|
|
19
20
|
private _errorCount;
|
|
20
21
|
private _apiCtx;
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* How often the server rejected our token in a row. Every retry forces a token refresh, and
|
|
24
|
+
* only `_maxConsecutiveAuthFailures` of them in a row are fatal. Reset on every successful
|
|
25
|
+
* authentication.
|
|
26
|
+
*/
|
|
27
|
+
private _authFailureCount;
|
|
28
|
+
private _maxConsecutiveAuthFailures;
|
|
29
|
+
private _forceTokenRefresh;
|
|
30
|
+
private _destroyed;
|
|
31
|
+
private _connectionState;
|
|
32
|
+
private _connectionStateCallbacks;
|
|
33
|
+
constructor(websocketUrl: string, auth: Auth, createWebSocket: (url: string) => WebSocket, options?: BrokerizeWebSocketClientOptions);
|
|
22
34
|
private _updateReconnectInterval;
|
|
23
35
|
/**
|
|
24
36
|
* Simple backoff behavior: first retry is fast (100ms), next 9 retries 1s, after that we only reconnect every 10s.
|
|
25
37
|
* Jitter is added to avoid a thundering herd when many clients reconnect simultaneously (e.g. after a server-side disconnect).
|
|
26
38
|
* The first retry uses a wider jitter window (~1s) because that's the scenario most prone to bursts of TLS handshakes.
|
|
39
|
+
*
|
|
40
|
+
* A token that keeps being rejected is retried far more slowly (`AUTH_RETRY_INTERVAL`), because
|
|
41
|
+
* every one of those attempts refreshes the token and a rejection is not something that tends to
|
|
42
|
+
* resolve within a second.
|
|
27
43
|
*/
|
|
28
44
|
private _computeReconnectIntervalInMilliseconds;
|
|
29
45
|
private _shouldConnect;
|
|
46
|
+
/**
|
|
47
|
+
* Invoke a subscriber callback. A callback that throws must not prevent the remaining
|
|
48
|
+
* subscribers from being notified, so everything is contained here.
|
|
49
|
+
*/
|
|
50
|
+
private _invokeCallback;
|
|
30
51
|
private subscribe;
|
|
31
52
|
subscribeInvalidate(subscribe: SubscribeInvalidateDetails, callback: Callback): Subscription;
|
|
32
53
|
subscribeDecoupledOperation(subscribe: Pick<SubscribeDecoupledOperation, "sessionId" | "decoupledOperationId">, callback: Callback): Subscription;
|
|
54
|
+
/**
|
|
55
|
+
* The current connection state. See `subscribeConnectionState`.
|
|
56
|
+
*/
|
|
57
|
+
getConnectionState(): WebSocketConnectionState;
|
|
58
|
+
/**
|
|
59
|
+
* Observe the state of the underlying websocket connection. The callback is invoked immediately
|
|
60
|
+
* with the current state and afterwards on every change.
|
|
61
|
+
*
|
|
62
|
+
* This is the only place where non-terminal errors are reported: the client recovers from them
|
|
63
|
+
* on its own, so they are not passed to the subscription callbacks, which would force
|
|
64
|
+
* applications to tear down subscriptions on every connection hiccup. Use this to show that
|
|
65
|
+
* live updates are currently unavailable.
|
|
66
|
+
*/
|
|
67
|
+
subscribeConnectionState(callback: ConnectionStateCallback): Subscription;
|
|
68
|
+
/**
|
|
69
|
+
* Recover from a fatal error (see `WebSocketConnectionState`). The client drops the fatal error
|
|
70
|
+
* state and connects again, retrieving a fresh token. Existing subscriptions were already
|
|
71
|
+
* terminated when the fatal error occurred, so applications have to subscribe again.
|
|
72
|
+
*
|
|
73
|
+
* Calling this without a fatal error forces a reconnect of the current connection.
|
|
74
|
+
*/
|
|
75
|
+
reconnect(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Release all resources: close the connection, drop all subscriptions and stop the reconnect and
|
|
78
|
+
* ping timers. A destroyed client cannot be revived with `reconnect()`.
|
|
79
|
+
*
|
|
80
|
+
* This is called by `AuthorizedApiContext.destroy()` for the client it created itself. A client
|
|
81
|
+
* that was passed in from outside is owned by the application and is not destroyed with the
|
|
82
|
+
* context.
|
|
83
|
+
*/
|
|
84
|
+
destroy(): void;
|
|
85
|
+
private _setConnectionState;
|
|
33
86
|
private _startSubscription;
|
|
34
87
|
private _fillInMessagesAfterConnectionInterruption;
|
|
35
88
|
private _endSubscription;
|
|
@@ -40,13 +93,26 @@ export declare class BrokerizeWebSocketClientImpl implements BrokerizeWebSocketC
|
|
|
40
93
|
_setAuthorizedApiContext(ctx: AuthorizedApiContext): void;
|
|
41
94
|
_startOrStopDisconnectTimeout(): void;
|
|
42
95
|
private _sendWs;
|
|
96
|
+
/**
|
|
97
|
+
* Close the current socket, if any, and detach its handlers so that a late `close` event of an
|
|
98
|
+
* outdated socket cannot interfere with a connection established in the meantime.
|
|
99
|
+
*/
|
|
100
|
+
private _closeSocket;
|
|
43
101
|
private _connect;
|
|
102
|
+
private _handleMessage;
|
|
103
|
+
/**
|
|
104
|
+
* The server rejected our token. The usual cause is an id token that expired between retrieving
|
|
105
|
+
* it and the server validating it, which a fresh token fixes, so retry once before giving up on
|
|
106
|
+
* this client.
|
|
107
|
+
*/
|
|
108
|
+
private _handleAuthenticationFailure;
|
|
44
109
|
/**
|
|
45
110
|
* Error happend when trying to connect, but it may be solved by trying a reconnect later.
|
|
46
111
|
*/
|
|
47
112
|
private _handleNonFatalError;
|
|
48
113
|
/**
|
|
49
|
-
* Fatal error: this means the client is unusable from now on and must be recreated
|
|
114
|
+
* Fatal error: this means the client is unusable from now on and must be recreated or revived
|
|
115
|
+
* with `reconnect()`.
|
|
50
116
|
*/
|
|
51
117
|
private _handleFatalError;
|
|
52
118
|
/**
|
|
@@ -59,10 +125,51 @@ export declare class BrokerizeWebSocketClientImpl implements BrokerizeWebSocketC
|
|
|
59
125
|
private _resetErrorState;
|
|
60
126
|
private _findSubscriptionEntry;
|
|
61
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Optional behavior of `BrokerizeWebSocketClientImpl`. The defaults are what an application
|
|
130
|
+
* wants; this exists for the rare case that they have to be tightened.
|
|
131
|
+
*/
|
|
132
|
+
export type BrokerizeWebSocketClientOptions = {
|
|
133
|
+
/**
|
|
134
|
+
* How often in a row the server may reject our token before the client gives up and goes
|
|
135
|
+
* `fatal`. Defaults to 10, which together with the backoff spans several minutes. Mainly here so
|
|
136
|
+
* that tests do not have to wait that long.
|
|
137
|
+
*/
|
|
138
|
+
maxConsecutiveAuthFailures?: number;
|
|
139
|
+
};
|
|
62
140
|
export interface BrokerizeWebSocketClient {
|
|
63
141
|
subscribeInvalidate: (subscribe: SubscribeInvalidateDetails, callback: Callback) => Subscription;
|
|
64
142
|
subscribeDecoupledOperation: (subscribe: Pick<SubscribeDecoupledOperation, "sessionId" | "decoupledOperationId">, callback: Callback) => Subscription;
|
|
143
|
+
subscribeConnectionState: (callback: ConnectionStateCallback) => Subscription;
|
|
144
|
+
getConnectionState: () => WebSocketConnectionState;
|
|
145
|
+
reconnect: () => void;
|
|
65
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* - `closed`: not connected, because nothing is subscribed.
|
|
149
|
+
* - `connecting`: the first connection attempt is in progress.
|
|
150
|
+
* - `open`: connected and authenticated, live updates are being delivered.
|
|
151
|
+
* - `reconnecting`: the connection failed or was lost and the client is retrying. `error` holds
|
|
152
|
+
* the error that caused it. Subscriptions stay alive and receive a synthetic invalidate once
|
|
153
|
+
* the connection is back.
|
|
154
|
+
*
|
|
155
|
+
* A rejected token lands here too, so an application can show that live updates are currently
|
|
156
|
+
* unavailable - and why - while the client works on getting back in, instead of having to
|
|
157
|
+
* rebuild everything over a token that expired in flight.
|
|
158
|
+
* - `fatal`: the client gave up and is unusable. All subscriptions were terminated with `error`.
|
|
159
|
+
* This only happens after the token has been rejected over and over for several minutes, i.e.
|
|
160
|
+
* when the session is gone rather than stale. Call `reconnect()` or create a new client.
|
|
161
|
+
*/
|
|
162
|
+
export type WebSocketConnectionStatus = "closed" | "connecting" | "open" | "reconnecting" | "fatal";
|
|
163
|
+
export type WebSocketConnectionState = {
|
|
164
|
+
status: WebSocketConnectionStatus;
|
|
165
|
+
error?: BrokerizeWebSocketError;
|
|
166
|
+
};
|
|
167
|
+
export type ConnectionStateCallback = (state: WebSocketConnectionState) => void;
|
|
168
|
+
/**
|
|
169
|
+
* Callback of a subscription. `err` is always a `BrokerizeWebSocketError` with
|
|
170
|
+
* `terminal === true`: the subscription is over and will not receive any further data. Errors the
|
|
171
|
+
* client recovers from on its own are reported via `subscribeConnectionState` instead.
|
|
172
|
+
*/
|
|
66
173
|
export type Callback<T = any> = (err: any, data: T) => void;
|
|
67
174
|
export type Subscription = {
|
|
68
175
|
unsubscribe: () => void;
|