@entur-partner/app-shell 6.1.4 → 6.1.6-alpha.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/LICENSE.md +1 -0
- package/dist/AppShell.d.ts +6 -6
- package/dist/ConsentManagerProvider.d.ts +2 -2
- package/dist/EnvironmentBanner.d.ts +2 -2
- package/dist/LanguageProvider.d.ts +1 -1
- package/dist/MenuProvider.d.ts +2 -2
- package/dist/MicroFrontendLink.d.ts +1 -1
- package/dist/OrganisationProvider.d.ts +1 -1
- package/dist/OrganisationSelector.d.ts +3 -3
- package/dist/PostHogProviderWrapper.d.ts +1 -1
- package/dist/app-shell.cjs.development.js +220 -214
- package/dist/app-shell.cjs.development.js.map +1 -1
- package/dist/app-shell.cjs.production.min.js +1 -1
- package/dist/app-shell.cjs.production.min.js.map +1 -1
- package/dist/app-shell.esm.js +222 -216
- package/dist/app-shell.esm.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/types/ConsentTypes.d.ts +1 -1
- package/dist/types/UserTypes.d.ts +2 -2
- package/dist/util/convertUCServicesToConsents.d.ts +1 -1
- package/package.json +53 -54
package/dist/app-shell.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
|
|
2
2
|
import { BannerAlertBox } from '@entur/alert';
|
|
3
|
-
import { Paragraph, Link, CodeText } from '@entur/typography';
|
|
4
3
|
import { Loader, SkeletonRectangle } from '@entur/loader';
|
|
5
4
|
import { space } from '@entur/tokens';
|
|
6
|
-
import {
|
|
5
|
+
import { Paragraph, Link, CodeText } from '@entur/typography';
|
|
7
6
|
import { getColorForEnvironment, Environment, OrganisationDropDown } from '@entur-partner/common';
|
|
8
7
|
import { assertIsDefined } from '@entur-partner/util';
|
|
8
|
+
import React, { useState, useEffect, useContext, createContext, useCallback } from 'react';
|
|
9
9
|
import postHog from 'posthog-js';
|
|
10
10
|
import { PostHogProvider } from 'posthog-js/react';
|
|
11
11
|
|
|
@@ -438,13 +438,13 @@ var EnvironmentBanner = function EnvironmentBanner(_ref) {
|
|
|
438
438
|
return React.createElement("div", {
|
|
439
439
|
className: "epp-environment-banner",
|
|
440
440
|
style: {
|
|
441
|
-
position:
|
|
441
|
+
position: "fixed",
|
|
442
442
|
zIndex: 9999,
|
|
443
443
|
top: 0,
|
|
444
444
|
left: 0,
|
|
445
445
|
right: 0,
|
|
446
|
-
width:
|
|
447
|
-
height:
|
|
446
|
+
width: "100vw",
|
|
447
|
+
height: "16px",
|
|
448
448
|
backgroundColor: getColorForEnvironment(environment)
|
|
449
449
|
}
|
|
450
450
|
});
|
|
@@ -497,7 +497,7 @@ var Authenticate = function Authenticate(_ref) {
|
|
|
497
497
|
case 10:
|
|
498
498
|
_context.prev = 10;
|
|
499
499
|
_context.t0 = _context["catch"](0);
|
|
500
|
-
console.error(
|
|
500
|
+
console.error("Error fetching user data:", _context.t0);
|
|
501
501
|
case 13:
|
|
502
502
|
case "end":
|
|
503
503
|
return _context.stop();
|
|
@@ -528,15 +528,15 @@ var Authenticate = function Authenticate(_ref) {
|
|
|
528
528
|
}, "Authenticating");
|
|
529
529
|
}
|
|
530
530
|
if (error) {
|
|
531
|
-
process.env.NODE_ENV !==
|
|
531
|
+
process.env.NODE_ENV !== "production" && console.error(error);
|
|
532
532
|
return React.createElement(BannerAlertBox, {
|
|
533
533
|
variant: "error",
|
|
534
534
|
title: "Authentication failed",
|
|
535
535
|
style: {
|
|
536
|
-
maxWidth:
|
|
537
|
-
margin:
|
|
536
|
+
maxWidth: "600px",
|
|
537
|
+
margin: "0 auto"
|
|
538
538
|
}
|
|
539
|
-
}, React.createElement(Paragraph, null, "Something went wrong while trying to authenticate you. If the problem persists you should contact",
|
|
539
|
+
}, React.createElement(Paragraph, null, "Something went wrong while trying to authenticate you. If the problem persists you should contact", " ", React.createElement(Link, {
|
|
540
540
|
href: "mailto:support@entur.org"
|
|
541
541
|
}, "support@entur.org"), " to get it resolved."), React.createElement(Paragraph, null, "Authentication failed with: ", React.createElement(CodeText, null, error == null ? void 0 : error.toString())));
|
|
542
542
|
}
|
|
@@ -572,38 +572,164 @@ var AppShell = function AppShell(_ref3) {
|
|
|
572
572
|
}));
|
|
573
573
|
};
|
|
574
574
|
|
|
575
|
-
var
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
575
|
+
var ORGANISATION_STORAGE_KEY = "EP::activeOrgId";
|
|
576
|
+
var organisationStorage = {
|
|
577
|
+
get: function get() {
|
|
578
|
+
return localStorage.getItem(ORGANISATION_STORAGE_KEY);
|
|
579
|
+
},
|
|
580
|
+
set: function set(value) {
|
|
581
|
+
return localStorage.setItem(ORGANISATION_STORAGE_KEY, value);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
var LANGUAGE_STORAGE_KEY = "EP::locale";
|
|
585
|
+
var languageStorage = {
|
|
586
|
+
get: function get() {
|
|
587
|
+
return localStorage.getItem(LANGUAGE_STORAGE_KEY);
|
|
588
|
+
},
|
|
589
|
+
set: function set(value) {
|
|
590
|
+
return localStorage.setItem(LANGUAGE_STORAGE_KEY, value);
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
var UC_UI_STORAGE_KEY = "ucData";
|
|
594
|
+
var ucUiStorage = {
|
|
595
|
+
get: function get() {
|
|
596
|
+
return localStorage.getItem(UC_UI_STORAGE_KEY);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
var SERVICE_NAMES = {
|
|
601
|
+
Usercentrics: "Usercentrics Consent Management Platform",
|
|
602
|
+
PostHog: "PostHog.com",
|
|
603
|
+
Sentry: "Sentry"
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
var DEFAULT_CONSENT_GIVEN = {
|
|
607
|
+
Usercentrics: {
|
|
608
|
+
consentGiven: false
|
|
609
|
+
},
|
|
610
|
+
PostHog: {
|
|
611
|
+
consentGiven: false
|
|
612
|
+
},
|
|
613
|
+
Sentry: {
|
|
614
|
+
consentGiven: false
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
var convertUCServicesToConsents = function convertUCServicesToConsents(services) {
|
|
618
|
+
return services.map(function (service) {
|
|
619
|
+
var _Object$entries$find, _ref3;
|
|
620
|
+
var serviceName = (_Object$entries$find = Object.entries(SERVICE_NAMES).find(function (keyValue) {
|
|
621
|
+
return keyValue[1] === service.name;
|
|
622
|
+
})) == null ? void 0 : _Object$entries$find[0];
|
|
623
|
+
// Ensure the service name exists in SERVICE_NAMES
|
|
624
|
+
assertIsDefined(serviceName, "Service name " + service.name + " not found in SERVICE_NAMES");
|
|
625
|
+
if (typeof service.consent === "boolean") {
|
|
626
|
+
var _ref;
|
|
627
|
+
var consentGiven = service.consent;
|
|
628
|
+
return _ref = {}, _ref[serviceName] = {
|
|
629
|
+
consentGiven: consentGiven
|
|
630
|
+
}, _ref;
|
|
631
|
+
} else if (typeof service.consent === "object" && "given" in service.consent) {
|
|
632
|
+
var _ref2;
|
|
633
|
+
var _consentGiven = service.consent.given;
|
|
634
|
+
return _ref2 = {}, _ref2[serviceName] = {
|
|
635
|
+
consentGiven: _consentGiven
|
|
636
|
+
}, _ref2;
|
|
637
|
+
}
|
|
638
|
+
return _ref3 = {}, _ref3[serviceName] = {
|
|
639
|
+
consentGiven: false
|
|
640
|
+
}, _ref3;
|
|
641
|
+
}).reduce(
|
|
642
|
+
// biome-ignore lint/performance/noAccumulatingSpread: Ignore it for now. No changes in code.
|
|
643
|
+
function (acc, curr) {
|
|
644
|
+
return _extends({}, acc, curr);
|
|
645
|
+
}, DEFAULT_CONSENT_GIVEN);
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
var ConsentContext = /*#__PURE__*/createContext(DEFAULT_CONSENT_GIVEN);
|
|
649
|
+
var useConsentManager = function useConsentManager() {
|
|
650
|
+
var context = useContext(ConsentContext);
|
|
651
|
+
return context;
|
|
652
|
+
};
|
|
653
|
+
var ConsentManagerProvider = function ConsentManagerProvider(_ref) {
|
|
654
|
+
var children = _ref.children;
|
|
655
|
+
var _useState = useState(DEFAULT_CONSENT_GIVEN),
|
|
656
|
+
consentManager = _useState[0],
|
|
657
|
+
setConsentManager = _useState[1];
|
|
658
|
+
// Initialize consent manager from local storage once
|
|
659
|
+
useEffect(function () {
|
|
660
|
+
if (typeof window === "undefined") return;
|
|
661
|
+
var ucData = ucUiStorage.get();
|
|
662
|
+
if (ucData) {
|
|
663
|
+
var data = JSON.parse(ucData);
|
|
664
|
+
var services = convertUCServicesToConsents(Object.values(data.consent.services));
|
|
665
|
+
setConsentManager(services);
|
|
666
|
+
}
|
|
667
|
+
}, []);
|
|
668
|
+
// Listen for Usercentrics consent events and update consent manager state
|
|
669
|
+
useEffect(function () {
|
|
670
|
+
var handleConsentEvent = /*#__PURE__*/function () {
|
|
671
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
672
|
+
var customEvent, services, updatedConsentManager;
|
|
673
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
674
|
+
while (1) switch (_context.prev = _context.next) {
|
|
675
|
+
case 0:
|
|
676
|
+
if (!(typeof window === "undefined")) {
|
|
677
|
+
_context.next = 2;
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
return _context.abrupt("return");
|
|
681
|
+
case 2:
|
|
682
|
+
customEvent = event;
|
|
683
|
+
services = Object.values(customEvent.detail.services);
|
|
684
|
+
updatedConsentManager = convertUCServicesToConsents(services);
|
|
685
|
+
setConsentManager(updatedConsentManager);
|
|
686
|
+
case 6:
|
|
687
|
+
case "end":
|
|
688
|
+
return _context.stop();
|
|
689
|
+
}
|
|
690
|
+
}, _callee);
|
|
691
|
+
}));
|
|
692
|
+
return function handleConsentEvent(_x) {
|
|
693
|
+
return _ref2.apply(this, arguments);
|
|
694
|
+
};
|
|
695
|
+
}();
|
|
696
|
+
window.addEventListener("UC_CONSENT", handleConsentEvent);
|
|
697
|
+
return function () {
|
|
698
|
+
return window.removeEventListener("UC_CONSENT", handleConsentEvent);
|
|
699
|
+
};
|
|
700
|
+
}, []);
|
|
701
|
+
return React.createElement(ConsentContext.Provider, {
|
|
702
|
+
value: consentManager
|
|
703
|
+
}, children);
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
var LanguageContext = /*#__PURE__*/React.createContext(undefined);
|
|
707
|
+
var useLanguageState = function useLanguageState(language) {
|
|
708
|
+
var _useState = useState(language),
|
|
709
|
+
activeLanguage = _useState[0],
|
|
710
|
+
setLanguage = _useState[1];
|
|
711
|
+
useEffect(function () {
|
|
712
|
+
languageStorage.set(activeLanguage);
|
|
713
|
+
}, [activeLanguage]);
|
|
714
|
+
return [activeLanguage, setLanguage];
|
|
715
|
+
};
|
|
716
|
+
var useLanguage = function useLanguage() {
|
|
717
|
+
var context = useContext(LanguageContext);
|
|
718
|
+
assertIsDefined(context);
|
|
719
|
+
return context;
|
|
720
|
+
};
|
|
721
|
+
var LanguageProvider = function LanguageProvider(_ref) {
|
|
722
|
+
var children = _ref.children,
|
|
723
|
+
language = _ref.language;
|
|
724
|
+
var _useLanguageState = useLanguageState(language),
|
|
725
|
+
activeLanguage = _useLanguageState[0],
|
|
726
|
+
setLanguage = _useLanguageState[1];
|
|
727
|
+
return React.createElement(LanguageContext.Provider, {
|
|
728
|
+
value: {
|
|
729
|
+
language: activeLanguage,
|
|
730
|
+
setLanguage: setLanguage
|
|
731
|
+
}
|
|
732
|
+
}, children);
|
|
607
733
|
};
|
|
608
734
|
|
|
609
735
|
var MenuContext = /*#__PURE__*/React.createContext({
|
|
@@ -641,7 +767,7 @@ var MenuProvider = function MenuProvider(_ref) {
|
|
|
641
767
|
var _extends2;
|
|
642
768
|
return _extends({}, prevState, (_extends2 = {}, _extends2[path] = newItems, _extends2));
|
|
643
769
|
});
|
|
644
|
-
}, [
|
|
770
|
+
}, []);
|
|
645
771
|
var getMFNavigate = function getMFNavigate(path) {
|
|
646
772
|
return navFuncs[path];
|
|
647
773
|
};
|
|
@@ -664,29 +790,42 @@ var MenuProvider = function MenuProvider(_ref) {
|
|
|
664
790
|
}, children);
|
|
665
791
|
};
|
|
666
792
|
|
|
667
|
-
var
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
793
|
+
var _excluded$1 = ["navigate", "children", "onClick", "target"];
|
|
794
|
+
function isModifiedEvent(event) {
|
|
795
|
+
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
796
|
+
}
|
|
797
|
+
var MicroFrontendLink = function MicroFrontendLink(_ref) {
|
|
798
|
+
var navigate = _ref.navigate,
|
|
799
|
+
children = _ref.children,
|
|
800
|
+
_onClick = _ref.onClick,
|
|
801
|
+
target = _ref.target,
|
|
802
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
803
|
+
return (
|
|
804
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: Ignore lint rule for now. No changes in code.
|
|
805
|
+
React.createElement("a", _extends({
|
|
806
|
+
// biome-ignore lint/a11y/useValidAnchor: Ignore lint rule for now. No changes in code.
|
|
807
|
+
onClick: function onClick(event) {
|
|
808
|
+
try {
|
|
809
|
+
if (_onClick) _onClick(event);
|
|
810
|
+
} catch (ex) {
|
|
811
|
+
event.preventDefault();
|
|
812
|
+
throw ex;
|
|
813
|
+
}
|
|
814
|
+
if (!event.defaultPrevented &&
|
|
815
|
+
// onClick prevented default
|
|
816
|
+
event.button === 0 && (
|
|
817
|
+
// ignore everything but right clicks
|
|
818
|
+
!target || target === "_self") &&
|
|
819
|
+
// let browser handle "target=_blank" etc.
|
|
820
|
+
!isModifiedEvent(event) // ignore clicks with modifier keys
|
|
821
|
+
) {
|
|
822
|
+
event.preventDefault();
|
|
823
|
+
navigate();
|
|
824
|
+
}
|
|
825
|
+
},
|
|
826
|
+
target: target
|
|
827
|
+
}, rest), children)
|
|
828
|
+
);
|
|
690
829
|
};
|
|
691
830
|
|
|
692
831
|
var OrganisationContext = /*#__PURE__*/React.createContext(undefined);
|
|
@@ -723,35 +862,6 @@ var OrganisationProvider = function OrganisationProvider(_ref) {
|
|
|
723
862
|
}, children);
|
|
724
863
|
};
|
|
725
864
|
|
|
726
|
-
var LanguageContext = /*#__PURE__*/React.createContext(undefined);
|
|
727
|
-
var useLanguageState = function useLanguageState(language) {
|
|
728
|
-
var _useState = useState(language),
|
|
729
|
-
activeLanguage = _useState[0],
|
|
730
|
-
setLanguage = _useState[1];
|
|
731
|
-
useEffect(function () {
|
|
732
|
-
languageStorage.set(activeLanguage);
|
|
733
|
-
}, [activeLanguage]);
|
|
734
|
-
return [activeLanguage, setLanguage];
|
|
735
|
-
};
|
|
736
|
-
var useLanguage = function useLanguage() {
|
|
737
|
-
var context = useContext(LanguageContext);
|
|
738
|
-
assertIsDefined(context);
|
|
739
|
-
return context;
|
|
740
|
-
};
|
|
741
|
-
var LanguageProvider = function LanguageProvider(_ref) {
|
|
742
|
-
var children = _ref.children,
|
|
743
|
-
language = _ref.language;
|
|
744
|
-
var _useLanguageState = useLanguageState(language),
|
|
745
|
-
activeLanguage = _useLanguageState[0],
|
|
746
|
-
setLanguage = _useLanguageState[1];
|
|
747
|
-
return React.createElement(LanguageContext.Provider, {
|
|
748
|
-
value: {
|
|
749
|
-
language: activeLanguage,
|
|
750
|
-
setLanguage: setLanguage
|
|
751
|
-
}
|
|
752
|
-
}, children);
|
|
753
|
-
};
|
|
754
|
-
|
|
755
865
|
var OrganisationsError = /*#__PURE__*/function (_Error) {
|
|
756
866
|
function OrganisationsError() {
|
|
757
867
|
var _this;
|
|
@@ -759,7 +869,7 @@ var OrganisationsError = /*#__PURE__*/function (_Error) {
|
|
|
759
869
|
args[_key] = arguments[_key];
|
|
760
870
|
}
|
|
761
871
|
_this = _Error.call.apply(_Error, [this].concat(args)) || this;
|
|
762
|
-
_this.message =
|
|
872
|
+
_this.message = "Failed fetching organisations";
|
|
763
873
|
return _this;
|
|
764
874
|
}
|
|
765
875
|
_inheritsLoose(OrganisationsError, _Error);
|
|
@@ -778,7 +888,7 @@ var OrganisationSelector = function OrganisationSelector(_ref) {
|
|
|
778
888
|
setOrganisations = _useState[1];
|
|
779
889
|
var _useLanguage = useLanguage(),
|
|
780
890
|
language = _useLanguage.language;
|
|
781
|
-
var _useState2 = useState(
|
|
891
|
+
var _useState2 = useState("LOADING"),
|
|
782
892
|
status = _useState2[0],
|
|
783
893
|
setStatus = _useState2[1];
|
|
784
894
|
useEffect(function () {
|
|
@@ -792,7 +902,7 @@ var OrganisationSelector = function OrganisationSelector(_ref) {
|
|
|
792
902
|
return getToken();
|
|
793
903
|
case 2:
|
|
794
904
|
token = _context.sent;
|
|
795
|
-
if (!(typeof getOrganisations ===
|
|
905
|
+
if (!(typeof getOrganisations === "string")) {
|
|
796
906
|
_context.next = 9;
|
|
797
907
|
break;
|
|
798
908
|
}
|
|
@@ -800,7 +910,7 @@ var OrganisationSelector = function OrganisationSelector(_ref) {
|
|
|
800
910
|
return fetch(getOrganisations, {
|
|
801
911
|
headers: {
|
|
802
912
|
Authorization: "Bearer " + token,
|
|
803
|
-
Accept:
|
|
913
|
+
Accept: "application/json"
|
|
804
914
|
}
|
|
805
915
|
}).then(function (response) {
|
|
806
916
|
return response.json();
|
|
@@ -816,7 +926,7 @@ var OrganisationSelector = function OrganisationSelector(_ref) {
|
|
|
816
926
|
organisations = _context.sent;
|
|
817
927
|
case 12:
|
|
818
928
|
setOrganisations(organisations);
|
|
819
|
-
setStatus(
|
|
929
|
+
setStatus("SUCCESS");
|
|
820
930
|
case 14:
|
|
821
931
|
case "end":
|
|
822
932
|
return _context.stop();
|
|
@@ -828,139 +938,35 @@ var OrganisationSelector = function OrganisationSelector(_ref) {
|
|
|
828
938
|
};
|
|
829
939
|
}();
|
|
830
940
|
fetchOrganisations()["catch"](function (error) {
|
|
831
|
-
if (process.env.NODE_ENV ===
|
|
941
|
+
if (process.env.NODE_ENV === "development") {
|
|
832
942
|
console.error(error);
|
|
833
943
|
}
|
|
834
|
-
setStatus(
|
|
944
|
+
setStatus("ERROR");
|
|
835
945
|
});
|
|
836
946
|
}, [getOrganisations, getToken]);
|
|
837
947
|
switch (status) {
|
|
838
|
-
case
|
|
948
|
+
case "LOADING":
|
|
839
949
|
return React.createElement("div", {
|
|
840
950
|
className: "eds-contrast"
|
|
841
951
|
}, React.createElement(SkeletonRectangle, {
|
|
842
952
|
style: {
|
|
843
|
-
height:
|
|
953
|
+
height: "2.4rem"
|
|
844
954
|
}
|
|
845
955
|
}));
|
|
846
|
-
case
|
|
956
|
+
case "SUCCESS":
|
|
847
957
|
return React.createElement(OrganisationDropDown, _extends({
|
|
848
|
-
label: language ===
|
|
958
|
+
label: language === "nb" || language === "nb-NO" ? "Organisasjon" : "Organisation",
|
|
849
959
|
selectedOrganisationId: selectedOrganisationId,
|
|
850
960
|
organisations: organisations,
|
|
851
961
|
onChange: onChange
|
|
852
962
|
}, rest));
|
|
853
|
-
case
|
|
963
|
+
case "ERROR":
|
|
854
964
|
throw new OrganisationsError();
|
|
855
965
|
default:
|
|
856
966
|
return null;
|
|
857
967
|
}
|
|
858
968
|
};
|
|
859
969
|
|
|
860
|
-
var SERVICE_NAMES = {
|
|
861
|
-
Usercentrics: 'Usercentrics Consent Management Platform',
|
|
862
|
-
PostHog: 'PostHog.com',
|
|
863
|
-
Sentry: 'Sentry'
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
var DEFAULT_CONSENT_GIVEN = {
|
|
867
|
-
Usercentrics: {
|
|
868
|
-
consentGiven: false
|
|
869
|
-
},
|
|
870
|
-
PostHog: {
|
|
871
|
-
consentGiven: false
|
|
872
|
-
},
|
|
873
|
-
Sentry: {
|
|
874
|
-
consentGiven: false
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
var convertUCServicesToConsents = function convertUCServicesToConsents(services) {
|
|
878
|
-
return services.map(function (service) {
|
|
879
|
-
var _Object$entries$find, _ref3;
|
|
880
|
-
var serviceName = (_Object$entries$find = Object.entries(SERVICE_NAMES).find(function (keyValue) {
|
|
881
|
-
return keyValue[1] === service.name;
|
|
882
|
-
})) == null ? void 0 : _Object$entries$find[0];
|
|
883
|
-
// Ensure the service name exists in SERVICE_NAMES
|
|
884
|
-
assertIsDefined(serviceName, "Service name " + service.name + " not found in SERVICE_NAMES");
|
|
885
|
-
if (typeof service.consent == 'boolean') {
|
|
886
|
-
var _ref;
|
|
887
|
-
var consentGiven = service.consent;
|
|
888
|
-
return _ref = {}, _ref[serviceName] = {
|
|
889
|
-
consentGiven: consentGiven
|
|
890
|
-
}, _ref;
|
|
891
|
-
} else if (typeof service.consent === 'object' && 'given' in service.consent) {
|
|
892
|
-
var _ref2;
|
|
893
|
-
var _consentGiven = service.consent.given;
|
|
894
|
-
return _ref2 = {}, _ref2[serviceName] = {
|
|
895
|
-
consentGiven: _consentGiven
|
|
896
|
-
}, _ref2;
|
|
897
|
-
}
|
|
898
|
-
return _ref3 = {}, _ref3[serviceName] = {
|
|
899
|
-
consentGiven: false
|
|
900
|
-
}, _ref3;
|
|
901
|
-
}).reduce(function (acc, curr) {
|
|
902
|
-
return _extends({}, acc, curr);
|
|
903
|
-
}, DEFAULT_CONSENT_GIVEN);
|
|
904
|
-
};
|
|
905
|
-
|
|
906
|
-
var ConsentContext = /*#__PURE__*/createContext(DEFAULT_CONSENT_GIVEN);
|
|
907
|
-
var useConsentManager = function useConsentManager() {
|
|
908
|
-
var context = useContext(ConsentContext);
|
|
909
|
-
return context;
|
|
910
|
-
};
|
|
911
|
-
var ConsentManagerProvider = function ConsentManagerProvider(_ref) {
|
|
912
|
-
var children = _ref.children;
|
|
913
|
-
var _useState = useState(DEFAULT_CONSENT_GIVEN),
|
|
914
|
-
consentManager = _useState[0],
|
|
915
|
-
setConsentManager = _useState[1];
|
|
916
|
-
// Initialize consent manager from local storage once
|
|
917
|
-
useEffect(function () {
|
|
918
|
-
if (typeof window === 'undefined') return;
|
|
919
|
-
var ucData = ucUiStorage.get();
|
|
920
|
-
if (ucData) {
|
|
921
|
-
var data = JSON.parse(ucData);
|
|
922
|
-
var services = convertUCServicesToConsents(Object.values(data.consent.services));
|
|
923
|
-
setConsentManager(services);
|
|
924
|
-
}
|
|
925
|
-
}, []);
|
|
926
|
-
// Listen for Usercentrics consent events and update consent manager state
|
|
927
|
-
useEffect(function () {
|
|
928
|
-
var handleConsentEvent = /*#__PURE__*/function () {
|
|
929
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
930
|
-
var customEvent, services, updatedConsentManager;
|
|
931
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
932
|
-
while (1) switch (_context.prev = _context.next) {
|
|
933
|
-
case 0:
|
|
934
|
-
if (!(typeof window === 'undefined')) {
|
|
935
|
-
_context.next = 2;
|
|
936
|
-
break;
|
|
937
|
-
}
|
|
938
|
-
return _context.abrupt("return");
|
|
939
|
-
case 2:
|
|
940
|
-
customEvent = event;
|
|
941
|
-
services = Object.values(customEvent.detail.services);
|
|
942
|
-
updatedConsentManager = convertUCServicesToConsents(services);
|
|
943
|
-
setConsentManager(updatedConsentManager);
|
|
944
|
-
case 6:
|
|
945
|
-
case "end":
|
|
946
|
-
return _context.stop();
|
|
947
|
-
}
|
|
948
|
-
}, _callee);
|
|
949
|
-
}));
|
|
950
|
-
return function handleConsentEvent(_x) {
|
|
951
|
-
return _ref2.apply(this, arguments);
|
|
952
|
-
};
|
|
953
|
-
}();
|
|
954
|
-
window.addEventListener('UC_CONSENT', handleConsentEvent);
|
|
955
|
-
return function () {
|
|
956
|
-
return window.removeEventListener('UC_CONSENT', handleConsentEvent);
|
|
957
|
-
};
|
|
958
|
-
}, []);
|
|
959
|
-
return React.createElement(ConsentContext.Provider, {
|
|
960
|
-
value: consentManager
|
|
961
|
-
}, children);
|
|
962
|
-
};
|
|
963
|
-
|
|
964
970
|
var PostHogProviderWrapper = function PostHogProviderWrapper(_ref) {
|
|
965
971
|
var _ref$debug = _ref.debug,
|
|
966
972
|
debug = _ref$debug === void 0 ? false : _ref$debug,
|
|
@@ -984,16 +990,16 @@ var PostHogProviderWrapper = function PostHogProviderWrapper(_ref) {
|
|
|
984
990
|
// If no API key is provided or PostHog is forced to be disabled, do not initialize PostHog
|
|
985
991
|
if (!postHogApiKey || forceDisablePostHog) {
|
|
986
992
|
if (!forceDisablePostHog) {
|
|
987
|
-
console.warn(
|
|
993
|
+
console.warn("AppShellStandalone Warning: PostHog API key is not provided. PostHog will not be initialized.");
|
|
988
994
|
} else {
|
|
989
|
-
console.warn(
|
|
995
|
+
console.warn("AppShellStandalone Warning: PostHog tracking is disabled by force. PostHog will not be initialized.");
|
|
990
996
|
}
|
|
991
997
|
return React.createElement(React.Fragment, null, children);
|
|
992
998
|
}
|
|
993
999
|
postHog.init(postHogApiKey, {
|
|
994
1000
|
debug: debug,
|
|
995
|
-
api_host: isStandalone ?
|
|
996
|
-
ui_host:
|
|
1001
|
+
api_host: isStandalone ? "https://eu.posthog.com" : "/ingest",
|
|
1002
|
+
ui_host: "https://eu.posthog.com",
|
|
997
1003
|
opt_out_capturing_by_default: true,
|
|
998
1004
|
autocapture: isStandalone
|
|
999
1005
|
}, project);
|