@shellui/core 0.5.4-alpha.1 → 0.6.0-beta.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.
- package/README.md +2 -0
- package/package.json +6 -4
- package/schemas/shellui.config.schema.json +104 -64
- package/src/app.tsx +5 -3
- package/src/components/ContentView.tsx +26 -5
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/sonner.spec.tsx +138 -0
- package/src/components/ui/sonner.tsx +5 -5
- package/src/components/ui/switch.tsx +1 -1
- package/src/features/admin/AdminView.tsx +14 -3
- package/src/features/ai/AiBridge.tsx +106 -0
- package/src/features/ai/AiUnavailableResponder.tsx +39 -0
- package/src/features/ai/README.md +52 -0
- package/src/features/ai/ShellAiHost.tsx +24 -0
- package/src/features/ai/adapters/ollama.ts +170 -0
- package/src/features/ai/adapters/promptApi.spec.ts +135 -0
- package/src/features/ai/adapters/promptApi.ts +222 -0
- package/src/features/ai/adapters/webllm.experimental.spec.ts +69 -0
- package/src/features/ai/adapters/webllm.spec.ts +527 -0
- package/src/features/ai/adapters/webllm.ts +142 -0
- package/src/features/ai/aiDisabledResponses.spec.ts +29 -0
- package/src/features/ai/aiDisabledResponses.ts +32 -0
- package/src/features/ai/browserInstallStore.spec.ts +58 -0
- package/src/features/ai/browserInstallStore.ts +76 -0
- package/src/features/ai/catalog.ts +31 -0
- package/src/features/ai/createRegistry.ts +83 -0
- package/src/features/ai/developHarness.spec.ts +108 -0
- package/src/features/ai/developHarness.ts +161 -0
- package/src/features/ai/engine/formatAiError.spec.ts +85 -0
- package/src/features/ai/engine/formatAiError.ts +132 -0
- package/src/features/ai/engine/mapInitProgress.ts +9 -0
- package/src/features/ai/engine/normalizeWebLlmModule.spec.ts +47 -0
- package/src/features/ai/engine/vite-worker.d.ts +6 -0
- package/src/features/ai/engine/webllm.worker.ts +51 -0
- package/src/features/ai/engine/webllmEngine.ts +1011 -0
- package/src/features/ai/handleRequest.spec.ts +288 -0
- package/src/features/ai/handleRequest.ts +325 -0
- package/src/features/ai/isAiFeatureEnabled.spec.ts +15 -0
- package/src/features/ai/isAiFeatureEnabled.ts +9 -0
- package/src/features/ai/promptApiSupport.spec.ts +64 -0
- package/src/features/ai/promptApiSupport.ts +117 -0
- package/src/features/ai/registry.spec.ts +100 -0
- package/src/features/ai/registry.ts +131 -0
- package/src/features/ai/status.spec.ts +92 -0
- package/src/features/ai/status.ts +85 -0
- package/src/features/ai/types.ts +100 -0
- package/src/features/ai/webLlmBrowserSupport.spec.ts +86 -0
- package/src/features/ai/webLlmBrowserSupport.ts +92 -0
- package/src/features/alertDialog/DialogContext.tsx +3 -1
- package/src/features/auth/AuthProvider.tsx +254 -39
- package/src/features/auth/backends/index.ts +8 -0
- package/src/features/auth/backends/shellui.spec.ts +201 -0
- package/src/features/auth/backends/shellui.ts +93 -16
- package/src/features/auth/backends/supabase.ts +8 -0
- package/src/features/auth/backends/types.ts +16 -1
- package/src/features/auth/components/LoginButton.tsx +26 -2
- package/src/features/auth/components/LoginView.tsx +114 -133
- package/src/features/auth/components/SessionLoadingView.tsx +21 -0
- package/src/features/auth/hooks/useAuth.tsx +12 -0
- package/src/features/auth/shellAccountRequests.ts +76 -0
- package/src/features/auth/utils/authRequestError.ts +4 -1
- package/src/features/auth/utils/authSessionPersistence.spec.ts +11 -0
- package/src/features/auth/utils/authSessionPersistence.ts +12 -0
- package/src/features/auth/utils/index.ts +4 -0
- package/src/features/auth/utils/resolveLoginSettings.spec.ts +33 -0
- package/src/features/auth/utils/resolveLoginSettings.ts +33 -0
- package/src/features/auth/utils/shareInFlight.spec.ts +41 -0
- package/src/features/auth/utils/shareInFlight.ts +14 -0
- package/src/features/config/ConfigProvider.ts +9 -1
- package/src/features/config/types.ts +43 -0
- package/src/features/layouts/appbar/AppBarLayout.tsx +8 -3
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +41 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +9 -4
- package/src/features/layouts/sidebar/SidebarLayout.tsx +9 -4
- package/src/features/layouts/utils.ts +6 -2
- package/src/features/layouts/windows/WindowsLayout.tsx +8 -3
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +6 -6
- package/src/features/security/trustedFrames.spec.ts +65 -0
- package/src/features/security/trustedFrames.ts +52 -0
- package/src/features/settings/SettingsIcons.tsx +17 -0
- package/src/features/settings/SettingsProvider.tsx +28 -3
- package/src/features/settings/SettingsRoutes.tsx +8 -0
- package/src/features/settings/SettingsView.tsx +21 -4
- package/src/features/settings/components/Ai.tsx +830 -0
- package/src/features/settings/components/Develop.tsx +4 -0
- package/src/features/settings/components/Storage.tsx +197 -32
- package/src/features/settings/components/UserSettingsPanel.tsx +160 -12
- package/src/features/settings/components/createUserSettingsRoute.tsx +4 -0
- package/src/features/settings/components/develop/AiTestTools.tsx +231 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +54 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +15 -1
- package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +6 -0
- package/src/features/settings/utils/shouldShowStorageSettings.spec.ts +49 -0
- package/src/features/settings/utils/shouldShowStorageSettings.ts +19 -0
- package/src/features/storage/uploads/UploadToastCard.tsx +2 -442
- package/src/features/storage/uploads/UploadToaster.tsx +2 -44
- package/src/features/storage/uploads/uploadQueue.ts +128 -308
- package/src/features/storage/uploads/useUploadQueue.ts +7 -3
- package/src/features/transfers/TransferToastCard.tsx +467 -0
- package/src/features/transfers/TransferToaster.tsx +50 -0
- package/src/features/transfers/index.ts +33 -0
- package/src/features/transfers/transferQueue.spec.ts +97 -0
- package/src/features/transfers/transferQueue.ts +442 -0
- package/src/features/transfers/types.ts +38 -0
- package/src/features/transfers/useTransferQueue.ts +30 -0
- package/src/i18n/translations/en/common.json +46 -2
- package/src/i18n/translations/en/settings.json +151 -2
- package/src/i18n/translations/fr/common.json +46 -2
- package/src/i18n/translations/fr/settings.json +151 -2
- package/src/index.css +57 -4
- package/src/index.ts +1 -0
- package/src/routes/components/NavigationItemRoute.tsx +2 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import type { AuthSession } from '../types';
|
|
3
|
+
import { AuthRequestError } from '../utils/authRequestError';
|
|
4
|
+
import { createShellUIAuthBackend } from './shellui';
|
|
5
|
+
|
|
6
|
+
vi.mock('../../config/useConfig', () => ({ useConfig: () => ({ config: {} }) }));
|
|
7
|
+
|
|
8
|
+
const jsonResponse = (status: number, body: unknown) =>
|
|
9
|
+
new Response(JSON.stringify(body), {
|
|
10
|
+
status,
|
|
11
|
+
headers: { 'Content-Type': 'application/json' },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('shellui backend sendMagicLink', () => {
|
|
15
|
+
const fetchMock = vi.fn();
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
const storage = new Map<string, string>([['shellui_auth_client_device_id', 'device-1']]);
|
|
19
|
+
vi.stubGlobal('window', { location: { origin: 'https://app.example.com' } });
|
|
20
|
+
vi.stubGlobal('localStorage', {
|
|
21
|
+
getItem: (key: string) => storage.get(key) ?? null,
|
|
22
|
+
setItem: (key: string, value: string) => storage.set(key, value),
|
|
23
|
+
});
|
|
24
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
fetchMock.mockReset();
|
|
29
|
+
vi.unstubAllGlobals();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('posts to /api/v1/magic-link/request with company and redirect_to', async () => {
|
|
33
|
+
fetchMock.mockResolvedValue(jsonResponse(200, { ok: true }));
|
|
34
|
+
const backend = createShellUIAuthBackend({
|
|
35
|
+
backendUrl: 'https://auth.example.com',
|
|
36
|
+
companyId: 7,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await backend.sendMagicLink('ada@acme.com', '/login/callback?next=%2Fapps');
|
|
40
|
+
|
|
41
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
42
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
43
|
+
expect(url).toBe('https://auth.example.com/api/v1/magic-link/request');
|
|
44
|
+
expect(init.method).toBe('POST');
|
|
45
|
+
const body = JSON.parse(init.body as string) as Record<string, unknown>;
|
|
46
|
+
expect(body).toMatchObject({
|
|
47
|
+
company_id: 7,
|
|
48
|
+
email: 'ada@acme.com',
|
|
49
|
+
redirect_to: 'https://app.example.com/login/callback?next=%2Fapps',
|
|
50
|
+
client_device_id: 'device-1',
|
|
51
|
+
});
|
|
52
|
+
expect(body).not.toHaveProperty('email_redirect_to');
|
|
53
|
+
expect(body).not.toHaveProperty('language');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('sends the UI language so the email is localized', async () => {
|
|
57
|
+
fetchMock.mockResolvedValue(jsonResponse(200, { ok: true }));
|
|
58
|
+
const backend = createShellUIAuthBackend({
|
|
59
|
+
backendUrl: 'https://auth.example.com',
|
|
60
|
+
companyId: 7,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await backend.sendMagicLink('ada@acme.com', '/login/callback', { language: 'fr' });
|
|
64
|
+
|
|
65
|
+
const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
66
|
+
const body = JSON.parse(init.body as string) as Record<string, unknown>;
|
|
67
|
+
expect(body.language).toBe('fr');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('throws AuthRequestError with error_code when disabled', async () => {
|
|
71
|
+
fetchMock.mockResolvedValue(
|
|
72
|
+
jsonResponse(403, {
|
|
73
|
+
error: 'Magic link sign-in is disabled for this company.',
|
|
74
|
+
error_code: 'magic_link_disabled',
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
const backend = createShellUIAuthBackend({
|
|
78
|
+
backendUrl: 'https://auth.example.com',
|
|
79
|
+
companyId: '7',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const error = await backend.sendMagicLink('ada@acme.com', '/login/callback').catch((e) => e);
|
|
83
|
+
expect(error).toBeInstanceOf(AuthRequestError);
|
|
84
|
+
expect((error as AuthRequestError).message).toBe(
|
|
85
|
+
'Magic link sign-in is disabled for this company.',
|
|
86
|
+
);
|
|
87
|
+
expect((error as AuthRequestError).code).toBe('magic_link_disabled');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('requires a company id', async () => {
|
|
91
|
+
const backend = createShellUIAuthBackend({ backendUrl: 'https://auth.example.com' });
|
|
92
|
+
|
|
93
|
+
await expect(backend.sendMagicLink('ada@acme.com', '/login/callback')).rejects.toThrow(
|
|
94
|
+
'Missing company_id for magic link request.',
|
|
95
|
+
);
|
|
96
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('shellui backend updateProfile', () => {
|
|
101
|
+
const fetchMock = vi.fn();
|
|
102
|
+
const session = { accessToken: 'access-1' } as AuthSession;
|
|
103
|
+
|
|
104
|
+
beforeEach(() => {
|
|
105
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
afterEach(() => {
|
|
109
|
+
fetchMock.mockReset();
|
|
110
|
+
vi.unstubAllGlobals();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('sends PATCH /api/v1/user and returns the stored name', async () => {
|
|
114
|
+
fetchMock.mockResolvedValue(jsonResponse(200, { user_metadata: { name: 'Ada Lovelace' } }));
|
|
115
|
+
const backend = createShellUIAuthBackend({ backendUrl: 'https://auth.example.com' });
|
|
116
|
+
|
|
117
|
+
const result = await backend.updateProfile(session, { name: ' Ada Lovelace ' });
|
|
118
|
+
|
|
119
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
120
|
+
expect(url).toBe('https://auth.example.com/api/v1/user');
|
|
121
|
+
expect(init.method).toBe('PATCH');
|
|
122
|
+
expect((init.headers as Record<string, string>).Authorization).toBe('Bearer access-1');
|
|
123
|
+
expect(JSON.parse(init.body as string)).toEqual({ name: ' Ada Lovelace ' });
|
|
124
|
+
expect(result).toEqual({ name: 'Ada Lovelace' });
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('surfaces field validation messages', async () => {
|
|
128
|
+
fetchMock.mockResolvedValue(jsonResponse(400, { name: ['Name cannot be blank.'] }));
|
|
129
|
+
const backend = createShellUIAuthBackend({ backendUrl: 'https://auth.example.com' });
|
|
130
|
+
|
|
131
|
+
await expect(backend.updateProfile(session, { name: ' ' })).rejects.toThrow(
|
|
132
|
+
'Name cannot be blank.',
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('shellui backend deleteAccount', () => {
|
|
138
|
+
const fetchMock = vi.fn();
|
|
139
|
+
const session = { accessToken: 'access-1', refreshToken: 'refresh-1' } as AuthSession;
|
|
140
|
+
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
afterEach(() => {
|
|
146
|
+
fetchMock.mockReset();
|
|
147
|
+
vi.unstubAllGlobals();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('sends DELETE /api/v1/user with bearer token and no company id', async () => {
|
|
151
|
+
fetchMock.mockResolvedValue(new Response(null, { status: 204 }));
|
|
152
|
+
const backend = createShellUIAuthBackend({
|
|
153
|
+
backendUrl: 'https://auth.example.com',
|
|
154
|
+
companyId: 7,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
await backend.deleteAccount(session);
|
|
158
|
+
|
|
159
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
160
|
+
expect(url).toBe('https://auth.example.com/api/v1/user');
|
|
161
|
+
expect(init.method).toBe('DELETE');
|
|
162
|
+
expect((init.headers as Record<string, string>).Authorization).toBe('Bearer access-1');
|
|
163
|
+
expect(JSON.parse(init.body as string)).toEqual({ confirm: true, refresh_token: 'refresh-1' });
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('surfaces recent_login_required as an AuthRequestError', async () => {
|
|
167
|
+
fetchMock.mockResolvedValue(
|
|
168
|
+
jsonResponse(403, {
|
|
169
|
+
error: 'Sign in again before deleting your account.',
|
|
170
|
+
error_code: 'recent_login_required',
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
const backend = createShellUIAuthBackend({ backendUrl: 'https://auth.example.com' });
|
|
174
|
+
|
|
175
|
+
const error = await backend.deleteAccount(session).catch((e) => e);
|
|
176
|
+
expect(error).toBeInstanceOf(AuthRequestError);
|
|
177
|
+
expect((error as AuthRequestError).code).toBe('recent_login_required');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('keeps the companies list when the user is the last owner', async () => {
|
|
181
|
+
fetchMock.mockResolvedValue(
|
|
182
|
+
jsonResponse(409, {
|
|
183
|
+
error: 'You are the only owner of Acme. Add another owner before deleting your account.',
|
|
184
|
+
error_code: 'last_company_owner',
|
|
185
|
+
companies: [{ id: 7, name: 'Acme' }],
|
|
186
|
+
}),
|
|
187
|
+
);
|
|
188
|
+
const backend = createShellUIAuthBackend({ backendUrl: 'https://auth.example.com' });
|
|
189
|
+
|
|
190
|
+
const error = (await backend.deleteAccount(session).catch((e) => e)) as AuthRequestError;
|
|
191
|
+
expect(error.code).toBe('last_company_owner');
|
|
192
|
+
expect(error.details.companies).toEqual([{ id: 7, name: 'Acme' }]);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('requires a session', async () => {
|
|
196
|
+
const backend = createShellUIAuthBackend({ backendUrl: 'https://auth.example.com' });
|
|
197
|
+
|
|
198
|
+
await expect(backend.deleteAccount(null)).rejects.toBeInstanceOf(AuthRequestError);
|
|
199
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -15,6 +15,8 @@ import type { AuthBackend } from './types';
|
|
|
15
15
|
const USER_PREFERENCES_ENDPOINT = '/api/v1/preferences';
|
|
16
16
|
const OAUTH_EXCHANGE_ENDPOINT = '/api/v1/oauth/exchange';
|
|
17
17
|
const OAUTH_SESSION_ENDPOINT = '/api/v1/oauth/session';
|
|
18
|
+
const MAGIC_LINK_REQUEST_ENDPOINT = '/api/v1/magic-link/request';
|
|
19
|
+
const USER_ENDPOINT = '/api/v1/user';
|
|
18
20
|
|
|
19
21
|
const parseAuthErrorPayload = (
|
|
20
22
|
payload: Record<string, unknown> | null,
|
|
@@ -200,6 +202,73 @@ export const createShellUIAuthBackend = ({
|
|
|
200
202
|
}),
|
|
201
203
|
});
|
|
202
204
|
},
|
|
205
|
+
supportsAccountDeletion: true,
|
|
206
|
+
deleteAccount: async (session) => {
|
|
207
|
+
if (!backendUrl) {
|
|
208
|
+
throw new Error('Missing Shellui backend URL.');
|
|
209
|
+
}
|
|
210
|
+
if (!session?.accessToken) {
|
|
211
|
+
throw new AuthRequestError(
|
|
212
|
+
'Sign in again, then delete your account.',
|
|
213
|
+
'recent_login_required',
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
// Company comes from the access token so only the current company is affected.
|
|
217
|
+
const response = await fetch(`${backendUrl}${USER_ENDPOINT}`, {
|
|
218
|
+
method: 'DELETE',
|
|
219
|
+
headers: {
|
|
220
|
+
Accept: 'application/json',
|
|
221
|
+
'Content-Type': 'application/json',
|
|
222
|
+
Authorization: `Bearer ${session.accessToken}`,
|
|
223
|
+
},
|
|
224
|
+
body: JSON.stringify({
|
|
225
|
+
confirm: true,
|
|
226
|
+
...(session.refreshToken ? { refresh_token: session.refreshToken } : {}),
|
|
227
|
+
}),
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
const payload = (await response.json().catch(() => null)) as Record<string, unknown> | null;
|
|
231
|
+
const err = payload?.error ?? payload?.detail;
|
|
232
|
+
const message =
|
|
233
|
+
typeof err === 'string' && err.trim()
|
|
234
|
+
? err
|
|
235
|
+
: `Could not delete account (HTTP ${response.status}).`;
|
|
236
|
+
const errorCode =
|
|
237
|
+
typeof payload?.error_code === 'string' ? payload.error_code.trim() || null : null;
|
|
238
|
+
throw new AuthRequestError(message, errorCode, payload ?? undefined);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
supportsProfileUpdate: true,
|
|
242
|
+
updateProfile: async (session, { name }) => {
|
|
243
|
+
if (!backendUrl) {
|
|
244
|
+
throw new Error('Missing Shellui backend URL.');
|
|
245
|
+
}
|
|
246
|
+
if (!session?.accessToken) {
|
|
247
|
+
throw new AuthRequestError('Sign in again, then update your name.', 'unauthorized');
|
|
248
|
+
}
|
|
249
|
+
const response = await fetch(`${backendUrl}${USER_ENDPOINT}`, {
|
|
250
|
+
method: 'PATCH',
|
|
251
|
+
headers: {
|
|
252
|
+
Accept: 'application/json',
|
|
253
|
+
'Content-Type': 'application/json',
|
|
254
|
+
Authorization: `Bearer ${session.accessToken}`,
|
|
255
|
+
},
|
|
256
|
+
body: JSON.stringify({ name }),
|
|
257
|
+
});
|
|
258
|
+
const payload = (await response.json().catch(() => null)) as Record<string, unknown> | null;
|
|
259
|
+
if (!response.ok) {
|
|
260
|
+
const fieldErrors = Array.isArray(payload?.name) ? payload.name : [];
|
|
261
|
+
const err = payload?.error ?? payload?.detail ?? fieldErrors[0];
|
|
262
|
+
const message =
|
|
263
|
+
typeof err === 'string' && err.trim()
|
|
264
|
+
? err
|
|
265
|
+
: `Could not update name (HTTP ${response.status}).`;
|
|
266
|
+
throw new AuthRequestError(message, null, payload ?? undefined);
|
|
267
|
+
}
|
|
268
|
+
const metadata = payload?.user_metadata as Record<string, unknown> | undefined;
|
|
269
|
+
const savedName = typeof metadata?.name === 'string' ? metadata.name : name;
|
|
270
|
+
return { name: savedName };
|
|
271
|
+
},
|
|
203
272
|
getAuthSettings: async () => {
|
|
204
273
|
if (!backendUrl) {
|
|
205
274
|
return { methods: [], oauthProviders: [], oauthClients: [] };
|
|
@@ -219,35 +288,43 @@ export const createShellUIAuthBackend = ({
|
|
|
219
288
|
const payload = (await response.json()) as unknown;
|
|
220
289
|
return normalizeAuthSettings(payload);
|
|
221
290
|
},
|
|
222
|
-
sendMagicLink: async (email, redirectPath) => {
|
|
291
|
+
sendMagicLink: async (email, redirectPath, options) => {
|
|
223
292
|
if (!backendUrl) {
|
|
224
293
|
throw new Error('Missing Shellui backend URL.');
|
|
225
294
|
}
|
|
226
|
-
const
|
|
227
|
-
|
|
295
|
+
const selectedCompanyId = getShellUILoginCompanyId(companyId);
|
|
296
|
+
if (!selectedCompanyId) {
|
|
297
|
+
throw new Error('Missing company_id for magic link request.');
|
|
298
|
+
}
|
|
299
|
+
const redirectTo = `${window.location.origin}${normalizeRedirectPath(redirectPath)}`;
|
|
300
|
+
const clientTz = getShellUILoginClientTimezone();
|
|
301
|
+
const clientDeviceId = getShellUILoginDeviceId();
|
|
302
|
+
const language = options?.language?.trim();
|
|
303
|
+
const response = await fetch(`${backendUrl}${MAGIC_LINK_REQUEST_ENDPOINT}`, {
|
|
228
304
|
method: 'POST',
|
|
229
305
|
headers: {
|
|
230
306
|
Accept: 'application/json',
|
|
231
307
|
'Content-Type': 'application/json',
|
|
232
308
|
},
|
|
233
309
|
body: JSON.stringify({
|
|
310
|
+
company_id: Number(selectedCompanyId),
|
|
234
311
|
email,
|
|
235
|
-
|
|
236
|
-
|
|
312
|
+
redirect_to: redirectTo,
|
|
313
|
+
...(clientTz ? { client_timezone: clientTz } : {}),
|
|
314
|
+
...(clientDeviceId ? { client_device_id: clientDeviceId } : {}),
|
|
315
|
+
...(language ? { language } : {}),
|
|
237
316
|
}),
|
|
238
317
|
});
|
|
239
318
|
if (!response.ok) {
|
|
240
|
-
const payload = (await response.json().catch(() => null)) as
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
`Could not send magic link (HTTP ${response.status}).`,
|
|
250
|
-
);
|
|
319
|
+
const payload = (await response.json().catch(() => null)) as Record<string, unknown> | null;
|
|
320
|
+
const err = payload?.error ?? payload?.detail;
|
|
321
|
+
const message =
|
|
322
|
+
typeof err === 'string' && err.trim()
|
|
323
|
+
? err
|
|
324
|
+
: `Could not send magic link (HTTP ${response.status}).`;
|
|
325
|
+
const errorCode =
|
|
326
|
+
typeof payload?.error_code === 'string' ? payload.error_code.trim() || null : null;
|
|
327
|
+
throw new AuthRequestError(message, errorCode);
|
|
251
328
|
}
|
|
252
329
|
},
|
|
253
330
|
syncUserPreferences: async (session, preferences: UserPreferences) => {
|
|
@@ -178,6 +178,14 @@ export const createSupabaseAuthBackend = ({
|
|
|
178
178
|
},
|
|
179
179
|
});
|
|
180
180
|
},
|
|
181
|
+
supportsAccountDeletion: false,
|
|
182
|
+
deleteAccount: async () => {
|
|
183
|
+
throw new Error('Account deletion is not supported by the Supabase backend.');
|
|
184
|
+
},
|
|
185
|
+
supportsProfileUpdate: false,
|
|
186
|
+
updateProfile: async () => {
|
|
187
|
+
throw new Error('Profile updates are not supported by the Supabase backend.');
|
|
188
|
+
},
|
|
181
189
|
getAuthSettings: async () => {
|
|
182
190
|
if (!backendUrl) {
|
|
183
191
|
return { methods: [], oauthProviders: [], oauthClients: [] };
|
|
@@ -28,8 +28,23 @@ export interface AuthBackend {
|
|
|
28
28
|
startOAuth: (provider: string, redirectPath: string, oauthClientId?: number) => void;
|
|
29
29
|
startWeb3Ethereum: () => Promise<AuthSession | null>;
|
|
30
30
|
logout: (session: AuthSession | null) => Promise<void>;
|
|
31
|
+
/** Whether {@link deleteAccount} is implemented for this backend. */
|
|
32
|
+
supportsAccountDeletion: boolean;
|
|
33
|
+
/** Permanently delete the signed-in user for the session's company. */
|
|
34
|
+
deleteAccount: (session: AuthSession | null) => Promise<void>;
|
|
35
|
+
/** Whether {@link updateProfile} is implemented for this backend. */
|
|
36
|
+
supportsProfileUpdate: boolean;
|
|
37
|
+
/** Update the signed-in user's display name; resolves with the name as stored. */
|
|
38
|
+
updateProfile: (
|
|
39
|
+
session: AuthSession | null,
|
|
40
|
+
profile: { name: string },
|
|
41
|
+
) => Promise<{ name: string }>;
|
|
31
42
|
getAuthSettings: () => Promise<AuthSettings>;
|
|
32
|
-
sendMagicLink: (
|
|
43
|
+
sendMagicLink: (
|
|
44
|
+
email: string,
|
|
45
|
+
redirectPath: string,
|
|
46
|
+
options?: { language?: string },
|
|
47
|
+
) => Promise<void>;
|
|
33
48
|
syncUserPreferences: (session: AuthSession | null, preferences: UserPreferences) => Promise<void>;
|
|
34
49
|
loadUserPreferences: (session: AuthSession | null) => Promise<UserPreferences | null>;
|
|
35
50
|
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
DropdownMenuSeparator,
|
|
21
21
|
DropdownMenuTrigger,
|
|
22
22
|
} from '../../../components/ui/dropdown-menu';
|
|
23
|
+
import { Skeleton } from '../../../components/ui/skeleton';
|
|
23
24
|
|
|
24
25
|
type LoginButtonVariant = 'sidebar' | 'appbar' | 'windows';
|
|
25
26
|
|
|
@@ -68,7 +69,7 @@ const SettingsMenuIcon = ({ className }: { className?: string }) => (
|
|
|
68
69
|
const variantConfig: Record<
|
|
69
70
|
LoginButtonVariant,
|
|
70
71
|
{
|
|
71
|
-
button: { authenticated: string; loggedOut: string };
|
|
72
|
+
button: { authenticated: string; loggedOut: string; loading: string };
|
|
72
73
|
avatar: string;
|
|
73
74
|
menu: { width: string; side: 'top' | 'right' | 'bottom'; align: 'start' | 'end' };
|
|
74
75
|
showDisplayName: boolean;
|
|
@@ -81,6 +82,8 @@ const variantConfig: Record<
|
|
|
81
82
|
'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
|
|
82
83
|
loggedOut:
|
|
83
84
|
'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
|
|
85
|
+
loading:
|
|
86
|
+
'w-full h-8 px-2 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
|
|
84
87
|
},
|
|
85
88
|
avatar: 'size-4',
|
|
86
89
|
menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'right', align: 'start' },
|
|
@@ -93,6 +96,7 @@ const variantConfig: Record<
|
|
|
93
96
|
'size-7 rounded-md p-0 justify-center text-xs text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
94
97
|
loggedOut:
|
|
95
98
|
'h-7 max-w-[220px] rounded-md px-2.5 text-xs text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
99
|
+
loading: 'size-7 justify-center',
|
|
96
100
|
},
|
|
97
101
|
avatar: 'size-4',
|
|
98
102
|
menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'bottom', align: 'end' },
|
|
@@ -105,6 +109,7 @@ const variantConfig: Record<
|
|
|
105
109
|
'h-8 w-8 rounded-md p-0 justify-center text-xs text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
106
110
|
loggedOut:
|
|
107
111
|
'h-8 max-w-[180px] rounded-md px-2 text-xs text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
|
|
112
|
+
loading: 'h-8 w-8 justify-center',
|
|
108
113
|
},
|
|
109
114
|
avatar: 'h-4 w-4',
|
|
110
115
|
menu: { width: 'w-[min(15rem,calc(100vw-1.5rem))]', side: 'top', align: 'end' },
|
|
@@ -126,7 +131,7 @@ export const LoginButton = ({
|
|
|
126
131
|
const isMobile = useIsMobile();
|
|
127
132
|
const { t } = useTranslation('common');
|
|
128
133
|
const { config } = useConfig();
|
|
129
|
-
const { isAuthenticated, user, logout } = useAuth();
|
|
134
|
+
const { isAuthenticated, isLoading, user, logout } = useAuth();
|
|
130
135
|
const location = useLocation();
|
|
131
136
|
const navigate = useNavigate();
|
|
132
137
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
@@ -232,6 +237,25 @@ export const LoginButton = ({
|
|
|
232
237
|
return null;
|
|
233
238
|
}
|
|
234
239
|
|
|
240
|
+
if (isLoading) {
|
|
241
|
+
return (
|
|
242
|
+
<div
|
|
243
|
+
role="status"
|
|
244
|
+
aria-label={t('authMenu.loadingAccount')}
|
|
245
|
+
data-shellui-auth-loading=""
|
|
246
|
+
className={cn(
|
|
247
|
+
'inline-flex min-w-0 shrink-0 items-center gap-2',
|
|
248
|
+
currentVariantConfig.button.loading,
|
|
249
|
+
)}
|
|
250
|
+
>
|
|
251
|
+
<Skeleton className={cn('shrink-0 rounded-full', currentVariantConfig.avatar)} />
|
|
252
|
+
{showDisplayName && (
|
|
253
|
+
<Skeleton className="h-3 w-24 max-w-full group-data-[collapsible=icon]:hidden" />
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
235
259
|
if (!isAuthenticated && hideWhenLoggedOut) {
|
|
236
260
|
return null;
|
|
237
261
|
}
|