@firebase/performance 0.5.17 → 0.6.0-20221206221533

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/index.cjs.js CHANGED
@@ -10,7 +10,7 @@ var component = require('@firebase/component');
10
10
  require('@firebase/installations');
11
11
 
12
12
  var name = "@firebase/performance";
13
- var version = "0.5.17";
13
+ var version = "0.6.0-20221206221533";
14
14
 
15
15
  /**
16
16
  * @license
@@ -63,22 +63,22 @@ var SERVICE_NAME = 'Performance';
63
63
  */
64
64
  var _a;
65
65
  var ERROR_DESCRIPTION_MAP = (_a = {},
66
- _a["trace started" /* TRACE_STARTED_BEFORE */] = 'Trace {$traceName} was started before.',
67
- _a["trace stopped" /* TRACE_STOPPED_BEFORE */] = 'Trace {$traceName} is not running.',
68
- _a["nonpositive trace startTime" /* NONPOSITIVE_TRACE_START_TIME */] = 'Trace {$traceName} startTime should be positive.',
69
- _a["nonpositive trace duration" /* NONPOSITIVE_TRACE_DURATION */] = 'Trace {$traceName} duration should be positive.',
70
- _a["no window" /* NO_WINDOW */] = 'Window is not available.',
71
- _a["no app id" /* NO_APP_ID */] = 'App id is not available.',
72
- _a["no project id" /* NO_PROJECT_ID */] = 'Project id is not available.',
73
- _a["no api key" /* NO_API_KEY */] = 'Api key is not available.',
74
- _a["invalid cc log" /* INVALID_CC_LOG */] = 'Attempted to queue invalid cc event',
75
- _a["FB not default" /* FB_NOT_DEFAULT */] = 'Performance can only start when Firebase app instance is the default one.',
76
- _a["RC response not ok" /* RC_NOT_OK */] = 'RC response is not ok',
77
- _a["invalid attribute name" /* INVALID_ATTRIBUTE_NAME */] = 'Attribute name {$attributeName} is invalid.',
78
- _a["invalid attribute value" /* INVALID_ATTRIBUTE_VALUE */] = 'Attribute value {$attributeValue} is invalid.',
79
- _a["invalid custom metric name" /* INVALID_CUSTOM_METRIC_NAME */] = 'Custom metric name {$customMetricName} is invalid',
80
- _a["invalid String merger input" /* INVALID_STRING_MERGER_PARAMETER */] = 'Input for String merger is invalid, contact support team to resolve.',
81
- _a["already initialized" /* ALREADY_INITIALIZED */] = 'initializePerformance() has already been called with ' +
66
+ _a["trace started" /* ErrorCode.TRACE_STARTED_BEFORE */] = 'Trace {$traceName} was started before.',
67
+ _a["trace stopped" /* ErrorCode.TRACE_STOPPED_BEFORE */] = 'Trace {$traceName} is not running.',
68
+ _a["nonpositive trace startTime" /* ErrorCode.NONPOSITIVE_TRACE_START_TIME */] = 'Trace {$traceName} startTime should be positive.',
69
+ _a["nonpositive trace duration" /* ErrorCode.NONPOSITIVE_TRACE_DURATION */] = 'Trace {$traceName} duration should be positive.',
70
+ _a["no window" /* ErrorCode.NO_WINDOW */] = 'Window is not available.',
71
+ _a["no app id" /* ErrorCode.NO_APP_ID */] = 'App id is not available.',
72
+ _a["no project id" /* ErrorCode.NO_PROJECT_ID */] = 'Project id is not available.',
73
+ _a["no api key" /* ErrorCode.NO_API_KEY */] = 'Api key is not available.',
74
+ _a["invalid cc log" /* ErrorCode.INVALID_CC_LOG */] = 'Attempted to queue invalid cc event',
75
+ _a["FB not default" /* ErrorCode.FB_NOT_DEFAULT */] = 'Performance can only start when Firebase app instance is the default one.',
76
+ _a["RC response not ok" /* ErrorCode.RC_NOT_OK */] = 'RC response is not ok',
77
+ _a["invalid attribute name" /* ErrorCode.INVALID_ATTRIBUTE_NAME */] = 'Attribute name {$attributeName} is invalid.',
78
+ _a["invalid attribute value" /* ErrorCode.INVALID_ATTRIBUTE_VALUE */] = 'Attribute value {$attributeValue} is invalid.',
79
+ _a["invalid custom metric name" /* ErrorCode.INVALID_CUSTOM_METRIC_NAME */] = 'Custom metric name {$customMetricName} is invalid',
80
+ _a["invalid String merger input" /* ErrorCode.INVALID_STRING_MERGER_PARAMETER */] = 'Input for String merger is invalid, contact support team to resolve.',
81
+ _a["already initialized" /* ErrorCode.ALREADY_INITIALIZED */] = 'initializePerformance() has already been called with ' +
82
82
  'different options. To avoid this error, call initializePerformance() with the ' +
83
83
  'same options as when it was originally called, or call getPerformance() to return the' +
84
84
  ' already initialized instance.',
@@ -130,7 +130,7 @@ var Api = /** @class */ (function () {
130
130
  function Api(window) {
131
131
  this.window = window;
132
132
  if (!window) {
133
- throw ERROR_FACTORY.create("no window" /* NO_WINDOW */);
133
+ throw ERROR_FACTORY.create("no window" /* ErrorCode.NO_WINDOW */);
134
134
  }
135
135
  this.performance = window.performance;
136
136
  this.PerformanceObserver = window.PerformanceObserver;
@@ -272,7 +272,7 @@ function getAuthTokenPromise(installationsService) {
272
272
  function mergeStrings(part1, part2) {
273
273
  var sizeDiff = part1.length - part2.length;
274
274
  if (sizeDiff < 0 || sizeDiff > 1) {
275
- throw ERROR_FACTORY.create("invalid String merger input" /* INVALID_STRING_MERGER_PARAMETER */);
275
+ throw ERROR_FACTORY.create("invalid String merger input" /* ErrorCode.INVALID_STRING_MERGER_PARAMETER */);
276
276
  }
277
277
  var resultArray = [];
278
278
  for (var i = 0; i < part1.length; i++) {
@@ -368,14 +368,14 @@ function getServiceWorkerStatus() {
368
368
  var navigator = Api.getInstance().navigator;
369
369
  if (navigator === null || navigator === void 0 ? void 0 : navigator.serviceWorker) {
370
370
  if (navigator.serviceWorker.controller) {
371
- return 2 /* CONTROLLED */;
371
+ return 2 /* ServiceWorkerStatus.CONTROLLED */;
372
372
  }
373
373
  else {
374
- return 3 /* UNCONTROLLED */;
374
+ return 3 /* ServiceWorkerStatus.UNCONTROLLED */;
375
375
  }
376
376
  }
377
377
  else {
378
- return 1 /* UNSUPPORTED */;
378
+ return 1 /* ServiceWorkerStatus.UNSUPPORTED */;
379
379
  }
380
380
  }
381
381
  function getVisibilityState() {
@@ -396,15 +396,15 @@ function getEffectiveConnectionType() {
396
396
  var effectiveType = navigatorConnection && navigatorConnection.effectiveType;
397
397
  switch (effectiveType) {
398
398
  case 'slow-2g':
399
- return 1 /* CONNECTION_SLOW_2G */;
399
+ return 1 /* EffectiveConnectionType.CONNECTION_SLOW_2G */;
400
400
  case '2g':
401
- return 2 /* CONNECTION_2G */;
401
+ return 2 /* EffectiveConnectionType.CONNECTION_2G */;
402
402
  case '3g':
403
- return 3 /* CONNECTION_3G */;
403
+ return 3 /* EffectiveConnectionType.CONNECTION_3G */;
404
404
  case '4g':
405
- return 4 /* CONNECTION_4G */;
405
+ return 4 /* EffectiveConnectionType.CONNECTION_4G */;
406
406
  default:
407
- return 0 /* UNKNOWN */;
407
+ return 0 /* EffectiveConnectionType.UNKNOWN */;
408
408
  }
409
409
  }
410
410
  function isValidCustomAttributeName(name) {
@@ -440,7 +440,7 @@ function getAppId(firebaseApp) {
440
440
  var _a;
441
441
  var appId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.appId;
442
442
  if (!appId) {
443
- throw ERROR_FACTORY.create("no app id" /* NO_APP_ID */);
443
+ throw ERROR_FACTORY.create("no app id" /* ErrorCode.NO_APP_ID */);
444
444
  }
445
445
  return appId;
446
446
  }
@@ -448,7 +448,7 @@ function getProjectId(firebaseApp) {
448
448
  var _a;
449
449
  var projectId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.projectId;
450
450
  if (!projectId) {
451
- throw ERROR_FACTORY.create("no project id" /* NO_PROJECT_ID */);
451
+ throw ERROR_FACTORY.create("no project id" /* ErrorCode.NO_PROJECT_ID */);
452
452
  }
453
453
  return projectId;
454
454
  }
@@ -456,7 +456,7 @@ function getApiKey(firebaseApp) {
456
456
  var _a;
457
457
  var apiKey = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.apiKey;
458
458
  if (!apiKey) {
459
- throw ERROR_FACTORY.create("no api key" /* NO_API_KEY */);
459
+ throw ERROR_FACTORY.create("no api key" /* ErrorCode.NO_API_KEY */);
460
460
  }
461
461
  return apiKey;
462
462
  }
@@ -533,10 +533,10 @@ function getRemoteConfig(performanceController, iid) {
533
533
  .then(function (authToken) {
534
534
  var projectId = getProjectId(performanceController.app);
535
535
  var apiKey = getApiKey(performanceController.app);
536
- var configEndPoint = "https://firebaseremoteconfig.googleapis.com/v1/projects/" + projectId + "/namespaces/fireperf:fetch?key=" + apiKey;
536
+ var configEndPoint = "https://firebaseremoteconfig.googleapis.com/v1/projects/".concat(projectId, "/namespaces/fireperf:fetch?key=").concat(apiKey);
537
537
  var request = new Request(configEndPoint, {
538
538
  method: 'POST',
539
- headers: { Authorization: FIS_AUTH_PREFIX + " " + authToken },
539
+ headers: { Authorization: "".concat(FIS_AUTH_PREFIX, " ").concat(authToken) },
540
540
  /* eslint-disable camelcase */
541
541
  body: JSON.stringify({
542
542
  app_instance_id: iid,
@@ -552,7 +552,7 @@ function getRemoteConfig(performanceController, iid) {
552
552
  return response.json();
553
553
  }
554
554
  // In case response is not ok. This will be caught by catch.
555
- throw ERROR_FACTORY.create("RC response not ok" /* RC_NOT_OK */);
555
+ throw ERROR_FACTORY.create("RC response not ok" /* ErrorCode.RC_NOT_OK */);
556
556
  });
557
557
  })
558
558
  .catch(function () {
@@ -643,16 +643,16 @@ function shouldLogAfterSampling(samplingRate) {
643
643
  * See the License for the specific language governing permissions and
644
644
  * limitations under the License.
645
645
  */
646
- var initializationStatus = 1 /* notInitialized */;
646
+ var initializationStatus = 1 /* InitializationStatus.notInitialized */;
647
647
  var initializationPromise;
648
648
  function getInitializationPromise(performanceController) {
649
- initializationStatus = 2 /* initializationPending */;
649
+ initializationStatus = 2 /* InitializationStatus.initializationPending */;
650
650
  initializationPromise =
651
651
  initializationPromise || initializePerf(performanceController);
652
652
  return initializationPromise;
653
653
  }
654
654
  function isPerfInitialized() {
655
- return initializationStatus === 3 /* initialized */;
655
+ return initializationStatus === 3 /* InitializationStatus.initialized */;
656
656
  }
657
657
  function initializePerf(performanceController) {
658
658
  return getDocumentReadyComplete()
@@ -682,7 +682,7 @@ function getDocumentReadyComplete() {
682
682
  });
683
683
  }
684
684
  function changeInitializationStatus() {
685
- initializationStatus = 3 /* initialized */;
685
+ initializationStatus = 3 /* InitializationStatus.initialized */;
686
686
  }
687
687
 
688
688
  /**
@@ -753,9 +753,9 @@ function dispatchQueueEvents() {
753
753
  sendEventsToFl(data, staged).catch(function () {
754
754
  // If the request fails for some reason, add the events that were attempted
755
755
  // back to the primary queue to retry later.
756
- queue = tslib.__spreadArray(tslib.__spreadArray([], staged), queue);
756
+ queue = tslib.__spreadArray(tslib.__spreadArray([], staged, true), queue, true);
757
757
  remainingTries--;
758
- consoleLogger.info("Tries left: " + remainingTries + ".");
758
+ consoleLogger.info("Tries left: ".concat(remainingTries, "."));
759
759
  processQueue(DEFAULT_SEND_INTERVAL_MS);
760
760
  });
761
761
  }
@@ -780,7 +780,7 @@ function sendEventsToFl(data, staged) {
780
780
  if (Array.isArray(logResponseDetails) &&
781
781
  logResponseDetails.length > 0 &&
782
782
  logResponseDetails[0].responseAction === 'RETRY_REQUEST_LATER') {
783
- queue = tslib.__spreadArray(tslib.__spreadArray([], staged), queue);
783
+ queue = tslib.__spreadArray(tslib.__spreadArray([], staged, true), queue, true);
784
784
  consoleLogger.info("Retry transport request later.");
785
785
  }
786
786
  remainingTries = DEFAULT_REMAINING_TRIES;
@@ -797,10 +797,10 @@ function postToFlEndpoint(data) {
797
797
  }
798
798
  function addToQueue(evt) {
799
799
  if (!evt.eventTime || !evt.message) {
800
- throw ERROR_FACTORY.create("invalid cc log" /* INVALID_CC_LOG */);
800
+ throw ERROR_FACTORY.create("invalid cc log" /* ErrorCode.INVALID_CC_LOG */);
801
801
  }
802
802
  // Add the new event to the queue.
803
- queue = tslib.__spreadArray(tslib.__spreadArray([], queue), [evt]);
803
+ queue = tslib.__spreadArray(tslib.__spreadArray([], queue, true), [evt], false);
804
804
  }
805
805
  /** Log handler for cc service to send the performance logs to the server. */
806
806
  function transportHandler(
@@ -880,7 +880,7 @@ function sendTraceLog(trace) {
880
880
  !settingsService.logTraceAfterSampling) {
881
881
  return;
882
882
  }
883
- setTimeout(function () { return sendLog(trace, 1 /* Trace */); }, 0);
883
+ setTimeout(function () { return sendLog(trace, 1 /* ResourceType.Trace */); }, 0);
884
884
  }
885
885
  function logNetworkRequest(networkRequest) {
886
886
  var settingsService = SettingsService.getInstance();
@@ -903,10 +903,10 @@ function logNetworkRequest(networkRequest) {
903
903
  !settingsService.logNetworkAfterSampling) {
904
904
  return;
905
905
  }
906
- setTimeout(function () { return sendLog(networkRequest, 0 /* NetworkRequest */); }, 0);
906
+ setTimeout(function () { return sendLog(networkRequest, 0 /* ResourceType.NetworkRequest */); }, 0);
907
907
  }
908
908
  function serializer(resource, resourceType) {
909
- if (resourceType === 0 /* NetworkRequest */) {
909
+ if (resourceType === 0 /* ResourceType.NetworkRequest */) {
910
910
  return serializeNetworkRequest(resource);
911
911
  }
912
912
  return serializeTrace(resource);
@@ -1007,7 +1007,7 @@ function isValidMetricName(name, traceName) {
1007
1007
  function convertMetricValueToInteger(providedValue) {
1008
1008
  var valueAsInteger = Math.floor(providedValue);
1009
1009
  if (valueAsInteger < providedValue) {
1010
- consoleLogger.info("Metric value should be an Integer, setting the value as : " + valueAsInteger + ".");
1010
+ consoleLogger.info("Metric value should be an Integer, setting the value as : ".concat(valueAsInteger, "."));
1011
1011
  }
1012
1012
  return valueAsInteger;
1013
1013
  }
@@ -1042,17 +1042,17 @@ var Trace = /** @class */ (function () {
1042
1042
  this.performanceController = performanceController;
1043
1043
  this.name = name;
1044
1044
  this.isAuto = isAuto;
1045
- this.state = 1 /* UNINITIALIZED */;
1045
+ this.state = 1 /* TraceState.UNINITIALIZED */;
1046
1046
  this.customAttributes = {};
1047
1047
  this.counters = {};
1048
1048
  this.api = Api.getInstance();
1049
1049
  this.randomId = Math.floor(Math.random() * 1000000);
1050
1050
  if (!this.isAuto) {
1051
- this.traceStartMark = TRACE_START_MARK_PREFIX + "-" + this.randomId + "-" + this.name;
1052
- this.traceStopMark = TRACE_STOP_MARK_PREFIX + "-" + this.randomId + "-" + this.name;
1051
+ this.traceStartMark = "".concat(TRACE_START_MARK_PREFIX, "-").concat(this.randomId, "-").concat(this.name);
1052
+ this.traceStopMark = "".concat(TRACE_STOP_MARK_PREFIX, "-").concat(this.randomId, "-").concat(this.name);
1053
1053
  this.traceMeasure =
1054
1054
  traceMeasureName ||
1055
- TRACE_MEASURE_PREFIX + "-" + this.randomId + "-" + this.name;
1055
+ "".concat(TRACE_MEASURE_PREFIX, "-").concat(this.randomId, "-").concat(this.name);
1056
1056
  if (traceMeasureName) {
1057
1057
  // For the case of direct user timing traces, no start stop will happen. The measure object
1058
1058
  // is already available.
@@ -1064,25 +1064,25 @@ var Trace = /** @class */ (function () {
1064
1064
  * Starts a trace. The measurement of the duration starts at this point.
1065
1065
  */
1066
1066
  Trace.prototype.start = function () {
1067
- if (this.state !== 1 /* UNINITIALIZED */) {
1068
- throw ERROR_FACTORY.create("trace started" /* TRACE_STARTED_BEFORE */, {
1067
+ if (this.state !== 1 /* TraceState.UNINITIALIZED */) {
1068
+ throw ERROR_FACTORY.create("trace started" /* ErrorCode.TRACE_STARTED_BEFORE */, {
1069
1069
  traceName: this.name
1070
1070
  });
1071
1071
  }
1072
1072
  this.api.mark(this.traceStartMark);
1073
- this.state = 2 /* RUNNING */;
1073
+ this.state = 2 /* TraceState.RUNNING */;
1074
1074
  };
1075
1075
  /**
1076
1076
  * Stops the trace. The measurement of the duration of the trace stops at this point and trace
1077
1077
  * is logged.
1078
1078
  */
1079
1079
  Trace.prototype.stop = function () {
1080
- if (this.state !== 2 /* RUNNING */) {
1081
- throw ERROR_FACTORY.create("trace stopped" /* TRACE_STOPPED_BEFORE */, {
1080
+ if (this.state !== 2 /* TraceState.RUNNING */) {
1081
+ throw ERROR_FACTORY.create("trace stopped" /* ErrorCode.TRACE_STOPPED_BEFORE */, {
1082
1082
  traceName: this.name
1083
1083
  });
1084
1084
  }
1085
- this.state = 3 /* TERMINATED */;
1085
+ this.state = 3 /* TraceState.TERMINATED */;
1086
1086
  this.api.mark(this.traceStopMark);
1087
1087
  this.api.measure(this.traceMeasure, this.traceStartMark, this.traceStopMark);
1088
1088
  this.calculateTraceMetrics();
@@ -1097,12 +1097,12 @@ var Trace = /** @class */ (function () {
1097
1097
  */
1098
1098
  Trace.prototype.record = function (startTime, duration, options) {
1099
1099
  if (startTime <= 0) {
1100
- throw ERROR_FACTORY.create("nonpositive trace startTime" /* NONPOSITIVE_TRACE_START_TIME */, {
1100
+ throw ERROR_FACTORY.create("nonpositive trace startTime" /* ErrorCode.NONPOSITIVE_TRACE_START_TIME */, {
1101
1101
  traceName: this.name
1102
1102
  });
1103
1103
  }
1104
1104
  if (duration <= 0) {
1105
- throw ERROR_FACTORY.create("nonpositive trace duration" /* NONPOSITIVE_TRACE_DURATION */, {
1105
+ throw ERROR_FACTORY.create("nonpositive trace duration" /* ErrorCode.NONPOSITIVE_TRACE_DURATION */, {
1106
1106
  traceName: this.name
1107
1107
  });
1108
1108
  }
@@ -1148,7 +1148,7 @@ var Trace = /** @class */ (function () {
1148
1148
  this.counters[counter] = convertMetricValueToInteger(numAsInteger !== null && numAsInteger !== void 0 ? numAsInteger : 0);
1149
1149
  }
1150
1150
  else {
1151
- throw ERROR_FACTORY.create("invalid custom metric name" /* INVALID_CUSTOM_METRIC_NAME */, {
1151
+ throw ERROR_FACTORY.create("invalid custom metric name" /* ErrorCode.INVALID_CUSTOM_METRIC_NAME */, {
1152
1152
  customMetricName: counter
1153
1153
  });
1154
1154
  }
@@ -1175,12 +1175,12 @@ var Trace = /** @class */ (function () {
1175
1175
  }
1176
1176
  // Throw appropriate error when the attribute name or value is invalid.
1177
1177
  if (!isValidName) {
1178
- throw ERROR_FACTORY.create("invalid attribute name" /* INVALID_ATTRIBUTE_NAME */, {
1178
+ throw ERROR_FACTORY.create("invalid attribute name" /* ErrorCode.INVALID_ATTRIBUTE_NAME */, {
1179
1179
  attributeName: attr
1180
1180
  });
1181
1181
  }
1182
1182
  if (!isValidValue) {
1183
- throw ERROR_FACTORY.create("invalid attribute value" /* INVALID_ATTRIBUTE_VALUE */, {
1183
+ throw ERROR_FACTORY.create("invalid attribute value" /* ErrorCode.INVALID_ATTRIBUTE_VALUE */, {
1184
1184
  attributeValue: value
1185
1185
  });
1186
1186
  }
@@ -1442,7 +1442,7 @@ var PerformanceController = /** @class */ (function () {
1442
1442
  }
1443
1443
  })
1444
1444
  .catch(function (error) {
1445
- consoleLogger.info("Environment doesn't support IndexedDB: " + error);
1445
+ consoleLogger.info("Environment doesn't support IndexedDB: ".concat(error));
1446
1446
  });
1447
1447
  }
1448
1448
  else {
@@ -1509,7 +1509,7 @@ function initializePerformance(app$1, settings) {
1509
1509
  return existingInstance;
1510
1510
  }
1511
1511
  else {
1512
- throw ERROR_FACTORY.create("already initialized" /* ALREADY_INITIALIZED */);
1512
+ throw ERROR_FACTORY.create("already initialized" /* ErrorCode.ALREADY_INITIALIZED */);
1513
1513
  }
1514
1514
  }
1515
1515
  var perfInstance = provider.initialize({
@@ -1535,10 +1535,10 @@ var factory = function (container, _a) {
1535
1535
  .getProvider('installations-internal')
1536
1536
  .getImmediate();
1537
1537
  if (app.name !== DEFAULT_ENTRY_NAME) {
1538
- throw ERROR_FACTORY.create("FB not default" /* FB_NOT_DEFAULT */);
1538
+ throw ERROR_FACTORY.create("FB not default" /* ErrorCode.FB_NOT_DEFAULT */);
1539
1539
  }
1540
1540
  if (typeof window === 'undefined') {
1541
- throw ERROR_FACTORY.create("no window" /* NO_WINDOW */);
1541
+ throw ERROR_FACTORY.create("no window" /* ErrorCode.NO_WINDOW */);
1542
1542
  }
1543
1543
  setupApi(window);
1544
1544
  var perfInstance = new PerformanceController(app, installations);
@@ -1546,7 +1546,7 @@ var factory = function (container, _a) {
1546
1546
  return perfInstance;
1547
1547
  };
1548
1548
  function registerPerformance() {
1549
- app._registerComponent(new component.Component('performance', factory, "PUBLIC" /* PUBLIC */));
1549
+ app._registerComponent(new component.Component('performance', factory, "PUBLIC" /* ComponentType.PUBLIC */));
1550
1550
  app.registerVersion(name, version);
1551
1551
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1552
1552
  app.registerVersion(name, version, 'cjs5');