Socket
Socket
Sign inDemoInstall

@datadog/browser-core

Package Overview
Dependencies
3
Maintainers
1
Versions
249
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.1 to 1.9.2

4

cjs/errorCollection.d.ts
import { Configuration } from './configuration';
import { Observable } from './observable';
import { RequestObservable } from './requestCollection';
import { RequestCompleteEvent } from './requestCollection';
import { StackTrace } from './tracekit';

@@ -49,2 +49,2 @@ export interface ErrorMessage {

export declare function toStackTraceString(stack: StackTrace): string;
export declare function trackNetworkError(configuration: Configuration, errorObservable: ErrorObservable, requestObservable: RequestObservable): void;
export declare function trackNetworkError(configuration: Configuration, errorObservable: ErrorObservable, requestObservable: Observable<RequestCompleteEvent>): void;

@@ -22,4 +22,4 @@ "use strict";

if (configuration.isCollectingError) {
var requestObservable = requestCollection_1.startRequestCollection();
trackNetworkError(configuration, errorObservable, requestObservable);
var _a = requestCollection_1.startRequestCollection(), requestCompleteObservable = _a[1];
trackNetworkError(configuration, errorObservable, requestCompleteObservable);
startConsoleTracking(errorObservable);

@@ -26,0 +26,0 @@ startRuntimeErrorTracking(errorObservable);

@@ -6,3 +6,3 @@ export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration } from './configuration';

export { Observable } from './observable';
export { RequestType, RequestDetails, startRequestCollection, RequestObservable } from './requestCollection';
export { RequestType, RequestCompleteEvent, RequestStartEvent, startRequestCollection, RequestObservables, } from './requestCollection';
export { startSessionManagement, SESSION_COOKIE_NAME, stopSessionManagement, } from './sessionManagement';

@@ -9,0 +9,0 @@ export { HttpRequest, Batch } from './transport';

@@ -6,3 +6,7 @@ import { Observable } from './observable';

}
export interface RequestDetails {
export interface RequestStartEvent {
requestId: number;
}
export interface RequestCompleteEvent {
requestId: number;
type: RequestType;

@@ -18,7 +22,7 @@ method: string;

}
export declare type RequestObservable = Observable<RequestDetails>;
export declare function startRequestCollection(): Observable<RequestDetails>;
export declare function trackXhr(observable: RequestObservable): void;
export declare function trackFetch(observable: RequestObservable): void;
export declare function isRejected(request: RequestDetails): boolean;
export declare function isServerError(request: RequestDetails): boolean;
export declare type RequestObservables = [Observable<RequestStartEvent>, Observable<RequestCompleteEvent>];
export declare function startRequestCollection(): RequestObservables;
export declare function trackXhr([requestStartObservable, requestCompleteObservable]: RequestObservables): void;
export declare function trackFetch([requestStartObservable, requestCompleteObservable]: RequestObservables): void;
export declare function isRejected(request: RequestCompleteEvent): boolean;
export declare function isServerError(request: RequestCompleteEvent): boolean;

@@ -14,13 +14,20 @@ "use strict";

})(RequestType = exports.RequestType || (exports.RequestType = {}));
var requestObservable;
var nextRequestId = 1;
function getNextRequestId() {
var result = nextRequestId;
nextRequestId += 1;
return result;
}
var requestObservablesSingleton;
function startRequestCollection() {
if (!requestObservable) {
requestObservable = new observable_1.Observable();
trackXhr(requestObservable);
trackFetch(requestObservable);
if (!requestObservablesSingleton) {
requestObservablesSingleton = [new observable_1.Observable(), new observable_1.Observable()];
trackXhr(requestObservablesSingleton);
trackFetch(requestObservablesSingleton);
}
return requestObservable;
return requestObservablesSingleton;
}
exports.startRequestCollection = startRequestCollection;
function trackXhr(observable) {
function trackXhr(_a) {
var requestStartObservable = _a[0], requestCompleteObservable = _a[1];
var originalOpen = XMLHttpRequest.prototype.open;

@@ -38,2 +45,6 @@ XMLHttpRequest.prototype.open = internalMonitoring_1.monitor(function (method, url) {

var startTime = performance.now();
var requestId = getNextRequestId();
requestStartObservable.notify({
requestId: requestId,
});
var hasBeenReported = false;

@@ -45,3 +56,4 @@ var reportXhr = function () {

hasBeenReported = true;
observable.notify({
requestCompleteObservable.notify({
requestId: requestId,
startTime: startTime,

@@ -71,3 +83,4 @@ duration: performance.now() - startTime,

exports.trackXhr = trackXhr;
function trackFetch(observable) {
function trackFetch(_a) {
var requestStartObservable = _a[0], requestCompleteObservable = _a[1];
if (!window.fetch) {

@@ -82,2 +95,6 @@ return;

var startTime = performance.now();
var requestId = getNextRequestId();
requestStartObservable.notify({
requestId: requestId,
});
var reportFetch = function (response) { return tslib_1.__awaiter(_this, void 0, void 0, function () {

@@ -92,5 +109,6 @@ var duration, url, stackTrace, text, e_1;

stackTrace = tracekit_1.computeStackTrace(response);
observable.notify({
requestCompleteObservable.notify({
duration: duration,
method: method,
requestId: requestId,
startTime: startTime,

@@ -119,5 +137,6 @@ url: url,

case 5:
observable.notify({
requestCompleteObservable.notify({
duration: duration,
method: method,
requestId: requestId,
startTime: startTime,

@@ -124,0 +143,0 @@ url: url,

import { CookieCache } from './cookie';
import { Observable } from './observable';
export declare const SESSION_COOKIE_NAME = "_dd_s";
export declare const EXPIRATION_DELAY: number;
export declare const SESSION_EXPIRATION_DELAY: number;
export declare const SESSION_TIME_OUT_DELAY: number;
export declare const VISIBILITY_CHECK_DELAY: number;
export interface Session<T> {

@@ -12,2 +14,4 @@ renewObservable: Observable<void>;

id?: string;
created?: string;
expire?: string;
[key: string]: string | undefined;

@@ -21,6 +25,6 @@ }

isTracked: boolean;
}): Session<Type>;
}, withNewSessionStrategy?: boolean): Session<Type>;
export declare function isValidSessionString(sessionString: string | undefined): sessionString is string;
export declare function persistSession(session: SessionState, cookie: CookieCache): void;
export declare function persistSession(session: SessionState, cookie: CookieCache, withNewSessionStrategy?: boolean): void;
export declare function stopSessionManagement(): void;
export declare function trackActivity(expandOrRenewSession: () => void): void;

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

var cookie_1 = require("./cookie");
var internalMonitoring_1 = require("./internalMonitoring");
var observable_1 = require("./observable");

@@ -10,13 +11,16 @@ var oldCookiesMigration_1 = require("./oldCookiesMigration");

exports.SESSION_COOKIE_NAME = '_dd_s';
exports.EXPIRATION_DELAY = 15 * utils.ONE_MINUTE;
exports.SESSION_EXPIRATION_DELAY = 15 * utils.ONE_MINUTE;
exports.SESSION_TIME_OUT_DELAY = 4 * utils.ONE_HOUR;
exports.VISIBILITY_CHECK_DELAY = utils.ONE_MINUTE;
/**
* Limit access to cookie to avoid performance issues
*/
function startSessionManagement(sessionTypeKey, computeSessionState) {
function startSessionManagement(sessionTypeKey, computeSessionState, withNewSessionStrategy) {
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; }
var sessionCookie = cookie_1.cacheCookieAccess(exports.SESSION_COOKIE_NAME);
oldCookiesMigration_1.tryOldCookiesMigration(sessionCookie);
var renewObservable = new observable_1.Observable();
var currentSessionId = retrieveSession(sessionCookie).id;
var currentSessionId = retrieveActiveSession(sessionCookie, withNewSessionStrategy).id;
var expandOrRenewSession = utils.throttle(function () {
var session = retrieveSession(sessionCookie);
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy);
var _a = computeSessionState(session[sessionTypeKey]), type = _a.type, isTracked = _a.isTracked;

@@ -26,5 +30,8 @@ session[sessionTypeKey] = type;

session.id = utils.generateUUID();
if (withNewSessionStrategy) {
session.created = String(Date.now());
}
}
// save changes and expand session duration
persistSession(session, sessionCookie);
persistSession(session, sessionCookie, withNewSessionStrategy);
// If the session id has changed, notify that the session has been renewed

@@ -36,10 +43,17 @@ if (isTracked && currentSessionId !== session.id) {

}, cookie_1.COOKIE_ACCESS_DELAY);
var expandSession = function () {
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy);
persistSession(session, sessionCookie, withNewSessionStrategy);
};
expandOrRenewSession();
trackActivity(expandOrRenewSession);
if (withNewSessionStrategy) {
trackVisibility(expandSession);
}
return {
getId: function () {
return retrieveSession(sessionCookie).id;
return retrieveActiveSession(sessionCookie, withNewSessionStrategy).id;
},
getType: function () {
return retrieveSession(sessionCookie)[sessionTypeKey];
return retrieveActiveSession(sessionCookie, withNewSessionStrategy)[sessionTypeKey];
},

@@ -57,2 +71,16 @@ renewObservable: renewObservable,

exports.isValidSessionString = isValidSessionString;
function retrieveActiveSession(sessionCookie, withNewSessionStrategy) {
var session = retrieveSession(sessionCookie);
if (!withNewSessionStrategy || isActiveSession(session)) {
return session;
}
clearSession(sessionCookie);
return {};
}
function isActiveSession(session) {
// 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 || Date.now() - Number(session.created) < exports.SESSION_TIME_OUT_DELAY) &&
(session.expire === undefined || Date.now() < Number(session.expire)));
}
function retrieveSession(sessionCookie) {

@@ -72,3 +100,11 @@ var sessionString = sessionCookie.get();

}
function persistSession(session, cookie) {
function persistSession(session, cookie, withNewSessionStrategy) {
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; }
if (utils.isEmptyObject(session)) {
clearSession(cookie);
return;
}
if (withNewSessionStrategy) {
session.expire = String(Date.now() + exports.SESSION_EXPIRATION_DELAY);
}
var cookieString = utils

@@ -81,19 +117,36 @@ .objectEntries(session)

.join(SESSION_ENTRY_SEPARATOR);
cookie.set(cookieString, exports.EXPIRATION_DELAY);
cookie.set(cookieString, exports.SESSION_EXPIRATION_DELAY);
}
exports.persistSession = persistSession;
function clearSession(cookie) {
cookie.set('', 0);
}
function stopSessionManagement() {
registeredActivityListeners.forEach(function (e) { return e(); });
registeredActivityListeners = [];
stopCallbacks.forEach(function (e) { return e(); });
stopCallbacks = [];
}
exports.stopSessionManagement = stopSessionManagement;
var registeredActivityListeners = [];
var stopCallbacks = [];
function trackActivity(expandOrRenewSession) {
var doExpandOrRenewSession = internalMonitoring_1.monitor(expandOrRenewSession);
var options = { capture: true, passive: true };
['click', 'touchstart', 'keydown', 'scroll'].forEach(function (event) {
document.addEventListener(event, expandOrRenewSession, options);
registeredActivityListeners.push(function () { return document.removeEventListener(event, expandOrRenewSession, options); });
[utils.DOM_EVENT.CLICK, utils.DOM_EVENT.TOUCH_START, utils.DOM_EVENT.KEY_DOWN, utils.DOM_EVENT.SCROLL].forEach(function (event) {
document.addEventListener(event, doExpandOrRenewSession, options);
stopCallbacks.push(function () { return document.removeEventListener(event, doExpandOrRenewSession, options); });
});
}
exports.trackActivity = trackActivity;
function trackVisibility(expandSession) {
var expandSessionWhenVisible = internalMonitoring_1.monitor(function () {
if (document.visibilityState === 'visible') {
expandSession();
}
});
var visibilityCheckInterval = window.setInterval(expandSessionWhenVisible, exports.VISIBILITY_CHECK_DELAY);
document.addEventListener(utils.DOM_EVENT.VISIBILITY_CHANGE, expandSessionWhenVisible);
stopCallbacks.push(function () {
clearInterval(visibilityCheckInterval);
document.removeEventListener(utils.DOM_EVENT.VISIBILITY_CHANGE, expandSessionWhenVisible);
});
}
//# sourceMappingURL=sessionManagement.js.map
import { Configuration } from './configuration';
import { Observable } from './observable';
import { RequestDetails } from './requestCollection';
import { RequestCompleteEvent, RequestObservables } from './requestCollection';
export declare const SPEC_ENDPOINTS: Partial<Configuration>;

@@ -11,6 +10,5 @@ export declare function isSafari(): boolean;

private requests;
private pendingFetch;
private whenAllCompleteFn;
constructor(observable: Observable<RequestDetails>);
whenAllComplete(onCompleteFn: (_: RequestDetails[]) => void): void;
constructor([requestStartObservable, requestCompleteObservable]: RequestObservables);
whenAllComplete(onCompleteFn: (_: RequestCompleteEvent[]) => void): void;
getStub(): FetchStub;

@@ -17,0 +15,0 @@ }

@@ -30,11 +30,15 @@ "use strict";

var FetchStubBuilder = /** @class */ (function () {
function FetchStubBuilder(observable) {
function FetchStubBuilder(_a) {
var _this = this;
var requestStartObservable = _a[0], requestCompleteObservable = _a[1];
this.requests = [];
this.pendingFetch = 0;
this.whenAllCompleteFn = utils_1.noop;
observable.subscribe(function (request) {
var pendingFetch = 0;
requestStartObservable.subscribe(function () {
pendingFetch += 1;
});
requestCompleteObservable.subscribe(function (request) {
_this.requests.push(request);
_this.pendingFetch -= 1;
if (_this.pendingFetch === 0) {
pendingFetch -= 1;
if (pendingFetch === 0) {
// ensure that AssertionError are not swallowed by promise context

@@ -53,3 +57,2 @@ setTimeout(function () {

return (function () {
_this.pendingFetch += 1;
var resolve;

@@ -56,0 +59,0 @@ var reject;

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

*/
window.addEventListener('beforeunload', internalMonitoring_1.monitor(function () {
window.addEventListener(utils_1.DOM_EVENT.BEFORE_UNLOAD, internalMonitoring_1.monitor(function () {
_this.beforeFlushOnUnloadHandlers.forEach(function (handler) { return handler(); });

@@ -163,3 +163,3 @@ }));

*/
document.addEventListener('visibilitychange', internalMonitoring_1.monitor(function () {
document.addEventListener(utils_1.DOM_EVENT.VISIBILITY_CHANGE, internalMonitoring_1.monitor(function () {
if (document.visibilityState === 'hidden') {

@@ -174,3 +174,3 @@ _this.flush();

*/
window.addEventListener('beforeunload', internalMonitoring_1.monitor(function () { return _this.flush(); }));
window.addEventListener(utils_1.DOM_EVENT.BEFORE_UNLOAD, internalMonitoring_1.monitor(function () { return _this.flush(); }));
}

@@ -177,0 +177,0 @@ };

@@ -5,4 +5,13 @@ export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

export declare const ONE_HOUR: number;
export declare const ONE_DAY: number;
export declare const ONE_KILO_BYTE = 1024;
export declare enum DOM_EVENT {
BEFORE_UNLOAD = "beforeunload",
CLICK = "click",
KEY_DOWN = "keydown",
LOAD = "load",
POP_STATE = "popstate",
SCROLL = "scroll",
TOUCH_START = "touchstart",
VISIBILITY_CHANGE = "visibilitychange"
}
export declare enum ResourceKind {

@@ -52,3 +61,5 @@ DOCUMENT = "document",

export declare function jsonStringify(value: unknown, replacer?: Array<string | number>, space?: string | number): string | undefined;
export declare function includes(candidate: unknown[], search: unknown): boolean;
export declare function includes(candidate: string, search: string): boolean;
export declare function includes<T>(candidate: T[], search: T): boolean;
export declare function find<T>(array: T[], predicate: (item: T, index: number, array: T[]) => unknown): T | undefined;
export declare function isPercentage(value: unknown): boolean;

@@ -72,2 +83,3 @@ export declare function isNumber(value: unknown): value is number;

}): unknown[][];
export declare function isEmptyObject(object: object): boolean;
export declare function getGlobalObject<T>(): T;

@@ -74,0 +86,0 @@ export declare function getLocationOrigin(): string;

@@ -6,4 +6,14 @@ "use strict";

exports.ONE_HOUR = 60 * exports.ONE_MINUTE;
exports.ONE_DAY = 24 * exports.ONE_HOUR;
exports.ONE_KILO_BYTE = 1024;
var DOM_EVENT;
(function (DOM_EVENT) {
DOM_EVENT["BEFORE_UNLOAD"] = "beforeunload";
DOM_EVENT["CLICK"] = "click";
DOM_EVENT["KEY_DOWN"] = "keydown";
DOM_EVENT["LOAD"] = "load";
DOM_EVENT["POP_STATE"] = "popstate";
DOM_EVENT["SCROLL"] = "scroll";
DOM_EVENT["TOUCH_START"] = "touchstart";
DOM_EVENT["VISIBILITY_CHANGE"] = "visibilitychange";
})(DOM_EVENT = exports.DOM_EVENT || (exports.DOM_EVENT = {}));
var ResourceKind;

@@ -154,5 +164,16 @@ (function (ResourceKind) {

function includes(candidate, search) {
// tslint:disable-next-line: no-unsafe-any
return candidate.indexOf(search) !== -1;
}
exports.includes = includes;
function find(array, predicate) {
for (var i = 0; i < array.length; i += 1) {
var item = array[i];
if (predicate(item, i, array)) {
return item;
}
}
return undefined;
}
exports.find = find;
function isPercentage(value) {

@@ -204,2 +225,6 @@ return isNumber(value) && value >= 0 && value <= 100;

exports.objectEntries = objectEntries;
function isEmptyObject(object) {
return Object.keys(object).length === 0;
}
exports.isEmptyObject = isEmptyObject;
function getGlobalObject() {

@@ -206,0 +231,0 @@ // tslint:disable-next-line: function-constructor no-function-constructor-with-string-args

import { Configuration } from './configuration';
import { Observable } from './observable';
import { RequestObservable } from './requestCollection';
import { RequestCompleteEvent } from './requestCollection';
import { StackTrace } from './tracekit';

@@ -49,2 +49,2 @@ export interface ErrorMessage {

export declare function toStackTraceString(stack: StackTrace): string;
export declare function trackNetworkError(configuration: Configuration, errorObservable: ErrorObservable, requestObservable: RequestObservable): void;
export declare function trackNetworkError(configuration: Configuration, errorObservable: ErrorObservable, requestObservable: Observable<RequestCompleteEvent>): void;

@@ -20,4 +20,4 @@ import { __spreadArrays } from "tslib";

if (configuration.isCollectingError) {
var requestObservable = startRequestCollection();
trackNetworkError(configuration, errorObservable, requestObservable);
var _a = startRequestCollection(), requestCompleteObservable = _a[1];
trackNetworkError(configuration, errorObservable, requestCompleteObservable);
startConsoleTracking(errorObservable);

@@ -24,0 +24,0 @@ startRuntimeErrorTracking(errorObservable);

@@ -6,3 +6,3 @@ export { DEFAULT_CONFIGURATION, Configuration, UserConfiguration } from './configuration';

export { Observable } from './observable';
export { RequestType, RequestDetails, startRequestCollection, RequestObservable } from './requestCollection';
export { RequestType, RequestCompleteEvent, RequestStartEvent, startRequestCollection, RequestObservables, } from './requestCollection';
export { startSessionManagement, SESSION_COOKIE_NAME, stopSessionManagement, } from './sessionManagement';

@@ -9,0 +9,0 @@ export { HttpRequest, Batch } from './transport';

@@ -6,3 +6,3 @@ export { DEFAULT_CONFIGURATION } from './configuration';

export { Observable } from './observable';
export { RequestType, startRequestCollection } from './requestCollection';
export { RequestType, startRequestCollection, } from './requestCollection';
export { startSessionManagement,

@@ -9,0 +9,0 @@ // Exposed for tests

@@ -6,3 +6,7 @@ import { Observable } from './observable';

}
export interface RequestDetails {
export interface RequestStartEvent {
requestId: number;
}
export interface RequestCompleteEvent {
requestId: number;
type: RequestType;

@@ -18,7 +22,7 @@ method: string;

}
export declare type RequestObservable = Observable<RequestDetails>;
export declare function startRequestCollection(): Observable<RequestDetails>;
export declare function trackXhr(observable: RequestObservable): void;
export declare function trackFetch(observable: RequestObservable): void;
export declare function isRejected(request: RequestDetails): boolean;
export declare function isServerError(request: RequestDetails): boolean;
export declare type RequestObservables = [Observable<RequestStartEvent>, Observable<RequestCompleteEvent>];
export declare function startRequestCollection(): RequestObservables;
export declare function trackXhr([requestStartObservable, requestCompleteObservable]: RequestObservables): void;
export declare function trackFetch([requestStartObservable, requestCompleteObservable]: RequestObservables): void;
export declare function isRejected(request: RequestCompleteEvent): boolean;
export declare function isServerError(request: RequestCompleteEvent): boolean;

@@ -12,12 +12,19 @@ import { __awaiter, __generator } from "tslib";

})(RequestType || (RequestType = {}));
var requestObservable;
var nextRequestId = 1;
function getNextRequestId() {
var result = nextRequestId;
nextRequestId += 1;
return result;
}
var requestObservablesSingleton;
export function startRequestCollection() {
if (!requestObservable) {
requestObservable = new Observable();
trackXhr(requestObservable);
trackFetch(requestObservable);
if (!requestObservablesSingleton) {
requestObservablesSingleton = [new Observable(), new Observable()];
trackXhr(requestObservablesSingleton);
trackFetch(requestObservablesSingleton);
}
return requestObservable;
return requestObservablesSingleton;
}
export function trackXhr(observable) {
export function trackXhr(_a) {
var requestStartObservable = _a[0], requestCompleteObservable = _a[1];
var originalOpen = XMLHttpRequest.prototype.open;

@@ -35,2 +42,6 @@ XMLHttpRequest.prototype.open = monitor(function (method, url) {

var startTime = performance.now();
var requestId = getNextRequestId();
requestStartObservable.notify({
requestId: requestId,
});
var hasBeenReported = false;

@@ -42,3 +53,4 @@ var reportXhr = function () {

hasBeenReported = true;
observable.notify({
requestCompleteObservable.notify({
requestId: requestId,
startTime: startTime,

@@ -67,3 +79,4 @@ duration: performance.now() - startTime,

}
export function trackFetch(observable) {
export function trackFetch(_a) {
var requestStartObservable = _a[0], requestCompleteObservable = _a[1];
if (!window.fetch) {

@@ -78,2 +91,6 @@ return;

var startTime = performance.now();
var requestId = getNextRequestId();
requestStartObservable.notify({
requestId: requestId,
});
var reportFetch = function (response) { return __awaiter(_this, void 0, void 0, function () {

@@ -88,5 +105,6 @@ var duration, url, stackTrace, text, e_1;

stackTrace = computeStackTrace(response);
observable.notify({
requestCompleteObservable.notify({
duration: duration,
method: method,
requestId: requestId,
startTime: startTime,

@@ -115,5 +133,6 @@ url: url,

case 5:
observable.notify({
requestCompleteObservable.notify({
duration: duration,
method: method,
requestId: requestId,
startTime: startTime,

@@ -120,0 +139,0 @@ url: url,

import { CookieCache } from './cookie';
import { Observable } from './observable';
export declare const SESSION_COOKIE_NAME = "_dd_s";
export declare const EXPIRATION_DELAY: number;
export declare const SESSION_EXPIRATION_DELAY: number;
export declare const SESSION_TIME_OUT_DELAY: number;
export declare const VISIBILITY_CHECK_DELAY: number;
export interface Session<T> {

@@ -12,2 +14,4 @@ renewObservable: Observable<void>;

id?: string;
created?: string;
expire?: string;
[key: string]: string | undefined;

@@ -21,6 +25,6 @@ }

isTracked: boolean;
}): Session<Type>;
}, withNewSessionStrategy?: boolean): Session<Type>;
export declare function isValidSessionString(sessionString: string | undefined): sessionString is string;
export declare function persistSession(session: SessionState, cookie: CookieCache): void;
export declare function persistSession(session: SessionState, cookie: CookieCache, withNewSessionStrategy?: boolean): void;
export declare function stopSessionManagement(): void;
export declare function trackActivity(expandOrRenewSession: () => void): void;
import { cacheCookieAccess, COOKIE_ACCESS_DELAY } from './cookie';
import { monitor } from './internalMonitoring';
import { Observable } from './observable';

@@ -6,13 +7,16 @@ import { tryOldCookiesMigration } from './oldCookiesMigration';

export var SESSION_COOKIE_NAME = '_dd_s';
export var EXPIRATION_DELAY = 15 * utils.ONE_MINUTE;
export var SESSION_EXPIRATION_DELAY = 15 * utils.ONE_MINUTE;
export var SESSION_TIME_OUT_DELAY = 4 * utils.ONE_HOUR;
export var VISIBILITY_CHECK_DELAY = utils.ONE_MINUTE;
/**
* Limit access to cookie to avoid performance issues
*/
export function startSessionManagement(sessionTypeKey, computeSessionState) {
export function startSessionManagement(sessionTypeKey, computeSessionState, withNewSessionStrategy) {
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; }
var sessionCookie = cacheCookieAccess(SESSION_COOKIE_NAME);
tryOldCookiesMigration(sessionCookie);
var renewObservable = new Observable();
var currentSessionId = retrieveSession(sessionCookie).id;
var currentSessionId = retrieveActiveSession(sessionCookie, withNewSessionStrategy).id;
var expandOrRenewSession = utils.throttle(function () {
var session = retrieveSession(sessionCookie);
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy);
var _a = computeSessionState(session[sessionTypeKey]), type = _a.type, isTracked = _a.isTracked;

@@ -22,5 +26,8 @@ session[sessionTypeKey] = type;

session.id = utils.generateUUID();
if (withNewSessionStrategy) {
session.created = String(Date.now());
}
}
// save changes and expand session duration
persistSession(session, sessionCookie);
persistSession(session, sessionCookie, withNewSessionStrategy);
// If the session id has changed, notify that the session has been renewed

@@ -32,10 +39,17 @@ if (isTracked && currentSessionId !== session.id) {

}, COOKIE_ACCESS_DELAY);
var expandSession = function () {
var session = retrieveActiveSession(sessionCookie, withNewSessionStrategy);
persistSession(session, sessionCookie, withNewSessionStrategy);
};
expandOrRenewSession();
trackActivity(expandOrRenewSession);
if (withNewSessionStrategy) {
trackVisibility(expandSession);
}
return {
getId: function () {
return retrieveSession(sessionCookie).id;
return retrieveActiveSession(sessionCookie, withNewSessionStrategy).id;
},
getType: function () {
return retrieveSession(sessionCookie)[sessionTypeKey];
return retrieveActiveSession(sessionCookie, withNewSessionStrategy)[sessionTypeKey];
},

@@ -51,2 +65,16 @@ renewObservable: renewObservable,

}
function retrieveActiveSession(sessionCookie, withNewSessionStrategy) {
var session = retrieveSession(sessionCookie);
if (!withNewSessionStrategy || isActiveSession(session)) {
return session;
}
clearSession(sessionCookie);
return {};
}
function isActiveSession(session) {
// 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 || Date.now() - Number(session.created) < SESSION_TIME_OUT_DELAY) &&
(session.expire === undefined || Date.now() < Number(session.expire)));
}
function retrieveSession(sessionCookie) {

@@ -66,3 +94,11 @@ var sessionString = sessionCookie.get();

}
export function persistSession(session, cookie) {
export function persistSession(session, cookie, withNewSessionStrategy) {
if (withNewSessionStrategy === void 0) { withNewSessionStrategy = false; }
if (utils.isEmptyObject(session)) {
clearSession(cookie);
return;
}
if (withNewSessionStrategy) {
session.expire = String(Date.now() + SESSION_EXPIRATION_DELAY);
}
var cookieString = utils

@@ -75,16 +111,33 @@ .objectEntries(session)

.join(SESSION_ENTRY_SEPARATOR);
cookie.set(cookieString, EXPIRATION_DELAY);
cookie.set(cookieString, SESSION_EXPIRATION_DELAY);
}
function clearSession(cookie) {
cookie.set('', 0);
}
export function stopSessionManagement() {
registeredActivityListeners.forEach(function (e) { return e(); });
registeredActivityListeners = [];
stopCallbacks.forEach(function (e) { return e(); });
stopCallbacks = [];
}
var registeredActivityListeners = [];
var stopCallbacks = [];
export function trackActivity(expandOrRenewSession) {
var doExpandOrRenewSession = monitor(expandOrRenewSession);
var options = { capture: true, passive: true };
['click', 'touchstart', 'keydown', 'scroll'].forEach(function (event) {
document.addEventListener(event, expandOrRenewSession, options);
registeredActivityListeners.push(function () { return document.removeEventListener(event, expandOrRenewSession, options); });
[utils.DOM_EVENT.CLICK, utils.DOM_EVENT.TOUCH_START, utils.DOM_EVENT.KEY_DOWN, utils.DOM_EVENT.SCROLL].forEach(function (event) {
document.addEventListener(event, doExpandOrRenewSession, options);
stopCallbacks.push(function () { return document.removeEventListener(event, doExpandOrRenewSession, options); });
});
}
function trackVisibility(expandSession) {
var expandSessionWhenVisible = monitor(function () {
if (document.visibilityState === 'visible') {
expandSession();
}
});
var visibilityCheckInterval = window.setInterval(expandSessionWhenVisible, VISIBILITY_CHECK_DELAY);
document.addEventListener(utils.DOM_EVENT.VISIBILITY_CHANGE, expandSessionWhenVisible);
stopCallbacks.push(function () {
clearInterval(visibilityCheckInterval);
document.removeEventListener(utils.DOM_EVENT.VISIBILITY_CHANGE, expandSessionWhenVisible);
});
}
//# sourceMappingURL=sessionManagement.js.map
import { Configuration } from './configuration';
import { Observable } from './observable';
import { RequestDetails } from './requestCollection';
import { RequestCompleteEvent, RequestObservables } from './requestCollection';
export declare const SPEC_ENDPOINTS: Partial<Configuration>;

@@ -11,6 +10,5 @@ export declare function isSafari(): boolean;

private requests;
private pendingFetch;
private whenAllCompleteFn;
constructor(observable: Observable<RequestDetails>);
whenAllComplete(onCompleteFn: (_: RequestDetails[]) => void): void;
constructor([requestStartObservable, requestCompleteObservable]: RequestObservables);
whenAllComplete(onCompleteFn: (_: RequestCompleteEvent[]) => void): void;
getStub(): FetchStub;

@@ -17,0 +15,0 @@ }

@@ -24,11 +24,15 @@ import { __assign, __awaiter, __generator } from "tslib";

var FetchStubBuilder = /** @class */ (function () {
function FetchStubBuilder(observable) {
function FetchStubBuilder(_a) {
var _this = this;
var requestStartObservable = _a[0], requestCompleteObservable = _a[1];
this.requests = [];
this.pendingFetch = 0;
this.whenAllCompleteFn = noop;
observable.subscribe(function (request) {
var pendingFetch = 0;
requestStartObservable.subscribe(function () {
pendingFetch += 1;
});
requestCompleteObservable.subscribe(function (request) {
_this.requests.push(request);
_this.pendingFetch -= 1;
if (_this.pendingFetch === 0) {
pendingFetch -= 1;
if (pendingFetch === 0) {
// ensure that AssertionError are not swallowed by promise context

@@ -47,3 +51,2 @@ setTimeout(function () {

return (function () {
_this.pendingFetch += 1;
var resolve;

@@ -50,0 +53,0 @@ var reject;

import { __spreadArrays } from "tslib";
import lodashMerge from 'lodash.merge';
import { monitor } from './internalMonitoring';
import { jsonStringify, objectValues } from './utils';
import { DOM_EVENT, jsonStringify, objectValues } from './utils';
/**

@@ -153,3 +153,3 @@ * Use POST request without content type to:

*/
window.addEventListener('beforeunload', monitor(function () {
window.addEventListener(DOM_EVENT.BEFORE_UNLOAD, monitor(function () {
_this.beforeFlushOnUnloadHandlers.forEach(function (handler) { return handler(); });

@@ -161,3 +161,3 @@ }));

*/
document.addEventListener('visibilitychange', monitor(function () {
document.addEventListener(DOM_EVENT.VISIBILITY_CHANGE, monitor(function () {
if (document.visibilityState === 'hidden') {

@@ -172,3 +172,3 @@ _this.flush();

*/
window.addEventListener('beforeunload', monitor(function () { return _this.flush(); }));
window.addEventListener(DOM_EVENT.BEFORE_UNLOAD, monitor(function () { return _this.flush(); }));
}

@@ -175,0 +175,0 @@ };

@@ -5,4 +5,13 @@ export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

export declare const ONE_HOUR: number;
export declare const ONE_DAY: number;
export declare const ONE_KILO_BYTE = 1024;
export declare enum DOM_EVENT {
BEFORE_UNLOAD = "beforeunload",
CLICK = "click",
KEY_DOWN = "keydown",
LOAD = "load",
POP_STATE = "popstate",
SCROLL = "scroll",
TOUCH_START = "touchstart",
VISIBILITY_CHANGE = "visibilitychange"
}
export declare enum ResourceKind {

@@ -52,3 +61,5 @@ DOCUMENT = "document",

export declare function jsonStringify(value: unknown, replacer?: Array<string | number>, space?: string | number): string | undefined;
export declare function includes(candidate: unknown[], search: unknown): boolean;
export declare function includes(candidate: string, search: string): boolean;
export declare function includes<T>(candidate: T[], search: T): boolean;
export declare function find<T>(array: T[], predicate: (item: T, index: number, array: T[]) => unknown): T | undefined;
export declare function isPercentage(value: unknown): boolean;

@@ -72,2 +83,3 @@ export declare function isNumber(value: unknown): value is number;

}): unknown[][];
export declare function isEmptyObject(object: object): boolean;
export declare function getGlobalObject<T>(): T;

@@ -74,0 +86,0 @@ export declare function getLocationOrigin(): string;

export var ONE_SECOND = 1000;
export var ONE_MINUTE = 60 * ONE_SECOND;
export var ONE_HOUR = 60 * ONE_MINUTE;
export var ONE_DAY = 24 * ONE_HOUR;
export var ONE_KILO_BYTE = 1024;
export var DOM_EVENT;
(function (DOM_EVENT) {
DOM_EVENT["BEFORE_UNLOAD"] = "beforeunload";
DOM_EVENT["CLICK"] = "click";
DOM_EVENT["KEY_DOWN"] = "keydown";
DOM_EVENT["LOAD"] = "load";
DOM_EVENT["POP_STATE"] = "popstate";
DOM_EVENT["SCROLL"] = "scroll";
DOM_EVENT["TOUCH_START"] = "touchstart";
DOM_EVENT["VISIBILITY_CHANGE"] = "visibilitychange";
})(DOM_EVENT || (DOM_EVENT = {}));
export var ResourceKind;

@@ -141,4 +151,14 @@ (function (ResourceKind) {

export function includes(candidate, search) {
// tslint:disable-next-line: no-unsafe-any
return candidate.indexOf(search) !== -1;
}
export function find(array, predicate) {
for (var i = 0; i < array.length; i += 1) {
var item = array[i];
if (predicate(item, i, array)) {
return item;
}
}
return undefined;
}
export function isPercentage(value) {

@@ -183,2 +203,5 @@ return isNumber(value) && value >= 0 && value <= 100;

}
export function isEmptyObject(object) {
return Object.keys(object).length === 0;
}
export function getGlobalObject() {

@@ -185,0 +208,0 @@ // tslint:disable-next-line: function-constructor no-function-constructor-with-string-args

{
"name": "@datadog/browser-core",
"version": "1.9.1",
"version": "1.9.2",
"license": "Apache-2.0",

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

},
"gitHead": "88a6e91a6e5ad395879cea173c0ac9b4abacd608"
"gitHead": "0cd09ed4844930c19084b9ac9c24635e108678ee"
}

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc