@redacto.io/consent-sdk-react 10.3.1 → 11.0.0-beta.2

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.mjs CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  THEMED_CONTROL_OFF,
16
16
  THEMED_TTS_BACKGROUND,
17
17
  TTS_TEXT_ATTRIBUTE,
18
+ applyScopedCustomCss,
18
19
  buildTtsCssVariables,
19
20
  buildTtsRootAttributes,
20
21
  configureNoticeFonts,
@@ -26,14 +27,16 @@ import {
26
27
  opaqueOver,
27
28
  paintableColor,
28
29
  prefersReducedMotion,
30
+ resolveEndpoints,
29
31
  resolveNoticeAppearance,
30
32
  resolveNoticeLayout,
31
33
  useIsomorphicLayoutEffect,
32
34
  useMediaQuery,
35
+ useResolvedEndpoints,
33
36
  withAlpha,
34
37
  withColorScheme,
35
38
  withIdempotencyKey
36
- } from "./chunk-RG4PVVKF.mjs";
39
+ } from "./chunk-W45JQYDG.mjs";
37
40
  import {
38
41
  NOTICE_FONT_ROOT_PROPS,
39
42
  REQUIRED_MARKER_ARIA_LABEL,
@@ -1312,8 +1315,6 @@ var MOTION_ATTRIBUTE = "data-redacto-motion";
1312
1315
  var MOTION_OFF = "off";
1313
1316
  var NOTICE_ID_ATTRIBUTE = "data-redacto-notice-id";
1314
1317
  var CUSTOM_CSS_ATTRIBUTE = "data-redacto-notice-css";
1315
- var CSS_SCOPE_AT_RULE = "@scope";
1316
- var CSS_STRING_SPECIALS_RE = /["\\\n]/g;
1317
1318
  var PX_LENGTH_RE = /^(\d+(?:\.\d+)?)px$/;
1318
1319
  var FONT_SIZE_PRECISION = 10;
1319
1320
  var DARK_SCHEME_QUERY = "(prefers-color-scheme: dark)";
@@ -3989,29 +3990,12 @@ var showsNoticePolicyLink = (productCount, entryCount) => entryCount === 0 || pr
3989
3990
  import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
3990
3991
 
3991
3992
  // src/RedactoNoticeConsent/services/customCss.ts
3992
- var escapesScope = (style) => {
3993
- var _a, _b;
3994
- return Array.from((_b = (_a = style.sheet) == null ? void 0 : _a.cssRules) != null ? _b : []).some(
3995
- (rule) => !rule.cssText.startsWith(CSS_SCOPE_AT_RULE)
3996
- );
3997
- };
3998
- var applyNoticeCustomCss = (noticeId, css3) => {
3999
- if (typeof document === "undefined") {
4000
- return () => void 0;
4001
- }
4002
- const id = noticeId.replace(CSS_STRING_SPECIALS_RE, "\\$&");
4003
- const style = document.createElement("style");
4004
- style.setAttribute(CUSTOM_CSS_ATTRIBUTE, noticeId);
4005
- style.textContent = `${CSS_SCOPE_AT_RULE} ([${NOTICE_ID_ATTRIBUTE}="${id}"]) {
4006
- ${css3}
4007
- }`;
4008
- document.head.appendChild(style);
4009
- if (escapesScope(style)) {
4010
- style.remove();
4011
- return () => void 0;
4012
- }
4013
- return () => style.remove();
4014
- };
3993
+ var applyNoticeCustomCss = (noticeId, css3) => applyScopedCustomCss({
3994
+ scopeAttribute: NOTICE_ID_ATTRIBUTE,
3995
+ scopeId: noticeId,
3996
+ markerAttribute: CUSTOM_CSS_ATTRIBUTE,
3997
+ css: css3
3998
+ });
4015
3999
 
4016
4000
  // src/RedactoNoticeConsent/utils/mergeHostSettings.ts
4017
4001
  var definedColors = (colors) => Object.fromEntries(
@@ -5455,8 +5439,8 @@ var NoticeConsentView = ({
5455
5439
  ucic,
5456
5440
  organisationUuid,
5457
5441
  workspaceUuid,
5458
- baseUrl,
5459
- ledgerBaseUrl,
5442
+ baseUrl: baseUrlProp,
5443
+ ledgerBaseUrl: ledgerBaseUrlProp,
5460
5444
  language = "en",
5461
5445
  blockUI = true,
5462
5446
  onAccept,
@@ -5478,6 +5462,10 @@ var NoticeConsentView = ({
5478
5462
  forceColorScheme
5479
5463
  }) => {
5480
5464
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
5465
+ const endpoints = useResolvedEndpoints(baseUrlProp, ledgerBaseUrlProp, {
5466
+ warn: !previewContent
5467
+ });
5468
+ const { baseUrl, ledgerBaseUrl } = endpoints;
5481
5469
  const sandboxParams = useMemo3(
5482
5470
  () => ({
5483
5471
  token,
@@ -7497,7 +7485,7 @@ var NoticeConsentView = ({
7497
7485
  const ttsAbortController = new AbortController();
7498
7486
  fetchTTSAudioUrls({
7499
7487
  accessToken,
7500
- baseUrl,
7488
+ baseUrl: endpoints.mode === "host" ? ledgerBaseUrl : baseUrl,
7501
7489
  ledgerBaseUrl,
7502
7490
  noticeUuid: content.notice_uuid,
7503
7491
  language: languageCode,
@@ -7522,6 +7510,7 @@ var NoticeConsentView = ({
7522
7510
  sandboxParams,
7523
7511
  baseUrl,
7524
7512
  ledgerBaseUrl,
7513
+ endpoints.mode,
7525
7514
  getLanguageCode
7526
7515
  ]);
7527
7516
  const hostRadius = noticeSettings == null ? void 0 : noticeSettings.borderRadius;
@@ -9427,8 +9416,8 @@ var RedactoConsentInlineComponent = ({
9427
9416
  workspace_uuid,
9428
9417
  notice_uuid,
9429
9418
  accessToken,
9430
- baseUrl,
9431
- ledgerBaseUrl,
9419
+ baseUrl: baseUrlProp,
9420
+ ledgerBaseUrl: ledgerBaseUrlProp,
9432
9421
  language = "en",
9433
9422
  onAccept,
9434
9423
  onError,
@@ -9437,6 +9426,8 @@ var RedactoConsentInlineComponent = ({
9437
9426
  applicationId
9438
9427
  }) => {
9439
9428
  var _a, _b, _c;
9429
+ const endpoints = useResolvedEndpoints(baseUrlProp, ledgerBaseUrlProp);
9430
+ const { baseUrl, ledgerBaseUrl } = endpoints;
9440
9431
  const [content, setContent] = useState3(null);
9441
9432
  const [isLoading, setIsLoading] = useState3(true);
9442
9433
  const [isSubmitting, setIsSubmitting] = useState3(false);
@@ -9454,6 +9445,31 @@ var RedactoConsentInlineComponent = ({
9454
9445
  const [awaitingConfirm, setAwaitingConfirm] = useState3(false);
9455
9446
  const refusedSelectionRef = useRef4(null);
9456
9447
  const confirmedSelectionRef = useRef4(null);
9448
+ const endpointsKey = JSON.stringify([endpoints.mode, baseUrl != null ? baseUrl : "", ledgerBaseUrl != null ? ledgerBaseUrl : ""]);
9449
+ const [loadedEndpointsKey, setLoadedEndpointsKey] = useState3(endpointsKey);
9450
+ if (loadedEndpointsKey !== endpointsKey) {
9451
+ setLoadedEndpointsKey(endpointsKey);
9452
+ setContent(null);
9453
+ setIsLoading(true);
9454
+ setFetchError(null);
9455
+ setErrorMessage(null);
9456
+ setHasAlreadyConsented(false);
9457
+ setIsCheckingConsent(Boolean(ledgerBaseUrl) && !applicationId);
9458
+ setIsSubmitting(false);
9459
+ setAwaitingConfirm(false);
9460
+ }
9461
+ const endpointsGenerationRef = useRef4(0);
9462
+ const committedEndpointsKeyRef = useRef4(endpointsKey);
9463
+ useIsomorphicLayoutEffect(() => {
9464
+ if (committedEndpointsKeyRef.current === endpointsKey) {
9465
+ return;
9466
+ }
9467
+ committedEndpointsKeyRef.current = endpointsKey;
9468
+ endpointsGenerationRef.current += 1;
9469
+ hasSubmittedRef.current = false;
9470
+ refusedSelectionRef.current = null;
9471
+ confirmedSelectionRef.current = null;
9472
+ }, [endpointsKey]);
9457
9473
  useEffect7(() => {
9458
9474
  injectSpinnerAnimation();
9459
9475
  injectCheckboxStyles();
@@ -9573,12 +9589,13 @@ var RedactoConsentInlineComponent = ({
9573
9589
  setFetchError(null);
9574
9590
  setHasAlreadyConsented(false);
9575
9591
  try {
9592
+ const noticeBaseUrl = endpoints.mode === "host" && accessToken && !applicationId ? ledgerBaseUrl : baseUrl;
9576
9593
  const consentContentData = await fetchConsentContent2({
9577
9594
  org_uuid,
9578
9595
  workspace_uuid,
9579
9596
  notice_uuid,
9580
9597
  accessToken,
9581
- baseUrl,
9598
+ baseUrl: noticeBaseUrl,
9582
9599
  language,
9583
9600
  specific_uuid: applicationId,
9584
9601
  signal
@@ -9642,7 +9659,8 @@ var RedactoConsentInlineComponent = ({
9642
9659
  notice_uuid,
9643
9660
  language,
9644
9661
  applicationId,
9645
- accessToken
9662
+ accessToken,
9663
+ endpointsKey
9646
9664
  ]);
9647
9665
  useEffect7(() => {
9648
9666
  if (!ledgerBaseUrl || applicationId) {
@@ -9747,6 +9765,8 @@ var RedactoConsentInlineComponent = ({
9747
9765
  setErrorMessage("Unable to submit consent. Please try again.");
9748
9766
  throw new Error("Access token or content not available");
9749
9767
  }
9768
+ const generation = endpointsGenerationRef.current;
9769
+ const isCurrent = () => endpointsGenerationRef.current === generation;
9750
9770
  try {
9751
9771
  setIsSubmitting(true);
9752
9772
  setErrorMessage(null);
@@ -9782,16 +9802,24 @@ var RedactoConsentInlineComponent = ({
9782
9802
  declined: false,
9783
9803
  meta_data: applicationId ? { specific_uuid: applicationId } : void 0
9784
9804
  });
9805
+ if (!isCurrent()) {
9806
+ return;
9807
+ }
9785
9808
  onAccept == null ? void 0 : onAccept();
9786
9809
  hasSubmittedRef.current = false;
9787
9810
  } catch (error) {
9811
+ if (!isCurrent()) {
9812
+ return;
9813
+ }
9788
9814
  const err = error;
9789
9815
  const message = err.message || "Failed to submit consent. Please try again.";
9790
9816
  setErrorMessage(message);
9791
9817
  hasSubmittedRef.current = false;
9792
9818
  throw error;
9793
9819
  } finally {
9794
- setIsSubmitting(false);
9820
+ if (isCurrent()) {
9821
+ setIsSubmitting(false);
9822
+ }
9795
9823
  }
9796
9824
  },
9797
9825
  [
@@ -12734,13 +12762,17 @@ var RedactoNoticeAssisted = ({
12734
12762
  organisationUuid,
12735
12763
  workspaceUuid,
12736
12764
  noticeUuid,
12737
- baseUrl,
12738
- ledgerBaseUrl,
12765
+ baseUrl: baseUrlProp,
12766
+ ledgerBaseUrl: ledgerBaseUrlProp,
12739
12767
  onDecline,
12740
12768
  onComplete,
12741
12769
  settings
12742
12770
  }) => {
12743
12771
  var _a, _b, _c, _d;
12772
+ const { baseUrl, ledgerBaseUrl } = useResolvedEndpoints(
12773
+ baseUrlProp,
12774
+ ledgerBaseUrlProp
12775
+ );
12744
12776
  const isMobile = useMediaQuery3("(max-width: 768px)");
12745
12777
  const [content, setContent] = useState5(null);
12746
12778
  const [isLoading, setIsLoading] = useState5(true);
@@ -14527,6 +14559,15 @@ var RedactoNoticePreview = ({
14527
14559
  // src/RedactoNoticeConsent/components/DigiLockerCallback.tsx
14528
14560
  import { useCallback as useCallback6, useEffect as useEffect10, useRef as useRef6, useState as useState6 } from "react";
14529
14561
  import { Fragment as Fragment5, jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
14562
+ var sameOriginUrlOrRoot = (candidate) => {
14563
+ if (!candidate) return "/";
14564
+ try {
14565
+ const url = new URL(candidate, window.location.origin);
14566
+ return url.origin === window.location.origin ? url.href : "/";
14567
+ } catch {
14568
+ return "/";
14569
+ }
14570
+ };
14530
14571
  var DigiLockerCallback = ({
14531
14572
  accessToken: propAccessToken,
14532
14573
  baseUrl,
@@ -14563,7 +14604,7 @@ var DigiLockerCallback = ({
14563
14604
  flowState: verificationResult === "verified" ? "consent-form" : "error"
14564
14605
  });
14565
14606
  redirectTimeoutRef.current = setTimeout(() => {
14566
- window.location.href = originalUrl;
14607
+ window.location.href = sameOriginUrlOrRoot(originalUrl);
14567
14608
  }, 1500);
14568
14609
  },
14569
14610
  []
@@ -14635,7 +14676,7 @@ var DigiLockerCallback = ({
14635
14676
  return;
14636
14677
  }
14637
14678
  setMessage("Processing verification...");
14638
- const apiBaseUrl = baseUrl || storedBaseUrl;
14679
+ const apiBaseUrl = resolveEndpoints(baseUrl || storedBaseUrl).baseUrl;
14639
14680
  const response = await verifyGuardianStatus({
14640
14681
  accessToken,
14641
14682
  baseUrl: apiBaseUrl,
@@ -14796,7 +14837,7 @@ var DigiLockerCallback = ({
14796
14837
  const persistedState = getConsentState();
14797
14838
  if (persistedState == null ? void 0 : persistedState.originalUrl) {
14798
14839
  clearConsentState();
14799
- window.location.href = persistedState.originalUrl;
14840
+ window.location.href = sameOriginUrlOrRoot(persistedState.originalUrl);
14800
14841
  } else {
14801
14842
  window.location.href = "/";
14802
14843
  }