core-3nweb-client-lib 0.49.4 → 0.49.6
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,11 +154,6 @@ 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 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.`}`);
|
|
162
157
|
// save msg, in case delivery should be restarted
|
|
163
158
|
const msgFS = await this.makeFSForNewMsg(id);
|
|
164
159
|
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);
|
|
@@ -65,7 +65,6 @@ class Msg {
|
|
|
65
65
|
this.msgFS = msgFS;
|
|
66
66
|
this.sendingProc = new synced_1.SingleProc();
|
|
67
67
|
this.completionPromise = undefined;
|
|
68
|
-
// private readonly progressSavingProc = new SingleProc();
|
|
69
68
|
this.cancelled = false;
|
|
70
69
|
this.sender = undefined;
|
|
71
70
|
this.recipients = undefined;
|
|
@@ -128,11 +127,7 @@ class Msg {
|
|
|
128
127
|
await this.msgFS.writeJSONFile(MAIN_OBJ_FILE_NAME, main, { create: true, exclusive: true });
|
|
129
128
|
await this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, { create: true, exclusive: true });
|
|
130
129
|
if (this.attachments) {
|
|
131
|
-
|
|
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));
|
|
130
|
+
await this.attachments.linkIn(this.msgFS);
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
133
|
notifyOfChangesInProgress(saveProgress, saveWIPs) {
|
|
@@ -193,8 +188,6 @@ class Msg {
|
|
|
193
188
|
msg.setSection('Cc', this.msgToSend.carbonCopy);
|
|
194
189
|
msg.setSection('To', this.msgToSend.recipients);
|
|
195
190
|
if (this.attachments) {
|
|
196
|
-
// DEBUG log
|
|
197
|
-
console.log(`setting attachment on messages packer`);
|
|
198
191
|
await msg.setAttachments(this.attachments);
|
|
199
192
|
}
|
|
200
193
|
return msg;
|
|
@@ -80,7 +80,6 @@ class WIP {
|
|
|
80
80
|
* or if this wip is done, undefined is returned.
|
|
81
81
|
*/
|
|
82
82
|
startNext() {
|
|
83
|
-
var _a, _b;
|
|
84
83
|
let proc = this.proc.latestTaskAtThisMoment();
|
|
85
84
|
if (proc) {
|
|
86
85
|
return;
|
|
@@ -102,13 +101,9 @@ class WIP {
|
|
|
102
101
|
proc = this.proc.addStarted(this.sendObjs());
|
|
103
102
|
}
|
|
104
103
|
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}`);
|
|
107
104
|
return;
|
|
108
105
|
}
|
|
109
106
|
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}`);
|
|
112
107
|
return;
|
|
113
108
|
}
|
|
114
109
|
else {
|
|
@@ -164,8 +159,6 @@ class WIP {
|
|
|
164
159
|
async getRecipientKeyAndEncrypt() {
|
|
165
160
|
const recipient = this.sender.recipient;
|
|
166
161
|
const introPKeyFromServer = await this.getIntroKeyIfRecipientIsUnknown(recipient);
|
|
167
|
-
// DEBUG log
|
|
168
|
-
console.log(`\n wip.getRecipientKeyAndEncrypt()`);
|
|
169
162
|
this.packer = await this.msg.msgPacker();
|
|
170
163
|
// get crypto parts for encrypting this message
|
|
171
164
|
const { currentPair, encryptor, msgCount } = await this.msg.r.correspondents.generateKeysToSend(recipient, introPKeyFromServer);
|
|
@@ -262,8 +255,6 @@ class WIP {
|
|
|
262
255
|
throw new Error(`Message pack is not set.`);
|
|
263
256
|
}
|
|
264
257
|
this.state.session = await this.sender.sendMetadata(this.state.pack.meta);
|
|
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
258
|
this.msg.progress.recipients[this.state.recipient].idOnDelivery = this.state.session.msgId;
|
|
268
259
|
if (this.state.stage !== "cancel") {
|
|
269
260
|
this.state.stage = "5-send-objs";
|
|
@@ -317,9 +308,6 @@ class WIP {
|
|
|
317
308
|
return { objId, upload, src };
|
|
318
309
|
}
|
|
319
310
|
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)}`);
|
|
323
311
|
await this.sender.completeDelivery();
|
|
324
312
|
this.updateInfo(0, true);
|
|
325
313
|
this.state.stage = undefined;
|
|
@@ -339,17 +327,12 @@ class WIP {
|
|
|
339
327
|
* completes sending, when no more sending is left.
|
|
340
328
|
*/
|
|
341
329
|
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}`);
|
|
345
330
|
if (!this.sender) {
|
|
346
331
|
this.sender = await sender_1.MailSender.resume(this.msg.r.makeNet(), this.state.recipient, this.state.session);
|
|
347
332
|
}
|
|
348
333
|
// ensure there is an object to send, or complete delivery
|
|
349
334
|
if (!this.currentObj) {
|
|
350
335
|
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}`);
|
|
353
336
|
if (!this.currentObj) {
|
|
354
337
|
return this.completeDelivery();
|
|
355
338
|
}
|
|
@@ -377,8 +360,6 @@ class WIP {
|
|
|
377
360
|
* @param obj is a message object to send
|
|
378
361
|
*/
|
|
379
362
|
async firstObjSendingRequest(obj) {
|
|
380
|
-
// DEBUG log
|
|
381
|
-
console.log(` wip.firstObjSendingRequest() ${obj.objId}`);
|
|
382
363
|
// read from source
|
|
383
364
|
const header = await obj.src.readHeader();
|
|
384
365
|
const { size, isEndless } = await obj.src.segSrc.getSize();
|
|
@@ -410,8 +391,6 @@ class WIP {
|
|
|
410
391
|
obj.upload.header = buffer_utils_1.base64.pack(header);
|
|
411
392
|
}
|
|
412
393
|
this.updateInfo(header.length + segsChunk.length);
|
|
413
|
-
// DEBUG log
|
|
414
|
-
console.log(` ... ${obj.objId} 1st/single obj request send, isObjDone is ${isObjDone}`);
|
|
415
394
|
return isObjDone;
|
|
416
395
|
}
|
|
417
396
|
/**
|
|
@@ -421,16 +400,12 @@ class WIP {
|
|
|
421
400
|
* @param obj is a message object to send
|
|
422
401
|
*/
|
|
423
402
|
async followingObjSendingRequest(obj) {
|
|
424
|
-
// DEBUG log
|
|
425
|
-
console.log(` wip.followingObjSendingRequest() ${obj.objId}`);
|
|
426
403
|
// read from source
|
|
427
404
|
const segsSize = obj.upload.expectedSegsSize;
|
|
428
405
|
const chunk = await obj.src.segSrc.readNext(this.sender.maxChunkSize);
|
|
429
406
|
// return early, when there are no bytes
|
|
430
407
|
if (!chunk) {
|
|
431
408
|
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`);
|
|
434
409
|
return true;
|
|
435
410
|
}
|
|
436
411
|
// check for an overrun
|
|
@@ -450,8 +425,6 @@ class WIP {
|
|
|
450
425
|
await this.sender.sendObj(obj.objId, chunk, undefined, opts);
|
|
451
426
|
obj.upload.segsOffset += chunk.length;
|
|
452
427
|
this.updateInfo(chunk.length);
|
|
453
|
-
// DEBUG log
|
|
454
|
-
console.log(` ... ${obj.objId} 2nd/following obj request sent ${chunk.length} bytes, isObjDone is ${isObjDone}`);
|
|
455
428
|
return isObjDone;
|
|
456
429
|
}
|
|
457
430
|
}
|
|
@@ -4,6 +4,7 @@ import { FolderInJSON } from '../../../lib-client/xsp-fs/common';
|
|
|
4
4
|
import { MsgEnvelope, SuggestedNextKeyPair, SendingParams } from './common';
|
|
5
5
|
import { Encryptor } from '../../../lib-common/async-cryptor-wrap';
|
|
6
6
|
import { AsyncRNG } from '../../../lib-common/rng-def';
|
|
7
|
+
import type { Attachments } from '../delivery/common';
|
|
7
8
|
type FS = web3n.files.FS;
|
|
8
9
|
type AttachmentsContainer = web3n.asmail.AttachmentsContainer;
|
|
9
10
|
type PKeyCertChain = web3n.keys.PKeyCertChain;
|
|
@@ -119,10 +120,7 @@ export declare class MsgPacker {
|
|
|
119
120
|
setNewKeyInfo(recipientKid: string, senderPKey: string, pkeyCerts: PKeyCertChain, msgCount: number): void;
|
|
120
121
|
setNextCrypto(pair: SuggestedNextKeyPair): void;
|
|
121
122
|
setNextSendingParams(params: SendingParams): void;
|
|
122
|
-
setAttachments(
|
|
123
|
-
fs: FS | undefined;
|
|
124
|
-
container: AttachmentsContainer | undefined;
|
|
125
|
-
}): Promise<void>;
|
|
123
|
+
setAttachments({ fs, container }: Attachments): Promise<void>;
|
|
126
124
|
private throwupOnMissingParts;
|
|
127
125
|
getSrcForMainObj(msgKeyEnc: Encryptor, cryptor: AsyncSBoxCryptor): Promise<ObjSource>;
|
|
128
126
|
private getFileByteSrc;
|
|
@@ -153,7 +153,7 @@ class MsgPacker {
|
|
|
153
153
|
const fPath = appendedPath(fsPath, fName);
|
|
154
154
|
if (entry.isFile) {
|
|
155
155
|
await fs.readonlyFile(fName);
|
|
156
|
-
this.addFileInto(folder, fName, fPath);
|
|
156
|
+
await this.addFileInto(folder, fName, fPath);
|
|
157
157
|
}
|
|
158
158
|
else if (entry.isFolder) {
|
|
159
159
|
const f = await fs.readonlySubRoot(fName);
|
|
@@ -281,7 +281,7 @@ class MsgPacker {
|
|
|
281
281
|
setNextSendingParams(params) {
|
|
282
282
|
this.main['Flow Params'].nextSendingParams = params;
|
|
283
283
|
}
|
|
284
|
-
async setAttachments(
|
|
284
|
+
async setAttachments({ fs, container }) {
|
|
285
285
|
this.throwIfAlreadyPacked();
|
|
286
286
|
if (this.hasAttachments) {
|
|
287
287
|
throw new Error(`Attachments are already set.`);
|
|
@@ -290,29 +290,29 @@ class MsgPacker {
|
|
|
290
290
|
const attachments = { nodes: {}, ctime: Date.now() };
|
|
291
291
|
// populate attachments json
|
|
292
292
|
const path = { start: 'attachments', path: [] };
|
|
293
|
-
if (
|
|
294
|
-
for (const f of (0, attachments_container_1.iterFilesIn)(
|
|
293
|
+
if (container && !(0, attachments_container_1.isContainerEmpty)(container)) {
|
|
294
|
+
for (const f of (0, attachments_container_1.iterFilesIn)(container)) {
|
|
295
295
|
const filePath = appendedPath(path, f.fileName);
|
|
296
|
-
this.addFileInto(attachments, f.fileName, filePath);
|
|
296
|
+
await this.addFileInto(attachments, f.fileName, filePath);
|
|
297
297
|
}
|
|
298
|
-
for (const f of (0, attachments_container_1.iterFoldersIn)(
|
|
298
|
+
for (const f of (0, attachments_container_1.iterFoldersIn)(container)) {
|
|
299
299
|
const fsPath = appendedPath(path, f.folderName);
|
|
300
300
|
await this.addFolderInto(attachments, f.folderName, f.folder, fsPath);
|
|
301
301
|
}
|
|
302
|
-
this.attachmentsCont =
|
|
302
|
+
this.attachmentsCont = container;
|
|
303
303
|
this.hasAttachments = true;
|
|
304
304
|
}
|
|
305
|
-
else if (
|
|
306
|
-
const list = await
|
|
305
|
+
else if (fs) {
|
|
306
|
+
const list = await fs.listFolder('.');
|
|
307
307
|
if (list.length > 0) {
|
|
308
308
|
for (const entry of list) {
|
|
309
309
|
const fName = entry.name;
|
|
310
310
|
const fPath = appendedPath(path, fName);
|
|
311
311
|
if (entry.isFile) {
|
|
312
|
-
this.addFileInto(attachments, fName, fPath);
|
|
312
|
+
await this.addFileInto(attachments, fName, fPath);
|
|
313
313
|
}
|
|
314
314
|
else if (entry.isFolder) {
|
|
315
|
-
const f = await
|
|
315
|
+
const f = await fs.readonlySubRoot(fName);
|
|
316
316
|
await this.addFolderInto(attachments, fName, f, fPath);
|
|
317
317
|
}
|
|
318
318
|
else {
|
|
@@ -320,7 +320,7 @@ class MsgPacker {
|
|
|
320
320
|
continue;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
this.attachmentsFS =
|
|
323
|
+
this.attachmentsFS = fs;
|
|
324
324
|
this.hasAttachments = true;
|
|
325
325
|
}
|
|
326
326
|
}
|
|
@@ -331,8 +331,6 @@ class MsgPacker {
|
|
|
331
331
|
if (this.hasAttachments) {
|
|
332
332
|
this.main['Attachments'] = attachments;
|
|
333
333
|
}
|
|
334
|
-
// DEBUG log
|
|
335
|
-
console.log(` message packer allObjs has ${this.allObjs.size} items`);
|
|
336
334
|
}
|
|
337
335
|
throwupOnMissingParts() {
|
|
338
336
|
if (!this.meta) {
|