core-3nweb-client-lib 0.42.0 → 0.42.2
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/build/core/asmail/inbox/inbox-events.d.ts +7 -1
- package/build/core/asmail/inbox/inbox-events.js +57 -15
- package/build/core/asmail/inbox/index.js +3 -4
- package/build/core/storage/synced/remote-events.js +1 -3
- package/build/lib-client/asmail/recipient.js +1 -2
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/server-events.d.ts +1 -4
- package/build/lib-client/server-events.js +2 -22
- package/build/lib-common/service-api/asmail/retrieval.d.ts +6 -1
- package/build/lib-common/service-api/asmail/retrieval.js +7 -2
- package/package.json +2 -2
- package/{test-data-1-1759545630658/util/logs/2025-10-04.log.txt → test-data-1-1759677394615/util/logs/2025-10-05.log.txt} +4 -4
- package/{test-data-10-1759545670471/util/logs/2025-10-04.log.txt → test-data-10-1759677431029/util/logs/2025-10-05.log.txt} +4 -4
- package/{test-data-11-1759545670472/util/logs/2025-10-04.log.txt → test-data-11-1759677431029/util/logs/2025-10-05.log.txt} +4 -4
- package/{test-data-12-1759545674484/util/logs/2025-10-04.log.txt → test-data-12-1759677434728/util/logs/2025-10-05.log.txt} +4 -4
- package/{test-data-13-1759545675527/util/logs/2025-10-04.log.txt → test-data-13-1759677435553/util/logs/2025-10-05.log.txt} +8 -8
- package/test-data-2-1759677394617/util/logs/2025-10-05.log.txt +14 -0
- package/{test-data-3-1759545636022/util/logs/2025-10-04.log.txt → test-data-3-1759677399141/util/logs/2025-10-05.log.txt} +8 -8
- package/{test-data-4-1759545642255/util/logs/2025-10-04.log.txt → test-data-4-1759677405076/util/logs/2025-10-05.log.txt} +8 -8
- package/test-data-5-1759677414316/util/logs/2025-10-05.log.txt +14 -0
- package/test-data-6-1759677416229/util/logs/2025-10-05.log.txt +14 -0
- package/test-data-7-1759677418207/util/logs/2025-10-05.log.txt +14 -0
- package/test-data-8-1759677426790/util/logs/2025-10-05.log.txt +14 -0
- package/{test-data-9-1759545666746/util/logs/2025-10-04.log.txt → test-data-9-1759677427624/util/logs/2025-10-05.log.txt} +8 -8
- package/test-data-2-1759545630661/util/logs/2025-10-04.log.txt +0 -14
- package/test-data-5-1759545652091/util/logs/2025-10-04.log.txt +0 -14
- package/test-data-6-1759545654150/util/logs/2025-10-04.log.txt +0 -14
- package/test-data-7-1759545656281/util/logs/2025-10-04.log.txt +0 -14
- package/test-data-8-1759545665798/util/logs/2025-10-04.log.txt +0 -14
|
@@ -3,6 +3,7 @@ import { LogError } from '../../../lib-client/logging/log-to-file';
|
|
|
3
3
|
type IncomingMessage = web3n.asmail.IncomingMessage;
|
|
4
4
|
type InboxEventType = web3n.asmail.InboxEventType;
|
|
5
5
|
type Observer<T> = web3n.Observer<T>;
|
|
6
|
+
type MsgInfo = web3n.asmail.MsgInfo;
|
|
6
7
|
/**
|
|
7
8
|
* Instance of this class handles event subscription from UI side. It observes
|
|
8
9
|
* inbox server events, handles them, and generates respective events for UI
|
|
@@ -15,6 +16,7 @@ type Observer<T> = web3n.Observer<T>;
|
|
|
15
16
|
*/
|
|
16
17
|
export declare class InboxEvents {
|
|
17
18
|
private readonly getMsg;
|
|
19
|
+
private readonly listMsgs;
|
|
18
20
|
private readonly rmMsg;
|
|
19
21
|
private readonly logError;
|
|
20
22
|
private readonly newMsgs;
|
|
@@ -22,8 +24,11 @@ export declare class InboxEvents {
|
|
|
22
24
|
private listeningProc;
|
|
23
25
|
private readonly makeServerEvents;
|
|
24
26
|
private networkActive;
|
|
25
|
-
|
|
27
|
+
private disconnectedAt;
|
|
28
|
+
constructor(msgReceiver: MailRecipient, getMsg: (msgId: string) => Promise<IncomingMessage>, listMsgs: (fromTS: number) => Promise<MsgInfo[]>, rmMsg: (msgId: string) => Promise<void>, logError: LogError);
|
|
26
29
|
private startListening;
|
|
30
|
+
private sleepAndRestart;
|
|
31
|
+
private getMessage;
|
|
27
32
|
subscribe<T>(event: InboxEventType, observer: Observer<T>): () => void;
|
|
28
33
|
close(): void;
|
|
29
34
|
get isListening(): boolean;
|
|
@@ -31,5 +36,6 @@ export declare class InboxEvents {
|
|
|
31
36
|
private stopListening;
|
|
32
37
|
suspendNetworkActivity(): void;
|
|
33
38
|
resumeNetworkActivity(): void;
|
|
39
|
+
private listMsgsFromDisconnectedPeriod;
|
|
34
40
|
}
|
|
35
41
|
export {};
|
|
@@ -24,6 +24,7 @@ const operators_1 = require("rxjs/operators");
|
|
|
24
24
|
const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
|
|
25
25
|
const sleep_1 = require("../../../lib-common/processes/sleep");
|
|
26
26
|
const SERVER_EVENTS_RESTART_WAIT_SECS = 5;
|
|
27
|
+
const BUFFER_MILLIS_FOR_LISTING = 2 * 60 * 1000;
|
|
27
28
|
/**
|
|
28
29
|
* Instance of this class handles event subscription from UI side. It observes
|
|
29
30
|
* inbox server events, handles them, and generates respective events for UI
|
|
@@ -35,15 +36,17 @@ const SERVER_EVENTS_RESTART_WAIT_SECS = 5;
|
|
|
35
36
|
* Hence, this should do restarts to server around wakeup events.
|
|
36
37
|
*/
|
|
37
38
|
class InboxEvents {
|
|
38
|
-
constructor(msgReceiver, getMsg, rmMsg, logError) {
|
|
39
|
+
constructor(msgReceiver, getMsg, listMsgs, rmMsg, logError) {
|
|
39
40
|
this.getMsg = getMsg;
|
|
41
|
+
this.listMsgs = listMsgs;
|
|
40
42
|
this.rmMsg = rmMsg;
|
|
41
43
|
this.logError = logError;
|
|
42
44
|
this.newMsgs = new rxjs_1.Subject();
|
|
43
45
|
this.newMsg$ = this.newMsgs.asObservable().pipe((0, operators_1.share)());
|
|
44
46
|
this.listeningProc = undefined;
|
|
45
47
|
this.networkActive = true;
|
|
46
|
-
this.
|
|
48
|
+
this.disconnectedAt = undefined;
|
|
49
|
+
this.makeServerEvents = () => new server_events_1.ServerEvents(() => msgReceiver.openEventSource(this.logError));
|
|
47
50
|
this.startListening();
|
|
48
51
|
Object.seal(this);
|
|
49
52
|
}
|
|
@@ -51,22 +54,17 @@ class InboxEvents {
|
|
|
51
54
|
if (this.listeningProc || !this.networkActive) {
|
|
52
55
|
return;
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
const clearListeningProc = () => {
|
|
55
58
|
if (this.listeningProc === sub) {
|
|
56
59
|
this.listeningProc = undefined;
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
if (!this.disconnectedAt) {
|
|
62
|
+
this.disconnectedAt = Date.now();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
59
65
|
const sub = this.makeServerEvents()
|
|
60
66
|
.observe(retrieval_1.msgRecievedCompletely.EVENT_NAME)
|
|
61
|
-
.pipe((0, operators_1.mergeMap)(async (ev) =>
|
|
62
|
-
try {
|
|
63
|
-
return await this.getMsg(ev.msgId);
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
await this.rmMsg(ev.msgId);
|
|
67
|
-
await this.logError(err, `Cannot get message ${ev.msgId}, and removing it as a result`);
|
|
68
|
-
}
|
|
69
|
-
}, 5))
|
|
67
|
+
.pipe((0, operators_1.mergeMap)(async (ev) => this.getMessage(ev.msgId), 5))
|
|
70
68
|
.subscribe({
|
|
71
69
|
next: msg => {
|
|
72
70
|
if (msg) {
|
|
@@ -79,12 +77,26 @@ class InboxEvents {
|
|
|
79
77
|
error: async (exc) => {
|
|
80
78
|
clearListeningProc();
|
|
81
79
|
if (this.shouldRestartAfterErr(exc)) {
|
|
82
|
-
|
|
83
|
-
this.startListening();
|
|
80
|
+
this.sleepAndRestart();
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
});
|
|
87
84
|
this.listeningProc = sub;
|
|
85
|
+
this.listMsgsFromDisconnectedPeriod();
|
|
86
|
+
}
|
|
87
|
+
async sleepAndRestart() {
|
|
88
|
+
await (0, sleep_1.sleep)(SERVER_EVENTS_RESTART_WAIT_SECS);
|
|
89
|
+
this.startListening();
|
|
90
|
+
}
|
|
91
|
+
async getMessage(msgId) {
|
|
92
|
+
try {
|
|
93
|
+
return await this.getMsg(msgId);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
// XXX we need to skip, if it is a connectivity error here
|
|
97
|
+
// await this.rmMsg(msgId);
|
|
98
|
+
await this.logError(err, `Cannot get message ${msgId}, and removing it as a result`);
|
|
99
|
+
}
|
|
88
100
|
}
|
|
89
101
|
subscribe(event, observer) {
|
|
90
102
|
if (event === 'message') {
|
|
@@ -126,6 +138,9 @@ class InboxEvents {
|
|
|
126
138
|
suspendNetworkActivity() {
|
|
127
139
|
this.networkActive = false;
|
|
128
140
|
if (this.isListening) {
|
|
141
|
+
if (!this.disconnectedAt) {
|
|
142
|
+
this.disconnectedAt = Date.now();
|
|
143
|
+
}
|
|
129
144
|
this.stopListening();
|
|
130
145
|
}
|
|
131
146
|
}
|
|
@@ -135,6 +150,33 @@ class InboxEvents {
|
|
|
135
150
|
this.startListening();
|
|
136
151
|
}
|
|
137
152
|
}
|
|
153
|
+
async listMsgsFromDisconnectedPeriod() {
|
|
154
|
+
// DEBUG log
|
|
155
|
+
await this.logError(null, `entering listMsgsFromDisconnectedPeriod at ${Date.now()}, this.disconnectedAt is ${this.disconnectedAt}`);
|
|
156
|
+
if (!this.disconnectedAt) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const fromTS = this.disconnectedAt - BUFFER_MILLIS_FOR_LISTING;
|
|
160
|
+
// DEBUG log
|
|
161
|
+
await this.logError(null, `starting listMsgsFromDisconnectedPeriod process with fromTS ${fromTS}`);
|
|
162
|
+
let msgInfos = (await this.listMsgs(fromTS))
|
|
163
|
+
.filter(info => (fromTS <= info.deliveryTS))
|
|
164
|
+
.sort((a, b) => (a.deliveryTS - b.deliveryTS));
|
|
165
|
+
// DEBUG log
|
|
166
|
+
await this.logError(null, ` ... filtered list has ${msgInfos.length} number of items`);
|
|
167
|
+
for (const info of msgInfos) {
|
|
168
|
+
const msg = await this.getMessage(info.msgId);
|
|
169
|
+
// DEBUG log
|
|
170
|
+
await this.logError(null, ` ... msg ${msg === null || msg === void 0 ? void 0 : msg.msgId} found`);
|
|
171
|
+
if (msg) {
|
|
172
|
+
this.newMsgs.next(msg);
|
|
173
|
+
}
|
|
174
|
+
else if (!this.networkActive) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
this.disconnectedAt = undefined;
|
|
179
|
+
}
|
|
138
180
|
}
|
|
139
181
|
exports.InboxEvents = InboxEvents;
|
|
140
182
|
Object.freeze(InboxEvents.prototype);
|
|
@@ -51,7 +51,7 @@ class InboxOnServer {
|
|
|
51
51
|
this.logError = logError;
|
|
52
52
|
this.procs = new synced_1.NamedProcs();
|
|
53
53
|
this.recentlyOpenedMsgs = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
54
|
-
this.inboxEvents = new inbox_events_1.InboxEvents(this.msgReceiver, this.getMsg.bind(this), this.removeMsg.bind(this), this.logError);
|
|
54
|
+
this.inboxEvents = new inbox_events_1.InboxEvents(this.msgReceiver, this.getMsg.bind(this), this.listMsgs.bind(this), this.removeMsg.bind(this), this.logError);
|
|
55
55
|
Object.seal(this);
|
|
56
56
|
}
|
|
57
57
|
static async makeAndStart(cachePath, syncedFS, r) {
|
|
@@ -230,11 +230,10 @@ class InboxOnServer {
|
|
|
230
230
|
if (msgIds.length === 0) {
|
|
231
231
|
return indexedMsgs;
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
await Promise.all(msgIds.map(msgId => this.startCachingAndAddKeyToIndex(msgId)
|
|
234
234
|
.catch(async (exc) => {
|
|
235
235
|
await this.logError(exc, `Failed to start caching message ${msgId}`);
|
|
236
|
-
}));
|
|
237
|
-
await Promise.all(keying);
|
|
236
|
+
})));
|
|
238
237
|
return this.index.listMsgs(fromTS);
|
|
239
238
|
});
|
|
240
239
|
}
|
|
@@ -36,9 +36,7 @@ class RemoteEvents {
|
|
|
36
36
|
Object.seal(this);
|
|
37
37
|
}
|
|
38
38
|
startAbsorbingRemoteEvents() {
|
|
39
|
-
const serverEvents = new server_events_1.ServerEvents(() => this.remoteStorage.openEventSource(this.logError)
|
|
40
|
-
// SERVER_EVENTS_RESTART_WAIT_SECS,
|
|
41
|
-
this.logError);
|
|
39
|
+
const serverEvents = new server_events_1.ServerEvents(() => this.remoteStorage.openEventSource(this.logError));
|
|
42
40
|
this.absorbingRemoteEventsProc = (0, rxjs_1.merge)(this.absorbObjChange(serverEvents), this.absorbObjRemoval(serverEvents),
|
|
43
41
|
// XXX commenting out to see if unknownEvent exception goes away
|
|
44
42
|
// Is server doesn't know it?
|
|
@@ -67,9 +67,8 @@ class MailRecipient extends user_with_mid_session_1.ServiceUser {
|
|
|
67
67
|
return this.net;
|
|
68
68
|
}
|
|
69
69
|
async listMsgs(fromTS) {
|
|
70
|
-
// XXX modify request to take fromTS parameter to limit number of msgs
|
|
71
70
|
const rep = await this.doBodylessSessionRequest({
|
|
72
|
-
appPath: api.listMsgs.
|
|
71
|
+
appPath: api.listMsgs.genUrlEnd(fromTS ? { from: fromTS } : undefined),
|
|
73
72
|
method: 'GET',
|
|
74
73
|
responseType: 'json'
|
|
75
74
|
});
|