@zeniai/client-epic-state 5.0.12-beta2ND → 5.0.12-betaVR1
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/lib/coreEpics.js +1 -2
- package/lib/entity/tenant/tenantReducer.d.ts +1 -5
- package/lib/entity/tenant/tenantReducer.js +2 -23
- package/lib/entity/tenant/tenantState.d.ts +0 -1
- package/lib/epic.d.ts +6 -7
- package/lib/epic.js +6 -7
- package/lib/esm/coreEpics.js +1 -2
- package/lib/esm/entity/tenant/tenantReducer.js +1 -21
- package/lib/esm/epic.js +6 -7
- package/lib/esm/index.js +2 -5
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +6 -2
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +7 -2
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +7 -3
- package/lib/index.d.ts +2 -5
- package/lib/index.js +30 -36
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +6 -2
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +7 -2
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +7 -7
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +7 -3
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +2 -2
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +2 -2
- package/package.json +2 -2
- package/lib/entity/tenant/SessionManager.d.ts +0 -56
- package/lib/entity/tenant/SessionManager.js +0 -310
- package/lib/entity/tenant/epic/sessionHeartbeatEpic.d.ts +0 -16
- package/lib/entity/tenant/epic/sessionHeartbeatEpic.js +0 -16
- package/lib/entity/tenant/sessionTypes.d.ts +0 -26
- package/lib/entity/tenant/sessionTypes.js +0 -12
- package/lib/esm/entity/tenant/SessionManager.js +0 -306
- package/lib/esm/entity/tenant/epic/sessionHeartbeatEpic.js +0 -12
- package/lib/esm/entity/tenant/sessionTypes.js +0 -9
- package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SessionManager — Central session lifecycle manager.
|
|
3
|
-
*
|
|
4
|
-
* Responsibilities:
|
|
5
|
-
* 1. Track user activity (mousemove, keydown, click, scroll, touch)
|
|
6
|
-
* 2. Send heartbeat at configurable intervals — only when user has been active
|
|
7
|
-
* 3. Show warning popup after idle timeout
|
|
8
|
-
* 4. Auto-logout after warning countdown expires
|
|
9
|
-
* 5. Sync activity across same-origin tabs via BroadcastChannel so one
|
|
10
|
-
* active tab keeps other tabs' sessions alive (no cascading logout).
|
|
11
|
-
*/
|
|
12
|
-
import { DEFAULT_SESSION_CONFIG, } from './sessionTypes';
|
|
13
|
-
/** Events that indicate user activity. */
|
|
14
|
-
const ACTIVITY_EVENTS = [
|
|
15
|
-
'mousemove',
|
|
16
|
-
'mousedown',
|
|
17
|
-
'keydown',
|
|
18
|
-
'scroll',
|
|
19
|
-
'touchstart',
|
|
20
|
-
'click',
|
|
21
|
-
];
|
|
22
|
-
/** Debounce interval for activity events (ms). */
|
|
23
|
-
const ACTIVITY_DEBOUNCE_MS = 1000;
|
|
24
|
-
/** Name of the BroadcastChannel used for cross-tab activity sync. */
|
|
25
|
-
const BROADCAST_CHANNEL_NAME = 'zeni-session-activity';
|
|
26
|
-
export class SessionManager {
|
|
27
|
-
constructor() {
|
|
28
|
-
this.config = DEFAULT_SESSION_CONFIG;
|
|
29
|
-
this.callbacks = null;
|
|
30
|
-
/** Timestamps and timers */
|
|
31
|
-
this.lastActivityTime = 0;
|
|
32
|
-
/** Timestamp of the last heartbeat fire (initial/periodic/continue/activity). */
|
|
33
|
-
this.lastHeartbeatTime = 0;
|
|
34
|
-
/** Set to true whenever user (or any same-origin tab) shows activity. */
|
|
35
|
-
this.hadActivitySinceLastHeartbeat = false;
|
|
36
|
-
this.idleCheckInterval = null;
|
|
37
|
-
this.heartbeatInterval = null;
|
|
38
|
-
this.countdownInterval = null;
|
|
39
|
-
this.activityDebounceTimer = null;
|
|
40
|
-
/** State */
|
|
41
|
-
this.running = false;
|
|
42
|
-
this.warningActive = false;
|
|
43
|
-
this.secondsRemaining = 0;
|
|
44
|
-
/** Wall-clock timestamp when the warning countdown began (for background-tab accuracy). */
|
|
45
|
-
this.warningStartTime = 0;
|
|
46
|
-
/** Cross-tab activity sync */
|
|
47
|
-
this.broadcastChannel = null;
|
|
48
|
-
/** Bound handlers for event listener cleanup. */
|
|
49
|
-
this.boundOnActivity = this.onActivity.bind(this);
|
|
50
|
-
this.boundOnVisibilityChange = this.onVisibilityChange.bind(this);
|
|
51
|
-
this.boundOnBroadcastMessage = this.onBroadcastMessage.bind(this);
|
|
52
|
-
}
|
|
53
|
-
// ─── Public API ────────────────────────────────────────────
|
|
54
|
-
start(config = {}, callbacks) {
|
|
55
|
-
if (this.running) {
|
|
56
|
-
this.stop();
|
|
57
|
-
}
|
|
58
|
-
this.config = { ...DEFAULT_SESSION_CONFIG, ...config };
|
|
59
|
-
this.callbacks = callbacks;
|
|
60
|
-
this.running = true;
|
|
61
|
-
this.warningActive = false;
|
|
62
|
-
this.lastActivityTime = Date.now();
|
|
63
|
-
this.lastHeartbeatTime = 0; // fireHeartbeat('initial') below will set this
|
|
64
|
-
this.hadActivitySinceLastHeartbeat = true; // initial heartbeat is expected
|
|
65
|
-
console.log('[SessionManager] start() called with config:', this.config);
|
|
66
|
-
const heartbeatEnabled = this.config.heartbeatIntervalMinutes > 0;
|
|
67
|
-
const idleTrackingEnabled = this.config.isAutoLogoutEnabled;
|
|
68
|
-
if (!heartbeatEnabled && !idleTrackingEnabled) {
|
|
69
|
-
console.log('[SessionManager] Heartbeat and idle tracking both disabled — nothing to start');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
// Activity listeners — needed for both heartbeat activity-gate and idle
|
|
73
|
-
// detection. BroadcastChannel keeps multiple tabs in sync.
|
|
74
|
-
ACTIVITY_EVENTS.forEach((event) => {
|
|
75
|
-
document.addEventListener(event, this.boundOnActivity, {
|
|
76
|
-
capture: true,
|
|
77
|
-
passive: true,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
this.setupBroadcastChannel();
|
|
81
|
-
if (heartbeatEnabled) {
|
|
82
|
-
this.startHeartbeat();
|
|
83
|
-
// Initial heartbeat on sign-in
|
|
84
|
-
this.fireHeartbeat('initial');
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
console.log('[SessionManager] Heartbeat disabled (heartbeatIntervalMinutes <= 0)');
|
|
88
|
-
}
|
|
89
|
-
if (idleTrackingEnabled) {
|
|
90
|
-
document.addEventListener('visibilitychange', this.boundOnVisibilityChange);
|
|
91
|
-
this.idleCheckInterval = setInterval(() => this.checkIdle(), 1000);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
console.log('[SessionManager] Idle tracking disabled for this user — heartbeat-only mode');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
stop() {
|
|
98
|
-
this.running = false;
|
|
99
|
-
this.warningActive = false;
|
|
100
|
-
ACTIVITY_EVENTS.forEach((event) => {
|
|
101
|
-
document.removeEventListener(event, this.boundOnActivity, {
|
|
102
|
-
capture: true,
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
document.removeEventListener('visibilitychange', this.boundOnVisibilityChange);
|
|
106
|
-
this.teardownBroadcastChannel();
|
|
107
|
-
this.clearTimer('idleCheckInterval');
|
|
108
|
-
this.clearTimer('heartbeatInterval');
|
|
109
|
-
this.clearTimer('countdownInterval');
|
|
110
|
-
this.clearTimer('activityDebounceTimer');
|
|
111
|
-
}
|
|
112
|
-
continueSession() {
|
|
113
|
-
if (!this.running) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
this.warningActive = false;
|
|
117
|
-
this.secondsRemaining = 0;
|
|
118
|
-
this.lastActivityTime = Date.now();
|
|
119
|
-
this.hadActivitySinceLastHeartbeat = true;
|
|
120
|
-
this.clearTimer('countdownInterval');
|
|
121
|
-
// Fire heartbeat immediately — user explicitly extended the session
|
|
122
|
-
this.fireHeartbeat('continue-session');
|
|
123
|
-
this.callbacks?.onSessionExtended();
|
|
124
|
-
this.broadcast({ type: 'activity', timestamp: Date.now() });
|
|
125
|
-
this.startHeartbeat();
|
|
126
|
-
}
|
|
127
|
-
isWarningActive() {
|
|
128
|
-
return this.warningActive;
|
|
129
|
-
}
|
|
130
|
-
getSecondsRemaining() {
|
|
131
|
-
return this.secondsRemaining;
|
|
132
|
-
}
|
|
133
|
-
// ─── Private ───────────────────────────────────────────────
|
|
134
|
-
onActivity() {
|
|
135
|
-
if (!this.running || this.warningActive) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
// Debounce: only update lastActivityTime at most once per second
|
|
139
|
-
if (this.activityDebounceTimer != null) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
this.registerActivity(now);
|
|
144
|
-
this.broadcast({ type: 'activity', timestamp: now });
|
|
145
|
-
// If heartbeat is enabled and the interval has elapsed since the last
|
|
146
|
-
// heartbeat, fire one immediately and restart the timer. This covers
|
|
147
|
-
// the "user active again after >interval idle" case without waiting
|
|
148
|
-
// for the next scheduled tick.
|
|
149
|
-
if (this.config.heartbeatIntervalMinutes > 0) {
|
|
150
|
-
const intervalMs = this.config.heartbeatIntervalMinutes * 60 * 1000;
|
|
151
|
-
const timeSinceLastHeartbeat = now - this.lastHeartbeatTime;
|
|
152
|
-
if (timeSinceLastHeartbeat >= intervalMs) {
|
|
153
|
-
this.fireHeartbeat('activity-after-idle');
|
|
154
|
-
this.startHeartbeat();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
this.activityDebounceTimer = setTimeout(() => {
|
|
158
|
-
this.activityDebounceTimer = null;
|
|
159
|
-
}, ACTIVITY_DEBOUNCE_MS);
|
|
160
|
-
}
|
|
161
|
-
onVisibilityChange() {
|
|
162
|
-
if (!this.running) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (document.visibilityState === 'visible') {
|
|
166
|
-
if (this.warningActive) {
|
|
167
|
-
// Tab was hidden while countdown was running — check if it already expired.
|
|
168
|
-
const elapsed = Math.floor((Date.now() - this.warningStartTime) / 1000);
|
|
169
|
-
if (elapsed >= this.config.warningDurationSeconds) {
|
|
170
|
-
this.secondsRemaining = 0;
|
|
171
|
-
this.clearTimer('countdownInterval');
|
|
172
|
-
this.warningActive = false;
|
|
173
|
-
this.callbacks?.onAutoLogout();
|
|
174
|
-
}
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
// Industry-standard idle detection: resetting on tab focus is expected.
|
|
178
|
-
this.registerActivity(Date.now());
|
|
179
|
-
this.checkIdle();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/** Single source of truth for marking activity locally. */
|
|
183
|
-
registerActivity(timestamp) {
|
|
184
|
-
this.lastActivityTime = Math.max(this.lastActivityTime, timestamp);
|
|
185
|
-
this.hadActivitySinceLastHeartbeat = true;
|
|
186
|
-
}
|
|
187
|
-
checkIdle() {
|
|
188
|
-
if (!this.running || this.warningActive) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
const idleMs = Date.now() - this.lastActivityTime;
|
|
192
|
-
const idleTimeoutMs = this.config.idleTimeoutMinutes * 60 * 1000;
|
|
193
|
-
if (idleMs >= idleTimeoutMs) {
|
|
194
|
-
this.startWarning();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
startWarning() {
|
|
198
|
-
this.warningActive = true;
|
|
199
|
-
this.warningStartTime = Date.now();
|
|
200
|
-
this.secondsRemaining = this.config.warningDurationSeconds;
|
|
201
|
-
// Don't extend session while warning is showing.
|
|
202
|
-
this.clearTimer('heartbeatInterval');
|
|
203
|
-
this.callbacks?.onWarningStart(this.secondsRemaining);
|
|
204
|
-
// Use wall-clock elapsed time so countdown stays accurate in background tabs.
|
|
205
|
-
// Browsers throttle setInterval when the tab is hidden, but each tick
|
|
206
|
-
// recomputes from the real start time so no seconds are "lost".
|
|
207
|
-
this.countdownInterval = setInterval(() => {
|
|
208
|
-
const elapsed = Math.floor((Date.now() - this.warningStartTime) / 1000);
|
|
209
|
-
const remaining = this.config.warningDurationSeconds - elapsed;
|
|
210
|
-
if (remaining <= 0) {
|
|
211
|
-
this.secondsRemaining = 0;
|
|
212
|
-
this.clearTimer('countdownInterval');
|
|
213
|
-
this.warningActive = false;
|
|
214
|
-
this.callbacks?.onAutoLogout();
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
this.secondsRemaining = remaining;
|
|
218
|
-
this.callbacks?.onWarningTick(this.secondsRemaining);
|
|
219
|
-
}
|
|
220
|
-
}, 1000);
|
|
221
|
-
}
|
|
222
|
-
startHeartbeat() {
|
|
223
|
-
this.clearTimer('heartbeatInterval');
|
|
224
|
-
const intervalMs = this.config.heartbeatIntervalMinutes * 60 * 1000;
|
|
225
|
-
console.log(`[SessionManager] Heartbeat timer set to fire every ${this.config.heartbeatIntervalMinutes} min (${intervalMs} ms)`);
|
|
226
|
-
this.heartbeatInterval = setInterval(() => {
|
|
227
|
-
if (!this.running || this.warningActive) {
|
|
228
|
-
console.log('[SessionManager] Heartbeat tick skipped — running:', this.running, 'warningActive:', this.warningActive);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (!this.hadActivitySinceLastHeartbeat) {
|
|
232
|
-
console.log('[SessionManager] Heartbeat tick skipped — no activity in this interval');
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
this.fireHeartbeat('periodic');
|
|
236
|
-
}, intervalMs);
|
|
237
|
-
}
|
|
238
|
-
fireHeartbeat(reason) {
|
|
239
|
-
console.log(`[SessionManager] Heartbeat fired (${reason})`);
|
|
240
|
-
this.lastHeartbeatTime = Date.now();
|
|
241
|
-
this.hadActivitySinceLastHeartbeat = false;
|
|
242
|
-
this.callbacks?.onHeartbeat();
|
|
243
|
-
// Let other tabs know we just fired a heartbeat — they can skip theirs
|
|
244
|
-
// this cycle to avoid N tabs all firing heartbeats.
|
|
245
|
-
this.broadcast({ type: 'heartbeat-fired', timestamp: this.lastHeartbeatTime });
|
|
246
|
-
}
|
|
247
|
-
// ─── BroadcastChannel (cross-tab activity sync) ───────────
|
|
248
|
-
setupBroadcastChannel() {
|
|
249
|
-
if (typeof BroadcastChannel === 'undefined') {
|
|
250
|
-
console.log('[SessionManager] BroadcastChannel not available — cross-tab sync disabled');
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
try {
|
|
254
|
-
this.broadcastChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
|
|
255
|
-
this.broadcastChannel.addEventListener('message', this.boundOnBroadcastMessage);
|
|
256
|
-
console.log('[SessionManager] BroadcastChannel ready for cross-tab sync');
|
|
257
|
-
}
|
|
258
|
-
catch (err) {
|
|
259
|
-
console.warn('[SessionManager] BroadcastChannel setup failed:', err);
|
|
260
|
-
this.broadcastChannel = null;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
teardownBroadcastChannel() {
|
|
264
|
-
if (this.broadcastChannel == null) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
this.broadcastChannel.removeEventListener('message', this.boundOnBroadcastMessage);
|
|
268
|
-
this.broadcastChannel.close();
|
|
269
|
-
this.broadcastChannel = null;
|
|
270
|
-
}
|
|
271
|
-
broadcast(message) {
|
|
272
|
-
this.broadcastChannel?.postMessage(message);
|
|
273
|
-
}
|
|
274
|
-
onBroadcastMessage(event) {
|
|
275
|
-
if (!this.running) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const msg = event.data;
|
|
279
|
-
if (msg == null) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (msg.type === 'activity') {
|
|
283
|
-
// Another tab saw user activity — treat as activity here too.
|
|
284
|
-
this.registerActivity(msg.timestamp);
|
|
285
|
-
}
|
|
286
|
-
else if (msg.type === 'heartbeat-fired') {
|
|
287
|
-
// Another tab already fired a heartbeat in this interval — backend
|
|
288
|
-
// session is already extended. Reset our local tracking so we don't
|
|
289
|
-
// also fire one this cycle.
|
|
290
|
-
this.lastHeartbeatTime = Math.max(this.lastHeartbeatTime, msg.timestamp);
|
|
291
|
-
this.hadActivitySinceLastHeartbeat = false;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
clearTimer(name) {
|
|
295
|
-
const timer = this[name];
|
|
296
|
-
if (timer != null) {
|
|
297
|
-
if (name === 'activityDebounceTimer') {
|
|
298
|
-
clearTimeout(timer);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
clearInterval(timer);
|
|
302
|
-
}
|
|
303
|
-
this[name] = null;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { of } from 'rxjs';
|
|
2
|
-
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
-
import { createZeniAPIStatus, isSuccessResponse, } from '../../../responsePayload';
|
|
4
|
-
import { sendSessionHeartbeat, sessionHeartbeatFailure, sessionHeartbeatSuccess, } from '../tenantReducer';
|
|
5
|
-
export const sessionHeartbeatEpic = (actions$, _, zeniAPI) => actions$.pipe(filter(sendSessionHeartbeat.match), switchMap(() => zeniAPI
|
|
6
|
-
.postAndGetJSON(`${zeniAPI.apiEndPoints.authMicroServiceBaseUrl}/1.0/heartbeat`)
|
|
7
|
-
.pipe(mergeMap((response) => {
|
|
8
|
-
if (isSuccessResponse(response)) {
|
|
9
|
-
return of(sessionHeartbeatSuccess(response.data?.expiry ?? ''));
|
|
10
|
-
}
|
|
11
|
-
return of(sessionHeartbeatFailure(response.status));
|
|
12
|
-
}), catchError((error) => of(sessionHeartbeatFailure(createZeniAPIStatus('Heartbeat failed', 'Session heartbeat API call errored: ' + JSON.stringify(error))))))));
|