@redacto.io/consent-sdk-react 4.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/LICENSE +176 -0
- package/README.md +98 -1
- package/dist/index.js +231 -96
- package/dist/index.mjs +231 -96
- package/dist/privacy-center.d.mts +649 -0
- package/dist/privacy-center.d.ts +649 -0
- package/dist/privacy-center.js +20824 -0
- package/dist/privacy-center.mjs +20789 -0
- package/package.json +47 -3
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +6 -4
- package/src/RedactoNoticeConsent/api/index.ts +2 -0
- package/src/RedactoNoticeConsent/api/types.ts +2 -0
- package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +128 -62
- package/src/RedactoNoticeConsent/language-codes.ts +97 -0
- package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -3
- package/src/RedactoNoticeConsentInline/api/index.ts +0 -1
- package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +154 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +30 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +173 -0
- package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +55 -0
- package/src/RedactoPrivacyCenter/api/actions.ts +476 -0
- package/src/RedactoPrivacyCenter/api/client.ts +524 -0
- package/src/RedactoPrivacyCenter/api/config.ts +33 -0
- package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
- package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
- package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
- package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
- package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
- package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
- package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +38 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +31 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +73 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +87 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +95 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +147 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +171 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +23 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +116 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +36 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +56 -0
- package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +469 -0
- package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +426 -0
- package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +732 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +238 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +304 -0
- package/src/RedactoPrivacyCenter/components/Form.tsx +1596 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +174 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +337 -0
- package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +330 -0
- package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
- package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +304 -0
- package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +232 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +408 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
- package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
- package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
- package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +159 -0
- package/src/RedactoPrivacyCenter/components/constant.ts +16 -0
- package/src/RedactoPrivacyCenter/components/types.ts +76 -0
- package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
- package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
- package/src/RedactoPrivacyCenter/config/table.ts +25 -0
- package/src/RedactoPrivacyCenter/context/AuthContext.tsx +137 -0
- package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +41 -0
- package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
- package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +96 -0
- package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
- package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
- package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
- package/src/RedactoPrivacyCenter/context/types.ts +14 -0
- package/src/RedactoPrivacyCenter/lib/api.ts +566 -0
- package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
- package/src/RedactoPrivacyCenter/lib/constants.ts +161 -0
- package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
- package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
- package/src/RedactoPrivacyCenter/lib/queries.ts +134 -0
- package/src/RedactoPrivacyCenter/lib/types.ts +531 -0
- package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
- package/src/RedactoPrivacyCenter/lib/utils.ts +626 -0
- package/src/RedactoPrivacyCenter/locales/as/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/bho/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/bn/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/brx/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/doi/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/en/translation.json +255 -0
- package/src/RedactoPrivacyCenter/locales/gom/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/gu/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/hi/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/kn/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ks/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/mai/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ml/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/mr/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ne/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/or/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/pa/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/sa/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/sat/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/sd/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ta/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/te/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ur/translation.json +280 -0
- package/src/RedactoPrivacyCenter/styles/base.css +117 -0
- package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1725 -0
- package/src/RedactoPrivacyCenter/styles/pcStyles.ts +813 -0
- package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
- package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +367 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +476 -0
- package/src/RedactoPrivacyCenter/table/index.ts +2 -0
- package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
- package/src/RedactoPrivacyCenter/ui/Footer.tsx +75 -0
- package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
- package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +93 -0
- package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
- package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
- package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
- package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
- package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
- package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +107 -0
- package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
- package/src/RedactoPrivacyCenter/ui/PCInput.tsx +132 -0
- package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +31 -0
- package/src/RedactoPrivacyCenter/ui/PCModal.tsx +106 -0
- package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +173 -0
- package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +387 -0
- package/src/RedactoPrivacyCenter/ui/PCTable.tsx +149 -0
- package/src/RedactoPrivacyCenter/ui/PCText.tsx +41 -0
- package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
- package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
- package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
- package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
- package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +53 -0
- package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +72 -0
- package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
- package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
- package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
- package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
- package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
- package/src/privacy-center.ts +108 -0
- package/tsconfig.json +2 -0
- package/tsup.config.ts +16 -1
- package/.turbo/turbo-build.log +0 -21
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import type { BaseRequest } from './client';
|
|
2
|
+
|
|
3
|
+
export type ConsentApiErrorCode = 'NOMINATOR_NOT_FOUND' | 'NOMINEE_MUST_SPECIFY_NOMINATOR';
|
|
4
|
+
|
|
5
|
+
export class ConsentApiError extends Error {
|
|
6
|
+
code: ConsentApiErrorCode;
|
|
7
|
+
constructor(code: ConsentApiErrorCode, message: string) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = 'ConsentApiError';
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
ActivityDetail,
|
|
16
|
+
CaseActionBaseParams,
|
|
17
|
+
CaseHistoryDetail,
|
|
18
|
+
CaseMessage,
|
|
19
|
+
ConsentAction,
|
|
20
|
+
CreateCaseResponse,
|
|
21
|
+
FormData,
|
|
22
|
+
GetCaseDocumentParams,
|
|
23
|
+
GetCaseMessagesParams,
|
|
24
|
+
MessageDocument,
|
|
25
|
+
OtpResponse,
|
|
26
|
+
OtpVerificationResponse,
|
|
27
|
+
Pagination,
|
|
28
|
+
SendCaseMessageParams,
|
|
29
|
+
SubmitDocumentForRequestParams,
|
|
30
|
+
TokenExchangeResponse,
|
|
31
|
+
UploadCaseDocumentParams,
|
|
32
|
+
UploadDocumentResponse,
|
|
33
|
+
UserConsentDetail,
|
|
34
|
+
} from '../lib/types';
|
|
35
|
+
|
|
36
|
+
function buildBaseRequest(organizationId: string, workspaceId: string, authToken?: string): BaseRequest {
|
|
37
|
+
return { organisationUuid: organizationId, workspaceUuid: workspaceId, authToken: authToken || '' };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if an error is an authentication/JWT related error
|
|
42
|
+
*/
|
|
43
|
+
function isAuthError(error: any): boolean {
|
|
44
|
+
const errorMessage = error?.message || '';
|
|
45
|
+
return (
|
|
46
|
+
errorMessage.includes('JWT') ||
|
|
47
|
+
errorMessage.includes('401') ||
|
|
48
|
+
errorMessage.includes('expired') ||
|
|
49
|
+
errorMessage.includes('token')
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Handle server action errors - re-throws auth errors, logs others
|
|
55
|
+
*/
|
|
56
|
+
function handleServerActionError(
|
|
57
|
+
error: any,
|
|
58
|
+
errorContext: string,
|
|
59
|
+
shouldThrow404 = false
|
|
60
|
+
): null {
|
|
61
|
+
// Re-throw auth errors so client can handle refresh
|
|
62
|
+
if (isAuthError(error)) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
console.error(`Error ${errorContext}:`, error);
|
|
66
|
+
if (shouldThrow404 && error.message?.includes('404')) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function getFormDataServer(
|
|
73
|
+
organizationId: string,
|
|
74
|
+
workspaceId: string,
|
|
75
|
+
contact: string,
|
|
76
|
+
authToken?: string,
|
|
77
|
+
useSessionAuth?: boolean,
|
|
78
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>,
|
|
79
|
+
language?: string
|
|
80
|
+
): Promise<FormData | null> {
|
|
81
|
+
try {
|
|
82
|
+
if (!consentClient) {
|
|
83
|
+
throw new Error('Consent client is required');
|
|
84
|
+
}
|
|
85
|
+
const baseRequest = buildBaseRequest(organizationId, workspaceId, authToken);
|
|
86
|
+
|
|
87
|
+
// If useSessionAuth is true (case management), use X-Auth-Token
|
|
88
|
+
// Otherwise (privacy center), use JWT Bearer token
|
|
89
|
+
const result = await consentClient.getFormData(baseRequest, contact, authToken, {
|
|
90
|
+
useSessionAuth: useSessionAuth ?? false, // Default to false for privacy center
|
|
91
|
+
}, language);
|
|
92
|
+
return result as FormData;
|
|
93
|
+
} catch (error: any) {
|
|
94
|
+
return handleServerActionError(error, 'fetching form data', true);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function createCaseRequestServer(
|
|
99
|
+
organizationId: string,
|
|
100
|
+
workspaceId: string,
|
|
101
|
+
data: unknown,
|
|
102
|
+
authToken?: string,
|
|
103
|
+
useSessionAuth?: boolean,
|
|
104
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>
|
|
105
|
+
): Promise<CreateCaseResponse | null> {
|
|
106
|
+
try {
|
|
107
|
+
if (!consentClient) {
|
|
108
|
+
throw new Error('Consent client is required');
|
|
109
|
+
}
|
|
110
|
+
const baseRequest = buildBaseRequest(organizationId, workspaceId, authToken);
|
|
111
|
+
|
|
112
|
+
// If useSessionAuth is true (case management), use X-Auth-Token
|
|
113
|
+
// Otherwise (privacy center), use JWT Bearer token
|
|
114
|
+
const result = await consentClient.createCaseRequest(baseRequest, data, authToken, {
|
|
115
|
+
useSessionAuth: useSessionAuth ?? false, // Default to false for privacy center
|
|
116
|
+
});
|
|
117
|
+
return result as CreateCaseResponse;
|
|
118
|
+
} catch (error: any) {
|
|
119
|
+
return handleServerActionError(error, 'creating case request');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function createOtpServer(
|
|
124
|
+
email: string,
|
|
125
|
+
organizationId: string,
|
|
126
|
+
workspaceId: string,
|
|
127
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>
|
|
128
|
+
): Promise<OtpResponse> {
|
|
129
|
+
try {
|
|
130
|
+
if (!consentClient) {
|
|
131
|
+
throw new Error('Consent client is required');
|
|
132
|
+
}
|
|
133
|
+
const result = await consentClient.createOtp(organizationId, workspaceId, email);
|
|
134
|
+
return result as OtpResponse;
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error('Error creating OTP:', error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function verifyOtpServer(
|
|
142
|
+
otpId: string,
|
|
143
|
+
otp: string,
|
|
144
|
+
organizationId: string,
|
|
145
|
+
workspaceId: string,
|
|
146
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>
|
|
147
|
+
): Promise<OtpVerificationResponse> {
|
|
148
|
+
try {
|
|
149
|
+
if (!consentClient) {
|
|
150
|
+
throw new Error('Consent client is required');
|
|
151
|
+
}
|
|
152
|
+
const result = await consentClient.verifyOtp(organizationId, workspaceId, otpId, otp);
|
|
153
|
+
const response = result as OtpVerificationResponse;
|
|
154
|
+
return response;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error('Error verifying OTP:', error);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function exchangeTokenServer(
|
|
162
|
+
token: string,
|
|
163
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>
|
|
164
|
+
): Promise<TokenExchangeResponse> {
|
|
165
|
+
try {
|
|
166
|
+
if (!consentClient) {
|
|
167
|
+
throw new Error('Consent client is required');
|
|
168
|
+
}
|
|
169
|
+
const result = await consentClient.exchangeToken(token);
|
|
170
|
+
return result as TokenExchangeResponse;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error('Error exchanging token:', error);
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function refreshOtpTokenServer(
|
|
178
|
+
organizationId: string,
|
|
179
|
+
workspaceId: string,
|
|
180
|
+
refreshToken: string,
|
|
181
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>
|
|
182
|
+
): Promise<OtpResponse | null> {
|
|
183
|
+
// Validate refreshToken before making API call
|
|
184
|
+
if (!refreshToken || typeof refreshToken !== 'string' || refreshToken.trim() === '') {
|
|
185
|
+
console.error('[Token Refresh] Invalid refresh token provided');
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Validate organizationId and workspaceId
|
|
190
|
+
if (!organizationId || !workspaceId) {
|
|
191
|
+
console.error('[Token Refresh] Missing organizationId or workspaceId');
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
if (!consentClient) {
|
|
197
|
+
throw new Error('Consent client is required');
|
|
198
|
+
}
|
|
199
|
+
const result = await consentClient.refreshOtpToken(
|
|
200
|
+
organizationId,
|
|
201
|
+
workspaceId,
|
|
202
|
+
refreshToken
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const response = result as OtpResponse;
|
|
206
|
+
// Check if the response indicates failure
|
|
207
|
+
if (response && response.success === false) {
|
|
208
|
+
// Return null to indicate refresh failed
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return response;
|
|
212
|
+
} catch (error: any) {
|
|
213
|
+
// Check if this is an expired refresh token error (expected scenario)
|
|
214
|
+
const errorMessage = error?.message || '';
|
|
215
|
+
const isExpiredTokenError =
|
|
216
|
+
errorMessage.includes('expired') ||
|
|
217
|
+
errorMessage.includes('Invalid refresh token') ||
|
|
218
|
+
errorMessage.includes('Refresh token') ||
|
|
219
|
+
errorMessage.includes('revoked');
|
|
220
|
+
|
|
221
|
+
// For expired/revoked tokens, return null gracefully (don't log as error)
|
|
222
|
+
if (isExpiredTokenError) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// For other errors (network, etc.), log and re-throw
|
|
227
|
+
console.error('Error refreshing token:', error);
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function fetchProductsServer(params: {
|
|
233
|
+
organizationId: string;
|
|
234
|
+
workspaceId: string;
|
|
235
|
+
skip?: number;
|
|
236
|
+
limit?: number;
|
|
237
|
+
authToken?: string;
|
|
238
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>;
|
|
239
|
+
}): Promise<Array<{ uuid: string; name: string; description?: string }> | null> {
|
|
240
|
+
try {
|
|
241
|
+
if (!params.consentClient) {
|
|
242
|
+
throw new Error('Consent client is required');
|
|
243
|
+
}
|
|
244
|
+
// Privacy center endpoints use JWT Bearer tokens, not session-based auth
|
|
245
|
+
const baseRequest = buildBaseRequest(params.organizationId, params.workspaceId, params.authToken);
|
|
246
|
+
|
|
247
|
+
const result = await params.consentClient.getProducts(
|
|
248
|
+
baseRequest,
|
|
249
|
+
params.skip || 0,
|
|
250
|
+
params.limit || 100 // Get more products for filter dropdown
|
|
251
|
+
);
|
|
252
|
+
return (result as { data?: Array<{ uuid: string; name: string; description?: string }> })?.data || [];
|
|
253
|
+
} catch (error: any) {
|
|
254
|
+
return handleServerActionError(error, 'fetching products');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export async function fetchUserConsentsServer(params: {
|
|
259
|
+
organizationId: string;
|
|
260
|
+
workspaceId: string;
|
|
261
|
+
contact: string;
|
|
262
|
+
offset?: number;
|
|
263
|
+
limit?: number;
|
|
264
|
+
search?: string;
|
|
265
|
+
status?: string;
|
|
266
|
+
product_uuid?: string;
|
|
267
|
+
language?: string;
|
|
268
|
+
authToken?: string;
|
|
269
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>;
|
|
270
|
+
}): Promise<UserConsentDetail | null> {
|
|
271
|
+
try {
|
|
272
|
+
if (!params.consentClient) {
|
|
273
|
+
throw new Error('Consent client is required');
|
|
274
|
+
}
|
|
275
|
+
// Privacy center endpoints use JWT Bearer tokens, not session-based auth
|
|
276
|
+
const baseRequest = buildBaseRequest(params.organizationId, params.workspaceId, params.authToken);
|
|
277
|
+
|
|
278
|
+
const result = await params.consentClient.getUserConsents(
|
|
279
|
+
baseRequest,
|
|
280
|
+
params.contact,
|
|
281
|
+
params.offset,
|
|
282
|
+
params.limit,
|
|
283
|
+
params.search,
|
|
284
|
+
params.status,
|
|
285
|
+
params.product_uuid,
|
|
286
|
+
params.language,
|
|
287
|
+
params.authToken
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
return result as UserConsentDetail;
|
|
291
|
+
} catch (error: any) {
|
|
292
|
+
return handleServerActionError(error, 'fetching user consents');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export async function manageConsentServer(params: {
|
|
297
|
+
organizationId: string;
|
|
298
|
+
workspaceId: string;
|
|
299
|
+
purposeId: string;
|
|
300
|
+
contact: string;
|
|
301
|
+
action: ConsentAction;
|
|
302
|
+
authToken?: string;
|
|
303
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>;
|
|
304
|
+
nominatorContact?: string;
|
|
305
|
+
dataElementUuids?: string[];
|
|
306
|
+
}): Promise<boolean | null> {
|
|
307
|
+
try {
|
|
308
|
+
if (!params.consentClient) {
|
|
309
|
+
throw new Error('Consent client is required');
|
|
310
|
+
}
|
|
311
|
+
// Privacy center endpoints use JWT Bearer tokens, not session-based auth
|
|
312
|
+
const baseRequest = buildBaseRequest(params.organizationId, params.workspaceId, params.authToken);
|
|
313
|
+
|
|
314
|
+
const result = await params.consentClient.manageConsent(
|
|
315
|
+
baseRequest,
|
|
316
|
+
params.purposeId,
|
|
317
|
+
params.contact,
|
|
318
|
+
params.action,
|
|
319
|
+
params.authToken,
|
|
320
|
+
undefined,
|
|
321
|
+
params.nominatorContact,
|
|
322
|
+
params.dataElementUuids
|
|
323
|
+
);
|
|
324
|
+
return (result as { success: boolean })?.success ?? null;
|
|
325
|
+
} catch (error: any) {
|
|
326
|
+
// Normalize nominator-specific errors into stable error codes
|
|
327
|
+
const errorMsg = error?.message || '';
|
|
328
|
+
if (errorMsg.includes('nominator_not_found')) {
|
|
329
|
+
throw new ConsentApiError('NOMINATOR_NOT_FOUND', errorMsg);
|
|
330
|
+
}
|
|
331
|
+
if (errorMsg.includes('nominee_must_specify_nominator')) {
|
|
332
|
+
throw new ConsentApiError('NOMINEE_MUST_SPECIFY_NOMINATOR', errorMsg);
|
|
333
|
+
}
|
|
334
|
+
return handleServerActionError(error, `${params.action} consent`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export async function fetchActivitiesServer(params: {
|
|
339
|
+
organizationId: string;
|
|
340
|
+
workspaceId: string;
|
|
341
|
+
offset?: number;
|
|
342
|
+
limit?: number;
|
|
343
|
+
language?: string;
|
|
344
|
+
authToken?: string;
|
|
345
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>;
|
|
346
|
+
}): Promise<ActivityDetail | null> {
|
|
347
|
+
try {
|
|
348
|
+
if (!params.consentClient) {
|
|
349
|
+
throw new Error('Consent client is required');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Privacy center endpoints use JWT Bearer tokens, not session-based auth
|
|
353
|
+
const baseRequest = buildBaseRequest(params.organizationId, params.workspaceId, params.authToken);
|
|
354
|
+
|
|
355
|
+
const result = await params.consentClient.getActivities(
|
|
356
|
+
baseRequest,
|
|
357
|
+
params.offset,
|
|
358
|
+
params.limit,
|
|
359
|
+
params.language,
|
|
360
|
+
params.authToken
|
|
361
|
+
);
|
|
362
|
+
return result as ActivityDetail;
|
|
363
|
+
} catch (error: any) {
|
|
364
|
+
return handleServerActionError(error, 'fetching activities');
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export async function fetchCaseHistoryServer(params: {
|
|
369
|
+
organizationId: string;
|
|
370
|
+
workspaceId: string;
|
|
371
|
+
contact: string;
|
|
372
|
+
offset?: number;
|
|
373
|
+
limit?: number;
|
|
374
|
+
language?: string;
|
|
375
|
+
authToken?: string;
|
|
376
|
+
consentClient?: ReturnType<typeof import('./client').createConsentClient>;
|
|
377
|
+
}): Promise<CaseHistoryDetail | null> {
|
|
378
|
+
try {
|
|
379
|
+
if (!params.consentClient) {
|
|
380
|
+
throw new Error('Consent client is required');
|
|
381
|
+
}
|
|
382
|
+
// Privacy center endpoints use JWT Bearer tokens, not session-based auth
|
|
383
|
+
const baseRequest = buildBaseRequest(params.organizationId, params.workspaceId, params.authToken);
|
|
384
|
+
|
|
385
|
+
const result = await params.consentClient.getCaseHistory(
|
|
386
|
+
baseRequest,
|
|
387
|
+
params.contact,
|
|
388
|
+
params.offset,
|
|
389
|
+
params.limit,
|
|
390
|
+
params.language,
|
|
391
|
+
params.authToken
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
if (Array.isArray(result)) {
|
|
395
|
+
return {
|
|
396
|
+
data: result,
|
|
397
|
+
pagination: {
|
|
398
|
+
total_count: result.length,
|
|
399
|
+
offset: params.offset || 0,
|
|
400
|
+
limit: params.limit || 10
|
|
401
|
+
},
|
|
402
|
+
} as CaseHistoryDetail;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (result && typeof result === 'object' && 'data' in result) {
|
|
406
|
+
const resultData = result as { data?: unknown[]; pagination?: Pagination };
|
|
407
|
+
return {
|
|
408
|
+
data: resultData.data || [],
|
|
409
|
+
pagination: resultData.pagination || {
|
|
410
|
+
total_count: resultData.data?.length || 0,
|
|
411
|
+
offset: params.offset || 0,
|
|
412
|
+
limit: params.limit || 10
|
|
413
|
+
},
|
|
414
|
+
} as CaseHistoryDetail;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return {
|
|
418
|
+
data: [],
|
|
419
|
+
pagination: {
|
|
420
|
+
total_count: 0,
|
|
421
|
+
offset: params.offset || 0,
|
|
422
|
+
limit: params.limit || 10
|
|
423
|
+
},
|
|
424
|
+
} as CaseHistoryDetail;
|
|
425
|
+
} catch (error: any) {
|
|
426
|
+
return handleServerActionError(error, 'fetching case history');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ─── Case Communication ──────────────────────────────────────────────────────
|
|
431
|
+
|
|
432
|
+
type ConsentClient = NonNullable<CaseActionBaseParams['consentClient']>;
|
|
433
|
+
|
|
434
|
+
async function runCaseAction<T>(
|
|
435
|
+
params: CaseActionBaseParams,
|
|
436
|
+
label: string,
|
|
437
|
+
fn: (client: ConsentClient, baseRequest: BaseRequest) => Promise<T>
|
|
438
|
+
): Promise<T | null> {
|
|
439
|
+
try {
|
|
440
|
+
if (!params.consentClient) throw new Error('Consent client is required');
|
|
441
|
+
const baseRequest = buildBaseRequest(params.organizationId, params.workspaceId, params.authToken);
|
|
442
|
+
return await fn(params.consentClient, baseRequest);
|
|
443
|
+
} catch (error: any) {
|
|
444
|
+
return handleServerActionError(error, label);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export async function getCaseMessagesServer(params: GetCaseMessagesParams): Promise<CaseMessage[] | null> {
|
|
449
|
+
return runCaseAction(params, 'fetching case messages', (client, base) =>
|
|
450
|
+
client.getCaseMessages(base, params.caseUuid, params.authToken)
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export async function sendCaseMessageServer(params: SendCaseMessageParams): Promise<CaseMessage | null> {
|
|
455
|
+
return runCaseAction(params, 'sending case message', (client, base) =>
|
|
456
|
+
client.sendCaseMessage(base, params.caseUuid, params.body, params.documentUuids, params.authToken)
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export async function uploadCaseDocumentServer(params: UploadCaseDocumentParams): Promise<UploadDocumentResponse | null> {
|
|
461
|
+
return runCaseAction(params, 'uploading case document', (client, base) =>
|
|
462
|
+
client.uploadCaseDocument(base, params.caseUuid, params.file, params.authToken)
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export async function submitDocumentForRequestServer(params: SubmitDocumentForRequestParams): Promise<CaseMessage | null> {
|
|
467
|
+
return runCaseAction(params, 'submitting document for request', (client, base) =>
|
|
468
|
+
client.submitDocumentForRequest(base, params.caseUuid, params.requestEventUuid, params.documentUuid, params.body, params.authToken)
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export async function getCaseDocumentServer(params: GetCaseDocumentParams): Promise<MessageDocument | null> {
|
|
473
|
+
return runCaseAction(params, 'fetching case document', (client, base) =>
|
|
474
|
+
client.getCaseDocument(base, params.caseUuid, params.documentUuid, params.authToken)
|
|
475
|
+
);
|
|
476
|
+
}
|