core-3nweb-client-lib 0.46.1 → 0.47.1
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/injected-globals/platform-devfs.d.ts +89 -15
- package/build/lib-client/doh.d.ts +2 -1
- package/build/lib-client/doh.js +13 -14
- package/build/lib-client/logging/log-to-file.js +0 -1
- package/build/lib-client/objs-on-disk/obj-on-disk.js +4 -2
- package/build/lib-client/request-utils.d.ts +7 -3
- package/build/lib-client/request-utils.js +5 -11
- package/build/lib-client/service-checks.d.ts +2 -1
- package/build/lib-client/service-checks.js +8 -6
- package/build/lib-client/service-locator.d.ts +6 -1
- package/build/lib-client/service-locator.js +31 -6
- package/build/lib-client/user-with-mid-session.d.ts +1 -1
- package/build/lib-client/user-with-mid-session.js +1 -2
- package/build/lib-common/async-fs-node.d.ts +70 -1
- package/build/lib-common/ipc/ws-ipc.d.ts +1 -1
- package/build/lib-common-on-node/dns-from-node.d.ts +0 -0
- package/build/lib-common-on-node/dns-from-node.js +0 -0
- package/build/lib-common-on-node/fs-on-node.d.ts +2 -0
- package/build/lib-common-on-node/request-from-node.d.ts +2 -0
- package/build/lib-common-on-node/request-from-node.js +28 -0
- package/build/lib-common-on-node/websocket-from-node.d.ts +3 -0
- package/build/{lib-client/ws-utils.js → lib-common-on-node/websocket-from-node.js} +5 -4
- package/build/tests/jasmine.js +2 -2
- package/build/tests/libs-for-tests/core-runner.js +3 -1
- package/build/tests/libs-for-tests/setups.js +3 -1
- package/package.json +1 -1
- package/build/injected-globals/inject-on-node.d.ts +0 -2
- package/build/lib-client/ws-utils.d.ts +0 -3
- /package/build/{injected-globals/inject-on-node.js → lib-common-on-node/fs-on-node.js} +0 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Abortable } from 'events';
|
|
2
|
+
import type { BigIntStats, BufferEncodingOption, Dirent, promises as fsFns, MakeDirectoryOptions, Mode, ObjectEncodingOptions, OpenMode, PathLike, RmDirOptions, StatOptions, Stats } from 'fs';
|
|
3
|
+
import { FlagAndOpenMode } from 'fs/promises';
|
|
4
|
+
import type Stream = require('stream');
|
|
2
5
|
export type { Stats } from 'fs';
|
|
3
6
|
export type { FileException } from '../lib-common/exceptions/file';
|
|
4
7
|
export type FileHandle = fsFns.FileHandle;
|
|
@@ -6,20 +9,20 @@ export type FileHandle = fsFns.FileHandle;
|
|
|
6
9
|
* This should be injected at globalThis.platform.device_fs
|
|
7
10
|
*/
|
|
8
11
|
export interface PlatformDeviceFS {
|
|
9
|
-
readFile: typeof
|
|
10
|
-
writeFile: typeof
|
|
11
|
-
appendFile: typeof
|
|
12
|
-
mkdir: typeof
|
|
13
|
-
open: typeof
|
|
14
|
-
symlink: typeof
|
|
15
|
-
readlink: typeof
|
|
16
|
-
lstat: typeof
|
|
17
|
-
stat: typeof
|
|
18
|
-
readdir: typeof
|
|
19
|
-
rmdir: typeof
|
|
20
|
-
unlink: typeof
|
|
21
|
-
rename: typeof
|
|
22
|
-
truncate: typeof
|
|
12
|
+
readFile: typeof readFile;
|
|
13
|
+
writeFile: typeof writeFile;
|
|
14
|
+
appendFile: typeof appendFile;
|
|
15
|
+
mkdir: typeof mkdir;
|
|
16
|
+
open: typeof open;
|
|
17
|
+
symlink: typeof symlink;
|
|
18
|
+
readlink: typeof readlink;
|
|
19
|
+
lstat: typeof lstat;
|
|
20
|
+
stat: typeof stat;
|
|
21
|
+
readdir: typeof readdir;
|
|
22
|
+
rmdir: typeof rmdir;
|
|
23
|
+
unlink: typeof unlink;
|
|
24
|
+
rename: typeof rename;
|
|
25
|
+
truncate: typeof truncate;
|
|
23
26
|
/**
|
|
24
27
|
* This pipes source file into destination file.
|
|
25
28
|
* @param src
|
|
@@ -29,3 +32,74 @@ export interface PlatformDeviceFS {
|
|
|
29
32
|
*/
|
|
30
33
|
copyFile(src: string, dst: string, overwrite?: boolean, dstMode?: string): Promise<void>;
|
|
31
34
|
}
|
|
35
|
+
declare function readFile(path: PathLike | FileHandle, options?: ({
|
|
36
|
+
encoding?: null | undefined;
|
|
37
|
+
flag?: OpenMode | undefined;
|
|
38
|
+
} & Abortable) | null): Promise<Buffer>;
|
|
39
|
+
declare function readFile(path: PathLike | FileHandle, options: ({
|
|
40
|
+
encoding: BufferEncoding;
|
|
41
|
+
flag?: OpenMode | undefined;
|
|
42
|
+
} & Abortable) | BufferEncoding): Promise<string>;
|
|
43
|
+
declare function readFile(path: PathLike | FileHandle, options?: (ObjectEncodingOptions & Abortable & {
|
|
44
|
+
flag?: OpenMode | undefined;
|
|
45
|
+
}) | BufferEncoding | null): Promise<string | Buffer>;
|
|
46
|
+
declare function writeFile(file: PathLike | FileHandle, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream, options?: (ObjectEncodingOptions & {
|
|
47
|
+
mode?: Mode | undefined;
|
|
48
|
+
flag?: OpenMode | undefined;
|
|
49
|
+
flush?: boolean | undefined;
|
|
50
|
+
} & Abortable) | BufferEncoding | null): Promise<void>;
|
|
51
|
+
declare function appendFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode & {
|
|
52
|
+
flush?: boolean | undefined;
|
|
53
|
+
}) | BufferEncoding | null): Promise<void>;
|
|
54
|
+
declare function mkdir(path: PathLike, options: MakeDirectoryOptions & {
|
|
55
|
+
recursive: true;
|
|
56
|
+
}): Promise<string | undefined>;
|
|
57
|
+
declare function mkdir(path: PathLike, options?: Mode | (MakeDirectoryOptions & {
|
|
58
|
+
recursive?: false | undefined;
|
|
59
|
+
}) | null): Promise<void>;
|
|
60
|
+
declare function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
|
|
61
|
+
declare function open(path: PathLike, flags?: string | number, mode?: Mode): Promise<FileHandle>;
|
|
62
|
+
declare function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
|
63
|
+
declare function readlink(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
64
|
+
declare function readlink(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
|
65
|
+
declare function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
|
|
66
|
+
declare function lstat(path: PathLike, opts?: StatOptions & {
|
|
67
|
+
bigint?: false | undefined;
|
|
68
|
+
}): Promise<Stats>;
|
|
69
|
+
declare function lstat(path: PathLike, opts: StatOptions & {
|
|
70
|
+
bigint: true;
|
|
71
|
+
}): Promise<BigIntStats>;
|
|
72
|
+
declare function lstat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
|
73
|
+
declare function stat(path: PathLike, opts?: StatOptions & {
|
|
74
|
+
bigint?: false | undefined;
|
|
75
|
+
}): Promise<Stats>;
|
|
76
|
+
declare function stat(path: PathLike, opts: StatOptions & {
|
|
77
|
+
bigint: true;
|
|
78
|
+
}): Promise<BigIntStats>;
|
|
79
|
+
declare function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
|
80
|
+
declare function readdir(path: PathLike, options?: (ObjectEncodingOptions & {
|
|
81
|
+
withFileTypes?: false | undefined;
|
|
82
|
+
recursive?: boolean | undefined;
|
|
83
|
+
}) | BufferEncoding | null): Promise<string[]>;
|
|
84
|
+
declare function readdir(path: PathLike, options: {
|
|
85
|
+
encoding: "buffer";
|
|
86
|
+
withFileTypes?: false | undefined;
|
|
87
|
+
recursive?: boolean | undefined;
|
|
88
|
+
} | "buffer"): Promise<Buffer[]>;
|
|
89
|
+
declare function readdir(path: PathLike, options?: (ObjectEncodingOptions & {
|
|
90
|
+
withFileTypes?: false | undefined;
|
|
91
|
+
recursive?: boolean | undefined;
|
|
92
|
+
}) | BufferEncoding | null): Promise<string[] | Buffer[]>;
|
|
93
|
+
declare function readdir(path: PathLike, options: ObjectEncodingOptions & {
|
|
94
|
+
withFileTypes: true;
|
|
95
|
+
recursive?: boolean | undefined;
|
|
96
|
+
}): Promise<Dirent[]>;
|
|
97
|
+
declare function readdir(path: PathLike, options: {
|
|
98
|
+
encoding: "buffer";
|
|
99
|
+
withFileTypes: true;
|
|
100
|
+
recursive?: boolean | undefined;
|
|
101
|
+
}): Promise<Dirent<Buffer>[]>;
|
|
102
|
+
declare function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
|
|
103
|
+
declare function unlink(path: PathLike): Promise<void>;
|
|
104
|
+
declare function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
105
|
+
declare function truncate(path: PathLike, len?: number): Promise<void>;
|
package/build/lib-client/doh.js
CHANGED
|
@@ -17,12 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.dohAt = dohAt;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const dns_1 = require("dns");
|
|
23
|
-
function dohAt(dohServerUrl) {
|
|
20
|
+
const service_locator_1 = require("./service-locator");
|
|
21
|
+
function dohAt(request, dohServerUrl) {
|
|
24
22
|
async function resolveTxt(domain) {
|
|
25
|
-
const answer = await sendDohQuestion(dohServerUrl, domain, 'TXT');
|
|
23
|
+
const answer = await sendDohQuestion(request, dohServerUrl, domain, 'TXT');
|
|
26
24
|
let txt = [];
|
|
27
25
|
for (const { data: line } of answer) {
|
|
28
26
|
txt.push([line]);
|
|
@@ -31,38 +29,39 @@ function dohAt(dohServerUrl) {
|
|
|
31
29
|
}
|
|
32
30
|
return { resolveTxt };
|
|
33
31
|
}
|
|
34
|
-
async function sendDohQuestion(serverUrl, domain, type) {
|
|
32
|
+
async function sendDohQuestion(request, serverUrl, domain, type) {
|
|
35
33
|
const opts = {
|
|
36
34
|
method: 'GET',
|
|
37
35
|
url: `${serverUrl}?name=${domain}&type=${type}`,
|
|
36
|
+
requestHeaders: {
|
|
37
|
+
accept: 'application/dns-json'
|
|
38
|
+
},
|
|
38
39
|
responseType: 'json'
|
|
39
40
|
};
|
|
40
|
-
const
|
|
41
|
-
httpsOpts.headers.accept = 'application/dns-json';
|
|
42
|
-
const reply = await (0, request_utils_1.processRequest)(opts => https.request(opts), httpsOpts, opts, undefined)
|
|
41
|
+
const reply = await request(opts)
|
|
43
42
|
.catch((exc) => {
|
|
44
43
|
if (exc.type === 'connect') {
|
|
45
|
-
throw { code:
|
|
44
|
+
throw { code: service_locator_1.CONNREFUSED, hostname: domain, cause: exc };
|
|
46
45
|
}
|
|
47
46
|
else {
|
|
48
|
-
throw { code:
|
|
47
|
+
throw { code: service_locator_1.SERVFAIL, hostname: domain, cause: exc };
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
const { status, data } = reply;
|
|
52
51
|
if (status !== 200) {
|
|
53
52
|
throw {
|
|
54
|
-
code:
|
|
53
|
+
code: service_locator_1.SERVFAIL, hostname: domain,
|
|
55
54
|
message: `status ${reply.status} from DoH server`
|
|
56
55
|
};
|
|
57
56
|
}
|
|
58
57
|
if (data.Status !== 0) {
|
|
59
|
-
throw { code:
|
|
58
|
+
throw { code: service_locator_1.NOTFOUND, hostname: domain };
|
|
60
59
|
}
|
|
61
60
|
if (data.Answer) {
|
|
62
61
|
return data.Answer;
|
|
63
62
|
}
|
|
64
63
|
else {
|
|
65
|
-
throw { code:
|
|
64
|
+
throw { code: service_locator_1.NODATA, hostname: domain };
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
Object.freeze(exports);
|
|
@@ -26,7 +26,6 @@ const file_writing_proc_1 = require("./file-writing-proc");
|
|
|
26
26
|
const operators_1 = require("rxjs/operators");
|
|
27
27
|
const obj_version_file_1 = require("../../lib-common/objs-on-disk/obj-version-file");
|
|
28
28
|
const utils_for_observables_1 = require("../../lib-common/utils-for-observables");
|
|
29
|
-
const types_1 = require("util/types");
|
|
30
29
|
const deferred_1 = require("../../lib-common/processes/deferred");
|
|
31
30
|
class ObjOnDisk {
|
|
32
31
|
constructor(objId, version, objFile, downloader, readable, getBaseSegsOnDisk, downloadsInProgress = undefined) {
|
|
@@ -349,7 +348,7 @@ class Download {
|
|
|
349
348
|
const { chunk, chunkBytes, deferred, segments } = this.segsAsapRequest[0];
|
|
350
349
|
const segment = segments[0];
|
|
351
350
|
try {
|
|
352
|
-
if (
|
|
351
|
+
if (isPromise(segment)) {
|
|
353
352
|
chunkBytes.push(await segment);
|
|
354
353
|
segments.shift();
|
|
355
354
|
}
|
|
@@ -561,6 +560,9 @@ class DownloadsRunner {
|
|
|
561
560
|
exports.DownloadsRunner = DownloadsRunner;
|
|
562
561
|
Object.freeze(DownloadsRunner.prototype);
|
|
563
562
|
Object.freeze(DownloadsRunner);
|
|
563
|
+
function isPromise(object) {
|
|
564
|
+
return !!object.then;
|
|
565
|
+
}
|
|
564
566
|
function makeExecPool(max) {
|
|
565
567
|
return { queue: [], max, numOfRunning: 0 };
|
|
566
568
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as https from 'https';
|
|
2
|
-
import
|
|
1
|
+
import type * as https from 'https';
|
|
2
|
+
import type * as WebSocket from 'ws';
|
|
3
|
+
import type { ClientRequest, OutgoingHttpHeaders } from 'http';
|
|
3
4
|
export declare const SESSION_ID_HEADER = "X-Session-Id";
|
|
4
5
|
export declare const CONTENT_TYPE_HEADER = "Content-Type";
|
|
5
6
|
export interface JSONHttpRequest extends XMLHttpRequest {
|
|
@@ -18,6 +19,7 @@ export interface RequestOpts {
|
|
|
18
19
|
appPath?: string;
|
|
19
20
|
responseType?: 'json' | 'arraybuffer' | 'text';
|
|
20
21
|
sessionId?: string;
|
|
22
|
+
requestHeaders?: OutgoingHttpHeaders;
|
|
21
23
|
responseHeaders?: string[];
|
|
22
24
|
timeout?: number;
|
|
23
25
|
timeoutRetries?: number;
|
|
@@ -30,6 +32,7 @@ export type RequestFn<T> = (opts: RequestOpts, contentType?: ContentType, reqBod
|
|
|
30
32
|
export declare function processRequest<T>(requester: (opts: https.RequestOptions) => ClientRequest, httpsOpts: https.RequestOptions, opts: RequestOpts, reqBody: Uint8Array | undefined, attempt?: number): Promise<Reply<T>>;
|
|
31
33
|
export declare function formHttpsReqOpts(opts: RequestOpts, contentType?: ContentType, reqBody?: Uint8Array): https.RequestOptions;
|
|
32
34
|
export declare function extractIntHeader(rep: Reply<any>, headerName: string): number;
|
|
35
|
+
export type OpenWebSocket = (url: string, sessionId: string) => Promise<Reply<WebSocket>>;
|
|
33
36
|
export interface NetClient {
|
|
34
37
|
/**
|
|
35
38
|
* This makes a 'Content-Type: application/json' request with given json,
|
|
@@ -52,5 +55,6 @@ export interface NetClient {
|
|
|
52
55
|
*/
|
|
53
56
|
doBodylessRequest<T>(opts: RequestOpts): Promise<Reply<T>>;
|
|
54
57
|
reset(): void;
|
|
58
|
+
openWebSocket: (url: string, sessionId: string) => Promise<Reply<WebSocket>>;
|
|
55
59
|
}
|
|
56
|
-
export declare function makeNetClient(request
|
|
60
|
+
export declare function makeNetClient(request: RequestFn<unknown>, openWebSocket: NetClient['openWebSocket'], reset?: () => void): NetClient;
|
|
@@ -22,7 +22,6 @@ exports.extractIntHeader = extractIntHeader;
|
|
|
22
22
|
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
|
-
const https = require("https");
|
|
26
25
|
const rxjs_1 = require("rxjs");
|
|
27
26
|
const buffer_utils_1 = require("../lib-common/buffer-utils");
|
|
28
27
|
const deferred_1 = require("../lib-common/processes/deferred");
|
|
@@ -47,6 +46,7 @@ async function processRequest(requester, httpsOpts, opts, reqBody, attempt = 0)
|
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
function formHttpsReqOpts(opts, contentType, reqBody) {
|
|
49
|
+
var _a;
|
|
50
50
|
if (!opts.url) {
|
|
51
51
|
throw new Error(`Cannot send net request, cause url is not set in given options.`);
|
|
52
52
|
}
|
|
@@ -60,7 +60,7 @@ function formHttpsReqOpts(opts, contentType, reqBody) {
|
|
|
60
60
|
hostname: url.hostname,
|
|
61
61
|
port: url.port,
|
|
62
62
|
path: url.pathname + url.search,
|
|
63
|
-
headers: {}
|
|
63
|
+
headers: (_a = opts.requestHeaders) !== null && _a !== void 0 ? _a : {}
|
|
64
64
|
};
|
|
65
65
|
if (reqBody) {
|
|
66
66
|
netReqOpts.headers['Content-Length'] = reqBody.length;
|
|
@@ -178,14 +178,7 @@ function extractIntHeader(rep, headerName) {
|
|
|
178
178
|
}
|
|
179
179
|
return intHeader;
|
|
180
180
|
}
|
|
181
|
-
function
|
|
182
|
-
const nodeRequest = (opts) => https.request(opts);
|
|
183
|
-
return (opts, contentType, reqBody) => {
|
|
184
|
-
const httpsOpts = formHttpsReqOpts(opts, contentType, reqBody);
|
|
185
|
-
return processRequest(nodeRequest, httpsOpts, opts, reqBody);
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
function makeNetClient(request = makeNodeRequest(), reset = () => { }) {
|
|
181
|
+
function makeNetClient(request, openWebSocket, reset = () => { }) {
|
|
189
182
|
const client = {
|
|
190
183
|
doBinaryRequest(opts, bytes) {
|
|
191
184
|
let reqBody;
|
|
@@ -208,7 +201,8 @@ function makeNetClient(request = makeNodeRequest(), reset = () => { }) {
|
|
|
208
201
|
const reqBody = ((json === undefined) ? new Uint8Array(0) : buffer_utils_1.utf8.pack(JSON.stringify(json)));
|
|
209
202
|
return request(opts, 'application/json', reqBody);
|
|
210
203
|
},
|
|
211
|
-
reset
|
|
204
|
+
reset,
|
|
205
|
+
openWebSocket
|
|
212
206
|
};
|
|
213
207
|
return Object.freeze(client);
|
|
214
208
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NetClient } from "./request-utils";
|
|
2
|
+
import { ServiceLocatorMaker } from "./service-locator";
|
|
2
3
|
export interface Check {
|
|
3
4
|
service: 'signup' | 'asmail' | '3nstorage' | 'mailerid';
|
|
4
5
|
}
|
|
@@ -15,4 +16,4 @@ export interface CheckResult extends Check {
|
|
|
15
16
|
message: string;
|
|
16
17
|
err?: any;
|
|
17
18
|
}
|
|
18
|
-
export declare function checkServicesStartingFromSignup(client: NetClient, signupUrl: string, signupToken: string | undefined, progress?: (result: CheckResult | CheckStart) => void): Promise<CheckResult[]>;
|
|
19
|
+
export declare function checkServicesStartingFromSignup(srvLocator: ServiceLocatorMaker, client: NetClient, signupUrl: string, signupToken: string | undefined, progress?: (result: CheckResult | CheckStart) => void): Promise<CheckResult[]>;
|
|
@@ -18,10 +18,8 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.checkServicesStartingFromSignup = checkServicesStartingFromSignup;
|
|
20
20
|
const _3nweb_signup_1 = require("./3nweb-signup");
|
|
21
|
-
const doh_1 = require("./doh");
|
|
22
21
|
const service_locator_1 = require("./service-locator");
|
|
23
|
-
|
|
24
|
-
async function checkServicesStartingFromSignup(client, signupUrl, signupToken, progress) {
|
|
22
|
+
async function checkServicesStartingFromSignup(srvLocator, client, signupUrl, signupToken, progress) {
|
|
25
23
|
const results = [];
|
|
26
24
|
function recordResult(r) {
|
|
27
25
|
progress === null || progress === void 0 ? void 0 : progress(r);
|
|
@@ -35,7 +33,7 @@ async function checkServicesStartingFromSignup(client, signupUrl, signupToken, p
|
|
|
35
33
|
}
|
|
36
34
|
async function checkService(service, userDomain) {
|
|
37
35
|
progress === null || progress === void 0 ? void 0 : progress({ start: true, service, userDomain });
|
|
38
|
-
const check = await checkUserDomainDNS(service, userDomain);
|
|
36
|
+
const check = await checkUserDomainDNS(srvLocator, service, userDomain);
|
|
39
37
|
recordResult(check);
|
|
40
38
|
if (check.isOk) {
|
|
41
39
|
await checkFstServiceEndpoint(service, check.serviceUrl);
|
|
@@ -127,8 +125,12 @@ async function checkSignup(client, signupURL, signupToken) {
|
|
|
127
125
|
};
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
|
-
const srvLocator =
|
|
131
|
-
|
|
128
|
+
// const srvLocator = makeServiceLocator(
|
|
129
|
+
// { resolveTxt: dns.resolveTxt },
|
|
130
|
+
// dohAt(`https://cloudflare-dns.com/dns-query`),
|
|
131
|
+
// dohAt(`https://dns.google/resolve`)
|
|
132
|
+
// );
|
|
133
|
+
async function checkUserDomainDNS(srvLocator, service, domain) {
|
|
132
134
|
try {
|
|
133
135
|
const serviceUrl = await (srvLocator(service, noop))(`u@${domain}`);
|
|
134
136
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NetClient } from './request-utils';
|
|
2
|
-
import { promises as dnsPromises } from 'dns';
|
|
2
|
+
import type { promises as dnsPromises } from 'dns';
|
|
3
3
|
import { StorageRootRoute } from '../lib-common/service-api/3nstorage/root-route';
|
|
4
4
|
import { ASMailRootRoute } from '../lib-common/service-api/asmail/root-route';
|
|
5
5
|
import { LogError } from './logging/log-to-file';
|
|
@@ -33,6 +33,11 @@ export type ServiceLocator = (address: string) => Promise<string>;
|
|
|
33
33
|
export interface DnsResolver {
|
|
34
34
|
resolveTxt: (typeof dnsPromises)['resolveTxt'];
|
|
35
35
|
}
|
|
36
|
+
export declare const NODATA = "ENODATA";
|
|
37
|
+
export declare const SERVFAIL = "ESERVFAIL";
|
|
38
|
+
export declare const NOTFOUND = "ENOTFOUND";
|
|
39
|
+
export declare const CONNREFUSED = "ECONNREFUSED";
|
|
40
|
+
export declare const TIMEOUT = "ETIMEOUT";
|
|
36
41
|
export declare function makeServiceLocator(...resolvers: DnsResolver[]): ServiceLocatorMaker;
|
|
37
42
|
/**
|
|
38
43
|
* @param resolver
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.TIMEOUT = exports.CONNREFUSED = exports.NOTFOUND = exports.SERVFAIL = exports.NODATA = void 0;
|
|
19
20
|
exports.asmailInfoAt = asmailInfoAt;
|
|
20
21
|
exports.mailerIdInfoAt = mailerIdInfoAt;
|
|
21
22
|
exports.storageInfoAt = storageInfoAt;
|
|
22
23
|
exports.makeServiceLocator = makeServiceLocator;
|
|
23
24
|
exports.getMailerIdInfoFor = getMailerIdInfoFor;
|
|
24
25
|
const jwkeys_1 = require("../lib-common/jwkeys");
|
|
25
|
-
|
|
26
|
+
// import { CONNREFUSED, NODATA, NOTFOUND, SERVFAIL, TIMEOUT } from 'dns';
|
|
26
27
|
const runtime_1 = require("../lib-common/exceptions/runtime");
|
|
27
28
|
const http_1 = require("../lib-common/exceptions/http");
|
|
28
29
|
async function readJSONLocatedAt(client, url) {
|
|
@@ -216,6 +217,30 @@ function getRecordAtStartOf(txt) {
|
|
|
216
217
|
value: txt
|
|
217
218
|
};
|
|
218
219
|
}
|
|
220
|
+
exports.NODATA = "ENODATA";
|
|
221
|
+
// export const FORMERR = "EFORMERR";
|
|
222
|
+
exports.SERVFAIL = "ESERVFAIL";
|
|
223
|
+
exports.NOTFOUND = "ENOTFOUND";
|
|
224
|
+
// export const NOTIMP = "ENOTIMP";
|
|
225
|
+
// export const REFUSED = "EREFUSED";
|
|
226
|
+
// export const BADQUERY = "EBADQUERY";
|
|
227
|
+
// export const BADNAME = "EBADNAME";
|
|
228
|
+
// export const BADFAMILY = "EBADFAMILY";
|
|
229
|
+
// export const BADRESP = "EBADRESP";
|
|
230
|
+
exports.CONNREFUSED = "ECONNREFUSED";
|
|
231
|
+
exports.TIMEOUT = "ETIMEOUT";
|
|
232
|
+
// export const EOF = "EOF";
|
|
233
|
+
// export const FILE = "EFILE";
|
|
234
|
+
// export const NOMEM = "ENOMEM";
|
|
235
|
+
// export const DESTRUCTION = "EDESTRUCTION";
|
|
236
|
+
// export const BADSTR = "EBADSTR";
|
|
237
|
+
// export const BADFLAGS = "EBADFLAGS";
|
|
238
|
+
// export const NONAME = "ENONAME";
|
|
239
|
+
// export const BADHINTS = "EBADHINTS";
|
|
240
|
+
// export const NOTINITIALIZED = "ENOTINITIALIZED";
|
|
241
|
+
// export const LOADIPHLPAPI = "ELOADIPHLPAPI";
|
|
242
|
+
// export const ADDRGETNETWORKPARAMS = "EADDRGETNETWORKPARAMS";
|
|
243
|
+
// export const CANCELLED = "ECANCELLED";
|
|
219
244
|
function makeServiceLocator(...resolvers) {
|
|
220
245
|
if (resolvers.length === 0) {
|
|
221
246
|
throw Error(`no DNS resolvers given`);
|
|
@@ -237,17 +262,17 @@ function makeServiceLocator(...resolvers) {
|
|
|
237
262
|
catch (err) {
|
|
238
263
|
await logError(err, `Resolver ${i + 1} fails to get TXT records of ${domain}`);
|
|
239
264
|
const { code, hostname, message } = err;
|
|
240
|
-
if (code ===
|
|
265
|
+
if (code === exports.NODATA) {
|
|
241
266
|
throw noServiceRecordExc(address);
|
|
242
267
|
}
|
|
243
|
-
else if ((code ===
|
|
244
|
-
|| (code ===
|
|
245
|
-
|| (code ===
|
|
268
|
+
else if ((code === exports.SERVFAIL)
|
|
269
|
+
|| (code === exports.CONNREFUSED)
|
|
270
|
+
|| (code === exports.TIMEOUT)) {
|
|
246
271
|
if (!prevConnectionExc) {
|
|
247
272
|
prevConnectionExc = noConnectionExc({ code, hostname, message });
|
|
248
273
|
}
|
|
249
274
|
}
|
|
250
|
-
else if ((code ===
|
|
275
|
+
else if ((code === exports.NOTFOUND) || hostname) {
|
|
251
276
|
throw domainNotFoundExc(address, { code, hostname, message });
|
|
252
277
|
}
|
|
253
278
|
else {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* MailerId and uses respectively authenticated session.
|
|
4
4
|
*/
|
|
5
5
|
import { Reply, RequestOpts, NetClient } from '../lib-client/request-utils';
|
|
6
|
-
import * as WebSocket from 'ws';
|
|
6
|
+
import type * as WebSocket from 'ws';
|
|
7
7
|
import { MailerIdSigner } from '../lib-common/mailerid-sigs/user';
|
|
8
8
|
import { AwaitableState } from '../lib-common/awaitable-state';
|
|
9
9
|
export type IGetMailerIdSigner = () => Promise<MailerIdSigner>;
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
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
|
-
const ws_utils_1 = require("./ws-utils");
|
|
22
21
|
const login_1 = require("./mailer-id/login");
|
|
23
22
|
const assert_1 = require("../lib-common/assert");
|
|
24
23
|
const http_1 = require("../lib-common/exceptions/http");
|
|
@@ -228,7 +227,7 @@ class ServiceUser {
|
|
|
228
227
|
};
|
|
229
228
|
return this.callEnsuringLogin(() => {
|
|
230
229
|
this.prepCallOpts(opts, true);
|
|
231
|
-
return
|
|
230
|
+
return this.net.openWebSocket(opts.url, opts.sessionId);
|
|
232
231
|
});
|
|
233
232
|
}
|
|
234
233
|
}
|
|
@@ -5,7 +5,76 @@ export type { FileHandle, FileException, Stats } from '../injected-globals/platf
|
|
|
5
5
|
* fs functions follow node's type, and are injected via global object to allow injection in
|
|
6
6
|
* non-node environments, like Android or browser.
|
|
7
7
|
*/
|
|
8
|
-
export declare const appendFile:
|
|
8
|
+
export declare const appendFile: (path: import("fs").PathLike | FileHandle, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & import("fs/promises").FlagAndOpenMode & {
|
|
9
|
+
flush?: boolean | undefined;
|
|
10
|
+
}) | BufferEncoding | null) => Promise<void>, lstat: {
|
|
11
|
+
(path: import("fs").PathLike, opts?: import("fs").StatOptions & {
|
|
12
|
+
bigint?: false | undefined;
|
|
13
|
+
}): Promise<import("fs").Stats>;
|
|
14
|
+
(path: import("fs").PathLike, opts: import("fs").StatOptions & {
|
|
15
|
+
bigint: true;
|
|
16
|
+
}): Promise<import("fs").BigIntStats>;
|
|
17
|
+
(path: import("fs").PathLike, opts?: import("fs").StatOptions): Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
18
|
+
}, mkdir: {
|
|
19
|
+
(path: import("fs").PathLike, options: import("fs").MakeDirectoryOptions & {
|
|
20
|
+
recursive: true;
|
|
21
|
+
}): Promise<string | undefined>;
|
|
22
|
+
(path: import("fs").PathLike, options?: import("fs").Mode | (import("fs").MakeDirectoryOptions & {
|
|
23
|
+
recursive?: false | undefined;
|
|
24
|
+
}) | null): Promise<void>;
|
|
25
|
+
(path: import("fs").PathLike, options?: import("fs").Mode | import("fs").MakeDirectoryOptions | null): Promise<string | undefined>;
|
|
26
|
+
}, open: (path: import("fs").PathLike, flags?: string | number, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
|
|
27
|
+
(path: import("fs").PathLike | FileHandle, options?: ({
|
|
28
|
+
encoding?: null | undefined;
|
|
29
|
+
flag?: import("fs").OpenMode | undefined;
|
|
30
|
+
} & import("events").Abortable) | null): Promise<Buffer>;
|
|
31
|
+
(path: import("fs").PathLike | FileHandle, options: ({
|
|
32
|
+
encoding: BufferEncoding;
|
|
33
|
+
flag?: import("fs").OpenMode | undefined;
|
|
34
|
+
} & import("events").Abortable) | BufferEncoding): Promise<string>;
|
|
35
|
+
(path: import("fs").PathLike | FileHandle, options?: (import("fs").ObjectEncodingOptions & import("events").Abortable & {
|
|
36
|
+
flag?: import("fs").OpenMode | undefined;
|
|
37
|
+
}) | BufferEncoding | null): Promise<string | Buffer>;
|
|
38
|
+
}, readdir: {
|
|
39
|
+
(path: import("fs").PathLike, options?: (import("fs").ObjectEncodingOptions & {
|
|
40
|
+
withFileTypes?: false | undefined;
|
|
41
|
+
recursive?: boolean | undefined;
|
|
42
|
+
}) | BufferEncoding | null): Promise<string[]>;
|
|
43
|
+
(path: import("fs").PathLike, options: {
|
|
44
|
+
encoding: "buffer";
|
|
45
|
+
withFileTypes?: false | undefined;
|
|
46
|
+
recursive?: boolean | undefined;
|
|
47
|
+
} | "buffer"): Promise<Buffer[]>;
|
|
48
|
+
(path: import("fs").PathLike, options?: (import("fs").ObjectEncodingOptions & {
|
|
49
|
+
withFileTypes?: false | undefined;
|
|
50
|
+
recursive?: boolean | undefined;
|
|
51
|
+
}) | BufferEncoding | null): Promise<string[] | Buffer[]>;
|
|
52
|
+
(path: import("fs").PathLike, options: import("fs").ObjectEncodingOptions & {
|
|
53
|
+
withFileTypes: true;
|
|
54
|
+
recursive?: boolean | undefined;
|
|
55
|
+
}): Promise<import("fs").Dirent[]>;
|
|
56
|
+
(path: import("fs").PathLike, options: {
|
|
57
|
+
encoding: "buffer";
|
|
58
|
+
withFileTypes: true;
|
|
59
|
+
recursive?: boolean | undefined;
|
|
60
|
+
}): Promise<import("fs").Dirent<Buffer>[]>;
|
|
61
|
+
}, readlink: {
|
|
62
|
+
(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
|
63
|
+
(path: import("fs").PathLike, options: import("fs").BufferEncodingOption): Promise<Buffer>;
|
|
64
|
+
(path: import("fs").PathLike, options?: import("fs").ObjectEncodingOptions | string | null): Promise<string | Buffer>;
|
|
65
|
+
}, rename: (oldPath: import("fs").PathLike, newPath: import("fs").PathLike) => Promise<void>, rmdir: (path: import("fs").PathLike, options?: import("fs").RmDirOptions) => Promise<void>, stat: {
|
|
66
|
+
(path: import("fs").PathLike, opts?: import("fs").StatOptions & {
|
|
67
|
+
bigint?: false | undefined;
|
|
68
|
+
}): Promise<import("fs").Stats>;
|
|
69
|
+
(path: import("fs").PathLike, opts: import("fs").StatOptions & {
|
|
70
|
+
bigint: true;
|
|
71
|
+
}): Promise<import("fs").BigIntStats>;
|
|
72
|
+
(path: import("fs").PathLike, opts?: import("fs").StatOptions): Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
73
|
+
}, symlink: (target: import("fs").PathLike, path: import("fs").PathLike, type?: string | null) => Promise<void>, truncate: (path: import("fs").PathLike, len?: number) => Promise<void>, unlink: (path: import("fs").PathLike) => Promise<void>, writeFile: (file: import("fs").PathLike | FileHandle, data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | import("stream"), options?: (import("fs").ObjectEncodingOptions & {
|
|
74
|
+
mode?: import("fs").Mode | undefined;
|
|
75
|
+
flag?: import("fs").OpenMode | undefined;
|
|
76
|
+
flush?: boolean | undefined;
|
|
77
|
+
} & import("events").Abortable) | BufferEncoding | null) => Promise<void>, copyFile: (src: string, dst: string, overwrite?: boolean, dstMode?: string) => Promise<void>;
|
|
9
78
|
/**
|
|
10
79
|
* @param fh is an open file handle
|
|
11
80
|
* @param pos is a position in the file, from which reading should start
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { SubscribingClient } from './generic-ipc';
|
|
3
|
-
import * as WebSocket from 'ws';
|
|
3
|
+
import type * as WebSocket from 'ws';
|
|
4
4
|
import type { ConnectException, HTTPException } from '../exceptions/http';
|
|
5
5
|
export { RequestEnvelope, RequestHandler, EventfulServer, makeEventfulServer, SubscribingClient } from './generic-ipc';
|
|
6
6
|
export interface WSException extends web3n.RuntimeException {
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2026 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
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/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.makeRequestFromNode = makeRequestFromNode;
|
|
20
|
+
const https = require("https");
|
|
21
|
+
const request_utils_1 = require("../lib-client/request-utils");
|
|
22
|
+
function makeRequestFromNode() {
|
|
23
|
+
const nodeRequest = (opts) => https.request(opts);
|
|
24
|
+
return (opts, contentType, reqBody) => {
|
|
25
|
+
const httpsOpts = (0, request_utils_1.formHttpsReqOpts)(opts, contentType, reqBody);
|
|
26
|
+
return (0, request_utils_1.processRequest)(nodeRequest, httpsOpts, opts, reqBody);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -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
|
-
exports.
|
|
19
|
+
exports.openSocketFromNode = openSocketFromNode;
|
|
19
20
|
const WebSocket = require("ws");
|
|
20
|
-
const request_utils_1 = require("
|
|
21
|
+
const request_utils_1 = require("../lib-client/request-utils");
|
|
21
22
|
const deferred_1 = require("../lib-common/processes/deferred");
|
|
22
23
|
const http_1 = require("../lib-common/exceptions/http");
|
|
23
24
|
const https_1 = require("https");
|
|
24
|
-
function
|
|
25
|
+
function openSocketFromNode(url, sessionId) {
|
|
25
26
|
if (!url.startsWith('wss://')) {
|
|
26
27
|
throw new Error(`Url protocol must be wss`);
|
|
27
28
|
}
|
package/build/tests/jasmine.js
CHANGED
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
const jasmine = require("jasmine");
|
|
20
|
-
const
|
|
20
|
+
const fs_on_node_1 = require("../lib-common-on-node/fs-on-node");
|
|
21
21
|
// injecting global's expected to be on node
|
|
22
22
|
globalThis.platform = {
|
|
23
|
-
device_fs: (0,
|
|
23
|
+
device_fs: (0, fs_on_node_1.makePlatformDeviceFS)()
|
|
24
24
|
};
|
|
25
25
|
const jas = new jasmine({});
|
|
26
26
|
const specsFromCLI = [];
|
|
@@ -29,6 +29,8 @@ const caps_ipc_wrap_1 = require("./caps-ipc-wrap");
|
|
|
29
29
|
const service_locator_1 = require("../../lib-client/service-locator");
|
|
30
30
|
const dns_1 = require("dns");
|
|
31
31
|
const napi_nacl_1 = require("napi-nacl");
|
|
32
|
+
const request_from_node_1 = require("../../lib-common-on-node/request-from-node");
|
|
33
|
+
const websocket_from_node_1 = require("../../lib-common-on-node/websocket-from-node");
|
|
32
34
|
exports.testApp = {
|
|
33
35
|
appDomain: 'test.3nweb.app',
|
|
34
36
|
capsRequested: {
|
|
@@ -80,7 +82,7 @@ class CoreRunner {
|
|
|
80
82
|
this.appCaps.close();
|
|
81
83
|
this.appCaps = undefined;
|
|
82
84
|
}
|
|
83
|
-
this.runningCore = lib_index_1.Core.make({ dataDir: this.dataFolder, signUpUrl: this.signUpUrl }, lib_index_1.makeNetClient, (0, service_locator_1.makeServiceLocator)({
|
|
85
|
+
this.runningCore = lib_index_1.Core.make({ dataDir: this.dataFolder, signUpUrl: this.signUpUrl }, () => (0, lib_index_1.makeNetClient)((0, request_from_node_1.makeRequestFromNode)(), websocket_from_node_1.openSocketFromNode), (0, service_locator_1.makeServiceLocator)({
|
|
84
86
|
resolveTxt: domain => new Promise((resolve, reject) => (0, dns_1.resolveTxt)(domain, (err, texts) => {
|
|
85
87
|
if (err) {
|
|
86
88
|
reject(err);
|
|
@@ -28,6 +28,8 @@ const assert_1 = require("../../lib-common/assert");
|
|
|
28
28
|
const request_utils_1 = require("../../lib-client/request-utils");
|
|
29
29
|
const retrieval_1 = require("../../lib-common/service-api/asmail/retrieval");
|
|
30
30
|
const sleep_1 = require("../../lib-common/processes/sleep");
|
|
31
|
+
const request_from_node_1 = require("../../lib-common-on-node/request-from-node");
|
|
32
|
+
const websocket_from_node_1 = require("../../lib-common-on-node/websocket-from-node");
|
|
31
33
|
const SERVICE_PORT = 8088;
|
|
32
34
|
const SIGNUP_URL = `https://localhost:${SERVICE_PORT}/signup/`;
|
|
33
35
|
function makeSetupObject(domains) {
|
|
@@ -260,7 +262,7 @@ function domainFromUserId(userId) {
|
|
|
260
262
|
function serviceWithMailerIdLogin() {
|
|
261
263
|
const testSrv = (new URL(SIGNUP_URL)).host;
|
|
262
264
|
const serviceUrl = `https://${testSrv}/asmail/retrieval/login/mailerid`;
|
|
263
|
-
const net = (0, request_utils_1.makeNetClient)();
|
|
265
|
+
const net = (0, request_utils_1.makeNetClient)((0, request_from_node_1.makeRequestFromNode)(), websocket_from_node_1.openSocketFromNode);
|
|
264
266
|
async function isSessionValid(sessionId) {
|
|
265
267
|
const rep = await net.doBodylessRequest({
|
|
266
268
|
url: `https://${testSrv}/asmail/retrieval/${retrieval_1.listMsgs.genUrlEnd()}`,
|
package/package.json
CHANGED
|
File without changes
|