@azure/msal-common 6.1.0 → 6.3.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 (138) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AccountInfo.d.ts +6 -1
  3. package/dist/account/AccountInfo.d.ts.map +1 -1
  4. package/dist/account/AuthToken.js +1 -1
  5. package/dist/account/CcsCredential.js +1 -1
  6. package/dist/account/ClientInfo.js +1 -1
  7. package/dist/account/TokenClaims.d.ts +29 -0
  8. package/dist/account/TokenClaims.d.ts.map +1 -1
  9. package/dist/authority/Authority.js +1 -1
  10. package/dist/authority/AuthorityFactory.js +1 -1
  11. package/dist/authority/AuthorityOptions.d.ts +1 -0
  12. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  13. package/dist/authority/AuthorityOptions.js +3 -1
  14. package/dist/authority/AuthorityOptions.js.map +1 -1
  15. package/dist/authority/AuthorityType.js +1 -1
  16. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  17. package/dist/authority/OpenIdConfigResponse.js +1 -1
  18. package/dist/authority/ProtocolMode.js +1 -1
  19. package/dist/authority/RegionDiscovery.js +1 -1
  20. package/dist/cache/CacheManager.d.ts +1 -1
  21. package/dist/cache/CacheManager.js +3 -3
  22. package/dist/cache/CacheManager.js.map +1 -1
  23. package/dist/cache/entities/AccessTokenEntity.js +1 -1
  24. package/dist/cache/entities/AccountEntity.d.ts +3 -1
  25. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  26. package/dist/cache/entities/AccountEntity.js +16 -12
  27. package/dist/cache/entities/AccountEntity.js.map +1 -1
  28. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  29. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  30. package/dist/cache/entities/CacheRecord.js +1 -1
  31. package/dist/cache/entities/CredentialEntity.js +5 -5
  32. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  33. package/dist/cache/entities/IdTokenEntity.js +1 -1
  34. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  35. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  36. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  37. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  38. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  39. package/dist/client/AuthorizationCodeClient.js +119 -93
  40. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  41. package/dist/client/BaseClient.js +1 -1
  42. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  43. package/dist/client/ClientCredentialClient.js +4 -3
  44. package/dist/client/ClientCredentialClient.js.map +1 -1
  45. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  46. package/dist/client/DeviceCodeClient.js +2 -1
  47. package/dist/client/DeviceCodeClient.js.map +1 -1
  48. package/dist/client/OnBehalfOfClient.js +3 -2
  49. package/dist/client/OnBehalfOfClient.js.map +1 -1
  50. package/dist/client/RefreshTokenClient.js +2 -1
  51. package/dist/client/RefreshTokenClient.js.map +1 -1
  52. package/dist/client/SilentFlowClient.js +1 -1
  53. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  54. package/dist/client/UsernamePasswordClient.js +3 -1
  55. package/dist/client/UsernamePasswordClient.js.map +1 -1
  56. package/dist/config/ClientConfiguration.d.ts +16 -1
  57. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  58. package/dist/config/ClientConfiguration.js +14 -7
  59. package/dist/config/ClientConfiguration.js.map +1 -1
  60. package/dist/crypto/ICrypto.d.ts +4 -2
  61. package/dist/crypto/ICrypto.d.ts.map +1 -1
  62. package/dist/crypto/ICrypto.js +1 -1
  63. package/dist/crypto/ICrypto.js.map +1 -1
  64. package/dist/crypto/IGuidGenerator.d.ts +5 -0
  65. package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
  66. package/dist/crypto/PopTokenGenerator.d.ts +30 -0
  67. package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
  68. package/dist/crypto/PopTokenGenerator.js +38 -2
  69. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  70. package/dist/error/AuthError.js +3 -3
  71. package/dist/error/AuthError.js.map +1 -1
  72. package/dist/error/ClientAuthError.js +1 -1
  73. package/dist/error/ClientConfigurationError.js +1 -1
  74. package/dist/error/InteractionRequiredAuthError.js +1 -1
  75. package/dist/error/ServerError.js +1 -1
  76. package/dist/index.cjs.js +659 -148
  77. package/dist/index.cjs.js.map +1 -1
  78. package/dist/index.d.ts +7 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +4 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/logger/Logger.js +13 -13
  83. package/dist/logger/Logger.js.map +1 -1
  84. package/dist/network/INetworkModule.js +1 -1
  85. package/dist/network/NetworkManager.js +1 -1
  86. package/dist/network/ThrottlingUtils.js +1 -1
  87. package/dist/packageMetadata.d.ts +1 -1
  88. package/dist/packageMetadata.js +2 -2
  89. package/dist/packageMetadata.js.map +1 -1
  90. package/dist/request/AuthenticationHeaderParser.js +3 -3
  91. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  92. package/dist/request/CommonAuthorizationUrlRequest.d.ts +1 -0
  93. package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
  94. package/dist/request/RequestParameterBuilder.d.ts +14 -1
  95. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  96. package/dist/request/RequestParameterBuilder.js +31 -3
  97. package/dist/request/RequestParameterBuilder.js.map +1 -1
  98. package/dist/request/RequestValidator.js +1 -1
  99. package/dist/request/ScopeSet.js +4 -4
  100. package/dist/request/ScopeSet.js.map +1 -1
  101. package/dist/response/AuthenticationResult.d.ts +1 -0
  102. package/dist/response/AuthenticationResult.d.ts.map +1 -1
  103. package/dist/response/ResponseHandler.d.ts.map +1 -1
  104. package/dist/response/ResponseHandler.js +6 -5
  105. package/dist/response/ResponseHandler.js.map +1 -1
  106. package/dist/response/ServerAuthorizationCodeResponse.d.ts +1 -0
  107. package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +1 -1
  108. package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
  109. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
  110. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
  111. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
  112. package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
  113. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
  114. package/dist/telemetry/performance/PerformanceClient.js +275 -0
  115. package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
  116. package/dist/telemetry/performance/PerformanceEvent.d.ts +203 -0
  117. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
  118. package/dist/telemetry/performance/PerformanceEvent.js +100 -0
  119. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
  120. package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
  121. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
  122. package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
  123. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
  124. package/dist/telemetry/server/ServerTelemetryManager.js +4 -4
  125. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  126. package/dist/url/UrlString.js +2 -2
  127. package/dist/url/UrlString.js.map +1 -1
  128. package/dist/utils/Constants.d.ts +5 -0
  129. package/dist/utils/Constants.d.ts.map +1 -1
  130. package/dist/utils/Constants.js +7 -2
  131. package/dist/utils/Constants.js.map +1 -1
  132. package/dist/utils/ProtocolUtils.js +3 -3
  133. package/dist/utils/ProtocolUtils.js.map +1 -1
  134. package/dist/utils/StringUtils.js +1 -1
  135. package/dist/utils/TimeUtils.js +1 -1
  136. package/package.json +2 -4
  137. package/CHANGELOG.json +0 -1319
  138. 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.3.0 2022-05-02 */
2
2
  'use strict';
3
3
  'use strict';
4
4
 
@@ -136,7 +136,9 @@ var Constants = {
136
136
  IMDS_TIMEOUT: 2000,
137
137
  AZURE_REGION_AUTO_DISCOVER_FLAG: "TryAutoDetect",
138
138
  REGIONAL_AUTH_PUBLIC_CLOUD_SUFFIX: "login.microsoft.com",
139
- KNOWN_PUBLIC_CLOUDS: ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"]
139
+ KNOWN_PUBLIC_CLOUDS: ["login.microsoftonline.com", "login.windows.net", "login.microsoft.com", "sts.windows.net"],
140
+ TOKEN_RESPONSE_TYPE: "token",
141
+ ID_TOKEN_RESPONSE_TYPE: "id_token"
140
142
  };
141
143
  var OIDC_DEFAULT_SCOPES = [
142
144
  Constants.OPENID_SCOPE,
@@ -213,6 +215,8 @@ var AADServerParamKeys;
213
215
  AADServerParamKeys["X_CLIENT_CURR_TELEM"] = "x-client-current-telemetry";
214
216
  AADServerParamKeys["X_CLIENT_LAST_TELEM"] = "x-client-last-telemetry";
215
217
  AADServerParamKeys["X_MS_LIB_CAPABILITY"] = "x-ms-lib-capability";
218
+ AADServerParamKeys["X_APP_NAME"] = "x-app-name";
219
+ AADServerParamKeys["X_APP_VER"] = "x-app-ver";
216
220
  AADServerParamKeys["POST_LOGOUT_URI"] = "post_logout_redirect_uri";
217
221
  AADServerParamKeys["ID_TOKEN_HINT"] = "id_token_hint";
218
222
  AADServerParamKeys["DEVICE_CODE"] = "device_code";
@@ -227,6 +231,7 @@ var AADServerParamKeys;
227
231
  AADServerParamKeys["FOCI"] = "foci";
228
232
  AADServerParamKeys["CCS_HEADER"] = "X-AnchorMailbox";
229
233
  AADServerParamKeys["RETURN_SPA_CODE"] = "return_spa_code";
234
+ AADServerParamKeys["NATIVE_BROKER"] = "nativebroker";
230
235
  AADServerParamKeys["LOGOUT_HINT"] = "logout_hint";
231
236
  })(AADServerParamKeys || (AADServerParamKeys = {}));
232
237
  /**
@@ -483,8 +488,8 @@ var AuthError = /** @class */ (function (_super) {
483
488
  _this = _super.call(this, errorString) || this;
484
489
  Object.setPrototypeOf(_this, AuthError.prototype);
485
490
  _this.errorCode = errorCode || Constants.EMPTY_STRING;
486
- _this.errorMessage = errorMessage || "";
487
- _this.subError = suberror || "";
491
+ _this.errorMessage = errorMessage || Constants.EMPTY_STRING;
492
+ _this.subError = suberror || Constants.EMPTY_STRING;
488
493
  _this.name = "AuthError";
489
494
  return _this;
490
495
  }
@@ -1185,7 +1190,7 @@ var Logger = /** @class */ (function () {
1185
1190
  this.localCallback = loggerOptions.loggerCallback || defaultLoggerCallback;
1186
1191
  this.piiLoggingEnabled = loggerOptions.piiLoggingEnabled || false;
1187
1192
  this.level = typeof (loggerOptions.logLevel) === "number" ? loggerOptions.logLevel : exports.LogLevel.Info;
1188
- this.correlationId = loggerOptions.correlationId || "";
1193
+ this.correlationId = loggerOptions.correlationId || Constants.EMPTY_STRING;
1189
1194
  this.packageName = packageName || Constants.EMPTY_STRING;
1190
1195
  this.packageVersion = packageVersion || Constants.EMPTY_STRING;
1191
1196
  }
@@ -1215,7 +1220,7 @@ var Logger = /** @class */ (function () {
1215
1220
  logHeader = "[" + timestamp + "]";
1216
1221
  }
1217
1222
  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);
1223
+ // debug(`msal:${LogLevel[options.logLevel]}${options.containsPii ? "-Pii": Constants.EMPTY_STRING}${options.context ? `:${options.context}` : Constants.EMPTY_STRING}`)(logMessage);
1219
1224
  this.executeCallback(options.logLevel, log, options.containsPii || false);
1220
1225
  };
1221
1226
  /**
@@ -1233,7 +1238,7 @@ var Logger = /** @class */ (function () {
1233
1238
  this.logMessage(message, {
1234
1239
  logLevel: exports.LogLevel.Error,
1235
1240
  containsPii: false,
1236
- correlationId: correlationId || ""
1241
+ correlationId: correlationId || Constants.EMPTY_STRING
1237
1242
  });
1238
1243
  };
1239
1244
  /**
@@ -1243,7 +1248,7 @@ var Logger = /** @class */ (function () {
1243
1248
  this.logMessage(message, {
1244
1249
  logLevel: exports.LogLevel.Error,
1245
1250
  containsPii: true,
1246
- correlationId: correlationId || ""
1251
+ correlationId: correlationId || Constants.EMPTY_STRING
1247
1252
  });
1248
1253
  };
1249
1254
  /**
@@ -1253,7 +1258,7 @@ var Logger = /** @class */ (function () {
1253
1258
  this.logMessage(message, {
1254
1259
  logLevel: exports.LogLevel.Warning,
1255
1260
  containsPii: false,
1256
- correlationId: correlationId || ""
1261
+ correlationId: correlationId || Constants.EMPTY_STRING
1257
1262
  });
1258
1263
  };
1259
1264
  /**
@@ -1263,7 +1268,7 @@ var Logger = /** @class */ (function () {
1263
1268
  this.logMessage(message, {
1264
1269
  logLevel: exports.LogLevel.Warning,
1265
1270
  containsPii: true,
1266
- correlationId: correlationId || ""
1271
+ correlationId: correlationId || Constants.EMPTY_STRING
1267
1272
  });
1268
1273
  };
1269
1274
  /**
@@ -1273,7 +1278,7 @@ var Logger = /** @class */ (function () {
1273
1278
  this.logMessage(message, {
1274
1279
  logLevel: exports.LogLevel.Info,
1275
1280
  containsPii: false,
1276
- correlationId: correlationId || ""
1281
+ correlationId: correlationId || Constants.EMPTY_STRING
1277
1282
  });
1278
1283
  };
1279
1284
  /**
@@ -1283,7 +1288,7 @@ var Logger = /** @class */ (function () {
1283
1288
  this.logMessage(message, {
1284
1289
  logLevel: exports.LogLevel.Info,
1285
1290
  containsPii: true,
1286
- correlationId: correlationId || ""
1291
+ correlationId: correlationId || Constants.EMPTY_STRING
1287
1292
  });
1288
1293
  };
1289
1294
  /**
@@ -1293,7 +1298,7 @@ var Logger = /** @class */ (function () {
1293
1298
  this.logMessage(message, {
1294
1299
  logLevel: exports.LogLevel.Verbose,
1295
1300
  containsPii: false,
1296
- correlationId: correlationId || ""
1301
+ correlationId: correlationId || Constants.EMPTY_STRING
1297
1302
  });
1298
1303
  };
1299
1304
  /**
@@ -1303,7 +1308,7 @@ var Logger = /** @class */ (function () {
1303
1308
  this.logMessage(message, {
1304
1309
  logLevel: exports.LogLevel.Verbose,
1305
1310
  containsPii: true,
1306
- correlationId: correlationId || ""
1311
+ correlationId: correlationId || Constants.EMPTY_STRING
1307
1312
  });
1308
1313
  };
1309
1314
  /**
@@ -1313,7 +1318,7 @@ var Logger = /** @class */ (function () {
1313
1318
  this.logMessage(message, {
1314
1319
  logLevel: exports.LogLevel.Trace,
1315
1320
  containsPii: false,
1316
- correlationId: correlationId || ""
1321
+ correlationId: correlationId || Constants.EMPTY_STRING
1317
1322
  });
1318
1323
  };
1319
1324
  /**
@@ -1323,7 +1328,7 @@ var Logger = /** @class */ (function () {
1323
1328
  this.logMessage(message, {
1324
1329
  logLevel: exports.LogLevel.Trace,
1325
1330
  containsPii: true,
1326
- correlationId: correlationId || ""
1331
+ correlationId: correlationId || Constants.EMPTY_STRING
1327
1332
  });
1328
1333
  };
1329
1334
  /**
@@ -1337,7 +1342,7 @@ var Logger = /** @class */ (function () {
1337
1342
 
1338
1343
  /* eslint-disable header/header */
1339
1344
  var name = "@azure/msal-common";
1340
- var version = "6.1.0";
1345
+ var version = "6.3.0";
1341
1346
 
1342
1347
  /*
1343
1348
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1349,6 +1354,8 @@ exports.AzureCloudInstance = void 0;
1349
1354
  AzureCloudInstance[AzureCloudInstance["None"] = 0] = "None";
1350
1355
  // Microsoft Azure public cloud
1351
1356
  AzureCloudInstance["AzurePublic"] = "https://login.microsoftonline.com";
1357
+ // Microsoft PPE
1358
+ AzureCloudInstance["AzurePpe"] = "https://login.windows-ppe.net";
1352
1359
  // Microsoft Chinese national cloud
1353
1360
  AzureCloudInstance["AzureChina"] = "https://login.chinacloudapi.cn";
1354
1361
  // Microsoft German national cloud ("Black Forest")
@@ -1485,7 +1492,7 @@ var CredentialEntity = /** @class */ (function () {
1485
1492
  var credentialId = [
1486
1493
  credentialType,
1487
1494
  clientOrFamilyId,
1488
- realm || "",
1495
+ realm || Constants.EMPTY_STRING,
1489
1496
  ];
1490
1497
  return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
1491
1498
  };
@@ -1493,13 +1500,13 @@ var CredentialEntity = /** @class */ (function () {
1493
1500
  * Generate target key component as per schema: <target>
1494
1501
  */
1495
1502
  CredentialEntity.generateTargetForCacheKey = function (scopes) {
1496
- return (scopes || "").toLowerCase();
1503
+ return (scopes || Constants.EMPTY_STRING).toLowerCase();
1497
1504
  };
1498
1505
  /**
1499
1506
  * Generate requested claims key component as per schema: <requestedClaims>
1500
1507
  */
1501
1508
  CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
1502
- return (requestedClaimsHash || "").toLowerCase();
1509
+ return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
1503
1510
  };
1504
1511
  /**
1505
1512
  * Generate scheme key componenet as per schema: <scheme>
@@ -1509,7 +1516,7 @@ var CredentialEntity = /** @class */ (function () {
1509
1516
  * PoP Tokens and SSH certs include scheme in cache key
1510
1517
  * Cast to lowercase to handle "bearer" from ADFS
1511
1518
  */
1512
- return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : "";
1519
+ return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
1513
1520
  };
1514
1521
  return CredentialEntity;
1515
1522
  }());
@@ -1794,7 +1801,7 @@ var ScopeSet = /** @class */ (function () {
1794
1801
  * @param scopesRequired
1795
1802
  */
1796
1803
  ScopeSet.fromString = function (inputScopeString) {
1797
- var scopeString = inputScopeString || "";
1804
+ var scopeString = inputScopeString || Constants.EMPTY_STRING;
1798
1805
  var inputScopes = scopeString.split(" ");
1799
1806
  return new ScopeSet(inputScopes);
1800
1807
  };
@@ -1938,7 +1945,7 @@ var ScopeSet = /** @class */ (function () {
1938
1945
  var scopeArr = this.asArray();
1939
1946
  return scopeArr.join(" ");
1940
1947
  }
1941
- return "";
1948
+ return Constants.EMPTY_STRING;
1942
1949
  };
1943
1950
  /**
1944
1951
  * Prints scopes into a space-delimited lower-case string (used for caching)
@@ -2023,6 +2030,7 @@ exports.AuthorityType = void 0;
2023
2030
  * lastModificationApp:
2024
2031
  * oboAssertion: access token passed in as part of OBO request
2025
2032
  * idTokenClaims: Object containing claims parsed from ID token
2033
+ * nativeAccountId: Account identifier on the native device
2026
2034
  * }
2027
2035
  */
2028
2036
  var AccountEntity = /** @class */ (function () {
@@ -2076,7 +2084,8 @@ var AccountEntity = /** @class */ (function () {
2076
2084
  username: this.username,
2077
2085
  localAccountId: this.localAccountId,
2078
2086
  name: this.name,
2079
- idTokenClaims: this.idTokenClaims
2087
+ idTokenClaims: this.idTokenClaims,
2088
+ nativeAccountId: this.nativeAccountId
2080
2089
  };
2081
2090
  };
2082
2091
  /**
@@ -2086,8 +2095,8 @@ var AccountEntity = /** @class */ (function () {
2086
2095
  AccountEntity.generateAccountCacheKey = function (accountInterface) {
2087
2096
  var accountKey = [
2088
2097
  accountInterface.homeAccountId,
2089
- accountInterface.environment || "",
2090
- accountInterface.tenantId || "",
2098
+ accountInterface.environment || Constants.EMPTY_STRING,
2099
+ accountInterface.tenantId || Constants.EMPTY_STRING,
2091
2100
  ];
2092
2101
  return accountKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
2093
2102
  };
@@ -2098,29 +2107,30 @@ var AccountEntity = /** @class */ (function () {
2098
2107
  * @param idToken
2099
2108
  * @param policy
2100
2109
  */
2101
- AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment) {
2110
+ AccountEntity.createAccount = function (clientInfo, homeAccountId, idToken, authority, oboAssertion, cloudGraphHostName, msGraphHost, environment, nativeAccountId) {
2102
2111
  var _a, _b, _c, _d, _e, _f;
2103
2112
  var account = new AccountEntity();
2104
2113
  account.authorityType = exports.CacheAccountType.MSSTS_ACCOUNT_TYPE;
2105
2114
  account.clientInfo = clientInfo;
2106
2115
  account.homeAccountId = homeAccountId;
2116
+ account.nativeAccountId = nativeAccountId;
2107
2117
  var env = environment || (authority && authority.getPreferredCache());
2108
2118
  if (!env) {
2109
2119
  throw ClientAuthError.createInvalidCacheEnvironmentError();
2110
2120
  }
2111
2121
  account.environment = env;
2112
2122
  // 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) || "";
2123
+ account.realm = ((_a = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _a === void 0 ? void 0 : _a.tid) || Constants.EMPTY_STRING;
2114
2124
  account.oboAssertion = oboAssertion;
2115
2125
  if (idToken) {
2116
2126
  account.idTokenClaims = idToken.claims;
2117
2127
  // 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) || "";
2128
+ 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
2129
  /*
2120
2130
  * 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
2131
  * This field should not be relied upon if a custom policy is configured to return more than 1 email.
2122
2132
  */
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] : "");
2133
+ 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
2134
  account.name = (_f = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _f === void 0 ? void 0 : _f.name;
2125
2135
  }
2126
2136
  account.cloudGraphHostName = cloudGraphHostName;
@@ -2138,7 +2148,7 @@ var AccountEntity = /** @class */ (function () {
2138
2148
  account.authorityType = (authority && authority.authorityType === exports.AuthorityType.Adfs) ? exports.CacheAccountType.ADFS_ACCOUNT_TYPE : exports.CacheAccountType.GENERIC_ACCOUNT_TYPE;
2139
2149
  account.homeAccountId = homeAccountId;
2140
2150
  // non AAD scenarios can have empty realm
2141
- account.realm = "";
2151
+ account.realm = Constants.EMPTY_STRING;
2142
2152
  account.oboAssertion = oboAssertion;
2143
2153
  var env = environment || authority && authority.getPreferredCache();
2144
2154
  if (!env) {
@@ -2146,10 +2156,10 @@ var AccountEntity = /** @class */ (function () {
2146
2156
  }
2147
2157
  if (idToken) {
2148
2158
  // 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) || "";
2159
+ 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
2160
  // 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) || "";
2161
+ account.username = ((_c = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _c === void 0 ? void 0 : _c.upn) || Constants.EMPTY_STRING;
2162
+ account.name = ((_d = idToken === null || idToken === void 0 ? void 0 : idToken.claims) === null || _d === void 0 ? void 0 : _d.name) || Constants.EMPTY_STRING;
2153
2163
  account.idTokenClaims = idToken === null || idToken === void 0 ? void 0 : idToken.claims;
2154
2164
  }
2155
2165
  account.environment = env;
@@ -2225,6 +2235,7 @@ var AccountEntity = /** @class */ (function () {
2225
2235
  (accountA.username === accountB.username) &&
2226
2236
  (accountA.tenantId === accountB.tenantId) &&
2227
2237
  (accountA.environment === accountB.environment) &&
2238
+ (accountA.nativeAccountId === accountB.nativeAccountId) &&
2228
2239
  claimsMatch;
2229
2240
  };
2230
2241
  return AccountEntity;
@@ -2386,7 +2397,7 @@ var CacheManager = /** @class */ (function () {
2386
2397
  * @param realm
2387
2398
  */
2388
2399
  CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
2389
- return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : "", accountFilter ? accountFilter.environment : "", accountFilter ? accountFilter.realm : "");
2400
+ return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING);
2390
2401
  };
2391
2402
  /**
2392
2403
  * retrieve accounts matching all provided filters; if no filter is set, get all accounts
@@ -2632,7 +2643,7 @@ var CacheManager = /** @class */ (function () {
2632
2643
  });
2633
2644
  };
2634
2645
  /**
2635
- * returns a boolean if the given account is removed
2646
+ * Removes credentials associated with the provided account
2636
2647
  * @param account
2637
2648
  */
2638
2649
  CacheManager.prototype.removeAccountContext = function (account) {
@@ -3115,7 +3126,7 @@ var DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
3115
3126
  var DEFAULT_SYSTEM_OPTIONS = {
3116
3127
  tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
3117
3128
  preventCorsPreflight: false,
3118
- proxyUrl: "",
3129
+ proxyUrl: Constants.EMPTY_STRING
3119
3130
  };
3120
3131
  var DEFAULT_LOGGER_IMPLEMENTATION = {
3121
3132
  loggerCallback: function () {
@@ -3123,7 +3134,7 @@ var DEFAULT_LOGGER_IMPLEMENTATION = {
3123
3134
  },
3124
3135
  piiLoggingEnabled: false,
3125
3136
  logLevel: exports.LogLevel.Info,
3126
- correlationId: ""
3137
+ correlationId: Constants.EMPTY_STRING
3127
3138
  };
3128
3139
  var DEFAULT_NETWORK_IMPLEMENTATION = {
3129
3140
  sendGetRequestAsync: function () {
@@ -3148,17 +3159,23 @@ var DEFAULT_NETWORK_IMPLEMENTATION = {
3148
3159
  var DEFAULT_LIBRARY_INFO = {
3149
3160
  sku: Constants.SKU,
3150
3161
  version: version,
3151
- cpu: "",
3152
- os: ""
3162
+ cpu: Constants.EMPTY_STRING,
3163
+ os: Constants.EMPTY_STRING
3153
3164
  };
3154
3165
  var DEFAULT_CLIENT_CREDENTIALS = {
3155
- clientSecret: "",
3166
+ clientSecret: Constants.EMPTY_STRING,
3156
3167
  clientAssertion: undefined
3157
3168
  };
3158
3169
  var DEFAULT_AZURE_CLOUD_OPTIONS = {
3159
3170
  azureCloudInstance: exports.AzureCloudInstance.None,
3160
3171
  tenant: "" + Constants.DEFAULT_COMMON_TENANT
3161
3172
  };
3173
+ var DEFAULT_TELEMETRY_OPTIONS = {
3174
+ application: {
3175
+ appName: "",
3176
+ appVersion: ""
3177
+ }
3178
+ };
3162
3179
  /**
3163
3180
  * Function that sets the default options when not explicitly configured from app developer
3164
3181
  *
@@ -3167,7 +3184,7 @@ var DEFAULT_AZURE_CLOUD_OPTIONS = {
3167
3184
  * @returns Configuration
3168
3185
  */
3169
3186
  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;
3187
+ 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
3188
  var loggerOptions = __assign(__assign({}, DEFAULT_LOGGER_IMPLEMENTATION), userLoggerOption);
3172
3189
  return {
3173
3190
  authOptions: buildAuthOptions(userAuthOptions),
@@ -3178,6 +3195,7 @@ function buildClientConfiguration(_a) {
3178
3195
  cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
3179
3196
  clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
3180
3197
  libraryInfo: __assign(__assign({}, DEFAULT_LIBRARY_INFO), libraryInfo),
3198
+ telemetry: __assign(__assign({}, DEFAULT_TELEMETRY_OPTIONS), telemetry),
3181
3199
  serverTelemetryManager: serverTelemetryManager || null,
3182
3200
  persistencePlugin: persistencePlugin || null,
3183
3201
  serializableCache: serializableCache || null
@@ -3545,6 +3563,12 @@ var RequestParameterBuilder = /** @class */ (function () {
3545
3563
  RequestParameterBuilder.prototype.addResponseTypeCode = function () {
3546
3564
  this.parameters.set(AADServerParamKeys.RESPONSE_TYPE, encodeURIComponent(Constants.CODE_RESPONSE_TYPE));
3547
3565
  };
3566
+ /**
3567
+ * add response_type = token id_token
3568
+ */
3569
+ RequestParameterBuilder.prototype.addResponseTypeForTokenAndIdToken = function () {
3570
+ this.parameters.set(AADServerParamKeys.RESPONSE_TYPE, encodeURIComponent(Constants.TOKEN_RESPONSE_TYPE + " " + Constants.ID_TOKEN_RESPONSE_TYPE));
3571
+ };
3548
3572
  /**
3549
3573
  * add response_mode. defaults to query.
3550
3574
  * @param responseMode
@@ -3552,6 +3576,12 @@ var RequestParameterBuilder = /** @class */ (function () {
3552
3576
  RequestParameterBuilder.prototype.addResponseMode = function (responseMode) {
3553
3577
  this.parameters.set(AADServerParamKeys.RESPONSE_MODE, encodeURIComponent((responseMode) ? responseMode : exports.ResponseMode.QUERY));
3554
3578
  };
3579
+ /**
3580
+ * Add flag to indicate STS should attempt to use WAM if available
3581
+ */
3582
+ RequestParameterBuilder.prototype.addNativeBroker = function () {
3583
+ this.parameters.set(AADServerParamKeys.NATIVE_BROKER, encodeURIComponent("1"));
3584
+ };
3555
3585
  /**
3556
3586
  * add scopes. set addOidcScopes to false to prevent default scopes in non-user scenarios
3557
3587
  * @param scopeSet
@@ -3652,8 +3682,24 @@ var RequestParameterBuilder = /** @class */ (function () {
3652
3682
  // Telemetry Info
3653
3683
  this.parameters.set(AADServerParamKeys.X_CLIENT_SKU, libraryInfo.sku);
3654
3684
  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);
3685
+ if (libraryInfo.os) {
3686
+ this.parameters.set(AADServerParamKeys.X_CLIENT_OS, libraryInfo.os);
3687
+ }
3688
+ if (libraryInfo.cpu) {
3689
+ this.parameters.set(AADServerParamKeys.X_CLIENT_CPU, libraryInfo.cpu);
3690
+ }
3691
+ };
3692
+ /**
3693
+ * Add client telemetry parameters
3694
+ * @param appTelemetry
3695
+ */
3696
+ RequestParameterBuilder.prototype.addApplicationTelemetry = function (appTelemetry) {
3697
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appName) {
3698
+ this.parameters.set(AADServerParamKeys.X_APP_NAME, appTelemetry.appName);
3699
+ }
3700
+ if (appTelemetry === null || appTelemetry === void 0 ? void 0 : appTelemetry.appVersion) {
3701
+ this.parameters.set(AADServerParamKeys.X_APP_VER, appTelemetry.appVersion);
3702
+ }
3657
3703
  };
3658
3704
  /**
3659
3705
  * add prompt
@@ -4295,11 +4341,11 @@ var ProtocolUtils = /** @class */ (function () {
4295
4341
  // Split the state between library state and user passed state and decode them separately
4296
4342
  var splitState = state.split(Constants.RESOURCE_DELIM);
4297
4343
  var libraryState = splitState[0];
4298
- var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : "";
4344
+ var userState = splitState.length > 1 ? splitState.slice(1).join(Constants.RESOURCE_DELIM) : Constants.EMPTY_STRING;
4299
4345
  var libraryStateString = cryptoObj.base64Decode(libraryState);
4300
4346
  var libraryStateObj = JSON.parse(libraryStateString);
4301
4347
  return {
4302
- userRequestState: !StringUtils.isEmpty(userState) ? userState : "",
4348
+ userRequestState: !StringUtils.isEmpty(userState) ? userState : Constants.EMPTY_STRING,
4303
4349
  libraryState: libraryStateObj
4304
4350
  };
4305
4351
  }
@@ -4469,7 +4515,7 @@ var UrlString = /** @class */ (function () {
4469
4515
  else if (hashIndex1 > -1) {
4470
4516
  return hashString.substring(hashIndex1 + 1);
4471
4517
  }
4472
- return "";
4518
+ return Constants.EMPTY_STRING;
4473
4519
  };
4474
4520
  UrlString.constructAuthorityUriFromObject = function (urlObject) {
4475
4521
  return new UrlString(urlObject.Protocol + "//" + urlObject.HostNameAndPort + "/" + urlObject.PathSegments.join("/"));
@@ -4522,6 +4568,11 @@ var PopTokenGenerator = /** @class */ (function () {
4522
4568
  function PopTokenGenerator(cryptoUtils) {
4523
4569
  this.cryptoUtils = cryptoUtils;
4524
4570
  }
4571
+ /**
4572
+ * Generates the req_cnf validated at the RP in the POP protocol for SHR parameters
4573
+ * @param request
4574
+ * @returns
4575
+ */
4525
4576
  PopTokenGenerator.prototype.generateCnf = function (request) {
4526
4577
  return __awaiter(this, void 0, void 0, function () {
4527
4578
  var reqCnf;
@@ -4535,6 +4586,23 @@ var PopTokenGenerator = /** @class */ (function () {
4535
4586
  });
4536
4587
  });
4537
4588
  };
4589
+ /**
4590
+ * Generates the hash of the req_cnf
4591
+ * @param cnf
4592
+ * @returns
4593
+ */
4594
+ PopTokenGenerator.prototype.generateCnfHash = function (cnf) {
4595
+ return __awaiter(this, void 0, void 0, function () {
4596
+ return __generator(this, function (_a) {
4597
+ return [2 /*return*/, this.cryptoUtils.hashString(cnf)];
4598
+ });
4599
+ });
4600
+ };
4601
+ /**
4602
+ * Generates key_id for a SHR token request
4603
+ * @param request
4604
+ * @returns
4605
+ */
4538
4606
  PopTokenGenerator.prototype.generateKid = function (request) {
4539
4607
  return __awaiter(this, void 0, void 0, function () {
4540
4608
  var kidThumbprint;
@@ -4551,6 +4619,12 @@ var PopTokenGenerator = /** @class */ (function () {
4551
4619
  });
4552
4620
  });
4553
4621
  };
4622
+ /**
4623
+ * Signs the POP access_token with the local generated key-pair
4624
+ * @param accessToken
4625
+ * @param request
4626
+ * @returns
4627
+ */
4554
4628
  PopTokenGenerator.prototype.signPopToken = function (accessToken, request) {
4555
4629
  var _a;
4556
4630
  return __awaiter(this, void 0, void 0, function () {
@@ -4564,6 +4638,14 @@ var PopTokenGenerator = /** @class */ (function () {
4564
4638
  });
4565
4639
  });
4566
4640
  };
4641
+ /**
4642
+ * Utility function to generate the signed JWT for an access_token
4643
+ * @param payload
4644
+ * @param kid
4645
+ * @param request
4646
+ * @param claims
4647
+ * @returns
4648
+ */
4567
4649
  PopTokenGenerator.prototype.signPayload = function (payload, kid, request, claims) {
4568
4650
  return __awaiter(this, void 0, void 0, function () {
4569
4651
  var resourceRequestMethod, resourceRequestUri, shrClaims, shrNonce, resourceUrlString, resourceUrlComponents;
@@ -4573,7 +4655,7 @@ var PopTokenGenerator = /** @class */ (function () {
4573
4655
  resourceRequestMethod = request.resourceRequestMethod, resourceRequestUri = request.resourceRequestUri, shrClaims = request.shrClaims, shrNonce = request.shrNonce;
4574
4656
  resourceUrlString = (resourceRequestUri) ? new UrlString(resourceRequestUri) : undefined;
4575
4657
  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)];
4658
+ 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
4659
  case 1: return [2 /*return*/, _a.sent()];
4578
4660
  }
4579
4661
  });
@@ -4864,8 +4946,8 @@ var ResponseHandler = /** @class */ (function () {
4864
4946
  */
4865
4947
  ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
4866
4948
  var authorityType = authority.authorityType;
4867
- var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : "";
4868
- var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : "";
4949
+ var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
4950
+ var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
4869
4951
  // ADFS does not require client_info in the response
4870
4952
  if (authorityType === exports.AuthorityType.Adfs) {
4871
4953
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
@@ -4896,7 +4978,7 @@ var ResponseHandler = /** @class */ (function () {
4896
4978
  return __generator(this, function (_d) {
4897
4979
  switch (_d.label) {
4898
4980
  case 0:
4899
- accessToken = "";
4981
+ accessToken = Constants.EMPTY_STRING;
4900
4982
  responseScopes = [];
4901
4983
  expiresOn = null;
4902
4984
  familyId = Constants.EMPTY_STRING;
@@ -4939,7 +5021,8 @@ var ResponseHandler = /** @class */ (function () {
4939
5021
  state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,
4940
5022
  cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
4941
5023
  msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING,
4942
- code: code
5024
+ code: code,
5025
+ fromNativeBroker: false
4943
5026
  }];
4944
5027
  }
4945
5028
  });
@@ -4977,8 +5060,12 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
4977
5060
  return __awaiter(this, void 0, void 0, function () {
4978
5061
  var queryString;
4979
5062
  return __generator(this, function (_a) {
4980
- queryString = this.createAuthCodeUrlQueryString(request);
4981
- return [2 /*return*/, UrlString.appendQueryString(this.authority.authorizationEndpoint, queryString)];
5063
+ switch (_a.label) {
5064
+ case 0: return [4 /*yield*/, this.createAuthCodeUrlQueryString(request)];
5065
+ case 1:
5066
+ queryString = _a.sent();
5067
+ return [2 /*return*/, UrlString.appendQueryString(this.authority.authorizationEndpoint, queryString)];
5068
+ }
4982
5069
  });
4983
5070
  });
4984
5071
  };
@@ -5134,6 +5221,7 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5134
5221
  parameterBuilder.addAuthorizationCode(request.code);
5135
5222
  // Add library metadata
5136
5223
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5224
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5137
5225
  parameterBuilder.addThrottling();
5138
5226
  if (this.serverTelemetryManager) {
5139
5227
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5227,95 +5315,116 @@ var AuthorizationCodeClient = /** @class */ (function (_super) {
5227
5315
  * @param request
5228
5316
  */
5229
5317
  AuthorizationCodeClient.prototype.createAuthCodeUrlQueryString = function (request) {
5230
- var parameterBuilder = new RequestParameterBuilder();
5231
- parameterBuilder.addClientId(this.config.authOptions.clientId);
5232
- var requestScopes = __spreadArrays(request.scopes || [], request.extraScopesToConsent || []);
5233
- parameterBuilder.addScopes(requestScopes);
5234
- // validate the redirectUri (to be a non null value)
5235
- parameterBuilder.addRedirectUri(request.redirectUri);
5236
- // generate the correlationId if not set by the user and add
5237
- var correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
5238
- parameterBuilder.addCorrelationId(correlationId);
5239
- // add response_mode. If not passed in it defaults to query.
5240
- parameterBuilder.addResponseMode(request.responseMode);
5241
- // add response_type = code
5242
- parameterBuilder.addResponseTypeCode();
5243
- // add library info parameters
5244
- parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5245
- // add client_info=1
5246
- parameterBuilder.addClientInfo();
5247
- if (request.codeChallenge && request.codeChallengeMethod) {
5248
- parameterBuilder.addCodeChallengeParams(request.codeChallenge, request.codeChallengeMethod);
5249
- }
5250
- if (request.prompt) {
5251
- parameterBuilder.addPrompt(request.prompt);
5252
- }
5253
- if (request.domainHint) {
5254
- parameterBuilder.addDomainHint(request.domainHint);
5255
- }
5256
- // Add sid or loginHint with preference for sid -> loginHint -> username of AccountInfo object
5257
- if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
5258
- // AAD will throw if prompt=select_account is passed with an account hint
5259
- if (request.sid && request.prompt === PromptValue.NONE) {
5260
- // SessionID is only used in silent calls
5261
- this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from request");
5262
- parameterBuilder.addSid(request.sid);
5263
- }
5264
- else if (request.account) {
5265
- var accountSid = this.extractAccountSid(request.account);
5266
- // If account and loginHint are provided, we will check account first for sid before adding loginHint
5267
- if (accountSid && request.prompt === PromptValue.NONE) {
5268
- // SessionId is only used in silent calls
5269
- this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
5270
- parameterBuilder.addSid(accountSid);
5271
- try {
5272
- var clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5273
- parameterBuilder.addCcsOid(clientInfo);
5274
- }
5275
- catch (e) {
5276
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5277
- }
5278
- }
5279
- else if (request.loginHint) {
5280
- this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from request");
5281
- parameterBuilder.addLoginHint(request.loginHint);
5282
- parameterBuilder.addCcsUpn(request.loginHint);
5283
- }
5284
- else if (request.account.username) {
5285
- // Fallback to account username if provided
5286
- this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from account");
5287
- parameterBuilder.addLoginHint(request.account.username);
5288
- try {
5289
- var clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5290
- parameterBuilder.addCcsOid(clientInfo);
5291
- }
5292
- catch (e) {
5293
- this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5294
- }
5318
+ return __awaiter(this, void 0, void 0, function () {
5319
+ var parameterBuilder, requestScopes, correlationId, accountSid, clientInfo, clientInfo, popTokenGenerator, cnf, cnfHash;
5320
+ return __generator(this, function (_a) {
5321
+ switch (_a.label) {
5322
+ case 0:
5323
+ parameterBuilder = new RequestParameterBuilder();
5324
+ parameterBuilder.addClientId(this.config.authOptions.clientId);
5325
+ requestScopes = __spreadArrays(request.scopes || [], request.extraScopesToConsent || []);
5326
+ parameterBuilder.addScopes(requestScopes);
5327
+ // validate the redirectUri (to be a non null value)
5328
+ parameterBuilder.addRedirectUri(request.redirectUri);
5329
+ correlationId = request.correlationId || this.config.cryptoInterface.createNewGuid();
5330
+ parameterBuilder.addCorrelationId(correlationId);
5331
+ // add response_mode. If not passed in it defaults to query.
5332
+ parameterBuilder.addResponseMode(request.responseMode);
5333
+ // add response_type = code
5334
+ parameterBuilder.addResponseTypeCode();
5335
+ // add library info parameters
5336
+ parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5337
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5338
+ // add client_info=1
5339
+ parameterBuilder.addClientInfo();
5340
+ if (request.codeChallenge && request.codeChallengeMethod) {
5341
+ parameterBuilder.addCodeChallengeParams(request.codeChallenge, request.codeChallengeMethod);
5342
+ }
5343
+ if (request.prompt) {
5344
+ parameterBuilder.addPrompt(request.prompt);
5345
+ }
5346
+ if (request.domainHint) {
5347
+ parameterBuilder.addDomainHint(request.domainHint);
5348
+ }
5349
+ // Add sid or loginHint with preference for sid -> loginHint -> username of AccountInfo object
5350
+ if (request.prompt !== PromptValue.SELECT_ACCOUNT) {
5351
+ // AAD will throw if prompt=select_account is passed with an account hint
5352
+ if (request.sid && request.prompt === PromptValue.NONE) {
5353
+ // SessionID is only used in silent calls
5354
+ this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from request");
5355
+ parameterBuilder.addSid(request.sid);
5356
+ }
5357
+ else if (request.account) {
5358
+ accountSid = this.extractAccountSid(request.account);
5359
+ // If account and loginHint are provided, we will check account first for sid before adding loginHint
5360
+ if (accountSid && request.prompt === PromptValue.NONE) {
5361
+ // SessionId is only used in silent calls
5362
+ this.logger.verbose("createAuthCodeUrlQueryString: Prompt is none, adding sid from account");
5363
+ parameterBuilder.addSid(accountSid);
5364
+ try {
5365
+ clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5366
+ parameterBuilder.addCcsOid(clientInfo);
5367
+ }
5368
+ catch (e) {
5369
+ this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5370
+ }
5371
+ }
5372
+ else if (request.loginHint) {
5373
+ this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from request");
5374
+ parameterBuilder.addLoginHint(request.loginHint);
5375
+ parameterBuilder.addCcsUpn(request.loginHint);
5376
+ }
5377
+ else if (request.account.username) {
5378
+ // Fallback to account username if provided
5379
+ this.logger.verbose("createAuthCodeUrlQueryString: Adding login_hint from account");
5380
+ parameterBuilder.addLoginHint(request.account.username);
5381
+ try {
5382
+ clientInfo = buildClientInfoFromHomeAccountId(request.account.homeAccountId);
5383
+ parameterBuilder.addCcsOid(clientInfo);
5384
+ }
5385
+ catch (e) {
5386
+ this.logger.verbose("Could not parse home account ID for CCS Header: " + e);
5387
+ }
5388
+ }
5389
+ }
5390
+ else if (request.loginHint) {
5391
+ this.logger.verbose("createAuthCodeUrlQueryString: No account, adding login_hint from request");
5392
+ parameterBuilder.addLoginHint(request.loginHint);
5393
+ parameterBuilder.addCcsUpn(request.loginHint);
5394
+ }
5395
+ }
5396
+ else {
5397
+ this.logger.verbose("createAuthCodeUrlQueryString: Prompt is select_account, ignoring account hints");
5398
+ }
5399
+ if (request.nonce) {
5400
+ parameterBuilder.addNonce(request.nonce);
5401
+ }
5402
+ if (request.state) {
5403
+ parameterBuilder.addState(request.state);
5404
+ }
5405
+ if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5406
+ parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5407
+ }
5408
+ if (request.extraQueryParameters) {
5409
+ parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5410
+ }
5411
+ if (!request.nativeBroker) return [3 /*break*/, 3];
5412
+ // signal ests that this is a WAM call
5413
+ parameterBuilder.addNativeBroker();
5414
+ if (!(request.authenticationScheme === exports.AuthenticationScheme.POP)) return [3 /*break*/, 3];
5415
+ popTokenGenerator = new PopTokenGenerator(this.cryptoUtils);
5416
+ return [4 /*yield*/, popTokenGenerator.generateCnf(request)];
5417
+ case 1:
5418
+ cnf = _a.sent();
5419
+ return [4 /*yield*/, popTokenGenerator.generateCnfHash(cnf)];
5420
+ case 2:
5421
+ cnfHash = _a.sent();
5422
+ parameterBuilder.addPopToken(cnfHash);
5423
+ _a.label = 3;
5424
+ case 3: return [2 /*return*/, parameterBuilder.createQueryString()];
5295
5425
  }
5296
- }
5297
- else if (request.loginHint) {
5298
- this.logger.verbose("createAuthCodeUrlQueryString: No account, adding login_hint from request");
5299
- parameterBuilder.addLoginHint(request.loginHint);
5300
- parameterBuilder.addCcsUpn(request.loginHint);
5301
- }
5302
- }
5303
- else {
5304
- this.logger.verbose("createAuthCodeUrlQueryString: Prompt is select_account, ignoring account hints");
5305
- }
5306
- if (request.nonce) {
5307
- parameterBuilder.addNonce(request.nonce);
5308
- }
5309
- if (request.state) {
5310
- parameterBuilder.addState(request.state);
5311
- }
5312
- if (!StringUtils.isEmpty(request.claims) || this.config.authOptions.clientCapabilities && this.config.authOptions.clientCapabilities.length > 0) {
5313
- parameterBuilder.addClaims(request.claims, this.config.authOptions.clientCapabilities);
5314
- }
5315
- if (request.extraQueryParameters) {
5316
- parameterBuilder.addExtraQueryParameters(request.extraQueryParameters);
5317
- }
5318
- return parameterBuilder.createQueryString();
5426
+ });
5427
+ });
5319
5428
  };
5320
5429
  /**
5321
5430
  * This API validates the `EndSessionRequest` and creates a URL
@@ -5557,6 +5666,7 @@ var DeviceCodeClient = /** @class */ (function (_super) {
5557
5666
  requestParameters.addCorrelationId(correlationId);
5558
5667
  requestParameters.addClientInfo();
5559
5668
  requestParameters.addLibraryInfo(this.config.libraryInfo);
5669
+ requestParameters.addApplicationTelemetry(this.config.telemetry.application);
5560
5670
  requestParameters.addThrottling();
5561
5671
  if (this.serverTelemetryManager) {
5562
5672
  requestParameters.addServerTelemetry(this.serverTelemetryManager);
@@ -5718,6 +5828,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
5718
5828
  parameterBuilder.addGrantType(GrantType.REFRESH_TOKEN_GRANT);
5719
5829
  parameterBuilder.addClientInfo();
5720
5830
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
5831
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5721
5832
  parameterBuilder.addThrottling();
5722
5833
  if (this.serverTelemetryManager) {
5723
5834
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -5852,7 +5963,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5852
5963
  */
5853
5964
  ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
5854
5965
  var accessTokenFilter = {
5855
- homeAccountId: "",
5966
+ homeAccountId: Constants.EMPTY_STRING,
5856
5967
  environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
5857
5968
  credentialType: exports.CredentialType.ACCESS_TOKEN,
5858
5969
  clientId: this.config.authOptions.clientId,
@@ -5917,6 +6028,7 @@ var ClientCredentialClient = /** @class */ (function (_super) {
5917
6028
  parameterBuilder.addScopes(request.scopes, false);
5918
6029
  parameterBuilder.addGrantType(GrantType.CLIENT_CREDENTIALS_GRANT);
5919
6030
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6031
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
5920
6032
  parameterBuilder.addThrottling();
5921
6033
  if (this.serverTelemetryManager) {
5922
6034
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6004,7 +6116,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6004
6116
  environment: cachedIdToken.environment,
6005
6117
  tenantId: cachedIdToken.realm,
6006
6118
  username: Constants.EMPTY_STRING,
6007
- localAccountId: localAccountId || ""
6119
+ localAccountId: localAccountId || Constants.EMPTY_STRING
6008
6120
  };
6009
6121
  cachedAccount = this.readAccountFromCache(accountInfo);
6010
6122
  }
@@ -6119,6 +6231,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
6119
6231
  parameterBuilder.addGrantType(GrantType.JWT_BEARER);
6120
6232
  parameterBuilder.addClientInfo();
6121
6233
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6234
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6122
6235
  parameterBuilder.addThrottling();
6123
6236
  if (this.serverTelemetryManager) {
6124
6237
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -6331,9 +6444,11 @@ var UsernamePasswordClient = /** @class */ (function (_super) {
6331
6444
  parameterBuilder.addUsername(request.username);
6332
6445
  parameterBuilder.addPassword(request.password);
6333
6446
  parameterBuilder.addScopes(request.scopes);
6447
+ parameterBuilder.addResponseTypeForTokenAndIdToken();
6334
6448
  parameterBuilder.addGrantType(GrantType.RESOURCE_OWNER_PASSWORD_GRANT);
6335
6449
  parameterBuilder.addClientInfo();
6336
6450
  parameterBuilder.addLibraryInfo(this.config.libraryInfo);
6451
+ parameterBuilder.addApplicationTelemetry(this.config.telemetry.application);
6337
6452
  parameterBuilder.addThrottling();
6338
6453
  if (this.serverTelemetryManager) {
6339
6454
  parameterBuilder.addServerTelemetry(this.serverTelemetryManager);
@@ -7351,7 +7466,7 @@ var AuthenticationHeaderParser = /** @class */ (function () {
7351
7466
  challenges.forEach(function (challenge) {
7352
7467
  var _a = challenge.split("="), key = _a[0], value = _a[1];
7353
7468
  // Remove escaped quotation marks (', ") from challenge string to keep only the challenge value
7354
- challengeMap[key] = unescape(value.replace(/['"]+/g, ""));
7469
+ challengeMap[key] = unescape(value.replace(/['"]+/g, Constants.EMPTY_STRING));
7355
7470
  });
7356
7471
  return challengeMap;
7357
7472
  };
@@ -7493,9 +7608,9 @@ var ServerTelemetryManager = /** @class */ (function () {
7493
7608
  */
7494
7609
  ServerTelemetryManager.prototype.getRegionDiscoveryFields = function () {
7495
7610
  var regionDiscoveryFields = [];
7496
- regionDiscoveryFields.push(this.regionUsed || "");
7497
- regionDiscoveryFields.push(this.regionSource || "");
7498
- regionDiscoveryFields.push(this.regionOutcome || "");
7611
+ regionDiscoveryFields.push(this.regionUsed || Constants.EMPTY_STRING);
7612
+ regionDiscoveryFields.push(this.regionSource || Constants.EMPTY_STRING);
7613
+ regionDiscoveryFields.push(this.regionOutcome || Constants.EMPTY_STRING);
7499
7614
  return regionDiscoveryFields.join(",");
7500
7615
  };
7501
7616
  /**
@@ -7518,6 +7633,400 @@ var ServerTelemetryManager = /** @class */ (function () {
7518
7633
  return ServerTelemetryManager;
7519
7634
  }());
7520
7635
 
7636
+ /*
7637
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7638
+ * Licensed under the MIT License.
7639
+ */
7640
+ /**
7641
+ * Enumeration of operations that are instrumented by have their performance measured by the PerformanceClient.
7642
+ *
7643
+ * @export
7644
+ * @enum {number}
7645
+ */
7646
+ exports.PerformanceEvents = void 0;
7647
+ (function (PerformanceEvents) {
7648
+ /**
7649
+ * acquireTokenByCode API (msal-browser and msal-node).
7650
+ * Used to acquire tokens by trading an authorization code against the token endpoint.
7651
+ */
7652
+ PerformanceEvents["AcquireTokenByCode"] = "acquireTokenByCode";
7653
+ /**
7654
+ * acquireTokenByRefreshToken API (msal-browser and msal-node).
7655
+ * Used to renew an access token using a refresh token against the token endpoint.
7656
+ */
7657
+ PerformanceEvents["AcquireTokenByRefreshToken"] = "acquireTokenByRefreshToken";
7658
+ /**
7659
+ * acquireTokenSilent API (msal-browser and msal-node).
7660
+ * Used to silently acquire a new access token (from the cache or the network).
7661
+ */
7662
+ PerformanceEvents["AcquireTokenSilent"] = "acquireTokenSilent";
7663
+ /**
7664
+ * acquireTokenSilentAsync (msal-browser).
7665
+ * Internal API for acquireTokenSilent.
7666
+ */
7667
+ PerformanceEvents["AcquireTokenSilentAsync"] = "acquireTokenSilentAsync";
7668
+ /**
7669
+ * acquireTokenPopup (msal-browser).
7670
+ * Used to acquire a new access token interactively through pop ups
7671
+ */
7672
+ PerformanceEvents["AcquireTokenPopup"] = "acquireTokenPopup";
7673
+ /**
7674
+ * getPublicKeyThumbprint API in CryptoOpts class (msal-browser).
7675
+ * Used to generate a public/private keypair and generate a public key thumbprint for pop requests.
7676
+ */
7677
+ PerformanceEvents["CryptoOptsGetPublicKeyThumbprint"] = "cryptoOptsGetPublicKeyThumbprint";
7678
+ /**
7679
+ * signJwt API in CryptoOpts class (msal-browser).
7680
+ * Used to signed a pop token.
7681
+ */
7682
+ PerformanceEvents["CryptoOptsSignJwt"] = "cryptoOptsSignJwt";
7683
+ /**
7684
+ * acquireToken API in the SilentCacheClient class (msal-browser).
7685
+ * Used to read access tokens from the cache.
7686
+ */
7687
+ PerformanceEvents["SilentCacheClientAcquireToken"] = "silentCacheClientAcquireToken";
7688
+ /**
7689
+ * acquireToken API in the SilentIframeClient class (msal-browser).
7690
+ * Used to acquire a new set of tokens from the authorize endpoint in a hidden iframe.
7691
+ */
7692
+ PerformanceEvents["SilentIframeClientAcquireToken"] = "silentIframeClientAcquireToken";
7693
+ /**
7694
+ * acquireToken API in SilentRereshClient (msal-browser).
7695
+ * Used to acquire a new set of tokens from the token endpoint using a refresh token.
7696
+ */
7697
+ PerformanceEvents["SilentRefreshClientAcquireToken"] = "silentRefreshClientAcquireToken";
7698
+ /**
7699
+ * ssoSilent API (msal-browser).
7700
+ * Used to silently acquire an authorization code and set of tokens using a hidden iframe.
7701
+ */
7702
+ PerformanceEvents["SsoSilent"] = "ssoSilent";
7703
+ /**
7704
+ * getDiscoveredAuthority API in StandardInteractionClient class (msal-browser).
7705
+ * Used to load authority metadata for a request.
7706
+ */
7707
+ PerformanceEvents["StandardInteractionClientGetDiscoveredAuthority"] = "standardInteractionClientGetDiscoveredAuthority";
7708
+ /**
7709
+ * acquireToken APIs in msal-browser.
7710
+ * Used to make an /authorize endpoint call with native brokering enabled.
7711
+ */
7712
+ PerformanceEvents["FetchAccountIdWithNativeBroker"] = "fetchAccountIdWithNativeBroker";
7713
+ /**
7714
+ * acquireToken API in NativeInteractionClient class (msal-browser).
7715
+ * Used to acquire a token from Native component when native brokering is enabled.
7716
+ */
7717
+ PerformanceEvents["NativeInteractionClientAcquireToken"] = "nativeInteractionClientAcquireToken";
7718
+ })(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
7719
+ /**
7720
+ * State of the performance event.
7721
+ *
7722
+ * @export
7723
+ * @enum {number}
7724
+ */
7725
+ exports.PerformanceEventStatus = void 0;
7726
+ (function (PerformanceEventStatus) {
7727
+ PerformanceEventStatus[PerformanceEventStatus["NotStarted"] = 0] = "NotStarted";
7728
+ PerformanceEventStatus[PerformanceEventStatus["InProgress"] = 1] = "InProgress";
7729
+ PerformanceEventStatus[PerformanceEventStatus["Completed"] = 2] = "Completed";
7730
+ })(exports.PerformanceEventStatus || (exports.PerformanceEventStatus = {}));
7731
+
7732
+ /*
7733
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7734
+ * Licensed under the MIT License.
7735
+ */
7736
+ var PerformanceClient = /** @class */ (function () {
7737
+ /**
7738
+ * Creates an instance of PerformanceClient,
7739
+ * an abstract class containing core performance telemetry logic.
7740
+ *
7741
+ * @constructor
7742
+ * @param {string} clientId Client ID of the application
7743
+ * @param {string} authority Authority used by the application
7744
+ * @param {Logger} logger Logger used by the application
7745
+ * @param {string} libraryName Name of the library
7746
+ * @param {string} libraryVersion Version of the library
7747
+ */
7748
+ function PerformanceClient(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
7749
+ this.authority = authority;
7750
+ this.libraryName = libraryName;
7751
+ this.libraryVersion = libraryVersion;
7752
+ this.applicationTelemetry = applicationTelemetry;
7753
+ this.clientId = clientId;
7754
+ this.logger = logger;
7755
+ this.callbacks = new Map();
7756
+ this.eventsByCorrelationId = new Map();
7757
+ this.measurementsById = new Map();
7758
+ }
7759
+ /**
7760
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
7761
+ *
7762
+ * @param {PerformanceEvents} measureName
7763
+ * @param {?string} [correlationId]
7764
+ * @returns {InProgressPerformanceEvent}
7765
+ */
7766
+ PerformanceClient.prototype.startMeasurement = function (measureName, correlationId) {
7767
+ var _this = this;
7768
+ var _a, _b;
7769
+ // Generate a placeholder correlation if the request does not provide one
7770
+ var eventCorrelationId = correlationId || this.generateId();
7771
+ if (!correlationId) {
7772
+ this.logger.info("PerformanceClient: No correlation id provided for " + measureName + ", generating", eventCorrelationId);
7773
+ }
7774
+ this.logger.trace("PerformanceClient: Performance measurement started for " + measureName, eventCorrelationId);
7775
+ var performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);
7776
+ performanceMeasurement.startMeasurement();
7777
+ var inProgressEvent = {
7778
+ eventId: this.generateId(),
7779
+ status: exports.PerformanceEventStatus.InProgress,
7780
+ authority: this.authority,
7781
+ libraryName: this.libraryName,
7782
+ libraryVersion: this.libraryVersion,
7783
+ appName: (_a = this.applicationTelemetry) === null || _a === void 0 ? void 0 : _a.appName,
7784
+ appVersion: (_b = this.applicationTelemetry) === null || _b === void 0 ? void 0 : _b.appVersion,
7785
+ clientId: this.clientId,
7786
+ name: measureName,
7787
+ startTimeMs: Date.now(),
7788
+ correlationId: eventCorrelationId
7789
+ };
7790
+ // Store in progress events so they can be discarded if not ended properly
7791
+ this.cacheEventByCorrelationId(inProgressEvent);
7792
+ this.cacheMeasurement(inProgressEvent, performanceMeasurement);
7793
+ // Return the event and functions the caller can use to properly end/flush the measurement
7794
+ return {
7795
+ endMeasurement: function (event) {
7796
+ var completedEvent = _this.endMeasurement(__assign(__assign({}, inProgressEvent), event));
7797
+ if (completedEvent) {
7798
+ // Cache event so that submeasurements can be added downstream
7799
+ _this.cacheEventByCorrelationId(completedEvent);
7800
+ }
7801
+ return completedEvent;
7802
+ },
7803
+ flushMeasurement: function () {
7804
+ return _this.flushMeasurements(inProgressEvent.name, inProgressEvent.correlationId);
7805
+ },
7806
+ discardMeasurement: function () {
7807
+ return _this.discardMeasurements(inProgressEvent.correlationId);
7808
+ },
7809
+ measurement: performanceMeasurement,
7810
+ event: inProgressEvent
7811
+ };
7812
+ };
7813
+ /**
7814
+ * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
7815
+ * as consumers should instead use the function returned by startMeasurement.
7816
+ *
7817
+ * @param {PerformanceEvent} event
7818
+ * @returns {(PerformanceEvent | null)}
7819
+ */
7820
+ PerformanceClient.prototype.endMeasurement = function (event) {
7821
+ var performanceMeasurement = this.measurementsById.get(event.eventId);
7822
+ if (performanceMeasurement) {
7823
+ // Immediately delete so that the same event isnt ended twice
7824
+ this.measurementsById.delete(event.eventId);
7825
+ performanceMeasurement.endMeasurement();
7826
+ var durationMs = performanceMeasurement.flushMeasurement();
7827
+ // null indicates no measurement was taken (e.g. needed performance APIs not present)
7828
+ if (durationMs !== null) {
7829
+ this.logger.trace("PerformanceClient: Performance measurement ended for " + event.name + ": " + durationMs + " ms", event.correlationId);
7830
+ var completedEvent = __assign(__assign({
7831
+ // Allow duration to be overwritten when event ends (e.g. testing), but not status
7832
+ durationMs: Math.round(durationMs) }, event), { status: exports.PerformanceEventStatus.Completed });
7833
+ return completedEvent;
7834
+ }
7835
+ else {
7836
+ this.logger.trace("PerformanceClient: Performance measurement not taken", event.correlationId);
7837
+ }
7838
+ }
7839
+ else {
7840
+ this.logger.trace("PerformanceClient: Measurement not found for " + event.eventId, event.correlationId);
7841
+ }
7842
+ return null;
7843
+ };
7844
+ /**
7845
+ * Upserts event into event cache.
7846
+ * First key is the correlation id, second key is the event id.
7847
+ * Allows for events to be grouped by correlation id,
7848
+ * and to easily allow for properties on them to be updated.
7849
+ *
7850
+ * @private
7851
+ * @param {PerformanceEvent} event
7852
+ */
7853
+ PerformanceClient.prototype.cacheEventByCorrelationId = function (event) {
7854
+ var existingEvents = this.eventsByCorrelationId.get(event.correlationId);
7855
+ if (existingEvents) {
7856
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " added/updated", event.correlationId);
7857
+ existingEvents.set(event.eventId, event);
7858
+ }
7859
+ else {
7860
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " started", event.correlationId);
7861
+ this.eventsByCorrelationId.set(event.correlationId, new Map().set(event.eventId, event));
7862
+ }
7863
+ };
7864
+ /**
7865
+ * Cache measurements by their id.
7866
+ *
7867
+ * @private
7868
+ * @param {PerformanceEvent} event
7869
+ * @param {IPerformanceMeasurement} measurement
7870
+ */
7871
+ PerformanceClient.prototype.cacheMeasurement = function (event, measurement) {
7872
+ this.measurementsById.set(event.eventId, measurement);
7873
+ };
7874
+ /**
7875
+ * Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
7876
+ *
7877
+ * @param {PerformanceEvents} measureName
7878
+ * @param {string} correlationId
7879
+ */
7880
+ PerformanceClient.prototype.flushMeasurements = function (measureName, correlationId) {
7881
+ var _this = this;
7882
+ this.logger.trace("PerformanceClient: Performance measurements flushed for " + measureName, correlationId);
7883
+ var eventsForCorrelationId = this.eventsByCorrelationId.get(correlationId);
7884
+ if (eventsForCorrelationId) {
7885
+ this.discardMeasurements(correlationId);
7886
+ /*
7887
+ * Manually end incomplete submeasurements to ensure there arent orphaned/never ending events.
7888
+ * Incomplete submeasurements are likely an instrumentation bug that should be fixed.
7889
+ * IE only supports Map.forEach.
7890
+ */
7891
+ var completedEvents_1 = [];
7892
+ eventsForCorrelationId.forEach(function (event) {
7893
+ if (event.name !== measureName && event.status !== exports.PerformanceEventStatus.Completed) {
7894
+ _this.logger.trace("PerformanceClient: Incomplete submeasurement " + event.name + " found for " + measureName, correlationId);
7895
+ var completedEvent = _this.endMeasurement(event);
7896
+ if (completedEvent) {
7897
+ completedEvents_1.push(completedEvent);
7898
+ }
7899
+ }
7900
+ completedEvents_1.push(event);
7901
+ });
7902
+ // Sort events by start time (earliest first)
7903
+ var sortedCompletedEvents = completedEvents_1.sort(function (eventA, eventB) { return eventA.startTimeMs - eventB.startTimeMs; });
7904
+ // Take completed top level event and add completed submeasurements durations as properties
7905
+ var topLevelEvents = sortedCompletedEvents.filter(function (event) { return event.name === measureName && event.status === exports.PerformanceEventStatus.Completed; });
7906
+ if (topLevelEvents.length > 0) {
7907
+ /*
7908
+ * Only take the first top-level event if there are multiple events with the same correlation id.
7909
+ * This greatly simplifies logic for submeasurements.
7910
+ */
7911
+ if (topLevelEvents.length > 1) {
7912
+ this.logger.verbose("PerformanceClient: Multiple distinct top-level performance events found, using the first", correlationId);
7913
+ }
7914
+ var topLevelEvent = topLevelEvents[0];
7915
+ this.logger.verbose("PerformanceClient: Measurement found for " + measureName, correlationId);
7916
+ // Build event object with top level and sub measurements
7917
+ var eventToEmit = sortedCompletedEvents.reduce(function (previous, current) {
7918
+ if (current.name !== measureName) {
7919
+ _this.logger.trace("PerformanceClient: Complete submeasurement found for " + current.name, correlationId);
7920
+ // TODO: Emit additional properties for each subMeasurement
7921
+ var subMeasurementName = current.name + "DurationMs";
7922
+ /*
7923
+ * Some code paths, such as resolving an authority, can occur multiple times.
7924
+ * Only take the first measurement, since the second could be read from the cache,
7925
+ * or due to the same correlation id being used for two distinct requests.
7926
+ */
7927
+ if (!previous[subMeasurementName]) {
7928
+ previous[subMeasurementName] = current.durationMs;
7929
+ }
7930
+ else {
7931
+ _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
7932
+ }
7933
+ }
7934
+ return previous;
7935
+ }, topLevelEvent);
7936
+ this.emitEvents([eventToEmit], eventToEmit.correlationId);
7937
+ }
7938
+ else {
7939
+ this.logger.verbose("PerformanceClient: No completed top-level measurements found for " + measureName, correlationId);
7940
+ }
7941
+ }
7942
+ else {
7943
+ this.logger.verbose("PerformanceClient: No measurements found", correlationId);
7944
+ }
7945
+ };
7946
+ /**
7947
+ * Removes measurements for a given correlation id.
7948
+ *
7949
+ * @param {string} correlationId
7950
+ */
7951
+ PerformanceClient.prototype.discardMeasurements = function (correlationId) {
7952
+ this.logger.trace("PerformanceClient: Performance measurements discarded", correlationId);
7953
+ this.eventsByCorrelationId.delete(correlationId);
7954
+ };
7955
+ /**
7956
+ * Registers a callback function to receive performance events.
7957
+ *
7958
+ * @param {PerformanceCallbackFunction} callback
7959
+ * @returns {string}
7960
+ */
7961
+ PerformanceClient.prototype.addPerformanceCallback = function (callback) {
7962
+ var callbackId = this.generateId();
7963
+ this.callbacks.set(callbackId, callback);
7964
+ this.logger.verbose("PerformanceClient: Performance callback registered with id: " + callbackId);
7965
+ return callbackId;
7966
+ };
7967
+ /**
7968
+ * Removes a callback registered with addPerformanceCallback.
7969
+ *
7970
+ * @param {string} callbackId
7971
+ * @returns {boolean}
7972
+ */
7973
+ PerformanceClient.prototype.removePerformanceCallback = function (callbackId) {
7974
+ var result = this.callbacks.delete(callbackId);
7975
+ if (result) {
7976
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " removed.");
7977
+ }
7978
+ else {
7979
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " not removed.");
7980
+ }
7981
+ return result;
7982
+ };
7983
+ /**
7984
+ * Emits events to all registered callbacks.
7985
+ *
7986
+ * @param {PerformanceEvent[]} events
7987
+ * @param {?string} [correlationId]
7988
+ */
7989
+ PerformanceClient.prototype.emitEvents = function (events, correlationId) {
7990
+ var _this = this;
7991
+ this.logger.verbose("PerformanceClient: Emitting performance events", correlationId);
7992
+ this.callbacks.forEach(function (callback, callbackId) {
7993
+ _this.logger.trace("PerformanceClient: Emitting event to callback " + callbackId, correlationId);
7994
+ callback.apply(null, [events]);
7995
+ });
7996
+ };
7997
+ return PerformanceClient;
7998
+ }());
7999
+
8000
+ /*
8001
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8002
+ * Licensed under the MIT License.
8003
+ */
8004
+ var StubPerformanceMeasurement = /** @class */ (function () {
8005
+ function StubPerformanceMeasurement() {
8006
+ }
8007
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
8008
+ StubPerformanceMeasurement.prototype.startMeasurement = function () { };
8009
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
8010
+ StubPerformanceMeasurement.prototype.endMeasurement = function () { };
8011
+ StubPerformanceMeasurement.prototype.flushMeasurement = function () {
8012
+ return null;
8013
+ };
8014
+ return StubPerformanceMeasurement;
8015
+ }());
8016
+ var StubPerformanceClient = /** @class */ (function (_super) {
8017
+ __extends(StubPerformanceClient, _super);
8018
+ function StubPerformanceClient() {
8019
+ return _super !== null && _super.apply(this, arguments) || this;
8020
+ }
8021
+ StubPerformanceClient.prototype.generateId = function () {
8022
+ return "callback-id";
8023
+ };
8024
+ StubPerformanceClient.prototype.startPerformanceMeasuremeant = function () {
8025
+ return new StubPerformanceMeasurement();
8026
+ };
8027
+ return StubPerformanceClient;
8028
+ }(PerformanceClient));
8029
+
7521
8030
  exports.AccessTokenEntity = AccessTokenEntity;
7522
8031
  exports.AccountEntity = AccountEntity;
7523
8032
  exports.AppMetadataEntity = AppMetadataEntity;
@@ -7549,6 +8058,7 @@ exports.Logger = Logger;
7549
8058
  exports.NetworkManager = NetworkManager;
7550
8059
  exports.OIDC_DEFAULT_SCOPES = OIDC_DEFAULT_SCOPES;
7551
8060
  exports.OnBehalfOfClient = OnBehalfOfClient;
8061
+ exports.PerformanceClient = PerformanceClient;
7552
8062
  exports.PopTokenGenerator = PopTokenGenerator;
7553
8063
  exports.PromptValue = PromptValue;
7554
8064
  exports.ProtocolUtils = ProtocolUtils;
@@ -7560,6 +8070,7 @@ exports.ServerTelemetryEntity = ServerTelemetryEntity;
7560
8070
  exports.ServerTelemetryManager = ServerTelemetryManager;
7561
8071
  exports.SilentFlowClient = SilentFlowClient;
7562
8072
  exports.StringUtils = StringUtils;
8073
+ exports.StubPerformanceClient = StubPerformanceClient;
7563
8074
  exports.StubbedNetworkModule = StubbedNetworkModule;
7564
8075
  exports.ThrottlingEntity = ThrottlingEntity;
7565
8076
  exports.ThrottlingUtils = ThrottlingUtils;