@firebase/util 1.12.0 → 1.12.1-canary.25b60fdaa

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.
@@ -574,7 +574,7 @@ const getDefaults = () => {
574
574
  * @returns a URL host formatted like `127.0.0.1:9999` or `[::1]:4000` if available
575
575
  * @public
576
576
  */
577
- const getDefaultEmulatorHost = (productName) => { var _a, _b; return (_b = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.emulatorHosts) === null || _b === void 0 ? void 0 : _b[productName]; };
577
+ const getDefaultEmulatorHost = (productName) => getDefaults()?.emulatorHosts?.[productName];
578
578
  /**
579
579
  * Returns emulator hostname and port stored in the __FIREBASE_DEFAULTS__ object
580
580
  * for the given product.
@@ -604,13 +604,13 @@ const getDefaultEmulatorHostnameAndPort = (productName) => {
604
604
  * Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
605
605
  * @public
606
606
  */
607
- const getDefaultAppConfig = () => { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
607
+ const getDefaultAppConfig = () => getDefaults()?.config;
608
608
  /**
609
609
  * Returns an experimental setting on the __FIREBASE_DEFAULTS__ object (properties
610
610
  * prefixed by "_")
611
611
  * @public
612
612
  */
613
- const getExperimentalSetting = (name) => { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a[`_${name}`]; };
613
+ const getExperimentalSetting = (name) => getDefaults()?.[`_${name}`];
614
614
 
615
615
  /**
616
616
  * @license
@@ -687,8 +687,20 @@ class Deferred {
687
687
  * Checks whether host is a cloud workstation or not.
688
688
  * @public
689
689
  */
690
- function isCloudWorkstation(host) {
691
- return host.endsWith('.cloudworkstations.dev');
690
+ function isCloudWorkstation(url) {
691
+ // `isCloudWorkstation` is called without protocol in certain connect*Emulator functions
692
+ // In HTTP request builders, it's called with the protocol.
693
+ // If called with protocol prefix, it's a valid URL, so we extract the hostname
694
+ // If called without, we assume the string is the hostname.
695
+ try {
696
+ const host = url.startsWith('http://') || url.startsWith('https://')
697
+ ? new URL(url).hostname
698
+ : url;
699
+ return host.endsWith('.cloudworkstations.dev');
700
+ }
701
+ catch {
702
+ return false;
703
+ }
692
704
  }
693
705
  /**
694
706
  * Makes a fetch request to the given server.
@@ -733,12 +745,22 @@ function createMockUserToken(token, projectId) {
733
745
  if (!sub) {
734
746
  throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
735
747
  }
736
- const payload = Object.assign({
748
+ const payload = {
737
749
  // Set all required fields to decent defaults
738
- iss: `https://securetoken.google.com/${project}`, aud: project, iat, exp: iat + 3600, auth_time: iat, sub, user_id: sub, firebase: {
750
+ iss: `https://securetoken.google.com/${project}`,
751
+ aud: project,
752
+ iat,
753
+ exp: iat + 3600,
754
+ auth_time: iat,
755
+ sub,
756
+ user_id: sub,
757
+ firebase: {
739
758
  sign_in_provider: 'custom',
740
759
  identities: {}
741
- } }, token);
760
+ },
761
+ // Override with user options
762
+ ...token
763
+ };
742
764
  // Unsecured JWTs use the empty string as a signature.
743
765
  const signature = '';
744
766
  return [
@@ -944,8 +966,7 @@ function isMobileCordova() {
944
966
  */
945
967
  // Node detection logic from: https://github.com/iliakan/detect-node/
946
968
  function isNode() {
947
- var _a;
948
- const forceEnvironment = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.forceEnvironment;
969
+ const forceEnvironment = getDefaults()?.forceEnvironment;
949
970
  if (forceEnvironment === 'node') {
950
971
  return true;
951
972
  }
@@ -1072,8 +1093,7 @@ function validateIndexedDBOpenable() {
1072
1093
  preExist = false;
1073
1094
  };
1074
1095
  request.onerror = () => {
1075
- var _a;
1076
- reject(((_a = request.error) === null || _a === void 0 ? void 0 : _a.message) || '');
1096
+ reject(request.error?.message || '');
1077
1097
  };
1078
1098
  }
1079
1099
  catch (error) {