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