@redacto.io/consent-sdk-react 10.0.0-beta.1 → 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 (258) hide show
  1. package/NOTICE.md +17 -0
  2. package/README.md +145 -3
  3. package/dist/chunk-FEGTW73Q.mjs +182 -0
  4. package/dist/{chunk-6A665OPR.mjs → chunk-OGL6OC3A.mjs} +4 -0
  5. package/dist/fonts.d.mts +35 -0
  6. package/dist/fonts.d.ts +35 -0
  7. package/dist/fonts.js +183 -0
  8. package/dist/fonts.mjs +10 -0
  9. package/dist/index.d.mts +44 -5
  10. package/dist/index.d.ts +44 -5
  11. package/dist/index.js +950 -476
  12. package/dist/index.mjs +572 -314
  13. package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
  14. package/dist/privacy-center.d.mts +55 -12
  15. package/dist/privacy-center.d.ts +55 -12
  16. package/dist/privacy-center.js +848 -950
  17. package/dist/privacy-center.mjs +698 -802
  18. package/dist/types-6Aj7faxL.d.mts +57 -0
  19. package/dist/types-6Aj7faxL.d.ts +57 -0
  20. package/package.json +10 -1
  21. package/.turbo/turbo-build.log +0 -22
  22. package/.turbo/turbo-test.log +0 -203
  23. package/.turbo/turbo-verify-pack.log +0 -6
  24. package/CHANGELOG.md +0 -274
  25. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -847
  26. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2133
  27. package/src/RedactoNoticeAssisted/api/index.ts +0 -269
  28. package/src/RedactoNoticeAssisted/api/types.ts +0 -180
  29. package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
  30. package/src/RedactoNoticeAssisted/constants.ts +0 -51
  31. package/src/RedactoNoticeAssisted/i18n.ts +0 -1463
  32. package/src/RedactoNoticeAssisted/index.ts +0 -1
  33. package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
  34. package/src/RedactoNoticeAssisted/styles.ts +0 -730
  35. package/src/RedactoNoticeAssisted/types.ts +0 -24
  36. package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
  37. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1152
  38. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4258
  39. package/src/RedactoNoticeConsent/api/index.ts +0 -573
  40. package/src/RedactoNoticeConsent/api/types.ts +0 -490
  41. package/src/RedactoNoticeConsent/assets/redacto-logo.png +0 -0
  42. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +0 -602
  43. package/src/RedactoNoticeConsent/components/index.ts +0 -7
  44. package/src/RedactoNoticeConsent/constants.ts +0 -20
  45. package/src/RedactoNoticeConsent/index.ts +0 -1
  46. package/src/RedactoNoticeConsent/injectStyles.ts +0 -151
  47. package/src/RedactoNoticeConsent/language-codes.ts +0 -97
  48. package/src/RedactoNoticeConsent/services/storage.ts +0 -122
  49. package/src/RedactoNoticeConsent/styles.ts +0 -409
  50. package/src/RedactoNoticeConsent/types.ts +0 -54
  51. package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
  52. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
  53. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -629
  54. package/src/RedactoNoticeConsentInline/api/index.ts +0 -106
  55. package/src/RedactoNoticeConsentInline/api/types.ts +0 -183
  56. package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
  57. package/src/RedactoNoticeConsentInline/index.ts +0 -1
  58. package/src/RedactoNoticeConsentInline/injectStyles.ts +0 -40
  59. package/src/RedactoNoticeConsentInline/styles.ts +0 -397
  60. package/src/RedactoNoticeConsentInline/types.ts +0 -51
  61. package/src/RedactoNoticeConsentInline/useMediaQuery.ts +0 -36
  62. package/src/RedactoPrivacyCenter/NotificationsPage.tsx +0 -182
  63. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +0 -19
  64. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +0 -156
  65. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +0 -17
  66. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +0 -79
  67. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +0 -36
  68. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +0 -177
  69. package/src/RedactoPrivacyCenter/PrivacyCenterMyReceiptPage.tsx +0 -26
  70. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +0 -58
  71. package/src/RedactoPrivacyCenter/api/actions.ts +0 -680
  72. package/src/RedactoPrivacyCenter/api/client.ts +0 -906
  73. package/src/RedactoPrivacyCenter/api/config.ts +0 -33
  74. package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -260
  75. package/src/RedactoPrivacyCenter/api/orgBranding.ts +0 -16
  76. package/src/RedactoPrivacyCenter/api/upload.ts +0 -93
  77. package/src/RedactoPrivacyCenter/assets/character.svg +0 -31
  78. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +0 -9
  79. package/src/RedactoPrivacyCenter/assets/greenTick.svg +0 -4
  80. package/src/RedactoPrivacyCenter/assets/mail.svg +0 -3
  81. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +0 -9
  82. package/src/RedactoPrivacyCenter/assets/sentImg.svg +0 -9
  83. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +0 -9
  84. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +0 -252
  85. package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +0 -239
  86. package/src/RedactoPrivacyCenter/components/AppShell/AppShell.tsx +0 -240
  87. package/src/RedactoPrivacyCenter/components/AppShell/MobileNavDrawer.tsx +0 -218
  88. package/src/RedactoPrivacyCenter/components/AppShell/NavItem.tsx +0 -205
  89. package/src/RedactoPrivacyCenter/components/AppShell/PageHeader.tsx +0 -107
  90. package/src/RedactoPrivacyCenter/components/AppShell/SidebarNav.tsx +0 -100
  91. package/src/RedactoPrivacyCenter/components/AppShell/TopAppBar.tsx +0 -339
  92. package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +0 -243
  93. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useIsTruncated.ts +0 -28
  94. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useKeyboardShortcut.ts +0 -40
  95. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useSidebarState.ts +0 -62
  96. package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +0 -36
  97. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +0 -38
  98. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +0 -31
  99. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +0 -79
  100. package/src/RedactoPrivacyCenter/components/CaseDetails/FinalizedTooltipWrapper.tsx +0 -25
  101. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +0 -96
  102. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +0 -97
  103. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +0 -156
  104. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +0 -171
  105. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +0 -23
  106. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +0 -116
  107. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +0 -43
  108. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +0 -71
  109. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +0 -469
  110. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +0 -426
  111. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +0 -1198
  112. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -201
  113. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +0 -138
  114. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +0 -7
  115. package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +0 -179
  116. package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +0 -318
  117. package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +0 -333
  118. package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +0 -102
  119. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +0 -159
  120. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +0 -189
  121. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +0 -118
  122. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +0 -66
  123. package/src/RedactoPrivacyCenter/components/DataRequest/ProductSelectionSection.tsx +0 -222
  124. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +0 -331
  125. package/src/RedactoPrivacyCenter/components/Form.tsx +0 -1796
  126. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +0 -174
  127. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +0 -337
  128. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +0 -334
  129. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +0 -173
  130. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +0 -18
  131. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +0 -54
  132. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +0 -57
  133. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +0 -19
  134. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +0 -92
  135. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +0 -20
  136. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +0 -58
  137. package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +0 -10
  138. package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +0 -112
  139. package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +0 -27
  140. package/src/RedactoPrivacyCenter/components/Pagination.tsx +0 -140
  141. package/src/RedactoPrivacyCenter/components/PrivacyCenterEmptyState.tsx +0 -76
  142. package/src/RedactoPrivacyCenter/components/PrivacyCenterSessionExpired.tsx +0 -97
  143. package/src/RedactoPrivacyCenter/components/ReceiptsList.tsx +0 -454
  144. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +0 -270
  145. package/src/RedactoPrivacyCenter/components/SelectUser.tsx +0 -83
  146. package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -193
  147. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +0 -25
  148. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +0 -21
  149. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +0 -159
  150. package/src/RedactoPrivacyCenter/components/constant.ts +0 -52
  151. package/src/RedactoPrivacyCenter/components/groupHelpers.ts +0 -119
  152. package/src/RedactoPrivacyCenter/components/receiptColumns.tsx +0 -203
  153. package/src/RedactoPrivacyCenter/components/types.ts +0 -123
  154. package/src/RedactoPrivacyCenter/components/utils.tsx +0 -10
  155. package/src/RedactoPrivacyCenter/config/routes.ts +0 -9
  156. package/src/RedactoPrivacyCenter/config/table.ts +0 -25
  157. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +0 -160
  158. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +0 -47
  159. package/src/RedactoPrivacyCenter/context/BrandingContext.tsx +0 -52
  160. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +0 -92
  161. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +0 -181
  162. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +0 -11
  163. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +0 -96
  164. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +0 -30
  165. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +0 -80
  166. package/src/RedactoPrivacyCenter/context/ProfileSwitchContext.tsx +0 -15
  167. package/src/RedactoPrivacyCenter/context/types.ts +0 -19
  168. package/src/RedactoPrivacyCenter/lib/api.ts +0 -756
  169. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
  170. package/src/RedactoPrivacyCenter/lib/constants.ts +0 -277
  171. package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
  172. package/src/RedactoPrivacyCenter/lib/locales.ts +0 -105
  173. package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
  174. package/src/RedactoPrivacyCenter/lib/types.ts +0 -868
  175. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
  176. package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
  177. package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
  178. package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
  179. package/src/RedactoPrivacyCenter/lib/utils.ts +0 -783
  180. package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -340
  181. package/src/RedactoPrivacyCenter/locales/bho/translation.json +0 -340
  182. package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -340
  183. package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -340
  184. package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -340
  185. package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -354
  186. package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -340
  187. package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -340
  188. package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -343
  189. package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -340
  190. package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -340
  191. package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -340
  192. package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -340
  193. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -340
  194. package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -340
  195. package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -340
  196. package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -340
  197. package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -340
  198. package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -340
  199. package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -340
  200. package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -340
  201. package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -340
  202. package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -340
  203. package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -340
  204. package/src/RedactoPrivacyCenter/styles/applyBrandingTheme.ts +0 -66
  205. package/src/RedactoPrivacyCenter/styles/base.css +0 -117
  206. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +0 -3103
  207. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -814
  208. package/src/RedactoPrivacyCenter/styles/responsive.ts +0 -138
  209. package/src/RedactoPrivacyCenter/styles/variables.css +0 -96
  210. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +0 -387
  211. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +0 -468
  212. package/src/RedactoPrivacyCenter/table/index.ts +0 -2
  213. package/src/RedactoPrivacyCenter/types/images.d.ts +0 -29
  214. package/src/RedactoPrivacyCenter/ui/Footer.tsx +0 -69
  215. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +0 -54
  216. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +0 -93
  217. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +0 -47
  218. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -69
  219. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
  220. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
  221. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
  222. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
  223. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
  224. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
  225. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
  226. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
  227. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
  228. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
  229. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
  230. package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
  231. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
  232. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
  233. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
  234. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
  235. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
  236. package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
  237. package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
  238. package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
  239. package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
  240. package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
  241. package/src/index.ts +0 -19
  242. package/src/privacy-center.ts +0 -113
  243. package/src/shared/api-errors.ts +0 -180
  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 -1287
  249. package/tests/ProductSelectionSection.test.tsx +0 -328
  250. package/tests/RequestSubmit.test.tsx +0 -135
  251. package/tests/consentClient.test.ts +0 -171
  252. package/tests/manageConsentServer.test.ts +0 -38
  253. package/tests/mocks.ts +0 -257
  254. package/tests/resolveContactFromJwt.test.ts +0 -44
  255. package/tests/setup.ts +0 -16
  256. package/tsconfig.json +0 -16
  257. package/tsup.config.ts +0 -31
  258. package/vitest.config.ts +0 -16
@@ -1,906 +0,0 @@
1
- import { apiFetch, ApiError } from "./fetcher";
2
- import type { ApiFetchOptions, ApiResponse } from "./fetcher";
3
- import type {
4
- CaseMessage,
5
- IdentityListResponse,
6
- MessageDocument,
7
- NotificationActionResponse,
8
- NotificationListResponse,
9
- NotificationQueryParams,
10
- NotificationSummary,
11
- SelectPrincipalResponse,
12
- UnreadCountResponse,
13
- UploadDocumentResponse,
14
- } from "../lib/types";
15
-
16
- /**
17
- * Base request parameters for consent service calls
18
- */
19
- export type BaseRequest = {
20
- organisationUuid: string;
21
- workspaceUuid: string;
22
- authToken: string;
23
- };
24
-
25
- /**
26
- * Consent service client factory.
27
- * Creates a client instance with a specific base URL.
28
- * @param baseUrl - Consent server base URL (Python service, e.g. http://host/consent)
29
- * @param ledgerBaseUrl - Go ledger base URL (e.g. http://host:8090/consent-ledger).
30
- * Used for user-consents reads/writes served from the ledger's `/public/...` paths.
31
- * When omitted, those calls fall back to the legacy Python
32
- * `/dsar/privacy-center` endpoints and payloads (pre-ledger behavior), so
33
- * integrations without a deployed ledger keep working.
34
- */
35
- export function createConsentClient(baseUrl: string, ledgerBaseUrl?: string) {
36
- const useLedger = Boolean(ledgerBaseUrl);
37
- const ledgerBase = (ledgerBaseUrl ?? "").replace(/\/$/, "");
38
- /**
39
- * Privacy Center API fetch wrapper that uses Authorization: Bearer header.
40
- * Privacy center endpoints require JWT tokens in Authorization header, not X-Auth-Token.
41
- */
42
- async function privacyCenterApiFetch<T>(
43
- url: string,
44
- options: ApiFetchOptions & { authToken?: string }
45
- ): Promise<T> {
46
- const { authToken, getAuthToken, headers = {}, ...fetchOptions } = options;
47
-
48
- // Build headers using Headers object
49
- const requestHeaders = new Headers();
50
-
51
- // Set default headers (skip Content-Type for FormData)
52
- const isFormData = fetchOptions.body instanceof FormData;
53
- if (!isFormData) {
54
- requestHeaders.set("Content-Type", "application/json");
55
- }
56
- requestHeaders.set("Accept", "application/json");
57
-
58
- // Add custom headers from options
59
- if (headers && typeof headers === "object") {
60
- if (headers instanceof Headers) {
61
- headers.forEach((value, key) => {
62
- requestHeaders.set(key, value);
63
- });
64
- } else {
65
- Object.entries(headers as Record<string, string>).forEach(
66
- ([key, value]) => {
67
- if (value) {
68
- requestHeaders.set(key, value);
69
- }
70
- }
71
- );
72
- }
73
- }
74
-
75
- // Add Authorization Bearer token for privacy center APIs
76
- const token = authToken || (getAuthToken ? await getAuthToken() : null);
77
- if (token) {
78
- const trimmedToken = token.trim();
79
- // Format token with Bearer prefix if not already present
80
- const bearerToken = trimmedToken.startsWith('Bearer ')
81
- ? trimmedToken
82
- : `Bearer ${trimmedToken}`;
83
- requestHeaders.set("Authorization", bearerToken);
84
- }
85
-
86
- // Build fetch options
87
- const fetchOptionsFinal: RequestInit = {
88
- ...fetchOptions,
89
- headers: requestHeaders,
90
- };
91
-
92
- try {
93
- const response = await fetch(url, fetchOptionsFinal);
94
-
95
- // Handle non-OK responses
96
- if (!response.ok) {
97
- let errorMessage = `Request failed with status ${response.status}`;
98
- let errorCode: string | undefined;
99
- let errorDetail: unknown;
100
-
101
- try {
102
- const errorData = (await response.json()) as {
103
- detail?: unknown;
104
- message?: string;
105
- code?: string;
106
- } | null;
107
- if (errorData) {
108
- errorDetail = errorData.detail;
109
- if (typeof errorData.code === "string") {
110
- errorCode = errorData.code;
111
- }
112
- if ("detail" in errorData && errorData.detail) {
113
- errorMessage =
114
- typeof errorData.detail === "string"
115
- ? errorData.detail
116
- : JSON.stringify(errorData.detail, null, 2);
117
- } else if ("message" in errorData && errorData.message) {
118
- errorMessage = errorData.message;
119
- } else if ("code" in errorData && errorData.code) {
120
- // e.g. { code: "empty_file" } or { code: "document_already_exists" }
121
- errorMessage = errorData.code;
122
- }
123
- }
124
- } catch {
125
- // If response is not JSON, try to get text
126
- try {
127
- const errorText = await response.text();
128
- if (errorText) {
129
- errorMessage = errorText;
130
- }
131
- } catch {
132
- // Ignore parsing errors
133
- }
134
- }
135
-
136
- // Throw a typed error carrying the status/code. The `[status]` prefix is
137
- // kept in the message for back-compat with callers that branch on it
138
- // (e.g. getFormData checks for "404").
139
- throw new ApiError(`[${response.status}] ${errorMessage}`, {
140
- status: response.status,
141
- code: errorCode,
142
- detail: errorDetail,
143
- });
144
- }
145
-
146
- // Parse JSON response
147
- const contentType = response.headers.get("Content-Type") || "";
148
- if (!contentType.includes("application/json")) {
149
- const textResponse = await response.text();
150
- throw new Error(
151
- `Expected JSON response, got ${contentType}: ${textResponse}`
152
- );
153
- }
154
-
155
- const data = (await response.json()) as ApiResponse<T> | T;
156
-
157
- // Handle wrapped API responses (code, status, detail format)
158
- if (
159
- typeof data === "object" &&
160
- data !== null &&
161
- "code" in data &&
162
- "status" in data &&
163
- "detail" in data
164
- ) {
165
- const apiResponse = data as ApiResponse<T>;
166
- return apiResponse.detail as T;
167
- }
168
-
169
- return data as T;
170
- } catch (error) {
171
- if (error instanceof Error) {
172
- throw error;
173
- }
174
- throw new Error(`Unknown error occurred: ${String(error)}`);
175
- }
176
- }
177
-
178
- function privacyCenterUrl(baseRequest: BaseRequest, path: string): string {
179
- return `${baseUrl}/organisations/${baseRequest.organisationUuid}/workspaces/${baseRequest.workspaceUuid}/dsar/privacy-center${path}`;
180
- }
181
-
182
- function ledgerUrl(baseRequest: BaseRequest, path: string): string {
183
- if (!useLedger) {
184
- throw new Error("ledgerUrl called without a configured ledgerBaseUrl");
185
- }
186
- return `${ledgerBase}/public/organisations/${baseRequest.organisationUuid}/workspaces/${baseRequest.workspaceUuid}${path}`;
187
- }
188
-
189
- function caseUrl(baseRequest: BaseRequest, caseUuid: string, path = ''): string {
190
- return privacyCenterUrl(baseRequest, `/cases/${caseUuid}${path}`);
191
- }
192
-
193
- function notificationUrl(baseRequest: BaseRequest, path = ''): string {
194
- return privacyCenterUrl(baseRequest, `/notifications${path}`);
195
- }
196
-
197
- function resolveAuthToken(authToken: string | undefined, baseRequest: BaseRequest): string {
198
- return authToken || baseRequest.authToken;
199
- }
200
-
201
- return {
202
- /**
203
- * Get form data (privacy center)
204
- */
205
- async getFormData(
206
- baseRequest: BaseRequest,
207
- contact: string,
208
- authToken?: string,
209
- options?: ApiFetchOptions & { useSessionAuth?: boolean },
210
- language?: string
211
- ): Promise<unknown> {
212
- const queryParams = new URLSearchParams();
213
- if (language) queryParams.append("language", language);
214
- const queryString = queryParams.toString();
215
- const url = privacyCenterUrl(baseRequest, `/form/data${queryString ? `?${queryString}` : ""}`);
216
- const { useSessionAuth = false, getAuthToken, ...fetchOptions } = options || {};
217
-
218
- // Case management uses session-based auth (X-Auth-Token)
219
- // Privacy center uses JWT Bearer tokens (Authorization: Bearer)
220
- if (useSessionAuth) {
221
- return apiFetch(url, {
222
- ...fetchOptions,
223
- method: "POST",
224
- body: JSON.stringify({ contact }),
225
- getAuthToken,
226
- });
227
- }
228
-
229
- // Privacy center: use JWT Bearer token
230
- return privacyCenterApiFetch(url, {
231
- ...fetchOptions,
232
- method: "POST",
233
- body: JSON.stringify({ contact }),
234
- authToken: resolveAuthToken(authToken, baseRequest),
235
- });
236
- },
237
-
238
- /**
239
- * Create case request (privacy center or case management)
240
- */
241
- async createCaseRequest(
242
- baseRequest: BaseRequest,
243
- payload: unknown,
244
- authToken?: string,
245
- options?: ApiFetchOptions & { useSessionAuth?: boolean }
246
- ): Promise<unknown> {
247
- const url = privacyCenterUrl(baseRequest, '/case');
248
- const { useSessionAuth = false, getAuthToken, ...fetchOptions } = options || {};
249
-
250
- // Case management uses session-based auth (X-Auth-Token)
251
- // Privacy center uses JWT Bearer tokens (Authorization: Bearer)
252
- if (useSessionAuth) {
253
- return apiFetch(url, {
254
- ...fetchOptions,
255
- method: "POST",
256
- body: JSON.stringify(payload),
257
- getAuthToken,
258
- });
259
- }
260
-
261
- // Privacy center: use JWT Bearer token
262
- return privacyCenterApiFetch(url, {
263
- ...fetchOptions,
264
- method: "POST",
265
- body: JSON.stringify(payload),
266
- authToken: resolveAuthToken(authToken, baseRequest),
267
- });
268
- },
269
-
270
- /**
271
- * Create OTP (public)
272
- */
273
- async createOtp(
274
- organisationId: string,
275
- workspaceId: string,
276
- email: string,
277
- options?: Omit<ApiFetchOptions, "getAuthToken">
278
- ): Promise<unknown> {
279
- const url = `${baseUrl}/public/organisations/${organisationId}/workspaces/${workspaceId}/otp/create`;
280
- return apiFetch(url, {
281
- ...options,
282
- method: "POST",
283
- body: JSON.stringify({ to: email, channel: "email" }),
284
- });
285
- },
286
-
287
- /**
288
- * Verify OTP (public)
289
- */
290
- async verifyOtp(
291
- organisationId: string,
292
- workspaceId: string,
293
- otpId: string,
294
- otp: string,
295
- options?: Omit<ApiFetchOptions, "getAuthToken">
296
- ): Promise<unknown> {
297
- const url = `${baseUrl}/public/organisations/${organisationId}/workspaces/${workspaceId}/otp/verify`;
298
- return apiFetch(url, {
299
- ...options,
300
- method: "POST",
301
- body: JSON.stringify({ uuid: otpId, otp }),
302
- });
303
- },
304
-
305
- /**
306
- * Exchange one-time token for JWT tokens (public)
307
- */
308
- async exchangeToken(
309
- token: string,
310
- ): Promise<unknown> {
311
- const url = `${baseUrl}/public/tokens/token-exchange?token=${encodeURIComponent(token)}`;
312
- const response = await fetch(url, {
313
- method: "GET",
314
- headers: { "Accept": "application/json" },
315
- });
316
-
317
- if (!response.ok) {
318
- const errorData = await response.json().catch(() => null) as { detail?: string; message?: string } | null;
319
- throw new Error(
320
- errorData?.detail || errorData?.message || `Token exchange failed with status ${response.status}`
321
- );
322
- }
323
-
324
- const data = await response.json() as { code?: number; status?: string; detail?: unknown };
325
- if (data && typeof data === "object" && "code" in data && "status" in data && "detail" in data) {
326
- return data.detail;
327
- }
328
- return data;
329
- },
330
-
331
- /**
332
- * Refresh OTP token (public)
333
- */
334
- async refreshOtpToken(
335
- organisationId: string,
336
- workspaceId: string,
337
- refreshToken: string,
338
- options?: Omit<ApiFetchOptions, "getAuthToken">
339
- ): Promise<unknown> {
340
- const url = `${baseUrl}/public/organisations/${organisationId}/workspaces/${workspaceId}/otp/refresh`;
341
- return apiFetch(url, {
342
- ...options,
343
- method: "POST",
344
- body: JSON.stringify({ refresh_token: refreshToken }),
345
- });
346
- },
347
-
348
- /**
349
- * Get products
350
- */
351
- async getProducts(
352
- baseRequest: BaseRequest,
353
- skip: number = 0,
354
- limit: number = 10,
355
- options?: Omit<ApiFetchOptions, "getAuthToken">
356
- ): Promise<unknown> {
357
- const url = `${baseUrl}/organisations/${baseRequest.organisationUuid}/workspaces/${baseRequest.workspaceUuid}/notice-management/products/?skip=${skip}&limit=${limit}`;
358
- return apiFetch<unknown>(url, {
359
- ...options,
360
- getAuthToken: async () => baseRequest.authToken,
361
- });
362
- },
363
-
364
- /**
365
- * Get user consents (privacy center)
366
- */
367
- async getUserConsents(
368
- baseRequest: BaseRequest,
369
- params: {
370
- offset?: number;
371
- limit?: number;
372
- nominated_offset?: number;
373
- nominated_limit?: number;
374
- status?: string;
375
- product_uuid?: string;
376
- search?: string;
377
- language?: string;
378
- },
379
- authToken?: string,
380
- options?: Omit<ApiFetchOptions, "getAuthToken">
381
- ): Promise<unknown> {
382
- const queryParams = new URLSearchParams();
383
- if (params.offset !== undefined) queryParams.append("offset", params.offset.toString());
384
- if (params.limit !== undefined) queryParams.append("limit", params.limit.toString());
385
- if (params.nominated_offset !== undefined) queryParams.append("nominated_offset", params.nominated_offset.toString());
386
- if (params.nominated_limit !== undefined) queryParams.append("nominated_limit", params.nominated_limit.toString());
387
- if (params.search) queryParams.append("search", params.search);
388
- if (params.status) queryParams.append("status", params.status);
389
- if (params.product_uuid) queryParams.append("product_uuid", params.product_uuid);
390
- if (params.language) queryParams.append("language", params.language);
391
- const queryString = queryParams.toString();
392
- const suffix = `/user-consents${queryString ? `?${queryString}` : ""}`;
393
- const url = useLedger
394
- ? ledgerUrl(baseRequest, suffix)
395
- : privacyCenterUrl(baseRequest, suffix);
396
- return privacyCenterApiFetch(url, {
397
- ...options,
398
- method: "GET",
399
- cache: "no-store",
400
- authToken: resolveAuthToken(authToken, baseRequest),
401
- });
402
- },
403
-
404
- /**
405
- * Get purposes for a single product card (privacy center) — sister endpoint
406
- * for lazy-loading purposes when a card returns has_more_purposes: true.
407
- */
408
- async getGroupPurposes(
409
- baseRequest: BaseRequest,
410
- productUuid: string,
411
- params: {
412
- offset?: number;
413
- limit?: number;
414
- status?: string;
415
- search?: string;
416
- language?: string;
417
- nominator_uuid?: string;
418
- },
419
- authToken?: string,
420
- options?: Omit<ApiFetchOptions, "getAuthToken">
421
- ): Promise<unknown> {
422
- const queryParams = new URLSearchParams();
423
- if (params.offset !== undefined) queryParams.append("offset", params.offset.toString());
424
- if (params.limit !== undefined) queryParams.append("limit", params.limit.toString());
425
- if (params.status) queryParams.append("status", params.status);
426
- if (params.search) queryParams.append("search", params.search);
427
- if (params.language) queryParams.append("language", params.language);
428
- if (params.nominator_uuid) queryParams.append("nominator_uuid", params.nominator_uuid);
429
- const queryString = queryParams.toString();
430
- const suffix = `/user-consents/${productUuid}/purposes${queryString ? `?${queryString}` : ""}`;
431
- const url = useLedger
432
- ? ledgerUrl(baseRequest, suffix)
433
- : privacyCenterUrl(baseRequest, suffix);
434
- return privacyCenterApiFetch(url, {
435
- ...options,
436
- method: "GET",
437
- cache: "no-store",
438
- authToken: resolveAuthToken(authToken, baseRequest),
439
- });
440
- },
441
-
442
- /**
443
- * Manage consent (privacy center) - revoke, regrant, or renew.
444
- *
445
- * The Go ledger has no manage-consent route, so with a ledger configured
446
- * this is expressed as a `partial` submit-consent on the ledger — mirroring
447
- * the Python dual-write relay (`build_consent_management_payload`): the
448
- * affected purpose is re-submitted with `selected: false` to revoke or
449
- * `selected: true` to regrant/renew, and `partial: true` so the rest of the
450
- * notice's purposes are left untouched. The principal is resolved from the
451
- * JWT, so no `contact`/identifiers are sent in the body, and
452
- * `consent_event_uuid` is omitted so the ledger mints a fresh event.
453
- *
454
- * Without a ledger, the legacy Python `/manage-consent?status=` endpoint is
455
- * used with its `{ purpose_uuid, contact, ... }` payload.
456
- */
457
- async manageConsent(
458
- baseRequest: BaseRequest,
459
- purposeId: string,
460
- // Sent to the legacy Python endpoint only; the ledger resolves the
461
- // principal from the JWT, so no identifiers are sent in ledger mode.
462
- contact: string,
463
- status: 'revoke' | 'regrant' | 'renew',
464
- authToken?: string,
465
- options?: Omit<ApiFetchOptions, "getAuthToken">,
466
- nominatorContact?: string,
467
- dataElementUuids?: string[],
468
- productUuid?: string,
469
- noticeUuid?: string,
470
- dataElements?: Array<{ uuid: string; selected: boolean }>
471
- ): Promise<unknown> {
472
- if (!useLedger) {
473
- const url = privacyCenterUrl(baseRequest, `/manage-consent?status=${status}`);
474
- const body: Record<string, unknown> = { purpose_uuid: purposeId, contact };
475
- if (nominatorContact) {
476
- body.nominator_contact = nominatorContact;
477
- }
478
- if (Array.isArray(dataElementUuids) && dataElementUuids.length > 0) {
479
- body.data_element_uuids = dataElementUuids;
480
- }
481
- if (productUuid) {
482
- body.product_uuid = productUuid;
483
- }
484
- return privacyCenterApiFetch(url, {
485
- ...options,
486
- method: "POST",
487
- body: JSON.stringify(body),
488
- authToken: resolveAuthToken(authToken, baseRequest),
489
- });
490
- }
491
- if (!noticeUuid) {
492
- throw new Error("notice_uuid is required to manage consent via the ledger");
493
- }
494
- const purposeSelected = status !== 'revoke';
495
- const elements = (dataElements ?? []).map((de) => {
496
- let selected: boolean;
497
- if (status === 'revoke') {
498
- selected = false;
499
- } else if (status === 'regrant') {
500
- // Only the data elements the user chose to re-grant become selected.
501
- selected = Array.isArray(dataElementUuids)
502
- ? dataElementUuids.includes(de.uuid)
503
- : de.selected;
504
- } else {
505
- // renew — preserve the currently-granted set.
506
- selected = de.selected;
507
- }
508
- return { uuid: de.uuid, selected };
509
- });
510
- const body = {
511
- notice_uuid: noticeUuid,
512
- partial: true,
513
- declined: false,
514
- select_all_mandatory: false,
515
- self_declared_adult: false,
516
- purposes: [
517
- {
518
- purpose_uuid: purposeId,
519
- selected: purposeSelected,
520
- data_elements: elements,
521
- },
522
- ],
523
- };
524
- const url = ledgerUrl(baseRequest, "/submit-consent");
525
- return privacyCenterApiFetch(url, {
526
- ...options,
527
- method: "POST",
528
- body: JSON.stringify(body),
529
- authToken: resolveAuthToken(authToken, baseRequest),
530
- });
531
- },
532
-
533
- /**
534
- * Get activities (privacy center)
535
- */
536
- async getActivities(
537
- baseRequest: BaseRequest,
538
- offset?: number,
539
- limit?: number,
540
- language?: string,
541
- authToken?: string,
542
- options?: Omit<ApiFetchOptions, "getAuthToken">
543
- ): Promise<unknown> {
544
- const queryParams = new URLSearchParams();
545
- if (offset !== undefined) queryParams.append("offset", offset.toString());
546
- if (limit !== undefined) queryParams.append("limit", limit.toString());
547
- if (language) queryParams.append("language", language);
548
- const queryString = queryParams.toString();
549
- const url = privacyCenterUrl(baseRequest, `/activities${queryString ? `?${queryString}` : ""}`);
550
- return privacyCenterApiFetch<unknown>(url, {
551
- ...options,
552
- authToken: resolveAuthToken(authToken, baseRequest),
553
- });
554
- },
555
-
556
- /**
557
- * List all data principals that share this session's contact
558
- * (shared-contact profile picker). Identity is derived server-side from the
559
- * JWT — the caller sends nothing but its bearer token.
560
- */
561
- async listIdentities(
562
- baseRequest: BaseRequest,
563
- authToken?: string,
564
- options?: Omit<ApiFetchOptions, "getAuthToken">
565
- ): Promise<IdentityListResponse> {
566
- const url = privacyCenterUrl(baseRequest, '/identities');
567
- return privacyCenterApiFetch<IdentityListResponse>(url, {
568
- ...options,
569
- cache: 'no-store',
570
- authToken: resolveAuthToken(authToken, baseRequest),
571
- });
572
- },
573
-
574
- /**
575
- * Re-scope the session to a chosen principal uuid (must be one of the
576
- * principals sharing this session's contact). Returns fresh access/refresh
577
- * tokens scoped to that principal.
578
- */
579
- async selectPrincipal(
580
- baseRequest: BaseRequest,
581
- principalUuid: string,
582
- authToken?: string,
583
- options?: Omit<ApiFetchOptions, "getAuthToken">
584
- ): Promise<SelectPrincipalResponse> {
585
- const url = privacyCenterUrl(baseRequest, '/identities/select');
586
- return privacyCenterApiFetch<SelectPrincipalResponse>(url, {
587
- ...options,
588
- method: 'POST',
589
- body: JSON.stringify({ uuid: principalUuid }),
590
- authToken: resolveAuthToken(authToken, baseRequest),
591
- });
592
- },
593
-
594
- /**
595
- * Get receipts (privacy center) — consent receipts for the authenticated user
596
- */
597
- async getReceipts(
598
- baseRequest: BaseRequest,
599
- params: {
600
- skip?: number;
601
- limit?: number;
602
- notice_uuid?: string;
603
- event_type?: string;
604
- status?: string;
605
- created_after?: string;
606
- created_before?: string;
607
- language?: string;
608
- },
609
- authToken?: string,
610
- options?: Omit<ApiFetchOptions, "getAuthToken">
611
- ): Promise<unknown> {
612
- const queryParams = new URLSearchParams();
613
- if (params.skip !== undefined) queryParams.append("skip", params.skip.toString());
614
- if (params.limit !== undefined) queryParams.append("limit", params.limit.toString());
615
- if (params.notice_uuid) queryParams.append("notice_uuid", params.notice_uuid);
616
- if (params.event_type) queryParams.append("event_type", params.event_type);
617
- if (params.status) queryParams.append("status", params.status);
618
- if (params.created_after) queryParams.append("created_after", params.created_after);
619
- if (params.created_before) queryParams.append("created_before", params.created_before);
620
- if (params.language) queryParams.append("language", params.language);
621
- const queryString = queryParams.toString();
622
- // With a ledger configured, receipts are served by the Go ledger
623
- // (paginated list under /public/...); otherwise the legacy Python
624
- // privacy-center list is used. normalizeReceipts tolerates both envelopes.
625
- const receiptsSuffix = `/receipts${queryString ? `?${queryString}` : ""}`;
626
- const url = useLedger
627
- ? ledgerUrl(baseRequest, receiptsSuffix)
628
- : privacyCenterUrl(baseRequest, receiptsSuffix);
629
- return privacyCenterApiFetch<unknown>(url, {
630
- ...options,
631
- method: "GET",
632
- cache: "no-store",
633
- authToken: resolveAuthToken(authToken, baseRequest),
634
- });
635
- },
636
-
637
- /**
638
- * Download a single receipt as a PDF (privacy center).
639
- * Returns raw PDF bytes as a Blob — the caller builds an object URL to open/save it.
640
- * Uses a direct fetch (not privacyCenterApiFetch) because the response is binary, not JSON,
641
- * and the Authorization header must be sent (anchor navigation wouldn't carry it).
642
- */
643
- async getReceiptPdf(
644
- baseRequest: BaseRequest,
645
- receiptUuid: string,
646
- authToken?: string
647
- ): Promise<Blob> {
648
- // The ledger serves the receipt PDF at /receipts/{uuid}/download, the
649
- // legacy Python service at /receipts/{uuid}/pdf. The receiptUuid always
650
- // comes from the same-mode list above, so list and download stay consistent.
651
- const url = useLedger
652
- ? ledgerUrl(baseRequest, `/receipts/${receiptUuid}/download`)
653
- : privacyCenterUrl(baseRequest, `/receipts/${receiptUuid}/pdf`);
654
- const token = resolveAuthToken(authToken, baseRequest);
655
- const requestHeaders = new Headers();
656
- requestHeaders.set("Accept", "application/pdf");
657
- if (token) {
658
- const trimmedToken = token.trim();
659
- requestHeaders.set(
660
- "Authorization",
661
- trimmedToken.startsWith("Bearer ") ? trimmedToken : `Bearer ${trimmedToken}`
662
- );
663
- }
664
- const response = await fetch(url, { method: "GET", headers: requestHeaders });
665
- if (!response.ok) {
666
- let errorMessage = `Request failed with status ${response.status}`;
667
- try {
668
- const errorData = (await response.json()) as { detail?: unknown; error_code?: string } | null;
669
- if (errorData?.detail) {
670
- errorMessage =
671
- typeof errorData.detail === "string" ? errorData.detail : JSON.stringify(errorData.detail);
672
- } else if (errorData?.error_code) {
673
- errorMessage = errorData.error_code;
674
- }
675
- } catch {
676
- // non-JSON error body — keep default message
677
- }
678
- // Prepend HTTP status so callers can branch on it (e.g. 404 = receipt not found)
679
- throw new Error(`[${response.status}] ${errorMessage}`);
680
- }
681
- return response.blob();
682
- },
683
-
684
- /**
685
- * Get case history (privacy center)
686
- */
687
- async getCaseHistory(
688
- baseRequest: BaseRequest,
689
- _contact: string,
690
- offset?: number,
691
- limit?: number,
692
- language?: string,
693
- authToken?: string,
694
- options?: Omit<ApiFetchOptions, "getAuthToken">
695
- ): Promise<unknown> {
696
- const queryParams = new URLSearchParams();
697
- if (offset !== undefined) queryParams.append("offset", offset.toString());
698
- if (limit !== undefined) queryParams.append("limit", limit.toString());
699
- if (language) queryParams.append("language", language);
700
- const queryString = queryParams.toString();
701
- const url = privacyCenterUrl(baseRequest, `/cases?${queryString}`);
702
- return privacyCenterApiFetch<unknown>(url, {
703
- ...options,
704
- authToken: resolveAuthToken(authToken, baseRequest),
705
- });
706
- },
707
-
708
- // ─── Case Communication ─────────────────────────────────────────────────
709
-
710
- /**
711
- * Get messages for a case (privacy center)
712
- */
713
- async getCaseMessages(
714
- baseRequest: BaseRequest,
715
- caseUuid: string,
716
- authToken?: string
717
- ): Promise<CaseMessage[]> {
718
- const url = caseUrl(baseRequest, caseUuid, '/messages');
719
- return privacyCenterApiFetch<CaseMessage[]>(url, {
720
- authToken: resolveAuthToken(authToken, baseRequest),
721
- });
722
- },
723
-
724
- /**
725
- * Send a message on a case (privacy center)
726
- */
727
- async sendCaseMessage(
728
- baseRequest: BaseRequest,
729
- caseUuid: string,
730
- body: string,
731
- documentUuids: string[],
732
- authToken?: string
733
- ): Promise<CaseMessage> {
734
- const url = caseUrl(baseRequest, caseUuid, '/messages');
735
- return privacyCenterApiFetch<CaseMessage>(url, {
736
- method: 'POST',
737
- body: JSON.stringify({ body, document_uuids: documentUuids }),
738
- authToken: resolveAuthToken(authToken, baseRequest),
739
- });
740
- },
741
-
742
- /**
743
- * Upload a document on a case (multipart/form-data, privacy center)
744
- */
745
- async uploadCaseDocument(
746
- baseRequest: BaseRequest,
747
- caseUuid: string,
748
- file: File,
749
- authToken?: string
750
- ): Promise<UploadDocumentResponse> {
751
- const url = caseUrl(baseRequest, caseUuid, '/upload-document');
752
- const formData = new FormData();
753
- formData.append('file', file, file.name); // field name must be exactly "file"
754
- // "payload" is required by the privacy-center endpoint (omitting it causes 422)
755
- formData.append('payload', JSON.stringify({ metadata: null }));
756
- return privacyCenterApiFetch<UploadDocumentResponse>(url, {
757
- method: 'POST',
758
- body: formData,
759
- authToken: resolveAuthToken(authToken, baseRequest),
760
- });
761
- },
762
-
763
- /**
764
- * Submit a document against a handler document request (privacy center)
765
- */
766
- async submitDocumentForRequest(
767
- baseRequest: BaseRequest,
768
- caseUuid: string,
769
- requestEventUuid: string,
770
- documentUuid: string,
771
- body: string,
772
- authToken?: string
773
- ): Promise<CaseMessage> {
774
- const url = caseUrl(baseRequest, caseUuid, `/document-requests/${requestEventUuid}/submit`);
775
- return privacyCenterApiFetch<CaseMessage>(url, {
776
- method: 'POST',
777
- body: JSON.stringify({ document_uuid: documentUuid, body }),
778
- authToken: resolveAuthToken(authToken, baseRequest),
779
- });
780
- },
781
-
782
- /**
783
- * Get document info/download URL for a case document (privacy center)
784
- */
785
- async getCaseDocument(
786
- baseRequest: BaseRequest,
787
- caseUuid: string,
788
- documentUuid: string,
789
- authToken?: string
790
- ): Promise<MessageDocument> {
791
- const url = caseUrl(baseRequest, caseUuid, `/documents/${documentUuid}`);
792
- return privacyCenterApiFetch<MessageDocument>(url, {
793
- authToken: resolveAuthToken(authToken, baseRequest),
794
- });
795
- },
796
-
797
- // ─── Notification Hub ─────────────────────────────────────────────────
798
-
799
- /**
800
- * List notifications (paginated, with filters)
801
- */
802
- async getNotifications(
803
- baseRequest: BaseRequest,
804
- params?: NotificationQueryParams,
805
- authToken?: string
806
- ): Promise<NotificationListResponse> {
807
- const queryParams = new URLSearchParams();
808
- if (params?.category) {
809
- queryParams.append('category', params.category);
810
- }
811
- if (params?.notification_type) {
812
- queryParams.append('notification_type', params.notification_type);
813
- }
814
- if (params?.is_read !== undefined) {
815
- queryParams.append('is_read', String(params.is_read));
816
- }
817
- if (params?.skip !== undefined) {
818
- queryParams.append('skip', params.skip.toString());
819
- }
820
- if (params?.limit !== undefined) {
821
- queryParams.append('limit', params.limit.toString());
822
- }
823
- if (params?.include_summary) {
824
- queryParams.append('include_summary', 'true');
825
- }
826
- if (params?.language) {
827
- queryParams.append('language', params.language);
828
- }
829
- const queryString = queryParams.toString();
830
- const url = notificationUrl(baseRequest, queryString ? `?${queryString}` : '');
831
- return privacyCenterApiFetch<NotificationListResponse>(url, {
832
- authToken: resolveAuthToken(authToken, baseRequest),
833
- });
834
- },
835
-
836
- /**
837
- * Get notification summary (aggregated counts only)
838
- */
839
- async getNotificationSummary(
840
- baseRequest: BaseRequest,
841
- authToken?: string
842
- ): Promise<NotificationSummary> {
843
- const url = notificationUrl(baseRequest, '/summary');
844
- return privacyCenterApiFetch<NotificationSummary>(url, {
845
- authToken: resolveAuthToken(authToken, baseRequest),
846
- });
847
- },
848
-
849
- /**
850
- * Get unread notification count (lightweight, for badge)
851
- */
852
- async getUnreadCount(
853
- baseRequest: BaseRequest,
854
- authToken?: string
855
- ): Promise<UnreadCountResponse> {
856
- const url = notificationUrl(baseRequest, '/unread-count');
857
- return privacyCenterApiFetch<UnreadCountResponse>(url, {
858
- authToken: resolveAuthToken(authToken, baseRequest),
859
- });
860
- },
861
-
862
- /**
863
- * Mark a single notification as read
864
- */
865
- async markNotificationRead(
866
- baseRequest: BaseRequest,
867
- notificationUuid: string,
868
- authToken?: string
869
- ): Promise<NotificationActionResponse> {
870
- const url = notificationUrl(baseRequest, `/${notificationUuid}/read`);
871
- return privacyCenterApiFetch<NotificationActionResponse>(url, {
872
- method: 'PATCH',
873
- authToken: resolveAuthToken(authToken, baseRequest),
874
- });
875
- },
876
-
877
- /**
878
- * Mark all notifications as read
879
- */
880
- async markAllNotificationsRead(
881
- baseRequest: BaseRequest,
882
- authToken?: string
883
- ): Promise<NotificationActionResponse> {
884
- const url = notificationUrl(baseRequest, '/mark-all-read');
885
- return privacyCenterApiFetch<NotificationActionResponse>(url, {
886
- method: 'POST',
887
- authToken: resolveAuthToken(authToken, baseRequest),
888
- });
889
- },
890
-
891
- /**
892
- * Acknowledge a notification (sets is_read and is_acknowledged to true)
893
- */
894
- async acknowledgeNotification(
895
- baseRequest: BaseRequest,
896
- notificationUuid: string,
897
- authToken?: string
898
- ): Promise<NotificationActionResponse> {
899
- const url = notificationUrl(baseRequest, `/${notificationUuid}/acknowledge`);
900
- return privacyCenterApiFetch<NotificationActionResponse>(url, {
901
- method: 'POST',
902
- authToken: resolveAuthToken(authToken, baseRequest),
903
- });
904
- },
905
- };
906
- }