core-3nweb-client-lib 0.50.3 → 0.50.4

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.
@@ -297,6 +297,7 @@ declare namespace web3n.asmail {
297
297
  msgId: string;
298
298
  msgNotFound?: true;
299
299
  incompleteDelivery?: true;
300
+ deliveryStart?: number;
300
301
  objNotFound?: true;
301
302
  objId?: string;
302
303
  msgIsBroken?: true;
@@ -87,16 +87,13 @@ class InboxEvents {
87
87
  async whenConnected() {
88
88
  return this.msgReceiver.connectedState.whenStateIsSet();
89
89
  }
90
- async getMessage(msgId) {
91
- try {
92
- return await this.getMsg(msgId);
93
- }
94
- catch (err) {
95
- // XXX we need to skip, if it is a connectivity error here;
96
- // should we remove on non-connectivity error
97
- // await this.rmMsg(msgId).catch(noop);
98
- await this.logError(err, `Cannot get message ${msgId}`);
99
- }
90
+ getMessage(msgId) {
91
+ return this.getMsg(msgId).catch(async (exc) => {
92
+ if ((exc.type === 'connect') || (exc.type === 'inbox')) {
93
+ return undefined;
94
+ }
95
+ await this.logError(exc, `Cannot get message ${msgId}`);
96
+ });
100
97
  }
101
98
  subscribe(event, observer) {
102
99
  if (event === 'message') {
@@ -83,7 +83,7 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
83
83
  if (msgOnDisk) {
84
84
  return msgOnDisk;
85
85
  }
86
- const meta = await downloader.getMsgMeta(msgId);
86
+ const meta = await downloader.getMsgMeta(msgId, false);
87
87
  return await cache.addMsg(msgId, meta);
88
88
  }
89
89
  function checkerOfMidKeyCerts(deliveryTS) {
@@ -201,7 +201,9 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
201
201
  }
202
202
  await Promise.all(msgIds.map(msgId => startCachingAndAddKeyToIndex(msgId)
203
203
  .catch(async (exc) => {
204
- await logError(exc, `Failed to start caching message ${msgId}`);
204
+ if (!exc.incompleteDelivery && !exc.msgNotFound) {
205
+ await logError(exc, `Failed to start caching message ${msgId}`);
206
+ }
205
207
  })));
206
208
  return index.listMsgs(fromTS);
207
209
  });
@@ -220,7 +222,12 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
220
222
  return [];
221
223
  }
222
224
  // cache and index these
223
- await Promise.all(msgIds.map(msgId => startCachingAndAddKeyToIndex(msgId)));
225
+ await Promise.all(msgIds.map(msgId => startCachingAndAddKeyToIndex(msgId)
226
+ .catch(async (exc) => {
227
+ if (!exc.incompleteDelivery && !exc.msgNotFound) {
228
+ await logError(exc, `Failed to start caching message ${msgId}`);
229
+ }
230
+ })));
224
231
  // get info's from index, focusing on specific messages only
225
232
  return (await index.listMsgs(fromTS)).filter(({ msgId }) => msgIds.includes(msgId));
226
233
  }
@@ -5,7 +5,7 @@ export declare class MsgDownloader {
5
5
  private readonly msgReceiver;
6
6
  private readonly runner;
7
7
  constructor(msgReceiver: MailRecipient);
8
- getMsgMeta(msgId: string): Promise<MsgMeta>;
8
+ getMsgMeta(msgId: string, allowIncomplete: boolean): Promise<MsgMeta>;
9
9
  getObjDownloader(msgId: string): ObjDownloader;
10
10
  private getLayoutWithHeaderAndFirstSegs;
11
11
  private getSegs;
@@ -17,8 +17,8 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.MsgDownloader = void 0;
20
+ const recipient_1 = require("../../../lib-client/asmail/recipient");
20
21
  const obj_on_disk_1 = require("../../../lib-client/objs-on-disk/obj-on-disk");
21
- const sleep_1 = require("../../../lib-common/processes/sleep");
22
22
  const MAX_GETTING_CHUNK = 512 * 1024;
23
23
  const DOWNLOAD_START_CHUNK = 128 * 1024;
24
24
  class MsgDownloader {
@@ -27,23 +27,19 @@ class MsgDownloader {
27
27
  this.runner = new obj_on_disk_1.DownloadsRunner();
28
28
  Object.freeze(this);
29
29
  }
30
- async getMsgMeta(msgId) {
31
- let lastExc = undefined;
32
- for (let attemptNum = 0; attemptNum < 10; attemptNum += 1) {
33
- try {
34
- return await this.msgReceiver.getMsgMeta(msgId, false);
35
- }
36
- catch (exc) {
37
- if (exc.incompleteDelivery) {
38
- lastExc = exc;
39
- }
40
- else {
41
- throw exc;
30
+ async getMsgMeta(msgId, allowIncomplete) {
31
+ return await this.msgReceiver.getMsgMeta(msgId, allowIncomplete)
32
+ .catch(async (exc) => {
33
+ if (exc.incompleteDelivery) {
34
+ // cleanout old incomplete messages
35
+ const deliveryStart = exc.deliveryStart;
36
+ if (!(Math.abs(Date.now() - deliveryStart) < 12 * 60 * 60 * 1000)) {
37
+ await this.msgReceiver.removeMsg(msgId).catch(noop);
38
+ throw (0, recipient_1.makeMsgNotFoundException)(msgId);
42
39
  }
43
40
  }
44
- await (0, sleep_1.sleep)((attemptNum < 2) ? 500 : attemptNum * 2000);
45
- }
46
- throw lastExc;
41
+ throw exc;
42
+ });
47
43
  }
48
44
  getObjDownloader(msgId) {
49
45
  return {
@@ -68,4 +64,5 @@ class MsgDownloader {
68
64
  exports.MsgDownloader = MsgDownloader;
69
65
  Object.freeze(MsgDownloader.prototype);
70
66
  Object.freeze(MsgDownloader);
67
+ function noop() { }
71
68
  Object.freeze(exports);
@@ -192,7 +192,7 @@ async function setMsgIndexInfoIntoAttrOf(dbFile, info) {
192
192
  });
193
193
  }
194
194
  function dbFileName(shardTS) {
195
- return (shardTS ? LATEST_DB : `${shardTS}${DB_EXT}`);
195
+ return (shardTS ? `${shardTS}${DB_EXT}` : LATEST_DB);
196
196
  }
197
197
  function shardTSFromFileName(fName) {
198
198
  if (fName.endsWith(DB_EXT)) {
@@ -5,7 +5,7 @@ import { SubscribingClient } from '../../lib-common/ipc/ws-ipc';
5
5
  type InboxException = web3n.asmail.InboxException;
6
6
  type Observer<T> = web3n.Observer<T>;
7
7
  export declare function makeMsgNotFoundException(msgId: string): InboxException;
8
- export declare function makeMsgIncompleteException(msgId: string): InboxException;
8
+ export declare function makeMsgIncompleteException(msgId: string, deliveryStart: number): InboxException;
9
9
  export declare function makeFailToDecryptMsgException(msgId: string): InboxException;
10
10
  export declare function makeObjNotFoundException(msgId: string, objId: string): InboxException;
11
11
  export declare function makeMsgIsBrokenException(msgId: string): InboxException;
@@ -39,12 +39,13 @@ function makeMsgNotFoundException(msgId) {
39
39
  };
40
40
  return exc;
41
41
  }
42
- function makeMsgIncompleteException(msgId) {
42
+ function makeMsgIncompleteException(msgId, deliveryStart) {
43
43
  const exc = {
44
44
  runtimeException: true,
45
45
  type: 'inbox',
46
46
  msgId,
47
47
  incompleteDelivery: true,
48
+ deliveryStart,
48
49
  stack: (0, runtime_1.getStackHere)(1)
49
50
  };
50
51
  return exc;
@@ -116,8 +117,9 @@ class MailRecipient extends user_with_mid_session_1.ServiceUser {
116
117
  responseType: 'json'
117
118
  });
118
119
  if (rep.status === api.msgMetadata.SC.ok) {
119
- if (!allowIncomplete && !rep.data.deliveryCompletion) {
120
- throw makeMsgIncompleteException(msgId);
120
+ if (!rep.data.deliveryCompletion && !allowIncomplete) {
121
+ const { deliveryStart } = rep.data;
122
+ throw makeMsgIncompleteException(msgId, deliveryStart);
121
123
  }
122
124
  const { meta, errMsg } = api.sanitizedMeta(rep.data, allowIncomplete);
123
125
  if (!meta) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.50.3",
3
+ "version": "0.50.4",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",