@forward-software/react-auth 1.0.2 → 2.0.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.
@@ -1,1267 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var React__default = _interopDefault(React);
9
- var shim = require('use-sync-external-store/shim');
10
-
11
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
12
- try {
13
- var info = gen[key](arg);
14
- var value = info.value;
15
- } catch (error) {
16
- reject(error);
17
- return;
18
- }
19
-
20
- if (info.done) {
21
- resolve(value);
22
- } else {
23
- Promise.resolve(value).then(_next, _throw);
24
- }
25
- }
26
-
27
- function _asyncToGenerator(fn) {
28
- return function () {
29
- var self = this,
30
- args = arguments;
31
- return new Promise(function (resolve, reject) {
32
- var gen = fn.apply(self, args);
33
-
34
- function _next(value) {
35
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
36
- }
37
-
38
- function _throw(err) {
39
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
40
- }
41
-
42
- _next(undefined);
43
- });
44
- };
45
- }
46
-
47
- function _defineProperties(target, props) {
48
- for (var i = 0; i < props.length; i++) {
49
- var descriptor = props[i];
50
- descriptor.enumerable = descriptor.enumerable || false;
51
- descriptor.configurable = true;
52
- if ("value" in descriptor) descriptor.writable = true;
53
- Object.defineProperty(target, descriptor.key, descriptor);
54
- }
55
- }
56
-
57
- function _createClass(Constructor, protoProps, staticProps) {
58
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
59
- if (staticProps) _defineProperties(Constructor, staticProps);
60
- Object.defineProperty(Constructor, "prototype", {
61
- writable: false
62
- });
63
- return Constructor;
64
- }
65
-
66
- function _extends() {
67
- _extends = Object.assign || function (target) {
68
- for (var i = 1; i < arguments.length; i++) {
69
- var source = arguments[i];
70
-
71
- for (var key in source) {
72
- if (Object.prototype.hasOwnProperty.call(source, key)) {
73
- target[key] = source[key];
74
- }
75
- }
76
- }
77
-
78
- return target;
79
- };
80
-
81
- return _extends.apply(this, arguments);
82
- }
83
-
84
- function createCommonjsModule(fn, module) {
85
- return module = { exports: {} }, fn(module, module.exports), module.exports;
86
- }
87
-
88
- var runtime_1 = createCommonjsModule(function (module) {
89
- /**
90
- * Copyright (c) 2014-present, Facebook, Inc.
91
- *
92
- * This source code is licensed under the MIT license found in the
93
- * LICENSE file in the root directory of this source tree.
94
- */
95
-
96
- var runtime = (function (exports) {
97
-
98
- var Op = Object.prototype;
99
- var hasOwn = Op.hasOwnProperty;
100
- var undefined$1; // More compressible than void 0.
101
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
102
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
103
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
104
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
105
-
106
- function define(obj, key, value) {
107
- Object.defineProperty(obj, key, {
108
- value: value,
109
- enumerable: true,
110
- configurable: true,
111
- writable: true
112
- });
113
- return obj[key];
114
- }
115
- try {
116
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
117
- define({}, "");
118
- } catch (err) {
119
- define = function(obj, key, value) {
120
- return obj[key] = value;
121
- };
122
- }
123
-
124
- function wrap(innerFn, outerFn, self, tryLocsList) {
125
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
126
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
127
- var generator = Object.create(protoGenerator.prototype);
128
- var context = new Context(tryLocsList || []);
129
-
130
- // The ._invoke method unifies the implementations of the .next,
131
- // .throw, and .return methods.
132
- generator._invoke = makeInvokeMethod(innerFn, self, context);
133
-
134
- return generator;
135
- }
136
- exports.wrap = wrap;
137
-
138
- // Try/catch helper to minimize deoptimizations. Returns a completion
139
- // record like context.tryEntries[i].completion. This interface could
140
- // have been (and was previously) designed to take a closure to be
141
- // invoked without arguments, but in all the cases we care about we
142
- // already have an existing method we want to call, so there's no need
143
- // to create a new function object. We can even get away with assuming
144
- // the method takes exactly one argument, since that happens to be true
145
- // in every case, so we don't have to touch the arguments object. The
146
- // only additional allocation required is the completion record, which
147
- // has a stable shape and so hopefully should be cheap to allocate.
148
- function tryCatch(fn, obj, arg) {
149
- try {
150
- return { type: "normal", arg: fn.call(obj, arg) };
151
- } catch (err) {
152
- return { type: "throw", arg: err };
153
- }
154
- }
155
-
156
- var GenStateSuspendedStart = "suspendedStart";
157
- var GenStateSuspendedYield = "suspendedYield";
158
- var GenStateExecuting = "executing";
159
- var GenStateCompleted = "completed";
160
-
161
- // Returning this object from the innerFn has the same effect as
162
- // breaking out of the dispatch switch statement.
163
- var ContinueSentinel = {};
164
-
165
- // Dummy constructor functions that we use as the .constructor and
166
- // .constructor.prototype properties for functions that return Generator
167
- // objects. For full spec compliance, you may wish to configure your
168
- // minifier not to mangle the names of these two functions.
169
- function Generator() {}
170
- function GeneratorFunction() {}
171
- function GeneratorFunctionPrototype() {}
172
-
173
- // This is a polyfill for %IteratorPrototype% for environments that
174
- // don't natively support it.
175
- var IteratorPrototype = {};
176
- define(IteratorPrototype, iteratorSymbol, function () {
177
- return this;
178
- });
179
-
180
- var getProto = Object.getPrototypeOf;
181
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
182
- if (NativeIteratorPrototype &&
183
- NativeIteratorPrototype !== Op &&
184
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
185
- // This environment has a native %IteratorPrototype%; use it instead
186
- // of the polyfill.
187
- IteratorPrototype = NativeIteratorPrototype;
188
- }
189
-
190
- var Gp = GeneratorFunctionPrototype.prototype =
191
- Generator.prototype = Object.create(IteratorPrototype);
192
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
193
- define(Gp, "constructor", GeneratorFunctionPrototype);
194
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
195
- GeneratorFunction.displayName = define(
196
- GeneratorFunctionPrototype,
197
- toStringTagSymbol,
198
- "GeneratorFunction"
199
- );
200
-
201
- // Helper for defining the .next, .throw, and .return methods of the
202
- // Iterator interface in terms of a single ._invoke method.
203
- function defineIteratorMethods(prototype) {
204
- ["next", "throw", "return"].forEach(function(method) {
205
- define(prototype, method, function(arg) {
206
- return this._invoke(method, arg);
207
- });
208
- });
209
- }
210
-
211
- exports.isGeneratorFunction = function(genFun) {
212
- var ctor = typeof genFun === "function" && genFun.constructor;
213
- return ctor
214
- ? ctor === GeneratorFunction ||
215
- // For the native GeneratorFunction constructor, the best we can
216
- // do is to check its .name property.
217
- (ctor.displayName || ctor.name) === "GeneratorFunction"
218
- : false;
219
- };
220
-
221
- exports.mark = function(genFun) {
222
- if (Object.setPrototypeOf) {
223
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
224
- } else {
225
- genFun.__proto__ = GeneratorFunctionPrototype;
226
- define(genFun, toStringTagSymbol, "GeneratorFunction");
227
- }
228
- genFun.prototype = Object.create(Gp);
229
- return genFun;
230
- };
231
-
232
- // Within the body of any async function, `await x` is transformed to
233
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
234
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
235
- // meant to be awaited.
236
- exports.awrap = function(arg) {
237
- return { __await: arg };
238
- };
239
-
240
- function AsyncIterator(generator, PromiseImpl) {
241
- function invoke(method, arg, resolve, reject) {
242
- var record = tryCatch(generator[method], generator, arg);
243
- if (record.type === "throw") {
244
- reject(record.arg);
245
- } else {
246
- var result = record.arg;
247
- var value = result.value;
248
- if (value &&
249
- typeof value === "object" &&
250
- hasOwn.call(value, "__await")) {
251
- return PromiseImpl.resolve(value.__await).then(function(value) {
252
- invoke("next", value, resolve, reject);
253
- }, function(err) {
254
- invoke("throw", err, resolve, reject);
255
- });
256
- }
257
-
258
- return PromiseImpl.resolve(value).then(function(unwrapped) {
259
- // When a yielded Promise is resolved, its final value becomes
260
- // the .value of the Promise<{value,done}> result for the
261
- // current iteration.
262
- result.value = unwrapped;
263
- resolve(result);
264
- }, function(error) {
265
- // If a rejected Promise was yielded, throw the rejection back
266
- // into the async generator function so it can be handled there.
267
- return invoke("throw", error, resolve, reject);
268
- });
269
- }
270
- }
271
-
272
- var previousPromise;
273
-
274
- function enqueue(method, arg) {
275
- function callInvokeWithMethodAndArg() {
276
- return new PromiseImpl(function(resolve, reject) {
277
- invoke(method, arg, resolve, reject);
278
- });
279
- }
280
-
281
- return previousPromise =
282
- // If enqueue has been called before, then we want to wait until
283
- // all previous Promises have been resolved before calling invoke,
284
- // so that results are always delivered in the correct order. If
285
- // enqueue has not been called before, then it is important to
286
- // call invoke immediately, without waiting on a callback to fire,
287
- // so that the async generator function has the opportunity to do
288
- // any necessary setup in a predictable way. This predictability
289
- // is why the Promise constructor synchronously invokes its
290
- // executor callback, and why async functions synchronously
291
- // execute code before the first await. Since we implement simple
292
- // async functions in terms of async generators, it is especially
293
- // important to get this right, even though it requires care.
294
- previousPromise ? previousPromise.then(
295
- callInvokeWithMethodAndArg,
296
- // Avoid propagating failures to Promises returned by later
297
- // invocations of the iterator.
298
- callInvokeWithMethodAndArg
299
- ) : callInvokeWithMethodAndArg();
300
- }
301
-
302
- // Define the unified helper method that is used to implement .next,
303
- // .throw, and .return (see defineIteratorMethods).
304
- this._invoke = enqueue;
305
- }
306
-
307
- defineIteratorMethods(AsyncIterator.prototype);
308
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
309
- return this;
310
- });
311
- exports.AsyncIterator = AsyncIterator;
312
-
313
- // Note that simple async functions are implemented on top of
314
- // AsyncIterator objects; they just return a Promise for the value of
315
- // the final result produced by the iterator.
316
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
317
- if (PromiseImpl === void 0) PromiseImpl = Promise;
318
-
319
- var iter = new AsyncIterator(
320
- wrap(innerFn, outerFn, self, tryLocsList),
321
- PromiseImpl
322
- );
323
-
324
- return exports.isGeneratorFunction(outerFn)
325
- ? iter // If outerFn is a generator, return the full iterator.
326
- : iter.next().then(function(result) {
327
- return result.done ? result.value : iter.next();
328
- });
329
- };
330
-
331
- function makeInvokeMethod(innerFn, self, context) {
332
- var state = GenStateSuspendedStart;
333
-
334
- return function invoke(method, arg) {
335
- if (state === GenStateExecuting) {
336
- throw new Error("Generator is already running");
337
- }
338
-
339
- if (state === GenStateCompleted) {
340
- if (method === "throw") {
341
- throw arg;
342
- }
343
-
344
- // Be forgiving, per 25.3.3.3.3 of the spec:
345
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
346
- return doneResult();
347
- }
348
-
349
- context.method = method;
350
- context.arg = arg;
351
-
352
- while (true) {
353
- var delegate = context.delegate;
354
- if (delegate) {
355
- var delegateResult = maybeInvokeDelegate(delegate, context);
356
- if (delegateResult) {
357
- if (delegateResult === ContinueSentinel) continue;
358
- return delegateResult;
359
- }
360
- }
361
-
362
- if (context.method === "next") {
363
- // Setting context._sent for legacy support of Babel's
364
- // function.sent implementation.
365
- context.sent = context._sent = context.arg;
366
-
367
- } else if (context.method === "throw") {
368
- if (state === GenStateSuspendedStart) {
369
- state = GenStateCompleted;
370
- throw context.arg;
371
- }
372
-
373
- context.dispatchException(context.arg);
374
-
375
- } else if (context.method === "return") {
376
- context.abrupt("return", context.arg);
377
- }
378
-
379
- state = GenStateExecuting;
380
-
381
- var record = tryCatch(innerFn, self, context);
382
- if (record.type === "normal") {
383
- // If an exception is thrown from innerFn, we leave state ===
384
- // GenStateExecuting and loop back for another invocation.
385
- state = context.done
386
- ? GenStateCompleted
387
- : GenStateSuspendedYield;
388
-
389
- if (record.arg === ContinueSentinel) {
390
- continue;
391
- }
392
-
393
- return {
394
- value: record.arg,
395
- done: context.done
396
- };
397
-
398
- } else if (record.type === "throw") {
399
- state = GenStateCompleted;
400
- // Dispatch the exception by looping back around to the
401
- // context.dispatchException(context.arg) call above.
402
- context.method = "throw";
403
- context.arg = record.arg;
404
- }
405
- }
406
- };
407
- }
408
-
409
- // Call delegate.iterator[context.method](context.arg) and handle the
410
- // result, either by returning a { value, done } result from the
411
- // delegate iterator, or by modifying context.method and context.arg,
412
- // setting context.delegate to null, and returning the ContinueSentinel.
413
- function maybeInvokeDelegate(delegate, context) {
414
- var method = delegate.iterator[context.method];
415
- if (method === undefined$1) {
416
- // A .throw or .return when the delegate iterator has no .throw
417
- // method always terminates the yield* loop.
418
- context.delegate = null;
419
-
420
- if (context.method === "throw") {
421
- // Note: ["return"] must be used for ES3 parsing compatibility.
422
- if (delegate.iterator["return"]) {
423
- // If the delegate iterator has a return method, give it a
424
- // chance to clean up.
425
- context.method = "return";
426
- context.arg = undefined$1;
427
- maybeInvokeDelegate(delegate, context);
428
-
429
- if (context.method === "throw") {
430
- // If maybeInvokeDelegate(context) changed context.method from
431
- // "return" to "throw", let that override the TypeError below.
432
- return ContinueSentinel;
433
- }
434
- }
435
-
436
- context.method = "throw";
437
- context.arg = new TypeError(
438
- "The iterator does not provide a 'throw' method");
439
- }
440
-
441
- return ContinueSentinel;
442
- }
443
-
444
- var record = tryCatch(method, delegate.iterator, context.arg);
445
-
446
- if (record.type === "throw") {
447
- context.method = "throw";
448
- context.arg = record.arg;
449
- context.delegate = null;
450
- return ContinueSentinel;
451
- }
452
-
453
- var info = record.arg;
454
-
455
- if (! info) {
456
- context.method = "throw";
457
- context.arg = new TypeError("iterator result is not an object");
458
- context.delegate = null;
459
- return ContinueSentinel;
460
- }
461
-
462
- if (info.done) {
463
- // Assign the result of the finished delegate to the temporary
464
- // variable specified by delegate.resultName (see delegateYield).
465
- context[delegate.resultName] = info.value;
466
-
467
- // Resume execution at the desired location (see delegateYield).
468
- context.next = delegate.nextLoc;
469
-
470
- // If context.method was "throw" but the delegate handled the
471
- // exception, let the outer generator proceed normally. If
472
- // context.method was "next", forget context.arg since it has been
473
- // "consumed" by the delegate iterator. If context.method was
474
- // "return", allow the original .return call to continue in the
475
- // outer generator.
476
- if (context.method !== "return") {
477
- context.method = "next";
478
- context.arg = undefined$1;
479
- }
480
-
481
- } else {
482
- // Re-yield the result returned by the delegate method.
483
- return info;
484
- }
485
-
486
- // The delegate iterator is finished, so forget it and continue with
487
- // the outer generator.
488
- context.delegate = null;
489
- return ContinueSentinel;
490
- }
491
-
492
- // Define Generator.prototype.{next,throw,return} in terms of the
493
- // unified ._invoke helper method.
494
- defineIteratorMethods(Gp);
495
-
496
- define(Gp, toStringTagSymbol, "Generator");
497
-
498
- // A Generator should always return itself as the iterator object when the
499
- // @@iterator function is called on it. Some browsers' implementations of the
500
- // iterator prototype chain incorrectly implement this, causing the Generator
501
- // object to not be returned from this call. This ensures that doesn't happen.
502
- // See https://github.com/facebook/regenerator/issues/274 for more details.
503
- define(Gp, iteratorSymbol, function() {
504
- return this;
505
- });
506
-
507
- define(Gp, "toString", function() {
508
- return "[object Generator]";
509
- });
510
-
511
- function pushTryEntry(locs) {
512
- var entry = { tryLoc: locs[0] };
513
-
514
- if (1 in locs) {
515
- entry.catchLoc = locs[1];
516
- }
517
-
518
- if (2 in locs) {
519
- entry.finallyLoc = locs[2];
520
- entry.afterLoc = locs[3];
521
- }
522
-
523
- this.tryEntries.push(entry);
524
- }
525
-
526
- function resetTryEntry(entry) {
527
- var record = entry.completion || {};
528
- record.type = "normal";
529
- delete record.arg;
530
- entry.completion = record;
531
- }
532
-
533
- function Context(tryLocsList) {
534
- // The root entry object (effectively a try statement without a catch
535
- // or a finally block) gives us a place to store values thrown from
536
- // locations where there is no enclosing try statement.
537
- this.tryEntries = [{ tryLoc: "root" }];
538
- tryLocsList.forEach(pushTryEntry, this);
539
- this.reset(true);
540
- }
541
-
542
- exports.keys = function(object) {
543
- var keys = [];
544
- for (var key in object) {
545
- keys.push(key);
546
- }
547
- keys.reverse();
548
-
549
- // Rather than returning an object with a next method, we keep
550
- // things simple and return the next function itself.
551
- return function next() {
552
- while (keys.length) {
553
- var key = keys.pop();
554
- if (key in object) {
555
- next.value = key;
556
- next.done = false;
557
- return next;
558
- }
559
- }
560
-
561
- // To avoid creating an additional object, we just hang the .value
562
- // and .done properties off the next function object itself. This
563
- // also ensures that the minifier will not anonymize the function.
564
- next.done = true;
565
- return next;
566
- };
567
- };
568
-
569
- function values(iterable) {
570
- if (iterable) {
571
- var iteratorMethod = iterable[iteratorSymbol];
572
- if (iteratorMethod) {
573
- return iteratorMethod.call(iterable);
574
- }
575
-
576
- if (typeof iterable.next === "function") {
577
- return iterable;
578
- }
579
-
580
- if (!isNaN(iterable.length)) {
581
- var i = -1, next = function next() {
582
- while (++i < iterable.length) {
583
- if (hasOwn.call(iterable, i)) {
584
- next.value = iterable[i];
585
- next.done = false;
586
- return next;
587
- }
588
- }
589
-
590
- next.value = undefined$1;
591
- next.done = true;
592
-
593
- return next;
594
- };
595
-
596
- return next.next = next;
597
- }
598
- }
599
-
600
- // Return an iterator with no values.
601
- return { next: doneResult };
602
- }
603
- exports.values = values;
604
-
605
- function doneResult() {
606
- return { value: undefined$1, done: true };
607
- }
608
-
609
- Context.prototype = {
610
- constructor: Context,
611
-
612
- reset: function(skipTempReset) {
613
- this.prev = 0;
614
- this.next = 0;
615
- // Resetting context._sent for legacy support of Babel's
616
- // function.sent implementation.
617
- this.sent = this._sent = undefined$1;
618
- this.done = false;
619
- this.delegate = null;
620
-
621
- this.method = "next";
622
- this.arg = undefined$1;
623
-
624
- this.tryEntries.forEach(resetTryEntry);
625
-
626
- if (!skipTempReset) {
627
- for (var name in this) {
628
- // Not sure about the optimal order of these conditions:
629
- if (name.charAt(0) === "t" &&
630
- hasOwn.call(this, name) &&
631
- !isNaN(+name.slice(1))) {
632
- this[name] = undefined$1;
633
- }
634
- }
635
- }
636
- },
637
-
638
- stop: function() {
639
- this.done = true;
640
-
641
- var rootEntry = this.tryEntries[0];
642
- var rootRecord = rootEntry.completion;
643
- if (rootRecord.type === "throw") {
644
- throw rootRecord.arg;
645
- }
646
-
647
- return this.rval;
648
- },
649
-
650
- dispatchException: function(exception) {
651
- if (this.done) {
652
- throw exception;
653
- }
654
-
655
- var context = this;
656
- function handle(loc, caught) {
657
- record.type = "throw";
658
- record.arg = exception;
659
- context.next = loc;
660
-
661
- if (caught) {
662
- // If the dispatched exception was caught by a catch block,
663
- // then let that catch block handle the exception normally.
664
- context.method = "next";
665
- context.arg = undefined$1;
666
- }
667
-
668
- return !! caught;
669
- }
670
-
671
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
672
- var entry = this.tryEntries[i];
673
- var record = entry.completion;
674
-
675
- if (entry.tryLoc === "root") {
676
- // Exception thrown outside of any try block that could handle
677
- // it, so set the completion value of the entire function to
678
- // throw the exception.
679
- return handle("end");
680
- }
681
-
682
- if (entry.tryLoc <= this.prev) {
683
- var hasCatch = hasOwn.call(entry, "catchLoc");
684
- var hasFinally = hasOwn.call(entry, "finallyLoc");
685
-
686
- if (hasCatch && hasFinally) {
687
- if (this.prev < entry.catchLoc) {
688
- return handle(entry.catchLoc, true);
689
- } else if (this.prev < entry.finallyLoc) {
690
- return handle(entry.finallyLoc);
691
- }
692
-
693
- } else if (hasCatch) {
694
- if (this.prev < entry.catchLoc) {
695
- return handle(entry.catchLoc, true);
696
- }
697
-
698
- } else if (hasFinally) {
699
- if (this.prev < entry.finallyLoc) {
700
- return handle(entry.finallyLoc);
701
- }
702
-
703
- } else {
704
- throw new Error("try statement without catch or finally");
705
- }
706
- }
707
- }
708
- },
709
-
710
- abrupt: function(type, arg) {
711
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
712
- var entry = this.tryEntries[i];
713
- if (entry.tryLoc <= this.prev &&
714
- hasOwn.call(entry, "finallyLoc") &&
715
- this.prev < entry.finallyLoc) {
716
- var finallyEntry = entry;
717
- break;
718
- }
719
- }
720
-
721
- if (finallyEntry &&
722
- (type === "break" ||
723
- type === "continue") &&
724
- finallyEntry.tryLoc <= arg &&
725
- arg <= finallyEntry.finallyLoc) {
726
- // Ignore the finally entry if control is not jumping to a
727
- // location outside the try/catch block.
728
- finallyEntry = null;
729
- }
730
-
731
- var record = finallyEntry ? finallyEntry.completion : {};
732
- record.type = type;
733
- record.arg = arg;
734
-
735
- if (finallyEntry) {
736
- this.method = "next";
737
- this.next = finallyEntry.finallyLoc;
738
- return ContinueSentinel;
739
- }
740
-
741
- return this.complete(record);
742
- },
743
-
744
- complete: function(record, afterLoc) {
745
- if (record.type === "throw") {
746
- throw record.arg;
747
- }
748
-
749
- if (record.type === "break" ||
750
- record.type === "continue") {
751
- this.next = record.arg;
752
- } else if (record.type === "return") {
753
- this.rval = this.arg = record.arg;
754
- this.method = "return";
755
- this.next = "end";
756
- } else if (record.type === "normal" && afterLoc) {
757
- this.next = afterLoc;
758
- }
759
-
760
- return ContinueSentinel;
761
- },
762
-
763
- finish: function(finallyLoc) {
764
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
765
- var entry = this.tryEntries[i];
766
- if (entry.finallyLoc === finallyLoc) {
767
- this.complete(entry.completion, entry.afterLoc);
768
- resetTryEntry(entry);
769
- return ContinueSentinel;
770
- }
771
- }
772
- },
773
-
774
- "catch": function(tryLoc) {
775
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
776
- var entry = this.tryEntries[i];
777
- if (entry.tryLoc === tryLoc) {
778
- var record = entry.completion;
779
- if (record.type === "throw") {
780
- var thrown = record.arg;
781
- resetTryEntry(entry);
782
- }
783
- return thrown;
784
- }
785
- }
786
-
787
- // The context.catch method must only be called with a location
788
- // argument that corresponds to a known catch block.
789
- throw new Error("illegal catch attempt");
790
- },
791
-
792
- delegateYield: function(iterable, resultName, nextLoc) {
793
- this.delegate = {
794
- iterator: values(iterable),
795
- resultName: resultName,
796
- nextLoc: nextLoc
797
- };
798
-
799
- if (this.method === "next") {
800
- // Deliberately forget the last sent value so that we don't
801
- // accidentally pass it on to the delegate.
802
- this.arg = undefined$1;
803
- }
804
-
805
- return ContinueSentinel;
806
- }
807
- };
808
-
809
- // Regardless of whether this script is executing as a CommonJS module
810
- // or not, return the runtime object so that we can declare the variable
811
- // regeneratorRuntime in the outer scope, which allows this module to be
812
- // injected easily by `bin/regenerator --include-runtime script.js`.
813
- return exports;
814
-
815
- }(
816
- // If this script is executing as a CommonJS module, use module.exports
817
- // as the regeneratorRuntime namespace. Otherwise create a new empty
818
- // object. Either way, the resulting object will be used to initialize
819
- // the regeneratorRuntime variable at the top of this file.
820
- module.exports
821
- ));
822
-
823
- try {
824
- regeneratorRuntime = runtime;
825
- } catch (accidentalStrictMode) {
826
- // This module should not be running in strict mode, so the above
827
- // assignment should always work unless something is misconfigured. Just
828
- // in case runtime.js accidentally runs in strict mode, in modern engines
829
- // we can explicitly access globalThis. In older engines we can escape
830
- // strict mode using a global Function call. This could conceivably fail
831
- // if a Content Security Policy forbids using Function, but in that case
832
- // the proper solution is to fix the accidental strict mode problem. If
833
- // you've misconfigured your bundler to force strict mode and applied a
834
- // CSP to forbid Function, and you're not willing to fix either of those
835
- // problems, please detail your unique predicament in a GitHub issue.
836
- if (typeof globalThis === "object") {
837
- globalThis.regeneratorRuntime = runtime;
838
- } else {
839
- Function("r", "regeneratorRuntime = r")(runtime);
840
- }
841
- }
842
- });
843
-
844
- // TODO: Improve -> `listeners` are unbounded -- don't use this in practice!
845
- function createEventEmitter() {
846
- var listeners = {};
847
- return {
848
- on: function on(key, fn) {
849
- listeners[key] = (listeners[key] || []).concat(fn);
850
- },
851
- off: function off(key, fn) {
852
- listeners[key] = (listeners[key] || []).filter(function (f) {
853
- return f !== fn;
854
- });
855
- },
856
- emit: function emit(key, data) {
857
- (listeners[key] || []).forEach(function (fn) {
858
- try {
859
- fn(data);
860
- } catch (_unused) {}
861
- });
862
- }
863
- };
864
- }
865
-
866
- var BaseAuthClient = /*#__PURE__*/function () {
867
- function BaseAuthClient() {
868
- var _this = this;
869
-
870
- this._state = {
871
- isAuthenticated: false,
872
- isInitialized: false,
873
- tokens: {}
874
- };
875
- this.eventEmitter = createEventEmitter();
876
- this.subscribers = new Set(); // Should be declared like this to avoid binding issues when used by useSyncExternalStore
877
-
878
- this.subscribe = function (subscription) {
879
- _this.subscribers.add(subscription);
880
-
881
- return function () {
882
- return _this.subscribers["delete"](subscription);
883
- };
884
- }; // Should be declared like this to avoid binding issues when used by useSyncExternalStore
885
-
886
-
887
- this.getSnapshot = function () {
888
- return _this._state;
889
- };
890
- } //
891
- // Getters
892
- //
893
-
894
-
895
- var _proto = BaseAuthClient.prototype;
896
-
897
- //
898
- // Public methods
899
- //
900
- _proto.init =
901
- /*#__PURE__*/
902
- function () {
903
- var _init = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
904
- var _this$onPostInit;
905
-
906
- return runtime_1.wrap(function _callee$(_context) {
907
- while (1) {
908
- switch (_context.prev = _context.next) {
909
- case 0:
910
- _context.prev = 0;
911
- _context.next = 3;
912
- return this.onInit();
913
-
914
- case 3:
915
- this.setState({
916
- isInitialized: true
917
- });
918
- this.emit('initSuccess', undefined);
919
- _context.next = 11;
920
- break;
921
-
922
- case 7:
923
- _context.prev = 7;
924
- _context.t0 = _context["catch"](0);
925
- this.setState({
926
- isInitialized: false
927
- });
928
- this.emit('initFailed', _context.t0);
929
-
930
- case 11:
931
- _context.next = 13;
932
- return (_this$onPostInit = this.onPostInit) == null ? void 0 : _this$onPostInit.call(this);
933
-
934
- case 13:
935
- return _context.abrupt("return", this.isInitialized);
936
-
937
- case 14:
938
- case "end":
939
- return _context.stop();
940
- }
941
- }
942
- }, _callee, this, [[0, 7]]);
943
- }));
944
-
945
- function init() {
946
- return _init.apply(this, arguments);
947
- }
948
-
949
- return init;
950
- }();
951
-
952
- _proto.login = /*#__PURE__*/function () {
953
- var _login = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(credentials) {
954
- var _this$onPreLogin, _this$onPostLogin;
955
-
956
- var isSuccess, tokens;
957
- return runtime_1.wrap(function _callee2$(_context2) {
958
- while (1) {
959
- switch (_context2.prev = _context2.next) {
960
- case 0:
961
- this.emit('loginStarted', undefined);
962
- _context2.next = 3;
963
- return (_this$onPreLogin = this.onPreLogin) == null ? void 0 : _this$onPreLogin.call(this);
964
-
965
- case 3:
966
- isSuccess = false;
967
- _context2.prev = 4;
968
- _context2.next = 7;
969
- return this.onLogin(credentials);
970
-
971
- case 7:
972
- tokens = _context2.sent;
973
- this.setState({
974
- isAuthenticated: true,
975
- tokens: tokens
976
- });
977
- this.emit('loginSuccess', undefined);
978
- isSuccess = true;
979
- _context2.next = 18;
980
- break;
981
-
982
- case 13:
983
- _context2.prev = 13;
984
- _context2.t0 = _context2["catch"](4);
985
- this.setState({
986
- isAuthenticated: false,
987
- tokens: {}
988
- });
989
- this.emit('loginFailed', _context2.t0);
990
- isSuccess = false;
991
-
992
- case 18:
993
- _context2.next = 20;
994
- return (_this$onPostLogin = this.onPostLogin) == null ? void 0 : _this$onPostLogin.call(this, isSuccess);
995
-
996
- case 20:
997
- return _context2.abrupt("return", this.isAuthenticated);
998
-
999
- case 21:
1000
- case "end":
1001
- return _context2.stop();
1002
- }
1003
- }
1004
- }, _callee2, this, [[4, 13]]);
1005
- }));
1006
-
1007
- function login(_x) {
1008
- return _login.apply(this, arguments);
1009
- }
1010
-
1011
- return login;
1012
- }();
1013
-
1014
- _proto.refresh = /*#__PURE__*/function () {
1015
- var _refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(minValidity) {
1016
- var _this$onPreRefresh, _this$onPostRefresh;
1017
-
1018
- var isSuccess, tokens;
1019
- return runtime_1.wrap(function _callee3$(_context3) {
1020
- while (1) {
1021
- switch (_context3.prev = _context3.next) {
1022
- case 0:
1023
- this.emit('refreshStarted', undefined);
1024
- _context3.next = 3;
1025
- return (_this$onPreRefresh = this.onPreRefresh) == null ? void 0 : _this$onPreRefresh.call(this);
1026
-
1027
- case 3:
1028
- isSuccess = false;
1029
- _context3.prev = 4;
1030
- _context3.next = 7;
1031
- return this.onRefresh(minValidity);
1032
-
1033
- case 7:
1034
- tokens = _context3.sent;
1035
- this.setState({
1036
- isAuthenticated: true,
1037
- tokens: tokens
1038
- });
1039
- this.emit('refreshSuccess', undefined);
1040
- isSuccess = true;
1041
- _context3.next = 18;
1042
- break;
1043
-
1044
- case 13:
1045
- _context3.prev = 13;
1046
- _context3.t0 = _context3["catch"](4);
1047
- this.setState({
1048
- isAuthenticated: false,
1049
- tokens: {}
1050
- });
1051
- this.emit('refreshFailed', _context3.t0);
1052
- isSuccess = false;
1053
-
1054
- case 18:
1055
- _context3.next = 20;
1056
- return (_this$onPostRefresh = this.onPostRefresh) == null ? void 0 : _this$onPostRefresh.call(this, isSuccess);
1057
-
1058
- case 20:
1059
- return _context3.abrupt("return", this.isAuthenticated);
1060
-
1061
- case 21:
1062
- case "end":
1063
- return _context3.stop();
1064
- }
1065
- }
1066
- }, _callee3, this, [[4, 13]]);
1067
- }));
1068
-
1069
- function refresh(_x2) {
1070
- return _refresh.apply(this, arguments);
1071
- }
1072
-
1073
- return refresh;
1074
- }();
1075
-
1076
- _proto.logout = /*#__PURE__*/function () {
1077
- var _logout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
1078
- var _this$onPreLogout, _this$onPostLogout;
1079
-
1080
- var isSuccess;
1081
- return runtime_1.wrap(function _callee4$(_context4) {
1082
- while (1) {
1083
- switch (_context4.prev = _context4.next) {
1084
- case 0:
1085
- this.emit('logoutStarted', undefined);
1086
- _context4.next = 3;
1087
- return (_this$onPreLogout = this.onPreLogout) == null ? void 0 : _this$onPreLogout.call(this);
1088
-
1089
- case 3:
1090
- isSuccess = false;
1091
- _context4.prev = 4;
1092
- _context4.next = 7;
1093
- return this.onLogout();
1094
-
1095
- case 7:
1096
- this.setState({
1097
- isAuthenticated: false,
1098
- tokens: {}
1099
- });
1100
- this.emit('logoutSuccess', undefined);
1101
- isSuccess = true;
1102
- _context4.next = 16;
1103
- break;
1104
-
1105
- case 12:
1106
- _context4.prev = 12;
1107
- _context4.t0 = _context4["catch"](4);
1108
- this.emit('logoutFailed', _context4.t0);
1109
- isSuccess = false;
1110
-
1111
- case 16:
1112
- _context4.next = 18;
1113
- return (_this$onPostLogout = this.onPostLogout) == null ? void 0 : _this$onPostLogout.call(this, isSuccess);
1114
-
1115
- case 18:
1116
- case "end":
1117
- return _context4.stop();
1118
- }
1119
- }
1120
- }, _callee4, this, [[4, 12]]);
1121
- }));
1122
-
1123
- function logout() {
1124
- return _logout.apply(this, arguments);
1125
- }
1126
-
1127
- return logout;
1128
- }();
1129
-
1130
- _proto.on = function on(eventName, listener) {
1131
- this.eventEmitter.on(eventName, listener);
1132
- };
1133
-
1134
- _proto.off = function off(eventName, listener) {
1135
- this.eventEmitter.off(eventName, listener);
1136
- } //
1137
- // Protected methods
1138
- //
1139
- ;
1140
-
1141
- _proto.setState = function setState(stateUpdate) {
1142
- this._state = _extends({}, this._state, stateUpdate);
1143
- this.notifySubscribers();
1144
- } //
1145
- // Private methods
1146
- //
1147
- ;
1148
-
1149
- _proto.emit = function emit(eventName, error) {
1150
- this.eventEmitter.emit(eventName, error);
1151
- };
1152
-
1153
- _proto.notifySubscribers = function notifySubscribers() {
1154
- this.subscribers.forEach(function (s) {
1155
- try {
1156
- s();
1157
- } catch (_unused) {}
1158
- });
1159
- };
1160
-
1161
- _createClass(BaseAuthClient, [{
1162
- key: "isInitialized",
1163
- get: function get() {
1164
- return this._state.isInitialized;
1165
- }
1166
- }, {
1167
- key: "isAuthenticated",
1168
- get: function get() {
1169
- return this._state.isAuthenticated;
1170
- }
1171
- }, {
1172
- key: "tokens",
1173
- get: function get() {
1174
- return this._state.tokens;
1175
- }
1176
- }]);
1177
-
1178
- return BaseAuthClient;
1179
- }();
1180
-
1181
- function createAuth(authClient) {
1182
- // Create a React context containing a BaseAuthClient instance.
1183
- var authContext = React.createContext(null); // Create the React Context Provider for the BaseAuthClient instance.
1184
-
1185
- var AuthProvider = function AuthProvider(_ref) {
1186
- var children = _ref.children,
1187
- ErrorComponent = _ref.ErrorComponent,
1188
- LoadingComponent = _ref.LoadingComponent;
1189
-
1190
- var _useState = React.useState(false),
1191
- isInitFailed = _useState[0],
1192
- setInitFailed = _useState[1];
1193
-
1194
- var _useSyncExternalStore = shim.useSyncExternalStore(authClient.subscribe, authClient.getSnapshot),
1195
- isAuthenticated = _useSyncExternalStore.isAuthenticated,
1196
- isInitialized = _useSyncExternalStore.isInitialized;
1197
-
1198
- React.useEffect(function () {
1199
- function initAuthClient() {
1200
- return _initAuthClient.apply(this, arguments);
1201
- } // Init AuthClient
1202
-
1203
-
1204
- function _initAuthClient() {
1205
- _initAuthClient = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1206
- var initSuccess;
1207
- return runtime_1.wrap(function _callee$(_context) {
1208
- while (1) {
1209
- switch (_context.prev = _context.next) {
1210
- case 0:
1211
- _context.next = 2;
1212
- return authClient.init();
1213
-
1214
- case 2:
1215
- initSuccess = _context.sent;
1216
- setInitFailed(!initSuccess);
1217
-
1218
- case 4:
1219
- case "end":
1220
- return _context.stop();
1221
- }
1222
- }
1223
- }, _callee);
1224
- }));
1225
- return _initAuthClient.apply(this, arguments);
1226
- }
1227
-
1228
- initAuthClient();
1229
- }, []);
1230
-
1231
- if (!!ErrorComponent && isInitFailed) {
1232
- return ErrorComponent;
1233
- }
1234
-
1235
- if (!!LoadingComponent && !isInitialized) {
1236
- return LoadingComponent;
1237
- }
1238
-
1239
- return React__default.createElement(authContext.Provider, {
1240
- value: {
1241
- authClient: authClient,
1242
- isAuthenticated: isAuthenticated,
1243
- isInitialized: isInitialized
1244
- }
1245
- }, children);
1246
- }; // Retrieve the AuthClient from the current context
1247
-
1248
-
1249
- var useAuthClient = function useAuthClient() {
1250
- var ctx = React.useContext(authContext);
1251
-
1252
- if (!ctx) {
1253
- throw new Error('useAuthClient hook should be used inside AuthProvider');
1254
- }
1255
-
1256
- return ctx.authClient;
1257
- };
1258
-
1259
- return {
1260
- AuthProvider: AuthProvider,
1261
- useAuthClient: useAuthClient
1262
- };
1263
- }
1264
-
1265
- exports.BaseAuthClient = BaseAuthClient;
1266
- exports.createAuth = createAuth;
1267
- //# sourceMappingURL=react-auth.cjs.development.js.map