core-3nweb-client-lib 0.53.0 → 0.53.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.
@@ -1,7 +1,8 @@
1
1
  import { NetClient, RequestFn, OpenServiceEventsSource } from './request-utils';
2
2
  import { LogError } from './logging/log-to-file';
3
3
  export type ServiceTypeDNSLabel = 'mailerid' | 'asmail' | '3nstorage';
4
- export type ServiceLocatorMaker = (serviceLabel: ServiceTypeDNSLabel | 'report', logError: LogError) => ServiceLocator;
4
+ export type DNSLabel = ServiceTypeDNSLabel | 'report' | 'w3nApp';
5
+ export type ServiceLocatorMaker = (serviceLabel: DNSLabel, logError: LogError) => ServiceLocator;
5
6
  export type ServiceLocator = (address: string) => Promise<string>;
6
7
  export interface DnsResolver {
7
8
  resolveTxt: (hostname: string) => Promise<string[][]>;
@@ -34,10 +34,6 @@ function domainOfAddress(address) {
34
34
  return address.substring(indOfAt + 1);
35
35
  }
36
36
  }
37
- function checkAndPrepareURL(value) {
38
- // XXX insert some value sanity check
39
- return 'https://' + value;
40
- }
41
37
  function domainNotFoundExc(address, cause) {
42
38
  return (0, runtime_1.makeRuntimeException)('service-locating', { address, cause }, { domainNotFound: true });
43
39
  }
@@ -94,7 +90,8 @@ const recordsStarts = {
94
90
  "3nstorage": '3nstorage=',
95
91
  asmail: 'asmail=',
96
92
  mailerid: 'mailerid=',
97
- report: 'report='
93
+ report: 'report=',
94
+ w3nApp: 'w3n-app='
98
95
  };
99
96
  function getRecordAtStartOf(txt) {
100
97
  let service = undefined;
@@ -147,23 +144,6 @@ exports.TIMEOUT = "ETIMEOUT";
147
144
  // export const LOADIPHLPAPI = "ELOADIPHLPAPI";
148
145
  // export const ADDRGETNETWORKPARAMS = "EADDRGETNETWORKPARAMS";
149
146
  // export const CANCELLED = "ECANCELLED";
150
- // XXX
151
- // - service exist in network.
152
- // - we go from name to address to service location in a network, and a request function ?
153
- // Or, should we assume that request function will engage with proper network, based on location,
154
- // implying that location string should always map to one network: regular | tor | i2p.
155
- // Implicit rule allows us not to force making request fn here, as well as naming system in one net,
156
- // pointing to another. bank.xyz can be served by server <key>.onion, and vice versa.
157
- //
158
- // - this function, ... doesn't have to change, as DnsResolver is given. May be we should make a more
159
- // general wrap, that gonna use this for DNS in regular net?
160
- // - and, we may probably want to make function here as a reusable wrapper around different network request fns.
161
- // Regular net request, may internally switch into proxy/hidding modes. Other networks provide anonymity,
162
- // hence, these additional options should stay "inside" regular network request fn.
163
- //
164
- // - should we have a reusable wrapper creator here, creating coherent pair of naming and request functions.
165
- // Cause, if embedding doesn't have explicit implementation for Tor, both initial naming and net-maker functions
166
- // should be coherent.
167
147
  const onionTLD = '.onion';
168
148
  const i2pTLD = '.i2p';
169
149
  function makeMissingImplementationException(networkType, location) {
@@ -269,12 +249,7 @@ function makeServiceLocatorInDNS(...resolvers) {
269
249
  }
270
250
  const recValue = extractPair(txtRecords, serviceLabel);
271
251
  if (recValue) {
272
- if (serviceLabel === 'report') {
273
- return recValue;
274
- }
275
- else {
276
- return checkAndPrepareURL(recValue);
277
- }
252
+ return postProcessValue(serviceLabel, recValue);
278
253
  }
279
254
  else {
280
255
  exc !== null && exc !== void 0 ? exc : (exc = noServiceRecordExc(address));
@@ -284,6 +259,18 @@ function makeServiceLocatorInDNS(...resolvers) {
284
259
  }
285
260
  return locateInDNS;
286
261
  }
262
+ function postProcessValue(serviceLabel, recordValue) {
263
+ switch (serviceLabel) {
264
+ case 'report':
265
+ return recordValue;
266
+ default:
267
+ return checkAndPrepareURL(recordValue);
268
+ }
269
+ }
270
+ function checkAndPrepareURL(value) {
271
+ // XXX insert some value sanity check
272
+ return 'https://' + value;
273
+ }
287
274
  const wellKnownPath = '/.well-known/3nweb.json';
288
275
  async function locateInWellKnown(request, address, serviceLabel) {
289
276
  const host = domainOfAddress(address);
@@ -295,12 +282,7 @@ async function locateInWellKnown(request, address, serviceLabel) {
295
282
  if (reply.status === 200) {
296
283
  const recValue = reply.data[serviceLabel];
297
284
  if (recValue) {
298
- if (serviceLabel === 'report') {
299
- return recValue;
300
- }
301
- else {
302
- return checkAndPrepareURL(recValue);
303
- }
285
+ return postProcessValue(serviceLabel, recValue);
304
286
  }
305
287
  else {
306
288
  throw noServiceRecordExc(address);
@@ -63,6 +63,7 @@ exports.testApp = {
63
63
  let numOfRunningCores = 0;
64
64
  const DATA_FOLDER = (0, path_1.join)(__dirname, '..', '..', '..', 'test-data');
65
65
  function resolveTxt(domain) {
66
+ // used non-promise dns method mocked for test data, hence, we use it here
66
67
  return new Promise((resolve, reject) => (0, dns_1.resolveTxt)(domain, (err, records) => {
67
68
  if (err) {
68
69
  reject(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.53.0",
3
+ "version": "0.53.1",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",