@firebase/util 1.7.3 → 1.8.0-canary.06dc1364d

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.
@@ -455,7 +455,7 @@ function isValidKey(key) {
455
455
 
456
456
  /**
457
457
  * @license
458
- * Copyright 2017 Google LLC
458
+ * Copyright 2022 Google LLC
459
459
  *
460
460
  * Licensed under the Apache License, Version 2.0 (the "License");
461
461
  * you may not use this file except in compliance with the License.
@@ -469,151 +469,10 @@ function isValidKey(key) {
469
469
  * See the License for the specific language governing permissions and
470
470
  * limitations under the License.
471
471
  */
472
- /**
473
- * Returns navigator.userAgent string or '' if it's not defined.
474
- * @return user agent string
475
- */
476
- function getUA() {
477
- if (typeof navigator !== 'undefined' &&
478
- typeof navigator['userAgent'] === 'string') {
479
- return navigator['userAgent'];
480
- }
481
- else {
482
- return '';
483
- }
484
- }
485
- /**
486
- * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
487
- *
488
- * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
489
- * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
490
- * wait for a callback.
491
- */
492
- function isMobileCordova() {
493
- return (typeof window !== 'undefined' &&
494
- // @ts-ignore Setting up an broadly applicable index signature for Window
495
- // just to deal with this case would probably be a bad idea.
496
- !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
497
- /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
498
- }
499
- /**
500
- * Detect Node.js.
501
- *
502
- * @return true if Node.js environment is detected.
503
- */
504
- // Node detection logic from: https://github.com/iliakan/detect-node/
505
- function isNode() {
506
- try {
507
- return (Object.prototype.toString.call(global.process) === '[object process]');
508
- }
509
- catch (e) {
510
- return false;
511
- }
512
- }
513
- /**
514
- * Detect Browser Environment
515
- */
516
- function isBrowser() {
517
- return typeof self === 'object' && self.self === self;
518
- }
519
- function isBrowserExtension() {
520
- var runtime = typeof chrome === 'object'
521
- ? chrome.runtime
522
- : typeof browser === 'object'
523
- ? browser.runtime
524
- : undefined;
525
- return typeof runtime === 'object' && runtime.id !== undefined;
526
- }
527
- /**
528
- * Detect React Native.
529
- *
530
- * @return true if ReactNative environment is detected.
531
- */
532
- function isReactNative() {
533
- return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
534
- }
535
- /** Detects Electron apps. */
536
- function isElectron() {
537
- return getUA().indexOf('Electron/') >= 0;
538
- }
539
- /** Detects Internet Explorer. */
540
- function isIE() {
541
- var ua = getUA();
542
- return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
543
- }
544
- /** Detects Universal Windows Platform apps. */
545
- function isUWP() {
546
- return getUA().indexOf('MSAppHost/') >= 0;
547
- }
548
- /**
549
- * Detect whether the current SDK build is the Node version.
550
- *
551
- * @return true if it's the Node SDK build.
552
- */
553
- function isNodeSdk() {
554
- return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
555
- }
556
- /** Returns true if we are running in Safari. */
557
- function isSafari() {
558
- return (!isNode() &&
559
- navigator.userAgent.includes('Safari') &&
560
- !navigator.userAgent.includes('Chrome'));
561
- }
562
- /**
563
- * This method checks if indexedDB is supported by current browser/service worker context
564
- * @return true if indexedDB is supported by current browser/service worker context
565
- */
566
- function isIndexedDBAvailable() {
567
- return typeof indexedDB === 'object';
568
- }
569
- /**
570
- * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
571
- * if errors occur during the database open operation.
572
- *
573
- * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
574
- * private browsing)
575
- */
576
- function validateIndexedDBOpenable() {
577
- return new Promise(function (resolve, reject) {
578
- try {
579
- var preExist_1 = true;
580
- var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
581
- var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
582
- request_1.onsuccess = function () {
583
- request_1.result.close();
584
- // delete database only when it doesn't pre-exist
585
- if (!preExist_1) {
586
- self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
587
- }
588
- resolve(true);
589
- };
590
- request_1.onupgradeneeded = function () {
591
- preExist_1 = false;
592
- };
593
- request_1.onerror = function () {
594
- var _a;
595
- reject(((_a = request_1.error) === null || _a === void 0 ? void 0 : _a.message) || '');
596
- };
597
- }
598
- catch (error) {
599
- reject(error);
600
- }
601
- });
602
- }
603
- /**
604
- *
605
- * This method checks whether cookie is enabled within current browser
606
- * @return true if cookie is enabled within current browser
607
- */
608
- function areCookiesEnabled() {
609
- if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
610
- return false;
611
- }
612
- return true;
613
- }
614
472
  /**
615
473
  * Polyfill for `globalThis` object.
616
474
  * @returns the `globalThis` object for the given environment.
475
+ * @public
617
476
  */
618
477
  function getGlobal() {
619
478
  if (typeof self !== 'undefined') {
@@ -649,8 +508,11 @@ var getDefaultsFromGlobal = function () {
649
508
  };
650
509
  /**
651
510
  * Attempt to read defaults from a JSON string provided to
652
- * process.env.__FIREBASE_DEFAULTS__ or a JSON file whose path is in
653
- * process.env.__FIREBASE_DEFAULTS_PATH__
511
+ * process(.)env(.)__FIREBASE_DEFAULTS__ or a JSON file whose path is in
512
+ * process(.)env(.)__FIREBASE_DEFAULTS_PATH__
513
+ * The dots are in parens because certain compilers (Vite?) cannot
514
+ * handle seeing that variable in comments.
515
+ * See https://github.com/firebase/firebase-js-sdk/issues/6838
654
516
  */
655
517
  var getDefaultsFromEnvVariable = function () {
656
518
  if (typeof process === 'undefined' || typeof process.env === 'undefined') {
@@ -682,6 +544,7 @@ var getDefaultsFromCookie = function () {
682
544
  * (1) if such an object exists as a property of `globalThis`
683
545
  * (2) if such an object was provided on a shell environment variable
684
546
  * (3) if such an object exists in a cookie
547
+ * @public
685
548
  */
686
549
  var getDefaults = function () {
687
550
  try {
@@ -696,7 +559,7 @@ var getDefaults = function () {
696
559
  * info instead of swallowing so we can find these unknown cases
697
560
  * and add paths for them if needed.
698
561
  */
699
- console.info("Unable to get __FIREBASE_DEFAULTS__ due to: " + e);
562
+ console.info("Unable to get __FIREBASE_DEFAULTS__ due to: ".concat(e));
700
563
  return;
701
564
  }
702
565
  };
@@ -720,7 +583,7 @@ var getDefaultEmulatorHostnameAndPort = function (productName) {
720
583
  }
721
584
  var separatorIndex = host.lastIndexOf(':'); // Finding the last since IPv6 addr also has colons.
722
585
  if (separatorIndex <= 0 || separatorIndex + 1 === host.length) {
723
- throw new Error("Invalid host " + host + " with no separate hostname and port!");
586
+ throw new Error("Invalid host ".concat(host, " with no separate hostname and port!"));
724
587
  }
725
588
  // eslint-disable-next-line no-restricted-globals
726
589
  var port = parseInt(host.substring(separatorIndex + 1), 10);
@@ -742,7 +605,7 @@ var getDefaultAppConfig = function () { var _a; return (_a = getDefaults()) ===
742
605
  * prefixed by "_")
743
606
  * @public
744
607
  */
745
- var getExperimentalSetting = function (name) { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a["_" + name]; };
608
+ var getExperimentalSetting = function (name) { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a["_".concat(name)]; };
746
609
 
747
610
  /**
748
611
  * @license
@@ -835,7 +698,7 @@ function createMockUserToken(token, projectId) {
835
698
  }
836
699
  var payload = tslib.__assign({
837
700
  // Set all required fields to decent defaults
838
- iss: "https://securetoken.google.com/" + project, aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
701
+ iss: "https://securetoken.google.com/".concat(project), aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
839
702
  sign_in_provider: 'custom',
840
703
  identities: {}
841
704
  } }, token);
@@ -848,6 +711,178 @@ function createMockUserToken(token, projectId) {
848
711
  ].join('.');
849
712
  }
850
713
 
714
+ /**
715
+ * @license
716
+ * Copyright 2017 Google LLC
717
+ *
718
+ * Licensed under the Apache License, Version 2.0 (the "License");
719
+ * you may not use this file except in compliance with the License.
720
+ * You may obtain a copy of the License at
721
+ *
722
+ * http://www.apache.org/licenses/LICENSE-2.0
723
+ *
724
+ * Unless required by applicable law or agreed to in writing, software
725
+ * distributed under the License is distributed on an "AS IS" BASIS,
726
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
727
+ * See the License for the specific language governing permissions and
728
+ * limitations under the License.
729
+ */
730
+ /**
731
+ * Returns navigator.userAgent string or '' if it's not defined.
732
+ * @return user agent string
733
+ */
734
+ function getUA() {
735
+ if (typeof navigator !== 'undefined' &&
736
+ typeof navigator['userAgent'] === 'string') {
737
+ return navigator['userAgent'];
738
+ }
739
+ else {
740
+ return '';
741
+ }
742
+ }
743
+ /**
744
+ * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
745
+ *
746
+ * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
747
+ * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
748
+ * wait for a callback.
749
+ */
750
+ function isMobileCordova() {
751
+ return (typeof window !== 'undefined' &&
752
+ // @ts-ignore Setting up an broadly applicable index signature for Window
753
+ // just to deal with this case would probably be a bad idea.
754
+ !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
755
+ /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
756
+ }
757
+ /**
758
+ * Detect Node.js.
759
+ *
760
+ * @return true if Node.js environment is detected or specified.
761
+ */
762
+ // Node detection logic from: https://github.com/iliakan/detect-node/
763
+ function isNode() {
764
+ var _a;
765
+ var forceEnvironment = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.forceEnvironment;
766
+ if (forceEnvironment === 'node') {
767
+ return true;
768
+ }
769
+ else if (forceEnvironment === 'browser') {
770
+ return false;
771
+ }
772
+ try {
773
+ return (Object.prototype.toString.call(global.process) === '[object process]');
774
+ }
775
+ catch (e) {
776
+ return false;
777
+ }
778
+ }
779
+ /**
780
+ * Detect Browser Environment
781
+ */
782
+ function isBrowser() {
783
+ return typeof self === 'object' && self.self === self;
784
+ }
785
+ function isBrowserExtension() {
786
+ var runtime = typeof chrome === 'object'
787
+ ? chrome.runtime
788
+ : typeof browser === 'object'
789
+ ? browser.runtime
790
+ : undefined;
791
+ return typeof runtime === 'object' && runtime.id !== undefined;
792
+ }
793
+ /**
794
+ * Detect React Native.
795
+ *
796
+ * @return true if ReactNative environment is detected.
797
+ */
798
+ function isReactNative() {
799
+ return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
800
+ }
801
+ /** Detects Electron apps. */
802
+ function isElectron() {
803
+ return getUA().indexOf('Electron/') >= 0;
804
+ }
805
+ /** Detects Internet Explorer. */
806
+ function isIE() {
807
+ var ua = getUA();
808
+ return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
809
+ }
810
+ /** Detects Universal Windows Platform apps. */
811
+ function isUWP() {
812
+ return getUA().indexOf('MSAppHost/') >= 0;
813
+ }
814
+ /**
815
+ * Detect whether the current SDK build is the Node version.
816
+ *
817
+ * @return true if it's the Node SDK build.
818
+ */
819
+ function isNodeSdk() {
820
+ return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
821
+ }
822
+ /** Returns true if we are running in Safari. */
823
+ function isSafari() {
824
+ return (!isNode() &&
825
+ navigator.userAgent.includes('Safari') &&
826
+ !navigator.userAgent.includes('Chrome'));
827
+ }
828
+ /**
829
+ * This method checks if indexedDB is supported by current browser/service worker context
830
+ * @return true if indexedDB is supported by current browser/service worker context
831
+ */
832
+ function isIndexedDBAvailable() {
833
+ try {
834
+ return typeof indexedDB === 'object';
835
+ }
836
+ catch (e) {
837
+ return false;
838
+ }
839
+ }
840
+ /**
841
+ * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
842
+ * if errors occur during the database open operation.
843
+ *
844
+ * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
845
+ * private browsing)
846
+ */
847
+ function validateIndexedDBOpenable() {
848
+ return new Promise(function (resolve, reject) {
849
+ try {
850
+ var preExist_1 = true;
851
+ var DB_CHECK_NAME_1 = 'validate-browser-context-for-indexeddb-analytics-module';
852
+ var request_1 = self.indexedDB.open(DB_CHECK_NAME_1);
853
+ request_1.onsuccess = function () {
854
+ request_1.result.close();
855
+ // delete database only when it doesn't pre-exist
856
+ if (!preExist_1) {
857
+ self.indexedDB.deleteDatabase(DB_CHECK_NAME_1);
858
+ }
859
+ resolve(true);
860
+ };
861
+ request_1.onupgradeneeded = function () {
862
+ preExist_1 = false;
863
+ };
864
+ request_1.onerror = function () {
865
+ var _a;
866
+ reject(((_a = request_1.error) === null || _a === void 0 ? void 0 : _a.message) || '');
867
+ };
868
+ }
869
+ catch (error) {
870
+ reject(error);
871
+ }
872
+ });
873
+ }
874
+ /**
875
+ *
876
+ * This method checks whether cookie is enabled within current browser
877
+ * @return true if cookie is enabled within current browser
878
+ */
879
+ function areCookiesEnabled() {
880
+ if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
881
+ return false;
882
+ }
883
+ return true;
884
+ }
885
+
851
886
  /**
852
887
  * @license
853
888
  * Copyright 2017 Google LLC
@@ -903,11 +938,11 @@ var ErrorFactory = /** @class */ (function () {
903
938
  data[_i - 1] = arguments[_i];
904
939
  }
905
940
  var customData = data[0] || {};
906
- var fullCode = this.service + "/" + code;
941
+ var fullCode = "".concat(this.service, "/").concat(code);
907
942
  var template = this.errors[code];
908
943
  var message = template ? replaceTemplate(template, customData) : 'Error';
909
944
  // Service Name: Error message (service/code).
910
- var fullMessage = this.serviceName + ": " + message + " (" + fullCode + ").";
945
+ var fullMessage = "".concat(this.serviceName, ": ").concat(message, " (").concat(fullCode, ").");
911
946
  var error = new FirebaseError(fullCode, fullMessage, customData);
912
947
  return error;
913
948
  };
@@ -916,7 +951,7 @@ var ErrorFactory = /** @class */ (function () {
916
951
  function replaceTemplate(template, data) {
917
952
  return template.replace(PATTERN, function (_, key) {
918
953
  var value = data[key];
919
- return value != null ? String(value) : "<" + key + "?>";
954
+ return value != null ? String(value) : "<".concat(key, "?>");
920
955
  });
921
956
  }
922
957
  var PATTERN = /\{\$([^}]+)}/g;
@@ -1773,7 +1808,7 @@ var validateArgCount = function (fnName, minCount, maxCount, argCount) {
1773
1808
  * @return The prefix to add to the error thrown for validation.
1774
1809
  */
1775
1810
  function errorPrefix(fnName, argName) {
1776
- return fnName + " failed: " + argName + " argument ";
1811
+ return "".concat(fnName, " failed: ").concat(argName, " argument ");
1777
1812
  }
1778
1813
  /**
1779
1814
  * @param fnName
@@ -2015,7 +2050,7 @@ function calculateBackoffMillis(backoffCount, intervalMillis, backoffFactor) {
2015
2050
  */
2016
2051
  function ordinal(i) {
2017
2052
  if (!Number.isFinite(i)) {
2018
- return "" + i;
2053
+ return "".concat(i);
2019
2054
  }
2020
2055
  return i + indicator(i);
2021
2056
  }
@@ -2110,6 +2145,7 @@ exports.extractQuerystring = extractQuerystring;
2110
2145
  exports.getDefaultAppConfig = getDefaultAppConfig;
2111
2146
  exports.getDefaultEmulatorHost = getDefaultEmulatorHost;
2112
2147
  exports.getDefaultEmulatorHostnameAndPort = getDefaultEmulatorHostnameAndPort;
2148
+ exports.getDefaults = getDefaults;
2113
2149
  exports.getExperimentalSetting = getExperimentalSetting;
2114
2150
  exports.getGlobal = getGlobal;
2115
2151
  exports.getModularInstance = getModularInstance;