@redacto.io/consent-sdk-react 10.0.0-beta.9 → 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/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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +724 -365
- package/dist/index.mjs +346 -201
- package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
- package/dist/privacy-center.d.mts +0 -1
- package/dist/privacy-center.d.ts +0 -1
- package/dist/privacy-center.js +2 -66
- package/dist/privacy-center.mjs +2 -66
- 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 -353
- 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 -4308
- package/src/RedactoNoticeConsent/api/index.ts +0 -542
- package/src/RedactoNoticeConsent/api/sandbox.ts +0 -150
- package/src/RedactoNoticeConsent/api/types.ts +0 -515
- 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 -80
- 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 -93
- package/src/RedactoPrivacyCenter/api/actions.ts +0 -695
- package/src/RedactoPrivacyCenter/api/client.ts +0 -1003
- package/src/RedactoPrivacyCenter/api/config.ts +0 -33
- package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -275
- 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 -1821
- 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 -195
- 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 -155
- 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 -252
- 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 -57
- 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 -283
- 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/sandbox.ts +0 -104
- package/src/RedactoPrivacyCenter/lib/types.ts +0 -896
- 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 -798
- 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/shared/sandbox.ts +0 -6
- 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 -1424
- 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,542 +0,0 @@
|
|
|
1
|
-
import { jwtDecode } from "jwt-decode";
|
|
2
|
-
import { parseApiError } from "../../shared/api-errors";
|
|
3
|
-
import {
|
|
4
|
-
buildAuthHeaders,
|
|
5
|
-
resolveRequestAuth,
|
|
6
|
-
sandboxBodyIdentity,
|
|
7
|
-
sandboxQueryIdentity,
|
|
8
|
-
} from "./sandbox";
|
|
9
|
-
import type {
|
|
10
|
-
ConsentContent,
|
|
11
|
-
ConsentEventPayload,
|
|
12
|
-
DataElementSelection,
|
|
13
|
-
FetchConsentContentParams,
|
|
14
|
-
FetchTTSAudioUrlsParams,
|
|
15
|
-
InitiateGuardianVerificationParams,
|
|
16
|
-
InitiateGuardianVerificationResponse,
|
|
17
|
-
NoticeConsentStatusResponse,
|
|
18
|
-
PurposeSelection,
|
|
19
|
-
RedactoJwtPayload,
|
|
20
|
-
SubmitConsentEventParams,
|
|
21
|
-
TTSAudioUrlsResponse,
|
|
22
|
-
VerifyGuardianStatusParams,
|
|
23
|
-
VerifyGuardianStatusResponse,
|
|
24
|
-
} from "./types";
|
|
25
|
-
|
|
26
|
-
// The ledger `check-consent` read is shared with RedactoNoticeConsentInline.
|
|
27
|
-
// Re-exported through this barrel so `./api` importers (and the test mock)
|
|
28
|
-
// resolve it here unchanged.
|
|
29
|
-
export { fetchNoticeConsentStatus } from "../../shared/notice-consent-status";
|
|
30
|
-
|
|
31
|
-
const BASE_URL = "https://api.redacto.io/consent";
|
|
32
|
-
|
|
33
|
-
// Simple in-memory cache for API responses to reduce calls
|
|
34
|
-
const apiCache = new Map<string, { data: any; timestamp: number; ttl: number }>();
|
|
35
|
-
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
|
36
|
-
|
|
37
|
-
// Utility function to get cached data
|
|
38
|
-
function getCachedData(key: string): any | null {
|
|
39
|
-
const cached = apiCache.get(key);
|
|
40
|
-
if (cached && Date.now() - cached.timestamp < cached.ttl) {
|
|
41
|
-
return cached.data;
|
|
42
|
-
}
|
|
43
|
-
if (cached) {
|
|
44
|
-
apiCache.delete(key);
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Utility function to set cached data
|
|
50
|
-
function setCachedData(key: string, data: any, ttl = CACHE_TTL): void {
|
|
51
|
-
apiCache.set(key, { data, timestamp: Date.now(), ttl });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Utility function to decode JWT with error handling
|
|
55
|
-
function decodeTokenSafely(token: string): RedactoJwtPayload | null {
|
|
56
|
-
try {
|
|
57
|
-
return jwtDecode(token) as RedactoJwtPayload;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.warn("Failed to decode JWT token:", error);
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Function to clear API cache (useful for testing or when switching users)
|
|
65
|
-
export const clearApiCache = (): void => {
|
|
66
|
-
apiCache.clear();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const fetchConsentContent = async ({
|
|
70
|
-
noticeId,
|
|
71
|
-
accessToken,
|
|
72
|
-
baseUrl,
|
|
73
|
-
language = "en",
|
|
74
|
-
specific_uuid,
|
|
75
|
-
validate_against = "all",
|
|
76
|
-
include_fully_consented_data = false,
|
|
77
|
-
signal,
|
|
78
|
-
...sandboxParams
|
|
79
|
-
}: FetchConsentContentParams & { signal?: AbortSignal }): Promise<ConsentContent> => {
|
|
80
|
-
if (!noticeId || !validate_against) {
|
|
81
|
-
throw new Error("noticeId is required");
|
|
82
|
-
}
|
|
83
|
-
if (!accessToken && !sandboxParams.token) {
|
|
84
|
-
throw new Error("accessToken or token is required");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const { organisationUuid: ORGANISATION_UUID, workspaceUuid: WORKSPACE_UUID, sandbox } =
|
|
88
|
-
resolveRequestAuth(accessToken, sandboxParams, decodeTokenSafely);
|
|
89
|
-
|
|
90
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
91
|
-
|
|
92
|
-
// Create cache key for this request - include the auth identity (token or
|
|
93
|
-
// sandbox org/workspace/subject) so different users get different cache
|
|
94
|
-
// entries. Org + workspace are part of the sandbox identity so two sessions
|
|
95
|
-
// sharing a subject but scoped to different orgs never collide.
|
|
96
|
-
const cacheIdentity = sandbox
|
|
97
|
-
? `sandbox:${sandbox.organisationUuid}:${sandbox.workspaceUuid}:${sandbox.ucic || sandbox.subject}`
|
|
98
|
-
: accessToken;
|
|
99
|
-
const cacheKey = `${cacheIdentity}-${noticeId}-${validate_against}-${language}-${specific_uuid || ''}-${include_fully_consented_data}`;
|
|
100
|
-
|
|
101
|
-
if (validate_against === "all" && !specific_uuid) {
|
|
102
|
-
const cachedData = getCachedData(cacheKey);
|
|
103
|
-
if (cachedData) {
|
|
104
|
-
return cachedData;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const url = new URL(
|
|
109
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/notices/${noticeId}`
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
if (specific_uuid) {
|
|
113
|
-
url.searchParams.append("specific_uuid", specific_uuid);
|
|
114
|
-
}
|
|
115
|
-
url.searchParams.append("validate_against", validate_against);
|
|
116
|
-
if (include_fully_consented_data) {
|
|
117
|
-
url.searchParams.append("include_fully_consented_data", "true");
|
|
118
|
-
}
|
|
119
|
-
// Sandbox mode: the acting identity travels as query params
|
|
120
|
-
// (primary_email / primary_mobile); the credential is the X-Consent-Token header.
|
|
121
|
-
if (sandbox) {
|
|
122
|
-
for (const [key, value] of Object.entries(sandboxQueryIdentity(sandbox))) {
|
|
123
|
-
url.searchParams.append(key, value);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const response = await fetch(url.toString(), {
|
|
128
|
-
method: "GET",
|
|
129
|
-
headers: {
|
|
130
|
-
...buildAuthHeaders(accessToken, sandbox),
|
|
131
|
-
"Accept-Language": language,
|
|
132
|
-
},
|
|
133
|
-
signal,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
if (!response.ok) {
|
|
137
|
-
throw await parseApiError(
|
|
138
|
-
response,
|
|
139
|
-
"Could not load the consent notice. Please try again."
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const data: ConsentContent = await response.json();
|
|
144
|
-
|
|
145
|
-
if (validate_against === "all" && !specific_uuid) {
|
|
146
|
-
setCachedData(cacheKey, data);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return data;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export const submitConsentEvent = async ({
|
|
153
|
-
accessToken,
|
|
154
|
-
baseUrl,
|
|
155
|
-
ledgerBaseUrl,
|
|
156
|
-
noticeUuid,
|
|
157
|
-
purposes,
|
|
158
|
-
declined,
|
|
159
|
-
language,
|
|
160
|
-
meta_data,
|
|
161
|
-
guardianVerificationReference,
|
|
162
|
-
selfDeclaredAdult,
|
|
163
|
-
signal,
|
|
164
|
-
...sandboxParams
|
|
165
|
-
}: SubmitConsentEventParams & { signal?: AbortSignal }): Promise<void> => {
|
|
166
|
-
if (!noticeUuid || !Array.isArray(purposes)) {
|
|
167
|
-
throw new Error("noticeUuid and purposes array are required");
|
|
168
|
-
}
|
|
169
|
-
if (!accessToken && !sandboxParams.token) {
|
|
170
|
-
throw new Error("accessToken or token is required");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const { organisationUuid: ORGANISATION_UUID, workspaceUuid: WORKSPACE_UUID, sandbox } =
|
|
174
|
-
resolveRequestAuth(accessToken, sandboxParams, decodeTokenSafely);
|
|
175
|
-
|
|
176
|
-
// Fall back to the consent server when no ledger is configured, so existing
|
|
177
|
-
// integrations that only pass baseUrl remain backwards compatible. Sandbox
|
|
178
|
-
// never routes to the Go ledger (no X-Consent-Token support), so a sandbox
|
|
179
|
-
// session forces the consent-server path even if a ledgerBaseUrl is set.
|
|
180
|
-
const apiBaseUrl = (sandbox ? null : ledgerBaseUrl) || baseUrl || BASE_URL;
|
|
181
|
-
|
|
182
|
-
const validatedPurposes = purposes.map((purpose) => {
|
|
183
|
-
if (!purpose.uuid) {
|
|
184
|
-
throw new Error(`Invalid purpose data: missing uuid`);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Only include enabled data elements (disabled elements are not selectable)
|
|
188
|
-
const dataElements = (purpose.data_elements || [])
|
|
189
|
-
.filter((element) => element.enabled)
|
|
190
|
-
.map((element) => ({
|
|
191
|
-
uuid: element.uuid,
|
|
192
|
-
selected: element.required ? true : Boolean(element.selected),
|
|
193
|
-
}));
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
purpose_uuid: purpose.uuid,
|
|
197
|
-
selected: Boolean(purpose.selected),
|
|
198
|
-
data_elements: dataElements.length > 0 ? dataElements : undefined,
|
|
199
|
-
};
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
const payload: ConsentEventPayload = {
|
|
203
|
-
notice_uuid: noticeUuid,
|
|
204
|
-
purposes: validatedPurposes,
|
|
205
|
-
select_all_mandatory: false,
|
|
206
|
-
source: "WEB",
|
|
207
|
-
declined: Boolean(declined),
|
|
208
|
-
language: language || undefined,
|
|
209
|
-
meta_data: meta_data ? { specific_uuid: meta_data.specific_uuid, minor_age: meta_data.minor_age } : undefined,
|
|
210
|
-
guardian_verification_reference: guardianVerificationReference,
|
|
211
|
-
self_declared_adult: selfDeclaredAdult,
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// Sandbox mode: merge the acting test identity into the body (the server has
|
|
215
|
-
// no subject header; it namespaces this identity `test::`).
|
|
216
|
-
const requestBody = sandbox ? { ...payload, ...sandboxBodyIdentity(sandbox) } : payload;
|
|
217
|
-
|
|
218
|
-
const response = await fetch(
|
|
219
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/submit-consent`,
|
|
220
|
-
{
|
|
221
|
-
method: "POST",
|
|
222
|
-
headers: {
|
|
223
|
-
...buildAuthHeaders(accessToken, sandbox),
|
|
224
|
-
"Content-Type": "application/json",
|
|
225
|
-
},
|
|
226
|
-
body: JSON.stringify(requestBody),
|
|
227
|
-
signal,
|
|
228
|
-
}
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
if (!response.ok) {
|
|
232
|
-
throw await parseApiError(
|
|
233
|
-
response,
|
|
234
|
-
"Could not submit your consent. Please try again."
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Clear any cached consent content since user preferences have changed
|
|
239
|
-
apiCache.clear();
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Translate the ledger's notice consent status into the
|
|
244
|
-
* `{ purpose_selections, reconsent_required }` shape the banner already
|
|
245
|
-
* consumes, so prior-consent pre-fill and reconsent categorization work off
|
|
246
|
-
* the ledger. Returns null for a first-time principal (no consent record —
|
|
247
|
-
* every purpose INACTIVE), preserving the normal first-time consent flow.
|
|
248
|
-
*
|
|
249
|
-
* `needs_reconsent` is derived from `status` (anything not ACTIVE needs
|
|
250
|
-
* reconsent: expired / withdrawn / declined / inactive). NOTE: notice-version
|
|
251
|
-
* reconsent is NOT covered — the ledger's check-consent has no version
|
|
252
|
-
* awareness yet, so a republished-notice version bump won't re-prompt until
|
|
253
|
-
* that lands on the ledger (tracked fast-follow).
|
|
254
|
-
*/
|
|
255
|
-
export const buildLedgerConsentOverlay = (
|
|
256
|
-
status: NoticeConsentStatusResponse,
|
|
257
|
-
configPurposes: ConsentContent["detail"]["active_config"]["purposes"]
|
|
258
|
-
): {
|
|
259
|
-
reconsent_required: boolean;
|
|
260
|
-
purpose_selections: Record<string, PurposeSelection>;
|
|
261
|
-
} | null => {
|
|
262
|
-
const byUuid = new Map(status.purposes.map((p) => [p.uuid, p]));
|
|
263
|
-
const hasHistory = status.purposes.some(
|
|
264
|
-
(p) => (p.status || "INACTIVE") !== "INACTIVE"
|
|
265
|
-
);
|
|
266
|
-
if (!hasHistory) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const purpose_selections: Record<string, PurposeSelection> = {};
|
|
271
|
-
for (const cp of configPurposes) {
|
|
272
|
-
const lp = byUuid.get(cp.uuid);
|
|
273
|
-
const purposeStatus = lp?.status || "INACTIVE";
|
|
274
|
-
const selectedByUuid = new Map(
|
|
275
|
-
(lp?.data_elements || []).map((de) => [de.uuid, de.selected])
|
|
276
|
-
);
|
|
277
|
-
const data_elements: Record<string, DataElementSelection> = {};
|
|
278
|
-
for (const de of cp.data_elements) {
|
|
279
|
-
data_elements[de.uuid] = {
|
|
280
|
-
selected: selectedByUuid.get(de.uuid) ?? false,
|
|
281
|
-
enabled: de.enabled,
|
|
282
|
-
required: de.required,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
purpose_selections[cp.uuid] = {
|
|
286
|
-
selected: lp?.selected ?? false,
|
|
287
|
-
status: purposeStatus,
|
|
288
|
-
needs_reconsent: purposeStatus !== "ACTIVE",
|
|
289
|
-
data_elements,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const reconsent_required = configPurposes.some(
|
|
294
|
-
(cp) => (purpose_selections[cp.uuid]?.status || "INACTIVE") !== "ACTIVE"
|
|
295
|
-
);
|
|
296
|
-
return { reconsent_required, purpose_selections };
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export const fetchTTSAudioUrls = async ({
|
|
300
|
-
accessToken,
|
|
301
|
-
baseUrl,
|
|
302
|
-
noticeUuid,
|
|
303
|
-
language,
|
|
304
|
-
signal,
|
|
305
|
-
...sandboxParams
|
|
306
|
-
}: FetchTTSAudioUrlsParams & { signal?: AbortSignal }): Promise<TTSAudioUrlsResponse> => {
|
|
307
|
-
if ((!accessToken && !sandboxParams.token) || !noticeUuid || !language) {
|
|
308
|
-
throw new Error("accessToken (or token), noticeUuid, and language are required");
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const { organisationUuid: ORGANISATION_UUID, workspaceUuid: WORKSPACE_UUID, sandbox } =
|
|
312
|
-
resolveRequestAuth(accessToken, sandboxParams, decodeTokenSafely);
|
|
313
|
-
|
|
314
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
315
|
-
|
|
316
|
-
const url = new URL(
|
|
317
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/notices/${noticeUuid}/audio/${language}`
|
|
318
|
-
);
|
|
319
|
-
// Sandbox mode: the acting identity travels as query params
|
|
320
|
-
// (primary_email / primary_mobile); the credential is the X-Consent-Token header.
|
|
321
|
-
if (sandbox) {
|
|
322
|
-
for (const [key, value] of Object.entries(sandboxQueryIdentity(sandbox))) {
|
|
323
|
-
url.searchParams.append(key, value);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const response = await fetch(url.toString(), {
|
|
328
|
-
method: "GET",
|
|
329
|
-
headers: {
|
|
330
|
-
...buildAuthHeaders(accessToken, sandbox),
|
|
331
|
-
Accept: "application/json",
|
|
332
|
-
},
|
|
333
|
-
signal,
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
if (!response.ok) {
|
|
337
|
-
throw await parseApiError(
|
|
338
|
-
response,
|
|
339
|
-
"Could not load audio narration. Please try again."
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const data: TTSAudioUrlsResponse = await response.json();
|
|
344
|
-
return data;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
// =============================================================================
|
|
348
|
-
// Guardian Verification API Functions
|
|
349
|
-
// =============================================================================
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Initiate guardian verification via DigiLocker
|
|
353
|
-
* POST /guardian/initiate-verification
|
|
354
|
-
*
|
|
355
|
-
* This combines guardian details submission and DigiLocker initiation in one call.
|
|
356
|
-
*/
|
|
357
|
-
export const initiateGuardianVerification = async ({
|
|
358
|
-
accessToken,
|
|
359
|
-
baseUrl,
|
|
360
|
-
guardianName,
|
|
361
|
-
guardianContact,
|
|
362
|
-
guardianRelationship,
|
|
363
|
-
frontendCallbackUrl,
|
|
364
|
-
metadata,
|
|
365
|
-
signal,
|
|
366
|
-
}: InitiateGuardianVerificationParams): Promise<InitiateGuardianVerificationResponse> => {
|
|
367
|
-
try {
|
|
368
|
-
// Guardian verification is JWT-only: sandbox sessions have no minor-notice /
|
|
369
|
-
// guardian support (the server 403s them, and C1 blocks minor notices at
|
|
370
|
-
// render), so no sandbox identity is wired through here.
|
|
371
|
-
if (!accessToken) {
|
|
372
|
-
throw new Error("accessToken is required");
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (!guardianName?.trim()) {
|
|
376
|
-
throw new Error("Guardian name is required");
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (!guardianContact?.trim()) {
|
|
380
|
-
throw new Error("Guardian contact is required");
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!guardianRelationship?.trim()) {
|
|
384
|
-
throw new Error("Guardian relationship is required");
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
388
|
-
if (!decodedToken) {
|
|
389
|
-
throw new Error("Invalid access token");
|
|
390
|
-
}
|
|
391
|
-
const {
|
|
392
|
-
organisation_uuid: ORGANISATION_UUID,
|
|
393
|
-
workspace_uuid: WORKSPACE_UUID,
|
|
394
|
-
} = decodedToken;
|
|
395
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
396
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
400
|
-
|
|
401
|
-
const payload: {
|
|
402
|
-
guardian_name: string;
|
|
403
|
-
guardian_contact: string;
|
|
404
|
-
guardian_relationship: string;
|
|
405
|
-
frontend_callback_url?: string;
|
|
406
|
-
metadata?: Record<string, unknown>;
|
|
407
|
-
} = {
|
|
408
|
-
guardian_name: guardianName.trim(),
|
|
409
|
-
guardian_contact: guardianContact.trim(),
|
|
410
|
-
guardian_relationship: guardianRelationship.trim(),
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
if (frontendCallbackUrl) {
|
|
414
|
-
payload.frontend_callback_url = frontendCallbackUrl;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (metadata) {
|
|
418
|
-
payload.metadata = metadata;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const response = await fetch(
|
|
422
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/guardian/initiate-verification`,
|
|
423
|
-
{
|
|
424
|
-
method: "POST",
|
|
425
|
-
headers: {
|
|
426
|
-
Authorization: `Bearer ${accessToken}`,
|
|
427
|
-
"Content-Type": "application/json",
|
|
428
|
-
},
|
|
429
|
-
body: JSON.stringify(payload),
|
|
430
|
-
signal,
|
|
431
|
-
}
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
if (!response.ok) {
|
|
435
|
-
throw await parseApiError(
|
|
436
|
-
response,
|
|
437
|
-
"Could not start guardian verification. Please try again."
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const responseData = await response.json();
|
|
442
|
-
|
|
443
|
-
// Handle response with detail wrapper (backend format: { code, status, detail: {...} })
|
|
444
|
-
const detail = responseData.detail || responseData;
|
|
445
|
-
|
|
446
|
-
// Already verified — skip DigiLocker entirely
|
|
447
|
-
if (detail.already_verified) {
|
|
448
|
-
return {
|
|
449
|
-
success: true,
|
|
450
|
-
guardian_info_uuid: detail.guardian_info_uuid,
|
|
451
|
-
already_verified: true,
|
|
452
|
-
verification_reference: detail.verification_reference,
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// New verification flow — needs DigiLocker
|
|
457
|
-
if (!detail.session_token || !detail.digilocker_redirect_url) {
|
|
458
|
-
throw new Error("Invalid response: missing session_token or digilocker_redirect_url");
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return {
|
|
462
|
-
success: detail.success ?? true,
|
|
463
|
-
guardian_info_uuid: detail.guardian_info_uuid,
|
|
464
|
-
already_verified: false,
|
|
465
|
-
session_token: detail.session_token,
|
|
466
|
-
digilocker_redirect_url: detail.digilocker_redirect_url,
|
|
467
|
-
expires_at: detail.expires_at,
|
|
468
|
-
};
|
|
469
|
-
} catch (error) {
|
|
470
|
-
console.error("Error initiating guardian verification:", error instanceof Error ? error.message : error);
|
|
471
|
-
throw error;
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Check guardian verification status
|
|
477
|
-
* POST /guardian/verify-status
|
|
478
|
-
*
|
|
479
|
-
* Poll this endpoint to check if DigiLocker verification is complete.
|
|
480
|
-
* Returns verification_reference when status is "verified".
|
|
481
|
-
*/
|
|
482
|
-
export const verifyGuardianStatus = async ({
|
|
483
|
-
accessToken,
|
|
484
|
-
baseUrl,
|
|
485
|
-
sessionToken,
|
|
486
|
-
signal,
|
|
487
|
-
}: VerifyGuardianStatusParams): Promise<VerifyGuardianStatusResponse> => {
|
|
488
|
-
// Guardian verification is JWT-only: sandbox sessions have no minor-notice /
|
|
489
|
-
// guardian support (the server 403s them, and C1 blocks minor notices at
|
|
490
|
-
// render), so no sandbox identity is wired through here.
|
|
491
|
-
if (!accessToken || !sessionToken) {
|
|
492
|
-
throw new Error("accessToken and sessionToken are required");
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
const decodedToken = decodeTokenSafely(accessToken);
|
|
496
|
-
if (!decodedToken) {
|
|
497
|
-
throw new Error("Invalid access token");
|
|
498
|
-
}
|
|
499
|
-
const {
|
|
500
|
-
organisation_uuid: ORGANISATION_UUID,
|
|
501
|
-
workspace_uuid: WORKSPACE_UUID,
|
|
502
|
-
} = decodedToken;
|
|
503
|
-
if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
|
|
504
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const apiBaseUrl = baseUrl || BASE_URL;
|
|
508
|
-
|
|
509
|
-
const response = await fetch(
|
|
510
|
-
`${apiBaseUrl}/public/organisations/${ORGANISATION_UUID}/workspaces/${WORKSPACE_UUID}/guardian/verify-status`,
|
|
511
|
-
{
|
|
512
|
-
method: "POST",
|
|
513
|
-
headers: {
|
|
514
|
-
Authorization: `Bearer ${accessToken}`,
|
|
515
|
-
"Content-Type": "application/json",
|
|
516
|
-
},
|
|
517
|
-
body: JSON.stringify({ session_token: sessionToken }),
|
|
518
|
-
signal,
|
|
519
|
-
}
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
if (!response.ok) {
|
|
523
|
-
throw await parseApiError(
|
|
524
|
-
response,
|
|
525
|
-
"Could not check verification status. Please try again."
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
const responseData = await response.json();
|
|
530
|
-
const detail = responseData.detail || responseData;
|
|
531
|
-
|
|
532
|
-
return {
|
|
533
|
-
status: detail.status ?? "in_progress",
|
|
534
|
-
guardian_info_uuid: detail.guardian_info_uuid ?? null,
|
|
535
|
-
verification_reference: detail.verification_reference ?? null,
|
|
536
|
-
guardian_details: detail.guardian_details ?? null,
|
|
537
|
-
error: detail.error ?? null,
|
|
538
|
-
error_code: detail.error_code ?? null,
|
|
539
|
-
can_retry: detail.can_retry ?? true,
|
|
540
|
-
};
|
|
541
|
-
};
|
|
542
|
-
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sandbox-mode auth primitives for the consent PoC.
|
|
3
|
-
*
|
|
4
|
-
* In sandbox mode the SDK talks to the consent-server with a pasted static
|
|
5
|
-
* token and an explicit test subject, bypassing the JWT entirely. Org/workspace
|
|
6
|
-
* UUIDs come from props (they still build the `/public/organisations/{org}/
|
|
7
|
-
* workspaces/{ws}/...` URL paths) instead of being decoded from a token.
|
|
8
|
-
*
|
|
9
|
-
* Auth is the single `X-Consent-Token` header carrying the static token; its
|
|
10
|
-
* presence alone marks the request as `environment=test`. There is no subject
|
|
11
|
-
* header. The acting identity (the test subject) rides the request's own
|
|
12
|
-
* payload: query params (`primary_email` / `primary_mobile`) on GET/query reads,
|
|
13
|
-
* and the body on POSTs. The server normalizes and namespaces it `test::`
|
|
14
|
-
* server-side. Call sites resolve the credential via {@link buildAuthHeaders}
|
|
15
|
-
* and the identity via {@link sandboxQueryIdentity} / {@link sandboxBodyIdentity}.
|
|
16
|
-
*
|
|
17
|
-
* This file exists so every API call site resolves its org/workspace UUIDs and
|
|
18
|
-
* builds its auth header through one place, keeping sandbox vs. JWT branching
|
|
19
|
-
* from drifting across the ~6 fetch sites.
|
|
20
|
-
*/
|
|
21
|
-
import { SANDBOX_TOKEN_HEADER } from "../../shared/sandbox";
|
|
22
|
-
import type {
|
|
23
|
-
RedactoJwtPayload,
|
|
24
|
-
ResolvedRequestAuth,
|
|
25
|
-
SandboxAuth,
|
|
26
|
-
SandboxAuthParams,
|
|
27
|
-
SandboxIdentityPayload,
|
|
28
|
-
} from "./types";
|
|
29
|
-
|
|
30
|
-
export { SANDBOX_TOKEN_HEADER };
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolve a {@link SandboxAuth} from the raw sandbox props, or return null when
|
|
34
|
-
* sandbox mode is not active (no token).
|
|
35
|
-
*
|
|
36
|
-
* @throws Error when a sandbox token is provided but org/workspace or the acting
|
|
37
|
-
* identity are incomplete — sandbox mode cannot build URLs or identify the
|
|
38
|
-
* acting principal without them, so failing loudly beats a silent malformed
|
|
39
|
-
* request.
|
|
40
|
-
*/
|
|
41
|
-
export const resolveSandboxAuth = (
|
|
42
|
-
params: SandboxAuthParams
|
|
43
|
-
): SandboxAuth | null => {
|
|
44
|
-
const token = params.token?.trim();
|
|
45
|
-
if (!token) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const organisationUuid = params.organisationUuid?.trim();
|
|
50
|
-
const workspaceUuid = params.workspaceUuid?.trim();
|
|
51
|
-
const ucic = params.sandboxUcic?.trim();
|
|
52
|
-
const subject = params.sandboxSubject?.trim();
|
|
53
|
-
|
|
54
|
-
if (!organisationUuid || !workspaceUuid) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
"Sandbox mode requires organisationUuid and workspaceUuid props"
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (!ucic && !subject) {
|
|
60
|
-
throw new Error("Sandbox mode requires a UCIC, email, or mobile");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return { token, ucic, subject: subject ?? "", organisationUuid, workspaceUuid };
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Resolve the org/workspace UUIDs and sandbox auth for a request. In sandbox
|
|
68
|
-
* mode these come straight from props; otherwise they are decoded from the JWT
|
|
69
|
-
* (preserving the pre-sandbox behavior and error messages exactly). The JWT
|
|
70
|
-
* decoder is injected so this module stays free of a direct jwt-decode import.
|
|
71
|
-
*
|
|
72
|
-
* @throws Error when neither a valid sandbox config nor a decodable token with
|
|
73
|
-
* org/workspace UUIDs is available.
|
|
74
|
-
*/
|
|
75
|
-
export const resolveRequestAuth = (
|
|
76
|
-
accessToken: string | undefined,
|
|
77
|
-
sandboxParams: SandboxAuthParams,
|
|
78
|
-
decodeTokenSafely: (token: string) => RedactoJwtPayload | null
|
|
79
|
-
): ResolvedRequestAuth => {
|
|
80
|
-
const sandbox = resolveSandboxAuth(sandboxParams);
|
|
81
|
-
if (sandbox) {
|
|
82
|
-
return {
|
|
83
|
-
organisationUuid: sandbox.organisationUuid,
|
|
84
|
-
workspaceUuid: sandbox.workspaceUuid,
|
|
85
|
-
sandbox,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const decodedToken = accessToken ? decodeTokenSafely(accessToken) : null;
|
|
90
|
-
if (!decodedToken) {
|
|
91
|
-
throw new Error("Invalid access token");
|
|
92
|
-
}
|
|
93
|
-
const { organisation_uuid, workspace_uuid } = decodedToken;
|
|
94
|
-
if (!organisation_uuid || !workspace_uuid) {
|
|
95
|
-
throw new Error("Invalid token: missing organization or workspace UUID");
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
organisationUuid: organisation_uuid,
|
|
99
|
-
workspaceUuid: workspace_uuid,
|
|
100
|
-
sandbox: null,
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Build the request headers for an authenticated call. In sandbox mode this is
|
|
106
|
-
* the single `X-Consent-Token` credential (its presence marks the request as
|
|
107
|
-
* `environment=test`); otherwise the standard `Authorization: Bearer`. There is
|
|
108
|
-
* no subject header — the acting identity travels in the request's own payload
|
|
109
|
-
* (see {@link sandboxQueryIdentity} for reads, {@link sandboxBodyIdentity} for
|
|
110
|
-
* POSTs).
|
|
111
|
-
*/
|
|
112
|
-
export const buildAuthHeaders = (
|
|
113
|
-
accessToken: string | undefined,
|
|
114
|
-
sandbox: SandboxAuth | null
|
|
115
|
-
): Record<string, string> => {
|
|
116
|
-
if (sandbox) {
|
|
117
|
-
return { [SANDBOX_TOKEN_HEADER]: sandbox.token };
|
|
118
|
-
}
|
|
119
|
-
return { Authorization: `Bearer ${accessToken}` };
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* The identity payload fragment for the sandbox acting principal:
|
|
124
|
-
* `{ org_user_id }` when a UCIC is set (it takes precedence), else
|
|
125
|
-
* `{ primary_email }` when the subject looks like an email (contains "@"),
|
|
126
|
-
* otherwise `{ primary_mobile }`. Merge this into a JSON request body (POST) or
|
|
127
|
-
* into query params (GET) so the server can resolve the acting test identity.
|
|
128
|
-
*/
|
|
129
|
-
export const sandboxBodyIdentity = (
|
|
130
|
-
sandbox: SandboxAuth
|
|
131
|
-
): SandboxIdentityPayload => {
|
|
132
|
-
if (sandbox.ucic) {
|
|
133
|
-
return { org_user_id: sandbox.ucic };
|
|
134
|
-
}
|
|
135
|
-
return sandbox.subject.includes("@")
|
|
136
|
-
? { primary_email: sandbox.subject }
|
|
137
|
-
: { primary_mobile: sandbox.subject };
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The identity query fragment for GET/query reads: `{ org_user_id }` when a UCIC
|
|
142
|
-
* is set (it takes precedence), else `{ primary_email }` when the subject looks
|
|
143
|
-
* like an email (contains "@"), otherwise `{ primary_mobile }`. Append these to
|
|
144
|
-
* the request's query string so the server can resolve the acting test identity
|
|
145
|
-
* (the server reads `org_user_id` / `primary_email` / `primary_mobile` query
|
|
146
|
-
* params on sandbox reads).
|
|
147
|
-
*/
|
|
148
|
-
export const sandboxQueryIdentity = (
|
|
149
|
-
sandbox: SandboxAuth
|
|
150
|
-
): SandboxIdentityPayload => sandboxBodyIdentity(sandbox);
|