@triveria/wallet 0.0.314 → 0.0.315
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/notifications.d.ts +15 -2
- package/notifications.js +19 -4
- package/package.json +1 -1
package/notifications.d.ts
CHANGED
|
@@ -52,7 +52,10 @@ export declare interface WalletNotificationStream {
|
|
|
52
52
|
* ```
|
|
53
53
|
*
|
|
54
54
|
* Drops are reconnected automatically (replaying queued notifications via
|
|
55
|
-
* `Last-Event-ID`) unless `options.reconnect` is set to `false`.
|
|
55
|
+
* `Last-Event-ID`) unless `options.reconnect` is set to `false`. The current
|
|
56
|
+
* `Last-Event-ID` is exposed via {@link WalletNotificationStream.lastEventId}
|
|
57
|
+
* so it can be persisted and used to resume the stream later, e.g. across
|
|
58
|
+
* process restarts.
|
|
56
59
|
*/
|
|
57
60
|
export declare class WalletNotificationStream extends EventEmitter implements AsyncIterable<WalletNotification> {
|
|
58
61
|
private readonly configuration;
|
|
@@ -64,7 +67,7 @@ export declare class WalletNotificationStream extends EventEmitter implements As
|
|
|
64
67
|
private readonly reconnect;
|
|
65
68
|
private readonly retryDelayMs;
|
|
66
69
|
private readonly maxRetryDelayMs;
|
|
67
|
-
private
|
|
70
|
+
private _lastEventId?;
|
|
68
71
|
private nextRetryDelayMs?;
|
|
69
72
|
private abortController?;
|
|
70
73
|
private retryTimer?;
|
|
@@ -75,6 +78,16 @@ export declare class WalletNotificationStream extends EventEmitter implements As
|
|
|
75
78
|
/** Stops the stream and prevents further reconnection attempts. */
|
|
76
79
|
close(): void;
|
|
77
80
|
get isClosed(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The ID of the last SSE event received on this stream (per the `id:` field),
|
|
83
|
+
* or the `lastEventId` the stream was constructed/reconnected with if no event
|
|
84
|
+
* has been received yet.
|
|
85
|
+
*
|
|
86
|
+
* Persist this value and pass it back as `options.lastEventId` when creating a
|
|
87
|
+
* new {@link WalletNotificationStream} (e.g. after a process restart) to resume
|
|
88
|
+
* the stream and replay any notifications queued since that event.
|
|
89
|
+
*/
|
|
90
|
+
get lastEventId(): string | undefined;
|
|
78
91
|
private connect;
|
|
79
92
|
private scheduleReconnect;
|
|
80
93
|
private dispatchToQueue;
|
package/notifications.js
CHANGED
|
@@ -140,7 +140,10 @@ function parseSseStream(source) {
|
|
|
140
140
|
* ```
|
|
141
141
|
*
|
|
142
142
|
* Drops are reconnected automatically (replaying queued notifications via
|
|
143
|
-
* `Last-Event-ID`) unless `options.reconnect` is set to `false`.
|
|
143
|
+
* `Last-Event-ID`) unless `options.reconnect` is set to `false`. The current
|
|
144
|
+
* `Last-Event-ID` is exposed via {@link WalletNotificationStream.lastEventId}
|
|
145
|
+
* so it can be persisted and used to resume the stream later, e.g. across
|
|
146
|
+
* process restarts.
|
|
144
147
|
*/
|
|
145
148
|
class WalletNotificationStream extends events_1.EventEmitter {
|
|
146
149
|
constructor(configuration, walletId, options = {}) {
|
|
@@ -155,7 +158,7 @@ class WalletNotificationStream extends events_1.EventEmitter {
|
|
|
155
158
|
this.basePath = (_c = (_b = options.basePath) !== null && _b !== void 0 ? _b : configuration.basePath) !== null && _c !== void 0 ? _c : base_1.BASE_PATH;
|
|
156
159
|
this.eventType = options.eventType;
|
|
157
160
|
this.state = options.state;
|
|
158
|
-
this.
|
|
161
|
+
this._lastEventId = options.lastEventId;
|
|
159
162
|
this.reconnect = (_d = options.reconnect) !== null && _d !== void 0 ? _d : true;
|
|
160
163
|
this.retryDelayMs = (_e = options.retryDelayMs) !== null && _e !== void 0 ? _e : 3000;
|
|
161
164
|
this.maxRetryDelayMs = (_f = options.maxRetryDelayMs) !== null && _f !== void 0 ? _f : 30000;
|
|
@@ -176,6 +179,18 @@ class WalletNotificationStream extends events_1.EventEmitter {
|
|
|
176
179
|
get isClosed() {
|
|
177
180
|
return this.closed;
|
|
178
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* The ID of the last SSE event received on this stream (per the `id:` field),
|
|
184
|
+
* or the `lastEventId` the stream was constructed/reconnected with if no event
|
|
185
|
+
* has been received yet.
|
|
186
|
+
*
|
|
187
|
+
* Persist this value and pass it back as `options.lastEventId` when creating a
|
|
188
|
+
* new {@link WalletNotificationStream} (e.g. after a process restart) to resume
|
|
189
|
+
* the stream and replay any notifications queued since that event.
|
|
190
|
+
*/
|
|
191
|
+
get lastEventId() {
|
|
192
|
+
return this._lastEventId;
|
|
193
|
+
}
|
|
179
194
|
connect() {
|
|
180
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
196
|
var _a, e_2, _b, _c;
|
|
@@ -184,7 +199,7 @@ class WalletNotificationStream extends events_1.EventEmitter {
|
|
|
184
199
|
return;
|
|
185
200
|
this.abortController = new AbortController();
|
|
186
201
|
try {
|
|
187
|
-
const requestArgs = yield (0, api_1.DefaultApiAxiosParamCreator)(this.configuration).walletNotifications(this.walletId, this.eventType, this.state, this.
|
|
202
|
+
const requestArgs = yield (0, api_1.DefaultApiAxiosParamCreator)(this.configuration).walletNotifications(this.walletId, this.eventType, this.state, this._lastEventId, { signal: this.abortController.signal, responseType: 'stream' });
|
|
188
203
|
const request = (0, common_1.createRequestFunction)(requestArgs, this.axiosInstance, this.basePath, this.configuration);
|
|
189
204
|
const response = yield request(this.axiosInstance, this.basePath);
|
|
190
205
|
this.emit('open');
|
|
@@ -200,7 +215,7 @@ class WalletNotificationStream extends events_1.EventEmitter {
|
|
|
200
215
|
continue;
|
|
201
216
|
}
|
|
202
217
|
if (message.id !== undefined)
|
|
203
|
-
this.
|
|
218
|
+
this._lastEventId = message.id;
|
|
204
219
|
if (!message.data)
|
|
205
220
|
continue;
|
|
206
221
|
let notification;
|