core-3nweb-client-lib 0.53.12 → 0.53.14

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.
Files changed (28) hide show
  1. package/build/core/asmail/delivery/per-recipient-wip.js +2 -3
  2. package/build/core/asmail/inbox/inbox-events.d.ts +3 -3
  3. package/build/core/asmail/inbox/inbox-events.js +34 -43
  4. package/build/core/asmail/inbox/index.js +3 -2
  5. package/build/core/storage/index.js +3 -18
  6. package/build/core/storage/synced/obj-status.js +1 -0
  7. package/build/core/storage/synced/remote-events.d.ts +4 -5
  8. package/build/core/storage/synced/remote-events.js +37 -45
  9. package/build/core/storage/synced/storage.js +5 -5
  10. package/build/lib-client/3nstorage/storage-owner.d.ts +1 -1
  11. package/build/lib-client/asmail/recipient.d.ts +1 -1
  12. package/build/lib-client/request-utils.d.ts +1 -0
  13. package/build/lib-client/request-utils.js +7 -0
  14. package/build/lib-client/user-with-mid-session.d.ts +1 -1
  15. package/build/lib-client/user-with-mid-session.js +14 -10
  16. package/build/lib-common/{awaitable-state.js → processes/awaitable-state.js} +1 -1
  17. package/build/lib-common/{periodic-trigger.js → processes/periodic-trigger.js} +4 -3
  18. package/build/lib-common/utils-for-observables.d.ts +10 -0
  19. package/build/lib-common/utils-for-observables.js +48 -2
  20. package/build/lib-common-on-node/request-from-node.d.ts +1 -1
  21. package/build/lib-common-on-node/request-from-node.js +13 -3
  22. package/build/lib-common-on-node/websocket-from-node.d.ts +6 -0
  23. package/build/lib-common-on-node/websocket-from-node.js +9 -5
  24. package/package.json +1 -1
  25. package/build/lib-common/ipc/ws-ipc.d.ts +0 -20
  26. package/build/lib-common/ipc/ws-ipc.js +0 -98
  27. /package/build/lib-common/{awaitable-state.d.ts → processes/awaitable-state.d.ts} +0 -0
  28. /package/build/lib-common/{periodic-trigger.d.ts → processes/periodic-trigger.d.ts} +0 -0
@@ -122,10 +122,9 @@ class WIP {
122
122
  return;
123
123
  }
124
124
  this.state.stage = undefined;
125
- if (!this.sender.sessionId) {
126
- return;
125
+ if (this.sender.sessionId) {
126
+ await this.sender.cancelDelivery();
127
127
  }
128
- await this.sender.cancelDelivery();
129
128
  });
130
129
  }
131
130
  async startSession() {
@@ -1,7 +1,7 @@
1
1
  import { MailRecipient } from '../../../lib-client/asmail/recipient';
2
2
  import { Observable } from 'rxjs';
3
3
  import { LogError } from '../../../lib-client/logging/log-to-file';
4
- import type { ConnectionStatus } from '../../../lib-client/request-utils';
4
+ import { type ConnectionStatus } from '../../../lib-client/request-utils';
5
5
  type IncomingMessage = web3n.asmail.IncomingMessage;
6
6
  type InboxEventType = web3n.asmail.InboxEventType;
7
7
  type Observer<T> = web3n.Observer<T>;
@@ -29,10 +29,10 @@ export declare class InboxEvents {
29
29
  private readonly newMsg$;
30
30
  private readonly connectionEvents;
31
31
  readonly connectionEvent$: Observable<InboxConnectionStatus>;
32
- private readonly wsProc;
32
+ private listening;
33
33
  private disconnectedAt;
34
34
  constructor(msgReceiver: MailRecipient, getMsg: (msgId: string) => Promise<IncomingMessage>, listNewMsgs: (fromTS: number) => Promise<MsgInfo[]>, rmMsg: (msgId: string) => Promise<void>, logError: LogError);
35
- private makeProc;
35
+ private subscribeToEventSrcAndPassHeartbeats;
36
36
  whenConnected(): Promise<void>;
37
37
  isConnected(): boolean;
38
38
  private getMessage;
@@ -21,14 +21,13 @@ const rxjs_1 = require("rxjs");
21
21
  const retrieval_1 = require("../../../lib-common/service-api/asmail/retrieval");
22
22
  const operators_1 = require("rxjs/operators");
23
23
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
24
- const ws_ipc_1 = require("../../../lib-common/ipc/ws-ipc");
24
+ const request_utils_1 = require("../../../lib-client/request-utils");
25
25
  function toInboxConnectionStatus(status, params) {
26
- return (0, ws_ipc_1.addToStatus)(status, {
26
+ return (0, request_utils_1.addToStatus)(status, {
27
27
  service: 'inbox',
28
28
  ...params
29
29
  });
30
30
  }
31
- const SERVER_EVENTS_RESTART_WAIT_SECS = 5;
32
31
  const BUFFER_MILLIS_FOR_LISTING = 2 * 60 * 1000;
33
32
  /**
34
33
  * Instance of this class handles event subscription from UI side. It observes
@@ -51,38 +50,36 @@ class InboxEvents {
51
50
  this.newMsg$ = this.newMsgs.asObservable().pipe((0, operators_1.share)());
52
51
  this.connectionEvents = new rxjs_1.Subject();
53
52
  this.connectionEvent$ = this.connectionEvents.asObservable().pipe((0, operators_1.share)());
53
+ this.listening = new utils_for_observables_1.CancellableProcHolder();
54
54
  this.disconnectedAt = undefined;
55
- this.wsProc = new ws_ipc_1.WebSocketListening(SERVER_EVENTS_RESTART_WAIT_SECS, this.makeProc.bind(this));
56
- this.wsProc.startListening();
57
55
  Object.seal(this);
58
56
  }
59
- makeProc() {
60
- const proc$ = (0, rxjs_1.from)(this.msgReceiver.openEventSource().then(({ client, watchHeartbeat }) => {
61
- const channel = retrieval_1.msgRecievedCompletely.EVENT_NAME;
62
- watchHeartbeat({
63
- next: ev => {
64
- this.connectionEvents.next(toInboxConnectionStatus(ev));
65
- if (ev.type === 'heartbeat') {
66
- this.msgReceiver.connectedState.setState();
67
- }
68
- else if ((ev.type === 'heartbeat-skip') || (ev.type === 'disconnected')) {
69
- this.msgReceiver.connectedState.clearState();
70
- }
57
+ async subscribeToEventSrcAndPassHeartbeats() {
58
+ const { client, watchHeartbeat } = await this.msgReceiver.openEventSource();
59
+ this.msgReceiver.connectedState.setState();
60
+ const channel = retrieval_1.msgRecievedCompletely.EVENT_NAME;
61
+ watchHeartbeat({
62
+ next: ev => {
63
+ this.connectionEvents.next(toInboxConnectionStatus(ev));
64
+ if (ev.type === 'heartbeat' || ev.type == 'connected') {
65
+ this.msgReceiver.connectedState.setState();
71
66
  }
72
- });
73
- return new rxjs_1.Observable(obs => client.subscribe(channel, obs));
74
- }))
75
- .pipe((0, operators_1.mergeMap)(events => events), (0, operators_1.mergeMap)(async (ev) => this.getMessage(ev.msgId), 5), (0, operators_1.filter)(msg => !!msg), (0, operators_1.tap)({
76
- next: msg => this.newMsgs.next(msg),
77
- error: () => {
78
- if (!this.disconnectedAt) {
79
- this.disconnectedAt = Date.now();
67
+ else if ((ev.type === 'heartbeat-skip') || (ev.type === 'disconnected')) {
68
+ this.msgReceiver.connectedState.clearState();
80
69
  }
81
70
  }
82
- }));
71
+ });
72
+ const proc = new rxjs_1.Observable(obs => client.subscribe(channel, obs))
73
+ .pipe((0, operators_1.mergeMap)(async (ev) => {
74
+ const msg = await this.getMessage(ev.msgId);
75
+ if (msg) {
76
+ this.newMsgs.next(msg);
77
+ }
78
+ return ev;
79
+ }, 5));
83
80
  // list messages as a side effect of starting, or at point of starting.
84
81
  this.listMsgsFromDisconnectedPeriod();
85
- return proc$;
82
+ return proc;
86
83
  }
87
84
  async whenConnected() {
88
85
  return this.msgReceiver.connectedState.whenStateIsSet();
@@ -108,28 +105,22 @@ class InboxEvents {
108
105
  }
109
106
  }
110
107
  close() {
108
+ this.listening.stop();
111
109
  this.newMsgs.complete();
112
- this.wsProc.close();
113
110
  }
114
- // XXX we should go along:
115
- // - last working connection and ping
116
- // - may be have an expect suspending of network, with less aggressive attempts to reconnect
117
- // - instead of talking about presence of network, expose methods to nudge restarting behaviour, as outside
118
- // may have better clues and able to command behaviour switch
119
111
  suspendNetworkActivity() {
120
- // XXX code below shutdown for good, but restart sometimes has been failing.
121
- //
122
- // if (this.isListening) {
123
- // if (!this.disconnectedAt) {
124
- // this.disconnectedAt = Date.now();
125
- // }
126
- // this.stopListening();
127
- // }
112
+ this.listening.stop();
128
113
  }
129
114
  resumeNetworkActivity() {
130
- if (!this.wsProc.isListening) {
131
- this.wsProc.startListening();
115
+ if (this.listening.proc) {
116
+ this.listening.startWith(this.listening.proc.completion.then(() => this.subscribeToEventSrcAndPassHeartbeats()));
132
117
  }
118
+ else {
119
+ this.listening.startWith(this.subscribeToEventSrcAndPassHeartbeats());
120
+ }
121
+ this.listening.proc.completion.then(() => {
122
+ this.disconnectedAt = Date.now();
123
+ });
133
124
  }
134
125
  async listMsgsFromDisconnectedPeriod() {
135
126
  if (!this.disconnectedAt) {
@@ -30,8 +30,8 @@ const msg_downloader_1 = require("./msg-downloader");
30
30
  const cached_msgs_1 = require("./cached-msgs");
31
31
  const timed_cache_1 = require("../../../lib-common/timed-cache");
32
32
  const fs_sync_utils_1 = require("../../../lib-client/fs-utils/fs-sync-utils");
33
- const periodic_trigger_1 = require("../../../lib-common/periodic-trigger");
34
- const CONNECTION_CHECK_WAIT_SECS = 30;
33
+ const periodic_trigger_1 = require("../../../lib-common/processes/periodic-trigger");
34
+ const CONNECTION_CHECK_WAIT_SECS = 15;
35
35
  const MSG_INDEX_FOLDER = 'msg-index';
36
36
  async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
37
37
  const procs = new synced_1.NamedProcs();
@@ -45,6 +45,7 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
45
45
  const cache = await cached_msgs_1.CachedMessages.makeFor(cachePath, downloader, r.logError);
46
46
  const index = await (0, msg_indexing_1.makeMsgIndex)(indexSyncedFS, indexLocalFS, r.logError);
47
47
  const inboxEvents = new inbox_events_1.InboxEvents(msgReceiver, getMsg, listNewMsgs, removeMsg, r.logError);
48
+ inboxEvents.resumeNetworkActivity();
48
49
  let stopConnectionCheckingProc = (0, periodic_trigger_1.startPeriodicConditionalTriggerProc)(() => !inboxEvents.isConnected(), () => inboxEvents.resumeNetworkActivity(), CONNECTION_CHECK_WAIT_SECS);
49
50
  async function close() {
50
51
  stopConnectionCheckingProc === null || stopConnectionCheckingProc === void 0 ? void 0 : stopConnectionCheckingProc();
@@ -437,7 +437,6 @@ class PerAppStorage {
437
437
  constructor(appFSsFactory, appDomain, policy) {
438
438
  this.appFSsFactory = appFSsFactory;
439
439
  this.policy = policy;
440
- this.appFSs = new Map();
441
440
  this.revAppDomain = reverseDomain(appDomain);
442
441
  Object.seal(this);
443
442
  }
@@ -453,29 +452,21 @@ class PerAppStorage {
453
452
  cap.getSysFS = this.getSysFS.bind(this);
454
453
  }
455
454
  Object.freeze(cap);
456
- return { cap, close: () => this.close() };
455
+ return { cap, close: () => { } };
457
456
  }
458
457
  async getAppSyncedFS(appName) {
459
458
  if (!appName) {
460
459
  appName = this.revAppDomain;
461
460
  }
462
461
  this.ensureAppFSAllowed(appName, 'synced');
463
- let appFS = this.appFSs.get(appName);
464
- if (!appFS) {
465
- appFS = await this.appFSsFactory.makeSyncedFSForApp(appName);
466
- }
467
- return appFS;
462
+ return await this.appFSsFactory.makeSyncedFSForApp(appName);
468
463
  }
469
464
  async getAppLocalFS(appName) {
470
465
  if (!appName) {
471
466
  appName = this.revAppDomain;
472
467
  }
473
468
  this.ensureAppFSAllowed(appName, 'local');
474
- let appFS = this.appFSs.get(appName);
475
- if (!appFS) {
476
- appFS = await this.appFSsFactory.makeLocalFSForApp(appName);
477
- }
478
- return appFS;
469
+ return await this.appFSsFactory.makeLocalFSForApp(appName);
479
470
  }
480
471
  /**
481
472
  * This throws up, if given file system is not allowed to be opened.
@@ -515,12 +506,6 @@ class PerAppStorage {
515
506
  const sysFS = await this.appFSsFactory.getSysFSs(type);
516
507
  return applyPolicyToFSItem(sysFS, policy, path);
517
508
  }
518
- close() {
519
- for (const fs of this.appFSs.values()) {
520
- this.appFSsFactory.addPreCloseWait(fs.close());
521
- }
522
- this.appFSs.clear();
523
- }
524
509
  }
525
510
  Object.freeze(PerAppStorage.prototype);
526
511
  Object.freeze(PerAppStorage);
@@ -518,6 +518,7 @@ class ObjStatus {
518
518
  const { local, remote } = this.status;
519
519
  if (this.stateIndicator !== 'behind') {
520
520
  if (this.stateIndicator === 'synced') {
521
+ // sync has already been done, nothing to do
521
522
  return;
522
523
  }
523
524
  else if ((this.stateIndicator === 'conflicting') && !version) {
@@ -3,7 +3,7 @@ import { StorageOwner } from '../../../lib-client/3nstorage/storage-owner';
3
3
  import { ObjFiles } from './obj-files';
4
4
  import { Storage } from '../../../lib-client/xsp-fs/common';
5
5
  import type { LogError } from '../../../lib-client/logging/log-to-file';
6
- import type { ConnectionStatus } from '../../../lib-client/request-utils';
6
+ import { type ConnectionStatus } from '../../../lib-client/request-utils';
7
7
  export interface StorageConnectionStatus extends ConnectionStatus {
8
8
  service: 'storage';
9
9
  }
@@ -18,10 +18,9 @@ export declare class RemoteEvents {
18
18
  private readonly logError;
19
19
  private readonly connectionEvents;
20
20
  readonly connectionEvent$: Observable<StorageConnectionStatus>;
21
- private readonly wsProc;
21
+ private listening;
22
22
  constructor(remoteStorage: StorageOwner, files: ObjFiles, broadcastNodeEvent: Storage['broadcastNodeEvent'], logError: LogError);
23
- private makeProc;
24
- startListening(): void;
23
+ private subscribeToEventSrcAndPassHeartbeats;
25
24
  close(): Promise<void>;
26
25
  whenConnected(): Promise<void>;
27
26
  isConnected(): boolean;
@@ -29,6 +28,6 @@ export declare class RemoteEvents {
29
28
  private absorbObjRemoval;
30
29
  private absorbObjVersionArchival;
31
30
  private absorbArchVersionRemoval;
32
- suspendNetworkActivity(): void;
31
+ stopNetworkActivity(): void;
33
32
  resumeNetworkActivity(): void;
34
33
  }
@@ -20,15 +20,15 @@ exports.RemoteEvents = void 0;
20
20
  const rxjs_1 = require("rxjs");
21
21
  const owner_1 = require("../../../lib-common/service-api/3nstorage/owner");
22
22
  const operators_1 = require("rxjs/operators");
23
- const ws_ipc_1 = require("../../../lib-common/ipc/ws-ipc");
23
+ const request_utils_1 = require("../../../lib-client/request-utils");
24
24
  const utils_1 = require("../common/utils");
25
+ const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
25
26
  function toStorageConnectionStatus(status, params) {
26
- return (0, ws_ipc_1.addToStatus)(status, {
27
+ return (0, request_utils_1.addToStatus)(status, {
27
28
  service: 'storage',
28
29
  ...params
29
30
  });
30
31
  }
31
- const SERVER_EVENTS_RESTART_WAIT_SECS = 5;
32
32
  /**
33
33
  * Remote events are absorbed into objects' statuses, broadcasting respective
34
34
  * events. Someone down the stream can react to these changes from remote.
@@ -41,39 +41,27 @@ class RemoteEvents {
41
41
  this.logError = logError;
42
42
  this.connectionEvents = new rxjs_1.Subject();
43
43
  this.connectionEvent$ = this.connectionEvents.asObservable().pipe((0, operators_1.share)());
44
- this.wsProc = new ws_ipc_1.WebSocketListening(SERVER_EVENTS_RESTART_WAIT_SECS, this.makeProc.bind(this));
44
+ this.listening = new utils_for_observables_1.CancellableProcHolder();
45
45
  Object.seal(this);
46
46
  }
47
- makeProc() {
48
- return (0, rxjs_1.from)(this.remoteStorage.openEventSource().then(({ client, watchHeartbeat }) => {
49
- this.remoteStorage.connectedState.setState();
50
- watchHeartbeat({
51
- next: ev => {
52
- this.connectionEvents.next(toStorageConnectionStatus(ev));
53
- if (ev.type === 'heartbeat') {
54
- this.remoteStorage.connectedState.setState();
55
- }
56
- else if ((ev.type === 'heartbeat-skip') || (ev.type === 'disconnected')) {
57
- this.remoteStorage.connectedState.clearState();
58
- }
47
+ async subscribeToEventSrcAndPassHeartbeats() {
48
+ const { client, watchHeartbeat } = await this.remoteStorage.openEventSource();
49
+ watchHeartbeat({
50
+ next: ev => {
51
+ this.connectionEvents.next(toStorageConnectionStatus(ev));
52
+ if (ev.type === 'heartbeat') {
53
+ this.remoteStorage.connectedState.setState();
59
54
  }
60
- });
61
- return [
62
- this.absorbObjChange(client),
63
- this.absorbObjRemoval(client),
64
- // XXX commenting out these for now, as server hasn't implemented these
65
- // this.absorbObjVersionArchival(client),
66
- // this.absorbArchVersionRemoval(client)
67
- ];
68
- }))
69
- .pipe((0, operators_1.mergeMap)(event$ => event$), (0, operators_1.mergeMap)(event$ => event$));
70
- }
71
- startListening() {
72
- this.wsProc.startListening();
55
+ else if ((ev.type === 'heartbeat-skip') || (ev.type === 'disconnected')) {
56
+ this.remoteStorage.connectedState.clearState();
57
+ }
58
+ }
59
+ });
60
+ return (0, rxjs_1.merge)(this.absorbObjChange(client), this.absorbObjRemoval(client));
73
61
  }
74
62
  async close() {
63
+ this.listening.stop();
75
64
  this.connectionEvents.complete();
76
- this.wsProc.close();
77
65
  }
78
66
  whenConnected() {
79
67
  return this.remoteStorage.connectedState.whenStateIsSet();
@@ -83,8 +71,9 @@ class RemoteEvents {
83
71
  }
84
72
  absorbObjChange(client) {
85
73
  return (new rxjs_1.Observable(obs => client.subscribe(owner_1.events.objChanged.EVENT_NAME, obs)))
86
- .pipe((0, operators_1.mergeMap)(async ({ newVer: newRemoteVersion, objId }) => {
74
+ .pipe((0, operators_1.mergeMap)(async (ev) => {
87
75
  var _a;
76
+ const { newVer: newRemoteVersion, objId } = ev;
88
77
  if (!Number.isInteger(newRemoteVersion) || (newRemoteVersion < 1)) {
89
78
  return;
90
79
  }
@@ -103,12 +92,13 @@ class RemoteEvents {
103
92
  newRemoteVersion,
104
93
  syncStatus: obj.syncStatus().syncStatus()
105
94
  });
95
+ return ev;
106
96
  }, 1));
107
97
  }
108
98
  absorbObjRemoval(client) {
109
99
  return (new rxjs_1.Observable(obs => client.subscribe(owner_1.events.objRemoved.EVENT_NAME, obs)))
110
- .pipe((0, operators_1.filter)(objRmEvent => !!objRmEvent.objId), (0, operators_1.mergeMap)(async ({ objId }) => {
111
- const obj = await this.files.findObj(objId);
100
+ .pipe((0, operators_1.filter)(objRmEvent => !!objRmEvent.objId), (0, operators_1.mergeMap)(async (ev) => {
101
+ const obj = await this.files.findObj(ev.objId);
112
102
  if (!obj) {
113
103
  return;
114
104
  }
@@ -118,11 +108,13 @@ class RemoteEvents {
118
108
  path: '',
119
109
  syncStatus: obj.syncStatus().syncStatus()
120
110
  });
111
+ return ev;
121
112
  }, 1));
122
113
  }
123
114
  absorbObjVersionArchival(client) {
124
115
  return (new rxjs_1.Observable(obs => client.subscribe(owner_1.events.objVersionArchived.EVENT_NAME, obs)))
125
- .pipe((0, operators_1.mergeMap)(async ({ objId, archivedVer }) => {
116
+ .pipe((0, operators_1.mergeMap)(async (ev) => {
117
+ const { objId, archivedVer } = ev;
126
118
  const obj = await this.files.findObj(objId);
127
119
  if (!obj) {
128
120
  return;
@@ -134,11 +126,13 @@ class RemoteEvents {
134
126
  archivedVersion: archivedVer,
135
127
  syncStatus: obj.syncStatus().syncStatus()
136
128
  });
129
+ return ev;
137
130
  }, 1));
138
131
  }
139
132
  absorbArchVersionRemoval(client) {
140
133
  return (new rxjs_1.Observable(obs => client.subscribe(owner_1.events.objArchivedVersionRemoved.EVENT_NAME, obs)))
141
- .pipe((0, operators_1.mergeMap)(async ({ objId, archivedVer }) => {
134
+ .pipe((0, operators_1.mergeMap)(async (ev) => {
135
+ const { objId, archivedVer } = ev;
142
136
  const obj = await this.files.findObj(objId);
143
137
  if (!obj) {
144
138
  return;
@@ -150,20 +144,18 @@ class RemoteEvents {
150
144
  removedArchVer: archivedVer,
151
145
  syncStatus: obj.syncStatus().syncStatus()
152
146
  });
147
+ return ev;
153
148
  }, 1));
154
149
  }
155
- // XXX we should go along:
156
- // - last working connection and ping
157
- // - may be have an expect suspending of network, with less aggressive attempts to reconnect
158
- // - instead of talking about presence of network, expose methods to nudge restarting behaviour, as outside
159
- // may have better clues and able to command behaviour switch
160
- suspendNetworkActivity() {
161
- // XXX
162
- // - ...
150
+ stopNetworkActivity() {
151
+ this.listening.stop();
163
152
  }
164
153
  resumeNetworkActivity() {
165
- if (!this.wsProc.isListening) {
166
- this.wsProc.startListening();
154
+ if (this.listening.proc) {
155
+ this.listening.startWith(this.listening.proc.completion.then(() => this.subscribeToEventSrcAndPassHeartbeats()));
156
+ }
157
+ else {
158
+ this.listening.startWith(this.subscribeToEventSrcAndPassHeartbeats());
167
159
  }
168
160
  }
169
161
  }
@@ -27,8 +27,8 @@ const remote_events_1 = require("./remote-events");
27
27
  const upsyncer_1 = require("./upsyncer");
28
28
  const rxjs_1 = require("rxjs");
29
29
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
30
- const periodic_trigger_1 = require("../../../lib-common/periodic-trigger");
31
- const CONNECTION_CHECK_WAIT_SECS = 30;
30
+ const periodic_trigger_1 = require("../../../lib-common/processes/periodic-trigger");
31
+ const CONNECTION_CHECK_WAIT_SECS = 15;
32
32
  class SyncedStore {
33
33
  constructor(files, remoteStorage, getStorages, cryptor, random, logError) {
34
34
  this.files = files;
@@ -54,7 +54,7 @@ class SyncedStore {
54
54
  return {
55
55
  syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
56
56
  startObjProcs: () => {
57
- s.remoteEvents.startListening();
57
+ s.remoteEvents.resumeNetworkActivity();
58
58
  s.startConnectionCheckingProc();
59
59
  }
60
60
  };
@@ -68,7 +68,7 @@ class SyncedStore {
68
68
  setupRemoteAndStartObjProcs: getSigner => {
69
69
  setMid(getSigner);
70
70
  s.uploader.start();
71
- s.remoteEvents.startListening();
71
+ s.remoteEvents.resumeNetworkActivity();
72
72
  s.startConnectionCheckingProc();
73
73
  }
74
74
  };
@@ -247,7 +247,7 @@ class SyncedStore {
247
247
  }
248
248
  }
249
249
  suspendNetworkActivity() {
250
- this.remoteEvents.suspendNetworkActivity();
250
+ this.remoteEvents.stopNetworkActivity();
251
251
  }
252
252
  resumeNetworkActivity() {
253
253
  this.remoteEvents.resumeNetworkActivity();
@@ -2,8 +2,8 @@ import { ConnectionStatus, NetClient } from '../request-utils';
2
2
  import * as api from '../../lib-common/service-api/3nstorage/owner';
3
3
  import { ServiceUser, IGetMailerIdSigner } from '../user-with-mid-session';
4
4
  import * as keyGen from '../key-derivation';
5
- import { SubscribingClient } from '../../lib-common/ipc/ws-ipc';
6
5
  import { ObjId } from '../xsp-fs/common';
6
+ import { SubscribingClient } from '../../lib-common/ipc/generic-ipc';
7
7
  export type FirstSaveReqOpts = api.PutObjFirstQueryOpts;
8
8
  export type FollowingSaveReqOpts = api.PutObjSecondQueryOpts;
9
9
  type Observer<T> = web3n.Observer<T>;
@@ -1,7 +1,7 @@
1
1
  import { ConnectionStatus, NetClient } from '../request-utils';
2
2
  import * as api from '../../lib-common/service-api/asmail/retrieval';
3
3
  import { ServiceUser, IGetMailerIdSigner } from '../user-with-mid-session';
4
- import { SubscribingClient } from '../../lib-common/ipc/ws-ipc';
4
+ import { SubscribingClient } from '../../lib-common/ipc/generic-ipc';
5
5
  type InboxException = web3n.asmail.InboxException;
6
6
  type Observer<T> = web3n.Observer<T>;
7
7
  export declare function makeMsgNotFoundException(msgId: string): InboxException;
@@ -80,5 +80,6 @@ export interface ConnectionStatus {
80
80
  socketClosed?: true;
81
81
  error?: any;
82
82
  }
83
+ export declare function addToStatus<T extends ConnectionStatus>(status: ConnectionStatus, params: Partial<T>): T;
83
84
  export declare function makeNetClient(request: RequestFn<unknown>, openEventSource: OpenServiceEventsSource, reset?: () => void): NetClient;
84
85
  export {};
@@ -19,6 +19,7 @@ exports.CONTENT_TYPE_HEADER = exports.SESSION_ID_HEADER = void 0;
19
19
  exports.processRequest = processRequest;
20
20
  exports.formHttpsReqOpts = formHttpsReqOpts;
21
21
  exports.extractIntHeader = extractIntHeader;
22
+ exports.addToStatus = addToStatus;
22
23
  exports.makeNetClient = makeNetClient;
23
24
  const http_1 = require("../lib-common/exceptions/http");
24
25
  const bytes_fifo_buffer_1 = require("../lib-common/byte-streaming/bytes-fifo-buffer");
@@ -178,6 +179,12 @@ function extractIntHeader(rep, headerName) {
178
179
  }
179
180
  return intHeader;
180
181
  }
182
+ function addToStatus(status, params) {
183
+ for (const [field, value] of Object.entries(params)) {
184
+ status[field] = value;
185
+ }
186
+ return status;
187
+ }
181
188
  function makeNetClient(request, openEventSource, reset = () => { }) {
182
189
  const client = {
183
190
  doBinaryRequest(opts, bytes) {
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { Reply, RequestOpts, NetClient, ServiceEventsSource } from '../lib-client/request-utils';
6
6
  import { MailerIdSigner } from '../lib-common/mailerid-sigs/user';
7
- import { AwaitableState } from '../lib-common/awaitable-state';
7
+ import { AwaitableState } from '../lib-common/processes/awaitable-state';
8
8
  export type IGetMailerIdSigner = () => Promise<MailerIdSigner>;
9
9
  export interface ServiceAccessParams {
10
10
  login: string;
@@ -21,7 +21,7 @@ const api = require("../lib-common/service-api/mailer-id/login");
21
21
  const login_1 = require("./mailer-id/login");
22
22
  const assert_1 = require("../lib-common/assert");
23
23
  const http_1 = require("../lib-common/exceptions/http");
24
- const awaitable_state_1 = require("../lib-common/awaitable-state");
24
+ const awaitable_state_1 = require("../lib-common/processes/awaitable-state");
25
25
  class ServiceUser {
26
26
  get serviceURI() {
27
27
  return this.uri;
@@ -127,17 +127,21 @@ class ServiceUser {
127
127
  return this.loginProc;
128
128
  }
129
129
  this.loginProc = (async () => {
130
- await this.initServiceURI();
131
- const sessionId = await this.startSession();
132
- if (!midSigner) {
133
- if (!this.getSigner) {
134
- throw new Error(`MailerId signer is not given, while signer getter is not set at construction time.`);
130
+ try {
131
+ await this.initServiceURI();
132
+ const sessionId = await this.startSession();
133
+ if (!midSigner) {
134
+ if (!this.getSigner) {
135
+ throw new Error(`MailerId signer is not given, while signer getter is not set at construction time.`);
136
+ }
137
+ midSigner = await this.getSigner();
135
138
  }
136
- midSigner = await this.getSigner();
139
+ await this.authenticateSession(sessionId, midSigner);
140
+ this.sessionId = sessionId;
141
+ }
142
+ finally {
143
+ this.loginProc = undefined;
137
144
  }
138
- await this.authenticateSession(sessionId, midSigner);
139
- this.sessionId = sessionId;
140
- this.loginProc = undefined;
141
145
  })();
142
146
  return this.loginProc;
143
147
  }
@@ -17,7 +17,7 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.AwaitableState = void 0;
20
- const deferred_1 = require("./processes/deferred");
20
+ const deferred_1 = require("./deferred");
21
21
  class AwaitableState {
22
22
  constructor() {
23
23
  this.deferredStateSetPoint = (0, deferred_1.defer)();
@@ -18,9 +18,8 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.startPeriodicConditionalTriggerProc = startPeriodicConditionalTriggerProc;
20
20
  function startPeriodicConditionalTriggerProc(shouldTrigger, trigger, timeoutSecond) {
21
- let checkActive = true;
22
21
  function checkAndTrigger() {
23
- if (!checkActive) {
22
+ if (!procIsON) {
24
23
  return;
25
24
  }
26
25
  if (shouldTrigger()) {
@@ -36,8 +35,10 @@ function startPeriodicConditionalTriggerProc(shouldTrigger, trigger, timeoutSeco
36
35
  (_a = triggerTime.unref) === null || _a === void 0 ? void 0 : _a.call(triggerTime);
37
36
  }
38
37
  }
38
+ let procIsON = true;
39
+ setNext();
39
40
  return () => {
40
- checkActive = false;
41
+ procIsON = false;
41
42
  clearTimeout(triggerTime);
42
43
  };
43
44
  }
@@ -36,3 +36,13 @@ export declare class Broadcast<T> {
36
36
  done(err?: any): void;
37
37
  isON(): boolean;
38
38
  }
39
+ export interface CancellableProc {
40
+ completion: Promise<void>;
41
+ stop: () => void;
42
+ }
43
+ export declare function toCancellableProc(procStart: Promise<Observable<unknown>>): CancellableProc;
44
+ export declare class CancellableProcHolder {
45
+ proc: CancellableProc | undefined;
46
+ startWith(procStart: Promise<Observable<unknown>>): void;
47
+ stop(): Promise<void> | undefined;
48
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017, 2019 - 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2017, 2019 - 2020, 2022, 2026 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
6
 
@@ -9,13 +9,15 @@
9
9
  You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Broadcast = void 0;
12
+ exports.CancellableProcHolder = exports.Broadcast = void 0;
13
13
  exports.flatMapComplete = flatMapComplete;
14
14
  exports.allowOnlySingleStart = allowOnlySingleStart;
15
15
  exports.flatTap = flatTap;
16
16
  exports.toRxObserver = toRxObserver;
17
+ exports.toCancellableProc = toCancellableProc;
17
18
  const rxjs_1 = require("rxjs");
18
19
  const operators_1 = require("rxjs/operators");
20
+ const deferred_1 = require("./processes/deferred");
19
21
  /**
20
22
  * This is a pipeable operator that runs given async process on completion and
21
23
  * sends result downstream, followed by complete signal.
@@ -142,3 +144,47 @@ class Broadcast {
142
144
  exports.Broadcast = Broadcast;
143
145
  Object.freeze(Broadcast.prototype);
144
146
  Object.freeze(Broadcast);
147
+ function toCancellableProc(procStart) {
148
+ const whenStops = (0, deferred_1.defer)();
149
+ const sub = (0, rxjs_1.from)(procStart)
150
+ .pipe((0, operators_1.mergeMap)(event$ => event$))
151
+ .subscribe({
152
+ error: () => {
153
+ whenStops.resolve();
154
+ },
155
+ complete: () => {
156
+ whenStops.resolve();
157
+ }
158
+ });
159
+ return {
160
+ stop: () => {
161
+ sub.unsubscribe();
162
+ whenStops.resolve();
163
+ },
164
+ completion: whenStops.promise
165
+ };
166
+ }
167
+ class CancellableProcHolder {
168
+ constructor() {
169
+ this.proc = undefined;
170
+ }
171
+ startWith(procStart) {
172
+ const proc = toCancellableProc(procStart);
173
+ proc.completion.then(() => {
174
+ if (this.proc === proc) {
175
+ this.proc = undefined;
176
+ }
177
+ });
178
+ this.proc = proc;
179
+ }
180
+ stop() {
181
+ const proc = this.proc;
182
+ if (!proc) {
183
+ return;
184
+ }
185
+ this.proc = undefined;
186
+ proc.stop();
187
+ return proc.completion;
188
+ }
189
+ }
190
+ exports.CancellableProcHolder = CancellableProcHolder;
@@ -1,3 +1,3 @@
1
1
  import * as https from 'https';
2
2
  import { RequestFn } from '../lib-client/request-utils';
3
- export declare function makeRequestFromNode(getAgent?: () => https.Agent | undefined): RequestFn<unknown>;
3
+ export declare function makeRequestFromNode(getAgent?: () => https.Agent | undefined, timeout?: number): RequestFn<unknown>;
@@ -23,9 +23,19 @@ const request_utils_1 = require("../lib-client/request-utils");
23
23
  // XXX
24
24
  // we need a request that uses http2, connected to some host:port, relying on downstream
25
25
  // making NetClient requester for every host:port.
26
- function makeRequestFromNode(getAgent) {
27
- const nodeHttpsRequest = (opts) => https.request(opts);
28
- const nodeHttpRequest = (opts) => http.request(opts);
26
+ function makeRequestFromNode(getAgent, timeout = 10000) {
27
+ const nodeHttpsRequest = (opts) => {
28
+ if (!opts.timeout) {
29
+ opts.timeout = timeout;
30
+ }
31
+ return https.request(opts);
32
+ };
33
+ const nodeHttpRequest = (opts) => {
34
+ if (!opts.timeout) {
35
+ opts.timeout = timeout;
36
+ }
37
+ return http.request(opts);
38
+ };
29
39
  return (opts, reqContentType, reqBody) => {
30
40
  const reqOpts = (0, request_utils_1.formHttpsReqOpts)(opts, reqContentType, reqBody);
31
41
  const agent = getAgent === null || getAgent === void 0 ? void 0 : getAgent();
@@ -1,3 +1,9 @@
1
1
  import { OpenServiceEventsSource } from '../lib-client/request-utils';
2
2
  import { Agent } from 'https';
3
+ export interface WSException extends web3n.RuntimeException {
4
+ type: 'websocket';
5
+ socketSlow?: true;
6
+ socketClosed?: true;
7
+ }
8
+ export declare function makeWSException(params: Partial<WSException>, flags?: Partial<WSException>): WSException;
3
9
  export declare function makeServiceEventsSourceFromNode(getAgent?: () => Agent | undefined): OpenServiceEventsSource;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017, 2019, 2025 3NSoft Inc.
3
+ Copyright (C) 2017, 2019, 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
@@ -16,6 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.makeWSException = makeWSException;
19
20
  exports.makeServiceEventsSourceFromNode = makeServiceEventsSourceFromNode;
20
21
  const WebSocket = require("ws");
21
22
  const request_utils_1 = require("../lib-client/request-utils");
@@ -23,8 +24,11 @@ const deferred_1 = require("../lib-common/processes/deferred");
23
24
  const http_1 = require("../lib-common/exceptions/http");
24
25
  const https_1 = require("https");
25
26
  const generic_ipc_1 = require("../lib-common/ipc/generic-ipc");
26
- const ws_ipc_1 = require("../lib-common/ipc/ws-ipc");
27
27
  const rxjs_1 = require("rxjs");
28
+ const runtime_1 = require("../lib-common/exceptions/runtime");
29
+ function makeWSException(params, flags) {
30
+ return (0, runtime_1.makeRuntimeException)('websocket', params, flags !== null && flags !== void 0 ? flags : {});
31
+ }
28
32
  function makeServiceEventsSourceFromNode(getAgent) {
29
33
  return async function openServiceEventsSrcFromNode(req) {
30
34
  const { url, sessionId } = req;
@@ -97,7 +101,7 @@ function makeJsonCommPoint(ws) {
97
101
  }
98
102
  else {
99
103
  otherBeat('disconnected', { error: { code, reason } }, true);
100
- observers.error((0, ws_ipc_1.makeWSException)({
104
+ observers.error(makeWSException({
101
105
  socketClosed: true,
102
106
  cause: { code, reason }
103
107
  }));
@@ -105,7 +109,7 @@ function makeJsonCommPoint(ws) {
105
109
  });
106
110
  ws.on('error', (err) => {
107
111
  otherBeat('disconnected', err, true);
108
- observers.error((0, ws_ipc_1.makeWSException)({ cause: err }));
112
+ observers.error(makeWSException({ cause: err }));
109
113
  clearInterval(pingRepeat);
110
114
  ws.close();
111
115
  });
@@ -122,7 +126,7 @@ function makeJsonCommPoint(ws) {
122
126
  postMessage(env) {
123
127
  if (ws.bufferedAmount > MAX_TXT_BUFFER) {
124
128
  otherBeat('heartbeat', { slowSocket: true });
125
- throw (0, ws_ipc_1.makeWSException)({ socketSlow: true });
129
+ throw makeWSException({ socketSlow: true });
126
130
  }
127
131
  ws.send(JSON.stringify(env));
128
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.53.12",
3
+ "version": "0.53.14",
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",
@@ -1,20 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import type { ConnectionStatus } from '../../lib-client/request-utils';
3
- export { RequestEnvelope, RequestHandler, EventfulServer, makeEventfulServer, SubscribingClient } from './generic-ipc';
4
- export interface WSException extends web3n.RuntimeException {
5
- type: 'websocket';
6
- socketSlow?: true;
7
- socketClosed?: true;
8
- }
9
- export declare function makeWSException(params: Partial<WSException>, flags?: Partial<WSException>): WSException;
10
- export declare function addToStatus<T extends ConnectionStatus>(status: ConnectionStatus, params: Partial<T>): T;
11
- export declare class WebSocketListening {
12
- readonly restartWaitSecs: number;
13
- private readonly startWSProc;
14
- private listeningProc;
15
- constructor(restartWaitSecs: number, startWSProc: () => Observable<unknown>);
16
- startListening(): void;
17
- private sleepAndRestart;
18
- close(): void;
19
- get isListening(): boolean;
20
- }
@@ -1,98 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (C) 2017, 2025 - 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.WebSocketListening = exports.makeEventfulServer = void 0;
20
- exports.makeWSException = makeWSException;
21
- exports.addToStatus = addToStatus;
22
- const runtime_1 = require("../exceptions/runtime");
23
- const sleep_1 = require("../processes/sleep");
24
- var generic_ipc_1 = require("./generic-ipc");
25
- Object.defineProperty(exports, "makeEventfulServer", { enumerable: true, get: function () { return generic_ipc_1.makeEventfulServer; } });
26
- function makeWSException(params, flags) {
27
- return (0, runtime_1.makeRuntimeException)('websocket', params, flags !== null && flags !== void 0 ? flags : {});
28
- }
29
- function addToStatus(status, params) {
30
- for (const [field, value] of Object.entries(params)) {
31
- status[field] = value;
32
- }
33
- return status;
34
- }
35
- function shouldRestartWSAfterErr(exc) {
36
- if (!exc.runtimeException) {
37
- return false;
38
- }
39
- if (exc.type === 'connect') {
40
- return true;
41
- }
42
- else if (exc.type === 'http-request') {
43
- return false;
44
- }
45
- else if (exc.type === 'websocket') {
46
- return true;
47
- }
48
- else {
49
- return false;
50
- }
51
- }
52
- class WebSocketListening {
53
- constructor(restartWaitSecs, startWSProc) {
54
- this.restartWaitSecs = restartWaitSecs;
55
- this.startWSProc = startWSProc;
56
- this.listeningProc = undefined;
57
- Object.seal(this);
58
- }
59
- startListening() {
60
- if (this.listeningProc) {
61
- return;
62
- }
63
- const clearListeningProc = () => {
64
- if (this.listeningProc === sub) {
65
- this.listeningProc = undefined;
66
- }
67
- };
68
- const sub = this.startWSProc()
69
- .subscribe({
70
- complete: () => {
71
- clearListeningProc();
72
- },
73
- error: async (exc) => {
74
- clearListeningProc();
75
- if (shouldRestartWSAfterErr(exc)) {
76
- this.sleepAndRestart();
77
- }
78
- }
79
- });
80
- this.listeningProc = sub;
81
- }
82
- async sleepAndRestart() {
83
- await (0, sleep_1.sleep)(this.restartWaitSecs * 1000);
84
- this.startListening();
85
- }
86
- close() {
87
- var _a;
88
- (_a = this.listeningProc) === null || _a === void 0 ? void 0 : _a.unsubscribe();
89
- this.listeningProc = undefined;
90
- }
91
- get isListening() {
92
- return !!this.listeningProc;
93
- }
94
- }
95
- exports.WebSocketListening = WebSocketListening;
96
- Object.freeze(WebSocketListening.prototype);
97
- Object.freeze(WebSocketListening);
98
- Object.freeze(exports);