@cloudcare/browser-core 3.2.4 → 3.2.7
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/cjs/browser/cookie.js +14 -9
- package/cjs/browser/cookie.js.map +1 -1
- package/cjs/configuration/configuration.js +3 -24
- package/cjs/configuration/configuration.js.map +1 -1
- package/cjs/index.js +90 -41
- package/cjs/index.js.map +1 -1
- package/cjs/init.js +0 -19
- package/cjs/init.js.map +1 -1
- package/cjs/session/sessionConstants.js +3 -1
- package/cjs/session/sessionConstants.js.map +1 -1
- package/cjs/session/sessionInCookie.js +59 -0
- package/cjs/session/sessionInCookie.js.map +1 -0
- package/cjs/session/sessionInLocalStorage.js +44 -0
- package/cjs/session/sessionInLocalStorage.js.map +1 -0
- package/cjs/session/sessionManagement.js +38 -31
- package/cjs/session/sessionManagement.js.map +1 -1
- package/cjs/session/sessionState.js +73 -0
- package/cjs/session/sessionState.js.map +1 -0
- package/cjs/session/sessionStore.js +113 -90
- package/cjs/session/sessionStore.js.map +1 -1
- package/cjs/session/sessionStoreOperations.js +117 -0
- package/cjs/session/sessionStoreOperations.js.map +1 -0
- package/esm/browser/cookie.js +15 -8
- package/esm/browser/cookie.js.map +1 -1
- package/esm/configuration/configuration.js +3 -23
- package/esm/configuration/configuration.js.map +1 -1
- package/esm/index.js +3 -4
- package/esm/index.js.map +1 -1
- package/esm/init.js +0 -19
- package/esm/init.js.map +1 -1
- package/esm/session/sessionConstants.js +1 -0
- package/esm/session/sessionConstants.js.map +1 -1
- package/esm/session/sessionInCookie.js +51 -0
- package/esm/session/sessionInCookie.js.map +1 -0
- package/esm/session/sessionInLocalStorage.js +37 -0
- package/esm/session/sessionInLocalStorage.js.map +1 -0
- package/esm/session/sessionManagement.js +35 -28
- package/esm/session/sessionManagement.js.map +1 -1
- package/esm/session/sessionState.js +59 -0
- package/esm/session/sessionState.js.map +1 -0
- package/esm/session/sessionStore.js +113 -90
- package/esm/session/sessionStore.js.map +1 -1
- package/esm/session/sessionStoreOperations.js +108 -0
- package/esm/session/sessionStoreOperations.js.map +1 -0
- package/package.json +2 -2
- package/src/browser/cookie.js +23 -11
- package/src/configuration/configuration.js +8 -32
- package/src/index.js +9 -4
- package/src/init.js +0 -19
- package/src/session/sessionConstants.js +1 -0
- package/src/session/sessionInCookie.js +87 -0
- package/src/session/sessionInLocalStorage.js +45 -0
- package/src/session/sessionManagement.js +48 -36
- package/src/session/sessionState.js +72 -0
- package/src/session/sessionStore.js +163 -108
- package/src/session/sessionStoreOperations.js +134 -0
- package/types/index.d.ts +4 -0
- package/cjs/session/sessionCookieStore.js +0 -156
- package/cjs/session/sessionCookieStore.js.map +0 -1
- package/cjs/synthetics/usr.js +0 -26
- package/cjs/synthetics/usr.js.map +0 -1
- package/esm/session/sessionCookieStore.js +0 -142
- package/esm/session/sessionCookieStore.js.map +0 -1
- package/esm/synthetics/usr.js +0 -17
- package/esm/synthetics/usr.js.map +0 -1
- package/src/session/sessionCookieStore.js +0 -169
- package/src/synthetics/usr.js +0 -18
|
@@ -4,152 +4,175 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.STORAGE_POLL_DELAY = void 0;
|
|
7
|
+
exports.selectSessionStoreStrategyType = selectSessionStoreStrategyType;
|
|
7
8
|
exports.startSessionStore = startSessionStore;
|
|
8
|
-
var
|
|
9
|
+
var _timer = require("../helper/timer");
|
|
9
10
|
var _observable = require("../helper/observable");
|
|
10
11
|
var _tools = require("../helper/tools");
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
12
|
+
var _sessionInCookie = require("./sessionInCookie");
|
|
13
|
+
var _sessionState = require("./sessionState");
|
|
14
|
+
var _sessionInLocalStorage = require("./sessionInLocalStorage");
|
|
15
|
+
var _sessionStoreOperations = require("./sessionStoreOperations");
|
|
16
|
+
/**
|
|
17
|
+
* Every second, the storage will be polled to check for any change that can occur
|
|
18
|
+
* to the session state in another browser tab, or another window.
|
|
19
|
+
* This value has been determined from our previous cookie-only implementation.
|
|
20
|
+
*/
|
|
14
21
|
var STORAGE_POLL_DELAY = _tools.ONE_SECOND;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Checks if cookies are available as the preferred storage
|
|
25
|
+
* Else, checks if LocalStorage is allowed and available
|
|
26
|
+
*/
|
|
27
|
+
exports.STORAGE_POLL_DELAY = STORAGE_POLL_DELAY;
|
|
28
|
+
function selectSessionStoreStrategyType(initConfiguration) {
|
|
29
|
+
var sessionStoreStrategyType = (0, _sessionInCookie.selectCookieStrategy)(initConfiguration);
|
|
30
|
+
if (!sessionStoreStrategyType && initConfiguration.allowFallbackToLocalStorage) {
|
|
31
|
+
sessionStoreStrategyType = (0, _sessionInLocalStorage.selectLocalStorageStrategy)();
|
|
32
|
+
}
|
|
33
|
+
return sessionStoreStrategyType;
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
/**
|
|
16
37
|
* Different session concepts:
|
|
17
38
|
* - tracked, the session has an id and is updated along the user navigation
|
|
18
39
|
* - not tracked, the session does not have an id but it is updated along the user navigation
|
|
19
40
|
* - inactive, no session in store or session expired, waiting for a renew session
|
|
20
41
|
*/
|
|
21
|
-
|
|
22
|
-
function startSessionStore(options, productKey, computeSessionState) {
|
|
42
|
+
function startSessionStore(sessionStoreStrategyType, productKey, computeSessionState) {
|
|
23
43
|
var renewObservable = new _observable.Observable();
|
|
24
44
|
var expireObservable = new _observable.Observable();
|
|
45
|
+
var sessionStateUpdateObservable = new _observable.Observable();
|
|
46
|
+
var sessionStoreStrategy = sessionStoreStrategyType.type === 'Cookie' ? (0, _sessionInCookie.initCookieStrategy)(sessionStoreStrategyType.cookieOptions) : (0, _sessionInLocalStorage.initLocalStorageStrategy)();
|
|
47
|
+
var expireSession = sessionStoreStrategy.expireSession;
|
|
25
48
|
var watchSessionTimeoutId = (0, _timer.setInterval)(watchSession, STORAGE_POLL_DELAY);
|
|
26
|
-
var sessionCache
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
var sessionCache;
|
|
50
|
+
startSession();
|
|
51
|
+
var _throttle = (0, _tools.throttle)(function () {
|
|
52
|
+
(0, _sessionStoreOperations.processSessionStoreOperations)({
|
|
53
|
+
process: function process(sessionState) {
|
|
54
|
+
if ((0, _sessionState.isSessionInNotStartedState)(sessionState)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var synchronizedSession = synchronizeSession(sessionState);
|
|
58
|
+
expandOrRenewSessionState(synchronizedSession);
|
|
59
|
+
return synchronizedSession;
|
|
60
|
+
},
|
|
61
|
+
after: function after(sessionState) {
|
|
62
|
+
if ((0, _sessionState.isSessionStarted)(sessionState) && !hasSessionInCache()) {
|
|
63
|
+
renewSessionInCache(sessionState);
|
|
64
|
+
}
|
|
65
|
+
sessionCache = sessionState;
|
|
39
66
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var throttledExpandOrRenewSession = _throttleExpandOrRenewSession.throttled;
|
|
45
|
-
var cancelExpandOrRenewSession = _throttleExpandOrRenewSession.cancel;
|
|
46
|
-
// function expandOrRenewSession() {
|
|
47
|
-
// var isTracked
|
|
48
|
-
// withCookieLockAccess({
|
|
49
|
-
// options: options,
|
|
50
|
-
// process: function (cookieSession) {
|
|
51
|
-
// var synchronizedSession = synchronizeSession(cookieSession)
|
|
52
|
-
// isTracked = expandOrRenewCookie(synchronizedSession)
|
|
53
|
-
// return synchronizedSession
|
|
54
|
-
// },
|
|
55
|
-
// after: function (cookieSession) {
|
|
56
|
-
// if (isTracked && !hasSessionInCache()) {
|
|
57
|
-
// renewSession(cookieSession)
|
|
58
|
-
// }
|
|
59
|
-
// sessionCache = cookieSession
|
|
60
|
-
// }
|
|
61
|
-
// })
|
|
62
|
-
// }
|
|
63
|
-
|
|
67
|
+
}, sessionStoreStrategy);
|
|
68
|
+
}, STORAGE_POLL_DELAY),
|
|
69
|
+
throttledExpandOrRenewSession = _throttle.throttled,
|
|
70
|
+
cancelExpandOrRenewSession = _throttle.cancel;
|
|
64
71
|
function expandSession() {
|
|
65
|
-
(0,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return hasSessionInCache() ? synchronizeSession(cookieSession) : undefined;
|
|
72
|
+
(0, _sessionStoreOperations.processSessionStoreOperations)({
|
|
73
|
+
process: function process(sessionState) {
|
|
74
|
+
return hasSessionInCache() ? synchronizeSession(sessionState) : undefined;
|
|
69
75
|
}
|
|
70
|
-
});
|
|
76
|
+
}, sessionStoreStrategy);
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
/**
|
|
74
80
|
* allows two behaviors:
|
|
75
|
-
* - if the session is active, synchronize the session cache without updating the session
|
|
76
|
-
* - if the session is not active, clear the session
|
|
81
|
+
* - if the session is active, synchronize the session cache without updating the session store
|
|
82
|
+
* - if the session is not active, clear the session store and expire the session cache
|
|
77
83
|
*/
|
|
78
84
|
function watchSession() {
|
|
79
|
-
(0,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return !isActiveSession(cookieSession) ? {} : undefined;
|
|
85
|
+
(0, _sessionStoreOperations.processSessionStoreOperations)({
|
|
86
|
+
process: function process(sessionState) {
|
|
87
|
+
return (0, _sessionState.isSessionInExpiredState)(sessionState) ? (0, _sessionState.getExpiredSessionState)() : undefined;
|
|
83
88
|
},
|
|
84
89
|
after: synchronizeSession
|
|
85
|
-
});
|
|
90
|
+
}, sessionStoreStrategy);
|
|
86
91
|
}
|
|
87
|
-
function synchronizeSession(
|
|
88
|
-
if (
|
|
89
|
-
|
|
92
|
+
function synchronizeSession(sessionState) {
|
|
93
|
+
if ((0, _sessionState.isSessionInExpiredState)(sessionState)) {
|
|
94
|
+
sessionState = (0, _sessionState.getExpiredSessionState)();
|
|
90
95
|
}
|
|
91
96
|
if (hasSessionInCache()) {
|
|
92
|
-
if (isSessionInCacheOutdated(
|
|
97
|
+
if (isSessionInCacheOutdated(sessionState)) {
|
|
93
98
|
expireSessionInCache();
|
|
94
99
|
} else {
|
|
95
|
-
|
|
100
|
+
sessionStateUpdateObservable.notify({
|
|
101
|
+
previousState: sessionCache,
|
|
102
|
+
newState: sessionState
|
|
103
|
+
});
|
|
104
|
+
sessionCache = sessionState;
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
|
-
return
|
|
107
|
+
return sessionState;
|
|
99
108
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
function startSession() {
|
|
110
|
+
(0, _sessionStoreOperations.processSessionStoreOperations)({
|
|
111
|
+
process: function process(sessionState) {
|
|
112
|
+
if ((0, _sessionState.isSessionInNotStartedState)(sessionState)) {
|
|
113
|
+
return (0, _sessionState.getExpiredSessionState)();
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
after: function after(sessionState) {
|
|
117
|
+
sessionCache = sessionState;
|
|
118
|
+
}
|
|
119
|
+
}, sessionStoreStrategy);
|
|
120
|
+
}
|
|
121
|
+
function expandOrRenewSessionState(sessionState) {
|
|
122
|
+
if ((0, _sessionState.isSessionInNotStartedState)(sessionState)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
var _computeSessionState = computeSessionState(sessionState[productKey]),
|
|
126
|
+
trackingType = _computeSessionState.trackingType,
|
|
127
|
+
isTracked = _computeSessionState.isTracked;
|
|
128
|
+
sessionState[productKey] = trackingType;
|
|
129
|
+
delete sessionState.isExpired;
|
|
130
|
+
if (isTracked && !sessionState.id) {
|
|
131
|
+
sessionState.id = (0, _tools.UUID)();
|
|
132
|
+
sessionState.created = String((0, _tools.dateNow)());
|
|
108
133
|
}
|
|
109
|
-
return isTracked;
|
|
110
134
|
}
|
|
111
135
|
function hasSessionInCache() {
|
|
112
136
|
return sessionCache[productKey] !== undefined;
|
|
113
137
|
}
|
|
114
|
-
function isSessionInCacheOutdated(
|
|
115
|
-
return sessionCache.id !==
|
|
138
|
+
function isSessionInCacheOutdated(sessionState) {
|
|
139
|
+
return sessionCache.id !== sessionState.id || sessionCache[productKey] !== sessionState[productKey];
|
|
116
140
|
}
|
|
117
141
|
function expireSessionInCache() {
|
|
118
|
-
sessionCache =
|
|
142
|
+
sessionCache = (0, _sessionState.getExpiredSessionState)();
|
|
119
143
|
expireObservable.notify();
|
|
120
144
|
}
|
|
121
|
-
function
|
|
122
|
-
sessionCache =
|
|
145
|
+
function renewSessionInCache(sessionState) {
|
|
146
|
+
sessionCache = sessionState;
|
|
123
147
|
renewObservable.notify();
|
|
124
148
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
function isActiveSession(session) {
|
|
133
|
-
// created and expire can be undefined for versions which was not storing them
|
|
134
|
-
// these checks could be removed when older versions will not be available/live anymore
|
|
135
|
-
return (session.created === undefined || (0, _tools.dateNow)() - Number(session.created) < _sessionConstants.SESSION_TIME_OUT_DELAY) && (session.expire === undefined || (0, _tools.dateNow)() < Number(session.expire));
|
|
149
|
+
function updateSessionState(partialSessionState) {
|
|
150
|
+
(0, _sessionStoreOperations.processSessionStoreOperations)({
|
|
151
|
+
process: function process(sessionState) {
|
|
152
|
+
return (0, _tools.assign)({}, sessionState, partialSessionState);
|
|
153
|
+
},
|
|
154
|
+
after: synchronizeSession
|
|
155
|
+
}, sessionStoreStrategy);
|
|
136
156
|
}
|
|
137
157
|
return {
|
|
138
158
|
expandOrRenewSession: throttledExpandOrRenewSession,
|
|
139
159
|
expandSession: expandSession,
|
|
140
160
|
getSession: function getSession() {
|
|
141
|
-
return sessionCache;
|
|
161
|
+
return sessionCache || {};
|
|
142
162
|
},
|
|
143
163
|
renewObservable: renewObservable,
|
|
144
164
|
expireObservable: expireObservable,
|
|
165
|
+
sessionStateUpdateObservable: sessionStateUpdateObservable,
|
|
166
|
+
restartSession: startSession,
|
|
145
167
|
expire: function expire() {
|
|
146
168
|
cancelExpandOrRenewSession();
|
|
147
|
-
(
|
|
148
|
-
synchronizeSession(
|
|
169
|
+
expireSession();
|
|
170
|
+
synchronizeSession((0, _sessionState.getExpiredSessionState)());
|
|
149
171
|
},
|
|
150
172
|
stop: function stop() {
|
|
151
173
|
(0, _timer.clearInterval)(watchSessionTimeoutId);
|
|
152
|
-
}
|
|
174
|
+
},
|
|
175
|
+
updateSessionState: updateSessionState
|
|
153
176
|
};
|
|
154
177
|
}
|
|
155
178
|
//# sourceMappingURL=sessionStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionStore.js","names":["_cookie","require","_observable","_tools","_sessionConstants","_sessionCookieStore","_timer","STORAGE_POLL_DELAY","ONE_SECOND","exports","startSessionStore","options","productKey","computeSessionState","renewObservable","Observable","expireObservable","watchSessionTimeoutId","setInterval","watchSession","sessionCache","retrieveActiveSession","_throttleExpandOrRenewSession","throttle","isTracked","withCookieLockAccess","process","cookieSession","synchronizedSession","synchronizeSession","expandOrRenewCookie","after","hasSessionInCache","renewSession","throttledExpandOrRenewSession","throttled","cancelExpandOrRenewSession","cancel","expandSession","undefined","isActiveSession","isSessionInCacheOutdated","expireSessionInCache","sessionState","trackingType","id","UUID","created","String","dateNow","notify","session","retrieveSession","Number","SESSION_TIME_OUT_DELAY","expire","expandOrRenewSession","getSession","clearSession","stop","clearInterval"],"sources":["../../src/session/sessionStore.js"],"sourcesContent":["import { COOKIE_ACCESS_DELAY } from '../browser/cookie'\nimport { Observable } from '../helper/observable'\nimport { dateNow, UUID, throttle, ONE_SECOND } from '../helper/tools'\nimport { SESSION_TIME_OUT_DELAY } from './sessionConstants'\nimport {\n retrieveSession,\n withCookieLockAccess,\n clearSession\n} from './sessionCookieStore'\nimport { clearInterval, setInterval } from '../helper/timer'\n\nexport var STORAGE_POLL_DELAY = ONE_SECOND\n/**\n * Different session concepts:\n * - tracked, the session has an id and is updated along the user navigation\n * - not tracked, the session does not have an id but it is updated along the user navigation\n * - inactive, no session in store or session expired, waiting for a renew session\n */\nexport function startSessionStore(options, productKey, computeSessionState) {\n var renewObservable = new Observable()\n var expireObservable = new Observable()\n\n var watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY)\n var sessionCache = retrieveActiveSession()\n var _throttleExpandOrRenewSession = throttle(function () {\n var isTracked\n withCookieLockAccess({\n options: options,\n process: function (cookieSession) {\n var synchronizedSession = synchronizeSession(cookieSession)\n isTracked = expandOrRenewCookie(synchronizedSession)\n return synchronizedSession\n },\n after: function (cookieSession) {\n if (isTracked && !hasSessionInCache()) {\n renewSession(cookieSession)\n }\n sessionCache = cookieSession\n }\n })\n }, STORAGE_POLL_DELAY)\n var throttledExpandOrRenewSession = _throttleExpandOrRenewSession.throttled\n var cancelExpandOrRenewSession = _throttleExpandOrRenewSession.cancel\n // function expandOrRenewSession() {\n // var isTracked\n // withCookieLockAccess({\n // options: options,\n // process: function (cookieSession) {\n // var synchronizedSession = synchronizeSession(cookieSession)\n // isTracked = expandOrRenewCookie(synchronizedSession)\n // return synchronizedSession\n // },\n // after: function (cookieSession) {\n // if (isTracked && !hasSessionInCache()) {\n // renewSession(cookieSession)\n // }\n // sessionCache = cookieSession\n // }\n // })\n // }\n\n function expandSession() {\n withCookieLockAccess({\n options: options,\n process: function (cookieSession) {\n return hasSessionInCache()\n ? synchronizeSession(cookieSession)\n : undefined\n }\n })\n }\n\n /**\n * allows two behaviors:\n * - if the session is active, synchronize the session cache without updating the session cookie\n * - if the session is not active, clear the session cookie and expire the session cache\n */\n function watchSession() {\n withCookieLockAccess({\n options: options,\n process: function (cookieSession) {\n return !isActiveSession(cookieSession) ? {} : undefined\n },\n after: synchronizeSession\n })\n }\n\n function synchronizeSession(cookieSession) {\n if (!isActiveSession(cookieSession)) {\n cookieSession = {}\n }\n if (hasSessionInCache()) {\n if (isSessionInCacheOutdated(cookieSession)) {\n expireSessionInCache()\n } else {\n sessionCache = cookieSession\n }\n }\n return cookieSession\n }\n\n function expandOrRenewCookie(cookieSession) {\n var sessionState = computeSessionState(cookieSession[productKey])\n var trackingType = sessionState.trackingType\n var isTracked = sessionState.isTracked\n cookieSession[productKey] = trackingType\n if (isTracked && !cookieSession.id) {\n cookieSession.id = UUID()\n cookieSession.created = String(dateNow())\n }\n return isTracked\n }\n\n function hasSessionInCache() {\n return sessionCache[productKey] !== undefined\n }\n\n function isSessionInCacheOutdated(cookieSession) {\n return (\n sessionCache.id !== cookieSession.id ||\n sessionCache[productKey] !== cookieSession[productKey]\n )\n }\n\n function expireSessionInCache() {\n sessionCache = {}\n expireObservable.notify()\n }\n\n function renewSession(cookieSession) {\n sessionCache = cookieSession\n renewObservable.notify()\n }\n\n function retrieveActiveSession() {\n var session = retrieveSession()\n if (isActiveSession(session)) {\n return session\n }\n return {}\n }\n\n function isActiveSession(session) {\n // created and expire can be undefined for versions which was not storing them\n // these checks could be removed when older versions will not be available/live anymore\n return (\n (session.created === undefined ||\n dateNow() - Number(session.created) < SESSION_TIME_OUT_DELAY) &&\n (session.expire === undefined || dateNow() < Number(session.expire))\n )\n }\n\n return {\n expandOrRenewSession: throttledExpandOrRenewSession,\n expandSession: expandSession,\n getSession: function () {\n return sessionCache\n },\n renewObservable: renewObservable,\n expireObservable: expireObservable,\n expire: function () {\n cancelExpandOrRenewSession()\n clearSession(options)\n synchronizeSession({})\n },\n stop: function () {\n clearInterval(watchSessionTimeoutId)\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AAEO,IAAIM,kBAAkB,GAAGC,i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AAC,CAAC;MAC5B,IAAAsB,gCAAY,EAAC/C,OAAO,CAAC;MACrBkB,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACD8B,IAAI,EAAE,SAAAA,KAAA,EAAY;MAChB,IAAAC,oBAAa,EAAC3C,qBAAqB,CAAC;IACtC;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"sessionStore.js","names":["_timer","require","_observable","_tools","_sessionInCookie","_sessionState","_sessionInLocalStorage","_sessionStoreOperations","STORAGE_POLL_DELAY","ONE_SECOND","exports","selectSessionStoreStrategyType","initConfiguration","sessionStoreStrategyType","selectCookieStrategy","allowFallbackToLocalStorage","selectLocalStorageStrategy","startSessionStore","productKey","computeSessionState","renewObservable","Observable","expireObservable","sessionStateUpdateObservable","sessionStoreStrategy","type","initCookieStrategy","cookieOptions","initLocalStorageStrategy","expireSession","watchSessionTimeoutId","setInterval","watchSession","sessionCache","startSession","_throttle","throttle","processSessionStoreOperations","process","sessionState","isSessionInNotStartedState","synchronizedSession","synchronizeSession","expandOrRenewSessionState","after","isSessionStarted","hasSessionInCache","renewSessionInCache","throttledExpandOrRenewSession","throttled","cancelExpandOrRenewSession","cancel","expandSession","undefined","isSessionInExpiredState","getExpiredSessionState","isSessionInCacheOutdated","expireSessionInCache","notify","previousState","newState","_computeSessionState","trackingType","isTracked","isExpired","id","UUID","created","String","dateNow","updateSessionState","partialSessionState","assign","expandOrRenewSession","getSession","restartSession","expire","stop","clearInterval"],"sources":["../../src/session/sessionStore.js"],"sourcesContent":["import { clearInterval, setInterval } from '../helper/timer'\nimport { Observable } from '../helper/observable'\nimport { ONE_SECOND, dateNow, throttle, UUID, assign } from '../helper/tools'\nimport { selectCookieStrategy, initCookieStrategy } from './sessionInCookie'\nimport {\n getExpiredSessionState,\n isSessionInExpiredState,\n isSessionInNotStartedState,\n isSessionStarted\n} from './sessionState'\nimport {\n initLocalStorageStrategy,\n selectLocalStorageStrategy\n} from './sessionInLocalStorage'\nimport { processSessionStoreOperations } from './sessionStoreOperations'\n\n/**\n * Every second, the storage will be polled to check for any change that can occur\n * to the session state in another browser tab, or another window.\n * This value has been determined from our previous cookie-only implementation.\n */\nexport const STORAGE_POLL_DELAY = ONE_SECOND\n\n/**\n * Checks if cookies are available as the preferred storage\n * Else, checks if LocalStorage is allowed and available\n */\nexport function selectSessionStoreStrategyType(initConfiguration) {\n let sessionStoreStrategyType = selectCookieStrategy(initConfiguration)\n if (\n !sessionStoreStrategyType &&\n initConfiguration.allowFallbackToLocalStorage\n ) {\n sessionStoreStrategyType = selectLocalStorageStrategy()\n }\n return sessionStoreStrategyType\n}\n\n/**\n * Different session concepts:\n * - tracked, the session has an id and is updated along the user navigation\n * - not tracked, the session does not have an id but it is updated along the user navigation\n * - inactive, no session in store or session expired, waiting for a renew session\n */\nexport function startSessionStore(\n sessionStoreStrategyType,\n productKey,\n computeSessionState\n) {\n const renewObservable = new Observable()\n const expireObservable = new Observable()\n const sessionStateUpdateObservable = new Observable()\n const sessionStoreStrategy =\n sessionStoreStrategyType.type === 'Cookie'\n ? initCookieStrategy(sessionStoreStrategyType.cookieOptions)\n : initLocalStorageStrategy()\n const { expireSession } = sessionStoreStrategy\n\n const watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY)\n let sessionCache\n\n startSession()\n\n const {\n throttled: throttledExpandOrRenewSession,\n cancel: cancelExpandOrRenewSession\n } = throttle(function () {\n processSessionStoreOperations(\n {\n process: function (sessionState) {\n if (isSessionInNotStartedState(sessionState)) {\n return\n }\n\n const synchronizedSession = synchronizeSession(sessionState)\n expandOrRenewSessionState(synchronizedSession)\n return synchronizedSession\n },\n after: function (sessionState) {\n if (isSessionStarted(sessionState) && !hasSessionInCache()) {\n renewSessionInCache(sessionState)\n }\n sessionCache = sessionState\n }\n },\n sessionStoreStrategy\n )\n }, STORAGE_POLL_DELAY)\n\n function expandSession() {\n processSessionStoreOperations(\n {\n process: function (sessionState) {\n return hasSessionInCache()\n ? synchronizeSession(sessionState)\n : undefined\n }\n },\n sessionStoreStrategy\n )\n }\n\n /**\n * allows two behaviors:\n * - if the session is active, synchronize the session cache without updating the session store\n * - if the session is not active, clear the session store and expire the session cache\n */\n function watchSession() {\n processSessionStoreOperations(\n {\n process: function (sessionState) {\n return isSessionInExpiredState(sessionState)\n ? getExpiredSessionState()\n : undefined\n },\n after: synchronizeSession\n },\n sessionStoreStrategy\n )\n }\n\n function synchronizeSession(sessionState) {\n if (isSessionInExpiredState(sessionState)) {\n sessionState = getExpiredSessionState()\n }\n if (hasSessionInCache()) {\n if (isSessionInCacheOutdated(sessionState)) {\n expireSessionInCache()\n } else {\n sessionStateUpdateObservable.notify({\n previousState: sessionCache,\n newState: sessionState\n })\n sessionCache = sessionState\n }\n }\n return sessionState\n }\n\n function startSession() {\n processSessionStoreOperations(\n {\n process: function (sessionState) {\n if (isSessionInNotStartedState(sessionState)) {\n return getExpiredSessionState()\n }\n },\n after: function (sessionState) {\n sessionCache = sessionState\n }\n },\n sessionStoreStrategy\n )\n }\n\n function expandOrRenewSessionState(sessionState) {\n if (isSessionInNotStartedState(sessionState)) {\n return false\n }\n\n const { trackingType, isTracked } = computeSessionState(\n sessionState[productKey]\n )\n sessionState[productKey] = trackingType\n delete sessionState.isExpired\n if (isTracked && !sessionState.id) {\n sessionState.id = UUID()\n sessionState.created = String(dateNow())\n }\n }\n\n function hasSessionInCache() {\n return sessionCache[productKey] !== undefined\n }\n\n function isSessionInCacheOutdated(sessionState) {\n return (\n sessionCache.id !== sessionState.id ||\n sessionCache[productKey] !== sessionState[productKey]\n )\n }\n\n function expireSessionInCache() {\n sessionCache = getExpiredSessionState()\n expireObservable.notify()\n }\n\n function renewSessionInCache(sessionState) {\n sessionCache = sessionState\n renewObservable.notify()\n }\n\n function updateSessionState(partialSessionState) {\n processSessionStoreOperations(\n {\n process: function (sessionState) {\n return assign({}, sessionState, partialSessionState)\n },\n after: synchronizeSession\n },\n sessionStoreStrategy\n )\n }\n\n return {\n expandOrRenewSession: throttledExpandOrRenewSession,\n expandSession,\n getSession: function () {\n return sessionCache || {}\n },\n renewObservable,\n expireObservable,\n sessionStateUpdateObservable,\n restartSession: startSession,\n expire: function () {\n cancelExpandOrRenewSession()\n expireSession()\n synchronizeSession(getExpiredSessionState())\n },\n stop: function () {\n clearInterval(watchSessionTimeoutId)\n },\n updateSessionState\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAMA,IAAAK,sBAAA,GAAAL,OAAA;AAIA,IAAAM,uBAAA,GAAAN,OAAA;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMO,kBAAkB,GAAGC,iBAAU;;AAE5C;AACA;AACA;AACA;AAHAC,OAAA,CAAAF,kBAAA,GAAAA,kBAAA;AAIO,SAASG,8BAA8BA,CAACC,iBAAiB,EAAE;EAChE,IAAIC,wBAAwB,GAAG,IAAAC,qCAAoB,EAACF,iBAAiB,CAAC;EACtE,IACE,CAACC,wBAAwB,IACzBD,iBAAiB,CAACG,2BAA2B,EAC7C;IACAF,wBAAwB,GAAG,IAAAG,iDAA0B,EAAC,CAAC;EACzD;EACA,OAAOH,wBAAwB;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,iBAAiBA,CAC/BJ,wBAAwB,EACxBK,UAAU,EACVC,mBAAmB,EACnB;EACA,IAAMC,eAAe,GAAG,IAAIC,sBAAU,CAAC,CAAC;EACxC,IAAMC,gBAAgB,GAAG,IAAID,sBAAU,CAAC,CAAC;EACzC,IAAME,4BAA4B,GAAG,IAAIF,sBAAU,CAAC,CAAC;EACrD,IAAMG,oBAAoB,GACxBX,wBAAwB,CAACY,IAAI,KAAK,QAAQ,GACtC,IAAAC,mCAAkB,EAACb,wBAAwB,CAACc,aAAa,CAAC,GA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IACDb,eAAe,EAAfA,eAAe;IACfE,gBAAgB,EAAhBA,gBAAgB;IAChBC,4BAA4B,EAA5BA,4BAA4B;IAC5BoD,cAAc,EAAEzC,YAAY;IAC5B0C,MAAM,EAAE,SAAAA,OAAA,EAAY;MAClB1B,0BAA0B,CAAC,CAAC;MAC5BrB,aAAa,CAAC,CAAC;MACfa,kBAAkB,CAAC,IAAAa,oCAAsB,EAAC,CAAC,CAAC;IAC9C,CAAC;IACDsB,IAAI,EAAE,SAAAA,KAAA,EAAY;MAChB,IAAAC,oBAAa,EAAChD,qBAAqB,CAAC;IACtC,CAAC;IACDwC,kBAAkB,EAAlBA;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LOCK_RETRY_DELAY = exports.LOCK_MAX_TRIES = void 0;
|
|
7
|
+
exports.processSessionStoreOperations = processSessionStoreOperations;
|
|
8
|
+
var _timer = require("../helper/timer");
|
|
9
|
+
var _tools = require("../helper/tools");
|
|
10
|
+
var _sessionState = require("./sessionState");
|
|
11
|
+
var LOCK_RETRY_DELAY = 10;
|
|
12
|
+
exports.LOCK_RETRY_DELAY = LOCK_RETRY_DELAY;
|
|
13
|
+
var LOCK_MAX_TRIES = 100;
|
|
14
|
+
exports.LOCK_MAX_TRIES = LOCK_MAX_TRIES;
|
|
15
|
+
var bufferedOperations = [];
|
|
16
|
+
var ongoingOperations;
|
|
17
|
+
function processSessionStoreOperations(operations, sessionStoreStrategy) {
|
|
18
|
+
var numberOfRetries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
19
|
+
var isLockEnabled = sessionStoreStrategy.isLockEnabled,
|
|
20
|
+
persistSession = sessionStoreStrategy.persistSession,
|
|
21
|
+
expireSession = sessionStoreStrategy.expireSession;
|
|
22
|
+
var persistWithLock = function persistWithLock(session) {
|
|
23
|
+
return persistSession((0, _tools.assign)({}, session, {
|
|
24
|
+
lock: currentLock
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
var retrieveStore = function retrieveStore() {
|
|
28
|
+
var session = sessionStoreStrategy.retrieveSession();
|
|
29
|
+
var lock = session.lock;
|
|
30
|
+
if (session.lock) {
|
|
31
|
+
delete session.lock;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
session: session,
|
|
35
|
+
lock: lock
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
if (!ongoingOperations) {
|
|
39
|
+
ongoingOperations = operations;
|
|
40
|
+
}
|
|
41
|
+
if (operations !== ongoingOperations) {
|
|
42
|
+
bufferedOperations.push(operations);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) {
|
|
46
|
+
next(sessionStoreStrategy);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var currentLock;
|
|
50
|
+
var currentStore = retrieveStore();
|
|
51
|
+
if (isLockEnabled) {
|
|
52
|
+
// if someone has lock, retry later
|
|
53
|
+
if (currentStore.lock && !(0, _sessionState.isSessionInNotStartedState)(currentStore.session)) {
|
|
54
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// acquire lock
|
|
58
|
+
currentLock = (0, _tools.UUID)();
|
|
59
|
+
persistWithLock(currentStore.session);
|
|
60
|
+
// if lock is not acquired, retry later
|
|
61
|
+
currentStore = retrieveStore();
|
|
62
|
+
if (currentStore.lock !== currentLock && !(0, _sessionState.isSessionInNotStartedState)(currentStore.session)) {
|
|
63
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
var processedSession = operations.process(currentStore.session);
|
|
68
|
+
if (isLockEnabled) {
|
|
69
|
+
// if lock corrupted after process, retry later
|
|
70
|
+
currentStore = retrieveStore();
|
|
71
|
+
if (currentStore.lock !== currentLock && !(0, _sessionState.isSessionInNotStartedState)(currentStore.session)) {
|
|
72
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (processedSession) {
|
|
77
|
+
if ((0, _sessionState.isSessionInExpiredState)(processedSession)) {
|
|
78
|
+
expireSession();
|
|
79
|
+
} else {
|
|
80
|
+
(0, _sessionState.expandSessionState)(processedSession);
|
|
81
|
+
isLockEnabled ? persistWithLock(processedSession) : persistSession(processedSession);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (isLockEnabled) {
|
|
85
|
+
// correctly handle lock around expiration would require to handle this case properly at several levels
|
|
86
|
+
// since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it
|
|
87
|
+
if (!(processedSession && (0, _sessionState.isSessionInExpiredState)(processedSession))) {
|
|
88
|
+
// if lock corrupted after persist, retry later
|
|
89
|
+
currentStore = retrieveStore();
|
|
90
|
+
if (currentStore.lock !== currentLock && !(0, _sessionState.isSessionInNotStartedState)(currentStore.session)) {
|
|
91
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
persistSession(currentStore.session);
|
|
95
|
+
processedSession = currentStore.session;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// call after even if session is not persisted in order to perform operations on
|
|
99
|
+
// up-to-date session state value => the value could have been modified by another tab
|
|
100
|
+
if (operations.after) {
|
|
101
|
+
operations.after(processedSession || currentStore.session);
|
|
102
|
+
}
|
|
103
|
+
next(sessionStoreStrategy);
|
|
104
|
+
}
|
|
105
|
+
function retryLater(operations, sessionStore, currentNumberOfRetries) {
|
|
106
|
+
(0, _timer.setTimeout)(function () {
|
|
107
|
+
processSessionStoreOperations(operations, sessionStore, currentNumberOfRetries + 1);
|
|
108
|
+
}, LOCK_RETRY_DELAY);
|
|
109
|
+
}
|
|
110
|
+
function next(sessionStore) {
|
|
111
|
+
ongoingOperations = undefined;
|
|
112
|
+
var nextOperations = bufferedOperations.shift();
|
|
113
|
+
if (nextOperations) {
|
|
114
|
+
processSessionStoreOperations(nextOperations, sessionStore);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=sessionStoreOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionStoreOperations.js","names":["_timer","require","_tools","_sessionState","LOCK_RETRY_DELAY","exports","LOCK_MAX_TRIES","bufferedOperations","ongoingOperations","processSessionStoreOperations","operations","sessionStoreStrategy","numberOfRetries","arguments","length","undefined","isLockEnabled","persistSession","expireSession","persistWithLock","session","assign","lock","currentLock","retrieveStore","retrieveSession","push","next","currentStore","isSessionInNotStartedState","retryLater","UUID","processedSession","process","isSessionInExpiredState","expandSessionState","after","sessionStore","currentNumberOfRetries","setTimeout","nextOperations","shift"],"sources":["../../src/session/sessionStoreOperations.js"],"sourcesContent":["import { setTimeout } from '../helper/timer'\nimport { UUID, assign } from '../helper/tools'\nimport {\n expandSessionState,\n isSessionInExpiredState,\n isSessionInNotStartedState\n} from './sessionState'\n\nexport const LOCK_RETRY_DELAY = 10\nexport const LOCK_MAX_TRIES = 100\nconst bufferedOperations = []\nlet ongoingOperations\n\nexport function processSessionStoreOperations(\n operations,\n sessionStoreStrategy,\n numberOfRetries = 0\n) {\n const { isLockEnabled, persistSession, expireSession } = sessionStoreStrategy\n const persistWithLock = function (session) {\n return persistSession(assign({}, session, { lock: currentLock }))\n }\n const retrieveStore = function () {\n const session = sessionStoreStrategy.retrieveSession()\n const lock = session.lock\n if (session.lock) {\n delete session.lock\n }\n\n return {\n session,\n lock\n }\n }\n\n if (!ongoingOperations) {\n ongoingOperations = operations\n }\n if (operations !== ongoingOperations) {\n bufferedOperations.push(operations)\n return\n }\n if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) {\n next(sessionStoreStrategy)\n return\n }\n let currentLock\n let currentStore = retrieveStore()\n if (isLockEnabled) {\n // if someone has lock, retry later\n if (\n currentStore.lock &&\n !isSessionInNotStartedState(currentStore.session)\n ) {\n retryLater(operations, sessionStoreStrategy, numberOfRetries)\n return\n }\n // acquire lock\n currentLock = UUID()\n persistWithLock(currentStore.session)\n // if lock is not acquired, retry later\n currentStore = retrieveStore()\n if (\n currentStore.lock !== currentLock &&\n !isSessionInNotStartedState(currentStore.session)\n ) {\n retryLater(operations, sessionStoreStrategy, numberOfRetries)\n return\n }\n }\n let processedSession = operations.process(currentStore.session)\n if (isLockEnabled) {\n // if lock corrupted after process, retry later\n currentStore = retrieveStore()\n if (\n currentStore.lock !== currentLock &&\n !isSessionInNotStartedState(currentStore.session)\n ) {\n retryLater(operations, sessionStoreStrategy, numberOfRetries)\n return\n }\n }\n if (processedSession) {\n if (isSessionInExpiredState(processedSession)) {\n expireSession()\n } else {\n expandSessionState(processedSession)\n isLockEnabled\n ? persistWithLock(processedSession)\n : persistSession(processedSession)\n }\n }\n if (isLockEnabled) {\n // correctly handle lock around expiration would require to handle this case properly at several levels\n // since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it\n if (!(processedSession && isSessionInExpiredState(processedSession))) {\n // if lock corrupted after persist, retry later\n currentStore = retrieveStore()\n if (\n currentStore.lock !== currentLock &&\n !isSessionInNotStartedState(currentStore.session)\n ) {\n retryLater(operations, sessionStoreStrategy, numberOfRetries)\n return\n }\n persistSession(currentStore.session)\n processedSession = currentStore.session\n }\n }\n // call after even if session is not persisted in order to perform operations on\n // up-to-date session state value => the value could have been modified by another tab\n if (operations.after) {\n operations.after(processedSession || currentStore.session)\n }\n next(sessionStoreStrategy)\n}\n\nfunction retryLater(operations, sessionStore, currentNumberOfRetries) {\n setTimeout(function () {\n processSessionStoreOperations(\n operations,\n sessionStore,\n currentNumberOfRetries + 1\n )\n }, LOCK_RETRY_DELAY)\n}\n\nfunction next(sessionStore) {\n ongoingOperations = undefined\n const nextOperations = bufferedOperations.shift()\n if (nextOperations) {\n processSessionStoreOperations(nextOperations, sessionStore)\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAMO,IAAMG,gBAAgB,GAAG,EAAE;AAAAC,OAAA,CAAAD,gBAAA,GAAAA,gBAAA;AAC3B,IAAME,cAAc,GAAG,GAAG;AAAAD,OAAA,CAAAC,cAAA,GAAAA,cAAA;AACjC,IAAMC,kBAAkB,GAAG,EAAE;AAC7B,IAAIC,iBAAiB;AAEd,SAASC,6BAA6BA,CAC3CC,UAAU,EACVC,oBAAoB,EAEpB;EAAA,IADAC,eAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAEnB,IAAQG,aAAa,GAAoCL,oBAAoB,CAArEK,aAAa;IAAEC,cAAc,GAAoBN,oBAAoB,CAAtDM,cAAc;IAAEC,aAAa,GAAKP,oBAAoB,CAAtCO,aAAa;EACpD,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CAAaC,OAAO,EAAE;IACzC,OAAOH,cAAc,CAAC,IAAAI,aAAM,EAAC,CAAC,CAAC,EAAED,OAAO,EAAE;MAAEE,IAAI,EAAEC;IAAY,CAAC,CAAC,CAAC;EACnE,CAAC;EACD,IAAMC,aAAa,GAAG,SAAhBA,aAAaA,CAAA,EAAe;IAChC,IAAMJ,OAAO,GAAGT,oBAAoB,CAACc,eAAe,CAAC,CAAC;IACtD,IAAMH,IAAI,GAAGF,OAAO,CAACE,IAAI;IACzB,IAAIF,OAAO,CAACE,IAAI,EAAE;MAChB,OAAOF,OAAO,CAACE,IAAI;IACrB;IAEA,OAAO;MACLF,OAAO,EAAPA,OAAO;MACPE,IAAI,EAAJA;IACF,CAAC;EACH,CAAC;EAED,IAAI,CAACd,iBAAiB,EAAE;I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ignoreList":[]}
|
package/esm/browser/cookie.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { findCommaSeparatedValue, UUID, ONE_SECOND, findCommaSeparatedValues } from '../helper/tools';
|
|
2
|
-
|
|
1
|
+
import { findCommaSeparatedValue, UUID, ONE_SECOND, ONE_MINUTE, findCommaSeparatedValues } from '../helper/tools';
|
|
2
|
+
function getCookieName(name, options) {
|
|
3
|
+
return "".concat(name, "_").concat(options && options.crossSite ? 'cs1' : 'cs0', "_").concat(options && options.domain ? 'd1' : 'd0', "_").concat(options && options.secure ? 'sec1' : 'sec0', "_").concat(options && options.partitioned ? 'part1' : 'part0');
|
|
4
|
+
}
|
|
3
5
|
export function setCookie(name, value, expireDelay, options) {
|
|
4
6
|
var date = new Date();
|
|
5
7
|
date.setTime(date.getTime() + expireDelay);
|
|
@@ -8,10 +10,10 @@ export function setCookie(name, value, expireDelay, options) {
|
|
|
8
10
|
var domain = options && options.domain ? ';domain=' + options.domain : '';
|
|
9
11
|
var secure = options && options.secure ? ';secure' : '';
|
|
10
12
|
var partitioned = options && options.partitioned ? ';partitioned' : '';
|
|
11
|
-
document.cookie = name + '=' + value + ';' + expires + ';path=/;samesite=' + sameSite + domain + secure + partitioned;
|
|
13
|
+
document.cookie = getCookieName(name, options) + '=' + value + ';' + expires + ';path=/;samesite=' + sameSite + domain + secure + partitioned;
|
|
12
14
|
}
|
|
13
|
-
export function getCookie(name) {
|
|
14
|
-
return findCommaSeparatedValue(document.cookie, name);
|
|
15
|
+
export function getCookie(name, options) {
|
|
16
|
+
return findCommaSeparatedValue(document.cookie, getCookieName(name, options));
|
|
15
17
|
}
|
|
16
18
|
var initCookieParsed;
|
|
17
19
|
/**
|
|
@@ -39,8 +41,10 @@ export function areCookiesAuthorized(options) {
|
|
|
39
41
|
// the test cookie lifetime
|
|
40
42
|
var testCookieName = "gc_cookie_test_".concat(UUID());
|
|
41
43
|
var testCookieValue = 'test';
|
|
42
|
-
setCookie(testCookieName, testCookieValue,
|
|
43
|
-
|
|
44
|
+
setCookie(testCookieName, testCookieValue, ONE_MINUTE, options);
|
|
45
|
+
var isCookieCorrectlySet = getCookie(testCookieName, options) === testCookieValue;
|
|
46
|
+
deleteCookie(testCookieName, options);
|
|
47
|
+
return isCookieCorrectlySet;
|
|
44
48
|
} catch (error) {
|
|
45
49
|
return false;
|
|
46
50
|
}
|
|
@@ -61,11 +65,14 @@ export function getCurrentSite() {
|
|
|
61
65
|
var domainLevels = window.location.hostname.split('.');
|
|
62
66
|
var candidateDomain = domainLevels.pop();
|
|
63
67
|
while (domainLevels.length && !getCookie(testCookieName)) {
|
|
64
|
-
candidateDomain = domainLevels.pop()
|
|
68
|
+
candidateDomain = "".concat(domainLevels.pop(), ".").concat(candidateDomain);
|
|
65
69
|
setCookie(testCookieName, testCookieValue, ONE_SECOND, {
|
|
66
70
|
domain: candidateDomain
|
|
67
71
|
});
|
|
68
72
|
}
|
|
73
|
+
deleteCookie(testCookieName, {
|
|
74
|
+
domain: candidateDomain
|
|
75
|
+
});
|
|
69
76
|
getCurrentSiteCache = candidateDomain;
|
|
70
77
|
}
|
|
71
78
|
return getCurrentSiteCache;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.js","names":["findCommaSeparatedValue","UUID","ONE_SECOND","
|
|
1
|
+
{"version":3,"file":"cookie.js","names":["findCommaSeparatedValue","UUID","ONE_SECOND","ONE_MINUTE","findCommaSeparatedValues","getCookieName","name","options","concat","crossSite","domain","secure","partitioned","setCookie","value","expireDelay","date","Date","setTime","getTime","expires","toUTCString","sameSite","document","cookie","getCookie","initCookieParsed","getInitCookie","get","resetInitCookies","undefined","deleteCookie","areCookiesAuthorized","testCookieName","testCookieValue","isCookieCorrectlySet","error","getCurrentSiteCache","getCurrentSite","domainLevels","window","location","hostname","split","candidateDomain","pop","length"],"sources":["../../src/browser/cookie.js"],"sourcesContent":["import {\n findCommaSeparatedValue,\n UUID,\n ONE_SECOND,\n ONE_MINUTE,\n findCommaSeparatedValues\n} from '../helper/tools'\n\nfunction getCookieName(name, options) {\n return `${name}_${options && options.crossSite ? 'cs1' : 'cs0'}_${\n options && options.domain ? 'd1' : 'd0'\n }_${options && options.secure ? 'sec1' : 'sec0'}_${\n options && options.partitioned ? 'part1' : 'part0'\n }`\n}\nexport function setCookie(name, value, expireDelay, options) {\n var date = new Date()\n date.setTime(date.getTime() + expireDelay)\n var expires = 'expires=' + date.toUTCString()\n var sameSite = options && options.crossSite ? 'none' : 'strict'\n var domain = options && options.domain ? ';domain=' + options.domain : ''\n var secure = options && options.secure ? ';secure' : ''\n var partitioned = options && options.partitioned ? ';partitioned' : ''\n\n document.cookie =\n getCookieName(name, options) +\n '=' +\n value +\n ';' +\n expires +\n ';path=/;samesite=' +\n sameSite +\n domain +\n secure +\n partitioned\n}\n\nexport function getCookie(name, options) {\n return findCommaSeparatedValue(document.cookie, getCookieName(name, options))\n}\nvar initCookieParsed\n/**\n * Returns a cached value of the cookie. Use this during SDK initialization (and whenever possible)\n * to avoid accessing document.cookie multiple times.\n */\nexport function getInitCookie(name) {\n if (!initCookieParsed) {\n initCookieParsed = findCommaSeparatedValues(document.cookie)\n }\n return initCookieParsed.get(name)\n}\n\nexport function resetInitCookies() {\n initCookieParsed = undefined\n}\nexport function deleteCookie(name, options) {\n setCookie(name, '', 0, options)\n}\n\nexport function areCookiesAuthorized(options) {\n if (document.cookie === undefined || document.cookie === null) {\n return false\n }\n try {\n // Use a unique cookie name to avoid issues when the SDK is initialized multiple times during\n // the test cookie lifetime\n var testCookieName = `gc_cookie_test_${UUID()}`\n var testCookieValue = 'test'\n setCookie(testCookieName, testCookieValue, ONE_MINUTE, options)\n const isCookieCorrectlySet =\n getCookie(testCookieName, options) === testCookieValue\n deleteCookie(testCookieName, options)\n return isCookieCorrectlySet\n } catch (error) {\n return false\n }\n}\n\n/**\n * No API to retrieve it, number of levels for subdomain and suffix are unknown\n * strategy: find the minimal domain on which cookies are allowed to be set\n * https://web.dev/same-site-same-origin/#site\n */\nvar getCurrentSiteCache\nexport function getCurrentSite() {\n if (getCurrentSiteCache === undefined) {\n // Use a unique cookie name to avoid issues when the SDK is initialized multiple times during\n // the test cookie lifetime\n const testCookieName = `gc_site_test_${UUID()}`\n const testCookieValue = 'test'\n\n const domainLevels = window.location.hostname.split('.')\n let candidateDomain = domainLevels.pop()\n while (domainLevels.length && !getCookie(testCookieName)) {\n candidateDomain = `${domainLevels.pop()}.${candidateDomain}`\n setCookie(testCookieName, testCookieValue, ONE_SECOND, {\n domain: candidateDomain\n })\n }\n deleteCookie(testCookieName, { domain: candidateDomain })\n getCurrentSiteCache = candidateDomain\n }\n return getCurrentSiteCache\n}\n"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,wBAAwB,QACnB,iBAAiB;AAExB,SAASC,aAAaA,CAACC,IAAI,EAAEC,OAAO,EAAE;EACpC,UAAAC,MAAA,CAAUF,IAAI,OAAAE,MAAA,CAAID,OAAO,IAAIA,OAAO,CAACE,SAAS,GAAG,KAAK,GAAG,KAAK,OAAAD,MAAA,CAC5DD,OAAO,IAAIA,OAAO,CAACG,MAAM,GAAG,IAAI,GAAG,IAAI,OAAAF,MAAA,CACrCD,OAAO,IAAIA,OAAO,CAACI,MAAM,GAAG,MAAM,GAAG,MAAM,OAAAH,MAAA,CAC7CD,OAAO,IAAIA,OAAO,CAACK,WAAW,GAAG,OAAO,GAAG,OAAO;AAEtD;AACA,OAAO,SAASC,SAASA,CAACP,IAAI,EAAEQ,KAAK,EAAEC,WAAW,EAAER,OAAO,EAAE;EAC3D,IAAIS,IAAI,GAAG,IAAIC,IAAI,CAAC,CAAC;EACrBD,IAAI,CAACE,OAAO,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC,GAAGJ,WAAW,CAAC;EAC1C,IAAIK,OAAO,GAAG,UAAU,GAAGJ,IAAI,CAACK,WAAW,CAAC,CAAC;EAC7C,IAAIC,QAAQ,GAAGf,OAAO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mB,GAAGO,eAAe;EACvC;EACA,OAAOP,mBAAmB;AAC5B","ignoreList":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getCurrentSite } from '../browser/cookie';
|
|
2
1
|
import { catchUserErrors } from '../helper/catchUserErrors';
|
|
3
2
|
import { display } from '../helper/display';
|
|
4
3
|
import { assign, isPercentage, ONE_SECOND, isNullUndefinedDefaultValue } from '../helper/tools';
|
|
5
4
|
import { ONE_KIBI_BYTE } from '../helper/byteUtils';
|
|
6
5
|
import { computeTransportConfiguration } from './transportConfiguration';
|
|
6
|
+
import { selectSessionStoreStrategyType } from '../session/sessionStore';
|
|
7
7
|
export var DefaultPrivacyLevel = {
|
|
8
8
|
ALLOW: 'allow',
|
|
9
9
|
MASK: 'mask',
|
|
@@ -22,10 +22,10 @@ export function validateAndBuildConfiguration(initConfiguration) {
|
|
|
22
22
|
display.error('Telemetry Sample Rate should be a number between 0 and 100');
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
var sessionSampleRate = initConfiguration.sessionSampleRate
|
|
25
|
+
var sessionSampleRate = isNullUndefinedDefaultValue(initConfiguration.sessionSampleRate, initConfiguration.sampleRate);
|
|
26
26
|
return assign({
|
|
27
27
|
beforeSend: initConfiguration.beforeSend && catchUserErrors(initConfiguration.beforeSend, 'beforeSend threw an error:'),
|
|
28
|
-
|
|
28
|
+
sessionStoreStrategyType: selectSessionStoreStrategyType(initConfiguration),
|
|
29
29
|
sessionSampleRate: isNullUndefinedDefaultValue(sessionSampleRate, 100),
|
|
30
30
|
service: initConfiguration.service,
|
|
31
31
|
version: initConfiguration.version,
|
|
@@ -74,24 +74,4 @@ export function validatePostRequestRequireParamsConfiguration(initConfiguration)
|
|
|
74
74
|
}
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
|
-
export function buildCookieOptions(initConfiguration) {
|
|
78
|
-
var cookieOptions = {};
|
|
79
|
-
|
|
80
|
-
// cookieOptions.secure = mustUseSecureCookie(initConfiguration)
|
|
81
|
-
// cookieOptions.crossSite = !!initConfiguration.useCrossSiteSessionCookie
|
|
82
|
-
cookieOptions.secure = !!initConfiguration.useSecureSessionCookie || !!initConfiguration.usePartitionedCrossSiteSessionCookie || !!initConfiguration.useCrossSiteSessionCookie;
|
|
83
|
-
cookieOptions.crossSite = !!initConfiguration.usePartitionedCrossSiteSessionCookie || !!initConfiguration.useCrossSiteSessionCookie;
|
|
84
|
-
cookieOptions.partitioned = !!initConfiguration.usePartitionedCrossSiteSessionCookie;
|
|
85
|
-
if (initConfiguration.trackSessionAcrossSubdomains) {
|
|
86
|
-
cookieOptions.domain = getCurrentSite();
|
|
87
|
-
}
|
|
88
|
-
return cookieOptions;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// function mustUseSecureCookie(initConfiguration) {
|
|
92
|
-
// return (
|
|
93
|
-
// !!initConfiguration.useSecureSessionCookie ||
|
|
94
|
-
// !!initConfiguration.useCrossSiteSessionCookie
|
|
95
|
-
// )
|
|
96
|
-
// }
|
|
97
77
|
//# sourceMappingURL=configuration.js.map
|