@redacto.io/consent-sdk-react 5.2.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.turbo/turbo-build.log +24 -0
  2. package/CHANGELOG.md +12 -0
  3. package/dist/index.d.mts +24 -1
  4. package/dist/index.d.ts +24 -1
  5. package/dist/index.js +149 -206
  6. package/dist/index.mjs +148 -206
  7. package/dist/privacy-center.d.mts +178 -39
  8. package/dist/privacy-center.d.ts +178 -39
  9. package/dist/privacy-center.js +10534 -6795
  10. package/dist/privacy-center.mjs +7922 -4181
  11. package/package.json +1 -1
  12. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +16 -20
  13. package/src/RedactoNoticeConsent/api/index.ts +21 -103
  14. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +5 -4
  15. package/src/RedactoNoticeConsentInline/api/index.ts +64 -117
  16. package/src/RedactoPrivacyCenter/NotificationsPage.tsx +174 -0
  17. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +3 -0
  18. package/src/RedactoPrivacyCenter/api/actions.ts +136 -8
  19. package/src/RedactoPrivacyCenter/api/client.ts +176 -15
  20. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +722 -273
  21. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +187 -0
  22. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +65 -165
  23. package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +179 -0
  24. package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +318 -0
  25. package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +333 -0
  26. package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +102 -0
  27. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +6 -2
  28. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +15 -0
  29. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +8 -5
  30. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +160 -0
  31. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +18 -0
  32. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +54 -0
  33. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +57 -0
  34. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +19 -0
  35. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +92 -0
  36. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +20 -0
  37. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +58 -0
  38. package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +10 -0
  39. package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +112 -0
  40. package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +27 -0
  41. package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +105 -55
  42. package/src/RedactoPrivacyCenter/components/types.ts +2 -5
  43. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +2 -2
  44. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +21 -1
  45. package/src/RedactoPrivacyCenter/lib/api.ts +147 -28
  46. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +4 -2
  47. package/src/RedactoPrivacyCenter/lib/constants.ts +78 -1
  48. package/src/RedactoPrivacyCenter/lib/types.ts +205 -36
  49. package/src/RedactoPrivacyCenter/lib/utils.ts +3 -0
  50. package/src/RedactoPrivacyCenter/locales/as/translation.json +12 -1
  51. package/src/RedactoPrivacyCenter/locales/bho/translation.json +12 -1
  52. package/src/RedactoPrivacyCenter/locales/bn/translation.json +12 -1
  53. package/src/RedactoPrivacyCenter/locales/brx/translation.json +12 -1
  54. package/src/RedactoPrivacyCenter/locales/doi/translation.json +12 -1
  55. package/src/RedactoPrivacyCenter/locales/en/translation.json +42 -1
  56. package/src/RedactoPrivacyCenter/locales/gom/translation.json +12 -1
  57. package/src/RedactoPrivacyCenter/locales/gu/translation.json +12 -1
  58. package/src/RedactoPrivacyCenter/locales/hi/translation.json +15 -1
  59. package/src/RedactoPrivacyCenter/locales/kn/translation.json +12 -1
  60. package/src/RedactoPrivacyCenter/locales/ks/translation.json +12 -1
  61. package/src/RedactoPrivacyCenter/locales/mai/translation.json +12 -1
  62. package/src/RedactoPrivacyCenter/locales/ml/translation.json +12 -1
  63. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +12 -1
  64. package/src/RedactoPrivacyCenter/locales/mr/translation.json +12 -1
  65. package/src/RedactoPrivacyCenter/locales/ne/translation.json +12 -1
  66. package/src/RedactoPrivacyCenter/locales/or/translation.json +12 -1
  67. package/src/RedactoPrivacyCenter/locales/pa/translation.json +12 -1
  68. package/src/RedactoPrivacyCenter/locales/sa/translation.json +12 -1
  69. package/src/RedactoPrivacyCenter/locales/sat/translation.json +12 -1
  70. package/src/RedactoPrivacyCenter/locales/sd/translation.json +12 -1
  71. package/src/RedactoPrivacyCenter/locales/ta/translation.json +12 -1
  72. package/src/RedactoPrivacyCenter/locales/te/translation.json +12 -1
  73. package/src/RedactoPrivacyCenter/locales/ur/translation.json +12 -1
  74. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1027 -0
  75. package/src/RedactoPrivacyCenter/styles/variables.css +5 -0
  76. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +36 -16
  77. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +4 -12
  78. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +1 -1
  79. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +23 -1
  80. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +51 -5
  81. package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +2 -4
  82. package/src/index.ts +5 -0
  83. package/src/privacy-center.ts +8 -3
  84. package/src/shared/api-errors.ts +171 -0
@@ -0,0 +1,24 @@
1
+
2
+ > @redacto.io/consent-sdk-react@5.3.0 build /Users/sadanmianredacto/Developer/redacto/consent-sdk/packages/consent-sdk-react
3
+ > tsup
4
+
5
+ CLI Building entry: {"index":"src/index.ts","privacy-center":"src/privacy-center.ts"}
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /Users/sadanmianredacto/Developer/redacto/consent-sdk/packages/consent-sdk-react/tsup.config.ts
9
+ CLI Target: es2019
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ ESM dist/index.mjs 225.25 KB
14
+ ESM dist/privacy-center.mjs 1.98 MB
15
+ ESM ⚡️ Build success in 67ms
16
+ CJS dist/index.js 234.39 KB
17
+ CJS dist/privacy-center.js 2.02 MB
18
+ CJS ⚡️ Build success in 66ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 2662ms
21
+ DTS dist/index.d.mts 6.12 KB
22
+ DTS dist/privacy-center.d.mts 27.06 KB
23
+ DTS dist/index.d.ts 6.12 KB
24
+ DTS dist/privacy-center.d.ts 27.06 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @redacto.io/consent-sdk-react
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - update Manage Consent
8
+
9
+ ## 5.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - notification hub
14
+
3
15
  ## 5.2.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -146,4 +146,27 @@ declare const RedactoConsentInline: react.MemoExoticComponent<{
146
146
 
147
147
  declare const DigiLockerCallback: react__default.FC<DigiLockerCallbackProps>;
148
148
 
149
- export { type ConsentFlowState, DigiLockerCallback, type DigiLockerCallbackProps, type GuardianVerificationErrorCode, RedactoNoticeConsent, RedactoConsentInline as RedactoNoticeConsentInline };
149
+ /**
150
+ * Shared API error handling for the consent-sdk-react package.
151
+ *
152
+ * The backend (consent-server) owns the user-facing copy. Each error
153
+ * response carries:
154
+ * - `message`: user-safe text the SDK displays verbatim
155
+ * - `error_code`: stable identifier for programmatic branching
156
+ *
157
+ * The SDK never re-translates a code into a message. To change wording,
158
+ * update the server titles registry -- no SDK release required.
159
+ */
160
+ type ApiErrorCode = "INVALID_TOKEN" | "TOKEN_TENANT_MISMATCH" | "UNAUTHORIZED" | "USER_NOT_FOUND" | "USER_EMAIL_MISMATCH" | "USER_MOBILE_MISMATCH" | "USER_CONTACT_MISMATCH" | "NO_IDENTIFIER_PROVIDED" | "INVALID_PAYLOAD" | "VALIDATION_ERROR" | "NOTICE_NOT_FOUND" | "NOTICE_CONFIGURATION_NOT_FOUND" | "NOTICE_STILL_IN_DRAFT" | "CONSENT_ALREADY_PROVIDED" | "PURPOSE_NOT_FOUND" | "INVALID_PURPOSE" | "INVALID_DATA_ELEMENTS" | "MISSING_PURPOSE" | "MISSING_DATA_ELEMENTS" | "REQUIRED_DATA_ELEMENT_NOT_ENABLED" | "AUDIO_NOT_FOUND" | "INVALID_LANGUAGE" | "VERIFICATION_FAILED" | "VERIFICATION_EXPIRED" | "GUARDIAN_INFO_NOT_FOUND" | "GUARDIAN_SESSION_INVALID" | "SESSION_EXPIRED" | "INTERNAL_ERROR";
161
+ type ApiErrorCodeLike = ApiErrorCode | (string & {});
162
+ declare class ApiError extends Error {
163
+ readonly status: number;
164
+ readonly code?: ApiErrorCodeLike;
165
+ constructor(opts: {
166
+ status: number;
167
+ code?: ApiErrorCodeLike;
168
+ message: string;
169
+ });
170
+ }
171
+
172
+ export { ApiError, type ApiErrorCode, type ConsentFlowState, DigiLockerCallback, type DigiLockerCallbackProps, type GuardianVerificationErrorCode, RedactoNoticeConsent, RedactoConsentInline as RedactoNoticeConsentInline };
package/dist/index.d.ts CHANGED
@@ -146,4 +146,27 @@ declare const RedactoConsentInline: react.MemoExoticComponent<{
146
146
 
147
147
  declare const DigiLockerCallback: react__default.FC<DigiLockerCallbackProps>;
148
148
 
149
- export { type ConsentFlowState, DigiLockerCallback, type DigiLockerCallbackProps, type GuardianVerificationErrorCode, RedactoNoticeConsent, RedactoConsentInline as RedactoNoticeConsentInline };
149
+ /**
150
+ * Shared API error handling for the consent-sdk-react package.
151
+ *
152
+ * The backend (consent-server) owns the user-facing copy. Each error
153
+ * response carries:
154
+ * - `message`: user-safe text the SDK displays verbatim
155
+ * - `error_code`: stable identifier for programmatic branching
156
+ *
157
+ * The SDK never re-translates a code into a message. To change wording,
158
+ * update the server titles registry -- no SDK release required.
159
+ */
160
+ type ApiErrorCode = "INVALID_TOKEN" | "TOKEN_TENANT_MISMATCH" | "UNAUTHORIZED" | "USER_NOT_FOUND" | "USER_EMAIL_MISMATCH" | "USER_MOBILE_MISMATCH" | "USER_CONTACT_MISMATCH" | "NO_IDENTIFIER_PROVIDED" | "INVALID_PAYLOAD" | "VALIDATION_ERROR" | "NOTICE_NOT_FOUND" | "NOTICE_CONFIGURATION_NOT_FOUND" | "NOTICE_STILL_IN_DRAFT" | "CONSENT_ALREADY_PROVIDED" | "PURPOSE_NOT_FOUND" | "INVALID_PURPOSE" | "INVALID_DATA_ELEMENTS" | "MISSING_PURPOSE" | "MISSING_DATA_ELEMENTS" | "REQUIRED_DATA_ELEMENT_NOT_ENABLED" | "AUDIO_NOT_FOUND" | "INVALID_LANGUAGE" | "VERIFICATION_FAILED" | "VERIFICATION_EXPIRED" | "GUARDIAN_INFO_NOT_FOUND" | "GUARDIAN_SESSION_INVALID" | "SESSION_EXPIRED" | "INTERNAL_ERROR";
161
+ type ApiErrorCodeLike = ApiErrorCode | (string & {});
162
+ declare class ApiError extends Error {
163
+ readonly status: number;
164
+ readonly code?: ApiErrorCodeLike;
165
+ constructor(opts: {
166
+ status: number;
167
+ code?: ApiErrorCodeLike;
168
+ message: string;
169
+ });
170
+ }
171
+
172
+ export { ApiError, type ApiErrorCode, type ConsentFlowState, DigiLockerCallback, type DigiLockerCallbackProps, type GuardianVerificationErrorCode, RedactoNoticeConsent, RedactoConsentInline as RedactoNoticeConsentInline };
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ ApiError: () => ApiError,
23
24
  DigiLockerCallback: () => DigiLockerCallback,
24
25
  RedactoNoticeConsent: () => RedactoNoticeConsent,
25
26
  RedactoNoticeConsentInline: () => RedactoConsentInline
@@ -31,6 +32,64 @@ var import_react2 = require("react");
31
32
 
32
33
  // src/RedactoNoticeConsent/api/index.ts
33
34
  var import_jwt_decode = require("jwt-decode");
35
+
36
+ // src/shared/api-errors.ts
37
+ var ApiError = class extends Error {
38
+ constructor(opts) {
39
+ super(opts.message);
40
+ this.name = "ApiError";
41
+ this.status = opts.status;
42
+ this.code = opts.code;
43
+ }
44
+ };
45
+ function statusFallback(status) {
46
+ if (status === 401) {
47
+ return "Your session has expired. Please request a new access link.";
48
+ }
49
+ if (status === 403) {
50
+ return "You do not have access to this resource.";
51
+ }
52
+ if (status >= 500) {
53
+ return "Something went wrong on our end. Please try again later.";
54
+ }
55
+ return void 0;
56
+ }
57
+ function extractFromDetail(detail) {
58
+ var _a;
59
+ if (typeof detail === "string") {
60
+ return { message: detail };
61
+ }
62
+ if (Array.isArray(detail)) {
63
+ return {};
64
+ }
65
+ if (detail && typeof detail === "object") {
66
+ const obj = detail;
67
+ return { message: (_a = obj.message) != null ? _a : obj.detail, code: obj.error_code };
68
+ }
69
+ return {};
70
+ }
71
+ async function parseApiError(response, fallbackMessage) {
72
+ var _a, _b, _c, _d;
73
+ let body;
74
+ let parsedBody = false;
75
+ try {
76
+ body = await response.json();
77
+ parsedBody = true;
78
+ } catch {
79
+ body = void 0;
80
+ }
81
+ const fromDetail = extractFromDetail(body == null ? void 0 : body.detail);
82
+ const serverMessage = (_a = body == null ? void 0 : body.message) != null ? _a : fromDetail.message;
83
+ const message = (_b = serverMessage != null ? serverMessage : parsedBody ? statusFallback(response.status) : void 0) != null ? _b : fallbackMessage;
84
+ const code = (_d = (_c = body == null ? void 0 : body.error_code) != null ? _c : fromDetail.code) != null ? _d : void 0;
85
+ return new ApiError({
86
+ status: response.status,
87
+ code,
88
+ message
89
+ });
90
+ }
91
+
92
+ // src/RedactoNoticeConsent/api/index.ts
34
93
  var BASE_URL = "https://api.redacto.io/consent";
35
94
  var apiCache = /* @__PURE__ */ new Map();
36
95
  var CACHE_TTL = 5 * 60 * 1e3;
@@ -106,21 +165,10 @@ var fetchConsentContent = async ({
106
165
  signal
107
166
  });
108
167
  if (!response.ok) {
109
- let errorMessage = `Failed to fetch consent content: ${response.status} ${response.statusText}`;
110
- if (response.status === 401) {
111
- errorMessage = "Unauthorized: Invalid or expired token";
112
- } else if (response.status === 403) {
113
- errorMessage = "Forbidden: Access denied";
114
- } else if (response.status === 404) {
115
- errorMessage = "Notice not found";
116
- } else if (response.status === 409) {
117
- errorMessage = "User has already provided consent";
118
- } else if (response.status >= 500) {
119
- errorMessage = "Server error: Please try again later";
120
- }
121
- const error = new Error(errorMessage);
122
- error.status = response.status;
123
- throw error;
168
+ throw await parseApiError(
169
+ response,
170
+ "Could not load the consent notice. Please try again."
171
+ );
124
172
  }
125
173
  const data = await response.json();
126
174
  if (validate_against === "all" && !specific_uuid) {
@@ -190,26 +238,10 @@ var submitConsentEvent = async ({
190
238
  }
191
239
  );
192
240
  if (!response.ok) {
193
- let errorMessage = `Failed to submit consent: ${response.status} ${response.statusText}`;
194
- if (response.status === 400) {
195
- try {
196
- const errorData = await response.json();
197
- errorMessage = errorData.message || "Invalid request data";
198
- } catch {
199
- errorMessage = "Invalid request data";
200
- }
201
- } else if (response.status === 401) {
202
- errorMessage = "Unauthorized: Invalid or expired token";
203
- } else if (response.status === 403) {
204
- errorMessage = "Forbidden: Access denied";
205
- } else if (response.status === 404) {
206
- errorMessage = "Notice not found";
207
- } else if (response.status >= 500) {
208
- errorMessage = "Server error: Please try again later";
209
- }
210
- const error = new Error(errorMessage);
211
- error.status = response.status;
212
- throw error;
241
+ throw await parseApiError(
242
+ response,
243
+ "Could not submit your consent. Please try again."
244
+ );
213
245
  }
214
246
  apiCache.clear();
215
247
  };
@@ -242,19 +274,10 @@ var fetchTTSAudioUrls = async ({
242
274
  signal
243
275
  });
244
276
  if (!response.ok) {
245
- let errorMessage = `Failed to fetch TTS audio URLs: ${response.status} ${response.statusText}`;
246
- if (response.status === 401) {
247
- errorMessage = "Unauthorized: Invalid or expired token";
248
- } else if (response.status === 403) {
249
- errorMessage = "Forbidden: Access denied";
250
- } else if (response.status === 404) {
251
- errorMessage = "Notice or audio not found";
252
- } else if (response.status >= 500) {
253
- errorMessage = "Server error: Please try again later";
254
- }
255
- const error = new Error(errorMessage);
256
- error.status = response.status;
257
- throw error;
277
+ throw await parseApiError(
278
+ response,
279
+ "Could not load audio narration. Please try again."
280
+ );
258
281
  }
259
282
  const data = await response.json();
260
283
  return data;
@@ -316,31 +339,10 @@ var initiateGuardianVerification = async ({
316
339
  }
317
340
  );
318
341
  if (!response.ok) {
319
- let errorMessage = `Failed to initiate verification: ${response.status} ${response.statusText}`;
320
- if (response.status === 400) {
321
- try {
322
- const errorData = await response.json();
323
- errorMessage = errorData.message || "Invalid request data";
324
- } catch {
325
- errorMessage = "Invalid request data";
326
- }
327
- } else if (response.status === 401) {
328
- errorMessage = "Unauthorized: Invalid or expired token";
329
- } else if (response.status === 404) {
330
- errorMessage = "Organization or workspace not found";
331
- } else if (response.status === 422) {
332
- try {
333
- const errorData = await response.json();
334
- errorMessage = errorData.message || "Validation error: Please check your input";
335
- } catch {
336
- errorMessage = "Validation error: Please check your input";
337
- }
338
- } else if (response.status >= 500) {
339
- errorMessage = "Server error: Please try again later";
340
- }
341
- const error = new Error(errorMessage);
342
- error.status = response.status;
343
- throw error;
342
+ throw await parseApiError(
343
+ response,
344
+ "Could not start guardian verification. Please try again."
345
+ );
344
346
  }
345
347
  const responseData = await response.json();
346
348
  const detail = responseData.detail || responseData;
@@ -374,7 +376,7 @@ var verifyGuardianStatus = async ({
374
376
  sessionToken,
375
377
  signal
376
378
  }) => {
377
- var _a, _b, _c, _d, _e, _f, _g, _h;
379
+ var _a, _b, _c, _d, _e, _f, _g;
378
380
  if (!accessToken || !sessionToken) {
379
381
  throw new Error("accessToken and sessionToken are required");
380
382
  }
@@ -402,37 +404,21 @@ var verifyGuardianStatus = async ({
402
404
  }
403
405
  );
404
406
  if (!response.ok) {
405
- let errorMessage = `Failed to check verification status: ${response.status} ${response.statusText}`;
406
- if (response.status === 400) {
407
- try {
408
- const errorData = await response.json();
409
- errorMessage = errorData.message || ((_a = errorData.detail) == null ? void 0 : _a.message) || "Invalid session token";
410
- } catch {
411
- errorMessage = "Invalid session token";
412
- }
413
- } else if (response.status === 401) {
414
- errorMessage = "Unauthorized: Invalid or expired token";
415
- } else if (response.status === 404) {
416
- errorMessage = "Verification session not found or expired. Please restart the verification process.";
417
- } else if (response.status === 410) {
418
- errorMessage = "Verification session has expired. Please restart the verification process.";
419
- } else if (response.status >= 500) {
420
- errorMessage = "Server error: Please try again later";
421
- }
422
- const error = new Error(errorMessage);
423
- error.status = response.status;
424
- throw error;
407
+ throw await parseApiError(
408
+ response,
409
+ "Could not check verification status. Please try again."
410
+ );
425
411
  }
426
412
  const responseData = await response.json();
427
413
  const detail = responseData.detail || responseData;
428
414
  return {
429
- status: (_b = detail.status) != null ? _b : "in_progress",
430
- guardian_info_uuid: (_c = detail.guardian_info_uuid) != null ? _c : null,
431
- verification_reference: (_d = detail.verification_reference) != null ? _d : null,
432
- guardian_details: (_e = detail.guardian_details) != null ? _e : null,
433
- error: (_f = detail.error) != null ? _f : null,
434
- error_code: (_g = detail.error_code) != null ? _g : null,
435
- can_retry: (_h = detail.can_retry) != null ? _h : true
415
+ status: (_a = detail.status) != null ? _a : "in_progress",
416
+ guardian_info_uuid: (_b = detail.guardian_info_uuid) != null ? _b : null,
417
+ verification_reference: (_c = detail.verification_reference) != null ? _c : null,
418
+ guardian_details: (_d = detail.guardian_details) != null ? _d : null,
419
+ error: (_e = detail.error) != null ? _e : null,
420
+ error_code: (_f = detail.error_code) != null ? _f : null,
421
+ can_retry: (_g = detail.can_retry) != null ? _g : true
436
422
  };
437
423
  };
438
424
 
@@ -2929,7 +2915,7 @@ var RedactoNoticeConsent = ({
2929
2915
  return;
2930
2916
  }
2931
2917
  const err = error;
2932
- const message = err.status === 500 ? "An error occurred while submitting your consent. Please try again later." : err.message || "Failed to submit consent. Please try again.";
2918
+ const message = err.message || "Failed to submit consent. Please try again.";
2933
2919
  setErrorMessage(message);
2934
2920
  onError == null ? void 0 : onError(error);
2935
2921
  } finally {
@@ -3351,20 +3337,12 @@ var RedactoNoticeConsent = ({
3351
3337
  }, []);
3352
3338
  const availableLanguages = (0, import_react2.useMemo)(() => {
3353
3339
  if (!content) return [language];
3354
- const languages = ["English"];
3340
+ const pinned = ["English"];
3355
3341
  if (content.default_language && content.default_language !== "English" && content.default_language !== "en") {
3356
- languages.push(content.default_language);
3342
+ pinned.push(content.default_language);
3357
3343
  }
3358
- if (content.supported_languages_and_translations) {
3359
- Object.keys(content.supported_languages_and_translations).forEach(
3360
- (lang) => {
3361
- if (!languages.includes(lang)) {
3362
- languages.push(lang);
3363
- }
3364
- }
3365
- );
3366
- }
3367
- return languages;
3344
+ const rest = content.supported_languages_and_translations ? Object.keys(content.supported_languages_and_translations).filter((lang) => !pinned.includes(lang)).sort((a, b) => a.localeCompare(b, "en")) : [];
3345
+ return [...pinned, ...rest];
3368
3346
  }, [content, language]);
3369
3347
  const getLanguageCode = (0, import_react2.useCallback)(
3370
3348
  (displayLanguage) => {
@@ -4609,40 +4587,27 @@ var fetchConsentContent2 = async ({
4609
4587
  baseUrl,
4610
4588
  specific_uuid
4611
4589
  }) => {
4612
- try {
4613
- const apiBaseUrl = baseUrl || BASE_URL2;
4614
- const url = new URL(
4615
- `${apiBaseUrl}/public/organisations/${org_uuid}/workspaces/${workspace_uuid}/notices/get-notice/${notice_uuid}`
4616
- );
4617
- if (specific_uuid) {
4618
- url.searchParams.append("specific_uuid", specific_uuid);
4619
- }
4620
- const response = await fetch(url.toString(), {
4621
- method: "GET",
4622
- headers: {
4623
- "Content-Type": "application/json"
4624
- }
4625
- });
4626
- if (response.status === 401) {
4627
- const error = new Error("Unauthorized");
4628
- error.status = 401;
4629
- throw error;
4630
- }
4631
- if (response.status === 409) {
4632
- const error = new Error("User has already provided consent");
4633
- error.status = 409;
4634
- throw error;
4635
- }
4636
- if (!response.ok) {
4637
- throw new Error(
4638
- `Failed to fetch consent content: ${response.statusText}`
4639
- );
4590
+ const apiBaseUrl = baseUrl || BASE_URL2;
4591
+ const url = new URL(
4592
+ `${apiBaseUrl}/public/organisations/${org_uuid}/workspaces/${workspace_uuid}/notices/get-notice/${notice_uuid}`
4593
+ );
4594
+ if (specific_uuid) {
4595
+ url.searchParams.append("specific_uuid", specific_uuid);
4596
+ }
4597
+ const response = await fetch(url.toString(), {
4598
+ method: "GET",
4599
+ headers: {
4600
+ "Content-Type": "application/json"
4640
4601
  }
4641
- const data = await response.json();
4642
- return data;
4643
- } catch (error) {
4644
- throw error;
4602
+ });
4603
+ if (!response.ok) {
4604
+ throw await parseApiError(
4605
+ response,
4606
+ "Could not load the consent notice. Please try again."
4607
+ );
4645
4608
  }
4609
+ const data = await response.json();
4610
+ return data;
4646
4611
  };
4647
4612
  var submitConsentEvent2 = async ({
4648
4613
  org_uuid,
@@ -4654,67 +4619,44 @@ var submitConsentEvent2 = async ({
4654
4619
  declined,
4655
4620
  meta_data
4656
4621
  }) => {
4657
- var _a, _b;
4658
- try {
4659
- const apiBaseUrl = baseUrl || BASE_URL2;
4660
- const payload = {
4661
- notice_uuid: noticeUuid,
4662
- purposes: purposes.map((purpose) => {
4663
- if (!purpose.uuid) {
4664
- throw new Error(`Invalid purpose data: missing uuid`);
4665
- }
4666
- const dataElements = purpose.data_elements.filter((element) => element.enabled).map((element) => ({
4667
- uuid: element.uuid,
4668
- selected: element.required ? true : Boolean(element.selected)
4669
- }));
4670
- return {
4671
- purpose_uuid: purpose.uuid,
4672
- selected: Boolean(purpose.selected),
4673
- data_elements: dataElements.length > 0 ? dataElements : void 0
4674
- };
4675
- }),
4676
- select_all_mandatory: false,
4677
- source: "WEB",
4678
- declined,
4679
- meta_data
4680
- };
4681
- const response = await fetch(
4682
- `${apiBaseUrl}/public/organisations/${org_uuid}/workspaces/${workspace_uuid}/submit-consent`,
4683
- {
4684
- method: "POST",
4685
- headers: {
4686
- Authorization: `Bearer ${accessToken}`,
4687
- "Content-Type": "application/json"
4688
- },
4689
- body: JSON.stringify(payload)
4690
- }
4691
- );
4692
- if (!response.ok) {
4693
- let errorData;
4694
- try {
4695
- errorData = await response.json();
4696
- } catch {
4697
- errorData = { message: response.statusText };
4698
- }
4699
- if (response.status === 409) {
4700
- const error2 = new Error(
4701
- ((_a = errorData.detail) == null ? void 0 : _a.message) || errorData.message || "User has already provided consent"
4702
- );
4703
- error2.status = 409;
4704
- error2.code = errorData.code || 409;
4705
- error2.detail = errorData.detail;
4706
- throw error2;
4622
+ const apiBaseUrl = baseUrl || BASE_URL2;
4623
+ const payload = {
4624
+ notice_uuid: noticeUuid,
4625
+ purposes: purposes.map((purpose) => {
4626
+ if (!purpose.uuid) {
4627
+ throw new Error(`Invalid purpose data: missing uuid`);
4707
4628
  }
4708
- const error = new Error(
4709
- ((_b = errorData.detail) == null ? void 0 : _b.message) || errorData.message || `Failed to submit consent event: ${response.statusText}`
4710
- );
4711
- error.status = response.status;
4712
- error.code = errorData.code;
4713
- error.detail = errorData.detail;
4714
- throw error;
4629
+ const dataElements = purpose.data_elements.filter((element) => element.enabled).map((element) => ({
4630
+ uuid: element.uuid,
4631
+ selected: element.required ? true : Boolean(element.selected)
4632
+ }));
4633
+ return {
4634
+ purpose_uuid: purpose.uuid,
4635
+ selected: Boolean(purpose.selected),
4636
+ data_elements: dataElements.length > 0 ? dataElements : void 0
4637
+ };
4638
+ }),
4639
+ select_all_mandatory: false,
4640
+ source: "WEB",
4641
+ declined,
4642
+ meta_data
4643
+ };
4644
+ const response = await fetch(
4645
+ `${apiBaseUrl}/public/organisations/${org_uuid}/workspaces/${workspace_uuid}/submit-consent`,
4646
+ {
4647
+ method: "POST",
4648
+ headers: {
4649
+ Authorization: `Bearer ${accessToken}`,
4650
+ "Content-Type": "application/json"
4651
+ },
4652
+ body: JSON.stringify(payload)
4715
4653
  }
4716
- } catch (error) {
4717
- throw error;
4654
+ );
4655
+ if (!response.ok) {
4656
+ throw await parseApiError(
4657
+ response,
4658
+ "Could not submit your consent. Please try again."
4659
+ );
4718
4660
  }
4719
4661
  };
4720
4662
 
@@ -5387,7 +5329,7 @@ var RedactoConsentInlineComponent = ({
5387
5329
  hasSubmittedRef.current = false;
5388
5330
  } catch (error) {
5389
5331
  const err = error;
5390
- const message = err.status === 500 ? "An error occurred while submitting your consent. Please try again later." : err.message || "Failed to submit consent. Please try again.";
5332
+ const message = err.message || "Failed to submit consent. Please try again.";
5391
5333
  setErrorMessage(message);
5392
5334
  hasSubmittedRef.current = false;
5393
5335
  throw error;
@@ -6101,6 +6043,7 @@ var DigiLockerCallback = ({
6101
6043
  };
6102
6044
  // Annotate the CommonJS export names for ESM import in node:
6103
6045
  0 && (module.exports = {
6046
+ ApiError,
6104
6047
  DigiLockerCallback,
6105
6048
  RedactoNoticeConsent,
6106
6049
  RedactoNoticeConsentInline