Socket
Socket
Sign inDemoInstall

@datadog/browser-core

Package Overview
Dependencies
0
Maintainers
1
Versions
246
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.42.2 to 4.43.0

cjs/domain/session/sessionState.d.ts

2

cjs/boot/init.js

@@ -9,3 +9,3 @@ "use strict";

var publicApi = (0, polyfills_1.assign)({
version: "4.42.2",
version: "4.43.0",
// This API method is intentionally not monitored, since the only thing executed is the

@@ -12,0 +12,0 @@ // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and

@@ -1,2 +0,1 @@

export declare const COOKIE_ACCESS_DELAY = 1000;
export interface CookieOptions {

@@ -3,0 +2,0 @@ secure?: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurrentSite = exports.areCookiesAuthorized = exports.deleteCookie = exports.getCookie = exports.setCookie = exports.COOKIE_ACCESS_DELAY = void 0;
exports.getCurrentSite = exports.areCookiesAuthorized = exports.deleteCookie = exports.getCookie = exports.setCookie = void 0;
var display_1 = require("../tools/display");
var timeUtils_1 = require("../tools/utils/timeUtils");
var stringUtils_1 = require("../tools/utils/stringUtils");
exports.COOKIE_ACCESS_DELAY = timeUtils_1.ONE_SECOND;
function setCookie(name, value, expireDelay, options) {

@@ -9,0 +8,0 @@ var date = new Date();

@@ -1,4 +0,4 @@

import type { CookieOptions } from '../../browser/cookie';
import type { RawTelemetryConfiguration } from '../telemetry';
import type { Duration } from '../../tools/utils/timeUtils';
import type { SessionStoreStrategyType } from '../session/storeStrategies/sessionStoreStrategy';
import type { TransportConfiguration } from './transportConfiguration';

@@ -35,2 +35,3 @@ export declare const DefaultPrivacyLevel: {

trackSessionAcrossSubdomains?: boolean | undefined;
allowFallbackToLocalStorage?: boolean | undefined;
enableExperimentalFeatures?: string[] | undefined;

@@ -49,3 +50,3 @@ replica?: ReplicaUserConfiguration | undefined;

beforeSend: GenericBeforeSendCallback | undefined;
cookieOptions: CookieOptions;
sessionStoreStrategyType: SessionStoreStrategyType | undefined;
sessionSampleRate: number;

@@ -64,4 +65,3 @@ telemetrySampleRate: number;

export declare function validateAndBuildConfiguration(initConfiguration: InitConfiguration): Configuration | undefined;
export declare function buildCookieOptions(initConfiguration: InitConfiguration): CookieOptions;
export declare function serializeConfiguration(configuration: InitConfiguration): Partial<RawTelemetryConfiguration>;
export declare function serializeConfiguration(initConfiguration: InitConfiguration): Partial<RawTelemetryConfiguration>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeConfiguration = exports.buildCookieOptions = exports.validateAndBuildConfiguration = exports.DefaultPrivacyLevel = void 0;
var cookie_1 = require("../../browser/cookie");
exports.serializeConfiguration = exports.validateAndBuildConfiguration = exports.DefaultPrivacyLevel = void 0;
var catchUserErrors_1 = require("../../tools/catchUserErrors");

@@ -13,2 +12,3 @@ var display_1 = require("../../tools/display");

var polyfills_1 = require("../../tools/utils/polyfills");
var sessionStore_1 = require("../session/sessionStore");
var transportConfiguration_1 = require("./transportConfiguration");

@@ -48,3 +48,3 @@ exports.DefaultPrivacyLevel = {

beforeSend: initConfiguration.beforeSend && (0, catchUserErrors_1.catchUserErrors)(initConfiguration.beforeSend, 'beforeSend threw an error:'),
cookieOptions: buildCookieOptions(initConfiguration),
sessionStoreStrategyType: (0, sessionStore_1.selectSessionStoreStrategyType)(initConfiguration),
sessionSampleRate: sessionSampleRate !== null && sessionSampleRate !== void 0 ? sessionSampleRate : 100,

@@ -75,30 +75,18 @@ telemetrySampleRate: (_b = initConfiguration.telemetrySampleRate) !== null && _b !== void 0 ? _b : 20,

exports.validateAndBuildConfiguration = validateAndBuildConfiguration;
function buildCookieOptions(initConfiguration) {
var cookieOptions = {};
cookieOptions.secure = mustUseSecureCookie(initConfiguration);
cookieOptions.crossSite = !!initConfiguration.useCrossSiteSessionCookie;
if (initConfiguration.trackSessionAcrossSubdomains) {
cookieOptions.domain = (0, cookie_1.getCurrentSite)();
}
return cookieOptions;
}
exports.buildCookieOptions = buildCookieOptions;
function mustUseSecureCookie(initConfiguration) {
return !!initConfiguration.useSecureSessionCookie || !!initConfiguration.useCrossSiteSessionCookie;
}
function serializeConfiguration(configuration) {
function serializeConfiguration(initConfiguration) {
var _a, _b;
var proxy = (_a = configuration.proxy) !== null && _a !== void 0 ? _a : configuration.proxyUrl;
var proxy = (_a = initConfiguration.proxy) !== null && _a !== void 0 ? _a : initConfiguration.proxyUrl;
return {
session_sample_rate: (_b = configuration.sessionSampleRate) !== null && _b !== void 0 ? _b : configuration.sampleRate,
telemetry_sample_rate: configuration.telemetrySampleRate,
telemetry_configuration_sample_rate: configuration.telemetryConfigurationSampleRate,
use_before_send: !!configuration.beforeSend,
use_cross_site_session_cookie: configuration.useCrossSiteSessionCookie,
use_secure_session_cookie: configuration.useSecureSessionCookie,
session_sample_rate: (_b = initConfiguration.sessionSampleRate) !== null && _b !== void 0 ? _b : initConfiguration.sampleRate,
telemetry_sample_rate: initConfiguration.telemetrySampleRate,
telemetry_configuration_sample_rate: initConfiguration.telemetryConfigurationSampleRate,
use_before_send: !!initConfiguration.beforeSend,
use_cross_site_session_cookie: initConfiguration.useCrossSiteSessionCookie,
use_secure_session_cookie: initConfiguration.useSecureSessionCookie,
use_proxy: proxy !== undefined ? !!proxy : undefined,
silent_multiple_init: configuration.silentMultipleInit,
track_session_across_subdomains: configuration.trackSessionAcrossSubdomains,
track_resources: configuration.trackResources,
track_long_task: configuration.trackLongTasks,
silent_multiple_init: initConfiguration.silentMultipleInit,
track_session_across_subdomains: initConfiguration.trackSessionAcrossSubdomains,
track_resources: initConfiguration.trackResources,
track_long_task: initConfiguration.trackLongTasks,
allow_fallback_to_local_storage: !!initConfiguration.allowFallbackToLocalStorage,
};

@@ -105,0 +93,0 @@ }

@@ -69,3 +69,3 @@ "use strict";

var clientToken = _a.clientToken, internalAnalyticsSubdomain = _a.internalAnalyticsSubdomain;
var tags = ["sdk_version:".concat("4.42.2"), "api:".concat(api)].concat(configurationTags);
var tags = ["sdk_version:".concat("4.43.0"), "api:".concat(api)].concat(configurationTags);
if (flushReason && (0, experimentalFeatures_1.isExperimentalFeatureEnabled)(experimentalFeatures_1.ExperimentalFeature.COLLECT_FLUSH_REASON)) {

@@ -81,3 +81,3 @@ tags.push("flush_reason:".concat(flushReason));

"dd-api-key=".concat(clientToken),
"dd-evp-origin-version=".concat(encodeURIComponent("4.42.2")),
"dd-evp-origin-version=".concat(encodeURIComponent("4.43.0")),
'dd-evp-origin=browser',

@@ -84,0 +84,0 @@ "dd-request-id=".concat((0, stringUtils_1.generateUUID)()),

@@ -1,3 +0,3 @@

export { Configuration, InitConfiguration, buildCookieOptions, DefaultPrivacyLevel, validateAndBuildConfiguration, serializeConfiguration, } from './configuration';
export { Configuration, InitConfiguration, DefaultPrivacyLevel, validateAndBuildConfiguration, serializeConfiguration, } from './configuration';
export { createEndpointBuilder, EndpointBuilder, EndpointType } from './endpointBuilder';
export * from './intakeSites';

@@ -17,5 +17,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createEndpointBuilder = exports.serializeConfiguration = exports.validateAndBuildConfiguration = exports.DefaultPrivacyLevel = exports.buildCookieOptions = void 0;
exports.createEndpointBuilder = exports.serializeConfiguration = exports.validateAndBuildConfiguration = exports.DefaultPrivacyLevel = void 0;
var configuration_1 = require("./configuration");
Object.defineProperty(exports, "buildCookieOptions", { enumerable: true, get: function () { return configuration_1.buildCookieOptions; } });
Object.defineProperty(exports, "DefaultPrivacyLevel", { enumerable: true, get: function () { return configuration_1.DefaultPrivacyLevel; } });

@@ -22,0 +21,0 @@ Object.defineProperty(exports, "validateAndBuildConfiguration", { enumerable: true, get: function () { return configuration_1.validateAndBuildConfiguration; } });

@@ -1,2 +0,2 @@

import type { CookieOptions } from '../../browser/cookie';
import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy';
export declare const OLD_SESSION_COOKIE_NAME = "_dd";

@@ -11,2 +11,2 @@ export declare const OLD_RUM_COOKIE_NAME = "_dd_r";

*/
export declare function tryOldCookiesMigration(options: CookieOptions): void;
export declare function tryOldCookiesMigration(cookieStoreStrategy: SessionStoreStrategy): void;

@@ -5,3 +5,4 @@ "use strict";

var cookie_1 = require("../../browser/cookie");
var sessionCookieStore_1 = require("./sessionCookieStore");
var sessionStoreStrategy_1 = require("./storeStrategies/sessionStoreStrategy");
var sessionState_1 = require("./sessionState");
exports.OLD_SESSION_COOKIE_NAME = '_dd';

@@ -17,8 +18,8 @@ exports.OLD_RUM_COOKIE_NAME = '_dd_r';

*/
function tryOldCookiesMigration(options) {
var sessionString = (0, cookie_1.getCookie)(sessionCookieStore_1.SESSION_COOKIE_NAME);
var oldSessionId = (0, cookie_1.getCookie)(exports.OLD_SESSION_COOKIE_NAME);
var oldRumType = (0, cookie_1.getCookie)(exports.OLD_RUM_COOKIE_NAME);
var oldLogsType = (0, cookie_1.getCookie)(exports.OLD_LOGS_COOKIE_NAME);
function tryOldCookiesMigration(cookieStoreStrategy) {
var sessionString = (0, cookie_1.getCookie)(sessionStoreStrategy_1.SESSION_STORE_KEY);
if (!sessionString) {
var oldSessionId = (0, cookie_1.getCookie)(exports.OLD_SESSION_COOKIE_NAME);
var oldRumType = (0, cookie_1.getCookie)(exports.OLD_RUM_COOKIE_NAME);
var oldLogsType = (0, cookie_1.getCookie)(exports.OLD_LOGS_COOKIE_NAME);
var session = {};

@@ -34,3 +35,6 @@ if (oldSessionId) {

}
(0, sessionCookieStore_1.persistSessionCookie)(session, options);
if (!(0, sessionState_1.isSessionInExpiredState)(session)) {
(0, sessionState_1.expandSessionState)(session);
cookieStoreStrategy.persistSession(session);
}
}

@@ -37,0 +41,0 @@ }

@@ -1,5 +0,5 @@

import type { CookieOptions } from '../../browser/cookie';
import type { Observable } from '../../tools/observable';
import type { Context } from '../../tools/serialisation/context';
import type { RelativeTime } from '../../tools/utils/timeUtils';
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy';
export interface SessionManager<TrackingType extends string> {

@@ -16,3 +16,3 @@ findActiveSession: (startTime?: RelativeTime) => SessionContext<TrackingType> | undefined;

export declare const VISIBILITY_CHECK_DELAY: number;
export declare function startSessionManager<TrackingType extends string>(options: CookieOptions, productKey: string, computeSessionState: (rawTrackingType?: string) => {
export declare function startSessionManager<TrackingType extends string>(sessionStoreStrategyType: SessionStoreStrategyType, productKey: string, computeSessionState: (rawTrackingType?: string) => {
trackingType: TrackingType;

@@ -19,0 +19,0 @@ isTracked: boolean;

@@ -8,11 +8,9 @@ "use strict";

var timer_1 = require("../../tools/timer");
var oldCookiesMigration_1 = require("./oldCookiesMigration");
var sessionConstants_1 = require("./sessionConstants");
var sessionStore_1 = require("./sessionStore");
var sessionConstants_1 = require("./sessionConstants");
exports.VISIBILITY_CHECK_DELAY = timeUtils_1.ONE_MINUTE;
var SESSION_CONTEXT_TIMEOUT_DELAY = sessionConstants_1.SESSION_TIME_OUT_DELAY;
var stopCallbacks = [];
function startSessionManager(options, productKey, computeSessionState) {
(0, oldCookiesMigration_1.tryOldCookiesMigration)(options);
var sessionStore = (0, sessionStore_1.startSessionStore)(options, productKey, computeSessionState);
function startSessionManager(sessionStoreStrategyType, productKey, computeSessionState) {
var sessionStore = (0, sessionStore_1.startSessionStore)(sessionStoreStrategyType, productKey, computeSessionState);
stopCallbacks.push(function () { return sessionStore.stop(); });

@@ -19,0 +17,0 @@ var sessionContextHistory = new valueHistory_1.ValueHistory(SESSION_CONTEXT_TIMEOUT_DELAY);

@@ -1,3 +0,5 @@

import type { CookieOptions } from '../../browser/cookie';
import { Observable } from '../../tools/observable';
import type { InitConfiguration } from '../configuration';
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy';
import type { SessionState } from './sessionState';
export interface SessionStore {

@@ -12,10 +14,14 @@ expandOrRenewSession: () => void;

}
export interface SessionState {
id?: string;
created?: string;
expire?: string;
lock?: string;
[key: string]: string | undefined;
}
/**
* Every second, the storage will be polled to check for any change that can occur
* to the session state in another browser tab, or another window.
* This value has been determined from our previous cookie-only implementation.
*/
export declare const STORAGE_POLL_DELAY = 1000;
/**
* Checks if cookies are available as the preferred storage
* Else, checks if LocalStorage is allowed and available
*/
export declare function selectSessionStoreStrategyType(initConfiguration: InitConfiguration): SessionStoreStrategyType | undefined;
/**
* Different session concepts:

@@ -26,5 +32,5 @@ * - tracked, the session has an id and is updated along the user navigation

*/
export declare function startSessionStore<TrackingType extends string>(options: CookieOptions, productKey: string, computeSessionState: (rawTrackingType?: string) => {
export declare function startSessionStore<TrackingType extends string>(sessionStoreStrategyType: SessionStoreStrategyType, productKey: string, computeSessionState: (rawTrackingType?: string) => {
trackingType: TrackingType;
isTracked: boolean;
}): SessionStore;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startSessionStore = void 0;
var cookie_1 = require("../../browser/cookie");
exports.startSessionStore = exports.selectSessionStoreStrategyType = exports.STORAGE_POLL_DELAY = void 0;
var timer_1 = require("../../tools/timer");

@@ -11,4 +10,24 @@ var observable_1 = require("../../tools/observable");

var sessionConstants_1 = require("./sessionConstants");
var sessionCookieStore_1 = require("./sessionCookieStore");
var sessionInCookie_1 = require("./storeStrategies/sessionInCookie");
var sessionInLocalStorage_1 = require("./storeStrategies/sessionInLocalStorage");
var sessionStoreOperations_1 = require("./sessionStoreOperations");
/**
* Every second, the storage will be polled to check for any change that can occur
* to the session state in another browser tab, or another window.
* This value has been determined from our previous cookie-only implementation.
*/
exports.STORAGE_POLL_DELAY = timeUtils_1.ONE_SECOND;
/**
* Checks if cookies are available as the preferred storage
* Else, checks if LocalStorage is allowed and available
*/
function selectSessionStoreStrategyType(initConfiguration) {
var sessionStoreStrategyType = (0, sessionInCookie_1.selectCookieStrategy)(initConfiguration);
if (!sessionStoreStrategyType && initConfiguration.allowFallbackToLocalStorage) {
sessionStoreStrategyType = (0, sessionInLocalStorage_1.selectLocalStorageStrategy)();
}
return sessionStoreStrategyType;
}
exports.selectSessionStoreStrategyType = selectSessionStoreStrategyType;
/**
* Different session concepts:

@@ -19,62 +38,63 @@ * - tracked, the session has an id and is updated along the user navigation

*/
function startSessionStore(options, productKey, computeSessionState) {
function startSessionStore(sessionStoreStrategyType, productKey, computeSessionState) {
var renewObservable = new observable_1.Observable();
var expireObservable = new observable_1.Observable();
var watchSessionTimeoutId = (0, timer_1.setInterval)(watchSession, cookie_1.COOKIE_ACCESS_DELAY);
var sessionStoreStrategy = sessionStoreStrategyType.type === 'Cookie'
? (0, sessionInCookie_1.initCookieStrategy)(sessionStoreStrategyType.cookieOptions)
: (0, sessionInLocalStorage_1.initLocalStorageStrategy)();
var clearSession = sessionStoreStrategy.clearSession, retrieveSession = sessionStoreStrategy.retrieveSession;
var watchSessionTimeoutId = (0, timer_1.setInterval)(watchSession, exports.STORAGE_POLL_DELAY);
var sessionCache = retrieveActiveSession();
function expandOrRenewSession() {
var isTracked;
(0, sessionCookieStore_1.withCookieLockAccess)({
options: options,
process: function (cookieSession) {
var synchronizedSession = synchronizeSession(cookieSession);
isTracked = expandOrRenewCookie(synchronizedSession);
(0, sessionStoreOperations_1.processSessionStoreOperations)({
process: function (sessionState) {
var synchronizedSession = synchronizeSession(sessionState);
isTracked = expandOrRenewSessionState(synchronizedSession);
return synchronizedSession;
},
after: function (cookieSession) {
after: function (sessionState) {
if (isTracked && !hasSessionInCache()) {
renewSessionInCache(cookieSession);
renewSessionInCache(sessionState);
}
sessionCache = cookieSession;
sessionCache = sessionState;
},
});
}, sessionStoreStrategy);
}
function expandSession() {
(0, sessionCookieStore_1.withCookieLockAccess)({
options: options,
process: function (cookieSession) { return (hasSessionInCache() ? synchronizeSession(cookieSession) : undefined); },
});
(0, sessionStoreOperations_1.processSessionStoreOperations)({
process: function (sessionState) { return (hasSessionInCache() ? synchronizeSession(sessionState) : undefined); },
}, sessionStoreStrategy);
}
/**
* allows two behaviors:
* - if the session is active, synchronize the session cache without updating the session cookie
* - if the session is not active, clear the session cookie and expire the session cache
* - if the session is active, synchronize the session cache without updating the session store
* - if the session is not active, clear the session store and expire the session cache
*/
function watchSession() {
(0, sessionCookieStore_1.withCookieLockAccess)({
options: options,
process: function (cookieSession) { return (!isActiveSession(cookieSession) ? {} : undefined); },
(0, sessionStoreOperations_1.processSessionStoreOperations)({
process: function (sessionState) { return (!isActiveSession(sessionState) ? {} : undefined); },
after: synchronizeSession,
});
}, sessionStoreStrategy);
}
function synchronizeSession(cookieSession) {
if (!isActiveSession(cookieSession)) {
cookieSession = {};
function synchronizeSession(sessionState) {
if (!isActiveSession(sessionState)) {
sessionState = {};
}
if (hasSessionInCache()) {
if (isSessionInCacheOutdated(cookieSession)) {
if (isSessionInCacheOutdated(sessionState)) {
expireSessionInCache();
}
else {
sessionCache = cookieSession;
sessionCache = sessionState;
}
}
return cookieSession;
return sessionState;
}
function expandOrRenewCookie(cookieSession) {
var _a = computeSessionState(cookieSession[productKey]), trackingType = _a.trackingType, isTracked = _a.isTracked;
cookieSession[productKey] = trackingType;
if (isTracked && !cookieSession.id) {
cookieSession.id = (0, stringUtils_1.generateUUID)();
cookieSession.created = String((0, timeUtils_1.dateNow)());
function expandOrRenewSessionState(sessionState) {
var _a = computeSessionState(sessionState[productKey]), trackingType = _a.trackingType, isTracked = _a.isTracked;
sessionState[productKey] = trackingType;
if (isTracked && !sessionState.id) {
sessionState.id = (0, stringUtils_1.generateUUID)();
sessionState.created = String((0, timeUtils_1.dateNow)());
}

@@ -86,4 +106,4 @@ return isTracked;

}
function isSessionInCacheOutdated(cookieSession) {
return sessionCache.id !== cookieSession.id || sessionCache[productKey] !== cookieSession[productKey];
function isSessionInCacheOutdated(sessionState) {
return sessionCache.id !== sessionState.id || sessionCache[productKey] !== sessionState[productKey];
}

@@ -94,8 +114,8 @@ function expireSessionInCache() {

}
function renewSessionInCache(cookieSession) {
sessionCache = cookieSession;
function renewSessionInCache(sessionState) {
sessionCache = sessionState;
renewObservable.notify();
}
function retrieveActiveSession() {
var session = (0, sessionCookieStore_1.retrieveSessionCookie)();
var session = retrieveSession();
if (isActiveSession(session)) {

@@ -106,10 +126,10 @@ return session;

}
function isActiveSession(session) {
function isActiveSession(sessionState) {
// created and expire can be undefined for versions which was not storing them
// these checks could be removed when older versions will not be available/live anymore
return ((session.created === undefined || (0, timeUtils_1.dateNow)() - Number(session.created) < sessionConstants_1.SESSION_TIME_OUT_DELAY) &&
(session.expire === undefined || (0, timeUtils_1.dateNow)() < Number(session.expire)));
return ((sessionState.created === undefined || (0, timeUtils_1.dateNow)() - Number(sessionState.created) < sessionConstants_1.SESSION_TIME_OUT_DELAY) &&
(sessionState.expire === undefined || (0, timeUtils_1.dateNow)() < Number(sessionState.expire)));
}
return {
expandOrRenewSession: (0, functionUtils_1.throttle)(expandOrRenewSession, cookie_1.COOKIE_ACCESS_DELAY).throttled,
expandOrRenewSession: (0, functionUtils_1.throttle)(expandOrRenewSession, exports.STORAGE_POLL_DELAY).throttled,
expandSession: expandSession,

@@ -120,3 +140,3 @@ getSession: function () { return sessionCache; },

expire: function () {
(0, sessionCookieStore_1.deleteSessionCookie)(options);
clearSession();
synchronizeSession({});

@@ -123,0 +143,0 @@ },

@@ -44,2 +44,3 @@ import type { Context } from '../../tools/serialisation/context';

session_replay_sample_rate?: number | undefined;
start_session_replay_recording_manually?: boolean | undefined;
use_proxy?: boolean | undefined;

@@ -46,0 +47,0 @@ use_before_send?: boolean | undefined;

@@ -21,2 +21,4 @@ "use strict";

'https://www.datad0g-browser-agent.com',
'https://d3uc069fcn7uxw.cloudfront.net',
'https://d20xtzwzcl0ceb.cloudfront.net',
'http://localhost',

@@ -52,3 +54,3 @@ '<anonymous>',

service: telemetryService,
version: "4.42.2",
version: "4.43.0",
source: 'browser',

@@ -55,0 +57,0 @@ _dd: {

@@ -115,2 +115,6 @@ /**

/**
* Whether the session replay start is handled manually
*/
start_session_replay_recording_manually?: boolean;
/**
* Whether a proxy configured is used

@@ -117,0 +121,0 @@ */

@@ -1,2 +0,2 @@

export { Configuration, InitConfiguration, buildCookieOptions, validateAndBuildConfiguration, DefaultPrivacyLevel, EndpointBuilder, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';
export { Configuration, InitConfiguration, validateAndBuildConfiguration, DefaultPrivacyLevel, EndpointBuilder, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';
export { isExperimentalFeatureEnabled, addExperimentalFeatures, resetExperimentalFeatures, getExperimentalFeatures, ExperimentalFeature, } from './tools/experimentalFeatures';

@@ -29,3 +29,3 @@ export { trackRuntimeError } from './domain/error/trackRuntimeError';

export { Context, ContextArray, ContextValue } from './tools/serialisation/context';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie } from './browser/cookie';
export { initXhrObservable, XhrCompleteContext, XhrStartContext } from './browser/xhrObservable';

@@ -43,3 +43,4 @@ export { initFetchObservable, FetchResolveContext, FetchStartContext, FetchContext } from './browser/fetchObservable';

export { readBytesFromStream } from './tools/readBytesFromStream';
export { SESSION_COOKIE_NAME } from './domain/session/sessionCookieStore';
export { STORAGE_POLL_DELAY } from './domain/session/sessionStore';
export { SESSION_STORE_KEY } from './domain/session/storeStrategies/sessionStoreStrategy';
export { willSyntheticsInjectRum, getSyntheticsTestId, getSyntheticsResultId, } from './domain/synthetics/syntheticsWorkerValues';

@@ -46,0 +47,0 @@ export { User, checkUser, sanitizeUser } from './domain/user';

@@ -17,6 +17,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createHandlingStack = exports.computeRawError = exports.instrumentSetter = exports.instrumentMethodAndCallOriginal = exports.instrumentMethod = exports.getZoneJsOriginalValue = exports.runOnReadyState = exports.sendToExtension = exports.AbstractLifeCycle = exports.createFlushController = exports.startBatchWithReplica = exports.getEventBridge = exports.canUseEventBridge = exports.Batch = exports.createHttpRequest = exports.SESSION_TIME_OUT_DELAY = exports.stopSessionManager = exports.startSessionManager = exports.Observable = exports.setDebugMode = exports.callMonitored = exports.monitor = exports.monitored = exports.addTelemetryConfiguration = exports.isTelemetryReplicationAllowed = exports.resetTelemetry = exports.startFakeTelemetry = exports.addTelemetryError = exports.addTelemetryDebug = exports.startTelemetry = exports.RawReportType = exports.initReportObservable = exports.makePublicApi = exports.defineGlobal = exports.computeStackTrace = exports.trackRuntimeError = exports.ExperimentalFeature = exports.getExperimentalFeatures = exports.resetExperimentalFeatures = exports.addExperimentalFeatures = exports.isExperimentalFeatureEnabled = exports.INTAKE_SITE_EU1 = exports.INTAKE_SITE_US1_FED = exports.INTAKE_SITE_US1 = exports.INTAKE_SITE_STAGING = exports.INTAKE_SITE_AP1 = exports.serializeConfiguration = exports.DefaultPrivacyLevel = exports.validateAndBuildConfiguration = exports.buildCookieOptions = void 0;
exports.ErrorSource = exports.sanitizeUser = exports.checkUser = exports.getSyntheticsResultId = exports.getSyntheticsTestId = exports.willSyntheticsInjectRum = exports.SESSION_COOKIE_NAME = exports.readBytesFromStream = exports.CLEAR_OLD_VALUES_INTERVAL = exports.ValueHistory = exports.CUSTOMER_DATA_BYTES_LIMIT = exports.warnIfCustomerDataLimitReached = exports.createContextManager = exports.catchUserErrors = exports.BoundedBuffer = exports.resetConsoleObservable = exports.initConsoleObservable = exports.isPageExitReason = exports.PageExitReason = exports.createPageExitObservable = exports.initFetchObservable = exports.initXhrObservable = exports.COOKIE_ACCESS_DELAY = exports.deleteCookie = exports.setCookie = exports.getCookie = exports.areCookiesAuthorized = exports.NO_ERROR_STACK_PRESENT_MESSAGE = exports.getFileFromStackTraceString = exports.toStackTraceString = void 0;
exports.toStackTraceString = exports.createHandlingStack = exports.computeRawError = exports.instrumentSetter = exports.instrumentMethodAndCallOriginal = exports.instrumentMethod = exports.getZoneJsOriginalValue = exports.runOnReadyState = exports.sendToExtension = exports.AbstractLifeCycle = exports.createFlushController = exports.startBatchWithReplica = exports.getEventBridge = exports.canUseEventBridge = exports.Batch = exports.createHttpRequest = exports.SESSION_TIME_OUT_DELAY = exports.stopSessionManager = exports.startSessionManager = exports.Observable = exports.setDebugMode = exports.callMonitored = exports.monitor = exports.monitored = exports.addTelemetryConfiguration = exports.isTelemetryReplicationAllowed = exports.resetTelemetry = exports.startFakeTelemetry = exports.addTelemetryError = exports.addTelemetryDebug = exports.startTelemetry = exports.RawReportType = exports.initReportObservable = exports.makePublicApi = exports.defineGlobal = exports.computeStackTrace = exports.trackRuntimeError = exports.ExperimentalFeature = exports.getExperimentalFeatures = exports.resetExperimentalFeatures = exports.addExperimentalFeatures = exports.isExperimentalFeatureEnabled = exports.INTAKE_SITE_EU1 = exports.INTAKE_SITE_US1_FED = exports.INTAKE_SITE_US1 = exports.INTAKE_SITE_STAGING = exports.INTAKE_SITE_AP1 = exports.serializeConfiguration = exports.DefaultPrivacyLevel = exports.validateAndBuildConfiguration = void 0;
exports.ErrorSource = exports.sanitizeUser = exports.checkUser = exports.getSyntheticsResultId = exports.getSyntheticsTestId = exports.willSyntheticsInjectRum = exports.SESSION_STORE_KEY = exports.STORAGE_POLL_DELAY = exports.readBytesFromStream = exports.CLEAR_OLD_VALUES_INTERVAL = exports.ValueHistory = exports.CUSTOMER_DATA_BYTES_LIMIT = exports.warnIfCustomerDataLimitReached = exports.createContextManager = exports.catchUserErrors = exports.BoundedBuffer = exports.resetConsoleObservable = exports.initConsoleObservable = exports.isPageExitReason = exports.PageExitReason = exports.createPageExitObservable = exports.initFetchObservable = exports.initXhrObservable = exports.deleteCookie = exports.setCookie = exports.getCookie = exports.areCookiesAuthorized = exports.NO_ERROR_STACK_PRESENT_MESSAGE = exports.getFileFromStackTraceString = void 0;
var configuration_1 = require("./domain/configuration");
Object.defineProperty(exports, "buildCookieOptions", { enumerable: true, get: function () { return configuration_1.buildCookieOptions; } });
Object.defineProperty(exports, "validateAndBuildConfiguration", { enumerable: true, get: function () { return configuration_1.validateAndBuildConfiguration; } });

@@ -105,3 +104,2 @@ Object.defineProperty(exports, "DefaultPrivacyLevel", { enumerable: true, get: function () { return configuration_1.DefaultPrivacyLevel; } });

Object.defineProperty(exports, "deleteCookie", { enumerable: true, get: function () { return cookie_1.deleteCookie; } });
Object.defineProperty(exports, "COOKIE_ACCESS_DELAY", { enumerable: true, get: function () { return cookie_1.COOKIE_ACCESS_DELAY; } });
var xhrObservable_1 = require("./browser/xhrObservable");

@@ -134,4 +132,6 @@ Object.defineProperty(exports, "initXhrObservable", { enumerable: true, get: function () { return xhrObservable_1.initXhrObservable; } });

Object.defineProperty(exports, "readBytesFromStream", { enumerable: true, get: function () { return readBytesFromStream_1.readBytesFromStream; } });
var sessionCookieStore_1 = require("./domain/session/sessionCookieStore");
Object.defineProperty(exports, "SESSION_COOKIE_NAME", { enumerable: true, get: function () { return sessionCookieStore_1.SESSION_COOKIE_NAME; } });
var sessionStore_1 = require("./domain/session/sessionStore");
Object.defineProperty(exports, "STORAGE_POLL_DELAY", { enumerable: true, get: function () { return sessionStore_1.STORAGE_POLL_DELAY; } });
var sessionStoreStrategy_1 = require("./domain/session/storeStrategies/sessionStoreStrategy");
Object.defineProperty(exports, "SESSION_STORE_KEY", { enumerable: true, get: function () { return sessionStoreStrategy_1.SESSION_STORE_KEY; } });
var syntheticsWorkerValues_1 = require("./domain/synthetics/syntheticsWorkerValues");

@@ -138,0 +138,0 @@ Object.defineProperty(exports, "willSyntheticsInjectRum", { enumerable: true, get: function () { return syntheticsWorkerValues_1.willSyntheticsInjectRum; } });

@@ -14,3 +14,5 @@ /**

RESOURCE_PAGE_STATES = "resource_page_states",
COLLECT_FLUSH_REASON = "collect_flush_reason"
PAGE_STATES = "page_states",
COLLECT_FLUSH_REASON = "collect_flush_reason",
NO_RESOURCE_DURATION_FROZEN_STATE = "no_resource_duration_frozen_state"
}

@@ -17,0 +19,0 @@ export declare function addExperimentalFeatures(enabledFeatures: ExperimentalFeature[]): void;

@@ -21,3 +21,5 @@ "use strict";

ExperimentalFeature["RESOURCE_PAGE_STATES"] = "resource_page_states";
ExperimentalFeature["PAGE_STATES"] = "page_states";
ExperimentalFeature["COLLECT_FLUSH_REASON"] = "collect_flush_reason";
ExperimentalFeature["NO_RESOURCE_DURATION_FROZEN_STATE"] = "no_resource_duration_frozen_state";
})(ExperimentalFeature = exports.ExperimentalFeature || (exports.ExperimentalFeature = {}));

@@ -24,0 +26,0 @@ var enabledExperimentalFeatures = new Set();

@@ -1,2 +0,2 @@

import type { RelativeTime } from './utils/timeUtils';
import type { Duration, RelativeTime } from './utils/timeUtils';
export interface ValueHistoryEntry<T> {

@@ -16,5 +16,6 @@ startTime: RelativeTime;

private expireDelay;
private maxEntries?;
private entries;
private clearOldValuesInterval;
constructor(expireDelay: number);
constructor(expireDelay: number, maxEntries?: number | undefined);
/**

@@ -36,6 +37,7 @@ * Add a value to the history associated with a start time. Returns a reference to this newly

/**
* Return all values that were active during `startTime`, or all currently active values if no
* `startTime` is provided.
* Return all values with an active period overlapping with the duration,
* or all values that were active during `startTime` if no duration is provided,
* or all currently active values if no `startTime` is provided.
*/
findAll(startTime?: RelativeTime): Value[];
findAll(startTime?: RelativeTime, duration?: Duration): Value[];
/**

@@ -42,0 +44,0 @@ * Remove all entries from this collection.

@@ -13,5 +13,6 @@ "use strict";

var ValueHistory = /** @class */ (function () {
function ValueHistory(expireDelay) {
function ValueHistory(expireDelay, maxEntries) {
var _this = this;
this.expireDelay = expireDelay;
this.maxEntries = maxEntries;
this.entries = [];

@@ -40,2 +41,5 @@ this.clearOldValuesInterval = (0, timer_1.setInterval)(function () { return _this.clearOldValues(); }, exports.CLEAR_OLD_VALUES_INTERVAL);

};
if (this.maxEntries && this.entries.length >= this.maxEntries) {
this.entries.pop();
}
this.entries.unshift(entry);

@@ -71,9 +75,12 @@ return entry;

/**
* Return all values that were active during `startTime`, or all currently active values if no
* `startTime` is provided.
* Return all values with an active period overlapping with the duration,
* or all values that were active during `startTime` if no duration is provided,
* or all currently active values if no `startTime` is provided.
*/
ValueHistory.prototype.findAll = function (startTime) {
ValueHistory.prototype.findAll = function (startTime, duration) {
if (startTime === void 0) { startTime = END_OF_TIMES; }
if (duration === void 0) { duration = 0; }
var endTime = (0, timeUtils_1.addDuration)(startTime, duration);
return this.entries
.filter(function (entry) { return entry.startTime <= startTime && startTime <= entry.endTime; })
.filter(function (entry) { return entry.startTime <= endTime && startTime <= entry.endTime; })
.map(function (entry) { return entry.value; });

@@ -80,0 +87,0 @@ };

@@ -6,3 +6,3 @@ import { catchUserErrors } from '../tools/catchUserErrors';

var publicApi = assign({
version: "4.42.2",
version: "4.43.0",
// This API method is intentionally not monitored, since the only thing executed is the

@@ -9,0 +9,0 @@ // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and

@@ -1,2 +0,1 @@

export declare const COOKIE_ACCESS_DELAY = 1000;
export interface CookieOptions {

@@ -3,0 +2,0 @@ secure?: boolean;

import { display } from '../tools/display';
import { ONE_MINUTE, ONE_SECOND } from '../tools/utils/timeUtils';
import { findCommaSeparatedValue, generateUUID } from '../tools/utils/stringUtils';
export var COOKIE_ACCESS_DELAY = ONE_SECOND;
export function setCookie(name, value, expireDelay, options) {

@@ -6,0 +5,0 @@ var date = new Date();

@@ -1,4 +0,4 @@

import type { CookieOptions } from '../../browser/cookie';
import type { RawTelemetryConfiguration } from '../telemetry';
import type { Duration } from '../../tools/utils/timeUtils';
import type { SessionStoreStrategyType } from '../session/storeStrategies/sessionStoreStrategy';
import type { TransportConfiguration } from './transportConfiguration';

@@ -35,2 +35,3 @@ export declare const DefaultPrivacyLevel: {

trackSessionAcrossSubdomains?: boolean | undefined;
allowFallbackToLocalStorage?: boolean | undefined;
enableExperimentalFeatures?: string[] | undefined;

@@ -49,3 +50,3 @@ replica?: ReplicaUserConfiguration | undefined;

beforeSend: GenericBeforeSendCallback | undefined;
cookieOptions: CookieOptions;
sessionStoreStrategyType: SessionStoreStrategyType | undefined;
sessionSampleRate: number;

@@ -64,4 +65,3 @@ telemetrySampleRate: number;

export declare function validateAndBuildConfiguration(initConfiguration: InitConfiguration): Configuration | undefined;
export declare function buildCookieOptions(initConfiguration: InitConfiguration): CookieOptions;
export declare function serializeConfiguration(configuration: InitConfiguration): Partial<RawTelemetryConfiguration>;
export declare function serializeConfiguration(initConfiguration: InitConfiguration): Partial<RawTelemetryConfiguration>;
export {};

@@ -1,2 +0,1 @@

import { getCurrentSite } from '../../browser/cookie';
import { catchUserErrors } from '../../tools/catchUserErrors';

@@ -10,2 +9,3 @@ import { display } from '../../tools/display';

import { assign } from '../../tools/utils/polyfills';
import { selectSessionStoreStrategyType } from '../session/sessionStore';
import { computeTransportConfiguration } from './transportConfiguration';

@@ -45,3 +45,3 @@ export var DefaultPrivacyLevel = {

beforeSend: initConfiguration.beforeSend && catchUserErrors(initConfiguration.beforeSend, 'beforeSend threw an error:'),
cookieOptions: buildCookieOptions(initConfiguration),
sessionStoreStrategyType: selectSessionStoreStrategyType(initConfiguration),
sessionSampleRate: sessionSampleRate !== null && sessionSampleRate !== void 0 ? sessionSampleRate : 100,

@@ -71,31 +71,20 @@ telemetrySampleRate: (_b = initConfiguration.telemetrySampleRate) !== null && _b !== void 0 ? _b : 20,

}
export function buildCookieOptions(initConfiguration) {
var cookieOptions = {};
cookieOptions.secure = mustUseSecureCookie(initConfiguration);
cookieOptions.crossSite = !!initConfiguration.useCrossSiteSessionCookie;
if (initConfiguration.trackSessionAcrossSubdomains) {
cookieOptions.domain = getCurrentSite();
}
return cookieOptions;
}
function mustUseSecureCookie(initConfiguration) {
return !!initConfiguration.useSecureSessionCookie || !!initConfiguration.useCrossSiteSessionCookie;
}
export function serializeConfiguration(configuration) {
export function serializeConfiguration(initConfiguration) {
var _a, _b;
var proxy = (_a = configuration.proxy) !== null && _a !== void 0 ? _a : configuration.proxyUrl;
var proxy = (_a = initConfiguration.proxy) !== null && _a !== void 0 ? _a : initConfiguration.proxyUrl;
return {
session_sample_rate: (_b = configuration.sessionSampleRate) !== null && _b !== void 0 ? _b : configuration.sampleRate,
telemetry_sample_rate: configuration.telemetrySampleRate,
telemetry_configuration_sample_rate: configuration.telemetryConfigurationSampleRate,
use_before_send: !!configuration.beforeSend,
use_cross_site_session_cookie: configuration.useCrossSiteSessionCookie,
use_secure_session_cookie: configuration.useSecureSessionCookie,
session_sample_rate: (_b = initConfiguration.sessionSampleRate) !== null && _b !== void 0 ? _b : initConfiguration.sampleRate,
telemetry_sample_rate: initConfiguration.telemetrySampleRate,
telemetry_configuration_sample_rate: initConfiguration.telemetryConfigurationSampleRate,
use_before_send: !!initConfiguration.beforeSend,
use_cross_site_session_cookie: initConfiguration.useCrossSiteSessionCookie,
use_secure_session_cookie: initConfiguration.useSecureSessionCookie,
use_proxy: proxy !== undefined ? !!proxy : undefined,
silent_multiple_init: configuration.silentMultipleInit,
track_session_across_subdomains: configuration.trackSessionAcrossSubdomains,
track_resources: configuration.trackResources,
track_long_task: configuration.trackLongTasks,
silent_multiple_init: initConfiguration.silentMultipleInit,
track_session_across_subdomains: initConfiguration.trackSessionAcrossSubdomains,
track_resources: initConfiguration.trackResources,
track_long_task: initConfiguration.trackLongTasks,
allow_fallback_to_local_storage: !!initConfiguration.allowFallbackToLocalStorage,
};
}
//# sourceMappingURL=configuration.js.map

@@ -65,3 +65,3 @@ import { timeStampNow } from '../../tools/utils/timeUtils';

var clientToken = _a.clientToken, internalAnalyticsSubdomain = _a.internalAnalyticsSubdomain;
var tags = ["sdk_version:".concat("4.42.2"), "api:".concat(api)].concat(configurationTags);
var tags = ["sdk_version:".concat("4.43.0"), "api:".concat(api)].concat(configurationTags);
if (flushReason && isExperimentalFeatureEnabled(ExperimentalFeature.COLLECT_FLUSH_REASON)) {

@@ -77,3 +77,3 @@ tags.push("flush_reason:".concat(flushReason));

"dd-api-key=".concat(clientToken),
"dd-evp-origin-version=".concat(encodeURIComponent("4.42.2")),
"dd-evp-origin-version=".concat(encodeURIComponent("4.43.0")),
'dd-evp-origin=browser',

@@ -80,0 +80,0 @@ "dd-request-id=".concat(generateUUID()),

@@ -1,3 +0,3 @@

export { Configuration, InitConfiguration, buildCookieOptions, DefaultPrivacyLevel, validateAndBuildConfiguration, serializeConfiguration, } from './configuration';
export { Configuration, InitConfiguration, DefaultPrivacyLevel, validateAndBuildConfiguration, serializeConfiguration, } from './configuration';
export { createEndpointBuilder, EndpointBuilder, EndpointType } from './endpointBuilder';
export * from './intakeSites';

@@ -1,4 +0,4 @@

export { buildCookieOptions, DefaultPrivacyLevel, validateAndBuildConfiguration, serializeConfiguration, } from './configuration';
export { DefaultPrivacyLevel, validateAndBuildConfiguration, serializeConfiguration, } from './configuration';
export { createEndpointBuilder } from './endpointBuilder';
export * from './intakeSites';
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import type { CookieOptions } from '../../browser/cookie';
import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy';
export declare const OLD_SESSION_COOKIE_NAME = "_dd";

@@ -11,2 +11,2 @@ export declare const OLD_RUM_COOKIE_NAME = "_dd_r";

*/
export declare function tryOldCookiesMigration(options: CookieOptions): void;
export declare function tryOldCookiesMigration(cookieStoreStrategy: SessionStoreStrategy): void;
import { getCookie } from '../../browser/cookie';
import { SESSION_COOKIE_NAME, persistSessionCookie } from './sessionCookieStore';
import { SESSION_STORE_KEY } from './storeStrategies/sessionStoreStrategy';
import { expandSessionState, isSessionInExpiredState } from './sessionState';
export var OLD_SESSION_COOKIE_NAME = '_dd';

@@ -13,8 +14,8 @@ export var OLD_RUM_COOKIE_NAME = '_dd_r';

*/
export function tryOldCookiesMigration(options) {
var sessionString = getCookie(SESSION_COOKIE_NAME);
var oldSessionId = getCookie(OLD_SESSION_COOKIE_NAME);
var oldRumType = getCookie(OLD_RUM_COOKIE_NAME);
var oldLogsType = getCookie(OLD_LOGS_COOKIE_NAME);
export function tryOldCookiesMigration(cookieStoreStrategy) {
var sessionString = getCookie(SESSION_STORE_KEY);
if (!sessionString) {
var oldSessionId = getCookie(OLD_SESSION_COOKIE_NAME);
var oldRumType = getCookie(OLD_RUM_COOKIE_NAME);
var oldLogsType = getCookie(OLD_LOGS_COOKIE_NAME);
var session = {};

@@ -30,5 +31,8 @@ if (oldSessionId) {

}
persistSessionCookie(session, options);
if (!isSessionInExpiredState(session)) {
expandSessionState(session);
cookieStoreStrategy.persistSession(session);
}
}
}
//# sourceMappingURL=oldCookiesMigration.js.map

@@ -1,5 +0,5 @@

import type { CookieOptions } from '../../browser/cookie';
import type { Observable } from '../../tools/observable';
import type { Context } from '../../tools/serialisation/context';
import type { RelativeTime } from '../../tools/utils/timeUtils';
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy';
export interface SessionManager<TrackingType extends string> {

@@ -16,3 +16,3 @@ findActiveSession: (startTime?: RelativeTime) => SessionContext<TrackingType> | undefined;

export declare const VISIBILITY_CHECK_DELAY: number;
export declare function startSessionManager<TrackingType extends string>(options: CookieOptions, productKey: string, computeSessionState: (rawTrackingType?: string) => {
export declare function startSessionManager<TrackingType extends string>(sessionStoreStrategyType: SessionStoreStrategyType, productKey: string, computeSessionState: (rawTrackingType?: string) => {
trackingType: TrackingType;

@@ -19,0 +19,0 @@ isTracked: boolean;

@@ -5,11 +5,9 @@ import { ValueHistory } from '../../tools/valueHistory';

import { clearInterval, setInterval } from '../../tools/timer';
import { tryOldCookiesMigration } from './oldCookiesMigration';
import { SESSION_TIME_OUT_DELAY } from './sessionConstants';
import { startSessionStore } from './sessionStore';
import { SESSION_TIME_OUT_DELAY } from './sessionConstants';
export var VISIBILITY_CHECK_DELAY = ONE_MINUTE;
var SESSION_CONTEXT_TIMEOUT_DELAY = SESSION_TIME_OUT_DELAY;
var stopCallbacks = [];
export function startSessionManager(options, productKey, computeSessionState) {
tryOldCookiesMigration(options);
var sessionStore = startSessionStore(options, productKey, computeSessionState);
export function startSessionManager(sessionStoreStrategyType, productKey, computeSessionState) {
var sessionStore = startSessionStore(sessionStoreStrategyType, productKey, computeSessionState);
stopCallbacks.push(function () { return sessionStore.stop(); });

@@ -16,0 +14,0 @@ var sessionContextHistory = new ValueHistory(SESSION_CONTEXT_TIMEOUT_DELAY);

@@ -1,3 +0,5 @@

import type { CookieOptions } from '../../browser/cookie';
import { Observable } from '../../tools/observable';
import type { InitConfiguration } from '../configuration';
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy';
import type { SessionState } from './sessionState';
export interface SessionStore {

@@ -12,10 +14,14 @@ expandOrRenewSession: () => void;

}
export interface SessionState {
id?: string;
created?: string;
expire?: string;
lock?: string;
[key: string]: string | undefined;
}
/**
* Every second, the storage will be polled to check for any change that can occur
* to the session state in another browser tab, or another window.
* This value has been determined from our previous cookie-only implementation.
*/
export declare const STORAGE_POLL_DELAY = 1000;
/**
* Checks if cookies are available as the preferred storage
* Else, checks if LocalStorage is allowed and available
*/
export declare function selectSessionStoreStrategyType(initConfiguration: InitConfiguration): SessionStoreStrategyType | undefined;
/**
* Different session concepts:

@@ -26,5 +32,5 @@ * - tracked, the session has an id and is updated along the user navigation

*/
export declare function startSessionStore<TrackingType extends string>(options: CookieOptions, productKey: string, computeSessionState: (rawTrackingType?: string) => {
export declare function startSessionStore<TrackingType extends string>(sessionStoreStrategyType: SessionStoreStrategyType, productKey: string, computeSessionState: (rawTrackingType?: string) => {
trackingType: TrackingType;
isTracked: boolean;
}): SessionStore;

@@ -1,10 +0,28 @@

import { COOKIE_ACCESS_DELAY } from '../../browser/cookie';
import { clearInterval, setInterval } from '../../tools/timer';
import { Observable } from '../../tools/observable';
import { dateNow } from '../../tools/utils/timeUtils';
import { ONE_SECOND, dateNow } from '../../tools/utils/timeUtils';
import { throttle } from '../../tools/utils/functionUtils';
import { generateUUID } from '../../tools/utils/stringUtils';
import { SESSION_TIME_OUT_DELAY } from './sessionConstants';
import { deleteSessionCookie, retrieveSessionCookie, withCookieLockAccess } from './sessionCookieStore';
import { selectCookieStrategy, initCookieStrategy } from './storeStrategies/sessionInCookie';
import { initLocalStorageStrategy, selectLocalStorageStrategy } from './storeStrategies/sessionInLocalStorage';
import { processSessionStoreOperations } from './sessionStoreOperations';
/**
* Every second, the storage will be polled to check for any change that can occur
* to the session state in another browser tab, or another window.
* This value has been determined from our previous cookie-only implementation.
*/
export var STORAGE_POLL_DELAY = ONE_SECOND;
/**
* Checks if cookies are available as the preferred storage
* Else, checks if LocalStorage is allowed and available
*/
export function selectSessionStoreStrategyType(initConfiguration) {
var sessionStoreStrategyType = selectCookieStrategy(initConfiguration);
if (!sessionStoreStrategyType && initConfiguration.allowFallbackToLocalStorage) {
sessionStoreStrategyType = selectLocalStorageStrategy();
}
return sessionStoreStrategyType;
}
/**
* Different session concepts:

@@ -15,62 +33,63 @@ * - tracked, the session has an id and is updated along the user navigation

*/
export function startSessionStore(options, productKey, computeSessionState) {
export function startSessionStore(sessionStoreStrategyType, productKey, computeSessionState) {
var renewObservable = new Observable();
var expireObservable = new Observable();
var watchSessionTimeoutId = setInterval(watchSession, COOKIE_ACCESS_DELAY);
var sessionStoreStrategy = sessionStoreStrategyType.type === 'Cookie'
? initCookieStrategy(sessionStoreStrategyType.cookieOptions)
: initLocalStorageStrategy();
var clearSession = sessionStoreStrategy.clearSession, retrieveSession = sessionStoreStrategy.retrieveSession;
var watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY);
var sessionCache = retrieveActiveSession();
function expandOrRenewSession() {
var isTracked;
withCookieLockAccess({
options: options,
process: function (cookieSession) {
var synchronizedSession = synchronizeSession(cookieSession);
isTracked = expandOrRenewCookie(synchronizedSession);
processSessionStoreOperations({
process: function (sessionState) {
var synchronizedSession = synchronizeSession(sessionState);
isTracked = expandOrRenewSessionState(synchronizedSession);
return synchronizedSession;
},
after: function (cookieSession) {
after: function (sessionState) {
if (isTracked && !hasSessionInCache()) {
renewSessionInCache(cookieSession);
renewSessionInCache(sessionState);
}
sessionCache = cookieSession;
sessionCache = sessionState;
},
});
}, sessionStoreStrategy);
}
function expandSession() {
withCookieLockAccess({
options: options,
process: function (cookieSession) { return (hasSessionInCache() ? synchronizeSession(cookieSession) : undefined); },
});
processSessionStoreOperations({
process: function (sessionState) { return (hasSessionInCache() ? synchronizeSession(sessionState) : undefined); },
}, sessionStoreStrategy);
}
/**
* allows two behaviors:
* - if the session is active, synchronize the session cache without updating the session cookie
* - if the session is not active, clear the session cookie and expire the session cache
* - if the session is active, synchronize the session cache without updating the session store
* - if the session is not active, clear the session store and expire the session cache
*/
function watchSession() {
withCookieLockAccess({
options: options,
process: function (cookieSession) { return (!isActiveSession(cookieSession) ? {} : undefined); },
processSessionStoreOperations({
process: function (sessionState) { return (!isActiveSession(sessionState) ? {} : undefined); },
after: synchronizeSession,
});
}, sessionStoreStrategy);
}
function synchronizeSession(cookieSession) {
if (!isActiveSession(cookieSession)) {
cookieSession = {};
function synchronizeSession(sessionState) {
if (!isActiveSession(sessionState)) {
sessionState = {};
}
if (hasSessionInCache()) {
if (isSessionInCacheOutdated(cookieSession)) {
if (isSessionInCacheOutdated(sessionState)) {
expireSessionInCache();
}
else {
sessionCache = cookieSession;
sessionCache = sessionState;
}
}
return cookieSession;
return sessionState;
}
function expandOrRenewCookie(cookieSession) {
var _a = computeSessionState(cookieSession[productKey]), trackingType = _a.trackingType, isTracked = _a.isTracked;
cookieSession[productKey] = trackingType;
if (isTracked && !cookieSession.id) {
cookieSession.id = generateUUID();
cookieSession.created = String(dateNow());
function expandOrRenewSessionState(sessionState) {
var _a = computeSessionState(sessionState[productKey]), trackingType = _a.trackingType, isTracked = _a.isTracked;
sessionState[productKey] = trackingType;
if (isTracked && !sessionState.id) {
sessionState.id = generateUUID();
sessionState.created = String(dateNow());
}

@@ -82,4 +101,4 @@ return isTracked;

}
function isSessionInCacheOutdated(cookieSession) {
return sessionCache.id !== cookieSession.id || sessionCache[productKey] !== cookieSession[productKey];
function isSessionInCacheOutdated(sessionState) {
return sessionCache.id !== sessionState.id || sessionCache[productKey] !== sessionState[productKey];
}

@@ -90,8 +109,8 @@ function expireSessionInCache() {

}
function renewSessionInCache(cookieSession) {
sessionCache = cookieSession;
function renewSessionInCache(sessionState) {
sessionCache = sessionState;
renewObservable.notify();
}
function retrieveActiveSession() {
var session = retrieveSessionCookie();
var session = retrieveSession();
if (isActiveSession(session)) {

@@ -102,10 +121,10 @@ return session;

}
function isActiveSession(session) {
function isActiveSession(sessionState) {
// created and expire can be undefined for versions which was not storing them
// these checks could be removed when older versions will not be available/live anymore
return ((session.created === undefined || dateNow() - Number(session.created) < SESSION_TIME_OUT_DELAY) &&
(session.expire === undefined || dateNow() < Number(session.expire)));
return ((sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) &&
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire)));
}
return {
expandOrRenewSession: throttle(expandOrRenewSession, COOKIE_ACCESS_DELAY).throttled,
expandOrRenewSession: throttle(expandOrRenewSession, STORAGE_POLL_DELAY).throttled,
expandSession: expandSession,

@@ -116,3 +135,3 @@ getSession: function () { return sessionCache; },

expire: function () {
deleteSessionCookie(options);
clearSession();
synchronizeSession({});

@@ -119,0 +138,0 @@ },

@@ -44,2 +44,3 @@ import type { Context } from '../../tools/serialisation/context';

session_replay_sample_rate?: number | undefined;
start_session_replay_recording_manually?: boolean | undefined;
use_proxy?: boolean | undefined;

@@ -46,0 +47,0 @@ use_before_send?: boolean | undefined;

@@ -18,2 +18,4 @@ import { ConsoleApiName } from '../../tools/display';

'https://www.datad0g-browser-agent.com',
'https://d3uc069fcn7uxw.cloudfront.net',
'https://d20xtzwzcl0ceb.cloudfront.net',
'http://localhost',

@@ -49,3 +51,3 @@ '<anonymous>',

service: telemetryService,
version: "4.42.2",
version: "4.43.0",
source: 'browser',

@@ -52,0 +54,0 @@ _dd: {

@@ -115,2 +115,6 @@ /**

/**
* Whether the session replay start is handled manually
*/
start_session_replay_recording_manually?: boolean;
/**
* Whether a proxy configured is used

@@ -117,0 +121,0 @@ */

@@ -1,2 +0,2 @@

export { Configuration, InitConfiguration, buildCookieOptions, validateAndBuildConfiguration, DefaultPrivacyLevel, EndpointBuilder, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';
export { Configuration, InitConfiguration, validateAndBuildConfiguration, DefaultPrivacyLevel, EndpointBuilder, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';
export { isExperimentalFeatureEnabled, addExperimentalFeatures, resetExperimentalFeatures, getExperimentalFeatures, ExperimentalFeature, } from './tools/experimentalFeatures';

@@ -29,3 +29,3 @@ export { trackRuntimeError } from './domain/error/trackRuntimeError';

export { Context, ContextArray, ContextValue } from './tools/serialisation/context';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie } from './browser/cookie';
export { initXhrObservable, XhrCompleteContext, XhrStartContext } from './browser/xhrObservable';

@@ -43,3 +43,4 @@ export { initFetchObservable, FetchResolveContext, FetchStartContext, FetchContext } from './browser/fetchObservable';

export { readBytesFromStream } from './tools/readBytesFromStream';
export { SESSION_COOKIE_NAME } from './domain/session/sessionCookieStore';
export { STORAGE_POLL_DELAY } from './domain/session/sessionStore';
export { SESSION_STORE_KEY } from './domain/session/storeStrategies/sessionStoreStrategy';
export { willSyntheticsInjectRum, getSyntheticsTestId, getSyntheticsResultId, } from './domain/synthetics/syntheticsWorkerValues';

@@ -46,0 +47,0 @@ export { User, checkUser, sanitizeUser } from './domain/user';

@@ -1,2 +0,2 @@

export { buildCookieOptions, validateAndBuildConfiguration, DefaultPrivacyLevel, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';
export { validateAndBuildConfiguration, DefaultPrivacyLevel, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';
export { isExperimentalFeatureEnabled, addExperimentalFeatures, resetExperimentalFeatures, getExperimentalFeatures, ExperimentalFeature, } from './tools/experimentalFeatures';

@@ -30,3 +30,3 @@ export { trackRuntimeError } from './domain/error/trackRuntimeError';

export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie } from './browser/cookie';
export { initXhrObservable } from './browser/xhrObservable';

@@ -44,3 +44,4 @@ export { initFetchObservable } from './browser/fetchObservable';

export { readBytesFromStream } from './tools/readBytesFromStream';
export { SESSION_COOKIE_NAME } from './domain/session/sessionCookieStore';
export { STORAGE_POLL_DELAY } from './domain/session/sessionStore';
export { SESSION_STORE_KEY } from './domain/session/storeStrategies/sessionStoreStrategy';
export { willSyntheticsInjectRum, getSyntheticsTestId, getSyntheticsResultId, } from './domain/synthetics/syntheticsWorkerValues';

@@ -47,0 +48,0 @@ export { checkUser, sanitizeUser } from './domain/user';

@@ -14,3 +14,5 @@ /**

RESOURCE_PAGE_STATES = "resource_page_states",
COLLECT_FLUSH_REASON = "collect_flush_reason"
PAGE_STATES = "page_states",
COLLECT_FLUSH_REASON = "collect_flush_reason",
NO_RESOURCE_DURATION_FROZEN_STATE = "no_resource_duration_frozen_state"
}

@@ -17,0 +19,0 @@ export declare function addExperimentalFeatures(enabledFeatures: ExperimentalFeature[]): void;

@@ -18,3 +18,5 @@ /**

ExperimentalFeature["RESOURCE_PAGE_STATES"] = "resource_page_states";
ExperimentalFeature["PAGE_STATES"] = "page_states";
ExperimentalFeature["COLLECT_FLUSH_REASON"] = "collect_flush_reason";
ExperimentalFeature["NO_RESOURCE_DURATION_FROZEN_STATE"] = "no_resource_duration_frozen_state";
})(ExperimentalFeature || (ExperimentalFeature = {}));

@@ -21,0 +23,0 @@ var enabledExperimentalFeatures = new Set();

@@ -1,2 +0,2 @@

import type { RelativeTime } from './utils/timeUtils';
import type { Duration, RelativeTime } from './utils/timeUtils';
export interface ValueHistoryEntry<T> {

@@ -16,5 +16,6 @@ startTime: RelativeTime;

private expireDelay;
private maxEntries?;
private entries;
private clearOldValuesInterval;
constructor(expireDelay: number);
constructor(expireDelay: number, maxEntries?: number | undefined);
/**

@@ -36,6 +37,7 @@ * Add a value to the history associated with a start time. Returns a reference to this newly

/**
* Return all values that were active during `startTime`, or all currently active values if no
* `startTime` is provided.
* Return all values with an active period overlapping with the duration,
* or all values that were active during `startTime` if no duration is provided,
* or all currently active values if no `startTime` is provided.
*/
findAll(startTime?: RelativeTime): Value[];
findAll(startTime?: RelativeTime, duration?: Duration): Value[];
/**

@@ -42,0 +44,0 @@ * Remove all entries from this collection.

import { setInterval, clearInterval } from './timer';
import { relativeNow, ONE_MINUTE } from './utils/timeUtils';
import { addDuration, relativeNow, ONE_MINUTE } from './utils/timeUtils';
var END_OF_TIMES = Infinity;

@@ -10,5 +10,6 @@ export var CLEAR_OLD_VALUES_INTERVAL = ONE_MINUTE;

var ValueHistory = /** @class */ (function () {
function ValueHistory(expireDelay) {
function ValueHistory(expireDelay, maxEntries) {
var _this = this;
this.expireDelay = expireDelay;
this.maxEntries = maxEntries;
this.entries = [];

@@ -37,2 +38,5 @@ this.clearOldValuesInterval = setInterval(function () { return _this.clearOldValues(); }, CLEAR_OLD_VALUES_INTERVAL);

};
if (this.maxEntries && this.entries.length >= this.maxEntries) {
this.entries.pop();
}
this.entries.unshift(entry);

@@ -68,9 +72,12 @@ return entry;

/**
* Return all values that were active during `startTime`, or all currently active values if no
* `startTime` is provided.
* Return all values with an active period overlapping with the duration,
* or all values that were active during `startTime` if no duration is provided,
* or all currently active values if no `startTime` is provided.
*/
ValueHistory.prototype.findAll = function (startTime) {
ValueHistory.prototype.findAll = function (startTime, duration) {
if (startTime === void 0) { startTime = END_OF_TIMES; }
if (duration === void 0) { duration = 0; }
var endTime = addDuration(startTime, duration);
return this.entries
.filter(function (entry) { return entry.startTime <= startTime && startTime <= entry.endTime; })
.filter(function (entry) { return entry.startTime <= endTime && startTime <= entry.endTime; })
.map(function (entry) { return entry.value; });

@@ -77,0 +84,0 @@ };

{
"name": "@datadog/browser-core",
"version": "4.42.2",
"version": "4.43.0",
"license": "Apache-2.0",

@@ -23,3 +23,3 @@ "main": "cjs/index.js",

},
"gitHead": "4c15587221b8f3c0c111500d9b65b679f4cf05b0"
"gitHead": "27baf6471a3e48028c52af9c6282e00662687cc2"
}

@@ -5,4 +5,2 @@ import { display } from '../tools/display'

export const COOKIE_ACCESS_DELAY = ONE_SECOND
export interface CookieOptions {

@@ -9,0 +7,0 @@ secure?: boolean

@@ -1,3 +0,1 @@

import type { CookieOptions } from '../../browser/cookie'
import { getCurrentSite } from '../../browser/cookie'
import { catchUserErrors } from '../../tools/catchUserErrors'

@@ -13,2 +11,4 @@ import { display } from '../../tools/display'

import { assign } from '../../tools/utils/polyfills'
import { selectSessionStoreStrategyType } from '../session/sessionStore'
import type { SessionStoreStrategyType } from '../session/storeStrategies/sessionStoreStrategy'
import type { TransportConfiguration } from './transportConfiguration'

@@ -56,2 +56,5 @@ import { computeTransportConfiguration } from './transportConfiguration'

// alternate storage option
allowFallbackToLocalStorage?: boolean | undefined
// internal options

@@ -78,3 +81,3 @@ enableExperimentalFeatures?: string[] | undefined

beforeSend: GenericBeforeSendCallback | undefined
cookieOptions: CookieOptions
sessionStoreStrategyType: SessionStoreStrategyType | undefined
sessionSampleRate: number

@@ -135,3 +138,3 @@ telemetrySampleRate: number

initConfiguration.beforeSend && catchUserErrors(initConfiguration.beforeSend, 'beforeSend threw an error:'),
cookieOptions: buildCookieOptions(initConfiguration),
sessionStoreStrategyType: selectSessionStoreStrategyType(initConfiguration),
sessionSampleRate: sessionSampleRate ?? 100,

@@ -168,34 +171,18 @@ telemetrySampleRate: initConfiguration.telemetrySampleRate ?? 20,

export function buildCookieOptions(initConfiguration: InitConfiguration) {
const cookieOptions: CookieOptions = {}
cookieOptions.secure = mustUseSecureCookie(initConfiguration)
cookieOptions.crossSite = !!initConfiguration.useCrossSiteSessionCookie
if (initConfiguration.trackSessionAcrossSubdomains) {
cookieOptions.domain = getCurrentSite()
}
return cookieOptions
}
function mustUseSecureCookie(initConfiguration: InitConfiguration) {
return !!initConfiguration.useSecureSessionCookie || !!initConfiguration.useCrossSiteSessionCookie
}
export function serializeConfiguration(configuration: InitConfiguration): Partial<RawTelemetryConfiguration> {
const proxy = configuration.proxy ?? configuration.proxyUrl
export function serializeConfiguration(initConfiguration: InitConfiguration): Partial<RawTelemetryConfiguration> {
const proxy = initConfiguration.proxy ?? initConfiguration.proxyUrl
return {
session_sample_rate: configuration.sessionSampleRate ?? configuration.sampleRate,
telemetry_sample_rate: configuration.telemetrySampleRate,
telemetry_configuration_sample_rate: configuration.telemetryConfigurationSampleRate,
use_before_send: !!configuration.beforeSend,
use_cross_site_session_cookie: configuration.useCrossSiteSessionCookie,
use_secure_session_cookie: configuration.useSecureSessionCookie,
session_sample_rate: initConfiguration.sessionSampleRate ?? initConfiguration.sampleRate,
telemetry_sample_rate: initConfiguration.telemetrySampleRate,
telemetry_configuration_sample_rate: initConfiguration.telemetryConfigurationSampleRate,
use_before_send: !!initConfiguration.beforeSend,
use_cross_site_session_cookie: initConfiguration.useCrossSiteSessionCookie,
use_secure_session_cookie: initConfiguration.useSecureSessionCookie,
use_proxy: proxy !== undefined ? !!proxy : undefined,
silent_multiple_init: configuration.silentMultipleInit,
track_session_across_subdomains: configuration.trackSessionAcrossSubdomains,
track_resources: configuration.trackResources,
track_long_task: configuration.trackLongTasks,
silent_multiple_init: initConfiguration.silentMultipleInit,
track_session_across_subdomains: initConfiguration.trackSessionAcrossSubdomains,
track_resources: initConfiguration.trackResources,
track_long_task: initConfiguration.trackLongTasks,
allow_fallback_to_local_storage: !!initConfiguration.allowFallbackToLocalStorage,
}
}
export {
Configuration,
InitConfiguration,
buildCookieOptions,
DefaultPrivacyLevel,

@@ -6,0 +5,0 @@ validateAndBuildConfiguration,

@@ -1,5 +0,6 @@

import type { CookieOptions } from '../../browser/cookie'
import { getCookie } from '../../browser/cookie'
import type { SessionState } from './sessionStore'
import { SESSION_COOKIE_NAME, persistSessionCookie } from './sessionCookieStore'
import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy'
import { SESSION_STORE_KEY } from './storeStrategies/sessionStoreStrategy'
import type { SessionState } from './sessionState'
import { expandSessionState, isSessionInExpiredState } from './sessionState'

@@ -18,9 +19,10 @@ export const OLD_SESSION_COOKIE_NAME = '_dd'

*/
export function tryOldCookiesMigration(options: CookieOptions) {
const sessionString = getCookie(SESSION_COOKIE_NAME)
const oldSessionId = getCookie(OLD_SESSION_COOKIE_NAME)
const oldRumType = getCookie(OLD_RUM_COOKIE_NAME)
const oldLogsType = getCookie(OLD_LOGS_COOKIE_NAME)
export function tryOldCookiesMigration(cookieStoreStrategy: SessionStoreStrategy) {
const sessionString = getCookie(SESSION_STORE_KEY)
if (!sessionString) {
const oldSessionId = getCookie(OLD_SESSION_COOKIE_NAME)
const oldRumType = getCookie(OLD_RUM_COOKIE_NAME)
const oldLogsType = getCookie(OLD_LOGS_COOKIE_NAME)
const session: SessionState = {}
if (oldSessionId) {

@@ -35,4 +37,8 @@ session.id = oldSessionId

}
persistSessionCookie(session, options)
if (!isSessionInExpiredState(session)) {
expandSessionState(session)
cookieStoreStrategy.persistSession(session)
}
}
}

@@ -1,2 +0,1 @@

import type { CookieOptions } from '../../browser/cookie'
import type { Observable } from '../../tools/observable'

@@ -9,5 +8,5 @@ import type { Context } from '../../tools/serialisation/context'

import { clearInterval, setInterval } from '../../tools/timer'
import { tryOldCookiesMigration } from './oldCookiesMigration'
import { SESSION_TIME_OUT_DELAY } from './sessionConstants'
import { startSessionStore } from './sessionStore'
import { SESSION_TIME_OUT_DELAY } from './sessionConstants'
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy'

@@ -31,8 +30,7 @@ export interface SessionManager<TrackingType extends string> {

export function startSessionManager<TrackingType extends string>(
options: CookieOptions,
sessionStoreStrategyType: SessionStoreStrategyType,
productKey: string,
computeSessionState: (rawTrackingType?: string) => { trackingType: TrackingType; isTracked: boolean }
): SessionManager<TrackingType> {
tryOldCookiesMigration(options)
const sessionStore = startSessionStore(options, productKey, computeSessionState)
const sessionStore = startSessionStore(sessionStoreStrategyType, productKey, computeSessionState)
stopCallbacks.push(() => sessionStore.stop())

@@ -39,0 +37,0 @@

@@ -1,10 +0,13 @@

import type { CookieOptions } from '../../browser/cookie'
import { COOKIE_ACCESS_DELAY } from '../../browser/cookie'
import { clearInterval, setInterval } from '../../tools/timer'
import { Observable } from '../../tools/observable'
import { dateNow } from '../../tools/utils/timeUtils'
import { ONE_SECOND, dateNow } from '../../tools/utils/timeUtils'
import { throttle } from '../../tools/utils/functionUtils'
import { generateUUID } from '../../tools/utils/stringUtils'
import type { InitConfiguration } from '../configuration'
import { SESSION_TIME_OUT_DELAY } from './sessionConstants'
import { deleteSessionCookie, retrieveSessionCookie, withCookieLockAccess } from './sessionCookieStore'
import { selectCookieStrategy, initCookieStrategy } from './storeStrategies/sessionInCookie'
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy'
import type { SessionState } from './sessionState'
import { initLocalStorageStrategy, selectLocalStorageStrategy } from './storeStrategies/sessionInLocalStorage'
import { processSessionStoreOperations } from './sessionStoreOperations'

@@ -21,9 +24,21 @@ export interface SessionStore {

export interface SessionState {
id?: string
created?: string
expire?: string
lock?: string
/**
* Every second, the storage will be polled to check for any change that can occur
* to the session state in another browser tab, or another window.
* This value has been determined from our previous cookie-only implementation.
*/
export const STORAGE_POLL_DELAY = ONE_SECOND
[key: string]: string | undefined
/**
* Checks if cookies are available as the preferred storage
* Else, checks if LocalStorage is allowed and available
*/
export function selectSessionStoreStrategyType(
initConfiguration: InitConfiguration
): SessionStoreStrategyType | undefined {
let sessionStoreStrategyType = selectCookieStrategy(initConfiguration)
if (!sessionStoreStrategyType && initConfiguration.allowFallbackToLocalStorage) {
sessionStoreStrategyType = selectLocalStorageStrategy()
}
return sessionStoreStrategyType
}

@@ -38,3 +53,3 @@

export function startSessionStore<TrackingType extends string>(
options: CookieOptions,
sessionStoreStrategyType: SessionStoreStrategyType,
productKey: string,

@@ -46,3 +61,9 @@ computeSessionState: (rawTrackingType?: string) => { trackingType: TrackingType; isTracked: boolean }

const watchSessionTimeoutId = setInterval(watchSession, COOKIE_ACCESS_DELAY)
const sessionStoreStrategy =
sessionStoreStrategyType.type === 'Cookie'
? initCookieStrategy(sessionStoreStrategyType.cookieOptions)
: initLocalStorageStrategy()
const { clearSession, retrieveSession } = sessionStoreStrategy
const watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY)
let sessionCache: SessionState = retrieveActiveSession()

@@ -52,23 +73,27 @@

let isTracked: boolean
withCookieLockAccess({
options,
process: (cookieSession) => {
const synchronizedSession = synchronizeSession(cookieSession)
isTracked = expandOrRenewCookie(synchronizedSession)
return synchronizedSession
processSessionStoreOperations(
{
process: (sessionState) => {
const synchronizedSession = synchronizeSession(sessionState)
isTracked = expandOrRenewSessionState(synchronizedSession)
return synchronizedSession
},
after: (sessionState) => {
if (isTracked && !hasSessionInCache()) {
renewSessionInCache(sessionState)
}
sessionCache = sessionState
},
},
after: (cookieSession) => {
if (isTracked && !hasSessionInCache()) {
renewSessionInCache(cookieSession)
}
sessionCache = cookieSession
},
})
sessionStoreStrategy
)
}
function expandSession() {
withCookieLockAccess({
options,
process: (cookieSession) => (hasSessionInCache() ? synchronizeSession(cookieSession) : undefined),
})
processSessionStoreOperations(
{
process: (sessionState) => (hasSessionInCache() ? synchronizeSession(sessionState) : undefined),
},
sessionStoreStrategy
)
}

@@ -78,33 +103,35 @@

* allows two behaviors:
* - if the session is active, synchronize the session cache without updating the session cookie
* - if the session is not active, clear the session cookie and expire the session cache
* - if the session is active, synchronize the session cache without updating the session store
* - if the session is not active, clear the session store and expire the session cache
*/
function watchSession() {
withCookieLockAccess({
options,
process: (cookieSession) => (!isActiveSession(cookieSession) ? {} : undefined),
after: synchronizeSession,
})
processSessionStoreOperations(
{
process: (sessionState) => (!isActiveSession(sessionState) ? {} : undefined),
after: synchronizeSession,
},
sessionStoreStrategy
)
}
function synchronizeSession(cookieSession: SessionState) {
if (!isActiveSession(cookieSession)) {
cookieSession = {}
function synchronizeSession(sessionState: SessionState) {
if (!isActiveSession(sessionState)) {
sessionState = {}
}
if (hasSessionInCache()) {
if (isSessionInCacheOutdated(cookieSession)) {
if (isSessionInCacheOutdated(sessionState)) {
expireSessionInCache()
} else {
sessionCache = cookieSession
sessionCache = sessionState
}
}
return cookieSession
return sessionState
}
function expandOrRenewCookie(cookieSession: SessionState) {
const { trackingType, isTracked } = computeSessionState(cookieSession[productKey])
cookieSession[productKey] = trackingType
if (isTracked && !cookieSession.id) {
cookieSession.id = generateUUID()
cookieSession.created = String(dateNow())
function expandOrRenewSessionState(sessionState: SessionState) {
const { trackingType, isTracked } = computeSessionState(sessionState[productKey])
sessionState[productKey] = trackingType
if (isTracked && !sessionState.id) {
sessionState.id = generateUUID()
sessionState.created = String(dateNow())
}

@@ -118,4 +145,4 @@ return isTracked

function isSessionInCacheOutdated(cookieSession: SessionState) {
return sessionCache.id !== cookieSession.id || sessionCache[productKey] !== cookieSession[productKey]
function isSessionInCacheOutdated(sessionState: SessionState) {
return sessionCache.id !== sessionState.id || sessionCache[productKey] !== sessionState[productKey]
}

@@ -128,4 +155,4 @@

function renewSessionInCache(cookieSession: SessionState) {
sessionCache = cookieSession
function renewSessionInCache(sessionState: SessionState) {
sessionCache = sessionState
renewObservable.notify()

@@ -135,3 +162,3 @@ }

function retrieveActiveSession(): SessionState {
const session = retrieveSessionCookie()
const session = retrieveSession()
if (isActiveSession(session)) {

@@ -143,8 +170,8 @@ return session

function isActiveSession(session: SessionState) {
function isActiveSession(sessionState: SessionState) {
// created and expire can be undefined for versions which was not storing them
// these checks could be removed when older versions will not be available/live anymore
return (
(session.created === undefined || dateNow() - Number(session.created) < SESSION_TIME_OUT_DELAY) &&
(session.expire === undefined || dateNow() < Number(session.expire))
(sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) &&
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire))
)

@@ -154,3 +181,3 @@ }

return {
expandOrRenewSession: throttle(expandOrRenewSession, COOKIE_ACCESS_DELAY).throttled,
expandOrRenewSession: throttle(expandOrRenewSession, STORAGE_POLL_DELAY).throttled,
expandSession,

@@ -161,3 +188,3 @@ getSession: () => sessionCache,

expire: () => {
deleteSessionCookie(options)
clearSession()
synchronizeSession({})

@@ -164,0 +191,0 @@ },

@@ -28,2 +28,4 @@ import type { Context } from '../../tools/serialisation/context'

'https://www.datad0g-browser-agent.com',
'https://d3uc069fcn7uxw.cloudfront.net',
'https://d20xtzwzcl0ceb.cloudfront.net',
'http://localhost',

@@ -30,0 +32,0 @@ '<anonymous>',

@@ -117,2 +117,6 @@ /* eslint-disable */

/**
* Whether the session replay start is handled manually
*/
start_session_replay_recording_manually?: boolean
/**
* Whether a proxy configured is used

@@ -119,0 +123,0 @@ */

export {
Configuration,
InitConfiguration,
buildCookieOptions,
validateAndBuildConfiguration,

@@ -88,3 +87,3 @@ DefaultPrivacyLevel,

export { Context, ContextArray, ContextValue } from './tools/serialisation/context'
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie'
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie } from './browser/cookie'
export { initXhrObservable, XhrCompleteContext, XhrStartContext } from './browser/xhrObservable'

@@ -106,3 +105,4 @@ export { initFetchObservable, FetchResolveContext, FetchStartContext, FetchContext } from './browser/fetchObservable'

export { readBytesFromStream } from './tools/readBytesFromStream'
export { SESSION_COOKIE_NAME } from './domain/session/sessionCookieStore'
export { STORAGE_POLL_DELAY } from './domain/session/sessionStore'
export { SESSION_STORE_KEY } from './domain/session/storeStrategies/sessionStoreStrategy'
export {

@@ -109,0 +109,0 @@ willSyntheticsInjectRum,

@@ -17,3 +17,5 @@ /**

RESOURCE_PAGE_STATES = 'resource_page_states',
PAGE_STATES = 'page_states',
COLLECT_FLUSH_REASON = 'collect_flush_reason',
NO_RESOURCE_DURATION_FROZEN_STATE = 'no_resource_duration_frozen_state',
}

@@ -20,0 +22,0 @@

import { setInterval, clearInterval } from './timer'
import type { TimeoutId } from './timer'
import type { RelativeTime } from './utils/timeUtils'
import { relativeNow, ONE_MINUTE } from './utils/timeUtils'
import type { Duration, RelativeTime } from './utils/timeUtils'
import { addDuration, relativeNow, ONE_MINUTE } from './utils/timeUtils'

@@ -26,3 +26,3 @@ const END_OF_TIMES = Infinity as RelativeTime

constructor(private expireDelay: number) {
constructor(private expireDelay: number, private maxEntries?: number) {
this.clearOldValuesInterval = setInterval(() => this.clearOldValues(), CLEAR_OLD_VALUES_INTERVAL)

@@ -50,3 +50,9 @@ }

}
if (this.maxEntries && this.entries.length >= this.maxEntries) {
this.entries.pop()
}
this.entries.unshift(entry)
return entry

@@ -82,8 +88,10 @@ }

/**
* Return all values that were active during `startTime`, or all currently active values if no
* `startTime` is provided.
* Return all values with an active period overlapping with the duration,
* or all values that were active during `startTime` if no duration is provided,
* or all currently active values if no `startTime` is provided.
*/
findAll(startTime: RelativeTime = END_OF_TIMES): Value[] {
findAll(startTime: RelativeTime = END_OF_TIMES, duration = 0 as Duration): Value[] {
const endTime = addDuration(startTime, duration)
return this.entries
.filter((entry) => entry.startTime <= startTime && startTime <= entry.endTime)
.filter((entry) => entry.startTime <= endTime && startTime <= entry.endTime)
.map((entry) => entry.value)

@@ -90,0 +98,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc