@micha.bigler/ui-core-micha 3.14.3 → 4.0.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 (367) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +7 -0
  3. package/dist/auth/UserMenu.js +1 -1
  4. package/dist/auth/apiClient.js +7 -6
  5. package/dist/chat/ChatList.js +1 -1
  6. package/dist/chat/ChatThread.js +2 -1
  7. package/dist/chat/ChatWorkspace.js +1 -1
  8. package/dist/chat/ModelPicker.js +2 -5
  9. package/dist/chat/kitSxRegistry.js +9 -0
  10. package/dist/chat/useChatSocket.js +1 -1
  11. package/dist/components/LoginForm.js +1 -1
  12. package/dist/components/SecurityComponent.js +1 -1
  13. package/dist/components/UserListComponent.js +2 -8
  14. package/dist/components/charts/ChartFrame.js +1 -1
  15. package/dist/components/charts/ScatterChart.js +2 -1
  16. package/dist/components/charts/kitSxRegistry.js +6 -0
  17. package/dist/entries/charts.js +6 -0
  18. package/dist/entries/chat.js +8 -0
  19. package/dist/entries/markdown.js +1 -0
  20. package/dist/index.js +0 -14
  21. package/dist/layout/SectionNav.js +1 -1
  22. package/dist/messaging/AttachmentList.js +2 -2
  23. package/dist/messaging/Composer.js +2 -1
  24. package/dist/messaging/ConversationLaunchers.js +1 -4
  25. package/dist/messaging/ConversationList.js +1 -1
  26. package/dist/messaging/DirectMessageLauncher.js +1 -1
  27. package/dist/messaging/MessagingProvider.js +0 -0
  28. package/dist/messaging/PollCard.js +7 -5
  29. package/dist/messaging/ReadTicks.js +2 -2
  30. package/dist/messaging/Thread.js +5 -3
  31. package/dist/notifications/NotificationBell.js +4 -7
  32. package/dist/notifications/NotificationSettings.js +1 -1
  33. package/dist/onboarding/OnboardingProvider.js +3 -6
  34. package/dist/pages/AccountPage.js +1 -2
  35. package/dist/pages/LoginPage.js +2 -3
  36. package/dist/pages/PasswordChangePage.js +2 -3
  37. package/dist/pages/PasswordInvitePage.js +2 -3
  38. package/dist/pages/PasswordResetRequestPage.js +2 -3
  39. package/dist/pages/SignUpPage.js +2 -3
  40. package/dist/pages/SignupConfirmPage.js +2 -3
  41. package/dist/theme/createAppTheme.js +5 -4
  42. package/dist/theme/kitSxEntry.js +11 -0
  43. package/dist/theme/kitSxRegistry.js +2 -15
  44. package/dist/theme/themeCompleteness.js +3 -12
  45. package/dist/utils/auth-errors.js +4 -3
  46. package/package.json +41 -16
  47. package/.github/workflows/publish.yml +0 -126
  48. package/DESIGN.md +0 -60
  49. package/WORK_ORDERS.md +0 -148
  50. package/dev/entries.jsx +0 -721
  51. package/dev/fixtures.js +0 -26
  52. package/dev/main.jsx +0 -75
  53. package/dev/mockTransport.jsx +0 -128
  54. package/docs/CHART-LAYOUT.md +0 -157
  55. package/docs/DARK-TOKENS.md +0 -140
  56. package/docs/TYPE-SCALE.md +0 -111
  57. package/docs/messaging-deviations.md +0 -118
  58. package/index.html +0 -12
  59. package/renovate.json +0 -10
  60. package/scripts/chart-api-census.mjs +0 -415
  61. package/src/auth/AuthContext.jsx +0 -158
  62. package/src/auth/ReauthModal.jsx +0 -82
  63. package/src/auth/UserMenu.jsx +0 -121
  64. package/src/auth/apiClient.jsx +0 -232
  65. package/src/auth/authApi.jsx +0 -539
  66. package/src/auth/authConfig.jsx +0 -34
  67. package/src/auth/reauth.js +0 -47
  68. package/src/chat/ChatComposer.jsx +0 -36
  69. package/src/chat/ChatList.jsx +0 -87
  70. package/src/chat/ChatThread.jsx +0 -128
  71. package/src/chat/ChatWorkspace.jsx +0 -244
  72. package/src/chat/MarkdownReply.jsx +0 -22
  73. package/src/chat/ModelPicker.jsx +0 -85
  74. package/src/chat/api.js +0 -18
  75. package/src/chat/useChatSocket.js +0 -32
  76. package/src/chat/wire.js +0 -7
  77. package/src/components/AccessCodeManager.jsx +0 -288
  78. package/src/components/AccessCodeSingleUseToggle.jsx +0 -92
  79. package/src/components/AllowedEmailDomainsManager.jsx +0 -92
  80. package/src/components/AuthFactorRequirementCard.jsx +0 -95
  81. package/src/components/BulkInviteCsvTab.jsx +0 -198
  82. package/src/components/EmptyState.jsx +0 -38
  83. package/src/components/LoginForm.jsx +0 -159
  84. package/src/components/MFAComponent.jsx +0 -350
  85. package/src/components/MfaLoginComponent.jsx +0 -252
  86. package/src/components/MobileBottomNav.jsx +0 -82
  87. package/src/components/PasskeysComponent.jsx +0 -252
  88. package/src/components/PasswordChangeForm.jsx +0 -87
  89. package/src/components/PasswordResetRequestForm.jsx +0 -43
  90. package/src/components/PasswordSetForm.jsx +0 -97
  91. package/src/components/ProfileComponent.jsx +0 -348
  92. package/src/components/QrSignupManager.jsx +0 -404
  93. package/src/components/QrSignupValidityManager.jsx +0 -106
  94. package/src/components/RegistrationMethodsManager.jsx +0 -150
  95. package/src/components/SecurityComponent.jsx +0 -141
  96. package/src/components/SocialLoginButtons.jsx +0 -83
  97. package/src/components/SoftChip.jsx +0 -93
  98. package/src/components/StatTile.jsx +0 -39
  99. package/src/components/SupportRecoveryRequestsTab.jsx +0 -482
  100. package/src/components/TurnstileWidget.jsx +0 -99
  101. package/src/components/UserInviteComponent.jsx +0 -76
  102. package/src/components/UserListComponent.jsx +0 -618
  103. package/src/components/charts/BarChart.jsx +0 -102
  104. package/src/components/charts/ChartFrame.jsx +0 -214
  105. package/src/components/charts/LineChart.jsx +0 -126
  106. package/src/components/charts/ScatterChart.jsx +0 -299
  107. package/src/components/charts/TimeSeriesChart.jsx +0 -300
  108. package/src/components/charts/chartDefaults.js +0 -644
  109. package/src/components/charts/chartLabels.js +0 -36
  110. package/src/components/charts/exportChart.js +0 -258
  111. package/src/components/charts/formatters.js +0 -39
  112. package/src/components/charts/palette.js +0 -33
  113. package/src/components/charts/yearTickInterval.js +0 -7
  114. package/src/i18n/authTranslations.ts +0 -2651
  115. package/src/i18n/chartsTranslations.ts +0 -91
  116. package/src/i18n/chatTranslations.ts +0 -55
  117. package/src/i18n/messagingTranslations.ts +0 -120
  118. package/src/i18n/notificationsTranslations.ts +0 -32
  119. package/src/i18n/onboardingTranslations.ts +0 -29
  120. package/src/i18n/sectionNavTranslations.ts +0 -20
  121. package/src/i18n/uiCoreTranslations.js +0 -29
  122. package/src/i18n/userMenuTranslations.ts +0 -5
  123. package/src/index.js +0 -158
  124. package/src/layout/PageLayout.jsx +0 -36
  125. package/src/layout/SectionNav.jsx +0 -320
  126. package/src/messaging/AttachmentList.jsx +0 -145
  127. package/src/messaging/Composer.jsx +0 -197
  128. package/src/messaging/ConversationLaunchers.jsx +0 -51
  129. package/src/messaging/ConversationList.jsx +0 -109
  130. package/src/messaging/DirectMessageLauncher.jsx +0 -112
  131. package/src/messaging/MessageBubble.jsx +0 -183
  132. package/src/messaging/MessagingProvider.jsx +0 -0
  133. package/src/messaging/MessagingScopeConfig.jsx +0 -24
  134. package/src/messaging/PollCard.jsx +0 -163
  135. package/src/messaging/ReactionBar.jsx +0 -43
  136. package/src/messaging/ReadTicks.jsx +0 -82
  137. package/src/messaging/Thread.jsx +0 -195
  138. package/src/messaging/api.js +0 -48
  139. package/src/messaging/composerImageCompression.js +0 -35
  140. package/src/messaging/linkifyText.jsx +0 -37
  141. package/src/notifications/NotificationBell.jsx +0 -84
  142. package/src/notifications/NotificationSettings.jsx +0 -330
  143. package/src/notifications/NotificationsProvider.jsx +0 -224
  144. package/src/notifications/PopupSurface.jsx +0 -105
  145. package/src/notifications/api.js +0 -55
  146. package/src/notifications/feedApi.js +0 -18
  147. package/src/notifications/realtime.jsx +0 -138
  148. package/src/notifications/serviceWorker/sw.js +0 -50
  149. package/src/onboarding/OnboardingProvider.jsx +0 -326
  150. package/src/onboarding/OnboardingWizard.jsx +0 -61
  151. package/src/onboarding/WizardDialogShell.jsx +0 -51
  152. package/src/onboarding/api.js +0 -13
  153. package/src/onboarding/stepSelection.js +0 -16
  154. package/src/onboarding/steps/BrowserPushStep.jsx +0 -121
  155. package/src/onboarding/steps/CompleteNameStep.jsx +0 -46
  156. package/src/onboarding/steps/CookieConsentStep.jsx +0 -133
  157. package/src/onboarding/steps/PwaInstallStep.jsx +0 -47
  158. package/src/pages/AccountPage.jsx +0 -394
  159. package/src/pages/LoginPage.jsx +0 -343
  160. package/src/pages/PasswordChangePage.jsx +0 -62
  161. package/src/pages/PasswordInvitePage.jsx +0 -177
  162. package/src/pages/PasswordResetRequestPage.jsx +0 -68
  163. package/src/pages/SignUpPage.jsx +0 -268
  164. package/src/pages/SignupConfirmPage.jsx +0 -155
  165. package/src/testing/checkKitIntegration.js +0 -233
  166. package/src/theme/createAppTheme.js +0 -423
  167. package/src/theme/fonts.js +0 -3
  168. package/src/theme/index.js +0 -21
  169. package/src/theme/kitSxRegistry.js +0 -285
  170. package/src/theme/themeCompleteness.js +0 -1045
  171. package/src/theme/tokens.js +0 -478
  172. package/src/utils/auth-errors.js +0 -76
  173. package/src/utils/authService.js +0 -223
  174. package/src/utils/resolveErrorText.js +0 -28
  175. package/src/utils/webauthn.js +0 -51
  176. package/tests/AccountPage.profileStatements.test.jsx +0 -162
  177. package/tests/AccountPage.test.jsx +0 -200
  178. package/tests/AuthContext.test.jsx +0 -129
  179. package/tests/BarChart.test.jsx +0 -112
  180. package/tests/BrowserPushStep.test.jsx +0 -110
  181. package/tests/ChartFrame.test.jsx +0 -336
  182. package/tests/ConversationList.test.jsx +0 -144
  183. package/tests/CookieConsentStep.test.jsx +0 -69
  184. package/tests/EmptyState.test.jsx +0 -62
  185. package/tests/LineChart.test.jsx +0 -80
  186. package/tests/MessagingProvider.test.jsx +0 -50
  187. package/tests/MobileBottomNav.test.jsx +0 -319
  188. package/tests/NotificationBell.test.jsx +0 -60
  189. package/tests/NotificationSettings.test.jsx +0 -276
  190. package/tests/NotificationsProvider.test.jsx +0 -240
  191. package/tests/OnboardingProvider.test.jsx +0 -294
  192. package/tests/OnboardingWizard.test.jsx +0 -143
  193. package/tests/PasswordChangeForm.test.jsx +0 -70
  194. package/tests/PasswordInvitePage.test.jsx +0 -142
  195. package/tests/PasswordSetForm.test.jsx +0 -70
  196. package/tests/PopupSurface.test.jsx +0 -142
  197. package/tests/ProfileComponent.refresh.test.jsx +0 -194
  198. package/tests/QrSignupManager.registrationContext.test.jsx +0 -106
  199. package/tests/QrSignupManagerInfoBox.test.jsx +0 -49
  200. package/tests/ScatterChart.test.jsx +0 -270
  201. package/tests/SectionNav.test.jsx +0 -363
  202. package/tests/SignUpPage.test.jsx +0 -208
  203. package/tests/SoftChip.test.jsx +0 -105
  204. package/tests/StatTile.test.jsx +0 -57
  205. package/tests/Thread.test.jsx +0 -151
  206. package/tests/TimeSeriesChart.test.jsx +0 -367
  207. package/tests/UserListComponent.test.jsx +0 -192
  208. package/tests/UserMenu.test.jsx +0 -171
  209. package/tests/apiClientLanguage.test.js +0 -33
  210. package/tests/apiClientPublicPaths.test.js +0 -178
  211. package/tests/authApiLogin.test.js +0 -42
  212. package/tests/authApiRegistration.test.js +0 -31
  213. package/tests/authErrorCodeRendering.test.jsx +0 -77
  214. package/tests/authErrors.test.js +0 -74
  215. package/tests/authTranslations.test.js +0 -74
  216. package/tests/chart-api-census.test.js +0 -366
  217. package/tests/chartAxisTickBand.test.jsx +0 -95
  218. package/tests/chartDefaults.test.js +0 -902
  219. package/tests/chartLabels.test.js +0 -50
  220. package/tests/chartsPalette.test.js +0 -99
  221. package/tests/chatApi.test.js +0 -48
  222. package/tests/chatDriverNames.test.jsx +0 -71
  223. package/tests/chatExports.test.js +0 -3
  224. package/tests/chatList.test.jsx +0 -84
  225. package/tests/chatPicker.test.jsx +0 -82
  226. package/tests/chatSocket.test.jsx +0 -26
  227. package/tests/chatThread.test.jsx +0 -116
  228. package/tests/chatTranslations.test.js +0 -47
  229. package/tests/chatWorkspace.test.jsx +0 -234
  230. package/tests/checkKitIntegration.test.jsx +0 -219
  231. package/tests/createAppTheme.test.js +0 -132
  232. package/tests/createAppThemeDark.test.js +0 -127
  233. package/tests/createAppThemeLightGuard.test.js +0 -40
  234. package/tests/createAppThemePageContrast.test.js +0 -108
  235. package/tests/createAppThemeTypography.test.js +0 -53
  236. package/tests/errorCallSiteGuard.test.js +0 -32
  237. package/tests/exportChart.test.js +0 -313
  238. package/tests/feedApi.test.js +0 -46
  239. package/tests/fixtures/light-theme-baseline.json +0 -2234
  240. package/tests/i18nAggregate.test.js +0 -120
  241. package/tests/i18nGermanVariant.test.js +0 -65
  242. package/tests/loginPageErrorResolution.test.jsx +0 -102
  243. package/tests/messagingApi.test.js +0 -32
  244. package/tests/messagingChunk6.test.jsx +0 -116
  245. package/tests/messagingCompactBubble.test.jsx +0 -64
  246. package/tests/messagingComposer.test.jsx +0 -136
  247. package/tests/messagingComposerChunk5.test.jsx +0 -113
  248. package/tests/messagingContractConformance.test.js +0 -69
  249. package/tests/messagingDirectMessageLauncher.test.jsx +0 -151
  250. package/tests/messagingExports.test.js +0 -21
  251. package/tests/messagingInteractions.test.jsx +0 -136
  252. package/tests/messagingLastMessagePreview.test.jsx +0 -93
  253. package/tests/messagingLinkify.test.jsx +0 -51
  254. package/tests/messagingMessageActions.test.jsx +0 -163
  255. package/tests/messagingMsg6.test.jsx +0 -105
  256. package/tests/messagingMsg6f.test.jsx +0 -155
  257. package/tests/messagingMsg6g.test.jsx +0 -166
  258. package/tests/messagingMsg6h.test.jsx +0 -136
  259. package/tests/messagingMsg6i.test.jsx +0 -129
  260. package/tests/messagingPollRendering.test.jsx +0 -142
  261. package/tests/messagingReactionMerge.test.jsx +0 -77
  262. package/tests/messagingReadTicksTooltip.test.jsx +0 -36
  263. package/tests/messagingThreadReceipts.test.jsx +0 -178
  264. package/tests/messagingThreadingQuoting.test.jsx +0 -87
  265. package/tests/messagingUnreadLifecycle.test.jsx +0 -78
  266. package/tests/notificationsApi.test.js +0 -41
  267. package/tests/notificationsExports.test.js +0 -34
  268. package/tests/onboardingDescriptors.test.js +0 -132
  269. package/tests/packageTreeShaking.test.js +0 -126
  270. package/tests/realtime.test.jsx +0 -219
  271. package/tests/resolveErrorText.test.js +0 -72
  272. package/tests/stepSelection.test.js +0 -53
  273. package/tests/themeCompleteness.test.js +0 -626
  274. package/tests/timeSeriesLegend.test.js +0 -99
  275. package/tests/userScreenTranslations.test.jsx +0 -218
  276. package/tsconfig.build.json +0 -18
  277. package/vite.config.mjs +0 -6
  278. package/work-orders/AUTH-1.md +0 -74
  279. package/work-orders/AUTH-2.md +0 -74
  280. package/work-orders/AUTH-4.md +0 -183
  281. package/work-orders/AUTH-5.md +0 -154
  282. package/work-orders/AUTH-7.md +0 -181
  283. package/work-orders/AUTH-8.md +0 -184
  284. package/work-orders/CHART-1.md +0 -285
  285. package/work-orders/CHART-2.md +0 -222
  286. package/work-orders/CHART-3.md +0 -163
  287. package/work-orders/CHART-4.md +0 -203
  288. package/work-orders/CHART-5.md +0 -226
  289. package/work-orders/CHART-6.md +0 -428
  290. package/work-orders/CHART-7.md +0 -175
  291. package/work-orders/DX-1.md +0 -169
  292. package/work-orders/DX-2.md +0 -188
  293. package/work-orders/DX-3.md +0 -195
  294. package/work-orders/I18N-1.md +0 -254
  295. package/work-orders/I18N-3.md +0 -207
  296. package/work-orders/MSG-3.md +0 -375
  297. package/work-orders/MSG-3b.md +0 -1002
  298. package/work-orders/MSG-3c.md +0 -378
  299. package/work-orders/MSG-3d.md +0 -268
  300. package/work-orders/MSG-3e.md +0 -164
  301. package/work-orders/MSG-3f.md +0 -391
  302. package/work-orders/MSG-6e.md +0 -308
  303. package/work-orders/MSG-6f.md +0 -214
  304. package/work-orders/MSG-6g.md +0 -244
  305. package/work-orders/MSG-6h.md +0 -238
  306. package/work-orders/MSG-6i.md +0 -271
  307. package/work-orders/MSG-6j.md +0 -117
  308. package/work-orders/NOTIF-12.md +0 -214
  309. package/work-orders/NOTIF-13.md +0 -142
  310. package/work-orders/NOTIF-14.md +0 -151
  311. package/work-orders/PRIM-1.md +0 -177
  312. package/work-orders/SHELL-1.md +0 -255
  313. package/work-orders/SHELL-2.md +0 -197
  314. package/work-orders/SHELL-3.md +0 -359
  315. package/work-orders/SHELL-4.md +0 -351
  316. package/work-orders/SHELL-5.md +0 -345
  317. package/work-orders/SHELL-6.md +0 -210
  318. package/work-orders/THEME-1.md +0 -587
  319. package/work-orders/THEME-10.md +0 -303
  320. package/work-orders/THEME-11.md +0 -208
  321. package/work-orders/THEME-2.md +0 -339
  322. package/work-orders/THEME-3.md +0 -210
  323. package/work-orders/THEME-4.md +0 -271
  324. package/work-orders/THEME-5.md +0 -341
  325. package/work-orders/THEME-6.md +0 -247
  326. package/work-orders/THEME-7.md +0 -82
  327. package/work-orders/THEME-8.md +0 -211
  328. package/work-orders/THEME-9.md +0 -194
  329. package/work-orders/UCM-AUTH-10.md +0 -490
  330. package/work-orders/UCM-AUTH-11.md +0 -185
  331. package/work-orders/UCM-AUTH-12.md +0 -98
  332. package/work-orders/UCM-AUTH-13.md +0 -47
  333. package/work-orders/UCM-AUTH-9.md +0 -207
  334. package/work-orders/UCM-CHART-10.md +0 -150
  335. package/work-orders/UCM-CHART-11.md +0 -132
  336. package/work-orders/UCM-CHART-12.md +0 -348
  337. package/work-orders/UCM-CHART-13.md +0 -122
  338. package/work-orders/UCM-CHART-14.md +0 -198
  339. package/work-orders/UCM-CHART-15.md +0 -187
  340. package/work-orders/UCM-CHART-16.md +0 -169
  341. package/work-orders/UCM-CHART-17.md +0 -195
  342. package/work-orders/UCM-CHART-18.md +0 -200
  343. package/work-orders/UCM-CHART-8.md +0 -147
  344. package/work-orders/UCM-CHART-9.md +0 -265
  345. package/work-orders/UCM-CHAT-1.md +0 -190
  346. package/work-orders/UCM-CHAT-2.md +0 -75
  347. package/work-orders/UCM-DEP-1.md +0 -63
  348. package/work-orders/UCM-I18N-4.md +0 -226
  349. package/work-orders/UCM-I18N-5.md +0 -211
  350. package/work-orders/UCM-MSG-20.md +0 -192
  351. package/work-orders/UCM-PRIM-2.md +0 -114
  352. package/work-orders/UCM-SHELL-7.md +0 -134
  353. package/work-orders/UCM-SHELL-8.md +0 -125
  354. package/work-orders/UCM-TEST-1.md +0 -304
  355. package/work-orders/UCM-THEME-13.md +0 -69
  356. package/work-orders/UCM-THEME-14.md +0 -312
  357. package/work-orders/UCM-THEME-15.md +0 -356
  358. package/work-orders/UCM-THEME-16.md +0 -80
  359. package/work-orders/UCM-THEME-17.md +0 -111
  360. package/work-orders/UCM-THEME-18.md +0 -184
  361. package/work-orders/assets/AUTH-4-user-list-card.html +0 -407
  362. package/work-orders/assets/PRIM-1-dashboard-primitives.html +0 -624
  363. package/work-orders/assets/SHELL-2-account-navigation.html +0 -1159
  364. package/work-orders/assets/THEME-1-baseline-reference-sheet.html +0 -1352
  365. package/work-orders/assets/UCM-CHAT-1-ai-chat.html +0 -447
  366. package/work-orders/assets/UCM-THEME-13-dark-prototype.html +0 -390
  367. package/work-orders/assets/UCM-THEME-17-type-scale.html +0 -391
@@ -1,158 +0,0 @@
1
- // src/auth/AuthContext.jsx
2
- import React, {
3
- createContext,
4
- useState,
5
- useEffect,
6
- } from 'react';
7
- import { ensureCsrfToken } from './apiClient'; // <--- IMPORT ADDED
8
- import {
9
- fetchAuthMethods,
10
- fetchCurrentUser,
11
- logoutSession,
12
- } from './authApi';
13
- import { ReauthModal } from './ReauthModal';
14
-
15
- export const AuthContext = createContext(null);
16
-
17
- const DEFAULT_AUTH_METHODS = {
18
- password_login: true,
19
- password_reset: true,
20
- signup: true,
21
- signup_modes: ['self_signup_access_code'],
22
- turnstile_site_key: '',
23
- password_change: true,
24
- social_login: true,
25
- social_providers: ['google', 'microsoft'],
26
- passkey_login: true,
27
- passkeys_manage: true,
28
- mfa_totp: true,
29
- mfa_recovery_codes: true,
30
- mfa_enabled: true,
31
- required_auth_factor_count: 1,
32
- two_factor_required: false,
33
- qr_signup_enabled: false,
34
- };
35
-
36
- export const AuthProvider = ({ children }) => {
37
- const [user, setUser] = useState(null);
38
- const [authMethods, setAuthMethods] = useState(DEFAULT_AUTH_METHODS);
39
- const [loading, setLoading] = useState(true);
40
-
41
- const mapUserFromApi = (data) => {
42
- const profile = data?.profile || {};
43
- return {
44
- ...data,
45
- id: data?.id,
46
- username: data?.username,
47
- email: data?.email,
48
- first_name: data?.first_name,
49
- last_name: data?.last_name,
50
- role: data?.role ?? profile?.role ?? null,
51
- language: data?.language ?? profile?.language ?? 'en',
52
- is_superuser: Boolean(data?.is_superuser),
53
- is_new: Boolean(data?.is_new ?? profile?.is_new),
54
- is_invited: Boolean(data?.is_invited ?? profile?.is_invited),
55
- accepted_privacy_statement: Boolean(
56
- data?.accepted_privacy_statement ?? profile?.accepted_privacy_statement
57
- ),
58
- accepted_convenience_cookies: Boolean(
59
- data?.accepted_convenience_cookies ?? profile?.accepted_convenience_cookies
60
- ),
61
- is_support_agent: Boolean(data?.is_support_agent ?? profile?.is_support_agent),
62
- support_contact_id: data?.support_contact_id ?? profile?.support_contact_id ?? null,
63
- security_state: data?.security_state,
64
- available_roles: data?.available_roles || [],
65
- ui_permissions: data?.ui_permissions || {},
66
- can_manage_support_agents: Boolean(data?.can_manage_support_agents),
67
- can_manage: Boolean(data?.can_manage),
68
- is_active: data?.is_active,
69
- successful_login: Boolean(data?.successful_login ?? data?.last_login),
70
- last_login: data?.last_login,
71
- date_joined: data?.date_joined,
72
- };
73
- };
74
-
75
- useEffect(() => {
76
- let isMounted = true;
77
-
78
- const initAuth = async () => {
79
- try {
80
- // 1) Ensure CSRF cookie exists using the specific client
81
- await ensureCsrfToken();
82
-
83
- // 2) Both calls depend on CSRF, but not on each other. Await both settlements
84
- // so loading stays true until the complete auth bootstrap has finished.
85
- const [methodsResult, userResult] = await Promise.allSettled([
86
- fetchAuthMethods(),
87
- fetchCurrentUser(),
88
- ]);
89
-
90
- // Keep defaults when the public auth-methods request fails.
91
- if (methodsResult.status === 'fulfilled') {
92
- const methods = methodsResult.value;
93
- if (isMounted && methods && typeof methods === 'object') {
94
- setAuthMethods((prev) => ({ ...prev, ...methods }));
95
- }
96
- }
97
-
98
- // Preserve the previous unauthenticated/error handling for current-user.
99
- if (userResult.status === 'rejected') {
100
- throw userResult.reason;
101
- }
102
-
103
- const data = userResult.value;
104
- if (isMounted) {
105
- setUser(mapUserFromApi(data));
106
- }
107
- } catch (err) {
108
- // Silent failure on 401/403 is expected (user not logged in)
109
- if (isMounted) setUser(null);
110
- } finally {
111
- if (isMounted) setLoading(false);
112
- }
113
- };
114
-
115
- initAuth();
116
-
117
- return () => { isMounted = false; };
118
- }, []);
119
-
120
- const login = (userData) => {
121
- setUser((prev) => ({
122
- ...prev,
123
- ...mapUserFromApi(userData),
124
- }));
125
- };
126
-
127
- const refreshUser = async () => {
128
- const data = await fetchCurrentUser();
129
- if (data) setUser(mapUserFromApi(data));
130
- };
131
-
132
- const logout = async () => {
133
- try {
134
- await logoutSession();
135
- } catch (error) {
136
- // eslint-disable-next-line no-console
137
- console.error('Error during logout:', error);
138
- } finally {
139
- setUser(null);
140
- }
141
- };
142
-
143
- return (
144
- <AuthContext.Provider
145
- value={{
146
- user,
147
- authMethods,
148
- loading,
149
- login,
150
- logout,
151
- refreshUser,
152
- }}
153
- >
154
- {children}
155
- <ReauthModal />
156
- </AuthContext.Provider>
157
- );
158
- };
@@ -1,82 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import {
3
- Alert,
4
- Button,
5
- Dialog,
6
- DialogActions,
7
- DialogContent,
8
- DialogTitle,
9
- TextField,
10
- } from '@mui/material';
11
- import { useTranslation } from 'react-i18next';
12
- import apiClient from './apiClient';
13
- import { HEADLESS_BASE } from './authConfig';
14
- import { rejectReauth, resolveReauth, subscribe } from './reauth';
15
-
16
- export const REAUTH_MODAL_ALERT_SX = { mb: 2 };
17
- export const REAUTH_MODAL_TEXT_FIELD_SX = { mt: 1 };
18
-
19
- export function ReauthModal() {
20
- const { t } = useTranslation();
21
- const [open, setOpen] = useState(false);
22
- const [password, setPassword] = useState('');
23
- const [loading, setLoading] = useState(false);
24
- const [error, setError] = useState(null);
25
-
26
- useEffect(() => {
27
- return subscribe((active) => {
28
- setOpen(active);
29
- if (!active) {
30
- setPassword('');
31
- setError(null);
32
- setLoading(false);
33
- }
34
- });
35
- }, []);
36
-
37
- const handleSubmit = async (e) => {
38
- e.preventDefault();
39
- setLoading(true);
40
- setError(null);
41
- try {
42
- await apiClient.post(`${HEADLESS_BASE}/auth/reauthenticate`, { password });
43
- resolveReauth();
44
- } catch {
45
- setError(t('Auth.REAUTH_FAILED'));
46
- setLoading(false);
47
- }
48
- };
49
-
50
- const handleCancel = () => {
51
- rejectReauth(new Error('cancelled'));
52
- };
53
-
54
- return (
55
- <Dialog open={open} onClose={handleCancel} maxWidth="xs" fullWidth>
56
- <form onSubmit={handleSubmit}>
57
- <DialogTitle>{t('Auth.REAUTH_TITLE')}</DialogTitle>
58
- <DialogContent>
59
- {error && <Alert severity="error" sx={REAUTH_MODAL_ALERT_SX}>{error}</Alert>}
60
- <TextField
61
- autoFocus
62
- fullWidth
63
- type="password"
64
- label={t('Auth.LOGIN_PASSWORD_LABEL')}
65
- value={password}
66
- onChange={(e) => setPassword(e.target.value)}
67
- disabled={loading}
68
- sx={REAUTH_MODAL_TEXT_FIELD_SX}
69
- />
70
- </DialogContent>
71
- <DialogActions>
72
- <Button onClick={handleCancel} disabled={loading}>
73
- {t('Auth.MFA_TOTP_CANCEL_BUTTON')}
74
- </Button>
75
- <Button type="submit" variant="contained" disabled={loading || !password}>
76
- {loading ? t('Auth.MFA_TOTP_VERIFY_BUTTON_LOADING') : t('Auth.MFA_VERIFY')}
77
- </Button>
78
- </DialogActions>
79
- </form>
80
- </Dialog>
81
- );
82
- }
@@ -1,121 +0,0 @@
1
- import { useContext, useState } from 'react';
2
-
3
- import {
4
- Avatar,
5
- Box,
6
- Divider,
7
- IconButton,
8
- Menu,
9
- MenuItem,
10
- Typography,
11
- } from '@mui/material';
12
- import { useTheme } from '@mui/material/styles';
13
- import { useTranslation } from 'react-i18next';
14
-
15
- import { AuthContext } from './AuthContext';
16
- import { calculateContrastRatio } from '../theme';
17
-
18
- function getInitials(user) {
19
- if (!user) return '';
20
- const first = user.first_name?.trim()?.[0];
21
- const last = user.last_name?.trim()?.[0];
22
- if (first || last) return `${first || ''}${last || ''}`.toUpperCase();
23
- return (user.username?.trim()?.[0] || '').toUpperCase();
24
- }
25
-
26
- function getDisplayName(user) {
27
- if (!user) return '';
28
- const name = `${user.first_name || ''} ${user.last_name || ''}`.trim();
29
- return name || user.username || '';
30
- }
31
-
32
- export function UserMenu({ resolveLink, items = [], profileLink = '/account', avatarSrc }) {
33
- const { t } = useTranslation();
34
- const { user, logout } = useContext(AuthContext);
35
- const theme = useTheme();
36
- const [anchorEl, setAnchorEl] = useState(null);
37
- const open = Boolean(anchorEl);
38
- const avatarBackground = theme.palette.primary.main;
39
- // True white/black (theme.palette.common.*, always present on any MUI theme,
40
- // never a source-level literal), not background.paper/ink.primary: contrast
41
- // against true white and true black multiplies to a constant 21 regardless
42
- // of the background's luminance, so max(contrastWhite, contrastBlack) is
43
- // mathematically guaranteed to be >= sqrt(21) =~ 4.58 for ANY primary.main a
44
- // consumer sets -- a near-black token like ink.primary (#212529, luminance
45
- // ~0.018, not 0) does not carry that guarantee and left a real gap for a
46
- // medium-luminance primary (caught by ui_reviewer, neither required test
47
- // exercised the fallback branch that gap lived in).
48
- const avatarText = calculateContrastRatio(theme.palette.common.white, avatarBackground) >= 4.5
49
- ? theme.palette.common.white
50
- : theme.palette.common.black;
51
-
52
- const handleClose = () => setAnchorEl(null);
53
-
54
- const handleProfile = () => {
55
- handleClose();
56
- resolveLink?.(profileLink);
57
- };
58
-
59
- const handleLogout = () => {
60
- handleClose();
61
- logout();
62
- };
63
-
64
- const handleItemSelect = (item) => {
65
- handleClose();
66
- item.onSelect?.();
67
- };
68
-
69
- return (
70
- <>
71
- <IconButton
72
- aria-label={t('UserMenu.TITLE')}
73
- color="inherit"
74
- onClick={(event) => setAnchorEl(event.currentTarget)}
75
- >
76
- <Avatar
77
- src={avatarSrc}
78
- sx={{
79
- width: 32,
80
- height: 32,
81
- fontSize: '0.8rem',
82
- bgcolor: avatarBackground,
83
- color: avatarText,
84
- }}
85
- >
86
- {avatarSrc ? null : getInitials(user)}
87
- </Avatar>
88
- </IconButton>
89
- <Menu
90
- anchorEl={anchorEl}
91
- anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
92
- onClose={handleClose}
93
- open={open}
94
- transformOrigin={{ horizontal: 'right', vertical: 'top' }}
95
- >
96
- <Box sx={{ minWidth: 240, px: 2, py: 1 }}>
97
- <Typography variant="subtitle1" noWrap>{getDisplayName(user)}</Typography>
98
- {/* A user with no first/last name falls back to username as the
99
- display name above — some hosts' usernames are the email
100
- address itself, which would otherwise repeat the same text
101
- on both lines. */}
102
- {user?.email && user.email !== getDisplayName(user) && (
103
- <Typography variant="body2" color="text.secondary" noWrap>{user.email}</Typography>
104
- )}
105
- </Box>
106
- <Divider />
107
- <MenuItem onClick={handleProfile}>{t('UserMenu.PROFILE')}</MenuItem>
108
- {items.length > 0 && <Divider />}
109
- {items.map((item) => (
110
- <MenuItem key={item.id} onClick={() => handleItemSelect(item)}>
111
- {item.label}
112
- </MenuItem>
113
- ))}
114
- <Divider />
115
- <MenuItem onClick={handleLogout}>{t('UserMenu.LOGOUT')}</MenuItem>
116
- </Menu>
117
- </>
118
- );
119
- }
120
-
121
- export default UserMenu;
@@ -1,232 +0,0 @@
1
- import axios from "axios";
2
- import i18next from "i18next";
3
- import { CSRF_URL } from "./authConfig";
4
- import { requestReauth } from "./reauth";
5
-
6
- const apiClient = axios.create({
7
- withCredentials: true,
8
- xsrfCookieName: "csrftoken",
9
- xsrfHeaderName: "X-CSRFToken",
10
- });
11
-
12
- apiClient.interceptors.request.use((config) => {
13
- const language = i18next?.isInitialized ? i18next.language : null;
14
- if (language) {
15
- config.headers = { ...config.headers, 'Accept-Language': language };
16
- }
17
- return config;
18
- });
19
-
20
- let redirectingToLogin = false;
21
-
22
- function isBrowser() {
23
- return typeof window !== "undefined";
24
- }
25
-
26
- // Routen, die OHNE Login funktionieren müssen. Library-eigene Pfade sind eingefroren
27
- // und können nicht entfernt werden — sonst würde z. B. `removePublicPath("/login")`
28
- // auf der Login-Page selbst einen Redirect-Loop auslösen.
29
- const BUILTIN_PUBLIC_PATHS = Object.freeze([
30
- "/login",
31
- "/signup",
32
- "/reset-request-password",
33
- "/invite", // /invite/:uid/:token
34
- "/reset", // /reset/:uid/:token
35
- "/welcome",
36
- ]);
37
-
38
- const CONSUMER_PUBLIC_PATHS = new Set();
39
-
40
- /**
41
- * Register an additional public path so a 401 on that route does not auto-redirect
42
- * to `/login`. Typical use: a public landing on `/` in an otherwise authenticated app.
43
- *
44
- * Accepts a `string` (matched like the builtins: exact for "/", prefix otherwise) or
45
- * a `RegExp` (AUTH-5) for consumers whose public area includes a dynamic segment —
46
- * e.g. `/<slug>`, `/<slug>/team` — that no finite set of string prefixes can describe.
47
- *
48
- * A `RegExp` is tested via `.test()` against `window.location.pathname` ONLY — never
49
- * against the query string or fragment. Anchor it (`^…$`): this library does not add
50
- * anchors for you, and an unanchored pattern like `/team` also matches `/admin/team`,
51
- * silently suppressing the redirect somewhere it's still needed. That failure is
52
- * invisible until someone opens the over-matched page anonymously and lands on a
53
- * blank error instead of `/login` — so test the non-matching direction too, not just
54
- * the intended match.
55
- *
56
- * MUST be called before the AuthProvider mounts (i.e. before `ReactDOM.render`).
57
- * Calling it later won't help the bootstrap probe which fires on AuthProvider mount.
58
- */
59
- export function addPublicPath(path) {
60
- if (typeof path === "string" && path) {
61
- CONSUMER_PUBLIC_PATHS.add(path);
62
- } else if (path instanceof RegExp) {
63
- CONSUMER_PUBLIC_PATHS.add(path);
64
- }
65
- }
66
-
67
- /**
68
- * Remove a consumer-added public path. Library-internal paths are protected.
69
- *
70
- * For a `RegExp` entry, removal is by object identity (`Set.delete` uses SameValueZero
71
- * equality) — pass the exact same `RegExp` instance `addPublicPath` was given, not a
72
- * new literal that merely looks the same. Two `/^\/team$/` literals are not equal.
73
- */
74
- export function removePublicPath(path) {
75
- CONSUMER_PUBLIC_PATHS.delete(path);
76
- }
77
-
78
- function isPublicSitePath(pathname) {
79
- return pathname === "/sites" || pathname.startsWith("/sites/");
80
- }
81
-
82
- // Match rule: a RegExp entry is tested against pathname only (AUTH-5). A string entry
83
- // of exactly "/" requires strict equality (avoids matching every path with
84
- // startsWith); other string entries keep the looser prefix match so dynamic routes
85
- // like /invite/:uid/:token still work.
86
- function matchesPublicPath(pathname, entry) {
87
- if (entry instanceof RegExp) {
88
- // `g`/`y` flags make `.test()` stateful (`lastIndex` advances on match), which would
89
- // make the same pathname alternate matched/unmatched across calls to this
90
- // long-lived, module-scoped RegExp — a redirect that only fires every other time.
91
- // Reset before every test so a consumer's flags can't leak state across calls.
92
- entry.lastIndex = 0;
93
- return entry.test(pathname);
94
- }
95
- if (entry === "/") return pathname === "/";
96
- return pathname.startsWith(entry);
97
- }
98
-
99
- function redirectToLoginOnce() {
100
- if (!isBrowser()) return;
101
-
102
- const currentPath = window.location.pathname;
103
-
104
- const isPublicPage =
105
- isPublicSitePath(currentPath) ||
106
- BUILTIN_PUBLIC_PATHS.some((path) => matchesPublicPath(currentPath, path)) ||
107
- Array.from(CONSUMER_PUBLIC_PATHS).some((path) => matchesPublicPath(currentPath, path));
108
-
109
- // Wenn ja: NICHT weiterleiten. Der 401 Fehler wird an die Komponente durchgereicht.
110
- if (isPublicPage) return;
111
-
112
- if (redirectingToLogin) return;
113
-
114
- redirectingToLogin = true;
115
-
116
- // Wir speichern die aktuelle Seite, um nach dem Login zurückzukehren
117
- // (außer wir sind schon auf Login)
118
- if (!currentPath.startsWith("/login")) {
119
- // Optional: ?next=... Logik
120
- // window.location.assign(`/login?next=${encodeURIComponent(currentPath)}`);
121
- window.location.assign("/login");
122
- } else {
123
- window.location.assign("/login");
124
- }
125
- }
126
-
127
- function extractAuthSignal(data) {
128
- if (!data) {
129
- return { code: null, i18nKey: null };
130
- }
131
-
132
- if (typeof data === "string") {
133
- try {
134
- const parsed = JSON.parse(data);
135
- return extractAuthSignal(parsed);
136
- } catch {
137
- return { code: null, i18nKey: null };
138
- }
139
- }
140
-
141
- if (typeof data !== "object") {
142
- return { code: null, i18nKey: null };
143
- }
144
-
145
- if (typeof data.code === "string" || typeof data.i18nKey === "string") {
146
- return {
147
- code: typeof data.code === "string" ? data.code : null,
148
- i18nKey: typeof data.i18nKey === "string" ? data.i18nKey : null,
149
- };
150
- }
151
-
152
- if (Array.isArray(data.errors) && data.errors.length > 0) {
153
- const first = data.errors[0] || {};
154
- return {
155
- code: typeof first.code === "string" ? first.code : null,
156
- i18nKey: typeof first.i18nKey === "string" ? first.i18nKey : null,
157
- };
158
- }
159
-
160
- if (data.detail && typeof data.detail === "object") {
161
- return {
162
- code: typeof data.detail.code === "string" ? data.detail.code : null,
163
- i18nKey: typeof data.detail.i18nKey === "string" ? data.detail.i18nKey : null,
164
- };
165
- }
166
-
167
- return { code: null, i18nKey: null };
168
- }
169
-
170
- apiClient.interceptors.response.use(
171
- (response) => response,
172
- async (error) => {
173
- const status = error?.response?.status ?? null;
174
- const data = error?.response?.data ?? {};
175
- const { code, i18nKey } = extractAuthSignal(data);
176
-
177
- const isAuthStatus = status === 401 || status === 403;
178
- const isNotAuthenticated =
179
- code === "not_authenticated" || i18nKey === "auth.not_authenticated";
180
-
181
- // Reauthentication gate: allauth returns 401 + flows[{id:"reauthenticate"}]
182
- // when the session is stale before a sensitive operation (e.g. adding a passkey).
183
- // Show the password-confirm modal, wait for it to complete, then retry once.
184
- const flows = data?.data?.flows ?? data?.flows ?? [];
185
- const needsReauth =
186
- status === 401 &&
187
- Array.isArray(flows) &&
188
- flows.some((f) => f.id === "reauthenticate");
189
-
190
- if (needsReauth && !error.config?._reauthRetried) {
191
- try {
192
- await requestReauth();
193
- return apiClient({ ...error.config, _reauthRetried: true });
194
- } catch {
195
- return Promise.reject(error);
196
- }
197
- }
198
-
199
- // Per-request opt-out: bootstrap probes (e.g. fetchCurrentUser on app start)
200
- // expect to handle 401 silently and must not trigger a redirect-on-mount.
201
- // Carried as an axios config property, so it never travels to the backend
202
- // (would otherwise trigger a CORS preflight on cross-origin requests).
203
- const skipRedirect = error?.config?.skipAuthRedirect === true;
204
-
205
- if (isAuthStatus && isNotAuthenticated && !skipRedirect) {
206
- redirectToLoginOnce();
207
- }
208
- return Promise.reject(error);
209
- }
210
- );
211
-
212
- function getCookie(name) {
213
- if (!isBrowser() || !document.cookie) return null;
214
- const xsrfCookies = document.cookie.split(';')
215
- .map(c => c.trim())
216
- .filter(c => c.startsWith(name + '='));
217
- if (xsrfCookies.length === 0) return null;
218
- return decodeURIComponent(xsrfCookies[0].split('=')[1]);
219
- }
220
-
221
- export async function ensureCsrfToken() {
222
- if (getCookie("csrftoken")) {
223
- return;
224
- }
225
- try {
226
- await apiClient.get(CSRF_URL);
227
- } catch (err) {
228
- console.warn("CSRF Initialization failed", err);
229
- }
230
- }
231
-
232
- export default apiClient;