spec-3nweb-server 1.3.8 → 1.5.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/build/3nstorage/3nstorage-app.js +4 -4
- package/build/3nstorage/owner.js +28 -28
- package/build/3nstorage/resources/store.d.ts +2 -9
- package/build/3nstorage/resources/store.js +76 -73
- package/build/3nstorage/resources/users.d.ts +4 -2
- package/build/3nstorage/resources/users.js +8 -4
- package/build/3nstorage/routes/owner/archive-obj-version.d.ts +2 -2
- package/build/3nstorage/routes/owner/archive-obj-version.js +36 -31
- package/build/3nstorage/routes/owner/cancel-trans.js +1 -1
- package/build/3nstorage/routes/owner/delete-obj.d.ts +3 -2
- package/build/3nstorage/routes/owner/delete-obj.js +42 -7
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +10 -6
- package/build/3nstorage/routes/owner/get-current-obj.js +2 -2
- package/build/3nstorage/routes/owner/list-obj-archive.js +28 -31
- package/build/3nstorage/routes/owner/param-getter.js +3 -2
- package/build/3nstorage/routes/owner/param-setter.js +3 -2
- package/build/3nstorage/routes/owner/put-current-obj.js +12 -10
- package/build/3nstorage/routes/owner/session-params.js +4 -3
- package/build/admin/admin-app.js +5 -5
- package/build/admin/resources/users.js +42 -42
- package/build/admin/routes/add.js +3 -3
- package/build/admin/signup-tokens.js +8 -8
- package/build/asmail/asmail-app.js +7 -7
- package/build/asmail/config.js +9 -8
- package/build/asmail/delivery.js +10 -9
- package/build/asmail/resources/delivery-sessions.js +4 -3
- package/build/asmail/resources/inbox.d.ts +1 -1
- package/build/asmail/resources/inbox.js +22 -22
- package/build/asmail/resources/recipients.d.ts +2 -1
- package/build/asmail/resources/recipients.js +4 -4
- package/build/asmail/resources/sessions.js +2 -1
- package/build/asmail/retrieval.js +13 -8
- package/build/asmail/routes/config/param-getter.js +3 -2
- package/build/asmail/routes/config/param-setter.js +3 -2
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +5 -4
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +3 -2
- package/build/asmail/routes/delivery/put-metadata.js +3 -2
- package/build/asmail/routes/delivery/put-obj.js +4 -4
- package/build/asmail/routes/delivery/restart-session.js +4 -3
- package/build/asmail/routes/delivery/sender-authorization.d.ts +1 -3
- package/build/asmail/routes/delivery/sender-authorization.js +3 -2
- package/build/asmail/routes/delivery/start-session.js +5 -4
- package/build/asmail/routes/retrieval/get-message-meta.js +3 -2
- package/build/asmail/routes/retrieval/get-message-obj.js +4 -3
- package/build/asmail/routes/retrieval/list-messages.js +3 -2
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/build/lib-common/async-fs-node.d.ts +2 -0
- package/build/lib-common/async-fs-node.js +13 -13
- package/build/lib-common/byte-streaming/common.js +9 -9
- package/build/lib-common/canonical-address.js +1 -1
- package/build/lib-common/ipc/generic-ipc.js +12 -12
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
- package/build/lib-common/objs-on-disk/file-layout.js +10 -10
- package/build/lib-common/objs-on-disk/obj-file.js +11 -11
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/objs-on-disk/utils.js +3 -3
- package/build/lib-common/processes.js +1 -1
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +24 -18
- package/build/lib-common/service-api/3nstorage/owner.js +31 -26
- 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-server/conf-util.js +2 -1
- package/build/lib-server/middleware/body-parsers.js +16 -16
- package/build/lib-server/middleware/error-handler.js +1 -1
- package/build/lib-server/resources/mailerid-authorizer.js +3 -3
- package/build/lib-server/resources/mem-backed-sessions-factory.js +3 -3
- package/build/lib-server/resources/server-data-folders.js +23 -23
- package/build/lib-server/resources/sessions.js +5 -5
- package/build/lib-server/resources/user-files.js +8 -8
- package/build/lib-server/routes/pub-key-login/complete-exchange.js +4 -3
- package/build/lib-server/routes/pub-key-login/start-exchange.js +7 -6
- package/build/lib-server/routes/sessions/mid-auth.js +6 -5
- package/build/lib-server/routes/sessions/start.js +4 -3
- package/build/lib-server/web-sockets/app.d.ts +1 -0
- package/build/lib-server/web-sockets/app.js +6 -5
- package/build/lib-server/web-sockets/server-events.js +5 -4
- package/build/mailerId/mailerId-app.js +7 -7
- package/build/mailerId/resources/certifier.d.ts +4 -6
- package/build/mailerId/resources/certifier.js +8 -7
- package/build/mailerId/resources/compute-login-dhshared-key.js +2 -1
- package/build/mailerId/resources/sessions.js +2 -1
- package/build/mailerId/resources/users.js +4 -4
- package/build/mailerId/routes/certify.js +1 -1
- package/build/main.js +10 -10
- package/build/mock/dns.js +1 -1
- package/build/mock/mock-as-child-proc.js +10 -10
- package/build/mock/node-child-ipc.js +2 -2
- package/build/mock/run-in-proc.js +7 -7
- package/build/run-config.js +10 -10
- package/build/run.js +4 -4
- package/build/services.js +5 -5
- package/package.json +13 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016, 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
|
|
@@ -16,19 +16,45 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
19
|
+
exports.deleteArchivedObjVer = exports.deleteCurrentObjVer = void 0;
|
|
20
20
|
const users_1 = require("../../resources/users");
|
|
21
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
22
|
+
const assert_1 = require("../../../tests/libs-for-tests/assert");
|
|
22
23
|
function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
23
24
|
if ('function' !== typeof deleteObjFunc) {
|
|
24
25
|
throw new TypeError("Given argument 'deleteObjFunc' must be function, but is not.");
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
if (delCurrent) {
|
|
28
|
+
(0, assert_1.assert)(!root);
|
|
29
|
+
}
|
|
30
|
+
return async (req, res, next) => {
|
|
27
31
|
const userId = req.session.params.userId;
|
|
28
32
|
const objId = (root ? null : req.params.objId);
|
|
29
|
-
const
|
|
33
|
+
const ver = parseInt(req.query.ver);
|
|
34
|
+
let version;
|
|
35
|
+
if (isNaN(ver)) {
|
|
36
|
+
if (delCurrent) {
|
|
37
|
+
version = undefined;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
res.status(owner_1.ERR_SC.malformed).send("Bad query parameters");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (ver < 1) {
|
|
46
|
+
res.status(owner_1.ERR_SC.malformed).send("Bad query parameters");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
version = ver;
|
|
50
|
+
}
|
|
30
51
|
try {
|
|
31
|
-
|
|
52
|
+
if (delCurrent) {
|
|
53
|
+
await deleteObjFunc(userId, objId, version);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await deleteObjFunc(userId, objId, version);
|
|
57
|
+
}
|
|
32
58
|
res.status(owner_1.currentObj.SC.okDelete).end();
|
|
33
59
|
}
|
|
34
60
|
catch (err) {
|
|
@@ -41,6 +67,9 @@ function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
|
41
67
|
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
42
68
|
res.status(owner_1.currentObj.SC.unknownObj).send(`Object ${objId} is unknown.`);
|
|
43
69
|
}
|
|
70
|
+
else if (err === users_1.SC.OBJ_VER_UNKNOWN) {
|
|
71
|
+
res.status(owner_1.currentObj.SC.unknownObjVer).send(`Object version ${version} is unknown.`);
|
|
72
|
+
}
|
|
44
73
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
45
74
|
res.status(owner_1.ERR_SC.server).send("Recipient disappeared from the system.");
|
|
46
75
|
req.session.close();
|
|
@@ -51,6 +80,12 @@ function deleteObj(root, delCurrent, deleteObjFunc) {
|
|
|
51
80
|
}
|
|
52
81
|
};
|
|
53
82
|
}
|
|
54
|
-
|
|
55
|
-
;
|
|
83
|
+
function deleteCurrentObjVer(deleteObjFunc) {
|
|
84
|
+
return deleteObj(false, true, deleteObjFunc);
|
|
85
|
+
}
|
|
86
|
+
exports.deleteCurrentObjVer = deleteCurrentObjVer;
|
|
87
|
+
function deleteArchivedObjVer(root, deleteObjFunc) {
|
|
88
|
+
return deleteObj(root, false, deleteObjFunc);
|
|
89
|
+
}
|
|
90
|
+
exports.deleteArchivedObjVer = deleteArchivedObjVer;
|
|
56
91
|
Object.freeze(exports);
|
|
@@ -49,7 +49,7 @@ function getArchivedObjVersion(root, getArchivedObjFunc) {
|
|
|
49
49
|
if ('function' !== typeof getArchivedObjFunc) {
|
|
50
50
|
throw new TypeError("Given argument 'getArchivedObjFunc' must be function, but is not.");
|
|
51
51
|
}
|
|
52
|
-
return async
|
|
52
|
+
return async (req, res, next) => {
|
|
53
53
|
const userId = req.session.params.userId;
|
|
54
54
|
const objId = (root ? null : req.params.objId);
|
|
55
55
|
const opts = extractQueryOptions(req);
|
|
@@ -71,7 +71,7 @@ function getArchivedObjVersion(root, getArchivedObjFunc) {
|
|
|
71
71
|
await reader.pipe(res);
|
|
72
72
|
}
|
|
73
73
|
catch (err) {
|
|
74
|
-
console.error(error_1.errWithCause(err, `Wasn't able to complete sending segments due to error in piping`));
|
|
74
|
+
console.error((0, error_1.errWithCause)(err, `Wasn't able to complete sending segments due to error in piping`));
|
|
75
75
|
}
|
|
76
76
|
finally {
|
|
77
77
|
res.end();
|
|
@@ -85,10 +85,14 @@ function getArchivedObjVersion(root, getArchivedObjFunc) {
|
|
|
85
85
|
if ("string" !== typeof err) {
|
|
86
86
|
next(err);
|
|
87
87
|
}
|
|
88
|
-
else if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
89
|
+
res.status(owner_1.archivedObjVersion.SC.unknownObj).send(objId ?
|
|
90
|
+
`Object ${objId}is unknown.` : `Root object is not set`);
|
|
91
|
+
}
|
|
92
|
+
else if (err === users_1.SC.OBJ_VER_UNKNOWN) {
|
|
93
|
+
res.status(owner_1.archivedObjVersion.SC.unknownObjVer).send(objId ?
|
|
94
|
+
`Object ${objId}, version ${opts.ver} is unknown.` :
|
|
95
|
+
`Root object version ${opts.ver} is not known.`);
|
|
92
96
|
}
|
|
93
97
|
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
94
98
|
res.status(owner_1.ERR_SC.server).send(`Recipient disappeared from the system.`);
|
|
@@ -54,7 +54,7 @@ function getCurrentObj(root, getCurrentObjFunc) {
|
|
|
54
54
|
if ('function' !== typeof getCurrentObjFunc) {
|
|
55
55
|
throw new TypeError("Given argument 'getCurrentObjFunc' must be function, but is not.");
|
|
56
56
|
}
|
|
57
|
-
return async
|
|
57
|
+
return async (req, res, next) => {
|
|
58
58
|
const userId = req.session.params.userId;
|
|
59
59
|
const objId = (root ? null : req.params.objId);
|
|
60
60
|
const opts = extractQueryOptions(req);
|
|
@@ -86,7 +86,7 @@ function getCurrentObj(root, getCurrentObjFunc) {
|
|
|
86
86
|
await reader.pipe(res);
|
|
87
87
|
}
|
|
88
88
|
catch (err) {
|
|
89
|
-
console.error(error_1.stringifyErr(error_1.errWithCause(err, `Wasn't able to complete sending segments due to error in piping`)));
|
|
89
|
+
console.error((0, error_1.stringifyErr)((0, error_1.errWithCause)(err, `Wasn't able to complete sending segments due to error in piping`)));
|
|
90
90
|
}
|
|
91
91
|
finally {
|
|
92
92
|
res.end();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C)
|
|
3
|
+
Copyright (C) 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
|
|
@@ -13,42 +13,39 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.listObjArchive = void 0;
|
|
20
|
+
const users_1 = require("../../resources/users");
|
|
21
|
+
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
19
22
|
function listObjArchive(root, listObjArchiveFunc) {
|
|
20
23
|
if ('function' !== typeof listObjArchiveFunc) {
|
|
21
24
|
throw new TypeError("Given argument 'listObjArchiveFunc' must be function, but is not.");
|
|
22
25
|
}
|
|
23
|
-
return async
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// "Recipient disappeared from the system.");
|
|
47
|
-
// req.session.close();
|
|
48
|
-
// } else {
|
|
49
|
-
// next(new Error("Unhandled storage error code: "+err));
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
26
|
+
return async (req, res, next) => {
|
|
27
|
+
const userId = req.session.params.userId;
|
|
28
|
+
const objId = (root ? null : req.params.objId);
|
|
29
|
+
try {
|
|
30
|
+
const lst = await listObjArchiveFunc(userId, objId);
|
|
31
|
+
res.status(owner_1.archiveObj.SC.okGet).json(lst);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if ("string" !== typeof err) {
|
|
35
|
+
next(err);
|
|
36
|
+
}
|
|
37
|
+
else if (err === users_1.SC.OBJ_UNKNOWN) {
|
|
38
|
+
res.status(owner_1.archiveObj.SC.unknownObj).send(root ?
|
|
39
|
+
`Root object is set.` : `Object ${objId} is unknown.`);
|
|
40
|
+
}
|
|
41
|
+
else if (err === users_1.SC.USER_UNKNOWN) {
|
|
42
|
+
res.status(owner_1.ERR_SC.server).send("Recipient disappeared from the system.");
|
|
43
|
+
req.session.close();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
next(new Error("Unhandled storage error code: " + err));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
51
|
exports.listObjArchive = listObjArchive;
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.getParam = void 0;
|
|
19
20
|
const users_1 = require("../../resources/users");
|
|
@@ -22,7 +23,7 @@ function getParam(paramGetter) {
|
|
|
22
23
|
if ('function' !== typeof paramGetter) {
|
|
23
24
|
throw new TypeError("Given argument 'paramGetter' must be function, but is not.");
|
|
24
25
|
}
|
|
25
|
-
return async
|
|
26
|
+
return async (req, res, next) => {
|
|
26
27
|
const session = req.session;
|
|
27
28
|
const userId = session.params.userId;
|
|
28
29
|
try {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.setParam = void 0;
|
|
19
20
|
const users_1 = require("../../resources/users");
|
|
@@ -22,7 +23,7 @@ function setParam(paramSetter) {
|
|
|
22
23
|
if ('function' !== typeof paramSetter) {
|
|
23
24
|
throw new TypeError("Given argument 'paramSetter' must be function, but is not.");
|
|
24
25
|
}
|
|
25
|
-
return async
|
|
26
|
+
return async (req, res, next) => {
|
|
26
27
|
const session = req.session;
|
|
27
28
|
const userId = session.params.userId;
|
|
28
29
|
const pValue = req.body;
|
|
@@ -28,10 +28,10 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
28
28
|
if ('function' !== typeof saveObjFunc) {
|
|
29
29
|
throw new TypeError("Given argument 'saveObjFunc' must be function, but is not.");
|
|
30
30
|
}
|
|
31
|
-
const maxChunkSize = conf_util_1.stringToNumOfBytes(chunkLimit);
|
|
32
|
-
return async
|
|
31
|
+
const maxChunkSize = (0, conf_util_1.stringToNumOfBytes)(chunkLimit);
|
|
32
|
+
return async (req, res, next) => {
|
|
33
33
|
if (!req.is(owner_1.BIN_TYPE)) {
|
|
34
|
-
body_parsers_1.attachByteDrainToRequest(req);
|
|
34
|
+
(0, body_parsers_1.attachByteDrainToRequest)(req);
|
|
35
35
|
res.status(owner_1.ERR_SC.wrongContentType).json({
|
|
36
36
|
error: `Content-Type must be ${owner_1.BIN_TYPE} for this call.`
|
|
37
37
|
});
|
|
@@ -42,7 +42,7 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
42
42
|
// get and check Content-Length, implicitly sending replies for bad length
|
|
43
43
|
let len = getContentLenOrSendError(req, res, maxChunkSize);
|
|
44
44
|
if (len === undefined) {
|
|
45
|
-
body_parsers_1.attachByteDrainToRequest(req);
|
|
45
|
+
(0, body_parsers_1.attachByteDrainToRequest)(req);
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
// extract and check query parameters
|
|
@@ -53,7 +53,7 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
53
53
|
const { fstReq, sndReq } = opts;
|
|
54
54
|
let diff;
|
|
55
55
|
if (fstReq) {
|
|
56
|
-
if (
|
|
56
|
+
if (fstReq.create && objId) {
|
|
57
57
|
if (!buffer_utils_1.base64urlSafe.allCharsFromAlphabet(objId)) {
|
|
58
58
|
return replyToMalformed(req, "Bad object id", res);
|
|
59
59
|
}
|
|
@@ -66,7 +66,7 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
66
66
|
}
|
|
67
67
|
// read diff, if it is expected
|
|
68
68
|
if (fstReq.diff) {
|
|
69
|
-
let diffBytes = await readChunkFrom(req, fstReq.diff).catch(
|
|
69
|
+
let diffBytes = await readChunkFrom(req, fstReq.diff).catch(noop);
|
|
70
70
|
if (diffBytes) {
|
|
71
71
|
len -= fstReq.diff;
|
|
72
72
|
}
|
|
@@ -75,7 +75,7 @@ function saveCurrentObj(root, saveObjFunc, chunkLimit) {
|
|
|
75
75
|
}
|
|
76
76
|
try {
|
|
77
77
|
const diffFromReq = JSON.parse(buffer_utils_1.utf8.open(diffBytes));
|
|
78
|
-
diff = owner_1.sanitizedDiff(diffFromReq, fstReq.ver);
|
|
78
|
+
diff = (0, owner_1.sanitizedDiff)(diffFromReq, fstReq.ver);
|
|
79
79
|
if (!diff) {
|
|
80
80
|
return replyToMalformed(req, "Malformed diff info", res);
|
|
81
81
|
}
|
|
@@ -171,6 +171,7 @@ function extractQueryOptions(req) {
|
|
|
171
171
|
// this is the first request
|
|
172
172
|
// query fields are string or undefined, yet, type info helps the show
|
|
173
173
|
const query = req.query;
|
|
174
|
+
const create = (query.create === 'true');
|
|
174
175
|
const ver = parseInt(query.ver);
|
|
175
176
|
if (isNaN(ver) || (ver < 1)) {
|
|
176
177
|
return;
|
|
@@ -186,7 +187,7 @@ function extractQueryOptions(req) {
|
|
|
186
187
|
return;
|
|
187
188
|
}
|
|
188
189
|
const last = (query.last === 'true');
|
|
189
|
-
return { fstReq: { diff, header, last, ver } };
|
|
190
|
+
return { fstReq: { diff, header, last, ver, create } };
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
function getContentLenOrSendError(req, res, maxChunkSize) {
|
|
@@ -219,7 +220,7 @@ function readChunkFrom(stream, bytesToRead) {
|
|
|
219
220
|
throw new Error(`Illegal number of bytes to read from stream: ${bytesToRead}`);
|
|
220
221
|
}
|
|
221
222
|
const buffer = new common_1.BytesFIFOBuffer();
|
|
222
|
-
let deferred = processes_1.defer();
|
|
223
|
+
let deferred = (0, processes_1.defer)();
|
|
223
224
|
const complete = (bytes, err) => {
|
|
224
225
|
if (!deferred) {
|
|
225
226
|
return;
|
|
@@ -270,7 +271,8 @@ function readChunkFrom(stream, bytesToRead) {
|
|
|
270
271
|
return deferred.promise;
|
|
271
272
|
}
|
|
272
273
|
function replyToMalformed(req, msg, res) {
|
|
273
|
-
body_parsers_1.attachByteDrainToRequest(req);
|
|
274
|
+
(0, body_parsers_1.attachByteDrainToRequest)(req);
|
|
274
275
|
res.status(owner_1.ERR_SC.malformed).json({ error: msg });
|
|
275
276
|
}
|
|
277
|
+
function noop() { }
|
|
276
278
|
Object.freeze(exports);
|
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.sessionParams = void 0;
|
|
19
20
|
const users_1 = require("../../resources/users");
|
|
20
21
|
const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
|
|
21
22
|
const conf_util_1 = require("../../../lib-server/conf-util");
|
|
22
23
|
function sessionParams(maxChunk) {
|
|
23
|
-
const maxChunkSize = conf_util_1.stringToNumOfBytes(maxChunk);
|
|
24
|
-
return async
|
|
24
|
+
const maxChunkSize = (0, conf_util_1.stringToNumOfBytes)(maxChunk);
|
|
25
|
+
return async (req, res, next) => {
|
|
25
26
|
const userId = req.session.params.userId;
|
|
26
27
|
try {
|
|
27
28
|
const reply = { maxChunkSize };
|
package/build/admin/admin-app.js
CHANGED
|
@@ -28,19 +28,19 @@ const signupApi = require("../lib-common/admin-api/signup");
|
|
|
28
28
|
function apiPart(users) {
|
|
29
29
|
const app = express();
|
|
30
30
|
app.disable('etag');
|
|
31
|
-
app.post('/' + signupApi.availableDomains.URL_END, body_parsers_1.json('1kb'), get_available_domains_1.availableDomains(users.getAvailableDomains));
|
|
32
|
-
app.post('/' + signupApi.availableAddressesForName.URL_END, body_parsers_1.json('1kb'), get_available_addresses_1.availableAddresses(users.getAvailableAddresses));
|
|
33
|
-
app.post('/' + signupApi.addUser.URL_END, body_parsers_1.json('4kb'), add_1.addUser(users.add));
|
|
31
|
+
app.post('/' + signupApi.availableDomains.URL_END, (0, body_parsers_1.json)('1kb'), (0, get_available_domains_1.availableDomains)(users.getAvailableDomains));
|
|
32
|
+
app.post('/' + signupApi.availableAddressesForName.URL_END, (0, body_parsers_1.json)('1kb'), (0, get_available_addresses_1.availableAddresses)(users.getAvailableAddresses));
|
|
33
|
+
app.post('/' + signupApi.addUser.URL_END, (0, body_parsers_1.json)('4kb'), (0, add_1.addUser)(users.add));
|
|
34
34
|
return app;
|
|
35
35
|
}
|
|
36
36
|
function makeApp(conf) {
|
|
37
37
|
const app = express();
|
|
38
38
|
const noTokenFile = (conf.signup ? conf.signup.noTokenFile : undefined);
|
|
39
|
-
const users = users_1.makeFactory(conf.rootFolder, noTokenFile);
|
|
39
|
+
const users = (0, users_1.makeFactory)(conf.rootFolder, noTokenFile);
|
|
40
40
|
if (conf.signup) {
|
|
41
41
|
app.use('/signup', apiPart(users));
|
|
42
42
|
}
|
|
43
|
-
app.use(error_handler_1.makeErrHandler());
|
|
43
|
+
app.use((0, error_handler_1.makeErrHandler)());
|
|
44
44
|
return app;
|
|
45
45
|
}
|
|
46
46
|
exports.makeApp = makeApp;
|
|
@@ -84,26 +84,26 @@ async function writeJson(path, json) {
|
|
|
84
84
|
return fs.writeFile(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
|
|
85
85
|
}
|
|
86
86
|
function writeJsonSync(path, json) {
|
|
87
|
-
fs_1.writeFileSync(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
|
|
87
|
+
(0, fs_1.writeFileSync)(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
|
|
88
88
|
}
|
|
89
89
|
function setGeneralDefaults(defaults) {
|
|
90
90
|
const infoFolder = defaults.info.path;
|
|
91
|
-
writeJsonSync(path_1.join(infoFolder, 'quota'), 100 * 1024 * 1024 * 1024);
|
|
91
|
+
writeJsonSync((0, path_1.join)(infoFolder, 'quota'), 100 * 1024 * 1024 * 1024);
|
|
92
92
|
}
|
|
93
93
|
function setStoreDefaults(store) {
|
|
94
94
|
const sp = store.params.path;
|
|
95
|
-
writeJsonSync(path_1.join(sp, 'key-deriv'), null);
|
|
95
|
+
writeJsonSync((0, path_1.join)(sp, 'key-deriv'), null);
|
|
96
96
|
}
|
|
97
97
|
function setMailDefaults(mail) {
|
|
98
|
-
writeJsonSync(path_1.join(mail.params.path, 'pubkey'), null);
|
|
98
|
+
writeJsonSync((0, path_1.join)(mail.params.path, 'pubkey'), null);
|
|
99
99
|
const anonFolder = mail.params.anonymous.path;
|
|
100
100
|
const anonPolicy = {
|
|
101
101
|
accept: true,
|
|
102
102
|
acceptWithInvitesOnly: false,
|
|
103
103
|
defaultMsgSize: 1024 * 1024
|
|
104
104
|
};
|
|
105
|
-
writeJsonSync(path_1.join(anonFolder, 'policy'), anonPolicy);
|
|
106
|
-
writeJsonSync(path_1.join(anonFolder, 'invites'), {});
|
|
105
|
+
writeJsonSync((0, path_1.join)(anonFolder, 'policy'), anonPolicy);
|
|
106
|
+
writeJsonSync((0, path_1.join)(anonFolder, 'invites'), {});
|
|
107
107
|
const authFolder = mail.params.authenticated.path;
|
|
108
108
|
const authPolicy = {
|
|
109
109
|
acceptWithInvitesOnly: false,
|
|
@@ -111,10 +111,10 @@ function setMailDefaults(mail) {
|
|
|
111
111
|
applyBlackList: true,
|
|
112
112
|
defaultMsgSize: 1024 * 1024
|
|
113
113
|
};
|
|
114
|
-
writeJsonSync(path_1.join(authFolder, 'policy'), authPolicy);
|
|
115
|
-
writeJsonSync(path_1.join(authFolder, 'whitelist'), {});
|
|
116
|
-
writeJsonSync(path_1.join(authFolder, 'blacklist'), {});
|
|
117
|
-
writeJsonSync(path_1.join(authFolder, 'invites'), {});
|
|
114
|
+
writeJsonSync((0, path_1.join)(authFolder, 'policy'), authPolicy);
|
|
115
|
+
writeJsonSync((0, path_1.join)(authFolder, 'whitelist'), {});
|
|
116
|
+
writeJsonSync((0, path_1.join)(authFolder, 'blacklist'), {});
|
|
117
|
+
writeJsonSync((0, path_1.join)(authFolder, 'invites'), {});
|
|
118
118
|
}
|
|
119
119
|
class Users {
|
|
120
120
|
constructor(rootFolder, noTokenFile) {
|
|
@@ -122,25 +122,25 @@ class Users {
|
|
|
122
122
|
if (!fs.existsFolderSync(rootFolder)) {
|
|
123
123
|
throw new Error(`Given root folder does not exist: ${rootFolder}`);
|
|
124
124
|
}
|
|
125
|
-
const folders = server_data_folders_1.treeInRootFolder(rootFolder);
|
|
126
|
-
server_data_folders_1.createFolderTreeSync(folders);
|
|
125
|
+
const folders = (0, server_data_folders_1.treeInRootFolder)(rootFolder);
|
|
126
|
+
(0, server_data_folders_1.createFolderTreeSync)(folders);
|
|
127
127
|
this.users = folders.users.path;
|
|
128
128
|
this.defaults = folders.defaults.path;
|
|
129
129
|
this.tokens = folders.tokens.path;
|
|
130
130
|
this.populateDefaultsIfEmpty();
|
|
131
131
|
}
|
|
132
132
|
populateDefaultsIfEmpty() {
|
|
133
|
-
if (fs_1.readdirSync(this.defaults).length > 0) {
|
|
133
|
+
if ((0, fs_1.readdirSync)(this.defaults).length > 0) {
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
136
|
-
const defaults = server_data_folders_1.treeInDefaultsFolder(this.defaults);
|
|
137
|
-
server_data_folders_1.createFolderTreeSync(defaults);
|
|
136
|
+
const defaults = (0, server_data_folders_1.treeInDefaultsFolder)(this.defaults);
|
|
137
|
+
(0, server_data_folders_1.createFolderTreeSync)(defaults);
|
|
138
138
|
setGeneralDefaults(defaults);
|
|
139
139
|
setMailDefaults(defaults.mail);
|
|
140
140
|
setStoreDefaults(defaults.store);
|
|
141
141
|
}
|
|
142
142
|
userFolderPath(userId) {
|
|
143
|
-
return path_1.join(this.users, server_data_folders_1.addressToFName(userId));
|
|
143
|
+
return (0, path_1.join)(this.users, (0, server_data_folders_1.addressToFName)(userId));
|
|
144
144
|
}
|
|
145
145
|
async add(userId, midParams, storeKeyDerivParams, signupToken) {
|
|
146
146
|
if (!validateUserMidParams(midParams)) {
|
|
@@ -161,16 +161,16 @@ class Users {
|
|
|
161
161
|
});
|
|
162
162
|
try {
|
|
163
163
|
// make folder tree
|
|
164
|
-
const tree = server_data_folders_1.treeInUserFolder(userFolder);
|
|
165
|
-
await server_data_folders_1.createFolderTree(tree);
|
|
164
|
+
const tree = (0, server_data_folders_1.treeInUserFolder)(userFolder);
|
|
165
|
+
await (0, server_data_folders_1.createFolderTree)(tree);
|
|
166
166
|
// record user id
|
|
167
|
-
await fs.writeFile(path_1.join(tree.info.path, 'userid'), userId, { encoding: 'utf8', flag: 'w', mode: '440' });
|
|
167
|
+
await fs.writeFile((0, path_1.join)(tree.info.path, 'userid'), userId, { encoding: 'utf8', flag: 'w', mode: '440' });
|
|
168
168
|
// copy defaults
|
|
169
169
|
await fs.copyTree(this.defaults, userFolder);
|
|
170
170
|
// record mid parameters
|
|
171
|
-
await writeJson(path_1.join(tree.info.path, 'mid-params'), midParams);
|
|
171
|
+
await writeJson((0, path_1.join)(tree.info.path, 'mid-params'), midParams);
|
|
172
172
|
// record storage params
|
|
173
|
-
await writeJson(path_1.join(tree.store.params.path, 'key-deriv'), storeKeyDerivParams);
|
|
173
|
+
await writeJson((0, path_1.join)(tree.store.params.path, 'key-deriv'), storeKeyDerivParams);
|
|
174
174
|
if (rmToken) {
|
|
175
175
|
await rmToken();
|
|
176
176
|
}
|
|
@@ -182,21 +182,21 @@ class Users {
|
|
|
182
182
|
}
|
|
183
183
|
async checkIfCreationAllowed(userId, signupToken) {
|
|
184
184
|
if (signupToken) {
|
|
185
|
-
const t = signup_tokens_1.parseToken(signupToken);
|
|
185
|
+
const t = (0, signup_tokens_1.parseToken)(signupToken);
|
|
186
186
|
if (!t) {
|
|
187
187
|
throw exports.SC.CREATION_UNAUTHORIZED;
|
|
188
188
|
}
|
|
189
|
-
const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
|
|
189
|
+
const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
|
|
190
190
|
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
191
191
|
.catch((exc) => {
|
|
192
192
|
throw (exc.notFound ? exports.SC.CREATION_UNAUTHORIZED : exc);
|
|
193
193
|
});
|
|
194
194
|
try {
|
|
195
195
|
const ctx = JSON.parse(str);
|
|
196
|
-
if (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token)) {
|
|
196
|
+
if (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token)) {
|
|
197
197
|
throw exports.SC.CREATION_UNAUTHORIZED;
|
|
198
198
|
}
|
|
199
|
-
if (signup_tokens_1.canCreateUser(userId, ctx)) {
|
|
199
|
+
if ((0, signup_tokens_1.canCreateUser)(userId, ctx)) {
|
|
200
200
|
if (ctx.type === 'single-user') {
|
|
201
201
|
return () => fs.unlink(ctxFilePath).catch(noop);
|
|
202
202
|
}
|
|
@@ -206,20 +206,20 @@ class Users {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
catch (err) {
|
|
209
|
-
throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
209
|
+
throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
else if (this.noTokenFile) {
|
|
213
213
|
try {
|
|
214
214
|
const str = await fs.readFile(this.noTokenFile, { encoding: 'utf8' });
|
|
215
215
|
const ctx = JSON.parse(str);
|
|
216
|
-
if (signup_tokens_1.canCreateUser(userId, ctx)) {
|
|
216
|
+
if ((0, signup_tokens_1.canCreateUser)(userId, ctx)) {
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
catch (exc) {
|
|
221
221
|
if (!exc.notFound) {
|
|
222
|
-
throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
222
|
+
throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
@@ -227,11 +227,11 @@ class Users {
|
|
|
227
227
|
}
|
|
228
228
|
async getAvailableDomains(signupToken) {
|
|
229
229
|
if (signupToken) {
|
|
230
|
-
const t = signup_tokens_1.parseToken(signupToken);
|
|
230
|
+
const t = (0, signup_tokens_1.parseToken)(signupToken);
|
|
231
231
|
if (!t) {
|
|
232
232
|
return [];
|
|
233
233
|
}
|
|
234
|
-
const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
|
|
234
|
+
const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
|
|
235
235
|
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
236
236
|
.catch((exc) => {
|
|
237
237
|
if (exc.notFound) {
|
|
@@ -247,7 +247,7 @@ class Users {
|
|
|
247
247
|
try {
|
|
248
248
|
const ctx = JSON.parse(str);
|
|
249
249
|
if ((ctx.type === 'single-user')
|
|
250
|
-
|| (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token))) {
|
|
250
|
+
|| (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token))) {
|
|
251
251
|
return [];
|
|
252
252
|
}
|
|
253
253
|
else {
|
|
@@ -255,7 +255,7 @@ class Users {
|
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
catch (err) {
|
|
258
|
-
throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
258
|
+
throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
else if (this.noTokenFile) {
|
|
@@ -269,7 +269,7 @@ class Users {
|
|
|
269
269
|
return [];
|
|
270
270
|
}
|
|
271
271
|
else {
|
|
272
|
-
throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
272
|
+
throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
}
|
|
@@ -279,11 +279,11 @@ class Users {
|
|
|
279
279
|
}
|
|
280
280
|
async getAvailableAddresses(name, signupToken) {
|
|
281
281
|
if (signupToken) {
|
|
282
|
-
const t = signup_tokens_1.parseToken(signupToken);
|
|
282
|
+
const t = (0, signup_tokens_1.parseToken)(signupToken);
|
|
283
283
|
if (!t) {
|
|
284
284
|
return [];
|
|
285
285
|
}
|
|
286
|
-
const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
|
|
286
|
+
const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
|
|
287
287
|
const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
|
|
288
288
|
.catch((exc) => {
|
|
289
289
|
if (exc.notFound) {
|
|
@@ -298,13 +298,13 @@ class Users {
|
|
|
298
298
|
}
|
|
299
299
|
try {
|
|
300
300
|
const ctx = JSON.parse(str);
|
|
301
|
-
if (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token)) {
|
|
301
|
+
if (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token)) {
|
|
302
302
|
return [];
|
|
303
303
|
}
|
|
304
304
|
return this.availableAddressInCtx(name, ctx);
|
|
305
305
|
}
|
|
306
306
|
catch (err) {
|
|
307
|
-
throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
307
|
+
throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
else if (this.noTokenFile) {
|
|
@@ -318,7 +318,7 @@ class Users {
|
|
|
318
318
|
return [];
|
|
319
319
|
}
|
|
320
320
|
else {
|
|
321
|
-
throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
321
|
+
throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
}
|
|
@@ -327,7 +327,7 @@ class Users {
|
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
async availableAddressInCtx(name, ctx) {
|
|
330
|
-
const allIds = signup_tokens_1.addressesForName(name, ctx);
|
|
330
|
+
const allIds = (0, signup_tokens_1.addressesForName)(name, ctx);
|
|
331
331
|
if (!allIds) {
|
|
332
332
|
return [];
|
|
333
333
|
}
|
|
@@ -357,9 +357,9 @@ class Users {
|
|
|
357
357
|
}
|
|
358
358
|
wrap() {
|
|
359
359
|
const wrap = {
|
|
360
|
-
getAvailableDomains: binding_1.bind(this, this.getAvailableDomains),
|
|
361
|
-
getAvailableAddresses: binding_1.bind(this, this.getAvailableAddresses),
|
|
362
|
-
add: binding_1.bind(this, this.add),
|
|
360
|
+
getAvailableDomains: (0, binding_1.bind)(this, this.getAvailableDomains),
|
|
361
|
+
getAvailableAddresses: (0, binding_1.bind)(this, this.getAvailableAddresses),
|
|
362
|
+
add: (0, binding_1.bind)(this, this.add),
|
|
363
363
|
};
|
|
364
364
|
Object.freeze(wrap);
|
|
365
365
|
return wrap;
|