core-3nweb-client-lib 0.25.6 → 0.27.0
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/README.md +2 -2
- package/build/api-defs/asmail.d.ts +1 -1
- package/build/api-defs/files.d.ts +282 -70
- package/build/core/app-files.js +7 -7
- package/build/core/asmail/config/common.js +4 -4
- package/build/core/asmail/config/index.js +2 -2
- package/build/core/asmail/config/published-intro-key.js +1 -1
- package/build/core/asmail/delivery/common.js +7 -7
- package/build/core/asmail/delivery/index.js +7 -6
- package/build/core/asmail/delivery/msg.js +8 -7
- package/build/core/asmail/delivery/per-recipient-wip.js +3 -3
- package/build/core/asmail/inbox/attachments/fs.js +11 -1
- package/build/core/asmail/inbox/cached-msgs.js +3 -3
- package/build/core/asmail/inbox/inbox-events.js +5 -4
- package/build/core/asmail/inbox/index.js +12 -12
- package/build/core/asmail/inbox/msg-downloader.js +3 -3
- package/build/core/asmail/inbox/msg-indexing.js +4 -4
- package/build/core/asmail/inbox/msg-on-disk.js +7 -7
- package/build/core/asmail/index.d.ts +3 -3
- package/build/core/asmail/index.js +13 -8
- package/build/core/asmail/key-verification.js +5 -5
- package/build/core/asmail/keyring/common.js +7 -6
- package/build/core/asmail/keyring/correspondent-keys.js +8 -7
- package/build/core/asmail/keyring/id-to-email-map.js +2 -1
- package/build/core/asmail/keyring/index.d.ts +7 -8
- package/build/core/asmail/keyring/index.js +15 -14
- package/build/core/asmail/keyring/keyring-storage.js +4 -3
- package/build/core/asmail/msg/opener.js +3 -3
- package/build/core/asmail/msg/packer.js +13 -13
- package/build/core/asmail/sending-params/own-params.js +4 -4
- package/build/core/asmail/sending-params/params-from-others.js +3 -3
- package/build/core/id-manager.js +8 -5
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +14 -14
- package/build/core/sign-in.d.ts +5 -4
- package/build/core/sign-in.js +12 -14
- package/build/core/sign-up.d.ts +1 -0
- package/build/core/sign-up.js +15 -11
- package/build/core/storage/common/json-saving.d.ts +21 -0
- package/build/core/storage/common/json-saving.js +82 -0
- package/build/core/storage/common/obj-info-file.d.ts +51 -0
- package/build/core/storage/common/obj-info-file.js +153 -5
- package/build/core/storage/common/utils.d.ts +2 -0
- package/build/core/storage/common/utils.js +32 -0
- package/build/core/storage/index.d.ts +3 -17
- package/build/core/storage/index.js +57 -77
- package/build/core/storage/local/obj-files-gc.d.ts +2 -0
- package/build/core/storage/local/obj-files-gc.js +53 -39
- package/build/core/storage/local/obj-files.d.ts +6 -9
- package/build/core/storage/local/obj-files.js +16 -19
- package/build/core/storage/local/obj-status.d.ts +20 -30
- package/build/core/storage/local/obj-status.js +46 -113
- package/build/core/storage/local/storage.d.ts +15 -5
- package/build/core/storage/local/storage.js +37 -18
- package/build/core/storage/synced/downloader.js +7 -6
- package/build/core/storage/synced/obj-files-gc.d.ts +6 -1
- package/build/core/storage/synced/obj-files-gc.js +106 -13
- package/build/core/storage/synced/obj-files.d.ts +46 -47
- package/build/core/storage/synced/obj-files.js +207 -154
- package/build/core/storage/synced/obj-status.d.ts +103 -42
- package/build/core/storage/synced/obj-status.js +525 -137
- package/build/core/storage/synced/remote-events.d.ts +11 -12
- package/build/core/storage/synced/remote-events.js +80 -57
- package/build/core/storage/synced/storage.d.ts +24 -5
- package/build/core/storage/synced/storage.js +123 -38
- package/build/core/storage/synced/upload-header-file.d.ts +4 -0
- package/build/core/storage/synced/upload-header-file.js +64 -0
- package/build/core/storage/synced/upsyncer.d.ts +15 -9
- package/build/core/storage/synced/upsyncer.js +219 -246
- package/build/core/storage/system-folders/apps-data.d.ts +16 -0
- package/build/core/storage/system-folders/apps-data.js +110 -0
- package/build/core/storage/system-folders/index.d.ts +18 -0
- package/build/core/storage/system-folders/index.js +77 -0
- package/build/core-ipc/common-caps.js +3 -3
- package/build/core-ipc/generic.js +8 -8
- package/build/core-ipc/startup-caps.js +2 -2
- package/build/cryptors.js +6 -2
- package/build/ipc-via-protobuf/asmail-cap.js +67 -83
- package/build/ipc-via-protobuf/bytes.js +16 -17
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +3 -0
- package/build/ipc-via-protobuf/connector-clients-side.js +62 -25
- package/build/ipc-via-protobuf/connector-services-side.js +10 -10
- package/build/ipc-via-protobuf/connector.js +4 -4
- package/build/ipc-via-protobuf/file.d.ts +48 -12
- package/build/ipc-via-protobuf/file.js +476 -120
- package/build/ipc-via-protobuf/fs.d.ts +8 -0
- package/build/ipc-via-protobuf/fs.js +592 -159
- package/build/ipc-via-protobuf/log-cap.js +2 -2
- package/build/ipc-via-protobuf/mailerid.js +3 -3
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
- package/build/ipc-via-protobuf/startup-cap.js +23 -23
- package/build/ipc-via-protobuf/storage-cap.js +12 -12
- package/build/ipc.js +7 -2
- package/build/lib-client/3nstorage/exceptions.d.ts +12 -8
- package/build/lib-client/3nstorage/exceptions.js +31 -10
- package/build/lib-client/3nstorage/service.d.ts +16 -2
- package/build/lib-client/3nstorage/service.js +109 -39
- package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
- package/build/lib-client/3nstorage/util/file-based-json.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +52 -14
- package/build/lib-client/3nstorage/xsp-fs/common.js +31 -16
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +18 -14
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
- package/build/lib-client/3nstorage/xsp-fs/file.js +74 -23
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +24 -11
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +599 -189
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +45 -9
- package/build/lib-client/3nstorage/xsp-fs/fs.js +326 -74
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -20
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +239 -106
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +18 -19
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +5 -5
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +56 -56
- package/build/lib-client/3nweb-signup.js +4 -4
- package/build/lib-client/asmail/recipient.js +15 -15
- package/build/lib-client/asmail/sender.js +22 -22
- package/build/lib-client/asmail/service-config.js +3 -3
- package/build/lib-client/cryptor/cryptor-in-worker.js +19 -17
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.js +4 -2
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.js +1 -1
- package/build/lib-client/cryptor/in-proc-wasm.js +7 -7
- package/build/lib-client/cryptor/worker-js.js +2 -2
- package/build/lib-client/cryptor/worker-wasm.js +2 -2
- package/build/lib-client/files-select.js +1 -1
- package/build/lib-client/files.d.ts +1 -1
- package/build/lib-client/files.js +71 -4
- package/build/lib-client/fs-collection.js +3 -2
- package/build/lib-client/fs-sync-utils.d.ts +5 -0
- package/build/lib-client/fs-sync-utils.js +61 -0
- package/build/lib-client/fs-view.d.ts +14 -0
- package/build/lib-client/fs-view.js +33 -0
- package/build/lib-client/key-derivation.js +1 -1
- package/build/lib-client/local-files/dev-file-sink.js +9 -9
- package/build/lib-client/local-files/dev-file-src.js +2 -2
- package/build/lib-client/local-files/device-fs.d.ts +1 -1
- package/build/lib-client/local-files/device-fs.js +56 -54
- package/build/lib-client/logging/log-to-file.d.ts +1 -1
- package/build/lib-client/logging/log-to-file.js +11 -11
- package/build/lib-client/mailer-id/login.js +7 -7
- package/build/lib-client/mailer-id/provisioner.js +12 -12
- package/build/lib-client/objs-on-disk/file-writing-proc.js +5 -5
- package/build/lib-client/objs-on-disk/obj-folders.js +33 -33
- package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
- package/build/lib-client/request-utils.d.ts +1 -0
- package/build/lib-client/request-utils.js +14 -14
- package/build/lib-client/server-events.d.ts +3 -3
- package/build/lib-client/server-events.js +12 -10
- package/build/lib-client/service-locator.js +10 -10
- package/build/lib-client/user-with-mid-session.js +7 -7
- package/build/lib-client/user-with-pkl-session.js +25 -25
- package/build/lib-client/ws-utils.js +3 -3
- package/build/lib-common/async-cryptor-wrap.js +4 -4
- package/build/lib-common/async-fs-node.d.ts +5 -3
- package/build/lib-common/async-fs-node.js +19 -18
- package/build/lib-common/byte-streaming/pipe.js +1 -1
- package/build/lib-common/byte-streaming/wrapping.js +17 -17
- package/build/lib-common/canonical-address.js +1 -1
- package/build/lib-common/exceptions/error.d.ts +1 -0
- package/build/lib-common/exceptions/error.js +7 -6
- package/build/lib-common/exceptions/file.js +10 -1
- package/build/lib-common/ipc/generic-ipc.js +2 -2
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/json-utils.js +2 -1
- package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
- package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
- package/build/lib-common/objs-on-disk/file-layout.js +130 -12
- package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
- package/build/lib-common/objs-on-disk/obj-file.js +99 -37
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/objs-on-disk/utils.js +4 -4
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
- package/build/lib-common/processes/deferred.d.ts +6 -0
- package/build/lib-common/processes/deferred.js +30 -0
- package/build/lib-common/processes/labelled-exec-pools.d.ts +33 -0
- package/build/lib-common/processes/labelled-exec-pools.js +141 -0
- package/build/lib-common/processes/pressure.d.ts +7 -0
- package/build/lib-common/processes/pressure.js +56 -0
- package/build/lib-common/processes/sleep.d.ts +1 -0
- package/build/lib-common/processes/sleep.js +26 -0
- package/build/lib-common/{processes.d.ts → processes/synced.d.ts} +0 -40
- package/build/lib-common/{processes.js → processes/synced.js} +187 -204
- package/build/lib-common/processes/timeout.d.ts +1 -0
- package/build/lib-common/processes/timeout.js +51 -0
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +100 -39
- package/build/lib-common/service-api/3nstorage/owner.js +85 -42
- package/build/lib-common/service-api/asmail/delivery.js +2 -2
- package/build/lib-common/service-api/asmail/retrieval.js +1 -1
- package/build/lib-common/timed-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.js +11 -0
- package/build/lib-common/utils-for-observables.d.ts +15 -1
- package/build/lib-common/utils-for-observables.js +70 -19
- package/build/lib-common/weak-cache.d.ts +1 -0
- package/build/lib-common/weak-cache.js +12 -1
- package/build/lib-index.d.ts +2 -1
- package/build/lib-index.js +10 -7
- package/build/protos/asmail.proto.js +12912 -7127
- package/build/protos/file.proto.js +4848 -2399
- package/build/protos/fs.proto.js +9230 -3445
- package/package.json +8 -7
- package/protos/file.proto +91 -11
- package/protos/fs.proto +107 -8
- package/build/core/storage/synced/upsync-status.d.ts +0 -41
- package/build/core/storage/synced/upsync-status.js +0 -158
|
@@ -26,7 +26,7 @@ class Attachments {
|
|
|
26
26
|
Object.freeze(this);
|
|
27
27
|
}
|
|
28
28
|
static fromMsg(msg) {
|
|
29
|
-
if (!attachments_container_1.isContainerEmpty(msg.attachments)) {
|
|
29
|
+
if (!(0, attachments_container_1.isContainerEmpty)(msg.attachments)) {
|
|
30
30
|
return new Attachments(msg.attachments, undefined);
|
|
31
31
|
}
|
|
32
32
|
return;
|
|
@@ -42,11 +42,11 @@ class Attachments {
|
|
|
42
42
|
const link = await msgFS.readLink(`${ATTACHMENTS_NAME}/${f.name}`);
|
|
43
43
|
if (link.isFile) {
|
|
44
44
|
const file = (await link.target());
|
|
45
|
-
attachments_container_1.addFileTo(container, file, f.name);
|
|
45
|
+
(0, attachments_container_1.addFileTo)(container, file, f.name);
|
|
46
46
|
}
|
|
47
47
|
else if (link.isFolder) {
|
|
48
48
|
const fs = (await link.target());
|
|
49
|
-
attachments_container_1.addFolderTo(container, fs, f.name);
|
|
49
|
+
(0, attachments_container_1.addFolderTo)(container, fs, f.name);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
return new Attachments(container, undefined);
|
|
@@ -63,10 +63,10 @@ class Attachments {
|
|
|
63
63
|
async linkIn(msgFS) {
|
|
64
64
|
if (this.container) {
|
|
65
65
|
await msgFS.makeFolder(ATTACHMENTS_NAME);
|
|
66
|
-
for (const f of attachments_container_1.iterFilesIn(this.container)) {
|
|
66
|
+
for (const f of (0, attachments_container_1.iterFilesIn)(this.container)) {
|
|
67
67
|
msgFS.link(`${ATTACHMENTS_NAME}/${f.fileName}`, f.file);
|
|
68
68
|
}
|
|
69
|
-
for (const f of attachments_container_1.iterFoldersIn(this.container)) {
|
|
69
|
+
for (const f of (0, attachments_container_1.iterFoldersIn)(this.container)) {
|
|
70
70
|
msgFS.link(`${ATTACHMENTS_NAME}/${f.folderName}`, f.folder);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -85,13 +85,13 @@ class Attachments {
|
|
|
85
85
|
async estimatedPackedSize() {
|
|
86
86
|
if (this.container) {
|
|
87
87
|
let totalSize = 0;
|
|
88
|
-
for (const f of attachments_container_1.iterFilesIn(this.container)) {
|
|
88
|
+
for (const f of (0, attachments_container_1.iterFilesIn)(this.container)) {
|
|
89
89
|
const fileSize = (await f.file.stat()).size;
|
|
90
90
|
if (typeof fileSize === 'number') {
|
|
91
91
|
totalSize += await estimatePackedSizeOf(fileSize);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
for (const f of attachments_container_1.iterFoldersIn(this.container)) {
|
|
94
|
+
for (const f of (0, attachments_container_1.iterFoldersIn)(this.container)) {
|
|
95
95
|
totalSize += await estimatePackedSizeOfFolder(f.folder);
|
|
96
96
|
}
|
|
97
97
|
return totalSize;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2017, 2020 -
|
|
3
|
+
Copyright (C) 2016 - 2017, 2020 - 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -24,6 +24,7 @@ const common_1 = require("./common");
|
|
|
24
24
|
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
25
25
|
const rxjs_1 = require("rxjs");
|
|
26
26
|
const operators_1 = require("rxjs/operators");
|
|
27
|
+
const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
|
|
27
28
|
const SMALL_MSG_SIZE = 1024 * 1024;
|
|
28
29
|
const MSGS_FOLDER = 'msgs';
|
|
29
30
|
function idToMsgFolder(id) {
|
|
@@ -50,8 +51,8 @@ class Delivery {
|
|
|
50
51
|
*/
|
|
51
52
|
this.queuedDelivery = [];
|
|
52
53
|
this.allDeliveries = new rxjs_1.Subject();
|
|
53
|
-
this.allDeliveries$ = this.allDeliveries.asObservable().pipe(operators_1.share());
|
|
54
|
-
file_1.ensureCorrectFS(fs, 'local', true);
|
|
54
|
+
this.allDeliveries$ = this.allDeliveries.asObservable().pipe((0, operators_1.share)());
|
|
55
|
+
(0, file_1.ensureCorrectFS)(fs, 'local', true);
|
|
55
56
|
this.r.notifyMsgProgress =
|
|
56
57
|
(id, progress) => this.allDeliveries.next({ id, progress });
|
|
57
58
|
Object.freeze(this.r);
|
|
@@ -113,18 +114,18 @@ class Delivery {
|
|
|
113
114
|
}
|
|
114
115
|
if (msg.isDone()) {
|
|
115
116
|
if (observer.next) {
|
|
116
|
-
observer.next(json_utils_1.copy(msg.progress));
|
|
117
|
+
observer.next((0, json_utils_1.copy)(msg.progress));
|
|
117
118
|
}
|
|
118
119
|
if (observer.complete) {
|
|
119
120
|
observer.complete();
|
|
120
121
|
}
|
|
121
122
|
return () => { };
|
|
122
123
|
}
|
|
123
|
-
const subToProgress = msg.progress$.subscribe(observer);
|
|
124
|
+
const subToProgress = msg.progress$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
|
|
124
125
|
return () => { subToProgress.unsubscribe(); };
|
|
125
126
|
}
|
|
126
127
|
observeAllDeliveries(observer) {
|
|
127
|
-
const subToProgress = this.allDeliveries$.subscribe(observer);
|
|
128
|
+
const subToProgress = this.allDeliveries$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
|
|
128
129
|
return () => subToProgress.unsubscribe();
|
|
129
130
|
}
|
|
130
131
|
async preFlight(recipient) {
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.Msg = void 0;
|
|
19
19
|
const packer_1 = require("../msg/packer");
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
21
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
22
22
|
const common_1 = require("./common");
|
|
23
23
|
const per_recipient_wip_1 = require("./per-recipient-wip");
|
|
24
24
|
const rxjs_1 = require("rxjs");
|
|
25
25
|
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
26
|
+
const deferred_1 = require("../../../lib-common/processes/deferred");
|
|
26
27
|
const MAIN_OBJ_FILE_NAME = 'msg.json';
|
|
27
28
|
const PROGRESS_INFO_FILE_NAME = 'progress.json';
|
|
28
29
|
const WIPS_INFO_FILE_NAME = 'wips.json';
|
|
@@ -36,7 +37,7 @@ function checkIfAllRecipientsDone(progress) {
|
|
|
36
37
|
return true;
|
|
37
38
|
}
|
|
38
39
|
async function estimatedPackedSize(msgToSend, attachments) {
|
|
39
|
-
let totalSize = common_1.estimatePackedSizeOf(buffer_utils_1.utf8.pack(JSON.stringify(msgToSend)).length);
|
|
40
|
+
let totalSize = (0, common_1.estimatePackedSizeOf)(buffer_utils_1.utf8.pack(JSON.stringify(msgToSend)).length);
|
|
40
41
|
if (attachments) {
|
|
41
42
|
totalSize += await attachments.estimatedPackedSize();
|
|
42
43
|
}
|
|
@@ -48,9 +49,9 @@ class Msg {
|
|
|
48
49
|
this.r = r;
|
|
49
50
|
this.progress = progress;
|
|
50
51
|
this.msgFS = msgFS;
|
|
51
|
-
this.sendingProc = new
|
|
52
|
+
this.sendingProc = new synced_1.SingleProc();
|
|
52
53
|
this.completionPromise = undefined;
|
|
53
|
-
this.progressSavingProc = new
|
|
54
|
+
this.progressSavingProc = new synced_1.SingleProc();
|
|
54
55
|
this.cancelled = false;
|
|
55
56
|
this.sender = undefined;
|
|
56
57
|
this.recipients = undefined;
|
|
@@ -126,8 +127,8 @@ class Msg {
|
|
|
126
127
|
this.progress.allDone = true;
|
|
127
128
|
saveProgress = true;
|
|
128
129
|
}
|
|
129
|
-
this.r.notifyMsgProgress(this.id, json_utils_1.copy(this.progress));
|
|
130
|
-
this.progressPublisher.next(json_utils_1.copy(this.progress));
|
|
130
|
+
this.r.notifyMsgProgress(this.id, (0, json_utils_1.copy)(this.progress));
|
|
131
|
+
this.progressPublisher.next((0, json_utils_1.copy)(this.progress));
|
|
131
132
|
if (saveProgress) {
|
|
132
133
|
this.progressSavingProc.startOrChain(async () => {
|
|
133
134
|
await this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, {});
|
|
@@ -197,7 +198,7 @@ class Msg {
|
|
|
197
198
|
throw new Error(`Message delivery has already completed.`);
|
|
198
199
|
}
|
|
199
200
|
if (!this.completionPromise) {
|
|
200
|
-
this.completionPromise =
|
|
201
|
+
this.completionPromise = (0, deferred_1.defer)();
|
|
201
202
|
}
|
|
202
203
|
return this.completionPromise.promise;
|
|
203
204
|
}
|
|
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.WIP = void 0;
|
|
20
20
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
21
21
|
const sender_1 = require("../../../lib-client/asmail/sender");
|
|
22
|
-
const
|
|
22
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
23
23
|
const key_verification_1 = require("../key-verification");
|
|
24
24
|
const MSG_SIZE_FOR_STATE_RECORDING = 1024 * 1024;
|
|
25
25
|
const EMPTY_BYTE_ARR = new Uint8Array(0);
|
|
@@ -34,7 +34,7 @@ class WIP {
|
|
|
34
34
|
this.msg = msg;
|
|
35
35
|
this.state = state;
|
|
36
36
|
this.cryptor = cryptor;
|
|
37
|
-
this.proc = new
|
|
37
|
+
this.proc = new synced_1.SingleProc();
|
|
38
38
|
this.sender = undefined;
|
|
39
39
|
this.packer = undefined;
|
|
40
40
|
this.currentObjIndInMeta = 0;
|
|
@@ -205,7 +205,7 @@ class WIP {
|
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
207
|
const certs = await this.sender.getRecipientsInitPubKey();
|
|
208
|
-
return key_verification_1.checkAndExtractPKey(this.sender.net, this.msg.r.midResolver, recipient, certs).catch(err => {
|
|
208
|
+
return (0, key_verification_1.checkAndExtractPKey)(this.sender.net, this.msg.r.midResolver, recipient, certs).catch(err => {
|
|
209
209
|
const exc = {
|
|
210
210
|
runtimeException: true,
|
|
211
211
|
type: 'asmail-delivery',
|
|
@@ -27,8 +27,15 @@ class AttachmentStore {
|
|
|
27
27
|
this.type = 'asmail-msg';
|
|
28
28
|
this.versioned = false;
|
|
29
29
|
this.nodes = new common_1.NodesContainer();
|
|
30
|
+
this.connect = undefined;
|
|
30
31
|
Object.seal(this);
|
|
31
32
|
}
|
|
33
|
+
getNodeEvents() {
|
|
34
|
+
throw new Error(`Attachment's storage is readonly.`);
|
|
35
|
+
}
|
|
36
|
+
broadcastNodeEvent() {
|
|
37
|
+
throw new Error(`Attachment's storage is readonly.`);
|
|
38
|
+
}
|
|
32
39
|
storageForLinking(type, location) {
|
|
33
40
|
if (type === 'share') {
|
|
34
41
|
return this.getStorages('share', location);
|
|
@@ -37,10 +44,13 @@ class AttachmentStore {
|
|
|
37
44
|
throw new Error(`Attachment's storage cannot link to ${type} storage.`);
|
|
38
45
|
}
|
|
39
46
|
}
|
|
47
|
+
status() {
|
|
48
|
+
throw new Error(`Attachment's storage is not versioned`);
|
|
49
|
+
}
|
|
40
50
|
generateNewObjId() {
|
|
41
51
|
throw new Error(`Attachment's storage is readonly.`);
|
|
42
52
|
}
|
|
43
|
-
|
|
53
|
+
getObjSrc(objId) {
|
|
44
54
|
if (typeof objId !== 'string') {
|
|
45
55
|
throw new Error(`Attachment's storage uses only string objId's, while given parameter is: ${objId}`);
|
|
46
56
|
}
|
|
@@ -20,13 +20,13 @@ exports.CachedMessages = void 0;
|
|
|
20
20
|
const msg_on_disk_1 = require("./msg-on-disk");
|
|
21
21
|
const timed_cache_1 = require("../../../lib-common/timed-cache");
|
|
22
22
|
const obj_folders_1 = require("../../../lib-client/objs-on-disk/obj-folders");
|
|
23
|
-
const
|
|
23
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
24
24
|
class CachedMessages {
|
|
25
25
|
constructor(folders, downloader) {
|
|
26
26
|
this.folders = folders;
|
|
27
27
|
this.downloader = downloader;
|
|
28
|
-
this.syncProc = new
|
|
29
|
-
this.msgFiles = timed_cache_1.makeTimedCache(60 * 1000);
|
|
28
|
+
this.syncProc = new synced_1.NamedProcs();
|
|
29
|
+
this.msgFiles = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
30
30
|
Object.freeze(this);
|
|
31
31
|
}
|
|
32
32
|
static async makeFor(path, downloader, logError) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017, 2019 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2019, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -19,6 +19,7 @@ exports.InboxEvents = void 0;
|
|
|
19
19
|
const retrieval_1 = require("../../../lib-common/service-api/asmail/retrieval");
|
|
20
20
|
const server_events_1 = require("../../../lib-client/server-events");
|
|
21
21
|
const operators_1 = require("rxjs/operators");
|
|
22
|
+
const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
|
|
22
23
|
const SERVER_EVENTS_RESTART_WAIT_SECS = 30;
|
|
23
24
|
/**
|
|
24
25
|
* Instance of this class handles event subscription from UI side. It observes
|
|
@@ -29,16 +30,16 @@ class InboxEvents {
|
|
|
29
30
|
constructor(msgReceiver, getMsg, logError) {
|
|
30
31
|
const serverEvents = new server_events_1.ServerEvents(() => msgReceiver.openEventSource(), SERVER_EVENTS_RESTART_WAIT_SECS);
|
|
31
32
|
this.newMsg$ = serverEvents.observe(retrieval_1.msgRecievedCompletely.EVENT_NAME)
|
|
32
|
-
.pipe(operators_1.mergeMap(ev => getMsg(ev.msgId)
|
|
33
|
+
.pipe((0, operators_1.mergeMap)(ev => getMsg(ev.msgId)
|
|
33
34
|
.catch(async (err) => {
|
|
34
35
|
// TODO should more error handling logic be added here?
|
|
35
36
|
await logError(err, `Cannot get message ${ev.msgId}`);
|
|
36
|
-
})), operators_1.filter(msg => !!msg), operators_1.share());
|
|
37
|
+
})), (0, operators_1.filter)(msg => !!msg), (0, operators_1.share)());
|
|
37
38
|
Object.seal(this);
|
|
38
39
|
}
|
|
39
40
|
subscribe(event, observer) {
|
|
40
41
|
if (event === 'message') {
|
|
41
|
-
const subscription = this.newMsg$.subscribe(observer);
|
|
42
|
+
const subscription = this.newMsg$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
|
|
42
43
|
return () => subscription.unsubscribe();
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.InboxOnServer = void 0;
|
|
20
20
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
22
22
|
const recipient_1 = require("../../../lib-client/asmail/recipient");
|
|
23
23
|
const opener_1 = require("../msg/opener");
|
|
24
24
|
const msg_indexing_1 = require("./msg-indexing");
|
|
@@ -48,14 +48,14 @@ class InboxOnServer {
|
|
|
48
48
|
this.cache = cache;
|
|
49
49
|
this.index = index;
|
|
50
50
|
this.logError = logError;
|
|
51
|
-
this.procs = new
|
|
52
|
-
this.recentlyOpenedMsgs = timed_cache_1.makeTimedCache(60 * 1000);
|
|
51
|
+
this.procs = new synced_1.NamedProcs();
|
|
52
|
+
this.recentlyOpenedMsgs = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
53
53
|
this.inboxEvents = new inbox_events_1.InboxEvents(this.msgReceiver, this.getMsg.bind(this), this.logError);
|
|
54
54
|
Object.seal(this);
|
|
55
55
|
}
|
|
56
56
|
static async makeAndStart(cachePath, fs, r) {
|
|
57
57
|
try {
|
|
58
|
-
file_1.ensureCorrectFS(fs, 'synced', true);
|
|
58
|
+
(0, file_1.ensureCorrectFS)(fs, 'synced', true);
|
|
59
59
|
const msgReceiver = new recipient_1.MailRecipient(r.address, r.getSigner, () => r.asmailResolver(r.address), r.makeNet());
|
|
60
60
|
const downloader = new msg_downloader_1.MsgDownloader(msgReceiver);
|
|
61
61
|
const cache = await cached_msgs_1.CachedMessages.makeFor(cachePath, downloader, r.logError);
|
|
@@ -63,7 +63,7 @@ class InboxOnServer {
|
|
|
63
63
|
return new InboxOnServer(r.correspondents, msgReceiver, r.getStorages, r.cryptor, downloader, cache, index, r.logError);
|
|
64
64
|
}
|
|
65
65
|
catch (err) {
|
|
66
|
-
throw error_1.errWithCause(err, 'Failed to initialize Inbox');
|
|
66
|
+
throw (0, error_1.errWithCause)(err, 'Failed to initialize Inbox');
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
wrap() {
|
|
@@ -122,12 +122,12 @@ class InboxOnServer {
|
|
|
122
122
|
mainObjSrc = await msgOnDisk.getMsgObj(mainObjId);
|
|
123
123
|
}
|
|
124
124
|
const fKey = buffer_utils_1.base64.open(mainObjFileKey);
|
|
125
|
-
const openedMsg = await opener_1.openMsg(msgId, mainObjId, mainObjSrc, msgKeyPackLen, fKey, this.cryptor);
|
|
125
|
+
const openedMsg = await (0, opener_1.openMsg)(msgId, mainObjId, mainObjSrc, msgKeyPackLen, fKey, this.cryptor);
|
|
126
126
|
fKey.fill(0);
|
|
127
127
|
return openedMsg;
|
|
128
128
|
};
|
|
129
129
|
const checkMidKeyCerts = (certs) => {
|
|
130
|
-
return key_verification_1.checkAndExtractPKeyWithAddress(this.msgReceiver.getNet(), this.r.midResolver, certs, Math.round(msgOnDisk.deliveryTS / 1000));
|
|
130
|
+
return (0, key_verification_1.checkAndExtractPKeyWithAddress)(this.msgReceiver.getNet(), this.r.midResolver, certs, Math.round(msgOnDisk.deliveryTS / 1000));
|
|
131
131
|
};
|
|
132
132
|
const decrOut = await this.r.msgDecryptor(meta.extMeta, getMainObjHeader, getOpenedMsg, checkMidKeyCerts);
|
|
133
133
|
if (decrOut) {
|
|
@@ -183,7 +183,7 @@ class InboxOnServer {
|
|
|
183
183
|
// if sender authenticated to server, check that it matches address,
|
|
184
184
|
// recovered from message decryption
|
|
185
185
|
if (meta.authSender &&
|
|
186
|
-
!canonical_address_1.areAddressesEqual(meta.authSender, decrInfo.correspondent)) {
|
|
186
|
+
!(0, canonical_address_1.areAddressesEqual)(meta.authSender, decrInfo.correspondent)) {
|
|
187
187
|
throw new Error(`Sender authenticated to server as ${meta.authSender}, while decrypting key is associated with ${decrInfo.correspondent}`);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -252,7 +252,7 @@ class InboxOnServer {
|
|
|
252
252
|
// this.index.remove(msgInfo),
|
|
253
253
|
// this.removeMsgFromServerAndCache(msgId)
|
|
254
254
|
// ]);
|
|
255
|
-
throw recipient_1.makeMsgNotFoundException(msgId);
|
|
255
|
+
throw (0, recipient_1.makeMsgNotFoundException)(msgId);
|
|
256
256
|
}
|
|
257
257
|
else if (msgOnDisk.keyStatus === 'not-checked') {
|
|
258
258
|
await this.startCachingAndAddKeyToIndex(msgId);
|
|
@@ -265,9 +265,9 @@ class InboxOnServer {
|
|
|
265
265
|
const mainObj = await msgOnDisk.getMsgObj(mainObjId);
|
|
266
266
|
const msgKey = await this.index.fKeyFor({ msgId, deliveryTS: meta.deliveryCompletion });
|
|
267
267
|
if (!msgKey) {
|
|
268
|
-
throw recipient_1.makeMsgNotFoundException(msgId);
|
|
268
|
+
throw (0, recipient_1.makeMsgNotFoundException)(msgId);
|
|
269
269
|
}
|
|
270
|
-
msg = await opener_1.openMsg(msgId, mainObjId, mainObj, msgKey.mainObjHeaderOfs, msgKey.msgKey, this.cryptor);
|
|
270
|
+
msg = await (0, opener_1.openMsg)(msgId, mainObjId, mainObj, msgKey.mainObjHeaderOfs, msgKey.msgKey, this.cryptor);
|
|
271
271
|
msg.setMsgKeyRole(msgKey.msgKeyRole);
|
|
272
272
|
return this.msgToUIForm(msg, msgOnDisk.deliveryTS, msgOnDisk);
|
|
273
273
|
});
|
|
@@ -297,7 +297,7 @@ class InboxOnServer {
|
|
|
297
297
|
}
|
|
298
298
|
const attachments = msg.attachmentsJSON;
|
|
299
299
|
if (attachments) {
|
|
300
|
-
m.attachments = fs_1.fsForAttachments(msgOnDisk, attachments, this.storages, this.cryptor);
|
|
300
|
+
m.attachments = (0, fs_1.fsForAttachments)(msgOnDisk, attachments, this.storages, this.cryptor);
|
|
301
301
|
}
|
|
302
302
|
return m;
|
|
303
303
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.MsgDownloader = void 0;
|
|
19
|
-
const
|
|
19
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
20
20
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
21
21
|
const MAX_GETTING_CHUNK = 512 * 1024;
|
|
22
22
|
const DOWNLOAD_START_CHUNK = 128 * 1024;
|
|
@@ -32,7 +32,7 @@ class MsgDownloader {
|
|
|
32
32
|
* When it comes to the download start, if chain exists, it means that
|
|
33
33
|
* process has already started.
|
|
34
34
|
*/
|
|
35
|
-
this.downloadProcs = new
|
|
35
|
+
this.downloadProcs = new synced_1.NamedProcs();
|
|
36
36
|
Object.freeze(this);
|
|
37
37
|
}
|
|
38
38
|
async sync(msgId, objId, action) {
|
|
@@ -76,7 +76,7 @@ class MsgDownloader {
|
|
|
76
76
|
chunks.push(chunk);
|
|
77
77
|
ofs += chunk.length;
|
|
78
78
|
}
|
|
79
|
-
return buffer_utils_1.joinByteArrs(chunks);
|
|
79
|
+
return (0, buffer_utils_1.joinByteArrs)(chunks);
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.MsgIndex = void 0;
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
21
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
22
22
|
const timed_cache_1 = require("../../../lib-common/timed-cache");
|
|
23
23
|
const LIMIT_RECORDS_PER_FILE = 200;
|
|
@@ -97,9 +97,9 @@ class MsgIndex {
|
|
|
97
97
|
constructor(files) {
|
|
98
98
|
this.files = files;
|
|
99
99
|
this.latest = undefined;
|
|
100
|
-
this.cached = timed_cache_1.makeTimedCache(10 * 60 * 1000);
|
|
100
|
+
this.cached = (0, timed_cache_1.makeTimedCache)(10 * 60 * 1000);
|
|
101
101
|
this.fileTSs = undefined;
|
|
102
|
-
this.fileProc = new
|
|
102
|
+
this.fileProc = new synced_1.SingleProc();
|
|
103
103
|
Object.seal(this);
|
|
104
104
|
}
|
|
105
105
|
static async makeWith(files) {
|
|
@@ -297,7 +297,7 @@ class MsgIndex {
|
|
|
297
297
|
}
|
|
298
298
|
if (msgFound) {
|
|
299
299
|
removeFrom(records, msgId);
|
|
300
|
-
if (
|
|
300
|
+
if (!!records.fileTS && (records.ordered.length === 0)) {
|
|
301
301
|
await this.files.deleteFile(records.fileTS + INDEX_EXT);
|
|
302
302
|
}
|
|
303
303
|
else {
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.MsgOnDisk = void 0;
|
|
19
19
|
const fs = require("../../../lib-common/async-fs-node");
|
|
20
20
|
const obj_on_disk_1 = require("../../../lib-client/objs-on-disk/obj-on-disk");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
22
22
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
23
23
|
const path_1 = require("path");
|
|
24
24
|
const META_FNAME = 'meta.json';
|
|
@@ -39,7 +39,7 @@ class MsgOnDisk {
|
|
|
39
39
|
this.msgDownloader = msgDownloader;
|
|
40
40
|
this.status = status;
|
|
41
41
|
this.objsIds = objsIds;
|
|
42
|
-
this.syncProc = new
|
|
42
|
+
this.syncProc = new synced_1.SingleProc();
|
|
43
43
|
this.objs = new Map();
|
|
44
44
|
this.objDownloader = this.msgDownloader.getObjDownloader(msgId);
|
|
45
45
|
Object.freeze(this.objDownloader);
|
|
@@ -63,7 +63,7 @@ class MsgOnDisk {
|
|
|
63
63
|
return readJSON(this.msgFolderPath, META_FNAME, this.msgId);
|
|
64
64
|
}
|
|
65
65
|
objFilePath(objId) {
|
|
66
|
-
return path_1.join(this.msgFolderPath, objId);
|
|
66
|
+
return (0, path_1.join)(this.msgFolderPath, objId);
|
|
67
67
|
}
|
|
68
68
|
async getObjFile(objId) {
|
|
69
69
|
let file = this.objs.get(objId);
|
|
@@ -79,7 +79,7 @@ class MsgOnDisk {
|
|
|
79
79
|
if (exc.notFound) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
throw error_1.errWithCause(exc, `Cannot stat message obj at ${path}`);
|
|
82
|
+
throw (0, error_1.errWithCause)(exc, `Cannot stat message obj at ${path}`);
|
|
83
83
|
}));
|
|
84
84
|
file = (isOnDisk ?
|
|
85
85
|
await obj_on_disk_1.ObjOnDisk.forExistingFile(objId, 0, path, this.objDownloader) :
|
|
@@ -119,16 +119,16 @@ exports.MsgOnDisk = MsgOnDisk;
|
|
|
119
119
|
Object.freeze(MsgOnDisk.prototype);
|
|
120
120
|
Object.freeze(MsgOnDisk);
|
|
121
121
|
async function readJSON(msgFolderPath, fname, msgId) {
|
|
122
|
-
const path = path_1.join(msgFolderPath, fname);
|
|
122
|
+
const path = (0, path_1.join)(msgFolderPath, fname);
|
|
123
123
|
try {
|
|
124
124
|
return JSON.parse(await fs.readFile(path, { flag: 'r', encoding: 'utf8' }));
|
|
125
125
|
}
|
|
126
126
|
catch (err) {
|
|
127
|
-
throw error_1.errWithCause(err, `Can't read file ${fname} of message ${msgId}`);
|
|
127
|
+
throw (0, error_1.errWithCause)(err, `Can't read file ${fname} of message ${msgId}`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
async function writeJSON(msgFolderPath, fname, json, exclusive = false) {
|
|
131
|
-
const path = path_1.join(msgFolderPath, fname);
|
|
131
|
+
const path = (0, path_1.join)(msgFolderPath, fname);
|
|
132
132
|
await fs.writeFile(path, JSON.stringify(json), { flag: (exclusive ? 'wx' : 'w') });
|
|
133
133
|
}
|
|
134
134
|
function objIdsFromMeta(meta) {
|
|
@@ -2,15 +2,14 @@ import { InboxPathForUser } from '../app-files';
|
|
|
2
2
|
import { StorageGetter } from '../../lib-client/3nstorage/xsp-fs/common';
|
|
3
3
|
import { GetSigner } from '../id-manager';
|
|
4
4
|
import { AsyncSBoxCryptor } from 'xsp-files';
|
|
5
|
-
import { NetClient } from '../../lib-client/request-utils';
|
|
6
5
|
import { Logger } from '../../lib-client/logging/log-to-file';
|
|
7
6
|
import { ServiceLocatorMaker } from '../../lib-client/service-locator';
|
|
7
|
+
import { MakeNet } from '..';
|
|
8
8
|
declare type WritableFS = web3n.files.WritableFS;
|
|
9
9
|
declare type Service = web3n.asmail.Service;
|
|
10
10
|
export declare type MailCAPMaker = () => Service;
|
|
11
11
|
export declare class ASMail {
|
|
12
12
|
private readonly cryptor;
|
|
13
|
-
private readonly makeNet;
|
|
14
13
|
private readonly inboxPathForUser;
|
|
15
14
|
private readonly logger;
|
|
16
15
|
private keyring;
|
|
@@ -19,7 +18,8 @@ export declare class ASMail {
|
|
|
19
18
|
private delivery;
|
|
20
19
|
private config;
|
|
21
20
|
private sendingParams;
|
|
22
|
-
|
|
21
|
+
private readonly makeNet;
|
|
22
|
+
constructor(cryptor: AsyncSBoxCryptor, makeNet: MakeNet, inboxPathForUser: InboxPathForUser, logger: Logger);
|
|
23
23
|
init(address: string, getSigner: GetSigner, syncedFS: WritableFS, localFS: WritableFS, getStorages: StorageGetter, makeResolver: ServiceLocatorMaker): Promise<void>;
|
|
24
24
|
private setupConfig;
|
|
25
25
|
private setupKeyring;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020 -
|
|
3
|
+
Copyright (C) 2015 - 2018, 2020 - 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -23,6 +23,7 @@ const keyring_1 = require("./keyring");
|
|
|
23
23
|
const config_1 = require("./config");
|
|
24
24
|
const delivery_1 = require("./delivery");
|
|
25
25
|
const sending_params_1 = require("./sending-params");
|
|
26
|
+
const fs_sync_utils_1 = require("../../lib-client/fs-sync-utils");
|
|
26
27
|
const KEYRING_DATA_FOLDER = 'keyring';
|
|
27
28
|
const INBOX_DATA_FOLDER = 'inbox';
|
|
28
29
|
const CONFIG_DATA_FOLDER = 'config';
|
|
@@ -31,7 +32,6 @@ const SEND_PARAMS_DATA_FOLDER = 'sending-params';
|
|
|
31
32
|
class ASMail {
|
|
32
33
|
constructor(cryptor, makeNet, inboxPathForUser, logger) {
|
|
33
34
|
this.cryptor = cryptor;
|
|
34
|
-
this.makeNet = makeNet;
|
|
35
35
|
this.inboxPathForUser = inboxPathForUser;
|
|
36
36
|
this.logger = logger;
|
|
37
37
|
this.keyring = undefined;
|
|
@@ -40,11 +40,13 @@ class ASMail {
|
|
|
40
40
|
this.delivery = undefined;
|
|
41
41
|
this.config = undefined;
|
|
42
42
|
this.sendingParams = undefined;
|
|
43
|
+
this.makeNet = () => makeNet();
|
|
43
44
|
Object.seal(this);
|
|
44
45
|
}
|
|
45
46
|
async init(address, getSigner, syncedFS, localFS, getStorages, makeResolver) {
|
|
46
47
|
try {
|
|
47
48
|
this.address = address;
|
|
49
|
+
await (0, fs_sync_utils_1.getRemoteFolderChanges)(syncedFS);
|
|
48
50
|
await this.setupConfig(getSigner, syncedFS, makeResolver('asmail'));
|
|
49
51
|
await Promise.all([
|
|
50
52
|
this.setupKeyring(syncedFS),
|
|
@@ -54,23 +56,24 @@ class ASMail {
|
|
|
54
56
|
this.setupInbox(syncedFS, getSigner, getStorages, makeResolver),
|
|
55
57
|
this.setupDelivery(localFS, getSigner, makeResolver)
|
|
56
58
|
]);
|
|
59
|
+
await (0, fs_sync_utils_1.uploadFolderChangesIfAny)(syncedFS);
|
|
57
60
|
await syncedFS.close();
|
|
58
61
|
await localFS.close();
|
|
59
62
|
}
|
|
60
63
|
catch (err) {
|
|
61
|
-
throw error_1.errWithCause(err, 'Failed to initialize ASMail');
|
|
64
|
+
throw (0, error_1.errWithCause)(err, 'Failed to initialize ASMail');
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
async setupConfig(getSigner, syncedFS, resolver) {
|
|
65
|
-
const fs = await
|
|
68
|
+
const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, CONFIG_DATA_FOLDER);
|
|
66
69
|
this.config = await config_1.ConfigOfASMailServer.makeAndStart(this.address, getSigner, resolver, this.makeNet(), fs);
|
|
67
70
|
}
|
|
68
71
|
async setupKeyring(syncedFS) {
|
|
69
|
-
const fs = await
|
|
72
|
+
const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, KEYRING_DATA_FOLDER);
|
|
70
73
|
this.keyring = await keyring_1.KeyRing.makeAndStart(this.cryptor, fs, this.config.publishedKeys);
|
|
71
74
|
}
|
|
72
75
|
async setupSendingParams(syncedFS) {
|
|
73
|
-
const fs = await
|
|
76
|
+
const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, SEND_PARAMS_DATA_FOLDER);
|
|
74
77
|
this.sendingParams = await sending_params_1.SendingParamsHolder.makeAndStart(fs, this.config.anonSenderInvites);
|
|
75
78
|
}
|
|
76
79
|
async setupDelivery(localFS, getSigner, makeResolver) {
|
|
@@ -96,7 +99,7 @@ class ASMail {
|
|
|
96
99
|
}
|
|
97
100
|
async setupInbox(syncedFS, getSigner, getStorages, makeResolver) {
|
|
98
101
|
const cachePath = this.inboxPathForUser(this.address);
|
|
99
|
-
const inboxFS = await
|
|
102
|
+
const inboxFS = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, INBOX_DATA_FOLDER);
|
|
100
103
|
this.inbox = await inbox_1.InboxOnServer.makeAndStart(cachePath, inboxFS, {
|
|
101
104
|
address: this.address,
|
|
102
105
|
cryptor: this.cryptor,
|
|
@@ -117,7 +120,7 @@ class ASMail {
|
|
|
117
120
|
const w = {
|
|
118
121
|
getUserId: async () => this.address,
|
|
119
122
|
delivery: this.delivery.wrap(),
|
|
120
|
-
inbox: this.inbox.wrap()
|
|
123
|
+
inbox: this.inbox.wrap(),
|
|
121
124
|
};
|
|
122
125
|
return Object.freeze(w);
|
|
123
126
|
}
|
|
@@ -127,4 +130,6 @@ class ASMail {
|
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
exports.ASMail = ASMail;
|
|
133
|
+
Object.freeze(ASMail.prototype);
|
|
134
|
+
Object.freeze(ASMail);
|
|
130
135
|
Object.freeze(exports);
|
|
@@ -30,10 +30,10 @@ const service_locator_1 = require("../../lib-client/service-locator");
|
|
|
30
30
|
* @param certs is an object with a MailerId certificates chain for a public key
|
|
31
31
|
*/
|
|
32
32
|
async function checkAndExtractPKey(client, resolver, address, certs) {
|
|
33
|
-
address = canonical_address_1.toCanonicalAddress(address);
|
|
33
|
+
address = (0, canonical_address_1.toCanonicalAddress)(address);
|
|
34
34
|
const validAt = Math.round(Date.now() / 1000);
|
|
35
35
|
// get MailerId provider's info with a root certificate(s)
|
|
36
|
-
const data = await service_locator_1.getMailerIdInfoFor(resolver, client, address);
|
|
36
|
+
const data = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
|
|
37
37
|
// TODO choose proper root certificate, as it may not be current one
|
|
38
38
|
const rootAddr = data.domain;
|
|
39
39
|
const rootCert = data.info.currentCert;
|
|
@@ -56,13 +56,13 @@ async function checkAndExtractPKeyWithAddress(client, resolver, certs, validAt)
|
|
|
56
56
|
// address here comes from certificates; we return it for further checks
|
|
57
57
|
let address;
|
|
58
58
|
try {
|
|
59
|
-
address = jwkeys_1.getKeyCert(certs.pkeyCert).cert.principal.address;
|
|
59
|
+
address = (0, jwkeys_1.getKeyCert)(certs.pkeyCert).cert.principal.address;
|
|
60
60
|
}
|
|
61
61
|
catch (err) {
|
|
62
|
-
throw mid_sigs_NaCl_Ed_1.makeMalformedCertsException(`Cannot read public key certificate`, err);
|
|
62
|
+
throw (0, mid_sigs_NaCl_Ed_1.makeMalformedCertsException)(`Cannot read public key certificate`, err);
|
|
63
63
|
}
|
|
64
64
|
// get MailerId provider's info with a root certificate(s)
|
|
65
|
-
const data = await service_locator_1.getMailerIdInfoFor(resolver, client, address);
|
|
65
|
+
const data = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
|
|
66
66
|
// TODO choose proper root certificate, as it may not be current one
|
|
67
67
|
const rootAddr = data.domain;
|
|
68
68
|
const rootCert = data.info.currentCert;
|