@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
package/cjs/synthetics/usr.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.startCacheUsrCache = exports.ANONYMOUS_ID_EXPIRATION = exports.ANONYMOUS_ID_COOKIE_NAME = void 0;
|
|
7
|
-
var _cookie = require("../browser/cookie");
|
|
8
|
-
var _tools = require("../helper/tools");
|
|
9
|
-
var ANONYMOUS_ID_COOKIE_NAME = '_dataflulx_usr_id';
|
|
10
|
-
exports.ANONYMOUS_ID_COOKIE_NAME = ANONYMOUS_ID_COOKIE_NAME;
|
|
11
|
-
var ANONYMOUS_ID_EXPIRATION = 60 * 24 * _tools.ONE_HOUR;
|
|
12
|
-
exports.ANONYMOUS_ID_EXPIRATION = ANONYMOUS_ID_EXPIRATION;
|
|
13
|
-
var startCacheUsrCache = function startCacheUsrCache(configuration) {
|
|
14
|
-
var usrCacheId = (0, _cookie.getCookie)(ANONYMOUS_ID_COOKIE_NAME);
|
|
15
|
-
if (!usrCacheId) {
|
|
16
|
-
usrCacheId = (0, _tools.UUID)();
|
|
17
|
-
(0, _cookie.setCookie)(ANONYMOUS_ID_COOKIE_NAME, usrCacheId, ANONYMOUS_ID_EXPIRATION, configuration.cookieOptions);
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
getUsrId: function getUsrId() {
|
|
21
|
-
return usrCacheId;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
exports.startCacheUsrCache = startCacheUsrCache;
|
|
26
|
-
//# sourceMappingURL=usr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usr.js","names":["_cookie","require","_tools","ANONYMOUS_ID_COOKIE_NAME","exports","ANONYMOUS_ID_EXPIRATION","ONE_HOUR","startCacheUsrCache","configuration","usrCacheId","getCookie","UUID","setCookie","cookieOptions","getUsrId"],"sources":["../../src/synthetics/usr.js"],"sourcesContent":["import { getCookie, setCookie } from '../browser/cookie'\nimport { ONE_HOUR, UUID } from '../helper/tools'\n\nexport var ANONYMOUS_ID_COOKIE_NAME = '_dataflulx_usr_id'\nexport var ANONYMOUS_ID_EXPIRATION = 60 * 24 * ONE_HOUR\n\nexport var startCacheUsrCache = function(configuration) {\n var usrCacheId = getCookie(ANONYMOUS_ID_COOKIE_NAME)\n if (!usrCacheId) {\n usrCacheId = UUID()\n setCookie(ANONYMOUS_ID_COOKIE_NAME, usrCacheId, ANONYMOUS_ID_EXPIRATION, configuration.cookieOptions)\n }\n return {\n getUsrId: function() {\n return usrCacheId\n }\n }\n}"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEO,IAAIE,wBAAwB,GAAG,mBAAmB;AAAAC,OAAA,CAAAD,wBAAA,GAAAA,wBAAA;AAClD,IAAIE,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAGC,eAAQ;AAAAF,OAAA,CAAAC,uBAAA,GAAAA,uBAAA;AAEhD,IAAIE,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAYC,aAAa,EAAE;EACtD,IAAIC,UAAU,GAAG,IAAAC,iBAAS,EAACP,wBAAwB,CAAC;EACpD,IAAI,CAACM,UAAU,EAAE;IACfA,UAAU,GAAG,IAAAE,WAAI,EAAC,CAAC;IACnB,IAAAC,iBAAS,EAACT,wBAAwB,EAAEM,UAAU,EAAEJ,uBAAuB,EAAEG,aAAa,CAACK,aAAa,CAAC;EACvG;EACA,OAAO;IACLC,QAAQ,EAAE,SAAAA,SAAA,EAAW;MACnB,OAAOL,UAAU;IACnB;EACF,CAAC;AACH,CAAC;AAAAL,OAAA,CAAAG,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { getCookie, setCookie } from '../browser/cookie';
|
|
2
|
-
import { isChromium, dateNow, isEmptyObject, UUID, objectEntries, map, each } from '../helper/tools';
|
|
3
|
-
import { SESSION_EXPIRATION_DELAY } from './sessionConstants';
|
|
4
|
-
import { setTimeout } from '../helper/timer';
|
|
5
|
-
var SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/;
|
|
6
|
-
var SESSION_ENTRY_SEPARATOR = '&';
|
|
7
|
-
export var SESSION_COOKIE_NAME = '_dataflux_s';
|
|
8
|
-
|
|
9
|
-
// arbitrary values
|
|
10
|
-
export var LOCK_RETRY_DELAY = 10;
|
|
11
|
-
export var MAX_NUMBER_OF_LOCK_RETRIES = 100;
|
|
12
|
-
var bufferedOperations = [];
|
|
13
|
-
var ongoingOperations;
|
|
14
|
-
export function withCookieLockAccess(operations, numberOfRetries) {
|
|
15
|
-
if (typeof numberOfRetries === 'undefined') {
|
|
16
|
-
numberOfRetries = 0;
|
|
17
|
-
}
|
|
18
|
-
if (!ongoingOperations) {
|
|
19
|
-
ongoingOperations = operations;
|
|
20
|
-
}
|
|
21
|
-
if (operations !== ongoingOperations) {
|
|
22
|
-
bufferedOperations.push(operations);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (numberOfRetries >= MAX_NUMBER_OF_LOCK_RETRIES) {
|
|
26
|
-
next();
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
var currentLock;
|
|
30
|
-
var currentSession = retrieveSession();
|
|
31
|
-
if (isCookieLockEnabled()) {
|
|
32
|
-
// if someone has lock, retry later
|
|
33
|
-
if (currentSession.lock) {
|
|
34
|
-
retryLater(operations, numberOfRetries);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// acquire lock
|
|
38
|
-
currentLock = UUID();
|
|
39
|
-
currentSession.lock = currentLock;
|
|
40
|
-
setSession(currentSession, operations.options);
|
|
41
|
-
// if lock is not acquired, retry later
|
|
42
|
-
currentSession = retrieveSession();
|
|
43
|
-
if (currentSession.lock !== currentLock) {
|
|
44
|
-
retryLater(operations, numberOfRetries);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
var processedSession = operations.process(currentSession);
|
|
49
|
-
if (isCookieLockEnabled()) {
|
|
50
|
-
// if lock corrupted after process, retry later
|
|
51
|
-
currentSession = retrieveSession();
|
|
52
|
-
if (currentSession.lock !== currentLock) {
|
|
53
|
-
retryLater(operations, numberOfRetries);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (processedSession) {
|
|
58
|
-
persistSession(processedSession, operations.options);
|
|
59
|
-
}
|
|
60
|
-
if (isCookieLockEnabled()) {
|
|
61
|
-
// correctly handle lock around expiration would require to handle this case properly at several levels
|
|
62
|
-
// since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it
|
|
63
|
-
if (!(processedSession && isExpiredState(processedSession))) {
|
|
64
|
-
// if lock corrupted after persist, retry later
|
|
65
|
-
currentSession = retrieveSession();
|
|
66
|
-
if (currentSession.lock !== currentLock) {
|
|
67
|
-
retryLater(operations, numberOfRetries);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
delete currentSession.lock;
|
|
71
|
-
setSession(currentSession, operations.options);
|
|
72
|
-
processedSession = currentSession;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// call after even if session is not persisted in order to perform operations on
|
|
76
|
-
// up-to-date cookie value, the value could have been modified by another tab
|
|
77
|
-
if (operations.after) {
|
|
78
|
-
operations.after(processedSession || currentSession);
|
|
79
|
-
}
|
|
80
|
-
next();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Cookie lock strategy allows mitigating issues due to concurrent access to cookie.
|
|
85
|
-
* This issue concerns only chromium browsers and enabling this on firefox increase cookie write failures.
|
|
86
|
-
*/
|
|
87
|
-
function isCookieLockEnabled() {
|
|
88
|
-
return isChromium();
|
|
89
|
-
}
|
|
90
|
-
function retryLater(operations, currentNumberOfRetries) {
|
|
91
|
-
setTimeout(function () {
|
|
92
|
-
withCookieLockAccess(operations, currentNumberOfRetries + 1);
|
|
93
|
-
}, LOCK_RETRY_DELAY);
|
|
94
|
-
}
|
|
95
|
-
function next() {
|
|
96
|
-
ongoingOperations = undefined;
|
|
97
|
-
var nextOperations = bufferedOperations.shift();
|
|
98
|
-
if (nextOperations) {
|
|
99
|
-
withCookieLockAccess(nextOperations);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export function persistSession(session, options) {
|
|
103
|
-
if (isExpiredState(session)) {
|
|
104
|
-
clearSession(options);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
session.expire = String(dateNow() + SESSION_EXPIRATION_DELAY);
|
|
108
|
-
setSession(session, options);
|
|
109
|
-
}
|
|
110
|
-
function setSession(session, options) {
|
|
111
|
-
setCookie(SESSION_COOKIE_NAME, toSessionString(session), SESSION_EXPIRATION_DELAY, options);
|
|
112
|
-
}
|
|
113
|
-
export function toSessionString(session) {
|
|
114
|
-
return map(objectEntries(session), function (item) {
|
|
115
|
-
return item[0] + '=' + item[1];
|
|
116
|
-
}).join(SESSION_ENTRY_SEPARATOR);
|
|
117
|
-
}
|
|
118
|
-
export function retrieveSession() {
|
|
119
|
-
var sessionString = getCookie(SESSION_COOKIE_NAME);
|
|
120
|
-
var session = {};
|
|
121
|
-
if (isValidSessionString(sessionString)) {
|
|
122
|
-
each(sessionString.split(SESSION_ENTRY_SEPARATOR), function (entry) {
|
|
123
|
-
var matches = SESSION_ENTRY_REGEXP.exec(entry);
|
|
124
|
-
if (matches !== null) {
|
|
125
|
-
var key = matches[1];
|
|
126
|
-
var value = matches[2];
|
|
127
|
-
session[key] = value;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return session;
|
|
132
|
-
}
|
|
133
|
-
function isValidSessionString(sessionString) {
|
|
134
|
-
return sessionString !== undefined && (sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 || SESSION_ENTRY_REGEXP.test(sessionString));
|
|
135
|
-
}
|
|
136
|
-
function isExpiredState(session) {
|
|
137
|
-
return isEmptyObject(session);
|
|
138
|
-
}
|
|
139
|
-
export function clearSession(options) {
|
|
140
|
-
setCookie(SESSION_COOKIE_NAME, '', 0, options);
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=sessionCookieStore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sessionCookieStore.js","names":["getCookie","setCookie","isChromium","dateNow","isEmptyObject","UUID","objectEntries","map","each","SESSION_EXPIRATION_DELAY","setTimeout","SESSION_ENTRY_REGEXP","SESSION_ENTRY_SEPARATOR","SESSION_COOKIE_NAME","LOCK_RETRY_DELAY","MAX_NUMBER_OF_LOCK_RETRIES","bufferedOperations","ongoingOperations","withCookieLockAccess","operations","numberOfRetries","push","next","currentLock","currentSession","retrieveSession","isCookieLockEnabled","lock","retryLater","setSession","options","processedSession","process","persistSession","isExpiredState","after","currentNumberOfRetries","undefined","nextOperations","shift","session","clearSession","expire","String","toSessionString","item","join","sessionString","isValidSessionString","split","entry","matches","exec","key","value","indexOf","test"],"sources":["../../src/session/sessionCookieStore.js"],"sourcesContent":["import { getCookie, setCookie } from '../browser/cookie'\nimport {\n isChromium,\n dateNow,\n isEmptyObject,\n UUID,\n objectEntries,\n map,\n each\n} from '../helper/tools'\nimport { SESSION_EXPIRATION_DELAY } from './sessionConstants'\nimport { setTimeout } from '../helper/timer'\nvar SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/\nvar SESSION_ENTRY_SEPARATOR = '&'\n\nexport var SESSION_COOKIE_NAME = '_dataflux_s'\n\n// arbitrary values\nexport var LOCK_RETRY_DELAY = 10\nexport var MAX_NUMBER_OF_LOCK_RETRIES = 100\n\nvar bufferedOperations = []\nvar ongoingOperations\n\nexport function withCookieLockAccess(operations, numberOfRetries) {\n if (typeof numberOfRetries === 'undefined') {\n numberOfRetries = 0\n }\n if (!ongoingOperations) {\n ongoingOperations = operations\n }\n if (operations !== ongoingOperations) {\n bufferedOperations.push(operations)\n return\n }\n if (numberOfRetries >= MAX_NUMBER_OF_LOCK_RETRIES) {\n next()\n return\n }\n var currentLock\n var currentSession = retrieveSession()\n if (isCookieLockEnabled()) {\n // if someone has lock, retry later\n if (currentSession.lock) {\n retryLater(operations, numberOfRetries)\n return\n }\n // acquire lock\n currentLock = UUID()\n currentSession.lock = currentLock\n setSession(currentSession, operations.options)\n // if lock is not acquired, retry later\n currentSession = retrieveSession()\n if (currentSession.lock !== currentLock) {\n retryLater(operations, numberOfRetries)\n return\n }\n }\n var processedSession = operations.process(currentSession)\n if (isCookieLockEnabled()) {\n // if lock corrupted after process, retry later\n currentSession = retrieveSession()\n if (currentSession.lock !== currentLock) {\n retryLater(operations, numberOfRetries)\n return\n }\n }\n if (processedSession) {\n persistSession(processedSession, operations.options)\n }\n if (isCookieLockEnabled()) {\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 && isExpiredState(processedSession))) {\n // if lock corrupted after persist, retry later\n currentSession = retrieveSession()\n if (currentSession.lock !== currentLock) {\n retryLater(operations, numberOfRetries)\n return\n }\n delete currentSession.lock\n setSession(currentSession, operations.options)\n processedSession = currentSession\n }\n }\n // call after even if session is not persisted in order to perform operations on\n // up-to-date cookie value, the value could have been modified by another tab\n if (operations.after) {\n operations.after(processedSession || currentSession)\n }\n next()\n}\n\n/**\n * Cookie lock strategy allows mitigating issues due to concurrent access to cookie.\n * This issue concerns only chromium browsers and enabling this on firefox increase cookie write failures.\n */\nfunction isCookieLockEnabled() {\n return isChromium()\n}\n\nfunction retryLater(operations, currentNumberOfRetries) {\n setTimeout(function () {\n withCookieLockAccess(operations, currentNumberOfRetries + 1)\n }, LOCK_RETRY_DELAY)\n}\n\nfunction next() {\n ongoingOperations = undefined\n var nextOperations = bufferedOperations.shift()\n if (nextOperations) {\n withCookieLockAccess(nextOperations)\n }\n}\n\nexport function persistSession(session, options) {\n if (isExpiredState(session)) {\n clearSession(options)\n return\n }\n session.expire = String(dateNow() + SESSION_EXPIRATION_DELAY)\n setSession(session, options)\n}\n\nfunction setSession(session, options) {\n setCookie(\n SESSION_COOKIE_NAME,\n toSessionString(session),\n SESSION_EXPIRATION_DELAY,\n options\n )\n}\n\nexport function toSessionString(session) {\n return map(objectEntries(session), function (item) {\n return item[0] + '=' + item[1]\n }).join(SESSION_ENTRY_SEPARATOR)\n}\n\nexport function retrieveSession() {\n var sessionString = getCookie(SESSION_COOKIE_NAME)\n var session = {}\n if (isValidSessionString(sessionString)) {\n each(sessionString.split(SESSION_ENTRY_SEPARATOR), function (entry) {\n var matches = SESSION_ENTRY_REGEXP.exec(entry)\n if (matches !== null) {\n var key = matches[1]\n var value = matches[2]\n session[key] = value\n }\n })\n }\n return session\n}\n\nfunction isValidSessionString(sessionString) {\n return (\n sessionString !== undefined &&\n (sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 ||\n SESSION_ENTRY_REGEXP.test(sessionString))\n )\n}\n\nfunction isExpiredState(session) {\n return isEmptyObject(session)\n}\nexport function clearSession(options) {\n setCookie(SESSION_COOKIE_NAME, '', 0, options)\n}\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,SAAS,QAAQ,mBAAmB;AACxD,SACEC,UAAU,EACVC,OAAO,EACPC,aAAa,EACbC,IAAI,EACJC,aAAa,EACbC,GAAG,EACHC,IAAI,QACC,iBAAiB;AACxB,SAASC,wBAAwB,QAAQ,oBAAoB;AAC7D,SAASC,UAAU,QAAQ,iBAAiB;AAC5C,IAAIC,oBAAoB,GAAG,yBAAyB;AACpD,IAAIC,uBAAuB,GAAG,GAAG;AAEjC,OAAO,IAAIC,mBAAmB,GAAG,aAAa;;AAE9C;AACA,OAAO,IAAIC,gBAAgB,GAAG,EAAE;AAChC,OAAO,IAAIC,0BAA0B,GAAG,GAAG;AAE3C,IAAIC,kBAAkB,GAAG,EAAE;AAC3B,IAAIC,iBAAiB;AAErB,OAAO,SAASC,oBAAoBA,CAACC,UAAU,EAAEC,eAAe,EAAE;EAChE,IAAI,OAAOA,eAAe,KAAK,WAAW,EAAE;IAC1CA,eAAe,GAAG,CAAC;EACrB;EACA,IAAI,CAACH,iBAAiB,EAAE;IACtBA,iBAAiB,GAAGE,UAAU;EAChC;EACA,IAAIA,UAAU,KAAKF,iBAAiB,EAAE;IACpCD,kBAAkB,CAACK,IAAI,CAACF,UAAU,CAAC;IACnC;EACF;EACA,IAAIC,eAAe,IAAIL,0BAA0B,EAAE;IACjDO,IAAI,CAAC,CAAC;IACN;EACF;EACA,IAAIC,WAAW;EACf,IAAIC,cAAc,GAAGC,eAAe,CAAC,CAAC;EACtC,IAAIC,mBAAmB,CAAC,CAAC,EAAE;IACzB;IACA,IAAIF,cAAc,CAACG,IAAI,EAAE;MACvBC,UAAU,CAACT,UAAU,EAAEC,eAAe,CAAC;MACvC;IACF;IACA;IACAG,WAAW,GAAGlB,IA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,CAAC;EAChB,IAAIQ,oBAAoB,CAACD,aAAa,CAAC,EAAE;IACvCvC,IAAI,CAACuC,aAAa,CAACE,KAAK,CAACrC,uBAAuB,CAAC,EAAE,UAAUsC,KAAK,EAAE;MAClE,IAAIC,OAAO,GAAGxC,oBAAoB,CAACyC,IAAI,CAACF,KAAK,CAAC;MAC9C,IAAIC,OAAO,KAAK,IAAI,EAAE;QACpB,IAAIE,GAAG,GAAGF,OAAO,CAAC,CAAC,CAAC;QACpB,IAAIG,KAAK,GAAGH,OAAO,CAAC,CAAC,CAAC;QACtBX,OAAO,CAACa,GAAG,CAAC,GAAGC,KAAK;MACtB;IACF,CAAC,CAAC;EACJ;EACA,OAAOd,OAAO;AAChB;AAEA,SAASQ,oBAAoBA,CAACD,aAAa,EAAE;EAC3C,OACEA,aAAa,KAAKV,SAAS,KAC1BU,aAAa,CAACQ,OAAO,CAAC3C,uBAAuB,CAAC,KAAK,CAAC,CAAC,IACpDD,oBAAoB,CAAC6C,IAAI,CAACT,aAAa,CAAC,CAAC;AAE/C;AAEA,SAASb,cAAcA,CAACM,OAAO,EAAE;EAC/B,OAAOpC,aAAa,CAACoC,OAAO,CAAC;AAC/B;AACA,OAAO,SAASC,YAAYA,CAACX,OAAO,EAAE;EACpC7B,SAAS,CAACY,mBAAmB,EAAE,EAAE,EAAE,CAAC,EAAEiB,OAAO,CAAC;AAChD","ignoreList":[]}
|
package/esm/synthetics/usr.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getCookie, setCookie } from '../browser/cookie';
|
|
2
|
-
import { ONE_HOUR, UUID } from '../helper/tools';
|
|
3
|
-
export var ANONYMOUS_ID_COOKIE_NAME = '_dataflulx_usr_id';
|
|
4
|
-
export var ANONYMOUS_ID_EXPIRATION = 60 * 24 * ONE_HOUR;
|
|
5
|
-
export var startCacheUsrCache = function startCacheUsrCache(configuration) {
|
|
6
|
-
var usrCacheId = getCookie(ANONYMOUS_ID_COOKIE_NAME);
|
|
7
|
-
if (!usrCacheId) {
|
|
8
|
-
usrCacheId = UUID();
|
|
9
|
-
setCookie(ANONYMOUS_ID_COOKIE_NAME, usrCacheId, ANONYMOUS_ID_EXPIRATION, configuration.cookieOptions);
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
getUsrId: function getUsrId() {
|
|
13
|
-
return usrCacheId;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=usr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usr.js","names":["getCookie","setCookie","ONE_HOUR","UUID","ANONYMOUS_ID_COOKIE_NAME","ANONYMOUS_ID_EXPIRATION","startCacheUsrCache","configuration","usrCacheId","cookieOptions","getUsrId"],"sources":["../../src/synthetics/usr.js"],"sourcesContent":["import { getCookie, setCookie } from '../browser/cookie'\nimport { ONE_HOUR, UUID } from '../helper/tools'\n\nexport var ANONYMOUS_ID_COOKIE_NAME = '_dataflulx_usr_id'\nexport var ANONYMOUS_ID_EXPIRATION = 60 * 24 * ONE_HOUR\n\nexport var startCacheUsrCache = function(configuration) {\n var usrCacheId = getCookie(ANONYMOUS_ID_COOKIE_NAME)\n if (!usrCacheId) {\n usrCacheId = UUID()\n setCookie(ANONYMOUS_ID_COOKIE_NAME, usrCacheId, ANONYMOUS_ID_EXPIRATION, configuration.cookieOptions)\n }\n return {\n getUsrId: function() {\n return usrCacheId\n }\n }\n}"],"mappings":"AAAA,SAASA,SAAS,EAAEC,SAAS,QAAQ,mBAAmB;AACxD,SAASC,QAAQ,EAAEC,IAAI,QAAQ,iBAAiB;AAEhD,OAAO,IAAIC,wBAAwB,GAAG,mBAAmB;AACzD,OAAO,IAAIC,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAGH,QAAQ;AAEvD,OAAO,IAAII,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAYC,aAAa,EAAE;EACtD,IAAIC,UAAU,GAAGR,SAAS,CAACI,wBAAwB,CAAC;EACpD,IAAI,CAACI,UAAU,EAAE;IACfA,UAAU,GAAGL,IAAI,CAAC,CAAC;IACnBF,SAAS,CAACG,wBAAwB,EAAEI,UAAU,EAAEH,uBAAuB,EAAEE,aAAa,CAACE,aAAa,CAAC;EACvG;EACA,OAAO;IACLC,QAAQ,EAAE,SAAAA,SAAA,EAAW;MACnB,OAAOF,UAAU;IACnB;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { getCookie, setCookie } from '../browser/cookie'
|
|
2
|
-
import {
|
|
3
|
-
isChromium,
|
|
4
|
-
dateNow,
|
|
5
|
-
isEmptyObject,
|
|
6
|
-
UUID,
|
|
7
|
-
objectEntries,
|
|
8
|
-
map,
|
|
9
|
-
each
|
|
10
|
-
} from '../helper/tools'
|
|
11
|
-
import { SESSION_EXPIRATION_DELAY } from './sessionConstants'
|
|
12
|
-
import { setTimeout } from '../helper/timer'
|
|
13
|
-
var SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/
|
|
14
|
-
var SESSION_ENTRY_SEPARATOR = '&'
|
|
15
|
-
|
|
16
|
-
export var SESSION_COOKIE_NAME = '_dataflux_s'
|
|
17
|
-
|
|
18
|
-
// arbitrary values
|
|
19
|
-
export var LOCK_RETRY_DELAY = 10
|
|
20
|
-
export var MAX_NUMBER_OF_LOCK_RETRIES = 100
|
|
21
|
-
|
|
22
|
-
var bufferedOperations = []
|
|
23
|
-
var ongoingOperations
|
|
24
|
-
|
|
25
|
-
export function withCookieLockAccess(operations, numberOfRetries) {
|
|
26
|
-
if (typeof numberOfRetries === 'undefined') {
|
|
27
|
-
numberOfRetries = 0
|
|
28
|
-
}
|
|
29
|
-
if (!ongoingOperations) {
|
|
30
|
-
ongoingOperations = operations
|
|
31
|
-
}
|
|
32
|
-
if (operations !== ongoingOperations) {
|
|
33
|
-
bufferedOperations.push(operations)
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
if (numberOfRetries >= MAX_NUMBER_OF_LOCK_RETRIES) {
|
|
37
|
-
next()
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
var currentLock
|
|
41
|
-
var currentSession = retrieveSession()
|
|
42
|
-
if (isCookieLockEnabled()) {
|
|
43
|
-
// if someone has lock, retry later
|
|
44
|
-
if (currentSession.lock) {
|
|
45
|
-
retryLater(operations, numberOfRetries)
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
// acquire lock
|
|
49
|
-
currentLock = UUID()
|
|
50
|
-
currentSession.lock = currentLock
|
|
51
|
-
setSession(currentSession, operations.options)
|
|
52
|
-
// if lock is not acquired, retry later
|
|
53
|
-
currentSession = retrieveSession()
|
|
54
|
-
if (currentSession.lock !== currentLock) {
|
|
55
|
-
retryLater(operations, numberOfRetries)
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
var processedSession = operations.process(currentSession)
|
|
60
|
-
if (isCookieLockEnabled()) {
|
|
61
|
-
// if lock corrupted after process, retry later
|
|
62
|
-
currentSession = retrieveSession()
|
|
63
|
-
if (currentSession.lock !== currentLock) {
|
|
64
|
-
retryLater(operations, numberOfRetries)
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (processedSession) {
|
|
69
|
-
persistSession(processedSession, operations.options)
|
|
70
|
-
}
|
|
71
|
-
if (isCookieLockEnabled()) {
|
|
72
|
-
// correctly handle lock around expiration would require to handle this case properly at several levels
|
|
73
|
-
// since we don't have evidence of lock issues around expiration, let's just not do the corruption check for it
|
|
74
|
-
if (!(processedSession && isExpiredState(processedSession))) {
|
|
75
|
-
// if lock corrupted after persist, retry later
|
|
76
|
-
currentSession = retrieveSession()
|
|
77
|
-
if (currentSession.lock !== currentLock) {
|
|
78
|
-
retryLater(operations, numberOfRetries)
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
delete currentSession.lock
|
|
82
|
-
setSession(currentSession, operations.options)
|
|
83
|
-
processedSession = currentSession
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// call after even if session is not persisted in order to perform operations on
|
|
87
|
-
// up-to-date cookie value, the value could have been modified by another tab
|
|
88
|
-
if (operations.after) {
|
|
89
|
-
operations.after(processedSession || currentSession)
|
|
90
|
-
}
|
|
91
|
-
next()
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Cookie lock strategy allows mitigating issues due to concurrent access to cookie.
|
|
96
|
-
* This issue concerns only chromium browsers and enabling this on firefox increase cookie write failures.
|
|
97
|
-
*/
|
|
98
|
-
function isCookieLockEnabled() {
|
|
99
|
-
return isChromium()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function retryLater(operations, currentNumberOfRetries) {
|
|
103
|
-
setTimeout(function () {
|
|
104
|
-
withCookieLockAccess(operations, currentNumberOfRetries + 1)
|
|
105
|
-
}, LOCK_RETRY_DELAY)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function next() {
|
|
109
|
-
ongoingOperations = undefined
|
|
110
|
-
var nextOperations = bufferedOperations.shift()
|
|
111
|
-
if (nextOperations) {
|
|
112
|
-
withCookieLockAccess(nextOperations)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function persistSession(session, options) {
|
|
117
|
-
if (isExpiredState(session)) {
|
|
118
|
-
clearSession(options)
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
session.expire = String(dateNow() + SESSION_EXPIRATION_DELAY)
|
|
122
|
-
setSession(session, options)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function setSession(session, options) {
|
|
126
|
-
setCookie(
|
|
127
|
-
SESSION_COOKIE_NAME,
|
|
128
|
-
toSessionString(session),
|
|
129
|
-
SESSION_EXPIRATION_DELAY,
|
|
130
|
-
options
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function toSessionString(session) {
|
|
135
|
-
return map(objectEntries(session), function (item) {
|
|
136
|
-
return item[0] + '=' + item[1]
|
|
137
|
-
}).join(SESSION_ENTRY_SEPARATOR)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function retrieveSession() {
|
|
141
|
-
var sessionString = getCookie(SESSION_COOKIE_NAME)
|
|
142
|
-
var session = {}
|
|
143
|
-
if (isValidSessionString(sessionString)) {
|
|
144
|
-
each(sessionString.split(SESSION_ENTRY_SEPARATOR), function (entry) {
|
|
145
|
-
var matches = SESSION_ENTRY_REGEXP.exec(entry)
|
|
146
|
-
if (matches !== null) {
|
|
147
|
-
var key = matches[1]
|
|
148
|
-
var value = matches[2]
|
|
149
|
-
session[key] = value
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
return session
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function isValidSessionString(sessionString) {
|
|
157
|
-
return (
|
|
158
|
-
sessionString !== undefined &&
|
|
159
|
-
(sessionString.indexOf(SESSION_ENTRY_SEPARATOR) !== -1 ||
|
|
160
|
-
SESSION_ENTRY_REGEXP.test(sessionString))
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function isExpiredState(session) {
|
|
165
|
-
return isEmptyObject(session)
|
|
166
|
-
}
|
|
167
|
-
export function clearSession(options) {
|
|
168
|
-
setCookie(SESSION_COOKIE_NAME, '', 0, options)
|
|
169
|
-
}
|
package/src/synthetics/usr.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { getCookie, setCookie } from '../browser/cookie'
|
|
2
|
-
import { ONE_HOUR, UUID } from '../helper/tools'
|
|
3
|
-
|
|
4
|
-
export var ANONYMOUS_ID_COOKIE_NAME = '_dataflulx_usr_id'
|
|
5
|
-
export var ANONYMOUS_ID_EXPIRATION = 60 * 24 * ONE_HOUR
|
|
6
|
-
|
|
7
|
-
export var startCacheUsrCache = function(configuration) {
|
|
8
|
-
var usrCacheId = getCookie(ANONYMOUS_ID_COOKIE_NAME)
|
|
9
|
-
if (!usrCacheId) {
|
|
10
|
-
usrCacheId = UUID()
|
|
11
|
-
setCookie(ANONYMOUS_ID_COOKIE_NAME, usrCacheId, ANONYMOUS_ID_EXPIRATION, configuration.cookieOptions)
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
getUsrId: function() {
|
|
15
|
-
return usrCacheId
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|