@azure/msal-common 10.0.0 → 11.0.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.
- package/dist/_virtual/_tslib.js +1 -1
- package/dist/account/AuthToken.js +1 -1
- package/dist/account/CcsCredential.js +1 -1
- package/dist/account/ClientInfo.js +1 -1
- package/dist/authority/Authority.js +1 -1
- package/dist/authority/AuthorityFactory.js +1 -1
- package/dist/authority/AuthorityMetadata.js +1 -1
- package/dist/authority/AuthorityOptions.js +1 -1
- package/dist/authority/AuthorityType.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
- package/dist/authority/OpenIdConfigResponse.js +1 -1
- package/dist/authority/ProtocolMode.js +1 -1
- package/dist/authority/RegionDiscovery.js +1 -1
- package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +16 -0
- package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts.map +1 -0
- package/dist/cache/CacheManager.js +2 -2
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.js +1 -1
- package/dist/cache/entities/AccountEntity.js +1 -1
- package/dist/cache/entities/AppMetadataEntity.js +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
- package/dist/cache/entities/CacheRecord.js +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/CredentialEntity.js +6 -3
- package/dist/cache/entities/CredentialEntity.js.map +1 -1
- package/dist/cache/entities/IdTokenEntity.js +1 -1
- package/dist/cache/entities/RefreshTokenEntity.js +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
- package/dist/cache/entities/ThrottlingEntity.js +1 -1
- package/dist/cache/persistence/TokenCacheContext.js +1 -1
- package/dist/client/AuthorizationCodeClient.js +1 -1
- package/dist/client/BaseClient.js +1 -1
- package/dist/client/ClientCredentialClient.js +1 -1
- package/dist/client/DeviceCodeClient.js +1 -1
- package/dist/client/OnBehalfOfClient.js +1 -1
- package/dist/client/RefreshTokenClient.js +1 -1
- package/dist/client/SilentFlowClient.js +1 -1
- package/dist/client/UsernamePasswordClient.js +1 -1
- package/dist/config/ClientConfiguration.js +1 -1
- package/dist/crypto/ICrypto.js +1 -1
- package/dist/crypto/JoseHeader.js +3 -3
- package/dist/crypto/JoseHeader.js.map +1 -1
- package/dist/crypto/PopTokenGenerator.js +1 -1
- package/dist/error/AuthError.js +1 -1
- package/dist/error/ClientAuthError.d.ts +16 -0
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.js +21 -1
- package/dist/error/ClientAuthError.js.map +1 -1
- package/dist/error/ClientConfigurationError.js +1 -1
- package/dist/error/InteractionRequiredAuthError.js +1 -1
- package/dist/error/JoseHeaderError.js +1 -1
- package/dist/error/ServerError.js +1 -1
- package/dist/index.cjs.js +132 -184
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/logger/Logger.js +1 -1
- package/dist/network/INetworkModule.js +1 -1
- package/dist/network/NetworkManager.d.ts +11 -0
- package/dist/network/NetworkManager.d.ts.map +1 -1
- package/dist/network/NetworkManager.js +1 -1
- package/dist/network/NetworkManager.js.map +1 -1
- package/dist/network/ThrottlingUtils.js +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/request/AuthenticationHeaderParser.js +1 -1
- package/dist/request/NativeRequest.d.ts +20 -0
- package/dist/request/NativeRequest.d.ts.map +1 -0
- package/dist/request/NativeSignOutRequest.d.ts +6 -0
- package/dist/request/NativeSignOutRequest.d.ts.map +1 -0
- package/dist/request/RequestParameterBuilder.js +1 -1
- package/dist/request/RequestValidator.js +1 -1
- package/dist/request/ScopeSet.js +1 -1
- package/dist/response/ResponseHandler.d.ts +1 -1
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.js +8 -4
- package/dist/response/ResponseHandler.js.map +1 -1
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +1 -0
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +5 -3
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts +18 -41
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.js +93 -175
- package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +28 -5
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.js +3 -1
- package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
- package/dist/url/UrlString.js +1 -1
- package/dist/utils/Constants.d.ts +2 -1
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.js +2 -1
- package/dist/utils/Constants.js.map +1 -1
- package/dist/utils/ProtocolUtils.js +1 -1
- package/dist/utils/StringUtils.js +1 -1
- package/dist/utils/TimeUtils.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-common
|
|
1
|
+
/*! @azure/msal-common v11.0.0 2023-03-07 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -486,6 +486,7 @@ var JsonTypes;
|
|
|
486
486
|
(function (JsonTypes) {
|
|
487
487
|
JsonTypes["Jwt"] = "JWT";
|
|
488
488
|
JsonTypes["Jwk"] = "JWK";
|
|
489
|
+
JsonTypes["Pop"] = "pop";
|
|
489
490
|
})(JsonTypes || (JsonTypes = {}));
|
|
490
491
|
var ONE_DAY_IN_MS = 86400000;
|
|
491
492
|
|
|
@@ -818,6 +819,14 @@ var ClientAuthErrorMessage = {
|
|
|
818
819
|
keyIdMissing: {
|
|
819
820
|
code: "key_id_missing",
|
|
820
821
|
desc: "A keyId value is missing from the requested bound token's cache record and is required to match the token to it's stored binding key."
|
|
822
|
+
},
|
|
823
|
+
noNetworkConnectivity: {
|
|
824
|
+
code: "no_network_connectivity",
|
|
825
|
+
desc: "No network connectivity. Check your internet connection."
|
|
826
|
+
},
|
|
827
|
+
userCanceledError: {
|
|
828
|
+
code: "user_canceled",
|
|
829
|
+
desc: "User canceled the flow."
|
|
821
830
|
}
|
|
822
831
|
};
|
|
823
832
|
/**
|
|
@@ -1106,6 +1115,18 @@ var ClientAuthError = /** @class */ (function (_super) {
|
|
|
1106
1115
|
ClientAuthError.createKeyIdMissingError = function () {
|
|
1107
1116
|
return new ClientAuthError(ClientAuthErrorMessage.keyIdMissing.code, ClientAuthErrorMessage.keyIdMissing.desc);
|
|
1108
1117
|
};
|
|
1118
|
+
/**
|
|
1119
|
+
* Create an error when the client does not have network connectivity
|
|
1120
|
+
*/
|
|
1121
|
+
ClientAuthError.createNoNetworkConnectivityError = function () {
|
|
1122
|
+
return new ClientAuthError(ClientAuthErrorMessage.noNetworkConnectivity.code, ClientAuthErrorMessage.noNetworkConnectivity.desc);
|
|
1123
|
+
};
|
|
1124
|
+
/**
|
|
1125
|
+
* Create an error when the user cancels the flow
|
|
1126
|
+
*/
|
|
1127
|
+
ClientAuthError.createUserCanceledError = function () {
|
|
1128
|
+
return new ClientAuthError(ClientAuthErrorMessage.userCanceledError.code, ClientAuthErrorMessage.userCanceledError.desc);
|
|
1129
|
+
};
|
|
1109
1130
|
return ClientAuthError;
|
|
1110
1131
|
}(AuthError));
|
|
1111
1132
|
|
|
@@ -1422,7 +1443,7 @@ var Logger = /** @class */ (function () {
|
|
|
1422
1443
|
|
|
1423
1444
|
/* eslint-disable header/header */
|
|
1424
1445
|
var name = "@azure/msal-common";
|
|
1425
|
-
var version = "
|
|
1446
|
+
var version = "11.0.0";
|
|
1426
1447
|
|
|
1427
1448
|
/*
|
|
1428
1449
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1610,8 +1631,11 @@ var CredentialEntity = /** @class */ (function () {
|
|
|
1610
1631
|
*/
|
|
1611
1632
|
return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
|
|
1612
1633
|
};
|
|
1613
|
-
|
|
1614
|
-
|
|
1634
|
+
/*
|
|
1635
|
+
* Match host names like "login.microsoftonline.com", "https://accounts.google.com:4000", https://localhost:5000,
|
|
1636
|
+
* "login.microsoftonline.com/common", "login.microsoftonline.com:4000/common", etc
|
|
1637
|
+
*/
|
|
1638
|
+
CredentialEntity.credentialDomainRegex = "(https?:\\/\\/)?((([\\w-]+\\.)*([\\w-]{1,63})(\\.(\\w{2,63})))|(localhost))(\\:[0-9]{4,5})?(\\/[\\w-]+)?";
|
|
1615
1639
|
return CredentialEntity;
|
|
1616
1640
|
}());
|
|
1617
1641
|
CredentialEntity._initRegex();
|
|
@@ -2889,7 +2913,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
2889
2913
|
else if (accounts.length > 1) {
|
|
2890
2914
|
throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
|
|
2891
2915
|
}
|
|
2892
|
-
return
|
|
2916
|
+
return accounts[0];
|
|
2893
2917
|
};
|
|
2894
2918
|
/**
|
|
2895
2919
|
* Retrieve IdTokenEntity from cache
|
|
@@ -4907,6 +4931,7 @@ exports.PerformanceEvents = void 0;
|
|
|
4907
4931
|
* Internal API for initializing silent request in SilentCacheClient (msal-browser)
|
|
4908
4932
|
*/
|
|
4909
4933
|
PerformanceEvents["InitializeSilentRequest"] = "initializeSilentRequest";
|
|
4934
|
+
PerformanceEvents["InitializeClientApplication"] = "initializeClientApplication";
|
|
4910
4935
|
/**
|
|
4911
4936
|
* Helper function in SilentIframeClient class (msal-browser).
|
|
4912
4937
|
*/
|
|
@@ -4972,6 +4997,7 @@ exports.PerformanceEvents = void 0;
|
|
|
4972
4997
|
PerformanceEvents["HandleRedirectPromiseMeasurement"] = "handleRedirectPromiseMeasurement";
|
|
4973
4998
|
PerformanceEvents["UpdateCloudDiscoveryMetadataMeasurement"] = "updateCloudDiscoveryMetadataMeasurement";
|
|
4974
4999
|
PerformanceEvents["UsernamePasswordClientAcquireToken"] = "usernamePasswordClientAcquireToken";
|
|
5000
|
+
PerformanceEvents["NativeMessageHandlerHandshake"] = "nativeMessageHandlerHandshake";
|
|
4975
5001
|
})(exports.PerformanceEvents || (exports.PerformanceEvents = {}));
|
|
4976
5002
|
/**
|
|
4977
5003
|
* State of the performance event.
|
|
@@ -5337,7 +5363,7 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
5337
5363
|
_b.sent();
|
|
5338
5364
|
_b.label = 7;
|
|
5339
5365
|
case 7: return [7 /*endfinally*/];
|
|
5340
|
-
case 8: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, serverTokenResponse
|
|
5366
|
+
case 8: return [2 /*return*/, ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, serverTokenResponse, serverRequestId)];
|
|
5341
5367
|
}
|
|
5342
5368
|
});
|
|
5343
5369
|
});
|
|
@@ -5423,7 +5449,7 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
5423
5449
|
* @param fromTokenCache
|
|
5424
5450
|
* @param stateString
|
|
5425
5451
|
*/
|
|
5426
|
-
ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState,
|
|
5452
|
+
ResponseHandler.generateAuthenticationResult = function (cryptoObj, authority, cacheRecord, fromTokenCache, request, idTokenObj, requestState, serverTokenResponse, requestId) {
|
|
5427
5453
|
var _a, _b, _c;
|
|
5428
5454
|
return __awaiter(this, void 0, void 0, function () {
|
|
5429
5455
|
var accessToken, responseScopes, expiresOn, extExpiresOn, familyId, popTokenGenerator, _d, secret, keyId, uid, tid;
|
|
@@ -5459,6 +5485,10 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
5459
5485
|
}
|
|
5460
5486
|
uid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.oid) || (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.sub) || Constants.EMPTY_STRING;
|
|
5461
5487
|
tid = (idTokenObj === null || idTokenObj === void 0 ? void 0 : idTokenObj.claims.tid) || Constants.EMPTY_STRING;
|
|
5488
|
+
// for hybrid + native bridge enablement, send back the native account Id
|
|
5489
|
+
if ((serverTokenResponse === null || serverTokenResponse === void 0 ? void 0 : serverTokenResponse.spa_accountid) && !!cacheRecord.account) {
|
|
5490
|
+
cacheRecord.account.nativeAccountId = serverTokenResponse === null || serverTokenResponse === void 0 ? void 0 : serverTokenResponse.spa_accountid;
|
|
5491
|
+
}
|
|
5462
5492
|
return [2 /*return*/, {
|
|
5463
5493
|
authority: authority.canonicalAuthority,
|
|
5464
5494
|
uniqueId: uid,
|
|
@@ -5478,7 +5508,7 @@ var ResponseHandler = /** @class */ (function () {
|
|
|
5478
5508
|
state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,
|
|
5479
5509
|
cloudGraphHostName: ((_b = cacheRecord.account) === null || _b === void 0 ? void 0 : _b.cloudGraphHostName) || Constants.EMPTY_STRING,
|
|
5480
5510
|
msGraphHost: ((_c = cacheRecord.account) === null || _c === void 0 ? void 0 : _c.msGraphHost) || Constants.EMPTY_STRING,
|
|
5481
|
-
code:
|
|
5511
|
+
code: serverTokenResponse === null || serverTokenResponse === void 0 ? void 0 : serverTokenResponse.spa_code,
|
|
5482
5512
|
fromNativeBroker: false,
|
|
5483
5513
|
}];
|
|
5484
5514
|
}
|
|
@@ -8323,8 +8353,8 @@ var JoseHeader = /** @class */ (function () {
|
|
|
8323
8353
|
throw JoseHeaderError.createMissingAlgError();
|
|
8324
8354
|
}
|
|
8325
8355
|
var shrHeader = new JoseHeader({
|
|
8326
|
-
// Access Token PoP headers must have type
|
|
8327
|
-
typ: shrHeaderOptions.typ || JsonTypes.
|
|
8356
|
+
// Access Token PoP headers must have type pop, but the type header can be overriden for special cases
|
|
8357
|
+
typ: shrHeaderOptions.typ || JsonTypes.Pop,
|
|
8328
8358
|
kid: shrHeaderOptions.kid,
|
|
8329
8359
|
alg: shrHeaderOptions.alg
|
|
8330
8360
|
});
|
|
@@ -8575,11 +8605,8 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8575
8605
|
this.logger = logger;
|
|
8576
8606
|
this.callbacks = new Map();
|
|
8577
8607
|
this.eventsByCorrelationId = new Map();
|
|
8578
|
-
this.staticFieldsByCorrelationId = new Map();
|
|
8579
|
-
this.measurementsById = new Map();
|
|
8580
8608
|
this.queueMeasurements = new Map();
|
|
8581
8609
|
this.preQueueTimeByCorrelationId = new Map();
|
|
8582
|
-
this.countersByCorrelationId = new Map();
|
|
8583
8610
|
}
|
|
8584
8611
|
/**
|
|
8585
8612
|
* Starts and returns an platform-specific implementation of IPerformanceMeasurement.
|
|
@@ -8620,16 +8647,16 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8620
8647
|
* @returns {number}
|
|
8621
8648
|
*/
|
|
8622
8649
|
PerformanceClient.prototype.getPreQueueTime = function (eventName, correlationId) {
|
|
8623
|
-
var
|
|
8624
|
-
if (!
|
|
8650
|
+
var preQueueEvent = this.preQueueTimeByCorrelationId.get(correlationId);
|
|
8651
|
+
if (!preQueueEvent) {
|
|
8625
8652
|
this.logger.trace("PerformanceClient.getPreQueueTime: no pre-queue times found for correlationId: " + correlationId + ", unable to add queue measurement");
|
|
8626
8653
|
return;
|
|
8627
8654
|
}
|
|
8628
|
-
else if (
|
|
8655
|
+
else if (preQueueEvent.name !== eventName) {
|
|
8629
8656
|
this.logger.trace("PerformanceClient.getPreQueueTime: no pre-queue time found for " + eventName + ", unable to add queue measurement");
|
|
8630
8657
|
return;
|
|
8631
8658
|
}
|
|
8632
|
-
return
|
|
8659
|
+
return preQueueEvent.time;
|
|
8633
8660
|
};
|
|
8634
8661
|
/**
|
|
8635
8662
|
* Calculates the difference between current time and time when function was queued.
|
|
@@ -8657,12 +8684,13 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8657
8684
|
/**
|
|
8658
8685
|
* Adds queue measurement time to QueueMeasurements array for given correlation ID.
|
|
8659
8686
|
*
|
|
8660
|
-
* @param {PerformanceEvents}
|
|
8687
|
+
* @param {PerformanceEvents} eventName
|
|
8661
8688
|
* @param {?string} correlationId
|
|
8662
|
-
* @param {?number}
|
|
8689
|
+
* @param {?number} queueTime
|
|
8690
|
+
* @param {?boolean} manuallyCompleted - indicator for manually completed queue measurements
|
|
8663
8691
|
* @returns
|
|
8664
8692
|
*/
|
|
8665
|
-
PerformanceClient.prototype.addQueueMeasurement = function (eventName, correlationId, queueTime) {
|
|
8693
|
+
PerformanceClient.prototype.addQueueMeasurement = function (eventName, correlationId, queueTime, manuallyCompleted) {
|
|
8666
8694
|
if (!correlationId) {
|
|
8667
8695
|
this.logger.trace("PerformanceClient.addQueueMeasurement: correlationId not provided for " + eventName + ", cannot add queue measurement");
|
|
8668
8696
|
return;
|
|
@@ -8675,7 +8703,7 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8675
8703
|
this.logger.trace("PerformanceClient.addQueueMeasurement: no queue time provided for " + eventName);
|
|
8676
8704
|
return;
|
|
8677
8705
|
}
|
|
8678
|
-
var queueMeasurement = { eventName: eventName, queueTime: queueTime };
|
|
8706
|
+
var queueMeasurement = { eventName: eventName, queueTime: queueTime, manuallyCompleted: manuallyCompleted };
|
|
8679
8707
|
// Adds to existing correlation Id if present in queueMeasurements
|
|
8680
8708
|
var existingMeasurements = this.queueMeasurements.get(correlationId);
|
|
8681
8709
|
if (existingMeasurements) {
|
|
@@ -8688,6 +8716,8 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8688
8716
|
var measurementArray = [queueMeasurement];
|
|
8689
8717
|
this.queueMeasurements.set(correlationId, measurementArray);
|
|
8690
8718
|
}
|
|
8719
|
+
// Delete processed pre-queue event.
|
|
8720
|
+
this.preQueueTimeByCorrelationId.delete(correlationId);
|
|
8691
8721
|
};
|
|
8692
8722
|
/**
|
|
8693
8723
|
* Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
|
|
@@ -8706,17 +8736,8 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8706
8736
|
}
|
|
8707
8737
|
// Duplicate code to address spelling error will be removed at the next major version bump.
|
|
8708
8738
|
this.logger.trace("PerformanceClient: Performance measurement started for " + measureName, eventCorrelationId);
|
|
8709
|
-
var
|
|
8710
|
-
|
|
8711
|
-
if (performanceMeasuremeant.startMeasurement) {
|
|
8712
|
-
performanceMeasuremeant.startMeasurement();
|
|
8713
|
-
validMeasurement = performanceMeasuremeant;
|
|
8714
|
-
}
|
|
8715
|
-
else {
|
|
8716
|
-
var performanceMeasurement = this.startPerformanceMeasurement(measureName, eventCorrelationId);
|
|
8717
|
-
performanceMeasurement.startMeasurement();
|
|
8718
|
-
validMeasurement = performanceMeasurement;
|
|
8719
|
-
}
|
|
8739
|
+
var performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);
|
|
8740
|
+
performanceMeasurement.startMeasurement();
|
|
8720
8741
|
var inProgressEvent = {
|
|
8721
8742
|
eventId: this.generateId(),
|
|
8722
8743
|
status: exports.PerformanceEventStatus.InProgress,
|
|
@@ -8727,27 +8748,15 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8727
8748
|
name: measureName,
|
|
8728
8749
|
startTimeMs: Date.now(),
|
|
8729
8750
|
correlationId: eventCorrelationId,
|
|
8730
|
-
};
|
|
8731
|
-
// Store in progress events so they can be discarded if not ended properly
|
|
8732
|
-
this.cacheEventByCorrelationId(inProgressEvent);
|
|
8733
|
-
var staticFields = {
|
|
8734
8751
|
appName: (_a = this.applicationTelemetry) === null || _a === void 0 ? void 0 : _a.appName,
|
|
8735
8752
|
appVersion: (_b = this.applicationTelemetry) === null || _b === void 0 ? void 0 : _b.appVersion,
|
|
8736
8753
|
};
|
|
8737
|
-
|
|
8738
|
-
this.
|
|
8754
|
+
// Store in progress events so they can be discarded if not ended properly
|
|
8755
|
+
this.cacheEventByCorrelationId(inProgressEvent);
|
|
8739
8756
|
// Return the event and functions the caller can use to properly end/flush the measurement
|
|
8740
8757
|
return {
|
|
8741
8758
|
endMeasurement: function (event) {
|
|
8742
|
-
|
|
8743
|
-
if (completedEvent) {
|
|
8744
|
-
// Cache event so that submeasurements can be added downstream
|
|
8745
|
-
_this.cacheEventByCorrelationId(completedEvent);
|
|
8746
|
-
}
|
|
8747
|
-
return completedEvent;
|
|
8748
|
-
},
|
|
8749
|
-
flushMeasurement: function () {
|
|
8750
|
-
return _this.flushMeasurements(inProgressEvent.name, inProgressEvent.correlationId);
|
|
8759
|
+
return _this.endMeasurement(__assign(__assign({}, inProgressEvent), event), performanceMeasurement);
|
|
8751
8760
|
},
|
|
8752
8761
|
discardMeasurement: function () {
|
|
8753
8762
|
return _this.discardMeasurements(inProgressEvent.correlationId);
|
|
@@ -8758,40 +8767,66 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8758
8767
|
increment: function (counters) {
|
|
8759
8768
|
return _this.increment(counters, inProgressEvent.correlationId);
|
|
8760
8769
|
},
|
|
8761
|
-
measurement:
|
|
8770
|
+
measurement: performanceMeasurement,
|
|
8762
8771
|
event: inProgressEvent
|
|
8763
8772
|
};
|
|
8764
8773
|
};
|
|
8765
8774
|
/**
|
|
8766
8775
|
* Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
|
|
8767
8776
|
* as consumers should instead use the function returned by startMeasurement.
|
|
8777
|
+
* Adds a new field named as "[event name]DurationMs" for sub-measurements, completes and emits an event
|
|
8778
|
+
* otherwise.
|
|
8768
8779
|
*
|
|
8769
8780
|
* @param {PerformanceEvent} event
|
|
8781
|
+
* @param {IPerformanceMeasurement} measurement
|
|
8770
8782
|
* @returns {(PerformanceEvent | null)}
|
|
8771
8783
|
*/
|
|
8772
|
-
PerformanceClient.prototype.endMeasurement = function (event) {
|
|
8773
|
-
var
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
}
|
|
8784
|
+
PerformanceClient.prototype.endMeasurement = function (event, measurement) {
|
|
8785
|
+
var _this = this;
|
|
8786
|
+
var _a, _b;
|
|
8787
|
+
var rootEvent = this.eventsByCorrelationId.get(event.correlationId);
|
|
8788
|
+
if (!rootEvent) {
|
|
8789
|
+
this.logger.trace("PerformanceClient: Measurement not found for " + event.eventId, event.correlationId);
|
|
8790
|
+
return null;
|
|
8791
|
+
}
|
|
8792
|
+
var isRoot = event.eventId === rootEvent.eventId;
|
|
8793
|
+
var queueInfo = {
|
|
8794
|
+
totalQueueTime: 0,
|
|
8795
|
+
totalQueueCount: 0,
|
|
8796
|
+
manuallyCompletedCount: 0
|
|
8797
|
+
};
|
|
8798
|
+
if (isRoot) {
|
|
8799
|
+
queueInfo = this.getQueueInfo(event.correlationId);
|
|
8800
|
+
this.discardCache(rootEvent.correlationId);
|
|
8790
8801
|
}
|
|
8791
8802
|
else {
|
|
8792
|
-
|
|
8803
|
+
(_a = rootEvent.incompleteSubMeasurements) === null || _a === void 0 ? void 0 : _a.delete(event.eventId);
|
|
8793
8804
|
}
|
|
8794
|
-
|
|
8805
|
+
measurement === null || measurement === void 0 ? void 0 : measurement.endMeasurement();
|
|
8806
|
+
var durationMs = measurement === null || measurement === void 0 ? void 0 : measurement.flushMeasurement();
|
|
8807
|
+
// null indicates no measurement was taken (e.g. needed performance APIs not present)
|
|
8808
|
+
if (!durationMs) {
|
|
8809
|
+
this.logger.trace("PerformanceClient: Performance measurement not taken", rootEvent.correlationId);
|
|
8810
|
+
return null;
|
|
8811
|
+
}
|
|
8812
|
+
this.logger.trace("PerformanceClient: Performance measurement ended for " + event.name + ": " + durationMs + " ms", event.correlationId);
|
|
8813
|
+
// Add sub-measurement attribute to root event.
|
|
8814
|
+
if (!isRoot) {
|
|
8815
|
+
rootEvent[event.name + "DurationMs"] = Math.floor(durationMs);
|
|
8816
|
+
return __assign({}, rootEvent);
|
|
8817
|
+
}
|
|
8818
|
+
var finalEvent = __assign(__assign({}, rootEvent), event);
|
|
8819
|
+
var incompleteSubsCount = 0;
|
|
8820
|
+
// Incomplete sub-measurements are discarded. They are likely an instrumentation bug that should be fixed.
|
|
8821
|
+
(_b = finalEvent.incompleteSubMeasurements) === null || _b === void 0 ? void 0 : _b.forEach(function (subMeasurement) {
|
|
8822
|
+
_this.logger.trace("PerformanceClient: Incomplete submeasurement " + subMeasurement.name + " found for " + event.name, finalEvent.correlationId);
|
|
8823
|
+
incompleteSubsCount++;
|
|
8824
|
+
});
|
|
8825
|
+
finalEvent.incompleteSubMeasurements = undefined;
|
|
8826
|
+
finalEvent = __assign(__assign({}, finalEvent), { durationMs: Math.round(durationMs), queuedTimeMs: queueInfo.totalQueueTime, queuedCount: queueInfo.totalQueueCount, queuedManuallyCompletedCount: queueInfo.manuallyCompletedCount, status: exports.PerformanceEventStatus.Completed, incompleteSubsCount: incompleteSubsCount });
|
|
8827
|
+
this.truncateIntegralFields(finalEvent, this.getIntFields());
|
|
8828
|
+
this.emitEvents([finalEvent], event.correlationId);
|
|
8829
|
+
return finalEvent;
|
|
8795
8830
|
};
|
|
8796
8831
|
/**
|
|
8797
8832
|
* Saves extra information to be emitted when the measurements are flushed
|
|
@@ -8799,14 +8834,13 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8799
8834
|
* @param correlationId
|
|
8800
8835
|
*/
|
|
8801
8836
|
PerformanceClient.prototype.addStaticFields = function (fields, correlationId) {
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
this.
|
|
8837
|
+
this.logger.trace("PerformanceClient: Updating static fields");
|
|
8838
|
+
var event = this.eventsByCorrelationId.get(correlationId);
|
|
8839
|
+
if (event) {
|
|
8840
|
+
this.eventsByCorrelationId.set(correlationId, __assign(__assign({}, event), fields));
|
|
8806
8841
|
}
|
|
8807
8842
|
else {
|
|
8808
|
-
this.logger.trace("PerformanceClient:
|
|
8809
|
-
this.staticFieldsByCorrelationId.set(correlationId, fields);
|
|
8843
|
+
this.logger.trace("PerformanceClient: Event not found for", correlationId);
|
|
8810
8844
|
}
|
|
8811
8845
|
};
|
|
8812
8846
|
/**
|
|
@@ -8815,18 +8849,18 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8815
8849
|
* @param correlationId {string} correlation identifier
|
|
8816
8850
|
*/
|
|
8817
8851
|
PerformanceClient.prototype.increment = function (counters, correlationId) {
|
|
8818
|
-
var existing = this.countersByCorrelationId.get(correlationId);
|
|
8819
|
-
if (!existing) {
|
|
8820
|
-
this.logger.trace("PerformanceClient: Setting counters");
|
|
8821
|
-
this.countersByCorrelationId.set(correlationId, __assign({}, counters));
|
|
8822
|
-
return;
|
|
8823
|
-
}
|
|
8824
8852
|
this.logger.trace("PerformanceClient: Updating counters");
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8853
|
+
var event = this.eventsByCorrelationId.get(correlationId);
|
|
8854
|
+
if (event) {
|
|
8855
|
+
for (var counter in counters) {
|
|
8856
|
+
if (!event.hasOwnProperty(counter)) {
|
|
8857
|
+
event[counter] = 0;
|
|
8858
|
+
}
|
|
8859
|
+
event[counter] += counters[counter];
|
|
8828
8860
|
}
|
|
8829
|
-
|
|
8861
|
+
}
|
|
8862
|
+
else {
|
|
8863
|
+
this.logger.trace("PerformanceClient: Event not found for", correlationId);
|
|
8830
8864
|
}
|
|
8831
8865
|
};
|
|
8832
8866
|
/**
|
|
@@ -8839,117 +8873,35 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8839
8873
|
* @param {PerformanceEvent} event
|
|
8840
8874
|
*/
|
|
8841
8875
|
PerformanceClient.prototype.cacheEventByCorrelationId = function (event) {
|
|
8842
|
-
var
|
|
8843
|
-
if (
|
|
8876
|
+
var rootEvent = this.eventsByCorrelationId.get(event.correlationId);
|
|
8877
|
+
if (rootEvent) {
|
|
8844
8878
|
this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " added/updated", event.correlationId);
|
|
8845
|
-
|
|
8879
|
+
rootEvent.incompleteSubMeasurements = rootEvent.incompleteSubMeasurements || new Map();
|
|
8880
|
+
rootEvent.incompleteSubMeasurements.set(event.eventId, { name: event.name, startTimeMs: event.startTimeMs });
|
|
8846
8881
|
}
|
|
8847
8882
|
else {
|
|
8848
8883
|
this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " started", event.correlationId);
|
|
8849
|
-
this.eventsByCorrelationId.set(event.correlationId,
|
|
8884
|
+
this.eventsByCorrelationId.set(event.correlationId, __assign({}, event));
|
|
8850
8885
|
}
|
|
8851
8886
|
};
|
|
8852
|
-
|
|
8853
|
-
* Cache measurements by their id.
|
|
8854
|
-
*
|
|
8855
|
-
* @private
|
|
8856
|
-
* @param {PerformanceEvent} event
|
|
8857
|
-
* @param {IPerformanceMeasurement} measurement
|
|
8858
|
-
*/
|
|
8859
|
-
PerformanceClient.prototype.cacheMeasurement = function (event, measurement) {
|
|
8860
|
-
this.measurementsById.set(event.eventId, measurement);
|
|
8861
|
-
};
|
|
8862
|
-
/**
|
|
8863
|
-
* Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
|
|
8864
|
-
*
|
|
8865
|
-
* @param {PerformanceEvents} measureName
|
|
8866
|
-
* @param {string} correlationId
|
|
8867
|
-
*/
|
|
8868
|
-
PerformanceClient.prototype.flushMeasurements = function (measureName, correlationId) {
|
|
8869
|
-
var _this = this;
|
|
8870
|
-
this.logger.trace("PerformanceClient: Performance measurements flushed for " + measureName, correlationId);
|
|
8871
|
-
/**
|
|
8872
|
-
* Adds all queue time and count measurements for given correlation ID
|
|
8873
|
-
* then deletes queue times for given correlation ID from queueMeasurements map.
|
|
8874
|
-
*/
|
|
8887
|
+
PerformanceClient.prototype.getQueueInfo = function (correlationId) {
|
|
8875
8888
|
var queueMeasurementForCorrelationId = this.queueMeasurements.get(correlationId);
|
|
8876
8889
|
if (!queueMeasurementForCorrelationId) {
|
|
8877
8890
|
this.logger.trace("PerformanceClient: no queue measurements found for for correlationId: " + correlationId);
|
|
8878
8891
|
}
|
|
8879
8892
|
var totalQueueTime = 0;
|
|
8880
8893
|
var totalQueueCount = 0;
|
|
8894
|
+
var manuallyCompletedCount = 0;
|
|
8881
8895
|
queueMeasurementForCorrelationId === null || queueMeasurementForCorrelationId === void 0 ? void 0 : queueMeasurementForCorrelationId.forEach(function (measurement) {
|
|
8882
8896
|
totalQueueTime += measurement.queueTime;
|
|
8883
8897
|
totalQueueCount++;
|
|
8898
|
+
manuallyCompletedCount += measurement.manuallyCompleted ? 1 : 0;
|
|
8884
8899
|
});
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
/*
|
|
8891
|
-
* Manually end incomplete submeasurements to ensure there arent orphaned/never ending events.
|
|
8892
|
-
* Incomplete submeasurements are likely an instrumentation bug that should be fixed.
|
|
8893
|
-
* IE only supports Map.forEach.
|
|
8894
|
-
*/
|
|
8895
|
-
var completedEvents_1 = [];
|
|
8896
|
-
var incompleteSubsCount_1 = 0;
|
|
8897
|
-
eventsForCorrelationId.forEach(function (event) {
|
|
8898
|
-
if (event.name !== measureName && event.status !== exports.PerformanceEventStatus.Completed) {
|
|
8899
|
-
_this.logger.trace("PerformanceClient: Incomplete submeasurement " + event.name + " found for " + measureName, correlationId);
|
|
8900
|
-
incompleteSubsCount_1++;
|
|
8901
|
-
var completedEvent = _this.endMeasurement(event);
|
|
8902
|
-
if (completedEvent) {
|
|
8903
|
-
completedEvents_1.push(completedEvent);
|
|
8904
|
-
}
|
|
8905
|
-
}
|
|
8906
|
-
completedEvents_1.push(event);
|
|
8907
|
-
});
|
|
8908
|
-
// Sort events by start time (earliest first)
|
|
8909
|
-
var sortedCompletedEvents = completedEvents_1.sort(function (eventA, eventB) { return eventA.startTimeMs - eventB.startTimeMs; });
|
|
8910
|
-
// Take completed top level event and add completed submeasurements durations as properties
|
|
8911
|
-
var topLevelEvents = sortedCompletedEvents.filter(function (event) { return event.name === measureName && event.status === exports.PerformanceEventStatus.Completed; });
|
|
8912
|
-
if (topLevelEvents.length > 0) {
|
|
8913
|
-
/*
|
|
8914
|
-
* Only take the first top-level event if there are multiple events with the same correlation id.
|
|
8915
|
-
* This greatly simplifies logic for submeasurements.
|
|
8916
|
-
*/
|
|
8917
|
-
if (topLevelEvents.length > 1) {
|
|
8918
|
-
this.logger.verbose("PerformanceClient: Multiple distinct top-level performance events found, using the first", correlationId);
|
|
8919
|
-
}
|
|
8920
|
-
var topLevelEvent = topLevelEvents[0];
|
|
8921
|
-
this.logger.verbose("PerformanceClient: Measurement found for " + measureName, correlationId);
|
|
8922
|
-
// Build event object with top level and sub measurements
|
|
8923
|
-
var eventToEmit = sortedCompletedEvents.reduce(function (previous, current) {
|
|
8924
|
-
if (current.name !== measureName) {
|
|
8925
|
-
_this.logger.trace("PerformanceClient: Complete submeasurement found for " + current.name, correlationId);
|
|
8926
|
-
// TODO: Emit additional properties for each subMeasurement
|
|
8927
|
-
var subMeasurementName = current.name + "DurationMs";
|
|
8928
|
-
/*
|
|
8929
|
-
* Some code paths, such as resolving an authority, can occur multiple times.
|
|
8930
|
-
* Only take the first measurement, since the second could be read from the cache,
|
|
8931
|
-
* or due to the same correlation id being used for two distinct requests.
|
|
8932
|
-
*/
|
|
8933
|
-
if (!previous[subMeasurementName]) {
|
|
8934
|
-
previous[subMeasurementName] = current.durationMs;
|
|
8935
|
-
}
|
|
8936
|
-
else {
|
|
8937
|
-
_this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
|
|
8938
|
-
}
|
|
8939
|
-
}
|
|
8940
|
-
return previous;
|
|
8941
|
-
}, topLevelEvent);
|
|
8942
|
-
var finalEvent = __assign(__assign(__assign(__assign({}, eventToEmit), staticFields), counters), { queuedTimeMs: totalQueueTime, queuedCount: totalQueueCount, incompleteSubsCount: incompleteSubsCount_1 });
|
|
8943
|
-
this.truncateIntegralFields(finalEvent, this.getIntFields());
|
|
8944
|
-
this.emitEvents([finalEvent], eventToEmit.correlationId);
|
|
8945
|
-
}
|
|
8946
|
-
else {
|
|
8947
|
-
this.logger.verbose("PerformanceClient: No completed top-level measurements found for " + measureName, correlationId);
|
|
8948
|
-
}
|
|
8949
|
-
}
|
|
8950
|
-
else {
|
|
8951
|
-
this.logger.verbose("PerformanceClient: No measurements found", correlationId);
|
|
8952
|
-
}
|
|
8900
|
+
return {
|
|
8901
|
+
totalQueueTime: totalQueueTime,
|
|
8902
|
+
totalQueueCount: totalQueueCount,
|
|
8903
|
+
manuallyCompletedCount: manuallyCompletedCount
|
|
8904
|
+
};
|
|
8953
8905
|
};
|
|
8954
8906
|
/**
|
|
8955
8907
|
* Removes measurements for a given correlation id.
|
|
@@ -8963,14 +8915,10 @@ var PerformanceClient = /** @class */ (function () {
|
|
|
8963
8915
|
/**
|
|
8964
8916
|
* Removes cache for a given correlation id.
|
|
8965
8917
|
*
|
|
8966
|
-
* @param {string} correlation identifier
|
|
8918
|
+
* @param {string} correlationId correlation identifier
|
|
8967
8919
|
*/
|
|
8968
8920
|
PerformanceClient.prototype.discardCache = function (correlationId) {
|
|
8969
8921
|
this.discardMeasurements(correlationId);
|
|
8970
|
-
this.logger.trace("PerformanceClient: Static fields discarded", correlationId);
|
|
8971
|
-
this.staticFieldsByCorrelationId.delete(correlationId);
|
|
8972
|
-
this.logger.trace("PerformanceClient: Counters discarded", correlationId);
|
|
8973
|
-
this.countersByCorrelationId.delete(correlationId);
|
|
8974
8922
|
this.logger.trace("PerformanceClient: QueueMeasurements discarded", correlationId);
|
|
8975
8923
|
this.queueMeasurements.delete(correlationId);
|
|
8976
8924
|
this.logger.trace("PerformanceClient: Pre-queue times discarded", correlationId);
|