@redacto.io/consent-sdk-react 10.0.0-beta.8 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +17 -0
- package/README.md +141 -3
- package/dist/chunk-FEGTW73Q.mjs +182 -0
- package/dist/{chunk-6A665OPR.mjs → chunk-OGL6OC3A.mjs} +4 -0
- package/dist/fonts.d.mts +35 -0
- package/dist/fonts.d.ts +35 -0
- package/dist/fonts.js +183 -0
- package/dist/fonts.mjs +10 -0
- package/dist/index.d.mts +41 -4
- package/dist/index.d.ts +41 -4
- package/dist/index.js +881 -416
- package/dist/index.mjs +502 -253
- package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
- package/dist/privacy-center.d.mts +51 -11
- package/dist/privacy-center.d.ts +51 -11
- package/dist/privacy-center.js +252 -136
- package/dist/privacy-center.mjs +251 -137
- package/dist/types-6Aj7faxL.d.mts +57 -0
- package/dist/types-6Aj7faxL.d.ts +57 -0
- package/package.json +10 -1
- package/.turbo/turbo-build.log +0 -22
- package/.turbo/turbo-test.log +0 -203
- package/.turbo/turbo-verify-pack.log +0 -6
- package/CHANGELOG.md +0 -343
- package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -934
- package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2160
- package/src/RedactoNoticeAssisted/api/index.ts +0 -275
- package/src/RedactoNoticeAssisted/api/types.ts +0 -182
- package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
- package/src/RedactoNoticeAssisted/constants.ts +0 -51
- package/src/RedactoNoticeAssisted/i18n.ts +0 -1408
- package/src/RedactoNoticeAssisted/index.ts +0 -1
- package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
- package/src/RedactoNoticeAssisted/styles.ts +0 -730
- package/src/RedactoNoticeAssisted/types.ts +0 -26
- package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1152
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4258
- package/src/RedactoNoticeConsent/api/index.ts +0 -512
- package/src/RedactoNoticeConsent/api/types.ts +0 -469
- package/src/RedactoNoticeConsent/assets/redacto-logo.png +0 -0
- package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +0 -602
- package/src/RedactoNoticeConsent/components/index.ts +0 -7
- package/src/RedactoNoticeConsent/constants.ts +0 -20
- package/src/RedactoNoticeConsent/index.ts +0 -1
- package/src/RedactoNoticeConsent/injectStyles.ts +0 -151
- package/src/RedactoNoticeConsent/language-codes.ts +0 -95
- package/src/RedactoNoticeConsent/services/storage.ts +0 -122
- package/src/RedactoNoticeConsent/styles.ts +0 -409
- package/src/RedactoNoticeConsent/types.ts +0 -54
- package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
- package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
- package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -687
- package/src/RedactoNoticeConsentInline/api/index.ts +0 -106
- package/src/RedactoNoticeConsentInline/api/types.ts +0 -183
- package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
- package/src/RedactoNoticeConsentInline/index.ts +0 -1
- package/src/RedactoNoticeConsentInline/injectStyles.ts +0 -40
- package/src/RedactoNoticeConsentInline/styles.ts +0 -397
- package/src/RedactoNoticeConsentInline/types.ts +0 -51
- package/src/RedactoNoticeConsentInline/useMediaQuery.ts +0 -36
- package/src/RedactoPrivacyCenter/NotificationsPage.tsx +0 -182
- package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +0 -19
- package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +0 -156
- package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +0 -17
- package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +0 -79
- package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +0 -36
- package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +0 -177
- package/src/RedactoPrivacyCenter/PrivacyCenterMyReceiptPage.tsx +0 -26
- package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +0 -58
- package/src/RedactoPrivacyCenter/api/actions.ts +0 -695
- package/src/RedactoPrivacyCenter/api/client.ts +0 -911
- package/src/RedactoPrivacyCenter/api/config.ts +0 -33
- package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -260
- package/src/RedactoPrivacyCenter/api/orgBranding.ts +0 -16
- package/src/RedactoPrivacyCenter/api/upload.ts +0 -93
- package/src/RedactoPrivacyCenter/assets/character.svg +0 -31
- package/src/RedactoPrivacyCenter/assets/fileAttach.svg +0 -9
- package/src/RedactoPrivacyCenter/assets/greenTick.svg +0 -4
- package/src/RedactoPrivacyCenter/assets/mail.svg +0 -3
- package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +0 -9
- package/src/RedactoPrivacyCenter/assets/sentImg.svg +0 -9
- package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +0 -9
- package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +0 -252
- package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +0 -239
- package/src/RedactoPrivacyCenter/components/AppShell/AppShell.tsx +0 -268
- package/src/RedactoPrivacyCenter/components/AppShell/MobileNavDrawer.tsx +0 -218
- package/src/RedactoPrivacyCenter/components/AppShell/NavItem.tsx +0 -205
- package/src/RedactoPrivacyCenter/components/AppShell/PageHeader.tsx +0 -107
- package/src/RedactoPrivacyCenter/components/AppShell/SidebarNav.tsx +0 -100
- package/src/RedactoPrivacyCenter/components/AppShell/TopAppBar.tsx +0 -339
- package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +0 -245
- package/src/RedactoPrivacyCenter/components/AppShell/hooks/useIsTruncated.ts +0 -28
- package/src/RedactoPrivacyCenter/components/AppShell/hooks/useKeyboardShortcut.ts +0 -40
- package/src/RedactoPrivacyCenter/components/AppShell/hooks/useSidebarState.ts +0 -62
- package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +0 -36
- package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +0 -38
- package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +0 -31
- package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +0 -79
- package/src/RedactoPrivacyCenter/components/CaseDetails/FinalizedTooltipWrapper.tsx +0 -25
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +0 -96
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +0 -97
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +0 -156
- package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +0 -171
- package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +0 -23
- package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +0 -116
- package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +0 -43
- package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +0 -71
- package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +0 -469
- package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +0 -426
- package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +0 -1206
- package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -218
- package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +0 -138
- package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +0 -7
- package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +0 -179
- package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +0 -318
- package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +0 -333
- package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +0 -102
- package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +0 -159
- package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +0 -189
- package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +0 -118
- package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +0 -66
- package/src/RedactoPrivacyCenter/components/DataRequest/ProductSelectionSection.tsx +0 -222
- package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +0 -331
- package/src/RedactoPrivacyCenter/components/Form.tsx +0 -1796
- package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +0 -174
- package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +0 -337
- package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +0 -334
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +0 -173
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +0 -18
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +0 -54
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +0 -57
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +0 -19
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +0 -92
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +0 -20
- package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +0 -58
- package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +0 -10
- package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +0 -112
- package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +0 -27
- package/src/RedactoPrivacyCenter/components/Pagination.tsx +0 -140
- package/src/RedactoPrivacyCenter/components/PrivacyCenterEmptyState.tsx +0 -76
- package/src/RedactoPrivacyCenter/components/PrivacyCenterSessionExpired.tsx +0 -97
- package/src/RedactoPrivacyCenter/components/ReceiptsList.tsx +0 -454
- package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +0 -270
- package/src/RedactoPrivacyCenter/components/SelectUser.tsx +0 -95
- package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -187
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +0 -25
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +0 -21
- package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +0 -159
- package/src/RedactoPrivacyCenter/components/constant.ts +0 -52
- package/src/RedactoPrivacyCenter/components/groupHelpers.ts +0 -119
- package/src/RedactoPrivacyCenter/components/receiptColumns.tsx +0 -203
- package/src/RedactoPrivacyCenter/components/types.ts +0 -123
- package/src/RedactoPrivacyCenter/components/utils.tsx +0 -10
- package/src/RedactoPrivacyCenter/config/routes.ts +0 -9
- package/src/RedactoPrivacyCenter/config/table.ts +0 -25
- package/src/RedactoPrivacyCenter/context/AuthContext.tsx +0 -160
- package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +0 -47
- package/src/RedactoPrivacyCenter/context/BrandingContext.tsx +0 -52
- package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +0 -92
- package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +0 -181
- package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +0 -11
- package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +0 -96
- package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +0 -30
- package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +0 -80
- package/src/RedactoPrivacyCenter/context/ProfileSwitchContext.tsx +0 -15
- package/src/RedactoPrivacyCenter/context/types.ts +0 -19
- package/src/RedactoPrivacyCenter/lib/api.ts +0 -759
- package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
- package/src/RedactoPrivacyCenter/lib/constants.ts +0 -276
- package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
- package/src/RedactoPrivacyCenter/lib/locales.ts +0 -102
- package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
- package/src/RedactoPrivacyCenter/lib/types.ts +0 -876
- package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
- package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
- package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
- package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
- package/src/RedactoPrivacyCenter/lib/utils.ts +0 -783
- package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -357
- package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -345
- package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -342
- package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -342
- package/src/RedactoPrivacyCenter/styles/applyBrandingTheme.ts +0 -66
- package/src/RedactoPrivacyCenter/styles/base.css +0 -117
- package/src/RedactoPrivacyCenter/styles/injectStyles.ts +0 -3108
- package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -831
- package/src/RedactoPrivacyCenter/styles/responsive.ts +0 -138
- package/src/RedactoPrivacyCenter/styles/variables.css +0 -96
- package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +0 -387
- package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +0 -468
- package/src/RedactoPrivacyCenter/table/index.ts +0 -2
- package/src/RedactoPrivacyCenter/types/images.d.ts +0 -29
- package/src/RedactoPrivacyCenter/ui/Footer.tsx +0 -69
- package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +0 -54
- package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +0 -93
- package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +0 -47
- package/src/RedactoPrivacyCenter/ui/PCAvatar.test.tsx +0 -83
- package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -93
- package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
- package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
- package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
- package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
- package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
- package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
- package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
- package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
- package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
- package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
- package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
- package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
- package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
- package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
- package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
- package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
- package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
- package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
- package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
- package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
- package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
- package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
- package/src/index.ts +0 -19
- package/src/privacy-center.ts +0 -113
- package/src/shared/api-errors.ts +0 -180
- package/src/shared/notice-consent-status.ts +0 -190
- package/src/types/css.d.ts +0 -4
- package/src/types/images.d.ts +0 -19
- package/src/types/react-jsx.d.ts +0 -26
- package/tests/DataAvailabilityContext.test.tsx +0 -123
- package/tests/Form.test.tsx +0 -1287
- package/tests/ManageConsentErrorMapping.test.tsx +0 -85
- package/tests/ProductSelectionSection.test.tsx +0 -328
- package/tests/RequestSubmit.test.tsx +0 -135
- package/tests/RevocablePurpose.test.tsx +0 -146
- package/tests/RevokeWarningMessage.test.tsx +0 -151
- package/tests/consentClient.test.ts +0 -217
- package/tests/manageConsentServer.test.ts +0 -38
- package/tests/mocks.ts +0 -257
- package/tests/resolveContactFromJwt.test.ts +0 -44
- package/tests/setup.ts +0 -16
- package/tsconfig.json +0 -16
- package/tsup.config.ts +0 -31
- package/vitest.config.ts +0 -16
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
import { jwtDecode } from "jwt-decode";
|
|
2
|
-
import { parseApiError } from "../../shared/api-errors";
|
|
3
|
-
import type {
|
|
4
|
-
ConsentContent,
|
|
5
|
-
ConsentEventPayload,
|
|
6
|
-
DataElementSelection,
|
|
7
|
-
FetchConsentContentParams,
|
|
8
|
-
FetchTTSAudioUrlsParams,
|
|
9
|
-
InitiateGuardianVerificationParams,
|
|
10
|
-
InitiateGuardianVerificationResponse,
|
|
11
|
-
NoticeConsentStatusResponse,
|
|
12
|
-
PurposeSelection,
|
|
13
|
-
RedactoJwtPayload,
|
|
14
|
-
SubmitConsentEventParams,
|
|
15
|
-
TTSAudioUrlsResponse,
|
|
16
|
-
VerifyGuardianStatusParams,
|
|
17
|
-
VerifyGuardianStatusResponse,
|
|
18
|
-
} from "./types";
|
|
19
|
-
|
|
20
|
-
// The ledger `check-consent` read is shared with RedactoNoticeConsentInline.
|
|
21
|
-
// Re-exported through this barrel so `./api` importers (and the test mock)
|
|
22
|
-
// resolve it here unchanged.
|
|
23
|
-
export { fetchNoticeConsentStatus } from "../../shared/notice-consent-status";
|
|
24
|
-
|
|
25
|
-
const BASE_URL = "https://api.redacto.io/consent";
|
|
26
|
-
|
|
27
|
-
// Simple in-memory cache for API responses to reduce calls
|
|
28
|
-
const apiCache = new Map<string, { data: any; timestamp: number; ttl: number }>();
|
|
29
|
-
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
30
|
-
|
|
31
|
-
// Utility function to get cached data
|
|
32
|
-
function getCachedData(key: string): any | null {
|
|
33
|
-
const cached = apiCache.get(key);
|
|
34
|
-
if (cached && Date.now() - cached.timestamp < cached.ttl) {
|
|
35
|
-
return cached.data;
|
|
36
|
-
}
|
|
37
|
-
if (cached) {
|
|
38
|
-
apiCache.delete(key);
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Utility function to set cached data
|
|
44
|
-
function setCachedData(key: string, data: any, ttl = CACHE_TTL): void {
|
|
45
|
-
apiCache.set(key, { data, timestamp: Date.now(), ttl });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Utility function to decode JWT with error handling
|
|
49
|
-
function decodeTokenSafely(token: string): RedactoJwtPayload | null {
|
|
50
|
-
try {
|
|
51
|
-
return jwtDecode(token) as RedactoJwtPayload;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.warn("Failed to decode JWT token:", error);
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Function to clear API cache (useful for testing or when switching users)
|
|
59
|
-
export const clearApiCache = (): void => {
|
|
60
|
-
apiCache.clear();
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const fetchConsentContent = async ({
|
|
64
|
-
noticeId,
|
|
65
|
-
accessToken,
|
|
66
|
-
baseUrl,
|
|
67
|
-
language = "en",
|
|
68
|
-
specific_uuid,
|
|
69
|
-
validate_against = "all",
|
|
70
|
-
include_fully_consented_data = false,
|
|
71
|
-
signal,
|
|
72
|
-
}: FetchConsentContentParams & { signal?: AbortSignal }): Promise<ConsentContent> => {
|
|
73
|
-
if (!noticeId || !accessToken || !validate_against) {
|
|
74
|
-
throw new Error("noticeId and accessToken are required");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
78
|
-
if (!decodedToken) {
|
|
79
|
-
throw new Error("Invalid access token");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const { organisation_uuid: ORGANISATION_UUID, workspace_uuid: WORKSPACE_UUID } = decodedToken;
|
|
83
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
84
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
88
|
-
|
|
89
|
-
// Create cache key for this request - include accessToken to ensure different users get different cache
|
|
90
|
-
const cacheKey = `${accessToken}-${noticeId}-${validate_against}-${language}-${specific_uuid || ''}-${include_fully_consented_data}`;
|
|
91
|
-
|
|
92
|
-
if (validate_against === "all" && !specific_uuid) {
|
|
93
|
-
const cachedData = getCachedData(cacheKey);
|
|
94
|
-
if (cachedData) {
|
|
95
|
-
return cachedData;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const url = new URL(
|
|
100
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/notices/${noticeId}`
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (specific_uuid) {
|
|
104
|
-
url.searchParams.append("specific_uuid", specific_uuid);
|
|
105
|
-
}
|
|
106
|
-
url.searchParams.append("validate_against", validate_against);
|
|
107
|
-
if (include_fully_consented_data) {
|
|
108
|
-
url.searchParams.append("include_fully_consented_data", "true");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const response = await fetch(url.toString(), {
|
|
112
|
-
method: "GET",
|
|
113
|
-
headers: {
|
|
114
|
-
Authorization: `Bearer ${accessToken}`,
|
|
115
|
-
"Accept-Language": language,
|
|
116
|
-
},
|
|
117
|
-
signal,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if (!response.ok) {
|
|
121
|
-
throw await parseApiError(
|
|
122
|
-
response,
|
|
123
|
-
"Could not load the consent notice. Please try again."
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const data: ConsentContent = await response.json();
|
|
128
|
-
|
|
129
|
-
if (validate_against === "all" && !specific_uuid) {
|
|
130
|
-
setCachedData(cacheKey, data);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return data;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export const submitConsentEvent = async ({
|
|
137
|
-
accessToken,
|
|
138
|
-
baseUrl,
|
|
139
|
-
ledgerBaseUrl,
|
|
140
|
-
noticeUuid,
|
|
141
|
-
purposes,
|
|
142
|
-
declined,
|
|
143
|
-
language,
|
|
144
|
-
meta_data,
|
|
145
|
-
guardianVerificationReference,
|
|
146
|
-
selfDeclaredAdult,
|
|
147
|
-
signal,
|
|
148
|
-
}: SubmitConsentEventParams & { signal?: AbortSignal }): Promise<void> => {
|
|
149
|
-
if (!noticeUuid || !accessToken || !Array.isArray(purposes)) {
|
|
150
|
-
throw new Error("noticeUuid, accessToken, and purposes array are required");
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
154
|
-
if (!decodedToken) {
|
|
155
|
-
throw new Error("Invalid access token");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const { organisation_uuid: ORGANISATION_UUID, workspace_uuid: WORKSPACE_UUID } = decodedToken;
|
|
159
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
160
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Fall back to the consent server when no ledger is configured, so existing
|
|
164
|
-
// integrations that only pass baseUrl remain backwards compatible.
|
|
165
|
-
const apiBaseUrl = ledgerBaseUrl || baseUrl || BASE_URL;
|
|
166
|
-
|
|
167
|
-
const validatedPurposes = purposes.map((purpose) => {
|
|
168
|
-
if (!purpose.uuid) {
|
|
169
|
-
throw new Error(`Invalid purpose data: missing uuid`);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Only include enabled data elements (disabled elements are not selectable)
|
|
173
|
-
const dataElements = (purpose.data_elements || [])
|
|
174
|
-
.filter((element) => element.enabled)
|
|
175
|
-
.map((element) => ({
|
|
176
|
-
uuid: element.uuid,
|
|
177
|
-
selected: element.required ? true : Boolean(element.selected),
|
|
178
|
-
}));
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
purpose_uuid: purpose.uuid,
|
|
182
|
-
selected: Boolean(purpose.selected),
|
|
183
|
-
data_elements: dataElements.length > 0 ? dataElements : undefined,
|
|
184
|
-
};
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
const payload: ConsentEventPayload = {
|
|
188
|
-
notice_uuid: noticeUuid,
|
|
189
|
-
purposes: validatedPurposes,
|
|
190
|
-
select_all_mandatory: false,
|
|
191
|
-
source: "WEB",
|
|
192
|
-
declined: Boolean(declined),
|
|
193
|
-
language: language || undefined,
|
|
194
|
-
meta_data: meta_data ? { specific_uuid: meta_data.specific_uuid, minor_age: meta_data.minor_age } : undefined,
|
|
195
|
-
guardian_verification_reference: guardianVerificationReference,
|
|
196
|
-
self_declared_adult: selfDeclaredAdult,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const response = await fetch(
|
|
200
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/submit-consent`,
|
|
201
|
-
{
|
|
202
|
-
method: "POST",
|
|
203
|
-
headers: {
|
|
204
|
-
Authorization: `Bearer ${accessToken}`,
|
|
205
|
-
"Content-Type": "application/json",
|
|
206
|
-
},
|
|
207
|
-
body: JSON.stringify(payload),
|
|
208
|
-
signal,
|
|
209
|
-
}
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
if (!response.ok) {
|
|
213
|
-
throw await parseApiError(
|
|
214
|
-
response,
|
|
215
|
-
"Could not submit your consent. Please try again."
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Clear any cached consent content since user preferences have changed
|
|
220
|
-
apiCache.clear();
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Translate the ledger's notice consent status into the
|
|
225
|
-
* `{ purpose_selections, reconsent_required }` shape the banner already
|
|
226
|
-
* consumes, so prior-consent pre-fill and reconsent categorization work off
|
|
227
|
-
* the ledger. Returns null for a first-time principal (no consent record —
|
|
228
|
-
* every purpose INACTIVE), preserving the normal first-time consent flow.
|
|
229
|
-
*
|
|
230
|
-
* `needs_reconsent` is derived from `status` (anything not ACTIVE needs
|
|
231
|
-
* reconsent: expired / withdrawn / declined / inactive). NOTE: notice-version
|
|
232
|
-
* reconsent is NOT covered — the ledger's check-consent has no version
|
|
233
|
-
* awareness yet, so a republished-notice version bump won't re-prompt until
|
|
234
|
-
* that lands on the ledger (tracked fast-follow).
|
|
235
|
-
*/
|
|
236
|
-
export const buildLedgerConsentOverlay = (
|
|
237
|
-
status: NoticeConsentStatusResponse,
|
|
238
|
-
configPurposes: ConsentContent["detail"]["active_config"]["purposes"]
|
|
239
|
-
): {
|
|
240
|
-
reconsent_required: boolean;
|
|
241
|
-
purpose_selections: Record<string, PurposeSelection>;
|
|
242
|
-
} | null => {
|
|
243
|
-
const byUuid = new Map(status.purposes.map((p) => [p.uuid, p]));
|
|
244
|
-
const hasHistory = status.purposes.some(
|
|
245
|
-
(p) => (p.status || "INACTIVE") !== "INACTIVE"
|
|
246
|
-
);
|
|
247
|
-
if (!hasHistory) {
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const purpose_selections: Record<string, PurposeSelection> = {};
|
|
252
|
-
for (const cp of configPurposes) {
|
|
253
|
-
const lp = byUuid.get(cp.uuid);
|
|
254
|
-
const purposeStatus = lp?.status || "INACTIVE";
|
|
255
|
-
const selectedByUuid = new Map(
|
|
256
|
-
(lp?.data_elements || []).map((de) => [de.uuid, de.selected])
|
|
257
|
-
);
|
|
258
|
-
const data_elements: Record<string, DataElementSelection> = {};
|
|
259
|
-
for (const de of cp.data_elements) {
|
|
260
|
-
data_elements[de.uuid] = {
|
|
261
|
-
selected: selectedByUuid.get(de.uuid) ?? false,
|
|
262
|
-
enabled: de.enabled,
|
|
263
|
-
required: de.required,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
purpose_selections[cp.uuid] = {
|
|
267
|
-
selected: lp?.selected ?? false,
|
|
268
|
-
status: purposeStatus,
|
|
269
|
-
needs_reconsent: purposeStatus !== "ACTIVE",
|
|
270
|
-
data_elements,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const reconsent_required = configPurposes.some(
|
|
275
|
-
(cp) => (purpose_selections[cp.uuid]?.status || "INACTIVE") !== "ACTIVE"
|
|
276
|
-
);
|
|
277
|
-
return { reconsent_required, purpose_selections };
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
export const fetchTTSAudioUrls = async ({
|
|
281
|
-
accessToken,
|
|
282
|
-
baseUrl,
|
|
283
|
-
noticeUuid,
|
|
284
|
-
language,
|
|
285
|
-
signal,
|
|
286
|
-
}: FetchTTSAudioUrlsParams & { signal?: AbortSignal }): Promise<TTSAudioUrlsResponse> => {
|
|
287
|
-
if (!accessToken || !noticeUuid || !language) {
|
|
288
|
-
throw new Error("accessToken, noticeUuid, and language are required");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
292
|
-
if (!decodedToken) {
|
|
293
|
-
throw new Error("Invalid access token");
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const { organisation_uuid: ORGANISATION_UUID, workspace_uuid: WORKSPACE_UUID } = decodedToken;
|
|
297
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
298
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
302
|
-
|
|
303
|
-
const url = `${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/notices/${noticeUuid}/audio/${language}`;
|
|
304
|
-
|
|
305
|
-
const response = await fetch(url, {
|
|
306
|
-
method: "GET",
|
|
307
|
-
headers: {
|
|
308
|
-
Authorization: `Bearer ${accessToken}`,
|
|
309
|
-
Accept: "application/json",
|
|
310
|
-
},
|
|
311
|
-
signal,
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
if (!response.ok) {
|
|
315
|
-
throw await parseApiError(
|
|
316
|
-
response,
|
|
317
|
-
"Could not load audio narration. Please try again."
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const data: TTSAudioUrlsResponse = await response.json();
|
|
322
|
-
return data;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// =============================================================================
|
|
326
|
-
// Guardian Verification API Functions
|
|
327
|
-
// =============================================================================
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Initiate guardian verification via DigiLocker
|
|
331
|
-
* POST /guardian/initiate-verification
|
|
332
|
-
*
|
|
333
|
-
* This combines guardian details submission and DigiLocker initiation in one call.
|
|
334
|
-
*/
|
|
335
|
-
export const initiateGuardianVerification = async ({
|
|
336
|
-
accessToken,
|
|
337
|
-
baseUrl,
|
|
338
|
-
guardianName,
|
|
339
|
-
guardianContact,
|
|
340
|
-
guardianRelationship,
|
|
341
|
-
frontendCallbackUrl,
|
|
342
|
-
metadata,
|
|
343
|
-
signal,
|
|
344
|
-
}: InitiateGuardianVerificationParams): Promise<InitiateGuardianVerificationResponse> => {
|
|
345
|
-
try {
|
|
346
|
-
if (!accessToken) {
|
|
347
|
-
throw new Error("accessToken is required");
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (!guardianName?.trim()) {
|
|
351
|
-
throw new Error("Guardian name is required");
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (!guardianContact?.trim()) {
|
|
355
|
-
throw new Error("Guardian contact is required");
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!guardianRelationship?.trim()) {
|
|
359
|
-
throw new Error("Guardian relationship is required");
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
363
|
-
if (!decodedToken) {
|
|
364
|
-
throw new Error("Invalid access token");
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const { organisation_uuid: ORGANISATION_UUID, workspace_uuid: WORKSPACE_UUID } = decodedToken;
|
|
368
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
369
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
373
|
-
|
|
374
|
-
const payload: {
|
|
375
|
-
guardian_name: string;
|
|
376
|
-
guardian_contact: string;
|
|
377
|
-
guardian_relationship: string;
|
|
378
|
-
frontend_callback_url?: string;
|
|
379
|
-
metadata?: Record<string, unknown>;
|
|
380
|
-
} = {
|
|
381
|
-
guardian_name: guardianName.trim(),
|
|
382
|
-
guardian_contact: guardianContact.trim(),
|
|
383
|
-
guardian_relationship: guardianRelationship.trim(),
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
if (frontendCallbackUrl) {
|
|
387
|
-
payload.frontend_callback_url = frontendCallbackUrl;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
if (metadata) {
|
|
391
|
-
payload.metadata = metadata;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const response = await fetch(
|
|
395
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/guardian/initiate-verification`,
|
|
396
|
-
{
|
|
397
|
-
method: "POST",
|
|
398
|
-
headers: {
|
|
399
|
-
Authorization: `Bearer ${accessToken}`,
|
|
400
|
-
"Content-Type": "application/json",
|
|
401
|
-
},
|
|
402
|
-
body: JSON.stringify(payload),
|
|
403
|
-
signal,
|
|
404
|
-
}
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
if (!response.ok) {
|
|
408
|
-
throw await parseApiError(
|
|
409
|
-
response,
|
|
410
|
-
"Could not start guardian verification. Please try again."
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const responseData = await response.json();
|
|
415
|
-
|
|
416
|
-
// Handle response with detail wrapper (backend format: { code, status, detail: {...} })
|
|
417
|
-
const detail = responseData.detail || responseData;
|
|
418
|
-
|
|
419
|
-
// Already verified — skip DigiLocker entirely
|
|
420
|
-
if (detail.already_verified) {
|
|
421
|
-
return {
|
|
422
|
-
success: true,
|
|
423
|
-
guardian_info_uuid: detail.guardian_info_uuid,
|
|
424
|
-
already_verified: true,
|
|
425
|
-
verification_reference: detail.verification_reference,
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// New verification flow — needs DigiLocker
|
|
430
|
-
if (!detail.session_token || !detail.digilocker_redirect_url) {
|
|
431
|
-
throw new Error("Invalid response: missing session_token or digilocker_redirect_url");
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return {
|
|
435
|
-
success: detail.success ?? true,
|
|
436
|
-
guardian_info_uuid: detail.guardian_info_uuid,
|
|
437
|
-
already_verified: false,
|
|
438
|
-
session_token: detail.session_token,
|
|
439
|
-
digilocker_redirect_url: detail.digilocker_redirect_url,
|
|
440
|
-
expires_at: detail.expires_at,
|
|
441
|
-
};
|
|
442
|
-
} catch (error) {
|
|
443
|
-
console.error("Error initiating guardian verification:", error instanceof Error ? error.message : error);
|
|
444
|
-
throw error;
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Check guardian verification status
|
|
450
|
-
* POST /guardian/verify-status
|
|
451
|
-
*
|
|
452
|
-
* Poll this endpoint to check if DigiLocker verification is complete.
|
|
453
|
-
* Returns verification_reference when status is "verified".
|
|
454
|
-
*/
|
|
455
|
-
export const verifyGuardianStatus = async ({
|
|
456
|
-
accessToken,
|
|
457
|
-
baseUrl,
|
|
458
|
-
sessionToken,
|
|
459
|
-
signal,
|
|
460
|
-
}: VerifyGuardianStatusParams): Promise<VerifyGuardianStatusResponse> => {
|
|
461
|
-
if (!accessToken || !sessionToken) {
|
|
462
|
-
throw new Error("accessToken and sessionToken are required");
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
466
|
-
if (!decodedToken) {
|
|
467
|
-
throw new Error("Invalid access token");
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const { organisation_uuid: ORGANISATION_UUID, workspace_uuid: WORKSPACE_UUID } = decodedToken;
|
|
471
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
472
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
476
|
-
|
|
477
|
-
const response = await fetch(
|
|
478
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/guardian/verify-status`,
|
|
479
|
-
{
|
|
480
|
-
method: "POST",
|
|
481
|
-
headers: {
|
|
482
|
-
Authorization: `Bearer ${accessToken}`,
|
|
483
|
-
"Content-Type": "application/json",
|
|
484
|
-
},
|
|
485
|
-
body: JSON.stringify({
|
|
486
|
-
session_token: sessionToken,
|
|
487
|
-
}),
|
|
488
|
-
signal,
|
|
489
|
-
}
|
|
490
|
-
);
|
|
491
|
-
|
|
492
|
-
if (!response.ok) {
|
|
493
|
-
throw await parseApiError(
|
|
494
|
-
response,
|
|
495
|
-
"Could not check verification status. Please try again."
|
|
496
|
-
);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
const responseData = await response.json();
|
|
500
|
-
const detail = responseData.detail || responseData;
|
|
501
|
-
|
|
502
|
-
return {
|
|
503
|
-
status: detail.status ?? "in_progress",
|
|
504
|
-
guardian_info_uuid: detail.guardian_info_uuid ?? null,
|
|
505
|
-
verification_reference: detail.verification_reference ?? null,
|
|
506
|
-
guardian_details: detail.guardian_details ?? null,
|
|
507
|
-
error: detail.error ?? null,
|
|
508
|
-
error_code: detail.error_code ?? null,
|
|
509
|
-
can_retry: detail.can_retry ?? true,
|
|
510
|
-
};
|
|
511
|
-
};
|
|
512
|
-
|