@microsoft/applicationinsights-properties-js 3.0.0-beta.2210-01 → 3.0.0-beta.2210-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.
Files changed (51) hide show
  1. package/browser/applicationinsights-properties-js.integrity.json +9 -9
  2. package/browser/applicationinsights-properties-js.js +938 -495
  3. package/browser/applicationinsights-properties-js.js.map +1 -1
  4. package/browser/applicationinsights-properties-js.min.js +2 -2
  5. package/browser/applicationinsights-properties-js.min.js.map +1 -1
  6. package/dist/applicationinsights-properties-js.api.json +21 -169
  7. package/dist/applicationinsights-properties-js.api.md +9 -20
  8. package/dist/applicationinsights-properties-js.d.ts +28 -33
  9. package/dist/applicationinsights-properties-js.js +938 -495
  10. package/dist/applicationinsights-properties-js.js.map +1 -1
  11. package/dist/applicationinsights-properties-js.min.js +2 -2
  12. package/dist/applicationinsights-properties-js.min.js.map +1 -1
  13. package/dist/applicationinsights-properties-js.rollup.d.ts +28 -33
  14. package/dist-esm/Context/Application.js +1 -1
  15. package/dist-esm/Context/Device.js +1 -1
  16. package/dist-esm/Context/Internal.js +3 -3
  17. package/dist-esm/Context/Internal.js.map +1 -1
  18. package/dist-esm/Context/Location.js +1 -1
  19. package/dist-esm/Context/Session.js +30 -35
  20. package/dist-esm/Context/Session.js.map +1 -1
  21. package/dist-esm/Context/TelemetryTrace.js +1 -1
  22. package/dist-esm/Context/User.js +54 -46
  23. package/dist-esm/Context/User.js.map +1 -1
  24. package/dist-esm/Interfaces/IPropTelemetryContext.js +1 -1
  25. package/dist-esm/Interfaces/{ITelemetryConfig.js → IPropertiesConfig.js} +2 -2
  26. package/dist-esm/Interfaces/IPropertiesConfig.js.map +1 -0
  27. package/dist-esm/PropertiesPlugin.js +57 -50
  28. package/dist-esm/PropertiesPlugin.js.map +1 -1
  29. package/dist-esm/TelemetryContext.js +7 -5
  30. package/dist-esm/TelemetryContext.js.map +1 -1
  31. package/dist-esm/__DynamicConstants.js +8 -13
  32. package/dist-esm/__DynamicConstants.js.map +1 -1
  33. package/dist-esm/applicationinsights-properties-js.js +1 -1
  34. package/package.json +4 -4
  35. package/src/Context/Internal.ts +10 -9
  36. package/src/Context/Session.ts +33 -45
  37. package/src/Context/User.ts +67 -56
  38. package/src/Interfaces/IPropertiesConfig.ts +20 -0
  39. package/src/PropertiesPlugin.ts +58 -54
  40. package/src/TelemetryContext.ts +8 -4
  41. package/src/__DynamicConstants.ts +7 -12
  42. package/types/Context/Internal.d.ts +2 -2
  43. package/types/Context/Session.d.ts +7 -11
  44. package/types/Context/User.d.ts +5 -5
  45. package/types/Interfaces/IPropertiesConfig.d.ts +17 -0
  46. package/types/PropertiesPlugin.d.ts +1 -3
  47. package/types/TelemetryContext.d.ts +2 -2
  48. package/types/__DynamicConstants.d.ts +1 -6
  49. package/dist-esm/Interfaces/ITelemetryConfig.js.map +0 -1
  50. package/src/Interfaces/ITelemetryConfig.ts +0 -20
  51. package/types/Interfaces/ITelemetryConfig.d.ts +0 -17
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights properties plugin, 3.0.0-beta.2210-01
2
+ * Microsoft Application Insights properties plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -36,6 +36,24 @@ import { ITraceState } from '@microsoft/applicationinsights-common';
36
36
  import { IUserContext } from '@microsoft/applicationinsights-common';
37
37
  import { IWeb } from '@microsoft/applicationinsights-common';
38
38
 
39
+ declare interface IPropertiesConfig {
40
+ readonly instrumentationKey: string;
41
+ readonly accountId: string;
42
+ readonly sessionRenewalMs: number;
43
+ readonly samplingPercentage: number;
44
+ readonly sessionExpirationMs: number;
45
+ readonly cookieDomain: string;
46
+ readonly sdkExtension: string;
47
+ readonly isBrowserLinkTrackingEnabled: boolean;
48
+ readonly appId: string;
49
+ readonly getSessionId: string;
50
+ readonly namePrefix: string;
51
+ readonly sessionCookiePostfix: string;
52
+ readonly userCookiePostfix: string;
53
+ readonly idLength: number;
54
+ readonly getNewId: (idLength?: number) => string;
55
+ }
56
+
39
57
  export declare interface IPropTelemetryContext extends ITelemetryContext {
40
58
  readonly sessionManager: SessionManager;
41
59
  applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
@@ -51,38 +69,19 @@ export declare interface IPropTelemetryContext extends ITelemetryContext {
51
69
  }
52
70
 
53
71
  export declare interface ISessionConfig {
54
- sessionRenewalMs?: () => number;
55
- sessionExpirationMs?: () => number;
56
- namePrefix?: () => string;
57
- sessionCookiePostfix?: () => string;
58
- idLength?: () => number;
59
- getNewId?: () => (idLength?: number) => string;
72
+ readonly sessionRenewalMs?: number;
73
+ readonly sessionExpirationMs?: number;
74
+ readonly namePrefix?: string;
75
+ readonly sessionCookiePostfix?: string;
76
+ readonly idLength?: number;
77
+ readonly getNewId?: (idLength?: number) => string;
60
78
  /**
61
79
  * @deprecated Avoid using this value to override the cookie manager cookie domain.
62
80
  */
63
- cookieDomain?: () => string;
64
- }
65
-
66
- declare interface ITelemetryConfig {
67
- instrumentationKey: () => string;
68
- accountId: () => string;
69
- sessionRenewalMs: () => number;
70
- samplingPercentage: () => number;
71
- sessionExpirationMs: () => number;
72
- cookieDomain: () => null;
73
- sdkExtension: () => string;
74
- isBrowserLinkTrackingEnabled: () => boolean;
75
- appId: () => string;
76
- getSessionId: () => string;
77
- namePrefix: () => string;
78
- sessionCookiePostfix: () => string;
79
- userCookiePostfix: () => string;
80
- idLength: () => number;
81
- getNewId: () => (idLength?: number) => string;
81
+ cookieDomain?: string;
82
82
  }
83
83
 
84
84
  export declare class PropertiesPlugin extends BaseTelemetryPlugin implements IPropertiesPlugin {
85
- static getDefaultConfig(): ITelemetryConfig;
86
85
  context: IPropTelemetryContext;
87
86
  priority: number;
88
87
  identifier: string;
@@ -90,7 +89,7 @@ export declare class PropertiesPlugin extends BaseTelemetryPlugin implements IPr
90
89
  initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
91
90
  /**
92
91
  * Add Part A fields to the event
93
- * @param event The event that needs to be processed
92
+ * @param event - The event that needs to be processed
94
93
  */
95
94
  processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
96
95
  }
@@ -114,11 +113,7 @@ export declare class Session implements ISession {
114
113
  }
115
114
 
116
115
  export declare class SessionManager {
117
- static acquisitionSpan: number;
118
- static renewalSpan: number;
119
- static cookieUpdateInterval: number;
120
116
  automaticSession: Session;
121
- config: ISessionConfig;
122
117
  constructor(config: ISessionConfig, core?: IAppInsightsCore);
123
118
  update(): void;
124
119
  /**
@@ -142,7 +137,7 @@ export declare class TelemetryContext implements IPropTelemetryContext {
142
137
  web: IWeb;
143
138
  appId: () => string;
144
139
  getSessionId: () => string;
145
- constructor(core: IAppInsightsCore, defaultConfig: ITelemetryConfig, previousTraceCtx?: IDistributedTraceContext);
140
+ constructor(core: IAppInsightsCore, defaultConfig: IPropertiesConfig, previousTraceCtx?: IDistributedTraceContext);
146
141
  applySessionContext(evt: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
147
142
  applyOperatingSystemContxt(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
148
143
  applyApplicationContext(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,17 +1,17 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
6
6
 
7
- import { _DYN_SDK_EXTENSION } from "../__DynamicConstants";
8
7
  var Version = "2.8.5";
9
8
  var Internal = /** @class */ (function () {
10
9
  /**
11
10
  * Constructs a new instance of the internal telemetry data class.
12
11
  */
13
12
  function Internal(config) {
14
- this.sdkVersion = (config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */] && config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */]() ? config[_DYN_SDK_EXTENSION /* @min:%2esdkExtension */]() + "_" : "") + "javascript:" + Version;
13
+ var prefix = config.sdkExtension;
14
+ this.sdkVersion = (prefix ? prefix + "_" : "") + "javascript:" + Version;
15
15
  }
16
16
  return Internal;
17
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\nimport { _DYN_SDK_EXTENSION } from \"../__DynamicConstants\";\r\nvar Version = \"2.8.5\";\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
+ {"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\";\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 var prefix = config.sdkExtension;\r\n this.sdkVersion = (prefix ? prefix + \"_\" : \"\") + \"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,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -7,8 +7,11 @@
7
7
  import dynamicProto from "@microsoft/dynamicproto-js";
8
8
  import { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "@microsoft/applicationinsights-common";
9
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";
11
- var cookieNameConst = "ai_session";
10
+ import { _DYN_ACQUISITION_DATE, _DYN_AUTOMATIC_SESSION, _DYN_GET_NEW_ID, _DYN_ID_LENGTH, _DYN_JOIN, _DYN_LENGTH, _DYN_NAME_PREFIX, _DYN_RENEWAL_DATE, _DYN_UPDATE } from "../__DynamicConstants";
11
+ var SESSION_COOKIE_NAME = "ai_session";
12
+ var ACQUISITION_SPAN = 86400000; // 24 hours in ms
13
+ var RENEWAL_SPAN = 1800000; // 30 minutes in ms
14
+ var COOKIE_UPDATE_INTERVAL = 60000; // 1 minute in ms
12
15
  var Session = /** @class */ (function () {
13
16
  function Session() {
14
17
  }
@@ -22,22 +25,17 @@ var _SessionManager = /** @class */ (function () {
22
25
  var _cookieUpdatedTimestamp;
23
26
  var _logger = safeGetLogger(core);
24
27
  var _cookieManager = safeGetCookieMgr(core);
28
+ var _sessionExpirationMs;
29
+ var _sessionRenewalMs;
25
30
  dynamicProto(_SessionManager, self, function (_self) {
26
31
  if (!config) {
27
32
  config = {};
28
33
  }
29
- if (!isFunction(config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */])) {
30
- config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */] = function () { return _SessionManager.acquisitionSpan; };
31
- }
32
- if (!isFunction(config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */])) {
33
- config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */] = function () { return _SessionManager.renewalSpan; };
34
- }
35
- _self[_DYN_CONFIG /* @min:%2econfig */] = config;
34
+ _sessionExpirationMs = config.sessionExpirationMs || ACQUISITION_SPAN;
35
+ _sessionRenewalMs = config.sessionRenewalMs || RENEWAL_SPAN;
36
36
  // sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.
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 */]() : "");
40
- _storageNamePrefix = function () { return cookieNameConst + sessionCookiePostfix; };
37
+ var sessionCookiePostfix = config.sessionCookiePostfix || config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] || "";
38
+ _storageNamePrefix = SESSION_COOKIE_NAME + sessionCookiePostfix;
41
39
  _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */] = new Session();
42
40
  _self[_DYN_UPDATE /* @min:%2eupdate */] = function () {
43
41
  // 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
@@ -48,14 +46,12 @@ var _SessionManager = /** @class */ (function () {
48
46
  if (!session.id) {
49
47
  isExpired = !_initializeAutomaticSession(session, nowMs);
50
48
  }
51
- var sessionExpirationMs = _self.config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]();
52
- if (!isExpired && sessionExpirationMs > 0) {
53
- var sessionRenewalMs = _self.config[_DYN_SESSION_RENEWAL_MS /* @min:%2esessionRenewalMs */]();
49
+ if (!isExpired && _sessionExpirationMs > 0) {
54
50
  var timeSinceAcqMs = nowMs - session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */];
55
51
  var timeSinceRenewalMs = nowMs - session[_DYN_RENEWAL_DATE /* @min:%2erenewalDate */];
56
52
  isExpired = timeSinceAcqMs < 0 || timeSinceRenewalMs < 0; // expired if the acquisition or last renewal are in the future
57
- isExpired = isExpired || timeSinceAcqMs > sessionExpirationMs; // expired if the time since acquisition is more than session Expiration
58
- isExpired = isExpired || timeSinceRenewalMs > sessionRenewalMs; // expired if the time since last renewal is more than renewal period
53
+ isExpired = isExpired || timeSinceAcqMs > _sessionExpirationMs; // expired if the time since acquisition is more than session Expiration
54
+ isExpired = isExpired || timeSinceRenewalMs > _sessionRenewalMs; // expired if the time since last renewal is more than renewal period
59
55
  }
60
56
  // renew if acquisitionSpan or renewalSpan has elapsed
61
57
  if (isExpired) {
@@ -64,7 +60,7 @@ var _SessionManager = /** @class */ (function () {
64
60
  }
65
61
  else {
66
62
  // do not update the cookie more often than cookieUpdateInterval
67
- if (!_cookieUpdatedTimestamp || nowMs - _cookieUpdatedTimestamp > _SessionManager.cookieUpdateInterval) {
63
+ if (!_cookieUpdatedTimestamp || nowMs - _cookieUpdatedTimestamp > COOKIE_UPDATE_INTERVAL) {
68
64
  _setCookie(session, nowMs);
69
65
  }
70
66
  }
@@ -85,7 +81,7 @@ var _SessionManager = /** @class */ (function () {
85
81
  */
86
82
  function _initializeAutomaticSession(session, now) {
87
83
  var isValid = false;
88
- var cookieValue = _cookieManager.get(_storageNamePrefix());
84
+ var cookieValue = _cookieManager.get(_storageNamePrefix);
89
85
  if (cookieValue && isFunction(cookieValue.split)) {
90
86
  isValid = _initializeAutomaticSessionWithData(session, cookieValue);
91
87
  }
@@ -94,7 +90,7 @@ var _SessionManager = /** @class */ (function () {
94
90
  // This can happen if the session expired or the user actively deleted the cookie
95
91
  // 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.
96
92
  // The User class handles this for us and deletes our local storage object if the persistent user cookie was removed.
97
- var storageValue = utlGetLocalStorage(_logger, _storageNamePrefix());
93
+ var storageValue = utlGetLocalStorage(_logger, _storageNamePrefix);
98
94
  if (storageValue) {
99
95
  isValid = _initializeAutomaticSessionWithData(session, storageValue);
100
96
  }
@@ -105,7 +101,7 @@ var _SessionManager = /** @class */ (function () {
105
101
  * Extract id, acquisitionDate, and renewalDate from an ai_session payload string and
106
102
  * use this data to initialize automaticSession.
107
103
  *
108
- * @param {string} sessionData - The string stored in an ai_session cookie or local storage backup
104
+ * @param sessionData - The string stored in an ai_session cookie or local storage backup
109
105
  * @returns true if values set otherwise false
110
106
  */
111
107
  function _initializeAutomaticSessionWithData(session, sessionData) {
@@ -137,9 +133,8 @@ var _SessionManager = /** @class */ (function () {
137
133
  return isValid;
138
134
  }
139
135
  function _renew(nowMs) {
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);
136
+ var getNewId = config[_DYN_GET_NEW_ID /* @min:%2egetNewId */] || newId;
137
+ _self.automaticSession.id = getNewId(config[_DYN_ID_LENGTH /* @min:%2eidLength */] || 22);
143
138
  _self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */][_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */] = nowMs;
144
139
  _setCookie(_self[_DYN_AUTOMATIC_SESSION /* @min:%2eautomaticSession */], nowMs);
145
140
  // If this browser does not support local storage, fire an internal log to keep track of it at this point
@@ -150,11 +145,10 @@ var _SessionManager = /** @class */ (function () {
150
145
  function _setCookie(session, nowMs) {
151
146
  var acq = session[_DYN_ACQUISITION_DATE /* @min:%2eacquisitionDate */];
152
147
  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 */]();
148
+ var renewalPeriodMs = _sessionRenewalMs;
155
149
  // Set cookie to expire after the session expiry time passes or the session renewal deadline, whichever is sooner
156
150
  // Expiring the cookie will cause the session to expire even if the user isn't on the page
157
- var acqTimeLeftMs = (acq + config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]()) - nowMs;
151
+ var acqTimeLeftMs = (acq + _sessionExpirationMs) - nowMs;
158
152
  var cookie = [session.id, acq, nowMs];
159
153
  var maxAgeSec = 0;
160
154
  if (acqTimeLeftMs < renewalPeriodMs) {
@@ -163,26 +157,27 @@ var _SessionManager = /** @class */ (function () {
163
157
  else {
164
158
  maxAgeSec = renewalPeriodMs / 1000;
165
159
  }
166
- var cookieDomain = config[_DYN_COOKIE_DOMAIN /* @min:%2ecookieDomain */] ? config[_DYN_COOKIE_DOMAIN /* @min:%2ecookieDomain */]() : null;
160
+ var cookieDomain = config.cookieDomain || null;
167
161
  // if sessionExpirationMs is set to 0, it means the expiry is set to 0 for this session cookie
168
162
  // A cookie with 0 expiry in the session cookie will never expire for that browser session. If the browser is closed the cookie expires.
169
163
  // Depending on the browser, another instance does not inherit this cookie, however, another tab will
170
- _cookieManager.set(_storageNamePrefix(), cookie.join("|"), config[_DYN_SESSION_EXPIRATION_M7 /* @min:%2esessionExpirationMs */]() > 0 ? maxAgeSec : null, cookieDomain);
164
+ _cookieManager.set(_storageNamePrefix, cookie[_DYN_JOIN /* @min:%2ejoin */]("|"), _sessionExpirationMs > 0 ? maxAgeSec : null, cookieDomain);
171
165
  _cookieUpdatedTimestamp = nowMs;
172
166
  }
173
167
  function _setStorage(guid, acq, renewal) {
174
168
  // Keep data in local storage to retain the last session id, allowing us to cleanly end the session when it expires
175
169
  // Browsers that don't support local storage won't be able to end sessions cleanly from the client
176
170
  // The server will notice this and end the sessions itself, with loss of accurate session duration
177
- utlSetLocalStorage(_logger, _storageNamePrefix(), [guid, acq, renewal][_DYN_JOIN /* @min:%2ejoin */]("|"));
171
+ utlSetLocalStorage(_logger, _storageNamePrefix, [guid, acq, renewal][_DYN_JOIN /* @min:%2ejoin */]("|"));
178
172
  }
179
173
  });
180
174
  }
181
175
  // Removed Stub for _SessionManager.prototype.update.
182
176
  // Removed Stub for _SessionManager.prototype.backup.
183
- _SessionManager.acquisitionSpan = 86400000; // 24 hours in ms
184
- _SessionManager.renewalSpan = 1800000; // 30 minutes in ms
185
- _SessionManager.cookieUpdateInterval = 60000; // 1 minute in ms
177
+ // This is a workaround for an IE bug when using dynamicProto() with classes that don't have any
178
+ // non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
179
+ _SessionManager.__ieDyn=1;
180
+
186
181
  return _SessionManager;
187
182
  }());
188
183
  export { _SessionManager };
@@ -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 { _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"}
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_GET_NEW_ID, _DYN_ID_LENGTH, _DYN_JOIN, _DYN_LENGTH, _DYN_NAME_PREFIX, _DYN_RENEWAL_DATE, _DYN_UPDATE } from \"../__DynamicConstants\";\r\nvar SESSION_COOKIE_NAME = \"ai_session\";\r\nvar ACQUISITION_SPAN = 86400000; // 24 hours in ms\r\nvar RENEWAL_SPAN = 1800000; // 30 minutes in ms\r\nvar COOKIE_UPDATE_INTERVAL = 60000; // 1 minute in ms\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 var _sessionExpirationMs;\r\n var _sessionRenewalMs;\r\n dynamicProto(_SessionManager, self, function (_self) {\r\n if (!config) {\r\n config = {};\r\n }\r\n _sessionExpirationMs = config.sessionExpirationMs || ACQUISITION_SPAN;\r\n _sessionRenewalMs = config.sessionRenewalMs || RENEWAL_SPAN;\r\n // sessionCookiePostfix takes the preference if it is configured, otherwise takes namePrefix if configured.\r\n var sessionCookiePostfix = config.sessionCookiePostfix || config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] || \"\";\r\n _storageNamePrefix = SESSION_COOKIE_NAME + 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 if (!isExpired && _sessionExpirationMs > 0) {\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 > COOKIE_UPDATE_INTERVAL) {\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 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 getNewId = config[_DYN_GET_NEW_ID /* @min:%2egetNewId */] || newId;\r\n _self.automaticSession.id = getNewId(config[_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 renewalPeriodMs = _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 + _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 || 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[_DYN_JOIN /* @min:%2ejoin */](\"|\"), _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][_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 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;qDAUM,CAAC;;;;;2BACoB;AAC3B;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,13 +1,14 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-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 { _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";
9
+ import { _throwInternal, newId, onConfigChange, safeGetCookieMgr, safeGetLogger, toISOString } from "@microsoft/applicationinsights-core-js";
10
+ import { objDefineProp } from "@nevware21/ts-utils";
11
+ import { _DYN_ACCOUNT_ID, _DYN_AUTHENTICATED_ID, _DYN_AUTH_USER_COOKIE_NAM7, _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";
11
12
  function _validateUserInput(id) {
12
13
  // Validate:
13
14
  // 1. Id is a non-empty string.
@@ -33,24 +34,56 @@ var User = /** @class */ (function () {
33
34
  var _cookieManager = safeGetCookieMgr(core);
34
35
  var _storageNamePrefix;
35
36
  dynamicProto(User, this, function (_self) {
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 */]() : "";
38
- _storageNamePrefix = function () { return User.userCookieName + userCookiePostfix; };
39
- // get userId or create new one if none exists
40
- var cookie = _cookieManager.get(_storageNamePrefix());
41
- if (cookie) {
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) {
45
- _self.id = params[0];
46
- // we already have a cookie
47
- _self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = !!_self.id;
37
+ // Define _self.config
38
+ objDefineProp(_self, "config", {
39
+ configurable: true,
40
+ enumerable: true,
41
+ get: function () { return config; }
42
+ });
43
+ onConfigChange(config, function () {
44
+ var userCookiePostfix = config[_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */] || "";
45
+ _storageNamePrefix = User.userCookieName + userCookiePostfix;
46
+ // get userId or create new one if none exists
47
+ var cookie = _cookieManager.get(_storageNamePrefix);
48
+ if (cookie) {
49
+ _self[_DYN_IS_NEW_USER /* @min:%2eisNewUser */] = false;
50
+ var params = cookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);
51
+ if (params[_DYN_LENGTH /* @min:%2elength */] > 0) {
52
+ _self.id = params[0];
53
+ // we already have a cookie
54
+ _self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = !!_self.id;
55
+ }
48
56
  }
49
- }
57
+ if (!_self.id) {
58
+ _self.id = _generateNewId();
59
+ var newCookie = _generateNewCookie(_self.id);
60
+ _setUserCookie(newCookie[_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]));
61
+ // If we have an config.namePrefix() + ai_session in local storage this means the user actively removed our cookies.
62
+ // We should respect their wishes and clear ourselves from local storage
63
+ var name_1 = (config[_DYN_NAME_PREFIX /* @min:%2enamePrefix */] || "") + "ai_session";
64
+ utlRemoveStorage(_logger, name_1);
65
+ }
66
+ // We still take the account id from the ctor param for backward compatibility.
67
+ // But if the the customer set the accountId through the newer setAuthenticatedUserContext API, we will override it.
68
+ _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] || undefined;
69
+ // Get the auth user id and account id from the cookie if exists
70
+ // Cookie is in the pattern: <authenticatedId>|<accountId>
71
+ var authCookie = _cookieManager.get(User[_DYN_AUTH_USER_COOKIE_NAM7 /* @min:%2eauthUserCookieName */]);
72
+ if (authCookie) {
73
+ authCookie = decodeURI(authCookie);
74
+ var authCookieString = authCookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);
75
+ if (authCookieString[0]) {
76
+ _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = authCookieString[0];
77
+ }
78
+ if (authCookieString[_DYN_LENGTH /* @min:%2elength */] > 1 && authCookieString[1]) {
79
+ _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = authCookieString[1];
80
+ }
81
+ }
82
+ });
50
83
  function _generateNewId() {
51
84
  var theConfig = (config || {});
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);
85
+ var getNewId = theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */] || newId;
86
+ var id = getNewId(theConfig[_DYN_ID_LENGTH /* @min:%2eidLength */] ? config[_DYN_ID_LENGTH /* @min:%2eidLength */] : 22);
54
87
  return id;
55
88
  }
56
89
  function _generateNewCookie(userId) {
@@ -65,32 +98,7 @@ var User = /** @class */ (function () {
65
98
  // set it to 365 days from now
66
99
  // 365 * 24 * 60 * 60 = 31536000
67
100
  var oneYear = 31536000;
68
- _self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = _cookieManager.set(_storageNamePrefix(), cookie, oneYear);
69
- }
70
- if (!_self.id) {
71
- _self.id = _generateNewId();
72
- var newCookie = _generateNewCookie(_self.id);
73
- _setUserCookie(newCookie[_DYN_JOIN /* @min:%2ejoin */](User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]));
74
- // If we have an config.namePrefix() + ai_session in local storage this means the user actively removed our cookies.
75
- // We should respect their wishes and clear ourselves from local storage
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";
77
- utlRemoveStorage(_logger, name_1);
78
- }
79
- // We still take the account id from the ctor param for backward compatibility.
80
- // But if the the customer set the accountId through the newer setAuthenticatedUserContext API, we will override it.
81
- _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] ? config[_DYN_ACCOUNT_ID /* @min:%2eaccountId */]() : undefined;
82
- // Get the auth user id and account id from the cookie if exists
83
- // Cookie is in the pattern: <authenticatedId>|<accountId>
84
- var authCookie = _cookieManager.get(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */]);
85
- if (authCookie) {
86
- authCookie = decodeURI(authCookie);
87
- var authCookieString = authCookie.split(User[_DYN_COOKIE_SEPARATOR /* @min:%2ecookieSeparator */]);
88
- if (authCookieString[0]) {
89
- _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = authCookieString[0];
90
- }
91
- if (authCookieString[_DYN_LENGTH /* @min:%2elength */] > 1 && authCookieString[1]) {
92
- _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = authCookieString[1];
93
- }
101
+ _self[_DYN_IS_USER_COOKIE_SET /* @min:%2eisUserCookieSet */] = _cookieManager.set(_storageNamePrefix, cookie, oneYear);
94
102
  }
95
103
  _self.setAuthenticatedUserContext = function (authenticatedUserId, accountId, storeInCookie) {
96
104
  if (storeInCookie === void 0) { storeInCookie = false; }
@@ -111,7 +119,7 @@ var User = /** @class */ (function () {
111
119
  if (storeInCookie) {
112
120
  // Set the cookie. No expiration date because this is a session cookie (expires when browser closed).
113
121
  // Encoding the cookie to handle unexpected unicode characters.
114
- _cookieManager.set(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */], encodeURI(authCookie));
122
+ _cookieManager.set(User[_DYN_AUTH_USER_COOKIE_NAM7 /* @min:%2eauthUserCookieName */], encodeURI(authCookie));
115
123
  }
116
124
  };
117
125
  /**
@@ -121,7 +129,7 @@ var User = /** @class */ (function () {
121
129
  _self.clearAuthenticatedUserContext = function () {
122
130
  _self[_DYN_AUTHENTICATED_ID /* @min:%2eauthenticatedId */] = null;
123
131
  _self[_DYN_ACCOUNT_ID /* @min:%2eaccountId */] = null;
124
- _cookieManager.del(User[_DYN_AUTH_USER_COOKIE_NAM8 /* @min:%2eauthUserCookieName */]);
132
+ _cookieManager.del(User[_DYN_AUTH_USER_COOKIE_NAM7 /* @min:%2eauthUserCookieName */]);
125
133
  };
126
134
  _self[_DYN_UPDATE /* @min:%2eupdate */] = function (userId) {
127
135
  // Optimizations to avoid setting and processing the cookie when not needed
@@ -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 { _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"}
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, onConfigChange, safeGetCookieMgr, safeGetLogger, toISOString } from \"@microsoft/applicationinsights-core-js\";\r\nimport { objDefineProp } from \"@nevware21/ts-utils\";\r\nimport { _DYN_ACCOUNT_ID, _DYN_AUTHENTICATED_ID, _DYN_AUTH_USER_COOKIE_NAM7, _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 // Define _self.config\r\n objDefineProp(_self, \"config\", {\r\n configurable: true,\r\n enumerable: true,\r\n get: function () { return config; }\r\n });\r\n onConfigChange(config, function () {\r\n var userCookiePostfix = config[_DYN_USER_COOKIE_POSTFIX /* @min:%2euserCookiePostfix */] || \"\";\r\n _storageNamePrefix = 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 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 */] || \"\") + \"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 */] || 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_NAM7 /* @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 });\r\n function _generateNewId() {\r\n var theConfig = (config || {});\r\n var getNewId = theConfig[_DYN_GET_NEW_ID /* @min:%2egetNewId */] || 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 _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_NAM7 /* @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_NAM7 /* @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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;0CAwBM;AACN;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-01
2
+ * Application Insights JavaScript SDK - Properties Plugin, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5