@microsoft/applicationinsights-properties-js 2.8.5-nightly.2206-04 → 2.8.5-nightly.2207-02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/applicationinsights-properties-js.integrity.json +9 -9
- package/browser/applicationinsights-properties-js.js +676 -526
- package/browser/applicationinsights-properties-js.js.map +1 -1
- package/browser/applicationinsights-properties-js.min.js +2 -2
- package/browser/applicationinsights-properties-js.min.js.map +1 -1
- package/dist/applicationinsights-properties-js.api.json +11 -2
- package/dist/applicationinsights-properties-js.d.ts +1 -1
- package/dist/applicationinsights-properties-js.js +676 -526
- package/dist/applicationinsights-properties-js.js.map +1 -1
- package/dist/applicationinsights-properties-js.min.js +2 -2
- package/dist/applicationinsights-properties-js.min.js.map +1 -1
- package/dist/applicationinsights-properties-js.rollup.d.ts +1 -1
- package/dist-esm/Context/Application.js +1 -1
- package/dist-esm/Context/Device.js +1 -1
- package/dist-esm/Context/Internal.js +4 -3
- package/dist-esm/Context/Internal.js.map +1 -1
- package/dist-esm/Context/Location.js +1 -1
- package/dist-esm/Context/Session.js +36 -35
- package/dist-esm/Context/Session.js.map +1 -1
- package/dist-esm/Context/TelemetryTrace.js +1 -1
- package/dist-esm/Context/User.js +32 -31
- package/dist-esm/Context/User.js.map +1 -1
- package/dist-esm/Interfaces/IPropTelemetryContext.js +1 -1
- package/dist-esm/Interfaces/ITelemetryConfig.js +1 -1
- package/dist-esm/PropertiesPlugin.js +65 -56
- package/dist-esm/PropertiesPlugin.js.map +1 -1
- package/dist-esm/TelemetryContext.js +27 -26
- package/dist-esm/TelemetryContext.js.map +1 -1
- package/dist-esm/__DynamicConstants.js +48 -0
- package/dist-esm/__DynamicConstants.js.map +1 -0
- package/dist-esm/applicationinsights-properties-js.js +1 -1
- package/package.json +7 -4
- package/src/Context/Internal.ts +8 -8
- package/src/Context/Session.ts +11 -11
- package/src/Context/TelemetryTrace.ts +3 -3
- package/src/Context/User.ts +11 -10
- package/src/PropertiesPlugin.ts +57 -46
- package/src/TelemetryContext.ts +25 -19
- package/src/__DynamicConstants.ts +46 -0
- package/types/Context/User.d.ts +1 -1
- package/types/PropertiesPlugin.d.ts +5 -5
- package/types/TelemetryContext.d.ts +6 -6
- package/types/__DynamicConstants.d.ts +34 -0
- package/types/tsdoc-metadata.json +1 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Properties Plugin, 2.8.5-nightly.
|
|
2
|
+
* Application Insights JavaScript SDK - Properties Plugin, 2.8.5-nightly.2207-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { _DYN_SDK_EXTENSION } from "../__DynamicConstants";
|
|
8
|
+
var Version = "2.8.5-nightly.2207-02";
|
|
8
9
|
var Internal = /** @class */ (function () {
|
|
9
10
|
/**
|
|
10
11
|
* Constructs a new instance of the internal telemetry data class.
|
|
11
12
|
*/
|
|
12
13
|
function Internal(config) {
|
|
13
|
-
this.sdkVersion = (config
|
|
14
|
+
this.sdkVersion = (config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */] && config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */]() ? config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */]() + "_" : "") + "javascript:" + Version;
|
|
14
15
|
}
|
|
15
16
|
return Internal;
|
|
16
17
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Internal.js.map","sources":["Internal.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nvar Version = \"2.8.5-nightly.
|
|
1
|
+
{"version":3,"file":"Internal.js.map","sources":["Internal.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { _DYN_SDK_EXTENSION } from \"../__DynamicConstants\";\r\nvar Version = \"2.8.5-nightly.2207-02\";\r\nvar Internal = /** @class */ (function () {\r\n /**\r\n * Constructs a new instance of the internal telemetry data class.\r\n */\r\n function Internal(config) {\r\n this.sdkVersion = (config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */] && config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */]() ? config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */]() + \"_\" : \"\") + \"javascript:\" + Version;\r\n }\r\n return Internal;\r\n}());\r\nexport { Internal };\r\n//# sourceMappingURL=Internal.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Properties Plugin, 2.8.5-nightly.
|
|
2
|
+
* Application Insights JavaScript SDK - Properties Plugin, 2.8.5-nightly.2207-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
8
8
|
import { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "@microsoft/applicationinsights-common";
|
|
9
|
-
import {
|
|
9
|
+
import { _throwInternal, dateNow, dumpObj, getExceptionName, isFunction, newId, safeGetCookieMgr, safeGetLogger } from "@microsoft/applicationinsights-core-js";
|
|
10
|
+
import { _DYN_ACQUISITION_DATE, _DYN_AUTOMATIC_SESSION, _DYN_CONFIG, _DYN_COOKIE_DOMAIN, _DYN_GET_NEW_ID, _DYN_ID_LENGTH, _DYN_JOIN, _DYN_LENGTH, _DYN_NAME_PREFIX, _DYN_RENEWAL_DATE, _DYN_SESSION_COOKIE_POSTF6, _DYN_SESSION_EXPIRATION_M7, _DYN_SESSION_RENEWAL_MS, _DYN_UPDATE } from "../__DynamicConstants";
|
|
10
11
|
var cookieNameConst = "ai_session";
|
|
11
12
|
var Session = /** @class */ (function () {
|
|
12
13
|
function Session() {
|
|
@@ -25,33 +26,33 @@ var _SessionManager = /** @class */ (function () {
|
|
|
25
26
|
if (!config) {
|
|
26
27
|
config = {};
|
|
27
28
|
}
|
|
28
|
-
if (!isFunction(config
|
|
29
|
-
config
|
|
29
|
+
if (!isFunction(config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */])) {
|
|
30
|
+
config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */] = function () { return _SessionManager.acquisitionSpan; };
|
|
30
31
|
}
|
|
31
|
-
if (!isFunction(config
|
|
32
|
-
config
|
|
32
|
+
if (!isFunction(config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */])) {
|
|
33
|
+
config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */] = function () { return _SessionManager.renewalSpan; };
|
|
33
34
|
}
|
|
34
|
-
_self
|
|
35
|
+
_self[_DYN_CONFIG /* @min:%2econfig */] = config;
|
|
35
36
|
// sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.
|
|
36
|
-
var sessionCookiePostfix = (_self.config
|
|
37
|
-
_self.config
|
|
38
|
-
((_self.config
|
|
37
|
+
var sessionCookiePostfix = (_self.config[_DYN_SESSION_COOKIE_POSTF6 /* @min:%2esessionCookiePostfix */] && _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_SESSION_COOKIE_POSTF6 /* @min:%2esessionCookiePostfix */]()) ?
|
|
38
|
+
_self.config[_DYN_SESSION_COOKIE_POSTF6 /* @min:%2esessionCookiePostfix */]() :
|
|
39
|
+
((_self.config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] && _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_NAME_PREFIX /* @min:%2enamePrefix */]()) ? _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_NAME_PREFIX /* @min:%2enamePrefix */]() : "");
|
|
39
40
|
_storageNamePrefix = function () { return cookieNameConst + sessionCookiePostfix; };
|
|
40
|
-
_self
|
|
41
|
-
_self
|
|
41
|
+
_self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */] = new Session();
|
|
42
|
+
_self[_DYN_UPDATE /* @min:%2eupdate */] = function () {
|
|
42
43
|
// Always using Date getTime() as there is a bug in older IE instances that causes the performance timings to have the hi-bit set eg 0x800000000 causing
|
|
43
44
|
// the number to be incorrect.
|
|
44
45
|
var nowMs = dateNow();
|
|
45
46
|
var isExpired = false;
|
|
46
|
-
var session = _self
|
|
47
|
+
var session = _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */];
|
|
47
48
|
if (!session.id) {
|
|
48
49
|
isExpired = !_initializeAutomaticSession(session, nowMs);
|
|
49
50
|
}
|
|
50
|
-
var sessionExpirationMs = _self.config
|
|
51
|
+
var sessionExpirationMs = _self.config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]();
|
|
51
52
|
if (!isExpired && sessionExpirationMs > 0) {
|
|
52
|
-
var sessionRenewalMs = _self.config
|
|
53
|
-
var timeSinceAcqMs = nowMs - session
|
|
54
|
-
var timeSinceRenewalMs = nowMs - session
|
|
53
|
+
var sessionRenewalMs = _self.config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */]();
|
|
54
|
+
var timeSinceAcqMs = nowMs - session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */];
|
|
55
|
+
var timeSinceRenewalMs = nowMs - session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */];
|
|
55
56
|
isExpired = timeSinceAcqMs < 0 || timeSinceRenewalMs < 0; // expired if the acquisition or last renewal are in the future
|
|
56
57
|
isExpired = isExpired || timeSinceAcqMs > sessionExpirationMs; // expired if the time since acquisition is more than session Expiration
|
|
57
58
|
isExpired = isExpired || timeSinceRenewalMs > sessionRenewalMs; // expired if the time since last renewal is more than renewal period
|
|
@@ -74,8 +75,8 @@ var _SessionManager = /** @class */ (function () {
|
|
|
74
75
|
* expires.
|
|
75
76
|
*/
|
|
76
77
|
_self.backup = function () {
|
|
77
|
-
var session = _self
|
|
78
|
-
_setStorage(session.id, session
|
|
78
|
+
var session = _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */];
|
|
79
|
+
_setStorage(session.id, session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */], session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */]);
|
|
79
80
|
};
|
|
80
81
|
/**
|
|
81
82
|
* Use config.namePrefix + ai_session cookie data or local storage data (when the cookie is unavailable) to
|
|
@@ -111,7 +112,7 @@ var _SessionManager = /** @class */ (function () {
|
|
|
111
112
|
var isValid = false;
|
|
112
113
|
var sessionReset = ", session will be reset";
|
|
113
114
|
var tokens = sessionData.split("|");
|
|
114
|
-
if (tokens
|
|
115
|
+
if (tokens[_DYN_LENGTH /* @min:%2elength */] >= 2) {
|
|
115
116
|
try {
|
|
116
117
|
var acqMs = +tokens[1] || 0;
|
|
117
118
|
var renewalMs = +tokens[2] || 0;
|
|
@@ -124,8 +125,8 @@ var _SessionManager = /** @class */ (function () {
|
|
|
124
125
|
else if (tokens[0]) {
|
|
125
126
|
// Everything looks valid so set the values
|
|
126
127
|
session.id = tokens[0];
|
|
127
|
-
session
|
|
128
|
-
session
|
|
128
|
+
session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */] = acqMs;
|
|
129
|
+
session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */] = renewalMs;
|
|
129
130
|
isValid = true;
|
|
130
131
|
}
|
|
131
132
|
}
|
|
@@ -136,24 +137,24 @@ var _SessionManager = /** @class */ (function () {
|
|
|
136
137
|
return isValid;
|
|
137
138
|
}
|
|
138
139
|
function _renew(nowMs) {
|
|
139
|
-
var theConfig = (_self
|
|
140
|
-
var getNewId = (theConfig
|
|
141
|
-
_self.automaticSession.id = getNewId(theConfig
|
|
142
|
-
_self
|
|
143
|
-
_setCookie(_self
|
|
140
|
+
var theConfig = (_self[_DYN_CONFIG /* @min:%2econfig */] || {});
|
|
141
|
+
var getNewId = (theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */] ? theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */]() : null) || newId;
|
|
142
|
+
_self.automaticSession.id = getNewId(theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */] ? theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */]() : 22);
|
|
143
|
+
_self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */][_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */] = nowMs;
|
|
144
|
+
_setCookie(_self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */], nowMs);
|
|
144
145
|
// If this browser does not support local storage, fire an internal log to keep track of it at this point
|
|
145
146
|
if (!utlCanUseLocalStorage()) {
|
|
146
147
|
_throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 0 /* _eInternalMessageId.BrowserDoesNotSupportLocalStorage */, "Browser does not support local storage. Session durations will be inaccurate.");
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
function _setCookie(session, nowMs) {
|
|
150
|
-
var acq = session
|
|
151
|
-
session
|
|
152
|
-
var config = _self
|
|
153
|
-
var renewalPeriodMs = config
|
|
151
|
+
var acq = session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */];
|
|
152
|
+
session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */] = nowMs;
|
|
153
|
+
var config = _self[_DYN_CONFIG /* @min:%2econfig */];
|
|
154
|
+
var renewalPeriodMs = config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */]();
|
|
154
155
|
// Set cookie to expire after the session expiry time passes or the session renewal deadline, whichever is sooner
|
|
155
156
|
// Expiring the cookie will cause the session to expire even if the user isn't on the page
|
|
156
|
-
var acqTimeLeftMs = (acq + config
|
|
157
|
+
var acqTimeLeftMs = (acq + config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]()) - nowMs;
|
|
157
158
|
var cookie = [session.id, acq, nowMs];
|
|
158
159
|
var maxAgeSec = 0;
|
|
159
160
|
if (acqTimeLeftMs < renewalPeriodMs) {
|
|
@@ -162,18 +163,18 @@ var _SessionManager = /** @class */ (function () {
|
|
|
162
163
|
else {
|
|
163
164
|
maxAgeSec = renewalPeriodMs / 1000;
|
|
164
165
|
}
|
|
165
|
-
var cookieDomain = config
|
|
166
|
+
var cookieDomain = config[_DYN_COOKIE_DOMAIN /* @min:%2ecookieDomain */] ? config[_DYN_COOKIE_DOMAIN /* @min:%2ecookieDomain */]() : null;
|
|
166
167
|
// if sessionExpirationMs is set to 0, it means the expiry is set to 0 for this session cookie
|
|
167
168
|
// A cookie with 0 expiry in the session cookie will never expire for that browser session. If the browser is closed the cookie expires.
|
|
168
169
|
// Depending on the browser, another instance does not inherit this cookie, however, another tab will
|
|
169
|
-
_cookieManager.set(_storageNamePrefix(), cookie.join("|"), config
|
|
170
|
+
_cookieManager.set(_storageNamePrefix(), cookie.join("|"), config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]() > 0 ? maxAgeSec : null, cookieDomain);
|
|
170
171
|
_cookieUpdatedTimestamp = nowMs;
|
|
171
172
|
}
|
|
172
173
|
function _setStorage(guid, acq, renewal) {
|
|
173
174
|
// Keep data in local storage to retain the last session id, allowing us to cleanly end the session when it expires
|
|
174
175
|
// Browsers that don't support local storage won't be able to end sessions cleanly from the client
|
|
175
176
|
// The server will notice this and end the sessions itself, with loss of accurate session duration
|
|
176
|
-
utlSetLocalStorage(_logger, _storageNamePrefix(), [guid, acq, renewal]
|
|
177
|
+
utlSetLocalStorage(_logger, _storageNamePrefix(), [guid, acq, renewal][_DYN_JOIN /* @min:%2ejoin */]("|"));
|
|
177
178
|
}
|
|
178
179
|
});
|
|
179
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Session.js.map","sources":["Session.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from \"@microsoft/applicationinsights-common\";\r\nimport { safeGetCookieMgr, isFunction, newId, dumpObj, getExceptionName, dateNow, safeGetLogger, _throwInternal } from \"@microsoft/applicationinsights-core-js\";\r\nvar cookieNameConst = \"ai_session\";\r\nvar Session = /** @class */ (function () {\r\n function Session() {\r\n }\r\n return Session;\r\n}());\r\nexport { Session };\r\nvar _SessionManager = /** @class */ (function () {\r\n function _SessionManager(config, core) {\r\n var self = this;\r\n var _storageNamePrefix;\r\n var _cookieUpdatedTimestamp;\r\n var _logger = safeGetLogger(core);\r\n var _cookieManager = safeGetCookieMgr(core);\r\n dynamicProto(_SessionManager, self, function (_self) {\r\n if (!config) {\r\n config = {};\r\n }\r\n if (!isFunction(config.sessionExpirationMs)) {\r\n config.sessionExpirationMs = function () { return _SessionManager.acquisitionSpan; };\r\n }\r\n if (!isFunction(config.sessionRenewalMs)) {\r\n config.sessionRenewalMs = function () { return _SessionManager.renewalSpan; };\r\n }\r\n _self.config = config;\r\n // sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.\r\n var sessionCookiePostfix = (_self.config.sessionCookiePostfix && _self.config.sessionCookiePostfix()) ?\r\n _self.config.sessionCookiePostfix() :\r\n ((_self.config.namePrefix && _self.config.namePrefix()) ? _self.config.namePrefix() : \"\");\r\n _storageNamePrefix = function () { return cookieNameConst + sessionCookiePostfix; };\r\n _self.automaticSession = new Session();\r\n _self.update = function () {\r\n // Always using Date getTime() as there is a bug in older IE instances that causes the performance timings to have the hi-bit set eg 0x800000000 causing\r\n // the number to be incorrect.\r\n var nowMs = dateNow();\r\n var isExpired = false;\r\n var session = _self.automaticSession;\r\n if (!session.id) {\r\n isExpired = !_initializeAutomaticSession(session, nowMs);\r\n }\r\n var sessionExpirationMs = _self.config.sessionExpirationMs();\r\n if (!isExpired && sessionExpirationMs > 0) {\r\n var sessionRenewalMs = _self.config.sessionRenewalMs();\r\n var timeSinceAcqMs = nowMs - session.acquisitionDate;\r\n var timeSinceRenewalMs = nowMs - session.renewalDate;\r\n isExpired = timeSinceAcqMs < 0 || timeSinceRenewalMs < 0; // expired if the acquisition or last renewal are in the future\r\n isExpired = isExpired || timeSinceAcqMs > sessionExpirationMs; // expired if the time since acquisition is more than session Expiration\r\n isExpired = isExpired || timeSinceRenewalMs > sessionRenewalMs; // expired if the time since last renewal is more than renewal period\r\n }\r\n // renew if acquisitionSpan or renewalSpan has elapsed\r\n if (isExpired) {\r\n // update automaticSession so session state has correct id\r\n _renew(nowMs);\r\n }\r\n else {\r\n // do not update the cookie more often than cookieUpdateInterval\r\n if (!_cookieUpdatedTimestamp || nowMs - _cookieUpdatedTimestamp > _SessionManager.cookieUpdateInterval) {\r\n _setCookie(session, nowMs);\r\n }\r\n }\r\n };\r\n /**\r\n * Record the current state of the automatic session and store it in our cookie string format\r\n * into the browser's local storage. This is used to restore the session data when the cookie\r\n * expires.\r\n */\r\n _self.backup = function () {\r\n var session = _self.automaticSession;\r\n _setStorage(session.id, session.acquisitionDate, session.renewalDate);\r\n };\r\n /**\r\n * Use config.namePrefix + ai_session cookie data or local storage data (when the cookie is unavailable) to\r\n * initialize the automatic session.\r\n * @returns true if values set otherwise false\r\n */\r\n function _initializeAutomaticSession(session, now) {\r\n var isValid = false;\r\n var cookieValue = _cookieManager.get(_storageNamePrefix());\r\n if (cookieValue && isFunction(cookieValue.split)) {\r\n isValid = _initializeAutomaticSessionWithData(session, cookieValue);\r\n }\r\n else {\r\n // There's no cookie, but we might have session data in local storage\r\n // This can happen if the session expired or the user actively deleted the cookie\r\n // We only want to recover data if the cookie is missing from expiry. We should respect the user's wishes if the cookie was deleted actively.\r\n // The User class handles this for us and deletes our local storage object if the persistent user cookie was removed.\r\n var storageValue = utlGetLocalStorage(_logger, _storageNamePrefix());\r\n if (storageValue) {\r\n isValid = _initializeAutomaticSessionWithData(session, storageValue);\r\n }\r\n }\r\n return isValid || !!session.id;\r\n }\r\n /**\r\n * Extract id, acquisitionDate, and renewalDate from an ai_session payload string and\r\n * use this data to initialize automaticSession.\r\n *\r\n * @param {string} sessionData - The string stored in an ai_session cookie or local storage backup\r\n * @returns true if values set otherwise false\r\n */\r\n function _initializeAutomaticSessionWithData(session, sessionData) {\r\n var isValid = false;\r\n var sessionReset = \", session will be reset\";\r\n var tokens = sessionData.split(\"|\");\r\n if (tokens.length >= 2) {\r\n try {\r\n var acqMs = +tokens[1] || 0;\r\n var renewalMs = +tokens[2] || 0;\r\n if (isNaN(acqMs) || acqMs <= 0) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 27 /* _eInternalMessageId.SessionRenewalDateIsZero */, \"AI session acquisition date is 0\" + sessionReset);\r\n }\r\n else if (isNaN(renewalMs) || renewalMs <= 0) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 27 /* _eInternalMessageId.SessionRenewalDateIsZero */, \"AI session renewal date is 0\" + sessionReset);\r\n }\r\n else if (tokens[0]) {\r\n // Everything looks valid so set the values\r\n session.id = tokens[0];\r\n session.acquisitionDate = acqMs;\r\n session.renewalDate = renewalMs;\r\n isValid = true;\r\n }\r\n }\r\n catch (e) {\r\n _throwInternal(_logger, 1 /* eLoggingSeverity.CRITICAL */, 9 /* _eInternalMessageId.ErrorParsingAISessionCookie */, \"Error parsing ai_session value [\" + (sessionData || \"\") + \"]\" + sessionReset + \" - \" + getExceptionName(e), { exception: dumpObj(e) });\r\n }\r\n }\r\n return isValid;\r\n }\r\n function _renew(nowMs) {\r\n var theConfig = (_self.config || {});\r\n var getNewId = (theConfig.getNewId ? theConfig.getNewId() : null) || newId;\r\n _self.automaticSession.id = getNewId(theConfig.idLength ? theConfig.idLength() : 22);\r\n _self.automaticSession.acquisitionDate = nowMs;\r\n _setCookie(_self.automaticSession, nowMs);\r\n // If this browser does not support local storage, fire an internal log to keep track of it at this point\r\n if (!utlCanUseLocalStorage()) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 0 /* _eInternalMessageId.BrowserDoesNotSupportLocalStorage */, \"Browser does not support local storage. Session durations will be inaccurate.\");\r\n }\r\n }\r\n function _setCookie(session, nowMs) {\r\n var acq = session.acquisitionDate;\r\n session.renewalDate = nowMs;\r\n var config = _self.config;\r\n var renewalPeriodMs = config.sessionRenewalMs();\r\n // Set cookie to expire after the session expiry time passes or the session renewal deadline, whichever is sooner\r\n // Expiring the cookie will cause the session to expire even if the user isn't on the page\r\n var acqTimeLeftMs = (acq + config.sessionExpirationMs()) - nowMs;\r\n var cookie = [session.id, acq, nowMs];\r\n var maxAgeSec = 0;\r\n if (acqTimeLeftMs < renewalPeriodMs) {\r\n maxAgeSec = acqTimeLeftMs / 1000;\r\n }\r\n else {\r\n maxAgeSec = renewalPeriodMs / 1000;\r\n }\r\n var cookieDomain = config.cookieDomain ? config.cookieDomain() : null;\r\n // if sessionExpirationMs is set to 0, it means the expiry is set to 0 for this session cookie\r\n // A cookie with 0 expiry in the session cookie will never expire for that browser session. If the browser is closed the cookie expires.\r\n // Depending on the browser, another instance does not inherit this cookie, however, another tab will\r\n _cookieManager.set(_storageNamePrefix(), cookie.join(\"|\"), config.sessionExpirationMs() > 0 ? maxAgeSec : null, cookieDomain);\r\n _cookieUpdatedTimestamp = nowMs;\r\n }\r\n function _setStorage(guid, acq, renewal) {\r\n // Keep data in local storage to retain the last session id, allowing us to cleanly end the session when it expires\r\n // Browsers that don't support local storage won't be able to end sessions cleanly from the client\r\n // The server will notice this and end the sessions itself, with loss of accurate session duration\r\n utlSetLocalStorage(_logger, _storageNamePrefix(), [guid, acq, renewal].join(\"|\"));\r\n }\r\n });\r\n }\r\n _SessionManager.prototype.update = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Record the current state of the automatic session and store it in our cookie string format\r\n * into the browser's local storage. This is used to restore the session data when the cookie\r\n * expires.\r\n */\r\n _SessionManager.prototype.backup = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n _SessionManager.acquisitionSpan = 86400000; // 24 hours in ms\r\n _SessionManager.renewalSpan = 1800000; // 30 minutes in ms\r\n _SessionManager.cookieUpdateInterval = 60000; // 1 minute in ms\r\n return _SessionManager;\r\n}());\r\nexport { _SessionManager };\r\n//# sourceMappingURL=Session.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;qDAUM;AACN;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"Session.js.map","sources":["Session.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from \"@microsoft/applicationinsights-common\";\r\nimport { _throwInternal, dateNow, dumpObj, getExceptionName, isFunction, newId, safeGetCookieMgr, safeGetLogger } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_ACQUISITION_DATE, _DYN_AUTOMATIC_SESSION, _DYN_CONFIG, _DYN_COOKIE_DOMAIN, _DYN_GET_NEW_ID, _DYN_ID_LENGTH, _DYN_JOIN, _DYN_LENGTH, _DYN_NAME_PREFIX, _DYN_RENEWAL_DATE, _DYN_SESSION_COOKIE_POSTF6, _DYN_SESSION_EXPIRATION_M7, _DYN_SESSION_RENEWAL_MS, _DYN_UPDATE } from \"../__DynamicConstants\";\r\nvar cookieNameConst = \"ai_session\";\r\nvar Session = /** @class */ (function () {\r\n function Session() {\r\n }\r\n return Session;\r\n}());\r\nexport { Session };\r\nvar _SessionManager = /** @class */ (function () {\r\n function _SessionManager(config, core) {\r\n var self = this;\r\n var _storageNamePrefix;\r\n var _cookieUpdatedTimestamp;\r\n var _logger = safeGetLogger(core);\r\n var _cookieManager = safeGetCookieMgr(core);\r\n dynamicProto(_SessionManager, self, function (_self) {\r\n if (!config) {\r\n config = {};\r\n }\r\n if (!isFunction(config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */])) {\r\n config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */] = function () { return _SessionManager.acquisitionSpan; };\r\n }\r\n if (!isFunction(config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */])) {\r\n config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */] = function () { return _SessionManager.renewalSpan; };\r\n }\r\n _self[_DYN_CONFIG /* @min:%2econfig */] = config;\r\n // sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.\r\n var sessionCookiePostfix = (_self.config[_DYN_SESSION_COOKIE_POSTF6 /* @min:%2esessionCookiePostfix */] && _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_SESSION_COOKIE_POSTF6 /* @min:%2esessionCookiePostfix */]()) ?\r\n _self.config[_DYN_SESSION_COOKIE_POSTF6 /* @min:%2esessionCookiePostfix */]() :\r\n ((_self.config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] && _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_NAME_PREFIX /* @min:%2enamePrefix */]()) ? _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_NAME_PREFIX /* @min:%2enamePrefix */]() : \"\");\r\n _storageNamePrefix = function () { return cookieNameConst + sessionCookiePostfix; };\r\n _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */] = new Session();\r\n _self[_DYN_UPDATE /* @min:%2eupdate */] = function () {\r\n // Always using Date getTime() as there is a bug in older IE instances that causes the performance timings to have the hi-bit set eg 0x800000000 causing\r\n // the number to be incorrect.\r\n var nowMs = dateNow();\r\n var isExpired = false;\r\n var session = _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */];\r\n if (!session.id) {\r\n isExpired = !_initializeAutomaticSession(session, nowMs);\r\n }\r\n var sessionExpirationMs = _self.config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]();\r\n if (!isExpired && sessionExpirationMs > 0) {\r\n var sessionRenewalMs = _self.config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */]();\r\n var timeSinceAcqMs = nowMs - session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */];\r\n var timeSinceRenewalMs = nowMs - session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */];\r\n isExpired = timeSinceAcqMs < 0 || timeSinceRenewalMs < 0; // expired if the acquisition or last renewal are in the future\r\n isExpired = isExpired || timeSinceAcqMs > sessionExpirationMs; // expired if the time since acquisition is more than session Expiration\r\n isExpired = isExpired || timeSinceRenewalMs > sessionRenewalMs; // expired if the time since last renewal is more than renewal period\r\n }\r\n // renew if acquisitionSpan or renewalSpan has elapsed\r\n if (isExpired) {\r\n // update automaticSession so session state has correct id\r\n _renew(nowMs);\r\n }\r\n else {\r\n // do not update the cookie more often than cookieUpdateInterval\r\n if (!_cookieUpdatedTimestamp || nowMs - _cookieUpdatedTimestamp > _SessionManager.cookieUpdateInterval) {\r\n _setCookie(session, nowMs);\r\n }\r\n }\r\n };\r\n /**\r\n * Record the current state of the automatic session and store it in our cookie string format\r\n * into the browser's local storage. This is used to restore the session data when the cookie\r\n * expires.\r\n */\r\n _self.backup = function () {\r\n var session = _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */];\r\n _setStorage(session.id, session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */], session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */]);\r\n };\r\n /**\r\n * Use config.namePrefix + ai_session cookie data or local storage data (when the cookie is unavailable) to\r\n * initialize the automatic session.\r\n * @returns true if values set otherwise false\r\n */\r\n function _initializeAutomaticSession(session, now) {\r\n var isValid = false;\r\n var cookieValue = _cookieManager.get(_storageNamePrefix());\r\n if (cookieValue && isFunction(cookieValue.split)) {\r\n isValid = _initializeAutomaticSessionWithData(session, cookieValue);\r\n }\r\n else {\r\n // There's no cookie, but we might have session data in local storage\r\n // This can happen if the session expired or the user actively deleted the cookie\r\n // We only want to recover data if the cookie is missing from expiry. We should respect the user's wishes if the cookie was deleted actively.\r\n // The User class handles this for us and deletes our local storage object if the persistent user cookie was removed.\r\n var storageValue = utlGetLocalStorage(_logger, _storageNamePrefix());\r\n if (storageValue) {\r\n isValid = _initializeAutomaticSessionWithData(session, storageValue);\r\n }\r\n }\r\n return isValid || !!session.id;\r\n }\r\n /**\r\n * Extract id, acquisitionDate, and renewalDate from an ai_session payload string and\r\n * use this data to initialize automaticSession.\r\n *\r\n * @param {string} sessionData - The string stored in an ai_session cookie or local storage backup\r\n * @returns true if values set otherwise false\r\n */\r\n function _initializeAutomaticSessionWithData(session, sessionData) {\r\n var isValid = false;\r\n var sessionReset = \", session will be reset\";\r\n var tokens = sessionData.split(\"|\");\r\n if (tokens[_DYN_LENGTH /* @min:%2elength */] >= 2) {\r\n try {\r\n var acqMs = +tokens[1] || 0;\r\n var renewalMs = +tokens[2] || 0;\r\n if (isNaN(acqMs) || acqMs <= 0) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 27 /* _eInternalMessageId.SessionRenewalDateIsZero */, \"AI session acquisition date is 0\" + sessionReset);\r\n }\r\n else if (isNaN(renewalMs) || renewalMs <= 0) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 27 /* _eInternalMessageId.SessionRenewalDateIsZero */, \"AI session renewal date is 0\" + sessionReset);\r\n }\r\n else if (tokens[0]) {\r\n // Everything looks valid so set the values\r\n session.id = tokens[0];\r\n session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */] = acqMs;\r\n session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */] = renewalMs;\r\n isValid = true;\r\n }\r\n }\r\n catch (e) {\r\n _throwInternal(_logger, 1 /* eLoggingSeverity.CRITICAL */, 9 /* _eInternalMessageId.ErrorParsingAISessionCookie */, \"Error parsing ai_session value [\" + (sessionData || \"\") + \"]\" + sessionReset + \" - \" + getExceptionName(e), { exception: dumpObj(e) });\r\n }\r\n }\r\n return isValid;\r\n }\r\n function _renew(nowMs) {\r\n var theConfig = (_self[_DYN_CONFIG /* @min:%2econfig */] || {});\r\n var getNewId = (theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */] ? theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */]() : null) || newId;\r\n _self.automaticSession.id = getNewId(theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */] ? theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */]() : 22);\r\n _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */][_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */] = nowMs;\r\n _setCookie(_self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */], nowMs);\r\n // If this browser does not support local storage, fire an internal log to keep track of it at this point\r\n if (!utlCanUseLocalStorage()) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 0 /* _eInternalMessageId.BrowserDoesNotSupportLocalStorage */, \"Browser does not support local storage. Session durations will be inaccurate.\");\r\n }\r\n }\r\n function _setCookie(session, nowMs) {\r\n var acq = session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */];\r\n session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */] = nowMs;\r\n var config = _self[_DYN_CONFIG /* @min:%2econfig */];\r\n var renewalPeriodMs = config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */]();\r\n // Set cookie to expire after the session expiry time passes or the session renewal deadline, whichever is sooner\r\n // Expiring the cookie will cause the session to expire even if the user isn't on the page\r\n var acqTimeLeftMs = (acq + config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]()) - nowMs;\r\n var cookie = [session.id, acq, nowMs];\r\n var maxAgeSec = 0;\r\n if (acqTimeLeftMs < renewalPeriodMs) {\r\n maxAgeSec = acqTimeLeftMs / 1000;\r\n }\r\n else {\r\n maxAgeSec = renewalPeriodMs / 1000;\r\n }\r\n var cookieDomain = config[_DYN_COOKIE_DOMAIN /* @min:%2ecookieDomain */] ? config[_DYN_COOKIE_DOMAIN /* @min:%2ecookieDomain */]() : null;\r\n // if sessionExpirationMs is set to 0, it means the expiry is set to 0 for this session cookie\r\n // A cookie with 0 expiry in the session cookie will never expire for that browser session. If the browser is closed the cookie expires.\r\n // Depending on the browser, another instance does not inherit this cookie, however, another tab will\r\n _cookieManager.set(_storageNamePrefix(), cookie.join(\"|\"), config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]() > 0 ? maxAgeSec : null, cookieDomain);\r\n _cookieUpdatedTimestamp = nowMs;\r\n }\r\n function _setStorage(guid, acq, renewal) {\r\n // Keep data in local storage to retain the last session id, allowing us to cleanly end the session when it expires\r\n // Browsers that don't support local storage won't be able to end sessions cleanly from the client\r\n // The server will notice this and end the sessions itself, with loss of accurate session duration\r\n utlSetLocalStorage(_logger, _storageNamePrefix(), [guid, acq, renewal][_DYN_JOIN /* @min:%2ejoin */](\"|\"));\r\n }\r\n });\r\n }\r\n _SessionManager.prototype.update = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Record the current state of the automatic session and store it in our cookie string format\r\n * into the browser's local storage. This is used to restore the session data when the cookie\r\n * expires.\r\n */\r\n _SessionManager.prototype.backup = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n _SessionManager.acquisitionSpan = 86400000; // 24 hours in ms\r\n _SessionManager.renewalSpan = 1800000; // 30 minutes in ms\r\n _SessionManager.cookieUpdateInterval = 60000; // 1 minute in ms\r\n return _SessionManager;\r\n}());\r\nexport { _SessionManager };\r\n//# sourceMappingURL=Session.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;qDAUM;AACN;AACA;AACA;AACA;AACA;AACA;AACA"}
|
package/dist-esm/Context/User.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Properties Plugin, 2.8.5-nightly.
|
|
2
|
+
* Application Insights JavaScript SDK - Properties Plugin, 2.8.5-nightly.2207-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
8
8
|
import { utlRemoveStorage } from "@microsoft/applicationinsights-common";
|
|
9
|
-
import {
|
|
9
|
+
import { _throwInternal, newId, safeGetCookieMgr, safeGetLogger, toISOString } from "@microsoft/applicationinsights-core-js";
|
|
10
|
+
import { _DYN_ACCOUNT_ID, _DYN_AUTHENTICATED_ID, _DYN_AUTH_USER_COOKIE_NAM8, _DYN_CONFIG, _DYN_COOKIE_SEPARATOR, _DYN_GET_NEW_ID, _DYN_ID_LENGTH, _DYN_IS_NEW_USER, _DYN_IS_USER_COOKIE_SET, _DYN_JOIN, _DYN_LENGTH, _DYN_NAME_PREFIX, _DYN_UPDATE, _DYN_USER_COOKIE_POSTFIX } from "../__DynamicConstants";
|
|
10
11
|
function _validateUserInput(id) {
|
|
11
12
|
// Validate:
|
|
12
13
|
// 1. Id is a non-empty string.
|
|
@@ -32,30 +33,30 @@ var User = /** @class */ (function () {
|
|
|
32
33
|
var _cookieManager = safeGetCookieMgr(core);
|
|
33
34
|
var _storageNamePrefix;
|
|
34
35
|
dynamicProto(User, this, function (_self) {
|
|
35
|
-
_self
|
|
36
|
-
var userCookiePostfix = (_self.config
|
|
36
|
+
_self[_DYN_CONFIG /* @min:%2econfig */] = config;
|
|
37
|
+
var userCookiePostfix = (_self.config[_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */] && _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */]()) ? _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */]() : "";
|
|
37
38
|
_storageNamePrefix = function () { return User.userCookieName + userCookiePostfix; };
|
|
38
39
|
// get userId or create new one if none exists
|
|
39
40
|
var cookie = _cookieManager.get(_storageNamePrefix());
|
|
40
41
|
if (cookie) {
|
|
41
|
-
_self
|
|
42
|
-
var params = cookie.split(User
|
|
43
|
-
if (params
|
|
42
|
+
_self[_DYN_IS_NEW_USER /* @min:%2eisNewUser */] = false;
|
|
43
|
+
var params = cookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);
|
|
44
|
+
if (params[_DYN_LENGTH /* @min:%2elength */] > 0) {
|
|
44
45
|
_self.id = params[0];
|
|
45
46
|
// we already have a cookie
|
|
46
|
-
_self
|
|
47
|
+
_self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = !!_self.id;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
function _generateNewId() {
|
|
50
51
|
var theConfig = (config || {});
|
|
51
|
-
var getNewId = (theConfig
|
|
52
|
-
var id = getNewId(theConfig
|
|
52
|
+
var getNewId = (theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */] ? theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */]() : null) || newId;
|
|
53
|
+
var id = getNewId(theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */] ? config[_DYN_ID_LENGTH /* @min:%2eidLength */]() : 22);
|
|
53
54
|
return id;
|
|
54
55
|
}
|
|
55
56
|
function _generateNewCookie(userId) {
|
|
56
57
|
var acqStr = toISOString(new Date());
|
|
57
58
|
_self.accountAcquisitionDate = acqStr;
|
|
58
|
-
_self
|
|
59
|
+
_self[_DYN_IS_NEW_USER /* @min:%2eisNewUser */] = true;
|
|
59
60
|
var newCookie = [userId, acqStr];
|
|
60
61
|
return newCookie;
|
|
61
62
|
}
|
|
@@ -64,31 +65,31 @@ var User = /** @class */ (function () {
|
|
|
64
65
|
// set it to 365 days from now
|
|
65
66
|
// 365 * 24 * 60 * 60 = 31536000
|
|
66
67
|
var oneYear = 31536000;
|
|
67
|
-
_self
|
|
68
|
+
_self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = _cookieManager.set(_storageNamePrefix(), cookie, oneYear);
|
|
68
69
|
}
|
|
69
70
|
if (!_self.id) {
|
|
70
71
|
_self.id = _generateNewId();
|
|
71
72
|
var newCookie = _generateNewCookie(_self.id);
|
|
72
|
-
_setUserCookie(newCookie
|
|
73
|
+
_setUserCookie(newCookie[_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]));
|
|
73
74
|
// If we have an config.namePrefix() + ai_session in local storage this means the user actively removed our cookies.
|
|
74
75
|
// We should respect their wishes and clear ourselves from local storage
|
|
75
|
-
var name_1 = config
|
|
76
|
+
var name_1 = config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] && config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */]() ? config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */]() + "ai_session" : "ai_session";
|
|
76
77
|
utlRemoveStorage(_logger, name_1);
|
|
77
78
|
}
|
|
78
79
|
// We still take the account id from the ctor param for backward compatibility.
|
|
79
80
|
// But if the the customer set the accountId through the newer setAuthenticatedUserContext API, we will override it.
|
|
80
|
-
_self
|
|
81
|
+
_self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] ? config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */]() : undefined;
|
|
81
82
|
// Get the auth user id and account id from the cookie if exists
|
|
82
83
|
// Cookie is in the pattern: <authenticatedId>|<accountId>
|
|
83
|
-
var authCookie = _cookieManager.get(User
|
|
84
|
+
var authCookie = _cookieManager.get(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */]);
|
|
84
85
|
if (authCookie) {
|
|
85
86
|
authCookie = decodeURI(authCookie);
|
|
86
|
-
var authCookieString = authCookie.split(User
|
|
87
|
+
var authCookieString = authCookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);
|
|
87
88
|
if (authCookieString[0]) {
|
|
88
|
-
_self
|
|
89
|
+
_self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = authCookieString[0];
|
|
89
90
|
}
|
|
90
|
-
if (authCookieString
|
|
91
|
-
_self
|
|
91
|
+
if (authCookieString[_DYN_LENGTH /* @min:%2elength */] > 1 && authCookieString[1]) {
|
|
92
|
+
_self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = authCookieString[1];
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
_self.setAuthenticatedUserContext = function (authenticatedUserId, accountId, storeInCookie) {
|
|
@@ -101,16 +102,16 @@ var User = /** @class */ (function () {
|
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
104
|
// Create cookie string.
|
|
104
|
-
_self
|
|
105
|
-
var authCookie = _self
|
|
105
|
+
_self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = authenticatedUserId;
|
|
106
|
+
var authCookie = _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */];
|
|
106
107
|
if (accountId) {
|
|
107
|
-
_self
|
|
108
|
-
authCookie = [_self
|
|
108
|
+
_self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = accountId;
|
|
109
|
+
authCookie = [_self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */], _self.accountId][_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);
|
|
109
110
|
}
|
|
110
111
|
if (storeInCookie) {
|
|
111
112
|
// Set the cookie. No expiration date because this is a session cookie (expires when browser closed).
|
|
112
113
|
// Encoding the cookie to handle unexpected unicode characters.
|
|
113
|
-
_cookieManager.set(User
|
|
114
|
+
_cookieManager.set(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */], encodeURI(authCookie));
|
|
114
115
|
}
|
|
115
116
|
};
|
|
116
117
|
/**
|
|
@@ -118,16 +119,16 @@ var User = /** @class */ (function () {
|
|
|
118
119
|
* @returns {}
|
|
119
120
|
*/
|
|
120
121
|
_self.clearAuthenticatedUserContext = function () {
|
|
121
|
-
_self
|
|
122
|
-
_self
|
|
123
|
-
_cookieManager.del(User
|
|
122
|
+
_self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = null;
|
|
123
|
+
_self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = null;
|
|
124
|
+
_cookieManager.del(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */]);
|
|
124
125
|
};
|
|
125
|
-
_self
|
|
126
|
+
_self[_DYN_UPDATE /* @min:%2eupdate */] = function (userId) {
|
|
126
127
|
// Optimizations to avoid setting and processing the cookie when not needed
|
|
127
|
-
if (_self.id !== userId || !_self
|
|
128
|
+
if (_self.id !== userId || !_self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */]) {
|
|
128
129
|
var user_id = userId ? userId : _generateNewId();
|
|
129
130
|
var user_cookie = _generateNewCookie(user_id);
|
|
130
|
-
_setUserCookie(user_cookie
|
|
131
|
+
_setUserCookie(user_cookie[_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]));
|
|
131
132
|
}
|
|
132
133
|
};
|
|
133
134
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"User.js.map","sources":["User.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { utlRemoveStorage } from \"@microsoft/applicationinsights-common\";\r\nimport { safeGetCookieMgr, safeGetLogger, newId, toISOString, _throwInternal } from \"@microsoft/applicationinsights-core-js\";\r\nfunction _validateUserInput(id) {\r\n // Validate:\r\n // 1. Id is a non-empty string.\r\n // 2. It does not contain special characters for cookies.\r\n if (typeof id !== \"string\" ||\r\n !id ||\r\n id.match(/,|;|=| |\\|/)) {\r\n return false;\r\n }\r\n return true;\r\n}\r\nvar User = /** @class */ (function () {\r\n function User(config, core) {\r\n /**\r\n * A flag indicating whether this represents a new user\r\n */\r\n this.isNewUser = false;\r\n /**\r\n * A flag indicating whether the user cookie has been set\r\n */\r\n this.isUserCookieSet = false;\r\n var _logger = safeGetLogger(core);\r\n var _cookieManager = safeGetCookieMgr(core);\r\n var _storageNamePrefix;\r\n dynamicProto(User, this, function (_self) {\r\n _self.config = config;\r\n var userCookiePostfix = (_self.config.userCookiePostfix && _self.config.userCookiePostfix()) ? _self.config.userCookiePostfix() : \"\";\r\n _storageNamePrefix = function () { return User.userCookieName + userCookiePostfix; };\r\n // get userId or create new one if none exists\r\n var cookie = _cookieManager.get(_storageNamePrefix());\r\n if (cookie) {\r\n _self.isNewUser = false;\r\n var params = cookie.split(User.cookieSeparator);\r\n if (params.length > 0) {\r\n _self.id = params[0];\r\n // we already have a cookie\r\n _self.isUserCookieSet = !!_self.id;\r\n }\r\n }\r\n function _generateNewId() {\r\n var theConfig = (config || {});\r\n var getNewId = (theConfig.getNewId ? theConfig.getNewId() : null) || newId;\r\n var id = getNewId(theConfig.idLength ? config.idLength() : 22);\r\n return id;\r\n }\r\n function _generateNewCookie(userId) {\r\n var acqStr = toISOString(new Date());\r\n _self.accountAcquisitionDate = acqStr;\r\n _self.isNewUser = true;\r\n var newCookie = [userId, acqStr];\r\n return newCookie;\r\n }\r\n function _setUserCookie(cookie) {\r\n // without expiration, cookies expire at the end of the session\r\n // set it to 365 days from now\r\n // 365 * 24 * 60 * 60 = 31536000\r\n var oneYear = 31536000;\r\n _self.isUserCookieSet = _cookieManager.set(_storageNamePrefix(), cookie, oneYear);\r\n }\r\n if (!_self.id) {\r\n _self.id = _generateNewId();\r\n var newCookie = _generateNewCookie(_self.id);\r\n _setUserCookie(newCookie.join(User.cookieSeparator));\r\n // If we have an config.namePrefix() + ai_session in local storage this means the user actively removed our cookies.\r\n // We should respect their wishes and clear ourselves from local storage\r\n var name_1 = config.namePrefix && config.namePrefix() ? config.namePrefix() + \"ai_session\" : \"ai_session\";\r\n utlRemoveStorage(_logger, name_1);\r\n }\r\n // We still take the account id from the ctor param for backward compatibility.\r\n // But if the the customer set the accountId through the newer setAuthenticatedUserContext API, we will override it.\r\n _self.accountId = config.accountId ? config.accountId() : undefined;\r\n // Get the auth user id and account id from the cookie if exists\r\n // Cookie is in the pattern: <authenticatedId>|<accountId>\r\n var authCookie = _cookieManager.get(User.authUserCookieName);\r\n if (authCookie) {\r\n authCookie = decodeURI(authCookie);\r\n var authCookieString = authCookie.split(User.cookieSeparator);\r\n if (authCookieString[0]) {\r\n _self.authenticatedId = authCookieString[0];\r\n }\r\n if (authCookieString.length > 1 && authCookieString[1]) {\r\n _self.accountId = authCookieString[1];\r\n }\r\n }\r\n _self.setAuthenticatedUserContext = function (authenticatedUserId, accountId, storeInCookie) {\r\n if (storeInCookie === void 0) { storeInCookie = false; }\r\n // Validate inputs to ensure no cookie control characters.\r\n var isInvalidInput = !_validateUserInput(authenticatedUserId) || (accountId && !_validateUserInput(accountId));\r\n if (isInvalidInput) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 60 /* _eInternalMessageId.SetAuthContextFailedAccountName */, \"Setting auth user context failed. \" +\r\n \"User auth/account id should be of type string, and not contain commas, semi-colons, equal signs, spaces, or vertical-bars.\", true);\r\n return;\r\n }\r\n // Create cookie string.\r\n _self.authenticatedId = authenticatedUserId;\r\n var authCookie = _self.authenticatedId;\r\n if (accountId) {\r\n _self.accountId = accountId;\r\n authCookie = [_self.authenticatedId, _self.accountId].join(User.cookieSeparator);\r\n }\r\n if (storeInCookie) {\r\n // Set the cookie. No expiration date because this is a session cookie (expires when browser closed).\r\n // Encoding the cookie to handle unexpected unicode characters.\r\n _cookieManager.set(User.authUserCookieName, encodeURI(authCookie));\r\n }\r\n };\r\n /**\r\n * Clears the authenticated user id and the account id from the user context.\r\n * @returns {}\r\n */\r\n _self.clearAuthenticatedUserContext = function () {\r\n _self.authenticatedId = null;\r\n _self.accountId = null;\r\n _cookieManager.del(User.authUserCookieName);\r\n };\r\n _self.update = function (userId) {\r\n // Optimizations to avoid setting and processing the cookie when not needed\r\n if (_self.id !== userId || !_self.isUserCookieSet) {\r\n var user_id = userId ? userId : _generateNewId();\r\n var user_cookie = _generateNewCookie(user_id);\r\n _setUserCookie(user_cookie.join(User.cookieSeparator));\r\n }\r\n };\r\n });\r\n }\r\n /**\r\n * Sets the authenticated user id and the account id in this session.\r\n *\r\n * @param authenticatedUserId {string} - The authenticated user id. A unique and persistent string that represents each authenticated user in the service.\r\n * @param accountId {string} - An optional string to represent the account associated with the authenticated user.\r\n */\r\n User.prototype.setAuthenticatedUserContext = function (authenticatedUserId, accountId, storeInCookie) {\r\n if (storeInCookie === void 0) { storeInCookie = false; }\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Clears the authenticated user id and the account id from the user context.\r\n * @returns {}\r\n */\r\n User.prototype.clearAuthenticatedUserContext = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Update or create the user cookie if cookies where previously disabled or the new userId does not match the existing value.\r\n * If you pass nothing a new random user id will be created.\r\n * @param userId - Specific either the current (via appInsights.context.user.id) or new id that you want to set\r\n */\r\n User.prototype.update = function (userId) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n User.cookieSeparator = \"|\";\r\n User.userCookieName = \"ai_user\";\r\n User.authUserCookieName = \"ai_authUser\";\r\n return User;\r\n}());\r\nexport { User };\r\n//# sourceMappingURL=User.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;0CAwBM;AACN;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"User.js.map","sources":["User.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { utlRemoveStorage } from \"@microsoft/applicationinsights-common\";\r\nimport { _throwInternal, newId, safeGetCookieMgr, safeGetLogger, toISOString } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_ACCOUNT_ID, _DYN_AUTHENTICATED_ID, _DYN_AUTH_USER_COOKIE_NAM8, _DYN_CONFIG, _DYN_COOKIE_SEPARATOR, _DYN_GET_NEW_ID, _DYN_ID_LENGTH, _DYN_IS_NEW_USER, _DYN_IS_USER_COOKIE_SET, _DYN_JOIN, _DYN_LENGTH, _DYN_NAME_PREFIX, _DYN_UPDATE, _DYN_USER_COOKIE_POSTFIX } from \"../__DynamicConstants\";\r\nfunction _validateUserInput(id) {\r\n // Validate:\r\n // 1. Id is a non-empty string.\r\n // 2. It does not contain special characters for cookies.\r\n if (typeof id !== \"string\" ||\r\n !id ||\r\n id.match(/,|;|=| |\\|/)) {\r\n return false;\r\n }\r\n return true;\r\n}\r\nvar User = /** @class */ (function () {\r\n function User(config, core) {\r\n /**\r\n * A flag indicating whether this represents a new user\r\n */\r\n this.isNewUser = false;\r\n /**\r\n * A flag indicating whether the user cookie has been set\r\n */\r\n this.isUserCookieSet = false;\r\n var _logger = safeGetLogger(core);\r\n var _cookieManager = safeGetCookieMgr(core);\r\n var _storageNamePrefix;\r\n dynamicProto(User, this, function (_self) {\r\n _self[_DYN_CONFIG /* @min:%2econfig */] = config;\r\n var userCookiePostfix = (_self.config[_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */] && _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */]()) ? _self[_DYN_CONFIG /* @min:%2econfig */][_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */]() : \"\";\r\n _storageNamePrefix = function () { return User.userCookieName + userCookiePostfix; };\r\n // get userId or create new one if none exists\r\n var cookie = _cookieManager.get(_storageNamePrefix());\r\n if (cookie) {\r\n _self[_DYN_IS_NEW_USER /* @min:%2eisNewUser */] = false;\r\n var params = cookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);\r\n if (params[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n _self.id = params[0];\r\n // we already have a cookie\r\n _self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = !!_self.id;\r\n }\r\n }\r\n function _generateNewId() {\r\n var theConfig = (config || {});\r\n var getNewId = (theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */] ? theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */]() : null) || newId;\r\n var id = getNewId(theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */] ? config[_DYN_ID_LENGTH /* @min:%2eidLength */]() : 22);\r\n return id;\r\n }\r\n function _generateNewCookie(userId) {\r\n var acqStr = toISOString(new Date());\r\n _self.accountAcquisitionDate = acqStr;\r\n _self[_DYN_IS_NEW_USER /* @min:%2eisNewUser */] = true;\r\n var newCookie = [userId, acqStr];\r\n return newCookie;\r\n }\r\n function _setUserCookie(cookie) {\r\n // without expiration, cookies expire at the end of the session\r\n // set it to 365 days from now\r\n // 365 * 24 * 60 * 60 = 31536000\r\n var oneYear = 31536000;\r\n _self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = _cookieManager.set(_storageNamePrefix(), cookie, oneYear);\r\n }\r\n if (!_self.id) {\r\n _self.id = _generateNewId();\r\n var newCookie = _generateNewCookie(_self.id);\r\n _setUserCookie(newCookie[_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]));\r\n // If we have an config.namePrefix() + ai_session in local storage this means the user actively removed our cookies.\r\n // We should respect their wishes and clear ourselves from local storage\r\n var name_1 = config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] && config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */]() ? config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */]() + \"ai_session\" : \"ai_session\";\r\n utlRemoveStorage(_logger, name_1);\r\n }\r\n // We still take the account id from the ctor param for backward compatibility.\r\n // But if the the customer set the accountId through the newer setAuthenticatedUserContext API, we will override it.\r\n _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] ? config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */]() : undefined;\r\n // Get the auth user id and account id from the cookie if exists\r\n // Cookie is in the pattern: <authenticatedId>|<accountId>\r\n var authCookie = _cookieManager.get(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */]);\r\n if (authCookie) {\r\n authCookie = decodeURI(authCookie);\r\n var authCookieString = authCookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);\r\n if (authCookieString[0]) {\r\n _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = authCookieString[0];\r\n }\r\n if (authCookieString[_DYN_LENGTH /* @min:%2elength */] > 1 && authCookieString[1]) {\r\n _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = authCookieString[1];\r\n }\r\n }\r\n _self.setAuthenticatedUserContext = function (authenticatedUserId, accountId, storeInCookie) {\r\n if (storeInCookie === void 0) { storeInCookie = false; }\r\n // Validate inputs to ensure no cookie control characters.\r\n var isInvalidInput = !_validateUserInput(authenticatedUserId) || (accountId && !_validateUserInput(accountId));\r\n if (isInvalidInput) {\r\n _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 60 /* _eInternalMessageId.SetAuthContextFailedAccountName */, \"Setting auth user context failed. \" +\r\n \"User auth/account id should be of type string, and not contain commas, semi-colons, equal signs, spaces, or vertical-bars.\", true);\r\n return;\r\n }\r\n // Create cookie string.\r\n _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = authenticatedUserId;\r\n var authCookie = _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */];\r\n if (accountId) {\r\n _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = accountId;\r\n authCookie = [_self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */], _self.accountId][_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);\r\n }\r\n if (storeInCookie) {\r\n // Set the cookie. No expiration date because this is a session cookie (expires when browser closed).\r\n // Encoding the cookie to handle unexpected unicode characters.\r\n _cookieManager.set(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */], encodeURI(authCookie));\r\n }\r\n };\r\n /**\r\n * Clears the authenticated user id and the account id from the user context.\r\n * @returns {}\r\n */\r\n _self.clearAuthenticatedUserContext = function () {\r\n _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = null;\r\n _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = null;\r\n _cookieManager.del(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */]);\r\n };\r\n _self[_DYN_UPDATE /* @min:%2eupdate */] = function (userId) {\r\n // Optimizations to avoid setting and processing the cookie when not needed\r\n if (_self.id !== userId || !_self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */]) {\r\n var user_id = userId ? userId : _generateNewId();\r\n var user_cookie = _generateNewCookie(user_id);\r\n _setUserCookie(user_cookie[_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]));\r\n }\r\n };\r\n });\r\n }\r\n /**\r\n * Sets the authenticated user id and the account id in this session.\r\n *\r\n * @param authenticatedUserId {string} - The authenticated user id. A unique and persistent string that represents each authenticated user in the service.\r\n * @param accountId {string} - An optional string to represent the account associated with the authenticated user.\r\n */\r\n User.prototype.setAuthenticatedUserContext = function (authenticatedUserId, accountId, storeInCookie) {\r\n if (storeInCookie === void 0) { storeInCookie = false; }\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Clears the authenticated user id and the account id from the user context.\r\n * @returns {}\r\n */\r\n User.prototype.clearAuthenticatedUserContext = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Update or create the user cookie if cookies where previously disabled or the new userId does not match the existing value.\r\n * If you pass nothing a new random user id will be created.\r\n * @param userId - Specific either the current (via appInsights.context.user.id) or new id that you want to set\r\n */\r\n User.prototype.update = function (userId) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n User.cookieSeparator = \"|\";\r\n User.userCookieName = \"ai_user\";\r\n User.authUserCookieName = \"ai_authUser\";\r\n return User;\r\n}());\r\nexport { User };\r\n//# sourceMappingURL=User.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;0CAwBM;AACN;AACA;AACA;AACA;AACA;AACA;AACA"}
|