@shellui/core 0.3.1 → 0.4.0

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 (56) hide show
  1. package/package.json +2 -2
  2. package/src/app.tsx +11 -1
  3. package/src/components/ui/dialog.tsx +26 -6
  4. package/src/components/ui/sonner.tsx +9 -5
  5. package/src/features/admin/AdminView.tsx +1 -20
  6. package/src/features/auth/AuthProvider.tsx +68 -13
  7. package/src/features/auth/backends/shellui.ts +8 -1
  8. package/src/features/auth/components/AccessPendingView.tsx +112 -0
  9. package/src/features/auth/components/LoginView.tsx +17 -0
  10. package/src/features/auth/components/OAuthCallbackView.tsx +211 -48
  11. package/src/features/auth/hooks/useAuth.tsx +8 -1
  12. package/src/features/auth/utils/authRequestError.spec.ts +52 -0
  13. package/src/features/auth/utils/authRequestError.ts +45 -0
  14. package/src/features/auth/utils/index.ts +7 -0
  15. package/src/features/auth/utils/isTokenAutoRefreshDisabled.spec.ts +71 -0
  16. package/src/features/auth/utils/isTokenAutoRefreshDisabled.ts +18 -0
  17. package/src/features/config/types.ts +46 -0
  18. package/src/features/layouts/AppLayout.tsx +3 -3
  19. package/src/features/layouts/OverlayShell.tsx +10 -6
  20. package/src/features/settings/SettingsIcons.tsx +35 -0
  21. package/src/features/settings/SettingsProvider.tsx +69 -4
  22. package/src/features/settings/SettingsRoutes.tsx +14 -6
  23. package/src/features/settings/SettingsView.tsx +11 -5
  24. package/src/features/settings/components/Advanced.tsx +117 -44
  25. package/src/features/settings/components/Develop.tsx +38 -0
  26. package/src/features/settings/components/Storage.tsx +138 -0
  27. package/src/features/settings/components/develop/StoragePickerTestButtons.tsx +148 -0
  28. package/src/features/settings/components/develop/UploadToastTestButton.tsx +29 -0
  29. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -0
  30. package/src/features/settings/utils/buildSettingsForPropagation.ts +34 -0
  31. package/src/features/settings/utils/toSettingsUser.spec.ts +4 -0
  32. package/src/features/settings/utils/toSettingsUser.ts +2 -0
  33. package/src/features/storage/StorageBridge.tsx +50 -0
  34. package/src/features/storage/StoragePickerContext.tsx +214 -0
  35. package/src/features/storage/api.spec.ts +303 -0
  36. package/src/features/storage/api.ts +414 -0
  37. package/src/features/storage/handleRequest.spec.ts +88 -0
  38. package/src/features/storage/handleRequest.ts +53 -0
  39. package/src/features/storage/quota.spec.ts +151 -0
  40. package/src/features/storage/quota.ts +104 -0
  41. package/src/features/storage/uploads/UploadToastCard.tsx +442 -0
  42. package/src/features/storage/uploads/UploadToaster.tsx +41 -0
  43. package/src/features/storage/uploads/handleTrackedUpload.spec.ts +170 -0
  44. package/src/features/storage/uploads/handleTrackedUpload.ts +97 -0
  45. package/src/features/storage/uploads/types.ts +24 -0
  46. package/src/features/storage/uploads/uploadQueue.spec.ts +118 -0
  47. package/src/features/storage/uploads/uploadQueue.ts +349 -0
  48. package/src/features/storage/uploads/useUploadQueue.ts +30 -0
  49. package/src/i18n/translations/en/common.json +33 -0
  50. package/src/i18n/translations/en/settings.json +47 -4
  51. package/src/i18n/translations/fr/common.json +33 -0
  52. package/src/i18n/translations/fr/settings.json +47 -4
  53. package/src/index.css +2 -1
  54. package/src/index.ts +2 -0
  55. package/src/lib/z-index.ts +9 -3
  56. package/src/service-worker/register.ts +4 -12
@@ -1,8 +1,18 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { useLocation, useNavigate } from 'react-router';
3
3
  import urls from '../../../constants/urls';
4
- import { buildAuthUrlWithNext, normalizeNextPath } from '../utils';
4
+ import {
5
+ buildAuthUrlWithNext,
6
+ inferAccessPendingErrorCode,
7
+ isAccessPendingErrorCode,
8
+ normalizeNextPath,
9
+ } from '../utils';
5
10
  import { useAuth } from '../hooks/useAuth';
11
+ import { AccessPendingView } from './AccessPendingView';
12
+
13
+ const SHELLUI_OAUTH_ERROR_PARAM = 'shellui_oauth_error';
14
+ const SHELLUI_OAUTH_ERROR_CODE_PARAM = 'shellui_oauth_error_code';
15
+ const PENDING_STORAGE_PREFIX = 'shellui.oauth.access_pending:';
6
16
 
7
17
  const toPositiveInt = (raw: string | null): number | undefined => {
8
18
  if (!raw) return undefined;
@@ -11,13 +21,69 @@ const toPositiveInt = (raw: string | null): number | undefined => {
11
21
  return Math.trunc(n);
12
22
  };
13
23
 
24
+ type PendingAccess = { message: string; code: string };
25
+
26
+ const readPendingForCode = (code: string): PendingAccess | null => {
27
+ if (typeof window === 'undefined') return null;
28
+ try {
29
+ const raw = sessionStorage.getItem(`${PENDING_STORAGE_PREFIX}${code}`);
30
+ if (!raw) return null;
31
+ const parsed = JSON.parse(raw) as { message?: unknown; code?: unknown };
32
+ if (typeof parsed.message === 'string' && typeof parsed.code === 'string') {
33
+ return { message: parsed.message, code: parsed.code };
34
+ }
35
+ } catch {
36
+ // ignore
37
+ }
38
+ return null;
39
+ };
40
+
41
+ const writePendingForCode = (oauthCode: string, pending: PendingAccess) => {
42
+ if (typeof window === 'undefined') return;
43
+ try {
44
+ sessionStorage.setItem(`${PENDING_STORAGE_PREFIX}${oauthCode}`, JSON.stringify(pending));
45
+ } catch {
46
+ // ignore
47
+ }
48
+ };
49
+
50
+ const clearPendingForCode = (oauthCode: string) => {
51
+ if (typeof window === 'undefined') return;
52
+ try {
53
+ sessionStorage.removeItem(`${PENDING_STORAGE_PREFIX}${oauthCode}`);
54
+ } catch {
55
+ // ignore
56
+ }
57
+ };
58
+
59
+ const buildLoginPendingUrl = (nextPath: string, pending: PendingAccess) => {
60
+ const loginUrl = new URL(buildAuthUrlWithNext(urls.login, nextPath), window.location.origin);
61
+ loginUrl.searchParams.set(SHELLUI_OAUTH_ERROR_PARAM, pending.message.slice(0, 500));
62
+ loginUrl.searchParams.set(SHELLUI_OAUTH_ERROR_CODE_PARAM, pending.code);
63
+ return `${loginUrl.pathname}${loginUrl.search}`;
64
+ };
65
+
66
+ const looksLikeUsedOAuthCode = (message: string | null | undefined) => {
67
+ const text = (message || '').toLowerCase();
68
+ return (
69
+ text.includes('bad_verification_code') ||
70
+ text.includes('code has already been used') ||
71
+ text.includes('authorization code was already redeemed') ||
72
+ text.includes('invalid_grant') ||
73
+ text.includes('expired') ||
74
+ text.includes('redirect_uri')
75
+ );
76
+ };
77
+
14
78
  export const OAuthCallbackView = () => {
15
79
  const location = useLocation();
16
80
  const navigate = useNavigate();
17
81
  const { completeOAuthCallback, isAuthenticated } = useAuth();
18
82
  const [localError, setLocalError] = useState<string | null>(null);
83
+ const [pendingAccess, setPendingAccess] = useState<PendingAccess | null>(null);
19
84
  const [isWorking, setIsWorking] = useState(true);
20
- const hasStartedRef = useRef(false);
85
+ /** OAuth `code` we already started exchanging (avoid double-spend / Strict Mode races). */
86
+ const startedCodeRef = useRef<string | null>(null);
21
87
  const nextPath = useMemo(() => {
22
88
  const params = new URLSearchParams(location.search);
23
89
  return normalizeNextPath(params.get('next')) ?? '/';
@@ -29,46 +95,102 @@ export const OAuthCallbackView = () => {
29
95
  }, [isAuthenticated, navigate, nextPath]);
30
96
 
31
97
  useEffect(() => {
32
- let cancelled = false;
33
- if (hasStartedRef.current || isAuthenticated) {
34
- return () => {
35
- cancelled = true;
36
- };
98
+ if (isAuthenticated) return;
99
+
100
+ const params = new URLSearchParams(location.search);
101
+ const oauthError = params.get('error');
102
+ if (oauthError) {
103
+ setLocalError(oauthError);
104
+ setIsWorking(false);
105
+ return;
106
+ }
107
+
108
+ const code = params.get('code');
109
+ const provider = params.get('provider');
110
+ if (!code || !provider) {
111
+ setLocalError('Missing OAuth callback parameters.');
112
+ setIsWorking(false);
113
+ return;
37
114
  }
38
- hasStartedRef.current = true;
115
+
116
+ // If a previous attempt already learned this login is pending, show it without re-exchanging.
117
+ const cachedPending = readPendingForCode(code);
118
+ if (cachedPending) {
119
+ setPendingAccess(cachedPending);
120
+ setIsWorking(false);
121
+ navigate(buildLoginPendingUrl(nextPath, cachedPending), { replace: true });
122
+ return;
123
+ }
124
+
125
+ if (startedCodeRef.current === code) {
126
+ return;
127
+ }
128
+ startedCodeRef.current = code;
129
+
130
+ let cancelled = false;
39
131
  const run = async () => {
40
- const params = new URLSearchParams(location.search);
41
- const oauthError = params.get('error');
42
- if (oauthError) {
43
- if (!cancelled) {
44
- setLocalError(oauthError);
132
+ const redirectUri = `${window.location.origin}${location.pathname}${location.search}`;
133
+ let result: { ok: boolean; error?: string | null; errorCode?: string | null };
134
+ try {
135
+ result = await completeOAuthCallback({
136
+ provider,
137
+ code,
138
+ redirectUri,
139
+ oauthClientId: toPositiveInt(params.get('company_oauth_client_id')),
140
+ });
141
+ } catch (err) {
142
+ result = {
143
+ ok: false,
144
+ error: err instanceof Error ? err.message : 'Unable to complete OAuth login.',
145
+ errorCode: null,
146
+ };
147
+ }
148
+
149
+ // Always apply UI state — do not drop failures when the effect cleans up
150
+ // (Strict Mode / callback identity changes), or the page stays on "Completing…".
151
+ if (!result.ok) {
152
+ const pendingCode =
153
+ (isAccessPendingErrorCode(result.errorCode) ? result.errorCode : null) ??
154
+ inferAccessPendingErrorCode(result.error);
155
+
156
+ if (pendingCode) {
157
+ const pending: PendingAccess = {
158
+ message:
159
+ (result.error && result.error.trim()) ||
160
+ 'Your account was created and is waiting for an administrator to grant access.',
161
+ code: pendingCode,
162
+ };
163
+ writePendingForCode(code, pending);
164
+ setPendingAccess(pending);
45
165
  setIsWorking(false);
166
+ if (!cancelled) {
167
+ navigate(buildLoginPendingUrl(nextPath, pending), { replace: true });
168
+ }
169
+ return;
46
170
  }
47
- return;
48
- }
49
- const code = params.get('code');
50
- const provider = params.get('provider');
51
- if (!code || !provider) {
52
- if (!cancelled) {
53
- setLocalError('Missing OAuth callback parameters.');
171
+
172
+ // Code was likely consumed by a cancelled first attempt that already marked pending.
173
+ const recovered = readPendingForCode(code);
174
+ if (recovered && looksLikeUsedOAuthCode(result.error)) {
175
+ setPendingAccess(recovered);
54
176
  setIsWorking(false);
177
+ if (!cancelled) {
178
+ navigate(buildLoginPendingUrl(nextPath, recovered), { replace: true });
179
+ }
180
+ return;
55
181
  }
56
- return;
57
- }
58
- const redirectUri = `${window.location.origin}${location.pathname}${location.search}`;
59
- const ok = await completeOAuthCallback({
60
- provider,
61
- code,
62
- redirectUri,
63
- oauthClientId: toPositiveInt(params.get('company_oauth_client_id')),
64
- });
65
- if (cancelled) return;
66
- if (!ok) {
182
+
183
+ setLocalError(result.error ?? 'Unable to complete OAuth login.');
67
184
  setIsWorking(false);
68
185
  return;
69
186
  }
70
- navigate(nextPath, { replace: true });
187
+
188
+ clearPendingForCode(code);
189
+ if (!cancelled) {
190
+ navigate(nextPath, { replace: true });
191
+ }
71
192
  };
193
+
72
194
  void run();
73
195
  return () => {
74
196
  cancelled = true;
@@ -82,24 +204,65 @@ export const OAuthCallbackView = () => {
82
204
  nextPath,
83
205
  ]);
84
206
 
85
- const displayError = localError;
86
- if (displayError) {
207
+ const backToLogin = () => {
208
+ const params = new URLSearchParams(location.search);
209
+ const code = params.get('code');
210
+ if (code) clearPendingForCode(code);
211
+ navigate(buildAuthUrlWithNext(urls.login, nextPath), { replace: true });
212
+ };
213
+
214
+ if (pendingAccess) {
87
215
  return (
88
- <main className="flex min-h-full items-center justify-center px-6 py-10">
89
- <div className="w-full max-w-lg space-y-3">
90
- <h1 className="text-xl font-semibold tracking-tight text-foreground">
91
- OAuth sign-in failed
92
- </h1>
93
- <p className="rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive">
94
- {displayError}
95
- </p>
96
- <button
97
- type="button"
98
- className="text-sm text-primary underline-offset-4 hover:underline"
99
- onClick={() => navigate(buildAuthUrlWithNext(urls.login, nextPath), { replace: true })}
216
+ <AccessPendingView
217
+ message={pendingAccess.message}
218
+ code={pendingAccess.code}
219
+ onBackToLogin={backToLogin}
220
+ />
221
+ );
222
+ }
223
+
224
+ if (localError && !isWorking) {
225
+ return (
226
+ <main className="flex min-h-full items-center justify-center bg-background px-6 py-12">
227
+ <div className="w-full max-w-xl animate-in fade-in-0 slide-in-from-bottom-3 duration-500">
228
+ <section
229
+ className="border border-border bg-card"
230
+ aria-labelledby="oauth-error-title"
100
231
  >
101
- Return to login
102
- </button>
232
+ <header className="border-b border-border px-8 py-6">
233
+ <span className="inline-flex items-center gap-2 border border-destructive/30 bg-destructive/5 px-2.5 py-1 font-mono text-[10px] font-medium uppercase tracking-[0.14em] text-destructive">
234
+ <span
235
+ className="size-1.5 shrink-0 rounded-full bg-destructive"
236
+ aria-hidden
237
+ />
238
+ Sign-in error
239
+ </span>
240
+ <h1
241
+ id="oauth-error-title"
242
+ className="mt-5 text-2xl font-semibold tracking-tight text-foreground"
243
+ >
244
+ We could not complete sign-in
245
+ </h1>
246
+ </header>
247
+ <div className="space-y-4 px-8 py-6">
248
+ <p className="text-[15px] leading-relaxed text-foreground/90">
249
+ Something went wrong while connecting to your identity provider. This is a technical
250
+ issue, not an account approval status.
251
+ </p>
252
+ <p className="border border-border bg-muted/30 px-4 py-3 font-mono text-xs leading-relaxed text-muted-foreground">
253
+ {localError}
254
+ </p>
255
+ </div>
256
+ <footer className="flex justify-end border-t border-border px-8 py-5">
257
+ <button
258
+ type="button"
259
+ className="text-sm font-medium text-primary underline-offset-4 hover:underline"
260
+ onClick={backToLogin}
261
+ >
262
+ Back to login
263
+ </button>
264
+ </footer>
265
+ </section>
103
266
  </div>
104
267
  </main>
105
268
  );
@@ -3,12 +3,19 @@ import type { AuthEvent, AuthSession, AuthSettings, AuthUser, UserPreferences }
3
3
 
4
4
  export type { AuthSession, AuthUser } from '../types';
5
5
 
6
+ export interface OAuthCallbackResult {
7
+ ok: boolean;
8
+ error?: string | null;
9
+ errorCode?: string | null;
10
+ }
11
+
6
12
  export interface AuthContextValue {
7
13
  session: AuthSession | null;
8
14
  user: AuthUser | null;
9
15
  isAuthenticated: boolean;
10
16
  isLoading: boolean;
11
17
  error: string | null;
18
+ errorCode: string | null;
12
19
  authEvent: AuthEvent;
13
20
  clearAuthEvent: () => void;
14
21
  completeOAuthCallback: (params: {
@@ -16,7 +23,7 @@ export interface AuthContextValue {
16
23
  code: string;
17
24
  redirectUri: string;
18
25
  oauthClientId?: number;
19
- }) => Promise<boolean>;
26
+ }) => Promise<OAuthCallbackResult>;
20
27
  startOAuth: (provider: string, redirectPath?: string, oauthClientId?: number) => boolean;
21
28
  startWeb3Ethereum: () => Promise<boolean>;
22
29
  getAuthSettings: () => Promise<AuthSettings>;
@@ -0,0 +1,52 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ AuthRequestError,
4
+ getAuthRequestErrorCode,
5
+ inferAccessPendingErrorCode,
6
+ isAccessPendingErrorCode,
7
+ } from './authRequestError';
8
+
9
+ describe('isAccessPendingErrorCode', () => {
10
+ it('recognizes pending and denied codes', () => {
11
+ expect(isAccessPendingErrorCode('access_pending')).toBe(true);
12
+ expect(isAccessPendingErrorCode('access_denied')).toBe(true);
13
+ expect(isAccessPendingErrorCode('oauth_authorize_failed')).toBe(false);
14
+ expect(isAccessPendingErrorCode(null)).toBe(false);
15
+ });
16
+ });
17
+
18
+ describe('AuthRequestError', () => {
19
+ it('stores optional error code', () => {
20
+ const err = new AuthRequestError('Waiting for approval.', 'access_pending');
21
+ expect(err.message).toBe('Waiting for approval.');
22
+ expect(err.code).toBe('access_pending');
23
+ });
24
+ });
25
+
26
+ describe('getAuthRequestErrorCode', () => {
27
+ it('reads code from AuthRequestError and duck-typed objects', () => {
28
+ expect(getAuthRequestErrorCode(new AuthRequestError('x', 'access_pending'))).toBe(
29
+ 'access_pending',
30
+ );
31
+ expect(getAuthRequestErrorCode({ name: 'AuthRequestError', code: 'access_denied' })).toBe(
32
+ 'access_denied',
33
+ );
34
+ expect(getAuthRequestErrorCode(new Error('nope'))).toBe(null);
35
+ });
36
+ });
37
+
38
+ describe('inferAccessPendingErrorCode', () => {
39
+ it('infers from known backend messages', () => {
40
+ expect(
41
+ inferAccessPendingErrorCode(
42
+ 'Your account was created and is waiting for an administrator to grant access.',
43
+ ),
44
+ ).toBe('access_pending');
45
+ expect(
46
+ inferAccessPendingErrorCode(
47
+ 'Your email domain is not authorized for this company. An administrator has been notified.',
48
+ ),
49
+ ).toBe('access_denied');
50
+ expect(inferAccessPendingErrorCode('Invalid code')).toBe(null);
51
+ });
52
+ });
@@ -0,0 +1,45 @@
1
+ export class AuthRequestError extends Error {
2
+ readonly code: string | null;
3
+
4
+ constructor(message: string, code?: string | null) {
5
+ super(message);
6
+ this.name = 'AuthRequestError';
7
+ this.code = typeof code === 'string' && code.trim() ? code.trim() : null;
8
+ }
9
+ }
10
+
11
+ /** Company join blocked until an admin enables the account (or domain mismatch). */
12
+ export function isAccessPendingErrorCode(code: string | null | undefined): boolean {
13
+ return code === 'access_pending' || code === 'access_denied';
14
+ }
15
+
16
+ /** Duck-type safe: `instanceof` can fail across duplicated bundles. */
17
+ export function getAuthRequestErrorCode(err: unknown): string | null {
18
+ if (!err || typeof err !== 'object') return null;
19
+ if (err instanceof AuthRequestError) return err.code;
20
+ const maybe = err as { name?: unknown; code?: unknown };
21
+ if (maybe.name === 'AuthRequestError' && typeof maybe.code === 'string' && maybe.code.trim()) {
22
+ return maybe.code.trim();
23
+ }
24
+ if (typeof maybe.code === 'string' && maybe.code.trim()) {
25
+ return maybe.code.trim();
26
+ }
27
+ return null;
28
+ }
29
+
30
+ /** Infer pending/denied from known backend messages when error_code is missing. */
31
+ export function inferAccessPendingErrorCode(
32
+ message: string | null | undefined,
33
+ ): 'access_pending' | 'access_denied' | null {
34
+ const text = (message || '').toLowerCase();
35
+ if (!text) return null;
36
+ if (text.includes('email domain is not authorized')) return 'access_denied';
37
+ if (
38
+ text.includes('waiting for an administrator') ||
39
+ text.includes('company access is disabled') ||
40
+ text.includes('grant access')
41
+ ) {
42
+ return 'access_pending';
43
+ }
44
+ return null;
45
+ }
@@ -5,6 +5,12 @@ export {
5
5
  } from './clientLoginContext';
6
6
  export { buildAuthUrlWithNext } from './buildAuthUrlWithNext';
7
7
  export { buildSessionFromParams } from './buildSessionFromParams';
8
+ export {
9
+ AuthRequestError,
10
+ getAuthRequestErrorCode,
11
+ inferAccessPendingErrorCode,
12
+ isAccessPendingErrorCode,
13
+ } from './authRequestError';
8
14
  export { clearStoredAuthSession } from './clearStoredAuthSession';
9
15
  export { decodeJwtPayload } from './decodeJwtPayload';
10
16
  export { formatProviderLabel } from './formatProviderLabel';
@@ -14,6 +20,7 @@ export { getPreferredBackendProvider } from './getPreferredBackendProvider';
14
20
  export { getProviderVisual } from './getProviderVisual';
15
21
  export { isLoginMethod } from './isLoginMethod';
16
22
  export { isSessionExpired } from './isSessionExpired';
23
+ export { isTokenAutoRefreshDisabled } from './isTokenAutoRefreshDisabled';
17
24
  export { normalizeAuthSettings } from './normalizeAuthSettings';
18
25
  export { normalizeNextPath } from './normalizeNextPath';
19
26
  export { normalizeRedirectPath } from './normalizeRedirectPath';
@@ -0,0 +1,71 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { isTokenAutoRefreshDisabled } from './isTokenAutoRefreshDisabled';
3
+
4
+ const createStorageMock = (value: string | null) => {
5
+ let stored = value;
6
+ return {
7
+ getItem: vi.fn((key: string) => (key === 'shellui:settings' ? stored : null)),
8
+ setItem: vi.fn((_key: string, next: string) => {
9
+ stored = next;
10
+ }),
11
+ removeItem: vi.fn(() => {
12
+ stored = null;
13
+ }),
14
+ clear: vi.fn(() => {
15
+ stored = null;
16
+ }),
17
+ key: vi.fn(() => null),
18
+ length: 0,
19
+ } as unknown as Storage;
20
+ };
21
+
22
+ describe('isTokenAutoRefreshDisabled', () => {
23
+ beforeEach(() => {
24
+ Object.defineProperty(globalThis, 'localStorage', {
25
+ configurable: true,
26
+ value: createStorageMock(null),
27
+ });
28
+ });
29
+
30
+ it('returns false when settings are missing', () => {
31
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
32
+ });
33
+
34
+ it('returns false when the flag is unset or false', () => {
35
+ Object.defineProperty(globalThis, 'localStorage', {
36
+ configurable: true,
37
+ value: createStorageMock(JSON.stringify({ developerFeatures: { enabled: true } })),
38
+ });
39
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
40
+
41
+ Object.defineProperty(globalThis, 'localStorage', {
42
+ configurable: true,
43
+ value: createStorageMock(
44
+ JSON.stringify({
45
+ developerFeatures: { enabled: true, disableTokenAutoRefresh: false },
46
+ }),
47
+ ),
48
+ });
49
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
50
+ });
51
+
52
+ it('returns true when the develop flag is enabled', () => {
53
+ Object.defineProperty(globalThis, 'localStorage', {
54
+ configurable: true,
55
+ value: createStorageMock(
56
+ JSON.stringify({
57
+ developerFeatures: { enabled: true, disableTokenAutoRefresh: true },
58
+ }),
59
+ ),
60
+ });
61
+ expect(isTokenAutoRefreshDisabled()).toBe(true);
62
+ });
63
+
64
+ it('returns false when localStorage JSON is invalid', () => {
65
+ Object.defineProperty(globalThis, 'localStorage', {
66
+ configurable: true,
67
+ value: createStorageMock('{not-json'),
68
+ });
69
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
70
+ });
71
+ });
@@ -0,0 +1,18 @@
1
+ const SETTINGS_STORAGE_KEY = 'shellui:settings';
2
+
3
+ /**
4
+ * Reads the Develop-panel flag that skips background (and restore) token refresh
5
+ * so expired access tokens can be exercised locally.
6
+ */
7
+ export const isTokenAutoRefreshDisabled = (): boolean => {
8
+ try {
9
+ const stored = localStorage.getItem(SETTINGS_STORAGE_KEY);
10
+ if (!stored) return false;
11
+ const parsed = JSON.parse(stored) as {
12
+ developerFeatures?: { disableTokenAutoRefresh?: boolean };
13
+ };
14
+ return parsed.developerFeatures?.disableTokenAutoRefresh === true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ };
@@ -26,6 +26,8 @@ export interface NavigationItem {
26
26
  requiresAuth?: boolean;
27
27
  /** When true, this item is available only when Settings > Advanced > Developer features is enabled. */
28
28
  requiresDevMode?: boolean;
29
+ /** When true, this item is available only to staff users (`isStaff`). */
30
+ requiresStaff?: boolean;
29
31
  /** When true, hide this item on mobile (bottom nav). Has no effect if hidden is true. */
30
32
  hiddenOnMobile?: boolean;
31
33
  /** When true, hide this item on desktop (sidebar). Has no effect if hidden is true. */
@@ -221,6 +223,39 @@ export interface BackendConfig {
221
223
  companyId?: string | number;
222
224
  }
223
225
 
226
+ /**
227
+ * Optional storage-service wiring for the shell and admin panel.
228
+ * When set, admin shows the Storage sidebar (files explorer, statistics, Django admin).
229
+ * Settings → Storage (quota) appears when `url` is set, unless `showInSettings` is false.
230
+ * ShellUI will also use this for the SDK file API (`shellui.storage`).
231
+ */
232
+ export interface StorageConfig {
233
+ /** Base URL of storage-service (e.g. `http://localhost:8001`). */
234
+ url: string;
235
+ /** Files explorer app URL embedded under Admin → Storage → Files (e.g. `http://localhost:5175/`). */
236
+ filesUrl?: string;
237
+ /**
238
+ * When false, hide Settings → Storage even if `url` is set.
239
+ * Admin Storage is unaffected. Default: true.
240
+ */
241
+ showInSettings?: boolean;
242
+ }
243
+
244
+ /**
245
+ * Custom navigation section for the staff administration panel.
246
+ * Admin app URL remains `backend.adminUrl` / `backend.adminPathname`.
247
+ * v1 is a flat list only (no nested groups).
248
+ */
249
+ export interface AdministrationConfig {
250
+ /** Section title shown in the admin sidebar below Dashboard. */
251
+ title: string | LocalizedString;
252
+ /**
253
+ * Flat list of navigation items (same shape as top-level `navigation` items).
254
+ * Order is preserved in the admin sidebar.
255
+ */
256
+ navigation: NavigationItem[];
257
+ }
258
+
224
259
  export interface ShellUIConfig {
225
260
  port?: number;
226
261
  title?: string;
@@ -238,6 +273,17 @@ export interface ShellUIConfig {
238
273
  /** When set, opening the app at "/" redirects to this path (e.g. "/playground"). */
239
274
  start_url?: string;
240
275
  navigation?: (NavigationItem | NavigationGroup)[];
276
+ /**
277
+ * Custom navigation for the staff admin panel (below Dashboard).
278
+ * Propagated to the admin iframe via SDK settings. See Administration docs.
279
+ */
280
+ administration?: AdministrationConfig;
281
+ /**
282
+ * Storage-service connection. Propagated to iframes via SDK settings.
283
+ * Enables Admin → Storage when `url` is set. Settings → Storage (quota) is shown
284
+ * when `url` is set unless `storage.showInSettings` is false.
285
+ */
286
+ storage?: StorageConfig;
241
287
  themes?: ThemeDefinition[]; // Custom themes to register
242
288
  defaultTheme?: string; // Default theme name to use
243
289
  /** Sentry error reporting. Load from env (e.g. SENTRY_DSN). Only active in production builds. */
@@ -1,10 +1,10 @@
1
1
  import { lazy, Suspense, type LazyExoticComponent, type ComponentType } from 'react';
2
2
  import type { LayoutType, NavigationItem, NavigationGroup } from '../config/types';
3
3
  import { useSettings } from '../settings/SettingsContext';
4
- import { SonnerProvider } from '../sonner/SonnerContext';
5
4
  import { ModalProvider } from '../modal/ModalContext';
6
5
  import { DrawerProvider } from '../drawer/DrawerContext';
7
6
  import { OverlayShell } from './OverlayShell';
7
+ import { StoragePickerProvider } from '../storage/StoragePickerContext';
8
8
  import { LayoutFallback } from './LayoutFallback';
9
9
 
10
10
  const SidebarLayout = lazy(() =>
@@ -61,13 +61,13 @@ export function AppLayout({
61
61
  return (
62
62
  <ModalProvider>
63
63
  <DrawerProvider>
64
- <SonnerProvider>
64
+ <StoragePickerProvider>
65
65
  <OverlayShell>
66
66
  <Suspense fallback={<LayoutFallback />}>
67
67
  {children ? children : <LayoutComponent {...layoutProps} />}
68
68
  </Suspense>
69
69
  </OverlayShell>
70
- </SonnerProvider>
70
+ </StoragePickerProvider>
71
71
  </DrawerProvider>
72
72
  </ModalProvider>
73
73
  );