@firebase/util 1.6.3 → 1.7.0-canary.03d1fabcb

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.
@@ -453,110 +453,6 @@ function isValidKey(key) {
453
453
  return key !== '__proto__';
454
454
  }
455
455
 
456
- /**
457
- * @license
458
- * Copyright 2017 Google LLC
459
- *
460
- * Licensed under the Apache License, Version 2.0 (the "License");
461
- * you may not use this file except in compliance with the License.
462
- * You may obtain a copy of the License at
463
- *
464
- * http://www.apache.org/licenses/LICENSE-2.0
465
- *
466
- * Unless required by applicable law or agreed to in writing, software
467
- * distributed under the License is distributed on an "AS IS" BASIS,
468
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
469
- * See the License for the specific language governing permissions and
470
- * limitations under the License.
471
- */
472
- var Deferred = /** @class */ (function () {
473
- function Deferred() {
474
- var _this = this;
475
- this.reject = function () { };
476
- this.resolve = function () { };
477
- this.promise = new Promise(function (resolve, reject) {
478
- _this.resolve = resolve;
479
- _this.reject = reject;
480
- });
481
- }
482
- /**
483
- * Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
484
- * invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
485
- * and returns a node-style callback which will resolve or reject the Deferred's promise.
486
- */
487
- Deferred.prototype.wrapCallback = function (callback) {
488
- var _this = this;
489
- return function (error, value) {
490
- if (error) {
491
- _this.reject(error);
492
- }
493
- else {
494
- _this.resolve(value);
495
- }
496
- if (typeof callback === 'function') {
497
- // Attaching noop handler just in case developer wasn't expecting
498
- // promises
499
- _this.promise.catch(function () { });
500
- // Some of our callbacks don't expect a value and our own tests
501
- // assert that the parameter length is 1
502
- if (callback.length === 1) {
503
- callback(error);
504
- }
505
- else {
506
- callback(error, value);
507
- }
508
- }
509
- };
510
- };
511
- return Deferred;
512
- }());
513
-
514
- /**
515
- * @license
516
- * Copyright 2021 Google LLC
517
- *
518
- * Licensed under the Apache License, Version 2.0 (the "License");
519
- * you may not use this file except in compliance with the License.
520
- * You may obtain a copy of the License at
521
- *
522
- * http://www.apache.org/licenses/LICENSE-2.0
523
- *
524
- * Unless required by applicable law or agreed to in writing, software
525
- * distributed under the License is distributed on an "AS IS" BASIS,
526
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
527
- * See the License for the specific language governing permissions and
528
- * limitations under the License.
529
- */
530
- function createMockUserToken(token, projectId) {
531
- if (token.uid) {
532
- throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
533
- }
534
- // Unsecured JWTs use "none" as the algorithm.
535
- var header = {
536
- alg: 'none',
537
- type: 'JWT'
538
- };
539
- var project = projectId || 'demo-project';
540
- var iat = token.iat || 0;
541
- var sub = token.sub || token.user_id;
542
- if (!sub) {
543
- throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
544
- }
545
- var payload = tslib.__assign({
546
- // Set all required fields to decent defaults
547
- iss: "https://securetoken.google.com/" + project, aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
548
- sign_in_provider: 'custom',
549
- identities: {}
550
- } }, token);
551
- // Unsecured JWTs use the empty string as a signature.
552
- var signature = '';
553
- return [
554
- base64urlEncodeWithoutPadding(JSON.stringify(header)),
555
- base64urlEncodeWithoutPadding(JSON.stringify(payload)),
556
- signature
557
- ].join('.');
558
- }
559
-
560
456
  /**
561
457
  * @license
562
458
  * Copyright 2017 Google LLC
@@ -732,6 +628,206 @@ function getGlobal() {
732
628
  throw new Error('Unable to locate global object.');
733
629
  }
734
630
 
631
+ /**
632
+ * @license
633
+ * Copyright 2022 Google LLC
634
+ *
635
+ * Licensed under the Apache License, Version 2.0 (the "License");
636
+ * you may not use this file except in compliance with the License.
637
+ * You may obtain a copy of the License at
638
+ *
639
+ * http://www.apache.org/licenses/LICENSE-2.0
640
+ *
641
+ * Unless required by applicable law or agreed to in writing, software
642
+ * distributed under the License is distributed on an "AS IS" BASIS,
643
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
644
+ * See the License for the specific language governing permissions and
645
+ * limitations under the License.
646
+ */
647
+ var getDefaultsFromGlobal = function () {
648
+ return getGlobal().__FIREBASE_DEFAULTS__;
649
+ };
650
+ /**
651
+ * 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__
654
+ */
655
+ var getDefaultsFromEnvVariable = function () {
656
+ if (typeof process === 'undefined' || typeof process.env === 'undefined') {
657
+ return;
658
+ }
659
+ var defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
660
+ if (defaultsJsonString) {
661
+ return JSON.parse(defaultsJsonString);
662
+ }
663
+ };
664
+ var getDefaultsFromCookie = function () {
665
+ if (typeof document === 'undefined') {
666
+ return;
667
+ }
668
+ var match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
669
+ var decoded = match && base64Decode(match[1]);
670
+ return decoded && JSON.parse(decoded);
671
+ };
672
+ /**
673
+ * Get the __FIREBASE_DEFAULTS__ object. It checks in order:
674
+ * (1) if such an object exists as a property of `globalThis`
675
+ * (2) if such an object was provided on a shell environment variable
676
+ * (3) if such an object exists in a cookie
677
+ */
678
+ var getDefaults = function () {
679
+ return getDefaultsFromGlobal() ||
680
+ getDefaultsFromEnvVariable() ||
681
+ getDefaultsFromCookie();
682
+ };
683
+ /**
684
+ * Returns emulator host stored in the __FIREBASE_DEFAULTS__ object
685
+ * for the given product.
686
+ * @returns a URL host formatted like `127.0.0.1:9999` or `[::1]:4000` if available
687
+ * @public
688
+ */
689
+ var getDefaultEmulatorHost = function (productName) { var _a, _b; return (_b = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.emulatorHosts) === null || _b === void 0 ? void 0 : _b[productName]; };
690
+ /**
691
+ * Returns emulator hostname and port stored in the __FIREBASE_DEFAULTS__ object
692
+ * for the given product.
693
+ * @returns a pair of hostname and port like `["::1", 4000]` if available
694
+ * @public
695
+ */
696
+ var getDefaultEmulatorHostnameAndPort = function (productName) {
697
+ var host = getDefaultEmulatorHost(productName);
698
+ if (!host) {
699
+ return undefined;
700
+ }
701
+ var separatorIndex = host.lastIndexOf(':'); // Finding the last since IPv6 addr also has colons.
702
+ if (separatorIndex <= 0 || separatorIndex + 1 === host.length) {
703
+ throw new Error("Invalid host " + host + " with no separate hostname and port!");
704
+ }
705
+ // eslint-disable-next-line no-restricted-globals
706
+ var port = parseInt(host.substring(separatorIndex + 1), 10);
707
+ if (host[0] === '[') {
708
+ // Bracket-quoted `[ipv6addr]:port` => return "ipv6addr" (without brackets).
709
+ return [host.substring(1, separatorIndex - 1), port];
710
+ }
711
+ else {
712
+ return [host.substring(0, separatorIndex), port];
713
+ }
714
+ };
715
+ /**
716
+ * Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
717
+ * @public
718
+ */
719
+ var getDefaultAppConfig = function () { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
720
+ /**
721
+ * Returns an experimental setting on the __FIREBASE_DEFAULTS__ object (properties
722
+ * prefixed by "_")
723
+ * @public
724
+ */
725
+ var getExperimentalSetting = function (name) { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a["_" + name]; };
726
+
727
+ /**
728
+ * @license
729
+ * Copyright 2017 Google LLC
730
+ *
731
+ * Licensed under the Apache License, Version 2.0 (the "License");
732
+ * you may not use this file except in compliance with the License.
733
+ * You may obtain a copy of the License at
734
+ *
735
+ * http://www.apache.org/licenses/LICENSE-2.0
736
+ *
737
+ * Unless required by applicable law or agreed to in writing, software
738
+ * distributed under the License is distributed on an "AS IS" BASIS,
739
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
740
+ * See the License for the specific language governing permissions and
741
+ * limitations under the License.
742
+ */
743
+ var Deferred = /** @class */ (function () {
744
+ function Deferred() {
745
+ var _this = this;
746
+ this.reject = function () { };
747
+ this.resolve = function () { };
748
+ this.promise = new Promise(function (resolve, reject) {
749
+ _this.resolve = resolve;
750
+ _this.reject = reject;
751
+ });
752
+ }
753
+ /**
754
+ * Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
755
+ * invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
756
+ * and returns a node-style callback which will resolve or reject the Deferred's promise.
757
+ */
758
+ Deferred.prototype.wrapCallback = function (callback) {
759
+ var _this = this;
760
+ return function (error, value) {
761
+ if (error) {
762
+ _this.reject(error);
763
+ }
764
+ else {
765
+ _this.resolve(value);
766
+ }
767
+ if (typeof callback === 'function') {
768
+ // Attaching noop handler just in case developer wasn't expecting
769
+ // promises
770
+ _this.promise.catch(function () { });
771
+ // Some of our callbacks don't expect a value and our own tests
772
+ // assert that the parameter length is 1
773
+ if (callback.length === 1) {
774
+ callback(error);
775
+ }
776
+ else {
777
+ callback(error, value);
778
+ }
779
+ }
780
+ };
781
+ };
782
+ return Deferred;
783
+ }());
784
+
785
+ /**
786
+ * @license
787
+ * Copyright 2021 Google LLC
788
+ *
789
+ * Licensed under the Apache License, Version 2.0 (the "License");
790
+ * you may not use this file except in compliance with the License.
791
+ * You may obtain a copy of the License at
792
+ *
793
+ * http://www.apache.org/licenses/LICENSE-2.0
794
+ *
795
+ * Unless required by applicable law or agreed to in writing, software
796
+ * distributed under the License is distributed on an "AS IS" BASIS,
797
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
798
+ * See the License for the specific language governing permissions and
799
+ * limitations under the License.
800
+ */
801
+ function createMockUserToken(token, projectId) {
802
+ if (token.uid) {
803
+ throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
804
+ }
805
+ // Unsecured JWTs use "none" as the algorithm.
806
+ var header = {
807
+ alg: 'none',
808
+ type: 'JWT'
809
+ };
810
+ var project = projectId || 'demo-project';
811
+ var iat = token.iat || 0;
812
+ var sub = token.sub || token.user_id;
813
+ if (!sub) {
814
+ throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
815
+ }
816
+ var payload = tslib.__assign({
817
+ // Set all required fields to decent defaults
818
+ iss: "https://securetoken.google.com/" + project, aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
819
+ sign_in_provider: 'custom',
820
+ identities: {}
821
+ } }, token);
822
+ // Unsecured JWTs use the empty string as a signature.
823
+ var signature = '';
824
+ return [
825
+ base64urlEncodeWithoutPadding(JSON.stringify(header)),
826
+ base64urlEncodeWithoutPadding(JSON.stringify(payload)),
827
+ signature
828
+ ].join('.');
829
+ }
830
+
735
831
  /**
736
832
  * @license
737
833
  * Copyright 2017 Google LLC
@@ -1991,6 +2087,10 @@ exports.deepEqual = deepEqual;
1991
2087
  exports.deepExtend = deepExtend;
1992
2088
  exports.errorPrefix = errorPrefix;
1993
2089
  exports.extractQuerystring = extractQuerystring;
2090
+ exports.getDefaultAppConfig = getDefaultAppConfig;
2091
+ exports.getDefaultEmulatorHost = getDefaultEmulatorHost;
2092
+ exports.getDefaultEmulatorHostnameAndPort = getDefaultEmulatorHostnameAndPort;
2093
+ exports.getExperimentalSetting = getExperimentalSetting;
1994
2094
  exports.getGlobal = getGlobal;
1995
2095
  exports.getModularInstance = getModularInstance;
1996
2096
  exports.getUA = getUA;