@azure/msal-common 6.1.0 → 6.2.0

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 (121) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AuthToken.js +1 -1
  3. package/dist/account/CcsCredential.js +1 -1
  4. package/dist/account/ClientInfo.js +1 -1
  5. package/dist/authority/Authority.js +1 -1
  6. package/dist/authority/AuthorityFactory.js +1 -1
  7. package/dist/authority/AuthorityOptions.d.ts +1 -0
  8. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  9. package/dist/authority/AuthorityOptions.js +3 -1
  10. package/dist/authority/AuthorityOptions.js.map +1 -1
  11. package/dist/authority/AuthorityType.js +1 -1
  12. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  13. package/dist/authority/OpenIdConfigResponse.js +1 -1
  14. package/dist/authority/ProtocolMode.js +1 -1
  15. package/dist/authority/RegionDiscovery.js +1 -1
  16. package/dist/cache/CacheManager.js +2 -2
  17. package/dist/cache/CacheManager.js.map +1 -1
  18. package/dist/cache/entities/AccessTokenEntity.js +1 -1
  19. package/dist/cache/entities/AccountEntity.js +10 -10
  20. package/dist/cache/entities/AccountEntity.js.map +1 -1
  21. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  22. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  23. package/dist/cache/entities/CacheRecord.js +1 -1
  24. package/dist/cache/entities/CredentialEntity.js +5 -5
  25. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  26. package/dist/cache/entities/IdTokenEntity.js +1 -1
  27. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  28. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  29. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  30. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  31. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  32. package/dist/client/AuthorizationCodeClient.js +3 -1
  33. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  34. package/dist/client/BaseClient.js +1 -1
  35. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  36. package/dist/client/ClientCredentialClient.js +4 -3
  37. package/dist/client/ClientCredentialClient.js.map +1 -1
  38. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  39. package/dist/client/DeviceCodeClient.js +2 -1
  40. package/dist/client/DeviceCodeClient.js.map +1 -1
  41. package/dist/client/OnBehalfOfClient.js +3 -2
  42. package/dist/client/OnBehalfOfClient.js.map +1 -1
  43. package/dist/client/RefreshTokenClient.js +2 -1
  44. package/dist/client/RefreshTokenClient.js.map +1 -1
  45. package/dist/client/SilentFlowClient.js +1 -1
  46. package/dist/client/UsernamePasswordClient.js +2 -1
  47. package/dist/client/UsernamePasswordClient.js.map +1 -1
  48. package/dist/config/ClientConfiguration.d.ts +16 -1
  49. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  50. package/dist/config/ClientConfiguration.js +14 -7
  51. package/dist/config/ClientConfiguration.js.map +1 -1
  52. package/dist/crypto/ICrypto.d.ts +4 -2
  53. package/dist/crypto/ICrypto.d.ts.map +1 -1
  54. package/dist/crypto/ICrypto.js +1 -1
  55. package/dist/crypto/ICrypto.js.map +1 -1
  56. package/dist/crypto/IGuidGenerator.d.ts +5 -0
  57. package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
  58. package/dist/crypto/PopTokenGenerator.js +2 -2
  59. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  60. package/dist/error/AuthError.js +3 -3
  61. package/dist/error/AuthError.js.map +1 -1
  62. package/dist/error/ClientAuthError.js +1 -1
  63. package/dist/error/ClientConfigurationError.js +1 -1
  64. package/dist/error/InteractionRequiredAuthError.js +1 -1
  65. package/dist/error/ServerError.js +1 -1
  66. package/dist/index.cjs.js +468 -53
  67. package/dist/index.cjs.js.map +1 -1
  68. package/dist/index.d.ts +7 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +4 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/logger/Logger.js +13 -13
  73. package/dist/logger/Logger.js.map +1 -1
  74. package/dist/network/INetworkModule.js +1 -1
  75. package/dist/network/NetworkManager.js +1 -1
  76. package/dist/network/ThrottlingUtils.js +1 -1
  77. package/dist/packageMetadata.d.ts +1 -1
  78. package/dist/packageMetadata.js +2 -2
  79. package/dist/packageMetadata.js.map +1 -1
  80. package/dist/request/AuthenticationHeaderParser.js +3 -3
  81. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  82. package/dist/request/RequestParameterBuilder.d.ts +6 -1
  83. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  84. package/dist/request/RequestParameterBuilder.js +19 -3
  85. package/dist/request/RequestParameterBuilder.js.map +1 -1
  86. package/dist/request/RequestValidator.js +1 -1
  87. package/dist/request/ScopeSet.js +4 -4
  88. package/dist/request/ScopeSet.js.map +1 -1
  89. package/dist/response/ResponseHandler.js +4 -4
  90. package/dist/response/ResponseHandler.js.map +1 -1
  91. package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
  92. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
  93. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
  94. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
  95. package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
  96. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
  97. package/dist/telemetry/performance/PerformanceClient.js +275 -0
  98. package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
  99. package/dist/telemetry/performance/PerformanceEvent.d.ts +182 -0
  100. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
  101. package/dist/telemetry/performance/PerformanceEvent.js +85 -0
  102. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
  103. package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
  104. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
  105. package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
  106. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
  107. package/dist/telemetry/server/ServerTelemetryManager.js +4 -4
  108. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  109. package/dist/url/UrlString.js +2 -2
  110. package/dist/url/UrlString.js.map +1 -1
  111. package/dist/utils/Constants.d.ts +2 -0
  112. package/dist/utils/Constants.d.ts.map +1 -1
  113. package/dist/utils/Constants.js +3 -1
  114. package/dist/utils/Constants.js.map +1 -1
  115. package/dist/utils/ProtocolUtils.js +3 -3
  116. package/dist/utils/ProtocolUtils.js.map +1 -1
  117. package/dist/utils/StringUtils.js +1 -1
  118. package/dist/utils/TimeUtils.js +1 -1
  119. package/package.json +2 -4
  120. package/CHANGELOG.json +0 -1319
  121. package/CHANGELOG.md +0 -504
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.1.0 2022-02-08 */
1
+ /*! @azure/msal-common v6.2.0 2022-04-04 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -213,6 +213,8 @@ var AADServerParamKeys;
213
213
  AADServerParamKeys["X_CLIENT_CURR_TELEM"] = "x-client-current-telemetry";
214
214
  AADServerParamKeys["X_CLIENT_LAST_TELEM"] = "x-client-last-telemetry";
215
215
  AADServerParamKeys["X_MS_LIB_CAPABILITY"] = "x-ms-lib-capability";
216
+ AADServerParamKeys["X_APP_NAME"] = "x-app-name";
217
+ AADServerParamKeys["X_APP_VER"] = "x-app-ver";
216
218
  AADServerParamKeys["POST_LOGOUT_URI"] = "post_logout_redirect_uri";
217
219
  AADServerParamKeys["ID_TOKEN_HINT"] = "id_token_hint";
218
220
  AADServerParamKeys["DEVICE_CODE"] = "device_code";
@@ -483,8 +485,8 @@ var AuthError = /** @class */ (function (_super) {
483
485
  _this = _super.call(this, errorString) || this;
484
486
  Object.setPrototypeOf(_this, AuthError.prototype);
485
487
  _this.errorCode = errorCode || Constants.EMPTY_STRING;
486
- _this.errorMessage = errorMessage || "";
487
- _this.subError = suberror || "";
488
+ _this.errorMessage = errorMessage || Constants.EMPTY_STRING;
489
+ _this.subError = suberror || Constants.EMPTY_STRING;
488
490
  _this.name = "AuthError";
489
491
  return _this;
490
492
  }
@@ -1185,7 +1187,7 @@ var Logger = /** @class */ (function () {
1185
1187
  this.localCallback = loggerOptions.loggerCallback || defaultLoggerCallback;
1186
1188
  this.piiLoggingEnabled = loggerOptions.piiLoggingEnabled || false;
1187
1189
  this.level = typeof (loggerOptions.logLevel) === "number" ? loggerOptions.logLevel : exports.LogLevel.Info;
1188
- this.correlationId = loggerOptions.correlationId || "";
1190
+ this.correlationId = loggerOptions.correlationId || Constants.EMPTY_STRING;
1189
1191
  this.packageName = packageName || Constants.EMPTY_STRING;
1190
1192
  this.packageVersion = packageVersion || Constants.EMPTY_STRING;
1191
1193
  }
@@ -1215,7 +1217,7 @@ var Logger = /** @class */ (function () {
1215
1217
  logHeader = "[" + timestamp + "]";
1216
1218
  }
1217
1219
  var log = logHeader + " : " + this.packageName + "@" + this.packageVersion + " : " + exports.LogLevel[options.logLevel] + " - " + logMessage;
1218
- // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": ""}${options.context ? `:${options.context}` : ""}`)(logMessage);
1220
+ // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": Constants.EMPTY_STRING}${options.context ? `:${options.context}` : Constants.EMPTY_STRING}`)(logMessage);
1219
1221
  this.executeCallback(options.logLevel, log, options.containsPii || false);
1220
1222
  };
1221
1223
  /**
@@ -1233,7 +1235,7 @@ var Logger = /** @class */ (function () {
1233
1235
  this.logMessage(message, {
1234
1236
  logLevel: exports.LogLevel.Error,
1235
1237
  containsPii: false,
1236
- correlationId: correlationId || ""
1238
+ correlationId: correlationId || Constants.EMPTY_STRING
1237
1239
  });
1238
1240
  };
1239
1241
  /**
@@ -1243,7 +1245,7 @@ var Logger = /** @class */ (function () {
1243
1245
  this.logMessage(message, {
1244
1246
  logLevel: exports.LogLevel.Error,
1245
1247
  containsPii: true,
1246
- correlationId: correlationId || ""
1248
+ correlationId: correlationId || Constants.EMPTY_STRING
1247
1249
  });
1248
1250
  };
1249
1251
  /**
@@ -1253,7 +1255,7 @@ var Logger = /** @class */ (function () {
1253
1255
  this.logMessage(message, {
1254
1256
  logLevel: exports.LogLevel.Warning,
1255
1257
  containsPii: false,
1256
- correlationId: correlationId || ""
1258
+ correlationId: correlationId || Constants.EMPTY_STRING
1257
1259
  });
1258
1260
  };
1259
1261
  /**
@@ -1263,7 +1265,7 @@ var Logger = /** @class */ (function () {
1263
1265
  this.logMessage(message, {
1264
1266
  logLevel: exports.LogLevel.Warning,
1265
1267
  containsPii: true,
1266
- correlationId: correlationId || ""
1268
+ correlationId: correlationId || Constants.EMPTY_STRING
1267
1269
  });
1268
1270
  };
1269
1271
  /**
@@ -1273,7 +1275,7 @@ var Logger = /** @class */ (function () {
1273
1275
  this.logMessage(message, {
1274
1276
  logLevel: exports.LogLevel.Info,
1275
1277
  containsPii: false,
1276
- correlationId: correlationId || ""
1278
+ correlationId: correlationId || Constants.EMPTY_STRING
1277
1279
  });
1278
1280
  };
1279
1281
  /**
@@ -1283,7 +1285,7 @@ var Logger = /** @class */ (function () {
1283
1285
  this.logMessage(message, {
1284
1286
  logLevel: exports.LogLevel.Info,
1285
1287
  containsPii: true,
1286
- correlationId: correlationId || ""
1288
+ correlationId: correlationId || Constants.EMPTY_STRING
1287
1289
  });
1288
1290
  };
1289
1291
  /**
@@ -1293,7 +1295,7 @@ var Logger = /** @class */ (function () {
1293
1295
  this.logMessage(message, {
1294
1296
  logLevel: exports.LogLevel.Verbose,
1295
1297
  containsPii: false,
1296
- correlationId: correlationId || ""
1298
+ correlationId: correlationId || Constants.EMPTY_STRING
1297
1299
  });
1298
1300
  };
1299
1301
  /**
@@ -1303,7 +1305,7 @@ var Logger = /** @class */ (function () {
1303
1305
  this.logMessage(message, {
1304
1306
  logLevel: exports.LogLevel.Verbose,
1305
1307
  containsPii: true,
1306
- correlationId: correlationId || ""
1308
+ correlationId: correlationId || Constants.EMPTY_STRING
1307
1309
  });
1308
1310
  };
1309
1311
  /**
@@ -1313,7 +1315,7 @@ var Logger = /** @class */ (function () {
1313
1315
  this.logMessage(message, {
1314
1316
  logLevel: exports.LogLevel.Trace,
1315
1317
  containsPii: false,
1316
- correlationId: correlationId || ""
1318
+ correlationId: correlationId || Constants.EMPTY_STRING
1317
1319
  });
1318
1320
  };
1319
1321
  /**
@@ -1323,7 +1325,7 @@ var Logger = /** @class */ (function () {
1323
1325
  this.logMessage(message, {
1324
1326
  logLevel: exports.LogLevel.Trace,
1325
1327
  containsPii: true,
1326
- correlationId: correlationId || ""
1328
+ correlationId: correlationId || Constants.EMPTY_STRING
1327
1329
  });
1328
1330
  };
1329
1331
  /**
@@ -1337,7 +1339,7 @@ var Logger = /** @class */ (function () {
1337
1339
 
1338
1340
  /* eslint-disable header/header */
1339
1341
  var name = "@azure/msal-common";
1340
- var version = "6.1.0";
1342
+ var version = "6.2.0";
1341
1343
 
1342
1344
  /*
1343
1345
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1349,6 +1351,8 @@ exports.AzureCloudInstance = void 0;
1349
1351
  AzureCloudInstance[AzureCloudInstance["None"] = 0] = "None";
1350
1352
  // Microsoft Azure public cloud
1351
1353
  AzureCloudInstance["AzurePublic"] = "https://login.microsoftonline.com";
1354
+ // Microsoft PPE
1355
+ AzureCloudInstance["AzurePpe"] = "https://login.windows-ppe.net";
1352
1356
  // Microsoft Chinese national cloud
1353
1357
  AzureCloudInstance["AzureChina"] = "https://login.chinacloudapi.cn";
1354
1358
  // Microsoft German national cloud ("Black Forest")
@@ -1485,7 +1489,7 @@ var CredentialEntity = /** @class */ (function () {
1485
1489
  var credentialId = [
1486
1490
  credentialType,
1487
1491
  clientOrFamilyId,
1488
- realm || "",
1492
+ realm || Constants.EMPTY_STRING,
1489
1493
  ];
1490
1494
  return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1491
1495
  };
@@ -1493,13 +1497,13 @@ var CredentialEntity = /** @class */ (function () {
1493
1497
  * Generate target key component as per schema: <target>
1494
1498
  */
1495
1499
  CredentialEntity.generateTargetForCacheKey = function (scopes) {
1496
- return (scopes || "").toLowerCase();
1500
+ return (scopes || Constants.EMPTY_STRING).toLowerCase();
1497
1501
  };
1498
1502
  /**
1499
1503
  * Generate requested claims key component as per schema: <requestedClaims>
1500
1504
  */
1501
1505
  CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
1502
- return (requestedClaimsHash || "").toLowerCase();
1506
+ return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
1503
1507
  };
1504
1508
  /**
1505
1509
  * Generate scheme key componenet as per schema: <scheme>
@@ -1509,7 +1513,7 @@ var CredentialEntity = /** @class */ (function () {
1509
1513
  * PoP Tokens and SSH certs include scheme in cache key
1510
1514
  * Cast to lowercase to handle "bearer" from ADFS
1511
1515
  */
1512
- return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : "";
1516
+ return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
1513
1517
  };
1514
1518
  return CredentialEntity;
1515
1519
  }());
@@ -1794,7 +1798,7 @@ var ScopeSet = /** @class */ (function () {
1794
1798
  * @param scopesRequired
1795
1799
  */
1796
1800
  ScopeSet.fromString = function (inputScopeString) {
1797
- var scopeString = inputScopeString || "";
1801
+ var scopeString = inputScopeString || Constants.EMPTY_STRING;
1798
1802
  var inputScopes = scopeString.split(" ");
1799
1803
  return new ScopeSet(inputScopes);
1800
1804
  };
@@ -1938,7 +1942,7 @@ var ScopeSet = /** @class */ (function () {
1938
1942
  var scopeArr = this.asArray();
1939
1943
  return scopeArr.join(" ");
1940
1944
  }
1941
- return "";
1945
+ return Constants.EMPTY_STRING;
1942
1946
  };
1943
1947
  /**
1944
1948
  * Prints scopes into a space-delimited lower-case string (used for caching)
@@ -2086,8 +2090,8 @@ var AccountEntity = /** @class */ (function () {
2086
2090
  AccountEntity.generateAccountCacheKey = function (accountInterface) {
2087
2091
  var accountKey = [
2088
2092
  accountInterface.homeAccountId,
2089
- accountInterface.environment || "",
2090
- accountInterface.tenantId || "",
2093
+ accountInterface.environment || Constants.EMPTY_STRING,
2094
+ accountInterface.tenantId || Constants.EMPTY_STRING,
2091
2095
  ];
2092
2096
  return accountKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
2093
2097
  };
@@ -2110,17 +2114,17 @@ var AccountEntity = /** @class */ (function () {
2110
2114
  }
2111
2115
  account.environment = env;
2112
2116
  // non AAD scenarios can have empty realm
2113
- account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || "";
2117
+ account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2114
2118
  account.oboAssertion = oboAssertion;
2115
2119
  if (idToken) {
2116
2120
  account.idTokenClaims = idToken.claims;
2117
2121
  // How do you account for MSA CID here?
2118
- account.localAccountId = ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.oid) || ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.sub) || "";
2122
+ account.localAccountId = ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.oid) || ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.sub) || Constants.EMPTY_STRING;
2119
2123
  /*
2120
2124
  * In B2C scenarios the emails claim is used instead of preferred_username and it is an array. In most cases it will contain a single email.
2121
2125
  * This field should not be relied upon if a custom policy is configured to return more than 1 email.
2122
2126
  */
2123
- account.username = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.preferred_username) || (((_e = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _e === void 0 ? void 0 : _e.emails) ? idToken.claims.emails[0] : "");
2127
+ account.username = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.preferred_username) || (((_e = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _e === void 0 ? void 0 : _e.emails) ? idToken.claims.emails[0] : Constants.EMPTY_STRING);
2124
2128
  account.name = (_f = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _f === void 0 ? void 0 : _f.name;
2125
2129
  }
2126
2130
  account.cloudGraphHostName = cloudGraphHostName;
@@ -2138,7 +2142,7 @@ var AccountEntity = /** @class */ (function () {
2138
2142
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2139
2143
  account.homeAccountId = homeAccountId;
2140
2144
  // non AAD scenarios can have empty realm
2141
- account.realm = "";
2145
+ account.realm = Constants.EMPTY_STRING;
2142
2146
  account.oboAssertion = oboAssertion;
2143
2147
  var env = environment || authority && authority.getPreferredCache();
2144
2148
  if (!env) {
@@ -2146,10 +2150,10 @@ var AccountEntity = /** @class */ (function () {
2146
2150
  }
2147
2151
  if (idToken) {
2148
2152
  // How do you account for MSA CID here?
2149
- account.localAccountId = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.oid) || ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.sub) || "";
2153
+ account.localAccountId = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.oid) || ((_b = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _b === void 0 ? void 0 : _b.sub) || Constants.EMPTY_STRING;
2150
2154
  // upn claim for most ADFS scenarios
2151
- account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || "";
2152
- account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || "";
2155
+ account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || Constants.EMPTY_STRING;
2156
+ account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || Constants.EMPTY_STRING;
2153
2157
  account.idTokenClaims = idToken === null || idToken === void 0 ? void 0 : idToken.claims;
2154
2158
  }
2155
2159
  account.environment = env;
@@ -2386,7 +2390,7 @@ var CacheManager = /** @class */ (function () {
2386
2390
  * @param realm
2387
2391
  */
2388
2392
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2389
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : "", accountFilter ? accountFilter.environment : "", accountFilter ? accountFilter.realm : "");
2393
+ return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING);
2390
2394
  };
2391
2395
  /**
2392
2396
  * retrieve accounts matching all provided filters; if no filter is set, get all accounts
@@ -3115,7 +3119,7 @@ var DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
3115
3119
  var DEFAULT_SYSTEM_OPTIONS = {
3116
3120
  tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
3117
3121
  preventCorsPreflight: false,
3118
- proxyUrl: "",
3122
+ proxyUrl: Constants.EMPTY_STRING
3119
3123
  };
3120
3124
  var DEFAULT_LOGGER_IMPLEMENTATION = {
3121
3125
  loggerCallback: function () {
@@ -3123,7 +3127,7 @@ var DEFAULT_LOGGER_IMPLEMENTATION = {
3123
3127
  },
3124
3128
  piiLoggingEnabled: false,
3125
3129
  logLevel: exports.LogLevel.Info,
3126
- correlationId: ""
3130
+ correlationId: Constants.EMPTY_STRING
3127
3131
  };
3128
3132
  var DEFAULT_NETWORK_IMPLEMENTATION = {
3129
3133
  sendGetRequestAsync: function () {
@@ -3148,17 +3152,23 @@ var DEFAULT_NETWORK_IMPLEMENTATION = {
3148
3152
  var DEFAULT_LIBRARY_INFO = {
3149
3153
  sku: Constants.SKU,
3150
3154
  version: version,
3151
- cpu: "",
3152
- os: ""
3155
+ cpu: Constants.EMPTY_STRING,
3156
+ os: Constants.EMPTY_STRING
3153
3157
  };
3154
3158
  var DEFAULT_CLIENT_CREDENTIALS = {
3155
- clientSecret: "",
3159
+ clientSecret: Constants.EMPTY_STRING,
3156
3160
  clientAssertion: undefined
3157
3161
  };
3158
3162
  var DEFAULT_AZURE_CLOUD_OPTIONS = {
3159
3163
  azureCloudInstance: exports.AzureCloudInstance.None,
3160
3164
  tenant: "" + Constants.DEFAULT_COMMON_TENANT
3161
3165
  };
3166
+ var DEFAULT_TELEMETRY_OPTIONS = {
3167
+ application: {
3168
+ appName: "",
3169
+ appVersion: ""
3170
+ }
3171
+ };
3162
3172
  /**
3163
3173
  * Function that sets the default options when not explicitly configured from app developer
3164
3174
  *
@@ -3167,7 +3177,7 @@ var DEFAULT_AZURE_CLOUD_OPTIONS = {
3167
3177
  * @returns Configuration
3168
3178
  */
3169
3179
  function buildClientConfiguration(_a) {
3170
- var userAuthOptions = _a.authOptions, userSystemOptions = _a.systemOptions, userLoggerOption = _a.loggerOptions, storageImplementation = _a.storageInterface, networkImplementation = _a.networkInterface, cryptoImplementation = _a.cryptoInterface, clientCredentials = _a.clientCredentials, libraryInfo = _a.libraryInfo, serverTelemetryManager = _a.serverTelemetryManager, persistencePlugin = _a.persistencePlugin, serializableCache = _a.serializableCache;
3180
+ var userAuthOptions = _a.authOptions, userSystemOptions = _a.systemOptions, userLoggerOption = _a.loggerOptions, storageImplementation = _a.storageInterface, networkImplementation = _a.networkInterface, cryptoImplementation = _a.cryptoInterface, clientCredentials = _a.clientCredentials, libraryInfo = _a.libraryInfo, telemetry = _a.telemetry, serverTelemetryManager = _a.serverTelemetryManager, persistencePlugin = _a.persistencePlugin, serializableCache = _a.serializableCache;
3171
3181
  var loggerOptions = __assign(__assign({}, DEFAULT_LOGGER_IMPLEMENTATION), userLoggerOption);
3172
3182
  return {
3173
3183
  authOptions: buildAuthOptions(userAuthOptions),
@@ -3178,6 +3188,7 @@ function buildClientConfiguration(_a) {
3178
3188
  cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
3179
3189
  clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
3180
3190
  libraryInfo: __assign(__assign({}, DEFAULT_LIBRARY_INFO), libraryInfo),
3191
+ telemetry: __assign(__assign({}, DEFAULT_TELEMETRY_OPTIONS), telemetry),
3181
3192
  serverTelemetryManager: serverTelemetryManager || null,
3182
3193
  persistencePlugin: persistencePlugin || null,
3183
3194
  serializableCache: serializableCache || null
@@ -3652,8 +3663,24 @@ var RequestParameterBuilder = /** @class */ (function () {
3652
3663
  // Telemetry Info
3653
3664
  this.parameters.set(AADServerParamKeys.X_CLIENT_SKU, libraryInfo.sku);
3654
3665
  this.parameters.set(AADServerParamKeys.X_CLIENT_VER, libraryInfo.version);
3655
- this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3656
- this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3666
+ if (libraryInfo.os) {
3667
+ this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3668
+ }
3669
+ if (libraryInfo.cpu) {
3670
+ this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3671
+ }
3672
+ };
3673
+ /**
3674
+ * Add client telemetry parameters
3675
+ * @param appTelemetry
3676
+ */
3677
+ RequestParameterBuilder.prototype.addApplicationTelemetry = function (appTelemetry) {
3678
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appName) {
3679
+ this.parameters.set(AADServerParamKeys.X_APP_NAME, appTelemetry.appName);
3680
+ }
3681
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appVersion) {
3682
+ this.parameters.set(AADServerParamKeys.X_APP_VER, appTelemetry.appVersion);
3683
+ }
3657
3684
  };
3658
3685
  /**
3659
3686
  * add prompt
@@ -4295,11 +4322,11 @@ var ProtocolUtils = /** @class */ (function () {
4295
4322
  // Split the state between library state and user passed state and decode them separately
4296
4323
  var splitState = state.split(Constants.RESOURCE_DELIM);
4297
4324
  var libraryState = splitState[0];
4298
- var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : "";
4325
+ var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : Constants.EMPTY_STRING;
4299
4326
  var libraryStateString = cryptoObj.base64Decode(libraryState);
4300
4327
  var libraryStateObj = JSON.parse(libraryStateString);
4301
4328
  return {
4302
- userRequestState: !StringUtils.isEmpty(userState) ? userState : "",
4329
+ userRequestState: !StringUtils.isEmpty(userState) ? userState : Constants.EMPTY_STRING,
4303
4330
  libraryState: libraryStateObj
4304
4331
  };
4305
4332
  }
@@ -4469,7 +4496,7 @@ var UrlString = /** @class */ (function () {
4469
4496
  else if (hashIndex1 > -1) {
4470
4497
  return hashString.substring(hashIndex1 + 1);
4471
4498
  }
4472
- return "";
4499
+ return Constants.EMPTY_STRING;
4473
4500
  };
4474
4501
  UrlString.constructAuthorityUriFromObject = function (urlObject) {
4475
4502
  return new UrlString(urlObject.Protocol + "//" + urlObject.HostNameAndPort + "/" + urlObject.PathSegments.join("/"));
@@ -4573,7 +4600,7 @@ var PopTokenGenerator = /** @class */ (function () {
4573
4600
  resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4574
4601
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4575
4602
  resourceUrlComponents = resourceUrlString === null || resourceUrlString === void 0 ? void 0 : resourceUrlString.getUrlComponents();
4576
- return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid)];
4603
+ return [4 /*yield*/, this.cryptoUtils.signJwt(__assign({ at: payload, ts: TimeUtils.nowSeconds(), m: resourceRequestMethod === null || resourceRequestMethod === void 0 ? void 0 : resourceRequestMethod.toUpperCase(), u: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.HostNameAndPort, nonce: shrNonce || this.cryptoUtils.createNewGuid(), p: resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.AbsolutePath, q: (resourceUrlComponents === null || resourceUrlComponents === void 0 ? void 0 : resourceUrlComponents.QueryString) ? [[], resourceUrlComponents.QueryString] : undefined, client_claims: shrClaims || undefined }, claims), kid, request.correlationId)];
4577
4604
  case 1: return [2 /*return*/, _a.sent()];
4578
4605
  }
4579
4606
  });
@@ -4864,8 +4891,8 @@ var ResponseHandler = /** @class */ (function () {
4864
4891
  */
4865
4892
  ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4866
4893
  var authorityType = authority.authorityType;
4867
- var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : "";
4868
- var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : "";
4894
+ var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4895
+ var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4869
4896
  // ADFS does not require client_info in the response
4870
4897
  if (authorityType === exports.AuthorityType.Adfs) {
4871
4898
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
@@ -4896,7 +4923,7 @@ var ResponseHandler = /** @class */ (function () {
4896
4923
  return __generator(this, function (_d) {
4897
4924
  switch (_d.label) {
4898
4925
  case 0:
4899
- accessToken = "";
4926
+ accessToken = Constants.EMPTY_STRING;
4900
4927
  responseScopes = [];
4901
4928
  expiresOn = null;
4902
4929
  familyId = Constants.EMPTY_STRING;
@@ -5134,6 +5161,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5134
5161
  parameterBuilder.addAuthorizationCode(request.code);
5135
5162
  // Add library metadata
5136
5163
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5164
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5137
5165
  parameterBuilder.addThrottling();
5138
5166
  if (this.serverTelemetryManager) {
5139
5167
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5242,6 +5270,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5242
5270
  parameterBuilder.addResponseTypeCode();
5243
5271
  // add library info parameters
5244
5272
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5273
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5245
5274
  // add client_info=1
5246
5275
  parameterBuilder.addClientInfo();
5247
5276
  if (request.codeChallenge && request.codeChallengeMethod) {
@@ -5557,6 +5586,7 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5557
5586
  requestParameters.addCorrelationId(correlationId);
5558
5587
  requestParameters.addClientInfo();
5559
5588
  requestParameters.addLibraryInfo(this.config.libraryInfo);
5589
+ requestParameters.addApplicationTelemetry(this.config.telemetry.application);
5560
5590
  requestParameters.addThrottling();
5561
5591
  if (this.serverTelemetryManager) {
5562
5592
  requestParameters.addServerTelemetry(this.serverTelemetryManager);
@@ -5718,6 +5748,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5718
5748
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
5719
5749
  parameterBuilder.addClientInfo();
5720
5750
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5751
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5721
5752
  parameterBuilder.addThrottling();
5722
5753
  if (this.serverTelemetryManager) {
5723
5754
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5852,7 +5883,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5852
5883
  */
5853
5884
  ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
5854
5885
  var accessTokenFilter = {
5855
- homeAccountId: "",
5886
+ homeAccountId: Constants.EMPTY_STRING,
5856
5887
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
5857
5888
  credentialType: exports.CredentialType.ACCESS_TOKEN,
5858
5889
  clientId: this.config.authOptions.clientId,
@@ -5917,6 +5948,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5917
5948
  parameterBuilder.addScopes(request.scopes, false);
5918
5949
  parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
5919
5950
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5951
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5920
5952
  parameterBuilder.addThrottling();
5921
5953
  if (this.serverTelemetryManager) {
5922
5954
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6004,7 +6036,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6004
6036
  environment: cachedIdToken.environment,
6005
6037
  tenantId: cachedIdToken.realm,
6006
6038
  username: Constants.EMPTY_STRING,
6007
- localAccountId: localAccountId || ""
6039
+ localAccountId: localAccountId || Constants.EMPTY_STRING
6008
6040
  };
6009
6041
  cachedAccount = this.readAccountFromCache(accountInfo);
6010
6042
  }
@@ -6119,6 +6151,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6119
6151
  parameterBuilder.addGrantType(GrantType.JWT_BEARER);
6120
6152
  parameterBuilder.addClientInfo();
6121
6153
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6154
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6122
6155
  parameterBuilder.addThrottling();
6123
6156
  if (this.serverTelemetryManager) {
6124
6157
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6334,6 +6367,7 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6334
6367
  parameterBuilder.addGrantType(GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
6335
6368
  parameterBuilder.addClientInfo();
6336
6369
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6370
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6337
6371
  parameterBuilder.addThrottling();
6338
6372
  if (this.serverTelemetryManager) {
6339
6373
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -7351,7 +7385,7 @@ var AuthenticationHeaderParser = /** @class */ (function () {
7351
7385
  challenges.forEach(function (challenge) {
7352
7386
  var _a = challenge.split("="), key = _a[0], value = _a[1];
7353
7387
  // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
7354
- challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
7388
+ challengeMap[key] = unescape(value.replace(/['"]+/g, Constants.EMPTY_STRING));
7355
7389
  });
7356
7390
  return challengeMap;
7357
7391
  };
@@ -7493,9 +7527,9 @@ var ServerTelemetryManager = /** @class */ (function () {
7493
7527
  */
7494
7528
  ServerTelemetryManager.prototype.getRegionDiscoveryFields = function () {
7495
7529
  var regionDiscoveryFields = [];
7496
- regionDiscoveryFields.push(this.regionUsed || "");
7497
- regionDiscoveryFields.push(this.regionSource || "");
7498
- regionDiscoveryFields.push(this.regionOutcome || "");
7530
+ regionDiscoveryFields.push(this.regionUsed || Constants.EMPTY_STRING);
7531
+ regionDiscoveryFields.push(this.regionSource || Constants.EMPTY_STRING);
7532
+ regionDiscoveryFields.push(this.regionOutcome || Constants.EMPTY_STRING);
7499
7533
  return regionDiscoveryFields.join(",");
7500
7534
  };
7501
7535
  /**
@@ -7518,6 +7552,385 @@ var ServerTelemetryManager = /** @class */ (function () {
7518
7552
  return ServerTelemetryManager;
7519
7553
  }());
7520
7554
 
7555
+ /*
7556
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7557
+ * Licensed under the MIT License.
7558
+ */
7559
+ /**
7560
+ * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.
7561
+ *
7562
+ * @export
7563
+ * @enum {number}
7564
+ */
7565
+ exports.PerformanceEvents = void 0;
7566
+ (function (PerformanceEvents) {
7567
+ /**
7568
+ * acquireTokenByCode API (msal-browser and msal-node).
7569
+ * Used to acquire tokens by trading an authorization code against the token endpoint.
7570
+ */
7571
+ PerformanceEvents["AcquireTokenByCode"] = "acquireTokenByCode";
7572
+ /**
7573
+ * acquireTokenByRefreshToken API (msal-browser and msal-node).
7574
+ * Used to renew an access token using a refresh token against the token endpoint.
7575
+ */
7576
+ PerformanceEvents["AcquireTokenByRefreshToken"] = "acquireTokenByRefreshToken";
7577
+ /**
7578
+ * acquireTokenSilent API (msal-browser and msal-node).
7579
+ * Used to silently acquire a new access token (from the cache or the network).
7580
+ */
7581
+ PerformanceEvents["AcquireTokenSilent"] = "acquireTokenSilent";
7582
+ /**
7583
+ * acquireTokenSilentAsync (msal-browser).
7584
+ * Internal API for acquireTokenSilent.
7585
+ */
7586
+ PerformanceEvents["AcquireTokenSilentAsync"] = "acquireTokenSilentAsync";
7587
+ /**
7588
+ * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).
7589
+ * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.
7590
+ */
7591
+ PerformanceEvents["CryptoOptsGetPublicKeyThumbprint"] = "cryptoOptsGetPublicKeyThumbprint";
7592
+ /**
7593
+ * signJwt API in CryptoOpts class (msal-browser).
7594
+ * Used to signed a pop token.
7595
+ */
7596
+ PerformanceEvents["CryptoOptsSignJwt"] = "cryptoOptsSignJwt";
7597
+ /**
7598
+ * acquireToken API in the SilentCacheClient class (msal-browser).
7599
+ * Used to read access tokens from the cache.
7600
+ */
7601
+ PerformanceEvents["SilentCacheClientAcquireToken"] = "silentCacheClientAcquireToken";
7602
+ /**
7603
+ * acquireToken API in the SilentIframeClient class (msal-browser).
7604
+ * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
7605
+ */
7606
+ PerformanceEvents["SilentIframeClientAcquireToken"] = "silentIframeClientAcquireToken";
7607
+ /**
7608
+ * acquireToken API in SilentRereshClient (msal-browser).
7609
+ * Used to acquire a new set of tokens from the token endpoint using a refresh token.
7610
+ */
7611
+ PerformanceEvents["SilentRefreshClientAcquireToken"] = "silentRefreshClientAcquireToken";
7612
+ /**
7613
+ * ssoSilent API (msal-browser).
7614
+ * Used to silently acquire an authorization code and set of tokens using a hidden iframe.
7615
+ */
7616
+ PerformanceEvents["SsoSilent"] = "ssoSilent";
7617
+ /**
7618
+ * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).
7619
+ * Used to load authority metadata for a request.
7620
+ */
7621
+ PerformanceEvents["StandardInteractionClientGetDiscoveredAuthority"] = "standardInteractionClientGetDiscoveredAuthority";
7622
+ })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
7623
+ /**
7624
+ * State of the performance event.
7625
+ *
7626
+ * @export
7627
+ * @enum {number}
7628
+ */
7629
+ exports.PerformanceEventStatus = void 0;
7630
+ (function (PerformanceEventStatus) {
7631
+ PerformanceEventStatus[PerformanceEventStatus["NotStarted"] = 0] = "NotStarted";
7632
+ PerformanceEventStatus[PerformanceEventStatus["InProgress"] = 1] = "InProgress";
7633
+ PerformanceEventStatus[PerformanceEventStatus["Completed"] = 2] = "Completed";
7634
+ })(exports.PerformanceEventStatus || (exports.PerformanceEventStatus = {}));
7635
+
7636
+ /*
7637
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7638
+ * Licensed under the MIT License.
7639
+ */
7640
+ var PerformanceClient = /** @class */ (function () {
7641
+ /**
7642
+ * Creates an instance of PerformanceClient,
7643
+ * an abstract class containing core performance telemetry logic.
7644
+ *
7645
+ * @constructor
7646
+ * @param {string} clientId Client ID of the application
7647
+ * @param {string} authority Authority used by the application
7648
+ * @param {Logger} logger Logger used by the application
7649
+ * @param {string} libraryName Name of the library
7650
+ * @param {string} libraryVersion Version of the library
7651
+ */
7652
+ function PerformanceClient(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
7653
+ this.authority = authority;
7654
+ this.libraryName = libraryName;
7655
+ this.libraryVersion = libraryVersion;
7656
+ this.applicationTelemetry = applicationTelemetry;
7657
+ this.clientId = clientId;
7658
+ this.logger = logger;
7659
+ this.callbacks = new Map();
7660
+ this.eventsByCorrelationId = new Map();
7661
+ this.measurementsById = new Map();
7662
+ }
7663
+ /**
7664
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
7665
+ *
7666
+ * @param {PerformanceEvents} measureName
7667
+ * @param {?string} [correlationId]
7668
+ * @returns {InProgressPerformanceEvent}
7669
+ */
7670
+ PerformanceClient.prototype.startMeasurement = function (measureName, correlationId) {
7671
+ var _this = this;
7672
+ var _a, _b;
7673
+ // Generate a placeholder correlation if the request does not provide one
7674
+ var eventCorrelationId = correlationId || this.generateId();
7675
+ if (!correlationId) {
7676
+ this.logger.info("PerformanceClient: No correlation id provided for " + measureName + ", generating", eventCorrelationId);
7677
+ }
7678
+ this.logger.trace("PerformanceClient: Performance measurement started for " + measureName, eventCorrelationId);
7679
+ var performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);
7680
+ performanceMeasurement.startMeasurement();
7681
+ var inProgressEvent = {
7682
+ eventId: this.generateId(),
7683
+ status: exports.PerformanceEventStatus.InProgress,
7684
+ authority: this.authority,
7685
+ libraryName: this.libraryName,
7686
+ libraryVersion: this.libraryVersion,
7687
+ appName: (_a = this.applicationTelemetry) === null || _a === void 0 ? void 0 : _a.appName,
7688
+ appVersion: (_b = this.applicationTelemetry) === null || _b === void 0 ? void 0 : _b.appVersion,
7689
+ clientId: this.clientId,
7690
+ name: measureName,
7691
+ startTimeMs: Date.now(),
7692
+ correlationId: eventCorrelationId
7693
+ };
7694
+ // Store in progress events so they can be discarded if not ended properly
7695
+ this.cacheEventByCorrelationId(inProgressEvent);
7696
+ this.cacheMeasurement(inProgressEvent, performanceMeasurement);
7697
+ // Return the event and functions the caller can use to properly end/flush the measurement
7698
+ return {
7699
+ endMeasurement: function (event) {
7700
+ var completedEvent = _this.endMeasurement(__assign(__assign({}, inProgressEvent), event));
7701
+ if (completedEvent) {
7702
+ // Cache event so that submeasurements can be added downstream
7703
+ _this.cacheEventByCorrelationId(completedEvent);
7704
+ }
7705
+ return completedEvent;
7706
+ },
7707
+ flushMeasurement: function () {
7708
+ return _this.flushMeasurements(inProgressEvent.name, inProgressEvent.correlationId);
7709
+ },
7710
+ discardMeasurement: function () {
7711
+ return _this.discardMeasurements(inProgressEvent.correlationId);
7712
+ },
7713
+ measurement: performanceMeasurement,
7714
+ event: inProgressEvent
7715
+ };
7716
+ };
7717
+ /**
7718
+ * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
7719
+ * as consumers should instead use the function returned by startMeasurement.
7720
+ *
7721
+ * @param {PerformanceEvent} event
7722
+ * @returns {(PerformanceEvent | null)}
7723
+ */
7724
+ PerformanceClient.prototype.endMeasurement = function (event) {
7725
+ var performanceMeasurement = this.measurementsById.get(event.eventId);
7726
+ if (performanceMeasurement) {
7727
+ // Immediately delete so that the same event isnt ended twice
7728
+ this.measurementsById.delete(event.eventId);
7729
+ performanceMeasurement.endMeasurement();
7730
+ var durationMs = performanceMeasurement.flushMeasurement();
7731
+ // null indicates no measurement was taken (e.g. needed performance APIs not present)
7732
+ if (durationMs !== null) {
7733
+ this.logger.trace("PerformanceClient: Performance measurement ended for " + event.name + ": " + durationMs + " ms", event.correlationId);
7734
+ var completedEvent = __assign(__assign({
7735
+ // Allow duration to be overwritten when event ends (e.g. testing), but not status
7736
+ durationMs: Math.round(durationMs) }, event), { status: exports.PerformanceEventStatus.Completed });
7737
+ return completedEvent;
7738
+ }
7739
+ else {
7740
+ this.logger.trace("PerformanceClient: Performance measurement not taken", event.correlationId);
7741
+ }
7742
+ }
7743
+ else {
7744
+ this.logger.trace("PerformanceClient: Measurement not found for " + event.eventId, event.correlationId);
7745
+ }
7746
+ return null;
7747
+ };
7748
+ /**
7749
+ * Upserts event into event cache.
7750
+ * First key is the correlation id, second key is the event id.
7751
+ * Allows for events to be grouped by correlation id,
7752
+ * and to easily allow for properties on them to be updated.
7753
+ *
7754
+ * @private
7755
+ * @param {PerformanceEvent} event
7756
+ */
7757
+ PerformanceClient.prototype.cacheEventByCorrelationId = function (event) {
7758
+ var existingEvents = this.eventsByCorrelationId.get(event.correlationId);
7759
+ if (existingEvents) {
7760
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " added/updated", event.correlationId);
7761
+ existingEvents.set(event.eventId, event);
7762
+ }
7763
+ else {
7764
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " started", event.correlationId);
7765
+ this.eventsByCorrelationId.set(event.correlationId, new Map().set(event.eventId, event));
7766
+ }
7767
+ };
7768
+ /**
7769
+ * Cache measurements by their id.
7770
+ *
7771
+ * @private
7772
+ * @param {PerformanceEvent} event
7773
+ * @param {IPerformanceMeasurement} measurement
7774
+ */
7775
+ PerformanceClient.prototype.cacheMeasurement = function (event, measurement) {
7776
+ this.measurementsById.set(event.eventId, measurement);
7777
+ };
7778
+ /**
7779
+ * Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
7780
+ *
7781
+ * @param {PerformanceEvents} measureName
7782
+ * @param {string} correlationId
7783
+ */
7784
+ PerformanceClient.prototype.flushMeasurements = function (measureName, correlationId) {
7785
+ var _this = this;
7786
+ this.logger.trace("PerformanceClient: Performance measurements flushed for " + measureName, correlationId);
7787
+ var eventsForCorrelationId = this.eventsByCorrelationId.get(correlationId);
7788
+ if (eventsForCorrelationId) {
7789
+ this.discardMeasurements(correlationId);
7790
+ /*
7791
+ * Manually end incomplete submeasurements to ensure there arent orphaned/never ending events.
7792
+ * Incomplete submeasurements are likely an instrumentation bug that should be fixed.
7793
+ * IE only supports Map.forEach.
7794
+ */
7795
+ var completedEvents_1 = [];
7796
+ eventsForCorrelationId.forEach(function (event) {
7797
+ if (event.name !== measureName && event.status !== exports.PerformanceEventStatus.Completed) {
7798
+ _this.logger.trace("PerformanceClient: Incomplete submeasurement " + event.name + " found for " + measureName, correlationId);
7799
+ var completedEvent = _this.endMeasurement(event);
7800
+ if (completedEvent) {
7801
+ completedEvents_1.push(completedEvent);
7802
+ }
7803
+ }
7804
+ completedEvents_1.push(event);
7805
+ });
7806
+ // Sort events by start time (earliest first)
7807
+ var sortedCompletedEvents = completedEvents_1.sort(function (eventA, eventB) { return eventA.startTimeMs - eventB.startTimeMs; });
7808
+ // Take completed top level event and add completed submeasurements durations as properties
7809
+ var topLevelEvents = sortedCompletedEvents.filter(function (event) { return event.name === measureName && event.status === exports.PerformanceEventStatus.Completed; });
7810
+ if (topLevelEvents.length > 0) {
7811
+ /*
7812
+ * Only take the first top-level event if there are multiple events with the same correlation id.
7813
+ * This greatly simplifies logic for submeasurements.
7814
+ */
7815
+ if (topLevelEvents.length > 1) {
7816
+ this.logger.verbose("PerformanceClient: Multiple distinct top-level performance events found, using the first", correlationId);
7817
+ }
7818
+ var topLevelEvent = topLevelEvents[0];
7819
+ this.logger.verbose("PerformanceClient: Measurement found for " + measureName, correlationId);
7820
+ // Build event object with top level and sub measurements
7821
+ var eventToEmit = sortedCompletedEvents.reduce(function (previous, current) {
7822
+ if (current.name !== measureName) {
7823
+ _this.logger.trace("PerformanceClient: Complete submeasurement found for " + current.name, correlationId);
7824
+ // TODO: Emit additional properties for each subMeasurement
7825
+ var subMeasurementName = current.name + "DurationMs";
7826
+ /*
7827
+ * Some code paths, such as resolving an authority, can occur multiple times.
7828
+ * Only take the first measurement, since the second could be read from the cache,
7829
+ * or due to the same correlation id being used for two distinct requests.
7830
+ */
7831
+ if (!previous[subMeasurementName]) {
7832
+ previous[subMeasurementName] = current.durationMs;
7833
+ }
7834
+ else {
7835
+ _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
7836
+ }
7837
+ }
7838
+ return previous;
7839
+ }, topLevelEvent);
7840
+ this.emitEvents([eventToEmit], eventToEmit.correlationId);
7841
+ }
7842
+ else {
7843
+ this.logger.verbose("PerformanceClient: No completed top-level measurements found for " + measureName, correlationId);
7844
+ }
7845
+ }
7846
+ else {
7847
+ this.logger.verbose("PerformanceClient: No measurements found", correlationId);
7848
+ }
7849
+ };
7850
+ /**
7851
+ * Removes measurements for a given correlation id.
7852
+ *
7853
+ * @param {string} correlationId
7854
+ */
7855
+ PerformanceClient.prototype.discardMeasurements = function (correlationId) {
7856
+ this.logger.trace("PerformanceClient: Performance measurements discarded", correlationId);
7857
+ this.eventsByCorrelationId.delete(correlationId);
7858
+ };
7859
+ /**
7860
+ * Registers a callback function to receive performance events.
7861
+ *
7862
+ * @param {PerformanceCallbackFunction} callback
7863
+ * @returns {string}
7864
+ */
7865
+ PerformanceClient.prototype.addPerformanceCallback = function (callback) {
7866
+ var callbackId = this.generateId();
7867
+ this.callbacks.set(callbackId, callback);
7868
+ this.logger.verbose("PerformanceClient: Performance callback registered with id: " + callbackId);
7869
+ return callbackId;
7870
+ };
7871
+ /**
7872
+ * Removes a callback registered with addPerformanceCallback.
7873
+ *
7874
+ * @param {string} callbackId
7875
+ * @returns {boolean}
7876
+ */
7877
+ PerformanceClient.prototype.removePerformanceCallback = function (callbackId) {
7878
+ var result = this.callbacks.delete(callbackId);
7879
+ if (result) {
7880
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " removed.");
7881
+ }
7882
+ else {
7883
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " not removed.");
7884
+ }
7885
+ return result;
7886
+ };
7887
+ /**
7888
+ * Emits events to all registered callbacks.
7889
+ *
7890
+ * @param {PerformanceEvent[]} events
7891
+ * @param {?string} [correlationId]
7892
+ */
7893
+ PerformanceClient.prototype.emitEvents = function (events, correlationId) {
7894
+ var _this = this;
7895
+ this.logger.verbose("PerformanceClient: Emitting performance events", correlationId);
7896
+ this.callbacks.forEach(function (callback, callbackId) {
7897
+ _this.logger.trace("PerformanceClient: Emitting event to callback " + callbackId, correlationId);
7898
+ callback.apply(null, [events]);
7899
+ });
7900
+ };
7901
+ return PerformanceClient;
7902
+ }());
7903
+
7904
+ /*
7905
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7906
+ * Licensed under the MIT License.
7907
+ */
7908
+ var StubPerformanceMeasurement = /** @class */ (function () {
7909
+ function StubPerformanceMeasurement() {
7910
+ }
7911
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
7912
+ StubPerformanceMeasurement.prototype.startMeasurement = function () { };
7913
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
7914
+ StubPerformanceMeasurement.prototype.endMeasurement = function () { };
7915
+ StubPerformanceMeasurement.prototype.flushMeasurement = function () {
7916
+ return null;
7917
+ };
7918
+ return StubPerformanceMeasurement;
7919
+ }());
7920
+ var StubPerformanceClient = /** @class */ (function (_super) {
7921
+ __extends(StubPerformanceClient, _super);
7922
+ function StubPerformanceClient() {
7923
+ return _super !== null && _super.apply(this, arguments) || this;
7924
+ }
7925
+ StubPerformanceClient.prototype.generateId = function () {
7926
+ return "callback-id";
7927
+ };
7928
+ StubPerformanceClient.prototype.startPerformanceMeasuremeant = function () {
7929
+ return new StubPerformanceMeasurement();
7930
+ };
7931
+ return StubPerformanceClient;
7932
+ }(PerformanceClient));
7933
+
7521
7934
  exports.AccessTokenEntity = AccessTokenEntity;
7522
7935
  exports.AccountEntity = AccountEntity;
7523
7936
  exports.AppMetadataEntity = AppMetadataEntity;
@@ -7549,6 +7962,7 @@ exports.Logger = Logger;
7549
7962
  exports.NetworkManager = NetworkManager;
7550
7963
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;
7551
7964
  exports.OnBehalfOfClient = OnBehalfOfClient;
7965
+ exports.PerformanceClient = PerformanceClient;
7552
7966
  exports.PopTokenGenerator = PopTokenGenerator;
7553
7967
  exports.PromptValue = PromptValue;
7554
7968
  exports.ProtocolUtils = ProtocolUtils;
@@ -7560,6 +7974,7 @@ exports.ServerTelemetryEntity = ServerTelemetryEntity;
7560
7974
  exports.ServerTelemetryManager = ServerTelemetryManager;
7561
7975
  exports.SilentFlowClient = SilentFlowClient;
7562
7976
  exports.StringUtils = StringUtils;
7977
+ exports.StubPerformanceClient = StubPerformanceClient;
7563
7978
  exports.StubbedNetworkModule = StubbedNetworkModule;
7564
7979
  exports.ThrottlingEntity = ThrottlingEntity;
7565
7980
  exports.ThrottlingUtils = ThrottlingUtils;