@entur-partner/app-shell 6.4.1 → 6.4.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.
@@ -1,853 +0,0 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
3
- import { BannerAlertBox } from '@entur/alert';
4
- import { Loader, SkeletonRectangle } from '@entur/loader';
5
- import { space } from '@entur/tokens';
6
- import { Paragraph, Link, CodeText } from '@entur/typography';
7
- import { getColorForEnvironment, Environment, OrganisationDropDown } from '@entur-partner/common';
8
- import { assertIsDefined } from '@entur-partner/util';
9
- import { useState, useEffect, useContext, createContext, useCallback } from 'react';
10
- import postHog from 'posthog-js';
11
- import { PostHogProvider } from 'posthog-js/react';
12
-
13
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
14
- try {
15
- var i = n[a](c),
16
- u = i.value;
17
- } catch (n) {
18
- return void e(n);
19
- }
20
- i.done ? t(u) : Promise.resolve(u).then(r, o);
21
- }
22
- function _asyncToGenerator(n) {
23
- return function () {
24
- var t = this,
25
- e = arguments;
26
- return new Promise(function (r, o) {
27
- var a = n.apply(t, e);
28
- function _next(n) {
29
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
30
- }
31
- function _throw(n) {
32
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
33
- }
34
- _next(void 0);
35
- });
36
- };
37
- }
38
- function _construct(t, e, r) {
39
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
40
- var o = [null];
41
- o.push.apply(o, e);
42
- var p = new (t.bind.apply(t, o))();
43
- return r && _setPrototypeOf(p, r.prototype), p;
44
- }
45
- function _extends() {
46
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
47
- for (var e = 1; e < arguments.length; e++) {
48
- var t = arguments[e];
49
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
50
- }
51
- return n;
52
- }, _extends.apply(null, arguments);
53
- }
54
- function _getPrototypeOf(t) {
55
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
56
- return t.__proto__ || Object.getPrototypeOf(t);
57
- }, _getPrototypeOf(t);
58
- }
59
- function _inheritsLoose(t, o) {
60
- t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
61
- }
62
- function _isNativeFunction(t) {
63
- try {
64
- return -1 !== Function.toString.call(t).indexOf("[native code]");
65
- } catch (n) {
66
- return "function" == typeof t;
67
- }
68
- }
69
- function _isNativeReflectConstruct() {
70
- try {
71
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
72
- } catch (t) {}
73
- return (_isNativeReflectConstruct = function () {
74
- return !!t;
75
- })();
76
- }
77
- function _objectWithoutPropertiesLoose(r, e) {
78
- if (null == r) return {};
79
- var t = {};
80
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
81
- if (-1 !== e.indexOf(n)) continue;
82
- t[n] = r[n];
83
- }
84
- return t;
85
- }
86
- function _regenerator() {
87
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
88
- var e,
89
- t,
90
- r = "function" == typeof Symbol ? Symbol : {},
91
- n = r.iterator || "@@iterator",
92
- o = r.toStringTag || "@@toStringTag";
93
- function i(r, n, o, i) {
94
- var c = n && n.prototype instanceof Generator ? n : Generator,
95
- u = Object.create(c.prototype);
96
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
97
- var i,
98
- c,
99
- u,
100
- f = 0,
101
- p = o || [],
102
- y = !1,
103
- G = {
104
- p: 0,
105
- n: 0,
106
- v: e,
107
- a: d,
108
- f: d.bind(e, 4),
109
- d: function (t, r) {
110
- return i = t, c = 0, u = e, G.n = r, a;
111
- }
112
- };
113
- function d(r, n) {
114
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
115
- var o,
116
- i = p[t],
117
- d = G.p,
118
- l = i[2];
119
- r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
120
- }
121
- if (o || r > 1) return a;
122
- throw y = !0, n;
123
- }
124
- return function (o, p, l) {
125
- if (f > 1) throw TypeError("Generator is already running");
126
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
127
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
128
- try {
129
- if (f = 2, i) {
130
- if (c || (o = "next"), t = i[o]) {
131
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
132
- if (!t.done) return t;
133
- u = t.value, c < 2 && (c = 0);
134
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
135
- i = e;
136
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
137
- } catch (t) {
138
- i = e, c = 1, u = t;
139
- } finally {
140
- f = 1;
141
- }
142
- }
143
- return {
144
- value: t,
145
- done: y
146
- };
147
- };
148
- }(r, o, i), !0), u;
149
- }
150
- var a = {};
151
- function Generator() {}
152
- function GeneratorFunction() {}
153
- function GeneratorFunctionPrototype() {}
154
- t = Object.getPrototypeOf;
155
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
156
- return this;
157
- }), t),
158
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
159
- function f(e) {
160
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
161
- }
162
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
163
- return this;
164
- }), _regeneratorDefine(u, "toString", function () {
165
- return "[object Generator]";
166
- }), (_regenerator = function () {
167
- return {
168
- w: i,
169
- m: f
170
- };
171
- })();
172
- }
173
- function _regeneratorDefine(e, r, n, t) {
174
- var i = Object.defineProperty;
175
- try {
176
- i({}, "", {});
177
- } catch (e) {
178
- i = 0;
179
- }
180
- _regeneratorDefine = function (e, r, n, t) {
181
- function o(r, n) {
182
- _regeneratorDefine(e, r, function (e) {
183
- return this._invoke(r, n, e);
184
- });
185
- }
186
- r ? i ? i(e, r, {
187
- value: n,
188
- enumerable: !t,
189
- configurable: !t,
190
- writable: !t
191
- }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
192
- }, _regeneratorDefine(e, r, n, t);
193
- }
194
- function _setPrototypeOf(t, e) {
195
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
196
- return t.__proto__ = e, t;
197
- }, _setPrototypeOf(t, e);
198
- }
199
- function _wrapNativeSuper(t) {
200
- var r = "function" == typeof Map ? new Map() : void 0;
201
- return _wrapNativeSuper = function (t) {
202
- if (null === t || !_isNativeFunction(t)) return t;
203
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
204
- if (void 0 !== r) {
205
- if (r.has(t)) return r.get(t);
206
- r.set(t, Wrapper);
207
- }
208
- function Wrapper() {
209
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
210
- }
211
- return Wrapper.prototype = Object.create(t.prototype, {
212
- constructor: {
213
- value: Wrapper,
214
- enumerable: !1,
215
- writable: !0,
216
- configurable: !0
217
- }
218
- }), _setPrototypeOf(Wrapper, t);
219
- }, _wrapNativeSuper(t);
220
- }
221
-
222
- var EnvironmentBanner = function EnvironmentBanner(_ref) {
223
- var environment = _ref.environment;
224
- return jsx("div", {
225
- className: "epp-environment-banner",
226
- style: {
227
- position: "fixed",
228
- zIndex: 9999,
229
- top: 0,
230
- left: 0,
231
- right: 0,
232
- width: "100vw",
233
- height: "16px",
234
- backgroundColor: getColorForEnvironment(environment)
235
- }
236
- });
237
- };
238
-
239
- function userLogout(logout) {
240
- var _window$location = window.location,
241
- protocol = _window$location.protocol,
242
- hostname = _window$location.hostname,
243
- port = _window$location.port;
244
- return logout({
245
- logoutParams: {
246
- returnTo: protocol + "//" + hostname + ":" + port
247
- }
248
- });
249
- }
250
- var Authenticate = function Authenticate(_ref) {
251
- var children = _ref.children,
252
- decorateUser = _ref.decorateUser,
253
- getReturnPath = _ref.getReturnPath;
254
- var _useState = useState(undefined),
255
- userWithPermission = _useState[0],
256
- setUserWithPermission = _useState[1];
257
- var _useAuth = useAuth0(),
258
- user = _useAuth.user,
259
- getAccessTokenSilently = _useAuth.getAccessTokenSilently,
260
- loginWithRedirect = _useAuth.loginWithRedirect,
261
- _logout = _useAuth.logout,
262
- isLoading = _useAuth.isLoading,
263
- isAuthenticated = _useAuth.isAuthenticated,
264
- error = _useAuth.error;
265
- useEffect(function () {
266
- var fetchUserData = /*#__PURE__*/function () {
267
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
268
- var token, decoratedUser, _t;
269
- return _regenerator().w(function (_context) {
270
- while (1) switch (_context.p = _context.n) {
271
- case 0:
272
- _context.p = 0;
273
- _context.n = 1;
274
- return getAccessTokenSilently();
275
- case 1:
276
- token = _context.v;
277
- _context.n = 2;
278
- return decorateUser(user, token);
279
- case 2:
280
- decoratedUser = _context.v;
281
- setUserWithPermission(decoratedUser);
282
- _context.n = 4;
283
- break;
284
- case 3:
285
- _context.p = 3;
286
- _t = _context.v;
287
- console.error("Error fetching user data:", _t);
288
- case 4:
289
- return _context.a(2);
290
- }
291
- }, _callee, null, [[0, 3]]);
292
- }));
293
- return function fetchUserData() {
294
- return _ref2.apply(this, arguments);
295
- };
296
- }();
297
- if (isAuthenticated) {
298
- fetchUserData();
299
- }
300
- }, [decorateUser, getAccessTokenSilently, isAuthenticated, user]);
301
- if (!isLoading && !isAuthenticated) {
302
- loginWithRedirect({
303
- appState: {
304
- returnTo: getReturnPath()
305
- }
306
- });
307
- return jsx(Loader, {
308
- style: {
309
- marginTop: space.extraLarge9
310
- },
311
- children: "Redirecting to login page"
312
- });
313
- }
314
- if (isLoading || !userWithPermission) {
315
- return jsx(Loader, {
316
- style: {
317
- marginTop: space.extraLarge9
318
- },
319
- children: "Authenticating"
320
- });
321
- }
322
- if (error) {
323
- process.env.NODE_ENV !== "production" && console.error(error);
324
- return jsxs(BannerAlertBox, {
325
- variant: "error",
326
- title: "Authentication failed",
327
- style: {
328
- maxWidth: "600px",
329
- margin: "0 auto"
330
- },
331
- children: [jsxs(Paragraph, {
332
- children: ["Something went wrong while trying to authenticate you. If the problem persists you should contact", " ", jsx(Link, {
333
- href: "mailto:support@entur.org",
334
- children: "support@entur.org"
335
- }), " to get it resolved."]
336
- }), jsxs(Paragraph, {
337
- children: ["Authentication failed with: ", jsx(CodeText, {
338
- children: error == null ? void 0 : error.toString()
339
- })]
340
- })]
341
- });
342
- }
343
- assertIsDefined(userWithPermission);
344
- return jsx(Fragment, {
345
- children: children({
346
- user: userWithPermission,
347
- logout: function logout() {
348
- return userLogout(_logout);
349
- },
350
- getToken: getAccessTokenSilently
351
- })
352
- });
353
- };
354
- var AppShell = function AppShell(_ref3) {
355
- var _children = _ref3.children,
356
- audience = _ref3.audience,
357
- domain = _ref3.domain,
358
- clientId = _ref3.clientId,
359
- decorateUser = _ref3.decorateUser,
360
- environment = _ref3.environment,
361
- redirectUri = _ref3.redirectUri,
362
- navigate = _ref3.navigate;
363
- // Central place to derive current in-app location (excluding origin)
364
- var getCurrentAppPath = function getCurrentAppPath() {
365
- return "" + window.location.pathname + window.location.search + window.location.hash;
366
- };
367
- // Provide an Auth0 onRedirectCallback that restores the stored path
368
- var handleRedirectCallback = function handleRedirectCallback(appState) {
369
- var target = appState == null ? void 0 : appState.returnTo;
370
- var destination = redirectUri || target || "/";
371
- if (navigate) {
372
- navigate(destination, {
373
- replace: true
374
- });
375
- } else {
376
- // Fallback: use History API
377
- window.history.replaceState({}, "", destination);
378
- }
379
- };
380
- return jsx(Auth0Provider, {
381
- domain: domain,
382
- clientId: clientId,
383
- authorizationParams: {
384
- redirect_uri: redirectUri != null ? redirectUri : window.location.origin,
385
- audience: audience
386
- },
387
- onRedirectCallback: handleRedirectCallback,
388
- children: jsx(Authenticate, {
389
- decorateUser: decorateUser,
390
- getReturnPath: getCurrentAppPath,
391
- children: function children(params) {
392
- return jsxs(Fragment, {
393
- children: [environment && environment !== Environment.Production && jsx(EnvironmentBanner, {
394
- environment: environment
395
- }), _children(params)]
396
- });
397
- }
398
- })
399
- });
400
- };
401
-
402
- var ORGANISATION_STORAGE_KEY = "EP::activeOrgId";
403
- var organisationStorage = {
404
- get: function get() {
405
- return localStorage.getItem(ORGANISATION_STORAGE_KEY);
406
- },
407
- set: function set(value) {
408
- return localStorage.setItem(ORGANISATION_STORAGE_KEY, value);
409
- }
410
- };
411
- var LANGUAGE_STORAGE_KEY = "EP::locale";
412
- var languageStorage = {
413
- get: function get() {
414
- return localStorage.getItem(LANGUAGE_STORAGE_KEY);
415
- },
416
- set: function set(value) {
417
- return localStorage.setItem(LANGUAGE_STORAGE_KEY, value);
418
- }
419
- };
420
- var UC_UI_STORAGE_KEY = "ucData";
421
- var ucUiStorage = {
422
- get: function get() {
423
- return localStorage.getItem(UC_UI_STORAGE_KEY);
424
- }
425
- };
426
-
427
- var SERVICE_NAMES = {
428
- Usercentrics: "Usercentrics Consent Management Platform",
429
- PostHog: "PostHog.com",
430
- Sentry: "Sentry"
431
- };
432
-
433
- var DEFAULT_CONSENT_GIVEN = {
434
- Usercentrics: {
435
- consentGiven: false
436
- },
437
- PostHog: {
438
- consentGiven: false
439
- },
440
- Sentry: {
441
- consentGiven: false
442
- }
443
- };
444
- var convertUCServicesToConsents = function convertUCServicesToConsents(services) {
445
- return services.map(function (service) {
446
- var _Object$entries$find, _ref3;
447
- var serviceName = (_Object$entries$find = Object.entries(SERVICE_NAMES).find(function (keyValue) {
448
- return keyValue[1] === service.name;
449
- })) == null ? void 0 : _Object$entries$find[0];
450
- // Ensure the service name exists in SERVICE_NAMES
451
- assertIsDefined(serviceName, "Service name " + service.name + " not found in SERVICE_NAMES");
452
- if (typeof service.consent === "boolean") {
453
- var _ref;
454
- var consentGiven = service.consent;
455
- return _ref = {}, _ref[serviceName] = {
456
- consentGiven: consentGiven
457
- }, _ref;
458
- } else if (typeof service.consent === "object" && "given" in service.consent) {
459
- var _ref2;
460
- var _consentGiven = service.consent.given;
461
- return _ref2 = {}, _ref2[serviceName] = {
462
- consentGiven: _consentGiven
463
- }, _ref2;
464
- }
465
- return _ref3 = {}, _ref3[serviceName] = {
466
- consentGiven: false
467
- }, _ref3;
468
- }).reduce(
469
- // biome-ignore lint/performance/noAccumulatingSpread: Ignore it for now. No changes in code.
470
- function (acc, curr) {
471
- return _extends({}, acc, curr);
472
- }, DEFAULT_CONSENT_GIVEN);
473
- };
474
-
475
- var ConsentContext = /*#__PURE__*/createContext(DEFAULT_CONSENT_GIVEN);
476
- var useConsentManager = function useConsentManager() {
477
- var context = useContext(ConsentContext);
478
- return context;
479
- };
480
- var ConsentManagerProvider = function ConsentManagerProvider(_ref) {
481
- var children = _ref.children;
482
- var _useState = useState(DEFAULT_CONSENT_GIVEN),
483
- consentManager = _useState[0],
484
- setConsentManager = _useState[1];
485
- // Initialize consent manager from local storage once
486
- useEffect(function () {
487
- if (typeof window === "undefined") return;
488
- var ucData = ucUiStorage.get();
489
- if (ucData) {
490
- var data = JSON.parse(ucData);
491
- var services = convertUCServicesToConsents(Object.values(data.consent.services));
492
- setConsentManager(services);
493
- }
494
- }, []);
495
- // Listen for Usercentrics consent events and update consent manager state
496
- useEffect(function () {
497
- var handleConsentEvent = /*#__PURE__*/function () {
498
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(event) {
499
- var customEvent, services, updatedConsentManager;
500
- return _regenerator().w(function (_context) {
501
- while (1) switch (_context.n) {
502
- case 0:
503
- if (!(typeof window === "undefined")) {
504
- _context.n = 1;
505
- break;
506
- }
507
- return _context.a(2);
508
- case 1:
509
- customEvent = event;
510
- services = Object.values(customEvent.detail.services);
511
- updatedConsentManager = convertUCServicesToConsents(services);
512
- setConsentManager(updatedConsentManager);
513
- case 2:
514
- return _context.a(2);
515
- }
516
- }, _callee);
517
- }));
518
- return function handleConsentEvent(_x) {
519
- return _ref2.apply(this, arguments);
520
- };
521
- }();
522
- window.addEventListener("UC_CONSENT", handleConsentEvent);
523
- return function () {
524
- return window.removeEventListener("UC_CONSENT", handleConsentEvent);
525
- };
526
- }, []);
527
- return jsx(ConsentContext.Provider, {
528
- value: consentManager,
529
- children: children
530
- });
531
- };
532
-
533
- var LanguageContext = /*#__PURE__*/createContext(undefined);
534
- var useLanguageState = function useLanguageState(language) {
535
- var _useState = useState(language),
536
- activeLanguage = _useState[0],
537
- setLanguage = _useState[1];
538
- useEffect(function () {
539
- languageStorage.set(activeLanguage);
540
- }, [activeLanguage]);
541
- return [activeLanguage, setLanguage];
542
- };
543
- var useLanguage = function useLanguage() {
544
- var context = useContext(LanguageContext);
545
- assertIsDefined(context);
546
- return context;
547
- };
548
- var LanguageProvider = function LanguageProvider(_ref) {
549
- var children = _ref.children,
550
- language = _ref.language;
551
- var _useLanguageState = useLanguageState(language),
552
- activeLanguage = _useLanguageState[0],
553
- setLanguage = _useLanguageState[1];
554
- return jsx(LanguageContext.Provider, {
555
- value: {
556
- language: activeLanguage,
557
- setLanguage: setLanguage
558
- },
559
- children: children
560
- });
561
- };
562
-
563
- var MenuContext = /*#__PURE__*/createContext({
564
- addItems: function addItems() {},
565
- getItemsForPath: function getItemsForPath() {
566
- return [];
567
- },
568
- getMFNavigate: function getMFNavigate() {
569
- return undefined;
570
- },
571
- setMFNavigate: function setMFNavigate() {},
572
- getItemGroupsPerPath: function getItemGroupsPerPath() {
573
- return {};
574
- }
575
- });
576
- var useMenuGroupItems = function useMenuGroupItems(path) {
577
- var context = useContext(MenuContext);
578
- return context.getItemsForPath(path);
579
- };
580
- var useMenu = function useMenu() {
581
- return useContext(MenuContext);
582
- };
583
- var useMFNavigation = function useMFNavigation(path) {
584
- var _useMenu = useMenu(),
585
- getMFNavigate = _useMenu.getMFNavigate;
586
- return getMFNavigate(path);
587
- };
588
- var MenuProvider = function MenuProvider(_ref) {
589
- var children = _ref.children;
590
- var _useState = useState({}),
591
- groups = _useState[0],
592
- setGroups = _useState[1];
593
- var _useState2 = useState({}),
594
- navFuncs = _useState2[0],
595
- setNavFuncs = _useState2[1];
596
- var addItems = useCallback(function (newItems, path) {
597
- setGroups(function (prevState) {
598
- var _extends2;
599
- return _extends({}, prevState, (_extends2 = {}, _extends2[path] = newItems, _extends2));
600
- });
601
- }, []);
602
- var getMFNavigate = function getMFNavigate(path) {
603
- return navFuncs[path];
604
- };
605
- var setMFNavigate = function setMFNavigate(path, navigation) {
606
- return setNavFuncs(function (prev) {
607
- var _extends3;
608
- return _extends({}, prev, (_extends3 = {}, _extends3[path] = navigation, _extends3));
609
- });
610
- };
611
- return jsx(MenuContext.Provider, {
612
- value: {
613
- addItems: addItems,
614
- getItemGroupsPerPath: function getItemGroupsPerPath() {
615
- return groups;
616
- },
617
- getItemsForPath: function getItemsForPath(path) {
618
- var _groups$path;
619
- return (_groups$path = groups[path]) != null ? _groups$path : [];
620
- },
621
- getMFNavigate: getMFNavigate,
622
- setMFNavigate: setMFNavigate
623
- },
624
- children: children
625
- });
626
- };
627
-
628
- var _excluded$1 = ["navigate", "children", "onClick", "target"];
629
- function isModifiedEvent(event) {
630
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
631
- }
632
- var MicroFrontendLink = function MicroFrontendLink(_ref) {
633
- var navigate = _ref.navigate,
634
- children = _ref.children,
635
- _onClick = _ref.onClick,
636
- target = _ref.target,
637
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
638
- return (
639
- // biome-ignore lint/a11y/noStaticElementInteractions: Ignore lint rule for now. No changes in code.
640
- jsx("a", _extends({
641
- // biome-ignore lint/a11y/useValidAnchor: Ignore lint rule for now. No changes in code.
642
- onClick: function onClick(event) {
643
- try {
644
- if (_onClick) _onClick(event);
645
- } catch (ex) {
646
- event.preventDefault();
647
- throw ex;
648
- }
649
- if (!event.defaultPrevented &&
650
- // onClick prevented default
651
- event.button === 0 && (
652
- // ignore everything but right clicks
653
- !target || target === "_self") &&
654
- // let browser handle "target=_blank" etc.
655
- !isModifiedEvent(event) // ignore clicks with modifier keys
656
- ) {
657
- event.preventDefault();
658
- navigate();
659
- }
660
- },
661
- target: target
662
- }, rest, {
663
- children: children
664
- }))
665
- );
666
- };
667
-
668
- var OrganisationContext = /*#__PURE__*/createContext(undefined);
669
- var useOrganisation = function useOrganisation() {
670
- var context = useContext(OrganisationContext);
671
- assertIsDefined(context);
672
- return context;
673
- };
674
- var useOrganisationId = function useOrganisationId() {
675
- var context = useContext(OrganisationContext);
676
- assertIsDefined(context);
677
- return context.organisationId;
678
- };
679
- var useOrganisationState = function useOrganisationState(initialOrganisationId) {
680
- var _useState = useState(Number(initialOrganisationId)),
681
- organisationId = _useState[0],
682
- setOrganisationId = _useState[1];
683
- useEffect(function () {
684
- organisationStorage.set(organisationId.toString());
685
- }, [organisationId]);
686
- return [organisationId, setOrganisationId];
687
- };
688
- var OrganisationProvider = function OrganisationProvider(_ref) {
689
- var children = _ref.children,
690
- organisationId = _ref.organisationId;
691
- var _useOrganisationState = useOrganisationState(organisationId),
692
- orgId = _useOrganisationState[0],
693
- setOrganisationId = _useOrganisationState[1];
694
- return jsx(OrganisationContext.Provider, {
695
- value: {
696
- organisationId: orgId,
697
- setOrganisationId: setOrganisationId
698
- },
699
- children: children
700
- });
701
- };
702
-
703
- var OrganisationsError = /*#__PURE__*/function (_Error) {
704
- function OrganisationsError() {
705
- var _this;
706
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
707
- args[_key] = arguments[_key];
708
- }
709
- _this = _Error.call.apply(_Error, [this].concat(args)) || this;
710
- _this.message = "Failed fetching organisations";
711
- return _this;
712
- }
713
- _inheritsLoose(OrganisationsError, _Error);
714
- return OrganisationsError;
715
- }(/*#__PURE__*/_wrapNativeSuper(Error));
716
-
717
- var _excluded = ["getToken", "getOrganisations", "selectedOrganisationId", "onChange"];
718
- var OrganisationSelector = function OrganisationSelector(_ref) {
719
- var getToken = _ref.getToken,
720
- getOrganisations = _ref.getOrganisations,
721
- selectedOrganisationId = _ref.selectedOrganisationId,
722
- onChange = _ref.onChange,
723
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
724
- var _useState = useState([]),
725
- organisations = _useState[0],
726
- setOrganisations = _useState[1];
727
- var _useLanguage = useLanguage(),
728
- language = _useLanguage.language;
729
- var _useState2 = useState("LOADING"),
730
- status = _useState2[0],
731
- setStatus = _useState2[1];
732
- useEffect(function () {
733
- var fetchOrganisations = /*#__PURE__*/function () {
734
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
735
- var token, organisations;
736
- return _regenerator().w(function (_context) {
737
- while (1) switch (_context.n) {
738
- case 0:
739
- _context.n = 1;
740
- return getToken();
741
- case 1:
742
- token = _context.v;
743
- if (!(typeof getOrganisations === "string")) {
744
- _context.n = 3;
745
- break;
746
- }
747
- _context.n = 2;
748
- return fetch(getOrganisations, {
749
- headers: {
750
- Authorization: "Bearer " + token,
751
- Accept: "application/json"
752
- }
753
- }).then(function (response) {
754
- return response.json();
755
- });
756
- case 2:
757
- organisations = _context.v;
758
- _context.n = 5;
759
- break;
760
- case 3:
761
- _context.n = 4;
762
- return getOrganisations(token);
763
- case 4:
764
- organisations = _context.v;
765
- case 5:
766
- setOrganisations(organisations);
767
- setStatus("SUCCESS");
768
- case 6:
769
- return _context.a(2);
770
- }
771
- }, _callee);
772
- }));
773
- return function fetchOrganisations() {
774
- return _ref2.apply(this, arguments);
775
- };
776
- }();
777
- fetchOrganisations()["catch"](function (error) {
778
- if (process.env.NODE_ENV === "development") {
779
- console.error(error);
780
- }
781
- setStatus("ERROR");
782
- });
783
- }, [getOrganisations, getToken]);
784
- switch (status) {
785
- case "LOADING":
786
- return jsx("div", {
787
- className: "eds-contrast",
788
- children: jsx(SkeletonRectangle, {
789
- style: {
790
- height: "2.4rem"
791
- }
792
- })
793
- });
794
- case "SUCCESS":
795
- return jsx(OrganisationDropDown, _extends({
796
- label: language === "nb" || language === "nb-NO" ? "Organisasjon" : "Organisation",
797
- selectedOrganisationId: selectedOrganisationId,
798
- organisations: organisations,
799
- onChange: onChange
800
- }, rest));
801
- case "ERROR":
802
- throw new OrganisationsError();
803
- default:
804
- return null;
805
- }
806
- };
807
-
808
- var PostHogProviderWrapper = function PostHogProviderWrapper(_ref) {
809
- var _ref$debug = _ref.debug,
810
- debug = _ref$debug === void 0 ? false : _ref$debug,
811
- postHogApiKey = _ref.postHogApiKey,
812
- isStandalone = _ref.isStandalone,
813
- project = _ref.project,
814
- _ref$forceDisablePost = _ref.forceDisablePostHog,
815
- forceDisablePostHog = _ref$forceDisablePost === void 0 ? false : _ref$forceDisablePost,
816
- children = _ref.children;
817
- var consents = useConsentManager();
818
- useEffect(function () {
819
- if (!postHogApiKey || forceDisablePostHog) {
820
- return;
821
- }
822
- if (consents != null && consents.PostHog.consentGiven) {
823
- postHog.opt_in_capturing();
824
- } else {
825
- postHog.opt_out_capturing();
826
- }
827
- }, [consents.PostHog.consentGiven, forceDisablePostHog, postHogApiKey]);
828
- // If no API key is provided or PostHog is forced to be disabled, do not initialize PostHog
829
- if (!postHogApiKey || forceDisablePostHog) {
830
- if (!forceDisablePostHog) {
831
- console.warn("AppShellStandalone Warning: PostHog API key is not provided. PostHog will not be initialized.");
832
- } else {
833
- console.warn("AppShellStandalone Warning: PostHog tracking is disabled by force. PostHog will not be initialized.");
834
- }
835
- return jsx(Fragment, {
836
- children: children
837
- });
838
- }
839
- postHog.init(postHogApiKey, {
840
- debug: debug,
841
- api_host: isStandalone ? "https://eu.posthog.com" : "/ingest",
842
- ui_host: "https://eu.posthog.com",
843
- opt_out_capturing_by_default: true,
844
- autocapture: isStandalone
845
- }, project);
846
- return jsx(PostHogProvider, {
847
- client: postHog,
848
- children: children
849
- });
850
- };
851
-
852
- export { AppShell, ConsentManagerProvider, LanguageProvider, MenuProvider, MicroFrontendLink, OrganisationProvider, OrganisationSelector, OrganisationsError, PostHogProviderWrapper, languageStorage, organisationStorage, useConsentManager, useLanguage, useMFNavigation, useMenu, useMenuGroupItems, useOrganisation, useOrganisationId };
853
- //# sourceMappingURL=app-shell.esm.js.map