@redacto.io/consent-sdk-react-native 5.0.0-beta.10 → 5.0.0-beta.11

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/dist/index.js CHANGED
@@ -526,122 +526,6 @@ var verifyGuardianStatus = async ({
526
526
  };
527
527
  };
528
528
 
529
- // src/shared/notice-consent-status.ts
530
- var import_jwt_decode2 = require("jwt-decode");
531
- var decodeNoticeConsentToken = (token) => {
532
- try {
533
- return (0, import_jwt_decode2.jwtDecode)(token);
534
- } catch {
535
- return null;
536
- }
537
- };
538
- var fetchNoticeConsentStatusForScope = async ({
539
- accessToken,
540
- ledgerBaseUrl,
541
- organisationUuid,
542
- workspaceUuid,
543
- noticeUuid,
544
- signal
545
- }) => {
546
- if (!accessToken || !ledgerBaseUrl || !organisationUuid || !workspaceUuid || !noticeUuid) {
547
- return null;
548
- }
549
- try {
550
- const response = await fetch(
551
- `${ledgerBaseUrl}/public/organisations/${organisationUuid}/workspaces/${workspaceUuid}/notices/${noticeUuid}/check-consent`,
552
- {
553
- method: "POST",
554
- headers: {
555
- Authorization: `Bearer ${accessToken}`,
556
- "Content-Type": "application/json"
557
- },
558
- body: "{}",
559
- signal
560
- }
561
- );
562
- if (!response.ok) {
563
- return null;
564
- }
565
- const data = await response.json();
566
- const body = data && typeof data === "object" && "detail" in data && data.detail ? data.detail : data;
567
- if (!body || !Array.isArray(body.purposes)) {
568
- return null;
569
- }
570
- return body;
571
- } catch {
572
- return null;
573
- }
574
- };
575
- var fetchNoticeConsentStatus = async ({
576
- accessToken,
577
- ledgerBaseUrl,
578
- noticeUuid,
579
- signal
580
- }) => {
581
- if (!accessToken || !ledgerBaseUrl || !noticeUuid) {
582
- return null;
583
- }
584
- const decodedToken = decodeNoticeConsentToken(accessToken);
585
- if (!decodedToken) {
586
- return null;
587
- }
588
- const {
589
- organisation_uuid: ORGANISATION_UUID,
590
- workspace_uuid: WORKSPACE_UUID
591
- } = decodedToken;
592
- if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
593
- return null;
594
- }
595
- return fetchNoticeConsentStatusForScope({
596
- accessToken,
597
- ledgerBaseUrl,
598
- organisationUuid: ORGANISATION_UUID,
599
- workspaceUuid: WORKSPACE_UUID,
600
- noticeUuid,
601
- signal
602
- });
603
- };
604
- var isNoticeFullyConsented = (status) => status.consented && status.all_mandatory_active;
605
- var buildLedgerConsentOverlay = (status, configPurposes) => {
606
- var _a, _b;
607
- const byUuid = new Map(status.purposes.map((p) => [p.uuid, p]));
608
- const hasHistory = status.purposes.some(
609
- (p) => (p.status || "INACTIVE") !== "INACTIVE"
610
- );
611
- if (!hasHistory) {
612
- return null;
613
- }
614
- const purpose_selections = {};
615
- for (const cp of configPurposes) {
616
- const lp = byUuid.get(cp.uuid);
617
- const purposeStatus = (lp == null ? void 0 : lp.status) || "INACTIVE";
618
- const selectedByUuid = new Map(
619
- ((lp == null ? void 0 : lp.data_elements) || []).map((de) => [de.uuid, de.selected])
620
- );
621
- const data_elements = {};
622
- for (const de of cp.data_elements) {
623
- data_elements[de.uuid] = {
624
- selected: (_a = selectedByUuid.get(de.uuid)) != null ? _a : false,
625
- enabled: de.enabled,
626
- required: de.required
627
- };
628
- }
629
- purpose_selections[cp.uuid] = {
630
- selected: (_b = lp == null ? void 0 : lp.selected) != null ? _b : false,
631
- status: purposeStatus,
632
- needs_reconsent: purposeStatus !== "ACTIVE",
633
- data_elements
634
- };
635
- }
636
- const reconsent_required = configPurposes.some(
637
- (cp) => {
638
- var _a2;
639
- return (((_a2 = purpose_selections[cp.uuid]) == null ? void 0 : _a2.status) || "INACTIVE") !== "ACTIVE";
640
- }
641
- );
642
- return { reconsent_required, purpose_selections };
643
- };
644
-
645
529
  // src/RedactoNoticeConsent/components/Checkbox.tsx
646
530
  var import_react_native = require("react-native");
647
531
  var import_react_native_svg = __toESM(require("react-native-svg"));
@@ -1941,7 +1825,6 @@ var RedactoNoticeConsent = ({
1941
1825
  const abortControllerRef = (0, import_react2.useRef)(null);
1942
1826
  const hasBootstrappedLanguageRef = (0, import_react2.useRef)(false);
1943
1827
  const fetchContent = (0, import_react2.useCallback)(async () => {
1944
- var _a2, _b2;
1945
1828
  if (abortControllerRef.current) {
1946
1829
  abortControllerRef.current.abort();
1947
1830
  }
@@ -1962,23 +1845,8 @@ var RedactoNoticeConsent = ({
1962
1845
  ...sandboxParams
1963
1846
  });
1964
1847
  const activeConfig2 = data.detail.active_config;
1965
- let purposeSelections = data.detail.purpose_selections;
1966
- let reconsentRequired = data.detail.reconsent_required || false;
1967
- if (accessToken && ledgerBaseUrl && !applicationId && !token) {
1968
- const ledgerStatus = await fetchNoticeConsentStatus({
1969
- accessToken,
1970
- ledgerBaseUrl,
1971
- noticeUuid: noticeId,
1972
- signal: (_a2 = abortControllerRef.current) == null ? void 0 : _a2.signal
1973
- });
1974
- if (ledgerStatus) {
1975
- const overlay = buildLedgerConsentOverlay(ledgerStatus, activeConfig2.purposes);
1976
- reconsentRequired = (_b2 = overlay == null ? void 0 : overlay.reconsent_required) != null ? _b2 : false;
1977
- purposeSelections = overlay == null ? void 0 : overlay.purpose_selections;
1978
- data.detail.purpose_selections = purposeSelections;
1979
- data.detail.reconsent_required = reconsentRequired;
1980
- }
1981
- }
1848
+ const purposeSelections = data.detail.purpose_selections;
1849
+ const reconsentRequired = data.detail.reconsent_required || false;
1982
1850
  const noticeIsMinor = data.detail.is_minor || false;
1983
1851
  setIsMinor(noticeIsMinor);
1984
1852
  const initialCollapsed = {};
@@ -1991,9 +1859,9 @@ var RedactoNoticeConsent = ({
1991
1859
  const purposeSelected = sel ? sel.selected : false;
1992
1860
  initialPurposeState[purpose.uuid] = purposeSelected;
1993
1861
  purpose.data_elements.forEach((el) => {
1994
- var _a3, _b3, _c2;
1862
+ var _a2, _b2, _c2;
1995
1863
  const combinedId = `${purpose.uuid}-${el.uuid}`;
1996
- const elementSel = (_c2 = (_b3 = (_a3 = sel == null ? void 0 : sel.data_elements) == null ? void 0 : _a3[el.uuid]) == null ? void 0 : _b3.selected) != null ? _c2 : false;
1864
+ const elementSel = (_c2 = (_b2 = (_a2 = sel == null ? void 0 : sel.data_elements) == null ? void 0 : _a2[el.uuid]) == null ? void 0 : _b2.selected) != null ? _c2 : false;
1997
1865
  initialDataElementState[combinedId] = elementSel;
1998
1866
  initialDataElementSelectionsMap[combinedId] = elementSel;
1999
1867
  });
@@ -3195,6 +3063,46 @@ var submitConsentEvent2 = async ({
3195
3063
  }
3196
3064
  };
3197
3065
 
3066
+ // src/shared/notice-consent-status.ts
3067
+ var fetchNoticeConsentStatusForScope = async ({
3068
+ accessToken,
3069
+ ledgerBaseUrl,
3070
+ organisationUuid,
3071
+ workspaceUuid,
3072
+ noticeUuid,
3073
+ signal
3074
+ }) => {
3075
+ if (!accessToken || !ledgerBaseUrl || !organisationUuid || !workspaceUuid || !noticeUuid) {
3076
+ return null;
3077
+ }
3078
+ try {
3079
+ const response = await fetch(
3080
+ `${ledgerBaseUrl}/public/organisations/${organisationUuid}/workspaces/${workspaceUuid}/notices/${noticeUuid}/check-consent`,
3081
+ {
3082
+ method: "POST",
3083
+ headers: {
3084
+ Authorization: `Bearer ${accessToken}`,
3085
+ "Content-Type": "application/json"
3086
+ },
3087
+ body: "{}",
3088
+ signal
3089
+ }
3090
+ );
3091
+ if (!response.ok) {
3092
+ return null;
3093
+ }
3094
+ const data = await response.json();
3095
+ const body = data && typeof data === "object" && "detail" in data && data.detail ? data.detail : data;
3096
+ if (!body || !Array.isArray(body.purposes)) {
3097
+ return null;
3098
+ }
3099
+ return body;
3100
+ } catch {
3101
+ return null;
3102
+ }
3103
+ };
3104
+ var isNoticeFullyConsented = (status) => status.consented && status.all_mandatory_active;
3105
+
3198
3106
  // src/RedactoNoticeConsentInline/styles.ts
3199
3107
  var import_react_native6 = require("react-native");
3200
3108
  var styles3 = import_react_native6.StyleSheet.create({
package/dist/index.mjs CHANGED
@@ -466,122 +466,6 @@ var verifyGuardianStatus = async ({
466
466
  };
467
467
  };
468
468
 
469
- // src/shared/notice-consent-status.ts
470
- import { jwtDecode as jwtDecode2 } from "jwt-decode";
471
- var decodeNoticeConsentToken = (token) => {
472
- try {
473
- return jwtDecode2(token);
474
- } catch {
475
- return null;
476
- }
477
- };
478
- var fetchNoticeConsentStatusForScope = async ({
479
- accessToken,
480
- ledgerBaseUrl,
481
- organisationUuid,
482
- workspaceUuid,
483
- noticeUuid,
484
- signal
485
- }) => {
486
- if (!accessToken || !ledgerBaseUrl || !organisationUuid || !workspaceUuid || !noticeUuid) {
487
- return null;
488
- }
489
- try {
490
- const response = await fetch(
491
- `${ledgerBaseUrl}/public/organisations/${organisationUuid}/workspaces/${workspaceUuid}/notices/${noticeUuid}/check-consent`,
492
- {
493
- method: "POST",
494
- headers: {
495
- Authorization: `Bearer ${accessToken}`,
496
- "Content-Type": "application/json"
497
- },
498
- body: "{}",
499
- signal
500
- }
501
- );
502
- if (!response.ok) {
503
- return null;
504
- }
505
- const data = await response.json();
506
- const body = data && typeof data === "object" && "detail" in data && data.detail ? data.detail : data;
507
- if (!body || !Array.isArray(body.purposes)) {
508
- return null;
509
- }
510
- return body;
511
- } catch {
512
- return null;
513
- }
514
- };
515
- var fetchNoticeConsentStatus = async ({
516
- accessToken,
517
- ledgerBaseUrl,
518
- noticeUuid,
519
- signal
520
- }) => {
521
- if (!accessToken || !ledgerBaseUrl || !noticeUuid) {
522
- return null;
523
- }
524
- const decodedToken = decodeNoticeConsentToken(accessToken);
525
- if (!decodedToken) {
526
- return null;
527
- }
528
- const {
529
- organisation_uuid: ORGANISATION_UUID,
530
- workspace_uuid: WORKSPACE_UUID
531
- } = decodedToken;
532
- if (!ORGANISATION_UUID || !WORKSPACE_UUID) {
533
- return null;
534
- }
535
- return fetchNoticeConsentStatusForScope({
536
- accessToken,
537
- ledgerBaseUrl,
538
- organisationUuid: ORGANISATION_UUID,
539
- workspaceUuid: WORKSPACE_UUID,
540
- noticeUuid,
541
- signal
542
- });
543
- };
544
- var isNoticeFullyConsented = (status) => status.consented && status.all_mandatory_active;
545
- var buildLedgerConsentOverlay = (status, configPurposes) => {
546
- var _a, _b;
547
- const byUuid = new Map(status.purposes.map((p) => [p.uuid, p]));
548
- const hasHistory = status.purposes.some(
549
- (p) => (p.status || "INACTIVE") !== "INACTIVE"
550
- );
551
- if (!hasHistory) {
552
- return null;
553
- }
554
- const purpose_selections = {};
555
- for (const cp of configPurposes) {
556
- const lp = byUuid.get(cp.uuid);
557
- const purposeStatus = (lp == null ? void 0 : lp.status) || "INACTIVE";
558
- const selectedByUuid = new Map(
559
- ((lp == null ? void 0 : lp.data_elements) || []).map((de) => [de.uuid, de.selected])
560
- );
561
- const data_elements = {};
562
- for (const de of cp.data_elements) {
563
- data_elements[de.uuid] = {
564
- selected: (_a = selectedByUuid.get(de.uuid)) != null ? _a : false,
565
- enabled: de.enabled,
566
- required: de.required
567
- };
568
- }
569
- purpose_selections[cp.uuid] = {
570
- selected: (_b = lp == null ? void 0 : lp.selected) != null ? _b : false,
571
- status: purposeStatus,
572
- needs_reconsent: purposeStatus !== "ACTIVE",
573
- data_elements
574
- };
575
- }
576
- const reconsent_required = configPurposes.some(
577
- (cp) => {
578
- var _a2;
579
- return (((_a2 = purpose_selections[cp.uuid]) == null ? void 0 : _a2.status) || "INACTIVE") !== "ACTIVE";
580
- }
581
- );
582
- return { reconsent_required, purpose_selections };
583
- };
584
-
585
469
  // src/RedactoNoticeConsent/components/Checkbox.tsx
586
470
  import { TouchableOpacity, View, StyleSheet } from "react-native";
587
471
  import Svg, { Path } from "react-native-svg";
@@ -1888,7 +1772,6 @@ var RedactoNoticeConsent = ({
1888
1772
  const abortControllerRef = useRef2(null);
1889
1773
  const hasBootstrappedLanguageRef = useRef2(false);
1890
1774
  const fetchContent = useCallback(async () => {
1891
- var _a2, _b2;
1892
1775
  if (abortControllerRef.current) {
1893
1776
  abortControllerRef.current.abort();
1894
1777
  }
@@ -1909,23 +1792,8 @@ var RedactoNoticeConsent = ({
1909
1792
  ...sandboxParams
1910
1793
  });
1911
1794
  const activeConfig2 = data.detail.active_config;
1912
- let purposeSelections = data.detail.purpose_selections;
1913
- let reconsentRequired = data.detail.reconsent_required || false;
1914
- if (accessToken && ledgerBaseUrl && !applicationId && !token) {
1915
- const ledgerStatus = await fetchNoticeConsentStatus({
1916
- accessToken,
1917
- ledgerBaseUrl,
1918
- noticeUuid: noticeId,
1919
- signal: (_a2 = abortControllerRef.current) == null ? void 0 : _a2.signal
1920
- });
1921
- if (ledgerStatus) {
1922
- const overlay = buildLedgerConsentOverlay(ledgerStatus, activeConfig2.purposes);
1923
- reconsentRequired = (_b2 = overlay == null ? void 0 : overlay.reconsent_required) != null ? _b2 : false;
1924
- purposeSelections = overlay == null ? void 0 : overlay.purpose_selections;
1925
- data.detail.purpose_selections = purposeSelections;
1926
- data.detail.reconsent_required = reconsentRequired;
1927
- }
1928
- }
1795
+ const purposeSelections = data.detail.purpose_selections;
1796
+ const reconsentRequired = data.detail.reconsent_required || false;
1929
1797
  const noticeIsMinor = data.detail.is_minor || false;
1930
1798
  setIsMinor(noticeIsMinor);
1931
1799
  const initialCollapsed = {};
@@ -1938,9 +1806,9 @@ var RedactoNoticeConsent = ({
1938
1806
  const purposeSelected = sel ? sel.selected : false;
1939
1807
  initialPurposeState[purpose.uuid] = purposeSelected;
1940
1808
  purpose.data_elements.forEach((el) => {
1941
- var _a3, _b3, _c2;
1809
+ var _a2, _b2, _c2;
1942
1810
  const combinedId = `${purpose.uuid}-${el.uuid}`;
1943
- const elementSel = (_c2 = (_b3 = (_a3 = sel == null ? void 0 : sel.data_elements) == null ? void 0 : _a3[el.uuid]) == null ? void 0 : _b3.selected) != null ? _c2 : false;
1811
+ const elementSel = (_c2 = (_b2 = (_a2 = sel == null ? void 0 : sel.data_elements) == null ? void 0 : _a2[el.uuid]) == null ? void 0 : _b2.selected) != null ? _c2 : false;
1944
1812
  initialDataElementState[combinedId] = elementSel;
1945
1813
  initialDataElementSelectionsMap[combinedId] = elementSel;
1946
1814
  });
@@ -3155,6 +3023,46 @@ var submitConsentEvent2 = async ({
3155
3023
  }
3156
3024
  };
3157
3025
 
3026
+ // src/shared/notice-consent-status.ts
3027
+ var fetchNoticeConsentStatusForScope = async ({
3028
+ accessToken,
3029
+ ledgerBaseUrl,
3030
+ organisationUuid,
3031
+ workspaceUuid,
3032
+ noticeUuid,
3033
+ signal
3034
+ }) => {
3035
+ if (!accessToken || !ledgerBaseUrl || !organisationUuid || !workspaceUuid || !noticeUuid) {
3036
+ return null;
3037
+ }
3038
+ try {
3039
+ const response = await fetch(
3040
+ `${ledgerBaseUrl}/public/organisations/${organisationUuid}/workspaces/${workspaceUuid}/notices/${noticeUuid}/check-consent`,
3041
+ {
3042
+ method: "POST",
3043
+ headers: {
3044
+ Authorization: `Bearer ${accessToken}`,
3045
+ "Content-Type": "application/json"
3046
+ },
3047
+ body: "{}",
3048
+ signal
3049
+ }
3050
+ );
3051
+ if (!response.ok) {
3052
+ return null;
3053
+ }
3054
+ const data = await response.json();
3055
+ const body = data && typeof data === "object" && "detail" in data && data.detail ? data.detail : data;
3056
+ if (!body || !Array.isArray(body.purposes)) {
3057
+ return null;
3058
+ }
3059
+ return body;
3060
+ } catch {
3061
+ return null;
3062
+ }
3063
+ };
3064
+ var isNoticeFullyConsented = (status) => status.consented && status.all_mandatory_active;
3065
+
3158
3066
  // src/RedactoNoticeConsentInline/styles.ts
3159
3067
  import { StyleSheet as StyleSheet5, Platform as Platform2 } from "react-native";
3160
3068
  var styles3 = StyleSheet5.create({