@cloudcare/browser-core 3.2.4 → 3.2.6
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 +2 -23
- 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 +2 -22
- 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 +3 -30
- 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
|
@@ -1,147 +1,170 @@
|
|
|
1
|
-
import { COOKIE_ACCESS_DELAY } from '../browser/cookie';
|
|
2
|
-
import { Observable } from '../helper/observable';
|
|
3
|
-
import { dateNow, UUID, throttle, ONE_SECOND } from '../helper/tools';
|
|
4
|
-
import { SESSION_TIME_OUT_DELAY } from './sessionConstants';
|
|
5
|
-
import { retrieveSession, withCookieLockAccess, clearSession } from './sessionCookieStore';
|
|
6
1
|
import { clearInterval, setInterval } from '../helper/timer';
|
|
2
|
+
import { Observable } from '../helper/observable';
|
|
3
|
+
import { ONE_SECOND, dateNow, throttle, UUID, assign } from '../helper/tools';
|
|
4
|
+
import { selectCookieStrategy, initCookieStrategy } from './sessionInCookie';
|
|
5
|
+
import { getExpiredSessionState, isSessionInExpiredState, isSessionInNotStartedState, isSessionStarted } from './sessionState';
|
|
6
|
+
import { initLocalStorageStrategy, selectLocalStorageStrategy } from './sessionInLocalStorage';
|
|
7
|
+
import { processSessionStoreOperations } from './sessionStoreOperations';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Every second, the storage will be polled to check for any change that can occur
|
|
11
|
+
* to the session state in another browser tab, or another window.
|
|
12
|
+
* This value has been determined from our previous cookie-only implementation.
|
|
13
|
+
*/
|
|
7
14
|
export var STORAGE_POLL_DELAY = ONE_SECOND;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks if cookies are available as the preferred storage
|
|
18
|
+
* Else, checks if LocalStorage is allowed and available
|
|
19
|
+
*/
|
|
20
|
+
export function selectSessionStoreStrategyType(initConfiguration) {
|
|
21
|
+
var sessionStoreStrategyType = selectCookieStrategy(initConfiguration);
|
|
22
|
+
if (!sessionStoreStrategyType && initConfiguration.allowFallbackToLocalStorage) {
|
|
23
|
+
sessionStoreStrategyType = selectLocalStorageStrategy();
|
|
24
|
+
}
|
|
25
|
+
return sessionStoreStrategyType;
|
|
26
|
+
}
|
|
27
|
+
|
|
8
28
|
/**
|
|
9
29
|
* Different session concepts:
|
|
10
30
|
* - tracked, the session has an id and is updated along the user navigation
|
|
11
31
|
* - not tracked, the session does not have an id but it is updated along the user navigation
|
|
12
32
|
* - inactive, no session in store or session expired, waiting for a renew session
|
|
13
33
|
*/
|
|
14
|
-
export function startSessionStore(
|
|
34
|
+
export function startSessionStore(sessionStoreStrategyType, productKey, computeSessionState) {
|
|
15
35
|
var renewObservable = new Observable();
|
|
16
36
|
var expireObservable = new Observable();
|
|
37
|
+
var sessionStateUpdateObservable = new Observable();
|
|
38
|
+
var sessionStoreStrategy = sessionStoreStrategyType.type === 'Cookie' ? initCookieStrategy(sessionStoreStrategyType.cookieOptions) : initLocalStorageStrategy();
|
|
39
|
+
var expireSession = sessionStoreStrategy.expireSession;
|
|
17
40
|
var watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY);
|
|
18
|
-
var sessionCache
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
var sessionCache;
|
|
42
|
+
startSession();
|
|
43
|
+
var _throttle = throttle(function () {
|
|
44
|
+
processSessionStoreOperations({
|
|
45
|
+
process: function process(sessionState) {
|
|
46
|
+
if (isSessionInNotStartedState(sessionState)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var synchronizedSession = synchronizeSession(sessionState);
|
|
50
|
+
expandOrRenewSessionState(synchronizedSession);
|
|
51
|
+
return synchronizedSession;
|
|
52
|
+
},
|
|
53
|
+
after: function after(sessionState) {
|
|
54
|
+
if (isSessionStarted(sessionState) && !hasSessionInCache()) {
|
|
55
|
+
renewSessionInCache(sessionState);
|
|
56
|
+
}
|
|
57
|
+
sessionCache = sessionState;
|
|
31
58
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var throttledExpandOrRenewSession = _throttleExpandOrRenewSession.throttled;
|
|
37
|
-
var cancelExpandOrRenewSession = _throttleExpandOrRenewSession.cancel;
|
|
38
|
-
// function expandOrRenewSession() {
|
|
39
|
-
// var isTracked
|
|
40
|
-
// withCookieLockAccess({
|
|
41
|
-
// options: options,
|
|
42
|
-
// process: function (cookieSession) {
|
|
43
|
-
// var synchronizedSession = synchronizeSession(cookieSession)
|
|
44
|
-
// isTracked = expandOrRenewCookie(synchronizedSession)
|
|
45
|
-
// return synchronizedSession
|
|
46
|
-
// },
|
|
47
|
-
// after: function (cookieSession) {
|
|
48
|
-
// if (isTracked && !hasSessionInCache()) {
|
|
49
|
-
// renewSession(cookieSession)
|
|
50
|
-
// }
|
|
51
|
-
// sessionCache = cookieSession
|
|
52
|
-
// }
|
|
53
|
-
// })
|
|
54
|
-
// }
|
|
55
|
-
|
|
59
|
+
}, sessionStoreStrategy);
|
|
60
|
+
}, STORAGE_POLL_DELAY),
|
|
61
|
+
throttledExpandOrRenewSession = _throttle.throttled,
|
|
62
|
+
cancelExpandOrRenewSession = _throttle.cancel;
|
|
56
63
|
function expandSession() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return hasSessionInCache() ? synchronizeSession(cookieSession) : undefined;
|
|
64
|
+
processSessionStoreOperations({
|
|
65
|
+
process: function process(sessionState) {
|
|
66
|
+
return hasSessionInCache() ? synchronizeSession(sessionState) : undefined;
|
|
61
67
|
}
|
|
62
|
-
});
|
|
68
|
+
}, sessionStoreStrategy);
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
/**
|
|
66
72
|
* allows two behaviors:
|
|
67
|
-
* - if the session is active, synchronize the session cache without updating the session
|
|
68
|
-
* - if the session is not active, clear the session
|
|
73
|
+
* - if the session is active, synchronize the session cache without updating the session store
|
|
74
|
+
* - if the session is not active, clear the session store and expire the session cache
|
|
69
75
|
*/
|
|
70
76
|
function watchSession() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return !isActiveSession(cookieSession) ? {} : undefined;
|
|
77
|
+
processSessionStoreOperations({
|
|
78
|
+
process: function process(sessionState) {
|
|
79
|
+
return isSessionInExpiredState(sessionState) ? getExpiredSessionState() : undefined;
|
|
75
80
|
},
|
|
76
81
|
after: synchronizeSession
|
|
77
|
-
});
|
|
82
|
+
}, sessionStoreStrategy);
|
|
78
83
|
}
|
|
79
|
-
function synchronizeSession(
|
|
80
|
-
if (
|
|
81
|
-
|
|
84
|
+
function synchronizeSession(sessionState) {
|
|
85
|
+
if (isSessionInExpiredState(sessionState)) {
|
|
86
|
+
sessionState = getExpiredSessionState();
|
|
82
87
|
}
|
|
83
88
|
if (hasSessionInCache()) {
|
|
84
|
-
if (isSessionInCacheOutdated(
|
|
89
|
+
if (isSessionInCacheOutdated(sessionState)) {
|
|
85
90
|
expireSessionInCache();
|
|
86
91
|
} else {
|
|
87
|
-
|
|
92
|
+
sessionStateUpdateObservable.notify({
|
|
93
|
+
previousState: sessionCache,
|
|
94
|
+
newState: sessionState
|
|
95
|
+
});
|
|
96
|
+
sessionCache = sessionState;
|
|
88
97
|
}
|
|
89
98
|
}
|
|
90
|
-
return
|
|
99
|
+
return sessionState;
|
|
100
|
+
}
|
|
101
|
+
function startSession() {
|
|
102
|
+
processSessionStoreOperations({
|
|
103
|
+
process: function process(sessionState) {
|
|
104
|
+
if (isSessionInNotStartedState(sessionState)) {
|
|
105
|
+
return getExpiredSessionState();
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
after: function after(sessionState) {
|
|
109
|
+
sessionCache = sessionState;
|
|
110
|
+
}
|
|
111
|
+
}, sessionStoreStrategy);
|
|
91
112
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
function expandOrRenewSessionState(sessionState) {
|
|
114
|
+
if (isSessionInNotStartedState(sessionState)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
var _computeSessionState = computeSessionState(sessionState[productKey]),
|
|
118
|
+
trackingType = _computeSessionState.trackingType,
|
|
119
|
+
isTracked = _computeSessionState.isTracked;
|
|
120
|
+
sessionState[productKey] = trackingType;
|
|
121
|
+
delete sessionState.isExpired;
|
|
122
|
+
if (isTracked && !sessionState.id) {
|
|
123
|
+
sessionState.id = UUID();
|
|
124
|
+
sessionState.created = String(dateNow());
|
|
100
125
|
}
|
|
101
|
-
return isTracked;
|
|
102
126
|
}
|
|
103
127
|
function hasSessionInCache() {
|
|
104
128
|
return sessionCache[productKey] !== undefined;
|
|
105
129
|
}
|
|
106
|
-
function isSessionInCacheOutdated(
|
|
107
|
-
return sessionCache.id !==
|
|
130
|
+
function isSessionInCacheOutdated(sessionState) {
|
|
131
|
+
return sessionCache.id !== sessionState.id || sessionCache[productKey] !== sessionState[productKey];
|
|
108
132
|
}
|
|
109
133
|
function expireSessionInCache() {
|
|
110
|
-
sessionCache =
|
|
134
|
+
sessionCache = getExpiredSessionState();
|
|
111
135
|
expireObservable.notify();
|
|
112
136
|
}
|
|
113
|
-
function
|
|
114
|
-
sessionCache =
|
|
137
|
+
function renewSessionInCache(sessionState) {
|
|
138
|
+
sessionCache = sessionState;
|
|
115
139
|
renewObservable.notify();
|
|
116
140
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
function isActiveSession(session) {
|
|
125
|
-
// created and expire can be undefined for versions which was not storing them
|
|
126
|
-
// these checks could be removed when older versions will not be available/live anymore
|
|
127
|
-
return (session.created === undefined || dateNow() - Number(session.created) < SESSION_TIME_OUT_DELAY) && (session.expire === undefined || dateNow() < Number(session.expire));
|
|
141
|
+
function updateSessionState(partialSessionState) {
|
|
142
|
+
processSessionStoreOperations({
|
|
143
|
+
process: function process(sessionState) {
|
|
144
|
+
return assign({}, sessionState, partialSessionState);
|
|
145
|
+
},
|
|
146
|
+
after: synchronizeSession
|
|
147
|
+
}, sessionStoreStrategy);
|
|
128
148
|
}
|
|
129
149
|
return {
|
|
130
150
|
expandOrRenewSession: throttledExpandOrRenewSession,
|
|
131
151
|
expandSession: expandSession,
|
|
132
152
|
getSession: function getSession() {
|
|
133
|
-
return sessionCache;
|
|
153
|
+
return sessionCache || {};
|
|
134
154
|
},
|
|
135
155
|
renewObservable: renewObservable,
|
|
136
156
|
expireObservable: expireObservable,
|
|
157
|
+
sessionStateUpdateObservable: sessionStateUpdateObservable,
|
|
158
|
+
restartSession: startSession,
|
|
137
159
|
expire: function expire() {
|
|
138
160
|
cancelExpandOrRenewSession();
|
|
139
|
-
|
|
140
|
-
synchronizeSession(
|
|
161
|
+
expireSession();
|
|
162
|
+
synchronizeSession(getExpiredSessionState());
|
|
141
163
|
},
|
|
142
164
|
stop: function stop() {
|
|
143
165
|
clearInterval(watchSessionTimeoutId);
|
|
144
|
-
}
|
|
166
|
+
},
|
|
167
|
+
updateSessionState: updateSessionState
|
|
145
168
|
};
|
|
146
169
|
}
|
|
147
170
|
//# sourceMappingURL=sessionStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionStore.js","names":["COOKIE_ACCESS_DELAY","Observable","dateNow","UUID","throttle","ONE_SECOND","SESSION_TIME_OUT_DELAY","retrieveSession","withCookieLockAccess","clearSession","clearInterval","setInterval","STORAGE_POLL_DELAY","startSessionStore","options","productKey","computeSessionState","renewObservable","expireObservable","watchSessionTimeoutId","watchSession","sessionCache","retrieveActiveSession","_throttleExpandOrRenewSession","isTracked","process","cookieSession","synchronizedSession","synchronizeSession","expandOrRenewCookie","after","hasSessionInCache","renewSession","throttledExpandOrRenewSession","throttled","cancelExpandOrRenewSession","cancel","expandSession","undefined","isActiveSession","isSessionInCacheOutdated","expireSessionInCache","sessionState","trackingType","id","created","String","notify","session","Number","expire","expandOrRenewSession","getSession","stop"],"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,SAASA,mBAAmB,QAAQ,mBAAmB;AACvD,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,OAAO,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,UAAU,QAAQ,iBAAiB;AACrE,SAASC,sBAAsB,QAAQ,oBAAoB;AAC3D,SACEC,eAAe,EACfC,oBAAoB,EACpBC,YAAY,QACP,sBAAsB;AAC7B,SAASC,aAAa,EAAEC,WAAW,QAAQ,iBAAiB;AAE5D,OAAO,IAAIC,kBAAkB,GAAGP,UAAU;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,iBAAiBA,CAACC,OAAO,EAAEC,UAAU,EAAEC,mBAAmB,EAAE;EAC1E,IAAIC,eAAe,GAAG,IAAIhB,UAAU,CAAC,CAAC;EACtC,IAAIiB,gBAAgB,GAAG,IAAIjB,UAAU,CAAC,CAAC;EAEvC,IAAIkB,qBAAqB,GAAGR,WAAW,CAACS,YAAY,EAAER,kBAAkB,CAAC;EACzE,IAAI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ACN,aAAa,EAAE;IACnCL,YAAY,GAAGK,aAAa;IAC5BT,eAAe,CAAC8B,MAAM,CAAC,CAAC;EAC1B;EAEA,SAASzB,qBAAqBA,CAAA,EAAG;IAC/B,IAAI0B,OAAO,GAAGzC,eAAe,CAAC,CAAC;IAC/B,IAAIgC,eAAe,CAACS,OAAO,CAAC,EAAE;MAC5B,OAAOA,OAAO;IAChB;IACA,OAAO,CAAC,CAAC;EACX;EAEA,SAAST,eAAeA,CAACS,OAAO,EAAE;IAChC;IACA;IACA,OACE,CAACA,OAAO,CAACH,OAAO,KAAKP,SAAS,IAC5BpC,OAAO,CAAC,CAAC,GAAG+C,MAAM,CAACD,OAAO,CAACH,OAAO,CAAC,GAAGvC,sBAAsB,MAC7D0C,OAAO,CAACE,MAAM,KAAKZ,SAAS,IAAIpC,OAAO,CAAC,CAAC,GAAG+C,MAAM,CAACD,OAAO,CAACE,MAAM,CAAC,CAAC;EAExE;EAEA,OAAO;IACLC,oBAAoB,EAAElB,6BAA6B;IACnDI,aAAa,EAAEA,aAAa;IAC5Be,UAAU,EAAE,SAAAA,WAAA,EAAY;MACtB,OAAO/B,YAAY;IACrB,CAAC;IACDJ,eAAe,EAAEA,eAAe;IAChCC,gBAAgB,EAAEA,gBAAgB;IAClCgC,MAAM,EAAE,SAAAA,OAAA,EAAY;MAClBf,0BAA0B,CAAC,CAAC;MAC5B1B,YAAY,CAACK,OAAO,CAAC;MACrBc,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACDyB,IAAI,EAAE,SAAAA,KAAA,EAAY;MAChB3C,aAAa,CAACS,qBAAqB,CAAC;IACtC;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"sessionStore.js","names":["clearInterval","setInterval","Observable","ONE_SECOND","dateNow","throttle","UUID","assign","selectCookieStrategy","initCookieStrategy","getExpiredSessionState","isSessionInExpiredState","isSessionInNotStartedState","isSessionStarted","initLocalStorageStrategy","selectLocalStorageStrategy","processSessionStoreOperations","STORAGE_POLL_DELAY","selectSessionStoreStrategyType","initConfiguration","sessionStoreStrategyType","allowFallbackToLocalStorage","startSessionStore","productKey","computeSessionState","renewObservable","expireObservable","sessionStateUpdateObservable","sessionStoreStrategy","type","cookieOptions","expireSession","watchSessionTimeoutId","watchSession","sessionCache","startSession","_throttle","process","sessionState","synchronizedSession","synchronizeSession","expandOrRenewSessionState","after","hasSessionInCache","renewSessionInCache","throttledExpandOrRenewSession","throttled","cancelExpandOrRenewSession","cancel","expandSession","undefined","isSessionInCacheOutdated","expireSessionInCache","notify","previousState","newState","_computeSessionState","trackingType","isTracked","isExpired","id","created","String","updateSessionState","partialSessionState","expandOrRenewSession","getSession","restartSession","expire","stop"],"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,SAASA,aAAa,EAAEC,WAAW,QAAQ,iBAAiB;AAC5D,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,MAAM,QAAQ,iBAAiB;AAC7E,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,mBAAmB;AAC5E,SACEC,s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
1
|
+
import { setTimeout } from '../helper/timer';
|
|
2
|
+
import { UUID, assign } from '../helper/tools';
|
|
3
|
+
import { expandSessionState, isSessionInExpiredState, isSessionInNotStartedState } from './sessionState';
|
|
4
|
+
export var LOCK_RETRY_DELAY = 10;
|
|
5
|
+
export var LOCK_MAX_TRIES = 100;
|
|
6
|
+
var bufferedOperations = [];
|
|
7
|
+
var ongoingOperations;
|
|
8
|
+
export function processSessionStoreOperations(operations, sessionStoreStrategy) {
|
|
9
|
+
var numberOfRetries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
10
|
+
var isLockEnabled = sessionStoreStrategy.isLockEnabled,
|
|
11
|
+
persistSession = sessionStoreStrategy.persistSession,
|
|
12
|
+
expireSession = sessionStoreStrategy.expireSession;
|
|
13
|
+
var persistWithLock = function persistWithLock(session) {
|
|
14
|
+
return persistSession(assign({}, session, {
|
|
15
|
+
lock: currentLock
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
var retrieveStore = function retrieveStore() {
|
|
19
|
+
var session = sessionStoreStrategy.retrieveSession();
|
|
20
|
+
var lock = session.lock;
|
|
21
|
+
if (session.lock) {
|
|
22
|
+
delete session.lock;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
session: session,
|
|
26
|
+
lock: lock
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
if (!ongoingOperations) {
|
|
30
|
+
ongoingOperations = operations;
|
|
31
|
+
}
|
|
32
|
+
if (operations !== ongoingOperations) {
|
|
33
|
+
bufferedOperations.push(operations);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (isLockEnabled && numberOfRetries >= LOCK_MAX_TRIES) {
|
|
37
|
+
next(sessionStoreStrategy);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var currentLock;
|
|
41
|
+
var currentStore = retrieveStore();
|
|
42
|
+
if (isLockEnabled) {
|
|
43
|
+
// if someone has lock, retry later
|
|
44
|
+
if (currentStore.lock && !isSessionInNotStartedState(currentStore.session)) {
|
|
45
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// acquire lock
|
|
49
|
+
currentLock = UUID();
|
|
50
|
+
persistWithLock(currentStore.session);
|
|
51
|
+
// if lock is not acquired, retry later
|
|
52
|
+
currentStore = retrieveStore();
|
|
53
|
+
if (currentStore.lock !== currentLock && !isSessionInNotStartedState(currentStore.session)) {
|
|
54
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
var processedSession = operations.process(currentStore.session);
|
|
59
|
+
if (isLockEnabled) {
|
|
60
|
+
// if lock corrupted after process, retry later
|
|
61
|
+
currentStore = retrieveStore();
|
|
62
|
+
if (currentStore.lock !== currentLock && !isSessionInNotStartedState(currentStore.session)) {
|
|
63
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (processedSession) {
|
|
68
|
+
if (isSessionInExpiredState(processedSession)) {
|
|
69
|
+
expireSession();
|
|
70
|
+
} else {
|
|
71
|
+
expandSessionState(processedSession);
|
|
72
|
+
isLockEnabled ? persistWithLock(processedSession) : persistSession(processedSession);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (isLockEnabled) {
|
|
76
|
+
// correctly handle lock around expiration would require to handle this case properly at several levels
|
|
77
|
+
// since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it
|
|
78
|
+
if (!(processedSession && isSessionInExpiredState(processedSession))) {
|
|
79
|
+
// if lock corrupted after persist, retry later
|
|
80
|
+
currentStore = retrieveStore();
|
|
81
|
+
if (currentStore.lock !== currentLock && !isSessionInNotStartedState(currentStore.session)) {
|
|
82
|
+
retryLater(operations, sessionStoreStrategy, numberOfRetries);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
persistSession(currentStore.session);
|
|
86
|
+
processedSession = currentStore.session;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// call after even if session is not persisted in order to perform operations on
|
|
90
|
+
// up-to-date session state value => the value could have been modified by another tab
|
|
91
|
+
if (operations.after) {
|
|
92
|
+
operations.after(processedSession || currentStore.session);
|
|
93
|
+
}
|
|
94
|
+
next(sessionStoreStrategy);
|
|
95
|
+
}
|
|
96
|
+
function retryLater(operations, sessionStore, currentNumberOfRetries) {
|
|
97
|
+
setTimeout(function () {
|
|
98
|
+
processSessionStoreOperations(operations, sessionStore, currentNumberOfRetries + 1);
|
|
99
|
+
}, LOCK_RETRY_DELAY);
|
|
100
|
+
}
|
|
101
|
+
function next(sessionStore) {
|
|
102
|
+
ongoingOperations = undefined;
|
|
103
|
+
var nextOperations = bufferedOperations.shift();
|
|
104
|
+
if (nextOperations) {
|
|
105
|
+
processSessionStoreOperations(nextOperations, sessionStore);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=sessionStoreOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionStoreOperations.js","names":["setTimeout","UUID","assign","expandSessionState","isSessionInExpiredState","isSessionInNotStartedState","LOCK_RETRY_DELAY","LOCK_MAX_TRIES","bufferedOperations","ongoingOperations","processSessionStoreOperations","operations","sessionStoreStrategy","numberOfRetries","arguments","length","undefined","isLockEnabled","persistSession","expireSession","persistWithLock","session","lock","currentLock","retrieveStore","retrieveSession","push","next","currentStore","retryLater","processedSession","process","after","sessionStore","currentNumberOfRetries","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,SAASA,UAAU,QAAQ,iBAAiB;AAC5C,SAASC,IAAI,EAAEC,MAAM,QAAQ,iBAAiB;AAC9C,SACEC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,QACrB,gBAAgB;AAEvB,OAAO,IAAMC,gBAAgB,GAAG,EAAE;AAClC,OAAO,IAAMC,cAAc,GAAG,GAAG;AACjC,IAAMC,kBAAkB,GAAG,EAAE;AAC7B,IAAIC,iBAAiB;AAErB,OAAO,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,CAAChB,MAAM,CAAC,CAAC,CAAC,EAAEmB,OAAO,EAAE;MAAEC,IAAI,EAAEC;IAAY,CAAC,CAAC,CAAC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sB,YAAY,EACZC,sBAAsB,GAAG,CAC3B,CAAC;EACH,CAAC,EAAE5B,gBAAgB,CAAC;AACtB;AAEA,SAASqB,IAAIA,CAACM,YAAY,EAAE;EAC1BxB,iBAAiB,GAAGO,SAAS;EAC7B,IAAMmB,cAAc,GAAG3B,kBAAkB,CAAC4B,KAAK,CAAC,CAAC;EACjD,IAAID,cAAc,EAAE;IAClBzB,6BAA6B,CAACyB,cAAc,EAAEF,YAAY,CAAC;EAC7D;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-core",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"author": "dataflux",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "5362ac30c3a0ffc29f856417d7ae42f22ae93087"
|
|
26
26
|
}
|
package/src/browser/cookie.js
CHANGED
|
@@ -2,10 +2,17 @@ import {
|
|
|
2
2
|
findCommaSeparatedValue,
|
|
3
3
|
UUID,
|
|
4
4
|
ONE_SECOND,
|
|
5
|
+
ONE_MINUTE,
|
|
5
6
|
findCommaSeparatedValues
|
|
6
7
|
} from '../helper/tools'
|
|
7
|
-
export var COOKIE_ACCESS_DELAY = ONE_SECOND
|
|
8
8
|
|
|
9
|
+
function getCookieName(name, options) {
|
|
10
|
+
return `${name}_${options && options.crossSite ? 'cs1' : 'cs0'}_${
|
|
11
|
+
options && options.domain ? 'd1' : 'd0'
|
|
12
|
+
}_${options && options.secure ? 'sec1' : 'sec0'}_${
|
|
13
|
+
options && options.partitioned ? 'part1' : 'part0'
|
|
14
|
+
}`
|
|
15
|
+
}
|
|
9
16
|
export function setCookie(name, value, expireDelay, options) {
|
|
10
17
|
var date = new Date()
|
|
11
18
|
date.setTime(date.getTime() + expireDelay)
|
|
@@ -14,8 +21,9 @@ export function setCookie(name, value, expireDelay, options) {
|
|
|
14
21
|
var domain = options && options.domain ? ';domain=' + options.domain : ''
|
|
15
22
|
var secure = options && options.secure ? ';secure' : ''
|
|
16
23
|
var partitioned = options && options.partitioned ? ';partitioned' : ''
|
|
24
|
+
|
|
17
25
|
document.cookie =
|
|
18
|
-
name +
|
|
26
|
+
getCookieName(name, options) +
|
|
19
27
|
'=' +
|
|
20
28
|
value +
|
|
21
29
|
';' +
|
|
@@ -27,8 +35,8 @@ export function setCookie(name, value, expireDelay, options) {
|
|
|
27
35
|
partitioned
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
export function getCookie(name) {
|
|
31
|
-
return findCommaSeparatedValue(document.cookie, name)
|
|
38
|
+
export function getCookie(name, options) {
|
|
39
|
+
return findCommaSeparatedValue(document.cookie, getCookieName(name, options))
|
|
32
40
|
}
|
|
33
41
|
var initCookieParsed
|
|
34
42
|
/**
|
|
@@ -58,8 +66,11 @@ export function areCookiesAuthorized(options) {
|
|
|
58
66
|
// the test cookie lifetime
|
|
59
67
|
var testCookieName = `gc_cookie_test_${UUID()}`
|
|
60
68
|
var testCookieValue = 'test'
|
|
61
|
-
setCookie(testCookieName, testCookieValue,
|
|
62
|
-
|
|
69
|
+
setCookie(testCookieName, testCookieValue, ONE_MINUTE, options)
|
|
70
|
+
const isCookieCorrectlySet =
|
|
71
|
+
getCookie(testCookieName, options) === testCookieValue
|
|
72
|
+
deleteCookie(testCookieName, options)
|
|
73
|
+
return isCookieCorrectlySet
|
|
63
74
|
} catch (error) {
|
|
64
75
|
return false
|
|
65
76
|
}
|
|
@@ -75,17 +86,18 @@ export function getCurrentSite() {
|
|
|
75
86
|
if (getCurrentSiteCache === undefined) {
|
|
76
87
|
// Use a unique cookie name to avoid issues when the SDK is initialized multiple times during
|
|
77
88
|
// the test cookie lifetime
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
const testCookieName = `gc_site_test_${UUID()}`
|
|
90
|
+
const testCookieValue = 'test'
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
const domainLevels = window.location.hostname.split('.')
|
|
93
|
+
let candidateDomain = domainLevels.pop()
|
|
83
94
|
while (domainLevels.length && !getCookie(testCookieName)) {
|
|
84
|
-
candidateDomain = domainLevels.pop()
|
|
95
|
+
candidateDomain = `${domainLevels.pop()}.${candidateDomain}`
|
|
85
96
|
setCookie(testCookieName, testCookieValue, ONE_SECOND, {
|
|
86
97
|
domain: candidateDomain
|
|
87
98
|
})
|
|
88
99
|
}
|
|
100
|
+
deleteCookie(testCookieName, { domain: candidateDomain })
|
|
89
101
|
getCurrentSiteCache = candidateDomain
|
|
90
102
|
}
|
|
91
103
|
return getCurrentSiteCache
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getCurrentSite } from '../browser/cookie'
|
|
2
1
|
import { catchUserErrors } from '../helper/catchUserErrors'
|
|
3
2
|
import { display } from '../helper/display'
|
|
4
3
|
import {
|
|
@@ -9,7 +8,7 @@ import {
|
|
|
9
8
|
} from '../helper/tools'
|
|
10
9
|
import { ONE_KIBI_BYTE } from '../helper/byteUtils'
|
|
11
10
|
import { computeTransportConfiguration } from './transportConfiguration'
|
|
12
|
-
|
|
11
|
+
import { selectSessionStoreStrategyType } from '../session/sessionStore'
|
|
13
12
|
export var DefaultPrivacyLevel = {
|
|
14
13
|
ALLOW: 'allow',
|
|
15
14
|
MASK: 'mask',
|
|
@@ -47,7 +46,8 @@ export function validateAndBuildConfiguration(initConfiguration) {
|
|
|
47
46
|
initConfiguration.beforeSend,
|
|
48
47
|
'beforeSend threw an error:'
|
|
49
48
|
),
|
|
50
|
-
|
|
49
|
+
sessionStoreStrategyType:
|
|
50
|
+
selectSessionStoreStrategyType(initConfiguration),
|
|
51
51
|
sessionSampleRate: isNullUndefinedDefaultValue(sessionSampleRate, 100),
|
|
52
52
|
service: initConfiguration.service,
|
|
53
53
|
version: initConfiguration.version,
|
|
@@ -118,30 +118,3 @@ export function validatePostRequestRequireParamsConfiguration(
|
|
|
118
118
|
}
|
|
119
119
|
return true
|
|
120
120
|
}
|
|
121
|
-
export function buildCookieOptions(initConfiguration) {
|
|
122
|
-
var cookieOptions = {}
|
|
123
|
-
|
|
124
|
-
// cookieOptions.secure = mustUseSecureCookie(initConfiguration)
|
|
125
|
-
// cookieOptions.crossSite = !!initConfiguration.useCrossSiteSessionCookie
|
|
126
|
-
cookieOptions.secure =
|
|
127
|
-
!!initConfiguration.useSecureSessionCookie ||
|
|
128
|
-
!!initConfiguration.usePartitionedCrossSiteSessionCookie ||
|
|
129
|
-
!!initConfiguration.useCrossSiteSessionCookie
|
|
130
|
-
cookieOptions.crossSite =
|
|
131
|
-
!!initConfiguration.usePartitionedCrossSiteSessionCookie ||
|
|
132
|
-
!!initConfiguration.useCrossSiteSessionCookie
|
|
133
|
-
cookieOptions.partitioned =
|
|
134
|
-
!!initConfiguration.usePartitionedCrossSiteSessionCookie
|
|
135
|
-
if (initConfiguration.trackSessionAcrossSubdomains) {
|
|
136
|
-
cookieOptions.domain = getCurrentSite()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return cookieOptions
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// function mustUseSecureCookie(initConfiguration) {
|
|
143
|
-
// return (
|
|
144
|
-
// !!initConfiguration.useSecureSessionCookie ||
|
|
145
|
-
// !!initConfiguration.useCrossSiteSessionCookie
|
|
146
|
-
// )
|
|
147
|
-
// }
|
package/src/index.js
CHANGED
|
@@ -38,10 +38,15 @@ export * from './browser/scroll'
|
|
|
38
38
|
|
|
39
39
|
export * from './dataMap'
|
|
40
40
|
export * from './init'
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
export {
|
|
42
|
+
startSessionManager,
|
|
43
|
+
stopSessionManager
|
|
44
|
+
} from './session/sessionManagement'
|
|
45
|
+
export {
|
|
46
|
+
SESSION_TIME_OUT_DELAY,
|
|
47
|
+
SESSION_STORE_KEY
|
|
48
|
+
} from './session/sessionConstants'
|
|
49
|
+
export { STORAGE_POLL_DELAY } from './session/sessionStore'
|
|
45
50
|
export * from './transport'
|
|
46
51
|
export * from './synthetics/syntheticsWorkerValues'
|
|
47
52
|
|
package/src/init.js
CHANGED
|
@@ -60,22 +60,3 @@ export function getGlobalObject() {
|
|
|
60
60
|
}
|
|
61
61
|
return globalObject
|
|
62
62
|
}
|
|
63
|
-
// export function checkCookiesAuthorized(options) {
|
|
64
|
-
// if (!areCookiesAuthorized(options)) {
|
|
65
|
-
// console.warn('Cookies are not authorized, we will not send any data.')
|
|
66
|
-
// return false
|
|
67
|
-
// }
|
|
68
|
-
// return true
|
|
69
|
-
// }
|
|
70
|
-
|
|
71
|
-
// export function checkIsNotLocalFile() {
|
|
72
|
-
// if (isLocalFile()) {
|
|
73
|
-
// console.error('Execution is not allowed in the current context.')
|
|
74
|
-
// return false
|
|
75
|
-
// }
|
|
76
|
-
// return true
|
|
77
|
-
// }
|
|
78
|
-
|
|
79
|
-
// function isLocalFile() {
|
|
80
|
-
// return window.location.protocol === 'file:'
|
|
81
|
-
// }
|