@firebase/util 1.6.3 → 1.7.0

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,197 @@ 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') {
657
+ return;
658
+ }
659
+ var defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
660
+ var defaultsJsonPath = process.env.__FIREBASE_DEFAULTS_PATH__;
661
+ if (defaultsJsonString) {
662
+ if (defaultsJsonPath) {
663
+ console.warn("Values were provided for both __FIREBASE_DEFAULTS__ " +
664
+ "and __FIREBASE_DEFAULTS_PATH__. __FIREBASE_DEFAULTS_PATH__ " +
665
+ "will be ignored.");
666
+ }
667
+ return JSON.parse(defaultsJsonString);
668
+ }
669
+ if (defaultsJsonPath && typeof require !== 'undefined') {
670
+ try {
671
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
672
+ var json = require(defaultsJsonPath);
673
+ return json;
674
+ }
675
+ catch (e) {
676
+ console.warn("Unable to read defaults from file provided to " +
677
+ ("__FIREBASE_DEFAULTS_PATH__: " + defaultsJsonPath));
678
+ }
679
+ }
680
+ };
681
+ var getDefaultsFromCookie = function () {
682
+ if (typeof document === 'undefined') {
683
+ return;
684
+ }
685
+ var match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
686
+ var decoded = match && base64Decode(match[1]);
687
+ return decoded && JSON.parse(decoded);
688
+ };
689
+ /**
690
+ * Get the __FIREBASE_DEFAULTS__ object. It checks in order:
691
+ * (1) if such an object exists as a property of `globalThis`
692
+ * (2) if such an object was provided on a shell environment variable
693
+ * (3) if such an object exists in a cookie
694
+ */
695
+ var getDefaults = function () {
696
+ return getDefaultsFromGlobal() ||
697
+ getDefaultsFromEnvVariable() ||
698
+ getDefaultsFromCookie();
699
+ };
700
+ /**
701
+ * Returns emulator host stored in the __FIREBASE_DEFAULTS__ object
702
+ * for the given product.
703
+ * @public
704
+ */
705
+ 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]; };
706
+ /**
707
+ * Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
708
+ * @public
709
+ */
710
+ var getDefaultAppConfig = function () { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
711
+ /**
712
+ * Returns an experimental setting on the __FIREBASE_DEFAULTS__ object (properties
713
+ * prefixed by "_")
714
+ * @public
715
+ */
716
+ var getExperimentalSetting = function (name) { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a["_" + name]; };
717
+
718
+ /**
719
+ * @license
720
+ * Copyright 2017 Google LLC
721
+ *
722
+ * Licensed under the Apache License, Version 2.0 (the "License");
723
+ * you may not use this file except in compliance with the License.
724
+ * You may obtain a copy of the License at
725
+ *
726
+ * http://www.apache.org/licenses/LICENSE-2.0
727
+ *
728
+ * Unless required by applicable law or agreed to in writing, software
729
+ * distributed under the License is distributed on an "AS IS" BASIS,
730
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
731
+ * See the License for the specific language governing permissions and
732
+ * limitations under the License.
733
+ */
734
+ var Deferred = /** @class */ (function () {
735
+ function Deferred() {
736
+ var _this = this;
737
+ this.reject = function () { };
738
+ this.resolve = function () { };
739
+ this.promise = new Promise(function (resolve, reject) {
740
+ _this.resolve = resolve;
741
+ _this.reject = reject;
742
+ });
743
+ }
744
+ /**
745
+ * Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
746
+ * invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
747
+ * and returns a node-style callback which will resolve or reject the Deferred's promise.
748
+ */
749
+ Deferred.prototype.wrapCallback = function (callback) {
750
+ var _this = this;
751
+ return function (error, value) {
752
+ if (error) {
753
+ _this.reject(error);
754
+ }
755
+ else {
756
+ _this.resolve(value);
757
+ }
758
+ if (typeof callback === 'function') {
759
+ // Attaching noop handler just in case developer wasn't expecting
760
+ // promises
761
+ _this.promise.catch(function () { });
762
+ // Some of our callbacks don't expect a value and our own tests
763
+ // assert that the parameter length is 1
764
+ if (callback.length === 1) {
765
+ callback(error);
766
+ }
767
+ else {
768
+ callback(error, value);
769
+ }
770
+ }
771
+ };
772
+ };
773
+ return Deferred;
774
+ }());
775
+
776
+ /**
777
+ * @license
778
+ * Copyright 2021 Google LLC
779
+ *
780
+ * Licensed under the Apache License, Version 2.0 (the "License");
781
+ * you may not use this file except in compliance with the License.
782
+ * You may obtain a copy of the License at
783
+ *
784
+ * http://www.apache.org/licenses/LICENSE-2.0
785
+ *
786
+ * Unless required by applicable law or agreed to in writing, software
787
+ * distributed under the License is distributed on an "AS IS" BASIS,
788
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
789
+ * See the License for the specific language governing permissions and
790
+ * limitations under the License.
791
+ */
792
+ function createMockUserToken(token, projectId) {
793
+ if (token.uid) {
794
+ throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
795
+ }
796
+ // Unsecured JWTs use "none" as the algorithm.
797
+ var header = {
798
+ alg: 'none',
799
+ type: 'JWT'
800
+ };
801
+ var project = projectId || 'demo-project';
802
+ var iat = token.iat || 0;
803
+ var sub = token.sub || token.user_id;
804
+ if (!sub) {
805
+ throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
806
+ }
807
+ var payload = tslib.__assign({
808
+ // Set all required fields to decent defaults
809
+ iss: "https://securetoken.google.com/" + project, aud: project, iat: iat, exp: iat + 3600, auth_time: iat, sub: sub, user_id: sub, firebase: {
810
+ sign_in_provider: 'custom',
811
+ identities: {}
812
+ } }, token);
813
+ // Unsecured JWTs use the empty string as a signature.
814
+ var signature = '';
815
+ return [
816
+ base64urlEncodeWithoutPadding(JSON.stringify(header)),
817
+ base64urlEncodeWithoutPadding(JSON.stringify(payload)),
818
+ signature
819
+ ].join('.');
820
+ }
821
+
735
822
  /**
736
823
  * @license
737
824
  * Copyright 2017 Google LLC
@@ -1991,6 +2078,9 @@ exports.deepEqual = deepEqual;
1991
2078
  exports.deepExtend = deepExtend;
1992
2079
  exports.errorPrefix = errorPrefix;
1993
2080
  exports.extractQuerystring = extractQuerystring;
2081
+ exports.getDefaultAppConfig = getDefaultAppConfig;
2082
+ exports.getDefaultEmulatorHost = getDefaultEmulatorHost;
2083
+ exports.getExperimentalSetting = getExperimentalSetting;
1994
2084
  exports.getGlobal = getGlobal;
1995
2085
  exports.getModularInstance = getModularInstance;
1996
2086
  exports.getUA = getUA;