@firebase/performance 0.5.17 → 0.6.0-canary.20e5ef7fb

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.
@@ -5,7 +5,7 @@ import { Component } from '@firebase/component';
5
5
  import '@firebase/installations';
6
6
 
7
7
  const name = "@firebase/performance";
8
- const version = "0.5.17";
8
+ const version = "0.6.0-canary.20e5ef7fb";
9
9
 
10
10
  /**
11
11
  * @license
@@ -57,22 +57,22 @@ const SERVICE_NAME = 'Performance';
57
57
  * limitations under the License.
58
58
  */
59
59
  const ERROR_DESCRIPTION_MAP = {
60
- ["trace started" /* TRACE_STARTED_BEFORE */]: 'Trace {$traceName} was started before.',
61
- ["trace stopped" /* TRACE_STOPPED_BEFORE */]: 'Trace {$traceName} is not running.',
62
- ["nonpositive trace startTime" /* NONPOSITIVE_TRACE_START_TIME */]: 'Trace {$traceName} startTime should be positive.',
63
- ["nonpositive trace duration" /* NONPOSITIVE_TRACE_DURATION */]: 'Trace {$traceName} duration should be positive.',
64
- ["no window" /* NO_WINDOW */]: 'Window is not available.',
65
- ["no app id" /* NO_APP_ID */]: 'App id is not available.',
66
- ["no project id" /* NO_PROJECT_ID */]: 'Project id is not available.',
67
- ["no api key" /* NO_API_KEY */]: 'Api key is not available.',
68
- ["invalid cc log" /* INVALID_CC_LOG */]: 'Attempted to queue invalid cc event',
69
- ["FB not default" /* FB_NOT_DEFAULT */]: 'Performance can only start when Firebase app instance is the default one.',
70
- ["RC response not ok" /* RC_NOT_OK */]: 'RC response is not ok',
71
- ["invalid attribute name" /* INVALID_ATTRIBUTE_NAME */]: 'Attribute name {$attributeName} is invalid.',
72
- ["invalid attribute value" /* INVALID_ATTRIBUTE_VALUE */]: 'Attribute value {$attributeValue} is invalid.',
73
- ["invalid custom metric name" /* INVALID_CUSTOM_METRIC_NAME */]: 'Custom metric name {$customMetricName} is invalid',
74
- ["invalid String merger input" /* INVALID_STRING_MERGER_PARAMETER */]: 'Input for String merger is invalid, contact support team to resolve.',
75
- ["already initialized" /* ALREADY_INITIALIZED */]: 'initializePerformance() has already been called with ' +
60
+ ["trace started" /* ErrorCode.TRACE_STARTED_BEFORE */]: 'Trace {$traceName} was started before.',
61
+ ["trace stopped" /* ErrorCode.TRACE_STOPPED_BEFORE */]: 'Trace {$traceName} is not running.',
62
+ ["nonpositive trace startTime" /* ErrorCode.NONPOSITIVE_TRACE_START_TIME */]: 'Trace {$traceName} startTime should be positive.',
63
+ ["nonpositive trace duration" /* ErrorCode.NONPOSITIVE_TRACE_DURATION */]: 'Trace {$traceName} duration should be positive.',
64
+ ["no window" /* ErrorCode.NO_WINDOW */]: 'Window is not available.',
65
+ ["no app id" /* ErrorCode.NO_APP_ID */]: 'App id is not available.',
66
+ ["no project id" /* ErrorCode.NO_PROJECT_ID */]: 'Project id is not available.',
67
+ ["no api key" /* ErrorCode.NO_API_KEY */]: 'Api key is not available.',
68
+ ["invalid cc log" /* ErrorCode.INVALID_CC_LOG */]: 'Attempted to queue invalid cc event',
69
+ ["FB not default" /* ErrorCode.FB_NOT_DEFAULT */]: 'Performance can only start when Firebase app instance is the default one.',
70
+ ["RC response not ok" /* ErrorCode.RC_NOT_OK */]: 'RC response is not ok',
71
+ ["invalid attribute name" /* ErrorCode.INVALID_ATTRIBUTE_NAME */]: 'Attribute name {$attributeName} is invalid.',
72
+ ["invalid attribute value" /* ErrorCode.INVALID_ATTRIBUTE_VALUE */]: 'Attribute value {$attributeValue} is invalid.',
73
+ ["invalid custom metric name" /* ErrorCode.INVALID_CUSTOM_METRIC_NAME */]: 'Custom metric name {$customMetricName} is invalid',
74
+ ["invalid String merger input" /* ErrorCode.INVALID_STRING_MERGER_PARAMETER */]: 'Input for String merger is invalid, contact support team to resolve.',
75
+ ["already initialized" /* ErrorCode.ALREADY_INITIALIZED */]: 'initializePerformance() has already been called with ' +
76
76
  'different options. To avoid this error, call initializePerformance() with the ' +
77
77
  'same options as when it was originally called, or call getPerformance() to return the' +
78
78
  ' already initialized instance.'
@@ -124,7 +124,7 @@ class Api {
124
124
  constructor(window) {
125
125
  this.window = window;
126
126
  if (!window) {
127
- throw ERROR_FACTORY.create("no window" /* NO_WINDOW */);
127
+ throw ERROR_FACTORY.create("no window" /* ErrorCode.NO_WINDOW */);
128
128
  }
129
129
  this.performance = window.performance;
130
130
  this.PerformanceObserver = window.PerformanceObserver;
@@ -264,7 +264,7 @@ function getAuthTokenPromise(installationsService) {
264
264
  function mergeStrings(part1, part2) {
265
265
  const sizeDiff = part1.length - part2.length;
266
266
  if (sizeDiff < 0 || sizeDiff > 1) {
267
- throw ERROR_FACTORY.create("invalid String merger input" /* INVALID_STRING_MERGER_PARAMETER */);
267
+ throw ERROR_FACTORY.create("invalid String merger input" /* ErrorCode.INVALID_STRING_MERGER_PARAMETER */);
268
268
  }
269
269
  const resultArray = [];
270
270
  for (let i = 0; i < part1.length; i++) {
@@ -359,14 +359,14 @@ function getServiceWorkerStatus() {
359
359
  const navigator = Api.getInstance().navigator;
360
360
  if (navigator === null || navigator === void 0 ? void 0 : navigator.serviceWorker) {
361
361
  if (navigator.serviceWorker.controller) {
362
- return 2 /* CONTROLLED */;
362
+ return 2 /* ServiceWorkerStatus.CONTROLLED */;
363
363
  }
364
364
  else {
365
- return 3 /* UNCONTROLLED */;
365
+ return 3 /* ServiceWorkerStatus.UNCONTROLLED */;
366
366
  }
367
367
  }
368
368
  else {
369
- return 1 /* UNSUPPORTED */;
369
+ return 1 /* ServiceWorkerStatus.UNSUPPORTED */;
370
370
  }
371
371
  }
372
372
  function getVisibilityState() {
@@ -387,15 +387,15 @@ function getEffectiveConnectionType() {
387
387
  const effectiveType = navigatorConnection && navigatorConnection.effectiveType;
388
388
  switch (effectiveType) {
389
389
  case 'slow-2g':
390
- return 1 /* CONNECTION_SLOW_2G */;
390
+ return 1 /* EffectiveConnectionType.CONNECTION_SLOW_2G */;
391
391
  case '2g':
392
- return 2 /* CONNECTION_2G */;
392
+ return 2 /* EffectiveConnectionType.CONNECTION_2G */;
393
393
  case '3g':
394
- return 3 /* CONNECTION_3G */;
394
+ return 3 /* EffectiveConnectionType.CONNECTION_3G */;
395
395
  case '4g':
396
- return 4 /* CONNECTION_4G */;
396
+ return 4 /* EffectiveConnectionType.CONNECTION_4G */;
397
397
  default:
398
- return 0 /* UNKNOWN */;
398
+ return 0 /* EffectiveConnectionType.UNKNOWN */;
399
399
  }
400
400
  }
401
401
  function isValidCustomAttributeName(name) {
@@ -429,7 +429,7 @@ function getAppId(firebaseApp) {
429
429
  var _a;
430
430
  const appId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.appId;
431
431
  if (!appId) {
432
- throw ERROR_FACTORY.create("no app id" /* NO_APP_ID */);
432
+ throw ERROR_FACTORY.create("no app id" /* ErrorCode.NO_APP_ID */);
433
433
  }
434
434
  return appId;
435
435
  }
@@ -437,7 +437,7 @@ function getProjectId(firebaseApp) {
437
437
  var _a;
438
438
  const projectId = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.projectId;
439
439
  if (!projectId) {
440
- throw ERROR_FACTORY.create("no project id" /* NO_PROJECT_ID */);
440
+ throw ERROR_FACTORY.create("no project id" /* ErrorCode.NO_PROJECT_ID */);
441
441
  }
442
442
  return projectId;
443
443
  }
@@ -445,7 +445,7 @@ function getApiKey(firebaseApp) {
445
445
  var _a;
446
446
  const apiKey = (_a = firebaseApp.options) === null || _a === void 0 ? void 0 : _a.apiKey;
447
447
  if (!apiKey) {
448
- throw ERROR_FACTORY.create("no api key" /* NO_API_KEY */);
448
+ throw ERROR_FACTORY.create("no api key" /* ErrorCode.NO_API_KEY */);
449
449
  }
450
450
  return apiKey;
451
451
  }
@@ -541,7 +541,7 @@ function getRemoteConfig(performanceController, iid) {
541
541
  return response.json();
542
542
  }
543
543
  // In case response is not ok. This will be caught by catch.
544
- throw ERROR_FACTORY.create("RC response not ok" /* RC_NOT_OK */);
544
+ throw ERROR_FACTORY.create("RC response not ok" /* ErrorCode.RC_NOT_OK */);
545
545
  });
546
546
  })
547
547
  .catch(() => {
@@ -632,16 +632,16 @@ function shouldLogAfterSampling(samplingRate) {
632
632
  * See the License for the specific language governing permissions and
633
633
  * limitations under the License.
634
634
  */
635
- let initializationStatus = 1 /* notInitialized */;
635
+ let initializationStatus = 1 /* InitializationStatus.notInitialized */;
636
636
  let initializationPromise;
637
637
  function getInitializationPromise(performanceController) {
638
- initializationStatus = 2 /* initializationPending */;
638
+ initializationStatus = 2 /* InitializationStatus.initializationPending */;
639
639
  initializationPromise =
640
640
  initializationPromise || initializePerf(performanceController);
641
641
  return initializationPromise;
642
642
  }
643
643
  function isPerfInitialized() {
644
- return initializationStatus === 3 /* initialized */;
644
+ return initializationStatus === 3 /* InitializationStatus.initialized */;
645
645
  }
646
646
  function initializePerf(performanceController) {
647
647
  return getDocumentReadyComplete()
@@ -671,7 +671,7 @@ function getDocumentReadyComplete() {
671
671
  });
672
672
  }
673
673
  function changeInitializationStatus() {
674
- initializationStatus = 3 /* initialized */;
674
+ initializationStatus = 3 /* InitializationStatus.initialized */;
675
675
  }
676
676
 
677
677
  /**
@@ -786,7 +786,7 @@ function postToFlEndpoint(data) {
786
786
  }
787
787
  function addToQueue(evt) {
788
788
  if (!evt.eventTime || !evt.message) {
789
- throw ERROR_FACTORY.create("invalid cc log" /* INVALID_CC_LOG */);
789
+ throw ERROR_FACTORY.create("invalid cc log" /* ErrorCode.INVALID_CC_LOG */);
790
790
  }
791
791
  // Add the new event to the queue.
792
792
  queue = [...queue, evt];
@@ -865,7 +865,7 @@ function sendTraceLog(trace) {
865
865
  !settingsService.logTraceAfterSampling) {
866
866
  return;
867
867
  }
868
- setTimeout(() => sendLog(trace, 1 /* Trace */), 0);
868
+ setTimeout(() => sendLog(trace, 1 /* ResourceType.Trace */), 0);
869
869
  }
870
870
  function logNetworkRequest(networkRequest) {
871
871
  const settingsService = SettingsService.getInstance();
@@ -888,10 +888,10 @@ function logNetworkRequest(networkRequest) {
888
888
  !settingsService.logNetworkAfterSampling) {
889
889
  return;
890
890
  }
891
- setTimeout(() => sendLog(networkRequest, 0 /* NetworkRequest */), 0);
891
+ setTimeout(() => sendLog(networkRequest, 0 /* ResourceType.NetworkRequest */), 0);
892
892
  }
893
893
  function serializer(resource, resourceType) {
894
- if (resourceType === 0 /* NetworkRequest */) {
894
+ if (resourceType === 0 /* ResourceType.NetworkRequest */) {
895
895
  return serializeNetworkRequest(resource);
896
896
  }
897
897
  return serializeTrace(resource);
@@ -1026,7 +1026,7 @@ class Trace {
1026
1026
  this.performanceController = performanceController;
1027
1027
  this.name = name;
1028
1028
  this.isAuto = isAuto;
1029
- this.state = 1 /* UNINITIALIZED */;
1029
+ this.state = 1 /* TraceState.UNINITIALIZED */;
1030
1030
  this.customAttributes = {};
1031
1031
  this.counters = {};
1032
1032
  this.api = Api.getInstance();
@@ -1048,25 +1048,25 @@ class Trace {
1048
1048
  * Starts a trace. The measurement of the duration starts at this point.
1049
1049
  */
1050
1050
  start() {
1051
- if (this.state !== 1 /* UNINITIALIZED */) {
1052
- throw ERROR_FACTORY.create("trace started" /* TRACE_STARTED_BEFORE */, {
1051
+ if (this.state !== 1 /* TraceState.UNINITIALIZED */) {
1052
+ throw ERROR_FACTORY.create("trace started" /* ErrorCode.TRACE_STARTED_BEFORE */, {
1053
1053
  traceName: this.name
1054
1054
  });
1055
1055
  }
1056
1056
  this.api.mark(this.traceStartMark);
1057
- this.state = 2 /* RUNNING */;
1057
+ this.state = 2 /* TraceState.RUNNING */;
1058
1058
  }
1059
1059
  /**
1060
1060
  * Stops the trace. The measurement of the duration of the trace stops at this point and trace
1061
1061
  * is logged.
1062
1062
  */
1063
1063
  stop() {
1064
- if (this.state !== 2 /* RUNNING */) {
1065
- throw ERROR_FACTORY.create("trace stopped" /* TRACE_STOPPED_BEFORE */, {
1064
+ if (this.state !== 2 /* TraceState.RUNNING */) {
1065
+ throw ERROR_FACTORY.create("trace stopped" /* ErrorCode.TRACE_STOPPED_BEFORE */, {
1066
1066
  traceName: this.name
1067
1067
  });
1068
1068
  }
1069
- this.state = 3 /* TERMINATED */;
1069
+ this.state = 3 /* TraceState.TERMINATED */;
1070
1070
  this.api.mark(this.traceStopMark);
1071
1071
  this.api.measure(this.traceMeasure, this.traceStartMark, this.traceStopMark);
1072
1072
  this.calculateTraceMetrics();
@@ -1081,12 +1081,12 @@ class Trace {
1081
1081
  */
1082
1082
  record(startTime, duration, options) {
1083
1083
  if (startTime <= 0) {
1084
- throw ERROR_FACTORY.create("nonpositive trace startTime" /* NONPOSITIVE_TRACE_START_TIME */, {
1084
+ throw ERROR_FACTORY.create("nonpositive trace startTime" /* ErrorCode.NONPOSITIVE_TRACE_START_TIME */, {
1085
1085
  traceName: this.name
1086
1086
  });
1087
1087
  }
1088
1088
  if (duration <= 0) {
1089
- throw ERROR_FACTORY.create("nonpositive trace duration" /* NONPOSITIVE_TRACE_DURATION */, {
1089
+ throw ERROR_FACTORY.create("nonpositive trace duration" /* ErrorCode.NONPOSITIVE_TRACE_DURATION */, {
1090
1090
  traceName: this.name
1091
1091
  });
1092
1092
  }
@@ -1130,7 +1130,7 @@ class Trace {
1130
1130
  this.counters[counter] = convertMetricValueToInteger(numAsInteger !== null && numAsInteger !== void 0 ? numAsInteger : 0);
1131
1131
  }
1132
1132
  else {
1133
- throw ERROR_FACTORY.create("invalid custom metric name" /* INVALID_CUSTOM_METRIC_NAME */, {
1133
+ throw ERROR_FACTORY.create("invalid custom metric name" /* ErrorCode.INVALID_CUSTOM_METRIC_NAME */, {
1134
1134
  customMetricName: counter
1135
1135
  });
1136
1136
  }
@@ -1157,12 +1157,12 @@ class Trace {
1157
1157
  }
1158
1158
  // Throw appropriate error when the attribute name or value is invalid.
1159
1159
  if (!isValidName) {
1160
- throw ERROR_FACTORY.create("invalid attribute name" /* INVALID_ATTRIBUTE_NAME */, {
1160
+ throw ERROR_FACTORY.create("invalid attribute name" /* ErrorCode.INVALID_ATTRIBUTE_NAME */, {
1161
1161
  attributeName: attr
1162
1162
  });
1163
1163
  }
1164
1164
  if (!isValidValue) {
1165
- throw ERROR_FACTORY.create("invalid attribute value" /* INVALID_ATTRIBUTE_VALUE */, {
1165
+ throw ERROR_FACTORY.create("invalid attribute value" /* ErrorCode.INVALID_ATTRIBUTE_VALUE */, {
1166
1166
  attributeValue: value
1167
1167
  });
1168
1168
  }
@@ -1473,7 +1473,7 @@ function initializePerformance(app, settings) {
1473
1473
  return existingInstance;
1474
1474
  }
1475
1475
  else {
1476
- throw ERROR_FACTORY.create("already initialized" /* ALREADY_INITIALIZED */);
1476
+ throw ERROR_FACTORY.create("already initialized" /* ErrorCode.ALREADY_INITIALIZED */);
1477
1477
  }
1478
1478
  }
1479
1479
  const perfInstance = provider.initialize({
@@ -1498,10 +1498,10 @@ const factory = (container, { options: settings }) => {
1498
1498
  .getProvider('installations-internal')
1499
1499
  .getImmediate();
1500
1500
  if (app.name !== DEFAULT_ENTRY_NAME) {
1501
- throw ERROR_FACTORY.create("FB not default" /* FB_NOT_DEFAULT */);
1501
+ throw ERROR_FACTORY.create("FB not default" /* ErrorCode.FB_NOT_DEFAULT */);
1502
1502
  }
1503
1503
  if (typeof window === 'undefined') {
1504
- throw ERROR_FACTORY.create("no window" /* NO_WINDOW */);
1504
+ throw ERROR_FACTORY.create("no window" /* ErrorCode.NO_WINDOW */);
1505
1505
  }
1506
1506
  setupApi(window);
1507
1507
  const perfInstance = new PerformanceController(app, installations);
@@ -1509,7 +1509,7 @@ const factory = (container, { options: settings }) => {
1509
1509
  return perfInstance;
1510
1510
  };
1511
1511
  function registerPerformance() {
1512
- _registerComponent(new Component('performance', factory, "PUBLIC" /* PUBLIC */));
1512
+ _registerComponent(new Component('performance', factory, "PUBLIC" /* ComponentType.PUBLIC */));
1513
1513
  registerVersion(name, version);
1514
1514
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
1515
1515
  registerVersion(name, version, 'esm2017');