@entur-partner/app-shell 4.0.1 → 5.0.1

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,302 +1,327 @@
1
- import React, { useReducer, useState, useEffect, useContext, useCallback } from 'react';
2
- import { Loader, SkeletonRectangle } from '@entur/loader';
1
+ import React, { useState, useEffect, useContext, useCallback } from 'react';
3
2
  import { BannerAlertBox } from '@entur/alert';
4
- import { space } from '@entur/tokens';
5
3
  import { Paragraph, Link, CodeText } from '@entur/typography';
6
- import { assertIsDefined } from '@entur-partner/util';
4
+ import { Loader, SkeletonRectangle } from '@entur/loader';
5
+ import { space } from '@entur/tokens';
6
+ import { Auth0Provider, useAuth0 } from '@auth0/auth0-react';
7
7
  import { getColorForEnvironment, Environment, OrganisationDropDown } from '@entur-partner/common';
8
- import createAuth0Client from '@auth0/auth0-spa-js';
8
+ import { assertIsDefined } from '@entur-partner/util';
9
9
 
10
+ function _construct(t, e, r) {
11
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
12
+ var o = [null];
13
+ o.push.apply(o, e);
14
+ var p = new (t.bind.apply(t, o))();
15
+ return r && _setPrototypeOf(p, r.prototype), p;
16
+ }
17
+ function _isNativeReflectConstruct() {
18
+ try {
19
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
20
+ } catch (t) {}
21
+ return (_isNativeReflectConstruct = function () {
22
+ return !!t;
23
+ })();
24
+ }
10
25
  function _regeneratorRuntime() {
11
26
  _regeneratorRuntime = function () {
12
- return exports;
27
+ return e;
13
28
  };
14
- var exports = {},
15
- Op = Object.prototype,
16
- hasOwn = Op.hasOwnProperty,
17
- $Symbol = "function" == typeof Symbol ? Symbol : {},
18
- iteratorSymbol = $Symbol.iterator || "@@iterator",
19
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
20
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
21
- function define(obj, key, value) {
22
- return Object.defineProperty(obj, key, {
23
- value: value,
29
+ var t,
30
+ e = {},
31
+ r = Object.prototype,
32
+ n = r.hasOwnProperty,
33
+ o = Object.defineProperty || function (t, e, r) {
34
+ t[e] = r.value;
35
+ },
36
+ i = "function" == typeof Symbol ? Symbol : {},
37
+ a = i.iterator || "@@iterator",
38
+ c = i.asyncIterator || "@@asyncIterator",
39
+ u = i.toStringTag || "@@toStringTag";
40
+ function define(t, e, r) {
41
+ return Object.defineProperty(t, e, {
42
+ value: r,
24
43
  enumerable: !0,
25
44
  configurable: !0,
26
45
  writable: !0
27
- }), obj[key];
46
+ }), t[e];
28
47
  }
29
48
  try {
30
49
  define({}, "");
31
- } catch (err) {
32
- define = function (obj, key, value) {
33
- return obj[key] = value;
50
+ } catch (t) {
51
+ define = function (t, e, r) {
52
+ return t[e] = r;
34
53
  };
35
54
  }
36
- function wrap(innerFn, outerFn, self, tryLocsList) {
37
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
38
- generator = Object.create(protoGenerator.prototype),
39
- context = new Context(tryLocsList || []);
40
- return generator._invoke = function (innerFn, self, context) {
41
- var state = "suspendedStart";
42
- return function (method, arg) {
43
- if ("executing" === state) throw new Error("Generator is already running");
44
- if ("completed" === state) {
45
- if ("throw" === method) throw arg;
46
- return doneResult();
47
- }
48
- for (context.method = method, context.arg = arg;;) {
49
- var delegate = context.delegate;
50
- if (delegate) {
51
- var delegateResult = maybeInvokeDelegate(delegate, context);
52
- if (delegateResult) {
53
- if (delegateResult === ContinueSentinel) continue;
54
- return delegateResult;
55
- }
56
- }
57
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
58
- if ("suspendedStart" === state) throw state = "completed", context.arg;
59
- context.dispatchException(context.arg);
60
- } else "return" === context.method && context.abrupt("return", context.arg);
61
- state = "executing";
62
- var record = tryCatch(innerFn, self, context);
63
- if ("normal" === record.type) {
64
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
65
- return {
66
- value: record.arg,
67
- done: context.done
68
- };
69
- }
70
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
71
- }
72
- };
73
- }(innerFn, self, context), generator;
55
+ function wrap(t, e, r, n) {
56
+ var i = e && e.prototype instanceof Generator ? e : Generator,
57
+ a = Object.create(i.prototype),
58
+ c = new Context(n || []);
59
+ return o(a, "_invoke", {
60
+ value: makeInvokeMethod(t, r, c)
61
+ }), a;
74
62
  }
75
- function tryCatch(fn, obj, arg) {
63
+ function tryCatch(t, e, r) {
76
64
  try {
77
65
  return {
78
66
  type: "normal",
79
- arg: fn.call(obj, arg)
67
+ arg: t.call(e, r)
80
68
  };
81
- } catch (err) {
69
+ } catch (t) {
82
70
  return {
83
71
  type: "throw",
84
- arg: err
72
+ arg: t
85
73
  };
86
74
  }
87
75
  }
88
- exports.wrap = wrap;
89
- var ContinueSentinel = {};
76
+ e.wrap = wrap;
77
+ var h = "suspendedStart",
78
+ l = "suspendedYield",
79
+ f = "executing",
80
+ s = "completed",
81
+ y = {};
90
82
  function Generator() {}
91
83
  function GeneratorFunction() {}
92
84
  function GeneratorFunctionPrototype() {}
93
- var IteratorPrototype = {};
94
- define(IteratorPrototype, iteratorSymbol, function () {
85
+ var p = {};
86
+ define(p, a, function () {
95
87
  return this;
96
88
  });
97
- var getProto = Object.getPrototypeOf,
98
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
99
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
100
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
101
- function defineIteratorMethods(prototype) {
102
- ["next", "throw", "return"].forEach(function (method) {
103
- define(prototype, method, function (arg) {
104
- return this._invoke(method, arg);
89
+ var d = Object.getPrototypeOf,
90
+ v = d && d(d(values([])));
91
+ v && v !== r && n.call(v, a) && (p = v);
92
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
93
+ function defineIteratorMethods(t) {
94
+ ["next", "throw", "return"].forEach(function (e) {
95
+ define(t, e, function (t) {
96
+ return this._invoke(e, t);
105
97
  });
106
98
  });
107
99
  }
108
- function AsyncIterator(generator, PromiseImpl) {
109
- function invoke(method, arg, resolve, reject) {
110
- var record = tryCatch(generator[method], generator, arg);
111
- if ("throw" !== record.type) {
112
- var result = record.arg,
113
- value = result.value;
114
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
115
- invoke("next", value, resolve, reject);
116
- }, function (err) {
117
- invoke("throw", err, resolve, reject);
118
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
119
- result.value = unwrapped, resolve(result);
120
- }, function (error) {
121
- return invoke("throw", error, resolve, reject);
100
+ function AsyncIterator(t, e) {
101
+ function invoke(r, o, i, a) {
102
+ var c = tryCatch(t[r], t, o);
103
+ if ("throw" !== c.type) {
104
+ var u = c.arg,
105
+ h = u.value;
106
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
107
+ invoke("next", t, i, a);
108
+ }, function (t) {
109
+ invoke("throw", t, i, a);
110
+ }) : e.resolve(h).then(function (t) {
111
+ u.value = t, i(u);
112
+ }, function (t) {
113
+ return invoke("throw", t, i, a);
122
114
  });
123
115
  }
124
- reject(record.arg);
116
+ a(c.arg);
125
117
  }
126
- var previousPromise;
127
- this._invoke = function (method, arg) {
128
- function callInvokeWithMethodAndArg() {
129
- return new PromiseImpl(function (resolve, reject) {
130
- invoke(method, arg, resolve, reject);
131
- });
118
+ var r;
119
+ o(this, "_invoke", {
120
+ value: function (t, n) {
121
+ function callInvokeWithMethodAndArg() {
122
+ return new e(function (e, r) {
123
+ invoke(t, n, e, r);
124
+ });
125
+ }
126
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
132
127
  }
133
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
134
- };
128
+ });
135
129
  }
136
- function maybeInvokeDelegate(delegate, context) {
137
- var method = delegate.iterator[context.method];
138
- if (undefined === method) {
139
- if (context.delegate = null, "throw" === context.method) {
140
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
141
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
130
+ function makeInvokeMethod(e, r, n) {
131
+ var o = h;
132
+ return function (i, a) {
133
+ if (o === f) throw Error("Generator is already running");
134
+ if (o === s) {
135
+ if ("throw" === i) throw a;
136
+ return {
137
+ value: t,
138
+ done: !0
139
+ };
142
140
  }
143
- return ContinueSentinel;
144
- }
145
- var record = tryCatch(method, delegate.iterator, context.arg);
146
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
147
- var info = record.arg;
148
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
141
+ for (n.method = i, n.arg = a;;) {
142
+ var c = n.delegate;
143
+ if (c) {
144
+ var u = maybeInvokeDelegate(c, n);
145
+ if (u) {
146
+ if (u === y) continue;
147
+ return u;
148
+ }
149
+ }
150
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
151
+ if (o === h) throw o = s, n.arg;
152
+ n.dispatchException(n.arg);
153
+ } else "return" === n.method && n.abrupt("return", n.arg);
154
+ o = f;
155
+ var p = tryCatch(e, r, n);
156
+ if ("normal" === p.type) {
157
+ if (o = n.done ? s : l, p.arg === y) continue;
158
+ return {
159
+ value: p.arg,
160
+ done: n.done
161
+ };
162
+ }
163
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
164
+ }
165
+ };
149
166
  }
150
- function pushTryEntry(locs) {
151
- var entry = {
152
- tryLoc: locs[0]
167
+ function maybeInvokeDelegate(e, r) {
168
+ var n = r.method,
169
+ o = e.iterator[n];
170
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
171
+ var i = tryCatch(o, e.iterator, r.arg);
172
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
173
+ var a = i.arg;
174
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
175
+ }
176
+ function pushTryEntry(t) {
177
+ var e = {
178
+ tryLoc: t[0]
153
179
  };
154
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
180
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
155
181
  }
156
- function resetTryEntry(entry) {
157
- var record = entry.completion || {};
158
- record.type = "normal", delete record.arg, entry.completion = record;
182
+ function resetTryEntry(t) {
183
+ var e = t.completion || {};
184
+ e.type = "normal", delete e.arg, t.completion = e;
159
185
  }
160
- function Context(tryLocsList) {
186
+ function Context(t) {
161
187
  this.tryEntries = [{
162
188
  tryLoc: "root"
163
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
189
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
164
190
  }
165
- function values(iterable) {
166
- if (iterable) {
167
- var iteratorMethod = iterable[iteratorSymbol];
168
- if (iteratorMethod) return iteratorMethod.call(iterable);
169
- if ("function" == typeof iterable.next) return iterable;
170
- if (!isNaN(iterable.length)) {
171
- var i = -1,
172
- next = function next() {
173
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
174
- return next.value = undefined, next.done = !0, next;
191
+ function values(e) {
192
+ if (e || "" === e) {
193
+ var r = e[a];
194
+ if (r) return r.call(e);
195
+ if ("function" == typeof e.next) return e;
196
+ if (!isNaN(e.length)) {
197
+ var o = -1,
198
+ i = function next() {
199
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
200
+ return next.value = t, next.done = !0, next;
175
201
  };
176
- return next.next = next;
202
+ return i.next = i;
177
203
  }
178
204
  }
179
- return {
180
- next: doneResult
181
- };
205
+ throw new TypeError(typeof e + " is not iterable");
182
206
  }
183
- function doneResult() {
207
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
208
+ value: GeneratorFunctionPrototype,
209
+ configurable: !0
210
+ }), o(GeneratorFunctionPrototype, "constructor", {
211
+ value: GeneratorFunction,
212
+ configurable: !0
213
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
214
+ var e = "function" == typeof t && t.constructor;
215
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
216
+ }, e.mark = function (t) {
217
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
218
+ }, e.awrap = function (t) {
184
219
  return {
185
- value: undefined,
186
- done: !0
220
+ __await: t
187
221
  };
188
- }
189
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
190
- var ctor = "function" == typeof genFun && genFun.constructor;
191
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
192
- }, exports.mark = function (genFun) {
193
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
194
- }, exports.awrap = function (arg) {
195
- return {
196
- __await: arg
197
- };
198
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
222
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
199
223
  return this;
200
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
201
- void 0 === PromiseImpl && (PromiseImpl = Promise);
202
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
203
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
204
- return result.done ? result.value : iter.next();
224
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
225
+ void 0 === i && (i = Promise);
226
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
227
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
228
+ return t.done ? t.value : a.next();
205
229
  });
206
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
230
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
207
231
  return this;
208
- }), define(Gp, "toString", function () {
232
+ }), define(g, "toString", function () {
209
233
  return "[object Generator]";
210
- }), exports.keys = function (object) {
211
- var keys = [];
212
- for (var key in object) keys.push(key);
213
- return keys.reverse(), function next() {
214
- for (; keys.length;) {
215
- var key = keys.pop();
216
- if (key in object) return next.value = key, next.done = !1, next;
234
+ }), e.keys = function (t) {
235
+ var e = Object(t),
236
+ r = [];
237
+ for (var n in e) r.push(n);
238
+ return r.reverse(), function next() {
239
+ for (; r.length;) {
240
+ var t = r.pop();
241
+ if (t in e) return next.value = t, next.done = !1, next;
217
242
  }
218
243
  return next.done = !0, next;
219
244
  };
220
- }, exports.values = values, Context.prototype = {
245
+ }, e.values = values, Context.prototype = {
221
246
  constructor: Context,
222
- reset: function (skipTempReset) {
223
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
247
+ reset: function (e) {
248
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
224
249
  },
225
250
  stop: function () {
226
251
  this.done = !0;
227
- var rootRecord = this.tryEntries[0].completion;
228
- if ("throw" === rootRecord.type) throw rootRecord.arg;
252
+ var t = this.tryEntries[0].completion;
253
+ if ("throw" === t.type) throw t.arg;
229
254
  return this.rval;
230
255
  },
231
- dispatchException: function (exception) {
232
- if (this.done) throw exception;
233
- var context = this;
234
- function handle(loc, caught) {
235
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
256
+ dispatchException: function (e) {
257
+ if (this.done) throw e;
258
+ var r = this;
259
+ function handle(n, o) {
260
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
236
261
  }
237
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
238
- var entry = this.tryEntries[i],
239
- record = entry.completion;
240
- if ("root" === entry.tryLoc) return handle("end");
241
- if (entry.tryLoc <= this.prev) {
242
- var hasCatch = hasOwn.call(entry, "catchLoc"),
243
- hasFinally = hasOwn.call(entry, "finallyLoc");
244
- if (hasCatch && hasFinally) {
245
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
246
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
247
- } else if (hasCatch) {
248
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
262
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
263
+ var i = this.tryEntries[o],
264
+ a = i.completion;
265
+ if ("root" === i.tryLoc) return handle("end");
266
+ if (i.tryLoc <= this.prev) {
267
+ var c = n.call(i, "catchLoc"),
268
+ u = n.call(i, "finallyLoc");
269
+ if (c && u) {
270
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
271
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
272
+ } else if (c) {
273
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
249
274
  } else {
250
- if (!hasFinally) throw new Error("try statement without catch or finally");
251
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
275
+ if (!u) throw Error("try statement without catch or finally");
276
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
252
277
  }
253
278
  }
254
279
  }
255
280
  },
256
- abrupt: function (type, arg) {
257
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
258
- var entry = this.tryEntries[i];
259
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
260
- var finallyEntry = entry;
281
+ abrupt: function (t, e) {
282
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
283
+ var o = this.tryEntries[r];
284
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
285
+ var i = o;
261
286
  break;
262
287
  }
263
288
  }
264
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
265
- var record = finallyEntry ? finallyEntry.completion : {};
266
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
289
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
290
+ var a = i ? i.completion : {};
291
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
267
292
  },
268
- complete: function (record, afterLoc) {
269
- if ("throw" === record.type) throw record.arg;
270
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
293
+ complete: function (t, e) {
294
+ if ("throw" === t.type) throw t.arg;
295
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
271
296
  },
272
- finish: function (finallyLoc) {
273
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
274
- var entry = this.tryEntries[i];
275
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
297
+ finish: function (t) {
298
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
299
+ var r = this.tryEntries[e];
300
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
276
301
  }
277
302
  },
278
- catch: function (tryLoc) {
279
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
280
- var entry = this.tryEntries[i];
281
- if (entry.tryLoc === tryLoc) {
282
- var record = entry.completion;
283
- if ("throw" === record.type) {
284
- var thrown = record.arg;
285
- resetTryEntry(entry);
303
+ catch: function (t) {
304
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
305
+ var r = this.tryEntries[e];
306
+ if (r.tryLoc === t) {
307
+ var n = r.completion;
308
+ if ("throw" === n.type) {
309
+ var o = n.arg;
310
+ resetTryEntry(r);
286
311
  }
287
- return thrown;
312
+ return o;
288
313
  }
289
314
  }
290
- throw new Error("illegal catch attempt");
315
+ throw Error("illegal catch attempt");
291
316
  },
292
- delegateYield: function (iterable, resultName, nextLoc) {
317
+ delegateYield: function (e, r, n) {
293
318
  return this.delegate = {
294
- iterator: values(iterable),
295
- resultName: resultName,
296
- nextLoc: nextLoc
297
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
319
+ iterator: values(e),
320
+ resultName: r,
321
+ nextLoc: n
322
+ }, "next" === this.method && (this.arg = t), y;
298
323
  }
299
- }, exports;
324
+ }, e;
300
325
  }
301
326
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
302
327
  try {
@@ -360,34 +385,12 @@ function _setPrototypeOf(o, p) {
360
385
  };
361
386
  return _setPrototypeOf(o, p);
362
387
  }
363
- function _isNativeReflectConstruct() {
364
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
365
- if (Reflect.construct.sham) return false;
366
- if (typeof Proxy === "function") return true;
388
+ function _isNativeFunction(fn) {
367
389
  try {
368
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
369
- return true;
390
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
370
391
  } catch (e) {
371
- return false;
372
- }
373
- }
374
- function _construct(Parent, args, Class) {
375
- if (_isNativeReflectConstruct()) {
376
- _construct = Reflect.construct.bind();
377
- } else {
378
- _construct = function _construct(Parent, args, Class) {
379
- var a = [null];
380
- a.push.apply(a, args);
381
- var Constructor = Function.bind.apply(Parent, a);
382
- var instance = new Constructor();
383
- if (Class) _setPrototypeOf(instance, Class.prototype);
384
- return instance;
385
- };
392
+ return typeof fn === "function";
386
393
  }
387
- return _construct.apply(null, arguments);
388
- }
389
- function _isNativeFunction(fn) {
390
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
391
394
  }
392
395
  function _wrapNativeSuper(Class) {
393
396
  var _cache = typeof Map === "function" ? new Map() : undefined;
@@ -428,234 +431,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
428
431
  return target;
429
432
  }
430
433
 
431
- var initialState$1 = {
432
- status: 'AUTHENTICATING'
433
- };
434
- function authReducer(state, event) {
435
- switch (event.type) {
436
- case 'AUTHENTICATED':
437
- return {
438
- status: 'AUTHENTICATED',
439
- user: event.data.user
440
- };
441
- case 'LOGOUT':
442
- return initialState$1;
443
- case 'ERROR':
444
- return {
445
- error: event.error,
446
- status: 'ERROR'
447
- };
448
- case 'NOT_AUTHENTICATED':
449
- return _extends({}, state, {
450
- status: 'NOT_AUTHENTICATED'
451
- });
452
- default:
453
- return state;
454
- }
455
- }
456
-
457
- var _excluded$2 = ["children", "decorateUser"];
458
- var POST_LOGIN_ROUTE_KEY = '@entur-partner:post-login-route';
459
- var LOGIN_LAST_RETRY = '@entur-partner:last-login-retry';
460
- var redirect = function redirect(pathname) {
461
- if (pathname === void 0) {
462
- pathname = '/';
463
- }
464
- return window.history.replaceState({}, document.title, pathname);
465
- }; // TODO: replace with react-router history
466
- var Auth0Context = /*#__PURE__*/React.createContext(undefined);
467
- var useAuth = function useAuth() {
468
- var auth = useContext(Auth0Context);
469
- assertIsDefined(auth, 'A `<Auth0Provider>` component needs to be higher up in the component hierarchy.');
470
- return auth;
471
- };
472
- var initialState = {
473
- status: 'AUTHENTICATING'
474
- };
475
- var AuthProvider = function AuthProvider(_ref) {
476
- var children = _ref.children,
477
- decorateUser = _ref.decorateUser,
478
- initOptions = _objectWithoutPropertiesLoose(_ref, _excluded$2);
479
- var _useReducer = useReducer(authReducer, initialState),
480
- state = _useReducer[0],
481
- dispatch = _useReducer[1];
482
- var _useState = useState(),
483
- auth0Client = _useState[0],
484
- setAuth0 = _useState[1];
485
- useEffect(function () {
486
- var initAuth0 = /*#__PURE__*/function () {
487
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
488
- var client, route, postLoginRoute, isAuthenticated, auth0User, token, user;
489
- return _regeneratorRuntime().wrap(function _callee$(_context) {
490
- while (1) switch (_context.prev = _context.next) {
491
- case 0:
492
- _context.next = 2;
493
- return createAuth0Client(initOptions);
494
- case 2:
495
- client = _context.sent;
496
- setAuth0(client);
497
- if (!window.location.search.includes('code=')) {
498
- _context.next = 11;
499
- break;
500
- }
501
- _context.next = 7;
502
- return client.handleRedirectCallback();
503
- case 7:
504
- route = localStorage.getItem(POST_LOGIN_ROUTE_KEY);
505
- localStorage.removeItem(POST_LOGIN_ROUTE_KEY);
506
- postLoginRoute = route || '/';
507
- redirect(postLoginRoute);
508
- case 11:
509
- _context.next = 13;
510
- return client.isAuthenticated();
511
- case 13:
512
- isAuthenticated = _context.sent;
513
- if (!isAuthenticated) {
514
- _context.next = 27;
515
- break;
516
- }
517
- _context.next = 17;
518
- return client.getUser();
519
- case 17:
520
- auth0User = _context.sent;
521
- _context.next = 20;
522
- return client.getTokenSilently();
523
- case 20:
524
- token = _context.sent;
525
- _context.next = 23;
526
- return decorateUser(auth0User, token);
527
- case 23:
528
- user = _context.sent;
529
- dispatch({
530
- type: 'AUTHENTICATED',
531
- data: {
532
- user: user
533
- }
534
- });
535
- _context.next = 28;
536
- break;
537
- case 27:
538
- dispatch({
539
- type: 'NOT_AUTHENTICATED'
540
- });
541
- case 28:
542
- case "end":
543
- return _context.stop();
544
- }
545
- }, _callee);
546
- }));
547
- return function initAuth0() {
548
- return _ref2.apply(this, arguments);
549
- };
550
- }();
551
- initAuth0()["catch"]( /*#__PURE__*/function () {
552
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
553
- var _localStorage$getItem, lastRetryEpochSeconds, nowEpochSeconds, timeSinceLastRetry, minimumTimeForRetry;
554
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
555
- while (1) switch (_context2.prev = _context2.next) {
556
- case 0:
557
- _context2.prev = 0;
558
- lastRetryEpochSeconds = parseInt((_localStorage$getItem = localStorage.getItem(LOGIN_LAST_RETRY)) != null ? _localStorage$getItem : '0');
559
- nowEpochSeconds = Math.floor(Date.now() / 1000);
560
- timeSinceLastRetry = nowEpochSeconds - lastRetryEpochSeconds;
561
- minimumTimeForRetry = 120; // Has there been more than x seconds since last retry?
562
- if (!(timeSinceLastRetry >= minimumTimeForRetry)) {
563
- _context2.next = 12;
564
- break;
565
- }
566
- localStorage.setItem(LOGIN_LAST_RETRY, nowEpochSeconds.toString());
567
- redirect('/');
568
- _context2.next = 10;
569
- return initAuth0();
570
- case 10:
571
- _context2.next = 13;
572
- break;
573
- case 12:
574
- throw error;
575
- case 13:
576
- _context2.next = 18;
577
- break;
578
- case 15:
579
- _context2.prev = 15;
580
- _context2.t0 = _context2["catch"](0);
581
- dispatch({
582
- type: 'ERROR',
583
- error: error
584
- });
585
- case 18:
586
- case "end":
587
- return _context2.stop();
588
- }
589
- }, _callee2, null, [[0, 15]]);
590
- }));
591
- return function (_x) {
592
- return _ref3.apply(this, arguments);
593
- };
594
- }());
595
- // eslint-disable-next-line
596
- }, []);
597
- var logout = function logout() {
598
- assertIsDefined(auth0Client);
599
- var _window$location = window.location,
600
- protocol = _window$location.protocol,
601
- hostname = _window$location.hostname,
602
- port = _window$location.port;
603
- auth0Client.logout({
604
- returnTo: protocol + "//" + hostname + ":" + port
605
- });
606
- };
607
- var login = /*#__PURE__*/function () {
608
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(redirectUri) {
609
- var _window, location;
610
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
611
- while (1) switch (_context3.prev = _context3.next) {
612
- case 0:
613
- if (redirectUri === void 0) {
614
- redirectUri = window.location.origin;
615
- }
616
- assertIsDefined(auth0Client);
617
- _window = window, location = _window.location;
618
- localStorage.setItem(POST_LOGIN_ROUTE_KEY, "" + location.pathname + location.search);
619
- auth0Client.loginWithRedirect({
620
- redirect_uri: redirectUri
621
- });
622
- case 5:
623
- case "end":
624
- return _context3.stop();
625
- }
626
- }, _callee3);
627
- }));
628
- return function login(_x2) {
629
- return _ref4.apply(this, arguments);
630
- };
631
- }();
632
- var getToken = /*#__PURE__*/function () {
633
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(options) {
634
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
635
- while (1) switch (_context4.prev = _context4.next) {
636
- case 0:
637
- assertIsDefined(auth0Client);
638
- return _context4.abrupt("return", auth0Client.getTokenSilently(options));
639
- case 2:
640
- case "end":
641
- return _context4.stop();
642
- }
643
- }, _callee4);
644
- }));
645
- return function getToken(_x3) {
646
- return _ref5.apply(this, arguments);
647
- };
648
- }();
649
- return React.createElement(Auth0Context.Provider, {
650
- value: _extends({}, state, {
651
- auth0Client: auth0Client,
652
- logout: logout,
653
- getToken: getToken,
654
- login: login
655
- })
656
- }, children);
657
- };
658
-
659
434
  var EnvironmentBanner = function EnvironmentBanner(_ref) {
660
435
  var environment = _ref.environment;
661
436
  return React.createElement("div", {
@@ -673,73 +448,121 @@ var EnvironmentBanner = function EnvironmentBanner(_ref) {
673
448
  });
674
449
  };
675
450
 
676
- var Login = function Login(_ref) {
677
- var redirectUri = _ref.redirectUri;
678
- var _useAuth = useAuth(),
679
- login = _useAuth.login;
451
+ function userLogout(logout) {
452
+ var _window$location = window.location,
453
+ protocol = _window$location.protocol,
454
+ hostname = _window$location.hostname,
455
+ port = _window$location.port;
456
+ return logout({
457
+ logoutParams: {
458
+ returnTo: protocol + "//" + hostname + ":" + port
459
+ }
460
+ });
461
+ }
462
+ var Authenticate = function Authenticate(_ref) {
463
+ var children = _ref.children,
464
+ decorateUser = _ref.decorateUser;
465
+ var _useState = useState(undefined),
466
+ userWithPermission = _useState[0],
467
+ setUserWithPermission = _useState[1];
468
+ var _useAuth = useAuth0(),
469
+ user = _useAuth.user,
470
+ getAccessTokenSilently = _useAuth.getAccessTokenSilently,
471
+ loginWithRedirect = _useAuth.loginWithRedirect,
472
+ _logout = _useAuth.logout,
473
+ isLoading = _useAuth.isLoading,
474
+ isAuthenticated = _useAuth.isAuthenticated,
475
+ error = _useAuth.error;
680
476
  useEffect(function () {
681
- login(redirectUri);
682
- }, [login, redirectUri]);
683
- return null;
684
- };
685
- var Authenticate = function Authenticate(_ref2) {
686
- var children = _ref2.children,
687
- redirectUri = _ref2.redirectUri;
688
- var _useAuth2 = useAuth(),
689
- status = _useAuth2.status,
690
- user = _useAuth2.user,
691
- error = _useAuth2.error,
692
- logout = _useAuth2.logout,
693
- getToken = _useAuth2.getToken;
694
- switch (status) {
695
- case 'NOT_AUTHENTICATED':
696
- return React.createElement(Login, {
697
- redirectUri: redirectUri
698
- });
699
- case 'AUTHENTICATED':
700
- assertIsDefined(user);
701
- return React.createElement(React.Fragment, null, children({
702
- user: user,
703
- logout: logout,
704
- getToken: getToken
477
+ var fetchUserData = /*#__PURE__*/function () {
478
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
479
+ var token, decoratedUser;
480
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
481
+ while (1) switch (_context.prev = _context.next) {
482
+ case 0:
483
+ _context.prev = 0;
484
+ _context.next = 3;
485
+ return getAccessTokenSilently();
486
+ case 3:
487
+ token = _context.sent;
488
+ _context.next = 6;
489
+ return decorateUser(user, token);
490
+ case 6:
491
+ decoratedUser = _context.sent;
492
+ setUserWithPermission(decoratedUser);
493
+ _context.next = 13;
494
+ break;
495
+ case 10:
496
+ _context.prev = 10;
497
+ _context.t0 = _context["catch"](0);
498
+ console.error('Error fetching user data:', _context.t0);
499
+ case 13:
500
+ case "end":
501
+ return _context.stop();
502
+ }
503
+ }, _callee, null, [[0, 10]]);
705
504
  }));
706
- case 'AUTHENTICATING':
707
- return React.createElement(Loader, {
708
- style: {
709
- marginTop: space.extraLarge9
710
- }
711
- }, "Authenticating");
712
- case 'ERROR':
713
- process.env.NODE_ENV !== 'production' && console.error(error);
714
- return React.createElement(BannerAlertBox, {
715
- variant: "error",
716
- title: "Authentication failed",
717
- style: {
718
- maxWidth: '600px',
719
- margin: '0 auto'
720
- }
721
- }, React.createElement(Paragraph, null, "Something went wrong while trying to authenticate you. If the problem persists you should contact", ' ', React.createElement(Link, {
722
- href: "mailto:support@entur.org"
723
- }, "support@entur.org"), " to get it resolved."), React.createElement(Paragraph, null, "Authentication failed with: ", React.createElement(CodeText, null, error == null ? void 0 : error.toString())));
724
- default:
725
- return null;
505
+ return function fetchUserData() {
506
+ return _ref2.apply(this, arguments);
507
+ };
508
+ }();
509
+ if (isAuthenticated) {
510
+ fetchUserData();
511
+ }
512
+ }, [decorateUser, getAccessTokenSilently, isAuthenticated, user]);
513
+ if (!isLoading && !isAuthenticated) {
514
+ loginWithRedirect();
515
+ return React.createElement(Loader, {
516
+ style: {
517
+ marginTop: space.extraLarge9
518
+ }
519
+ }, "Redirecting to login page");
520
+ }
521
+ if (isLoading || !userWithPermission) {
522
+ return React.createElement(Loader, {
523
+ style: {
524
+ marginTop: space.extraLarge9
525
+ }
526
+ }, "Authenticating");
726
527
  }
528
+ if (error) {
529
+ process.env.NODE_ENV !== 'production' && console.error(error);
530
+ return React.createElement(BannerAlertBox, {
531
+ variant: "error",
532
+ title: "Authentication failed",
533
+ style: {
534
+ maxWidth: '600px',
535
+ margin: '0 auto'
536
+ }
537
+ }, React.createElement(Paragraph, null, "Something went wrong while trying to authenticate you. If the problem persists you should contact", ' ', React.createElement(Link, {
538
+ href: "mailto:support@entur.org"
539
+ }, "support@entur.org"), " to get it resolved."), React.createElement(Paragraph, null, "Authentication failed with: ", React.createElement(CodeText, null, error == null ? void 0 : error.toString())));
540
+ }
541
+ assertIsDefined(userWithPermission);
542
+ return React.createElement(React.Fragment, null, children({
543
+ user: userWithPermission,
544
+ logout: function logout() {
545
+ return userLogout(_logout);
546
+ },
547
+ getToken: getAccessTokenSilently
548
+ }));
727
549
  };
728
550
  var AppShell = function AppShell(_ref3) {
729
551
  var children = _ref3.children,
730
552
  audience = _ref3.audience,
731
553
  domain = _ref3.domain,
732
554
  clientId = _ref3.clientId,
733
- redirectUri = _ref3.redirectUri,
734
555
  decorateUser = _ref3.decorateUser,
735
556
  environment = _ref3.environment;
736
- return React.createElement(AuthProvider, {
737
- audience: audience,
557
+ return React.createElement(Auth0Provider, {
738
558
  domain: domain,
739
- client_id: clientId,
740
- decorateUser: decorateUser
559
+ clientId: clientId,
560
+ authorizationParams: {
561
+ redirect_uri: window.location.origin,
562
+ audience: audience
563
+ }
741
564
  }, React.createElement(Authenticate, {
742
- redirectUri: redirectUri
565
+ decorateUser: decorateUser
743
566
  }, function (params) {
744
567
  return React.createElement(React.Fragment, null, environment && environment !== Environment.Production && React.createElement(EnvironmentBanner, {
745
568
  environment: environment
@@ -922,7 +745,6 @@ var LanguageProvider = function LanguageProvider(_ref) {
922
745
  };
923
746
 
924
747
  var OrganisationsError = /*#__PURE__*/function (_Error) {
925
- _inheritsLoose(OrganisationsError, _Error);
926
748
  function OrganisationsError() {
927
749
  var _this;
928
750
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -932,6 +754,7 @@ var OrganisationsError = /*#__PURE__*/function (_Error) {
932
754
  _this.message = 'Failed fetching organisations';
933
755
  return _this;
934
756
  }
757
+ _inheritsLoose(OrganisationsError, _Error);
935
758
  return OrganisationsError;
936
759
  }( /*#__PURE__*/_wrapNativeSuper(Error));
937
760