core-3nweb-client-lib 0.44.6 → 0.44.8
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/api-defs/files.d.ts +1 -0
- package/build/api-defs/web3n.d.ts +2 -1
- package/build/core/asmail/inbox/inbox-events.d.ts +0 -1
- package/build/core/asmail/inbox/inbox-events.js +3 -5
- package/build/core/asmail/inbox/index.js +1 -1
- package/build/core/asmail/inbox/msg-downloader.d.ts +1 -2
- package/build/core/asmail/inbox/msg-downloader.js +3 -4
- package/build/core/storage/synced/obj-files.js +1 -1
- package/build/core/storage/synced/obj-status.d.ts +2 -0
- package/build/core/storage/synced/obj-status.js +9 -5
- package/build/core/storage/synced/remote-events.d.ts +0 -1
- package/build/core/storage/synced/remote-events.js +5 -7
- package/build/core/storage/synced/storage.js +2 -2
- package/build/core/storage/synced/upsyncer.d.ts +1 -2
- package/build/core/storage/synced/upsyncer.js +49 -25
- package/build/lib-client/3nstorage/storage-owner.js +1 -1
- package/build/lib-client/asmail/recipient.js +8 -4
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/worker-js.js +4 -2
- package/build/lib-client/local-files/dev-file-sink.js +30 -28
- package/build/lib-client/local-files/dev-file-src.js +7 -6
- package/build/lib-client/local-files/device-fs.js +23 -23
- package/build/lib-client/objs-on-disk/obj-folders.js +6 -3
- package/build/lib-client/request-utils.d.ts +2 -1
- package/build/lib-client/request-utils.js +8 -19
- package/build/lib-client/user-with-mid-session.d.ts +2 -0
- package/build/lib-client/user-with-mid-session.js +33 -22
- package/build/lib-client/xsp-fs/attrs.js +4 -2
- package/build/lib-client/xsp-fs/exceptions.js +5 -2
- package/build/lib-client/xsp-fs/folder-node-serialization.js +4 -2
- package/build/lib-client/xsp-fs/node-in-fs.js +2 -5
- package/build/lib-common/async-fs-node.d.ts +30 -46
- package/build/lib-common/async-fs-node.js +71 -309
- package/build/lib-common/awaitable-state.js +3 -1
- package/build/lib-common/exceptions/file.d.ts +1 -1
- package/build/lib-common/exceptions/file.js +11 -6
- package/build/lib-common/exceptions/runtime.d.ts +7 -1
- package/build/lib-common/exceptions/runtime.js +16 -2
- package/build/lib-common/objs-on-disk/obj-version-file.d.ts +1 -1
- package/build/lib-common/objs-on-disk/obj-version-file.js +35 -33
- package/build/lib-index.d.ts +1 -1
- package/package.json +1 -1
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2020, 2026 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 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
const worker_threads_1 = require("worker_threads");
|
|
20
20
|
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
21
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
22
|
+
const runtime_1 = require("../../lib-common/exceptions/runtime");
|
|
22
23
|
if (!worker_threads_1.parentPort) {
|
|
23
24
|
throw new Error(`Missing expected parentPort. Is this called within WebWorker process?`);
|
|
24
25
|
}
|
|
@@ -100,7 +101,8 @@ const funcs = {
|
|
|
100
101
|
function wrapError(err) {
|
|
101
102
|
const exc = {
|
|
102
103
|
runtimeException: true,
|
|
103
|
-
type: 'cryptor'
|
|
104
|
+
type: 'cryptor',
|
|
105
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
104
106
|
};
|
|
105
107
|
if (err.failedCipherVerification) {
|
|
106
108
|
exc.failedCipherVerification = true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2018, 2020, 2026 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
|
|
@@ -21,6 +21,11 @@ const file_1 = require("../../lib-common/exceptions/file");
|
|
|
21
21
|
const wrapping_1 = require("../../lib-common/byte-streaming/wrapping");
|
|
22
22
|
const assert_1 = require("../../lib-common/assert");
|
|
23
23
|
const buffer_utils_1 = require("../../lib-common/buffer-utils");
|
|
24
|
+
function throwRangeErrorParamsIf(conditionToThrow) {
|
|
25
|
+
if (conditionToThrow) {
|
|
26
|
+
throw RangeError(`Invalid parameters given`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
class DevFileByteSink {
|
|
25
30
|
constructor(path, pathPrefixMaskLen, size) {
|
|
26
31
|
this.path = path;
|
|
@@ -44,13 +49,12 @@ class DevFileByteSink {
|
|
|
44
49
|
};
|
|
45
50
|
}
|
|
46
51
|
async truncate(size) {
|
|
47
|
-
(
|
|
52
|
+
throwRangeErrorParamsIf(!Number.isInteger(size) || (size < 0));
|
|
48
53
|
await fs.truncate(this.path, size);
|
|
49
54
|
this.size = size;
|
|
50
55
|
}
|
|
51
56
|
async splice(pos, del, bytes) {
|
|
52
|
-
(
|
|
53
|
-
&& Number.isInteger(del) && (del >= 0), `Invalid parameters given`);
|
|
57
|
+
throwRangeErrorParamsIf(!Number.isInteger(pos) || (pos < 0) || !Number.isInteger(del) || (del < 0));
|
|
54
58
|
const ins = (bytes ? bytes.length : 0);
|
|
55
59
|
if ((del === 0) && (ins === 0)) {
|
|
56
60
|
return;
|
|
@@ -71,17 +75,17 @@ class DevFileByteSink {
|
|
|
71
75
|
if (!bytes) {
|
|
72
76
|
return;
|
|
73
77
|
}
|
|
74
|
-
let
|
|
78
|
+
let fh = undefined;
|
|
75
79
|
try {
|
|
76
|
-
|
|
77
|
-
await fs.writeFromBuf(
|
|
80
|
+
fh = await fs.open(this.path, 'r+');
|
|
81
|
+
await fs.writeFromBuf(fh, pos, (0, buffer_utils_1.toBuffer)(bytes));
|
|
78
82
|
}
|
|
79
83
|
catch (e) {
|
|
80
84
|
throw (0, file_1.maskPathInExc)(this.pathPrefixMaskLen, e);
|
|
81
85
|
}
|
|
82
86
|
finally {
|
|
83
|
-
if (
|
|
84
|
-
await
|
|
87
|
+
if (fh !== undefined) {
|
|
88
|
+
await fh.close();
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
}
|
|
@@ -89,9 +93,8 @@ class DevFileByteSink {
|
|
|
89
93
|
if (delta === 0) {
|
|
90
94
|
return;
|
|
91
95
|
}
|
|
92
|
-
(
|
|
93
|
-
|
|
94
|
-
&& (pos <= initFileLen), `Invalid parameters given`);
|
|
96
|
+
throwRangeErrorParamsIf(!Number.isInteger(pos) || (pos < 0) || !Number.isInteger(delta) ||
|
|
97
|
+
!Number.isInteger(initFileLen) || (pos > initFileLen));
|
|
95
98
|
if (delta > 0) {
|
|
96
99
|
await this.insFileBytesAt(pos, delta, initFileLen);
|
|
97
100
|
}
|
|
@@ -102,20 +105,19 @@ class DevFileByteSink {
|
|
|
102
105
|
async insFileBytesAt(pos, ins, initFileLen) {
|
|
103
106
|
const bytesToMove = Math.max(0, initFileLen - pos);
|
|
104
107
|
const buf = Buffer.allocUnsafe(Math.min(MAX_SHIFT_BUFFER_SIZE, bytesToMove));
|
|
105
|
-
let
|
|
108
|
+
let fh = undefined;
|
|
106
109
|
try {
|
|
107
|
-
|
|
108
|
-
await
|
|
110
|
+
fh = await fs.open(this.path, 'r+');
|
|
111
|
+
await fh.truncate(initFileLen + ins);
|
|
109
112
|
let bytesLeft = bytesToMove;
|
|
110
113
|
let readPos = initFileLen;
|
|
111
114
|
let writePos = initFileLen + ins;
|
|
112
115
|
while (bytesLeft > 0) {
|
|
113
|
-
const chunk = ((buf.length <= bytesLeft) ?
|
|
114
|
-
buf : buf.slice(0, bytesLeft));
|
|
116
|
+
const chunk = ((buf.length <= bytesLeft) ? buf : buf.slice(0, bytesLeft));
|
|
115
117
|
readPos -= chunk.length;
|
|
116
118
|
writePos -= chunk.length;
|
|
117
|
-
await fs.readToBuf(
|
|
118
|
-
await fs.writeFromBuf(
|
|
119
|
+
await fs.readToBuf(fh, readPos, chunk);
|
|
120
|
+
await fs.writeFromBuf(fh, writePos, chunk);
|
|
119
121
|
bytesLeft -= chunk.length;
|
|
120
122
|
}
|
|
121
123
|
}
|
|
@@ -123,37 +125,37 @@ class DevFileByteSink {
|
|
|
123
125
|
throw (0, file_1.maskPathInExc)(this.pathPrefixMaskLen, e);
|
|
124
126
|
}
|
|
125
127
|
finally {
|
|
126
|
-
if (
|
|
127
|
-
await
|
|
128
|
+
if (fh !== undefined) {
|
|
129
|
+
await fh.close();
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
async rmFileBytesAt(pos, del, initFileLen) {
|
|
132
134
|
const bytesToMove = Math.max(0, initFileLen - pos - del);
|
|
133
135
|
const buf = Buffer.allocUnsafe(Math.min(MAX_SHIFT_BUFFER_SIZE, bytesToMove));
|
|
134
|
-
let
|
|
136
|
+
let fh = undefined;
|
|
135
137
|
try {
|
|
136
|
-
|
|
138
|
+
fh = await fs.open(this.path, 'r+');
|
|
137
139
|
let bytesLeft = bytesToMove;
|
|
138
140
|
let readPos = pos + del;
|
|
139
141
|
let writePos = pos;
|
|
140
142
|
while (bytesLeft > 0) {
|
|
141
143
|
const chunk = ((buf.length <= bytesLeft) ?
|
|
142
144
|
buf : buf.slice(0, bytesLeft));
|
|
143
|
-
await fs.readToBuf(
|
|
144
|
-
await fs.writeFromBuf(
|
|
145
|
+
await fs.readToBuf(fh, readPos, chunk);
|
|
146
|
+
await fs.writeFromBuf(fh, writePos, chunk);
|
|
145
147
|
bytesLeft -= chunk.length;
|
|
146
148
|
readPos += chunk.length;
|
|
147
149
|
writePos += chunk.length;
|
|
148
150
|
}
|
|
149
|
-
await
|
|
151
|
+
await fh.truncate(pos + bytesToMove);
|
|
150
152
|
}
|
|
151
153
|
catch (e) {
|
|
152
154
|
throw (0, file_1.maskPathInExc)(this.pathPrefixMaskLen, e);
|
|
153
155
|
}
|
|
154
156
|
finally {
|
|
155
|
-
if (
|
|
156
|
-
await
|
|
157
|
+
if (fh !== undefined) {
|
|
158
|
+
await fh.close();
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
161
|
}
|
|
@@ -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.DevFileByteSource = void 0;
|
|
19
20
|
const fs = require("../../lib-common/async-fs-node");
|
|
@@ -38,9 +39,9 @@ class DevFileByteSource {
|
|
|
38
39
|
if (this.offset >= this.size) {
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
|
-
let
|
|
42
|
+
let fh = undefined;
|
|
42
43
|
try {
|
|
43
|
-
|
|
44
|
+
fh = await fs.open(this.path, 'r');
|
|
44
45
|
let buf;
|
|
45
46
|
if (typeof len === 'number') {
|
|
46
47
|
len = Math.min(this.size - this.offset, len);
|
|
@@ -49,7 +50,7 @@ class DevFileByteSource {
|
|
|
49
50
|
else {
|
|
50
51
|
buf = Buffer.allocUnsafe(this.size - this.offset);
|
|
51
52
|
}
|
|
52
|
-
await fs.readToBuf(
|
|
53
|
+
await fs.readToBuf(fh, this.offset, buf);
|
|
53
54
|
this.offset += buf.length;
|
|
54
55
|
return buf;
|
|
55
56
|
}
|
|
@@ -57,8 +58,8 @@ class DevFileByteSource {
|
|
|
57
58
|
throw (0, file_1.maskPathInExc)(this.pathPrefixMaskLen, e);
|
|
58
59
|
}
|
|
59
60
|
finally {
|
|
60
|
-
if (
|
|
61
|
-
await
|
|
61
|
+
if (fh !== undefined) {
|
|
62
|
+
await fh.close();
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020, 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2018, 2020, 2022, 2026 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
|
|
@@ -335,15 +335,15 @@ class DeviceFS {
|
|
|
335
335
|
}
|
|
336
336
|
async readBytes(path, start, end) {
|
|
337
337
|
if ((typeof start === 'number') && (start < 0)) {
|
|
338
|
-
throw new
|
|
338
|
+
throw new RangeError(`Parameter start has bad value: ${start}`);
|
|
339
339
|
}
|
|
340
340
|
if ((typeof end === 'number') && (end < 0)) {
|
|
341
|
-
throw new
|
|
341
|
+
throw new RangeError(`Parameter end has bad value: ${end}`);
|
|
342
342
|
}
|
|
343
|
-
let
|
|
343
|
+
let fh = undefined;
|
|
344
344
|
try {
|
|
345
|
-
|
|
346
|
-
const size = (await
|
|
345
|
+
fh = await fs.open(this.fullPath(path), 'r');
|
|
346
|
+
const size = (await fh.stat()).size;
|
|
347
347
|
if (size === 0) {
|
|
348
348
|
return;
|
|
349
349
|
}
|
|
@@ -358,22 +358,22 @@ class DeviceFS {
|
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
360
|
const bytes = Buffer.allocUnsafe(end - start);
|
|
361
|
-
await fs.readToBuf(
|
|
361
|
+
await fs.readToBuf(fh, start, bytes);
|
|
362
362
|
return bytes;
|
|
363
363
|
}
|
|
364
364
|
catch (e) {
|
|
365
365
|
throw (0, file_1.maskPathInExc)(this.root.length, e);
|
|
366
366
|
}
|
|
367
367
|
finally {
|
|
368
|
-
if (
|
|
369
|
-
await
|
|
368
|
+
if (fh !== undefined) {
|
|
369
|
+
await fh.close();
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
async getByteSink(path, flags = WRITE_NONEXCL_FLAGS) {
|
|
374
374
|
const pathSections = splitPathIntoParts(path);
|
|
375
375
|
const pathStr = this.fullPath(path);
|
|
376
|
-
let
|
|
376
|
+
let fh = undefined;
|
|
377
377
|
try {
|
|
378
378
|
if (flags.create) {
|
|
379
379
|
if (pathSections.length > 1) {
|
|
@@ -381,10 +381,10 @@ class DeviceFS {
|
|
|
381
381
|
await this.makeFolder(enclosingFolder);
|
|
382
382
|
}
|
|
383
383
|
if (flags.exclusive) {
|
|
384
|
-
|
|
384
|
+
fh = await fs.open(pathStr, 'wx');
|
|
385
385
|
}
|
|
386
386
|
else {
|
|
387
|
-
|
|
387
|
+
fh = await fs.open(pathStr, flags.truncate ? 'w' : 'r+')
|
|
388
388
|
.catch((exc) => {
|
|
389
389
|
if (exc.notFound) {
|
|
390
390
|
return fs.open(pathStr, 'w');
|
|
@@ -396,17 +396,17 @@ class DeviceFS {
|
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
else {
|
|
399
|
-
|
|
399
|
+
fh = await fs.open(pathStr, flags.truncate ? 'w' : 'r+');
|
|
400
400
|
}
|
|
401
|
-
const stats = await
|
|
401
|
+
const stats = await fh.stat();
|
|
402
402
|
return dev_file_sink_1.DevFileByteSink.make(pathStr, this.root.length, stats);
|
|
403
403
|
}
|
|
404
404
|
catch (e) {
|
|
405
405
|
throw (0, file_1.maskPathInExc)(this.root.length, e);
|
|
406
406
|
}
|
|
407
407
|
finally {
|
|
408
|
-
if (
|
|
409
|
-
await
|
|
408
|
+
if (fh !== undefined) {
|
|
409
|
+
await fh.close();
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
412
|
}
|
|
@@ -427,27 +427,27 @@ class DeviceFS {
|
|
|
427
427
|
async writeBytes(path, bytes, flags = WRITE_NONEXCL_FLAGS) {
|
|
428
428
|
const pathSections = splitPathIntoParts(path);
|
|
429
429
|
const pathStr = this.fullPath(path);
|
|
430
|
-
let
|
|
430
|
+
let fh = undefined;
|
|
431
431
|
try {
|
|
432
432
|
if (flags.create) {
|
|
433
433
|
if (pathSections.length > 1) {
|
|
434
434
|
const enclosingFolder = pathSections.slice(0, pathSections.length - 1).join('/');
|
|
435
435
|
await this.makeFolder(enclosingFolder);
|
|
436
436
|
}
|
|
437
|
-
|
|
437
|
+
fh = await fs.open(pathStr, (flags.exclusive ? 'wx' : 'w'));
|
|
438
438
|
}
|
|
439
439
|
else {
|
|
440
|
-
|
|
441
|
-
await
|
|
440
|
+
fh = await fs.open(pathStr, 'r+');
|
|
441
|
+
await fh.truncate(0);
|
|
442
442
|
}
|
|
443
|
-
await fs.writeFromBuf(
|
|
443
|
+
await fs.writeFromBuf(fh, 0, (0, buffer_utils_1.toBuffer)(bytes));
|
|
444
444
|
}
|
|
445
445
|
catch (e) {
|
|
446
446
|
throw (0, file_1.maskPathInExc)(this.root.length, e);
|
|
447
447
|
}
|
|
448
448
|
finally {
|
|
449
|
-
if (
|
|
450
|
-
await
|
|
449
|
+
if (fh !== undefined) {
|
|
450
|
+
await fh.close();
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2020, 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2016 - 2020, 2022, 2026 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
|
|
@@ -25,12 +25,14 @@ const xsp_files_1 = require("xsp-files");
|
|
|
25
25
|
const assert_1 = require("../../lib-common/assert");
|
|
26
26
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
27
27
|
const path_1 = require("path");
|
|
28
|
+
const runtime_1 = require("../../lib-common/exceptions/runtime");
|
|
28
29
|
function makeNotFoundExc(msg) {
|
|
29
30
|
return {
|
|
30
31
|
runtimeException: true,
|
|
31
32
|
type: 'cache',
|
|
32
33
|
cause: msg,
|
|
33
|
-
notFound: true
|
|
34
|
+
notFound: true,
|
|
35
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
function makeAlreadyExistExc(msg) {
|
|
@@ -38,7 +40,8 @@ function makeAlreadyExistExc(msg) {
|
|
|
38
40
|
runtimeException: true,
|
|
39
41
|
type: 'cache',
|
|
40
42
|
cause: msg,
|
|
41
|
-
alreadyExist: true
|
|
43
|
+
alreadyExist: true,
|
|
44
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
47
|
function alreadyExistsOrReThrow(exc) {
|
|
@@ -51,5 +51,6 @@ export interface NetClient {
|
|
|
51
51
|
* @param opts
|
|
52
52
|
*/
|
|
53
53
|
doBodylessRequest<T>(opts: RequestOpts): Promise<Reply<T>>;
|
|
54
|
+
reset(): void;
|
|
54
55
|
}
|
|
55
|
-
export declare function makeNetClient(request?: RequestFn<unknown
|
|
56
|
+
export declare function makeNetClient(request?: RequestFn<unknown>, reset?: () => void): NetClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020, 2025 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2018, 2020, 2025 - 2026 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,7 +23,6 @@ exports.makeNetClient = makeNetClient;
|
|
|
23
23
|
const http_1 = require("../lib-common/exceptions/http");
|
|
24
24
|
const bytes_fifo_buffer_1 = require("../lib-common/byte-streaming/bytes-fifo-buffer");
|
|
25
25
|
const https = require("https");
|
|
26
|
-
const url_1 = require("url");
|
|
27
26
|
const rxjs_1 = require("rxjs");
|
|
28
27
|
const buffer_utils_1 = require("../lib-common/buffer-utils");
|
|
29
28
|
const deferred_1 = require("../lib-common/processes/deferred");
|
|
@@ -54,13 +53,13 @@ function formHttpsReqOpts(opts, contentType, reqBody) {
|
|
|
54
53
|
if (reqBody && (opts.method !== 'POST') && (opts.method !== 'PUT')) {
|
|
55
54
|
throw new Error(`Cannot have body in ${opts.method} request.`);
|
|
56
55
|
}
|
|
57
|
-
const url =
|
|
56
|
+
const url = new URL(opts.url);
|
|
58
57
|
const netReqOpts = {
|
|
59
58
|
protocol: url.protocol,
|
|
60
59
|
method: opts.method,
|
|
61
60
|
hostname: url.hostname,
|
|
62
61
|
port: url.port,
|
|
63
|
-
path: url.
|
|
62
|
+
path: url.pathname + url.search,
|
|
64
63
|
headers: {}
|
|
65
64
|
};
|
|
66
65
|
if (reqBody) {
|
|
@@ -147,8 +146,7 @@ function formReply(res, resBody, reqOpts) {
|
|
|
147
146
|
status,
|
|
148
147
|
data,
|
|
149
148
|
headers: (reqOpts.responseHeaders ?
|
|
150
|
-
makeHeaders(filterHeaders(res.headers, reqOpts.responseHeaders)) :
|
|
151
|
-
undefined)
|
|
149
|
+
makeHeaders(filterHeaders(res.headers, reqOpts.responseHeaders)) : undefined)
|
|
152
150
|
};
|
|
153
151
|
return rep;
|
|
154
152
|
}
|
|
@@ -171,14 +169,6 @@ function makeHeaders(headers) {
|
|
|
171
169
|
}
|
|
172
170
|
};
|
|
173
171
|
}
|
|
174
|
-
// /**
|
|
175
|
-
// * @param rep
|
|
176
|
-
// * @param errMsg
|
|
177
|
-
// * @return http exception based on given reply, with an optional message
|
|
178
|
-
// */
|
|
179
|
-
// export function makeException(rep: Reply<any>, message?: string): HTTPException {
|
|
180
|
-
// return makeHTTPException(rep.url, rep.method, rep.status, { message });
|
|
181
|
-
// }
|
|
182
172
|
function extractIntHeader(rep, headerName) {
|
|
183
173
|
const intHeader = parseInt(rep.headers.get(headerName));
|
|
184
174
|
if (isNaN(intHeader)) {
|
|
@@ -195,7 +185,7 @@ function makeNodeRequest() {
|
|
|
195
185
|
return processRequest(nodeRequest, httpsOpts, opts, reqBody);
|
|
196
186
|
};
|
|
197
187
|
}
|
|
198
|
-
function makeNetClient(request = makeNodeRequest()) {
|
|
188
|
+
function makeNetClient(request = makeNodeRequest(), reset = () => { }) {
|
|
199
189
|
const client = {
|
|
200
190
|
doBinaryRequest(opts, bytes) {
|
|
201
191
|
let reqBody;
|
|
@@ -215,11 +205,10 @@ function makeNetClient(request = makeNodeRequest()) {
|
|
|
215
205
|
return request(opts);
|
|
216
206
|
},
|
|
217
207
|
doJsonRequest(opts, json) {
|
|
218
|
-
const reqBody = ((json === undefined) ?
|
|
219
|
-
new Uint8Array(0) :
|
|
220
|
-
buffer_utils_1.utf8.pack(JSON.stringify(json)));
|
|
208
|
+
const reqBody = ((json === undefined) ? new Uint8Array(0) : buffer_utils_1.utf8.pack(JSON.stringify(json)));
|
|
221
209
|
return request(opts, 'application/json', reqBody);
|
|
222
|
-
}
|
|
210
|
+
},
|
|
211
|
+
reset
|
|
223
212
|
};
|
|
224
213
|
return Object.freeze(client);
|
|
225
214
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { Reply, RequestOpts, NetClient } from '../lib-client/request-utils';
|
|
6
6
|
import * as WebSocket from 'ws';
|
|
7
7
|
import { MailerIdSigner } from '../lib-common/mailerid-sigs/user';
|
|
8
|
+
import { AwaitableState } from '../lib-common/awaitable-state';
|
|
8
9
|
export type IGetMailerIdSigner = () => Promise<MailerIdSigner>;
|
|
9
10
|
export interface ServiceAccessParams {
|
|
10
11
|
login: string;
|
|
@@ -22,6 +23,7 @@ export declare abstract class ServiceUser {
|
|
|
22
23
|
private loginUrlPart;
|
|
23
24
|
private logoutUrlEnd;
|
|
24
25
|
private get loginUrl();
|
|
26
|
+
readonly connectedState: AwaitableState;
|
|
25
27
|
private redirectedFrom;
|
|
26
28
|
private canBeRedirected;
|
|
27
29
|
private sessionId;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015, 2017, 2020, 2022, 2025 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015, 2017, 2020, 2022, 2025 - 2026 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,16 +19,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.ServiceUser = void 0;
|
|
20
20
|
const api = require("../lib-common/service-api/mailer-id/login");
|
|
21
21
|
const ws_utils_1 = require("./ws-utils");
|
|
22
|
-
const url_1 = require("url");
|
|
23
22
|
const login_1 = require("./mailer-id/login");
|
|
24
23
|
const assert_1 = require("../lib-common/assert");
|
|
25
24
|
const http_1 = require("../lib-common/exceptions/http");
|
|
25
|
+
const awaitable_state_1 = require("../lib-common/awaitable-state");
|
|
26
26
|
class ServiceUser {
|
|
27
27
|
get serviceURI() {
|
|
28
28
|
return this.uri;
|
|
29
29
|
}
|
|
30
30
|
set serviceURI(uriString) {
|
|
31
|
-
const u =
|
|
31
|
+
const u = new URL(uriString);
|
|
32
32
|
if (u.protocol !== 'https:') {
|
|
33
33
|
throw new Error("Url protocol must be https.");
|
|
34
34
|
}
|
|
@@ -49,12 +49,12 @@ class ServiceUser {
|
|
|
49
49
|
this.getInitServiceURI = getInitServiceURI;
|
|
50
50
|
this.net = net;
|
|
51
51
|
this.uri = undefined;
|
|
52
|
+
this.connectedState = new awaitable_state_1.AwaitableState();
|
|
52
53
|
this.redirectedFrom = undefined;
|
|
53
54
|
this.sessionId = undefined;
|
|
54
55
|
this.loginProc = undefined;
|
|
55
56
|
this.loginUrlPart = accessParams.login;
|
|
56
|
-
if ((this.loginUrlPart.length > 0)
|
|
57
|
-
&& (this.loginUrlPart[this.loginUrlPart.length - 1] !== '/')) {
|
|
57
|
+
if ((this.loginUrlPart.length > 0) && !this.loginUrlPart.endsWith('/')) {
|
|
58
58
|
this.loginUrlPart += '/';
|
|
59
59
|
}
|
|
60
60
|
this.logoutUrlEnd = accessParams.logout;
|
|
@@ -162,31 +162,42 @@ class ServiceUser {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
async callEnsuringLogin(func) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
165
|
+
try {
|
|
166
|
+
let reply;
|
|
167
|
+
if (this.loginProc || !this.sessionId) {
|
|
168
|
+
await this.login();
|
|
169
|
+
reply = await func();
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// first attepmt
|
|
173
|
+
const initSessionId = this.sessionId;
|
|
174
|
+
const rep = await func();
|
|
175
|
+
if (rep.status !== api.ERR_SC.needAuth) {
|
|
176
|
+
return rep;
|
|
177
|
+
}
|
|
178
|
+
// if auth is needed, do login and a second attempt
|
|
179
|
+
if (this.sessionId === initSessionId) {
|
|
180
|
+
this.sessionId = undefined;
|
|
181
|
+
}
|
|
182
|
+
await this.login();
|
|
183
|
+
reply = await func();
|
|
175
184
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
this.connectedState.setState();
|
|
186
|
+
return reply;
|
|
187
|
+
}
|
|
188
|
+
catch (exc) {
|
|
189
|
+
if (exc.type === 'connect') {
|
|
190
|
+
this.net.reset();
|
|
191
|
+
this.connectedState.clearState();
|
|
179
192
|
}
|
|
180
|
-
|
|
181
|
-
return func();
|
|
193
|
+
throw exc;
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
196
|
prepCallOpts(opts, isWS) {
|
|
185
197
|
opts.sessionId = this.sessionId;
|
|
186
198
|
if (opts.appPath) {
|
|
187
199
|
opts.url = (isWS ?
|
|
188
|
-
`wss${this.serviceURI.substring(5)}${opts.appPath}` :
|
|
189
|
-
`${this.serviceURI}${opts.appPath}`);
|
|
200
|
+
`wss${this.serviceURI.substring(5)}${opts.appPath}` : `${this.serviceURI}${opts.appPath}`);
|
|
190
201
|
}
|
|
191
202
|
else if (!opts.url) {
|
|
192
203
|
throw new Error(`Missing both appPath and ready url in request options.`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2020, 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2020, 2022, 2026 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
|
|
@@ -20,6 +20,7 @@ exports.XAttrs = exports.CommonAttrs = void 0;
|
|
|
20
20
|
const assert_1 = require("../../lib-common/assert");
|
|
21
21
|
const buffer_utils_1 = require("../../lib-common/buffer-utils");
|
|
22
22
|
const big_endian_1 = require("../../lib-common/big-endian");
|
|
23
|
+
const runtime_1 = require("../../lib-common/exceptions/runtime");
|
|
23
24
|
class CommonAttrs {
|
|
24
25
|
constructor(ctime, mtime) {
|
|
25
26
|
this.ctime = ctime;
|
|
@@ -309,7 +310,8 @@ function parsingException(msg, cause) {
|
|
|
309
310
|
return {
|
|
310
311
|
runtimeException: true,
|
|
311
312
|
type: 'attrs-parsing',
|
|
312
|
-
cause, msg
|
|
313
|
+
cause, msg,
|
|
314
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
313
315
|
};
|
|
314
316
|
}
|
|
315
317
|
Object.freeze(exports);
|
|
@@ -25,10 +25,12 @@ exports.makeUnknownTransactionExc = makeUnknownTransactionExc;
|
|
|
25
25
|
exports.makeVersionMismatchExc = makeVersionMismatchExc;
|
|
26
26
|
exports.makeStorageIsClosedExc = makeStorageIsClosedExc;
|
|
27
27
|
exports.makeFSSyncException = makeFSSyncException;
|
|
28
|
+
const runtime_1 = require("../../lib-common/exceptions/runtime");
|
|
28
29
|
function makeStorageException(fields) {
|
|
29
30
|
const exc = {
|
|
30
31
|
runtimeException: true,
|
|
31
|
-
type: 'storage'
|
|
32
|
+
type: 'storage',
|
|
33
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
32
34
|
};
|
|
33
35
|
for (const [key, value] of Object.entries(fields)) {
|
|
34
36
|
exc[key] = value;
|
|
@@ -72,7 +74,8 @@ function makeFSSyncException(path, fields) {
|
|
|
72
74
|
const exc = {
|
|
73
75
|
runtimeException: true,
|
|
74
76
|
type: 'fs-sync',
|
|
75
|
-
path
|
|
77
|
+
path,
|
|
78
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
76
79
|
};
|
|
77
80
|
for (const [key, value] of Object.entries(fields)) {
|
|
78
81
|
exc[key] = value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017, 2022 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2022, 2026 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
|
|
@@ -22,6 +22,7 @@ const buffer_utils_1 = require("../../lib-common/buffer-utils");
|
|
|
22
22
|
const xsp_files_1 = require("xsp-files");
|
|
23
23
|
const big_endian_1 = require("../../lib-common/big-endian");
|
|
24
24
|
const assert_1 = require("../../lib-common/assert");
|
|
25
|
+
const runtime_1 = require("../../lib-common/exceptions/runtime");
|
|
25
26
|
const ver1Serialization = new Uint8Array([1]);
|
|
26
27
|
function parseFolderInfo(bytes) {
|
|
27
28
|
if (!bytes) {
|
|
@@ -42,7 +43,8 @@ function parsingException(msg, cause) {
|
|
|
42
43
|
runtimeException: true,
|
|
43
44
|
type: 'folder-parsing',
|
|
44
45
|
message: msg,
|
|
45
|
-
cause
|
|
46
|
+
cause,
|
|
47
|
+
stack: (0, runtime_1.getStackHere)(1)
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
var formatV1;
|