@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.
@@ -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
  });
@@ -2214,6 +2300,7 @@ exports.issuedAtTime = issuedAtTime;
2214
2300
  exports.jsonEval = jsonEval;
2215
2301
  exports.map = map;
2216
2302
  exports.ordinal = ordinal;
2303
+ exports.pingServer = pingServer;
2217
2304
  exports.promiseWithTimeout = promiseWithTimeout;
2218
2305
  exports.querystring = querystring;
2219
2306
  exports.querystringDecode = querystringDecode;
@@ -2221,7 +2308,7 @@ exports.safeGet = safeGet;
2221
2308
  exports.stringLength = stringLength;
2222
2309
  exports.stringToByteArray = stringToByteArray;
2223
2310
  exports.stringify = stringify;
2224
- exports.testConnectionAlive = testConnectionAlive;
2311
+ exports.updateEmulatorBanner = updateEmulatorBanner;
2225
2312
  exports.validateArgCount = validateArgCount;
2226
2313
  exports.validateCallback = validateCallback;
2227
2314
  exports.validateContextObject = validateContextObject;