@djangocfg/layouts 2.1.605 → 2.1.607

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 (48) hide show
  1. package/package.json +12 -12
  2. package/src/layouts/AuthLayout/AuthLayout.tsx +1 -0
  3. package/src/layouts/AuthLayout/README.md +20 -3
  4. package/src/layouts/AuthLayout/components/oauth/OAuthSection.tsx +60 -0
  5. package/src/layouts/AuthLayout/components/oauth/buttons/OAuthButtonList.test.tsx +52 -0
  6. package/src/layouts/AuthLayout/components/oauth/buttons/OAuthButtonList.tsx +49 -0
  7. package/src/layouts/AuthLayout/components/oauth/buttons/OAuthButtons.tsx +44 -0
  8. package/src/layouts/AuthLayout/components/oauth/buttons/OAuthProviderButton.test.tsx +56 -0
  9. package/src/layouts/AuthLayout/components/oauth/buttons/OAuthProviderButton.tsx +51 -0
  10. package/src/layouts/AuthLayout/components/oauth/{OAuthCallback.tsx → callback/OAuthCallback.tsx} +7 -33
  11. package/src/layouts/AuthLayout/components/oauth/callback/OAuthCallbackOverlay.tsx +41 -0
  12. package/src/layouts/AuthLayout/components/oauth/{oauthCallbackParams.test.ts → callback/callbackParams.test.ts} +1 -1
  13. package/src/layouts/AuthLayout/components/oauth/errors/errorCopy.test.ts +63 -0
  14. package/src/layouts/AuthLayout/components/oauth/errors/errorCopy.ts +95 -0
  15. package/src/layouts/AuthLayout/components/oauth/errors/useOAuthErrorText.ts +25 -0
  16. package/src/layouts/AuthLayout/components/oauth/index.ts +29 -4
  17. package/src/layouts/AuthLayout/components/oauth/notice/OAuthNotice.tsx +38 -0
  18. package/src/layouts/AuthLayout/components/oauth/notice/OAuthNoticeView.test.tsx +78 -0
  19. package/src/layouts/AuthLayout/components/oauth/notice/OAuthNoticeView.tsx +84 -0
  20. package/src/layouts/AuthLayout/components/oauth/{GithubIcon.tsx → providers/icons/GithubIcon.tsx} +0 -1
  21. package/src/layouts/AuthLayout/components/oauth/{GoogleIcon.tsx → providers/icons/GoogleIcon.tsx} +1 -1
  22. package/src/layouts/AuthLayout/components/oauth/providers/index.ts +2 -0
  23. package/src/layouts/AuthLayout/components/oauth/providers/registry.test.ts +23 -0
  24. package/src/layouts/AuthLayout/components/oauth/providers/registry.ts +32 -0
  25. package/src/layouts/AuthLayout/components/oauth/{oauthProviders.test.ts → providers/resolveProviders.test.ts} +1 -1
  26. package/src/layouts/AuthLayout/components/shared/AuthButton.tsx +1 -2
  27. package/src/layouts/AuthLayout/components/steps/IdentifierStep.tsx +4 -26
  28. package/src/layouts/AuthLayout/context.tsx +1 -1
  29. package/src/layouts/AuthLayout/styles/auth.css +3 -70
  30. package/src/layouts/AuthLayout/styles/oauth.css +78 -0
  31. package/src/layouts/PrivateLayout/README.md +4 -2
  32. package/src/layouts/PrivateLayout/components/PrivateContent.test.tsx +65 -0
  33. package/src/layouts/PrivateLayout/components/PrivateContent.tsx +16 -9
  34. package/src/layouts/PrivateLayout/components/PrivateSidebarAccount.tsx +1 -1
  35. package/src/layouts/PrivateLayout/components/SidebarBody.tsx +1 -1
  36. package/src/layouts/PrivateLayout/components/SidebarBrand.tsx +2 -2
  37. package/src/layouts/PrivateLayout/components/SidebarNavGroup.tsx +5 -5
  38. package/src/layouts/PrivateLayout/components/SidebarNavItem.tsx +2 -2
  39. package/src/layouts/PrivateLayout/geometry.test.ts +32 -0
  40. package/src/layouts/PrivateLayout/geometry.ts +18 -14
  41. package/src/testing/MockAuthFormProvider.tsx +1 -1
  42. package/src/layouts/AuthLayout/components/oauth/OAuthButtons.tsx +0 -82
  43. package/src/layouts/AuthLayout/components/oauth/OAuthNotice.tsx +0 -94
  44. package/src/layouts/AuthLayout/components/oauth/oauthErrors.ts +0 -23
  45. package/src/layouts/AuthLayout/components/oauth/oauthNoticeCopy.test.ts +0 -36
  46. package/src/layouts/AuthLayout/components/oauth/oauthNoticeCopy.ts +0 -86
  47. /package/src/layouts/AuthLayout/components/oauth/{oauthCallbackParams.ts → callback/callbackParams.ts} +0 -0
  48. /package/src/layouts/AuthLayout/components/oauth/{oauthProviders.ts → providers/resolveProviders.ts} +0 -0
@@ -1,86 +0,0 @@
1
- import type { OAuthFailureCode } from '@djangocfg/api/auth';
2
-
3
- /**
4
- * Copy for each failure code. Exhaustive on purpose: a code the backend adds
5
- * fails typecheck here until someone decides what to tell the visitor.
6
- */
7
- export const OAUTH_ERROR_KEYS = {
8
- invalid_state: 'layouts.auth.oauth.error.invalid_state',
9
- oauth_exchange_failed: 'layouts.auth.oauth.error.oauth_exchange_failed',
10
- invalid_id_token: 'layouts.auth.oauth.error.invalid_id_token',
11
- email_missing: 'layouts.auth.oauth.error.email_missing',
12
- email_not_verified: 'layouts.auth.oauth.error.email_not_verified',
13
- hosted_domain_not_allowed: 'layouts.auth.oauth.error.hosted_domain_not_allowed',
14
- account_inactive: 'layouts.auth.oauth.error.account_inactive',
15
- link_not_allowed: 'layouts.auth.oauth.error.link_not_allowed',
16
- rate_limited: 'layouts.auth.oauth.error.rate_limited',
17
- provider_unavailable: 'layouts.auth.oauth.error.provider_unavailable',
18
- cancelled: 'layouts.auth.oauth.error.cancelled',
19
- generic: 'layouts.auth.oauth.error.generic',
20
- } as const;
21
-
22
- export type OAuthErrorKey = (typeof OAUTH_ERROR_KEYS)[keyof typeof OAUTH_ERROR_KEYS];
23
-
24
- /** Maps every failure code to one of the keys above. Configuration faults the visitor cannot fix read as "unavailable" or generic. */
25
- export const OAUTH_CODE_TO_KEY: Record<OAuthFailureCode, OAuthErrorKey> = {
26
- invalid_state: OAUTH_ERROR_KEYS.invalid_state,
27
- oauth_exchange_failed: OAUTH_ERROR_KEYS.oauth_exchange_failed,
28
- invalid_id_token: OAUTH_ERROR_KEYS.invalid_id_token,
29
- email_missing: OAUTH_ERROR_KEYS.email_missing,
30
- email_not_verified: OAUTH_ERROR_KEYS.email_not_verified,
31
- hosted_domain_not_allowed: OAUTH_ERROR_KEYS.hosted_domain_not_allowed,
32
- account_inactive: OAUTH_ERROR_KEYS.account_inactive,
33
- link_not_allowed: OAUTH_ERROR_KEYS.link_not_allowed,
34
- rate_limited: OAUTH_ERROR_KEYS.rate_limited,
35
- provider_unavailable: OAUTH_ERROR_KEYS.provider_unavailable,
36
- cancelled: OAUTH_ERROR_KEYS.cancelled,
37
- oauth_disabled: OAUTH_ERROR_KEYS.provider_unavailable,
38
- github_oauth_disabled: OAUTH_ERROR_KEYS.provider_unavailable,
39
- origin_not_allowed: OAUTH_ERROR_KEYS.generic,
40
- missing_redirect_uri: OAUTH_ERROR_KEYS.generic,
41
- server_error: OAUTH_ERROR_KEYS.generic,
42
- not_found: OAUTH_ERROR_KEYS.generic,
43
- unknown_provider: OAUTH_ERROR_KEYS.generic,
44
- };
45
-
46
- /** The one next step a notice offers: reveal the email field, run the provider again, or nothing the visitor can do. */
47
- export type OAuthNoticeAction = 'email' | 'retry' | 'none';
48
-
49
- /** What the visitor does next, per copy key. A retry is only offered where trying again can change the outcome. */
50
- const ACTION_BY_KEY: Record<OAuthErrorKey, OAuthNoticeAction> = {
51
- [OAUTH_ERROR_KEYS.invalid_state]: 'retry',
52
- [OAUTH_ERROR_KEYS.oauth_exchange_failed]: 'retry',
53
- [OAUTH_ERROR_KEYS.invalid_id_token]: 'retry',
54
- [OAUTH_ERROR_KEYS.email_missing]: 'email',
55
- [OAUTH_ERROR_KEYS.email_not_verified]: 'email',
56
- [OAUTH_ERROR_KEYS.hosted_domain_not_allowed]: 'email',
57
- [OAUTH_ERROR_KEYS.account_inactive]: 'none',
58
- [OAUTH_ERROR_KEYS.link_not_allowed]: 'email',
59
- [OAUTH_ERROR_KEYS.rate_limited]: 'none',
60
- [OAUTH_ERROR_KEYS.provider_unavailable]: 'retry',
61
- [OAUTH_ERROR_KEYS.cancelled]: 'none',
62
- [OAUTH_ERROR_KEYS.generic]: 'retry',
63
- };
64
-
65
- export interface OAuthNoticeCopy {
66
- /** Only the code that needs a heading has one; the rest are a single sentence. */
67
- titleKey?: 'layouts.auth.oauth.notice.linkNotAllowedTitle';
68
- bodyKey: OAuthErrorKey;
69
- action: OAuthNoticeAction;
70
- }
71
-
72
- /**
73
- * What the sign-in form tells a visitor whose provider round trip failed.
74
- *
75
- * `null` means "say nothing": the visitor cancelled on the provider's page and
76
- * is back at the form they started from. An absent code is the unknown case.
77
- */
78
- export const describeOAuthFailure = (code?: OAuthFailureCode | null): OAuthNoticeCopy | null => {
79
- const bodyKey = code ? OAUTH_CODE_TO_KEY[code] : OAUTH_ERROR_KEYS.generic;
80
- if (bodyKey === OAUTH_ERROR_KEYS.cancelled) return null;
81
- return {
82
- titleKey: bodyKey === OAUTH_ERROR_KEYS.link_not_allowed ? 'layouts.auth.oauth.notice.linkNotAllowedTitle' : undefined,
83
- bodyKey,
84
- action: ACTION_BY_KEY[bodyKey],
85
- };
86
- };