@azure/msal-common 6.1.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/_virtual/_tslib.js +1 -1
  2. package/dist/account/AuthToken.js +1 -1
  3. package/dist/account/CcsCredential.js +1 -1
  4. package/dist/account/ClientInfo.js +1 -1
  5. package/dist/authority/Authority.js +1 -1
  6. package/dist/authority/AuthorityFactory.js +1 -1
  7. package/dist/authority/AuthorityOptions.d.ts +1 -0
  8. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  9. package/dist/authority/AuthorityOptions.js +3 -1
  10. package/dist/authority/AuthorityOptions.js.map +1 -1
  11. package/dist/authority/AuthorityType.js +1 -1
  12. package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
  13. package/dist/authority/OpenIdConfigResponse.js +1 -1
  14. package/dist/authority/ProtocolMode.js +1 -1
  15. package/dist/authority/RegionDiscovery.js +1 -1
  16. package/dist/cache/CacheManager.js +2 -2
  17. package/dist/cache/CacheManager.js.map +1 -1
  18. package/dist/cache/entities/AccessTokenEntity.js +1 -1
  19. package/dist/cache/entities/AccountEntity.js +10 -10
  20. package/dist/cache/entities/AccountEntity.js.map +1 -1
  21. package/dist/cache/entities/AppMetadataEntity.js +1 -1
  22. package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
  23. package/dist/cache/entities/CacheRecord.js +1 -1
  24. package/dist/cache/entities/CredentialEntity.js +5 -5
  25. package/dist/cache/entities/CredentialEntity.js.map +1 -1
  26. package/dist/cache/entities/IdTokenEntity.js +1 -1
  27. package/dist/cache/entities/RefreshTokenEntity.js +1 -1
  28. package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
  29. package/dist/cache/entities/ThrottlingEntity.js +1 -1
  30. package/dist/cache/persistence/TokenCacheContext.js +1 -1
  31. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  32. package/dist/client/AuthorizationCodeClient.js +3 -1
  33. package/dist/client/AuthorizationCodeClient.js.map +1 -1
  34. package/dist/client/BaseClient.js +1 -1
  35. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  36. package/dist/client/ClientCredentialClient.js +4 -3
  37. package/dist/client/ClientCredentialClient.js.map +1 -1
  38. package/dist/client/DeviceCodeClient.d.ts.map +1 -1
  39. package/dist/client/DeviceCodeClient.js +2 -1
  40. package/dist/client/DeviceCodeClient.js.map +1 -1
  41. package/dist/client/OnBehalfOfClient.js +3 -2
  42. package/dist/client/OnBehalfOfClient.js.map +1 -1
  43. package/dist/client/RefreshTokenClient.js +2 -1
  44. package/dist/client/RefreshTokenClient.js.map +1 -1
  45. package/dist/client/SilentFlowClient.js +1 -1
  46. package/dist/client/UsernamePasswordClient.js +2 -1
  47. package/dist/client/UsernamePasswordClient.js.map +1 -1
  48. package/dist/config/ClientConfiguration.d.ts +16 -1
  49. package/dist/config/ClientConfiguration.d.ts.map +1 -1
  50. package/dist/config/ClientConfiguration.js +14 -7
  51. package/dist/config/ClientConfiguration.js.map +1 -1
  52. package/dist/crypto/ICrypto.d.ts +4 -2
  53. package/dist/crypto/ICrypto.d.ts.map +1 -1
  54. package/dist/crypto/ICrypto.js +1 -1
  55. package/dist/crypto/ICrypto.js.map +1 -1
  56. package/dist/crypto/IGuidGenerator.d.ts +5 -0
  57. package/dist/crypto/IGuidGenerator.d.ts.map +1 -0
  58. package/dist/crypto/PopTokenGenerator.js +2 -2
  59. package/dist/crypto/PopTokenGenerator.js.map +1 -1
  60. package/dist/error/AuthError.js +3 -3
  61. package/dist/error/AuthError.js.map +1 -1
  62. package/dist/error/ClientAuthError.js +1 -1
  63. package/dist/error/ClientConfigurationError.js +1 -1
  64. package/dist/error/InteractionRequiredAuthError.js +1 -1
  65. package/dist/error/ServerError.js +1 -1
  66. package/dist/index.cjs.js +468 -53
  67. package/dist/index.cjs.js.map +1 -1
  68. package/dist/index.d.ts +7 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +4 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/logger/Logger.js +13 -13
  73. package/dist/logger/Logger.js.map +1 -1
  74. package/dist/network/INetworkModule.js +1 -1
  75. package/dist/network/NetworkManager.js +1 -1
  76. package/dist/network/ThrottlingUtils.js +1 -1
  77. package/dist/packageMetadata.d.ts +1 -1
  78. package/dist/packageMetadata.js +2 -2
  79. package/dist/packageMetadata.js.map +1 -1
  80. package/dist/request/AuthenticationHeaderParser.js +3 -3
  81. package/dist/request/AuthenticationHeaderParser.js.map +1 -1
  82. package/dist/request/RequestParameterBuilder.d.ts +6 -1
  83. package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
  84. package/dist/request/RequestParameterBuilder.js +19 -3
  85. package/dist/request/RequestParameterBuilder.js.map +1 -1
  86. package/dist/request/RequestValidator.js +1 -1
  87. package/dist/request/ScopeSet.js +4 -4
  88. package/dist/request/ScopeSet.js.map +1 -1
  89. package/dist/response/ResponseHandler.js +4 -4
  90. package/dist/response/ResponseHandler.js.map +1 -1
  91. package/dist/telemetry/performance/IPerformanceClient.d.ts +22 -0
  92. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -0
  93. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +6 -0
  94. package/dist/telemetry/performance/IPerformanceMeasurement.d.ts.map +1 -0
  95. package/dist/telemetry/performance/PerformanceClient.d.ts +125 -0
  96. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -0
  97. package/dist/telemetry/performance/PerformanceClient.js +275 -0
  98. package/dist/telemetry/performance/PerformanceClient.js.map +1 -0
  99. package/dist/telemetry/performance/PerformanceEvent.d.ts +182 -0
  100. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -0
  101. package/dist/telemetry/performance/PerformanceEvent.js +85 -0
  102. package/dist/telemetry/performance/PerformanceEvent.js.map +1 -0
  103. package/dist/telemetry/performance/StubPerformanceClient.d.ts +13 -0
  104. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -0
  105. package/dist/telemetry/performance/StubPerformanceClient.js +37 -0
  106. package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -0
  107. package/dist/telemetry/server/ServerTelemetryManager.js +4 -4
  108. package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
  109. package/dist/url/UrlString.js +2 -2
  110. package/dist/url/UrlString.js.map +1 -1
  111. package/dist/utils/Constants.d.ts +2 -0
  112. package/dist/utils/Constants.d.ts.map +1 -1
  113. package/dist/utils/Constants.js +3 -1
  114. package/dist/utils/Constants.js.map +1 -1
  115. package/dist/utils/ProtocolUtils.js +3 -3
  116. package/dist/utils/ProtocolUtils.js.map +1 -1
  117. package/dist/utils/StringUtils.js +1 -1
  118. package/dist/utils/TimeUtils.js +1 -1
  119. package/package.json +2 -4
  120. package/CHANGELOG.json +0 -1319
  121. package/CHANGELOG.md +0 -504
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v6.1.0 2022-02-08 */
1
+ /*! @azure/msal-common v6.2.0 2022-04-04 */
2
2
  'use strict';
3
3
  import { __awaiter, __generator } from '../_virtual/_tslib.js';
4
4
  import { buildClientInfo } from '../account/ClientInfo.js';
@@ -199,8 +199,8 @@ var ResponseHandler = /** @class */ (function () {
199
199
  */
200
200
  ResponseHandler.prototype.generateAccountEntity = function (serverTokenResponse, idToken, authority, oboAssertion, authCodePayload) {
201
201
  var authorityType = authority.authorityType;
202
- var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : "";
203
- var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : "";
202
+ var cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;
203
+ var msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;
204
204
  // ADFS does not require client_info in the response
205
205
  if (authorityType === AuthorityType.Adfs) {
206
206
  this.logger.verbose("Authority type is ADFS, creating ADFS account");
@@ -231,7 +231,7 @@ var ResponseHandler = /** @class */ (function () {
231
231
  return __generator(this, function (_d) {
232
232
  switch (_d.label) {
233
233
  case 0:
234
- accessToken = "";
234
+ accessToken = Constants.EMPTY_STRING;
235
235
  responseScopes = [];
236
236
  expiresOn = null;
237
237
  familyId = Constants.EMPTY_STRING;
@@ -1 +1 @@
1
- {"version":3,"file":"ResponseHandler.js","sources":["../../src/response/ResponseHandler.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ServerAuthorizationTokenResponse } from \"./ServerAuthorizationTokenResponse\";\nimport { buildClientInfo} from \"../account/ClientInfo\";\nimport { ICrypto } from \"../crypto/ICrypto\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { ServerAuthorizationCodeResponse } from \"./ServerAuthorizationCodeResponse\";\nimport { Logger } from \"../logger/Logger\";\nimport { ServerError } from \"../error/ServerError\";\nimport { AuthToken } from \"../account/AuthToken\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { AuthenticationResult } from \"./AuthenticationResult\";\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\nimport { Authority } from \"../authority/Authority\";\nimport { AuthorityType } from \"../authority/AuthorityType\";\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { RefreshTokenEntity } from \"../cache/entities/RefreshTokenEntity\";\nimport { InteractionRequiredAuthError } from \"../error/InteractionRequiredAuthError\";\nimport { CacheRecord } from \"../cache/entities/CacheRecord\";\nimport { CacheManager } from \"../cache/CacheManager\";\nimport { ProtocolUtils, RequestStateObject } from \"../utils/ProtocolUtils\";\nimport { AuthenticationScheme, Constants, THE_FAMILY_ID } from \"../utils/Constants\";\nimport { PopTokenGenerator } from \"../crypto/PopTokenGenerator\";\nimport { AppMetadataEntity } from \"../cache/entities/AppMetadataEntity\";\nimport { ICachePlugin } from \"../cache/interface/ICachePlugin\";\nimport { TokenCacheContext } from \"../cache/persistence/TokenCacheContext\";\nimport { ISerializableTokenCache } from \"../cache/interface/ISerializableTokenCache\";\nimport { AuthorizationCodePayload } from \"./AuthorizationCodePayload\";\nimport { BaseAuthRequest } from \"../request/BaseAuthRequest\";\n\n/**\n * Class that handles response parsing.\n */\nexport class ResponseHandler {\n private clientId: string;\n private cacheStorage: CacheManager;\n private cryptoObj: ICrypto;\n private logger: Logger;\n private homeAccountIdentifier: string;\n private serializableCache: ISerializableTokenCache | null;\n private persistencePlugin: ICachePlugin | null;\n\n constructor(clientId: string, cacheStorage: CacheManager, cryptoObj: ICrypto, logger: Logger, serializableCache: ISerializableTokenCache | null, persistencePlugin: ICachePlugin | null) {\n this.clientId = clientId;\n this.cacheStorage = cacheStorage;\n this.cryptoObj = cryptoObj;\n this.logger = logger;\n this.serializableCache = serializableCache;\n this.persistencePlugin = persistencePlugin;\n }\n\n /**\n * Function which validates server authorization code response.\n * @param serverResponseHash\n * @param cachedState\n * @param cryptoObj\n */\n validateServerAuthorizationCodeResponse(serverResponseHash: ServerAuthorizationCodeResponse, cachedState: string, cryptoObj: ICrypto): void {\n\n if (!serverResponseHash.state || !cachedState) {\n throw !serverResponseHash.state ? ClientAuthError.createStateNotFoundError(\"Server State\") : ClientAuthError.createStateNotFoundError(\"Cached State\");\n }\n\n if (decodeURIComponent(serverResponseHash.state) !== decodeURIComponent(cachedState)) {\n throw ClientAuthError.createStateMismatchError();\n }\n\n // Check for error\n if (serverResponseHash.error || serverResponseHash.error_description || serverResponseHash.suberror) {\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponseHash.error, serverResponseHash.error_description, serverResponseHash.suberror)) {\n throw new InteractionRequiredAuthError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\n }\n\n throw new ServerError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\n }\n\n if (serverResponseHash.client_info) {\n buildClientInfo(serverResponseHash.client_info, cryptoObj);\n }\n }\n\n /**\n * Function which validates server authorization token response.\n * @param serverResponse\n */\n validateTokenResponse(serverResponse: ServerAuthorizationTokenResponse): void {\n // Check for error\n if (serverResponse.error || serverResponse.error_description || serverResponse.suberror) {\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponse.error, serverResponse.error_description, serverResponse.suberror)) {\n throw new InteractionRequiredAuthError(serverResponse.error, serverResponse.error_description, serverResponse.suberror);\n }\n\n const errString = `${serverResponse.error_codes} - [${serverResponse.timestamp}]: ${serverResponse.error_description} - Correlation ID: ${serverResponse.correlation_id} - Trace ID: ${serverResponse.trace_id}`;\n throw new ServerError(serverResponse.error, errString, serverResponse.suberror);\n }\n }\n\n /**\n * Returns a constructed token response based on given string. Also manages the cache updates and cleanups.\n * @param serverTokenResponse\n * @param authority\n */\n async handleServerTokenResponse(\n serverTokenResponse: ServerAuthorizationTokenResponse,\n authority: Authority,\n reqTimestamp: number,\n request: BaseAuthRequest,\n authCodePayload?: AuthorizationCodePayload,\n oboAssertion?: string,\n handlingRefreshTokenResponse?: boolean): Promise<AuthenticationResult> {\n\n // create an idToken object (not entity)\n let idTokenObj: AuthToken | undefined;\n if (serverTokenResponse.id_token) {\n idTokenObj = new AuthToken(serverTokenResponse.id_token || Constants.EMPTY_STRING, this.cryptoObj);\n \n // token nonce check (TODO: Add a warning if no nonce is given?)\n if (authCodePayload && !StringUtils.isEmpty(authCodePayload.nonce)) {\n if (idTokenObj.claims.nonce !== authCodePayload.nonce) {\n throw ClientAuthError.createNonceMismatchError();\n }\n }\n }\n\n // generate homeAccountId\n this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);\n\n // save the response tokens\n let requestStateObj: RequestStateObject | undefined;\n if (!!authCodePayload && !!authCodePayload.state) {\n requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);\n }\n\n // Add keyId from request to serverTokenResponse if defined\n serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;\n\n const cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);\n let cacheContext;\n try {\n if (this.persistencePlugin && this.serializableCache) {\n this.logger.verbose(\"Persistence enabled, calling beforeCacheAccess\");\n cacheContext = new TokenCacheContext(this.serializableCache, true);\n await this.persistencePlugin.beforeCacheAccess(cacheContext);\n }\n /*\n * When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.\n * If not present, we should return null, as it's the case that another application called removeAccount in between\n * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal.\n */\n if (handlingRefreshTokenResponse && cacheRecord.account) {\n const key = cacheRecord.account.generateAccountKey();\n const account = this.cacheStorage.getAccount(key);\n if (!account) {\n this.logger.warning(\"Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache\");\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj);\n }\n }\n await this.cacheStorage.saveCacheRecord(cacheRecord);\n } finally {\n if (this.persistencePlugin && this.serializableCache && cacheContext) {\n this.logger.verbose(\"Persistence enabled, calling afterCacheAccess\");\n await this.persistencePlugin.afterCacheAccess(cacheContext);\n }\n }\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, serverTokenResponse.spa_code);\n }\n\n /**\n * Generates CacheRecord\n * @param serverTokenResponse\n * @param idTokenObj\n * @param authority\n */\n private generateCacheRecord(serverTokenResponse: ServerAuthorizationTokenResponse, authority: Authority, reqTimestamp: number, request: BaseAuthRequest, idTokenObj?: AuthToken, oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): CacheRecord {\n const env = authority.getPreferredCache();\n if (StringUtils.isEmpty(env)) {\n throw ClientAuthError.createInvalidCacheEnvironmentError();\n }\n\n // IdToken: non AAD scenarios can have empty realm\n let cachedIdToken: IdTokenEntity | undefined;\n let cachedAccount: AccountEntity | undefined;\n if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {\n cachedIdToken = IdTokenEntity.createIdTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.id_token || Constants.EMPTY_STRING,\n this.clientId,\n idTokenObj.claims.tid || Constants.EMPTY_STRING,\n oboAssertion\n );\n\n cachedAccount = this.generateAccountEntity(\n serverTokenResponse,\n idTokenObj,\n authority,\n oboAssertion,\n authCodePayload\n );\n }\n\n // AccessToken\n let cachedAccessToken: AccessTokenEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {\n\n // If scopes not returned in server response, use request scopes\n const responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(request.scopes || []);\n\n /*\n * Use timestamp calculated before request\n * Server may return timestamps as strings, parse to numbers if so.\n */\n const expiresIn: number = (typeof serverTokenResponse.expires_in === \"string\" ? parseInt(serverTokenResponse.expires_in, 10) : serverTokenResponse.expires_in) || 0;\n const extExpiresIn: number = (typeof serverTokenResponse.ext_expires_in === \"string\" ? parseInt(serverTokenResponse.ext_expires_in, 10) : serverTokenResponse.ext_expires_in) || 0;\n const refreshIn: number | undefined = (typeof serverTokenResponse.refresh_in === \"string\" ? parseInt(serverTokenResponse.refresh_in, 10) : serverTokenResponse.refresh_in) || undefined;\n const tokenExpirationSeconds = reqTimestamp + expiresIn;\n const extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;\n const refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;\n\n // non AAD scenarios can have empty realm\n cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.access_token || Constants.EMPTY_STRING,\n this.clientId,\n idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant,\n responseScopes.printScopes(),\n tokenExpirationSeconds,\n extendedTokenExpirationSeconds,\n this.cryptoObj,\n refreshOnSeconds,\n serverTokenResponse.token_type,\n oboAssertion,\n serverTokenResponse.key_id,\n request.claims,\n request.requestedClaimsHash\n );\n }\n \n // refreshToken\n let cachedRefreshToken: RefreshTokenEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {\n cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.refresh_token || Constants.EMPTY_STRING,\n this.clientId,\n serverTokenResponse.foci,\n oboAssertion\n );\n }\n\n // appMetadata\n let cachedAppMetadata: AppMetadataEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.foci)) {\n cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);\n }\n\n return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);\n }\n\n /**\n * Generate Account\n * @param serverTokenResponse\n * @param idToken\n * @param authority\n */\n private generateAccountEntity(serverTokenResponse: ServerAuthorizationTokenResponse, idToken: AuthToken, authority: Authority, oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): AccountEntity {\n const authorityType = authority.authorityType;\n const cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : \"\";\n const msGraphhost = authCodePayload ? authCodePayload.msgraph_host : \"\";\n\n // ADFS does not require client_info in the response\n if (authorityType === AuthorityType.Adfs) {\n this.logger.verbose(\"Authority type is ADFS, creating ADFS account\");\n return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);\n }\n\n // This fallback applies to B2C as well as they fall under an AAD account type.\n if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === \"AAD\") {\n throw ClientAuthError.createClientInfoEmptyError();\n }\n\n return serverTokenResponse.client_info ?\n AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :\n AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);\n }\n\n /**\n * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.\n *\n * Optionally takes a state string that is set as-is in the response.\n *\n * @param cacheRecord\n * @param idTokenObj\n * @param fromTokenCache\n * @param stateString\n */\n static async generateAuthenticationResult(\n cryptoObj: ICrypto, \n authority: Authority,\n cacheRecord: CacheRecord, \n fromTokenCache: boolean, \n request: BaseAuthRequest,\n idTokenObj?: AuthToken,\n requestState?: RequestStateObject,\n code?: string\n ): Promise<AuthenticationResult> {\n let accessToken: string = \"\";\n let responseScopes: Array<string> = [];\n let expiresOn: Date | null = null;\n let extExpiresOn: Date | undefined;\n let familyId: string = Constants.EMPTY_STRING;\n\n if (cacheRecord.accessToken) {\n if (cacheRecord.accessToken.tokenType === AuthenticationScheme.POP) {\n const popTokenGenerator: PopTokenGenerator = new PopTokenGenerator(cryptoObj);\n accessToken = await popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request);\n } else {\n accessToken = cacheRecord.accessToken.secret;\n }\n responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();\n expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);\n extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);\n }\n\n if (cacheRecord.appMetadata) {\n familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;\n }\n const uid = idTokenObj?.claims.oid || idTokenObj?.claims.sub || Constants.EMPTY_STRING;\n const tid = idTokenObj?.claims.tid || Constants.EMPTY_STRING;\n\n return {\n authority: authority.canonicalAuthority,\n uniqueId: uid,\n tenantId: tid,\n scopes: responseScopes,\n account: cacheRecord.account ? cacheRecord.account.getAccountInfo() : null,\n idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,\n idTokenClaims: idTokenObj ? idTokenObj.claims : {},\n accessToken: accessToken,\n fromCache: fromTokenCache,\n expiresOn: expiresOn,\n correlationId: request.correlationId,\n extExpiresOn: extExpiresOn,\n familyId: familyId,\n tokenType: cacheRecord.accessToken?.tokenType || Constants.EMPTY_STRING,\n state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,\n cloudGraphHostName: cacheRecord.account?.cloudGraphHostName || Constants.EMPTY_STRING,\n msGraphHost: cacheRecord.account?.msGraphHost || Constants.EMPTY_STRING,\n code\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAmCA;;;;IAYI,yBAAY,QAAgB,EAAE,YAA0B,EAAE,SAAkB,EAAE,MAAc,EAAE,iBAAiD,EAAE,iBAAsC;QACnL,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;KAC9C;;;;;;;IAQD,iEAAuC,GAAvC,UAAwC,kBAAmD,EAAE,WAAmB,EAAE,SAAkB;QAEhI,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE;YAC3C,MAAM,CAAC,kBAAkB,CAAC,KAAK,GAAG,eAAe,CAAC,wBAAwB,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAC;SACzJ;QAED,IAAI,kBAAkB,CAAC,kBAAkB,CAAC,KAAK,CAAC,KAAK,kBAAkB,CAAC,WAAW,CAAC,EAAE;YAClF,MAAM,eAAe,CAAC,wBAAwB,EAAE,CAAC;SACpD;;QAGD,IAAI,kBAAkB,CAAC,KAAK,IAAI,kBAAkB,CAAC,iBAAiB,IAAI,kBAAkB,CAAC,QAAQ,EA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E,OAAA,WAAW,CAAC,OAAO,0CAAE,WAAW,KAAI,SAAS,CAAC,YAAY;gCACvE,IAAI,MAAA;6BACP,EAAC;;;;KACL;IACL,sBAAC;AAAD,CAAC;;;;"}
1
+ {"version":3,"file":"ResponseHandler.js","sources":["../../src/response/ResponseHandler.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ServerAuthorizationTokenResponse } from \"./ServerAuthorizationTokenResponse\";\nimport { buildClientInfo} from \"../account/ClientInfo\";\nimport { ICrypto } from \"../crypto/ICrypto\";\nimport { ClientAuthError } from \"../error/ClientAuthError\";\nimport { StringUtils } from \"../utils/StringUtils\";\nimport { ServerAuthorizationCodeResponse } from \"./ServerAuthorizationCodeResponse\";\nimport { Logger } from \"../logger/Logger\";\nimport { ServerError } from \"../error/ServerError\";\nimport { AuthToken } from \"../account/AuthToken\";\nimport { ScopeSet } from \"../request/ScopeSet\";\nimport { AuthenticationResult } from \"./AuthenticationResult\";\nimport { AccountEntity } from \"../cache/entities/AccountEntity\";\nimport { Authority } from \"../authority/Authority\";\nimport { AuthorityType } from \"../authority/AuthorityType\";\nimport { IdTokenEntity } from \"../cache/entities/IdTokenEntity\";\nimport { AccessTokenEntity } from \"../cache/entities/AccessTokenEntity\";\nimport { RefreshTokenEntity } from \"../cache/entities/RefreshTokenEntity\";\nimport { InteractionRequiredAuthError } from \"../error/InteractionRequiredAuthError\";\nimport { CacheRecord } from \"../cache/entities/CacheRecord\";\nimport { CacheManager } from \"../cache/CacheManager\";\nimport { ProtocolUtils, RequestStateObject } from \"../utils/ProtocolUtils\";\nimport { AuthenticationScheme, Constants, THE_FAMILY_ID } from \"../utils/Constants\";\nimport { PopTokenGenerator } from \"../crypto/PopTokenGenerator\";\nimport { AppMetadataEntity } from \"../cache/entities/AppMetadataEntity\";\nimport { ICachePlugin } from \"../cache/interface/ICachePlugin\";\nimport { TokenCacheContext } from \"../cache/persistence/TokenCacheContext\";\nimport { ISerializableTokenCache } from \"../cache/interface/ISerializableTokenCache\";\nimport { AuthorizationCodePayload } from \"./AuthorizationCodePayload\";\nimport { BaseAuthRequest } from \"../request/BaseAuthRequest\";\n\n/**\n * Class that handles response parsing.\n */\nexport class ResponseHandler {\n private clientId: string;\n private cacheStorage: CacheManager;\n private cryptoObj: ICrypto;\n private logger: Logger;\n private homeAccountIdentifier: string;\n private serializableCache: ISerializableTokenCache | null;\n private persistencePlugin: ICachePlugin | null;\n\n constructor(clientId: string, cacheStorage: CacheManager, cryptoObj: ICrypto, logger: Logger, serializableCache: ISerializableTokenCache | null, persistencePlugin: ICachePlugin | null) {\n this.clientId = clientId;\n this.cacheStorage = cacheStorage;\n this.cryptoObj = cryptoObj;\n this.logger = logger;\n this.serializableCache = serializableCache;\n this.persistencePlugin = persistencePlugin;\n }\n\n /**\n * Function which validates server authorization code response.\n * @param serverResponseHash\n * @param cachedState\n * @param cryptoObj\n */\n validateServerAuthorizationCodeResponse(serverResponseHash: ServerAuthorizationCodeResponse, cachedState: string, cryptoObj: ICrypto): void {\n\n if (!serverResponseHash.state || !cachedState) {\n throw !serverResponseHash.state ? ClientAuthError.createStateNotFoundError(\"Server State\") : ClientAuthError.createStateNotFoundError(\"Cached State\");\n }\n\n if (decodeURIComponent(serverResponseHash.state) !== decodeURIComponent(cachedState)) {\n throw ClientAuthError.createStateMismatchError();\n }\n\n // Check for error\n if (serverResponseHash.error || serverResponseHash.error_description || serverResponseHash.suberror) {\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponseHash.error, serverResponseHash.error_description, serverResponseHash.suberror)) {\n throw new InteractionRequiredAuthError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\n }\n\n throw new ServerError(serverResponseHash.error || Constants.EMPTY_STRING, serverResponseHash.error_description, serverResponseHash.suberror);\n }\n\n if (serverResponseHash.client_info) {\n buildClientInfo(serverResponseHash.client_info, cryptoObj);\n }\n }\n\n /**\n * Function which validates server authorization token response.\n * @param serverResponse\n */\n validateTokenResponse(serverResponse: ServerAuthorizationTokenResponse): void {\n // Check for error\n if (serverResponse.error || serverResponse.error_description || serverResponse.suberror) {\n if (InteractionRequiredAuthError.isInteractionRequiredError(serverResponse.error, serverResponse.error_description, serverResponse.suberror)) {\n throw new InteractionRequiredAuthError(serverResponse.error, serverResponse.error_description, serverResponse.suberror);\n }\n\n const errString = `${serverResponse.error_codes} - [${serverResponse.timestamp}]: ${serverResponse.error_description} - Correlation ID: ${serverResponse.correlation_id} - Trace ID: ${serverResponse.trace_id}`;\n throw new ServerError(serverResponse.error, errString, serverResponse.suberror);\n }\n }\n\n /**\n * Returns a constructed token response based on given string. Also manages the cache updates and cleanups.\n * @param serverTokenResponse\n * @param authority\n */\n async handleServerTokenResponse(\n serverTokenResponse: ServerAuthorizationTokenResponse,\n authority: Authority,\n reqTimestamp: number,\n request: BaseAuthRequest,\n authCodePayload?: AuthorizationCodePayload,\n oboAssertion?: string,\n handlingRefreshTokenResponse?: boolean): Promise<AuthenticationResult> {\n\n // create an idToken object (not entity)\n let idTokenObj: AuthToken | undefined;\n if (serverTokenResponse.id_token) {\n idTokenObj = new AuthToken(serverTokenResponse.id_token || Constants.EMPTY_STRING, this.cryptoObj);\n \n // token nonce check (TODO: Add a warning if no nonce is given?)\n if (authCodePayload && !StringUtils.isEmpty(authCodePayload.nonce)) {\n if (idTokenObj.claims.nonce !== authCodePayload.nonce) {\n throw ClientAuthError.createNonceMismatchError();\n }\n }\n }\n\n // generate homeAccountId\n this.homeAccountIdentifier = AccountEntity.generateHomeAccountId(serverTokenResponse.client_info || Constants.EMPTY_STRING, authority.authorityType, this.logger, this.cryptoObj, idTokenObj);\n\n // save the response tokens\n let requestStateObj: RequestStateObject | undefined;\n if (!!authCodePayload && !!authCodePayload.state) {\n requestStateObj = ProtocolUtils.parseRequestState(this.cryptoObj, authCodePayload.state);\n }\n\n // Add keyId from request to serverTokenResponse if defined\n serverTokenResponse.key_id = serverTokenResponse.key_id || request.sshKid || undefined;\n\n const cacheRecord = this.generateCacheRecord(serverTokenResponse, authority, reqTimestamp, request, idTokenObj, oboAssertion, authCodePayload);\n let cacheContext;\n try {\n if (this.persistencePlugin && this.serializableCache) {\n this.logger.verbose(\"Persistence enabled, calling beforeCacheAccess\");\n cacheContext = new TokenCacheContext(this.serializableCache, true);\n await this.persistencePlugin.beforeCacheAccess(cacheContext);\n }\n /*\n * When saving a refreshed tokens to the cache, it is expected that the account that was used is present in the cache.\n * If not present, we should return null, as it's the case that another application called removeAccount in between\n * the calls to getAllAccounts and acquireTokenSilent. We should not overwrite that removal.\n */\n if (handlingRefreshTokenResponse && cacheRecord.account) {\n const key = cacheRecord.account.generateAccountKey();\n const account = this.cacheStorage.getAccount(key);\n if (!account) {\n this.logger.warning(\"Account used to refresh tokens not in persistence, refreshed tokens will not be stored in the cache\");\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj);\n }\n }\n await this.cacheStorage.saveCacheRecord(cacheRecord);\n } finally {\n if (this.persistencePlugin && this.serializableCache && cacheContext) {\n this.logger.verbose(\"Persistence enabled, calling afterCacheAccess\");\n await this.persistencePlugin.afterCacheAccess(cacheContext);\n }\n }\n return ResponseHandler.generateAuthenticationResult(this.cryptoObj, authority, cacheRecord, false, request, idTokenObj, requestStateObj, serverTokenResponse.spa_code);\n }\n\n /**\n * Generates CacheRecord\n * @param serverTokenResponse\n * @param idTokenObj\n * @param authority\n */\n private generateCacheRecord(serverTokenResponse: ServerAuthorizationTokenResponse, authority: Authority, reqTimestamp: number, request: BaseAuthRequest, idTokenObj?: AuthToken, oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): CacheRecord {\n const env = authority.getPreferredCache();\n if (StringUtils.isEmpty(env)) {\n throw ClientAuthError.createInvalidCacheEnvironmentError();\n }\n\n // IdToken: non AAD scenarios can have empty realm\n let cachedIdToken: IdTokenEntity | undefined;\n let cachedAccount: AccountEntity | undefined;\n if (!StringUtils.isEmpty(serverTokenResponse.id_token) && !!idTokenObj) {\n cachedIdToken = IdTokenEntity.createIdTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.id_token || Constants.EMPTY_STRING,\n this.clientId,\n idTokenObj.claims.tid || Constants.EMPTY_STRING,\n oboAssertion\n );\n\n cachedAccount = this.generateAccountEntity(\n serverTokenResponse,\n idTokenObj,\n authority,\n oboAssertion,\n authCodePayload\n );\n }\n\n // AccessToken\n let cachedAccessToken: AccessTokenEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.access_token)) {\n\n // If scopes not returned in server response, use request scopes\n const responseScopes = serverTokenResponse.scope ? ScopeSet.fromString(serverTokenResponse.scope) : new ScopeSet(request.scopes || []);\n\n /*\n * Use timestamp calculated before request\n * Server may return timestamps as strings, parse to numbers if so.\n */\n const expiresIn: number = (typeof serverTokenResponse.expires_in === \"string\" ? parseInt(serverTokenResponse.expires_in, 10) : serverTokenResponse.expires_in) || 0;\n const extExpiresIn: number = (typeof serverTokenResponse.ext_expires_in === \"string\" ? parseInt(serverTokenResponse.ext_expires_in, 10) : serverTokenResponse.ext_expires_in) || 0;\n const refreshIn: number | undefined = (typeof serverTokenResponse.refresh_in === \"string\" ? parseInt(serverTokenResponse.refresh_in, 10) : serverTokenResponse.refresh_in) || undefined;\n const tokenExpirationSeconds = reqTimestamp + expiresIn;\n const extendedTokenExpirationSeconds = tokenExpirationSeconds + extExpiresIn;\n const refreshOnSeconds = refreshIn && refreshIn > 0 ? reqTimestamp + refreshIn : undefined;\n\n // non AAD scenarios can have empty realm\n cachedAccessToken = AccessTokenEntity.createAccessTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.access_token || Constants.EMPTY_STRING,\n this.clientId,\n idTokenObj ? idTokenObj.claims.tid || Constants.EMPTY_STRING : authority.tenant,\n responseScopes.printScopes(),\n tokenExpirationSeconds,\n extendedTokenExpirationSeconds,\n this.cryptoObj,\n refreshOnSeconds,\n serverTokenResponse.token_type,\n oboAssertion,\n serverTokenResponse.key_id,\n request.claims,\n request.requestedClaimsHash\n );\n }\n \n // refreshToken\n let cachedRefreshToken: RefreshTokenEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.refresh_token)) {\n cachedRefreshToken = RefreshTokenEntity.createRefreshTokenEntity(\n this.homeAccountIdentifier,\n env,\n serverTokenResponse.refresh_token || Constants.EMPTY_STRING,\n this.clientId,\n serverTokenResponse.foci,\n oboAssertion\n );\n }\n\n // appMetadata\n let cachedAppMetadata: AppMetadataEntity | null = null;\n if (!StringUtils.isEmpty(serverTokenResponse.foci)) {\n cachedAppMetadata = AppMetadataEntity.createAppMetadataEntity(this.clientId, env, serverTokenResponse.foci);\n }\n\n return new CacheRecord(cachedAccount, cachedIdToken, cachedAccessToken, cachedRefreshToken, cachedAppMetadata);\n }\n\n /**\n * Generate Account\n * @param serverTokenResponse\n * @param idToken\n * @param authority\n */\n private generateAccountEntity(serverTokenResponse: ServerAuthorizationTokenResponse, idToken: AuthToken, authority: Authority, oboAssertion?: string, authCodePayload?: AuthorizationCodePayload): AccountEntity {\n const authorityType = authority.authorityType;\n const cloudGraphHostName = authCodePayload ? authCodePayload.cloud_graph_host_name : Constants.EMPTY_STRING;\n const msGraphhost = authCodePayload ? authCodePayload.msgraph_host : Constants.EMPTY_STRING;\n\n // ADFS does not require client_info in the response\n if (authorityType === AuthorityType.Adfs) {\n this.logger.verbose(\"Authority type is ADFS, creating ADFS account\");\n return AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);\n }\n\n // This fallback applies to B2C as well as they fall under an AAD account type.\n if (StringUtils.isEmpty(serverTokenResponse.client_info) && authority.protocolMode === \"AAD\") {\n throw ClientAuthError.createClientInfoEmptyError();\n }\n\n return serverTokenResponse.client_info ?\n AccountEntity.createAccount(serverTokenResponse.client_info, this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost) :\n AccountEntity.createGenericAccount(this.homeAccountIdentifier, idToken, authority, oboAssertion, cloudGraphHostName, msGraphhost);\n }\n\n /**\n * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.\n *\n * Optionally takes a state string that is set as-is in the response.\n *\n * @param cacheRecord\n * @param idTokenObj\n * @param fromTokenCache\n * @param stateString\n */\n static async generateAuthenticationResult(\n cryptoObj: ICrypto, \n authority: Authority,\n cacheRecord: CacheRecord, \n fromTokenCache: boolean, \n request: BaseAuthRequest,\n idTokenObj?: AuthToken,\n requestState?: RequestStateObject,\n code?: string\n ): Promise<AuthenticationResult> {\n let accessToken: string = Constants.EMPTY_STRING;\n let responseScopes: Array<string> = [];\n let expiresOn: Date | null = null;\n let extExpiresOn: Date | undefined;\n let familyId: string = Constants.EMPTY_STRING;\n\n if (cacheRecord.accessToken) {\n if (cacheRecord.accessToken.tokenType === AuthenticationScheme.POP) {\n const popTokenGenerator: PopTokenGenerator = new PopTokenGenerator(cryptoObj);\n accessToken = await popTokenGenerator.signPopToken(cacheRecord.accessToken.secret, request);\n } else {\n accessToken = cacheRecord.accessToken.secret;\n }\n responseScopes = ScopeSet.fromString(cacheRecord.accessToken.target).asArray();\n expiresOn = new Date(Number(cacheRecord.accessToken.expiresOn) * 1000);\n extExpiresOn = new Date(Number(cacheRecord.accessToken.extendedExpiresOn) * 1000);\n }\n\n if (cacheRecord.appMetadata) {\n familyId = cacheRecord.appMetadata.familyId === THE_FAMILY_ID ? THE_FAMILY_ID : Constants.EMPTY_STRING;\n }\n const uid = idTokenObj?.claims.oid || idTokenObj?.claims.sub || Constants.EMPTY_STRING;\n const tid = idTokenObj?.claims.tid || Constants.EMPTY_STRING;\n\n return {\n authority: authority.canonicalAuthority,\n uniqueId: uid,\n tenantId: tid,\n scopes: responseScopes,\n account: cacheRecord.account ? cacheRecord.account.getAccountInfo() : null,\n idToken: idTokenObj ? idTokenObj.rawToken : Constants.EMPTY_STRING,\n idTokenClaims: idTokenObj ? idTokenObj.claims : {},\n accessToken: accessToken,\n fromCache: fromTokenCache,\n expiresOn: expiresOn,\n correlationId: request.correlationId,\n extExpiresOn: extExpiresOn,\n familyId: familyId,\n tokenType: cacheRecord.accessToken?.tokenType || Constants.EMPTY_STRING,\n state: requestState ? requestState.userRequestState : Constants.EMPTY_STRING,\n cloudGraphHostName: cacheRecord.account?.cloudGraphHostName || Constants.EMPTY_STRING,\n msGraphHost: cacheRecord.account?.msGraphHost || Constants.EMPTY_STRING,\n code\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAmCA;;;;IAYI,yBAAY,QAAgB,EAAE,YAA0B,EAAE,SAAkB,EAAE,MAAc,EAAE,iBAAiD,EAAE,iBAAsC;QACnL,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;KAC9C;;;;;;;IAQD,iEAAuC,GAAvC,UAAwC,kBAAmD,EAAE,WAAmB,EAAE,SAAkB;QAEhI,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE;YAC3C,MAAM,CAAC,kBAAkB,CAAC,KAAK,GAAG,eAAe,CAAC,wBAAwB,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAC;SACzJ;QAED,IAAI,kBAAkB,CAAC,kBAAkB,CAAC,KAAK,CAAC,KAAK,kBAAkB,CAAC,WAAW,CAAC,EAAE;YAClF,MAAM,eAAe,CAAC,wBAAwB,EAAE,CAAC;SACpD;;QAGD,IAAI,kBAAkB,CAAC,KAAK,IAAI,kBAAkB,CAAC,iBAAiB,IAAI,kBAA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,0CAAE,kBAAkB,KAAI,SAAS,CAAC,YAAY;gCACrF,WAAW,EAAE,OAAA,WAAW,CAAC,OAAO,0CAAE,WAAW,KAAI,SAAS,CAAC,YAAY;gCACvE,IAAI,MAAA;6BACP,EAAC;;;;KACL;IACL,sBAAC;AAAD,CAAC;;;;"}
@@ -0,0 +1,22 @@
1
+ import { PerformanceEvent, PerformanceEvents } from "./PerformanceEvent";
2
+ import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
3
+ export declare type PerformanceCallbackFunction = (events: PerformanceEvent[]) => void;
4
+ export declare type InProgressPerformanceEvent = {
5
+ endMeasurement: (event?: Partial<PerformanceEvent>) => PerformanceEvent | null;
6
+ flushMeasurement: () => void;
7
+ discardMeasurement: () => void;
8
+ event: PerformanceEvent;
9
+ measurement: IPerformanceMeasurement;
10
+ };
11
+ export interface IPerformanceClient {
12
+ startMeasurement(measureName: PerformanceEvents, correlationId?: string): InProgressPerformanceEvent;
13
+ endMeasurement(event: PerformanceEvent): PerformanceEvent | null;
14
+ flushMeasurements(measureName: PerformanceEvents, correlationId?: string): void;
15
+ discardMeasurements(correlationId: string): void;
16
+ removePerformanceCallback(callbackId: string): boolean;
17
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string;
18
+ emitEvents(events: PerformanceEvent[], correlationId: string): void;
19
+ startPerformanceMeasuremeant(measureName: string, correlationId: string): IPerformanceMeasurement;
20
+ generateId(): string;
21
+ }
22
+ //# sourceMappingURL=IPerformanceClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IPerformanceClient.d.ts","sourceRoot":"","sources":["../../../src/telemetry/performance/IPerformanceClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,oBAAY,2BAA2B,GAAG,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;AAE/E,oBAAY,0BAA0B,GAAG;IACrC,cAAc,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,gBAAgB,GAAG,IAAI,CAAA;IAC9E,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,KAAK,EAAE,gBAAgB,CAAC;IACxB,WAAW,EAAE,uBAAuB,CAAA;CACvC,CAAC;AAEF,MAAM,WAAW,kBAAkB;IAC/B,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,0BAA0B,CAAC;IACrG,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,IAAI,CAAC;IACjE,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChF,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IACvD,sBAAsB,CAAC,QAAQ,EAAE,2BAA2B,GAAG,MAAM,CAAC;IACtE,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IACpE,4BAA4B,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,uBAAuB,CAAC;IAClG,UAAU,IAAI,MAAM,CAAC;CACxB"}
@@ -0,0 +1,6 @@
1
+ export interface IPerformanceMeasurement {
2
+ startMeasurement(): void;
3
+ endMeasurement(): void;
4
+ flushMeasurement(): number | null;
5
+ }
6
+ //# sourceMappingURL=IPerformanceMeasurement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IPerformanceMeasurement.d.ts","sourceRoot":"","sources":["../../../src/telemetry/performance/IPerformanceMeasurement.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,uBAAuB;IACpC,gBAAgB,IAAI,IAAI,CAAC;IACzB,cAAc,IAAI,IAAI,CAAC;IACvB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAAC;CACrC"}
@@ -0,0 +1,125 @@
1
+ import { ApplicationTelemetry } from "../../config/ClientConfiguration";
2
+ import { Logger } from "../../logger/Logger";
3
+ import { InProgressPerformanceEvent, IPerformanceClient, PerformanceCallbackFunction } from "./IPerformanceClient";
4
+ import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
5
+ import { PerformanceEvent, PerformanceEvents } from "./PerformanceEvent";
6
+ export declare abstract class PerformanceClient implements IPerformanceClient {
7
+ protected authority: string;
8
+ protected libraryName: string;
9
+ protected libraryVersion: string;
10
+ protected applicationTelemetry: ApplicationTelemetry;
11
+ protected clientId: string;
12
+ protected logger: Logger;
13
+ protected callbacks: Map<string, PerformanceCallbackFunction>;
14
+ /**
15
+ * Multiple events with the same correlation id.
16
+ * Double keyed by correlation id and event id.
17
+ * @protected
18
+ * @type {Map<string, Map<string, PerformanceEvent>>}
19
+ */
20
+ protected eventsByCorrelationId: Map<string, Map<string, PerformanceEvent>>;
21
+ /**
22
+ * Underlying performance measurements for each operation
23
+ *
24
+ * @protected
25
+ * @type {Map<string, IPerformanceMeasurement>}
26
+ */
27
+ protected measurementsById: Map<string, IPerformanceMeasurement>;
28
+ /**
29
+ * Creates an instance of PerformanceClient,
30
+ * an abstract class containing core performance telemetry logic.
31
+ *
32
+ * @constructor
33
+ * @param {string} clientId Client ID of the application
34
+ * @param {string} authority Authority used by the application
35
+ * @param {Logger} logger Logger used by the application
36
+ * @param {string} libraryName Name of the library
37
+ * @param {string} libraryVersion Version of the library
38
+ */
39
+ constructor(clientId: string, authority: string, logger: Logger, libraryName: string, libraryVersion: string, applicationTelemetry: ApplicationTelemetry);
40
+ /**
41
+ * Starts and returns an platform-specific implementation of IPerformanceMeasurement.
42
+ *
43
+ * @abstract
44
+ * @param {string} measureName
45
+ * @param {string} correlationId
46
+ * @returns {IPerformanceMeasurement}
47
+ */
48
+ abstract startPerformanceMeasuremeant(measureName: string, correlationId: string): IPerformanceMeasurement;
49
+ /**
50
+ * Generates and returns a unique id, typically a guid.
51
+ *
52
+ * @abstract
53
+ * @returns {string}
54
+ */
55
+ abstract generateId(): string;
56
+ /**
57
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
58
+ *
59
+ * @param {PerformanceEvents} measureName
60
+ * @param {?string} [correlationId]
61
+ * @returns {InProgressPerformanceEvent}
62
+ */
63
+ startMeasurement(measureName: PerformanceEvents, correlationId?: string): InProgressPerformanceEvent;
64
+ /**
65
+ * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
66
+ * as consumers should instead use the function returned by startMeasurement.
67
+ *
68
+ * @param {PerformanceEvent} event
69
+ * @returns {(PerformanceEvent | null)}
70
+ */
71
+ endMeasurement(event: PerformanceEvent): PerformanceEvent | null;
72
+ /**
73
+ * Upserts event into event cache.
74
+ * First key is the correlation id, second key is the event id.
75
+ * Allows for events to be grouped by correlation id,
76
+ * and to easily allow for properties on them to be updated.
77
+ *
78
+ * @private
79
+ * @param {PerformanceEvent} event
80
+ */
81
+ private cacheEventByCorrelationId;
82
+ /**
83
+ * Cache measurements by their id.
84
+ *
85
+ * @private
86
+ * @param {PerformanceEvent} event
87
+ * @param {IPerformanceMeasurement} measurement
88
+ */
89
+ private cacheMeasurement;
90
+ /**
91
+ * Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
92
+ *
93
+ * @param {PerformanceEvents} measureName
94
+ * @param {string} correlationId
95
+ */
96
+ flushMeasurements(measureName: PerformanceEvents, correlationId: string): void;
97
+ /**
98
+ * Removes measurements for a given correlation id.
99
+ *
100
+ * @param {string} correlationId
101
+ */
102
+ discardMeasurements(correlationId: string): void;
103
+ /**
104
+ * Registers a callback function to receive performance events.
105
+ *
106
+ * @param {PerformanceCallbackFunction} callback
107
+ * @returns {string}
108
+ */
109
+ addPerformanceCallback(callback: PerformanceCallbackFunction): string;
110
+ /**
111
+ * Removes a callback registered with addPerformanceCallback.
112
+ *
113
+ * @param {string} callbackId
114
+ * @returns {boolean}
115
+ */
116
+ removePerformanceCallback(callbackId: string): boolean;
117
+ /**
118
+ * Emits events to all registered callbacks.
119
+ *
120
+ * @param {PerformanceEvent[]} events
121
+ * @param {?string} [correlationId]
122
+ */
123
+ emitEvents(events: PerformanceEvent[], correlationId: string): void;
124
+ }
125
+ //# sourceMappingURL=PerformanceClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PerformanceClient.d.ts","sourceRoot":"","sources":["../../../src/telemetry/performance/PerformanceClient.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAA0B,MAAM,oBAAoB,CAAC;AAEjG,8BAAsB,iBAAkB,YAAW,kBAAkB;IACjE,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;IACrD,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IAE9D;;;;;OAKG;IACH,SAAS,CAAC,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAE5E;;;;;OAK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formanceEvent.js';
5
+
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ var PerformanceClient = /** @class */ (function () {
11
+ /**
12
+ * Creates an instance of PerformanceClient,
13
+ * an abstract class containing core performance telemetry logic.
14
+ *
15
+ * @constructor
16
+ * @param {string} clientId Client ID of the application
17
+ * @param {string} authority Authority used by the application
18
+ * @param {Logger} logger Logger used by the application
19
+ * @param {string} libraryName Name of the library
20
+ * @param {string} libraryVersion Version of the library
21
+ */
22
+ function PerformanceClient(clientId, authority, logger, libraryName, libraryVersion, applicationTelemetry) {
23
+ this.authority = authority;
24
+ this.libraryName = libraryName;
25
+ this.libraryVersion = libraryVersion;
26
+ this.applicationTelemetry = applicationTelemetry;
27
+ this.clientId = clientId;
28
+ this.logger = logger;
29
+ this.callbacks = new Map();
30
+ this.eventsByCorrelationId = new Map();
31
+ this.measurementsById = new Map();
32
+ }
33
+ /**
34
+ * Starts measuring performance for a given operation. Returns a function that should be used to end the measurement.
35
+ *
36
+ * @param {PerformanceEvents} measureName
37
+ * @param {?string} [correlationId]
38
+ * @returns {InProgressPerformanceEvent}
39
+ */
40
+ PerformanceClient.prototype.startMeasurement = function (measureName, correlationId) {
41
+ var _this = this;
42
+ var _a, _b;
43
+ // Generate a placeholder correlation if the request does not provide one
44
+ var eventCorrelationId = correlationId || this.generateId();
45
+ if (!correlationId) {
46
+ this.logger.info("PerformanceClient: No correlation id provided for " + measureName + ", generating", eventCorrelationId);
47
+ }
48
+ this.logger.trace("PerformanceClient: Performance measurement started for " + measureName, eventCorrelationId);
49
+ var performanceMeasurement = this.startPerformanceMeasuremeant(measureName, eventCorrelationId);
50
+ performanceMeasurement.startMeasurement();
51
+ var inProgressEvent = {
52
+ eventId: this.generateId(),
53
+ status: PerformanceEventStatus.InProgress,
54
+ authority: this.authority,
55
+ libraryName: this.libraryName,
56
+ libraryVersion: this.libraryVersion,
57
+ appName: (_a = this.applicationTelemetry) === null || _a === void 0 ? void 0 : _a.appName,
58
+ appVersion: (_b = this.applicationTelemetry) === null || _b === void 0 ? void 0 : _b.appVersion,
59
+ clientId: this.clientId,
60
+ name: measureName,
61
+ startTimeMs: Date.now(),
62
+ correlationId: eventCorrelationId
63
+ };
64
+ // Store in progress events so they can be discarded if not ended properly
65
+ this.cacheEventByCorrelationId(inProgressEvent);
66
+ this.cacheMeasurement(inProgressEvent, performanceMeasurement);
67
+ // Return the event and functions the caller can use to properly end/flush the measurement
68
+ return {
69
+ endMeasurement: function (event) {
70
+ var completedEvent = _this.endMeasurement(__assign(__assign({}, inProgressEvent), event));
71
+ if (completedEvent) {
72
+ // Cache event so that submeasurements can be added downstream
73
+ _this.cacheEventByCorrelationId(completedEvent);
74
+ }
75
+ return completedEvent;
76
+ },
77
+ flushMeasurement: function () {
78
+ return _this.flushMeasurements(inProgressEvent.name, inProgressEvent.correlationId);
79
+ },
80
+ discardMeasurement: function () {
81
+ return _this.discardMeasurements(inProgressEvent.correlationId);
82
+ },
83
+ measurement: performanceMeasurement,
84
+ event: inProgressEvent
85
+ };
86
+ };
87
+ /**
88
+ * Stops measuring the performance for an operation. Should only be called directly by PerformanceClient classes,
89
+ * as consumers should instead use the function returned by startMeasurement.
90
+ *
91
+ * @param {PerformanceEvent} event
92
+ * @returns {(PerformanceEvent | null)}
93
+ */
94
+ PerformanceClient.prototype.endMeasurement = function (event) {
95
+ var performanceMeasurement = this.measurementsById.get(event.eventId);
96
+ if (performanceMeasurement) {
97
+ // Immediately delete so that the same event isnt ended twice
98
+ this.measurementsById.delete(event.eventId);
99
+ performanceMeasurement.endMeasurement();
100
+ var durationMs = performanceMeasurement.flushMeasurement();
101
+ // null indicates no measurement was taken (e.g. needed performance APIs not present)
102
+ if (durationMs !== null) {
103
+ this.logger.trace("PerformanceClient: Performance measurement ended for " + event.name + ": " + durationMs + " ms", event.correlationId);
104
+ var completedEvent = __assign(__assign({
105
+ // Allow duration to be overwritten when event ends (e.g. testing), but not status
106
+ durationMs: Math.round(durationMs) }, event), { status: PerformanceEventStatus.Completed });
107
+ return completedEvent;
108
+ }
109
+ else {
110
+ this.logger.trace("PerformanceClient: Performance measurement not taken", event.correlationId);
111
+ }
112
+ }
113
+ else {
114
+ this.logger.trace("PerformanceClient: Measurement not found for " + event.eventId, event.correlationId);
115
+ }
116
+ return null;
117
+ };
118
+ /**
119
+ * Upserts event into event cache.
120
+ * First key is the correlation id, second key is the event id.
121
+ * Allows for events to be grouped by correlation id,
122
+ * and to easily allow for properties on them to be updated.
123
+ *
124
+ * @private
125
+ * @param {PerformanceEvent} event
126
+ */
127
+ PerformanceClient.prototype.cacheEventByCorrelationId = function (event) {
128
+ var existingEvents = this.eventsByCorrelationId.get(event.correlationId);
129
+ if (existingEvents) {
130
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " added/updated", event.correlationId);
131
+ existingEvents.set(event.eventId, event);
132
+ }
133
+ else {
134
+ this.logger.trace("PerformanceClient: Performance measurement for " + event.name + " started", event.correlationId);
135
+ this.eventsByCorrelationId.set(event.correlationId, new Map().set(event.eventId, event));
136
+ }
137
+ };
138
+ /**
139
+ * Cache measurements by their id.
140
+ *
141
+ * @private
142
+ * @param {PerformanceEvent} event
143
+ * @param {IPerformanceMeasurement} measurement
144
+ */
145
+ PerformanceClient.prototype.cacheMeasurement = function (event, measurement) {
146
+ this.measurementsById.set(event.eventId, measurement);
147
+ };
148
+ /**
149
+ * Gathers and emits performance events for measurements taked for the given top-level API and correlation ID.
150
+ *
151
+ * @param {PerformanceEvents} measureName
152
+ * @param {string} correlationId
153
+ */
154
+ PerformanceClient.prototype.flushMeasurements = function (measureName, correlationId) {
155
+ var _this = this;
156
+ this.logger.trace("PerformanceClient: Performance measurements flushed for " + measureName, correlationId);
157
+ var eventsForCorrelationId = this.eventsByCorrelationId.get(correlationId);
158
+ if (eventsForCorrelationId) {
159
+ this.discardMeasurements(correlationId);
160
+ /*
161
+ * Manually end incomplete submeasurements to ensure there arent orphaned/never ending events.
162
+ * Incomplete submeasurements are likely an instrumentation bug that should be fixed.
163
+ * IE only supports Map.forEach.
164
+ */
165
+ var completedEvents_1 = [];
166
+ eventsForCorrelationId.forEach(function (event) {
167
+ if (event.name !== measureName && event.status !== PerformanceEventStatus.Completed) {
168
+ _this.logger.trace("PerformanceClient: Incomplete submeasurement " + event.name + " found for " + measureName, correlationId);
169
+ var completedEvent = _this.endMeasurement(event);
170
+ if (completedEvent) {
171
+ completedEvents_1.push(completedEvent);
172
+ }
173
+ }
174
+ completedEvents_1.push(event);
175
+ });
176
+ // Sort events by start time (earliest first)
177
+ var sortedCompletedEvents = completedEvents_1.sort(function (eventA, eventB) { return eventA.startTimeMs - eventB.startTimeMs; });
178
+ // Take completed top level event and add completed submeasurements durations as properties
179
+ var topLevelEvents = sortedCompletedEvents.filter(function (event) { return event.name === measureName && event.status === PerformanceEventStatus.Completed; });
180
+ if (topLevelEvents.length > 0) {
181
+ /*
182
+ * Only take the first top-level event if there are multiple events with the same correlation id.
183
+ * This greatly simplifies logic for submeasurements.
184
+ */
185
+ if (topLevelEvents.length > 1) {
186
+ this.logger.verbose("PerformanceClient: Multiple distinct top-level performance events found, using the first", correlationId);
187
+ }
188
+ var topLevelEvent = topLevelEvents[0];
189
+ this.logger.verbose("PerformanceClient: Measurement found for " + measureName, correlationId);
190
+ // Build event object with top level and sub measurements
191
+ var eventToEmit = sortedCompletedEvents.reduce(function (previous, current) {
192
+ if (current.name !== measureName) {
193
+ _this.logger.trace("PerformanceClient: Complete submeasurement found for " + current.name, correlationId);
194
+ // TODO: Emit additional properties for each subMeasurement
195
+ var subMeasurementName = current.name + "DurationMs";
196
+ /*
197
+ * Some code paths, such as resolving an authority, can occur multiple times.
198
+ * Only take the first measurement, since the second could be read from the cache,
199
+ * or due to the same correlation id being used for two distinct requests.
200
+ */
201
+ if (!previous[subMeasurementName]) {
202
+ previous[subMeasurementName] = current.durationMs;
203
+ }
204
+ else {
205
+ _this.logger.verbose("PerformanceClient: Submeasurement for " + measureName + " already exists for " + current.name + ", ignoring", correlationId);
206
+ }
207
+ }
208
+ return previous;
209
+ }, topLevelEvent);
210
+ this.emitEvents([eventToEmit], eventToEmit.correlationId);
211
+ }
212
+ else {
213
+ this.logger.verbose("PerformanceClient: No completed top-level measurements found for " + measureName, correlationId);
214
+ }
215
+ }
216
+ else {
217
+ this.logger.verbose("PerformanceClient: No measurements found", correlationId);
218
+ }
219
+ };
220
+ /**
221
+ * Removes measurements for a given correlation id.
222
+ *
223
+ * @param {string} correlationId
224
+ */
225
+ PerformanceClient.prototype.discardMeasurements = function (correlationId) {
226
+ this.logger.trace("PerformanceClient: Performance measurements discarded", correlationId);
227
+ this.eventsByCorrelationId.delete(correlationId);
228
+ };
229
+ /**
230
+ * Registers a callback function to receive performance events.
231
+ *
232
+ * @param {PerformanceCallbackFunction} callback
233
+ * @returns {string}
234
+ */
235
+ PerformanceClient.prototype.addPerformanceCallback = function (callback) {
236
+ var callbackId = this.generateId();
237
+ this.callbacks.set(callbackId, callback);
238
+ this.logger.verbose("PerformanceClient: Performance callback registered with id: " + callbackId);
239
+ return callbackId;
240
+ };
241
+ /**
242
+ * Removes a callback registered with addPerformanceCallback.
243
+ *
244
+ * @param {string} callbackId
245
+ * @returns {boolean}
246
+ */
247
+ PerformanceClient.prototype.removePerformanceCallback = function (callbackId) {
248
+ var result = this.callbacks.delete(callbackId);
249
+ if (result) {
250
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " removed.");
251
+ }
252
+ else {
253
+ this.logger.verbose("PerformanceClient: Performance callback " + callbackId + " not removed.");
254
+ }
255
+ return result;
256
+ };
257
+ /**
258
+ * Emits events to all registered callbacks.
259
+ *
260
+ * @param {PerformanceEvent[]} events
261
+ * @param {?string} [correlationId]
262
+ */
263
+ PerformanceClient.prototype.emitEvents = function (events, correlationId) {
264
+ var _this = this;
265
+ this.logger.verbose("PerformanceClient: Emitting performance events", correlationId);
266
+ this.callbacks.forEach(function (callback, callbackId) {
267
+ _this.logger.trace("PerformanceClient: Emitting event to callback " + callbackId, correlationId);
268
+ callback.apply(null, [events]);
269
+ });
270
+ };
271
+ return PerformanceClient;
272
+ }());
273
+
274
+ export { PerformanceClient };
275
+ //# sourceMappingURL=PerformanceClient.js.map