@leanbase.com/js 0.1.2 → 0.2.0-alpha.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/dist/autocapture-utils.d.ts +17 -0
- package/dist/autocapture.d.ts +35 -0
- package/dist/config.d.ts +5 -0
- package/dist/constants.d.ts +54 -0
- package/dist/entrypoints/main.cjs.d.ts +4 -0
- package/dist/entrypoints/module.es.d.ts +4 -0
- package/dist/extensions/rageclick.d.ts +9 -0
- package/dist/iife.d.ts +19 -0
- package/dist/index.d.ts +2 -779
- package/dist/leanbase-logger.d.ts +6 -0
- package/dist/leanbase-persistence.d.ts +64 -0
- package/dist/leanbase.d.ts +49 -0
- package/dist/leanbase.iife.js +1 -4745
- package/dist/leanbase.iife.js.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/module.d.ts +780 -0
- package/dist/module.js +2 -0
- package/dist/module.js.map +1 -0
- package/dist/page-view.d.ts +29 -0
- package/dist/scroll-manager.d.ts +21 -0
- package/dist/session-props.d.ts +32 -0
- package/dist/sessionid.d.ts +50 -0
- package/dist/storage.d.ts +24 -0
- package/{src/types.ts → dist/types.d.ts} +145 -235
- package/dist/utils/blocked-uas.d.ts +17 -0
- package/dist/utils/element-utils.d.ts +5 -0
- package/dist/utils/event-utils.d.ts +22 -0
- package/dist/utils/index.d.ts +44 -0
- package/dist/utils/request-utils.d.ts +12 -0
- package/dist/utils/simple-event-emitter.d.ts +6 -0
- package/dist/utils/user-agent-utils.d.ts +18 -0
- package/dist/uuidv7.d.ts +43 -0
- package/dist/version.d.ts +1 -0
- package/lib/autocapture-utils.d.ts +17 -0
- package/{src/autocapture-utils.ts → lib/autocapture-utils.js} +196 -280
- package/lib/autocapture-utils.js.map +1 -0
- package/lib/autocapture.d.ts +35 -0
- package/lib/autocapture.js +311 -0
- package/lib/autocapture.js.map +1 -0
- package/lib/config.d.ts +5 -0
- package/lib/config.js +7 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +54 -0
- package/{src/constants.ts → lib/constants.js} +58 -55
- package/lib/constants.js.map +1 -0
- package/lib/entrypoints/main.cjs.d.ts +4 -0
- package/lib/entrypoints/main.cjs.js +3 -0
- package/lib/entrypoints/main.cjs.js.map +1 -0
- package/lib/entrypoints/module.es.d.ts +4 -0
- package/lib/entrypoints/module.es.js +3 -0
- package/lib/entrypoints/module.es.js.map +1 -0
- package/lib/extensions/rageclick.d.ts +9 -0
- package/lib/extensions/rageclick.js +27 -0
- package/lib/extensions/rageclick.js.map +1 -0
- package/lib/iife.d.ts +19 -0
- package/lib/iife.js +67 -0
- package/lib/iife.js.map +1 -0
- package/{src/index.ts → lib/index.d.ts} +2 -2
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/leanbase-logger.d.ts +6 -0
- package/lib/leanbase-logger.js +25 -0
- package/lib/leanbase-logger.js.map +1 -0
- package/lib/leanbase-persistence.d.ts +64 -0
- package/lib/leanbase-persistence.js +287 -0
- package/lib/leanbase-persistence.js.map +1 -0
- package/lib/leanbase.d.ts +49 -0
- package/lib/leanbase.js +294 -0
- package/lib/leanbase.js.map +1 -0
- package/lib/page-view.d.ts +29 -0
- package/lib/page-view.js +81 -0
- package/lib/page-view.js.map +1 -0
- package/lib/scroll-manager.d.ts +21 -0
- package/lib/scroll-manager.js +79 -0
- package/lib/scroll-manager.js.map +1 -0
- package/lib/session-props.d.ts +32 -0
- package/lib/session-props.js +73 -0
- package/lib/session-props.js.map +1 -0
- package/lib/sessionid.d.ts +50 -0
- package/{src/sessionid.ts → lib/sessionid.js} +128 -204
- package/lib/sessionid.js.map +1 -0
- package/lib/storage.d.ts +24 -0
- package/{src/storage.ts → lib/storage.js} +182 -225
- package/lib/storage.js.map +1 -0
- package/lib/types.d.ts +544 -0
- package/lib/types.js +7 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/blocked-uas.d.ts +17 -0
- package/{src/utils/blocked-uas.ts → lib/utils/blocked-uas.js} +19 -48
- package/lib/utils/blocked-uas.js.map +1 -0
- package/lib/utils/element-utils.d.ts +5 -0
- package/{src/utils/element-utils.ts → lib/utils/element-utils.js} +13 -17
- package/lib/utils/element-utils.js.map +1 -0
- package/lib/utils/event-utils.d.ts +22 -0
- package/lib/utils/event-utils.js +258 -0
- package/lib/utils/event-utils.js.map +1 -0
- package/lib/utils/index.d.ts +44 -0
- package/lib/utils/index.js +183 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/request-utils.d.ts +12 -0
- package/lib/utils/request-utils.js +107 -0
- package/lib/utils/request-utils.js.map +1 -0
- package/lib/utils/simple-event-emitter.d.ts +6 -0
- package/lib/utils/simple-event-emitter.js +24 -0
- package/lib/utils/simple-event-emitter.js.map +1 -0
- package/lib/utils/user-agent-utils.d.ts +18 -0
- package/lib/utils/user-agent-utils.js +369 -0
- package/lib/utils/user-agent-utils.js.map +1 -0
- package/lib/uuidv7.d.ts +43 -0
- package/{src/uuidv7.ts → lib/uuidv7.js} +103 -131
- package/lib/uuidv7.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/package.json +23 -11
- package/dist/index.cjs +0 -3032
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs +0 -3030
- package/dist/index.mjs.map +0 -1
- package/src/autocapture.ts +0 -415
- package/src/config.ts +0 -8
- package/src/extensions/rageclick.ts +0 -34
- package/src/iife.ts +0 -87
- package/src/leanbase-logger.ts +0 -26
- package/src/leanbase-persistence.ts +0 -374
- package/src/leanbase.ts +0 -424
- package/src/page-view.ts +0 -124
- package/src/scroll-manager.ts +0 -103
- package/src/session-props.ts +0 -114
- package/src/utils/event-utils.ts +0 -304
- package/src/utils/index.ts +0 -222
- package/src/utils/request-utils.ts +0 -128
- package/src/utils/simple-event-emitter.ts +0 -27
- package/src/utils/user-agent-utils.ts +0 -357
- package/src/version.ts +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SessionIdChangedCallback } from './types';
|
|
2
|
+
import { Leanbase } from './leanbase';
|
|
3
|
+
export declare const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS: number;
|
|
4
|
+
export declare const MAX_SESSION_IDLE_TIMEOUT_SECONDS: number;
|
|
5
|
+
export declare class SessionIdManager {
|
|
6
|
+
private readonly _sessionIdGenerator;
|
|
7
|
+
private readonly _windowIdGenerator;
|
|
8
|
+
private _config;
|
|
9
|
+
private _persistence;
|
|
10
|
+
private _windowId;
|
|
11
|
+
private _sessionId;
|
|
12
|
+
private readonly _window_id_storage_key;
|
|
13
|
+
private readonly _primary_window_exists_storage_key;
|
|
14
|
+
private _sessionStartTimestamp;
|
|
15
|
+
private _sessionActivityTimestamp;
|
|
16
|
+
private _sessionIdChangedHandlers;
|
|
17
|
+
private readonly _sessionTimeoutMs;
|
|
18
|
+
private _enforceIdleTimeout;
|
|
19
|
+
private _beforeUnloadListener;
|
|
20
|
+
private _eventEmitter;
|
|
21
|
+
on(event: 'forcedIdleReset', handler: () => void): () => void;
|
|
22
|
+
constructor(instance: Leanbase, sessionIdGenerator?: () => string, windowIdGenerator?: () => string);
|
|
23
|
+
get sessionTimeoutMs(): number;
|
|
24
|
+
onSessionId(callback: SessionIdChangedCallback): () => void;
|
|
25
|
+
private _canUseSessionStorage;
|
|
26
|
+
private _setWindowId;
|
|
27
|
+
private _getWindowId;
|
|
28
|
+
private _setSessionId;
|
|
29
|
+
private _getSessionId;
|
|
30
|
+
resetSessionId(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Cleans up resources used by SessionIdManager.
|
|
33
|
+
* Should be called when the SessionIdManager is no longer needed to prevent memory leaks.
|
|
34
|
+
*/
|
|
35
|
+
destroy(): void;
|
|
36
|
+
private _listenToReloadWindow;
|
|
37
|
+
private _sessionHasBeenIdleTooLong;
|
|
38
|
+
checkAndGetSessionAndWindowId(readOnly?: boolean, _timestamp?: number | null): {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
windowId: string;
|
|
41
|
+
sessionStartTimestamp: number;
|
|
42
|
+
changeReason: {
|
|
43
|
+
noSessionId: boolean;
|
|
44
|
+
activityTimeout: boolean;
|
|
45
|
+
sessionPastMaximumLength: boolean;
|
|
46
|
+
} | undefined;
|
|
47
|
+
lastActivityTimestamp: number;
|
|
48
|
+
};
|
|
49
|
+
private _resetIdleTimer;
|
|
50
|
+
}
|
|
@@ -1,239 +1,178 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS = 30 * 60 // 30 minutes
|
|
15
|
-
export const MAX_SESSION_IDLE_TIMEOUT_SECONDS = 10 * 60 * 60 // 10 hours
|
|
16
|
-
const MIN_SESSION_IDLE_TIMEOUT_SECONDS = 60 // 1 minute
|
|
17
|
-
const SESSION_LENGTH_LIMIT_MILLISECONDS = 24 * 3600 * 1000 // 24 hours
|
|
18
|
-
|
|
1
|
+
import { SESSION_ID } from './constants';
|
|
2
|
+
import { sessionStore } from './storage';
|
|
3
|
+
import { uuid7ToTimestampMs, uuidv7 } from './uuidv7';
|
|
4
|
+
import { window } from './utils';
|
|
5
|
+
import { isArray, isNumber, isUndefined, clampToRange } from '@posthog/core';
|
|
6
|
+
import { addEventListener } from './utils';
|
|
7
|
+
import { SimpleEventEmitter } from './utils/simple-event-emitter';
|
|
8
|
+
import { logger } from './leanbase-logger';
|
|
9
|
+
export const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS = 30 * 60; // 30 minutes
|
|
10
|
+
export const MAX_SESSION_IDLE_TIMEOUT_SECONDS = 10 * 60 * 60; // 10 hours
|
|
11
|
+
const MIN_SESSION_IDLE_TIMEOUT_SECONDS = 60; // 1 minute
|
|
12
|
+
const SESSION_LENGTH_LIMIT_MILLISECONDS = 24 * 3600 * 1000; // 24 hours
|
|
19
13
|
export class SessionIdManager {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private _config: Partial<LeanbaseConfig>
|
|
23
|
-
private _persistence: LeanbasePersistence
|
|
24
|
-
private _windowId: string | null | undefined
|
|
25
|
-
private _sessionId: string | null | undefined
|
|
26
|
-
private readonly _window_id_storage_key: string
|
|
27
|
-
private readonly _primary_window_exists_storage_key: string
|
|
28
|
-
private _sessionStartTimestamp: number | null
|
|
29
|
-
|
|
30
|
-
private _sessionActivityTimestamp: number | null
|
|
31
|
-
private _sessionIdChangedHandlers: SessionIdChangedCallback[] = []
|
|
32
|
-
private readonly _sessionTimeoutMs: number
|
|
33
|
-
|
|
34
|
-
// we track activity so we can end the session proactively when it has passed the idle timeout
|
|
35
|
-
private _enforceIdleTimeout: ReturnType<typeof setTimeout> | undefined
|
|
36
|
-
|
|
37
|
-
private _beforeUnloadListener: (() => void) | undefined = undefined
|
|
38
|
-
|
|
39
|
-
private _eventEmitter: SimpleEventEmitter = new SimpleEventEmitter()
|
|
40
|
-
public on(event: 'forcedIdleReset', handler: () => void): () => void {
|
|
41
|
-
return this._eventEmitter.on(event, handler)
|
|
14
|
+
on(event, handler) {
|
|
15
|
+
return this._eventEmitter.on(event, handler);
|
|
42
16
|
}
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
constructor(instance, sessionIdGenerator, windowIdGenerator) {
|
|
18
|
+
this._sessionIdChangedHandlers = [];
|
|
19
|
+
this._beforeUnloadListener = undefined;
|
|
20
|
+
this._eventEmitter = new SimpleEventEmitter();
|
|
21
|
+
this._sessionHasBeenIdleTooLong = (timestamp, lastActivityTimestamp) => {
|
|
22
|
+
return Math.abs(timestamp - lastActivityTimestamp) > this.sessionTimeoutMs;
|
|
23
|
+
};
|
|
45
24
|
if (!instance.persistence) {
|
|
46
|
-
throw new Error('SessionIdManager requires a LeanbasePersistence instance')
|
|
25
|
+
throw new Error('SessionIdManager requires a LeanbasePersistence instance');
|
|
47
26
|
}
|
|
48
27
|
if (instance.config.cookieless_mode === 'always') {
|
|
49
|
-
throw new Error('SessionIdManager cannot be used with cookieless_mode="always"')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const persistenceName = this._config['persistence_name'] || this._config['token']
|
|
62
|
-
|
|
63
|
-
const desiredTimeout = this._config['session_idle_timeout_seconds'] || DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS
|
|
28
|
+
throw new Error('SessionIdManager cannot be used with cookieless_mode="always"');
|
|
29
|
+
}
|
|
30
|
+
this._config = instance.config;
|
|
31
|
+
this._persistence = instance.persistence;
|
|
32
|
+
this._windowId = undefined;
|
|
33
|
+
this._sessionId = undefined;
|
|
34
|
+
this._sessionStartTimestamp = null;
|
|
35
|
+
this._sessionActivityTimestamp = null;
|
|
36
|
+
this._sessionIdGenerator = sessionIdGenerator || uuidv7;
|
|
37
|
+
this._windowIdGenerator = windowIdGenerator || uuidv7;
|
|
38
|
+
const persistenceName = this._config['persistence_name'] || this._config['token'];
|
|
39
|
+
const desiredTimeout = this._config['session_idle_timeout_seconds'] || DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS;
|
|
64
40
|
this._sessionTimeoutMs =
|
|
65
|
-
clampToRange(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS
|
|
71
|
-
) * 1000
|
|
72
|
-
|
|
73
|
-
instance.register({ $configured_session_timeout_ms: this._sessionTimeoutMs })
|
|
74
|
-
this._resetIdleTimer()
|
|
75
|
-
|
|
76
|
-
this._window_id_storage_key = 'ph_' + persistenceName + '_window_id'
|
|
77
|
-
this._primary_window_exists_storage_key = 'ph_' + persistenceName + '_primary_window_exists'
|
|
78
|
-
|
|
41
|
+
clampToRange(desiredTimeout, MIN_SESSION_IDLE_TIMEOUT_SECONDS, MAX_SESSION_IDLE_TIMEOUT_SECONDS, logger, DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS) * 1000;
|
|
42
|
+
instance.register({ $configured_session_timeout_ms: this._sessionTimeoutMs });
|
|
43
|
+
this._resetIdleTimer();
|
|
44
|
+
this._window_id_storage_key = 'ph_' + persistenceName + '_window_id';
|
|
45
|
+
this._primary_window_exists_storage_key = 'ph_' + persistenceName + '_primary_window_exists';
|
|
79
46
|
// primary_window_exists is set when the DOM has been loaded and is cleared on unload
|
|
80
47
|
// if it exists here it means there was no unload which suggests this window is opened as a tab duplication, window.open, etc.
|
|
81
48
|
if (this._canUseSessionStorage()) {
|
|
82
|
-
const lastWindowId = sessionStore._parse(this._window_id_storage_key)
|
|
83
|
-
|
|
84
|
-
const primaryWindowExists = sessionStore._parse(this._primary_window_exists_storage_key)
|
|
49
|
+
const lastWindowId = sessionStore._parse(this._window_id_storage_key);
|
|
50
|
+
const primaryWindowExists = sessionStore._parse(this._primary_window_exists_storage_key);
|
|
85
51
|
if (lastWindowId && !primaryWindowExists) {
|
|
86
52
|
// Persist window from previous storage state
|
|
87
|
-
this._windowId = lastWindowId
|
|
88
|
-
}
|
|
53
|
+
this._windowId = lastWindowId;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
89
56
|
// Wipe any reference to previous window id
|
|
90
|
-
sessionStore._remove(this._window_id_storage_key)
|
|
57
|
+
sessionStore._remove(this._window_id_storage_key);
|
|
91
58
|
}
|
|
92
59
|
// Flag this session as having a primary window
|
|
93
|
-
sessionStore._set(this._primary_window_exists_storage_key, true)
|
|
60
|
+
sessionStore._set(this._primary_window_exists_storage_key, true);
|
|
94
61
|
}
|
|
95
|
-
|
|
96
62
|
if (this._config.bootstrap?.sessionID) {
|
|
97
63
|
try {
|
|
98
|
-
const sessionStartTimestamp = uuid7ToTimestampMs(this._config.bootstrap.sessionID)
|
|
99
|
-
this._setSessionId(this._config.bootstrap.sessionID, new Date().getTime(), sessionStartTimestamp)
|
|
100
|
-
}
|
|
101
|
-
|
|
64
|
+
const sessionStartTimestamp = uuid7ToTimestampMs(this._config.bootstrap.sessionID);
|
|
65
|
+
this._setSessionId(this._config.bootstrap.sessionID, new Date().getTime(), sessionStartTimestamp);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
logger.error('Invalid sessionID in bootstrap', e);
|
|
102
69
|
}
|
|
103
70
|
}
|
|
104
|
-
|
|
105
|
-
this._listenToReloadWindow()
|
|
71
|
+
this._listenToReloadWindow();
|
|
106
72
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return this._sessionTimeoutMs
|
|
73
|
+
get sessionTimeoutMs() {
|
|
74
|
+
return this._sessionTimeoutMs;
|
|
110
75
|
}
|
|
111
|
-
|
|
112
|
-
onSessionId(callback: SessionIdChangedCallback): () => void {
|
|
76
|
+
onSessionId(callback) {
|
|
113
77
|
// KLUDGE: when running in tests the handlers array was always undefined
|
|
114
78
|
// it's yucky but safe to set it here so that it's always definitely available
|
|
115
79
|
if (isUndefined(this._sessionIdChangedHandlers)) {
|
|
116
|
-
this._sessionIdChangedHandlers = []
|
|
80
|
+
this._sessionIdChangedHandlers = [];
|
|
117
81
|
}
|
|
118
|
-
|
|
119
|
-
this._sessionIdChangedHandlers.push(callback)
|
|
82
|
+
this._sessionIdChangedHandlers.push(callback);
|
|
120
83
|
if (this._sessionId) {
|
|
121
|
-
callback(this._sessionId, this._windowId)
|
|
84
|
+
callback(this._sessionId, this._windowId);
|
|
122
85
|
}
|
|
123
86
|
return () => {
|
|
124
|
-
this._sessionIdChangedHandlers = this._sessionIdChangedHandlers.filter((h) => h !== callback)
|
|
125
|
-
}
|
|
87
|
+
this._sessionIdChangedHandlers = this._sessionIdChangedHandlers.filter((h) => h !== callback);
|
|
88
|
+
};
|
|
126
89
|
}
|
|
127
|
-
|
|
128
|
-
private _canUseSessionStorage(): boolean {
|
|
90
|
+
_canUseSessionStorage() {
|
|
129
91
|
// We only want to use sessionStorage if persistence is enabled and not memory storage
|
|
130
|
-
return this._config.persistence !== 'memory' && !this._persistence._disabled && sessionStore._is_supported()
|
|
92
|
+
return this._config.persistence !== 'memory' && !this._persistence._disabled && sessionStore._is_supported();
|
|
131
93
|
}
|
|
132
|
-
|
|
133
94
|
// Note: this tries to store the windowId in sessionStorage. SessionStorage is unique to the current window/tab,
|
|
134
95
|
// and persists page loads/reloads. So it's uniquely suited for storing the windowId. This function also respects
|
|
135
96
|
// when persistence is disabled (by user config) and when sessionStorage is not supported (it *should* be supported on all browsers),
|
|
136
97
|
// and in that case, it falls back to memory (which sadly, won't persist page loads)
|
|
137
|
-
|
|
98
|
+
_setWindowId(windowId) {
|
|
138
99
|
if (windowId !== this._windowId) {
|
|
139
|
-
this._windowId = windowId
|
|
100
|
+
this._windowId = windowId;
|
|
140
101
|
if (this._canUseSessionStorage()) {
|
|
141
|
-
sessionStore._set(this._window_id_storage_key, windowId)
|
|
102
|
+
sessionStore._set(this._window_id_storage_key, windowId);
|
|
142
103
|
}
|
|
143
104
|
}
|
|
144
105
|
}
|
|
145
|
-
|
|
146
|
-
private _getWindowId(): string | null {
|
|
106
|
+
_getWindowId() {
|
|
147
107
|
if (this._windowId) {
|
|
148
|
-
return this._windowId
|
|
108
|
+
return this._windowId;
|
|
149
109
|
}
|
|
150
110
|
if (this._canUseSessionStorage()) {
|
|
151
|
-
return sessionStore._parse(this._window_id_storage_key)
|
|
111
|
+
return sessionStore._parse(this._window_id_storage_key);
|
|
152
112
|
}
|
|
153
113
|
// New window id will be generated
|
|
154
|
-
return null
|
|
114
|
+
return null;
|
|
155
115
|
}
|
|
156
|
-
|
|
157
116
|
// Note: 'this.persistence.register' can be disabled in the config.
|
|
158
117
|
// In that case, this works by storing sessionId and the timestamp in memory.
|
|
159
|
-
|
|
160
|
-
sessionId
|
|
161
|
-
sessionActivityTimestamp: number | null,
|
|
162
|
-
sessionStartTimestamp: number | null
|
|
163
|
-
): void {
|
|
164
|
-
if (
|
|
165
|
-
sessionId !== this._sessionId ||
|
|
118
|
+
_setSessionId(sessionId, sessionActivityTimestamp, sessionStartTimestamp) {
|
|
119
|
+
if (sessionId !== this._sessionId ||
|
|
166
120
|
sessionActivityTimestamp !== this._sessionActivityTimestamp ||
|
|
167
|
-
sessionStartTimestamp !== this._sessionStartTimestamp
|
|
168
|
-
|
|
169
|
-
this.
|
|
170
|
-
this.
|
|
171
|
-
this._sessionId = sessionId
|
|
172
|
-
|
|
121
|
+
sessionStartTimestamp !== this._sessionStartTimestamp) {
|
|
122
|
+
this._sessionStartTimestamp = sessionStartTimestamp;
|
|
123
|
+
this._sessionActivityTimestamp = sessionActivityTimestamp;
|
|
124
|
+
this._sessionId = sessionId;
|
|
173
125
|
this._persistence.register({
|
|
174
126
|
[SESSION_ID]: [sessionActivityTimestamp, sessionId, sessionStartTimestamp],
|
|
175
|
-
})
|
|
127
|
+
});
|
|
176
128
|
}
|
|
177
129
|
}
|
|
178
|
-
|
|
179
|
-
private _getSessionId(): [number, string, number] {
|
|
130
|
+
_getSessionId() {
|
|
180
131
|
if (this._sessionId && this._sessionActivityTimestamp && this._sessionStartTimestamp) {
|
|
181
|
-
return [this._sessionActivityTimestamp, this._sessionId, this._sessionStartTimestamp]
|
|
132
|
+
return [this._sessionActivityTimestamp, this._sessionId, this._sessionStartTimestamp];
|
|
182
133
|
}
|
|
183
|
-
const sessionIdInfo = this._persistence.props[SESSION_ID]
|
|
184
|
-
|
|
134
|
+
const sessionIdInfo = this._persistence.props[SESSION_ID];
|
|
185
135
|
if (isArray(sessionIdInfo) && sessionIdInfo.length === 2) {
|
|
186
136
|
// Storage does not yet have a session start time. Add the last activity timestamp as the start time
|
|
187
|
-
sessionIdInfo.push(sessionIdInfo[0])
|
|
137
|
+
sessionIdInfo.push(sessionIdInfo[0]);
|
|
188
138
|
}
|
|
189
|
-
|
|
190
|
-
return sessionIdInfo || [0, null, 0]
|
|
139
|
+
return sessionIdInfo || [0, null, 0];
|
|
191
140
|
}
|
|
192
|
-
|
|
193
141
|
// Resets the session id by setting it to null. On the subsequent call to checkAndGetSessionAndWindowId,
|
|
194
142
|
// new ids will be generated.
|
|
195
|
-
resetSessionId()
|
|
196
|
-
this._setSessionId(null, null, null)
|
|
143
|
+
resetSessionId() {
|
|
144
|
+
this._setSessionId(null, null, null);
|
|
197
145
|
}
|
|
198
|
-
|
|
199
146
|
/**
|
|
200
147
|
* Cleans up resources used by SessionIdManager.
|
|
201
148
|
* Should be called when the SessionIdManager is no longer needed to prevent memory leaks.
|
|
202
149
|
*/
|
|
203
|
-
destroy()
|
|
150
|
+
destroy() {
|
|
204
151
|
// Clear the idle timeout timer
|
|
205
|
-
clearTimeout(this._enforceIdleTimeout)
|
|
206
|
-
this._enforceIdleTimeout = undefined
|
|
207
|
-
|
|
152
|
+
clearTimeout(this._enforceIdleTimeout);
|
|
153
|
+
this._enforceIdleTimeout = undefined;
|
|
208
154
|
// Remove the beforeunload event listener
|
|
209
155
|
if (this._beforeUnloadListener && window) {
|
|
210
|
-
window.removeEventListener('beforeunload', this._beforeUnloadListener, { capture: false }
|
|
211
|
-
this._beforeUnloadListener = undefined
|
|
156
|
+
window.removeEventListener('beforeunload', this._beforeUnloadListener, { capture: false });
|
|
157
|
+
this._beforeUnloadListener = undefined;
|
|
212
158
|
}
|
|
213
|
-
|
|
214
159
|
// Clear session id changed handlers
|
|
215
|
-
this._sessionIdChangedHandlers = []
|
|
160
|
+
this._sessionIdChangedHandlers = [];
|
|
216
161
|
}
|
|
217
|
-
|
|
218
162
|
/*
|
|
219
163
|
* Listens to window unloads and removes the primaryWindowExists key from sessionStorage.
|
|
220
164
|
* Reloaded or fresh tabs created after a DOM unloads (reloading the same tab) WILL NOT have this primaryWindowExists flag in session storage.
|
|
221
165
|
* Cloned sessions (new tab, tab duplication, window.open(), ...) WILL have this primaryWindowExists flag in their copied session storage.
|
|
222
166
|
* We conditionally check the primaryWindowExists value in the constructor to decide if the window id in the last session storage should be carried over.
|
|
223
167
|
*/
|
|
224
|
-
|
|
168
|
+
_listenToReloadWindow() {
|
|
225
169
|
this._beforeUnloadListener = () => {
|
|
226
170
|
if (this._canUseSessionStorage()) {
|
|
227
|
-
sessionStore._remove(this._primary_window_exists_storage_key)
|
|
171
|
+
sessionStore._remove(this._primary_window_exists_storage_key);
|
|
228
172
|
}
|
|
229
|
-
}
|
|
230
|
-
addEventListener(window, 'beforeunload', this._beforeUnloadListener, { capture: false })
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
private _sessionHasBeenIdleTooLong = (timestamp: number, lastActivityTimestamp: number) => {
|
|
234
|
-
return Math.abs(timestamp - lastActivityTimestamp) > this.sessionTimeoutMs
|
|
173
|
+
};
|
|
174
|
+
addEventListener(window, 'beforeunload', this._beforeUnloadListener, { capture: false });
|
|
235
175
|
}
|
|
236
|
-
|
|
237
176
|
/*
|
|
238
177
|
* This function returns the current sessionId and windowId. It should be used to
|
|
239
178
|
* access these values over directly calling `._sessionId` or `._windowId`.
|
|
@@ -250,81 +189,66 @@ export class SessionIdManager {
|
|
|
250
189
|
* @param {boolean} readOnly (optional) Defaults to False. Should be set to True when the call to the function should not extend or cycle the session (e.g. being called for non-user generated events)
|
|
251
190
|
* @param {Number} timestamp (optional) Defaults to the current time. The timestamp to be stored with the sessionId (used when determining if a new sessionId should be generated)
|
|
252
191
|
*/
|
|
253
|
-
checkAndGetSessionAndWindowId(readOnly = false, _timestamp
|
|
192
|
+
checkAndGetSessionAndWindowId(readOnly = false, _timestamp = null) {
|
|
254
193
|
if (this._config.cookieless_mode === 'always') {
|
|
255
|
-
throw new Error('checkAndGetSessionAndWindowId should not be called with cookieless_mode="always"')
|
|
194
|
+
throw new Error('checkAndGetSessionAndWindowId should not be called with cookieless_mode="always"');
|
|
256
195
|
}
|
|
257
|
-
const timestamp = _timestamp || new Date().getTime()
|
|
258
|
-
|
|
196
|
+
const timestamp = _timestamp || new Date().getTime();
|
|
259
197
|
// eslint-disable-next-line prefer-const
|
|
260
|
-
let [lastActivityTimestamp, sessionId, startTimestamp] = this._getSessionId()
|
|
261
|
-
let windowId = this._getWindowId()
|
|
262
|
-
|
|
263
|
-
const sessionPastMaximumLength =
|
|
264
|
-
isNumber(startTimestamp) &&
|
|
198
|
+
let [lastActivityTimestamp, sessionId, startTimestamp] = this._getSessionId();
|
|
199
|
+
let windowId = this._getWindowId();
|
|
200
|
+
const sessionPastMaximumLength = isNumber(startTimestamp) &&
|
|
265
201
|
startTimestamp > 0 &&
|
|
266
|
-
Math.abs(timestamp - startTimestamp) > SESSION_LENGTH_LIMIT_MILLISECONDS
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
const activityTimeout = !readOnly && this._sessionHasBeenIdleTooLong(timestamp, lastActivityTimestamp)
|
|
202
|
+
Math.abs(timestamp - startTimestamp) > SESSION_LENGTH_LIMIT_MILLISECONDS;
|
|
203
|
+
let valuesChanged = false;
|
|
204
|
+
const noSessionId = !sessionId;
|
|
205
|
+
const activityTimeout = !readOnly && this._sessionHasBeenIdleTooLong(timestamp, lastActivityTimestamp);
|
|
271
206
|
if (noSessionId || activityTimeout || sessionPastMaximumLength) {
|
|
272
|
-
sessionId = this._sessionIdGenerator()
|
|
273
|
-
windowId = this._windowIdGenerator()
|
|
207
|
+
sessionId = this._sessionIdGenerator();
|
|
208
|
+
windowId = this._windowIdGenerator();
|
|
274
209
|
logger.info('new session ID generated', {
|
|
275
210
|
sessionId,
|
|
276
211
|
windowId,
|
|
277
212
|
changeReason: { noSessionId, activityTimeout, sessionPastMaximumLength },
|
|
278
|
-
})
|
|
279
|
-
startTimestamp = timestamp
|
|
280
|
-
valuesChanged = true
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const newActivityTimestamp =
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
this._setWindowId(windowId)
|
|
291
|
-
this._setSessionId(sessionId, newActivityTimestamp, sessionStartTimestamp)
|
|
292
|
-
|
|
213
|
+
});
|
|
214
|
+
startTimestamp = timestamp;
|
|
215
|
+
valuesChanged = true;
|
|
216
|
+
}
|
|
217
|
+
else if (!windowId) {
|
|
218
|
+
windowId = this._windowIdGenerator();
|
|
219
|
+
valuesChanged = true;
|
|
220
|
+
}
|
|
221
|
+
const newActivityTimestamp = lastActivityTimestamp === 0 || !readOnly || sessionPastMaximumLength ? timestamp : lastActivityTimestamp;
|
|
222
|
+
const sessionStartTimestamp = startTimestamp === 0 ? new Date().getTime() : startTimestamp;
|
|
223
|
+
this._setWindowId(windowId);
|
|
224
|
+
this._setSessionId(sessionId, newActivityTimestamp, sessionStartTimestamp);
|
|
293
225
|
if (!readOnly) {
|
|
294
|
-
this._resetIdleTimer()
|
|
226
|
+
this._resetIdleTimer();
|
|
295
227
|
}
|
|
296
|
-
|
|
297
228
|
if (valuesChanged) {
|
|
298
|
-
this._sessionIdChangedHandlers.forEach((handler) =>
|
|
299
|
-
handler(
|
|
300
|
-
sessionId,
|
|
301
|
-
windowId,
|
|
302
|
-
valuesChanged ? { noSessionId, activityTimeout, sessionPastMaximumLength } : undefined
|
|
303
|
-
)
|
|
304
|
-
)
|
|
229
|
+
this._sessionIdChangedHandlers.forEach((handler) => handler(sessionId, windowId, valuesChanged ? { noSessionId, activityTimeout, sessionPastMaximumLength } : undefined));
|
|
305
230
|
}
|
|
306
|
-
|
|
307
231
|
return {
|
|
308
232
|
sessionId,
|
|
309
233
|
windowId,
|
|
310
234
|
sessionStartTimestamp,
|
|
311
235
|
changeReason: valuesChanged ? { noSessionId, activityTimeout, sessionPastMaximumLength } : undefined,
|
|
312
236
|
lastActivityTimestamp: lastActivityTimestamp,
|
|
313
|
-
}
|
|
237
|
+
};
|
|
314
238
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
clearTimeout(this._enforceIdleTimeout)
|
|
239
|
+
_resetIdleTimer() {
|
|
240
|
+
clearTimeout(this._enforceIdleTimeout);
|
|
318
241
|
this._enforceIdleTimeout = setTimeout(() => {
|
|
319
242
|
// enforce idle timeout a little after the session timeout to ensure the session is reset even without activity
|
|
320
243
|
// we need to check session activity first in case a different window has kept the session active
|
|
321
244
|
// while this window has been idle - and the timer has not progressed - e.g. window memory frozen while hidden
|
|
322
|
-
const [lastActivityTimestamp] = this._getSessionId()
|
|
245
|
+
const [lastActivityTimestamp] = this._getSessionId();
|
|
323
246
|
if (this._sessionHasBeenIdleTooLong(new Date().getTime(), lastActivityTimestamp)) {
|
|
324
|
-
const idleSessionId = this._sessionId
|
|
325
|
-
this.resetSessionId()
|
|
326
|
-
this._eventEmitter.emit('forcedIdleReset', { idleSessionId })
|
|
247
|
+
const idleSessionId = this._sessionId;
|
|
248
|
+
this.resetSessionId();
|
|
249
|
+
this._eventEmitter.emit('forcedIdleReset', { idleSessionId });
|
|
327
250
|
}
|
|
328
|
-
}, this.sessionTimeoutMs * 1.1)
|
|
251
|
+
}, this.sessionTimeoutMs * 1.1);
|
|
329
252
|
}
|
|
330
253
|
}
|
|
254
|
+
//# sourceMappingURL=sessionid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionid.js","sourceRoot":"","sources":["../src/sessionid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAU,MAAM,eAAe,CAAA;AAEpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,M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AAS;YACT,QAAQ;YACR,qBAAqB;YACrB,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAC,CAAC,CAAC,SAAS;YACpG,qBAAqB,EAAE,qBAAqB;SAC/C,CAAA;IACL,CAAC;IAEO,eAAe;QACnB,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;QACtC,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,GAAG,EAAE;YACvC,+GAA+G;YAC/G,iGAAiG;YACjG,8GAA8G;YAC9G,MAAM,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;YACpD,IAAI,IAAI,CAAC,0BAA0B,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,qBAAqB,CAAC,EAAE,CAAC;gBAC/E,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAA;gBACrC,IAAI,CAAC,cAAc,EAAE,CAAA;gBACrB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,aAAa,EAAE,CAAC,CAAA;YACjE,CAAC;QACL,CAAC,EAAE,IAAI,CAAC,gBAAgB,GAAG,GAAG,CAAC,CAAA;IACnC,CAAC;CACJ"}
|
package/lib/storage.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PersistentStore } from './types';
|
|
2
|
+
export declare const resetSubDomainCache: () => void;
|
|
3
|
+
/**
|
|
4
|
+
* Browsers don't offer a way to check if something is a public suffix
|
|
5
|
+
* e.g. `.com.au`, `.io`, `.org.uk`
|
|
6
|
+
*
|
|
7
|
+
* But they do reject cookies set on public suffixes
|
|
8
|
+
* Setting a cookie on `.co.uk` would mean it was sent for every `.co.uk` site visited
|
|
9
|
+
*
|
|
10
|
+
* So, we can use this to check if a domain is a public suffix
|
|
11
|
+
* by trying to set a cookie on a subdomain of the provided hostname
|
|
12
|
+
* until the browser accepts it
|
|
13
|
+
*
|
|
14
|
+
* inspired by https://github.com/AngusFu/browser-root-domain
|
|
15
|
+
*/
|
|
16
|
+
export declare function seekFirstNonPublicSubDomain(hostname: string, cookieJar?: Document | undefined): string;
|
|
17
|
+
export declare function chooseCookieDomain(hostname: string, cross_subdomain: boolean | undefined): string;
|
|
18
|
+
export declare const cookieStore: PersistentStore;
|
|
19
|
+
export declare const resetLocalStorageSupported: () => void;
|
|
20
|
+
export declare const localStore: PersistentStore;
|
|
21
|
+
export declare const localPlusCookieStore: PersistentStore;
|
|
22
|
+
export declare const memoryStore: PersistentStore;
|
|
23
|
+
export declare const resetSessionStorageSupported: () => void;
|
|
24
|
+
export declare const sessionStore: PersistentStore;
|