core-3nweb-client-lib 0.31.3 → 0.31.5

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.
@@ -32,7 +32,7 @@ declare namespace web3n.caps.common {
32
32
  mail?: MailCAPSetting;
33
33
  storage?: StorageCAPSetting;
34
34
  mailerid?: true;
35
- log?: LogCAPSetting;
35
+ logToPlatform?: true;
36
36
  }
37
37
 
38
38
  interface StorageCAPSetting {
@@ -65,12 +65,10 @@ declare namespace web3n.caps.common {
65
65
  receivingFrom?: 'all' | { whitelist: string[]; };
66
66
  }
67
67
 
68
- type LogCAPSetting = 'all';
69
-
70
68
  interface W3N {
69
+ log: Logger;
71
70
  mail?: asmail.Service;
72
71
  storage?: storage.Service;
73
- log?: Logger;
74
72
  mailerid?: mailerid.Service;
75
73
  }
76
74
 
@@ -157,7 +157,7 @@ class Core {
157
157
  }
158
158
  }
159
159
  makeLogCAP(appDomain, requestedCAPs) {
160
- if (requestedCAPs.log === 'all') {
160
+ if (requestedCAPs.logToPlatform === true) {
161
161
  return (type, msg, e) => this.logger.appLog(type, appDomain, msg, e);
162
162
  }
163
163
  else {
@@ -44,15 +44,49 @@ function makeW3Nclient(clientSide, extraCAPs) {
44
44
  mailerid: mailerid_cap_ipc_1.makeMailerIdCaller,
45
45
  storage: storage_cap_ipc_1.makeStorageCaller,
46
46
  };
47
- return (0, generic_1.makeClientSide)(clientSide, mainCAPs, extraCAPs);
47
+ const clientW3N = (0, generic_1.makeClientSide)(clientSide, mainCAPs, extraCAPs);
48
+ addLogToConsoleIfNoCap(clientW3N);
49
+ return clientW3N;
48
50
  }
49
- function promiseW3Nclient(clientSide, extraCAPs) {
51
+ async function promiseW3Nclient(clientSide, extraCAPs) {
50
52
  const mainCAPs = {
51
53
  log: log_cap_1.makeLogCaller,
52
54
  mail: asmail_cap_ipc_1.makeASMailCaller,
53
55
  mailerid: mailerid_cap_ipc_1.makeMailerIdCaller,
54
56
  storage: storage_cap_ipc_1.promiseStorageCaller,
55
57
  };
56
- return (0, generic_1.promiseClientSide)(clientSide, mainCAPs, extraCAPs);
58
+ const clientW3N = await (0, generic_1.promiseClientSide)(clientSide, mainCAPs, extraCAPs);
59
+ addLogToConsoleIfNoCap(clientW3N);
60
+ return clientW3N;
61
+ }
62
+ function addLogToConsoleIfNoCap(clientW3N) {
63
+ if (!clientW3N.log) {
64
+ clientW3N.log = async (type, msg, err) => {
65
+ if (type === 'error') {
66
+ if (err === undefined) {
67
+ console.error(msg);
68
+ }
69
+ else {
70
+ console.error(msg, err);
71
+ }
72
+ }
73
+ else if (type === 'warning') {
74
+ if (err === undefined) {
75
+ console.warn(msg);
76
+ }
77
+ else {
78
+ console.warn(msg, err);
79
+ }
80
+ }
81
+ else {
82
+ if (err === undefined) {
83
+ console.log(msg);
84
+ }
85
+ else {
86
+ console.log(msg, err);
87
+ }
88
+ }
89
+ };
90
+ }
57
91
  }
58
92
  Object.freeze(exports);
@@ -26,6 +26,7 @@ function exposeLogger(fn) {
26
26
  }
27
27
  function makeLogCaller(caller, path) {
28
28
  const log = (0, caller_side_wrap_1.makeReqRepFuncCaller)(caller, path);
29
- return (type, msg, err) => log(type, msg, (0, error_1.stringifyErr)(err));
29
+ return (type, msg, err) => log(type, msg, (0, error_1.stringifyErr)(err)).catch(noop);
30
30
  }
31
+ function noop() { }
31
32
  Object.freeze(exports);
@@ -192,12 +192,12 @@ class ClientsSideImpl {
192
192
  const fnCallNum = reqEnv.headers.fnCallNum.value;
193
193
  try {
194
194
  this.startCall(reqEnv);
195
- return deferred.promise;
196
195
  }
197
196
  catch (err) {
198
197
  this.fnCalls.delete(fnCallNum);
199
- throw err;
198
+ deferred.reject(err);
200
199
  }
200
+ return deferred.promise;
201
201
  }
202
202
  startObservableCall(path, req, obs) {
203
203
  const reqEnv = this.setupFnCall(path, req, undefined, obs);