@datadog/browser-core
Advanced tools
Comparing version 1.9.4 to 1.10.0
@@ -24,6 +24,6 @@ import { CookieCache } from './cookie'; | ||
isTracked: boolean; | ||
}, withNewSessionStrategy?: boolean): Session<Type>; | ||
}): Session<Type>; | ||
export declare function isValidSessionString(sessionString: string | undefined): sessionString is string; | ||
export declare function persistSession(session: SessionState, cookie: CookieCache, withNewSessionStrategy?: boolean): void; | ||
export declare function persistSession(session: SessionState, cookie: CookieCache): void; | ||
export declare function stopSessionManagement(): void; | ||
export declare function trackActivity(expandOrRenewSession: () => void): void; |
@@ -16,10 +16,9 @@ "use strict"; | ||
*/ | ||
function startSessionManagement(sessionTypeKey, computeSessionState, withNewSessionStrategy) { | ||
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; } | ||
function startSessionManagement(sessionTypeKey, computeSessionState) { | ||
var sessionCookie = cookie_1.cacheCookieAccess(exports.SESSION_COOKIE_NAME); | ||
oldCookiesMigration_1.tryOldCookiesMigration(sessionCookie); | ||
var renewObservable = new observable_1.Observable(); | ||
var currentSessionId = retrieveActiveSession(sessionCookie, withNewSessionStrategy).id; | ||
var currentSessionId = retrieveActiveSession(sessionCookie).id; | ||
var expandOrRenewSession = utils.throttle(function () { | ||
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy); | ||
var session = retrieveActiveSession(sessionCookie); | ||
var _a = computeSessionState(session[sessionTypeKey]), type = _a.type, isTracked = _a.isTracked; | ||
@@ -29,8 +28,6 @@ session[sessionTypeKey] = type; | ||
session.id = utils.generateUUID(); | ||
if (withNewSessionStrategy) { | ||
session.created = String(Date.now()); | ||
} | ||
session.created = String(Date.now()); | ||
} | ||
// save changes and expand session duration | ||
persistSession(session, sessionCookie, withNewSessionStrategy); | ||
persistSession(session, sessionCookie); | ||
// If the session id has changed, notify that the session has been renewed | ||
@@ -43,16 +40,14 @@ if (isTracked && currentSessionId !== session.id) { | ||
var expandSession = function () { | ||
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy); | ||
persistSession(session, sessionCookie, withNewSessionStrategy); | ||
var session = retrieveActiveSession(sessionCookie); | ||
persistSession(session, sessionCookie); | ||
}; | ||
expandOrRenewSession(); | ||
trackActivity(expandOrRenewSession); | ||
if (withNewSessionStrategy) { | ||
trackVisibility(expandSession); | ||
} | ||
trackVisibility(expandSession); | ||
return { | ||
getId: function () { | ||
return retrieveActiveSession(sessionCookie, withNewSessionStrategy).id; | ||
return retrieveActiveSession(sessionCookie).id; | ||
}, | ||
getType: function () { | ||
return retrieveActiveSession(sessionCookie, withNewSessionStrategy)[sessionTypeKey]; | ||
return retrieveActiveSession(sessionCookie)[sessionTypeKey]; | ||
}, | ||
@@ -70,5 +65,5 @@ renewObservable: renewObservable, | ||
exports.isValidSessionString = isValidSessionString; | ||
function retrieveActiveSession(sessionCookie, withNewSessionStrategy) { | ||
function retrieveActiveSession(sessionCookie) { | ||
var session = retrieveSession(sessionCookie); | ||
if (!withNewSessionStrategy || isActiveSession(session)) { | ||
if (isActiveSession(session)) { | ||
return session; | ||
@@ -99,4 +94,3 @@ } | ||
} | ||
function persistSession(session, cookie, withNewSessionStrategy) { | ||
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; } | ||
function persistSession(session, cookie) { | ||
if (utils.isEmptyObject(session)) { | ||
@@ -106,5 +100,3 @@ clearSession(cookie); | ||
} | ||
if (withNewSessionStrategy) { | ||
session.expire = String(Date.now() + exports.SESSION_EXPIRATION_DELAY); | ||
} | ||
session.expire = String(Date.now() + exports.SESSION_EXPIRATION_DELAY); | ||
var cookieString = utils | ||
@@ -111,0 +103,0 @@ .objectEntries(session) |
@@ -24,6 +24,6 @@ import { CookieCache } from './cookie'; | ||
isTracked: boolean; | ||
}, withNewSessionStrategy?: boolean): Session<Type>; | ||
}): Session<Type>; | ||
export declare function isValidSessionString(sessionString: string | undefined): sessionString is string; | ||
export declare function persistSession(session: SessionState, cookie: CookieCache, withNewSessionStrategy?: boolean): void; | ||
export declare function persistSession(session: SessionState, cookie: CookieCache): void; | ||
export declare function stopSessionManagement(): void; | ||
export declare function trackActivity(expandOrRenewSession: () => void): void; |
@@ -13,10 +13,9 @@ import { cacheCookieAccess, COOKIE_ACCESS_DELAY } from './cookie'; | ||
*/ | ||
export function startSessionManagement(sessionTypeKey, computeSessionState, withNewSessionStrategy) { | ||
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; } | ||
export function startSessionManagement(sessionTypeKey, computeSessionState) { | ||
var sessionCookie = cacheCookieAccess(SESSION_COOKIE_NAME); | ||
tryOldCookiesMigration(sessionCookie); | ||
var renewObservable = new Observable(); | ||
var currentSessionId = retrieveActiveSession(sessionCookie, withNewSessionStrategy).id; | ||
var currentSessionId = retrieveActiveSession(sessionCookie).id; | ||
var expandOrRenewSession = utils.throttle(function () { | ||
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy); | ||
var session = retrieveActiveSession(sessionCookie); | ||
var _a = computeSessionState(session[sessionTypeKey]), type = _a.type, isTracked = _a.isTracked; | ||
@@ -26,8 +25,6 @@ session[sessionTypeKey] = type; | ||
session.id = utils.generateUUID(); | ||
if (withNewSessionStrategy) { | ||
session.created = String(Date.now()); | ||
} | ||
session.created = String(Date.now()); | ||
} | ||
// save changes and expand session duration | ||
persistSession(session, sessionCookie, withNewSessionStrategy); | ||
persistSession(session, sessionCookie); | ||
// If the session id has changed, notify that the session has been renewed | ||
@@ -40,16 +37,14 @@ if (isTracked && currentSessionId !== session.id) { | ||
var expandSession = function () { | ||
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy); | ||
persistSession(session, sessionCookie, withNewSessionStrategy); | ||
var session = retrieveActiveSession(sessionCookie); | ||
persistSession(session, sessionCookie); | ||
}; | ||
expandOrRenewSession(); | ||
trackActivity(expandOrRenewSession); | ||
if (withNewSessionStrategy) { | ||
trackVisibility(expandSession); | ||
} | ||
trackVisibility(expandSession); | ||
return { | ||
getId: function () { | ||
return retrieveActiveSession(sessionCookie, withNewSessionStrategy).id; | ||
return retrieveActiveSession(sessionCookie).id; | ||
}, | ||
getType: function () { | ||
return retrieveActiveSession(sessionCookie, withNewSessionStrategy)[sessionTypeKey]; | ||
return retrieveActiveSession(sessionCookie)[sessionTypeKey]; | ||
}, | ||
@@ -65,5 +60,5 @@ renewObservable: renewObservable, | ||
} | ||
function retrieveActiveSession(sessionCookie, withNewSessionStrategy) { | ||
function retrieveActiveSession(sessionCookie) { | ||
var session = retrieveSession(sessionCookie); | ||
if (!withNewSessionStrategy || isActiveSession(session)) { | ||
if (isActiveSession(session)) { | ||
return session; | ||
@@ -94,4 +89,3 @@ } | ||
} | ||
export function persistSession(session, cookie, withNewSessionStrategy) { | ||
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; } | ||
export function persistSession(session, cookie) { | ||
if (utils.isEmptyObject(session)) { | ||
@@ -101,5 +95,3 @@ clearSession(cookie); | ||
} | ||
if (withNewSessionStrategy) { | ||
session.expire = String(Date.now() + SESSION_EXPIRATION_DELAY); | ||
} | ||
session.expire = String(Date.now() + SESSION_EXPIRATION_DELAY); | ||
var cookieString = utils | ||
@@ -106,0 +98,0 @@ .objectEntries(session) |
{ | ||
"name": "@datadog/browser-core", | ||
"version": "1.9.4", | ||
"version": "1.10.0", | ||
"license": "Apache-2.0", | ||
@@ -29,3 +29,3 @@ "main": "cjs/index.js", | ||
}, | ||
"gitHead": "9b90635fe65260cb6b8b1d960e6fbb6e1912e04d" | ||
"gitHead": "bbe113b3206ebd5f18b9a0f14ec1f1577a91b0f5" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
354583
5853