@redacto.io/consent-sdk-react 10.0.0-beta.11 → 10.0.0-beta.12

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