@firebase/performance 0.5.17-canary.37dd6f6f4 → 0.5.17-canary.3bd031691

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.
@@ -6,7 +6,7 @@ import { Component } from '@firebase/component';
6
6
  import '@firebase/installations';
7
7
 
8
8
  var name = "@firebase/performance";
9
- var version = "0.5.17-canary.37dd6f6f4";
9
+ var version = "0.5.17-canary.3bd031691";
10
10
 
11
11
  /**
12
12
  * @license
@@ -59,22 +59,22 @@ var SERVICE_NAME = 'Performance';
59
59
  */
60
60
  var _a;
61
61
  var ERROR_DESCRIPTION_MAP = (_a = {},
62
- _a["trace started" /* TRACE_STARTED_BEFORE */] = 'Trace {$traceName} was started before.',
63
- _a["trace stopped" /* TRACE_STOPPED_BEFORE */] = 'Trace {$traceName} is not running.',
64
- _a["nonpositive trace startTime" /* NONPOSITIVE_TRACE_START_TIME */] = 'Trace {$traceName} startTime should be positive.',
65
- _a["nonpositive trace duration" /* NONPOSITIVE_TRACE_DURATION */] = 'Trace {$traceName} duration should be positive.',
66
- _a["no window" /* NO_WINDOW */] = 'Window is not available.',
67
- _a["no app id" /* NO_APP_ID */] = 'App id is not available.',
68
- _a["no project id" /* NO_PROJECT_ID */] = 'Project id is not available.',
69
- _a["no api key" /* NO_API_KEY */] = 'Api key is not available.',
70
- _a["invalid cc log" /* INVALID_CC_LOG */] = 'Attempted to queue invalid cc event',
71
- _a["FB not default" /* FB_NOT_DEFAULT */] = 'Performance can only start when Firebase app instance is the default one.',
72
- _a["RC response not ok" /* RC_NOT_OK */] = 'RC response is not ok',
73
- _a["invalid attribute name" /* INVALID_ATTRIBUTE_NAME */] = 'Attribute name {$attributeName} is invalid.',
74
- _a["invalid attribute value" /* INVALID_ATTRIBUTE_VALUE */] = 'Attribute value {$attributeValue} is invalid.',
75
- _a["invalid custom metric name" /* INVALID_CUSTOM_METRIC_NAME */] = 'Custom metric name {$customMetricName} is invalid',
76
- _a["invalid String merger input" /* INVALID_STRING_MERGER_PARAMETER */] = 'Input for String merger is invalid, contact support team to resolve.',
77
- _a["already initialized" /* ALREADY_INITIALIZED */] = 'initializePerformance() has already been called with ' +
62
+ _a["trace started" /* ErrorCode.TRACE_STARTED_BEFORE */] = 'Trace {$traceName} was started before.',
63
+ _a["trace stopped" /* ErrorCode.TRACE_STOPPED_BEFORE */] = 'Trace {$traceName} is not running.',
64
+ _a["nonpositive trace startTime" /* ErrorCode.NONPOSITIVE_TRACE_START_TIME */] = 'Trace {$traceName} startTime should be positive.',
65
+ _a["nonpositive trace duration" /* ErrorCode.NONPOSITIVE_TRACE_DURATION */] = 'Trace {$traceName} duration should be positive.',
66
+ _a["no window" /* ErrorCode.NO_WINDOW */] = 'Window is not available.',
67
+ _a["no app id" /* ErrorCode.NO_APP_ID */] = 'App id is not available.',
68
+ _a["no project id" /* ErrorCode.NO_PROJECT_ID */] = 'Project id is not available.',
69
+ _a["no api key" /* ErrorCode.NO_API_KEY */] = 'Api key is not available.',
70
+ _a["invalid cc log" /* ErrorCode.INVALID_CC_LOG */] = 'Attempted to queue invalid cc event',
71
+ _a["FB not default" /* ErrorCode.FB_NOT_DEFAULT */] = 'Performance can only start when Firebase app instance is the default one.',
72
+ _a["RC response not ok" /* ErrorCode.RC_NOT_OK */] = 'RC response is not ok',
73
+ _a["invalid attribute name" /* ErrorCode.INVALID_ATTRIBUTE_NAME */] = 'Attribute name {$attributeName} is invalid.',
74
+ _a["invalid attribute value" /* ErrorCode.INVALID_ATTRIBUTE_VALUE */] = 'Attribute value {$attributeValue} is invalid.',
75
+ _a["invalid custom metric name" /* ErrorCode.INVALID_CUSTOM_METRIC_NAME */] = 'Custom metric name {$customMetricName} is invalid',
76
+ _a["invalid String merger input" /* ErrorCode.INVALID_STRING_MERGER_PARAMETER */] = 'Input for String merger is invalid, contact support team to resolve.',
77
+ _a["already initialized" /* ErrorCode.ALREADY_INITIALIZED */] = 'initializePerformance() has already been called with ' +
78
78
  'different options. To avoid this error, call initializePerformance() with the ' +
79
79
  'same options as when it was originally called, or call getPerformance() to return the' +
80
80
  ' already initialized instance.',
@@ -126,7 +126,7 @@ var Api = /** @class */ (function () {
126
126
  function Api(window) {
127
127
  this.window = window;
128
128
  if (!window) {
129
- throw ERROR_FACTORY.create("no window" /* NO_WINDOW */);
129
+ throw ERROR_FACTORY.create("no window" /* ErrorCode.NO_WINDOW */);
130
130
  }
131
131
  this.performance = window.performance;
132
132
  this.PerformanceObserver = window.PerformanceObserver;
@@ -268,7 +268,7 @@ function getAuthTokenPromise(installationsService) {
268
268
  function mergeStrings(part1, part2) {
269
269
  var sizeDiff = part1.length - part2.length;
270
270
  if (sizeDiff < 0 || sizeDiff > 1) {
271
- throw ERROR_FACTORY.create("invalid String merger input" /* INVALID_STRING_MERGER_PARAMETER */);
271
+ throw ERROR_FACTORY.create("invalid String merger input" /* ErrorCode.INVALID_STRING_MERGER_PARAMETER */);
272
272
  }
273
273
  var resultArray = [];
274
274
  for (var i = 0; i < part1.length; i++) {
@@ -364,14 +364,14 @@ function getServiceWorkerStatus() {
364
364
  var navigator = Api.getInstance().navigator;
365
365
  if (navigator === null || navigator === void 0 ? void 0 : navigator.serviceWorker) {
366
366
  if (navigator.serviceWorker.controller) {
367
- return 2 /* CONTROLLED */;
367
+ return 2 /* ServiceWorkerStatus.CONTROLLED */;
368
368
  }
369
369
  else {
370
- return 3 /* UNCONTROLLED */;
370
+ return 3 /* ServiceWorkerStatus.UNCONTROLLED */;
371
371
  }
372
372
  }
373
373
  else {
374
- return 1 /* UNSUPPORTED */;
374
+ return 1 /* ServiceWorkerStatus.UNSUPPORTED */;
375
375
  }
376
376
  }
377
377
  function getVisibilityState() {
@@ -392,15 +392,15 @@ function getEffectiveConnectionType() {
392
392
  var effectiveType = navigatorConnection && navigatorConnection.effectiveType;
393
393
  switch (effectiveType) {
394
394
  case 'slow-2g':
395
- return 1 /* CONNECTION_SLOW_2G */;
395
+ return 1 /* EffectiveConnectionType.CONNECTION_SLOW_2G */;
396
396
  case '2g':
397
- return 2 /* CONNECTION_2G */;
397
+ return 2 /* EffectiveConnectionType.CONNECTION_2G */;
398
398
  case '3g':
399
- return 3 /* CONNECTION_3G */;
399
+ return 3 /* EffectiveConnectionType.CONNECTION_3G */;
400
400
  case '4g':
401
- return 4 /* CONNECTION_4G */;
401
+ return 4 /* EffectiveConnectionType.CONNECTION_4G */;
402
402
  default:
403
- return 0 /* UNKNOWN */;
403
+ return 0 /* EffectiveConnectionType.UNKNOWN */;
404
404
  }
405
405
  }
406
406
  function isValidCustomAttributeName(name) {
@@ -436,7 +436,7 @@ function getAppId(firebaseApp) {
436
436
  var _a;
437
437
  var appId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.appId;
438
438
  if (!appId) {
439
- throw ERROR_FACTORY.create("no app id" /* NO_APP_ID */);
439
+ throw ERROR_FACTORY.create("no app id" /* ErrorCode.NO_APP_ID */);
440
440
  }
441
441
  return appId;
442
442
  }
@@ -444,7 +444,7 @@ function getProjectId(firebaseApp) {
444
444
  var _a;
445
445
  var projectId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.projectId;
446
446
  if (!projectId) {
447
- throw ERROR_FACTORY.create("no project id" /* NO_PROJECT_ID */);
447
+ throw ERROR_FACTORY.create("no project id" /* ErrorCode.NO_PROJECT_ID */);
448
448
  }
449
449
  return projectId;
450
450
  }
@@ -452,7 +452,7 @@ function getApiKey(firebaseApp) {
452
452
  var _a;
453
453
  var apiKey = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.apiKey;
454
454
  if (!apiKey) {
455
- throw ERROR_FACTORY.create("no api key" /* NO_API_KEY */);
455
+ throw ERROR_FACTORY.create("no api key" /* ErrorCode.NO_API_KEY */);
456
456
  }
457
457
  return apiKey;
458
458
  }
@@ -529,10 +529,10 @@ function getRemoteConfig(performanceController, iid) {
529
529
  .then(function (authToken) {
530
530
  var projectId = getProjectId(performanceController.app);
531
531
  var apiKey = getApiKey(performanceController.app);
532
- var configEndPoint = "https://firebaseremoteconfig.googleapis.com/v1/projects/" + projectId + "/namespaces/fireperf:fetch?key=" + apiKey;
532
+ var configEndPoint = "https://firebaseremoteconfig.googleapis.com/v1/projects/".concat(projectId, "/namespaces/fireperf:fetch?key=").concat(apiKey);
533
533
  var request = new Request(configEndPoint, {
534
534
  method: 'POST',
535
- headers: { Authorization: FIS_AUTH_PREFIX + " " + authToken },
535
+ headers: { Authorization: "".concat(FIS_AUTH_PREFIX, " ").concat(authToken) },
536
536
  /* eslint-disable camelcase */
537
537
  body: JSON.stringify({
538
538
  app_instance_id: iid,
@@ -548,7 +548,7 @@ function getRemoteConfig(performanceController, iid) {
548
548
  return response.json();
549
549
  }
550
550
  // In case response is not ok. This will be caught by catch.
551
- throw ERROR_FACTORY.create("RC response not ok" /* RC_NOT_OK */);
551
+ throw ERROR_FACTORY.create("RC response not ok" /* ErrorCode.RC_NOT_OK */);
552
552
  });
553
553
  })
554
554
  .catch(function () {
@@ -639,16 +639,16 @@ function shouldLogAfterSampling(samplingRate) {
639
639
  * See the License for the specific language governing permissions and
640
640
  * limitations under the License.
641
641
  */
642
- var initializationStatus = 1 /* notInitialized */;
642
+ var initializationStatus = 1 /* InitializationStatus.notInitialized */;
643
643
  var initializationPromise;
644
644
  function getInitializationPromise(performanceController) {
645
- initializationStatus = 2 /* initializationPending */;
645
+ initializationStatus = 2 /* InitializationStatus.initializationPending */;
646
646
  initializationPromise =
647
647
  initializationPromise || initializePerf(performanceController);
648
648
  return initializationPromise;
649
649
  }
650
650
  function isPerfInitialized() {
651
- return initializationStatus === 3 /* initialized */;
651
+ return initializationStatus === 3 /* InitializationStatus.initialized */;
652
652
  }
653
653
  function initializePerf(performanceController) {
654
654
  return getDocumentReadyComplete()
@@ -678,7 +678,7 @@ function getDocumentReadyComplete() {
678
678
  });
679
679
  }
680
680
  function changeInitializationStatus() {
681
- initializationStatus = 3 /* initialized */;
681
+ initializationStatus = 3 /* InitializationStatus.initialized */;
682
682
  }
683
683
 
684
684
  /**
@@ -749,9 +749,9 @@ function dispatchQueueEvents() {
749
749
  sendEventsToFl(data, staged).catch(function () {
750
750
  // If the request fails for some reason, add the events that were attempted
751
751
  // back to the primary queue to retry later.
752
- queue = __spreadArray(__spreadArray([], staged), queue);
752
+ queue = __spreadArray(__spreadArray([], staged, true), queue, true);
753
753
  remainingTries--;
754
- consoleLogger.info("Tries left: " + remainingTries + ".");
754
+ consoleLogger.info("Tries left: ".concat(remainingTries, "."));
755
755
  processQueue(DEFAULT_SEND_INTERVAL_MS);
756
756
  });
757
757
  }
@@ -776,7 +776,7 @@ function sendEventsToFl(data, staged) {
776
776
  if (Array.isArray(logResponseDetails) &&
777
777
  logResponseDetails.length > 0 &&
778
778
  logResponseDetails[0].responseAction === 'RETRY_REQUEST_LATER') {
779
- queue = __spreadArray(__spreadArray([], staged), queue);
779
+ queue = __spreadArray(__spreadArray([], staged, true), queue, true);
780
780
  consoleLogger.info("Retry transport request later.");
781
781
  }
782
782
  remainingTries = DEFAULT_REMAINING_TRIES;
@@ -793,10 +793,10 @@ function postToFlEndpoint(data) {
793
793
  }
794
794
  function addToQueue(evt) {
795
795
  if (!evt.eventTime || !evt.message) {
796
- throw ERROR_FACTORY.create("invalid cc log" /* INVALID_CC_LOG */);
796
+ throw ERROR_FACTORY.create("invalid cc log" /* ErrorCode.INVALID_CC_LOG */);
797
797
  }
798
798
  // Add the new event to the queue.
799
- queue = __spreadArray(__spreadArray([], queue), [evt]);
799
+ queue = __spreadArray(__spreadArray([], queue, true), [evt], false);
800
800
  }
801
801
  /** Log handler for cc service to send the performance logs to the server. */
802
802
  function transportHandler(
@@ -876,7 +876,7 @@ function sendTraceLog(trace) {
876
876
  !settingsService.logTraceAfterSampling) {
877
877
  return;
878
878
  }
879
- setTimeout(function () { return sendLog(trace, 1 /* Trace */); }, 0);
879
+ setTimeout(function () { return sendLog(trace, 1 /* ResourceType.Trace */); }, 0);
880
880
  }
881
881
  function logNetworkRequest(networkRequest) {
882
882
  var settingsService = SettingsService.getInstance();
@@ -899,10 +899,10 @@ function logNetworkRequest(networkRequest) {
899
899
  !settingsService.logNetworkAfterSampling) {
900
900
  return;
901
901
  }
902
- setTimeout(function () { return sendLog(networkRequest, 0 /* NetworkRequest */); }, 0);
902
+ setTimeout(function () { return sendLog(networkRequest, 0 /* ResourceType.NetworkRequest */); }, 0);
903
903
  }
904
904
  function serializer(resource, resourceType) {
905
- if (resourceType === 0 /* NetworkRequest */) {
905
+ if (resourceType === 0 /* ResourceType.NetworkRequest */) {
906
906
  return serializeNetworkRequest(resource);
907
907
  }
908
908
  return serializeTrace(resource);
@@ -1003,7 +1003,7 @@ function isValidMetricName(name, traceName) {
1003
1003
  function convertMetricValueToInteger(providedValue) {
1004
1004
  var valueAsInteger = Math.floor(providedValue);
1005
1005
  if (valueAsInteger < providedValue) {
1006
- consoleLogger.info("Metric value should be an Integer, setting the value as : " + valueAsInteger + ".");
1006
+ consoleLogger.info("Metric value should be an Integer, setting the value as : ".concat(valueAsInteger, "."));
1007
1007
  }
1008
1008
  return valueAsInteger;
1009
1009
  }
@@ -1038,17 +1038,17 @@ var Trace = /** @class */ (function () {
1038
1038
  this.performanceController = performanceController;
1039
1039
  this.name = name;
1040
1040
  this.isAuto = isAuto;
1041
- this.state = 1 /* UNINITIALIZED */;
1041
+ this.state = 1 /* TraceState.UNINITIALIZED */;
1042
1042
  this.customAttributes = {};
1043
1043
  this.counters = {};
1044
1044
  this.api = Api.getInstance();
1045
1045
  this.randomId = Math.floor(Math.random() * 1000000);
1046
1046
  if (!this.isAuto) {
1047
- this.traceStartMark = TRACE_START_MARK_PREFIX + "-" + this.randomId + "-" + this.name;
1048
- this.traceStopMark = TRACE_STOP_MARK_PREFIX + "-" + this.randomId + "-" + this.name;
1047
+ this.traceStartMark = "".concat(TRACE_START_MARK_PREFIX, "-").concat(this.randomId, "-").concat(this.name);
1048
+ this.traceStopMark = "".concat(TRACE_STOP_MARK_PREFIX, "-").concat(this.randomId, "-").concat(this.name);
1049
1049
  this.traceMeasure =
1050
1050
  traceMeasureName ||
1051
- TRACE_MEASURE_PREFIX + "-" + this.randomId + "-" + this.name;
1051
+ "".concat(TRACE_MEASURE_PREFIX, "-").concat(this.randomId, "-").concat(this.name);
1052
1052
  if (traceMeasureName) {
1053
1053
  // For the case of direct user timing traces, no start stop will happen. The measure object
1054
1054
  // is already available.
@@ -1060,25 +1060,25 @@ var Trace = /** @class */ (function () {
1060
1060
  * Starts a trace. The measurement of the duration starts at this point.
1061
1061
  */
1062
1062
  Trace.prototype.start = function () {
1063
- if (this.state !== 1 /* UNINITIALIZED */) {
1064
- throw ERROR_FACTORY.create("trace started" /* TRACE_STARTED_BEFORE */, {
1063
+ if (this.state !== 1 /* TraceState.UNINITIALIZED */) {
1064
+ throw ERROR_FACTORY.create("trace started" /* ErrorCode.TRACE_STARTED_BEFORE */, {
1065
1065
  traceName: this.name
1066
1066
  });
1067
1067
  }
1068
1068
  this.api.mark(this.traceStartMark);
1069
- this.state = 2 /* RUNNING */;
1069
+ this.state = 2 /* TraceState.RUNNING */;
1070
1070
  };
1071
1071
  /**
1072
1072
  * Stops the trace. The measurement of the duration of the trace stops at this point and trace
1073
1073
  * is logged.
1074
1074
  */
1075
1075
  Trace.prototype.stop = function () {
1076
- if (this.state !== 2 /* RUNNING */) {
1077
- throw ERROR_FACTORY.create("trace stopped" /* TRACE_STOPPED_BEFORE */, {
1076
+ if (this.state !== 2 /* TraceState.RUNNING */) {
1077
+ throw ERROR_FACTORY.create("trace stopped" /* ErrorCode.TRACE_STOPPED_BEFORE */, {
1078
1078
  traceName: this.name
1079
1079
  });
1080
1080
  }
1081
- this.state = 3 /* TERMINATED */;
1081
+ this.state = 3 /* TraceState.TERMINATED */;
1082
1082
  this.api.mark(this.traceStopMark);
1083
1083
  this.api.measure(this.traceMeasure, this.traceStartMark, this.traceStopMark);
1084
1084
  this.calculateTraceMetrics();
@@ -1093,12 +1093,12 @@ var Trace = /** @class */ (function () {
1093
1093
  */
1094
1094
  Trace.prototype.record = function (startTime, duration, options) {
1095
1095
  if (startTime <= 0) {
1096
- throw ERROR_FACTORY.create("nonpositive trace startTime" /* NONPOSITIVE_TRACE_START_TIME */, {
1096
+ throw ERROR_FACTORY.create("nonpositive trace startTime" /* ErrorCode.NONPOSITIVE_TRACE_START_TIME */, {
1097
1097
  traceName: this.name
1098
1098
  });
1099
1099
  }
1100
1100
  if (duration <= 0) {
1101
- throw ERROR_FACTORY.create("nonpositive trace duration" /* NONPOSITIVE_TRACE_DURATION */, {
1101
+ throw ERROR_FACTORY.create("nonpositive trace duration" /* ErrorCode.NONPOSITIVE_TRACE_DURATION */, {
1102
1102
  traceName: this.name
1103
1103
  });
1104
1104
  }
@@ -1144,7 +1144,7 @@ var Trace = /** @class */ (function () {
1144
1144
  this.counters[counter] = convertMetricValueToInteger(numAsInteger !== null && numAsInteger !== void 0 ? numAsInteger : 0);
1145
1145
  }
1146
1146
  else {
1147
- throw ERROR_FACTORY.create("invalid custom metric name" /* INVALID_CUSTOM_METRIC_NAME */, {
1147
+ throw ERROR_FACTORY.create("invalid custom metric name" /* ErrorCode.INVALID_CUSTOM_METRIC_NAME */, {
1148
1148
  customMetricName: counter
1149
1149
  });
1150
1150
  }
@@ -1171,12 +1171,12 @@ var Trace = /** @class */ (function () {
1171
1171
  }
1172
1172
  // Throw appropriate error when the attribute name or value is invalid.
1173
1173
  if (!isValidName) {
1174
- throw ERROR_FACTORY.create("invalid attribute name" /* INVALID_ATTRIBUTE_NAME */, {
1174
+ throw ERROR_FACTORY.create("invalid attribute name" /* ErrorCode.INVALID_ATTRIBUTE_NAME */, {
1175
1175
  attributeName: attr
1176
1176
  });
1177
1177
  }
1178
1178
  if (!isValidValue) {
1179
- throw ERROR_FACTORY.create("invalid attribute value" /* INVALID_ATTRIBUTE_VALUE */, {
1179
+ throw ERROR_FACTORY.create("invalid attribute value" /* ErrorCode.INVALID_ATTRIBUTE_VALUE */, {
1180
1180
  attributeValue: value
1181
1181
  });
1182
1182
  }
@@ -1438,7 +1438,7 @@ var PerformanceController = /** @class */ (function () {
1438
1438
  }
1439
1439
  })
1440
1440
  .catch(function (error) {
1441
- consoleLogger.info("Environment doesn't support IndexedDB: " + error);
1441
+ consoleLogger.info("Environment doesn't support IndexedDB: ".concat(error));
1442
1442
  });
1443
1443
  }
1444
1444
  else {
@@ -1505,7 +1505,7 @@ function initializePerformance(app, settings) {
1505
1505
  return existingInstance;
1506
1506
  }
1507
1507
  else {
1508
- throw ERROR_FACTORY.create("already initialized" /* ALREADY_INITIALIZED */);
1508
+ throw ERROR_FACTORY.create("already initialized" /* ErrorCode.ALREADY_INITIALIZED */);
1509
1509
  }
1510
1510
  }
1511
1511
  var perfInstance = provider.initialize({
@@ -1531,10 +1531,10 @@ var factory = function (container, _a) {
1531
1531
  .getProvider('installations-internal')
1532
1532
  .getImmediate();
1533
1533
  if (app.name !== DEFAULT_ENTRY_NAME) {
1534
- throw ERROR_FACTORY.create("FB not default" /* FB_NOT_DEFAULT */);
1534
+ throw ERROR_FACTORY.create("FB not default" /* ErrorCode.FB_NOT_DEFAULT */);
1535
1535
  }
1536
1536
  if (typeof window === 'undefined') {
1537
- throw ERROR_FACTORY.create("no window" /* NO_WINDOW */);
1537
+ throw ERROR_FACTORY.create("no window" /* ErrorCode.NO_WINDOW */);
1538
1538
  }
1539
1539
  setupApi(window);
1540
1540
  var perfInstance = new PerformanceController(app, installations);
@@ -1542,7 +1542,7 @@ var factory = function (container, _a) {
1542
1542
  return perfInstance;
1543
1543
  };
1544
1544
  function registerPerformance() {
1545
- _registerComponent(new Component('performance', factory, "PUBLIC" /* PUBLIC */));
1545
+ _registerComponent(new Component('performance', factory, "PUBLIC" /* ComponentType.PUBLIC */));
1546
1546
  registerVersion(name, version);
1547
1547
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1548
1548
  registerVersion(name, version, 'esm5');