core-3nweb-client-lib 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- 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.js +4 -0
- 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/lib-index.d.ts +0 -1
- package/build/lib-index.js +1 -2
- 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
package/README.md
CHANGED
|
@@ -6,18 +6,36 @@
|
|
|
6
6
|
## Development and testing
|
|
7
7
|
|
|
8
8
|
After repository clone, bring down all NodeJS modules, by running in project's folder:
|
|
9
|
-
```
|
|
9
|
+
```bash
|
|
10
10
|
npm ci
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Tests have some unit and integrated components. Integration test uses 3NWeb spec server. Integrated tests use server and dns mocking from `spec-3nweb-server`.
|
|
14
14
|
|
|
15
15
|
Build is done with
|
|
16
|
-
```
|
|
16
|
+
```bash
|
|
17
17
|
npm run build
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Test is done with (after build)
|
|
21
|
-
```
|
|
21
|
+
```bash
|
|
22
22
|
npm run test
|
|
23
23
|
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Reuse on non-Node and injecting implementation
|
|
27
|
+
|
|
28
|
+
To reuse this library in non-Node environments, like Android's jsengine and browser, we need to provide different implementations for access to network, files.
|
|
29
|
+
|
|
30
|
+
Some of these functions are explicitly passed in setup phases, like naming functionality that may either use DNS of DoH. Switch between these may even be done based on same platform, but depending on user prefernces.
|
|
31
|
+
|
|
32
|
+
Other functions, like access to device's file system, depend only on environment. For these we use a bit cheaper injection approach. We articulate types that should be implemented. And modules expect to get implementation from `globalThis`. Hence, environments that use core should inject respective implementations at some early stage.
|
|
33
|
+
|
|
34
|
+
Note that import of implementations of injected for node should be done directly, placing it before other imports that need injected global value(s). Do something like:
|
|
35
|
+
```typescript
|
|
36
|
+
import { makePlatformDeviceFS } from 'core-3nweb-client-lib/build/injected-globals/inject-on-node';
|
|
37
|
+
globalThis.platform = {
|
|
38
|
+
device_fs: makePlatformDeviceFS()
|
|
39
|
+
};
|
|
40
|
+
import ... // other modules
|
|
41
|
+
```
|
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
|
}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
var _a;
|
|
19
|
+
var _b;
|
|
19
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
21
|
exports.copyFile = exports.writeFile = exports.unlink = exports.truncate = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.readFile = exports.open = exports.mkdir = exports.lstat = exports.appendFile = void 0;
|
|
21
22
|
exports.readToBuf = readToBuf;
|
|
@@ -37,6 +38,9 @@ const deferred_1 = require("./processes/deferred");
|
|
|
37
38
|
const bytes_fifo_buffer_1 = require("./byte-streaming/bytes-fifo-buffer");
|
|
38
39
|
const buffer_utils_1 = require("./buffer-utils");
|
|
39
40
|
function noop() { }
|
|
41
|
+
if (!((_b = globalThis.platform) === null || _b === void 0 ? void 0 : _b.device_fs)) {
|
|
42
|
+
throw new Error(`Expected globally injected object globalThis.platform?.device_fs is missing`);
|
|
43
|
+
}
|
|
40
44
|
/**
|
|
41
45
|
* fs functions follow node's type, and are injected via global object to allow injection in
|
|
42
46
|
* non-node environments, like Android or browser.
|
|
@@ -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/lib-index.d.ts
CHANGED
|
@@ -14,4 +14,3 @@ export { makeLogger } from './lib-client/logging/log-to-file';
|
|
|
14
14
|
export declare const SYSTEM_DOMAIN = "3nweb.computer";
|
|
15
15
|
export { checkServicesStartingFromSignup } from './lib-client/service-checks';
|
|
16
16
|
export { dohAt } from './lib-client/doh';
|
|
17
|
-
export * as injectOnNode from './injected-globals/inject-on-node';
|
package/build/lib-index.js
CHANGED
|
@@ -30,7 +30,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
30
30
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
31
31
|
};
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
-
exports.
|
|
33
|
+
exports.dohAt = exports.checkServicesStartingFromSignup = exports.SYSTEM_DOMAIN = exports.makeLogger = exports.DeviceFS = exports.sysFolders = exports.appDirs = exports.makeNetClient = exports.makeServiceLocator = exports.ASMail = exports.SignIn = exports.reverseDomain = exports.Storages = exports.IdManager = exports.SignUp = void 0;
|
|
34
34
|
__exportStar(require("./core"), exports);
|
|
35
35
|
var sign_up_1 = require("./core/startup/sign-up");
|
|
36
36
|
Object.defineProperty(exports, "SignUp", { enumerable: true, get: function () { return sign_up_1.SignUp; } });
|
|
@@ -60,5 +60,4 @@ var service_checks_1 = require("./lib-client/service-checks");
|
|
|
60
60
|
Object.defineProperty(exports, "checkServicesStartingFromSignup", { enumerable: true, get: function () { return service_checks_1.checkServicesStartingFromSignup; } });
|
|
61
61
|
var doh_1 = require("./lib-client/doh");
|
|
62
62
|
Object.defineProperty(exports, "dohAt", { enumerable: true, get: function () { return doh_1.dohAt; } });
|
|
63
|
-
exports.injectOnNode = require("./injected-globals/inject-on-node");
|
|
64
63
|
Object.freeze(exports);
|
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
|