@salesforce/webapp-template-app-react-template-b2e-experimental 1.36.3

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 (122) hide show
  1. package/LICENSE.txt +82 -0
  2. package/dist/.a4drules/build-validation.md +81 -0
  3. package/dist/.a4drules/code-quality.md +150 -0
  4. package/dist/.a4drules/graphql/tools/knowledge/lds-explore-graphql-schema.md +227 -0
  5. package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-mutationquery.md +212 -0
  6. package/dist/.a4drules/graphql/tools/knowledge/lds-generate-graphql-readquery.md +185 -0
  7. package/dist/.a4drules/graphql/tools/knowledge/lds-guide-graphql.md +205 -0
  8. package/dist/.a4drules/graphql/tools/schemas/shared.graphqls +1150 -0
  9. package/dist/.a4drules/graphql.md +408 -0
  10. package/dist/.a4drules/images.md +13 -0
  11. package/dist/.a4drules/react.md +361 -0
  12. package/dist/.a4drules/react_image_processing.md +45 -0
  13. package/dist/.a4drules/skills/install-feature/SKILL.md +67 -0
  14. package/dist/.a4drules/skills/install-feature/scripts/copy-feature-assets.sh +36 -0
  15. package/dist/.a4drules/typescript.md +224 -0
  16. package/dist/.forceignore +15 -0
  17. package/dist/.husky/pre-commit +4 -0
  18. package/dist/.prettierignore +11 -0
  19. package/dist/.prettierrc +17 -0
  20. package/dist/CHANGELOG.md +533 -0
  21. package/dist/README.md +18 -0
  22. package/dist/config/project-scratch-def.json +13 -0
  23. package/dist/force-app/main/default/classes/WebAppAuthUtils.cls +68 -0
  24. package/dist/force-app/main/default/classes/WebAppAuthUtils.cls-meta.xml +5 -0
  25. package/dist/force-app/main/default/classes/WebAppChangePassword.cls +77 -0
  26. package/dist/force-app/main/default/classes/WebAppChangePassword.cls-meta.xml +5 -0
  27. package/dist/force-app/main/default/classes/WebAppForgotPassword.cls +71 -0
  28. package/dist/force-app/main/default/classes/WebAppForgotPassword.cls-meta.xml +5 -0
  29. package/dist/force-app/main/default/classes/WebAppLogin.cls +97 -0
  30. package/dist/force-app/main/default/classes/WebAppLogin.cls-meta.xml +5 -0
  31. package/dist/force-app/main/default/classes/WebAppRegistration.cls +162 -0
  32. package/dist/force-app/main/default/classes/WebAppRegistration.cls-meta.xml +5 -0
  33. package/dist/force-app/main/default/digitalExperienceConfigs/appreacttemplateb2e1.digitalExperienceConfig +8 -0
  34. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/appreacttemplateb2e1.digitalExperience-meta.xml +11 -0
  35. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/sfdc_cms__site/appreacttemplateb2e1/_meta.json +5 -0
  36. package/dist/force-app/main/default/digitalExperiences/site/appreacttemplateb2e1/sfdc_cms__site/appreacttemplateb2e1/content.json +10 -0
  37. package/dist/force-app/main/default/networks/appreacttemplateb2e.network +60 -0
  38. package/dist/force-app/main/default/package.xml +20 -0
  39. package/dist/force-app/main/default/sites/appreacttemplateb2e.site +31 -0
  40. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/.graphqlrc.yml +2 -0
  41. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/.prettierignore +9 -0
  42. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/.prettierrc +11 -0
  43. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/appreacttemplateb2e.webapplication-meta.xml +7 -0
  44. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/build/vite.config.d.ts +2 -0
  45. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/build/vite.config.js +94 -0
  46. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/codegen.yml +12 -0
  47. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/e2e/app.spec.ts +24 -0
  48. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/eslint.config.js +141 -0
  49. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/index.html +13 -0
  50. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package-lock.json +13980 -0
  51. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package.json +66 -0
  52. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/playwright.config.ts +24 -0
  53. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/scripts/get-graphql-schema.mjs +68 -0
  54. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/scripts/rewrite-e2e-assets.mjs +23 -0
  55. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/graphql-operations-types.ts +129 -0
  56. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/utils/accounts.ts +33 -0
  57. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/api/utils/query/highRevenueAccountsQuery.graphql +29 -0
  58. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/app.tsx +16 -0
  59. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/appLayout.tsx +11 -0
  60. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/book.svg +3 -0
  61. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/copy.svg +4 -0
  62. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/rocket.svg +3 -0
  63. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/icons/star.svg +3 -0
  64. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/codey-1.png +0 -0
  65. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/codey-2.png +0 -0
  66. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/codey-3.png +0 -0
  67. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/assets/images/vibe-codey.svg +194 -0
  68. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/alerts/status-alert.tsx +45 -0
  69. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/auth/authentication-route.tsx +21 -0
  70. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/auth/private-route.tsx +36 -0
  71. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/footers/footer-link.tsx +36 -0
  72. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/auth-form.tsx +81 -0
  73. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/forms/submit-button.tsx +49 -0
  74. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/card-layout.tsx +23 -0
  75. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/centered-page-layout.tsx +73 -0
  76. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/layout/loading-page.tsx +46 -0
  77. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/alert.tsx +65 -0
  78. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/button.tsx +54 -0
  79. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/card.tsx +77 -0
  80. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/field.tsx +111 -0
  81. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/index.ts +71 -0
  82. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/input.tsx +19 -0
  83. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/label.tsx +19 -0
  84. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/pagination.tsx +99 -0
  85. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/select.tsx +151 -0
  86. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/skeleton.tsx +7 -0
  87. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/spinner.tsx +26 -0
  88. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/table.tsx +114 -0
  89. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/components/ui/tabs.tsx +115 -0
  90. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/context/AuthContext.tsx +83 -0
  91. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/hooks/form.tsx +116 -0
  92. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/lib/utils.ts +6 -0
  93. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/navigationMenu.tsx +81 -0
  94. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/About.tsx +12 -0
  95. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ChangePassword.tsx +98 -0
  96. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ForgotPassword.tsx +67 -0
  97. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Home.tsx +12 -0
  98. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Login.tsx +89 -0
  99. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/NotFound.tsx +18 -0
  100. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Profile.tsx +146 -0
  101. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/Register.tsx +130 -0
  102. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/ResetPassword.tsx +101 -0
  103. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/pages/new.tsx +10 -0
  104. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/router-utils.tsx +34 -0
  105. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/routes.tsx +88 -0
  106. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/styles/global.css +94 -0
  107. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/authenticationConfig.ts +52 -0
  108. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/src/utils/helpers.ts +187 -0
  109. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/tsconfig.json +36 -0
  110. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/tsconfig.node.json +13 -0
  111. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vite-env.d.ts +1 -0
  112. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vite.config.ts +102 -0
  113. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vitest-env.d.ts +2 -0
  114. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vitest.config.ts +11 -0
  115. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/vitest.setup.ts +1 -0
  116. package/dist/force-app/main/default/webapplications/appreacttemplateb2e/webapplication.json +7 -0
  117. package/dist/jest.config.js +6 -0
  118. package/dist/package.json +38 -0
  119. package/dist/scripts/apex/hello.apex +10 -0
  120. package/dist/scripts/soql/account.soql +6 -0
  121. package/dist/sfdx-project.json +12 -0
  122. package/package.json +37 -0
@@ -0,0 +1,101 @@
1
+ import { useState } from "react";
2
+ import { Link, useSearchParams } from "react-router";
3
+ import { baseClient } from "@salesforce/webapp-experimental/api";
4
+ import { CardLayout } from "../components/layout/card-layout";
5
+ import { CenteredPageLayout } from "../components/layout/centered-page-layout";
6
+ import { AuthForm } from "../components/forms/auth-form";
7
+ import { StatusAlert } from "../components/alerts/status-alert";
8
+ import { useAppForm } from "../hooks/form";
9
+ import { ROUTES, AUTH_PLACEHOLDERS } from "../utils/authenticationConfig";
10
+ import { newPasswordSchema, handleApiResponse, getErrorMessage } from "../utils/helpers";
11
+
12
+ export default function ResetPassword() {
13
+ const [searchParams] = useSearchParams();
14
+ const token = searchParams.get("token");
15
+ const [success, setSuccess] = useState(false);
16
+ const [submitError, setSubmitError] = useState<string | null>(null);
17
+
18
+ const form = useAppForm({
19
+ defaultValues: { newPassword: "", confirmPassword: "" },
20
+ validators: { onChange: newPasswordSchema, onSubmit: newPasswordSchema },
21
+ onSubmit: async ({ value }) => {
22
+ setSubmitError(null);
23
+ setSuccess(false);
24
+ try {
25
+ // [Dev Note] Custom Apex Endpoint: /auth/reset-password
26
+ // You must ensure this Apex class exists in your org
27
+ const response = await baseClient.post("/services/apexrest/auth/reset-password", {
28
+ token,
29
+ newPassword: value.newPassword,
30
+ });
31
+ await handleApiResponse(response, "Password reset failed");
32
+ setSuccess(true);
33
+ // Scroll to top of page after successful submission so user sees it
34
+ window.scrollTo({ top: 0, behavior: "smooth" });
35
+ } catch (err) {
36
+ setSubmitError(getErrorMessage(err, "Password reset failed"));
37
+ }
38
+ },
39
+ onSubmitInvalid: () => {},
40
+ });
41
+
42
+ if (!token) {
43
+ return (
44
+ <CenteredPageLayout title={ROUTES.RESET_PASSWORD.TITLE}>
45
+ <CardLayout title="Reset Password">
46
+ <StatusAlert>
47
+ Reset token is invalid or expired.{" "}
48
+ <Link to={ROUTES.FORGOT_PASSWORD.PATH} className="underline underline-offset-4">
49
+ Request a new password reset link.
50
+ </Link>
51
+ </StatusAlert>
52
+ </CardLayout>
53
+ </CenteredPageLayout>
54
+ );
55
+ }
56
+
57
+ return (
58
+ <CenteredPageLayout title={ROUTES.RESET_PASSWORD.TITLE}>
59
+ <form.AppForm>
60
+ <AuthForm
61
+ title="Reset Password"
62
+ description="Enter your new password below"
63
+ error={submitError}
64
+ success={
65
+ success && (
66
+ <>
67
+ Password reset successfully!{" "}
68
+ <Link to={ROUTES.LOGIN.PATH} className="underline">
69
+ Sign in
70
+ </Link>
71
+ </>
72
+ )
73
+ }
74
+ submit={{ text: "Reset Password", loadingText: "Resetting…" }}
75
+ footer={{ text: "Remember your password?", link: ROUTES.LOGIN.PATH, linkText: "Sign in" }}
76
+ >
77
+ <form.AppField name="newPassword">
78
+ {(field) => (
79
+ <field.PasswordField
80
+ label="New Password"
81
+ placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW}
82
+ autoComplete="new-password"
83
+ disabled={success}
84
+ />
85
+ )}
86
+ </form.AppField>
87
+ <form.AppField name="confirmPassword">
88
+ {(field) => (
89
+ <field.PasswordField
90
+ label="Confirm Password"
91
+ placeholder={AUTH_PLACEHOLDERS.PASSWORD_NEW_CONFIRM}
92
+ autoComplete="new-password"
93
+ disabled={success}
94
+ />
95
+ )}
96
+ </form.AppField>
97
+ </AuthForm>
98
+ </form.AppForm>
99
+ </CenteredPageLayout>
100
+ );
101
+ }
@@ -0,0 +1,10 @@
1
+ export default function New() {
2
+ return (
3
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
4
+ <div className="text-center">
5
+ <h1 className="text-4xl font-bold text-gray-900 mb-4">New</h1>
6
+ <p className="text-lg text-gray-600">This is the new page.</p>
7
+ </div>
8
+ </div>
9
+ );
10
+ }
@@ -0,0 +1,34 @@
1
+ import type { RouteObject } from "react-router";
2
+ import { routes } from "./routes";
3
+
4
+ export type RouteWithFullPath = RouteObject & { fullPath: string };
5
+
6
+ const flatMapRoutes = (route: RouteObject, parentPath: string = ""): RouteWithFullPath[] => {
7
+ // Construct the full path for this route
8
+ let fullPath: string;
9
+
10
+ if (route.index) {
11
+ // Index routes use the parent path
12
+ fullPath = parentPath || "/";
13
+ } else if (route.path) {
14
+ // Combine parent path with current path
15
+ if (route.path.startsWith("/")) {
16
+ fullPath = route.path;
17
+ } else {
18
+ fullPath = parentPath === "/" ? `/${route.path}` : `${parentPath}/${route.path}`;
19
+ }
20
+ } else {
21
+ fullPath = parentPath;
22
+ }
23
+
24
+ const routeWithPath = { ...route, fullPath };
25
+
26
+ // Recursively process children
27
+ const childRoutes = route.children?.flatMap((child) => flatMapRoutes(child, fullPath)) || [];
28
+
29
+ return [routeWithPath, ...childRoutes];
30
+ };
31
+
32
+ export const getAllRoutes = (): RouteWithFullPath[] => {
33
+ return routes.flatMap((route) => flatMapRoutes(route));
34
+ };
@@ -0,0 +1,88 @@
1
+ import type { RouteObject } from 'react-router';
2
+ import AppLayout from './appLayout';
3
+ import Home from './pages/Home';
4
+ import About from './pages/About';
5
+ import NotFound from './pages/NotFound';
6
+ import Login from "./pages/Login";
7
+ import Register from "./pages/Register";
8
+ import ForgotPassword from "./pages/ForgotPassword";
9
+ import ResetPassword from "./pages/ResetPassword";
10
+ import Profile from "./pages/Profile";
11
+ import ChangePassword from "./pages/ChangePassword";
12
+ import AuthenticationRoute from "./components/auth/authentication-route";
13
+ import PrivateRoute from "./components/auth/private-route";
14
+ import { ROUTES } from "./utils/authenticationConfig";
15
+ import New from "./pages/new";
16
+
17
+ export const routes: RouteObject[] = [
18
+ {
19
+ path: "/",
20
+ element: <AppLayout />,
21
+ children: [
22
+ {
23
+ index: true,
24
+ element: <Home />,
25
+ handle: { showInNavigation: true, label: 'Home' }
26
+ },
27
+ {
28
+ path: "about",
29
+ element: <About />,
30
+ handle: { showInNavigation: true, label: "About" }
31
+ },
32
+ {
33
+ path: '*',
34
+ element: <NotFound />
35
+ },
36
+ {
37
+ element: <AuthenticationRoute />,
38
+ children: [
39
+ {
40
+ path: ROUTES.LOGIN.PATH,
41
+ element: <Login />,
42
+ handle: { showInNavigation: true, label: "Login", title: ROUTES.LOGIN.TITLE }
43
+ },
44
+ {
45
+ path: ROUTES.REGISTER.PATH,
46
+ element: <Register />,
47
+ handle: { showInNavigation: false, title: ROUTES.REGISTER.TITLE }
48
+ },
49
+ {
50
+ path: ROUTES.FORGOT_PASSWORD.PATH,
51
+ element: <ForgotPassword />,
52
+ handle: { showInNavigation: false, title: ROUTES.FORGOT_PASSWORD.TITLE }
53
+ },
54
+ {
55
+ path: ROUTES.RESET_PASSWORD.PATH,
56
+ element: <ResetPassword />,
57
+ handle: { showInNavigation: false, title: ROUTES.RESET_PASSWORD.TITLE }
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ element: <PrivateRoute />,
63
+ children: [
64
+ {
65
+ path: ROUTES.PROFILE.PATH,
66
+ element: <Profile />,
67
+ handle: { showInNavigation: true, label: "Profile", title: ROUTES.PROFILE.TITLE }
68
+ },
69
+ {
70
+ path: ROUTES.CHANGE_PASSWORD.PATH,
71
+ element: <ChangePassword />,
72
+ handle: { showInNavigation: false, title: ROUTES.CHANGE_PASSWORD.TITLE }
73
+ }
74
+ ]
75
+ },
76
+ {
77
+ path: "contact",
78
+ element: <h1>Hello World from Contact Page</h1>,
79
+ handle: { showInNavigation: false }
80
+ },
81
+ {
82
+ path: "new",
83
+ element: <New />,
84
+ handle: { showInNavigation: true, label: "New Page" }
85
+ }
86
+ ]
87
+ }
88
+ ];
@@ -0,0 +1,94 @@
1
+ @import "tailwindcss";
2
+ @layer base {
3
+ :root {
4
+ /* browser system elements (scrollbars, etc) */
5
+ color-scheme: light;
6
+
7
+ --background: oklch(1 0 0);
8
+ --foreground: oklch(0.145 0 0);
9
+ --card: oklch(1 0 0);
10
+ --card-foreground: oklch(0.145 0 0);
11
+ --popover: oklch(1 0 0);
12
+ --popover-foreground: oklch(0.145 0 0);
13
+ --primary: oklch(0.205 0 0);
14
+ --primary-foreground: oklch(0.985 0 0);
15
+ --secondary: oklch(0.97 0 0);
16
+ --secondary-foreground: oklch(0.205 0 0);
17
+ --muted: oklch(0.97 0 0);
18
+ --muted-foreground: oklch(0.556 0 0);
19
+ --accent: oklch(0.97 0 0);
20
+ --accent-foreground: oklch(0.205 0 0);
21
+ --destructive: oklch(0.577 0.245 27.325);
22
+ /* 1. Maintenance: Added missing token for accessible text on red backgrounds */
23
+ --destructive-foreground: oklch(0.985 0 0);
24
+ --border: oklch(0.922 0 0);
25
+ --input: oklch(0.922 0 0);
26
+ --ring: oklch(0.205 0 0);
27
+ --radius: 0.625rem;
28
+ --spacing: 0.25rem;
29
+ }
30
+ .dark {
31
+ /* browser system elements */
32
+ color-scheme: dark;
33
+
34
+ --background: oklch(0.145 0 0);
35
+ --foreground: oklch(0.985 0 0);
36
+ --card: oklch(0.145 0 0);
37
+ --card-foreground: oklch(0.985 0 0);
38
+ --popover: oklch(0.145 0 0);
39
+ --popover-foreground: oklch(0.985 0 0);
40
+ --primary: oklch(0.985 0 0);
41
+ --primary-foreground: oklch(0.205 0 0);
42
+ --secondary: oklch(0.269 0 0);
43
+ --secondary-foreground: oklch(0.985 0 0);
44
+ --muted: oklch(0.269 0 0);
45
+ --muted-foreground: oklch(0.708 0 0);
46
+ --accent: oklch(0.269 0 0);
47
+ --accent-foreground: oklch(0.985 0 0);
48
+ --destructive: oklch(0.396 0.141 25.723);
49
+ /* Dark mode text for destructive actions */
50
+ --destructive-foreground: oklch(0.985 0 0);
51
+ --accent-foreground: oklch(0.985 0 0);
52
+ }
53
+ /* 2. Accessibility: Global reset for users who prefer reduced motion */
54
+ @media (prefers-reduced-motion: reduce) {
55
+ * {
56
+ animation-duration: 0.01ms !important;
57
+ animation-iteration-count: 1 !important;
58
+ transition-duration: 0.01ms !important;
59
+ scroll-behavior: auto !important;
60
+ }
61
+ }
62
+ * {
63
+ @apply border-[var(--border)];
64
+ }
65
+ body {
66
+ @apply bg-[var(--background)] text-[var(--foreground)] antialiased;
67
+ }
68
+ }
69
+
70
+ @theme inline {
71
+ --color-background: var(--background);
72
+ --color-foreground: var(--foreground);
73
+ --color-card: var(--card);
74
+ --color-card-foreground: var(--card-foreground);
75
+ --color-popover: var(--popover);
76
+ --color-popover-foreground: var(--popover-foreground);
77
+ --color-primary: var(--primary);
78
+ --color-primary-foreground: var(--primary-foreground);
79
+ --color-secondary: var(--secondary);
80
+ --color-secondary-foreground: var(--secondary-foreground);
81
+ --color-muted: var(--muted);
82
+ --color-muted-foreground: var(--muted-foreground);
83
+ --color-accent: var(--accent);
84
+ --color-accent-foreground: var(--accent-foreground);
85
+ --color-destructive: var(--destructive);
86
+ --color-border: var(--border);
87
+ --color-input: var(--input);
88
+ --color-ring: var(--ring);
89
+ --radius-sm: calc(var(--radius) - 4px);
90
+ --radius-md: calc(var(--radius) - 2px);
91
+ --radius-lg: var(--radius);
92
+ --radius-xl: calc(var(--radius) + 4px);
93
+ --spacing: var(--spacing);
94
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * [Dev Note] Centralized configuration for Auth routes.
3
+ * Each route contains both the path and page title.
4
+ * Using constants prevents typos in route paths across the application.
5
+ */
6
+ export const ROUTES = {
7
+ LOGIN: {
8
+ PATH: "/login",
9
+ TITLE: "Login | MyApp",
10
+ },
11
+ REGISTER: {
12
+ PATH: "/register",
13
+ TITLE: "Create Account | MyApp",
14
+ },
15
+ FORGOT_PASSWORD: {
16
+ PATH: "/forgot-password",
17
+ TITLE: "Recover Password | MyApp",
18
+ },
19
+ RESET_PASSWORD: {
20
+ PATH: "/reset-password",
21
+ TITLE: "Reset Password | MyApp",
22
+ },
23
+ PROFILE: {
24
+ PATH: "/profile",
25
+ TITLE: "My Profile | MyApp",
26
+ },
27
+ CHANGE_PASSWORD: {
28
+ PATH: "/change-password",
29
+ TITLE: "Change Password | MyApp",
30
+ },
31
+ } as const;
32
+
33
+ /**
34
+ * [Dev Note] Query parameter key used to store the return URL.
35
+ * e.g. /login?startUrl=/profile
36
+ */
37
+ export const AUTH_REDIRECT_PARAM = "startUrl";
38
+
39
+ /**
40
+ * Placeholder text constants for authentication form inputs.
41
+ */
42
+ export const AUTH_PLACEHOLDERS = {
43
+ EMAIL: "asalesforce@example.com",
44
+ PASSWORD: "",
45
+ PASSWORD_CREATE: "",
46
+ PASSWORD_CONFIRM: "",
47
+ PASSWORD_NEW: "",
48
+ PASSWORD_NEW_CONFIRM: "",
49
+ FIRST_NAME: "Astro",
50
+ LAST_NAME: "Salesforce",
51
+ USERNAME: "asalesforce",
52
+ } as const;
@@ -0,0 +1,187 @@
1
+ import { AUTH_REDIRECT_PARAM } from "./authenticationConfig";
2
+ import { z } from "zod";
3
+
4
+ /** Email field validation */
5
+ export const emailSchema = z.string().trim().email("Please enter a valid email address");
6
+
7
+ /** Password field validation (minimum 8 characters) */
8
+ export const passwordSchema = z.string().min(8, "Password must be at least 8 characters");
9
+
10
+ /**
11
+ * Shared schema for new password + confirmation fields.
12
+ * Validates password length and matching confirmation.
13
+ */
14
+ export const newPasswordSchema = z
15
+ .object({
16
+ newPassword: passwordSchema,
17
+ confirmPassword: z.string().min(1, "Please confirm your password"),
18
+ })
19
+ .refine((data) => data.newPassword === data.confirmPassword, {
20
+ message: "Passwords do not match",
21
+ path: ["confirmPassword"],
22
+ });
23
+
24
+ /**
25
+ *
26
+ * Extracts the startUrl from URLSearchParams, defaulting to '/'.
27
+ *
28
+ * SECURITY NOTE: This function strictly validates the URL to prevent
29
+ * Open Redirect vulnerabilities. It allows only relative paths.
30
+ *
31
+ * @param searchParams - The URLSearchParams object from useSearchParams()
32
+ * @returns The start URL for post-authentication redirect
33
+ */
34
+ export function getStartUrl(searchParams: URLSearchParams): string {
35
+ // 1. Check for the standard redirect parameter
36
+ const url = searchParams.get(AUTH_REDIRECT_PARAM);
37
+ // 2. Security Check: Validation Logic
38
+ if (url && isValidRedirect(url)) {
39
+ return url;
40
+ }
41
+ // 3. Fallback: Default to root
42
+ return "/";
43
+ }
44
+
45
+ /**
46
+ * [Dev Note] Security: Validates that the redirect URL is a relative path
47
+ * to prevent Open Redirect vulnerabilities.
48
+ *
49
+ * Security Checks:
50
+ * 1. Rejects protocol-relative URLs (//)
51
+ * 2. Rejects backslash usage which some browsers treat as slashes (/\)
52
+ * 3. Rejects control characters
53
+ */
54
+ function isValidRedirect(url: string): boolean {
55
+ // Basic structure check
56
+ if (!url.startsWith("/") || url.startsWith("//")) return false;
57
+ // Security: Reject backslashes to prevent /\example.com bypasses
58
+ if (url.includes("\\")) return false;
59
+ // Robustness: Ensure it doesn't contain whitespace/control characters
60
+ if (/[^\u0021-\u00ff]/.test(url)) return false;
61
+ return true;
62
+ }
63
+
64
+ /**
65
+ * MAINTAINABILITY: Robust error extraction.
66
+ * Handles strings, objects, and standard Error instances.
67
+ *
68
+ * @param err - The error object (unknown type)
69
+ * @param fallback - Fallback message if error doesn't have a message property
70
+ * @returns The error message string
71
+ */
72
+ export function getErrorMessage(err: unknown, fallback: string): string {
73
+ if (err instanceof Error) return err.message;
74
+ if (typeof err === "string") return err;
75
+ // Check if it's an object with a message property
76
+ if (typeof err === "object" && err !== null && "message" in err) {
77
+ return String((err as { message: unknown }).message);
78
+ }
79
+ return fallback;
80
+ }
81
+
82
+ /**
83
+ * [Dev Note] Helper to parse the fetch Response.
84
+ * It handles the distinction between success (JSON) and failure (throwing Error).
85
+ */
86
+ export async function handleApiResponse<T = unknown>(
87
+ response: Response,
88
+ fallbackError: string,
89
+ ): Promise<T> {
90
+ // 1. Robustness: Handle 204 No Content gracefully
91
+ if (response.status === 204) {
92
+ return {} as T;
93
+ }
94
+
95
+ let data: any = null;
96
+
97
+ const contentType = response.headers.get("content-type");
98
+ if (contentType?.includes("application/json")) {
99
+ data = await response.json();
100
+ } else {
101
+ // [Dev Note] If Salesforce returns HTML (e.g. standard error page),
102
+ // we consume text to avoid parsing errors.
103
+ await response.text();
104
+ }
105
+
106
+ if (!response.ok) {
107
+ // [Dev Note] Throwing here allows the calling component to catch and
108
+ // display the error via getErrorMessage()
109
+ throw new Error(parseApiResponseError(data, fallbackError));
110
+ }
111
+
112
+ return data as T;
113
+ }
114
+
115
+ /**
116
+ * Shared response type for authentication endpoints (login/register).
117
+ * Success responses contain `success: true` and `redirectUrl`.
118
+ * Error responses contain `errors` array.
119
+ */
120
+ export interface AuthResponse {
121
+ success?: boolean;
122
+ redirectUrl?: string | null;
123
+ errors?: string[];
124
+ }
125
+
126
+ /**
127
+ * UI API Record response structure.
128
+ */
129
+ export type RecordResponse = {
130
+ fields: Record<
131
+ string,
132
+ {
133
+ value: string;
134
+ }
135
+ >;
136
+ };
137
+
138
+ /**
139
+ * [Dev Note] The UI API returns a complex nested structure.
140
+ * This helper flattens it to a simple object for easier form binding.
141
+ * Flattens { fields: { FieldName: { displayValue, value } } } to { FieldName: value }
142
+ *
143
+ * @param data - The RecordResponse with field objects.
144
+ * @throws {Error} If data is not a valid RecordResponse.
145
+ * @returns Flattened object with field values.
146
+ */
147
+ export function flattenUiApiRecord<T>(data: RecordResponse): T {
148
+ if (!data?.fields) {
149
+ throw new Error(parseApiResponseError(data));
150
+ }
151
+
152
+ return Object.fromEntries(
153
+ Object.entries(data.fields).map(([key, field]) => [key, field?.value ?? null]),
154
+ ) as T;
155
+ }
156
+
157
+ /**
158
+ * [Dev Note] Salesforce APIs may return errors as an array or a single object.
159
+ * This helper standardizes the extraction of the error message string.
160
+ *
161
+ * @param data - The response data.
162
+ * @param fallbackError - Fallback error message if response doesn't have a message property
163
+ * @returns The error message string
164
+ */
165
+ function parseApiResponseError(
166
+ data: any,
167
+ fallbackError: string = "An unknown error occurred",
168
+ ): string {
169
+ if (data?.message) {
170
+ return data.message;
171
+ }
172
+ if (data?.error) {
173
+ return data.error;
174
+ }
175
+ if (data?.errors && Array.isArray(data.errors) && data.errors.length > 0) {
176
+ return data.errors.join(" ") || fallbackError;
177
+ }
178
+ if (Array.isArray(data) && data.length > 0) {
179
+ return (
180
+ data
181
+ .map((e) => e?.message)
182
+ .filter(Boolean)
183
+ .join(" ") || fallbackError
184
+ );
185
+ }
186
+ return fallbackError;
187
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+
23
+ /* Path mapping */
24
+ "baseUrl": ".",
25
+ "paths": {
26
+ "@/*": ["./src/*"],
27
+ "@api/*": ["./src/api/*"],
28
+ "@components/*": ["./src/components/*"],
29
+ "@utils/*": ["./src/utils/*"],
30
+ "@styles/*": ["./src/styles/*"],
31
+ "@assets/*": ["./src/assets/*"]
32
+ }
33
+ },
34
+ "include": ["src", "vite-env.d.ts", "vitest-env.d.ts"],
35
+ "references": [{ "path": "./tsconfig.node.json" }]
36
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
5
+ "skipLibCheck": true,
6
+ "module": "ESNext",
7
+ "moduleResolution": "bundler",
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "outDir": "./build"
11
+ },
12
+ "include": ["vite.config.ts"]
13
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />