@seliseblocks/genesis-os 4.4.0 → 4.4.1

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.
@@ -7091,8 +7091,24 @@ function Logo({
7091
7091
  ] });
7092
7092
  }
7093
7093
  var logicOrigin = () => chunkX4YCRWXO_cjs.getRuntimeEnv("BLOCKS_LOGIC_BASE_URL").trim().replace(/\/$/, "");
7094
+ var RETRY_DELAYS_MS = [2e3, 5e3, 15e3, 3e4];
7095
+ var STEADY_RETRY_MS = 6e4;
7096
+ var isLoggedOut = (error) => error?.status === 401;
7097
+ var hasHttpStatus = (error) => typeof error?.status === "number";
7098
+ var refreshLoginCall = async (probe) => {
7099
+ try {
7100
+ await probe;
7101
+ } catch (error) {
7102
+ if (isLoggedOut(error) || !hasHttpStatus(error)) throw error;
7103
+ }
7104
+ };
7094
7105
  var NotificationListenerService = class {
7095
7106
  connection;
7107
+ // True from connect() until disconnect(): the app wants the hub up.
7108
+ wanted = false;
7109
+ attempt = 0;
7110
+ timer;
7111
+ inFlight;
7096
7112
  constructor() {
7097
7113
  this.connection = new signalr.HubConnectionBuilder().withUrl(
7098
7114
  `${logicOrigin()}/api/NotificationHub?x-blocks-key=${chunkX4YCRWXO_cjs.getRuntimeEnv("BLOCKS_X_BLOCKS_KEY")}`,
@@ -7100,17 +7116,72 @@ var NotificationListenerService = class {
7100
7116
  transport: signalr.HttpTransportType.WebSockets
7101
7117
  }
7102
7118
  ).withAutomaticReconnect().build();
7119
+ this.connection.onclose(() => {
7120
+ if (this.wanted) this.recover(true);
7121
+ });
7103
7122
  }
7104
7123
  async connect() {
7105
- if (this.connection.state === "Disconnected") {
7106
- await this.connection.start();
7124
+ if (!this.wanted) {
7125
+ this.wanted = true;
7126
+ this.attempt = 0;
7127
+ globalThis.addEventListener("online", this.onWake);
7128
+ document.addEventListener("visibilitychange", this.onVisibility);
7107
7129
  }
7130
+ if (this.timer === void 0) await this.recover(false);
7108
7131
  }
7109
7132
  async disconnect() {
7133
+ this.wanted = false;
7134
+ this.stopWatching();
7110
7135
  if (this.connection.state !== "Disconnected") {
7111
7136
  await this.connection.stop();
7112
7137
  }
7113
7138
  }
7139
+ onWake = () => {
7140
+ if (this.wanted) this.recover(true);
7141
+ };
7142
+ onVisibility = () => {
7143
+ if (document.visibilityState === "visible") this.onWake();
7144
+ };
7145
+ stopWatching() {
7146
+ clearTimeout(this.timer);
7147
+ this.timer = void 0;
7148
+ globalThis.removeEventListener("online", this.onWake);
7149
+ document.removeEventListener("visibilitychange", this.onVisibility);
7150
+ }
7151
+ // Never two starts at once: callers share the run that is already going.
7152
+ recover(refreshLogin) {
7153
+ this.inFlight ??= this.tryStart(refreshLogin).finally(() => {
7154
+ this.inFlight = void 0;
7155
+ });
7156
+ return this.inFlight;
7157
+ }
7158
+ async tryStart(refreshLogin) {
7159
+ clearTimeout(this.timer);
7160
+ this.timer = void 0;
7161
+ if (!this.wanted || this.connection.state !== "Disconnected") return;
7162
+ if (refreshLogin && navigator.onLine === false) return;
7163
+ try {
7164
+ if (refreshLogin)
7165
+ await refreshLoginCall(chunkHBVSAOTQ_cjs.notificationService.getNotifications(1, 1));
7166
+ if (!this.wanted) return;
7167
+ await this.connection.start();
7168
+ this.attempt = 0;
7169
+ if (!this.wanted) await this.connection.stop();
7170
+ } catch (error) {
7171
+ if (!this.wanted) return;
7172
+ if (isLoggedOut(error)) {
7173
+ this.wanted = false;
7174
+ this.stopWatching();
7175
+ return;
7176
+ }
7177
+ this.scheduleRetry();
7178
+ }
7179
+ }
7180
+ scheduleRetry() {
7181
+ const delay = RETRY_DELAYS_MS[this.attempt] ?? STEADY_RETRY_MS;
7182
+ this.attempt += 1;
7183
+ this.timer = setTimeout(() => this.recover(true), delay);
7184
+ }
7114
7185
  };
7115
7186
  var notificationListenerService = new NotificationListenerService();
7116
7187
 
@@ -10691,6 +10762,16 @@ var ConsolePage = ({ canCreateProject = false }) => {
10691
10762
  ] })
10692
10763
  ] });
10693
10764
  };
10765
+ var toSafeAppPath = (value) => {
10766
+ if (!value || !value.startsWith("/")) return null;
10767
+ try {
10768
+ const target = new URL(value, window.location.origin);
10769
+ if (target.origin !== window.location.origin) return null;
10770
+ return target.href;
10771
+ } catch {
10772
+ return null;
10773
+ }
10774
+ };
10694
10775
  var CallbackPage = ({ defaultRedirectUrl }) => {
10695
10776
  const [searchParams] = reactRouter.useSearchParams();
10696
10777
  const hasProcessed = React8.useRef(false);
@@ -10706,7 +10787,7 @@ var CallbackPage = ({ defaultRedirectUrl }) => {
10706
10787
  const idpBaseUrl = window.process?.env.userBaseUrl;
10707
10788
  const callbackUrl = new URL(`${idpBaseUrl}/api/idp/callback`);
10708
10789
  const tenantId = window.process?.env.BLOCKS_X_BLOCKS_KEY;
10709
- const appRedirectUrl = forwardTo || defaultRedirectUrl || "/";
10790
+ const appRedirectUrl = toSafeAppPath(forwardTo) || defaultRedirectUrl || "/";
10710
10791
  if (code) callbackUrl.searchParams.set("code", code);
10711
10792
  if (state) callbackUrl.searchParams.set("state", state);
10712
10793
  if (error) callbackUrl.searchParams.set("error", error);
@@ -13834,5 +13915,5 @@ exports.usePaginationQueryParams = usePaginationQueryParams;
13834
13915
  exports.useRightSidePanel = useRightSidePanel;
13835
13916
  exports.useSortQueryParams = useSortQueryParams;
13836
13917
  exports.useWizardStepper = useWizardStepper;
13837
- //# sourceMappingURL=chunk-DXITHNQR.cjs.map
13838
- //# sourceMappingURL=chunk-DXITHNQR.cjs.map
13918
+ //# sourceMappingURL=chunk-GFGUKRBD.cjs.map
13919
+ //# sourceMappingURL=chunk-GFGUKRBD.cjs.map