core-3nweb-client-lib 0.49.2 → 0.49.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.
@@ -154,8 +154,11 @@ class Delivery {
154
154
  }
155
155
  const attachments = common_1.Attachments.fromMsg(msgToSend);
156
156
  const localMeta = opts === null || opts === void 0 ? void 0 : opts.localMeta;
157
- // DEBUG console to help capturing a bug
158
- console.log(`Sending msg with delivery id ${id} ${attachments ? `with attachments` : `without attachments`}`);
157
+ // DEBUG log
158
+ console.log(`\n adding message ${msgToSend.attachments ? `with attachments: ${{
159
+ files: msgToSend.attachments.files ? Object.keys(msgToSend.attachments.files).length : 0,
160
+ folders: msgToSend.attachments.folders ? Object.keys(msgToSend.attachments.folders).length : 0
161
+ }}` : `without attachments in outgoing msg object.`}`);
159
162
  // save msg, in case delivery should be restarted
160
163
  const msgFS = await this.makeFSForNewMsg(id);
161
164
  const msg = await msg_1.Msg.forNew(id, msgFS, msgToSend, sender, recipients, this.r, attachments, localMeta, opts === null || opts === void 0 ? void 0 : opts.retryRecipient);
@@ -128,7 +128,11 @@ class Msg {
128
128
  await this.msgFS.writeJSONFile(MAIN_OBJ_FILE_NAME, main, { create: true, exclusive: true });
129
129
  await this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, { create: true, exclusive: true });
130
130
  if (this.attachments) {
131
- await this.attachments.linkIn(this.msgFS);
131
+ console.log(`Linking attachments ...`);
132
+ await this.attachments.linkIn(this.msgFS)
133
+ .then(
134
+ // DEBUG log
135
+ () => console.log(` .... msg attachments linked while delivery`), err => console.error(`linking attachments error:`, err));
132
136
  }
133
137
  }
134
138
  notifyOfChangesInProgress(saveProgress, saveWIPs) {
@@ -189,6 +193,8 @@ class Msg {
189
193
  msg.setSection('Cc', this.msgToSend.carbonCopy);
190
194
  msg.setSection('To', this.msgToSend.recipients);
191
195
  if (this.attachments) {
196
+ // DEBUG log
197
+ console.log(`setting attachment on messages packer`);
192
198
  await msg.setAttachments(this.attachments);
193
199
  }
194
200
  return msg;
@@ -39,8 +39,7 @@ class WIP {
39
39
  this.packer = undefined;
40
40
  this.currentObjIndInMeta = 0;
41
41
  this.currentObj = undefined;
42
- this.doStateRecording =
43
- (this.msg.progress.msgSize > MSG_SIZE_FOR_STATE_RECORDING);
42
+ this.doStateRecording = (this.msg.progress.msgSize > MSG_SIZE_FOR_STATE_RECORDING);
44
43
  Object.seal(this);
45
44
  }
46
45
  /**
@@ -81,6 +80,7 @@ class WIP {
81
80
  * or if this wip is done, undefined is returned.
82
81
  */
83
82
  startNext() {
83
+ var _a, _b;
84
84
  let proc = this.proc.latestTaskAtThisMoment();
85
85
  if (proc) {
86
86
  return;
@@ -102,9 +102,13 @@ class WIP {
102
102
  proc = this.proc.addStarted(this.sendObjs());
103
103
  }
104
104
  else if (stage === "cancel") {
105
+ // DEBUG log
106
+ console.log(` canceled sending msgId: ${(_a = this.state.session) === null || _a === void 0 ? void 0 : _a.msgId}`);
105
107
  return;
106
108
  }
107
109
  else if (stage === undefined) {
110
+ // DEBUG log
111
+ console.log(` done sending msgId: ${(_b = this.state.session) === null || _b === void 0 ? void 0 : _b.msgId}`);
108
112
  return;
109
113
  }
110
114
  else {
@@ -160,6 +164,8 @@ class WIP {
160
164
  async getRecipientKeyAndEncrypt() {
161
165
  const recipient = this.sender.recipient;
162
166
  const introPKeyFromServer = await this.getIntroKeyIfRecipientIsUnknown(recipient);
167
+ // DEBUG log
168
+ console.log(`\n wip.getRecipientKeyAndEncrypt()`);
163
169
  this.packer = await this.msg.msgPacker();
164
170
  // get crypto parts for encrypting this message
165
171
  const { currentPair, encryptor, msgCount } = await this.msg.r.correspondents.generateKeysToSend(recipient, introPKeyFromServer);
@@ -187,7 +193,7 @@ class WIP {
187
193
  this.packer.setNextSendingParams(nextSendingParams);
188
194
  }
189
195
  // pack the message
190
- this.state.pack = await this.packer.pack();
196
+ this.state.pack = this.packer.pack();
191
197
  // initialize uploads info
192
198
  this.state.objUploads = new Array(this.state.pack.meta.objIds.length);
193
199
  this.state.objUploads.fill(null);
@@ -256,8 +262,9 @@ class WIP {
256
262
  throw new Error(`Message pack is not set.`);
257
263
  }
258
264
  this.state.session = await this.sender.sendMetadata(this.state.pack.meta);
259
- this.msg.progress.recipients[this.state.recipient].idOnDelivery =
260
- this.state.session.msgId;
265
+ // DEBUG log
266
+ console.log(`\n wip.sendMeta() returned with\n msgId: ${this.state.session.msgId}\n meta.objIds sent to server:`, this.state.pack.meta.objIds);
267
+ this.msg.progress.recipients[this.state.recipient].idOnDelivery = this.state.session.msgId;
261
268
  if (this.state.stage !== "cancel") {
262
269
  this.state.stage = "5-send-objs";
263
270
  }
@@ -310,6 +317,9 @@ class WIP {
310
317
  return { objId, upload, src };
311
318
  }
312
319
  async completeDelivery() {
320
+ var _a;
321
+ // DEBUG log
322
+ console.log(` wip.completeDelivery() msg ${!!((_a = this.state.session) === null || _a === void 0 ? void 0 : _a.msgId)}`);
313
323
  await this.sender.completeDelivery();
314
324
  this.updateInfo(0, true);
315
325
  this.state.stage = undefined;
@@ -329,12 +339,17 @@ class WIP {
329
339
  * completes sending, when no more sending is left.
330
340
  */
331
341
  async sendObjs() {
342
+ var _a, _b, _c;
343
+ // DEBUG log
344
+ console.log(` wip.sendObjs(), msgId: ${(_a = this.state.session) === null || _a === void 0 ? void 0 : _a.msgId}, p 0, \n !!this.sender is ${!!this.sender}\n this.currentObj is ${(_b = this.currentObj) === null || _b === void 0 ? void 0 : _b.objId}`);
332
345
  if (!this.sender) {
333
346
  this.sender = await sender_1.MailSender.resume(this.msg.r.makeNet(), this.state.recipient, this.state.session);
334
347
  }
335
348
  // ensure there is an object to send, or complete delivery
336
349
  if (!this.currentObj) {
337
350
  this.currentObj = await this.getObjToSend();
351
+ // DEBUG log
352
+ console.log(` ... this.getObjToSend() sets currentObj to be ${(_c = this.currentObj) === null || _c === void 0 ? void 0 : _c.objId}`);
338
353
  if (!this.currentObj) {
339
354
  return this.completeDelivery();
340
355
  }
@@ -362,6 +377,8 @@ class WIP {
362
377
  * @param obj is a message object to send
363
378
  */
364
379
  async firstObjSendingRequest(obj) {
380
+ // DEBUG log
381
+ console.log(` wip.firstObjSendingRequest() ${obj.objId}`);
365
382
  // read from source
366
383
  const header = await obj.src.readHeader();
367
384
  const { size, isEndless } = await obj.src.segSrc.getSize();
@@ -393,6 +410,8 @@ class WIP {
393
410
  obj.upload.header = buffer_utils_1.base64.pack(header);
394
411
  }
395
412
  this.updateInfo(header.length + segsChunk.length);
413
+ // DEBUG log
414
+ console.log(` ... ${obj.objId} 1st/single obj request send, isObjDone is ${isObjDone}`);
396
415
  return isObjDone;
397
416
  }
398
417
  /**
@@ -402,12 +421,16 @@ class WIP {
402
421
  * @param obj is a message object to send
403
422
  */
404
423
  async followingObjSendingRequest(obj) {
424
+ // DEBUG log
425
+ console.log(` wip.followingObjSendingRequest() ${obj.objId}`);
405
426
  // read from source
406
427
  const segsSize = obj.upload.expectedSegsSize;
407
428
  const chunk = await obj.src.segSrc.readNext(this.sender.maxChunkSize);
408
429
  // return early, when there are no bytes
409
430
  if (!chunk) {
410
431
  await this.sender.sendObj(obj.objId, EMPTY_BYTE_ARR, undefined, { ofs: obj.upload.segsOffset, last: true });
432
+ // DEBUG log
433
+ console.log(` ... ${obj.objId} 2nd/following obj request has no more chunk to send, and completed sending obj`);
411
434
  return true;
412
435
  }
413
436
  // check for an overrun
@@ -427,6 +450,8 @@ class WIP {
427
450
  await this.sender.sendObj(obj.objId, chunk, undefined, opts);
428
451
  obj.upload.segsOffset += chunk.length;
429
452
  this.updateInfo(chunk.length);
453
+ // DEBUG log
454
+ console.log(` ... ${obj.objId} 2nd/following obj request sent ${chunk.length} bytes, isObjDone is ${isObjDone}`);
430
455
  return isObjDone;
431
456
  }
432
457
  }
@@ -129,6 +129,6 @@ export declare class MsgPacker {
129
129
  getNewSrcForObj(objId: string, cryptor: AsyncSBoxCryptor): Promise<ObjSource>;
130
130
  getRestartedSrcForObj(objId: string, header: Uint8Array, offset: number, cryptor: AsyncSBoxCryptor): Promise<ObjSource>;
131
131
  private getSrcForNonMainObj;
132
- pack(): Promise<PackJSON>;
132
+ pack(): PackJSON;
133
133
  }
134
134
  export {};
@@ -238,9 +238,7 @@ class MsgPacker {
238
238
  if (this.meta) {
239
239
  throw new Error("Message metadata has already been set.");
240
240
  }
241
- this.meta = {
242
- pid: pid,
243
- };
241
+ this.meta = { pid };
244
242
  this.main['Flow Params'].msgCount = msgCount;
245
243
  Object.freeze(this.meta);
246
244
  }
@@ -333,6 +331,8 @@ class MsgPacker {
333
331
  if (this.hasAttachments) {
334
332
  this.main['Attachments'] = attachments;
335
333
  }
334
+ // DEBUG log
335
+ console.log(` message packer allObjs has ${this.allObjs.size} items`);
336
336
  }
337
337
  throwupOnMissingParts() {
338
338
  if (!this.meta) {
@@ -341,8 +341,7 @@ class MsgPacker {
341
341
  if (!this.wasBodySet) {
342
342
  throw new Error("Message Body is not set.");
343
343
  }
344
- if (this.meta.senderPKey &&
345
- !this.main['Flow Params'].introCerts) {
344
+ if (this.meta.senderPKey && !this.main['Flow Params'].introCerts) {
346
345
  throw new Error("Sender's key certification is missing.");
347
346
  }
348
347
  }
@@ -365,16 +364,14 @@ class MsgPacker {
365
364
  if (this.attachmentsCont) {
366
365
  const fName = path.path[0];
367
366
  if (path.path.length === 1) {
368
- const file = (this.attachmentsCont.files ?
369
- this.attachmentsCont.files[fName] : undefined);
367
+ const file = (this.attachmentsCont.files ? this.attachmentsCont.files[fName] : undefined);
370
368
  if (!file) {
371
369
  throw new Error(`File ${fName} is not found in attachments.`);
372
370
  }
373
371
  return file.getByteSource();
374
372
  }
375
373
  else {
376
- const fs = (this.attachmentsCont.folders ?
377
- this.attachmentsCont.folders[fName] : undefined);
374
+ const fs = (this.attachmentsCont.folders ? this.attachmentsCont.folders[fName] : undefined);
378
375
  if (!fs) {
379
376
  throw new Error(`Folder ${fName} is not found in attachments.`);
380
377
  }
@@ -440,7 +437,7 @@ class MsgPacker {
440
437
  }
441
438
  return src;
442
439
  }
443
- async pack() {
440
+ pack() {
444
441
  if (this.readyPack) {
445
442
  return this.readyPack;
446
443
  }
@@ -451,10 +451,6 @@ class MailSender {
451
451
  }
452
452
  }
453
453
  else if (rep.status === api.msgObj.SC.ok) {
454
- // DEBUG console to help capturing a bug
455
- if ((fstReq === null || fstReq === void 0 ? void 0 : fstReq.last) || (followReq === null || followReq === void 0 ? void 0 : followReq.last)) {
456
- console.log(`sent obj ${objId} within msg ${this.msgId}`);
457
- }
458
454
  // normal return
459
455
  return;
460
456
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.49.2",
3
+ "version": "0.49.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",