@salesforce/ui-bundle-template-feature-react-authentication 1.117.2
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/LICENSE.txt +82 -0
- package/README.md +77 -0
- package/dist/.forceignore +15 -0
- package/dist/.husky/pre-commit +4 -0
- package/dist/.prettierignore +11 -0
- package/dist/.prettierrc +17 -0
- package/dist/AGENT.md +193 -0
- package/dist/CHANGELOG.md +2128 -0
- package/dist/README.md +28 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/eslint.config.js +7 -0
- package/dist/force-app/main/default/classes/UIBundleAuthUtils.cls +68 -0
- package/dist/force-app/main/default/classes/UIBundleAuthUtils.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/UIBundleChangePassword.cls +77 -0
- package/dist/force-app/main/default/classes/UIBundleChangePassword.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/UIBundleForgotPassword.cls +71 -0
- package/dist/force-app/main/default/classes/UIBundleForgotPassword.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/UIBundleLogin.cls +105 -0
- package/dist/force-app/main/default/classes/UIBundleLogin.cls-meta.xml +5 -0
- package/dist/force-app/main/default/classes/UIBundleRegistration.cls +162 -0
- package/dist/force-app/main/default/classes/UIBundleRegistration.cls-meta.xml +5 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/.forceignore +15 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/.graphqlrc.yml +2 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/.prettierignore +9 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/.prettierrc +11 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/CHANGELOG.md +10 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/README.md +75 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/codegen.yml +95 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/components.json +18 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/e2e/app.spec.ts +17 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/eslint.config.js +169 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/feature-react-authentication.uibundle-meta.xml +7 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/index.html +12 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/package.json +70 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/playwright.config.ts +24 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/scripts/get-graphql-schema.mjs +68 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/scripts/rewrite-e2e-assets.mjs +23 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/api/graphqlClient.ts +25 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/app.tsx +16 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/appLayout.tsx +83 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/icons/book.svg +3 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/icons/copy.svg +4 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/icons/rocket.svg +3 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/icons/star.svg +3 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/images/codey-1.png +0 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/images/codey-2.png +0 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/images/codey-3.png +0 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/assets/images/vibe-codey.svg +194 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/alerts/status-alert.tsx +49 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/layouts/card-layout.tsx +29 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/alert.tsx +76 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/badge.tsx +48 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/breadcrumb.tsx +109 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/button.tsx +67 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/calendar.tsx +232 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/card.tsx +103 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/checkbox.tsx +32 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/collapsible.tsx +33 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/datePicker.tsx +127 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/dialog.tsx +162 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/field.tsx +237 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/index.ts +84 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/input.tsx +19 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/label.tsx +22 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/pagination.tsx +132 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/popover.tsx +89 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/select.tsx +193 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/separator.tsx +26 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/skeleton.tsx +14 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/sonner.tsx +20 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/spinner.tsx +16 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/table.tsx +114 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/components/ui/tabs.tsx +88 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/api/userProfileApi.ts +95 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/authHelpers.ts +73 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/authenticationConfig.ts +61 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/context/AuthContext.tsx +95 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/footers/footer-link.tsx +36 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/forms/auth-form.tsx +81 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/forms/submit-button.tsx +49 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/hooks/form.tsx +120 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/hooks/useCountdownTimer.ts +266 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/hooks/useRetryWithBackoff.ts +109 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layout/card-skeleton.tsx +38 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layout/centered-page-layout.tsx +87 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layouts/AuthAppLayout.tsx +12 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layouts/authenticationRouteLayout.tsx +21 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/layouts/privateRouteLayout.tsx +44 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/ChangePassword.tsx +107 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/ForgotPassword.tsx +73 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/Login.tsx +97 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/Profile.tsx +161 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/Register.tsx +133 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/pages/ResetPassword.tsx +107 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/sessionTimeout/SessionTimeoutValidator.tsx +602 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/sessionTimeout/sessionTimeService.ts +149 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/sessionTimeout/sessionTimeoutConfig.ts +77 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/features/authentication/utils/helpers.ts +121 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/navigationMenu.tsx +80 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/pages/Home.tsx +12 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/pages/NotFound.tsx +18 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/router-utils.tsx +35 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/routes.tsx +71 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/styles/global.css +135 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/tsconfig.json +42 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/ui-bundle.json +7 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/vite-env.d.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/vite.config.ts +106 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/vitest-env.d.ts +2 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/vitest.config.ts +11 -0
- package/dist/force-app/main/default/uiBundles/feature-react-authentication/vitest.setup.ts +1 -0
- package/dist/jest.config.js +6 -0
- package/dist/package-lock.json +9995 -0
- package/dist/package.json +40 -0
- package/dist/scripts/apex/hello.apex +10 -0
- package/dist/scripts/graphql-search.sh +191 -0
- package/dist/scripts/prepare-import-unique-fields.js +122 -0
- package/dist/scripts/setup-cli.mjs +563 -0
- package/dist/scripts/sf-project-setup.mjs +66 -0
- package/dist/scripts/soql/account.soql +6 -0
- package/dist/sfdx-project.json +12 -0
- package/package.json +44 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionTimeServlet API service
|
|
3
|
+
* Handles communication with the session validation endpoint
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { SESSION_CONFIG } from "./sessionTimeoutConfig";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Response from SessionTimeServlet API
|
|
10
|
+
*/
|
|
11
|
+
export interface SessionResponse {
|
|
12
|
+
/** Session phase */
|
|
13
|
+
sp: number;
|
|
14
|
+
/** Seconds remaining in session */
|
|
15
|
+
sr: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse the servlet response text into SessionResponse object
|
|
20
|
+
* Handles CSRF protection prefix
|
|
21
|
+
*
|
|
22
|
+
* @param text - Raw response text from servlet
|
|
23
|
+
* @returns Parsed session response, or undefined if parsing fails
|
|
24
|
+
*/
|
|
25
|
+
function parseResponseResult(text: string): SessionResponse | undefined {
|
|
26
|
+
let cleanedText = text;
|
|
27
|
+
|
|
28
|
+
// Strip CSRF protection prefix if present
|
|
29
|
+
if (cleanedText.startsWith(SESSION_CONFIG.CSRF_TOKEN)) {
|
|
30
|
+
cleanedText = cleanedText.substring(SESSION_CONFIG.CSRF_TOKEN.length);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Trim whitespace
|
|
34
|
+
cleanedText = cleanedText.trim();
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(cleanedText) as SessionResponse;
|
|
38
|
+
|
|
39
|
+
// Validate response structure
|
|
40
|
+
if (typeof parsed.sp !== "number" || typeof parsed.sr !== "number") {
|
|
41
|
+
throw new Error("Invalid response structure: missing sp or sr properties");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return parsed;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error("[sessionTimeService] Failed to parse response:", error, "Text:", cleanedText);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Call SessionTimeServlet API
|
|
52
|
+
* Internal function used by both poll and extend functions.
|
|
53
|
+
* Returns undefined on any failure so the session timeout feature
|
|
54
|
+
* never crashes the running application.
|
|
55
|
+
*
|
|
56
|
+
* @param basePath - Community base path (e.g., "/sfsites/c/")
|
|
57
|
+
* @param extend - Whether to extend the session (updateTimedOutSession param)
|
|
58
|
+
* @returns Session response with remaining time, or undefined on failure
|
|
59
|
+
*/
|
|
60
|
+
async function callSessionTimeServlet(
|
|
61
|
+
basePath: string,
|
|
62
|
+
extend: boolean = false,
|
|
63
|
+
): Promise<SessionResponse | undefined> {
|
|
64
|
+
// Build URL with cache-busting timestamp
|
|
65
|
+
const timestamp = Date.now();
|
|
66
|
+
let url = `${basePath}${SESSION_CONFIG.SERVLET_URL}?buster=${timestamp}`;
|
|
67
|
+
|
|
68
|
+
if (extend) {
|
|
69
|
+
url += "&updateTimedOutSession=true";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch(url, {
|
|
74
|
+
method: "GET",
|
|
75
|
+
credentials: "same-origin",
|
|
76
|
+
cache: "no-cache",
|
|
77
|
+
headers: {
|
|
78
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
console.error(`[sessionTimeService] HTTP ${response.status}: ${response.statusText}`);
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const contentType = response.headers.get("content-type");
|
|
88
|
+
if (contentType && !contentType.includes("text") && !contentType.includes("json")) {
|
|
89
|
+
console.error(`[sessionTimeService] Unexpected content type: ${contentType}`);
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const text = await response.text();
|
|
94
|
+
const parsed = parseResponseResult(text);
|
|
95
|
+
if (!parsed) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
sp: parsed.sp,
|
|
101
|
+
sr: Math.max(0, parsed.sr - SESSION_CONFIG.LATENCY_BUFFER_SECONDS),
|
|
102
|
+
};
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error("[sessionTimeService] API call failed:", error);
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Poll SessionTimeServlet to check remaining session time
|
|
111
|
+
* Called periodically to monitor session status
|
|
112
|
+
*
|
|
113
|
+
* @param basePath - Community base path (e.g., "/sfsites/c/")
|
|
114
|
+
* @returns Session response with remaining time, or undefined on failure
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const response = await pollSessionTimeServlet('/sfsites/c/');
|
|
118
|
+
* if (response && response.sr <= 300) {
|
|
119
|
+
* showWarning();
|
|
120
|
+
* }
|
|
121
|
+
*/
|
|
122
|
+
export async function pollSessionTimeServlet(
|
|
123
|
+
basePath: string,
|
|
124
|
+
): Promise<SessionResponse | undefined> {
|
|
125
|
+
return callSessionTimeServlet(basePath, false);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Extend the current session time
|
|
130
|
+
* Called when user clicks "Continue Working" in warning modal
|
|
131
|
+
*
|
|
132
|
+
* @param basePath - Community base path (e.g., "/sfsites/c/")
|
|
133
|
+
* @returns Session response with new remaining time, or undefined on failure
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const response = await extendSessionTime('/sfsites/c/');
|
|
137
|
+
* if (response) {
|
|
138
|
+
* console.log(`Session extended. ${response.sr} seconds remaining.`);
|
|
139
|
+
* }
|
|
140
|
+
*/
|
|
141
|
+
export async function extendSessionTime(basePath: string): Promise<SessionResponse | undefined> {
|
|
142
|
+
return callSessionTimeServlet(basePath, true);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Export parseResponseResult for testing purposes
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
export { parseResponseResult };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration constants for session timeout monitoring
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Retry Configuration
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
/** Initial delay for first retry attempt (2 seconds) */
|
|
10
|
+
export const INITIAL_RETRY_DELAY = 2000;
|
|
11
|
+
|
|
12
|
+
/** Maximum number of retry attempts before giving up */
|
|
13
|
+
export const MAX_RETRY_ATTEMPTS = 10;
|
|
14
|
+
|
|
15
|
+
/** Maximum retry delay (30 minutes) */
|
|
16
|
+
export const MAX_RETRY_DELAY = 30 * 60 * 1000;
|
|
17
|
+
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Session Storage Keys
|
|
20
|
+
// ============================================================================
|
|
21
|
+
|
|
22
|
+
/** sessionStorage keys used by session validator */
|
|
23
|
+
export const STORAGE_KEYS = {
|
|
24
|
+
/** Flag to show session expired message on login page */
|
|
25
|
+
SHOW_SESSION_MESSAGE: "lwrSessionValidator.showSessionMessage",
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Servlet Configuration
|
|
30
|
+
// ============================================================================
|
|
31
|
+
|
|
32
|
+
/** SessionTimeServlet configuration */
|
|
33
|
+
export const SESSION_CONFIG = {
|
|
34
|
+
/** Relative URL to SessionTimeServlet */
|
|
35
|
+
SERVLET_URL: "/sfsites/c/_nc_external/system/security/session/SessionTimeServlet",
|
|
36
|
+
|
|
37
|
+
/** Latency buffer to subtract from server response (seconds) */
|
|
38
|
+
LATENCY_BUFFER_SECONDS: 3,
|
|
39
|
+
|
|
40
|
+
/** CSRF protection prefix in servlet responses */
|
|
41
|
+
CSRF_TOKEN: "while(1);\n",
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
// ============================================================================
|
|
45
|
+
// UI Labels
|
|
46
|
+
// ============================================================================
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* UI labels for session timeout components
|
|
50
|
+
*/
|
|
51
|
+
export const LABELS = {
|
|
52
|
+
/** Title for session warning modal */
|
|
53
|
+
sessionWarningTitle: "Session Timeout Warning",
|
|
54
|
+
|
|
55
|
+
/** Message text in session warning modal */
|
|
56
|
+
sessionWarningMessage:
|
|
57
|
+
"For security, we log you out if you’re inactive for too long. To continue working, click Continue before the time expires.",
|
|
58
|
+
|
|
59
|
+
/** Text for "Continue" button */
|
|
60
|
+
continueButton: "Continue",
|
|
61
|
+
|
|
62
|
+
/** Text for "Log Out" button */
|
|
63
|
+
logoutButton: "Log Out",
|
|
64
|
+
|
|
65
|
+
/** Message shown on login page after session expires */
|
|
66
|
+
invalidSessionMessage: "Your session has expired. Please log in again.",
|
|
67
|
+
|
|
68
|
+
/** Accessibility label for close button */
|
|
69
|
+
closeLabel: "Close",
|
|
70
|
+
} as const;
|
|
71
|
+
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Session Timeout Configuration
|
|
74
|
+
// ============================================================================
|
|
75
|
+
|
|
76
|
+
/** Session warning time in seconds (30 seconds) */
|
|
77
|
+
export const SESSION_WARNING_TIME = 30;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MAINTAINABILITY: Robust error extraction.
|
|
3
|
+
* Handles strings, objects, and standard Error instances.
|
|
4
|
+
*
|
|
5
|
+
* @param err - The error object (unknown type)
|
|
6
|
+
* @param fallback - Fallback message if error doesn't have a message property
|
|
7
|
+
* @returns The error message string
|
|
8
|
+
*/
|
|
9
|
+
export function getErrorMessage(err: unknown, fallback: string): string {
|
|
10
|
+
if (err instanceof Error) return err.message;
|
|
11
|
+
if (typeof err === "string") return err;
|
|
12
|
+
// Check if it's an object with a message property
|
|
13
|
+
if (typeof err === "object" && err !== null && "message" in err) {
|
|
14
|
+
return String((err as { message: unknown }).message);
|
|
15
|
+
}
|
|
16
|
+
return fallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* [Dev Note] Helper to parse the fetch Response.
|
|
21
|
+
* It handles the distinction between success (JSON) and failure (throwing Error).
|
|
22
|
+
*/
|
|
23
|
+
export async function handleApiResponse<T = unknown>(
|
|
24
|
+
response: Response,
|
|
25
|
+
fallbackError: string,
|
|
26
|
+
): Promise<T> {
|
|
27
|
+
// 1. Robustness: Handle 204 No Content gracefully
|
|
28
|
+
if (response.status === 204) {
|
|
29
|
+
return {} as T;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let data: any = null;
|
|
33
|
+
|
|
34
|
+
const contentType = response.headers.get("content-type");
|
|
35
|
+
if (contentType?.includes("application/json")) {
|
|
36
|
+
data = await response.json();
|
|
37
|
+
} else {
|
|
38
|
+
// [Dev Note] If Salesforce returns HTML (e.g. standard error page),
|
|
39
|
+
// we consume text to avoid parsing errors.
|
|
40
|
+
await response.text();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
// [Dev Note] Throwing here allows the calling component to catch and
|
|
45
|
+
// display the error via getErrorMessage()
|
|
46
|
+
throw new Error(parseApiResponseError(data, fallbackError));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return data as T;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* UI API Record response structure.
|
|
54
|
+
*/
|
|
55
|
+
export type RecordResponse = {
|
|
56
|
+
fields: Record<
|
|
57
|
+
string,
|
|
58
|
+
{
|
|
59
|
+
value: string;
|
|
60
|
+
}
|
|
61
|
+
>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* [Dev Note] GraphQL can return a complex nested structure.
|
|
66
|
+
* This helper flattens it to a simple object for easier form binding.
|
|
67
|
+
*
|
|
68
|
+
* @param data - Extracted payload from the GraphQL response.
|
|
69
|
+
* @param fallbackError - Fallback error message if data is null/undefined or not an object.
|
|
70
|
+
* @throws {Error} If data is not valid.
|
|
71
|
+
* @returns Flattened object with values mapped directly to the fields.
|
|
72
|
+
*/
|
|
73
|
+
export function flattenGraphQLRecord<T>(
|
|
74
|
+
data: any,
|
|
75
|
+
fallbackError: string = "An unknown error occurred",
|
|
76
|
+
): T {
|
|
77
|
+
if (!data || typeof data !== "object") {
|
|
78
|
+
throw new Error(fallbackError);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return Object.fromEntries(
|
|
82
|
+
Object.entries(data).map(([key, field]) => [
|
|
83
|
+
key,
|
|
84
|
+
field !== null && typeof field === "object" && "value" in field
|
|
85
|
+
? (field as { value: unknown }).value
|
|
86
|
+
: (field ?? null),
|
|
87
|
+
]),
|
|
88
|
+
) as T;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* [Dev Note] Salesforce APIs may return errors as an array or a single object.
|
|
93
|
+
* This helper standardizes the extraction of the error message string.
|
|
94
|
+
*
|
|
95
|
+
* @param data - The response data.
|
|
96
|
+
* @param fallbackError - Fallback error message if response doesn't have a message property
|
|
97
|
+
* @returns The error message string
|
|
98
|
+
*/
|
|
99
|
+
function parseApiResponseError(
|
|
100
|
+
data: any,
|
|
101
|
+
fallbackError: string = "An unknown error occurred",
|
|
102
|
+
): string {
|
|
103
|
+
if (data?.message) {
|
|
104
|
+
return data.message;
|
|
105
|
+
}
|
|
106
|
+
if (data?.error) {
|
|
107
|
+
return data.error;
|
|
108
|
+
}
|
|
109
|
+
if (data?.errors && Array.isArray(data.errors) && data.errors.length > 0) {
|
|
110
|
+
return data.errors.join(" ") || fallbackError;
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
113
|
+
return (
|
|
114
|
+
data
|
|
115
|
+
.map((e) => e?.message)
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join(" ") || fallbackError
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return fallbackError;
|
|
121
|
+
}
|
package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/navigationMenu.tsx
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Link, useLocation } from 'react-router';
|
|
2
|
+
import { getAllRoutes } from './router-utils';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export default function NavigationMenu() {
|
|
6
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
|
|
9
|
+
const isActive = (path: string) => location.pathname === path;
|
|
10
|
+
|
|
11
|
+
const toggleMenu = () => setIsOpen(!isOpen);
|
|
12
|
+
|
|
13
|
+
const navigationRoutes: { path: string; label: string }[] = getAllRoutes()
|
|
14
|
+
.filter(
|
|
15
|
+
route =>
|
|
16
|
+
route.handle?.showInNavigation === true &&
|
|
17
|
+
route.fullPath !== undefined &&
|
|
18
|
+
route.handle?.label !== undefined
|
|
19
|
+
)
|
|
20
|
+
.map(
|
|
21
|
+
route =>
|
|
22
|
+
({
|
|
23
|
+
path: route.fullPath,
|
|
24
|
+
label: route.handle?.label,
|
|
25
|
+
}) as { path: string; label: string }
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<nav className="bg-white border-b border-gray-200">
|
|
30
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
31
|
+
<div className="flex justify-between items-center h-16">
|
|
32
|
+
<Link to="/" className="text-xl font-semibold text-gray-900">
|
|
33
|
+
React App
|
|
34
|
+
</Link>
|
|
35
|
+
<button
|
|
36
|
+
onClick={toggleMenu}
|
|
37
|
+
className="p-2 rounded-md text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
38
|
+
aria-label="Toggle menu"
|
|
39
|
+
>
|
|
40
|
+
<div className="w-6 h-6 flex flex-col justify-center space-y-1.5">
|
|
41
|
+
<span
|
|
42
|
+
className={`block h-0.5 w-6 bg-current transition-all ${
|
|
43
|
+
isOpen ? 'rotate-45 translate-y-2' : ''
|
|
44
|
+
}`}
|
|
45
|
+
/>
|
|
46
|
+
<span
|
|
47
|
+
className={`block h-0.5 w-6 bg-current transition-all ${isOpen ? 'opacity-0' : ''}`}
|
|
48
|
+
/>
|
|
49
|
+
<span
|
|
50
|
+
className={`block h-0.5 w-6 bg-current transition-all ${
|
|
51
|
+
isOpen ? '-rotate-45 -translate-y-2' : ''
|
|
52
|
+
}`}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
</button>
|
|
56
|
+
</div>
|
|
57
|
+
{isOpen && (
|
|
58
|
+
<div className="pb-4">
|
|
59
|
+
<div className="flex flex-col space-y-2">
|
|
60
|
+
{navigationRoutes.map(item => (
|
|
61
|
+
<Link
|
|
62
|
+
key={item.path}
|
|
63
|
+
to={item.path}
|
|
64
|
+
onClick={() => setIsOpen(false)}
|
|
65
|
+
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
|
|
66
|
+
isActive(item.path)
|
|
67
|
+
? 'bg-blue-100 text-blue-700'
|
|
68
|
+
: 'text-gray-700 hover:bg-gray-100'
|
|
69
|
+
}`}
|
|
70
|
+
>
|
|
71
|
+
{item.label}
|
|
72
|
+
</Link>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
</div>
|
|
78
|
+
</nav>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default function Home() {
|
|
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">Home</h1>
|
|
6
|
+
<p className="text-lg text-gray-600 mb-8">
|
|
7
|
+
Welcome to your React application.
|
|
8
|
+
</p>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/pages/NotFound.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Link } from 'react-router';
|
|
2
|
+
|
|
3
|
+
export default function NotFound() {
|
|
4
|
+
return (
|
|
5
|
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
|
|
6
|
+
<div className="text-center">
|
|
7
|
+
<h1 className="text-4xl font-bold text-gray-900 mb-4">404</h1>
|
|
8
|
+
<p className="text-lg text-gray-600 mb-8">Page not found</p>
|
|
9
|
+
<Link
|
|
10
|
+
to="/"
|
|
11
|
+
className="inline-block px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors"
|
|
12
|
+
>
|
|
13
|
+
Go to Home
|
|
14
|
+
</Link>
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
package/dist/force-app/main/default/uiBundles/feature-react-authentication/src/router-utils.tsx
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RouteObject } from 'react-router';
|
|
2
|
+
import { routes } from './routes';
|
|
3
|
+
|
|
4
|
+
export type RouteWithFullPath = RouteObject & { fullPath: string };
|
|
5
|
+
|
|
6
|
+
const flatMapRoutes = (
|
|
7
|
+
route: RouteObject,
|
|
8
|
+
parentPath: string = ''
|
|
9
|
+
): RouteWithFullPath[] => {
|
|
10
|
+
let fullPath: string;
|
|
11
|
+
|
|
12
|
+
if (route.index) {
|
|
13
|
+
fullPath = parentPath || '/';
|
|
14
|
+
} else if (route.path) {
|
|
15
|
+
if (route.path.startsWith('/')) {
|
|
16
|
+
fullPath = route.path;
|
|
17
|
+
} else {
|
|
18
|
+
fullPath =
|
|
19
|
+
parentPath === '/' ? `/${route.path}` : `${parentPath}/${route.path}`;
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
fullPath = parentPath;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const routeWithPath = { ...route, fullPath };
|
|
26
|
+
|
|
27
|
+
const childRoutes =
|
|
28
|
+
route.children?.flatMap(child => flatMapRoutes(child, fullPath)) || [];
|
|
29
|
+
|
|
30
|
+
return [routeWithPath, ...childRoutes];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getAllRoutes = (): RouteWithFullPath[] => {
|
|
34
|
+
return routes.flatMap(route => flatMapRoutes(route));
|
|
35
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { RouteObject } from 'react-router';
|
|
2
|
+
import Home from './pages/Home';
|
|
3
|
+
import NotFound from './pages/NotFound';
|
|
4
|
+
import AuthAppLayout from "./features/authentication/layouts/AuthAppLayout";
|
|
5
|
+
import Login from "./features/authentication/pages/Login";
|
|
6
|
+
import Register from "./features/authentication/pages/Register";
|
|
7
|
+
import ForgotPassword from "./features/authentication/pages/ForgotPassword";
|
|
8
|
+
import ResetPassword from "./features/authentication/pages/ResetPassword";
|
|
9
|
+
import Profile from "./features/authentication/pages/Profile";
|
|
10
|
+
import ChangePassword from "./features/authentication/pages/ChangePassword";
|
|
11
|
+
import AuthenticationRoute from "./features/authentication/layouts/authenticationRouteLayout";
|
|
12
|
+
import PrivateRoute from "./features/authentication/layouts/privateRouteLayout";
|
|
13
|
+
import { ROUTES } from "./features/authentication/authenticationConfig";
|
|
14
|
+
|
|
15
|
+
export const routes: RouteObject[] = [
|
|
16
|
+
{
|
|
17
|
+
path: "/",
|
|
18
|
+
element: <AuthAppLayout />,
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
index: true,
|
|
22
|
+
element: <Home />,
|
|
23
|
+
handle: { showInNavigation: true, label: 'Home' }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
path: '*',
|
|
27
|
+
element: <NotFound />
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
element: <AuthenticationRoute />,
|
|
31
|
+
children: [
|
|
32
|
+
{
|
|
33
|
+
path: ROUTES.LOGIN.PATH,
|
|
34
|
+
element: <Login />,
|
|
35
|
+
handle: { showInNavigation: true, label: "Login", title: ROUTES.LOGIN.TITLE }
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
path: ROUTES.REGISTER.PATH,
|
|
39
|
+
element: <Register />,
|
|
40
|
+
handle: { showInNavigation: false, title: ROUTES.REGISTER.TITLE }
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
path: ROUTES.FORGOT_PASSWORD.PATH,
|
|
44
|
+
element: <ForgotPassword />,
|
|
45
|
+
handle: { showInNavigation: false, title: ROUTES.FORGOT_PASSWORD.TITLE }
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
path: ROUTES.RESET_PASSWORD.PATH,
|
|
49
|
+
element: <ResetPassword />,
|
|
50
|
+
handle: { showInNavigation: false, title: ROUTES.RESET_PASSWORD.TITLE }
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
element: <PrivateRoute showCardSkeleton />,
|
|
56
|
+
children: [
|
|
57
|
+
{
|
|
58
|
+
path: ROUTES.PROFILE.PATH,
|
|
59
|
+
element: <Profile />,
|
|
60
|
+
handle: { showInNavigation: true, label: "Profile", title: ROUTES.PROFILE.TITLE }
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
path: ROUTES.CHANGE_PASSWORD.PATH,
|
|
64
|
+
element: <ChangePassword />,
|
|
65
|
+
handle: { showInNavigation: false, title: ROUTES.CHANGE_PASSWORD.TITLE }
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
];
|