@redacto.io/consent-sdk-react 3.5.0 → 3.6.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.
- package/CHANGELOG.md +6 -0
- package/LICENSE +176 -0
- package/dist/index.d.mts +51 -4
- package/dist/index.d.ts +51 -4
- package/dist/index.js +1891 -243
- package/dist/index.mjs +1890 -243
- package/dist/privacy-center.d.mts +566 -0
- package/dist/privacy-center.d.ts +566 -0
- package/dist/privacy-center.js +17174 -0
- package/dist/privacy-center.mjs +17136 -0
- package/package.json +47 -3
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +201 -118
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +1194 -93
- package/src/RedactoNoticeConsent/api/index.ts +335 -206
- package/src/RedactoNoticeConsent/api/types.ts +140 -16
- package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +602 -0
- package/src/RedactoNoticeConsent/components/index.ts +7 -0
- package/src/RedactoNoticeConsent/injectStyles.ts +11 -0
- package/src/RedactoNoticeConsent/language-codes.ts +61 -0
- package/src/RedactoNoticeConsent/services/storage.ts +122 -0
- package/src/RedactoNoticeConsent/types.ts +2 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +27 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +142 -0
- package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +51 -0
- package/src/RedactoPrivacyCenter/api/actions.ts +444 -0
- package/src/RedactoPrivacyCenter/api/client.ts +413 -0
- package/src/RedactoPrivacyCenter/api/config.ts +33 -0
- package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
- package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
- package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
- package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
- package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
- package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
- package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
- package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +468 -0
- package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +433 -0
- package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +726 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +239 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +305 -0
- package/src/RedactoPrivacyCenter/components/Form.tsx +1455 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +176 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +330 -0
- package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +329 -0
- package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
- package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +302 -0
- package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +218 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +412 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
- package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
- package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
- package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +179 -0
- package/src/RedactoPrivacyCenter/components/constant.ts +20 -0
- package/src/RedactoPrivacyCenter/components/types.ts +68 -0
- package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
- package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
- package/src/RedactoPrivacyCenter/config/table.ts +25 -0
- package/src/RedactoPrivacyCenter/context/AuthContext.tsx +123 -0
- package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +44 -0
- package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
- package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +64 -0
- package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
- package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
- package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
- package/src/RedactoPrivacyCenter/lib/api.ts +468 -0
- package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
- package/src/RedactoPrivacyCenter/lib/constants.ts +116 -0
- package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
- package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
- package/src/RedactoPrivacyCenter/lib/queries.ts +30 -0
- package/src/RedactoPrivacyCenter/lib/types.ts +346 -0
- package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
- package/src/RedactoPrivacyCenter/lib/utils.ts +625 -0
- package/src/RedactoPrivacyCenter/locales/as/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/bho/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/bn/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/brx/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/doi/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/en/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/gom/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/gu/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/hi/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/kn/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ks/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/mai/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ml/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/mr/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ne/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/or/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/pa/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/sa/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/sat/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/sd/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ta/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/te/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ur/translation.json +188 -0
- package/src/RedactoPrivacyCenter/styles/base.css +117 -0
- package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1000 -0
- package/src/RedactoPrivacyCenter/styles/pcStyles.ts +819 -0
- package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
- package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +365 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +479 -0
- package/src/RedactoPrivacyCenter/table/index.ts +2 -0
- package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
- package/src/RedactoPrivacyCenter/ui/Footer.tsx +73 -0
- package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
- package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +87 -0
- package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
- package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
- package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
- package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
- package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
- package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +97 -0
- package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
- package/src/RedactoPrivacyCenter/ui/PCInput.tsx +128 -0
- package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +30 -0
- package/src/RedactoPrivacyCenter/ui/PCModal.tsx +104 -0
- package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +175 -0
- package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +381 -0
- package/src/RedactoPrivacyCenter/ui/PCTable.tsx +137 -0
- package/src/RedactoPrivacyCenter/ui/PCText.tsx +39 -0
- package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
- package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
- package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
- package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
- package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +55 -0
- package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +70 -0
- package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
- package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
- package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
- package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
- package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
- package/src/index.ts +10 -0
- package/src/privacy-center.ts +107 -0
- package/tsconfig.json +2 -0
- package/tsup.config.ts +16 -1
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DigiLockerCallback Component
|
|
3
|
+
*
|
|
4
|
+
* Standalone component for handling DigiLocker redirect callbacks.
|
|
5
|
+
* Clients should add this to their routing (e.g., /digilocker-callback page).
|
|
6
|
+
*
|
|
7
|
+
* Usage in Next.js:
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // pages/digilocker-callback.tsx
|
|
10
|
+
* import { DigiLockerCallback } from '@redacto.io/consent-sdk-react';
|
|
11
|
+
*
|
|
12
|
+
* export default function DigiLockerCallbackPage() {
|
|
13
|
+
* return <DigiLockerCallback accessToken={"<token>"} />;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Usage in React Router:
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <Route path="/digilocker-callback" element={<DigiLockerCallback accessToken={"<token>"} />} />
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* URL Parameters expected from redirect:
|
|
23
|
+
* - session_token: The verification session token
|
|
24
|
+
* - status: "verified" | "failed" | "expired"
|
|
25
|
+
* - verification_reference: (if verified) Reference for consent submission
|
|
26
|
+
* - error_code: (if failed) Error code like GUARDIAN_UNDER_18, SESSION_EXPIRED, etc.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
30
|
+
import { verifyGuardianStatus } from "../api";
|
|
31
|
+
import type { DigiLockerCallbackProps, GuardianVerificationErrorCode } from "../api/types";
|
|
32
|
+
import { injectCheckboxStyles } from "../injectStyles";
|
|
33
|
+
import {
|
|
34
|
+
clearConsentState,
|
|
35
|
+
getConsentState,
|
|
36
|
+
updateConsentState,
|
|
37
|
+
} from "../services/storage";
|
|
38
|
+
|
|
39
|
+
type CallbackStatus = "processing" | "success" | "error";
|
|
40
|
+
|
|
41
|
+
export const DigiLockerCallback: React.FC<DigiLockerCallbackProps> = ({
|
|
42
|
+
accessToken: propAccessToken,
|
|
43
|
+
baseUrl,
|
|
44
|
+
onSuccess,
|
|
45
|
+
onError,
|
|
46
|
+
}) => {
|
|
47
|
+
const [status, setStatus] = useState<CallbackStatus>("processing");
|
|
48
|
+
const [message, setMessage] = useState("Verifying your guardian...");
|
|
49
|
+
const [errorDetail, setErrorDetail] = useState<string | null>(null);
|
|
50
|
+
const retryTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
51
|
+
const redirectTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
52
|
+
const isMountedRef = useRef(true);
|
|
53
|
+
|
|
54
|
+
const getErrorMessage = (errorCode?: GuardianVerificationErrorCode): string => {
|
|
55
|
+
switch (errorCode) {
|
|
56
|
+
case "GUARDIAN_UNDER_18":
|
|
57
|
+
return "Guardian verification failed: The guardian must be 18 years or older.";
|
|
58
|
+
case "SESSION_EXPIRED":
|
|
59
|
+
return "Verification session has expired. Please restart the verification process.";
|
|
60
|
+
case "TOKEN_FAILED":
|
|
61
|
+
return "DigiLocker authentication failed. Please try again.";
|
|
62
|
+
case "DIGILOCKER_AUTH_FAILED":
|
|
63
|
+
return "DigiLocker authorization was cancelled or failed. Please try again.";
|
|
64
|
+
case "NO_AUTH_CODE":
|
|
65
|
+
return "Missing authorization code from DigiLocker. Please try again.";
|
|
66
|
+
default:
|
|
67
|
+
return "Verification failed. Please try again.";
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const redirectToOriginalPage = useCallback(
|
|
72
|
+
(
|
|
73
|
+
originalUrl: string,
|
|
74
|
+
verificationResult: "verified" | "failed" | "expired",
|
|
75
|
+
verificationReference?: string
|
|
76
|
+
) => {
|
|
77
|
+
// Update persisted state with verification result
|
|
78
|
+
updateConsentState({
|
|
79
|
+
verificationResult,
|
|
80
|
+
verificationReference,
|
|
81
|
+
flowState: verificationResult === "verified" ? "consent-form" : "error",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Redirect back to original page
|
|
85
|
+
redirectTimeoutRef.current = setTimeout(() => {
|
|
86
|
+
window.location.href = originalUrl;
|
|
87
|
+
}, 1500);
|
|
88
|
+
},
|
|
89
|
+
[]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const handleCallback = useCallback(async () => {
|
|
93
|
+
try {
|
|
94
|
+
// 1. Extract URL parameters (new format from backend)
|
|
95
|
+
const params = new URLSearchParams(window.location.search);
|
|
96
|
+
const sessionToken = params.get("session_token");
|
|
97
|
+
const urlStatus = params.get("status") as "verified" | "failed" | "expired" | null;
|
|
98
|
+
const verificationReference = params.get("verification_reference");
|
|
99
|
+
const errorCode = params.get("error_code") as GuardianVerificationErrorCode | null;
|
|
100
|
+
|
|
101
|
+
// 2. Retrieve persisted state (optional — popup mode may not have saved state)
|
|
102
|
+
const persistedState = getConsentState();
|
|
103
|
+
|
|
104
|
+
const originalUrl = persistedState?.originalUrl || "/";
|
|
105
|
+
const storedBaseUrl = persistedState?.baseUrl;
|
|
106
|
+
const storedSessionToken = persistedState?.sessionToken;
|
|
107
|
+
|
|
108
|
+
// Use accessToken from props (never stored in sessionStorage for security)
|
|
109
|
+
const accessToken = propAccessToken;
|
|
110
|
+
if (!accessToken) {
|
|
111
|
+
throw new Error("Access token not provided. Please pass accessToken as a prop.");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Use session token from URL (source of truth) or stored state as fallback
|
|
115
|
+
const activeSessionToken = sessionToken || storedSessionToken;
|
|
116
|
+
if (!activeSessionToken) {
|
|
117
|
+
throw new Error("Session token not found. Please restart the verification process.");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Check if we're in an iframe (for iframe mode)
|
|
121
|
+
// Wrapped in try-catch: cross-origin iframes throw SecurityError on window.top access
|
|
122
|
+
let isInIframe = false;
|
|
123
|
+
try {
|
|
124
|
+
isInIframe = window.self !== window.top;
|
|
125
|
+
} catch {
|
|
126
|
+
isInIframe = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 3. If status is already in URL params (direct redirect from backend)
|
|
130
|
+
if (urlStatus === "verified" && verificationReference) {
|
|
131
|
+
setStatus("success");
|
|
132
|
+
setMessage("Guardian verified successfully! Redirecting...");
|
|
133
|
+
onSuccess?.(verificationReference);
|
|
134
|
+
|
|
135
|
+
// If in iframe, postMessage to parent instead of redirecting
|
|
136
|
+
if (isInIframe && window.parent) {
|
|
137
|
+
window.parent.postMessage(
|
|
138
|
+
{
|
|
139
|
+
type: "DIGILOCKER_VERIFICATION_STATUS",
|
|
140
|
+
status: "verified",
|
|
141
|
+
verificationReference,
|
|
142
|
+
},
|
|
143
|
+
window.location.origin
|
|
144
|
+
);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
redirectToOriginalPage(originalUrl, "verified", verificationReference);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (urlStatus === "failed" || urlStatus === "expired") {
|
|
153
|
+
const urlErrorCode = errorCode ?? undefined;
|
|
154
|
+
const errorMessage = getErrorMessage(urlErrorCode);
|
|
155
|
+
setStatus("error");
|
|
156
|
+
setMessage("Verification failed");
|
|
157
|
+
setErrorDetail(errorMessage);
|
|
158
|
+
onError?.(new Error(errorMessage), urlErrorCode);
|
|
159
|
+
|
|
160
|
+
// If in iframe, postMessage to parent instead of redirecting
|
|
161
|
+
if (isInIframe && window.parent) {
|
|
162
|
+
window.parent.postMessage(
|
|
163
|
+
{
|
|
164
|
+
type: "DIGILOCKER_VERIFICATION_STATUS",
|
|
165
|
+
status: urlStatus,
|
|
166
|
+
errorCode: urlErrorCode,
|
|
167
|
+
error: errorMessage,
|
|
168
|
+
},
|
|
169
|
+
window.location.origin
|
|
170
|
+
);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
redirectToOriginalPage(originalUrl, urlStatus);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 4. If no status in URL, poll the backend for verification status
|
|
179
|
+
setMessage("Processing verification...");
|
|
180
|
+
|
|
181
|
+
const apiBaseUrl = baseUrl || storedBaseUrl;
|
|
182
|
+
|
|
183
|
+
const response = await verifyGuardianStatus({
|
|
184
|
+
accessToken,
|
|
185
|
+
baseUrl: apiBaseUrl,
|
|
186
|
+
sessionToken: activeSessionToken,
|
|
187
|
+
});
|
|
188
|
+
if (!isMountedRef.current) return;
|
|
189
|
+
|
|
190
|
+
if (response.status === "verified") {
|
|
191
|
+
// Use top-level verification_reference first, fall back to guardian_details
|
|
192
|
+
const verificationRef = response.verification_reference || response.guardian_details?.verification_reference || undefined;
|
|
193
|
+
|
|
194
|
+
if (!verificationRef) {
|
|
195
|
+
setStatus("error");
|
|
196
|
+
setMessage("Verification failed");
|
|
197
|
+
setErrorDetail("Verification completed but no reference received. Please try again.");
|
|
198
|
+
onError?.(new Error("Verification completed but no reference received."));
|
|
199
|
+
redirectToOriginalPage(originalUrl, "failed");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
setStatus("success");
|
|
204
|
+
setMessage("Guardian verified successfully! Redirecting...");
|
|
205
|
+
onSuccess?.(verificationRef);
|
|
206
|
+
|
|
207
|
+
// If in iframe, postMessage to parent instead of redirecting
|
|
208
|
+
if (isInIframe && window.parent) {
|
|
209
|
+
window.parent.postMessage(
|
|
210
|
+
{
|
|
211
|
+
type: "DIGILOCKER_VERIFICATION_STATUS",
|
|
212
|
+
status: "verified",
|
|
213
|
+
verificationReference: verificationRef,
|
|
214
|
+
},
|
|
215
|
+
window.location.origin
|
|
216
|
+
);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
redirectToOriginalPage(originalUrl, "verified", verificationRef);
|
|
221
|
+
} else if (response.status === "failed" || response.status === "expired") {
|
|
222
|
+
const responseErrorCode = response.error_code ?? undefined;
|
|
223
|
+
const errorMessage = response.error || getErrorMessage(responseErrorCode);
|
|
224
|
+
setStatus("error");
|
|
225
|
+
setMessage("Verification failed");
|
|
226
|
+
setErrorDetail(errorMessage);
|
|
227
|
+
onError?.(new Error(errorMessage), responseErrorCode);
|
|
228
|
+
|
|
229
|
+
// If in iframe, postMessage to parent instead of redirecting
|
|
230
|
+
if (isInIframe && window.parent) {
|
|
231
|
+
window.parent.postMessage(
|
|
232
|
+
{
|
|
233
|
+
type: "DIGILOCKER_VERIFICATION_STATUS",
|
|
234
|
+
status: response.status,
|
|
235
|
+
errorCode: responseErrorCode,
|
|
236
|
+
error: errorMessage,
|
|
237
|
+
},
|
|
238
|
+
window.location.origin
|
|
239
|
+
);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
redirectToOriginalPage(originalUrl, response.status);
|
|
244
|
+
} else {
|
|
245
|
+
// Still in progress - this shouldn't happen on callback page
|
|
246
|
+
// but handle it gracefully
|
|
247
|
+
setMessage("Verification is still in progress. Please wait...");
|
|
248
|
+
// Poll again after a short delay
|
|
249
|
+
// Retry with exponential backoff before giving up
|
|
250
|
+
const MAX_RETRIES = 3;
|
|
251
|
+
let retryCount = 0;
|
|
252
|
+
|
|
253
|
+
const attemptRetry = () => {
|
|
254
|
+
retryCount++;
|
|
255
|
+
const delay = 3000 * Math.pow(2, retryCount - 1); // 3s, 6s, 12s
|
|
256
|
+
retryTimeoutRef.current = setTimeout(async () => {
|
|
257
|
+
if (!isMountedRef.current) return;
|
|
258
|
+
try {
|
|
259
|
+
const retryResponse = await verifyGuardianStatus({
|
|
260
|
+
accessToken,
|
|
261
|
+
baseUrl: apiBaseUrl,
|
|
262
|
+
sessionToken: activeSessionToken,
|
|
263
|
+
});
|
|
264
|
+
if (!isMountedRef.current) return;
|
|
265
|
+
|
|
266
|
+
const retryRef = retryResponse.verification_reference || retryResponse.guardian_details?.verification_reference || undefined;
|
|
267
|
+
|
|
268
|
+
if (retryResponse.status === "verified" && retryRef) {
|
|
269
|
+
setStatus("success");
|
|
270
|
+
setMessage("Guardian verified successfully! Redirecting...");
|
|
271
|
+
onSuccess?.(retryRef);
|
|
272
|
+
|
|
273
|
+
if (isInIframe && window.parent) {
|
|
274
|
+
window.parent.postMessage(
|
|
275
|
+
{
|
|
276
|
+
type: "DIGILOCKER_VERIFICATION_STATUS",
|
|
277
|
+
status: "verified",
|
|
278
|
+
verificationReference: retryRef,
|
|
279
|
+
},
|
|
280
|
+
window.location.origin
|
|
281
|
+
);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
redirectToOriginalPage(originalUrl, "verified", retryRef);
|
|
286
|
+
} else if (retryResponse.status === "failed" || retryResponse.status === "expired") {
|
|
287
|
+
const retryErrorCode = retryResponse.error_code ?? undefined;
|
|
288
|
+
const retryErrorMessage = retryResponse.error || getErrorMessage(retryErrorCode) || "Verification could not be completed. Please try again.";
|
|
289
|
+
setStatus("error");
|
|
290
|
+
setMessage("Verification failed");
|
|
291
|
+
setErrorDetail(retryErrorMessage);
|
|
292
|
+
onError?.(new Error(retryErrorMessage), retryErrorCode);
|
|
293
|
+
|
|
294
|
+
if (isInIframe && window.parent) {
|
|
295
|
+
window.parent.postMessage(
|
|
296
|
+
{
|
|
297
|
+
type: "DIGILOCKER_VERIFICATION_STATUS",
|
|
298
|
+
status: retryResponse.status,
|
|
299
|
+
errorCode: retryErrorCode,
|
|
300
|
+
error: retryErrorMessage,
|
|
301
|
+
},
|
|
302
|
+
window.location.origin
|
|
303
|
+
);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
redirectToOriginalPage(originalUrl, retryResponse.status);
|
|
308
|
+
} else if (retryCount < MAX_RETRIES) {
|
|
309
|
+
setMessage("Verification taking longer than expected. Please wait...");
|
|
310
|
+
attemptRetry();
|
|
311
|
+
} else {
|
|
312
|
+
const timeoutMessage = "Verification could not be completed in time. Please try again.";
|
|
313
|
+
setStatus("error");
|
|
314
|
+
setMessage("Verification failed");
|
|
315
|
+
setErrorDetail(timeoutMessage);
|
|
316
|
+
onError?.(new Error(timeoutMessage));
|
|
317
|
+
redirectToOriginalPage(originalUrl, "failed");
|
|
318
|
+
}
|
|
319
|
+
} catch (retryErr) {
|
|
320
|
+
if (!isMountedRef.current) return;
|
|
321
|
+
if (retryCount < MAX_RETRIES) {
|
|
322
|
+
attemptRetry();
|
|
323
|
+
} else {
|
|
324
|
+
setStatus("error");
|
|
325
|
+
setMessage("Verification failed");
|
|
326
|
+
setErrorDetail((retryErr as Error).message);
|
|
327
|
+
onError?.(retryErr as Error);
|
|
328
|
+
redirectToOriginalPage(originalUrl, "failed");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}, delay);
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
attemptRetry();
|
|
335
|
+
}
|
|
336
|
+
} catch (error) {
|
|
337
|
+
console.error("DigiLocker callback error:", error);
|
|
338
|
+
setStatus("error");
|
|
339
|
+
|
|
340
|
+
const err = error as Error;
|
|
341
|
+
setMessage("Verification failed");
|
|
342
|
+
setErrorDetail(err.message || "An error occurred during verification");
|
|
343
|
+
|
|
344
|
+
onError?.(err);
|
|
345
|
+
|
|
346
|
+
// Try to redirect back even on error
|
|
347
|
+
const persistedState = getConsentState();
|
|
348
|
+
if (persistedState?.originalUrl) {
|
|
349
|
+
redirectTimeoutRef.current = setTimeout(() => {
|
|
350
|
+
redirectToOriginalPage(persistedState.originalUrl, "failed");
|
|
351
|
+
}, 3000);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}, [propAccessToken, baseUrl, onSuccess, onError, redirectToOriginalPage]);
|
|
355
|
+
|
|
356
|
+
useEffect(() => {
|
|
357
|
+
injectCheckboxStyles();
|
|
358
|
+
handleCallback();
|
|
359
|
+
return () => {
|
|
360
|
+
isMountedRef.current = false;
|
|
361
|
+
if (retryTimeoutRef.current) clearTimeout(retryTimeoutRef.current);
|
|
362
|
+
if (redirectTimeoutRef.current) clearTimeout(redirectTimeoutRef.current);
|
|
363
|
+
};
|
|
364
|
+
}, [handleCallback]);
|
|
365
|
+
|
|
366
|
+
const handleRetry = useCallback(() => {
|
|
367
|
+
const persistedState = getConsentState();
|
|
368
|
+
if (persistedState?.originalUrl) {
|
|
369
|
+
clearConsentState();
|
|
370
|
+
window.location.href = persistedState.originalUrl;
|
|
371
|
+
} else {
|
|
372
|
+
window.location.href = "/";
|
|
373
|
+
}
|
|
374
|
+
}, []);
|
|
375
|
+
|
|
376
|
+
// --- Styles ---
|
|
377
|
+
|
|
378
|
+
const containerStyle: React.CSSProperties = {
|
|
379
|
+
display: "flex",
|
|
380
|
+
alignItems: "center",
|
|
381
|
+
justifyContent: "center",
|
|
382
|
+
minHeight: "100vh",
|
|
383
|
+
backgroundColor: "#f8fafc",
|
|
384
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
|
385
|
+
padding: "24px",
|
|
386
|
+
boxSizing: "border-box",
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const cardStyle: React.CSSProperties = {
|
|
390
|
+
backgroundColor: "#ffffff",
|
|
391
|
+
borderRadius: "16px",
|
|
392
|
+
boxShadow: "0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 30px rgba(0, 0, 0, 0.06)",
|
|
393
|
+
padding: "48px 40px 40px",
|
|
394
|
+
textAlign: "center",
|
|
395
|
+
maxWidth: "420px",
|
|
396
|
+
width: "100%",
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const spinnerContainerStyle: React.CSSProperties = {
|
|
400
|
+
width: "72px",
|
|
401
|
+
height: "72px",
|
|
402
|
+
margin: "0 auto 28px",
|
|
403
|
+
position: "relative",
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const spinnerStyle: React.CSSProperties = {
|
|
407
|
+
width: "72px",
|
|
408
|
+
height: "72px",
|
|
409
|
+
border: "3px solid #e5e7eb",
|
|
410
|
+
borderTopColor: "#4f87ff",
|
|
411
|
+
borderRadius: "50%",
|
|
412
|
+
animation: "redacto-dl-spin 0.8s linear infinite",
|
|
413
|
+
boxSizing: "border-box",
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const iconContainerStyle: React.CSSProperties = {
|
|
417
|
+
width: "72px",
|
|
418
|
+
height: "72px",
|
|
419
|
+
borderRadius: "50%",
|
|
420
|
+
display: "flex",
|
|
421
|
+
alignItems: "center",
|
|
422
|
+
justifyContent: "center",
|
|
423
|
+
margin: "0 auto 28px",
|
|
424
|
+
animation: "redacto-dl-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards",
|
|
425
|
+
position: "relative",
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
const successIconStyle: React.CSSProperties = {
|
|
429
|
+
...iconContainerStyle,
|
|
430
|
+
backgroundColor: "#d1fae5",
|
|
431
|
+
color: "#059669",
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const errorIconStyle: React.CSSProperties = {
|
|
435
|
+
...iconContainerStyle,
|
|
436
|
+
backgroundColor: "#fee2e2",
|
|
437
|
+
color: "#dc2626",
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const titleStyle: React.CSSProperties = {
|
|
441
|
+
fontSize: "22px",
|
|
442
|
+
fontWeight: 700,
|
|
443
|
+
color: "#111827",
|
|
444
|
+
margin: "0 0 8px 0",
|
|
445
|
+
letterSpacing: "-0.01em",
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const messageStyle: React.CSSProperties = {
|
|
449
|
+
fontSize: "14px",
|
|
450
|
+
color: "#6b7280",
|
|
451
|
+
marginBottom: "0",
|
|
452
|
+
lineHeight: 1.6,
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const subtextStyle: React.CSSProperties = {
|
|
456
|
+
fontSize: "13px",
|
|
457
|
+
color: "#9ca3af",
|
|
458
|
+
marginTop: "16px",
|
|
459
|
+
lineHeight: 1.5,
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const errorDetailStyle: React.CSSProperties = {
|
|
463
|
+
fontSize: "13px",
|
|
464
|
+
color: "#dc2626",
|
|
465
|
+
marginTop: "16px",
|
|
466
|
+
padding: "12px 16px",
|
|
467
|
+
backgroundColor: "#fef2f2",
|
|
468
|
+
borderRadius: "10px",
|
|
469
|
+
border: "1px solid #fecaca",
|
|
470
|
+
lineHeight: 1.5,
|
|
471
|
+
textAlign: "left",
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
const buttonStyle: React.CSSProperties = {
|
|
475
|
+
marginTop: "24px",
|
|
476
|
+
padding: "12px 28px",
|
|
477
|
+
backgroundColor: "#4f87ff",
|
|
478
|
+
color: "#ffffff",
|
|
479
|
+
border: "none",
|
|
480
|
+
borderRadius: "10px",
|
|
481
|
+
fontSize: "15px",
|
|
482
|
+
fontWeight: 600,
|
|
483
|
+
cursor: "pointer",
|
|
484
|
+
transition: "background-color 0.2s, transform 0.15s",
|
|
485
|
+
width: "100%",
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const keyframesStyle = `
|
|
489
|
+
@keyframes redacto-dl-spin {
|
|
490
|
+
to { transform: rotate(360deg); }
|
|
491
|
+
}
|
|
492
|
+
@keyframes redacto-dl-pop {
|
|
493
|
+
0% { transform: scale(0.3); opacity: 0; }
|
|
494
|
+
60% { transform: scale(1.08); opacity: 1; }
|
|
495
|
+
100% { transform: scale(1); opacity: 1; }
|
|
496
|
+
}
|
|
497
|
+
@keyframes redacto-dl-check {
|
|
498
|
+
0% { stroke-dashoffset: 24; }
|
|
499
|
+
100% { stroke-dashoffset: 0; }
|
|
500
|
+
}
|
|
501
|
+
@keyframes redacto-dl-pulse {
|
|
502
|
+
0%, 100% { transform: scale(1); opacity: 0.6; }
|
|
503
|
+
50% { transform: scale(1.15); opacity: 0; }
|
|
504
|
+
}
|
|
505
|
+
.redacto-dl-retry-btn:hover {
|
|
506
|
+
background-color: #3d6fdb !important;
|
|
507
|
+
transform: translateY(-1px);
|
|
508
|
+
}
|
|
509
|
+
.redacto-dl-retry-btn:active {
|
|
510
|
+
transform: translateY(0);
|
|
511
|
+
}
|
|
512
|
+
`;
|
|
513
|
+
|
|
514
|
+
return (
|
|
515
|
+
<>
|
|
516
|
+
<style dangerouslySetInnerHTML={{ __html: keyframesStyle }} />
|
|
517
|
+
<div style={containerStyle}>
|
|
518
|
+
<div style={cardStyle}>
|
|
519
|
+
{status === "processing" && (
|
|
520
|
+
<>
|
|
521
|
+
<div style={spinnerContainerStyle}>
|
|
522
|
+
<div style={spinnerStyle} />
|
|
523
|
+
</div>
|
|
524
|
+
<h2 style={titleStyle}>Processing Verification</h2>
|
|
525
|
+
<p style={messageStyle}>{message}</p>
|
|
526
|
+
<p style={subtextStyle}>
|
|
527
|
+
Please wait while we verify your guardian's identity...
|
|
528
|
+
</p>
|
|
529
|
+
</>
|
|
530
|
+
)}
|
|
531
|
+
|
|
532
|
+
{status === "success" && (
|
|
533
|
+
<>
|
|
534
|
+
<div style={{ position: "relative", width: "72px", height: "72px", margin: "0 auto 28px" }}>
|
|
535
|
+
{/* Pulse ring */}
|
|
536
|
+
<div style={{
|
|
537
|
+
position: "absolute",
|
|
538
|
+
inset: "-8px",
|
|
539
|
+
borderRadius: "50%",
|
|
540
|
+
border: "2px solid #d1fae5",
|
|
541
|
+
animation: "redacto-dl-pulse 1.5s ease-out infinite",
|
|
542
|
+
}} />
|
|
543
|
+
<div style={successIconStyle}>
|
|
544
|
+
<svg
|
|
545
|
+
width="30"
|
|
546
|
+
height="30"
|
|
547
|
+
viewBox="0 0 24 24"
|
|
548
|
+
fill="none"
|
|
549
|
+
stroke="currentColor"
|
|
550
|
+
strokeWidth="2.5"
|
|
551
|
+
strokeLinecap="round"
|
|
552
|
+
strokeLinejoin="round"
|
|
553
|
+
style={{ strokeDasharray: 24, animation: "redacto-dl-check 0.4s ease-out 0.3s forwards", strokeDashoffset: 24 }}
|
|
554
|
+
>
|
|
555
|
+
<polyline points="20 6 9 17 4 12" />
|
|
556
|
+
</svg>
|
|
557
|
+
</div>
|
|
558
|
+
</div>
|
|
559
|
+
<h2 style={titleStyle}>Verification Successful</h2>
|
|
560
|
+
<p style={messageStyle}>{message}</p>
|
|
561
|
+
<p style={subtextStyle}>
|
|
562
|
+
You will be redirected automatically.
|
|
563
|
+
</p>
|
|
564
|
+
</>
|
|
565
|
+
)}
|
|
566
|
+
|
|
567
|
+
{status === "error" && (
|
|
568
|
+
<>
|
|
569
|
+
<div style={errorIconStyle}>
|
|
570
|
+
<svg
|
|
571
|
+
width="30"
|
|
572
|
+
height="30"
|
|
573
|
+
viewBox="0 0 24 24"
|
|
574
|
+
fill="none"
|
|
575
|
+
stroke="currentColor"
|
|
576
|
+
strokeWidth="2.5"
|
|
577
|
+
strokeLinecap="round"
|
|
578
|
+
strokeLinejoin="round"
|
|
579
|
+
>
|
|
580
|
+
<line x1="18" y1="6" x2="6" y2="18" />
|
|
581
|
+
<line x1="6" y1="6" x2="18" y2="18" />
|
|
582
|
+
</svg>
|
|
583
|
+
</div>
|
|
584
|
+
<h2 style={titleStyle}>Verification Failed</h2>
|
|
585
|
+
<p style={messageStyle}>{message}</p>
|
|
586
|
+
{errorDetail && <p style={errorDetailStyle}>{errorDetail}</p>}
|
|
587
|
+
<button
|
|
588
|
+
className="redacto-dl-retry-btn"
|
|
589
|
+
style={buttonStyle}
|
|
590
|
+
onClick={handleRetry}
|
|
591
|
+
>
|
|
592
|
+
Try Again
|
|
593
|
+
</button>
|
|
594
|
+
</>
|
|
595
|
+
)}
|
|
596
|
+
</div>
|
|
597
|
+
</div>
|
|
598
|
+
</>
|
|
599
|
+
);
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
export default DigiLockerCallback;
|
|
@@ -133,6 +133,17 @@ export const injectCheckboxStyles = () => {
|
|
|
133
133
|
outline: 3px solid #FFF9C4 !important;
|
|
134
134
|
outline-offset: 2px !important;
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
/* Spinner animation for verification screens */
|
|
138
|
+
@keyframes spin {
|
|
139
|
+
from { transform: rotate(0deg); }
|
|
140
|
+
to { transform: rotate(360deg); }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* DigiLocker callback retry button hover */
|
|
144
|
+
.redacto-dl-retry-btn:hover {
|
|
145
|
+
background-color: #2563eb !important;
|
|
146
|
+
}
|
|
136
147
|
`;
|
|
137
148
|
|
|
138
149
|
document.head.appendChild(style);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps display language names (as used in supported_languages_and_translations
|
|
3
|
+
* keys and the language dropdown) to BCP-47 codes for the submit-consent payload.
|
|
4
|
+
*
|
|
5
|
+
* Covers English + the 22 languages in the 8th Schedule of the Indian Constitution
|
|
6
|
+
* (DPDP Act 2023, Sections 5 & 6).
|
|
7
|
+
*/
|
|
8
|
+
const LANGUAGE_NAME_TO_BCP47: Record<string, string> = {
|
|
9
|
+
English: "en",
|
|
10
|
+
Assamese: "as",
|
|
11
|
+
Bengali: "bn",
|
|
12
|
+
Bodo: "brx",
|
|
13
|
+
Dogri: "doi",
|
|
14
|
+
Gujarati: "gu",
|
|
15
|
+
Hindi: "hi",
|
|
16
|
+
Kannada: "kn",
|
|
17
|
+
Kashmiri: "ks",
|
|
18
|
+
Konkani: "gom",
|
|
19
|
+
Maithili: "mai",
|
|
20
|
+
Malayalam: "ml",
|
|
21
|
+
Manipuri: "mni-Mtei",
|
|
22
|
+
Marathi: "mr",
|
|
23
|
+
Nepali: "ne",
|
|
24
|
+
Odia: "or",
|
|
25
|
+
Punjabi: "pa",
|
|
26
|
+
Sanskrit: "sa",
|
|
27
|
+
Santali: "sat",
|
|
28
|
+
Sindhi: "sd",
|
|
29
|
+
Tamil: "ta",
|
|
30
|
+
Telugu: "te",
|
|
31
|
+
Urdu: "ur",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const KNOWN_BCP47_CODES = new Set(Object.values(LANGUAGE_NAME_TO_BCP47));
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Convert a language display name or code to a BCP-47 code.
|
|
38
|
+
* Handles these cases:
|
|
39
|
+
* 1. Display name ("Punjabi") → BCP-47 ("pa")
|
|
40
|
+
* 2. Already a BCP-47 tag, including region/script subtags ("pa", "en-US", "zh-Hans") → returned as-is
|
|
41
|
+
* 3. Unknown value → falls back to "en"
|
|
42
|
+
*/
|
|
43
|
+
export const toBcp47Code = (language: string): string => {
|
|
44
|
+
if (LANGUAGE_NAME_TO_BCP47[language]) {
|
|
45
|
+
return LANGUAGE_NAME_TO_BCP47[language];
|
|
46
|
+
}
|
|
47
|
+
if (KNOWN_BCP47_CODES.has(language)) {
|
|
48
|
+
return language;
|
|
49
|
+
}
|
|
50
|
+
const lower = language.toLowerCase();
|
|
51
|
+
for (const [name, code] of Object.entries(LANGUAGE_NAME_TO_BCP47)) {
|
|
52
|
+
if (name.toLowerCase() === lower) {
|
|
53
|
+
return code;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Pass through well-formed BCP-47 tags with subtags (e.g. en-US, pa-IN, zh-Hans).
|
|
57
|
+
if (/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/.test(language)) {
|
|
58
|
+
return language;
|
|
59
|
+
}
|
|
60
|
+
return "en";
|
|
61
|
+
};
|