@hexclave/react 1.0.51 → 1.0.52

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.
Files changed (158) hide show
  1. package/dist/{admin-app-impl-DAQHCcD9.d.ts → admin-app-impl-CObFu26f.d.ts} +11 -8
  2. package/dist/{admin-app-impl-DAQHCcD9.d.ts.map → admin-app-impl-CObFu26f.d.ts.map} +1 -1
  3. package/dist/clickmap/clickmap-core.d.ts +1 -1
  4. package/dist/clickmap/index.d.ts +1 -1
  5. package/dist/{client-app-O21Ylb76.d.ts → client-app-DhFlsws7.d.ts} +2 -1
  6. package/dist/{client-app-O21Ylb76.d.ts.map → client-app-DhFlsws7.d.ts.map} +1 -1
  7. package/dist/common-BijZ0ocq.d.ts.map +1 -1
  8. package/dist/components/selected-team-switcher.d.ts +1 -1
  9. package/dist/components/team-icon.d.ts +1 -1
  10. package/dist/components/team-switcher.d.ts +1 -1
  11. package/dist/components-page/account-settings/payments/payments-page.d.ts +1 -1
  12. package/dist/components-page/account-settings/teams/leave-team-section.d.ts +1 -1
  13. package/dist/components-page/account-settings/teams/team-api-keys-section.d.ts +1 -1
  14. package/dist/components-page/account-settings/teams/team-display-name-section.d.ts +1 -1
  15. package/dist/components-page/account-settings/teams/team-member-invitation-section.d.ts +1 -1
  16. package/dist/components-page/account-settings/teams/team-member-list-section.d.ts +1 -1
  17. package/dist/components-page/account-settings/teams/team-page.d.ts +1 -1
  18. package/dist/components-page/account-settings/teams/team-profile-image-section.d.ts +1 -1
  19. package/dist/components-page/account-settings/teams/team-profile-user-section.d.ts +1 -1
  20. package/dist/components-page/hexclave-handler-client.d.ts +1 -1
  21. package/dist/components-page/hexclave-handler.d.ts +1 -1
  22. package/dist/components-page/sign-out.js +11 -2
  23. package/dist/components-page/sign-out.js.map +1 -1
  24. package/dist/components-page/sign-out.test.d.ts +1 -0
  25. package/dist/components-page/sign-out.test.js +157 -0
  26. package/dist/components-page/sign-out.test.js.map +1 -0
  27. package/dist/dev-tool/dev-tool-core.d.ts +1 -1
  28. package/dist/dev-tool/dev-tool-core.d.ts.map +1 -1
  29. package/dist/dev-tool/dev-tool-core.js +58 -28
  30. package/dist/dev-tool/dev-tool-core.js.map +1 -1
  31. package/dist/dev-tool/dev-tool-styles.js +35 -0
  32. package/dist/dev-tool/dev-tool-styles.js.map +1 -1
  33. package/dist/dev-tool/index.d.ts +1 -1
  34. package/dist/esm/components-page/sign-out.d.ts.map +1 -1
  35. package/dist/esm/components-page/sign-out.js +12 -3
  36. package/dist/esm/components-page/sign-out.js.map +1 -1
  37. package/dist/esm/components-page/sign-out.test.d.ts +1 -0
  38. package/dist/esm/components-page/sign-out.test.js +156 -0
  39. package/dist/esm/components-page/sign-out.test.js.map +1 -0
  40. package/dist/esm/dev-tool/dev-tool-core.d.ts.map +1 -1
  41. package/dist/esm/dev-tool/dev-tool-core.js +58 -28
  42. package/dist/esm/dev-tool/dev-tool-core.js.map +1 -1
  43. package/dist/esm/dev-tool/dev-tool-styles.js +35 -0
  44. package/dist/esm/dev-tool/dev-tool-styles.js.map +1 -1
  45. package/dist/esm/generated/global-css.d.ts +1 -1
  46. package/dist/esm/generated/global-css.js +1 -1
  47. package/dist/esm/generated/global-css.js.map +1 -1
  48. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +5 -4
  49. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  50. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +97 -0
  51. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  52. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +3 -2
  53. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  54. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js +26 -1
  55. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  56. package/dist/esm/lib/hexclave-app/apps/implementations/common.d.ts.map +1 -1
  57. package/dist/esm/lib/hexclave-app/apps/implementations/common.js +21 -4
  58. package/dist/esm/lib/hexclave-app/apps/implementations/common.js.map +1 -1
  59. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts +37 -0
  60. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts.map +1 -0
  61. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.js +89 -0
  62. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.js.map +1 -0
  63. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.test.d.ts +1 -0
  64. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.test.js +134 -0
  65. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-back-state.test.js.map +1 -0
  66. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.d.ts +8 -0
  67. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.d.ts.map +1 -0
  68. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.js +73 -0
  69. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.js.map +1 -0
  70. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.d.ts +1 -0
  71. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.js +92 -0
  72. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.js.map +1 -0
  73. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -0
  74. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.d.ts.map +1 -1
  75. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.js +27 -6
  76. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.js.map +1 -1
  77. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts +1 -0
  78. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts.map +1 -1
  79. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
  80. package/dist/esm/pushed-config-error-overlay/index.js +1 -1
  81. package/dist/esm/pushed-config-error-overlay/index.js.map +1 -1
  82. package/dist/esm/utils/session-storage.d.ts +12 -0
  83. package/dist/esm/utils/session-storage.d.ts.map +1 -0
  84. package/dist/esm/utils/session-storage.js +30 -0
  85. package/dist/esm/utils/session-storage.js.map +1 -0
  86. package/dist/generated/global-css.d.ts +1 -1
  87. package/dist/generated/global-css.js +1 -1
  88. package/dist/generated/global-css.js.map +1 -1
  89. package/dist/{hexclave-provider-DMSXFNp-.d.ts → hexclave-provider-C7c7GEpb.d.ts} +2 -2
  90. package/dist/{hexclave-provider-DMSXFNp-.d.ts.map → hexclave-provider-C7c7GEpb.d.ts.map} +1 -1
  91. package/dist/{hooks-UtbmjOdS.d.ts → hooks-BZQw1aT7.d.ts} +2 -2
  92. package/dist/{hooks-UtbmjOdS.d.ts.map → hooks-BZQw1aT7.d.ts.map} +1 -1
  93. package/dist/{index-C8Roh_o-.d.ts → index-6eQ0iUUE.d.ts} +2 -2
  94. package/dist/{index-C8Roh_o-.d.ts.map → index-6eQ0iUUE.d.ts.map} +1 -1
  95. package/dist/index.d.ts +4 -4
  96. package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -1
  97. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +97 -0
  98. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  99. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +1 -1
  100. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js +26 -1
  101. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  102. package/dist/lib/hexclave-app/apps/implementations/common.js +21 -4
  103. package/dist/lib/hexclave-app/apps/implementations/common.js.map +1 -1
  104. package/dist/lib/hexclave-app/apps/implementations/index.d.ts +1 -1
  105. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts +37 -0
  106. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.d.ts.map +1 -0
  107. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.js +92 -0
  108. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.js.map +1 -0
  109. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.test.d.ts +1 -0
  110. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.test.js +133 -0
  111. package/dist/lib/hexclave-app/apps/implementations/redirect-back-state.test.js.map +1 -0
  112. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.d.ts +8 -0
  113. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.d.ts.map +1 -0
  114. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.js +74 -0
  115. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.js.map +1 -0
  116. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.d.ts +1 -0
  117. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.js +91 -0
  118. package/dist/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.js.map +1 -0
  119. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
  120. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.js +27 -6
  121. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.js.map +1 -1
  122. package/dist/lib/hexclave-app/apps/index.d.ts +1 -1
  123. package/dist/lib/hexclave-app/apps/interfaces/admin-app.d.ts +1 -1
  124. package/dist/lib/hexclave-app/apps/interfaces/client-app.d.ts +1 -1
  125. package/dist/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
  126. package/dist/lib/hexclave-app/apps/interfaces/server-app.d.ts +1 -1
  127. package/dist/lib/hexclave-app/index.d.ts +1 -1
  128. package/dist/lib/hexclave-app/projects/index.d.ts +1 -1
  129. package/dist/lib/hexclave-app/teams/index.d.ts +1 -1
  130. package/dist/lib/hexclave-app/users/index.d.ts +1 -1
  131. package/dist/lib/hooks.d.ts +1 -1
  132. package/dist/providers/hexclave-context.d.ts +1 -1
  133. package/dist/providers/hexclave-provider-client.d.ts +1 -1
  134. package/dist/providers/hexclave-provider.d.ts +1 -1
  135. package/dist/pushed-config-error-overlay/index.d.ts +1 -1
  136. package/dist/pushed-config-error-overlay/index.js +1 -1
  137. package/dist/pushed-config-error-overlay/index.js.map +1 -1
  138. package/dist/sign-out-DBnSkfDz.d.ts.map +1 -1
  139. package/dist/utils/session-storage.d.ts +12 -0
  140. package/dist/utils/session-storage.d.ts.map +1 -0
  141. package/dist/utils/session-storage.js +33 -0
  142. package/dist/utils/session-storage.js.map +1 -0
  143. package/package.json +3 -3
  144. package/src/components-page/sign-out.test.tsx +190 -0
  145. package/src/components-page/sign-out.tsx +22 -3
  146. package/src/dev-tool/dev-tool-core.ts +100 -35
  147. package/src/dev-tool/dev-tool-styles.ts +35 -0
  148. package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +127 -0
  149. package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +34 -1
  150. package/src/lib/hexclave-app/apps/implementations/common.ts +18 -1
  151. package/src/lib/hexclave-app/apps/implementations/redirect-back-state.test.ts +134 -0
  152. package/src/lib/hexclave-app/apps/implementations/redirect-back-state.ts +140 -0
  153. package/src/lib/hexclave-app/apps/implementations/redirect-loop-breaker.test.ts +127 -0
  154. package/src/lib/hexclave-app/apps/implementations/redirect-loop-breaker.ts +117 -0
  155. package/src/lib/hexclave-app/apps/implementations/server-app-impl.ts +31 -5
  156. package/src/lib/hexclave-app/apps/interfaces/client-app.ts +1 -0
  157. package/src/pushed-config-error-overlay/index.ts +1 -1
  158. package/src/utils/session-storage.ts +45 -0
@@ -6,9 +6,26 @@
6
6
  //===========================================
7
7
 
8
8
  import { cacheFunction } from "@hexclave/shared/dist/utils/caches";
9
+ import { captureError } from "@hexclave/shared/dist/utils/errors";
9
10
  import { use } from "@hexclave/shared/dist/utils/react";
10
- import { CurrentUser, useUser } from "..";
11
+ import { CurrentUser, useStackApp, useUser } from "..";
11
12
  import { PredefinedMessageCard } from "../components/message-cards/predefined-message-card";
13
+ import { StackClientApp, hexclaveAppInternalsSymbol } from "../lib/hexclave-app";
14
+
15
+ // The sign-out page's `after_auth_return_to` comes straight from the query string, so it is
16
+ // attacker-craftable (open-redirect shaped). Only follow it if it passes the same trust validation
17
+ // as every other SDK redirect; otherwise ignore it and fall back to the default after-sign-out
18
+ // destination.
19
+ const cacheGetTrustedRedirectUrl = cacheFunction(async (app: StackClientApp<true, string>, redirectUrl: string | undefined): Promise<string | undefined> => {
20
+ if (redirectUrl == null) {
21
+ return undefined;
22
+ }
23
+ if (await app[hexclaveAppInternalsSymbol].isTrustedRedirectUrl(redirectUrl)) {
24
+ return redirectUrl;
25
+ }
26
+ captureError("sign-out-untrusted-redirect-url", new Error(`Ignoring untrusted after_auth_return_to query parameter on the sign-out page: ${redirectUrl}`));
27
+ return undefined;
28
+ });
12
29
 
13
30
  const cacheSignOut = cacheFunction(async (user: CurrentUser, redirectUrl: string | undefined) => {
14
31
  return await user.signOut({ redirectUrl });
@@ -24,13 +41,15 @@ const cacheRedirectIfAlreadySignedOut = cacheFunction(async (redirectUrl: string
24
41
  });
25
42
 
26
43
  export function SignOut(props: { fullPage?: boolean, searchParams?: Record<string, string> }) {
44
+ const app = useStackApp();
27
45
  const user = useUser({ or: "return-null" });
28
46
  const redirectUrl = props.searchParams?.after_auth_return_to;
47
+ const trustedRedirectUrl = use(cacheGetTrustedRedirectUrl(app, redirectUrl));
29
48
 
30
49
  if (user) {
31
- use(cacheSignOut(user, redirectUrl));
50
+ use(cacheSignOut(user, trustedRedirectUrl));
32
51
  } else {
33
- use(cacheRedirectIfAlreadySignedOut(redirectUrl));
52
+ use(cacheRedirectIfAlreadySignedOut(trustedRedirectUrl));
34
53
  }
35
54
 
36
55
  return <PredefinedMessageCard type='signedOut' fullPage={props.fullPage} />;
@@ -8,7 +8,6 @@ import { DEV_TOOL_ROOT_ID } from "@hexclave/shared/dist/utils/dev-tool";
8
8
  import { runAsynchronously, runAsynchronouslyWithAlert } from "@hexclave/shared/dist/utils/promises";
9
9
  import { isLocalhost } from "@hexclave/shared/dist/utils/urls";
10
10
  import type { StackClientApp } from "../lib/hexclave-app";
11
- import { envVars } from "../generated/env";
12
11
  import { getGlobalUiInstance, h, hasAppendChild, setGlobalUiInstance, setHtml, type UiGlobalInstance } from "../in-page-ui/dom";
13
12
  import { getBaseUrl } from "../lib/hexclave-app/apps/implementations/common";
14
13
  import type { HandlerUrlOptions, HandlerUrls, HandlerUrlTarget } from "../lib/hexclave-app/common";
@@ -63,6 +62,11 @@ const MAX_LOG_ENTRIES = 500;
63
62
  const CONSOLE_LOG_BATCH_SIZE = 100;
64
63
  const DRAG_THRESHOLD = 5;
65
64
  const DOCS_URL = 'https://docs.hexclave.com';
65
+ // The local development-environment dashboard always listens on this loopback
66
+ // port (see the CLI's DEFAULT_DASHBOARD_PORT). The dev tool runs inside the
67
+ // customer's own app, so it can't read the CLI's env vars — the port is fixed.
68
+ const LOCAL_DASHBOARD_ORIGIN = 'http://localhost:26700';
69
+ const HOSTED_DASHBOARD_URL = 'https://app.hexclave.com';
66
70
 
67
71
  const TABS: { id: TabId; label: string; icon: string }[] = [
68
72
  { id: 'overview', label: 'Overview', icon: '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>' },
@@ -193,42 +197,60 @@ function resolveApiBaseUrl(app: StackClientApp<true>): string {
193
197
  return getBaseUrl(opts.baseUrl);
194
198
  }
195
199
 
196
- function shouldShowDashboardTab(app: StackClientApp<true>): boolean {
197
- return envVars.HEXCLAVE_IS_LOCAL_EMULATOR === "true" && isLocalhost(resolveApiBaseUrl(app));
200
+ function localDashboardProjectUrl(app: StackClientApp<true>): string {
201
+ return `${LOCAL_DASHBOARD_ORIGIN}/projects/${encodeURIComponent(app.projectId)}`;
198
202
  }
199
203
 
200
- function getTabsForApp(app: StackClientApp<true>): { id: TabId; label: string; icon: string }[] {
201
- if (shouldShowDashboardTab(app)) {
202
- return TABS;
203
- }
204
- return TABS.filter((tab) => tab.id !== 'dashboard');
204
+ function parseProjectAvailabilityResponse(body: unknown): boolean {
205
+ if (typeof body !== 'object' || body === null) return false;
206
+ return 'project_available' in body && body.project_available === true;
207
+ }
208
+
209
+ // How long to wait for the availability probe before giving up. A refused
210
+ // connection rejects almost immediately, but a host that accepts the socket yet
211
+ // never responds would otherwise leave the tab stuck on "Checking…" forever.
212
+ const LOCAL_DASHBOARD_PROBE_TIMEOUT_MS = 3000;
213
+
214
+ // Whether the current page can even talk to the HTTP-only local dashboard.
215
+ // LOCAL_DASHBOARD_ORIGIN is `http://localhost:26700`, so the page itself must be
216
+ // an http: localhost origin: an https: page (e.g. an HTTPS dev server) would
217
+ // have both the probe fetch and the iframe embed blocked as mixed content, so
218
+ // we treat that as "not available" and fall back to the hosted dashboard.
219
+ function canReachLocalDashboard(): boolean {
220
+ return isLocalhost(window.location.href) && window.location.protocol === 'http:';
205
221
  }
206
222
 
207
- function deriveDashboardBaseUrl(apiBaseUrl: string): string {
223
+ // Decides whether the Dashboard tab can embed the locally-running
224
+ // development-environment dashboard. Rather than inferring from build-time env
225
+ // vars (which don't reflect whether the dev environment is actually up right
226
+ // now), we ask the running development environment directly:
227
+ // 1. We must be viewing the app from an http: localhost origin — the HTTP-only
228
+ // dashboard on :26700 is only reachable from, and only relevant to, a local
229
+ // browser (and an https: page can't reach it without mixed-content errors).
230
+ // 2. The development environment must be running AND already own this exact
231
+ // project (see the project-availability route it answers).
232
+ // Any failure — dev environment not running (connection refused), probe timeout,
233
+ // project unknown, or a malformed response — resolves to `false`, which shows
234
+ // the hosted-dashboard hint instead.
235
+ async function isLocalDashboardProjectAvailable(app: StackClientApp<true>): Promise<boolean> {
236
+ if (!canReachLocalDashboard()) return false;
237
+ const url = `${LOCAL_DASHBOARD_ORIGIN}/api/development-environment/project-availability?project_id=${encodeURIComponent(app.projectId)}`;
238
+ const controller = new AbortController();
239
+ const timeout = setTimeout(() => controller.abort(), LOCAL_DASHBOARD_PROBE_TIMEOUT_MS);
208
240
  try {
209
- const url = new URL(apiBaseUrl);
210
- if (url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]') {
211
- const port = url.port;
212
- if (port && port.endsWith('02')) {
213
- url.port = port.slice(0, -2) + '01';
214
- }
215
- return url.origin;
216
- }
217
- if (url.hostname.startsWith('api.')) {
218
- url.hostname = 'app.' + url.hostname.slice(4);
219
- return url.origin;
220
- }
221
- return url.origin;
241
+ const response = await fetch(url, { method: 'GET', signal: controller.signal });
242
+ if (!response.ok) return false;
243
+ return parseProjectAvailabilityResponse(await response.json());
222
244
  } catch {
223
- return 'https://app.hexclave.com';
245
+ // Reachability probe: when the local development environment isn't running,
246
+ // the fetch rejects (connection refused); when it hangs, the AbortController
247
+ // aborts it. Either way that simply means "not available".
248
+ return false;
249
+ } finally {
250
+ clearTimeout(timeout);
224
251
  }
225
252
  }
226
253
 
227
- function resolveDashboardUrl(app: StackClientApp<true>): string {
228
- const base = deriveDashboardBaseUrl(resolveApiBaseUrl(app));
229
- return `${base}/projects/${encodeURIComponent(app.projectId)}`;
230
- }
231
-
232
254
  function formatTimestamp(ts: number): string {
233
255
  return new Date(ts).toLocaleTimeString([], {
234
256
  hour: '2-digit',
@@ -563,8 +585,8 @@ function createTabBar(
563
585
  // Iframe helper
564
586
  // ---------------------------------------------------------------------------
565
587
 
566
- function createIframeTab(src: string, title: string, loadingMsg = 'Loading\u2026', errorMsg = 'Unable to load content', errorDetail?: string, openExternallyLabel?: string): HTMLElement {
567
- const container = h('div', { className: 'sdt-iframe-container' });
588
+ function populateIframeTab(container: HTMLElement, src: string, title: string, loadingMsg = 'Loading\u2026', errorMsg = 'Unable to load content', errorDetail?: string, openExternallyLabel?: string): void {
589
+ container.innerHTML = '';
568
590
  if (openExternallyLabel != null) {
569
591
  container.appendChild(h('div', { className: 'sdt-iframe-toolbar' },
570
592
  h('a', { href: src, target: '_blank', rel: 'noopener noreferrer', className: 'sdt-iframe-open-link' }, openExternallyLabel),
@@ -594,7 +616,7 @@ function createIframeTab(src: string, title: string, loadingMsg = 'Loading\u2026
594
616
  }
595
617
  const retryBtn = h('button', { className: 'sdt-iframe-error-btn' }, 'Retry');
596
618
  retryBtn.addEventListener('click', () => {
597
- container.replaceWith(createIframeTab(src, title, loadingMsg, errorMsg, errorDetail, openExternallyLabel));
619
+ populateIframeTab(container, src, title, loadingMsg, errorMsg, errorDetail, openExternallyLabel);
598
620
  });
599
621
  errDiv.appendChild(retryBtn);
600
622
  const link = h('a', { href: src, target: '_blank', rel: 'noopener noreferrer', style: { color: 'var(--sdt-accent)', fontSize: '12px', textDecoration: 'none' } }, 'Open in new tab');
@@ -603,7 +625,6 @@ function createIframeTab(src: string, title: string, loadingMsg = 'Loading\u2026
603
625
  });
604
626
 
605
627
  container.appendChild(iframe);
606
- return container;
607
628
  }
608
629
 
609
630
  // ===========================================================================================
@@ -1681,8 +1702,52 @@ function createAITab(app: StackClientApp<true>): HTMLElement {
1681
1702
  // ---------------------------------------------------------------------------
1682
1703
 
1683
1704
  function createDashboardTab(app: StackClientApp<true>): HTMLElement {
1684
- const dashboardUrl = resolveDashboardUrl(app);
1685
- return createIframeTab(dashboardUrl, 'Hexclave Dashboard', 'Loading dashboard\u2026', 'Unable to load dashboard', 'The dashboard may require authentication or block framing', 'Open in New Tab');
1705
+ const container = h('div', { className: 'sdt-iframe-container' });
1706
+
1707
+ function showChecking() {
1708
+ container.innerHTML = '';
1709
+ container.appendChild(h('div', { className: 'sdt-iframe-loading' }, 'Checking development environment\u2026'));
1710
+ }
1711
+
1712
+ function showUnavailable() {
1713
+ container.innerHTML = '';
1714
+ const message = h('div', { className: 'sdt-dashboard-unavailable' });
1715
+ const text = h('div', { className: 'sdt-dashboard-unavailable-text' });
1716
+ text.appendChild(document.createTextNode('Navigate to '));
1717
+ text.appendChild(h('a', {
1718
+ className: 'sdt-dashboard-unavailable-link',
1719
+ href: HOSTED_DASHBOARD_URL,
1720
+ target: '_blank',
1721
+ rel: 'noopener noreferrer',
1722
+ }, HOSTED_DASHBOARD_URL));
1723
+ text.appendChild(document.createTextNode(" to view this project's dashboard"));
1724
+ message.appendChild(text);
1725
+ container.appendChild(message);
1726
+ }
1727
+
1728
+ async function check() {
1729
+ showChecking();
1730
+ const available = await isLocalDashboardProjectAvailable(app);
1731
+ // The dev tool may have been torn down while we were probing; only mutate
1732
+ // the DOM if this container is still mounted.
1733
+ if (!container.isConnected) return;
1734
+ if (available) {
1735
+ populateIframeTab(
1736
+ container,
1737
+ localDashboardProjectUrl(app),
1738
+ 'Hexclave Dashboard',
1739
+ 'Loading dashboard\u2026',
1740
+ 'Unable to load dashboard',
1741
+ 'The dashboard may require authentication or block framing',
1742
+ 'Open in New Tab',
1743
+ );
1744
+ } else {
1745
+ showUnavailable();
1746
+ }
1747
+ }
1748
+
1749
+ runAsynchronously(check);
1750
+ return container;
1686
1751
  }
1687
1752
 
1688
1753
  // ---------------------------------------------------------------------------
@@ -2112,7 +2177,7 @@ function createPanel(
2112
2177
  panel.style.height = state.get().panelHeight + 'px';
2113
2178
  }
2114
2179
 
2115
- const tabs = getTabsForApp(app);
2180
+ const tabs = TABS;
2116
2181
  const storedActiveTab = state.get().activeTab;
2117
2182
  const activeTab = tabs.some((tab) => tab.id === storedActiveTab) ? storedActiveTab : DEFAULT_STATE.activeTab;
2118
2183
 
@@ -328,6 +328,14 @@ export const devToolCSS = getInPageUiBaseCSS('.hexclave-devtool') + `
328
328
  z-index: 1;
329
329
  }
330
330
 
331
+ /* Iframe panes lay their content out as a flex column so the embedded
332
+ dashboard (or the fallback message) fills the pane height. Uses two
333
+ classes to win over the plain .sdt-tab-pane-active { display: block }. */
334
+ .hexclave-devtool .sdt-tab-pane-iframe.sdt-tab-pane-active {
335
+ display: flex;
336
+ flex-direction: column;
337
+ }
338
+
331
339
  /* ===== Overview tab — single column ===== */
332
340
 
333
341
  .hexclave-devtool .sdt-ov {
@@ -1235,6 +1243,33 @@ export const devToolCSS = getInPageUiBaseCSS('.hexclave-devtool') + `
1235
1243
  background: var(--sdt-accent-hover);
1236
1244
  }
1237
1245
 
1246
+ .hexclave-devtool .sdt-dashboard-unavailable {
1247
+ flex: 1;
1248
+ display: flex;
1249
+ flex-direction: column;
1250
+ align-items: center;
1251
+ justify-content: center;
1252
+ gap: 12px;
1253
+ padding: 24px;
1254
+ text-align: center;
1255
+ color: var(--sdt-text-secondary);
1256
+ font-size: 14px;
1257
+ }
1258
+
1259
+ .hexclave-devtool .sdt-dashboard-unavailable-text {
1260
+ max-width: 420px;
1261
+ line-height: 1.5;
1262
+ }
1263
+
1264
+ .hexclave-devtool .sdt-dashboard-unavailable-link {
1265
+ color: var(--sdt-accent);
1266
+ text-decoration: none;
1267
+ }
1268
+
1269
+ .hexclave-devtool .sdt-dashboard-unavailable-link:hover {
1270
+ text-decoration: underline;
1271
+ }
1272
+
1238
1273
  /* Shared content fade animation */
1239
1274
  .hexclave-devtool .sdt-tab-content-fade {
1240
1275
  animation: sdt-tab-fade-in 0.15s ease-out;
@@ -648,6 +648,133 @@ describe("StackClientApp cross-domain auth", () => {
648
648
  expect(redirectedUrl).toBe("/settings?tab=profile");
649
649
  });
650
650
 
651
+ it("restores a dropped after_auth_return_to from the sessionStorage mirror when redirecting after sign-in", async () => {
652
+ const previousWindow = globalThis.window;
653
+ const previousDocument = globalThis.document;
654
+ const hadPreviousWindow = Reflect.has(globalThis, "window");
655
+ const sessionStorageMap = new Map<string, string>();
656
+ const windowMock = {
657
+ location: {
658
+ href: "https://demo.example.test/handler/sign-in?after_auth_return_to=%2Fmusic%3Ftrack%3D1",
659
+ },
660
+ sessionStorage: {
661
+ getItem: (key: string) => sessionStorageMap.get(key) ?? null,
662
+ setItem: (key: string, value: string) => {
663
+ sessionStorageMap.set(key, value);
664
+ },
665
+ removeItem: (key: string) => {
666
+ sessionStorageMap.delete(key);
667
+ },
668
+ },
669
+ };
670
+ Reflect.set(globalThis, "window", windowMock);
671
+ globalThis.document = createMockDocument();
672
+
673
+ try {
674
+ // The constructor mirrors the redirect-back state from the arrival URL into sessionStorage.
675
+ const clientApp = new StackClientApp({
676
+ baseUrl: "http://localhost:12345",
677
+ projectId: "00000000-0000-4000-8000-000000000011",
678
+ publishableClientKey: "stack-pk-test",
679
+ tokenStore: "memory",
680
+ redirectMethod: "window",
681
+ noAutomaticPrefetch: true,
682
+ });
683
+
684
+ // Intermediate hops (MFA, magic link, OAuth round-trips, ...) dropped the query params.
685
+ windowMock.location.href = "https://demo.example.test/handler/mfa";
686
+
687
+ const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl("afterSignIn");
688
+ expect(redirectUrl).toBe("/music?track=1");
689
+
690
+ // noRedirectBack opts out of the mirror just like it opts out of the query param.
691
+ const noRedirectBackUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl("afterSignIn", { noRedirectBack: true });
692
+ expect(new URL(noRedirectBackUrl, "https://demo.example.test").pathname).toBe("/");
693
+ } finally {
694
+ globalThis.document = previousDocument;
695
+ if (hadPreviousWindow) {
696
+ Reflect.set(globalThis, "window", previousWindow);
697
+ } else {
698
+ Reflect.deleteProperty(globalThis, "window");
699
+ }
700
+ }
701
+ });
702
+
703
+ it("restores dropped cross-domain handoff state from the sessionStorage mirror when redirecting after sign-in", async () => {
704
+ const projectId = "00000000-0000-4000-8000-000000000012";
705
+ const previousWindow = globalThis.window;
706
+ const hadPreviousWindow = Reflect.has(globalThis, "window");
707
+ const sessionStorageMap = new Map<string, string>();
708
+
709
+ const handoffState = "mirror-handoff-state";
710
+ const handoffCodeChallenge = "abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~";
711
+ const handoffAfterCallbackRedirect = "https://demo.example.test/dashboard";
712
+ const redirectBackUrl = new URL("https://demo.example.test/handler/oauth-callback");
713
+ redirectBackUrl.searchParams.set("hexclave_cross_domain_auth", "1");
714
+ redirectBackUrl.searchParams.set("hexclave_cross_domain_state", handoffState);
715
+ redirectBackUrl.searchParams.set("hexclave_cross_domain_code_challenge", handoffCodeChallenge);
716
+ redirectBackUrl.searchParams.set("hexclave_cross_domain_after_callback_redirect_url", handoffAfterCallbackRedirect);
717
+
718
+ const arrivalUrl = new URL(`https://${projectId}.built-with-stack-auth.com/handler/sign-in`);
719
+ arrivalUrl.searchParams.set("after_auth_return_to", redirectBackUrl.toString());
720
+ arrivalUrl.searchParams.set("hexclave_cross_domain_state", handoffState);
721
+ arrivalUrl.searchParams.set("hexclave_cross_domain_code_challenge", handoffCodeChallenge);
722
+ arrivalUrl.searchParams.set("hexclave_cross_domain_after_callback_redirect_url", handoffAfterCallbackRedirect);
723
+
724
+ const previousDocument = globalThis.document;
725
+ const windowMock = {
726
+ location: {
727
+ href: arrivalUrl.toString(),
728
+ },
729
+ sessionStorage: {
730
+ getItem: (key: string) => sessionStorageMap.get(key) ?? null,
731
+ setItem: (key: string, value: string) => {
732
+ sessionStorageMap.set(key, value);
733
+ },
734
+ removeItem: (key: string) => {
735
+ sessionStorageMap.delete(key);
736
+ },
737
+ },
738
+ };
739
+ Reflect.set(globalThis, "window", windowMock);
740
+ globalThis.document = createMockDocument();
741
+
742
+ try {
743
+ const clientApp = new StackClientApp({
744
+ baseUrl: "http://localhost:12345",
745
+ projectId,
746
+ publishableClientKey: "stack-pk-test",
747
+ tokenStore: "memory",
748
+ redirectMethod: "window",
749
+ noAutomaticPrefetch: true,
750
+ });
751
+ const crossDomainAuthorizeRedirect = "https://demo.example.test/handler/oauth-callback?code=minted-code&state=mirror-handoff-state";
752
+ const createCrossDomainAuthRedirectUrlSpy = vi
753
+ .spyOn(clientApp as any, "_createCrossDomainAuthRedirectUrl")
754
+ .mockResolvedValue(crossDomainAuthorizeRedirect);
755
+
756
+ // All redirect-back query params were dropped before the after-sign-in redirect.
757
+ windowMock.location.href = `https://${projectId}.built-with-stack-auth.com/handler/sign-in`;
758
+
759
+ const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl("afterSignIn");
760
+
761
+ expect(createCrossDomainAuthRedirectUrlSpy).toHaveBeenCalledWith(expect.objectContaining({
762
+ redirectUri: redirectBackUrl.toString(),
763
+ state: handoffState,
764
+ codeChallenge: handoffCodeChallenge,
765
+ afterCallbackRedirectUrl: handoffAfterCallbackRedirect,
766
+ }));
767
+ expect(redirectUrl).toBe(crossDomainAuthorizeRedirect);
768
+ } finally {
769
+ globalThis.document = previousDocument;
770
+ if (hadPreviousWindow) {
771
+ Reflect.set(globalThis, "window", previousWindow);
772
+ } else {
773
+ Reflect.deleteProperty(globalThis, "window");
774
+ }
775
+ }
776
+ });
777
+
651
778
  it("ignores stale session callbacks after a newer refresh token owns the token store", async () => {
652
779
  const clientApp = new StackClientApp({
653
780
  baseUrl: "http://localhost:12345",
@@ -58,6 +58,8 @@ import { TeamPermission } from "../../permissions";
58
58
  import { AdminOwnedProject, AdminProjectUpdateOptions, Project, adminProjectCreateOptionsToCrud } from "../../projects";
59
59
  import { EditableTeamMemberProfile, ReceivedTeamInvitation, SentTeamInvitation, Team, TeamCreateOptions, TeamUpdateOptions, TeamUser, teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams";
60
60
  import { buildCliAuthConfirmUrl, getHostedHandlerUrl, isHostedHandlerUrlForProject, resolveHandlerUrls } from "../../url-targets";
61
+ import { augmentUrlWithPersistedRedirectBackState, saveRedirectBackStateFromUrl } from "./redirect-back-state";
62
+ import { recordRedirectAndThrowIfLoopDetected } from "./redirect-loop-breaker";
61
63
  import { ActiveSession, Auth, BaseUser, CurrentUser, InternalUserExtra, OAuthProvider, ProjectCurrentUser, SyncedPartialUser, TokenPartialUser, UserExtra, UserUpdateOptions, userUpdateOptionsToCrud, withUserDestructureGuard } from "../../users";
62
64
  import { StackClientApp, StackClientAppConstructorOptions, StackClientAppJson } from "../interfaces/client-app";
63
65
  import { _HexclaveAdminAppImplIncomplete } from "./admin-app-impl";
@@ -723,6 +725,11 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
723
725
  this._trackPendingAuthResolution(async () => {
724
726
  await this._maybeHandleNestedCrossDomainAuth(urlAtConstructionTime);
725
727
  });
728
+
729
+ // Mirror any redirect-back state from the page URL into sessionStorage, so the return trip
730
+ // survives later hops that drop the query params (OAuth provider round-trips, MFA, magic
731
+ // links, ...). See redirect-back-state.ts for details.
732
+ saveRedirectBackStateFromUrl({ url: urlAtConstructionTime, projectId: this.projectId });
726
733
  }
727
734
 
728
735
  if (isBrowserLike() && resolvedOptions.devTool !== false) {
@@ -2894,6 +2901,17 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
2894
2901
  }
2895
2902
 
2896
2903
  protected async _redirectTo(options: { url: URL | string, replace?: boolean }) {
2904
+ if (this._redirectMethod !== "none" && isBrowserLike()) {
2905
+ const currentUrl = new URL(window.location.href);
2906
+ const targetUrl = new URL(options.url, currentUrl);
2907
+ // Circuit breaker: if this exact redirect keeps repeating, throw so the initiating page
2908
+ // renders its error state instead of bouncing the user between pages forever.
2909
+ recordRedirectAndThrowIfLoopDetected({ currentUrl, targetUrl });
2910
+ // Client-side navigations don't re-run the app constructor, so mirror redirect-back state
2911
+ // on every SDK-driven hop too (see redirect-back-state.ts).
2912
+ saveRedirectBackStateFromUrl({ url: targetUrl, projectId: this.projectId });
2913
+ }
2914
+
2897
2915
  if (this._redirectMethod === "none") {
2898
2916
  return;
2899
2917
  } else if (typeof this._redirectMethod === "object" && this._redirectMethod.navigate) {
@@ -2953,9 +2971,21 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
2953
2971
  throw new Error(`No URL for handler name ${handlerName}`);
2954
2972
  }
2955
2973
 
2956
- const currentUrl = isReactServer || typeof window === "undefined"
2974
+ let currentUrl = isReactServer || typeof window === "undefined"
2957
2975
  ? null
2958
2976
  : new URL(window.location.href);
2977
+ if (
2978
+ currentUrl != null
2979
+ && options?.noRedirectBack !== true
2980
+ && (handlerName === "afterSignIn" || handlerName === "afterSignUp")
2981
+ ) {
2982
+ // If intermediate hops dropped the redirect-back query params, restore them from the
2983
+ // sessionStorage mirror so the user still returns to where they came from instead of
2984
+ // stranding on the default post-auth page (on hosted components, that would be the hosted
2985
+ // welcome page). The restored URL goes through the same _isTrusted / cross-domain-authorize
2986
+ // validation below as one read from query params.
2987
+ currentUrl = augmentUrlWithPersistedRedirectBackState({ currentUrl, projectId: this.projectId });
2988
+ }
2959
2989
  const plan = await planRedirectToHandler({
2960
2990
  handlerName,
2961
2991
  rawHandlerUrl,
@@ -4057,6 +4087,9 @@ export class _HexclaveClientAppImplIncomplete<HasTokenStore extends boolean, Pro
4057
4087
  awaitPendingAuthResolutions: async () => {
4058
4088
  await this._awaitPendingAuthResolutions();
4059
4089
  },
4090
+ isTrustedRedirectUrl: async (url: string) => {
4091
+ return await this._isTrusted(url);
4092
+ },
4060
4093
  };
4061
4094
  };
4062
4095
 
@@ -12,6 +12,7 @@ import { ReactPromise, runAsynchronously } from "@hexclave/shared/dist/utils/pro
12
12
  import { suspendIfSsr, use } from "@hexclave/shared/dist/utils/react";
13
13
  import { Result } from "@hexclave/shared/dist/utils/results";
14
14
  import { Store } from "@hexclave/shared/dist/utils/stores";
15
+ import { deindent } from "@hexclave/shared/dist/utils/strings";
15
16
  import { getDefaultApiUrls } from "@hexclave/shared/dist/utils/urls";
16
17
  import React, { useCallback } from "react"; // THIS_LINE_PLATFORM react-like
17
18
  import { envVars } from "../../../../generated/env";
@@ -44,7 +45,23 @@ const showMissingConfigAlertInBrowser = (message: string) => {
44
45
  };
45
46
 
46
47
  const throwMissingProjectIdError = (): never => {
47
- const message = "Welcome to Hexclave! It seems that you haven't provided a project ID. Please create a project on the Hexclave dashboard at https://app.hexclave.com and put it in the HEXCLAVE_PROJECT_ID environment variable.";
48
+ const message = deindent`
49
+ Welcome to Hexclave!
50
+
51
+ It seems that you haven't provided a project ID.
52
+
53
+ ${envVars.NODE_ENV?.includes("dev") ? deindent`
54
+ You are running this app in development mode. Make sure that your start command is wrapped in a call to the Hexclave CLI: \`npx @hexclave/cli dev --config-file <file> -- <command>\`
55
+
56
+ Alternatively, you can also connect to a Cloud project's environment variables instead by creating a project on the Hexclave dashboard at https://app.hexclave.com and put its information in the HEXCLAVE_PROJECT_ID environment variable.
57
+ ` : envVars.NODE_ENV?.includes("prod") ? deindent`
58
+ It seems you are running a project in production. Please create a project on the Hexclave dashboard at https://app.hexclave.com and put it in the HEXCLAVE_PROJECT_ID environment variable.
59
+ ` : deindent`
60
+ - If you are running a development project and would like to connect the local Hexclave dashboard, wrap your start command in: \`npx @hexclave/cli dev --config-file <file> -- <command>\`
61
+
62
+ - If you are running a project in production and would like to connect to Hexclave Cloud, create a project on the Hexclave dashboard at https://app.hexclave.com and put its information in the HEXCLAVE_PROJECT_ID environment variable.
63
+ `}
64
+ `;
48
65
  showMissingConfigAlertInBrowser(message);
49
66
  return throwErr(new Error(message));
50
67
  };