@firebase/util 1.8.0 → 1.9.0-canary.27b5e7d70

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @firebase/util
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`06dc1364d`](https://github.com/firebase/firebase-js-sdk/commit/06dc1364d7560f4c563e1ccc89af9cad4cd91df8) [#6901](https://github.com/firebase/firebase-js-sdk/pull/6901) - Allow users to specify their environment as `node` or `browser` to override Firebase's runtime environment detection and force the SDK to act as if it were in the respective environment.
8
+
9
+ ### Patch Changes
10
+
11
+ - [`d4114a4f7`](https://github.com/firebase/firebase-js-sdk/commit/d4114a4f7da3f469c0c900416ac8beee58885ec3) [#6874](https://github.com/firebase/firebase-js-sdk/pull/6874) (fixes [#6838](https://github.com/firebase/firebase-js-sdk/issues/6838)) - Reformat a comment that causes compile errors in some build toolchains.
12
+
3
13
  ## 1.8.0
4
14
 
5
15
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -36,3 +36,4 @@ export * from './src/uuid';
36
36
  export * from './src/exponential_backoff';
37
37
  export * from './src/formatters';
38
38
  export * from './src/compat';
39
+ export * from './src/global';
@@ -449,7 +449,7 @@ function isValidKey(key) {
449
449
 
450
450
  /**
451
451
  * @license
452
- * Copyright 2017 Google LLC
452
+ * Copyright 2022 Google LLC
453
453
  *
454
454
  * Licensed under the Apache License, Version 2.0 (the "License");
455
455
  * you may not use this file except in compliance with the License.
@@ -463,156 +463,10 @@ function isValidKey(key) {
463
463
  * See the License for the specific language governing permissions and
464
464
  * limitations under the License.
465
465
  */
466
- /**
467
- * Returns navigator.userAgent string or '' if it's not defined.
468
- * @return user agent string
469
- */
470
- function getUA() {
471
- if (typeof navigator !== 'undefined' &&
472
- typeof navigator['userAgent'] === 'string') {
473
- return navigator['userAgent'];
474
- }
475
- else {
476
- return '';
477
- }
478
- }
479
- /**
480
- * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
481
- *
482
- * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
483
- * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
484
- * wait for a callback.
485
- */
486
- function isMobileCordova() {
487
- return (typeof window !== 'undefined' &&
488
- // @ts-ignore Setting up an broadly applicable index signature for Window
489
- // just to deal with this case would probably be a bad idea.
490
- !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
491
- /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
492
- }
493
- /**
494
- * Detect Node.js.
495
- *
496
- * @return true if Node.js environment is detected.
497
- */
498
- // Node detection logic from: https://github.com/iliakan/detect-node/
499
- function isNode() {
500
- try {
501
- return (Object.prototype.toString.call(global.process) === '[object process]');
502
- }
503
- catch (e) {
504
- return false;
505
- }
506
- }
507
- /**
508
- * Detect Browser Environment
509
- */
510
- function isBrowser() {
511
- return typeof self === 'object' && self.self === self;
512
- }
513
- function isBrowserExtension() {
514
- const runtime = typeof chrome === 'object'
515
- ? chrome.runtime
516
- : typeof browser === 'object'
517
- ? browser.runtime
518
- : undefined;
519
- return typeof runtime === 'object' && runtime.id !== undefined;
520
- }
521
- /**
522
- * Detect React Native.
523
- *
524
- * @return true if ReactNative environment is detected.
525
- */
526
- function isReactNative() {
527
- return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
528
- }
529
- /** Detects Electron apps. */
530
- function isElectron() {
531
- return getUA().indexOf('Electron/') >= 0;
532
- }
533
- /** Detects Internet Explorer. */
534
- function isIE() {
535
- const ua = getUA();
536
- return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
537
- }
538
- /** Detects Universal Windows Platform apps. */
539
- function isUWP() {
540
- return getUA().indexOf('MSAppHost/') >= 0;
541
- }
542
- /**
543
- * Detect whether the current SDK build is the Node version.
544
- *
545
- * @return true if it's the Node SDK build.
546
- */
547
- function isNodeSdk() {
548
- return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
549
- }
550
- /** Returns true if we are running in Safari. */
551
- function isSafari() {
552
- return (!isNode() &&
553
- navigator.userAgent.includes('Safari') &&
554
- !navigator.userAgent.includes('Chrome'));
555
- }
556
- /**
557
- * This method checks if indexedDB is supported by current browser/service worker context
558
- * @return true if indexedDB is supported by current browser/service worker context
559
- */
560
- function isIndexedDBAvailable() {
561
- try {
562
- return typeof indexedDB === 'object';
563
- }
564
- catch (e) {
565
- return false;
566
- }
567
- }
568
- /**
569
- * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
570
- * if errors occur during the database open operation.
571
- *
572
- * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
573
- * private browsing)
574
- */
575
- function validateIndexedDBOpenable() {
576
- return new Promise((resolve, reject) => {
577
- try {
578
- let preExist = true;
579
- const DB_CHECK_NAME = 'validate-browser-context-for-indexeddb-analytics-module';
580
- const request = self.indexedDB.open(DB_CHECK_NAME);
581
- request.onsuccess = () => {
582
- request.result.close();
583
- // delete database only when it doesn't pre-exist
584
- if (!preExist) {
585
- self.indexedDB.deleteDatabase(DB_CHECK_NAME);
586
- }
587
- resolve(true);
588
- };
589
- request.onupgradeneeded = () => {
590
- preExist = false;
591
- };
592
- request.onerror = () => {
593
- var _a;
594
- reject(((_a = request.error) === null || _a === void 0 ? void 0 : _a.message) || '');
595
- };
596
- }
597
- catch (error) {
598
- reject(error);
599
- }
600
- });
601
- }
602
- /**
603
- *
604
- * This method checks whether cookie is enabled within current browser
605
- * @return true if cookie is enabled within current browser
606
- */
607
- function areCookiesEnabled() {
608
- if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
609
- return false;
610
- }
611
- return true;
612
- }
613
466
  /**
614
467
  * Polyfill for `globalThis` object.
615
468
  * @returns the `globalThis` object for the given environment.
469
+ * @public
616
470
  */
617
471
  function getGlobal() {
618
472
  if (typeof self !== 'undefined') {
@@ -646,8 +500,11 @@ function getGlobal() {
646
500
  const getDefaultsFromGlobal = () => getGlobal().__FIREBASE_DEFAULTS__;
647
501
  /**
648
502
  * Attempt to read defaults from a JSON string provided to
649
- * process.env.__FIREBASE_DEFAULTS__ or a JSON file whose path is in
650
- * process.env.__FIREBASE_DEFAULTS_PATH__
503
+ * process(.)env(.)__FIREBASE_DEFAULTS__ or a JSON file whose path is in
504
+ * process(.)env(.)__FIREBASE_DEFAULTS_PATH__
505
+ * The dots are in parens because certain compilers (Vite?) cannot
506
+ * handle seeing that variable in comments.
507
+ * See https://github.com/firebase/firebase-js-sdk/issues/6838
651
508
  */
652
509
  const getDefaultsFromEnvVariable = () => {
653
510
  if (typeof process === 'undefined' || typeof process.env === 'undefined') {
@@ -679,6 +536,7 @@ const getDefaultsFromCookie = () => {
679
536
  * (1) if such an object exists as a property of `globalThis`
680
537
  * (2) if such an object was provided on a shell environment variable
681
538
  * (3) if such an object exists in a cookie
539
+ * @public
682
540
  */
683
541
  const getDefaults = () => {
684
542
  try {
@@ -842,6 +700,178 @@ function createMockUserToken(token, projectId) {
842
700
  ].join('.');
843
701
  }
844
702
 
703
+ /**
704
+ * @license
705
+ * Copyright 2017 Google LLC
706
+ *
707
+ * Licensed under the Apache License, Version 2.0 (the "License");
708
+ * you may not use this file except in compliance with the License.
709
+ * You may obtain a copy of the License at
710
+ *
711
+ * http://www.apache.org/licenses/LICENSE-2.0
712
+ *
713
+ * Unless required by applicable law or agreed to in writing, software
714
+ * distributed under the License is distributed on an "AS IS" BASIS,
715
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
716
+ * See the License for the specific language governing permissions and
717
+ * limitations under the License.
718
+ */
719
+ /**
720
+ * Returns navigator.userAgent string or '' if it's not defined.
721
+ * @return user agent string
722
+ */
723
+ function getUA() {
724
+ if (typeof navigator !== 'undefined' &&
725
+ typeof navigator['userAgent'] === 'string') {
726
+ return navigator['userAgent'];
727
+ }
728
+ else {
729
+ return '';
730
+ }
731
+ }
732
+ /**
733
+ * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
734
+ *
735
+ * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
736
+ * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
737
+ * wait for a callback.
738
+ */
739
+ function isMobileCordova() {
740
+ return (typeof window !== 'undefined' &&
741
+ // @ts-ignore Setting up an broadly applicable index signature for Window
742
+ // just to deal with this case would probably be a bad idea.
743
+ !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) &&
744
+ /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA()));
745
+ }
746
+ /**
747
+ * Detect Node.js.
748
+ *
749
+ * @return true if Node.js environment is detected or specified.
750
+ */
751
+ // Node detection logic from: https://github.com/iliakan/detect-node/
752
+ function isNode() {
753
+ var _a;
754
+ const forceEnvironment = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.forceEnvironment;
755
+ if (forceEnvironment === 'node') {
756
+ return true;
757
+ }
758
+ else if (forceEnvironment === 'browser') {
759
+ return false;
760
+ }
761
+ try {
762
+ return (Object.prototype.toString.call(global.process) === '[object process]');
763
+ }
764
+ catch (e) {
765
+ return false;
766
+ }
767
+ }
768
+ /**
769
+ * Detect Browser Environment
770
+ */
771
+ function isBrowser() {
772
+ return typeof self === 'object' && self.self === self;
773
+ }
774
+ function isBrowserExtension() {
775
+ const runtime = typeof chrome === 'object'
776
+ ? chrome.runtime
777
+ : typeof browser === 'object'
778
+ ? browser.runtime
779
+ : undefined;
780
+ return typeof runtime === 'object' && runtime.id !== undefined;
781
+ }
782
+ /**
783
+ * Detect React Native.
784
+ *
785
+ * @return true if ReactNative environment is detected.
786
+ */
787
+ function isReactNative() {
788
+ return (typeof navigator === 'object' && navigator['product'] === 'ReactNative');
789
+ }
790
+ /** Detects Electron apps. */
791
+ function isElectron() {
792
+ return getUA().indexOf('Electron/') >= 0;
793
+ }
794
+ /** Detects Internet Explorer. */
795
+ function isIE() {
796
+ const ua = getUA();
797
+ return ua.indexOf('MSIE ') >= 0 || ua.indexOf('Trident/') >= 0;
798
+ }
799
+ /** Detects Universal Windows Platform apps. */
800
+ function isUWP() {
801
+ return getUA().indexOf('MSAppHost/') >= 0;
802
+ }
803
+ /**
804
+ * Detect whether the current SDK build is the Node version.
805
+ *
806
+ * @return true if it's the Node SDK build.
807
+ */
808
+ function isNodeSdk() {
809
+ return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
810
+ }
811
+ /** Returns true if we are running in Safari. */
812
+ function isSafari() {
813
+ return (!isNode() &&
814
+ navigator.userAgent.includes('Safari') &&
815
+ !navigator.userAgent.includes('Chrome'));
816
+ }
817
+ /**
818
+ * This method checks if indexedDB is supported by current browser/service worker context
819
+ * @return true if indexedDB is supported by current browser/service worker context
820
+ */
821
+ function isIndexedDBAvailable() {
822
+ try {
823
+ return typeof indexedDB === 'object';
824
+ }
825
+ catch (e) {
826
+ return false;
827
+ }
828
+ }
829
+ /**
830
+ * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
831
+ * if errors occur during the database open operation.
832
+ *
833
+ * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
834
+ * private browsing)
835
+ */
836
+ function validateIndexedDBOpenable() {
837
+ return new Promise((resolve, reject) => {
838
+ try {
839
+ let preExist = true;
840
+ const DB_CHECK_NAME = 'validate-browser-context-for-indexeddb-analytics-module';
841
+ const request = self.indexedDB.open(DB_CHECK_NAME);
842
+ request.onsuccess = () => {
843
+ request.result.close();
844
+ // delete database only when it doesn't pre-exist
845
+ if (!preExist) {
846
+ self.indexedDB.deleteDatabase(DB_CHECK_NAME);
847
+ }
848
+ resolve(true);
849
+ };
850
+ request.onupgradeneeded = () => {
851
+ preExist = false;
852
+ };
853
+ request.onerror = () => {
854
+ var _a;
855
+ reject(((_a = request.error) === null || _a === void 0 ? void 0 : _a.message) || '');
856
+ };
857
+ }
858
+ catch (error) {
859
+ reject(error);
860
+ }
861
+ });
862
+ }
863
+ /**
864
+ *
865
+ * This method checks whether cookie is enabled within current browser
866
+ * @return true if cookie is enabled within current browser
867
+ */
868
+ function areCookiesEnabled() {
869
+ if (typeof navigator === 'undefined' || !navigator.cookieEnabled) {
870
+ return false;
871
+ }
872
+ return true;
873
+ }
874
+
845
875
  /**
846
876
  * @license
847
877
  * Copyright 2017 Google LLC
@@ -2069,5 +2099,5 @@ function getModularInstance(service) {
2069
2099
  }
2070
2100
  }
2071
2101
 
2072
- export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getDefaultEmulatorHostnameAndPort, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
2102
+ export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getDefaultEmulatorHostnameAndPort, getDefaults, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
2073
2103
  //# sourceMappingURL=index.esm2017.js.map