@firebase/util 1.11.0-firebase-studio-sdk-integration.226be0bb1 → 1.11.0-firebase-studio-sdk-integration.bffdabd70

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/dist/index.cjs.js CHANGED
@@ -716,6 +716,87 @@ function createMockUserToken(token, projectId) {
716
716
  signature
717
717
  ].join('.');
718
718
  }
719
+ const emulatorStatus = {};
720
+ // Checks whether any products are running on an emulator
721
+ function areRunningEmulator() {
722
+ let runningEmulator = false;
723
+ for (const key of Object.keys(emulatorStatus)) {
724
+ if (emulatorStatus[key]) {
725
+ runningEmulator = true;
726
+ }
727
+ }
728
+ return runningEmulator;
729
+ }
730
+ function getOrCreateEl(id) {
731
+ let parentDiv = document.getElementById(id);
732
+ let created = false;
733
+ if (!parentDiv) {
734
+ parentDiv = document.createElement('div');
735
+ parentDiv.setAttribute('id', id);
736
+ created = true;
737
+ }
738
+ return { created, element: parentDiv };
739
+ }
740
+ /**
741
+ * Updates Emulator Banner. Primarily used for Firebase Studio
742
+ * @param name
743
+ * @param isRunningEmulator
744
+ * @public
745
+ */
746
+ function updateEmulatorBanner(name, isRunningEmulator) {
747
+ if (typeof window === 'undefined' ||
748
+ typeof document === 'undefined' ||
749
+ emulatorStatus[name] === isRunningEmulator) {
750
+ return;
751
+ }
752
+ emulatorStatus[name] = isRunningEmulator;
753
+ const bannerId = '__firebase__banner';
754
+ if (!areRunningEmulator()) {
755
+ tearDown();
756
+ return;
757
+ }
758
+ function tearDown() {
759
+ const element = document.getElementById(bannerId);
760
+ if (element) {
761
+ element.remove();
762
+ }
763
+ }
764
+ function setupDom() {
765
+ const banner = getOrCreateEl(bannerId);
766
+ const firebaseText = document.getElementById('__firebase__text') ||
767
+ document.createElement('span');
768
+ if (banner.created) {
769
+ // update styles
770
+ const bannerEl = banner.element;
771
+ bannerEl.style.display = 'flex';
772
+ bannerEl.style.background = '#7faaf0';
773
+ bannerEl.style.position = 'absolute';
774
+ bannerEl.style.bottom = '5px';
775
+ bannerEl.style.left = '5px';
776
+ bannerEl.style.padding = '.5em';
777
+ bannerEl.style.borderRadius = '5px';
778
+ bannerEl.style.alignContent = 'center';
779
+ const closeBtn = document.createElement('span');
780
+ closeBtn.style.cursor = 'pointer';
781
+ closeBtn.style.paddingLeft = '5px';
782
+ closeBtn.innerHTML = ' ×';
783
+ closeBtn.onclick = () => {
784
+ tearDown();
785
+ };
786
+ bannerEl.appendChild(firebaseText);
787
+ bannerEl.appendChild(closeBtn);
788
+ document.body.appendChild(banner.element);
789
+ }
790
+ firebaseText.setAttribute('id', '__firebase__text');
791
+ firebaseText.innerText = 'Running in this workspace';
792
+ }
793
+ if (document.readyState === 'loading') {
794
+ window.addEventListener('DOMContentLoaded', setupDom);
795
+ }
796
+ else {
797
+ setupDom();
798
+ }
799
+ }
719
800
 
720
801
  /**
721
802
  * @license
@@ -2132,7 +2213,12 @@ function getModularInstance(service) {
2132
2213
  function isCloudWorkstation(host) {
2133
2214
  return host.endsWith('.cloudworkstations.dev');
2134
2215
  }
2135
- async function testConnectionAlive(endpoint) {
2216
+ /**
2217
+ * Makes a fetch request to the given server.
2218
+ * Mostly used for forwarding cookies in Firebase Studio.
2219
+ * @public
2220
+ */
2221
+ async function pingServer(endpoint) {
2136
2222
  const result = await fetch(endpoint, {
2137
2223
  credentials: 'include'
2138
2224
  });
@@ -2195,6 +2281,7 @@ exports.issuedAtTime = issuedAtTime;
2195
2281
  exports.jsonEval = jsonEval;
2196
2282
  exports.map = map;
2197
2283
  exports.ordinal = ordinal;
2284
+ exports.pingServer = pingServer;
2198
2285
  exports.promiseWithTimeout = promiseWithTimeout;
2199
2286
  exports.querystring = querystring;
2200
2287
  exports.querystringDecode = querystringDecode;
@@ -2202,7 +2289,7 @@ exports.safeGet = safeGet;
2202
2289
  exports.stringLength = stringLength;
2203
2290
  exports.stringToByteArray = stringToByteArray;
2204
2291
  exports.stringify = stringify;
2205
- exports.testConnectionAlive = testConnectionAlive;
2292
+ exports.updateEmulatorBanner = updateEmulatorBanner;
2206
2293
  exports.validateArgCount = validateArgCount;
2207
2294
  exports.validateCallback = validateCallback;
2208
2295
  exports.validateContextObject = validateContextObject;