text: /**
   * PropertiesPlugin.ts
   * @copyright Microsoft 2018
   */
  import { CoreUtils } from '@microsoft/applicationinsights-core-js';
  import { TelemetryContext } from './TelemetryContext';
  import { PageView, ConfigurationManager, PropertiesPluginIdentifier, Extensions } from '@microsoft/applicationinsights-common';
  var PropertiesPlugin = /** @class */ (function () {
      function PropertiesPlugin() {
          this.priority = 170;
          this.identifier = PropertiesPluginIdentifier;
      }
      PropertiesPlugin.getDefaultConfig = function () {
          var defaultConfig = {
              instrumentationKey: function () { return undefined; },
              accountId: function () { return null; },
              sessionRenewalMs: function () { return 30 * 60 * 1000; },
              samplingPercentage: function () { return 100; },
              sessionExpirationMs: function () { return 24 * 60 * 60 * 1000; },
              cookieDomain: function () { return null; },
              sdkExtension: function () { return null; },
              isBrowserLinkTrackingEnabled: function () { return false; },
              appId: function () { return null; },
              namePrefix: function () { return undefined; }
          };
          return defaultConfig;
      };
      PropertiesPlugin.prototype.initialize = function (config, core, extensions) {
          var _this = this;
          var defaultConfig = PropertiesPlugin.getDefaultConfig();
          this._extensionConfig = this._extensionConfig || PropertiesPlugin.getDefaultConfig();
          var _loop_1 = function (field) {
              this_1._extensionConfig[field] = function () { return ConfigurationManager.getConfig(config, field, _this.identifier, defaultConfig[field]()); };
          };
          var this_1 = this;
          for (var field in defaultConfig) {
              _loop_1(field);
          }
          this._logger = core.logger;
          this.context = new TelemetryContext(core.logger, this._extensionConfig);
      };
      /**
       * Add Part A fields to the event
       * @param event The event that needs to be processed
       */
      PropertiesPlugin.prototype.processTelemetry = function (event) {
          if (CoreUtils.isNullOrUndefined(event)) {
              // TODO(barustum): throw an internal event once we have support for internal logging
          }
          else {
              // if the event is not sampled in, do not bother going through the pipeline
              if (this.context.sample.isSampledIn(event)) {
                  // If the envelope is PageView, reset the internal message count so that we can send internal telemetry for the new page.
                  if (event.name === PageView.envelopeType) {
                      this._logger.resetInternalMessageCount();
                  }
                  if (this.context.session) {
                      // If customer did not provide custom session id update the session manager
                      if (typeof this.context.session.id !== "string") {
                          this.context.sessionManager.update();
                      }
                  }
                  this._processTelemetryInternal(event);
              }
              if (!CoreUtils.isNullOrUndefined(this._nextPlugin)) {
                  this._nextPlugin.processTelemetry(event);
              }
          }
      };
      /**
       * Sets the next plugin that comes after this plugin
       * @param nextPlugin The next plugin
       */
      PropertiesPlugin.prototype.setNextPlugin = function (nextPlugin) {
          this._nextPlugin = nextPlugin;
      };
      PropertiesPlugin.prototype._processTelemetryInternal = function (event) {
          // set part A  fields
          if (!event.tags) {
              event.tags = [];
          }
          if (!event.ext) {
              event.ext = {};
          }
          event.ext[Extensions.DeviceExt] = event.ext[Extensions.DeviceExt] || {};
          event.ext[Extensions.WebExt] = event.ext[Extensions.WebExt] || {};
          event.ext[Extensions.UserExt] = event.ext[Extensions.UserExt] || {};
          event.ext[Extensions.OSExt] = event.ext[Extensions.OSExt] || {};
          event.ext[Extensions.AppExt] = event.ext[Extensions.AppExt] || {};
          event.ext[Extensions.TraceExt] = event.ext[Extensions.TraceExt] || {};
          this.context.applySessionContext(event);
          this.context.applyApplicationContext(event);
          this.context.applyDeviceContext(event);
          this.context.applyOperationContext(event);
          this.context.applyUserContext(event);
          this.context.applyOperatingSystemContxt(event);
          this.context.applyWebContext(event);
          this.context.applyLocationContext(event); // legacy tags
          this.context.applySampleContext(event); // legacy tags
          this.context.applyInternalContext(event); // legacy tags
          this.context.cleanUp(event);
      };
      return PropertiesPlugin;
  }());
  export default PropertiesPlugin;
  //# sourceMappingURL=PropertiesPlugin.js.map